RecordLists: Difference between revisions

From Compost Wiki
Jump to navigation Jump to search
Jeffm (talk | contribs)
Noahj (talk | contribs)
 
(5 intermediate revisions by 2 users not shown)
Line 19: Line 19:
==Iteration==
==Iteration==
Record lists can be iterated (processed in a loop). This feature is one that was lacking in Named Maps. The [[EachRecordListItem]] loop is used to iterate record lists, as shown bellow.
Record lists can be iterated (processed in a loop). This feature is one that was lacking in Named Maps. The [[EachRecordListItem]] loop is used to iterate record lists, as shown bellow.
===Named Maps and Iteration===
Named maps are internal implemented using Record Lists, so they can also be iterated using the [[EachRecordListItem]] loop. Named maps are simply record lists with a pre-defined numeric field with the name "VALUE".


==Implementation==
==Implementation==
Line 32: Line 35:


=== Retrieving data from a list===
=== Retrieving data from a list===
To access the data store in a map, by the key, the command [[GetRecordListField|GetRecordListField#]] or [GetRecordListField|GetRecordListField?]] can be used (depending on the data type)
To access the data store in a list, by the key, the command [[GetRecordListField|GetRecordListField#]] or [GetRecordListField|GetRecordListField?]] can be used (depending on the data type)


   GetRecordListField#('Tools',ToolPostion#,'Diam')
   GetRecordListField#('Tools',ToolPostion#,'Diam')
Line 39: Line 42:


=== Clearing lists and items===
=== Clearing lists and items===
If the data in the map is not longer needed, or the record list needs to be reused, the post can call the command [[ClearRecordList]] to remove all data in the list.
If the data in a list is not longer needed, or the list needs to be reused, the post can call the command [[ClearRecordList]] to remove all data in the list.
   ClearRecordList('Tools')
   ClearRecordList('Tools')


Line 51: Line 54:
When inside this loop, the command [[ThisRecordListKey]]# will return the key for the current list record. This command can be used to access any field in the record list as needed.
When inside this loop, the command [[ThisRecordListKey]]# will return the key for the current list record. This command can be used to access any field in the record list as needed.


==Tool List Exampl ==
==Finding Records==
The commands [[GetNearestRecordListField]]# and [[GetNearestRecordListField]]? can be used to find a record that may not have the exact same key that the post currently has. These command will find the record that has a key that is closest but not greater then the specified value. These commands are useful for features such as Gear and Speed ranges.
 
==Tool List Example ==
This sample shows an tool list that is created, then output based on the tool position sorting.
This sample shows an tool list that is created, then output based on the tool position sorting.


Line 75: Line 81:
   NextRecordListItem
   NextRecordListItem
   ' ' EOL
   ' ' EOL
  RETURN
==G10 style WFO List Example ==
This example shows a work fixture offset list ordered by ascending WFO number designation, regardless of the order of WFO use. It avoids the common issue of multiple nested eachop loops which can cause a significant delay in post processing.
  doG10_WFOList:
  {///////}
  {I moved this section into progstart to fully utilize another eachop loop and save time}
    EachOp
    SetRecordListFieldBool('wfoList',csPartNum#,'LWord',gtPart6?)
    {SetWfoCS} {ONLY NEEDED IF IN PROGSTART}
    SetRecordListFieldNum('wfoList',csPartNum#,'WFONumInListWFO',doWFONumInList#)
    {SetG92CS} {ONLY NEEDED IF IN PROGSTART}
    SetRecordListFieldNum('wfoList',csPartNum#,'WFONumInListD',doWFONumInList#)
    SetRecordListFieldNum('wfoList',csPartNum#,'csOffsetX',CSOffsetX#)
    SetRecordListFieldNum('wfoList',csPartNum#,'csOffsetY',CSOffsetY#)
    SetRecordListFieldNum('wfoList',csPartNum#,'csOffsetZ',CSOffsetZ#)
    NextOp
  {\\\\\\\}
  EachRecordListItem('wfoList')
    SeqC 'G90G10'
    {doLWord}
    IF GetRecordListField?('wfoList',ThisRecordListKey#,'LWord')
    'L20'
    ELSE
    'L2'
    END 
    'P'
    IF WFOCS?
    Output('5',GetRecordListField#('wfoList',ThisRecordListKey#,'WFONumInListWFO'))
    ELSE
    Output('5',GetRecordListField#('wfoList',ThisRecordListKey#,'WFONumInListD'))
    END
    IF MetricOutput?
    'X' Output('X', GetRecordListField#('wfoList',ThisRecordListKey#,'csOffsetX') + Num#('274.9804') )
    'Y' Output('Y', GetRecordListField#('wfoList',ThisRecordListKey#,'csOffsetY') + Num#('-175.006') )
    'Z' Output('Z', GetRecordListField#('wfoList',ThisRecordListKey#,'csOffsetZ') + Num#('-634.98222') )
    ELSE
    'X' Output('X', GetRecordListField#('wfoList',ThisRecordListKey#,'csOffsetX') + Num#('10.826') )
    'Y' Output('Y', GetRecordListField#('wfoList',ThisRecordListKey#,'csOffsetY') + Num#('-6.89') )
    'Z' Output('Z', GetRecordListField#('wfoList',ThisRecordListKey#,'csOffsetZ') + Num#('-24.9993') )
    END
    'B0.C0.' EOL
  NextRecordListItem
  RETURN
  gtPart6?:
  ReturnBool GreaterThan? PartNum# Num#('6') OR GreaterThan? csPartNum# Num#('6')
  RETURN
  doWFONumInList#:
  IF GreaterThan? PartNum# Num#('6') OR GreaterThan? csPartNum# Num#('6')
    IF WFOCS?
    ReturnNum SUB# csPartNum# Num#('6')
    ELSE
    ReturnNum SUB# PartNum# Num#('6')
    END
  ELSE
    IF WFOCS?
    ReturnNum SUB# csPartNum# Num#('0')
    ELSE
    ReturnNum SUB# PartNum# Num#('0')
    END
  END
   RETURN
   RETURN

Latest revision as of 23:27, 22 August 2016

Named Record Lists

Overview

Named Record Lists are a convenience feature for Compost4 that were added to GibbsCAM 11.3 (11.2.1) to help post developers store, sort, and retrieve data as needed. This type of storage and retrieval is common for posts that need to build up custom lists such as tool and WFO lists.

Records

Records are a data structure that will store list of named values all associated with a single key.

Records can contain any number of named value fields, and be ether numeric (NUM) or boolean (Flag) types.

Keys

The key for a list record is always a number. The records in the list are always stored in ascending order based on the key. This means that when using a record list to sort items, the key defines the sort order.

Names

Each list has it's own name. These names are shared with the legacy Named Maps system. Names are not case sensitive and can be on any length.

Fields also have names. Field names are used only in conjunction with a named list, so multiple lists can have fields with identical names. Field names are also case insensitive and can be of any length.

Iteration

Record lists can be iterated (processed in a loop). This feature is one that was lacking in Named Maps. The EachRecordListItem loop is used to iterate record lists, as shown bellow.

Named Maps and Iteration

Named maps are internal implemented using Record Lists, so they can also be iterated using the EachRecordListItem loop. Named maps are simply record lists with a pre-defined numeric field with the name "VALUE".

Implementation

Record lists can be implemented in a manner very similar to Named maps

Saving data in a list

To save data in a record list and associate it with a key, the commands SetRecordListFieldNum or SetRecordListFieldBool are used, depending on the type of data the post wishes to store.

 SetRecordListFieldNum('Tools',TLPosition#,'Diam',TLDia#)
 SetRecordListFieldBool('Tools',TLPosition#,'IsMill', TLMillingTool?)

This example will save the current tool diameter and milling state into the record list "Tools", and associated them with the Tool position as it's key.

Retrieving data from a list

To access the data store in a list, by the key, the command GetRecordListField# or [GetRecordListField|GetRecordListField?]] can be used (depending on the data type)

 GetRecordListField#('Tools',ToolPostion#,'Diam')

This example would return the diameter value that was associated with the tool position, in this case.

Clearing lists and items

If the data in a list is not longer needed, or the list needs to be reused, the post can call the command ClearRecordList to remove all data in the list.

 ClearRecordList('Tools')

If a post needs to just remove a single entry in a record list it can simply call EraseRecordListItem('N',key#). This command only removes fields for the specified key value.

 EraseRecordListItem('Tools',ToolPostion#)

All record lists are cleared at the start of posting.

Iteration

The EachRecordListItem/NextRecordListItem loop will cycle through all elements of a list that have had some data set. This loop will iterate using in ascending order by the key. When inside this loop, the command ThisRecordListKey# will return the key for the current list record. This command can be used to access any field in the record list as needed.

Finding Records

The commands GetNearestRecordListField# and GetNearestRecordListField? can be used to find a record that may not have the exact same key that the post currently has. These command will find the record that has a key that is closest but not greater then the specified value. These commands are useful for features such as Gear and Speed ranges.

Tool List Example

This sample shows an tool list that is created, then output based on the tool position sorting.

 DoToolList:
   EachSortedTool('UsedThisFlowWithOffsets')	
     SetRecordListFieldNum('Tools',TLPosition#,'Offset',TLOffset#)
     SetRecordListFieldNum('Tools',TLPosition#,'ID',TLNum#)
     SetRecordListFieldNum('Tools',TLPosition#,'Diam',TLDia#)
     SetRecordListFieldBool('Tools',TLPosition#,'IsMill', TLMillingTool?)
   NextTool
   ' ' EOL
   '( Tool List )' EOL
   EachRecordListItem('Tools')
     ' ( '
     IF GetRecordListField?('Tools',ThisRecordListKey#,'IsMill')
         'Milling ' 
     ELSE
         'Turning '
     END
     'Tool ' Output('##',GetRecordListField#('Tools',ThisRecordListKey#,'ID'))
     ', Offset ' Output('###',GetRecordListField#('Tools',ThisRecordListKey#,'Offset'))
     ', Diam ' Output('###0.###',GetRecordListField#('Tools',ThisRecordListKey#,'Diam')) ' in)' EOL
  NextRecordListItem
  ' ' EOL
 RETURN

G10 style WFO List Example

This example shows a work fixture offset list ordered by ascending WFO number designation, regardless of the order of WFO use. It avoids the common issue of multiple nested eachop loops which can cause a significant delay in post processing.

 doG10_WFOList:
  {///////}
  {I moved this section into progstart to fully utilize another eachop loop and save time}
   EachOp
    SetRecordListFieldBool('wfoList',csPartNum#,'LWord',gtPart6?)
    {SetWfoCS} {ONLY NEEDED IF IN PROGSTART}
    SetRecordListFieldNum('wfoList',csPartNum#,'WFONumInListWFO',doWFONumInList#)
    {SetG92CS} {ONLY NEEDED IF IN PROGSTART}
    SetRecordListFieldNum('wfoList',csPartNum#,'WFONumInListD',doWFONumInList#)
    SetRecordListFieldNum('wfoList',csPartNum#,'csOffsetX',CSOffsetX#)
    SetRecordListFieldNum('wfoList',csPartNum#,'csOffsetY',CSOffsetY#)
    SetRecordListFieldNum('wfoList',csPartNum#,'csOffsetZ',CSOffsetZ#)
   NextOp
  {\\\\\\\}
  EachRecordListItem('wfoList')
   SeqC 'G90G10'
   {doLWord}
   IF GetRecordListField?('wfoList',ThisRecordListKey#,'LWord')
    'L20'
   ELSE
    'L2'
   END  
   'P'
   IF WFOCS?
    Output('5',GetRecordListField#('wfoList',ThisRecordListKey#,'WFONumInListWFO'))
   ELSE
    Output('5',GetRecordListField#('wfoList',ThisRecordListKey#,'WFONumInListD'))
   END
   IF MetricOutput?
    'X' Output('X', GetRecordListField#('wfoList',ThisRecordListKey#,'csOffsetX') + Num#('274.9804') )
    'Y' Output('Y', GetRecordListField#('wfoList',ThisRecordListKey#,'csOffsetY') + Num#('-175.006') )
    'Z' Output('Z', GetRecordListField#('wfoList',ThisRecordListKey#,'csOffsetZ') + Num#('-634.98222') )
   ELSE
    'X' Output('X', GetRecordListField#('wfoList',ThisRecordListKey#,'csOffsetX') + Num#('10.826') )
    'Y' Output('Y', GetRecordListField#('wfoList',ThisRecordListKey#,'csOffsetY') + Num#('-6.89') )
    'Z' Output('Z', GetRecordListField#('wfoList',ThisRecordListKey#,'csOffsetZ') + Num#('-24.9993') )
   END
   'B0.C0.' EOL
  NextRecordListItem
 RETURN
 gtPart6?:
  ReturnBool GreaterThan? PartNum# Num#('6') OR GreaterThan? csPartNum# Num#('6')
 RETURN
 doWFONumInList#:
  IF GreaterThan? PartNum# Num#('6') OR GreaterThan? csPartNum# Num#('6')
   IF WFOCS?
    ReturnNum SUB# csPartNum# Num#('6')
   ELSE
    ReturnNum SUB# PartNum# Num#('6')
   END
  ELSE
   IF WFOCS?
    ReturnNum SUB# csPartNum# Num#('0')
   ELSE
    ReturnNum SUB# PartNum# Num#('0')
   END
  END
 RETURN