/// <summary> /// entfernt die TimelineGroup g /// </summary> /// <param name="g">zu entfernende TimelineGroup</param> public void RemoveGroup(TimelineGroup g) { if (g.entries.Count == 0) { g.GroupChanged -= tg_GroupChanged; _groups.Remove(g); OnGroupsChanged(); } }
private void groupComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (!isNotified && timelineControl.selectedEntry != null) { TimelineGroup newGroup = groupComboBox.SelectedItem as TimelineGroup; TimelineEntry te = timelineControl.selectedEntry; steuerung.RemoveEntry(te); te.parentGroup = newGroup; steuerung.AddEntry(te); } }
private void addGroupButton_Click(object sender, EventArgs e) { timelineControl.selectedEntry = null; TimelineGroup tg = new TimelineGroup(groupTitleEdit.Text, false); if (tg.title == "") { tg.title = "Gruppe " + (steuerung.groups.Count + 1).ToString(); } steuerung.AddGroup(tg); }
private void addTrafficLightButton_Click(object sender, EventArgs e) { TimelineGroup parentGroup = groupComboBox.SelectedItem as TimelineGroup; if (parentGroup != null) { TimelineEntry te = new TrafficLight(); te.parentGroup = parentGroup; te.name = trafficLightNameEdit.Text; if (te.name == "") { te.name = "LSA " + (parentGroup.entries.Count + 1).ToString(); } steuerung.AddEntry(te); } else { MessageBox.Show("Keine Gruppe ausgewählt!"); } }
/// <summary> /// Eventhandler beim Drücken der Maustaste /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TimelineControl_MouseDown(object sender, MouseEventArgs e) { // wurde der Zeitschieber angeklickt? if ((e.Button == MouseButtons.Left) && (Math.Abs(e.X - GetHorizontalClientPositionAtCurrentTime()) < 2)) { // Drag'n'Drop Modus setzen howToDrag = DragNDrop.MOVE_TIMELINE_BAR; } // wurde ein Plus-/Minussysmbol einer Gruppe angeklickt? else if (e.X < rowHeight && GetGroupAtClientPosition(e.Location, true) != null) { TimelineGroup tg = GetGroupAtClientPosition(e.Location, true); tg.collapsed = !tg.collapsed; } // wurde vielleicht was anderes wichtiges angeklickt? else { TimelineEntry newEntry = GetTimelineEntryAtControlPosition(e.Location); TimelineGroup newGroup = GetGroupAtClientPosition(e.Location, false); if (newEntry != m_selectedEntry || newGroup != m_selectedGroup) { m_selectedGroup = newGroup; m_selectedEntry = newEntry; OnSelectionChanged(); } // wurde ein TimelineEntry angeklickt? if (m_selectedEntry != null) { // gucken, ob es sich bei te um ein TrafficLight handelt TrafficLight tl = m_selectedEntry as TrafficLight; if (tl != null) { switch (e.Button) { case MouseButtons.Left: #region TimelineEvent hinzufügen if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { double time = GetTimeAtControlPosition(e.Location, true); // Event hinzufügen, welches die Ampel umschaltet TimelineEvent eventToAdd = new TimelineEvent(time, Math.Min(1, (m_selectedEntry.GetTimeOfNextEvent(time) - time) / 2), Color.Green, tl.SwitchToGreen, tl.SwitchToRed); m_selectedEntry.AddEvent(eventToAdd, true, false); howToDrag = DragNDrop.MOVE_EVENT_END; eventToDrag = eventToAdd; this.Cursor = Cursors.SizeWE; Invalidate(); } #endregion #region TimelineEntry selektieren else { // Drag'n'Drop für Events initialisieren TimelineEvent theEvent = GetTimelineEventAtControlPosition(e.Location, true); if (theEvent != null) { if (Math.Abs(GetClientPositionForTimelineEvent(theEvent).X - e.Location.X) < 3) { howToDrag = DragNDrop.MOVE_EVENT_START; eventToDrag = theEvent; } else if (Math.Abs(GetClientPositionForTimelineEvent(theEvent).X + theEvent.eventLength * zoom - e.Location.X) < 3) { howToDrag = DragNDrop.MOVE_EVENT_END; eventToDrag = theEvent; } else { mouseDownPosition = e.Location; eventToDragOffset = GetClientPositionForTimelineEvent(theEvent).X - e.Location.X; howToDrag = DragNDrop.MOVE_EVENT; eventToDrag = theEvent; } } } #endregion break; case MouseButtons.Right: #region TimelineEvent entfernen if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { double time = GetTimeAtControlPosition(e.Location, false); TimelineEvent eventToRemove = tl.GetEventAtTime(time); tl.RemoveEvent(eventToRemove); } #endregion break; } } } Invalidate(); } }
/// <summary> /// Erstellt ein neues SelectionChangedEventArgs /// </summary> /// <param name="tg">ausgewählte TimelineGroup</param> /// <param name="te">ausgewählte TimelineGroup</param> public SelectionChangedEventArgs(TimelineGroup tg, TimelineEntry te) { this.m_selectedGroup = tg; this.m_selectedEntry = te; }
/// <summary> /// Läd eine XML Datei und versucht daraus den gespeicherten Zustand wiederherzustellen /// </summary> /// <param name="xd">XmlDocument mit den zu ladenden Daten</param> /// <param name="nodesList">Liste von allen existierenden LineNodes</param> /// <param name="lf">LoadingForm für Statusinformationen</param> public void LoadFromFile(XmlDocument xd, List <LineNode> nodesList, LoadingForm.LoadingForm lf) { lf.SetupLowerProgess("Parsing XML...", 1); int saveVersion = 0; // erstma alles vorhandene löschen foreach (TimelineGroup tg in _groups) { foreach (TimelineEntry te in tg.entries) { // Löschen vorbereiten te.Dispose(); } tg.entries.Clear(); } _groups.Clear(); XmlNode mainNode = xd.SelectSingleNode("//CityTrafficSimulator"); XmlNode saveVersionNode = mainNode.Attributes.GetNamedItem("saveVersion"); if (saveVersionNode != null) { saveVersion = Int32.Parse(saveVersionNode.Value); } else { saveVersion = 0; } lf.StepLowerProgress(); if (saveVersion >= 4) { XmlNode xnlTrafficLights = xd.SelectSingleNode("//CityTrafficSimulator/TrafficLights"); XmlNode cycleTimeNode = xnlTrafficLights.Attributes.GetNamedItem("cycleTime"); if (cycleTimeNode != null) { maxTime = Double.Parse(cycleTimeNode.Value); } } else { maxTime = 50; } if (saveVersion >= 3) { // entsprechenden Node auswählen XmlNodeList xnlLineNode = xd.SelectNodes("//CityTrafficSimulator/TrafficLights/TimelineGroup"); Type[] extraTypes = { typeof(TrafficLight) }; foreach (XmlNode aXmlNode in xnlLineNode) { // Node in einen TextReader packen TextReader tr = new StringReader(aXmlNode.OuterXml); // und Deserializen XmlSerializer xs = new XmlSerializer(typeof(TimelineGroup), extraTypes); TimelineGroup tg = (TimelineGroup)xs.Deserialize(tr); // ab in die Liste tg.GroupChanged += new TimelineGroup.GroupChangedEventHandler(tg_GroupChanged); _groups.Add(tg); } } else { TimelineGroup unsortedGroup = new TimelineGroup("Unsorted Signals", false); // entsprechenden Node auswählen XmlNodeList xnlLineNode = xd.SelectNodes("//CityTrafficSimulator/Layout/LineNode/tLight"); foreach (XmlNode aXmlNode in xnlLineNode) { // der XMLNode darf nicht tLight heißen, sondern muss TrafficLight heißen. Das müssen wir mal anpassen: XmlDocument doc = new XmlDocument(); XmlElement elem = doc.CreateElement("TrafficLight"); elem.InnerXml = aXmlNode.InnerXml; doc.AppendChild(elem); // so, das war nicht wirklich hübsch und schnell, aber es funktioniert ;) // Node in einen TextReader packen StringReader tr = new StringReader(doc.InnerXml); // und Deserializen XmlSerializer xs = new XmlSerializer(typeof(TrafficLight)); TrafficLight tl = (TrafficLight)xs.Deserialize(tr); XmlNode pnhNode = doc.SelectSingleNode("//TrafficLight/parentNodeHash"); tl.parentNodeHash = Int32.Parse(pnhNode.InnerXml); unsortedGroup.AddEntry(tl); } // ab in die Liste _groups.Add(unsortedGroup); } lf.SetupLowerProgess("Restoring Signals...", _groups.Count); // Abschließende Arbeiten: Referenzen auflösen foreach (TimelineGroup tg in _groups) { tg.RecoverFromLoad(saveVersion, nodesList); lf.StepLowerProgress(); } OnGroupsChanged(); }
/// <summary> /// fügt der Timeline eine neue TimelineGroup hinzu /// </summary> /// <param name="tg">hinzuzufügende TimelineGroup</param> public void AddGroup(TimelineGroup tg) { tg.GroupChanged += new TimelineGroup.GroupChangedEventHandler(tg_GroupChanged); _groups.Add(tg); OnGroupsChanged(); }
/// <summary> /// Läd eine XML Datei und versucht daraus den gespeicherten Zustand wiederherzustellen /// </summary> /// <param name="xd">XmlDocument mit den zu ladenden Daten</param> /// <param name="nodesList">Liste von allen existierenden LineNodes</param> /// <param name="lf">LoadingForm für Statusinformationen</param> public void LoadFromFile(XmlDocument xd, List<LineNode> nodesList, LoadingForm.LoadingForm lf) { lf.SetupLowerProgess("Parsing XML...", 1); int saveVersion = 0; // erstma alles vorhandene löschen foreach (TimelineGroup tg in _groups) { foreach (TimelineEntry te in tg.entries) { // Löschen vorbereiten te.Dispose(); } tg.entries.Clear(); } _groups.Clear(); XmlNode mainNode = xd.SelectSingleNode("//CityTrafficSimulator"); XmlNode saveVersionNode = mainNode.Attributes.GetNamedItem("saveVersion"); if (saveVersionNode != null) saveVersion = Int32.Parse(saveVersionNode.Value); else saveVersion = 0; lf.StepLowerProgress(); if (saveVersion >= 4) { XmlNode xnlTrafficLights = xd.SelectSingleNode("//CityTrafficSimulator/TrafficLights"); XmlNode cycleTimeNode = xnlTrafficLights.Attributes.GetNamedItem("cycleTime"); if (cycleTimeNode != null) maxTime = Double.Parse(cycleTimeNode.Value); } else { maxTime = 50; } if (saveVersion >= 3) { // entsprechenden Node auswählen XmlNodeList xnlLineNode = xd.SelectNodes("//CityTrafficSimulator/TrafficLights/TimelineGroup"); Type[] extraTypes = { typeof(TrafficLight) }; foreach (XmlNode aXmlNode in xnlLineNode) { // Node in einen TextReader packen TextReader tr = new StringReader(aXmlNode.OuterXml); // und Deserializen XmlSerializer xs = new XmlSerializer(typeof(TimelineGroup), extraTypes); TimelineGroup tg = (TimelineGroup)xs.Deserialize(tr); // ab in die Liste tg.GroupChanged += new TimelineGroup.GroupChangedEventHandler(tg_GroupChanged); _groups.Add(tg); } } else { TimelineGroup unsortedGroup = new TimelineGroup("Unsorted Signals", false); // entsprechenden Node auswählen XmlNodeList xnlLineNode = xd.SelectNodes("//CityTrafficSimulator/Layout/LineNode/tLight"); foreach (XmlNode aXmlNode in xnlLineNode) { // der XMLNode darf nicht tLight heißen, sondern muss TrafficLight heißen. Das müssen wir mal anpassen: XmlDocument doc = new XmlDocument(); XmlElement elem = doc.CreateElement("TrafficLight"); elem.InnerXml = aXmlNode.InnerXml; doc.AppendChild(elem); // so, das war nicht wirklich hübsch und schnell, aber es funktioniert ;) // Node in einen TextReader packen StringReader tr = new StringReader(doc.InnerXml); // und Deserializen XmlSerializer xs = new XmlSerializer(typeof(TrafficLight)); TrafficLight tl = (TrafficLight)xs.Deserialize(tr); XmlNode pnhNode = doc.SelectSingleNode("//TrafficLight/parentNodeHash"); tl.parentNodeHash = Int32.Parse(pnhNode.InnerXml); unsortedGroup.AddEntry(tl); } // ab in die Liste _groups.Add(unsortedGroup); } lf.SetupLowerProgess("Restoring Signals...", _groups.Count); // Abschließende Arbeiten: Referenzen auflösen foreach (TimelineGroup tg in _groups) { tg.RecoverFromLoad(saveVersion, nodesList); lf.StepLowerProgress(); } OnGroupsChanged(); }