From: lempinen Date: Mon, 7 Nov 2011 10:25:46 +0000 (+0000) Subject: git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23224 ac1ea38d-2e2b... X-Git-Tag: simantics-1.6~110 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=f6bfe5cad7a17d88b054b7a39957b214c0832dc9;p=simantics%2Fsysdyn.git git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23224 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF index 82956043..8b918eab 100644 --- a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF @@ -48,7 +48,8 @@ Require-Bundle: org.simantics.layer0.utils;bundle-version="0.6.2", org.simantics.issues.common;bundle-version="1.1.0", org.simantics.scenegraph.profile;bundle-version="1.0.0", org.simantics.trend;bundle-version="1.0.0", - org.simantics.history;bundle-version="1.0.0" + org.simantics.history;bundle-version="1.0.0", + org.simantics.utils.thread.swt;bundle-version="1.1.0" Bundle-Activator: org.simantics.sysdyn.ui.Activator Bundle-ActivationPolicy: lazy Export-Package: org.simantics.sysdyn.ui.browser.nodes diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 80ceb505..c6f9ccb5 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -107,10 +107,10 @@ @@ -187,7 +187,7 @@ relative="org.simantics.browsing.ui.graph.propertyView"> 3) { - if(coordinates[0] == coordinates[2]) { - // starts to south or north - double[] tempCoordinates = new double[coordinates.length - 1]; - for(int i = 0; i < coordinates.length - 1 ; i++) - tempCoordinates[i] = coordinates[i + 1]; - - coordinates = new double[tempCoordinates.length]; - for(int i = 0; i < tempCoordinates.length ; i++) - coordinates[i] = tempCoordinates[i]; - vertical = true; - } - } - - Flows.createOffsetLine(completePath, vertical, OFFSET, coordinates); - Flows.createOffsetLine(completePath, vertical, -OFFSET, coordinates); -// return localRouter.path; - -// Flows.createLines(completePath, false, beginObstacle, endObstacle); return completePath; - */ } @Override public void route(IConnection connection) { - Collection segments = connection.getSegments(); - if(segments.size() == 1) - for(Object seg : segments) { - Connector begin = connection.getBegin(seg); - Connector end = connection.getEnd(seg); - - double bestLength = Double.POSITIVE_INFINITY; - Path2D bestPath = null; - - for(int sDir : Constants.POSSIBLE_DIRECTIONS[begin.allowedDirections]) - for(int tDir : Constants.POSSIBLE_DIRECTIONS[end.allowedDirections]) { - Path2D path = route(begin.x, begin.y, sDir, begin.parentObstacle, - end.x, end.y, tDir, end.parentObstacle); - - double length = pathCost(path); - if(length < bestLength) { - bestLength = length; - bestPath = localRouter.path; - } - } - - if(bestPath != null) - connection.setPath(seg, bestPath); - } - else { - TObjectIntHashMap leftSegments = new TObjectIntHashMap(); - TObjectIntHashMap rightSegments = new TObjectIntHashMap(); - TObjectIntHashMap upSegments = new TObjectIntHashMap(); - TObjectIntHashMap downSegments = new TObjectIntHashMap(); - TObjectIntHashMap horizontalCount = new TObjectIntHashMap(); - for(Object seg : segments) { - Connector begin = connection.getBegin(seg); - Connector end = connection.getEnd(seg); - if(begin.x < end.x) { - leftSegments.adjustOrPutValue(end, 1, 1); - rightSegments.adjustOrPutValue(begin, 1, 1); - } - else { - leftSegments.adjustOrPutValue(begin, 1, 1); - rightSegments.adjustOrPutValue(end, 1, 1); - } - if(begin.y < end.y) { - upSegments.adjustOrPutValue(end, 1, 1); - downSegments.adjustOrPutValue(begin, 1, 1); - } - else { - upSegments.adjustOrPutValue(begin, 1, 1); - downSegments.adjustOrPutValue(end, 1, 1); - } - if((begin.allowedDirections & 5) != 0) - horizontalCount.adjustOrPutValue(end, 1, 1); - if((begin.allowedDirections & 10) != 0) - horizontalCount.adjustOrPutValue(end, -1, -1); - if((end.allowedDirections & 5) != 0) - horizontalCount.adjustOrPutValue(begin, 1, 1); - if((end.allowedDirections & 10) != 0) - horizontalCount.adjustOrPutValue(begin, -1, -1); - } - for(Object seg : segments) { - Connector begin = connection.getBegin(seg); - Connector end = connection.getEnd(seg); - int allowedBegin = begin.allowedDirections; - int allowedEnd = end.allowedDirections; - - if(horizontalCount.get(begin) + horizontalCount.get(end) >= 0) { - //System.out.println("horizontal"); - if(begin.x < end.x) { - if(allowedBegin == 0xf) { - if(rightSegments.get(begin) <= 1) - allowedBegin = 1; - else - allowedBegin = 11; - } - if(allowedEnd == 0xf) { - if(leftSegments.get(end) <= 1) - allowedEnd = 4; - else - allowedEnd = 14; - } - } - else { - if(allowedBegin == 0xf) { - if(leftSegments.get(begin) <= 1) - allowedBegin = 4; - else - allowedBegin = 14; - } - if(allowedEnd == 0xf) { - if(rightSegments.get(end) <= 1) - allowedEnd = 1; - else - allowedEnd = 11; - } - } - } - else { - //System.out.println("vertical"); - if(begin.y < end.y) { - if(allowedBegin == 0xf) { - if(downSegments.get(begin) <= 1) - allowedBegin = 2; - else - allowedBegin = 7; - } - if(allowedEnd == 0xf) { - if(upSegments.get(end) <= 1) - allowedEnd = 8; - else - allowedEnd = 13; - } - } - else { - if(allowedBegin == 0xf) { - if(upSegments.get(begin) <= 1) - allowedBegin = 8; - else - allowedBegin = 13; - } - if(allowedEnd == 0xf) { - if(downSegments.get(end) <= 1) - allowedEnd = 2; - else - allowedEnd = 7; - } - } - } - - //System.out.println(allowedBegin + " " + allowedEnd); - - double bestLength = Double.POSITIVE_INFINITY; - Path2D bestPath = null; - - for(int sDir : Constants.POSSIBLE_DIRECTIONS[allowedBegin]) - for(int tDir : Constants.POSSIBLE_DIRECTIONS[allowedEnd]) { - Path2D path = route(begin.x, begin.y, sDir, begin.parentObstacle, - end.x, end.y, tDir, end.parentObstacle); - - double length = pathCost(path); - if(length < bestLength) { - bestLength = length; - bestPath = localRouter.path; - } - } - - if(bestPath != null) - connection.setPath(seg, bestPath); - } - } - } - - /* - @Override - public void route(IConnection connection) { - - if(!(connection instanceof SysdynConnection)) { - return; - } Collection segments = connection.getSegments(); if(segments.size() == 1) for(Object seg : segments) { @@ -297,7 +115,7 @@ public class FlowRouter implements IRouter2{ connection.setPath(seg, bestPath); } } - */ + final static AffineTransform IDENTITY = new AffineTransform(); @@ -315,7 +133,6 @@ public class FlowRouter implements IRouter2{ y = temp[1]; it.next(); } - //return length * (6.0 + bendCount); return bendCount - 1.0 / length; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/SysdynLocalRouter.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/SysdynLocalRouter.java index e594abe1..253e6a17 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/SysdynLocalRouter.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/SysdynLocalRouter.java @@ -357,41 +357,41 @@ public class SysdynLocalRouter { * share Y-Axis at some point 3. Obstacles don't share axis => Have to * make corners. */ - if ( - aMinX > bMinX && aMinX < bMaxX || - aMaxX > bMinX && aMaxX < bMaxX || - aMinX < bMinX && aMaxX > bMaxX) { - // Obstacles share x-axis => no corner - double minX = aMinX > bMinX ? aMinX : bMinX; - double maxX = aMaxX < bMaxX ? aMaxX : bMaxX; - double middle = minX + (maxX - minX) / 2; - sx = middle; - tx = middle; - if (sy > ty) { - sy = aMinY; - ty = bMaxY; - } else { - sy = aMaxY; - ty = bMinY; - } - } else if ( - aMinY > bMinY && aMinY < bMaxY || - aMaxY > bMinY && aMaxY < bMaxY || - aMinY < bMinY && aMaxY > bMaxY) { - // Obstacles share y-axis => no corner - double minY = aMinY > bMinY ? aMinY : bMinY; - double maxY = aMaxY < bMaxY ? aMaxY : bMaxY; - double middle = minY + (maxY - minY) / 2; - sy = middle; - ty = middle; - if (sx > tx) { - sx = aMinX; - tx = bMaxX; - } else { - sx = aMaxX; - tx = bMinX; - } - } else { +// if ( +// aMinX > bMinX && aMinX < bMaxX || +// aMaxX > bMinX && aMaxX < bMaxX || +// aMinX < bMinX && aMaxX > bMaxX) { +// // Obstacles share x-axis => no corner +// double minX = aMinX > bMinX ? aMinX : bMinX; +// double maxX = aMaxX < bMaxX ? aMaxX : bMaxX; +// double middle = minX + (maxX - minX) / 2; +// sx = middle; +// tx = middle; +// if (sy > ty) { +// sy = aMinY; +// ty = bMaxY; +// } else { +// sy = aMaxY; +// ty = bMinY; +// } +// } else if ( +// aMinY > bMinY && aMinY < bMaxY || +// aMaxY > bMinY && aMaxY < bMaxY || +// aMinY < bMinY && aMaxY > bMaxY) { +// // Obstacles share y-axis => no corner +// double minY = aMinY > bMinY ? aMinY : bMinY; +// double maxY = aMaxY < bMaxY ? aMaxY : bMaxY; +// double middle = minY + (maxY - minY) / 2; +// sy = middle; +// ty = middle; +// if (sx > tx) { +// sx = aMinX; +// tx = bMaxX; +// } else { +// sx = aMaxX; +// tx = bMinX; +// } +// } else { sx = aMinX + (aMaxX - aMinX) / 2; sy = aMinY + (aMaxY - aMinY) / 2; tx = bMinX + (bMaxX - bMinX) / 2; @@ -427,7 +427,7 @@ public class SysdynLocalRouter { ty = bMaxY; break; } - } +// } path = new Path2D.Double(); points = new ArrayList(); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowConnectionStyle.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowConnectionStyle.java index b975e17c..90da81ed 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowConnectionStyle.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowConnectionStyle.java @@ -4,12 +4,10 @@ import java.awt.Color; import java.awt.Graphics2D; import java.awt.Stroke; import java.awt.geom.Path2D; -import java.awt.geom.PathIterator; -import java.io.Serializable; -import org.simantics.diagram.connection.rendering.ConnectionStyle; +import org.simantics.diagram.connection.rendering.BasicConnectionStyle; -public class FlowConnectionStyle implements ConnectionStyle, Serializable { +public class FlowConnectionStyle extends BasicConnectionStyle { private static final long serialVersionUID = 2777194644079591357L; @@ -17,6 +15,7 @@ public class FlowConnectionStyle implements ConnectionStyle, Serializable { Stroke lineStroke; public FlowConnectionStyle(Color lineColor, Stroke lineStroke) { + super(lineColor, Color.BLACK, 0.5, lineStroke, lineStroke, 0.8); this.lineColor = lineColor; this.lineStroke = lineStroke; } @@ -37,8 +36,8 @@ public class FlowConnectionStyle implements ConnectionStyle, Serializable { if (lineStroke != null) g.setStroke(lineStroke); - Path2D p1 = createOffsetPath(g, path, 1); - Path2D p2 = createOffsetPath(g, path, -1); + Path2D p1 = Flows.createOffsetPath(path, 1); + Path2D p2 = Flows.createOffsetPath(path, -1); p1.append(p2, false); g.draw(p1); } @@ -52,92 +51,4 @@ public class FlowConnectionStyle implements ConnectionStyle, Serializable { return 0; } - private static int x = 0; - private static int y = 1; - private Path2D createOffsetPath(Graphics2D g, Path2D originalPath, float offset) { - PathIterator pi = originalPath.getPathIterator(null); - Path2D newPath = new Path2D.Double(); - double[] previous = new double[6]; - double[] current = new double[6]; - double[] next = new double[6]; - boolean vertical = false; - pi.currentSegment(current); - pi.next(); - pi.currentSegment(next); - - Direction direction = getDirection(current, next); - - int i = 0; - if(direction == Direction.SOUTH || direction == Direction.NORTH) { - // First line vertical - vertical = true; - current[x] += offset; - newPath.moveTo(current[x], current[y]); - - if(direction == Direction.SOUTH) - offset = -offset; - } else { - // First line horizontal - current[y] += offset; - i = 1; - newPath.moveTo(current[x], current[y]); - if(direction == Direction.WEST) - offset = -offset; - } - - - previous[x] = current[x]; - previous[y] = current[y]; - current[x] = next[x]; - current[y] = next[y]; - - while(!pi.isDone()) { - pi.next(); - pi.currentSegment(next); - if(previous[i] < next[i] ^ (i&1)==1) { - if(vertical) { - if(!pi.isDone()) current[y] += offset; - newPath.lineTo(previous[x], current[y]); - } else { - if(!pi.isDone()) current[x] += offset; - newPath.lineTo(current[x], previous[y]); - } - } else { - if(vertical) { - if(!pi.isDone()) current[y] -= offset; - newPath.lineTo(previous[x], current[y]); - } else { - if(!pi.isDone()) current[x] -= offset; - newPath.lineTo(current[x], previous[y]); - } - } - - previous[x] = current[x]; - previous[y] = current[y]; - current[x] = next[x]; - current[y] = next[y]; - vertical = !vertical; - i = (i + 1) % 2; - } - return newPath; - } - - private enum Direction {NORTH, SOUTH, EAST, WEST}; - - private Direction getDirection(double[] current, double[] next) { - if(current[x] == next[x]) { - // move vertically - if(current[y] < next[y]) - return Direction.SOUTH; - else - return Direction.NORTH; - } else { - //move horizontally - if(current[x] < next[x]) - return Direction.EAST; - else - return Direction.WEST; - } - } - } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowStroke.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowStroke.java deleted file mode 100644 index 2c293e44..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowStroke.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.elements2.connections; - -import java.awt.Shape; -import java.awt.Stroke; - -public class FlowStroke implements Stroke { - private Stroke stroke1, stroke2; - - public FlowStroke( Stroke stroke1, Stroke stroke2 ) { - this.stroke1 = stroke1; - this.stroke2 = stroke2; - } - - public Shape createStrokedShape( Shape shape ) { - return stroke2.createStrokedShape( stroke1.createStrokedShape( shape ) ); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/Flows.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/Flows.java index eccf2461..051b3b18 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/Flows.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/Flows.java @@ -12,6 +12,7 @@ package org.simantics.sysdyn.ui.elements2.connections; import java.awt.geom.Path2D; +import java.awt.geom.PathIterator; import java.awt.geom.Rectangle2D; public class Flows { @@ -164,4 +165,93 @@ public class Flows { return createLine(path, vertical, newCoordinats); } + + private static int x = 0; + private static int y = 1; + public static Path2D createOffsetPath(Path2D originalPath, float offset) { + PathIterator pi = originalPath.getPathIterator(null); + Path2D newPath = new Path2D.Double(); + double[] previous = new double[6]; + double[] current = new double[6]; + double[] next = new double[6]; + boolean vertical = false; + pi.currentSegment(current); + pi.next(); + pi.currentSegment(next); + + Direction direction = getDirection(current, next); + + int i = 0; + if(direction == Direction.SOUTH || direction == Direction.NORTH) { + // First line vertical + vertical = true; + current[x] += offset; + newPath.moveTo(current[x], current[y]); + + if(direction == Direction.SOUTH) + offset = -offset; + } else { + // First line horizontal + current[y] += offset; + i = 1; + newPath.moveTo(current[x], current[y]); + if(direction == Direction.WEST) + offset = -offset; + } + + + previous[x] = current[x]; + previous[y] = current[y]; + current[x] = next[x]; + current[y] = next[y]; + + while(!pi.isDone()) { + pi.next(); + pi.currentSegment(next); + if(previous[i] < next[i] ^ (i&1)==1) { + if(vertical) { + if(!pi.isDone()) current[y] += offset; + newPath.lineTo(previous[x], current[y]); + } else { + if(!pi.isDone()) current[x] += offset; + newPath.lineTo(current[x], previous[y]); + } + } else { + if(vertical) { + if(!pi.isDone()) current[y] -= offset; + newPath.lineTo(previous[x], current[y]); + } else { + if(!pi.isDone()) current[x] -= offset; + newPath.lineTo(current[x], previous[y]); + } + } + + previous[x] = current[x]; + previous[y] = current[y]; + current[x] = next[x]; + current[y] = next[y]; + vertical = !vertical; + i = (i + 1) % 2; + } + return newPath; + } + + private static enum Direction {NORTH, SOUTH, EAST, WEST}; + + private static Direction getDirection(double[] current, double[] next) { + if(current[x] == next[x]) { + // move vertically + if(current[y] < next[y]) + return Direction.SOUTH; + else + return Direction.NORTH; + } else { + //move horizontally + if(current[x] < next[x]) + return Direction.EAST; + else + return Direction.WEST; + } + } + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java index e7e57bcd..cd6af741 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java @@ -22,22 +22,33 @@ import org.eclipse.ui.IWorkbenchSite; import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.properties.widgets.ValveOrientationGroup; import org.simantics.sysdyn.ui.properties.widgets.ValveTextLocationGroup; import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; +import org.simantics.ui.utils.AdaptionUtils; -public class VariableInformationTab extends LabelPropertyTabContributor { - +public class VariableInformationTab extends LabelPropertyTabContributor implements Widget { + Composite orientationComposite; + WidgetSupport support; + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + this.support = support; + support.register(this); + Composite composite = new Composite(body, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); - GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite); + GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); Group informationGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); informationGroup.setText("Information"); @@ -49,6 +60,10 @@ public class VariableInformationTab extends LabelPropertyTabContributor { information.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasDescription)); GridDataFactory.fillDefaults().grab(true, true).applyTo(information.getWidget()); + orientationComposite = new Composite(composite, SWT.NONE); + GridDataFactory.fillDefaults().span(1, 2).applyTo(orientationComposite); + GridLayoutFactory.fillDefaults().margins(3,3).applyTo(orientationComposite); + Group rangeGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); rangeGroup.setText("Range"); GridDataFactory.fillDefaults().applyTo(rangeGroup); @@ -83,11 +98,7 @@ public class VariableInformationTab extends LabelPropertyTabContributor { rangeStep.setInputValidator(new DoubleValidator()); GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeStep.getWidget()); - Composite valveComposite = new Composite(composite, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(valveComposite); - GridLayoutFactory.fillDefaults().numColumns(2).margins(3,3).applyTo(valveComposite); - new ValveOrientationGroup(valveComposite, context, support, SWT.NONE); - new ValveTextLocationGroup(valveComposite, context, support, SWT.NONE); + } @@ -108,4 +119,29 @@ public class VariableInformationTab extends LabelPropertyTabContributor { } } + @Override + public void setInput(ISessionContext context, Object input) { + final Resource valve = AdaptionUtils.adaptToSingle(input, Resource.class); + Boolean isValve = false; + try { + isValve = context.getSession().syncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + return graph.isInstanceOf(valve, sr.Valve); + } + + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + if(isValve) { + ValveOrientationGroup vog = new ValveOrientationGroup(orientationComposite, context, support, SWT.NONE); + vog.setInput(context, input); + ValveTextLocationGroup vtlg = new ValveTextLocationGroup(orientationComposite, context, support, SWT.NONE); + vtlg.setInput(context, input); + orientationComposite.getParent().layout(); + } + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveOrientationGroup.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveOrientationGroup.java index 9b3ff468..6f7546ed 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveOrientationGroup.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveOrientationGroup.java @@ -38,7 +38,6 @@ public class ValveOrientationGroup extends WidgetImpl { public ValveOrientationGroup(Composite parent, ISessionContext context, WidgetSupport support, int style) { super(support); - support.register(this); group = new Group(parent, SWT.NONE); group.setText("Valve orientation"); GridDataFactory.fillDefaults().applyTo(group); @@ -57,8 +56,8 @@ public class ValveOrientationGroup extends WidgetImpl { @Override public void setInput(ISessionContext context, Object input) { - - + horizontal.setInput(context, input); + vertical.setInput(context, input); } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveTextLocationGroup.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveTextLocationGroup.java index 04252f0a..69d8376a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveTextLocationGroup.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveTextLocationGroup.java @@ -68,8 +68,10 @@ public class ValveTextLocationGroup extends WidgetImpl { @Override public void setInput(ISessionContext context, Object input) { - // TODO Auto-generated method stub - + top.setInput(context, input); + bottom.setInput(context, input); + left.setInput(context, input); + right.setInput(context, input); } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPane.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPane.java deleted file mode 100644 index 4ee9a596..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPane.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.ui.trend; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.part.ViewPart; -import org.simantics.g2d.chassis.SWTChassis; - -public class ChartPane extends ViewPart { - - - @Override - public void createPartControl(Composite parent) { - SWTChassis canvas = new SWTChassis(parent, SWT.NONE); - canvas.syncPopulate(); - } - - - @Override - public void setFocus() { - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java new file mode 100644 index 00000000..65e97ddf --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java @@ -0,0 +1,277 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend; + +import java.awt.Frame; +import java.text.SimpleDateFormat; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.graphics.Transform; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.part.ViewPart; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.ChartFrame; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.DateAxis; +import org.jfree.chart.plot.XYPlot; +import org.jfree.data.time.Day; +import org.jfree.data.time.TimeSeries; +import org.jfree.data.time.TimeSeriesCollection; +import org.simantics.g2d.chassis.SWTChassis; +import org.simantics.utils.threads.SWTThread; +import org.simantics.utils.threads.ThreadUtils; +import org.simantics.utils.ui.SWTAWTComponent; + +public class ChartPanel extends ViewPart { + + ScrolledComposite sc; + Composite composite; + + @Override + public void createPartControl(Composite parent) { + Composite c = new Composite(parent, SWT.NONE); + GridLayoutFactory.fillDefaults().applyTo(c); + + sc = new ScrolledComposite(c, SWT.H_SCROLL | SWT.V_SCROLL); + GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); + GridLayoutFactory.fillDefaults().applyTo(sc); + + composite = new Composite(sc, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(6).applyTo(composite); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + + + sc.setContent(composite); + sc.setExpandHorizontal(true); + sc.setExpandVertical(true); + sc.getVerticalBar().setIncrement(30); + sc.getVerticalBar().setPageIncrement(200); + sc.addControlListener( new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + //System.out.println("ScrolledComposite resized: " + sc.getSize()); + refreshScrolledComposite(); + } + }); + + final Canvas canvas = new Canvas(composite, SWT.BORDER); + // Create a paint handler for the canvas + canvas.addPaintListener(new PaintListener() { + public void paintControl(PaintEvent e) { + int canvasHeight = canvas.getSize().y; + String text = "Module1.Variable2[index3]"; + Transform t = new Transform(e.display); + t.rotate(-90); + t.translate(- (canvasHeight - 10), 0); + e.gc.setTransform(t); + e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_BLACK)); + e.gc.drawText(text, 0, 0); + } + }); + GridDataFactory.fillDefaults().hint(20, SWT.DEFAULT).grab(false, true).applyTo(canvas); + canvas.setCursor(new Cursor(canvas.getDisplay(), SWT.CURSOR_HAND)); + canvas.addMouseListener(new NewTrendListener()); + ToolTipListener ttl = new ToolTipListener(canvas); + canvas.addListener(SWT.Dispose, ttl); + canvas.addListener(SWT.KeyDown, ttl); + canvas.addListener(SWT.MouseMove, ttl); + canvas.addListener(SWT.MouseHover, ttl); + + Composite swtComposite = new Composite(composite, + SWT.NO_BACKGROUND | SWT.EMBEDDED); + GridDataFactory.fillDefaults().hint(200, 200).applyTo(swtComposite); + Frame frame = SWT_AWT.new_Frame(swtComposite); + setChart(frame); + } + + + @Override + public void setFocus() { + } + + @Override + public void dispose() { + + } + + + void refreshScrolledComposite() { + // Execute asynchronously to give the UI events triggering this method + // call time to run through before actually doing any resizing. + // Otherwise the result will lag behind reality when scrollbar + // visibility is toggled by the toolkit. + ThreadUtils.asyncExec(SWTThread.getThreadAccess(composite.getDisplay()), new Runnable() { + @Override + public void run() { + if (sc.isDisposed()) + return; + syncRefreshScrolledComposite(); + } + }); + } + + void syncRefreshScrolledComposite() { + // Execute asynchronously to give the UI events triggering this method + // call time to run through before actually doing any resizing. + // Otherwise the result will lag behind reality when scrollbar + // visibility is toggled by the toolkit. + Rectangle r = sc.getClientArea(); + Point contentSize = composite.computeSize(r.width, SWT.DEFAULT); + //System.out.println("[" + Thread.currentThread() + "] computed content size: " + contentSize + ", " + r); + composite.setSize(contentSize); + } + + private class NewTrendListener implements MouseListener { + + @Override + public void mouseUp(MouseEvent e) { + final Canvas canvas = new Canvas(composite, SWT.BORDER); + // Create a paint handler for the canvas + canvas.addPaintListener(new PaintListener() { + public void paintControl(PaintEvent e) { + int canvasHeight = canvas.getSize().y; + String text = "Module1.Variable2[index3]"; + Transform t = new Transform(e.display); + t.rotate(-90); + t.translate(- (canvasHeight - 10), 0); + e.gc.setTransform(t); + e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_BLACK)); + e.gc.drawText(text, 0, 0); + } + }); + GridDataFactory.fillDefaults().hint(20, SWT.DEFAULT).grab(false, true).applyTo(canvas); + composite.layout(); + canvas.addMouseListener(this); + canvas.setCursor(new Cursor(canvas.getDisplay(), SWT.CURSOR_HAND)); + ToolTipListener ttl = new ToolTipListener(canvas); + canvas.addListener(SWT.Dispose, ttl); + canvas.addListener(SWT.KeyDown, ttl); + canvas.addListener(SWT.MouseMove, ttl); + canvas.addListener(SWT.MouseHover, ttl); + + Composite swtComposite = new Composite(composite, + SWT.NO_BACKGROUND | SWT.EMBEDDED); + Frame frame = SWT_AWT.new_Frame(swtComposite); + GridDataFactory.fillDefaults().hint(200, 200).applyTo(swtComposite); + setChart(frame); + syncRefreshScrolledComposite(); + } + + @Override + public void mouseDown(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + // TODO Auto-generated method stub + + } + } + + + private void setChart(Frame frame) { + TimeSeries population = new TimeSeries("Indian Population"); + population.add(new Day(1, 3, 1961), 439234771); + population.add(new Day(1, 3, 1971), 548159652); + population.add(new Day(1, 3, 1981), 683329097); + population.add(new Day(1, 3, 1991), 843387888); + population.add(new Day(1, 3, 2001), 1028610328); + population.add(new Day(1, 3, 2011), 1210193422); + TimeSeriesCollection dataset = new TimeSeriesCollection(population); + + // Create the chart + JFreeChart chart = ChartFactory.createTimeSeriesChart( + "Population of India", "Date", "Population", dataset, + true, true, false); + + //Get the plot and set date format + XYPlot plot = chart.getXYPlot(); + DateAxis axis = (DateAxis) plot.getDomainAxis(); + axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); + + // Render the frame + org.jfree.chart.ChartPanel panel = new org.jfree.chart.ChartPanel(chart); + panel.setSize(200, 200); + frame.add(panel); + } + + + + private class ToolTipListener implements Listener { + Shell tip = null; + Label label = null; + Composite composite; + + public ToolTipListener(Composite composite) { + this.composite = composite; + } + + public void handleEvent(Event event) { + switch (event.type) { + case SWT.Dispose: + case SWT.KeyDown: + case SWT.MouseMove: { + if (tip == null) + break; + tip.dispose(); + tip = null; + label = null; + break; + } + case SWT.MouseHover: { + if(composite.isDisposed()) + return; + if (tip != null && !tip.isDisposed()) + tip.dispose(); + Display display = composite.getDisplay(); + tip = new Shell(display, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); + tip.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + FillLayout layout = new FillLayout(); + layout.marginWidth = 2; + tip.setLayout(layout); + label = new Label(tip, SWT.NONE); + label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); + label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + label.setText("Module1.Variable2[index3]"); +// label.addListener(SWT.MouseExit, labelListener); +// label.addListener(SWT.MouseDown, labelListener); + Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT); + Point pt = composite.toDisplay(event.x, event.y); + tip.setBounds(pt.x, pt.y, size.x, size.y); + tip.setVisible(true); + } + } + } + }; +} diff --git a/org.simantics.sysdyn.ui/sysdyn.product b/org.simantics.sysdyn.ui/sysdyn.product index 1ddfd708..03cbd945 100644 --- a/org.simantics.sysdyn.ui/sysdyn.product +++ b/org.simantics.sysdyn.ui/sysdyn.product @@ -3,7 +3,6 @@ - @@ -26,8 +25,8 @@ - + org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6