373 lines
13 KiB
C#
373 lines
13 KiB
C#
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Collections;
|
||
|
using System.Text;
|
||
|
using System.Drawing;
|
||
|
using MapGoogle;
|
||
|
using SafeMobileLib;
|
||
|
|
||
|
namespace Safedispatch_4_0
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// This class implements a route
|
||
|
/// </summary>
|
||
|
public class RouteInfo
|
||
|
{
|
||
|
public Int32 startTime;
|
||
|
public Int32 endTime;
|
||
|
public Color colorName;
|
||
|
public String routeName;
|
||
|
public String vehicleName;
|
||
|
public int nOfPositions;
|
||
|
public ArrayList positions = new ArrayList();
|
||
|
public double[] corners;
|
||
|
public bool checkedRoute;
|
||
|
public int currentPosition = 0;
|
||
|
public int lastPosition = 0;
|
||
|
public int samePosCount = 0;
|
||
|
// private Locationx[] locations;
|
||
|
public String[] Addresses;
|
||
|
private Pushpinx ppin;
|
||
|
public uint speed;
|
||
|
public uint engine; //0 unchecked 1 checked
|
||
|
public bool Addr;
|
||
|
public int currentLocIndex = 0;
|
||
|
public ArrayList LocationArray = new ArrayList();
|
||
|
/// <summary>
|
||
|
/// The class constructor
|
||
|
/// </summary>
|
||
|
/// <param name="startTimeParam">start time</param>
|
||
|
/// <param name="endTimeParam">end time</param>
|
||
|
/// <parm name="vehNameParam">vehicle name</parm>
|
||
|
/// <param name="colorNameParam">route color</param>
|
||
|
/// <param name="nameParam">route name</param>
|
||
|
/// <param name="positionsParam">array with route positions</param>
|
||
|
/// <param name="actEventsParam">array with route events</param>
|
||
|
public RouteInfo(Int32 startTimeParam, Int32 endTimeParam, String vehNameParam, Color colorNameParam, String nameParam, Boolean checkedRouteParam)
|
||
|
{
|
||
|
//int contor=0;
|
||
|
|
||
|
startTime = startTimeParam;
|
||
|
endTime = endTimeParam;
|
||
|
colorName = colorNameParam;
|
||
|
vehicleName = vehNameParam;
|
||
|
routeName = nameParam;
|
||
|
checkedRoute = checkedRouteParam;
|
||
|
corners = new double[4];
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Computes the addresses of the positions
|
||
|
/// </summary>
|
||
|
public void ComputeAddresses(AxMappointControlx mapControl)
|
||
|
{
|
||
|
int contor = 0;
|
||
|
foreach (SMposition obj in positions)
|
||
|
{
|
||
|
Addresses[contor] = obj.m_address;
|
||
|
contor++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Computes the route "boundaries"
|
||
|
/// </summary>
|
||
|
public void ComputeCorners()
|
||
|
{
|
||
|
corners[0] = corners[2] = 181.00;
|
||
|
corners[1] = corners[3] = -181.00;
|
||
|
foreach (SMposition obj in positions)
|
||
|
{
|
||
|
if ((Math.Round(obj.m_lat) == 0) && (Math.Round(obj.m_lng) == 0)) continue;
|
||
|
if (corners[0] > obj.m_lat) corners[0] = obj.m_lat;
|
||
|
if (corners[1] < obj.m_lat) corners[1] = obj.m_lat;
|
||
|
if (corners[2] > obj.m_lng) corners[2] = obj.m_lng;
|
||
|
if (corners[3] < obj.m_lng) corners[3] = obj.m_lng;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Sets the current position in the route
|
||
|
/// </summary>
|
||
|
/// <param name="paramCurrentPosition">Position to be set</param>
|
||
|
public void SetCurrentPosition(int paramCurrentPosition)
|
||
|
{
|
||
|
currentPosition = paramCurrentPosition;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Gets the current position in the route
|
||
|
/// </summary>
|
||
|
/// <returns>The current position</returns>
|
||
|
public SMposition GetCurrentPosition()
|
||
|
{
|
||
|
return (SMposition)positions[currentPosition];
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Sets the current position to zero
|
||
|
/// </summary>
|
||
|
public void ResetCurrentPosition()
|
||
|
{
|
||
|
currentPosition = 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// /Returns the position smaller than a given time and closest to it
|
||
|
/// </summary>
|
||
|
/// <param name="paramGivenTime"></param>
|
||
|
/// <returns></returns>
|
||
|
public SMposition LastPositionBeforeGivenTime(Int32 paramGivenTimeStart, Int32 paramGivenTimeEnd, out Int32 paramOutTimeEnd, bool back)
|
||
|
{
|
||
|
paramOutTimeEnd = paramGivenTimeEnd;
|
||
|
if (paramGivenTimeStart >= startTime)
|
||
|
{
|
||
|
currentPosition = 0;
|
||
|
while (((SMposition)positions[currentPosition]).m_time <= paramGivenTimeEnd)
|
||
|
if (currentPosition < positions.Count - 1)
|
||
|
currentPosition++;
|
||
|
else return (SMposition)positions[positions.Count - 1];
|
||
|
if (currentPosition > 0)
|
||
|
currentPosition--;
|
||
|
if (currentPosition == lastPosition) samePosCount++;
|
||
|
else
|
||
|
{
|
||
|
lastPosition = currentPosition;
|
||
|
samePosCount = 0;
|
||
|
}
|
||
|
if (samePosCount > 4)
|
||
|
{
|
||
|
if (back)
|
||
|
{
|
||
|
if (currentPosition>0) currentPosition--;
|
||
|
}
|
||
|
else currentPosition++;
|
||
|
samePosCount = 0;
|
||
|
paramOutTimeEnd = ((SMposition)positions[currentPosition]).m_time;
|
||
|
return (SMposition)positions[currentPosition];
|
||
|
}
|
||
|
else return (SMposition)positions[currentPosition];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return (SMposition)positions[0];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// /Returns the position bigger than a given time and closest to it
|
||
|
/// </summary>
|
||
|
/// <param name="paramGivenTime"></param>
|
||
|
/// <returns></returns>
|
||
|
public SMposition FirstPositionBeforeGivenTime(Int32 paramGivenTime)
|
||
|
{
|
||
|
if (paramGivenTime > startTime)
|
||
|
{
|
||
|
currentPosition = 0;
|
||
|
while (((SMposition)positions[currentPosition]).m_time < paramGivenTime)
|
||
|
if (currentPosition < positions.Count-1)
|
||
|
currentPosition++;
|
||
|
else
|
||
|
return (SMposition)positions[0];
|
||
|
if (currentPosition!=0) currentPosition--;
|
||
|
return (SMposition)positions[currentPosition];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return (SMposition)positions[positions.Count - 1];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// /Returns the position bigger than a given time and closest to it
|
||
|
/// </summary>
|
||
|
/// <param name="paramGivenTime"></param>
|
||
|
/// <returns></returns>
|
||
|
/// //object used to perform various time/date conversions
|
||
|
//private ConvertDT convDT = new ConvertDT();
|
||
|
|
||
|
public SMposition FirstPositionAfterGivenTime(Int32 paramGivenTime)
|
||
|
{
|
||
|
SMposition tmp = null;
|
||
|
currentPosition = -1;
|
||
|
foreach (SMposition obj in positions)
|
||
|
{
|
||
|
currentPosition++;
|
||
|
if (obj.m_time > paramGivenTime)
|
||
|
{
|
||
|
tmp = obj;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (tmp == null) { tmp = (SMposition)positions[positions.Count - 1]; }
|
||
|
SM.Debug("TIME GIVEN:" + paramGivenTime.ConvertGMTToLocal().GetDTFromSeconds().ToString() + "\n TIME FIND:" + tmp.m_time.ConvertGMTToLocal().GetDTFromSeconds().ToString());
|
||
|
return tmp;
|
||
|
}
|
||
|
|
||
|
public void SaveRouteLocations(ArrayList paramLocations, Color colorParam, Int32 StartTimeParam, Int32 StopTimeParam)
|
||
|
{
|
||
|
LocAndColor tmp = new LocAndColor();
|
||
|
|
||
|
//tmp.location = new Locationx[paramLocations.Length];
|
||
|
/*for (int i = 0; i < paramLocations.Length; i++)
|
||
|
{
|
||
|
//tmp.location[i] = paramLocations[i];
|
||
|
tmp.latlng.Add(paramLocations[i].Latitude);
|
||
|
tmp.latlng.Add(paramLocations[i].Longitude);
|
||
|
}*/
|
||
|
foreach (Double obj in paramLocations)
|
||
|
tmp.latlng.Add(obj);
|
||
|
tmp.color = colorParam;
|
||
|
|
||
|
if ((StartTimeParam == 0) && (StopTimeParam == 0))
|
||
|
{
|
||
|
tmp.startTime = startTime;
|
||
|
tmp.endTime = endTime;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
tmp.startTime = StartTimeParam;
|
||
|
tmp.endTime = StopTimeParam;
|
||
|
}
|
||
|
|
||
|
LocationArray.Add(tmp);
|
||
|
}
|
||
|
|
||
|
public ArrayList GetRouteLocations()
|
||
|
{
|
||
|
return LocationArray;
|
||
|
}
|
||
|
|
||
|
public void ResetRouteLocations()
|
||
|
{
|
||
|
LocationArray.Clear();
|
||
|
}
|
||
|
|
||
|
public void SetPushpin(Pushpinx pp)
|
||
|
{
|
||
|
ppin = pp;
|
||
|
}
|
||
|
|
||
|
public Pushpinx GetPushpin()
|
||
|
{
|
||
|
return ppin;
|
||
|
}
|
||
|
|
||
|
|
||
|
public Int32 GetInitialHeading()
|
||
|
{
|
||
|
return ((SMposition)positions[0]).m_heading;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public class SimpleRoute
|
||
|
{
|
||
|
public ArrayList PositionList = new ArrayList();
|
||
|
public int currentPosition = 0;
|
||
|
public Int32 startTime=0;
|
||
|
public Int32 endTime=0;
|
||
|
public int lastPosition = 0;
|
||
|
public int samePosCount = 0;
|
||
|
|
||
|
public SimpleRoute(ArrayList pos)
|
||
|
{
|
||
|
foreach (object obj in pos)
|
||
|
PositionList.Add(obj);
|
||
|
if (pos.Count > 0)
|
||
|
{
|
||
|
startTime = ((SMposition)pos[0]).m_time;
|
||
|
endTime = ((SMposition)pos[pos.Count-1]).m_time;
|
||
|
}
|
||
|
}
|
||
|
public SMposition FirstPositionAfterGivenTime(Int32 paramGivenTime)
|
||
|
{
|
||
|
SMposition tmp = null;
|
||
|
currentPosition = -1;
|
||
|
foreach (SMposition obj in PositionList)
|
||
|
{
|
||
|
currentPosition++;
|
||
|
if (obj.m_time > paramGivenTime)
|
||
|
{
|
||
|
tmp = obj;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (tmp == null) { tmp = (SMposition)PositionList[PositionList.Count - 1]; }
|
||
|
return tmp;
|
||
|
}
|
||
|
|
||
|
public SMposition FirstPositionBeforeGivenTime(Int32 paramGivenTime)
|
||
|
{
|
||
|
if (paramGivenTime > startTime)
|
||
|
{
|
||
|
currentPosition = 0;
|
||
|
while (((SMposition)PositionList[currentPosition]).m_time < paramGivenTime)
|
||
|
if (currentPosition < PositionList.Count - 1)
|
||
|
currentPosition++;
|
||
|
else
|
||
|
return (SMposition)PositionList[PositionList.Count - 1];
|
||
|
if (currentPosition != 0) currentPosition--;
|
||
|
return (SMposition)PositionList[currentPosition];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return (SMposition)PositionList[0];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public SMposition LastPositionBeforeGivenTime(Int32 paramGivenTimeStart, Int32 paramGivenTimeEnd, out Int32 paramOutTimeEnd, bool back)
|
||
|
{
|
||
|
paramOutTimeEnd = paramGivenTimeEnd;
|
||
|
if (paramGivenTimeStart >= startTime)
|
||
|
{
|
||
|
currentPosition = 0;
|
||
|
while (((SMposition)PositionList[currentPosition]).m_time <= paramGivenTimeEnd)
|
||
|
if (currentPosition < PositionList.Count - 1)
|
||
|
currentPosition++;
|
||
|
else return (SMposition)PositionList[PositionList.Count - 1];
|
||
|
if (currentPosition > 0)
|
||
|
currentPosition--;
|
||
|
if (currentPosition == lastPosition) samePosCount++;
|
||
|
else
|
||
|
{
|
||
|
lastPosition = currentPosition;
|
||
|
samePosCount = 0;
|
||
|
}
|
||
|
if (samePosCount > 4)
|
||
|
{
|
||
|
if (back)
|
||
|
{
|
||
|
if (currentPosition > 0) currentPosition--;
|
||
|
}
|
||
|
else currentPosition++;
|
||
|
samePosCount = 0;
|
||
|
paramOutTimeEnd = ((SMposition)PositionList[currentPosition]).m_time;
|
||
|
return (SMposition)PositionList[currentPosition];
|
||
|
}
|
||
|
else return (SMposition)PositionList[currentPosition];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return (SMposition)PositionList[0];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public SMposition GetCurrentPosition()
|
||
|
{
|
||
|
return (SMposition)PositionList[currentPosition];
|
||
|
}
|
||
|
|
||
|
public void ResetCurrentPosition()
|
||
|
{
|
||
|
currentPosition = 0;
|
||
|
}
|
||
|
|
||
|
public Int32 GetInitialHeading()
|
||
|
{
|
||
|
return ((SMposition)PositionList[0]).m_heading;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|