Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Problems with self referencing objects
Problems with self referencing objects [message #1720599] Tue, 19 January 2016 16:38 Go to next message
Thomas Bechmann is currently offline Thomas BechmannFriend
Messages: 3
Registered: January 2016
Junior Member
Hi,
I am writing an editor for trains and have problems to create the edges for the rails. A rail has a self reference "adjacentRails" with a cardinality of [1..2]. On the viewpoint I created an relation based edge from rail to rail with [adjacentRails/] as target finder. When the edge is created the target will be added to the source list and vice versa.
Now I have two problems:

1. Connecting two rails will produce two edges, which is kind of logic, because the rails are appearing in both lists. Is it possible to create a bi-directional edge and if so, how? I could also show only one edge, but I have no idea how to do that.

2. To prevent the user from creating a third connection, I tried to limit the creation of an edge with the following precondition:
[source.oclAsType(Rail).adjacentRails->count(Rail) < 2 and target.oclAsType(Rail).adjacentRails->count(Rail) < 2/]
But it doesn't work, so I used the Acceleo Interpreter and took a look at what happens there. I clicked on a rail which has two rails in the adjacentRails list and tried the following:
[self.adjacentRails->excludes(Rail)/] which resulted True. If I delete the excludes part, it shows me the two rails, which are in the list. What have I done wrong?

I am forced to use Sirius 3.0.2, wich is installed on the PCs of my university.

Regards
Thomas
Re: Problems with self referencing objects [message #1720870 is a reply to message #1720599] Thu, 21 January 2016 15:07 Go to previous messageGo to next message
Thomas Bechmann is currently offline Thomas BechmannFriend
Messages: 3
Registered: January 2016
Junior Member
I found the solution for #2 myself. Obviously I have misunderstood what count(Rail) does. It counts the appearences of the specific object Rail and not how much objects of the type Rail are in the list.
size() will do the trick.

But #1 is still unsolved.
Re: Problems with self referencing objects [message #1721924 is a reply to message #1720599] Mon, 01 February 2016 17:02 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 500
Registered: July 2009
Location: Nantes, France
Senior Member
Hi Thomas,

Le 19/01/2016 19:38, Thomas Bechmann a écrit :
> Hi,
> I am writing an editor for trains and have problems to create the edges
> for the rails. A rail has a self reference "adjacentRails" with a
> cardinality of [1..2]. On the viewpoint I created an relation based edge
> from rail to rail with [adjacentRails/] as target finder. When the edge
> is created the target will be added to the source list and vice versa.
> Now I have two problems:
>
> 1. Connecting two rails will produce two edges, which is kind of logic,
> because the rails are appearing in both lists. Is it possible to create
> a bi-directional edge and if so, how? I could also show only one edge,
> but I have no idea how to do that.

Did you put the adjacentRails as eOpposite of itself ?
You might look in EcoreTools how Cédric managed to display a single edge
for eOpposite EReferences and is able to display only one edge to
represent two semantic elements: two EReference which are set as
eOpposite. But he uses Domain Based Edges as he wants to represents
plain EObject.

Howerver you want to represent a relation, and can only use a Relation
Based Edge mapping. I think I would try to do somethinf like in
EcoreTools but in the target finder expression of the relation based
mapping instead of the semantic condition of the Domain Based mapping.
You have to find a pattern to return an empty list when you decide that
you have returned the result in "the other direction".

You might take a look to the Bi-directional EC_EReference mapping of
EcoreTools and its semantic candidates service in [1] and [2]. I think
that the EcoreTools branch which corresponds to Sirius 3.0.2 is the 3.0
branch. In the service, we look for all references with eOpposite and
put them in a map with a key (refHashCode concatenated with
eOppositeRefHashCode) and we do not put the ref in the map if the key or
its "opposite key" is already in it.

You might have to replace your relation based edge mapping by a domain
base edge mapping with domain class Rail and do your logic in the
semantic candidates. Then targetFinder expression would be
[self.adjacentRails/] and sourceFinderExpression could be var:self


>
> 2. To prevent the user from creating a third connection, I tried to
> limit the creation of an edge with the following precondition:
> [source.oclAsType(Rail).adjacentRails->count(Rail) < 2 and
> target.oclAsType(Rail).adjacentRails->count(Rail) < 2/]
> But it doesn't work, so I used the Acceleo Interpreter and took a look
> at what happens there. I clicked on a rail which has two rails in the
> adjacentRails list and tried the following:
> [self.adjacentRails->excludes(Rail)/] which resulted True. If I delete
> the excludes part, it shows me the two rails, which are in the list.
> What have I done wrong?

As you mentionned in your own answer, the OCL count() operation returns
how many times object is in the collection self. You should use ->
size() to return the number of elements in the adjacentRails list.
You can find the OCL operations in Acceleo reference in [3]

Note that in your VSM, you should use the preconditions of the edge
creation tool to prevent your user to add too many adjacents rails:
check on the first click can be done by the connection start
precondition (with the use of the preSource variable) and check on the
second clic can be done with the connection complete precondition (with
the ise of the preSource and preTarget variables.

I think that in your question you spoke about some tests on source and
target in the tool application, but with the connection start/complete
precondition you will be able to display the "forbidden" feedback to
your user.



>
> I am forced to use Sirius 3.0.2, wich is installed on the PCs of my
> university.
>
> Regards
> Thomas


Regards,

--
Maxime - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
--
[1]
http://git.eclipse.org/c/ecoretools/org.eclipse.ecoretools.git/tree/org.eclipse.emf.ecoretools.design
[2]
http://git.eclipse.org/c/ecoretools/org.eclipse.ecoretools.git/tree/org.eclipse.emf.ecoretools.design/src/org/eclipse/emf/ecoretools/design/service/EReferenceServices.java
[3] https://wiki.eclipse.org/Acceleo/OCL_Operations_Reference


Maxime Porhel - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Problems with self referencing objects [message #1724277 is a reply to message #1721924] Mon, 22 February 2016 17:21 Go to previous message
Thomas Bechmann is currently offline Thomas BechmannFriend
Messages: 3
Registered: January 2016
Junior Member
Hi,
thank you for your answer and sorry for my late answer. My superviser suggested to create a connector class, which holds two rails. This worked for me and I havent looked into it since then. For now I will keep it that way, but I will write it in my thesis, that there might be a better different solution for further improvement.

Maxime Porhel wrote on Mon, 01 February 2016 17:02
Hi Thomas,

Did you put the adjacentRails as eOpposite of itself ?
You might look in EcoreTools how Cédric managed to display a single edge
for eOpposite EReferences and is able to display only one edge to
represent two semantic elements: two EReference which are set as
eOpposite. But he uses Domain Based Edges as he wants to represents
plain EObject.

Howerver you want to represent a relation, and can only use a Relation
Based Edge mapping. I think I would try to do somethinf like in
EcoreTools but in the target finder expression of the relation based
mapping instead of the semantic condition of the Domain Based mapping.
You have to find a pattern to return an empty list when you decide that
you have returned the result in "the other direction".

You might take a look to the Bi-directional EC_EReference mapping of
EcoreTools and its semantic candidates service in [1] and [2]. I think
that the EcoreTools branch which corresponds to Sirius 3.0.2 is the 3.0
branch. In the service, we look for all references with eOpposite and
put them in a map with a key (refHashCode concatenated with
eOppositeRefHashCode) and we do not put the ref in the map if the key or
its "opposite key" is already in it.

You might have to replace your relation based edge mapping by a domain
base edge mapping with domain class Rail and do your logic in the
semantic candidates. Then targetFinder expression would be
[self.adjacentRails/] and sourceFinderExpression could be var:self



First I tried it with a normal reference with an empty eOpposite there. Then I tried the Bi-directional Reference, but I didnt understand, what the eOpposite was good for. I also wasnt able to find anything about that in the documentation.

Regards
Thomas
Previous Topic:How to access diagram from a tabbar extenstion
Next Topic:Layout nodes in container in tree programmatically
Goto Forum:
  


Current Time: Thu Jan 21 19:13:53 GMT 2021

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

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

Back to the top