From: jsimomaa Date: Fri, 13 Jan 2017 07:48:14 +0000 (+0200) Subject: Implement district features to Simantics platform X-Git-Tag: v1.31.0~20 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=8034693a5c86d690649a70a62709d29c3fa197aa;p=simantics%2Fdistrict.git Implement district features to Simantics platform refs #6958 Change-Id: I4200a696e3ddca7fafa5d2a1e3dd34aee8bac914 --- diff --git a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java index 85eeb942..71017b32 100644 --- a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java +++ b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java @@ -44,6 +44,7 @@ public class CSVImportWizardPage extends WizardPage implements FileSelectionList private Combo delimiterCombo; private TableColumnLayout tableColumnLayout; private TableViewer tableViewer; + private Composite tableComposite; protected CSVImportWizardPage(CSVImportModel model) { super("Import CSV Data"); @@ -94,37 +95,15 @@ public class CSVImportWizardPage extends WizardPage implements FileSelectionList }); - Composite tableComposite = new Composite(composite, SWT.BORDER); - TreeColumnLayout treeColumnLayout = new TreeColumnLayout(); - tableComposite.setLayout(treeColumnLayout); - - tableViewer = new TableViewer(tableComposite, SWT.V_SCROLL | SWT.H_SCROLL); - ColumnViewerToolTipSupport.enableFor(tableViewer); - tableViewer.setContentProvider(new IContentProvider() { - - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - - } - - @Override - public void dispose() { - - } - }); - - Table table = tableViewer.getTable(); - table.setHeaderVisible(true); - table.setLinesVisible(true); - - headerTable = new Table(tableComposite, SWT.NONE); - headerTable.setHeaderVisible(true); - headerTable.setLinesVisible(true); - GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(tableComposite); + tableComposite = new Composite(composite, SWT.BORDER); + tableColumnLayout = new TableColumnLayout(); + tableComposite.setLayout(tableColumnLayout); + + updateHeaders(); setControl(composite); - updateHeaders(); + setPageComplete(false); } @@ -147,7 +126,12 @@ public class CSVImportWizardPage extends WizardPage implements FileSelectionList } private void updateHeaders() { - headerTable.setRedraw(false); + if (headerTable != null) + headerTable.dispose(); + headerTable = new Table(tableComposite, SWT.NONE); + headerTable.setHeaderVisible(true); + headerTable.setLinesVisible(true); + GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(tableComposite); for (int i = 0; i < headerTable.getColumns().length; i++) { TableColumn column = headerTable.getColumns()[i]; column.dispose(); @@ -179,7 +163,6 @@ public class CSVImportWizardPage extends WizardPage implements FileSelectionList } catch (IOException e) { setErrorMessage(e.getMessage()); } - headerTable.setRedraw(true); } } diff --git a/org.simantics.district.network.ontology/META-INF/MANIFEST.MF b/org.simantics.district.network.ontology/META-INF/MANIFEST.MF index 0302088e..18b8713d 100644 --- a/org.simantics.district.network.ontology/META-INF/MANIFEST.MF +++ b/org.simantics.district.network.ontology/META-INF/MANIFEST.MF @@ -8,6 +8,7 @@ Require-Bundle: org.simantics.layer0, org.simantics.structural.ontology;bundle-version="1.2.0", org.simantics.modeling.ontology;bundle-version="1.2.0", org.simantics.viewpoint.ontology;bundle-version="1.2.0", - org.simantics.image2.ontology;bundle-version="1.2.0" + org.simantics.image2.ontology;bundle-version="1.2.0", + org.simantics.selectionview.ontology;bundle-version="1.2.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: org.simantics.district.network.ontology diff --git a/org.simantics.district.network.ontology/build.properties b/org.simantics.district.network.ontology/build.properties index 022de173..73ce7d41 100644 --- a/org.simantics.district.network.ontology/build.properties +++ b/org.simantics.district.network.ontology/build.properties @@ -3,4 +3,5 @@ output.. = bin/ bin.includes = plugin.xml,\ META-INF/,\ .,\ - graph.tg + graph.tg,\ + scl/ diff --git a/org.simantics.district.network.ontology/graph.tg b/org.simantics.district.network.ontology/graph.tg index 70e6cc27..73e40a0a 100644 Binary files a/org.simantics.district.network.ontology/graph.tg and b/org.simantics.district.network.ontology/graph.tg differ diff --git a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph index 612fb303..2c6ac584 100644 --- a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph +++ b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph @@ -4,32 +4,98 @@ STR = MOD = VP = IMAGE = +SEL = MBC = MOD.ModelingBrowseContext DN = : L0.Ontology @L0.new + L0.Ontology.global true L0.HasResourceClass "org.simantics.district.network.ontology.DistrictNetworkResource" +DN.Layer -- DN.Mapping.InputTerminal --> DN.Mapping.Terminal -- DN.Mapping.OutputTerminal --> DN.Mapping.Terminal -- DN.Mapping.ComponentType --> STR.ComponentType -- DN.Mapping.VertexMapping.ElevationAttribute --> L0.String -- DN.Mapping.Terminals --> DN.Mapping.TerminalPair -- DN.Mapping.ComponentType + >-- DN.Mapping.EdgeMapping.Bidirectional --> L0.Boolean -- DN.Mapping.EdgeMapping.LengthAttribute --> L0.String -- DN.Mapping.EdgeMapping.DiameterAttribute --> L0.String -- DN.Mapping.Terminals diff --git a/org.simantics.district.network.ontology/graph/epsg/EPSG_4326 b/org.simantics.district.network.ontology/graph/epsg/EPSG_4326 new file mode 100644 index 00000000..30d74d25 --- /dev/null +++ b/org.simantics.district.network.ontology/graph/epsg/EPSG_4326 @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/org.simantics.district.network.ontology/scl/Simantics/District/ComponentMapping.scl b/org.simantics.district.network.ontology/scl/Simantics/District/ComponentMapping.scl new file mode 100644 index 00000000..9219ba47 --- /dev/null +++ b/org.simantics.district.network.ontology/scl/Simantics/District/ComponentMapping.scl @@ -0,0 +1,18 @@ +data VertexMapping = VertexMapping { + componentType :: String, + elevationAttribute :: String, + terminals :: [TerminalPair] +} + +data TerminalPair = TerminalPair { + inputTerminal :: String, + outputTerminal :: String +} + +data EdgeMapping = EdgeMapping { + componentType :: String, + bidirectional :: Boolean, + lengthAttribute :: String, + diameterAttribute :: String, + terminals :: [TerminalPair] +} \ No newline at end of file diff --git a/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java b/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java index 513891df..6ab511e1 100644 --- a/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java +++ b/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java @@ -14,34 +14,122 @@ public class DistrictNetworkResource { public final Resource ActionContext_newDiagramContribution; public final Resource Actions; public final Resource Actions_NewDNDiagram; + public final Resource AddLayerToDNDiagramTemplate; + public final Resource Bidirectional; + public final Resource Bidirectional_Inverse; public final Resource Composite; public final Resource Connection; public final Resource Diagram; + public final Resource EPSG_4326; public final Resource Edge; + public final Resource EdgeDefaultMapping; + public final Resource EdgeDefaultMapping_Inverse; + public final Resource Edge_HasDiameter; + public final Resource Edge_HasDiameter_Inverse; public final Resource HasEndVertex; public final Resource HasEndVertex_Inverse; + public final Resource HasInLayerTag; + public final Resource HasInLayerTag_Inverse; + public final Resource HasMapping; + public final Resource HasMapping_Inverse; + public final Resource HasSRID; + public final Resource HasSRID_Inverse; + public final Resource HasSRTEXT; + public final Resource HasSRTEXT_Inverse; + public final Resource HasSpatialRefSystem; + public final Resource HasSpatialRefSystem_Inverse; public final Resource HasStartVertex; public final Resource HasStartVertex_Inverse; public final Resource Images; public final Resource Images_ConfigurationFolder; + public final Resource InLayer; + public final Resource Layer; + public final Resource Mapping; + public final Resource Mapping_ComponentType; + public final Resource Mapping_ComponentType_Inverse; + public final Resource Mapping_EdgeMapping; + public final Resource Mapping_EdgeMapping_Bidirectional; + public final Resource Mapping_EdgeMapping_Bidirectional_Inverse; + public final Resource Mapping_EdgeMapping_DiameterAttribute; + public final Resource Mapping_EdgeMapping_DiameterAttribute_Inverse; + public final Resource Mapping_EdgeMapping_LengthAttribute; + public final Resource Mapping_EdgeMapping_LengthAttribute_Inverse; + public final Resource Mapping_InputTerminal; + public final Resource Mapping_InputTerminal_Inverse; + public final Resource Mapping_OutputTerminal; + public final Resource Mapping_OutputTerminal_Inverse; + public final Resource Mapping_Terminal; + public final Resource Mapping_TerminalPair; + public final Resource Mapping_Terminals; + public final Resource Mapping_Terminals_Inverse; + public final Resource Mapping_VertexMapping; + public final Resource Mapping_VertexMapping_ElevationAttribute; + public final Resource Mapping_VertexMapping_ElevationAttribute_Inverse; + public final Resource SpatialRefSystem; public final Resource Vertex; + public final Resource VertexDefaultMapping; + public final Resource VertexDefaultMapping_Inverse; public static class URIs { public static final String ActionContext = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext"; public static final String ActionContext_newDiagramContribution = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext/newDiagramContribution"; public static final String Actions = "http://www.simantics.org/DistrictNetwork-1.0/Actions"; public static final String Actions_NewDNDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Actions/NewDNDiagram"; + public static final String AddLayerToDNDiagramTemplate = "http://www.simantics.org/DistrictNetwork-1.0/AddLayerToDNDiagramTemplate"; + public static final String Bidirectional = "http://www.simantics.org/DistrictNetwork-1.0/Bidirectional"; + public static final String Bidirectional_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Bidirectional/Inverse"; public static final String Composite = "http://www.simantics.org/DistrictNetwork-1.0/Composite"; public static final String Connection = "http://www.simantics.org/DistrictNetwork-1.0/Connection"; public static final String Diagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram"; + public static final String EPSG_4326 = "http://www.simantics.org/DistrictNetwork-1.0/EPSG_4326"; public static final String Edge = "http://www.simantics.org/DistrictNetwork-1.0/Edge"; + public static final String EdgeDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/EdgeDefaultMapping"; + public static final String EdgeDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/EdgeDefaultMapping/Inverse"; + public static final String Edge_HasDiameter = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter"; + public static final String Edge_HasDiameter_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter/Inverse"; public static final String HasEndVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex"; - public static final String HasEndVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex/Inverse"; + public static final String HasEndVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex_Inverse"; + public static final String HasInLayerTag = "http://www.simantics.org/DistrictNetwork-1.0/HasInLayerTag"; + public static final String HasInLayerTag_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasInLayerTag/Inverse"; + public static final String HasMapping = "http://www.simantics.org/DistrictNetwork-1.0/HasMapping"; + public static final String HasMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasMapping/Inverse"; + public static final String HasSRID = "http://www.simantics.org/DistrictNetwork-1.0/HasSRID"; + public static final String HasSRID_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSRID/Inverse"; + public static final String HasSRTEXT = "http://www.simantics.org/DistrictNetwork-1.0/HasSRTEXT"; + public static final String HasSRTEXT_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSRTEXT/Inverse"; + public static final String HasSpatialRefSystem = "http://www.simantics.org/DistrictNetwork-1.0/HasSpatialRefSystem"; + public static final String HasSpatialRefSystem_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSpatialRefSystem/Inverse"; public static final String HasStartVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex"; - public static final String HasStartVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex/Inverse"; + public static final String HasStartVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex_Inverse"; public static final String Images = "http://www.simantics.org/DistrictNetwork-1.0/Images"; public static final String Images_ConfigurationFolder = "http://www.simantics.org/DistrictNetwork-1.0/Images/ConfigurationFolder"; + public static final String InLayer = "http://www.simantics.org/DistrictNetwork-1.0/InLayer"; + public static final String Layer = "http://www.simantics.org/DistrictNetwork-1.0/Layer"; + public static final String Mapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping"; + public static final String Mapping_ComponentType = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/ComponentType"; + public static final String Mapping_ComponentType_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/ComponentType/Inverse"; + public static final String Mapping_EdgeMapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping"; + public static final String Mapping_EdgeMapping_Bidirectional = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/Bidirectional"; + public static final String Mapping_EdgeMapping_Bidirectional_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/Bidirectional/Inverse"; + public static final String Mapping_EdgeMapping_DiameterAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/DiameterAttribute"; + public static final String Mapping_EdgeMapping_DiameterAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/DiameterAttribute/Inverse"; + public static final String Mapping_EdgeMapping_LengthAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/LengthAttribute"; + public static final String Mapping_EdgeMapping_LengthAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/LengthAttribute/Inverse"; + public static final String Mapping_InputTerminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/InputTerminal"; + public static final String Mapping_InputTerminal_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/InputTerminal/Inverse"; + public static final String Mapping_OutputTerminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/OutputTerminal"; + public static final String Mapping_OutputTerminal_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/OutputTerminal/Inverse"; + public static final String Mapping_Terminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminal"; + public static final String Mapping_TerminalPair = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/TerminalPair"; + public static final String Mapping_Terminals = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminals"; + public static final String Mapping_Terminals_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminals/Inverse"; + public static final String Mapping_VertexMapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping"; + public static final String Mapping_VertexMapping_ElevationAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/ElevationAttribute"; + public static final String Mapping_VertexMapping_ElevationAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/ElevationAttribute/Inverse"; + public static final String SpatialRefSystem = "http://www.simantics.org/DistrictNetwork-1.0/SpatialRefSystem"; public static final String Vertex = "http://www.simantics.org/DistrictNetwork-1.0/Vertex"; + public static final String VertexDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/VertexDefaultMapping"; + public static final String VertexDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/VertexDefaultMapping/Inverse"; } public static Resource getResourceOrNull(ReadGraph graph, String uri) { @@ -58,17 +146,61 @@ public class DistrictNetworkResource { ActionContext_newDiagramContribution = getResourceOrNull(graph, URIs.ActionContext_newDiagramContribution); Actions = getResourceOrNull(graph, URIs.Actions); Actions_NewDNDiagram = getResourceOrNull(graph, URIs.Actions_NewDNDiagram); + AddLayerToDNDiagramTemplate = getResourceOrNull(graph, URIs.AddLayerToDNDiagramTemplate); + Bidirectional = getResourceOrNull(graph, URIs.Bidirectional); + Bidirectional_Inverse = getResourceOrNull(graph, URIs.Bidirectional_Inverse); Composite = getResourceOrNull(graph, URIs.Composite); Connection = getResourceOrNull(graph, URIs.Connection); Diagram = getResourceOrNull(graph, URIs.Diagram); + EPSG_4326 = getResourceOrNull(graph, URIs.EPSG_4326); Edge = getResourceOrNull(graph, URIs.Edge); + EdgeDefaultMapping = getResourceOrNull(graph, URIs.EdgeDefaultMapping); + EdgeDefaultMapping_Inverse = getResourceOrNull(graph, URIs.EdgeDefaultMapping_Inverse); + Edge_HasDiameter = getResourceOrNull(graph, URIs.Edge_HasDiameter); + Edge_HasDiameter_Inverse = getResourceOrNull(graph, URIs.Edge_HasDiameter_Inverse); HasEndVertex = getResourceOrNull(graph, URIs.HasEndVertex); HasEndVertex_Inverse = getResourceOrNull(graph, URIs.HasEndVertex_Inverse); + HasInLayerTag = getResourceOrNull(graph, URIs.HasInLayerTag); + HasInLayerTag_Inverse = getResourceOrNull(graph, URIs.HasInLayerTag_Inverse); + HasMapping = getResourceOrNull(graph, URIs.HasMapping); + HasMapping_Inverse = getResourceOrNull(graph, URIs.HasMapping_Inverse); + HasSRID = getResourceOrNull(graph, URIs.HasSRID); + HasSRID_Inverse = getResourceOrNull(graph, URIs.HasSRID_Inverse); + HasSRTEXT = getResourceOrNull(graph, URIs.HasSRTEXT); + HasSRTEXT_Inverse = getResourceOrNull(graph, URIs.HasSRTEXT_Inverse); + HasSpatialRefSystem = getResourceOrNull(graph, URIs.HasSpatialRefSystem); + HasSpatialRefSystem_Inverse = getResourceOrNull(graph, URIs.HasSpatialRefSystem_Inverse); HasStartVertex = getResourceOrNull(graph, URIs.HasStartVertex); HasStartVertex_Inverse = getResourceOrNull(graph, URIs.HasStartVertex_Inverse); Images = getResourceOrNull(graph, URIs.Images); Images_ConfigurationFolder = getResourceOrNull(graph, URIs.Images_ConfigurationFolder); + InLayer = getResourceOrNull(graph, URIs.InLayer); + Layer = getResourceOrNull(graph, URIs.Layer); + Mapping = getResourceOrNull(graph, URIs.Mapping); + Mapping_ComponentType = getResourceOrNull(graph, URIs.Mapping_ComponentType); + Mapping_ComponentType_Inverse = getResourceOrNull(graph, URIs.Mapping_ComponentType_Inverse); + Mapping_EdgeMapping = getResourceOrNull(graph, URIs.Mapping_EdgeMapping); + Mapping_EdgeMapping_Bidirectional = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_Bidirectional); + Mapping_EdgeMapping_Bidirectional_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_Bidirectional_Inverse); + Mapping_EdgeMapping_DiameterAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_DiameterAttribute); + Mapping_EdgeMapping_DiameterAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_DiameterAttribute_Inverse); + Mapping_EdgeMapping_LengthAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_LengthAttribute); + Mapping_EdgeMapping_LengthAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_LengthAttribute_Inverse); + Mapping_InputTerminal = getResourceOrNull(graph, URIs.Mapping_InputTerminal); + Mapping_InputTerminal_Inverse = getResourceOrNull(graph, URIs.Mapping_InputTerminal_Inverse); + Mapping_OutputTerminal = getResourceOrNull(graph, URIs.Mapping_OutputTerminal); + Mapping_OutputTerminal_Inverse = getResourceOrNull(graph, URIs.Mapping_OutputTerminal_Inverse); + Mapping_Terminal = getResourceOrNull(graph, URIs.Mapping_Terminal); + Mapping_TerminalPair = getResourceOrNull(graph, URIs.Mapping_TerminalPair); + Mapping_Terminals = getResourceOrNull(graph, URIs.Mapping_Terminals); + Mapping_Terminals_Inverse = getResourceOrNull(graph, URIs.Mapping_Terminals_Inverse); + Mapping_VertexMapping = getResourceOrNull(graph, URIs.Mapping_VertexMapping); + Mapping_VertexMapping_ElevationAttribute = getResourceOrNull(graph, URIs.Mapping_VertexMapping_ElevationAttribute); + Mapping_VertexMapping_ElevationAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_VertexMapping_ElevationAttribute_Inverse); + SpatialRefSystem = getResourceOrNull(graph, URIs.SpatialRefSystem); Vertex = getResourceOrNull(graph, URIs.Vertex); + VertexDefaultMapping = getResourceOrNull(graph, URIs.VertexDefaultMapping); + VertexDefaultMapping_Inverse = getResourceOrNull(graph, URIs.VertexDefaultMapping_Inverse); } public static DistrictNetworkResource getInstance(ReadGraph graph) { diff --git a/org.simantics.district.network.ui/META-INF/MANIFEST.MF b/org.simantics.district.network.ui/META-INF/MANIFEST.MF index 0e348e6b..267a0dd0 100644 --- a/org.simantics.district.network.ui/META-INF/MANIFEST.MF +++ b/org.simantics.district.network.ui/META-INF/MANIFEST.MF @@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.e4.ui.model.workbench;bundle-version="1.1.100.v20150 org.simantics.modeling.ui, org.simantics.district.network.ontology, org.simantics.utils.datastructures, - org.simantics.district.network;bundle-version="1.0.0" + org.simantics.district.network;bundle-version="1.0.0", + org.simantics.layer0.utils Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: org.simantics.district.network.ui.adapters Bundle-ActivationPolicy: lazy diff --git a/org.simantics.district.network.ui/adapters.xml b/org.simantics.district.network.ui/adapters.xml index 57243ce1..8fdfa320 100644 --- a/org.simantics.district.network.ui/adapters.xml +++ b/org.simantics.district.network.ui/adapters.xml @@ -18,4 +18,30 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.simantics.district.network.ui/icons/diagramEditor.png b/org.simantics.district.network.ui/icons/diagramEditor.png new file mode 100644 index 00000000..aab17bb4 Binary files /dev/null and b/org.simantics.district.network.ui/icons/diagramEditor.png differ diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNEdgeBuilder.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNEdgeBuilder.java index 475269f8..b9b73e54 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNEdgeBuilder.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNEdgeBuilder.java @@ -3,17 +3,31 @@ package org.simantics.district.network.ui; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; import org.simantics.db.layer0.util.Layer0Utils; +import org.simantics.diagram.synchronization.IModifiableSynchronizationContext; +import org.simantics.diagram.synchronization.SynchronizationHints; import org.simantics.diagram.synchronization.graph.AddElement; +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.ui.DiagramModelHints; import org.simantics.district.network.DistrictNetworkUtil; import org.simantics.district.network.ontology.DistrictNetworkResource; +import org.simantics.g2d.diagram.IDiagram; public class DNEdgeBuilder { private Resource diagramResource; + private IDiagram diagram; + private GraphLayerManager glm; - public DNEdgeBuilder(Resource diagramResource) { + public DNEdgeBuilder(Resource diagramResource, IDiagram diagram) { this.diagramResource = diagramResource; + this.diagram = diagram; + + IModifiableSynchronizationContext context = diagram.getHint(SynchronizationHints.CONTEXT); + glm = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER); } public void create(WriteGraph graph, double[] start, double[] end) throws DatabaseException { @@ -33,9 +47,21 @@ public class DNEdgeBuilder { graph.claim(edge, DN.HasStartVertex, startVertex); graph.claim(edge, DN.HasEndVertex, endVertex); + // 7. Put the element on all the currently active layers if possible. + if (glm != null) { + putOnActiveLayer(graph, edge); + putOnActiveLayer(graph, startVertex); + putOnActiveLayer(graph, endVertex); + } + Layer0Utils.addCommentMetadata(graph, "Added edge " + edge); graph.markUndoPoint(); } + + private void putOnActiveLayer(WriteGraph graph, Resource res) throws DatabaseException { + glm.removeFromAllLayers(graph, res); + glm.putElementOnVisibleLayers(diagram, graph, res); + } private Resource getOrCreateVertex(WriteGraph graph, double[] coords) throws DatabaseException { // TODO: check if vertex exists already, for now create always new diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNElementRemover.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNElementRemover.java new file mode 100644 index 00000000..2cbfe98e --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNElementRemover.java @@ -0,0 +1,61 @@ +package org.simantics.district.network.ui; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.impl.EntityRemover; +import org.simantics.district.network.ontology.DistrictNetworkResource; +import org.simantics.layer0.utils.binaryPredicates.OrderedSetElementsPredicate; +import org.simantics.modeling.adapters.ElementRemover; + +public class DNElementRemover extends ElementRemover { + + public DNElementRemover(Resource element) { + super(element); + } + + @Override + public void removeConnection(WriteGraph graph) throws DatabaseException { + throw new UnsupportedOperationException("Distrct network should not have STR.Connection resources! " + resource); + } + + @Override + public void removeElement(WriteGraph graph) throws DatabaseException { + + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + + if (graph.isInstanceOf(resource, DN.Vertex)) { + graph.getObjects(resource, DN.HasEndVertex_Inverse).forEach(res -> { + try { + doRemove(graph, res); + } catch (DatabaseException e) { + e.printStackTrace(); + } + }); + graph.getObjects(resource, DN.HasStartVertex_Inverse).forEach(res -> { + try { + doRemove(graph, res); + } catch (DatabaseException e) { + e.printStackTrace(); + } + }); + } + doRemove(graph, resource); + } + + private static void doRemove(WriteGraph graph, Resource resource) throws DatabaseException { + // 1. Disconnect element from diagrams + for (Resource diagram : OrderedSetElementsPredicate.INSTANCE.getSubjects(graph, resource)) { + OrderedSetUtils.remove(graph, diagram, resource); + } + + // 2. Delete element itself + EntityRemover.remove(graph, resource); + + // 3. Recursively remove all related degenerate connections + // i.e. connections that only have one connector after remove the + // one connected to this removed element. + } + +} diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNGraphLayerUtil.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNGraphLayerUtil.java new file mode 100644 index 00000000..27905a55 --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNGraphLayerUtil.java @@ -0,0 +1,66 @@ +package org.simantics.district.network.ui; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.diagram.synchronization.graph.layer.GraphLayer; +import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil; +import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil; +import org.simantics.district.network.ontology.DistrictNetworkResource; +import org.simantics.layer0.Layer0; + +public class DNGraphLayerUtil implements IGraphLayerUtil { + + public DNGraphLayerUtil(Resource layer) { + + } + + @Override + public GraphLayer loadLayer(ReadGraph graph, Resource layer) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + String name = graph.getRelatedValue(layer, L0.HasName); + Resource inLayer = graph.getSingleObject(layer, DN.HasInLayerTag); + + Map properties = new HashMap<>(); + properties.put("IN_LAYER", inLayer); + + return new GraphLayer(name, layer, properties); + } + + @Override + public GraphLayer createLayer(WriteGraph graph, String layerName, boolean active) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + DiagramResource DIA = DiagramResource.getInstance(graph); + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + + + Resource layer = graph.newResource(); + graph.claim(layer, L0.InstanceOf, null, DN.Layer); + + // Assign tagging relations + Resource inLayerTag = GraphLayerUtil.newTag(graph, L0, DN.InLayer); + graph.claim(layer, DN.HasInLayerTag, inLayerTag); + + // Assign shared name property for all, the layer and the tags + Resource name = graph.newResource(); + graph.claim(name, L0.InstanceOf, null, L0.String); + graph.claimValue(name, layerName); + + graph.claim(layer, L0.HasName, name); + graph.claim(inLayerTag, L0.HasName, name); + + graph.claim(layer, DN.HasSpatialRefSystem, DN.EPSG_4326); + + GraphLayerUtil.setLayerActive(graph, DIA, layer, active); + + return new GraphLayer(layerName, layer, Collections.emptyMap()); + } + +} diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java index e536f3cc..9acad52c 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java @@ -2,6 +2,7 @@ package org.simantics.district.network.ui; import java.util.concurrent.TimeUnit; +import org.simantics.district.network.ui.participants.DNPointerInteractor; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.diagram.handler.PickRequest.PickFilter; import org.simantics.g2d.diagram.participant.DelayedBatchElementPainter; @@ -18,6 +19,7 @@ public class DistrictDiagramViewer extends DiagramViewer { ctx.add(new ZOrderHandler()); ctx.add(new Selection()); ctx.add(new ElementPainter()); + ctx.add(new DNPointerInteractor()); ctx.add(new NetworkDrawingParticipant()); } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictNetworkEdge.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictNetworkEdge.java index 1a99ae3c..e30b4cb0 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictNetworkEdge.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictNetworkEdge.java @@ -16,6 +16,7 @@ public class DistrictNetworkEdge { } public Rectangle2D getBounds(Rectangle2D rect) { - return path.getBounds2D(); + rect.setFrame(path.getBounds2D()); + return rect; } } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java index a8cd239b..6ae6097c 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java @@ -1,45 +1,11 @@ package org.simantics.district.network.ui; -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.Shape; -import java.awt.geom.Path2D; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.simantics.Simantics; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.ui.DiagramModelHints; -import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency; +import org.simantics.district.network.ui.nodes.NetworkDrawingNode; import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit; import org.simantics.g2d.diagram.IDiagram; -import org.simantics.g2d.diagram.handler.PickContext; -import org.simantics.g2d.diagram.handler.PickRequest; -import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy; import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant; -import org.simantics.g2d.diagram.participant.Selection; -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.participant.TransformUtil; -import org.simantics.g2d.utils.GeometryUtils; -import org.simantics.scenegraph.g2d.G2DNode; import org.simantics.scenegraph.g2d.G2DParentNode; -import org.simantics.scenegraph.g2d.events.EventTypes; -import org.simantics.scenegraph.g2d.events.MouseEvent; -import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler; -import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent; -import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent; -import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent; -import org.simantics.scenegraph.utils.NodeUtil; import org.simantics.utils.datastructures.hints.IHintContext.Key; import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; @@ -59,195 +25,15 @@ public class NetworkDrawingParticipant extends AbstractDiagramParticipant { private NetworkDrawingNode node; - @Dependency Selection selection; - @Dependency TransformUtil util; - @Dependency PickContext pickContext; - @SGInit public void initSG(G2DParentNode parent) { node = parent.addNode("networkDrawingNode", NetworkDrawingNode.class); + node.setNetworkDrawingParticipant(this); } @Override protected void onDiagramSet(IDiagram newDiagram, IDiagram oldDiagram) { node.setDiagram(newDiagram); } - - @EventHandler(priority = 1 << 21) - public boolean handleClick(MouseClickEvent me) { - - boolean isLeft = me.button == MouseEvent.LEFT_BUTTON; - boolean isRight = me.button == MouseEvent.RIGHT_BUTTON; - if (!isLeft && !isRight) - return false; - boolean isShiftPressed = me.hasAllModifiers(MouseEvent.SHIFT_MASK); - - int selectionId = me.mouseId; - - double pickDist = getPickDistance(); - Rectangle2D controlPickRect = new Rectangle2D.Double(me.controlPosition.getX()-pickDist, me.controlPosition.getY()-pickDist, pickDist*2+1, pickDist*2+1); - Shape canvasPickRect = GeometryUtils.transformShape(controlPickRect, util.getInverseTransform()); - - PickRequest req = new PickRequest(canvasPickRect); - req.pickPolicy = PickPolicy.PICK_INTERSECTING_OBJECTS; - //req.pickSorter = PickRequest.PickSorter.CONNECTIONS_LAST; - List pickables = new ArrayList(); - pickContext.pick(diagram, req, pickables); - - Set currentSelection = selection.getSelection(selectionId); - - if (!pickables.isEmpty()) { - /* - * Select the one object the mouse points to. If multiple object - * are picked, select the one that is after the earliest by - * index of the current selection when shift is pressed. Otherwise - * always pick the topmost element. - */ - IElement selectedPick = isShiftPressed - ? rotatingPick(currentSelection, pickables) - : pickables.get(pickables.size() - 1); - - // Only select when - // 1. the selection would actually change - // AND - // 2.1. left button was pressed - // OR - // 2.2. right button was pressed and the element to-be-selected - // is NOT a part of the current selection - if (!Collections.singleton(selectedPick).equals(currentSelection) - && (isLeft || (isRight && !currentSelection.contains(selectedPick)))) { - selection.setSelection(selectionId, selectedPick); - } - } - - return false; - } - - private double getPickDistance() { - Double pickDistance = getHint(KEY_PICK_DISTANCE); - return pickDistance == null ? PICK_DIST : Math.max(pickDistance, 0); - } - - private IElement rotatingPick(int selectionId, List pickables) { - Set sel = selection.getSelection(selectionId); - return rotatingPick(sel, pickables); - } - private IElement rotatingPick(Set sel, List pickables) { - int earliestIndex = pickables.size(); - for (int i = pickables.size() - 1; i >= 0; --i) { - if (sel.contains(pickables.get(i))) { - earliestIndex = i; - break; - } - } - if (earliestIndex == 0) - earliestIndex = pickables.size(); - IElement selectedPick = pickables.get(earliestIndex - 1); - return selectedPick; - } - - public static class NetworkDrawingNode extends G2DNode { - - private static final long serialVersionUID = -3475301184009620573L; - - private List nodes = new ArrayList<>(); - - private Rectangle2D rect = new Rectangle2D.Double(10, 10, 10, 10); - - private Set paths = new HashSet<>(); - - private Resource diagramResource; - - private boolean committed; - - @Override - public void init() { - super.init(); - addEventHandler(this); - } - - public void setDiagram(IDiagram diagram) { - if (diagram != null) - this.diagramResource = diagram.getHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE); - } - - @Override - public void render(Graphics2D g2d) { - Color old = g2d.getColor(); - g2d.setColor(Color.BLUE); - - paths.forEach(p -> { - g2d.draw(p); - }); - - g2d.setColor(old); - } - - @Override - public Rectangle2D getBoundsInLocal() { - return rect.getBounds2D(); - } - - @Override - public int getEventMask() { - return EventTypes.MouseMask; - } - - @Override - protected boolean mouseDoubleClicked(MouseDoubleClickedEvent e) { - // nodes to path2d - Point2D start = null; - Point2D end = null; - Iterator nodeIter = nodes.iterator(); - while (nodeIter.hasNext()) { - if (end == null) { - start = nodeIter.next(); - } else { - start = end; - } - end = nodeIter.next(); - - createEdge(start, end); - } - - nodes.clear(); - committed = true; - - repaint(); - - return true; - } - - private void createEdge(Point2D start, Point2D end) { - double[] startCoords = new double[] { start.getX(), start.getY() }; - double[] endCoords = new double[] { end.getX(), end.getY() }; - - DNEdgeBuilder builder = new DNEdgeBuilder(diagramResource); - Simantics.getSession().asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - builder.create(graph, startCoords, endCoords); - } - }); - - } - - @Override - protected boolean mouseClicked(MouseClickEvent e) { - if (committed) { - committed = false; - return false; - } - Point2D localPos = NodeUtil.worldToLocal(this, e.controlPosition, new Point2D.Double()); - nodes.add(new Point2D.Double(localPos.getX(), localPos.getY())); - return super.mouseClicked(e); - } - - @Override - protected boolean mouseMoved(MouseMovedEvent e) { - return super.mouseMoved(e); - } - } } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java index 8ec1430b..a53c02d2 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java @@ -10,7 +10,7 @@ import org.simantics.g2d.element.IElement; import org.simantics.g2d.element.SceneGraphNodeKey; import org.simantics.g2d.element.handler.InternalSize; import org.simantics.g2d.element.handler.SceneGraph; -import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform; +import org.simantics.g2d.element.handler.impl.DefaultTransform; import org.simantics.scenegraph.g2d.G2DParentNode; import org.simantics.utils.datastructures.hints.IHintContext.Key; import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; @@ -22,7 +22,7 @@ public class DistrictNetworkEdgeElement { public static final ElementClass CLASS = ElementClass.compile( - FixedTransform.INSTANCE, + DefaultTransform.INSTANCE, DNEdgeInternalSize.INSTANCE, DNEdgeSceneGraph.INSTANCE ).setId(DistrictNetworkEdgeElement.class.getSimpleName()); @@ -64,7 +64,11 @@ public class DistrictNetworkEdgeElement { @Override public Rectangle2D getBounds(IElement e, Rectangle2D size) { DistrictNetworkEdge edge = e.getHint(KEY_DN_EDGE); - return edge.getBounds(size); + if (size == null) + size = new Rectangle2D.Double(); + edge.getBounds(size); + + return size; } } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java index bb75ab0c..339d51d4 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java @@ -1,6 +1,7 @@ package org.simantics.district.network.ui.adapters; import java.awt.Dimension; +import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import org.simantics.district.network.ui.nodes.DistrictNetworkVertexNode; @@ -10,7 +11,7 @@ import org.simantics.g2d.element.IElement; import org.simantics.g2d.element.SceneGraphNodeKey; import org.simantics.g2d.element.handler.InternalSize; import org.simantics.g2d.element.handler.SceneGraph; -import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform; +import org.simantics.g2d.element.handler.impl.DefaultTransform; import org.simantics.scenegraph.g2d.G2DParentNode; import org.simantics.utils.datastructures.hints.IHintContext.Key; import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; @@ -22,7 +23,7 @@ public class DistrictNetworkVertexElement { public static final ElementClass CLASS = ElementClass.compile( - FixedTransform.INSTANCE, + DefaultTransform.INSTANCE, DNVertexInternalSize.INSTANCE, DNVertexSceneGraph.INSTANCE ).setId(DistrictNetworkVertexElement.class.getSimpleName()); @@ -45,6 +46,10 @@ public class DistrictNetworkVertexElement { edgeElement.setHint(KEY_DN_VERTEX_NODE, node); } node.setVertex(vertex); + + AffineTransform at = ElementUtils.getTransform(edgeElement); + if(at != null) + node.setTransform(at); } } @@ -63,10 +68,9 @@ public class DistrictNetworkVertexElement { @Override public Rectangle2D getBounds(IElement e, Rectangle2D size) { - DistrictNetworkVertex vertex = e.getHint(KEY_DN_VERTEX); if (size == null) size = new Rectangle2D.Double(); - size.setFrame(vertex.getPoint(), new Dimension(1, 1)); + size.setFrame(-0.5, -0.5, 1, 1); return size; } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java index 909f7fb1..c1971646 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java @@ -1,5 +1,7 @@ package org.simantics.district.network.ui.adapters; +import java.awt.geom.AffineTransform; + import org.simantics.db.AsyncReadGraph; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -11,6 +13,7 @@ import org.simantics.district.network.ontology.DistrictNetworkResource; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.diagram.IDiagram; import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementUtils; import org.simantics.g2d.element.IElement; import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; @@ -26,8 +29,7 @@ public class DistrictNetworkVertexElementFactory extends SyncElementFactory { } @Override - public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, - AsyncProcedure procedure) { + public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure procedure) { procedure.execute(graph, CLASS.newClassWith(false, new StaticObjectAdapter(elementType))); } @@ -40,9 +42,11 @@ public class DistrictNetworkVertexElementFactory extends SyncElementFactory { public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource vertexResource, IElement element) throws DatabaseException { double[] coords = graph.getRelatedValue(vertexResource, DIA.HasLocation); - DistrictNetworkVertex vertex = new DistrictNetworkVertex(coords); - element.setHint(DistrictNetworkVertexElement.KEY_DN_VERTEX, vertex); + + // set element transform based on layer SRS and coords + AffineTransform at = new AffineTransform(1, 0, 0, 1, coords[0], coords[1]); + ElementUtils.setTransform(element, at); } } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java index 60013653..eb1d26eb 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java @@ -38,14 +38,14 @@ public class DistrictNetworkEdgeNode extends G2DNode { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); Color oldColor = g2d.getColor(); - boolean selected = isSelected(); - if (selected) { - Path2D selectionPath = edge.getPath(); - Shape selectionShape = SELECTION_STROKE.createStrokedShape(selectionPath); - g2d.setColor(SELECTION_COLOR); - g2d.fill(selectionShape); - } - +// boolean selected = isSelected(); +// if (selected) { +// Path2D selectionPath = edge.getPath(); +// Shape selectionShape = SELECTION_STROKE.createStrokedShape(selectionPath); +// g2d.setColor(SELECTION_COLOR); +// g2d.fill(selectionShape); +// } +// g2d.setColor(Color.BLUE); // render g2d.draw(edge.getPath()); @@ -80,6 +80,7 @@ public class DistrictNetworkEdgeNode extends G2DNode { public void setDNEdge(DistrictNetworkEdge edge) { this.edge = edge; + updateBounds(); } } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java index 77038500..7365060b 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java @@ -30,7 +30,7 @@ public class DistrictNetworkVertexNode extends G2DNode { g2d.setColor(Color.RED); // render - Rectangle2D.Double rect = new Rectangle2D.Double(vertex.getPoint().getX() - 0.5, vertex.getPoint().getY() - 0.5, 1, 1); + Rectangle2D.Double rect = new Rectangle2D.Double(-0.5, -0.5, 1, 1); g2d.draw(rect); // Reset stats @@ -44,7 +44,7 @@ public class DistrictNetworkVertexNode extends G2DNode { @Override public Rectangle2D getBoundsInLocal() { - return new Rectangle2D.Double(vertex.getPoint().getX(), vertex.getPoint().getY(), 1, 1); + return new Rectangle2D.Double(-0.5, -0.5, 1, 1); } public void setVertex(DistrictNetworkVertex vertex) { diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java new file mode 100644 index 00000000..48629427 --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java @@ -0,0 +1,157 @@ +package org.simantics.district.network.ui.nodes; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.Path2D; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.simantics.Simantics; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.ui.DiagramModelHints; +import org.simantics.district.network.ui.DNEdgeBuilder; +import org.simantics.district.network.ui.NetworkDrawingParticipant; +import org.simantics.g2d.canvas.Hints; +import org.simantics.g2d.canvas.IToolMode; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.scenegraph.g2d.G2DNode; +import org.simantics.scenegraph.g2d.events.EventTypes; +import org.simantics.scenegraph.g2d.events.MouseEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent; +import org.simantics.scenegraph.utils.NodeUtil; + +public class NetworkDrawingNode extends G2DNode { + + private static final long serialVersionUID = -3475301184009620573L; + + private List nodes = new ArrayList<>(); + + private Rectangle2D rect = new Rectangle2D.Double(10, 10, 10, 10); + + private Set paths = new HashSet<>(); + + private Resource diagramResource; + + private boolean committed; + + private NetworkDrawingParticipant participant; + + private IDiagram diagram; + + @Override + public void init() { + super.init(); + addEventHandler(this); + } + + public void setNetworkDrawingParticipant(NetworkDrawingParticipant participant) { + this.participant = participant; + } + + public void setDiagram(IDiagram diagram) { + if (diagram != null) { + this.diagram = diagram; + this.diagramResource = diagram.getHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE); + } + } + + @Override + public void render(Graphics2D g2d) { + Color old = g2d.getColor(); + g2d.setColor(Color.BLUE); + + paths.forEach(p -> { + g2d.draw(p); + }); + + g2d.setColor(old); + } + + @Override + public Rectangle2D getBoundsInLocal() { + return rect.getBounds2D(); + } + + @Override + public int getEventMask() { + return EventTypes.MouseMask; + } + + @Override + protected boolean mouseDoubleClicked(MouseDoubleClickedEvent e) { + // nodes to path2d + IToolMode mode = getToolMode(); + if (mode == Hints.CONNECTTOOL || e.hasAnyModifier(MouseEvent.ALT_MASK | MouseEvent.ALT_GRAPH_MASK)) { + Point2D start = null; + Point2D end = null; + Iterator nodeIter = nodes.iterator(); + while (nodeIter.hasNext()) { + if (end == null) { + start = nodeIter.next(); + } else { + start = end; + } + end = nodeIter.next(); + + createEdge(start, end); + } + + nodes.clear(); + committed = true; + + repaint(); + + return true; + } + return super.mouseDoubleClicked(e); + } + + private void createEdge(Point2D start, Point2D end) { + double[] startCoords = new double[] { start.getX(), start.getY() }; + double[] endCoords = new double[] { end.getX(), end.getY() }; + + DNEdgeBuilder builder = new DNEdgeBuilder(diagramResource, diagram); + Simantics.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + builder.create(graph, startCoords, endCoords); + } + }); + + } + + @Override + protected boolean mouseClicked(MouseClickEvent e) { + // check ToolMode + IToolMode mode = getToolMode(); + if (mode == Hints.CONNECTTOOL || e.hasAnyModifier(MouseEvent.ALT_MASK | MouseEvent.ALT_GRAPH_MASK)) { + if (committed) { + committed = false; + return false; + } + Point2D localPos = NodeUtil.worldToLocal(this, e.controlPosition, new Point2D.Double()); + nodes.add(new Point2D.Double(localPos.getX(), localPos.getY())); + } + return super.mouseClicked(e); + } + + private IToolMode getToolMode() { + return participant.getHint(Hints.KEY_TOOL); + } + + @Override + protected boolean mouseMoved(MouseMovedEvent e) { + return super.mouseMoved(e); + } +} \ No newline at end of file diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNPointerInteractor.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNPointerInteractor.java new file mode 100644 index 00000000..e8b8337b --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNPointerInteractor.java @@ -0,0 +1,22 @@ +package org.simantics.district.network.ui.participants; + +import java.awt.geom.Point2D; +import java.util.Set; + +import org.simantics.g2d.canvas.ICanvasParticipant; +import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor; +import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo; +import org.simantics.g2d.element.IElement; + +public class DNPointerInteractor extends PointerInteractor { + + @Override + protected ICanvasParticipant createConnectTool(TerminalInfo ti, int mouseId, Point2D startCanvasPos) { + return super.createConnectTool(ti, mouseId, startCanvasPos); + } + + @Override + protected ICanvasParticipant createTranslateTool(int mouseId, Point2D startCanvasPos, Point2D curCanvasPos, Set elementsToDrag) { + return new DNTranslateMode(startCanvasPos, curCanvasPos, mouseId, elementsToDrag); + } +} diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java new file mode 100644 index 00000000..74a46475 --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java @@ -0,0 +1,83 @@ +package org.simantics.district.network.ui.participants; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.Simantics; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.CommentMetadata; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.elements.ElementTransforms; +import org.simantics.diagram.elements.ElementTransforms.TransformedObject; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.district.network.ontology.DistrictNetworkResource; +import org.simantics.g2d.canvas.Hints; +import org.simantics.g2d.diagram.participant.pointertool.TranslateMode; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.Move; + +public class DNTranslateMode extends TranslateMode { + + public DNTranslateMode(Point2D startingPoint, Point2D currentPoint, int mouseId, Collection elements) { + super(startingPoint, currentPoint, mouseId, elements); + } + + @Override + protected boolean commit() { + for (IElement el : elementsToReallyTranslate) { + Move move = el.getElementClass().getAtMostOneItemOfClass(Move.class); + if (move != null) { + Point2D oldPos = move.getPosition(el); + move.moveTo(el, oldPos.getX() + dx, oldPos.getY() + dy); + } + } + try { + Simantics.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Collection transformed = new ArrayList(); + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + DiagramResource DIA = DiagramResource.getInstance(graph); + for (IElement e : elementsToReallyTranslate) { + Object obj = ElementUtils.getObject(e); + if (obj instanceof Resource) { + Resource res = (Resource) obj; + if (graph.isInstanceOf(res, DN.Vertex)) { + AffineTransform at = ElementUtils.getLocalTransform(e, new AffineTransform()); + transformed.add( new TransformedObject((Resource) obj, at) ); + + + // write to db + double[] coords = new double[] { at.getTranslateX(), at.getTranslateY() }; + graph.claimLiteral(res, DIA.HasLocation, coords); + } + } + } + + if (!transformed.isEmpty()) { + CommentMetadata cm = graph.getMetadata(CommentMetadata.class); + graph.addMetadata(cm.add("Translated " + transformed.size() + " " + + (transformed.size() == 1 ? "element" : "elements") + + " by (" + dx + "," + dy + ") mm.")); + graph.markUndoPoint(); + } + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + for (IElement dirty : elementsToDirty) + dirty.setHint(Hints.KEY_DIRTY, Hints.VALUE_SG_DIRTY); + + setDirty(); + remove(); + return false; + } + +} diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/templates/AddLayerToDNDiagramTemplate.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/templates/AddLayerToDNDiagramTemplate.java new file mode 100644 index 00000000..4b846c31 --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/templates/AddLayerToDNDiagramTemplate.java @@ -0,0 +1,40 @@ +package org.simantics.district.network.ui.templates; + +import java.util.Map; +import java.util.UUID; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.Template; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.diagram.synchronization.graph.layer.GraphLayer; +import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil; +import org.simantics.district.network.ontology.DistrictNetworkResource; + +public class AddLayerToDNDiagramTemplate implements Template { + + Resource template; + + public AddLayerToDNDiagramTemplate(Resource template) { + this.template = template; + } + + @Override + public void apply(WriteGraph graph, Map parameters) throws DatabaseException { + Resource diagram = (Resource)parameters.get("diagram"); + if (diagram == null) { + diagram = graph.newResource(); + parameters.put("diagram", diagram); + } + + DiagramResource DIA = DiagramResource.getInstance(graph); + IGraphLayerUtil layerUtil = graph.adapt(DistrictNetworkResource.getInstance(graph).Layer, IGraphLayerUtil.class); + GraphLayer layer = layerUtil.createLayer(graph, UUID.randomUUID().toString(), true); + + // Create layer + graph.claim(diagram, DIA.HasLayer, layer.getLayer()); + + } + +} diff --git a/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java b/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java index f9e0439d..25503407 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java +++ b/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java @@ -13,7 +13,6 @@ public class DistrictNetworkUtil { public static Resource createEdge(WriteGraph graph, Resource composite) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); - DiagramResource DIA = DiagramResource.getInstance(graph); Resource edge = graph.newResource(); graph.claim(edge, L0.InstanceOf, DN.Edge); diff --git a/org.simantics.district.ui.feature/feature.xml b/org.simantics.district.ui.feature/feature.xml index e43314c8..8faefe0e 100644 --- a/org.simantics.district.ui.feature/feature.xml +++ b/org.simantics.district.ui.feature/feature.xml @@ -34,4 +34,11 @@ version="0.0.0" unpack="false"/> + +