string = sb.toString();\r
}\r
\r
- string = toCamelCase(string);\r
- \r
return string;\r
\r
}\r
string = string.replace("ö", "o");\r
string = string.replace("Ö", "O");\r
string = string.replaceAll("[^a-zA-Z 0-9]+", "");\r
- return toCamelCase(string);\r
- }\r
- \r
- \r
- public static String toCamelCase(String string) {\r
- if(string.length() < 1) {\r
- return string;\r
- }\r
- \r
- try {\r
- String result = new String(string);\r
- BufferedReader br = new BufferedReader(new StringReader(string));\r
- Pattern p = Pattern.compile("[a-zA-Z0-9]+");\r
- Matcher m;\r
- m = p.matcher(br.readLine());\r
- String word;\r
- boolean first = true;\r
- while (m.find()) {\r
- word = m.group();\r
- String replacement;\r
- if(first) {\r
- replacement = word;\r
- first = false;\r
- } else {\r
- replacement = word.substring(0, 1).toUpperCase() + word.substring(1);\r
- }\r
- result = result.replace(word, replacement);\r
- }\r
- return result.replace(" ", "");\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- return string;\r
- }\r
- \r
+ return string;\r
}\r
\r
}\r
\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.Template;\r
-import org.simantics.document.DocumentResource;\r
import org.simantics.layer0.Layer0;\r
-import org.simantics.layer0.utils.direct.GraphUtils;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.operation.Layer0X;\r
import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.utils.datastructures.ArrayMap;\r
+import org.simantics.sysdyn.utils.ModelUtils;\r
\r
public class Model implements IWriteableMDLObject {\r
\r
return;\r
\r
try {\r
+ \r
+ \r
SysdynResource sr = SysdynResource.getInstance(graph);\r
Layer0 l0 = Layer0.getInstance(graph);\r
- Layer0X L0X = Layer0X.getInstance(graph);\r
SimulationResource simu = SimulationResource.getInstance(graph);\r
- DocumentResource DOC = DocumentResource.getInstance(graph);\r
-\r
- // Diagram creation copied from SysdynProject. \r
- // Could the same code be reused? \r
- \r
- Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.1");\r
- Resource layer0 = graph.getResource("http://www.simantics.org/Layer0-1.1");\r
-\r
- Resource model = GraphUtils.create2(\r
- graph,\r
- sr.SysdynModel,\r
- l0.PartOf, parent,\r
- l0.HasName, NameUtils.findFreshName(graph, getName(), parent, l0.ConsistsOf, "%s%d"),\r
- l0.HasLabel, getName(),\r
- sr.SysdynModel_startTime, startTime,\r
- sr.SysdynModel_stopTime, endTime,\r
- l0.IsLinkedTo, sysdyn,\r
- l0.IsLinkedTo, layer0\r
- );\r
\r
+ Resource model = ModelUtils.createModelAt(graph, parent);\r
+ graph.claimLiteral(model, l0.HasLabel, getName());\r
+ graph.claimLiteral(model, sr.SysdynModel_startTime, startTime);\r
+ graph.claimLiteral(model, sr.SysdynModel_stopTime, endTime);\r
+
\r
- Resource conf = GraphUtils.create2(graph,\r
- sr.Configuration,\r
- l0.PartOf, model,\r
- l0.HasName, getName()\r
- );\r
- \r
- Resource diagram = graph.newResource();\r
- graph.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(graph,\r
- ArrayMap\r
- .keys("", "diagram", "name")\r
- .values(conf, diagram, "Diagrammi")\r
- );\r
- \r
+ Resource conf = graph.getSingleObject(model, simu.HasConfiguration);\r
\r
- ModelingResources mr = ModelingResources.getInstance(graph);\r
- // Remove default mapping and add sysdyn mapping\r
- for(Resource trigger : graph.getObjects(diagram, L0X.HasTrigger)) {\r
- if(graph.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) {\r
- graph.deny(diagram, L0X.HasTrigger, trigger);\r
- }\r
- }\r
- Resource mapping = graph.newResource();\r
- graph.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
- graph.claim(diagram, L0X.HasTrigger, mapping);\r
-\r
- graph.claim(model, simu.HasConfiguration, conf);\r
- graph.claim(model, L0X.HasBaseRealization, conf);\r
-\r
- Resource report = GraphUtils.create2(graph, DOC.Report, DOC.HasDocumentation, "===Report===");\r
-\r
- GraphUtils.create2(graph, simu.Experiment,\r
- l0.HasName, "Experiment",\r
- l0.HasLabel, "Experiment",\r
- DOC.HasReportFactory, report,\r
- l0.PartOf, model);\r
-\r
for(Subscript s : subscripts) {\r
s.write(graph, conf, 0, 0);\r
}\r