Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Newbie - Inherting a ShapeNode (Read 1628 times)
Darin
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 2
Joined: Feb 27th, 2009
Newbie - Inherting a ShapeNode
Feb 27th, 2009 at 7:52pm
Print Post  
Based on my limited knowledge, the ShapeNode looks like the right class for me to inherit so I can add various additional properties like TaskName, TaskRequired, TaskStatus, TaskSuccessorConditions, etc. for use in an application.

When I create a simple vb.net class (TaskNode) that inherits the ShapeNode using VS2005, I see warnings indicating the ShapeNode is CLS-Compliant. This doesn't bother me but are there any problems down the line?

Also, as a test, I am trying to modify the FlowCharter sample to use my new TaskNode class. At first I thought I would just create TaskNodes instead of ShapeNodes but then noticed that there is a Factory method used to create the nodes and return is ShapeNode.

So I left the sample code in tact where it relates to the factory returning ShapeNode and thought I would just cast the ShapeNode as a TaskNode but I recieve an "System.InvalidCastException" error. (see the last code line below)

Any ideas on what I need to do to make my class work in this way or is there any other way to add my own properties to a ShapeNode and use it with full functionality?

====================================
Dim b As FlowCharter.ShapeNode = _doc.Factory.CreateShapeNode(pt.X, pt.Y, 20, 20)
b.Shape = _nodes(sdi.Index).Template
b.AnchorPattern = ap
b.HandlesStyle = HandlesStyle.DashFrame

Dim t As TaskNode
t = CType(b, FlowCharter.ShapeNode)
====================================

Thanks for your help.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Newbie - Inherting a ShapeNode
Reply #1 - Feb 27th, 2009 at 8:32pm
Print Post  
Hi,

The Factory methods are just a shortcut for creating nodes from the standard types. You can add nodes from any type to the diagram by adding them to Diagram.Nodes:

dim tn as new TaskNode(...)
diagram.Nodes.Add(tn)

We'll check the CLS warnings next week.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Darin
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 2
Joined: Feb 27th, 2009
Re: Newbie - Inherting a ShapeNode
Reply #2 - Mar 2nd, 2009 at 12:25am
Print Post  
That certainly makes sense. Not sure why I didn't look for that basic method first but I guess the example just threw me off. Anyway, works great, thanks for the help.

On another note, now that everything works as I wanted with my new class that inherits the shapenode I tried to use the savetofile/loadfromfile methods.

While it appears to save and load everything OK, it looks like it saves and/or loads the shapenode instead of my new TaskNode. I end up having to try to cast again which is obviously not working as I indicated in the last message.

Do you have any suggestions for saving the diagram and making it save and load my extension of the ShapeNode class? I can do this from scratch but I am sure someone has had to do this before.

Thanks again for your help.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Newbie - Inherting a ShapeNode
Reply #3 - Mar 2nd, 2009 at 8:41am
Print Post  
You must override the SaveTo and LoadFrom methods for binary serialization, or SaveToXml and LoadFromXml for XML serialization. You should also use the Diagram.RegisterItemClass to designate some string as an id for your class. Serialization of custom types is shown in the IconNodes sample project.

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