Skip to content

Commit a5be129

Browse files
Merge pull request #1153 from rwf-rr/fix-tritems-in-track-viewer
Fix TrItems in track viewer (events were over-writing mileposts)
2 parents 9357ae7 + d2f2a02 commit a5be129

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

Source/Contrib/TrackViewer/Drawing/DrawTrackDB.cs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -107,37 +107,14 @@ public RouteData(string routePath, MessageDelegate messageDelegate)
107107
//sigcfgFile = null; // default initialization
108108
}
109109

110-
// read the activity location events and store them in the TrackDB.TrItemTable
110+
// read the activity location events and add them to the TrackDB.TrItemTable
111111

112112
ActivityNames.Clear();
113113
var directory = System.IO.Path.Combine(routePath, "ACTIVITIES");
114114
if (System.IO.Directory.Exists(directory))
115115
{
116-
// counting
117-
int cnt = 0;
118-
119-
foreach (var file in Directory.GetFiles(directory, "*.act"))
120-
{
121-
try
122-
{
123-
var activityFile = new ActivityFile(file);
124-
Events events = activityFile.Tr_Activity.Tr_Activity_File.Events;
125-
if (events != null)
126-
{
127-
for (int i = 0; i < events.EventList.Count; i++)
128-
{
129-
if (events.EventList[i].GetType() == typeof(EventCategoryLocation))
130-
{
131-
cnt++;
132-
}
133-
}
134-
}
135-
}
136-
catch { }
137-
}
138-
139-
// adding
140-
uint index = 0;
116+
int index = TrackDB.TrItemTable.Length;
117+
List<TrItem> eventItems = new List<TrItem>();
141118
foreach (var file in Directory.GetFiles(directory, "*.act"))
142119
{
143120
try
@@ -157,8 +134,8 @@ public RouteData(string routePath, MessageDelegate messageDelegate)
157134
eventCategoryLocation.Outcomes.DisplayMessage,
158135
eventCategoryLocation.TileX, eventCategoryLocation.TileZ,
159136
eventCategoryLocation.X, 0, eventCategoryLocation.Z,
160-
index);
161-
TrackDB.TrItemTable[index] = eventItem;
137+
(uint)index);
138+
eventItems.Add(eventItem);
162139
index++;
163140
found = true;
164141
}
@@ -168,9 +145,18 @@ public RouteData(string routePath, MessageDelegate messageDelegate)
168145
ActivityNames.Add(activityFile.Tr_Activity.Tr_Activity_Header.Name);
169146
}
170147
}
171-
catch { }
148+
catch { /* just ignore activity files with problems */ }
172149
}
173150

151+
// extend the track items array and append the event items
152+
if (eventItems.Count > 0)
153+
{
154+
int oldSize = TrackDB.TrItemTable.Length;
155+
Array.Resize<TrItem>(ref TrackDB.TrItemTable, index);
156+
int newSize = TrackDB.TrItemTable.Length;
157+
int eventSize = eventItems.Count;
158+
for (int toIdx = oldSize, fromIdx = 0; toIdx < newSize && fromIdx < eventSize; toIdx++, fromIdx++) { TrackDB.TrItemTable[toIdx] = eventItems[fromIdx]; }
159+
}
174160
}
175161
}
176162

Source/Contrib/TrackViewer/Editing/Charts/DrawPathChart.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public class DrawPathChart
5454

5555
private bool ChartWindowIsOpen { get { return chartWindow.Visibility == Visibility.Visible; } }
5656

57+
// save window title from properies, so that the window's title can be changed when the selected path is changed
58+
private readonly String WindowTitle;
59+
5760
/// <summary>
5861
/// Constructor
5962
/// </summary>
@@ -64,6 +67,7 @@ public DrawPathChart()
6467
OnJsonSaveClick = OnJsonSave
6568
};
6669
TrackViewer.Localize(chartWindow);
70+
if (WindowTitle == null) WindowTitle = chartWindow.Title;
6771
}
6872

6973
/// <summary>
@@ -113,6 +117,7 @@ public void Open()
113117
{ // it path is broken, OnPathChanged performed a close
114118
return;
115119
}
120+
chartWindow.Title = String.Format("{0}: {1}", WindowTitle, pathEditor.CurrentTrainPath.PathName);
116121
chartWindow.Show();
117122

118123
}
@@ -160,6 +165,7 @@ private void OnPathChanged()
160165
return;
161166
}
162167
pathData.Update(trainpath);
168+
chartWindow.Title = String.Format("{0}: {1}", WindowTitle, pathEditor.CurrentTrainPath.PathName);
163169
chartWindow.Draw();
164170
}
165171

0 commit comments

Comments
 (0)