|
Re: Message Position [message #1806854 is a reply to message #1806705] |
Thu, 16 May 2019 11:29 |
Antonio Campesino Messages: 56 Registered: August 2016 |
Member |
|
|
Hi Oliver,
The connector in the notation diagram needs to have the source and target lifelines as source and target nodes of the connector. Then you need to define the anchoring points. That it is a little more tricky. You need to define identities anchors, which defined the position in relative coordinates to the lifeline, where (0.0 ,0,0) correspond to the top-left corner of the lifeline and (1.0,1.0) correspond to the right bottom corner of the diagram.
So basically you need to do:
IdentityAnchor notAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
notAnchor.setId(terminal);
Where terminal is a string in the form "(0.5,0.20)" will it will create the anchor in the (lifeline_width * 0.5), (lifeline_height * 0.20) relative to th etop-left corner of the lifeline. The size of the is equal to the constraint you set for the lifeline shape in the notation diagram.
Now if you are creating the diagram, with a sequence diagram open in papyrus, and you have access to the GraphicalViewer of the diagram, you can use the editparts and figures to create the anchors, like that:
private IdentityAnchor createAnchor(GraphicalViewer viewer, Node source, Node target, Point absolutePoint, boolean isSource) {
CreateConnectionRequest loc = new CreateConnectionRequest();
loc.setSourceEditPart(source.getEditPart());
loc.setTargetEditPart(target.getEditPart());
Point pt = CoordinateReferentialUtils.transformPointFromDiagramToScreenReferential(absolutePoint
new Point(dimension.width, dimension.height), (GraphicalViewer)viewer);
loc.setLocation(pt);
loc.setSnapToEnabled(true);
INodeEditPart editPart = isSource ? (INodeEditPart)source.getEditPart() : (INodeEditPart)target.getEditPart();
ConnectionAnchor anchor = isSource ? editPart.getSourceConnectionAnchor(loc) : editPart.getTargetConnectionAnchor(loc);
String terminal = editPart.mapConnectionAnchorToTerminal(anchor);
IdentityAnchor notAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
notAnchor.setId(terminal);
return notAnchor;
}
I hope this will help you. However, the final location in the diagram, when you open it in papyrus is modified in many ways by the installed edit policies. It may happen you set the anchor in a specific location in the notation, but the position where they are displayed, it maybe different.
We are working in a fork of the sequence diagrams, trying to fix many of the issues the current implementation has today. Also trying to simplify and improved the usability of that diagrams, it is work in progress but you could give it a try. In any case there is a lot of code that shows how you manipulate the notation diagram to create programatically the different elements in the sequence diagrams:
The fork is here:
https://github.com/Ericsson/papyrus-patches
And details how we are implementing it here:
https://github.com/Ericsson/papyrus-patches/wiki/Sequence-Diagram-Implementation-Details
But what you are probably more interested is in this class: InteractionGraphCommand, and specially in the function. buildDelegateCommands()
Best regards,
Antonio
|
|
|
|
Re: Message Position [message #1806949 is a reply to message #1806940] |
Sun, 19 May 2019 07:45 |
Antonio Campesino Messages: 56 Registered: August 2016 |
Member |
|
|
Hi,
No, it is not removed is that that Node in the function is a wrapper we used, but still the principle is the same:
private IdentityAnchor createAnchor(GraphicalViewer viewer, Edge edge, Point absolutePoint, boolean isSource) {
View source = edge.getSource();
View target = edge.getTarget();
EditPart sourceEp = viewer.getEditPartRegistry().get(source);
EditPart targetEp = viewer.getEditPartRegistry().get(target);
CreateConnectionRequest loc = new CreateConnectionRequest();
loc.setSourceEditPart(sourceEp);
loc.setTargetEditPart(targetEp);
Point pt = CoordinateReferentialUtils.transformPointFromDiagramToScreenReferential(absolutePoint
new Point(dimension.width, dimension.height), (GraphicalViewer)viewer);
loc.setLocation(pt);
loc.setSnapToEnabled(true);
INodeEditPart editPart = isSource ? (INodeEditPart)sourceEp : (INodeEditPart)targetEp();
ConnectionAnchor anchor = isSource ? editPart.getSourceConnectionAnchor(loc) : editPart.getTargetConnectionAnchor(loc);
String terminal = editPart.mapConnectionAnchorToTerminal(anchor);
IdentityAnchor notAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
notAnchor.setId(terminal);
return notAnchor;
}
Now the snippet should work. Note the CSSConnector is a notation Edge, so you can pass it to the function
Regards,
Antoni
|
|
|
|
Re: Message Position [message #1806956 is a reply to message #1806954] |
Sun, 19 May 2019 16:00 |
Oliver Holdt Messages: 9 Registered: April 2019 |
Junior Member |
|
|
Nevermind. I found it out myself
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IEditorPart editorPart = page.getActiveEditor();
GraphicalViewer viewer = (GraphicalViewer) editorPart.getAdapter(GraphicalViewer.class);
Edit: This is returning null for my nodes. Is there another way?
[Updated on: Sun, 19 May 2019 16:50] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04917 seconds