private double edgePadding = 0.0001; // default
private int valvePositionIndx = -1;
private int addressIndex;
+ private int lengthIndex;
// Third page
public int getAddressIndex() {
return addressIndex;
}
+
+ public int getLengthIndex() {
+ return lengthIndex;
+ }
+
+ public void setLengthIndex(int lengthIndex) {
+ this.lengthIndex = lengthIndex;
+ }
}
int edgeFlowAreaIndex = model.getEdgeFlowAreaIndex();
int kReturnIndex = model.getkReturnIndex();
int kSupplyIndex = model.getkSupplyIndex();
+ int lengthIndex = model.getLengthIndex();
int mappingColumn = model.getComponentMappingIndex();
int idColumn = model.getIdIndex();
endCoords = new double[] { endXCoord , endYCoord };
}
- Resource edge = DNEdgeBuilder.create(graph, vv, model.getParentDiagram(), model.getComponentMappings().get(mappingValue), startCoords, endCoords, padding);
+ Resource edge = DNEdgeBuilder.create(graph, vv, model.getParentDiagram(), model.getComponentMappings().get(mappingValue), startCoords, endCoords, padding, true);
writeStringValue(graph, row, idColumn, edge, DN.HasId);
writeValue(graph, row, diameterColumnIndex, edge, DN.Edge_HasDiameter);
writeValue(graph, row, kReturnIndex, edge, DN.Edge_HasKReturn);
writeValue(graph, row, kSupplyIndex, edge, DN.Edge_HasKSupply);
writeValue(graph, row, edgeFlowAreaIndex, edge, DN.Edge_HasFlowArea);
+ writeValue(graph, row, lengthIndex, edge, DN.Edge_HasLength);
}
} catch (MismatchedDimensionException | TransformException | DatabaseException e) {
throw new DatabaseException(e);
import org.eclipse.jface.dialogs.IPageChangedListener;
import org.eclipse.jface.dialogs.PageChangedEvent;
import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.wizard.IWizardContainer;
private DynamicComboFieldEditor nominalPressureLossSelector;
private DynamicComboFieldEditor valvePositionSelector;
private DynamicComboFieldEditor addressSelector;
+ private DynamicComboFieldEditor lengthSelector;
// For edge import
private DynamicComboFieldEditor startXCoordSelector;
validatePageComplete();
}
});
+
+
}
private void createEdgeIndexMappingField(Group parent) {
validatePageComplete();
}
});
+ lengthSelector = new DynamicComboFieldEditor("lengthValue", "lengthSelector", parent);
+ lengthSelector.addComboListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ widgetDefaultSelected(e);
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ model.setLengthIndex(Integer.parseInt(lengthSelector.getValue()));
+ validatePageComplete();
+ }
+ });
}
private void updateCombos() {
kReturnSelector.updateCombo(namesAndValues);
kSupplySelector.updateCombo(namesAndValues);
tGroundSelector.updateCombo(namesAndValues);
+ lengthSelector.updateCombo(namesAndValues);
}
private void updateVertexCombos(String[][] namesAndValues) {
velocitySelector.updateCombo(namesAndValues);
flowAreaSelector.updateCombo(namesAndValues);
nominalPressureLossSelector.updateCombo(namesAndValues);
- addressSelector.updateCombo(namesAndValues);
+ addressSelector.updateCombo(namesAndValues);
}
@L0.assert DN.Vertex.HasElevation 0.0
DN.Edge <T DN.Element
+ >-- DN.Edge.HasElevation
+ @defProperty "Elevation" L0.Double
>-- DN.Edge.HasLength
@defProperty "Length" L0.Double
L0.readOnly true
>-- DN.Mapping.EdgeMapping.KReturnAttribute --> L0.String <R L0.HasProperty
>-- DN.Mapping.EdgeMapping.KSupplyAttribute --> L0.String <R L0.HasProperty
>-- DN.Mapping.EdgeMapping.TGroundAttribute --> L0.String <R L0.HasProperty
+ >-- DN.Mapping.EdgeMapping.ElevationAttribute --> L0.String <R L0.HasProperty
>-- DN.Mapping.Terminals
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.request.ObjectsWithType;
+import org.simantics.db.exception.BindingException;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
+import org.simantics.db.exception.ServiceException;
import org.simantics.db.layer0.util.Layer0Utils;
import org.simantics.diagram.stubs.DiagramResource;
import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;
import org.simantics.diagram.synchronization.SynchronizationHints;
-import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;
-import org.simantics.diagram.synchronization.graph.layer.GraphLayer;
import org.simantics.diagram.synchronization.graph.layer.GraphLayerManager;
-import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil;
import org.simantics.district.network.DistrictNetworkUtil;
import org.simantics.district.network.ontology.DistrictNetworkResource;
import org.simantics.g2d.diagram.IDiagram;
double[] existingCoords = graph.getRelatedValue2(vertex, DiagramResource.getInstance(graph).HasLocation, Bindings.DOUBLE_ARRAY);
vv.add(new ResourceVertex(vertex, existingCoords));
}
- return create(graph, vv, diagramResource, null, start, end, padding);
+ return create(graph, vv, diagramResource, null, start, end, padding, false);
}
- public static Resource create(WriteGraph graph, Collection<ResourceVertex> vertices, Resource diagramResource, Resource mapping, double[] start, double[] end, double padding) throws DatabaseException {
+ public static Resource create(WriteGraph graph, Collection<ResourceVertex> vertices, Resource diagramResource, Resource mapping, double[] start, double[] end, double padding, boolean writeElevationToEdgeFromPoints) throws DatabaseException {
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
// 2. Add vertices
Resource startVertex = getOrCreateVertex(graph, diagramResource, vertices, start, padding, null);
Resource endVertex = getOrCreateVertex(graph, diagramResource, vertices, end, padding, startVertex);
+ if (writeElevationToEdgeFromPoints) {
+ graph.claimLiteral(edge, DN.Edge_HasElevation, calculateElevationFromVertices(graph, startVertex, endVertex), Bindings.DOUBLE);
+ }
graph.claim(edge, DN.HasStartVertex, startVertex);
graph.claim(edge, DN.HasEndVertex, endVertex);
//
return edge;
}
+ private static double calculateElevationFromVertices(WriteGraph graph, Resource startVertex, Resource endVertex) throws ManyObjectsForFunctionalRelationException, BindingException, ServiceException {
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ Double startElevation = graph.getPossibleRelatedValue(startVertex, DN.Vertex_HasElevation, Bindings.DOUBLE);
+ Double endElevation = graph.getPossibleRelatedValue(endVertex, DN.Vertex_HasElevation, Bindings.DOUBLE);
+ if (startElevation != null && endElevation != null) {
+ return (startElevation + endElevation) / 2;
+ }
+ return 0;
+ }
+
public void create(WriteGraph graph, double[] start, double[] end, double padding) throws DatabaseException {
Resource edge = create(graph, diagramResource, start, end, padding);