public static File getModelicaHome() {\r
\r
String dir = System.getenv("OPENMODELICAHOME");\r
+ File omhome = null;\r
\r
String osName = System.getProperty("os.name");\r
OSType os = calculateOS();\r
\r
if (os == OSType.UNKNOWN)\r
throw new UnsatisfiedLinkError("unknown OS '" + osName + "' for running OpenModelica");\r
+ \r
+ // If OPENMODELICAHOME is found, try to return the folder.\r
+ if(dir != null) {\r
+ switch (os) {\r
+ case APPLE:\r
+ case LINUX:\r
+ case SUN:\r
+ omhome = new File(dir);\r
+ if(omhome.isDirectory())\r
+ return omhome;\r
+ else\r
+ break;\r
+ case WINDOWS:\r
+ omhome = new File(dir);\r
+ if(omhome.isDirectory())\r
+ return omhome;\r
+ else\r
+ break;\r
+ }\r
+ }\r
\r
- // Teemu's stuff, testing openmodelica in a plugin\r
- if(dir == null && os.equals(OSType.WINDOWS)) {\r
+ // OPENMODELICAHOMe was not found or the folder does not exist. Try built-in OpenModelica for windows\r
+ if(os.equals(OSType.WINDOWS)) {\r
\r
Bundle bundle = Platform.getBundle("org.simantics.openmodelica.win32");\r
if (bundle != null) {\r
}\r
}\r
\r
- // Back to normal\r
-\r
- if(dir == null) {\r
- switch (os) {\r
- case APPLE:\r
- case LINUX:\r
- case SUN:\r
- return new File("/usr/bin/omc");\r
- case WINDOWS:\r
- return new File("c:/OpenModelica1.7.0");\r
- default:\r
- throw new UnsatisfiedLinkError("Unsupported operating system: " + os);\r
- }\r
- } else {\r
- switch (os) {\r
- case APPLE:\r
- case LINUX:\r
- case SUN:\r
- return new File(dir);\r
- case WINDOWS:\r
- return new File(dir);\r
- default:\r
- throw new UnsatisfiedLinkError("Unsupported operating system: " + os);\r
- }\r
+ // OS was not windows or built-in OpenModelica did not work\r
+ switch (os) {\r
+ case APPLE:\r
+ case LINUX:\r
+ case SUN:\r
+ return new File("/usr/bin/omc");\r
+ case WINDOWS:\r
+ return new File("c:/OpenModelica1.7.0");\r
+ default:\r
+ throw new UnsatisfiedLinkError("Unsupported operating system: " + os);\r
}\r
}\r
\r
DIA.HasSymbolContribution _ : DIA.BasicSymbolContribution
DIA.BasicSymbolContributionHasSymbolLibrary
BasicSymbols
+
+SYSDYN.ConfigurationDiagramTemplate : MOD.DiagramTemplate
+ MOD.HasDiagramType SYSDYN.ConfigurationDiagram
SYSDYN.SysdynDiagramModelingRules : MOD.MappedModelingRules
MOD.HasBaseRules STR.StandardModelingRules
public final Resource CloudSymbol;\r
public final Resource Configuration;\r
public final Resource ConfigurationDiagram;\r
+ public final Resource ConfigurationDiagramTemplate;\r
public final Resource ConstantExpression;\r
public final Resource DefaultRealization;\r
public final Resource DelayExpression;\r
public static final String CloudSymbol = "http://www.simantics.org/Sysdyn-1.0/CloudSymbol";\r
public static final String Configuration = "http://www.simantics.org/Sysdyn-1.0/Configuration";\r
public static final String ConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.0/ConfigurationDiagram";\r
+ public static final String ConfigurationDiagramTemplate = "http://www.simantics.org/Sysdyn-1.0/ConfigurationDiagramTemplate";\r
public static final String ConstantExpression = "http://www.simantics.org/Sysdyn-1.0/ConstantExpression";\r
public static final String DefaultRealization = "http://www.simantics.org/Sysdyn-1.0/DefaultRealization";\r
public static final String DelayExpression = "http://www.simantics.org/Sysdyn-1.0/DelayExpression";\r
CloudSymbol = getResourceOrNull(graph, URIs.CloudSymbol);\r
Configuration = getResourceOrNull(graph, URIs.Configuration);\r
ConfigurationDiagram = getResourceOrNull(graph, URIs.ConfigurationDiagram);\r
+ ConfigurationDiagramTemplate = getResourceOrNull(graph, URIs.ConfigurationDiagramTemplate);\r
ConstantExpression = getResourceOrNull(graph, URIs.ConstantExpression);\r
DefaultRealization = getResourceOrNull(graph, URIs.DefaultRealization);\r
DelayExpression = getResourceOrNull(graph, URIs.DelayExpression);\r
Layer0 l0 = Layer0.getInstance(graph);\r
Resource baseRealization = graph.syncRequest(new PossibleObject(model.data, l0.HasBaseRealization));\r
if (baseRealization != null) {\r
- Variable variable = Variables.getVariable(graph, graph.getURI(baseRealization));\r
- result.add(new ConfigurationNode<Resource>(variable, baseRealization));\r
+ try {\r
+ String URI = graph.getURI(baseRealization);\r
+ Variable variable = Variables.getVariable(graph, URI);\r
+ result.add(new ConfigurationNode<Resource>(variable, baseRealization));\r
+ } catch (DatabaseException e) {\r
+ }\r
}\r
result.add(new ExperimentsFolder(model.data));\r
result.add(new ModulesNode(model.data));\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.CancelTransactionException;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.procedure.Listener;\r
import org.simantics.db.request.Read;\r
+import org.simantics.db.request.Write;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.sysdyn.SysdynResource;\r
return "Spaces are not allowed";\r
return null;\r
}\r
+ \r
+ @Override\r
+ protected Write getWriteRequest(final String label) {\r
+ return new WriteRequest() {\r
+ @Override\r
+ public void perform(WriteGraph g) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(g);\r
+ g.claimLiteral(data, l0.HasLabel, label);\r
+ String safeName = NameUtils.findFreshName(g, label, g.getSingleObject(data, l0.PartOf), l0.ConsistsOf, "%s%d");\r
+ g.claimLiteral(data, l0.HasName, safeName);\r
+ }\r
+ };\r
+ }\r
};\r
return modifier;\r
}\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.editor.participant;\r
\r
+import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.Statement;\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.exception.ServiceException;\r
import org.simantics.diagram.synchronization.ISynchronizationContext;\r
import org.simantics.diagram.synchronization.graph.CopyAdvisorUtil;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ComponentUtils;\r
import org.simantics.modeling.mapping.ComponentCopyAdvisor;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.utils.datastructures.BinaryFunction;\r
};\r
\r
Resource copy = CopyAdvisorUtil.copy(graph, source, tester);\r
+ \r
renameComponent(context, graph, source, copy, sourceContainer, targetContainer);\r
return copy;\r
}\r
+ \r
+\r
+ public static String renameComponent(ISynchronizationContext context, WriteGraph graph, Resource source,\r
+ Resource copy, Resource sourceContainer, Resource targetContainer) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ String copyName = NameUtils.getSafeName(graph, copy);\r
+ Resource configurationRoot = ComponentUtils.getCompositeConfigurationRoot(graph, targetContainer);\r
+ String name = NameUtils.findFreshName(graph, copyName, configurationRoot, l0.ConsistsOf, "%s%d");\r
+ graph.claimLiteral(copy, l0.HasName, name, Bindings.STRING);\r
+ return name;\r
+ }\r
}\r
\r
import java.io.File;\r
import java.io.IOException;\r
+import java.util.HashSet;\r
\r
import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
import org.simantics.graph.representation.TransferableGraph1;\r
import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.modeling.ModelingResources;\r
import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.utils.OldTransferableGraph1;\r
import org.simantics.ui.SimanticsUI;\r
\r
DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(project);\r
DefaultPasteHandler.defaultExecute(tg, SimanticsUI.getProject().get(), ia);\r
\r
+ \r
+ // Fix changes made to old ontology versions\r
final Resource root = ia.getRoot();\r
SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- updateOldConfiguration(graph, root);\r
- \r
- // FIXME: the links should be exported and imported automatically\r
- Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.0");\r
- Resource layer0 = graph.getResource("http://www.simantics.org/Layer0-1.0");\r
- if(!graph.hasStatement(root, l0.IsLinkedTo, sysdyn))\r
- graph.claim(root, l0.IsLinkedTo, sysdyn);\r
- if(!graph.hasStatement(root, l0.IsLinkedTo, layer0))\r
- graph.claim(root, l0.IsLinkedTo, layer0);\r
+ updateOldConfigurationToBaseRealization(graph, root);\r
+ addDefaultOntologyLinks(graph, root);\r
+ addURIsToDiagrams(graph, root);\r
}\r
});\r
} catch (DatabaseException e) {\r
return null;\r
}\r
\r
- private void updateOldConfiguration(WriteGraph graph, Resource model) {\r
+ /**\r
+ * In old versions base realization was separate. Newer versions use configuration as base realization. \r
+ * @param graph WriteGraph\r
+ * @param model Imported model\r
+ */\r
+ private static void updateOldConfigurationToBaseRealization(WriteGraph graph, Resource model) {\r
Layer0 l0 = Layer0.getInstance(graph);\r
try {\r
Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
}\r
\r
}\r
-\r
+ \r
+ /**\r
+ * Links should be exported and imported automatically. If it has failed, the \r
+ * default ontology links sysdyn and layer0 are added.\r
+ * \r
+ * @param graph WriteGraph\r
+ * @param model Imported model\r
+ */\r
+ \r
+ private static void addDefaultOntologyLinks(WriteGraph graph, Resource model) {\r
+ try {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ // The links should be exported and imported automatically\r
+ Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.0");\r
+ Resource layer0 = graph.getResource("http://www.simantics.org/Layer0-1.0");\r
+ if(!graph.hasStatement(model, l0.IsLinkedTo, sysdyn))\r
+ graph.claim(model, l0.IsLinkedTo, sysdyn);\r
+ if(!graph.hasStatement(model, l0.IsLinkedTo, layer0))\r
+ graph.claim(model, l0.IsLinkedTo, layer0);\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ \r
+ private static void addURIsToDiagrams(WriteGraph graph, Resource model) {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SimulationResource simu = SimulationResource.getInstance(graph);\r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+ try {\r
+ HashSet<Resource> configurations = new HashSet<Resource>();\r
+ \r
+ Resource configuration = graph.getPossibleObject(model, simu.HasConfiguration);\r
+ if(configuration != null) \r
+ configurations.add(configuration);\r
+ \r
+ for(Resource r : graph.getObjects(model, l0.ConsistsOf)) {\r
+ if(graph.isInheritedFrom(r, sr.Module)) {\r
+ Resource moduleConfiguration = graph.getPossibleObject(r, sr2.IsDefinedBy);\r
+ if(moduleConfiguration != null)\r
+ configurations.add(moduleConfiguration);\r
+ }\r
+ }\r
+ \r
+ for(Resource conf : configurations) {\r
+ Resource configurationDiagram = graph.getPossibleObject(conf, mr.CompositeToDiagram);\r
+ if(configurationDiagram != null && !graph.hasStatement(configurationDiagram, l0.PartOf)) {\r
+ GraphUtils.create2(graph, l0.Library, \r
+ l0.HasName, "__CONTAINER__",\r
+ l0.PartOf, conf,\r
+ l0.ConsistsOf, configurationDiagram);\r
+ }\r
+ }\r
+ \r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
}\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.DiagramConstants;\r
+import org.simantics.db.layer0.adapter.Template;\r
import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
-import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.sysdyn.ui.browser.nodes.ModulesNode;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
\r
public class NewModuleNodeHandler extends AbstractHandler {\r
\r
g.claim(moduleType, l0.Inherits, sr.Module);\r
g.claim(moduleType, l0.PartOf, model);\r
\r
- Resource diagram = OrderedSetUtils.create(g, sr.ConfigurationDiagram);\r
- GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true);\r
- g.claim(diagram, dr.HasLayer, l.getLayer());\r
- Resource mapping = g.newResource();\r
- g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
- g.claim(diagram, l0.HasTrigger, mapping);\r
-\r
- \r
Resource configuration = GraphUtils.create2(g, \r
sr.Configuration,\r
l0.HasName, name + "Configuration",\r
- mr.CompositeToDiagram, diagram,\r
l0.PartOf, model);\r
\r
g.claim(moduleType, sr2.IsDefinedBy , configuration);\r
\r
+ Resource diagram = g.newResource();\r
+ g.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(g,\r
+ ArrayMap\r
+ .keys("", "diagram", "name")\r
+ .values(configuration, diagram, "Diagrammi")\r
+ );\r
+ \r
+ \r
+ // Remove default mapping and add sysdyn mapping\r
+ for(Resource trigger : g.getObjects(diagram, l0.HasTrigger)) {\r
+ if(g.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) {\r
+ g.deny(diagram, l0.HasTrigger, trigger);\r
+ }\r
+ }\r
+ Resource mapping = g.newResource();\r
+ g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
+ g.claim(diagram, l0.HasTrigger, mapping);\r
\r
Resource moduleSymbol = g.newResource();\r
g.claimLiteral(moduleSymbol, l0.HasName, name + " Symbol");\r
import org.simantics.db.common.request.Queries;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.adapter.RuntimeValuations;\r
+import org.simantics.db.layer0.adapter.Template;\r
import org.simantics.db.layer0.adapter.TrendVariable;\r
import org.simantics.db.layer0.service.ActivationManager;\r
import org.simantics.db.request.Read;\r
import org.simantics.db.service.GraphChangeListenerSupport;\r
import org.simantics.db.service.LifecycleSupport;\r
import org.simantics.db.service.VirtualGraphSupport;\r
-import org.simantics.diagram.DiagramConstants;\r
-import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
-import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.ui.workbench.project.UIModelManager;\r
import org.simantics.ui.workbench.project.UIModelManagerBase;\r
import org.simantics.ui.workbench.project.UIModelManagerBase.WriteRunnable;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
import org.simantics.utils.datastructures.Callback;\r
import org.simantics.utils.ui.ErrorLogger;\r
import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
try {\r
Layer0 l0 = Layer0.getInstance(g);\r
SysdynResource sr = SysdynResource.getInstance(g);\r
- ModelingResources mr = ModelingResources.getInstance(g);\r
ModelingUtils mu = new ModelingUtils(g);\r
\r
String modelName = NameUtils.findFreshName(g, "Model", SimanticsUI.getProject().get(), l0.ConsistsOf, "%s%d");\r
g.claim(model, l0.InstanceOf, sr.SysdynModel);\r
g.claim(model, l0.PartOf, SimanticsUI.getProject().get());\r
\r
-\r
- Resource diagram = OrderedSetUtils.create(g, sr.ConfigurationDiagram);\r
- GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true);\r
- g.claim(diagram, mu.dr.HasLayer, l.getLayer());\r
- g.claimLiteral(diagram, l0.HasName, "Diagrammi", Bindings.STRING);\r
-\r
Resource conf = GraphUtils.create2(g,\r
sr.Configuration,\r
l0.PartOf, model,\r
l0.IsBaseRealizationOf, model,\r
l0.HasName, modelName\r
);\r
+ \r
+ Resource diagram = g.newResource();\r
+ g.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(g,\r
+ ArrayMap\r
+ .keys("", "diagram", "name")\r
+ .values(conf, diagram, "Diagrammi")\r
+ );\r
\r
- g.claim(conf, mr.CompositeToDiagram, diagram);\r
g.claim(model, mu.SIMU.HasConfiguration, conf);\r
\r
+ ModelingResources mr = ModelingResources.getInstance(g);\r
+ // Remove default mapping and add sysdyn mapping\r
+ for(Resource trigger : g.getObjects(diagram, l0.HasTrigger)) {\r
+ if(g.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) {\r
+ g.deny(diagram, l0.HasTrigger, trigger);\r
+ }\r
+ }\r
Resource mapping = g.newResource();\r
g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
g.claim(diagram, l0.HasTrigger, mapping);\r
\r
import java.awt.event.ActionEvent;\r
import java.awt.event.ActionListener;\r
+import java.util.Collection;\r
import java.util.HashMap;\r
import java.util.Map;\r
\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypes.ExpressionType;\r
import org.simantics.sysdyn.ui.properties.widgets.expressions.AuxiliaryExpression;\r
@Override\r
public Resource perform(ReadGraph graph) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
-\r
- Resource expressionList = OrderedSetUtils.getSingleOwnerList(graph, expr);\r
- Resource variable = graph.getPossibleObject(expressionList, sr.HasExpressions_Inverse);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Collection<Resource> expressionLists = OrderedSetUtils.getOwnerLists(graph, expr, l0.OrderedSet);\r
+ Resource variable = null;\r
+ if(expressionLists.size() == 1)\r
+ variable = graph.getPossibleObject(expressionLists.iterator().next(), sr.HasExpressions_Inverse);\r
return variable;\r
}\r
});\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
- if(graph.hasStatement(activefor, sr.HasActiveExpression))\r
- graph.deny(activefor, sr.HasActiveExpression);\r
- graph.claim(activefor, sr.HasActiveExpression, newExpression);\r
+ if(activefor != null) {\r
+ if(graph.hasStatement(activefor, sr.HasActiveExpression))\r
+ graph.deny(activefor, sr.HasActiveExpression);\r
+ graph.claim(activefor, sr.HasActiveExpression, newExpression);\r
+ }\r
}\r
}\r
);\r
\r
// find the variable\r
Resource expressionList = OrderedSetUtils.getSingleOwnerList(graph, expression);\r
- Resource variable = graph.getSingleObject(expressionList, sr.HasExpressions_Inverse);\r
- \r
+ Resource variable = graph.getPossibleObject(expressionList, sr.HasExpressions_Inverse);\r
+ if(variable == null)\r
+ return "";\r
\r
SysdynModelManager sdm = SysdynModelManager.getInstance(graph.getSession());\r
SysdynModel model = sdm.getModel(graph, graph.getSingleObject(variable, l0.PartOf));\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
+import org.simantics.db.exception.AdaptionException;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.variable.StandardGraphChildVariable;\r
import org.simantics.db.layer0.variable.Variable;\r
@Override\r
public Collection<Variable> browseChildren(ReadGraph graph) throws DatabaseException {\r
ArrayList<Variable> result = new ArrayList<Variable>();\r
- for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(resource)).values())\r
+ for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(resource)).values()) {\r
+ try {\r
result.add(graph.adaptContextual(child, this, Variable.class, Variable.class));\r
+ } catch (AdaptionException e) {\r
+ }\r
+ }\r
collectSpecialChildren(graph, result);\r
return result;\r
}\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.AdaptionException;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.exception.MissingVariableException;\r
import org.simantics.db.layer0.variable.Variable;\r
if(configuration == null)\r
return result;\r
\r
- for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(configuration)).values())\r
- result.add(graph.adaptContextual(child, this, Variable.class, Variable.class));\r
+ for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(configuration)).values()) {\r
+ try {\r
+ result.add(graph.adaptContextual(child, this, Variable.class, Variable.class));\r
+ } catch (AdaptionException e) {\r
+ }\r
+ }\r
\r
return result;\r
}\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
\r
-import org.simantics.databoard.Bindings;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.DiagramConstants;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
-import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;\r
+import org.simantics.db.layer0.adapter.Template;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.modeling.ModelingResources;\r
import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.modeling.ModelingResources;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
\r
public class Model implements IWriteableMDLObject {\r
\r
try {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
Layer0 l0 = Layer0.getInstance(graph);\r
- ModelingResources mr = ModelingResources.getInstance(graph);\r
- DiagramResource dr = DiagramResource.getInstance(graph);\r
SimulationResource simu = SimulationResource.getInstance(graph);\r
\r
// Diagram creation copied from SysdynProject. \r
graph,\r
sr.SysdynModel,\r
l0.PartOf, parent,\r
- l0.HasName, getName(),\r
+ l0.HasName, NameUtils.findFreshName(graph, getName(), parent, l0.ConsistsOf, "%s%d"),\r
l0.HasLabel, getName(),\r
sr.HasStartTime, startTime,\r
sr.HasStopTime, endTime,\r
l0.IsLinkedTo, layer0\r
);\r
\r
- Resource diagram = OrderedSetUtils.create(graph, sr.ConfigurationDiagram);\r
- GraphLayer l = new GraphLayerUtil(graph).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true);\r
- graph.claim(diagram, dr.HasLayer, l.getLayer());\r
- graph.claimLiteral(diagram, l0.HasName, "Diagrammi", Bindings.STRING);\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
+ \r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+ // Remove default mapping and add sysdyn mapping\r
+ for(Resource trigger : graph.getObjects(diagram, l0.HasTrigger)) {\r
+ if(graph.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) {\r
+ graph.deny(diagram, l0.HasTrigger, trigger);\r
+ }\r
+ }\r
+ Resource mapping = graph.newResource();\r
+ graph.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
+ graph.claim(diagram, l0.HasTrigger, mapping);\r
\r
- graph.claim(conf, mr.CompositeToDiagram, diagram);\r
graph.claim(model, simu.HasConfiguration, conf);\r
graph.claim(model, l0.HasBaseRealization, conf);\r
\r
- Resource mapping = graph.newResource();\r
- graph.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
- graph.claim(diagram, l0.HasTrigger, mapping);\r
-\r
Resource report = GraphUtils.create2(graph, l0.Report, l0.HasDocumentation, "===Report===");\r
\r
GraphUtils.create2(graph, simu.Experiment,\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+\r
+@GraphType("http://www.simantics.org/Layer0-1.0/Library")\r
+public class LibraryDummy implements IElement {\r
+ \r
+ @Override\r
+ public void accept(IElementVisitorVoid v) {\r
+ v.visit(this); \r
+ }\r
+\r
+}\r
addLinkType(MappingSchemas.fromAnnotations(g, WithLookupExpression.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, LookupExpression.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, Redeclaration.class));\r
- \r
- \r
+ addLinkType(MappingSchemas.fromAnnotations(g, LibraryDummy.class));\r
} catch (DatabaseException e) {\r
- // TODO Auto-generated catch block\r
e.printStackTrace();\r
} catch (InstantiationException e) {\r
- // TODO Auto-generated catch block\r
e.printStackTrace();\r
} catch (IllegalAccessException e) {\r
- // TODO Auto-generated catch block\r
e.printStackTrace();\r
} \r
}\r
import org.simantics.sysdyn.representation.Enumeration;\r
import org.simantics.sysdyn.representation.Flow;\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.Stock;\r
import org.simantics.sysdyn.representation.Valve;\r
@Override\r
public void visit(Enumeration enumeration) {\r
}\r
+ \r
+ @Override\r
+ public void visit(LibraryDummy libraryDummy) {\r
+ }\r
}\r
import org.simantics.sysdyn.representation.Enumeration;\r
import org.simantics.sysdyn.representation.Flow;\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.Stock;\r
import org.simantics.sysdyn.representation.Valve;\r
void visit(Module module);\r
void visit(Configuration configuration);\r
void visit(Enumeration enumeration);\r
+ void visit(LibraryDummy libraryDummy);\r
}\r