diff --git a/Box/Box.cpp b/Box/Box.cpp index c512b7f54e7d89f03dea31fb1493baf2103f3d0c..69998dd2a0cece47d2ea3624af2dcc550b66108a 100644 --- a/Box/Box.cpp +++ b/Box/Box.cpp @@ -1,4 +1,4 @@ -// $Id: Box.cpp,v 1.43 2008-02-17 08:47:55 geuzaine Exp $ +// $Id: Box.cpp,v 1.44 2008-03-11 20:03:09 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -19,11 +19,9 @@ // // Please report all bugs and problems to <gmsh@geuz.org>. -#include <signal.h> #include "GModel.h" +#include "Gmsh.h" #include "Message.h" -#include "OS.h" -#include "Numeric.h" #include "Generator.h" #include "Parser.h" #include "Context.h" @@ -32,7 +30,6 @@ #include "CommandLine.h" #include "CreateFile.h" #include "ParUtil.h" -#include "PluginManager.h" #include "Field.h" #include "BackgroundMesh.h" @@ -40,7 +37,7 @@ Context_T CTX; // Print some help/info messages -void Info(int level, char *arg0) +static void Info(int level, char *arg0) { switch (level) { case 0: @@ -76,28 +73,11 @@ int GMSHBOX(int argc, char *argv[]) { ParUtil::Instance()->init(argc, argv); - new GModel; - - InitSymbols(); - Init_Options(0); - - if(argc < 2) - Info(0, argv[0]); - - Get_Options(argc, argv); - - // FIXME: could not make this work on IRIX -#if !defined(__sgi__) - signal(SIGINT, Signal); - signal(SIGSEGV, Signal); - signal(SIGFPE, Signal); -#endif + if(argc < 2) Info(0, argv[0]); - CheckResources(); + GmshInitialize(argc, argv); - GMSH_PluginManager::instance()->registerDefaultPlugins(); - - check_gsl(); + new GModel; OpenProject(CTX.filename); if(gmsh_yyerrorstate) @@ -118,7 +98,7 @@ int GMSHBOX(int argc, char *argv[]) } } if(CTX.batch > 0) { - GenerateMesh(CTX.batch); + GModel::current()->mesh(CTX.batch); CreateOutputFile(CTX.output_filename, CTX.mesh.format); } else if(CTX.batch == -1) @@ -128,29 +108,11 @@ int GMSHBOX(int argc, char *argv[]) } ParUtil::Instance()->Barrier(__LINE__, __FILE__); + GmshFinalize(); + return 1; } -// Handle signals. We should not use Msg functions in these... - -void Signal(int sig_num) -{ - switch (sig_num) { - case SIGSEGV: - Msg(FATAL, "Segmentation violation (invalid memory reference)"); - break; - case SIGFPE: - Msg(FATAL, "Floating point exception (division by zero?)"); - break; - case SIGINT: - Msg(FATAL, "Interrupt (generated from terminal special char)"); - break; - default: - Msg(FATAL, "Unknown signal"); - break; - } -} - // General purpose message routine void Msg(int level, const char *fmt, ...) diff --git a/Common/Gmsh.cpp b/Common/Gmsh.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d1b563cbf5d2e7cfce8565631bf6cd881e16723f --- /dev/null +++ b/Common/Gmsh.cpp @@ -0,0 +1,55 @@ +// $Id: Gmsh.cpp,v 1.1 2008-03-11 20:03:09 geuzaine Exp $ +// +// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems to <gmsh@geuz.org>. + +#include "Parser.h" +#include "Options.h" +#include "CommandLine.h" +#include "OS.h" +#include "PluginManager.h" +#include "Numeric.h" + +int GmshInitialize(int argc, char **argv) +{ + // Initialize the symbol tree that will hold variable names in the + // parser + InitSymbols(); + + // Load default options + Init_Options(0); + + // Read configuration files and command line options + Get_Options(argc, argv); + + // Make sure we have enough resources (stack) + CheckResources(); + + // Initialize the default plugins + GMSH_PluginManager::instance()->registerDefaultPlugins(); + + // Check for buggy obsolete GSL versions + check_gsl(); + return 1; +} + +int GmshFinalize() +{ + return 1; +} diff --git a/Common/Gmsh.h b/Common/Gmsh.h new file mode 100644 index 0000000000000000000000000000000000000000..dbf587db048f83533c9e6e261f8eec0ca72d3f58 --- /dev/null +++ b/Common/Gmsh.h @@ -0,0 +1,25 @@ +#ifndef _GMSH_H_ +#define _GMSH_H_ + +// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // USA. +// +// Please report all bugs and problems to <gmsh@geuz.org>. + +int GmshInitialize(int argc, char **argv); +int GmshFinalize(); + +#endif diff --git a/Common/Makefile b/Common/Makefile index 5b76aa2fb2fe99286568b3cc348d45fc53991a35..67c941f630c926e24230c35fdf8b1e827e07e151 100644 --- a/Common/Makefile +++ b/Common/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.160 2008-03-10 16:01:15 geuzaine Exp $ +# $Id: Makefile,v 1.161 2008-03-11 20:03:09 geuzaine Exp $ # # Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle # @@ -34,6 +34,7 @@ SRC = Context.cpp\ Octree.cpp OctreeInternals.cpp\ Options.cpp\ CommandLine.cpp\ + Gmsh.cpp\ OS.cpp\ Visibility.cpp\ Trackball.cpp\ @@ -94,6 +95,14 @@ CommandLine.o: CommandLine.cpp GmshUI.h GmshDefines.h GmshVersion.h \ ../Geo/GPoint.h ../Geo/GEdgeLoop.h ../Geo/GEdge.h ../Geo/SPoint2.h \ ../Geo/SVector3.h ../Geo/Pair.h ../Geo/GRegion.h ../Geo/GEntity.h \ ../Geo/SBoundingBox3d.h OS.h +Gmsh.o: Gmsh.cpp ../Parser/Parser.h ../DataStr/List.h ../DataStr/Tree.h \ + ../DataStr/avl.h Options.h ../Post/ColorTable.h CommandLine.h OS.h \ + ../Plugin/PluginManager.h ../Plugin/Plugin.h ../Common/Options.h \ + ../Common/Message.h ../Post/PView.h ../Post/PViewData.h \ + ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Post/PViewOptions.h \ + ../Post/ColorTable.h ../Post/PViewDataList.h ../Post/PViewData.h \ + ../Post/AdaptiveViews.h ../Common/GmshMatrix.h ../Numeric/Numeric.h \ + ../Numeric/NumericEmbedded.h OS.o: OS.cpp Message.h Visibility.o: Visibility.cpp Visibility.h GmshDefines.h ../Geo/GVertex.h \ ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \ diff --git a/Common/Message.h b/Common/Message.h index 4e7810319fdc7a150ccfbe9550e52da49e27617c..4a4d76f99f05b18a7ab92b7dee78a421198f89e8 100644 --- a/Common/Message.h +++ b/Common/Message.h @@ -69,7 +69,6 @@ #define DEBUG_STR "Debug : " #define STATUS_STR "Info : " -void Signal(int signum); void Msg(int level, const char *fmt, ...); void Exit(int); double GetValue(const char *text, double defaultval); diff --git a/Common/Options.cpp b/Common/Options.cpp index edce452d98b8cad9086de66ce4e376e949d48136..f4ceecc3635028252f7f02fd90d83df9cf0c67b5 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -1,4 +1,4 @@ -// $Id: Options.cpp,v 1.385 2008-02-23 15:30:06 geuzaine Exp $ +// $Id: Options.cpp,v 1.386 2008-03-11 20:03:09 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -72,7 +72,7 @@ void Init_Options_Safe(int num) Set_DefaultColorOptions(num, PrintOptions_Color); } -const char *gmsh_getenv(const char *var) +static const char *gmsh_getenv(const char *var) { #if !defined(WIN32) return getenv(var); @@ -185,7 +185,7 @@ void Init_Options_GUI(int num) Set_ColorOptions_GUI(num, PrintOptions_Color); } -void Print_OptionCategory(int level, int diff, int help, const char *cat, FILE *file) +static void Print_OptionCategory(int level, int diff, int help, const char *cat, FILE *file) { if(diff || !help || !(level & GMSH_FULLRC)) return; @@ -214,7 +214,7 @@ GmshColorTable *Get_ColorTable(int num) return &opt->CT; } -void Print_ColorTable(int num, int diff, const char *prefix, FILE *file) +static void Print_ColorTable(int num, int diff, const char *prefix, FILE *file) { PViewOptions *opt; if(PView::list.empty() || num < 0 || num > (int)PView::list.size() - 1) @@ -359,7 +359,7 @@ void Print_Options(int num, int level, int diff, int help, const char *filename) if(filename) fclose(file); } -const char *Get_OptionSaveLevel(int level){ +static const char *Get_OptionSaveLevel(int level){ if(level & GMSH_SESSIONRC){ return "General.SessionFileName"; } diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index 1b5af9a12314e1189f2cc81048958c63bc89bbe6..ead665a313df941b7ab1af47ea6fb35d15d7681f 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -1,4 +1,4 @@ -// $Id: Callbacks.cpp,v 1.565 2008-02-23 15:30:06 geuzaine Exp $ +// $Id: Callbacks.cpp,v 1.566 2008-03-11 20:03:09 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -3670,21 +3670,21 @@ void mesh_define_cb(CALLBACK_ARGS) void mesh_1d_cb(CALLBACK_ARGS) { - GenerateMesh(1); + GModel::current()->mesh(1); Draw(); Msg(STATUS2N, " "); } void mesh_2d_cb(CALLBACK_ARGS) { - GenerateMesh(2); + GModel::current()->mesh(2); Draw(); Msg(STATUS2N, " "); } void mesh_3d_cb(CALLBACK_ARGS) { - GenerateMesh(3); + GModel::current()->mesh(3); Draw(); Msg(STATUS2N, " "); } diff --git a/Fltk/GUI_Projection.cpp b/Fltk/GUI_Projection.cpp index 9870eb8800ab70b506eec6445a31cf4bfefcfe34..52912c1f70e37928d6570092a3abd7bbed733c62 100644 --- a/Fltk/GUI_Projection.cpp +++ b/Fltk/GUI_Projection.cpp @@ -931,7 +931,7 @@ void compute_cb(Fl_Widget *w, void *data) // create the US-FFT/Windowing faces (with boundaries) FM::Patch* patch = new FM::WFPatch(0, ps->clone(), u, v, f, 3, uModes, vModes); - makeGFace(patch); + makeGFace(GModel::current(), patch); } else { // create the Fourier faces (with boundaries) @@ -941,13 +941,13 @@ void compute_cb(Fl_Widget *w, void *data) uM, vM, h0, h1, h2, h3); patchL->SetMinU(-0.35); patchL->SetMaxU(0.35); - makeGFace(patchL); + makeGFace(GModel::current(), patchL); FM::Patch* patchR = new FM::FPatch(0, ps->clone(), u, v, f, 3, uModes, vModes, uM, vM, h0, h1, h2, h3); patchR->SetMinU(0.15); patchR->SetMaxU(0.85); - makeGFace(patchR); + makeGFace(GModel::current(), patchR); } else if (ps->IsVPeriodic()) { FM::Patch* patchL = @@ -955,19 +955,19 @@ void compute_cb(Fl_Widget *w, void *data) uM, vM, h0, h1, h2, h3); patchL->SetMinV(-0.35); patchL->SetMaxV(0.35); - makeGFace(patchL); + makeGFace(GModel::current(), patchL); FM::Patch* patchR = new FM::FPatch(0, ps->clone(), u, v, f, 3, uModes, vModes, uM, vM, h0, h1, h2, h3); patchR->SetMinV(0.15); patchR->SetMaxV(0.85); - makeGFace(patchR); + makeGFace(GModel::current(), patchR); } else { FM::Patch* patch = new FM::FPatch(0, ps->clone(), u, v, f, 3, uModes, vModes, uM, vM, h0, h1, h2, h3); - makeGFace(patch); + makeGFace(GModel::current(), patch); } } } @@ -1011,7 +1011,7 @@ void blend_cb(Fl_Widget *w, void *data) FM::BlendOperator* blendOp = new FM::BlendOperator(patches); for (unsigned int i = 0; i < patches.size(); i++) { FM::BlendedPatch* patch = new FM::BlendedPatch(i, blendOp); - makeGFace(patch); + makeGFace(GModel::current(), patch); } for(unsigned int i = 0; i < faces.size(); i++) { delete_fourier(faces[i]); diff --git a/Fltk/Main.cpp b/Fltk/Main.cpp index 07a4dd95222c1772c6ab87cd9630dc47567a9e43..b3dbbe446b1fd1bf8a5a628bda993e6d1b4d289e 100644 --- a/Fltk/Main.cpp +++ b/Fltk/Main.cpp @@ -1,4 +1,4 @@ -// $Id: Main.cpp,v 1.117 2008-02-22 07:59:00 geuzaine Exp $ +// $Id: Main.cpp,v 1.118 2008-03-11 20:03:09 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -19,14 +19,12 @@ // // Please report all bugs and problems to <gmsh@geuz.org>. -#include <string.h> -#include <signal.h> +#include <string> #include <time.h> #include "GUI.h" +#include "Gmsh.h" #include "GmshUI.h" #include "Message.h" -#include "Malloc.h" -#include "OS.h" #include "Generator.h" #include "CreateFile.h" #include "Draw.h" @@ -35,7 +33,6 @@ #include "Parser.h" #include "OpenFile.h" #include "CommandLine.h" -#include "Numeric.h" #include "Solvers.h" #include "PluginManager.h" #include "GModel.h" @@ -48,66 +45,37 @@ GUI *WID = 0; int main(int argc, char *argv[]) { - char *cmdline, currtime[100]; - time_t now; - // Log some info + time_t now; time(&now); - strcpy(currtime, ctime(&now)); - currtime[strlen(currtime) - 1] = '\0'; - - int cll = 0; - for(int i = 0; i < argc; i++) { - cll += strlen(argv[i]); - } - cmdline = (char*)Malloc((cll+argc+1)*sizeof(char)); - cmdline[0] = '\0'; - for(int i = 0; i < argc; i++) { - strcat(cmdline, argv[i]); - strcat(cmdline, " "); + std::string currtime(ctime(&now)); + std::string cmdline; + for(int i = 0; i < argc; i++){ + cmdline += argv[i]; + cmdline += " "; } - // Create a new model - new GModel; - - // Initialize the symbol tree that will hold variable names - InitSymbols(); - - // Load default options - Init_Options(0); - - // Generate automatic documentation (before getting user-defined options) - if(argc == 2 && !strcmp(argv[1], "-doc")){ - // force all plugins for the doc + // Hack to generate automatic documentation (before getting + // user-defined options) + if(argc == 2 && std::string(argv[1]) == "-doc"){ + Init_Options(0); GMSH_PluginManager::instance()->registerDefaultPlugins(); Print_OptionsDoc(); exit(0); } - // Read configuration files and command line options - Get_Options(argc, argv); + // Initialize static stuff (parser symbols, options) + GmshInitialize(argc, argv); // Always print info on terminal for non-interactive execution - if(CTX.batch) - CTX.terminal = 1; - - // Signal handling - // FIXME: could not make this work on IRIX -#if !defined(__sgi__) - signal(SIGINT, Signal); - signal(SIGSEGV, Signal); - signal(SIGFPE, Signal); -#endif - - CheckResources(); - - // Initialize the default plugins - GMSH_PluginManager::instance()->registerDefaultPlugins(); + if(CTX.batch) CTX.terminal = 1; + + // Create a new model + new GModel; // Non-interactive Gmsh if(CTX.batch) { - check_gsl(); - Msg(INFO, "'%s' started on %s", cmdline, currtime); + Msg(INFO, "'%s' started on %s", cmdline.c_str(), currtime.c_str()); OpenProject(CTX.filename); if(gmsh_yyerrorstate) exit(1); @@ -127,11 +95,11 @@ int main(int argc, char *argv[]) Msg(GERROR, "Invalid background mesh (no view)"); } if(CTX.batch == 4) { - AdaptMesh(); + AdaptMesh(GModel::current()); CreateOutputFile(CTX.output_filename, CTX.mesh.format); } else if(CTX.batch > 0) { - GenerateMesh(CTX.batch); + GModel::current()->mesh(CTX.batch); CreateOutputFile(CTX.output_filename, CTX.mesh.format); } else if(CTX.batch == -1) @@ -142,7 +110,6 @@ int main(int argc, char *argv[]) } } - // Interactive Gmsh CTX.batch = -1; // The GUI is not ready yet for interactivity @@ -168,15 +135,10 @@ int main(int argc, char *argv[]) Msg(INFO, gmsh_host); Msg(INFO, gmsh_packager); Msg(INFO, "Home directory : %s", CTX.home_dir); - Msg(INFO, "Launch date : %s", currtime); - Msg(INFO, "Command line : %s", cmdline); + Msg(INFO, "Launch date : %s", currtime.c_str()); + Msg(INFO, "Command line : %s", cmdline.c_str()); Msg(INFO, "-------------------------------------------------------"); - Free(cmdline); - - // Check for buggy obsolete GSL versions - check_gsl(); - // Display the GUI immediately to have a quick "a la Windows" launch time WID->check(); @@ -191,18 +153,10 @@ int main(int argc, char *argv[]) // Init first context switch (CTX.initial_context) { - case 1: - WID->set_context(menu_geometry, 0); - break; - case 2: - WID->set_context(menu_mesh, 0); - break; - case 3: - WID->set_context(menu_solver, 0); - break; - case 4: - WID->set_context(menu_post, 0); - break; + case 1: WID->set_context(menu_geometry, 0); break; + case 2: WID->set_context(menu_mesh, 0); break; + case 3: WID->set_context(menu_solver, 0); break; + case 4: WID->set_context(menu_post, 0); break; default: // automatic if(PView::list.size()) WID->set_context(menu_post, 0); @@ -227,8 +181,7 @@ int main(int argc, char *argv[]) Draw(); // Listen to external solvers - if(CTX.solver.listen) - Solver(-1, NULL); + if(CTX.solver.listen) Solver(-1, NULL); // loop return WID->run(); diff --git a/Fltk/Makefile b/Fltk/Makefile index 5e0871310694ff0f9c6a67eccfe00b18d414ac08..e9be1aeee611a15745489a3acae8d71faf3ce0fa 100644 --- a/Fltk/Makefile +++ b/Fltk/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.172 2008-03-10 16:01:15 geuzaine Exp $ +# $Id: Makefile,v 1.173 2008-03-11 20:03:09 geuzaine Exp $ # # Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle # @@ -70,13 +70,12 @@ depend: # DO NOT DELETE THIS LINE Main.o: Main.cpp GUI.h Opengl_Window.h Colorbar_Window.h \ ../Common/GmshUI.h ../Post/ColorTable.h Popup_Button.h \ - SpherePosition_Widget.h ../Common/Message.h ../DataStr/Malloc.h \ - ../Common/OS.h ../Mesh/Generator.h ../Parser/CreateFile.h \ - ../Graphics/Draw.h ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h \ - ../Common/Context.h ../DataStr/List.h ../Common/Options.h \ - ../Parser/Parser.h ../DataStr/Tree.h ../DataStr/avl.h \ - ../Parser/OpenFile.h ../Common/CommandLine.h ../Numeric/Numeric.h \ - ../Numeric/NumericEmbedded.h Solvers.h ../Plugin/PluginManager.h \ + SpherePosition_Widget.h ../Common/Gmsh.h ../Common/Message.h \ + ../Mesh/Generator.h ../Parser/CreateFile.h ../Graphics/Draw.h \ + ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Common/Context.h \ + ../DataStr/List.h ../Common/Options.h ../Parser/Parser.h \ + ../DataStr/Tree.h ../DataStr/avl.h ../Parser/OpenFile.h \ + ../Common/CommandLine.h Solvers.h ../Plugin/PluginManager.h \ ../Plugin/Plugin.h ../Post/PView.h ../Post/PViewData.h \ ../Post/PViewOptions.h ../Post/ColorTable.h ../Post/PViewDataList.h \ ../Post/PViewData.h ../Post/AdaptiveViews.h ../Common/GmshMatrix.h \ @@ -90,9 +89,9 @@ Main.o: Main.cpp GUI.h Opengl_Window.h Colorbar_Window.h \ ../Mesh/Field.h ../Geo/Geo.h ../Common/GmshDefines.h \ ../Geo/gmshSurface.h ../Geo/Pair.h ../Geo/Range.h ../Geo/SPoint2.h \ ../Geo/SPoint3.h ../Geo/SVector3.h ../Geo/SBoundingBox3d.h \ - ../Geo/SPoint2.h ../Geo/ExtrudeParams.h ../Common/SmoothData.h \ - ../Post/OctreePost.h ../Common/Octree.h ../Common/OctreeInternals.h \ - ../Mesh/BackgroundMesh.h + ../Numeric/Numeric.h ../Numeric/NumericEmbedded.h ../Geo/SPoint2.h \ + ../Geo/ExtrudeParams.h ../Common/SmoothData.h ../Post/OctreePost.h \ + ../Common/Octree.h ../Common/OctreeInternals.h ../Mesh/BackgroundMesh.h Message.o: Message.cpp ../Common/Message.h ../Common/GmshUI.h \ ../Common/Context.h ../DataStr/List.h ../Common/Options.h \ ../Post/ColorTable.h GUI.h Opengl_Window.h Colorbar_Window.h \ diff --git a/Fltk/Message.cpp b/Fltk/Message.cpp index 5798500aea6bebfe1bb4aaa9cfc3b780d2d0ef4b..6d427d429edfde0b9d75ab702de0fe296eb57c43 100644 --- a/Fltk/Message.cpp +++ b/Fltk/Message.cpp @@ -1,4 +1,4 @@ -// $Id: Message.cpp,v 1.85 2008-02-23 15:30:07 geuzaine Exp $ +// $Id: Message.cpp,v 1.86 2008-03-11 20:03:10 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -20,7 +20,6 @@ // Please report all bugs and problems to <gmsh@geuz.org>. #include <string.h> -#include <signal.h> #include "Message.h" #include "GmshUI.h" #include "Context.h" @@ -32,32 +31,6 @@ extern GUI *WID; extern Context_T CTX; -// Handle signals. It is a crime to call stdio functions in a signal -// handler. But who cares? ;-) - -void Signal(int sig_num) -{ - switch (sig_num) { - case SIGSEGV: - Msg(FATAL1, "Segmentation violation (invalid memory reference)"); - Msg(FATAL2, "------------------------------------------------------"); - Msg(FATAL2, "You have discovered a bug in Gmsh! You may report it"); - Msg(FATAL2, "by e-mail (together with any helpful data permitting to"); - Msg(FATAL3, "reproduce it) to <gmsh@geuz.org>"); - break; - case SIGFPE: - Msg(FATAL, "Floating point exception (division by zero?)"); - break; - case SIGINT: - Msg(INFO, "Interrupt (generated from terminal special character)"); - Exit(1); - break; - default: - Msg(FATAL, "Unknown signal"); - break; - } -} - // General purpose message routine void Debug() diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index c81b31c02be113b251bec359139ad5506d506287..2d43ec00a3464f11716fb36340074b6850f859ac 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -1,4 +1,4 @@ -// $Id: GModel.cpp,v 1.68 2008-03-08 22:03:12 geuzaine Exp $ +// $Id: GModel.cpp,v 1.69 2008-03-11 20:03:10 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -29,6 +29,7 @@ # include "Message.h" # include "gmshSurface.h" # include "Field.h" +# include "Generator.h" # include "BackgroundMesh.h" # include "Context.h" #endif @@ -57,10 +58,8 @@ GModel::~GModel() GModel *GModel::current() { - if(list.empty()){ - Msg(GERROR, "No model available"); - return 0; - } + if(list.empty()) return 0; // not an error + // return last one for now return list.back(); } @@ -346,6 +345,17 @@ SBoundingBox3d GModel::bounds() return bb; } +int GModel::mesh(int dimension) +{ +#if !defined(HAVE_GMSH_EMBEDDED) + GenerateMesh(this, dimension); + return true; +#else + Msg(GERROR, "Embedded Gmsh cannot do mesh generation"); + return false; +#endif +} + int GModel::getMeshStatus(bool countDiscrete) { for(riter it = firstRegion(); it != lastRegion(); ++it) diff --git a/Geo/GModel.h b/Geo/GModel.h index 89ff9f056d83596f8a023d7f0a49f1a761381257..12648f5a2fbe563a3c12faa8dcac3327ec260ee0 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -183,6 +183,9 @@ class GModel // A container for smooth normals smooth_normals *normals; + // Mesh the model + int mesh(int dimension); + // Gmsh native CAD format int importGEOInternals(); int readGEO(const std::string &name); diff --git a/Geo/GModelIO_Fourier.cpp b/Geo/GModelIO_Fourier.cpp index 552f4b11cf212731a337d51d00106814990564ee..97efcb1d47542f7f0e39675b72cba1e23ea47614 100644 --- a/Geo/GModelIO_Fourier.cpp +++ b/Geo/GModelIO_Fourier.cpp @@ -15,7 +15,7 @@ #include "FM_TopoFace.h" #include "FM_Reader.h" -void makeGFace(FM::Patch* patch) +void makeGFace(GModel *m, FM::Patch* patch) { double LL[2], LR[2], UL[2], UR[2]; LL[0] = 0.0; LL[1] = 0.0; @@ -25,8 +25,6 @@ void makeGFace(FM::Patch* patch) int i1, i2; double xx,yy,zz; - - GModel *m = GModel::current(); int tagVertex = m->getNumVertices(); patch->F(LL[0], LL[1], xx, yy, zz); @@ -82,9 +80,9 @@ void makeGFace(FM::Patch* patch) int GModel::readFourier(const std::string &filename) { - FM::Reader* reader = new FM::Reader(filename.c_str()); + FM::Reader *reader = new FM::Reader(filename.c_str()); for (int i = 0; i < reader->GetNumPatches(); i++) - makeGFace(reader->GetPatch(i)); + makeGFace(this, reader->GetPatch(i)); return 1; } diff --git a/Geo/GModelIO_Fourier.h b/Geo/GModelIO_Fourier.h index a66848c7bde611b68bb3e3ab76313d3a0b4c340e..605a99d0f399cdc3939a0630b71229b1d11a572f 100644 --- a/Geo/GModelIO_Fourier.h +++ b/Geo/GModelIO_Fourier.h @@ -7,7 +7,7 @@ #include "FM_Patch.h" -void makeGFace(FM::Patch* patch); +void makeGFace(GModel *m, FM::Patch* patch); #endif diff --git a/Makefile b/Makefile index 961ace28287da318ef69f041383fcc920de97e3a..a6255e102aafcb47f6daaad31dc62fb66b587425 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.473 2008-03-10 16:01:15 geuzaine Exp $ +# $Id: Makefile,v 1.474 2008-03-11 20:03:09 geuzaine Exp $ # # Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle # @@ -39,7 +39,7 @@ GMSH_API = Geo/GModel.h\ Geo/MVertex.h Geo/MEdge.h Geo/MFace.h Geo/MElement.h\ Geo/SPoint2.h Geo/SPoint3.h Geo/SVector3.h Geo/SBoundingBox3d.h\ Geo/Pair.h Geo/Range.h\ - Common/GmshDefines.h Common/GmshVersion.h + Common/Gmsh.h Common/GmshDefines.h Common/GmshVersion.h GMSH_EMBEDDED = ${GMSH_API} Geo/discrete*.h\ Geo/GModel.cpp Geo/GModelIO_Mesh.cpp\ diff --git a/Mesh/Generator.cpp b/Mesh/Generator.cpp index eda50762e47a2c31a765af6a9c8e697cfeba8af4..97566e929c2992d01623c47773da7c60e648b68a 100644 --- a/Mesh/Generator.cpp +++ b/Mesh/Generator.cpp @@ -1,4 +1,4 @@ -// $Id: Generator.cpp,v 1.137 2008-02-24 14:55:36 geuzaine Exp $ +// $Id: Generator.cpp,v 1.138 2008-03-11 20:03:10 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -37,7 +37,7 @@ extern Context_T CTX; template<class T> -static void GetQualityMeasure(std::vector<T*>& ele, +static void GetQualityMeasure(std::vector<T*> &ele, double &gamma, double &gammaMin, double &gammaMax, double &eta, double &etaMin, double &etaMax, double &rho, double &rhoMin, double &rhoMax, @@ -70,6 +70,8 @@ void GetStatistics(double stat[50], double quality[3][100]) GModel *m = GModel::current(); + if(!m) return; + stat[0] = m->getNumVertices(); stat[1] = m->getNumEdges(); stat[2] = m->getNumFaces(); @@ -145,7 +147,7 @@ void GetStatistics(double stat[50], double quality[3][100]) } } -bool TooManyElements(GModel *m, int dim) +static bool TooManyElements(GModel *m, int dim) { if(CTX.expert_mode || !m->getNumVertices()) return false; @@ -165,7 +167,7 @@ bool TooManyElements(GModel *m, int dim) return false; } -void Mesh1D(GModel *m) +static void Mesh1D(GModel *m) { if(TooManyElements(m, 1)) return; Msg(STATUS1, "Meshing 1D..."); @@ -179,7 +181,7 @@ void Mesh1D(GModel *m) Msg(STATUS1, "Mesh"); } -void PrintMesh2dStatistics(GModel *m) +static void PrintMesh2dStatistics(GModel *m) { FILE *statreport = 0; if(CTX.create_append_statreport == 1) @@ -194,7 +196,7 @@ void PrintMesh2dStatistics(GModel *m) int nUnmeshed = 0, numFaces = 0; Msg(INFO,"2D Mesh Statistics :"); - for(GModel::fiter it = m->firstFace() ; it!=m->lastFace(); ++it){ + for(GModel::fiter it = m->firstFace() ; it != m->lastFace(); ++it){ worst = std::min((*it)->meshStatistics.worst_element_shape, worst); best = std::max((*it)->meshStatistics.best_element_shape, best); avg += (*it)->meshStatistics.average_element_shape * (*it)->meshStatistics.nbTriangle; @@ -226,7 +228,7 @@ void PrintMesh2dStatistics(GModel *m) fclose(statreport); } -void Mesh2D(GModel *m) +static void Mesh2D(GModel *m) { if(TooManyElements(m, 2)) return; @@ -272,15 +274,14 @@ void Mesh2D(GModel *m) PrintMesh2dStatistics(m); } - -void FindConnectedRegions(std::vector<GRegion*> &delaunay, +static void FindConnectedRegions(std::vector<GRegion*> &delaunay, std::vector<std::vector<GRegion*> > &connected) { // FIXME: need to split region vector into connected components here! connected.push_back(delaunay); } -void Mesh3D(GModel *m) +static void Mesh3D(GModel *m) { if(TooManyElements(m, 3)) return; Msg(STATUS1, "Meshing 3D..."); @@ -335,7 +336,7 @@ void OptimizeMesh(GModel *m) Msg(STATUS1, "Mesh"); } -void AdaptMesh() +void AdaptMesh(GModel *m) { Msg(STATUS1, "Adapting the 3D Mesh..."); double t1 = Cpu(); @@ -347,8 +348,6 @@ void AdaptMesh() CTX.threads_lock = 1; - GModel *m = GModel::current(); - std::for_each(m->firstRegion(), m->lastRegion(), adaptMeshGRegion()); std::for_each(m->firstRegion(), m->lastRegion(), adaptMeshGRegion()); std::for_each(m->firstRegion(), m->lastRegion(), adaptMeshGRegion()); @@ -365,7 +364,7 @@ void AdaptMesh() Msg(STATUS1, "Mesh"); } -void GenerateMesh(int ask) +void GenerateMesh(GModel *m, int ask) { if(CTX.threads_lock) { Msg(INFO, "I'm busy! Ask me that later..."); @@ -373,8 +372,6 @@ void GenerateMesh(int ask) } CTX.threads_lock = 1; - GModel *m = GModel::current(); - int old = m->getMeshStatus(false); // Initialize pseudo random mesh generator with the same seed diff --git a/Mesh/Generator.h b/Mesh/Generator.h index e22d0c6ba774f5754073361559879b947166911e..931d4bd412419aaf57ef405623a0d54186dd01f2 100644 --- a/Mesh/Generator.h +++ b/Mesh/Generator.h @@ -23,8 +23,8 @@ class GModel; void GetStatistics(double stat[50], double quality[3][100]=0); -void AdaptMesh(); -void GenerateMesh(int dimension); +void AdaptMesh(GModel *m); +void GenerateMesh(GModel *m, int dimension); void OptimizeMesh(GModel *m); void OptimizeMeshNetgen(GModel *m); diff --git a/doc/texinfo/opt_general.texi b/doc/texinfo/opt_general.texi index 9a16dfd3b86789726a576d6740579a350c60ad4c..f804c625fa6a2d3612f3541537ff5a99fe37d2ef 100644 --- a/doc/texinfo/opt_general.texi +++ b/doc/texinfo/opt_general.texi @@ -76,7 +76,7 @@ Saved in: @code{-} @item General.TextEditor System command to launch a text editor@* -Default value: @code{"open -e %s"}@* +Default value: @code{"open -t %s"}@* Saved in: @code{General.OptionsFileName} @item General.TmpFileName @@ -716,7 +716,7 @@ Saved in: @code{General.OptionsFileName} @item General.PolygonOffsetFactor Polygon offset factor (offset = factor * DZ + r * units)@* -Default value: @code{1}@* +Default value: @code{0.5}@* Saved in: @code{General.OptionsFileName} @item General.PolygonOffsetUnits diff --git a/utils/embed/GmshEmbedded.cpp b/utils/embed/GmshEmbedded.cpp index 7d73949c0f4456f59b775dbe180516906d5a4b59..f13ecf4d1671c64ee82800b38ee6fa214b6a6ac0 100644 --- a/utils/embed/GmshEmbedded.cpp +++ b/utils/embed/GmshEmbedded.cpp @@ -7,6 +7,14 @@ void GModel::createGEOInternals(){} void GModel::deleteGEOInternals(){} void GModel::deleteOCCInternals(){} +void GmshInitialize(int argc, char **argv) +{ +} + +void GmshFinalize(int argc, char **argv) +{ +} + void Msg(int level, const char *fmt, ...) { va_list args; diff --git a/utils/embed/GmshEmbedded.h b/utils/embed/GmshEmbedded.h index 89586113ee0ad7c79f94fb0595713b7652c1164d..eacd93745237203b95694ac0fc73384a5c94228e 100644 --- a/utils/embed/GmshEmbedded.h +++ b/utils/embed/GmshEmbedded.h @@ -51,7 +51,6 @@ #define DEBUG_STR "Debug : " #define STATUS_STR "Info : " -void Signal(int signum); void Msg(int level, const char *fmt, ...); class Context_T{ diff --git a/utils/embed/Makefile b/utils/embed/Makefile index 9c865012525ecb7c704a870d1b3900e047c4f6ab..98ca20a57456506095883164947c24073dd75e97 100644 --- a/utils/embed/Makefile +++ b/utils/embed/Makefile @@ -13,6 +13,7 @@ SRC = GModel.cpp\ MElement.cpp\ MFace.cpp MVertex.cpp\ NumericEmbedded.cpp\ + StringUtils.cpp\ GmshEmbedded.cpp OBJ = ${SRC:.cpp=${OBJEXT}}