private static void _SaveFakeItems(XmlWriter writer, int partID, IList <Stop> sortedStops, Stop currentStop, bool previouslyStopBreak, int currentIndex) { Debug.Assert(currentStop.StopType == StopType.Lunch); // WORKAROUND: add fake direction for break var stopWithLocation = SolveHelper.GetActualLunchStop(sortedStops, currentIndex); Debug.Assert(0 < stopWithLocation.Directions.Length); int lastDirIndex = stopWithLocation.Directions.Length - 1; Direction lastDirection = stopWithLocation.Directions[lastDirIndex]; string geometry = lastDirection.Geometry; // hardcoded text string text = Properties.Resources.DomainPropertyNameLunch; // add depart direction string departText = text; string departGeometry = geometry; StopManeuverType maneuver = StopManeuverType.Depart; // if previously stop not Break if (!previouslyStopBreak) { // if next stop have directions Direction?nextDirection = _GetNextStopStartDirection(sortedStops, currentIndex); if (nextDirection.HasValue) { // update values from start direction Direction direction = nextDirection.Value; maneuver = direction.ManeuverType; departText = direction.Text; departGeometry = direction.Geometry; } } _SaveStopDirection(writer, partID, 0.0, 0.0, maneuver, departText, departGeometry); // add arrive direction _SaveStopDirection(writer, partID, 0.0, 0.0, StopManeuverType.Stop, text, geometry); }
private static void _SaveRouteSettings(XmlWriter writer, Route route, IVrpSolver solver, GrfExportResult result) { SolverSettings settings = solver.SolverSettings; writer.WriteStartElement(ROUTE_SETTINGS_NODE_NAME); writer.WriteStartElement(UTURNPOLICY_NODE_NAME); string uTurnPolicy = ""; switch (settings.GetUTurnPolicy()) { case UTurnPolicy.Nowhere: uTurnPolicy = UTurnNowhere; break; case UTurnPolicy.AtDeadEnds: uTurnPolicy = UTurnAtDeadEnds; break; case UTurnPolicy.AtDeadEndsAndIntersections: // GRF doesnt support "U-Turns at Dead Ends and Intersections" UTurnPolicy, // so replace it with "U-Turns at Dead Ends". //fjk: updated so UTurnEverywhere respected uTurnPolicy = UTurnEverywhere; //fjk: commented out b/c of the above change // Add warning message //result.Warnings.Add(Properties.Messages.Warning_UTurnPolicyNotSupported); break; default: Debug.Assert(false); // NOTE: not supported break; } writer.WriteAttributeString(VALUE_ATTR_NAME, uTurnPolicy); writer.WriteEndElement(); writer.WriteStartElement(IMPEDANCE_ATTR_NODE_NAME); writer.WriteAttributeString(NAME_ATTR_NAME, "Time"); writer.WriteEndElement(); writer.WriteStartElement(RESTRICTIONS_ATTR_NODE_NAME); ICollection <string> restrictions = SolveHelper.GetEnabledRestrictionNames( solver.SolverSettings.Restrictions); foreach (string name in restrictions) { writer.WriteStartElement(RESTRICTION_NODE_NAME); writer.WriteAttributeString(NAME_ATTR_NAME, name); writer.WriteAttributeString(TYPE_ATTR_NAME, STRICT_ATTR_NAME); writer.WriteAttributeString(STATUS_ATTR_NAME, ON_ATTR); writer.WriteEndElement(); } writer.WriteEndElement(); _SaveRouteAttributes(writer, route, solver); writer.WriteStartElement(TRIPPLANSETTINGS_NODE_NAME); writer.WriteStartElement(TRIP_START_NODE_NAME); string startTime = route.StartTime.Value.ToString("yyyy-MM-ddTHH:mm:ss"); writer.WriteAttributeString(VALUE_ATTR_NAME, startTime); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteStartElement(DIRECTIONS_LENGTH_UNITS_NODE_NAME); string lengthUnits; RegionInfo ri = new RegionInfo(System.Threading.Thread.CurrentThread.CurrentCulture.LCID); if (ri.IsMetric) { lengthUnits = KILOMETERS; } else { lengthUnits = MILES; } writer.WriteAttributeString(VALUE_ATTR_NAME, lengthUnits); writer.WriteEndElement(); writer.WriteStartElement(DIRECTIONS_CONTENT_NODE_NAME); writer.WriteAttributeString(VALUE_ATTR_NAME, "all"); writer.WriteEndElement(); writer.WriteEndElement(); }
private static void _SaveStops( XmlWriter writer, Route route, ICollection <Stop> stops, ICollection <string> orderPropertiesToExport, Project project, AddressField[] addressFields) { Debug.Assert(route != null); var sortedStops = new List <Stop>(stops); CommonHelpers.SortBySequence(sortedStops); var orderPropertiesTitlesToExport = new List <string>(); var names = new List <string>(Order.GetPropertyNames(project.CapacitiesInfo, project.OrderCustomPropertiesInfo, addressFields)); var titles = new List <string>(Order.GetPropertyTitles(project.CapacitiesInfo, project.OrderCustomPropertiesInfo, addressFields)); foreach (string name in orderPropertiesToExport) { int index = names.IndexOf(name); string title = titles[index]; orderPropertiesTitlesToExport.Add(title); } var routeStops = CommonHelpers.GetSortedStops(route); writer.WriteStartElement(STOPS_NODE_NAME); foreach (Stop stop in sortedStops) { string name = _GetStopName(stop, routeStops); var mapLocation = stop.MapLocation; if (!mapLocation.HasValue) { if (stop.StopType != StopType.Lunch) { throw new InvalidOperationException( Properties.Messages.Error_GrfExporterNoLocationForStop); // exception } var currentIndex = stop.SequenceNumber - 1; var stopWithLocation = SolveHelper.GetActualLunchStop(routeStops, currentIndex); if (!stopWithLocation.MapLocation.HasValue) { throw new InvalidOperationException( Properties.Messages.Error_GrfExporterNoLocationForStop); // exception } mapLocation = stopWithLocation.MapLocation.Value; } writer.WriteStartElement(STOP_NODE_NAME); writer.WriteAttributeString(ENABLED_ATTR_NAME, TRUE_VALUE); string comments = _GetComments(stop, orderPropertiesToExport, orderPropertiesTitlesToExport); _SaveLocationNode(writer, mapLocation.Value, name, comments); writer.WriteStartElement(DURATION_NODE_NAME); double duration = stop.TimeAtStop * 60; writer.WriteValue(duration.ToString(DOUBLE_FORMAT, NumberFormatInfo.InvariantInfo)); writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); }