Bug 266512 - [ImageSupport] GraphicsToGraphics2DAdapter doesn't implement draw, fill and clip methods for Path
Summary: [ImageSupport] GraphicsToGraphics2DAdapter doesn't implement draw, fill and c...
Status: RESOLVED FIXED
Alias: None
Product: GMF-Runtime
Classification: Modeling
Component: General (show other bugs)
Version: 2.2   Edit
Hardware: PC Windows XP
: P3 normal
Target Milestone: 2.2   Edit
Assignee: Alex Boyko CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-27 11:26 EST by Alex Boyko CLA
Modified: 2010-07-16 23:35 EDT (History)
4 users (show)

See Also:


Attachments
proposed patch (4.27 KB, patch)
2009-02-27 11:26 EST, Alex Boyko CLA
no flags Details | Diff
JUnit support for painting Path with Graphics2D (3.21 KB, patch)
2009-02-27 13:08 EST, Alex Boyko CLA
no flags Details | Diff
final patch (7.33 KB, patch)
2009-02-27 13:31 EST, Alex Boyko CLA
no flags Details | Diff
patch to fix #setFillRule(int) (5.80 KB, patch)
2009-03-04 19:43 EST, Alex Boyko CLA
no flags Details | Diff
JUnit support for Cylinder with gradient (3.65 KB, patch)
2009-03-05 02:00 EST, Alex Boyko CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Boyko CLA 2009-02-27 11:26:48 EST
Created attachment 127021 [details]
proposed patch

1. Create a geoshape diagram
2. Create a note on it
3. Save diagram as either JPEG or PNG, or SVG, or PDF.
4. Operation fails with exception from GraphicstoGraphics2DAdapter that #fillPath(Path) method is not implemented.

NoteFigure uses SWT Path to paint itself (gradient is supported for Path)

P.S. Alex Fitzpatrick was about to raise a bug on that.
Comment 1 Alex Boyko CLA 2009-02-27 13:08:18 EST
Created attachment 127028 [details]
JUnit support for painting Path with Graphics2D

JUnit addition that adds a note to the diagram beside the circuit. The diagram is exported to images of various formats.
Comment 2 Alex Boyko CLA 2009-02-27 13:31:16 EST
Created attachment 127031 [details]
final patch

Final patch for code review.
Cleaned up and merged with JUnit support.
Comment 3 Alex Fitzpatrick CLA 2009-02-27 14:19:06 EST
I verify that this patch fixes the failure in GMF that I observed.
Comment 4 Alex Boyko CLA 2009-02-27 14:28:57 EST
Marc, could you code review this patch please?
Comment 5 Marc Gobeil CLA 2009-02-27 15:06:50 EST
Just two things, otherwise looks good.

1. On the last line of drawPath(), path2D isn't used (compiler misses it because of the path2D.transform() call), so it's missing the transform.

2. I'd factor out these lines from fillPath and drawPath

	Path2D path2D = createPathAWT(path);
	AffineTransform transform = new AffineTransform();
	transform.translate(transX, transY);
	path2D.transform(transform);

  and roll them into createPathAWT(), making drawPath for example into just 3 lines:

  checkState();
  getGraphics2D().setPaint(getColor(swtGraphics.getForegroundColor()));
  getGraphics2D().draw(createPathAWT(path));
Comment 6 Alex Boyko CLA 2009-02-27 15:15:11 EST
Sounds good - I'll do that.
Comment 7 Alex Boyko CLA 2009-02-27 15:27:06 EST
Corrected as Marc suggested (Thanks, Marc!)
Committed the fix for 2.2
Comment 8 Alex Fitzpatrick CLA 2009-02-27 15:33:46 EST
Nice work... I guess that's another lunch I owe you.
Comment 9 Alex Boyko CLA 2009-03-04 15:02:41 EST
Need to use GeneralPath instead of Path2D.Float, because Path2D is introduced in Java 6.
Comment 10 Lidija Grahek CLA 2009-03-04 15:35:23 EST
Hi Alex, it also needs to implement setFillRule(), can be tested with GeoShapeCylinderFigure. It is also used when gradient is applied.

Comment 11 Alex Boyko CLA 2009-03-04 15:43:37 EST
Ok, will add that too. Thanks, Lidija.
Comment 12 Alex Boyko CLA 2009-03-04 16:11:47 EST
Regarding the setFillRule()... is that something obvious about Cylinder figure that I should notice when export it to image? Or perhaps gradient etc should be set on it to notice the problem? I just need to know what is the problem with the cylinder, so I can test the fix...
Comment 13 Lidija Grahek CLA 2009-03-04 16:45:07 EST
It is the same use case you described when raising this defect. Just add cylinder on a diagram. Or add any other geoshape or note and apply gradient. Then, do File->Save As Image, PNG.

Comment 14 Alex Boyko CLA 2009-03-04 19:43:20 EST
Created attachment 127587 [details]
patch to fix #setFillRule(int)

Proposed patch to implement #setFillRule(int)

1. Use GeneralPath supported in Java 5 instead of Java 6 Path2D.Float
2. Implementation of #setFillRule(int), #getFillRule() is essentially ported from SWTGraphics in draw2D. The fill rule cannot be set on Graphics2D, but instead it can be set on GeneralPath, so I set it from the applied state.
3. #setClip(Path) fixes... before I had no idea when this gets called, because with plain GMF examples gradient cannot be set.
4. Clean up for the creation of the AWT path. Can translate points during conversion.

Lidija, am I missing anything now? Anything else we're missing in GraphicstoGraphics2DAdapter? If everything looks in order, could you code review the patch please?
Yhanks in advance.
Comment 15 Alex Boyko CLA 2009-03-05 02:00:42 EST
Created attachment 127612 [details]
JUnit support for Cylinder with gradient

Added cylinder with gradient on the diagram that is used in image export JUnits
Comment 16 Anthony Hunter CLA 2009-03-06 11:43:22 EST
(In reply to comment #14)
> Lidija, am I missing anything now? Anything else we're missing in
> GraphicstoGraphics2DAdapter? If everything looks in order, could you code
> review the patch please?
> Yhanks in advance.

Alex, we are good to commit this now, since the existing code in CVS has build errors. 

Comment 17 Lidija Grahek CLA 2009-03-06 12:15:39 EST
I just looked at the patch, works well, don't think there is anything else.
Comment 18 Alex Boyko CLA 2009-03-06 13:26:53 EST
Committed the fix + JUnit for 2.2.
Anthony and Lidija hanks for the feedback on this one.
Comment 19 Eclipse Webmaster CLA 2010-07-16 23:35:39 EDT
[target cleanup] 2.2 M6 was the original target milestone for this
bug
Comment 20 Eclipse Webmaster CLA 2010-07-19 12:30:27 EDT
[GMF Restructure] Bug 319140 : product GMF and component Runtime Diagram was the original product and component for this bug