Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Message Position
Message Position [message #1806705] Tue, 14 May 2019 08:49 Go to next message
Oliver Holdt is currently offline Oliver HoldtFriend
Messages: 9
Registered: April 2019
Junior Member
Hi guys,
I'm currently trying to create a sequence diagram programmatically. I'm having the problem that if I have a message edge (CSSConnectorImpl), I don't know how to set the location of the two endpoints on the diagram. How can I do that? Thanks in advance.
Re: Message Position [message #1806854 is a reply to message #1806705] Thu, 16 May 2019 11:29 Go to previous messageGo to next message
Antonio Campesino is currently offline Antonio CampesinoFriend
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 #1806940 is a reply to message #1806854] Sat, 18 May 2019 11:38 Go to previous messageGo to next message
Oliver Holdt is currently offline Oliver HoldtFriend
Messages: 9
Registered: April 2019
Junior Member
Hello Antonio,
the method getEditPart() of Node seems to removed. Is there another way to achieve this?

Best Regards
Oliver
Re: Message Position [message #1806949 is a reply to message #1806940] Sun, 19 May 2019 07:45 Go to previous messageGo to next message
Antonio Campesino is currently offline Antonio CampesinoFriend
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 #1806954 is a reply to message #1806949] Sun, 19 May 2019 09:59 Go to previous messageGo to next message
Oliver Holdt is currently offline Oliver HoldtFriend
Messages: 9
Registered: April 2019
Junior Member
Thanks for the help,but I have one more question. I've followed this example code to create my program:
https://git.eclipse.org/c/papyrus/org.eclipse.papyrus.git/tree/examples/uml/org.eclipse.papyrus.uml.diagram.example.programmaticcreation/src/org/eclipse/papyrus/uml/diagram/example/programmaticcreation/CreateSequenceDiagramElementsCommand.java?id=921e050373ff74f9367fb9c9c8ca618b4e97928a
How can I get the GraphicalViewer of the diagram?
Re: Message Position [message #1806956 is a reply to message #1806954] Sun, 19 May 2019 16:00 Go to previous messageGo to next message
Oliver Holdt is currently offline Oliver HoldtFriend
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

Re: Message Position [message #1807258 is a reply to message #1806956] Mon, 27 May 2019 05:41 Go to previous message
Oliver Holdt is currently offline Oliver HoldtFriend
Messages: 9
Registered: April 2019
Junior Member
Whe using the code scippet I always get (0.5,0.0) as a terminal value. It seems like I'm using a wrong absolutePoint. It doesn't seem to work if I use the x coordinate of the lifeline and a y value for a position along the lifeline. Can someone help?
Previous Topic:Class Diagrams get messed up?
Next Topic:Which command framework should be used preferably?
Goto Forum:
  


Current Time: Fri Apr 19 16:04:54 GMT 2024

Powered by FUDForum. Page generated in 0.02532 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top