Results 1 to 5 of 5

Thread: Which type of container to use?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2018
    Posts
    28

    Which type of container to use?

    Hello all,

    I am a newbie and trying my hand at creating an application to read in data from a text file and then drawing to a picturebox (my Canvas). The data represents a Printed Circuit Board.

    My question is what type of container should I use to store the data that is read in from the text file. I have had suggestions of "Dictionary", "List", and I am somewhat familiar with "Arrays" and "Tables" from past experience limited as it may be and from decades ago. I want the application to be as fast as possible and have been told that a very large array can be slower than a Dictionary or List. The data to be read in can contain just a few items or thousands, it all depends on the PCB.

    I hope I have explained what I want to do and my terminology is correct, if not, please forgive me and ask for clarification.

    I know this is a huge task but I like programming and need a task to keep me occupied.

    So far, with the help of some of you, I have created a Windows Form Application and I can read in the text file and place the contents in a textbox. Now I need to be able to parse thru the file and draw what it represents on the screen

    Thanks

    Dave

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,101

    Re: Which type of container to use?

    Perhaps if you could explain what the data actually is and how it's stored, we might be able to work out the best way to store it. There isn't just one best way for all data. It depends what the data is and exactly what you want to do with it. A Dictionary will be faster than an array if you want perform key-based lookups but you've given no indication of whether you do or not, so how could we advise?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2018
    Posts
    28

    Re: Which type of container to use?

    Here is a sample of the data, this is a very simple example, it Draws 2 Rectangles and is only meant to show the format of the data.

    Code:
    %FSLAX26Y26*%                 FS(format specification)L(Leading zeros omitted)A(Absolute coordinates) X26(X is 00.000000)Y26(00.000000)
    %MOMM*%                         Units are Millimeters
    %TF.Part,Other,example*%   File is not a PCB layer, just an example
    %LPD*%                             Start of new layer, level polarity is dark
    %ADD10C,0.010*%             Define Aperture with D-code 10 as a 0.01 mm circle
    D10*                                   Set Aperture with D-code 10 as current aperture (lines drawn will be .01mm thick, and circular ends)
    X0Y0D02*                           Move current point to 0,0 (D02 means move, don't draw)
    G01*                                  Sets linear interpolation mode (draw linearly between points, rather than a curve between points)
    X5000000Y0D01*                Draw to (5,0) (remember units are millimeter with 6 fractional digits) 
    Y5000000D01*                    Draw to (5,5)
    X0D01*                              Draw to (0,5)
    Y0D01*                              Draw to (0,0)
    X6000000D02*                   Move to (6,0)
    X11000000D01*                 Draw to (11,0)
    Y5000000D01*                   Draw to (11,5)
    X6000000D01*                   Draw to (6,5)
    Y0D01*                              Draw to (6,0)
    M02*                                 End of File
    Each line of text ends at the * everything after that has been added to explain what that line represents or an instruction. Once everything has been read and drawn in the picture box there may not even be a need to store the data. I want to be able to save the file and reopen it but wouldn't the data be saved in the picturebox?

    There may be as few as 3 different files(Layers) that need to be read in or many more, depending on the complexity of the PCB. Some files can be thousands of lines, again, depending on the complexity of the PCB.

    I also want to be able to Identify which layer is which and color them differently, maybe that would be a good use for a dictionary or list where each new layer could have it's own color assigned and each new layer a counter gets incremented by 1?

    Later, I want to be able to create a new text file to be saved that will contain info such as placement data and when that is opened all work previously completed is still there.

    The placement data consists of the location on the PCB in X, Y, Rotation, etc.

    I also want to be able to reset the origin from the origin of the picturebox (Top Left?)which I believe is from where everything is going to be drawn to an origin I determine, typically a corner of the PCB and all coordinates adjusted accordingly. I also want to be able to changed the "Units" after reading in the data.

    I am sure not all of this applies to what type of container but I wanted to let everyone know where I am going with this so to hopefully set up everything correctly up front rather than decide later on that something should have been done differently and have to be redone to correct.

    Thanks

    Dave

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,252

    Re: Which type of container to use?

    Of course that example is very simple and doesn't really give much of a clue to the complexity that the file format can be.
    Your second example, while also considered quite simple, gives a bit more of a clue to the complexity of the code that needs to be written and things that need to be stored in order to draw what the contents of the file suggests.

    You have a specification of the file format, and the document has multiple diagrams that categorize the hierarchy of commands and objects that the file contains. You will need to parse those commands and structures from the file and build up the hierarchy of structures and definition of the macros and have code that can evaluate expressions within those macros and support parameter substitution, etc...

    The effort to build the code to process the file, will be along the same effort it would take to write a small BASIC interpreter.
    So there is no simple "type of container" to hold the data read from the file. It will be a collection of containers, i.e. I would assume a minimum of a number of classes, dictionaries, lists and data structures. You will use dictionaries and lists within the various classes, and you will use dictionaries and lists outside of the classes to keep track of hierarchies of classes.

    The file format is designed to be processed in one pass, so there are no branches in the code that loop back, but since you can define macros (essentially Subs), that can later be reference in the file, you have to be able to save "executable" portions of the file to be processed when later referenced in the file.
    And since the macros can take a variable number of parameters, and has mathematical expressions in the macro that use those parameters in code that defines coordinates for drawing commands within the macro, that is something to be "stored" which is not simply data but expressions, or statements, that have to be evaluated, with parameter substituted values in them.
    Code:
    G04 Generated by UcamX v2017.04-170404 on 2017.4.7*
    G04 Ucamco copyright*
    %TF.GenerationSoftware,Ucamco,UcamX,v2017.04-170404*%
    %TF.CreationDate,2017-04-18T10:09:12+00:00*%
    %TF.FileFunction,Other,SMD prim20*%
    %TF.FilePolarity,Positive*%
    %FSLAX46Y46*%
    %MOMM*%
    G01*
    G04 Create aperture macro*
    %AMRECTROUNDCORNERS*
    0 Rectangle with rounded corners*
    0 $1 width *
    0 $2 height *
    0 $3 corner radius *
    0 $4 flash origin X offset *
    0 $5 flash origin Y offset *
    0 $6 rotation angle *
    0 Create two overlapping rectangles that omit the rounded corner areas*
    20,1,$2-2x$3,$4-$1/2,$5,$4+$1/2,$5,$6*
    20,1,$2,$4,$5-$2/2,$4,$5+$2/2,$6*
    0 Add circles at the corners. *
    1,1,2x$3,$4+$1/2-$3,$5+$2/2-$3,$6*
    1,1,2x$3,$4-$1/2+$3,$5+$2/2-$3,$6*
    1,1,2x$3,$4-$1/2+$3,$5-$2/2+$3,$6*
    1,1,2x$3,$4+$1/2-$3,$5-$2/2+$3,$6*%
    G04 Create aperture*
    %ADD10RECTROUNDCORNERS,4X3X0.5X0X0X0*%
    %ADD11RECTROUNDCORNERS,4X3X0.5X0X0X10*%
    %ADD12RECTROUNDCORNERS,4X3X0.5X0X0X30*%
    %ADD13RECTROUNDCORNERS,4X3X0.5X0X0X45*%
    %ADD20RECTROUNDCORNERS,4X3X0.5X1.0X2.0X0*%
    %ADD21RECTROUNDCORNERS,4X3X0.5X1.0X2.0X10*%
    %ADD22RECTROUNDCORNERS,4X3X0.5X1.0X2.0X30*%
    %ADD23RECTROUNDCORNERS,4X3X0.5X1.0X2.0X45*%
    G04 Select aperture*
    D10*
    G04 Flash aperture*
    X0Y0D03*
    D11*
    X6000000D03*
    D12*
    X12000000D03*
    D13*
    X18000000D03*
    D20*
    X0Y5000000D03*
    D21*
    X6000000Y5000000D03*
    D22*
    X12000000D03*
    D23*
    X18000000D03*
    %TF.MD5,2A4CB336BBB01B553283D651B0C6E89A*%
    M02*
    My previous comments on the code above, which I've reiterated above somewhat, can be found in this post of one of your previous threads.
    I don't think asking essentially the same naive question, will eventually result in a simple answer. It is a complex task and there isn't any getting around that. You need to write a full fledged interpreter, so probably worrying about an efficient data container isn't really important at this point.

    Writing out a high level design of what functional things need to be done, and fleshing out the logic of how things will be processed would be my first step.
    I mean, could you look at the file and process it by hand at this stage and draw the image on paper? Could you describe what you do in pseudo code at that point?
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,980

    Re: Which type of container to use?

    Quote Originally Posted by Dave14867 View Post
    I have had suggestions of "Dictionary", "List", and I am somewhat familiar with "Arrays" and "Tables" from past experience limited as it may be and from decades ago. I want the application to be as fast as possible and have been told that a very large array can be slower than a Dictionary or List. The data to be read in can contain just a few items or thousands, it all depends on the PCB.
    If you intend to be performing searches, then yea, a Dictionary would be ideal. However, what it sounds like is that this data needs to be processed in it's entirety to produce some kind of output. In this case I'd recommend using a simple Array or List(Of String) to store contents of the file.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width