From adf6ffa8a4c1bca07201f547a6494beb2cb091c1 Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 25 May 2010 06:36:05 +0000 Subject: [PATCH] buggy symbol viewer git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@15843 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.ui/META-INF/MANIFEST.MF | 4 +- .../sysdyn/ui/editor/SysdynDiagramEditor.java | 38 +++++++++ .../sysdyn/ui/handlers/NewModelHandler.java | 33 ++++++-- .../ui/project/SysdynPerspectiveFactory.java | 3 + .../sysdyn/ui/project/SysdynProject.java | 25 +++++- .../org/simantics/sysdyn/SysdynResource.java | 3 + sysdyn_ontologies/sysdyn.graph | 83 +++++++++++++++++-- 7 files changed, 176 insertions(+), 13 deletions(-) diff --git a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF index df09a233..9fcc740c 100644 --- a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF @@ -26,6 +26,8 @@ Require-Bundle: org.simantics.h2d;bundle-version="1.0.0", 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 diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java index 497b8cf9..05d41f6e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java @@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.editor; import java.awt.Frame; import java.util.ArrayList; +import java.util.Collection; import javax.swing.SwingUtilities; @@ -31,6 +32,10 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.management.ISessionContextProvider; +import org.simantics.diagram.DiagramTypeUtils; +import org.simantics.diagram.symbolcontribution.ISymbolProvider; import org.simantics.h2d.canvas.EditorCanvas; import org.simantics.h2d.diagram.IDiagram; import org.simantics.h2d.diagram.IDiagramListener; @@ -40,6 +45,9 @@ import org.simantics.h2d.editor.impl.DiagramEditor; import org.simantics.h2d.element.IElement; import org.simantics.h2d.element.IElementListener; import org.simantics.h2d.event.handler.DefaultEventHandlers; +import org.simantics.layer0.utils.triggers.IActivation; +import org.simantics.layer0.utils.triggers.IActivationManager; +import org.simantics.modeling.ModelingResources; import org.simantics.objmap.IMapping; import org.simantics.objmap.IMappingListener; import org.simantics.objmap.MappingException; @@ -58,6 +66,7 @@ import org.simantics.ui.workbench.TitleRequest; import org.simantics.ui.workbench.TitleUpdater; import org.simantics.utils.datastructures.Callable; import org.simantics.utils.datastructures.Callback; +import org.simantics.utils.ui.ErrorLogger; import org.simantics.utils.ui.jface.ActiveSelectionProvider; public class SysdynDiagramEditor extends ResourceEditorPart { @@ -68,6 +77,10 @@ public class SysdynDiagramEditor extends ResourceEditorPart { Frame frame; boolean disposed = false; Composite frameComposite; + Resource diagramResource; + protected ISessionContextProvider sessionContextProvider; + protected ISessionContext sessionContext; + protected IActivation activation; IElementListener elementUpdateListener = new IElementListener() { @@ -168,6 +181,8 @@ public class SysdynDiagramEditor extends ResourceEditorPart { @Override public void run(ReadGraph g) throws DatabaseException { + diagramResource = g.getSingleObject(getInputResource(), ModelingResources.getInstance(g).CompositeToDiagram); + System.out.println(diagramResource); readDiagram(g); } @@ -206,6 +221,20 @@ public class SysdynDiagramEditor extends ResourceEditorPart { frameComposite = new Composite(parent, SWT.NO_BACKGROUND | SWT.EMBEDDED); frame = SWT_AWT.new_Frame(frameComposite); + + + /// KOKEILLAAN + + /* + sessionContextProvider = SimanticsUI.getSessionContextProvider(); + sessionContext = sessionContextProvider.getSessionContext(); + + IActivationManager activationManager = sessionContext.getSession().peekService(IActivationManager.class); + if (activationManager != null) { + activation = activationManager.activate(diagramResource); + } + */ + /// LOPPUU final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider(); getSite().setSelectionProvider(selectionProvider); @@ -285,6 +314,15 @@ public class SysdynDiagramEditor extends ResourceEditorPart { if (adapter == INode.class) { return canvas.getEditor().getSceneGraph(); } + if (adapter == ISymbolProvider.class) { + try { + + return DiagramTypeUtils.readSymbolContributions(SimanticsUI.getSession(), diagramResource); + } catch (DatabaseException e) { + ErrorLogger.defaultLogError(getClass() + " failed to adapt to ISymbolProvider, see exception for details.", e); + return null; + } + } return super.getAdapter(adapter); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java index 148bb34e..19d0611e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java @@ -3,11 +3,19 @@ package org.simantics.sysdyn.ui.handlers; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; +import org.simantics.databoard.binding.java.StringJavaBinding; import org.simantics.db.Builtins; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.DiagramConstants; +import org.simantics.diagram.synchronization.graph.layer.GraphLayer; +import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.ModelingUtils; import org.simantics.sysdyn.SysdynResource; import org.simantics.ui.SimanticsUI; @@ -22,18 +30,33 @@ public class NewModelHandler extends AbstractHandler { // Same as in SysdynProject.java. Should use the same code, not copy. Builtins b = graph.getBuiltins(); SysdynResource sr = SysdynResource.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + ModelingUtils mu = new ModelingUtils(graph); + Resource model = graph.newResource(); graph.claimValue(model, b.HasName, "Model1"); graph.claimValue(model, b.HasLabel, "Model1"); graph.claim(model, b.InstanceOf, sr.SysdynModel); graph.claim(model, b.PartOf, SimanticsUI.getProject().get()); - Resource conf = graph.newResource(); - graph.claimValue(conf, b.HasName, "Configuration"); - graph.claim(conf, b.InstanceOf, sr.Configuration); + + Resource diagram = OrderedSetUtils.create(graph, sr.ConfigurationDiagram); + GraphLayer l = new GraphLayerUtil(graph).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true); + graph.claim(diagram, mu.dr.HasLayer, l.getLayer()); + graph.claimValue(diagram, b.HasName, "Diagrammi", StringJavaBinding.INSTANCE); + + Resource conf = GraphUtils.create2(graph, + sr.Configuration, + b.HasName, "Configuration", + sr.HasStartTime, 0.0, + sr.HasStopTime, 10.0); + + graph.claim(conf, mr.CompositeToDiagram, diagram); graph.claim(model, b.HasConfiguration, conf); - graph.claimValue(conf, sr.HasStartTime, 0.0); - graph.claimValue(conf, sr.HasStopTime, 10.0); + + Resource mapping = graph.newResource(); + graph.claim(mapping, b.InstanceOf, null, mr.DiagramToCompositeMapping); + graph.claim(diagram, b.HasTrigger, mapping); } }); return null; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java index 1d86dbe6..4ced7a11 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java @@ -43,6 +43,9 @@ public class SysdynPerspectiveFactory implements IPerspectiveFactory { IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT, 0.25f, editorArea); left.addView("org.simantics.sysdyn.ui.browser"); + + IFolderLayout right = layout.createFolder("right", IPageLayout.RIGHT, 0.7f, editorArea); + right.addView("org.simantics.diagram.symbollibrary"); // Open cheatsheets view on the first time the user creates a sysdyn project // for a particular workspace. diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java index 1020b1cd..178089b8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java @@ -13,13 +13,20 @@ package org.simantics.sysdyn.ui.project; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PartInitException; +import org.simantics.databoard.binding.java.StringJavaBinding; import org.simantics.db.Builtins; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.Queries; +import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.service.LifecycleSupport; +import org.simantics.diagram.DiagramConstants; +import org.simantics.diagram.synchronization.graph.layer.GraphLayer; +import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil; +import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.ModelingUtils; import org.simantics.project.ProjectElementType; import org.simantics.project.ProjectElements; import org.simantics.project.ProjectKeys; @@ -71,19 +78,35 @@ public class SysdynProject extends AbstractProjectFeature { try { Builtins b = g.getBuiltins(); SysdynResource sr = SysdynResource.getInstance(g); + ModelingResources mr = ModelingResources.getInstance(g); + ModelingUtils mu = new ModelingUtils(g); + Resource model = g.newResource(); g.claimValue(model, b.HasName, "Model1"); g.claimValue(model, b.HasLabel, "Model1"); g.claim(model, b.InstanceOf, sr.SysdynModel); g.claim(model, b.PartOf, library); + + Resource diagram = OrderedSetUtils.create(g, sr.ConfigurationDiagram); + GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true); + g.claim(diagram, mu.dr.HasLayer, l.getLayer()); + g.claimValue(diagram, b.HasName, "Diagrammi", StringJavaBinding.INSTANCE); + Resource conf = g.newResource(); g.claimValue(conf, b.HasName, "Configuration"); g.claim(conf, b.InstanceOf, sr.Configuration); - g.claim(model, b.HasConfiguration, conf); g.claimValue(conf, sr.HasStartTime, 0.0); g.claimValue(conf, sr.HasStopTime, 10.0); + + g.claim(conf, mr.CompositeToDiagram, diagram); + g.claim(model, b.HasConfiguration, conf); + + Resource mapping = g.newResource(); + g.claim(mapping, b.InstanceOf, null, mr.DiagramToCompositeMapping); + g.claim(diagram, b.HasTrigger, mapping); + callback.run(model); } catch(Exception e) { errorCallback.run(e); } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java index 87165c9e..8f3d8b31 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java @@ -23,6 +23,7 @@ public class SysdynResource { public final Resource Auxiliary; public final Resource Cloud; public final Resource Configuration; + public final Resource ConfigurationDiagram; public final Resource ConstantExpression; public final Resource DelayExpression; public final Resource Dependency; @@ -63,6 +64,7 @@ public class SysdynResource { public static final String Auxiliary = "http://www.simantics.org/Sysdyn-1.0/Auxiliary"; public static final String Cloud = "http://www.simantics.org/Sysdyn-1.0/Cloud"; public static final String Configuration = "http://www.simantics.org/Sysdyn-1.0/Configuration"; + public static final String ConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.0/ConfigurationDiagram"; public static final String ConstantExpression = "http://www.simantics.org/Sysdyn-1.0/ConstantExpression"; public static final String DelayExpression = "http://www.simantics.org/Sysdyn-1.0/DelayExpression"; public static final String Dependency = "http://www.simantics.org/Sysdyn-1.0/Dependency"; @@ -113,6 +115,7 @@ public class SysdynResource { Auxiliary = getResourceOrNull(graph, URIs.Auxiliary); Cloud = getResourceOrNull(graph, URIs.Cloud); Configuration = getResourceOrNull(graph, URIs.Configuration); + ConfigurationDiagram = getResourceOrNull(graph, URIs.ConfigurationDiagram); ConstantExpression = getResourceOrNull(graph, URIs.ConstantExpression); DelayExpression = getResourceOrNull(graph, URIs.DelayExpression); Dependency = getResourceOrNull(graph, URIs.Dependency); diff --git a/sysdyn_ontologies/sysdyn.graph b/sysdyn_ontologies/sysdyn.graph index a615777e..f847af7d 100644 --- a/sysdyn_ontologies/sysdyn.graph +++ b/sysdyn_ontologies/sysdyn.graph @@ -1,11 +1,23 @@ %import "layer0.graph" L0 +%import "diagram2.graph" DIA +%import "g2d.graph" G2D %import "structural2.graph" ST +%import "modeling.graph" MOD %import "project.graph" PROJ %import "simulation.graph" SIMU %deflib L0.Type Sysdyn %deflib L0.Relation Sysdyn + +%deflib DIA.ElementClass Symbols + +%define assert($pred,$obj) + $subject + L0.Asserts _ : L0.Assertion + L0.HasPredicate $pred + L0.HasObject $obj + ###################################################################### # Defines ontology and attaches it to SimanticsDomain ###################################################################### @@ -15,29 +27,47 @@ Sysdyn @ "Sysdyn-1.0" : L0.Ontology L0.HasVersion "1.0" : L0.Version L0.HasResourceClass "org.simantics.sysdyn.SysdynResource" : L0.String L0.HasPackageName "sysdyn" : L0.String + L0.ConsistsOf + Symbols : L0.Library SysdynProject : PROJ.Feature L0.HasLabel "System Dynamics Project" : L0.String L0.HasDescription """System dynamics modelling project. Create system dynamics models and simulate them with OpenModelica.""" : L0.String L0.PartOf Sysdyn - L0.PartOf PROJ.PublishedProjectFeatures + L0.PartOf PROJ.PublishedProjectFeatures ###################################################################### # Model ###################################################################### SysdynModel +# +# +#""" : L0.String + +#Stock +# MOD.ComponentTypeToSymbol StockSymbol +# +# +#""" : L0.String + + +#Valve +# MOD.ComponentTypeToSymbol ValveSymbol +# +# +#""" : L0.String + -- 2.47.1