|
|
|
|
Re: Support for using SVG figures/shapes (GSoC 2016?) [message #1726595 is a reply to message #1725975] |
Mon, 14 March 2016 23:22 |
Erwin De Ley Messages: 52 Registered: August 2013 |
Member |
|
|
I've got something working, from the info described in the other post, example in sketch tool with SketchGraphicsAlgorithmRendererFactory etc and GMF SVGFigure.
In the process I discovered one thing that is still somewhat annoying. When the AddFeature does something like :
GraphicsAlgorithm platformGA = Graphiti.getGaCreateService().createPlatformGraphicsAlgorithm(invisibleRectangle, "myID");
gaService.setLocationAndSize(extFigure, SHAPE_X_OFFSET, 0, width, height);
I would like to be able to derive width&height matching the SVG that was read in the platformGA's shape.
The above eventually ends up invoking my factory and custom figure rendering in fillShape() :
public class SvgModelElementShape extends RectangleFigure implements IGraphicsAlgorithmRenderer {
private String svgURI;
SvgModelElementShape(String svgURI) {
this.svgURI = svgURI;
}
@Override
protected void fillShape(Graphics graphics) {
SVGFigure figure = new SVGFigure();
figure.setURI(svgURI);
figure.setBounds(this.getBounds());
figure.paint(graphics);
}
// ...
Now I would like to be able to adjust the effective dimensions used by the AddFeature, using the size (or at least the aspect ratio) of the parsed SVG.
But I could not find a way for the AddFeature to access my SvgModelElementShape from the created platformGA above?
I would like to encapsulate the details of parsing SVG and determining its characteristics in this special shape implementation. I also need to add other external figure/shape/icon definition approaches. And so my AddFeature should not be aware of the underlying technologies and would ideally be able to invoke layout/sizing info from such special shapes via a simple common interface, i.e. have access to the shape instances involved to inspect them.
Is there a way to achieve that?
thanks
erwin
[Updated on: Mon, 14 March 2016 23:26] Report message to a moderator
|
|
|
|
Re: Support for using SVG figures/shapes (GSoC 2016?) [message #1727373 is a reply to message #1727335] |
Tue, 22 March 2016 14:07 |
Erwin De Ley Messages: 52 Registered: August 2013 |
Member |
|
|
Michael,
In the meantime I've got something working, although it's not as clean as it could be, I guess...
I'm writing something about the approach in more detail, but the main thing is that the custom shape (impl of IGraphicsAlgorithmRenderer) resizes its parent GA during the rendering, based on the size info in the icon/figure definition. It uses the available resize feature, that in turn invokes the layout feature. Getting this working did involve adding some properties on the GA for render state management, which is not ideal.
The most important issue is that I noticed that the custom shapes' fillShape() method is invoked many many times. It seems everytime something somewhere in the diagram is selected/done, not only when a change has effectively been made that might impact that particular shape. Depending on the actual possibilities of the underlying graphics this induces a non-negligable performance penalty.
I haven't been able to identify ways yet to ensure that the fillShape is only invoked when there is a real trigger for which the shape should effectively be redrawn.
So for the moment it works, but I see that zooming/... of diagrams with several/many custom shapes is becoming slow.
Second thing is that I'm using (a simplified extracted version of) GMF SVGFigure. This converts the SVG in an image, so the scaling is lost from then on.
The other mechanism that I have integrated is using Ptolemy II's custom icon definitions. These are not in SVG but in an own XML format that has more limited features and was easy to map to straight draw2d. So this has better results than what SVGFigure gives me. Luckily I see that most Ptolemy components that I need to integrate use that second method for their icons/shapes/figures!
If you could point me to possibilities to block unneeded fillShape() invocations, that would help me most for now!
cheers
erwin
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05166 seconds