VP.ChildContribution.HasChildNodeType SBC.BuiltinFunctions\r
VP.ChildContribution.HasRule _ : VP.ConstantChildRule\r
VP.ConstantChildRule.HasChild BuiltinFunctions \r
+ @VP.relationChildRule SBC.BuiltinFunctions L0.ConsistsOf SYSDYN.SysdynModelicaFunctionLibrary \r
+ @VP.relationChildRule SBC.BuiltinFunctions L0.ConsistsOf SYSDYN.SysdynModelicaFunction \r
// Shared functions linked to a model \r
@VP.relationChildRuleWithFolder SBC.FunctionsFolder L0.IsLinkedTo SYSDYN.SharedFunctionOntology \r
SBC.SharedFunctionsFolder : VP.ResourceNodeType\r
org.simantics.diagram;bundle-version="1.1.1",
org.simantics.diagram.ontology;bundle-version="1.1.1",
org.simantics.scl.runtime;bundle-version="0.1.3",
- org.simantics.db.layer0;bundle-version="1.1.0"
+ org.simantics.db.layer0;bundle-version="1.1.0",
+ org.simantics.spreadsheet.common;bundle-version="1.1.0",
+ org.simantics.spreadsheet;bundle-version="1.1.0"
Export-Package: org.simantics.sysdyn,
org.simantics.sysdyn.adapter,
org.simantics.sysdyn.expressionParser,
import java.util.ArrayList;\r
import java.util.HashMap;\r
\r
+import org.simantics.sysdyn.representation.Book;\r
import org.simantics.sysdyn.representation.Configuration;\r
import org.simantics.sysdyn.representation.Dependency;\r
import org.simantics.sysdyn.representation.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
+ Book book = null;\r
\r
// Initialize lists\r
for(IElement element : configuration.getElements()) {\r
} else if(dependency.getTail() instanceof Module){\r
inputDependencies.add(dependency);\r
}\r
+ } else if (element instanceof Book) {\r
+ book = (Book)element;\r
}\r
}\r
\r
b.append(e.getDeclaration());\r
}\r
}\r
+ \r
+ if(book != null) {\r
+ b.append("// Spreadsheet definition\n");\r
+ b.append(book.getBook());\r
+ }\r
\r
boolean initialEquations = false;\r
for(Stock stock : stocks) {\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.simantics.objmap.IMapping;\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedElements;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+@GraphType("http://www.simantics.org/Spreadsheet-1.0/Book")\r
+public class Book implements IElement {\r
+ \r
+ @RelatedElements(\r
+ value = "http://www.simantics.org/Layer0-1.0/ConsistsOf",\r
+ composition = true)\r
+ private ArrayList<Sheet> sheets = new ArrayList<Sheet>();\r
+\r
+ @Override\r
+ public void accept(IElementVisitorVoid v) {\r
+ v.visit(this); \r
+ }\r
+ \r
+ public List<Sheet> getSheets() {\r
+ return sheets;\r
+ }\r
+ \r
+ public String getBook() {\r
+ StringBuilder book = new StringBuilder();\r
+ for(Sheet sheet : sheets)\r
+ book.append(sheet.getCells());\r
+ return book.toString();\r
+ }\r
+\r
+}\r
import org.simantics.objmap.Mappings;\r
\r
public class LoadRepresentation {\r
+ \r
+ public static IMapping loadMappedMapping(Session session, final Resource configuration) throws DatabaseException {\r
+ return session.syncRequest(new Read<IMapping>() {\r
+\r
+ @Override\r
+ public IMapping perform(ReadGraph graph)\r
+ throws DatabaseException {\r
+ SysdynSchema schema = new SysdynSchema(graph);\r
+ IMapping mapping = Mappings.createWithoutListening(schema);\r
+ mapping.map(graph, configuration);\r
+ return mapping;\r
+ }\r
+ \r
+ });\r
+ }\r
\r
public static Configuration loadConfiguration(Session session, final Resource configuration) throws DatabaseException {\r
return session.syncRequest(new Read<Configuration>() {\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import java.util.HashMap;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\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.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
+import org.simantics.objmap.annotations.UpdateMethod;\r
+import org.simantics.spreadsheet.Range;\r
+import org.simantics.spreadsheet.SheetVariables;\r
+import org.simantics.spreadsheet.common.exception.CellParseException;\r
+import org.simantics.spreadsheet.util.SpreadsheetUtils;\r
+\r
+@GraphType("http://www.simantics.org/Spreadsheet-1.0/Spreadsheet")\r
+public class Sheet {\r
+ \r
+ @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName")\r
+ protected String name;\r
+ \r
+ HashMap<String, Object> cells = new HashMap<String, Object>();\r
+\r
+ public String getSheet() {\r
+ return "Sheet";\r
+ }\r
+ \r
+ @UpdateMethod\r
+ public boolean updateCells(ReadGraph g, Resource r) throws DatabaseException {\r
+ System.out.println("updating cells");\r
+ Variable v = g.adapt(r, Variable.class);\r
+ cells.clear();\r
+ for(Variable child : v.browseChildren(g)) {\r
+ String name = child.getPropertyValue(g, Variables.NAME);\r
+ try {\r
+ Range range = SpreadsheetUtils.decodeCellAbsolute(name);\r
+ Variant value = child.getPropertyValue(g, SheetVariables.CONTENT, Bindings.VARIANT);\r
+ cells.put(name, value.getValue());\r
+ } catch (CellParseException e) {\r
+ } catch (MissingVariableException e) {\r
+ System.out.println("missing content for: " + name);\r
+ }\r
+ }\r
+ return true;\r
+ }\r
+ \r
+ public String getCells() {\r
+ StringBuilder clazz = new StringBuilder();\r
+ \r
+ clazz.append(" class " + name + "_class\n ");\r
+ \r
+ int counter = 0;\r
+ for(String key : cells.keySet()) {\r
+ Object value = cells.get(key);\r
+ if(value instanceof Double) {\r
+ Double d = (Double)value;\r
+ clazz.append("constant Real " + key + " = " + d + "; ");\r
+ counter++;\r
+ if(counter > 10) {\r
+ counter = 0;\r
+ clazz.append("\n ");\r
+ }\r
+ }\r
+ }\r
+ clazz.append("\n end " + name + "_class;\n");\r
+ clazz.append(" " + name + "_class " + name + ";\n");\r
+ return clazz.toString();\r
+ }\r
+ \r
+}\r
addLinkType(MappingSchemas.fromAnnotations(g, LookupExpression.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, Redeclaration.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, LibraryDummy.class));\r
+ addLinkType(MappingSchemas.fromAnnotations(g, Book.class));\r
+ addLinkType(MappingSchemas.fromAnnotations(g, Sheet.class));\r
} catch (DatabaseException e) {\r
e.printStackTrace();\r
} catch (InstantiationException e) {\r
\r
\r
public static String rangeToIndexes(Variable variable, String range) {\r
+ if(variable == null)\r
+ return range;\r
StringBuilder sb = new StringBuilder();\r
ArrayIndexes arrayIndexes = variable.getArrayIndexes();\r
if(arrayIndexes == null || range == null)\r
import org.simantics.sysdyn.representation.Input;\r
import org.simantics.sysdyn.representation.LibraryDummy;\r
import org.simantics.sysdyn.representation.Module;\r
+import org.simantics.sysdyn.representation.Book;\r
import org.simantics.sysdyn.representation.Stock;\r
import org.simantics.sysdyn.representation.Valve;\r
\r
@Override\r
public void visit(LibraryDummy libraryDummy) {\r
}\r
+ \r
+ @Override\r
+ public void visit(Book sheet) {\r
+ }\r
}\r
import org.simantics.sysdyn.representation.Input;\r
import org.simantics.sysdyn.representation.LibraryDummy;\r
import org.simantics.sysdyn.representation.Module;\r
+import org.simantics.sysdyn.representation.Book;\r
import org.simantics.sysdyn.representation.Stock;\r
import org.simantics.sysdyn.representation.Valve;\r
\r
void visit(Configuration configuration);\r
void visit(Enumeration enumeration);\r
void visit(LibraryDummy libraryDummy);\r
+ void visit(Book sheet);\r
}\r