gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Context.cpp
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 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 #include <stdlib.h>
7 #include <string.h>
8 #include "GmshConfig.h"
9 #include "Context.h"
10 #include "OS.h"
11 #include "GamePad.h"
12 
13 #if defined(HAVE_FLTK)
14 #include <FL/Fl.H>
15 #endif
16 
18 {
19  // Warning: this does not initialize all the variables; for all the options
20  // that have default values that job is left to InitOptions() - which calls
21  // init()
22  init();
23 }
24 
26 {
27  if(gamepad) delete gamepad;
28 }
29 
30 void CTX::init()
31 {
32  // initialize everything that has no default value in DefaultOptions.h
33  debugSurface = -1;
34 
35  short int word = 0x0001;
36  char *byte = (char*)&word;
37  bigEndian = (byte[0] ? 0 : 1);
38 
39  if(homeDir.empty()) homeDir = GetEnvironmentVar("GMSH_HOME");
40 #if defined(WIN32)
41  if(homeDir.empty()) homeDir = GetEnvironmentVar("APPDATA");
42 #else
43  if(homeDir.empty()) homeDir = GetEnvironmentVar("HOME");
44 #endif
45  if(homeDir.empty()) homeDir = GetEnvironmentVar("TMP");
46  if(homeDir.empty()) homeDir = GetEnvironmentVar("TEMP");
47  int len = homeDir.size();
48  if(len && homeDir[len - 1] != '/') homeDir += "/";
49 
50  batch = batchAfterMesh = 0;
51  batchSomeValue = 0;
52  outputFileName = "";
53  bgmFileName = "";
56  lc = 1.;
57  min[0] = min[1] = min[2] = max[2] = 0.;
58  max[0] = max[1] = 1.; // for nice view when adding point in new model
59  cg[0] = cg[1] = cg[2] = 0.;
60  polygonOffset = 0;
61  printing = 0;
62  meshTimer[0] = meshTimer[1] = meshTimer[2] = 0.;
64  pickElements = 0;
65  geom.draw = 1;
66  mesh.draw = 1;
67  post.draw = 1;
68  post.combineTime = 0; // try to combineTime views at startup
69  lock = 0; // very primitive locking
70  fileread = false;
71 
72  geom.autoExtrude = 0; // FIXME: temporary for auto-extrude testing
73 
74 #if defined(HAVE_FLTK)
75  glFontEnum = FL_HELVETICA;
76 #else
77  glFontEnum = -1;
78 #endif
79  forcedBBox = 0;
80  hideUnselected = 0;
81  numWindows = numTiles = 1;
82  deltaFontSize = 0;
83  recentFiles.resize(10);
84  gamepad = nullptr;
86  terminal = 0;
87  detachedProcess = 1;
88 
89  // need to initialize these too, since the corresponding opt_XXX routines use
90  // the current value to detect changes
91  mesh.changed = 0;
99  mesh.numSubEdges = 0;
100  mesh.colorCarousel = 0;
101  mesh.saveTri = 0;
102  color.mesh.tangents = color.mesh.tetrahedron = color.mesh.triangle = 0;
103  color.mesh.prism = color.mesh.pyramid = color.mesh.hexahedron = color.mesh.trihedron = 0;
104  color.mesh.tangents = color.mesh.line = color.mesh.quadrangle = 0;
105  for (int i = 0; i < 20; i++)
106  color.mesh.carousel[i] = 0;
117  mesh.lightLines = 2;
118 }
119 
120 CTX *CTX::_instance = nullptr;
121 
123 {
124  if(!_instance) _instance = new CTX();
125  return _instance;
126 }
127 
128 unsigned int CTX::packColor(int R, int G, int B, int A)
129 {
130  if(bigEndian)
131  return ( (unsigned int)((R)<<24 | (G)<<16 | (B)<<8 | (A)) );
132  else
133  return ( (unsigned int)((A)<<24 | (B)<<16 | (G)<<8 | (R)) );
134 }
135 
136 int CTX::unpackRed(unsigned int X)
137 {
138  if(bigEndian)
139  return ( ( (X) >> 24 ) & 0xff );
140  else
141  return ( (X) & 0xff );
142 }
143 
144 int CTX::unpackGreen(unsigned int X)
145 {
146  if(bigEndian)
147  return ( ( (X) >> 16 ) & 0xff );
148  else
149  return ( ( (X) >> 8 ) & 0xff );
150 }
151 
152 int CTX::unpackBlue(unsigned int X)
153 {
154  if(bigEndian)
155  return ( ( (X) >> 8 ) & 0xff );
156  else
157  return ( ( (X) >> 16 ) & 0xff );
158 }
159 
160 int CTX::unpackAlpha(unsigned int X)
161 {
162  if(bigEndian)
163  return ( (X) & 0xff );
164  else
165  return ( ( (X) >> 24 ) & 0xff );
166 }
contextMeshOptions::recombineAll
int recombineAll
Definition: Context.h:30
contextMeshOptions::trihedra
int trihedra
Definition: Context.h:84
contextMeshOptions::angleSmoothNormals
double angleSmoothNormals
Definition: Context.h:22
CTX::fileread
bool fileread
Definition: Context.h:237
contextMeshOptions::volumeEdges
int volumeEdges
Definition: Context.h:85
CTX::packColor
unsigned int packColor(int R, int G, int B, int A)
Definition: Context.cpp:128
CTX::polygonOffset
int polygonOffset
Definition: Context.h:280
CTX::deltaFontSize
int deltaFontSize
Definition: Context.h:264
contextMeshOptions::triangles
int triangles
Definition: Context.h:83
contextMeshOptions::optimizeNetgen
int optimizeNetgen
Definition: Context.h:19
contextMeshOptions::draw
int draw
Definition: Context.h:82
CTX
Definition: Context.h:127
contextMeshOptions::surfaceEdges
int surfaceEdges
Definition: Context.h:85
CTX::bgmFileName
std::string bgmFileName
Definition: Context.h:141
CTX::color
struct CTX::@3 color
contextMeshOptions::lcFromCurvature
int lcFromCurvature
Definition: Context.h:27
CTX::init
void init()
Definition: Context.cpp:30
CTX::detachedProcess
int detachedProcess
Definition: Context.h:171
CTX::createAppendMeshStatReport
int createAppendMeshStatReport
Definition: Context.h:151
contextMeshOptions::lcExtendFromBoundary
int lcExtendFromBoundary
Definition: Context.h:28
CTX::unpackBlue
int unpackBlue(unsigned int X)
Definition: Context.cpp:152
CTX::homeDir
std::string homeDir
Definition: Context.h:147
contextMeshOptions::optimize
int optimize
Definition: Context.h:19
OS.h
contextMeshOptions::refineSteps
int refineSteps
Definition: Context.h:19
contextMeshOptions::lcIntegrationPrecision
double lcIntegrationPrecision
Definition: Context.h:21
contextMeshOptions::surfaceFaces
int surfaceFaces
Definition: Context.h:85
CTX::post
struct CTX::@0 post
CTX::pickElements
int pickElements
Definition: Context.h:294
contextMeshOptions::qualityType
int qualityType
Definition: Context.h:86
contextMeshOptions::lcMin
double lcMin
Definition: Context.h:25
contextMeshOptions::order
int order
Definition: Context.h:35
contextMeshOptions::meshOnlyVisible
int meshOnlyVisible
Definition: Context.h:36
contextMeshOptions::prisms
int prisms
Definition: Context.h:83
CTX::printing
int printing
Definition: Context.h:304
CTX::batch
int batch
Definition: Context.h:203
contextMeshOptions::volumeFaces
int volumeFaces
Definition: Context.h:85
contextMeshOptions::lcFromParametricPoints
int lcFromParametricPoints
Definition: Context.h:27
contextMeshOptions::lcMax
double lcMax
Definition: Context.h:25
contextMeshOptions::lightLines
int lightLines
Definition: Context.h:82
contextMeshOptions::scalingFactor
double scalingFactor
Definition: Context.h:58
contextMeshOptions::toleranceInitialDelaunay
double toleranceInitialDelaunay
Definition: Context.h:25
contextGeometryOptions::draw
int draw
Definition: Context.h:114
CTX::numTiles
int numTiles
Definition: Context.h:173
CTX::drawRotationCenter
int drawRotationCenter
Definition: Context.h:242
contextMeshOptions::switchElementTags
int switchElementTags
Definition: Context.h:67
CTX::instance
static CTX * instance()
Definition: Context.cpp:122
GamePad.h
contextMeshOptions::tetrahedra
int tetrahedra
Definition: Context.h:83
contextMeshOptions::numSubEdges
int numSubEdges
Definition: Context.h:85
contextMeshOptions::algoSubdivide
int algoSubdivide
Definition: Context.h:29
contextMeshOptions::recombine3DAll
int recombine3DAll
Definition: Context.h:33
CTX::gamepad
GamePad * gamepad
Definition: Context.h:223
CTX::lc
double lc
Definition: Context.h:234
contextMeshOptions::algo3d
int algo3d
Definition: Context.h:29
CTX::min
double min[3]
Definition: Context.h:229
CTX::unpackGreen
int unpackGreen(unsigned int X)
Definition: Context.cpp:144
CTX::max
double max[3]
Definition: Context.h:229
CTX::outputFileName
std::string outputFileName
Definition: Context.h:141
contextMeshOptions::quadrangles
int quadrangles
Definition: Context.h:83
contextMeshOptions::saveTri
int saveTri
Definition: Context.h:60
CTX::cg
double cg[3]
Definition: Context.h:231
CTX::mesh
contextMeshOptions mesh
Definition: Context.h:313
GetEnvironmentVar
std::string GetEnvironmentVar(const std::string &var)
Definition: OS.cpp:284
CTX::hideUnselected
int hideUnselected
Definition: Context.h:306
CTX::geom
contextGeometryOptions geom
Definition: Context.h:311
contextMeshOptions::secondOrderIncomplete
int secondOrderIncomplete
Definition: Context.h:35
contextMeshOptions::minCircleNodes
int minCircleNodes
Definition: Context.h:37
contextMeshOptions::changed
int changed
Definition: Context.h:82
CTX::unpackAlpha
int unpackAlpha(unsigned int X)
Definition: Context.cpp:160
CTX::glFontEnum
int glFontEnum
Definition: Context.h:267
contextMeshOptions::qualitySup
double qualitySup
Definition: Context.h:24
CTX::bigEndian
int bigEndian
Definition: Context.h:373
CTX::recentFiles
std::vector< std::string > recentFiles
Definition: Context.h:149
CTX::debugSurface
int debugSurface
Definition: Context.h:138
Context.h
contextMeshOptions::qualityInf
double qualityInf
Definition: Context.h:24
contextMeshOptions::secondOrderLinear
int secondOrderLinear
Definition: Context.h:35
contextMeshOptions::radiusInf
double radiusInf
Definition: Context.h:24
contextMeshOptions::lcFactor
double lcFactor
Definition: Context.h:21
contextMeshOptions::algo2d
int algo2d
Definition: Context.h:29
contextMeshOptions::radiusSup
double radiusSup
Definition: Context.h:24
contextMeshOptions::smoothNormals
int smoothNormals
Definition: Context.h:89
contextMeshOptions::pyramids
int pyramids
Definition: Context.h:84
CTX::batchAfterMesh
int batchAfterMesh
Definition: Context.h:205
CTX::~CTX
~CTX()
Definition: Context.cpp:25
CTX::launchSolverAtStartup
int launchSolverAtStartup
Definition: Context.h:155
contextMeshOptions::toleranceEdgeLength
double toleranceEdgeLength
Definition: Context.h:25
contextMeshOptions::algoRecombine
int algoRecombine
Definition: Context.h:30
contextMeshOptions::explode
double explode
Definition: Context.h:22
contextMeshOptions::hexahedra
int hexahedra
Definition: Context.h:83
contextMeshOptions::lines
int lines
Definition: Context.h:83
CTX::_instance
static CTX * _instance
Definition: Context.h:129
CTX::terminal
int terminal
Definition: Context.h:167
contextGeometryOptions::autoExtrude
int autoExtrude
Definition: Context.h:98
CTX::unpackRed
int unpackRed(unsigned int X)
Definition: Context.cpp:136
CTX::CTX
CTX()
Definition: Context.cpp:17
CTX::lock
int lock
Definition: Context.h:252
contextMeshOptions::lcFromPoints
int lcFromPoints
Definition: Context.h:27
contextMeshOptions::colorCarousel
int colorCarousel
Definition: Context.h:88
CTX::batchSomeValue
double batchSomeValue
Definition: Context.h:207
CTX::meshTimer
double meshTimer[3]
Definition: Context.h:290
CTX::numWindows
int numWindows
Definition: Context.h:173
CTX::forcedBBox
int forcedBBox
Definition: Context.h:292
contextMeshOptions::hoOptimize
int hoOptimize
Definition: Context.h:38
contextMeshOptions::randFactor
double randFactor
Definition: Context.h:21