Skip to content

Commit 5c427fb

Browse files
committed
Improve utility of verbose logging, expand capabilities of automatic friction calculation
1 parent a5ff181 commit 5c427fb

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

Source/Orts.Common/Conversions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public static class NpM
260260
/// <summary>
261261
/// Resistance conversions from and to Newtons/metre/sec
262262
/// </summary>
263-
public static class NpMpS
263+
public static class NSpM
264264
{
265265
}
266266

@@ -576,8 +576,12 @@ public static class FormatStrings
576576
public static string f = Catalog.GetString("°F");
577577
public static string n = Catalog.GetString("N");
578578
public static string kN = Catalog.GetString("kN");
579+
public static string nspm = Catalog.GetString("N/m/s");
580+
public static string nsspmm = Catalog.GetString("N/(m/s)²");
579581
public static string lbf = Catalog.GetString("lbf");
580582
public static string klbf = Catalog.GetString("klbf");
583+
public static string lbfpmph = Catalog.GetString("lbf/mph");
584+
public static string lbfpmph2 = Catalog.GetString("lbf/mph²");
581585
public static string deg = Catalog.GetString("°");
582586

583587
/// <summary>

Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public enum WindowState
120120

121121
// wag file data
122122
public string MainShapeFileName;
123+
public string WagonName;
123124
public string FreightShapeFileName;
124125
public float FreightAnimMaxLevelM;
125126
public float FreightAnimMinLevelM;
@@ -395,6 +396,9 @@ public virtual void LoadFromWagFile(string wagFilePath)
395396
if (File.Exists(orFile))
396397
wagFilePath = orFile;
397398

399+
// Get the path starting at the TRAINS folder, in order to produce a shorter, more legible, path
400+
string shortPath = wagFilePath.Remove(0, Simulator.BasePath.Length);
401+
398402
using (STFReader stf = new STFReader(wagFilePath, true))
399403
{
400404
while (!stf.Eof)
@@ -407,41 +411,41 @@ public virtual void LoadFromWagFile(string wagFilePath)
407411
var wagonFolderSlash = Path.GetDirectoryName(WagFilePath) + @"\";
408412
if (MainShapeFileName != null && !File.Exists(wagonFolderSlash + MainShapeFileName))
409413
{
410-
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + MainShapeFileName);
414+
Trace.TraceWarning("{0} references non-existent shape {1}", shortPath, wagonFolderSlash + MainShapeFileName);
411415
MainShapeFileName = string.Empty;
412416
}
413417
if (FreightShapeFileName != null && !File.Exists(wagonFolderSlash + FreightShapeFileName))
414418
{
415-
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + FreightShapeFileName);
419+
Trace.TraceWarning("{0} references non-existent shape {1}", shortPath, wagonFolderSlash + FreightShapeFileName);
416420
FreightShapeFileName = null;
417421
}
418422
if (InteriorShapeFileName != null && !File.Exists(wagonFolderSlash + InteriorShapeFileName))
419423
{
420-
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + InteriorShapeFileName);
424+
Trace.TraceWarning("{0} references non-existent shape {1}", shortPath, wagonFolderSlash + InteriorShapeFileName);
421425
InteriorShapeFileName = null;
422426
}
423427

424428
if (FrontCoupler.Closed.ShapeFileName != null && !File.Exists(wagonFolderSlash + FrontCoupler.Closed.ShapeFileName))
425429
{
426-
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + FrontCoupler.Closed.ShapeFileName);
430+
Trace.TraceWarning("{0} references non-existent shape {1}", shortPath, wagonFolderSlash + FrontCoupler.Closed.ShapeFileName);
427431
FrontCoupler.Closed.ShapeFileName = null;
428432
}
429433

430434
if (RearCoupler.Closed.ShapeFileName != null && !File.Exists(wagonFolderSlash + RearCoupler.Closed.ShapeFileName))
431435
{
432-
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + RearCoupler.Closed.ShapeFileName);
436+
Trace.TraceWarning("{0} references non-existent shape {1}", shortPath, wagonFolderSlash + RearCoupler.Closed.ShapeFileName);
433437
RearCoupler.Closed.ShapeFileName = null;
434438
}
435439

436440
if (FrontAirHose.Connected.ShapeFileName != null && !File.Exists(wagonFolderSlash + FrontAirHose.Connected.ShapeFileName))
437441
{
438-
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + FrontAirHose.Connected.ShapeFileName);
442+
Trace.TraceWarning("{0} references non-existent shape {1}", shortPath, wagonFolderSlash + FrontAirHose.Connected.ShapeFileName);
439443
FrontAirHose.Connected.ShapeFileName = null;
440444
}
441445

442446
if (RearAirHose.Connected.ShapeFileName != null && !File.Exists(wagonFolderSlash + RearAirHose.Connected.ShapeFileName))
443447
{
444-
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + RearAirHose.Connected.ShapeFileName);
448+
Trace.TraceWarning("{0} references non-existent shape {1}", shortPath, wagonFolderSlash + RearAirHose.Connected.ShapeFileName);
445449
RearAirHose.Connected.ShapeFileName = null;
446450
}
447451

@@ -539,15 +543,49 @@ public virtual void LoadFromWagFile(string wagFilePath)
539543
CarWidthM = Math.Max((maxes.X - mins.X) + AutoWidthOffsetM, 0.1f);
540544
CarHeightM = Math.Max((maxes.Y - mins.Y) + AutoHeightOffsetM, 0.1f);
541545
CarLengthM = Math.Max((maxes.Z - mins.Z) + AutoLengthOffsetM, 0.1f);
546+
547+
if (Simulator.Settings.VerboseConfigurationMessages)
548+
{
549+
Trace.TraceInformation("Rolling stock {0} size automatically calculated using ORTSAutoSize ( {1}, {2}, {3} ).", shortPath,
550+
FormatStrings.FormatVeryShortDistanceDisplay(AutoWidthOffsetM, IsMetric),
551+
FormatStrings.FormatVeryShortDistanceDisplay(AutoHeightOffsetM, IsMetric),
552+
FormatStrings.FormatVeryShortDistanceDisplay(AutoLengthOffsetM, IsMetric));
553+
Trace.TraceInformation("Main shape file {0} calculated to be {1} wide, {2} tall, and {3} long. " +
554+
"Resulting Size ( ) is {4} wide, {5} tall, and {6} long.\n", MainShapeFileName,
555+
FormatStrings.FormatVeryShortDistanceDisplay((maxes.X - mins.X), IsMetric),
556+
FormatStrings.FormatVeryShortDistanceDisplay((maxes.Y - mins.Y), IsMetric),
557+
FormatStrings.FormatVeryShortDistanceDisplay((maxes.Z - mins.Z), IsMetric),
558+
FormatStrings.FormatVeryShortDistanceDisplay(CarWidthM, IsMetric),
559+
FormatStrings.FormatVeryShortDistanceDisplay(CarHeightM, IsMetric),
560+
FormatStrings.FormatVeryShortDistanceDisplay(CarLengthM, IsMetric));
561+
}
542562
}
543563

544564
// Automatically determine the center of gravity offset required to perfectly center the shape (lengthwise)
545565
if (AutoCenter)
566+
{
546567
InitialCentreOfGravityM.Z = (maxes.Z + mins.Z) / 2.0f;
568+
569+
if (Simulator.Settings.VerboseConfigurationMessages)
570+
{
571+
Trace.TraceInformation("Rolling stock {0} CoG z-value automatically calculated using ORTSAutoCenter.", shortPath);
572+
if (Math.Abs(InitialCentreOfGravityM.Z) < 0.0001f)
573+
Trace.TraceInformation("Main shape file {0} bounds calculated to be {1} to {2}. Shape is already centered, CoG offset reset to zero.\n",
574+
MainShapeFileName,
575+
FormatStrings.FormatVeryShortDistanceDisplay(mins.Z, IsMetric),
576+
FormatStrings.FormatVeryShortDistanceDisplay(maxes.Z, IsMetric));
577+
else
578+
Trace.TraceInformation("Main shape file {0} bounds calculated to be {1} to {2}. CoG offset used to center shape is {0}.\n",
579+
MainShapeFileName,
580+
FormatStrings.FormatVeryShortDistanceDisplay(mins.Z, IsMetric),
581+
FormatStrings.FormatVeryShortDistanceDisplay(maxes.Z, IsMetric),
582+
FormatStrings.FormatVeryShortDistanceDisplay(InitialCentreOfGravityM.Z, IsMetric));
583+
}
584+
}
547585
}
548586
catch
549587
{
550-
Trace.TraceWarning("Could not automatically determine size of shape {0} in wagon {1}, there may be an error in the shape.", MainShapeFileName, wagFilePath);
588+
Trace.TraceWarning("Could not automatically determine size of shape {0} in wagon {1}, there may be an error in the shape.", MainShapeFileName, shortPath);
551589
}
552590
}
553591

@@ -608,7 +646,7 @@ public virtual void LoadFromWagFile(string wagFilePath)
608646

609647
if (Simulator.Settings.VerboseConfigurationMessages)
610648
{
611-
Trace.TraceInformation("Derailment Coefficient set to false for Wagon {0}", WagFilePath);
649+
Trace.TraceInformation("Derailment Coefficient set to false for Wagon {0}", shortPath);
612650
}
613651
}
614652

@@ -626,7 +664,7 @@ public virtual void LoadFromWagFile(string wagFilePath)
626664

627665
if (Simulator.Settings.VerboseConfigurationMessages)
628666
{
629-
Trace.TraceInformation("Number of Wagon Axles set to default value of {0} on Wagon {1}", WagonNumAxles, WagFilePath);
667+
Trace.TraceInformation("Number of Wagon Axles set to default value of {0} on Wagon {1}", WagonNumAxles, shortPath);
630668
}
631669
}
632670
else
@@ -763,7 +801,7 @@ public virtual void LoadFromWagFile(string wagFilePath)
763801
{
764802
if (ortsFreightAnim.ShapeFileName != null && !File.Exists(wagonFolderSlash + ortsFreightAnim.ShapeFileName))
765803
{
766-
Trace.TraceWarning("ORTS FreightAnim in trainset {0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + ortsFreightAnim.ShapeFileName);
804+
Trace.TraceWarning("ORTS FreightAnim in trainset {0} references non-existent shape {1}", file, wagonFolderSlash + ortsFreightAnim.ShapeFileName);
767805
ortsFreightAnim.ShapeFileName = null;
768806
}
769807

@@ -1277,6 +1315,7 @@ public virtual void Parse(string lowercasetoken, STFReader stf)
12771315
STFException.TraceWarning(stf, "Skipped unknown wagon type " + wagonType);
12781316
}
12791317
break;
1318+
case "wagon(name": WagonName = stf.ReadStringBlock(null); break;
12801319
case "wagon(ortswagonspecialtype":
12811320
stf.MustMatch("(");
12821321
var wagonspecialType = stf.ReadString();

0 commit comments

Comments
 (0)