]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches/simantics-1.4...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 17 May 2011 13:46:22 +0000 (13:46 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 17 May 2011 13:46:22 +0000 (13:46 +0000)
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewEnumerationNodeHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ModuleOutputEditingSupport.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRow.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java

index 8d3212d828442d3d180efae6d5e3147c702e4e03..49b3f023d3602f176b72d79500f7a1123db3bf2e 100644 (file)
@@ -52,8 +52,7 @@ public class NewEnumerationNodeHandler extends AbstractHandler {
 \r
                Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes);\r
                \r
-               String name = NameUtils.findFreshName(g, "Enumeration", configuration, l0.ConsistsOf, "%s%d");\r
-               if("Enumeration".equals(name)) name = "Enumeration1";\r
+               String name = NameUtils.findFreshName(g, "Enum", configuration, l0.ConsistsOf, "%s%d");\r
                \r
                GraphUtils.create2(g, \r
                                sr.Enumeration,\r
index 67732e3ac74ae7a857ace47e601c6b38834958af..6c289d6638c4145cbdc42088787a82cebf4f7ce6 100644 (file)
@@ -23,6 +23,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.exception.MissingVariableException;\r
 import org.simantics.db.layer0.variable.Variable;\r
 import org.simantics.db.layer0.variable.Variables;\r
 import org.simantics.diagram.stubs.DiagramResource;\r
@@ -71,8 +72,17 @@ public class ShowModuleHandler extends AbstractHandler {
                                        final Resource configuration = graph.getPossibleObject(componentType, st.IsDefinedBy);\r
                                        final Resource diagram = ComponentUtils.getPossibleCompositeDiagram(graph, configuration);\r
 \r
-                                       Variable variable = parent.browsePossible(graph, component);\r
-                                       final String finalRvi = Variables.getRVI(graph, variable);\r
+                                       Variable variable;\r
+                                       String rvi = "";\r
+                                       try {\r
+                                               variable = parent.browse(graph, component);\r
+                                               rvi = Variables.getRVI(graph, variable);\r
+                                       } catch (MissingVariableException e ) {\r
+                                               variable = Variables.getVariable(graph, graph.getURI(component));\r
+                                       }\r
+                                       final String finalRvi = rvi;\r
+                                       \r
+\r
                                        \r
                                        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
 \r
index d8dbd3af21a2b1e946c6a2dce74969a0bab17b4b..7a69d742a0d8cef16c5e2efdec98101bd1c9f6f6 100644 (file)
@@ -71,8 +71,9 @@ public class ModuleOutputEditingSupport  extends EditingSupport {
                             SysdynResource sr = SysdynResource.getInstance(graph);\r
                             HashMap<String, Resource> result = new HashMap<String, Resource>();\r
                             for(Resource dependency : graph.syncRequest(new ObjectsWithType(module, sr.IsTailOf, sr.Dependency))) {\r
-                                if(graph.getPossibleObject(dependency, sr.RefersTo) == null ||\r
-                                        graph.getPossibleObject(dependency, sr.RefersTo).equals(outputVariable)) {\r
+                                if(graph.getPossibleObject(dependency, sr.RefersTo) == null \r
+                                               || !graph.hasStatement(graph.getPossibleObject(dependency, sr.RefersTo), l0.HasName)\r
+                                               || graph.getPossibleObject(dependency, sr.RefersTo).equals(outputVariable)) {\r
                                     Resource input = graph.getSingleObject(dependency, sr.HasHead);\r
                                     result.put((String)graph.getRelatedValue(input, l0.HasName), dependency);\r
                                 }\r
index d3ad27189b538d0911c0de9d316fedc6439b0c47..5aeeaec77acfdefc9ff0b835d3116dcedf91a7f8 100644 (file)
@@ -95,6 +95,8 @@ public class ReferenceRow {
                 SysdynResource sr = SysdynResource.getInstance(graph);\r
                 if(getDependency() != null && graph.hasStatement(getDependency(), sr.RefersTo))\r
                     graph.deny(getDependency(), sr.RefersTo);\r
+                if(dependency != null && graph.hasStatement(dependency, sr.RefersTo))\r
+                       graph.deny(dependency, sr.RefersTo);\r
                 setDependency(null);\r
                 if(dependency != null) {\r
                     setDependency(dependency);\r
index bd4629532745bf62144434af94bed615a137a04b..d88a02a50f5af3c53d57eb84f6e4bb462a92515b 100644 (file)
@@ -141,7 +141,7 @@ public class ModelicaWriter {
             Input variable = (Input)dependency.getHead();\r
             Module module = (Module)dependency.getTail();\r
             Variable reference = (Variable)dependency.refersTo();\r
-            if(reference != null)\r
+            if(reference != null && reference.getName() != null)\r
                b.append("    " + variable.getName() + " = " + module.getName() + "." + reference.getName() + ";\n");\r
             else\r
                b.append("    " + variable.getName() + " = " + variable.getDefaultInputValue() + ";\n");\r
index d04bc24041924c55caf9f63f00f4d90c2f4f3e8b..941e0632a49d7d82d6843b4bd5107714842ba560 100644 (file)
@@ -51,28 +51,43 @@ public class Module implements IElement {
     \r
     /**\r
      * Returns the declaration of a module with possible redeclared enumerations\r
+     *     \r
+     * parameter Integer Enum__size = Enum.size;\r
+     * parameter Integer Enum__elements[:] = Enum.elements;\r
+     * ModuleType ModuleType1(Enum.size = Enum__size, Enum.elements = Enum__elements);\r
      * \r
-     * Module m(redeclared.size = enumeration.size, redeclared.elements = enumeration.elements);\r
+     * Temporary parameter variables are needed to avoid name conflicts when redeclaring an \r
+     * enumeration with the same name.\r
      * \r
      * @return Declaration of a module instance\r
      */\r
     public String getDeclaration() {\r
-       StringBuilder sb = new StringBuilder();\r
-       sb.append("    ");\r
-       sb.append(getType().getName());\r
-       sb.append(" ");\r
-       sb.append(getName());\r
+       \r
+       StringBuilder parameters = new StringBuilder();\r
+       StringBuilder redeclarations = new StringBuilder();\r
+       \r
+       \r
        if(!getRedeclarations().isEmpty()) {\r
-               sb.append("(");\r
+               redeclarations.append("(");\r
                Iterator<Redeclaration> i = getRedeclarations().iterator();\r
                while(i.hasNext()) {\r
                        Redeclaration rd = i.next();\r
-                       sb.append(rd.getRedeclaration());\r
+                       redeclarations.append(rd.getRedeclaration());\r
+                       parameters.append(rd.getParameters());\r
                        if(i.hasNext())\r
-                               sb.append(",");\r
+                               redeclarations.append(",");\r
                }\r
-               sb.append(")");\r
+               redeclarations.append(")");\r
        }\r
+       \r
+       \r
+       StringBuilder sb = new StringBuilder();\r
+       sb.append(parameters);\r
+       sb.append("    ");\r
+       sb.append(getType().getName());\r
+       sb.append(" ");\r
+       sb.append(getName());\r
+       sb.append(redeclarations.toString());\r
        sb.append(";\n");\r
        return sb.toString();\r
     }\r
index b048bbdbcb344c27189613f98eb0a6f853e6d6cd..cdf33978734847316c43177899117852b0aa29e5 100644 (file)
@@ -27,18 +27,60 @@ public class Redeclaration {
        if(replacedEnumeration == null || replacingEnumeration == null) {\r
                return "";\r
        }\r
+       String separator = getSeparator();\r
        StringBuilder sb = new StringBuilder();\r
        sb.append(replacedEnumeration.getName());\r
        sb.append(".size = ");\r
        sb.append(replacingEnumeration.getName());\r
-       sb.append(".size, ");\r
+       sb.append(separator + "size, ");\r
        sb.append(replacedEnumeration.getName());\r
        sb.append(".elements = ");\r
        sb.append(replacingEnumeration.getName());\r
-       sb.append(".elements");\r
+       sb.append(separator + "elements");\r
        \r
        return sb.toString();\r
     }\r
+    \r
+    /**\r
+     * Change the name of the re-declaration parameters to enable the use of \r
+     * enumerations with same names.\r
+     * \r
+     * @return\r
+     */\r
+    public String getParameters() {\r
+       String separator = getSeparator();\r
+       StringBuilder sb = new StringBuilder();\r
+       sb.append("    parameter Integer " + replacingEnumeration.getName() + separator + "size = " + replacingEnumeration.getName() + ".size;\n");\r
+       sb.append("    parameter Integer " + replacingEnumeration.getName() + separator + "elements[:] = " + replacingEnumeration.getName() + ".elements;\n");\r
+       return sb.toString();\r
+    }\r
+    \r
+    private String getSeparator() {\r
+       return getSeparator(this, "_");\r
+    }\r
+\r
+    /**\r
+     * Add enough separation marks that name conflicts would not exist.\r
+     * \r
+     * @param redeclaration\r
+     * @param separator\r
+     * @return\r
+     */\r
+    private String getSeparator(Redeclaration redeclaration, String separator) {\r
+       for(IElement e : redeclaration.replacedEnumeration.getParentConfiguration().getElements()) {\r
+               if(e instanceof Module) {\r
+                       for(Redeclaration rd : ((Module)e).getRedeclarations()) {\r
+                               if(rd.replacedEnumeration.name.equals(redeclaration.replacedEnumeration.name) &&\r
+                                               rd.replacingEnumeration.equals(redeclaration.replacedEnumeration)) {\r
+                                       String separatorTmp = getSeparator(rd, separator);\r
+                                       if(separatorTmp.length() > separator.length())\r
+                                               separator = separatorTmp;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       return separator + "_";\r
+    }\r
 \r
        public Enumeration getReplacedEnumeration() {\r
                return replacedEnumeration;\r