-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add preliminary support for Cubic Bézier curve edge #245
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this huge contribution!
The approach of using green and red handles for adding / deleting sections is interesting and probably a good match for handling Bezier edge sections. I'd propose to add +
/ -
icons to those handles. However, a single click on those handles has no effect, but you need to move the mouse before anything happens; this is probably unintuitive.
Interesting: Bezier control points are handled as regular line segments for the computation of line jumps, see below. This is not critical, but should be noted in a separate issue once we merge this.
Keep up the good work!
@@ -0,0 +1,44 @@ | |||
/******************************************************************************** | |||
* Copyright (c) 2019 TypeFox and others. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use an up-to-date-year for new files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I will. Thanks.
+/- icons, yes definitely. Colors-only was a short-cut.
Fixing this behaviour is likely not easy (needs investigation). Actually the curve should define the line jumps and not the handles. |
5b78de3
to
c95cea4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things left to fix, otherwise it's looking great!
- Clicking on + / - still doesn't work unless I move the mouse a bit. We should listen on the
mouseUp
event, notmouseMove
. - When moving a split point between two Bezier segments, I'd expect the connected control points to move by the same amount.
- The source and target anchors seem to be determined by the position of the other node instead of the nearest control point. For example, moving around the "Ada" node affects the anchor position on the Foo node.
import { LinearEdgeRouter } from './linear-edge-router'; | ||
|
||
@injectable() | ||
export abstract class BezierEdgeRouter extends LinearEdgeRouter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks strange to inherit from LinearEdgeRouter. Shall we rename that to "AbstractEdgeRouter", or rather copy some code to avoid the inheritance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming it sounds better. I need to check how much code is really required from the inherited class. I will come back with a proposal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I go for rename, otherwise we have to copy too much code.
x: relH2.x + BezierEdgeRouter.DEFAULT_BEZIER_HANDLE_OFFSET, | ||
y: relH2.y | ||
}; | ||
return { h1: h1, h2: h2 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hint: you can write this as { h1, h2 }
. But in this case I'd propose to return a tuple instead: [h1, h2]
of type [Point, Point]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will do so.
Only one segment for now Signed-off-by: Kai Salmen <kai.salmen@typefox.io>
Allow to add but not yet remove additional new curve segment Classpath example now features to curves Control handle movement is mirrored on control handle opposite to bezier-junction Signed-off-by: Kai Salmen <kai.salmen@typefox.io>
Add and remove is done via new red and green handles available at source or junction. If only one curve is available, then there is no delete Signed-off-by: Kai Salmen <kai.salmen@typefox.io>
Add separate handle view for add/remove of bezier curves Add SBezierControlHandleView for handle visualization Signed-off-by: Kai Salmen <kai.salmen@typefox.io>
509694d
to
e97073f
Compare
Only thing left now is the +/- button behaviour. I fixed some issue with the mirrored control point alignment (when model is initially loaded) as well. |
- Renamed LinearEdgeRouter to AbstractEdgeRouter - Bezier control points move along with source, target and bezier-junctions - Fixed eslint issues - Fixed source and target anchors when moving control points and attached objects Signed-off-by: Kai Salmen <kai.salmen@typefox.io>
e97073f
to
a56cd88
Compare
- Add MouseListener that reacts on mouseDown on bezier-add and bezier-remove elements. It triggers an Action and Command that adds or removes a curve segment - Adjust class diagram layout Signed-off-by: Kai Salmen <kai.salmen@typefox.io>
Ready for review. The last open point is now resolved: Add MouseListener that reacts on mouseDown on bezier-add and bezier-remove handles. The event riggers a new Action and Command that adds or removes a curve segment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I have a few more remarks, but I'll merge it anyway so we can start the work on #243. @kaisalmen please create a new PR to address the remaining comments when the restructuring is done (will submit a PR for that today).
|
||
const result = []; | ||
let router; | ||
const element = target.root.index.getById(target.id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will just point to the same element, so target
and element
are the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I will simplify it.
edgeId: string; | ||
actionTask: BezierActionTask; | ||
|
||
constructor(@inject(TYPES.IEdgeRouter) protected readonly router: BezierEdgeRouter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actions should be serializable, so please remove the router and fetch it in the BezierCurveCommand
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, the action will only contain the targetId and a value from the enum in the future.
this.edgeId = edgeId; | ||
} | ||
|
||
getRouter(): BezierEdgeRouter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need these getters because the properties are public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ It was a bit late yesterday evening.
}; | ||
|
||
@injectable() | ||
export class BezierCurveCommand extends Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the command name should be more specific, like AddRemoveBezierSegmentCommand
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good idea. I will rename the action accordingly
This PR introduces preliminary support for cubic Bézier curve edges.
What has been achieved:
Issues that should be fixed before PR is ready
What is still missing (reason for being preliminary). To be discussed if done in scope of this PR or later:
The classdiagram has been enhanced to show the new capabilities.