Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Adding my own nodes to diagram,ItemAdded not fired (Read 4337 times)
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Adding my own nodes to diagram,ItemAdded not fired
Apr 12th, 2009 at 12:22pm
Print Post  
Hi.
After reading many threads in this forum Im confused because of my situation.

Descriptionof my situation:

1) I have:
- my own class ClsMMTableNode inherited from TableNode
- registered this class via RegisterItemClass method

2) In diagram I would like to work with objects of ClsMMTableNode class instead of TableNode

3) Programmatically its not problem

4) But when user is drawing TableNode I need to find right place where TableNode is created!

Since ItemAdded event is not fired when node is drawn by user its not possible to handle this situation.

Instead of that I handle NodeCreated event. There is my object created, original node is removed from diagram and my new object is added to diagram.

Code
Select All
Private Sub fcDiagram_NodeCreated(ByVal sender As Object, ByVal e As MindFusion.Diagramming.NodeEventArgs) Handles fcDiagram.NodeCreated


  Select Case e.Node.GetType().ToString


Case "MindFusion.Diagramming.TableNode"


    Dim LoMMTableNode As ClsMMTableNode = New ClsMMTableNode(e.Node)


    Me.fcDiagram.Nodes.Remove(e.Node)


    Me.fcDiagram.Nodes.Add(LoMMTableNode)

  End Select
    End Sub
 



Why ItemAdded event is not fired when node is drawn by user?

Where is the right place for handling "new node creation" situation? Before creating of node or after adding node to diagram?

Or is there any sophisticated way how to work with my own object in diagram?


Thx.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Adding my own nodes to diagram,ItemAdded not f
Reply #1 - Apr 13th, 2009 at 8:10am
Print Post  
Quote:
Why ItemAdded event is not fired when node is drawn by user?


That's not possible. Please e-mail us a small project that shows adding a custom node without raising this event.

Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: Adding my own nodes to diagram,ItemAdded not f
Reply #2 - Apr 13th, 2009 at 9:33am
Print Post  
Hi.

After checking situtuation on new project I found out that ItemAdded event is not raised when

DiagramView.Behavior = MindFusion.Diagramming.Behavior.DrawShapes

or DrawTables or DrawContainers or Draw...

Theres a problem Smiley Thats why Im handling NodeCreated event.

I sent you a simple project on support@mindfusion.eu.

Any help?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Adding my own nodes to diagram,ItemAdded not f
Reply #3 - Apr 13th, 2009 at 10:07am
Print Post  
Seems you forgot to attach the project. The user cannot draw items from your custom type when Behavior is set to any of the values you list anyway. You will have to set CustomNodeType to typeof(your class) and set Behavior = Custom; the DrawTables behavior will let the user draw only nodes from the standard TableNode type.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Adding my own nodes to diagram,ItemAdded not f
Reply #4 - Apr 13th, 2009 at 11:39am
Print Post  
ItemAdded is raised only if you add items programmatically, e.g.:

Diagram1.Items.Add(New LoMMTableNode)

The documentation is incorrectly stating that it's raised for interactively added ones.

Anyway, you can let the user draw items from your type like this:

Me.DiagramView1.CustomNodeType = gettype (LoMMTableNode)
Me.DiagramView1.Behavior = Behavior.Custom

instead of replacing TableNodes with your custom nodes in the Created event handler.
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: Adding my own nodes to diagram,ItemAdded not f
Reply #5 - Apr 13th, 2009 at 1:20pm
Print Post  
Thx Stoyo!

In this case it prevents me from draging selection rectangle.

What I want to do is have 2 modes:

1.
- moving all nodes
- creating my own links (MMlinkNode) from nodes (because HandlesStyle property of TableNodes is set to HandlesStyle.EasyMove)
- selection rectangle

2.
- moving all nodes
- creating my own links (MMlinkNode) from nodes (because HandlesStyle property of TableNodes is set to HandlesStyle.EasyMove)
- TableNode creating (MMTableNode)

Do I nedd to use DiagramView.CustomBehavior and my own object? If yes, can You pls write here a sample code.

Thx

...MUDO...
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: Adding my own nodes to diagram,ItemAdded not f
Reply #6 - Apr 13th, 2009 at 2:24pm
Print Post  
Hi again.

When I can use CustomLinkType property?

How to combine CustomLinkType, CustomNodeType and Behavior if I want to draw my own shapes and my own links?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Adding my own nodes to diagram,ItemAdded not f
Reply #7 - Apr 13th, 2009 at 4:32pm
Print Post  
For the 1st mode you will have to use a custom class derived from BehaviorBase. Override StartDraw, and if you detect there is a node under the mouse cursor, return this:

DiagramLink link = new MMlinkNode(...);
link.Origin = node;
return new InteractionState(link, -1, Action.Create);

otherwise return this:

return new InteractionState(Diagram.Selection, -1, Action.Create);

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: Adding my own nodes to diagram,ItemAdded not f
Reply #8 - Apr 26th, 2009 at 11:45am
Print Post  
Hi!

My current situation is also final, but two troubles are still there.

I have my own BehaviorBase class.

1) How can I set InteractionState to "nothing"? All I want to do is set a behavior when user can drag selection rectangle. It looks very simply but what should be assigned to InteractionState object in StartDraw sub to do this?

2) I want to move with controlpoint of link. How can I get to links controlpoint which is actually clicked? Im using this code to recognize item under cursor

Dim LoItem As DiagramItem = Diagram.GetItemAt(IoPointF, False)

What I have to do to make controlpoints moving real? How to recognize , what to assign to InteractionState object?

Thx.

...MUDO...
« Last Edit: Apr 26th, 2009 at 7:23pm by MUDO »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Adding my own nodes to diagram,ItemAdded not f
Reply #9 - Apr 27th, 2009 at 8:27am
Print Post  
Hi,

1. Return new InteractionState(Diagram.Selection, -1, Action.Create) from StartDraw.

2. You could use the DiagramItem.HitTestHandle method to find which point is under the mouse cursor.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: Adding my own nodes to diagram,ItemAdded not f
Reply #10 - Apr 27th, 2009 at 11:30am
Print Post  
Hi!

Thats what I exactly want Smiley Thx so much.

...MUDO...
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint