Support for using SVG figures/shapes (GSoC 2016?) [message #1725558] |
Fri, 04 March 2016 11:47  |
Eclipse User |
|
|
|
This has popped up several times in the past already, but without a resolution as far as I know:
Would it be feasible to add support in Graphiti for including SVG-defined shapes (I guess it would be via a specialized GraphicalAlgorithm)?
For Triquetrum, we're building a Graphiti-based editor for Ptolemy II workflows.
Ptolemy has a large library of existing model components, and lots of them have existing "icon" definitions in SVG, often with lots of nice details in them. It would be almost unfeasible to have to redefine all of those using the existing Graphiti graphical-algorithm-approach.
On the other hand, having a generic SVG-parser algorithm or something would allow us to reuse the existing SVG. And it would allow mixing SVG with the "traditionally"-defined shapes in one diagram.
Is there interest in this from other Graphiti users? Can someone evaluate if this is technically feasible, e.g. to build something that translates SVG in draw2d or so?
As eclipse is participating in Google Summer of Code, could this be a candidate proposal there? Or would it be too complex for that?
If that would be feasible, I would be a candidate mentor (although I need to check in more detail what this really implies )
thanks
erwin
|
|
|
Re: Support for using SVG figures/shapes (GSoC 2016?) [message #1725891 is a reply to message #1725558] |
Tue, 08 March 2016 10:14   |
Eclipse User |
|
|
|
Erwin,
have you seen the post https://www.eclipse.org/forums/index.php/m/650289/?srch=svg#msg_650289 ? There Tim describes an idea how this could be implemented. I have never tried it and at least in that post nobody reported success.
Your idea of transforming SVG to Draw2D objects appears straight-forward, but I'm afraid that will result in much detail work to be done to support all cases (not sure if that is needed in your case, but for framework functionality it definitely would be required). I would rather rate it too hard for a Google Summer of Code proposal. At least you will need somebody with deep knowledge in both SVG and Draw2D.
Not sure if there is demand for this from others, in case somebody is interested please comment here.
Michael
|
|
|
|
|
Re: Support for using SVG figures/shapes (GSoC 2016?) [message #1726595 is a reply to message #1725975] |
Mon, 14 March 2016 23:22   |
Eclipse User |
|
|
|
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] by Moderator Report message to a moderator
|
|
|
Re: Support for using SVG figures/shapes (GSoC 2016?) [message #1727335 is a reply to message #1726595] |
Tue, 22 March 2016 08:56   |
Eclipse User |
|
|
|
Erwin,
hm, this sounds a bit like Graphiti should provide means to hook in custom shapes. There is an old open enhancement request for this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=352117.
It was actually requested by one of the internal SAP tools, but did not get that much focus. Since this is a large thing to build and given my very limited time I can spent on Graphiti I did not even think about what exactly that would require.
Not sure if it was not easier to move the SVG-handling logic into a special AddSvgModelElementFeature that could do the mappings (maybe based on a map stored at editor level - Graphiti does something similar for its shapes).
Michael
|
|
|
Re: Support for using SVG figures/shapes (GSoC 2016?) [message #1727373 is a reply to message #1727335] |
Tue, 22 March 2016 14:07   |
Eclipse User |
|
|
|
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.03854 seconds