Skip to content

Commit 277624f

Browse files
committed
Little Changes on the Update Plot behaviour.
First implemenation for GeometryParameter transform
1 parent 37e638a commit 277624f

File tree

4 files changed

+68
-22
lines changed

4 files changed

+68
-22
lines changed

TRA.Lib/Trasse.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void AssignGRA(GRATrasse GRATrasse)
9393
/// <summary>
9494
/// Estimate coordinates of slopechanges(NW) of the GRA_Data. If a TrasseS is set, a projection to TrasseS is applied.
9595
/// </summary>
96-
void CalcGradientCoordinates()
96+
public void CalcGradientCoordinates()
9797
{
9898
if (GradientenElemente == null) return;
9999
foreach (GradientElementExt gradientElement in GradientenElemente)
@@ -147,7 +147,7 @@ internal TrassenElementExt GetTrassenElementFromS(double s)
147147
/// </summary>
148148
/// <param name="X">X coordinate of Point of Interest</param>
149149
/// <param name="Y">Y coordinate of Point of Interest</param>
150-
/// <returns></returns>
150+
/// <returns>returns Element[0] if point is behind first element</returns>
151151
internal TrassenElementExt GetElementFromPoint(double X, double Y)
152152
{
153153
foreach (TrassenElementExt element in Elemente.Reverse())
@@ -156,7 +156,7 @@ internal TrassenElementExt GetElementFromPoint(double X, double Y)
156156
Vector2 v2 = new Vector2((float)(X - element.Xstart), (float)(Y - element.Ystart));
157157
if (Vector2.Dot(v1, v2) > 0) { return element; }
158158
}
159-
return null;
159+
return Elemente[0];
160160
}
161161
/// <summary>
162162
/// Interpolate 2D Points allog the Trasse
@@ -511,13 +511,13 @@ public void Plot()
511511
Plot2D.Plot.Axes.Link(PlotG, true, false);
512512
PlotG.Plot.Axes.Link(Plot2D, true, false);
513513

514-
gridView.Rows.Clear();
514+
gridView.Rows.Clear();
515+
PlotT.Plot.Clear();
516+
PlotG.Plot.Clear();
515517
//Remove previous Plottables from Plots
516518
foreach (IPlottable plottable in Plottables)
517519
{
518520
Plot2D.Plot.Remove(plottable);
519-
PlotT.Plot.Remove(plottable);
520-
PlotG.Plot.Remove(plottable);
521521
}
522522

523523
foreach (TrassenElementExt element in Elemente)
@@ -530,11 +530,9 @@ public void Plot()
530530
ElementMarker marker = new(element, color);
531531
Plottables.Add(Plot2D.Plot.Add.Plottable(marker));
532532
var scatterT = PlotT.Plot.Add.Scatter(interpolation.Y, interpolation.T, color);
533-
Plottables.Add(scatterT);
534533
//scatterT.LegendText = "Heading";
535534
Plottables.Add(PlotT.Plot.Add.VerticalLine(element.Ystart, 2, color));
536535
var scatterK = PlotT.Plot.Add.ScatterLine(interpolation.Y, interpolation.K, color);
537-
Plottables.Add(scatterK);
538536
//scatterK.LegendText = "Curvature";
539537
// tell each T and K plot to use a different axis
540538
scatterT.Axes.YAxis = PlotT.Plot.Axes.Left;
@@ -543,11 +541,9 @@ public void Plot()
543541
if (interpolation.H != null && interpolation.s != null)
544542
{
545543
var scatterH = PlotG.Plot.Add.Scatter(interpolation.Y, interpolation.H, color);
546-
Plottables.Add(scatterH);
547544
//scatterH.LegendText = "Elevation";
548545
scatterH.Axes.YAxis = PlotG.Plot.Axes.Left;
549546
var scatterSlope = PlotG.Plot.Add.ScatterLine(interpolation.Y, interpolation.s, color);
550-
Plottables.Add(scatterSlope);
551547
//scatterSlope.LegendText = "Slope";
552548
scatterSlope.Axes.YAxis = PlotG.Plot.Axes.Right;
553549
}
@@ -573,7 +569,6 @@ public void Plot()
573569
{
574570
if (element.Y == double.NaN) continue;
575571
var vline = PlotG.Plot.Add.VerticalLine(element.Y);
576-
Plottables.Add(vline);
577572
vline.Text = " NW " + element.Pkt.ToString() + " " + element.H.ToString() + "m";
578573
vline.LabelRotation = -90;
579574
vline.ManualLabelAlignment = Alignment.UpperLeft;
@@ -590,6 +585,8 @@ public void Plot()
590585
Plot2D.Plot.Axes.SquareUnits();
591586
Plot2D.Plot.HideLegend();
592587
Plot2D.Refresh();
588+
PlotT.Refresh();
589+
PlotG.Refresh();
593590
if (!Form.Visible) Form.Show();// ShowDialog();
594591
Form.Update();
595592
}
@@ -636,6 +633,7 @@ private void Warning_CollectionChanged(object sender, NotifyCollectionChangedEve
636633
case NotifyCollectionChangedAction.Reset:
637634
break;
638635
}
636+
Plot2D.Refresh();
639637
}
640638
private void CheckProjections_CheckedChanged(object sender, EventArgs e)
641639
{

TRA.Lib/TrassenElementExt.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public class TrassenElementExt : TrassenElement
135135
/// <value>Hochwert am Elementanfang</value>
136136
public TrassenElementExt Successor { get { return successor; } }
137137
/// <value>Returns Interpolationresult</value>
138-
public Interpolation InterpolationResult { get { return Interpolation; } }
138+
public Interpolation InterpolationResult { get { return Interpolation; }}
139139

140140
/// <value>List of Warnings/ Callouts to show on Plot if compiled with SCOTTPLOT</value>
141141
//public GeometryWarning[] GetWarnings { get { return WarningCallouts.ToArray(); } }
@@ -179,13 +179,33 @@ public TrassenElementExt(double r1, double r2, double y, double x, double t, dou
179179
break;
180180
}
181181
}
182-
public void Relocate(double x, double y, double t = double.NaN)
182+
183+
public void Relocate(double x, double y, double deltaGamma = double.NaN, double deltaK_start = double.NaN, double deltaK_end = double.NaN)
183184
{
184185
this.x = x;
185186
this.y = y;
186-
if (!double.IsNaN(t))
187+
if (!double.IsNaN(deltaGamma))
188+
{
189+
t = t - deltaGamma;
190+
}
191+
if (!double.IsNaN(deltaK_start))
187192
{
188-
this.t = t;
193+
// TODO decide if we need to change the length and if yes, do we want to update the stationvalues s
194+
l = l; //* (deltaK_start + deltaK_end) / 2;
195+
if (Double.IsNaN(deltaK_end)) { deltaK_end = deltaK_start; }
196+
switch (this.TrassenGeometrie)
197+
{
198+
case Gerade:
199+
break;
200+
case Kreis:
201+
r1 = r1 * (deltaK_start + deltaK_end) / 2;
202+
r2 = r1;
203+
break;
204+
case Klothoid:
205+
r1 = r1 * deltaK_start;
206+
r2 = r2 * deltaK_end;
207+
break;
208+
}
189209
}
190210
PlausibilityCheck();
191211
}
@@ -247,7 +267,7 @@ public ref Interpolation Interpolate(double delta = 1.0, double allowedTolerance
247267
{
248268
Transform2D transform = new Transform2D(x, y, t);
249269
if (TrassenGeometrie == null) { AddWarningCallout("No Gemetry for interpolation " + kz.ToString() + "set, maybe not implemented yet", Xstart,Ystart); return ref Interpolation; }
250-
270+
if (Double.IsNaN(l)) { AddWarningCallout("Length is NaN, no interpolation calculated", Xstart, Ystart); return ref Interpolation; }
251271
List<double> Xlst = new List<double>();
252272
List<double> Ylst = new List<double>();
253273
List<double> Slst = new List<double>();

TRA.Tool/TRA.Tool.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30+
<Reference Include="egbt22lib">
31+
<HintPath>..\..\egbt22trans\egbt22trans\bin\Debug\net6.0\egbt22lib.dll</HintPath>
32+
</Reference>
3033
<Reference Include="LowDistortionProjection">
3134
<HintPath>..\..\LowDistortionProjection\LowDistortionProjection\bin\Debug\netstandard2.1\LowDistortionProjection.dll</HintPath>
3235
</Reference>

TRA.Tool/TransformPanel.cs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ private void TransformPanel_MouseDown(object sender, MouseEventArgs e)
3333
DoDragDrop(this, DragDropEffects.Move);
3434
}
3535

36+
private static double DegreesToRadians(double degrees)
37+
{
38+
return degrees * (Math.PI / 180.0);
39+
}
40+
3641
private void btn_Transform_Click(object sender, EventArgs e)
3742
{
3843
SpatialReference SRS_Target;
@@ -70,17 +75,28 @@ private void btn_Transform_Click(object sender, EventArgs e)
7075
if(panel.trasseL != null ) { elements = elements.Concat(panel.trasseL.Elemente); }
7176
if (panel.trasseS != null) { elements = elements.Concat(panel.trasseS.Elemente); }
7277
if (panel.trasseR != null) { elements = elements.Concat(panel.trasseR.Elemente); }
73-
foreach (TrassenElementExt element in elements.Reverse()) //run reverse for having X/Yend from the successor is already transformed for plasability checks
78+
double previousdK = double.NaN;
79+
foreach (TrassenElementExt element in elements.Reverse()) //run reverse for having X/Yend from the successor is already transformed for plausability checks
7480
{
7581
//Transform Interpolation Points
7682
Interpolation interp = element.InterpolationResult;
7783
double elementHeight = interp.H != null ? interp.H[0] : double.NaN; //save original height befor transforming
78-
if (interp.X.Length > 0)
84+
// TODO how to handle trasse without heights (like S) in transformations
85+
if (interp.H == null) { interp.H = new double[interp.X.Length]; }
86+
if (interp.X.Length > 0 && interp.H != null)
7987
{
8088
try
8189
{
8290
double[][] points = { interp.Y, interp.X, interp.H };
83-
Srs.ConvertInPlace(ref points, SRS_Source, SRS_Target);
91+
//Srs.ConvertInPlace(ref points, SRS_Source, SRS_Target);
92+
egbt22lib.Convert.DBRef_GK5_to_EGBT22_Local(points[0], points[1], points[2],out points[0], out points[1]);
93+
//Workaround to set values in place
94+
for (int i = 0; i < interp.X.Length; i++)
95+
{
96+
interp.X[i] = points[1][i];
97+
interp.Y[i] = points[0][i];
98+
interp.H[i] = points[2][i];
99+
}
84100
}
85101
catch {
86102
}
@@ -90,9 +106,16 @@ private void btn_Transform_Click(object sender, EventArgs e)
90106
{
91107
double[][] coordinate = !Double.IsNaN(elementHeight) ?
92108
new double[][] { new double[] { element.Ystart }, new double[] { element.Xstart }, new double[] { elementHeight } }
93-
: new double[][]{ new double[] { element.Ystart }, new double[] { element.Xstart } };
94-
Srs.ConvertInPlace(ref coordinate, SRS_Source, SRS_Target);
95-
element.Relocate(coordinate[1][0], coordinate[0][0]);
109+
: new double[][]{ new double[] { element.Ystart }, new double[] { element.Xstart }, new double[] { 0.0 } };
110+
//Srs.ConvertInPlace(ref coordinate, SRS_Source, SRS_Target);
111+
double[] gamma_i, k_i,gamma_o,k_o;
112+
egbt22lib.Convert.DBRef_GK5_Gamma_k(coordinate[0], coordinate[1], out gamma_i, out k_i);
113+
egbt22lib.Convert.DBRef_GK5_to_EGBT22_Local(coordinate[0], coordinate[1],coordinate[2],out coordinate[0], out coordinate[1]);
114+
egbt22lib.Convert.EGBT22_Local_Gamma_k(coordinate[0], coordinate[1], out gamma_o, out k_o);
115+
double dK = (k_i[0] / k_o[0]);
116+
117+
element.Relocate(coordinate[1][0], coordinate[0][0], DegreesToRadians(gamma_o[0] - gamma_i[0]), dK,previousdK);
118+
previousdK = element.ID == 0 ? double.NaN : dK; //reset prviousScale for next Element
96119
}
97120
catch {
98121
}
@@ -106,6 +129,7 @@ private void btn_Transform_Click(object sender, EventArgs e)
106129
string ownerString = panel.trasseL.Filename + "_" + element.ID;
107130
TrassierungLog.Logger?.LogInformation(ownerString + " " + "Deviation to geometry after transform: " + deviation);
108131
}
132+
panel.trasseL.CalcGradientCoordinates();
109133
panel.trasseL.Plot();
110134
}
111135
if (panel.trasseS != null) {
@@ -126,6 +150,7 @@ private void btn_Transform_Click(object sender, EventArgs e)
126150
string ownerString = panel.trasseR.Filename + "_" + element.ID;
127151
TrassierungLog.Logger?.LogInformation(ownerString + " " + "Deviation to geometry after transform: " + deviation);
128152
}
153+
panel.trasseR.CalcGradientCoordinates();
129154
panel.trasseR.Plot();
130155
}
131156
}

0 commit comments

Comments
 (0)