Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Question about behavior class (Read 8533 times)
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Question about behavior class
Feb 6th, 2013 at 6:04am
Print Post  
I customize the behave of a diagram by my own behavior class, base class is ModifyBehavior. The process of my behavior class is, create a new shape then create InteractionState object with the new shape. So actually the shape user drag/move is the new shape. It can work well.

But I try to do better. When use move a shape in this way, the original selected shape looks is not selected. There are not 6 small rectangles around shape. So how to still show these 6 rectangles when use move a shape in this way ?
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Question about behavior class
Reply #1 - Feb 6th, 2013 at 6:53am
Print Post  
while user move a shape/shapes in the way, how to cancel the operation when user click right button ?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Question about behavior class
Reply #2 - Feb 6th, 2013 at 8:52am
Print Post  
Quote:
So how to still show these 6 rectangles when use move a shape in this way ?


Set the shape.Selected property to true.

Quote:
while user move a shape/shapes in the way, how to cancel the operation when user click right button?


All operations should be automatically cancelled upon right click, unless you have changed something in the RightButtonActions property. When this happens, the base behavior class will call the virtual CancelDrag() method, which you could override to do some cleanup if necessary.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Question about behavior class
Reply #3 - Feb 6th, 2013 at 11:14pm
Print Post  
Thanks for your reply.

Below code can work well, when I move a shape and click right button, the operation can be canceled well.
public override InteractionState StartDraw(PointF point)
{
     return base.StartDraw(point);
}
protected override void OnMouseMove(Point mousePosition)
{
     base.OnMouseMove(mousePosition);
     return;
}
protected override void OnMouseUp(Point mousePosition, MouseButtons mouseButton)
{
     base.OnMouseUp(mousePosition, mouseButton);
     return;
}

So I change method StartDraw like below:
public override InteractionState StartDraw(PointF point)
{
     DiagramItem activeItem = base.Diagram.ActiveItem;
     int handle = 0;
     if (((activeItem != null) && !activeItem.NotInteractive()) && activeItem.HitTestHandle(point, ref handle))
     {
           return new InteractionState(activeItem, handle, MindFusion.Diagramming.Action.Modify);
     }
     return new InteractionState(base.Diagram.Selection, -1, MindFusion.Diagramming.Action.Create);
}
It still can work, and I do believe you know these code very well.

So I think if I can set a correct value to ActiveItem property of Diagram then I can customize the behaviour. Then I change method StartDraw like below:
public override InteractionState StartDraw(PointF point)
{
     DiagramNode item = new CurrentNode(base.Diagram);
     item.SetBounds(((DiagramNode)base.Diagram.ActiveItem).Bounds, false, false);
     base.Diagram.Items.Add(item);
     base.Diagram.Selection.Items.Clear();
     item.Selected = true;
     base.Diagram.ActiveItem = item;
     item.ZTop();

     DiagramItem activeItem = base.Diagram.ActiveItem;
     int handle = 0;
     if (((activeItem != null) && !activeItem.NotInteractive()) && activeItem.HitTestHandle(point, ref handle))
     {
           return new InteractionState(activeItem, handle, MindFusion.Diagramming.Action.Modify);
     }
     return new InteractionState(base.Diagram.Selection, -1, MindFusion.Diagramming.Action.Create);
}

But this code can not work. When I click right button there is a big red cross on client of DiagramView. The base class of CurruentNode is ShapeNode, and the base class of the shape that I want to move is TableNode.

Could you help me to solve this problem? Thanks a lot
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Question about behavior class
Reply #4 - Feb 7th, 2013 at 12:34am
Print Post  
Stoyo wrote on Feb 6th, 2013 at 8:52am:
Set the shape.Selected property to true.
I hope that helps,
Stoyan


I did. But it flickered, when I was moving a shape in this way.
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Question about behavior class
Reply #5 - Feb 7th, 2013 at 1:10am
Print Post  


Look this picture above. It looks like Table0 covers Table1. Three left handle rectangles of Table1 only can be show half. That's why cause flickering.
How to solve this problem?

Thanks a lot.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Question about behavior class
Reply #6 - Feb 8th, 2013 at 1:35pm
Print Post  
Your StartDraw will never get called if you start dragging a handle of the ActiveItem, which I suppose you do seeing that its Bounds are assigned to the new item's Bounds. The movement of selected items is common for all behavior classes; it starts from the base OnMouseMove method if the mouse was pressed over an adjustment handle, and StartDraw is not called in that case. In this version we have moved that common code to a StartDrawCommon method which you could override to implement your scenario:
https://mindfusion.eu/_beta/fcnet602.zip

Otherwise with older versions you could create and select the new item from the OnMouseDown override if you detect the mouse is over the ActiveItem's handle, and then the standard interaction code should pick up and move your item.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Question about behavior class
Reply #7 - Feb 9th, 2013 at 12:53am
Print Post  
Thanks for reply.
I think StarDarw was called, becasue I got what I want. What I did is
1. Select a shape
2. Darg and move. So in StarDraw I add new shape then create a new InteractionState object, so actually I moved is the new shape.
3. Then at new position release button of mouse, delete new shape and move the shape to new position.

All of above have done and work well. Then I try to do something more to achieve a better experience.
1. Select shape Table0
2. Then drag and move Table0. At the very beginning of the operation (in StartDraw method) I try to assign Table1 to ActiveItem property and I still can move Table0. So what user can see is that Table0 is unselected and Table0 is being dragged and moved, Table1 is selected and is activated. So far I can finish this feature.

Then drag and move Table0 to the position where is the picture shows. At this moment 3 left handle rectangles of Table1 looks are covered by Table0, that's why cause flickering. This is the problem I face right now. I guess this is a bug. What do you think about? Could give some tips to solve this problem?

Thanks a lot and happy Chinese new year
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Question about behavior class
Reply #8 - Feb 11th, 2013 at 12:54pm
Print Post  
Here is a test project with your code and some fixes in StartDraw:
https://mindfusion.eu/_samples/BehaviorTest.zip

Let me know what I should change to see the problem. Also note that StartDraw will not get called if there are multiple items selected, but you can override the ShouldMoveSelection method and return false to avoid that.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Question about behavior class
Reply #9 - Feb 11th, 2013 at 11:47pm
Print Post  
hi Stoyan:

Thanks for your reply and your source code is a good smaple for me.
In the construction method of Form1, I change your code:
diagram1.Factory.CreateTableNode(10, 10, 30, 30).HandlesStyle = HandlesStyle.EasyMove;
To:
TableNode node0 = diagram1.Factory.CreateTableNode(30, 30, 150, 120);
node0.HandlesStyle = HandlesStyle.EasyMove;
node0.Caption = "Table0";

And in StartDRaw method I change your code:
DiagramNode item = new TableNode(base.Diagram);
To:
TableNode item = new TableNode(base.Diagram);
item.Caption = "Table1";

So It's easier for me to describe these two shapes. Stoyan, please do same thing to test this program. You will see, although you press button of mouse on Table0 but the shape that you move is Table1 actually. This is a part of what I want to do. Another part is when you are doing this operation, I want Table0 is selected and activated and Table1 is unselected. You may see the behave of Sequence Diagram of Visual Studio 2010. You press down left button on the head of a Lifeline shape then do same thing, you will see the difference compare with your sample.

Thanks a lot.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Question about behavior class
Reply #10 - Feb 12th, 2013 at 1:41pm
Print Post  
If what you are trying to do is to draw the modified table at both its original location and current mouse location, you could implement it via DrawForeground event handler:

Code
Select All
RectangleF originalPos = RectangleF.Empty;
DiagramNode modifiedNode = null;

void OnNodeStartModifying(object sender, NodeValidationEventArgs e)
{
	originalPos = e.Node.Bounds;
	modifiedNode = e.Node;
}

void OnDrawForeground(object sender, DiagramEventArgs e)
{
	if (modifiedNode != null)
	{
		var state = e.Graphics.Save();
		e.Graphics.TranslateTransform(
			originalPos.X - modifiedNode.Bounds.X,
			originalPos.Y - modifiedNode.Bounds.Y);
		modifiedNode.Draw(e.Graphics, new RenderOptions());
		modifiedNode.DrawHandles(e.Graphics, diagram.ActiveItemHandlesStyle);
		e.Graphics.Restore(state);
	}
}

void OnNodeModified(object sender, NodeEventArgs e)
{
	modifiedNode = null;
	diagram.Invalidate();
} 



That will also save you some headaches with undo/redo.

If you prefer the custom behavior solution and using a second table, where the original remains selected, first you will have to remove the code that changes the selection:

//base.Diagram.Selection.Clear();
//item.Selected = true;
//base.Diagram.ActiveItem = item;

and start modification via the item variable instead of ActiveItem:

//return new InteractionState(activeItem, handle, Action.Modify);
return new InteractionState(item, handle, Action.Modify);

You will also have to temporarily change the HandlesStyle to Invisible or InvisibleMove, since handles for the currently modified item are always drawn:

item.HandlesStyle = HandlesStyle.InvisibleMove;

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Question about behavior class
Reply #11 - Feb 13th, 2013 at 12:30am
Print Post  
Thanks for your reply.

Today I try custom behavior solution first, I list my code below:
public override InteractionState StartDraw(PointF point)
{
     int handle = 0;

     // this avoids a null-ref exception
     if (!(Diagram.ActiveItem != null && Diagram.ActiveItem.HitTestHandle(point, ref handle)))
           return base.StartDraw(point);

     TableNode item = new TableNode(base.Diagram);
     item.Caption = "Table1";
     item.HandlesStyle = HandlesStyle.EasyMove;
     item.SetBounds(((DiagramNode)base.Diagram.ActiveItem).Bounds, false, false);
     base.Diagram.Items.Add(item);
     item.HandlesStyle = HandlesStyle.Invisible;

     return new InteractionState(item, handle, MindFusion.Diagramming.Action.Modify);
}

But the reuslt is unacceptable, it is flickering. I recorded a video you may download here:
http://www.WideUnion.com/Temp/TestBehave.rmvb.
http://www.WideUnion.com/Temp/TestBehave.swf
or see here
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Question about behavior class
Reply #12 - Feb 13th, 2013 at 12:44am
Print Post  
hi Stoyan,
There is the same problem flickering, if I use DrawForeground event handler .
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Question about behavior class
Reply #13 - Feb 13th, 2013 at 7:32am
Print Post  
I can't see any flickering in my test project, neither when using two tables nor with custom drawing. Try disabling SelectionOnTop or AutoHandles if they are enabled in yours.
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Question about behavior class
Reply #14 - Feb 13th, 2013 at 11:56pm
Print Post  
hi Stoyan

My project is here: https://www.WideUnion.com/temp/TestCustomBehaviour.zip
Could you check it and solve the problem?

Thanks a lot.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint