Skip to content
Snippets Groups Projects
CommandLine.cpp 38.5 KiB
Newer Older
Christophe Geuzaine's avatar
Christophe Geuzaine committed
// Gmsh - Copyright (C) 1997-2013 C. Geuzaine, J.-F. Remacle
Christophe Geuzaine's avatar
Christophe Geuzaine committed
// See the LICENSE.txt file for license information. Please report all
Christophe Geuzaine's avatar
Christophe Geuzaine committed
// bugs and problems to the public mailing list <gmsh@geuz.org>.
#include <string>
Christophe Geuzaine's avatar
Christophe Geuzaine committed
#include <string.h>
Claudine Bon's avatar
Claudine Bon committed
#include <stdlib.h>
Christophe Geuzaine's avatar
Christophe Geuzaine committed
#include <fstream>
#include "GmshConfig.h"
#include "GmshDefines.h"
#include "GmshVersion.h"
#include "GmshMessage.h"
#include "OpenFile.h"
#include "CommandLine.h"
#include "Context.h"
#include "Options.h"
#include "GModel.h"
#include "CreateFile.h"
#include "OS.h"
#if (FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION >= 3)
#if defined(HAVE_POST)
Christophe Geuzaine's avatar
Christophe Geuzaine committed
#if defined(HAVE_MESH)
#include "periodical.h"
#endif

int GetGmshMajorVersion(){ return GMSH_MAJOR_VERSION; }
int GetGmshMinorVersion(){ return GMSH_MINOR_VERSION; }
int GetGmshPatchVersion(){ return GMSH_PATCH_VERSION; }
const char *GetGmshExtraVersion(){ return GMSH_EXTRA_VERSION; }
const char *GetGmshVersion(){ return GMSH_VERSION; }
const char *GetGmshBuildDate(){ return GMSH_DATE; }
const char *GetGmshBuildHost(){ return GMSH_HOST; }
const char *GetGmshPackager(){ return GMSH_PACKAGER; }
const char *GetGmshBuildOS(){ return GMSH_OS; }
const char *GetGmshShortLicense(){ return GMSH_SHORT_LICENSE; }
const char *GetGmshBuildOptions(){ return GMSH_CONFIG_OPTIONS; }
Christophe Geuzaine's avatar
Christophe Geuzaine committed
std::vector<std::pair<std::string, std::string> > GetUsage()
  typedef std::pair<std::string, std::string> mp;
  std::vector<mp> s;
  s.push_back(mp("Geometry options:", ""));
  s.push_back(mp("-0",                 "Output unrolled geometry, then exit"));
  s.push_back(mp("-tol float",         "Set geometrical tolerance"));
  s.push_back(mp("-match",             "Match geometries and meshes"));
  s.push_back(mp("Mesh options:", ""));
  s.push_back(mp("-1, -2, -3",         "Perform 1D, 2D or 3D mesh generation, then exit"));
  s.push_back(mp("-format string",     "Select output mesh format (auto (default), msh, "
                                       "msh1, msh2, unv, vrml, ply2, stl, mesh, bdf, cgns, "
                                       "p3d, diff, med, ...)"));
  s.push_back(mp("-vmsh float",        "Select msh file version"));
  s.push_back(mp("-refine",            "Perform uniform mesh refinement, then exit"));
  s.push_back(mp("-part int",          "Partition after batch mesh generation"));
  s.push_back(mp("-partWeight tri|quad|tet|prism|hex int", "Weight of a triangle/quad/etc. "
                                                           "during partitioning"));
  s.push_back(mp("-renumber",          "Renumber the mesh elements after batch mesh generation"));
  s.push_back(mp("-saveall",           "Save all elements (discard physical group definitions)"));
  s.push_back(mp("-o file",            "Specify output file name"));
  s.push_back(mp("-bin",               "Use binary format when available"));
  s.push_back(mp("-parametric",        "Save vertices with their parametric coordinates"));
  s.push_back(mp("-numsubedges",       "Set num of subdivisions for high order element display"));
  s.push_back(mp("-algo string",       "Select mesh algorithm (meshadapt, del2d, front2d, "
                                        "delquad, del3d, front3d, mmg3d)"));
  s.push_back(mp("-smooth int",        "Set number of mesh smoothing steps"));
  s.push_back(mp("-order int",         "Set mesh order (1, ..., 5)"));
  s.push_back(mp("-hoOptimize",        "Optimize high order meshes"));
  s.push_back(mp("-hoMindisto float",  "Min high-order element quality before optim (0.0->1.0)"));
  s.push_back(mp("-hoNLayers int",     "Number of high order element layers to optimize"));
  s.push_back(mp("-hoElasticity float","Poisson ration for elasticity analogy (nu in [-1.0,0.5])"));
  s.push_back(mp("-optimize[_netgen]", "Optimize quality of tetrahedral elements"));
  s.push_back(mp("-optimize_lloyd",    "Optimize 2D meshes using Lloyd algorithm"));
  s.push_back(mp("-microstructure",    "Generate polycrystal Voronoi geometry"));
  s.push_back(mp("-clscale float",     "Set global mesh element size scaling factor"));
  s.push_back(mp("-clmin float",       "Set minimum mesh element size"));
  s.push_back(mp("-clmax float",       "Set maximum mesh element size"));
  s.push_back(mp("-anisoMax float",    "Set maximum anisotropy (only used in bamg for now)"));
  s.push_back(mp("-smoothRatio float", "Set smoothing ration between mesh sizes at nodes of "
                                       "a same edge (only used in bamg)"));
  s.push_back(mp("-clcurv",            "Automatically compute element sizes from curvatures"));
  s.push_back(mp("-epslc1d",           "Set accuracy of evaluation of LCFIELD for 1D mesh"));
  s.push_back(mp("-swapangle",         "Set the threshold angle (in degree) between two adjacent"
                                       " faces below which a swap is allowed"));
  s.push_back(mp("-rand float",        "Set random perturbation factor"));
  s.push_back(mp("-bgm file",          "Load background mesh from file"));
  s.push_back(mp("-check",             "Perform various consistency checks on mesh"));
  s.push_back(mp("-mpass int",         "Do several passes on the mesh for complex backround fields"));
  s.push_back(mp("-ignorePartBound",   "Ignore partitions boundaries"));
Christophe Geuzaine's avatar
 
Christophe Geuzaine committed
#if defined(HAVE_FLTK)
  s.push_back(mp("Post-processing options:", ""));
  s.push_back(mp("-link int",          "Select link mode between views (0, 1, 2, 3, 4)"));
  s.push_back(mp("-combine",           "Combine views having identical names into "
                                       "multi-time-step views"));
  s.push_back(mp("Display options:", ""));
  s.push_back(mp("-n",                 "Hide all meshes and post-processing views on startup"));
  s.push_back(mp("-nodb",              "Disable double buffering"));
  s.push_back(mp("-fontsize int",      "Specify the font size for the GUI"));
  s.push_back(mp("-theme string",      "Specify FLTK GUI theme"));
  s.push_back(mp("-display string",    "Specify display"));
  s.push_back(mp("-camera",            "Use camera mode view;"));
  s.push_back(mp("-stereo",            "OpenGL quad-buffered stereo rendering (requires "
                                       "special graphic card)"));
  s.push_back(mp("-gamepad",           "Use gamepad controller if available"));
  s.push_back(mp("Other options:", ""));
  s.push_back(mp("-",                  "Parse input files, then exit"));
  s.push_back(mp("-new",               "Create new model before merge next file"));
  s.push_back(mp("-merge",             "Merge next files"));
  s.push_back(mp("-open",              "Open next files"));
Christophe Geuzaine's avatar
 
Christophe Geuzaine committed
#if defined(HAVE_FLTK)
  s.push_back(mp("-a, -g, -m, -s, -p", "Start in automatic, geometry, mesh, solver or "
                                       "post-processing mode"));
  s.push_back(mp("-pid",               "Print process id on stdout"));
  s.push_back(mp("-listen",            "Always listen to incoming connection requests"));
  s.push_back(mp("-watch pattern",     "Pattern of files to merge as they become available"));
  s.push_back(mp("-v int",             "Set verbosity level"));
  s.push_back(mp("-nopopup",           "Don't popup dialog windows in scripts"));
  s.push_back(mp("-string \"string\"", "Parse option string at startup"));
  s.push_back(mp("-option file",       "Parse option file at startup"));
  s.push_back(mp("-convert files",     "Convert files into latest binary formats, then exit"));
  s.push_back(mp("-version",           "Show version number"));
  s.push_back(mp("-info",              "Show detailed version information"));
  s.push_back(mp("-help",              "Show command line usage"));
Christophe Geuzaine's avatar
Christophe Geuzaine committed
  return s;
}

std::vector<std::pair<std::string, std::string> > GetShortcutsUsage(const std::string &ctrl)
Christophe Geuzaine's avatar
Christophe Geuzaine committed
{
  std::string cc = ctrl;
Christophe Geuzaine's avatar
Christophe Geuzaine committed
#if defined(__APPLE__)
  if(cc.empty()) cc = "Cmd+";
Christophe Geuzaine's avatar
Christophe Geuzaine committed
#else
  if(cc.empty()) cc = "Ctrl+";
Christophe Geuzaine's avatar
Christophe Geuzaine committed
#endif
  typedef std::pair<std::string, std::string> mp;
  std::vector<mp> s;
  s.push_back(mp("Left arrow",     "Go to previous time step"));
  s.push_back(mp("Right arrow",    "Go to next time step"));
  s.push_back(mp("Up arrow",       "Make previous view visible"));
  s.push_back(mp("Down arrow",     "Make next view visible"));
  s.push_back(mp("0",              "Reload project file"));
  s.push_back(mp("1 or F1",        "Mesh lines"));
  s.push_back(mp("2 or F2",        "Mesh surfaces"));
  s.push_back(mp("3 or F3",        "Mesh volumes"));
  s.push_back(mp("Escape",         "Cancel lasso zoom/selection, toggle mouse selection ON/OFF"));
  s.push_back(mp("g",              "Go to geometry module"));
  s.push_back(mp("m",              "Go to mesh module"));
  s.push_back(mp("p",              "Go to post-processing module"));
  s.push_back(mp("s",              "Go to solver module"));
  s.push_back(mp("Shift+a",        "Bring all windows to front"));
  s.push_back(mp("Shift+g",        "Show geometry options"));
  s.push_back(mp("Shift+m",        "Show mesh options"));
  s.push_back(mp("Shift+o",        "Show general options"));
  s.push_back(mp("Shift+p",        "Show post-processing options"));
  s.push_back(mp("Shift+s",        "Show solver options"));
  s.push_back(mp("Shift+u",        "Show post-processing view plugins"));
  s.push_back(mp("Shift+w",        "Show post-processing view options"));
  s.push_back(mp("Shift+Escape",   "Enable full mouse selection"));
  s.push_back(mp(cc + "d",         "Attach/detach menu"));
Christophe Geuzaine's avatar
Christophe Geuzaine committed
  s.push_back(mp(cc + "f",         "Enter full screen"));
  s.push_back(mp(cc + "i",         "Show statistics window"));
  s.push_back(mp(cc + "j",         "Save model options"));
  s.push_back(mp(cc + "l",         "Show message console"));
Christophe Geuzaine's avatar
Christophe Geuzaine committed
#if defined(__APPLE__)
  s.push_back(mp(cc + "m",         "Minimize window"));
Christophe Geuzaine's avatar
Christophe Geuzaine committed
#endif
  s.push_back(mp(cc + "n",         "Create new project file"));
  s.push_back(mp(cc + "o",         "Open project file"));
  s.push_back(mp(cc + "q",         "Quit"));
  s.push_back(mp(cc + "r",         "Rename project file"));
  s.push_back(mp(cc + "s",         "Save file as"));
  s.push_back(mp("Shift+" + cc + "c", "Show clipping plane window"));
  s.push_back(mp("Shift+" + cc + "j", "Save options as default"));
  s.push_back(mp("Shift+" + cc + "m", "Show manipulator window"));
  s.push_back(mp("Shift+" + cc + "n", "Show option window"));
  s.push_back(mp("Shift+" + cc + "o", "Merge file(s)"));
  s.push_back(mp("Shift+" + cc + "s", "Save mesh in default format"));
  s.push_back(mp("Shift+" + cc + "u", "Show plugin window"));
  s.push_back(mp("Shift+" + cc + "v", "Show visibility window"));
  s.push_back(mp("Alt+a",          "Loop through axes modes"));
  s.push_back(mp("Alt+b",          "Hide/show bounding boxes"));
  s.push_back(mp("Alt+c",          "Loop through predefined color schemes"));
  s.push_back(mp("Alt+e",          "Hide/Show element outlines for visible post-pro views"));
  s.push_back(mp("Alt+f",          "Change redraw mode (fast/full)"));
  s.push_back(mp("Alt+h",          "Hide/show all post-processing views"));
  s.push_back(mp("Alt+i",          "Hide/show all post-processing view scales"));
  s.push_back(mp("Alt+l",          "Hide/show geometry lines"));
  s.push_back(mp("Alt+m",          "Toggle visibility of all mesh entities"));
  s.push_back(mp("Alt+n",          "Hide/show all post-processing view annotations"));
  s.push_back(mp("Alt+o",          "Change projection mode (orthographic/perspective)"));
  s.push_back(mp("Alt+p",          "Hide/show geometry points"));
  s.push_back(mp("Alt+r",          "Loop through range modes for visible post-pro views"));
  s.push_back(mp("Alt+s",          "Hide/show geometry surfaces"));
  s.push_back(mp("Alt+t",          "Loop through interval modes for visible post-pro views"));
  s.push_back(mp("Alt+v",          "Hide/show geometry volumes"));
  s.push_back(mp("Alt+w",          "Enable/disable all lighting"));
  s.push_back(mp("Alt+x",          "Set X view"));
  s.push_back(mp("Alt+y",          "Set Y view"));
  s.push_back(mp("Alt+z",          "Set Z view"));
  s.push_back(mp("Alt+Shift+a",    "Hide/show small axes"));
  s.push_back(mp("Alt+Shift+b",    "Hide/show mesh volume faces"));
  s.push_back(mp("Alt+Shift+d",    "Hide/show mesh surface faces"));
  s.push_back(mp("Alt+Shift+l",    "Hide/show mesh lines"));
  s.push_back(mp("Alt+Shift+o",    "Adjust projection parameters"));
  s.push_back(mp("Alt+Shift+p",    "Hide/show mesh points"));
  s.push_back(mp("Alt+Shift+s",    "Hide/show mesh surface edges"));
  s.push_back(mp("Alt+Shift+v",    "Hide/show mesh volume edges"));
  s.push_back(mp("Alt+Shift+w",    "Reverse all mesh normals"));
  s.push_back(mp("Alt+Shift+x",    "Set -X view"));
  s.push_back(mp("Alt+Shift+y",    "Set -Y view"));
  s.push_back(mp("Alt+Shift+z",    "Set -Z view"));
Christophe Geuzaine's avatar
Christophe Geuzaine committed
  return s;
}

std::vector<std::pair<std::string, std::string> > GetMouseUsage()
Christophe Geuzaine's avatar
Christophe Geuzaine committed
{
  typedef std::pair<std::string, std::string> mp;
  std::vector<mp> s;
  s.push_back(mp("Move", "- Highlight the entity under the mouse pointer and display its properties"));
  s.push_back(mp("",     "- Resize a lasso zoom or a lasso (un)selection"));
  s.push_back(mp("Left button", "- Rotate"));
  s.push_back(mp("",            "- Select an entity"));
  s.push_back(mp("",            "- Accept a lasso zoom or a lasso selection"));
  s.push_back(mp("Ctrl+Left button", "Start a lasso zoom or a lasso (un)selection"));
  s.push_back(mp("Middle button", "- Zoom"));
  s.push_back(mp("",              "- Unselect an entity"));
  s.push_back(mp("",              "- Accept a lasso zoom or a lasso unselection"));
  s.push_back(mp("Ctrl+Middle button", "Orthogonalize display"));
  s.push_back(mp("Right button", "- Pan"));
  s.push_back(mp("",             "- Cancel a lasso zoom or a lasso (un)selection"));
  s.push_back(mp("",             "- Pop-up menu on post-processing view button"));
  s.push_back(mp("Ctrl+Right button", "Reset to default viewpoint"));
Christophe Geuzaine's avatar
Christophe Geuzaine committed
  return s;
}

void PrintUsage(const std::string &name)
{
Christophe Geuzaine's avatar
Christophe Geuzaine committed
  Msg::Direct("Usage: %s [options] [files]", name.c_str());
  std::vector<std::pair<std::string, std::string> > s = GetUsage();
  for(unsigned int i = 0; i < s.size(); i++){
    std::string a = s[i].first, b = s[i].second;
    if(b.empty()){
      Msg::Direct("%s", a.c_str());
    }
    else{
      if(a.size() < 20) a.resize(20, ' ');
      Msg::Direct("  %s %s", a.c_str(), b.c_str());
    }
  }
void GetOptions(int argc, char *argv[])
Christophe Geuzaine's avatar
 
Christophe Geuzaine committed
{
  int terminal = CTX::instance()->terminal;
Christophe Geuzaine's avatar
Christophe Geuzaine committed
  CTX::instance()->terminal = 1;
#if defined(HAVE_PARSER)
  if(argc && argv){
    // parse session and option file (if argc/argv is not provided skip this
    // step: this is usually what is expected when using Gmsh as a library)
    ParseFile(CTX::instance()->homeDir + CTX::instance()->sessionFileName, true);
    ParseFile(CTX::instance()->homeDir + CTX::instance()->optionsFileName, true);
  }
#endif
Francois Henrotte's avatar
Francois Henrotte committed
  if(argc) Msg::SetExecutableName(argv[0]);
Christophe Geuzaine's avatar
 
Christophe Geuzaine committed
  int i = 1;
Christophe Geuzaine's avatar
 
Christophe Geuzaine committed
  while(i < argc) {

    if(argv[i][0] == '-') {

      if(!strcmp(argv[i] + 1, "")) {
        CTX::instance()->batch = -99;
        i++;
      }
      else if(!strcmp(argv[i] + 1, "onelab")) {
Christophe Geuzaine's avatar
Christophe Geuzaine committed
        if(argv[i] && argv[i + 1] && argv[i + 1][0] != '-'){
          Msg::InitializeOnelab(argv[i], argv[i + 1]);
          i += 2;
        }
        else if(argv[i]){
Christophe Geuzaine's avatar
Christophe Geuzaine committed
          Msg::InitializeOnelab(argv[i]);
          Msg::Fatal("Missing client name and/or address of OneLab server");
      else if(!strcmp(argv[i] + 1, "lol")) {
        if(argv[i] && argv[i + 1] && argv[i + 1][0] != '-'){
          Msg::LoadOnelabClient(argv[i], argv[i + 1]);
          i += 2;
        }
        else
          Msg::Fatal("Missing client name and/or address of OneLab server");
      else if(!strcmp(argv[i] + 1, "socket")) {
Christophe Geuzaine's avatar
 
Christophe Geuzaine committed
        if(argv[i])
          Msg::InitializeOnelab("GmshRemote", argv[i++]);
          Msg::Fatal("Missing string");
        CTX::instance()->batch = -3;
      else if(!strcmp(argv[i] + 1, "check")) {
        CTX::instance()->batch = -2;
        i++;
      }
      else if(!strcmp(argv[i] + 1, "0")) {
        CTX::instance()->batch = -1;
        i++;
      }
      else if(!strcmp(argv[i] + 1, "1")) {
        CTX::instance()->batch = 1;
        i++;
      }
      else if(!strcmp(argv[i] + 1, "2")) {
        CTX::instance()->batch = 2;
        i++;
      }
      else if(!strcmp(argv[i] + 1, "3")) {
        CTX::instance()->batch = 3;
      else if(!strcmp(argv[i] + 1, "4")) {
        CTX::instance()->batch = 4;
      else if(!strcmp(argv[i] + 1, "refine")) {
        CTX::instance()->batch = 5;
      else if(!strcmp(argv[i] + 1, "renumber")) {
        CTX::instance()->batchAfterMesh = 1;
Christophe Geuzaine's avatar
Christophe Geuzaine committed
        CTX::instance()->partitionOptions.renumber = 1;
Stefen Guzik's avatar
Stefen Guzik committed
      else if(!strcmp(argv[i] + 1, "part")) {
Christophe Geuzaine's avatar
 
Christophe Geuzaine committed
        if(argv[i]){
Christophe Geuzaine's avatar
Christophe Geuzaine committed
          CTX::instance()->batchAfterMesh = 1 ;
Christophe Geuzaine's avatar
 
Christophe Geuzaine committed
          opt_mesh_partition_num(0, GMSH_SET, atoi(argv[i++]));
        }
        else
Loading
Loading full blame...