Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Problem with CopyToClipboard (Read 5522 times)
mberger
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Problem with CopyToClipboard
Oct 27th, 2009 at 10:50am
Print Post  
hi,

i know that i have to provide a copy constructor in my custom SVGNode class for clipboard operations. How should this copy constructor look like in vb.net?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with CopyToClipboard
Reply #1 - Oct 27th, 2009 at 11:41am
Print Post  
Hi,

It should look like this:

Code
Select All
Public Sub New(ByVal protoype As MyNode)
	MyBase.New(protoype)
End Sub 



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


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Re: Problem with CopyToClipboard
Reply #2 - Oct 27th, 2009 at 12:03pm
Print Post  
Hi Stoyo,

CopyFromClipboard works...
But if i try to PasteFromClipboard, PasteFromClipboard returns false?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with CopyToClipboard
Reply #3 - Oct 27th, 2009 at 1:19pm
Print Post  
Hi Marco,

Have you called the RegisterItemClass method to register the custom class for serialization?

Stoyan
  
Back to top
 
IP Logged
 
mberger
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Re: Problem with CopyToClipboard
Reply #4 - Oct 27th, 2009 at 2:54pm
Print Post  
Hi Stoyo,

i got it - but now i have an other problem.

i provide some properties in my customnodes. What i have to do, that this properties will be copied too?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with CopyToClipboard
Reply #5 - Oct 27th, 2009 at 3:36pm
Print Post  
Hi Marco,

Apart from copying them in the copy constructor, you must also implement the binary serialization methods - SaveTo(BinaryWriter) and LoadFrom(BinaryReader).

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


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Re: Problem with CopyToClipboard
Reply #6 - Oct 27th, 2009 at 3:50pm
Print Post  
Ok i have fixed the proiblem with the properties,

... but is it also possible to copy attached Nodes?

I have attached some Nodes to my customnode but if i paste my customnode from the clipboard the attached node will not be copied to the diagram.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with CopyToClipboard
Reply #7 - Oct 28th, 2009 at 7:37am
Print Post  
Set the boolean 'groups' argument of CopyToClipboard to true.

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


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Re: Problem with CopyToClipboard
Reply #8 - Oct 28th, 2009 at 12:43pm
Print Post  
Hi Stoyo,

... thanks a lot for your support !!!

But i have now a last problem with the copy and paste action. I have a custom DiagramLink class with the following copy constructor

Code
Select All
    Public Sub New(ByVal prototype As CustomLink, ByVal Origin As DiagramNode, ByVal Destination As DiagramNode)
        MyBase.new(prototype, Origin, Destination)
        ' ...
    End Sub
 



Now if i try to paste a CustomLink from the clipboard, i get a InvalidCastException
"Unable to cast object of DiagramLink to type CustomLink "

What's wrong with my copy constructor ???

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with CopyToClipboard
Reply #9 - Oct 28th, 2009 at 1:38pm
Print Post  
There's nothing wrong, but actually the requirement for clipboard support is to implement the DiagramItem.Clone method, so you should do that, say by returning an instance created with that copy constructor. It seems for nodes this works out-of-the-box because their default Clone implementation calls the copy constructor automatically.

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


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Re: Problem with CopyToClipboard
Reply #10 - Oct 28th, 2009 at 1:57pm
Print Post  
Ok,

i add the following code to my CustomLink class

Code
Select All
    Public Overrides Function Clone(ByVal clipboard As Boolean) As MindFusion.Diagramming.DiagramItem
	  Return MyBase.Clone(clipboard)
    End Function
 



But nothing happends.... ???

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with CopyToClipboard
Reply #11 - Oct 28th, 2009 at 3:37pm
Print Post  
base.Clone returns a DiagramLink. You could call your copy constructor instead:
Return New MyLink(Me)
  
Back to top
 
IP Logged
 
mberger
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Re: Problem with CopyToClipboard
Reply #12 - Oct 28th, 2009 at 4:03pm
Print Post  
hmmm,

it doesn't work for me...

"Registration of the Custom DiagramItems"
Code
Select All
    Public Sub RegisterDiagramItems()
        ' ...
        ' Registrieren der DiagramItems
        Diagram.RegisterItemClass(GetType(SVGNode_Node), "SVGNode", 1)
        Diagram.RegisterItemClass(GetType(SVGNode_Inlet), "SVGInlet", 1)
        Diagram.RegisterItemClass(GetType(SVGNode_Outlet), "SVGOutlet", 1)
        Diagram.RegisterItemClass(GetType(SVGNode_Resistance), "SVGResistance", 1)
        Diagram.RegisterItemClass(GetType(CustomLink), "CustomLink", 1)
        ' ...
    End Sub
 



"CustomLink Class"
Code
Select All
Public Class CustomLink
    ' ...
    Inherits DiagramLink
    ' ...
    Public Sub New(ByVal prototype As CustomLink, ByVal origin As DiagramNode, ByVal destination As DiagramNode)
        MyBase.new(prototype, origin, destination)
        ' ...
        Tag_BrokenLink = prototype.Tag_BrokenLink
        FakeVolumFlow = prototype.FakeVolumFlow
        ' ...
    End Sub
    ' ...
    Public Sub New(ByVal diagram As Diagram, ByVal Origin As DiagramNode, ByVal Destination As DiagramNode)
        MyBase.New(diagram, Origin, Destination)
        ' ...
        Tag = "hasNoAttechedNodes"
        Tag_BrokenLink = ""
        FakeVolumFlow = 0
        ' ...
        ' Look and Feel
        BaseShape = MindFusion.Diagramming.ArrowHead.None
        HeadShape = MindFusion.Diagramming.ArrowHead.Triangle
        Pen.DashStyle = Drawing2D.DashStyle.Solid
        ' ...
        Dim CBrush As New MindFusion.Drawing.SolidBrush(System.Drawing.Color.FromArgb(255, 60, 60, 60))
        Pen.Brush = CBrush
        Brush = CBrush
        HeadPen.Brush = CBrush
        ' ...
        Selected = False
        ' ...
    End Sub
    ' ...
    Public Overrides Function Clone(ByVal clipboard As Boolean) As MindFusion.Diagramming.DiagramItem
        Return New CustomLink(Me, Me.Origin, Me.Destination)
        ' ...
    End Function
    ' ...
#Region "Save / Load"
    ' ...
    Protected Overrides Sub SaveTo(ByVal writer As System.IO.BinaryWriter, ByVal ctx As PersistContext)
        MyBase.SaveTo(writer, ctx)
        ' ...
        writer.Write(_Tag_BrokenLink)
        writer.Write(_FakeVolumFlow)
    End Sub
    ' ...
    Protected Overrides Sub LoadFrom(ByVal reader As System.IO.BinaryReader, ByVal ctx As PersistContext)
        MyBase.LoadFrom(reader, ctx)
        ' ...
        _Tag_BrokenLink = reader.ReadString
        _FakeVolumFlow = reader.ReadDouble
    End Sub
    ' ...
#End Region
    ' ...
    Public Property Tag_BrokenLink() As String
        Get
            Return _Tag_BrokenLink
        End Get
        Set(ByVal value As String)
            _Tag_BrokenLink = value
        End Set
    End Property
    ' ...
    Public Property FakeVolumFlow() As Double
        Get
            Return _FakeVolumFlow
        End Get
        Set(ByVal value As Double)
            _FakeVolumFlow = value
        End Set
    End Property
    ' ...
    Private _Tag_BrokenLink
    Private _FakeVolumFlow
    ' ...
End Class
 



Should i implement the DiagramItem.Clone method in all custom nodes or only in the customLink class ?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with CopyToClipboard
Reply #13 - Oct 29th, 2009 at 2:45pm
Print Post  
For successful serialization you must add a no-args constructor, or one that takes just a Diagram argument. Otherwise the load method won't be able to create an instance of the custom class. This worked for me:

Code
Select All
Public Class CustomLink
	Inherits DiagramLink
	Public Sub New(ByVal d As Diagram)
		MyBase.New(d)
	End Sub

	Public Sub New(ByVal prototype As CustomLink, ByVal origin As DiagramNode, ByVal destination As DiagramNode)
		MyBase.new(prototype, origin, destination)
	End Sub

	Public Overrides Function Clone(ByVal clipboard As Boolean) As MindFusion.Diagramming.DiagramItem
		Return New CustomLink(Me, Me.Origin, Me.Destination)
	End Function
End Class
 



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


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Re: Problem with CopyToClipboard
Reply #14 - Oct 30th, 2009 at 11:26am
Print Post  
Hi Stoyo,

... now it works fine!
thanks a lot for your support.  Grin

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