From 1d88840d47716b71e1dc0d0e3ffdabdb20b7dd60 Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 12 May 2011 06:20:07 +0000 Subject: [PATCH] git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches/simantics-1.4@20884 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.objmap/META-INF/MANIFEST.MF | 1 + .../objmap/annotations/RelatedValue.java | 5 +- .../factories/RelatedValueRuleFactory.java | 35 ++++-- .../rules/adapters/IdentityAdapter.java | 8 ++ .../objmap/rules/adapters/ValueAdapter.java | 4 + org.simantics.sysdyn.ui/plugin.xml | 48 +++++++++ .../elements2/HoverTextElementNoBounds.java | 22 ++-- .../sysdyn/ui/elements2/HoverTextNode.java | 5 +- .../sysdyn/ui/elements2/ModuleFactory.java | 25 ++++- .../sysdyn/ui/elements2/ModuleNode.java | 100 ++++++++++++++++++ .../ui/handlers/EnumerationPasteHandler.java | 29 +++++ .../sysdyn/ui/properties/EnumerationTab.java | 23 +++- .../sysdyn/ui/utils/ExpressionUtils.java | 5 +- .../sysdyn/modelica/ModelicaWriter.java | 15 ++- 14 files changed, 292 insertions(+), 33 deletions(-) create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleNode.java create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/EnumerationPasteHandler.java diff --git a/org.simantics.objmap/META-INF/MANIFEST.MF b/org.simantics.objmap/META-INF/MANIFEST.MF index 89cfd50b..52d144d7 100644 --- a/org.simantics.objmap/META-INF/MANIFEST.MF +++ b/org.simantics.objmap/META-INF/MANIFEST.MF @@ -12,6 +12,7 @@ Export-Package: org.simantics.objmap, org.simantics.objmap.annotations, org.simantics.objmap.annotations.meta, org.simantics.objmap.rules, + org.simantics.objmap.rules.adapters, org.simantics.objmap.rules.domain, org.simantics.objmap.rules.factory, org.simantics.objmap.rules.range, diff --git a/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedValue.java b/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedValue.java index 98dfcca4..23d3e9a8 100644 --- a/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedValue.java +++ b/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedValue.java @@ -18,6 +18,8 @@ import java.lang.annotation.Target; import org.simantics.objmap.annotations.factories.RelatedValueRuleFactory; import org.simantics.objmap.annotations.meta.HasFieldRuleFactory; +import org.simantics.objmap.rules.adapters.IdentityAdapter; +import org.simantics.objmap.rules.adapters.ValueAdapter; /** * Specifies a correspondence between a field and @@ -28,5 +30,6 @@ import org.simantics.objmap.annotations.meta.HasFieldRuleFactory; @Target(ElementType.FIELD) @HasFieldRuleFactory(RelatedValueRuleFactory.class) public @interface RelatedValue { - String value(); + String value(); + Class adapter() default IdentityAdapter.class; } diff --git a/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedValueRuleFactory.java b/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedValueRuleFactory.java index 5843fb1b..828bb59f 100644 --- a/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedValueRuleFactory.java +++ b/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedValueRuleFactory.java @@ -15,29 +15,44 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Field; import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; import org.simantics.db.exception.ResourceNotFoundException; import org.simantics.db.exception.ServiceException; import org.simantics.db.exception.ValidationException; import org.simantics.objmap.IMappingRule; import org.simantics.objmap.annotations.RelatedValue; import org.simantics.objmap.rules.ValueRule; +import org.simantics.objmap.rules.adapters.IdentityAdapter; +import org.simantics.objmap.rules.adapters.ValueAdapter; import org.simantics.objmap.rules.domain.RelatedValueAccessor; import org.simantics.objmap.rules.factory.IFieldRuleFactory; +import org.simantics.objmap.rules.range.AdaptedRangeAccessor; import org.simantics.objmap.rules.range.FieldAccessor; +import org.simantics.objmap.rules.range.IRangeAccessor; public class RelatedValueRuleFactory implements IFieldRuleFactory { @Override - public IMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException { - RelatedValue annotation = (RelatedValue)_annotation; - //Builtins b = g.getBuiltins(); - return new ValueRule( - new RelatedValueAccessor( - g.getResource(annotation.value()), - DataTypeUtils.dataTypeOfClass(g, field.getType()) - ), - new FieldAccessor(field) - ); + public IMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, + ValidationException, ServiceException { + RelatedValue annotation = (RelatedValue) _annotation; + Class adapterClass = annotation.adapter(); + IRangeAccessor rangeAccessor = new FieldAccessor(field); + Resource valueType; + if (adapterClass == IdentityAdapter.class) { + valueType = DataTypeUtils.dataTypeOfClass(g, field.getType()); + } else { + try { + ValueAdapter adapter = adapterClass.newInstance(); + rangeAccessor = new AdaptedRangeAccessor(rangeAccessor, adapter); + valueType = adapter.rangeTypeToDomainType(g, field.getType()); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + return new ValueRule(new RelatedValueAccessor(g.getResource(annotation.value()), valueType), rangeAccessor); } } diff --git a/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java b/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java index 3d4b6913..913357b2 100644 --- a/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java +++ b/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java @@ -1,5 +1,8 @@ package org.simantics.objmap.rules.adapters; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + public enum IdentityAdapter implements ValueAdapter { INSTANCE; @@ -12,4 +15,9 @@ public enum IdentityAdapter implements ValueAdapter { public Object rangeToDomain(Object rangeValue) { return rangeValue; } + + @Override + public Resource rangeTypeToDomainType(ReadGraph graph, Class rangeType) { + return null; + } } diff --git a/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java b/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java index c8d0d2d0..85e40169 100644 --- a/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java +++ b/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java @@ -1,6 +1,10 @@ package org.simantics.objmap.rules.adapters; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + public interface ValueAdapter { + Resource rangeTypeToDomainType(ReadGraph graph, Class rangeType); Object domainToRange(Object domainValue); Object rangeToDomain(Object rangeValue); } diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 49de4a69..563a7dd3 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -870,6 +870,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java index 2b583a4a..1495974b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in + * Copyright (c) 2007, 2011 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 @@ -33,9 +33,9 @@ import org.simantics.scenegraph.g2d.G2DParentNode; import org.simantics.sysdyn.ui.utils.VariableNameUtils; import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.Callback; +import org.simantics.utils.datastructures.hints.IHintContext.Key; import org.simantics.utils.datastructures.hints.IHintListener; import org.simantics.utils.datastructures.hints.IHintObservable; -import org.simantics.utils.datastructures.hints.IHintContext.Key; /** * ElementHandler for text elements @@ -67,11 +67,14 @@ public class HoverTextElementNoBounds extends TextElementNoBounds { super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable); } - @Override - public void init(final IElement e, G2DParentNode parent) { - HoverTextNode node = ElementUtils.getOrCreateNode(e, parent, SG_NODE, "text", HoverTextNode.class, new Callback() { + protected HoverTextNode getTextNode(IElement e, G2DParentNode parent) { + return ElementUtils.getOrCreateNode(e, parent, SG_NODE, "text", HoverTextNode.class, getCallback(e, parent, HoverTextNode.class)); + } + + protected Callback getCallback(final IElement e, G2DParentNode parent, Class nodeClass) { + return new Callback() { @Override - public void run(HoverTextNode node) { + public void run(T node) { node.setTextListener(new ITextListener() { String textBeforeEdit; @@ -149,7 +152,12 @@ public class HoverTextElementNoBounds extends TextElementNoBounds { } }); } - }); + }; + } + + @Override + public void init(final IElement e, G2DParentNode parent) { + HoverTextNode node = getTextNode(e, parent); //Font font = new Font("Tahoma", 0, 12); Font font = ElementUtils.getTextFont(e); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextNode.java index f3d3e0d7..7b4f2463 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextNode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in + * Copyright (c) 2007, 2011 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 @@ -18,7 +18,6 @@ import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import org.simantics.diagram.elements.TextNode; -import org.simantics.g2d.utils.Alignment; import org.simantics.scenegraph.ISelectionPainterNode; import org.simantics.scenegraph.utils.NodeUtil; @@ -26,7 +25,7 @@ public class HoverTextNode extends TextNode implements ISelectionPainterNode { private static final long serialVersionUID = 3539499125943249895L; - private static transient ThreadLocal tempBounds = new ThreadLocal() { + protected static transient ThreadLocal tempBounds = new ThreadLocal() { @Override protected Rectangle2D initialValue() { return new Rectangle2D.Double(); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleFactory.java index e7321734..678f63e8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in + * Copyright (c) 2007, 2011 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 @@ -18,6 +18,9 @@ import java.util.Collection; import org.simantics.db.Resource; import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.InternalSize; import org.simantics.g2d.element.handler.impl.BoundsOutline; import org.simantics.g2d.element.handler.impl.DefaultTransform; import org.simantics.g2d.element.handler.impl.ObjectTerminal; @@ -32,10 +35,11 @@ import org.simantics.g2d.element.handler.impl.TextImpl; import org.simantics.g2d.image.Image; import org.simantics.g2d.image.impl.ShapeImage; import org.simantics.g2d.utils.Alignment; +import org.simantics.scenegraph.g2d.G2DParentNode; public class ModuleFactory extends SysdynElementFactory { - private static final BasicStroke STROKE = new BasicStroke(1f); + private static final BasicStroke STROKE = new BasicStroke(2.0f); private static final Image DEFAULT_IMAGE = new ShapeImage(new Rectangle2D.Double(-5, -2.5, 10, 5), null, STROKE, true); @Override @@ -50,10 +54,25 @@ public class ModuleFactory extends SysdynElementFactory { new StaticObjectAdapter(elementType), new StaticSymbolImpl(DEFAULT_IMAGE), StaticSymbolImageInitializer.INSTANCE, - new HoverTextElementHandler(0, 0, Alignment.LEADING, 1f , 7, 7, true), + new ModuleSceneGraph(0, 0, Alignment.LEADING, 1f , 4, 4, true), BoundsOutline.INSTANCE, new WholeElementTerminals(terminals) ).setId(ModuleFactory.class.getSimpleName()); } + + + public static class ModuleSceneGraph extends HoverTextElementHandler implements InternalSize { + private static final long serialVersionUID = 2367230056477661273L; + + public ModuleSceneGraph(double originX, double originY, Alignment horizontalAlignment, double borderWidth, + double paddingX, double paddingY, boolean editable) { + super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable); + } + + protected HoverTextNode getTextNode(IElement e, G2DParentNode parent) { + return ElementUtils.getOrCreateNode(e, parent, SG_NODE, "text", ModuleNode.class, getCallback(e, parent, ModuleNode.class)); + } + + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleNode.java new file mode 100644 index 00000000..6695543d --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleNode.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.elements2; + +import java.awt.AlphaComposite; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Composite; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; + +import org.simantics.scenegraph.utils.GeometryUtils; +import org.simantics.scenegraph.utils.NodeUtil; + +public class ModuleNode extends HoverTextNode { + + private static final long serialVersionUID = 8535695797227320496L; + private static double CORNER_LENGTH = 2.0; + private static double CORNER_PADDING = 0.8; + + + @Override + public void render(Graphics2D g) { + super.render(g); + + AffineTransform ot = g.getTransform(); + BasicStroke oldStroke = (BasicStroke)g.getStroke(); + Color oldColor = g.getColor(); + + + g.transform(transform); + + Rectangle2D bounds = expandBounds( alignBounds( getTightUnalignedBoundsInLocal( tempBounds.get() ) ) ); + + Path2D path = new Path2D.Double(); + // LEFT TOP + path.moveTo(bounds.getMinX() + CORNER_LENGTH, bounds.getMinY() - CORNER_PADDING); + path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMinY() - CORNER_PADDING); + path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMinY() + CORNER_LENGTH); + + // LEFT BOTTOM + path.moveTo(bounds.getMinX() + CORNER_LENGTH, bounds.getMaxY() + CORNER_PADDING); + path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMaxY() + CORNER_PADDING); + path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMaxY() - CORNER_LENGTH); + + // RIGHT TOP + path.moveTo(bounds.getMaxX() - CORNER_LENGTH, bounds.getMinY() - CORNER_PADDING); + path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMinY() - CORNER_PADDING); + path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMinY() + CORNER_LENGTH); + + // RIGHT BOTTOM + path.moveTo(bounds.getMaxX() - CORNER_LENGTH, bounds.getMaxY() + CORNER_PADDING); + path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMaxY() + CORNER_PADDING); + path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMaxY() - CORNER_LENGTH); + + g.translate(x, y); + g.setStroke(new BasicStroke((float) (scale*borderWidth))); + g.setColor(Color.GRAY); + g.draw(path); + + + boolean selected = NodeUtil.isSelected(this, 1); + if (selected && showSelection()) { + Composite oc = g.getComposite(); + g.setComposite(AlphaComposite.SrcAtop.derive(0.5f)); + + g.setColor(Color.RED); + float bw = borderWidth; + double s = GeometryUtils.getScale(g.getTransform()); + if (bw <= 0f) { + bw = (float) (1f / s); + } else { + bw *= 3f * scale; + } + g.setStroke(new BasicStroke(bw)); + g.draw(path); + //g.draw(GeometryUtils.expandRectangle(r, 1.0)); + + g.setComposite(oc); + } + + g.setColor(oldColor); + g.setStroke(oldStroke); + g.translate(-x, -y); + + g.setTransform(ot); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/EnumerationPasteHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/EnumerationPasteHandler.java new file mode 100644 index 00000000..a37cb37c --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/EnumerationPasteHandler.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; + +public class EnumerationPasteHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection sel = HandlerUtil.getCurrentSelection(event); + System.out.println("PASTE " + sel); + return null; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java index 3d88d849..589f0c36 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java @@ -1,5 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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 java.util.HashSet; import java.util.List; import org.eclipse.jface.layout.GridDataFactory; @@ -31,6 +43,7 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; @@ -164,11 +177,15 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge public void perform(WriteGraph graph) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); Layer0 l0 = Layer0.getInstance(graph); - - + + HashSet names = new HashSet(); + for(Resource r : OrderedSetUtils.toList(graph, enumerationIndexes)) { + names.add(NameUtils.getSafeName(graph, r)); + } + Resource ei = GraphUtils.create2(graph, sr.EnumerationIndex, - l0.HasName, "index"); + l0.HasName, NameUtils.findFreshName(graph, "index", names, "")); OrderedSetUtils.add(graph, enumerationIndexes, ei); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java index 5297a2f5..904378ba 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in + * Copyright (c) 2007, 2011 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 @@ -164,6 +164,9 @@ public class ExpressionUtils { } // VARIABLE NAMES + + if(variables.contains("time")) + variables.remove("time"); for(String v : variables) { if(!modelVariables.keySet().contains(v)) { 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 f1b60899..bd462953 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in + * Copyright (c) 2007, 2011 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 @@ -73,7 +73,7 @@ public class ModelicaWriter { inputs.add((Input)element); } else if (element instanceof Enumeration) { enumerations.add((Enumeration)element); - } else if (element instanceof Dependency && ((Dependency)element).refersTo() != null) { + } else if (element instanceof Dependency) { Dependency dependency = (Dependency)element; if(dependency.getHead() instanceof Module) { outputDependencies.add(dependency); @@ -141,7 +141,10 @@ public class ModelicaWriter { Input variable = (Input)dependency.getHead(); Module module = (Module)dependency.getTail(); Variable reference = (Variable)dependency.refersTo(); - b.append(" " + variable.getName() + " = " + module.getName() + "." + reference.getName() + ";\n"); + if(reference != null) + b.append(" " + variable.getName() + " = " + module.getName() + "." + reference.getName() + ";\n"); + else + b.append(" " + variable.getName() + " = " + variable.getDefaultInputValue() + ";\n"); } b.append("// Outputs\n"); @@ -149,8 +152,10 @@ public class ModelicaWriter { Variable variable = (Variable)dependency.getTail(); Module module = (Module)dependency.getHead(); Input reference = (Input)dependency.refersTo(); - b.append(" " + module.getName() + "." + reference.getName() + " = " + variable.getName() + ";\n"); - moduleInputs.get(module.getName()).remove(reference); + if(reference != null) { + b.append(" " + module.getName() + "." + reference.getName() + " = " + variable.getName() + ";\n"); + moduleInputs.get(module.getName()).remove(reference); + } } b.append("// Default values for inputs in modules\n"); -- 2.47.1