]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Some problems with diagram (e.g. copypaste) fixed by using diagramtemplate to create...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 28 Apr 2011 13:47:36 +0000 (13:47 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 28 Apr 2011 13:47:36 +0000 (13:47 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20617 ac1ea38d-2e2b-0410-8846-a27921b304fc

20 files changed:
org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java
org.simantics.sysdyn.ontology/graph.tg
org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph
org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ModuleVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Model.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LibraryDummy.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java

index 5295b6fdeb2b9a4b692bb14371a52326cae30ce9..f8e4b18e91772591f6a01fd860fe72aca7bc42b7 100644 (file)
@@ -51,15 +51,36 @@ public class ModelicaManager {
        public static File getModelicaHome() {\r
 \r
                String dir = System.getenv("OPENMODELICAHOME");\r
+               File omhome = null;\r
 \r
                String osName = System.getProperty("os.name");\r
                OSType os = calculateOS();\r
 \r
                if (os == OSType.UNKNOWN)\r
                        throw new UnsatisfiedLinkError("unknown OS '" + osName + "' for running OpenModelica");\r
+               \r
+               // If OPENMODELICAHOME is found, try to return the folder.\r
+               if(dir != null) {\r
+                       switch (os) {\r
+                       case APPLE:\r
+                       case LINUX:\r
+                       case SUN:\r
+                               omhome = new File(dir);\r
+                               if(omhome.isDirectory())\r
+                                       return  omhome;\r
+                               else\r
+                                       break;\r
+                       case WINDOWS:\r
+                               omhome = new File(dir);\r
+                               if(omhome.isDirectory())\r
+                                       return  omhome;\r
+                               else\r
+                                       break;\r
+                       }\r
+               }\r
 \r
-               // Teemu's stuff, testing openmodelica in a plugin\r
-               if(dir == null && os.equals(OSType.WINDOWS)) {\r
+               // OPENMODELICAHOMe was not found or the folder does not exist. Try built-in OpenModelica for windows\r
+               if(os.equals(OSType.WINDOWS)) {\r
 \r
                        Bundle bundle = Platform.getBundle("org.simantics.openmodelica.win32");\r
                        if (bundle != null) {\r
@@ -78,30 +99,16 @@ public class ModelicaManager {
                        }\r
                }\r
 \r
-               // Back to normal\r
-\r
-               if(dir == null) {\r
-                       switch (os) {\r
-                       case APPLE:\r
-                       case LINUX:\r
-                       case SUN:\r
-                               return new File("/usr/bin/omc");\r
-                       case WINDOWS:\r
-                               return new File("c:/OpenModelica1.7.0");\r
-                       default:\r
-                               throw new UnsatisfiedLinkError("Unsupported operating system: " + os);\r
-                       }\r
-               } else {\r
-                       switch (os) {\r
-                       case APPLE:\r
-                       case LINUX:\r
-                       case SUN:\r
-                               return new File(dir);\r
-                       case WINDOWS:\r
-                               return new File(dir);\r
-                       default:\r
-                               throw new UnsatisfiedLinkError("Unsupported operating system: " + os);\r
-                       }\r
+               // OS was not windows or built-in OpenModelica did not work\r
+               switch (os) {\r
+               case APPLE:\r
+               case LINUX:\r
+               case SUN:\r
+                       return new File("/usr/bin/omc");\r
+               case WINDOWS:\r
+                       return new File("c:/OpenModelica1.7.0");\r
+               default:\r
+                       throw new UnsatisfiedLinkError("Unsupported operating system: " + os);\r
                }\r
        }\r
 \r
index 2456f494df1875f56f76afb46b2501ea1e8a9cbc..9249c4122a42b528f10e68ddcb7c6e925f0ee30e 100644 (file)
Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ
index f150ba4393d42fdcf92d8c5bdc8b019d0af898c1..e714c7c884c5682ac9286949cfe966e1766c09c1 100644 (file)
@@ -64,6 +64,9 @@ SYSDYN.ConfigurationDiagram <T DIA.Diagram
     DIA.HasSymbolContribution _ : DIA.BasicSymbolContribution
         DIA.BasicSymbolContributionHasSymbolLibrary
             BasicSymbols
+            
+SYSDYN.ConfigurationDiagramTemplate : MOD.DiagramTemplate
+    MOD.HasDiagramType SYSDYN.ConfigurationDiagram            
 
 SYSDYN.SysdynDiagramModelingRules : MOD.MappedModelingRules
     MOD.HasBaseRules STR.StandardModelingRules
index 5c3e87a790ee6921c00564aca006851599e1025f..a363ff30281203a74a308ea9f9b43861252f5f80 100644 (file)
@@ -42,6 +42,7 @@ public class SysdynResource {
     public final Resource CloudSymbol;\r
     public final Resource Configuration;\r
     public final Resource ConfigurationDiagram;\r
+    public final Resource ConfigurationDiagramTemplate;\r
     public final Resource ConstantExpression;\r
     public final Resource DefaultRealization;\r
     public final Resource DelayExpression;\r
@@ -204,6 +205,7 @@ public class SysdynResource {
         public static final String CloudSymbol = "http://www.simantics.org/Sysdyn-1.0/CloudSymbol";\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 ConfigurationDiagramTemplate = "http://www.simantics.org/Sysdyn-1.0/ConfigurationDiagramTemplate";\r
         public static final String ConstantExpression = "http://www.simantics.org/Sysdyn-1.0/ConstantExpression";\r
         public static final String DefaultRealization = "http://www.simantics.org/Sysdyn-1.0/DefaultRealization";\r
         public static final String DelayExpression = "http://www.simantics.org/Sysdyn-1.0/DelayExpression";\r
@@ -376,6 +378,7 @@ public class SysdynResource {
         CloudSymbol = getResourceOrNull(graph, URIs.CloudSymbol);\r
         Configuration = getResourceOrNull(graph, URIs.Configuration);\r
         ConfigurationDiagram = getResourceOrNull(graph, URIs.ConfigurationDiagram);\r
+        ConfigurationDiagramTemplate = getResourceOrNull(graph, URIs.ConfigurationDiagramTemplate);\r
         ConstantExpression = getResourceOrNull(graph, URIs.ConstantExpression);\r
         DefaultRealization = getResourceOrNull(graph, URIs.DefaultRealization);\r
         DelayExpression = getResourceOrNull(graph, URIs.DelayExpression);\r
index 13333428ca472002af93b258fc6c863613540c80..2c89a4b2a2c1d30a4c85b06b355e798987f676c9 100644 (file)
@@ -39,8 +39,12 @@ public class Model  extends ViewpointContributor<ModelNode> {
         Layer0 l0 = Layer0.getInstance(graph);\r
         Resource baseRealization = graph.syncRequest(new PossibleObject(model.data, l0.HasBaseRealization));\r
         if (baseRealization != null) {\r
-               Variable variable = Variables.getVariable(graph, graph.getURI(baseRealization));\r
-            result.add(new ConfigurationNode<Resource>(variable, baseRealization));\r
+               try {\r
+                       String URI = graph.getURI(baseRealization);\r
+               Variable variable = Variables.getVariable(graph, URI);\r
+                result.add(new ConfigurationNode<Resource>(variable, baseRealization));\r
+               } catch (DatabaseException e) {\r
+               }\r
         }\r
         result.add(new ExperimentsFolder(model.data));\r
         result.add(new ModulesNode(model.data));\r
index 4b96fdc68432c8120514ee6af271132974eb0e6c..86c672a3ac350aaf2b208899bc2b0d14b1903300 100644 (file)
@@ -22,10 +22,12 @@ import org.simantics.db.ReadGraph;
 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.NameUtils;\r
 import org.simantics.db.exception.CancelTransactionException;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.procedure.Listener;\r
 import org.simantics.db.request.Read;\r
+import org.simantics.db.request.Write;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.sysdyn.SysdynResource;\r
@@ -89,6 +91,19 @@ public class ModelNode extends AbstractNode<Resource> implements IDoubleClickabl
                     return "Spaces are not allowed";\r
                 return null;\r
             }\r
+            \r
+            @Override\r
+            protected Write getWriteRequest(final String label) {\r
+                return new WriteRequest() {\r
+                    @Override\r
+                    public void perform(WriteGraph g) throws DatabaseException {\r
+                       Layer0 l0 = Layer0.getInstance(g);\r
+                        g.claimLiteral(data, l0.HasLabel, label);\r
+                        String safeName = NameUtils.findFreshName(g, label, g.getSingleObject(data, l0.PartOf), l0.ConsistsOf, "%s%d");\r
+                        g.claimLiteral(data, l0.HasName, safeName);\r
+                    }\r
+                };\r
+            }\r
         };\r
         return modifier;\r
     }\r
index 170d02de59e165a84dbf5d3f86abf584f357507f..5b3c122c0c7397a9df40d14feba907d7d12be91c 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.editor.participant;\r
 \r
+import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.Statement;\r
 import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.exception.ServiceException;\r
 import org.simantics.diagram.synchronization.ISynchronizationContext;\r
 import org.simantics.diagram.synchronization.graph.CopyAdvisorUtil;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ComponentUtils;\r
 import org.simantics.modeling.mapping.ComponentCopyAdvisor;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.utils.datastructures.BinaryFunction;\r
@@ -47,7 +51,19 @@ public class SysdynComponentCopyAdvisor extends ComponentCopyAdvisor{
        };\r
        \r
         Resource copy = CopyAdvisorUtil.copy(graph, source, tester);\r
+        \r
         renameComponent(context, graph, source, copy, sourceContainer, targetContainer);\r
         return copy;\r
     }\r
+    \r
+\r
+    public static String renameComponent(ISynchronizationContext context, WriteGraph graph, Resource source,\r
+            Resource copy, Resource sourceContainer, Resource targetContainer) throws DatabaseException {\r
+       Layer0 l0 = Layer0.getInstance(graph);\r
+       String copyName = NameUtils.getSafeName(graph, copy);\r
+        Resource configurationRoot = ComponentUtils.getCompositeConfigurationRoot(graph, targetContainer);\r
+       String name =  NameUtils.findFreshName(graph, copyName, configurationRoot, l0.ConsistsOf, "%s%d");\r
+       graph.claimLiteral(copy, l0.HasName, name, Bindings.STRING);\r
+       return name;\r
+    }\r
 }\r
index 02ee621a900a25ffdff2cc2bd4686b2baa63168a..ad38e9c99e4fd19f6c359169d4bc3b4d2a23c062 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.handlers;
 \r
 import java.io.File;\r
 import java.io.IOException;\r
+import java.util.HashSet;\r
 \r
 import org.eclipse.core.commands.AbstractHandler;\r
 import org.eclipse.core.commands.ExecutionEvent;\r
@@ -33,7 +34,11 @@ import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;
 import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
 import org.simantics.graph.representation.TransferableGraph1;\r
 import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.modeling.ModelingResources;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.utils.OldTransferableGraph1;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
@@ -76,21 +81,16 @@ public class ImportModelHandler extends AbstractHandler {
                        DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(project);\r
                        DefaultPasteHandler.defaultExecute(tg, SimanticsUI.getProject().get(), ia);\r
 \r
+                       \r
+                       // Fix changes made to old ontology versions\r
                        final Resource root = ia.getRoot();\r
                        SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
                                \r
                                @Override\r
                                public void perform(WriteGraph graph) throws DatabaseException {\r
-                                       Layer0 l0 = Layer0.getInstance(graph);\r
-                                       updateOldConfiguration(graph, root);\r
-                                       \r
-                                       // FIXME: the links should be exported and imported automatically\r
-                                       Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.0");\r
-                                       Resource layer0 = graph.getResource("http://www.simantics.org/Layer0-1.0");\r
-                                       if(!graph.hasStatement(root, l0.IsLinkedTo, sysdyn))\r
-                                               graph.claim(root, l0.IsLinkedTo, sysdyn);\r
-                                       if(!graph.hasStatement(root, l0.IsLinkedTo, layer0))\r
-                                               graph.claim(root, l0.IsLinkedTo, layer0);\r
+                                       updateOldConfigurationToBaseRealization(graph, root);\r
+                                       addDefaultOntologyLinks(graph, root);\r
+                                       addURIsToDiagrams(graph, root);\r
                                }\r
                        });\r
                } catch (DatabaseException e) {\r
@@ -102,7 +102,12 @@ public class ImportModelHandler extends AbstractHandler {
                return null;\r
        }\r
        \r
-       private void updateOldConfiguration(WriteGraph graph, Resource model) {\r
+       /**\r
+        * In old versions base realization was separate. Newer versions use configuration as base realization. \r
+        * @param graph WriteGraph\r
+        * @param model Imported model\r
+        */\r
+       private static void updateOldConfigurationToBaseRealization(WriteGraph graph, Resource model) {\r
                Layer0 l0 = Layer0.getInstance(graph);\r
                try {\r
                        Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
@@ -113,5 +118,64 @@ public class ImportModelHandler extends AbstractHandler {
                }\r
                \r
        }\r
-\r
+       \r
+       /**\r
+        * Links should be exported and imported automatically. If it has failed, the \r
+        * default ontology links sysdyn and layer0 are added.\r
+        * \r
+        * @param graph WriteGraph\r
+        * @param model Imported model\r
+        */\r
+        \r
+       private static void addDefaultOntologyLinks(WriteGraph graph, Resource model) {\r
+               try {\r
+                       Layer0 l0 = Layer0.getInstance(graph);\r
+                       // The links should be exported and imported automatically\r
+                       Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.0");\r
+                       Resource layer0 = graph.getResource("http://www.simantics.org/Layer0-1.0");\r
+                       if(!graph.hasStatement(model, l0.IsLinkedTo, sysdyn))\r
+                               graph.claim(model, l0.IsLinkedTo, sysdyn);\r
+                       if(!graph.hasStatement(model, l0.IsLinkedTo, layer0))\r
+                               graph.claim(model, l0.IsLinkedTo, layer0);\r
+               } catch (DatabaseException e) {\r
+                       e.printStackTrace();\r
+               }\r
+       }\r
+       \r
+       \r
+       private static void addURIsToDiagrams(WriteGraph graph, Resource model) {\r
+               Layer0 l0 = Layer0.getInstance(graph);\r
+               SimulationResource simu = SimulationResource.getInstance(graph);\r
+               ModelingResources mr = ModelingResources.getInstance(graph);\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+               try {\r
+                       HashSet<Resource> configurations = new HashSet<Resource>();\r
+               \r
+                       Resource configuration = graph.getPossibleObject(model, simu.HasConfiguration);\r
+                       if(configuration != null) \r
+                               configurations.add(configuration);\r
+                       \r
+                       for(Resource r : graph.getObjects(model, l0.ConsistsOf)) {\r
+                               if(graph.isInheritedFrom(r, sr.Module)) {\r
+                                       Resource moduleConfiguration = graph.getPossibleObject(r, sr2.IsDefinedBy);\r
+                                       if(moduleConfiguration != null)\r
+                                               configurations.add(moduleConfiguration);\r
+                               }\r
+                       }\r
+                       \r
+                       for(Resource conf : configurations) {\r
+                               Resource configurationDiagram = graph.getPossibleObject(conf, mr.CompositeToDiagram);\r
+                               if(configurationDiagram != null && !graph.hasStatement(configurationDiagram, l0.PartOf)) {\r
+                                       GraphUtils.create2(graph, l0.Library, \r
+                                                       l0.HasName, "__CONTAINER__",\r
+                                                       l0.PartOf, conf,\r
+                                                       l0.ConsistsOf, configurationDiagram);\r
+                               }\r
+                       }\r
+                       \r
+               } catch (DatabaseException e) {\r
+                       e.printStackTrace();\r
+               }\r
+       }\r
 }\r
index 048d6291041972f025c381f45f1534abd3f9946a..5f8a66fb69640a73eb5afaad6df3edd551ed4c67 100644 (file)
@@ -22,10 +22,8 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.NameUtils;\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.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.GraphLayerUtil;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.modeling.ModelingResources;\r
@@ -34,6 +32,7 @@ import org.simantics.sysdyn.SysdynResource;
 import org.simantics.sysdyn.ui.browser.nodes.ModulesNode;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
 \r
 public class NewModuleNodeHandler extends AbstractHandler {\r
 \r
@@ -66,22 +65,30 @@ public class NewModuleNodeHandler extends AbstractHandler {
                 g.claim(moduleType, l0.Inherits, sr.Module);\r
                 g.claim(moduleType, l0.PartOf, model);\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, dr.HasLayer, l.getLayer());\r
-                Resource mapping = g.newResource();\r
-                g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
-                g.claim(diagram, l0.HasTrigger, mapping);\r
-\r
-                \r
                 Resource configuration = GraphUtils.create2(g, \r
                         sr.Configuration,\r
                         l0.HasName, name + "Configuration",\r
-                        mr.CompositeToDiagram, diagram,\r
                         l0.PartOf, model);\r
                 \r
                 g.claim(moduleType, sr2.IsDefinedBy , configuration);\r
                 \r
+                Resource diagram = g.newResource();\r
+                g.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(g,\r
+                        ArrayMap\r
+                        .keys("", "diagram", "name")\r
+                        .values(configuration, diagram, "Diagrammi")\r
+                );\r
+                \r
+                \r
+                // Remove default mapping and add sysdyn mapping\r
+                for(Resource trigger : g.getObjects(diagram, l0.HasTrigger)) {\r
+                       if(g.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) {\r
+                               g.deny(diagram, l0.HasTrigger, trigger);\r
+                       }\r
+                }\r
+                Resource mapping = g.newResource();\r
+                g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
+                g.claim(diagram, l0.HasTrigger, mapping);\r
                 \r
                 Resource moduleSymbol = g.newResource();\r
                 g.claimLiteral(moduleSymbol, l0.HasName, name + " Symbol");\r
index 504b7e040e2914e8fc71fa9612f9251916e80f55..96f7693aa7f443b9105b9fe56ebf3be5a6d9bf52 100644 (file)
@@ -29,18 +29,15 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.Queries;\r
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.adapter.RuntimeValuations;\r
+import org.simantics.db.layer0.adapter.Template;\r
 import org.simantics.db.layer0.adapter.TrendVariable;\r
 import org.simantics.db.layer0.service.ActivationManager;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.db.service.GraphChangeListenerSupport;\r
 import org.simantics.db.service.LifecycleSupport;\r
 import org.simantics.db.service.VirtualGraphSupport;\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.Layer0;\r
 import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.modeling.ModelingResources;\r
@@ -66,6 +63,7 @@ import org.simantics.ui.workbench.action.ChooseActionRequest;
 import org.simantics.ui.workbench.project.UIModelManager;\r
 import org.simantics.ui.workbench.project.UIModelManagerBase;\r
 import org.simantics.ui.workbench.project.UIModelManagerBase.WriteRunnable;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
 import org.simantics.utils.datastructures.Callback;\r
 import org.simantics.utils.ui.ErrorLogger;\r
 import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
@@ -111,7 +109,6 @@ public class SysdynProject extends AbstractProjectFeature {
             try {\r
                 Layer0 l0 = Layer0.getInstance(g);\r
                 SysdynResource sr = SysdynResource.getInstance(g);\r
-                ModelingResources mr = ModelingResources.getInstance(g);\r
                 ModelingUtils mu = new ModelingUtils(g);\r
 \r
                 String modelName = NameUtils.findFreshName(g, "Model", SimanticsUI.getProject().get(), l0.ConsistsOf, "%s%d");\r
@@ -122,22 +119,29 @@ public class SysdynProject extends AbstractProjectFeature {
                 g.claim(model, l0.InstanceOf, sr.SysdynModel);\r
                 g.claim(model, l0.PartOf, SimanticsUI.getProject().get());\r
 \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.claimLiteral(diagram, l0.HasName, "Diagrammi", Bindings.STRING);\r
-\r
                 Resource conf = GraphUtils.create2(g,\r
                         sr.Configuration,\r
                         l0.PartOf, model,\r
                         l0.IsBaseRealizationOf, model,\r
                         l0.HasName, modelName\r
                 );\r
+                \r
+                Resource diagram = g.newResource();\r
+                g.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(g,\r
+                        ArrayMap\r
+                        .keys("", "diagram", "name")\r
+                        .values(conf, diagram, "Diagrammi")\r
+                );\r
 \r
-                g.claim(conf, mr.CompositeToDiagram, diagram);\r
                 g.claim(model, mu.SIMU.HasConfiguration, conf);\r
 \r
+                ModelingResources mr = ModelingResources.getInstance(g);\r
+                // Remove default mapping and add sysdyn mapping\r
+                for(Resource trigger : g.getObjects(diagram, l0.HasTrigger)) {\r
+                       if(g.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) {\r
+                               g.deny(diagram, l0.HasTrigger, trigger);\r
+                       }\r
+                }\r
                 Resource mapping = g.newResource();\r
                 g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
                 g.claim(diagram, l0.HasTrigger, mapping);\r
index ac2e1c8e36f6525679f45e5ab70bebf51e8a2a3a..f6e40dedb75dab01dc4339d66ec23ee445340f7d 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.properties.widgets;
 \r
 import java.awt.event.ActionEvent;\r
 import java.awt.event.ActionListener;\r
+import java.util.Collection;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
 \r
@@ -32,6 +33,7 @@ import org.simantics.db.common.utils.OrderedSetUtils;
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypes.ExpressionType;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.AuxiliaryExpression;\r
@@ -171,9 +173,11 @@ public class ExpressionWidget implements Widget {
                                @Override\r
                                public Resource perform(ReadGraph graph) throws DatabaseException {\r
                                        SysdynResource sr = SysdynResource.getInstance(graph);\r
-\r
-                                       Resource expressionList = OrderedSetUtils.getSingleOwnerList(graph, expr);\r
-                                       Resource variable = graph.getPossibleObject(expressionList, sr.HasExpressions_Inverse);\r
+                                       Layer0 l0 = Layer0.getInstance(graph);\r
+                                       Collection<Resource> expressionLists = OrderedSetUtils.getOwnerLists(graph, expr, l0.OrderedSet);\r
+                                       Resource variable = null;\r
+                                       if(expressionLists.size() == 1)\r
+                                               variable = graph.getPossibleObject(expressionLists.iterator().next(), sr.HasExpressions_Inverse);\r
                                        return variable;\r
                                }\r
                        });\r
index d1edbb2b446c17a2deb01e6b7c21b6255aa642b7..e36ffbad7e2e77f21dbe80d4c54a9e78b5844e8e 100644 (file)
@@ -154,9 +154,11 @@ public class BasicExpression implements IExpression {
                                                        @Override\r
                                                        public void perform(WriteGraph graph) throws DatabaseException {\r
                                                                SysdynResource sr = SysdynResource.getInstance(graph);\r
-                                                               if(graph.hasStatement(activefor, sr.HasActiveExpression))\r
-                                                                       graph.deny(activefor, sr.HasActiveExpression);\r
-                                                               graph.claim(activefor, sr.HasActiveExpression, newExpression);\r
+                                                               if(activefor != null) {\r
+                                                                       if(graph.hasStatement(activefor, sr.HasActiveExpression))\r
+                                                                               graph.deny(activefor, sr.HasActiveExpression);\r
+                                                                       graph.claim(activefor, sr.HasActiveExpression, newExpression);\r
+                                                               }\r
                                                        }\r
                                                }\r
                                                );\r
index f07b19fb1c941c1e725e7b85f2abdb1472dc636a..fbee902cd6604c680cc285f09dd31eaf49693ca5 100644 (file)
@@ -181,8 +181,9 @@ public class StockExpression implements IExpression {
                     \r
                     // find the variable\r
                     Resource expressionList = OrderedSetUtils.getSingleOwnerList(graph, expression);\r
-                    Resource variable = graph.getSingleObject(expressionList, sr.HasExpressions_Inverse);\r
-                    \r
+                    Resource variable = graph.getPossibleObject(expressionList, sr.HasExpressions_Inverse);\r
+                    if(variable == null)\r
+                       return "";\r
                     \r
                        SysdynModelManager sdm = SysdynModelManager.getInstance(graph.getSession());\r
                        SysdynModel model = sdm.getModel(graph, graph.getSingleObject(variable, l0.PartOf));\r
index 2b08d71e419349edb087167e9932080022d0046d..1402f225b609a6c103891bc224437f2401639ba5 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Map;
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
+import org.simantics.db.exception.AdaptionException;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.variable.StandardGraphChildVariable;\r
 import org.simantics.db.layer0.variable.Variable;\r
@@ -42,8 +43,12 @@ public class ConfigurationVariable extends StandardGraphChildVariable {
        @Override\r
        public Collection<Variable> browseChildren(ReadGraph graph) throws DatabaseException {\r
                ArrayList<Variable> result = new ArrayList<Variable>();\r
-               for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(resource)).values())\r
+               for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(resource)).values()) {\r
+                       try {\r
                        result.add(graph.adaptContextual(child, this, Variable.class, Variable.class));\r
+                       } catch (AdaptionException e) {\r
+                       }\r
+               }\r
                collectSpecialChildren(graph, result);\r
                return result;\r
        }\r
index c5e21968cbd2fc49ec6f59f3bddf43383a005037..bfc5120f574c2aa28479c882da2fc5501383edc2 100644 (file)
@@ -19,6 +19,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
 import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.AdaptionException;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.exception.MissingVariableException;\r
 import org.simantics.db.layer0.variable.Variable;\r
@@ -60,8 +61,12 @@ public class ModuleVariable extends ChildVariable {
                if(configuration == null)\r
                        return result;\r
                \r
-               for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(configuration)).values())\r
-                       result.add(graph.adaptContextual(child, this, Variable.class, Variable.class));\r
+               for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(configuration)).values()) {\r
+                       try {\r
+                               result.add(graph.adaptContextual(child, this, Variable.class, Variable.class));\r
+                       } catch (AdaptionException e) {\r
+                       }\r
+               }\r
                \r
                return result;\r
        }\r
index 98e00c954e6732694b149fc6879e2b493f028c30..d684b8862730a78a6ab5ff4809f69e3153e3cb3d 100644 (file)
@@ -14,20 +14,17 @@ package org.simantics.sysdyn.mdlImport.mdlElements;
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
 \r
-import org.simantics.databoard.Bindings;\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.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.DiagramConstants;\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.db.layer0.adapter.Template;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.modeling.ModelingResources;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.modeling.ModelingResources;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
 \r
 public class Model implements IWriteableMDLObject {\r
 \r
@@ -219,8 +216,6 @@ public class Model implements IWriteableMDLObject {
                try {\r
                        SysdynResource sr = SysdynResource.getInstance(graph);\r
                        Layer0 l0 = Layer0.getInstance(graph);\r
-                       ModelingResources mr = ModelingResources.getInstance(graph);\r
-                       DiagramResource dr = DiagramResource.getInstance(graph);\r
                        SimulationResource simu = SimulationResource.getInstance(graph);\r
 \r
                        // Diagram creation copied from SysdynProject. \r
@@ -233,7 +228,7 @@ public class Model implements IWriteableMDLObject {
                                        graph,\r
                                        sr.SysdynModel,\r
                                        l0.PartOf, parent,\r
-                                       l0.HasName, getName(),\r
+                                       l0.HasName, NameUtils.findFreshName(graph, getName(), parent, l0.ConsistsOf, "%s%d"),\r
                                        l0.HasLabel, getName(),\r
                                        sr.HasStartTime, startTime,\r
                                        sr.HasStopTime, endTime,\r
@@ -241,25 +236,35 @@ public class Model implements IWriteableMDLObject {
                                        l0.IsLinkedTo, layer0\r
                        );\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, dr.HasLayer, l.getLayer());\r
-                       graph.claimLiteral(diagram, l0.HasName, "Diagrammi", Bindings.STRING);\r
 \r
                        Resource conf = GraphUtils.create2(graph,\r
                                        sr.Configuration,\r
                                        l0.PartOf, model,\r
                                        l0.HasName, getName()\r
                        );\r
+                       \r
+                       Resource diagram = graph.newResource();\r
+            graph.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(graph,\r
+                    ArrayMap\r
+                    .keys("", "diagram", "name")\r
+                    .values(conf, diagram, "Diagrammi")\r
+            );\r
+            \r
+            \r
+            ModelingResources mr = ModelingResources.getInstance(graph);\r
+            // Remove default mapping and add sysdyn mapping\r
+            for(Resource trigger : graph.getObjects(diagram, l0.HasTrigger)) {\r
+               if(graph.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) {\r
+                       graph.deny(diagram, l0.HasTrigger, trigger);\r
+               }\r
+            }\r
+            Resource mapping = graph.newResource();\r
+            graph.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
+            graph.claim(diagram, l0.HasTrigger, mapping);\r
 \r
-                       graph.claim(conf, mr.CompositeToDiagram, diagram);\r
                        graph.claim(model, simu.HasConfiguration, conf);\r
                        graph.claim(model, l0.HasBaseRealization, conf);\r
 \r
-                       Resource mapping = graph.newResource();\r
-                       graph.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
-                       graph.claim(diagram, l0.HasTrigger, mapping);\r
-\r
                        Resource report = GraphUtils.create2(graph, l0.Report,  l0.HasDocumentation, "===Report===");\r
 \r
                        GraphUtils.create2(graph, simu.Experiment,\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LibraryDummy.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LibraryDummy.java
new file mode 100644 (file)
index 0000000..8762ade
--- /dev/null
@@ -0,0 +1,15 @@
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+\r
+@GraphType("http://www.simantics.org/Layer0-1.0/Library")\r
+public class LibraryDummy implements IElement {\r
+       \r
+    @Override\r
+    public void accept(IElementVisitorVoid v) {\r
+        v.visit(this);        \r
+    }\r
+\r
+}\r
index 29a78badef08efb1ea7a6fbe70a6d961b7294c7a..3614a667ca44ea76da723ce3c7873c988b0a2eb3 100644 (file)
@@ -50,16 +50,12 @@ public class SysdynSchema extends SimpleSchema {
             addLinkType(MappingSchemas.fromAnnotations(g, WithLookupExpression.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, LookupExpression.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, Redeclaration.class));\r
-            \r
-            \r
+            addLinkType(MappingSchemas.fromAnnotations(g, LibraryDummy.class));\r
         } catch (DatabaseException e) {\r
-            // TODO Auto-generated catch block\r
             e.printStackTrace();\r
         } catch (InstantiationException e) {\r
-            // TODO Auto-generated catch block\r
             e.printStackTrace();\r
         } catch (IllegalAccessException e) {\r
-            // TODO Auto-generated catch block\r
             e.printStackTrace();\r
         }        \r
     }\r
index 7a224f9516f9b94ff43ab6c2d852ac06cb30b08e..af988b5dc10a51f6059ec80dd1b5015a7981b432 100644 (file)
@@ -18,6 +18,7 @@ import org.simantics.sysdyn.representation.Dependency;
 import org.simantics.sysdyn.representation.Enumeration;\r
 import org.simantics.sysdyn.representation.Flow;\r
 import org.simantics.sysdyn.representation.Input;\r
+import org.simantics.sysdyn.representation.LibraryDummy;\r
 import org.simantics.sysdyn.representation.Module;\r
 import org.simantics.sysdyn.representation.Stock;\r
 import org.simantics.sysdyn.representation.Valve;\r
@@ -63,4 +64,8 @@ public class ElementVisitorVoidAdapter implements IElementVisitorVoid {
     @Override\r
     public void visit(Enumeration enumeration) {\r
     }\r
+    \r
+    @Override\r
+    public void visit(LibraryDummy libraryDummy) {\r
+    }\r
 }\r
index 0d560b2b434f32d09b425b65b908118255d41307..9c7e55045d4b0a885d78871b982a616067159f29 100644 (file)
@@ -18,6 +18,7 @@ import org.simantics.sysdyn.representation.Dependency;
 import org.simantics.sysdyn.representation.Enumeration;\r
 import org.simantics.sysdyn.representation.Flow;\r
 import org.simantics.sysdyn.representation.Input;\r
+import org.simantics.sysdyn.representation.LibraryDummy;\r
 import org.simantics.sysdyn.representation.Module;\r
 import org.simantics.sysdyn.representation.Stock;\r
 import org.simantics.sysdyn.representation.Valve;\r
@@ -34,4 +35,5 @@ public interface IElementVisitorVoid {
     void visit(Module module);\r
     void visit(Configuration configuration);\r
     void visit(Enumeration enumeration);\r
+    void visit(LibraryDummy libraryDummy);\r
 }\r