private void modifySetDefaultSpeeds_Click(object sender, EventArgs e) { try { double defMin = double.Parse(this.modifyDefaultMinimumSpeedTextBox.Text); double defMax = double.Parse(this.modifyDefaultMaximumSpeedTextBox.Text); this.Mission.SpeedLimits = new List <ArbiterSpeedLimit>(); foreach (ArbiterSegment asg in this.RoadNetwork.ArbiterSegments.Values) { ArbiterSpeedLimit asl = new ArbiterSpeedLimit(); asl.MinimumSpeed = defMin; asl.MaximumSpeed = defMax; asl.Area = asg.SegmentId; this.Mission.SpeedLimits.Add(asl); } foreach (ArbiterZone az in this.RoadNetwork.ArbiterZones.Values) { ArbiterSpeedLimit asl = new ArbiterSpeedLimit(); asl.MinimumSpeed = defMin; asl.MaximumSpeed = defMax; asl.Area = az.ZoneId; this.Mission.SpeedLimits.Add(asl); } this.PopulateModifyTab(); } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } }
private void modifyRemoveCheckpointButton_Click(object sender, EventArgs e) { try { int index = this.modifySelectMissionCheckpointComboBox.SelectedIndex; if (index >= 0) { ArbiterCheckpoint[] acs = this.Mission.MissionCheckpoints.ToArray(); this.Mission.MissionCheckpoints = new Queue <ArbiterCheckpoint>(); for (int i = 0; i < acs.Length; i++) { if (i != index) { this.Mission.MissionCheckpoints.Enqueue(acs[i]); } } this.modifySelectMissionCheckpointComboBox.Text = ""; this.PopulateModifyTab(); } } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } }
private void PopulateModifyTab() { try { if (this.Mission != null) { this.modifySelectAreaComboBox.Items.Clear(); this.modifySelectAreaComboBox.Items.AddRange(this.GetAreaNames().ToArray()); this.modifySelectCheckpointComboBox.Items.Clear(); this.modifySelectCheckpointComboBox.Items.AddRange(this.GetRoadCheckpointNames().ToArray()); this.modifySelectMissionCheckpointComboBox.Items.Clear(); ArbiterCheckpoint[] acs = this.Mission.MissionCheckpoints.ToArray(); for (int i = 0; i < acs.Length; i++) { this.modifySelectMissionCheckpointComboBox.Items.Add(i.ToString() + " - " + acs[i].CheckpointNumber.ToString() + " - " + acs[i].WaypointId.ToString()); } this.PopulateMissionBrowser(); } } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } }
private void setAreaSpeedButton_Click(object sender, EventArgs e) { try { if (this.selectAreaComboBox.SelectedIndex >= 0 && this.minAreaSpeedTextBox.Text != null && this.minAreaSpeedTextBox.Text != "" && this.maxAreaSpeedTextBox.Text != null && this.maxAreaSpeedTextBox.Text != "") { string id = (string)this.selectAreaComboBox.Items[this.selectAreaComboBox.SelectedIndex]; if (this.CreateMissionNonDefaultSpeeds.ContainsKey(id)) { this.CreateMissionNonDefaultSpeeds[id].MaximumSpeed = double.Parse(this.maxAreaSpeedTextBox.Text); this.CreateMissionNonDefaultSpeeds[id].MinimumSpeed = double.Parse(this.minAreaSpeedTextBox.Text); } else { ArbiterSpeedLimit asl = new ArbiterSpeedLimit(); asl.MaximumSpeed = double.Parse(this.maxAreaSpeedTextBox.Text); asl.MinimumSpeed = double.Parse(this.minAreaSpeedTextBox.Text); this.CreateMissionNonDefaultSpeeds.Add(id, asl); } } } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } }
private void modifyMoveCheckpointUpButton_Click(object sender, EventArgs e) { try { int index = this.modifySelectMissionCheckpointComboBox.SelectedIndex; if (index > 0 && index < this.Mission.MissionCheckpoints.Count) { ArbiterCheckpoint[] acs = this.Mission.MissionCheckpoints.ToArray(); this.Mission.MissionCheckpoints = new Queue <ArbiterCheckpoint>(); ArbiterCheckpoint tmp = acs[index]; acs[index] = acs[index - 1]; acs[index - 1] = tmp; for (int i = 0; i < acs.Length; i++) { this.Mission.MissionCheckpoints.Enqueue(acs[i]); } this.PopulateModifyTab(); this.modifySelectMissionCheckpointComboBox.SelectedItem = this.modifySelectMissionCheckpointComboBox.Items[index - 1]; this.modifySelectMissionCheckpointComboBox.SelectedIndex = index - 1; } } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } }
private void modifyRandomizeButton_Click(object sender, EventArgs e) { try { int length = int.Parse(this.modifyNumberToRandomizeTextBox.Text); this.Mission.MissionCheckpoints = new Queue <ArbiterCheckpoint>(); List <ArbiterCheckpoint> acs = new List <ArbiterCheckpoint>(); foreach (KeyValuePair <int, IArbiterWaypoint> ac in this.RoadNetwork.Checkpoints) { acs.Add(new ArbiterCheckpoint(ac.Key, ac.Value.AreaSubtypeWaypointId)); } Random r = new Random(); for (int i = 0; i < length; i++) { int num = r.Next(acs.Count); this.Mission.MissionCheckpoints.Enqueue(acs[num]); } this.PopulateModifyTab(); } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } }
private void modifySetAreaSpeedButton_Click(object sender, EventArgs e) { try { int index = this.modifySelectAreaComboBox.SelectedIndex; if (index >= 0) { double minSpeed = double.Parse(this.modifyMinSpeedTextBox.Text); double maxSpeed = double.Parse(this.modifyMaxSpeedTextBox.Text); int areaId = int.Parse((string)this.modifySelectAreaComboBox.Items[index]); foreach (ArbiterSpeedLimit asl in this.Mission.SpeedLimits) { if (asl.Area.Number.Equals(areaId)) { asl.MaximumSpeed = maxSpeed; asl.MinimumSpeed = minSpeed; break; } } this.PopulateModifyTab(); } } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } }
private void PopulateMissionBrowser() { try { if (this.Mission != null) { List <List <string> > browser = new List <List <string> >(); ArbiterCheckpoint[] acs = this.Mission.MissionCheckpoints.ToArray(); for (int i = 0; i < this.Mission.MissionCheckpoints.Count; i++) { List <string> cpString = new List <string>(); cpString.Add(i.ToString()); cpString.Add(acs[i].CheckpointNumber.ToString()); cpString.Add(acs[i].WaypointId.ToString()); browser.Add(cpString); } for (int i = 0; i < this.Mission.SpeedLimits.Count; i++) { List <string> slString = new List <string>(); slString.Add(this.Mission.SpeedLimits[i].Area.ToString()); slString.Add(this.Mission.SpeedLimits[i].MinimumSpeed.ToString()); slString.Add(this.Mission.SpeedLimits[i].MaximumSpeed.ToString()); if (browser.Count > i) { browser[i].AddRange(slString); } else { List <string> tmpString = new List <string>(); tmpString.Add(""); tmpString.Add(""); tmpString.Add(""); tmpString.AddRange(slString); browser.Add(tmpString); } } this.missionBrowser.Items.Clear(); foreach (List <string> vals in browser) { this.missionBrowser.Items.Add(new ListViewItem(vals.ToArray())); } this.missionBrowser.Invalidate(); } } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } }
private void selectRoadNetworkCheckpointComboBox_SelectedIndexChanged(object sender, EventArgs e) { try { int index = this.selectRoadNetworkCheckpointComboBox.SelectedIndex; string text = (string)this.selectRoadNetworkCheckpointComboBox.Items[index]; string[] delimeters = new string[] { " - " }; string[] final = text.Split(delimeters, StringSplitOptions.RemoveEmptyEntries); int goal = int.Parse(final[0]); this.roadDisplay1.Center(this.RoadNetwork.Checkpoints[goal].Position); this.roadDisplay1.Invalidate(); } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } }
private void modifySaveButton_Click(object sender, EventArgs e) { // create a new open file dialog this.saveFileDialog1 = new SaveFileDialog(); // settings for openFileDialog saveFileDialog1.InitialDirectory = "Desktop\\"; saveFileDialog1.Filter = "Arbiter Mission Description (*.amd)|*.amd|All files (*.*)|*.*"; saveFileDialog1.FilterIndex = 1; saveFileDialog1.RestoreDirectory = true; // check if everything was selected alright if (saveFileDialog1.ShowDialog() == DialogResult.OK) { try { // switch over the final index switch (saveFileDialog1.FilterIndex) { // create an mdf case 1: // create file FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create); // serializer BinaryFormatter bf = new BinaryFormatter(); // serialize bf.Serialize(fs, this.Mission); // release holds fs.Dispose(); // end case break; } } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } } }
private void MoveUpMissionCheckpointButton_Click(object sender, EventArgs e) { try { int index = this.selectMissionCheckpointComboBox.SelectedIndex; if (index > 0 && index < CreateMissionCheckpoints.Count) { this.SwapCreateMissionCheckpoint(index, index - 1); this.selectMissionCheckpointComboBox.Items.Clear(); this.selectMissionCheckpointComboBox.Items.AddRange(this.CreateMissionCheckpoints.ToArray()); this.selectMissionCheckpointComboBox.SelectedIndex = index - 1; this.selectMissionCheckpointComboBox.Invalidate(); } } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } }
/// <summary> /// Generates a road graph to a file from the internal road network /// </summary> /// <param name="fileName"></param> public void GenerateRoadGraph(string fileName) { // create file FileStream fs = new FileStream(fileName, FileMode.Create); // create writer StreamWriter sw = new StreamWriter(fs); // notify EditorOutput.WriteLine("Generating road graph to file: " + fileName); // notify EditorOutput.WriteLine("Writing general information"); // general this.WriteGeneralInformation(sw); // notify EditorOutput.WriteLine("Writing waypoint information"); // waypoint this.WriteWaypointInformation(sw); // notify EditorOutput.WriteLine("Writing partition information"); // partitions this.WritePartitionInformation(sw); // end rndf sw.WriteLine("End_Rndf"); // write final sw.Close(); // release holds fs.Dispose(); // notify EditorOutput.WriteLine("Generated road graph to file: " + fileName); }
private void modifyAddCheckpointButton_Click(object sender, EventArgs e) { try { int index = this.modifySelectCheckpointComboBox.SelectedIndex; if (index >= 0) { string text = (string)this.modifySelectCheckpointComboBox.Items[index]; string[] delimeters = new string[] { " - " }; string[] final = text.Split(delimeters, StringSplitOptions.RemoveEmptyEntries); int goal = int.Parse(final[0]); this.Mission.MissionCheckpoints.Enqueue(new ArbiterCheckpoint(goal, this.RoadNetwork.Checkpoints[goal].AreaSubtypeWaypointId)); this.PopulateModifyTab(); } } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } }
private void RemoveMissionCheckpointButton_Click(object sender, EventArgs e) { try { int index = this.selectMissionCheckpointComboBox.SelectedIndex; if (index >= 0 && index < CreateMissionCheckpoints.Count) { this.CreateMissionCheckpoints.RemoveAt(index); this.selectMissionCheckpointComboBox.Items.Clear(); this.selectMissionCheckpointComboBox.Items.AddRange(this.CreateMissionCheckpoints.ToArray()); this.selectMissionCheckpointComboBox.SelectedIndex = this.CreateMissionCheckpoints.Count > 0 ? 0 : -1; if (this.CreateMissionCheckpoints.Count == 0) { this.selectMissionCheckpointComboBox.Text = ""; } this.selectMissionCheckpointComboBox.Invalidate(); } } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } }
private void ShiftNetworkOkButton_Click(object sender, EventArgs e) { try { double east = double.Parse(this.ShiftNetworkEastTextBox.Text); double north = double.Parse(this.ShiftNetworkNorthTextBox.Text); Coordinates shift = new Coordinates(east, north); foreach (IArbiterWaypoint iaw in roads.ArbiterWaypoints.Values) { iaw.Position = iaw.Position + shift; } // safety zone filter DisplayObjectFilter f = delegate(IDisplayObject target) { // check if target is network object if (target is ArbiterSafetyZone) { return(true); } else { return(false); } }; // remove safety zones display.RemoveDisplayObjectType(f); // new safety roads.ArbiterSafetyZones = new List <ArbiterSafetyZone>(); // remove from network List <IDisplayObject> displayObjects = new List <IDisplayObject>(); foreach (IDisplayObject ido in roads.DisplayObjects) { if (!f(ido)) { displayObjects.Add(ido); } } // remove lane safety zones, create new partition paths foreach (ArbiterSegment asg in roads.ArbiterSegments.Values) { foreach (ArbiterLane al in asg.Lanes.Values) { al.SafetyZones = new List <ArbiterSafetyZone>(); // path segments of lane List <IPathSegment> pathSegments = new List <IPathSegment>(); // loop foreach (ArbiterLanePartition alPar in al.Partitions) { // make new segment pathSegments.Add(new LinePathSegment(alPar.Initial.Position, alPar.Final.Position)); } // generate lane partition path Path partitionPath = new Path(pathSegments); al.PartitionPath = partitionPath; } } // recreate safety zones foreach (IArbiterWaypoint iaw in roads.ArbiterWaypoints.Values) { if (iaw is ArbiterWaypoint) { ArbiterWaypoint aw = (ArbiterWaypoint)iaw; if (aw.IsStop) { ArbiterLane al = aw.Lane; LinePath.PointOnPath end = al.GetClosestPoint(aw.Position); double dist = -30; LinePath.PointOnPath begin = al.LanePath().AdvancePoint(end, ref dist); if (dist != 0) { EditorOutput.WriteLine(aw.ToString() + " safety zone too close to start of lane, setting start to start of lane"); begin = al.LanePath().StartPoint; } ArbiterSafetyZone asz = new ArbiterSafetyZone(al, end, begin); asz.isExit = true; asz.Exit = aw; al.SafetyZones.Add(asz); roads.DisplayObjects.Add(asz); roads.ArbiterSafetyZones.Add(asz); display.AddDisplayObject(asz); } } } // redraw this.display.Invalidate(); // notify EditorOutput.WriteLine("Shifted road network: east: " + east.ToString("F6") + ", north: " + north.ToString("F6")); EditorOutput.WriteLine("Recomputed position-dependent types"); // close form this.Close(); } catch (Exception ex) { EditorOutput.WriteLine("Shift of road network failed: \n" + ex.ToString()); } }
/// <summary> /// Write partition informaton /// </summary> /// <param name="sw"></param> private void WritePartitionInformation(StreamWriter sw) { // get list of all partitions that connect waypoints List <IConnectAreaWaypoints> icaws = new List <IConnectAreaWaypoints>(); #region Populate partitions // get lane partitions foreach (ArbiterSegment asg in roadNetwork.ArbiterSegments.Values) { foreach (ArbiterLane al in asg.Lanes.Values) { foreach (ArbiterLanePartition alp in al.Partitions) { icaws.Add(alp); } } } // get interconnects foreach (ArbiterInterconnect ai in roadNetwork.ArbiterInterconnects.Values) { icaws.Add(ai); } // zones (holy stuff what a hack) foreach (ArbiterZone az in roadNetwork.ArbiterZones.Values) { icaws.Add(new SceneZonePartition(az)); } #endregion // notify sw.WriteLine("NumberOfPartitions" + "\t" + icaws.Count.ToString()); string completionPercent = ""; #region Create Partitions in Road Graph // write each for (int i = 0; i < icaws.Count; i++) { IConnectAreaWaypoints icaw = icaws[i]; sw.WriteLine("Partition"); string id = ""; if (icaw is SceneZonePartition) { id = ("PartitionId" + "\t" + ((SceneZonePartition)icaw).Zone.ToString()); } else { id = ("PartitionId" + "\t" + icaw.ConnectionId.ToString()); } sw.WriteLine(id); // notify double percent = ((double)i) / ((double)icaws.Count) * 100.0; string tmpP = percent.ToString("F0") + "% Complete"; if (tmpP != completionPercent) { completionPercent = tmpP; EditorOutput.WriteLine(completionPercent); } #region Interconnect if (icaw is ArbiterInterconnect) { ArbiterInterconnect ai = (ArbiterInterconnect)icaw; sw.WriteLine("PartitionType" + "\t" + "Interconnect"); sw.WriteLine("Sparse" + "\t" + "False"); sw.WriteLine("FitType" + "\t" + "Line"); Coordinates c = ai.FinalGeneric.Position - ai.InitialGeneric.Position; sw.WriteLine("FitParameters" + "\t" + c.ArcTan.ToString("F6")); sw.WriteLine("LeftBoundary" + "\t" + "None"); sw.WriteLine("RightBoundary" + "\t" + "None"); sw.WriteLine("NumberOfPoints" + "\t" + "2"); sw.WriteLine("Points"); sw.WriteLine(ai.InitialGeneric.ToString()); sw.WriteLine(ai.FinalGeneric.ToString()); sw.WriteLine("End_Points"); List <ArbiterWaypoint> aws = this.GetNearbyStops(ai); sw.WriteLine("NumberOfNearbyStoplines" + "\t" + aws.Count); if (aws.Count != 0) { sw.WriteLine("NearbyStoplines"); foreach (ArbiterWaypoint aw in aws) { sw.WriteLine(aw.ToString()); } sw.WriteLine("End_NearbyStoplines"); } #region Adjacent List <string> adjacentPartitions = new List <string>(); // add current adjacentPartitions.Add(ai.ToString()); #region Initial if (icaw.InitialGeneric is ArbiterWaypoint) { // wp ArbiterWaypoint aw = (ArbiterWaypoint)icaw.InitialGeneric; // prev if (aw.PreviousPartition != null) { adjacentPartitions.Add(aw.PreviousPartition.ToString()); } // next if (aw.NextPartition != null) { adjacentPartitions.Add(aw.NextPartition.ToString()); } // exits if (aw.IsExit) { foreach (ArbiterInterconnect ais in aw.Exits) { if (!ais.Equals(ai)) { adjacentPartitions.Add(ais.ToString()); } } } if (aw.IsEntry) { foreach (ArbiterInterconnect ais in aw.Entries) { if (!ais.Equals(ai)) { adjacentPartitions.Add(ais.ToString()); } } } } else if (icaw.InitialGeneric is ArbiterPerimeterWaypoint) { adjacentPartitions.Add((new SceneZonePartition(((ArbiterPerimeterWaypoint)icaw.InitialGeneric).Perimeter.Zone)).ToString()); } #endregion #region Final if (icaw.FinalGeneric is ArbiterWaypoint) { // wp ArbiterWaypoint aw = (ArbiterWaypoint)icaw.FinalGeneric; // prev if (aw.PreviousPartition != null) { adjacentPartitions.Add(aw.PreviousPartition.ToString()); } // next if (aw.NextPartition != null) { adjacentPartitions.Add(aw.NextPartition.ToString()); } // exits if (aw.IsExit) { foreach (ArbiterInterconnect ais in aw.Exits) { adjacentPartitions.Add(ais.ToString()); } } if (aw.IsEntry) { foreach (ArbiterInterconnect ais in aw.Entries) { if (!ais.Equals(ai)) { adjacentPartitions.Add(ais.ToString()); } } } } else if (icaw.FinalGeneric is ArbiterPerimeterWaypoint) { adjacentPartitions.Add((new SceneZonePartition(((ArbiterPerimeterWaypoint)icaw.FinalGeneric).Perimeter.Zone)).ToString()); } #endregion sw.WriteLine("NumberOfLaneAdjacentPartitions" + "\t" + adjacentPartitions.Count.ToString()); if (adjacentPartitions.Count != 0) { sw.WriteLine("LaneAdjacentPartitions"); foreach (string s in adjacentPartitions) { sw.WriteLine(s); } sw.WriteLine("End_LaneAdjacentPartitions"); } #endregion sw.WriteLine("NumberOfLeftLaneAdjacentPartitions" + "\t" + "0"); sw.WriteLine("NumberOfRightLaneAdjacentPartitions" + "\t" + "0"); List <IConnectAreaWaypoints> nearby = this.GetNearbyPartitions(ai, icaws); sw.WriteLine("NumberOfNearbyPartitions" + "\t" + nearby.Count.ToString()); if (nearby.Count != 0) { sw.WriteLine("NearbyPartitions"); foreach (IConnectAreaWaypoints tmp in nearby) { sw.WriteLine(tmp.ToString()); } sw.WriteLine("End_NearbyPartitions"); } sw.WriteLine("End_Partition"); } #endregion #region Zone else if (icaw is SceneZonePartition) { SceneZonePartition szp = (SceneZonePartition)icaw; sw.WriteLine("PartitionType" + "\t" + "Zone"); sw.WriteLine("Sparse" + "\t" + "False"); sw.WriteLine("FitType" + "\t" + "Polygon"); string count = szp.Zone.Perimeter.PerimeterPoints.Count.ToString(); string wps = ""; foreach (ArbiterPerimeterWaypoint apw in szp.Zone.Perimeter.PerimeterPoints.Values) { wps = wps + "\t" + apw.Position.X.ToString("f6") + "\t" + apw.Position.Y.ToString("f6"); } sw.WriteLine("FitParameters" + "\t" + count + wps); sw.WriteLine("LeftBoundary" + "\t" + "None"); sw.WriteLine("RightBoundary" + "\t" + "None"); sw.WriteLine("NumberOfPoints" + "\t" + szp.Zone.Perimeter.PerimeterPoints.Count.ToString()); sw.WriteLine("Points"); foreach (ArbiterPerimeterWaypoint apw in szp.Zone.Perimeter.PerimeterPoints.Values) { sw.WriteLine(apw.WaypointId.ToString()); } sw.WriteLine("End_Points"); List <ArbiterWaypoint> aws = this.GetNearbyStops(szp); sw.WriteLine("NumberOfNearbyStoplines" + "\t" + aws.Count); if (aws.Count != 0) { sw.WriteLine("NearbyStoplines"); foreach (ArbiterWaypoint aw in aws) { sw.WriteLine(aw.ToString()); } sw.WriteLine("End_NearbyStoplines"); } #region Adjacent List <string> adjacentStrings = new List <string>(); // add current adjacentStrings.Add(szp.ToString()); foreach (ArbiterPerimeterWaypoint apw in szp.Zone.Perimeter.PerimeterPoints.Values) { if (apw.IsExit) { foreach (ArbiterInterconnect ai in apw.Exits) { adjacentStrings.Add(ai.ToString()); } } if (apw.IsEntry) { foreach (ArbiterInterconnect ais in apw.Entries) { adjacentStrings.Add(ais.ToString()); } } } sw.WriteLine("NumberOfLaneAdjacentPartitions" + "\t" + adjacentStrings.Count.ToString()); if (adjacentStrings.Count != 0) { sw.WriteLine("LaneAdjacentPartitions"); foreach (string s in adjacentStrings) { sw.WriteLine(s); } sw.WriteLine("End_LaneAdjacentPartitions"); } #endregion sw.WriteLine("NumberOfLeftLaneAdjacentPartitions" + "\t" + "0"); sw.WriteLine("NumberOfRightLaneAdjacentPartitions" + "\t" + "0"); List <IConnectAreaWaypoints> nearby = this.GetNearbyPartitions(szp, icaws); sw.WriteLine("NumberOfNearbyPartitions" + "\t" + nearby.Count.ToString()); if (nearby.Count != 0) { sw.WriteLine("NearbyPartitions"); foreach (IConnectAreaWaypoints tmp in nearby) { sw.WriteLine(tmp.ToString()); } sw.WriteLine("End_NearbyPartitions"); } sw.WriteLine("End_Partition"); } #endregion #region Lane else if (icaw is ArbiterLanePartition) { ArbiterLanePartition alp = (ArbiterLanePartition)icaw; sw.WriteLine("PartitionType" + "\t" + "Lane"); string sparseString = alp.Type == PartitionType.Sparse ? "True" : "False"; sw.WriteLine("Sparse" + "\t" + sparseString); if (alp.Type != PartitionType.Sparse) //alp.UserPartitions.Count <= 1) { sw.WriteLine("FitType" + "\t" + "Line"); sw.WriteLine("FitParameters" + "\t" + alp.Vector().ArcTan.ToString("F6")); } else { sw.WriteLine("FitType" + "\t" + "Polygon"); /*List<Coordinates> polyCoords = new List<Coordinates>(); * polyCoords.Add(alp.Initial.Position); * polyCoords.AddRange(alp.NotInitialPathCoords()); * LinePath lpr = (new LinePath(polyCoords)).ShiftLateral(-TahoeParams.VL * 3.0); * LinePath lpl = (new LinePath(polyCoords)).ShiftLateral(TahoeParams.VL * 3.0); * List<Coordinates> finalCoords = new List<Coordinates>(polyCoords.ToArray()); * finalCoords.AddRange(lpr); * finalCoords.AddRange(lpl); * Polygon p = Polygon.GrahamScan(finalCoords);*/ if (alp.SparsePolygon == null) { alp.SetDefaultSparsePolygon(); } string coordinateString = ""; foreach (Coordinates c in alp.SparsePolygon) { coordinateString = coordinateString + "\t" + c.X.ToString("F6") + "\t" + c.Y.ToString("F6"); } sw.WriteLine("FitParameters" + "\t" + alp.SparsePolygon.Count.ToString() + coordinateString); } sw.WriteLine("LaneWidth" + "\t" + alp.Lane.Width.ToString("F6")); sw.WriteLine("LeftBoundary" + "\t" + alp.Lane.BoundaryLeft.ToString()); sw.WriteLine("RightBoundary" + "\t" + alp.Lane.BoundaryRight.ToString()); sw.WriteLine("NumberOfPoints" + "\t" + "2"); sw.WriteLine("Points"); sw.WriteLine(alp.InitialGeneric.ToString()); sw.WriteLine(alp.FinalGeneric.ToString()); sw.WriteLine("End_Points"); List <ArbiterWaypoint> aws = this.GetNearbyStops(alp); sw.WriteLine("NumberOfNearbyStoplines" + "\t" + aws.Count); if (aws.Count != 0) { sw.WriteLine("NearbyStoplines"); foreach (ArbiterWaypoint aw in aws) { sw.WriteLine(aw.ToString()); } sw.WriteLine("End_NearbyStoplines"); } #region Adjacent List <string> adjacentPartitions = new List <string>(); // add current adjacentPartitions.Add(alp.ToString()); #region Initial if (icaw.InitialGeneric is ArbiterWaypoint) { // wp ArbiterWaypoint aw = (ArbiterWaypoint)icaw.InitialGeneric; // prev if (aw.PreviousPartition != null) { adjacentPartitions.Add(aw.PreviousPartition.ToString()); } // next if (aw.NextPartition != null && !aw.NextPartition.Equals(alp)) { adjacentPartitions.Add(aw.NextPartition.ToString()); } // exits if (aw.IsExit) { foreach (ArbiterInterconnect ais in aw.Exits) { adjacentPartitions.Add(ais.ToString()); } } if (aw.IsEntry) { foreach (ArbiterInterconnect ais in aw.Entries) { adjacentPartitions.Add(ais.ToString()); } } } #endregion #region Final if (icaw.FinalGeneric is ArbiterWaypoint) { // wp ArbiterWaypoint aw = (ArbiterWaypoint)icaw.FinalGeneric; // prev if (aw.PreviousPartition != null && !aw.PreviousPartition.Equals(alp)) { adjacentPartitions.Add(aw.PreviousPartition.ToString()); } // next if (aw.NextPartition != null) { adjacentPartitions.Add(aw.NextPartition.ToString()); } // exits if (aw.IsExit) { foreach (ArbiterInterconnect ais in aw.Exits) { adjacentPartitions.Add(ais.ToString()); } } if (aw.IsEntry) { foreach (ArbiterInterconnect ais in aw.Entries) { adjacentPartitions.Add(ais.ToString()); } } } #endregion sw.WriteLine("NumberOfLaneAdjacentPartitions" + "\t" + adjacentPartitions.Count.ToString()); if (adjacentPartitions.Count != 0) { sw.WriteLine("LaneAdjacentPartitions"); foreach (string s in adjacentPartitions) { sw.WriteLine(s); } sw.WriteLine("End_LaneAdjacentPartitions"); } #endregion List <string> leftAlps = new List <string>(); List <string> rightAlps = new List <string>(); foreach (ArbiterLanePartition tmpAlp in alp.NonLaneAdjacentPartitions) { if (tmpAlp.Lane.Equals(alp.Lane.LaneOnLeft)) { leftAlps.Add(tmpAlp.ToString()); } else { rightAlps.Add(tmpAlp.ToString()); } } sw.WriteLine("NumberOfLeftLaneAdjacentPartitions" + "\t" + leftAlps.Count.ToString()); if (leftAlps.Count != 0) { sw.WriteLine("LeftLaneAdjacentPartitions"); foreach (string s in leftAlps) { sw.WriteLine(s); } sw.WriteLine("End_LeftLaneAdjacentPartitions"); } sw.WriteLine("NumberOfRightLaneAdjacentPartitions" + "\t" + rightAlps.Count.ToString()); if (rightAlps.Count != 0) { sw.WriteLine("RightLaneAdjacentPartitions"); foreach (string s in rightAlps) { sw.WriteLine(s); } sw.WriteLine("End_RightLaneAdjacentPartitions"); } List <IConnectAreaWaypoints> nearby = this.GetNearbyPartitions(alp, icaws); sw.WriteLine("NumberOfNearbyPartitions" + "\t" + nearby.Count.ToString()); if (nearby.Count != 0) { sw.WriteLine("NearbyPartitions"); foreach (IConnectAreaWaypoints tmp in nearby) { sw.WriteLine(tmp.ToString()); } sw.WriteLine("End_NearbyPartitions"); } sw.WriteLine("End_Partition"); } #endregion } #endregion }
private void createMissionButton_Click_1(object sender, EventArgs e) { // create a new open file dialog this.saveFileDialog1 = new SaveFileDialog(); // settings for openFileDialog saveFileDialog1.InitialDirectory = "Desktop\\"; saveFileDialog1.Filter = "Mission Description File (*.mdf)|*.mdf|All files (*.*)|*.*"; saveFileDialog1.FilterIndex = 1; saveFileDialog1.RestoreDirectory = true; saveFileDialog1.FileName = this.missionNameTextBox.Text; // check if everything was selected alright if (saveFileDialog1.ShowDialog() == DialogResult.OK) { try { // switch over the final index switch (saveFileDialog1.FilterIndex) { // create an mdf case 1: // save to a file FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("MDF_name" + "\t" + this.missionNameTextBox.Text); sw.WriteLine("RNDF_name" + "\t" + this.roadNetworkNameTextBox.Text); sw.WriteLine("creation_date" + "\t" + this.creationDateTimePicker.Value.ToString()); sw.WriteLine("checkpoints"); sw.WriteLine("num_checkpoints" + "\t" + this.CreateMissionCheckpoints.Count.ToString()); foreach (object obj in this.CreateMissionCheckpoints) { string text = (string)obj; string[] delimeters = new string[] { " - " }; string[] final = text.Split(delimeters, StringSplitOptions.RemoveEmptyEntries); int goal = int.Parse(final[0]); sw.WriteLine(goal.ToString()); } sw.WriteLine("end_checkpoints"); sw.WriteLine("speed_limits"); sw.WriteLine("num_speed_limits" + "\t" + this.GetAreaNames().Count); foreach (string s in this.GetAreaNames()) { if (this.CreateMissionNonDefaultSpeeds.ContainsKey(s)) { sw.WriteLine(s + "\t" + this.CreateMissionNonDefaultSpeeds[s].MinimumSpeed.ToString("F0") + "\t" + this.CreateMissionNonDefaultSpeeds[s].MaximumSpeed.ToString("F0")); } else { sw.WriteLine(s + "\t" + this.defaultMinimumSpeedTextBox.Text + "\t" + this.defaultMaximumSpeedTextBox.Text); } } sw.WriteLine("end_speed_limits"); sw.WriteLine("end_file"); sw.Dispose(); fs.Close(); // end case break; } } catch (Exception ex) { EditorOutput.WriteLine(ex.ToString()); } } }