\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
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
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
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
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
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
\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
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