Journal to collect lots of circles and segregate into different groups

Hi,
Our company deal a lot with 2d drawings for NC drilling programming.
So, I'm trying to create a journal to collect lots of circles and segregate into different groups of circles.
The process:
1) Collect circles
2) Assign circles with same XY coordinate into a Group(of circles)
3) After complete assign all circles into Group(of circles), these Group(of circles) will further assign into a bigger family(I call it NCCircleGroup) base on the following guidance:
Group(of circles) with identical quantity of circles per Group(of circles) and radius and linefont of each of the circle of different Group(of circles) are identical are to group into one NCCircleGroup.
4) Segregation completed, wait for further action.

The journal completed and looks like running, but I'm a novice programmer in NX API and VB .NET and I have some question:
1) Please recommend a more efficient data structures; currently I use collectionbase class ( please refer to portion: class NCCircleGroup, class circleGroup & class circle); someone commended that not efficient:(
2) After completion of segregation how to close the current winform and call another winform
3) Can I use datagridview in journal? If can, how to link the data?

Thanks

#Region "import"

Option Strict Off
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports System.Collections '.ObjectModel
Imports system.collections.generic
Imports NXOpen
Imports NXOpen.CAM
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpenUI

#End Region

Module Module1

#Region "setting"

#Region "declaration"
Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow

#End Region
#Region "variables"
Dim mTolerence As Double = 0.01
Dim mAcrPropertyName As String = "try123"
Dim mySelectedObjects As NXObject()
Dim myForm As New Form1 'create new form object
Dim mTagNoList As New List(Of Tag)()
Dim mCircleGroupList As New list(Of circleGroup)()
Dim mNCCircleGroupList As New list(Of NCCircleGroup)()
#End Region

#End Region

Sub Main()

Dim setupTag As Tag
Dim selectedTags() As Tag = Nothing

If IsNothing(workPart) Then Return 'active part required

'theUfSession.Cam.InitSession()
'theUfSession.Setup.AskSetup(setupTag)
'If setupTag <> 0 Then

lw.Open()
Do
myForm.ShowDialog() 'display our form
If myForm.Canceled Then
Return 'user pressed cancel, exit journal
ElseIf myForm.SelectCurve Then
createGroupsOfCircles(_SelectCircles())
End If

Loop Until myform.ok
CreateNCCircleGroup()
Action()
'Else
'MsgBox("Not CAM session!", MsgBoxStyle.Exclamation, "WARNING")
'End If

End Sub

Function _SelectCircles()
Dim myTagNo As New List(Of Tag)()
Dim DisplayableObject1 As DisplayableObject

If SelectObjects("Select curves", mySelectedObjects) = Selection.Response.Ok Then
lw.WriteLine("")
For Each myObj As NXObject In mySelectedObjects
DisplayableObject1 = CType(NXObjectManager.Get(myObj.tag), DisplayableObject)
DisplayableObject1.unHighlight()

If TypeOf myObj Is NXOpen.Arc Then
If Not myTagNo.contains(myObj.Tag) Then
myTagNo.add(myObj.Tag)

Dim objects1(0) As NXOpen.NXObject
objects1(0) = Utilities.NXObjectManager.Get(myObj.Tag)

Dim objectGeneralPropertiesBuilder1 As NXOpen.ObjectGeneralPropertiesBuilder
objectGeneralPropertiesBuilder1 = workPart.PropertiesManager.CreateObjectGeneralPropertiesBuilder(objects1)

Dim selectNXObjectList1 As NXOpen.SelectNXObjectList
selectNXObjectList1 = objectGeneralPropertiesBuilder1.SelectedObjects

objectGeneralPropertiesBuilder1.Name = mAcrPropertyName

Dim nXObject1 As NXOpen.NXObject
nXObject1 = objectGeneralPropertiesBuilder1.Commit()

objectGeneralPropertiesBuilder1.Destroy()
End If
End If
Next
End If
Return myTagNo
End Function

Function SelectObjects(prompt As String, _
ByRef selObj As NXObject()) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.Curves} ', _
'Selection.SelectionType.Faces, _
'Selection.SelectionType.Edges, _
'Selection.SelectionType.Features}

Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
prompt, "Selection", _
Selection.SelectionScope.AnyInAssembly, _
False, typeArray, selobj)

If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.OK Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Private Sub createGroupsOfCircles(ByVal selectedCirclesTagNoList As List(Of Tag))

Dim TaggedObject1 As TaggedObject

For Each objTag As Tag In selectedCirclesTagNoList
Dim radius As String = Nothing
Dim centerPoint As String = Nothing
Dim lineFont As String = Nothing

Dim type, subtype As Integer
theUFSession.Obj.AskTypeAndSubtype(objTag, type, subtype)

TaggedObject1 = Utilities.NXObjectManager.Get(objTag)
Dim NamedProps() As String = thesession.GetNamedProperties(TaggedObject1)

For Each thisProp As String In NamedProps
Dim thisValue As String = thesession.GetProperty(TaggedObject1, thisProp)
If thisProp.contains("Radius") Then
radius = thisValue
If centerPoint IsNot Nothing And lineFont IsNot Nothing Then Exit For
ElseIf thisProp.contains("CenterPoint") Then
centerpoint = thisValue
If radius IsNot Nothing And lineFont IsNot Nothing Then Exit For
ElseIf thisProp.contains("LineFont") Then
lineFont = thisValue
If radius IsNot Nothing And centerPoint IsNot Nothing Then Exit For
End If
Next
If assignToGroupOfCircles(objTag, radius, centerPoint, lineFont) Then mTagNoList.add(objTag)
Next
End Sub

Public Function assignToGroupOfCircles(ByVal objtag As tag, ByVal radius As String, ByVal centerPoint As String, ByVal lineFont As String)

If radius Is Nothing Then Return False 'if not valid radius

Dim point(2) As Double
point = getPoint(centerPoint)
Dim myCircleGroup As circleGroup
Dim bIsSamePoint As Boolean = False

'check if circle of same location(member of the same group)
For Each myCircleGroup In mCircleGroupList
If myCircleGroup.X = point(0) And myCircleGroup.Y = point(1) Then
bIsSamePoint = True
Exit For
End If
Next

Dim dbRadius As Double = Math.Round(Convert.ToDouble(radius), 4)
If bIsSamePoint Then 'if same point, add circle only to the group

Dim index As Integer
index = indexAtSortedLocation(myCircleGroup, dbRadius)
If Not index < 0 Then 'sort radius; biggest radius as 1st item
myCircleGroup.insert(index, New circle(dbRadius, lineFont, objtag))
Else 'identical radius, ignored
Return False
End If
Else 'not same point, create new group and circle to the group
myCircleGroup = New circleGroup(POINT)
myCircleGroup.Add(New circle(dbRadius, lineFont, objtag))
mCircleGroupList.add(myCircleGroup)
myCircleGroup.Name = "Circle Group No." & mCircleGroupList.count.tostring()
End If

Return True
End Function

Public Function indexAtSortedLocation(ByVal myCirclegroup As circleGroup, ByVal dbRadius As Double)
Dim index As Integer = 0
For Each tmpCircle As circle In myCirclegroup
If tmpCircle.radius = dbRadius Then 'identical radius, ignored
Return -1
Else
If tmpCircle.radius < dbRadius Then
Exit For
End If
index += 1
End If
Next

Return index
End Function

Public Function getPoint(ByVal centerPoint As String)
Dim point(2) As Double
Dim strArr() As String

strArr = centerPoint.Split(" ")
For count As Integer = 0 To strArr.Length - 1
point(count) = Convert.ToDouble(strArr(count))
Next

Return point
End Function

Private Sub CreateNCCircleGroup()
lw.WriteLine(" ")
lw.WriteLine(" ")
lw.WriteLine(" ")
lw.WriteLine(" ")
lw.WriteLine(" ")
lw.WriteLine(" total collected circle groups = " & mCircleGroupList.count)
Dim myCircle As circle
Dim myCircleGroup As circleGroup
Dim myNCCircleGroup As NCCircleGroup

If mCircleGroupList.count = 0 Then Return
For Each myCircleGroup In mCircleGroupList

Dim IsSameNCCircleGroup As NCCircleGroup = Nothing
IsSameNCCircleGroup = assignToNCCircleGroup(myCircleGroup)
If Not IsSameNCCircleGroup Is Nothing Then 'same NCCircleGroup
IsSameNCCircleGroup.Add(myCircleGroup)
Else 'not same NCCircleGroup
myNCCircleGroup = New NCCircleGroup
myNCCircleGroup.Add(myCircleGroup)
myNCCircleGroup.circleQtyAsREF = myCircleGroup.count
mNCCircleGroupList.add(myNCCircleGroup)
End If
Next

End Sub

Public Function assignToNCCircleGroup(ByVal CircleGroupToBeAssign As circleGroup)
Dim IsSameNCCircleGroup As NCCircleGroup = Nothing

For Each mNCCirclegroup As NCCircleGroup In mNCCircleGroupList ' go through all the existing NCCircleGroup
If mNCCirclegroup.circleQtyAsREF = CircleGroupToBeAssign.count Then 'First check for qty of circle per circlegroup if same as REF qty
If circleGroupMatched(mNCCirclegroup, CircleGroupToBeAssign) Then
IsSameNCCircleGroup = mNCCirclegroup
Exit For
End If
End If
Next

Return IsSameNCCircleGroup
End Function

Public Function circleGroupMatched(ByVal mNCCirclegroup As NCCircleGroup, ByVal CircleGroupToBeAssign As circleGroup)
Dim IsMatched As Boolean = True

Dim myFirstCircleGroup As circleGroup
Dim myCircle, circleOfGroupToBeAssign As circle
For Each myFirstCircleGroup In mNCCirclegroup
For Each myCircle In myFirstCircleGroup 'iterate through all circle data in the 1st circleGroup
Dim atleastOneMatched As Boolean = False
For Each circleOfGroupToBeAssign In CircleGroupToBeAssign
If myCircle.radius = circleOfGroupToBeAssign.radius Then 'if radius are same
If myCircle.LineFont = circleOfGroupToBeAssign.LineFont Then 'if linefont are same, then we have a matched group
atleastOneMatched = True
Exit For
End If
End If
Next
If Not atleastOneMatched Then
IsMatched = False
Exit For
End If
Next
Exit For 'refer to the 1st item only
Next

Return IsMatched
End Function

Private Sub Action()
lw.WriteLine(" ")
lw.WriteLine(" ")
lw.WriteLine("Action: Total NCCircleGroup = " & mNCCircleGroupList.count)
Dim obj As DisplayableObject
For Each myNCCircleGroup As NCCircleGroup In mNCCircleGroupList
lw.WriteLine(" ")
lw.WriteLine(" ")
lw.writeline(" Ref cicle groups per NCCircleGroup = " & myNCCircleGroup.circleQtyAsREF & " total members = " & myNCCircleGroup.count)

For Each myCircleGroup1 As circleGroup In myNCCircleGroup
lw.writeline(" X = " & myCircleGroup1.x & ", Y = " & myCircleGroup1.y)
For Each myCircle As circle In myCircleGroup1
lw.writeline(" radius = " & myCircle.radius)
Next
Exit For
Next
For Each myCircleGroup As circleGroup In myNCCircleGroup
lw.writeline(" members = " & myCircleGroup.Name) ' & " qty of circles per CircleGroup = " & myCircleGroup.count)
For Each myCircle As circle In myCircleGroup
'lw.writeline(" radius = " & myCircle.radius)
obj = CType(NXObjectManager.Get(myCircle.tagno), DisplayableObject)
obj.unHighlight()
'Exit For
Next
Next
Next
End Sub

End Module

Public Class NCCircleGroup
Inherits CollectionBase

Private _Name As String
Private _circleQtyAsREF As Integer = 0

Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Public Property circleQtyAsREF() As Integer
Get
Return _circleQtyAsREF
End Get
Set(ByVal value As Integer)
_circleQtyAsREF = value
End Set
End Property
Public Sub Add(ByVal value As circleGroup) ' Add an circleGroup.
List.Add(value)
End Sub

End Class

Public Class circleGroup
Inherits CollectionBase
Private _Name As String
Private _point(2) As Double

Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Public Property point() As Double()
Get
Return _point
End Get
Set(ByVal value As Double())
_point = value
End Set
End Property
Public Property X() As Double
Get
Return _point(0)
End Get
Set(ByVal value As Double)
_point(0) = value
End Set
End Property
Public Property Y() As Double
Get
Return _point(1)
End Get
Set(ByVal value As Double)
_point(1) = value
End Set
End Property
Public Property Z() As Double
Get
Return _point(2)
End Get
Set(ByVal value As Double)
_point(2) = value
End Set
End Property
Public Sub New(ByVal point() As Double)
_point = point
End Sub
Public Sub Add(ByVal value As circle) ' Add an circle.
List.Add(value)
End Sub
Public Sub Insert(ByVal index As Integer, ByVal value As circle) ' Insert a new circle.
List.Insert(index, value)
End Sub
End Class

Public Class circle
Private _radius As Double
Private _LineFont As String
Private _tagNo As tag

Public Property radius() As Double
Get
Return _radius
End Get
Set(ByVal value As Double)
_radius = value
End Set
End Property
Public Property LineFont() As String
Get
Return _LineFont
End Get
Set(ByVal value As String)
_LineFont = value
End Set
End Property
Public Property tagNo() As tag
Get
Return _tagNo
End Get
Set(ByVal value As tag)
_tagNo = value
End Set
End Property
Public Sub New(ByVal radius As Double, LineFont As String, ByVal tagNo As tag)
_radius = radius
_LineFont = LineFont
_tagNo = tagNo
End Sub
End Class

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
_SelectCurve = False
End Sub

Private _canceled As Boolean = False
Public ReadOnly Property Canceled() As Boolean
Get
Return _canceled
End Get
End Property

Private _OK As Boolean = False
Public ReadOnly Property OK() As Boolean
Get
Return _OK
End Get
End Property

Private _Apply As Boolean = False
Public ReadOnly Property apply() As Boolean
Get
Return _Apply
End Get
End Property

Private _SelectCurve As Boolean = False
Public ReadOnly Property SelectCurve() As Boolean
Get
Return _SelectCurve
End Get
End Property

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
_canceled = True
Me.Close()
End Sub

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
_ok = True
Me.Close()
End Sub

Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApply.Click
_Apply = True
Me.Close()
End Sub

Private Sub btnSelectCurve_Click(sender As Object, e As EventArgs) Handles btnSelectCurve.Click
_SelectCurve = True
Me.Close()
End Sub

End Class

_
Partial Class Form1
Inherits System.Windows.Forms.Form

'Form overrides dispose to clean up the component list.
_
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
_
Private Sub InitializeComponent()
Me.btnOK = New System.Windows.Forms.Button()
Me.btnCancel = New System.Windows.Forms.Button()
Me.btnApply = New System.Windows.Forms.Button()
Me.btnSelectCurve = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'btnOK
'
Me.btnOK.Location = New System.Drawing.Point(216, 248)
Me.btnOK.Name = "btnOK"
Me.btnOK.Size = New System.Drawing.Size(75, 51)
Me.btnOK.TabIndex = 38
Me.btnOK.Text = "OK"
Me.btnOK.UseVisualStyleBackColor = True
'
'btnCancel
'
Me.btnCancel.Location = New System.Drawing.Point(297, 248)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(75, 51)
Me.btnCancel.TabIndex = 38
Me.btnCancel.Text = "Cancel"
Me.btnCancel.UseVisualStyleBackColor = True
'
'btnApply
'
Me.btnApply.Location = New System.Drawing.Point(135, 248)
Me.btnApply.Name = "btnApply"
Me.btnApply.Size = New System.Drawing.Size(75, 51)
Me.btnApply.TabIndex = 38
Me.btnApply.Text = "Apply"
Me.btnApply.UseVisualStyleBackColor = True
'
'btnSelectCurve
'
Me.btnSelectCurve.Location = New System.Drawing.Point(135, 67)
Me.btnSelectCurve.Name = "btnSelectCurve"
Me.btnSelectCurve.Size = New System.Drawing.Size(75, 51)
Me.btnSelectCurve.TabIndex = 38
Me.btnSelectCurve.Text = "Select Curves"
Me.btnSelectCurve.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(515, 315)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.btnSelectCurve)
Me.Controls.Add(Me.btnApply)
Me.Controls.Add(Me.btnOK)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "2D HOLE MAKING"
Me.ResumeLayout(False)

End Sub
Friend WithEvents btnOK As System.Windows.Forms.Button
Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents btnApply As System.Windows.Forms.Button
Friend WithEvents btnSelectCurve As System.Windows.Forms.Button

End Class