From: lempinen Date: Wed, 21 Jul 2010 07:39:21 +0000 (+0000) Subject: new variable type: Input. X-Git-Tag: simantics-1.2.0~170 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=eafac6a5825cd44a8675b15b23cd85fd5f83a35d;p=simantics%2Fsysdyn.git new variable type: Input. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16740 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/adapters.xml b/org.simantics.sysdyn.ui/adapters.xml index 99230159..339b34aa 100644 --- a/org.simantics.sysdyn.ui/adapters.xml +++ b/org.simantics.sysdyn.ui/adapters.xml @@ -25,5 +25,5 @@ - none 0 fill 1 + none 0 fill 1 \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/icons/brick_link.png b/org.simantics.sysdyn.ui/icons/brick_link.png new file mode 100644 index 00000000..9ebf013a Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/brick_link.png differ diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 602cf206..90babd61 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -623,6 +623,10 @@ class="org.simantics.sysdyn.ui.browser.contributions.ModuleLabeler" preference="2.0"> + + + + { e.printStackTrace(); } } + for(Resource r : graph.syncRequest(new ObjectsWithType(configuration.resource, b.ConsistsOf, sr.Input))) { + try { + result.add(graph.adapt(r, AbstractNode.class)); + } catch(DatabaseException e) { + e.printStackTrace(); + } + } for(Resource r : graph.syncRequest(new ObjectsWithType(configuration.resource, b.ConsistsOf, sr.Module))) { try { result.add(graph.adapt(r, AbstractNode.class)); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputImager.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputImager.java new file mode 100644 index 00000000..c70b3665 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputImager.java @@ -0,0 +1,17 @@ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.swt.ImagerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.browser.nodes.InputNode; + +public class InputImager extends ImagerContributor { + + @Override + public ImageDescriptor getDescriptor(ReadGraph graph, InputNode node) throws DatabaseException { + return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/brick_link.png")); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputLabeler.java new file mode 100644 index 00000000..3e042c6e --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputLabeler.java @@ -0,0 +1,27 @@ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.Builtins; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.InputNode; + +public class InputLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, InputNode var) throws DatabaseException { + Builtins b = graph.getBuiltins(); + Resource varres = var.resource; + StringBuilder sb = new StringBuilder(); + for(Resource r : graph.getObjects(varres, b.HasName)) + sb.append(graph.getValue(r)); + sb.append(" : "); + for(Resource t : graph.getObjects(varres, b.InstanceOf)) + for(Resource r : graph.getObjects(t, b.HasName)) + sb.append(graph.getValue(r)); + return sb.toString(); + } + + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/InputNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/InputNode.java new file mode 100644 index 00000000..b0efeb7b --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/InputNode.java @@ -0,0 +1,10 @@ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.db.Resource; + +public class InputNode extends AbstractNode { + + public InputNode(Resource resource) { + super(resource); + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynConnectionAdvisor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynConnectionAdvisor.java index bcec3c9a..bcf57825 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynConnectionAdvisor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynConnectionAdvisor.java @@ -30,7 +30,7 @@ public class SysdynConnectionAdvisor implements IConnectionAdvisor { this.modelingRules = modelingRules; this.processor = processor; } - + IConnectionPoint getConnectionPoint(ReadGraph g, IElement element, Terminal term) throws DatabaseException { Object obj = null; if (element != null) @@ -40,11 +40,11 @@ public class SysdynConnectionAdvisor implements IConnectionAdvisor { Resource elementResource = (Resource) obj; return ConnectionUtil.toConnectionPoint(g, elementResource, term); } - + if(element.getElementClass().containsClass(FlagHandler.class)) { return new CPFlag(null); } - + return null; } @@ -67,8 +67,21 @@ public class SysdynConnectionAdvisor implements IConnectionAdvisor { if(!g.hasStatement(connectionVariable, str2.Binds, sr.IsHeadOfTerminal)) { return null; } + + // Only one incoming dependency allowed in inputs. That dependency must be from a module + Object obj1 = ElementUtils.getObject(element1); + Object obj2 = ElementUtils.getObject(element2); + if(obj2 instanceof Resource) { + Resource startElementResource = (Resource)obj1; + Resource endElementResource = (Resource)obj2; + if(g.isInstanceOf(endElementResource, sr.InputSymbol)) { + if(g.isInheritedFrom(startElementResource, sr.ModuleSymbol)) return null; + if(g.getObjects(endElementResource, sr.IsHeadOfTerminal).size() > 0) return null; + } + } + IConnection connection = modelingRules.createConnection() - .attachNew(g, getConnectionPoint(g, element1, term1)); + .attachNew(g, getConnectionPoint(g, element1, term1)); if(element2 != null) connection = connection.attachNew(g, getConnectionPoint(g, element2, term2)); if(connection.isLegal()) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java new file mode 100644 index 00000000..e266bf22 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java @@ -0,0 +1,63 @@ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.BasicStroke; +import java.awt.Shape; +import java.awt.geom.Path2D; +import java.util.Collection; + +import org.simantics.db.Resource; +import org.simantics.diagram.elements.TextElementHandler; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.handler.impl.BoundsOutline; +import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.ObjectTerminal; +import org.simantics.g2d.element.handler.impl.OutlinePick; +import org.simantics.g2d.element.handler.impl.SimpleElementLayers; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer; +import org.simantics.g2d.element.handler.impl.StaticSymbolImpl; +import org.simantics.g2d.element.handler.impl.TextColorImpl; +import org.simantics.g2d.element.handler.impl.TextFontImpl; +import org.simantics.g2d.element.handler.impl.TextImpl; +import org.simantics.g2d.image.Image; +import org.simantics.g2d.image.impl.ShapeImage; + +public class InputFactory extends SysdynElementFactory { + + private static final BasicStroke STROKE = new BasicStroke(1f); + private static final Image INPUT_IMAGE = new ShapeImage(getInputShape(), null, STROKE, true); + + static Shape getInputShape() { + Path2D path = new Path2D.Double(); + path.moveTo(0, -1); + path.lineTo(5, -1); + path.lineTo(5, -2.5); + path.lineTo(7.5, 0); + path.curveTo(7.5, -2.5, 12.5, -2.5, 12.5, 0); + path.curveTo(12.5, 2.5, 7.5, 2.5, 7.5, 0); + path.lineTo(5, 2.5); + path.lineTo(5, 1); + path.lineTo(0, 1); + path.closePath(); + return path; + } + @Override + protected ElementClass compileElementClass(Resource elementType, Collection terminals) { + return ElementClass.compile( + SimpleElementLayers.INSTANCE, + OutlinePick.INSTANCE, + TextImpl.INSTANCE, + TextColorImpl.BLACK, + TextFontImpl.DEFAULT, + DefaultTransform.INSTANCE, + new StaticObjectAdapter(elementType), + new StaticSymbolImpl(INPUT_IMAGE), + StaticSymbolImageInitializer.INSTANCE, + TextElementHandler.INSTANCE, + BoundsOutline.INSTANCE, + new WholeElementTerminals(terminals) + ).setId(AuxiliaryFactory.class.getSimpleName()); + } + + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java index b3015879..ae407a96 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java @@ -60,7 +60,7 @@ import org.simantics.sysdyn.manager.SysdynModel; import org.simantics.sysdyn.manager.SysdynModelManager; import org.simantics.sysdyn.representation.Configuration; import org.simantics.sysdyn.representation.IElement; -import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.representation.IndependentVariable; import org.simantics.sysdyn.ui.equation.expressions.ExpressionField; import org.simantics.sysdyn.ui.equation.expressions.StockExpressionViewFactor; import org.simantics.ui.SimanticsUI; @@ -406,8 +406,8 @@ public class EquationView extends ViewPart implements ISelectionListener { Configuration conf = model.getConfiguration(); ArrayList elements = conf.getElements(); for(IElement e : elements) { - if(e instanceof Variable) { - Variable v = (Variable) e; + if(e instanceof IndependentVariable) { + IndependentVariable v = (IndependentVariable) e; modelVariables.add(v.getName()); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/NameComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/NameComposite.java index fbc5fef6..bc959253 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/NameComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/NameComposite.java @@ -36,7 +36,7 @@ import org.simantics.sysdyn.manager.SysdynModel; import org.simantics.sysdyn.manager.SysdynModelManager; import org.simantics.sysdyn.representation.Configuration; import org.simantics.sysdyn.representation.IElement; -import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.representation.IndependentVariable; import org.simantics.ui.SimanticsUI; import org.simantics.ui.workbench.ResourceEditorInput; @@ -118,8 +118,8 @@ public class NameComposite extends Composite { IElement thisElement = model.getElement(variable); ArrayList elements = conf.getElements(); for(IElement e : elements) { - if(e instanceof Variable) { - Variable v = (Variable)e; + if(e instanceof IndependentVariable) { + IndependentVariable v = (IndependentVariable)e; if(v != thisElement && v.getName().equals(this.nameText.getText())) { this.nameText.setText(this.originalName); this.nameText.setSelection(this.originalName.length()); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/InputVariableTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/InputVariableTab.java new file mode 100644 index 00000000..357bdf65 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/InputVariableTab.java @@ -0,0 +1,70 @@ +package org.simantics.sysdyn.ui.properties; + + +import org.eclipse.jface.dialogs.IInputValidator; +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.Label; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.PropertyTabContributorImpl; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedCombo; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.Builtins; +import org.simantics.db.management.ISessionContext; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.IsOutputWidget; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; + +public class InputVariableTab extends PropertyTabContributorImpl { + + TrackedCombo expressionTypeCombo; + IsOutputWidget isOutput; + + @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).numColumns(2).applyTo(composite); + + TrackedText nameText = new TrackedText(composite, support, SWT.BORDER); + nameText.setTextFactory(new StringPropertyFactory(Builtins.URIs.HasName)); + nameText.addModifyListener(new StringPropertyModifier(context, Builtins.URIs.HasName)); + GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText.getWidget()); + + isOutput = new IsOutputWidget(composite, support, SWT.NULL); + + Label label = new Label(composite, SWT.NULL); + label.setText("Default Value"); + + TrackedText rangeStep = new TrackedText(composite, support, SWT.RIGHT | SWT.BORDER); + rangeStep.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasRangeStep)); + rangeStep.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasDefaultInputValue)); + rangeStep.setInputValidator(new DoubleValidator()); + GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeStep.getWidget()); + + + } + + private class DoubleValidator implements IInputValidator { + + @Override + public String isValid(String newText) { + for(int i = 0; i < newText.length(); i++){ + if(!Character.isDigit(newText.charAt(i))){ + if(newText.charAt(i) != '.') { + return "Invalid character '" + newText.charAt(i) + "'"; + } else if(newText.indexOf('.') != newText.lastIndexOf('.')) { + return "There can be only one '.'"; + } + } + } + return null; + } + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ReferenceDependencyTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ReferenceDependencyTab.java new file mode 100644 index 00000000..56fa1044 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ReferenceDependencyTab.java @@ -0,0 +1,15 @@ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.PropertyTabContributorImpl; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; + +public class ReferenceDependencyTab extends PropertyTabContributorImpl { + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + } + +} 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 2f2bc298..e2756e9a 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 @@ -31,16 +31,21 @@ public class ResourceSelectionProcessor implements SelectionProcessor tabs = new ArrayList(); if (backend.isInstanceOf(r, dr.Element)) { Resource component = backend.getPossibleObject(r, mr.ElementToComponent); - if (component != null) + if (component != null) { r = component; + } else { + Resource connection = backend.getPossibleObject(r, mr.DiagramConnectionToConnection); + if(connection != null) + r = connection; + } } if (backend.isInstanceOf(r, sr.IndependentVariable)) { - tabs.add(new ComparableTabContributor( - new EquationTab(), - 2, - r, - "Equation")); Resource expression = backend.getPossibleObject(r, sr.HasExpression); + tabs.add(new ComparableTabContributor( + new EquationTab(), + 2, + r, + "Equation")); if(expression != null && backend.isInstanceOf(expression, sr.WithLookupExpression)) { tabs.add(new ComparableTabContributor( new LookupTableTab(), @@ -55,6 +60,13 @@ public class ResourceSelectionProcessor implements SelectionProcessor(context) { + + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.hasStatement(input, sr.IsOutput)) { + graph.deny(input, sr.IsOutput); + } else { + graph.claim(input, SysdynResource.getInstance(graph).IsOutput, null, input); + } + } + }); + } + + public Button getWidget() { + return isOutputButton.getWidget(); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java index 5c8a2cdd..92ef2326 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java @@ -19,7 +19,7 @@ import org.simantics.sysdyn.manager.SysdynModel; import org.simantics.sysdyn.manager.SysdynModelManager; import org.simantics.sysdyn.representation.Configuration; import org.simantics.sysdyn.representation.IElement; -import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.representation.IndependentVariable; import org.simantics.sysdyn.ui.properties.widgets.expressions.IExpression; import org.simantics.ui.SimanticsUI; @@ -56,8 +56,8 @@ public class ExpressionValidation { Configuration conf = model.getConfiguration(); ArrayList elements = conf.getElements(); for(IElement e : elements) { - if(e instanceof Variable) { - Variable v = (Variable) e; + if(e instanceof IndependentVariable) { + IndependentVariable v = (IndependentVariable) e; modelVariables.add(v.getName()); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/InputExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/InputExpression.java deleted file mode 100644 index 384182d8..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/InputExpression.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.simantics.sysdyn.ui.properties.widgets.expressions; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.simantics.db.Resource; - -public class InputExpression implements IExpression { - - @Override - public void createExpressionFields(Composite parent, Map data) { - GridLayoutFactory.fillDefaults().applyTo(parent); - Label label = new Label(parent, SWT.NONE); - label.setText("Input"); - } - - @Override - public void readData(Resource variable, Map data) { - // TODO Auto-generated method stub - - } - - @Override - public void save(Resource variable, Map data) { - // TODO Auto-generated method stub - - } - - @Override - public void focus() { - // TODO Auto-generated method stub - - } - - @Override - public void replaceSelection(String var) { - // TODO Auto-generated method stub - - } - - @Override - public void updateData(Map data) { - // TODO Auto-generated method stub - - } - - @SuppressWarnings("unchecked") - @Override - public List getExpressionFields() { - // TODO Auto-generated method stub - return Collections.EMPTY_LIST; - } - - @Override - public void addModifyListener(ModifyListener listener) { - // TODO Auto-generated method stub - - } - - @Override - public void addKeyListener(KeyListener listener) { - // TODO Auto-generated method stub - - } - - @Override - public void addFocusListener(FocusListener listener) { - // TODO Auto-generated method stub - - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java index 67d3649b..8ad31ef2 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java @@ -13,7 +13,6 @@ package org.simantics.sysdyn.ui.trend; import java.awt.Frame; import java.util.ArrayList; -import java.util.HashMap; import java.util.Set; import javax.swing.SwingUtilities; @@ -49,8 +48,6 @@ import org.simantics.diagram.stubs.DiagramResource; import org.simantics.modeling.ModelingUtils; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.manager.SysdynDataSet; -import org.simantics.sysdyn.manager.SysdynModel; -import org.simantics.sysdyn.manager.SysdynModelManager; import org.simantics.ui.SimanticsUI; import org.simantics.utils.ui.ISelectionUtils; import org.simantics.utils.ui.jface.ActiveSelectionProvider; @@ -249,6 +246,7 @@ public class TrendView extends ViewPart { System.out.println("load dataset for '" + item.getURI(g) + "'"); Accessor accessor = item.getInterface(g, Accessor.class); + if(accessor == null) return null; try { return (SysdynDataSet)accessor.getValue(Bindings.getBindingUnchecked(SysdynDataSet.class)); } catch (RuntimeBindingConstructionException e) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java index 924b6fdf..75411206 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java @@ -46,6 +46,7 @@ public class SysdynResource { public final Resource Flow; public final Resource FlowConnection; public final Resource GameExperiment; + public final Resource HasDefaultInputValue; public final Resource HasEquation; public final Resource HasExpression; public final Resource HasHead; @@ -71,7 +72,8 @@ public class SysdynResource { public final Resource HasY; public final Resource HistoryRealization; public final Resource IndependentVariable; - public final Resource InputExpression; + public final Resource Input; + public final Resource InputSymbol; public final Resource IsHeadOf; public final Resource IsHeadOfTerminal; public final Resource IsInput; @@ -130,6 +132,7 @@ public class SysdynResource { public static final String Flow = "http://www.simantics.org/Sysdyn-1.0/Flow"; public static final String FlowConnection = "http://www.simantics.org/Sysdyn-1.0/FlowConnection"; public static final String GameExperiment = "http://www.simantics.org/Sysdyn-1.0/GameExperiment"; + public static final String HasDefaultInputValue = "http://www.simantics.org/Sysdyn-1.0/HasDefaultInputValue"; public static final String HasEquation = "http://www.simantics.org/Sysdyn-1.0/HasEquation"; public static final String HasExpression = "http://www.simantics.org/Sysdyn-1.0/HasExpression"; public static final String HasHead = "http://www.simantics.org/Sysdyn-1.0/HasHead"; @@ -155,7 +158,8 @@ public class SysdynResource { public static final String HasY = "http://www.simantics.org/Sysdyn-1.0/HasY"; public static final String HistoryRealization = "http://www.simantics.org/Sysdyn-1.0/HistoryRealization"; public static final String IndependentVariable = "http://www.simantics.org/Sysdyn-1.0/IndependentVariable"; - public static final String InputExpression = "http://www.simantics.org/Sysdyn-1.0/InputExpression"; + public static final String Input = "http://www.simantics.org/Sysdyn-1.0/Input"; + public static final String InputSymbol = "http://www.simantics.org/Sysdyn-1.0/InputSymbol"; public static final String IsHeadOf = "http://www.simantics.org/Sysdyn-1.0/IsHeadOf"; public static final String IsHeadOfTerminal = "http://www.simantics.org/Sysdyn-1.0/IsHeadOfTerminal"; public static final String IsInput = "http://www.simantics.org/Sysdyn-1.0/IsInput"; @@ -224,6 +228,7 @@ public class SysdynResource { Flow = getResourceOrNull(graph, URIs.Flow); FlowConnection = getResourceOrNull(graph, URIs.FlowConnection); GameExperiment = getResourceOrNull(graph, URIs.GameExperiment); + HasDefaultInputValue = getResourceOrNull(graph, URIs.HasDefaultInputValue); HasEquation = getResourceOrNull(graph, URIs.HasEquation); HasExpression = getResourceOrNull(graph, URIs.HasExpression); HasHead = getResourceOrNull(graph, URIs.HasHead); @@ -249,7 +254,8 @@ public class SysdynResource { HasY = getResourceOrNull(graph, URIs.HasY); HistoryRealization = getResourceOrNull(graph, URIs.HistoryRealization); IndependentVariable = getResourceOrNull(graph, URIs.IndependentVariable); - InputExpression = getResourceOrNull(graph, URIs.InputExpression); + Input = getResourceOrNull(graph, URIs.Input); + InputSymbol = getResourceOrNull(graph, URIs.InputSymbol); IsHeadOf = getResourceOrNull(graph, URIs.IsHeadOf); IsHeadOfTerminal = getResourceOrNull(graph, URIs.IsHeadOfTerminal); IsInput = getResourceOrNull(graph, URIs.IsInput); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java index 02e71a7d..9270f113 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java @@ -12,13 +12,16 @@ package org.simantics.sysdyn.modelica; import java.util.ArrayList; +import java.util.HashMap; import org.simantics.sysdyn.representation.Configuration; import org.simantics.sysdyn.representation.Dependency; import org.simantics.sysdyn.representation.IElement; +import org.simantics.sysdyn.representation.Input; import org.simantics.sysdyn.representation.Module; import org.simantics.sysdyn.representation.ModuleType; import org.simantics.sysdyn.representation.Stock; +import org.simantics.sysdyn.representation.IndependentVariable; import org.simantics.sysdyn.representation.Variable; import org.simantics.sysdyn.representation.expressions.IExpression; import org.simantics.sysdyn.representation.expressions.WithLookupExpression; @@ -58,20 +61,30 @@ public class ModelicaWriter { configuration.update(); - ArrayList variables = new ArrayList(); + ArrayList variables = new ArrayList(); + ArrayList inputs = new ArrayList(); ArrayList modules = new ArrayList(); ArrayList stocks = new ArrayList(); ArrayList inputDependencies = new ArrayList(); ArrayList outputDependencies = new ArrayList(); - + HashMap> moduleInputs = new HashMap>(); + // Initialize lists for(IElement element : configuration.getElements()) { - if(element instanceof Variable) { - variables.add((Variable)element); + if(element instanceof IndependentVariable) { + variables.add((IndependentVariable)element); if(element instanceof Stock) stocks.add((Stock)element); } else if (element instanceof Module) { - modules.add((Module)element); + Module m = (Module)element; + modules.add(m); + ArrayList inputsInModule = new ArrayList(); + for(IElement e : m.getType().getConfiguration().getElements()) + if(e instanceof Input && ((Input)e).isInput()) + inputsInModule.add((Input)e); + moduleInputs.put(m, inputsInModule); + } else if (element instanceof Input) { + inputs.add((Input)element); } else if (element instanceof Dependency && ((Dependency)element).refersTo() != null) { Dependency dependency = (Dependency)element; if(dependency.getHead() instanceof Module) { @@ -88,8 +101,8 @@ public class ModelicaWriter { b.append("class ").append(className).append('\n'); b.append("// Variable definitions\n"); - for(Variable variable : variables) { - IExpression expr = (variable).getExpression(); + for(IndependentVariable variable : variables) { + IExpression expr = variable.getExpression(); if(expr != null && insertInterpolate == false) { app = expr.getDeclaration(variable); if (app != null) b.append(app); @@ -103,7 +116,14 @@ public class ModelicaWriter { b.append(" " + m.getType().getName() + " " + m.getLabel() + ";\n"); } } - + + if(!inputs.isEmpty()) { + b.append("// Input definitions\n"); + for(Input i : inputs) { + b.append(" " + i.getType() + " " + i.getName() + ";\n"); + } + } + for(Stock stock : stocks) { IExpression expr = stock.getExpression(); if(expr != null) { @@ -122,7 +142,7 @@ public class ModelicaWriter { b.append("equation\n"); b.append("// Equations\n"); - for(Variable variable : variables) { + for(IndependentVariable variable : variables) { IExpression expr = variable.getExpression(); if(expr != null) { app = expr.getEquation(variable); @@ -133,7 +153,7 @@ public class ModelicaWriter { b.append("// Inputs\n"); for(Dependency dependency : inputDependencies) { - Variable variable = (Variable)dependency.getHead(); + Input variable = (Input)dependency.getHead(); Module module = (Module)dependency.getTail(); Variable reference = (Variable)dependency.refersTo(); b.append(" " + variable.getName() + " = " + module.getLabel() + "." + reference.getName() + ";\n"); @@ -143,10 +163,18 @@ public class ModelicaWriter { for(Dependency dependency : outputDependencies) { Variable variable = (Variable)dependency.getTail(); Module module = (Module)dependency.getHead(); - Variable reference = (Variable)dependency.refersTo(); + Input reference = (Input)dependency.refersTo(); b.append(" " + module.getLabel() + "." + reference.getName() + " = " + variable.getName() + ";\n"); + moduleInputs.get(module).remove(reference); } - + + b.append("// Default values for inputs in modules\n"); + for(Module module : moduleInputs.keySet()) { + for(Input input : moduleInputs.get(module)) { + b.append(" " + module.getLabel() + "." + input.getName() + " = " + input.getDefaultInputValue() + ";\n"); + } + } + b.append("end ").append(className).append(";\n\n"); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Auxiliary.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Auxiliary.java index a79be278..d4aae21f 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Auxiliary.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Auxiliary.java @@ -15,7 +15,7 @@ import org.simantics.objmap.annotations.GraphType; import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; @GraphType("http://www.simantics.org/Sysdyn-1.0/Auxiliary") -public class Auxiliary extends Variable { +public class Auxiliary extends IndependentVariable { @Override public void accept(IElementVisitorVoid v) { v.visit(this); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java index e59128a8..77e632bf 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java @@ -54,10 +54,10 @@ public class Configuration { IElementVisitorVoid updateVisitor = new ElementVisitorVoidAdapter() { public void visit(Flow flow) { if(flow.getHead() instanceof Stock) { - ((Stock)flow.getHead()).incomingFlows.add((Variable)flow.getTail()); + ((Stock)flow.getHead()).incomingFlows.add((IndependentVariable)flow.getTail()); } else if(flow.getTail() instanceof Stock) { - ((Stock)flow.getTail()).outgoingFlows.add((Variable)flow.getHead()); + ((Stock)flow.getTail()).outgoingFlows.add((IndependentVariable)flow.getHead()); } } }; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/InputExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IndependentVariable.java similarity index 58% rename from org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/InputExpression.java rename to org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IndependentVariable.java index 84590be6..24aa1f16 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/InputExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IndependentVariable.java @@ -9,17 +9,17 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.representation.expressions; +package org.simantics.sysdyn.representation; -import org.simantics.objmap.annotations.GraphType; -import org.simantics.sysdyn.representation.Variable; +import org.simantics.objmap.annotations.RelatedElement; +import org.simantics.sysdyn.representation.expressions.IExpression; -@GraphType("http://www.simantics.org/Sysdyn-1.0/InputExpression") -public class InputExpression extends Expression { +public abstract class IndependentVariable extends Variable { - @Override - public String getDeclaration(Variable variable) { - return " " + variable.getType() + " " + variable.getName() + ";\n"; + @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasExpression") + protected IExpression expression; + + public IExpression getExpression() { + return this.expression; } - } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Input.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Input.java new file mode 100644 index 00000000..b280fe0a --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Input.java @@ -0,0 +1,29 @@ +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.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Sysdyn-1.0/Input") +public class Input extends Variable { + + @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasDefaultInputValue") + private Double defaultInputValue; + @RelatedElement("http://www.simantics.org/Sysdyn-1.0/IsInput") + private IElement isInput; + + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } + + public String getDefaultInputValue() { + return defaultInputValue.toString(); + } + + public boolean isInput() { + return isInput != null; + } + +} 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 b28a7ffe..7aed35d3 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java @@ -21,9 +21,6 @@ public class Module implements IElement { @RelatedElement("http://www.simantics.org/Layer0-1.0/InstanceOf") private ModuleType type; - @RelatedElement("http://www.simantics.org/Structural-1.0/IsDefinedBy") - private Configuration configuration; - IElementVisitorVoid clearVisitor = new ElementVisitorVoidAdapter() { public void visit(Stock stock) { stock.incomingFlows.clear(); @@ -34,10 +31,10 @@ public class Module implements IElement { IElementVisitorVoid updateVisitor = new ElementVisitorVoidAdapter() { public void visit(Flow flow) { if(flow.getHead() instanceof Stock) { - ((Stock)flow.getHead()).incomingFlows.add((Variable)flow.getTail()); + ((Stock)flow.getHead()).incomingFlows.add((IndependentVariable)flow.getTail()); } else if(flow.getTail() instanceof Stock) { - ((Stock)flow.getTail()).outgoingFlows.add((Variable)flow.getHead()); + ((Stock)flow.getTail()).outgoingFlows.add((IndependentVariable)flow.getHead()); } } }; @@ -64,7 +61,4 @@ public class Module implements IElement { return this.parentConfiguration; } - public Configuration getConfiguration() { - return this.configuration; - } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ModuleType.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ModuleType.java index af934555..bbf7277e 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ModuleType.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ModuleType.java @@ -1,6 +1,7 @@ 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.representation.visitors.IElementVisitorVoid; @@ -9,10 +10,17 @@ public class ModuleType implements IElement { @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName") private String name; + + @RelatedElement("http://www.simantics.org/Structural-1.0/IsDefinedBy") + private Configuration configuration; public String getName() { return name; } + + public Configuration getConfiguration() { + return this.configuration; + } @Override public void accept(IElementVisitorVoid v) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Stock.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Stock.java index 4d522590..906fb094 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Stock.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Stock.java @@ -17,9 +17,9 @@ import org.simantics.objmap.annotations.GraphType; import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; @GraphType("http://www.simantics.org/Sysdyn-1.0/Stock") -public class Stock extends Variable { - public ArrayList incomingFlows = new ArrayList(2); - public ArrayList outgoingFlows = new ArrayList(2); +public class Stock extends IndependentVariable { + public ArrayList incomingFlows = new ArrayList(2); + public ArrayList outgoingFlows = new ArrayList(2); public Stock() { name = "Valve" + hashCode(); // FIXME 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 877401e2..c837a3ca 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java @@ -16,7 +16,6 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.objmap.schema.MappingSchemas; import org.simantics.objmap.schema.SimpleSchema; import org.simantics.sysdyn.representation.expressions.ConstantExpression; -import org.simantics.sysdyn.representation.expressions.InputExpression; import org.simantics.sysdyn.representation.expressions.LookupExpression; import org.simantics.sysdyn.representation.expressions.NormalExpression; import org.simantics.sysdyn.representation.expressions.ParameterExpression; @@ -35,9 +34,9 @@ public class SysdynSchema extends SimpleSchema { addLinkType(MappingSchemas.fromAnnotations(g, Stock.class)); addLinkType(MappingSchemas.fromAnnotations(g, Valve.class)); addLinkType(MappingSchemas.fromAnnotations(g, Module.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Input.class)); addLinkType(MappingSchemas.fromAnnotations(g, ModuleType.class)); addLinkType(MappingSchemas.fromAnnotations(g, NormalExpression.class)); - addLinkType(MappingSchemas.fromAnnotations(g, InputExpression.class)); addLinkType(MappingSchemas.fromAnnotations(g, ParameterExpression.class)); addLinkType(MappingSchemas.fromAnnotations(g, StockExpression.class)); addLinkType(MappingSchemas.fromAnnotations(g, ConstantExpression.class)); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Valve.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Valve.java index d4d8dbee..5773fc47 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Valve.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Valve.java @@ -15,7 +15,7 @@ import org.simantics.objmap.annotations.GraphType; import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; @GraphType("http://www.simantics.org/Sysdyn-1.0/Valve") -public class Valve extends Variable { +public class Valve extends IndependentVariable { @Override public void accept(IElementVisitorVoid v) { v.visit(this); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variable.java index e18bd33e..c77814ec 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variable.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variable.java @@ -1,45 +1,26 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.RelatedElement; import org.simantics.objmap.annotations.RelatedValue; -import org.simantics.sysdyn.representation.expressions.IExpression; public abstract class Variable implements IElement { - @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName") - protected String name; + @RelatedValue("http://www.simantics.org/Layer0-1.0/HasType") protected String type; - @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasExpression") - protected IExpression expression; + @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName") + protected String name; @RelatedElement("http://www.simantics.org/Layer0-1.0/PartOf") protected Configuration configuration; - - public String getName() { return this.name; } - - public String getType() { - return this.type; - } - - public IExpression getExpression() { - return this.expression; - } public Configuration getParentConfiguration() { return this.configuration; } + + public String getType() { + return this.type; + } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ConstantExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ConstantExpression.java index cb845067..1491a72a 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ConstantExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ConstantExpression.java @@ -13,7 +13,7 @@ package org.simantics.sysdyn.representation.expressions; import org.simantics.objmap.annotations.GraphType; import org.simantics.objmap.annotations.RelatedValue; -import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.representation.IndependentVariable; @GraphType("http://www.simantics.org/Sysdyn-1.0/ConstantExpression") public class ConstantExpression extends Expression { @@ -22,7 +22,7 @@ public class ConstantExpression extends Expression { private String equation; @Override - public String getDeclaration(Variable variable) { + public String getDeclaration(IndependentVariable variable) { StringBuilder b = new StringBuilder(); b.append(" constant " + variable.getType() + " " + variable.getName()); b.append(" = " + equation + ";\n"); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expression.java index 887438cf..c8d77e34 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expression.java @@ -11,22 +11,22 @@ *******************************************************************************/ package org.simantics.sysdyn.representation.expressions; -import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.representation.IndependentVariable; public abstract class Expression implements IExpression { @Override - public String getDeclaration(Variable variable) { + public String getDeclaration(IndependentVariable variable) { return null; } @Override - public String getEquation(Variable variable) { + public String getEquation(IndependentVariable variable) { return null; } @Override - public String getInitialEquation(Variable variable) { + public String getInitialEquation(IndependentVariable variable) { return null; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/IExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/IExpression.java index 1481f4b4..0bf75a77 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/IExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/IExpression.java @@ -11,12 +11,12 @@ *******************************************************************************/ package org.simantics.sysdyn.representation.expressions; -import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.representation.IndependentVariable; public interface IExpression { - String getDeclaration(Variable variable); - String getInitialEquation(Variable variable); - String getEquation(Variable variable); + String getDeclaration(IndependentVariable variable); + String getInitialEquation(IndependentVariable variable); + String getEquation(IndependentVariable variable); } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/NormalExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/NormalExpression.java index e08a4594..fa83da50 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/NormalExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/NormalExpression.java @@ -13,7 +13,7 @@ package org.simantics.sysdyn.representation.expressions; import org.simantics.objmap.annotations.GraphType; import org.simantics.objmap.annotations.RelatedValue; -import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.representation.IndependentVariable; @GraphType("http://www.simantics.org/Sysdyn-1.0/NormalExpression") public class NormalExpression extends Expression { @@ -22,12 +22,12 @@ public class NormalExpression extends Expression { private String equation; @Override - public String getDeclaration(Variable variable) { + public String getDeclaration(IndependentVariable variable) { return " " + variable.getType() + " " + variable.getName() + ";\n"; } @Override - public String getEquation(Variable variable) { + public String getEquation(IndependentVariable variable) { return " " + variable.getName() + " = " + equation + ";\n"; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ParameterExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ParameterExpression.java index cb11e661..6a92d4c1 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ParameterExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ParameterExpression.java @@ -13,7 +13,7 @@ package org.simantics.sysdyn.representation.expressions; import org.simantics.objmap.annotations.GraphType; import org.simantics.objmap.annotations.RelatedValue; -import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.representation.IndependentVariable; @GraphType("http://www.simantics.org/Sysdyn-1.0/ParameterExpression") public class ParameterExpression extends Expression { @@ -22,7 +22,7 @@ public class ParameterExpression extends Expression { private String equation; @Override - public String getDeclaration(Variable variable) { + public String getDeclaration(IndependentVariable variable) { StringBuilder b = new StringBuilder(); b.append(" parameter " + variable.getType() + " " + variable.getName()); b.append(" = " + equation + ";\n"); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java index 20bf189b..afcccc56 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java @@ -14,7 +14,7 @@ package org.simantics.sysdyn.representation.expressions; import org.simantics.objmap.annotations.GraphType; import org.simantics.objmap.annotations.RelatedValue; import org.simantics.sysdyn.representation.Stock; -import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.representation.IndependentVariable; @GraphType("http://www.simantics.org/Sysdyn-1.0/StockExpression") public class StockExpression extends Expression { @@ -23,7 +23,7 @@ public class StockExpression extends Expression { private String initialEquation; @Override - public String getDeclaration(Variable variable) { + public String getDeclaration(IndependentVariable variable) { Double value = null; try { value = Double.parseDouble(initialEquation); @@ -39,21 +39,21 @@ public class StockExpression extends Expression { } @Override - public String getEquation(Variable variable) { + public String getEquation(IndependentVariable variable) { StringBuilder b = new StringBuilder(); b.append(" der(") .append(variable.getName()) .append(") ="); - for(Variable flow : ((Stock)variable).incomingFlows) + for(IndependentVariable flow : ((Stock)variable).incomingFlows) b.append("\n + ").append(flow.getName()); - for(Variable flow : ((Stock)variable).outgoingFlows) + for(IndependentVariable flow : ((Stock)variable).outgoingFlows) b.append("\n - ").append(flow.getName()); b.append(";\n"); return b.toString(); } @Override - public String getInitialEquation(Variable variable) { + public String getInitialEquation(IndependentVariable variable) { Double value = null; try { value = Double.parseDouble(initialEquation); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/WithLookupExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/WithLookupExpression.java index 81eb5be6..017a11bf 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/WithLookupExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/WithLookupExpression.java @@ -13,7 +13,7 @@ package org.simantics.sysdyn.representation.expressions; import org.simantics.objmap.annotations.GraphType; import org.simantics.objmap.annotations.RelatedValue; -import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.representation.IndependentVariable; @GraphType("http://www.simantics.org/Sysdyn-1.0/WithLookupExpression") @@ -25,12 +25,12 @@ public class WithLookupExpression extends Expression { private String equation; @Override - public String getDeclaration(Variable variable) { + public String getDeclaration(IndependentVariable variable) { return " " + variable.getType() + " " + variable.getName() + ";\n"; } @Override - public String getEquation(Variable variable) { + public String getEquation(IndependentVariable variable) { return " " + variable.getName() + " = Interpolate(table = " + lookupTable + ", xp = " + equation + ");\n"; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java index b5f37225..fc6168de 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java @@ -16,6 +16,7 @@ import org.simantics.sysdyn.representation.Cloud; import org.simantics.sysdyn.representation.Configuration; import org.simantics.sysdyn.representation.Dependency; import org.simantics.sysdyn.representation.Flow; +import org.simantics.sysdyn.representation.Input; import org.simantics.sysdyn.representation.Module; import org.simantics.sysdyn.representation.Stock; import org.simantics.sysdyn.representation.Valve; @@ -38,6 +39,10 @@ public class ElementVisitorVoidAdapter implements IElementVisitorVoid { public void visit(Cloud cloud) { } + @Override + public void visit(Input input) { + } + @Override public void visit(Dependency dependency) { } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java index a80acc0d..0f1f2e14 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java @@ -16,6 +16,7 @@ import org.simantics.sysdyn.representation.Cloud; import org.simantics.sysdyn.representation.Configuration; import org.simantics.sysdyn.representation.Dependency; import org.simantics.sysdyn.representation.Flow; +import org.simantics.sysdyn.representation.Input; import org.simantics.sysdyn.representation.Module; import org.simantics.sysdyn.representation.Stock; import org.simantics.sysdyn.representation.Valve; @@ -26,6 +27,7 @@ public interface IElementVisitorVoid { void visit(Stock stock); void visit(Valve valve); void visit(Cloud cloud); + void visit(Input input); void visit(Dependency dependency); void visit(Flow flow); void visit(Module module); diff --git a/sysdyn_ontologies/sysdyn.graph b/sysdyn_ontologies/sysdyn.graph index 863918a3..ca34717e 100644 --- a/sysdyn_ontologies/sysdyn.graph +++ b/sysdyn_ontologies/sysdyn.graph @@ -128,6 +128,7 @@ DefaultRealization