• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

VB.net: How to use nested ListOf to create Jagged List ?

I'm writing a program to create simple G-code for CNC machining based on creating a chain of lines and arcs.   The basic element is a cContour class which defines a single segment (LINE or ARC).    I then have a class, cChain, which contains a ListOf (cContour), which defines a single Chain or Loop.    

So, I have the capabliltiy to define a boundary or toolpath to machine.    Now, for machining a pockiet, I'll need to have a series of chains to remove all the material at the boundary and all areas within.   For simple shapes such as a circle (2 semi-circles), the pocket consists of a single chain at each offset layer.   This could be handled by having a Class called cToolPath containing a ListOf(cChain).

However, for more complex shapes the toolpath may be separated into multiple chains at each offset layer.  For example, let's consider a shape like a butterfly or bowtie which narrows in the middle.  At successive offset layers to generate the toolpath,  the offset path will yield two chains as the middle section collapses.    So, now, I need a jagged list of cChains at each layer.   Eseentially, I have a nested ListOf.   Unfortunately, I don't know how to get this to work.  

I tried to create a new Class called LayerOfChains which contains a ListOf(cChain).   I can't seem to be able to retrieve the data from the class using CTYPE.       How do I handle having a ListOf ( List Of (cContour)) ??



0
jlaidlaw
Asked:
jlaidlaw
  • 3
  • 2
1 Solution
 
Bob LearnedCommented:
Hmmm, let's see if I understand what you are looking for:

Public Class ChainLayer
  Public Chains As New List(Of Chain)
End Class

Public Class Chain
  Public Contours As New List(Of Contour)
End Class

Public Class Contour

End Class
0
 
Bob LearnedCommented:
   Dim layer As New ChainLayer()
    Dim chain As New Chain()
    Dim contour As New Contour()

    chain.Contours.Add(contour)

    layer.Chains.Add(chain)

Bob
 
0
 
jlaidlawAuthor Commented:
Ok, how do I retrieve the Chains in Layer?

For example, for working with the elements of the Chain, I used CTYPE

TempContour = CYTPE ( Chain(index), cContour)

If I used CTYPE  with ListOf(Chain), it fails.
0
 
Bob LearnedCommented:
1) With generics, you don't need CType, the compiler will check the type for you.

2) To get at a contour from a chain from a layer:

    Dim tempContour As Contour = layer.Chains(0).Contours(0)

3) To loop through all the chains in a layer:

  For Each chainCurrent As Chain In layer.Chains
  Next chainCurrent

4) To loop through all the contours in a chain:

  For Each chainCurrent As Chain In layer.Chains
      For Each contourCurrent As Contour In chainCurrent.Contours
      Next contourCurrent
  Next chainCurrent

Bob
0
 
jlaidlawAuthor Commented:
I kept running into the same brick wall.

Thanks for the help!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now