]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
First take on Enumerations in System Dynamics.
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 2 Nov 2010 14:11:03 +0000 (14:11 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 2 Nov 2010 14:11:03 +0000 (14:11 +0000)
Enumerations can be created to Configurations and deleted from the model browser.

Properties of the enumerations can be modified from the property view (add & remove indexes).

Enumeration is added to the modelica code, but it cannot be used yet.

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@18557 ac1ea38d-2e2b-0410-8846-a27921b304fc

22 files changed:
org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedOrderedSetElements.java [new file with mode: 0644]
org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedOrderedSetElementsRuleFactory.java [new file with mode: 0644]
org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedOrderedSetElementsAccessor.java [new file with mode: 0644]
org.simantics.sysdyn.ontology/graph.tg
org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph
org.simantics.sysdyn.ontology/graph/WorkModel.pgraph
org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/BrowserSelection.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynBrowser.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Configuration.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewEnumerationNodeHandler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/EnumerationIndex.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/EnumerationIndexes.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

diff --git a/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedOrderedSetElements.java b/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedOrderedSetElements.java
new file mode 100644 (file)
index 0000000..21b3e17
--- /dev/null
@@ -0,0 +1,27 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.objmap.annotations;\r
+\r
+import java.lang.annotation.ElementType;\r
+import java.lang.annotation.Retention;\r
+import java.lang.annotation.RetentionPolicy;\r
+import java.lang.annotation.Target;\r
+\r
+import org.simantics.objmap.annotations.factories.RelatedOrderedSetElementsRuleFactory;\r
+import org.simantics.objmap.annotations.meta.HasFieldRuleFactory;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@Target(ElementType.FIELD)\r
+@HasFieldRuleFactory(RelatedOrderedSetElementsRuleFactory.class)\r
+public @interface RelatedOrderedSetElements {\r
+       boolean composition() default false;\r
+}\r
diff --git a/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedOrderedSetElementsRuleFactory.java b/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedOrderedSetElementsRuleFactory.java
new file mode 100644 (file)
index 0000000..fb78847
--- /dev/null
@@ -0,0 +1,40 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.objmap.annotations.factories;\r
+\r
+import java.lang.annotation.Annotation;\r
+import java.lang.reflect.Field;\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.ResourceNotFoundException;\r
+import org.simantics.db.exception.ServiceException;\r
+import org.simantics.db.exception.ValidationException;\r
+import org.simantics.objmap.IMappingRule;\r
+import org.simantics.objmap.annotations.RelatedOrderedSetElements;\r
+import org.simantics.objmap.rules.MappedElementsRule;\r
+import org.simantics.objmap.rules.domain.RelatedOrderedSetElementsAccessor;\r
+import org.simantics.objmap.rules.factory.IFieldRuleFactory;\r
+import org.simantics.objmap.rules.range.FieldAccessor;\r
+\r
+public class RelatedOrderedSetElementsRuleFactory implements IFieldRuleFactory {\r
+\r
+    @Override\r
+    public IMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException {\r
+        RelatedOrderedSetElements annotation = (RelatedOrderedSetElements)_annotation;\r
+        return new MappedElementsRule(\r
+                new RelatedOrderedSetElementsAccessor(annotation.composition()),\r
+                new FieldAccessor<Collection<Object>>(field)\r
+                );\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedOrderedSetElementsAccessor.java b/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedOrderedSetElementsAccessor.java
new file mode 100644 (file)
index 0000000..a92d2d2
--- /dev/null
@@ -0,0 +1,62 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.objmap.rules.domain;\r
+\r
+import java.util.Collection;\r
+\r
+import org.apache.log4j.Logger;\r
+import org.simantics.db.ReadGraph;\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.objmap.MappingException;\r
+\r
+/**\r
+ * Accesses the set of objects attached to the element by the given relation.\r
+ * @author Hannu Niemistö\r
+ */\r
+public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Collection<Resource>> {\r
+\r
+    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");\r
+    \r
+       boolean deleteExtraObjects;\r
+\r
+       public RelatedOrderedSetElementsAccessor(boolean deleteExtraObjects) {\r
+        super();\r
+        this.deleteExtraObjects = deleteExtraObjects;\r
+    }\r
+\r
+    @Override\r
+       public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {\r
+               try {\r
+                   LOGGER.info("        RelatedOrderedSetElementsAccessor.get");\r
+                       return OrderedSetUtils.toList(g, element);\r
+               } catch (DatabaseException e) {\r
+                       throw new MappingException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public boolean set(WriteGraph g, Resource element, Collection<Resource> value)\r
+                       throws MappingException {\r
+               try {\r
+                   LOGGER.info("        RelatedOrderedSetElementsAccessor.set");\r
+                   return OrderedSetUtils.set(g, element, value);\r
+                   // FIXME Implement deleteExtraObjects\r
+               } catch (DatabaseException e) {\r
+                       throw new MappingException(e);\r
+               }\r
+               \r
+       }\r
+\r
+}\r
index 05c8dcb9682d71024a1e3bd8e3b04632f2c7b26e..ee9c3913f501dd71c9016fdd35654c78a50ef5ec 100644 (file)
Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ
index c87108f13df6affa347010bd399635389518bc38..e76fb2903ca344e44170198093aa4f447271e383 100644 (file)
@@ -80,17 +80,10 @@ SYSDYN.DefaultRealization <T L0.Realization
 
 SYSDYN.Variable <T STR.Component    
     @L0.singleProperty L0.HasType
-    @L0.singleProperty SYSDYN.HasX
-    @L0.singleProperty SYSDYN.HasY
 
-SYSDYN.HasX <R L0.HasProperty : L0.FunctionalRelation
-    L0.HasRange L0.Double
-SYSDYN.HasY <R L0.HasProperty : L0.FunctionalRelation
-    L0.HasRange L0.Double
 SYSDYN.HasExpression <R L0.IsComposedOf : L0.FunctionalRelation
     L0.HasRange SYSDYN.Expression
 
-
 SYSDYN.HasUnit <R L0.HasProperty
     L0.HasRange L0.String
 
@@ -128,6 +121,11 @@ SYSDYN.Input <T SYSDYN.Variable
     @L0.optionalProperty SYSDYN.HasUnit
     @L0.assert SYSDYN.HasDefaultInputValue 0.0
     @L0.assert L0.HasType "Real"
+    
+SYSDYN.Enumeration <T SYSDYN.Variable
+    @L0.singleProperty SYSDYN.HasEnumerationIndexes
+    @L0.assert L0.HasType "type"
+    
 
 //#####################################################################
 // Modules
@@ -237,6 +235,14 @@ SYSDYN.WithLookupExpression <T SYSDYN.Expression
 SYSDYN.HasDefaultInputValue <R L0.HasProperty : L0.FunctionalRelation
     L0.HasRange L0.Double
 
+SYSDYN.HasEnumerationIndexes <R L0.DependsOn : L0.FunctionalRelation
+    L0.HasDomain SYSDYN.Enumeration
+    L0.HasRange SYSDYN.EnumerationIndexes
+    
+SYSDYN.EnumerationIndexes <T L0.OrderedSet <R L0.HasNext
+
+SYSDYN.EnumerationIndex <T L0.Entity
+    L0.singleProperty L0.HasName
 //#####################################################################
 // Experiments
 //#####################################################################
index 038af8d4bed88f4d3c994fb045a1c8730dd58440..6463583d787ce8e4c589315e5f3f6e948381cd8f 100644 (file)
@@ -119,7 +119,16 @@ WC.Work2CompletionTime : SYSDYN.Auxiliary
 WC.Work2Amount : SYSDYN.Auxiliary\r
       @L0.tag MOD.Mapped    \r
       SYSDYN.HasExpression _ : SYSDYN.ParameterExpression\r
-        SYSDYN.HasEquation "700"             \r
+        SYSDYN.HasEquation "700"     \r
+        \r
+// Enumeration Test\r
+WC.EnumerationTest : SYSDYN.Enumeration\r
+    SYSDYN.HasEnumerationIndexes _ : SYSDYN.EnumerationIndexes\r
+        @L0.list\r
+            _ : SYSDYN.EnumerationIndex\r
+                L0.HasName "Moro" : L0.String\r
+            _ : SYSDYN.EnumerationIndex\r
+                L0.HasName "Tere" : L0.String            \r
      \r
 // Inputs\r
 WC.TotalPossibleWorkingSpeedInput : SYSDYN.Input\r
index bb693dcccfa28f3a0af0114d6bd027769ec432c2..15448870845c14c3d87cf47e9c71075d68f44f99 100644 (file)
@@ -39,6 +39,7 @@ public class SysdynResource {
     public final Resource DevelopmentProject_WorkModel;\r
     public final Resource DevelopmentProject_WorkModel_Experiment;\r
     public final Resource DevelopmentProject_WorkModel_WorkModelConfiguration;\r
+    public final Resource DevelopmentProject_WorkModel_WorkModelConfiguration_EnumerationTest;\r
     public final Resource DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed1;\r
     public final Resource DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed2;\r
     public final Resource DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeedTotal;\r
@@ -141,6 +142,10 @@ public class SysdynResource {
     public final Resource DevelopmentProject_dependency;\r
     public final Resource DevelopmentProject_flow;\r
     public final Resource DiagramToCompositeMapping;\r
+    public final Resource Enumeration;\r
+    public final Resource EnumerationIndex;\r
+    public final Resource EnumerationIndexes;\r
+    public final Resource EnumerationIndexes_Inverse;\r
     public final Resource Experiment;\r
     public final Resource Expression;\r
     public final Resource Flow;\r
@@ -148,6 +153,8 @@ public class SysdynResource {
     public final Resource GameExperiment;\r
     public final Resource HasDefaultInputValue;\r
     public final Resource HasDefaultInputValue_Inverse;\r
+    public final Resource HasEnumerationIndexes;\r
+    public final Resource HasEnumerationIndexes_Inverse;\r
     public final Resource HasEquation;\r
     public final Resource HasEquation_Inverse;\r
     public final Resource HasExpression;\r
@@ -192,10 +199,6 @@ public class SysdynResource {
     public final Resource HasTolerance_Inverse;\r
     public final Resource HasUnit;\r
     public final Resource HasUnit_Inverse;\r
-    public final Resource HasX;\r
-    public final Resource HasX_Inverse;\r
-    public final Resource HasY;\r
-    public final Resource HasY_Inverse;\r
     public final Resource HistoryRealization;\r
     public final Resource ImportedOntologies;\r
     public final Resource IndependentVariable;\r
@@ -252,6 +255,7 @@ public class SysdynResource {
         public static final String DevelopmentProject_WorkModel = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel";\r
         public static final String DevelopmentProject_WorkModel_Experiment = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel/Experiment";\r
         public static final String DevelopmentProject_WorkModel_WorkModelConfiguration = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel/WorkModelConfiguration";\r
+        public static final String DevelopmentProject_WorkModel_WorkModelConfiguration_EnumerationTest = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel/WorkModelConfiguration/EnumerationTest";\r
         public static final String DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed1 = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel/WorkModelConfiguration/RequiredWorkingSpeed1";\r
         public static final String DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed2 = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel/WorkModelConfiguration/RequiredWorkingSpeed2";\r
         public static final String DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeedTotal = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel/WorkModelConfiguration/RequiredWorkingSpeedTotal";\r
@@ -354,6 +358,10 @@ public class SysdynResource {
         public static final String DevelopmentProject_dependency = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/dependency";\r
         public static final String DevelopmentProject_flow = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/flow";\r
         public static final String DiagramToCompositeMapping = "http://www.simantics.org/Sysdyn-1.0/DiagramToCompositeMapping";\r
+        public static final String Enumeration = "http://www.simantics.org/Sysdyn-1.0/Enumeration";\r
+        public static final String EnumerationIndex = "http://www.simantics.org/Sysdyn-1.0/EnumerationIndex";\r
+        public static final String EnumerationIndexes = "http://www.simantics.org/Sysdyn-1.0/EnumerationIndexes";\r
+        public static final String EnumerationIndexes_Inverse = "http://www.simantics.org/Sysdyn-1.0/EnumerationIndexes/Inverse";\r
         public static final String Experiment = "http://www.simantics.org/Sysdyn-1.0/Experiment";\r
         public static final String Expression = "http://www.simantics.org/Sysdyn-1.0/Expression";\r
         public static final String Flow = "http://www.simantics.org/Sysdyn-1.0/Flow";\r
@@ -361,6 +369,8 @@ public class SysdynResource {
         public static final String GameExperiment = "http://www.simantics.org/Sysdyn-1.0/GameExperiment";\r
         public static final String HasDefaultInputValue = "http://www.simantics.org/Sysdyn-1.0/HasDefaultInputValue";\r
         public static final String HasDefaultInputValue_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasDefaultInputValue/Inverse";\r
+        public static final String HasEnumerationIndexes = "http://www.simantics.org/Sysdyn-1.0/HasEnumerationIndexes";\r
+        public static final String HasEnumerationIndexes_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasEnumerationIndexes/Inverse";\r
         public static final String HasEquation = "http://www.simantics.org/Sysdyn-1.0/HasEquation";\r
         public static final String HasEquation_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasEquation/Inverse";\r
         public static final String HasExpression = "http://www.simantics.org/Sysdyn-1.0/HasExpression";\r
@@ -405,10 +415,6 @@ public class SysdynResource {
         public static final String HasTolerance_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasTolerance/Inverse";\r
         public static final String HasUnit = "http://www.simantics.org/Sysdyn-1.0/HasUnit";\r
         public static final String HasUnit_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasUnit/Inverse";\r
-        public static final String HasX = "http://www.simantics.org/Sysdyn-1.0/HasX";\r
-        public static final String HasX_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasX/Inverse";\r
-        public static final String HasY = "http://www.simantics.org/Sysdyn-1.0/HasY";\r
-        public static final String HasY_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasY/Inverse";\r
         public static final String HistoryRealization = "http://www.simantics.org/Sysdyn-1.0/HistoryRealization";\r
         public static final String ImportedOntologies = "http://www.simantics.org/Sysdyn-1.0/ImportedOntologies";\r
         public static final String IndependentVariable = "http://www.simantics.org/Sysdyn-1.0/IndependentVariable";\r
@@ -475,6 +481,7 @@ public class SysdynResource {
         DevelopmentProject_WorkModel = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel);\r
         DevelopmentProject_WorkModel_Experiment = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel_Experiment);\r
         DevelopmentProject_WorkModel_WorkModelConfiguration = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel_WorkModelConfiguration);\r
+        DevelopmentProject_WorkModel_WorkModelConfiguration_EnumerationTest = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel_WorkModelConfiguration_EnumerationTest);\r
         DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed1 = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed1);\r
         DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed2 = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed2);\r
         DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeedTotal = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeedTotal);\r
@@ -577,6 +584,10 @@ public class SysdynResource {
         DevelopmentProject_dependency = getResourceOrNull(graph, URIs.DevelopmentProject_dependency);\r
         DevelopmentProject_flow = getResourceOrNull(graph, URIs.DevelopmentProject_flow);\r
         DiagramToCompositeMapping = getResourceOrNull(graph, URIs.DiagramToCompositeMapping);\r
+        Enumeration = getResourceOrNull(graph, URIs.Enumeration);\r
+        EnumerationIndex = getResourceOrNull(graph, URIs.EnumerationIndex);\r
+        EnumerationIndexes = getResourceOrNull(graph, URIs.EnumerationIndexes);\r
+        EnumerationIndexes_Inverse = getResourceOrNull(graph, URIs.EnumerationIndexes_Inverse);\r
         Experiment = getResourceOrNull(graph, URIs.Experiment);\r
         Expression = getResourceOrNull(graph, URIs.Expression);\r
         Flow = getResourceOrNull(graph, URIs.Flow);\r
@@ -584,6 +595,8 @@ public class SysdynResource {
         GameExperiment = getResourceOrNull(graph, URIs.GameExperiment);\r
         HasDefaultInputValue = getResourceOrNull(graph, URIs.HasDefaultInputValue);\r
         HasDefaultInputValue_Inverse = getResourceOrNull(graph, URIs.HasDefaultInputValue_Inverse);\r
+        HasEnumerationIndexes = getResourceOrNull(graph, URIs.HasEnumerationIndexes);\r
+        HasEnumerationIndexes_Inverse = getResourceOrNull(graph, URIs.HasEnumerationIndexes_Inverse);\r
         HasEquation = getResourceOrNull(graph, URIs.HasEquation);\r
         HasEquation_Inverse = getResourceOrNull(graph, URIs.HasEquation_Inverse);\r
         HasExpression = getResourceOrNull(graph, URIs.HasExpression);\r
@@ -628,10 +641,6 @@ public class SysdynResource {
         HasTolerance_Inverse = getResourceOrNull(graph, URIs.HasTolerance_Inverse);\r
         HasUnit = getResourceOrNull(graph, URIs.HasUnit);\r
         HasUnit_Inverse = getResourceOrNull(graph, URIs.HasUnit_Inverse);\r
-        HasX = getResourceOrNull(graph, URIs.HasX);\r
-        HasX_Inverse = getResourceOrNull(graph, URIs.HasX_Inverse);\r
-        HasY = getResourceOrNull(graph, URIs.HasY);\r
-        HasY_Inverse = getResourceOrNull(graph, URIs.HasY_Inverse);\r
         HistoryRealization = getResourceOrNull(graph, URIs.HistoryRealization);\r
         ImportedOntologies = getResourceOrNull(graph, URIs.ImportedOntologies);\r
         IndependentVariable = getResourceOrNull(graph, URIs.IndependentVariable);\r
index d6acf449e0ec38f2fd994e0ab61aeae49d34b2a5..f03840181ac87225049c77bc4f9991e75ff5a663 100644 (file)
                   </with>\r
                </visibleWhen>\r
             </command>\r
+            <command\r
+                  commandId="org.simantics.sysdyn.ui.newEnumeration"\r
+                  id="org.simantics.sysdyn.ui.browser.newEnumeration"\r
+                  label="Enumeration"\r
+                  style="push">\r
+               <visibleWhen\r
+                     checkEnabled="true">\r
+                  <with\r
+                        variable="selection">\r
+                     <test\r
+                           args="org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode"\r
+                           property="org.simantics.sysdyn.ui.nodeClass">\r
+                     </test>\r
+                  </with>\r
+               </visibleWhen>\r
+            </command>\r
          </menu>\r
          <command\r
                commandId="org.simantics.image.ui.importImage"\r
             id="org.simantics.sysdyn.ui.importModel"\r
             name="Import...">\r
       </command>\r
+      <command\r
+            defaultHandler="org.simantics.sysdyn.ui.handlers.NewEnumerationNodeHandler"\r
+            id="org.simantics.sysdyn.ui.newEnumeration"\r
+            name="New Enumeration">\r
+      </command>\r
    </extension>\r
    <extension\r
          point="org.eclipse.ui.handlers">\r
                         args="org.simantics.image.ui.modelBrowser.ImageNode"\r
                         property="org.simantics.sysdyn.ui.nodeClass">\r
                   </test>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.EnumerationNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
                </or>\r
             </with>\r
          </activeWhen>\r
index 619de4f0a36dc19945fa037dbba6729b4cb64aed..4106a4553b8afc42453631c6e737b6ad375df495 100644 (file)
 package org.simantics.sysdyn.ui.browser;\r
 \r
 import org.eclipse.core.runtime.IAdaptable;\r
+import org.simantics.browsing.ui.NodeContext;\r
 import org.simantics.db.Resource;\r
 \r
 public class BrowserSelection implements IAdaptable {\r
        private Resource resource;\r
        private Resource model;\r
        private String URI;\r
+       private Object originalInput;\r
 \r
-       public BrowserSelection(Resource resource, String URI, Resource model) {\r
+       public BrowserSelection(Object originalInput, Resource resource, String URI, Resource model) {\r
+               this.originalInput = originalInput;\r
                this.resource = resource;\r
                this.URI = URI;\r
                this.model = model;\r
@@ -30,6 +33,12 @@ public class BrowserSelection implements IAdaptable {
        public Object getAdapter(Class adapter) {\r
                if (adapter == Resource.class)\r
                        return resource;\r
+               if (NodeContext.class.equals(adapter))\r
+            return originalInput;\r
+               if (originalInput instanceof IAdaptable) {\r
+                       IAdaptable input = (IAdaptable)originalInput;\r
+                       return input.getAdapter(adapter);\r
+               }\r
                return null;\r
        }\r
        \r
index 6905e7e6024b35f9170ca0ec56b86932fc1bcc96..dac17e5e20ca416bd4877ed9ca754b725e71a69b 100644 (file)
@@ -54,7 +54,7 @@ public class SysdynBrowser extends GraphExplorerView {
                    if(vn != null) {\r
                        Resource resource = vn.getResource() == null ? vn.data : vn.getResource();\r
                        context = new AdaptableHintContext(SelectionHints.KEY_MAIN, SelectionHints.KEY_SELECTION_PROPERTY);\r
-                       context.setHint(SelectionHints.KEY_MAIN, new BrowserSelection(resource, vn.getURI(), vn.getModel()));\r
+                       context.setHint(SelectionHints.KEY_MAIN, new BrowserSelection(objects[i], resource, vn.getURI(), vn.getModel()));\r
                        context.setHint(SelectionHints.KEY_SELECTION_PROPERTY, vn.getVariable());\r
                    } else {\r
                        context = new AdaptableHintContext(SelectionHints.KEY_MAIN);\r
index 89edaaa4a2558e4705a685d1fdbe4d79ec5e2f3e..7baf104839b8ddfd538d274fda5f26dffa42c124 100644 (file)
@@ -22,6 +22,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.EnumerationNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.InputNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
@@ -39,6 +40,7 @@ public class Configuration extends ViewpointContributor<ConfigurationNode<Resour
                ArrayList<Resource> variables = new ArrayList<Resource>();\r
                ArrayList<Resource> inputs = new ArrayList<Resource>();\r
                ArrayList<Resource> modules = new ArrayList<Resource>();\r
+               ArrayList<Resource> enumerations = new ArrayList<Resource>();\r
                \r
                for(Resource r : graph.getObjects(configuration.data, l0.ConsistsOf)) {\r
                        Resource represents  = graph.getSingleObject(r, l0.Represents);\r
@@ -48,6 +50,8 @@ public class Configuration extends ViewpointContributor<ConfigurationNode<Resour
                                inputs.add(r);\r
                        } else if (graph.isInstanceOf(represents, sr.Module)) {\r
                                modules.add(r);\r
+                       } else if (graph.isInstanceOf(represents, sr.Enumeration)) {\r
+                               enumerations.add(r);\r
                        }\r
                }\r
                \r
@@ -57,6 +61,8 @@ public class Configuration extends ViewpointContributor<ConfigurationNode<Resour
                        result.add(new InputNode(r));\r
                for (Resource r : modules) \r
                        result.add(new ModuleNode(r));\r
+               for (Resource r : enumerations) \r
+                       result.add(new EnumerationNode(r));\r
                return result;\r
        }\r
 \r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java
new file mode 100644 (file)
index 0000000..a069acb
--- /dev/null
@@ -0,0 +1,35 @@
+package org.simantics.sysdyn.ui.browser.nodes;\r
+\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDeletableNode;\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.CancelTransactionException;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+\r
+public class EnumerationNode extends VariableNode<Resource> implements IDeletableNode {\r
+\r
+       public EnumerationNode(Resource resource) {\r
+               super(resource);\r
+       }\r
+\r
+       @Override\r
+       public void delete() throws DeleteException {\r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+                @Override\r
+                public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
+                    Layer0 l0 = Layer0.getInstance(graph);\r
+                    graph.deny(resource, l0.PartOf);                \r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            ExceptionUtils.logAndShowError(e);\r
+        }        \r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewEnumerationNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewEnumerationNodeHandler.java
new file mode 100644 (file)
index 0000000..bbccf0b
--- /dev/null
@@ -0,0 +1,50 @@
+package org.simantics.sysdyn.ui.handlers;\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.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\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.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+\r
+public class NewEnumerationNodeHandler extends AbstractHandler {\r
+\r
+       @Override\r
+       public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+        ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+        \r
+               final Resource configuration = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
+        \r
+        SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+            @Override\r
+            public void perform(WriteGraph g) throws DatabaseException {\r
+               SysdynResource sr = SysdynResource.getInstance(g);\r
+               Layer0 l0 = Layer0.getInstance(g);\r
+               \r
+\r
+                               Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes);\r
+                               \r
+                               Resource enumeration = GraphUtils.create2(g, \r
+                                               sr.Enumeration,\r
+                                               l0.HasName, "Enumeration",\r
+                                               sr.HasEnumerationIndexes, enumerationIndexes);\r
+               \r
+               g.claim(configuration, l0.ConsistsOf, enumeration);\r
+               \r
+            }\r
+        });\r
+               return null;\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java
new file mode 100644 (file)
index 0000000..ffabdef
--- /dev/null
@@ -0,0 +1,281 @@
+package org.simantics.sysdyn.ui.properties;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.TableEditor;\r
+import org.eclipse.swt.events.FocusAdapter;\r
+import org.eclipse.swt.events.FocusEvent;\r
+import org.eclipse.swt.events.ModifyEvent;\r
+import org.eclipse.swt.events.ModifyListener;\r
+import org.eclipse.swt.events.SelectionAdapter;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.TableItem;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
+import org.simantics.browsing.ui.swt.widgets.Button;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.Table;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.databoard.binding.java.StringBindingDefault;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ReadRequest;\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.db.management.ISessionContext;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameValidator;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+public class EnumerationTab extends PropertyTabContributorImpl {\r
+\r
+       Table table;\r
+       @Override\r
+       public void createControls(Composite body, IWorkbenchSite site,\r
+                       final ISessionContext context, WidgetSupport support) {\r
+\r
+               Composite container = new Composite(body, SWT.None);\r
+               GridDataFactory.fillDefaults().grab(true, true).applyTo(container);\r
+               GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(container);\r
+\r
+        TrackedText nameText = new TrackedText(container, support, SWT.BORDER);\r
+        nameText.setTextFactory(new StringPropertyFactory(Builtins.URIs.HasName));\r
+        nameText.addModifyListener(new VariableNamePropertyModifier(context, Builtins.URIs.HasName));\r
+        nameText.setInputValidator(new VariableNameValidator(support));\r
+        GridDataFactory.fillDefaults().grab(true, false).span(2,1).applyTo(nameText.getWidget());\r
+\r
+\r
+               table = new Table(container, support, SWT.BORDER);\r
+               table.setItemFactory(new ReadFactoryImpl<Object, List<Pair<String,Object>>>() {\r
+\r
+                       @Override\r
+                       public List<Pair<String, Object>> perform(ReadGraph graph,\r
+                                       Object input) throws DatabaseException {\r
+                               Resource enumeration = (Resource)input;\r
+                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                               Resource list = graph.getSingleObject(enumeration, sr.HasEnumerationIndexes);\r
+                               List<Resource> resourceList = OrderedSetUtils.toList(graph, list);\r
+\r
+                               List<Pair<String, Object>> result = new ArrayList<Pair<String, Object>>();\r
+                               for(Resource r : resourceList) {\r
+                                       result.add(new Pair<String, Object>( \r
+                                                       (String)graph.getRelatedValue(r, Layer0.getInstance(graph).HasName, StringBindingDefault.INSTANCE)\r
+                                                       , r));\r
+                               }\r
+                               return result;\r
+                       }\r
+               });\r
+               table.setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
+\r
+                       @Override\r
+                       public String perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+                               return graph.getRelatedValue(input, Layer0.getInstance(graph).HasName);\r
+                       }\r
+               });\r
+               GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(table.getWidget());\r
+               \r
+\r
+               final TableEditor editor = new TableEditor(table.getWidget());\r
+               // The editor must have the same size as the cell and must\r
+               // not be any smaller than 50 pixels.\r
+               editor.horizontalAlignment = SWT.LEFT;\r
+               editor.grabHorizontal = true;\r
+               editor.minimumWidth = 50;\r
+               // editing the second column\r
+               final int EDITABLECOLUMN = 0;\r
+\r
+               table.addSelectionListener(new SelectionAdapter() {\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               // Clean up any previous editor control\r
+                               Control oldEditor = editor.getEditor();\r
+                               if (oldEditor != null)\r
+                                       oldEditor.dispose();\r
+\r
+                               // Identify the selected row\r
+                               final TableItem item = (TableItem) e.item;\r
+                               if (item == null)\r
+                                       return;\r
+\r
+                               // The control that will be the editor must be a child of the\r
+                               // Table\r
+                               Text newEditor = new Text(item.getParent(), SWT.NONE);\r
+                               final String originalText = item.getText(EDITABLECOLUMN);\r
+                               final Resource resource = (Resource) item.getData();\r
+                               newEditor.setText(originalText);\r
+                               newEditor.addModifyListener(new ModifyListener() {\r
+                                       public void modifyText(ModifyEvent me) {\r
+                                               Text text = (Text) editor.getEditor();\r
+                                               if(!text.isDisposed()) {\r
+                                                       TableItem item = editor.getItem();\r
+                                                       if(!item.isDisposed())\r
+                                                               item.setText(EDITABLECOLUMN, text.getText());\r
+                                               }\r
+                                       }\r
+                               });\r
+                               newEditor.addFocusListener(new FocusAdapter() {\r
+                                       @Override\r
+                                       public void focusLost(FocusEvent e) {\r
+                                               final Text text = (Text) editor.getEditor();\r
+                                               if(!text.getText().equals(originalText)) {\r
+                                                       final String newText = text.getText();\r
+                                                       try {\r
+                                                               context.getSession().syncRequest(new WriteRequest() {\r
+\r
+                                                                       @Override\r
+                                                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                                                               graph.claimLiteral(\r
+                                                                                               resource, \r
+                                                                                               Layer0.getInstance(graph).HasName, \r
+                                                                                               newText);\r
+                                                                       }\r
+                                                               });\r
+                                                       } catch (DatabaseException e1) {\r
+                                                               e1.printStackTrace();\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               });\r
+                               newEditor.selectAll();\r
+                               newEditor.setFocus();\r
+                               editor.setEditor(newEditor, item, EDITABLECOLUMN);\r
+                       }\r
+               });\r
+\r
+\r
+               Button add = new Button(container, support, SWT.None);\r
+               add.setText("Add index");\r
+               add.addSelectionListener(new addEnumerationIndexListener(support));\r
+\r
+               Button remove = new Button(container, support, SWT.None);\r
+               remove.setText("Remove");\r
+               remove.addSelectionListener(new removeEnumerationIndexListener(support));\r
+       }\r
+\r
+       private class addEnumerationIndexListener implements SelectionListener, Widget {\r
+\r
+               Resource enumerationIndexes;\r
+\r
+               public addEnumerationIndexListener(WidgetSupport support) {\r
+                       support.register(this);\r
+               }\r
+\r
+               @Override\r
+               public void setInput(ISessionContext context, Object input) {\r
+                       final Resource enumeration = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+                       try {\r
+                               context.getSession().syncRequest(new ReadRequest() {\r
+\r
+                                       @Override\r
+                                       public void run(ReadGraph graph) throws DatabaseException {\r
+                                               enumerationIndexes = graph.getSingleObject(enumeration, SysdynResource.getInstance(graph).HasEnumerationIndexes);\r
+                                       }\r
+                               });\r
+                       } catch (DatabaseException e) {\r
+                               e.printStackTrace();\r
+                       }\r
+               }\r
+\r
+               @Override\r
+               public void widgetSelected(SelectionEvent e) {\r
+                       try {\r
+                               SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+                                       @Override\r
+                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                                               Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+\r
+                                               Resource ei = GraphUtils.create2(graph, \r
+                                                               sr.EnumerationIndex,\r
+                                                               l0.HasName, "index");\r
+                                               OrderedSetUtils.add(graph, enumerationIndexes, ei);\r
+                                       }\r
+                               });\r
+                       } catch (DatabaseException e1) {\r
+                               e1.printStackTrace();\r
+                       }\r
+\r
+               }\r
+\r
+               @Override\r
+               public void widgetDefaultSelected(SelectionEvent e) {\r
+\r
+               }\r
+\r
+       }\r
+\r
+       private class removeEnumerationIndexListener implements SelectionListener, Widget {\r
+\r
+               Resource enumerationIndexes;\r
+\r
+               public removeEnumerationIndexListener(WidgetSupport support) {\r
+                       support.register(this);\r
+               }\r
+\r
+               @Override\r
+               public void setInput(ISessionContext context, Object input) {\r
+                       final Resource enumeration = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+                       try {\r
+                               context.getSession().syncRequest(new ReadRequest() {\r
+\r
+                                       @Override\r
+                                       public void run(ReadGraph graph) throws DatabaseException {\r
+                                               enumerationIndexes = graph.getSingleObject(enumeration, SysdynResource.getInstance(graph).HasEnumerationIndexes);\r
+                                       }\r
+                               });\r
+                       } catch (DatabaseException e) {\r
+                               e.printStackTrace();\r
+                       }\r
+               }\r
+\r
+               @Override\r
+               public void widgetSelected(SelectionEvent e) {\r
+                       TableItem[] items = table.getWidget().getSelection();\r
+                       final ArrayList<Resource> resources = new ArrayList<Resource>();\r
+                       for(int i = 0; i < items.length; i++) {\r
+                               if(items[i].getData() instanceof Resource)\r
+                                       resources.add((Resource)items[i].getData());\r
+                       }\r
+                       try {\r
+                               SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+                                       @Override\r
+                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                               for(Resource r : resources)\r
+                                                       OrderedSetUtils.remove(graph, enumerationIndexes, r);\r
+                                       }\r
+                               });\r
+                       } catch (DatabaseException e1) {\r
+                               e1.printStackTrace();\r
+                       }\r
+\r
+               }\r
+\r
+               @Override\r
+               public void widgetDefaultSelected(SelectionEvent e) {\r
+\r
+               }\r
+\r
+       }\r
+}\r
index cf603073b32cc6ad3d82e295abf34b993aa61aa8..1bb77cb0ae9bed57d802bb024757e9d0d12a1387 100644 (file)
@@ -78,6 +78,13 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
                         r,\r
                 "Input"));\r
             }\r
+            if (backend.isInstanceOf(r, sr.Enumeration)) {\r
+                return Collections.singleton(new ComparableTabContributor(\r
+                        new EnumerationTab(),\r
+                        2,\r
+                        r,\r
+                "Enumeration"));\r
+            }\r
             if ( backend.isInstanceOf(r, sr.Configuration) || backend.isInstanceOf(r, sr.SysdynModel)) {\r
                if(!backend.isInstanceOf(r, sr.SysdynModel))\r
                        r = backend.getPossibleObject(r, SimulationResource.getInstance(backend).IsConfigurationOf);\r
index 8aee0a4b47c1c433498a492c6e2ffd38cb8196ad..cb05625818abaa7785513648e59dd21d41620ada 100644 (file)
@@ -16,6 +16,7 @@ import java.util.HashMap;
 \r
 import org.simantics.sysdyn.representation.Configuration;\r
 import org.simantics.sysdyn.representation.Dependency;\r
+import org.simantics.sysdyn.representation.Enumeration;\r
 import org.simantics.sysdyn.representation.IElement;\r
 import org.simantics.sysdyn.representation.Input;\r
 import org.simantics.sysdyn.representation.Module;\r
@@ -116,6 +117,7 @@ public class ModelicaWriter {
         ArrayList<Input> inputs = new ArrayList<Input>();\r
         ArrayList<Module> modules = new ArrayList<Module>();\r
         ArrayList<Stock> stocks = new ArrayList<Stock>();\r
+        ArrayList<Enumeration> enumerations = new ArrayList<Enumeration>();\r
         ArrayList<Dependency> inputDependencies = new ArrayList<Dependency>();\r
         ArrayList<Dependency> outputDependencies = new ArrayList<Dependency>();\r
         HashMap<String, ArrayList<Input>> moduleInputs = new HashMap<String, ArrayList<Input>>();\r
@@ -136,6 +138,8 @@ public class ModelicaWriter {
                     }\r
             } else if (element instanceof Input) {\r
                 inputs.add((Input)element);\r
+            } else if (element instanceof Enumeration) {\r
+                enumerations.add((Enumeration)element);\r
             } else if (element instanceof Dependency && ((Dependency)element).refersTo() != null) {\r
                 Dependency dependency = (Dependency)element;\r
                 if(dependency.getHead() instanceof Module) {\r
@@ -172,6 +176,13 @@ public class ModelicaWriter {
                 b.append("    " + i.getType() + " " + i.getName() + ";\n");\r
             }\r
         }\r
+        \r
+        if(!enumerations.isEmpty()) {\r
+            b.append("// Enumeration definitions\n");\r
+            for(Enumeration e : enumerations) {\r
+                b.append(e.getDeclaration());\r
+            }\r
+        }\r
 \r
         for(Stock stock : stocks) {\r
             IExpression expr = stock.getExpression();\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java
new file mode 100644 (file)
index 0000000..4176277
--- /dev/null
@@ -0,0 +1,31 @@
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedElement;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn-1.0/Enumeration")\r
+public class Enumeration extends Variable {\r
+       \r
+    @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasEnumerationIndexes")\r
+    private EnumerationIndexes enumerationIndexes;\r
+\r
+       @Override\r
+       public void accept(IElementVisitorVoid v) {\r
+               v.visit(this);  \r
+       }\r
+       \r
+       public String getDeclaration() {\r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append("    " + this.getType());\r
+               sb.append(" " + this.name);\r
+               sb.append(" = enumeration(");\r
+               for(int i = 0; i < enumerationIndexes.getEnumerationIndexes().size(); i++) {\r
+                       sb.append(enumerationIndexes.getEnumerationIndexes().get(i).getName());\r
+                       if(i < enumerationIndexes.getEnumerationIndexes().size() - 1)\r
+                               sb.append(", ");\r
+               }\r
+               sb.append(");\n");\r
+               return sb.toString();\r
+       }\r
+}\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/EnumerationIndex.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/EnumerationIndex.java
new file mode 100644 (file)
index 0000000..9cbff86
--- /dev/null
@@ -0,0 +1,16 @@
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn-1.0/EnumerationIndex")\r
+public class EnumerationIndex {\r
+\r
+    @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName")\r
+    protected String name;\r
+    \r
+    public String getName() {\r
+        return this.name;\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/EnumerationIndexes.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/EnumerationIndexes.java
new file mode 100644 (file)
index 0000000..024a7b3
--- /dev/null
@@ -0,0 +1,17 @@
+package org.simantics.sysdyn.representation;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedOrderedSetElements;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn-1.0/EnumerationIndexes")\r
+public class EnumerationIndexes {\r
+       \r
+    @RelatedOrderedSetElements\r
+    private ArrayList<EnumerationIndex> enumerationIndexes = new ArrayList<EnumerationIndex>();\r
+\r
+    public ArrayList<EnumerationIndex> getEnumerationIndexes() {\r
+       return enumerationIndexes;\r
+    }\r
+}\r
index 745fd6ad9658daca52b8701931d03cbafda5c121..3c0888e0193628e6de63a9801b87476736f0ed66 100644 (file)
@@ -37,6 +37,9 @@ public class SysdynSchema extends SimpleSchema {
             addLinkType(MappingSchemas.fromAnnotations(g, Input.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, ModuleType.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, Model.class));\r
+            addLinkType(MappingSchemas.fromAnnotations(g, Enumeration.class));\r
+            addLinkType(MappingSchemas.fromAnnotations(g, EnumerationIndex.class));\r
+            addLinkType(MappingSchemas.fromAnnotations(g, EnumerationIndexes.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, NormalExpression.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, ParameterExpression.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, StockExpression.class));\r
index fe3afd768ec9ddf5355d9d6106647aaf106bd7f0..7a224f9516f9b94ff43ab6c2d852ac06cb30b08e 100644 (file)
@@ -15,6 +15,7 @@ import org.simantics.sysdyn.representation.Auxiliary;
 import org.simantics.sysdyn.representation.Cloud;\r
 import org.simantics.sysdyn.representation.Configuration;\r
 import org.simantics.sysdyn.representation.Dependency;\r
+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.Module;\r
@@ -58,4 +59,8 @@ public class ElementVisitorVoidAdapter implements IElementVisitorVoid {
     @Override\r
     public void visit(Configuration configuration) {\r
     }\r
+    \r
+    @Override\r
+    public void visit(Enumeration enumeration) {\r
+    }\r
 }\r
index d73203427d8d385d82f9996bac2449c8eade4afa..0d560b2b434f32d09b425b65b908118255d41307 100644 (file)
@@ -15,6 +15,7 @@ import org.simantics.sysdyn.representation.Auxiliary;
 import org.simantics.sysdyn.representation.Cloud;\r
 import org.simantics.sysdyn.representation.Configuration;\r
 import org.simantics.sysdyn.representation.Dependency;\r
+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.Module;\r
@@ -32,4 +33,5 @@ public interface IElementVisitorVoid {
     void visit(Flow flow);   \r
     void visit(Module module);\r
     void visit(Configuration configuration);\r
+    void visit(Enumeration enumeration);\r
 }\r