GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmPrintUtils.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
24#ifndef _GEMA_PRINT_UTILS_H_
25#define _GEMA_PRINT_UTILS_H_
26
27#include "gmLog.h"
28
29class GmValueInfo;
30class GmValueAccessor;
31class GmCellAccessor;
32class GmGaussAccessor;
33class GmCellMesh;
34class GmElementMesh;
35class GmPCR;
36
37struct lua_State;
38class LuaTable;
39class Unit;
40
77
78
81{
82public:
85 : _logger(logger), _level(level), _options(opt), _firstGhostIndex(-1) {}
86
88 void setOption(GmPrintUtilsFlags opt, bool mode) { _options = mode ? (_options | opt) : (_options & ~opt); }
89
91 void setOptions(int options) { _options = options; }
92
99 void setFirstGhostIndex(int index) { _firstGhostIndex = index; }
100
101 GmValueAccessor* valueAccessorForStringColumn(QString title, const QStringList& data, int width);
102
103 void printValueTable(const QList<GmValueAccessor*>& dataList, QString title = "", const QList<int>& columnWidths = QList<int>(), const GmPCR* pcr = NULL);
104 void printCellTable (const GmCellMesh* mesh, const QList<GmCellAccessor* >& dataList, QString title = "",
105 const QList<int>& columnWidths = QList<int>(), int ip = -1);
106 void printGaussTable(const GmElementMesh* mesh, const QList<GmGaussAccessor* >& dataList, QString title = "",
107 const QList<int>& columnWidths = QList<int>());
108
109
110 static bool parseValueIds (lua_State* L, int index, QString fname, QStringList& valueList, QList<Unit>& unitList);
111 static QList<int> parseColumnWidths(lua_State* L, int index, QString fname, int ncol);
112 static void parsePrintOptions(lua_State* L, int index, QString fname, int& options, int* state);
113
114 static QString leftStr (QString str, int width, bool clip = false);
115 static QString centerStr(QString str, int width, bool clip = false);
116 static QString rightStr (QString str, int width, bool clip = false);
117 static QString quoteStr (QString str, QString separator = ",");
118
119 static void progressBar(int i, int size, int& mark, const GmLogCategory& logger, int freq = 10);
120
121protected:
122 template <class A> GMC_API_EXPORT void addDataColumnSizes (const QList<A*>& dataList, const QList<int>& colWidths, QList<int>& sizes);
123 template <class A> GMC_API_EXPORT int printColumnHeaders (QString title, const QStringList& extraCols, const QList<A*>& dataList,
124 const QList<int>& colWidths);
125 template <class A> GMC_API_EXPORT void buildReverseConstMaps(const QList<A*>& dataList, QList<QMap<double, QString> >& revConstMapList);
126
127 static void checkOption(LuaTable& table, const char* field, int& options, int flag);
128
132 QString center(QString val, int size) { return centerStr(val, size, _options & GM_PRINT_CLIP_TITLES); }
133
138};
139
140#endif
141
The GmCellAccessor class is a proxy object to a value accesor implementing a more convenient interfac...
Definition gmCellAccessor.h:67
Base interface class for CellMesh type plugins.
Definition gmCellMesh.h:40
Base interface for FEM (finite element) meshes.
Definition gmElementMesh.h:42
The GmGaussAccessor class is a proxy object to a value accessor implementing a more convenient interf...
Definition gmGaussAccessor.h:39
Class representing a category with multiple logging levels.
Definition gmLog.h:58
Base interface class for Partition-Color-Renumber object plugins.
Definition gmPCR.h:54
Groups utilitary routines for pretty printing data.
Definition gmPrintUtils.h:81
void setOptions(int options)
Sets all printing options.
Definition gmPrintUtils.h:91
QString center(QString val, int size)
Given a string, returns a new string with the given size, where val is centered on the available spac...
Definition gmPrintUtils.h:132
int _options
Print options, stores a bit field with PrintFlags options that are turned on.
Definition gmPrintUtils.h:136
int _firstGhostIndex
Index used by printValueTable() to identify which table lines, if any, refer to ghost nodes....
Definition gmPrintUtils.h:137
void setOption(GmPrintUtilsFlags opt, bool mode)
Enable or desable a printing option.
Definition gmPrintUtils.h:88
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.
Definition gmPrintUtils.h:84
void setFirstGhostIndex(int index)
Informs the printer about the border between normal and ghost nodes.
Definition gmPrintUtils.h:99
const GmLogCategory & _logger
The logger used to print messages.
Definition gmPrintUtils.h:134
GmLogLevel _level
The log level used to print messages.
Definition gmPrintUtils.h:135
Interface class for accessing and setting values from an "indexable" collection of values.
Definition gmValueAccessor.h:60
Auxiliar class used to store the definition of a value. It can be used to store informations about st...
Definition gmValueInfo.h:132
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35
Declaration of support functions and macros for information logging.
GmLogLevel
Available log levels list.
Definition gmLog.h:36
@ GM_EXT_INFO
Extended information. Probably more than you wanted.
Definition gmLog.h:38
GmPrintUtilsFlags
Set of combinable options controlling the behaviour of print functions.
Definition gmPrintUtils.h:43
@ GM_PRINT_TRAILLER
Should we add a closing trailler line to the table? Default = false.
Definition gmPrintUtils.h:59
@ GM_PRINT_UNITS
Should we print units in column title? Default = true.
Definition gmPrintUtils.h:44
@ GM_PRINT_MARK_GHOST_NODES
Should we mark line numbers (with a '|' prefix) in printValueTable() or cell node numbers in printCel...
Definition gmPrintUtils.h:57
@ GM_PRINT_CELL_ACTIVE
Should we add a column telling if the cell is active or not for cell meshes? Default = false.
Definition gmPrintUtils.h:54
@ GM_PRINT_LINE_NUMBERS
Should we print line numbers on the left margin? Default = true.
Definition gmPrintUtils.h:48
@ GM_PRINT_UNITS_ON_SECOND_LINE
Should we print units in the header in a separate line? Default = false.
Definition gmPrintUtils.h:45
@ GM_PRINT_HEADER_TITLE
Should we print a title in the header, for the entire table? Default = false.
Definition gmPrintUtils.h:58
@ GM_PRINT_CELL_PROPERTY_NAMES
Should we add a columns with property names for cell meshes? Default = true.
Definition gmPrintUtils.h:52
@ GM_PRINT_NODE_GEOMETRY
Should we print common geometry nodes? When false, filters rows in printValueTable() or cell nodes in...
Definition gmPrintUtils.h:55
@ GM_PRINT_INTERNAL_ORDER
Should we order the rows in the table according to the internal id (instead of the model id)?...
Definition gmPrintUtils.h:64
@ GM_PRINT_CELL_TYPE
Should we add a type column for cell meshes / Gauss attributes? Default = true.
Definition gmPrintUtils.h:50
@ GM_PRINT_CLIP_TITLES
Should we clip column titles when the user gave us a width and the title is bigger than that?...
Definition gmPrintUtils.h:49
@ GM_PRINT_CELL_EVAL_POINT
Should we add a evaluation point column when EVAL_FUNCTIONS = true for cell meshes or for Gauss Attri...
Definition gmPrintUtils.h:53
@ GM_PRINT_CELL_NODES
Should we add a node column for cell meshes? Default = true.
Definition gmPrintUtils.h:51
@ GM_PRINT_CONSTMAP
Should we try to translate values back to strings when a scalar data column has an associated const m...
Definition gmPrintUtils.h:61
@ GM_PRINT_DEF_AS_NIL
Should we print default values as 'nil'? Default = false.
Definition gmPrintUtils.h:47
@ GM_PRINT_NODE_GHOST
Should we print ghost nodes? When false, filters rows in printValueTable() or cell nodes in printCell...
Definition gmPrintUtils.h:56
@ GM_PRINT_ID
Should we add a node or cell Ids column? For node ids, ghost nodes are represented as negative number...
Definition gmPrintUtils.h:62
@ GM_PRINT_INTERNAL_ID
Should we add an internal (renumbered but 1-based) node/cell id column? For node ids,...
Definition gmPrintUtils.h:63
@ GM_PRINT_DEFAULT
A tag to request that the options should be filled with the default.
Definition gmPrintUtils.h:72
@ GM_PRINT_ACTIVEONLY
Should we print only active cells? Default = true.
Definition gmPrintUtils.h:60
@ GM_PRINT_EVAL_FUNCTIONS
Should we evaluate functions or do we print its name? Default = false.
Definition gmPrintUtils.h:46
@ GM_PRINT_USER
A mark to set the first 'user' option available. This value should be updated whenever adding options...
Definition gmPrintUtils.h:68