Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Copy and paste ShapeNode (Read 2058 times)
RunMan
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 7
Joined: Sep 24th, 2015
Copy and paste ShapeNode
Oct 6th, 2015 at 11:37am
Print Post  
Hello,

i create a custom shape node and add this node to a nodelistview. Now i can drag the node to my diagram.
I select the node and copy and paste it. The node will be copied. New position is in the upper left corner of the diagram. I expect the node with some offset from origin position. What's wrong?
This is the code i create the node:
Code (C++)
Select All
public class LogicGateNot : ShapeNode
    {
        public LogicGateNot()
        {
            InitNode();
        }

        // Required for creating nodes by dragging them from the NodeListView
        public LogicGateNot(LogicGateNot prototype)
            : base(prototype)
        {
            InitNode();
        }

        private void InitNode()
        {
            // comment out the next line and copy/paste will work correctly
            this.SetBounds(new Rect(0, 0, 100, 100), true, true);
        }

        public override void Draw(System.Windows.Media.DrawingContext graphics, RenderOptions options)
        {
            graphics.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Red, 1), new Rect(0, 0, 100, 100));
            //base.Draw(graphics, options);
        }
    }
 


When i set the width/heigth to 100/100 the error (for me Wink) occurs. When i comment out the SetBounds function the default width/heigth is 75/75, but this is to small.

Thank you
RunMan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Copy and paste ShapeNode
Reply #1 - Oct 6th, 2015 at 12:22pm
Print Post  
Hi,

Not only NodeListView but copy / paste relies on the copy constructor too. The constructor's base(prototype) call will copy Bounds value of prototype, but then your InitNode method overwrites it. You could use a Boolean argument for InitNode to specify whether it should change Bounds, and pass false when calling from copy constructor.

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


I Love MindFusion!

Posts: 7
Joined: Sep 24th, 2015
Re: Copy and paste ShapeNode
Reply #2 - Oct 6th, 2015 at 1:30pm
Print Post  
Perfect! It's working!

Thank you!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint