Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic drag-drop custom ShapeNode Type instance, and Customized link Type instance ? (Read 2331 times)
GoldyWang
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 34
Joined: May 7th, 2012
drag-drop custom ShapeNode Type instance, and Customized link Type instance ?
May 20th, 2012 at 9:19am
Print Post  
I want to drag-drop custom ShapeNode Type instance, and link nodes with Customized Link Type instance.

I read the demo project 'FlowCharter.csproj'. it show us drag-drop.

In demo code, create Node when reponse the diagramView_DragDrop event:

ShapeNode b = diagram.Factory.CreateShapeNode(pt, new SizeF(20, 20));

I know i can intercept here, write own CreateNode logic such as:

TMyShapeNode node = new TMyShapeNode(Diagram); //Create strong-typed ShapeNode
Diagram.Nodes.Add(node);

When create links in demo, it seems using the default behavior of the diagram view?
diagramView.Behavior = Behavior.DrawLinks;

My Qustion is: how can I intercept the default drawing-link, and create my own custom Link instance?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: drag-drop custom ShapeNode Type instance, and Customized link Type instance ?
Reply #1 - May 21st, 2012 at 8:11am
Print Post  
Hi,

1. Derive a new class from DrawLinksBehavior.
2. Override the CreateLink method.
3. Return an instance of your custom link class.
4. Set DiagramView.Behavior = Custom.
5. Assign the custom Behavior object to DiagramView.CustomBehavior.

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


I Love MindFusion!

Posts: 34
Joined: May 7th, 2012
Re: drag-drop custom ShapeNode Type instance, and Customized link Type instance ?
Reply #2 - May 22nd, 2012 at 3:12pm
Print Post  
Hi..

I try it in code:

        diagramView.Behavior = Behavior.Custom;
       diagramView.CustomNodeType = typeof(TPlace);  // Custom Node Type
       node = diagram.Factory.CreateShapeNode(pt, new SizeF(20, 20)); 
 
  Create node but not the TPlace Type, just ShapeNode Type
  Is there something I should do more?

  I again try:
                        node = new TPlace(diagram);
                        node.Text = "p";

                        diagram.Nodes.Add(node);
                        RectangleF bounds = node.GetBounds();
                        bounds.Location = pt;
                        node.SetBounds(bounds, false, false);

   it is OK, and create custom TPlace Typed instance on view
   is there something different from the 'diagram.Factory.CreateShapeNode()' ?
  is there more tricks be done in the factory function?



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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: drag-drop custom ShapeNode Type instance, and Customized link Type instance ?
Reply #3 - May 23rd, 2012 at 7:24am
Print Post  
These lines of code only specify that when the user draws with the mouse there should be a TPlace node created:

diagramView.Behavior = Behavior.Custom;
diagramView.CustomNodeType = typeof(TPlace);  // Custom Node Type

The Factory methods only create objects of the built-in types. The following always creates a ShapeNode instance, not the derived class you assigned to DiagramView.CustomNodeType:

node = diagram.Factory.CreateShapeNode(pt, new SizeF(20, 20)); 

As you found out you can add a custom node from code by instantiating and adding it to the Diagram.Nodes collection:

node = new TPlace(diagram);
diagram.Nodes.Add(node);

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