From: lempinen Date: Tue, 13 Mar 2012 13:54:58 +0000 (+0000) Subject: First take on module instances with individual parameter values. Applicable only... X-Git-Tag: simantics-1.6~24 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=1cfa0b83f10ebd8523771c03f1fd6ed528ca469a;p=simantics%2Fsysdyn.git First take on module instances with individual parameter values. Applicable only to parameters with one parameter expression. The values can only be numbers. (refs #2992) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@24419 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index bb8b1f48..735898e4 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/PropertyViewpoints.pgraph b/org.simantics.sysdyn.ontology/graph/PropertyViewpoints.pgraph index 3d939280..ca6fea3c 100644 --- a/org.simantics.sysdyn.ontology/graph/PropertyViewpoints.pgraph +++ b/org.simantics.sysdyn.ontology/graph/PropertyViewpoints.pgraph @@ -2,6 +2,9 @@ L0 = VP = SYSDYN = +///////////////////////////////// +/// History datasets +///////////////////////////////// HDBC = SYSDYN.HistoryDataset.HistoryDatasetVariablesBrowseContext : VP.BrowseContext HDBC.StringNodeType -- SYSDYN.Module.redeclaration --> SYSDYN.Redeclaration -- SYSDYN.Module.parameterOverride --> SYSDYN.Module.ParameterOverride -- SYSDYN.Module.ParameterOverride.overriddenParameter --> SYSDYN.IndependentVariable -- SYSDYN.Module.ParameterOverride.overrideExpression --> L0.String - none 0 fill 1 + none 0 fill 1 \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java index 2ee0ac0f..b29c0357 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in + * Copyright (c) 2010, 2012 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -27,11 +27,11 @@ import org.simantics.db.management.ISessionContext; import org.simantics.layer0.Layer0; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.ui.properties.widgets.ModuleInputEditingSupport; -import org.simantics.sysdyn.ui.properties.widgets.ReferenceRow; -import org.simantics.sysdyn.ui.properties.widgets.ReferenceRowLabelProvider; -import org.simantics.sysdyn.ui.properties.widgets.ReferenceTable; -import org.simantics.sysdyn.ui.properties.widgets.RowProvider; +import org.simantics.sysdyn.ui.properties.widgets.modules.ModuleInputEditingSupport; +import org.simantics.sysdyn.ui.properties.widgets.modules.ReferenceRow; +import org.simantics.sysdyn.ui.properties.widgets.modules.ReferenceRowLabelProvider; +import org.simantics.sysdyn.ui.properties.widgets.modules.ReferenceTable; +import org.simantics.sysdyn.ui.properties.widgets.modules.RowProvider; public class ModuleInputTab extends LabelPropertyTabContributor { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleOutputTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleOutputTab.java index 24e08266..47a114e7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleOutputTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleOutputTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in + * Copyright (c) 2010, 2012 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -27,11 +27,11 @@ import org.simantics.db.management.ISessionContext; import org.simantics.layer0.Layer0; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.ui.properties.widgets.ModuleOutputEditingSupport; -import org.simantics.sysdyn.ui.properties.widgets.ReferenceRow; -import org.simantics.sysdyn.ui.properties.widgets.ReferenceRowLabelProvider; -import org.simantics.sysdyn.ui.properties.widgets.ReferenceTable; -import org.simantics.sysdyn.ui.properties.widgets.RowProvider; +import org.simantics.sysdyn.ui.properties.widgets.modules.ModuleOutputEditingSupport; +import org.simantics.sysdyn.ui.properties.widgets.modules.ReferenceRow; +import org.simantics.sysdyn.ui.properties.widgets.modules.ReferenceRowLabelProvider; +import org.simantics.sysdyn.ui.properties.widgets.modules.ReferenceTable; +import org.simantics.sysdyn.ui.properties.widgets.modules.RowProvider; public class ModuleOutputTab extends LabelPropertyTabContributor { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleParameterTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleParameterTab.java new file mode 100644 index 00000000..42220661 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleParameterTab.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2007, 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.SingleSelectionInputSource; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.Resource; +import org.simantics.db.management.ISessionContext; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys; +import org.simantics.utils.datastructures.ArrayMap; + +public class ModuleParameterTab extends LabelPropertyTabContributor { + + GraphExplorerComposite explorer; + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite); + + explorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, composite, support, SWT.FULL_SELECTION | SWT.BORDER); + + explorer.setBrowseContexts(SysdynResource.URIs.Module_ParameterOverrideBrowseContext); + explorer.setColumns(ColumnKeys.MODULE_PARAMETER_COLUMNS); + explorer.setInputSource(new SingleSelectionInputSource( + Resource.class)); + + explorer.finish(); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + explorer); + + Control c = explorer.getExplorerControl(); + if (c instanceof Tree) + ((Tree) c).setLinesVisible(true); + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java index 35f0299f..c01f4733 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -212,9 +212,14 @@ public class ResourceSelectionProcessor implements SelectionProcessor expressions = OrderedSetUtils.toList(graph, expressionsResource); + if(expressions.size() == 1 && graph.isInstanceOf(expressions.get(0), sr.ParameterExpression)) { + result = graph.getPossibleRelatedValue(expressions.get(0), sr.Expression_equation); + } + } + return result; + } + + /** + * Get the expression, or the overriding expression, of a parameter + * @param graph ReadGraph + * @param parent Parent resource + * @param variable Variable resource + * @return Overriding expression, or the default parameter expression, or null + * @throws DatabaseException + */ + public static String getParameterExpressionOrOverride(ReadGraph graph, Resource parent, Resource variable) + throws DatabaseException { + String result = null; + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 L0 = Layer0.getInstance(graph); + + // Get possible override + for(Resource r : graph.syncRequest(new ObjectsWithType(parent, L0.ConsistsOf, sr.Module_ParameterOverride))) { + if(variable.equals(graph.getPossibleObject(r, sr.Module_ParameterOverride_overriddenParameter))) { + result = graph.getPossibleRelatedValue(r, sr.Module_ParameterOverride_overrideExpression); + } + } + + if(result == null) { + // Parameter is not overridden, find the actual expression + result = getParameterExpression(graph, variable); + } + return result; + } + + /** + * Find out if a variable has a single parameter expression + * @param graph ReadGraph + * @param variable Variable + * @return does the variable have a single parameter expression + * @throws DatabaseException + */ + public static boolean hasParameterExpression(ReadGraph graph, Resource variable) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + boolean result = false; + Resource expressionsResource = graph.getPossibleObject(variable, sr.Variable_expressions); + if(expressionsResource != null) { + List expressions = OrderedSetUtils.toList(graph, expressionsResource); + if(expressions.size() == 1 && graph.isInstanceOf(expressions.get(0), sr.ParameterExpression)) { + result = true; + } + } + return result; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterChildRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterChildRule.java new file mode 100644 index 00000000..263ffd36 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterChildRule.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.modules; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.model.children.ChildRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; + +public class ParameterChildRule implements ChildRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Collection getChildren(ReadGraph graph, Object parent) throws DatabaseException { + ArrayList result = new ArrayList(); + if(!(parent instanceof Resource)) + return result; + + Layer0 L0 = Layer0.getInstance(graph); + StructuralResource2 STR = StructuralResource2.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + + Resource moduleInstance = (Resource) parent; + + Resource type = graph.getSingleObject(moduleInstance, L0.InstanceOf); + Resource configuration = graph.getSingleObject(type, STR.IsDefinedBy); + + for(Resource variable : graph.syncRequest(new ObjectsWithType(configuration, L0.ConsistsOf, sr.IndependentVariable))) { + if(ModuleParameterOverrideUtils.hasParameterExpression(graph, variable)) + result.add(new ParameterNode(moduleInstance, variable)); + } + + return result; + + + } + + @Override + public Collection getParents(ReadGraph graph, Object child) throws DatabaseException { + return new ArrayList(); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterLabelDecorationRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterLabelDecorationRule.java new file mode 100644 index 00000000..c9f7f691 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterLabelDecorationRule.java @@ -0,0 +1,57 @@ +package org.simantics.sysdyn.ui.properties.widgets.modules; + +import org.eclipse.jface.resource.ColorDescriptor; +import org.eclipse.swt.graphics.RGB; +import org.simantics.browsing.ui.content.LabelDecorator; +import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys; + +public class ParameterLabelDecorationRule implements LabelDecorationRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Object.class); + } + + @Override + public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException { + if(content instanceof ParameterNode) { + ParameterNode node = (ParameterNode) content; + String notOverriding = ModuleParameterOverrideUtils.getParameterExpression(graph, node.getVariable()); + String overriding = ModuleParameterOverrideUtils.getParameterExpressionOrOverride(graph, node.getParent(), node.getVariable()); + + if(notOverriding == null) + return null; + + final boolean original = notOverriding.equals(overriding); + + return new LabelDecorator.Stub() { + @Override + public String decorateLabel(String label, String column, int itemIndex) { + if(ColumnKeys.VALUE.equals(column)) { + return original ? label : label + " [Overridden]"; + } else { + return label; + } + } + + @SuppressWarnings("unchecked") + @Override + public Color decorateForeground(Color color, String column, int itemIndex) { + Color result = null; + if(ColumnKeys.VALUE.equals(column)) { + if(original) + result = (Color) ColorDescriptor.createFrom(new RGB(125,125,125)); + else + result = (Color) ColorDescriptor.createFrom(new RGB(0,0,0)); + } + return result; + } + }; + } + return null; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterLabelRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterLabelRule.java new file mode 100644 index 00000000..0b539ae4 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterLabelRule.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2007, 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.modules; + +import java.util.HashMap; +import java.util.Map; + +import org.simantics.browsing.ui.model.labels.LabelRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys; + +public class ParameterLabelRule implements LabelRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Object.class); + } + + @Override + public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { + Map result = new HashMap(); + + if(content instanceof ParameterNode) { + ParameterNode node = (ParameterNode) content; + String parameterExpression = ModuleParameterOverrideUtils.getParameterExpressionOrOverride(graph, node.getParent(), node.getVariable()); + String name = NameUtils.getSafeName(graph, node.getVariable()); + + result.put(ColumnKeys.MODULE_PARAMETER, name); + result.put(ColumnKeys.VALUE, parameterExpression); + } + return result; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterModifierRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterModifierRule.java new file mode 100644 index 00000000..da19b2bb --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterModifierRule.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2007, 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.modules; + +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.browsing.ui.model.modifiers.ModifierRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys; +import org.simantics.ui.SimanticsUI; + +public class ParameterModifierRule implements ModifierRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Object.class); + } + + @Override + public Modifier getModifier(ReadGraph graph, Object content, String columnKey) throws DatabaseException { + if(content instanceof ParameterNode && ColumnKeys.VALUE.equals(columnKey)) { + final ParameterNode node = (ParameterNode) content; + return new Modifier() { + + @Override + public String getValue() { + Read request = + new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + String parameterExpression = ModuleParameterOverrideUtils.getParameterExpressionOrOverride( + graph, + node.getParent(), + node.getVariable()); + + return parameterExpression != null ? parameterExpression : ""; + } + + }; + try { + return SimanticsUI.getSession().syncRequest(request); + } catch (DatabaseException e) { + e.printStackTrace(); + return ""; + } + } + + @Override + public String isValid(String label) { + if(label.isEmpty()) + return null; + + try { + Double.parseDouble(label); + } catch (NumberFormatException e) { + return "Not valid"; + } + return null; + } + + @Override + public void modify(final String label) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 L0 = Layer0.getInstance(graph); + + // Remove possible old override + for(Resource r : graph.syncRequest(new ObjectsWithType(node.getParent(), L0.ConsistsOf, sr.Module_ParameterOverride))) { + if(node.getVariable().equals(graph.getPossibleObject(r, sr.Module_ParameterOverride_overriddenParameter))) { + RemoverUtil.remove(graph, r); + break; + } + } + + // Write the new override, if there is one + if(label != null && !label.isEmpty()) { + GraphUtils.create2(graph, sr.Module_ParameterOverride, + sr.Module_ParameterOverride_overriddenParameter, node.getVariable(), + sr.Module_ParameterOverride_overrideExpression, label, + L0.PartOf, node.getParent() + ); + } + } + }); + } + + }; + } else { + return null; + } + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterNode.java new file mode 100644 index 00000000..4c759400 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ParameterNode.java @@ -0,0 +1,25 @@ +package org.simantics.sysdyn.ui.properties.widgets.modules; + +import org.simantics.db.Resource; + +public class ParameterNode { + + private Resource moduleInstance; + private Resource variable; + + public ParameterNode(Resource parent, Resource variable) { + this.moduleInstance = parent; + this.variable = variable; + } + + public Resource getParent() { + return moduleInstance; + } + + public Resource getVariable() { + return variable; + } + + + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRow.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceRow.java similarity index 94% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRow.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceRow.java index 6bebab0e..03400481 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRow.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceRow.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in + * Copyright (c) 2010, 2012 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.properties.widgets; +package org.simantics.sysdyn.ui.properties.widgets.modules; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRowLabelProvider.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceRowLabelProvider.java similarity index 87% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRowLabelProvider.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceRowLabelProvider.java index b44432a0..763e8411 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRowLabelProvider.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceRowLabelProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in + * Copyright (c) 2010, 2012 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.properties.widgets; +package org.simantics.sysdyn.ui.properties.widgets.modules; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceTable.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceTable.java similarity index 94% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceTable.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceTable.java index 29066345..aeb5dafd 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceTable.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceTable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in + * Copyright (c) 2010, 2012 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.properties.widgets; +package org.simantics.sysdyn.ui.properties.widgets.modules; import java.util.ArrayList; import org.eclipse.jface.layout.GridDataFactory; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/RowProvider.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/RowProvider.java similarity index 83% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/RowProvider.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/RowProvider.java index cd36f387..9b424d26 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/RowProvider.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/RowProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in + * Copyright (c) 2010, 2012 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.properties.widgets; +package org.simantics.sysdyn.ui.properties.widgets.modules; import java.util.ArrayList; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java index 415fdc05..f4487ebf 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java @@ -21,6 +21,8 @@ import org.simantics.objmap.annotations.RelatedElement; import org.simantics.objmap.annotations.RelatedElements; import org.simantics.objmap.annotations.RelatedValue; import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.representation.expressions.IExpression; +import org.simantics.sysdyn.representation.expressions.ParameterExpression; import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; import org.simantics.utils.datastructures.Pair; @@ -44,6 +46,9 @@ public class Module implements IElement { @RelatedElements(SysdynResource.URIs.Module_redeclaration) private List redeclarations; + @RelatedElements(Layer0.URIs.ConsistsOf) + private List consistsOf; + @Override public void accept(IElementVisitorVoid v) { v.visit(this); @@ -77,10 +82,11 @@ public class Module implements IElement { String enumerationRedeclarations = getEnumerationRedeclarations(); Pair inputRedeclarations = getInputRedeclarations(); + String parameterOverrides = getParameterOverrides(); StringBuilder redeclarations = new StringBuilder(); - if(!enumerationRedeclarations.isEmpty() || !inputRedeclarations.first.isEmpty()) { + if(!enumerationRedeclarations.isEmpty() || !inputRedeclarations.first.isEmpty() || !parameterOverrides.isEmpty()) { redeclarations.append("("); redeclarations.append(enumerationRedeclarations); @@ -89,6 +95,12 @@ public class Module implements IElement { // remove first ", " if no enumeration redeclarations ir = inputRedeclarations.first.substring(2); redeclarations.append(ir); + + if(!parameterOverrides.isEmpty()) { + if(redeclarations.length() > 1) + redeclarations.append(", "); + redeclarations.append(parameterOverrides); + } redeclarations.append(")"); } @@ -202,5 +214,35 @@ public class Module implements IElement { } return redeclarations; } + + + /** + * Get all parameter override elements for this module instance + * @return parameter overrides + */ + public String getParameterOverrides() { + String result = ""; + + if(consistsOf != null) { + for(Entity e : consistsOf) { + if(e instanceof ParameterOverride) { + ParameterOverride po = (ParameterOverride) e; + IndependentVariable var = po.getVariable(); + if(var != null && var.getExpressions() != null) { + List expressions = var.getExpressions().getExpressions(); + if(expressions.size() == 1 && expressions.get(0) instanceof ParameterExpression) { + if(!result.isEmpty()) + result += ", "; + + result += po.getOverride(); + } + } + + } + } + } + + return result; + } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ParameterOverride.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ParameterOverride.java new file mode 100644 index 00000000..c9f1b2f9 --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ParameterOverride.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007, 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElement; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.sysdyn.SysdynResource; + + +/** + * Representation of a parameter override + * @author Teemu Lempinen + * + */ +@GraphType(SysdynResource.URIs.Module_ParameterOverride) +public class ParameterOverride extends Entity { + + @RelatedElement(SysdynResource.URIs.Module_ParameterOverride_overriddenParameter) + private IndependentVariable variable; + + @RelatedValue(SysdynResource.URIs.Module_ParameterOverride_overrideExpression) + private String expression; + + /** + * Get the parameter variable to be overridden + * @return parameter variable to be overridden + */ + public IndependentVariable getVariable() { + return variable; + } + + /** + * Get the overriding expression + * @return overriding expression + */ + public String getExpression() { + return expression; + } + + /** + * Get the complete override equation: "variable = overridingExpression" + * @return override equation + */ + public String getOverride() { + return variable.getName() + " = " + expression; + } + +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java index 0621f830..5b8812b0 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java @@ -60,6 +60,7 @@ public class SysdynSchema extends SimpleSchema { addLinkType(MappingSchemas.fromAnnotations(g, SharedFunctionLibrary.class)); addLinkType(MappingSchemas.fromAnnotations(g, Function.class)); addLinkType(MappingSchemas.fromAnnotations(g, Entity.class)); + addLinkType(MappingSchemas.fromAnnotations(g, ParameterOverride.class)); } catch (DatabaseException e) { e.printStackTrace(); } catch (InstantiationException e) {