Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Is it possible to create a myBox class? (Read 6429 times)
Erison Liang
Guest


Is it possible to create a myBox class?
Nov 4th, 2005 at 11:28am
Print Post  
Hi,

Can I create myBox class that inherit from Box class? If yes, how to do it?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Is it possible to create a myBox class?
Reply #1 - Nov 4th, 2005 at 12:33pm
Print Post  
It is possible, but I believe you will be able to create myBox objects only programmatically. I.e. your users won't be able to create myBoxes by drawing with the mouse. Now in FlowChart.NET version 4 it is possible to define custom behaviors that will let you allow drawing custom node object too.

And if you just need to attach additional data to boxes, it is easier to use the Tag property for that. Create a class to hold all additional data you need and assign its instances to Box.Tag. The tags will be saved in diagram files if your data class is serializable.
  
Back to top
 
IP Logged
 
Erison Liang
Guest


Re: Is it possible to create a myBox class?
Reply #2 - Nov 7th, 2005 at 8:43am
Print Post  
You are right. I am planning to add myBox programming. I've try to define it. But it seems that I can not get it back when I deserialize it. Could you please help?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Is it possible to create a myBox class?
Reply #3 - Nov 7th, 2005 at 11:00am
Print Post  
I don't know how well this would work, but you can override the following box methods to implement serialization:

public virtual int getClassId();
public virtual void saveTo(BinaryWriter writer, PersistContext ctx);
public virtual void loadFrom(BinaryReader reader, PersistContext ctx);

You must also override the Flowchart's

public IPersists createObj(int clsId)

method. The clsId identifier returned by your class getClassId will be passed to createObj when loading and you must return a new instance of your class then. For any other id, return the base.createObj implementation. FlowChart.NET uses the IDs from 0 to 100 at this time, so use some ID greater than 100 for your class.

Stoyan
  
Back to top
 
IP Logged
 
Erison Liang
Guest


Re: Is it possible to create a myBox class?
Reply #4 - Nov 8th, 2005 at 3:41am
Print Post  
Thanks for your useful information. It will be great if an example is provided. Smiley
  
Back to top
 
IP Logged
 
Erison Liang
Guest


Re: Is it possible to create a myBox class?
Reply #5 - Nov 8th, 2005 at 4:40am
Print Post  
Hi,

I can not override "public IPersists createObj(int clsId)". It is not a virtual method.  ???
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Is it possible to create a myBox class?
Reply #6 - Nov 8th, 2005 at 6:30am
Print Post  
Well here is some sample from FC.NET source code of the Box class:

public override int getClassId()
{
   return 3;
}

public override void saveTo(BinaryWriter writer, PersistContext ctx)
{
   base.saveTo(writer, ctx);

   writer.Write(Expanded);
   writer.Write(Expandable);
   writer.Write((long)enabledHandles);
   writer.Write((int)style);

   // etc
}

public override void loadFrom(BinaryReader reader, PersistContext ctx)
{
   base.loadFrom(reader, ctx);

   setExpanded(reader.ReadBoolean());
   setExpandable(reader.ReadBoolean());
   enabledHandles = (Handles)reader.ReadInt64();
   intStyle = reader.ReadInt32();

   // etc
}

And FlowChart.createObj(int clsId):

public IPersists createObj(int clsId)
{
   switch (clsId)
   {
   case 2:
     return new Arrow(this);
   case 3:
     return new Box(this);

   // etc
}
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Is it possible to create a myBox class?
Reply #7 - Nov 8th, 2005 at 6:33am
Print Post  
Ok, we'll make that method virtual in the today's build of the beta version.
  
Back to top
 
IP Logged
 
Erison Liang
Guest


Re: Is it possible to create a myBox class?
Reply #8 - Nov 8th, 2005 at 10:04am
Print Post  
Thanks to you. I'll try it.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Is it possible to create a myBox class?
Reply #9 - Nov 8th, 2005 at 12:19pm
Print Post  
The new build has just been uploaded:

https://mindfusion.org/_beta/FCNetDemo.zip
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint