org.simantics.modeling.ui;bundle-version="1.0.0",
org.eclipse.ui.cheatsheets,
org.simantics.graphviz.ui;bundle-version="1.0.0",
- org.simantics.graphviz;bundle-version="1.0.0"
+ org.simantics.graphviz;bundle-version="1.0.0",
+ org.simantics.diagram;bundle-version="0.9.4",
+ org.simantics.modeling;bundle-version="1.0.0"
Bundle-Activator: org.simantics.sysdyn.ui.Activator
Bundle-ActivationPolicy: lazy
\r
import java.awt.Frame;\r
import java.util.ArrayList;\r
+import java.util.Collection;\r
\r
import javax.swing.SwingUtilities;\r
\r
import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.db.management.ISessionContextProvider;\r
+import org.simantics.diagram.DiagramTypeUtils;\r
+import org.simantics.diagram.symbolcontribution.ISymbolProvider;\r
import org.simantics.h2d.canvas.EditorCanvas;\r
import org.simantics.h2d.diagram.IDiagram;\r
import org.simantics.h2d.diagram.IDiagramListener;\r
import org.simantics.h2d.element.IElement;\r
import org.simantics.h2d.element.IElementListener;\r
import org.simantics.h2d.event.handler.DefaultEventHandlers;\r
+import org.simantics.layer0.utils.triggers.IActivation;\r
+import org.simantics.layer0.utils.triggers.IActivationManager;\r
+import org.simantics.modeling.ModelingResources;\r
import org.simantics.objmap.IMapping;\r
import org.simantics.objmap.IMappingListener;\r
import org.simantics.objmap.MappingException;\r
import org.simantics.ui.workbench.TitleUpdater;\r
import org.simantics.utils.datastructures.Callable;\r
import org.simantics.utils.datastructures.Callback;\r
+import org.simantics.utils.ui.ErrorLogger;\r
import org.simantics.utils.ui.jface.ActiveSelectionProvider;\r
\r
public class SysdynDiagramEditor extends ResourceEditorPart {\r
Frame frame;\r
boolean disposed = false; \r
Composite frameComposite;\r
+ Resource diagramResource;\r
+ protected ISessionContextProvider sessionContextProvider;\r
+ protected ISessionContext sessionContext;\r
+ protected IActivation activation;\r
\r
IElementListener elementUpdateListener = new IElementListener() {\r
\r
\r
@Override\r
public void run(ReadGraph g) throws DatabaseException {\r
+ diagramResource = g.getSingleObject(getInputResource(), ModelingResources.getInstance(g).CompositeToDiagram);\r
+ System.out.println(diagramResource);\r
readDiagram(g); \r
}\r
\r
frameComposite = new Composite(parent, \r
SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
frame = SWT_AWT.new_Frame(frameComposite);\r
+ \r
+ \r
+ /// KOKEILLAAN\r
+ \r
+ /*\r
+ sessionContextProvider = SimanticsUI.getSessionContextProvider();\r
+ sessionContext = sessionContextProvider.getSessionContext();\r
+\r
+ IActivationManager activationManager = sessionContext.getSession().peekService(IActivationManager.class);\r
+ if (activationManager != null) {\r
+ activation = activationManager.activate(diagramResource);\r
+ }\r
+ */\r
+ /// LOPPUU\r
\r
final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider();\r
getSite().setSelectionProvider(selectionProvider);\r
if (adapter == INode.class) {\r
return canvas.getEditor().getSceneGraph();\r
}\r
+ if (adapter == ISymbolProvider.class) {\r
+ try {\r
+\r
+ return DiagramTypeUtils.readSymbolContributions(SimanticsUI.getSession(), diagramResource);\r
+ } catch (DatabaseException e) {\r
+ ErrorLogger.defaultLogError(getClass() + " failed to adapt to ISymbolProvider, see exception for details.", e);\r
+ return null;\r
+ }\r
+ }\r
return super.getAdapter(adapter);\r
}\r
}\r
import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.eclipse.core.commands.ExecutionException; \r
+import org.simantics.databoard.binding.java.StringJavaBinding;\r
import org.simantics.db.Builtins;\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.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.DiagramConstants;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.modeling.ModelingUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.ui.SimanticsUI;\r
\r
// Same as in SysdynProject.java. Should use the same code, not copy.\r
Builtins b = graph.getBuiltins();\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+ ModelingUtils mu = new ModelingUtils(graph);\r
+ \r
Resource model = graph.newResource();\r
graph.claimValue(model, b.HasName, "Model1");\r
graph.claimValue(model, b.HasLabel, "Model1");\r
graph.claim(model, b.InstanceOf, sr.SysdynModel);\r
graph.claim(model, b.PartOf, SimanticsUI.getProject().get());\r
\r
- Resource conf = graph.newResource();\r
- graph.claimValue(conf, b.HasName, "Configuration");\r
- graph.claim(conf, b.InstanceOf, sr.Configuration);\r
+ \r
+ Resource diagram = OrderedSetUtils.create(graph, sr.ConfigurationDiagram);\r
+ GraphLayer l = new GraphLayerUtil(graph).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true);\r
+ graph.claim(diagram, mu.dr.HasLayer, l.getLayer());\r
+ graph.claimValue(diagram, b.HasName, "Diagrammi", StringJavaBinding.INSTANCE);\r
+ \r
+ Resource conf = GraphUtils.create2(graph, \r
+ sr.Configuration,\r
+ b.HasName, "Configuration",\r
+ sr.HasStartTime, 0.0,\r
+ sr.HasStopTime, 10.0);\r
+\r
+ graph.claim(conf, mr.CompositeToDiagram, diagram);\r
graph.claim(model, b.HasConfiguration, conf);\r
- graph.claimValue(conf, sr.HasStartTime, 0.0);\r
- graph.claimValue(conf, sr.HasStopTime, 10.0);\r
+ \r
+ Resource mapping = graph.newResource();\r
+ graph.claim(mapping, b.InstanceOf, null, mr.DiagramToCompositeMapping);\r
+ graph.claim(diagram, b.HasTrigger, mapping);\r
}\r
});\r
return null;\r
\r
IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT, 0.25f, editorArea);\r
left.addView("org.simantics.sysdyn.ui.browser");\r
+ \r
+ IFolderLayout right = layout.createFolder("right", IPageLayout.RIGHT, 0.7f, editorArea);\r
+ right.addView("org.simantics.diagram.symbollibrary");\r
\r
// Open cheatsheets view on the first time the user creates a sysdyn project\r
// for a particular workspace.\r
\r
import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.ui.PartInitException;\r
+import org.simantics.databoard.binding.java.StringJavaBinding;\r
import org.simantics.db.Builtins;\r
import org.simantics.db.Resource;\r
import org.simantics.db.Session;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.request.Queries;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.service.LifecycleSupport;\r
+import org.simantics.diagram.DiagramConstants;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.modeling.ModelingUtils;\r
import org.simantics.project.ProjectElementType;\r
import org.simantics.project.ProjectElements;\r
import org.simantics.project.ProjectKeys;\r
try {\r
Builtins b = g.getBuiltins();\r
SysdynResource sr = SysdynResource.getInstance(g);\r
+ ModelingResources mr = ModelingResources.getInstance(g);\r
+ ModelingUtils mu = new ModelingUtils(g);\r
+ \r
Resource model = g.newResource();\r
g.claimValue(model, b.HasName, "Model1");\r
g.claimValue(model, b.HasLabel, "Model1");\r
g.claim(model, b.InstanceOf, sr.SysdynModel);\r
g.claim(model, b.PartOf, library);\r
+\r
+ Resource diagram = OrderedSetUtils.create(g, sr.ConfigurationDiagram);\r
+ GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true);\r
+ g.claim(diagram, mu.dr.HasLayer, l.getLayer());\r
+ g.claimValue(diagram, b.HasName, "Diagrammi", StringJavaBinding.INSTANCE);\r
\r
+\r
Resource conf = g.newResource();\r
g.claimValue(conf, b.HasName, "Configuration");\r
g.claim(conf, b.InstanceOf, sr.Configuration);\r
- g.claim(model, b.HasConfiguration, conf);\r
g.claimValue(conf, sr.HasStartTime, 0.0);\r
g.claimValue(conf, sr.HasStopTime, 10.0);\r
+ \r
+ g.claim(conf, mr.CompositeToDiagram, diagram);\r
+ g.claim(model, b.HasConfiguration, conf);\r
+ \r
+ Resource mapping = g.newResource();\r
+ g.claim(mapping, b.InstanceOf, null, mr.DiagramToCompositeMapping);\r
+ g.claim(diagram, b.HasTrigger, mapping);\r
\r
+ callback.run(model);\r
} catch(Exception e) {\r
errorCallback.run(e);\r
}\r
public final Resource Auxiliary;\r
public final Resource Cloud;\r
public final Resource Configuration;\r
+ public final Resource ConfigurationDiagram;\r
public final Resource ConstantExpression;\r
public final Resource DelayExpression;\r
public final Resource Dependency;\r
public static final String Auxiliary = "http://www.simantics.org/Sysdyn-1.0/Auxiliary";\r
public static final String Cloud = "http://www.simantics.org/Sysdyn-1.0/Cloud";\r
public static final String Configuration = "http://www.simantics.org/Sysdyn-1.0/Configuration";\r
+ public static final String ConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.0/ConfigurationDiagram";\r
public static final String ConstantExpression = "http://www.simantics.org/Sysdyn-1.0/ConstantExpression";\r
public static final String DelayExpression = "http://www.simantics.org/Sysdyn-1.0/DelayExpression";\r
public static final String Dependency = "http://www.simantics.org/Sysdyn-1.0/Dependency";\r
Auxiliary = getResourceOrNull(graph, URIs.Auxiliary);\r
Cloud = getResourceOrNull(graph, URIs.Cloud);\r
Configuration = getResourceOrNull(graph, URIs.Configuration);\r
+ ConfigurationDiagram = getResourceOrNull(graph, URIs.ConfigurationDiagram);\r
ConstantExpression = getResourceOrNull(graph, URIs.ConstantExpression);\r
DelayExpression = getResourceOrNull(graph, URIs.DelayExpression);\r
Dependency = getResourceOrNull(graph, URIs.Dependency);\r
%import "layer0.graph" L0\r
+%import "diagram2.graph" DIA\r
+%import "g2d.graph" G2D\r
%import "structural2.graph" ST\r
+%import "modeling.graph" MOD\r
%import "project.graph" PROJ\r
%import "simulation.graph" SIMU\r
\r
%deflib L0.Type Sysdyn\r
%deflib L0.Relation Sysdyn\r
\r
+\r
+%deflib DIA.ElementClass Symbols\r
+\r
+%define assert($pred,$obj)\r
+ $subject\r
+ L0.Asserts _ : L0.Assertion\r
+ L0.HasPredicate $pred\r
+ L0.HasObject $obj\r
+\r
######################################################################\r
# Defines ontology and attaches it to SimanticsDomain\r
######################################################################\r
L0.HasVersion "1.0" : L0.Version\r
L0.HasResourceClass "org.simantics.sysdyn.SysdynResource" : L0.String\r
L0.HasPackageName "sysdyn" : L0.String \r
+ L0.ConsistsOf\r
+ Symbols : L0.Library\r
\r
SysdynProject : PROJ.Feature\r
L0.HasLabel "System Dynamics Project" : L0.String\r
L0.HasDescription """System dynamics modelling project. Create system dynamics models and simulate them with OpenModelica.""" : L0.String\r
L0.PartOf Sysdyn\r
- L0.PartOf PROJ.PublishedProjectFeatures\r
+ L0.PartOf PROJ.PublishedProjectFeatures \r
\r
######################################################################\r
# Model\r
###################################################################### \r
\r
SysdynModel <T SIMU.Model\r
- [SIMU.HasConfiguration all Configuration]\r
+ L0.PartOf Sysdyn\r
+ [SIMU.HasConfiguration all Configuration]\r
\r
######################################################################\r
# Configuration\r
######################################################################\r
+ \r
+ConfigurationDiagram <T DIA.Diagram\r
+ L0.PartOf Sysdyn\r
+ assert(ST.HasModelingRules, SysdynDiagramModelingRules) \r
+ DIA.HasSymbolContribution _ : DIA.BasicSymbolContribution\r
+ DIA.BasicSymbolContributionHasSymbolLibrary\r
+ BasicSymbolLibrary\r
+ \r
+SysdynDiagramModelingRules : MOD.MappedModelingRules\r
+ MOD.HasBaseRules ST.StandardModelingRules\r
+ \r
+SymbolReferences : DIA.SymbolReferenceLibrary\r
+ L0.PartOf Sysdyn\r
+ L0.ConsistsOf\r
+ BasicSymbolLibrary @ "Basic Symbols" : DIA.SymbolReferenceLibrary\r
\r
Configuration <T ST.Composite\r
[L0.ConsistsOf all (Variable or Dependency)]\r
[HasStartTime card "1"]\r
[HasStopTime card "1"]\r
-\r
+ \r
HasStartTime <R L0.HasProperty\r
L0.HasRange L0.Double \r
\r
[HasExpression card "0..1"] \r
\r
Auxiliary <T IndependentVariable\r
- \r
-Stock <T IndependentVariable\r
\r
Valve <T IndependentVariable\r
+ \r
+Stock <T IndependentVariable\r
\r
Cloud <T Variable \r
\r
\r
WithLookupExpression <T Expression\r
[HasLookup card "1"] \r
- [HasEquation card "1"]
\ No newline at end of file
+ [HasEquation card "1"] \r
+ \r
+######################################################################\r
+# Symbols\r
+###################################################################### \r
+\r
+#Auxiliary\r
+# MOD.ComponentTypeToSymbol AuxiliarySymbol <T DIA.DefinedElement\r
+# L0.HasLabel "Auxiliary" : L0.String\r
+# L0.IsDependencyOf BasicSymbolLibrary\r
+# ST.IsDefinedBy %list : DIA.Composite <R L0.IsRelatedTo\r
+# _ : DIA.SVGElement\r
+# G2D.HasSVGDocument """<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r
+#<svg xmlns="http://www.w3.org/2000/svg" overflow="visible">\r
+#<ellipse cx="0" cy="0" rx="8" ry="4" stroke="black" stroke-width="0.2" fill="none" />\r
+#</svg>""" : L0.String\r
+\r
+#Stock\r
+# MOD.ComponentTypeToSymbol StockSymbol <T DIA.DefinedElement\r
+# L0.HasLabel "Stock" : L0.String\r
+# L0.IsDependencyOf BasicSymbolLibrary\r
+# ST.IsDefinedBy %list : DIA.Composite <R L0.IsRelatedTo\r
+# _ : DIA.SVGElement\r
+# G2D.HasSVGDocument """<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r
+#<svg xmlns="http://www.w3.org/2000/svg" overflow="visible">\r
+#<rect x="-8" y="-4" width="16" height="8" stroke="black" stroke-width="0.2" fill="none"/>\r
+#</svg>""" : L0.String\r
+\r
+\r
+#Valve\r
+# MOD.ComponentTypeToSymbol ValveSymbol <T DIA.DefinedElement\r
+# L0.HasLabel "Valve" : L0.String\r
+# L0.IsDependencyOf BasicSymbolLibrary\r
+# ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
+# _ : DIA.SVGElement\r
+# G2D.HasSVGDocument """<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r
+#<svg xmlns="http://www.w3.org/2000/svg" overflow="visible">\r
+#<path\r
+# stroke="black" stroke-width="0.2" fill="none"\r
+# d="M-3 3 L3 -3 L-3 -3 L3 3 Z" /> \r
+#</svg>""" : L0.String\r
+\r