//#####################################################################
// Variables
//#####################################################################
-
-SYSDYN.Variable <T STR.Component
+SYSDYN.Component <T STR.Component
+SYSDYN.Variable <T SYSDYN.Component
>-- SYSDYN.Variable.type --> L0.String <R L0.HasProperty : L0.FunctionalRelation
>-- SYSDYN.Variable.expressions --> SYSDYN.Expressions <R L0.IsComposedOf : L0.FunctionalRelation
>-- SYSDYN.Variable.expressionList --> L0.List <R L0.IsComposedOf : L0.FunctionalRelation
// Modules
//#####################################################################
-SYSDYN.Module <T STR.Component
+SYSDYN.Module <T SYSDYN.Component
>-- SYSDYN.Module.redeclaration --> SYSDYN.Redeclaration <R L0.IsComposedOf
>-- SYSDYN.Module.parameterOverride --> SYSDYN.Module.ParameterOverride <R L0.IsComposedOf
@L0.assert DIA.Terminal.AllowedDirections 0
//#####################################################################
-SYSDYN.Valve <T STR.Component
+SYSDYN.Valve
@MOD.connection SYSDYN.Variable.isTailOf
@MOD.connection SYSDYN.Variable.isHeadOf
@MOD.terminal SYSDYN.ValveSymbol SYSDYN.IsTailOfTerminal
//#####################################################################
-SYSDYN.Auxiliary <T STR.Component
+SYSDYN.Auxiliary
@MOD.connection SYSDYN.Variable.isTailOf
@MOD.connection SYSDYN.Variable.isHeadOf
@MOD.terminal SYSDYN.AuxiliarySymbol SYSDYN.IsTailOfTerminal
//#####################################################################
-SYSDYN.Cloud <T STR.Component
+SYSDYN.Cloud
@MOD.connection SYSDYN.Variable.isTailOf
@MOD.connection SYSDYN.Variable.isHeadOf
@MOD.terminal SYSDYN.CloudSymbol SYSDYN.IsTailOfTerminal
//#####################################################################
-SYSDYN.Input <T STR.Component
+SYSDYN.Input
@MOD.connection SYSDYN.Variable.isTailOf
@MOD.connection SYSDYN.Variable.isHeadOf
@MOD.terminal SYSDYN.StockSymbol SYSDYN.IsTailOfTerminal
//#####################################################################
-SYSDYN.Shadow <T STR.Component
+SYSDYN.Shadow
@MOD.connection SYSDYN.Variable.isTailOf
@MOD.connection SYSDYN.Variable.isHeadOf
L0X = <http://www.simantics.org/Layer0X-1.1>\r
ISSUE = <http://www.simantics.org/Issue-1.2>\r
SYSDYN = <http://www.simantics.org/Sysdyn-1.1>\r
+STR = <http://www.simantics.org/Structural-1.2>\r
\r
VALIDATIONS = SYSDYN.Validations : L0.Library\r
\r
VALIDATIONS.Enumerations : L0.Library\r
VALIDATIONS.Enumerations.enumerationIndexValidator : L0.Function\r
\r
-// ENUMERATIONS\r
+// UNITS\r
VALIDATIONS.Units : L0.Library\r
VALIDATIONS.Units.unitValidator : L0.Function\r
+VALIDATIONS.Units.moduleInterfaceExtension : L0.Function\r
+\r
+\r
\r
SYSDYN.Variable\r
@VALIDATIONS.constraint\r
@L0.assert L0.HasName "MissingDependencyConnectionsIssueSource"\r
VALIDATIONS.Dependencies.missingDependencyValidator \r
VALIDATIONS.Functions.baseRealizationFunction \r
- \r
-SYSDYN.IndependentVariable\r
+\r
+SYSDYN.Component\r
@VALIDATIONS.listeningConstraint\r
VALIDATIONS.UnitConstraint\r
VALIDATIONS.Units.UnitIssueSource\r
@L0.assert L0.HasName "UnitIssueSource"\r
+ L0.Asserts _ : L0.Assertion\r
+ L0.HasPredicate ISSUE.Sources.DependencyTracker.HasExtension\r
+ L0.HasObject VALIDATIONS.Units.moduleInterfaceExtension\r
VALIDATIONS.Units.unitValidator \r
VALIDATIONS.Functions.baseRealizationFunction\r
- \r
+\r
VALIDATIONS.ExpressionIssue\r
@VALIDATIONS.issue\r
ISSUE.Severity.Error\r
L0.HasValueType "String"\r
VALIDATIONS.Functions.path \r
\r
+VALIDATIONS.ModuleInputUnitWarning\r
+ @VALIDATIONS.issue\r
+ ISSUE.Severity.Warning\r
+ VALIDATIONS.Units.moduleInputUnitWarningDescription : L0.Function\r
+ L0.HasValueType "String"\r
+ VALIDATIONS.Functions.path \r
+ \r
+VALIDATIONS.ModuleOutputUnitWarning\r
+ @VALIDATIONS.issue\r
+ ISSUE.Severity.Warning\r
+ VALIDATIONS.Units.moduleOutputUnitWarningDescription : L0.Function\r
+ L0.HasValueType "String"\r
+ VALIDATIONS.Functions.path \r
\r
// IssueSource template\r
VALIDATIONS.constraint : L0.Template\r
L0.Asserts _ : L0.Assertion\r
L0.HasPredicate ISSUE.Sources.DependencyTracker.HasBaseFunction\r
L0.HasObject %baseFunction \r
- \r
\r
VALIDATIONS.listeningConstraint : L0.Template\r
@template %type %constraint %source %validator %baseFunction\r
public final Resource Charts_SensitivityPlot;\r
public final Resource Cloud;\r
public final Resource CloudSymbol;\r
+ public final Resource Component;\r
public final Resource Configuration;\r
public final Resource ConfigurationDiagram;\r
public final Resource ConfigurationDiagramTemplate;\r
public final Resource Validations_Issue_stringContexts_Inverse;\r
public final Resource Validations_MissingDependencyConstraint;\r
public final Resource Validations_MissingLinkIssue;\r
+ public final Resource Validations_ModuleInputUnitWarning;\r
+ public final Resource Validations_ModuleOutputUnitWarning;\r
public final Resource Validations_NoSuchVariableIssue;\r
public final Resource Validations_RangeIssue;\r
public final Resource Validations_RangeWarning;\r
public final Resource Validations_UnitWarning;\r
public final Resource Validations_Units;\r
public final Resource Validations_Units_UnitIssueSource;\r
+ public final Resource Validations_Units_moduleInputUnitWarningDescription;\r
+ public final Resource Validations_Units_moduleInterfaceExtension;\r
+ public final Resource Validations_Units_moduleOutputUnitWarningDescription;\r
public final Resource Validations_Units_unitValidator;\r
public final Resource Validations_Units_unitWarningDescription;\r
public final Resource Validations_UnusedDependencyIssue;\r
public static final String Charts_SensitivityPlot = "http://www.simantics.org/Sysdyn-1.1/Charts/SensitivityPlot";\r
public static final String Cloud = "http://www.simantics.org/Sysdyn-1.1/Cloud";\r
public static final String CloudSymbol = "http://www.simantics.org/Sysdyn-1.1/CloudSymbol";\r
+ public static final String Component = "http://www.simantics.org/Sysdyn-1.1/Component";\r
public static final String Configuration = "http://www.simantics.org/Sysdyn-1.1/Configuration";\r
public static final String ConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.1/ConfigurationDiagram";\r
public static final String ConfigurationDiagramTemplate = "http://www.simantics.org/Sysdyn-1.1/ConfigurationDiagramTemplate";\r
public static final String Validations_Issue_stringContexts_Inverse = "http://www.simantics.org/Sysdyn-1.1/Validations/Issue/stringContexts/Inverse";\r
public static final String Validations_MissingDependencyConstraint = "http://www.simantics.org/Sysdyn-1.1/Validations/MissingDependencyConstraint";\r
public static final String Validations_MissingLinkIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/MissingLinkIssue";\r
+ public static final String Validations_ModuleInputUnitWarning = "http://www.simantics.org/Sysdyn-1.1/Validations/ModuleInputUnitWarning";\r
+ public static final String Validations_ModuleOutputUnitWarning = "http://www.simantics.org/Sysdyn-1.1/Validations/ModuleOutputUnitWarning";\r
public static final String Validations_NoSuchVariableIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/NoSuchVariableIssue";\r
public static final String Validations_RangeIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/RangeIssue";\r
public static final String Validations_RangeWarning = "http://www.simantics.org/Sysdyn-1.1/Validations/RangeWarning";\r
public static final String Validations_UnitWarning = "http://www.simantics.org/Sysdyn-1.1/Validations/UnitWarning";\r
public static final String Validations_Units = "http://www.simantics.org/Sysdyn-1.1/Validations/Units";\r
public static final String Validations_Units_UnitIssueSource = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/UnitIssueSource";\r
+ public static final String Validations_Units_moduleInputUnitWarningDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/moduleInputUnitWarningDescription";\r
+ public static final String Validations_Units_moduleInterfaceExtension = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/moduleInterfaceExtension";\r
+ public static final String Validations_Units_moduleOutputUnitWarningDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/moduleOutputUnitWarningDescription";\r
public static final String Validations_Units_unitValidator = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/unitValidator";\r
public static final String Validations_Units_unitWarningDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/unitWarningDescription";\r
public static final String Validations_UnusedDependencyIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/UnusedDependencyIssue";\r
Charts_SensitivityPlot = getResourceOrNull(graph, URIs.Charts_SensitivityPlot);\r
Cloud = getResourceOrNull(graph, URIs.Cloud);\r
CloudSymbol = getResourceOrNull(graph, URIs.CloudSymbol);\r
+ Component = getResourceOrNull(graph, URIs.Component);\r
Configuration = getResourceOrNull(graph, URIs.Configuration);\r
ConfigurationDiagram = getResourceOrNull(graph, URIs.ConfigurationDiagram);\r
ConfigurationDiagramTemplate = getResourceOrNull(graph, URIs.ConfigurationDiagramTemplate);\r
Validations_Issue_stringContexts_Inverse = getResourceOrNull(graph, URIs.Validations_Issue_stringContexts_Inverse);\r
Validations_MissingDependencyConstraint = getResourceOrNull(graph, URIs.Validations_MissingDependencyConstraint);\r
Validations_MissingLinkIssue = getResourceOrNull(graph, URIs.Validations_MissingLinkIssue);\r
+ Validations_ModuleInputUnitWarning = getResourceOrNull(graph, URIs.Validations_ModuleInputUnitWarning);\r
+ Validations_ModuleOutputUnitWarning = getResourceOrNull(graph, URIs.Validations_ModuleOutputUnitWarning);\r
Validations_NoSuchVariableIssue = getResourceOrNull(graph, URIs.Validations_NoSuchVariableIssue);\r
Validations_RangeIssue = getResourceOrNull(graph, URIs.Validations_RangeIssue);\r
Validations_RangeWarning = getResourceOrNull(graph, URIs.Validations_RangeWarning);\r
Validations_UnitWarning = getResourceOrNull(graph, URIs.Validations_UnitWarning);\r
Validations_Units = getResourceOrNull(graph, URIs.Validations_Units);\r
Validations_Units_UnitIssueSource = getResourceOrNull(graph, URIs.Validations_Units_UnitIssueSource);\r
+ Validations_Units_moduleInputUnitWarningDescription = getResourceOrNull(graph, URIs.Validations_Units_moduleInputUnitWarningDescription);\r
+ Validations_Units_moduleInterfaceExtension = getResourceOrNull(graph, URIs.Validations_Units_moduleInterfaceExtension);\r
+ Validations_Units_moduleOutputUnitWarningDescription = getResourceOrNull(graph, URIs.Validations_Units_moduleOutputUnitWarningDescription);\r
Validations_Units_unitValidator = getResourceOrNull(graph, URIs.Validations_Units_unitValidator);\r
Validations_Units_unitWarningDescription = getResourceOrNull(graph, URIs.Validations_Units_unitWarningDescription);\r
Validations_UnusedDependencyIssue = getResourceOrNull(graph, URIs.Validations_UnusedDependencyIssue);\r
org.simantics.scenegraph.swing;bundle-version="1.0.0",
org.eclipse.nebula.widgets.tablecombo;bundle-version="1.0.0",
org.simantics.fmu;bundle-version="1.0.0",
- org.simantics.jfreechart;bundle-version="1.0.0"
+ org.simantics.jfreechart;bundle-version="1.0.0",
+ org.simantics.db.indexing;bundle-version="1.1.0"
Bundle-Activator: org.simantics.sysdyn.ui.Activator
Bundle-ActivationPolicy: lazy
Export-Package: org.simantics.sysdyn.ui.browser.nodes
list = graph.getPossibleObject(issueResource, ISSUE.Issue_HasContexts);\r
List<Resource> contexts = ListUtils.toList(graph, list);\r
if(!contexts.isEmpty()) {\r
- if(ListUtils.toList(graph, list).get(0).equals(component)) {\r
+ if(ListUtils.toList(graph, list).subList(0, 1).contains(component)) {\r
return new IssueResult(severity, transform);\r
}\r
}\r
import org.simantics.db.Resource;\r
import org.simantics.db.Session;\r
import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.changeset.GenericChangeListener;\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.layer0.adapter.RuntimeValuations;\r
import org.simantics.db.layer0.adapter.TrendVariable;\r
-import org.simantics.db.layer0.genericrelation.DependenciesRelation.DependencyChangesRequest;\r
-import org.simantics.db.layer0.genericrelation.DependencyChanges;\r
import org.simantics.db.layer0.service.ActivationManager;\r
import org.simantics.db.request.Read;\r
import org.simantics.db.service.GraphChangeListenerSupport;\r
import org.simantics.db.service.VirtualGraphSupport;\r
+import org.simantics.fmu.FMUControlJNI;\r
import org.simantics.issues.common.IssueUtils;\r
import org.simantics.layer0.Layer0;\r
-import org.simantics.fmu.FMUControlJNI;\r
+import org.simantics.modeling.ModelingUtils;\r
import org.simantics.modeling.services.CaseInsensitiveComponentNamingStrategy2;\r
import org.simantics.modeling.services.ComponentNamingStrategy;\r
import org.simantics.project.IProject;\r
\r
public void onActivated(final ReadGraph graph, final IProject project) throws DatabaseException {\r
\r
- GraphChangeListenerSupport changeSupport = graph.getService(GraphChangeListenerSupport.class);\r
- changeSupport.addMetadataListener(new GenericChangeListener<DependencyChangesRequest, DependencyChanges>() {\r
-\r
- @Override\r
- public void onEvent(ReadGraph graph, DependencyChanges event) throws DatabaseException {\r
-\r
- WriteGraph w = (WriteGraph)graph;\r
- w.addMetadata(event);\r
-\r
- }\r
-\r
- });\r
+// GraphChangeListenerSupport changeSupport = graph.getService(GraphChangeListenerSupport.class);\r
+// changeSupport.addMetadataListener(new GenericChangeListener<DependencyChangesRequest, DependencyChanges>() {\r
+//\r
+// @Override\r
+// public void onEvent(ReadGraph graph, DependencyChanges event) throws DatabaseException {\r
+//\r
+// WriteGraph w = (WriteGraph)graph;\r
+// w.addMetadata(event);\r
+//\r
+// }\r
+//\r
+// });\r
\r
IssueUtils.listenActiveProjectIssueSources(graph, project.get());\r
+ \r
+ ModelingUtils.trackDependencies(graph);\r
+\r
\r
}\r
\r
new PossibleObjectWithType(model, \r
Layer0X.getInstance(graph).Activates, \r
SysdynResource.getInstance(graph).Validations_Units_UnitIssueSource));\r
+ if(unitIssueSource == null)\r
+ return false;\r
+ \r
Boolean result = graph.getPossibleRelatedValue(unitIssueSource, IssueResource.getInstance(graph).IssueSource_active, Bindings.BOOLEAN);\r
return Boolean.TRUE.equals(result);\r
}\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.properties.widgets.IsOutputWidget;\r
+import org.simantics.sysdyn.ui.properties.widgets.UnitComboWidget;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier;\r
defaultValue.setInputValidator(new DoubleValidator());\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(defaultValue.getWidget());\r
\r
+\r
+ Composite unitComposite = new Composite(composite, SWT.NONE);\r
+ GridDataFactory.fillDefaults().applyTo(unitComposite);\r
+ GridLayoutFactory.fillDefaults().numColumns(2).applyTo(unitComposite);\r
+ \r
+ label = new Label(unitComposite, SWT.NULL );\r
+ label.setText("Unit:");\r
+ GridDataFactory.fillDefaults().applyTo(label);\r
+\r
+ TrackedCombo unitCombo = new UnitComboWidget(unitComposite, support, SWT.DROP_DOWN | SWT.BORDER);\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(unitCombo.getWidget());\r
+ \r
+ \r
Composite variabilityComposite = new Composite(composite, SWT.NONE);\r
GridDataFactory.fillDefaults().grab(false, true).applyTo(variabilityComposite);\r
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(variabilityComposite);\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 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
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.properties.widgets;\r
+\r
+import java.util.Collection;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedCombo;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\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.SysdynModel;\r
+import org.simantics.sysdyn.manager.SysdynModelManager;\r
+\r
+public class UnitComboWidget extends TrackedCombo {\r
+\r
+ public UnitComboWidget(Composite parent, WidgetSupport support, int style) {\r
+ super(parent, support, style);\r
+ \r
+ \r
+ // Add all units used in the model to the unit combo\r
+ setItemFactory(new ReadFactoryImpl<Resource, Map<String,Object>>() {\r
+\r
+ @Override\r
+ public Map<String, Object> perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+ Map<String, Object> map = new HashMap<String, Object>();\r
+\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource model = graph.getPossibleObject(input, l0.PartOf);\r
+ if (model != null) {\r
+ Collection<Resource> variables = graph.getObjects(model, l0.ConsistsOf);\r
+ for(Resource v : variables) {\r
+ Object unit = graph.getPossibleRelatedValue(v, sr.Variable_unit);\r
+ if (unit != null && !map.keySet().contains(unit)) {\r
+ map.put((String)unit, (String)unit);\r
+\r
+ }\r
+ }\r
+ }\r
+ return map;\r
+ }\r
+ });\r
+ \r
+ // Set initial selection of unit combo\r
+ setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+ String unit = graph.getPossibleRelatedValue(input, SysdynResource.getInstance(graph).Variable_unit);\r
+ if(unit == null)\r
+ return "";\r
+ else \r
+ return unit;\r
+ }\r
+ });\r
+\r
+ // Modify unit\r
+ addModifyListener(new ComboModifyListenerImpl<Resource>() {\r
+\r
+ @Override\r
+ public void applyText(WriteGraph graph, Resource input, String text) throws DatabaseException {\r
+ graph.denyValue(input, SysdynResource.getInstance(graph).Variable_unit);\r
+ graph.claimLiteral(input, SysdynResource.getInstance(graph).Variable_unit, text);\r
+ \r
+ Resource conf = graph.getPossibleObject(input, Layer0.getInstance(graph).PartOf);\r
+ SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
+ SysdynModel sm = smm.getModel(graph, conf);\r
+ sm.getMapping().domainModified(input);\r
+ sm.update(graph);\r
+ }\r
+ });\r
+\r
+ }\r
+ \r
+ \r
+\r
+}\r
L0X.IsActivatedBy, model,\r
l0.PartOf, model,\r
IssueResource.getInstance(g).IssueSource_active, false\r
- ); \r
-\r
+ ); \r
+ \r
Resource conf = GraphUtils.create2(g,\r
sr.Configuration,\r
l0.PartOf, model,\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 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
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.validation;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.issue.StandardIssue;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.issues.ontology.IssueResource;\r
+\r
+public class ModuleStandardIssue extends StandardIssue {\r
+\r
+ public ModuleStandardIssue(Resource type, Resource ... contexts) {\r
+ super(type, contexts);\r
+ }\r
+ \r
+ @Override\r
+ public void writeAdditionalContext(WriteGraph graph, Resource issue) throws DatabaseException {\r
+ super.writeAdditionalContext(graph, issue);\r
+\r
+ if(contexts.length >= 2) {\r
+ IssueResource IR = IssueResource.getInstance(graph);\r
+ // Input / output context\r
+ graph.claim(issue, IR.Issue_HasContext, IR.Issue_HasContext_Inverse, contexts[1]);\r
+ }\r
+ }\r
+\r
+}\r
package org.simantics.sysdyn.ui.validation;\r
\r
import java.util.ArrayList;\r
+import java.util.Collection;\r
import java.util.Collections;\r
+import java.util.HashSet;\r
import java.util.List;\r
\r
+import org.simantics.Simantics;\r
import org.simantics.db.Issue;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.issue.StandardIssue;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.issues.common.IssueUtils;\r
import org.simantics.sysdyn.manager.SysdynModelManager;\r
import org.simantics.sysdyn.representation.IndependentVariable;\r
import org.simantics.sysdyn.representation.expressions.IExpression;\r
+import org.simantics.sysdyn.representation.utils.UnitUtils;\r
\r
public class UnitFunction {\r
- \r
+\r
@SCLValue(type = "ReadGraph -> Resource -> [Issue]")\r
- public static List<Issue> unitValidator(ReadGraph graph, Resource independentVariable) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
+ public static List<Issue> unitValidator(ReadGraph graph, Resource component) throws DatabaseException {\r
SysdynResource SR = SysdynResource.getInstance(graph);\r
-\r
- \r
- if(independentVariable == null)\r
+ if(graph.isInstanceOf(component, SR.Variable))\r
+ return variableValidator(graph, component);\r
+ else if(graph.isInstanceOf(component, SR.Module))\r
+ return moduleValidator(graph, component);\r
+ else\r
return Collections.emptyList();\r
- \r
- Resource configuration = graph.getPossibleObject(independentVariable, L0.PartOf);\r
+ }\r
+ \r
+ private static List<Issue> variableValidator(ReadGraph graph, Resource variable) throws DatabaseException {\r
+ Layer0 L0 = Layer0.getInstance(graph); \r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+\r
+ Resource configuration = graph.getPossibleObject(variable, L0.PartOf);\r
if(configuration == null)\r
return Collections.emptyList();\r
- \r
+\r
// Make sure unit updates are listened to\r
- Resource unitResource = graph.getPossibleObject(independentVariable, SR.Variable_unit);\r
- String unit = graph.getPossibleRelatedValue(independentVariable, SR.Variable_unit);\r
+ String unit = graph.getPossibleRelatedValue(variable, SR.Variable_unit);\r
if(unit == null || unit.trim().length() == 0)\r
- return Collections.<Issue>singletonList(new StandardIssue(SR.Validations_UnitWarning, independentVariable));\r
- \r
- Resource expressionList = graph.getPossibleObject(independentVariable, SR.Variable_expressionList);\r
+ return Collections.<Issue>singletonList(new StandardIssue(SR.Validations_UnitWarning, variable));\r
+\r
+ if(!graph.isInstanceOf(variable, SR.IndependentVariable))\r
+ return Collections.emptyList();\r
\r
+ Resource expressionList = graph.getPossibleObject(variable, SR.Variable_expressionList);\r
+\r
if(expressionList == null)\r
return Collections.emptyList();\r
\r
- \r
+\r
SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
SysdynModel sm = smm.getModel(graph, configuration);\r
- sm.getMapping().domainModified(independentVariable);\r
+ sm.getMapping().domainModified(variable);\r
\r
sm.update(graph);\r
- Object var = sm.getMapping().get(independentVariable);\r
+ Object var = sm.getMapping().get(variable);\r
\r
ArrayList<Issue> issues = new ArrayList<Issue>();\r
\r
for(Resource r : graph.getObjects(expression, SR.Expression_equation)) {\r
graph.getValue(r);\r
}\r
- \r
+\r
sm.getMapping().domainModified(expression);\r
sm.update(graph);\r
- \r
+\r
Object expr = sm.getMapping().get(expression);\r
\r
if(expr != null && var != null && expr instanceof IExpression && var instanceof IndependentVariable) {\r
String result = ((IExpression)expr).validateUnits(graph, sm);\r
if(result != null) {\r
- Issue issue = new StandardIssue(SR.Validations_UnitWarning, independentVariable, expression, unitResource);\r
+ Issue issue = new StandardIssue(SR.Validations_UnitWarning, variable, expression, graph.getPossibleObject(variable, SR.Variable_unit));\r
issues.add(issue);\r
}\r
}\r
}\r
+ return issues;\r
+ }\r
+ \r
+ private static List<Issue> moduleValidator(ReadGraph graph, Resource module) throws DatabaseException {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+\r
+ if(module == null)\r
+ return Collections.emptyList();\r
+\r
+ Resource configuration = graph.getPossibleObject(module, L0.PartOf);\r
+ if(configuration == null)\r
+ return Collections.emptyList();\r
\r
+ String result = null;\r
+ ArrayList<Issue> issues = new ArrayList<Issue>();\r
+ for(Resource outputRelation : graph.getObjects(module, SR.Variable_isTailOf)) {\r
+ Resource reference = graph.getPossibleObject(outputRelation, SR.Dependency_refersTo);\r
+ if(reference != null) {\r
+ Resource output = graph.getPossibleObject(outputRelation, SR.Variable_HasHead);\r
+ String left = graph.getPossibleRelatedValue(output, SR.Variable_unit);\r
+ String right = graph.getPossibleRelatedValue(reference, SR.Variable_unit);\r
+ result = UnitUtils.matchUnits(left, right);\r
+ if(result != null)\r
+ issues.add(new ModuleStandardIssue(SR.Validations_ModuleOutputUnitWarning, module, output, reference));\r
+ }\r
+ }\r
+ for(Resource inputRelation : graph.getObjects(module, SR.Variable_isHeadOf)) {\r
+ Resource reference = graph.getPossibleObject(inputRelation, SR.Dependency_refersTo);\r
+ if(reference != null) {\r
+ Resource variable = graph.getPossibleObject(inputRelation, SR.Variable_HasTail);\r
+ String left = graph.getPossibleRelatedValue(variable, SR.Variable_unit);\r
+ String right = graph.getPossibleRelatedValue(reference, SR.Variable_unit);\r
+ result = UnitUtils.matchUnits(left, right);\r
+ if(result != null)\r
+ issues.add(new ModuleStandardIssue(SR.Validations_ModuleInputUnitWarning, module, variable, reference));\r
+ }\r
+ }\r
return issues;\r
}\r
\r
+\r
@SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
public static String unitWarningDescription(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {\r
List<Resource> contexts = IssueUtils.getContextsForProperty(graph, property);\r
- \r
+\r
if(contexts.size() == 0)\r
return "Error, No contexts";\r
- \r
+\r
Resource variable = contexts.get(0);\r
String unit = graph.getPossibleRelatedValue(variable, SysdynResource.getInstance(graph).Variable_unit);\r
\r
if(unit == null || unit.length() == 0)\r
return "No unit defined";\r
\r
+ if(contexts.size() < 2)\r
+ return "Error, not enough contexts";\r
+\r
Layer0 L0 = Layer0.getInstance(graph);\r
Resource configuration = graph.getPossibleObject(variable, L0.PartOf);\r
if(configuration == null)\r
return "Error, No Confiugration";\r
- \r
+\r
\r
SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
SysdynModel sm = smm.getModel(graph, configuration);\r
- \r
+\r
SysdynResource SR = SysdynResource.getInstance(graph);\r
for(Resource r : graph.getObjects(contexts.get(1), SR.Expression_equation)) {\r
graph.getValue(r);\r
}\r
- \r
+\r
Object expr = sm.getMapping().get(contexts.get(1));\r
String result = ((IExpression)expr).validateUnits(graph, sm);\r
+ \r
return result;\r
}\r
\r
+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
+ public static String moduleOutputUnitWarningDescription(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {\r
+ List<Resource> contexts = IssueUtils.getContextsForProperty(graph, property);\r
+\r
+ if(contexts.size() < 3)\r
+ return "Error, No contexts";\r
+\r
+ Resource output = contexts.get(1);\r
+ Resource reference = contexts.get(2);\r
+\r
+ return moduleInterfaceDescription(graph, output, reference, "Module output has different unit. (", ")");\r
+\r
+ }\r
+ \r
+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
+ public static String moduleInputUnitWarningDescription(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {\r
+ List<Resource> contexts = IssueUtils.getContextsForProperty(graph, property);\r
+\r
+ if(contexts.size() < 3)\r
+ return "Error, No contexts";\r
+\r
+ Resource output = contexts.get(1);\r
+ Resource reference = contexts.get(2);\r
+\r
+ return moduleInterfaceDescription(graph, output, reference, "Module input has different unit. (", ")");\r
+\r
+ }\r
+ \r
+ private static String moduleInterfaceDescription(ReadGraph graph, Resource leftResource, Resource rightResource, String prefix, String suffix) throws DatabaseException {\r
+ if(leftResource == null)\r
+ return "Erroneus error: left == null";\r
+ \r
+ if(rightResource == null)\r
+ return "Erroneus error: right == null";\r
+ \r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ \r
+ String left = graph.getPossibleRelatedValue(leftResource, SR.Variable_unit);\r
+ if(left == null || left.isEmpty())\r
+ return "No unit defined for " + NameUtils.getSafeName(graph, leftResource);\r
+ \r
+ String right = graph.getPossibleRelatedValue(rightResource, SR.Variable_unit);\r
+ if(right == null || right.isEmpty())\r
+ return "No unit defined for " + NameUtils.getSafeName(graph, rightResource);\r
+ \r
+ String result = UnitUtils.matchUnits(left, right);\r
+ \r
+ if(result != null)\r
+ result = prefix + result + suffix;\r
+ \r
+ return result;\r
+ }\r
+ \r
+ \r
+ \r
+ \r
+ @SCLValue(type = "ReadGraph -> [Resource] -> [Resource]")\r
+ public static List<Resource> moduleInterfaceExtension(ReadGraph graph, List<Resource> rs) throws DatabaseException {\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ \r
+ HashSet<Resource> components = new HashSet<Resource>();\r
+ HashSet<Resource> searchedModuleTypes = new HashSet<Resource>();\r
+ for(Resource r : rs) {\r
+ if(!graph.isInstanceOf(r, SR.Variable))\r
+ continue;\r
+ \r
+ if(graph.isInstanceOf(r, SR.Input)) {\r
+ Resource connection = graph.getPossibleObject(r, SR.Variable_isHeadOf);\r
+ if(connection != null)\r
+ components.add(graph.getPossibleObject(connection, SR.Variable_HasTail));\r
+ }\r
+ \r
+ for(Resource connection : graph.getObjects(r, SR.Variable_isTailOf)) {\r
+ Resource head = graph.getPossibleObject(connection, SR.Variable_HasHead);\r
+ if(graph.isInstanceOf(head, SR.Module)) {\r
+ components.add(head);\r
+ }\r
+ }\r
+ \r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ Resource configuration = graph.getPossibleObject(r, L0.PartOf);\r
+ Resource possibleModule = graph.getPossibleObject(configuration, L0.PartOf);\r
+ if(graph.isInheritedFrom(possibleModule, SR.Module) && !searchedModuleTypes.contains(possibleModule)) {\r
+ searchedModuleTypes.add(possibleModule);\r
+ for(Resource model : graph.syncRequest(new ObjectsWithType(Simantics.getProject().get(), L0.ConsistsOf, SR.SysdynModel))) {\r
+ Collection<Resource> found = org.simantics.db.indexing.IndexUtils.findByType(graph, model, possibleModule);\r
+ components.addAll(found);\r
+ }\r
+ }\r
+\r
+ }\r
+ \r
+ if(!components.isEmpty()) {\r
+ rs.addAll(components);\r
+ }\r
+ \r
+ return rs;\r
+ \r
+ }\r
+\r
}
\ No newline at end of file
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\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.simulation.ontology.SimulationResource;\r
}\r
}\r
}\r
+ \r
+ \r
+ public static String matchUnits(String left, String right) throws DatabaseException {\r
+ if(left == null || right == null || left.isEmpty() || right.isEmpty())\r
+ return "No unit defined";\r
+ \r
+ try {\r
+\r
+ StringReader leftReader = new StringReader(left);\r
+ UnitParser leftParser = new UnitParser(leftReader);\r
+ UnitCheckingNode leftNode = (UnitCheckingNode) leftParser.expr();\r
+ leftReader.close();\r
+\r
+ StringReader rightReader = new StringReader(right);\r
+ UnitParser rightParser = new UnitParser(rightReader);\r
+ UnitCheckingNode rightNode = (UnitCheckingNode) rightParser.expr();\r
+ rightReader.close();\r
+\r
+ try {\r
+ UnitResult leftUnits = leftNode.getUnits(null);\r
+ UnitResult rightUnits = rightNode.getUnits(null);\r
+\r
+ if(!rightUnits.equals(leftUnits))\r
+ return leftUnits.getCleanFullUnit() + " != " + rightUnits.getCleanFullUnit();\r
+ } catch (UnitCheckingException e) {\r
+ return e.getMessage();\r
+ }\r
+\r
+ } catch (ParseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ return null;\r
+ }\r
\r
}\r