From: lempinen Date: Tue, 7 May 2013 12:13:46 +0000 (+0000) Subject: Allow shadow variables to provide values (of the original variables) to modules.... X-Git-Tag: 1.8.1~309 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=ff96730481de7b3014e26540639eaa63a9fd8685;p=simantics%2Fsysdyn.git Allow shadow variables to provide values (of the original variables) to modules. (fixes #4273) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27317 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/CreateVariablesShortcutParticipant.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/CreateVariablesShortcutParticipant.java index e518828c..7866f7d8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/CreateVariablesShortcutParticipant.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/CreateVariablesShortcutParticipant.java @@ -48,6 +48,7 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.elements.AuxiliaryFactory; import org.simantics.sysdyn.ui.elements.CloudFactory; import org.simantics.sysdyn.ui.elements.InputFactory; +import org.simantics.sysdyn.ui.elements.ShadowFactory; import org.simantics.sysdyn.ui.elements.StockFactory; import org.simantics.sysdyn.ui.elements.ValveFactory; import org.simantics.ui.SimanticsUI; @@ -153,7 +154,13 @@ public class CreateVariablesShortcutParticipant extends AbstractDiagramParticipa SysdynResource.URIs.InputSymbol, (ShapeNode)InputFactory.INPUT_IMAGE.init(parent) ); - } + } else if (kpe.keyCode == java.awt.event.KeyEvent.VK_G) { + variableInformation = new VariableInformation( + java.awt.event.KeyEvent.VK_G, + SysdynResource.URIs.ShadowSymbol, + (ShapeNode)ShadowFactory.GHOST_IMAGE.init(parent) + ); + } if (variableInformation != null) { updateSG(); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java index 93ff24b0..8e615863 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java @@ -54,7 +54,8 @@ public class SysdynComponentCopyAdvisor extends ComponentCopyAdvisor { return StatementEvaluation.INCLUDE; else return StatementEvaluation.INCLUDE_AND_FOLLOW; - } + } else if(statement.getPredicate().equals(SYSDYN.Shadow_original)) + return StatementEvaluation.INCLUDE; } catch (ServiceException e) { e.printStackTrace(); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java index 1b4b7a79..9182e3b1 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java @@ -271,6 +271,7 @@ public class SysdynConnectTool extends ConnectTool2 { Resource start = soa.adapt(Resource.class); if(g.isInheritedFrom(start, sr.ModuleSymbol) && !end.equals(sr.InputSymbol)) return null; if(end.equals(sr.StockSymbol)) return null; + if(end.equals(sr.ShadowSymbol)) return null; } else if (currentConnection.equals(flow)) { if(!(end.equals(sr.StockSymbol) || end.equals(sr.ValveSymbol) || end.equals(sr.CloudSymbol))) return null; } else { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ModuleInputEditingSupport.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ModuleInputEditingSupport.java index 0fc9588d..42a751a1 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ModuleInputEditingSupport.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ModuleInputEditingSupport.java @@ -74,7 +74,13 @@ public class ModuleInputEditingSupport extends EditingSupport { if(graph.getPossibleObject(dependency, sr.Dependency_refersTo) == null || graph.getPossibleObject(dependency, sr.Dependency_refersTo).equals(inputVariable)) { Resource output = graph.getSingleObject(dependency, sr.Variable_HasTail); - result.put((String)graph.getRelatedValue(output, l0.HasName), dependency); + + if(graph.isInstanceOf(output, sr.Shadow)) { + output = graph.getPossibleObject(output, sr.Shadow_original); + } + + if(output != null) + result.put((String)graph.getRelatedValue(output, l0.HasName), dependency); } } return result; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceRow.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceRow.java index bab8583c..e6685123 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceRow.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceRow.java @@ -76,8 +76,13 @@ public class ReferenceRow { Resource valueResource = graph.getPossibleObject(dependency, sr.Variable_HasTail); if(!graph.isInstanceOf(valueResource, sr.Variable)) valueResource = graph.getPossibleObject(dependency, sr.Variable_HasHead); - if(!graph.isInstanceOf(valueResource, sr.Variable)) + + if(graph.isInstanceOf(valueResource, sr.Shadow)) + valueResource = graph.getPossibleObject(valueResource, sr.Shadow_original); + + if(valueResource == null || !graph.isInstanceOf(valueResource, sr.Variable)) return ""; + return (String)graph.getRelatedValue(valueResource, l0.HasName, Bindings.STRING); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnitFunction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnitFunction.java index c01fbadf..3e7d30fb 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnitFunction.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnitFunction.java @@ -119,6 +119,8 @@ public class UnitFunction { Resource reference = graph.getPossibleObject(outputRelation, SR.Dependency_refersTo); if(reference != null) { Resource output = graph.getPossibleObject(outputRelation, SR.Variable_HasHead); + if(output == null) + continue; String left = graph.getPossibleRelatedValue(output, SR.Variable_unit); String right = graph.getPossibleRelatedValue(reference, SR.Variable_unit); result = UnitUtils.matchUnits(left, right); @@ -130,6 +132,8 @@ public class UnitFunction { Resource reference = graph.getPossibleObject(inputRelation, SR.Dependency_refersTo); if(reference != null) { Resource variable = graph.getPossibleObject(inputRelation, SR.Variable_HasTail); + if(variable == null) + continue; String left = graph.getPossibleRelatedValue(variable, SR.Variable_unit); String right = graph.getPossibleRelatedValue(reference, SR.Variable_unit); result = UnitUtils.matchUnits(left, right); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java index 62b678ac..688ba1f7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java @@ -210,6 +210,7 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen DiagramResource dr = DiagramResource.getInstance(g); if(runtime == null) return null; Resource resource = ModelingUtils.getPossibleElementCorrespondendence(g, element); + if(resource != null && g.isInstanceOf(resource, sr.Shadow)) resource = g.getPossibleObject(resource, sr.Shadow_original); if(resource == null || !g.isInstanceOf(resource, sr.Variable)) return null; String variableURI = g.getPossibleRelatedValue(runtime, dr.RuntimeDiagram_HasVariable); if(variableURI != 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 15a8b729..9d55df02 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java @@ -161,6 +161,9 @@ public class Module implements IElement { if(dependency.getHead().equals(this)){ Input reference = (Input)dependency.refersTo(); Variable outputVariable = (Variable)dependency.getTail(); + if(outputVariable instanceof Shadow) + outputVariable = ((Shadow) outputVariable).getOriginal(); + String name = outputVariable.getName(); Module module = (Module)dependency.getHead(); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Shadow.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Shadow.java new file mode 100644 index 00000000..b652f801 --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Shadow.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2013 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: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import java.util.ArrayList; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElement; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.representation.expressions.IExpression; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType(SysdynResource.URIs.Shadow) +public class Shadow extends Variable { + + @RelatedElement(SysdynResource.URIs.Shadow_original) + private Variable original; + + @Override + public void accept(IElementVisitorVoid v) { + if(getOriginal() != null) + original.accept(v); + } + + public Variable getOriginal() { + return original; + } + + @Override + public String getName() { + if(getOriginal() != null) + return getOriginal().getName(); + else + return super.getName(); + } + + @Override + public ArrayList getArrayIndexes() { + if(getOriginal() != null) + return getOriginal().getArrayIndexes(); + else + return super.getArrayIndexes(); + } + + @Override + public ArrayList getExpressions() { + if(getOriginal() != null) + return getOriginal().getExpressions(); + else + return super.getExpressions(); + } + + @Override + public String getVariability() { + if(getOriginal() != null) + return getOriginal().getVariability(); + else + return super.getVariability(); + } + + @Override + public String getType() { + if(getOriginal() != null) + return getOriginal().getType(); + else + return super.getType(); + } + + @Override + public String getUnit() { + if(getOriginal() != null) + return getOriginal().getUnit(); + else + return super.getUnit(); + } + +} + 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 9d4eab26..4d47a8c5 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java @@ -57,6 +57,7 @@ public class SysdynSchema extends SimpleSchema { addLinkType(MappingSchemas.fromAnnotations(g, Function.class)); addLinkType(MappingSchemas.fromAnnotations(g, Entity.class)); addLinkType(MappingSchemas.fromAnnotations(g, ParameterOverride.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Shadow.class)); } catch (DatabaseException e) { e.printStackTrace(); } catch (InstantiationException e) { 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 64c7d287..b48955c4 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 @@ -12,6 +12,7 @@ package org.simantics.sysdyn.representation.visitors; import org.simantics.sysdyn.representation.Auxiliary; +import org.simantics.sysdyn.representation.Book; import org.simantics.sysdyn.representation.Cloud; import org.simantics.sysdyn.representation.Configuration; import org.simantics.sysdyn.representation.Dependency; @@ -21,9 +22,9 @@ import org.simantics.sysdyn.representation.Flow; import org.simantics.sysdyn.representation.Input; import org.simantics.sysdyn.representation.LibraryDummy; import org.simantics.sysdyn.representation.Module; -import org.simantics.sysdyn.representation.Book; import org.simantics.sysdyn.representation.Stock; import org.simantics.sysdyn.representation.Valve; +import org.simantics.sysdyn.representation.Variable; public class ElementVisitorVoidAdapter implements IElementVisitorVoid { @@ -78,4 +79,8 @@ public class ElementVisitorVoidAdapter implements IElementVisitorVoid { @Override public void visit(DiagramContainerDummy container) { } + + @Override + public void visit(Variable variable) { + } } 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 3c78343b..a15028dc 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 @@ -12,6 +12,7 @@ package org.simantics.sysdyn.representation.visitors; import org.simantics.sysdyn.representation.Auxiliary; +import org.simantics.sysdyn.representation.Book; import org.simantics.sysdyn.representation.Cloud; import org.simantics.sysdyn.representation.Configuration; import org.simantics.sysdyn.representation.Dependency; @@ -21,9 +22,9 @@ import org.simantics.sysdyn.representation.Flow; import org.simantics.sysdyn.representation.Input; import org.simantics.sysdyn.representation.LibraryDummy; import org.simantics.sysdyn.representation.Module; -import org.simantics.sysdyn.representation.Book; import org.simantics.sysdyn.representation.Stock; import org.simantics.sysdyn.representation.Valve; +import org.simantics.sysdyn.representation.Variable; public interface IElementVisitorVoid { @@ -40,4 +41,5 @@ public interface IElementVisitorVoid { void visit(LibraryDummy libraryDummy); void visit(Book sheet); void visit(DiagramContainerDummy container); + void visit(Variable variable); }