14
14
import edu .ie3 .datamodel .models .input .connector .Transformer2WInput ;
15
15
import edu .ie3 .datamodel .models .input .container .GridContainer ;
16
16
import edu .ie3 .datamodel .models .input .container .JointGridContainer ;
17
- import edu .ie3 .datamodel .models .input .container .RawGridElements ;
18
17
import edu .ie3 .datamodel .models .input .container .SubGridContainer ;
19
18
import edu .ie3 .datamodel .models .input .system .LoadInput ;
20
19
import edu .ie3 .datamodel .models .input .system .PvInput ;
21
20
import edu .ie3 .datamodel .models .input .system .StorageInput ;
22
21
import edu .ie3 .datamodel .models .input .system .SystemParticipantInput ;
23
22
import edu .ie3 .datamodel .utils .ContainerUtils ;
24
- import edu .ie3 .datamodel .utils .GridAndGeoUtils ;
25
23
import edu .ie3 .netpad .grid .GridModel ;
26
24
import edu .ie3 .netpad .grid .GridModification ;
27
25
import edu .ie3 .netpad .grid .ModifiedSubGridData ;
31
29
import edu .ie3 .netpad .io .event .ReadGridEvent ;
32
30
import edu .ie3 .netpad .io .event .SaveGridEvent ;
33
31
import edu .ie3 .netpad .map .event .MapEvent ;
34
- import edu .ie3 .netpad .tool .LineLengthResolutionMode ;
35
32
import edu .ie3 .netpad .tool .controller .ToolController ;
36
- import edu .ie3 .netpad .tool .controller .ToolDialogs ;
37
33
import edu .ie3 .netpad .tool .event .FixLineLengthRequestEvent ;
38
34
import edu .ie3 .netpad .tool .event .LayoutGridRequestEvent ;
39
35
import edu .ie3 .netpad .tool .event .LayoutGridResponse ;
40
36
import edu .ie3 .netpad .tool .event .ToolEvent ;
41
- import edu .ie3 .util .geo .GeoUtils ;
37
+ import edu .ie3 .netpad .tool .grid .LineLengthFixer ;
38
+ import edu .ie3 .netpad .tool .grid .LineLengthResolutionMode ;
42
39
import java .util .*;
43
40
import java .util .stream .Collectors ;
44
41
import java .util .stream .Stream ;
45
42
import javafx .beans .property .ObjectProperty ;
46
43
import javafx .beans .property .SimpleObjectProperty ;
47
44
import javafx .beans .value .ChangeListener ;
48
- import javax .measure .quantity .Length ;
49
- import org .locationtech .jts .geom .Coordinate ;
50
- import org .locationtech .jts .geom .LineString ;
51
45
import org .slf4j .Logger ;
52
46
import org .slf4j .LoggerFactory ;
53
- import tech .units .indriya .ComparableQuantity ;
54
47
55
48
/**
56
49
* //ToDo: Class Description
@@ -221,7 +214,8 @@ private ChangeListener<ToolEvent> toolEventListener() {
221
214
FixLineLengthRequestEvent event = (FixLineLengthRequestEvent ) newValue ;
222
215
LineLengthResolutionMode resolutionMode = event .getResolutionMode ();
223
216
Set <Integer > selectedSubnets = event .getSelectedSubnets ();
224
- fixLineLength (resolutionMode , selectedSubnets );
217
+ LineLengthFixer .execute (resolutionMode , selectedSubnets , subGrids )
218
+ .ifPresent (this ::handleReadGridEvent );
225
219
} else {
226
220
throw new RuntimeException ("Invalid GridContainer provided!" );
227
221
}
@@ -231,131 +225,6 @@ private ChangeListener<ToolEvent> toolEventListener() {
231
225
};
232
226
}
233
227
234
- /**
235
- * Fix the line length discrepancy based on the user given {@link ToolDialogs.FixLineLengthData}
236
- *
237
- * @param resolutionMode Selected resolution mode
238
- * @param selectedSubnets Subnets to apply adjustments to
239
- */
240
- public void fixLineLength (LineLengthResolutionMode resolutionMode , Set <Integer > selectedSubnets ) {
241
- JointGridContainer updatedGrid ;
242
-
243
- /* Act depending on the chosen resolution mode */
244
- switch (resolutionMode ) {
245
- case GEOGRAPHICAL :
246
- updatedGrid = setElectricalToGeographicalLineLength (selectedSubnets );
247
- break ;
248
- case ELECTRICAL :
249
- /* TODO CK: Figure out, what to do here */
250
- default :
251
- log .error ("Unknown resolution mode '{}'" , resolutionMode );
252
- return ;
253
- }
254
-
255
- /* Build a new event and inform the listeners about the "new" / adapted grid model */
256
- handleReadGridEvent (new ReadGridEvent (updatedGrid ));
257
- }
258
-
259
- /**
260
- * Sets the electrical length of all lines within the selected sub nets to the length of their
261
- * geographical line string if apparent. If not, it is set to the geographical distance between
262
- * start and end node.
263
- *
264
- * @param selectedSubnets Subnets to apply adjustments to
265
- * @return A {@link JointGridContainer} with updated line models
266
- */
267
- private JointGridContainer setElectricalToGeographicalLineLength (Set <Integer > selectedSubnets ) {
268
- /* Adjust the electrical line length to be the same as the geographical distance */
269
- List <SubGridContainer > subGridContainers =
270
- subGrids .values ().parallelStream ()
271
- .map (GridModel ::getSubGridContainer )
272
- .map (
273
- subGridContainer -> {
274
- if (!selectedSubnets .contains (subGridContainer .getSubnet ())) {
275
- /* If this grid isn't selected, hand it back, as it is */
276
- return subGridContainer ;
277
- } else {
278
- /* Update all lines */
279
- Set <LineInput > lines =
280
- subGridContainer .getRawGrid ().getLines ().parallelStream ()
281
- .map (GridController ::setLineLengthToGeographicDistance )
282
- .collect (Collectors .toSet ());
283
-
284
- /* Put together, what has been there before */
285
- RawGridElements rawGrid =
286
- new RawGridElements (
287
- subGridContainer .getRawGrid ().getNodes (),
288
- lines ,
289
- subGridContainer .getRawGrid ().getTransformer2Ws (),
290
- subGridContainer .getRawGrid ().getTransformer3Ws (),
291
- subGridContainer .getRawGrid ().getSwitches (),
292
- subGridContainer .getRawGrid ().getMeasurementUnits ());
293
- return new SubGridContainer (
294
- subGridContainer .getGridName (),
295
- subGridContainer .getSubnet (),
296
- rawGrid ,
297
- subGridContainer .getSystemParticipants (),
298
- subGridContainer .getGraphics ());
299
- }
300
- })
301
- .collect (Collectors .toList ());
302
-
303
- /* Assemble all sub grids to one container */
304
- return ContainerUtils .combineToJointGrid (subGridContainers );
305
- }
306
-
307
- /**
308
- * Adjusts the line length to the length of their geographical line string if apparent. If not, it
309
- * is set to the geographical distance between start and end node.
310
- *
311
- * @param line line model to adjust
312
- * @return The adjusted line model
313
- * @deprecated This method should be transferred to PowerSystemDataModel
314
- */
315
- @ Deprecated
316
- private static LineInput setLineLengthToGeographicDistance (LineInput line ) {
317
- ComparableQuantity <Length > lineLength ;
318
- lineLength =
319
- lengthOfLineString (line .getGeoPosition ())
320
- .orElseGet (
321
- () -> {
322
- log .warn (
323
- "Cannot determine the length of the line string of line '{}' as it only contains one coordinate."
324
- + " Take distance between it's nodes instead." ,
325
- line );
326
- return GridAndGeoUtils .distanceBetweenNodes (line .getNodeA (), line .getNodeB ());
327
- });
328
- return line .copy ().length (lineLength ).build ();
329
- }
330
-
331
- /**
332
- * Calculate the length of a line string
333
- *
334
- * @param lineString The line string to calculate the length of
335
- * @return An option to the length, if it can be determined
336
- * @deprecated This method should be transferred to PowerSystemUtils
337
- */
338
- @ Deprecated
339
- private static Optional <ComparableQuantity <Length >> lengthOfLineString (LineString lineString ) {
340
- Coordinate [] coordinates = lineString .getCoordinates ();
341
-
342
- if (coordinates .length == 1 ) {
343
- return Optional .empty ();
344
- }
345
-
346
- /* Go over the line piecewise and sum up the distance */
347
- Coordinate a = coordinates [0 ];
348
- Coordinate b = coordinates [1 ];
349
- ComparableQuantity <Length > length = GeoUtils .calcHaversine (a .x , a .y , b .x , b .y );
350
- for (int coordIndex = 2 ; coordIndex < coordinates .length ; coordIndex ++) {
351
- a = b ;
352
- b = coordinates [coordIndex ];
353
- length = length .add (GeoUtils .calcHaversine (a .x , a .y , b .x , b .y ));
354
- }
355
-
356
- return Optional .of (length );
357
- }
358
-
359
228
private ChangeListener <IOEvent > ioEventListener () {
360
229
return (observable , oldValue , newValue ) -> {
361
230
if (newValue instanceof ReadGridEvent ) {
0 commit comments