4
4
using System . Globalization ;
5
5
using System . Numerics ;
6
6
using System . Runtime . CompilerServices ;
7
+ using System . Collections . Specialized ;
8
+
7
9
#if USE_SCOTTPLOT
10
+ using ScottPlot . Plottables ;
11
+ using OpenTK . Platform . Windows ;
8
12
using ScottPlot ;
9
13
using SkiaSharp ;
10
14
#endif
@@ -188,18 +192,7 @@ public Interpolation Interpolate3D(TRATrasse stationierungsTrasse = null, double
188
192
double s ;
189
193
if ( trasseS != null ) //If TrasseS is set, try projecting coordinate to trasseS, s = NaN if fails
190
194
{
191
- TrassenElementExt stationierungsElement = trasseS . GetElementFromPoint ( Interpolation . X [ i ] , Interpolation . Y [ i ] ) ;
192
- s = ( stationierungsElement != null ? stationierungsElement . GetSAtPoint ( Interpolation . X [ i ] , Interpolation . Y [ i ] ) : double . NaN ) ;
193
- if ( Double . IsNaN ( s ) ) { Interpolation . H [ i ] = double . NaN ; continue ; }
194
- #if USE_SCOTTPLOT
195
- //Visualisation
196
- if ( stationierungsElement != null )
197
- {
198
- double X_ , Y_ ;
199
- ( X_ , Y_ , _ ) = stationierungsElement . GetPointAtS ( s ) ;
200
- element . projections . Add ( new ProjectionArrow ( new Coordinates ( Interpolation . Y [ i ] , Interpolation . X [ i ] ) , new Coordinates ( Y_ , X_ ) ) ) ;
201
- }
202
- #endif
195
+ ( s , _ , _ , _ ) = trasseS . ProjectPoints ( Interpolation . X [ i ] , Interpolation . Y [ i ] , element . projections ) ;
203
196
}
204
197
else //if no trasseS provided use original value S
205
198
{
@@ -212,6 +205,50 @@ public Interpolation Interpolate3D(TRATrasse stationierungsTrasse = null, double
212
205
}
213
206
return interp ;
214
207
}
208
+ /// <summary>
209
+ /// Project an Array of X,Y coordinates on elements geoemtry
210
+ /// </summary>
211
+ /// <param name="X">array of X-coordinates</param>
212
+ /// <param name="Y">array of Y-coordinates</param>
213
+ /// <returns>mean deviation(distance) from point to geometry</returns>
214
+ public float ProjectPoints ( double [ ] X , double [ ] Y )
215
+ {
216
+ int num = Math . Min ( X . Length , Y . Length ) ;
217
+ float deviation = 0 ;
218
+ double dist = 0 ;
219
+ for ( int i = 0 ; i < num ; i ++ )
220
+ {
221
+ ( _ , dist , _ , _ ) = ProjectPoints ( X [ i ] , Y [ i ] ) ;
222
+ deviation += ( float ) dist ;
223
+ }
224
+ return deviation / num ;
225
+ }
226
+ /// <summary>
227
+ /// Projecting a Point on this trasse
228
+ /// </summary>
229
+ /// <param name="X">X-Coordinate</param>
230
+ /// <param name="Y">Y-Coordinate</param>
231
+ /// <returns>s(Milage),distance,X-Coordinate of the projection,Y-Coordinate of the projection</returns>
232
+ internal ( double , double , double , double ) ProjectPoints ( double X , double Y , List < ProjectionArrow > projections = null )
233
+ {
234
+ TrassenElementExt element = GetElementFromPoint ( X , Y ) ;
235
+ double s = ( element != null ? element . GetSAtPoint ( X , Y ) : double . NaN ) ;
236
+ double X_ , Y_ ;
237
+ if ( element != null && ! Double . IsNaN ( s ) )
238
+ {
239
+ ( X_ , Y_ , _ ) = element . GetPointAtS ( s ) ;
240
+ #if USE_SCOTTPLOT
241
+ if ( projections == null )
242
+ {
243
+ projections = element . projections ;
244
+ }
245
+ projections . Add ( new ProjectionArrow ( new Coordinates ( Y , X ) , new Coordinates ( Y_ , X_ ) ) ) ;
246
+ #endif
247
+ return ( s , Math . Sqrt ( Math . Pow ( X - X_ , 2 ) + Math . Pow ( Y - Y_ , 2 ) ) , X_ , Y_ ) ;
248
+ }
249
+ return ( double . NaN , double . NaN , double . NaN , double . NaN ) ;
250
+
251
+ }
215
252
216
253
public void SaveCSV ( StreamWriter outputFile )
217
254
{
@@ -248,6 +285,8 @@ public void SaveCSV(StreamWriter outputFile)
248
285
static Form Form ;
249
286
/// <value>Plot for a 2D overview of all plotted trassen</value>
250
287
static ScottPlot . WinForms . FormsPlot Plot2D ;
288
+ /// <value>List of all Plottables of this element</value>
289
+ List < IPlottable > Plottables = new ( ) ;
251
290
/// <value>Callout for right-click selected Coordinate and s-projection</value>
252
291
static ScottPlot . Plottables . Callout selectedS ;
253
292
/// <value>Plot for TRA-Details heading and hurvature </value>
@@ -459,19 +498,30 @@ public void Plot()
459
498
Plot2D . Plot . Axes . Link ( PlotG , true , false ) ;
460
499
PlotG . Plot . Axes . Link ( Plot2D , true , false ) ;
461
500
501
+ gridView . Rows . Clear ( ) ;
502
+ //Remove previous Plottables from Plots
503
+ foreach ( IPlottable plottable in Plottables )
504
+ {
505
+ Plot2D . Plot . Remove ( plottable ) ;
506
+ PlotT . Plot . Remove ( plottable ) ;
507
+ PlotG . Plot . Remove ( plottable ) ;
508
+ }
509
+
462
510
foreach ( TrassenElementExt element in Elemente )
463
511
{
464
512
Interpolation interpolation = element . InterpolationResult ;
465
513
var scatter = Plot2D . Plot . Add . Scatter ( interpolation . Y , interpolation . X ) ;
514
+ Plottables . Add ( scatter ) ;
466
515
scatter . LegendText = Filename ;
467
516
ScottPlot . Color color = scatter . MarkerFillColor ;
468
517
ElementMarker marker = new ( element , color ) ;
469
- Plot2D . Plot . Add . Plottable ( marker ) ;
470
-
518
+ Plottables . Add ( Plot2D . Plot . Add . Plottable ( marker ) ) ;
471
519
var scatterT = PlotT . Plot . Add . Scatter ( interpolation . Y , interpolation . T , color ) ;
520
+ Plottables . Add ( scatterT ) ;
472
521
//scatterT.LegendText = "Heading";
473
- PlotT . Plot . Add . VerticalLine ( element . Ystart , 2 , color ) ;
522
+ Plottables . Add ( PlotT . Plot . Add . VerticalLine ( element . Ystart , 2 , color ) ) ;
474
523
var scatterK = PlotT . Plot . Add . ScatterLine ( interpolation . Y , interpolation . K , color ) ;
524
+ Plottables . Add ( scatterK ) ;
475
525
//scatterK.LegendText = "Curvature";
476
526
// tell each T and K plot to use a different axis
477
527
scatterT . Axes . YAxis = PlotT . Plot . Axes . Left ;
@@ -480,25 +530,28 @@ public void Plot()
480
530
if ( interpolation . H != null && interpolation . s != null )
481
531
{
482
532
var scatterH = PlotG . Plot . Add . Scatter ( interpolation . Y , interpolation . H , color ) ;
533
+ Plottables . Add ( scatterH ) ;
483
534
//scatterH.LegendText = "Elevation";
484
535
scatterH . Axes . YAxis = PlotG . Plot . Axes . Left ;
485
536
var scatterSlope = PlotG . Plot . Add . ScatterLine ( interpolation . Y , interpolation . s , color ) ;
537
+ Plottables . Add ( scatterSlope ) ;
486
538
//scatterSlope.LegendText = "Slope";
487
539
scatterSlope . Axes . YAxis = PlotG . Plot . Axes . Right ;
488
540
}
489
541
490
542
//Raw Data to GridView
491
543
gridView . Rows . Add ( element . ID , element . R1 , element . R2 , element . Ystart , element . Xstart , element . T , element . S , element . KzString , element . L , element . U1 , element . U2 , element . C ) ;
492
544
//Warnings
493
- foreach ( var warning in element . GetWarnings )
545
+ element . WarningCallouts . CollectionChanged += Warning_CollectionChanged ;
546
+ foreach ( var warning in element . WarningCallouts )
494
547
{
495
548
Plot2D . Plot . Add . Plottable ( warning ) ;
496
549
}
497
550
//Visualize Projections
498
551
foreach ( ProjectionArrow projection in element . projections )
499
552
{
500
553
projection . IsVisible = false ;
501
- Plot2D . Plot . Add . Plottable ( projection ) ;
554
+ Plottables . Add ( Plot2D . Plot . Add . Plottable ( projection ) ) ;
502
555
}
503
556
}
504
557
if ( GradientenElemente != null )
@@ -507,6 +560,7 @@ public void Plot()
507
560
{
508
561
if ( element . Y == double . NaN ) continue ;
509
562
var vline = PlotG . Plot . Add . VerticalLine ( element . Y ) ;
563
+ Plottables . Add ( vline ) ;
510
564
vline . Text = " NW " + element . Pkt . ToString ( ) + " " + element . H . ToString ( ) + "m" ;
511
565
vline . LabelRotation = - 90 ;
512
566
vline . ManualLabelAlignment = Alignment . UpperLeft ;
@@ -516,7 +570,7 @@ public void Plot()
516
570
}
517
571
else
518
572
{
519
- PlotG . Plot . Add . Annotation ( "No Gradient Data available" ) ;
573
+ Plottables . Add ( PlotG . Plot . Add . Annotation ( "No Gradient Data available" ) ) ;
520
574
}
521
575
522
576
// Set the axis scale to be equal
@@ -527,6 +581,49 @@ public void Plot()
527
581
Form . Update ( ) ;
528
582
}
529
583
584
+ public void UpdatePlot ( )
585
+ {
586
+ if ( gridView != null )
587
+ {
588
+ gridView . Rows . Clear ( ) ;
589
+ foreach ( TrassenElementExt element in Elemente )
590
+ {
591
+ gridView . Rows . Add ( element . ID , element . R1 , element . R2 , element . Ystart , element . Xstart , element . T , element . S , element . KzString , element . L , element . U1 , element . U2 , element . C ) ;
592
+ }
593
+ }
594
+
595
+ }
596
+ private void Warning_CollectionChanged ( object sender , NotifyCollectionChangedEventArgs e )
597
+ {
598
+ switch ( e . Action )
599
+ {
600
+ case NotifyCollectionChangedAction . Add :
601
+ foreach ( var item in e . NewItems )
602
+ {
603
+ Plot2D . Plot . Add . Plottable ( item as GeometryWarning ) ;
604
+ }
605
+ break ;
606
+ case NotifyCollectionChangedAction . Remove :
607
+ foreach ( var item in e . OldItems )
608
+ {
609
+ Plot2D . Plot . Remove ( item as GeometryWarning ) ;
610
+ }
611
+ break ;
612
+ case NotifyCollectionChangedAction . Replace :
613
+ int i = 0 ;
614
+ foreach ( var item in e . OldItems )
615
+ {
616
+ Plot2D . Plot . Remove ( item as GeometryWarning ) ;
617
+ Plot2D . Plot . Add . Plottable ( e . NewItems [ i ] as GeometryWarning ) ;
618
+ i ++ ;
619
+ }
620
+ break ;
621
+ case NotifyCollectionChangedAction . Move :
622
+ break ;
623
+ case NotifyCollectionChangedAction . Reset :
624
+ break ;
625
+ }
626
+ }
530
627
private void CheckProjections_CheckedChanged ( object sender , EventArgs e )
531
628
{
532
629
CheckBox box = ( CheckBox ) sender ;
@@ -559,7 +656,7 @@ private void CheckShowWarnings_CheckedChanged(object sender, EventArgs e)
559
656
}
560
657
Plot2D . Refresh ( ) ;
561
658
}
562
-
659
+
563
660
private void Plot2D_MouseClick ( object sender , MouseEventArgs e )
564
661
{
565
662
if ( e . Button == MouseButtons . Left && Control . ModifierKeys . HasFlag ( Keys . Control ) )
0 commit comments