\r
@Override\r
public String getLabel(ReadGraph graph, ConfigurationNode conf) throws DatabaseException {\r
- String name = graph.getPossibleRelatedValue(conf.resource, graph.getBuiltins().HasName);\r
+ String name = graph.getPossibleRelatedValue(conf.resource, graph.getBuiltins().HasLabel);\r
return name == null ? "Project (no name)" : name;\r
}\r
\r
Builtins b = graph.getBuiltins();\r
Resource resource = module.resource;\r
StringBuilder sb = new StringBuilder();\r
+ for(Resource r : graph.getObjects(resource, b.HasLabel))\r
+ sb.append(graph.getValue(r));\r
+ sb.append(" : ");\r
for(Resource r : graph.getObjects(resource, b.HasName))\r
sb.append(graph.getValue(r));\r
sb.append(" : ");\r
public final Resource HasStartTime;\r
public final Resource HasStopTime;\r
public final Resource HasTail;\r
- public final Resource HasTerminal;\r
public final Resource HasUnit;\r
public final Resource HasX;\r
public final Resource HasY;\r
public final Resource IndependentVariable;\r
- public final Resource Input;\r
public final Resource IsHeadOf;\r
public final Resource IsHeadOfTerminal;\r
+ public final Resource IsReferredBy;\r
public final Resource IsTailOf;\r
public final Resource IsTailOfTerminal;\r
public final Resource LookupExpression;\r
public final Resource SysdynModelManager;\r
public final Resource SysdynProject;\r
public final Resource SysdynTerminal;\r
- public final Resource Terminal;\r
public final Resource Valve;\r
public final Resource ValveSymbol;\r
public final Resource Variable;\r
public static final String HasStartTime = "http://www.simantics.org/Sysdyn-1.0/HasStartTime";\r
public static final String HasStopTime = "http://www.simantics.org/Sysdyn-1.0/HasStopTime";\r
public static final String HasTail = "http://www.simantics.org/Sysdyn-1.0/HasTail";\r
- public static final String HasTerminal = "http://www.simantics.org/Sysdyn-1.0/HasTerminal";\r
public static final String HasUnit = "http://www.simantics.org/Sysdyn-1.0/HasUnit";\r
public static final String HasX = "http://www.simantics.org/Sysdyn-1.0/HasX";\r
public static final String HasY = "http://www.simantics.org/Sysdyn-1.0/HasY";\r
public static final String IndependentVariable = "http://www.simantics.org/Sysdyn-1.0/IndependentVariable";\r
- public static final String Input = "http://www.simantics.org/Sysdyn-1.0/Input";\r
public static final String IsHeadOf = "http://www.simantics.org/Sysdyn-1.0/IsHeadOf";\r
public static final String IsHeadOfTerminal = "http://www.simantics.org/Sysdyn-1.0/IsHeadOfTerminal";\r
+ public static final String IsReferredBy = "http://www.simantics.org/Sysdyn-1.0/IsReferredBy";\r
public static final String IsTailOf = "http://www.simantics.org/Sysdyn-1.0/IsTailOf";\r
public static final String IsTailOfTerminal = "http://www.simantics.org/Sysdyn-1.0/IsTailOfTerminal";\r
public static final String LookupExpression = "http://www.simantics.org/Sysdyn-1.0/LookupExpression";\r
public static final String SysdynModelManager = "http://www.simantics.org/Sysdyn-1.0/SysdynModelManager";\r
public static final String SysdynProject = "http://www.simantics.org/Sysdyn-1.0/SysdynProject";\r
public static final String SysdynTerminal = "http://www.simantics.org/Sysdyn-1.0/SysdynTerminal";\r
- public static final String Terminal = "http://www.simantics.org/Sysdyn-1.0/Terminal";\r
public static final String Valve = "http://www.simantics.org/Sysdyn-1.0/Valve";\r
public static final String ValveSymbol = "http://www.simantics.org/Sysdyn-1.0/ValveSymbol";\r
public static final String Variable = "http://www.simantics.org/Sysdyn-1.0/Variable";\r
HasStartTime = getResourceOrNull(graph, URIs.HasStartTime);\r
HasStopTime = getResourceOrNull(graph, URIs.HasStopTime);\r
HasTail = getResourceOrNull(graph, URIs.HasTail);\r
- HasTerminal = getResourceOrNull(graph, URIs.HasTerminal);\r
HasUnit = getResourceOrNull(graph, URIs.HasUnit);\r
HasX = getResourceOrNull(graph, URIs.HasX);\r
HasY = getResourceOrNull(graph, URIs.HasY);\r
IndependentVariable = getResourceOrNull(graph, URIs.IndependentVariable);\r
- Input = getResourceOrNull(graph, URIs.Input);\r
IsHeadOf = getResourceOrNull(graph, URIs.IsHeadOf);\r
IsHeadOfTerminal = getResourceOrNull(graph, URIs.IsHeadOfTerminal);\r
+ IsReferredBy = getResourceOrNull(graph, URIs.IsReferredBy);\r
IsTailOf = getResourceOrNull(graph, URIs.IsTailOf);\r
IsTailOfTerminal = getResourceOrNull(graph, URIs.IsTailOfTerminal);\r
LookupExpression = getResourceOrNull(graph, URIs.LookupExpression);\r
SysdynModelManager = getResourceOrNull(graph, URIs.SysdynModelManager);\r
SysdynProject = getResourceOrNull(graph, URIs.SysdynProject);\r
SysdynTerminal = getResourceOrNull(graph, URIs.SysdynTerminal);\r
- Terminal = getResourceOrNull(graph, URIs.Terminal);\r
Valve = getResourceOrNull(graph, URIs.Valve);\r
ValveSymbol = getResourceOrNull(graph, URIs.ValveSymbol);\r
Variable = getResourceOrNull(graph, URIs.Variable);\r
public void write(Configuration conf) {\r
\r
writeModule(conf);\r
- \r
+\r
if(insertInterpolate)\r
b.append(\r
"\nfunction Interpolate\n" +\r
" end for;\n" +\r
" end Interpolate;\n");\r
}\r
- \r
+\r
private void writeModule(IModule module) {\r
- \r
+\r
module.update();\r
- \r
- ArrayList<IElement> variables = new ArrayList<IElement>();\r
+\r
+ ArrayList<Variable> variables = new ArrayList<Variable>();\r
ArrayList<Module> modules = new ArrayList<Module>();\r
- ArrayList<IElement> stocks = new ArrayList<IElement>();\r
+ ArrayList<Stock> stocks = new ArrayList<Stock>();\r
\r
// Initialize lists\r
for(IElement element : module.getElements()) {\r
if(element instanceof Variable) {\r
- variables.add(element);\r
+ variables.add((Variable)element);\r
if(element instanceof Stock)\r
- stocks.add(element);\r
+ stocks.add((Stock)element);\r
} else if (element instanceof Module) {\r
modules.add((Module)element);\r
}\r
\r
\r
b.append("class ").append(module.getName().replace(" ", "")).append('\n');\r
- for(IElement element : variables) {\r
- IExpression expr = ((Variable)element).expression;\r
+ \r
+ b.append("// Variable definitions\n");\r
+ for(Variable variable : variables) {\r
+ IExpression expr = (variable).getExpression();\r
if(expr != null && insertInterpolate == false) {\r
- app = expr.getDeclaration((Variable)element);\r
+ app = expr.getDeclaration(variable);\r
if (app != null) b.append(app);\r
if (expr instanceof WithLookupExpression) insertInterpolate = true;\r
}\r
}\r
+ \r
+ if(!modules.isEmpty()) {\r
+ b.append("// Module definitions\n");\r
+ for(Module m : modules) {\r
+ b.append(" " + m.getName() + " " + m.getLabel() + ";\n");\r
+ }\r
+ }\r
\r
- for(IElement element : stocks) {\r
- IExpression expr = ((Stock)element).expression;\r
+ for(Stock stock : stocks) {\r
+ IExpression expr = stock.getExpression();\r
if(expr != null) {\r
- app = expr.getInitialEquation((Stock)element);\r
+ app = expr.getInitialEquation(stock);\r
if (app != null) {\r
if(initialEquations == false) {\r
initialEquations = true;\r
+ b.append("// Initial Equations\n");\r
b.append("initial equation\n");\r
}\r
b.append(app);\r
}\r
}\r
}\r
- \r
+\r
b.append("equation\n");\r
- for(IElement element : variables) {\r
- IExpression expr = ((Variable)element).expression;\r
- if(expr != null) {\r
- app = expr.getEquation((Variable)element);\r
- if (app != null) b.append(app);\r
+\r
+ b.append("// Equations\n");\r
+ for(Variable variable : variables) {\r
+ if(variable.getRefersTo() != null) continue;\r
+ IExpression expr = variable.getExpression();\r
+ if(expr != null) {\r
+ app = expr.getEquation(variable);\r
+ if (app != null) b.append(app);\r
+ }\r
+ }\r
+\r
+\r
+ b.append("// Inputs\n");\r
+ for(Variable variable : variables) {\r
+ Variable reference = variable.getRefersTo();\r
+ if(reference == null) continue;\r
+ if(variable.getParentModule().getElements().contains(reference.getParentModule())) {\r
+ b.append(" " + variable.getName() +\r
+ " = " + reference.getParentModule().getLabel() + "." + reference.getName() + ";\n");\r
+ }\r
+ }\r
+\r
+ b.append("// Outputs\n");\r
+ for(Variable variable : variables) {\r
+ ArrayList<Variable> isReferredBy = variable.getIsReferredBy();\r
+ for(Variable var : isReferredBy) {\r
+ if(variable.getParentModule().getElements().contains(var.getParentModule())) {\r
+ b.append(" " + var.getParentModule().getLabel() + "." + var.getName() +\r
+ " = " + variable.getName() + ";\n");\r
}\r
}\r
+ }\r
+\r
b.append("end ").append(module.getName().replace(" ", "")).append(";\n\n");\r
- \r
- \r
+\r
+\r
for(Module m : modules) {\r
writeModule(m);\r
}\r
}\r
- \r
+\r
public String escape(String name) {\r
return name.replace(' ', '_');\r
}\r
@RelatedValue("http://www.simantics.org/Layer0-1.0/HasName")\r
private String name;\r
\r
+ @RelatedValue("http://www.simantics.org/Layer0-1.0/HasLabel")\r
+ private String label;\r
+ \r
@RelatedElements(\r
value = "http://www.simantics.org/Layer0-1.0/ConsistsOf",\r
composition = true)\r
public String getName() {\r
return name;\r
}\r
+\r
+ @Override\r
+ public String getLabel() {\r
+ return label;\r
+ }\r
\r
\r
}\r
public interface IModule {\r
\r
public ArrayList<IElement> getElements(); \r
- public String getName(); \r
+ public String getName();\r
+ public String getLabel(); \r
public void update();\r
\r
}\r
\r
@RelatedValue("http://www.simantics.org/Layer0-1.0/HasName")\r
private String name;\r
+ \r
+ @RelatedValue("http://www.simantics.org/Layer0-1.0/HasLabel")\r
+ private String label;\r
\r
@RelatedElements(\r
value = "http://www.simantics.org/Layer0-1.0/ConsistsOf",\r
public String getName() {\r
return name;\r
}\r
+\r
+\r
+ @Override\r
+ public String getLabel() {\r
+ return label;\r
+ }\r
}\r
*******************************************************************************/\r
package org.simantics.sysdyn.representation;\r
\r
+import java.util.ArrayList;\r
+\r
import org.simantics.objmap.annotations.RelatedElement;\r
+import org.simantics.objmap.annotations.RelatedElements;\r
import org.simantics.objmap.annotations.RelatedValue;\r
import org.simantics.sysdyn.representation.expressions.IExpression;\r
\r
@RelatedValue("http://www.simantics.org/Layer0-1.0/HasType")\r
protected String type;\r
@RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasExpression")\r
- public IExpression expression;\r
+ protected IExpression expression;\r
+ @RelatedElement("http://www.simantics.org/Sysdyn-1.0/RefersTo")\r
+ protected Variable refersTo;\r
+ @RelatedElements(\r
+ value = "http://www.simantics.org/Sysdyn-1.0/IsReferredBy",\r
+ composition = true)\r
+ private ArrayList<Variable> isReferredBy = new ArrayList<Variable>();\r
+ @RelatedElement("http://www.simantics.org/Layer0-1.0/PartOf")\r
+ protected IModule module;\r
+\r
+ \r
\r
public String getName() {\r
return this.name;\r
public String getType() {\r
return this.type;\r
}\r
+ \r
+ public IExpression getExpression() {\r
+ return this.expression;\r
+ }\r
+ \r
+ public Variable getRefersTo() {\r
+ return this.refersTo;\r
+ }\r
+ \r
+ public ArrayList<Variable> getIsReferredBy() {\r
+ return this.isReferredBy;\r
+ }\r
+ \r
+ public IModule getParentModule() {\r
+ return this.module;\r
+ }\r
}\r
\r
@Override\r
public String getDeclaration(Variable variable) {\r
- return " constant " + variable.getType() + " " + variable.getName() + " = " + equation + ";\n";\r
- }\r
+ StringBuilder b = new StringBuilder();\r
+ b.append(" constant " + variable.getType() + " " + variable.getName());\r
+ if(variable.getRefersTo() == null)\r
+ b.append(" = " + equation);\r
+ b.append(";\n");\r
+ return b.toString(); }\r
\r
}\r
\r
@Override\r
public String getDeclaration(Variable variable) {\r
- return " parameter " + variable.getType() + " " + variable.getName() + " = " + equation + ";\n";\r
+ StringBuilder b = new StringBuilder();\r
+ b.append(" parameter " + variable.getType() + " " + variable.getName());\r
+ if(variable.getRefersTo() == null)\r
+ b.append(" = " + equation);\r
+ b.append(";\n");\r
+ return b.toString();\r
}\r
}\r
L0.HasRange L0.Double\r
HasExpression <R L0.IsRelatedTo : L0.FunctionalRelation\r
L0.HasRange Expression\r
- \r
-#HasType <R L0.HasProperty : L0.FunctionalRelation\r
-# L0.HasRange L0.String\r
+\r
\r
HasUnit <R L0.HasProperty\r
L0.HasRange L0.String\r
[HasRangeEnd card "0..1"]\r
[HasRangeStep card "0..1"]\r
[L0.HasDescription card "0..1"]\r
+ [RefersTo card "0..1"]\r
\r
\r
Auxiliary <T IndependentVariable\r
L0.HasObject "Real" : L0.String\r
\r
Cloud <T Variable\r
- \r
-Input <T Variable\r
- [RefersTo card "0..1"]\r
- \r
-Terminal <T Input\r
\r
######################################################################\r
# Modules\r
\r
Module <T ST.Composite\r
[L0.ConsistsOf all (Variable or Dependency or Module)]\r
+ [L0.HasLabel card "1"]\r
[HasInput]\r
[HasOutput]\r
\r
[HasHead card "1"]\r
[HasTail card "1"]\r
\r
-RefersTo <R L0.IsRelatedTo\r
+RefersTo <R L0.IsRelatedTo : L0.FunctionalRelation\r
+ L0.InverseOf IsReferredBy\r
L0.HasDomain [IndependentVariable]\r
L0.HasRange [IndependentVariable]\r
\r
-HasTerminal <R L0.IsRelatedTo\r
- L0.HasRange [Terminal]\r
-\r
+IsReferredBy <R L0.IsRelatedTo\r
\r
######################################################################\r
# Expression\r
\r
\r
ModuleConfiguration @ "ModuleConfiguration" : Configuration\r
+ L0.HasLabel "Mallikonfiguraatio" : L0.String\r
HasStartTime "0.0" : L0.Double\r
HasStopTime "10.0" : L0.Double\r
L0.ConsistsOf\r
Module1\r
+ L0.HasLabel "EkaModuuli" : L0.String\r
RootAux1 @ "Aux1" : Auxiliary\r
L0.HasType "Real" : L0.String\r
HasUnit "m" : L0.String\r
FirstModuleInput1 @ "Aux1" : Auxiliary\r
L0.HasType "Real" : L0.String\r
HasUnit "s" : L0.String\r
- HasExpression _ : ParameterExpression\r
+ HasExpression _ : NormalExpression\r
HasEquation "2+2" : L0.String\r
RefersTo RootAux2\r
FirstModuleInput2 @ "Aux2" : Auxiliary\r
L0.HasType "Real" : L0.String\r
HasUnit "s" : L0.String\r
- HasExpression _ : ParameterExpression\r
+ HasExpression _ : NormalExpression\r
HasEquation "2+2" : L0.String\r
+ RefersTo RootAux2\r
FirstModuleStock @ "Stock1" : Stock\r
HasExpression _ : StockExpression\r
HasInitialEquation "0" : L0.String\r
FirstModuleCloud : Cloud\r
FirstModuleOutput1 @ "Valve" : Valve\r
HasUnit "s" : L0.String\r
- HasExpression _ : ParameterExpression\r
+ HasExpression _ : NormalExpression\r
HasEquation "Aux1 + Aux2" : L0.String \r
_ : Flow\r
HasHead FirstModuleOutput1\r