SafeDispatch/Safedispatch_4_0/RoutesInfo.cs

193 lines
6.7 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.Collections;
using System.Drawing;
using System.Text;
//using XmlLibrary;
/*==================================================================================================
Revision History:
Modification Tracking
Author (email) Date Number Description of Changes
------------------------- ------------ ---------- -------------------------------------------
Ilie Luican August 18, 2006 x.x first commented version
ilie@airadio.net
------------------------- ------------ ---------- -------------------------------------------
------------------------- ------------ ---------- -------------------------------------------
==================================================================================================*/
namespace Safedispatch_4_0
{
/// <summary>
/// This class implements a list of routes associated with a vehicle
/// </summary>
public class RoutesInfo
{
public ArrayList routes=null;
public int nOfRoutes;
public int nOfPositions;
public double[] corners;
public String IMEI="";
private String vehicleName;
public Int32 minTime;
public Int32 maxTime;
static public uint iMaxPos = 0;
/// <summary>
/// The class constructor
/// </summary>
/// <param name="paramIMEI">the IMEI of the associated vehicle</param>
public RoutesInfo(String paramIMEI, String vehNamePass)
{
routes = new ArrayList();
nOfRoutes = 0;
nOfPositions = 0;
corners = new double[4];
IMEI = paramIMEI;
vehicleName = vehNamePass;
}
/// <summary>
/// Adds a route to the routes list
/// </summary>
/// <param name="startTimeParam">start time</param>
/// <param name="endTimeParam">end time</param>
/// <param name="vehNameParam">vehicle name</param>
/// <param name="colorNameParam">color name</param>
/// <param name="routeNameParam">route name</param>
/// <param name="iSpeedLimit">minimum speed for select</param>
/// <param name="iEngine">select cars with engine on</param>
public void AddRoute2(Int32 startTimeParam, Int32 endTimeParam, String vehNameParam, Color colorNameParam, String routeNameParam)
{
if (nOfRoutes==0) routes.Add(new RouteInfo(startTimeParam, endTimeParam, vehNameParam, colorNameParam, routeNameParam, true));
else routes.Add(new RouteInfo(startTimeParam, endTimeParam, vehNameParam, colorNameParam, routeNameParam, false));
nOfRoutes++;
ComputeMinMaxTime();
}
/// <summary>
/// Removes a route from the routes list
/// </summary>
/// <param name="routeNameParam">route name</param>
public void RemoveRoute(String routeNameParam)
{
foreach (RouteInfo obj in routes)
{
if (obj.routeName == routeNameParam)
{
nOfPositions = nOfPositions - obj.nOfPositions;
routes.Remove(obj);
nOfRoutes--;
break;
}
}
ComputeMinMaxTime();
}
public void RemoveQuick()
{
foreach (RouteInfo obj in routes)
{
if (obj.routeName.Contains("_quick"))
{
nOfPositions = nOfPositions - obj.nOfPositions;
routes.Remove(obj);
nOfRoutes--;
break;
}
}
ComputeMinMaxTime();
}
public void ComputeMinMaxTime()
{
minTime = Int32.MinValue;
maxTime = Int32.MaxValue;
foreach (RouteInfo obj in routes)
{
if (obj.startTime < minTime)
minTime = obj.startTime;
if (obj.endTime > maxTime)
maxTime = obj.endTime;
}
}
/// Determines if an interval is already contained within current intervals in routes
/// </summary>
/// <param name="param1">Start time of the interval</param>
/// <param name="param2">End time of the interval</param>
/// <returns>Returns true if interval is contained, and false otherwise</returns>
public Boolean CheckInterval(uint param1, uint param2)
{
if (nOfRoutes > 0)
{
foreach (RouteInfo obj in routes)
{
if (param1 >= obj.startTime)
{
if (param1 <= obj.endTime)
return true;
}
else
{
if (param2 >= obj.startTime)
return true;
}
}
return false;
}
else
return false;
}
/// <summary>
/// Computes the "boundaries" of the entire routes list
/// </summary>
public void ComputeCorners()
{
corners[0] = corners[2] = 181.00;
corners[1] = corners[3] = -181.00;
foreach (RouteInfo obj in routes)
{
if (obj.checkedRoute)
{
if (corners[0] > obj.corners[0]) corners[0] = obj.corners[0];
if (corners[1] < obj.corners[1]) corners[1] = obj.corners[1];
if (corners[2] > obj.corners[2]) corners[2] = obj.corners[2];
if (corners[3] < obj.corners[3]) corners[3] = obj.corners[3];
}
}
}
/// <summary>
/// Sets the checked flag to true/false for each route
/// from the routes list
/// </summary>
/// <param name="paramSelectedRoutes"></param>
public void SetCheckedRoutes(ArrayList paramSelectedRoutes)
{
bool found;
found = false;
foreach (RouteInfo obj2 in routes)
{
foreach (String obj in paramSelectedRoutes)
{
found = false;
if (obj2.routeName == obj)
{
obj2.checkedRoute = true;
found = true;
break;
}
}
if (!found)
obj2.checkedRoute = false;
}
}
}
}