Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 507616

Summary: Paste layout fails and introduce wrong colors on some edges
Product: [Modeling] Sirius Reporter: Cedric Brun <cedric.brun>
Component: DiagramAssignee: Pierre Guilet <pierre.guilet>
Status: CLOSED FIXED QA Contact: Florian Barbin <florian.barbin>
Severity: normal    
Priority: P3 CC: florian.barbin, laurent.redor, pierre-charles.david, pierre.guilet
Version: 4.1.0Keywords: triaged
Target Milestone: 4.1.2   
Hardware: PC   
OS: All   
See Also: https://git.eclipse.org/r/85496
https://git.eclipse.org/r/85598
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=5ecd3c3dd5e9844c8ac9bf9bf9e2bcd84f3563e1
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=8dadc572a41ead59b252e84e97704a285170306f
Whiteboard:
Attachments:
Description Flags
diagram to copy
none
diagram before paste
none
diagram after paste
none
projets to reproduce the problem none

Description Cedric Brun CLA 2016-11-16 09:39:25 EST
Created attachment 265378 [details]
diagram to copy

Steps to reproduce:
- install the family metamodel
- import the attached projects into your workspace
- open "basicfamily.sample"
- open the diagram "nice hierarchy"
- right click, Edit, Copy Format
- open the diagram "unlayouted"
- right click, Edit, Paste Layout
=> some edges don't have the same layout as what they had in "nice-hierarchy" and even worst their colors are wrong and are pink whereas they should be blue.
Comment 1 Cedric Brun CLA 2016-11-16 09:40:00 EST
Created attachment 265379 [details]
diagram before paste
Comment 2 Cedric Brun CLA 2016-11-16 09:40:14 EST
Created attachment 265380 [details]
diagram after paste
Comment 3 Cedric Brun CLA 2016-11-16 09:42:34 EST
Created attachment 265381 [details]
projets to reproduce the problem
Comment 4 Laurent Redor CLA 2016-11-16 09:46:46 EST
(In reply to Cedric Brun from comment #0)
> and even worst their colors are wrong and are pink whereas
> they should be blue.

They are pink in "diagram before paste" so they are always pink in "diagram after paste". It is normal. The paste layout does not paste the style.
Comment 5 Cedric Brun CLA 2016-11-16 09:52:53 EST
(In reply to Laurent Redor from comment #4)
> (In reply to Cedric Brun from comment #0)
> > and even worst their colors are wrong and are pink whereas
> > they should be blue.
> 
> They are pink in "diagram before paste" so they are always pink in "diagram
> after paste". It is normal. The paste layout does not paste the style.

You are right (though I have no clue why...) that might be a separate issue, ignore this comment please.
Comment 6 Cedric Brun CLA 2016-11-16 10:01:38 EST
(In reply to Cedric Brun from comment #5)
> (In reply to Laurent Redor from comment #4)
> > (In reply to Cedric Brun from comment #0)
> > > and even worst their colors are wrong and are pink whereas
> > > they should be blue.
> > 
> > They are pink in "diagram before paste" so they are always pink in "diagram
> > after paste". It is normal. The paste layout does not paste the style.
> 
> You are right (though I have no clue why...) that might be a separate issue,
> ignore this comment please.

Correction of the correction: it is probably related, I guess the edges are not matched correctly for some reasons, when doing the same scenario but at the end: 
- create a new diagram for the family
- right click, Edit, Paste Style
=> the edge colors are unexpectedly changed from blue (the father relationship) to pink on the Elias->Paul relationship. The styles goes into "customized mode" though it was not done so in the original diagram .
=> the expectation was that this edge would stay blue in the first place.
Comment 7 Pierre Guilet CLA 2016-11-17 11:14:31 EST
The color problem as well as the layout problem comes from the same source that is the construction of the key in org.eclipse.sirius.diagram.ui.tools.internal.format.semantic.AbstractSemanticFormatDataKey.

This key is used in the map containing all format for all edges in org.eclipse.sirius.diagram.ui.tools.internal.format.semantic.SiriusFormatDataManagerForSemanticElements.edgeFormatDataMap

For all edges the key must be unique but this currently not the case. 
Indeed, the key is constructed with the following :   this.semanticElementURIFragment = EcoreUtil.getURI(semanticElement).fragment();

So if we copy format of a node with two edges, we will keep the format of the second one only.

We must modify the key construction to be unique.
We cannot be based on the source and target because we can have multiple edges with the same source and target.
Comment 8 Pierre Guilet CLA 2016-11-17 11:29:24 EST
The key must be constructed with the mapping id, the source and target fragment instead of the target only.
Comment 9 Laurent Redor CLA 2016-11-18 05:28:35 EST
(In reply to Pierre Guilet from comment #8)
> The key must be constructed with the mapping id, the source and target
> fragment instead of the target only.

No, it is not possible. The copy/paste must be allowed between two diagrams with the same semantic elements representing by different mapping. So the mapping id can not be used as part of the key. Another solution must be chosen.
Comment 10 Cedric Brun CLA 2016-11-18 05:47:00 EST
You might want to add the mapping, source/target information as a "hint" which can be used to pick the most specific one  when two possibles set of style/format/layout are candidates to a given paste.

In my case the mapping would have been enough to get the expected result. I think this would work quite well for a lot of cases.
Comment 11 Pierre Guilet CLA 2016-11-18 09:09:43 EST
(In reply to Pierre Guilet from comment #7)
> The color problem as well as the layout problem comes from the same source
> that is the construction of the key in
> org.eclipse.sirius.diagram.ui.tools.internal.format.semantic.
> AbstractSemanticFormatDataKey.
> 
> This key is used in the map containing all format for all edges in
> org.eclipse.sirius.diagram.ui.tools.internal.format.semantic.
> SiriusFormatDataManagerForSemanticElements.edgeFormatDataMap
> 
> For all edges the key must be unique but this currently not the case. 
> Indeed, the key is constructed with the following :  
> this.semanticElementURIFragment =
> EcoreUtil.getURI(semanticElement).fragment();
> 
> So if we copy format of a node with two edges, we will keep the format of
> the second one only.
> 
> We must modify the key construction to be unique.
> We cannot be based on the source and target because we can have multiple
> edges with the same source and target.

This "limitation" is known for node and more easily understandable. The key used to retrieve layout information is the semantic element. If a semantic element is represented several times in a diagram, only one location/size is stored for all the "graphical representations" of this semantic element (as the key is the same). For "relation based" edge, the semantic element considered as key is the semantic element of the source of the edge. So the problem is exactly the same if there are several "relation based" edges starting from a same element.
As explained in previous comment, we can not use the mapping as part of the key (to allow copy/paste bewteen diagram of different kind). But we can even so consider it to avoid this limitation in most common cases.
Here is a description of the choosen approach:
	- If we have only one value stored during the format copy, then we keep the current way to distinguish it.
	- If we have more than one value to store for the same key during the format copy, we will keep track of additional information to distinguish the different values (and facilite reconciliation during paste). The additional information is the mapping.
While pasting format (or style or layout), when trying to retrieve the format information for a representation of a semantic element, we try to find the best match format among those with the following rules:
	-First the key is used to retreive the associated format information.
		- If we find only one format, we apply this format
		- If many formats exist for this key, we use additional information (mapping) to retreive the correct format. If the mapping does not allow to distinguish the correct format, we use the first one (as today).
Comment 12 Eclipse Genie CLA 2016-11-22 09:17:02 EST
New Gerrit change created: https://git.eclipse.org/r/85496
Comment 13 Eclipse Genie CLA 2016-11-23 10:10:27 EST
New Gerrit change created: https://git.eclipse.org/r/85598
Comment 16 Florian Barbin CLA 2016-12-01 08:52:46 EST
Verified on Sirius 4.1.2.201612011000.
Comment 17 Pierre-Charles David CLA 2016-12-08 11:12:54 EST
Available in Sirius 4.1.2 (see https://wiki.eclipse.org/Sirius/4.1.2 for details).