/// <summary> /// Constructor /// </summary> /// <param name="trackViewer">Trackviewer so we can perform a callback</param> /// <param name="searchItem">Type of item that needs to be searched</param> public SearchControl(TrackViewer trackViewer, SearchableItem searchItem) { InitializeComponent(); this.trackViewer = trackViewer; this.searchItem = searchItem; textboxIndex.Focus(); this.Top = trackViewer.Window.ClientBounds.Top + 20; this.Left = trackViewer.Window.ClientBounds.Left + 0; switch (searchItem) { case SearchableItem.TrackNode: labelType.Content = "trackNode index = "; break; case SearchableItem.TrackItem: labelType.Content = "trackItem index = "; break; case SearchableItem.TrackNodeRoad: labelType.Content = "road trackNode index = "; break; case SearchableItem.TrackItemRoad: labelType.Content = "road trackItem index = "; break; } }
/// <summary> /// Add information from terrain /// </summary> /// <param name="trackViewer"></param> private void AddTerrainStatus(TrackViewer trackViewer) { if (Properties.Settings.Default.statusShowTerrain && (trackViewer.drawTerrain != null)) { statusAdditional.Text += trackViewer.drawTerrain.StatusInformation; } }
/// <summary> /// Popup a dialog to enable to user to edit the path meta data /// </summary> /// <param name="popupX">The screen x-location of where the popup needs to be placed</param> /// <param name="popupY">The screen y-location of where the popup needs to be placed</param> public void EditMetaData(int popupX, int popupY) { string[] metadata = { CurrentTrainPath.PathId, CurrentTrainPath.PathName, CurrentTrainPath.PathStart, CurrentTrainPath.PathEnd }; bool isPlayerPath = (CurrentTrainPath.PathFlags & PathFlags.NotPlayerPath) == 0; PathMetadataDialog metadataDialog = new PathMetadataDialog(metadata, isPlayerPath) { Left = popupX, Top = popupY }; TrackViewer.Localize(metadataDialog); if (metadataDialog.ShowDialog() == true) { metadata = metadataDialog.GetMetadata(); CurrentTrainPath.PathId = metadata[0]; CurrentTrainPath.PathName = metadata[1]; CurrentTrainPath.PathStart = metadata[2]; CurrentTrainPath.PathEnd = metadata[3]; isPlayerPath = (metadata[4] == true.ToString()); if (isPlayerPath) { CurrentTrainPath.PathFlags &= ~PathFlags.NotPlayerPath; // unset the nonplayerpath flag } else { CurrentTrainPath.PathFlags |= PathFlags.NotPlayerPath; // set the nonplayerpath flag } } }
/// <summary> /// Set the status of the closest trackItem (junction or other item) /// </summary> /// <param name="trackViewer"></param> private void SetTrackItemStatus(TrackViewer trackViewer) { // Track items: clear first statusTrItemType.Text = statusTrItemIndex.Text = statusTrItemLocationX.Text = statusTrItemLocationZ.Text = string.Empty; ORTS.TrackViewer.Drawing.CloseToMouseItem closestItem = trackViewer.DrawTrackDB.ClosestTrackItem; ORTS.TrackViewer.Drawing.CloseToMouseJunctionOrEnd closestJunction = trackViewer.DrawTrackDB.ClosestJunctionOrEnd; ORTS.TrackViewer.Drawing.CloseToMousePoint closestPoint; if (closestItem != null && closestItem.IsCloserThan(closestJunction)) { closestPoint = closestItem; } else if (closestJunction.JunctionOrEndNode != null) { closestPoint = closestJunction; } else { closestPoint = null; } if (closestPoint != null) { statusTrItemType.Text = closestPoint.Description; statusTrItemIndex.Text = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} ", closestPoint.Index); statusTrItemLocationX.Text = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0,3:F3} ", closestPoint.X); statusTrItemLocationZ.Text = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0,3:F3} ", closestPoint.Z); AddSignalStatus(trackViewer, closestPoint.Description, closestPoint.Index); } }
private void menuSearchTrackItemRoad_Click(object sender, RoutedEventArgs e) { SearchControl searchControl = new SearchControl(trackViewer, SearchableItem.TrackItemRoad); TrackViewer.Localize(searchControl); searchControl.ShowDialog(); }
/// <summary> /// Constructor /// </summary> public DrawPathChart() { chartWindow = new PathChartWindow { OnJsonSaveClick = OnJsonSave }; TrackViewer.Localize(chartWindow); }
/// <summary> /// Add the FPS to the statusbar (Frames Per Second) /// </summary> private void AddFPS(TrackViewer trackViewer) { if (Properties.Settings.Default.statusShowFPS) { statusAdditional.Text += string.Format(System.Globalization.CultureInfo.CurrentCulture, " FPS={0:F1} ", trackViewer.FrameRate.SmoothedValue); } }
/// <summary> /// Call this when adding a new label /// </summary> /// <param name="mouseX">Current X-location of the mouse to determine popup location</param> /// <param name="mouseY">Current Y-location of the mouse to determine popu location</param> internal void AddLabel(int mouseX, int mouseY) { var labelInputPopup = new EditLabel("<label>", mouseX, mouseY, (newLabelText) => labels.Add(drawArea.MouseLocation, newLabelText), allowDelete: false); TrackViewer.Localize(labelInputPopup); labelInputPopup.ShowDialog(); }
/// <summary> /// Add information from signal /// </summary> /// <param name="trackViewer"></param> private void AddSignalStatus(TrackViewer trackViewer, string description, uint index) { if (Properties.Settings.Default.statusShowSignal) { if (String.Equals(description, "signal")) { statusAdditional.Text += "signal shape = "; statusAdditional.Text += trackViewer.RouteData.GetSignalFilename(index); } } }
/// <summary> /// Add information from Trainpaths /// </summary> /// <param name="trackViewer"></param> private void AddTrainpathStatus(TrackViewer trackViewer) { if (Properties.Settings.Default.statusShowTrainpath && (trackViewer.PathEditor != null)) { if (trackViewer.PathEditor.HasValidPath) { //gather some info on path status List <string> statusItems = new List <string>(); if (trackViewer.PathEditor.HasEndingPath) { statusItems.Add("good end"); } if (trackViewer.PathEditor.HasBrokenPath) { statusItems.Add("broken"); } if (trackViewer.PathEditor.HasModifiedPath) { statusItems.Add("modified"); } if (trackViewer.PathEditor.HasStoredTail) { statusItems.Add("stored tail"); } string pathStatus = String.Join(", ", statusItems.ToArray()); ORTS.TrackViewer.Editing.TrainpathNode curNode = trackViewer.PathEditor.CurrentNode; statusAdditional.Text += string.Format(System.Globalization.CultureInfo.CurrentCulture, " {0} ({4}): TVNs=[{1} {2}] (type={3})", trackViewer.PathEditor.FileName, curNode.NextMainTvnIndex, curNode.NextSidingTvnIndex, curNode.NodeType, pathStatus); if (curNode.IsBroken) { statusAdditional.Text += string.Format(System.Globalization.CultureInfo.CurrentCulture, " Broken: {0} ", curNode.BrokenStatusString()); } TrainpathVectorNode curVectorNode = curNode as TrainpathVectorNode; if (curVectorNode != null && curNode.NodeType == TrainpathNodeType.Stop) { statusAdditional.Text += string.Format(System.Globalization.CultureInfo.CurrentCulture, " (wait-time={0}s)", curVectorNode.WaitTimeS); } } else { statusAdditional.Text += "Invalid path"; } } }
/// <summary> /// Add information of the basic MSTS PATfile /// </summary> /// <param name="trackViewer"></param> private void AddPATfileStatus(TrackViewer trackViewer) { if (Properties.Settings.Default.statusShowPATfile && (trackViewer.DrawPATfile != null)) { TrPathNode curNode = trackViewer.DrawPATfile.CurrentNode; TrackPDP curPDP = trackViewer.DrawPATfile.CurrentPdp; statusAdditional.Text += string.Format(System.Globalization.CultureInfo.CurrentCulture, " {7}: {3}, {4} [{1} {2}] [{5} {6}] <{0}>", curNode.pathFlags, (int)curNode.nextMainNode, (int)curNode.nextSidingNode, curPDP.X, curPDP.Z, curPDP.junctionFlag, curPDP.invalidFlag, trackViewer.DrawPATfile.FileName); } }
/// <summary> /// Constructor for the statusbar /// </summary> /// <param name="trackViewer">Track viewer object that contains all the information we want to show the status for</param> public StatusBarControl(TrackViewer trackViewer) { InitializeComponent(); StatusbarHeight = (int)tvStatusbar.Height; //ElementHost object helps us to connect a WPF User Control. elementHost = new ElementHost { Location = new System.Drawing.Point(0, 0), TabIndex = 1, Child = this }; System.Windows.Forms.Control.FromHandle(trackViewer.Window.Handle).Controls.Add(elementHost); }
/// <summary> /// Update the various elements in the statusbar /// </summary> /// <param name="trackViewer">trackViewer object that contains all relevant data</param> /// <param name="mouseLocation">The Worldlocation of the mouse pointer</param> public void Update(TrackViewer trackViewer, WorldLocation mouseLocation) { ResetAdditionalText(); SetMouseLocationStatus(mouseLocation); SetTrackIndexStatus(trackViewer); SetTrackItemStatus(trackViewer); AddFPS(trackViewer); AddVectorSectionStatus(trackViewer); AddPATfileStatus(trackViewer); AddTrainpathStatus(trackViewer); AddTerrainStatus(trackViewer); }
/// <summary> /// Update the status of the track index /// </summary> /// <param name="trackViewer"></param> private void SetTrackIndexStatus(TrackViewer trackViewer) { Drawing.CloseToMouseTrack closestTrack = trackViewer.DrawTrackDB.ClosestTrack; if (closestTrack == null) { return; } TrackNode tn = closestTrack.TrackNode; if (tn == null) { return; } statusTrIndex.Text = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} ", tn.Index); //debug: statusAdditional.Text += Math.Sqrt((double)trackViewer.drawTrackDB.closestTrack.ClosestMouseDistanceSquared); }
/// <summary> /// constructor /// </summary> /// <param name="trackViewer">The trackviewer object we need for callbacks</param> public MenuControl(TrackViewer trackViewer) { this.trackViewer = trackViewer; InitializeComponent(); MenuHeight = (int)menuMain.Height; //ElementHost object helps us to connect a WPF User Control. elementHost = new ElementHost(); elementHost.Location = new System.Drawing.Point(0, 0); //elementHost.Name = "elementHost"; elementHost.TabIndex = 1; //elementHost.Text = "elementHost"; elementHost.Child = this; System.Windows.Forms.Control.FromHandle(trackViewer.Window.Handle).Controls.Add(elementHost); InitUserSettings(); }
/// <summary> /// Add information about the closest vector section /// </summary> /// <param name="trackViewer"></param> private void AddVectorSectionStatus(TrackViewer trackViewer) { if (Properties.Settings.Default.statusShowVectorSections) { TrVectorSection tvs = trackViewer.DrawTrackDB.ClosestTrack.VectorSection; if (tvs == null) { return; } uint shapeIndex = tvs.ShapeIndex; string shapeName = "Unknown:" + shapeIndex.ToString(System.Globalization.CultureInfo.CurrentCulture); try { // Try to find a fixed track TrackShape shape = trackViewer.RouteData.TsectionDat.TrackShapes.Get(shapeIndex); shapeName = shape.FileName; } catch { // try to find a dynamic track try { TrackPath trackPath = trackViewer.RouteData.TsectionDat.TSectionIdx.TrackPaths[tvs.ShapeIndex]; shapeName = "<dynamic ?>"; foreach (uint trackSection in trackPath.TrackSections) { if (trackSection == tvs.SectionIndex) { shapeName = "<dynamic>"; } // For some reason I do not undestand the (route) section.tdb. trackpaths are not consistent tracksections // so this foreach loop will not always find a combination } } catch { } } statusAdditional.Text += string.Format(System.Globalization.CultureInfo.CurrentCulture, " VectorSection ({3}/{4}) filename={2} Index={0} shapeIndex={1}", tvs.SectionIndex, shapeIndex, shapeName, trackViewer.DrawTrackDB.ClosestTrack.TrackVectorSectionIndex + 1, trackViewer.DrawTrackDB.ClosestTrack.TrackNode.TrVectorNode.TrVectorSections.Count()); } }
private void Open() { if (!checkSave()) { return; } OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Supported files|*.gcode; *.ptf|gcode file (*.gcode)|*.gcode|Petri Task File (*.ptf)|*.ptf"; if (openFileDialog.ShowDialog() != true) { return; } filePath = openFileDialog.FileName; if (System.IO.Path.GetExtension(filePath).Contains("ptf")) { var task = IOTools.Open <PetriTask>(filePath); Code = task.Code; Task = task; TaskPath = filePath; } else { var r = new GCodeReader(openFileDialog.FileName); Code = r.Code; } RowList = new ObservableCollection <IGCode>(); renderList(); if (PositionChanged != null) { PositionChanged(0); } viewer = new TrackViewer(Code); viewer.AddPoint += CodeAddPoint; viewer.RemovePoint += CodeRemovePoint; viewer.Show(); isChanged = true; UpdateObjSize(); }
/// <summary> /// Callback that is called when the user clicks on the menuitem connected to a new label /// </summary> /// <param name="oldLabel">The old label that needs to be replaced</param> /// <param name="mouseX">Current X-location of the mouse to determine popup location</param> /// <param name="mouseY">Current Y-location of the mouse to determine popu location</param> private void ModifyLabel(StorableLabel oldLabel, int mouseX, int mouseY) { var labelInputPopup = new EditLabel(oldLabel.LabelText, mouseX, mouseY, (newLabelText) => { if (newLabelText == null) { labels.Delete(oldLabel); } else { var newLabel = new StorableLabel(oldLabel.WorldLocation, newLabelText); labels.Replace(oldLabel, newLabel); } }, allowDelete: true); TrackViewer.Localize(labelInputPopup); labelInputPopup.ShowDialog(); }
/// <summary> /// Add information from platform and station name /// </summary> /// <param name="trackViewer">The trackviewer we need to find the trackDB</param> /// <param name="description">The description of the item we might want to show, needed to make sure it is a proper item</param> /// <param name="index">The index of the item to show</param> private void AddNamesStatus(TrackViewer trackViewer, string description, uint index) { if (!Properties.Settings.Default.statusShowNames) { return; } if (!String.Equals(description, "platform")) { return; } TrItem item = trackViewer.RouteData.TrackDB.TrItemTable[index]; PlatformItem platform = item as PlatformItem; if (platform == null) { return; } statusAdditional.Text += string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} ({1})", platform.Station, platform.ItemName); }
private void menuShowOtherPaths_Click(object sender, RoutedEventArgs e) { otherPathsWindow = new OtherPathsWindow(trackViewer.DrawMultiplePaths); TrackViewer.Localize(otherPathsWindow); otherPathsWindow.Show(); }
/// <summary> /// Update the various elements in the statusbar /// </summary> /// <param name="trackViewer">trackViewer object that contains all relevant data</param> /// <param name="mouseLocation">The Worldlocation of the mouse pointer</param> public void Update(TrackViewer trackViewer, in WorldLocation mouseLocation)