private int valvePositionIndx = -1;
private int addressIndex;
private int lengthIndex;
+ private int detailedGeometryIndex;
// Third page
public void setLengthIndex(int lengthIndex) {
this.lengthIndex = lengthIndex;
}
+
+ public void detailedGeometryIndex(int detailedGeometryIndex) {
+ this.detailedGeometryIndex = detailedGeometryIndex;
+ }
+
+ public int getDetailedGeometryIndex() {
+ return detailedGeometryIndex;
+ }
}
int kReturnIndex = model.getkReturnIndex();
int kSupplyIndex = model.getkSupplyIndex();
int lengthIndex = model.getLengthIndex();
+ int detailedGeometryIndex = model.getDetailedGeometryIndex();
int mappingColumn = model.getComponentMappingIndex();
int idColumn = model.getIdIndex();
writeValue(graph, row, kSupplyIndex, edge, DN.Edge_HasKSupply);
writeValue(graph, row, edgeFlowAreaIndex, edge, DN.Edge_HasFlowArea);
writeValue(graph, row, lengthIndex, edge, DN.Edge_HasLength);
+ writeDoubleArrayFromString(graph, row, detailedGeometryIndex, edge, DN.Edge_HasGeometry, actualTransform);
}
} catch (MismatchedDimensionException | TransformException | DatabaseException e) {
throw new DatabaseException(e);
}
}
}
+
+ private static void writeDoubleArrayFromString(WriteGraph graph, CSVRecord row, int index, Resource subject, Resource relation, MathTransform actualTransform) throws DatabaseException, MismatchedDimensionException, TransformException {
+ if (index != -1) {
+ String stringValue = row.get(index);
+ if (!stringValue.isEmpty()) {
+ stringValue = stringValue.substring(1, stringValue.length() - 1);
+ String[] coordPairs = stringValue.split(";");
+ ArrayList<Double> dd = new ArrayList<>(coordPairs.length * 2);
+ for (int i = 0; i < coordPairs.length; i++) {
+ String coordPair = coordPairs[i];
+ String[] p = coordPair.split(" ");
+ double x = Double.parseDouble(p[0]);
+ double y = Double.parseDouble(p[1]);
+ if (actualTransform != null) {
+ DirectPosition2D targetPos = new DirectPosition2D();
+ DirectPosition2D sourcePos = new DirectPosition2D(y, x);
+ DirectPosition res = actualTransform.transform(sourcePos, targetPos);
+ double[] coords = res.getCoordinate();
+ x = coords[1];
+ y = coords[0];
+ }
+ dd.add(x);
+ dd.add(y);
+ }
+ double[] detailedGeometryCoords = new double[dd.size()];
+ for (int i = 0; i < dd.size(); i++) {
+ double d = dd.get(i);
+ detailedGeometryCoords[i] = d;
+ }
+ try {
+ graph.claimLiteral(subject, relation, detailedGeometryCoords, Bindings.DOUBLE_ARRAY);
+ } catch (NumberFormatException e) {
+ throw new DatabaseException(e);
+ }
+ }
+ }
+ }
}
private DynamicComboFieldEditor endXCoordSelector;
private DynamicComboFieldEditor endYCoordSelector;
private DynamicComboFieldEditor endZValueSelector;
+ private DynamicComboFieldEditor detailedGeometrySelector;
private Text edgeConnectionPadding;
validatePageComplete();
}
});
+ detailedGeometrySelector = new DynamicComboFieldEditor("detailedGeometryValue", "Geometry", parent);
+ detailedGeometrySelector.addComboListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ widgetDefaultSelected(e);
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ model.detailedGeometryIndex(Integer.parseInt(detailedGeometrySelector.getValue()));
+ validatePageComplete();
+ }
+ });
diameterSelector = new DynamicComboFieldEditor("diameterValue", "Diameter value", parent);
diameterSelector.addComboListener(new SelectionListener() {
endYCoordSelector.updateCombo(namesAndValues);
startZValueSelector.updateCombo(namesAndValues);
endZValueSelector.updateCombo(namesAndValues);
+ detailedGeometrySelector.updateCombo(namesAndValues);
diameterSelector.updateCombo(namesAndValues);
outerDiameterSelector.updateCombo(namesAndValues);
nominalMassFlowSelector.updateCombo(namesAndValues);
>-- DN.Edge.HasLength
@defProperty "Length" L0.Double
L0.readOnly true
+ >-- DN.Edge.HasGeometry
+ @defProperty "Detailed Geometry" L0.DoubleArray
>-- DN.Edge.HasDiameter
@defProperty "Diameter" L0.Double
>-- DN.Edge.HasOuterDiameter
public final Resource Edge_HasElevation_Inverse;
public final Resource Edge_HasFlowArea;
public final Resource Edge_HasFlowArea_Inverse;
+ public final Resource Edge_HasGeometry;
+ public final Resource Edge_HasGeometry_Inverse;
public final Resource Edge_HasKReturn;
public final Resource Edge_HasKReturn_Inverse;
public final Resource Edge_HasKSupply;
public static final String Edge_HasElevation_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasElevation/Inverse";
public static final String Edge_HasFlowArea = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasFlowArea";
public static final String Edge_HasFlowArea_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasFlowArea/Inverse";
+ public static final String Edge_HasGeometry = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasGeometry";
+ public static final String Edge_HasGeometry_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasGeometry/Inverse";
public static final String Edge_HasKReturn = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasKReturn";
public static final String Edge_HasKReturn_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasKReturn/Inverse";
public static final String Edge_HasKSupply = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasKSupply";
Edge_HasElevation_Inverse = getResourceOrNull(graph, URIs.Edge_HasElevation_Inverse);
Edge_HasFlowArea = getResourceOrNull(graph, URIs.Edge_HasFlowArea);
Edge_HasFlowArea_Inverse = getResourceOrNull(graph, URIs.Edge_HasFlowArea_Inverse);
+ Edge_HasGeometry = getResourceOrNull(graph, URIs.Edge_HasGeometry);
+ Edge_HasGeometry_Inverse = getResourceOrNull(graph, URIs.Edge_HasGeometry_Inverse);
Edge_HasKReturn = getResourceOrNull(graph, URIs.Edge_HasKReturn);
Edge_HasKReturn_Inverse = getResourceOrNull(graph, URIs.Edge_HasKReturn_Inverse);
Edge_HasKSupply = getResourceOrNull(graph, URIs.Edge_HasKSupply);
public class DistrictNetworkEdge {
- private Point2D startPoint;
- private Point2D endPoint;
+ private final Point2D startPoint;
+ private final Point2D endPoint;
+ private final double[] geometry;
- public DistrictNetworkEdge(Point2D startPoint, Point2D endPoint) {
+ public DistrictNetworkEdge(Point2D startPoint, Point2D endPoint, double[] geometry) {
this.startPoint = startPoint;
this.endPoint = endPoint;
+ this.geometry = geometry;
}
public Point2D getStartPoint() {
return endPoint;
}
+ public double[] getGeometry() {
+ return geometry;
+ }
}
if (size == null)
size = new Rectangle2D.Double();
if (edge != null)
- size.setFrame(DistrictNetworkEdgeNode.calculatePath(edge, null).getBounds2D());
+ size.setFrame(DistrictNetworkEdgeNode.calculatePath(edge, null, false).getBounds2D());
else
LOGGER.debug("Element {} does not have edge!", e);
public Shape getElementShape(IElement e) {
DistrictNetworkEdge edge = e.getHint(KEY_DN_EDGE);
if (edge != null) {
- return DistrictNetworkEdgeNode.calculatePath(edge, null);
+ return DistrictNetworkEdgeNode.calculatePath(edge, null, false);
} else {
return getBounds(e, null);
}
import java.awt.geom.Point2D;
+import org.simantics.databoard.Bindings;
import org.simantics.db.AsyncReadGraph;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
public class DistrictNetworkEdgeElementFactory extends SyncElementFactory {
public static final ElementClass CLASS = DistrictNetworkEdgeElement.CLASS;
-
+ public static final double[] EMPTY = new double[0];
+
private DistrictNetworkResource DN;
private DiagramResource DIA;
protected Resource getElementClassBaseType(AsyncReadGraph graph) {
return DN.Edge;
}
-
+
@Override
public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource edgeResource, IElement element) throws DatabaseException {
if (!graph.hasStatement(edgeResource))
return; // already deleted
+ if (!graph.hasStatement(edgeResource, DN.HasStartVertex))
+ return; // already deleted
Resource startVertex = graph.getSingleObject(edgeResource, DN.HasStartVertex);
+
+ if (!graph.hasStatement(edgeResource, DN.HasEndVertex))
+ return; // already deleted
Resource endVertex = graph.getSingleObject(edgeResource, DN.HasEndVertex);
- // TODO: Find maybe a better way to apply the scaling
- double[] startCoords = graph.getRelatedValue2(startVertex, DIA.HasLocation);
- double[] endCoords = graph.getRelatedValue2(endVertex, DIA.HasLocation);
- DistrictNetworkEdge edge = new DistrictNetworkEdge(new Point2D.Double(startCoords[0], startCoords[1]), new Point2D.Double(endCoords[0], endCoords[1]));
+ double[] startCoords = graph.getRelatedValue2(startVertex, DIA.HasLocation, Bindings.DOUBLE_ARRAY);
+ double[] endCoords = graph.getRelatedValue2(endVertex, DIA.HasLocation, Bindings.DOUBLE_ARRAY);
+
+ double[] geometry = EMPTY;
+ try {
+ geometry = graph.getPossibleRelatedValue2(edgeResource, DN.Edge_HasGeometry, Bindings.DOUBLE_ARRAY);
+ } catch (Exception e) {
+ // most likely no geometry available
+ }
+ DistrictNetworkEdge edge = new DistrictNetworkEdge(new Point2D.Double(startCoords[0], startCoords[1]), new Point2D.Double(endCoords[0], endCoords[1]), geometry);
Resource mapping = graph.getSingleObject(edgeResource, DistrictNetworkResource.getInstance(graph).HasMapping);
element.setHint(DistrictNetworkAdditionalColor.KEY_DN_MAPPING_RESOURCE, mapping);
double counterExpansion = 0.001;
double x = boundsInLocal.getX() + counterExpansion;
double y = boundsInLocal.getY() + counterExpansion;
- double scaledWidth = boundsInLocal.getWidth() / canvasTransform.getScaleX() / 10000.0;
- double scaledHeight = boundsInLocal.getHeight() / canvasTransform.getScaleY() / 10000.0;
+ double scaledWidth = boundsInLocal.getWidth();
+ double scaledHeight = boundsInLocal.getHeight();
+ if (canvasTransform != null) {
+ scaledWidth = boundsInLocal.getWidth() / canvasTransform.getScaleX() / 10000.0;
+ scaledHeight= boundsInLocal.getHeight() / canvasTransform.getScaleY() / 10000.0;
+ }
double width = scaledWidth - 2*counterExpansion;
double height = scaledHeight - 2*counterExpansion;
size.setFrame(x, y, width, height);
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
-import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import org.simantics.district.network.ModelledCRS;
import org.simantics.district.network.ui.DistrictNetworkEdge;
+import org.simantics.district.network.ui.adapters.DistrictNetworkEdgeElementFactory;
+import org.simantics.maps.MapScalingTransform;
import org.simantics.scenegraph.INode;
import org.simantics.scenegraph.ISelectionPainterNode;
import org.simantics.scenegraph.g2d.G2DNode;
private DistrictNetworkEdge edge;
private Rectangle2D bounds;
- private transient Line2D path;
+ private transient Path2D path;
private boolean scaleStroke = true;
private Color color;
} else {
bs = STROKE;
}
-
- path = calculateLine(edge, path);
+ int zoomLevel = MapScalingTransform.zoomLevel(ot);
+ path = calculatePath(edge, path, zoomLevel > 15);
if (isSelected()) {
g2d.setColor(SELECTION_COLOR);
return centerPoint;
}
- public static Line2D calculateLine(DistrictNetworkEdge edge, Line2D result) {
- // Convert to screen coordinates
- double startX = ModelledCRS.longitudeToX(edge.getStartPoint().getX());
- double startY = ModelledCRS.latitudeToY(-edge.getStartPoint().getY()); // Invert for Simantics
- double endX = ModelledCRS.longitudeToX(edge.getEndPoint().getX());
- double endY = ModelledCRS.latitudeToY(-edge.getEndPoint().getY());// Invert for Simantics
-
- if (result == null)
- result = new Line2D.Double();
- result.setLine(startX, startY, endX, endY);
- return result;
- }
-
- public static Path2D calculatePath(DistrictNetworkEdge edge, Path2D result) {
+// public static Line2D calculateLine(DistrictNetworkEdge edge, Line2D result) {
+// // Convert to screen coordinates
+// double startX = ModelledCRS.longitudeToX(edge.getStartPoint().getX());
+// double startY = ModelledCRS.latitudeToY(-edge.getStartPoint().getY()); // Invert for Simantics
+// double endX = ModelledCRS.longitudeToX(edge.getEndPoint().getX());
+// double endY = ModelledCRS.latitudeToY(-edge.getEndPoint().getY());// Invert for Simantics
+//
+// if (result == null)
+// result = new Line2D.Double();
+// result.setLine(startX, startY, endX, endY);
+// return result;
+// }
+
+ public static Path2D calculatePath(DistrictNetworkEdge edge, Path2D result, boolean detailed) {
// Convert to screen coordinates
double startX = ModelledCRS.longitudeToX(edge.getStartPoint().getX());
double startY = ModelledCRS.latitudeToY(-edge.getStartPoint().getY()); // Invert for Simantics
result.reset();
}
result.moveTo(startX, startY);
+ if (detailed) {
+ double[] detailedGeometry = edge.getGeometry();
+ if (detailedGeometry != null && !DistrictNetworkEdgeElementFactory.EMPTY.equals(detailedGeometry)) {
+ // ok, lets do this
+
+ for (int i = 0; i < detailedGeometry.length; i += 2) {
+ double x = ModelledCRS.longitudeToX(detailedGeometry[i]);
+ double y = ModelledCRS.latitudeToY(-detailedGeometry[i+1]);// Invert for Simantics
+ result.lineTo(x, y);
+ }
+ }
+ }
result.lineTo(endX, endY);
return result;
}
}
private Rectangle2D calculateBounds(Rectangle2D rect) {
- return calculatePath(edge, null).getBounds2D();
+ return calculatePath(edge, null, false).getBounds2D();
}
public void setDNEdge(DistrictNetworkEdge edge) {