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

Bug 320942

Summary: DiagramImageUtils should not modify Rectangle received by getExpandedBounds
Product: [Modeling] GMF-Runtime Reporter: Johannes Michler <orgler>
Component: GeneralAssignee: Alex Boyko <aboyko>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: aboyko, ahunter.eclipse, orgler
Version: unspecifiedKeywords: contributed
Target Milestone: 1.4.1   
Hardware: PC   
OS: Windows 7   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=319191
Whiteboard:
Attachments:
Description Flags
Patch according to fix 1 none

Description Johannes Michler CLA 2010-07-26 14:07:21 EDT
Build Identifier: 20100617-1415

In
org.eclipse.gmf.runtime.diagram.ui.render.util.DiagramImageUtils.calculateImageRectangle(List<IGraphicalEditPart>,
double, Dimension) there is the following code:

if (figure instanceof IExpandableFigure)
    bounds = ((IExpandableFigure) figure).getExtendedBounds();
else
    bounds = figure.getBounds().getCopy();
translateTo(bounds, figure, printableLayer);

For figure beeing a BorderedNodeFigure this goes through the first branch to
get the bounds. After getting the bounds, it translates these bounds. During
this method, the Rectangle gets modified (especially if the Figure is in a compartment)

In the next call to the getClip(IFigure)-Method provided at https://bugs.eclipse.org/bugs/show_bug.cgi?id=319191 this wrong
rectangle is returned, resulting in an wrongly clipped and therefore invisible figure.

I think there are a few ways to fix this:
1) modify calculateImageRectange to bounds = ((IExpandableFigure)figure).getExtendedBounds().getCopy();
2) Always return a copy in the getExtendedBounds()-Method of BorderedNodeFigure

I don't know what is the proposed semantic of the getExtendedBound()-Method:
should it return a modifiable Rectangle or not. Depending on this, Fix 1 or 2
should be prefered. The getBounds()-Method for IFigure specifies that the rectangle can be
passed by reference and that callers may not modify this rectangle. The
getExtendedBound() Method lacks such a comment. So I propose adding one and to
modify calculateImageRectangle (see my Patch according to fix-1)

For our rcp-editor, it happens when calling copy on a element in a compartment
and afterwards clicking on the compartment. But I think this problem will
always occur when calling calculateImageRectange.

Reproducible: Always

Steps to Reproduce:
This problem always happens when adding a BorderedNodeFigure to a compartment and afterwards calling the DiagramImageUtils.calculateImageRectangle-Method. This Method is called e.g. when saving an image of the model or using copy-paste.
Comment 1 Johannes Michler CLA 2010-07-26 14:09:44 EDT
Created attachment 175252 [details]
Patch according to fix 1

Of cause we should check if there are other methods using getExtendedBounds() and afterwards modifying the returned Rectangle (I did a quick check and it seems the other methods do not modify the rectangle at least for all plugins available in my local eclipse-installation). 

Furthermore the Javadoc-Comment could somewhat more exactly describe the method-functionality.
Comment 2 Alex Boyko CLA 2010-07-26 14:26:25 EDT
Anthony, I'm going to deliver this fix and update the java-doc for IExpandableFigure#getExtendedBounds(). It used to be internal and now public, so a java-doc comment would be useful for clients.
Comment 3 Alex Boyko CLA 2010-07-29 13:12:30 EDT
Delivered the contributed patch + Java-doc for IExpandableFigure#getExtendedBounds() for 2.3.1 and 2.4 (maintenance 1.4 and HEAD)