Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Support for using SVG figures/shapes (GSoC 2016?)
Support for using SVG figures/shapes (GSoC 2016?) [message #1725558] Fri, 04 March 2016 11:47 Go to next message
Erwin De Ley is currently offline Erwin De LeyFriend
Messages: 52
Registered: August 2013
Member
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 Wink )

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 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
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 #1725972 is a reply to message #1725891] Tue, 08 March 2016 17:48 Go to previous messageGo to next message
Krisztian Koncz is currently offline Krisztian KonczFriend
Messages: 31
Registered: September 2014
Location: Budapest
Member

I tried the idea about a year ago, and it worked, but nor remember the details. If I have some time in the near future, I will try to share some code example.
Re: Support for using SVG figures/shapes (GSoC 2016?) [message #1725975 is a reply to message #1725972] Tue, 08 March 2016 18:25 Go to previous messageGo to next message
Erwin De Ley is currently offline Erwin De LeyFriend
Messages: 52
Registered: August 2013
Member
Thank you Michael, I'll look into the GMF SVGFigure.
That seems like the best approach indeed.

Krisztian, if you do find sample code that would be helpful of course!

cheers
erwin
Re: Support for using SVG figures/shapes (GSoC 2016?) [message #1726595 is a reply to message #1725975] Mon, 14 March 2016 23:22 Go to previous messageGo to next message
Erwin De Ley is currently offline Erwin De LeyFriend
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 #1727335 is a reply to message #1726595] Tue, 22 March 2016 08:56 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
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 Go to previous messageGo to next message
Erwin De Ley is currently offline Erwin De LeyFriend
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


Re: Support for using SVG figures/shapes (GSoC 2016?) [message #1727543 is a reply to message #1727373] Wed, 23 March 2016 16:24 Go to previous messageGo to next message
Krisztian Koncz is currently offline Krisztian KonczFriend
Messages: 31
Registered: September 2014
Location: Budapest
Member

Erwin: sorry to miss the code example, I totally forgot it. But I see you did a great work Smile Nice article Smile
Re: Support for using SVG figures/shapes (GSoC 2016?) [message #1727550 is a reply to message #1727543] Wed, 23 March 2016 17:22 Go to previous messageGo to next message
Erwin De Ley is currently offline Erwin De LeyFriend
Messages: 52
Registered: August 2013
Member
Krisztian,

You beat me to it, I was just going to announce the article here Wink

if you could review it and let me know if it's more-or-less clear and useful, that would be great.

cheers
erwin
Re: Support for using SVG figures/shapes (GSoC 2016?) [message #1727587 is a reply to message #1727550] Thu, 24 March 2016 08:58 Go to previous messageGo to next message
Krisztian Koncz is currently offline Krisztian KonczFriend
Messages: 31
Registered: September 2014
Location: Budapest
Member

Of course Smile I have some idea about the "parent resize hack". What do you want? Just write it down here or make a contribution?
Re: Support for using SVG figures/shapes (GSoC 2016?) [message #1727612 is a reply to message #1727587] Thu, 24 March 2016 12:49 Go to previous message
Erwin De Ley is currently offline Erwin De LeyFriend
Messages: 52
Registered: August 2013
Member
A contribution would be great, I'll expect your pull request Wink !

(At least if you have some time to setup a Triquetrum workspace?
Info on this is at https://wiki.eclipse.org/Triquetrum/Building_From_Sources )

But of course, if that would not be possible, a short description/proposal here is perfect as well!

cheers
erwin
Previous Topic:Unable to change shape Background color
Next Topic:Undo / Redo not active when in Graphiti property view
Goto Forum:
  


Current Time: Tue Mar 19 02:46:18 GMT 2024

Powered by FUDForum. Page generated in 0.02930 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top