Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Crash when copying links (Read 4708 times)
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Crash when copying links
Jan 21st, 2009 at 2:10pm
Print Post  
Hi Stoyan,

When I copy a selection that includes links, an exception is raised:
Code
Select All
Exception message:
Object reference not set to an instance of an object.

Stack:
   at MindFusion.Diagramming.ConnectionPoint.GetAnchorPos(Int32 anchorIdx, PointF& point)
   at MindFusion.Diagramming.DiagramLink.set_OriginAnchor(Int32 value)
   at MindFusion.Diagramming.DiagramLink.set_OriginIndex(Int32 value)
   at MindFusion.Diagramming.DiagramLink..ctor(DiagramLink prototype, DiagramNode src, DiagramNode dest)
   at MindFusion.Diagramming.DiagramLink.Clone(Boolean clipboard)
   at MindFusion.Diagramming.Diagram.CopySelection(Diagram source, Boolean unconnectedLinks, Boolean copyGroups)
   at MindFusion.Diagramming.WinForms.DiagramView.xd387e793db5b6581(Boolean x14d6ee1d6b77a32d, Boolean xf7b2c9839607605d)
   at MindFusion.Diagramming.WinForms.DiagramView.CopyToClipboard(Boolean persist, Boolean groups)
   at Entities.MainForm.button3_Click(Object sender, EventArgs e) in M:\Varies\TestsC#\CopyWithLinks\MainForm.cs:line 306
A first chance exception of type 'System.NullReferenceException' occurred in MindFusion.Diagramming.dll 



To reproduce this error:
I used the Entities sample (my favorite Wink). I added 2 buttons (Copy and Paste). They do:
Code
Select All
// Copy
private void button3_Click(object sender, EventArgs e)
{
    this._pasteDelta = 10;
    try
    {
        this.diagramView.CopyToClipboard(false, true);
    }
    catch (Exception exc)
    {
        System.Console.WriteLine("Exception message:\n" + exc.Message + "\n\nStack:\n" + exc.StackTrace);
    }
}

// Paste
private void button4_Click(object sender, EventArgs e)
{
    this.diagramView.PasteFromClipboard(this._pasteDelta, this._pasteDelta, false);
    this._pasteDelta += 25;
} 



Then, create 2 entities, link them and CTRL-Click to select all 3 components. Click Copy and BOOM!

How can I avoid this?

Thanks,
Marie
« Last Edit: Jan 22nd, 2009 at 2:58pm by marie »  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Crash when copying links
Reply #1 - Jan 21st, 2009 at 3:51pm
Print Post  
Hi,

I have another problem with the same code. Select a container that has a node in it (but don't select the node). Copy / paste. The pasted container includes the node as it should. However, that node doesn't have the ShapeNode buttons anymore...

Thanks!
Marie
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Crash when copying links
Reply #2 - Jan 21st, 2009 at 7:14pm
Print Post  
Hi again,

I have a 3rd question.

Is there a way to know which node what copied? I am catching diagram.NodePasted and I have access to the new node, but not the old one (I need to have the .tag associated to it but it seems to be lost).

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Crash when copying links
Reply #3 - Jan 22nd, 2009 at 7:05am
Print Post  
Hi Marie,

1) Please try that with the build from the PM page.
2) Works fine here when the copyGroups argument of CopyToClipboard is set to true.
3) It's not possible; there's no way to find out if the clipboard data comes from the same process at all, so the control can't assume the original objects are in the same memory address space and give you references to them. If you need copy/paste only for a single process, you could use the CopySelection and PasteSelection methods. The SelectionCopy object contains references to both the copies and the original items.

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



Posts: 147
Joined: Nov 11th, 2008
Re: Crash when copying links
Reply #4 - Jan 22nd, 2009 at 1:37pm
Print Post  
Hi Stoyan,

1) Wow! Cheesy Grin Smiley 8) Is it going to be in the next released version?
2) I can't get it to work... I do
Code
Select All
this.diagramView.CopyToClipboard(false,true); 

The problem is still there (missing ShapeNodes). Also, if I copy a container with 2 tablenodes in it that are linked to each other, the link doesn't get copied. Could you retry it using the Entities sample (the standalone one)... I just added the code above (from the 1st post) and added another button to create containers:
Code
Select All
// Create container
private void button2_Click(object sender, EventArgs e)
{
    ContainerNode container = this.diagram.Factory.CreateContainerNode(0, 0, 50, 50);
    container.Caption = "Caption";
    container.EnabledHandles = AdjustmentHandles.ResizeBottomRight |
                       AdjustmentHandles.Move;
    container.HandlesStyle = HandlesStyle.DashFrame;
} 

I can send you the project if you think it could be helpful.

3) CopySelection & PasteSelection will be perfect for me Smiley


Thanks again for your answers. You're a big help.
Marie


Edit: Forgot to mention... Also replaced the dlls to use the ones from the private message Grin
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Crash when copying links
Reply #5 - Jan 22nd, 2009 at 2:38pm
Print Post  
Hi Marie,

1) Of course 8)
2) So you mean button nodes attached to the contained node, and not to the container itself? At this time only the first level of children in groups is copied automatically. As a workaround, you could check if the buttons are present after the NodePasted event, and re-create them if they aren't there.

Stoyan
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Crash when copying links
Reply #6 - Jan 22nd, 2009 at 2:49pm
Print Post  
Hi Stoyan,

2) I'll do that.
However, if it would be possible to include all group levels, it would be helpful to me, because if I have containers containing containers with containers in it with nodes in it, only the first two are copied...

Do you know why the links are not pasted (in the case I copied a container containing 2 nodes linked together)? Is it for the same reason? Any idea of a workaround (I need to know if they should be linked)?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Crash when copying links
Reply #7 - Jan 22nd, 2009 at 2:54pm
Print Post  
Hi Marie,

You could implement your copy method so that before CopySelection it first selects all contained items recursively, and then in a second pass select all links between selected nodes.

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



Posts: 147
Joined: Nov 11th, 2008
Re: Crash when copying links
Reply #8 - Jan 22nd, 2009 at 2:58pm
Print Post  
I'll do that too!

Thanks a lot!
Marie
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint