Copy Subgraph

Hi,

Below is my custom subgraph.

When i copy and paste nothing is pasted from clipboard.

Can you suggest me what could wrong.


Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports Northwoods.Go

Namespace Mes.Plasma.Draw
<Serializable()> _
Public Class LimitingSubGraph
Inherits GoSubGraph
Public Sub New(ByVal cView As GraphView)
myView = cView
Me.SkipsUndoManager = True
Me.BorderPenColor = Color.Black
Me.Resizable = True
Me.Movable = True
Me.PickableBackground = True
Me.Handle.Style = GoCollapsibleHandleStyle.ChevronUp
Me.Label.Bold = False
Dim obj As GoObject = New LimitingSubGraphMarker
obj.Position = New PointF(0, 0)
Add(obj)
obj = New LimitingSubGraphMarker
obj.Position = New PointF(350, 175)
Add(obj)
myCollaspeObj.Image = CType(GoImage.DefaultResourceManager.GetObject(“RBD.bmp”), System.Drawing.Image)
myCollaspeObj.Selectable = False
myCollaspeObj.Printable = True
CollapsedObject = myCollaspeObj
CollapsedLabelSpot = GoObject.MiddleBottom
Corner = New SizeF(1, 1)
Me.SkipsUndoManager = False
End Sub
Public Sub ArrangeLayout(ByVal CurGraph As LimitingSubGraph, Optional ByVal ChangedX As Double = 0)
Dim CurBounds As New RectangleF()
CurBounds = CurGraph.Bounds
Dim rMin As New RectangleF()
Dim objGraph As LimitingSubGraph
If Me.Document Is Nothing Then Return
If Me.Document.Count = 0 Then Return
For Each obj As GoObject In Me.Document
If TypeOf obj Is LimitingSubGraph And obj IsNot CurGraph Then
objGraph = CType(obj, LimitingSubGraph)
rMin = obj.Bounds
If CurBounds.IntersectsWith(rMin) = True And CurGraph.Parent Is objGraph.Parent Then
If ChangedX <> 0 Then
obj.Left = ChangedX + 25
Else
If (obj.Right - CurBounds.Left) < (CurBounds.Right - obj.Left) AndAlso objGraph.IsExpanded = True Then
obj.Left = CurBounds.Left - obj.Width - 25
Else
obj.Left = CurBounds.Left + CurBounds.Width + 25
End If
End If
ArrangeLayout(obj)
End If
End If
Next
End Sub
Public Overrides Sub Changed(ByVal subhint As Integer, ByVal oldI As Integer, ByVal oldVal As Object, ByVal oldRect As System.Drawing.RectangleF, ByVal newI As Integer, ByVal newVal As Object, ByVal newRect As System.Drawing.RectangleF)
MyBase.Changed(subhint, oldI, oldVal, oldRect, newI, newVal, newRect)
If subhint = GoSubGraph.ChangedBottomRightMargin Then
'when you resize the subgraph
If CInt(oldRect.X) <> CInt(newRect.X) OrElse CInt(oldRect.Y) <> CInt(newRect.Y) OrElse CInt(oldRect.Width) <> CInt(newRect.Width) OrElse CInt(oldRect.Height) <> CInt(newRect.Height) Then
ArrangeLayout(Me)
End If
ElseIf subhint = GoObject.ChangedBounds Then
'when you move subgraph
If oldRect.X <> 0 AndAlso oldRect.Y <> 0 AndAlso newRect.X <> 0 AndAlso newRect.Y <> 0 AndAlso oldI = 0 AndAlso newI = 0 AndAlso oldVal Is Nothing AndAlso newVal Is Nothing Then
If (CInt(oldRect.X) <> CInt(newRect.X) OrElse CInt(oldRect.Y) <> CInt(newRect.Y)) AndAlso CInt(oldRect.Width) = CInt(newRect.Width) AndAlso CInt(oldRect.Height) = CInt(newRect.Height) Then
ArrangeLayout(Me)
ElseIf (CInt(oldRect.X) = CInt(newRect.X) AndAlso CInt(oldRect.Y) = CInt(newRect.Y)) AndAlso (CInt(oldRect.Width) <> CInt(newRect.Width) OrElse CInt(oldRect.Height) <> CInt(newRect.Height)) Then
ArrangeLayout(Me)
End If
End If
ElseIf subhint = GoSubGraph.ChangedExpandedResizable Then
'expanded state
'oldval=false and newval=true is collapse state
If oldVal = True And newVal = False Then
ArrangeLayout(Me)
End If
ElseIf subhint = GoGroup.ChangedPickableBackground Then
End If
End Sub
Protected Overrides Sub CollapseChild(ByVal child As GoObject, ByVal sgrect As RectangleF)
If (TypeOf child Is LimitedNodePort) Then Return ’ don’t “collapse” each port
MyBase.CollapseChild(child, sgrect)
End Sub
Protected Overrides Function ComputeInsideMarginsSkip(ByVal child As GoObject) As Boolean
’ don’t consider the MultiPortSubGraphPorts
If (TypeOf child Is IGoPort) Then
Return True
End If
Dim link As IGoLink
’ nor any links connected to them
If (TypeOf child Is IGoLink) Then
link = CType(child, IGoLink)
Else
link = Nothing
End If
If (Not link Is Nothing) Then
Dim p As IGoPort = link.FromPort
If (Not p Is Nothing AndAlso Me.MultiPorts.Contains(p.GoObject)) Then
Return True
End If
p = link.ToPort
If (Not p Is Nothing AndAlso Me.MultiPorts.Contains(p.GoObject)) Then
Return True
End If
End If
Return MyBase.ComputeInsideMarginsSkip(child)
End Function
Protected Overrides Function ComputeCollapsedSizeSkip(ByVal child As GoObject) As Boolean
’ don’t consider the MultiPortSubGraphPorts
If (TypeOf child Is IGoPort) Then
Return True
End If
Dim link As IGoLink
’ nor any links connected to them
If (TypeOf child Is IGoLink) Then
link = CType(child, IGoLink)
Else
link = Nothing
End If
If (Not link Is Nothing) Then
Dim p As IGoPort = link.FromPort
If (Not p Is Nothing AndAlso Me.MultiPorts.Contains(p.GoObject)) Then
Return True
End If
p = link.ToPort
If (Not p Is Nothing AndAlso Me.MultiPorts.Contains(p.GoObject)) Then
Return True
End If
End If
Return MyBase.ComputeCollapsedSizeSkip(child)
End Function
Protected Overrides Sub CopyChildren(ByVal newgroup As GoGroup, ByVal env As GoCopyDictionary)
MyBase.CopyChildren(newgroup, env)
Dim newsg As LimitingSubGraph = CType(newgroup, LimitingSubGraph)
newsg.myPorts = New ArrayList()
newsg.myCollaspeObj = newsg.CollapsedObject
If newsg.myCollaspeObj.Image Is Nothing Then
newsg.myCollaspeObj.Image = CType(GoImage.DefaultResourceManager.GetObject(“RBD.bmp”), System.Drawing.Image)
End If
newsg.CollapsedObject = newsg.myCollaspeObj
Dim p As GoObject
For Each p In myPorts
newsg.myPorts.Add(env§)
Next
End Sub
Private Sub CopyMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim v As GoView = GoContextMenu.FindView(CType(sender, MenuItem))
If Not (v Is Nothing) Then
v.EditCopy()
End If
End Sub
Private Sub CutMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim v As GoView = GoContextMenu.FindView(CType(sender, MenuItem))
If Not (v Is Nothing) Then
v.EditCut()
End If
End Sub
Private Sub DeleteMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim v As GoView = GoContextMenu.FindView(CType(sender, MenuItem))
If Not (v Is Nothing) Then
v.EditDelete()
End If
End Sub
Protected Overrides Sub FinishExpand(ByVal hpos As PointF)
MyBase.FinishExpand(hpos)
If CurrentSubGraph IsNot Nothing Then
CurrentSubGraph.PickableBackground = True
CurrentSubGraph.BackgroundColor = Color.LightBlue
End If
Me.BackgroundColor = Color.LightGreen
Me.PickableBackground = False
CurrentSubGraph = Me
End Sub
Public Overrides Function GetContextMenu(ByVal view As GoView) As GoContextMenu
Dim cm As GoContextMenu = New GoContextMenu(view)
If (view.CanEditDelete()) Then
cm.MenuItems.Add(New MenuItem(“Delete”, New EventHandler(AddressOf Me.DeleteMenuItem_Click), Shortcut.Del))
End If
If (view.CanEditCut()) Then
cm.MenuItems.Add(New MenuItem(“Cut”, New EventHandler(AddressOf Me.CutMenuItem_Click), Shortcut.CtrlX))
End If
If (view.CanEditCopy()) Then
cm.MenuItems.Add(New MenuItem(“Copy”, New EventHandler(AddressOf Me.CopyMenuItem_Click), Shortcut.CtrlC))
End If
If (view.CanInsertObjects()) Then
cm.MenuItems.Add(New MenuItem(“Paste”, New EventHandler(AddressOf Me.Paste_Command)))
End If
cm.MenuItems.Add(New MenuItem(“Properties”, New EventHandler(AddressOf Me.PropertiesMenuItem_Click), Shortcut.CtrlP))
Return cm
End Function
Public Property InternalNextNodePos() As PointF
Get
Return myNextNodePos
End Get
Set(ByVal Value As PointF)
myNextNodePos = Value
End Set
End Property
Public Function IsUnusedName(ByVal s As String) As Boolean
If (Me.Document Is Nothing) Then Return True
Dim obj As GoObject
Dim CurSG As GoSubGraph = CType(Me.Parent, GoSubGraph)
If CurSG Is Nothing Then
For Each obj In Me.Document.Layers.Default
If Not (obj Is Me) Then
Dim n As LimitingSubGraph = Nothing
If (TypeOf obj Is LimitingSubGraph) Then n = CType(obj, LimitingSubGraph)
If (Not (n Is Nothing) AndAlso n.Text = s) Then
Return False
End If
End If
Next
Else
For Each obj In CurSG
If Not (obj Is Me) Then
Dim n As LimitingSubGraph = Nothing
If (TypeOf obj Is LimitingSubGraph) Then n = CType(obj, LimitingSubGraph)
If (Not (n Is Nothing) AndAlso n.Text = s) Then
Return False
End If
End If
Next
End If
Return True
End Function
Public Overrides Sub LayoutHandle()
Dim h As GoSubGraphHandle = Me.Handle
If h IsNot Nothing AndAlso h.CanView() Then
’ keep handle up-to-date
Dim b As RectangleF = ComputeBorder()
h.SetSpotLocation(TopLeft, New PointF(b.Left, b.Top))
End If
End Sub
Public Overrides Sub LayoutLabel()
If Label Is Nothing OrElse (Me.IsExpanded) Then
MyBase.LayoutLabel()
Else
Dim b As RectangleF = ComputeBorder()
Label.Position = New PointF(b.Left, CollapsedObject.Bottom)
End If
End Sub
Public Overridable Sub LayoutAllPorts()
If (Me.MultiPorts.Count = 0) Then Return
If (myLayingOutPorts) Then Return
’ recalculate border, in case base.LayoutChildren caused changes
’ Note that ComputeInsideMarginsSkip skips all ports in its determination of the border
Dim rect As RectangleF = ComputeBorder()
If Me.IsExpanded = False Then
rect = Me.CollapsedObject.Bounds()
End If
myLayingOutPorts = True
’ compute corners
Dim tl As PointF = New PointF(rect.X, rect.Y)
Dim tr As PointF = New PointF(rect.X + rect.Width, rect.Y)
Dim br As PointF = New PointF(rect.X + rect.Width, rect.Y + rect.Height)
Dim bl As PointF = New PointF(rect.X, rect.Y + rect.Height)
’ now layout each set of ports between the corners
LayoutPorts(MiddleLeft, tl, bl)
LayoutPorts(MiddleRight, tr, br)
myLayingOutPorts = False
End Sub
Public Overrides Sub LayoutChildren(ByVal childchanged As GoObject)
’ implementations of LayoutChildren shouldn’t do anything when Initializing is true
If (Me.Initializing) Then Return
If (myPorts Is Nothing) Then Return
MyBase.LayoutChildren(childchanged)
’ don’t call LayoutAllPorts when the child whose bounds were changed was a port
If (TypeOf childchanged Is GoImage) OrElse (childchanged Is Nothing) Then
LayoutHandle()
End If
If (TypeOf childchanged Is GoText) OrElse (childchanged Is Nothing) Then
LayoutLabel()
End If
If Not Me.MultiPorts.Contains(childchanged) OrElse (childchanged Is Nothing) Then
LayoutAllPorts()
End If
End Sub
Private Sub LayoutPorts(ByVal spot As Integer, ByVal a As PointF, ByVal b As PointF)
’ count how many there are on a particular side (as specified by SPOT)
Dim Count As Integer = 0
Dim port As LimitedNodePort
For Each port In Me.Ports
If (port.Side = spot) Then
Count = Count + 1
End If
Next
’ now position them evenly along that side
Dim c As Single = 1
For Each port In Me.MultiPorts
If (port.Side = spot) Then
Dim p As PointF = New PointF(a.X + 0.5 * (b.X - a.X), a.Y + 0.5 * (b.Y - a.Y))
port.SetSpotLocation(spot, p)
c = c + 1
End If
Next
End Sub
Public Overridable Function MakePort(ByVal spot As Integer) As LimitedNodePort
Dim p As LimitedNodePort = New LimitedNodePort()
p.MaxLinks = 1
p.Side = spot
p.Size = New SizeF(3, 10)
myPorts.Add§
Add§
LayoutAllPorts()
Return p
End Function

    Public Function MakeUniqueName(ByVal prefix As String) As String
        Dim counter As Integer = 1
        Dim isNumber As Boolean
        Dim s As String = prefix
        If prefix.Length > 0 Then
            isNumber = False
            If IsNumeric(s.Substring(prefix.Length - 1, 1)) = False Then
                If prefix.Length > 1 Then
                    If IsNumeric(s.Substring(prefix.Length - 2, 1)) = True Then
                        isNumber = True
                    End If
                End If
                If isNumber = False Then
                    s = prefix & " " & counter.ToString()
                End If
            Else
                isNumber = True
            End If
            While (Not IsUnusedName(s))
                If isNumber = True Then
                    s = prefix + " (" & counter.ToString() & ")"
                Else
                    s = prefix + " " & counter.ToString()
                End If
                counter += 1
            End While
        End If
        Return s
    End Function
    Public Property MultiPorts() As ArrayList
        Get
            Return myPorts   ' an unordered list of MultiPortSubGraphPorts
        End Get
        Set(ByVal Value As ArrayList)
            myPorts = Value
        End Set
    End Property
    Public Function NextNodePosition() As PointF
        Dim nxt As PointF = myNextNodePos
        myNextNodePos.X += 65
        If myNextNodePos.X > 5000 Then
            myNextNodePos.X = 65
            myNextNodePos.Y += 50
            If myNextNodePos.Y > 9999999 Then
                myNextNodePos.Y = 50
            End If
        End If
        Return nxt
    End Function
    Public Overrides Function OnContextClick(ByVal evt As GoInputEventArgs, ByVal view As GoView) As Boolean
        view.RaiseBackgroundContextClicked(evt)
        Return True
    End Function
    Public Overrides Function OnDoubleClick(ByVal evt As Northwoods.Go.GoInputEventArgs, ByVal view As Northwoods.Go.GoView) As Boolean
        If Me.WasExpanded = False Then
            Me.Expand()
        Else
            Me.myNextNodePos.X = evt.DocPoint.X
            Me.myNextNodePos.Y = evt.DocPoint.Y
        End If
        Return True
    End Function
    Protected Overrides Sub OnLayerChanged(ByVal oldlayer As GoLayer, ByVal newlayer As GoLayer, ByVal mainObject As GoObject)
        MyBase.OnLayerChanged(oldlayer, newlayer, mainObject)
        If (oldlayer Is Nothing AndAlso Not (newlayer Is Nothing)) Then
            ' make sure the name is unique, ignoring this node itself
            Me.Text = MakeUniqueName(Me.Text)
        End If
    End Sub
    Public Overrides Function OnSingleClick(ByVal evt As Northwoods.Go.GoInputEventArgs, ByVal view As Northwoods.Go.GoView) As Boolean
        Dim curView As GraphView = CType(view, GraphView)
        If curView IsNot Nothing AndAlso TypeOf curView Is GraphView Then 'AndAlso view.Selection Is Nothing
            If CurrentSubGraph IsNot Nothing Then
                CurrentSubGraph.PickableBackground = True
                CurrentSubGraph.BackgroundColor = Color.LightBlue
            End If
            curView.CurrentSubGraphNode = CType(Me, LimitingSubGraph)
            Me.BackgroundColor = Color.LightGreen
            Me.PickableBackground = False
            CurrentSubGraph = Me
        End If
        MyBase.OnSingleClick(evt, view)
    End Function
    Public Sub Paste_Command(ByVal sender As Object, ByVal e As EventArgs)
        Dim v As GoView = GoContextMenu.FindView(CType(sender, MenuItem))
        If Not (v Is Nothing) Then
            v.StartTransaction()
            Dim docpt As PointF = v.LastInput.DocPoint
            v.Selection.Clear()
            v.EditPaste()  ' selects all newly pasted objects
            Dim copybounds As RectangleF = GoDocument.ComputeBounds(v.Selection, v)
            Dim offset As SizeF = New SizeF(docpt.X - copybounds.X, docpt.Y - copybounds.Y)
            v.MoveSelection(v.Selection, offset, True)
            v.FinishTransaction("Context Paste")
        End If
    End Sub
    Public Shared Function CreateSubSystemNode(ByVal View As GraphView, Optional ByVal subGraph As LimitingSubGraph = Nothing, Optional ByVal ID As Integer = -1, Optional ByVal nodeLable As String = "RBD", _
                                   Optional ByVal StartX As Single = -1, Optional ByVal StartY As Single = -1, Optional ByVal IsExpanded As Boolean = False, _
                                   Optional ByVal NextNodeX As Single = -1, Optional ByVal NextNodeY As Single = -1) As LimitingSubGraph
        View.StartTransaction()
        View.Document.SkipsUndoManager = True
        Dim doc As GraphDoc
        Dim stn As LimitingSubGraph = New LimitingSubGraph(View)
        If View.Selection.Primary IsNot Nothing AndAlso TypeOf View.Selection.Primary Is LimitingSubGraph Then
            subGraph = CType(View.Selection.Primary, LimitingSubGraph)
        End If
        stn.Reshapable = True
        stn.Selectable = True
        stn.Text = nodeLable
        stn.PartID = ID
        stn.Width = 350
        stn.Height = 175
        If subGraph IsNot Nothing Then
            If NextNodeX <> -1 And NextNodeY <> -1 Then
                subGraph.InternalNextNodePos = New PointF(NextNodeX, NextNodeY)
            End If
            If StartX = -1 And StartY = -1 Then
                Dim nxtPos As PointF = subGraph.NextNodePosition
                StartX = subGraph.Left + nxtPos.X
                StartY = subGraph.Top + nxtPos.Y
                stn.Width = 350 ' - nxtPos.X
                stn.Height = 175 ' - nxtPos.Y
            Else
                StartX = subGraph.Left + StartX
                StartY = subGraph.Top + StartY
            End If
            stn.Position = New PointF(StartX, StartY)
            View.Document.SkipsUndoManager = False
            subGraph.Add(stn)
            subGraph.AddChildName(stn.Text, stn)
            View.Document.SkipsUndoManager = True
        Else
            doc = CType(View.Document, GraphDoc)
            stn.Position = doc.NextNodePosition
            If NextNodeX <> -1 And NextNodeY <> -1 Then
                stn.InternalNextNodePos = New PointF(NextNodeX, NextNodeY)
            End If
            View.Document.SkipsUndoManager = False
            doc.Add(stn)
            View.Document.SkipsUndoManager = True
        End If
        stn.MakePort(MiddleLeft)
        stn.MakePort(MiddleRight)
        If IsExpanded = True Then
            stn.Expand()
        Else
            stn.Collapse()
        End If
        View.Document.SkipsUndoManager = False
        View.ScrollRectangleToVisible(stn.Bounds)
        View.FinishTransaction("Insert RBD SubSystem")
        Return stn
    End Function
    Private myNextNodePos As PointF = New PointF(25, 25)
    Private myPorts As ArrayList = New ArrayList()
    Private myCollaspeObj As GoImage = New GoImage()
    Private myView As GraphView
    Public Shared CurrentSubGraph As LimitingSubGraph
    <NonSerialized()> Private myLayingOutPorts As Boolean
End Class
<Serializable()> _
Public Class LimitingSubGraphMarker
    Inherits GoRectangle
    Public Sub New()
        Me.Size = New Size(1, 1)
        Me.Printable = False
        Me.Brush = Nothing
        Me.PenColor = Color.LightGray
    End Sub
    ' only seen when the mouse is over it
    Public Overloads Function OnEnterLeave(ByVal from As GoObject, ByVal [to] As GoObject, ByVal view As GoView) As Boolean
        If from Is Me Then
            Me.Brush = Nothing
        End If
        If [to] Is Me Then
            Me.BrushColor = Color.Gold
        End If
        Return True
    End Function
End Class

End Namespace

see this note

Hello Jake,



I have tried doc.TestSerialization()



This has given exception like below





System.Runtime.Serialization.SerializationException was unhandled by user code

Message=Type ‘Northwoods.Go.GoView’ in Assembly ‘Northwoods.Go, Version=4.1.0.2, Culture=neutral, PublicKeyToken=a4e3b7b70161cfe8’ is not marked as serializable.

Source=mscorlib

StackTrace:

at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)

at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)

at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()

at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)

at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)

at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)

at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)

at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)

at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)

at Northwoods.Go.GoDocument.TestSerialization()

at DevExpress.XtraBars.Demos.RibbonSimplePad.frmMain.iCopy_ItemClick(Object sender, ItemClickEventArgs e) in E:\PDFTools and VB Examples\Mes.Plamsa\Mes.Plasma.MDI\frmMain.vb:line 540

at DevExpress.XtraBars.BarItem.OnClick(BarItemLink link)

at DevExpress.XtraBars.BarBaseButtonItem.OnClick(BarItemLink link)

at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.OnShortcutItemClick(BarItem item, BarShortcut shortcut)

at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.CheckShortcut(BarManager manager, KeyEventArgs e)

at DevExpress.XtraBars.MessageFilter.BarManagerHook.PreFilterMessage(Message& m)

at DevExpress.XtraBars.MessageFilter.BarManagerMessageFilter.System.Windows.Forms.IMessageFilter.PreFilterMessage(Message& m)

InnerException:

Hello Jake,



Fixed this problem by setting



<NonSerialized()> Private myView As GraphView



in my custom subgraph.



Thanks & regards,



Venkatesh