PROJ.RequiresNamespace
"http://www.simantics.org/Sysdyn-1.0" : L0.URI
"http://www.simantics.org/Layer0-1.0" : L0.URI
+
+SYSDYN.SharedFunctionOntology <T L0.Ontology
+SYSDYN.SharedModuleOntolofgy <T L0.Ontology
//#####################################################################
// Model
SYSDYN.IsOutput <R L0.IsRelatedTo : L0.Tag
@L0.symmetric
+
+SYSDYN.SysdynModuleLibrary <T L0.Library
+ @L0.singleProperty L0.HasName
+ @L0.optionalProperty L0.HasDescription
+
+
//#####################################################################
// Connections and Relations
//#####################################################################
SYSDYN.HasExternalFile <R L0.HasProperty
L0.HasRange L0.ByteArray
-
+SYSDYN.SysdynModelicaFunctionLibrary <T L0.Library
+ @L0.singleProperty L0.HasName
+ @L0.optionalProperty L0.HasDescription
+
//#####################################################################
// Experiments
//#####################################################################
L0 = <http://www.simantics.org/Layer0-1.0>\r
SYSDYN = <http://www.simantics.org/Sysdyn-1.0>\r
\r
-FL = <http://www.simantics.org/Sysdyn-1.0/BasicFunctions> : L0.Library\r
+FL = <http://www.simantics.org/Sysdyn-1.0/Built-in Functions> : SYSDYN.SysdynModelicaFunctionLibrary\r
\r
\r
FL.xidz : SYSDYN.SysdynModelicaFunction\r
//######################################################################\r
\r
/*\r
-WM = <http://www.simantics.org/Sysdyn-1.0/WorkModel> : PROJ.Project\r
- PROJ.HasFeature _ : PROJ.FeatureSpec\r
- PROJ.HasGroupId "org.simantics.sysdyn.feature.group"\r
- L0.PartOf <http://Projects>\r
-*/\r
-\r
-WORKMODEL = <http://www.simantics.org/WorkModel> : L0.Ontology\r
+WM = <http://Projects/Development Project> : PROJ.Project\r
@L0.new\r
+*/\r
\r
-WORKMODEL.WM : PROJ.Project\r
- PROJ.HasFeature _ : PROJ.FeatureSpec\r
- PROJ.HasGroupId "org.simantics.sysdyn.feature.group"\r
- L0.PartOf <http://Projects>\r
+WM = <http://Projects/Work Model Project> : PROJ.Project\r
+ @L0.new\r
\r
-WM = WORKMODEL.WM\r
\r
TAGS = WM.Tags : L0.Library\r
\r
SIMU.HasConfiguration WC\r
SYSDYN.HasStartTime 0.0 \r
SYSDYN.HasStopTime 24.0 \r
+ L0.IsLinkedTo SYSDYN\r
+ L0.IsLinkedTo L0\r
+ \r
WM.WorkModel.Experiment : SYSDYN.Experiment\r
L0.HasLabel "Experiment" \r
\r
public final Resource Auxiliary;\r
public final Resource AuxiliarySymbol;\r
public final Resource BasicExperiment;\r
- public final Resource BasicFunctions;\r
- public final Resource BasicFunctions_interpolate;\r
- public final Resource BasicFunctions_interpolateFull;\r
- public final Resource BasicFunctions_xidz;\r
- public final Resource BasicFunctions_zidz;\r
+ public final Resource Built$in_Functions;\r
+ public final Resource Built$in_Functions_interpolate;\r
+ public final Resource Built$in_Functions_interpolateFull;\r
+ public final Resource Built$in_Functions_xidz;\r
+ public final Resource Built$in_Functions_zidz;\r
public final Resource Cloud;\r
public final Resource CloudSymbol;\r
public final Resource Configuration;\r
public final Resource ReplacingEnumeration;\r
public final Resource ReplacingEnumeration_Inverse;\r
public final Resource Result;\r
+ public final Resource SharedFunctionOntology;\r
+ public final Resource SharedModuleOntolofgy;\r
public final Resource ShowEnumerationIndexInCharts;\r
public final Resource ShowEnumerationIndexInCharts_Inverse;\r
public final Resource SimulateOnChangeExperiment;\r
public final Resource SysdynDiagramModelingRules;\r
public final Resource SysdynModel;\r
public final Resource SysdynModelicaFunction;\r
+ public final Resource SysdynModelicaFunctionLibrary;\r
+ public final Resource SysdynModuleLibrary;\r
public final Resource SysdynTerminal;\r
public final Resource Valve;\r
public final Resource ValveSymbol;\r
public static final String Auxiliary = "http://www.simantics.org/Sysdyn-1.0/Auxiliary";\r
public static final String AuxiliarySymbol = "http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol";\r
public static final String BasicExperiment = "http://www.simantics.org/Sysdyn-1.0/BasicExperiment";\r
- public static final String BasicFunctions = "http://www.simantics.org/Sysdyn-1.0/BasicFunctions";\r
- public static final String BasicFunctions_interpolate = "http://www.simantics.org/Sysdyn-1.0/BasicFunctions/interpolate";\r
- public static final String BasicFunctions_interpolateFull = "http://www.simantics.org/Sysdyn-1.0/BasicFunctions/interpolateFull";\r
- public static final String BasicFunctions_xidz = "http://www.simantics.org/Sysdyn-1.0/BasicFunctions/xidz";\r
- public static final String BasicFunctions_zidz = "http://www.simantics.org/Sysdyn-1.0/BasicFunctions/zidz";\r
+ public static final String Built$in_Functions = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions";\r
+ public static final String Built$in_Functions_interpolate = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/interpolate";\r
+ public static final String Built$in_Functions_interpolateFull = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/interpolateFull";\r
+ public static final String Built$in_Functions_xidz = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/xidz";\r
+ public static final String Built$in_Functions_zidz = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/zidz";\r
public static final String Cloud = "http://www.simantics.org/Sysdyn-1.0/Cloud";\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 ReplacingEnumeration = "http://www.simantics.org/Sysdyn-1.0/ReplacingEnumeration";\r
public static final String ReplacingEnumeration_Inverse = "http://www.simantics.org/Sysdyn-1.0/ReplacingEnumeration/Inverse";\r
public static final String Result = "http://www.simantics.org/Sysdyn-1.0/Result";\r
+ public static final String SharedFunctionOntology = "http://www.simantics.org/Sysdyn-1.0/SharedFunctionOntology";\r
+ public static final String SharedModuleOntolofgy = "http://www.simantics.org/Sysdyn-1.0/SharedModuleOntolofgy";\r
public static final String ShowEnumerationIndexInCharts = "http://www.simantics.org/Sysdyn-1.0/ShowEnumerationIndexInCharts";\r
public static final String ShowEnumerationIndexInCharts_Inverse = "http://www.simantics.org/Sysdyn-1.0/ShowEnumerationIndexInCharts/Inverse";\r
public static final String SimulateOnChangeExperiment = "http://www.simantics.org/Sysdyn-1.0/SimulateOnChangeExperiment";\r
public static final String SysdynDiagramModelingRules = "http://www.simantics.org/Sysdyn-1.0/SysdynDiagramModelingRules";\r
public static final String SysdynModel = "http://www.simantics.org/Sysdyn-1.0/SysdynModel";\r
public static final String SysdynModelicaFunction = "http://www.simantics.org/Sysdyn-1.0/SysdynModelicaFunction";\r
+ public static final String SysdynModelicaFunctionLibrary = "http://www.simantics.org/Sysdyn-1.0/SysdynModelicaFunctionLibrary";\r
+ public static final String SysdynModuleLibrary = "http://www.simantics.org/Sysdyn-1.0/SysdynModuleLibrary";\r
public static final String SysdynTerminal = "http://www.simantics.org/Sysdyn-1.0/SysdynTerminal";\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
Auxiliary = getResourceOrNull(graph, URIs.Auxiliary);\r
AuxiliarySymbol = getResourceOrNull(graph, URIs.AuxiliarySymbol);\r
BasicExperiment = getResourceOrNull(graph, URIs.BasicExperiment);\r
- BasicFunctions = getResourceOrNull(graph, URIs.BasicFunctions);\r
- BasicFunctions_interpolate = getResourceOrNull(graph, URIs.BasicFunctions_interpolate);\r
- BasicFunctions_interpolateFull = getResourceOrNull(graph, URIs.BasicFunctions_interpolateFull);\r
- BasicFunctions_xidz = getResourceOrNull(graph, URIs.BasicFunctions_xidz);\r
- BasicFunctions_zidz = getResourceOrNull(graph, URIs.BasicFunctions_zidz);\r
+ Built$in_Functions = getResourceOrNull(graph, URIs.Built$in_Functions);\r
+ Built$in_Functions_interpolate = getResourceOrNull(graph, URIs.Built$in_Functions_interpolate);\r
+ Built$in_Functions_interpolateFull = getResourceOrNull(graph, URIs.Built$in_Functions_interpolateFull);\r
+ Built$in_Functions_xidz = getResourceOrNull(graph, URIs.Built$in_Functions_xidz);\r
+ Built$in_Functions_zidz = getResourceOrNull(graph, URIs.Built$in_Functions_zidz);\r
Cloud = getResourceOrNull(graph, URIs.Cloud);\r
CloudSymbol = getResourceOrNull(graph, URIs.CloudSymbol);\r
Configuration = getResourceOrNull(graph, URIs.Configuration);\r
ReplacingEnumeration = getResourceOrNull(graph, URIs.ReplacingEnumeration);\r
ReplacingEnumeration_Inverse = getResourceOrNull(graph, URIs.ReplacingEnumeration_Inverse);\r
Result = getResourceOrNull(graph, URIs.Result);\r
+ SharedFunctionOntology = getResourceOrNull(graph, URIs.SharedFunctionOntology);\r
+ SharedModuleOntolofgy = getResourceOrNull(graph, URIs.SharedModuleOntolofgy);\r
ShowEnumerationIndexInCharts = getResourceOrNull(graph, URIs.ShowEnumerationIndexInCharts);\r
ShowEnumerationIndexInCharts_Inverse = getResourceOrNull(graph, URIs.ShowEnumerationIndexInCharts_Inverse);\r
SimulateOnChangeExperiment = getResourceOrNull(graph, URIs.SimulateOnChangeExperiment);\r
SysdynDiagramModelingRules = getResourceOrNull(graph, URIs.SysdynDiagramModelingRules);\r
SysdynModel = getResourceOrNull(graph, URIs.SysdynModel);\r
SysdynModelicaFunction = getResourceOrNull(graph, URIs.SysdynModelicaFunction);\r
+ SysdynModelicaFunctionLibrary = getResourceOrNull(graph, URIs.SysdynModelicaFunctionLibrary);\r
+ SysdynModuleLibrary = getResourceOrNull(graph, URIs.SysdynModuleLibrary);\r
SysdynTerminal = getResourceOrNull(graph, URIs.SysdynTerminal);\r
Valve = getResourceOrNull(graph, URIs.Valve);\r
ValveSymbol = getResourceOrNull(graph, URIs.ValveSymbol);\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.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.structural.stubs.StructuralResource2;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.adapter.ChildVariable;\r
import org.simantics.sysdyn.ui.browser.BrowserSelection;\r
import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
import org.simantics.ui.DoubleClickEvent;\r
if(!bss.isEmpty()) {\r
Layer0 l0 = Layer0.getInstance(g);\r
for(BrowserSelection bs : bss) {\r
- Resource instanceOf = g.getSingleObject((Resource)bs.getAdapter(Resource.class), l0.InstanceOf);\r
+ Resource configuration = (Resource)bs.getAdapter(Resource.class);\r
+ Resource instanceOf = g.getSingleObject(configuration, l0.InstanceOf);\r
+ \r
SysdynResource sr = SysdynResource.getInstance(g);\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(g);\r
if(g.isInheritedFrom(instanceOf, sr.Module)) {\r
- StructuralResource2 sr2 = StructuralResource2.getInstance(g);\r
- Resource conf = g.getSingleObject(instanceOf, sr2.IsDefinedBy);\r
- addShowModuleAction(e, getResourceEditorInput(g, bs.getModel(), conf, bs.getURI()));\r
- }\r
+ configuration = g.getSingleObject(instanceOf, sr2.IsDefinedBy);\r
+ ChildVariable variable = (ChildVariable) bs.getAdapter(Variable.class);\r
+ String rvi = variable.getRvi(g);\r
+ Resource model = Variables.getModel(g, variable);\r
+ addShowModuleAction(e, getResourceEditorInput(g, model, configuration, rvi));\r
+ } \r
}\r
} else {\r
ModuleNode moduleNode = ISelectionUtils.filterSingleSelection(e.getResource(), ModuleNode.class);\r
if(moduleNode != null) {\r
Layer0 l0 = Layer0.getInstance(g);\r
StructuralResource2 sr2 = StructuralResource2.getInstance(g);\r
- String rvi = moduleNode.getURI(g);\r
- Resource instanceOf = g.getSingleObject(moduleNode.getResource() != null ? moduleNode.getResource() : moduleNode.data, l0.InstanceOf);\r
+ Resource model;\r
+ String rvi;\r
+ if(moduleNode.getVariable() != null) {\r
+ model = Variables.getModel(g, moduleNode.getVariable());\r
+ ChildVariable var = (ChildVariable)moduleNode.getVariable();\r
+ rvi = var.getRvi(g);\r
+ } else {\r
+ rvi = (String)g.getRelatedValue(moduleNode.data, Layer0.getInstance(g).HasName);\r
+ model = g.getSingleObject(moduleNode.data, l0.PartOf);\r
+ }\r
+ \r
+ Resource instanceOf = g.getSingleObject(moduleNode.data, l0.InstanceOf);\r
Resource conf = g.getSingleObject(instanceOf, sr2.IsDefinedBy);\r
- addShowModuleAction(e, getResourceEditorInput(g, moduleNode.getModel(), conf, rvi));\r
+ \r
+ addShowModuleAction(e, getResourceEditorInput(g, model, conf, rvi));\r
}\r
}\r
} \r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.HashSet;\r
+import java.util.Map;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.scl.runtime.function.Function;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode;\r
+\r
+public class FunctionLibraries extends ViewpointContributor<FunctionsFolder> {\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, FunctionsFolder functionsFolder)\r
+ throws DatabaseException {\r
+\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ \r
+ ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+ \r
+ // Find model functions\r
+ for(Resource function : graph.syncRequest(new ObjectsWithType(functionsFolder.data, l0.ConsistsOf, sr.SysdynModelicaFunction))) {\r
+ result.add(new FunctionNode(function));\r
+ }\r
+ \r
+ // Find shared libraries\r
+ Function index = graph.adapt(L0.Dependencies, Function.class);\r
+ Collection<Map<String, Object>> results = (Collection<Map<String, Object>>)index.apply(graph, functionsFolder.data, "Types:SharedFunctionOntology");\r
+ HashSet<Resource> sharedLibraries = new HashSet<Resource>();\r
+ for(Map<String, Object> r : results) {\r
+ Resource sharedLibrary = (Resource)r.get("Resource");\r
+ if(sharedLibrary == null)\r
+ continue;\r
+ sharedLibraries.add(sharedLibrary);\r
+ }\r
+ \r
+ // Find function libraries in model and sysdyn ontology\r
+ index = graph.adapt(L0.Dependencies, Function.class);\r
+ results = (Collection<Map<String, Object>>)index.apply(graph, functionsFolder.data, "Types:SysdynModelicaFunctionLibrary");\r
+ HashSet<Resource> modelLibraries = new HashSet<Resource>();\r
+ for(Map<String, Object> r : results) {\r
+ Resource library = (Resource)r.get("Resource");\r
+ if(library == null)\r
+ continue;\r
+ Resource root = graph.getPossibleObject(library, l0.PartOf);\r
+ while(!graph.isInstanceOf(root, sr.SysdynModel) && !graph.isInstanceOf(root, l0.Ontology)) {\r
+ library = root;\r
+ root = graph.getPossibleObject(library, l0.PartOf);\r
+ }\r
+ \r
+ // If the root is not a shared library (it is the model or sysdyn ontology)\r
+ if(!sharedLibraries.contains(root))\r
+ modelLibraries.add(library);\r
+ }\r
+ \r
+ \r
+ for(Resource modelLibrary : modelLibraries) {\r
+ Resource partOf = graph.getPossibleObject(modelLibrary, l0.PartOf);\r
+ if(graph.isInstanceOf(partOf, sr.SysdynModel))\r
+ // From the model\r
+ result.add(new FunctionLibraryNode<Resource>(modelLibrary));\r
+ else\r
+ // From sysdyn ontology, this is read only\r
+ result.add(new FunctionLibraryNode<Resource>(modelLibrary));\r
+ }\r
+ \r
+ for(Resource sharedLibrary : sharedLibraries)\r
+ result.add(new SharedFunctionLibraryNode(sharedLibrary));\r
+ \r
+ return result;\r
+\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Standard";\r
+ }\r
+ \r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
+\r
+public class FunctionLibraryLabeler extends LabelerContributor<FunctionLibraryNode<Resource>>{\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, FunctionLibraryNode<Resource> input)\r
+ throws DatabaseException {\r
+ String name = NameUtils.getSafeName(graph, input.data);\r
+ return name;\r
+ }\r
+\r
+\r
+}\r
\r
import java.util.ArrayList;\r
import java.util.Collection;\r
-import java.util.Map;\r
\r
import org.simantics.browsing.ui.common.node.AbstractNode;\r
import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.scl.runtime.function.Function;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
import org.simantics.sysdyn.ui.browser.nodes.FunctionNode;\r
-import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder;\r
\r
-public class Functions extends ViewpointContributor<FunctionsFolder> {\r
-\r
- @Override\r
- public Collection<?> getContribution(ReadGraph graph, FunctionsFolder functionsFolder)\r
- throws DatabaseException {\r
-\r
- ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
- Function index = graph.adapt(L0.Dependencies, Function.class);\r
- Collection<Map<String, Object>> results = (Collection<Map<String, Object>>)index.apply(graph, functionsFolder.data, "Types:SysdynModelicaFunction");\r
- for(Map<String, Object> r : results) {\r
- Resource function = (Resource)r.get("Resource");\r
- if(function != null);\r
- result.add(new FunctionNode(function));\r
- }\r
- return result;\r
+public class LibraryFunctions extends ViewpointContributor<FunctionLibraryNode<Resource>> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph,\r
+ FunctionLibraryNode<Resource> library) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+ for(Resource function : graph.syncRequest(new ObjectsWithType(library.data, l0.ConsistsOf, SysdynResource.getInstance(graph).SysdynModelicaFunction))) {\r
+ result.add(new FunctionNode(function));\r
+ }\r
+ for(Resource functionLibrary : graph.syncRequest(new ObjectsWithType(library.data, l0.ConsistsOf, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary))) {\r
+ result.add(new FunctionLibraryNode<Resource>(functionLibrary));\r
+ }\r
+ return result;\r
\r
}\r
\r
public String getViewpointId() {\r
return "Standard";\r
}\r
- \r
-\r
}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.structural.ui.modelBrowser.nodes.AbstractNode;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+public class SysdynProject extends ViewpointContributor<Resource> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, Resource project)\r
+ throws DatabaseException {\r
+\r
+ ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(project, L0.ConsistsOf, SysdynResource.getInstance(graph).SysdynModel))) {\r
+ try {\r
+ result.add(graph.adapt(r, AbstractNode.class));\r
+ } catch(DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ return result;\r
+\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Standard";\r
+ }\r
+\r
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.browser.nodes;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDeletableNode;\r
+import org.simantics.browsing.ui.common.node.IDropTargetNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.browsing.ui.graph.impl.LabelModifier;\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.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.FunctionUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+\r
+public class FunctionLibraryNode<T> extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode, IDropTargetNode {\r
+\r
+ \r
+ public FunctionLibraryNode(Resource resource) {\r
+ super(resource);\r
+ }\r
+\r
+ @Override\r
+ public Modifier getModifier(String columnId) {\r
+ try {\r
+ Resource hasName = Layer0.getInstance(SimanticsUI.getSession()).HasName;\r
+ LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data, hasName) {\r
+ @Override\r
+ public String isValid(String label) {\r
+ if (label.isEmpty())\r
+ return "Empty label not allowed";\r
+ if (label.contains(" "))\r
+ return "Spaces are not allowed";\r
+ return null;\r
+ }\r
+ };\r
+ return modifier;\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public void delete() throws DeleteException {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ graph.deny(data, l0.PartOf);\r
+ }\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public void drop(Object data) {\r
+ final Resource[] resources = ResourceAdaptionUtils.toResources(data);\r
+ final Resource library = this.data;\r
+ if(resources.length > 0) {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ for(Resource tobeMoved : resources) {\r
+ if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||\r
+ graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {\r
+ Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf);\r
+ graph.deny(tobeMoved, l0.PartOf);\r
+ graph.claim(tobeMoved, l0.PartOf, library);\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, oldLib);\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
+ }\r
+ }\r
+ }\r
+ });\r
+ }\r
+ }\r
+ \r
+}\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.browser.nodes;\r
\r
-import org.simantics.browsing.ui.common.node.IDeletable;\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDeletableNode;\r
+import org.simantics.browsing.ui.common.node.IDropTargetNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.browsing.ui.graph.impl.LabelModifier;\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.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.FunctionUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
\r
-public class FunctionNode extends VariableNode<Resource> implements IDeletable {\r
+public class FunctionNode extends VariableNode<Resource> implements IDeletableNode, IModifiableNode, IDropTargetNode {\r
\r
public FunctionNode(final Resource resource) {\r
super(resource);\r
}\r
+ \r
+ @Override\r
+ public Modifier getModifier(String columnId) {\r
+ try {\r
+ Resource hasName = Layer0.getInstance(SimanticsUI.getSession()).HasName;\r
+ LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data, hasName) {\r
+ @Override\r
+ public String isValid(String label) {\r
+ if (label.isEmpty())\r
+ return "Empty label not allowed";\r
+ if (label.contains(" "))\r
+ return "Spaces are not allowed";\r
+ return null;\r
+ }\r
+ };\r
+ return modifier;\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ return null;\r
+ }\r
\r
+ @Override\r
+ public void delete() throws DeleteException {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource partOf = graph.getSingleObject(data, l0.PartOf);\r
+ if(partOf != null) {\r
+ graph.deny(data, l0.PartOf, partOf);\r
+ }\r
+ }\r
+ });\r
+ }\r
+ \r
+ @Override\r
+ public void drop(Object data) {\r
+ final Resource[] resources = ResourceAdaptionUtils.toResources(data);\r
+ final Resource thisFunction = this.data;\r
+ \r
+ if(resources.length > 0) {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource library = null;\r
+ for(Resource tobeMoved : resources) {\r
+ if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||\r
+ graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {\r
+ if(library == null) {\r
+ library = graph.getSingleObject(thisFunction, l0.PartOf);\r
+ }\r
+ Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf);\r
+ graph.deny(tobeMoved, l0.PartOf);\r
+ graph.claim(tobeMoved, l0.PartOf, library);\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, oldLib);\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
+ }\r
+ }\r
+ }\r
+ });\r
+ }\r
+ }\r
}\r
package org.simantics.sysdyn.ui.browser.nodes;\r
\r
import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.IDropTargetNode;\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.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.FunctionUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
\r
-public class FunctionsFolder extends AbstractNode<Resource> {\r
+public class FunctionsFolder extends AbstractNode<Resource> implements IDropTargetNode{\r
\r
public FunctionsFolder(Resource resource) {\r
super(resource);\r
return null;\r
return super.getAdapter(adapter);\r
}\r
+ \r
+ @Override\r
+ public void drop(Object data) {\r
+ final Resource[] resources = ResourceAdaptionUtils.toResources(data);\r
+ final Resource library = this.data;\r
+ if(resources.length > 0) {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ for(Resource tobeMoved : resources) {\r
+ if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||\r
+ graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {\r
+ Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf);\r
+ graph.deny(tobeMoved, l0.PartOf);\r
+ graph.claim(tobeMoved, l0.PartOf, library);\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, oldLib);\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
+ }\r
+ }\r
+ }\r
+ });\r
+ }\r
+ }\r
+ \r
+\r
+
+ \r
+ \r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.browser.nodes;\r
+\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDropTargetNode;\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.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.FunctionUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+\r
+public class SharedFunctionLibraryNode extends FunctionLibraryNode<Resource> implements IDropTargetNode {\r
+\r
+ public SharedFunctionLibraryNode(Resource resource) {\r
+ super(resource);\r
+ }\r
+\r
+ @Override\r
+ public void delete() throws DeleteException {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ \r
+ graph.deny(data, l0.PartOf);\r
+ graph.deny(data, l0.IsLinkedTo_Inverse);\r
+\r
+ // TODO: remove file\r
+ }\r
+ });\r
+ }\r
+ \r
+ @Override\r
+ public void drop(Object data) {\r
+ final Resource[] resources = ResourceAdaptionUtils.toResources(data);\r
+ final Resource library = this.data;\r
+ if(resources.length > 0) {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ for(Resource tobeMoved : resources) {\r
+ if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||\r
+ graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {\r
+ Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf);\r
+ graph.deny(tobeMoved, l0.PartOf);\r
+ graph.claim(tobeMoved, l0.PartOf, library);\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, oldLib);\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
+ }\r
+ }\r
+ \r
+ }\r
+ });\r
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.Files;\r
+import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.primitiverequest.PossibleRelatedValue;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.TransferableGraphRequest2;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.graph.representation.TransferableGraph1;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+public class ExportFunctionLibrary extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ final Resource functionLibrary = ResourceAdaptionUtils.toSingleResource(sel);\r
+ if(functionLibrary == null) return null;\r
+ \r
+ String name = null;\r
+ try {\r
+ name = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ if (!graph.hasStatement(functionLibrary, Layer0.getInstance(graph).PartOf))\r
+ return null;\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ String name = graph.syncRequest(new PossibleRelatedValue<String>(functionLibrary, l0.HasName, Bindings.STRING ));\r
+ return name;\r
+ \r
+ }\r
+ \r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ if(name == null) return null;\r
+ \r
+ Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
+ fd.setText("Export..");\r
+ fd.setFileName(name);\r
+ fd.setFilterPath(Platform.getLocation().toOSString());\r
+ String[] filterExt = {"*.tg"};\r
+ fd.setFilterExtensions(filterExt);\r
+ final String selected = fd.open();\r
+ if(selected == null) return null;\r
+ \r
+ \r
+ SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+ \r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ String name = graph.syncRequest(new PossibleRelatedValue<String>(functionLibrary, l0.HasName, Bindings.STRING ));\r
+ ArrayList<Pair<Resource, String>> roots = new ArrayList<Pair<Resource, String>>();\r
+ roots.add(Pair.make(functionLibrary, name));\r
+ TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, functionLibrary));\r
+\r
+ try {\r
+ Files.createFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class), tg);\r
+ } catch (RuntimeBindingConstructionException e) {\r
+ e.printStackTrace();\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ }\r
+\r
+ \r
+ }\r
+ });\r
+\r
+ return null;\r
+ }\r
+\r
+}\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.widgets.FileDialog;\r
import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.ui.IWorkbenchPart;\r
import org.eclipse.ui.handlers.HandlerUtil;\r
-import org.simantics.browsing.ui.platform.PropertyPageView;\r
import org.simantics.databoard.Bindings;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.ui.properties.SysdynPropertyPage;\r
+import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.datastructures.Pair;\r
\r
public static final String[] C_EXTENSIONS = {"*.c","*.h","*.a","*.o"};\r
@Override\r
public Object execute(ExecutionEvent event) throws ExecutionException {\r
- IWorkbenchPart part = HandlerUtil.getActivePart(event);\r
- PropertyPageView ppv = (PropertyPageView)part;\r
- SysdynPropertyPage page = (SysdynPropertyPage)ppv.getCurrentPage();\r
- Object o = page.getAdapter(Resource.class);\r
- if (part == null)\r
- return null;\r
- \r
Shell shell = HandlerUtil.getActiveShellChecked(event);\r
Pair<String, String[]> selected = importFiles(shell, "Import...", C_EXTENSIONS);\r
if(selected.second == null || selected.second.length < 1) return null;\r
FileInputStream fis = new FileInputStream(file);\r
fis.read(fileBArray);\r
graph.claimLiteral(externalFile, sr.HasExternalFile, fileBArray, Bindings.BYTE_ARRAY);\r
+ \r
+ FunctionUtils.createExternalFunctionFile(graph, externalFile);\r
} catch (IOException e) {\r
- // TODO Auto-generated catch block\r
e.printStackTrace();\r
}\r
\r
}\r
+ \r
}\r
\r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.Files;\r
+import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.WriteOnlyGraph;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.ResourceNotFoundException;\r
+import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
+import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.graph.representation.Root;\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.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.FunctionUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+\r
+public class ImportFunctionLibrary extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ Resource project = SimanticsUI.getProject().get();\r
+ if(project == null) return null;\r
+\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ final Resource functionLibrary = ResourceAdaptionUtils.toSingleResource(sel);\r
+ if(functionLibrary == null) return null;\r
+ \r
+ Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
+ fd.setText("Import Function Library");\r
+ fd.setFilterPath(Platform.getLocation().toOSString());\r
+ String[] filterExt = {"*.tg"};\r
+ fd.setFilterExtensions(filterExt);\r
+ String selected = fd.open();\r
+ if(selected == null) return null;\r
+\r
+ TransferableGraph1 tg = null;\r
+ try {\r
+ tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class));\r
+ } catch (RuntimeBindingConstructionException e) {\r
+ e.printStackTrace();\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ }\r
+ if(tg == null) return null;\r
+\r
+ \r
+ try {\r
+ Boolean hasSharedOntologies;\r
+ hasSharedOntologies = SimanticsUI.getSession().syncRequest(new Read<Boolean>() {\r
+\r
+ @Override\r
+ public Boolean perform(ReadGraph graph) throws DatabaseException {\r
+ try {\r
+ graph.getResource("http://SharedOntologies");\r
+ } catch (ResourceNotFoundException e) {\r
+ return false;\r
+ } \r
+ return true;\r
+ }\r
+ });\r
+\r
+ if(!hasSharedOntologies) {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ GraphUtils.create2(graph, l0.Library, \r
+ l0.HasName, "SharedOntologies",\r
+ l0.PartOf, graph.getResource("http:/"));\r
+ }\r
+ });\r
+\r
+ }\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ return null;\r
+ }\r
+\r
+ \r
+ SysdynFunctionLibraryImportAdvisor ia = new SysdynFunctionLibraryImportAdvisor(functionLibrary);\r
+ try {\r
+ DefaultPasteHandler.defaultExecute(tg, functionLibrary, ia);\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+ \r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary);\r
+ }\r
+ });\r
+ return null;\r
+ }\r
+ \r
+ private class SysdynFunctionLibraryImportAdvisor extends DefaultPasteImportAdvisor {\r
+\r
+ \r
+ Resource model = null;\r
+ \r
+ public SysdynFunctionLibraryImportAdvisor(Resource library) {\r
+ super(library);\r
+ }\r
+ \r
+ @Override\r
+ public void analyzeType(ReadGraph graph, Root root) throws DatabaseException {\r
+ if(root.type.equals(SysdynResource.URIs.SharedFunctionOntology)) {\r
+ library = null;\r
+ try {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource r = library;\r
+ while(!graph.isInstanceOf(r, sr.SysdynModel) && graph.isInstanceOf(r, l0.Ontology))\r
+ r = graph.getSingleObject(r, l0.PartOf);\r
+ if(graph.isInstanceOf(r, sr.SysdynModel))\r
+ model = r;\r
+ \r
+ library = graph.getResource("http://SharedOntologies");\r
+ } catch (ResourceNotFoundException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public Resource createRoot(WriteOnlyGraph graph, Root root) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+ this.root = graph.newResource();\r
+ graph.claim(library, b.ConsistsOf, b.PartOf, this.root);\r
+ String name = root.name;\r
+ String newName = nameMappings.get(name);\r
+ graph.addLiteral(this.root, b.HasName, b.NameOf, b.String, newName, Bindings.STRING);\r
+ if(model != null && root.type.equals(SysdynResource.URIs.SharedFunctionOntology)) {\r
+ graph.claim(model, b.IsLinkedTo, b.IsLinkedTo_Inverse, this.root);\r
+ }\r
+ return this.root;\r
+\r
+ }\r
+ \r
+ }\r
+\r
+}\r
import org.eclipse.core.commands.ExecutionException;\r
import org.eclipse.jface.viewers.ISelection;\r
import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.manager.FunctionUtils;\r
-import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.AdaptionUtils;\r
\r
\r
ISelection sel = HandlerUtil.getCurrentSelection(event);\r
\r
- FunctionsFolder node = AdaptionUtils.adaptToSingle(sel, FunctionsFolder.class);\r
+ @SuppressWarnings("unchecked")\r
+ AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
if (node == null)\r
return null;\r
\r
- final Resource model = node.data;\r
+ final Resource data = node.data;\r
\r
SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
\r
@Override\r
public void perform(WriteGraph g) throws DatabaseException {\r
Layer0 l0 = Layer0.getInstance(g);\r
- String name = NameUtils.findFreshName(g, "Function", model, l0.ConsistsOf, "%s%d");\r
-\r
SysdynResource sr = SysdynResource.getInstance(g);\r
+\r
+ Resource library = null;\r
+ if(g.isInstanceOf(data, sr.SysdynModel) || g.isInstanceOf(data, l0.Library))\r
+ library = data;\r
+ else if (g.isInstanceOf(data, sr.SysdynModelicaFunction))\r
+ library = g.getPossibleObject(data, l0.PartOf);\r
+ \r
+ if(library == null)\r
+ return;\r
+ \r
+ \r
+ String name = NameUtils.findFreshName(g, "Function", library, l0.ConsistsOf, "%s%d");\r
+\r
GraphUtils.create2(g, sr.SysdynModelicaFunction,\r
l0.HasName, name,\r
l0.HasDescription, "",\r
sr.HasModelicaFunctionCode, "",\r
- l0.PartOf, model);\r
+ l0.PartOf, library);\r
\r
- FunctionUtils.updateFunctionFileForLibrary(g, model);\r
+ FunctionUtils.updateFunctionFileForLibrary(g, library);\r
}\r
});\r
\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\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.DatabaseException;\r
+import org.simantics.db.exception.ResourceNotFoundException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.FunctionUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+\r
+public class NewFunctionLibraryHandler extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ \r
+ @SuppressWarnings("unchecked")\r
+ AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+ if (node == null)\r
+ return null;\r
+\r
+ createLibrary(node.data, false);\r
+ return null;\r
+ }\r
+ \r
+ /**\r
+ * Create function library. Shared libraries are created to root, local libraries to the model. \r
+ * Shared libraries can be used in other models in the project.\r
+ * \r
+ * @param model The initial location of the command\r
+ * @param shared Shared libraries are created to root, local libraries to the model.\r
+ */\r
+ protected void createLibrary(final Resource model, final boolean shared) {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph g) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(g);\r
+ SysdynResource sr = SysdynResource.getInstance(g);\r
+\r
+ if(!(g.isInstanceOf(model, sr.SysdynModel) ||\r
+ g.isInstanceOf(model, sr.SysdynModelicaFunctionLibrary) ||\r
+ g.isInstanceOf(model, sr.SharedFunctionOntology)))\r
+ return;\r
+\r
+ Resource root = model;\r
+\r
+ String name = "FunctionLibrary";\r
+ Resource libraryType = sr.SysdynModelicaFunctionLibrary;\r
+ \r
+ if(shared) {\r
+ \r
+ try {\r
+ root = g.getResource("http://SharedOntologies");\r
+ } catch (ResourceNotFoundException e) {\r
+ root = g.getResource("http:/");\r
+ root = GraphUtils.create2(g, l0.Library, \r
+ l0.HasName, "SharedOntologies",\r
+ l0.PartOf, root);\r
+ }\r
+ \r
+ name = "Shared" + name;\r
+ libraryType = sr.SharedFunctionOntology;\r
+ }\r
+\r
+ name = NameUtils.findFreshName(g, name, root, l0.ConsistsOf, "%s%d");\r
+ \r
+ Resource functionLibrary = GraphUtils.create2(g, libraryType,\r
+ l0.HasName, name,\r
+ l0.HasDescription, "",\r
+ l0.PartOf, root);\r
+ \r
+ if(shared)\r
+ g.claim(model, l0.IsLinkedTo, functionLibrary);\r
+\r
+ FunctionUtils.updateFunctionFileForLibrary(g, functionLibrary);\r
+ }\r
+ });\r
+ }\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.db.Resource;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+\r
+public class NewSharedFunctionLibraryHandler extends NewFunctionLibraryHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ \r
+ @SuppressWarnings("unchecked")\r
+ AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+ if (node == null)\r
+ return null;\r
+\r
+ createLibrary(node.data, true);\r
+ return null;\r
+ }\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.properties;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.layer0.Layer0;\r
+\r
+public class FunctionLibraryTab extends PropertyTabContributorImpl {\r
+\r
+ @Override\r
+ public void createControls(Composite body, IWorkbenchSite site,\r
+ ISessionContext context, WidgetSupport support) {\r
+ Composite composite = new Composite(body, SWT.NONE);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
+ GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite);\r
+\r
+\r
+ TrackedText nameText = new TrackedText(composite, support, SWT.BORDER);\r
+ nameText.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasName));\r
+ nameText.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasName));\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText.getWidget());\r
+\r
+\r
+ TrackedText information = new TrackedText(composite, support, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);\r
+ information.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasDescription));\r
+ information.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasDescription));\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(information.getWidget());\r
+ }\r
+\r
+}\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Write;\r
import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
\r
public class ExternalFileNode extends AbstractNode<Resource> implements IModifiableNode, IDeletableNode {\r
@Override\r
public Modifier getModifier(String columnId) {\r
try {\r
- Resource hasName = Layer0.getInstance(SimanticsUI.getSession()).HasName;\r
+ final Resource hasName = Layer0.getInstance(SimanticsUI.getSession()).HasName;\r
LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data, hasName) {\r
@Override\r
public String isValid(String label) {\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
+ FunctionUtils.removeExternalFunctionFile(g, data);\r
+ g.claimLiteral(data, hasName, label);\r
+ FunctionUtils.createExternalFunctionFile(g, data);\r
+ }\r
+ };\r
+ }\r
};\r
return modifier;\r
} catch (DatabaseException e) {\r
if(function != null) {\r
graph.deny(data, l0.PartOf, function);\r
}\r
+ FunctionUtils.removeExternalFunctionFile(graph, data);\r
}\r
});\r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.utils;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.serialization.Serializer;\r
+import org.simantics.graph.representation.External;\r
+import org.simantics.graph.representation.Identity;\r
+import org.simantics.graph.representation.Internal;\r
+import org.simantics.graph.representation.Root;\r
+import org.simantics.graph.representation.TransferableGraph1;\r
+import org.simantics.graph.representation.Value;\r
+\r
+\r
+/**\r
+ * Transferable graph datatype. \r
+ * See <a href="https://www.simantics.org/wiki/index.php/Graph_exchange_format">specification</a>. \r
+ * @author Hannu Niemistö\r
+ */\r
+public class OldTransferableGraph1 {\r
+ public static Binding BINDING = Bindings.getBindingUnchecked(TransferableGraph1.class);\r
+ public static Serializer SERIALIZER = Bindings.getSerializerUnchecked(BINDING);\r
+ \r
+ public int resourceCount;\r
+ public Identity[] identities; \r
+ public int[] statements;\r
+ public Value[] values; \r
+ \r
+ public OldTransferableGraph1() {\r
+ }\r
+ \r
+ public OldTransferableGraph1(int resourceCount, Identity[] identities,\r
+ int[] statements, Value[] values) {\r
+ this.resourceCount = resourceCount;\r
+ this.identities = identities;\r
+ this.statements = statements;\r
+ this.values = values;\r
+ }\r
+\r
+ public void print() {\r
+ System.out.println("Identities");\r
+ for(Identity id : identities) {\r
+ System.out.print(" " + id.resource + " = ");\r
+ if(id.definition instanceof Root) {\r
+ Root def = (Root)id.definition;\r
+ System.out.println("ROOT(" + def.name + ")");\r
+ }\r
+ else if(id.definition instanceof External) {\r
+ External def = (External)id.definition;\r
+ System.out.println("EXTERNAL(" + def.parent + ", " + def.name + ")");\r
+ }\r
+ else if(id.definition instanceof Internal) {\r
+ Internal def = (Internal)id.definition;\r
+ System.out.println("INTERNAL(" + def.parent + ", " + def.name + ")");\r
+ }\r
+ }\r
+ System.out.println("Statements:");\r
+ for(int i=0;i<statements.length;i+=4)\r
+ System.out.println(" " + \r
+ statements[i] + " " +\r
+ statements[i+1] + " " +\r
+ statements[i+2] + " " +\r
+ statements[i+3]\r
+ );\r
+ }\r
+}\r
org.simantics.sysdyn.representation,
org.simantics.sysdyn.representation.visitors,
org.simantics.sysdyn.simulation,
- org.simantics.sysdyn.tableParser
+ org.simantics.sysdyn.tableParser,
+ org.simantics.sysdyn.adapter
Bundle-Activator: org.simantics.sysdyn.Activator
Bundle-ActivationPolicy: lazy
Import-Package: org.eclipse.ui
<adapter uri="http://www.simantics.org/Sysdyn-1.0/Variable"\r
contextClass="org.simantics.db.layer0.variable.Variable"\r
adapterClass="org.simantics.sysdyn.adapter.ChildVariableAdapter"/>\r
+ <adapter uri="http://www.simantics.org/Sysdyn-1.0/Module"\r
+ contextClass="org.simantics.db.layer0.variable.Variable"\r
+ adapterClass="org.simantics.sysdyn.adapter.ChildVariableAdapter"/>\r
+ \r
</target>\r
\r
</adapters>
\ No newline at end of file
\r
import java.io.File;\r
import java.io.FileNotFoundException;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
import java.io.PrintStream;\r
import java.util.ArrayList;\r
import java.util.Collection;\r
import java.util.Map;\r
import java.util.Set;\r
\r
+import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.Simantics;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.scl.runtime.function.Function;\r
import org.simantics.simulation.ontology.SimulationResource;\r
final ArrayList<String> paths = new ArrayList<String>();\r
\r
try {\r
- model.session.syncRequest(new ReadRequest() {\r
+ Simantics.getSession().syncRequest(new ReadRequest() {\r
\r
@Override\r
public void run(ReadGraph graph) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
- Layer0 l0 = Layer0.getInstance(graph);\r
SimulationResource simu = SimulationResource.getInstance(graph);\r
\r
Set<Resource> parents = getParents(graph, model);\r
for(Resource parent : parents) {\r
- Resource partof = graph.getPossibleObject(parent, l0.PartOf);\r
if(graph.isInstanceOf(parent, sr.SysdynModel)) {\r
Resource configuration = graph.getPossibleObject(parent, simu.HasConfiguration);\r
- if(configuration.equals(model.configurationResource)) {\r
+ if(configuration.equals(model.getConfigurationResource())) {\r
String parentName = NameUtils.getSafeName(graph, parent);\r
paths.add(parentName + "_functions.mo");\r
}\r
- } else if (graph.isInstanceOf(partof, sr.SysdynModel)) {\r
- // TODO\r
} else {\r
String libraryname = NameUtils.getSafeName(graph, parent);\r
paths.add("..\\\\..\\\\libraries\\\\functions\\\\" + libraryname + ".mo");\r
\r
private static Set<Resource> getParents(ReadGraph graph, SysdynModel model) throws DatabaseException{\r
HashSet<Resource> parents = new HashSet<Resource>();\r
+ HashSet<Resource> checked = new HashSet<Resource>();\r
+ ArrayList<Resource> toCheck = new ArrayList<Resource>();\r
\r
Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
SimulationResource simu = SimulationResource.getInstance(graph);\r
- Resource modelResource = graph.getPossibleObject(model.configurationResource, simu.IsConfigurationOf);\r
+ Resource modelResource = graph.getPossibleObject(model.getConfigurationResource(), simu.IsConfigurationOf);\r
+ \r
+ \r
+ // add model to parents and all the model libraries to checked\r
+ if(!graph.syncRequest(new ObjectsWithType(modelResource, l0.ConsistsOf, sr.SysdynModelicaFunction)).isEmpty() ||\r
+ !graph.syncRequest(new ObjectsWithType(modelResource, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)).isEmpty()) {\r
+ parents.add(modelResource);\r
+ toCheck.clear();\r
+ toCheck.add(modelResource);\r
+ while(!toCheck.isEmpty()){\r
+ Resource checkedLibrary = toCheck.get(0);\r
+ checked.add(checkedLibrary);\r
+ toCheck.addAll(graph.syncRequest(new ObjectsWithType(checkedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)));\r
+ toCheck.remove(checkedLibrary);\r
+ }\r
+ }\r
+ \r
+ // add all linked function ontologies to parents and their children ontologies to checked \r
+ Function index = graph.adapt(l0.Dependencies, Function.class);\r
+ Collection<Map<String, Object>> results = (Collection<Map<String, Object>>)index.apply(graph, modelResource, "Types:SharedFunctionOntology");\r
+ for(Map<String, Object> r : results) {\r
+ Resource sharedLibrary = (Resource)r.get("Resource");\r
+ if(sharedLibrary == null)\r
+ continue;\r
+ if(graph.syncRequest(new ObjectsWithType(sharedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunction)).isEmpty() &&\r
+ graph.syncRequest(new ObjectsWithType(sharedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)).isEmpty())\r
+ continue;\r
+ \r
+ parents.add(sharedLibrary);\r
+ toCheck.clear();\r
+ toCheck.add(sharedLibrary);\r
+ while(!toCheck.isEmpty()){\r
+ Resource checkedLibrary = toCheck.get(0);\r
+ checked.add(checkedLibrary);\r
+ toCheck.addAll(graph.syncRequest(new ObjectsWithType(checkedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)));\r
+ toCheck.remove(checkedLibrary);\r
+ }\r
+ }\r
+ \r
+ // it is assumed that only built-in function libraries remain\r
if(modelResource != null) {\r
- Function index = graph.adapt(l0.Dependencies, Function.class);\r
- Collection<Map<String, Object>> results = (Collection<Map<String, Object>>)index.apply(graph, modelResource, "Types:SysdynModelicaFunction");\r
+ index = graph.adapt(l0.Dependencies, Function.class);\r
+ results = (Collection<Map<String, Object>>)index.apply(graph, modelResource, "Types:SysdynModelicaFunctionLibrary");\r
for(Map<String, Object> r : results) {\r
- Resource function = (Resource)r.get("Resource");\r
- if(function != null) {\r
- parents.add(graph.getSingleObject(function, l0.PartOf));\r
+ Resource library = (Resource)r.get("Resource");\r
+ if(library != null && !checked.contains(library)) {\r
+ \r
+ while(!graph.isInstanceOf(library, sr.SysdynModel) && !graph.isInstanceOf(library, l0.Ontology)) {\r
+ library = graph.getPossibleObject(library, l0.PartOf);\r
+ }\r
+ \r
+ if(graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunction)).isEmpty() &&\r
+ graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)).isEmpty())\r
+ continue;\r
+ \r
+ parents.add(library);\r
+ \r
+ toCheck.clear();\r
+ toCheck.add(library);\r
+ while(!toCheck.isEmpty()){\r
+ Resource checkedLibrary = toCheck.get(0);\r
+ checked.add(checkedLibrary);\r
+ toCheck.addAll(graph.syncRequest(new ObjectsWithType(checkedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)));\r
+ toCheck.remove(checkedLibrary);\r
+ }\r
}\r
}\r
}\r
- \r
return parents;\r
\r
}\r
if(graph.isInstanceOf(parent, sr.SysdynModel)) {\r
String parentName = NameUtils.getSafeName(graph, parent);\r
File scriptFile = new File(model.getSimulationDir(), parentName + "_functions.mo");\r
- updateFunctionFile(graph, parent, scriptFile);\r
+ updateFunctionFile(graph, parent, scriptFile, false);\r
} else {\r
updateFunctionFileForLibrary(graph, parent);\r
}\r
return;\r
}\r
\r
+ private static File getDir(ReadGraph graph, Resource resource) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ \r
+ Resource library = resource;\r
+ while(!graph.isInstanceOf(library, sr.SysdynModel) && !graph.isInstanceOf(library, l0.Ontology)) {\r
+ library = graph.getSingleObject(resource, l0.PartOf);\r
+ }\r
+ \r
+ File dir = null;\r
+ \r
+ if(graph.isInstanceOf(library, sr.SysdynModel)) {\r
+ SimulationResource simu = SimulationResource.getInstance(graph);\r
+ Resource configuration = graph.getSingleObject(library, simu.HasConfiguration);\r
+ SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
+ SysdynModel model = smm.getModel(graph, configuration);\r
+ dir = model.getSimulationDir();\r
+ } else {\r
+ File librariesDir = Activator.getBundleContext().getDataFile("libraries");\r
+ if (!librariesDir.exists()) {\r
+ librariesDir.mkdir();\r
+ }\r
+ dir = new File(librariesDir, "functions");\r
+ if (!dir.exists()) {\r
+ dir.mkdir();\r
+ }\r
+ }\r
+ return dir;\r
+ }\r
+\r
+ public static void createExternalFunctionFile(ReadGraph graph, Resource externalFunction) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+ Resource function = graph.getSingleObject(externalFunction, l0.PartOf);\r
+ File dir = getDir(graph, function);\r
+\r
+ try {\r
+ String name = NameUtils.getSafeName(graph, externalFunction);\r
+ if(name.endsWith(".o") || name.endsWith(".a")) {\r
+ FileOutputStream fos = new FileOutputStream(dir + "\\" + name);\r
+ byte[] fileBArray = graph.getPossibleRelatedValue(externalFunction, sr.HasExternalFile, Bindings.BYTE_ARRAY);\r
+ fos.write(fileBArray);\r
+ fos.close();\r
+ }\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ public static void removeExternalFunctionFile(ReadGraph graph, Resource externalFunction) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+ Resource function = graph.getSingleObject(externalFunction, l0.PartOf);\r
+ File dir = getDir(graph, function);\r
+ String name = NameUtils.getSafeName(graph, externalFunction);\r
+ File file = new File(dir, name);\r
+ file.delete();\r
+ }\r
+\r
+ \r
+ \r
public static void updateFunctionFileForLibrary(ReadGraph graph, Resource library) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ \r
+ while(!graph.isInstanceOf(library, sr.SysdynModel) && !graph.isInstanceOf(library, l0.Ontology)) {\r
+ library = graph.getSingleObject(library, l0.PartOf);\r
+ }\r
+ \r
if(graph.isInstanceOf(library, sr.SysdynModel)) {\r
SimulationResource simu = SimulationResource.getInstance(graph);\r
Resource configuration = graph.getSingleObject(library, simu.HasConfiguration);\r
SysdynModel model = smm.getModel(graph, configuration);\r
updateFunctionFilesForModel(graph, model);\r
} else {\r
+ \r
File librariesDir = Activator.getBundleContext().getDataFile("libraries");\r
if (!librariesDir.exists()) {\r
librariesDir.mkdir();\r
}\r
String parentName = NameUtils.getSafeName(graph, library);\r
File scriptFile = new File(dir, parentName + ".mo");\r
- updateFunctionFile(graph, library, scriptFile);\r
+ \r
+ Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.0");\r
+\r
+ if(library.equals(sysdyn)) {\r
+ updateFunctionFile(graph, library, scriptFile, true);\r
+ } else {\r
+ updateFunctionFile(graph, library, scriptFile, false);\r
+ }\r
}\r
\r
\r
}\r
\r
- private static void updateFunctionFile(ReadGraph graph, Resource library, File scriptFile) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- \r
+ private static void updateFunctionFile(ReadGraph graph, Resource library, File scriptFile, boolean builtIn) throws DatabaseException {\r
PrintStream s;\r
try {\r
s = new PrintStream(scriptFile);\r
e.printStackTrace();\r
return;\r
}\r
-\r
+ \r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ String name = NameUtils.getSafeName(graph, library);\r
+ if(!builtIn && !graph.isInstanceOf(library, sr.SysdynModel))\r
+ s.println("package " + name);\r
+ writeLibrary(graph, library, s, builtIn);\r
+ if(!builtIn && !graph.isInstanceOf(library, sr.SysdynModel))\r
+ s.println("end " + name + ";\n");\r
+ \r
+ s.close();\r
+ }\r
+ \r
+ private static void writeLibrary(ReadGraph graph, Resource library, PrintStream stream, boolean builtIn) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ writeLibraryFunctions(graph, library, stream);\r
+ for(Resource sublibrary : graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) {\r
+ String name = NameUtils.getSafeName(graph, sublibrary);\r
+ if(!builtIn)\r
+ stream.println("encapsulated package " + name);\r
+ writeLibrary(graph, sublibrary, stream, builtIn);\r
+ if(!builtIn)\r
+ stream.println("end " + name + ";\n");\r
+ }\r
+ }\r
+ \r
+ private static void writeLibraryFunctions(ReadGraph graph, Resource library, PrintStream stream) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
for(Resource function : graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunction))) {\r
String name = NameUtils.getSafeName(graph, function);\r
String functionCode = graph.getRelatedValue(function, sr.HasModelicaFunctionCode);\r
- s.println("function " + name);\r
- s.println(functionCode);\r
- s.println("end " + name + ";\n");\r
+ stream.println("function " + name);\r
+ stream.println(functionCode);\r
+ stream.println("end " + name + ";\n");\r
+ for(Resource externalFunction : graph.syncRequest(new ObjectsWithType(function, l0.ConsistsOf, sr.ExternalFunctionFile))) {\r
+ createExternalFunctionFile(graph, externalFunction);\r
+ }\r
}\r
- s.close();\r
}\r
}\r
import org.simantics.db.Session;\r
import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
+import org.simantics.db.exception.ServiceException;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.modelica.IModelicaMonitor;\r
import org.simantics.modelica.ModelicaException;\r
*/\r
public class SysdynModel implements IMappingListener, IModel {\r
\r
- Session session;\r
+ private Session session;\r
\r
- IMapping mapping;\r
+ private IMapping mapping;\r
\r
- Resource configurationResource;\r
- Configuration configuration;\r
+ private Resource configurationResource;\r
+ private Resource modelResource;\r
+ \r
+ private Configuration configuration;\r
\r
- Set<Configuration> modules = new HashSet<Configuration>();\r
+ private Set<Configuration> modules = new HashSet<Configuration>();\r
\r
- Process process;\r
- boolean canceled;\r
- SimulationResult result;\r
- SysdynResult sysdynResult;\r
+ private Process process;\r
+ private boolean canceled;\r
+ private SimulationResult result;\r
+ private SysdynResult sysdynResult;\r
\r
- CopyOnWriteArrayList<Runnable> modificationListeners =\r
+ private CopyOnWriteArrayList<Runnable> modificationListeners =\r
new CopyOnWriteArrayList<Runnable>();\r
- CopyOnWriteArrayList<Runnable> resultListeners =\r
+ private CopyOnWriteArrayList<Runnable> resultListeners =\r
new CopyOnWriteArrayList<Runnable>();\r
\r
@SuppressWarnings("rawtypes")\r
- Map<Class, Object> services = new HashMap<Class, Object>();\r
+ private Map<Class, Object> services = new HashMap<Class, Object>();\r
\r
- String previousModelStructure;\r
- HashMap<String, String> previousImportantInits = new HashMap<String, String>();\r
+ private String previousModelStructure;\r
+ private HashMap<String, String> previousImportantInits = new HashMap<String, String>();\r
\r
- File simulationDir;\r
+ private File simulationDir;\r
\r
void readModules(ReadGraph graph, Resource configResource, Set<Resource> result) throws DatabaseException {\r
\r
sysdynResult.setResult(new SimulationResult());\r
\r
previousModelStructure = "";\r
-\r
- File modelsDir = Activator.getBundleContext().getDataFile("models");\r
- String configName = configuration.getName();\r
- List<String> files = Arrays.asList(modelsDir.list());\r
- if (files.contains(configName)) {\r
- int i = 2;\r
- while (files.contains(configName + "_" + i)){\r
- i++;\r
- }\r
- configName += "_" + i;\r
- }\r
-\r
- simulationDir = Activator.getBundleContext().getDataFile("models/" + configName);\r
- if (!simulationDir.exists()) {\r
- simulationDir.mkdir();\r
- }\r
- \r
- try {\r
- FunctionUtils.updateFunctionFilesForModel(g, this);\r
- } catch (DatabaseException e) {\r
- System.err.println("Error creating functions");\r
- e.printStackTrace();\r
- }\r
- \r
}\r
\r
\r
/*\r
* some dummy(?) stuff for experiments\r
*/\r
- public SysdynModel(Resource configurationResource) {\r
- this.configurationResource = configurationResource;\r
+ public SysdynModel(Resource modelResource) {\r
+ this.modelResource = modelResource;\r
}\r
\r
public synchronized void simulate(IModelicaMonitor monitor, final IProgressMonitor progressMonitor, final Experiment experiment) throws IOException {\r
}\r
\r
final SimulationLocation simulationLocation = ModelicaManager.createInputFiles(\r
- simulationDir,\r
+ getSimulationDir(),\r
configuration.getName(),\r
writer.toString(),\r
inits,\r
public Configuration getConfiguration() {\r
return configuration;\r
}\r
+ \r
+ public Resource getConfigurationResource() {\r
+ return configurationResource;\r
+ }\r
\r
public IMapping getMapping() {\r
return mapping;\r
\r
@Override\r
public IExperiment loadExperiment(ReadGraph g, Resource experiment, IExperimentActivationListener listener) {\r
- SysdynExperiment exp = new SysdynExperiment(experiment, configurationResource);\r
+ \r
+ // Not good. IModel pushes only modelResource and it is assumed that\r
+ // SysdynModel is based on configuration\r
+ if(configurationResource == null && modelResource != null) {\r
+ SimulationResource simu = SimulationResource.getInstance(g);\r
+ try {\r
+ configurationResource = g.getPossibleObject(modelResource, simu.HasConfiguration);\r
+ } catch (ManyObjectsForFunctionalRelationException e) {\r
+ e.printStackTrace();\r
+ } catch (ServiceException e) {\r
+ e.printStackTrace();\r
+ } \r
+ }\r
+\r
+ SysdynExperiment exp = new SysdynExperiment(experiment, modelResource);\r
try {\r
exp.init(g);\r
ExperimentRuns.createRun(g.getSession(), experiment, exp, listener, null);\r
}\r
\r
public File getSimulationDir() {\r
+ if(simulationDir == null) {\r
+ File modelsDir = Activator.getBundleContext().getDataFile("models");\r
+ String configName = configuration.getName();\r
+ List<String> files = Arrays.asList(modelsDir.list());\r
+ if (files.contains(configName)) {\r
+ int i = 2;\r
+ while (files.contains(configName + "_" + i)){\r
+ i++;\r
+ }\r
+ configName += "_" + i;\r
+ }\r
+\r
+ simulationDir = Activator.getBundleContext().getDataFile("models/" + configName);\r
+ if (!simulationDir.exists()) {\r
+ simulationDir.mkdir();\r
+ }\r
+ }\r
return simulationDir;\r
}\r
\r
import org.simantics.db.Session;\r
import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
\r
/**\r
* Manages system dynamic models.\r
\r
@Override\r
public void run(ReadGraph graph) throws DatabaseException {\r
- models.put(resource, new SysdynModel(graph, resource));\r
- \r
+ SysdynModel model = new SysdynModel(graph, resource);\r
+ models.put(resource, model);\r
+ FunctionUtils.updateFunctionFilesForModel(graph, model);\r
}\r
});\r
} catch (DatabaseException e) {\r
if(model == null) {\r
model = new SysdynModel(g, resource);\r
models.put(resource, model);\r
+ try {\r
+ SimulationResource simu = SimulationResource.getInstance(g);\r
+ Resource modelResource = g.getPossibleObject(model.getConfigurationResource(), simu.IsConfigurationOf);\r
+ if(modelResource != null)\r
+ FunctionUtils.updateFunctionFilesForModel(g, model);\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
}\r
return model;\r
}\r