From: lempinen Date: Thu, 28 Apr 2011 13:47:36 +0000 (+0000) Subject: Some problems with diagram (e.g. copypaste) fixed by using diagramtemplate to create... X-Git-Tag: simantics-1.4RC1~32 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=bf7691ee96f5ad837112605f12be6967b6b4001e;p=simantics%2Fsysdyn.git Some problems with diagram (e.g. copypaste) fixed by using diagramtemplate to create the diagram and give it an uri. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20617 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java index 5295b6fd..f8e4b18e 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java +++ b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java @@ -51,15 +51,36 @@ public class ModelicaManager { public static File getModelicaHome() { String dir = System.getenv("OPENMODELICAHOME"); + File omhome = null; String osName = System.getProperty("os.name"); OSType os = calculateOS(); if (os == OSType.UNKNOWN) throw new UnsatisfiedLinkError("unknown OS '" + osName + "' for running OpenModelica"); + + // If OPENMODELICAHOME is found, try to return the folder. + if(dir != null) { + switch (os) { + case APPLE: + case LINUX: + case SUN: + omhome = new File(dir); + if(omhome.isDirectory()) + return omhome; + else + break; + case WINDOWS: + omhome = new File(dir); + if(omhome.isDirectory()) + return omhome; + else + break; + } + } - // Teemu's stuff, testing openmodelica in a plugin - if(dir == null && os.equals(OSType.WINDOWS)) { + // OPENMODELICAHOMe was not found or the folder does not exist. Try built-in OpenModelica for windows + if(os.equals(OSType.WINDOWS)) { Bundle bundle = Platform.getBundle("org.simantics.openmodelica.win32"); if (bundle != null) { @@ -78,30 +99,16 @@ public class ModelicaManager { } } - // Back to normal - - if(dir == null) { - switch (os) { - case APPLE: - case LINUX: - case SUN: - return new File("/usr/bin/omc"); - case WINDOWS: - return new File("c:/OpenModelica1.7.0"); - default: - throw new UnsatisfiedLinkError("Unsupported operating system: " + os); - } - } else { - switch (os) { - case APPLE: - case LINUX: - case SUN: - return new File(dir); - case WINDOWS: - return new File(dir); - default: - throw new UnsatisfiedLinkError("Unsupported operating system: " + os); - } + // OS was not windows or built-in OpenModelica did not work + switch (os) { + case APPLE: + case LINUX: + case SUN: + return new File("/usr/bin/omc"); + case WINDOWS: + return new File("c:/OpenModelica1.7.0"); + default: + throw new UnsatisfiedLinkError("Unsupported operating system: " + os); } } diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 2456f494..9249c412 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index f150ba43..e714c7c8 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -64,6 +64,9 @@ SYSDYN.ConfigurationDiagram { Layer0 l0 = Layer0.getInstance(graph); Resource baseRealization = graph.syncRequest(new PossibleObject(model.data, l0.HasBaseRealization)); if (baseRealization != null) { - Variable variable = Variables.getVariable(graph, graph.getURI(baseRealization)); - result.add(new ConfigurationNode(variable, baseRealization)); + try { + String URI = graph.getURI(baseRealization); + Variable variable = Variables.getVariable(graph, URI); + result.add(new ConfigurationNode(variable, baseRealization)); + } catch (DatabaseException e) { + } } result.add(new ExperimentsFolder(model.data)); result.add(new ModulesNode(model.data)); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java index 4b96fdc6..86c672a3 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java @@ -22,10 +22,12 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; +import org.simantics.db.request.Write; import org.simantics.layer0.Layer0; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.sysdyn.SysdynResource; @@ -89,6 +91,19 @@ public class ModelNode extends AbstractNode implements IDoubleClickabl return "Spaces are not allowed"; return null; } + + @Override + protected Write getWriteRequest(final String label) { + return new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + g.claimLiteral(data, l0.HasLabel, label); + String safeName = NameUtils.findFreshName(g, label, g.getSingleObject(data, l0.PartOf), l0.ConsistsOf, "%s%d"); + g.claimLiteral(data, l0.HasName, safeName); + } + }; + } }; return modifier; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java index 170d02de..5b3c122c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java @@ -11,14 +11,18 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.editor.participant; +import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Statement; import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ServiceException; import org.simantics.diagram.synchronization.ISynchronizationContext; import org.simantics.diagram.synchronization.graph.CopyAdvisorUtil; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ComponentUtils; import org.simantics.modeling.mapping.ComponentCopyAdvisor; import org.simantics.sysdyn.SysdynResource; import org.simantics.utils.datastructures.BinaryFunction; @@ -47,7 +51,19 @@ public class SysdynComponentCopyAdvisor extends ComponentCopyAdvisor{ }; Resource copy = CopyAdvisorUtil.copy(graph, source, tester); + renameComponent(context, graph, source, copy, sourceContainer, targetContainer); return copy; } + + + public static String renameComponent(ISynchronizationContext context, WriteGraph graph, Resource source, + Resource copy, Resource sourceContainer, Resource targetContainer) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + String copyName = NameUtils.getSafeName(graph, copy); + Resource configurationRoot = ComponentUtils.getCompositeConfigurationRoot(graph, targetContainer); + String name = NameUtils.findFreshName(graph, copyName, configurationRoot, l0.ConsistsOf, "%s%d"); + graph.claimLiteral(copy, l0.HasName, name, Bindings.STRING); + return name; + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java index 02ee621a..ad38e9c9 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java @@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.handlers; import java.io.File; import java.io.IOException; +import java.util.HashSet; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -33,7 +34,11 @@ import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; import org.simantics.graph.representation.TransferableGraph1; import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.utils.OldTransferableGraph1; import org.simantics.ui.SimanticsUI; @@ -76,21 +81,16 @@ public class ImportModelHandler extends AbstractHandler { DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(project); DefaultPasteHandler.defaultExecute(tg, SimanticsUI.getProject().get(), ia); + + // Fix changes made to old ontology versions final Resource root = ia.getRoot(); SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - updateOldConfiguration(graph, root); - - // FIXME: the links should be exported and imported automatically - Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.0"); - Resource layer0 = graph.getResource("http://www.simantics.org/Layer0-1.0"); - if(!graph.hasStatement(root, l0.IsLinkedTo, sysdyn)) - graph.claim(root, l0.IsLinkedTo, sysdyn); - if(!graph.hasStatement(root, l0.IsLinkedTo, layer0)) - graph.claim(root, l0.IsLinkedTo, layer0); + updateOldConfigurationToBaseRealization(graph, root); + addDefaultOntologyLinks(graph, root); + addURIsToDiagrams(graph, root); } }); } catch (DatabaseException e) { @@ -102,7 +102,12 @@ public class ImportModelHandler extends AbstractHandler { return null; } - private void updateOldConfiguration(WriteGraph graph, Resource model) { + /** + * In old versions base realization was separate. Newer versions use configuration as base realization. + * @param graph WriteGraph + * @param model Imported model + */ + private static void updateOldConfigurationToBaseRealization(WriteGraph graph, Resource model) { Layer0 l0 = Layer0.getInstance(graph); try { Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration); @@ -113,5 +118,64 @@ public class ImportModelHandler extends AbstractHandler { } } - + + /** + * Links should be exported and imported automatically. If it has failed, the + * default ontology links sysdyn and layer0 are added. + * + * @param graph WriteGraph + * @param model Imported model + */ + + private static void addDefaultOntologyLinks(WriteGraph graph, Resource model) { + try { + Layer0 l0 = Layer0.getInstance(graph); + // The links should be exported and imported automatically + Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.0"); + Resource layer0 = graph.getResource("http://www.simantics.org/Layer0-1.0"); + if(!graph.hasStatement(model, l0.IsLinkedTo, sysdyn)) + graph.claim(model, l0.IsLinkedTo, sysdyn); + if(!graph.hasStatement(model, l0.IsLinkedTo, layer0)) + graph.claim(model, l0.IsLinkedTo, layer0); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + + private static void addURIsToDiagrams(WriteGraph graph, Resource model) { + Layer0 l0 = Layer0.getInstance(graph); + SimulationResource simu = SimulationResource.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + try { + HashSet configurations = new HashSet(); + + Resource configuration = graph.getPossibleObject(model, simu.HasConfiguration); + if(configuration != null) + configurations.add(configuration); + + for(Resource r : graph.getObjects(model, l0.ConsistsOf)) { + if(graph.isInheritedFrom(r, sr.Module)) { + Resource moduleConfiguration = graph.getPossibleObject(r, sr2.IsDefinedBy); + if(moduleConfiguration != null) + configurations.add(moduleConfiguration); + } + } + + for(Resource conf : configurations) { + Resource configurationDiagram = graph.getPossibleObject(conf, mr.CompositeToDiagram); + if(configurationDiagram != null && !graph.hasStatement(configurationDiagram, l0.PartOf)) { + GraphUtils.create2(graph, l0.Library, + l0.HasName, "__CONTAINER__", + l0.PartOf, conf, + l0.ConsistsOf, configurationDiagram); + } + } + + } catch (DatabaseException e) { + e.printStackTrace(); + } + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java index 048d6291..5f8a66fb 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java @@ -22,10 +22,8 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.DiagramConstants; +import org.simantics.db.layer0.adapter.Template; import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.diagram.synchronization.graph.layer.GraphLayer; -import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.modeling.ModelingResources; @@ -34,6 +32,7 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.browser.nodes.ModulesNode; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.datastructures.ArrayMap; public class NewModuleNodeHandler extends AbstractHandler { @@ -66,22 +65,30 @@ public class NewModuleNodeHandler extends AbstractHandler { g.claim(moduleType, l0.Inherits, sr.Module); g.claim(moduleType, l0.PartOf, model); - Resource diagram = OrderedSetUtils.create(g, sr.ConfigurationDiagram); - GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true); - g.claim(diagram, dr.HasLayer, l.getLayer()); - Resource mapping = g.newResource(); - g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); - g.claim(diagram, l0.HasTrigger, mapping); - - Resource configuration = GraphUtils.create2(g, sr.Configuration, l0.HasName, name + "Configuration", - mr.CompositeToDiagram, diagram, l0.PartOf, model); g.claim(moduleType, sr2.IsDefinedBy , configuration); + Resource diagram = g.newResource(); + g.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(g, + ArrayMap + .keys("", "diagram", "name") + .values(configuration, diagram, "Diagrammi") + ); + + + // Remove default mapping and add sysdyn mapping + for(Resource trigger : g.getObjects(diagram, l0.HasTrigger)) { + if(g.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) { + g.deny(diagram, l0.HasTrigger, trigger); + } + } + Resource mapping = g.newResource(); + g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); + g.claim(diagram, l0.HasTrigger, mapping); Resource moduleSymbol = g.newResource(); g.claimLiteral(moduleSymbol, l0.HasName, name + " Symbol"); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java index 504b7e04..96f7693a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java @@ -29,18 +29,15 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.Queries; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.RuntimeValuations; +import org.simantics.db.layer0.adapter.Template; import org.simantics.db.layer0.adapter.TrendVariable; import org.simantics.db.layer0.service.ActivationManager; import org.simantics.db.request.Read; import org.simantics.db.service.GraphChangeListenerSupport; import org.simantics.db.service.LifecycleSupport; import org.simantics.db.service.VirtualGraphSupport; -import org.simantics.diagram.DiagramConstants; -import org.simantics.diagram.synchronization.graph.layer.GraphLayer; -import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.modeling.ModelingResources; @@ -66,6 +63,7 @@ import org.simantics.ui.workbench.action.ChooseActionRequest; import org.simantics.ui.workbench.project.UIModelManager; import org.simantics.ui.workbench.project.UIModelManagerBase; import org.simantics.ui.workbench.project.UIModelManagerBase.WriteRunnable; +import org.simantics.utils.datastructures.ArrayMap; import org.simantics.utils.datastructures.Callback; import org.simantics.utils.ui.ErrorLogger; import org.simantics.utils.ui.workbench.WorkbenchUtils; @@ -111,7 +109,6 @@ public class SysdynProject extends AbstractProjectFeature { try { Layer0 l0 = Layer0.getInstance(g); SysdynResource sr = SysdynResource.getInstance(g); - ModelingResources mr = ModelingResources.getInstance(g); ModelingUtils mu = new ModelingUtils(g); String modelName = NameUtils.findFreshName(g, "Model", SimanticsUI.getProject().get(), l0.ConsistsOf, "%s%d"); @@ -122,22 +119,29 @@ public class SysdynProject extends AbstractProjectFeature { g.claim(model, l0.InstanceOf, sr.SysdynModel); g.claim(model, l0.PartOf, SimanticsUI.getProject().get()); - - Resource diagram = OrderedSetUtils.create(g, sr.ConfigurationDiagram); - GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true); - g.claim(diagram, mu.dr.HasLayer, l.getLayer()); - g.claimLiteral(diagram, l0.HasName, "Diagrammi", Bindings.STRING); - Resource conf = GraphUtils.create2(g, sr.Configuration, l0.PartOf, model, l0.IsBaseRealizationOf, model, l0.HasName, modelName ); + + Resource diagram = g.newResource(); + g.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(g, + ArrayMap + .keys("", "diagram", "name") + .values(conf, diagram, "Diagrammi") + ); - g.claim(conf, mr.CompositeToDiagram, diagram); g.claim(model, mu.SIMU.HasConfiguration, conf); + ModelingResources mr = ModelingResources.getInstance(g); + // Remove default mapping and add sysdyn mapping + for(Resource trigger : g.getObjects(diagram, l0.HasTrigger)) { + if(g.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) { + g.deny(diagram, l0.HasTrigger, trigger); + } + } Resource mapping = g.newResource(); g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); g.claim(diagram, l0.HasTrigger, mapping); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java index ac2e1c8e..f6e40ded 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java @@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.properties.widgets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -32,6 +33,7 @@ import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypes.ExpressionType; import org.simantics.sysdyn.ui.properties.widgets.expressions.AuxiliaryExpression; @@ -171,9 +173,11 @@ public class ExpressionWidget implements Widget { @Override public Resource perform(ReadGraph graph) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); - - Resource expressionList = OrderedSetUtils.getSingleOwnerList(graph, expr); - Resource variable = graph.getPossibleObject(expressionList, sr.HasExpressions_Inverse); + Layer0 l0 = Layer0.getInstance(graph); + Collection expressionLists = OrderedSetUtils.getOwnerLists(graph, expr, l0.OrderedSet); + Resource variable = null; + if(expressionLists.size() == 1) + variable = graph.getPossibleObject(expressionLists.iterator().next(), sr.HasExpressions_Inverse); return variable; } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java index d1edbb2b..e36ffbad 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java @@ -154,9 +154,11 @@ public class BasicExpression implements IExpression { @Override public void perform(WriteGraph graph) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); - if(graph.hasStatement(activefor, sr.HasActiveExpression)) - graph.deny(activefor, sr.HasActiveExpression); - graph.claim(activefor, sr.HasActiveExpression, newExpression); + if(activefor != null) { + if(graph.hasStatement(activefor, sr.HasActiveExpression)) + graph.deny(activefor, sr.HasActiveExpression); + graph.claim(activefor, sr.HasActiveExpression, newExpression); + } } } ); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java index f07b19fb..fbee902c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java @@ -181,8 +181,9 @@ public class StockExpression implements IExpression { // find the variable Resource expressionList = OrderedSetUtils.getSingleOwnerList(graph, expression); - Resource variable = graph.getSingleObject(expressionList, sr.HasExpressions_Inverse); - + Resource variable = graph.getPossibleObject(expressionList, sr.HasExpressions_Inverse); + if(variable == null) + return ""; SysdynModelManager sdm = SysdynModelManager.getInstance(graph.getSession()); SysdynModel model = sdm.getModel(graph, graph.getSingleObject(variable, l0.PartOf)); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java index 2b08d71e..1402f225 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java @@ -18,6 +18,7 @@ import java.util.Map; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.uri.UnescapedChildMapOfResource; +import org.simantics.db.exception.AdaptionException; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.StandardGraphChildVariable; import org.simantics.db.layer0.variable.Variable; @@ -42,8 +43,12 @@ public class ConfigurationVariable extends StandardGraphChildVariable { @Override public Collection browseChildren(ReadGraph graph) throws DatabaseException { ArrayList result = new ArrayList(); - for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(resource)).values()) + for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(resource)).values()) { + try { result.add(graph.adaptContextual(child, this, Variable.class, Variable.class)); + } catch (AdaptionException e) { + } + } collectSpecialChildren(graph, result); return result; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ModuleVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ModuleVariable.java index c5e21968..bfc5120f 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ModuleVariable.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ModuleVariable.java @@ -19,6 +19,7 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.uri.UnescapedChildMapOfResource; import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.AdaptionException; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.exception.MissingVariableException; import org.simantics.db.layer0.variable.Variable; @@ -60,8 +61,12 @@ public class ModuleVariable extends ChildVariable { if(configuration == null) return result; - for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(configuration)).values()) - result.add(graph.adaptContextual(child, this, Variable.class, Variable.class)); + for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(configuration)).values()) { + try { + result.add(graph.adaptContextual(child, this, Variable.class, Variable.class)); + } catch (AdaptionException e) { + } + } return result; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Model.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Model.java index 98e00c95..d684b886 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Model.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Model.java @@ -14,20 +14,17 @@ package org.simantics.sysdyn.mdlImport.mdlElements; import java.util.ArrayList; import java.util.HashMap; -import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; -import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.DiagramConstants; -import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.diagram.synchronization.graph.layer.GraphLayer; -import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil; +import org.simantics.db.layer0.adapter.Template; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.sysdyn.SysdynResource; -import org.simantics.modeling.ModelingResources; +import org.simantics.utils.datastructures.ArrayMap; public class Model implements IWriteableMDLObject { @@ -219,8 +216,6 @@ public class Model implements IWriteableMDLObject { try { SysdynResource sr = SysdynResource.getInstance(graph); Layer0 l0 = Layer0.getInstance(graph); - ModelingResources mr = ModelingResources.getInstance(graph); - DiagramResource dr = DiagramResource.getInstance(graph); SimulationResource simu = SimulationResource.getInstance(graph); // Diagram creation copied from SysdynProject. @@ -233,7 +228,7 @@ public class Model implements IWriteableMDLObject { graph, sr.SysdynModel, l0.PartOf, parent, - l0.HasName, getName(), + l0.HasName, NameUtils.findFreshName(graph, getName(), parent, l0.ConsistsOf, "%s%d"), l0.HasLabel, getName(), sr.HasStartTime, startTime, sr.HasStopTime, endTime, @@ -241,25 +236,35 @@ public class Model implements IWriteableMDLObject { l0.IsLinkedTo, layer0 ); - Resource diagram = OrderedSetUtils.create(graph, sr.ConfigurationDiagram); - GraphLayer l = new GraphLayerUtil(graph).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true); - graph.claim(diagram, dr.HasLayer, l.getLayer()); - graph.claimLiteral(diagram, l0.HasName, "Diagrammi", Bindings.STRING); Resource conf = GraphUtils.create2(graph, sr.Configuration, l0.PartOf, model, l0.HasName, getName() ); + + Resource diagram = graph.newResource(); + graph.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(graph, + ArrayMap + .keys("", "diagram", "name") + .values(conf, diagram, "Diagrammi") + ); + + + ModelingResources mr = ModelingResources.getInstance(graph); + // Remove default mapping and add sysdyn mapping + for(Resource trigger : graph.getObjects(diagram, l0.HasTrigger)) { + if(graph.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) { + graph.deny(diagram, l0.HasTrigger, trigger); + } + } + Resource mapping = graph.newResource(); + graph.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); + graph.claim(diagram, l0.HasTrigger, mapping); - graph.claim(conf, mr.CompositeToDiagram, diagram); graph.claim(model, simu.HasConfiguration, conf); graph.claim(model, l0.HasBaseRealization, conf); - Resource mapping = graph.newResource(); - graph.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); - graph.claim(diagram, l0.HasTrigger, mapping); - Resource report = GraphUtils.create2(graph, l0.Report, l0.HasDocumentation, "===Report==="); GraphUtils.create2(graph, simu.Experiment, diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LibraryDummy.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LibraryDummy.java new file mode 100644 index 00000000..8762ade8 --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LibraryDummy.java @@ -0,0 +1,15 @@ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + + +@GraphType("http://www.simantics.org/Layer0-1.0/Library") +public class LibraryDummy implements IElement { + + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } + +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java index 29a78bad..3614a667 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java @@ -50,16 +50,12 @@ public class SysdynSchema extends SimpleSchema { addLinkType(MappingSchemas.fromAnnotations(g, WithLookupExpression.class)); addLinkType(MappingSchemas.fromAnnotations(g, LookupExpression.class)); addLinkType(MappingSchemas.fromAnnotations(g, Redeclaration.class)); - - + addLinkType(MappingSchemas.fromAnnotations(g, LibraryDummy.class)); } catch (DatabaseException e) { - // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { - // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java index 7a224f95..af988b5d 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java @@ -18,6 +18,7 @@ import org.simantics.sysdyn.representation.Dependency; import org.simantics.sysdyn.representation.Enumeration; import org.simantics.sysdyn.representation.Flow; import org.simantics.sysdyn.representation.Input; +import org.simantics.sysdyn.representation.LibraryDummy; import org.simantics.sysdyn.representation.Module; import org.simantics.sysdyn.representation.Stock; import org.simantics.sysdyn.representation.Valve; @@ -63,4 +64,8 @@ public class ElementVisitorVoidAdapter implements IElementVisitorVoid { @Override public void visit(Enumeration enumeration) { } + + @Override + public void visit(LibraryDummy libraryDummy) { + } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java index 0d560b2b..9c7e5504 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java @@ -18,6 +18,7 @@ import org.simantics.sysdyn.representation.Dependency; import org.simantics.sysdyn.representation.Enumeration; import org.simantics.sysdyn.representation.Flow; import org.simantics.sysdyn.representation.Input; +import org.simantics.sysdyn.representation.LibraryDummy; import org.simantics.sysdyn.representation.Module; import org.simantics.sysdyn.representation.Stock; import org.simantics.sysdyn.representation.Valve; @@ -34,4 +35,5 @@ public interface IElementVisitorVoid { void visit(Module module); void visit(Configuration configuration); void visit(Enumeration enumeration); + void visit(LibraryDummy libraryDummy); }