GemaCoreLib
The GeMA Core library
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
GmPrintUtils Class Reference

Groups utilitary routines for pretty printing data. More...

#include <gmPrintUtils.h>

Collaboration diagram for GmPrintUtils:
Collaboration graph
[legend]

Public Member Functions

 GmPrintUtils (const GmLogCategory &logger, GmLogLevel level=GM_EXT_INFO, int opt=GM_PRINT_DEFAULT)
 Constructor receiving the logger and level used to print data, along with print options.
 
void setOption (GmPrintUtilsFlags opt, bool mode)
 Enable or desable a printing option.
 
void setOptions (int options)
 Sets all printing options.
 
void setFirstGhostIndex (int index)
 Informs the printer about the border between normal and ghost nodes. More...
 
GmValueAccessorvalueAccessorForStringColumn (QString title, const QStringList &data, int width)
 Returns an accessor suitable for printing a string column with printValueTable() More...
 
void printValueTable (const QList< GmValueAccessor * > &dataList, QString title="", const QList< int > &columnWidths=QList< int >())
 Prints a table of values where each accessor is a table column, using the object configured logger and options. More...
 
void printCellTable (const GmCellMesh *mesh, const QList< GmCellAccessor * > &dataList, QString title="", const QList< int > &columnWidths=QList< int >(), int ip=-1)
 Prints a table of values where each cell accessor is a table column, using the object configured logger and options. More...
 
void printGaussTable (const GmElementMesh *mesh, const QList< GmGaussAccessor * > &dataList, QString title="", const QList< int > &columnWidths=QList< int >())
 Prints a table of values where each Gauss accessor is a table column, using the object configured logger and options. More...
 
template<class A >
void addDataColumnSizes (const QList< A * > &dataList, const QList< int > &colWidths, QList< int > &sizes)
 Discovers the size of each data column, taking into account the accessor metadata, user defined column widths and object options, and adds them to the size list. More...
 
template<class A >
int printColumnHeaders (QString title, const QStringList &extraCols, const QList< A * > &dataList, const QList< int > &colWidths)
 Prints a set of column headers. More...
 
template<class A >
void buildReverseConstMaps (const QList< A * > &dataList, QList< QMap< double, QString > > &revConstMapList)
 Aux function to build the reverse const maps used when print options include GM_PRINT_CONSTMAP.
 

Static Public Member Functions

static bool parseValueIds (lua_State *L, int index, QString fname, QStringList &valueList, QList< Unit > &unitList)
 Auxilliary function used to parse a table parameter describing values to be printed or saved. More...
 
static QList< int > parseColumnWidths (lua_State *L, int index, QString fname, int ncol)
 Auxilliary function used to parse column sizes.
 
static void parsePrintOptions (lua_State *L, int index, QString fname, int &options, int *state)
 Auxilliary function used to parse print options given in a Lua table. Common code used by print process functions to parse print option tables. More...
 
static void progressBar (int i, int size, int &mark, const GmLogCategory &logger, int freq=10)
 Auxilliary function used to display a progress status of a countable/iterative process. More...
 

Protected Member Functions

template<class A >
GMC_API_EXPORT void addDataColumnSizes (const QList< A * > &dataList, const QList< int > &colWidths, QList< int > &sizes)
 
template<class A >
GMC_API_EXPORT int printColumnHeaders (QString title, const QStringList &extraCols, const QList< A * > &dataList, const QList< int > &colWidths)
 
template<class A >
GMC_API_EXPORT void buildReverseConstMaps (const QList< A * > &dataList, QList< QMap< double, QString > > &revConstMapList)
 
QString center (QString val, int size)
 Given a string, returns a new string with the given size, where val is centered on the available space. If the size of val is greater than size, returns val.
 

Static Protected Member Functions

static void checkOption (LuaTable &table, const char *field, int &options, int flag)
 Aux function used by parsePrintOptions(). If field is present in table, updates options setting or clearing flag.
 

Protected Attributes

const GmLogCategory_logger
 The logger used to print messages.
 
GmLogLevel _level
 The log level used to print messages.
 
int _options
 Print options, stores a bit field with PrintFlags options that are turned on.
 
int _firstGhostIndex
 Index used by printValueTable() to identify which table lines, if any, refer to ghost nodes. A value of -1 (default) means no ghost nodes.
 

Detailed Description

Groups utilitary routines for pretty printing data.

Member Function Documentation

◆ addDataColumnSizes()

template<class A >
void GmPrintUtils::addDataColumnSizes ( const QList< A * > &  dataList,
const QList< int > &  colWidths,
QList< int > &  sizes 
)

Discovers the size of each data column, taking into account the accessor metadata, user defined column widths and object options, and adds them to the size list.

Parameters
dataListThe set of column accessors needed to define column sizes and units.
colWidthsList with user defined column widths
sizesThe list where we are adding sizes

◆ parsePrintOptions()

void GmPrintUtils::parsePrintOptions ( lua_State *  L,
int  index,
QString  fname,
int &  options,
int *  state 
)
static

Auxilliary function used to parse print options given in a Lua table. Common code used by print process functions to parse print option tables.

The following fields are parsed from the Lua table. Each one (except for the state field) corresponds to a flag in GmPrintUtilsFlags (but not all flags are parsed in this function since some of them represent the presence or not of a column and are not given by the option table).

Each table option is a boolean flag or numeric value associated to a table field. When an option is not present in the table its default value will be used. Available options are: 'state' – The state number used to find values when the attribute/ state var has an associated history. Default = 0 (present state) If the state is invalid for an accessor, the default will be used for it. 'units' – Should we print units in column title? Default = true 'unit_line' – Should we print units in the header in a separate line? Default = false 'eval_functions' – Should we evaluate functions or do we print its name? Default = false 'def_nil' – Should we print default values as 'nil'? Default = false 'const_map' – Should we try to translate values back to strings when a scalar data column has an associated const map? 'line_numbers' – Should we print line numbers on the left margin? Default = true 'active_only' – Should we print only active cells? Default = true 'node_geometry' – Should we print common geometry nodes? Default = true 'node_ghost' – Should we print ghost nodes (if they exist)? Default = true 'mark_ghost' – Should we add a '|' between geometry and ghost node numbers? Default = false 'clip_title' – Should we clip column titles when the user gave us a width and the title is bigger than that? Default = true 'header_title' – Should we print a title in the header, for the entire table? Default = false 'trailler' – Should we add a closing trailler line to the table? Default = false

If the supplied table index is not a table, this function will generate an error by calling luaL_error().

Parameters
LThe current Lua state
indexThe position on the Lua stack where the options table can be found
fnameThe called process function name, used for error messages.
optionsInteger filled with the bitwise or of the selected flags.
stateReturns the desiredstate number.

◆ parseValueIds()

bool GmPrintUtils::parseValueIds ( lua_State *  L,
int  index,
QString  fname,
QStringList valueList,
QList< Unit > &  unitList 
)
static

Auxilliary function used to parse a table parameter describing values to be printed or saved.

The parameter containing the values description should be in the Lua stack in the index position. It should be a string with the name of the value to be printed/exported or a list with the names of values. Can be nil.

Optionally, value names can have a suffix surrounded by () with the desired unit (ex: T(K) would ask for a temperature value named T and with values converted, if needed, to Kelvin).

If the parameter at index is nil or missing, the function returns false. On errors, the function does not return, throwing a message using lua_error()

Parameters
LThe Lua state
indexPosition in the stack with the value list description
valueListList filled with value names (stripped from unit definitions)
unitListList with size equal to valueList with defined units or Unit()
fnameThe name of the called function, used on error messages

◆ printCellTable()

void GmPrintUtils::printCellTable ( const GmCellMesh mesh,
const QList< GmCellAccessor * > &  dataList,
QString  title = "",
const QList< int > &  columnWidths = QList<int>(),
int  ip = -1 
)

Prints a table of values where each cell accessor is a table column, using the object configured logger and options.

Parameters
meshThe mesh.
dataListList with accessors giving column values.
titleAn optional title for the table. Will be printed only if the object options contain GM_PRINT_HEADER_TITLE.
columnWidthsOptional list containing column widths for the columns in dataList. If empty, each column will have its size defined by its info object. A value of 0 also means that the size should be calculated by the function.
ipWhen the option to evaluate functions is enabled, the ip parameter defines the integration point index where the function will be eveluated, using the DEFAULT integration rule. A value of -1 defines that the evaluation will be made at the cell centroid and is the ONLY option for cell (and not element) meshes. For heterogeneous meshes, if the requested integration point is not valid for the element, an "NA" will be printed.

◆ printColumnHeaders()

template<class A >
int GmPrintUtils::printColumnHeaders ( QString  title,
const QStringList extraCols,
const QList< A * > &  dataList,
const QList< int > &  colWidths 
)

Prints a set of column headers.

Parameters
titleAn optional title for the table. Will be printed only if the object options contains GM_PRINT_HEADER_TITLE.
extraColsSet of additional column names added to the beggining of the header
dataListThe set of column accessors needed to define data column headers and units.
colWidthsList with column widths (extra columns + data columns)
Returns
Returns the global table width, as specified by colWidths

◆ printGaussTable()

void GmPrintUtils::printGaussTable ( const GmElementMesh mesh,
const QList< GmGaussAccessor * > &  dataList,
QString  title = "",
const QList< int > &  columnWidths = QList<int>() 
)

Prints a table of values where each Gauss accessor is a table column, using the object configured logger and options.

When requesting that integration points be printed (by setting GM_PRINT_CELL_EVAL_POINT in the options object), if the data columns do NOT share the seme set of integration rules, the point will not be printed and "Multi rule sets" will be printed instead

Parameters
meshThe mesh.
dataListList with accessors giving column values.
titleAn optional title for the table. Will be printed only if the object options contain GM_PRINT_HEADER_TITLE.
columnWidthsOptional list containing column widths for the columns in dataList. If empty, each column will have its size defined by its info object. A value of 0 also means that the size should be calculated by the function.

◆ printValueTable()

void GmPrintUtils::printValueTable ( const QList< GmValueAccessor * > &  dataList,
QString  title = "",
const QList< int > &  columnWidths = QList<int>() 
)

Prints a table of values where each accessor is a table column, using the object configured logger and options.

If in the object options GM_PRINT_MARK_GHOST_NODES is true or GM_PRINT_NODE_GEOMETRY is false or GM_PRINT_NODE_GHOST is false, a call to setFirstGhostIndex() should have been made prior to this call to printValueTable(). Of course those flasgs only make sense if the mesh contains ghost nodes.

Parameters
dataListList with accessors giving column values. If you want to include a string column in the table, please use valueAccessorForStringColumn() to create a column accessor for a string list.
titleAn optional title for the table. Will be printed only if the object options contain GM_PRINT_HEADER_TITLE.
columnWidthsOptional list containing column widths. If empty, each column will have its size defined by its info object. A value of 0 also means that the size should be calculated by the function.

◆ progressBar()

void GmPrintUtils::progressBar ( int  i,
int  size,
int &  mark,
const GmLogCategory logger,
int  freq = 10 
)
static

Auxilliary function used to display a progress status of a countable/iterative process.

Parameters
iThe current iteration.
sizeThe total number of iterations of the process.
markThe current mark to reach to display status.
loggerThe logger used to display status.
freqthe frequency of displaying the status (default = 10, i.e display status at each 10% of the process).

◆ setFirstGhostIndex()

void GmPrintUtils::setFirstGhostIndex ( int  index)
inline

Informs the printer about the border between normal and ghost nodes.

This information is needed by printValueTable() whenever the accessors in the column data list belong to a mesh that supports ghost nodes. A value of -1 (the default) means that the mesh has no ghost nodes.

◆ valueAccessorForStringColumn()

GmValueAccessor * GmPrintUtils::valueAccessorForStringColumn ( QString  title,
const QStringList data,
int  width 
)

Returns an accessor suitable for printing a string column with printValueTable()

Receives as parameters the column title, the string list with the column values and the desired column width.

IMPORTANT: The accessor returned by this function should be used ONLY as a parameter to printValueTable(). PLEASE, do not use it in any other way. REALLY!

Please remember to deallocate the accessor after its use.


The documentation for this class was generated from the following files: