Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » How to access an EObject's position and size?
How to access an EObject's position and size? [message #1834259] Fri, 06 November 2020 04:14 Go to next message
Yufei Zhou is currently offline Yufei ZhouFriend
Messages: 44
Registered: March 2020
Member
Hi,

I'm working with sirius to save my model with nodes' position and size information to a file. I searched in the forum but didn't find any documents about how can I access the position and size of an EObject. I tried SiriusLayoutDataManager.INSTANCE.getData() on an existing eobject node, but the return value is null.

How can I get and set the position and size programmatically in sirius? Is there any api to do that work? Any advice would help a lot.

Thanks.
Re: How to access an EObject's position and size? [message #1834264 is a reply to message #1834259] Fri, 06 November 2020 08:45 Go to previous messageGo to next message
Anthony Nillar is currently offline Anthony NillarFriend
Messages: 74
Registered: May 2014
Member
Hi Yufei Zhou,

I have a code in which a get the position of the graphical elements. If you get the NodeImpl (org.eclipse.gmf.runtime.notation.impl.NodeImpl) probably you can try:
NodeImpl node = (NodeImpl) modelObject;
LayoutConstraint nodeLayoutConstraint = node.getLayoutConstraint();
if (nodeLayoutConstraint instanceof Bounds) {
    Bounds bounds = (Bounds) nodeLayoutConstraint;
    int x = bounds.getX()
    int y = bounds.getY()
}

Hope that this helps.

Kind regards,
Anthony

Re: How to access an EObject's position and size? [message #1834270 is a reply to message #1834264] Fri, 06 November 2020 10:08 Go to previous messageGo to next message
Yufei Zhou is currently offline Yufei ZhouFriend
Messages: 44
Registered: March 2020
Member
Hi Anthony,

Thanks for your help. I tried your code snippet, but there's a ClassCastException said that the modelObject cannot cast to NodeImpl. Is there any other way to obtain a Sirius NodeImpl from a semantic eobject?
Re: How to access an EObject's position and size? [message #1834276 is a reply to message #1834270] Fri, 06 November 2020 10:59 Go to previous messageGo to next message
Anthony Nillar is currently offline Anthony NillarFriend
Messages: 74
Registered: May 2014
Member
Hi Yufei Zhou,

I do not know if I understand your point. I suppose that you are loading an .aird representation to get the current objects' positions, it is that correct? Would you please describe in detail what you are trying to do? Thanks.

Kind regards,
Anthony
Re: How to access an EObject's position and size? [message #1834280 is a reply to message #1834276] Fri, 06 November 2020 11:41 Go to previous messageGo to next message
Yufei Zhou is currently offline Yufei ZhouFriend
Messages: 44
Registered: March 2020
Member
Hi Anthony,

This is my previous post, where I described my need that I hope to copy&paste an EObject while keeping its layout. I'm finding internal apis to implement it but met some difficulties.
https://www.eclipse.org/forums/index.php/t/1105696/

What I really want to do is let my user choose a device(by typing its name in a textfield so I can find it) and input a location, then the application will place the device to that location. I've finished the first step(choose a device), so I have a Device EObject right now, and I'm finding a method to get and set the Device EObject's location. In other words, I hope to find an api to access a semantic eobject's graphical data.

I don't know if I explained myself well, sorry for the bad English. Thanks very much for your help Anthony, I will appreciate it if you can give me some further information. Any advice would be helpful.

Kindly Regards,
Yufei Zhou
Re: How to access an EObject's position and size? [message #1834285 is a reply to message #1834280] Fri, 06 November 2020 14:12 Go to previous messageGo to next message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 270
Registered: July 2009
Senior Member
Hi,

If you are in a create tool, you can also something like explained in Set Coordinates/Position at node creation using a Node Creation Tool or in Set Coordinates/Position at node creation using an existing node.

I'm not sure it's a good solution to go through semantic elements if you initially "start" from graphical elements. Otherwise, you have to use crossreferencer and helper like
org.eclipse.sirius.business.api.query.EObjectQuery.getInverseReferences(EReference)
.
Warning: There are 2 graphical notions :
* One between GMF graphical elements and Sirius graphical elements:
org.eclipse.gmf.runtime.notation.View.getElement()

* One between Sirius graphical elements and semantic elements:
org.eclipse.sirius.viewpoint.DSemanticDecorator.getTarget()


Regards,

Laurent


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: How to access an EObject's position and size? [message #1834322 is a reply to message #1834285] Sat, 07 November 2020 08:28 Go to previous messageGo to next message
Yufei Zhou is currently offline Yufei ZhouFriend
Messages: 44
Registered: March 2020
Member
Hi Laurent,

Thanks for your help. I've tried the two notions you mentioned, they are both useful, but I still need another api for getting a GMF view from a semantic element. Is there any api I can do this?
Re: How to access an EObject's position and size? [message #1834445 is a reply to message #1834322] Tue, 10 November 2020 13:37 Go to previous messageGo to next message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 270
Registered: July 2009
Senior Member
Hi,
I already gave you the pointers to crossreferencer in previous comment.

The code should be something like (untested code just written for easy understanding):
        Collection<EObject> targetReferences = eObjectQuery.getInverseReferences(ViewpointPackage.Literals.DSEMANTIC_DECORATOR__TARGET);
        for (EObject targetReference : targetReferences) {
            if (targetReference instanceof DDiagramElementContainer) {
                // or (targetReference instanceof DNode) if the expected element is a Node (use a NodeMapping and not a ContainerMapping)
                EObjectQuery dDiagElementQuery = new EObjectQuery((DDiagramElementContainer) targetReference);
                Collection<EObject> elementReferences = dDiagElementQuery.getInverseReferences(NotationPackage.Literals.VIEW__ELEMENT);
                for (EObject elementReference : elementReferences) {
                    if (elementReference instanceof org.eclipse.gmf.runtime.notation.Node) {
                        //Do someting with GMF Node
                    }
                }
            }
        }


Regards,

Laurent


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: How to access an EObject's position and size? [message #1834448 is a reply to message #1834445] Tue, 10 November 2020 14:30 Go to previous messageGo to next message
Yufei Zhou is currently offline Yufei ZhouFriend
Messages: 44
Registered: March 2020
Member
Thanks Laurent, I've managed to get the node from semantic elements.
But I still cannot set the gmf node's bounds. I used setLayoutConstraint api and passed a bounds to that api, but the node on the diagram doesn't change. Is there something wrong the procedure? Or there is some other method to set the node's location and size?
Re: How to access an EObject's position and size? [message #1834553 is a reply to message #1834448] Thu, 12 November 2020 10:23 Go to previous messageGo to next message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 270
Registered: July 2009
Senior Member
In theory, it is enough. But it depends when you do this change, the "location and size" management is tricky. For example during a creation tool, it is possible that Sirius overrides your change by the standard location.
So without more details on your specific code, it's difficult to help you more.


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: How to access an EObject's position and size? [message #1834560 is a reply to message #1834553] Thu, 12 November 2020 12:59 Go to previous message
Yufei Zhou is currently offline Yufei ZhouFriend
Messages: 44
Registered: March 2020
Member
Thanks Laurent, I've managed to solve this problem.
Previous Topic:How to copy an element while keeping its layout?
Next Topic:What happens after DiagramDialectUIServices.openEditor?
Goto Forum:
  


Current Time: Mon Apr 19 13:45:05 GMT 2021

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

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

Back to the top