Problem with BezierCurve

Hi
I am using setCubic(true) and overridden gainedSelection and handleResize methods for curviness of the link.The whole curve lies inside the convex hull of the control points.That is contol points will not sit on the link.(That is the BezierCurve property)…
See the following link to understand my situation:
http://www.webreference.com/dlab/9902/bezier.html
I want the control points should sit always on the curve(link).So,is there any other method to get the curved link,instead of setCubic(true)?
My Question is: Is there another user manipulation model or class extension for these curved links?

Thanks,kiks

Not that is currently implemented by JGo.

Hi
Thats good.Three more things I want to know is :

  1. I have a flow activity,whcih contains arrowhead.From which,I can create(drag) more than one link and I can connect those links to the individual activities.But Problem I am getting is,I have cretaed one link from Flowactivity named “A” and connected to activity named “B”.Again I want to start(create) a link from “A”'s arrowhead to another activity “C”.That is I want to create one more link(Bezier curve) from A to C.The problem I am getting is “for creating a link ,I am keeping the cursor at the A’s arrowhead and dragging .But unfortunately,the first link(A—B) is selecting ,and I am unable to create a link from A to C.”
    I think while putting cursor on the arrowhead,the gainedSelection() method is calling ,which makes me unable to create one morelink from the activity A.What I have to do,to overcome this behaviour?
  2. “Is there any method in JGo , which supports Multiple Bezier Edge Router,so that I can drag one more link from the same activity?”
  3. I have two activities,those two activities are connected by Bezier Link.I have one facility for my link that,if I right click on the link I will get one popup menu which asks 1.Add a BusinessRule 2.Delete a Business Rule.If I select 1st option,the Business Rule will be added at the center.If I select the 2nd option,the added BusinessRule will be deleted from the link.This is the facility I have to add a BusinessRule and Delete a BusinessRule on the BezierLink.
    My problem is ,if I first add a BusinessRule to Link and then reshape the link with controlpoints,and there I am deleting the businessRule (by using right click on the link+select the 2nd option).Then my BezierLink is getting originalshape with deleted BusinessRule.I want the the shape of the Bezier link should be the same(whatever the way I have reshaped),only that BusinessRule will be deleted from the link.
    In the same way,first I will reshape the BezierLink with control points,in whatever the style I want.Then I am adding a BusinessRule(rightclick on the link+select 1st option).BusinessRule is adding on the link and the shape of the link is changing to the original style.
    Instead of that BusinessRule should be added on the reshaped link.
    Means after adding or deleting the BusinessRule on the BezierCurve,that action(adding or deleting) only should be performed .The shape should remain same.It should not come to the original shape.
    What may be the reason for this behaviour ? and what methods I have to override ?
    Thanks,kiks
  1. If I understand your situation correctly, it would be normal to make sure all of the links are in a JGoLayer that is behind the layer containing the nodes. That way the ports are in front of the links, so that the ports will get “picked” first.
  2. Yes, this is the default behavior, but perhaps you don’t see it because of your problem with (1).
    If instead you are referring to the user not being able to draw a second link between the same pair of ports, you’ll need to call JGoPort.setValidDuplicateLinks(true) on both ports.
    Then if you want the Bezier/Cubic links to have different paths, you’ll need to set their Curviness property according to how many links there are. For example, you could modify the “documentChanged” method in the BasicApp example to count how many links there are going from the FromPort to the ToPort, and call setCurviness with a new larger value than any of the existing links in that direction.
  3. I believe that the problem is that JGoLink.calculateStroke() is called when you add or remove an object as a “label” on the JGoLabeledLink. You could override calculateStroke to be a no-op when you are setting the label, and to be just the super behavior at other times.
    I suppose the call to calculateStroke() in setMidLabel is a mistake–it ought to be a call to positionLabels() instead. I think we’ll make that change for the next release.

Hi
From A to B,link was already drawn.I am unable to draw one more link from A(i.e. from A to C) easily.
Means ,For creating a link,The procedure we adopted is (in the viewrs perspective) I will put cursor on the JGoPort,then cursor will be changed to hand symbol and then I can able to draw a link.But after creating Beziercurve,by putting cursor on the JGoPort ,I am unable to get Hand cursor.But once I reshape the Bezierlink with handles to very down,means in ‘V’ shape,then I am getting handycursor on the mousemove upon JGoPort and I am able to draw onemore link(A to C).
In the same way,I am able to draw as many Beziercurved links from a single node to different destination nodes.
It seems cumbersome ,because everytime I am searching for handsymbol ,which depends on the mousemove on JGoPort.
I think this behaviour is may be due to the convexhull of BezierCurve.What is ur suggestion for this?
Thanks,kiks

Did you try what I suggested in 1.?

hi,
I have already tried that.Ports are infront of the links.
I am able to draw multiple links from the same node(port) to different nodes(exactly ports).But On mouseover the port ,I am not getting the cursor changed.I have to search at which positon of the port the cursor will change and able to draw.Once I get the changed cursor then I am able to draw a link.But why mouse moving on to the port is not changing the cursor,eventhough the ports are infront of the links?

Kiks

I don’t know. Perhaps you need to make the ports bigger so they are easier for the user to “find”.

Hi
As per my requirements,I can’t do the ports bigger in size.
For the JGoLink,the default link stroke will consist of three segments. The end segments, at the ports, will be relatively short and either horizontal or vertical. The middle segment will be just a straight line connecting the two short segments at the ports. There is no short end segment if the corresponding port does not have a link port spot (i.e., the value is NoSpot).
I have implemented Beziercurve,but I want the end segments for the Bezier curve ,which is similar to the default link stroke.I want the Bezier curve in such a way that, on both ends of the Beziercuve ,there should be a horizontal short segment,so that while drawing multiple links from the same port(SimpleNodePort),the first short segment should be same for every link coming out of the from port,next different Bezier curves,at last the same short horizontal segment should be there for the toport.
Thanks,kiks

Since such a feature isn’t built into JGo, I guess you are just asking for advice.
Are you saying that you have implemented your own Bezier curves? If so, then adding an additional segment at either end should be pretty easy. You can look at how JGoLink.calculateStroke looks at the port spot and (if not NoSpot) calls getEndSegmentLength to determine the length of that end segment.

Hi
thanks for ur immediate reply.
I have used setCubic(true) to construct a Beziercurve.And created 2 handles in gainedSelection() method and overridden the handleResize() for resizing .
But I want short horizontal end segments on both endpoints of BezierCurve.Is it possible?

Thanks,kiks

“Is it possible?” Yes, but it requires a lot of implementation work.
An alternative would be to override calculateStroke to define a three-segment bezier curve, the main segment plus one for each straight line at the end. You might then also want to override gainedSelection not to add selection handles for the control points on those two end segments, and to disallow moving the point that joins each end segment with the middle one.

can I have a sample code for this?

Sorry, but if I had had it, I would have posted it already.

Hi
Yesterday i have seen the JGO Demonstration Application.In that I saw for a JGoLink,on right click,there is popup for “Insert Point” and “Remove Segment”.If I click Insert Point,one Point is inserting ,by which I can reshape the link.
Instead of BezierCurve,I want to use this feature in my application.Tell me the steps I have to follow to develop this feature?

Thanks,kiks

That code is in Demo1View.java.
You might also be interested in what the Processor example does. In addition to adding/removing segments via the popup menu, it also lets the user draw a new link by clicking where the points of the link should be. That’s the “routing link” functionality, which implements an additional state for the view: MouseStateRoutingLink in ProcessView.java.

Is the following 2 functions sufficient?
void insertPointIntoLink()
{
if (getSelection().getPrimarySelection() instanceof JGoLink) {
JGoLink s = (JGoLink)getSelection().getPrimarySelection();
int i = s.getSegmentNearPoint(myMouseUpDocPoint);
if (s.getNumPoints() > 3) {
if (i < 1)
i = 1; // don’t add to first segment
else if (i >= s.getNumPoints()-2)
i = s.getNumPoints()-3; // don’t add to last segment
}
Point a = s.getPoint(i);
Point b = s.getPoint(i+1);
Point closest = new Point((a.x+b.x)/2, (a.y+b.y)/2);
getDocument().startTransaction();
s.insertPoint(i+1, closest);
if (s.isOrthogonal()) // when orthogonal, gotta insert two points
s.insertPoint(i+1, closest);
getSelection().toggleSelection(s);
selectObject(s);
getDocument().endTransaction(“inserted point into link stroke”);
}
}

void removeSegmentFromLink()
{
if (getSelection().getPrimarySelection() instanceof JGoLink) {
JGoLink s = (JGoLink)getSelection().getPrimarySelection();
int i = s.getSegmentNearPoint(myMouseUpDocPoint);
getDocument().startTransaction();
if (s.isOrthogonal()) { // will have at least 7 points
// don’t remove either first two or last two segments
i = Math.max(i, 2);
i = Math.min(i, s.getNumPoints()-5);
Point a = s.getPoint(i);
Point b = s.getPoint(i+1);
s.removePoint(i);
// to maintain orthogonality, gotta remove two points
s.removePoint(i);
// now fix up following point to maintain orthogonality
Point c = new Point(s.getPoint(i));
if (a.x == b.x) {
c.y = a.y;
} else {
c.x = a.x;
}
s.setPoint(i, c);
} else { // will have at least 3 points
i = Math.max(i, 1); // don’t remove point 0
i = Math.min(i, s.getNumPoints()-2); // don’t remove last point
s.removePoint(i);
}
getSelection().toggleSelection(s);
selectObject(s);
getDocument().endTransaction(“removed segment from link stroke”);
}
}

I think these are only for inserting and removing the Points.If I drag the point(reshape),wht method I suppose to see ?Is it MouseStateRoutingLink in ProcessView.java of Processor folder?
And if I want to save/retrieve the reshaped link to database,what method I suppose to be used?

Thanks,kiks

Yes, that’s for adding/removing points via menu commands (including popup menus).
The other functionality you can try by means of the Edit menu command Draw Routed Link.
For persistence, you’ll need to save the vector returned by JGoStroke.copyPoints and restore by calling JGoStroke.setPoints. Be sure to call setPoints after you have called JGoLink.setFromPort and setToPort and after you have made and initialized the nodes and their ports. Otherwise, if you move a node after calling JGoStroke.setPoints, the port will be changed, and that will call JGoLink.calculateStroke on each of the links connected to the port, which will mess up the stroke path you had dutifully restored.