From: niemisto Date: Fri, 29 Jan 2010 08:48:06 +0000 (+0000) Subject: fixed the but with the connection updates when valve was moved X-Git-Tag: simantics-1.0~85 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=6ada5868989a5cc7bf371581b6c0c7de4ab4c68a;p=simantics%2Fsysdyn.git fixed the but with the connection updates when valve was moved git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13757 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.h2d/src/org/simantics/h2d/element/Element.java b/org.simantics.h2d/src/org/simantics/h2d/element/Element.java index e51faa65..05b2ecb2 100644 --- a/org.simantics.h2d/src/org/simantics/h2d/element/Element.java +++ b/org.simantics.h2d/src/org/simantics/h2d/element/Element.java @@ -12,7 +12,7 @@ public abstract class Element implements IElement { return null; } - protected void update() { + protected void fireElementUpdated() { if(listener != null) listener.elementUpdated(this); } @@ -32,6 +32,5 @@ public abstract class Element implements IElement { if(listener != null) listener.elementRemoved(this); } - } diff --git a/org.simantics.h2d/src/org/simantics/h2d/event/handler/MoveSelected.java b/org.simantics.h2d/src/org/simantics/h2d/event/handler/MoveSelected.java index d55befc6..be23005d 100644 --- a/org.simantics.h2d/src/org/simantics/h2d/event/handler/MoveSelected.java +++ b/org.simantics.h2d/src/org/simantics/h2d/event/handler/MoveSelected.java @@ -49,8 +49,11 @@ public class MoveSelected extends DragEventHandler { @Override protected void end(IDiagramEditor editor, DragEvent event) { for(IElement element : selection) - if(element instanceof Movable) + if(element instanceof Movable) { + System.out.println("move"); ((Movable)element).move(deltaX, deltaY); + System.out.println("move ok"); + } selection = null; editor.requestRepaint(); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/CloudElement.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/CloudElement.java index 97c974d1..279feecf 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/CloudElement.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/CloudElement.java @@ -42,7 +42,6 @@ public class CloudElement extends RectangularElement implements Connectable { cloudNode.remove(); } - @Override protected void update() { //bounds.setFrame(posX-CLOUD_SIZE_X, posY-CLOUD_SIZE_Y, 2.0*CLOUD_SIZE_X, 2.0*CLOUD_SIZE_Y); Path2D path = new Path2D.Double(); @@ -62,7 +61,7 @@ public class CloudElement extends RectangularElement implements Connectable { } cloudNode.setShape(path); bounds = path.getBounds2D(); - super.update(); + fireElementUpdated(); } public boolean isRotated() { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/DependencyElement.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/DependencyElement.java index ca449e7a..41efa59f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/DependencyElement.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/DependencyElement.java @@ -96,6 +96,7 @@ public class DependencyElement extends Element implements IElementListener { } protected void updateSceneGraph() { + System.out.println("update"); double x0 = tail.getOrigo().getX(); double y0 = tail.getOrigo().getY(); double x1 = head.getOrigo().getX(); @@ -114,9 +115,11 @@ public class DependencyElement extends Element implements IElementListener { r = Math.sqrt(dx0*dx0 + dy0*dy0); Rectangle2D bounds = new Rectangle2D.Double(); tail.getBounds(bounds); + System.out.println("tail: " + bounds); angle0 = Arcs.nextIntersectingAngle(cx, cy, r, Math.atan2(-dy0, dx0), bounds, angle < 0.0); head.getBounds(bounds); + System.out.println("head: " + bounds); angle1 = Arcs.nextIntersectingAngle(cx, cy, r, Math.atan2(-dy1, dx1), bounds, angle > 0.0); double extent = angle1-angle0; @@ -148,7 +151,7 @@ public class DependencyElement extends Element implements IElementListener { public void update() { if(arcNode != null) updateSceneGraph(); - super.update(); + fireElementUpdated(); } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/FlowElement.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/FlowElement.java index 4e93b7fb..4501e6fb 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/FlowElement.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/FlowElement.java @@ -205,7 +205,7 @@ public class FlowElement extends Element implements IElementListener { public void update() { if(lineNode1 != null) updateSceneGraph(); - super.update(); + fireElementUpdated(); } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/RectangularElement.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/RectangularElement.java index c2d4a2ad..af7c0ba4 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/RectangularElement.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/RectangularElement.java @@ -34,6 +34,8 @@ public abstract class RectangularElement extends Element implements Movable { return bounds.intersects(x-tolerance, y-tolerance, 2.0*tolerance, 2.0*tolerance); } + protected abstract void update(); + @Override public void move(double deltaX, double deltaY) { posX += deltaX; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TextElement.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TextElement.java index 915b5656..860091f8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TextElement.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TextElement.java @@ -73,29 +73,31 @@ public class TextElement extends RectangularElement implements Movable, Connecta update(); } - @Override - protected void update() { - Rectangle2D textBounds = FONT.getStringBounds(label, FRC); - textBounds.setFrame( - textBounds.getX()*FONT_SCALE, - textBounds.getY()*FONT_SCALE, - textBounds.getWidth()*FONT_SCALE, - textBounds.getHeight()*FONT_SCALE - ); - - textX = posX+getTextDeltaX()-textBounds.getCenterX(); - textY = posY+getTextDeltaY()-textBounds.getCenterY(); - bounds.setFrame( - posX+getTextDeltaX()-textBounds.getWidth()*0.5-XPADDING, - posY+getTextDeltaY()-textBounds.getHeight()*0.5-YPADDING, - textBounds.getWidth()+XPADDING*2, - textBounds.getHeight()+YPADDING*2 - ); + protected void updateText() { + Rectangle2D textBounds = FONT.getStringBounds(label, FRC); + textBounds.setFrame( + textBounds.getX()*FONT_SCALE, + textBounds.getY()*FONT_SCALE, + textBounds.getWidth()*FONT_SCALE, + textBounds.getHeight()*FONT_SCALE + ); + + textX = posX+getTextDeltaX()-textBounds.getCenterX(); + textY = posY+getTextDeltaY()-textBounds.getCenterY(); + bounds.setFrame( + posX+getTextDeltaX()-textBounds.getWidth()*0.5-XPADDING, + posY+getTextDeltaY()-textBounds.getHeight()*0.5-YPADDING, + textBounds.getWidth()+XPADDING*2, + textBounds.getHeight()+YPADDING*2 + ); + + if(textNode != null) + textNode.init(label, FONT, Color.BLACK, textX, textY, FONT_SCALE); + } - if(textNode != null) - textNode.init(label, FONT, Color.BLACK, textX, textY, FONT_SCALE); - - super.update(); + protected void update() { + updateText(); + fireElementUpdated(); } class TextEditingAction implements IAction, ITextListener { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElement.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElement.java index ad3a4cd2..6cf57f6f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElement.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElement.java @@ -61,8 +61,9 @@ public class ValveElement extends TextElement implements Rotatable { path.lineTo(posX+VALVE_SIZE, posY+VALVE_SIZE); path.closePath(); valveNode.setShape(path); - super.update(); + updateText(); bounds.setFrame(posX-VALVE_SIZE, posY-VALVE_SIZE, 2.0*VALVE_SIZE, 2.0*VALVE_SIZE); + fireElementUpdated(); } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElementOld.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElementOld.java index e70e1b1b..7b33b5ca 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElementOld.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElementOld.java @@ -40,7 +40,6 @@ public class ValveElementOld extends RectangularElement implements Connectable, valveNode.remove(); } - @Override protected void update() { bounds.setFrame(posX-VALVE_SIZE, posY-VALVE_SIZE, 2.0*VALVE_SIZE, 2.0*VALVE_SIZE); Path2D path = new Path2D.Double(); @@ -56,7 +55,7 @@ public class ValveElementOld extends RectangularElement implements Connectable, path.lineTo(posX+VALVE_SIZE, posY+VALVE_SIZE); path.closePath(); valveNode.setShape(path); - super.update(); + fireElementUpdated(); } @Override