Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to save/load custom shapes from XML (Read 2239 times)
danilom
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Location: Italy
Joined: Feb 23rd, 2012
How to save/load custom shapes from XML
Apr 17th, 2012 at 10:44am
Print Post  
Hi Stoyan,
In my diagram I have shape nodes with custom shape.
The shape is created dinamically during node creation based on some user parameters.
An example of these shapes is the following:

Shape = new Shape(new ElementTemplate[]
                                    {
                                        new LineTemplate(0, 100, 100, 100),
                                        new LineTemplate(100, 100, 100, 0),
                                        new LineTemplate(100, 0, 100 - thickness/width*100, 0),
                                        new LineTemplate(100 - thickness/width*100, 0, 100 - thickness/width*100, 100 - thickness/height*100),
                                        new LineTemplate(100 - thickness/width*100, 100 - thickness/height*100, thickness/width*100, 100 - thickness/height*100),
                                        new LineTemplate(thickness/width*100, 100 - thickness/height*100, thickness/width*100, 0),
                                        new LineTemplate(thickness/width*100, 0, 0, 0),
                                        new LineTemplate(0, 0, 0, 100)
                                    },
                                FillRule.EvenOdd);

When I save to XML a diagram containing these nodes, the node shape is not saved (and consequently is not loaded in the loadFromXML method).
Is there a way to save custom shapes?

Best Regards,

Danilo
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to save/load custom shapes from XML
Reply #1 - Apr 17th, 2012 at 1:01pm
Print Post  
Hi Danilo,

At this time shapes are saved only by their Id, and any shapes referenced by Id when loading a file must be already defined.

One thing you could do is to assign Ids to the dynamically created shapes, add them to a ShapeLibrary, and use its SaveToXml method to save the shape definitions in a separate file. Then before loading the diagram file, you can call ShapeLibrary.LoadFrom to preload the shapes.

Since the Shape class already has SaveToXml and LoadFromXml methods (used for creating and loading shape libraries), another option is to handle SerializeTag/DeserializeTag events and serialize the shape from there. Anyway with these methods it should be easy to implement built-in support for this in the ShapeNode class - our developer will try to do that in the next few days.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to save/load custom shapes from XML
Reply #2 - Apr 24th, 2012 at 8:07am
Print Post  
Hi Danilo,

The version below will save the shape definitions in the diagram's XML file for shapes without an Id. If you specify an Id when defining a shape, only the Id is saved as in the old version, and the control will rely that such shapes already exist when loading a diagram file.

https://mindfusion.eu/_beta/wpfdiag282.zip

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint