Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Behavior.Modify still allows creating new links? (Read 2371 times)
AnthonyBrien
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 11
Joined: Feb 5th, 2008
Behavior.Modify still allows creating new links?
Mar 18th, 2008 at 1:44pm
Print Post  
I have a couple of modes for users to edit my diagram. The diagram consists of custom nodes and link types.
* Selection: Nothing can be changed, I just want things to get selected.
* Link: Can drag to create links, but cannot move nodes.
* Nodes: Can click or drag to create new nodes.

I'm not sure how to accomplish this. When I set Behavior = Modify, I can still create links and nodes (of the default type, not my custom type) between my nodes. When I set Behavior = Custom, and CustomLinkType to my custom link class, I can still create nodes (of the default type) and similarly, when I set CustomNodeType, I can still create links (of the default type)!

If I set the CustomLinkType or CustomNodeType to null, I get exceptions when I try clicking or dragging on the diagram.

So what is the best way to only permit creating nodes, creating links or selecting objects?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Behavior.Modify still allows creating new link
Reply #1 - Mar 18th, 2008 at 2:19pm
Print Post  
Modify should not let the users create links and nodes, but will still let them move existing items. You could use the following custom behavior class:

Code
Select All
public enum EditMode
{
	Selection,
	Link,
	Nodes
}

public class MyBehavior : LinkNodesBehavior
{
	public MyBehavior(DiagramView view) : base(view)
	{
		editMode = EditMode.Selection;
	}

	public override InteractionState StartDraw(PointF point)
	{
		switch (editMode)
		{
			case EditMode.Selection:
			{
				return new InteractionState(Diagram.Selection, 8, Action.Create);
			}
			break;
		case EditMode.Link:
			{
				DiagramNode node = Diagram.GetNodeAt(point);
				if (node != null)
					return base.StartDraw(point);
			}
			break;
		case EditMode.Nodes:
			{
				return new InteractionState(CreateNode(), 8, Action.Create);
			}
			break;
		}
		return null;
	}

	protected override DiagramNode CreateNode()
	{
		return new ContainerNode(Diagram);
	}


	public EditMode EditMode
	{
		get { return editMode; }
		set { editMode = value; }
	}

	private EditMode editMode;
}
 



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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Behavior.Modify still allows creating new link
Reply #2 - Mar 18th, 2008 at 2:21pm
Print Post  
and then define aMyBehavior myBehavior; member in your form and use it like this

private void Form1_Load(object sender, System.EventArgs e)
{
     myBehavior = new MyBehavior(diagramView);
     diagramView.CustomBehavior = myBehavior;
     myBehavior.EditMode = EditMode.Nodes;
     ...
}

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


I love YaBB 1G - SP1!

Posts: 11
Joined: Feb 5th, 2008
Re: Behavior.Modify still allows creating new link
Reply #3 - Mar 18th, 2008 at 9:55pm
Print Post  
Sorry, this was a silly mistake on my part, I was resetting the Behavior to LinkContainer in another place in my code. Thanks for the sample custom behavior class, it will make my code cleaner.

However I still have an issue, and this one is reproducible in the demo application with the Containers: When you set the Behavior to modify, and have two Containers side by side, selecting them by dragging a selection box around them makes one container child of the other one.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Behavior.Modify still allows creating new link
Reply #4 - Mar 19th, 2008 at 10:04am
Print Post  
This version fixes the selection problem:
https://mindfusion.eu/_temp/ctrsel_fix.zip

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