Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Loading Custom Shape from XML File (Read 4288 times)
Viev
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 15
Location: Australia
Joined: Jan 3rd, 2015
Loading Custom Shape from XML File
Feb 2nd, 2017 at 12:15am
Print Post  
Hi there,

If I save a diagram to XML (using the SaveToXML method) and a Node has a custom shape, only the "Id" of the Shape is stored in the respective [Node] element of the XML, not the Shape definition/template.

Quite obviously, when I then go to load the XML document (using the LoadFromXML method) I get the error "Failed to open document!"....because the loader can't match the "Id" of the Node to a Shape definition/template.

Let's say that the "Id" of my node is "ShapeId123"....my question is

"How can I make the loader match that Node Id to a respective Shape definition/template within the software loading the XML document?".

Please note...I have no problem saving and retrieving the Shape definition using the "SaveTo" and "FromXMLElement" methods....I just don't know how to link the loading of an XML file (with only "Ids" for Nodes) to a Shape definition loaded from XML (FromXMLElement).

Any assistance most welcome.
Thanking you in advance,
Victor
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Loading Custom Shape from XML File
Reply #1 - Feb 2nd, 2017 at 9:10am
Print Post  
Hi,

The control expects all shapes to be defined and registered by id at startup time, so when loading a file it can find the shape by id. Its versions for some other platforms raise a ShapeNotDefined event when it cannot find shape definition for id - we could implement it in Windows Forms too if you prefer to load custom shape definitions on demand instead of pre-defining them all.

Another possibility is to use the SaveToXml(XmlDocument) method, and append your own <Shapes> element containing shape definitions. Then when loading files you could first parse and register the shapes and the call LoadFromXml(XmlDocument).

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Loading Custom Shape from XML File
Reply #2 - Feb 2nd, 2017 at 1:21pm
Print Post  
This build adds a ShapeNotDefined event you could handle as below -
https://mindfusion.eu/_beta/fcnet_shpevt.zip

Code
Select All
diagram.ShapeNotDefined += (s, a) =>
{
	if (a.UnknownId == "custom")
	{
		a.Shape = new Shape(
			Shapes.Decision.Outline, FillMode.Winding, "custom");
	}
};
diagram.LoadFromXml("test.xml"); 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Viev
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 15
Location: Australia
Joined: Jan 3rd, 2015
Re: Loading Custom Shape from XML File
Reply #3 - Feb 3rd, 2017 at 1:10am
Print Post  
Hi Slavcho,

Thank you for your reply. That helps understand "why". I just need information as to "how"....

>> The control expects all shapes to be defined and registered by id at startup time, so when loading a file it can find the shape by id.

How do I "define and register by id" the shape/s at startup time?....that's the bit I'm missing.

I know how to define a shape...but I don't know how to "register by id" the shape so that it is registered with the control ("at startup time").

That's the missing link for me.

Any information most welcome.

kind regards,
Victor

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Loading Custom Shape from XML File
Reply #4 - Feb 3rd, 2017 at 6:22am
Print Post  
Hi,

Calling constructors with Id argument is enough; pre-loading a shape library file where shapes have associated identifiers should work too.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Viev
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 15
Location: Australia
Joined: Jan 3rd, 2015
Re: Loading Custom Shape from XML File
Reply #5 - Feb 5th, 2017 at 11:48pm
Print Post  
Hi Slavcho,

>> pre-loading a shape library file where shapes have associated identifiers should work too.

That worked.

Anybody else reading this thread can also look at the following thread for more information....

http://mindfusion.eu/Forum/YaBB.pl?num=1184853723/10

kind regards,
Victor
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint