1 // Gmsh - Copyright (C) 1997-2021 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef CONTEXT_H
7 #define CONTEXT_H
8 
9 #include <vector>
10 #include <map>
11 #include <string>
12 
13 #define NUM_SOLVERS 10
14 
15 class GamePad;
16 
17 struct contextMeshOptions {
18   // mesh algorithms
19   int optimize, optimizeNetgen, refineSteps;
20   int smoothCrossField, crossFieldClosestPoint;
21   double lcFactor, randFactor, randFactor3d, lcIntegrationPrecision;
22   double optimizeThreshold, normals, tangents, explode, angleSmoothNormals;
23   double allowSwapEdgeAngle;
24   double qualityInf, qualitySup, radiusInf, radiusSup;
25   double lcMin, lcMax, toleranceEdgeLength, toleranceInitialDelaunay;
26   double anisoMax, smoothRatio;
27   int lcFromPoints, lcFromParametricPoints, lcFromCurvature, lcFromCurvatureIso;
28   int lcExtendFromBoundary;
29   int nbSmoothing, algo2d, algo3d, algoSubdivide, algoSwitchOnFailure;
30   int algoRecombine, recombineAll, recombineOptimizeTopology;
31   int recombine3DAll, recombine3DLevel, recombine3DConformity;
32   int flexibleTransfinite, maxRetries;
33   int order, secondOrderLinear, secondOrderIncomplete;
34   int meshOnlyVisible, meshOnlyEmpty;
35   int minCircleNodes, minCurveNodes;
36   int hoOptimize, hoPeriodic, hoNLayers, hoPrimSurfMesh, hoIterMax, hoPassMax;
37   int hoDistCAD, hoSavePeriodic;
38   double hoThresholdMin, hoThresholdMax, hoPoissonRatio;
39   bool hoNewFastCurvingAlgo;
40   int hoCurveOuterBL;
41   double hoMaxRho, hoMaxAngle, hoMaxInnerAngle;
42   int NewtonConvergenceTestXYZ, maxIterDelaunay3D;
43   int ignorePeriodicityMsh2, ignoreParametrizationMsh4, boundaryLayerFanElements;
44   int maxNumThreads1D, maxNumThreads2D, maxNumThreads3D;
45   double angleToleranceFacetOverlap, toleranceReferenceElement;
46   int renumber, compoundClassify, reparamMaxTriangles;
47   double compoundLcFactor;
48   unsigned int randomSeed;
49   int nLayersPerGap;
50   double gradation;
51   int quadqsSizemapMethod, quadqsTopoOptimMethods;
52   double quadqsRemeshingBoldness, quadqsScalingOnTriangulation;
53   int oldInitialDelaunay2D;
54   // mesh IO
55   int fileFormat, firstElementTag, firstNodeTag;
56   double mshFileVersion, medFileMinorVersion, scalingFactor;
57   int medImportGroupsOfNodes, medSingleModel;
58   int saveAll, saveTri, saveGroupsOfNodes, saveGroupsOfElements;
59   int readGroupsOfElements;
60   int binary, bdfFieldFormat;
61   int unvStrictFormat, stlRemoveDuplicateTriangles, stlOneSolidPerSurface;
62   double stlLinearDeflection, stlAngularDeflection;
63   int saveParametric, saveTopology, zoneDefinition;
64   int saveElementTagType, switchElementTags;
65   int cgnsImportIgnoreBC, cgnsImportIgnoreSolution, cgnsImportOrder;
66   int cgnsConstructTopology, cgnsExportCPEX0045, cgnsExportStructured;
67   int preserveNumberingMsh2, createTopologyMsh2;
68   // partitioning
69   int numPartitions, partitionCreateTopology, partitionCreateGhostCells;
70   int partitionCreatePhysicals, partitionSplitMeshFiles;
71   int partitionSaveTopologyFile, partitionTriWeight, partitionQuaWeight;
72   int partitionTetWeight, partitionHexWeight, partitionLinWeight;
73   int partitionPriWeight, partitionPyrWeight, partitionTrihWeight;
74   int partitionOldStyleMsh2, partitionConvertMsh2;
75   int metisAlgorithm, metisEdgeMatching, metisRefinementAlgorithm;
76   int metisObjective, metisMinConn;
77   double metisMaxLoadImbalance;
78   // mesh display
79   int draw, changed, light, lightTwoSide, lightLines, nodeType;
80   int nodes, lines, triangles, quadrangles, tetrahedra, hexahedra, prisms;
81   int pyramids, trihedra;
82   int surfaceEdges, surfaceFaces, volumeEdges, volumeFaces, numSubEdges;
83   int nodeLabels, lineLabels, surfaceLabels, volumeLabels, qualityType, labelType;
84   double nodeSize, lineWidth;
85   int dual, voronoi, drawSkinOnly, colorCarousel, labelSampling;
86   int smoothNormals, clip;
87 };
88 
89 struct contextGeometryOptions {
90   // geometry algorithms
91   int oldCircle, oldNewreg, oldRuledSurface;
92   int extrudeSplinePoints, extrudeReturnLateral;
93   int autoCoherence;
94   double tolerance, toleranceBoolean, snap[3], transform[3][3], offset[3];
95   int occAutoFix, occAutoEmbed;
96   int occFixDegenerated, occFixSmallEdges, occFixSmallFaces;
97   int occSewFaces, occMakeSolids, occParallel, occBooleanPreserveNumbering;
98   int occBoundsUseSTL, occDisableSTL, occImportLabels, occUnionUnify;
99   int occThruSectionsDegree, occUseGenericClosestPoint;
100   double occScaling;
101   std::string occTargetUnit;
102   int copyMeshingMethod, exactExtrusion;
103   int matchGeomAndMesh;
104   double matchMeshScaleFactor;
105   double matchMeshTolerance;
106   int orientedPhysicals;
107   int reparamOnFaceRobust;
108   // geometry display
109   int draw, light, lightTwoSide, points, curves, surfaces, volumes;
110   int pointLabels, curveLabels, surfaceLabels, volumeLabels, labelType;
111   double pointSize, curveWidth, selectedPointSize, selectedCurveWidth;
112   int pointType, curveType, surfaceType, numSubEdges;
113   double normals, tangents, scalingFactor;
114   int snapPoints;
115   int highlightOrphans, clip, useTransform;
116   int doubleClickedEntityTag;
117   std::string doubleClickedPointCommand, doubleClickedCurveCommand;
118   std::string doubleClickedSurfaceCommand, doubleClickedVolumeCommand;
119 };
120 
121 // The interface-independent context.
122 class CTX {
123 private:
124   static CTX *_instance;
125 
126 public:
127   CTX();
128   ~CTX();
129   void init();
130   static CTX *instance();
131 
132   // for debug purposes only, i.e. JF and CG personal use
133   int debugSurface;
134   // files on the command line and various file names
135   std::vector<std::string> files;
136   std::string bgmFileName, outputFileName, defaultFileName, tmpFileName;
137   std::string sessionFileName, optionsFileName, errorFileName;
138   std::string meshStatReportFileName;
139   // filename of the executable, with full path
140   std::string exeFileName;
141   // the home directory
142   std::string homeDir;
143   // file history
144   std::vector<std::string> recentFiles;
145   // create mesh statistics report (0: do nothing, 1: create, 2: append)
146   int createAppendMeshStatReport;
147   // behavior on error
148   int abortOnError;
149   // should we launch a solver at startup?
150   int launchSolverAtStartup;
151   // save session/option file on exit?
152   int sessionSave, optionsSave;
153   // ask confirmation when overwriting files?
154   int confirmOverwrite;
155   // forced display host:0.0 under X11
156   std::string display;
157   // FLTK theme
158   std::string guiTheme;
159   // FLTK color scheme and max refresh rate
160   int guiColorScheme, guiRefreshRate;
161   // print messages on to the terminal?
162   int terminal;
163   // detached processes (WIN32)?
164   int detachedProcess;
165   // number of graphical windows/tiles
166   int numWindows, numTiles;
167   // text editor command (with included '%s')
168   std::string editor;
169   // pattern of files to watch out for
170   std::string watchFilePattern;
171   // script generator languages ("geo", "py", ...)
172   std::vector<std::string> scriptLang;
173   // show tootips in the GUI?
174   int tooltips;
175   // enable input field scrolling (moving the mouse to change numbers)
176   int inputScrolling;
177   // position and size of various windows in the GUI
178   int glPosition[2], glSize[2], msgSize, menuPosition[2], menuSize[2],
179     detachedMenu;
180   int optPosition[2], visPosition[2], hotPosition[2], clipPosition[2],
181     manipPosition[2];
182   int statPosition[2], ctxPosition[2];
183   int pluginPosition[2], pluginSize[2], fieldPosition[2], fieldSize[2];
184   int fileChooserPosition[2], extraPosition[2], extraSize[2];
185   // use the system menu bar on Mac OS X?
186   int systemMenuBar;
187   // use the native file chooser?
188   int nativeFileChooser;
189   // show standard Gmsh menu in onelab window
190   int showModuleMenu;
191   // use high-resolution opengl graphics (retina Macs)
192   int highResolutionGraphics;
193   // batch mode (-4: lua session, -3: server daemon, -2: check coherence, -1:
194   // write geo, 0: full gfx, 1: 1D mesh, 2: 2D mesh, 3: 3D mesh, 4: adapt mesh,
195   // 5: refine mesh, 6: reclassify mesh)
196   int batch;
197   // batch operations to apply after meshing (1: partition mesh)
198   int batchAfterMesh;
199   // some option for batch processing
200   double batchSomeValue;
201   // initial menu (0: automatic, 1: geom, 2: mesh, 3: solver, 4: post)
202   int initialContext;
203   // show some windows on startup?
204   int showOptionsOnStartup, showMessagesOnStartup;
205   // never popup dialogs in scripts (use default values instead)?
206   int noPopup;
207   // make all windows "non modal"?
208   int nonModalWindows;
209   // clipping plane distance factor
210   double clipFactor;
211   // display border factor (0 = model fits window size exactly)
212   double displayBorderFactor;
213   // do or do not use the trackball for rotations
214   int useTrackball, trackballHyperbolicSheet;
215   // gamepad controller
216   GamePad *gamepad;
217   // point around which to rotate the scene
218   double rotationCenter[3];
219   // rotate around the center of mass instead of rotationCenter[]
220   int rotationCenterCg;
221   // "overall" x, y and z min used for drawing and lc computation
222   double min[3], max[3];
223   // "center of mass" of the current geometry, used for graphics only
224   double cg[3];
225   // characteristic length for the whole problem, measuring the overall bounding
226   // box (used to set tolerances relative to the overall model size)
227   double lc;
228   // double buffer/antialias/stereo graphics?
229   int db, antialiasing, stereo, camera;
230   bool fileread;
231   double eye_sep_ratio, focallength_ratio, camera_aperture;
232   // orthogonal projection?
233   int ortho;
234   // draw the bounding boxes and the rot center?
235   int drawBBox, drawRotationCenter;
236   // draw simplified model during user interaction?
237   int fastRedraw;
238   // small axes options
239   int smallAxes, smallAxesSize, smallAxesPos[2];
240   // large axes options
241   int axes, axesAutoPosition, axesMikado, axesForceValue;
242   double axesPosition[6], axesValue[6], axesTics[3];
243   std::string axesLabel[3], axesFormat[3];
244   // simple dynamic lock (should be a mutex)
245   int lock;
246   // enable alpha blending?
247   int alpha;
248   // mouse2 zoom coefficient
249   double zoomFactor;
250   // draw background gradient?
251   int bgGradient;
252   // draw background image?
253   std::string bgImageFileName;
254   double bgImagePosition[2], bgImageSize[2];
255   int bgImage3d, bgImagePage;
256   // fltk font size (and delta for palette windows)
257   int fontSize, deltaFontSize;
258   // font name, FLTK enum and size for opengl graphics
259   std::string glFont, glFontTitle, glFontEngine;
260   int glFontEnum, glFontEnumTitle, glFontSize, glFontSizeTitle;
261   // font size of messages
262   int msgFontSize;
263   // point/line widths
264   double pointSize, lineWidth;
265   double highResolutionPointSizeFactor;
266   // light options
267   int light[6];
268   double lightPosition[6][4], shine, shineExponent;
269   // clipping plane options
270   double clipPlane[6][4];
271   int clipWholeElements, clipOnlyDrawIntersectingVolume, clipOnlyVolume;
272   // polygon offset options
273   int polygonOffset, polygonOffsetAlways;
274   double polygonOffsetFactor, polygonOffsetUnits;
275   // color scheme
276   int colorScheme;
277   // number of subdivisions for gluQuadrics
278   int quadricSubdivisions;
279   // vector display type and options (for normals, etc.)
280   int vectorType;
281   double arrowRelHeadRadius, arrowRelStemRadius, arrowRelStemLength;
282   // records cpu times for 1-D, 2-D and 3-D mesh generation
283   double meshTimer[3];
284   // dynamic variable tracking if the bbox is currently imposed
285   int forcedBBox;
286   // enable selection/hover/picking using the mouse
287   int mouseSelection, mouseHoverMeshes, pickElements;
288   // invert sense of mouse wheel zoom
289   int mouseInvertZoom;
290   // disable some warnings for expert users?
291   int expertMode;
292 #if defined(HAVE_VISUDEV)
293   // Enable heavy visualization capabilities (for development purpose)
294   int heavyVisu;
295 #endif
296   // dynamic: equal to 1 while gmsh is printing
297   int printing;
298   // hide all unselected entities?
299   int hideUnselected;
300   // temporary storage of rotation, translation, scale (until the GUI
301   // is ready)
302   double tmpRotation[3], tmpTranslation[3], tmpScale[3], tmpQuaternion[4];
303   // geometry options
304   contextGeometryOptions geom;
305   // mesh options
306   contextMeshOptions mesh;
307   // post processing options
308   struct {
309     int draw, link, horizontalScales, binary;
310     int smooth, animCycle, animStep;
311     int combineTime, combineRemoveOrig, combineCopyOptions;
312     int fileFormat, plugins, forceNodeData, forceElementData;
313     int saveMesh, saveInterpolationMatrices;
314     double animDelay;
315     std::string doubleClickedGraphPointCommand;
316     double doubleClickedGraphPointX, doubleClickedGraphPointY;
317     int doubleClickedView;
318   } post;
319   // solver options
320   struct {
321     int plugins, listen;
322     double timeout;
323     std::string socketName, pythonInterpreter, octaveInterpreter;
324     std::string name[NUM_SOLVERS], extension[NUM_SOLVERS];
325     std::string executable[NUM_SOLVERS], remoteLogin[NUM_SOLVERS];
326     int autoSaveDatabase, autoLoadDatabase;
327     int autoArchiveOutputFiles, autoMesh, autoMergeFile;
328     int autoShowViews, autoShowLastStep, autoCheck, showInvisibleParameters;
329   } solver;
330   // print options
331   struct {
332     int fileFormat, epsQuality, epsCompress, epsPS3Shading;
333     int epsOcclusionCulling, epsBestRoot;
334     double epsLineWidthFactor, epsPointSizeFactor;
335     int jpegQuality, jpegSmoothing, geoLabels, geoOnlyPhysicals;
336     int text, texAsEquation, texForceFontSize;
337     double texWidthInMm;
338     int gifDither, gifSort, gifInterlace, gifTransparent;
339     int posElementary, posElement, posGamma, posEta, posSICN, posSIGE, posDisto;
340     int compositeWindows, deleteTmpFiles, background;
341     int width, height;
342     double parameter, parameterFirst, parameterLast, parameterSteps;
343     int pgfTwoDim, pgfExportAxis, pgfHorizBar;
344     std::string parameterCommand;
345     int x3dCompatibility, x3dRemoveInnerBorders;
346     double x3dPrecision, x3dTransparency;
347     int x3dSurfaces, x3dEdges, x3dVertices;
348   } print;
349   // color options
350   struct {
351     unsigned int bg, bgGrad, fg, text, axes, smallAxes;
352     unsigned int ambientLight[6], diffuseLight[6], specularLight[6];
353     struct {
354       unsigned int point, curve, surface, volume;
355       unsigned int selection, highlight[3], projection;
356       unsigned int tangents, normals;
357     } geom;
358     struct {
359       unsigned int node, nodeSup, line, triangle, quadrangle;
360       unsigned int tetrahedron, hexahedron, prism, pyramid, trihedron;
361       unsigned int carousel[20];
362       unsigned int tangents, normals;
363     } mesh;
364   } color;
365   // is the machine big-endian?
366   int bigEndian;
367   // how RGBA values are packed and unpacked into/from an unsigned integer to be
368   // fed to glColor4ubv (depends on machine byte ordering!):
369   unsigned int packColor(int R, int G, int B, int A);
370   int unpackRed(unsigned int X);
371   int unpackGreen(unsigned int X);
372   int unpackBlue(unsigned int X);
373   int unpackAlpha(unsigned int X);
374 };
375 
376 #endif
377