Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Dynamically change node type (Read 5170 times)
mjweyland
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Apr 2nd, 2007
Dynamically change node type
Aug 29th, 2007 at 11:19pm
Print Post  
Any suggestions on how one might go about dynamically changing the type of node on a diagramview?

I would like to use a flow chart to present information to a user in two different formats depending on the view they use to implement. 

View one would use ShapeNodes and Containers which would be related to each other using linkobjects.

View two would use TableNodes and containers which would mirror the relationships defined previously.

When user wanted view 1 they would see the shape nodes, when users wanted view 2 they would see the tablenodes.

I would like to implement this on the fly if at all possible, i.e. allow users to select a view from a pulldown. 

My initial thoughts for this were to:
  • Create a custom object which would inherit from diagram node.
  • It would store objects for a ShapeNode and for a TableNode.
  • It would have a method for changing the current presented node etc. and call the draw method.

however I need an IGraphics interface object and some RenderOptions and cannot seem to find where in the diagram or diagram view these are implemented or what object I can cast to this to be able to implement this.   

In addition after I create this object and add it to a flow chart it doesn't allow me to move the item etc. 

Related to this topic I would like to trap events on this newly created node.  So if a user were to click on a node which might raise a selected event that event could pass back information to a property grid. 

Any suggestions or ideas on this topic are greatly appreciated and if you need more information please let me know.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dynamically change node type
Reply #1 - Aug 30th, 2007 at 6:09am
Print Post  
This class seems to do the job:

Code
Select All
public class DynamicNode : DiagramNode
{
	public DynamicNode(Diagram diagram)
	{
		wrappedNode = new ShapeNode(diagram);
		wrappedNode.Bounds = new RectangleF(-1000, -1000, 1, 1);
	}

	public override void Draw(IGraphics graphics, RenderOptions options)
	{
		wrappedNode.Draw(graphics, options);
	}

	public override void DrawShadow(IGraphics graphics)
	{
		wrappedNode.DrawShadow(graphics);
	}

	protected override void OnUpdateBounds()
	{
		wrappedNode.Bounds = base.Bounds;
	}

	public new RectangleF Bounds
	{
		get { return wrappedNode.Bounds; }
		set { wrappedNode.Bounds = value; }
	}

	public void Toggle()
	{
		if (wrappedNode is ShapeNode)
			wrappedNode = new TableNode(Parent);
		else
			wrappedNode = new ShapeNode(Parent);

		wrappedNode.Bounds = base.Bounds;

		Parent.Invalidate(GetRepaintRect(false));
	}

	private DiagramNode wrappedNode;
}
 



You can use it like this:

Code
Select All
private void diagram_NodeDoubleClicked(object sender, MindFusion.Diagramming.NodeEventArgs e)
{
	DynamicNode node = e.Node as DynamicNode;
	if (node != null)
	{
		node.Toggle();
	}
}

private void Form1_Load(object sender, System.EventArgs e)
{
	diagramView.CustomNodeType = typeof(DynamicNode);
	diagramView.Behavior = Behavior.Custom;
}
 



Stoyan
  
Back to top
 
IP Logged
 
mjweyland
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Apr 2nd, 2007
Re: Dynamically change node type
Reply #2 - Aug 30th, 2007 at 12:33pm
Print Post  
Thanks.

This worked wonderfully.

Has there been any thought for future versions of the tool to allow for events to be explicitly handled by a node rather than a diagramview?  i.e. MouseOver, OnClick, OnMove, OnLink, OnUnLink etc.

Thanks.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dynamically change node type
Reply #3 - Aug 30th, 2007 at 3:02pm
Print Post  
There hasn't been any; though that should be very easy to implement, so we'll try to add such methods to version 5.0.1.

Stoyan
  
Back to top
 
IP Logged
 
mjweyland
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Apr 2nd, 2007
Re: Dynamically change node type
Reply #4 - Feb 11th, 2008 at 1:43pm
Print Post  
Has this functionality been implemented in versions 5.01 or 5.02?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dynamically change node type
Reply #5 - Feb 11th, 2008 at 2:10pm
Print Post  
There are OnClick and OnDoubleClick methods available now. We will add mouse-movement related ones after we move to a quadtree -based hit testing implementation.

Stoyan
  
Back to top
 
IP Logged
 
mjweyland
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Apr 2nd, 2007
Re: Dynamically change node type
Reply #6 - Feb 12th, 2008 at 1:47pm
Print Post  
What is your time frame expectation for this?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dynamically change node type
Reply #7 - Feb 12th, 2008 at 2:21pm
Print Post  
Well, the fast hit-testing was planned for version 5.0, but we postponed it for a later release, and haven't started work on it yet. We are releasing V5.0.3 in a couple of weeks, and will try to implement that for 5.0.4.

Stoyan
  
Back to top
 
IP Logged
 
mjweyland
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Apr 2nd, 2007
Re: Dynamically change node type
Reply #8 - Feb 22nd, 2008 at 9:24pm
Print Post  
I downloaded and installed 5.0.2 and am not seeing these events availabe on any node types( ShapeNode, DiagramNode etc.)  Where are these exposed?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dynamically change node type
Reply #9 - Feb 23rd, 2008 at 7:40am
Print Post  
They are virtual methods that you can override in your classes inherited from ShapeNode or DiagramNode. Additionally, these methods are protected - you won't see them in the Intellisense list, unless you are coding the inherited class.

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


I love YaBB 1G - SP1!

Posts: 37
Joined: Apr 2nd, 2007
Re: Dynamically change node type
Reply #10 - Feb 29th, 2008 at 12:23am
Print Post  
Thanks, I see them as methods available from the baseclass.  Any thoughts on how to expose these as events?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dynamically change node type
Reply #11 - Feb 29th, 2008 at 6:43am
Print Post  
There are related events in the Diagram class. We keep them there to let you attach an event handler just once, and have it raised for each node. Otherwise you would have to attach a handler to each node after the node is created, loaded from a file, or after some undo/redo operations . If you prefer that, you can always declare an event member in your derived class, and raise it from the OnClick implementation.

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