Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Drag & Drop - Create Composite Node at cursor (Read 7434 times)
moelski
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
Drag & Drop - Create Composite Node at cursor
Jun 28th, 2011 at 3:02am
Print Post  
Hi !

I use a treeview control which list some node descriptions. The user can select such a node description and move it with drag & drop to the diagramview.

Now Iīd like to create a new composite node on that position where the user unpress the mousebutton.

I have the D&D running until this point:
Code
Select All
        private void diagramview_DragDrop(object sender, DragEventArgs e)
        {
            MessageBox.Show("Mouse : " + MousePosition.X +
                            (sender as DiagramView));
        } 



Now I need to know two things:
1) How can I get the mouse position within the diagramview? MousePosition will give me only the screen coordinates.
2) How can I set the initial position if I create a new CompositeNode? All nodes are created at the upper left corner by default.

btw.
Where can I set the diagramView size? Is there no autosize option? I have the DiagramView within a MDI Form and there are always scrollbars.

Greetz
Dominik
  
Back to top
 
IP Logged
 
moelski
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
Re: Drag & Drop - Create Composite Node at cur
Reply #1 - Jun 28th, 2011 at 3:55am
Print Post  
Hi !

Ok I figured out two things ...

1) I get the position within the DiagramView with this code:
Code
Select All
 (sender as DiagramView).PointToClient(MousePosition) 



2) I Can set the position of a node with the methode Move and use getPixel:
Code
Select All
		this.Move(X * Constants.GetPixel(diagram.MeasureUnit),
			    Y * Constants.GetPixel(diagram.MeasureUnit)); 


X position seems to be ok. But Y is not ok. The pixelvalue is about 10% wrong  Sad
  
Back to top
 
IP Logged
 
moelski
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
Re: Drag & Drop - Create Composite Node at cur
Reply #2 - Jun 28th, 2011 at 4:01am
Print Post  
Hi !

Forget all questions Grin

Setting the diagram.MeasureUnit to Pixel makes my life a lot easier Roll Eyes

Greetz
Dominik
  
Back to top
 
IP Logged
 
moelski
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
Re: Drag & Drop - Create Composite Node at cur
Reply #3 - Jun 28th, 2011 at 5:01am
Print Post  
well ... It seems that setting the MeasureUnit to Pixel results in some drawing problems.

The DiagramView wonīt get refreshed if I move a node.  Sad

So maybe you could give me some information how to handle it with the default measureunit. Thx
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drag & Drop - Create Composite Node at cur
Reply #4 - Jun 28th, 2011 at 6:02am
Print Post  
You must first convert the drag-and-drop screen coordinates to the view's client rectangle coordinates, and then to diagram units:
Code
Select All
PointF diagramPoint = diagramView.ClientToDoc(diagramView.PointToClient(new Point(e.X, e.Y))); 



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


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
Re: Drag & Drop - Create Composite Node at cur
Reply #5 - Jun 28th, 2011 at 8:59am
Print Post  
Hi Stoyan,

Quote:
The DiagramView wonīt get refreshed if I move a node.

Do you have an idea why the nodes wonīt get refresh correctly?

If I move a node there are always rests ...
Take a look at the picture.


The only thing I changed was setting the MeasureUnit to Pixel.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drag & Drop - Create Composite Node at cur
Reply #6 - Jun 28th, 2011 at 9:39am
Print Post  
Are you by chance moving nodes from the DragOver handler? You will have to call the view.RecreateCacheImage method in that case.
  
Back to top
 
IP Logged
 
moelski
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
Re: Drag & Drop - Create Composite Node at cur
Reply #7 - Jun 28th, 2011 at 9:43am
Print Post  
Hi !

No I only have these two eventhandler for d&d:
Code
Select All
Proj.DiagramView.DragEnter += diagram_DragEnter;
		Proj.DiagramView.DragDrop += diagram_DragDrop; 



And the strange thing is ... It works perfect if I switch back to measureUnit = Millimeter
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drag & Drop - Create Composite Node at cur
Reply #8 - Jun 28th, 2011 at 9:57am
Print Post  
If you are using custom-drawn node type, you must make sure the node graphics are inside the rectangle returned by GetRepaintRect. If deriving from CompositeNode, the components should be inside Bounds. Repainting might work ok in millimeters if the part outside Bounds/GetRepaintRect is still smaller than AdjustmentHandlesSize and ShadowOffset, but its larger in pixels. By the way you will have to change all size and length -related properties if you change the unit. Their values are not scaled automatically for the new unit.
  
Back to top
 
IP Logged
 
moelski
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
Re: Drag & Drop - Create Composite Node at cur
Reply #9 - Jun 28th, 2011 at 10:08am
Print Post  
Hi !

I think they are.
I use the code from your CompositeNode demo and this is my Node:
Root:
Code
Select All
private static readonly string Template = @"<SimplePanel Height=""55"" Width=""80"">
<Border Name=""Selection"" Pen=""LightSteelBlue"" Visible=""False"" />
<Border Name=""Highlight"" Pen=""Red"" Visible=""False"" />
<Border Padding=""1"">
   <Border Name=""Frame"" Background=""#F0F0F0"" Pen=""Black"" />
</Border>
</SimplePanel>"; 


And the frame content:
Code
Select All
private static readonly string ContentTemplate = @"
                <Border Padding=""1.5,1.5,1.5,1.5"">
                <GridPanel>
                    <GridPanel.Columns>
                            <GridColumn />
                    </GridPanel.Columns>
                    <GridPanel.Rows>
                            <GridRow Height=""4.2""/>
                            <GridRow />
                    </GridPanel.Rows>

                    <Border Name=""HeadBorder"" Background=""#D2D2D2"">
                        <Text Name=""Title"" Text=""Device"" TextAlignment=""Center"" GridRow=""0""/>
                    </Border>

                    <GridPanel GridRow=""1"">
                            <GridPanel.Columns>
                                <GridColumn />
                                <GridColumn />
                            </GridPanel.Columns>
                            <GridPanel.Rows>
                                <GridRow />
                            </GridPanel.Rows>

                            <Image Name=""Picture"" ImageAlign=""Center"" GridColumn=""0"" IsHitTestVisible=""False"">
                                <Image.Image>
                                        <Bitmap>D:\Dev Priv\LogView V3 .net\LogView V3\_Icons\_Found\missing.gif</Bitmap>
                                </Image.Image>
                            </Image>
                            <Text Text=""O"" Font=""Courier New, 12pt, style=Bold"" TextAlignment=""Far"" GridColumn=""1"" />

                    </GridPanel>

                </GridPanel>
</Border>"; 



So as far as I can see ... All is inside the bounds. Isnīt it?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drag & Drop - Create Composite Node at cur
Reply #10 - Jun 28th, 2011 at 12:00pm
Print Post  
It seems you have set fixed size for the root panel, and components might get repainted outside of the node's bounds and not get refreshed correctly. Setting fixed root dimensions is not advisable unless you know you nodes will have some minimum size. If you skip the Width and Height setters, this should let the content adjust automatically to the size of the node. If Width and/or Height are set, you have to ensure that the size of the node is at least as big as the size of its root component.

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


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
Re: Drag & Drop - Create Composite Node at cur
Reply #11 - Jun 29th, 2011 at 1:51pm
Print Post  
Hi !

Thx for your help !

Code
Select All
Rectangle test = new Rectangle(x, y, 80, 45);
this.SetBounds(test, false, false);    



Setting the bounds in the compositenodes constructor solved my problem.

Now I can set the node where I like in the correct size without any drawing problems.  Smiley

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