Home » Eclipse Projects » Sirius » Findings node in the path edges
Findings node in the path edges [message #1734025] |
Fri, 03 June 2016 03:13  |
Eclipse User |
|
|
|
Hello,
I implement a custom layout provider. I implement a custom algorithm to create edges. Creating edges and sets them each RelativeBendpoint, so that the edge leading the way.
I need to find out whether the road on the edge there is a node, and if so, what position is the node that I could keep the edge another way.
Thanks for any advice.
Martin
|
|
| | | |
Re: Findings node in the path edges [message #1735202 is a reply to message #1734324] |
Thu, 16 June 2016 06:12   |
Eclipse User |
|
|
|
Hi Laurent,
Thank you for your answer, but I do not know exactly what method getIntersection returns.
I thought that returned intersections of edges and nodes that are on the edge, but the result somehow understand.
On the attached figure (intersections.png) shows that the edge intersects the node TST001_U003 left and above. I expected that these points method returns, but the returns do not understand.
Because I want to lead otherwise edge (around node), so I implement custom layout provider, see code below where excerpting node coordinates and intersections.
So what exactly the method returns?
Thanks so much for any advice.
Martin
Output:
source bound: (101, 70), target bound: (101, 70)
source point: (153, 209), target point: (293, 79)
intersections: Option: Point(265.0, 105.0)
Code:
class CustomLayout extends AbstractLayoutProvider {
private IGraphicalEditPart container;
public CustomLayout(IGraphicalEditPart container) {
this.container = container;
}
@SuppressWarnings("rawtypes")
@Override
public Command layoutEditParts(List selectedObjects, IAdaptable layoutHint) {
if (selectedObjects.isEmpty()) {
return UnexecutableCommand.INSTANCE;
}
for (IGraphicalEditPart graphicalEditPart : Iterables.filter(selectedObjects, IGraphicalEditPart.class)) {
EObject semanticElement = graphicalEditPart.resolveSemanticElement();
if (semanticElement instanceof DDiagramElement) {
View notationView = graphicalEditPart.getNotationView();
if (notationView instanceof Edge) {
final Edge edge = (Edge) notationView;
Bendpoints bendpoints = edge.getBendpoints();
if (bendpoints instanceof RelativeBendpoints) {
Connection connection = (Connection) GMFHelper.getGraphicalEditPart(edge).get().getFigure();
Point sourceRefPoint = connection.getSourceAnchor().getReferencePoint();
Point targetRefPoint = connection.getTargetAnchor().getReferencePoint();
connection.translateToRelative(sourceRefPoint);
connection.translateToRelative(targetRefPoint);
IFigure sourceFigure = connection.getSourceAnchor().getOwner();
IFigure targetFigure = connection.getTargetAnchor().getOwner();
System.out.println("source bound: (" + sourceFigure.getBounds().width +", "+ sourceFigure.getBounds().height + "), target bound: (" + targetFigure.getBounds().width + ", " + targetFigure.getBounds().height + ")");
System.out.println("source point: (" + sourceRefPoint.x + ", " + sourceRefPoint.y + "), target point: (" + targetRefPoint.x + ", " + targetRefPoint.y + ")");
Option<Point> intersections = GraphicalHelper.getIntersection(sourceRefPoint, targetRefPoint, graphicalEditPart, false);
System.out.println("intersections: " + intersections);
}
}
}
}
return new CompoundCommand();
}
}
[Updated on: Fri, 17 June 2016 07:03] by Moderator
|
|
| |
Re: Findings node in the path edges [message #1735470 is a reply to message #1735202] |
Mon, 20 June 2016 03:55  |
Eclipse User |
|
|
|
Hi Martin,
I gave you these methods as starting point. I didn't say that it is THE
solution. These methods allow to detect/find an intersection between an
edge and a rectangle.
You have to analyse the code of these methods and to test with your
specific code to correctly understand what they do or how to adapt them
to answer your needs. These methods use other GMF utilities classes. You
also have to look at them (and the associated javadoc). I can't do more
for you in the scope of this forum.
If this is blocking for you, you can contact us at Obeo for consulting &
coaching, or even custom development. See
http://www.obeodesigner.com/sirius for more details on Obeo's offers.
Regards,
Laurent
Le 16/06/2016 à 12:12, Martin Jedlicka a écrit :
> Hello,
>
> Thank you for your answer, but I do not know exactly what method getIntersection returns.
>
> I thought that returned intersections of edges and nodes that are on the edge, but the result somehow understand.
>
> On the attached figure (intersections.png) shows that the edge intersects the node TST001_U003 left and above. I expected that these points method returns, but the returns do not understand.
>
> Because I want to lead otherwise edge (around node), so I implement custom layout provider, see code below where excerpting node coordinates and intersections.
>
> So what exactly the method returns?
>
> Thanks so much for any advice.
>
> Martin
>
> Output:
>
> source bound: (101, 70), target bound: (101, 70)
> source point: (153, 209), target point: (293, 79)
> intersections: Option: Point(265.0, 105.0)
>
>
> Code:
>
> class CustomLayout extends AbstractLayoutProvider {
>
> private IGraphicalEditPart container;
>
> public CustomLayout(IGraphicalEditPart container) {
> this.container = container;
> }
>
> @SuppressWarnings("rawtypes")
> @Override
> public Command layoutEditParts(List selectedObjects, IAdaptable layoutHint) {
>
> if (selectedObjects.isEmpty()) {
> return UnexecutableCommand.INSTANCE;
> }
>
> for (IGraphicalEditPart graphicalEditPart : Iterables.filter(selectedObjects, IGraphicalEditPart.class)) {
>
> EObject semanticElement = graphicalEditPart.resolveSemanticElement();
>
> if (semanticElement instanceof DDiagramElement) {
> View notationView = graphicalEditPart.getNotationView();
>
> if (notationView instanceof Edge) {
> final Edge edge = (Edge) notationView;
> Bendpoints bendpoints = edge.getBendpoints();
>
> if (bendpoints instanceof RelativeBendpoints) {
> Connection connection = (Connection) GMFHelper.getGraphicalEditPart(edge).get().getFigure();
>
> Point sourceRefPoint = connection.getSourceAnchor().getReferencePoint();
> Point targetRefPoint = connection.getTargetAnchor().getReferencePoint();
> connection.translateToRelative(sourceRefPoint);
> connection.translateToRelative(targetRefPoint);
> IFigure sourceFigure = connection.getSourceAnchor().getOwner();
> IFigure targetFigure = connection.getTargetAnchor().getOwner();
>
> System.out.println("source bound: (" + sourceFigure.getBounds().width +", "+ sourceFigure.getBounds().height + "), target bound: (" + targetFigure.getBounds().width + ", " + targetFigure.getBounds().height + ")");
> System.out.println("source point: (" + sourceRefPoint.x + ", " + sourceRefPoint.y + "), target point: (" + targetRefPoint.x + ", " + targetRefPoint.y + ")");
>
> Option<Point> intersections = GraphicalHelper.getIntersection(sourceRefPoint, targetRefPoint, graphicalEditPart, false);
> System.out.println("intersections: " + intersections);
> }
> }
> }
> }
>
> return new CompoundCommand();
> }
> }
>
--
Laurent Redor - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
Goto Forum:
Current Time: Tue Apr 15 01:17:15 EDT 2025
Powered by FUDForum. Page generated in 0.03065 seconds
|