]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Flipped coordinate axes for network diagrams in import wizard. 55/2655/3
authorReino Ruusu <reino.ruusu@semantum.fi>
Mon, 18 Feb 2019 11:10:43 +0000 (13:10 +0200)
committerJani Simomaa <jani.simomaa@semantum.fi>
Tue, 19 Feb 2019 17:02:35 +0000 (17:02 +0000)
gitlab #3

Change-Id: I36b5f67821079d91f7f75d3dc9bda79d83149c8e

org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java

index 490c9505ecde9e459b1c9c2547d38e0e7b41278a..54a578ddac5a837d884de0d38a1ca20c4890a6ed 100644 (file)
@@ -176,6 +176,10 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                                             } else {
                                                 coords = new double[] { xCoord, yCoord };
                                             }
+                                            
+                                            // Switch to (longitude, latitude)
+                                            flipAxes(coords);
+                                            
                                             Resource vertex = DistrictNetworkUtil.createVertex(graph, model.getParentDiagram(), coords, model.getComponentMappings().get(mappingValue));
                                             
                                             writeStringValue(graph, row, idColumn, vertex, DN.HasId);
@@ -230,7 +234,11 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                                                 startCoords = new double[] { startXCoord , startYCoord };
                                                 endCoords = new double[] { endXCoord , endYCoord };
                                             }
-
+                                            
+                                            // Switch to (longitude, latitude)
+                                            flipAxes(startCoords);
+                                            flipAxes(endCoords);
+                                            
                                             Resource edge = DNEdgeBuilder.create(graph, vv, model.getParentDiagram(), model.getComponentMappings().get(mappingValue), startCoords, endCoords, padding, true);
                                             writeStringValue(graph, row, idColumn, edge, DN.HasId);
                                             
@@ -267,9 +275,15 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
             return false;
         }
     }
-    
+
+    private static void flipAxes(double[] coords) {
+       double tmp = coords[0];
+       coords[0] = coords[1];
+       coords[1] = tmp;
+    }
+
     private static void writeValue(WriteGraph graph, CSVRecord row, int index, Resource subject, Resource relation) throws DatabaseException {
-        if (index != -1) {
+       if (index != -1) {
             String stringValue = row.get(index);
             if (!stringValue.isEmpty()) {
                 try {