From 3b209a41267468f9d96a9ec4d58dad047f7e041a Mon Sep 17 00:00:00 2001 From: jkauttio Date: Mon, 10 Mar 2014 09:15:29 +0000 Subject: [PATCH] Attempt to fix a svn commit error refs #2924 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches/dev-jkauttio@29059 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/mdlImport/model/Auxiliary.java | 49 ---- .../sysdyn/mdlImport/model/Auxiliary2.java | 45 --- .../sysdyn/mdlImport/model/Cloud.java | 71 ----- .../sysdyn/mdlImport/model/Cloud2.java | 9 - .../sysdyn/mdlImport/model/Comment2.java | 5 - .../sysdyn/mdlImport/model/Connection.java | 98 ------- .../sysdyn/mdlImport/model/Connection2.java | 29 -- .../sysdyn/mdlImport/model/Dependency.java | 93 ------ .../sysdyn/mdlImport/model/Dependency2.java | 25 -- .../sysdyn/mdlImport/model/Element.java | 80 ----- .../sysdyn/mdlImport/model/Element2.java | 65 ----- .../mdlImport/model/EquivalenceSubscript.java | 37 --- .../sysdyn/mdlImport/model/Expression.java | 42 --- .../sysdyn/mdlImport/model/Flow.java | 33 --- .../sysdyn/mdlImport/model/Flow2.java | 21 -- .../sysdyn/mdlImport/model/Function.java | 61 ---- .../mdlImport/model/IWriteableMDLElement.java | 30 -- .../mdlImport/model/IWriteableMDLObject.java | 26 -- .../mdlImport/model/IWriteableObject.java | 26 -- .../sysdyn/mdlImport/model/Model.java | 275 ------------------ .../sysdyn/mdlImport/model/Model2.java | 94 ------ .../sysdyn/mdlImport/model/ModelVariable.java | 48 --- .../sysdyn/mdlImport/model/Range.java | 15 - .../sysdyn/mdlImport/model/Sketch2.java | 108 ------- .../sysdyn/mdlImport/model/SketchComment.java | 52 ---- .../mdlImport/model/SketchConnection.java | 64 ---- .../sysdyn/mdlImport/model/SketchElement.java | 39 --- .../sysdyn/mdlImport/model/SketchObject.java | 17 -- .../sysdyn/mdlImport/model/SketchValve.java | 29 -- .../mdlImport/model/SketchVariable.java | 53 ---- .../sysdyn/mdlImport/model/Stock.java | 79 ----- .../sysdyn/mdlImport/model/Stock2.java | 49 ---- .../sysdyn/mdlImport/model/Subscript.java | 67 ----- .../sysdyn/mdlImport/model/Valve.java | 45 --- .../sysdyn/mdlImport/model/Valve2.java | 17 -- .../sysdyn/mdlImport/model/Variable.java | 211 -------------- .../sysdyn/mdlImport/model/Variable2.java | 48 --- .../sysdyn/mdlImport/model/View.java | 134 --------- 38 files changed, 2289 deletions(-) delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Auxiliary.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Auxiliary2.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Cloud.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Cloud2.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Comment2.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Connection.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Connection2.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Dependency.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Dependency2.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Element.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Element2.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/EquivalenceSubscript.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Expression.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Flow.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Flow2.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Function.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/IWriteableMDLElement.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/IWriteableMDLObject.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/IWriteableObject.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Model.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Model2.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/ModelVariable.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Range.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Sketch2.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchComment.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchConnection.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchElement.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchObject.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchValve.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchVariable.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Stock.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Stock2.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Subscript.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Valve.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Valve2.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Variable.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Variable2.java delete mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/View.java diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Auxiliary.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Auxiliary.java deleted file mode 100644 index 663b1cfb..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Auxiliary.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.mdlImport.ImportUtils; - -public class Auxiliary extends Variable { - - @Override - public Resource getExpression(WriteGraph graph, Expression expression) throws DatabaseException { - - SysdynResource sr = SysdynResource.getInstance(graph); - Resource e = GraphUtils.create2(graph, - sr.NormalExpression, - sr.Expression_equation, ImportUtils.escapeExpression(expression.getExpression()).trim()); - return e; - } - - @Override - public void write(WriteGraph graph, Resource parent, double xOffset, - double yOffset) { - if(parent == null || graph == null) - return; - - try { - SysdynResource sr = SysdynResource.getInstance(graph); - if(!graph.isInstanceOf(parent, sr.Configuration)) - return; - createVariable(graph, parent, sr.Auxiliary, sr.AuxiliarySymbol, xOffset, yOffset); - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Auxiliary2.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Auxiliary2.java deleted file mode 100644 index e75d9450..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Auxiliary2.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -import java.util.Arrays; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.sysdyn.SysdynResource; - -public class Auxiliary2 extends ModelVariable { - - protected String equation; - - public Auxiliary2(double x, double y, - String name, String unit, Range range, String description, - String equation) { - this.equation = equation; - } - - public Auxiliary2(double x, double y, Variable2 variable, String equation) { - this.equation = equation; - } - - @Override - public void write(WriteGraph graph, Resource parent) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - SysdynResource sr = SysdynResource.getInstance(graph); - - Resource variable = createVariable(graph, sr.Auxiliary, parent); - - Resource expression = GraphUtils.create2(graph, sr.NormalExpression, - sr.Expression_equation, equation, - l0.PartOf, variable); - // TODO: why is the expressoin stored in two places? - graph.claim(variable, sr.Variable_expressionList, ListUtils.create(graph, Arrays.asList(expression))); - - createSymbol(graph, sr.AuxiliarySymbol, variable, parent); - - setResource(variable); - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Cloud.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Cloud.java deleted file mode 100644 index 143a93d4..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Cloud.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.utils.OrderedSetUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.diagram.stubs.G2DResource; -import org.simantics.layer0.Layer0; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.modeling.ModelingResources; -import org.simantics.sysdyn.SysdynResource; - -public class Cloud extends Element { - - @Override - public void write(WriteGraph graph, Resource parent, double xOffset, - double yOffset) { - if(parent == null || graph == null) - return; - - try { - SysdynResource sr = SysdynResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - ModelingResources mr = ModelingResources.getInstance(graph); - DiagramResource dr = DiagramResource.getInstance(graph); - G2DResource g2d = G2DResource.getInstance(graph); - - if(!graph.isInstanceOf(parent, sr.Configuration)) - return; - - Resource diagram = graph.getSingleObject(parent, mr.CompositeToDiagram); - - if(diagram == null) - return; - - Resource cloud = GraphUtils.create2(graph, - sr.Cloud); - - graph.claim(parent, l0.ConsistsOf, cloud); - - - - Resource symbol = GraphUtils.create2(graph, - sr.CloudSymbol, - mr.ElementToComponent, cloud); - - double[] transform = {1.0, 0.0, 0.0, 1.0, getX() + xOffset, getY() + yOffset}; - graph.claimLiteral(symbol, dr.HasTransform, g2d.Transform, transform); - - OrderedSetUtils.add(graph, diagram, symbol); - - setResource(cloud); - - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Cloud2.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Cloud2.java deleted file mode 100644 index fbf0c3ea..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Cloud2.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -public class Cloud2 extends Element2 { - - public Cloud2() { - - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Comment2.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Comment2.java deleted file mode 100644 index 7b93b96c..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Comment2.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -public class Comment2 extends Element2 { - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Connection.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Connection.java deleted file mode 100644 index 2e14ca90..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Connection.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.utils.OrderedSetUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.layer0.Layer0; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.modeling.ModelingResources; -import org.simantics.structural.stubs.StructuralResource2; -import org.simantics.sysdyn.SysdynResource; - -public abstract class Connection implements IWriteableMDLObject { - protected Element start, end; - - public Resource writeConnection(WriteGraph graph, Resource configuration, Resource connectionType, Resource connectionSymbol) throws DatabaseException { - if(configuration == null || graph == null - || start.getResource() == null || end.getResource() == null) { - return null; - } - SysdynResource sr = SysdynResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - ModelingResources mr = ModelingResources.getInstance(graph); - DiagramResource dr = DiagramResource.getInstance(graph); - StructuralResource2 sr2 = StructuralResource2.getInstance(graph); - - Resource diagram = graph.getPossibleObject(configuration, mr.CompositeToDiagram); - Resource startElement = graph.getPossibleObject(start.getResource(), mr.ComponentToElement); - Resource endElement = graph.getPossibleObject(end.getResource(), mr.ComponentToElement); - if(diagram == null || startElement == null || endElement == null) - return null; - - - if(connectionType == null) - connectionType = sr.Dependency; - - if(connectionSymbol == null) - connectionSymbol = sr.DependencyConnection; - - // Build the connection to configuration - Resource connection = GraphUtils.create2(graph, - connectionType, - sr.Variable_HasHead, end.getResource(), - sr.Variable_HasTail, start.getResource(), - l0.PartOf, configuration); - graph.claim(connection, mr.Mapped, connection); - - - // Build diagram connectors and connection - Resource tailConnector = GraphUtils.create2(graph, - dr.Connector, - sr.HasTailTerminal, startElement); - - Resource headConnector = GraphUtils.create2(graph, - dr.Connector, - sr.HasHeadTerminal, endElement, - dr.AreConnected, tailConnector); - - Resource diagramConnection = GraphUtils.create2(graph, - connectionSymbol, - sr2.HasConnectionType, sr.SysdynConnectionType, - mr.DiagramConnectionToConnection, connection, - dr.HasArrowConnector, headConnector, - dr.HasPlainConnector, tailConnector); - - OrderedSetUtils.add(graph, diagram, diagramConnection); - - return connection; - } - - public Element getStart() { - return start; - } - - public void setStart(Element start) { - this.start = start; - } - - public Element getEnd() { - return end; - } - - public void setEnd(Element end) { - this.end = end; - } -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Connection2.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Connection2.java deleted file mode 100644 index eb01d503..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Connection2.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; - -public abstract class Connection2 implements IWriteableObject { - - protected Element2 head; - protected Element2 tail; - - @Override - public void write(WriteGraph graph, Resource parent) throws DatabaseException { - System.err.println("Writing connection"); - } - - protected void writeConnection() { - - } - - public void setHead(Element2 head) { - this.head = head; - } - - public void setTail(Element2 tail) { - this.tail = tail; - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Dependency.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Dependency.java deleted file mode 100644 index b9b41d6e..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Dependency.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.modeling.ModelingResources; -import org.simantics.sysdyn.SysdynResource; - -public class Dependency extends Connection { - - private double angle; - - public Dependency() { - this(-0.1); - } - - public Dependency(double angle) { - this.angle = angle; - } - - @Override - public void write(WriteGraph graph, Resource parent) { - if(parent == null || graph == null || start == null || end == null) - return; - try { - SysdynResource sr = SysdynResource.getInstance(graph); - Resource connection = writeConnection(graph, parent, sr.Dependency, sr.DependencyConnection); - - if(connection != null) { - ModelingResources mr = ModelingResources.getInstance(graph); - Resource diagramConnection = graph.getSingleObject(connection, mr.ConnectionToDiagramConnection); - graph.claimLiteral(diagramConnection, sr.Dependency_angle, angle); - } - - } catch (DatabaseException e) { - e.printStackTrace(); - } - - } - - public double getAngle() { - return angle; - } - - public void setAngle(double angle) { - this.angle = angle; - } - - - - /** - * Returns an angle in radians between straight line from (x0,y0) to (x2,y2) - * and an arc from (x0,y0) to (x2,y2) thru (x1,y1). The angle - * is measured at (x0,y0) and is between -PI and PI. - */ - public static double angleOfArc( - double x0, double y0, - double x1, double y1, - double x2, double y2) { - double dx0 = x1-x0; - double dy0 = y1-y0; - double dx1 = x1-x2; - double dy1 = y1-y2; - double dx = x2-x0; - double dy = y2-y0; - // Length of cross product (p1-p0)x(p2-p0) - double dd = dx0*dy - dy0*dx; - - if(Math.abs(dd) < 1e-6) // Points are (almost) collinear - return 0.0; - else { - // (p1-p0)*(p1-p2) / dd - double offset = (dx0*dx1 + dy0*dy1) / dd; - double angle = Math.PI*0.5 - Math.atan(offset); - if(dd > 0.0) - angle = angle-Math.PI; - return angle; - - } - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Dependency2.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Dependency2.java deleted file mode 100644 index 14f2d5b0..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Dependency2.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -public class Dependency2 extends Connection2 { - - private boolean showArrow; - private boolean showDelay; - - public Dependency2(boolean showArrow, boolean showDelay) { - this.showArrow = showArrow; - this.showDelay = showDelay; - } - - @Override - public void setHead(Element2 head) { - // TODO: make sure head is of the right type - super.setHead(head); - } - - @Override - public void setTail(Element2 Tail) { - // TODO: make sure tail is of the right type - super.setTail(tail); - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Element.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Element.java deleted file mode 100644 index c431f201..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Element.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import java.util.ArrayList; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; - -public abstract class Element implements IWriteableMDLElement { - - protected int x, y; - protected Resource resource; - protected String name; - protected ArrayList connections; - - protected Resource getExpression(WriteGraph graph, Expression expression) - throws DatabaseException { - return null; - } - - public int getX() { - return x; - } - - public void setX(int x) { - this.x = x; - } - - public int getY() { - return y; - } - - public void setY(int y) { - this.y = y; - } - - public String getName() { - if(name == null) - return "Name"; - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Resource getResource() { - return resource; - } - - public void setResource(Resource resource) { - this.resource = resource; - } - - public ArrayList getConnections() { - if(connections == null) - connections = new ArrayList(); - return connections; - } - - public void setConnections(ArrayList connections) { - this.connections = connections; - } - - public void addConnection(Connection connection) { - getConnections().add(connection); - } -} - diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Element2.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Element2.java deleted file mode 100644 index b04010f6..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Element2.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -import org.simantics.databoard.Bindings; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.utils.OrderedSetUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.diagram.stubs.G2DResource; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.modeling.ModelingResources; - -public class Element2 implements IWriteableObject { - - private int x; - private int y; - - private Resource resource; - - public Element2() { - - } - - // public Element2(int x, int y, int width, int height) { - // this.x = x; - // this.y = y; - // this.width = width; - // this.height = height; - // - // this.resource = null; - // } - - @Override - public void write(WriteGraph graph, Resource parent) throws DatabaseException { - System.err.println("Writing element"); - } - - // TODO: is this the right place for this? - - public Resource getResource() { - return resource; - } - - public void setResource(Resource resource) { - this.resource = resource; - } - - public Resource createSymbol(WriteGraph graph, Resource type, Resource variable, Resource parent) throws DatabaseException { - DiagramResource dr = DiagramResource.getInstance(graph); - G2DResource g2d = G2DResource.getInstance(graph); - ModelingResources mr = ModelingResources.getInstance(graph); - - Resource symbol = GraphUtils.create2(graph, type, - mr.ElementToComponent, variable); - - double[] transform = { 1.0, 0.0, 0.0, 1.0, x, y }; - graph.claimLiteral(symbol, dr.HasTransform, g2d.Transform, transform, Bindings.DOUBLE_ARRAY); - - Resource diagram = graph.getSingleObject(parent, mr.CompositeToDiagram); - OrderedSetUtils.add(graph, diagram, symbol); - - return symbol; - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/EquivalenceSubscript.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/EquivalenceSubscript.java deleted file mode 100644 index 41d2eb54..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/EquivalenceSubscript.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; - -public class EquivalenceSubscript extends Subscript { - - public String getEquivalentToName() { - String name = ""; - if(expressions != null && expressions.get(0) != null) { - name = expressions.get(0).getExpression().trim(); - } - return name; - } - - public void setEquivalentTo(Subscript equivalentTo) { - setExpressions(equivalentTo.getExpressions()); - } - - @Override - public void write(WriteGraph graph, Resource parent, double xOffset, - double yOffset) { - super.write(graph, parent, xOffset, yOffset); - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Expression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Expression.java deleted file mode 100644 index fe6e9756..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Expression.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - - -public class Expression { - - private String range, expression; - - @Override - public String toString() { - return (range != null ? "[" + range + "]: " : "") + expression; - } - - public String getRange() { - return range; - } - - public void setRange(String range) { - this.range = range; - } - - public String getExpression() { - if (expression == null) - return ""; - return expression; - } - - public void setExpression(String expression) { - this.expression = expression; - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Flow.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Flow.java deleted file mode 100644 index 6067029b..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Flow.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.sysdyn.SysdynResource; - -public class Flow extends Connection { - - @Override - public void write(WriteGraph graph, Resource parent) { - if(parent == null || graph == null) - return; - try { - SysdynResource sr = SysdynResource.getInstance(graph); - writeConnection(graph, parent, sr.Flow, sr.FlowConnection); - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Flow2.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Flow2.java deleted file mode 100644 index a257e07d..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Flow2.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -public class Flow2 extends Connection2 { - - public Flow2() { - - } - - @Override - public void setHead(Element2 head) { - // TODO: make sure head is of the right type - super.setHead(head); - } - - @Override - public void setTail(Element2 tail) { - // TODO: make sure tail is of the right type - super.setTail(tail); - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Function.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Function.java deleted file mode 100644 index 6d5e402f..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Function.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.mdlImport.ImportUtils; - -public class Function extends Variable { - - @Override - public void write(WriteGraph graph, Resource parent, double xOffset, - double yOffset) { - if(parent == null || graph == null) - return; - - try { - SysdynResource sr = SysdynResource.getInstance(graph); - if(!graph.isInstanceOf(parent, sr.SysdynModel)) - return; - Layer0 l0 = Layer0.getInstance(graph); - - Resource function = GraphUtils.create2(graph, - sr.SysdynModelicaFunction, - l0.HasName, ImportUtils.escapeName(this.getName())); - - if(comments != null && comments.length() > 0) - graph.claimLiteral(function, l0.HasDescription, comments); - - if(expressions != null && expressions.get(0) != null) { - StringBuilder sb = new StringBuilder(); - sb.append(" input Real a;\n"); - sb.append(" output Real result;\n"); - sb.append("algorithm\n"); - sb.append(" result := interpolate(a, " + expressions.get(0).getExpression() + ");"); - graph.claimLiteral(function, sr.SysdynModelicaFunction_modelicaFunctionCode, sb.toString()); - } - - graph.claim(parent, l0.ConsistsOf, function); - resource = function; - } catch (DatabaseException e) { - e.printStackTrace(); - } - - } - - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/IWriteableMDLElement.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/IWriteableMDLElement.java deleted file mode 100644 index d21f5394..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/IWriteableMDLElement.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; - -public interface IWriteableMDLElement { - - /** - * Writes an element with coordinates (variable, cloud) to the given resource. - * - * Offsets determine where the parent view is located in the combined diagram - * - * @param graph WriteGraph - * @param parent The resource where the object is located - * @param xOffset xOffset of the view in the diagram - * @param yOffset yOffset of the view in the diagram - */ - public void write(WriteGraph graph, Resource parent, double xOffset, double yOffset); -} \ No newline at end of file diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/IWriteableMDLObject.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/IWriteableMDLObject.java deleted file mode 100644 index 67b9d06c..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/IWriteableMDLObject.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; - -public interface IWriteableMDLObject { - - /** - * Writes an object with no coordinates (connection, model, view) to the given resource - * - * @param graph WriteGraph - * @param parent The resource where the object is located - */ - public void write(WriteGraph graph, Resource parent); -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/IWriteableObject.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/IWriteableObject.java deleted file mode 100644 index 996fbf4c..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/IWriteableObject.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; - -public interface IWriteableObject { - - /** - * @param graph WriteGraph - * @param parent The resource where the object is located - * @throws DatabaseException - */ - public void write(WriteGraph graph, Resource parent) throws DatabaseException; -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Model.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Model.java deleted file mode 100644 index 0b5013f6..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Model.java +++ /dev/null @@ -1,275 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import java.util.ArrayList; -import java.util.HashMap; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.simulation.ontology.SimulationResource; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.utils.ModelUtils; - -public class Model implements IWriteableMDLObject { - - private String name, timeUnit, saveper; - private double startTime = 0, endTime = 10, timeStep = 1; - - private HashMap elementMap = new HashMap(); - private ArrayList subscripts = new ArrayList(); - private ArrayList functions = new ArrayList(); - private ArrayList connections = new ArrayList(); - private ArrayList views = new ArrayList(); - private ArrayList unlocatedElements = new ArrayList(); - - public void addElement(Element element) { - if(element instanceof Subscript) - addSubscript((Subscript)element); - else if(element instanceof Function) - addFunction((Function)element); - else - unlocatedElements.add(element); - if(element.getName() != null) - elementMap.put(element.getName(), element); - } - - public void addSubscript(Subscript subscript) { - subscripts.add(subscript); - } - - public void addFunction(Function function) { - functions.add(function); - } - - public void addElement(View view, Element element) { - if(element instanceof Subscript) - addSubscript((Subscript)element); - else { - if(unlocatedElements.contains(element)) - unlocatedElements.remove(element); - view.addElement(element); - } - if(element.getName() != null) - elementMap.put(element.getName(), element); - } - - public void relocateElement(View view, Element element) { - if(unlocatedElements.contains(element)) - unlocatedElements.remove(element); - for(View v : views) { - if(v.getElements().contains(element)) - v.getElements().remove(element); - } - view.addElement(element); - } - - public void removeElement(Element element) { - if(unlocatedElements.contains(element)) - unlocatedElements.remove(element); - - for(View view : views) { - if(view.getElements().contains(element)) { - view.getElements().remove(element); - } - } - - // just to be sure: loop the whole elementMap and don't trust the element's name - String toBeRemoved = null; - for(String key : elementMap.keySet()) { - if(element.equals(elementMap.get(key))) { - toBeRemoved = key; - break; - } - } - if(toBeRemoved != null) - elementMap.remove(toBeRemoved); - } - - public ArrayList getUnlocatedElements() { - return unlocatedElements; - } - - public Element getElement(String name) { - return elementMap.get(name); - } - - public void addConnection(Connection connection) { - connections.add(connection); - if(connection.getStart() != null && - !connection.getStart().getConnections().contains(connection)) { - connection.getStart().addConnection(connection); - } - if(connection.getEnd() != null && - !connection.getEnd().getConnections().contains(connection)) { - connection.getEnd().addConnection(connection); - } - } - - public ArrayList getConnections() { - return connections; - } - - public ArrayList getSubscripts() { - return subscripts; - } - - public String getName() { - if(name == null) - return "ModelName"; - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getTimeUnit() { - return timeUnit; - } - - public void setTimeUnit(String timeUnit) { - this.timeUnit = timeUnit; - } - - public String getSaveper() { - return saveper; - } - - public void setSaveper(String saveper) { - this.saveper = saveper; - } - - public double getStartTime() { - return startTime; - } - - public void setStartTime(double startTime) { - this.startTime = startTime; - } - - public double getEndTime() { - return endTime; - } - - public void setEndTime(double endTime) { - this.endTime = endTime; - } - - public double getTimeStep() { - return timeStep; - } - - public void setTimeStep(double timeStep) { - this.timeStep = timeStep; - } - - public HashMap getElementMap() { - return elementMap; - } - - public void setElementMap(HashMap elementMap) { - this.elementMap = elementMap; - } - - public void setSubscripts(ArrayList subscripts) { - this.subscripts = subscripts; - } - - public void setConnections(ArrayList connections) { - this.connections = connections; - } - - public void addView(View view) { - views.add(view); - } - - public ArrayList getViews() { - return views; - } - - /** - * Write the model to a project - * @param graph WriteGraph - * @param parent Project resource - */ - @Override - public void write(WriteGraph graph, Resource parent) { - if(parent == null || graph == null) - return; - - try { - - - SysdynResource sr = SysdynResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - SimulationResource simu = SimulationResource.getInstance(graph); - - Resource model = ModelUtils.createModelAt(graph, parent); - graph.claimLiteral(model, l0.HasLabel, getName()); - graph.claimLiteral(model, sr.SysdynModel_startTime, startTime); - graph.claimLiteral(model, sr.SysdynModel_stopTime, endTime); - - - Resource conf = graph.getSingleObject(model, simu.HasConfiguration); - - for(Subscript s : subscripts) { - s.write(graph, conf, 0, 0); - } - - // Create the grid n*n of views: - - double n = Math.sqrt(views.size()); - n = Math.ceil(n); - - int width = 0, height = 0; - for(View v : views) { - if(v.getWidth() > width) - width = v.getWidth(); - if(v.getHeight() > height) - height = v.getHeight(); - } - - for(int i = 0; i < n; i++) { - for(int j = 0; j < n; j++) { - int index = i * (int)n + j; - if(index < views.size()) { - View v = views.get(index); - v.setxOffset(width * j); - v.setyOffset(height * i); - v.write(graph, conf); - } - } - } - - for(Element e : unlocatedElements) { - e.write(graph, conf, 0, 0); - } - - for(Connection c : connections) { - c.write(graph, conf); - } - - for(Function f : functions) { - f.write(graph, model, 0, 0); - } - - - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Model2.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Model2.java deleted file mode 100644 index 88f1bde4..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Model2.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import java.util.ArrayList; - -import org.simantics.databoard.Bindings; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.simulation.ontology.SimulationResource; -import org.simantics.sysdyn.utils.ModelUtils; - -public class Model2 implements IWriteableObject { - - private String name; - // necessary simulation parameters - private double start, stop, step; - - // the structure of the model - private ArrayList elements; - private ArrayList connections; - - public Model2(String name) { - this.name = name; - - elements = new ArrayList(); - connections = new ArrayList(); - } - - public double getStart() { - return start; - } - - public void setStart(double start) { - this.start = start; - } - - public double getStop() { - return stop; - } - - public void setStop(double stop) { - this.stop = stop; - } - - public double getStep() { - return step; - } - - public void setStep(double step) { - this.step = step; - } - - public void addElement(Element2 element) { - elements.add(element); - } - - public void addConnection(Connection2 connection) { - connections.add(connection); - } - - @Override - public void write(WriteGraph graph, Resource parent) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - SimulationResource sim = SimulationResource.getInstance(graph); - - Resource model = ModelUtils.createModel(graph); - graph.claimLiteral(model, l0.HasLabel, name, Bindings.STRING); - - // TODO: set simulatin parameters - - Resource configuration = graph.getSingleObject(model, sim.HasConfiguration); - - for (Element2 e : elements) { - e.write(graph, configuration); - } - - for (Connection2 c : connections) { - c.write(graph, configuration); - } - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/ModelVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/ModelVariable.java deleted file mode 100644 index bbd818e2..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/ModelVariable.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -import org.simantics.databoard.Bindings; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.modeling.ModelingResources; -import org.simantics.sysdyn.SysdynResource; - -public class ModelVariable extends Element2 { - - protected String name; - protected Range range; - protected String unit; - protected String description; - - public ModelVariable() { - - } - - public Resource createVariable(WriteGraph graph, Resource type, Resource parent) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - ModelingResources mr = ModelingResources.getInstance(graph); - SysdynResource sr = SysdynResource.getInstance(graph); - - Resource variable = GraphUtils.create2(graph, type, - l0.HasName, name, - l0.PartOf, parent); - graph.claim(variable, mr.Mapped, variable); - - if (unit != null && !unit.isEmpty()) { - graph.claimLiteral(variable, sr.Variable_unit, unit, Bindings.STRING); - } - if (description != null && !description.isEmpty()) { - graph.claimLiteral(variable, l0.HasDescription, description, Bindings.STRING); - } - if (range != null) { - //graph.claimLiteral(variable, sr.HasRangeStart, rangeStart); - //graph.claimLiteral(variable, sr.HasRangeEnd, rangeEnd); - //graph.claimLiteral(variable, sr.HasRangeStep, rangeStep); - } - - return variable; - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Range.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Range.java deleted file mode 100644 index 43c7eea8..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Range.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -public class Range { - - private double start; - private double end; - private double step; - - public Range(double start, double end, double step) { - this.start = start; - this.end = end; - this.step = step; - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Sketch2.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Sketch2.java deleted file mode 100644 index 1408125c..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Sketch2.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -public class Sketch2 { - - private String name; - - private HashMap objectMap; - private ArrayList unfinished; - - public Sketch2() { - objectMap = new HashMap(); - unfinished = new ArrayList(); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public SketchObject getSketchObject(int index) { - return objectMap.get(index); - } - - public void addSketchObject(SketchConnection object) { - unfinished.add(object); - - addSketchObject((SketchObject)object); - } - - public void addSketchObject(SketchObject object) { - if (objectMap.get(object.getId()) != null) { - System.err.println("duplicate object with id "+object.getId()); - return; - } - objectMap.put(object.getId(), object); - - // NOTE: could just do another pass to update connections at the end - // or just use a priority queue or something but the number of - // unfinished connections at any given time should be relatively - // small in practice so it does not matter that this is inefficient - Iterator i = unfinished.iterator(); - while (i.hasNext()) { - SketchConnection connection = i.next(); - - SketchObject from = objectMap.get(connection.getFromId()); - SketchObject to = objectMap.get(connection.getToId()); - - if (from != null && to != null) { - // connections can only connect elements so if this is not the - // case something has gone wrong with the indexing - assert from instanceof SketchElement; - assert to instanceof SketchElement; - - connection.setFrom((SketchElement)from); - connection.setTo((SketchElement)to); - - i.remove(); - } - } - } - - // TODO: ugly and inefficient - - public List getElements() { - ArrayList list = new ArrayList(); - for (SketchObject o : objectMap.values()) { - if (o instanceof SketchElement) { - list.add((SketchElement)o); - } - } - return list; - } - - public List getConnections() { - ArrayList list = new ArrayList(); - for (SketchObject o : objectMap.values()) { - if (o instanceof SketchConnection) { - list.add((SketchConnection)o); - } - } - return list; - } - - public int getWidth() { - int width = 0; - for (SketchElement e : getElements()) { - width = Math.max(width, e.getX()+e.getWidth()); - } - return width; - } - - public int getHeight() { - int height = 0; - for (SketchElement e : getElements()) { - height = Math.max(height, e.getY()+e.getHeight()); - } - return height; - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchComment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchComment.java deleted file mode 100644 index 3baa5fbd..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchComment.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -import org.simantics.sysdyn.mdlImport.MdlUtils.CommentIcon; - -public class SketchComment extends SketchElement { - - private String text; - private CommentIcon icon; - private boolean nextLine; - private boolean isIO; - - public SketchComment(int id, CommentIcon icon, boolean nextLine, boolean isIO) { - super(id); - this.icon = icon; - this.nextLine = nextLine; - this.isIO = isIO; - } - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - public CommentIcon getIcon() { - return this.icon; - } - - public boolean isCloud() { - return this.icon.equals(CommentIcon.CLOUD); - } - - public boolean hasTextNextLine() { - return nextLine; - } - - public boolean isIOElement() { - return this.isIO; - } - - public Comment2 getWriteableElement(int xOffset, int yOffset) { - return null; - } - - @Override - public String toString() { - return text != null ? "\""+text+"\"" : "(empty comment)"; - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchConnection.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchConnection.java deleted file mode 100644 index 4ab59659..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchConnection.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -import org.simantics.sysdyn.mdlImport.MdlUtils.ConnectionType; - -public class SketchConnection extends SketchObject { - - private int fromId; - private SketchElement from; - private int toId; - private SketchElement to; - private ConnectionType type; - - public SketchConnection(int id, int fromId, int toId, ConnectionType type) { - super(id); - this.fromId = fromId; - this.toId = toId; - this.type = type; - } - - public int getFromId() { - return fromId; - } - - public int getToId() { - return toId; - } - - public SketchElement getFrom() { - if (from == null) { - System.err.println("endpoint "+fromId+" for connection "+getId()+" is unset"); - } - return from; - } - - public void setFrom(SketchElement from) { - this.from = from; - } - - public SketchElement getTo() { - if (to == null) { - System.err.println("endpoint "+toId+" for connection "+getId()+" is unset"); - } - return to; - } - - public void setTo(SketchElement to) { - this.to = to; - } - - public ConnectionType getType() { - return type; - } - - public Connection2 getWriteableConnection() { - // return dependency or flow - return null; - } - - @Override - public String toString() { - return from.toString() + " --> " + to.toString(); - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchElement.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchElement.java deleted file mode 100644 index 1625ae65..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchElement.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -public abstract class SketchElement extends SketchObject { - - private int x; - private int y; - private int width; - private int height; - - public SketchElement(int id) { - super(id); - } - - public void setLocationAndSize(int x, int y, int width, int height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public int getWidth() { - return width; - } - - public int getHeight() { - return height; - } - - public abstract Element2 getWriteableElement(int xOffset, int yOffset); - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchObject.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchObject.java deleted file mode 100644 index bb9608d1..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchObject.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -public abstract class SketchObject { - - // TODO: some type stuff here maybe? - - private int id; - - SketchObject(int id) { - this.id = id; - } - - public int getId() { - return id; - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchValve.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchValve.java deleted file mode 100644 index f4f12109..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchValve.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -public class SketchValve extends SketchElement { - - private SketchVariable variable; - - public SketchValve(int id) { - super(id); - } - - public SketchVariable getAttachedVariable() { - return variable; - } - - public void setAttachedVariable(SketchVariable variable) { - this.variable = variable; - } - - @Override - public Valve2 getWriteableElement(int xOffset, int yOffset) { - return null; - } - - @Override - public String toString() { - return "X("+variable.toString()+")"; - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchVariable.java deleted file mode 100644 index 5be5f830..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/SketchVariable.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -import org.simantics.sysdyn.mdlImport.MdlUtils; -import org.simantics.utils.datastructures.Pair; - -public class SketchVariable extends SketchElement { - - private Variable2 variable; - boolean isAttached; - boolean allowsInBound; - boolean allowsOutBound; - - public SketchVariable(int id, Variable2 variable, boolean isAttached, boolean in, boolean out) { - super(id); - this.variable = variable; - this.isAttached = isAttached; - this.allowsInBound = in; - this.allowsOutBound = out; - } - - public Variable2 getVariable() { - return this.variable; - } - - public boolean isAttached() { - return isAttached; - } - - public boolean allowsInBound() { - return allowsInBound; - } - - public boolean allowsOutBound() { - return allowsOutBound; - } - - @Override - public Element2 getWriteableElement(int xOffset, int yOffset) { - Pair integral = MdlUtils.getPossibleIntegral(variable.getEquation()); - if (integral != null) { - return new Stock2(getX(), getY(), variable, integral); - } - else { - return new Auxiliary2(getX(), getY(), variable, variable.getEquation()); - } - } - - @Override - public String toString() { - return (allowsInBound?"":"<")+variable.getName()+(allowsInBound?"":">"); - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Stock.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Stock.java deleted file mode 100644 index ec88915c..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Stock.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.mdlImport.ImportUtils; - -public class Stock extends Variable { - - @Override - public Resource getExpression(WriteGraph graph, Expression expression) throws DatabaseException { - - String integralEquation = ImportUtils.escapeExpression(getIntegralParts(expression)[1]); - SysdynResource sr = SysdynResource.getInstance(graph); - Resource e = GraphUtils.create2(graph, - sr.StockExpression, - sr.StockExpression_initialEquation, integralEquation); - - return e; - } - - public String[] getIntegralParts(Expression expression) { - // Does not work, if the integral has some other logic than +inflows -outflows! - - // Parsing the possible functions. Searching ',' that divides the INTEG -function - int parenthesiscount = 0; - int location = 0; - char[] charArray = expression.getExpression().toCharArray(); - for(int i = 0; i < charArray.length; i++) { - char c = charArray[i]; - if(c == '(') - parenthesiscount++; - else if(c == ')') - parenthesiscount--; - else if(c == ',' && parenthesiscount == 1) { - location = i + 1; - break; - } - } - - String exp = expression.getExpression(); - String initialEquation = exp.substring(location, exp.lastIndexOf(')')).trim(); - String integral = exp.substring(exp.indexOf("(") + 1, location - 1).trim(); - - - return new String[] {integral, initialEquation}; - } - - @Override - public void write(WriteGraph graph, Resource parent, double xOffset, - double yOffset) { - if(parent == null || graph == null) - return; - - try { - SysdynResource sr = SysdynResource.getInstance(graph); - if(!graph.isInstanceOf(parent, sr.Configuration)) - return; - createVariable(graph, parent, sr.Stock, sr.StockSymbol, xOffset, yOffset); - } catch (DatabaseException e) { - e.printStackTrace(); - } - - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Stock2.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Stock2.java deleted file mode 100644 index 8b827e3a..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Stock2.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -import java.util.Arrays; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.utils.datastructures.Pair; - -public class Stock2 extends ModelVariable { - - protected String integral; - protected String initial; - - public Stock2(double x, double y, - String name, String unit, Range range, String description, - String integral, String initial) { - this.integral = integral; - this.initial = initial; - } - - public Stock2(double x, double y, Variable2 variable, Pair equation) { - this.integral = equation.first; - this.initial = equation.second; - } - - public void write(WriteGraph graph, Resource parent) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - SysdynResource sr = SysdynResource.getInstance(graph); - - Resource stock = createVariable(graph, sr.Stock, parent); - - Resource expression = GraphUtils.create2(graph, sr.StockExpression, - sr.StockExpression_integralEquation, integral, - sr.StockExpression_initialEquation, initial, - l0.PartOf, stock); - // TODO: why is the expressoin stored in two places? - graph.claim(stock, sr.Variable_expressionList, ListUtils.create(graph, Arrays.asList(expression))); - - createSymbol(graph, sr.StockSymbol, stock, parent); - - setResource(stock); - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Subscript.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Subscript.java deleted file mode 100644 index 5a96d94c..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Subscript.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import java.util.ArrayList; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.sysdyn.SysdynResource; - -public class Subscript extends Variable { - - @Override - public Resource getExpression(WriteGraph graph, Expression expression) - throws DatabaseException { - return null; - } - - @Override - public void write(WriteGraph graph, Resource parent, double xOffset, - double yOffset) { - if(parent == null || graph == null) - return; - - try { - SysdynResource sr = SysdynResource.getInstance(graph); - if(!graph.isInstanceOf(parent, sr.Configuration)) - return; - Layer0 l0 = Layer0.getInstance(graph); - ArrayList enumerationIndexes = new ArrayList(); - if(expressions != null && expressions.get(0) != null) { - String[] indexes = expressions.get(0).getExpression().split(","); - for(String s : indexes) { - Resource ei = GraphUtils.create2(graph, - sr.EnumerationIndex, - l0.HasName, s.trim()); - enumerationIndexes.add(ei); - } - } - - Resource enumeration = GraphUtils.create2(graph, - sr.Enumeration, - l0.HasName, this.getName(), - sr.Enumeration_enumerationIndexList, ListUtils.create(graph, enumerationIndexes)); - - graph.claim(parent, l0.ConsistsOf, enumeration); - - resource = enumeration; - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Valve.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Valve.java deleted file mode 100644 index 6b93e5d8..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Valve.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.mdlImport.ImportUtils; - -public class Valve extends Variable { - - @Override - public Resource getExpression(WriteGraph graph, Expression expression) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - String expressionString = ImportUtils.escapeExpression(expression.getExpression()); - Resource e = GraphUtils.create2(graph, - sr.NormalExpression, - sr.Expression_equation, expressionString.trim()); - return e; - } - - @Override - public void write(WriteGraph graph, Resource parent, double xOffset, - double yOffset) { - try { - SysdynResource sr = SysdynResource.getInstance(graph); - if(!graph.isInstanceOf(parent, sr.Configuration)) - return; - createVariable(graph, parent, sr.Valve, sr.ValveSymbol, xOffset, yOffset); - } catch (DatabaseException e) { - e.printStackTrace(); - } - } -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Valve2.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Valve2.java deleted file mode 100644 index c08eb562..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Valve2.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -public class Valve2 extends Element2 { - - public enum Orientation { - HORIZONTAL, VERTICAL - } - - public enum TextPosition { - INSIDE, BELOW, LEFT, ABOVE, RIGHT, UNSET - } - - public Valve2(String equation, Orientation orientation, TextPosition position, String unit, Range range, String description) { - - } - -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Variable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Variable.java deleted file mode 100644 index f0e579ab..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Variable.java +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import java.util.ArrayList; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.common.utils.OrderedSetUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.diagram.stubs.G2DResource; -import org.simantics.layer0.Layer0; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.modeling.ModelingResources; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.mdlImport.ImportUtils; - -public abstract class Variable extends Element { - protected String units; - protected String comments; - protected ArrayList expressions; - protected ArrayList subscripts; - - private Double rangeStart, rangeEnd, rangeStep; - - protected void createVariable(WriteGraph graph, Resource configuration, Resource variableType, Resource symbolType, double xOffset, double yOffset) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - ModelingResources mr = ModelingResources.getInstance(graph); - DiagramResource dr = DiagramResource.getInstance(graph); - G2DResource g2d = G2DResource.getInstance(graph); - - Resource diagram = graph.getSingleObject(configuration, mr.CompositeToDiagram); - if(diagram == null) - return; - - // Make sure at least one expression exist - if(getExpressions().isEmpty()) { - Expression e = new Expression(); - e.setExpression(""); - getExpressions().add(e); - } - - Resource variable = GraphUtils.create2(graph, - variableType, - l0.HasName, ImportUtils.escapeName(name)); - graph.claim(variable, mr.Mapped, variable); - - ArrayList expressions = new ArrayList(); - for(Expression e : getExpressions()) { - - // Get expression from the variable. They have different types - Resource expression = getExpression(graph, e); - - if(e.getRange() != null) { - graph.claimLiteral(expression, sr.Expression_arrayRange, "[" + e.getRange().trim() + "]"); - } - expressions.add(expression); - graph.claim(variable, l0.ConsistsOf, expression); - } - graph.claim(variable, sr.Variable_expressionList, ListUtils.create(graph, expressions)); - - if(subscripts != null) { - ArrayList arrayIndexes = new ArrayList(); - for(Subscript sub : subscripts) { - if(sub.getResource() != null) - arrayIndexes.add(sub.getResource()); - } - graph.claim(variable, sr.Variable_arrayIndexesList, ListUtils.create(graph, arrayIndexes)); - } - - if(units != null && units.length() > 0) - graph.claimLiteral(variable, sr.Variable_unit, units); - if(comments != null && comments.length() > 0) - graph.claimLiteral(variable, l0.HasDescription, comments); - if(rangeStart != null) - graph.claimLiteral(variable, sr.HasRangeStart, rangeStart); - if(rangeEnd != null) - graph.claimLiteral(variable, sr.HasRangeEnd, rangeEnd); - if(rangeStep != null) - graph.claimLiteral(variable, sr.HasRangeStep, rangeStep); - - graph.claim(configuration, l0.ConsistsOf, variable); - - - Resource symbol = GraphUtils.create2(graph, - symbolType, - mr.ElementToComponent, variable); - - double[] transform = {1.0, 0.0, 0.0, 1.0, x + xOffset, y + yOffset}; - graph.claimLiteral(symbol, dr.HasTransform, g2d.Transform, transform); - - OrderedSetUtils.add(graph, diagram, symbol); - - resource = variable; - } - - - public String getUnits() { - return units; - } - - public void setUnits(String units) { - this.units = units; - } - - public String getComments() { - return comments; - } - - public void setComments(String comments) { - this.comments = comments; - } - - public ArrayList getExpressions() { - if(expressions == null) { - expressions = new ArrayList(); - } - return expressions; - } - - public void setExpressions(ArrayList expressions) { - this.expressions = expressions; - } - - public ArrayList getSubscripts() { - if(subscripts == null) - subscripts = new ArrayList(); - return subscripts; - } - - public void setSubscripts(ArrayList subscripts) { - this.subscripts = subscripts; - } - - - public Double getRangeStart() { - return rangeStart; - } - - public void setRangeStart(Double rangeStart) { - this.rangeStart = rangeStart; - } - - public Double getRangeEnd() { - return rangeEnd; - } - - public void setRangeEnd(Double rangeEnd) { - this.rangeEnd = rangeEnd; - } - - public Double getRangeStep() { - return rangeStep; - } - - public void setRangeStep(Double rangeStep) { - this.rangeStep = rangeStep; - } - - /** - * Use this to set subscripts after all elements have been read - * - * @param model The model where the variable is located - */ - public void initializeSubscripts(Model model) { - for(Expression ex : getExpressions()) { - if(ex.getRange() != null) { - - // Subscripts exist, check that subscripts -array is initialized - getSubscripts(); - - String[] elements = ex.getRange().split(","); - // Search the corresponding subscript for each element, if it has not been searched already - for(int i = 0; i < elements.length; i++) { - // The subscript has been defined, move to next - if(subscripts.size() > i) - continue; - - String element = elements[i].trim(); - for(Subscript sub : model.getSubscripts()) { - if(sub.getName().equals(element)) { - subscripts.add(sub); - break; - } - for(String index : sub.getExpressions().get(0).getExpression().split(",")) { - if(index.trim().equals(element)) { - subscripts.add(sub); - break; - } - } - // Subscript was defined for this index in previous for-loop - if(subscripts.size() == i + 1) - break; - } - } - } - } - } -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Variable2.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Variable2.java deleted file mode 100644 index f478b443..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/Variable2.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.simantics.sysdyn.mdlImport.model; - -public class Variable2 { - - private String name; - private String equation; - private String unit; - private String description; - - public Variable2(String name, String equation, String unit, String description) { - this.name = name; - this.equation = equation; - this.unit = unit; - this.description = description; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getEquation() { - return equation; - } - - public void setEquation(String equation) { - this.equation = equation; - } - - public String getUnit() { - return unit; - } - - public void setUnit(String unit) { - this.unit = unit; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } -} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/View.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/View.java deleted file mode 100644 index acfa849a..00000000 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/model/View.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * 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.mdlImport.model; - -import java.util.ArrayList; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; - -public class View implements IWriteableMDLObject { - - private int minX = 0, maxX = 0, minY = 0, maxY = 0; - private double xOffset = 0, yOffset = 0; - private String name, fontParameters; - - private ArrayList elements = new ArrayList(); - - @Override - public void write(WriteGraph graph, Resource parent) { - xOffset = xOffset - minX; - yOffset = yOffset - minY; - for(Element e : elements) { - e.write(graph, parent, xOffset, yOffset); - } - } - - public void addElement(Element e) { - if (e instanceof Subscript || e instanceof Function) - return; - - if (e.getX() < minX) - minX = e.getX(); - if (e.getX() > maxX) - maxX = e.getX(); - if (e.getY() < minY) - minY = e.getY(); - if (e.getY() > maxY) - maxY = e.getY(); - - this.elements.add(e); - } - - public ArrayList getElements() { - return elements; - } - - public void setElements(ArrayList elements) { - this.elements = elements; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - - public String getFontParameters() { - return fontParameters; - } - - - public void setFontParameters(String fontParameters) { - this.fontParameters = fontParameters; - } - - - public int getMinX() { - return minX; - } - - public void setMinX(int minX) { - this.minX = minX; - } - - public int getMaxX() { - return maxX; - } - - public void setMaxX(int maxX) { - this.maxX = maxX; - } - - public int getMinY() { - return minY; - } - - public void setMinY(int minY) { - this.minY = minY; - } - - public int getMaxY() { - return maxY; - } - - public void setMaxY(int maxY) { - this.maxY = maxY; - } - - public double getxOffset() { - return xOffset; - } - - public void setxOffset(double xOffset) { - this.xOffset = xOffset; - } - - public double getyOffset() { - return yOffset; - } - - public void setyOffset(double yOffset) { - this.yOffset = yOffset; - } - - public int getWidth() { - return maxX - minX; - } - - public int getHeight() { - return maxY - minY; - } -} -- 2.47.1