]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Editor name fixed to show "module name : module type name" instead of "module name...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 16 May 2012 12:40:22 +0000 (12:40 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 16 May 2012 12:40:22 +0000 (12:40 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@24990 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromConfigurationAdapter.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorInput.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RangeComposite.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java

index 433a3b36d047a3e4c63989ec142099c3c59013db..d5a155cff3e490b4e70c81ed01e2bde6552ca45a 100644 (file)
@@ -18,7 +18,6 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.ResourceArray;\r
 import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.layer0.Layer0;\r
 import org.simantics.modeling.ComponentUtils;\r
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.modeling.ui.Activator;\r
index 67b642d2bbdcb2c803c2df315d61035c065b37b1..ee100d49af55a5847f00385d5fd54b7363511cad 100644 (file)
@@ -17,7 +17,6 @@ import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;\r
 import org.simantics.db.service.LifecycleSupport;\r
 import org.simantics.db.service.SerialisationSupport;\r
-import org.simantics.layer0.Layer0;\r
 import org.simantics.operation.Layer0X;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.icons.ImageDescriptorProvider;\r
@@ -379,7 +378,6 @@ public class SysdynEditorInput extends ResourceEditorInput2 {
         if (!exists)\r
             throw new Nonexistant();\r
 \r
-        Layer0 L0 = Layer0.getInstance(g);\r
         // 2. Validate modelURI\r
         if (getModelURI() != null) {\r
             Layer0X L0X = Layer0X.getInstance(g);\r
index abb9f0b802a23ae6ce1f174dd8be21e3ecfd412f..f47c890cb3bdc339577f0edc705f127e9739fbc6 100644 (file)
@@ -18,6 +18,8 @@ import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.variable.Variable;\r
 import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ModelingResources;\r
 import org.simantics.modeling.ui.features.EditorNamingService2;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.ui.workbench.IResourceEditorInput2;\r
@@ -31,32 +33,39 @@ import org.simantics.ui.workbench.IResourceEditorInput2;
  *\r
  */\r
 public class SysdynEditorNamingService extends EditorNamingService2 {\r
-       \r
-    @Override\r
-    public String getName(ReadGraph g, String editorId, IEditorInput in) throws DatabaseException {\r
-        if(in instanceof IResourceEditorInput2) {\r
-                IResourceEditorInput2 input = (IResourceEditorInput2) in;\r
-                \r
 \r
-                if(!input.getRVI().isEmpty()) {\r
-                 Resource model = g.getPossibleResource(input.getModelURI());\r
-                        if(model != null) {\r
-                                Resource configuration = g.getPossibleObject(model, SimulationResource.getInstance(g).HasConfiguration);\r
-                                String configurationName = NameUtils.getSafeName(g, configuration);\r
-                        String uri = input.getModelURI() + "/" + configurationName + input.getRVI();\r
-                        Variable v = Variables.getPossibleVariable(g, uri);\r
-                        if(v != null) {\r
-                                String name = input.getRVI();\r
-                                if(name.contains("/"))\r
-                                        name = name.substring(name.lastIndexOf("/") + 1);\r
-                                \r
-                                String instanceOf = super.getName(g, editorId, in);\r
-                                return name + " : " + instanceOf;\r
-                        }\r
-                        }\r
-                } \r
-        }\r
-        return super.getName(g, editorId, in);\r
-    }\r
+       @Override\r
+       public String getName(ReadGraph g, String editorId, IEditorInput in) throws DatabaseException {\r
+               if(in instanceof IResourceEditorInput2) {\r
+                       IResourceEditorInput2 input = (IResourceEditorInput2) in;\r
+\r
+                       if(!input.getRVI().isEmpty()) {\r
+                               Resource model = g.getPossibleResource(input.getModelURI());\r
+                               if(model != null) {\r
+                                       Resource configuration = g.getPossibleObject(model, SimulationResource.getInstance(g).HasConfiguration);\r
+                                       String configurationName = NameUtils.getSafeName(g, configuration);\r
+                                       String uri = input.getModelURI() + "/" + configurationName + input.getRVI();\r
+                                       Variable v = Variables.getPossibleVariable(g, uri);\r
+                                       if(v != null) {\r
+                                               String name = input.getRVI();\r
+                                               if(name.contains("/"))\r
+                                                       name = name.substring(name.lastIndexOf("/") + 1);\r
+\r
+                                               Resource instanceOf = g.getPossibleObject(v.getRepresents(g), Layer0.getInstance(g).InstanceOf);\r
+                                               return name + " : " + NameUtils.getSafeName(g, instanceOf);\r
+                                       }\r
+                               }\r
+                       } else {\r
+                               ModelingResources mr = ModelingResources.getInstance(g);\r
+                               Resource conf = g.getPossibleObject(input.getResource(), mr.DiagramToComposite);\r
+                               if(conf != null) {\r
+                                       Resource module = g.getPossibleObject(conf, Layer0.getInstance(g).PartOf);\r
+                                       if(module != null) \r
+                                               return NameUtils.getSafeName(g, module);\r
+                               }\r
+                       }\r
+               }\r
+               return super.getName(g, editorId, in);\r
+       }\r
 \r
 }\r
index e7284fc1db298ee0a8ddec1eb49b0c7037546370..7ccce0297e21e4e2f1786ee9aeb34dc08c12e79c 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.trend.chart.properties;\r
 \r
+import java.util.HashMap;\r
 import java.util.Iterator;\r
 import java.util.LinkedHashMap;\r
 import java.util.List;\r
@@ -43,6 +44,7 @@ import org.simantics.db.layer0.variable.Variables;
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.db.procedure.Listener;\r
 import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.JFreeChartResource;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.trend.chart.ChartUtils;\r
@@ -97,6 +99,27 @@ public class RangeComposite extends Composite implements Widget {
                     Variable v = Variables.getVariable(graph, realizationURI + rvi.trim());\r
                     if(v == null)\r
                         return null;\r
+                    \r
+                    // Find all enumeration replacements in the variable's path\r
+                    HashMap<Resource, Resource> redeclarations = new HashMap<Resource, Resource>();\r
+                    Variable parent = v;\r
+                    while((parent = parent.getParent(graph)) != null) {\r
+                       Resource represents = parent.getRepresents(graph);\r
+                       Resource type = graph.getSingleObject(represents, Layer0.getInstance(graph).InstanceOf);\r
+                       if(!graph.isInheritedFrom(type, sr.Module))\r
+                               break;\r
+                       \r
+                       for(Resource redeclaration : graph.getObjects(represents, sr.Module_redeclaration)) {\r
+                               redeclarations.put(\r
+                                               graph.getPossibleObject(redeclaration, sr.Redeclaration_replacedEnumeration), \r
+                                               graph.getPossibleObject(redeclaration, sr.Redeclaration_replacingEnumeration)\r
+                                               );\r
+                       }\r
+                    }\r
+                    \r
+                    \r
+                    \r
+                    \r
                     Resource variable = v.getRepresents(graph);\r
                     \r
                     // Return the enumerations assigned to that variable\r
@@ -104,8 +127,14 @@ public class RangeComposite extends Composite implements Widget {
                     if(arrayIndexes != null) {\r
                         LinkedHashMap<String, Resource> result = new LinkedHashMap<String, Resource>();\r
                         for(Resource enumeration : OrderedSetUtils.toList(graph, arrayIndexes)) {\r
-                            String enumerationName = NameUtils.getSafeName(graph, enumeration);\r
-                            result.put(enumerationName, enumeration);\r
+                               \r
+                               // Find possible redeclarations for enumeration\r
+                               Resource redeclaration = enumeration;\r
+                               while(redeclarations.get(redeclaration) != null)\r
+                                       redeclaration = redeclarations.get(redeclaration);\r
+                               \r
+                            String enumerationName = NameUtils.getSafeName(graph, redeclaration);\r
+                            result.put(enumerationName, redeclaration);\r
                         }\r
                         return result;\r
                     }\r
index d0acb0858a746611b97def40d6e8db92ba4454b1..6773376db00cc59cd52e50efdc29128113c8ca65 100644 (file)
@@ -83,7 +83,9 @@ public class ExpressionUtils {
      * @param configuration configuration where the variable is located\r
      */\r
     static public void validateExpressionFields(final Resource variable, IExpression expression, Table variableTable) {\r
-\r
+       if(variable == null || expression == null || variableTable == null)\r
+               return;\r
+       \r
         Resource configuration = null;\r
         try {\r
             configuration = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
index f9c9da3307b149d7bfb94db5df062f8999a8f20e..be625aa33ac9f838d5a2354c6718ef12009fa041 100644 (file)
@@ -209,9 +209,6 @@ public class SysdynGameExperiment extends SysdynExperiment {
                \r
                \r
                try {\r
-                       long t = System.currentTimeMillis();\r
-                       long oldT;\r
-                       \r
                        control.setStepLength(stepLength); // Set step length each time in case there has been changes\r
 \r
                        double time = control.getTime();\r
@@ -220,41 +217,18 @@ public class SysdynGameExperiment extends SysdynExperiment {
 \r
                        while(control.getTime() < (eTime - 1e-9)) { // Substract a very small number, because OpenModelica is not very precise with its Real numbers\r
                                \r
-                               oldT = t;\r
-                               t = System.currentTimeMillis();\r
-                               System.out.println("step start ----------------------------------------- ");\r
-                               \r
                                control.simulateStep();\r
                                \r
-                               System.out.println("simulate step \t\t " + (System.currentTimeMillis() - oldT));\r
-\r
-\r
                                results = control.getSubscribedResults(results);\r
 \r
-                               System.out.println("results\t\t\t " + (System.currentTimeMillis() - oldT));\r
-                               \r
                                for(int k = 0; k < subscription.length; k++) {\r
                                        this.results.get(subscription[k]).add(results[k]);\r
                                }\r
-                               \r
-                               oldT = t;\r
-                               t = System.currentTimeMillis();                         \r
-                               System.out.println("step complete\t " + (t - oldT));\r
                        }\r
                        \r
-                       oldT = t;\r
-                       t = System.currentTimeMillis();\r
-                       System.out.println("results ready ------------------------------- ");\r
-                       \r
-                       \r
                        sysdynModel.getSysdynResult().setResult(new GameResult(this.results, this.subscription));\r
                        sysdynModel.resultChanged();\r
                        \r
-                       oldT = t;\r
-                       t = System.currentTimeMillis();\r
-                       System.out.println("results changed\t " + (t - oldT));\r
-                       \r
-\r
                } catch (FMUJNIException e) {\r
                        System.err.println("SysdynGameExperiment simulateDuration failed: \n\t" + e.getMessage());\r
                }\r