omdl
v0.9.5
OpenSCAD Mechanical Design Library
|
Table data type and operations. More...
Files | |
file | table.scad |
Table data structure and operations. | |
Separate table data | |
function | table_get_row_index (r, ri) |
Get the table row index that matches a table row identifier. More... | |
function | table_get_row (r, ri) |
Get the table row that matches a table row identifier. More... | |
function | table_get_column_index (c, ci) |
Get the table column index that matches a table column identifier. More... | |
function | table_get_column (c, ci) |
Get the table column that matches a table column identifier. More... | |
function | table_get_value (r, c, ri, ci) |
Get the table cell value for a specified row and column identifier. More... | |
function | table_get_columns (r, c, ci) |
Form a list of a select column across all table rows. More... | |
function | table_get (r, c, ri, ci) |
Get a row, a column, or a specific cell value from a table. More... | |
function | table_get_row_ids (r) |
Form a list of all table row identifiers. More... | |
function | table_get_column_ids (c) |
Form a list of all table column identifiers. More... | |
function | table_exists (r, c, ri, ci) |
Test the existence of a table row identifier, table column identifier, or both. More... | |
function | table_get_size (r, c) |
Get the size of a table. More... | |
function | table_get_copy (r, c, rs, cs) |
Create a new matrix from select rows and columns of a table. More... | |
function | table_get_sum (r, c, rs, cs) |
Sum select rows and columns of a table. More... | |
function | table_errors (r, c) |
Perform basic format checks on a table and return errors. More... | |
module | table_check (r, c, verbose=false) |
Perform basic format checks on a table and output errors to console. More... | |
module | table_dump (r, c, rs, cs, number=true) |
Dump a table to the console. More... | |
module | table_dump_getters (r, c, tr="table_rows", tc="table_cols", ri="ri", ci="ci", vri=false, vci=false, name="get_helper", append=false, comment=0, verbose=false) |
Dump table getter functions to the console. More... | |
module | table_write (r, c, rs, cs, number=false, heading_id=true, heading_text=false, fs="^", thn="idx", index_tags=empty_lst, row_id_tags=["b"], value_tags=empty_lst) |
Write formatted map entries to the console. More... | |
Combined table data | |
function | ctable_get (t, ri, ci) |
Get a row, a column, or a specific cell value from a table. More... | |
function | ctable_exists (t, ri, ci) |
Test the existence of a table row identifier, table column identifier, or both. More... | |
function | ctable_get_size (t) |
Get the size of a table. More... | |
function | ctable_errors (t) |
Perform basic format checks on a table and return errors. More... | |
Table data type and operations.
Requires: |
---|
include <omdl-base.scad>; |
The table functions were originally coded with the row and column data as separate parameters. Some equivalent functions are provided that accept the row and column data as a single combined parameter, where t = [r, c];
for convenience and are prefaced with the letter 'c'.
Table use script
Table use script output
function ctable_errors | ( | t | ) |
Perform basic format checks on a table and return errors.
t | <datastruct-list-2> A list [<table>, <map>], [r, c], of the row data matrix (C-columns x R-rows) and column identifier matrix (2 x C-columns). |
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
Check that: (1) the first table column identifier is 'id'. (2) Make sure that each row has the same number of columns as defined in the columns vector. (3) Make sure that there are no repeating column identifiers. (4) Make sure that there are no repeating row identifiers. When there are no errors, the empty_lst is returned.
function ctable_exists | ( | t | , |
ri | , | ||
ci | |||
) |
Test the existence of a table row identifier, table column identifier, or both.
t | <datastruct-list-2> A list [<table>, <map>], [r, c], of the row data matrix (C-columns x R-rows) and column identifier matrix (2 x C-columns). |
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
ri | <string> The row identifier. |
ci | <string> The column identifier. |
The functions can be used to check for a row or a column identifier alone, or can be use to check for the existence of a specific row and column combination.
function ctable_get | ( | t | , |
ri | , | ||
ci | |||
) |
Get a row, a column, or a specific cell value from a table.
t | <datastruct-list-2> A list [<table>, <map>], [r, c], of the row data matrix (C-columns x R-rows) and column identifier matrix (2 x C-columns). |
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
ri | <string> The row identifier. |
ci | <string> The column identifier. |
[ri, ci]
when both ri
and ci
are defined. (2) The row <list-R> when only ri
is defined. (3) The column <list-C> when only ci
is defined. (4) Returns undef when the specified row or column identifier is not present in the table or when both are undefined.This function combines the behavior of several other table access functions dependent on the supplied parameters.
Example
function ctable_get_size | ( | t | ) |
Get the size of a table.
t | <datastruct-list-2> A list [<table>, <map>], [r, c], of the row data matrix (C-columns x R-rows) and column identifier matrix (2 x C-columns). |
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
The size is reported as: (1) The number of rows when only the r
parameter is specified. (2) The number of columns when only the c
parameter is specified. (3) The (r * columns) when both parameters are specified.
module table_check | ( | r | , |
c | , | ||
verbose | = false |
||
) |
Perform basic format checks on a table and output errors to console.
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
verbose | <boolean> Be verbose during check. |
Check that: (1) the first table column identifier is 'id'. (2) Make sure that each row has the same number of columns as defined in the columns vector. (3) Make sure that there are no repeating column identifiers. (4) Make sure that there are no repeating row identifiers.
Definition at line 594 of file table.scad.
module table_dump | ( | r | , |
c | , | ||
rs | , | ||
cs | , | ||
number | = true |
||
) |
Dump a table to the console.
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
rs | <string-list> A list of selected row identifiers. |
cs | <string-list> A list of selected column identifiers. |
number | <boolean> Number the rows. |
Output each table row to the console. To output only select rows and columns, assign the desired identifiers to rs
and cs
. For example to output only the column identifiers 'c1' and 'c2', assign cs = ["c1", "c2"]
.
Definition at line 673 of file table.scad.
module table_dump_getters | ( | r | , |
c | , | ||
tr | = "table_rows" , |
||
tc | = "table_cols" , |
||
ri | = "ri" , |
||
ci | = "ci" , |
||
vri | = false , |
||
vci | = false , |
||
name | = "get_helper" , |
||
append | = false , |
||
comment | = 0 , |
||
verbose | = false |
||
) |
Dump table getter functions to the console.
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
tr | <string> The table row data matrix variable name. |
tc | <string> The table column identifier matrix variable name. |
ri | <string | value> The row identifier variable name or value. |
ci | <string | value> The column identifier variable name or value. |
vri | <boolean> The row identifier ri is a value. |
vci | <boolean> The column identifier ci is a value. |
name | <string> The getter function name. |
append | <boolean> Append id to names. |
comment | <integer> Output comment mode {0, 1, 2}. |
verbose | <boolean> Be verbose. |
Output getter functions for a table to the console. The resulting functions can be used within scripts to access table data.
Example
Definition at line 766 of file table.scad.
function table_errors | ( | r | , |
c | |||
) |
Perform basic format checks on a table and return errors.
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
Check that: (1) the first table column identifier is 'id'. (2) Make sure that each row has the same number of columns as defined in the columns vector. (3) Make sure that there are no repeating column identifiers. (4) Make sure that there are no repeating row identifiers. When there are no errors, the empty_lst is returned.
function table_exists | ( | r | , |
c | , | ||
ri | , | ||
ci | |||
) |
Test the existence of a table row identifier, table column identifier, or both.
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
ri | <string> The row identifier. |
ci | <string> The column identifier. |
The functions can be used to check for a row or a column identifier alone, or can be use to check for the existence of a specific row and column combination.
function table_get | ( | r | , |
c | , | ||
ri | , | ||
ci | |||
) |
Get a row, a column, or a specific cell value from a table.
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
ri | <string> The row identifier. |
ci | <string> The column identifier. |
[ri, ci]
when both ri
and ci
are defined. (2) The row <list-R> when only ri
is defined. (3) The column <list-C> when only ci
is defined. (4) Returns undef when the specified row or column identifier is not present in the table or when both are undefined.This function combines the behavior of several other table access functions dependent on the supplied parameters.
Example
function table_get_column | ( | c | , |
ci | |||
) |
Get the table column that matches a table column identifier.
c | <map> The table column identifier matrix (2 x C-columns). |
ci | <string> The column identifier. |
function table_get_column_ids | ( | c | ) |
Form a list of all table column identifiers.
c | <map> The table column identifier matrix (2 x C-columns). |
This functions assumes the first element of each table column to be the column identifier.
function table_get_column_index | ( | c | , |
ci | |||
) |
Get the table column index that matches a table column identifier.
c | <map> The table column identifier matrix (2 x C-columns). |
ci | <string> The column identifier. |
function table_get_columns | ( | r | , |
c | , | ||
ci | |||
) |
Form a list of a select column across all table rows.
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
ci | <string> The column identifier. |
function table_get_copy | ( | r | , |
c | , | ||
rs | , | ||
cs | |||
) |
Create a new matrix from select rows and columns of a table.
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
rs | <string-list> A list of selected row identifiers. |
cs | <string-list> A list of selected column identifiers. |
function table_get_row | ( | r | , |
ri | |||
) |
Get the table row that matches a table row identifier.
r | <table> The table row data matrix (C-columns x R-rows). |
ri | <string> The row identifier. |
function table_get_row_ids | ( | r | ) |
Form a list of all table row identifiers.
r | <table> The table row data matrix (C-columns x R-rows). |
This functions assumes the first element of each table row to be the row identifier, as enforced by the table_check(). As an alternative, the function table_get_columns(), of the form table_get_columns(r, c, id), may be used without this assumption.
function table_get_row_index | ( | r | , |
ri | |||
) |
Get the table row index that matches a table row identifier.
r | <table> The table row data matrix (C-columns x R-rows). |
ri | <string> The row identifier. |
function table_get_size | ( | r | , |
c | |||
) |
Get the size of a table.
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
The size is reported as: (1) The number of rows when only the r
parameter is specified. (2) The number of columns when only the c
parameter is specified. (3) The (r * columns) when both parameters are specified.
function table_get_sum | ( | r | , |
c | , | ||
rs | , | ||
cs | |||
) |
Sum select rows and columns of a table.
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
rs | <string-list> A list of selected row identifiers. |
cs | <string-list> A list of selected column identifiers. |
function table_get_value | ( | r | , |
c | , | ||
ri | , | ||
ci | |||
) |
Get the table cell value for a specified row and column identifier.
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
ri | <string> The row identifier. |
ci | <string> The column identifier. |
[ri, ci]
. If either identifier does not exists, returns undef. module table_write | ( | r | , |
c | , | ||
rs | , | ||
cs | , | ||
number | = false , |
||
heading_id | = true , |
||
heading_text | = false , |
||
fs | = "^" , |
||
thn | = "idx" , |
||
index_tags | = empty_lst , |
||
row_id_tags | = ["b"] , |
||
value_tags | = empty_lst |
||
) |
Write formatted map entries to the console.
r | <table> The table row data matrix (C-columns x R-rows). |
c | <map> The table column identifier matrix (2 x C-columns). |
rs | <string-list> A list of selected row identifiers. |
cs | <string-list> A list of selected column identifiers. |
number | <boolean> Number the rows. |
heading_id | <boolean> Output table heading identifiers. |
heading_text | <boolean> Output table heading description text. |
fs | <string> A field separator. |
thn | <string> Column heading for numbered row output. |
index_tags | <string-list> List of html formatting tags. |
row_id_tags | <string-list> List of html formatting tags. |
value_tags | <string-list> List of html formatting tags. |
Output each table row to the console. To output only select rows and columns, assign the desired identifiers to rs
and cs
. For example to output only the column identifiers 'c1' and 'c2', assign cs = ["c1", "c2"]
. The output can then be processed to produce documentation tables as shown in the example below.
Table write script
Table write script output
Table write table
key | value |
---|---|
id | row identifier |
ht | head type |
td | thread diameter |
tl | thread length |
hd | head diameter |
hl | head length |
nd | nut width |
nl | nut length |
Table write table
id | ht | td | tl | hd | hl | nd | nl |
---|---|---|---|---|---|---|---|
m3r08r | r | 3 | 8 | 5.5 | 3 | 5.5 | 25.4 |
m3r14r | r | 3 | 14 | 5.5 | 3 | 5.5 | 31.75 |
m4r16s | s | 4 | 16 | 4.5 | 4 | 5.5 | 38.1 |
m5r20h | h | 5 | 20 | 6 | 5 | 5.5 | 44.45 |
Definition at line 1182 of file table.scad.