Author: kono
Date: 2012-01-11 10:08:01 -0800 (Wed, 11 Jan 2012)
New Revision: 27978
Added:
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/editor/EditMode.java
Modified:
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DEdgeView.java
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DGraphView.java
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/HandleImpl.java
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/InnerCanvas.java
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/editor/EdgeBendValueEditor.java
Log:
Fixed some bend issues. Still needs lots of minor bug fixes and cleanup.
Modified:
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DEdgeView.java
===================================================================
---
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DEdgeView.java
2012-01-11 17:12:12 UTC (rev 27977)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DEdgeView.java
2012-01-11 18:08:01 UTC (rev 27978)
@@ -354,13 +354,21 @@
m_view.m_edgeDetails.select(m_inx);
m_view.m_selectedEdges.insert(m_inx);
- for (int j = 0; j < numHandles(); j++) {
- getHandleInternal(j, m_view.m_anchorsBuff);
+ final int numHandles =
m_view.m_edgeDetails.bend(m_inx).getAllHandles().size();
+ for (int j = 0; j < numHandles; j++) {
+ //getHandleInternal(j, m_view.m_anchorsBuff);
+
+ final Bend bend = m_view.m_edgeDetails.bend(m_inx);
+ final Handle handle = bend.getAllHandles().get(j);
+ final Point2D newPoint = handle.getPoint(this);
+ m_view.handleLocationBuffer[0] = (float)
newPoint.getX();
+ m_view.handleLocationBuffer[1] = (float)
newPoint.getY();
+
m_view.m_spacialA.insert((m_inx << 6) | j,
- (float) (m_view.m_anchorsBuff[0] -
(m_view.getAnchorSize() / 2.0d)),
- (float) (m_view.m_anchorsBuff[1] -
(m_view.getAnchorSize() / 2.0d)),
- (float) (m_view.m_anchorsBuff[0] +
(m_view.getAnchorSize() / 2.0d)),
- (float) (m_view.m_anchorsBuff[1] +
(m_view.getAnchorSize() / 2.0d)));
+ (float) (m_view.handleLocationBuffer[0]
- (m_view.getAnchorSize() / 2.0d)),
+ (float) (m_view.handleLocationBuffer[1]
- (m_view.getAnchorSize() / 2.0d)),
+ (float) (m_view.handleLocationBuffer[0]
+ (m_view.getAnchorSize() / 2.0d)),
+ (float) (m_view.handleLocationBuffer[1]
+ (m_view.getAnchorSize() / 2.0d)));
if (selectAnchors)
m_view.m_selectedAnchors.insert((m_inx << 6) |
j);
}
@@ -388,7 +396,8 @@
m_view.m_edgeDetails.unselect(m_inx);
m_view.m_selectedEdges.delete(m_inx);
- for (int j = 0; j < numHandles(); j++) {
+ final int numHandles =
m_view.m_edgeDetails.bend(m_inx).getAllHandles().size();
+ for (int j = 0; j < numHandles; j++) {
m_view.m_selectedAnchors.delete((m_inx << 6) | j);
m_view.m_spacialA.delete((m_inx << 6) | j);
}
@@ -530,26 +539,14 @@
}
- public int numHandles() {
- synchronized (m_view.m_lock) {
- // Extract number of bends from bend object.
- return
m_view.m_edgeDetails.bend(m_inx).getAllHandles().size();
- }
- }
+// public int numHandles() {
+// synchronized (m_view.m_lock) {
+// // Extract number of bends from bend object.
+// return
m_view.m_edgeDetails.bend(m_inx).getAllHandles().size();
+// }
+// }
- public void setHandles(final List<Point2D> bendPoints) {
- synchronized (m_view.m_lock) {
- removeAllHandles();
- for (int i = 0; i < bendPoints.size(); i++) {
- final Point2D nextPt = (Point2D)
bendPoints.get(i);
- addHandleInternal(i, nextPt);
- }
- m_view.m_contentChanged = true;
- }
- }
-
-
final void moveHandleInternal(final int inx, double x, double y) {
final Bend bend = m_view.m_edgeDetails.bend(m_inx);
final Handle handle = bend.getAllHandles().get(inx);
@@ -563,16 +560,7 @@
(float) (y + (m_view.getAnchorSize() /
2.0d)));
}
- final void getHandleInternal(int inx, float[] buff) {
-
- final Bend bend = m_view.m_edgeDetails.bend(m_inx);
- final Handle handle = bend.getAllHandles().get(inx);
- final Point2D newPoint = handle.getPoint(this);
- buff[0] = (float) newPoint.getX();
- buff[1] = (float) newPoint.getY();
- }
-
/**
* Add a new handle and returns its index.
*
@@ -655,14 +643,12 @@
if
(m_view.m_selectedAnchors.delete((m_inx << 6) | (j - 1)))
m_view.m_selectedAnchors.insert((m_inx << 6) | j);
}
-
- final Point2D newPoint = handle.getPoint(this);
m_view.m_spacialA.insert((m_inx << 6) |
insertInx,
- (float) (newPoint.getX() -
(m_view.getAnchorSize() / 2.0d)),
- (float) (newPoint.getY() -
(m_view.getAnchorSize() / 2.0d)),
- (float) (newPoint.getX() +
(m_view.getAnchorSize() / 2.0d)),
- (float) (newPoint.getY() +
(m_view.getAnchorSize() / 2.0d)));
+ (float) (handleLocation.getX()
- (m_view.getAnchorSize() / 2.0d)),
+ (float) (handleLocation.getY()
- (m_view.getAnchorSize() / 2.0d)),
+ (float) (handleLocation.getX()
+ (m_view.getAnchorSize() / 2.0d)),
+ (float) (handleLocation.getY()
+ (m_view.getAnchorSize() / 2.0d)));
}
m_view.m_contentChanged = true;
Modified:
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DGraphView.java
===================================================================
---
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DGraphView.java
2012-01-11 17:12:12 UTC (rev 27977)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DGraphView.java
2012-01-11 18:08:01 UTC (rev 27978)
@@ -342,7 +342,7 @@
/**
* Used for holding edge anchors.
*/
- final float[] m_anchorsBuff = new float[2];
+ final float[] handleLocationBuffer = new float[2];
/**
*
Modified:
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/HandleImpl.java
===================================================================
---
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/HandleImpl.java
2012-01-11 17:12:12 UTC (rev 27977)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/HandleImpl.java
2012-01-11 18:08:01 UTC (rev 27978)
@@ -3,6 +3,7 @@
import java.awt.geom.Point2D;
import org.cytoscape.ding.Handle;
+import org.cytoscape.ding.impl.editor.EditMode;
import org.cytoscape.model.CyNode;
import org.cytoscape.view.model.View;
@@ -11,106 +12,137 @@
*
*/
public class HandleImpl implements Handle {
-
+
+ double cosTheta;
+ double sinTheta;
+ double ratio;
+
// Original handle location
private double x;
- private double y;
+ private double y;
- private double[] orthVector;
- private double originalDist;
- private double positionRatioOnEdge;
-
+ /**
+ * Create a handle at the given (x, y) position.
+ *
+ * @param x x location of handle.
+ * @param y y location of handle.
+ */
public HandleImpl(final double x, final double y) {
this.x = x;
this.y = y;
}
+
@Override
public Point2D getPoint(final DEdgeView view) {
-
final DGraphView graphView = (DGraphView) view.getGraphView();
final CyNode source = view.getModel().getSource();
final CyNode target = view.getModel().getTarget();
final View<CyNode> sourceView = graphView.getNodeView(source);
final View<CyNode> targetView = graphView.getNodeView(target);
- final Double sX = sourceView
-
.getVisualProperty(DVisualLexicon.NODE_X_LOCATION);
- final Double sY = sourceView
-
.getVisualProperty(DVisualLexicon.NODE_Y_LOCATION);
+ final Double sX =
sourceView.getVisualProperty(DVisualLexicon.NODE_X_LOCATION);
+ final Double sY =
sourceView.getVisualProperty(DVisualLexicon.NODE_Y_LOCATION);
- final Double tX = targetView
-
.getVisualProperty(DVisualLexicon.NODE_X_LOCATION);
- final Double tY = targetView
-
.getVisualProperty(DVisualLexicon.NODE_Y_LOCATION);
+ final Double tX =
targetView.getVisualProperty(DVisualLexicon.NODE_X_LOCATION);
+ final Double tY =
targetView.getVisualProperty(DVisualLexicon.NODE_Y_LOCATION);
final Point2D newPoint = new Point2D.Double();
- if (orthVector != null) {
- final double newDist = Math.sqrt(Math.pow(tX - sX, 2) +
Math.pow(tY - sY, 2));
- final double newRatio = newDist / originalDist;
- final double[] newOrth = new double[2];
- newOrth[0] = orthVector[0] * newRatio;
- newOrth[1] = orthVector[1] * newRatio;
+ if (EditMode.isDirectMode() == false) {
- final double newX = newOrth[0] + positionRatioOnEdge *
(tX - sX) + sX;
- final double newY = newOrth[1] + positionRatioOnEdge *
(tY - sY) + sY;
-
+ // edge vector v = (tX-sX, tY-sY)
+ final double vx = tX-sX;
+ final double vy = tY-sY;
+
+ // rotate
+ double newX = vx*cosTheta - vy*sinTheta;
+ double newY = vx*sinTheta + vy*cosTheta;
+
+ // Translate
+ newX = (newX+sX)*ratio;
+ newY = (newY+sY)*ratio;
newPoint.setLocation(newX, newY);
- } else {
+
+ double distedge = Math.sqrt(Math.pow(tX - sX, 2) +
Math.pow(tY - sY, 2));
+ double distnew = Math.sqrt(Math.pow(newX - sX, 2) +
Math.pow(newY - sY, 2));
+// System.out.println("(Sx, Sy) = (" + sX + ", " + sY +
")");
+// System.out.println("(Tx, Ty) = (" + tX + ", " + tY +
")");
+// System.out.println("newX = " + newX);
+// System.out.println("newY = " + newY );
+// System.out.println("edgeLen = " + distedge);
+// System.out.println("ratio = " + ratio);
+// System.out.println("dist to handle = " + distnew );
+// System.out.println("** theta degree = " +
Math.acos(cosTheta)* 180 / Math.PI);
+ } else
newPoint.setLocation(x, y);
- }
return newPoint;
}
+
@Override
public void setPoint(final DEdgeView view, double x, double y) {
final DGraphView graphView = (DGraphView) view.getGraphView();
this.x = x;
this.y = y;
-
convertToRatio(graphView, view, new Point2D.Double(x, y));
}
- private void convertToRatio(DGraphView graphView, DEdgeView view,
- final Point2D absolutePoint) {
- orthVector = new double[2];
-
+ private void convertToRatio(DGraphView graphView, DEdgeView view, final
Point2D absolutePoint) {
final CyNode source = view.getModel().getSource();
final CyNode target = view.getModel().getTarget();
final View<CyNode> sourceView = graphView.getNodeView(source);
final View<CyNode> targetView = graphView.getNodeView(target);
- final Double sX = sourceView
-
.getVisualProperty(DVisualLexicon.NODE_X_LOCATION);
- final Double sY = sourceView
-
.getVisualProperty(DVisualLexicon.NODE_Y_LOCATION);
+ // Location of source node
+ final Double sX =
sourceView.getVisualProperty(DVisualLexicon.NODE_X_LOCATION);
+ final Double sY =
sourceView.getVisualProperty(DVisualLexicon.NODE_Y_LOCATION);
- final Double tX = targetView
-
.getVisualProperty(DVisualLexicon.NODE_X_LOCATION);
- final Double tY = targetView
-
.getVisualProperty(DVisualLexicon.NODE_Y_LOCATION);
+ // Location of target node
+ final Double tX =
targetView.getVisualProperty(DVisualLexicon.NODE_X_LOCATION);
+ final Double tY =
targetView.getVisualProperty(DVisualLexicon.NODE_Y_LOCATION);
+ // Location of handle
final double hX = absolutePoint.getX();
final double hY = absolutePoint.getY();
- final double oX;
- final double oY;
- final double k;
+ // Vector v1
+ // Distance from source to target (Edge length)
+ double dist1 = Math.sqrt(Math.pow(tX - sX, 2) + Math.pow(tY -
sY, 2));
+
+ // Vector v2
+ // Distance from source to current handle
+ double dist2 = Math.sqrt(Math.pow(hX - sX, 2) + Math.pow(hY -
sY, 2));
+
+ // Ratio of vector lengths
+ ratio = dist2/dist1;
+
+ // Dot product of v1 and v2
+ double dotProduct = ((tX-sX) * (hX-sX)) + ((tY-sY) * (hY-sY));
+ double dist2Squared = Math.pow(dist2, 2);
+
+ // vp is a component vector parallel to v2.
+ // vp = k*v2
+ double r = dotProduct/dist2Squared;
+
+ // Now, we can get the length of the vp
+ double lengthVp = Math.sqrt(Math.pow(r * (hX-sX), 2) +
Math.pow(r * (hY-sY), 2));
+
+ // Now we can get the Cos(theta)
+ cosTheta = lengthVp/dist1;
+ // Theta is the angle between v1 and v2
+ final double theta = Math.acos(cosTheta);
+ sinTheta = Math.sin(theta);
- // Solved the equation to find orthogonal vector manually...
Can be replaced once we find better 2D Vector library.
- k = -((tX - sY) * (sX - tX) + (tY - sY) * (sY - tY))
- / (hX * tX - hX * sX + hY * tY - hY * sY + sX *
sX - sX * tX
- + sY * sY - sY * tY);
- oX = (tX - sX + k * sX) / k;
- oY = (tY - sY + k * sY) / k;
-
- orthVector[0] = hX - oX;
- orthVector[1] = hY - oY;
-
- originalDist = Math.sqrt(Math.pow(tX - sX, 2) + Math.pow(tY -
sY, 2));
- positionRatioOnEdge = Math.sqrt(Math.pow(oX - sX, 2)
- + Math.pow(oY - sY, 2))
- / originalDist;
+// System.out.println("** (Sx, Sy) = (" + sX + ", " + sY + ")");
+// System.out.println("** (Tx, Ty) = (" + tX + ", " + tY + ")");
+// System.out.println("!Handle ID = " + this.hashCode());
+// System.out.println("** edge Distance = " + dist1);
+// System.out.println("** Handle Distance = " + dist2);
+// System.out.println("** distance R2 = " + ratio);
+// System.out.println("** cos = " + cosTheta);
+// System.out.println("** sin = " + sinTheta);
+// System.out.println("** theta rad = " + theta);
+// System.out.println("** theta degree = " + (theta* 180 /
Math.PI));
}
}
Modified:
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/InnerCanvas.java
===================================================================
---
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/InnerCanvas.java
2012-01-11 17:12:12 UTC (rev 27977)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/InnerCanvas.java
2012-01-11 18:08:01 UTC (rev 27978)
@@ -56,8 +56,10 @@
import java.awt.image.BufferedImage;
import java.util.List;
+import org.cytoscape.ding.Bend;
import org.cytoscape.ding.EdgeView;
import org.cytoscape.ding.GraphViewChangeListener;
+import org.cytoscape.ding.Handle;
import org.cytoscape.ding.NodeView;
import org.cytoscape.ding.ViewChangeEdit;
import org.cytoscape.ding.impl.events.GraphViewEdgesSelectedEvent;
@@ -506,7 +508,7 @@
m_view.xformComponentToNodeCoords(m_ptBuff);
// Store current handle list
m_undoable_edit = new ViewChangeEdit(m_view,
ViewChangeEdit.SavedObjs.SELECTED_EDGES, "Add Edge Handle", m_undo);
- final int chosenInx = ((DEdgeView)
m_view.getDEdgeView(chosenEdge)).addHandlePoint(new Point2D.Float(
+ final int chosenInx =
m_view.getDEdgeView(chosenEdge).addHandlePoint(new Point2D.Float(
(float) m_ptBuff[0], (float)
m_ptBuff[1]));
m_view.m_selectedAnchors.insert(((chosenEdge) << 6) |
chosenInx);
@@ -1023,7 +1025,13 @@
final int edge = edgeAndAnchor >>> 6;
final int anchorInx = edgeAndAnchor &
0x0000003f;
final DEdgeView ev = (DEdgeView)
m_view.getDEdgeView(edge);
- ev.getHandleInternal(anchorInx, m_floatBuff1);
+ //ev.getHandleInternal(anchorInx, m_floatBuff1);
+
+ final Bend bend = ev.getBend();
+ final Handle handle =
bend.getAllHandles().get(anchorInx);
+ final Point2D newPoint = handle.getPoint(ev);
+ m_floatBuff1[0] = (float) newPoint.getX();
+ m_floatBuff1[1] = (float) newPoint.getY();
if (code == KeyEvent.VK_UP) {
ev.moveHandleInternal(anchorInx,
m_floatBuff1[0], m_floatBuff1[1] - move);
@@ -1357,9 +1365,16 @@
final int edge = edgeAndAnchor
>>> 6;
final int anchorInx =
edgeAndAnchor & 0x0000003f;
final DEdgeView ev =
(DEdgeView) m_view.getDEdgeView(edge);
- ev.getHandleInternal(anchorInx,
m_floatBuff1);
-
ev.moveHandleInternal(anchorInx, m_floatBuff1[0] + deltaX,
-
m_floatBuff1[1] + deltaY);
+
+
//ev.getHandleInternal(anchorInx, m_floatBuff1);
+
+ final Bend bend = ev.getBend();
+ final Handle handle =
bend.getAllHandles().get(anchorInx);
+ final Point2D newPoint =
handle.getPoint(ev);
+ m_floatBuff1[0] = (float)
newPoint.getX();
+ m_floatBuff1[1] = (float)
newPoint.getY();
+
+
ev.moveHandleInternal(anchorInx, m_floatBuff1[0] + deltaX, m_floatBuff1[1] +
deltaY);
}
if ((selectedNodes.length > 0) ||
(m_view.m_selectedAnchors.size() > 0))
Modified:
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/editor/EdgeBendValueEditor.java
===================================================================
---
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/editor/EdgeBendValueEditor.java
2012-01-11 17:12:12 UTC (rev 27977)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/editor/EdgeBendValueEditor.java
2012-01-11 18:08:01 UTC (rev 27978)
@@ -127,8 +127,8 @@
dummyview.getNodeView(source).setVisualProperty(NODE_X_LOCATION, 0d);
-
dummyview.getNodeView(source).setVisualProperty(NODE_Y_LOCATION, 20d);
-
dummyview.getNodeView(target).setVisualProperty(NODE_X_LOCATION, 300d);
+
dummyview.getNodeView(source).setVisualProperty(NODE_Y_LOCATION, 200d);
+
dummyview.getNodeView(target).setVisualProperty(NODE_X_LOCATION, 200d);
dummyview.getNodeView(target).setVisualProperty(NODE_Y_LOCATION, 0d);
innerPanel.setBackground(BACKGROUND_COLOR);
@@ -163,8 +163,10 @@
@Override
public <S extends Bend> Bend showEditor(Component parent, S
initialValue) {
initUI(cyNetworkFactory, cyNetworkViewFactory,
presentationFactory);
+ EditMode.setMode(true);
this.setLocationRelativeTo(parent);
- this.setVisible(true);
+ this.setVisible(true);
+ EditMode.setMode(false);
return edgeView.getBend();
}
Added:
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/editor/EditMode.java
===================================================================
---
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/editor/EditMode.java
(rev 0)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/editor/EditMode.java
2012-01-11 18:08:01 UTC (rev 27978)
@@ -0,0 +1,15 @@
+package org.cytoscape.ding.impl.editor;
+
+public class EditMode {
+
+ private static boolean mode = false;
+
+ public static final boolean isDirectMode() {
+ return mode;
+ }
+
+ public static final void setMode(final boolean newMode) {
+ mode = newMode;
+ }
+
+}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.