private Combo delimiterCombo;\r
private TableColumnLayout tableColumnLayout;\r
private TableViewer tableViewer;\r
+ private Composite tableComposite;\r
\r
protected CSVImportWizardPage(CSVImportModel model) {\r
super("Import CSV Data");\r
});\r
\r
\r
- Composite tableComposite = new Composite(composite, SWT.BORDER);\r
- TreeColumnLayout treeColumnLayout = new TreeColumnLayout();\r
- tableComposite.setLayout(treeColumnLayout);\r
- \r
- tableViewer = new TableViewer(tableComposite, SWT.V_SCROLL | SWT.H_SCROLL);\r
- ColumnViewerToolTipSupport.enableFor(tableViewer);\r
- tableViewer.setContentProvider(new IContentProvider() {\r
- \r
- @Override\r
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {\r
- \r
- }\r
- \r
- @Override\r
- public void dispose() {\r
- \r
- }\r
- });\r
- \r
- Table table = tableViewer.getTable();\r
- table.setHeaderVisible(true);\r
- table.setLinesVisible(true);\r
- \r
- headerTable = new Table(tableComposite, SWT.NONE);\r
- headerTable.setHeaderVisible(true);\r
- headerTable.setLinesVisible(true);\r
- GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(tableComposite);\r
+ tableComposite = new Composite(composite, SWT.BORDER);\r
+ tableColumnLayout = new TableColumnLayout();\r
+ tableComposite.setLayout(tableColumnLayout);\r
+\r
+ updateHeaders();\r
\r
setControl(composite);\r
\r
- updateHeaders();\r
+ \r
\r
setPageComplete(false);\r
}\r
}\r
\r
private void updateHeaders() {\r
- headerTable.setRedraw(false);\r
+ if (headerTable != null)\r
+ headerTable.dispose();\r
+ headerTable = new Table(tableComposite, SWT.NONE);\r
+ headerTable.setHeaderVisible(true);\r
+ headerTable.setLinesVisible(true);\r
+ GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(tableComposite);\r
for (int i = 0; i < headerTable.getColumns().length; i++) {\r
TableColumn column = headerTable.getColumns()[i];\r
column.dispose();\r
} catch (IOException e) {\r
setErrorMessage(e.getMessage());\r
}\r
- headerTable.setRedraw(true);\r
}\r
\r
}\r
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
bin.includes = plugin.xml,\\r
META-INF/,\\r
.,\\r
- graph.tg\r
+ graph.tg,\\r
+ scl/\r
MOD = <http://www.simantics.org/Modeling-1.2>
VP = <http://www.simantics.org/Viewpoint-1.2>
IMAGE = <http://www.simantics.org/Image2-1.2>
+SEL = <http://www.simantics.org/SelectionView-1.2>
MBC = MOD.ModelingBrowseContext
DN = <http://www.simantics.org/DistrictNetwork-1.0> : L0.Ontology
@L0.new
+ L0.Ontology.global true
L0.HasResourceClass "org.simantics.district.network.ontology.DistrictNetworkResource"
+DN.Layer <T DIA.Layer
+
DN.Edge <T DIA.Element : L0.Type
+ @L0.assert DN.HasMapping ""
+ @L0.assert DN.Bidirectional false
+ @L0.assert DN.Edge.HasDiameter 1
DN.Vertex <T DIA.Element : L0.Type
+ @L0.assert DN.HasMapping ""
+ @L0.assert DN.Bidirectional false
+
+DN.Bidirectional <R L0.HasProperty : SEL.GenericParameterType
+ L0.HasLabel "Is network bidirectional"
+ L0.HasRange L0.Boolean
+ L0.readOnly false
+
+DN.EdgeDefaultMapping <R L0.HasProperty : SEL.GenericParameterType
+ L0.HasLabel "Default Edge mapping"
+ L0.HasRange L0.String
+ L0.readOnly false
+
+DN.VertexDefaultMapping <R L0.HasProperty : SEL.GenericParameterType
+ L0.HasLabel "Default Vertex mapping"
+ L0.HasRange L0.String
+ L0.readOnly false
+
+DN.HasMapping <R L0.HasProperty : SEL.GenericParameterType
+ L0.HasLabel "Mapping"
+ L0.HasRange DN.Mapping.EdgeMapping
+ L0.readOnly false
+
+DN.Edge.HasDiameter <R L0.HasProperty : SEL.GenericParameterType
+ L0.HasLabel "Diameter"
+ L0.HasRange L0.Double
+ L0.readOnly false
+
+DN.InLayer
+ @L0.defTag
+ @L0.tag L0.Abstract
+
+DN.HasInLayerTag <R L0.HasProperty
+ L0.HasRange L0.Tag
DN.Connection <T DIA.Connection
DN.Diagram <T DIA.Diagram
+ @L0.assert DN.VertexDefaultMapping ""
+ @L0.assert DN.EdgeDefaultMapping ""
+
+DN.AddLayerToDNDiagramTemplate <T L0.Template
+
+DN.EPSG_4326 <T DN.SpatialRefSystem
+ DN.HasSRID 4326
+ DN.HasSRTEXT _ : L0.String
+ @L0.loadString "epsg/EPSG_4326"
+DN.SpatialRefSystem <T L0.Entity
+
+DN.HasSpatialRefSystem <R L0.HasProperty
+ L0.HasRange DN.SpatialRefSystem
+
+DN.HasSRID <R L0.HasProperty
+ L0.HasRange L0.Integer
+
+DN.HasSRTEXT <R L0.HasProperty
+ L0.HasRange L0.String
DN.Composite <T STR.Composite
@L0.assert MOD.HasModelingTemplate
_ : MOD.DiagramTemplate
MOD.HasDiagramType DN.Diagram
+ @L0.assert MOD.HasModelingTemplate
+ _ : DN.AddLayerToDNDiagramTemplate
-DN.HasStartVertex <R L0.HasProperty
+DN.HasStartVertex <R L0.DependsOn
+ L0.HasDomain DN.Edge
L0.HasRange DN.Vertex
+ L0.InverseOf DN.HasStartVertex_Inverse <R L0.IsRelatedTo
-DN.HasEndVertex <R L0.HasProperty
+DN.HasEndVertex <R L0.DependsOn
+ L0.HasDomain DN.Edge
L0.HasRange DN.Vertex
+ L0.InverseOf DN.HasEndVertex_Inverse <R L0.IsRelatedTo
DNAC.newDiagramContribution : L0.Template
@template %actionContext %label %image %action
IMAGES.ConfigurationFolder : IMAGE.PngImage
@L0.loadBytes "images/Configuration.png"
+
+
+// Component MAPPING
+DN.Mapping <T L0.Library
+
+DN.Mapping.Terminal <T L0.Entity
+
+DN.Mapping.TerminalPair <T L0.Entity
+ >-- DN.Mapping.InputTerminal --> DN.Mapping.Terminal <R L0.HasProperty
+ >-- DN.Mapping.OutputTerminal --> DN.Mapping.Terminal <R L0.HasProperty
+
+DN.Mapping.VertexMapping <T L0.Entity
+ >-- DN.Mapping.ComponentType --> STR.ComponentType <R L0.HasProperty
+ >-- DN.Mapping.VertexMapping.ElevationAttribute --> L0.String <R L0.HasProperty
+ >-- DN.Mapping.Terminals --> DN.Mapping.TerminalPair <R L0.HasProperty
+
+DN.Mapping.EdgeMapping <T L0.Entity
+ >-- DN.Mapping.ComponentType
+ >-- DN.Mapping.EdgeMapping.Bidirectional --> L0.Boolean <R L0.HasProperty
+ >-- DN.Mapping.EdgeMapping.LengthAttribute --> L0.String <R L0.HasProperty
+ >-- DN.Mapping.EdgeMapping.DiameterAttribute --> L0.String <R L0.HasProperty
+ >-- DN.Mapping.Terminals
--- /dev/null
+test
\ No newline at end of file
--- /dev/null
+data VertexMapping = VertexMapping {\r
+ componentType :: String,\r
+ elevationAttribute :: String,\r
+ terminals :: [TerminalPair]\r
+}\r
+\r
+data TerminalPair = TerminalPair {\r
+ inputTerminal :: String,\r
+ outputTerminal :: String\r
+}\r
+\r
+data EdgeMapping = EdgeMapping {\r
+ componentType :: String,\r
+ bidirectional :: Boolean,\r
+ lengthAttribute :: String,\r
+ diameterAttribute :: String,\r
+ terminals :: [TerminalPair]\r
+}
\ No newline at end of file
public final Resource ActionContext_newDiagramContribution;\r
public final Resource Actions;\r
public final Resource Actions_NewDNDiagram;\r
+ public final Resource AddLayerToDNDiagramTemplate;\r
+ public final Resource Bidirectional;\r
+ public final Resource Bidirectional_Inverse;\r
public final Resource Composite;\r
public final Resource Connection;\r
public final Resource Diagram;\r
+ public final Resource EPSG_4326;\r
public final Resource Edge;\r
+ public final Resource EdgeDefaultMapping;\r
+ public final Resource EdgeDefaultMapping_Inverse;\r
+ public final Resource Edge_HasDiameter;\r
+ public final Resource Edge_HasDiameter_Inverse;\r
public final Resource HasEndVertex;\r
public final Resource HasEndVertex_Inverse;\r
+ public final Resource HasInLayerTag;\r
+ public final Resource HasInLayerTag_Inverse;\r
+ public final Resource HasMapping;\r
+ public final Resource HasMapping_Inverse;\r
+ public final Resource HasSRID;\r
+ public final Resource HasSRID_Inverse;\r
+ public final Resource HasSRTEXT;\r
+ public final Resource HasSRTEXT_Inverse;\r
+ public final Resource HasSpatialRefSystem;\r
+ public final Resource HasSpatialRefSystem_Inverse;\r
public final Resource HasStartVertex;\r
public final Resource HasStartVertex_Inverse;\r
public final Resource Images;\r
public final Resource Images_ConfigurationFolder;\r
+ public final Resource InLayer;\r
+ public final Resource Layer;\r
+ public final Resource Mapping;\r
+ public final Resource Mapping_ComponentType;\r
+ public final Resource Mapping_ComponentType_Inverse;\r
+ public final Resource Mapping_EdgeMapping;\r
+ public final Resource Mapping_EdgeMapping_Bidirectional;\r
+ public final Resource Mapping_EdgeMapping_Bidirectional_Inverse;\r
+ public final Resource Mapping_EdgeMapping_DiameterAttribute;\r
+ public final Resource Mapping_EdgeMapping_DiameterAttribute_Inverse;\r
+ public final Resource Mapping_EdgeMapping_LengthAttribute;\r
+ public final Resource Mapping_EdgeMapping_LengthAttribute_Inverse;\r
+ public final Resource Mapping_InputTerminal;\r
+ public final Resource Mapping_InputTerminal_Inverse;\r
+ public final Resource Mapping_OutputTerminal;\r
+ public final Resource Mapping_OutputTerminal_Inverse;\r
+ public final Resource Mapping_Terminal;\r
+ public final Resource Mapping_TerminalPair;\r
+ public final Resource Mapping_Terminals;\r
+ public final Resource Mapping_Terminals_Inverse;\r
+ public final Resource Mapping_VertexMapping;\r
+ public final Resource Mapping_VertexMapping_ElevationAttribute;\r
+ public final Resource Mapping_VertexMapping_ElevationAttribute_Inverse;\r
+ public final Resource SpatialRefSystem;\r
public final Resource Vertex;\r
+ public final Resource VertexDefaultMapping;\r
+ public final Resource VertexDefaultMapping_Inverse;\r
\r
public static class URIs {\r
public static final String ActionContext = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext";\r
public static final String ActionContext_newDiagramContribution = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext/newDiagramContribution";\r
public static final String Actions = "http://www.simantics.org/DistrictNetwork-1.0/Actions";\r
public static final String Actions_NewDNDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Actions/NewDNDiagram";\r
+ public static final String AddLayerToDNDiagramTemplate = "http://www.simantics.org/DistrictNetwork-1.0/AddLayerToDNDiagramTemplate";\r
+ public static final String Bidirectional = "http://www.simantics.org/DistrictNetwork-1.0/Bidirectional";\r
+ public static final String Bidirectional_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Bidirectional/Inverse";\r
public static final String Composite = "http://www.simantics.org/DistrictNetwork-1.0/Composite";\r
public static final String Connection = "http://www.simantics.org/DistrictNetwork-1.0/Connection";\r
public static final String Diagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram";\r
+ public static final String EPSG_4326 = "http://www.simantics.org/DistrictNetwork-1.0/EPSG_4326";\r
public static final String Edge = "http://www.simantics.org/DistrictNetwork-1.0/Edge";\r
+ public static final String EdgeDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/EdgeDefaultMapping";\r
+ public static final String EdgeDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/EdgeDefaultMapping/Inverse";\r
+ public static final String Edge_HasDiameter = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter";\r
+ public static final String Edge_HasDiameter_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter/Inverse";\r
public static final String HasEndVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex";\r
- public static final String HasEndVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex/Inverse";\r
+ public static final String HasEndVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex_Inverse";\r
+ public static final String HasInLayerTag = "http://www.simantics.org/DistrictNetwork-1.0/HasInLayerTag";\r
+ public static final String HasInLayerTag_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasInLayerTag/Inverse";\r
+ public static final String HasMapping = "http://www.simantics.org/DistrictNetwork-1.0/HasMapping";\r
+ public static final String HasMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasMapping/Inverse";\r
+ public static final String HasSRID = "http://www.simantics.org/DistrictNetwork-1.0/HasSRID";\r
+ public static final String HasSRID_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSRID/Inverse";\r
+ public static final String HasSRTEXT = "http://www.simantics.org/DistrictNetwork-1.0/HasSRTEXT";\r
+ public static final String HasSRTEXT_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSRTEXT/Inverse";\r
+ public static final String HasSpatialRefSystem = "http://www.simantics.org/DistrictNetwork-1.0/HasSpatialRefSystem";\r
+ public static final String HasSpatialRefSystem_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSpatialRefSystem/Inverse";\r
public static final String HasStartVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex";\r
- public static final String HasStartVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex/Inverse";\r
+ public static final String HasStartVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex_Inverse";\r
public static final String Images = "http://www.simantics.org/DistrictNetwork-1.0/Images";\r
public static final String Images_ConfigurationFolder = "http://www.simantics.org/DistrictNetwork-1.0/Images/ConfigurationFolder";\r
+ public static final String InLayer = "http://www.simantics.org/DistrictNetwork-1.0/InLayer";\r
+ public static final String Layer = "http://www.simantics.org/DistrictNetwork-1.0/Layer";\r
+ public static final String Mapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping";\r
+ public static final String Mapping_ComponentType = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/ComponentType";\r
+ public static final String Mapping_ComponentType_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/ComponentType/Inverse";\r
+ public static final String Mapping_EdgeMapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping";\r
+ public static final String Mapping_EdgeMapping_Bidirectional = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/Bidirectional";\r
+ public static final String Mapping_EdgeMapping_Bidirectional_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/Bidirectional/Inverse";\r
+ public static final String Mapping_EdgeMapping_DiameterAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/DiameterAttribute";\r
+ public static final String Mapping_EdgeMapping_DiameterAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/DiameterAttribute/Inverse";\r
+ public static final String Mapping_EdgeMapping_LengthAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/LengthAttribute";\r
+ public static final String Mapping_EdgeMapping_LengthAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/LengthAttribute/Inverse";\r
+ public static final String Mapping_InputTerminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/InputTerminal";\r
+ public static final String Mapping_InputTerminal_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/InputTerminal/Inverse";\r
+ public static final String Mapping_OutputTerminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/OutputTerminal";\r
+ public static final String Mapping_OutputTerminal_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/OutputTerminal/Inverse";\r
+ public static final String Mapping_Terminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminal";\r
+ public static final String Mapping_TerminalPair = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/TerminalPair";\r
+ public static final String Mapping_Terminals = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminals";\r
+ public static final String Mapping_Terminals_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminals/Inverse";\r
+ public static final String Mapping_VertexMapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping";\r
+ public static final String Mapping_VertexMapping_ElevationAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/ElevationAttribute";\r
+ public static final String Mapping_VertexMapping_ElevationAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/ElevationAttribute/Inverse";\r
+ public static final String SpatialRefSystem = "http://www.simantics.org/DistrictNetwork-1.0/SpatialRefSystem";\r
public static final String Vertex = "http://www.simantics.org/DistrictNetwork-1.0/Vertex";\r
+ public static final String VertexDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/VertexDefaultMapping";\r
+ public static final String VertexDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/VertexDefaultMapping/Inverse";\r
}\r
\r
public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
ActionContext_newDiagramContribution = getResourceOrNull(graph, URIs.ActionContext_newDiagramContribution);\r
Actions = getResourceOrNull(graph, URIs.Actions);\r
Actions_NewDNDiagram = getResourceOrNull(graph, URIs.Actions_NewDNDiagram);\r
+ AddLayerToDNDiagramTemplate = getResourceOrNull(graph, URIs.AddLayerToDNDiagramTemplate);\r
+ Bidirectional = getResourceOrNull(graph, URIs.Bidirectional);\r
+ Bidirectional_Inverse = getResourceOrNull(graph, URIs.Bidirectional_Inverse);\r
Composite = getResourceOrNull(graph, URIs.Composite);\r
Connection = getResourceOrNull(graph, URIs.Connection);\r
Diagram = getResourceOrNull(graph, URIs.Diagram);\r
+ EPSG_4326 = getResourceOrNull(graph, URIs.EPSG_4326);\r
Edge = getResourceOrNull(graph, URIs.Edge);\r
+ EdgeDefaultMapping = getResourceOrNull(graph, URIs.EdgeDefaultMapping);\r
+ EdgeDefaultMapping_Inverse = getResourceOrNull(graph, URIs.EdgeDefaultMapping_Inverse);\r
+ Edge_HasDiameter = getResourceOrNull(graph, URIs.Edge_HasDiameter);\r
+ Edge_HasDiameter_Inverse = getResourceOrNull(graph, URIs.Edge_HasDiameter_Inverse);\r
HasEndVertex = getResourceOrNull(graph, URIs.HasEndVertex);\r
HasEndVertex_Inverse = getResourceOrNull(graph, URIs.HasEndVertex_Inverse);\r
+ HasInLayerTag = getResourceOrNull(graph, URIs.HasInLayerTag);\r
+ HasInLayerTag_Inverse = getResourceOrNull(graph, URIs.HasInLayerTag_Inverse);\r
+ HasMapping = getResourceOrNull(graph, URIs.HasMapping);\r
+ HasMapping_Inverse = getResourceOrNull(graph, URIs.HasMapping_Inverse);\r
+ HasSRID = getResourceOrNull(graph, URIs.HasSRID);\r
+ HasSRID_Inverse = getResourceOrNull(graph, URIs.HasSRID_Inverse);\r
+ HasSRTEXT = getResourceOrNull(graph, URIs.HasSRTEXT);\r
+ HasSRTEXT_Inverse = getResourceOrNull(graph, URIs.HasSRTEXT_Inverse);\r
+ HasSpatialRefSystem = getResourceOrNull(graph, URIs.HasSpatialRefSystem);\r
+ HasSpatialRefSystem_Inverse = getResourceOrNull(graph, URIs.HasSpatialRefSystem_Inverse);\r
HasStartVertex = getResourceOrNull(graph, URIs.HasStartVertex);\r
HasStartVertex_Inverse = getResourceOrNull(graph, URIs.HasStartVertex_Inverse);\r
Images = getResourceOrNull(graph, URIs.Images);\r
Images_ConfigurationFolder = getResourceOrNull(graph, URIs.Images_ConfigurationFolder);\r
+ InLayer = getResourceOrNull(graph, URIs.InLayer);\r
+ Layer = getResourceOrNull(graph, URIs.Layer);\r
+ Mapping = getResourceOrNull(graph, URIs.Mapping);\r
+ Mapping_ComponentType = getResourceOrNull(graph, URIs.Mapping_ComponentType);\r
+ Mapping_ComponentType_Inverse = getResourceOrNull(graph, URIs.Mapping_ComponentType_Inverse);\r
+ Mapping_EdgeMapping = getResourceOrNull(graph, URIs.Mapping_EdgeMapping);\r
+ Mapping_EdgeMapping_Bidirectional = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_Bidirectional);\r
+ Mapping_EdgeMapping_Bidirectional_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_Bidirectional_Inverse);\r
+ Mapping_EdgeMapping_DiameterAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_DiameterAttribute);\r
+ Mapping_EdgeMapping_DiameterAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_DiameterAttribute_Inverse);\r
+ Mapping_EdgeMapping_LengthAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_LengthAttribute);\r
+ Mapping_EdgeMapping_LengthAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_LengthAttribute_Inverse);\r
+ Mapping_InputTerminal = getResourceOrNull(graph, URIs.Mapping_InputTerminal);\r
+ Mapping_InputTerminal_Inverse = getResourceOrNull(graph, URIs.Mapping_InputTerminal_Inverse);\r
+ Mapping_OutputTerminal = getResourceOrNull(graph, URIs.Mapping_OutputTerminal);\r
+ Mapping_OutputTerminal_Inverse = getResourceOrNull(graph, URIs.Mapping_OutputTerminal_Inverse);\r
+ Mapping_Terminal = getResourceOrNull(graph, URIs.Mapping_Terminal);\r
+ Mapping_TerminalPair = getResourceOrNull(graph, URIs.Mapping_TerminalPair);\r
+ Mapping_Terminals = getResourceOrNull(graph, URIs.Mapping_Terminals);\r
+ Mapping_Terminals_Inverse = getResourceOrNull(graph, URIs.Mapping_Terminals_Inverse);\r
+ Mapping_VertexMapping = getResourceOrNull(graph, URIs.Mapping_VertexMapping);\r
+ Mapping_VertexMapping_ElevationAttribute = getResourceOrNull(graph, URIs.Mapping_VertexMapping_ElevationAttribute);\r
+ Mapping_VertexMapping_ElevationAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_VertexMapping_ElevationAttribute_Inverse);\r
+ SpatialRefSystem = getResourceOrNull(graph, URIs.SpatialRefSystem);\r
Vertex = getResourceOrNull(graph, URIs.Vertex);\r
+ VertexDefaultMapping = getResourceOrNull(graph, URIs.VertexDefaultMapping);\r
+ VertexDefaultMapping_Inverse = getResourceOrNull(graph, URIs.VertexDefaultMapping_Inverse);\r
}\r
\r
public static DistrictNetworkResource getInstance(ReadGraph graph) {\r
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
<graph />\r
</type>\r
</target>\r
+ \r
+ <target interface="org.simantics.db.layer0.adapter.Remover">\r
+ <type uri="http://www.simantics.org/DistrictNetwork-1.0/Vertex"\r
+ class="org.simantics.district.network.ui.DNElementRemover">\r
+ <this />\r
+ </type>\r
+ <type uri="http://www.simantics.org/DistrictNetwork-1.0/Edge"\r
+ class="org.simantics.district.network.ui.DNElementRemover">\r
+ <this />\r
+ </type>\r
+ </target>\r
+ \r
+ <target interface="org.simantics.db.layer0.adapter.Template">\r
+ <type uri="http://www.simantics.org/DistrictNetwork-1.0/AddLayerToDNDiagramTemplate"\r
+ class="org.simantics.district.network.ui.templates.AddLayerToDNDiagramTemplate">\r
+ <this />\r
+ </type>\r
+ </target>\r
+ \r
+ <target interface="org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil">\r
+ <resource uri="http://www.simantics.org/DistrictNetwork-1.0/Layer"\r
+ class="org.simantics.district.network.ui.DNGraphLayerUtil">\r
+ <this />\r
+ </resource>\r
+ </target>\r
+ \r
</adapters>
\ No newline at end of file
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.ServiceException;\r
import org.simantics.db.layer0.util.Layer0Utils;\r
+import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;\r
+import org.simantics.diagram.synchronization.SynchronizationHints;\r
import org.simantics.diagram.synchronization.graph.AddElement;\r
+import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerManager;\r
+import org.simantics.diagram.ui.DiagramModelHints;\r
import org.simantics.district.network.DistrictNetworkUtil;\r
import org.simantics.district.network.ontology.DistrictNetworkResource;\r
+import org.simantics.g2d.diagram.IDiagram;\r
\r
public class DNEdgeBuilder {\r
\r
private Resource diagramResource;\r
+ private IDiagram diagram;\r
+ private GraphLayerManager glm;\r
\r
- public DNEdgeBuilder(Resource diagramResource) {\r
+ public DNEdgeBuilder(Resource diagramResource, IDiagram diagram) {\r
this.diagramResource = diagramResource;\r
+ this.diagram = diagram;\r
+ \r
+ IModifiableSynchronizationContext context = diagram.getHint(SynchronizationHints.CONTEXT);\r
+ glm = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER);\r
}\r
\r
public void create(WriteGraph graph, double[] start, double[] end) throws DatabaseException {\r
graph.claim(edge, DN.HasStartVertex, startVertex);\r
graph.claim(edge, DN.HasEndVertex, endVertex);\r
\r
+ // 7. Put the element on all the currently active layers if possible.\r
+ if (glm != null) {\r
+ putOnActiveLayer(graph, edge);\r
+ putOnActiveLayer(graph, startVertex);\r
+ putOnActiveLayer(graph, endVertex);\r
+ }\r
+ \r
Layer0Utils.addCommentMetadata(graph, "Added edge " + edge);\r
graph.markUndoPoint();\r
}\r
+ \r
+ private void putOnActiveLayer(WriteGraph graph, Resource res) throws DatabaseException {\r
+ glm.removeFromAllLayers(graph, res);\r
+ glm.putElementOnVisibleLayers(diagram, graph, res);\r
+ }\r
\r
private Resource getOrCreateVertex(WriteGraph graph, double[] coords) throws DatabaseException {\r
// TODO: check if vertex exists already, for now create always new\r
--- /dev/null
+package org.simantics.district.network.ui;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.impl.EntityRemover;\r
+import org.simantics.district.network.ontology.DistrictNetworkResource;\r
+import org.simantics.layer0.utils.binaryPredicates.OrderedSetElementsPredicate;\r
+import org.simantics.modeling.adapters.ElementRemover;\r
+\r
+public class DNElementRemover extends ElementRemover {\r
+\r
+ public DNElementRemover(Resource element) {\r
+ super(element);\r
+ }\r
+ \r
+ @Override\r
+ public void removeConnection(WriteGraph graph) throws DatabaseException {\r
+ throw new UnsupportedOperationException("Distrct network should not have STR.Connection resources! " + resource);\r
+ }\r
+ \r
+ @Override\r
+ public void removeElement(WriteGraph graph) throws DatabaseException {\r
+ \r
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
+ \r
+ if (graph.isInstanceOf(resource, DN.Vertex)) {\r
+ graph.getObjects(resource, DN.HasEndVertex_Inverse).forEach(res -> {\r
+ try {\r
+ doRemove(graph, res);\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ });\r
+ graph.getObjects(resource, DN.HasStartVertex_Inverse).forEach(res -> {\r
+ try {\r
+ doRemove(graph, res);\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ });\r
+ }\r
+ doRemove(graph, resource);\r
+ }\r
+ \r
+ private static void doRemove(WriteGraph graph, Resource resource) throws DatabaseException {\r
+ // 1. Disconnect element from diagrams\r
+ for (Resource diagram : OrderedSetElementsPredicate.INSTANCE.getSubjects(graph, resource)) {\r
+ OrderedSetUtils.remove(graph, diagram, resource);\r
+ }\r
+\r
+ // 2. Delete element itself\r
+ EntityRemover.remove(graph, resource);\r
+\r
+ // 3. Recursively remove all related degenerate connections\r
+ // i.e. connections that only have one connector after remove the\r
+ // one connected to this removed element.\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.district.network.ui;\r
+\r
+import java.util.Collections;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;\r
+import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil;\r
+import org.simantics.district.network.ontology.DistrictNetworkResource;\r
+import org.simantics.layer0.Layer0;\r
+\r
+public class DNGraphLayerUtil implements IGraphLayerUtil {\r
+\r
+ public DNGraphLayerUtil(Resource layer) {\r
+ \r
+ }\r
+\r
+ @Override\r
+ public GraphLayer loadLayer(ReadGraph graph, Resource layer) throws DatabaseException {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
+ String name = graph.getRelatedValue(layer, L0.HasName);\r
+ Resource inLayer = graph.getSingleObject(layer, DN.HasInLayerTag);\r
+ \r
+ Map<String, Resource> properties = new HashMap<>();\r
+ properties.put("IN_LAYER", inLayer);\r
+\r
+ return new GraphLayer(name, layer, properties);\r
+ }\r
+\r
+ @Override\r
+ public GraphLayer createLayer(WriteGraph graph, String layerName, boolean active) throws DatabaseException {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ DiagramResource DIA = DiagramResource.getInstance(graph);\r
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
+ \r
+ \r
+ Resource layer = graph.newResource();\r
+ graph.claim(layer, L0.InstanceOf, null, DN.Layer);\r
+\r
+ // Assign tagging relations\r
+ Resource inLayerTag = GraphLayerUtil.newTag(graph, L0, DN.InLayer);\r
+ graph.claim(layer, DN.HasInLayerTag, inLayerTag);\r
+\r
+ // Assign shared name property for all, the layer and the tags\r
+ Resource name = graph.newResource();\r
+ graph.claim(name, L0.InstanceOf, null, L0.String);\r
+ graph.claimValue(name, layerName);\r
+\r
+ graph.claim(layer, L0.HasName, name);\r
+ graph.claim(inLayerTag, L0.HasName, name);\r
+ \r
+ graph.claim(layer, DN.HasSpatialRefSystem, DN.EPSG_4326);\r
+\r
+ GraphLayerUtil.setLayerActive(graph, DIA, layer, active);\r
+\r
+ return new GraphLayer(layerName, layer, Collections.emptyMap());\r
+ }\r
+\r
+}\r
\r
import java.util.concurrent.TimeUnit;\r
\r
+import org.simantics.district.network.ui.participants.DNPointerInteractor;\r
import org.simantics.g2d.canvas.ICanvasContext;\r
import org.simantics.g2d.diagram.handler.PickRequest.PickFilter;\r
import org.simantics.g2d.diagram.participant.DelayedBatchElementPainter;\r
ctx.add(new ZOrderHandler());\r
ctx.add(new Selection());\r
ctx.add(new ElementPainter());\r
+ ctx.add(new DNPointerInteractor());\r
\r
ctx.add(new NetworkDrawingParticipant());\r
}\r
}\r
\r
public Rectangle2D getBounds(Rectangle2D rect) {\r
- return path.getBounds2D();\r
+ rect.setFrame(path.getBounds2D());\r
+ return rect;\r
}\r
}\r
\r
package org.simantics.district.network.ui;\r
\r
-import java.awt.Color;\r
-import java.awt.Graphics2D;\r
-import java.awt.Shape;\r
-import java.awt.geom.Path2D;\r
-import java.awt.geom.Point2D;\r
-import java.awt.geom.Rectangle2D;\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.HashSet;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import org.simantics.Simantics;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.ui.DiagramModelHints;\r
-import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
+import org.simantics.district.network.ui.nodes.NetworkDrawingNode;\r
import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;\r
import org.simantics.g2d.diagram.IDiagram;\r
-import org.simantics.g2d.diagram.handler.PickContext;\r
-import org.simantics.g2d.diagram.handler.PickRequest;\r
-import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy;\r
import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant;\r
-import org.simantics.g2d.diagram.participant.Selection;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.participant.TransformUtil;\r
-import org.simantics.g2d.utils.GeometryUtils;\r
-import org.simantics.scenegraph.g2d.G2DNode;\r
import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.scenegraph.g2d.events.EventTypes;\r
-import org.simantics.scenegraph.g2d.events.MouseEvent;\r
-import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;\r
-import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent;\r
-import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;\r
-import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;\r
-import org.simantics.scenegraph.utils.NodeUtil;\r
import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
\r
\r
private NetworkDrawingNode node;\r
\r
- @Dependency Selection selection;\r
- @Dependency TransformUtil util;\r
- @Dependency PickContext pickContext;\r
- \r
@SGInit\r
public void initSG(G2DParentNode parent) {\r
node = parent.addNode("networkDrawingNode", NetworkDrawingNode.class);\r
+ node.setNetworkDrawingParticipant(this);\r
}\r
\r
@Override\r
protected void onDiagramSet(IDiagram newDiagram, IDiagram oldDiagram) {\r
node.setDiagram(newDiagram);\r
}\r
- \r
- @EventHandler(priority = 1 << 21)\r
- public boolean handleClick(MouseClickEvent me) {\r
- \r
- boolean isLeft = me.button == MouseEvent.LEFT_BUTTON;\r
- boolean isRight = me.button == MouseEvent.RIGHT_BUTTON;\r
- if (!isLeft && !isRight)\r
- return false;\r
- boolean isShiftPressed = me.hasAllModifiers(MouseEvent.SHIFT_MASK);\r
- \r
- int selectionId = me.mouseId;\r
- \r
- double pickDist = getPickDistance();\r
- Rectangle2D controlPickRect = new Rectangle2D.Double(me.controlPosition.getX()-pickDist, me.controlPosition.getY()-pickDist, pickDist*2+1, pickDist*2+1);\r
- Shape canvasPickRect = GeometryUtils.transformShape(controlPickRect, util.getInverseTransform());\r
- \r
- PickRequest req = new PickRequest(canvasPickRect);\r
- req.pickPolicy = PickPolicy.PICK_INTERSECTING_OBJECTS;\r
- //req.pickSorter = PickRequest.PickSorter.CONNECTIONS_LAST;\r
- List<IElement> pickables = new ArrayList<IElement>();\r
- pickContext.pick(diagram, req, pickables);\r
- \r
- Set<IElement> currentSelection = selection.getSelection(selectionId);\r
- \r
- if (!pickables.isEmpty()) {\r
- /*\r
- * Select the one object the mouse points to. If multiple object\r
- * are picked, select the one that is after the earliest by\r
- * index of the current selection when shift is pressed. Otherwise\r
- * always pick the topmost element.\r
- */\r
- IElement selectedPick = isShiftPressed\r
- ? rotatingPick(currentSelection, pickables)\r
- : pickables.get(pickables.size() - 1);\r
- \r
- // Only select when\r
- // 1. the selection would actually change\r
- // AND\r
- // 2.1. left button was pressed\r
- // OR\r
- // 2.2. right button was pressed and the element to-be-selected\r
- // is NOT a part of the current selection\r
- if (!Collections.singleton(selectedPick).equals(currentSelection)\r
- && (isLeft || (isRight && !currentSelection.contains(selectedPick)))) {\r
- selection.setSelection(selectionId, selectedPick);\r
- }\r
- }\r
- \r
- return false;\r
- }\r
- \r
- private double getPickDistance() {\r
- Double pickDistance = getHint(KEY_PICK_DISTANCE);\r
- return pickDistance == null ? PICK_DIST : Math.max(pickDistance, 0);\r
- }\r
- \r
- private IElement rotatingPick(int selectionId, List<IElement> pickables) {\r
- Set<IElement> sel = selection.getSelection(selectionId);\r
- return rotatingPick(sel, pickables);\r
- }\r
\r
- private IElement rotatingPick(Set<IElement> sel, List<IElement> pickables) {\r
- int earliestIndex = pickables.size();\r
- for (int i = pickables.size() - 1; i >= 0; --i) {\r
- if (sel.contains(pickables.get(i))) {\r
- earliestIndex = i;\r
- break;\r
- }\r
- }\r
- if (earliestIndex == 0)\r
- earliestIndex = pickables.size();\r
- IElement selectedPick = pickables.get(earliestIndex - 1);\r
- return selectedPick;\r
- }\r
-\r
- public static class NetworkDrawingNode extends G2DNode {\r
-\r
- private static final long serialVersionUID = -3475301184009620573L;\r
- \r
- private List<Point2D> nodes = new ArrayList<>();\r
-\r
- private Rectangle2D rect = new Rectangle2D.Double(10, 10, 10, 10);\r
-\r
- private Set<Path2D> paths = new HashSet<>();\r
-\r
- private Resource diagramResource;\r
-\r
- private boolean committed;\r
- \r
- @Override\r
- public void init() {\r
- super.init();\r
- addEventHandler(this);\r
- }\r
- \r
- public void setDiagram(IDiagram diagram) {\r
- if (diagram != null)\r
- this.diagramResource = diagram.getHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE);\r
- }\r
-\r
- @Override\r
- public void render(Graphics2D g2d) {\r
- Color old = g2d.getColor();\r
- g2d.setColor(Color.BLUE);\r
- \r
- paths.forEach(p -> {\r
- g2d.draw(p);\r
- });\r
- \r
- g2d.setColor(old);\r
- }\r
-\r
- @Override\r
- public Rectangle2D getBoundsInLocal() {\r
- return rect.getBounds2D();\r
- }\r
- \r
- @Override\r
- public int getEventMask() {\r
- return EventTypes.MouseMask;\r
- }\r
- \r
- @Override\r
- protected boolean mouseDoubleClicked(MouseDoubleClickedEvent e) {\r
- // nodes to path2d\r
- Point2D start = null;\r
- Point2D end = null;\r
- Iterator<Point2D> nodeIter = nodes.iterator();\r
- while (nodeIter.hasNext()) {\r
- if (end == null) {\r
- start = nodeIter.next();\r
- } else {\r
- start = end;\r
- }\r
- end = nodeIter.next();\r
- \r
- createEdge(start, end);\r
- }\r
- \r
- nodes.clear();\r
- committed = true;\r
- \r
- repaint();\r
- \r
- return true;\r
- }\r
- \r
- private void createEdge(Point2D start, Point2D end) {\r
- double[] startCoords = new double[] { start.getX(), start.getY() };\r
- double[] endCoords = new double[] { end.getX(), end.getY() };\r
- \r
- DNEdgeBuilder builder = new DNEdgeBuilder(diagramResource);\r
- Simantics.getSession().asyncRequest(new WriteRequest() {\r
- \r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- builder.create(graph, startCoords, endCoords);\r
- }\r
- });\r
- \r
- }\r
- \r
- @Override\r
- protected boolean mouseClicked(MouseClickEvent e) {\r
- if (committed) {\r
- committed = false;\r
- return false;\r
- }\r
- Point2D localPos = NodeUtil.worldToLocal(this, e.controlPosition, new Point2D.Double());\r
- nodes.add(new Point2D.Double(localPos.getX(), localPos.getY()));\r
- return super.mouseClicked(e);\r
- }\r
- \r
- @Override\r
- protected boolean mouseMoved(MouseMovedEvent e) {\r
- return super.mouseMoved(e);\r
- }\r
- }\r
}\r
import org.simantics.g2d.element.SceneGraphNodeKey;\r
import org.simantics.g2d.element.handler.InternalSize;\r
import org.simantics.g2d.element.handler.SceneGraph;\r
-import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform;\r
+import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
import org.simantics.scenegraph.g2d.G2DParentNode;\r
import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
\r
public static final ElementClass CLASS =\r
ElementClass.compile(\r
- FixedTransform.INSTANCE,\r
+ DefaultTransform.INSTANCE,\r
DNEdgeInternalSize.INSTANCE,\r
DNEdgeSceneGraph.INSTANCE\r
).setId(DistrictNetworkEdgeElement.class.getSimpleName());\r
@Override\r
public Rectangle2D getBounds(IElement e, Rectangle2D size) {\r
DistrictNetworkEdge edge = e.getHint(KEY_DN_EDGE);\r
- return edge.getBounds(size);\r
+ if (size == null)\r
+ size = new Rectangle2D.Double();\r
+ edge.getBounds(size);\r
+\r
+ return size;\r
}\r
\r
}\r
package org.simantics.district.network.ui.adapters;\r
\r
import java.awt.Dimension;\r
+import java.awt.geom.AffineTransform;\r
import java.awt.geom.Rectangle2D;\r
\r
import org.simantics.district.network.ui.nodes.DistrictNetworkVertexNode;\r
import org.simantics.g2d.element.SceneGraphNodeKey;\r
import org.simantics.g2d.element.handler.InternalSize;\r
import org.simantics.g2d.element.handler.SceneGraph;\r
-import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform;\r
+import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
import org.simantics.scenegraph.g2d.G2DParentNode;\r
import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
\r
public static final ElementClass CLASS =\r
ElementClass.compile(\r
- FixedTransform.INSTANCE,\r
+ DefaultTransform.INSTANCE,\r
DNVertexInternalSize.INSTANCE,\r
DNVertexSceneGraph.INSTANCE\r
).setId(DistrictNetworkVertexElement.class.getSimpleName());\r
edgeElement.setHint(KEY_DN_VERTEX_NODE, node);\r
}\r
node.setVertex(vertex);\r
+ \r
+ AffineTransform at = ElementUtils.getTransform(edgeElement);\r
+ if(at != null)\r
+ node.setTransform(at);\r
}\r
}\r
\r
\r
@Override\r
public Rectangle2D getBounds(IElement e, Rectangle2D size) {\r
- DistrictNetworkVertex vertex = e.getHint(KEY_DN_VERTEX);\r
if (size == null)\r
size = new Rectangle2D.Double();\r
- size.setFrame(vertex.getPoint(), new Dimension(1, 1));\r
+ size.setFrame(-0.5, -0.5, 1, 1);\r
return size;\r
}\r
\r
package org.simantics.district.network.ui.adapters;\r
\r
+import java.awt.geom.AffineTransform;\r
+\r
import org.simantics.db.AsyncReadGraph;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.g2d.canvas.ICanvasContext;\r
import org.simantics.g2d.diagram.IDiagram;\r
import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.ElementUtils;\r
import org.simantics.g2d.element.IElement;\r
import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
\r
}\r
\r
@Override\r
- public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType,\r
- AsyncProcedure<ElementClass> procedure) {\r
+ public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure) {\r
procedure.execute(graph, CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));\r
}\r
\r
public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource vertexResource, IElement element) throws DatabaseException {\r
\r
double[] coords = graph.getRelatedValue(vertexResource, DIA.HasLocation);\r
- \r
DistrictNetworkVertex vertex = new DistrictNetworkVertex(coords);\r
- \r
element.setHint(DistrictNetworkVertexElement.KEY_DN_VERTEX, vertex);\r
+ \r
+ // set element transform based on layer SRS and coords\r
+ AffineTransform at = new AffineTransform(1, 0, 0, 1, coords[0], coords[1]);\r
+ ElementUtils.setTransform(element, at);\r
}\r
}\r
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);\r
\r
Color oldColor = g2d.getColor();\r
- boolean selected = isSelected();\r
- if (selected) {\r
- Path2D selectionPath = edge.getPath();\r
- Shape selectionShape = SELECTION_STROKE.createStrokedShape(selectionPath);\r
- g2d.setColor(SELECTION_COLOR);\r
- g2d.fill(selectionShape);\r
- }\r
- \r
+// boolean selected = isSelected();\r
+// if (selected) {\r
+// Path2D selectionPath = edge.getPath();\r
+// Shape selectionShape = SELECTION_STROKE.createStrokedShape(selectionPath);\r
+// g2d.setColor(SELECTION_COLOR);\r
+// g2d.fill(selectionShape);\r
+// }\r
+// \r
g2d.setColor(Color.BLUE);\r
// render\r
g2d.draw(edge.getPath());\r
\r
public void setDNEdge(DistrictNetworkEdge edge) {\r
this.edge = edge;\r
+ updateBounds();\r
}\r
\r
}\r
g2d.setColor(Color.RED);\r
// render\r
\r
- Rectangle2D.Double rect = new Rectangle2D.Double(vertex.getPoint().getX() - 0.5, vertex.getPoint().getY() - 0.5, 1, 1);\r
+ Rectangle2D.Double rect = new Rectangle2D.Double(-0.5, -0.5, 1, 1);\r
g2d.draw(rect);\r
\r
// Reset stats\r
\r
@Override\r
public Rectangle2D getBoundsInLocal() {\r
- return new Rectangle2D.Double(vertex.getPoint().getX(), vertex.getPoint().getY(), 1, 1);\r
+ return new Rectangle2D.Double(-0.5, -0.5, 1, 1);\r
}\r
\r
public void setVertex(DistrictNetworkVertex vertex) {\r
--- /dev/null
+package org.simantics.district.network.ui.nodes;\r
+\r
+import java.awt.Color;\r
+import java.awt.Graphics2D;\r
+import java.awt.geom.Path2D;\r
+import java.awt.geom.Point2D;\r
+import java.awt.geom.Rectangle2D;\r
+import java.util.ArrayList;\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Set;\r
+\r
+import org.simantics.Simantics;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.ui.DiagramModelHints;\r
+import org.simantics.district.network.ui.DNEdgeBuilder;\r
+import org.simantics.district.network.ui.NetworkDrawingParticipant;\r
+import org.simantics.g2d.canvas.Hints;\r
+import org.simantics.g2d.canvas.IToolMode;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.scenegraph.g2d.G2DNode;\r
+import org.simantics.scenegraph.g2d.events.EventTypes;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;\r
+import org.simantics.scenegraph.utils.NodeUtil;\r
+\r
+public class NetworkDrawingNode extends G2DNode {\r
+\r
+ private static final long serialVersionUID = -3475301184009620573L;\r
+ \r
+ private List<Point2D> nodes = new ArrayList<>();\r
+\r
+ private Rectangle2D rect = new Rectangle2D.Double(10, 10, 10, 10);\r
+\r
+ private Set<Path2D> paths = new HashSet<>();\r
+\r
+ private Resource diagramResource;\r
+\r
+ private boolean committed;\r
+\r
+ private NetworkDrawingParticipant participant;\r
+\r
+ private IDiagram diagram;\r
+ \r
+ @Override\r
+ public void init() {\r
+ super.init();\r
+ addEventHandler(this);\r
+ }\r
+ \r
+ public void setNetworkDrawingParticipant(NetworkDrawingParticipant participant) {\r
+ this.participant = participant;\r
+ }\r
+ \r
+ public void setDiagram(IDiagram diagram) {\r
+ if (diagram != null) {\r
+ this.diagram = diagram;\r
+ this.diagramResource = diagram.getHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void render(Graphics2D g2d) {\r
+ Color old = g2d.getColor();\r
+ g2d.setColor(Color.BLUE);\r
+ \r
+ paths.forEach(p -> {\r
+ g2d.draw(p);\r
+ });\r
+ \r
+ g2d.setColor(old);\r
+ }\r
+\r
+ @Override\r
+ public Rectangle2D getBoundsInLocal() {\r
+ return rect.getBounds2D();\r
+ }\r
+ \r
+ @Override\r
+ public int getEventMask() {\r
+ return EventTypes.MouseMask;\r
+ }\r
+ \r
+ @Override\r
+ protected boolean mouseDoubleClicked(MouseDoubleClickedEvent e) {\r
+ // nodes to path2d\r
+ IToolMode mode = getToolMode();\r
+ if (mode == Hints.CONNECTTOOL || e.hasAnyModifier(MouseEvent.ALT_MASK | MouseEvent.ALT_GRAPH_MASK)) {\r
+ Point2D start = null;\r
+ Point2D end = null;\r
+ Iterator<Point2D> nodeIter = nodes.iterator();\r
+ while (nodeIter.hasNext()) {\r
+ if (end == null) {\r
+ start = nodeIter.next();\r
+ } else {\r
+ start = end;\r
+ }\r
+ end = nodeIter.next();\r
+ \r
+ createEdge(start, end);\r
+ }\r
+ \r
+ nodes.clear();\r
+ committed = true;\r
+ \r
+ repaint();\r
+ \r
+ return true;\r
+ }\r
+ return super.mouseDoubleClicked(e);\r
+ }\r
+ \r
+ private void createEdge(Point2D start, Point2D end) {\r
+ double[] startCoords = new double[] { start.getX(), start.getY() };\r
+ double[] endCoords = new double[] { end.getX(), end.getY() };\r
+ \r
+ DNEdgeBuilder builder = new DNEdgeBuilder(diagramResource, diagram);\r
+ Simantics.getSession().asyncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ builder.create(graph, startCoords, endCoords);\r
+ }\r
+ });\r
+ \r
+ }\r
+ \r
+ @Override\r
+ protected boolean mouseClicked(MouseClickEvent e) {\r
+ // check ToolMode\r
+ IToolMode mode = getToolMode();\r
+ if (mode == Hints.CONNECTTOOL || e.hasAnyModifier(MouseEvent.ALT_MASK | MouseEvent.ALT_GRAPH_MASK)) {\r
+ if (committed) {\r
+ committed = false;\r
+ return false;\r
+ }\r
+ Point2D localPos = NodeUtil.worldToLocal(this, e.controlPosition, new Point2D.Double());\r
+ nodes.add(new Point2D.Double(localPos.getX(), localPos.getY()));\r
+ }\r
+ return super.mouseClicked(e);\r
+ }\r
+ \r
+ private IToolMode getToolMode() {\r
+ return participant.getHint(Hints.KEY_TOOL);\r
+ }\r
+\r
+ @Override\r
+ protected boolean mouseMoved(MouseMovedEvent e) {\r
+ return super.mouseMoved(e);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package org.simantics.district.network.ui.participants;\r
+\r
+import java.awt.geom.Point2D;\r
+import java.util.Set;\r
+\r
+import org.simantics.g2d.canvas.ICanvasParticipant;\r
+import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;\r
+import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo;\r
+import org.simantics.g2d.element.IElement;\r
+\r
+public class DNPointerInteractor extends PointerInteractor {\r
+\r
+ @Override\r
+ protected ICanvasParticipant createConnectTool(TerminalInfo ti, int mouseId, Point2D startCanvasPos) {\r
+ return super.createConnectTool(ti, mouseId, startCanvasPos);\r
+ }\r
+ \r
+ @Override\r
+ protected ICanvasParticipant createTranslateTool(int mouseId, Point2D startCanvasPos, Point2D curCanvasPos, Set<IElement> elementsToDrag) {\r
+ return new DNTranslateMode(startCanvasPos, curCanvasPos, mouseId, elementsToDrag);\r
+ }\r
+}\r
--- /dev/null
+package org.simantics.district.network.ui.participants;\r
+\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Point2D;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.Simantics;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.CommentMetadata;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.elements.ElementTransforms;\r
+import org.simantics.diagram.elements.ElementTransforms.TransformedObject;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.district.network.ontology.DistrictNetworkResource;\r
+import org.simantics.g2d.canvas.Hints;\r
+import org.simantics.g2d.diagram.participant.pointertool.TranslateMode;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.Move;\r
+\r
+public class DNTranslateMode extends TranslateMode {\r
+\r
+ public DNTranslateMode(Point2D startingPoint, Point2D currentPoint, int mouseId, Collection<IElement> elements) {\r
+ super(startingPoint, currentPoint, mouseId, elements);\r
+ }\r
+ \r
+ @Override\r
+ protected boolean commit() {\r
+ for (IElement el : elementsToReallyTranslate) {\r
+ Move move = el.getElementClass().getAtMostOneItemOfClass(Move.class);\r
+ if (move != null) {\r
+ Point2D oldPos = move.getPosition(el);\r
+ move.moveTo(el, oldPos.getX() + dx, oldPos.getY() + dy);\r
+ }\r
+ }\r
+ try {\r
+ Simantics.getSession().syncRequest(new WriteRequest() {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Collection<TransformedObject> transformed = new ArrayList<TransformedObject>();\r
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
+ DiagramResource DIA = DiagramResource.getInstance(graph);\r
+ for (IElement e : elementsToReallyTranslate) {\r
+ Object obj = ElementUtils.getObject(e);\r
+ if (obj instanceof Resource) {\r
+ Resource res = (Resource) obj;\r
+ if (graph.isInstanceOf(res, DN.Vertex)) {\r
+ AffineTransform at = ElementUtils.getLocalTransform(e, new AffineTransform());\r
+ transformed.add( new TransformedObject((Resource) obj, at) );\r
+ \r
+ \r
+ // write to db\r
+ double[] coords = new double[] { at.getTranslateX(), at.getTranslateY() };\r
+ graph.claimLiteral(res, DIA.HasLocation, coords);\r
+ }\r
+ }\r
+ }\r
+ \r
+ if (!transformed.isEmpty()) {\r
+ CommentMetadata cm = graph.getMetadata(CommentMetadata.class);\r
+ graph.addMetadata(cm.add("Translated " + transformed.size() + " "\r
+ + (transformed.size() == 1 ? "element" : "elements")\r
+ + " by (" + dx + "," + dy + ") mm."));\r
+ graph.markUndoPoint();\r
+ }\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ for (IElement dirty : elementsToDirty)\r
+ dirty.setHint(Hints.KEY_DIRTY, Hints.VALUE_SG_DIRTY);\r
+\r
+ setDirty();\r
+ remove();\r
+ return false;\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.district.network.ui.templates;\r
+\r
+import java.util.Map;\r
+import java.util.UUID;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.Template;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
+import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil;\r
+import org.simantics.district.network.ontology.DistrictNetworkResource;\r
+\r
+public class AddLayerToDNDiagramTemplate implements Template {\r
+\r
+ Resource template;\r
+ \r
+ public AddLayerToDNDiagramTemplate(Resource template) {\r
+ this.template = template;\r
+ }\r
+ \r
+ @Override\r
+ public void apply(WriteGraph graph, Map<String, Object> parameters) throws DatabaseException {\r
+ Resource diagram = (Resource)parameters.get("diagram");\r
+ if (diagram == null) {\r
+ diagram = graph.newResource();\r
+ parameters.put("diagram", diagram);\r
+ }\r
+ \r
+ DiagramResource DIA = DiagramResource.getInstance(graph);\r
+ IGraphLayerUtil layerUtil = graph.adapt(DistrictNetworkResource.getInstance(graph).Layer, IGraphLayerUtil.class);\r
+ GraphLayer layer = layerUtil.createLayer(graph, UUID.randomUUID().toString(), true);\r
+ \r
+ // Create layer\r
+ graph.claim(diagram, DIA.HasLayer, layer.getLayer());\r
+ \r
+ }\r
+\r
+}\r
public static Resource createEdge(WriteGraph graph, Resource composite) throws DatabaseException {\r
Layer0 L0 = Layer0.getInstance(graph);\r
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
- DiagramResource DIA = DiagramResource.getInstance(graph);\r
\r
Resource edge = graph.newResource();\r
graph.claim(edge, L0.InstanceOf, DN.Edge);\r
version="0.0.0"\r
unpack="false"/>\r
\r
+ <plugin\r
+ id="org.simantics.district.network.ui.ontology"\r
+ download-size="0"\r
+ install-size="0"\r
+ version="0.0.0"\r
+ unpack="false"/>\r
+\r
</feature>\r