PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 2ms

/Common/Options.cpp

https://bitbucket.org/lge/gmsh
C++ | 8910 lines | 8124 code | 734 blank | 52 comment | 1668 complexity | 78163dd2f0ca41f1e2fcf4aef69c6c57 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. // Gmsh - Copyright (C) 1997-2012 C. Geuzaine, J.-F. Remacle
  2. //
  3. // See the LICENSE.txt file for license information. Please report all
  4. // bugs and problems to <gmsh@geuz.org>.
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include "GmshConfig.h"
  9. #include "GmshDefines.h"
  10. #include "GmshMessage.h"
  11. #include "StringUtils.h"
  12. #include "GModel.h"
  13. #include "Context.h"
  14. #include "Options.h"
  15. #include "Colors.h"
  16. #include "DefaultOptions.h"
  17. #if defined(HAVE_MESH)
  18. #include "Generator.h"
  19. #include "Field.h"
  20. #include "BackgroundMesh.h"
  21. #endif
  22. #if defined(HAVE_PARSER)
  23. #include "Parser.h"
  24. #endif
  25. #if defined(HAVE_POST)
  26. #include "PView.h"
  27. #include "PViewOptions.h"
  28. #include "PViewData.h"
  29. #include "adaptiveData.h"
  30. #endif
  31. #if defined(HAVE_PLUGINS)
  32. #include "PluginManager.h"
  33. #include "Plugin.h"
  34. #endif
  35. #if defined(HAVE_FLTK)
  36. #include <FL/Fl_Tooltip.H>
  37. #include "FlGui.h"
  38. #include "graphicWindow.h"
  39. #include "optionWindow.h"
  40. #include "manipWindow.h"
  41. #include "contextWindow.h"
  42. #include "clippingWindow.h"
  43. #include "onelabGroup.h"
  44. #include "viewButton.h"
  45. #endif
  46. // General routines for string options
  47. bool StringOption(int action, const char *category, int num,
  48. const char *name, std::string &val)
  49. {
  50. StringXString *s = 0;
  51. if(!strcmp(category, "General"))
  52. s = GeneralOptions_String;
  53. else if(!strcmp(category, "Geometry"))
  54. s = GeometryOptions_String;
  55. else if(!strcmp(category, "Mesh"))
  56. s = MeshOptions_String;
  57. else if(!strcmp(category, "Solver"))
  58. s = SolverOptions_String;
  59. else if(!strcmp(category, "PostProcessing"))
  60. s = PostProcessingOptions_String;
  61. else if(!strcmp(category, "View"))
  62. s = ViewOptions_String;
  63. else if(!strcmp(category, "Print"))
  64. s = PrintOptions_String;
  65. else{
  66. Msg::Error("Unknown string option category '%s'", category);
  67. return false;
  68. }
  69. int i = 0;
  70. while(s[i].str && strcmp(s[i].str, name)) i++;
  71. if(!s[i].str){
  72. Msg::Error("Unknown string option '%s.%s'", category, name);
  73. return false;
  74. }
  75. val = s[i].function(num, action, val);
  76. return true;
  77. }
  78. static void SetDefaultStringOptions(int num, StringXString s[])
  79. {
  80. int i = 0;
  81. while(s[i].str) {
  82. s[i].function(num, GMSH_SET, s[i].def);
  83. i++;
  84. }
  85. }
  86. static void SetStringOptionsGUI(int num, StringXString s[])
  87. {
  88. int i = 0;
  89. while(s[i].str) {
  90. s[i].function(num, GMSH_GUI, "");
  91. i++;
  92. }
  93. }
  94. static void PrintStringOptions(int num, int level, int diff, int help,
  95. StringXString s[], const char *prefix, FILE *file)
  96. {
  97. int i = 0;
  98. while(s[i].str) {
  99. if(s[i].level & level) {
  100. if(!diff || s[i].function(num, GMSH_GET, "") != s[i].def){
  101. char tmp[1024];
  102. sprintf(tmp, "%s%s = \"%s\";%s%s", prefix,
  103. s[i].str, s[i].function(num, GMSH_GET, "").c_str(),
  104. help ? " // " : "", help ? s[i].help : "");
  105. if(file)
  106. fprintf(file, "%s\n", tmp);
  107. else{
  108. // remove \n, \t, \r
  109. for(unsigned int i = 0; i < strlen(tmp); i++)
  110. if(tmp[i] == '\n' || tmp[i] == '\t' || tmp[i] == '\r') tmp[i] = ' ';
  111. // Warning: must call Msg::Direct(level, ...) here, because
  112. // we cannot use tmp as a format string (it can contain %s!)
  113. Msg::Direct(3, "%s", tmp);
  114. }
  115. }
  116. }
  117. i++;
  118. }
  119. }
  120. static const char *GetOptionSaveLevel(int level)
  121. {
  122. if(level & GMSH_SESSIONRC){
  123. return "General.SessionFileName";
  124. }
  125. else if(level & GMSH_OPTIONSRC){
  126. return "General.OptionsFileName";
  127. }
  128. else{
  129. return "-";
  130. }
  131. }
  132. static void PrintStringOptionsDoc(StringXString s[], const char *prefix, FILE *file)
  133. {
  134. int i = 0;
  135. while(s[i].str) {
  136. fprintf(file, "@item %s%s\n", prefix, s[i].str);
  137. fprintf(file, "%s@*\n", s[i].help);
  138. // sanitize the string for texinfo
  139. std::string val = s[i].function(0, GMSH_GET, "");
  140. for(unsigned int j = 1; j < val.size(); j++){
  141. if(val[j] == '\n' && val[j - 1] == '\n')
  142. val[j - 1] = '.';
  143. }
  144. fprintf(file, "Default value: @code{\"%s\"}@*\n", val.c_str());
  145. fprintf(file, "Saved in: @code{%s}\n\n", GetOptionSaveLevel(s[i].level));
  146. i++;
  147. }
  148. }
  149. // General routines for numeric options
  150. bool NumberOption(int action, const char *category, int num,
  151. const char *name, double &val)
  152. {
  153. StringXNumber *s = 0;
  154. if(!strcmp(category, "General"))
  155. s = GeneralOptions_Number;
  156. else if(!strcmp(category, "Geometry"))
  157. s = GeometryOptions_Number;
  158. else if(!strcmp(category, "Mesh"))
  159. s = MeshOptions_Number;
  160. else if(!strcmp(category, "Solver"))
  161. s = SolverOptions_Number;
  162. else if(!strcmp(category, "PostProcessing"))
  163. s = PostProcessingOptions_Number;
  164. else if(!strcmp(category, "View"))
  165. s = ViewOptions_Number;
  166. else if(!strcmp(category, "Print"))
  167. s = PrintOptions_Number;
  168. else{
  169. Msg::Error("Unknown number option category '%s'", category);
  170. return false;
  171. }
  172. int i = 0;
  173. while(s[i].str && strcmp(s[i].str, name)) i++;
  174. if(!s[i].str){
  175. Msg::Error("Unknown number option '%s.%s'", category, name);
  176. return false;
  177. }
  178. val = s[i].function(num, action, val);
  179. return true;
  180. }
  181. static void SetDefaultNumberOptions(int num, StringXNumber s[])
  182. {
  183. int i = 0;
  184. while(s[i].str) {
  185. s[i].function(num, GMSH_SET, s[i].def);
  186. i++;
  187. }
  188. }
  189. static void SetNumberOptionsGUI(int num, StringXNumber s[])
  190. {
  191. int i = 0;
  192. while(s[i].str) {
  193. s[i].function(num, GMSH_GUI, 0);
  194. i++;
  195. }
  196. }
  197. static void PrintNumberOptions(int num, int level, int diff, int help,
  198. StringXNumber s[], const char *prefix, FILE * file)
  199. {
  200. int i = 0;
  201. char tmp[1024];
  202. while(s[i].str) {
  203. if(s[i].level & level) {
  204. if(!diff || (s[i].function(num, GMSH_GET, 0) != s[i].def)){
  205. sprintf(tmp, "%s%s = %.16g;%s%s", prefix,
  206. s[i].str, s[i].function(num, GMSH_GET, 0),
  207. help ? " // " : "", help ? s[i].help : "");
  208. if(file)
  209. fprintf(file, "%s\n", tmp);
  210. else
  211. Msg::Direct(tmp);
  212. }
  213. }
  214. i++;
  215. }
  216. }
  217. static void PrintNumberOptionsDoc(StringXNumber s[], const char *prefix, FILE * file)
  218. {
  219. int i = 0;
  220. while(s[i].str) {
  221. fprintf(file, "@item %s%s\n", prefix, s[i].str);
  222. fprintf(file, "%s@*\n", s[i].help);
  223. fprintf(file, "Default value: @code{%g}@*\n", s[i].function(0, GMSH_GET, 0));
  224. fprintf(file, "Saved in: @code{%s}\n\n", GetOptionSaveLevel(s[i].level));
  225. i++;
  226. }
  227. }
  228. // General routines for color options
  229. bool ColorOption(int action, const char *category, int num,
  230. const char *name, unsigned int &val)
  231. {
  232. StringXColor *s = 0;
  233. if(!strcmp(category, "General"))
  234. s = GeneralOptions_Color;
  235. else if(!strcmp(category, "Geometry"))
  236. s = GeometryOptions_Color;
  237. else if(!strcmp(category, "Mesh"))
  238. s = MeshOptions_Color;
  239. else if(!strcmp(category, "Solver"))
  240. s = SolverOptions_Color;
  241. else if(!strcmp(category, "PostProcessing"))
  242. s = PostProcessingOptions_Color;
  243. else if(!strcmp(category, "View"))
  244. s = ViewOptions_Color;
  245. else if(!strcmp(category, "Print"))
  246. s = PrintOptions_Color;
  247. else{
  248. Msg::Error("Unknown color option category '%s'", category);
  249. return false;
  250. }
  251. int i = 0;
  252. while(s[i].str && strcmp(s[i].str, name)) i++;
  253. if(!s[i].str){
  254. Msg::Error("Unknown color option '%s.%s'", category, name);
  255. return false;
  256. }
  257. val = s[i].function(num, action, val);
  258. return true;
  259. }
  260. int GetColorForString(int alpha, const char *str, int *FlagError)
  261. {
  262. int i = 0;
  263. while(ColorString[i].str && strcmp(ColorString[i].str, str))
  264. i++;
  265. *FlagError = !ColorString[i].str ? 1 : 0;
  266. if(alpha > 0)
  267. return CTX::instance()->packColor
  268. (ColorString[i].int1, ColorString[i].int2, ColorString[i].int3, alpha);
  269. else
  270. return CTX::instance()->packColor
  271. (ColorString[i].int1, ColorString[i].int2, ColorString[i].int3,
  272. ColorString[i].int4);
  273. }
  274. bool GetRGBForString(const char *str, int &r, int &g, int &b)
  275. {
  276. int i = 0;
  277. while(ColorString[i].str && strcmp(ColorString[i].str, str))
  278. i++;
  279. if(!ColorString[i].str){
  280. r = g = b = 0;
  281. return false;
  282. }
  283. r = ColorString[i].int1;
  284. g = ColorString[i].int2;
  285. b = ColorString[i].int3;
  286. return true;
  287. }
  288. static void SetDefaultColorOptions(int num, StringXColor s[])
  289. {
  290. int i = 0;
  291. // Warning: this assumes that CTX::instance()->color_scheme is set...
  292. switch (CTX::instance()->colorScheme) {
  293. case 1:
  294. while(s[i].str) {
  295. s[i].function(num, GMSH_SET, CTX::instance()->packColor
  296. (s[i].def2[0], s[i].def2[1], s[i].def2[2], s[i].def2[3]));
  297. i++;
  298. }
  299. break;
  300. case 2:
  301. while(s[i].str) {
  302. s[i].function(num, GMSH_SET, CTX::instance()->packColor
  303. (s[i].def3[0], s[i].def3[1], s[i].def3[2], s[i].def3[3]));
  304. i++;
  305. }
  306. break;
  307. default:
  308. while(s[i].str) {
  309. s[i].function(num, GMSH_SET, CTX::instance()->packColor
  310. (s[i].def1[0], s[i].def1[1], s[i].def1[2], s[i].def1[3]));
  311. i++;
  312. }
  313. break;
  314. }
  315. }
  316. static void SetColorOptionsGUI(int num, StringXColor s[])
  317. {
  318. int i = 0;
  319. while(s[i].str) {
  320. s[i].function(num, GMSH_GUI, 0);
  321. i++;
  322. }
  323. }
  324. static void PrintColorOptions(int num, int level, int diff, int help,
  325. StringXColor s[], const char *prefix, FILE * file)
  326. {
  327. int i = 0;
  328. char tmp[1024];
  329. while(s[i].str) {
  330. if(s[i].level & level) {
  331. unsigned int def;
  332. switch (CTX::instance()->colorScheme) {
  333. case 1:
  334. def = CTX::instance()->packColor
  335. (s[i].def2[0], s[i].def2[1], s[i].def2[2], s[i].def2[3]);
  336. break;
  337. case 2:
  338. def = CTX::instance()->packColor
  339. (s[i].def3[0], s[i].def3[1], s[i].def3[2], s[i].def3[3]);
  340. break;
  341. default:
  342. def = CTX::instance()->packColor
  343. (s[i].def1[0], s[i].def1[1], s[i].def1[2], s[i].def1[3]);
  344. break;
  345. }
  346. if(!diff || (s[i].function(num, GMSH_GET, 0) != def)){
  347. sprintf(tmp, "%sColor.%s = {%d,%d,%d};%s%s",
  348. prefix, s[i].str,
  349. CTX::instance()->unpackRed(s[i].function(num, GMSH_GET, 0)),
  350. CTX::instance()->unpackGreen(s[i].function(num, GMSH_GET, 0)),
  351. CTX::instance()->unpackBlue(s[i].function(num, GMSH_GET, 0)),
  352. help ? " // " : "", help ? s[i].help : "");
  353. if(file)
  354. fprintf(file, "%s\n", tmp);
  355. else
  356. Msg::Direct(tmp);
  357. }
  358. }
  359. i++;
  360. }
  361. }
  362. static void PrintColorOptionsDoc(StringXColor s[], const char *prefix, FILE * file)
  363. {
  364. int i = 0;
  365. while(s[i].str) {
  366. fprintf(file, "@item %sColor.%s\n", prefix, s[i].str);
  367. fprintf(file, "%s@*\n", s[i].help);
  368. fprintf(file, "Default value: @code{@{%d,%d,%d@}}@*\n",
  369. CTX::instance()->unpackRed(s[i].function(0, GMSH_GET, 0)),
  370. CTX::instance()->unpackGreen(s[i].function(0, GMSH_GET, 0)),
  371. CTX::instance()->unpackBlue(s[i].function(0, GMSH_GET, 0)));
  372. fprintf(file, "Saved in: @code{%s}\n\n", GetOptionSaveLevel(s[i].level));
  373. i++;
  374. }
  375. }
  376. // General routines
  377. void InitOptions(int num)
  378. {
  379. // Default string options
  380. SetDefaultStringOptions(num, GeneralOptions_String);
  381. SetDefaultStringOptions(num, GeometryOptions_String);
  382. SetDefaultStringOptions(num, MeshOptions_String);
  383. SetDefaultStringOptions(num, SolverOptions_String);
  384. SetDefaultStringOptions(num, PostProcessingOptions_String);
  385. SetDefaultStringOptions(num, ViewOptions_String);
  386. SetDefaultStringOptions(num, PrintOptions_String);
  387. // Default number options
  388. SetDefaultNumberOptions(num, GeneralOptions_Number);
  389. SetDefaultNumberOptions(num, GeometryOptions_Number);
  390. SetDefaultNumberOptions(num, MeshOptions_Number);
  391. SetDefaultNumberOptions(num, SolverOptions_Number);
  392. SetDefaultNumberOptions(num, PostProcessingOptions_Number);
  393. SetDefaultNumberOptions(num, ViewOptions_Number);
  394. SetDefaultNumberOptions(num, PrintOptions_Number);
  395. // Default color options
  396. SetDefaultColorOptions(num, GeneralOptions_Color);
  397. SetDefaultColorOptions(num, GeometryOptions_Color);
  398. SetDefaultColorOptions(num, MeshOptions_Color);
  399. SetDefaultColorOptions(num, SolverOptions_Color);
  400. SetDefaultColorOptions(num, PostProcessingOptions_Color);
  401. SetDefaultColorOptions(num, ViewOptions_Color);
  402. SetDefaultColorOptions(num, PrintOptions_Color);
  403. }
  404. void ReInitOptions(int num)
  405. {
  406. // horrible trick so that opt_view_XXX will act on the reference view
  407. #if defined(HAVE_POST)
  408. std::vector<PView*> tmp = PView::list;
  409. PView::list.clear();
  410. #endif
  411. InitOptions(num);
  412. #if defined(HAVE_POST)
  413. PView::list = tmp;
  414. for(unsigned int i = 0; i < PView::list.size(); i++)
  415. PView::list[i]->setOptions();
  416. #endif
  417. }
  418. void InitOptionsGUI(int num)
  419. {
  420. SetStringOptionsGUI(num, GeneralOptions_String);
  421. SetStringOptionsGUI(num, GeometryOptions_String);
  422. SetStringOptionsGUI(num, MeshOptions_String);
  423. SetStringOptionsGUI(num, SolverOptions_String);
  424. SetStringOptionsGUI(num, PostProcessingOptions_String);
  425. SetStringOptionsGUI(num, PrintOptions_String);
  426. SetNumberOptionsGUI(num, GeneralOptions_Number);
  427. SetNumberOptionsGUI(num, GeometryOptions_Number);
  428. SetNumberOptionsGUI(num, MeshOptions_Number);
  429. SetNumberOptionsGUI(num, SolverOptions_Number);
  430. SetNumberOptionsGUI(num, PostProcessingOptions_Number);
  431. SetNumberOptionsGUI(num, PrintOptions_Number);
  432. SetColorOptionsGUI(num, GeneralOptions_Color);
  433. SetColorOptionsGUI(num, GeometryOptions_Color);
  434. SetColorOptionsGUI(num, MeshOptions_Color);
  435. SetColorOptionsGUI(num, SolverOptions_Color);
  436. SetColorOptionsGUI(num, PostProcessingOptions_Color);
  437. SetColorOptionsGUI(num, PrintOptions_Color);
  438. }
  439. static void PrintOptionCategory(int level, int diff, int help, const char *cat,
  440. FILE *file)
  441. {
  442. if(diff || !help || !(level & GMSH_FULLRC))
  443. return;
  444. if(file) {
  445. fprintf(file, "//\n");
  446. fprintf(file, "// %s\n", cat);
  447. fprintf(file, "//\n");
  448. }
  449. else {
  450. Msg::Direct("//");
  451. Msg::Direct("// %s", cat);
  452. Msg::Direct("//");
  453. }
  454. }
  455. GmshColorTable *GetColorTable(int num)
  456. {
  457. #if defined(HAVE_POST)
  458. PViewOptions *opt;
  459. if(PView::list.empty() || num < 0 || num > (int)PView::list.size() - 1)
  460. opt = PViewOptions::reference();
  461. else{
  462. opt = PView::list[num]->getOptions();
  463. // assume that if we access the colortable we will change it
  464. PView::list[num]->setChanged(true);
  465. }
  466. return &opt->colorTable;
  467. #else
  468. return 0;
  469. #endif
  470. }
  471. static void PrintColorTable(int num, int diff, const char *prefix, FILE *file)
  472. {
  473. #if defined(HAVE_POST)
  474. PViewOptions *opt;
  475. if(PView::list.empty() || num < 0 || num > (int)PView::list.size() - 1)
  476. opt = PViewOptions::reference();
  477. else
  478. opt = PView::list[num]->getOptions();
  479. if(diff){
  480. // compare the current colormap with a vanilla colormap having the
  481. // parameters
  482. GmshColorTable ref;
  483. ColorTable_InitParam(opt->colorTable.ipar[COLORTABLE_NUMBER], &ref);
  484. for(int i = 0; i < COLORTABLE_NBMAX_PARAM; i++){
  485. ref.ipar[i] = opt->colorTable.ipar[i];
  486. ref.dpar[i] = opt->colorTable.dpar[i];
  487. }
  488. ColorTable_Recompute(&ref);
  489. if(!ColorTable_Diff(&ref, &opt->colorTable))
  490. return;
  491. }
  492. char tmp[1024];
  493. sprintf(tmp, "%s = {", prefix);
  494. if(file)
  495. fprintf(file, "%s\n", tmp);
  496. else
  497. Msg::Direct(tmp);
  498. ColorTable_Print(&opt->colorTable, file);
  499. sprintf(tmp, "};");
  500. if(file)
  501. fprintf(file, "%s\n", tmp);
  502. else
  503. Msg::Direct(tmp);
  504. #endif
  505. }
  506. void Sanitize_String_Texi(std::string &s)
  507. {
  508. int i = -1;
  509. while ((i = s.find('\n', i + 1)) >= 0){
  510. s.insert(i, "@*");
  511. i += 2;
  512. }
  513. i = -1;
  514. while ((i = s.find_first_of("{}", i + 1)) >= 0)
  515. s.insert(i++, "@");
  516. }
  517. void PrintOptions(int num, int level, int diff, int help, const char *filename)
  518. {
  519. #if defined(HAVE_FLTK)
  520. if(FlGui::available())
  521. FlGui::instance()->storeCurrentWindowsInfo();
  522. #endif
  523. FILE *file;
  524. if(filename) {
  525. file = fopen(filename, "w");
  526. if(!file) {
  527. Msg::Error("Unable to open file '%s'", filename);
  528. return;
  529. }
  530. }
  531. else
  532. file = 0;
  533. if((level & GMSH_SESSIONRC) && file) {
  534. fprintf(file, "// Gmsh Session File\n");
  535. fprintf(file, "//\n");
  536. fprintf(file, "// This file contains session specific info (that is info you\n");
  537. fprintf(file, "// want to keep between two Gmsh sessions). You are not supposed\n");
  538. fprintf(file, "// to edit it manually, but of course you can. This file will be\n");
  539. fprintf(file, "// entirely rewritten every time you quit Gmsh if the option \n");
  540. fprintf(file, "// 'General.SaveSession' is set.\n");
  541. fprintf(file, "//\n");
  542. }
  543. if((level & GMSH_OPTIONSRC) && file) {
  544. fprintf(file, "// Gmsh Option File\n");
  545. fprintf(file, "//\n");
  546. fprintf(file, "// This file contains configuration options (preferences) that\n");
  547. fprintf(file, "// are loaded each time Gmsh is launched. You can create this\n");
  548. fprintf(file, "// file by hand, or let Gmsh generate it for you (with\n");
  549. fprintf(file, "// 'File->Save Default Options'). This file can also be\n");
  550. fprintf(file, "// automatically saved every time you quit Gmsh if the option\n");
  551. fprintf(file, "// 'General.SaveOptions' is set.\n");
  552. fprintf(file, "//\n");
  553. }
  554. PrintOptionCategory(level, diff, help, "General options (strings)", file);
  555. PrintStringOptions(num, level, diff, help, GeneralOptions_String, "General.", file);
  556. PrintOptionCategory(level, diff, help, "General options (numbers)", file);
  557. PrintNumberOptions(num, level, diff, help, GeneralOptions_Number, "General.", file);
  558. PrintOptionCategory(level, diff, help, "General options (colors)", file);
  559. PrintColorOptions(num, level, diff, help, GeneralOptions_Color, "General.", file);
  560. PrintOptionCategory(level, diff, help, "Geometry options (strings)", file);
  561. PrintStringOptions(num, level, diff, help, GeometryOptions_String, "Geometry.", file);
  562. PrintOptionCategory(level, diff, help, "Geometry options (numbers)", file);
  563. PrintNumberOptions(num, level, diff, help, GeometryOptions_Number, "Geometry.", file);
  564. PrintOptionCategory(level, diff, help, "Geometry options (colors)", file);
  565. PrintColorOptions(num, level, diff, help, GeometryOptions_Color, "Geometry.", file);
  566. PrintOptionCategory(level, diff, help, "Mesh options (strings)", file);
  567. PrintStringOptions(num, level, diff, help, MeshOptions_String, "Mesh.", file);
  568. PrintOptionCategory(level, diff, help, "Mesh options (numbers)", file);
  569. PrintNumberOptions(num, level, diff, help, MeshOptions_Number, "Mesh.", file);
  570. PrintOptionCategory(level, diff, help, "Mesh options (colors)", file);
  571. PrintColorOptions(num, level, diff, help, MeshOptions_Color, "Mesh.", file);
  572. PrintOptionCategory(level, diff, help, "Solver options (strings)", file);
  573. PrintStringOptions(num, level, diff, help, SolverOptions_String, "Solver.", file);
  574. PrintOptionCategory(level, diff, help, "Solver options (numbers)", file);
  575. PrintNumberOptions(num, level, diff, help, SolverOptions_Number, "Solver.", file);
  576. PrintOptionCategory(level, diff, help, "Solver options (colors)", file);
  577. PrintColorOptions(num, level, diff, help, SolverOptions_Color, "Solver.", file);
  578. PrintOptionCategory(level, diff, help, "Post-processing options (strings)", file);
  579. PrintStringOptions(num, level, diff, help, PostProcessingOptions_String,
  580. "PostProcessing.", file);
  581. PrintOptionCategory(level, diff, help, "Post-processing options (numbers)", file);
  582. PrintNumberOptions(num, level, diff, help, PostProcessingOptions_Number,
  583. "PostProcessing.", file);
  584. PrintOptionCategory(level, diff, help, "Post-processing options (colors)", file);
  585. PrintColorOptions(num, level, diff, help, PostProcessingOptions_Color,
  586. "PostProcessing.", file);
  587. if(level & GMSH_FULLRC) {
  588. #if defined(HAVE_POST)
  589. for(unsigned int i = 0; i < PView::list.size(); i++) {
  590. char tmp[256];
  591. sprintf(tmp, "View[%d].", i);
  592. PrintOptionCategory(level, diff, help, "View options (strings)", file);
  593. PrintStringOptions(i, level, diff, help, ViewOptions_String, tmp, file);
  594. PrintOptionCategory(level, diff, help, "View options (numbers)", file);
  595. PrintNumberOptions(i, level, diff, help, ViewOptions_Number, tmp, file);
  596. PrintOptionCategory(level, diff, help, "View options (colors)", file);
  597. PrintColorOptions(i, level, diff, help, ViewOptions_Color, tmp, file);
  598. strcat(tmp, "ColorTable");
  599. PrintColorTable(i, diff, tmp, file);
  600. }
  601. #endif
  602. }
  603. else if(level & GMSH_OPTIONSRC) {
  604. PrintOptionCategory(level, diff, help, "View options (strings)", file);
  605. PrintStringOptions(num, level, diff, help, ViewOptions_String, "View.", file);
  606. PrintOptionCategory(level, diff, help, "View options (numbers)", file);
  607. PrintNumberOptions(num, level, diff, help, ViewOptions_Number, "View.", file);
  608. PrintOptionCategory(level, diff, help, "View options (colors)", file);
  609. PrintColorOptions(num, level, diff, help, ViewOptions_Color, "View.", file);
  610. PrintColorTable(num, diff, "View.ColorTable", file);
  611. }
  612. PrintOptionCategory(level, diff, help, "Print options (strings)", file);
  613. PrintStringOptions(num, level, diff, help, PrintOptions_String, "Print.", file);
  614. PrintOptionCategory(level, diff, help, "Print options (numbers)", file);
  615. PrintNumberOptions(num, level, diff, help, PrintOptions_Number, "Print.", file);
  616. PrintOptionCategory(level, diff, help, "Print options (colors)", file);
  617. PrintColorOptions(num, level, diff, help, PrintOptions_Color, "Print.", file);
  618. if(filename) fclose(file);
  619. }
  620. void PrintOptionsDoc()
  621. {
  622. const char *warn =
  623. "@c\n"
  624. "@c This file is generated automatically by running \"gmsh -doc\".\n"
  625. "@c Do not edit by hand!\n"
  626. "@c\n\n";
  627. FILE *file = fopen("opt_general.texi", "w");
  628. if(!file) {
  629. Msg::Error("Unable to open file 'opt_general.texi'");
  630. return;
  631. }
  632. fprintf(file, "%s@ftable @code\n", warn);
  633. PrintStringOptionsDoc(GeneralOptions_String, "General.", file);
  634. PrintNumberOptionsDoc(GeneralOptions_Number, "General.", file);
  635. PrintColorOptionsDoc(GeneralOptions_Color, "General.", file);
  636. fprintf(file, "@end ftable\n");
  637. fclose(file);
  638. file = fopen("opt_print.texi", "w");
  639. if(!file) {
  640. Msg::Error("Unable to open file 'opt_print.texi'");
  641. return;
  642. }
  643. fprintf(file, "%s@ftable @code\n", warn);
  644. PrintStringOptionsDoc(PrintOptions_String, "Print.", file);
  645. PrintNumberOptionsDoc(PrintOptions_Number, "Print.", file);
  646. PrintColorOptionsDoc(PrintOptions_Color, "Print.", file);
  647. fprintf(file, "@end ftable\n");
  648. fclose(file);
  649. file = fopen("opt_geometry.texi", "w");
  650. if(!file) {
  651. Msg::Error("Unable to open file 'opt_geometry.texi'");
  652. return;
  653. }
  654. fprintf(file, "%s@ftable @code\n", warn);
  655. PrintStringOptionsDoc(GeometryOptions_String, "Geometry.", file);
  656. PrintNumberOptionsDoc(GeometryOptions_Number, "Geometry.", file);
  657. PrintColorOptionsDoc(GeometryOptions_Color, "Geometry.", file);
  658. fprintf(file, "@end ftable\n");
  659. fclose(file);
  660. file = fopen("opt_mesh.texi", "w");
  661. if(!file) {
  662. Msg::Error("Unable to open file 'opt_mesh.texi'");
  663. return;
  664. }
  665. fprintf(file, "%s@ftable @code\n", warn);
  666. PrintStringOptionsDoc(MeshOptions_String, "Mesh.", file);
  667. PrintNumberOptionsDoc(MeshOptions_Number, "Mesh.", file);
  668. PrintColorOptionsDoc(MeshOptions_Color, "Mesh.", file);
  669. fprintf(file, "@end ftable\n");
  670. fclose(file);
  671. file = fopen("opt_solver.texi", "w");
  672. if(!file) {
  673. Msg::Error("Unable to open file 'opt_solver.texi'");
  674. return;
  675. }
  676. fprintf(file, "%s@ftable @code\n", warn);
  677. PrintStringOptionsDoc(SolverOptions_String, "Solver.", file);
  678. PrintNumberOptionsDoc(SolverOptions_Number, "Solver.", file);
  679. PrintColorOptionsDoc(SolverOptions_Color, "Solver.", file);
  680. fprintf(file, "@end ftable\n");
  681. fclose(file);
  682. file = fopen("opt_post.texi", "w");
  683. if(!file) {
  684. Msg::Error("Unable to open file 'opt_post.texi'");
  685. return;
  686. }
  687. fprintf(file, "%s@ftable @code\n", warn);
  688. PrintStringOptionsDoc(PostProcessingOptions_String, "PostProcessing.", file);
  689. PrintNumberOptionsDoc(PostProcessingOptions_Number, "PostProcessing.", file);
  690. PrintColorOptionsDoc(PostProcessingOptions_Color, "PostProcessing.", file);
  691. fprintf(file, "@end ftable\n");
  692. fclose(file);
  693. #if defined(HAVE_POST)
  694. file = fopen("opt_view.texi", "w");
  695. if(!file) {
  696. Msg::Error("Unable to open file 'opt_view.texi'");
  697. return;
  698. }
  699. fprintf(file, "%s@ftable @code\n", warn);
  700. PrintStringOptionsDoc(ViewOptions_String, "View.", file);
  701. PrintNumberOptionsDoc(ViewOptions_Number, "View.", file);
  702. PrintColorOptionsDoc(ViewOptions_Color, "View.", file);
  703. fprintf(file, "@item View.ColorTable\n");
  704. fprintf(file, "Color table used to draw the view@*\n");
  705. fprintf(file, "Saved in: @code{%s}\n\n",
  706. GetOptionSaveLevel(GMSH_FULLRC|GMSH_OPTIONSRC));
  707. fprintf(file, "@end ftable\n");
  708. fclose(file);
  709. #endif
  710. #if defined(HAVE_PLUGINS)
  711. file = fopen("opt_plugin.texi", "w");
  712. if(!file) {
  713. Msg::Error("Unable to open file 'opt_plugin.texi'");
  714. return;
  715. }
  716. fprintf(file, "%s@ftable @code\n", warn);
  717. for(std::map<std::string, GMSH_Plugin*>::iterator it = PluginManager::
  718. instance()->begin(); it != PluginManager::instance()->end(); ++it) {
  719. GMSH_Plugin *p = it->second;
  720. if(p->getType() == GMSH_Plugin::GMSH_POST_PLUGIN) {
  721. fprintf(file, "@item Plugin(%s)\n", p->getName().c_str());
  722. fprintf(file, "%s\n", p->getHelp().c_str());
  723. int m = p->getNbOptionsStr();
  724. if(m){
  725. fprintf(file, "String options:\n");
  726. fprintf(file, "@table @code\n");
  727. for(int i = 0; i < m; i++) {
  728. StringXString *sxs = p->getOptionStr(i);
  729. fprintf(file, "@item %s\n", sxs->str);
  730. fprintf(file, "Default value: @code{\"%s\"}\n", sxs->def.c_str());
  731. }
  732. fprintf(file, "@end table\n");
  733. }
  734. int n = p->getNbOptions();
  735. if(n){
  736. fprintf(file, "Numeric options:\n");
  737. fprintf(file, "@table @code\n");
  738. for(int i = 0; i < n; i++) {
  739. StringXNumber *sxn = p->getOption(i);
  740. fprintf(file, "@item %s\n", sxn->str);
  741. fprintf(file, "Default value: @code{%g}\n", sxn->def);
  742. }
  743. fprintf(file, "@end table\n");
  744. }
  745. }
  746. fprintf(file, "\n");
  747. }
  748. fprintf(file, "@end ftable\n");
  749. fclose(file);
  750. #endif
  751. #if defined(HAVE_MESH)
  752. file = fopen("opt_fields.texi", "w");
  753. if(!file) {
  754. Msg::Error("Unable to open file 'opt_fields.texi'");
  755. return;
  756. }
  757. fprintf(file, "%s@ftable @code\n", warn);
  758. FieldManager &fields = *GModel::current()->getFields();
  759. for(std::map<std::string, FieldFactory*>::iterator it = fields.map_type_name.begin();
  760. it != fields.map_type_name.end(); it++){
  761. fprintf(file, "@item %s\n", it->first.c_str());
  762. Field *f = (*it->second)();
  763. std::string field_description = f->getDescription();
  764. Sanitize_String_Texi(field_description);
  765. fprintf(file,"%s@*\n", field_description.c_str());
  766. if (!f->options.empty()) {
  767. fprintf(file, "Options:@*\n");
  768. fprintf(file, "@table @code\n");
  769. for(std::map<std::string, FieldOption*>::iterator it2 = f->options.begin();
  770. it2 != f->options.end(); it2++){
  771. fprintf(file, "@item %s\n", it2->first.c_str());
  772. std::string val;
  773. it2->second->getTextRepresentation(val);
  774. Sanitize_String_Texi(val);
  775. fprintf(file, "%s@*\ntype: %s@*\ndefault value: @code{%s}\n",
  776. it2->second->getDescription().c_str(),
  777. it2->second->getTypeName().c_str(), val.c_str());
  778. }
  779. fprintf(file, "@end table\n\n");
  780. }
  781. if (!f->callbacks.empty()) {
  782. fprintf(file, "Actions:@*\n");
  783. fprintf(file, "@table @code\n");
  784. for(std::map<std::string, FieldCallback*>::iterator it2 = f->callbacks.begin();
  785. it2 != f->callbacks.end(); it2++){
  786. fprintf(file, "@item %s\n", it2->first.c_str());
  787. fprintf(file, "%s@*\n", it2->second->getDescription().c_str());
  788. }
  789. fprintf(file, "@end table\n\n");
  790. }
  791. }
  792. fprintf(file, "@end ftable\n");
  793. fclose(file);
  794. #endif
  795. }
  796. #define GET_VIEW(error_val) \
  797. PView *view = 0; \
  798. PViewData *data = 0; \
  799. PViewOptions *opt; \
  800. if(PView::list.empty()) \
  801. opt = PViewOptions::reference(); \
  802. else{ \
  803. if(num < 0 || num >= (int)PView::list.size()){ \
  804. Msg::Warning("View[%d] does not exist", num); \
  805. return (error_val); \
  806. } \
  807. view = PView::list[num]; \
  808. data = view->getData(); \
  809. opt = view->getOptions(); \
  810. }
  811. #define GET_VIEWo(error_val) \
  812. PView *view = 0; \
  813. PViewOptions *opt; \
  814. if(PView::list.empty()) \
  815. opt = PViewOptions::reference(); \
  816. else{ \
  817. if(num < 0 || num >= (int)PView::list.size()){ \
  818. Msg::Warning("View[%d] does not exist", num); \
  819. return (error_val); \
  820. } \
  821. view = PView::list[num]; \
  822. opt = view->getOptions(); \
  823. }
  824. #define GET_VIEWd(error_val) \
  825. PView *view = 0; \
  826. PViewData *data = 0; \
  827. if(!PView::list.empty()){ \
  828. if(num < 0 || num >= (int)PView::list.size()){ \
  829. Msg::Warning("View[%d] does not exist", num); \
  830. return (error_val); \
  831. } \
  832. view = PView::list[num]; \
  833. data = view->getData(); \
  834. }
  835. // String option routines
  836. std::string opt_general_axes_label0(OPT_ARGS_STR)
  837. {
  838. if(action & GMSH_SET)
  839. CTX::instance()->axesLabel[0] = val;
  840. #if defined(HAVE_FLTK)
  841. if(FlGui::available() && (action & GMSH_GUI))
  842. FlGui::instance()->options->general.input[6]->value
  843. (CTX::instance()->axesLabel[0].c_str());
  844. #endif
  845. return CTX::instance()->axesLabel[0];
  846. }
  847. std::string opt_general_axes_label1(OPT_ARGS_STR)
  848. {
  849. if(action & GMSH_SET)
  850. CTX::instance()->axesLabel[1] = val;
  851. #if defined(HAVE_FLTK)
  852. if(FlGui::available() && (action & GMSH_GUI))
  853. FlGui::instance()->options->general.input[7]->value
  854. (CTX::instance()->axesLabel[1].c_str());
  855. #endif
  856. return CTX::instance()->axesLabel[1];
  857. }
  858. std::string opt_general_axes_label2(OPT_ARGS_STR)
  859. {
  860. if(action & GMSH_SET)
  861. CTX::instance()->axesLabel[2] = val;
  862. #if defined(HAVE_FLTK)
  863. if(FlGui::available() && (action & GMSH_GUI))
  864. FlGui::instance()->options->general.input[8]->value
  865. (CTX::instance()->axesLabel[2].c_str());
  866. #endif
  867. return CTX::instance()->axesLabel[2];
  868. }
  869. std::string opt_general_axes_format0(OPT_ARGS_STR)
  870. {
  871. if(action & GMSH_SET)
  872. CTX::instance()->axesFormat[0] = val;
  873. #if defined(HAVE_FLTK)
  874. if(FlGui::available() && (action & GMSH_GUI))
  875. FlGui::instance()->options->general.input[3]->value
  876. (CTX::instance()->axesFormat[0].c_str());
  877. #endif
  878. return CTX::instance()->axesFormat[0];
  879. }
  880. std::string opt_general_axes_format1(OPT_ARGS_STR)
  881. {
  882. if(action & GMSH_SET)
  883. CTX::instance()->axesFormat[1] = val;
  884. #if defined(HAVE_FLTK)
  885. if(FlGui::available() && (action & GMSH_GUI))
  886. FlGui::instance()->options->general.input[4]->value
  887. (CTX::instance()->axesFormat[1].c_str());
  888. #endif
  889. return CTX::instance()->axesFormat[1];
  890. }
  891. std::string opt_general_axes_format2(OPT_ARGS_STR)
  892. {
  893. if(action & GMSH_SET)
  894. CTX::instance()->axesFormat[2] = val;
  895. #if defined(HAVE_FLTK)
  896. if(FlGui::available() && (action & GMSH_GUI))
  897. FlGui::instance()->options->general.input[5]->value
  898. (CTX::instance()->axesFormat[2].c_str());
  899. #endif
  900. return CTX::instance()->axesFormat[2];
  901. }
  902. std::string opt_general_display(OPT_ARGS_STR)
  903. {
  904. if(action & GMSH_SET)
  905. CTX::instance()->display = val;
  906. return CTX::instance()->display;
  907. }
  908. std::string opt_general_background_image_filename(OPT_ARGS_STR)
  909. {
  910. if(action & GMSH_SET)
  911. CTX::instance()->bgImageFileName = val;
  912. return CTX::instance()->bgImageFileName;
  913. }
  914. std::string opt_general_filename(OPT_ARGS_STR)
  915. {
  916. return GModel::current()->getFileName();
  917. }
  918. std::string opt_general_default_filename(OPT_ARGS_STR)
  919. {
  920. if(action & GMSH_SET)
  921. CTX::instance()->defaultFileName = val;
  922. #if defined(HAVE_FLTK)
  923. if(FlGui::available() && (action & GMSH_GUI))
  924. FlGui::instance()->options->general.input[0]->value
  925. (CTX::instance()->defaultFileName.c_str());
  926. #endif
  927. return CTX::instance()->defaultFileName;
  928. }
  929. std::string opt_general_tmp_filename(OPT_ARGS_STR)
  930. {
  931. if(action & GMSH_SET)
  932. CTX::instance()->tmpFileName = val;
  933. return CTX::instance()->tmpFileName;
  934. }
  935. std::string opt_general_error_filename(OPT_ARGS_STR)
  936. {
  937. if(action & GMSH_SET)
  938. CTX::instance()->errorFileName = val;
  939. return CTX::instance()->errorFileName;
  940. }
  941. std::string opt_general_session_filename(OPT_ARGS_STR)
  942. {
  943. if(action & GMSH_SET)
  944. CTX::instance()->sessionFileName = val;
  945. return CTX::instance()->sessionFileName;
  946. }
  947. std::string opt_general_options_filename(OPT_ARGS_STR)
  948. {
  949. if(action & GMSH_SET)
  950. CTX::instance()->optionsFileName = val;
  951. return CTX::instance()->optionsFileName;
  952. }
  953. std::string opt_general_recent_file0(OPT_ARGS_STR)
  954. {
  955. if(action & GMSH_SET)
  956. CTX::instance()->recentFiles[0] = val;
  957. return CTX::instance()->recentFiles[0];
  958. }
  959. std::string opt_general_recent_file1(OPT_ARGS_STR)
  960. {
  961. if(action & GMSH_SET)
  962. CTX::instance()->recentFiles[1] = val;
  963. return CTX::instance()->recentFiles[1];
  964. }
  965. std::string opt_general_recent_file2(OPT_ARGS_STR)
  966. {
  967. if(action & GMSH_SET)
  968. CTX::instance()->recentFiles[2] = val;
  969. return CTX::instance()->recentFiles[2];
  970. }
  971. std::string opt_general_recent_file3(OPT_ARGS_STR)
  972. {
  973. if(action & GMSH_SET)
  974. CTX::instance()->recentFiles[3] = val;
  975. return CTX::instance()->recentFiles[3];
  976. }
  977. std::string opt_general_recent_file4(OPT_ARGS_STR)
  978. {
  979. if(action & GMSH_SET)
  980. CTX::instance()->recentFiles[4] = val;
  981. return CTX::instance()->recentFiles[4];
  982. }
  983. std::string opt_general_editor(OPT_ARGS_STR)
  984. {
  985. if(action & GMSH_SET)
  986. CTX::instance()->editor = val;
  987. #if defined(HAVE_FLTK)
  988. if(FlGui::available() && (action & GMSH_GUI))
  989. FlGui::instance()->options->general.input[1]->value
  990. (CTX::instance()->editor.c_str());
  991. #endif
  992. return CTX::instance()->editor;
  993. }
  994. std::string opt_general_web_browser(OPT_ARGS_STR)
  995. {
  996. if(action & GMSH_SET)
  997. CTX::instance()->webBrowser = val;
  998. #if defined(HAVE_FLTK)
  999. if(FlGui::available() && (action & GMSH_GUI))
  1000. FlGui::instance()->options->general.input[2]->value
  1001. (CTX::instance()->webBrowser.c_str());
  1002. #endif
  1003. return CTX::instance()->webBrowser;
  1004. }
  1005. std::string opt_general_watch_file_pattern(OPT_ARGS_STR)
  1006. {
  1007. if(action & GMSH_SET)
  1008. CTX::instance()->watchFilePattern = val;
  1009. return CTX::instance()->watchFilePattern;
  1010. }
  1011. std::string opt_general_gui_theme(OPT_ARGS_STR)
  1012. {
  1013. if(action & GMSH_SET)
  1014. CTX::instance()->guiTheme = val;
  1015. return CTX::instance()->guiTheme;
  1016. }
  1017. std::string opt_general_graphics_font(OPT_ARGS_STR)
  1018. {
  1019. if(action & GMSH_SET)
  1020. CTX::instance()->glFont = val;
  1021. #if defined(HAVE_FLTK)
  1022. int index = drawContext::global()->getFontIndex(CTX::instance()->glFont.c_str());
  1023. if(action & GMSH_SET){
  1024. CTX::instance()->glFont = drawContext::global()->getFontName(index);
  1025. CTX::instance()->glFontEnum = drawContext::global()->getFontEnum(index);
  1026. }
  1027. if(FlGui::available() && (action & GMSH_GUI)){
  1028. FlGui::instance()->options->general.choice[1]->value(index);
  1029. }
  1030. #endif
  1031. return CTX::instance()->glFont;
  1032. }
  1033. std::string opt_general_graphics_font_title(OPT_ARGS_STR)
  1034. {
  1035. if(action & GMSH_SET)
  1036. CTX::instance()->glFontTitle = val;
  1037. #if defined(HAVE_FLTK)
  1038. int index = drawContext::global()->getFontIndex(CTX::instance()->glFontTitle.c_str());
  1039. if(action & GMSH_SET){
  1040. CTX::instance()->glFontTitle = drawContext::global()->getFontName(index);
  1041. CTX::instance()->glFontEnumTitle = drawContext::global()->getFontEnum(index);
  1042. }
  1043. if(FlGui::available() && (action & GMSH_GUI)){
  1044. FlGui::instance()->options->general.choice[6]->value(index);
  1045. }
  1046. #endif
  1047. return CTX::instance()->glFontTitle;
  1048. }
  1049. std::string opt_solver_socket_name(OPT_ARGS_STR)
  1050. {
  1051. if(action & GMSH_SET)
  1052. CTX::instance()->solver.socketName = val;
  1053. #if defined(HAVE_FLTK)
  1054. if(FlGui::available() && (action & GMSH_GUI))
  1055. FlGui::instance()->options->solver.input[0]->value
  1056. (CTX::instance()->solver.socketName.c_str());
  1057. #endif
  1058. return CTX::instance()->solver.socketName;
  1059. }
  1060. std::string opt_solver_name(OPT_ARGS_STR)
  1061. {
  1062. if(action & GMSH_SET)
  1063. CTX::instance()->solver.name[num] = val;
  1064. return CTX::instance()->solver.name[num];
  1065. }
  1066. std::string opt_solver_name0(OPT_ARGS_STR)
  1067. {
  1068. return opt_solver_name(0, action, val);
  1069. }
  1070. std::string opt_solver_name1(OPT_ARGS_STR)
  1071. {
  1072. return opt_solver_name(1, action, val);
  1073. }
  1074. std::string opt_solver_name2(OPT_ARGS_STR)
  1075. {
  1076. return opt_solver_name(2, action, val);
  1077. }
  1078. std::string opt_solver_name3(OPT_ARGS_STR)
  1079. {
  1080. return opt_solver_name(3, action, val);
  1081. }
  1082. std::string opt_solver_name4(OPT_ARGS_STR)
  1083. {
  1084. return opt_solver_name(4, action, val);
  1085. }
  1086. std::string opt_solver_executable(OPT_ARGS_STR)
  1087. {
  1088. if(action & GMSH_SET)
  1089. CTX::instance()->solver.executable[num] = val;
  1090. return CTX::instance()->solver.executable[num];
  1091. }
  1092. std::string opt_solver_executable0(OPT_ARGS_STR)
  1093. {
  1094. return opt_solver_executable(0, action, val);
  1095. }
  1096. std::string opt_solver_executable1(OPT_ARGS_STR)
  1097. {
  1098. return opt_solver_executable(1, action, val);
  1099. }
  1100. std::string opt_solver_executable2(OPT_ARGS_STR)
  1101. {
  1102. return opt_solver_executable(2, action, val);
  1103. }
  1104. std::string opt_solver_executable3(OPT_ARGS_STR)
  1105. {
  1106. return opt_solver_executable(3, action, val);
  1107. }
  1108. std::string opt_solver_executable4(OPT_ARGS_STR)
  1109. {
  1110. return opt_solver_executable(4, action, val);
  1111. }
  1112. std::string opt_solver_remote_login(OPT_ARGS_STR)
  1113. {
  1114. if(action & GMSH_SET)
  1115. CTX::instance()->solver.remoteLogin[num] = val;
  1116. return CTX::instance()->solver.remoteLogin[num];
  1117. }
  1118. std::string opt_solver_remote_login0(OPT_ARGS_STR)
  1119. {
  1120. return opt_solver_remote_login(0, action, val);
  1121. }
  1122. std::string opt_solver_remote_login1(OPT_ARGS_STR)
  1123. {
  1124. return opt_solver_remote_login(1, action, val);
  1125. }
  1126. std::string opt_solver_remote_login2(OPT_ARGS_STR)
  1127. {
  1128. return opt_solver_remote_login(2, action, val);
  1129. }
  1130. std::string opt_solver_remote_login3(OPT_ARGS_STR)
  1131. {
  1132. return opt_solver_remote_login(3, action, val);
  1133. }
  1134. std::string opt_solver_remote_login4(OPT_ARGS_STR)
  1135. {
  1136. return opt_solver_remote_login(4, action, val);
  1137. }
  1138. #if defined(HAVE_FLTK)
  1139. int _gui_action_valid(int action, int num)
  1140. {
  1141. if(!FlGui::available()) return 0;
  1142. return (action & GMSH_GUI) && (num == FlGui::instance()->options->view.index);
  1143. }
  1144. #endif
  1145. std::string opt_view_name(OPT_ARGS_STR)
  1146. {
  1147. #if defined(HAVE_POST)
  1148. GET_VIEWd("");
  1149. if(!data) return "";
  1150. if(action & GMSH_SET) {
  1151. data->setName(val);
  1152. #if defined(HAVE_FLTK)
  1153. // change name in GUI for the view and its aliases
  1154. if(FlGui::available()){
  1155. for(int i = 0; i < (int)PView::list.size(); i++){
  1156. if((i == num ||
  1157. PView::list[i]->getAliasOf() == view->getNum() ||
  1158. PView::list[i]->getNum() == view->getAliasOf()) &&
  1159. FlGui::instance()->onelab->getViewButton(i)) {
  1160. FlGui::instance()->onelab->getViewButton(i)->copy_label(data->getName());
  1161. FlGui::instance()->onelab->getViewButton(i)->redraw();
  1162. }
  1163. }
  1164. }
  1165. #endif
  1166. }
  1167. #if defined(HAVE_FLTK)
  1168. if(_gui_action_valid(action, num)) {
  1169. FlGui::instance()->options->view.input[0]->value(data->getName().c_str());
  1170. }
  1171. #endif
  1172. return data->getName();
  1173. #else
  1174. return "";
  1175. #endif
  1176. }
  1177. std::string opt_view_format(OPT_ARGS_STR)
  1178. {
  1179. #if defined(HAVE_POST)
  1180. GET_VIEWo("");
  1181. if(action & GMSH_SET) {
  1182. opt->format = val;
  1183. }
  1184. #if defined(HAVE_FLTK)
  1185. if(_gui_action_valid(action, num))
  1186. FlGui::instance()->options->view.input[1]->value(opt->format.c_str());
  1187. #endif
  1188. return opt->format;
  1189. #else
  1190. return "";
  1191. #endif
  1192. }
  1193. std::string opt_view_filename(OPT_ARGS_STR)
  1194. {
  1195. #if defined(HAVE_POST)
  1196. GET_VIEWd("");
  1197. if(!data) return "";
  1198. return data->getFileName();
  1199. #else
  1200. return "";
  1201. #endif
  1202. }
  1203. std::string opt_view_axes_label0(OPT_ARGS_STR)
  1204. {
  1205. #if defined(HAVE_POST)
  1206. GET_VIEWo("");
  1207. if(action & GMSH_SET) {
  1208. opt->axesLabel[0] = val;
  1209. }
  1210. #if defined(HAVE_FLTK)
  1211. if(_gui_action_valid(action, num))
  1212. FlGui::instance()->options->view.input[10]->value(opt->axesLabel[0].c_str());
  1213. #endif
  1214. return opt->axesLabel[0];
  1215. #else
  1216. return "";
  1217. #endif
  1218. }
  1219. std::string opt_view_axes_label1(OPT_ARGS_STR)
  1220. {
  1221. #if defined(HAVE_POST)
  1222. GET_VIEWo("");
  1223. if(action & GMSH_SET) {
  1224. opt->axesLabel[1] = val;
  1225. }
  1226. #if defined(HAVE_FLTK)
  1227. if(_gui_action_valid(action, num))
  1228. FlGui::instance()->options->view.input[11]->value(opt->axesLabel[1].c_str());
  1229. #endif
  1230. return opt->axesLabel[1];
  1231. #else
  1232. return "";
  1233. #endif
  1234. }
  1235. std::string opt_view_axes_label2(OPT_ARGS_STR)
  1236. {
  1237. #if defined(HAVE_POST)
  1238. GET_VIEWo("");
  1239. if(action & GMSH_SET) {
  1240. opt->axesLabel[2] = val;
  1241. }
  1242. #if defined(HAVE_FLTK)
  1243. if(_gui_action_valid(action, num))
  1244. FlGui::instance()->options->view.input[12]->value(opt->axesLabel[2].c_str());
  1245. #endif
  1246. return opt->axesLabel[2];
  1247. #else
  1248. return "";
  1249. #endif
  1250. }
  1251. std::string opt_view_axes_format0(OPT_ARGS_STR)
  1252. {
  1253. #if defined(HAVE_POST)
  1254. GET_VIEWo("");
  1255. if(action & GMSH_SET) {
  1256. opt->axesFormat[0] = val;
  1257. }
  1258. #if defined(HAVE_FLTK)
  1259. if(_gui_action_valid(action, num))
  1260. FlGui::instance()->options->view.input[7]->value(opt->axesFormat[0].c_str());
  1261. #endif
  1262. return opt->axesFormat[0];
  1263. #else
  1264. return "";
  1265. #endif
  1266. }
  1267. std::string opt_view_axes_format1(OPT_ARGS_STR)
  1268. {
  1269. #if defined(HAVE_POST)
  1270. GET_VIEWo("");
  1271. if(action & GMSH_SET) {
  1272. opt->axesFormat[1] = val;
  1273. }
  1274. #if defined(HAVE_FLTK)
  1275. if(_gui_action_valid(action, num))
  1276. FlGui::instance()->options->view.input[8]->value(opt->axesFormat[1].c_str());
  1277. #endif
  1278. return opt->axesFormat[1];
  1279. #else
  1280. return "";
  1281. #endif
  1282. }
  1283. std::string opt_view_axes_format2(OPT_ARGS_STR)
  1284. {
  1285. #if defined(HAVE_POST)
  1286. GET_VIEWo("");
  1287. if(action & GMSH_SET) {
  1288. opt->axesFormat[2] = val;
  1289. }
  1290. #if defined(HAVE_FLTK)
  1291. if(_gui_action_valid(action, num))
  1292. FlGui::instance()->options->view.input[9]->value(opt->axesFormat[2].c_str());
  1293. #endif
  1294. return opt->axesFormat[2];
  1295. #else
  1296. return "";
  1297. #endif
  1298. }
  1299. std::string opt_view_gen_raise0(OPT_ARGS_STR)
  1300. {
  1301. #if defined(HAVE_POST)
  1302. GET_VIEWo("");
  1303. if(action & GMSH_SET) {
  1304. opt->genRaiseX = val;
  1305. if(view) view->setChanged(true);
  1306. }
  1307. #if defined(HAVE_FLTK)
  1308. if(_gui_action_valid(action, num))
  1309. FlGui::instance()->options->view.input[4]->value(opt->genRaiseX.c_str());
  1310. #endif
  1311. return opt->genRaiseX;
  1312. #else
  1313. return "";
  1314. #endif
  1315. }
  1316. std::string opt_view_gen_raise1(OPT_ARGS_STR)
  1317. {
  1318. #if defined(HAVE_POST)
  1319. GET_VIEWo("");
  1320. if(action & GMSH_SET) {
  1321. opt->genRaiseY = val;
  1322. if(view) view->setChanged(true);
  1323. }
  1324. #if defined(HAVE_FLTK)
  1325. if(_gui_action_valid(action, num))
  1326. FlGui::instance()->options->view.input[5]->value(opt->genRaiseY.c_str());
  1327. #endif
  1328. return opt->genRaiseY;
  1329. #else
  1330. return "";
  1331. #endif
  1332. }
  1333. std::string opt_view_gen_raise2(OPT_ARGS_STR)
  1334. {
  1335. #if defined(HAVE_POST)
  1336. GET_VIEWo("");
  1337. if(action & GMSH_SET) {
  1338. opt->genRaiseZ = val;
  1339. if(view) view->setChanged(true);
  1340. }
  1341. #if defined(HAVE_FLTK)
  1342. if(_gui_action_valid(action, num))
  1343. FlGui::instance()->options->view.input[6]->value(opt->genRaiseZ.c_str());
  1344. #endif
  1345. return opt->genRaiseZ;
  1346. #else
  1347. return "";
  1348. #endif
  1349. }
  1350. int _h2d(char c)
  1351. {
  1352. switch(c){
  1353. case 'a': case 'A': return 10;
  1354. case 'b': case 'B': return 11;
  1355. case 'c': case 'C': return 12;
  1356. case 'd': case 'D': return 13;
  1357. case 'e': case 'E': return 14;
  1358. case 'f': case 'F': return 15;
  1359. default :
  1360. if(c >= '0' && c <= '9')
  1361. return c - '0';
  1362. else
  1363. return 0;
  1364. }
  1365. }
  1366. void _string2stipple(std::string str, int &repeat, int &pattern)
  1367. {
  1368. // "n*0xabcd"
  1369. if(str.size() < 8){
  1370. repeat = 1;
  1371. pattern = 0xFFFF;
  1372. }
  1373. else if(str[1] != '*' || str[2] != '0' || str[3] != 'x'){
  1374. // bad format
  1375. repeat = 1;
  1376. pattern = 0xFFFF;
  1377. }
  1378. else{
  1379. repeat = (int)str[0] - '0';
  1380. pattern = 16 * 16 * 16 * _h2d(str[4]) + 16 * 16 * _h2d(str[5]) +
  1381. 16 * _h2d(str[6]) + _h2d(str[7]);
  1382. }
  1383. }
  1384. std::string opt_view_stipple0(OPT_ARGS_STR)
  1385. {
  1386. #if defined(HAVE_POST)
  1387. GET_VIEWo("");
  1388. if(action & GMSH_SET) {
  1389. opt->stippleString[0] = val;
  1390. _string2stipple(opt->stippleString[0], opt->stipple[0][0], opt->stipple[0][1]);
  1391. }
  1392. return opt->stippleString[0];
  1393. #else
  1394. return "";
  1395. #endif
  1396. }
  1397. std::string opt_view_stipple1(OPT_ARGS_STR)
  1398. {
  1399. #if defined(HAVE_POST)
  1400. GET_VIEWo("");
  1401. if(action & GMSH_SET) {
  1402. opt->stippleString[1] = val;
  1403. _string2stipple(opt->stippleString[1], opt->stipple[1][0], opt->stipple[1][1]);
  1404. }
  1405. return opt->stippleString[1];
  1406. #else
  1407. return "";
  1408. #endif
  1409. }
  1410. std::string opt_view_stipple2(OPT_ARGS_STR)
  1411. {
  1412. #if defined(HAVE_POST)
  1413. GET_VIEWo("");
  1414. if(action & GMSH_SET) {
  1415. opt->stippleString[2] = val;
  1416. _string2stipple(opt->stippleString[2], opt->stipple[2][0], opt->stipple[2][1]);
  1417. }
  1418. return opt->stippleString[2];
  1419. #else
  1420. return "";
  1421. #endif
  1422. }
  1423. std::string opt_view_stipple3(OPT_ARGS_STR)
  1424. {
  1425. #if defined(HAVE_POST)
  1426. GET_VIEWo("");
  1427. if(action & GMSH_SET) {
  1428. opt->stippleString[3] = val;
  1429. _string2stipple(opt->stippleString[3], opt->stipple[3][0], opt->stipple[3][1]);
  1430. }
  1431. return opt->stippleString[3];
  1432. #else
  1433. return "";
  1434. #endif
  1435. }
  1436. std::string opt_view_stipple4(OPT_ARGS_STR)
  1437. {
  1438. #if defined(HAVE_POST)
  1439. GET_VIEWo("");
  1440. if(action & GMSH_SET) {
  1441. opt->stippleString[4] = val;
  1442. _string2stipple(opt->stippleString[4], opt->stipple[4][0], opt->stipple[4][1]);
  1443. }
  1444. return opt->stippleString[4];
  1445. #else
  1446. return "";
  1447. #endif
  1448. }
  1449. std::string opt_view_stipple5(OPT_ARGS_STR)
  1450. {
  1451. #if defined(HAVE_POST)
  1452. GET_VIEWo("");
  1453. if(action & GMSH_SET) {
  1454. opt->stippleString[5] = val;
  1455. _string2stipple(opt->stippleString[5], opt->stipple[5][0], opt->stipple[5][1]);
  1456. }
  1457. return opt->stippleString[5];
  1458. #else
  1459. return "";
  1460. #endif
  1461. }
  1462. std::string opt_view_stipple6(OPT_ARGS_STR)
  1463. {
  1464. #if defined(HAVE_POST)
  1465. GET_VIEWo("");
  1466. if(action & GMSH_SET) {
  1467. opt->stippleString[6] = val;
  1468. _string2stipple(opt->stippleString[6], opt->stipple[6][0], opt->stipple[6][1]);
  1469. }
  1470. return opt->stippleString[6];
  1471. #else
  1472. return "";
  1473. #endif
  1474. }
  1475. std::string opt_view_stipple7(OPT_ARGS_STR)
  1476. {
  1477. #if defined(HAVE_POST)
  1478. GET_VIEWo("");
  1479. if(action & GMSH_SET) {
  1480. opt->stippleString[7] = val;
  1481. _string2stipple(opt->stippleString[7], opt->stipple[7][0], opt->stipple[7][1]);
  1482. }
  1483. return opt->stippleString[7];
  1484. #else
  1485. return "";
  1486. #endif
  1487. }
  1488. std::string opt_view_stipple8(OPT_ARGS_STR)
  1489. {
  1490. #if defined(HAVE_POST)
  1491. GET_VIEWo("");
  1492. if(action & GMSH_SET) {
  1493. opt->stippleString[8] = val;
  1494. _string2stipple(opt->stippleString[8], opt->stipple[8][0], opt->stipple[8][1]);
  1495. }
  1496. return opt->stippleString[8];
  1497. #else
  1498. return "";
  1499. #endif
  1500. }
  1501. std::string opt_view_stipple9(OPT_ARGS_STR)
  1502. {
  1503. #if defined(HAVE_POST)
  1504. GET_VIEWo("");
  1505. if(action & GMSH_SET) {
  1506. opt->stippleString[9] = val;
  1507. _string2stipple(opt->stippleString[9], opt->stipple[9][0], opt->stipple[9][1]);
  1508. }
  1509. return opt->stippleString[9];
  1510. #else
  1511. return "";
  1512. #endif
  1513. }
  1514. std::string opt_view_attributes(OPT_ARGS_STR)
  1515. {
  1516. #if defined(HAVE_POST)
  1517. GET_VIEWo("");
  1518. if(action & GMSH_SET)
  1519. opt->attributes = val;
  1520. return opt->attributes;
  1521. #else
  1522. return "";
  1523. #endif
  1524. }
  1525. // Numeric option routines
  1526. double opt_general_initial_context(OPT_ARGS_NUM)
  1527. {
  1528. if(action & GMSH_SET)
  1529. CTX::instance()->initialContext = (int)val;
  1530. return CTX::instance()->initialContext;
  1531. }
  1532. double opt_general_fontsize(OPT_ARGS_NUM)
  1533. {
  1534. if(action & GMSH_SET)
  1535. CTX::instance()->fontSize = (int)val;
  1536. return CTX::instance()->fontSize;
  1537. }
  1538. double opt_general_graphics_fontsize(OPT_ARGS_NUM)
  1539. {
  1540. if(action & GMSH_SET)
  1541. CTX::instance()->glFontSize = (int)val;
  1542. #if defined(HAVE_FLTK)
  1543. if(FlGui::available() && (action & GMSH_GUI))
  1544. FlGui::instance()->options->general.value[12]->value
  1545. (CTX::instance()->glFontSize);
  1546. #endif
  1547. return CTX::instance()->glFontSize;
  1548. }
  1549. double opt_general_graphics_fontsize_title(OPT_ARGS_NUM)
  1550. {
  1551. if(action & GMSH_SET)
  1552. CTX::instance()->glFontSizeTitle = (int)val;
  1553. #if defined(HAVE_FLTK)
  1554. if(FlGui::available() && (action & GMSH_GUI))
  1555. FlGui::instance()->options->general.value[28]->value
  1556. (CTX::instance()->glFontSizeTitle);
  1557. #endif
  1558. return CTX::instance()->glFontSizeTitle;
  1559. }
  1560. double opt_general_polygon_offset_always(OPT_ARGS_NUM)
  1561. {
  1562. if(action & GMSH_SET)
  1563. CTX::instance()->polygonOffsetAlways = (int)val;
  1564. #if defined(HAVE_FLTK)
  1565. if(FlGui::available() && (action & GMSH_GUI))
  1566. FlGui::instance()->options->general.butt[4]->value
  1567. (CTX::instance()->polygonOffsetAlways);
  1568. #endif
  1569. return CTX::instance()->polygonOffsetAlways;
  1570. }
  1571. double opt_general_polygon_offset_factor(OPT_ARGS_NUM)
  1572. {
  1573. if(action & GMSH_SET)
  1574. CTX::instance()->polygonOffsetFactor = val;
  1575. #if defined(HAVE_FLTK)
  1576. if(FlGui::available() && (action & GMSH_GUI))
  1577. FlGui::instance()->options->general.value[15]->value
  1578. (CTX::instance()->polygonOffsetFactor);
  1579. #endif
  1580. return CTX::instance()->polygonOffsetFactor;
  1581. }
  1582. double opt_general_polygon_offset_units(OPT_ARGS_NUM)
  1583. {
  1584. if(action & GMSH_SET)
  1585. CTX::instance()->polygonOffsetUnits = val;
  1586. #if defined(HAVE_FLTK)
  1587. if(FlGui::available() && (action & GMSH_GUI))
  1588. FlGui::instance()->options->general.value[16]->value
  1589. (CTX::instance()->polygonOffsetUnits);
  1590. #endif
  1591. return CTX::instance()->polygonOffsetUnits;
  1592. }
  1593. double opt_general_graphics_position0(OPT_ARGS_NUM)
  1594. {
  1595. if(action & GMSH_SET)
  1596. CTX::instance()->glPosition[0] = (int)val;
  1597. re

Large files files are truncated, but you can click here to view the full file