diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp index ed6cf5ad84f01a2b183f0b89f2571ccc208fff98..4fe2722751f18d5954b3933f699397844e8f16c3 100644 --- a/Fltk/FlGui.cpp +++ b/Fltk/FlGui.cpp @@ -104,15 +104,11 @@ void FlGui::unlock() Fl::unlock(); } -int FlGui::locked() -{ - return _locked; -} +int FlGui::locked() { return _locked; } static void awake_cb(void *data) { - if(data) - FlGui::instance()->updateViews(true, false); + if(data) FlGui::instance()->updateViews(true, false); } void FlGui::awake(const std::string &action) @@ -120,7 +116,7 @@ void FlGui::awake(const std::string &action) if(action.empty()) Fl::awake(awake_cb, nullptr); else - Fl::awake(awake_cb, (void*)"update"); + Fl::awake(awake_cb, (void *)"update"); } void FlGui::setOpenedThroughMacFinder(const std::string &name) @@ -421,9 +417,9 @@ void FlGui::applyColorScheme(bool redraw) // thinner scrollbars Fl::scrollbar_size(std::max(10, FL_NORMAL_SIZE)); - if(redraw && available()){ + if(redraw && available()) { updateViews(true, true); - for (Fl_Window *win = Fl::first_window(); win; win = Fl::next_window(win)) { + for(Fl_Window *win = Fl::first_window(); win; win = Fl::next_window(win)) { win->redraw(); } } @@ -495,7 +491,8 @@ FlGui::FlGui(int argc, char **argv, bool quitShouldExit, applyColorScheme(); // add gamepad handler - if(CTX::instance()->gamepad) Fl::add_timeout(5., gamepad_handler, (void *)nullptr); + if(CTX::instance()->gamepad) + Fl::add_timeout(5., gamepad_handler, (void *)nullptr); // add global shortcuts Fl::add_handler(globalShortcut); @@ -1251,7 +1248,9 @@ void FlGui::setStatus(const std::string &msg, bool opengl) sprintf(n, "%d", ne ? ne : nw); tmp += n; tmp += (ne > 1) ? " Errors" : - ne ? " Error" : (nw > 1) ? " Warnings" : " Warning"; + ne ? " Error" : + (nw > 1) ? " Warnings" : + " Warning"; tmp += " : Click to show messages [ ... "; tmp += (ne ? Msg::GetFirstError() : Msg::GetFirstWarning()); tmp += " ... ]"; @@ -1503,10 +1502,8 @@ void FlGui::saveMessages(const char *fileName) void FlGui::rebuildTree(bool deleteWidgets) { - if(onelab) - onelab->rebuildTree(deleteWidgets); - if(onelabContext) - onelabContext->rebuild(deleteWidgets); + if(onelab) onelab->rebuildTree(deleteWidgets); + if(onelabContext) onelabContext->rebuild(deleteWidgets); } void FlGui::openModule(const std::string &name) diff --git a/Fltk/FlGui.h b/Fltk/FlGui.h index 39456745cd126ebe096a3190e878e2cdcb60471e..f4b17f077be17a431fca06f63a7838d4af57d928 100644 --- a/Fltk/FlGui.h +++ b/Fltk/FlGui.h @@ -161,7 +161,7 @@ public: // apply color scheme to widgets void applyColorScheme(bool redraw = false); // should the quit callback exit the app, or just close all windows? - bool quitShouldExit(){ return _quitShouldExit; } + bool quitShouldExit() { return _quitShouldExit; } }; void redraw_cb(Fl_Widget *w, void *data); diff --git a/Fltk/Navigator.cpp b/Fltk/Navigator.cpp index 536a9ad581d89cbf5c4748899dafd07fe70b37fb..f272522b06ea5e329e9276d50c20b36cb7e06b38 100644 --- a/Fltk/Navigator.cpp +++ b/Fltk/Navigator.cpp @@ -681,9 +681,7 @@ void Navigator::move() if(!pad->button[pad->button_map[4]]) { if(pad->axe[pad->axe_map[1]] != 0.) { acc = -pad->axe[pad->axe_map[1]] * ctx->camera.Lc / 500. * frequency; - if(acc > 0.) { - speed = reference_speed + acc; - } + if(acc > 0.) { speed = reference_speed + acc; } else { speed = reference_speed + 2. * acc; } @@ -720,18 +718,14 @@ void Navigator::move() angular_fr = 1.0 * (pad->axe[pad->axe_map[0]]) * reference_angle; if(pad->axe[pad->axe_map[1]] != 0.) { acc = -pad->axe[pad->axe_map[1]] * ctx->camera.Lc / 1000. * frequency; - if(acc > 0.) { - speed = reference_speed + acc; - } + if(acc > 0.) { speed = reference_speed + acc; } else { speed = reference_speed + 2. * acc; } speed = std::max(speed, (frequency * ctx->camera.Lc / 1000.)); reference_speed = std::min(speed, (frequency * (ctx->camera.Lc))); } - if(pad->button[pad->button_map[6]]) { - speed = reference_speed; - } + if(pad->button[pad->button_map[6]]) { speed = reference_speed; } else { speed = 0.; } @@ -747,11 +741,9 @@ void Navigator::move() //------------------------------------- break; // end of mode DIVER - case PLANE: - break; // end of mode PLANE + case PLANE: break; // end of mode PLANE - case CAR: - break; // end of mode CAR + case CAR: break; // end of mode CAR default: break; diff --git a/Fltk/classificationEditor.cpp b/Fltk/classificationEditor.cpp index ca155f66ce44f339ab7c383be580a9fff091d54f..3b3b9442ef64e55a8004905e0cddd1b9637df4f0 100644 --- a/Fltk/classificationEditor.cpp +++ b/Fltk/classificationEditor.cpp @@ -86,9 +86,9 @@ static void select_elements_cb(Fl_Widget *w, void *data) // allocate discrete edge to hold the selected mesh segments if(!e->selected) { - e->selected = - new discreteEdge(GModel::current(), - GModel::current()->getMaxElementaryNumber(1) + 1, nullptr, nullptr); + e->selected = new discreteEdge( + GModel::current(), GModel::current()->getMaxElementaryNumber(1) + 1, + nullptr, nullptr); GModel::current()->add(e->selected); } @@ -230,8 +230,7 @@ static void delete_edge_cb(Fl_Widget *w, void *data) std::vector<MLine *> temp = e->selected->lines; e->selected->lines.clear(); for(std::size_t i = 0; i < temp.size(); i++) { - auto it = - std::find(ele.begin(), ele.end(), temp[i]); + auto it = std::find(ele.begin(), ele.end(), temp[i]); if(it != ele.end()) delete temp[i]; else @@ -265,9 +264,9 @@ static void classify_cb(Fl_Widget *w, void *data) classificationEditor *e = (classificationEditor *)data; if(!e->selected) { - e->selected = - new discreteEdge(GModel::current(), - GModel::current()->getMaxElementaryNumber(1) + 1, nullptr, nullptr); + e->selected = new discreteEdge( + GModel::current(), GModel::current()->getMaxElementaryNumber(1) + 1, + nullptr, nullptr); GModel::current()->add(e->selected); } diff --git a/Fltk/contextWindow.cpp b/Fltk/contextWindow.cpp index ab1062b38015030893a8b82bac169664897e96c7..30ddb9d7d62b7cfd13ac699b033f688698d2c4c9 100644 --- a/Fltk/contextWindow.cpp +++ b/Fltk/contextWindow.cpp @@ -34,9 +34,7 @@ static bool getval(const char *str, double &val) std::vector<double> valVar; // we should probably use the actual .geo parser instead... - for(auto it = - gmsh_yysymbols.begin(); - it != gmsh_yysymbols.end(); it++) { + for(auto it = gmsh_yysymbols.begin(); it != gmsh_yysymbols.end(); it++) { if(it->second.value.size() == 1) { var.push_back(it->first); valVar.push_back(it->second.value[0]); @@ -1202,8 +1200,8 @@ physicalContextWindow::physicalContextWindow(int deltaFontSize) input[0]->callback(physical_add_cb, (void *)"Name"); input[0]->when(FL_WHEN_CHANGED); - value[0] = new Fl_Value_Input(2 * WB, 2 * WB + 3 * BH, - (int)(0.6 * width), BH, "Tag"); + value[0] = new Fl_Value_Input(2 * WB, 2 * WB + 3 * BH, (int)(0.6 * width), + BH, "Tag"); value[0]->value(0); value[0]->deactivate(); value[0]->align(FL_ALIGN_RIGHT); @@ -1336,8 +1334,9 @@ void physicalContextWindow::show(const std::string &what, bool remove) } static Fl_Menu_Item menu_selection_mode[] = { - {"All entities", 0, nullptr, nullptr}, {"Points", 0, nullptr, nullptr}, {"Curves", 0, nullptr, nullptr}, - {"Surfaces", 0, nullptr, nullptr}, {"Volumes", 0, nullptr, nullptr}, {nullptr}}; + {"All entities", 0, nullptr, nullptr}, {"Points", 0, nullptr, nullptr}, + {"Curves", 0, nullptr, nullptr}, {"Surfaces", 0, nullptr, nullptr}, + {"Volumes", 0, nullptr, nullptr}, {nullptr}}; static void selection_mode_cb(Fl_Widget *w, void *data) { @@ -1568,8 +1567,10 @@ meshContextWindow::meshContextWindow(int deltaFontSize) { FL_NORMAL_SIZE -= deltaFontSize; - static Fl_Menu menu_transfinite_dir[] = { - {"Left", 0, nullptr, nullptr}, {"Right", 0, nullptr, nullptr}, {"Alternated", 0, nullptr, nullptr}, {nullptr}}; + static Fl_Menu menu_transfinite_dir[] = {{"Left", 0, nullptr, nullptr}, + {"Right", 0, nullptr, nullptr}, + {"Alternated", 0, nullptr, nullptr}, + {nullptr}}; int width = 29 * FL_NORMAL_SIZE; int height = 4 * WB + 4 * BH; @@ -1599,7 +1600,10 @@ meshContextWindow::meshContextWindow(int deltaFontSize) input[2]->value("1"); for(int i = 1; i < 3; i++) { input[i]->align(FL_ALIGN_RIGHT); } static Fl_Menu_Item menu_trsf_mesh[] = { - {"Progression", 0, nullptr, nullptr}, {"Bump", 0, nullptr, nullptr}, {"Beta", 0, nullptr, nullptr}, {nullptr}}; + {"Progression", 0, nullptr, nullptr}, + {"Bump", 0, nullptr, nullptr}, + {"Beta", 0, nullptr, nullptr}, + {nullptr}}; choice[0] = new Fl_Choice(2 * WB, 2 * WB + 2 * BH, IW, BH, "Type"); choice[0]->menu(menu_trsf_mesh); choice[0]->align(FL_ALIGN_RIGHT); diff --git a/Fltk/drawContextFltk.h b/Fltk/drawContextFltk.h index d5ec20b25e5310b66f13334240f0774e35dccf6b..b22b5eca972a9fd2ee7164dc45ad03a40b0ad0ea 100644 --- a/Fltk/drawContextFltk.h +++ b/Fltk/drawContextFltk.h @@ -120,9 +120,7 @@ public: } int getFontSize() { - if(CTX::instance()->fontSize > 0) { - return CTX::instance()->fontSize; - } + if(CTX::instance()->fontSize > 0) { return CTX::instance()->fontSize; } else { int h = Fl::h(); // main (first) screen if(h < 800) @@ -150,7 +148,7 @@ public: void drawString(const char *str) { gl_draw(str); } void resetFontTextures() { -#if ((FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION >= 4)) || defined(__APPLE__) +#if((FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION >= 4)) || defined(__APPLE__) // force font texture recomputation gl_texture_pile_height(gl_texture_pile_height()); #endif diff --git a/Fltk/drawContextFltkCairo.cpp b/Fltk/drawContextFltkCairo.cpp index 49b6fba680d83e44ec18e454b30ff58304f0f8e8..a263bf43cb33b3af48d42cd9f617cf0cd9c30ae6 100644 --- a/Fltk/drawContextFltkCairo.cpp +++ b/Fltk/drawContextFltkCairo.cpp @@ -40,8 +40,7 @@ public: ~queueString() { - for(auto it = _elements.begin(); - it != _elements.end(); ++it) { + for(auto it = _elements.begin(); it != _elements.end(); ++it) { cairo_font_face_destroy(it->fontFace); } } @@ -73,8 +72,7 @@ public: cairo_font_options_destroy(fontOptions); cairo_set_source_rgba(cr, 1, 1, 1, 1); - for(auto it = _elements.begin(); - it != _elements.end(); ++it) { + for(auto it = _elements.begin(); it != _elements.end(); ++it) { cairo_move_to(cr, pos - it->xBearing, -it->yBearing); cairo_set_font_size(cr, it->fontSize); cairo_set_font_face(cr, it->fontFace); @@ -115,8 +113,7 @@ public: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); pos = 0; - for(auto it = _elements.begin(); - it != _elements.end(); ++it) { + for(auto it = _elements.begin(); it != _elements.end(); ++it) { glTranslatef(it->x, it->y, it->z); glColor4f(it->r, it->g, it->b, it->alpha); int Lx = it->width; diff --git a/Fltk/drawContextFltkStringTexture.cpp b/Fltk/drawContextFltkStringTexture.cpp index b9ee8a6e1aac0f0e7854f489a34cd4184c95e9e7..e18e8274b8e64b1884e14e4a1e9fe57f7e4b790b 100644 --- a/Fltk/drawContextFltkStringTexture.cpp +++ b/Fltk/drawContextFltkStringTexture.cpp @@ -52,16 +52,13 @@ public: fl_rectf(0, 0, w, h); fl_color(255, 255, 255); int pos = 0; - for(auto it = _elements.begin(); - it != _elements.end(); ++it) { + for(auto it = _elements.begin(); it != _elements.end(); ++it) { fl_font(it->fontId, it->fontSize); fl_draw(it->text.c_str(), pos, it->height - fl_descent()); pos += it->width; } uchar *data = fl_read_image(nullptr, 0, 0, w, h); - for(int i = 0; i < w * h; ++i) { - data[i] = data[i * 3]; - } + for(int i = 0; i < w * h; ++i) { data[i] = data[i * 3]; } fl_end_offscreen(); fl_delete_offscreen(offscreen); @@ -100,8 +97,7 @@ public: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); pos = 0; - for(auto it = _elements.begin(); - it != _elements.end(); ++it) { + for(auto it = _elements.begin(); it != _elements.end(); ++it) { glTranslatef(it->x, it->y, it->z); glColor4f(it->r, it->g, it->b, it->alpha); int Lx = it->width; diff --git a/Fltk/extraDialogs.cpp b/Fltk/extraDialogs.cpp index be1ff2b3d809dace44b28e168b905849fd3d1817..c45bec7f2e8f0db3752efc3f15b9ff0d6a9a1d2f 100644 --- a/Fltk/extraDialogs.cpp +++ b/Fltk/extraDialogs.cpp @@ -362,8 +362,6 @@ static cgnsImportDialog *_cgnsImport = nullptr; */ int cgnsImport() { - if(!_cgnsImport) { - _cgnsImport = new cgnsImportDialog(); - } + if(!_cgnsImport) { _cgnsImport = new cgnsImportDialog(); } return _cgnsImport->run(); } diff --git a/Fltk/fieldWindow.cpp b/Fltk/fieldWindow.cpp index 389bfe8ef29bb9c5b67e340a790fb6da7e232c02..7ff8e2680fa560cd91a23e702c651c9b19bb1414 100644 --- a/Fltk/fieldWindow.cpp +++ b/Fltk/fieldWindow.cpp @@ -237,8 +237,7 @@ void fieldWindow::saveFieldOptions() char a; double d; sstream.precision(16); - for(auto it = f->options.begin(); - it != f->options.end(); it++) { + for(auto it = f->options.begin(); it != f->options.end(); it++) { FieldOption *option = it->second; if(option->isDeprecated()) continue; sstream.str(""); @@ -310,8 +309,7 @@ void fieldWindow::loadFieldOptions() { Field *f = (Field *)editor_group->user_data(); auto input = options_widget.begin(); - for(auto it = f->options.begin(); - it != f->options.end(); it++) { + for(auto it = f->options.begin(); it != f->options.end(); it++) { FieldOption *option = it->second; if(option->isDeprecated()) continue; std::ostringstream vstr; @@ -399,8 +397,7 @@ void fieldWindow::editField(Field *f) ConvertToHTML(help); if(!f->options.empty()) help += std::string("<p><center><b>Options</b></center>"); - for(auto it = f->options.begin(); - it != f->options.end(); it++) { + for(auto it = f->options.begin(); it != f->options.end(); it++) { if(it->second->isDeprecated()) continue; Fl_Widget *input; help += std::string("<p><b>") + it->first + "</b>"; @@ -439,9 +436,7 @@ void fieldWindow::editField(Field *f) } if(!f->callbacks.empty()) help += std::string("<p><center><b>Actions</b></center>"); - for(auto it = - f->callbacks.begin(); - it != f->callbacks.end(); it++) { + for(auto it = f->callbacks.begin(); it != f->callbacks.end(); it++) { Fl_Widget *btn; help += std::string("<p><b>") + it->first + "</b>: "; help += it->second->getDescription(); diff --git a/Fltk/fileDialogs.cpp b/Fltk/fileDialogs.cpp index cf66c6a9be8c164fdd6df9f7cd1997cbf891a6e2..7bec4a498ee85d923016643f66c828e76cb8293a 100644 --- a/Fltk/fileDialogs.cpp +++ b/Fltk/fileDialogs.cpp @@ -178,9 +178,9 @@ int fileChooser(FILE_CHOOSER_TYPE type, const char *message, const char *filter, Fl_File_Chooser::show_label = "Format:"; Fl_File_Chooser::all_files_label = "All files (*)"; if(!fc) { - fc = - new flFileChooser(getenv("PWD") ? "." : CTX::instance()->homeDir.c_str(), - thefilter2, Fl_File_Chooser::SINGLE, message); + fc = new flFileChooser(getenv("PWD") ? "." : + CTX::instance()->homeDir.c_str(), + thefilter2, Fl_File_Chooser::SINGLE, message); fc->position(CTX::instance()->fileChooserPosition[0], CTX::instance()->fileChooserPosition[1]); } @@ -435,7 +435,8 @@ int pgfBitmapFileDialog(const char *name, const char *title, int format) if(!o) break; if(o == dialog->ok) { opt_print_text(0, GMSH_SET | GMSH_GUI, 0); // never print any text - opt_print_background(0, GMSH_SET | GMSH_GUI, 0); // never print background + opt_print_background(0, GMSH_SET | GMSH_GUI, + 0); // never print background opt_print_pgf_two_dim(0, GMSH_SET | GMSH_GUI, (int)dialog->b[0]->value()); opt_print_pgf_export_axis(0, GMSH_SET | GMSH_GUI, @@ -516,8 +517,7 @@ int latexFileDialog(const char *name) (int)dialog->b[0]->value()); opt_print_tex_force_fontsize(0, GMSH_SET | GMSH_GUI, (int)dialog->b[1]->value()); - opt_print_tex_width_in_mm(0, GMSH_SET | GMSH_GUI, - dialog->v->value()); + opt_print_tex_width_in_mm(0, GMSH_SET | GMSH_GUI, dialog->v->value()); CreateOutputFile(name, FORMAT_TEX); dialog->window->hide(); return 1; @@ -677,7 +677,9 @@ int mpegFileDialog(const char *name) } if(o == dialog->ok || o == dialog->preview) { opt_post_anim_cycle(0, GMSH_SET | GMSH_GUI, - dialog->b[2]->value() ? 2 : dialog->b[1]->value() ? 1 : 0); + dialog->b[2]->value() ? 2 : + dialog->b[1]->value() ? 1 : + 0); opt_post_anim_delay(0, GMSH_SET | GMSH_GUI, dialog->v[0]->value()); opt_post_anim_step(0, GMSH_SET | GMSH_GUI, (int)dialog->v[1]->value()); @@ -843,11 +845,12 @@ int gl2psFileDialog(const char *name, const char *title, int format) }; static _gl2psFileDialog *dialog = nullptr; - static Fl_Menu_Item sortmenu[] = {{"Raster image", 0, nullptr, nullptr}, - {"Vector simple sort", 0, nullptr, nullptr}, - {"Vector accurate sort", 0, nullptr, nullptr}, - {"Vector unsorted", 0, nullptr, nullptr}, - {nullptr}}; + static Fl_Menu_Item sortmenu[] = { + {"Raster image", 0, nullptr, nullptr}, + {"Vector simple sort", 0, nullptr, nullptr}, + {"Vector accurate sort", 0, nullptr, nullptr}, + {"Vector unsorted", 0, nullptr, nullptr}, + {nullptr}}; if(!dialog) { dialog = new _gl2psFileDialog; @@ -1165,10 +1168,12 @@ int mshFileDialog(const char *name) { static _mshFileDialog *dialog = nullptr; - static Fl_Menu_Item formatmenu[] = { - {"Version 1", 0, nullptr, nullptr}, {"Version 2 ASCII", 0, nullptr, nullptr}, - {"Version 2 Binary", 0, nullptr, nullptr}, {"Version 4 ASCII", 0, nullptr, nullptr}, - {"Version 4 Binary", 0, nullptr, nullptr}, {nullptr}}; + static Fl_Menu_Item formatmenu[] = {{"Version 1", 0, nullptr, nullptr}, + {"Version 2 ASCII", 0, nullptr, nullptr}, + {"Version 2 Binary", 0, nullptr, nullptr}, + {"Version 4 ASCII", 0, nullptr, nullptr}, + {"Version 4 Binary", 0, nullptr, nullptr}, + {nullptr}}; int BBB = BB + 9; // labels too long @@ -1219,8 +1224,10 @@ int mshFileDialog(const char *name) dialog->c->value(!opt_mesh_binary(0, GMSH_GET, 0) ? 3 : 4); dialog->b[0]->value(opt_mesh_save_all(0, GMSH_GET, 0) ? 1 : 0); dialog->b[1]->value(opt_mesh_save_parametric(0, GMSH_GET, 0) ? 1 : 0); - dialog->b[2]->value(opt_mesh_partition_split_mesh_files(0, GMSH_GET, 0) ? 1 : 0); - dialog->b[3]->value(opt_mesh_partition_save_topology_file(0, GMSH_GET, 0) ? 1 : 0); + dialog->b[2]->value(opt_mesh_partition_split_mesh_files(0, GMSH_GET, 0) ? 1 : + 0); + dialog->b[3]->value( + opt_mesh_partition_save_topology_file(0, GMSH_GET, 0) ? 1 : 0); if(GModel::current()->getNumPartitions() == 0) { dialog->b[2]->deactivate(); dialog->b[3]->deactivate(); @@ -1233,10 +1240,13 @@ int mshFileDialog(const char *name) Fl_Widget *o = Fl::readqueue(); if(!o) break; if(o == dialog->ok) { - opt_mesh_msh_file_version(0, GMSH_SET | GMSH_GUI, - (dialog->c->value() == 0) ? 1.0 : - (dialog->c->value() == 1 || dialog->c->value() == 2) ? 2.2 : 4.1); - opt_mesh_binary(0, GMSH_SET | GMSH_GUI, + opt_mesh_msh_file_version( + 0, GMSH_SET | GMSH_GUI, + (dialog->c->value() == 0) ? 1.0 : + (dialog->c->value() == 1 || dialog->c->value() == 2) ? 2.2 : + 4.1); + opt_mesh_binary( + 0, GMSH_SET | GMSH_GUI, (dialog->c->value() == 2 || dialog->c->value() == 4) ? 1 : 0); opt_mesh_save_all(0, GMSH_SET | GMSH_GUI, dialog->b[0]->value() ? 1 : 0); @@ -1400,13 +1410,18 @@ int keyFileDialog(const char *name, const char *title, int format) } dialog->c[0]->value(((int)opt_mesh_save_all(0, GMSH_GET, 0) & 4) ? 1 : - ((int)opt_mesh_save_all(0, GMSH_GET, 0) & 8) ? 2 : 0); + ((int)opt_mesh_save_all(0, GMSH_GET, 0) & 8) ? 2 : + 0); dialog->c[1]->value(((int)opt_mesh_save_all(0, GMSH_GET, 0) & 16) ? 1 : - ((int)opt_mesh_save_all(0, GMSH_GET, 0) & 32) ? 2 : 0); - dialog->c[2]->value(((int)opt_mesh_save_all(0, GMSH_GET, 0) & 64) ? 1 : - ((int)opt_mesh_save_all(0, GMSH_GET, 0) & 128) ? 2 : 0); - dialog->b[0]->value((int)opt_mesh_save_groups_of_nodes(0, GMSH_GET, 0) & 2 ? 1 : 0); - dialog->b[1]->value((int)opt_mesh_save_groups_of_nodes(0, GMSH_GET, 0) & 1 ? 1 : 0); + ((int)opt_mesh_save_all(0, GMSH_GET, 0) & 32) ? 2 : + 0); + dialog->c[2]->value(((int)opt_mesh_save_all(0, GMSH_GET, 0) & 64) ? 1 : + ((int)opt_mesh_save_all(0, GMSH_GET, 0) & 128) ? 2 : + 0); + dialog->b[0]->value( + (int)opt_mesh_save_groups_of_nodes(0, GMSH_GET, 0) & 2 ? 1 : 0); + dialog->b[1]->value( + (int)opt_mesh_save_groups_of_nodes(0, GMSH_GET, 0) & 1 ? 1 : 0); dialog->window->show(); while(dialog->window->shown()) { @@ -1417,11 +1432,11 @@ int keyFileDialog(const char *name, const char *title, int format) if(o == dialog->ok) { opt_mesh_save_all(0, GMSH_SET | GMSH_GUI, dialog->c[0]->value() * 4 + - dialog->c[1]->value() * 16 + - dialog->c[2]->value() * 64); + dialog->c[1]->value() * 16 + + dialog->c[2]->value() * 64); opt_mesh_save_groups_of_nodes(0, GMSH_SET | GMSH_GUI, (dialog->b[0]->value() ? 2 : 0) + - (dialog->b[1]->value() ? 1 : 0)); + (dialog->b[1]->value() ? 1 : 0)); CreateOutputFile(name, format); dialog->window->hide(); return 1; @@ -1488,7 +1503,8 @@ int bdfFileDialog(const char *name) dialog->c->value(opt_mesh_bdf_field_format(0, GMSH_GET, 0)); dialog->d->value((opt_mesh_save_element_tag_type(0, GMSH_GET, 0) == 3) ? 2 : - (opt_mesh_save_element_tag_type(0, GMSH_GET, 0) == 2) ? 1 : 0); + (opt_mesh_save_element_tag_type(0, GMSH_GET, 0) == 2) ? 1 : + 0); dialog->b->value(opt_mesh_save_all(0, GMSH_GET, 0) ? 1 : 0); dialog->window->show(); @@ -1528,16 +1544,12 @@ int stlFileDialog(const char *name) static _stlFileDialog *dialog = nullptr; static Fl_Menu_Item formatmenu[] = { - {"ASCII", 0, nullptr, nullptr}, - {"Binary", 0, nullptr, nullptr}, - {nullptr} - }; + {"ASCII", 0, nullptr, nullptr}, {"Binary", 0, nullptr, nullptr}, {nullptr}}; static Fl_Menu_Item solidmenu[] = { {"Single", 0, nullptr, nullptr}, {"Per surface", 0, nullptr, nullptr}, {"Per physical surface", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; int BBB = BB + 9; // labels too long @@ -1552,8 +1564,8 @@ int stlFileDialog(const char *name) y += BH; dialog->c[0]->menu(formatmenu); dialog->c[0]->align(FL_ALIGN_RIGHT); - dialog->b = new Fl_Check_Button - (WB, y, 2 * BBB + WB, BH, "Save all elements"); + dialog->b = + new Fl_Check_Button(WB, y, 2 * BBB + WB, BH, "Save all elements"); dialog->b->tooltip("Mesh.SaveAll"); y += BH; dialog->b->type(FL_TOGGLE_BUTTON); @@ -1570,8 +1582,10 @@ int stlFileDialog(const char *name) dialog->c[0]->value(opt_mesh_binary(0, GMSH_GET, 0) ? 1 : 0); dialog->b->value(opt_mesh_save_all(0, GMSH_GET, 0) ? 1 : 0); - dialog->c[1]->value(opt_mesh_stl_one_solid_per_surface(0, GMSH_GET, 0) == 2 ? 2 : - opt_mesh_stl_one_solid_per_surface(0, GMSH_GET, 0) == 1 ? 1 :0); + dialog->c[1]->value( + opt_mesh_stl_one_solid_per_surface(0, GMSH_GET, 0) == 2 ? 2 : + opt_mesh_stl_one_solid_per_surface(0, GMSH_GET, 0) == 1 ? 1 : + 0); if(dialog->c[1]->value() == 2) dialog->b->deactivate(); @@ -1666,7 +1680,8 @@ int genericMeshFileDialog(const char *name, const char *title, int format, else dialog->c->deactivate(); dialog->d->value((opt_mesh_save_element_tag_type(0, GMSH_GET, 0) == 3) ? 2 : - (opt_mesh_save_element_tag_type(0, GMSH_GET, 0) == 2) ? 1 : 0); + (opt_mesh_save_element_tag_type(0, GMSH_GET, 0) == 2) ? 1 : + 0); if(element_tag_support) dialog->d->activate(); else @@ -1754,8 +1769,10 @@ int posFileDialog(const char *name) }; static _posFileDialog *dialog = nullptr; - static Fl_Menu_Item viewmenu[] = { - {"Current", 0, nullptr, nullptr}, {"Visible", 0, nullptr, nullptr}, {"All", 0, nullptr, nullptr}, {nullptr}}; + static Fl_Menu_Item viewmenu[] = {{"Current", 0, nullptr, nullptr}, + {"Visible", 0, nullptr, nullptr}, + {"All", 0, nullptr, nullptr}, + {nullptr}}; static Fl_Menu_Item formatmenu[] = {{"Parsed", 0, nullptr, nullptr}, {"Mesh-based", 0, nullptr, nullptr}, {"Legacy ASCII", 0, nullptr, nullptr}, @@ -1879,8 +1896,10 @@ int pvtuAdaptFileDialog(const char *name) }; static _pvtuAdaptFileDialog *dialog = nullptr; - static Fl_Menu_Item viewmenu[] = { - {"Current", 0, nullptr, nullptr}, {"Visible", 0, nullptr, nullptr}, {"All", 0, nullptr, nullptr}, {nullptr}}; + static Fl_Menu_Item viewmenu[] = {{"Current", 0, nullptr, nullptr}, + {"Visible", 0, nullptr, nullptr}, + {"All", 0, nullptr, nullptr}, + {nullptr}}; static Fl_Menu_Item formatmenu[] = { {"Binary", 0, nullptr, nullptr}, {"ASCII", 0, nullptr, nullptr}, {nullptr}}; @@ -1990,8 +2009,10 @@ int x3dViewFileDialog(const char *name, const char *title, int format) }; static _viewFileDialog *dialog = nullptr; - static Fl_Menu_Item viewmenu[] = { - {"Current", 0, nullptr, nullptr}, {"Visible", 0, nullptr, nullptr}, {"All", 0, nullptr, nullptr}, {nullptr}}; + static Fl_Menu_Item viewmenu[] = {{"Current", 0, nullptr, nullptr}, + {"Visible", 0, nullptr, nullptr}, + {"All", 0, nullptr, nullptr}, + {nullptr}}; int BBB = BB + 9; // labels too long @@ -2079,8 +2100,10 @@ int genericViewFileDialog(const char *name, const char *title, int format) }; static _viewFileDialog *dialog = nullptr; - static Fl_Menu_Item viewmenu[] = { - {"Current", 0, nullptr, nullptr}, {"Visible", 0, nullptr, nullptr}, {"All", 0, nullptr, nullptr}, {nullptr}}; + static Fl_Menu_Item viewmenu[] = {{"Current", 0, nullptr, nullptr}, + {"Visible", 0, nullptr, nullptr}, + {"All", 0, nullptr, nullptr}, + {nullptr}}; int BBB = BB + 9; // labels too long diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp index 6c5566d3112c631b9779834dfbdfb076d2f43bbf..263b0b23a9fb2d7facc908a70106087f7293bf2f 100644 --- a/Fltk/graphicWindow.cpp +++ b/Fltk/graphicWindow.cpp @@ -70,17 +70,18 @@ typedef unsigned long intptr_t; static void file_new_cb(Fl_Widget *w, void *data) { - test: +test: if(fileChooser(FILE_CHOOSER_CREATE, "New", "")) { std::string name = fileChooserGetName(1); std::vector<std::string> split = SplitFileName(name); - if(split[2] != ".geo"){ + if(split[2] != ".geo") { if(fl_choice("File '%s' does not have the '.geo' extension.\n\n" "Do you want to continue as-is?", - "Continue as-is", "Use '.geo' extension", nullptr, name.c_str())) + "Continue as-is", "Use '.geo' extension", nullptr, + name.c_str())) name = split[0] + split[1] + ".geo"; } - if(!StatFile(name)){ + if(!StatFile(name)) { if(fl_choice("File '%s' already exists.\n\nDo you want to delete it?", "Cancel", "Delete", nullptr, name.c_str())) UnlinkFile(name); @@ -88,7 +89,7 @@ static void file_new_cb(Fl_Widget *w, void *data) goto test; } FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return; } @@ -154,12 +155,12 @@ static const char *input_formats = static void file_open_merge_cb(Fl_Widget *w, void *data) { if(!data) return; - std::string mode((char*)data); + std::string mode((char *)data); int n = PView::list.size(); int f = fileChooser(FILE_CHOOSER_MULTI, (mode == "open") ? "Open" : "Merge", input_formats); - if(f){ - for(int i = 1; i <= f; i++){ + if(f) { + for(int i = 1; i <= f; i++) { if(mode == "open") OpenProject(fileChooserGetName(i)); else @@ -168,9 +169,10 @@ static void file_open_merge_cb(Fl_Widget *w, void *data) if(n != (int)PView::list.size()) FlGui::instance()->openModule("Post-processing"); if(CTX::instance()->launchSolverAtStartup >= 0) - solver_cb(nullptr, (void*)(intptr_t)CTX::instance()->launchSolverAtStartup); + solver_cb(nullptr, + (void *)(intptr_t)CTX::instance()->launchSolverAtStartup); else if(onelabUtils::haveSolverToRun()) - onelab_cb(nullptr, (void*)"check"); + onelab_cb(nullptr, (void *)"check"); drawContext::global()->draw(); } } @@ -178,16 +180,17 @@ static void file_open_merge_cb(Fl_Widget *w, void *data) static void file_open_recent_cb(Fl_Widget *w, void *data) { if(!data) return; - std::string str((const char*)data); + std::string str((const char *)data); int n = PView::list.size(); OpenProject(str); drawContext::global()->draw(); if(n != (int)PView::list.size()) FlGui::instance()->openModule("Post-processing"); if(CTX::instance()->launchSolverAtStartup >= 0) - solver_cb(nullptr, (void*)(intptr_t)CTX::instance()->launchSolverAtStartup); + solver_cb(nullptr, + (void *)(intptr_t)CTX::instance()->launchSolverAtStartup); else if(onelabUtils::haveSolverToRun()) - onelab_cb(nullptr, (void*)"check"); + onelab_cb(nullptr, (void *)"check"); } static void file_clear_cb(Fl_Widget *w, void *data) @@ -198,7 +201,7 @@ static void file_clear_cb(Fl_Widget *w, void *data) } ClearProject(); if(onelabUtils::haveSolverToRun()) - onelab_cb(nullptr, (void*)"reset"); // this will call OpenProject + onelab_cb(nullptr, (void *)"reset"); // this will call OpenProject else OpenProject(GModel::current()->getFileName()); drawContext::global()->draw(); @@ -208,44 +211,44 @@ static void file_remote_cb(Fl_Widget *w, void *data) { onelab::localNetworkClient *c; auto it = onelab::server::instance()->findClient("GmshRemote"); - if(it == onelab::server::instance()->lastClient()){ + if(it == onelab::server::instance()->lastClient()) { c = new gmshLocalNetworkClient("GmshRemote", ""); c->setSocketSwitch("-socket"); } else - c = (onelab::localNetworkClient*)(*it); + c = (onelab::localNetworkClient *)(*it); GmshServer *server = c->getGmshServer(); - std::string str((const char*)data); + std::string str((const char *)data); - if(str == "start"){ - if(server){ + if(str == "start") { + if(server) { Msg::Error("Cannot start: remote Gmsh is already running"); return; } c->setExecutable(connectionChooser()); if(c->getExecutable().size()) c->run(); } - else{ - if(!server){ + else { + if(!server) { Msg::Error("Cannot %s: remote Gmsh not running", str.c_str()); return; } - if(str == "stop"){ + if(str == "stop") { server->SendString(GmshSocket::GMSH_STOP, "Disconnect!"); } - else if(str == "merge"){ + else if(str == "merge") { const char *file = fl_input("Merge", "/tmp/data.pos"); if(file) server->SendString(GmshSocket::GMSH_MERGE_FILE, file); } - else if(str == "clear"){ + else if(str == "clear") { server->SendString(GmshSocket::GMSH_PARSE_STRING, "Delete All;"); for(int i = PView::list.size() - 1; i >= 0; i--) if(PView::list[i]->getData()->isRemote()) delete PView::list[i]; FlGui::instance()->updateViews(true, true); drawContext::global()->draw(); } - else if(str == "test"){ + else if(str == "test") { server->SendString(GmshSocket::GMSH_SPEED_TEST, "Speed test"); } } @@ -253,165 +256,245 @@ static void file_remote_cb(Fl_Widget *w, void *data) static void file_window_cb(Fl_Widget *w, void *data) { - std::string str((const char*)data); - if(str == "new"){ + std::string str((const char *)data); + if(str == "new") { graphicWindow *g1 = FlGui::instance()->graph.back(); graphicWindow *g2 = new graphicWindow(false, CTX::instance()->numTiles); FlGui::instance()->graph.push_back(g2); g2->getWindow()->resize(g1->getWindow()->x() + 10, - g1->getWindow()->y() + 10, - g1->getWindow()->w(), + g1->getWindow()->y() + 10, g1->getWindow()->w(), g1->getWindow()->h()); g2->getWindow()->show(); } - else if(str == "split_h"){ + else if(str == "split_h") { FlGui::instance()->splitCurrentOpenglWindow('h', 0.5); } - else if(str == "split_v"){ + else if(str == "split_v") { FlGui::instance()->splitCurrentOpenglWindow('v', 0.5); } - else if(str == "split_u"){ + else if(str == "split_u") { FlGui::instance()->splitCurrentOpenglWindow('u'); } - else if(str == "copy"){ + else if(str == "copy") { FlGui::instance()->copyCurrentOpenglWindowToClipboard(); } drawContext::global()->draw(); FlGui::instance()->setGraphicTitle(GModel::current()->getFileName()); } -static int _save_msh(const char *name){ return mshFileDialog(name); } -static int _save_mesh_stat(const char *name){ return meshStatFileDialog(name); } -static int _save_options(const char *name){ return optionsFileDialog(name); } -static int _save_geo(const char *name){ return geoFileDialog(name); } -static int _save_brep(const char *name){ CreateOutputFile(name, FORMAT_BREP); return 1; } -static int _save_step(const char *name){ CreateOutputFile(name, FORMAT_STEP); return 1; } -static int _save_xmt(const char *name){ CreateOutputFile(name, FORMAT_XMT); return 1; } -static int _save_cgns(const char *name){ return cgnsFileDialog(name); } -static int _save_unv(const char *name){ return unvinpFileDialog - (name, "UNV Options", FORMAT_UNV); } -static int _save_vtk(const char *name){ return genericMeshFileDialog - (name, "VTK Options", FORMAT_VTK, true, false); } -static int _save_tochnog(const char *name){ return genericMeshFileDialog - (name, "Tochnog Options", FORMAT_TOCHNOG, true, false); } -static int _save_diff(const char *name){ return genericMeshFileDialog - (name, "Diffpack Options", FORMAT_DIFF, true, false); } -static int _save_inp(const char *name){ return unvinpFileDialog - (name, "Abaqus INP Options", FORMAT_INP); } -static int _save_key(const char *name){ return keyFileDialog - (name, "LSDYNA KEY Options", FORMAT_KEY); } -static int _save_celum(const char *name){ return genericMeshFileDialog - (name, "CELUM Options", FORMAT_CELUM, false, false); } -static int _save_su2(const char *name){ return genericMeshFileDialog - (name, "SU2 Options", FORMAT_SU2, false, false); } -static int _save_med(const char *name){ return genericMeshFileDialog - (name, "MED Options", FORMAT_MED, false, false); } -static int _save_mesh(const char *name){ return genericMeshFileDialog - (name, "MESH Options", FORMAT_MESH, false, true); } -static int _save_mail(const char *name){ return genericMeshFileDialog - (name, "MAIL Options", FORMAT_MAIL, false, false); } -static int _save_matlab(const char *name){ return genericMeshFileDialog - (name, "MATLAB Options", FORMAT_MATLAB, false, false); } -static int _save_bdf(const char *name){ return bdfFileDialog(name); } -static int _save_p3d(const char *name){ return genericMeshFileDialog - (name, "P3D Options", FORMAT_P3D, false, false); } -static int _save_ir3(const char *name){ return genericMeshFileDialog - (name, "Iridium Options", FORMAT_IR3, false, true); } -static int _save_stl(const char *name){ return stlFileDialog(name); } -static int _save_vrml(const char *name){ return genericMeshFileDialog - (name, "VRML Options", FORMAT_VRML, false, false); } -static int _save_ply2(const char *name){ return genericMeshFileDialog - (name, "PLY2 Options", FORMAT_PLY2, false, false); } -static int _save_neu(const char *name){ return genericMeshFileDialog - (name, "NEU Options", FORMAT_NEU, false, false); } -static int _save_eps(const char *name){ return gl2psFileDialog - (name, "EPS Options", FORMAT_EPS); } -static int _save_gif(const char *name){ return gifFileDialog(name); } -static int _save_jpeg(const char *name){ return genericBitmapFileDialog - (name, "JPEG Options", FORMAT_JPEG); } -static int _save_mpeg(const char *name){ return mpegFileDialog(name); } -static int _save_tex(const char *name){ return latexFileDialog(name); } -static int _save_pdf(const char *name){ return gl2psFileDialog - (name, "PDF Options", FORMAT_PDF); } -static int _save_png(const char *name){ return genericBitmapFileDialog - (name, "PNG Options", FORMAT_PNG); } -static int _save_pgf(const char *name){ return pgfBitmapFileDialog - (name, "PGF Options", FORMAT_PGF); } -static int _save_ps(const char *name){ return gl2psFileDialog - (name, "PS Options", FORMAT_PS); } -static int _save_ppm(const char *name){ return genericBitmapFileDialog - (name, "PPM Options", FORMAT_PPM); } -static int _save_svg(const char *name){ return gl2psFileDialog - (name, "SVG Options", FORMAT_SVG); } -static int _save_tikz(const char *name){ return gl2psFileDialog - (name, "TIKZ Options", FORMAT_TIKZ); } -static int _save_yuv(const char *name){ return genericBitmapFileDialog - (name, "YUV Options", FORMAT_YUV); } -static int _save_view_pos(const char *name){ return posFileDialog(name); } -static int _save_view_adapt_pvtu(const char *name){ return pvtuAdaptFileDialog(name); } -static int _save_view_med(const char *name){ return genericViewFileDialog - (name, "MED Options", 6); } -static int _save_view_txt(const char *name){ return genericViewFileDialog - (name, "TXT Options", 4); } -static int _save_view_x3d(const char *name){ return x3dViewFileDialog - (name, "X3D Options", 7); } +static int _save_msh(const char *name) { return mshFileDialog(name); } +static int _save_mesh_stat(const char *name) +{ + return meshStatFileDialog(name); +} +static int _save_options(const char *name) { return optionsFileDialog(name); } +static int _save_geo(const char *name) { return geoFileDialog(name); } +static int _save_brep(const char *name) +{ + CreateOutputFile(name, FORMAT_BREP); + return 1; +} +static int _save_step(const char *name) +{ + CreateOutputFile(name, FORMAT_STEP); + return 1; +} +static int _save_xmt(const char *name) +{ + CreateOutputFile(name, FORMAT_XMT); + return 1; +} +static int _save_cgns(const char *name) { return cgnsFileDialog(name); } +static int _save_unv(const char *name) +{ + return unvinpFileDialog(name, "UNV Options", FORMAT_UNV); +} +static int _save_vtk(const char *name) +{ + return genericMeshFileDialog(name, "VTK Options", FORMAT_VTK, true, false); +} +static int _save_tochnog(const char *name) +{ + return genericMeshFileDialog(name, "Tochnog Options", FORMAT_TOCHNOG, true, + false); +} +static int _save_diff(const char *name) +{ + return genericMeshFileDialog(name, "Diffpack Options", FORMAT_DIFF, true, + false); +} +static int _save_inp(const char *name) +{ + return unvinpFileDialog(name, "Abaqus INP Options", FORMAT_INP); +} +static int _save_key(const char *name) +{ + return keyFileDialog(name, "LSDYNA KEY Options", FORMAT_KEY); +} +static int _save_celum(const char *name) +{ + return genericMeshFileDialog(name, "CELUM Options", FORMAT_CELUM, false, + false); +} +static int _save_su2(const char *name) +{ + return genericMeshFileDialog(name, "SU2 Options", FORMAT_SU2, false, false); +} +static int _save_med(const char *name) +{ + return genericMeshFileDialog(name, "MED Options", FORMAT_MED, false, false); +} +static int _save_mesh(const char *name) +{ + return genericMeshFileDialog(name, "MESH Options", FORMAT_MESH, false, true); +} +static int _save_mail(const char *name) +{ + return genericMeshFileDialog(name, "MAIL Options", FORMAT_MAIL, false, false); +} +static int _save_matlab(const char *name) +{ + return genericMeshFileDialog(name, "MATLAB Options", FORMAT_MATLAB, false, + false); +} +static int _save_bdf(const char *name) { return bdfFileDialog(name); } +static int _save_p3d(const char *name) +{ + return genericMeshFileDialog(name, "P3D Options", FORMAT_P3D, false, false); +} +static int _save_ir3(const char *name) +{ + return genericMeshFileDialog(name, "Iridium Options", FORMAT_IR3, false, + true); +} +static int _save_stl(const char *name) { return stlFileDialog(name); } +static int _save_vrml(const char *name) +{ + return genericMeshFileDialog(name, "VRML Options", FORMAT_VRML, false, false); +} +static int _save_ply2(const char *name) +{ + return genericMeshFileDialog(name, "PLY2 Options", FORMAT_PLY2, false, false); +} +static int _save_neu(const char *name) +{ + return genericMeshFileDialog(name, "NEU Options", FORMAT_NEU, false, false); +} +static int _save_eps(const char *name) +{ + return gl2psFileDialog(name, "EPS Options", FORMAT_EPS); +} +static int _save_gif(const char *name) { return gifFileDialog(name); } +static int _save_jpeg(const char *name) +{ + return genericBitmapFileDialog(name, "JPEG Options", FORMAT_JPEG); +} +static int _save_mpeg(const char *name) { return mpegFileDialog(name); } +static int _save_tex(const char *name) { return latexFileDialog(name); } +static int _save_pdf(const char *name) +{ + return gl2psFileDialog(name, "PDF Options", FORMAT_PDF); +} +static int _save_png(const char *name) +{ + return genericBitmapFileDialog(name, "PNG Options", FORMAT_PNG); +} +static int _save_pgf(const char *name) +{ + return pgfBitmapFileDialog(name, "PGF Options", FORMAT_PGF); +} +static int _save_ps(const char *name) +{ + return gl2psFileDialog(name, "PS Options", FORMAT_PS); +} +static int _save_ppm(const char *name) +{ + return genericBitmapFileDialog(name, "PPM Options", FORMAT_PPM); +} +static int _save_svg(const char *name) +{ + return gl2psFileDialog(name, "SVG Options", FORMAT_SVG); +} +static int _save_tikz(const char *name) +{ + return gl2psFileDialog(name, "TIKZ Options", FORMAT_TIKZ); +} +static int _save_yuv(const char *name) +{ + return genericBitmapFileDialog(name, "YUV Options", FORMAT_YUV); +} +static int _save_view_pos(const char *name) { return posFileDialog(name); } +static int _save_view_adapt_pvtu(const char *name) +{ + return pvtuAdaptFileDialog(name); +} +static int _save_view_med(const char *name) +{ + return genericViewFileDialog(name, "MED Options", 6); +} +static int _save_view_txt(const char *name) +{ + return genericViewFileDialog(name, "TXT Options", 4); +} +static int _save_view_x3d(const char *name) +{ + return x3dViewFileDialog(name, "X3D Options", 7); +} static int _save_auto(const char *name) { - switch(GuessFileFormatFromFileName(name)){ - case FORMAT_MSH : return _save_msh(name); - case FORMAT_POS : return _save_view_pos(name); - case FORMAT_X3D : return _save_view_x3d(name); - case FORMAT_PVTU : return _save_view_adapt_pvtu(name); - case FORMAT_TXT : return _save_view_txt(name); - case FORMAT_OPT : return _save_options(name); - case FORMAT_GEO : return _save_geo(name); - case FORMAT_BREP : return _save_brep(name); - case FORMAT_STEP : return _save_step(name); - case FORMAT_CGNS : return _save_cgns(name); - case FORMAT_UNV : return _save_unv(name); - case FORMAT_VTK : return _save_vtk(name); + switch(GuessFileFormatFromFileName(name)) { + case FORMAT_MSH: return _save_msh(name); + case FORMAT_POS: return _save_view_pos(name); + case FORMAT_X3D: return _save_view_x3d(name); + case FORMAT_PVTU: return _save_view_adapt_pvtu(name); + case FORMAT_TXT: return _save_view_txt(name); + case FORMAT_OPT: return _save_options(name); + case FORMAT_GEO: return _save_geo(name); + case FORMAT_BREP: return _save_brep(name); + case FORMAT_STEP: return _save_step(name); + case FORMAT_CGNS: return _save_cgns(name); + case FORMAT_UNV: return _save_unv(name); + case FORMAT_VTK: return _save_vtk(name); case FORMAT_TOCHNOG: return _save_tochnog(name); - case FORMAT_MED : return _save_med(name); - case FORMAT_RMED : return _save_view_med(name); - case FORMAT_MESH : return _save_mesh(name); - case FORMAT_MAIL : return _save_mail(name); - case FORMAT_MATLAB : return _save_matlab(name); - case FORMAT_BDF : return _save_bdf(name); - case FORMAT_DIFF : return _save_diff(name); - case FORMAT_INP : return _save_inp(name); - case FORMAT_KEY : return _save_key(name); + case FORMAT_MED: return _save_med(name); + case FORMAT_RMED: return _save_view_med(name); + case FORMAT_MESH: return _save_mesh(name); + case FORMAT_MAIL: return _save_mail(name); + case FORMAT_MATLAB: return _save_matlab(name); + case FORMAT_BDF: return _save_bdf(name); + case FORMAT_DIFF: return _save_diff(name); + case FORMAT_INP: return _save_inp(name); + case FORMAT_KEY: return _save_key(name); case FORMAT_CELUM: return _save_celum(name); - case FORMAT_SU2 : return _save_su2(name); - case FORMAT_P3D : return _save_p3d(name); - case FORMAT_IR3 : return _save_ir3(name); - case FORMAT_STL : return _save_stl(name); - case FORMAT_VRML : return _save_vrml(name); - case FORMAT_PLY2 : return _save_ply2(name); - case FORMAT_NEU : return _save_neu(name); - case FORMAT_EPS : return _save_eps(name); - case FORMAT_GIF : return _save_gif(name); - case FORMAT_JPEG : return _save_jpeg(name); - case FORMAT_MPEG : return _save_mpeg(name); - case FORMAT_TEX : return _save_tex(name); - case FORMAT_PDF : return _save_pdf(name); - case FORMAT_PNG : return _save_png(name); - case FORMAT_PGF : return _save_pgf(name); - case FORMAT_PS : return _save_ps(name); - case FORMAT_PPM : return _save_ppm(name); - case FORMAT_SVG : return _save_svg(name); - case FORMAT_TIKZ : return _save_tikz(name); - case FORMAT_YUV : return _save_yuv(name); - case FORMAT_XMT : return _save_xmt(name); - default : - CreateOutputFile(name, FORMAT_AUTO); - return 1; - } -} - -typedef struct{ + case FORMAT_SU2: return _save_su2(name); + case FORMAT_P3D: return _save_p3d(name); + case FORMAT_IR3: return _save_ir3(name); + case FORMAT_STL: return _save_stl(name); + case FORMAT_VRML: return _save_vrml(name); + case FORMAT_PLY2: return _save_ply2(name); + case FORMAT_NEU: return _save_neu(name); + case FORMAT_EPS: return _save_eps(name); + case FORMAT_GIF: return _save_gif(name); + case FORMAT_JPEG: return _save_jpeg(name); + case FORMAT_MPEG: return _save_mpeg(name); + case FORMAT_TEX: return _save_tex(name); + case FORMAT_PDF: return _save_pdf(name); + case FORMAT_PNG: return _save_png(name); + case FORMAT_PGF: return _save_pgf(name); + case FORMAT_PS: return _save_ps(name); + case FORMAT_PPM: return _save_ppm(name); + case FORMAT_SVG: return _save_svg(name); + case FORMAT_TIKZ: return _save_tikz(name); + case FORMAT_YUV: return _save_yuv(name); + case FORMAT_XMT: return _save_xmt(name); + default: CreateOutputFile(name, FORMAT_AUTO); return 1; + } +} + +typedef struct { const char *pat; - int (*func) (const char *name); + int (*func)(const char *name); } patXfunc; static void file_export_cb(Fl_Widget *w, void *data) @@ -493,7 +576,7 @@ static void file_export_cb(Fl_Widget *w, void *data) } } - test: +test: if(fileChooser(FILE_CHOOSER_CREATE, "Export", pat)) { std::string name = fileChooserGetName(1); bool confirmOverwrite = CTX::instance()->confirmOverwrite; @@ -508,10 +591,10 @@ static void file_export_cb(Fl_Widget *w, void *data) goto test; } int i = fileChooserGetFilter(); - if(i >= 0 && i < nbformats){ + if(i >= 0 && i < nbformats) { if(!formats[i].func(name.c_str())) goto test; } - else{ // handle any additional automatic fltk filter + else { // handle any additional automatic fltk filter if(!_save_auto(name.c_str())) goto test; } } @@ -519,7 +602,7 @@ static void file_export_cb(Fl_Widget *w, void *data) static void file_options_save_cb(Fl_Widget *w, void *data) { - std::string str((const char*)data), fileName; + std::string str((const char *)data), fileName; if(str == "file") fileName = GModel::current()->getFileName() + ".opt"; else @@ -534,7 +617,7 @@ static void file_options_save_cb(Fl_Widget *w, void *data) static void file_rename_cb(Fl_Widget *w, void *data) { - test: +test: if(fileChooser(FILE_CHOOSER_CREATE, "Rename", "")) { std::string name = fileChooserGetName(1); bool confirmOverwrite = CTX::instance()->confirmOverwrite; @@ -552,16 +635,15 @@ static void file_rename_cb(Fl_Widget *w, void *data) GModel::current()->setFileName(name); GModel::current()->setName(SplitFileName(name)[1]); Msg::SetOnelabChanged(3); - if(onelabUtils::haveSolverToRun()) - onelab_cb(nullptr, (void*)"check"); + if(onelabUtils::haveSolverToRun()) onelab_cb(nullptr, (void *)"check"); drawContext::global()->draw(); } } static void file_delete_cb(Fl_Widget *w, void *data) { - if(fl_choice("Do you really want to delete file '%s'?", - "Cancel", "Delete", nullptr, GModel::current()->getFileName().c_str())){ + if(fl_choice("Do you really want to delete file '%s'?", "Cancel", "Delete", + nullptr, GModel::current()->getFileName().c_str())) { UnlinkFile(GModel::current()->getFileName()); Msg::Info("Deleted `%s'", GModel::current()->getFileName().c_str()); file_clear_cb(nullptr, nullptr); @@ -570,18 +652,15 @@ static void file_delete_cb(Fl_Widget *w, void *data) void file_quit_cb(Fl_Widget *w, void *data) { - if(FlGui::instance()->quitShouldExit()) { - Msg::Exit(0); - } + if(FlGui::instance()->quitShouldExit()) { Msg::Exit(0); } else { FlGui::instance()->onelabContext->disableRedraw(); // hide all windows (in case they are not tracked by FlGui)... - std::vector<Fl_Window*> wins; - for (Fl_Window *win = Fl::first_window(); win; win = Fl::next_window(win)) + std::vector<Fl_Window *> wins; + for(Fl_Window *win = Fl::first_window(); win; win = Fl::next_window(win)) wins.push_back(win); - for (std::size_t i = 0; i < wins.size(); i++) - wins[i]->hide(); + for(std::size_t i = 0; i < wins.size(); i++) wins[i]->hide(); // process remaining events FlGui::check(); @@ -596,8 +675,8 @@ void file_watch_cb(Fl_Widget *w, void *data) if(CTX::instance()->watchFilePattern.empty()) return; - std::string pattern = FixRelativePath - (GModel::current()->getFileName(), CTX::instance()->watchFilePattern); + std::string pattern = FixRelativePath(GModel::current()->getFileName(), + CTX::instance()->watchFilePattern); std::string directory = SplitFileName(pattern)[0]; if(directory.empty()) directory = "./"; @@ -605,13 +684,13 @@ void file_watch_cb(Fl_Widget *w, void *data) int num = fl_filename_list(directory.c_str(), &files, fl_numericsort); if(num <= 0) return; std::vector<std::string> matches; - for (int i = 0; i < num; i++) { + for(int i = 0; i < num; i++) { std::string name = directory + files[i]->d_name; if(fl_filename_match(name.c_str(), pattern.c_str())) matches.push_back(name); - free((void*)files[i]); + free((void *)files[i]); } - if(files) free((void*)files); + if(files) free((void *)files); Msg::Info("%d match%s for pattern '%s'", (int)matches.size(), (matches.size() > 1) ? "es" : "", pattern.c_str()); @@ -621,7 +700,8 @@ void file_watch_cb(Fl_Widget *w, void *data) allFiles.insert(GetFileNameWithoutPath(GModel::list[i]->getFileName())); for(std::size_t i = 0; i < PView::list.size(); i++) for(int j = 0; j < PView::list[i]->getData()->getNumTimeSteps(); j++) - allFiles.insert(GetFileNameWithoutPath(PView::list[i]->getData()->getFileName(j))); + allFiles.insert( + GetFileNameWithoutPath(PView::list[i]->getData()->getFileName(j))); for(std::size_t i = 0; i < matches.size(); i++) if(allFiles.find(GetFileNameWithoutPath(matches[i])) == allFiles.end()) @@ -661,14 +741,14 @@ void onelab_reload_cb(Fl_Widget *w, void *data) std::string fileName = GModel::current()->getFileName(); ClearProject(); GModel::current()->setFileName(fileName); - onelab_cb(nullptr, (void*)"reset"); // will call OpenProject + onelab_cb(nullptr, (void *)"reset"); // will call OpenProject drawContext::global()->draw(); } void geometry_reload_cb(Fl_Widget *w, void *data) { - if(onelabUtils::haveSolverToRun()){ - onelab_cb(nullptr, (void*)"check_always"); + if(onelabUtils::haveSolverToRun()) { + onelab_cb(nullptr, (void *)"check_always"); } else OpenProject(GModel::current()->getFileName()); @@ -697,13 +777,14 @@ static void add_new_point_based_entity(const std::string &what, int pane) FlGui::instance()->graph[i]->gl[j]->addPointMode = 1; std::string name = what; std::transform(name.begin(), name.end(), name.begin(), ::tolower); - Msg::StatusGl("Move mouse and/or enter coordinates\n" - "[Press 'Shift' to hold position, 'e' to add %s or 'q' to abort]", - name.c_str()); + Msg::StatusGl( + "Move mouse and/or enter coordinates\n" + "[Press 'Shift' to hold position, 'e' to add %s or 'q' to abort]", + name.c_str()); char ib = FlGui::instance()->selectEntity(ENT_NONE); if(!FlGui::available()) return; - if(ib == 'e'){ - switch(pane){ + if(ib == 'e') { + switch(pane) { case 1: scriptAddPoint(GModel::current()->getFileName(), FlGui::instance()->elementaryContext->input[4]->value(), @@ -712,23 +793,25 @@ static void add_new_point_based_entity(const std::string &what, int pane) FlGui::instance()->elementaryContext->input[7]->value()); break; case 2: - scriptAddCircle(GModel::current()->getFileName(), - FlGui::instance()->elementaryContext->input[8]->value(), - FlGui::instance()->elementaryContext->input[9]->value(), - FlGui::instance()->elementaryContext->input[10]->value(), - FlGui::instance()->elementaryContext->input[11]->value(), - FlGui::instance()->elementaryContext->input[12]->value(), - FlGui::instance()->elementaryContext->input[13]->value()); + scriptAddCircle( + GModel::current()->getFileName(), + FlGui::instance()->elementaryContext->input[8]->value(), + FlGui::instance()->elementaryContext->input[9]->value(), + FlGui::instance()->elementaryContext->input[10]->value(), + FlGui::instance()->elementaryContext->input[11]->value(), + FlGui::instance()->elementaryContext->input[12]->value(), + FlGui::instance()->elementaryContext->input[13]->value()); break; case 3: - scriptAddEllipse(GModel::current()->getFileName(), - FlGui::instance()->elementaryContext->input[14]->value(), - FlGui::instance()->elementaryContext->input[15]->value(), - FlGui::instance()->elementaryContext->input[16]->value(), - FlGui::instance()->elementaryContext->input[17]->value(), - FlGui::instance()->elementaryContext->input[18]->value(), - FlGui::instance()->elementaryContext->input[19]->value(), - FlGui::instance()->elementaryContext->input[20]->value()); + scriptAddEllipse( + GModel::current()->getFileName(), + FlGui::instance()->elementaryContext->input[14]->value(), + FlGui::instance()->elementaryContext->input[15]->value(), + FlGui::instance()->elementaryContext->input[16]->value(), + FlGui::instance()->elementaryContext->input[17]->value(), + FlGui::instance()->elementaryContext->input[18]->value(), + FlGui::instance()->elementaryContext->input[19]->value(), + FlGui::instance()->elementaryContext->input[20]->value()); break; case 4: scriptAddDisk(GModel::current()->getFileName(), @@ -739,34 +822,37 @@ static void add_new_point_based_entity(const std::string &what, int pane) FlGui::instance()->elementaryContext->input[25]->value()); break; case 5: - scriptAddRectangle(GModel::current()->getFileName(), - FlGui::instance()->elementaryContext->input[26]->value(), - FlGui::instance()->elementaryContext->input[27]->value(), - FlGui::instance()->elementaryContext->input[28]->value(), - FlGui::instance()->elementaryContext->input[29]->value(), - FlGui::instance()->elementaryContext->input[30]->value(), - FlGui::instance()->elementaryContext->input[31]->value()); + scriptAddRectangle( + GModel::current()->getFileName(), + FlGui::instance()->elementaryContext->input[26]->value(), + FlGui::instance()->elementaryContext->input[27]->value(), + FlGui::instance()->elementaryContext->input[28]->value(), + FlGui::instance()->elementaryContext->input[29]->value(), + FlGui::instance()->elementaryContext->input[30]->value(), + FlGui::instance()->elementaryContext->input[31]->value()); break; case 6: - scriptAddSphere(GModel::current()->getFileName(), - FlGui::instance()->elementaryContext->input[32]->value(), - FlGui::instance()->elementaryContext->input[33]->value(), - FlGui::instance()->elementaryContext->input[34]->value(), - FlGui::instance()->elementaryContext->input[35]->value(), - FlGui::instance()->elementaryContext->input[36]->value(), - FlGui::instance()->elementaryContext->input[37]->value(), - FlGui::instance()->elementaryContext->input[38]->value()); + scriptAddSphere( + GModel::current()->getFileName(), + FlGui::instance()->elementaryContext->input[32]->value(), + FlGui::instance()->elementaryContext->input[33]->value(), + FlGui::instance()->elementaryContext->input[34]->value(), + FlGui::instance()->elementaryContext->input[35]->value(), + FlGui::instance()->elementaryContext->input[36]->value(), + FlGui::instance()->elementaryContext->input[37]->value(), + FlGui::instance()->elementaryContext->input[38]->value()); break; case 7: - scriptAddCylinder(GModel::current()->getFileName(), - FlGui::instance()->elementaryContext->input[39]->value(), - FlGui::instance()->elementaryContext->input[40]->value(), - FlGui::instance()->elementaryContext->input[41]->value(), - FlGui::instance()->elementaryContext->input[42]->value(), - FlGui::instance()->elementaryContext->input[43]->value(), - FlGui::instance()->elementaryContext->input[44]->value(), - FlGui::instance()->elementaryContext->input[45]->value(), - FlGui::instance()->elementaryContext->input[46]->value()); + scriptAddCylinder( + GModel::current()->getFileName(), + FlGui::instance()->elementaryContext->input[39]->value(), + FlGui::instance()->elementaryContext->input[40]->value(), + FlGui::instance()->elementaryContext->input[41]->value(), + FlGui::instance()->elementaryContext->input[42]->value(), + FlGui::instance()->elementaryContext->input[43]->value(), + FlGui::instance()->elementaryContext->input[44]->value(), + FlGui::instance()->elementaryContext->input[45]->value(), + FlGui::instance()->elementaryContext->input[46]->value()); break; case 8: scriptAddBox(GModel::current()->getFileName(), @@ -778,13 +864,14 @@ static void add_new_point_based_entity(const std::string &what, int pane) FlGui::instance()->elementaryContext->input[52]->value()); break; case 9: - scriptAddTorus(GModel::current()->getFileName(), - FlGui::instance()->elementaryContext->input[53]->value(), - FlGui::instance()->elementaryContext->input[54]->value(), - FlGui::instance()->elementaryContext->input[55]->value(), - FlGui::instance()->elementaryContext->input[56]->value(), - FlGui::instance()->elementaryContext->input[57]->value(), - FlGui::instance()->elementaryContext->input[58]->value()); + scriptAddTorus( + GModel::current()->getFileName(), + FlGui::instance()->elementaryContext->input[53]->value(), + FlGui::instance()->elementaryContext->input[54]->value(), + FlGui::instance()->elementaryContext->input[55]->value(), + FlGui::instance()->elementaryContext->input[56]->value(), + FlGui::instance()->elementaryContext->input[57]->value(), + FlGui::instance()->elementaryContext->input[58]->value()); break; case 10: scriptAddCone(GModel::current()->getFileName(), @@ -799,20 +886,21 @@ static void add_new_point_based_entity(const std::string &what, int pane) FlGui::instance()->elementaryContext->input[67]->value()); break; case 11: - scriptAddWedge(GModel::current()->getFileName(), - FlGui::instance()->elementaryContext->input[68]->value(), - FlGui::instance()->elementaryContext->input[69]->value(), - FlGui::instance()->elementaryContext->input[70]->value(), - FlGui::instance()->elementaryContext->input[71]->value(), - FlGui::instance()->elementaryContext->input[72]->value(), - FlGui::instance()->elementaryContext->input[73]->value(), - FlGui::instance()->elementaryContext->input[74]->value()); + scriptAddWedge( + GModel::current()->getFileName(), + FlGui::instance()->elementaryContext->input[68]->value(), + FlGui::instance()->elementaryContext->input[69]->value(), + FlGui::instance()->elementaryContext->input[70]->value(), + FlGui::instance()->elementaryContext->input[71]->value(), + FlGui::instance()->elementaryContext->input[72]->value(), + FlGui::instance()->elementaryContext->input[73]->value(), + FlGui::instance()->elementaryContext->input[74]->value()); break; } FlGui::instance()->resetVisibility(); drawContext::global()->draw(); } - if(ib == 'q'){ + if(ib == 'q') { for(std::size_t i = 0; i < FlGui::instance()->graph.size(); i++) for(std::size_t j = 0; j < FlGui::instance()->graph[i]->gl.size(); j++) FlGui::instance()->graph[i]->gl[j]->addPointMode = 0; @@ -848,14 +936,16 @@ static void add_new_multiline(const std::string &type) char ib = FlGui::instance()->selectEntity(ENT_POINT); if(!FlGui::available()) return; if(ib == 'l') { - for(std::size_t i = 0; i < FlGui::instance()->selectedVertices.size(); i++){ + for(std::size_t i = 0; i < FlGui::instance()->selectedVertices.size(); + i++) { FlGui::instance()->selectedVertices[i]->setSelection(1); p.push_back(FlGui::instance()->selectedVertices[i]->tag()); } drawContext::global()->draw(); } if(ib == 'r') { - Msg::Warning("Entity de-selection not supported yet during multi-line creation"); + Msg::Warning( + "Entity de-selection not supported yet during multi-line creation"); } if(ib == 'e') { if(p.size() >= 2) @@ -866,7 +956,7 @@ static void add_new_multiline(const std::string &type) p.clear(); } if(ib == 'u') { - if(p.size()){ + if(p.size()) { GVertex *gv = GModel::current()->getVertexByTag(p.back()); if(gv) gv->setSelection(0); drawContext::global()->draw(); @@ -907,10 +997,11 @@ static void add_new_line() p.push_back(FlGui::instance()->selectedVertices[0]->tag()); } if(ib == 'r') { - Msg::Warning("Entity de-selection not supported yet during curve creation"); + Msg::Warning( + "Entity de-selection not supported yet during curve creation"); } if(ib == 'u') { - if(p.size()){ + if(p.size()) { GVertex *gv = GModel::current()->getVertexByTag(p.back()); if(gv) gv->setSelection(0); drawContext::global()->draw(); @@ -961,10 +1052,11 @@ static void add_new_circle_arc() p.push_back(FlGui::instance()->selectedVertices[0]->tag()); } if(ib == 'r') { - Msg::Warning("Entity de-selection not supported yet during circle creation"); + Msg::Warning( + "Entity de-selection not supported yet during circle creation"); } if(ib == 'u') { - if(p.size()){ + if(p.size()) { GVertex *gv = GModel::current()->getVertexByTag(p.back()); if(gv) gv->setSelection(0); drawContext::global()->draw(); @@ -1019,10 +1111,11 @@ static void add_new_ellipse_arc() p.push_back(FlGui::instance()->selectedVertices[0]->tag()); } if(ib == 'r') { - Msg::Warning("Entity de-selection not supported yet during ellipse creation"); + Msg::Warning( + "Entity de-selection not supported yet during ellipse creation"); } if(ib == 'u') { - if(p.size()){ + if(p.size()) { GVertex *gv = GModel::current()->getVertexByTag(p.back()); if(gv) gv->setSelection(0); drawContext::global()->draw(); @@ -1035,7 +1128,8 @@ static void add_new_ellipse_arc() break; } if(p.size() == 4) { - scriptAddEllipseArc(p[0], p[1], p[2], p[3], GModel::current()->getFileName()); + scriptAddEllipseArc(p[0], p[1], p[2], p[3], + GModel::current()->getFileName()); FlGui::instance()->resetVisibility(); GModel::current()->setSelection(0); drawContext::global()->draw(); @@ -1046,11 +1140,11 @@ static void add_new_ellipse_arc() Msg::StatusGl(""); } -static int selectContour(int type, int num, List_T * List) +static int selectContour(int type, int num, List_T *List) { int k = 0; - switch (type) { + switch(type) { case ENT_CURVE: k = allEdgesLinked(num, List); for(int i = 0; i < List_Nbr(List); i++) { @@ -1101,7 +1195,7 @@ static void add_new_surface_volume(int mode) while(1) { if(!FlGui::available()) return; - if(type == ENT_CURVE){ + if(type == ENT_CURVE) { if(!List_Nbr(List1)) Msg::StatusGl("Select surface boundary\n" "[Press 'q' to abort]"); @@ -1109,7 +1203,7 @@ static void add_new_surface_volume(int mode) Msg::StatusGl("Select surface boundary\n" "[Press 'u' to undo last selection or 'q' to abort]"); } - else{ + else { if(!List_Nbr(List1)) Msg::StatusGl("Select volume boundary\n" "[Press 'q' to abort]"); @@ -1126,14 +1220,14 @@ static void add_new_surface_volume(int mode) goto stopall; } if(ib == 'u') { - if(List_Nbr(List1) > 0){ + if(List_Nbr(List1) > 0) { int num; - List_Read(List1, List_Nbr(List1)-1, &num); - if(type == ENT_CURVE){ + List_Read(List1, List_Nbr(List1) - 1, &num); + if(type == ENT_CURVE) { GEdge *ge = GModel::current()->getEdgeByTag(abs(num)); if(ge) ge->setSelection(0); } - else{ + else { GFace *gf = GModel::current()->getFaceByTag(abs(num)); if(gf) gf->setSelection(0); } @@ -1147,8 +1241,8 @@ static void add_new_surface_volume(int mode) } if(ib == 'l') { int num = (type == ENT_CURVE) ? - FlGui::instance()->selectedEdges[0]->tag() : - FlGui::instance()->selectedFaces[0]->tag(); + FlGui::instance()->selectedEdges[0]->tag() : + FlGui::instance()->selectedFaces[0]->tag(); if(selectContour(type, num, List1)) { if(type == ENT_CURVE) scriptAddCurveLoop(List1, GModel::current()->getFileName(), &num); @@ -1163,9 +1257,10 @@ static void add_new_surface_volume(int mode) Msg::StatusGl("Select hole boundaries (if none, press 'e')\n" "[Press 'e' to end selection or 'q' to abort]"); else - Msg::StatusGl("Select hole boundaries\n" - "[Press 'e' to end selection, 'u' to undo last selection " - "or 'q' to abort]"); + Msg::StatusGl( + "Select hole boundaries\n" + "[Press 'e' to end selection, 'u' to undo last selection " + "or 'q' to abort]"); ib = FlGui::instance()->selectEntity(type); if(!FlGui::available()) return; if(ib == 'q') { @@ -1180,14 +1275,14 @@ static void add_new_surface_volume(int mode) break; } if(ib == 'u') { - if(List_Nbr(List1) > 0){ + if(List_Nbr(List1) > 0) { int num; - List_Read(List1, List_Nbr(List1)-1, &num); - if(type == ENT_CURVE){ + List_Read(List1, List_Nbr(List1) - 1, &num); + if(type == ENT_CURVE) { GEdge *ge = GModel::current()->getEdgeByTag(abs(num)); if(ge) ge->setSelection(0); } - else{ + else { GFace *gf = GModel::current()->getFaceByTag(abs(num)); if(gf) gf->setSelection(0); } @@ -1197,17 +1292,19 @@ static void add_new_surface_volume(int mode) } if(ib == 'l') { int size = (type == ENT_CURVE) ? - FlGui::instance()->selectedEdges.size() : - FlGui::instance()->selectedFaces.size(); - for(int i=0;i<size;i++){ + FlGui::instance()->selectedEdges.size() : + FlGui::instance()->selectedFaces.size(); + for(int i = 0; i < size; i++) { int num = (type == ENT_CURVE) ? - FlGui::instance()->selectedEdges[i]->tag() : - FlGui::instance()->selectedFaces[i]->tag(); + FlGui::instance()->selectedEdges[i]->tag() : + FlGui::instance()->selectedFaces[i]->tag(); if(selectContour(type, num, List1)) { if(type == ENT_CURVE) - scriptAddCurveLoop(List1, GModel::current()->getFileName(), &num); + scriptAddCurveLoop(List1, GModel::current()->getFileName(), + &num); else - scriptAddSurfaceLoop(List1, GModel::current()->getFileName(), &num); + scriptAddSurfaceLoop( + List1, GModel::current()->getFileName(), &num); List_Reset(List1); List_Add(List2, &num); } @@ -1218,14 +1315,20 @@ static void add_new_surface_volume(int mode) "surface/volume creation"); } } - List_Unique(List2,fcmp_absint); + List_Unique(List2, fcmp_absint); if(List_Nbr(List2)) { - switch (mode) { - case 0: scriptAddSurface("Plane Surface", List2, - GModel::current()->getFileName()); break; - case 1: scriptAddSurface("Surface", List2, - GModel::current()->getFileName()); break; - case 2: scriptAddVolume(List2, GModel::current()->getFileName()); break; + switch(mode) { + case 0: + scriptAddSurface("Plane Surface", List2, + GModel::current()->getFileName()); + break; + case 1: + scriptAddSurface("Surface", List2, + GModel::current()->getFileName()); + break; + case 2: + scriptAddVolume(List2, GModel::current()->getFileName()); + break; } FlGui::instance()->resetVisibility(); GModel::current()->setSelection(0); @@ -1237,7 +1340,7 @@ static void add_new_surface_volume(int mode) } } - stopall: +stopall: List_Delete(List1); List_Delete(List2); @@ -1247,7 +1350,7 @@ static void add_new_surface_volume(int mode) static void geometry_elementary_set_factory_cb(Fl_Widget *w, void *data) { if(!data) return; - std::string str((const char*)data); + std::string str((const char *)data); scriptSetFactory(str, GModel::current()->getFileName()); if(FlGui::available()) Msg::StatusBar(false, "Setting %s factory", str.c_str()); @@ -1257,7 +1360,7 @@ static void geometry_elementary_add_new_cb(Fl_Widget *w, void *data) { if(!data) return; - std::string str((const char*)data); + std::string str((const char *)data); if(str == "Parameter") FlGui::instance()->elementaryContext->show(0); else if(str == "Point") @@ -1304,7 +1407,8 @@ static void geometry_elementary_add_new_cb(Fl_Widget *w, void *data) Msg::Error("Unknown entity to create: %s", str.c_str()); } -static void action_point_line_surface_volume(int action, const std::string &onwhat="") +static void action_point_line_surface_volume(int action, + const std::string &onwhat = "") { drawContext::global()->draw(); @@ -1324,62 +1428,81 @@ static void action_point_line_surface_volume(int action, const std::string &onwh std::string str; int type; - if(what == "Point"){ + if(what == "Point") { str = "points"; type = ENT_POINT; } - else if(what == "Curve"){ + else if(what == "Curve") { str = "curves"; type = ENT_CURVE; } - else if(what == "Surface"){ + else if(what == "Surface") { str = "surfaces"; type = ENT_SURFACE; } - else if(what == "Volume"){ + else if(what == "Volume") { str = "volumes"; type = ENT_VOLUME; } - else{ - switch(FlGui::instance()->transformContext->choice->value()){ - case 1: str = "points"; type = ENT_POINT; break; - case 2: str = "curves"; type = ENT_CURVE; break; - case 3: str = "surfaces"; type = ENT_SURFACE; break; - case 4: str = "volumes"; type = ENT_VOLUME; break; - default: str = "entities"; type = ENT_ALL; break; + else { + switch(FlGui::instance()->transformContext->choice->value()) { + case 1: + str = "points"; + type = ENT_POINT; + break; + case 2: + str = "curves"; + type = ENT_CURVE; + break; + case 3: + str = "surfaces"; + type = ENT_SURFACE; + break; + case 4: + str = "volumes"; + type = ENT_VOLUME; + break; + default: + str = "entities"; + type = ENT_ALL; + break; } } if(dimTags.empty()) Msg::StatusGl("Select %s\n" - "[Press 'e' to end selection or 'q' to abort]", str.c_str()); + "[Press 'e' to end selection or 'q' to abort]", + str.c_str()); else Msg::StatusGl("Select %s\n" "[Press 'e' to end selection, 'u' to undo last selection " - "or 'q' to abort]", str.c_str()); + "or 'q' to abort]", + str.c_str()); char ib = FlGui::instance()->selectEntity(type); if(!FlGui::available()) return; if(ib == 'l') { - for(std::size_t i = 0; i < FlGui::instance()->selectedVertices.size(); i++){ + for(std::size_t i = 0; i < FlGui::instance()->selectedVertices.size(); + i++) { FlGui::instance()->selectedVertices[i]->setSelection(1); std::pair<int, int> t(0, FlGui::instance()->selectedVertices[i]->tag()); if(std::find(dimTags.begin(), dimTags.end(), t) == dimTags.end()) dimTags.push_back(t); } - for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); i++){ + for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); i++) { FlGui::instance()->selectedEdges[i]->setSelection(1); std::pair<int, int> t(1, FlGui::instance()->selectedEdges[i]->tag()); if(std::find(dimTags.begin(), dimTags.end(), t) == dimTags.end()) dimTags.push_back(t); } - for(std::size_t i = 0; i < FlGui::instance()->selectedFaces.size(); i++){ + for(std::size_t i = 0; i < FlGui::instance()->selectedFaces.size(); i++) { FlGui::instance()->selectedFaces[i]->setSelection(1); std::pair<int, int> t(2, FlGui::instance()->selectedFaces[i]->tag()); if(std::find(dimTags.begin(), dimTags.end(), t) == dimTags.end()) dimTags.push_back(t); } - for(std::size_t i = 0; i < FlGui::instance()->selectedRegions.size(); i++){ + for(std::size_t i = 0; i < FlGui::instance()->selectedRegions.size(); + i++) { FlGui::instance()->selectedRegions[i]->setSelection(1); std::pair<int, int> t(3, FlGui::instance()->selectedRegions[i]->tag()); if(std::find(dimTags.begin(), dimTags.end(), t) == dimTags.end()) @@ -1389,37 +1512,39 @@ static void action_point_line_surface_volume(int action, const std::string &onwh } if(ib == 'r') { std::vector<std::pair<int, int> >::iterator it; - for(std::size_t i = 0; i < FlGui::instance()->selectedVertices.size(); i++){ + for(std::size_t i = 0; i < FlGui::instance()->selectedVertices.size(); + i++) { std::pair<int, int> t(0, FlGui::instance()->selectedVertices[i]->tag()); it = std::find(dimTags.begin(), dimTags.end(), t); - if(it != dimTags.end()){ + if(it != dimTags.end()) { dimTags.erase(it); GEntity *ge = GModel::current()->getEntityByTag(t.first, t.second); if(ge) ge->setSelection(0); } } - for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); i++){ + for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); i++) { std::pair<int, int> t(1, FlGui::instance()->selectedEdges[i]->tag()); it = std::find(dimTags.begin(), dimTags.end(), t); - if(it != dimTags.end()){ + if(it != dimTags.end()) { dimTags.erase(it); GEntity *ge = GModel::current()->getEntityByTag(t.first, t.second); if(ge) ge->setSelection(0); } } - for(std::size_t i = 0; i < FlGui::instance()->selectedFaces.size(); i++){ + for(std::size_t i = 0; i < FlGui::instance()->selectedFaces.size(); i++) { std::pair<int, int> t(2, FlGui::instance()->selectedFaces[i]->tag()); it = std::find(dimTags.begin(), dimTags.end(), t); - if(it != dimTags.end()){ + if(it != dimTags.end()) { dimTags.erase(it); GEntity *ge = GModel::current()->getEntityByTag(t.first, t.second); if(ge) ge->setSelection(0); } } - for(std::size_t i = 0; i < FlGui::instance()->selectedRegions.size(); i++){ + for(std::size_t i = 0; i < FlGui::instance()->selectedRegions.size(); + i++) { std::pair<int, int> t(3, FlGui::instance()->selectedRegions[i]->tag()); it = std::find(dimTags.begin(), dimTags.end(), t); - if(it != dimTags.end()){ + if(it != dimTags.end()) { dimTags.erase(it); GEntity *ge = GModel::current()->getEntityByTag(t.first, t.second); if(ge) ge->setSelection(0); @@ -1436,18 +1561,17 @@ static void action_point_line_surface_volume(int action, const std::string &onwh drawContext::global()->draw(); } } - if(ib == 'i') { - Msg::Error("Inverting selection!"); - } + if(ib == 'i') { Msg::Error("Inverting selection!"); } if(ib == 'e') { - if(dimTags.size()){ - switch (action) { + if(dimTags.size()) { + switch(action) { case 0: - scriptTranslate(GModel::current()->getFileName(), dimTags, - FlGui::instance()->transformContext->input[0]->value(), - FlGui::instance()->transformContext->input[1]->value(), - FlGui::instance()->transformContext->input[2]->value(), - FlGui::instance()->transformContext->butt[0]->value()); + scriptTranslate( + GModel::current()->getFileName(), dimTags, + FlGui::instance()->transformContext->input[0]->value(), + FlGui::instance()->transformContext->input[1]->value(), + FlGui::instance()->transformContext->input[2]->value(), + FlGui::instance()->transformContext->butt[0]->value()); break; case 1: scriptRotate(GModel::current()->getFileName(), dimTags, @@ -1501,106 +1625,100 @@ static void action_point_line_surface_volume(int action, const std::string &onwh FlGui::instance()->transformContext->butt[10]->value()); break; case 6: - scriptDeleteEntities(GModel::current()->getFileName(), dimTags, - FlGui::instance()->transformContext->butt[6]->value()); + scriptDeleteEntities( + GModel::current()->getFileName(), dimTags, + FlGui::instance()->transformContext->butt[6]->value()); break; case 7: - case 11: - { - std::vector<int> tags; - int dim = 0; - for(std::size_t i = 0; i < dimTags.size(); i++){ - if((dimTags[i].first == 0 && what == "Point") || - (dimTags[i].first == 1 && what == "Curve") || - (dimTags[i].first == 2 && what == "Surface") || - (dimTags[i].first == 3 && what == "Volume")) { - dim = dimTags[i].first; - tags.push_back(dimTags[i].second); - } + case 11: { + std::vector<int> tags; + int dim = 0; + for(std::size_t i = 0; i < dimTags.size(); i++) { + if((dimTags[i].first == 0 && what == "Point") || + (dimTags[i].first == 1 && what == "Curve") || + (dimTags[i].first == 2 && what == "Surface") || + (dimTags[i].first == 3 && what == "Volume")) { + dim = dimTags[i].first; + tags.push_back(dimTags[i].second); } - scriptAddRemovePhysicalGroup(GModel::current()->getFileName(), what, tags, - FlGui::instance()->physicalContext->selectedName, - FlGui::instance()->physicalContext->selectedTag, - FlGui::instance()->physicalContext->append, - FlGui::instance()->physicalContext->mode); - if(!FlGui::available()) return; + } + scriptAddRemovePhysicalGroup( + GModel::current()->getFileName(), what, tags, + FlGui::instance()->physicalContext->selectedName, + FlGui::instance()->physicalContext->selectedTag, + FlGui::instance()->physicalContext->append, + FlGui::instance()->physicalContext->mode); + if(!FlGui::available()) return; - // ask clients to update using the new physical definition - onelab_cb(nullptr, (void*)"check"); - - // if onelab context parameters are defined for the physical group, - // show the parameter definition window and abort the physical group - // creation loop (otherwise events cannot be processed by outside - // codes through the api, as we are stuck in the while(1) for the - // physical creation mode) - std::vector<std::string> param; - onelab::server::instance()->getParameterNames - (param, "ONELAB Context/" + what + " Template"); - if(tags.size() && param.size() && action == 7) { - FlGui::instance()->getCurrentOpenglWindow()->quitSelection = 1; - FlGui::instance()->getCurrentOpenglWindow()->selectionMode = false; - GModel::current()->setSelection(0); - FlGui::instance()->onelabContext->show(dim, tags[0]); - ib = 'z'; - } - else { - FlGui::instance()->physicalContext->show(what, action == 7 ? false : true); - } + // ask clients to update using the new physical definition + onelab_cb(nullptr, (void *)"check"); + + // if onelab context parameters are defined for the physical group, + // show the parameter definition window and abort the physical group + // creation loop (otherwise events cannot be processed by outside + // codes through the api, as we are stuck in the while(1) for the + // physical creation mode) + std::vector<std::string> param; + onelab::server::instance()->getParameterNames( + param, "ONELAB Context/" + what + " Template"); + if(tags.size() && param.size() && action == 7) { + FlGui::instance()->getCurrentOpenglWindow()->quitSelection = 1; + FlGui::instance()->getCurrentOpenglWindow()->selectionMode = false; + GModel::current()->setSelection(0); + FlGui::instance()->onelabContext->show(dim, tags[0]); + ib = 'z'; } - break; - case 8: - { - std::vector<int> tags; - for(std::size_t i = 0; i < dimTags.size(); i++){ - if(dimTags[i].first == 0 && what == "Point") - tags.push_back(dimTags[i].second); - } - if(tags.size()) - scriptSetMeshSize(GModel::current()->getFileName(), tags, - FlGui::instance()->meshContext->input[0]->value()); + else { + FlGui::instance()->physicalContext->show(what, action == 7 ? false : + true); } - break; - case 9: - { - std::vector<int> tags; - for(std::size_t i = 0; i < dimTags.size(); i++){ - if(dimTags[i].first == 2 && what == "Surface") - tags.push_back(dimTags[i].second); - } - scriptRecombineSurface(GModel::current()->getFileName(), tags); + } break; + case 8: { + std::vector<int> tags; + for(std::size_t i = 0; i < dimTags.size(); i++) { + if(dimTags[i].first == 0 && what == "Point") + tags.push_back(dimTags[i].second); } - break; - case 10: - { - std::vector<int> tags; - for(std::size_t i = 0; i < dimTags.size(); i++){ - if((dimTags[i].first == 1 && what == "Curve") || - (dimTags[i].first == 2 && what == "Surface") || - (dimTags[i].first == 3 && what == "Volume")) - tags.push_back(dimTags[i].second); - } - scriptSetCompound(GModel::current()->getFileName(), what, tags); + if(tags.size()) + scriptSetMeshSize( + GModel::current()->getFileName(), tags, + FlGui::instance()->meshContext->input[0]->value()); + } break; + case 9: { + std::vector<int> tags; + for(std::size_t i = 0; i < dimTags.size(); i++) { + if(dimTags[i].first == 2 && what == "Surface") + tags.push_back(dimTags[i].second); } - break; + scriptRecombineSurface(GModel::current()->getFileName(), tags); + } break; + case 10: { + std::vector<int> tags; + for(std::size_t i = 0; i < dimTags.size(); i++) { + if((dimTags[i].first == 1 && what == "Curve") || + (dimTags[i].first == 2 && what == "Surface") || + (dimTags[i].first == 3 && what == "Volume")) + tags.push_back(dimTags[i].second); + } + scriptSetCompound(GModel::current()->getFileName(), what, tags); + } break; case 12: - if(dimTagsSaved.empty()){ + if(dimTagsSaved.empty()) { dimTagsSaved = dimTags; dimTags.clear(); what = "Curve"; continue; } - else{ + else { std::vector<int> l; - for(std::size_t i = 0; i < dimTags.size(); i++){ + for(std::size_t i = 0; i < dimTags.size(); i++) { if(dimTags[i].first == 1) l.push_back(dimTags[i].second); } scriptAddPipe(GModel::current()->getFileName(), dimTagsSaved, l); dimTagsSaved.clear(); } break; - default: - Msg::Error("Unknown action on selected entities"); - break; + default: Msg::Error("Unknown action on selected entities"); break; } dimTags.clear(); FlGui::instance()->resetVisibility(); @@ -1689,7 +1807,7 @@ static void geometry_elementary_boolean_cb(Fl_Widget *w, void *data) if(!data) return; FlGui::instance()->transformContext->show(4); - std::string mode((const char*)data); + std::string mode((const char *)data); bool selectObject = true; std::vector<std::pair<int, int> > object, tool; @@ -1700,19 +1818,21 @@ static void geometry_elementary_boolean_cb(Fl_Widget *w, void *data) Msg::StatusGl("Select object\n" "[Press 'e' to end selection or 'q' to abort]"); else if(selectObject) - Msg::StatusGl("Select object\n" - "[Press 'e' to end selection, 'u' to undo last selection or " - "'q' to abort]"); + Msg::StatusGl( + "Select object\n" + "[Press 'e' to end selection, 'u' to undo last selection or " + "'q' to abort]"); else if(tool.empty()) Msg::StatusGl("Select tool\n" "[Press 'e' to end selection or 'q' to abort]"); else - Msg::StatusGl("Select tool\n" - "[Press 'e' to end selection, 'u' to undo last selection or " - "'q' to abort]"); + Msg::StatusGl( + "Select tool\n" + "[Press 'e' to end selection, 'u' to undo last selection or " + "'q' to abort]"); int type = ENT_ALL; - switch(FlGui::instance()->transformContext->choice->value()){ + switch(FlGui::instance()->transformContext->choice->value()) { case 1: type = ENT_POINT; break; case 2: type = ENT_CURVE; break; case 3: type = ENT_SURFACE; break; @@ -1722,8 +1842,8 @@ static void geometry_elementary_boolean_cb(Fl_Widget *w, void *data) char ib = FlGui::instance()->selectEntity(type); if(!FlGui::available()) return; if(ib == 'l') { - for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); i++){ - if(FlGui::instance()->selectedEdges[i]->getSelection() != 1){ + for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); i++) { + if(FlGui::instance()->selectedEdges[i]->getSelection() != 1) { FlGui::instance()->selectedEdges[i]->setSelection(1); std::pair<int, int> t(1, FlGui::instance()->selectedEdges[i]->tag()); if(selectObject) @@ -1732,8 +1852,8 @@ static void geometry_elementary_boolean_cb(Fl_Widget *w, void *data) tool.push_back(t); } } - for(std::size_t i = 0; i < FlGui::instance()->selectedFaces.size(); i++){ - if(FlGui::instance()->selectedFaces[i]->getSelection() != 1){ + for(std::size_t i = 0; i < FlGui::instance()->selectedFaces.size(); i++) { + if(FlGui::instance()->selectedFaces[i]->getSelection() != 1) { FlGui::instance()->selectedFaces[i]->setSelection(1); std::pair<int, int> t(2, FlGui::instance()->selectedFaces[i]->tag()); if(selectObject) @@ -1742,10 +1862,12 @@ static void geometry_elementary_boolean_cb(Fl_Widget *w, void *data) tool.push_back(t); } } - for(std::size_t i = 0; i < FlGui::instance()->selectedRegions.size(); i++){ - if(FlGui::instance()->selectedRegions[i]->getSelection() != 1){ + for(std::size_t i = 0; i < FlGui::instance()->selectedRegions.size(); + i++) { + if(FlGui::instance()->selectedRegions[i]->getSelection() != 1) { FlGui::instance()->selectedRegions[i]->setSelection(1); - std::pair<int, int> t(3, FlGui::instance()->selectedRegions[i]->tag()); + std::pair<int, int> t(3, + FlGui::instance()->selectedRegions[i]->tag()); if(selectObject) object.push_back(t); else @@ -1754,16 +1876,17 @@ static void geometry_elementary_boolean_cb(Fl_Widget *w, void *data) } } if(ib == 'r') { - Msg::Warning("Entity de-selection not supported yet during boolean operation"); + Msg::Warning( + "Entity de-selection not supported yet during boolean operation"); } if(ib == 'u') { - if(selectObject && object.size()){ + if(selectObject && object.size()) { std::pair<int, int> t = object.back(); GEntity *ge = GModel::current()->getEntityByTag(t.first, t.second); if(ge) ge->setSelection(0); object.pop_back(); } - else if(tool.size()){ + else if(tool.size()) { std::pair<int, int> t = tool.back(); GEntity *ge = GModel::current()->getEntityByTag(t.first, t.second); if(ge) ge->setSelection(0); @@ -1771,20 +1894,21 @@ static void geometry_elementary_boolean_cb(Fl_Widget *w, void *data) } } if(ib == 'e') { - if(selectObject){ + if(selectObject) { if(object.empty()) Msg::Error("At least one object must be selected"); else selectObject = false; } - else if(tool.empty() && mode != "BooleanFragments"){ + else if(tool.empty() && mode != "BooleanFragments") { Msg::Error("At least one tool must be selected"); } - else{ + else { scriptBoolean(GModel::current()->getFileName(), mode, object, tool, FlGui::instance()->transformContext->butt[4]->value(), tool.size() ? - FlGui::instance()->transformContext->butt[5]->value() : 0); + FlGui::instance()->transformContext->butt[5]->value() : + 0); GModel::current()->setSelection(0); selectObject = true; object.clear(); @@ -1819,59 +1943,64 @@ static void geometry_elementary_fillet_cb(Fl_Widget *w, void *data) Msg::StatusGl("Select volume\n" "[Press 'e' to end selection or 'q' to abort]"); else if(selectRegions) - Msg::StatusGl("Select volume\n" - "[Press 'e' to end selection, 'u' to undo last selection or " - "'q' to abort]"); + Msg::StatusGl( + "Select volume\n" + "[Press 'e' to end selection, 'u' to undo last selection or " + "'q' to abort]"); else if(edges.empty()) Msg::StatusGl("Select curve\n" "[Press 'e' to end selection or 'q' to abort]"); else - Msg::StatusGl("Select curve\n" - "[Press 'e' to end selection, 'u' to undo last selection or " - "'q' to abort]"); + Msg::StatusGl( + "Select curve\n" + "[Press 'e' to end selection, 'u' to undo last selection or " + "'q' to abort]"); - char ib = FlGui::instance()->selectEntity(selectRegions ? ENT_VOLUME : ENT_CURVE); + char ib = + FlGui::instance()->selectEntity(selectRegions ? ENT_VOLUME : ENT_CURVE); if(!FlGui::available()) return; if(ib == 'l') { - for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); i++){ - if(FlGui::instance()->selectedEdges[i]->getSelection() != 1){ + for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); i++) { + if(FlGui::instance()->selectedEdges[i]->getSelection() != 1) { FlGui::instance()->selectedEdges[i]->setSelection(1); edges.push_back(FlGui::instance()->selectedEdges[i]->tag()); } } - for(std::size_t i = 0; i < FlGui::instance()->selectedRegions.size(); i++){ - if(FlGui::instance()->selectedRegions[i]->getSelection() != 1){ + for(std::size_t i = 0; i < FlGui::instance()->selectedRegions.size(); + i++) { + if(FlGui::instance()->selectedRegions[i]->getSelection() != 1) { FlGui::instance()->selectedRegions[i]->setSelection(1); regions.push_back(FlGui::instance()->selectedRegions[i]->tag()); } } } if(ib == 'r') { - Msg::Warning("Entity de-selection not supported yet during boolean operation"); + Msg::Warning( + "Entity de-selection not supported yet during boolean operation"); } if(ib == 'u') { - if(selectRegions && regions.size()){ + if(selectRegions && regions.size()) { GRegion *ge = GModel::current()->getRegionByTag(regions.back()); if(ge) ge->setSelection(0); regions.pop_back(); } - else if(edges.size()){ + else if(edges.size()) { GEdge *ge = GModel::current()->getEdgeByTag(edges.back()); if(ge) ge->setSelection(0); edges.pop_back(); } } if(ib == 'e') { - if(selectRegions){ + if(selectRegions) { if(regions.empty()) Msg::Error("At least one volume must be selected"); else selectRegions = false; } - else if(edges.empty()){ + else if(edges.empty()) { Msg::Error("At least one curve must be selected"); } - else{ + else { scriptFillet(GModel::current()->getFileName(), regions, edges, FlGui::instance()->transformContext->input[20]->value()); GModel::current()->setSelection(0); @@ -1898,15 +2027,13 @@ static void geometry_elementary_split_cb(Fl_Widget *w, void *data) drawContext::global()->draw(); Msg::StatusGl("Select curve to split\n" "[Press 'q' to abort]"); - GEdge* edge_to_split = nullptr; - while(1){ + GEdge *edge_to_split = nullptr; + while(1) { if(!FlGui::available()) return; char ib = FlGui::instance()->selectEntity(ENT_CURVE); if(!FlGui::available()) return; - if(ib == 'q') { - break; - } + if(ib == 'q') { break; } if(!FlGui::instance()->selectedEdges.empty()) { edge_to_split = FlGui::instance()->selectedEdges[0]; edge_to_split->setSelection(1); @@ -1920,19 +2047,19 @@ static void geometry_elementary_split_cb(Fl_Widget *w, void *data) "[Press 'e' to end selection or 'q' to abort]"); opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); drawContext::global()->draw(); - while(1){ + while(1) { if(!FlGui::available()) return; char ib = FlGui::instance()->selectEntity(ENT_POINT); if(!FlGui::available()) return; - if(ib == 'q') { + if(ib == 'q') { break; } + if(ib == 'e' && edge_to_split) { + scriptSplitCurve(edge_to_split->tag(), List1, + GModel::current()->getFileName()); break; } - if(ib == 'e' && edge_to_split){ - scriptSplitCurve(edge_to_split->tag(), List1, GModel::current()->getFileName()); - break; - } - for(std::size_t i = 0; i < FlGui::instance()->selectedVertices.size(); i++){ + for(std::size_t i = 0; i < FlGui::instance()->selectedVertices.size(); + i++) { int tag = FlGui::instance()->selectedVertices[i]->tag(); int index = List_ISearchSeq(List1, &tag, fcmp_int); if(index < 0) List_Add(List1, &tag); @@ -1953,7 +2080,7 @@ static void geometry_elementary_coherence_cb(Fl_Widget *w, void *data) static void geometry_physical_add_cb(Fl_Widget *w, void *data) { if(!data) return; - std::string what((const char*)data); + std::string what((const char *)data); FlGui::instance()->physicalContext->show(what, false); action_point_line_surface_volume(7, what); if(!FlGui::available()) return; @@ -1963,7 +2090,7 @@ static void geometry_physical_add_cb(Fl_Widget *w, void *data) static void geometry_physical_remove_cb(Fl_Widget *w, void *data) { if(!data) return; - std::string what((const char*)data); + std::string what((const char *)data); FlGui::instance()->physicalContext->show(what, true); action_point_line_surface_volume(11, what); if(FlGui::available()) FlGui::instance()->physicalContext->hide(); @@ -1972,7 +2099,7 @@ static void geometry_physical_remove_cb(Fl_Widget *w, void *data) void mesh_save_cb(Fl_Widget *w, void *data) { std::string name = CTX::instance()->outputFileName; - if(name.empty()){ + if(name.empty()) { if(CTX::instance()->mesh.fileFormat == FORMAT_AUTO) name = GetDefaultFileName(FORMAT_MSH); else @@ -2005,32 +2132,33 @@ void mesh_3d_cb(Fl_Widget *w, void *data) drawContext::global()->draw(); } -static void mesh_modify_parts(Fl_Widget *w, void *data, const std::string &action) +static void mesh_modify_parts(Fl_Widget *w, void *data, + const std::string &action) { - const char *str = (const char*)data; + const char *str = (const char *)data; int what; - if(!strcmp(str, "elements")){ + if(!strcmp(str, "elements")) { CTX::instance()->pickElements = 1; what = ENT_ALL; } - else if(!strcmp(str, "curves")){ + else if(!strcmp(str, "curves")) { CTX::instance()->pickElements = 0; what = ENT_CURVE; } - else if(!strcmp(str, "surfaces")){ + else if(!strcmp(str, "surfaces")) { CTX::instance()->pickElements = 0; what = ENT_SURFACE; } - else if(!strcmp(str, "volumes")){ + else if(!strcmp(str, "volumes")) { CTX::instance()->pickElements = 0; what = ENT_VOLUME; } else return; - std::vector<MElement*> ele; - std::vector<GEntity*> ent; + std::vector<MElement *> ele; + std::vector<GEntity *> ent; while(1) { if(!FlGui::available()) return; @@ -2039,39 +2167,46 @@ static void mesh_modify_parts(Fl_Widget *w, void *data, const std::string &actio drawContext::global()->draw(); if(ele.size() || ent.size()) - Msg::StatusGl("Select %s\n" - "[Press 'e' to end selection, 'u' to undo last selection or " - "'q' to abort]", str); + Msg::StatusGl( + "Select %s\n" + "[Press 'e' to end selection, 'u' to undo last selection or " + "'q' to abort]", + str); else Msg::StatusGl("Select %s\n" - "[Press 'e' to end selection or 'q' to abort]", str); + "[Press 'e' to end selection or 'q' to abort]", + str); char ib = FlGui::instance()->selectEntity(what); if(!FlGui::available()) return; if(ib == 'l') { - if(CTX::instance()->pickElements){ - for(std::size_t i = 0; i < FlGui::instance()->selectedElements.size(); i++){ - if(FlGui::instance()->selectedElements[i]->getVisibility() != 2){ + if(CTX::instance()->pickElements) { + for(std::size_t i = 0; i < FlGui::instance()->selectedElements.size(); + i++) { + if(FlGui::instance()->selectedElements[i]->getVisibility() != 2) { FlGui::instance()->selectedElements[i]->setVisibility(2); ele.push_back(FlGui::instance()->selectedElements[i]); } } } - else{ - for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); i++){ - if(FlGui::instance()->selectedEdges[i]->getSelection() != 1){ + else { + for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); + i++) { + if(FlGui::instance()->selectedEdges[i]->getSelection() != 1) { FlGui::instance()->selectedEdges[i]->setSelection(1); ent.push_back(FlGui::instance()->selectedEdges[i]); } } - for(std::size_t i = 0; i < FlGui::instance()->selectedFaces.size(); i++){ - if(FlGui::instance()->selectedFaces[i]->getSelection() != 1){ + for(std::size_t i = 0; i < FlGui::instance()->selectedFaces.size(); + i++) { + if(FlGui::instance()->selectedFaces[i]->getSelection() != 1) { FlGui::instance()->selectedFaces[i]->setSelection(1); ent.push_back(FlGui::instance()->selectedFaces[i]); } } - for(std::size_t i = 0; i < FlGui::instance()->selectedRegions.size(); i++){ - if(FlGui::instance()->selectedRegions[i]->getSelection() != 1){ + for(std::size_t i = 0; i < FlGui::instance()->selectedRegions.size(); + i++) { + if(FlGui::instance()->selectedRegions[i]->getSelection() != 1) { FlGui::instance()->selectedRegions[i]->setSelection(1); ent.push_back(FlGui::instance()->selectedRegions[i]); } @@ -2079,41 +2214,43 @@ static void mesh_modify_parts(Fl_Widget *w, void *data, const std::string &actio } } if(ib == 'r') { - if(CTX::instance()->pickElements){ - for(std::size_t i = 0; i < FlGui::instance()->selectedElements.size(); i++) + if(CTX::instance()->pickElements) { + for(std::size_t i = 0; i < FlGui::instance()->selectedElements.size(); + i++) FlGui::instance()->selectedElements[i]->setVisibility(1); } - else{ + else { for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); i++) FlGui::instance()->selectedEdges[i]->setSelection(0); for(std::size_t i = 0; i < FlGui::instance()->selectedFaces.size(); i++) FlGui::instance()->selectedFaces[i]->setSelection(0); - for(std::size_t i = 0; i < FlGui::instance()->selectedRegions.size(); i++) + for(std::size_t i = 0; i < FlGui::instance()->selectedRegions.size(); + i++) FlGui::instance()->selectedRegions[i]->setSelection(0); } } if(ib == 'u') { - if(CTX::instance()->pickElements){ - if(ele.size()){ + if(CTX::instance()->pickElements) { + if(ele.size()) { ele[ele.size() - 1]->setVisibility(1); ele.pop_back(); } } - else{ - if(ent.size()){ + else { + if(ent.size()) { ent[ent.size() - 1]->setSelection(0); ent.pop_back(); } } } if(ib == 'e') { - if(CTX::instance()->pickElements){ + if(CTX::instance()->pickElements) { for(std::size_t i = 0; i < ele.size(); i++) if(ele[i]->getVisibility() == 2) ele[i]->setVisibility(0); } - else{ + else { for(std::size_t i = 0; i < ent.size(); i++) - if(ent[i]->getSelection() == 1){ + if(ent[i]->getSelection() == 1) { ent[i]->setVisibility(0); ent[i]->setSelection(0); } @@ -2162,19 +2299,19 @@ static void mesh_inspect_cb(Fl_Widget *w, void *data) char ib = FlGui::instance()->selectEntity(ENT_ALL); if(!FlGui::available()) return; if(ib == 'l') { - if(FlGui::instance()->selectedElements.size()){ + if(FlGui::instance()->selectedElements.size()) { MElement *ele = FlGui::instance()->selectedElements[0]; GModel::current()->setSelection(0); ele->setVisibility(2); CTX::instance()->mesh.changed = ENT_ALL; drawContext::global()->draw(); - std::vector<std::string> info = SplitString(ele->getInfoString(true), '\n'); + std::vector<std::string> info = + SplitString(ele->getInfoString(true), '\n'); for(std::size_t i = 0; i < info.size(); i++) Msg::Direct("%s", info[i].c_str()); - if(CTX::instance()->tooltips){ + if(CTX::instance()->tooltips) { std::string str; - for(std::size_t i = 0; i < info.size(); i++) - str += info[i] + "\n"; + for(std::size_t i = 0; i < info.size(); i++) str += info[i] + "\n"; FlGui::instance()->getCurrentOpenglWindow()->drawTooltip(str); } } @@ -2214,7 +2351,7 @@ static void mesh_optimize_cb(Fl_Widget *w, void *data) static void mesh_cross_compute_cb(Fl_Widget *w, void *data) { std::vector<int> tags; - computeCrossField (GModel::current(), tags); + computeCrossField(GModel::current(), tags); drawContext::global()->draw(); } @@ -2250,10 +2387,7 @@ static void mesh_optimize_netgen_cb(Fl_Widget *w, void *data) } #endif -static void mesh_partition_cb(Fl_Widget *w, void *data) -{ - partition_dialog(); -} +static void mesh_partition_cb(Fl_Widget *w, void *data) { partition_dialog(); } static void mesh_unpartition_cb(Fl_Widget *w, void *data) { @@ -2296,7 +2430,7 @@ static void mesh_define_recombine_cb(Fl_Widget *w, void *data) static void mesh_define_transfinite(int dim) { opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); - switch (dim) { + switch(dim) { case 1: opt_geometry_curves(0, GMSH_SET | GMSH_GUI, 1); break; case 2: opt_geometry_surfaces(0, GMSH_SET | GMSH_GUI, 1); break; case 3: opt_geometry_volumes(0, GMSH_SET | GMSH_GUI, 1); break; @@ -2308,7 +2442,7 @@ static void mesh_define_transfinite(int dim) while(1) { if(!FlGui::available()) return; - switch (dim) { + switch(dim) { case 1: if(p.empty()) Msg::StatusGl("Select curves\n" @@ -2330,18 +2464,17 @@ static void mesh_define_transfinite(int dim) ib = FlGui::instance()->selectEntity(ENT_VOLUME); if(!FlGui::available()) return; break; - default: - ib = 'l'; - break; + default: ib = 'l'; break; } if(ib == 'e') { if(dim == 1) { if(p.size()) - scriptSetTransfiniteLine(p, GModel::current()->getFileName(), - FlGui::instance()->meshContext->choice[0]->text(), - FlGui::instance()->meshContext->input[2]->value(), - FlGui::instance()->meshContext->input[1]->value()); + scriptSetTransfiniteLine( + p, GModel::current()->getFileName(), + FlGui::instance()->meshContext->choice[0]->text(), + FlGui::instance()->meshContext->input[2]->value(), + FlGui::instance()->meshContext->input[1]->value()); } GModel::current()->setSelection(0); drawContext::global()->draw(); @@ -2349,7 +2482,7 @@ static void mesh_define_transfinite(int dim) } if(ib == 'u') { if(dim == 1) { - if(p.size()){ + if(p.size()) { GEdge *ge = GModel::current()->getEdgeByTag(p.back()); if(ge) ge->setSelection(0); drawContext::global()->draw(); @@ -2367,9 +2500,10 @@ static void mesh_define_transfinite(int dim) "transfinite definition"); } if(ib == 'l') { - switch (dim) { + switch(dim) { case 1: - for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); i++){ + for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); + i++) { FlGui::instance()->selectedEdges[i]->setSelection(1); p.push_back(FlGui::instance()->selectedEdges[i]->tag()); } @@ -2377,12 +2511,12 @@ static void mesh_define_transfinite(int dim) break; case 2: case 3: - if(dim == 2){ + if(dim == 2) { FlGui::instance()->selectedFaces[0]->setSelection(1); drawContext::global()->draw(); p.push_back(FlGui::instance()->selectedFaces[0]->tag()); } - else{ + else { FlGui::instance()->selectedRegions[0]->setSelection(1); drawContext::global()->draw(); p.push_back(FlGui::instance()->selectedRegions[0]->tag()); @@ -2394,13 +2528,15 @@ static void mesh_define_transfinite(int dim) Msg::StatusGl("Select (ordered) boundary points\n" "[Press 'e' to end selection or 'q' to abort]"); else - Msg::StatusGl("Select (ordered) boundary points\n" - "[Press 'e' to end selection, 'u' to undo last selection " - "or 'q' to abort]"); + Msg::StatusGl( + "Select (ordered) boundary points\n" + "[Press 'e' to end selection, 'u' to undo last selection " + "or 'q' to abort]"); ib = FlGui::instance()->selectEntity(ENT_POINT); if(!FlGui::available()) return; if(ib == 'l') { - for(std::size_t i = 0; i < FlGui::instance()->selectedVertices.size(); i++){ + for(std::size_t i = 0; + i < FlGui::instance()->selectedVertices.size(); i++) { FlGui::instance()->selectedVertices[i]->setSelection(1); p.push_back(FlGui::instance()->selectedVertices[i]->tag()); break; @@ -2408,7 +2544,7 @@ static void mesh_define_transfinite(int dim) drawContext::global()->draw(); } if(ib == 'u') { - if(p.size() > 1){ + if(p.size() > 1) { GVertex *gv = GModel::current()->getVertexByTag(p.back()); if(gv) gv->setSelection(0); drawContext::global()->draw(); @@ -2420,11 +2556,12 @@ static void mesh_define_transfinite(int dim) "transfinite definition"); } if(ib == 'e') { - switch (dim) { + switch(dim) { case 2: if((p.size() == 0 + 1 || p.size() == 3 + 1 || p.size() == 4 + 1)) - scriptSetTransfiniteSurface(p, GModel::current()->getFileName(), - FlGui::instance()->meshContext->choice[1]->text()); + scriptSetTransfiniteSurface( + p, GModel::current()->getFileName(), + FlGui::instance()->meshContext->choice[1]->text()); else Msg::Error("Wrong number of points for mesh constraint"); break; @@ -2451,7 +2588,7 @@ static void mesh_define_transfinite(int dim) } } - stopall: +stopall: Msg::StatusGl(""); } @@ -2477,24 +2614,28 @@ static void mesh_define_transfinite_volume_cb(Fl_Widget *w, void *data) static void mesh_define_embedded_cb(Fl_Widget *w, void *data) { if(!data) return; - std::string what((const char*)data); + std::string what((const char *)data); std::vector<int> entities; bool selectEntities = true; - int type; const char *str = ""; - if(what == "Surface"){ - type = ENT_SURFACE; str = "surfaces"; + int type; + const char *str = ""; + if(what == "Surface") { + type = ENT_SURFACE; + str = "surfaces"; opt_geometry_surfaces(0, GMSH_SET | GMSH_GUI, 1); } - else if(what == "Curve"){ - type = ENT_CURVE; str = "curves"; + else if(what == "Curve") { + type = ENT_CURVE; + str = "curves"; opt_geometry_curves(0, GMSH_SET | GMSH_GUI, 1); } - else if(what == "Point"){ - type = ENT_POINT; str = "points"; + else if(what == "Point") { + type = ENT_POINT; + str = "points"; opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); } - else{ + else { Msg::Error("Unknown type of entity to embed: %s", what.c_str()); return; } @@ -2503,17 +2644,21 @@ static void mesh_define_embedded_cb(Fl_Widget *w, void *data) if(entities.empty()) Msg::StatusGl("Select %s\n" - "[Press 'e' to end selection or 'q' to abort]", str); + "[Press 'e' to end selection or 'q' to abort]", + str); else if(selectEntities) - Msg::StatusGl("Select %s\n" - "[Press 'e' to end selection, 'u' to undo last selection or " - "'q' to abort]", str); + Msg::StatusGl( + "Select %s\n" + "[Press 'e' to end selection, 'u' to undo last selection or " + "'q' to abort]", + str); else Msg::StatusGl("Select entity in which to embed the %s\n" - "[Press 'q' to abort]", str); + "[Press 'q' to abort]", + str); int t = type; - if(!selectEntities){ - switch(FlGui::instance()->transformContext->choice->value()){ + if(!selectEntities) { + switch(FlGui::instance()->transformContext->choice->value()) { case 2: t = ENT_CURVE; break; case 3: t = ENT_SURFACE; break; case 4: t = ENT_VOLUME; break; @@ -2523,32 +2668,35 @@ static void mesh_define_embedded_cb(Fl_Widget *w, void *data) char ib = FlGui::instance()->selectEntity(t); if(!FlGui::available()) return; if(ib == 'l') { - if(selectEntities && what == "Point"){ - for(std::size_t i = 0; i < FlGui::instance()->selectedVertices.size(); i++){ - if(FlGui::instance()->selectedVertices[i]->getSelection() != 1){ + if(selectEntities && what == "Point") { + for(std::size_t i = 0; i < FlGui::instance()->selectedVertices.size(); + i++) { + if(FlGui::instance()->selectedVertices[i]->getSelection() != 1) { FlGui::instance()->selectedVertices[i]->setSelection(1); entities.push_back(FlGui::instance()->selectedVertices[i]->tag()); } } } - else if(selectEntities && what == "Curve"){ - for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); i++){ - if(FlGui::instance()->selectedEdges[i]->getSelection() != 1){ + else if(selectEntities && what == "Curve") { + for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); + i++) { + if(FlGui::instance()->selectedEdges[i]->getSelection() != 1) { FlGui::instance()->selectedEdges[i]->setSelection(1); entities.push_back(FlGui::instance()->selectedEdges[i]->tag()); } } } - else if(selectEntities && what == "Surface"){ - for(std::size_t i = 0; i < FlGui::instance()->selectedFaces.size(); i++){ - if(FlGui::instance()->selectedFaces[i]->getSelection() != 1){ + else if(selectEntities && what == "Surface") { + for(std::size_t i = 0; i < FlGui::instance()->selectedFaces.size(); + i++) { + if(FlGui::instance()->selectedFaces[i]->getSelection() != 1) { FlGui::instance()->selectedFaces[i]->setSelection(1); entities.push_back(FlGui::instance()->selectedFaces[i]->tag()); } } } else if(!selectEntities && (FlGui::instance()->selectedFaces.size() || - FlGui::instance()->selectedRegions.size())){ + FlGui::instance()->selectedRegions.size())) { int dim = FlGui::instance()->selectedFaces.size() ? 2 : 3; if(dim == 2) FlGui::instance()->selectedFaces[0]->setSelection(1); @@ -2556,7 +2704,7 @@ static void mesh_define_embedded_cb(Fl_Widget *w, void *data) FlGui::instance()->selectedRegions[0]->setSelection(1); drawContext::global()->draw(); int tag = (dim == 2) ? FlGui::instance()->selectedFaces[0]->tag() : - FlGui::instance()->selectedRegions[0]->tag(); + FlGui::instance()->selectedRegions[0]->tag(); scriptEmbed(GModel::current()->getFileName(), what, entities, dim, tag); GModel::current()->setSelection(0); selectEntities = true; @@ -2564,10 +2712,11 @@ static void mesh_define_embedded_cb(Fl_Widget *w, void *data) } } if(ib == 'r') { - Msg::Warning("Entity de-selection not supported yet during boolean operation"); + Msg::Warning( + "Entity de-selection not supported yet during boolean operation"); } if(ib == 'u') { - if(selectEntities && entities.size()){ + if(selectEntities && entities.size()) { int dim = (what == "Surface") ? 2 : (what == "Curve") ? 1 : 0; GEntity *ge = GModel::current()->getEntityByTag(dim, entities.back()); if(ge) ge->setSelection(0); @@ -2575,7 +2724,7 @@ static void mesh_define_embedded_cb(Fl_Widget *w, void *data) } } if(ib == 'e') { - if(selectEntities){ + if(selectEntities) { if(entities.empty()) Msg::Error("At least one entity must be selected"); else @@ -2598,6 +2747,8 @@ static void mesh_define_compound_entity_cb(Fl_Widget *w, void *data) action_point_line_surface_volume(10, (const char *)data); } +// clang-format off + // The static menus (we cannot use the 'g', 'm' 's' and 'p' mnemonics since they // are already defined as global shortcuts) static Fl_Menu_Item bar_table[] = { @@ -2740,6 +2891,8 @@ static Fl_Menu_Item sysbar_table[] = { #endif +// clang-format on + static graphicWindow *getGraphicWindow(Fl_Widget *w) { if(!w || !w->parent()) return FlGui::instance()->graph[0]; @@ -2751,114 +2904,118 @@ static graphicWindow *getGraphicWindow(Fl_Widget *w) void status_xyz1p_cb(Fl_Widget *w, void *data) { - const char *str = (const char*)data; + const char *str = (const char *)data; - std::vector<openglWindow*> gls; + std::vector<openglWindow *> gls; if(w) gls = getGraphicWindow(w)->gl; else gls.push_back(FlGui::instance()->getCurrentOpenglWindow()); - for(std::size_t i = 0; i < gls.size(); i++){ + for(std::size_t i = 0; i < gls.size(); i++) { drawContext *ctx = gls[i]->getDrawContext(); - if(!strcmp(str, "r")){ + if(!strcmp(str, "r")) { // rotate +90 or -90 (shift) degress around axis perp to the // screen, or sync rotation with first window (Ctrl) double axis[3] = {0., 0., 1.}; - if(Fl::event_state(FL_CTRL) || Fl::event_state(FL_META)){ - if(i != 0){ + if(Fl::event_state(FL_CTRL) || Fl::event_state(FL_META)) { + if(i != 0) { drawContext *ctx0 = gls[0]->getDrawContext(); ctx->setQuaternion(ctx0->quaternion[0], ctx0->quaternion[1], ctx0->quaternion[2], ctx0->quaternion[3]); } } - else if(!Fl::event_state(FL_SHIFT)){ + else if(!Fl::event_state(FL_SHIFT)) { ctx->addQuaternionFromAxisAndAngle(axis, -90.); - if (CTX::instance()->camera) ctx->camera.tiltHeadRight(); + if(CTX::instance()->camera) ctx->camera.tiltHeadRight(); } - else{ + else { ctx->addQuaternionFromAxisAndAngle(axis, 90.); - if (CTX::instance()->camera) ctx->camera.tiltHeadLeft(); + if(CTX::instance()->camera) ctx->camera.tiltHeadLeft(); } } - else if(!strcmp(str, "x")){ + else if(!strcmp(str, "x")) { // set X-axis pointing out or into (shift) the screen - if (CTX::instance()->camera) { - ctx->camera.alongX();} - else{ - if(!Fl::event_state(FL_SHIFT)){ - ctx->r[0] = -90.; ctx->r[1] = 0.; ctx->r[2] = -90.; - } - else{ - ctx->r[0] = -90.; ctx->r[1] = 0.; ctx->r[2] = 90.; - } - ctx->setQuaternionFromEulerAngles(); + if(CTX::instance()->camera) { ctx->camera.alongX(); } + else { + if(!Fl::event_state(FL_SHIFT)) { + ctx->r[0] = -90.; + ctx->r[1] = 0.; + ctx->r[2] = -90.; + } + else { + ctx->r[0] = -90.; + ctx->r[1] = 0.; + ctx->r[2] = 90.; + } + ctx->setQuaternionFromEulerAngles(); } } - else if(!strcmp(str, "y")){ + else if(!strcmp(str, "y")) { // set Y-axis pointing out or into (shift) the screen - if (CTX::instance()->camera) { - ctx->camera.alongY();} - else{ - if(!Fl::event_state(FL_SHIFT)){ - ctx->r[0] = -90.; ctx->r[1] = 0.; ctx->r[2] = 180.; - } - else{ - ctx->r[0] = -90.; ctx->r[1] = 0.; ctx->r[2] = 0.; - } - ctx->setQuaternionFromEulerAngles(); + if(CTX::instance()->camera) { ctx->camera.alongY(); } + else { + if(!Fl::event_state(FL_SHIFT)) { + ctx->r[0] = -90.; + ctx->r[1] = 0.; + ctx->r[2] = 180.; + } + else { + ctx->r[0] = -90.; + ctx->r[1] = 0.; + ctx->r[2] = 0.; + } + ctx->setQuaternionFromEulerAngles(); } } - else if(!strcmp(str, "z")){ + else if(!strcmp(str, "z")) { // set Z-axis pointing out or into (shift) the screen - if (CTX::instance()->camera) { - ctx->camera.alongZ();} - else{ - if(!Fl::event_state(FL_SHIFT)){ - ctx->r[0] = 0.; ctx->r[1] = 0.; ctx->r[2] = 0.; - } - else{ - ctx->r[0] = 0.; ctx->r[1] = 180.; ctx->r[2] = 0.; - } - ctx->setQuaternionFromEulerAngles(); + if(CTX::instance()->camera) { ctx->camera.alongZ(); } + else { + if(!Fl::event_state(FL_SHIFT)) { + ctx->r[0] = 0.; + ctx->r[1] = 0.; + ctx->r[2] = 0.; + } + else { + ctx->r[0] = 0.; + ctx->r[1] = 180.; + ctx->r[2] = 0.; + } + ctx->setQuaternionFromEulerAngles(); } } - else if(!strcmp(str, "1:1")){ + else if(!strcmp(str, "1:1")) { // if Shift is pressed, reset bounding box around visible // entities - if(Fl::event_state(FL_SHIFT)) - SetBoundingBox(true); + if(Fl::event_state(FL_SHIFT)) SetBoundingBox(true); // reset translation and scaling, or sync translation and // scaling with the first window (alt) - if (CTX::instance()->camera) { - ctx->camera.lookAtCg(); - } - else{ - if(Fl::event_state(FL_CTRL) || Fl::event_state(FL_META)){ - if(i != 0){ - drawContext *ctx0 = gls[0]->getDrawContext(); - for(int j = 0; j < 3; j++){ - ctx->t[j] = ctx0->t[j]; - ctx->s[j] = ctx0->s[j]; - } - } - } - else{ - ctx->t[0] = ctx->t[1] = ctx->t[2] = 0.; - ctx->s[0] = ctx->s[1] = ctx->s[2] = 1.; - } + if(CTX::instance()->camera) { ctx->camera.lookAtCg(); } + else { + if(Fl::event_state(FL_CTRL) || Fl::event_state(FL_META)) { + if(i != 0) { + drawContext *ctx0 = gls[0]->getDrawContext(); + for(int j = 0; j < 3; j++) { + ctx->t[j] = ctx0->t[j]; + ctx->s[j] = ctx0->s[j]; + } + } + } + else { + ctx->t[0] = ctx->t[1] = ctx->t[2] = 0.; + ctx->s[0] = ctx->s[1] = ctx->s[2] = 1.; + } } } - else if(!strcmp(str, "reset")){ - if (CTX::instance()->camera) { - ctx->camera.init(); - } - else{ - // reset everything - ctx->t[0] = ctx->t[1] = ctx->t[2] = 0.; - ctx->s[0] = ctx->s[1] = ctx->s[2] = 1.; - ctx->r[0] = ctx->r[1] = ctx->r[2] = 0.; - ctx->setQuaternionFromEulerAngles(); + else if(!strcmp(str, "reset")) { + if(CTX::instance()->camera) { ctx->camera.init(); } + else { + // reset everything + ctx->t[0] = ctx->t[1] = ctx->t[2] = 0.; + ctx->s[0] = ctx->s[1] = ctx->s[2] = 1.; + ctx->r[0] = ctx->r[1] = ctx->r[2] = 0.; + ctx->setQuaternionFromEulerAngles(); } } } @@ -2869,7 +3026,7 @@ void status_xyz1p_cb(Fl_Widget *w, void *data) void quick_access_cb(Fl_Widget *w, void *data) { if(!data) return; - std::string what((const char*)data); + std::string what((const char *)data); if(what == "general") general_options_cb(nullptr, nullptr); else if(what == "geometry") @@ -2878,78 +3035,76 @@ void quick_access_cb(Fl_Widget *w, void *data) mesh_options_cb(nullptr, nullptr); else if(what == "view") view_options_cb(nullptr, (void *)-1); - else if(what == "reset_viewport"){ + else if(what == "reset_viewport") { status_xyz1p_cb(nullptr, (void *)"1:1"); status_xyz1p_cb(nullptr, (void *)"z"); } - else if(what == "select_center"){ + else if(what == "select_center") { opt_general_rotation_center_cg(0, GMSH_SET | GMSH_GUI, 0); general_options_ok_cb(nullptr, (void *)"rotation_center"); general_options_rotation_center_select_cb(nullptr, nullptr); } - else if(what == "hover_meshes"){ - opt_general_mouse_hover_meshes(0, GMSH_SET|GMSH_GUI, - !opt_general_mouse_hover_meshes(0, GMSH_GET, 0)); + else if(what == "hover_meshes") { + opt_general_mouse_hover_meshes( + 0, GMSH_SET | GMSH_GUI, !opt_general_mouse_hover_meshes(0, GMSH_GET, 0)); } - else if(what == "split_hor"){ - file_window_cb(nullptr, (void*)"split_h"); + else if(what == "split_hor") { + file_window_cb(nullptr, (void *)"split_h"); } - else if(what == "split_ver"){ - file_window_cb(nullptr, (void*)"split_v"); + else if(what == "split_ver") { + file_window_cb(nullptr, (void *)"split_v"); } - else if(what == "unsplit"){ - file_window_cb(nullptr, (void*)"split_u"); + else if(what == "unsplit") { + file_window_cb(nullptr, (void *)"split_u"); } - else if(what == "axes"){ + else if(what == "axes") { int old = opt_general_axes(0, GMSH_GET, 0); - opt_general_axes(0, GMSH_SET|GMSH_GUI, old ? 0 : 3); - if(!old){ - opt_general_axes_auto_position(0, GMSH_SET|GMSH_GUI, 0); + opt_general_axes(0, GMSH_SET | GMSH_GUI, old ? 0 : 3); + if(!old) { + opt_general_axes_auto_position(0, GMSH_SET | GMSH_GUI, 0); general_options_axes_fit_cb(nullptr, nullptr); } } else if(what == "orthographic") opt_general_orthographic(0, GMSH_SET | GMSH_GUI, 1); - else if(what == "perspective"){ + else if(what == "perspective") { opt_general_orthographic(0, GMSH_SET | GMSH_GUI, 0); drawContext::global()->draw(); - numberOrStringOptionChooser("General", 0, "ClipFactor", - true, "Factor", true, 0.1, 20., 0.1); + numberOrStringOptionChooser("General", 0, "ClipFactor", true, "Factor", + true, 0.1, 20., 0.1); } else if(what == "geometry_points") - opt_geometry_points(0, GMSH_SET|GMSH_GUI, + opt_geometry_points(0, GMSH_SET | GMSH_GUI, !opt_geometry_points(0, GMSH_GET, 0)); else if(what == "geometry_curves") - opt_geometry_curves(0, GMSH_SET|GMSH_GUI, - !opt_geometry_curves(0, GMSH_GET, 0)); + opt_geometry_curves(0, GMSH_SET | GMSH_GUI, + !opt_geometry_curves(0, GMSH_GET, 0)); else if(what == "geometry_surfaces") - opt_geometry_surfaces(0, GMSH_SET|GMSH_GUI, + opt_geometry_surfaces(0, GMSH_SET | GMSH_GUI, !opt_geometry_surfaces(0, GMSH_GET, 0)); else if(what == "geometry_volumes") - opt_geometry_volumes(0, GMSH_SET|GMSH_GUI, + opt_geometry_volumes(0, GMSH_SET | GMSH_GUI, !opt_geometry_volumes(0, GMSH_GET, 0)); else if(what == "mesh_points") - opt_mesh_points(0, GMSH_SET|GMSH_GUI, - !opt_mesh_points(0, GMSH_GET, 0)); + opt_mesh_points(0, GMSH_SET | GMSH_GUI, !opt_mesh_points(0, GMSH_GET, 0)); else if(what == "mesh_lines") - opt_mesh_lines(0, GMSH_SET|GMSH_GUI, - !opt_mesh_lines(0, GMSH_GET, 0)); + opt_mesh_lines(0, GMSH_SET | GMSH_GUI, !opt_mesh_lines(0, GMSH_GET, 0)); else if(what == "mesh_surfaces_edges") - opt_mesh_surfaces_edges(0, GMSH_SET|GMSH_GUI, + opt_mesh_surfaces_edges(0, GMSH_SET | GMSH_GUI, !opt_mesh_surfaces_edges(0, GMSH_GET, 0)); else if(what == "mesh_surfaces_faces") - opt_mesh_surfaces_faces(0, GMSH_SET|GMSH_GUI, + opt_mesh_surfaces_faces(0, GMSH_SET | GMSH_GUI, !opt_mesh_surfaces_faces(0, GMSH_GET, 0)); else if(what == "mesh_volumes_edges") - opt_mesh_volumes_edges(0, GMSH_SET|GMSH_GUI, + opt_mesh_volumes_edges(0, GMSH_SET | GMSH_GUI, !opt_mesh_volumes_edges(0, GMSH_GET, 0)); else if(what == "mesh_volumes_faces") - opt_mesh_volumes_faces(0, GMSH_SET|GMSH_GUI, + opt_mesh_volumes_faces(0, GMSH_SET | GMSH_GUI, !opt_mesh_volumes_faces(0, GMSH_GET, 0)); else if(what == "mesh_size") - numberOrStringOptionChooser("Mesh", 0, "MeshSizeFactor", - true, "Factor", true, 0.01, 100, 0.01); - else if(what == "view_element_outlines"){ + numberOrStringOptionChooser("Mesh", 0, "MeshSizeFactor", true, "Factor", + true, 0.01, 100, 0.01); + else if(what == "view_element_outlines") { int set = 0; for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0) && @@ -2957,121 +3112,122 @@ void quick_access_cb(Fl_Widget *w, void *data) break; for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_show_element(i, GMSH_SET|GMSH_GUI, !set); + opt_view_show_element(i, GMSH_SET | GMSH_GUI, !set); } - else if(what == "view_normal_raise"){ + else if(what == "view_normal_raise") { double val = 0.; - for(std::size_t i = 0; i < PView::list.size(); i++){ - if(opt_view_visible(i, GMSH_GET, 0)){ + for(std::size_t i = 0; i < PView::list.size(); i++) { + if(opt_view_visible(i, GMSH_GET, 0)) { double maxval = std::max(fabs(opt_view_min(i, GMSH_GET, 0)), fabs(opt_view_max(i, GMSH_GET, 0))); if(!maxval) maxval = 1.; double val2 = 2. * CTX::instance()->lc / maxval; - val = numberOrStringOptionChooser("View", i, "NormalRaise", - true, "Raise", true, -val2, val2, val2 / 200.); + val = + numberOrStringOptionChooser("View", i, "NormalRaise", true, "Raise", + true, -val2, val2, val2 / 200.); break; } } for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_normal_raise(i, GMSH_SET|GMSH_GUI, val); + opt_view_normal_raise(i, GMSH_SET | GMSH_GUI, val); } - else if(what == "view_iso"){ + else if(what == "view_iso") { for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_intervals_type(i, GMSH_SET|GMSH_GUI, 1); + opt_view_intervals_type(i, GMSH_SET | GMSH_GUI, 1); drawContext::global()->draw(); double val = 0.; - for(std::size_t i = 0; i < PView::list.size(); i++){ - if(opt_view_visible(i, GMSH_GET, 0)){ - val = numberOrStringOptionChooser("View", i, "NbIso", - true, "Intervals", true, 1, 100, 1); + for(std::size_t i = 0; i < PView::list.size(); i++) { + if(opt_view_visible(i, GMSH_GET, 0)) { + val = numberOrStringOptionChooser("View", i, "NbIso", true, "Intervals", + true, 1, 100, 1); break; } } for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_nb_iso(i, GMSH_SET|GMSH_GUI, val); + opt_view_nb_iso(i, GMSH_SET | GMSH_GUI, val); } - else if(what == "view_continous"){ + else if(what == "view_continous") { for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_intervals_type(i, GMSH_SET|GMSH_GUI, 2); + opt_view_intervals_type(i, GMSH_SET | GMSH_GUI, 2); } - else if(what == "view_filled"){ + else if(what == "view_filled") { for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_intervals_type(i, GMSH_SET|GMSH_GUI, 3); + opt_view_intervals_type(i, GMSH_SET | GMSH_GUI, 3); drawContext::global()->draw(); double val = 0.; - for(std::size_t i = 0; i < PView::list.size(); i++){ - if(opt_view_visible(i, GMSH_GET, 0)){ - val = numberOrStringOptionChooser("View", i, "NbIso", - true, "Intervals", true, 1, 100, 1); + for(std::size_t i = 0; i < PView::list.size(); i++) { + if(opt_view_visible(i, GMSH_GET, 0)) { + val = numberOrStringOptionChooser("View", i, "NbIso", true, "Intervals", + true, 1, 100, 1); break; } } for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_nb_iso(i, GMSH_SET|GMSH_GUI, val); + opt_view_nb_iso(i, GMSH_SET | GMSH_GUI, val); } - else if(what == "view_numeric"){ + else if(what == "view_numeric") { for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_intervals_type(i, GMSH_SET|GMSH_GUI, 4); + opt_view_intervals_type(i, GMSH_SET | GMSH_GUI, 4); } - else if(what == "view_line"){ + else if(what == "view_line") { for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_vector_type(i, GMSH_SET|GMSH_GUI, 1); + opt_view_vector_type(i, GMSH_SET | GMSH_GUI, 1); } - else if(what == "view_3d_arrow"){ + else if(what == "view_3d_arrow") { for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_vector_type(i, GMSH_SET|GMSH_GUI, 4); + opt_view_vector_type(i, GMSH_SET | GMSH_GUI, 4); } - else if(what == "view_displacement"){ + else if(what == "view_displacement") { for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_vector_type(i, GMSH_SET|GMSH_GUI, 5); + opt_view_vector_type(i, GMSH_SET | GMSH_GUI, 5); drawContext::global()->draw(); double val = 0.; - for(std::size_t i = 0; i < PView::list.size(); i++){ - if(opt_view_visible(i, GMSH_GET, 0)){ + for(std::size_t i = 0; i < PView::list.size(); i++) { + if(opt_view_visible(i, GMSH_GET, 0)) { double maxval = std::max(fabs(opt_view_min(i, GMSH_GET, 0)), fabs(opt_view_max(i, GMSH_GET, 0))); if(!maxval) maxval = 1.; double val3 = 2. * CTX::instance()->lc / maxval; - val = numberOrStringOptionChooser("View", i, "DisplacementFactor", - true, "Factor", true, 0, val3, val3 / 100.); + val = numberOrStringOptionChooser("View", i, "DisplacementFactor", true, + "Factor", true, 0, val3, val3 / 100.); break; } } for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_displacement_factor(i, GMSH_SET|GMSH_GUI, val); + opt_view_displacement_factor(i, GMSH_SET | GMSH_GUI, val); } - else if(what == "view_glyph_barycenter"){ + else if(what == "view_glyph_barycenter") { for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_glyph_location(i, GMSH_SET|GMSH_GUI, 1); + opt_view_glyph_location(i, GMSH_SET | GMSH_GUI, 1); } - else if(what == "view_glyph_node"){ + else if(what == "view_glyph_node") { for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_glyph_location(i, GMSH_SET|GMSH_GUI, 2); + opt_view_glyph_location(i, GMSH_SET | GMSH_GUI, 2); } - else if(what == "view_range_default"){ + else if(what == "view_range_default") { for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_range_type(i, GMSH_SET|GMSH_GUI, 1); + opt_view_range_type(i, GMSH_SET | GMSH_GUI, 1); } - else if(what == "view_range_per_step"){ + else if(what == "view_range_per_step") { for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_range_type(i, GMSH_SET|GMSH_GUI, 3); + opt_view_range_type(i, GMSH_SET | GMSH_GUI, 3); } - else if(what == "mesh_toggle"){ + else if(what == "mesh_toggle") { static int value = 1; static int old_p = (int)opt_mesh_points(0, GMSH_GET, 0.); static int old_l = (int)opt_mesh_lines(0, GMSH_GET, 0.); @@ -3079,7 +3235,7 @@ void quick_access_cb(Fl_Widget *w, void *data) static int old_sf = (int)opt_mesh_surfaces_faces(0, GMSH_GET, 0.); static int old_ve = (int)opt_mesh_volumes_edges(0, GMSH_GET, 0.); static int old_vf = (int)opt_mesh_volumes_faces(0, GMSH_GET, 0.); - if(!value){ // retore visibility + if(!value) { // retore visibility Msg::StatusBar(false, "Mesh display restored"); value = 1; opt_mesh_points(0, GMSH_SET | GMSH_GUI, old_p); @@ -3089,7 +3245,7 @@ void quick_access_cb(Fl_Widget *w, void *data) opt_mesh_volumes_edges(0, GMSH_SET | GMSH_GUI, old_ve); opt_mesh_volumes_faces(0, GMSH_SET | GMSH_GUI, old_vf); } - else{ + else { Msg::StatusBar(false, "Mesh display OFF"); value = 0; old_p = (int)opt_mesh_points(0, GMSH_GET, 0.); @@ -3112,7 +3268,7 @@ void quick_access_cb(Fl_Widget *w, void *data) #endif } -static void model_switch_cb(Fl_Widget* w, void *data) +static void model_switch_cb(Fl_Widget *w, void *data) { int index = (intptr_t)data; GModel::current(index); @@ -3129,21 +3285,22 @@ static void model_switch_cb(Fl_Widget* w, void *data) void status_options_cb(Fl_Widget *w, void *data) { if(!data) return; - std::string what((const char*)data); + std::string what((const char *)data); - if(what == "model"){ // model selection - std::vector<char*> tofree; + if(what == "model") { // model selection + std::vector<char *> tofree; std::vector<Fl_Menu_Item> menu; int selected = 0; - for(std::size_t i = 0; i < GModel::list.size(); i++){ + for(std::size_t i = 0; i < GModel::list.size(); i++) { std::ostringstream sstream; sstream << "Model " << i; if(GModel::list[i]->getName().size()) sstream << " - " << GModel::list[i]->getName(); sstream << " "; char *str = strdup(sstream.str().c_str()); - Fl_Menu_Item menuItem = {str, 0, model_switch_cb, (void*)(intptr_t)i, FL_MENU_RADIO}; - if(GModel::list[i] == GModel::current()){ + Fl_Menu_Item menuItem = {str, 0, model_switch_cb, (void *)(intptr_t)i, + FL_MENU_RADIO}; + if(GModel::list[i] == GModel::current()) { selected = i; menuItem.flags |= FL_MENU_VALUE; } @@ -3152,22 +3309,23 @@ void status_options_cb(Fl_Widget *w, void *data) } Fl_Menu_Item it = {nullptr}; menu.push_back(it); - Fl_Menu_Item *m = (Fl_Menu_Item*)(&menu[0])->popup(Fl::event_x(), Fl::event_y(), - nullptr, &menu[selected], nullptr); + Fl_Menu_Item *m = (Fl_Menu_Item *)(&menu[0])->popup( + Fl::event_x(), Fl::event_y(), nullptr, &menu[selected], nullptr); if(m) m->do_callback(nullptr); for(std::size_t i = 0; i < tofree.size(); i++) free(tofree[i]); drawContext::global()->draw(); } - else if(what == "?"){ // display options + else if(what == "?") { // display options help_options_cb(nullptr, nullptr); FlGui::instance()->help->options->show(); } - else if(what == "p"){ // toggle projection mode + else if(what == "p") { // toggle projection mode opt_general_orthographic(0, GMSH_SET | GMSH_GUI, !opt_general_orthographic(0, GMSH_GET, 0)); drawContext::global()->draw(); } - else if(what == "quick_access"){ // quick access menu + else if(what == "quick_access") { // quick access menu + // clang-format off static Fl_Menu_Item menu[] = { { "Reset viewport", 0, quick_access_cb, (void*)"reset_viewport" }, { "Select rotation center", 0, quick_access_cb, (void*)"select_center" }, @@ -3241,46 +3399,71 @@ void status_options_cb(Fl_Widget *w, void *data) { "All view options...", 0, quick_access_cb, (void*)"view", 0, 0, FL_ITALIC }, { nullptr } }; + // clang-format on const int gen = 7, geo = 14, msh = 21, pos = 32, end = 54; - if(opt_general_axes(0, GMSH_GET, 0)) menu[gen + 0].set(); - else menu[gen + 0].clear(); - if(opt_general_mouse_hover_meshes(0, GMSH_GET, 0)) menu[gen + 1].set(); - else menu[gen + 1].clear(); + if(opt_general_axes(0, GMSH_GET, 0)) + menu[gen + 0].set(); + else + menu[gen + 0].clear(); + if(opt_general_mouse_hover_meshes(0, GMSH_GET, 0)) + menu[gen + 1].set(); + else + menu[gen + 1].clear(); for(std::size_t i = 0; i < PView::list.size(); i++) if(opt_view_visible(i, GMSH_GET, 0) && opt_view_axes(i, GMSH_GET, 0)) menu[gen + 7].set(); - if(opt_geometry_points(0, GMSH_GET, 0)) menu[geo + 1].set(); - else menu[geo + 1].clear(); - if(opt_geometry_curves(0, GMSH_GET, 0)) menu[geo + 2].set(); - else menu[geo + 2].clear(); - if(opt_geometry_surfaces(0, GMSH_GET, 0)) menu[geo + 3].set(); - else menu[geo + 3].clear(); - if(opt_geometry_volumes(0, GMSH_GET, 0)) menu[geo + 4].set(); - else menu[geo + 4].clear(); - if(opt_mesh_points(0, GMSH_GET, 0)) menu[msh + 1].set(); - else menu[msh + 1].clear(); - if(opt_mesh_lines(0, GMSH_GET, 0)) menu[msh + 2].set(); - else menu[msh + 2].clear(); - if(opt_mesh_surfaces_edges(0, GMSH_GET, 0)) menu[msh + 3].set(); - else menu[msh + 3].clear(); - if(opt_mesh_surfaces_faces(0, GMSH_GET, 0)) menu[msh + 4].set(); - else menu[msh + 4].clear(); - if(opt_mesh_volumes_edges(0, GMSH_GET, 0)) menu[msh + 5].set(); - else menu[msh + 5].clear(); - if(opt_mesh_volumes_faces(0, GMSH_GET, 0)) menu[msh + 6].set(); - else menu[msh + 6].clear(); - if(PView::list.empty()){ + if(opt_geometry_points(0, GMSH_GET, 0)) + menu[geo + 1].set(); + else + menu[geo + 1].clear(); + if(opt_geometry_curves(0, GMSH_GET, 0)) + menu[geo + 2].set(); + else + menu[geo + 2].clear(); + if(opt_geometry_surfaces(0, GMSH_GET, 0)) + menu[geo + 3].set(); + else + menu[geo + 3].clear(); + if(opt_geometry_volumes(0, GMSH_GET, 0)) + menu[geo + 4].set(); + else + menu[geo + 4].clear(); + if(opt_mesh_points(0, GMSH_GET, 0)) + menu[msh + 1].set(); + else + menu[msh + 1].clear(); + if(opt_mesh_lines(0, GMSH_GET, 0)) + menu[msh + 2].set(); + else + menu[msh + 2].clear(); + if(opt_mesh_surfaces_edges(0, GMSH_GET, 0)) + menu[msh + 3].set(); + else + menu[msh + 3].clear(); + if(opt_mesh_surfaces_faces(0, GMSH_GET, 0)) + menu[msh + 4].set(); + else + menu[msh + 4].clear(); + if(opt_mesh_volumes_edges(0, GMSH_GET, 0)) + menu[msh + 5].set(); + else + menu[msh + 5].clear(); + if(opt_mesh_volumes_faces(0, GMSH_GET, 0)) + menu[msh + 6].set(); + else + menu[msh + 6].clear(); + if(PView::list.empty()) { // if there are no post-processing view, hide all entries below the mesh // options... menu[pos - 1].flags = 0; for(int i = pos; i <= end; i++) menu[i].hide(); } - else{ + else { // otherwise add a divider and show the post-pro view entries menu[pos - 1].flags = FL_MENU_DIVIDER; for(int i = pos; i <= end; i++) menu[i].show(); menu[pos].clear(); - for(std::size_t i = 0; i < PView::list.size(); i++){ + for(std::size_t i = 0; i < PView::list.size(); i++) { if(opt_view_visible(i, GMSH_GET, 0) && opt_view_show_element(i, GMSH_GET, 0)) { menu[pos].set(); @@ -3289,20 +3472,22 @@ void status_options_cb(Fl_Widget *w, void *data) } } // popup the menu - static Fl_Menu_Item *picked = &menu[msh + 8]; // toggle mesh display - the default - picked = (Fl_Menu_Item*)menu->popup(Fl::event_x(), Fl::event_y(), nullptr, - (picked && picked->visible()) ? picked : - &menu[msh + 8], nullptr); - if(picked && picked->callback()) picked->do_callback(nullptr, picked->user_data()); + static Fl_Menu_Item *picked = + &menu[msh + 8]; // toggle mesh display - the default + picked = (Fl_Menu_Item *)menu->popup( + Fl::event_x(), Fl::event_y(), nullptr, + (picked && picked->visible()) ? picked : &menu[msh + 8], nullptr); + if(picked && picked->callback()) + picked->do_callback(nullptr, picked->user_data()); drawContext::global()->draw(); } - else if(what == "S"){ // mouse selection - if(CTX::instance()->mouseSelection){ + else if(what == "S") { // mouse selection + if(CTX::instance()->mouseSelection) { opt_general_mouse_selection(0, GMSH_SET | GMSH_GUI, 0); for(std::size_t i = 0; i < FlGui::instance()->graph.size(); i++) for(std::size_t j = 0; j < FlGui::instance()->graph[i]->gl.size(); j++) - FlGui::instance()->graph[i]->gl[j]->cursor - (FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE); + FlGui::instance()->graph[i]->gl[j]->cursor(FL_CURSOR_DEFAULT, + FL_BLACK, FL_WHITE); } else opt_general_mouse_selection(0, GMSH_SET | GMSH_GUI, 1); @@ -3325,12 +3510,12 @@ void status_play_manual(int time, int incr, bool redraw) file_watch_cb(nullptr, nullptr); if(time) { - for(std::size_t i = 0; i < PView::list.size(); i++){ - if(opt_view_visible(i, GMSH_GET, 0)){ + for(std::size_t i = 0; i < PView::list.size(); i++) { + if(opt_view_visible(i, GMSH_GET, 0)) { // skip empty steps int step = (int)opt_view_timestep(i, GMSH_GET, 0) + incr; int numSteps = (int)opt_view_nb_timestep(i, GMSH_GET, 0); - for(int j = 0; j < numSteps; j++){ + for(int j = 0; j < numSteps; j++) { if(PView::list[i]->getData()->hasTimeStep(step)) break; else @@ -3349,14 +3534,12 @@ void status_play_manual(int time, int incr, bool redraw) opt_view_visible(i, GMSH_SET | GMSH_GUI, (i == view_in_cycle)); } else if(incr > 0) { - if((view_in_cycle += incr) >= (int)PView::list.size()) - view_in_cycle = 0; + if((view_in_cycle += incr) >= (int)PView::list.size()) view_in_cycle = 0; for(int i = 0; i < (int)PView::list.size(); i++) opt_view_visible(i, GMSH_SET | GMSH_GUI, (i == view_in_cycle)); } else { - if((view_in_cycle += incr) < 0) - view_in_cycle = PView::list.size() - 1; + if((view_in_cycle += incr) < 0) view_in_cycle = PView::list.size() - 1; for(int i = PView::list.size() - 1; i >= 0; i--) opt_view_visible(i, GMSH_SET | GMSH_GUI, (i == view_in_cycle)); } @@ -3374,11 +3557,11 @@ static void status_play_cb(Fl_Widget *w, void *data) while(1) { if(!FlGui::available()) return; - if(stop_anim) - break; + if(stop_anim) break; if(TimeOfDay() - anim_time > CTX::instance()->post.animDelay) { anim_time = TimeOfDay(); - status_play_manual(!CTX::instance()->post.animCycle, CTX::instance()->post.animStep); + status_play_manual(!CTX::instance()->post.animCycle, + CTX::instance()->post.animStep); } FlGui::check(); } @@ -3408,25 +3591,27 @@ static void status_rewind_cb(Fl_Widget *w, void *data) static void status_stepbackward_cb(Fl_Widget *w, void *data) { - status_play_manual(!CTX::instance()->post.animCycle, -CTX::instance()->post.animStep); + status_play_manual(!CTX::instance()->post.animCycle, + -CTX::instance()->post.animStep); } static void status_stepforward_cb(Fl_Widget *w, void *data) { - status_play_manual(!CTX::instance()->post.animCycle, CTX::instance()->post.animStep); + status_play_manual(!CTX::instance()->post.animCycle, + CTX::instance()->post.animStep); } static void remove_graphic_window_cb(Fl_Widget *w, void *data) { - std::vector<graphicWindow*> graph2; + std::vector<graphicWindow *> graph2; graphicWindow *deleteMe = nullptr; - for(std::size_t i = 0; i < FlGui::instance()->graph.size(); i++){ + for(std::size_t i = 0; i < FlGui::instance()->graph.size(); i++) { if(FlGui::instance()->graph[i]->getWindow() == w) deleteMe = FlGui::instance()->graph[i]; else graph2.push_back(FlGui::instance()->graph[i]); } - if(deleteMe){ + if(deleteMe) { openglWindow::setLastHandled(nullptr); FlGui::instance()->graph = graph2; delete deleteMe; @@ -3435,56 +3620,56 @@ static void remove_graphic_window_cb(Fl_Widget *w, void *data) void show_hide_message_cb(Fl_Widget *w, void *data) { - graphicWindow *g = getGraphicWindow - (FlGui::instance()->getCurrentOpenglWindow()->parent()); + graphicWindow *g = + getGraphicWindow(FlGui::instance()->getCurrentOpenglWindow()->parent()); g->showHideMessages(); FlGui::check(); } void show_hide_menu_cb(Fl_Widget *w, void *data) { - graphicWindow *g = getGraphicWindow - (FlGui::instance()->getCurrentOpenglWindow()->parent()); + graphicWindow *g = + getGraphicWindow(FlGui::instance()->getCurrentOpenglWindow()->parent()); g->showHideMenu(); FlGui::check(); } void attach_detach_menu_cb(Fl_Widget *w, void *data) { - graphicWindow *g = getGraphicWindow - (FlGui::instance()->getCurrentOpenglWindow()->parent()); + graphicWindow *g = + getGraphicWindow(FlGui::instance()->getCurrentOpenglWindow()->parent()); g->attachDetachMenu(); FlGui::check(); } static void message_menu_autoscroll_cb(Fl_Widget *w, void *data) { - graphicWindow *g = (graphicWindow*)data; + graphicWindow *g = (graphicWindow *)data; g->setAutoScroll(!g->getAutoScroll()); } static void message_menu_clear_cb(Fl_Widget *w, void *data) { - graphicWindow *g = (graphicWindow*)data; + graphicWindow *g = (graphicWindow *)data; g->clearMessages(); } static void message_menu_save_cb(Fl_Widget *w, void *data) { - graphicWindow *g = (graphicWindow*)data; + graphicWindow *g = (graphicWindow *)data; if(fileChooser(FILE_CHOOSER_CREATE, "Save Messages", "")) g->saveMessages(fileChooserGetName(1).c_str()); } static void message_browser_cb(Fl_Widget *w, void *data) { - graphicWindow *g = (graphicWindow*)data; + graphicWindow *g = (graphicWindow *)data; g->copySelectedMessagesToClipboard(); } static void message_menu_search_cb(Fl_Widget *w, void *data) { - graphicWindow *g = (graphicWindow*)data; + graphicWindow *g = (graphicWindow *)data; g->getMessageBrowser()->clear(); for(int i = 0; i < (int)g->getMessages().size(); i++) g->getMessageBrowser()->add(g->getMessages()[i].c_str()); @@ -3492,7 +3677,7 @@ static void message_menu_search_cb(Fl_Widget *w, void *data) static void tile_cb(Fl_Widget *w, void *data) { - if(Fl::event() == FL_RELEASE){ + if(Fl::event() == FL_RELEASE) { // rebuild the tree when we relase the mouse after resizing FlGui::instance()->rebuildTree(true); } @@ -3502,25 +3687,29 @@ static void tile_cb(Fl_Widget *w, void *data) // FL_ENTER/FL_LEAVE events (the box widget in fltk > 1.1 does that, so that // gl->handle() was not called when the mouse moved) class dummyBox : public Fl_Box { - private: - int handle(int){ return 0; } // always! - public: - dummyBox(int x, int y, int w, int h, const char *l=nullptr) : Fl_Box(x, y, w, h, l) {} +private: + int handle(int) { return 0; } // always! +public: + dummyBox(int x, int y, int w, int h, const char *l = nullptr) + : Fl_Box(x, y, w, h, l) + { + } }; // The main graphic window has a special resize behaviour forcing the message // tile to always keep its height class mainWindowSpecialResize : public mainWindow { - public: - mainWindowSpecialResize(int w, int h, bool nonModal, const char *l=nullptr) - : mainWindow(w, h, nonModal, l) {} - virtual void resize(int X,int Y,int W,int H) +public: + mainWindowSpecialResize(int w, int h, bool nonModal, const char *l = nullptr) + : mainWindow(w, h, nonModal, l) + { + } + virtual void resize(int X, int Y, int W, int H) { bool special = (FlGui::available() && shown() && - this == FlGui::instance()->graph[0]->getWindow()); + this == FlGui::instance()->graph[0]->getWindow()); int mh = 0; - if(special) - mh = FlGui::instance()->graph[0]->getMessageHeight(); + if(special) mh = FlGui::instance()->graph[0]->getMessageHeight(); Fl_Window::resize(X, Y, W, H); const int minimum_non_message_height = 100; if(special && mh < h() - minimum_non_message_height) @@ -3528,14 +3717,16 @@ class mainWindowSpecialResize : public mainWindow { } }; -class mainWindowProgress : public Fl_Progress{ +class mainWindowProgress : public Fl_Progress { public: - mainWindowProgress(int x, int y, int w, int h, const char *l=nullptr) : - Fl_Progress(x, y, w, h, l){} + mainWindowProgress(int x, int y, int w, int h, const char *l = nullptr) + : Fl_Progress(x, y, w, h, l) + { + } int handle(int event) { - if(event == FL_PUSH){ - if(FlGui::available()){ + if(event == FL_PUSH) { + if(FlGui::available()) { for(std::size_t i = 0; i < FlGui::instance()->graph.size(); i++) FlGui::instance()->graph[i]->showHideMessages(); } @@ -3559,7 +3750,7 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) int glheight = CTX::instance()->glSize[1] - mheight; int height = mh + glheight + mheight + sh; // make sure height < screen height - if(height > Fl::h()){ + if(height > Fl::h()) { height = Fl::h(); glheight = height - mh - mheight - sh; CTX::instance()->glSize[1] = glheight + mheight; @@ -3569,7 +3760,7 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) int glwidth = CTX::instance()->glSize[0] - twidth; int width = glwidth + twidth; // make sure width < screen width - if(width > Fl::w()){ + if(width > Fl::w()) { width = Fl::w(); glwidth = width - twidth; CTX::instance()->glSize[0] = glwidth + twidth; @@ -3577,11 +3768,11 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) // the graphic window should be a "normal" window (neither modal nor // non-modal) - if(main){ + if(main) { _win = new mainWindowSpecialResize(width, height, false); _win->callback(file_quit_cb); } - else{ + else { _win = new paletteWindow(width, height, false); _win->callback(remove_graphic_window_cb); } @@ -3590,15 +3781,15 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) _sysbar = nullptr; #endif _bar = nullptr; - if(main){ + if(main) { #if defined(__APPLE__) - if(CTX::instance()->systemMenuBar){ + if(CTX::instance()->systemMenuBar) { _sysbar = new Fl_Sys_Menu_Bar(1, 1, 1, 1); _sysbar->menu(sysbar_table); _sysbar->global(); fillRecentHistoryMenu(); } - else{ + else { #endif _bar = new Fl_Menu_Bar(0, 0, width, BH); _bar->menu(bar_table); @@ -3623,31 +3814,33 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) _tile = new Fl_Tile(0, mh, glwidth + twidth, glheight + mheight); int w2 = glwidth / 2, h2 = glheight / 2; - if(numTiles == 2){ + if(numTiles == 2) { gl.push_back(new openglWindow(twidth, mh, w2, glheight)); gl.back()->end(); gl.push_back(new openglWindow(twidth + w2, mh, glwidth - w2, glheight)); gl.back()->end(); } - else if(numTiles == 3){ + else if(numTiles == 3) { gl.push_back(new openglWindow(twidth, mh, w2, glheight)); gl.back()->end(); gl.push_back(new openglWindow(twidth + w2, mh, glwidth - w2, h2)); gl.back()->end(); - gl.push_back(new openglWindow(twidth + w2, mh + h2, glwidth - w2, glheight - h2)); + gl.push_back( + new openglWindow(twidth + w2, mh + h2, glwidth - w2, glheight - h2)); gl.back()->end(); } - else if(numTiles == 4){ + else if(numTiles == 4) { gl.push_back(new openglWindow(twidth, mh, w2, h2)); gl.back()->end(); gl.push_back(new openglWindow(twidth + w2, mh, glwidth - w2, h2)); gl.back()->end(); gl.push_back(new openglWindow(twidth, mh + h2, w2, glheight - h2)); gl.back()->end(); - gl.push_back(new openglWindow(twidth + w2, mh + h2, glwidth - w2, glheight - h2)); + gl.push_back( + new openglWindow(twidth + w2, mh + h2, glwidth - w2, glheight - h2)); gl.back()->end(); } - else{ + else { gl.push_back(new openglWindow(twidth, mh, glwidth, glheight)); gl.back()->end(); } @@ -3660,7 +3853,7 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) } for(std::size_t i = 0; i < gl.size(); i++) gl[i]->mode(mode); - if(main){ + if(main) { _browser = new messageBrowser(twidth, mh + glheight, glwidth, mheight); int s = CTX::instance()->msgFontSize; _browser->textsize(s <= 0 ? FL_NORMAL_SIZE - 2 : s); @@ -3670,15 +3863,15 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) _browser->save_callback(message_menu_save_cb, this); _browser->clear_callback(message_menu_clear_cb, this); } - else{ + else { _browser = nullptr; } - if(main && !detachedMenu){ + if(main && !detachedMenu) { _onelab = new onelabGroup(0, mh, twidth, height - mh - sh); _onelab->enableTreeWidgetResize(false); } - else{ + else { _onelab = nullptr; } @@ -3690,7 +3883,7 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) // if the tree widget is too small it will not be rebuilt correctly (probably // a bug)... so impose minimum width - int minw = 3 * BB/2 + 4 * WB; + int minw = 3 * BB / 2 + 4 * WB; if(CTX::instance()->menuSize[0] < minw) CTX::instance()->menuSize[0] = minw; _tile->position(twidth, 0, CTX::instance()->menuSize[0], 0); @@ -3701,14 +3894,15 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) int x = 2; int sht = sh - 4; // leave a 2 pixel border at the bottom - _butt[5] = new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "@-1gmsh_models"); + _butt[5] = + new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "@-1gmsh_models"); _butt[5]->callback(status_options_cb, (void *)"model"); _butt[5]->tooltip("Set current (active) model"); x += sw; _butt[8] = new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "O"); _butt[8]->callback(status_options_cb, (void *)"quick_access"); _butt[8]->tooltip("Open quick access menu (also available by double-clicking " - "in the graphic window)"); + "in the graphic window)"); x += sw; _butt[0] = new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "X"); _butt[0]->callback(status_xyz1p_cb, (void *)"x"); @@ -3722,14 +3916,17 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) _butt[2]->callback(status_xyz1p_cb, (void *)"z"); _butt[2]->tooltip("Set +Z or -Z (Shift) view (Alt+z or Alt+Shift+z)"); x += sw; - _butt[4] = new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "@-1gmsh_rotate"); + _butt[4] = + new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "@-1gmsh_rotate"); _butt[4]->callback(status_xyz1p_cb, (void *)"r"); - _butt[4]->tooltip("Rotate +90 or -90 (Shift) degrees, or sync rotations (Ctrl)"); + _butt[4]->tooltip( + "Rotate +90 or -90 (Shift) degrees, or sync rotations (Ctrl)"); x += sw; - _butt[3] = new Fl_Button(x, mh + glheight + mheight + 2, 2 * FL_NORMAL_SIZE, sht, "1:1"); + _butt[3] = new Fl_Button(x, mh + glheight + mheight + 2, 2 * FL_NORMAL_SIZE, + sht, "1:1"); _butt[3]->callback(status_xyz1p_cb, (void *)"1:1"); _butt[3]->tooltip("Set unit scale, sync scale between viewports (Ctrl), " - "or reset bounding box around visible entities (Shift) " + "or reset bounding box around visible entities (Shift) " "(Alt+1, Alt+Ctrl+1, Alt+Shift+1)"); x += 1.75 * FL_NORMAL_SIZE; _butt[9] = new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "S"); @@ -3737,22 +3934,26 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) _butt[9]->tooltip("Toggle mouse selection ON/OFF (Escape)"); x += sw; x += 4; - _butt[6] = new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "@-1gmsh_rewind"); + _butt[6] = + new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "@-1gmsh_rewind"); _butt[6]->callback(status_rewind_cb); _butt[6]->tooltip("Rewind animation"); _butt[6]->deactivate(); x += sw; - _butt[10] = new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "@-1gmsh_back"); + _butt[10] = + new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "@-1gmsh_back"); _butt[10]->callback(status_stepbackward_cb); _butt[10]->tooltip("Step backward (Left arrow)"); _butt[10]->deactivate(); x += sw; - _butt[7] = new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "@-1gmsh_play"); + _butt[7] = + new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "@-1gmsh_play"); _butt[7]->callback(status_play_cb); _butt[7]->tooltip("Play/pause animation"); _butt[7]->deactivate(); x += sw; - _butt[11] = new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "@-1gmsh_forward"); + _butt[11] = + new Fl_Button(x, mh + glheight + mheight + 2, sw, sht, "@-1gmsh_forward"); _butt[11]->callback(status_stepforward_cb); _butt[11]->tooltip("Step forward (Right arrow)"); _butt[11]->deactivate(); @@ -3765,7 +3966,8 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) } x += 4; - _label = new mainWindowProgress(x, mh + glheight + mheight + 2, width - x - 2, sht); + _label = + new mainWindowProgress(x, mh + glheight + mheight + 2, width - x - 2, sht); _label->box(FL_FLAT_BOX); _label->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP); if(CTX::instance()->guiColorScheme) @@ -3773,13 +3975,14 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) else _label->color(FL_BACKGROUND_COLOR, FL_DARK2); - _win->position(CTX::instance()->glPosition[0], CTX::instance()->glPosition[1]); + _win->position(CTX::instance()->glPosition[0], + CTX::instance()->glPosition[1]); _win->end(); - if(main && detachedMenu){ - _menuwin = new mainWindow - (CTX::instance()->menuSize[0], CTX::instance()->menuSize[1], - CTX::instance()->nonModalWindows ? true : false, "Gmsh"); + if(main && detachedMenu) { + _menuwin = + new mainWindow(CTX::instance()->menuSize[0], CTX::instance()->menuSize[1], + CTX::instance()->nonModalWindows ? true : false, "Gmsh"); _menuwin->callback(file_quit_cb); _menuwin->box(GMSH_WINDOW_BOX); _onelab = new onelabGroup(0, 0, _menuwin->w(), _menuwin->h()); @@ -3787,10 +3990,11 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) _menuwin->position(CTX::instance()->menuPosition[0], CTX::instance()->menuPosition[1]); _menuwin->resizable(_onelab); - _menuwin->size_range(_onelab->getMinWindowWidth(), _onelab->getMinWindowHeight()); + _menuwin->size_range(_onelab->getMinWindowWidth(), + _onelab->getMinWindowHeight()); _menuwin->end(); } - else{ + else { _menuwin = nullptr; } } @@ -3801,7 +4005,7 @@ graphicWindow::~graphicWindow() _tile->clear(); _win->clear(); Fl::delete_widget(_win); - if(_menuwin){ + if(_menuwin) { _menuwin->clear(); Fl::delete_widget(_menuwin); } @@ -3819,16 +4023,16 @@ void graphicWindow::detachMenu() int w = _onelab->w(); _tile->remove(_onelab); _browser->resize(0, _browser->y(), _browser->w() + w, _browser->h()); - for(std::size_t i = 0; i < gl.size(); i++){ - if(gl[i]->x() == w){ + for(std::size_t i = 0; i < gl.size(); i++) { + if(gl[i]->x() == w) { gl[i]->resize(0, gl[i]->y(), gl[i]->w() + w, gl[i]->h()); } } _tile->redraw(); - _menuwin = new mainWindow(_onelab->w(), CTX::instance()->menuSize[1], - CTX::instance()->nonModalWindows ? true : false, - "Gmsh"); + _menuwin = + new mainWindow(_onelab->w(), CTX::instance()->menuSize[1], + CTX::instance()->nonModalWindows ? true : false, "Gmsh"); _menuwin->callback(file_quit_cb); _menuwin->box(GMSH_WINDOW_BOX); _onelab->box(FL_FLAT_BOX); @@ -3837,7 +4041,8 @@ void graphicWindow::detachMenu() _menuwin->position(CTX::instance()->menuPosition[0], CTX::instance()->menuPosition[1]); _menuwin->resizable(_onelab); - _menuwin->size_range(_onelab->getMinWindowWidth(), _onelab->getMinWindowHeight()); + _menuwin->size_range(_onelab->getMinWindowWidth(), + _onelab->getMinWindowHeight()); _menuwin->end(); _menuwin->show(); @@ -3859,8 +4064,8 @@ void graphicWindow::attachMenu() int w = _onelab->w(); if(_browser->w() - w < 0) w = _browser->w() / 2; _browser->resize(w, _browser->y(), _browser->w() - w, _browser->h()); - for(std::size_t i = 0; i < gl.size(); i++){ - if(gl[i]->x() == 0){ + for(std::size_t i = 0; i < gl.size(); i++) { + if(gl[i]->x() == 0) { gl[i]->resize(w, gl[i]->y(), gl[i]->w() - w, gl[i]->h()); } } @@ -3875,14 +4080,16 @@ void graphicWindow::attachMenu() void graphicWindow::attachDetachMenu() { - if(_menuwin) attachMenu(); - else detachMenu(); + if(_menuwin) + attachMenu(); + else + detachMenu(); } void graphicWindow::showMenu() { if(_menuwin || !_onelab || !_win->shown()) return; - if(_onelab->w() < FL_NORMAL_SIZE){ + if(_onelab->w() < FL_NORMAL_SIZE) { int width = CTX::instance()->menuSize[0]; if(width < FL_NORMAL_SIZE) width = _onelab->getMinWindowWidth(); int maxw = _win->w(); @@ -3903,8 +4110,10 @@ void graphicWindow::hideMenu() void graphicWindow::showHideMenu() { if(_menuwin || !_onelab) return; - if(_onelab->w() < FL_NORMAL_SIZE) showMenu(); - else hideMenu(); + if(_onelab->w() < FL_NORMAL_SIZE) + showMenu(); + else + hideMenu(); } int graphicWindow::getMenuWidth() @@ -3935,21 +4144,20 @@ bool graphicWindow::split(openglWindow *g, char how, double ratio) { if(_tile->find(g) == _tile->children()) return false; // not found - if(how == 'u'){ + if(how == 'u') { // after many tries I cannot figure out how to do this cleanly, so let's be // brutal :-) int mode = g->mode(); openglWindow::setLastHandled(nullptr); - for(std::size_t i = 0; i < gl.size(); i++){ + for(std::size_t i = 0; i < gl.size(); i++) { _tile->remove(gl[i]); delete gl[i]; } gl.clear(); - openglWindow *g2 = new openglWindow - (_tile->x() + (_onelab && !_menuwin ? _onelab->w() : 0), - _tile->y(), - _tile->w() - (_onelab && !_menuwin ? _onelab->w() : 0), - _tile->h() - (_browser ? _browser->h() : 0)); + openglWindow *g2 = new openglWindow( + _tile->x() + (_onelab && !_menuwin ? _onelab->w() : 0), _tile->y(), + _tile->w() - (_onelab && !_menuwin ? _onelab->w() : 0), + _tile->h() - (_browser ? _browser->h() : 0)); g2->end(); g2->mode(mode); gl.push_back(g2); @@ -3957,7 +4165,7 @@ bool graphicWindow::split(openglWindow *g, char how, double ratio) g2->show(); openglWindow::setLastHandled(g2); } - else{ + else { double fact = (ratio <= 0.) ? 0.01 : (ratio >= 1.) ? 0.99 : ratio; // make sure browser is not zero-size when adding children if(_browser && _browser->h() == 0) setMessageHeight(1); @@ -3991,11 +4199,9 @@ bool graphicWindow::split(openglWindow *g, char how, double ratio) void graphicWindow::setStereo(bool st) { openglWindow::setLastHandled(nullptr); - for(std::size_t i = 0; i < gl.size(); i++){ - if (st) { - gl[i]->mode(FL_RGB | FL_DEPTH | FL_DOUBLE | FL_STEREO); - } - else{ + for(std::size_t i = 0; i < gl.size(); i++) { + if(st) { gl[i]->mode(FL_RGB | FL_DEPTH | FL_DOUBLE | FL_STEREO); } + else { gl[i]->mode(FL_RGB | FL_DEPTH | FL_DOUBLE); } gl[i]->show(); @@ -4018,24 +4224,22 @@ void graphicWindow::setAnimButtons(int mode) void graphicWindow::checkAnimButtons() { bool play = false; - if(CTX::instance()->post.animCycle){ - play = true; - } - else{ - for(std::size_t i = 0; i < PView::list.size(); i++){ - if(PView::list[i]->getData()->getNumTimeSteps() > 1){ + if(CTX::instance()->post.animCycle) { play = true; } + else { + for(std::size_t i = 0; i < PView::list.size(); i++) { + if(PView::list[i]->getData()->getNumTimeSteps() > 1) { play = true; break; } } } - if(play){ + if(play) { _butt[6]->activate(); _butt[7]->activate(); _butt[10]->activate(); _butt[11]->activate(); } - else{ + else { _butt[6]->deactivate(); _butt[7]->deactivate(); _butt[10]->deactivate(); @@ -4046,7 +4250,7 @@ void graphicWindow::checkAnimButtons() void graphicWindow::setMenuWidth(int w) { if(!_onelab) return; - if(_menuwin){ + if(_menuwin) { _menuwin->size(std::max(w, _onelab->getMinWindowWidth()), _menuwin->h()); _menuwin->redraw(); return; @@ -4054,12 +4258,13 @@ void graphicWindow::setMenuWidth(int w) if(!_browser) return; double dw = w - _onelab->w(); if(!dw) return; - for(std::size_t i = 0; i < gl.size(); i++){ - if(gl[i]->x() == _onelab->x() + _onelab->w()){ + for(std::size_t i = 0; i < gl.size(); i++) { + if(gl[i]->x() == _onelab->x() + _onelab->w()) { gl[i]->resize(gl[i]->x() + dw, gl[i]->y(), gl[i]->w() - dw, gl[i]->h()); } } - _browser->resize(_browser->x() + dw, _browser->y(), _browser->w() - dw, _browser->h()); + _browser->resize(_browser->x() + dw, _browser->y(), _browser->w() - dw, + _browser->h()); _onelab->resize(_onelab->x(), _onelab->y(), _onelab->w() + dw, _onelab->h()); _tile->redraw(); } @@ -4071,10 +4276,7 @@ int graphicWindow::getGlHeight() return h; } -int graphicWindow::getGlWidth() -{ - return _win->w(); -} +int graphicWindow::getGlWidth() { return _win->w(); } void graphicWindow::setGlWidth(int w) { @@ -4097,13 +4299,13 @@ void graphicWindow::setMessageHeight(int h) if(!_browser) return; int dh = h - _browser->h(); if(!dh) return; - for(std::size_t i = 0; i < gl.size(); i++){ - if(gl[i]->y() + gl[i]->h() == _browser->y()){ + for(std::size_t i = 0; i < gl.size(); i++) { + if(gl[i]->y() + gl[i]->h() == _browser->y()) { gl[i]->resize(gl[i]->x(), gl[i]->y(), gl[i]->w(), gl[i]->h() - dh); } } - _browser->resize(_browser->x(), _browser->y() - dh, - _browser->w(), _browser->h() + dh); + _browser->resize(_browser->x(), _browser->y() - dh, _browser->w(), + _browser->h() + dh); _tile->redraw(); } @@ -4111,15 +4313,14 @@ void graphicWindow::showMessages() { if(!_browser || !_win->shown()) return; Msg::ResetErrorCounter(); - if(_browser->h() < FL_NORMAL_SIZE){ + if(_browser->h() < FL_NORMAL_SIZE) { int height = CTX::instance()->msgSize; if(height < FL_NORMAL_SIZE) height = 10 * FL_NORMAL_SIZE; int maxh = _win->h() - _bottom->h(); if(height > maxh) height = maxh / 2; setMessageHeight(height); } - if(_autoScrollMessages) - _browser->bottomline(_browser->size()); + if(_autoScrollMessages) _browser->bottomline(_browser->size()); } void graphicWindow::hideMessages() @@ -4132,8 +4333,10 @@ void graphicWindow::hideMessages() void graphicWindow::showHideMessages() { if(!_browser) return; - if(_browser->h() < FL_NORMAL_SIZE) showMessages(); - else hideMessages(); + if(_browser->h() < FL_NORMAL_SIZE) + showMessages(); + else + hideMessages(); } int graphicWindow::getMessageHeight() @@ -4146,9 +4349,9 @@ void graphicWindow::addMessage(const char *msg) { if(!_browser) return; - // this routine can be called from multiple threads, e.g. via Msg::Info calls - // in meshGFace(). We should use FlGui::lock/unlock, but currently this does - // not seem to work (17/02/2017) + // this routine can be called from multiple threads, e.g. via Msg::Info + // calls in meshGFace(). We should use FlGui::lock/unlock, but currently + // this does not seem to work (17/02/2017) #if defined(_OPENMP) #pragma omp critical #endif @@ -4225,20 +4428,27 @@ void graphicWindow::changeMessageFontSize(int incr) static bool check_utf8(const std::string &string) { - for (int i = 0, ix = string.length(); i < ix; i++){ + for(int i = 0, ix = string.length(); i < ix; i++) { int n; - int c = (unsigned char) string[i]; - if (0x00 <= c && c <= 0x7f) n = 0; // 0bbbbbbb - else if ((c & 0xE0) == 0xC0) n = 1; // 110bbbbb - else if (c==0xed && i < (ix-1) && ((unsigned char)string[i+1] & 0xa0) == 0xa0) - return false; //U+d800 to U+dfff - else if ((c & 0xF0) == 0xE0) n = 2; // 1110bbbb - else if ((c & 0xF8) == 0xF0) n = 3; // 11110bbb - //else if (($c & 0xFC) == 0xF8) n=4; // 111110bb //byte 5, unnecessary in 4 byte UTF-8 - //else if (($c & 0xFE) == 0xFC) n=5; // 1111110b //byte 6, unnecessary in 4 byte UTF-8 - else return false; - for (int j = 0; j < n && i < ix; j++) { // n bytes matching 10bbbbbb follow ? - if ((++i == ix) || (((unsigned char)string[i] & 0xC0) != 0x80)) + int c = (unsigned char)string[i]; + if(0x00 <= c && c <= 0x7f) + n = 0; // 0bbbbbbb + else if((c & 0xE0) == 0xC0) + n = 1; // 110bbbbb + else if(c == 0xed && i < (ix - 1) && + ((unsigned char)string[i + 1] & 0xa0) == 0xa0) + return false; // U+d800 to U+dfff + else if((c & 0xF0) == 0xE0) + n = 2; // 1110bbbb + else if((c & 0xF8) == 0xF0) + n = 3; // 11110bbb + // else if (($c & 0xFC) == 0xF8) n=4; // 111110bb //byte 5, unnecessary in 4 + // byte UTF-8 else if (($c & 0xFE) == 0xFC) n=5; // 1111110b //byte 6, + // unnecessary in 4 byte UTF-8 + else + return false; + for(int j = 0; j < n && i < ix; j++) { // n bytes matching 10bbbbbb follow ? + if((++i == ix) || (((unsigned char)string[i] & 0xC0) != 0x80)) return false; } } @@ -4248,22 +4458,20 @@ static bool check_utf8(const std::string &string) void graphicWindow::fillRecentHistoryMenu() { #if defined(__APPLE__) - if(CTX::instance()->systemMenuBar && !_sysbar) - return; + if(CTX::instance()->systemMenuBar && !_sysbar) return; #endif Fl_Menu_Item *table = bar_table; #if defined(__APPLE__) - if(CTX::instance()->systemMenuBar) - table = sysbar_table; + if(CTX::instance()->systemMenuBar) table = sysbar_table; #endif static char recent[10][256]; - for(int i = 0; i < 10; i++){ - if(i < (int)CTX::instance()->recentFiles.size()){ + for(int i = 0; i < 10; i++) { + if(i < (int)CTX::instance()->recentFiles.size()) { if(check_utf8(CTX::instance()->recentFiles[i])) - strcpy(recent[i], CTX::instance()->recentFiles[i].c_str()); - else{ + strcpy(recent[i], CTX::instance()->recentFiles[i].c_str()); + else { Msg::Info("Ignoring invalid General.RecentFile%d", i); strcpy(recent[i], ""); } @@ -4271,16 +4479,15 @@ void graphicWindow::fillRecentHistoryMenu() else strcpy(recent[i], ""); table[4 + i].text = recent[i]; - table[4 + i].user_data_ = (void*)recent[i]; + table[4 + i].user_data_ = (void *)recent[i]; } #if defined(__APPLE__) - if(CTX::instance()->systemMenuBar) - _sysbar->menu(table); + if(CTX::instance()->systemMenuBar) _sysbar->menu(table); #endif } -typedef struct{ +typedef struct { std::string label; Fl_Callback *callback; void *arg; @@ -4288,185 +4495,165 @@ typedef struct{ static menuItem static_modules[] = { {"0Modules/Geometry/Elementary entities/Set geometry kernel/Built-in", - (Fl_Callback *)geometry_elementary_set_factory_cb, (void*)"Built-in"} , + (Fl_Callback *)geometry_elementary_set_factory_cb, (void *)"Built-in"}, {"0Modules/Geometry/Elementary entities/Set geometry kernel/OpenCASCADE", - (Fl_Callback *)geometry_elementary_set_factory_cb, (void*)"OpenCASCADE"} , + (Fl_Callback *)geometry_elementary_set_factory_cb, (void *)"OpenCASCADE"}, {"0Modules/Geometry/Elementary entities/Add/Parameter", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Parameter"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Parameter"}, {"0Modules/Geometry/Elementary entities/Add/Point", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Point"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Point"}, {"0Modules/Geometry/Elementary entities/Add/Line", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Line"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Line"}, {"0Modules/Geometry/Elementary entities/Add/Spline", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Spline"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Spline"}, {"0Modules/Geometry/Elementary entities/Add/Bezier", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Bezier"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Bezier"}, {"0Modules/Geometry/Elementary entities/Add/B-Spline", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"BSpline"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"BSpline"}, {"0Modules/Geometry/Elementary entities/Add/Circle", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Circle"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Circle"}, {"0Modules/Geometry/Elementary entities/Add/Circle arc", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Circle arc"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Circle arc"}, {"0Modules/Geometry/Elementary entities/Add/Ellipse", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Ellipse"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Ellipse"}, {"0Modules/Geometry/Elementary entities/Add/Ellipse arc", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Ellipse arc"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Ellipse arc"}, {"0Modules/Geometry/Elementary entities/Add/Rectangle", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Rectangle"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Rectangle"}, {"0Modules/Geometry/Elementary entities/Add/Disk", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Disk"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Disk"}, {"0Modules/Geometry/Elementary entities/Add/Plane surface", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Plane Surface"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Plane Surface"}, {"0Modules/Geometry/Elementary entities/Add/Surface filling", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Surface"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Surface"}, {"0Modules/Geometry/Elementary entities/Add/Sphere", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Sphere"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Sphere"}, {"0Modules/Geometry/Elementary entities/Add/Cylinder", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Cylinder"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Cylinder"}, {"0Modules/Geometry/Elementary entities/Add/Box", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Box"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Box"}, {"0Modules/Geometry/Elementary entities/Add/Torus", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Torus"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Torus"}, {"0Modules/Geometry/Elementary entities/Add/Cone", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Cone"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Cone"}, {"0Modules/Geometry/Elementary entities/Add/Wedge", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Wedge"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Wedge"}, {"0Modules/Geometry/Elementary entities/Add/Volume", - (Fl_Callback *)geometry_elementary_add_new_cb, (void*)"Volume"} , + (Fl_Callback *)geometry_elementary_add_new_cb, (void *)"Volume"}, {"0Modules/Geometry/Elementary entities/Transform/Translate", - (Fl_Callback *)geometry_elementary_translate_cb} , + (Fl_Callback *)geometry_elementary_translate_cb}, {"0Modules/Geometry/Elementary entities/Transform/Rotate", - (Fl_Callback *)geometry_elementary_rotate_cb} , + (Fl_Callback *)geometry_elementary_rotate_cb}, {"0Modules/Geometry/Elementary entities/Transform/Scale", - (Fl_Callback *)geometry_elementary_scale_cb} , + (Fl_Callback *)geometry_elementary_scale_cb}, {"0Modules/Geometry/Elementary entities/Transform/Symmetry", - (Fl_Callback *)geometry_elementary_symmetry_cb} , + (Fl_Callback *)geometry_elementary_symmetry_cb}, {"0Modules/Geometry/Elementary entities/Extrude/Translate", - (Fl_Callback *)geometry_elementary_extrude_translate_cb} , + (Fl_Callback *)geometry_elementary_extrude_translate_cb}, {"0Modules/Geometry/Elementary entities/Extrude/Rotate", - (Fl_Callback *)geometry_elementary_extrude_rotate_cb} , + (Fl_Callback *)geometry_elementary_extrude_rotate_cb}, {"0Modules/Geometry/Elementary entities/Extrude/Pipe", - (Fl_Callback *)geometry_elementary_pipe_cb} , + (Fl_Callback *)geometry_elementary_pipe_cb}, {"0Modules/Geometry/Elementary entities/Boolean/Intersection", - (Fl_Callback *)geometry_elementary_boolean_cb, (void*)"BooleanIntersection"} , + (Fl_Callback *)geometry_elementary_boolean_cb, + (void *)"BooleanIntersection"}, {"0Modules/Geometry/Elementary entities/Boolean/Union", - (Fl_Callback *)geometry_elementary_boolean_cb, (void*)"BooleanUnion"} , + (Fl_Callback *)geometry_elementary_boolean_cb, (void *)"BooleanUnion"}, {"0Modules/Geometry/Elementary entities/Boolean/Difference", - (Fl_Callback *)geometry_elementary_boolean_cb, (void*)"BooleanDifference"} , + (Fl_Callback *)geometry_elementary_boolean_cb, (void *)"BooleanDifference"}, {"0Modules/Geometry/Elementary entities/Boolean/Fragments", - (Fl_Callback *)geometry_elementary_boolean_cb, (void*)"BooleanFragments"} , + (Fl_Callback *)geometry_elementary_boolean_cb, (void *)"BooleanFragments"}, {"0Modules/Geometry/Elementary entities/Fillet", (Fl_Callback *)geometry_elementary_fillet_cb}, {"0Modules/Geometry/Elementary entities/Split curve", - (Fl_Callback *)geometry_elementary_split_cb, (void*)"Curve"}, + (Fl_Callback *)geometry_elementary_split_cb, (void *)"Curve"}, {"0Modules/Geometry/Elementary entities/Delete", - (Fl_Callback *)geometry_elementary_delete_cb} , + (Fl_Callback *)geometry_elementary_delete_cb}, {"0Modules/Geometry/Elementary entities/Coherence", - (Fl_Callback *)geometry_elementary_coherence_cb} , + (Fl_Callback *)geometry_elementary_coherence_cb}, {"0Modules/Geometry/Physical groups/Add/Point", - (Fl_Callback *)geometry_physical_add_cb, (void*)"Point" } , + (Fl_Callback *)geometry_physical_add_cb, (void *)"Point"}, {"0Modules/Geometry/Physical groups/Add/Curve", - (Fl_Callback *)geometry_physical_add_cb, (void*)"Curve" } , + (Fl_Callback *)geometry_physical_add_cb, (void *)"Curve"}, {"0Modules/Geometry/Physical groups/Add/Surface", - (Fl_Callback *)geometry_physical_add_cb, (void*)"Surface" } , + (Fl_Callback *)geometry_physical_add_cb, (void *)"Surface"}, {"0Modules/Geometry/Physical groups/Add/Volume", - (Fl_Callback *)geometry_physical_add_cb, (void*)"Volume" } , + (Fl_Callback *)geometry_physical_add_cb, (void *)"Volume"}, {"0Modules/Geometry/Physical groups/Remove/Point", - (Fl_Callback *)geometry_physical_remove_cb, (void*)"Point" } , + (Fl_Callback *)geometry_physical_remove_cb, (void *)"Point"}, {"0Modules/Geometry/Physical groups/Remove/Curve", - (Fl_Callback *)geometry_physical_remove_cb, (void*)"Curve" } , + (Fl_Callback *)geometry_physical_remove_cb, (void *)"Curve"}, {"0Modules/Geometry/Physical groups/Remove/Surface", - (Fl_Callback *)geometry_physical_remove_cb, (void*)"Surface" } , + (Fl_Callback *)geometry_physical_remove_cb, (void *)"Surface"}, {"0Modules/Geometry/Physical groups/Remove/Volume", - (Fl_Callback *)geometry_physical_remove_cb, (void*)"Volume" } , - {"0Modules/Geometry/Reload script", - (Fl_Callback *)geometry_reload_cb} , + (Fl_Callback *)geometry_physical_remove_cb, (void *)"Volume"}, + {"0Modules/Geometry/Reload script", (Fl_Callback *)geometry_reload_cb}, {"0Modules/Geometry/Remove last script command", - (Fl_Callback *)geometry_remove_last_command_cb} , - {"0Modules/Geometry/Edit script", - (Fl_Callback *)geometry_edit_cb} , - {"0Modules/Mesh/Define/Size at points", - (Fl_Callback *)mesh_define_length_cb } , - {"0Modules/Mesh/Define/Size fields", - (Fl_Callback *)field_cb}, + (Fl_Callback *)geometry_remove_last_command_cb}, + {"0Modules/Geometry/Edit script", (Fl_Callback *)geometry_edit_cb}, + {"0Modules/Mesh/Define/Size at points", (Fl_Callback *)mesh_define_length_cb}, + {"0Modules/Mesh/Define/Size fields", (Fl_Callback *)field_cb}, {"0Modules/Mesh/Define/Embedded/Point", - (Fl_Callback *)mesh_define_embedded_cb, (void*)"Point" } , + (Fl_Callback *)mesh_define_embedded_cb, (void *)"Point"}, {"0Modules/Mesh/Define/Embedded/Curve", - (Fl_Callback *)mesh_define_embedded_cb, (void*)"Curve" } , + (Fl_Callback *)mesh_define_embedded_cb, (void *)"Curve"}, {"0Modules/Mesh/Define/Embedded/Surface", - (Fl_Callback *)mesh_define_embedded_cb, (void*)"Surface" } , + (Fl_Callback *)mesh_define_embedded_cb, (void *)"Surface"}, {"0Modules/Mesh/Define/Transfinite/Curve", - (Fl_Callback *)mesh_define_transfinite_line_cb} , + (Fl_Callback *)mesh_define_transfinite_line_cb}, {"0Modules/Mesh/Define/Transfinite/Surface", - (Fl_Callback *)mesh_define_transfinite_surface_cb} , + (Fl_Callback *)mesh_define_transfinite_surface_cb}, {"0Modules/Mesh/Define/Transfinite/Volume", - (Fl_Callback *)mesh_define_transfinite_volume_cb} , + (Fl_Callback *)mesh_define_transfinite_volume_cb}, {"0Modules/Mesh/Define/Compound/Curve", - (Fl_Callback *)mesh_define_compound_entity_cb, (void*)"Curve"} , + (Fl_Callback *)mesh_define_compound_entity_cb, (void *)"Curve"}, {"0Modules/Mesh/Define/Compound/Surface", - (Fl_Callback *)mesh_define_compound_entity_cb, (void*)"Surface"} , - {"0Modules/Mesh/Define/Recombine", - (Fl_Callback *)mesh_define_recombine_cb } , - {"0Modules/Mesh/1D", - (Fl_Callback *)mesh_1d_cb} , - {"0Modules/Mesh/2D", - (Fl_Callback *)mesh_2d_cb} , - {"0Modules/Mesh/3D", - (Fl_Callback *)mesh_3d_cb} , - {"0Modules/Mesh/Optimize 3D", - (Fl_Callback *)mesh_optimize_cb} , + (Fl_Callback *)mesh_define_compound_entity_cb, (void *)"Surface"}, + {"0Modules/Mesh/Define/Recombine", (Fl_Callback *)mesh_define_recombine_cb}, + {"0Modules/Mesh/1D", (Fl_Callback *)mesh_1d_cb}, + {"0Modules/Mesh/2D", (Fl_Callback *)mesh_2d_cb}, + {"0Modules/Mesh/3D", (Fl_Callback *)mesh_3d_cb}, + {"0Modules/Mesh/Optimize 3D", (Fl_Callback *)mesh_optimize_cb}, #if defined(HAVE_NETGEN) {"0Modules/Mesh/Optimize 3D (Netgen)", - (Fl_Callback *)mesh_optimize_netgen_cb} , + (Fl_Callback *)mesh_optimize_netgen_cb}, #endif - {"0Modules/Mesh/Set order 1", - (Fl_Callback *)mesh_degree_cb, (void*)1}, - {"0Modules/Mesh/Set order 2", - (Fl_Callback *)mesh_degree_cb, (void*)2}, - {"0Modules/Mesh/Set order 3", - (Fl_Callback *)mesh_degree_cb, (void*)3}, - {"0Modules/Mesh/High-order tools", - (Fl_Callback *)highordertools_cb}, - {"0Modules/Mesh/Refine by splitting", - (Fl_Callback *)mesh_refine_cb} , + {"0Modules/Mesh/Set order 1", (Fl_Callback *)mesh_degree_cb, (void *)1}, + {"0Modules/Mesh/Set order 2", (Fl_Callback *)mesh_degree_cb, (void *)2}, + {"0Modules/Mesh/Set order 3", (Fl_Callback *)mesh_degree_cb, (void *)3}, + {"0Modules/Mesh/High-order tools", (Fl_Callback *)highordertools_cb}, + {"0Modules/Mesh/Refine by splitting", (Fl_Callback *)mesh_refine_cb}, #if defined(HAVE_METIS) - {"0Modules/Mesh/Partition", - (Fl_Callback *)mesh_partition_cb} , - {"0Modules/Mesh/Unpartition", - (Fl_Callback *)mesh_unpartition_cb} , + {"0Modules/Mesh/Partition", (Fl_Callback *)mesh_partition_cb}, + {"0Modules/Mesh/Unpartition", (Fl_Callback *)mesh_unpartition_cb}, #endif - {"0Modules/Mesh/Smooth 2D", - (Fl_Callback *)mesh_smooth_cb} , - {"0Modules/Mesh/Recombine 2D", - (Fl_Callback *)mesh_recombine_cb} , - {"0Modules/Mesh/Reclassify 2D", - (Fl_Callback *)mesh_classify_cb} , + {"0Modules/Mesh/Smooth 2D", (Fl_Callback *)mesh_smooth_cb}, + {"0Modules/Mesh/Recombine 2D", (Fl_Callback *)mesh_recombine_cb}, + {"0Modules/Mesh/Reclassify 2D", (Fl_Callback *)mesh_classify_cb}, {"0Modules/Mesh/Experimental/Compute quad layout", - (Fl_Callback *)mesh_cross_compute_cb} , + (Fl_Callback *)mesh_cross_compute_cb}, #if defined(HAVE_METIS) {"0Modules/Mesh/Experimental/Convert old partitioning", - (Fl_Callback *)mesh_convert_old_partitioning_cb} , + (Fl_Callback *)mesh_convert_old_partitioning_cb}, #endif - {"0Modules/Mesh/Reverse/Elements", - (Fl_Callback *)mesh_reverse_parts_cb, (void*)"elements"} , - {"0Modules/Mesh/Reverse/Curves", - (Fl_Callback *)mesh_reverse_parts_cb, (void*)"curves"} , - {"0Modules/Mesh/Reverse/Surfaces", - (Fl_Callback *)mesh_reverse_parts_cb, (void*)"surfaces"} , - {"0Modules/Mesh/Reverse/Volumes", - (Fl_Callback *)mesh_reverse_parts_cb, (void*)"volumes"} , - {"0Modules/Mesh/Delete/Elements", - (Fl_Callback *)mesh_delete_parts_cb, (void*)"elements"} , - {"0Modules/Mesh/Delete/Curves", - (Fl_Callback *)mesh_delete_parts_cb, (void*)"curves"} , - {"0Modules/Mesh/Delete/Surfaces", - (Fl_Callback *)mesh_delete_parts_cb, (void*)"surfaces"} , - {"0Modules/Mesh/Delete/Volumes", - (Fl_Callback *)mesh_delete_parts_cb, (void*)"volumes"} , - {"0Modules/Mesh/Inspect", - (Fl_Callback *)mesh_inspect_cb} , - {"0Modules/Mesh/Save", - (Fl_Callback *)mesh_save_cb} , + {"0Modules/Mesh/Reverse/Elements", (Fl_Callback *)mesh_reverse_parts_cb, + (void *)"elements"}, + {"0Modules/Mesh/Reverse/Curves", (Fl_Callback *)mesh_reverse_parts_cb, + (void *)"curves"}, + {"0Modules/Mesh/Reverse/Surfaces", (Fl_Callback *)mesh_reverse_parts_cb, + (void *)"surfaces"}, + {"0Modules/Mesh/Reverse/Volumes", (Fl_Callback *)mesh_reverse_parts_cb, + (void *)"volumes"}, + {"0Modules/Mesh/Delete/Elements", (Fl_Callback *)mesh_delete_parts_cb, + (void *)"elements"}, + {"0Modules/Mesh/Delete/Curves", (Fl_Callback *)mesh_delete_parts_cb, + (void *)"curves"}, + {"0Modules/Mesh/Delete/Surfaces", (Fl_Callback *)mesh_delete_parts_cb, + (void *)"surfaces"}, + {"0Modules/Mesh/Delete/Volumes", (Fl_Callback *)mesh_delete_parts_cb, + (void *)"volumes"}, + {"0Modules/Mesh/Inspect", (Fl_Callback *)mesh_inspect_cb}, + {"0Modules/Mesh/Save", (Fl_Callback *)mesh_save_cb}, }; void onelabGroup::_addGmshMenus() @@ -4474,11 +4661,13 @@ void onelabGroup::_addGmshMenus() _tree->sortorder(FL_TREE_SORT_NONE); // add static geometry and mesh module items - for(std::size_t i = 0; i < sizeof(static_modules) / sizeof(static_modules[0]); i++) - _addMenu(static_modules[i].label, static_modules[i].callback, static_modules[i].arg); + for(std::size_t i = 0; i < sizeof(static_modules) / sizeof(static_modules[0]); + i++) + _addMenu(static_modules[i].label, static_modules[i].callback, + static_modules[i].arg); // add dynamic solver module items - for(int i = 0; i < 5; i++){ + for(int i = 0; i < 5; i++) { std::string name = opt_solver_name(i, GMSH_GET, ""); if(name.size()) _addSolverMenu(i); } @@ -4488,12 +4677,11 @@ void onelabGroup::_addGmshMenus() _tree->sortorder(FL_TREE_SORT_ASCENDING); - if(_firstBuild){ + if(_firstBuild) { _firstBuild = false; Fl_Tree_Item *n0 = _tree->find_item("0Modules"); - for(Fl_Tree_Item *n = n0; n; n = n->next()){ - if(!n->is_root() && n->has_children() && n->depth() > 1) - n->close(); + for(Fl_Tree_Item *n = n0; n; n = n->next()) { + if(!n->is_root() && n->has_children() && n->depth() > 1) n->close(); } } } @@ -4502,8 +4690,8 @@ std::set<std::string> onelabGroup::_getClosedGmshMenus() { std::set<std::string> closed; Fl_Tree_Item *n0 = _tree->find_item("0Modules"); - for(Fl_Tree_Item *n = n0; n; n = n->next()){ - if(!n->is_root() && n->has_children() && n->is_close()){ + for(Fl_Tree_Item *n = n0; n; n = n->next()) { + if(!n->is_root() && n->has_children() && n->is_close()) { char path[1024]; _tree->item_pathname(path, sizeof(path), n); closed.insert(path); diff --git a/Fltk/helpWindow.cpp b/Fltk/helpWindow.cpp index 840cea213ccafb9558c644a0cff4dbef2829b1a3..911ba489a4fc6aa1c97a78d738da7a9b6ee74e0a 100644 --- a/Fltk/helpWindow.cpp +++ b/Fltk/helpWindow.cpp @@ -285,12 +285,12 @@ void help_options_cb(Fl_Widget *w, void *data) FlGui::instance()->help->browser->add(s0[i].c_str(), d); } else { - try{ + try { // icase for case-insensitive search - if(std::regex_search(s0[i], std::regex(search, std::regex_constants::icase))) + if(std::regex_search(s0[i], + std::regex(search, std::regex_constants::icase))) FlGui::instance()->help->browser->add(s0[i].c_str(), d); - } - catch(...) { + } catch(...) { } } } diff --git a/Fltk/highOrderToolsWindow.cpp b/Fltk/highOrderToolsWindow.cpp index 64c12f2230a5be9f488f9ffc61ade34d2fd51a63..ec52185b6a3e5f396469e5e8a6680a06c396e959 100644 --- a/Fltk/highOrderToolsWindow.cpp +++ b/Fltk/highOrderToolsWindow.cpp @@ -248,7 +248,7 @@ static void getMeshInfoForHighOrder(GModel *gm, int &meshOrder, bool &complete, for(auto itr = gm->firstRegion(); itr != gm->lastRegion(); ++itr) { if((*itr)->getNumMeshElements()) { meshOrder = (*itr)->getMeshElement(0)->getPolynomialOrder(); - //complete = (meshOrder <= 2) ? true : + // complete = (meshOrder <= 2) ? true : // (*itr)->getMeshElement(0)->getNumVolumeVertices() ? true : false; if((*itr)->isFullyDiscrete()) CAD = false; break; @@ -432,10 +432,11 @@ highOrderToolsWindow::highOrderToolsWindow(int deltaFontSize) value[4]->align(FL_ALIGN_RIGHT); value[4]->value(CTX::instance()->mesh.hoPassMax); - static Fl_Menu_Item menu_strategy[] = {{"Disjoint strong", 0, nullptr, nullptr}, - {"Adaptive one-by-one", 0, nullptr, nullptr}, - {"Disjoint weak", 0, nullptr, nullptr}, - {nullptr}}; + static Fl_Menu_Item menu_strategy[] = { + {"Disjoint strong", 0, nullptr, nullptr}, + {"Adaptive one-by-one", 0, nullptr, nullptr}, + {"Disjoint weak", 0, nullptr, nullptr}, + {nullptr}}; y += BH; choice[3] = new Fl_Choice(x, y, IW, BH, "Strategy"); diff --git a/Fltk/inputValue.h b/Fltk/inputValue.h index defddef86ede76d760bb84bd056fa6915fb71d62..9b76573b87c004a42b9fa8fab5070198072abebf 100644 --- a/Fltk/inputValue.h +++ b/Fltk/inputValue.h @@ -15,6 +15,7 @@ class inputValue : public Fl_Value_Input { private: std::string _number_format; + public: inputValue(int x, int y, int w, int h, const char *l = nullptr) : Fl_Value_Input(x, y, w, h, l) @@ -23,9 +24,7 @@ public: void numberFormat(const std::string &fmt) { _number_format = fmt; } virtual int format(char *buffer) { - if(_number_format.empty()) { - return sprintf(buffer, "%g", value()); - } + if(_number_format.empty()) { return sprintf(buffer, "%g", value()); } else { if(_number_format.find("d") != std::string::npos || _number_format.find("u") != std::string::npos) diff --git a/Fltk/messageBrowser.h b/Fltk/messageBrowser.h index 17eb3e723b17afb471000b6376cb74b822cdb18c..c5c21203b66da2edda5c314a784347ef6b456577 100644 --- a/Fltk/messageBrowser.h +++ b/Fltk/messageBrowser.h @@ -89,17 +89,15 @@ public: void add(const char *newtext) { std::string search = _search->value(); - if(search.empty()) { - _browser->add(newtext); - } + if(search.empty()) { _browser->add(newtext); } else { std::string tmp(newtext); - try{ + try { // icase for case-insensitive search - if(std::regex_search(tmp, std::regex(search, std::regex_constants::icase))) + if(std::regex_search(tmp, + std::regex(search, std::regex_constants::icase))) _browser->add(newtext); - } - catch(...) { + } catch(...) { } } } diff --git a/Fltk/onelabContextWindow.cpp b/Fltk/onelabContextWindow.cpp index 4322b8972b522cae460d9395112adb0befabb0b0..46249f58838bb526c5b2863d91cab2eb85f0f970 100644 --- a/Fltk/onelabContextWindow.cpp +++ b/Fltk/onelabContextWindow.cpp @@ -38,18 +38,17 @@ static std::string getDimName(int dim) template <typename T> void onelabContextWindow::_addOnelabWidget( T &p, const std::string &pattern, - std::set<std::pair<std::string, Fl_Widget *>> &widgets) + std::set<std::pair<std::string, Fl_Widget *> > &widgets) { - if(p.getName().find(pattern) == std::string::npos) - return; + if(p.getName().find(pattern) == std::string::npos) return; // does the parameter exist? std::string in = getDimName(_dim) + " Template"; std::string out; - if(_choice->value() == 0) // elementary + if(_choice->value() == 0) // elementary out = getDimName(_dim) + " " + std::to_string(_tag); else // physical out = "Physical " + getDimName(_dim) + " " + - std::to_string(_physicalGroups[_choice->value() - 1].first); + std::to_string(_physicalGroups[_choice->value() - 1].first); std::string name = ReplaceSubString(in, out, p.getName()); std::vector<T> pn; onelab::server::instance()->get(pn, name); @@ -58,9 +57,7 @@ void onelabContextWindow::_addOnelabWidget( n = p; n.setName(name); auto attr = n.getAttributes(); - for(auto &a : attr) { - ReplaceSubStringInPlace(in, out, a.second); - } + for(auto &a : attr) { ReplaceSubStringInPlace(in, out, a.second); } n.setAttributes(attr); onelab::server::instance()->set(n); } @@ -71,9 +68,8 @@ void onelabContextWindow::_addOnelabWidget( bool highlight = false; Fl_Color c; if(getParameterColor(n.getAttribute("Highlight"), c)) highlight = true; - Fl_Widget *w = - addParameterWidget(n, WB, 1, _width / 2, BH, 1., n.getName(), highlight, - c, win->color(), _toFree); + Fl_Widget *w = addParameterWidget(n, WB, 1, _width / 2, BH, 1., n.getName(), + highlight, c, win->color(), _toFree); w->copy_label(n.getShortName().c_str()); std::string help = n.getHelp(); if(help.empty()) help = n.getLabel(); @@ -112,10 +108,7 @@ onelabContextWindow::onelabContextWindow(int deltaFontSize) FL_NORMAL_SIZE += deltaFontSize; } -onelabContextWindow::~onelabContextWindow() -{ - Fl::delete_widget(win); -} +onelabContextWindow::~onelabContextWindow() { Fl::delete_widget(win); } void onelabContextWindow::show(int dim, int tag) { @@ -132,8 +125,8 @@ void onelabContextWindow::show(int dim, int tag) GModel::current()->getPhysicalGroups(_dim, groups); for(auto &p : _entity->physicals) { int n = std::abs(p); // can be < 0 to switch orientation - _physicalGroups.push_back - (std::make_pair(n, GModel::current()->getPhysicalName(dim, n))); + _physicalGroups.push_back( + std::make_pair(n, GModel::current()->getPhysicalName(dim, n))); _physicalGroupEntities.push_back(groups[n]); } } @@ -145,8 +138,7 @@ void onelabContextWindow::show(int dim, int tag) for(std::size_t i = 0; i < toFree.size(); i++) free(toFree[i]); toFree.clear(); { - std::string label = getDimName(_dim) + " " + - std::to_string(_tag); + std::string label = getDimName(_dim) + " " + std::to_string(_tag); if(_name.size()) label += ": " + _name; char *str = strdup(label.c_str()); Fl_Menu_Item item = {str, 0, nullptr, nullptr, 0}; @@ -154,8 +146,8 @@ void onelabContextWindow::show(int dim, int tag) menu.push_back(item); } for(auto &p : _physicalGroups) { - std::string label = "Physical " + getDimName(_dim) + " " + - std::to_string(p.first); + std::string label = + "Physical " + getDimName(_dim) + " " + std::to_string(p.first); if(p.second.size()) label += ": " + p.second; char *str = strdup(label.c_str()); Fl_Menu_Item item = {str, 0, nullptr, nullptr, 0}; @@ -166,8 +158,7 @@ void onelabContextWindow::show(int dim, int tag) menu.push_back(item); _choice->copy(&menu[0]); - if(menu.size() > 1) - _choice->value(menu.size() - 2); // last physical + if(menu.size() > 1) _choice->value(menu.size() - 2); // last physical rebuild(true); highlightSelection(); @@ -176,10 +167,7 @@ void onelabContextWindow::show(int dim, int tag) win->enableRedraw(); } -void onelabContextWindow::hide() -{ - win->hide(); -} +void onelabContextWindow::hide() { win->hide(); } void onelabContextWindow::rebuild(bool deleteWidgets) { @@ -209,7 +197,7 @@ void onelabContextWindow::rebuild(bool deleteWidgets) // if the corresponding parameter exists; if not, create it and add it to the // server; then create the widget std::string pat = "ONELAB Context/" + getDimName(_dim) + " Template/"; - std::set<std::pair<std::string, Fl_Widget *>> widgets; + std::set<std::pair<std::string, Fl_Widget *> > widgets; for(auto &p : pn) _addOnelabWidget(p, pat, widgets); for(auto &p : ps) _addOnelabWidget(p, pat, widgets); int h = _height; @@ -230,10 +218,8 @@ void onelabContextWindow::rebuild(bool deleteWidgets) // resize the window and restore the focus win->resize(win->x(), win->y(), win->w(), h); - for(auto w: _onelabWidgets) { - if(focus == std::string(w->label())) { - w->take_focus(); - } + for(auto w : _onelabWidgets) { + if(focus == std::string(w->label())) { w->take_focus(); } } // we should add a "Check" button if Solver.AutoCheck is not set (as in the @@ -243,7 +229,7 @@ void onelabContextWindow::rebuild(bool deleteWidgets) void onelabContextWindow::highlightSelection() { GModel::current()->setSelection(0); - if(_choice->value() == 0) { // elementary + if(_choice->value() == 0) { // elementary if(_entity) { _entity->setVisibility(1); _entity->setSelection(2); @@ -260,7 +246,4 @@ void onelabContextWindow::highlightSelection() drawContext::global()->draw(); } -void onelabContextWindow::disableRedraw() -{ - win->disableRedraw(); -} +void onelabContextWindow::disableRedraw() { win->disableRedraw(); } diff --git a/Fltk/onelabContextWindow.h b/Fltk/onelabContextWindow.h index 50aa2f58af1c66931cdd8e7454a39c30cbcac8e2..d26a2004b8fe76af48ae3adaf34c8895dc0686ff 100644 --- a/Fltk/onelabContextWindow.h +++ b/Fltk/onelabContextWindow.h @@ -19,9 +19,12 @@ class GEntity; class contextWindow : public paletteWindow { private: bool _redraw; + public: contextWindow(int w, int h, bool nonModal, const char *l = nullptr) - : paletteWindow(w, h, nonModal, l), _redraw(false) { } + : paletteWindow(w, h, nonModal, l), _redraw(false) + { + } virtual int handle(int event); void enableRedraw() { _redraw = true; } void disableRedraw() { _redraw = false; } @@ -33,8 +36,9 @@ private: std::vector<char *> _toFree; std::vector<Fl_Widget *> _onelabWidgets; template <class T> - void _addOnelabWidget(T &p, const std::string &pattern, - std::set<std::pair<std::string, Fl_Widget *>> &widgets); + void + _addOnelabWidget(T &p, const std::string &pattern, + std::set<std::pair<std::string, Fl_Widget *> > &widgets); Fl_Choice *_choice; int _dim, _tag; GEntity *_entity; diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp index e9a2ac1f8afbe47996952078cc6a09d7c959b2d3..1ace74689dc531c7438c208596ef2dc1b94f13dc 100644 --- a/Fltk/onelabGroup.cpp +++ b/Fltk/onelabGroup.cpp @@ -215,10 +215,11 @@ void onelab_cb(Fl_Widget *w, void *data) it != onelab::server::instance()->lastClient(); it++) { onelab::client *c = *it; if(c->getName() == "Gmsh" || // local Gmsh client - c->getName() == "Listen" || // unknown client connecting through "-listen" + c->getName() == + "Listen" || // unknown client connecting through "-listen" c->getName() == "GmshRemote" || // distant post-processing Gmsh client c->getName().find("NoAutoRun") != - std::string::npos) // client name contains "NoAutoRun" + std::string::npos) // client name contains "NoAutoRun" continue; if(action != "initialize") onelabUtils::guessModelName(c); onelab::string o(c->getName() + "/Action", action); @@ -358,9 +359,7 @@ static void onelab_add_solver_cb(Fl_Widget *w, void *data) for(int i = 0; i < NUM_SOLVERS; i++) { if(opt_solver_name(i, GMSH_GET, "").empty() || i == (NUM_SOLVERS - 1)) { const char *name = fl_input("Solver name:", ""); - if(name) { - FlGui::instance()->onelab->addSolver(name, "", "", i); - } + if(name) { FlGui::instance()->onelab->addSolver(name, "", "", i); } return; } } @@ -599,9 +598,9 @@ template <class T> void onelabGroup::_addParameter(T &p) int ww = (int)(_baseWidth - (n->depth() + 1) * _indent); int hh = n->labelsize() + 4; Fl_Group *grp = new Fl_Group(1, 1, ww, hh); - Fl_Widget *widget = addParameterWidget - (p, 1, 1, ww * _widgetLabelRatio, hh, _widgetLabelRatio, - getPath(n), highlight, c, _tree->color(), _treeStrings); + Fl_Widget *widget = + addParameterWidget(p, 1, 1, ww * _widgetLabelRatio, hh, _widgetLabelRatio, + getPath(n), highlight, c, _tree->color(), _treeStrings); grp->end(); if(!_enableTreeWidgetResize) grp->resizable(nullptr); _treeWidgets.push_back(grp); @@ -751,11 +750,9 @@ static bool serverActionMatch(const std::string &action, onelab::server::instance()->getParameterNames(names, match); for(auto &var : names) { - Msg::Debug("Performing action '%s' on variable '%s'", - action.c_str(), var.c_str()); - if(action == "ResetMatch") { - onelab::server::instance()->clear(var); - } + Msg::Debug("Performing action '%s' on variable '%s'", action.c_str(), + var.c_str()); + if(action == "ResetMatch") { onelab::server::instance()->clear(var); } else { std::vector<onelab::string> ps; onelab::server::instance()->get(ps, var); @@ -790,8 +787,7 @@ static bool serverActionMatch(const std::string &action, return !names.empty(); } -static bool serverActionList(const std::string &path, - const std::string &action, +static bool serverActionList(const std::string &path, const std::string &action, const std::string &data) { std::vector<std::string> what = onelab::parameter::split(data, ','); @@ -808,11 +804,9 @@ static bool serverActionList(const std::string &path, var.erase(0, 1); var = path + "/" + var; } - Msg::Debug("Performing action '%s' on variable '%s'", - action.c_str(), var.c_str()); - if(action == "Reset") { - onelab::server::instance()->clear(var); - } + Msg::Debug("Performing action '%s' on variable '%s'", action.c_str(), + var.c_str()); + if(action == "Reset") { onelab::server::instance()->clear(var); } else { std::string val; if(action == "Set") { @@ -867,8 +861,8 @@ template <class T> static void performServerAction(T &n) // parameters have been changed on the server-side): // * actions using one variable or a list of variables - std::vector<std::string> list = - {"Reset", "Hide", "Show", "Set", "ReadOnly", "ReadWrite"}; + std::vector<std::string> list = {"Reset", "Hide", "Show", + "Set", "ReadOnly", "ReadWrite"}; for(auto &a : list) { // global std::string data = n.getAttribute("ServerAction" + a); @@ -879,8 +873,8 @@ template <class T> static void performServerAction(T &n) } // * actions using a regex - std::vector<std::string> regex = - {"ResetMatch", "HideMatch", "ShowMatch", "ReadOnlyMatch", "ReadWriteMatch"}; + std::vector<std::string> regex = {"ResetMatch", "HideMatch", "ShowMatch", + "ReadOnlyMatch", "ReadWriteMatch"}; for(auto &a : regex) { // global std::string data = n.getAttribute("ServerAction" + a); @@ -979,10 +973,8 @@ static void onelab_number_output_range_cb(Fl_Widget *w, void *data) } } -Fl_Widget *addParameterWidget(onelab::number &p, - int xx, int yy, int ww, int hh, - double labelRatio, - const std::string &ppath, +Fl_Widget *addParameterWidget(onelab::number &p, int xx, int yy, int ww, int hh, + double labelRatio, const std::string &ppath, bool highlight, Fl_Color c, Fl_Color bgc, std::vector<char *> &stringsToFree) { @@ -1021,9 +1013,8 @@ Fl_Widget *addParameterWidget(onelab::number &p, // check box (boolean choice) if(p.getChoices().size() == 2 && p.getChoices()[0] == 0 && p.getChoices()[1] == 1) { - //n->labelsize(FL_NORMAL_SIZE + 2); - Fl_Check_Button *but = - new Fl_Check_Button(xx, yy, ww / labelRatio, hh); + // n->labelsize(FL_NORMAL_SIZE + 2); + Fl_Check_Button *but = new Fl_Check_Button(xx, yy, ww / labelRatio, hh); but->box(FL_FLAT_BOX); but->color(bgc); but->value(p.getValue()); @@ -1050,8 +1041,9 @@ Fl_Widget *addParameterWidget(onelab::number &p, } // general number input - inputRange *but = new inputRange(xx, yy, ww, hh, onelab::parameter::maxNumber(), - p.getAttribute("ReadOnlyRange") == "1"); + inputRange *but = + new inputRange(xx, yy, ww, hh, onelab::parameter::maxNumber(), + p.getAttribute("ReadOnlyRange") == "1"); but->numberFormat(p.getAttribute("NumberFormat")); but->value(p.getValue()); but->minimum(p.getMin()); @@ -1226,10 +1218,8 @@ static void multiple_selection_menu_none_cb(Fl_Widget *w, void *data) but->do_callback(); } -Fl_Widget *addParameterWidget(onelab::string &p, - int xx, int yy, int ww, int hh, - double labelRatio, - const std::string &ppath, +Fl_Widget *addParameterWidget(onelab::string &p, int xx, int yy, int ww, int hh, + double labelRatio, const std::string &ppath, bool highlight, Fl_Color c, Fl_Color bgc, std::vector<char *> &stringsToFree) { @@ -1294,7 +1284,8 @@ Fl_Widget *addParameterWidget(onelab::string &p, int choice = multipleSelection.size() ? FL_MENU_TOGGLE : 0; if(multipleSelection.size() > j && multipleSelection[j] == '1') choice |= FL_MENU_VALUE; - Fl_Menu_Item it = {str, 0, nullptr, nullptr, choice | (divider ? FL_MENU_DIVIDER : 0)}; + Fl_Menu_Item it = {str, 0, nullptr, nullptr, + choice | (divider ? FL_MENU_DIVIDER : 0)}; menu.push_back(it); } if(multipleSelection.size()) { @@ -1385,9 +1376,7 @@ static void highlight_physical_group_cb(Fl_Widget *w, void *data) for(std::size_t i = 0; i < entities.size(); i++) { entities[i]->setVisibility(1); - if(!entities[i]->getSelection()) { - entities[i]->setSelection(2); - } + if(!entities[i]->getSelection()) { entities[i]->setSelection(2); } else entities[i]->setSelection(0); } @@ -1437,8 +1426,7 @@ void onelabGroup::rebuildTree(bool deleteWidgets) _treeStrings.clear(); } - if(CTX::instance()->showModuleMenu) - _addGmshMenus(); + if(CTX::instance()->showModuleMenu) _addGmshMenus(); std::vector<onelab::number> numbers; onelab::server::instance()->get(numbers); @@ -1511,8 +1499,7 @@ void onelabGroup::rebuildTree(bool deleteWidgets) } } - for(auto it = closed.begin(); it != closed.end(); - it++) { + for(auto it = closed.begin(); it != closed.end(); it++) { if(it->size()) _tree->close(it->c_str(), 0); } @@ -1619,7 +1606,7 @@ void onelabGroup::setButtonMode(const std::string &butt0, int w = 0, h = 0; fl_measure(label, w, h); int diff = w - _butt[1]->w() + 2 * WB; - if(diff > 0){ + if(diff > 0) { _butt[1]->resize(_butt[1]->x() - diff, _butt[1]->y(), _butt[1]->w() + diff, _butt[1]->h()); _butt[1]->redraw(); @@ -1724,8 +1711,7 @@ void onelabGroup::rebuildSolverList() } for(std::size_t i = 0; i < NUM_SOLVERS; i++) { if(i < names.size()) { - auto it = - onelab::server::instance()->findClient(names[i]); + auto it = onelab::server::instance()->findClient(names[i]); if(it != onelab::server::instance()->lastClient()) (*it)->setIndex(i); opt_solver_name(i, GMSH_SET, names[i]); opt_solver_executable(i, GMSH_SET, exes[i]); diff --git a/Fltk/onelabGroup.h b/Fltk/onelabGroup.h index d8944aa2a416289c3c164b551d0ceb39a518afb9..bc35c7ae770050d443071bc064719cf71a9a0d71 100644 --- a/Fltk/onelabGroup.h +++ b/Fltk/onelabGroup.h @@ -76,15 +76,12 @@ public: }; bool getParameterColor(const std::string &str, Fl_Color &c); -Fl_Widget *addParameterWidget(onelab::number &p, - int xx, int yy, int ww, int hh, +Fl_Widget *addParameterWidget(onelab::number &p, int xx, int yy, int ww, int hh, double labelRatio, const std::string &ppath, bool highlight, Fl_Color c, Fl_Color bgc, std::vector<char *> &stringsToFree); -Fl_Widget *addParameterWidget(onelab::string &p, - int xx, int yy, int ww, int hh, - double labelRatio, - const std::string &ppath, +Fl_Widget *addParameterWidget(onelab::string &p, int xx, int yy, int ww, int hh, + double labelRatio, const std::string &ppath, bool highlight, Fl_Color c, Fl_Color bgc, std::vector<char *> &stringsToFree); void solver_cb(Fl_Widget *w, void *data); diff --git a/Fltk/openglWindow.cpp b/Fltk/openglWindow.cpp index dbf3b13011103629d875f17fa2913841aff4e55b..8f653bbf54496dfd69f508541b59dc4370ce455a 100644 --- a/Fltk/openglWindow.cpp +++ b/Fltk/openglWindow.cpp @@ -108,11 +108,10 @@ void openglWindow::show() /* You can uncomment this if you cannot use the very latest FLTK 1.4 version patched for macOS mojave -#if defined(__APPLE__) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14) - Msg::Info("OpenGL hack for macOS 10.14: see http://www.fltk.org/str.php?L3496"); - resize(x(), y(), w()+1, h()); - resize(x(), y(), w()-1, h()); -#endif +#if defined(__APPLE__) && (MAC_OS_X_VERSION_MAX_ALLOWED >= +MAC_OS_X_VERSION_10_14) Msg::Info("OpenGL hack for macOS 10.14: see +http://www.fltk.org/str.php?L3496"); resize(x(), y(), w()+1, h()); resize(x(), +y(), w()-1, h()); #endif */ } @@ -182,9 +181,7 @@ void openglWindow::draw() Msg::Debug("openglWindow::draw()"); - if(!context_valid()) { - _ctx->invalidateQuadricsAndDisplayLists(); - } + if(!context_valid()) { _ctx->invalidateQuadricsAndDisplayLists(); } _ctx->viewport[0] = 0; _ctx->viewport[1] = 0; @@ -249,7 +246,8 @@ void openglWindow::draw() _ctx->draw3d(); glColor4ubv((GLubyte *)&CTX::instance()->color.geom.highlight[0]); - float ps = CTX::instance()->geom.pointSize * _ctx->highResolutionPixelFactor(); + float ps = + CTX::instance()->geom.pointSize * _ctx->highResolutionPixelFactor(); glPointSize(ps); glBegin(GL_POINTS); glVertex3d(_point[0], _point[1], _point[2]); @@ -391,9 +389,9 @@ int openglWindow::handle(int event) std::vector<MElement *> elements; std::vector<SPoint2> points; std::vector<PView *> views; - _select(ENT_ALL, false, CTX::instance()->mouseHoverMeshes, - true, Fl::event_x(), Fl::event_y(), 5, 5, - vertices, edges, faces, regions, elements, points, views); + _select(ENT_ALL, false, CTX::instance()->mouseHoverMeshes, true, + Fl::event_x(), Fl::event_y(), 5, 5, vertices, edges, faces, + regions, elements, points, views); if(vertices.size() && CTX::instance()->geom.doubleClickedPointCommand.size()) { CTX::instance()->geom.doubleClickedEntityTag = vertices[0]->tag(); @@ -584,9 +582,7 @@ int openglWindow::handle(int event) { double dx = _curr.win[0] - _prev.win[0]; double dy = _curr.win[1] - _prev.win[1]; - if(lassoMode) { - redraw(); - } + if(lassoMode) { redraw(); } else { if(Fl::event_state(FL_META)) { // will try to select or unselect entities on the fly @@ -672,9 +668,7 @@ int openglWindow::handle(int event) case FL_MOVE: _curr.set(_ctx, Fl::event_x(), Fl::event_y()); - if(lassoMode) { - redraw(); - } + if(lassoMode) { redraw(); } else if(addPointMode && !Fl::event_state(FL_SHIFT)) { cursor(FL_CURSOR_CROSS, FL_BLACK, FL_WHITE); // find line in real space corresponding to current cursor position @@ -902,11 +896,9 @@ char openglWindow::selectEntity(int type, std::vector<GVertex *> &vertices, void openglWindow::drawTooltip(const std::string &text) { #if defined(NEW_TOOLTIPS) - if(text.empty()){ - _tooltip->hide(); - } - else{ - _tooltip->position(Fl::event_x_root(), Fl::event_y_root()+20); + if(text.empty()) { _tooltip->hide(); } + else { + _tooltip->position(Fl::event_x_root(), Fl::event_y_root() + 20); _tooltip->value(text); _tooltip->show(); } diff --git a/Fltk/openglWindow.h b/Fltk/openglWindow.h index 64736d9d9a790edc26452bc45576b199d12dfddd..8ebe66c4c7c136a18135eba0628e86733390f80d 100644 --- a/Fltk/openglWindow.h +++ b/Fltk/openglWindow.h @@ -19,9 +19,10 @@ #include <FL/fl_draw.H> class tooltipWindow : public Fl_Menu_Window { - private: +private: char _text[1024]; - public: + +public: tooltipWindow() : Fl_Menu_Window(1, 1) { strcpy(_text, ""); @@ -34,11 +35,12 @@ class tooltipWindow : public Fl_Menu_Window { draw_box(FL_BORDER_BOX, 0, 0, w(), h(), Fl_Color(175)); fl_color(FL_BLACK); fl_font(labelfont(), labelsize()); - fl_draw(_text, 3, 3, w() - 6, h() - 6, Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_WRAP)); + fl_draw(_text, 3, 3, w() - 6, h() - 6, + Fl_Align(FL_ALIGN_LEFT | FL_ALIGN_WRAP)); } int handle(int e) { - if (e == FL_PUSH || e == FL_KEYDOWN) { + if(e == FL_PUSH || e == FL_KEYDOWN) { hide(); return 1; } diff --git a/Fltk/optionWindow.cpp b/Fltk/optionWindow.cpp index 1cac3f32bd3cae55a167809ddb8f91179a509328..fdd928c5843b95fdd98d0ef6e623fbc1be736697 100644 --- a/Fltk/optionWindow.cpp +++ b/Fltk/optionWindow.cpp @@ -46,49 +46,41 @@ extern StringXColor GeometryOptions_Color[]; extern StringXColor MeshOptions_Color[]; extern StringXColor ViewOptions_Color[]; -static Fl_Menu_Item menu_point_display[] = { - {"Color dot", 0, nullptr, nullptr}, - {"3D sphere", 0, nullptr, nullptr}, - {nullptr} -}; +static Fl_Menu_Item menu_point_display[] = {{"Color dot", 0, nullptr, nullptr}, + {"3D sphere", 0, nullptr, nullptr}, + {nullptr}}; static Fl_Menu_Item menu_point_display_post[] = { {"Color dot", 0, nullptr, nullptr}, {"3D sphere", 0, nullptr, nullptr}, {"Scaled dot", 0, nullptr, nullptr}, {"Scaled sphere", 0, nullptr, nullptr}, - {nullptr} -}; + {nullptr}}; static Fl_Menu_Item menu_line_display[] = { {"Color segment", 0, nullptr, nullptr}, {"3D cylinder", 0, nullptr, nullptr}, - {nullptr} -}; + {nullptr}}; static Fl_Menu_Item menu_line_display_post[] = { {"Color segment", 0, nullptr, nullptr}, {"3D cylinder", 0, nullptr, nullptr}, {"Tapered cylinder", 0, nullptr, nullptr}, - {nullptr} -}; + {nullptr}}; static Fl_Menu_Item menu_surface_display[] = { {"Cross", 0, nullptr, nullptr}, {"Wireframe", 0, nullptr, nullptr}, {"Solid", 0, nullptr, nullptr}, - {nullptr} -}; - -static Fl_Menu_Item menu_axes_mode[] = { - {"None", 0, nullptr, nullptr}, - {"Simple axes", 0, nullptr, nullptr}, - {"Box", 0, nullptr, nullptr}, - {"Full grid", 0, nullptr, nullptr}, - {"Open grid", 0, nullptr, nullptr}, - {"Ruler", 0, nullptr, nullptr}, - {nullptr} -}; + {nullptr}}; + +static Fl_Menu_Item menu_axes_mode[] = {{"None", 0, nullptr, nullptr}, + {"Simple axes", 0, nullptr, nullptr}, + {"Box", 0, nullptr, nullptr}, + {"Full grid", 0, nullptr, nullptr}, + {"Open grid", 0, nullptr, nullptr}, + {"Ruler", 0, nullptr, nullptr}, + {nullptr}}; static Fl_Menu_Item menu_position[] = { {"Manual", 0, nullptr, nullptr}, @@ -104,8 +96,7 @@ static Fl_Menu_Item menu_position[] = { {"Full", 0, nullptr, nullptr}, {"Top third", 0, nullptr, nullptr}, {"In model coordinates", 0, nullptr, nullptr}, - {nullptr} -}; + {nullptr}}; Fl_Menu_Item menu_font_names[] = { {"Times-Roman", 0, nullptr, (void *)FL_TIMES}, @@ -123,8 +114,7 @@ Fl_Menu_Item menu_font_names[] = { {"Symbol", 0, nullptr, (void *)FL_SYMBOL}, {"ZapfDingbats", 0, nullptr, (void *)FL_ZAPF_DINGBATS}, {"Screen", 0, nullptr, (void *)FL_SCREEN}, - {nullptr} -}; + {nullptr}}; static void color_cb(Fl_Widget *w, void *data) { @@ -211,8 +201,9 @@ static void general_options_color_scheme_cb(Fl_Widget *w, void *data) void general_options_rotation_center_select_cb(Fl_Widget *w, void *data) { - Msg::StatusGl("Select geometrical entity, mesh element or post-processing view\n" - "[Press 'q' to abort]"); + Msg::StatusGl( + "Select geometrical entity, mesh element or post-processing view\n" + "[Press 'q' to abort]"); CTX::instance()->pickElements = 1; CTX::instance()->mesh.changed = ENT_ALL; @@ -234,7 +225,11 @@ void general_options_rotation_center_select_cb(Fl_Widget *w, void *data) pc = FlGui::instance()->selectedRegions[0]->bounds().center(); else if(FlGui::instance()->selectedViews.size() && FlGui::instance()->selectedViews[0]->getData()) - pc = FlGui::instance()->selectedViews[0]->getData()->getBoundingBox().center(); + pc = FlGui::instance() + ->selectedViews[0] + ->getData() + ->getBoundingBox() + .center(); opt_general_rotation_center0(0, GMSH_SET | GMSH_GUI, pc.x()); opt_general_rotation_center1(0, GMSH_SET | GMSH_GUI, pc.y()); opt_general_rotation_center2(0, GMSH_SET | GMSH_GUI, pc.z()); @@ -253,7 +248,7 @@ void general_options_rotation_center_select_cb(Fl_Widget *w, void *data) void general_options_axes_fit_cb(Fl_Widget *w, void *data) { SBoundingBox3d bbox = GModel::current()->bounds(true); - for(std::size_t i = 0; i < PView::list.size(); i++){ + for(std::size_t i = 0; i < PView::list.size(); i++) { if(PView::list[i]->getOptions()->visible && !PView::list[i]->getData()->getBoundingBox().empty()) bbox += PView::list[i]->getData()->getBoundingBox(); @@ -262,12 +257,12 @@ void general_options_axes_fit_cb(Fl_Widget *w, void *data) bbox = SBoundingBox3d(CTX::instance()->min[0], CTX::instance()->min[1], CTX::instance()->min[2], CTX::instance()->max[0], CTX::instance()->max[1], CTX::instance()->max[2]); - opt_general_axes_xmin(0, GMSH_SET|GMSH_GUI, bbox.min().x()); - opt_general_axes_ymin(0, GMSH_SET|GMSH_GUI, bbox.min().y()); - opt_general_axes_zmin(0, GMSH_SET|GMSH_GUI, bbox.min().z()); - opt_general_axes_xmax(0, GMSH_SET|GMSH_GUI, bbox.max().x()); - opt_general_axes_ymax(0, GMSH_SET|GMSH_GUI, bbox.max().y()); - opt_general_axes_zmax(0, GMSH_SET|GMSH_GUI, bbox.max().z()); + opt_general_axes_xmin(0, GMSH_SET | GMSH_GUI, bbox.min().x()); + opt_general_axes_ymin(0, GMSH_SET | GMSH_GUI, bbox.min().y()); + opt_general_axes_zmin(0, GMSH_SET | GMSH_GUI, bbox.min().z()); + opt_general_axes_xmax(0, GMSH_SET | GMSH_GUI, bbox.max().x()); + opt_general_axes_ymax(0, GMSH_SET | GMSH_GUI, bbox.max().y()); + opt_general_axes_zmax(0, GMSH_SET | GMSH_GUI, bbox.max().z()); drawContext::global()->draw(); } @@ -589,13 +584,13 @@ static void mesh_options_ok_cb(Fl_Widget *w, void *data) (o->mesh.choice[2]->value() == 5) ? ALGO_2D_FRONTAL_QUAD : (o->mesh.choice[2]->value() == 6) ? ALGO_2D_PACK_PRLGRMS : (o->mesh.choice[2]->value() == 7) ? ALGO_2D_INITIAL_ONLY : - ALGO_2D_AUTO); + ALGO_2D_AUTO); opt_mesh_algo3d(0, GMSH_SET, (o->mesh.choice[3]->value() == 1) ? ALGO_3D_FRONTAL : (o->mesh.choice[3]->value() == 2) ? ALGO_3D_HXT : (o->mesh.choice[3]->value() == 3) ? ALGO_3D_MMG3D : (o->mesh.choice[3]->value() == 4) ? ALGO_3D_INITIAL_ONLY : - ALGO_3D_DELAUNAY); + ALGO_3D_DELAUNAY); opt_mesh_algo_recombine(0, GMSH_SET, o->mesh.choice[1]->value()); opt_mesh_algo_subdivide(0, GMSH_SET, o->mesh.choice[5]->value()); opt_mesh_color_carousel(0, GMSH_SET, o->mesh.choice[4]->value()); @@ -913,11 +908,10 @@ static void view_options_ok_cb(Fl_Widget *w, void *data) val = o->view.choice[13]->value() + 1; if(force || (val != type)) opt_view_type(i, GMSH_SET, val); - val = (o->view.choice[14]->value() == 1) ? - 1 : - (o->view.choice[14]->value() == 2) ? - 3 : - (o->view.choice[14]->value() == 3) ? 9 : 0; + val = (o->view.choice[14]->value() == 1) ? 1 : + (o->view.choice[14]->value() == 2) ? 3 : + (o->view.choice[14]->value() == 3) ? 9 : + 0; if(force || (val != force_num_components)) opt_view_force_num_components(i, GMSH_SET, val); @@ -1290,8 +1284,8 @@ static void view_options_ok_cb(Fl_Widget *w, void *data) opt_view_color_text3d(current, GMSH_GET, 0)); opt_view_color_axes(i, GMSH_SET, opt_view_color_axes(current, GMSH_GET, 0)); - opt_view_color_background2d(i, GMSH_SET, - opt_view_color_background2d(current, GMSH_GET, 0)); + opt_view_color_background2d( + i, GMSH_SET, opt_view_color_background2d(current, GMSH_GET, 0)); } // colorbar window @@ -1476,8 +1470,9 @@ optionWindow::optionWindow(int deltaFontSize) general.value[10]->callback(general_options_ok_cb, (void *)"rotation_center_coord"); - general.butt[22] = new Fl_Check_Button - (L + 2 * WB, 2 * WB + 11 * BH, BW, BH, "Invert mouse wheel zoom direction"); + general.butt[22] = + new Fl_Check_Button(L + 2 * WB, 2 * WB + 11 * BH, BW, BH, + "Invert mouse wheel zoom direction"); general.butt[22]->tooltip("General.MouseInvertZoom"); general.butt[22]->type(FL_TOGGLE_BUTTON); general.butt[22]->callback(general_options_ok_cb); @@ -1550,8 +1545,8 @@ optionWindow::optionWindow(int deltaFontSize) general.butt[10]->type(FL_TOGGLE_BUTTON); general.butt[10]->callback(general_options_ok_cb); - general.value[32] = new Fl_Value_Input(L + 2 * WB, 2 * WB + 9 * BH, IW, BH, - "Number of threads"); + general.value[32] = new Fl_Value_Input(L + 2 * WB, 2 * WB + 9 * BH, IW, + BH, "Number of threads"); general.value[32]->tooltip("General.NumThreads"); general.value[32]->minimum(0); general.value[32]->maximum(16); @@ -1564,7 +1559,7 @@ optionWindow::optionWindow(int deltaFontSize) #if defined(HAVE_VISUDEV) general.butt[20] = - new Fl_Check_Button(L + 2 * WB, 2 * WB + 10 * BH, BW / 2 - WB, BH, + new Fl_Check_Button(L + 2 * WB, 2 * WB + 10 * BH, BW / 2 - WB, BH, "Enable heavy visualization capabilities"); general.butt[20]->type(FL_TOGGLE_BUTTON); general.butt[20]->callback(general_options_ok_cb); @@ -1722,8 +1717,7 @@ optionWindow::optionWindow(int deltaFontSize) static Fl_Menu_Item menu_projection[] = { {"Orthographic", 0, nullptr, nullptr}, {"Perspective", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; general.choice[2] = new Fl_Choice(L + 2 * WB, 2 * WB + 1 * BH, IW, BH, "Projection mode"); general.choice[2]->tooltip("General.Orthographic (Alt+o)"); @@ -1796,8 +1790,7 @@ optionWindow::optionWindow(int deltaFontSize) {"Arrow", 0, nullptr, nullptr}, {"Pyramid", 0, nullptr, nullptr}, {"3D arrow", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; general.choice[0] = new Fl_Choice(L + 2 * WB, 2 * WB + 8 * BH, IW, BH, "Vector display"); general.choice[0]->tooltip("General.VectorType"); @@ -1813,12 +1806,12 @@ optionWindow::optionWindow(int deltaFontSize) {"Native", 0, nullptr, nullptr}, {"Cairo", 0, nullptr, nullptr #if !defined(HAVE_CAIRO) - , FL_MENU_INACTIVE + , + FL_MENU_INACTIVE #endif }, {"StringTexture", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; general.choice[7] = new Fl_Choice(L + 2 * WB, 2 * WB + 9 * BH, IW, BH, "Font rendering engine"); general.choice[7]->tooltip("General.GraphicsFontEngine"); @@ -1922,8 +1915,7 @@ optionWindow::optionWindow(int deltaFontSize) {"Default", 0, nullptr, nullptr}, {"Grayscale", 0, nullptr, nullptr}, {"Dark", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; general.choice[3] = new Fl_Choice(L + 2 * WB, 2 * WB + 4 * BH, IW, BH, "Predefined color scheme"); @@ -1932,13 +1924,11 @@ optionWindow::optionWindow(int deltaFontSize) general.choice[3]->align(FL_ALIGN_RIGHT); general.choice[3]->callback(general_options_color_scheme_cb); - static Fl_Menu_Item menu_bg_grad[] = { - {"None", 0, nullptr, nullptr}, - {"Vertical", 0, nullptr, nullptr}, - {"Horizontal", 0, nullptr, nullptr}, - {"Radial", 0, nullptr, nullptr}, - {nullptr} - }; + static Fl_Menu_Item menu_bg_grad[] = {{"None", 0, nullptr, nullptr}, + {"Vertical", 0, nullptr, nullptr}, + {"Horizontal", 0, nullptr, nullptr}, + {"Radial", 0, nullptr, nullptr}, + {nullptr}}; general.choice[5] = new Fl_Choice(L + 2 * WB, 2 * WB + 5 * BH, IW, BH, "Background gradient"); @@ -1963,7 +1953,7 @@ optionWindow::optionWindow(int deltaFontSize) (void *)GeneralOptions_Color[j].function); i++; j++; - if(i >= general.color.size()){ + if(i >= general.color.size()) { Msg::Error("General color widget vector should be resized"); break; } @@ -2084,9 +2074,8 @@ optionWindow::optionWindow(int deltaFontSize) b->box(FL_ENGRAVED_FRAME); b->labeltype(FL_NO_LABEL); - Fl_Box *b2 = - new Fl_Box(FL_NO_BOX, L + 2 * WB, 2 * WB + 3 * BH + 1, IW, BH, - "Open CASCADE model healing options:"); + Fl_Box *b2 = new Fl_Box(FL_NO_BOX, L + 2 * WB, 2 * WB + 3 * BH + 1, IW, + BH, "Open CASCADE model healing options:"); b2->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT); geo.butt[16] = new Fl_Check_Button(L + 2 * WB, 2 * WB + 4 * BH, BW, BH, @@ -2113,8 +2102,8 @@ optionWindow::optionWindow(int deltaFontSize) geo.butt[13]->type(FL_TOGGLE_BUTTON); geo.butt[13]->callback(geometry_options_ok_cb); - geo.butt[14] = - new Fl_Check_Button(L + 2 * WB, 2 * WB + 8 * BH, BW, BH, "Fix shells and make solids"); + geo.butt[14] = new Fl_Check_Button(L + 2 * WB, 2 * WB + 8 * BH, BW, BH, + "Fix shells and make solids"); geo.butt[14]->tooltip("Geometry.OCCMakeSolids"); geo.butt[14]->type(FL_TOGGLE_BUTTON); geo.butt[14]->callback(geometry_options_ok_cb); @@ -2192,8 +2181,7 @@ optionWindow::optionWindow(int deltaFontSize) {"Description", 0, nullptr, nullptr}, {"Elementary tag", 0, nullptr, nullptr}, {"Physical tag(s)", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; geo.choice[4] = new Fl_Choice(L + 2 * WB, 2 * WB + 5 * BH, IW, BH, "Label type"); geo.choice[4]->tooltip("Geometry.LabelType"); @@ -2228,11 +2216,9 @@ optionWindow::optionWindow(int deltaFontSize) height - 2 * WB - BH, "Transfo"); o->hide(); - static Fl_Menu_Item menu_transform[] = { - {"None", 0, nullptr, nullptr}, - {"Scaling", 0, nullptr, nullptr}, - {nullptr} - }; + static Fl_Menu_Item menu_transform[] = {{"None", 0, nullptr, nullptr}, + {"Scaling", 0, nullptr, nullptr}, + {nullptr}}; geo.choice[3] = new Fl_Choice(L + 2 * WB, 2 * WB + 1 * BH, IW, BH, "Main window transform"); geo.choice[3]->tooltip("Geometry.Transform"); @@ -2398,7 +2384,7 @@ optionWindow::optionWindow(int deltaFontSize) (void *)GeometryOptions_Color[j].function); i++; j++; - if(i >= geo.color.size()){ + if(i >= geo.color.size()) { Msg::Error("Geometry color widget vector should be resized"); break; } @@ -2428,31 +2414,28 @@ optionWindow::optionWindow(int deltaFontSize) {"Frontal-Delaunay", 0, nullptr, nullptr}, {"BAMG (experimental)", 0, nullptr, nullptr}, {"Frontal-Delaunay for Quads (experimental)", 0, nullptr, nullptr}, - {"Packing of Parallelograms (experimental, planar only)", 0, nullptr, nullptr}, + {"Packing of Parallelograms (experimental, planar only)", 0, nullptr, + nullptr}, {"Initial Mesh Only (no node insertion)", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; static Fl_Menu_Item menu_3d_algo[] = { {"Delaunay", 0, nullptr, nullptr}, {"Frontal", 0, nullptr, nullptr}, {"HXT (experimental)", 0, nullptr, nullptr}, {"MMG3D (experimental, single volume only)", 0, nullptr, nullptr}, {"Initial Mesh Only (no node insertion)", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; static Fl_Menu_Item menu_recombination_algo[] = { {"Simple", 0, nullptr, nullptr}, {"Blossom", 0, nullptr, nullptr}, {"Simple Full-Quad", 0, nullptr, nullptr}, {"Blossom Full-Quad", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; static Fl_Menu_Item menu_subdivision_algo[] = { {"None", 0, nullptr, nullptr}, {"All Quads", 0, nullptr, nullptr}, {"All Hexas", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; mesh.choice[2] = new Fl_Choice(L + 2 * WB, 2 * WB + 1 * BH, IW, BH, "2D algorithm"); @@ -2547,23 +2530,25 @@ optionWindow::optionWindow(int deltaFontSize) "Compute element sizes using point values"); mesh.butt[5]->tooltip("Mesh.MeshSizeFromPoints"); mesh.butt[5]->type(FL_TOGGLE_BUTTON); - mesh.butt[5]->callback(mesh_options_ok_cb,(void*)"mesh_lc_from_points"); + mesh.butt[5]->callback(mesh_options_ok_cb, (void *)"mesh_lc_from_points"); - mesh.butt[26] = - new Fl_Check_Button(L + 2 * WB, 2 * WB + 2 * BH, BW, BH, - "Compute element sizes using parametric point values"); + mesh.butt[26] = new Fl_Check_Button( + L + 2 * WB, 2 * WB + 2 * BH, BW, BH, + "Compute element sizes using parametric point values"); mesh.butt[26]->tooltip("Mesh.MeshSizeFromParametricPoints"); mesh.butt[26]->type(FL_TOGGLE_BUTTON); mesh.butt[26]->callback(mesh_options_ok_cb); - mesh.butt[1] = new Fl_Check_Button(L + 2 * WB, 2 * WB + 3 * BH, BW, BH, - "Compute element sizes from curvature"); + mesh.butt[1] = + new Fl_Check_Button(L + 2 * WB, 2 * WB + 3 * BH, BW, BH, + "Compute element sizes from curvature"); mesh.butt[1]->tooltip("Mesh.MeshSizeFromCurvature"); mesh.butt[1]->type(FL_TOGGLE_BUTTON); mesh.butt[1]->callback(mesh_options_ok_cb, (void *)"mesh_curvature"); - mesh.value[1] = new Fl_Value_Input(L + 2 * WB, 2 * WB + 4 * BH, IW / 2, BH, - "Number of elements per 2 pi radians"); + mesh.value[1] = + new Fl_Value_Input(L + 2 * WB, 2 * WB + 4 * BH, IW / 2, BH, + "Number of elements per 2 pi radians"); mesh.value[1]->tooltip("Mesh.MinimumElementsPerTwoPi"); mesh.value[1]->minimum(3); mesh.value[1]->maximum(50); @@ -2594,9 +2579,8 @@ optionWindow::optionWindow(int deltaFontSize) #endif mesh.butt[24]->callback(mesh_options_ok_cb); - mesh.butt[3] = - new Fl_Check_Button(L + 2 * WB, 2 * WB + 8 * BH, BW, BH, - "Optimize high-order meshes"); + mesh.butt[3] = new Fl_Check_Button(L + 2 * WB, 2 * WB + 8 * BH, BW, BH, + "Optimize high-order meshes"); mesh.butt[3]->tooltip("Mesh.HighOrderOptimize"); mesh.butt[3]->type(FL_TOGGLE_BUTTON); mesh.butt[3]->callback(mesh_options_ok_cb); @@ -2674,8 +2658,7 @@ optionWindow::optionWindow(int deltaFontSize) {"Physical group tag(s)", 0, nullptr, nullptr}, {"Mesh partition", 0, nullptr, nullptr}, {"Coordinates", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; mesh.choice[7] = new Fl_Choice(L + 2 * WB, 2 * WB + 7 * BH, IW, BH, "Label type"); mesh.choice[7]->tooltip("Mesh.LabelType"); @@ -2702,13 +2685,13 @@ optionWindow::optionWindow(int deltaFontSize) {"Prisms", 0, nullptr, nullptr, FL_MENU_TOGGLE}, {"Pyramids", 0, nullptr, nullptr, FL_MENU_TOGGLE}, {"Trihedra", 0, nullptr, nullptr, FL_MENU_TOGGLE}, - {nullptr} - }; + {nullptr}}; mesh.menu = new Fl_Menu_Button(L + 2 * WB, 2 * WB + 8 * BH, IW, BH, "Elements"); - mesh.menu->tooltip("Mesh.Triangles, Mesh.Quadrangles, Mesh.Tetrahedra, " - "Mesh.Hexahedra, Mesh.Prisms, Mesh.Pyramids, Mesh.Trihedra"); + mesh.menu->tooltip( + "Mesh.Triangles, Mesh.Quadrangles, Mesh.Tetrahedra, " + "Mesh.Hexahedra, Mesh.Prisms, Mesh.Pyramids, Mesh.Trihedra"); mesh.menu->menu(menu_mesh_element_types); mesh.menu->callback(mesh_options_ok_cb); @@ -2732,13 +2715,11 @@ optionWindow::optionWindow(int deltaFontSize) mesh.value[5]->when(FL_WHEN_RELEASE); mesh.value[5]->callback(mesh_options_ok_cb); - static Fl_Menu_Item menu_quality_type[] = { - {"SICN", 0, nullptr, nullptr}, - {"SIGE", 0, nullptr, nullptr}, - {"Gamma", 0, nullptr, nullptr}, - {"Disto", 0, nullptr, nullptr}, - {nullptr} - }; + static Fl_Menu_Item menu_quality_type[] = {{"SICN", 0, nullptr, nullptr}, + {"SIGE", 0, nullptr, nullptr}, + {"Gamma", 0, nullptr, nullptr}, + {"Disto", 0, nullptr, nullptr}, + {nullptr}}; mesh.choice[6] = new Fl_Choice(L + 2 * WB + IW / 2, 2 * WB + 9 * BH, IW / 2, BH, "Quality range"); mesh.choice[6]->tooltip("Mesh.QualityType"); @@ -2849,8 +2830,7 @@ optionWindow::optionWindow(int deltaFontSize) {"No", 0, nullptr, nullptr}, {"Surface", 0, nullptr, nullptr}, {"Volume and surface", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; mesh.choice[10] = new Fl_Choice(L + 2 * WB, 2 * WB + 2 * BH, IW, BH, "Edge lighting"); mesh.choice[10]->tooltip("Mesh.LightLines"); @@ -2885,8 +2865,7 @@ optionWindow::optionWindow(int deltaFontSize) {"By elementary entity", 0, nullptr, nullptr}, {"By physical group", 0, nullptr, nullptr}, {"By mesh partition", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; mesh.choice[4] = new Fl_Choice(L + 2 * WB, 2 * WB + 6 * BH, IW, BH, "Coloring mode"); mesh.choice[4]->tooltip("Mesh.ColorCarousel"); @@ -2908,7 +2887,7 @@ optionWindow::optionWindow(int deltaFontSize) (void *)MeshOptions_Color[j].function); i++; j++; - if(i >= mesh.color.size()){ + if(i >= mesh.color.size()) { Msg::Error("Mesh color widget vector should be resized"); break; } @@ -2981,8 +2960,7 @@ optionWindow::optionWindow(int deltaFontSize) static Fl_Menu_Item menu_links[] = { {"Apply next changes to selected views", 0, nullptr, nullptr}, {"Force same options for selected views", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; post.choice[0] = new Fl_Choice(L + 2 * WB, 2 * WB + 1 * BH, IW, BH, "View links"); @@ -3045,13 +3023,11 @@ optionWindow::optionWindow(int deltaFontSize) Fl_Group *o = new Fl_Group(L + WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "General"); - static Fl_Menu_Item menu_plot_type[] = { - {"3D", 0, nullptr, nullptr}, - {"2D space", 0, nullptr, nullptr}, - {"2D time", 0, nullptr, nullptr}, - {"2D", 0, nullptr, nullptr}, - {nullptr} - }; + static Fl_Menu_Item menu_plot_type[] = {{"3D", 0, nullptr, nullptr}, + {"2D space", 0, nullptr, nullptr}, + {"2D time", 0, nullptr, nullptr}, + {"2D", 0, nullptr, nullptr}, + {nullptr}}; view.choice[13] = new Fl_Choice(L + 2 * WB, 2 * WB + 1 * BH, IW, BH, "Plot type"); view.choice[13]->tooltip("View.Type"); @@ -3109,8 +3085,7 @@ optionWindow::optionWindow(int deltaFontSize) {"Continuous map", 0, nullptr, nullptr}, {"Filled iso-values", 0, nullptr, nullptr}, {"Numeric values", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; view.choice[0] = new Fl_Choice(L + 2 * WB, 2 * WB + 5 * BH, IW, BH, "Intervals type"); view.choice[0]->tooltip("View.IntervalsType (Alt+t)"); @@ -3122,8 +3097,7 @@ optionWindow::optionWindow(int deltaFontSize) {"Linear", 0, nullptr, nullptr}, {"Logarithmic", 0, nullptr, nullptr}, {"Double logarithmic", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; view.choice[1] = new Fl_Choice(L + width - (int)(0.85 * IW) - 2 * WB, 2 * WB + 5 * BH, (int)(0.85 * IW), BH); view.choice[1]->tooltip("View.ScaleType"); @@ -3131,12 +3105,10 @@ optionWindow::optionWindow(int deltaFontSize) view.choice[1]->align(FL_ALIGN_RIGHT); view.choice[1]->callback(view_options_ok_cb); - static Fl_Menu_Item menu_range[] = { - {"Default", 0, nullptr, nullptr}, - {"Custom", 0, nullptr, nullptr}, - {"Per step", 0, nullptr, nullptr}, - {nullptr} - }; + static Fl_Menu_Item menu_range[] = {{"Default", 0, nullptr, nullptr}, + {"Custom", 0, nullptr, nullptr}, + {"Per step", 0, nullptr, nullptr}, + {nullptr}}; view.choice[7] = new Fl_Choice(L + 2 * WB, 2 * WB + 6 * BH, IW, BH, "Range mode"); view.choice[7]->tooltip("View.RangeType (Alt+r)"); @@ -3375,8 +3347,7 @@ optionWindow::optionWindow(int deltaFontSize) {"Multi-step data", 0, nullptr, nullptr}, {"Real eigenvalues", 0, nullptr, nullptr}, {"Complex eigenvalues", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; view.choice[12] = new Fl_Choice(L + 2 * WB, 2 * WB + 2 * BH, IW, BH, "Time display"); view.choice[12]->tooltip("View.ShowTime"); @@ -3411,14 +3382,14 @@ optionWindow::optionWindow(int deltaFontSize) {"Hexahedra", 0, nullptr, nullptr, FL_MENU_TOGGLE}, {"Prisms", 0, nullptr, nullptr, FL_MENU_TOGGLE}, {"Pyramids", 0, nullptr, nullptr, FL_MENU_TOGGLE}, - {nullptr} - }; + {nullptr}}; view.menu[1] = new Fl_Menu_Button(L + 2 * WB, 2 * WB + 6 * BH, IW, BH, "Elements"); - view.menu[1]->tooltip("View.DrawPoints, View.DrawLines, View.DrawTriangles, " - "View.DrawQuadrangles, View.DrawTetrahedra, View.DrawHexahedra, " - "View.DrawPrisms, View.DrawPyramids"); + view.menu[1]->tooltip( + "View.DrawPoints, View.DrawLines, View.DrawTriangles, " + "View.DrawQuadrangles, View.DrawTetrahedra, View.DrawHexahedra, " + "View.DrawPrisms, View.DrawPyramids"); view.menu[1]->menu(menu_view_element_types); view.menu[1]->callback(view_options_ok_cb); @@ -3437,8 +3408,7 @@ optionWindow::optionWindow(int deltaFontSize) {"Dimension - 1", 0, nullptr, nullptr}, {"Dimension - 2", 0, nullptr, nullptr}, {"Dimension - 3", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; view.choice[9] = new Fl_Choice(L + 2 * WB, 2 * WB + 7 * BH, IW, BH, "Element boundary mode"); view.choice[9]->tooltip("View.Boundary"); @@ -3470,11 +3440,11 @@ optionWindow::optionWindow(int deltaFontSize) {"Scalar", 0, nullptr, nullptr, FL_MENU_TOGGLE}, {"Vector", 0, nullptr, nullptr, FL_MENU_TOGGLE}, {"Tensor", 0, nullptr, nullptr, FL_MENU_TOGGLE}, - {nullptr} - }; + {nullptr}}; view.menu[0] = new Fl_Menu_Button(L + 2 * WB, 2 * WB + 9 * BH, IW, BH, "Fields"); - view.menu[0]->tooltip("View.DrawScalars, View.DrawVectors, View.DrawTensors"); + view.menu[0]->tooltip( + "View.DrawScalars, View.DrawVectors, View.DrawTensors"); view.menu[0]->menu(menu_view_field_types); view.menu[0]->callback(view_options_ok_cb); @@ -3483,8 +3453,7 @@ optionWindow::optionWindow(int deltaFontSize) {"Force Scalar", 0, nullptr, nullptr}, {"Force Vector", 0, nullptr, nullptr}, {"Force Tensor", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; view.choice[14] = new Fl_Choice(L + 2 * WB, 2 * WB + 10 * BH, IW, BH); view.choice[14]->tooltip("View.ForceNumComponents"); view.choice[14]->menu(menu_force_field_type); @@ -3662,9 +3631,9 @@ optionWindow::optionWindow(int deltaFontSize) view.choice[6]->align(FL_ALIGN_RIGHT); view.choice[6]->callback(view_options_ok_cb); - view.butt[26] = new Fl_Check_Button(L + width - (int)(0.85 * IW) - 2 * WB, - 2 * WB + 4 * BH, (int)(0.85 * IW), BH, - "Stipple"); + view.butt[26] = + new Fl_Check_Button(L + width - (int)(0.85 * IW) - 2 * WB, + 2 * WB + 4 * BH, (int)(0.85 * IW), BH, "Stipple"); view.butt[26]->tooltip("View.Stipple"); view.butt[26]->type(FL_TOGGLE_BUTTON); view.butt[26]->callback(view_options_ok_cb); @@ -3686,8 +3655,7 @@ optionWindow::optionWindow(int deltaFontSize) {"3D arrow", 0, nullptr, nullptr}, {"Displacement", 0, nullptr, nullptr}, {"Comet", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; view.choice[2] = new Fl_Choice(L + 2 * WB, 2 * WB + 6 * BH, IW, BH, "Vector display"); view.choice[2]->tooltip("View.VectorType"); @@ -3733,8 +3701,7 @@ optionWindow::optionWindow(int deltaFontSize) static Fl_Menu_Item menu_glyph_loc[] = { {"Barycenter", 0, nullptr, nullptr}, {"Node", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; view.choice[3] = new Fl_Choice(L + 2 * WB, 2 * WB + 10 * BH, IW, BH, "Glyph location"); view.choice[3]->tooltip("View.GlyphLocation"); @@ -3746,8 +3713,7 @@ optionWindow::optionWindow(int deltaFontSize) {"Left-aligned", 0, nullptr, nullptr}, {"Centered", 0, nullptr, nullptr}, {"Right-aligned", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; view.choice[15] = new Fl_Choice(L + width - (int)(0.85 * IW) - 2 * WB, 2 * WB + 10 * BH, (int)(0.85 * IW), BH); view.choice[15]->tooltip("View.CenterGlyphs"); @@ -3762,8 +3728,7 @@ optionWindow::optionWindow(int deltaFontSize) {"Ellipse", 0, nullptr, nullptr}, {"Ellipsoid", 0, nullptr, nullptr}, {"Frame", 0, nullptr, nullptr}, - {nullptr} - }; + {nullptr}}; view.choice[4] = new Fl_Choice(L + 2 * WB, 2 * WB + 11 * BH, IW, BH, "Tensor display"); view.choice[4]->tooltip("View.TensorType"); @@ -3832,7 +3797,7 @@ optionWindow::optionWindow(int deltaFontSize) (void *)ViewOptions_Color[j].function); i++; j++; - if(i >= view.color.size()){ + if(i >= view.color.size()) { Msg::Error("View color widget vector should be resized"); break; } @@ -4255,9 +4220,7 @@ void optionWindow::activate(const char *what) general.gamepadconfig->deactivate(); } - if(general.butt[17]->value() == 0) { - general.value[29]->deactivate(); - } + if(general.butt[17]->value() == 0) { general.value[29]->deactivate(); } else { general.value[29]->activate(); } @@ -4343,9 +4306,7 @@ void optionWindow::activate(const char *what) } } else if(!strcmp(what, "mesh_curvature")) { - if(mesh.butt[1]->value()) { - mesh.value[1]->activate(); - } + if(mesh.butt[1]->value()) { mesh.value[1]->activate(); } else { mesh.value[1]->deactivate(); } diff --git a/Fltk/outputRange.h b/Fltk/outputRange.h index 895bbf3587afba736422bf28426fd6b46ad4dbdc..1c3a265dd499820b60d885a02225a68fdf626592 100644 --- a/Fltk/outputRange.h +++ b/Fltk/outputRange.h @@ -141,10 +141,8 @@ public: void value(double val) { char buffer[256]; - if(_number_format.empty()) { - sprintf(buffer, "%g", val); - } - else{ + if(_number_format.empty()) { sprintf(buffer, "%g", val); } + else { if(_number_format.find("d") != std::string::npos || _number_format.find("u") != std::string::npos) sprintf(buffer, _number_format.c_str(), (int)val); diff --git a/Fltk/partitionDialog.cpp b/Fltk/partitionDialog.cpp index 15b4a31556513b0c5c6c001fe8a8244a2cec26ab..0aa3cf647927b295c1f22b11a7dab5e2e1a14ed4 100644 --- a/Fltk/partitionDialog.cpp +++ b/Fltk/partitionDialog.cpp @@ -210,19 +210,24 @@ void partition_dialog() { static PartitionDialog dlg; - static Fl_Menu_Item partitionTypeMenu[] = {{"Metis", 0, nullptr, nullptr}, {nullptr}}; + static Fl_Menu_Item partitionTypeMenu[] = {{"Metis", 0, nullptr, nullptr}, + {nullptr}}; - static Fl_Menu_Item metisAlgMenu[] = { - {"Recursive", 0, nullptr, nullptr}, {"K-way", 0, nullptr, nullptr}, {nullptr}}; + static Fl_Menu_Item metisAlgMenu[] = {{"Recursive", 0, nullptr, nullptr}, + {"K-way", 0, nullptr, nullptr}, + {nullptr}}; static Fl_Menu_Item metisEdgeMatchingMenu[] = { - {"Random", 0, nullptr, nullptr}, {"Sorted heavy-edge", 0, nullptr, nullptr}, {nullptr}}; - - static Fl_Menu_Item metisRefineAlgMenu[] = {{"FM-based cut", 0, nullptr, nullptr}, - {"Greedy", 0, nullptr, nullptr}, - {"Two-sided node FM", 0, nullptr, nullptr}, - {"One-sided node FM", 0, nullptr, nullptr}, - {nullptr}}; + {"Random", 0, nullptr, nullptr}, + {"Sorted heavy-edge", 0, nullptr, nullptr}, + {nullptr}}; + + static Fl_Menu_Item metisRefineAlgMenu[] = { + {"FM-based cut", 0, nullptr, nullptr}, + {"Greedy", 0, nullptr, nullptr}, + {"Two-sided node FM", 0, nullptr, nullptr}, + {"One-sided node FM", 0, nullptr, nullptr}, + {nullptr}}; // This will be resized based on groups that are displayed const int h = 8 * WB + 5 * BH + 4; diff --git a/Fltk/pluginWindow.cpp b/Fltk/pluginWindow.cpp index b79ef2b35431769db9980310afaebbf56943ba99..913bd83d67c5d422c9230bb8aa270183aa2e3869 100644 --- a/Fltk/pluginWindow.cpp +++ b/Fltk/pluginWindow.cpp @@ -138,9 +138,7 @@ static void add_scripting(GMSH_PostPlugin *p, PView *view) fileName += ".opt"; FILE *fp = Fopen(fileName.c_str(), "a"); - if(!fp) { - Msg::Error("Could not open file '%s'", fileName.c_str()); - } + if(!fp) { Msg::Error("Could not open file '%s'", fileName.c_str()); } else { fprintf(fp, "%s", p->serialize().c_str()); fclose(fp); @@ -327,8 +325,7 @@ pluginWindow::pluginWindow(int deltaFontSize) view_browser->callback(plugin_browser_cb); view_browser->box(GMSH_SIMPLE_RIGHT_BOX); - for(auto it = - PluginManager::instance()->begin(); + for(auto it = PluginManager::instance()->begin(); it != PluginManager::instance()->end(); ++it) { GMSH_Plugin *p = it->second; if(p->getType() == GMSH_Plugin::GMSH_POST_PLUGIN || diff --git a/Fltk/solverButton.cpp b/Fltk/solverButton.cpp index fea328a8ef34c34c0e2803aa7c7a2078a5374ddc..9891c0ba98fd0880c43a00824f11c3b54e0e28be 100644 --- a/Fltk/solverButton.cpp +++ b/Fltk/solverButton.cpp @@ -80,9 +80,7 @@ static void solver_remove_cb(Fl_Widget *w, void *data) opt_solver_remote_login(num, GMSH_SET, ""); auto it = onelab::server::instance()->findClient(name); - if(it != onelab::server::instance()->lastClient()) { - delete *it; - } + if(it != onelab::server::instance()->lastClient()) { delete *it; } FlGui::instance()->onelab->rebuildSolverList(); } diff --git a/Fltk/statisticsWindow.cpp b/Fltk/statisticsWindow.cpp index 16586b6f213a94e3dff0e8ea6f3b87a6b3d809ee..475e8ea77e5ce232cc7ce807b7a78b529d772b75 100644 --- a/Fltk/statisticsWindow.cpp +++ b/Fltk/statisticsWindow.cpp @@ -82,10 +82,10 @@ static void statistics_histogram_cb(Fl_Widget *w, void *data) d[e->getNum()].push_back(e->minSIGEShapeMeasure()); } } - std::string name = - (qmh == QMH_SICN_3D) ? - "SICN" : - (qmh == QMH_GAMMA_3D) ? "Gamma" : (qmh == QMH_SIGE_3D) ? "SIGE" : ""; + std::string name = (qmh == QMH_SICN_3D) ? "SICN" : + (qmh == QMH_GAMMA_3D) ? "Gamma" : + (qmh == QMH_SIGE_3D) ? "SIGE" : + ""; new PView(name, "ElementData", GModel::current(), d); } @@ -174,8 +174,9 @@ statisticsWindow::statisticsWindow(int deltaFontSize) butt[4]->callback(statistics_histogram_cb, (void *)&qmh4); butt[5]->callback(statistics_histogram_cb, (void *)&qmh5); - visible = new Fl_Check_Button(2 * WB, 2 * WB + 17 * BH + WB, width - 4 * WB, - BH, "Compute statistics for visible entities only"); + visible = + new Fl_Check_Button(2 * WB, 2 * WB + 17 * BH + WB, width - 4 * WB, BH, + "Compute statistics for visible entities only"); group[1]->end(); } diff --git a/Fltk/treeIcons.h b/Fltk/treeIcons.h index 7cc2ba9ba926c552e5669085d31a4dd4981bebf1..03407f4444432334e669fbe97d225c8d5781b119 100644 --- a/Fltk/treeIcons.h +++ b/Fltk/treeIcons.h @@ -24,7 +24,7 @@ "#....@....#", "#....@....#", "#.........#", "#.........#", "###########" #define TREE_ICON_MINUS(col) \ - "11 11 3 1", col, "# c #323232", "@ c #000000", "###########", \ + "11 11 3 1", col, "# c #323232", "@ c #000000", "###########", \ "#.........#", "#.........#", "#.........#", "#.........#", "#..@@@@@..#", \ "#.........#", "#.........#", "#.........#", "#.........#", "###########" diff --git a/Fltk/viewButton.cpp b/Fltk/viewButton.cpp index e78e2b1400b1b919d8225036fbbf504f197999e7..85c3bb8c51e78cb2bc9f10ca926640b49c6ddfab 100644 --- a/Fltk/viewButton.cpp +++ b/Fltk/viewButton.cpp @@ -158,7 +158,7 @@ static void view_save_cb(Fl_Widget *w, void *data) "MED\t*.rmed\nSTL Surface\t*.stl\nGeneric TXT\t*.txt\n"; PView *view = PView::list[(intptr_t)data]; - test: +test: if(fileChooser(FILE_CHOOSER_CREATE, "Export", formats, view->getData()->getFileName().c_str())) { std::string name = fileChooserGetName(1); @@ -253,7 +253,8 @@ static void view_all_visible_cb(Fl_Widget *w, void *data) (mode == -1) ? 1 : (mode == -2) ? 0 : (mode == -3) ? !opt_view_visible(i, GMSH_GET, 0) : - (name == PView::list[i]->getData()->getName()) ? 1 : 0); + (name == PView::list[i]->getData()->getName()) ? 1 : + 0); drawContext::global()->draw(); } @@ -323,7 +324,8 @@ viewButton::viewButton(int x, int y, int w, int h, int num, Fl_Color col) _popup->add("Remove Views/With Same Name", 0, (Fl_Callback *)view_remove_all_cb, (void *)(intptr_t)num, 0); - _popup->add("Sort By Name", 0, (Fl_Callback *)view_sort_cb, (void *)nullptr, 0); + _popup->add("Sort By Name", 0, (Fl_Callback *)view_sort_cb, (void *)nullptr, + 0); _popup->add("Set Visibility/All On", 0, (Fl_Callback *)view_all_visible_cb, (void *)-1, 0); _popup->add("Set Visibility/All Off", 0, (Fl_Callback *)view_all_visible_cb, diff --git a/Fltk/visibilityWindow.cpp b/Fltk/visibilityWindow.cpp index 5957a433027442c15bbea44c8b76bf659556f3e8..561f747c7c825b582c4f32d9187acd984cfa14d7 100644 --- a/Fltk/visibilityWindow.cpp +++ b/Fltk/visibilityWindow.cpp @@ -238,13 +238,19 @@ public: { switch(instance()->getSortMode()) { case 1: - if(v1->getDim() < v2->getDim()) return true; - else if(v1->getDim() > v2->getDim()) return false; - else return v1->getTag() < v2->getTag(); + if(v1->getDim() < v2->getDim()) + return true; + else if(v1->getDim() > v2->getDim()) + return false; + else + return v1->getTag() < v2->getTag(); case -1: - if(v1->getDim() > v2->getDim()) return true; - else if(v1->getDim() < v2->getDim()) return false; - else return v1->getTag() < v2->getTag(); + if(v1->getDim() > v2->getDim()) + return true; + else if(v1->getDim() < v2->getDim()) + return false; + else + return v1->getTag() < v2->getTag(); case 2: return v1->getTag() < v2->getTag() ? true : false; case -2: return v1->getTag() > v2->getTag() ? true : false; case 3: @@ -261,9 +267,7 @@ public: { std::map<int, std::string> oldLabels; #if defined(HAVE_PARSER) - for(auto it = - gmsh_yysymbols.begin(); - it != gmsh_yysymbols.end(); ++it) + for(auto it = gmsh_yysymbols.begin(); it != gmsh_yysymbols.end(); ++it) if(it->first.size()) for(std::size_t i = 0; i < it->second.value.size(); i++) oldLabels[(int)it->second.value[i]] = @@ -560,8 +564,7 @@ static void _add_face(GFace *gf, Fl_Tree *tree, const std::string &path) n->user_data((void *)gf); n->close(); std::vector<GEdge *> const &edges = gf->edges(); - for(auto it = edges.begin(); - it != edges.end(); it++) + for(auto it = edges.begin(); it != edges.end(); it++) _add_edge(*it, tree, face.str()); } @@ -578,8 +581,7 @@ static void _add_region(GRegion *gr, Fl_Tree *tree, const std::string &path) n->user_data((void *)gr); n->close(); std::vector<GFace *> faces = gr->faces(); - for(auto it = faces.begin(); it != faces.end(); - it++) + for(auto it = faces.begin(); it != faces.end(); it++) _add_face(*it, tree, region.str()); } @@ -683,18 +685,14 @@ static void _rebuild_tree_browser(bool force) m->getPhysicalGroups(groups); std::map<int, std::string> oldLabels; #if defined(HAVE_PARSER) - for(auto it = - gmsh_yysymbols.begin(); - it != gmsh_yysymbols.end(); ++it) + for(auto it = gmsh_yysymbols.begin(); it != gmsh_yysymbols.end(); ++it) if(it->first.size()) for(std::size_t i = 0; i < it->second.value.size(); i++) oldLabels[(int)it->second.value[i]] = std::string("(") + it->first + ")"; #endif for(int i = 3; i >= 0; i--) - for(auto it = - groups[i].begin(); - it != groups[i].end(); it++) + for(auto it = groups[i].begin(); it != groups[i].end(); it++) _add_physical_group(i, it->first, it->second, oldLabels, FlGui::instance()->visibility->tree, physical); } @@ -1212,23 +1210,21 @@ static void browser_cb(Fl_Widget *w, void *data) static void tree_cb(Fl_Widget *w, void *data) { -#if (FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION >= 4) +#if(FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION >= 4) Fl_Tree *tree = (Fl_Tree *)w; - if(tree->callback_reason() == FL_TREE_REASON_RESELECTED && Fl::event_clicks()) { + if(tree->callback_reason() == FL_TREE_REASON_RESELECTED && + Fl::event_clicks()) { // double click Fl_Tree_Item *item = (Fl_Tree_Item *)tree->callback_item(); GEntity *ge = nullptr; if(item) { - if(item->user_data()) { - ge = (GEntity*)item->user_data(); - } + if(item->user_data()) { ge = (GEntity *)item->user_data(); } else if(item->children() && item->child(0) && item->child(0)->user_data()) { - ge = (GEntity*)item->child(0)->user_data(); + ge = (GEntity *)item->child(0)->user_data(); } } - if(ge) - FlGui::instance()->onelabContext->show(ge->dim(), ge->tag()); + if(ge) FlGui::instance()->onelabContext->show(ge->dim(), ge->tag()); } #endif } @@ -1358,7 +1354,7 @@ visibilityWindow::visibilityWindow(int deltaFontSize) tree->labelsize(FL_NORMAL_SIZE - 1); tree->selectmode(FL_TREE_SELECT_MULTI); tree->connectorstyle(FL_TREE_CONNECTOR_SOLID); -#if (FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION >= 4) +#if(FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION >= 4) tree->item_reselect_mode(FL_TREE_SELECTABLE_ALWAYS); // for double-clicks #endif tree->callback(tree_cb); diff --git a/Mesh/BDS.h b/Mesh/BDS.h index 78df29c80607cc90e4caad4e40fdeea16cce98a7..8e19c2e872a987c33e69849079424dba42ed6a34 100644 --- a/Mesh/BDS.h +++ b/Mesh/BDS.h @@ -113,8 +113,8 @@ public: { if(p1 == other->p1 || p1 == other->p2) return p1; if(p2 == other->p1 || p2 == other->p2) return p2; - Msg::Error("Edge %d %d has no common node with edge %d %d", - p1->iD, p2->iD, other->p1->iD, other->p2->iD); + Msg::Error("Edge %d %d has no common node with edge %d %d", p1->iD, p2->iD, + other->p1->iD, other->p2->iD); return nullptr; } BDS_Point *othervertex(const BDS_Point *p) const @@ -125,7 +125,7 @@ public: return nullptr; } void addface(BDS_Face *f) { _faces.push_back(f); } - bool operator < (const BDS_Edge &other) const + bool operator<(const BDS_Edge &other) const { if(*other.p1 < *p1) return true; if(*p1 < *other.p1) return false; @@ -135,8 +135,8 @@ public: BDS_Face *otherFace(const BDS_Face *f) const { if(numfaces() != 2) { - Msg::Error("%d face(s) attached to edge %d %d", numfaces(), - p1->iD, p2->iD); + Msg::Error("%d face(s) attached to edge %d %d", numfaces(), p1->iD, + p2->iD); return nullptr; } if(f == _faces[0]) return _faces[1]; @@ -154,6 +154,7 @@ public: void oppositeof(BDS_Point *oface[2]) const; void computeNeighborhood(BDS_Point *oface[2], BDS_Point *t1[4], BDS_Point *t2[4]) const; + public: bool deleted; BDS_Point *p1, *p2; diff --git a/Mesh/DivideAndConquer.h b/Mesh/DivideAndConquer.h index ecf02dd9f79e4b26bc0c17d7c38919b3b178e90e..bb07863c9fce38137358a9914453e11f35c92ac0 100644 --- a/Mesh/DivideAndConquer.h +++ b/Mesh/DivideAndConquer.h @@ -109,8 +109,8 @@ public: return std::binary_search(_hull, _hull + _hullSize, i); } void makePosView(const std::string &, GFace *gf = nullptr); - void printMedialAxis(Octree *_octree, const std::string &, GFace *gf = nullptr, - GEdge *ge = nullptr); + void printMedialAxis(Octree *_octree, const std::string &, + GFace *gf = nullptr, GEdge *ge = nullptr); void voronoiCell(PointNumero pt, std::vector<SPoint2> &pts) const; std::set<std::pair<void *, void *> > boundaryEdges; @@ -125,8 +125,7 @@ public: { void *a = (p1 < p2) ? p1 : p2; void *b = (p1 > p2) ? p1 : p2; - auto it = - boundaryEdges.find(std::make_pair(a, b)); + auto it = boundaryEdges.find(std::make_pair(a, b)); return it != boundaryEdges.end(); } @@ -155,8 +154,7 @@ public: { void *a = (p1 < p2) ? p1 : p2; void *b = (p1 > p2) ? p1 : p2; - auto it = - mesh_edges.find(std::make_pair(a, b)); + auto it = mesh_edges.find(std::make_pair(a, b)); return it != mesh_edges.end(); } diff --git a/Mesh/Field.h b/Mesh/Field.h index b800a9384ada8ef052be816afe484c9f39a01f4e..257363548c43c19fd3dd3b9c1387def12f69c4d3 100644 --- a/Mesh/Field.h +++ b/Mesh/Field.h @@ -110,7 +110,8 @@ public: std::map<std::string, FieldCallback *> callbacks; virtual bool isotropic() const { return true; } // isotropic - virtual double operator()(double x, double y, double z, GEntity *ge = nullptr) = 0; + virtual double operator()(double x, double y, double z, + GEntity *ge = nullptr) = 0; // anisotropic virtual void operator()(double x, double y, double z, SMetric3 &, GEntity *ge = nullptr) @@ -200,7 +201,8 @@ public: virtual std::string getDescription(); BoundaryLayerField(); ~BoundaryLayerField() { removeAttractors(); } - virtual double operator()(double x, double y, double z, GEntity *ge = nullptr); + virtual double operator()(double x, double y, double z, + GEntity *ge = nullptr); virtual void operator()(double x, double y, double z, SMetric3 &metr, GEntity *ge = nullptr); bool isEdgeBL(int iE) const @@ -237,8 +239,7 @@ public: } double hWall(int iV) { - for(auto it = _hWallNNodes.begin(); - it != _hWallNNodes.end(); ++it) { + for(auto it = _hWallNNodes.begin(); it != _hWallNNodes.end(); ++it) { int i = (int)*it; ++it; double h = *it; @@ -279,8 +280,8 @@ class FieldOptionDouble : public FieldOption { public: double &val; FieldOptionType getType() { return FIELD_OPTION_DOUBLE; } - FieldOptionDouble(double &_val, const std::string &help, bool *status = nullptr, - bool deprecated = false) + FieldOptionDouble(double &_val, const std::string &help, + bool *status = nullptr, bool deprecated = false) : FieldOption(help, status, deprecated), val(_val) { } @@ -382,8 +383,8 @@ public: class FieldOptionPath : public FieldOptionString { public: virtual FieldOptionType getType() { return FIELD_OPTION_PATH; } - FieldOptionPath(std::string &val, const std::string &help, bool *status = nullptr, - bool deprecated = false) + FieldOptionPath(std::string &val, const std::string &help, + bool *status = nullptr, bool deprecated = false) : FieldOptionString(val, help, status, deprecated) { } @@ -447,7 +448,8 @@ public: GenericField(); ~GenericField(); using Field::operator(); - virtual double operator()(double x, double y, double z, GEntity *ge = nullptr); + virtual double operator()(double x, double y, double z, + GEntity *ge = nullptr); virtual const char *getName() { return "GenericField"; }; // sets the callbacks diff --git a/Mesh/automaticMeshSizeField.h b/Mesh/automaticMeshSizeField.h index 79bb692403784f224913d1aa6a6dad25d66860de..27d79c0237e5f108b71db55ca208623fb44d33a4 100644 --- a/Mesh/automaticMeshSizeField.h +++ b/Mesh/automaticMeshSizeField.h @@ -206,7 +206,8 @@ public: } void update(); - virtual double operator()(double X, double Y, double Z, GEntity *ge = nullptr); + virtual double operator()(double X, double Y, double Z, + GEntity *ge = nullptr); virtual void operator()(double x, double y, double z, SMetric3 &m, GEntity *ge = nullptr); }; diff --git a/Mesh/delaunay3d.h b/Mesh/delaunay3d.h index 625118c45d8413506973334bfd43e5ded1fcfe9e..c1ba9a9c8a1a2754752f59c629e8318221742d4c 100644 --- a/Mesh/delaunay3d.h +++ b/Mesh/delaunay3d.h @@ -9,11 +9,10 @@ class MVertex; class MTetrahedron; -// tetrahedralize the vertices given in S; adds 8 new vertices at the end of S (the -// corners of an enclosing box) +// tetrahedralize the vertices given in S; adds 8 new vertices at the end of S +// (the corners of an enclosing box) void delaunayTriangulation(const int numThreads, const int nptsatonce, std::vector<MVertex *> &S, - std::vector<MTetrahedron *> &T, - bool removeBox); + std::vector<MTetrahedron *> &T, bool removeBox); #endif diff --git a/Mesh/gmshCrossFields.cpp b/Mesh/gmshCrossFields.cpp index 573e2e639036b1eee05f2646b747ecf07f6f4ccb..55d1310d908d6ac3804ca9fd74775c2c5c01419a 100644 --- a/Mesh/gmshCrossFields.cpp +++ b/Mesh/gmshCrossFields.cpp @@ -1589,7 +1589,7 @@ groupBoundaries(GModel *gm, std::map<MEdge, cross2d, MEdgeLessThan> &C, singularities.find(v) != singularities.end()) { // printf("START POINT %lu %d %d\n",v->getNum(),cutgraph.find(v) //!= cutgraph.end() , singularities.find(v) != - //!singularities.end()); + //! singularities.end()); std::vector<cross2d *> group; do { MVertex *vnew = nullptr; diff --git a/Mesh/meshGFace.h b/Mesh/meshGFace.h index 3a643750deac46f14ed7200d73ae5930f1576719..19817ef9604bb30a5e83bde5b0cc04642f2399bf 100644 --- a/Mesh/meshGFace.h +++ b/Mesh/meshGFace.h @@ -48,7 +48,8 @@ void fourthPoint(double *p1, double *p2, double *p3, double *p4); void findTransfiniteCorners(GFace *gf, std::vector<MVertex *> &corners); int MeshTransfiniteSurface(GFace *gf); int MeshExtrudedSurface( - GFace *gf, std::set<std::pair<MVertex *, MVertex *> > *constrainedEdges = nullptr); + GFace *gf, + std::set<std::pair<MVertex *, MVertex *> > *constrainedEdges = nullptr); bool meshGenerator(GFace *gf, int RECUR_ITER, bool repairSelfIntersecting1dMesh, bool onlyInitialMesh, bool debug = true, std::vector<GEdge *> *replacement_edges = nullptr); diff --git a/Mesh/meshGFaceDelaunayInsertion.h b/Mesh/meshGFaceDelaunayInsertion.h index c2769a0afa66278216f6bdd94d7ba9440c0f80b1..5f9e33923e8813ff6f0b113a494e89f17fbfe578 100644 --- a/Mesh/meshGFaceDelaunayInsertion.h +++ b/Mesh/meshGFaceDelaunayInsertion.h @@ -37,8 +37,7 @@ struct bidimMeshData { else indices[mv] = index; if(parametricCoordinates) { - auto it = - parametricCoordinates->find(mv); + auto it = parametricCoordinates->find(mv); if(it != parametricCoordinates->end()) { u = it->second.x(); v = it->second.y(); @@ -100,8 +99,8 @@ public: return n->tri()->getVertex(j); return nullptr; } - MTri3(MTriangle *t, double lc, SMetric3 *m = nullptr, bidimMeshData *data = nullptr, - GFace *gf = nullptr); + MTri3(MTriangle *t, double lc, SMetric3 *m = nullptr, + bidimMeshData *data = nullptr, GFace *gf = nullptr); inline void setTri(MTriangle *t) { base = t; } inline MTriangle *tri() const { return base; } inline void setNeigh(int iN, MTri3 *n) { neigh[iN] = n; } @@ -147,9 +146,10 @@ public: void connectTriangles(std::list<MTri3 *> &); void connectTriangles(std::vector<MTri3 *> &); void connectTriangles(std::set<MTri3 *, compareTri3Ptr> &AllTris); -void bowyerWatson(GFace *gf, int MAXPNT = 1000000000, - std::map<MVertex *, MVertex *> *equivalence = nullptr, - std::map<MVertex *, SPoint2> *parametricCoordinates = nullptr); +void bowyerWatson( + GFace *gf, int MAXPNT = 1000000000, + std::map<MVertex *, MVertex *> *equivalence = nullptr, + std::map<MVertex *, SPoint2> *parametricCoordinates = nullptr); void bowyerWatsonFrontal( GFace *gf, std::map<MVertex *, MVertex *> *equivalence = nullptr, std::map<MVertex *, SPoint2> *parametricCoordinates = nullptr, diff --git a/Mesh/meshGFaceOptimize.h b/Mesh/meshGFaceOptimize.h index 489e5cae1f582e5d0a9a7d8f56320902117cd34e..90e1922e5802dd761d78baf145b103c43e151f8b 100644 --- a/Mesh/meshGFaceOptimize.h +++ b/Mesh/meshGFaceOptimize.h @@ -26,10 +26,12 @@ struct edge_angle { }; // TODO: switch to unordered_map here & verify deterministic bahavior -typedef std::map<MVertex *, std::vector<MElement *>, MVertexPtrLessThan> v2t_cont; -//typedef std::unordered_map<MVertex *, std::vector<MElement *> > v2t_cont; +typedef std::map<MVertex *, std::vector<MElement *>, MVertexPtrLessThan> + v2t_cont; +// typedef std::unordered_map<MVertex *, std::vector<MElement *> > v2t_cont; -typedef std::map<MEdge, std::pair<MElement *, MElement *>, MEdgeLessThan> e2t_cont; +typedef std::map<MEdge, std::pair<MElement *, MElement *>, MEdgeLessThan> + e2t_cont; template <class T> void buildVertexToElement(std::vector<T *> const &elements, v2t_cont &adj) diff --git a/Mesh/meshGRegion.h b/Mesh/meshGRegion.h index 82b70bb797f91fc297af1bdf57904b22600ac72e..8c55c16615fdda4b5e212229ba3c6a64f30cb344 100644 --- a/Mesh/meshGRegion.h +++ b/Mesh/meshGRegion.h @@ -64,7 +64,8 @@ GFace *findInFaceSearchStructure(MVertex *p1, MVertex *p2, MVertex *p3, GFace *findInFaceSearchStructure(const MFace &f, const fs_cont &search); GEdge *findInEdgeSearchStructure(MVertex *p1, MVertex *p2, const es_cont &search); -bool buildFaceSearchStructure(GModel *model, fs_cont &search, bool onlyTriangles = false); +bool buildFaceSearchStructure(GModel *model, fs_cont &search, + bool onlyTriangles = false); bool buildEdgeSearchStructure(GModel *model, es_cont &search); // hybrid mesh recovery structure @@ -72,6 +73,7 @@ class splitQuadRecovery { private: std::map<MFace, MVertex *, MFaceLessThan> _quad; std::map<MFace, GFace *, MFaceLessThan> _tri; + public: splitQuadRecovery() {} void add(const MFace &f, MVertex *v, GFace *gf); diff --git a/Mesh/meshGRegionBoundaryRecovery.cpp b/Mesh/meshGRegionBoundaryRecovery.cpp index 482df260ac66f3d375316673e5bf92e03eb095ff..1e59729de3bb0652d0a8309219003dae328200a1 100644 --- a/Mesh/meshGRegionBoundaryRecovery.cpp +++ b/Mesh/meshGRegionBoundaryRecovery.cpp @@ -65,7 +65,7 @@ namespace tetgenBR { #define REAL double - struct brdata{ + struct brdata { GRegion *gr; splitQuadRecovery *sqr; }; @@ -157,8 +157,7 @@ namespace tetgenBR { { std::set<MVertex *, MVertexPtrLessThan> all; std::vector<GFace *> const &f = _gr->faces(); - for(auto it = f.begin(); it != f.end(); - ++it) { + for(auto it = f.begin(); it != f.end(); ++it) { GFace *gf = *it; for(std::size_t i = 0; i < gf->triangles.size(); i++) { MVertex *v0 = gf->triangles[i]->getVertex(0); @@ -168,16 +167,16 @@ namespace tetgenBR { all.insert(v1); all.insert(v2); } - if(_sqr){ + if(_sqr) { for(std::size_t i = 0; i < gf->quadrangles.size(); i++) { MVertex *v0 = gf->quadrangles[i]->getVertex(0); MVertex *v1 = gf->quadrangles[i]->getVertex(1); MVertex *v2 = gf->quadrangles[i]->getVertex(2); MVertex *v3 = gf->quadrangles[i]->getVertex(3); - MVertex *newv = new MVertex - ((v0->x() + v1->x() + v2->x() + v3->x()) * 0.25, - (v0->y() + v1->y() + v2->y() + v3->y()) * 0.25, - (v0->z() + v1->z() + v2->z() + v3->z()) * 0.25, gf); + MVertex *newv = + new MVertex((v0->x() + v1->x() + v2->x() + v3->x()) * 0.25, + (v0->y() + v1->y() + v2->y() + v3->y()) * 0.25, + (v0->z() + v1->z() + v2->z() + v3->z()) * 0.25, gf); // the extra vertex will be added in a GRegion (and reclassified // correctly on that GRegion) when the pyramid is generated MFace mf = gf->quadrangles[i]->getFace(0); @@ -191,8 +190,7 @@ namespace tetgenBR { } } std::vector<GEdge *> const &e = _gr->embeddedEdges(); - for(auto it = e.begin(); it != e.end(); - ++it) { + for(auto it = e.begin(); it != e.end(); ++it) { GEdge *ge = *it; for(std::size_t i = 0; i < ge->lines.size(); i++) { all.insert(ge->lines[i]->getVertex(0)); @@ -200,8 +198,7 @@ namespace tetgenBR { } } std::vector<GVertex *> const &v = _gr->embeddedVertices(); - for(auto it = v.begin(); it != v.end(); - ++it) { + for(auto it = v.begin(); it != v.end(); ++it) { GVertex *gv = *it; for(std::size_t i = 0; i < gv->points.size(); i++) { all.insert(gv->points[i]->getVertex(0)); @@ -224,7 +221,8 @@ namespace tetgenBR { std::vector<MTetrahedron *> tets; - delaunayMeshIn3D(_vertices, tets); // will add 8 MVertices at the end of _vertices + delaunayMeshIn3D(_vertices, + tets); // will add 8 MVertices at the end of _vertices if(Msg::GetErrorCount()) return false; Msg::Debug("Points have been tetrahedralized"); @@ -267,9 +265,7 @@ namespace tetgenBR { } // Two identical points are distinguished by 'lengthlimit'. - if(minedgelength == 0.0) { - minedgelength = longest * b->epsilon; - } + if(minedgelength == 0.0) { minedgelength = longest * b->epsilon; } } point *idx2verlist; @@ -304,8 +300,6 @@ namespace tetgenBR { ver2tetarray[i] = nullptr; } - - #if 0 /* N E W V E R S I O N */ std::vector<triface> ts( tets.size() ); @@ -495,375 +489,367 @@ namespace tetgenBR { } #endif - std::vector<GFace *> const &f_list = _gr->faces(); - std::vector<GEdge *> const &e_list = _gr->embeddedEdges(); + std::vector<GFace *> const &f_list = _gr->faces(); + std::vector<GEdge *> const &e_list = _gr->embeddedEdges(); - { - Msg::Info(" - Creating surface mesh"); - face newsh; - face newseg; - point p[4]; - int idx; - - for(auto it = f_list.begin(); - it != f_list.end(); ++it) { - GFace *gf = *it; - for(std::size_t i = 0; i < gf->triangles.size(); i++) { - for(int j = 0; j < 3; j++) { - p[j] = idx2verlist[gf->triangles[i]->getVertex(j)->getIndex()]; - if(pointtype(p[j]) == VOLVERTEX) { - setpointtype(p[j], FACETVERTEX); + { + Msg::Info(" - Creating surface mesh"); + face newsh; + face newseg; + point p[4]; + int idx; + + for(auto it = f_list.begin(); it != f_list.end(); ++it) { + GFace *gf = *it; + for(std::size_t i = 0; i < gf->triangles.size(); i++) { + for(int j = 0; j < 3; j++) { + p[j] = idx2verlist[gf->triangles[i]->getVertex(j)->getIndex()]; + if(pointtype(p[j]) == VOLVERTEX) { + setpointtype(p[j], FACETVERTEX); + } } - } - makeshellface(subfaces, &newsh); - setshvertices(newsh, p[0], p[1], p[2]); - setshellmark(newsh, gf->tag()); // the GFace's tag. - recentsh = newsh; - for(int j = 0; j < 3; j++) { - makeshellface(subsegs, &newseg); - setshvertices(newseg, sorg(newsh), sdest(newsh), nullptr); - // Set the default segment marker '-1'. - setshellmark(newseg, -1); - ssbond(newsh, newseg); - senextself(newsh); - } - } - } // it - - if(_sqr){ - std::map<MFace, GFace *, MFaceLessThan> f = _sqr->getTri(); - for(auto it = f.begin(); - it != f.end(); it++){ - const MFace &mf = it->first; - for(int j = 0; j < 3; j++) { - p[j] = idx2verlist[mf.getVertex(j)->getIndex()]; - if(pointtype(p[j]) == VOLVERTEX) { - setpointtype(p[j], FACETVERTEX); + makeshellface(subfaces, &newsh); + setshvertices(newsh, p[0], p[1], p[2]); + setshellmark(newsh, gf->tag()); // the GFace's tag. + recentsh = newsh; + for(int j = 0; j < 3; j++) { + makeshellface(subsegs, &newseg); + setshvertices(newseg, sorg(newsh), sdest(newsh), nullptr); + // Set the default segment marker '-1'. + setshellmark(newseg, -1); + ssbond(newsh, newseg); + senextself(newsh); } } - makeshellface(subfaces, &newsh); - setshvertices(newsh, p[0], p[1], p[2]); - setshellmark(newsh, it->second->tag()); - recentsh = newsh; - for(int j = 0; j < 3; j++) { - makeshellface(subsegs, &newseg); - setshvertices(newseg, sorg(newsh), sdest(newsh), nullptr); - // Set the default segment marker '-1'. - setshellmark(newseg, -1); - ssbond(newsh, newseg); - senextself(newsh); + } // it + + if(_sqr) { + std::map<MFace, GFace *, MFaceLessThan> f = _sqr->getTri(); + for(auto it = f.begin(); it != f.end(); it++) { + const MFace &mf = it->first; + for(int j = 0; j < 3; j++) { + p[j] = idx2verlist[mf.getVertex(j)->getIndex()]; + if(pointtype(p[j]) == VOLVERTEX) { + setpointtype(p[j], FACETVERTEX); + } + } + makeshellface(subfaces, &newsh); + setshvertices(newsh, p[0], p[1], p[2]); + setshellmark(newsh, it->second->tag()); + recentsh = newsh; + for(int j = 0; j < 3; j++) { + makeshellface(subsegs, &newseg); + setshvertices(newseg, sorg(newsh), sdest(newsh), nullptr); + // Set the default segment marker '-1'. + setshellmark(newseg, -1); + ssbond(newsh, newseg); + senextself(newsh); + } } } - } - - // Connecting triangles, removing redundant segments. - unifysegments(); - - Msg::Info(" - Identifying boundary edges"); - - face *shperverlist; - int *idx2shlist; - face searchsh, neighsh; - face segloop, checkseg; - point checkpt; - // Construct a map from points to subfaces. - makepoint2submap(subfaces, idx2shlist, shperverlist); - - // Process the set of PSC edges. - // Remeber that all segments have default marker '-1'. - // int COUNTER = 0; - for(auto it = e_list.begin(); - it != e_list.end(); ++it) { - GEdge *ge = *it; - for(std::size_t i = 0; i < ge->lines.size(); i++) { - for(int j = 0; j < 2; j++) { - p[j] = idx2verlist[ge->lines[i]->getVertex(j)->getIndex()]; - setpointtype(p[j], RIDGEVERTEX); - } - if(p[0] == p[1]) { - // This is a potential problem in surface mesh. - continue; // Skip this edge. - } - // Find a face contains the edge p[0], p[1]. - newseg.sh = nullptr; - searchsh.sh = nullptr; - idx = pointmark(p[0]) - in->firstnumber; - for(int j = idx2shlist[idx]; j < idx2shlist[idx + 1]; j++) { - checkpt = sdest(shperverlist[j]); - if(checkpt == p[1]) { - searchsh = shperverlist[j]; - break; // Found. + // Connecting triangles, removing redundant segments. + unifysegments(); + + Msg::Info(" - Identifying boundary edges"); + + face *shperverlist; + int *idx2shlist; + face searchsh, neighsh; + face segloop, checkseg; + point checkpt; + + // Construct a map from points to subfaces. + makepoint2submap(subfaces, idx2shlist, shperverlist); + + // Process the set of PSC edges. + // Remeber that all segments have default marker '-1'. + // int COUNTER = 0; + for(auto it = e_list.begin(); it != e_list.end(); ++it) { + GEdge *ge = *it; + for(std::size_t i = 0; i < ge->lines.size(); i++) { + for(int j = 0; j < 2; j++) { + p[j] = idx2verlist[ge->lines[i]->getVertex(j)->getIndex()]; + setpointtype(p[j], RIDGEVERTEX); } - else { - checkpt = sapex(shperverlist[j]); + if(p[0] == p[1]) { + // This is a potential problem in surface mesh. + continue; // Skip this edge. + } + // Find a face contains the edge p[0], p[1]. + newseg.sh = nullptr; + searchsh.sh = nullptr; + idx = pointmark(p[0]) - in->firstnumber; + for(int j = idx2shlist[idx]; j < idx2shlist[idx + 1]; j++) { + checkpt = sdest(shperverlist[j]); if(checkpt == p[1]) { - senext2(shperverlist[j], searchsh); - sesymself(searchsh); - break; + searchsh = shperverlist[j]; + break; // Found. } - } - } // j - if(searchsh.sh != nullptr) { - // Check if this edge is already a segment of the mesh. - sspivot(searchsh, checkseg); - if(checkseg.sh != nullptr) { - // This segment already exist. - newseg = checkseg; - } - else { - // Create a new segment at this edge. - makeshellface(subsegs, &newseg); - setshvertices(newseg, p[0], p[1], nullptr); - ssbond(searchsh, newseg); - spivot(searchsh, neighsh); - if(neighsh.sh != nullptr) { - ssbond(neighsh, newseg); + else { + checkpt = sapex(shperverlist[j]); + if(checkpt == p[1]) { + senext2(shperverlist[j], searchsh); + sesymself(searchsh); + break; + } } - } - } - else { - // It is a dangling segment (not belong to any facets). - // Check if segment [p[0],p[1]] already exists. - // TODO: Change the brute-force search. Slow! - /* point *ppt; - subsegs->traversalinit(); - segloop.sh = shellfacetraverse(subsegs); - while (segloop.sh != nullptr){ - ppt = (point *) &(segloop.sh[3]); - if(((ppt[0] == p[0]) && (ppt[1] == p[1])) || - ((ppt[0] == p[1]) && (ppt[1] == p[0]))){ - // Found! - newseg = segloop; - break; + } // j + if(searchsh.sh != nullptr) { + // Check if this edge is already a segment of the mesh. + sspivot(searchsh, checkseg); + if(checkseg.sh != nullptr) { + // This segment already exist. + newseg = checkseg; } + else { + // Create a new segment at this edge. + makeshellface(subsegs, &newseg); + setshvertices(newseg, p[0], p[1], nullptr); + ssbond(searchsh, newseg); + spivot(searchsh, neighsh); + if(neighsh.sh != nullptr) { ssbond(neighsh, newseg); } + } + } + else { + // It is a dangling segment (not belong to any facets). + // Check if segment [p[0],p[1]] already exists. + // TODO: Change the brute-force search. Slow! + /* point *ppt; + subsegs->traversalinit(); segloop.sh = shellfacetraverse(subsegs); - }*/ - if(newseg.sh == nullptr) { - makeshellface(subsegs, &newseg); - setshvertices(newseg, p[0], p[1], nullptr); + while (segloop.sh != nullptr){ + ppt = (point *) &(segloop.sh[3]); + if(((ppt[0] == p[0]) && (ppt[1] == p[1])) || + ((ppt[0] == p[1]) && (ppt[1] == p[0]))){ + // Found! + newseg = segloop; + break; + } + segloop.sh = shellfacetraverse(subsegs); + }*/ + if(newseg.sh == nullptr) { + makeshellface(subsegs, &newseg); + setshvertices(newseg, p[0], p[1], nullptr); + } } - } - setshellmark(newseg, ge->tag()); - } // i - } // e_list + setshellmark(newseg, ge->tag()); + } // i + } // e_list - delete[] shperverlist; - delete[] idx2shlist; + delete[] shperverlist; + delete[] idx2shlist; - Msg::Debug(" %ld (%ld) subfaces (segments)", subfaces->items, - subsegs->items); + Msg::Debug(" %ld (%ld) subfaces (segments)", subfaces->items, + subsegs->items); - // The total number of iunput segments. - insegments = subsegs->items; + // The total number of iunput segments. + insegments = subsegs->items; - if(0) { - outmesh2medit("dump2"); + if(0) { outmesh2medit("dump2"); } } - } - delete[] idx2verlist; + delete[] idx2verlist; - // Boundary recovery. + // Boundary recovery. - clock_t t; - Msg::Info(" - Recovering boundary"); - recoverboundary(t); + clock_t t; + Msg::Info(" - Recovering boundary"); + recoverboundary(t); - carveholes(); + carveholes(); - if(subvertstack->objects > 0l) { - suppresssteinerpoints(); - } + if(subvertstack->objects > 0l) { suppresssteinerpoints(); } - recoverdelaunay(); + recoverdelaunay(); - // let's try - optimizemesh(); + // let's try + optimizemesh(); - if((dupverts > 0l) || (unuverts > 0l)) { - // Remove hanging nodes. - // cannot call this here due to 8 additional exterior vertices we inserted - // jettisonnodes(); - } + if((dupverts > 0l) || (unuverts > 0l)) { + // Remove hanging nodes. + // cannot call this here due to 8 additional exterior vertices we + // inserted jettisonnodes(); + } - long tetnumber, facenumber; + long tetnumber, facenumber; - Msg::Debug("Statistics:\n"); - Msg::Debug(" Input points: %ld", _vertices.size()); - if(b->plc) { - Msg::Debug(" Input facets: %ld", f_list.size()); - Msg::Debug(" Input segments: %ld", e_list.size()); - } + Msg::Debug("Statistics:\n"); + Msg::Debug(" Input points: %ld", _vertices.size()); + if(b->plc) { + Msg::Debug(" Input facets: %ld", f_list.size()); + Msg::Debug(" Input segments: %ld", e_list.size()); + } - tetnumber = tetrahedrons->items - hullsize; - facenumber = (tetnumber * 4l + hullsize) / 2l; + tetnumber = tetrahedrons->items - hullsize; + facenumber = (tetnumber * 4l + hullsize) / 2l; - if(b->weighted) { // -w option - Msg::Debug(" Mesh points: %ld", points->items - nonregularcount); - } - else { - Msg::Debug(" Mesh points: %ld", points->items); - } - Msg::Debug(" Mesh tetrahedra: %ld", tetnumber); - Msg::Debug(" Mesh faces: %ld", facenumber); - if(meshedges > 0l) { - Msg::Debug(" Mesh edges: %ld", meshedges); - } - else { - if(!nonconvex) { - long vsize = points->items - dupverts - unuverts; - if(b->weighted) vsize -= nonregularcount; - meshedges = vsize + facenumber - tetnumber - 1; - Msg::Debug(" Mesh edges: %ld", meshedges); + if(b->weighted) { // -w option + Msg::Debug(" Mesh points: %ld", points->items - nonregularcount); } - } - - if(b->plc || b->refine) { - Msg::Debug(" Mesh faces on facets: %ld", subfaces->items); - Msg::Debug(" Mesh edges on segments: %ld", subsegs->items); - if(st_volref_count > 0l) { - Msg::Debug(" Steiner points inside domain: %ld", st_volref_count); + else { + Msg::Debug(" Mesh points: %ld", points->items); } - if(st_facref_count > 0l) { - Msg::Debug(" Steiner points on facets: %ld", st_facref_count); + Msg::Debug(" Mesh tetrahedra: %ld", tetnumber); + Msg::Debug(" Mesh faces: %ld", facenumber); + if(meshedges > 0l) { Msg::Debug(" Mesh edges: %ld", meshedges); } + else { + if(!nonconvex) { + long vsize = points->items - dupverts - unuverts; + if(b->weighted) vsize -= nonregularcount; + meshedges = vsize + facenumber - tetnumber - 1; + Msg::Debug(" Mesh edges: %ld", meshedges); + } } - if(st_segref_count > 0l) { - Msg::Debug(" Steiner points on segments: %ld", st_segref_count); + + if(b->plc || b->refine) { + Msg::Debug(" Mesh faces on facets: %ld", subfaces->items); + Msg::Debug(" Mesh edges on segments: %ld", subsegs->items); + if(st_volref_count > 0l) { + Msg::Debug(" Steiner points inside domain: %ld", st_volref_count); + } + if(st_facref_count > 0l) { + Msg::Debug(" Steiner points on facets: %ld", st_facref_count); + } + if(st_segref_count > 0l) { + Msg::Debug(" Steiner points on segments: %ld", st_segref_count); + } } - } - else { - Msg::Debug(" Convex hull faces: %ld", hullsize); - if(meshhulledges > 0l) { - Msg::Debug(" Convex hull edges: %ld", meshhulledges); + else { + Msg::Debug(" Convex hull faces: %ld", hullsize); + if(meshhulledges > 0l) { + Msg::Debug(" Convex hull edges: %ld", meshhulledges); + } + } + if(b->weighted) { // -w option + Msg::Debug(" Skipped non-regular points: %ld", nonregularcount); } - } - if(b->weighted) { // -w option - Msg::Debug(" Skipped non-regular points: %ld", nonregularcount); - } - // Debug - if(0) { - outmesh2medit("dump"); - } + // Debug + if(0) { outmesh2medit("dump"); } - { - // Write mesh into to GRegion. + { + // Write mesh into to GRegion. - Msg::Debug("Writing to GRegion..."); + Msg::Debug("Writing to GRegion..."); - point p[4]; + point p[4]; - // In some hard cases, the surface mesh may be modified. - // Find the list of GFaces, GEdges that have been modified. - std::set<int> l_faces, l_edges; + // In some hard cases, the surface mesh may be modified. + // Find the list of GFaces, GEdges that have been modified. + std::set<int> l_faces, l_edges; - if(points->items > (int)_vertices.size()) { - face parentseg, parentsh, spinsh; - point pointloop; - // Create newly added mesh vertices. - // The new vertices must be added at the end of the point list. - points->traversalinit(); - pointloop = pointtraverse(); - while(pointloop != (point)nullptr) { - if(issteinerpoint(pointloop)) { - // Check if this Steiner point locates on boundary. - if(pointtype(pointloop) == FREESEGVERTEX) { - sdecode(point2sh(pointloop), parentseg); - assert(parentseg.sh != nullptr); - l_edges.insert(shellmark(parentseg)); - // Get the GEdge containing this vertex. - GEdge *ge = nullptr; - GFace *gf = nullptr; - int etag = shellmark(parentseg); - for(auto it = e_list.begin(); - it != e_list.end(); ++it) { - if((*it)->tag() == etag) { - ge = *it; - break; + if(points->items > (int)_vertices.size()) { + face parentseg, parentsh, spinsh; + point pointloop; + // Create newly added mesh vertices. + // The new vertices must be added at the end of the point list. + points->traversalinit(); + pointloop = pointtraverse(); + while(pointloop != (point)nullptr) { + if(issteinerpoint(pointloop)) { + // Check if this Steiner point locates on boundary. + if(pointtype(pointloop) == FREESEGVERTEX) { + sdecode(point2sh(pointloop), parentseg); + assert(parentseg.sh != nullptr); + l_edges.insert(shellmark(parentseg)); + // Get the GEdge containing this vertex. + GEdge *ge = nullptr; + GFace *gf = nullptr; + int etag = shellmark(parentseg); + for(auto it = e_list.begin(); it != e_list.end(); ++it) { + if((*it)->tag() == etag) { + ge = *it; + break; + } } - } - if(ge != nullptr) { - MEdgeVertex *v = new MEdgeVertex(pointloop[0], pointloop[1], - pointloop[2], ge, 0); - double uu = 0; - if(reparamMeshVertexOnEdge(v, ge, uu)) { - v->setParameter(0, uu); + if(ge != nullptr) { + MEdgeVertex *v = new MEdgeVertex(pointloop[0], pointloop[1], + pointloop[2], ge, 0); + double uu = 0; + if(reparamMeshVertexOnEdge(v, ge, uu)) { + v->setParameter(0, uu); + } + v->setIndex(pointmark(pointloop)); + _gr->mesh_vertices.push_back(v); + _extras[pointmark(pointloop) - in->firstnumber] = v; } - v->setIndex(pointmark(pointloop)); - _gr->mesh_vertices.push_back(v); - _extras[pointmark(pointloop) - in->firstnumber] = v; - } - spivot(parentseg, parentsh); - if(parentsh.sh != nullptr) { - if(ge == nullptr) { - // We treat this vertex a facet vertex. - int ftag = shellmark(parentsh); - for(auto it = f_list.begin(); - it != f_list.end(); ++it) { - if((*it)->tag() == ftag) { - gf = *it; - break; + spivot(parentseg, parentsh); + if(parentsh.sh != nullptr) { + if(ge == nullptr) { + // We treat this vertex a facet vertex. + int ftag = shellmark(parentsh); + for(auto it = f_list.begin(); it != f_list.end(); ++it) { + if((*it)->tag() == ftag) { + gf = *it; + break; + } } - } - if(gf != nullptr) { - MFaceVertex *v = new MFaceVertex(pointloop[0], pointloop[1], - pointloop[2], gf, 0, 0); - SPoint2 param; - if(reparamMeshVertexOnFace(v, gf, param)) { - v->setParameter(0, param.x()); - v->setParameter(1, param.y()); + if(gf != nullptr) { + MFaceVertex *v = new MFaceVertex( + pointloop[0], pointloop[1], pointloop[2], gf, 0, 0); + SPoint2 param; + if(reparamMeshVertexOnFace(v, gf, param)) { + v->setParameter(0, param.x()); + v->setParameter(1, param.y()); + } + v->setIndex(pointmark(pointloop)); + _gr->mesh_vertices.push_back(v); + _extras[pointmark(pointloop) - in->firstnumber] = v; } - v->setIndex(pointmark(pointloop)); - _gr->mesh_vertices.push_back(v); - _extras[pointmark(pointloop) - in->firstnumber] = v; + } + // Record all the GFaces' tag at this segment. + spinsh = parentsh; + while(1) { + l_faces.insert(shellmark(spinsh)); + spivotself(spinsh); + if(spinsh.sh == parentsh.sh) break; } } - // Record all the GFaces' tag at this segment. - spinsh = parentsh; - while(1) { - l_faces.insert(shellmark(spinsh)); - spivotself(spinsh); - if(spinsh.sh == parentsh.sh) break; + if((ge == nullptr) && (gf == nullptr)) { + // Create an interior mesh vertex. + MVertex *v = + new MVertex(pointloop[0], pointloop[1], pointloop[2], _gr); + v->setIndex(pointmark(pointloop)); + _extras[pointmark(pointloop) - in->firstnumber] = v; + _gr->mesh_vertices.push_back(v); } } - if((ge == nullptr) && (gf == nullptr)) { - // Create an interior mesh vertex. - MVertex *v = - new MVertex(pointloop[0], pointloop[1], pointloop[2], _gr); - v->setIndex(pointmark(pointloop)); - _extras[pointmark(pointloop) - in->firstnumber] = v; - _gr->mesh_vertices.push_back(v); - } - } - else if(pointtype(pointloop) == FREEFACETVERTEX) { - sdecode(point2sh(pointloop), parentsh); - assert(parentsh.sh != nullptr); - l_faces.insert(shellmark(parentsh)); - // Get the GFace containing this vertex. - GFace *gf = nullptr; - int ftag = shellmark(parentsh); - for(auto it = f_list.begin(); - it != f_list.end(); ++it) { - if((*it)->tag() == ftag) { - gf = *it; - break; + else if(pointtype(pointloop) == FREEFACETVERTEX) { + sdecode(point2sh(pointloop), parentsh); + assert(parentsh.sh != nullptr); + l_faces.insert(shellmark(parentsh)); + // Get the GFace containing this vertex. + GFace *gf = nullptr; + int ftag = shellmark(parentsh); + for(auto it = f_list.begin(); it != f_list.end(); ++it) { + if((*it)->tag() == ftag) { + gf = *it; + break; + } } - } - if(gf != nullptr) { - MFaceVertex *v = new MFaceVertex(pointloop[0], pointloop[1], - pointloop[2], gf, 0, 0); - SPoint2 param; - if(reparamMeshVertexOnFace(v, gf, param)) { - v->setParameter(0, param.x()); - v->setParameter(1, param.y()); + if(gf != nullptr) { + MFaceVertex *v = new MFaceVertex(pointloop[0], pointloop[1], + pointloop[2], gf, 0, 0); + SPoint2 param; + if(reparamMeshVertexOnFace(v, gf, param)) { + v->setParameter(0, param.x()); + v->setParameter(1, param.y()); + } + v->setIndex(pointmark(pointloop)); + _gr->mesh_vertices.push_back(v); + _extras[pointmark(pointloop) - in->firstnumber] = v; + } + else { + // Create a mesh vertex. + MVertex *v = + new MVertex(pointloop[0], pointloop[1], pointloop[2], _gr); + v->setIndex(pointmark(pointloop)); + _gr->mesh_vertices.push_back(v); + _extras[pointmark(pointloop) - in->firstnumber] = v; } - v->setIndex(pointmark(pointloop)); - _gr->mesh_vertices.push_back(v); - _extras[pointmark(pointloop) - in->firstnumber] = v; } else { - // Create a mesh vertex. MVertex *v = new MVertex(pointloop[0], pointloop[1], pointloop[2], _gr); v->setIndex(pointmark(pointloop)); @@ -871,513 +857,493 @@ namespace tetgenBR { _extras[pointmark(pointloop) - in->firstnumber] = v; } } - else { - MVertex *v = - new MVertex(pointloop[0], pointloop[1], pointloop[2], _gr); - v->setIndex(pointmark(pointloop)); - _gr->mesh_vertices.push_back(v); - _extras[pointmark(pointloop) - in->firstnumber] = v; - } + pointloop = pointtraverse(); } - pointloop = pointtraverse(); + // assert((int)_vertices.size() == points->items); } - // assert((int)_vertices.size() == points->items); - } - if(!_extras.empty()) - Msg::Info(" - Added %d Steiner point%s", _extras.size(), - (_extras.size() > 1) ? "s" : ""); + if(!_extras.empty()) + Msg::Info(" - Added %d Steiner point%s", _extras.size(), + (_extras.size() > 1) ? "s" : ""); - if(l_edges.size() > 0) { - // There are Steiner points on segments! - face segloop; - // Re-create the segment mesh in the corresponding GEdges. - for(auto it = l_edges.begin(); it != l_edges.end(); - ++it) { - // Find the GFace with tag = *it. + if(l_edges.size() > 0) { + // There are Steiner points on segments! + face segloop; + // Re-create the segment mesh in the corresponding GEdges. + for(auto it = l_edges.begin(); it != l_edges.end(); ++it) { + // Find the GFace with tag = *it. - int etag = *it; + int etag = *it; - const auto edge_location = std::find_if(begin(e_list), end(e_list), [&](GEdge *const edge) { + const auto edge_location = + std::find_if(begin(e_list), end(e_list), [&](GEdge *const edge) { return edge->tag() == etag; - }); - - GEdge *ge = edge_location == end(e_list) ? nullptr : *edge_location; - assert(ge != nullptr); - - Msg::Info(" - Steiner points exist on curve %d", ge->tag()); - // Delete the old triangles. - for(std::size_t i = 0; i < ge->lines.size(); i++) - delete ge->lines[i]; - ge->lines.clear(); - ge->deleteVertexArrays(); - // Create the new triangles. - segloop.shver = 0; - subsegs->traversalinit(); - segloop.sh = shellfacetraverse(subsegs); - while(segloop.sh != nullptr) { - if(shellmark(segloop) == etag) { - p[0] = sorg(segloop); - p[1] = sdest(segloop); - int idx1 = pointmark(p[0]) - in->firstnumber; - MVertex *v1 = - idx1 >= (int)_vertices.size() ? _extras[idx1] : _vertices[idx1]; - int idx2 = pointmark(p[1]) - in->firstnumber; - MVertex *v2 = - idx2 >= (int)_vertices.size() ? _extras[idx2] : _vertices[idx2]; - MLine *t = new MLine(v1, v2); - ge->lines.push_back(t); - } + }); + + GEdge *ge = edge_location == end(e_list) ? nullptr : *edge_location; + assert(ge != nullptr); + + Msg::Info(" - Steiner points exist on curve %d", ge->tag()); + // Delete the old triangles. + for(std::size_t i = 0; i < ge->lines.size(); i++) + delete ge->lines[i]; + ge->lines.clear(); + ge->deleteVertexArrays(); + // Create the new triangles. + segloop.shver = 0; + subsegs->traversalinit(); segloop.sh = shellfacetraverse(subsegs); - } - } // it - } - - if(l_faces.size() > 0) { - // There are Steiner points on facets! - face subloop; - // Re-create the surface mesh in the corresponding GFaces. - for(auto it = l_faces.begin(); it != l_faces.end(); - ++it) { - // Find the GFace with tag = *it. + while(segloop.sh != nullptr) { + if(shellmark(segloop) == etag) { + p[0] = sorg(segloop); + p[1] = sdest(segloop); + int idx1 = pointmark(p[0]) - in->firstnumber; + MVertex *v1 = idx1 >= (int)_vertices.size() ? _extras[idx1] : + _vertices[idx1]; + int idx2 = pointmark(p[1]) - in->firstnumber; + MVertex *v2 = idx2 >= (int)_vertices.size() ? _extras[idx2] : + _vertices[idx2]; + MLine *t = new MLine(v1, v2); + ge->lines.push_back(t); + } + segloop.sh = shellfacetraverse(subsegs); + } + } // it + } - int ftag = *it; + if(l_faces.size() > 0) { + // There are Steiner points on facets! + face subloop; + // Re-create the surface mesh in the corresponding GFaces. + for(auto it = l_faces.begin(); it != l_faces.end(); ++it) { + // Find the GFace with tag = *it. - const auto face_location = std::find_if(begin(f_list), end(f_list), [&](GFace *const face) { - return face->tag() == ftag; - }); + int ftag = *it; - GFace *gf = face_location == end(f_list) ? nullptr : *face_location; - assert(gf != nullptr); + const auto face_location = + std::find_if(begin(f_list), end(f_list), [&](GFace *const face) { + return face->tag() == ftag; + }); - // Delete the old triangles. - Msg::Info(" - Steiner points exist on surface %d", gf->tag()); - for(std::size_t i = 0; i < gf->triangles.size(); i++) - delete gf->triangles[i]; - gf->triangles.clear(); - gf->deleteVertexArrays(); + GFace *gf = face_location == end(f_list) ? nullptr : *face_location; + assert(gf != nullptr); - if(gf->quadrangles.size()){ - Msg::Warning("Steiner points not handled for quad surface mesh"); - } + // Delete the old triangles. + Msg::Info(" - Steiner points exist on surface %d", gf->tag()); + for(std::size_t i = 0; i < gf->triangles.size(); i++) + delete gf->triangles[i]; + gf->triangles.clear(); + gf->deleteVertexArrays(); - // Create the new triangles. - subloop.shver = 0; - subfaces->traversalinit(); - subloop.sh = shellfacetraverse(subfaces); - while(subloop.sh != nullptr) { - if(shellmark(subloop) == ftag) { - p[0] = sorg(subloop); - p[1] = sdest(subloop); - p[2] = sapex(subloop); - int idx1 = pointmark(p[0]) - in->firstnumber; - MVertex *v1 = - idx1 >= (int)_vertices.size() ? _extras[idx1] : _vertices[idx1]; - int idx2 = pointmark(p[1]) - in->firstnumber; - MVertex *v2 = - idx2 >= (int)_vertices.size() ? _extras[idx2] : _vertices[idx2]; - int idx3 = pointmark(p[2]) - in->firstnumber; - MVertex *v3 = - idx3 >= (int)_vertices.size() ? _extras[idx3] : _vertices[idx3]; - MTriangle *t = new MTriangle(v1, v2, v3); - gf->triangles.push_back(t); + if(gf->quadrangles.size()) { + Msg::Warning("Steiner points not handled for quad surface mesh"); } - subloop.sh = shellfacetraverse(subfaces); - } - } // it - } - triface tetloop; + // Create the new triangles. + subloop.shver = 0; + subfaces->traversalinit(); + subloop.sh = shellfacetraverse(subfaces); + while(subloop.sh != nullptr) { + if(shellmark(subloop) == ftag) { + p[0] = sorg(subloop); + p[1] = sdest(subloop); + p[2] = sapex(subloop); + int idx1 = pointmark(p[0]) - in->firstnumber; + MVertex *v1 = idx1 >= (int)_vertices.size() ? _extras[idx1] : + _vertices[idx1]; + int idx2 = pointmark(p[1]) - in->firstnumber; + MVertex *v2 = idx2 >= (int)_vertices.size() ? _extras[idx2] : + _vertices[idx2]; + int idx3 = pointmark(p[2]) - in->firstnumber; + MVertex *v3 = idx3 >= (int)_vertices.size() ? _extras[idx3] : + _vertices[idx3]; + MTriangle *t = new MTriangle(v1, v2, v3); + gf->triangles.push_back(t); + } + subloop.sh = shellfacetraverse(subfaces); + } + } // it + } - tetloop.ver = 11; - tetrahedrons->traversalinit(); - tetloop.tet = tetrahedrontraverse(); + triface tetloop; - while(tetloop.tet != (tetrahedron *)nullptr) { - p[0] = org(tetloop); - p[1] = dest(tetloop); - p[2] = apex(tetloop); - p[3] = oppo(tetloop); - - int idx1 = pointmark(p[0]) - in->firstnumber; - MVertex *v1 = - idx1 >= (int)_vertices.size() ? _extras[idx1] : _vertices[idx1]; - int idx2 = pointmark(p[1]) - in->firstnumber; - MVertex *v2 = - idx2 >= (int)_vertices.size() ? _extras[idx2] : _vertices[idx2]; - int idx3 = pointmark(p[2]) - in->firstnumber; - MVertex *v3 = - idx3 >= (int)_vertices.size() ? _extras[idx3] : _vertices[idx3]; - int idx4 = pointmark(p[3]) - in->firstnumber; - MVertex *v4 = - idx4 >= (int)_vertices.size() ? _extras[idx4] : _vertices[idx4]; - MTetrahedron *t = new MTetrahedron(v1, v2, v3, v4); - _gr->tetrahedra.push_back(t); + tetloop.ver = 11; + tetrahedrons->traversalinit(); tetloop.tet = tetrahedrontraverse(); - } - } // mesh output - - Msg::Info("Done reconstructing mesh (Wall %gs, CPU %gs)", - TimeOfDay() - w_start, Cpu() - t_start); - - // Put all coordinates back so they are not pertubated anymore (pertubation - // done in delaunayTriangulation) - for(auto vIter = - originalCoordinates.begin(); - vIter != originalCoordinates.end(); ++vIter) { - const SPoint3 &coordinates = vIter->second; - vIter->first->setXYZ(coordinates.x(), coordinates.y(), coordinates.z()); - } - - // delete 8 new enclosing box vertices added in delaunayMeshIn3d - for(std::size_t i = _vertices.size() - 8; i < _vertices.size(); i++) - delete _vertices[i]; - return true; - } + while(tetloop.tet != (tetrahedron *)nullptr) { + p[0] = org(tetloop); + p[1] = dest(tetloop); + p[2] = apex(tetloop); + p[3] = oppo(tetloop); - // Dump the input surface mesh. - // 'mfilename' is a filename without suffix. - void tetgenmesh::outsurfacemesh(const char *mfilename) - { - FILE *outfile = nullptr; - char sfilename[256]; - int firstindex; - - point pointloop; - int pointnumber; - strcpy(sfilename, mfilename); - strcat(sfilename, ".node"); - outfile = fopen(sfilename, "w"); - if(!b->quiet) { - printf("Writing %s.\n", sfilename); - } - fprintf(outfile, "%ld 3 0 0\n", points->items); - // Determine the first index (0 or 1). - firstindex = b->zeroindex ? 0 : in->firstnumber; - points->traversalinit(); - pointloop = pointtraverse(); - pointnumber = firstindex; // in->firstnumber; - while(pointloop != (point)nullptr) { - // Point number, x, y and z coordinates. - fprintf(outfile, "%4d %.17g %.17g %.17g", pointnumber, pointloop[0], - pointloop[1], pointloop[2]); - fprintf(outfile, "\n"); - pointloop = pointtraverse(); - pointnumber++; - } - fclose(outfile); - - face faceloop; - point torg, tdest, tapex; - strcpy(sfilename, mfilename); - strcat(sfilename, ".smesh"); - outfile = fopen(sfilename, "w"); - if(!b->quiet) { - printf("Writing %s.\n", sfilename); - } - int shift = 0; // Default no shiftment. - if((in->firstnumber == 1) && (firstindex == 0)) { - shift = 1; // Shift the output indices by 1. - } - fprintf(outfile, "0 3 0 0\n"); - fprintf(outfile, "%ld 1\n", subfaces->items); - subfaces->traversalinit(); - faceloop.sh = shellfacetraverse(subfaces); - while(faceloop.sh != (shellface *)nullptr) { - torg = sorg(faceloop); - tdest = sdest(faceloop); - tapex = sapex(faceloop); - fprintf(outfile, "3 %4d %4d %4d %d\n", pointmark(torg) - shift, - pointmark(tdest) - shift, pointmark(tapex) - shift, - shellmark(faceloop)); - faceloop.sh = shellfacetraverse(subfaces); - } - fprintf(outfile, "0\n"); - fprintf(outfile, "0\n"); - fclose(outfile); - - face edgeloop; - int edgenumber; - strcpy(sfilename, mfilename); - strcat(sfilename, ".edge"); - outfile = fopen(sfilename, "w"); - if(!b->quiet) { - printf("Writing %s.\n", sfilename); - } - fprintf(outfile, "%ld 1\n", subsegs->items); - subsegs->traversalinit(); - edgeloop.sh = shellfacetraverse(subsegs); - edgenumber = firstindex; // in->firstnumber; - while(edgeloop.sh != (shellface *)nullptr) { - torg = sorg(edgeloop); - tdest = sdest(edgeloop); - fprintf(outfile, "%5d %4d %4d %d\n", edgenumber, - pointmark(torg) - shift, pointmark(tdest) - shift, - shellmark(edgeloop)); - edgenumber++; - edgeloop.sh = shellfacetraverse(subsegs); - } - fclose(outfile); - } + int idx1 = pointmark(p[0]) - in->firstnumber; + MVertex *v1 = + idx1 >= (int)_vertices.size() ? _extras[idx1] : _vertices[idx1]; + int idx2 = pointmark(p[1]) - in->firstnumber; + MVertex *v2 = + idx2 >= (int)_vertices.size() ? _extras[idx2] : _vertices[idx2]; + int idx3 = pointmark(p[2]) - in->firstnumber; + MVertex *v3 = + idx3 >= (int)_vertices.size() ? _extras[idx3] : _vertices[idx3]; + int idx4 = pointmark(p[3]) - in->firstnumber; + MVertex *v4 = + idx4 >= (int)_vertices.size() ? _extras[idx4] : _vertices[idx4]; + MTetrahedron *t = new MTetrahedron(v1, v2, v3, v4); + _gr->tetrahedra.push_back(t); + tetloop.tet = tetrahedrontraverse(); + } + } // mesh output - void tetgenmesh::outmesh2medit(const char *mfilename) - { - FILE *outfile; - char mefilename[256]; - tetrahedron *tetptr; - triface tface, tsymface; - face segloop, checkmark; - point ptloop, p1, p2, p3, p4; - long ntets, faces; - int shift = 0; - int marker; - - if(mfilename != (char *)nullptr && mfilename[0] != '\0') { - strcpy(mefilename, mfilename); - } - else { - strcpy(mefilename, "unnamed"); - } - strcat(mefilename, ".mesh"); + Msg::Info("Done reconstructing mesh (Wall %gs, CPU %gs)", + TimeOfDay() - w_start, Cpu() - t_start); - if(!b->quiet) { - printf("Writing %s.\n", mefilename); - } - outfile = fopen(mefilename, "w"); - if(outfile == (FILE *)nullptr) { - Msg::Error("Could not open file '%s'", mefilename); - return; - } + // Put all coordinates back so they are not pertubated anymore + // (pertubation done in delaunayTriangulation) + for(auto vIter = originalCoordinates.begin(); + vIter != originalCoordinates.end(); ++vIter) { + const SPoint3 &coordinates = vIter->second; + vIter->first->setXYZ(coordinates.x(), coordinates.y(), coordinates.z()); + } - fprintf(outfile, "MeshVersionFormatted 1\n"); - fprintf(outfile, "\n"); - fprintf(outfile, "Dimension\n"); - fprintf(outfile, "3\n"); - fprintf(outfile, "\n"); - - fprintf(outfile, "\n# Set of mesh vertices\n"); - fprintf(outfile, "Vertices\n"); - fprintf(outfile, "%ld\n", points->items); - - points->traversalinit(); - ptloop = pointtraverse(); - // pointnumber = 1; - while(ptloop != (point)nullptr) { - // Point coordinates. - fprintf(outfile, "%.17g %.17g %.17g", ptloop[0], ptloop[1], ptloop[2]); - fprintf(outfile, " 0\n"); - // setpointmark(ptloop, pointnumber); - ptloop = pointtraverse(); - // pointnumber++; - } + // delete 8 new enclosing box vertices added in delaunayMeshIn3d + for(std::size_t i = _vertices.size() - 8; i < _vertices.size(); i++) + delete _vertices[i]; - // Medit need start number form 1. - if(in->firstnumber == 1) { - shift = 0; - } - else { - shift = 1; + return true; } - // Compute the number of faces. - ntets = tetrahedrons->items - hullsize; + // Dump the input surface mesh. + // 'mfilename' is a filename without suffix. + void tetgenmesh::outsurfacemesh(const char *mfilename) + { + FILE *outfile = nullptr; + char sfilename[256]; + int firstindex; - fprintf(outfile, "\n# Set of Tetrahedra\n"); - fprintf(outfile, "Tetrahedra\n"); - fprintf(outfile, "%ld\n", ntets); + point pointloop; + int pointnumber; + strcpy(sfilename, mfilename); + strcat(sfilename, ".node"); + outfile = fopen(sfilename, "w"); + if(!b->quiet) { printf("Writing %s.\n", sfilename); } + fprintf(outfile, "%ld 3 0 0\n", points->items); + // Determine the first index (0 or 1). + firstindex = b->zeroindex ? 0 : in->firstnumber; + points->traversalinit(); + pointloop = pointtraverse(); + pointnumber = firstindex; // in->firstnumber; + while(pointloop != (point)nullptr) { + // Point number, x, y and z coordinates. + fprintf(outfile, "%4d %.17g %.17g %.17g", pointnumber, + pointloop[0], pointloop[1], pointloop[2]); + fprintf(outfile, "\n"); + pointloop = pointtraverse(); + pointnumber++; + } + fclose(outfile); + + face faceloop; + point torg, tdest, tapex; + strcpy(sfilename, mfilename); + strcat(sfilename, ".smesh"); + outfile = fopen(sfilename, "w"); + if(!b->quiet) { printf("Writing %s.\n", sfilename); } + int shift = 0; // Default no shiftment. + if((in->firstnumber == 1) && (firstindex == 0)) { + shift = 1; // Shift the output indices by 1. + } + fprintf(outfile, "0 3 0 0\n"); + fprintf(outfile, "%ld 1\n", subfaces->items); + subfaces->traversalinit(); + faceloop.sh = shellfacetraverse(subfaces); + while(faceloop.sh != (shellface *)nullptr) { + torg = sorg(faceloop); + tdest = sdest(faceloop); + tapex = sapex(faceloop); + fprintf(outfile, "3 %4d %4d %4d %d\n", pointmark(torg) - shift, + pointmark(tdest) - shift, pointmark(tapex) - shift, + shellmark(faceloop)); + faceloop.sh = shellfacetraverse(subfaces); + } + fprintf(outfile, "0\n"); + fprintf(outfile, "0\n"); + fclose(outfile); + + face edgeloop; + int edgenumber; + strcpy(sfilename, mfilename); + strcat(sfilename, ".edge"); + outfile = fopen(sfilename, "w"); + if(!b->quiet) { printf("Writing %s.\n", sfilename); } + fprintf(outfile, "%ld 1\n", subsegs->items); + subsegs->traversalinit(); + edgeloop.sh = shellfacetraverse(subsegs); + edgenumber = firstindex; // in->firstnumber; + while(edgeloop.sh != (shellface *)nullptr) { + torg = sorg(edgeloop); + tdest = sdest(edgeloop); + fprintf(outfile, "%5d %4d %4d %d\n", edgenumber, + pointmark(torg) - shift, pointmark(tdest) - shift, + shellmark(edgeloop)); + edgenumber++; + edgeloop.sh = shellfacetraverse(subsegs); + } + fclose(outfile); + } - tetrahedrons->traversalinit(); - tetptr = tetrahedrontraverse(); - while(tetptr != (tetrahedron *)nullptr) { - if(!b->reversetetori) { - p1 = (point)tetptr[4]; - p2 = (point)tetptr[5]; + void tetgenmesh::outmesh2medit(const char *mfilename) + { + FILE *outfile; + char mefilename[256]; + tetrahedron *tetptr; + triface tface, tsymface; + face segloop, checkmark; + point ptloop, p1, p2, p3, p4; + long ntets, faces; + int shift = 0; + int marker; + + if(mfilename != (char *)nullptr && mfilename[0] != '\0') { + strcpy(mefilename, mfilename); } else { - p1 = (point)tetptr[5]; - p2 = (point)tetptr[4]; + strcpy(mefilename, "unnamed"); } - p3 = (point)tetptr[6]; - p4 = (point)tetptr[7]; - fprintf(outfile, "%5d %5d %5d %5d", pointmark(p1) + shift, - pointmark(p2) + shift, pointmark(p3) + shift, - pointmark(p4) + shift); - if(numelemattrib > 0) { - fprintf(outfile, " %.17g", elemattribute(tetptr, 0)); + strcat(mefilename, ".mesh"); + + if(!b->quiet) { printf("Writing %s.\n", mefilename); } + outfile = fopen(mefilename, "w"); + if(outfile == (FILE *)nullptr) { + Msg::Error("Could not open file '%s'", mefilename); + return; } + + fprintf(outfile, "MeshVersionFormatted 1\n"); + fprintf(outfile, "\n"); + fprintf(outfile, "Dimension\n"); + fprintf(outfile, "3\n"); + fprintf(outfile, "\n"); + + fprintf(outfile, "\n# Set of mesh vertices\n"); + fprintf(outfile, "Vertices\n"); + fprintf(outfile, "%ld\n", points->items); + + points->traversalinit(); + ptloop = pointtraverse(); + // pointnumber = 1; + while(ptloop != (point)nullptr) { + // Point coordinates. + fprintf(outfile, "%.17g %.17g %.17g", ptloop[0], ptloop[1], + ptloop[2]); + fprintf(outfile, " 0\n"); + // setpointmark(ptloop, pointnumber); + ptloop = pointtraverse(); + // pointnumber++; + } + + // Medit need start number form 1. + if(in->firstnumber == 1) { shift = 0; } else { - fprintf(outfile, " 0"); + shift = 1; } - fprintf(outfile, "\n"); + + // Compute the number of faces. + ntets = tetrahedrons->items - hullsize; + + fprintf(outfile, "\n# Set of Tetrahedra\n"); + fprintf(outfile, "Tetrahedra\n"); + fprintf(outfile, "%ld\n", ntets); + + tetrahedrons->traversalinit(); tetptr = tetrahedrontraverse(); - } + while(tetptr != (tetrahedron *)nullptr) { + if(!b->reversetetori) { + p1 = (point)tetptr[4]; + p2 = (point)tetptr[5]; + } + else { + p1 = (point)tetptr[5]; + p2 = (point)tetptr[4]; + } + p3 = (point)tetptr[6]; + p4 = (point)tetptr[7]; + fprintf(outfile, "%5d %5d %5d %5d", pointmark(p1) + shift, + pointmark(p2) + shift, pointmark(p3) + shift, + pointmark(p4) + shift); + if(numelemattrib > 0) { + fprintf(outfile, " %.17g", elemattribute(tetptr, 0)); + } + else { + fprintf(outfile, " 0"); + } + fprintf(outfile, "\n"); + tetptr = tetrahedrontraverse(); + } - // faces = (ntets * 4l + hullsize) / 2l; - faces = subfaces->items; - face sface; - - fprintf(outfile, "\n# Set of Triangles\n"); - fprintf(outfile, "Triangles\n"); - fprintf(outfile, "%ld\n", faces); - - subfaces->traversalinit(); - sface.sh = shellfacetraverse(subfaces); - while(sface.sh != nullptr) { - p1 = sorg(sface); - p2 = sdest(sface); - p3 = sapex(sface); - fprintf(outfile, "%5d %5d %5d", pointmark(p1) + shift, - pointmark(p2) + shift, pointmark(p3) + shift); - marker = shellmark(sface); - fprintf(outfile, " %d\n", marker); - sface.sh = shellfacetraverse(subfaces); - } + // faces = (ntets * 4l + hullsize) / 2l; + faces = subfaces->items; + face sface; - fprintf(outfile, "\nEnd\n"); - fclose(outfile); - } + fprintf(outfile, "\n# Set of Triangles\n"); + fprintf(outfile, "Triangles\n"); + fprintf(outfile, "%ld\n", faces); -} // end namespace + subfaces->traversalinit(); + sface.sh = shellfacetraverse(subfaces); + while(sface.sh != nullptr) { + p1 = sorg(sface); + p2 = sdest(sface); + p3 = sapex(sface); + fprintf(outfile, "%5d %5d %5d", pointmark(p1) + shift, + pointmark(p2) + shift, pointmark(p3) + shift); + marker = shellmark(sface); + fprintf(outfile, " %d\n", marker); + sface.sh = shellfacetraverse(subfaces); + } -bool meshGRegionBoundaryRecovery(GRegion *gr, splitQuadRecovery *sqr) -{ - bool ret = false; - try { - tetgenBR::tetgenmesh *m = new tetgenBR::tetgenmesh(); - m->in = new tetgenBR::tetgenio(); - m->b = new tetgenBR::tetgenbehavior(); - tetgenBR::brdata data = {gr, sqr}; - ret = m->reconstructmesh((void *)&data); - delete m->in; - delete m->b; - delete m; - } catch(int err) { - if(err == 1) { - Msg::Error("Out of memory in boundary mesh recovery"); - ret = false; + fprintf(outfile, "\nEnd\n"); + fclose(outfile); } - else if(err == 3) { - std::map<int, MVertex *> all; - std::vector<GFace *> f = gr->faces(); - for(auto it = f.begin(); it != f.end(); ++it) { - GFace *gf = *it; - for(std::size_t i = 0; i < gf->triangles.size(); i++) { - for(int j = 0; j < 3; j++) { - MVertex *v = gf->triangles[i]->getVertex(j); - all[v->getIndex()] = v; + + } // namespace tetgenBR + + bool meshGRegionBoundaryRecovery(GRegion *gr, splitQuadRecovery *sqr) + { + bool ret = false; + try { + tetgenBR::tetgenmesh *m = new tetgenBR::tetgenmesh(); + m->in = new tetgenBR::tetgenio(); + m->b = new tetgenBR::tetgenbehavior(); + tetgenBR::brdata data = {gr, sqr}; + ret = m->reconstructmesh((void *)&data); + delete m->in; + delete m->b; + delete m; + } catch(int err) { + if(err == 1) { + Msg::Error("Out of memory in boundary mesh recovery"); + ret = false; + } + else if(err == 3) { + std::map<int, MVertex *> all; + std::vector<GFace *> f = gr->faces(); + for(auto it = f.begin(); it != f.end(); ++it) { + GFace *gf = *it; + for(std::size_t i = 0; i < gf->triangles.size(); i++) { + for(int j = 0; j < 3; j++) { + MVertex *v = gf->triangles[i]->getVertex(j); + all[v->getIndex()] = v; + } } } - } - std::vector<GEdge *> const &e = gr->embeddedEdges(); - for(auto it = e.begin(); it != e.end(); - ++it) { - GEdge *ge = *it; - for(std::size_t i = 0; i < ge->lines.size(); i++) { - for(int j = 0; j < 2; j++) { - MVertex *v = ge->lines[i]->getVertex(j); + std::vector<GEdge *> const &e = gr->embeddedEdges(); + for(auto it = e.begin(); it != e.end(); ++it) { + GEdge *ge = *it; + for(std::size_t i = 0; i < ge->lines.size(); i++) { + for(int j = 0; j < 2; j++) { + MVertex *v = ge->lines[i]->getVertex(j); + all[v->getIndex()] = v; + } + } + } + std::vector<GVertex *> const &v = gr->embeddedVertices(); + for(auto it = v.begin(); it != v.end(); ++it) { + GVertex *gv = *it; + for(std::size_t i = 0; i < gv->points.size(); i++) { + MVertex *v = gv->points[i]->getVertex(0); all[v->getIndex()] = v; } } - } - std::vector<GVertex *> const &v = gr->embeddedVertices(); - for(auto it = v.begin(); it != v.end(); - ++it) { - GVertex *gv = *it; - for(std::size_t i = 0; i < gv->points.size(); i++) { - MVertex *v = gv->points[i]->getVertex(0); + for(std::size_t i = 0; i < gr->mesh_vertices.size(); i++) { + MVertex *v = gr->mesh_vertices[i]; all[v->getIndex()] = v; } - } - for(std::size_t i = 0; i < gr->mesh_vertices.size(); i++) { - MVertex *v = gr->mesh_vertices[i]; - all[v->getIndex()] = v; - } - std::string what; - bool pnt = true; - switch(tetgenBR::sevent.e_type) { - case 1: what = "segment-segment intersection"; break; - case 2: what = "segment-facet intersection"; break; - case 3: what = "facet-facet intersection"; break; - case 4: - what = "overlapping segments"; - pnt = false; - break; - case 5: - what = "segment in facet"; - pnt = false; - break; - case 6: - what = "overlapping facets"; - pnt = false; - break; - case 7: what = "vertex in segment"; break; - case 8: what = "vertex in facet"; break; - default: what = "unknown"; break; - } - int vtags[2][3] = { - {tetgenBR::sevent.f_vertices1[0], tetgenBR::sevent.f_vertices1[1], - tetgenBR::sevent.f_vertices1[2]}, - {tetgenBR::sevent.f_vertices2[0], tetgenBR::sevent.f_vertices2[1], - tetgenBR::sevent.f_vertices2[2]}}; - int ftags[2] = {tetgenBR::sevent.f_marker1, tetgenBR::sevent.f_marker2}; - int etags[2] = {tetgenBR::sevent.s_marker1, tetgenBR::sevent.s_marker2}; - std::ostringstream pb; - std::vector<double> x, y, z, val; - for(int f = 0; f < 2; f++) { - if(ftags[f] > 0) { - GFace *gf = gr->model()->getFaceByTag(ftags[f]); - if(gf) { - gr->model()->addLastMeshEntityError(gf); - pb << " surface " << ftags[f]; - } + std::string what; + bool pnt = true; + switch(tetgenBR::sevent.e_type) { + case 1: what = "segment-segment intersection"; break; + case 2: what = "segment-facet intersection"; break; + case 3: what = "facet-facet intersection"; break; + case 4: + what = "overlapping segments"; + pnt = false; + break; + case 5: + what = "segment in facet"; + pnt = false; + break; + case 6: + what = "overlapping facets"; + pnt = false; + break; + case 7: what = "vertex in segment"; break; + case 8: what = "vertex in facet"; break; + default: what = "unknown"; break; } - if(etags[f] > 0) { - GEdge *ge = gr->model()->getEdgeByTag(etags[f]); - if(ge) { - gr->model()->addLastMeshEntityError(ge); - pb << " curve " << etags[f]; + int vtags[2][3] = { + {tetgenBR::sevent.f_vertices1[0], tetgenBR::sevent.f_vertices1[1], + tetgenBR::sevent.f_vertices1[2]}, + {tetgenBR::sevent.f_vertices2[0], tetgenBR::sevent.f_vertices2[1], + tetgenBR::sevent.f_vertices2[2]}}; + int ftags[2] = {tetgenBR::sevent.f_marker1, tetgenBR::sevent.f_marker2}; + int etags[2] = {tetgenBR::sevent.s_marker1, tetgenBR::sevent.s_marker2}; + std::ostringstream pb; + std::vector<double> x, y, z, val; + for(int f = 0; f < 2; f++) { + if(ftags[f] > 0) { + GFace *gf = gr->model()->getFaceByTag(ftags[f]); + if(gf) { + gr->model()->addLastMeshEntityError(gf); + pb << " surface " << ftags[f]; + } } - } - for(int i = 0; i < 3; i++) { - MVertex *v = all[vtags[f][i]]; - if(v) { - gr->model()->addLastMeshVertexError(v); - x.push_back(v->x()); - y.push_back(v->y()); - z.push_back(v->z()); - val.push_back(f); + if(etags[f] > 0) { + GEdge *ge = gr->model()->getEdgeByTag(etags[f]); + if(ge) { + gr->model()->addLastMeshEntityError(ge); + pb << " curve " << etags[f]; + } + } + for(int i = 0; i < 3; i++) { + MVertex *v = all[vtags[f][i]]; + if(v) { + gr->model()->addLastMeshVertexError(v); + x.push_back(v->x()); + y.push_back(v->y()); + z.push_back(v->z()); + val.push_back(f); + } } } - } - if(pnt) { - double px = tetgenBR::sevent.int_point[0]; - double py = tetgenBR::sevent.int_point[1]; - double pz = tetgenBR::sevent.int_point[2]; - pb << ", intersection (" << px << "," << py << "," << pz << ")"; - x.push_back(px); - y.push_back(py); - z.push_back(pz); - val.push_back(3.); - } - Msg::Error("Invalid boundary mesh (%s) on%s", what.c_str(), - pb.str().c_str()); + if(pnt) { + double px = tetgenBR::sevent.int_point[0]; + double py = tetgenBR::sevent.int_point[1]; + double pz = tetgenBR::sevent.int_point[2]; + pb << ", intersection (" << px << "," << py << "," << pz << ")"; + x.push_back(px); + y.push_back(py); + z.push_back(pz); + val.push_back(3.); + } + Msg::Error("Invalid boundary mesh (%s) on%s", what.c_str(), + pb.str().c_str()); #if defined(HAVE_POST) - new PView("Boundary mesh issue", x, y, z, val); + new PView("Boundary mesh issue", x, y, z, val); #if defined(HAVE_FLTK) - if(FlGui::available()) FlGui::instance()->updateViews(true, true); - drawContext::global()->draw(); + if(FlGui::available()) FlGui::instance()->updateViews(true, true); + drawContext::global()->draw(); #endif #endif - ret = false; - } - else { - Msg::Error("Could not recover boundary mesh: error %d", err); - ret = false; + ret = false; + } + else { + Msg::Error("Could not recover boundary mesh: error %d", err); + ret = false; + } } + return ret; } - return ret; -} #else diff --git a/Mesh/meshGRegionDelaunayInsertion.h b/Mesh/meshGRegionDelaunayInsertion.h index a8e316da36347f6a5919ef584b094fef7c3a86c7..6afb58c5a41af685bff775146095424e3f2f522d 100644 --- a/Mesh/meshGRegionDelaunayInsertion.h +++ b/Mesh/meshGRegionDelaunayInsertion.h @@ -215,12 +215,15 @@ public: } }; -void connectTets(std::list<MTet4 *> &, const std::set<MFace, MFaceLessThan> * = nullptr); -void connectTets(std::vector<MTet4 *> &, const std::set<MFace, MFaceLessThan> * = nullptr); +void connectTets(std::list<MTet4 *> &, + const std::set<MFace, MFaceLessThan> * = nullptr); +void connectTets(std::vector<MTet4 *> &, + const std::set<MFace, MFaceLessThan> * = nullptr); void delaunayMeshIn3D(std::vector<MVertex *> &, std::vector<MTetrahedron *> &, bool removeBox = false); -void insertVerticesInRegion(GRegion *gr, int maxIter, double worstTetRadiusTarget, - bool _classify = true, splitQuadRecovery *sqr = nullptr); +void insertVerticesInRegion(GRegion *gr, int maxIter, + double worstTetRadiusTarget, bool _classify = true, + splitQuadRecovery *sqr = nullptr); void bowyerWatsonFrontalLayers(GRegion *gr, bool hex); struct compareTet4Ptr { diff --git a/Mesh/meshGRegionLocalMeshMod.h b/Mesh/meshGRegionLocalMeshMod.h index b7b73be119f36c5cf1d9ea9a7eb14b54d4c6fed9..673d05ac67d91391c1c7a0e6f7f9bafbf05401f6 100644 --- a/Mesh/meshGRegionLocalMeshMod.h +++ b/Mesh/meshGRegionLocalMeshMod.h @@ -32,7 +32,8 @@ bool smoothVertexOptimize(MTet4 *t, int iVertex, bool collapseVertex(std::vector<MTet4 *> &newTets, MTet4 *t, int iVertex, int iTarget, const qmTetrahedron::Measures &cr, - const localMeshModAction = GMSH_DOIT, double *result = nullptr); + const localMeshModAction = GMSH_DOIT, + double *result = nullptr); bool edgeSplit(std::vector<MTet4 *> &newTets, MTet4 *tet, MVertex *newVertex, int iLocalEdge, const qmTetrahedron::Measures &cr); diff --git a/Mesh/meshMetric.h b/Mesh/meshMetric.h index 5b6e9c4c6aa992d99c3c73dd714b7f24a3a8a525..0d3c580ccb92d55b1166281d5e58f395c8bf7561 100644 --- a/Mesh/meshMetric.h +++ b/Mesh/meshMetric.h @@ -140,7 +140,8 @@ public: // get metric at point(x,y,z) (previously computes intersection of metrics if // not done yet) - virtual double operator()(double x, double y, double z, GEntity *ge = nullptr); + virtual double operator()(double x, double y, double z, + GEntity *ge = nullptr); virtual void operator()(double x, double y, double z, SMetric3 &metr, GEntity *ge = nullptr); diff --git a/Mesh/meshRelocateVertex.h b/Mesh/meshRelocateVertex.h index 2c57bcd7cc8017fc21be77d158f5562f8e95cd71..8be777fd26bbd207a81f82cf5ae3f4fc47917310 100644 --- a/Mesh/meshRelocateVertex.h +++ b/Mesh/meshRelocateVertex.h @@ -16,7 +16,8 @@ void RelocateVertices(GRegion *region, int niter, double tol = 1.e-2); void RelocateVertices(std::vector<GRegion *> ®ions, int niter, double tol = 1.e-2); void RelocateVertices(GFace *, int niter, double tol = 1.e-6); -void RelocateVerticesOfPyramids(GRegion *region, int niter, double tol= 1.e-2); -void RelocateVerticesOfPyramids(std::vector<GRegion *> ®ions, int niter, double tol= 1.e-2); +void RelocateVerticesOfPyramids(GRegion *region, int niter, double tol = 1.e-2); +void RelocateVerticesOfPyramids(std::vector<GRegion *> ®ions, int niter, + double tol = 1.e-2); #endif diff --git a/Mesh/qualityMeasures.h b/Mesh/qualityMeasures.h index 45f674fab982627cd28ded40f1536072d492874b..a0ef46d8fddcbaba4c1ac5f8a2b9657d4ccf902d 100644 --- a/Mesh/qualityMeasures.h +++ b/Mesh/qualityMeasures.h @@ -66,11 +66,13 @@ public: class qmTetrahedron { public: enum Measures { QMTET_GAMMA, QMTET_ETA, QMTET_ONE, QMTET_COND }; - static double qm(MTetrahedron *t, const Measures &cr, double *volume = nullptr); + static double qm(MTetrahedron *t, const Measures &cr, + double *volume = nullptr); static double qm(const BDS_Point *p1, const BDS_Point *p2, const BDS_Point *p3); static double qm(const MVertex *v1, const MVertex *v2, const MVertex *v3, - const MVertex *v4, const Measures &cr, double *volume = nullptr); + const MVertex *v4, const Measures &cr, + double *volume = nullptr); static double qm(const double &x1, const double &y1, const double &z1, const double &x2, const double &y2, const double &z2, const double &x3, const double &y3, const double &z3, diff --git a/Mesh/qualityMeasuresJacobian.h b/Mesh/qualityMeasuresJacobian.h index 3a5ad16f7e667df20d3df4099ab71cb62d268ab1..d54ff4db90e8b3a0e48bb707aa1956925b7bb666 100644 --- a/Mesh/qualityMeasuresJacobian.h +++ b/Mesh/qualityMeasuresJacobian.h @@ -40,7 +40,8 @@ namespace jacobianBasedQuality { // For regression tests: void testAllMeasuresAllElements(); - void testAllMeasures(MElement *el, const fullMatrix<double> *normals = nullptr); + void testAllMeasures(MElement *el, + const fullMatrix<double> *normals = nullptr); class _coeffData { protected: diff --git a/Mesh/tetgenBR.h b/Mesh/tetgenBR.h index 86f7ec7d3f26e175f90d742ec6b24087133385b9..f634eb62a2091dc0ea73ae6d95d81abf7cc36cae 100644 --- a/Mesh/tetgenBR.h +++ b/Mesh/tetgenBR.h @@ -1428,17 +1428,13 @@ public: void freememory() { - if(bgm != NULL) { - delete bgm; - } + if(bgm != NULL) { delete bgm; } if(points != (memorypool *)NULL) { delete points; delete[] dummypoint; } - if(tetrahedrons != (memorypool *)NULL) { - delete tetrahedrons; - } + if(tetrahedrons != (memorypool *)NULL) { delete tetrahedrons; } if(subfaces != (memorypool *)NULL) { delete subfaces; delete subsegs; @@ -1448,21 +1444,11 @@ public: delete tet2subpool; } - if(badtetrahedrons) { - delete badtetrahedrons; - } - if(badsubfacs) { - delete badsubfacs; - } - if(badsubsegs) { - delete badsubsegs; - } - if(encseglist) { - delete encseglist; - } - if(encshlist) { - delete encshlist; - } + if(badtetrahedrons) { delete badtetrahedrons; } + if(badsubfacs) { delete badsubfacs; } + if(badsubsegs) { delete badsubsegs; } + if(encseglist) { delete encseglist; } + if(encshlist) { delete encshlist; } if(flippool != NULL) { delete flippool; @@ -1497,13 +1483,9 @@ public: delete[] facetverticeslist; } - if(segmentendpointslist != NULL) { - delete[] segmentendpointslist; - } + if(segmentendpointslist != NULL) { delete[] segmentendpointslist; } - if(highordertable != NULL) { - delete[] highordertable; - } + if(highordertable != NULL) { delete[] highordertable; } initializetetgenmesh(); } @@ -2258,9 +2240,7 @@ inline void tetgenmesh::tsbond(triface &t, face &s) // Allocate space for this tet. (t).tet[9] = (tetrahedron)tet2subpool->alloc(); // Initialize. - for(int i = 0; i < 4; i++) { - ((shellface *)(t).tet[9])[i] = NULL; - } + for(int i = 0; i < 4; i++) { ((shellface *)(t).tet[9])[i] = NULL; } } // Bond t <== s. ((shellface *)(t).tet[9])[(t).ver & 3] = @@ -2296,13 +2276,11 @@ inline void tetgenmesh::tspivot(triface &t, face &s) inline void tetgenmesh::stpivot(face &s, triface &t) { decode((tetrahedron)s.sh[9 + (s.shver & 1)], t); - if((t).tet == NULL) { - return; - } + if((t).tet == NULL) { return; } (t).ver = stpivottbl[t.ver][s.shver]; } - // Quickly check if this subface is attached to a tetrahedron. +// Quickly check if this subface is attached to a tetrahedron. #define isshtet(s) ((s).sh[9 + ((s).shver & 1)]) @@ -2310,9 +2288,7 @@ inline void tetgenmesh::stpivot(face &s, triface &t) inline void tetgenmesh::tsdissolve(triface &t) { - if((t).tet[9] != NULL) { - ((shellface *)(t).tet[9])[(t).ver & 3] = NULL; - } + if((t).tet[9] != NULL) { ((shellface *)(t).tet[9])[(t).ver & 3] = NULL; } } // stdissolve() dissolve a bond (from the subface side). @@ -2354,7 +2330,7 @@ inline void tetgenmesh::sspivot(face &s, face &edge) sdecode((shellface)s.sh[6 + (s.shver >> 1)], edge); } - // Quickly check if the edge is a subsegment. +// Quickly check if the edge is a subsegment. #define isshsubseg(s) ((s).sh[6 + ((s).shver >> 1)]) @@ -2370,9 +2346,7 @@ inline void tetgenmesh::tssbond1(triface &t, face &s) // Allocate space for this tet. (t).tet[8] = (tetrahedron)tet2segpool->alloc(); // Initialization. - for(int i = 0; i < 6; i++) { - ((shellface *)(t).tet[8])[i] = NULL; - } + for(int i = 0; i < 6; i++) { ((shellface *)(t).tet[8])[i] = NULL; } } ((shellface *)(t).tet[8])[ver2edge[(t).ver]] = sencode((s)); } @@ -2404,7 +2378,7 @@ inline void tetgenmesh::tsspivot1(triface &t, face &s) } } - // Quickly check whether 't' is a segment or not. +// Quickly check whether 't' is a segment or not. #define issubseg(t) ((t).tet[8] && ((t).tet[8])[ver2edge[(t).ver]]) @@ -2597,9 +2571,7 @@ inline bool tetgenmesh::issteinerpoint(point pt) inline void tetgenmesh::point2tetorg(point pa, triface &searchtet) { decode(point2tet(pa), searchtet); - if((point)searchtet.tet[4] == pa) { - searchtet.ver = 11; - } + if((point)searchtet.tet[4] == pa) { searchtet.ver = 11; } else if((point)searchtet.tet[5] == pa) { searchtet.ver = 3; } @@ -2616,9 +2588,7 @@ inline void tetgenmesh::point2tetorg(point pa, triface &searchtet) inline void tetgenmesh::point2shorg(point pa, face &searchsh) { sdecode(point2sh(pa), searchsh); - if((point)searchsh.sh[3] == pa) { - searchsh.shver = 0; - } + if((point)searchsh.sh[3] == pa) { searchsh.shver = 0; } else if((point)searchsh.sh[4] == pa) { searchsh.shver = (searchsh.sh[5] != NULL ? 2 : 1); } diff --git a/contrib/domhex/BGMBase.cpp b/contrib/domhex/BGMBase.cpp index df71464302c675915be5b1778bb52a6876d3ddbb..ebf8d7b58037a5f4f45bdb606dd3e4030fea9192 100644 --- a/contrib/domhex/BGMBase.cpp +++ b/contrib/domhex/BGMBase.cpp @@ -250,8 +250,7 @@ BGMBase::get_nodal_values(const MElement *e, std::vector<std::vector<double> > res(e->getNumVertices()); for(std::size_t i = 0; i < e->getNumVertices(); i++) { - auto itfind = - data.find(const_cast<MVertex *>(e->getVertex(i))); + auto itfind = data.find(const_cast<MVertex *>(e->getVertex(i))); for(int j = 0; j < 3; j++) res[i].push_back((itfind->second)[j]); } return res; diff --git a/contrib/domhex/BackgroundMesh2D.cpp b/contrib/domhex/BackgroundMesh2D.cpp index 0f62caf32f996eb61a99828794ba721eb4b794ba..84999c89e7f2789c797ef74dc76464ae0d2d51f1 100644 --- a/contrib/domhex/BackgroundMesh2D.cpp +++ b/contrib/domhex/BackgroundMesh2D.cpp @@ -111,13 +111,9 @@ void backgroundMesh2D::reset(bool erase_2D3D) create_face_mesh(); // computes the mesh sizes at nodes - if(CTX::instance()->mesh.lcFromPoints) { - computeSizeField(); - } + if(CTX::instance()->mesh.lcFromPoints) { computeSizeField(); } else - for(auto itv2 = - _2Dto3D.begin(); - itv2 != _2Dto3D.end(); ++itv2) + for(auto itv2 = _2Dto3D.begin(); itv2 != _2Dto3D.end(); ++itv2) sizeField[itv2->first] = CTX::instance()->mesh.lcMax; // ensure that other criteria are fullfilled @@ -211,14 +207,13 @@ void backgroundMesh2D::propagateValues(DoubleStorageType &dirichlet, linearSystemCSRGmm<double> *_lsys = new linearSystemCSRGmm<double>; _lsys->setGmres(1); #else - linearSystemFull<double> *_lsys = new linearSystemFull<double>; + linearSystemFull<double> *_lsys = new linearSystemFull<double>; #endif dofManager<double> myAssembler(_lsys); // fix boundary conditions - for(auto itv = dirichlet.begin(); - itv != dirichlet.end(); ++itv) { + for(auto itv = dirichlet.begin(); itv != dirichlet.end(); ++itv) { myAssembler.fixVertex(itv->first, 0, 1, itv->second); } @@ -257,9 +252,7 @@ void backgroundMesh2D::propagateValues(DoubleStorageType &dirichlet, } // Solve - if(myAssembler.sizeOfR()) { - _lsys->systemSolve(); - } + if(myAssembler.sizeOfR()) { _lsys->systemSolve(); } // save solution for(auto it = vs.begin(); it != vs.end(); ++it) { @@ -581,8 +574,7 @@ void frameFieldBackgroundMesh2D::computeSmoothness() // build vertex -> neighbors table std::multimap<MVertex *, MVertex *> vertex2vertex; - for(auto it = beginelements(); - it != endelements(); it++) { + for(auto it = beginelements(); it != endelements(); it++) { MElement *e = *it; for(std::size_t i = 0; i < e->getNumVertices(); i++) { MVertex *current = e->getVertex(i); @@ -595,8 +587,7 @@ void frameFieldBackgroundMesh2D::computeSmoothness() } // compute smoothness - for(auto it = beginvertices(); - it != endvertices(); it++) { + for(auto it = beginvertices(); it != endvertices(); it++) { MVertex *v = *it; double angle_current = angle(v); // compare to all neighbors... @@ -605,8 +596,8 @@ void frameFieldBackgroundMesh2D::computeSmoothness() range = vertex2vertex.equal_range(v); double minangle, totalangle = 0.; int N = 0; - for(auto itneighbor = range.first; - itneighbor != range.second; itneighbor++) { + for(auto itneighbor = range.first; itneighbor != range.second; + itneighbor++) { N++; minangle = M_PI / 2; MVertex *v_nb = itneighbor->second; @@ -636,8 +627,7 @@ void frameFieldBackgroundMesh2D::exportCrossField(const std::string &filename) deltas[0] = 0.; deltas[1] = M_PI; - for(auto it = beginvertices(); - it != endvertices(); it++) { + for(auto it = beginvertices(); it != endvertices(); it++) { MVertex *v = *it; double angle_current = angle(v); GPoint p = get_GPoint_from_MVertex(v); @@ -735,9 +725,7 @@ bool frameFieldBackgroundMesh2D::compute_RK_infos(double u, double v, double x, FieldManager *fields = gf->model()->getFields(); if(fields->getBackgroundField() > 0) { Field *f = fields->get(fields->getBackgroundField()); - if(!f->isotropic()) { - (*f)(x, y, z, infos.metricField, gf); - } + if(!f->isotropic()) { (*f)(x, y, z, infos.metricField, gf); } else { L = (*f)(x, y, z, gf); infos.metricField = SMetric3(1. / (L * L)); diff --git a/contrib/domhex/BackgroundMesh3D.cpp b/contrib/domhex/BackgroundMesh3D.cpp index 48acd511c5132b332c63232d774f8ba80ffe288e..b1be0546a065e5574ebd1a27707ae70132273e1b 100644 --- a/contrib/domhex/BackgroundMesh3D.cpp +++ b/contrib/domhex/BackgroundMesh3D.cpp @@ -69,8 +69,7 @@ void backgroundMesh3D::computeSizeField() MVertex *v; MElement *e; - for(auto it = faces.begin(); it != faces.end(); - it++) { // for all GFace + for(auto it = faces.begin(); it != faces.end(); it++) { // for all GFace GFace *face = *it; frameFieldBackgroundMesh2D *bgm2d = dynamic_cast<frameFieldBackgroundMesh2D *>(BGMManager::get(face)); @@ -118,7 +117,7 @@ void backgroundMesh3D::propagateValues(DoubleStorageType &dirichlet, linearSystemCSRGmm<double> *lsys = new linearSystemCSRGmm<double>; lsys->setGmres(1); #else - linearSystemFull<double> *lsys = new linearSystemFull<double>; + linearSystemFull<double> *lsys = new linearSystemFull<double>; #endif size_t i; @@ -149,9 +148,7 @@ void backgroundMesh3D::propagateValues(DoubleStorageType &dirichlet, for(it = interior.begin(); it != interior.end(); it++) { it2 = dirichlet.find(*it); - if(it2 == dirichlet.end()) { - assembler.numberVertex(*it, 0, 1); - } + if(it2 == dirichlet.end()) { assembler.numberVertex(*it, 0, 1); } } for(i = 0; i < gr->tetrahedra.size(); i++) { @@ -170,9 +167,7 @@ void backgroundMesh3D::propagateValues(DoubleStorageType &dirichlet, // printf("number of tetrahedra = %d\n",count2); // printf("volume = %f\n",volume); - if(assembler.sizeOfR()) { - lsys->systemSolve(); - } + if(assembler.sizeOfR()) { lsys->systemSolve(); } for(it = interior.begin(); it != interior.end(); it++) { assembler.getDofValue(*it, 0, 1, val); @@ -244,8 +239,7 @@ MVertex *backgroundMesh3D::get_nearest_neighbor(const double *xyz, candidates[i] = v; distances[i] = p.distance(v->point()); } - auto itmax = - std::max_element(distances.begin(), distances.end()); + auto itmax = std::max_element(distances.begin(), distances.end()); return candidates[std::distance(distances.begin(), itmax)]; // map<double,MVertex*> distances; @@ -289,9 +283,7 @@ frameFieldBackgroundMesh3D::frameFieldBackgroundMesh3D(GRegion *_gr) initiate_ANN_research(); initiate_crossfield(); - if(smooth_the_crossfield) { - computeCrossField(); - } + if(smooth_the_crossfield) { computeCrossField(); } else { computeSmoothnessOnlyFromBoundaries(); } @@ -313,8 +305,8 @@ void frameFieldBackgroundMesh3D::initiate_ANN_research() dataPtsBnd = annAllocPts(maxPts, 3); int i = 0; MVertex *v; - for(auto it = listOfBndVertices.begin(); - it != listOfBndVertices.end(); it++) { + for(auto it = listOfBndVertices.begin(); it != listOfBndVertices.end(); + it++) { v = *it; for(int k = 0; k < 3; ++k) dataPtsBnd[i][k] = (v->point())[k]; ++i; @@ -337,8 +329,8 @@ void frameFieldBackgroundMesh3D::computeSmoothnessOnlyFromBoundaries() double mean_angle = 0.; std::vector<double> vectorial_smoothness(3); - for(auto it_vertex = vert2elem.begin(); - it_vertex != vert2elem.end(); it_vertex++) { // for all vertices + for(auto it_vertex = vert2elem.begin(); it_vertex != vert2elem.end(); + it_vertex++) { // for all vertices themap.clear(); neighbors.clear(); MVertex const *current = it_vertex->first; @@ -348,8 +340,7 @@ void frameFieldBackgroundMesh3D::computeSmoothnessOnlyFromBoundaries() for(; itgraph != range.second; itgraph++) { // for all neighbors neighbors.insert(itgraph->second.second); } - for(auto it = neighbors.begin(); - it != neighbors.end(); it++) { + for(auto it = neighbors.begin(); it != neighbors.end(); it++) { themap.insert(std::make_pair(1., *it)); } @@ -386,8 +377,8 @@ void frameFieldBackgroundMesh3D::computeCrossField() std::map<MVertex const *const, bool> vertex_is_still; std::map<MVertex const *const, double> vertex_movement; - for(auto it_vertex = vert2elem.begin(); - it_vertex != vert2elem.end(); it_vertex++) { + for(auto it_vertex = vert2elem.begin(); it_vertex != vert2elem.end(); + it_vertex++) { MVertex const *const current = it_vertex->first; vertex_is_still[current] = current->onWhat()->dim() <= 2; @@ -397,8 +388,8 @@ void frameFieldBackgroundMesh3D::computeCrossField() // OLD - NEW COMPARISON std::map<MVertex const *, double> vertex_to_rank; - for(auto it_vertex = vert2elem.begin(); - it_vertex != vert2elem.end(); it_vertex++) { // for all vertices + for(auto it_vertex = vert2elem.begin(); it_vertex != vert2elem.end(); + it_vertex++) { // for all vertices // vertex_to_rank[it_vertex->first] = 0.; vertex_to_rank[it_vertex->first] = 1.; rank.insert(std::make_pair(0., it_vertex->first)); @@ -503,8 +494,7 @@ void frameFieldBackgroundMesh3D::computeCrossField() // iterations, convergence of the local cavity... for(; Nlocaliter < 20; Nlocaliter++) { - auto it_neighbors_to_trust = - neighbors_to_trust.begin(); + auto it_neighbors_to_trust = neighbors_to_trust.begin(); crossFieldSmoothness[current] = compare_to_neighbors(current->point(), ref, it_neighbors_to_trust, neighbors_to_trust.end(), mean_axis, mean_angle, @@ -577,8 +567,8 @@ void frameFieldBackgroundMesh3D::computeCrossField() } // end Niter iterations // also computes smoothness for boundary points - for(auto it_vertex = vert2elem.begin(); - it_vertex != vert2elem.end(); it_vertex++) { + for(auto it_vertex = vert2elem.begin(); it_vertex != vert2elem.end(); + it_vertex++) { MVertex const *const current = it_vertex->first; if(current->onWhat()->dim() <= 2) { auto itcurrent = crossField.find(current); @@ -632,8 +622,7 @@ void frameFieldBackgroundMesh3D::initiate_crossfield() std::vector<GFace *> faces = gr->faces(); // here, not using the gm2D since we are interested by the new 2D vertices, // not the old (now erased) ones... alternative would be to reset the 2DBGM... - for(auto it = faces.begin(); it != faces.end(); - it++) { // for all GFace + for(auto it = faces.begin(); it != faces.end(); it++) { // for all GFace GFace *face = *it; frameFieldBackgroundMesh2D *bgm2d = dynamic_cast<frameFieldBackgroundMesh2D *>(BGMManager::get(face)); @@ -846,8 +835,8 @@ void frameFieldBackgroundMesh3D::build_neighbors(const int &max_recursion_level) std::multimap<int, MVertex const *> proximity; // int counter=0; - for(auto it_vertex = vert2elem.begin(); - it_vertex != vert2elem.end(); it_vertex++) { // for all vertices + for(auto it_vertex = vert2elem.begin(); it_vertex != vert2elem.end(); + it_vertex++) { // for all vertices MVertex const *const current_vertex = it_vertex->first; visited.clear(); visited_elements.clear(); @@ -859,8 +848,7 @@ void frameFieldBackgroundMesh3D::build_neighbors(const int &max_recursion_level) get_recursive_neighbors(start, visited, visited_elements, proximity, max_recursion_level); - for(auto it1 = proximity.begin(); - it1 != proximity.end(); it1++) { + for(auto it1 = proximity.begin(); it1 != proximity.end(); it1++) { graph.insert(std::make_pair(current_vertex, std::make_pair(it1->first, it1->second))); } @@ -899,8 +887,8 @@ void frameFieldBackgroundMesh3D::get_recursive_neighbors( std::set<MVertex const *> new_vertices; - for(auto it_start = start.begin(); - it_start != start.end(); it_start++) { // for all initial vertices + for(auto it_start = start.begin(); it_start != start.end(); + it_start++) { // for all initial vertices MVertex const *current = *it_start; // std::cout << "get_recursive_neighbors : on vertex " << // current->getNum() @@ -1016,8 +1004,8 @@ double frameFieldBackgroundMesh3D::compare_to_neighbors( auto itan = all_angle.begin(); auto itpond = ponderations_vec.begin(); - for(auto ita = all_axis.begin(); - ita != all_axis.end(); ita++, itan++, itpond++) { + for(auto ita = all_axis.begin(); ita != all_axis.end(); + ita++, itan++, itpond++) { // mean_axis += ((*ita)*(*itan)); mean_axis += ((*ita) * (*itan)) * (*itpond); } diff --git a/contrib/domhex/BackgroundMeshManager.cpp b/contrib/domhex/BackgroundMeshManager.cpp index fec613218a52cf1128a16bdb59ea65ec55d89732..485a74c9aff90b364f8ec339af97c4ef106a4b15 100644 --- a/contrib/domhex/BackgroundMeshManager.cpp +++ b/contrib/domhex/BackgroundMeshManager.cpp @@ -27,9 +27,7 @@ void BGMManager::set_use_cross_field(bool b) BGMBase *BGMManager::get(GRegion *gf) { auto itfind = data.find(gf); - if(itfind != data.end()) { - return itfind->second; - } + if(itfind != data.end()) { return itfind->second; } BGMBase *bgm = use_cross_field ? new frameFieldBackgroundMesh3D(gf) : new backgroundMesh3D(gf); diff --git a/contrib/domhex/ThinLayer.cpp b/contrib/domhex/ThinLayer.cpp index 1f4c391abf12cf73029ddf9103f32ee9c9399921..fd85ecfd4b1be23e4483e7fd5f3e2a970a3f8022 100644 --- a/contrib/domhex/ThinLayer.cpp +++ b/contrib/domhex/ThinLayer.cpp @@ -66,9 +66,7 @@ void ThinLayer::perform() void ThinLayer::checkOppositeTriangles() { // all endTriangle will be set to active or not - for(auto it1 = - VertexToCorresp.begin(); - it1 != VertexToCorresp.end(); it1++) { + for(auto it1 = VertexToCorresp.begin(); it1 != VertexToCorresp.end(); it1++) { std::vector<CorrespVertices *> vecCorr = (*it1).second; for(unsigned int i = 0; i < vecCorr.size(); i++) { CorrespVertices *currentCorr = vecCorr[i]; @@ -76,12 +74,9 @@ void ThinLayer::checkOppositeTriangles() MVertex *endP0 = currentEndTri.v[0]; MVertex *endP1 = currentEndTri.v[1]; MVertex *endP2 = currentEndTri.v[2]; - auto it2 = - VertexToCorresp.find(endP0); - auto it3 = - VertexToCorresp.find(endP1); - auto it4 = - VertexToCorresp.find(endP2); + auto it2 = VertexToCorresp.find(endP0); + auto it3 = VertexToCorresp.find(endP1); + auto it4 = VertexToCorresp.find(endP2); (*it1).second[i]->setEndTriangleActive(false); if(it2 != VertexToCorresp.end()) { if(it3 != VertexToCorresp.end()) { @@ -102,9 +97,7 @@ void ThinLayer::checkOppositeTriangles() void ThinLayer::fillvecOfThinSheets() { - for(auto it1 = - VertexToCorresp.begin(); - it1 != VertexToCorresp.end(); it1++) { + for(auto it1 = VertexToCorresp.begin(); it1 != VertexToCorresp.end(); it1++) { std::vector<CorrespVertices *> vecCorr = (*it1).second; for(unsigned int i = 0; i < vecCorr.size(); i++) { CorrespVertices *currentCorr = vecCorr[i]; @@ -117,8 +110,7 @@ void ThinLayer::fillvecOfThinSheets() (*it1).second[i]->setTagMaster(-1); faceXtet faceEndSlave = (*it1).second[i]->getEndTriangle(); for(unsigned int j = 0; j < 3; j++) { - auto it2 = - VertexToCorresp.find(faceEndSlave.v[j]); + auto it2 = VertexToCorresp.find(faceEndSlave.v[j]); if(it2 != VertexToCorresp.end()) { if(faceEndSlave.v[j]->onWhat()->dim() == 2) { (*it2).second[0]->setTagMaster( @@ -137,8 +129,7 @@ void ThinLayer::fillvecOfThinSheets() for(std::size_t k = 0; k < surroundingTet[j]->getNumVertices(); k++) { MVertex *ToInsertTmp = surroundingTet[j]->getVertex(k); - auto - it2 = VertexToCorresp.find(ToInsertTmp); + auto it2 = VertexToCorresp.find(ToInsertTmp); if(ToInsertTmp->onWhat()->tag() == VToDo->onWhat()->tag()) { // TODO: OR that onwhat -> dim <, for edges if(it2 != VertexToCorresp.end()) { @@ -151,8 +142,7 @@ void ThinLayer::fillvecOfThinSheets() (*it2).second[0]->setTagMaster(-1); faceXtet faceEndSlave2 = (*it2).second[0]->getEndTriangle(); for(unsigned int j = 0; j < 3; j++) { - auto it3 = - VertexToCorresp.find(faceEndSlave2.v[j]); + auto it3 = VertexToCorresp.find(faceEndSlave2.v[j]); if(it3 != VertexToCorresp.end()) { if(faceEndSlave2.v[j]->onWhat()->dim() == 2) { (*it3).second[0]->setTagMaster( @@ -202,8 +192,7 @@ std::map<MVertex *, double> ThinLayer::computeAllDistToOppSide() } } } - for(auto it = BoundaryVertices.begin(); - it != BoundaryVertices.end(); it++) { + for(auto it = BoundaryVertices.begin(); it != BoundaryVertices.end(); it++) { MVertex *toCompute = (*it); double resultTmp = computeDistToOppSide(toCompute); AllDistToOppSide[toCompute] = resultTmp; @@ -418,9 +407,7 @@ MTet4 *ThinLayer::getTetFromPoint(MVertex *v, const SVector3 &InteriorNormal) ThinLayer::IsPositivOrientation(vecDir[2], vecDir[0], InteriorNormal); if(isPositiv1) { if(isPositiv2) { - if(isPositiv3) { - TetToGet = TetToTet4[currentVecTet[i]]; - } + if(isPositiv3) { TetToGet = TetToTet4[currentVecTet[i]]; } } } } @@ -435,9 +422,7 @@ bool ThinLayer::IsPositivOrientation(const SVector3 &a, const SVector3 &b, a.x() * b.y() - a.y() * b.x()); double ProdScal = ProdVec.x() * c.x() + ProdVec.y() * c.y() + ProdVec.z() * c.z(); - if(ProdScal >= 0.0) { - result = true; - } + if(ProdScal >= 0.0) { result = true; } return result; } diff --git a/contrib/domhex/ThinLayer.h b/contrib/domhex/ThinLayer.h index 631d4fa44ef49f9169430ad47bb5f1e144d32a8c..57bc60d363fe97517c684c4c7fd22d9b1e38f04f 100644 --- a/contrib/domhex/ThinLayer.h +++ b/contrib/domhex/ThinLayer.h @@ -30,8 +30,9 @@ struct faceXtet { v[0] = std::min(std::min(v0, v1), v2); v[2] = std::max(std::max(v0, v1), v2); - v[1] = - (v0 != v[0] && v0 != v[2]) ? v0 : (v1 != v[0] && v1 != v[2]) ? v1 : v2; + v[1] = (v0 != v[0] && v0 != v[2]) ? v0 : + (v1 != v[0] && v1 != v[2]) ? v1 : + v2; // // std::sort(v, v + 3); } diff --git a/contrib/domhex/cross3D.h b/contrib/domhex/cross3D.h index a0a8fb4f76c19ec30bd68a5a8908dd5efe7ae995..803b9ffa89daa97f5d467f20d9bea7b34eb158a1 100644 --- a/contrib/domhex/cross3D.h +++ b/contrib/domhex/cross3D.h @@ -552,16 +552,12 @@ double computeSetSmoothness(std::vector<cross3D> S) } } // on a trouve le quat approprie - for(unsigned int j = 0; j < 4; j++) { - qmean[j] += qTmp[j]; - } + for(unsigned int j = 0; j < 4; j++) { qmean[j] += qTmp[j]; } } double normQt = sqrt(qmean[0] * qmean[0] + qmean[1] * qmean[1] + qmean[2] * qmean[2] + qmean[3] * qmean[3]); if(normQt != 0.0) { - for(unsigned int j = 0; j < 4; j++) { - qmean[j] = qmean[j] / normQt; - } + for(unsigned int j = 0; j < 4; j++) { qmean[j] = qmean[j] / normQt; } } for(it1 = S.begin(); it1 != S.end(); it1++) { // pour chaque element du set @@ -572,9 +568,7 @@ double computeSetSmoothness(std::vector<cross3D> S) // on trouve la cross appropriee Qtn qTmpi = cTmp.get(i).correspQuat(); double prodVeci = 0.0; - for(unsigned int j = 0; j < 4; j++) { - prodVeci += qmean[j] * qTmpi.v[j]; - } + for(unsigned int j = 0; j < 4; j++) { prodVeci += qmean[j] * qTmpi.v[j]; } if(prodVeci >= 0.0) { if(prodVeci > prodVecMin) { prodVecMin = prodVeci; @@ -591,9 +585,7 @@ double computeSetSmoothness(std::vector<cross3D> S) } } // on a trouve le quat approprie - if(prodVecMin < result) { - result = prodVecMin; - } + if(prodVecMin < result) { result = prodVecMin; } } return result; } diff --git a/contrib/domhex/directions3D.cpp b/contrib/domhex/directions3D.cpp index cc15a5558e79554c5c9ea0e005b92da38a1f28a6..35d403c4ea772010d9cb358d56f5457b9377a36e 100644 --- a/contrib/domhex/directions3D.cpp +++ b/contrib/domhex/directions3D.cpp @@ -116,9 +116,7 @@ STensor3 Frame_field::search(double x, double y, double z) ANNidxArray indices; ANNdistArray distances; - if(field.size() <= 1) { - return STensor3(1.0); - } + if(field.size() <= 1) { return STensor3(1.0); } query = annAllocPt(3); query[0] = x; @@ -141,9 +139,7 @@ STensor3 Frame_field::search(double x, double y, double z) #endif if(fabs(sqrt(distance2) - sqrt(distance1)) < e2) { - if(labels[index2] < labels[index1]) { - return field[index2].second; - } + if(labels[index2] < labels[index1]) { return field[index2].second; } else { return field[index1].second; } @@ -178,9 +174,7 @@ STensor3 Frame_field::combine(double x, double y, double z) val2 = fabs(dot(vec, vec2)); val3 = fabs(dot(vec, vec3)); - if(val1 <= val2 && val1 <= val3) { - other = vec1; - } + if(val1 <= val2 && val1 <= val3) { other = vec1; } else if(val2 <= val1 && val2 <= val3) { other = vec2; } @@ -346,8 +340,7 @@ int Frame_field::build_vertex_to_vertices(GEntity *gr, int onWhat, MVertex *pVertex = pElem->getVertex(j); if(onWhat > 0 && pVertex->onWhat()->dim() != onWhat) continue; - auto it = - vertex_to_vertices.find(pVertex); + auto it = vertex_to_vertices.find(pVertex); if(it != vertex_to_vertices.end()) { for(unsigned int k = 1; k < n; k++) it->second.insert(pElem->getVertex((j + k) % n)); @@ -373,8 +366,7 @@ int Frame_field::build_vertex_to_elements(GEntity *gr, bool initialize) unsigned int n = pElem->getNumVertices(); for(unsigned int j = 0; j < n; j++) { MVertex *pVertex = pElem->getVertex(j); - auto it = - vertex_to_elements.find(pVertex); + auto it = vertex_to_elements.find(pVertex); if(it != vertex_to_elements.end()) it->second.insert(pElem); else { @@ -400,8 +392,7 @@ void Frame_field::build_listVertices(GEntity *gr, int dim, bool initialize) } if(initialize) listVertices.clear(); - for(auto it = list.begin(); it != list.end(); - it++) { + for(auto it = list.begin(); it != list.end(); it++) { listVertices.push_back(*it); } } @@ -464,8 +455,7 @@ void Frame_field::initFace(GFace *gf) it != vertex_to_elements.end(); it++) { std::set<MElement *> elements = it->second; SVector3 Area = SVector3(0, 0, 0); - for(auto iter = elements.begin(); - iter != elements.end(); iter++) { + for(auto iter = elements.begin(); iter != elements.end(); iter++) { MElement *pElem = *iter; int n = pElem->getNumVertices(); int i; @@ -497,8 +487,7 @@ void Frame_field::initFace(GFace *gf) // of gf std::vector<GEdge *> const &edges = gf->edges(); vertex_to_elements.clear(); - for(auto it = edges.begin(); - it != edges.end(); it++) { + for(auto it = edges.begin(); it != edges.end(); it++) { build_vertex_to_elements(*it, false); } @@ -639,8 +628,7 @@ double Frame_field::findBarycenter( SVector3 T = SVector3(0.), dT; double temp = 0.; energy = 0; - for(auto it = list.begin(); it != list.end(); - ++it) { + for(auto it = list.begin(); it != list.end(); ++it) { MVertex *pVertex = *it; if(pVertex->getNum() == pVertex0->getNum()) std::cout << "This should not happen!" << std::endl; @@ -713,26 +701,18 @@ void Frame_field::buildSmoothness() MVertex *v0 = entities[i]->mesh_vertices[j]; V1.insert(v0); std::vector<MVertex *> v0vec = Neighbours[v0]; - for(unsigned int k = 0; k < v0vec.size(); k++) { - V1.insert(v0vec[k]); - } - for(auto itSet = V1.begin(); itSet != V1.end(); - itSet++) { + for(unsigned int k = 0; k < v0vec.size(); k++) { V1.insert(v0vec[k]); } + for(auto itSet = V1.begin(); itSet != V1.end(); itSet++) { MVertex *vTmp = (*itSet); V2.insert(vTmp); v0vec = Neighbours[vTmp]; - for(unsigned int k = 0; k < v0vec.size(); k++) { - V2.insert(v0vec[k]); - } + for(unsigned int k = 0; k < v0vec.size(); k++) { V2.insert(v0vec[k]); } } - for(auto itSet = V2.begin(); itSet != V2.end(); - itSet++) { + for(auto itSet = V2.begin(); itSet != V2.end(); itSet++) { MVertex *vTmp = (*itSet); V3.insert(vTmp); v0vec = Neighbours[vTmp]; - for(unsigned int k = 0; k < v0vec.size(); k++) { - V3.insert(v0vec[k]); - } + for(unsigned int k = 0; k < v0vec.size(); k++) { V3.insert(v0vec[k]); } } // we have all three set here, time to compute the smoothnesses for each // one @@ -742,22 +722,19 @@ void Frame_field::buildSmoothness() double S1 = 0.0; double S2 = 0.0; double S3 = 0.0; - for(auto itSet = V1.begin(); itSet != V1.end(); - itSet++) { + for(auto itSet = V1.begin(); itSet != V1.end(); itSet++) { MVertex *vTmp = (*itSet); STensor3 tTmp = crossField[vTmp]; cross3D cTmp = cross3D(tTmp); C1.push_back(cTmp); } - for(auto itSet = V2.begin(); itSet != V2.end(); - itSet++) { + for(auto itSet = V2.begin(); itSet != V2.end(); itSet++) { MVertex *vTmp = (*itSet); STensor3 tTmp = crossField[vTmp]; cross3D cTmp = cross3D(tTmp); C2.push_back(cTmp); } - for(auto itSet = V3.begin(); itSet != V3.end(); - itSet++) { + for(auto itSet = V3.begin(); itSet != V3.end(); itSet++) { MVertex *vTmp = (*itSet); STensor3 tTmp = crossField[vTmp]; cross3D cTmp = cross3D(tTmp); @@ -874,8 +851,7 @@ void Frame_field::recur_connect_vert(FILE *fi, int count, MVertex *v, count++; - for(auto it = v2v.lower_bound(v); - it != v2v.upper_bound(v); ++it) { + for(auto it = v2v.lower_bound(v); it != v2v.upper_bound(v); ++it) { MVertex *nextV = it->second; if(touched.find(nextV) == touched.end()) { // compute dot product (N0,R0,A0) dot (Ni,Ri,Ai)^T @@ -912,9 +888,7 @@ void Frame_field::recur_connect_vert(FILE *fi, int count, MVertex *v, // create new cross fullMatrix<double> newmat(3, 3); for(int i = 0; i < 3; i++) { - for(int j = 0; j < 3; j++) { - newmat(i, j) = nextCross(Id(i), j); - } + for(int j = 0; j < 3; j++) { newmat(i, j) = nextCross(Id(i), j); } } STensor3 newcross(0.0); @@ -971,8 +945,7 @@ void Frame_field::continuousCrossField(GRegion *gr, GFace *gf) iter != vertex_to_vertices.end(); ++iter) { MVertex *v = iter->first; std::set<MVertex *> mySet = iter->second; - for(auto it = mySet.begin(); it != mySet.end(); - ++it) { + for(auto it = mySet.begin(); it != mySet.end(); ++it) { v2v.insert(std::make_pair(v, *it)); } } @@ -1046,8 +1019,7 @@ void Frame_field::save_dist(const std::string &filename) std::ofstream file(filename.c_str()); file << "View \"Distance\" {\n"; - for(auto it = crossDist.begin(); - it != crossDist.end(); it++) { + for(auto it = crossDist.begin(); it != crossDist.end(); it++) { MVertex *pVerta = it->first.getVertex(0); MVertex *pVertb = it->first.getVertex(1); double value = it->second * 180. / M_PI; @@ -1118,8 +1090,7 @@ void Frame_field::save_energy(GRegion *gr, const std::string &filename) matvec(inv, gsf[nod1], grd1); matvec(inv, gsf[nod2], grd2); SVector3 esf = sf[nod1] * SVector3(grd2) - sf[nod2] * SVector3(grd1); - auto it = - crossDist.find(pTet->getEdge(k)); + auto it = crossDist.find(pTet->getEdge(k)); sum += it->second * esf; // sum += (pTet->getVertex(nod2)->z() - pTet->getVertex(nod1)->z()) * // esf; @@ -1254,9 +1225,7 @@ void Size_field::solve(GRegion *gr) for(it = interior.begin(); it != interior.end(); it++) { it2 = boundary.find(*it); - if(it2 == boundary.end()) { - assembler.numberVertex(*it, 0, 1); - } + if(it2 == boundary.end()) { assembler.numberVertex(*it, 0, 1); } } for(i = 0; i < gr->tetrahedra.size(); i++) { @@ -1276,9 +1245,7 @@ void Size_field::solve(GRegion *gr) // printf("number of tetrahedra = %d\n",count2); // printf("volume = %f\n",volume); - if(assembler.sizeOfR()) { - system->systemSolve(); - } + if(assembler.sizeOfR()) { system->systemSolve(); } for(it = interior.begin(); it != interior.end(); it++) { assembler.getDofValue(*it, 0, 1, val); @@ -1354,13 +1321,9 @@ void Size_field::print_field(GRegion *gr) // y = (it->first)->y(); // z = (it->first)->z(); - if(it->second > max) { - max = it->second; - } + if(it->second > max) { max = it->second; } - if(it->second < min) { - min = it->second; - } + if(it->second < min) { min = it->second; } // printf("x = %f, y = %f, z = %f, mesh size = %f\n",x,y,z,it->second); } @@ -1680,9 +1643,7 @@ double Nearest_point::clamp(double x, double min, double max) val = x; - if(val < min) { - val = min; - } + if(val < min) { val = min; } else if(val > max) { val = max; } diff --git a/contrib/domhex/meshGFaceQuadrilateralize.cpp b/contrib/domhex/meshGFaceQuadrilateralize.cpp index 3e772d15496584443a103738dd9f08249d721459..809ff8dfdf3d94d5287f2166119ca362c38fb32e 100644 --- a/contrib/domhex/meshGFaceQuadrilateralize.cpp +++ b/contrib/domhex/meshGFaceQuadrilateralize.cpp @@ -352,9 +352,7 @@ bool edgeFront::formQuad(BDS_Edge *e, BDS_Edge *left, BDS_Edge *right) BDS_Point *p = toUpdate[i]; for(std::list<BDS_Edge *>::iterator itp = p->edges.begin(); itp != p->edges.end(); ++itp) { - if(inFront(*itp)) { - updateStatus(*itp); - } + if(inFront(*itp)) { updateStatus(*itp); } } } return true; diff --git a/contrib/domhex/pointInsertion.cpp b/contrib/domhex/pointInsertion.cpp index 92ddbde97f55000e8a7678e5216285e551fb1f7f..64b92cc86f4ef2ab4070973f97c33d408fd20a22 100644 --- a/contrib/domhex/pointInsertion.cpp +++ b/contrib/domhex/pointInsertion.cpp @@ -33,8 +33,7 @@ void print_nodal_info(const std::string &filename, std::ofstream out(filename.c_str()); out << "View \"\"{" << std::endl; - for(auto it = map.begin(); - it != map.end(); it++) { + for(auto it = map.begin(); it != map.end(); it++) { MVertex *v = it->first; out << "SP( " << v->x() << "," << v->y() << "," << v->z() << "){" << it->second << "};" << std::endl; @@ -128,9 +127,7 @@ bool computeFourNeighbors(frameFieldBackgroundMesh2D *bgm, double L = infos.localsize; double newPoint[4][2]; for(int j = 0; j < 2; j++) { - for(int i = 0; i < 4; i++) { - newPoint[i][j] = newP[i][0][j]; - } + for(int i = 0; i < 4; i++) { newPoint[i][j] = newP[i][0][j]; } } double ERR[4]; for(int i = 0; i < 4; i++) { // @@ -536,8 +533,7 @@ bool Filler3D::treat_region(GRegion *gr) MElement *element; MVertex *vertex; std::vector<GFace *> faces = gr->faces(); - for(auto it = faces.begin(); it != faces.end(); - it++) { + for(auto it = faces.begin(); it != faces.end(); it++) { GFace *gf = *it; // int limit = code_kesskessai(gf->tag()); for(unsigned int i = 0; i < gf->getNumMeshElements(); i++) { @@ -583,9 +579,7 @@ bool Filler3D::treat_region(GRegion *gr) bgm->eval_approximate_crossfield(closest, svp->cf); fifo->insert(svp); - if(debug) { - smoothness_forplot[svp->v] = svp->rank; - } + if(debug) { smoothness_forplot[svp->v] = svp->rank; } } else { STensor3 temp; @@ -715,9 +709,7 @@ bool Filler3D::treat_region(GRegion *gr) } } } - if(!spawn_created) { - delete individual; - } + if(!spawn_created) { delete individual; } } // end loop on spawns } diff --git a/contrib/domhex/pointInsertionRTreeTools.h b/contrib/domhex/pointInsertionRTreeTools.h index 7c22eb870a158cc8f1e1be14ec3d8da48c76318d..32498f9b963017867bd0dc26b89db0c4449529cd 100644 --- a/contrib/domhex/pointInsertionRTreeTools.h +++ b/contrib/domhex/pointInsertionRTreeTools.h @@ -43,9 +43,9 @@ public: + p1 */ - surfacePointWithExclusionRegion(MVertex *v, SPoint2 p[4][NUMDIR], - SPoint2 &_mp, SMetric3 &meshMetric, - surfacePointWithExclusionRegion *father = nullptr); + surfacePointWithExclusionRegion( + MVertex *v, SPoint2 p[4][NUMDIR], SPoint2 &_mp, SMetric3 &meshMetric, + surfacePointWithExclusionRegion *father = nullptr); bool inExclusionZone(const SPoint2 &p); void minmax(double _min[2], double _max[2]) const; @@ -107,9 +107,14 @@ private: bool ok; public: - Wrapper3D() : individual(nullptr), parent(nullptr), size(nullptr), cf(nullptr), vec(nullptr), ok(true) {} + Wrapper3D() + : individual(nullptr), parent(nullptr), size(nullptr), cf(nullptr), + vec(nullptr), ok(true) + { + } Wrapper3D(MVertex *_i, MVertex *_p) - : individual(_i), parent(_p), size(nullptr), cf(nullptr), vec(nullptr), ok(true) + : individual(_i), parent(_p), size(nullptr), cf(nullptr), vec(nullptr), + ok(true) { } ~Wrapper3D() {} diff --git a/contrib/domhex/simple3D.cpp b/contrib/domhex/simple3D.cpp index 16086c1d5aae4dc7d146e5571eba6b9d08424161..88770a91bbe64e05cbc21d8df6708a37ff36a71f 100644 --- a/contrib/domhex/simple3D.cpp +++ b/contrib/domhex/simple3D.cpp @@ -282,9 +282,7 @@ void Filler::treat_model() for(it = model->firstRegion(); it != model->lastRegion(); it++) { gr = *it; - if(gr->getNumMeshElements() > 0) { - treat_region(gr); - } + if(gr->getNumMeshElements() > 0) { treat_region(gr); } } } @@ -347,21 +345,15 @@ void Filler::treat_region(GRegion *gr) } for(it = temp.begin(); it != temp.end(); it++) { - if((*it)->onWhat()->dim() == 0) { - boundary_vertices.push_back(*it); - } + if((*it)->onWhat()->dim() == 0) { boundary_vertices.push_back(*it); } } for(it = temp.begin(); it != temp.end(); it++) { - if((*it)->onWhat()->dim() == 1) { - boundary_vertices.push_back(*it); - } + if((*it)->onWhat()->dim() == 1) { boundary_vertices.push_back(*it); } } for(it = temp.begin(); it != temp.end(); it++) { - if((*it)->onWhat()->dim() == 2) { - boundary_vertices.push_back(*it); - } + if((*it)->onWhat()->dim() == 2) { boundary_vertices.push_back(*it); } } std::queue<Node *> fifo; @@ -394,9 +386,7 @@ void Filler::treat_region(GRegion *gr) } std::vector<Node *> spawns(6); - for(int i = 0; i < 6; i++) { - spawns[i] = new Node(); - } + for(int i = 0; i < 6; i++) { spawns[i] = new Node(); } create_spawns(gr, octree, parent, spawns); @@ -433,9 +423,7 @@ void Filler::treat_region(GRegion *gr) if(!ok2) delete individual; } - if(count % 100 == 0) { - printf("%d\n", count); - } + if(count % 100 == 0) { printf("%d\n", count); } count++; } @@ -501,9 +489,7 @@ Metric Filler::get_metric(double x, double y, double z, GEntity *ge) manager = ge->model()->getFields(); if(manager->getBackgroundField() > 0) { field = manager->get(manager->getBackgroundField()); - if(field) { - (*field)(x, y, z, temp, ge); - } + if(field) { (*field)(x, y, z, temp, ge); } } m.set_m11(v1.x()); @@ -536,9 +522,7 @@ double Filler::get_size(double x, double y, double z, GEntity *ge) manager = ge->model()->getFields(); if(manager->getBackgroundField() > 0) { field = manager->get(manager->getBackgroundField()); - if(field) { - h = (*field)(x, y, z, ge); - } + if(field) { h = (*field)(x, y, z, ge); } } return h; @@ -574,8 +558,8 @@ bool Filler::far_from_boundary(MElementOctree *octree, Node *node) e5 = (MElement *)octree->find(x, y, z + k2 * h, 3, true); e6 = (MElement *)octree->find(x, y, z - k2 * h, 3, true); - if(e1 != nullptr && e2 != nullptr && e3 != nullptr && e4 != nullptr && e5 != nullptr && - e6 != nullptr) + if(e1 != nullptr && e2 != nullptr && e3 != nullptr && e4 != nullptr && + e5 != nullptr && e6 != nullptr) return 1; else return 0; @@ -684,18 +668,14 @@ double Filler::improvement(GEntity *ge, MElementOctree *octree, y = point.y() + h1 * direction.y(); z = point.z() + h1 * direction.z(); - if(inside_domain(octree, x, y, z)) { - h2 = get_size(x, y, z); - } + if(inside_domain(octree, x, y, z)) { h2 = get_size(x, y, z); } else h2 = h1; coeffA = 1.0; coeffB = 0.16; - if(h2 > h1) { - average = coeffA * h1 + (1.0 - coeffA) * h2; - } + if(h2 > h1) { average = coeffA * h1 + (1.0 - coeffA) * h2; } else { average = coeffB * h1 + (1.0 - coeffB) * h2; } diff --git a/contrib/domhex/surfaceFiller.cpp b/contrib/domhex/surfaceFiller.cpp index c5da3cb993d2a3ca605809adc14998dd18dc73f4..003bb90d58065c0ed5829474407a46432a63c208 100644 --- a/contrib/domhex/surfaceFiller.cpp +++ b/contrib/domhex/surfaceFiller.cpp @@ -243,8 +243,8 @@ double get_smoothness(MVertex *v, GFace *gf, elem = backgroundMesh::current()->getMeshElementByCoord( param_point[0], param_point[1], 0., false); if(!elem) - Msg::Warning("No element found for coordinate (%g, %g, %g)", - sp3.x(), sp3.y(), sp3.z()); + Msg::Warning("No element found for coordinate (%g, %g, %g)", sp3.x(), + sp3.y(), sp3.z()); } // recover element's vertices: @@ -266,11 +266,9 @@ double get_smoothness(MVertex *v, GFace *gf, // interpolate : double val[3]; int i = 0; - for(auto it = localvertices.begin(); - it != localvertices.end(); it++) { + for(auto it = localvertices.begin(); it != localvertices.end(); it++) { MVertex *localv = *it; - auto itfind = - vertices2smoothness.find(localv); + auto itfind = vertices2smoothness.find(localv); if(itfind == vertices2smoothness.end()) { Msg::Warning("Background vertex not found"); return 0; @@ -281,7 +279,8 @@ double get_smoothness(MVertex *v, GFace *gf, return res; } -void print_nodal_info_int(const std::string &filename, std::map<MVertex *, int> &mapp) +void print_nodal_info_int(const std::string &filename, + std::map<MVertex *, int> &mapp) { std::ofstream out(filename.c_str()); @@ -303,8 +302,7 @@ void print_nodal_info_double(const std::string &filename, std::ofstream out(filename.c_str()); out << "View \"\"{" << std::endl; - for(auto it = mapp.begin(); it != mapp.end(); - it++) { + for(auto it = mapp.begin(); it != mapp.end(); it++) { MVertex *v = it->first; out << "SP( " << v->x() << "," << v->y() << "," << v->z() << "){" << it->second << "};" << std::endl; @@ -360,7 +358,7 @@ void export_point(surfacePointWithExclusionRegion *sp, int DIR, FILE *crossf, double size_1 = sqrt(1. / dot(t1, metricField, t1)); double size_2 = sqrt(1. / dot(t2, metricField, t2)); - if(crossf){ + if(crossf) { fprintf(crossf, "VP(%g,%g,%g) {%g,%g,%g};\n", sp->_v->x(), sp->_v->y(), sp->_v->z(), t1.x() * size_1, t1.y() * size_1, t1.z() * size_1); fprintf(crossf, "VP(%g,%g,%g) {%g,%g,%g};\n", sp->_v->x(), sp->_v->y(), @@ -521,8 +519,7 @@ void packingOfParallelogramsSmoothness(GFace *gf, // build vertex -> neighbors table std::multimap<MVertex *, MVertex *> vertex2vertex; - for(auto it = - backgroundMesh::current()->begin_triangles(); + for(auto it = backgroundMesh::current()->begin_triangles(); it != backgroundMesh::current()->end_triangles(); it++) { MElement *e = *it; for(std::size_t i = 0; i < e->getNumVertices(); i++) { @@ -538,8 +535,7 @@ void packingOfParallelogramsSmoothness(GFace *gf, // build table vertex->smoothness std::map<MVertex *, double> vertices2smoothness; std::map<MVertex *, double> smoothness_essai; - for(auto it = - backgroundMesh::current()->begin_vertices(); + for(auto it = backgroundMesh::current()->begin_vertices(); it != backgroundMesh::current()->end_vertices(); it++) { MVertex *v = *it; @@ -559,8 +555,8 @@ void packingOfParallelogramsSmoothness(GFace *gf, double covar1_nb[2], covar2_nb[2], L_nb, size_param_1_nb, size_param_2_nb; double maxprod, angle = 0.; int N = 0; - for(auto itneighbor = range.first; - itneighbor != range.second; itneighbor++) { + for(auto itneighbor = range.first; itneighbor != range.second; + itneighbor++) { N++; maxprod = 0.; MVertex *v_nb = itneighbor->second; @@ -586,8 +582,7 @@ void packingOfParallelogramsSmoothness(GFace *gf, ss << "backgroundmesh_element_smoothness_" << gf->tag() << ".pos"; std::ofstream out(ss.str().c_str()); out << "View \"directions\" {" << std::endl; - for(auto it = - backgroundMesh::current()->begin_triangles(); + for(auto it = backgroundMesh::current()->begin_triangles(); it != backgroundMesh::current()->end_triangles(); it++) { MElement *e = *it; std::vector<MVertex *> nodes; @@ -643,9 +638,7 @@ void packingOfParallelogramsSmoothness(GFace *gf, char NAME[345]; sprintf(NAME, "crossReal%d.pos", gf->tag()); FILE *crossf = nullptr; - if(debug) { - crossf = Fopen(NAME, "w"); - } + if(debug) { crossf = Fopen(NAME, "w"); } if(crossf) fprintf(crossf, "View \"\"{\n"); for(; it != bnd_vertices.end(); ++it) { SPoint2 midpoint; @@ -660,9 +653,7 @@ void packingOfParallelogramsSmoothness(GFace *gf, mp.rank = get_smoothness(*it, gf, vertices2smoothness); fifo.insert(mp); - if(debug) { - smoothness_essai[*it] = mp.rank; - } + if(debug) { smoothness_essai[*it] = mp.rank; } vertices.push_back(sp); double _min[2], _max[2]; @@ -725,14 +716,13 @@ void packingOfParallelogramsSmoothness(GFace *gf, } // add the vertices as additional vertices in the surface mesh - char ccc[256]; sprintf(ccc,"points%d.pos",gf->tag()); + char ccc[256]; + sprintf(ccc, "points%d.pos", gf->tag()); FILE *f = nullptr; - if(debug){ - f = Fopen(ccc,"w"); - } + if(debug) { f = Fopen(ccc, "w"); } if(f) fprintf(f, "View \"\"{\n"); for(unsigned int i = 0; i < vertices.size(); i++) { - if(f) vertices[i]->print(f,i); + if(f) vertices[i]->print(f, i); if(vertices[i]->_v->onWhat() == gf) { packed.push_back(vertices[i]->_v); metrics.push_back(vertices[i]->_meshMetric); @@ -741,8 +731,8 @@ void packingOfParallelogramsSmoothness(GFace *gf, } delete vertices[i]; } - if(f){ - fprintf(f,"};"); + if(f) { + fprintf(f, "};"); fclose(f); } } @@ -761,7 +751,7 @@ void packingOfParallelograms(GFace *gf, std::vector<MVertex *> &packed, const bool goNonLinear = true; - if(debug){ + if(debug) { std::stringstream ssa; ssa << "oldbgm_angles_" << gf->tag() << ".pos"; backgroundMesh::current()->print(ssa.str(), gf, 1); @@ -779,7 +769,8 @@ void packingOfParallelograms(GFace *gf, std::vector<MVertex *> &packed, // put boundary vertices in a fifo queue std::set<surfacePointWithExclusionRegion *, - compareSurfacePointWithExclusionRegionPtr> fifo; + compareSurfacePointWithExclusionRegionPtr> + fifo; std::vector<surfacePointWithExclusionRegion *> vertices; // put the RTREE RTree<surfacePointWithExclusionRegion *, double, 2, double> rtree; @@ -790,9 +781,7 @@ void packingOfParallelograms(GFace *gf, std::vector<MVertex *> &packed, char NAME[345]; sprintf(NAME, "crossReal%d.pos", gf->tag()); FILE *crossf = nullptr; - if(debug) { - crossf = Fopen(NAME, "w"); - } + if(debug) { crossf = Fopen(NAME, "w"); } if(crossf) fprintf(crossf, "View \"\"{\n"); for(; it != bnd_vertices.end(); ++it) { SPoint2 midpoint; @@ -844,9 +833,7 @@ void packingOfParallelograms(GFace *gf, std::vector<MVertex *> &packed, char ccc[256]; sprintf(ccc, "points%d.pos", gf->tag()); FILE *f = nullptr; - if(debug){ - f = Fopen(ccc, "w"); - } + if(debug) { f = Fopen(ccc, "w"); } if(f) fprintf(f, "View \"\"{\n"); for(unsigned int i = 0; i < vertices.size(); i++) { // if(vertices[i]->_v->onWhat() != gf) @@ -894,7 +881,8 @@ void packingOfParallelogramsConstrained( // put boundary vertices in a fifo queue std::set<surfacePointWithExclusionRegion *, - compareSurfacePointWithExclusionRegionPtr> fifo; + compareSurfacePointWithExclusionRegionPtr> + fifo; std::vector<surfacePointWithExclusionRegion *> vertices; // put the RTREE RTree<surfacePointWithExclusionRegion *, double, 2, double> rtree; @@ -905,9 +893,7 @@ void packingOfParallelogramsConstrained( char NAME[345]; sprintf(NAME, "crossReal%d.pos", gf->tag()); FILE *crossf = NULL; - if(debug){ - crossf = Fopen(NAME, "w"); - } + if(debug) { crossf = Fopen(NAME, "w"); } if(crossf) fprintf(crossf, "View \"\"{\n"); std::cout << " entering first for" << std::endl; for(; it != bnd_vertices.end(); ++it) { @@ -996,9 +982,7 @@ void packingOfParallelogramsConstrained( char ccc[256]; sprintf(ccc, "points%d.pos", gf->tag()); FILE *f = NULL; - if(debug){ - f = Fopen(ccc, "w"); - } + if(debug) { f = Fopen(ccc, "w"); } if(f) fprintf(f, "View \"\"{\n"); std::cout << " entering another for" << std::endl; for(unsigned int i = 0; i < vertices.size(); i++) { @@ -1018,7 +1002,7 @@ void packingOfParallelogramsConstrained( } delete vertices[i]; } - if(f){ + if(f) { fprintf(f, "};"); fclose(f); } diff --git a/contrib/domhex/yamakawa.cpp b/contrib/domhex/yamakawa.cpp index b1e74958b51125cf3f4f1a348e64abf1f24d6d8d..6cfe3281f41a5d4097284230faa7750021af8c57 100644 --- a/contrib/domhex/yamakawa.cpp +++ b/contrib/domhex/yamakawa.cpp @@ -93,8 +93,7 @@ namespace { bool inclusion(MVertex *v1, MVertex *v2, MVertex *v3, const std::set<MElement *> &tets) { - for(auto it = tets.begin(); - it != tets.end(); it++) { + for(auto it = tets.begin(); it != tets.end(); it++) { if(tet_contains_vertex(*it, v1) && tet_contains_vertex(*it, v2) && tet_contains_vertex(*it, v3)) { return true; @@ -393,8 +392,7 @@ namespace { { TetMeshConnectivity::TetSet tets_around_v = tet_mesh.tets_around_vertex(vertex); - for(auto tet = tets_around_v.begin(); - tet != tets_around_v.end(); ++tet) { + for(auto tet = tets_around_v.begin(); tet != tets_around_v.end(); ++tet) { if(hex_contains_tet(hex, *tet)) { result.insert(*tet); } } } @@ -424,8 +422,7 @@ namespace { MVertex *find(MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, const std::set<MElement *> &tets) { - for(auto it = tets.begin(); - it != tets.end(); it++) { + for(auto it = tets.begin(); it != tets.end(); it++) { MElement *tet = *it; if(tet_contains_vertex(tet, v1) && tet_contains_vertex(tet, v2) && tet_contains_vertex(tet, v3) && !tet_contains_vertex(tet, v4)) { @@ -494,29 +491,25 @@ void export_gregion_mesh(GRegion *gr, const string &filename) map<MVertex *, int> vertices; int counterv = 1; - for(auto it = gr->tetrahedra.begin(); - it != gr->tetrahedra.end(); it++) { + for(auto it = gr->tetrahedra.begin(); it != gr->tetrahedra.end(); it++) { for(std::size_t i = 0; i < (*it)->getNumVertices(); i++) { vertices.insert(make_pair((*it)->getVertex(i), counterv)); counterv++; } } - for(auto it = gr->hexahedra.begin(); - it != gr->hexahedra.end(); it++) { + for(auto it = gr->hexahedra.begin(); it != gr->hexahedra.end(); it++) { for(std::size_t i = 0; i < (*it)->getNumVertices(); i++) { vertices.insert(make_pair((*it)->getVertex(i), counterv)); counterv++; } } - for(auto it = gr->prisms.begin(); - it != gr->prisms.end(); it++) { + for(auto it = gr->prisms.begin(); it != gr->prisms.end(); it++) { for(std::size_t i = 0; i < (*it)->getNumVertices(); i++) { vertices.insert(make_pair((*it)->getVertex(i), counterv)); counterv++; } } - for(auto it = gr->pyramids.begin(); - it != gr->pyramids.end(); it++) { + for(auto it = gr->pyramids.begin(); it != gr->pyramids.end(); it++) { for(std::size_t i = 0; i < (*it)->getNumVertices(); i++) { vertices.insert(make_pair((*it)->getVertex(i), counterv)); counterv++; @@ -531,8 +524,7 @@ void export_gregion_mesh(GRegion *gr, const string &filename) << "$Nodes" << endl << vertices.size() << endl; // write vertices - for(auto it = vertices.begin(); it != vertices.end(); - it++) + for(auto it = vertices.begin(); it != vertices.end(); it++) out << it->second << " " << it->first->x() << " " << it->first->y() << " " << it->first->z() << endl; out << "$EndNodes" << endl @@ -543,8 +535,7 @@ void export_gregion_mesh(GRegion *gr, const string &filename) // write elems int counter = 1; - for(auto it = gr->tetrahedra.begin(); - it != gr->tetrahedra.end(); it++) { + for(auto it = gr->tetrahedra.begin(); it != gr->tetrahedra.end(); it++) { out << counter << " 4 2 0 26"; for(std::size_t i = 0; i < (*it)->getNumVertices(); i++) { MVertex *v = (*it)->getVertex(i); @@ -553,8 +544,7 @@ void export_gregion_mesh(GRegion *gr, const string &filename) out << endl; counter++; } - for(auto it = gr->hexahedra.begin(); - it != gr->hexahedra.end(); it++) { + for(auto it = gr->hexahedra.begin(); it != gr->hexahedra.end(); it++) { out << counter << " 5 2 0 26"; for(std::size_t i = 0; i < (*it)->getNumVertices(); i++) { MVertex *v = (*it)->getVertex(i); @@ -563,8 +553,7 @@ void export_gregion_mesh(GRegion *gr, const string &filename) out << endl; counter++; } - for(auto it = gr->prisms.begin(); - it != gr->prisms.end(); it++) { + for(auto it = gr->prisms.begin(); it != gr->prisms.end(); it++) { out << counter << " 6 2 0 26"; for(std::size_t i = 0; i < (*it)->getNumVertices(); i++) { MVertex *v = (*it)->getVertex(i); @@ -573,8 +562,7 @@ void export_gregion_mesh(GRegion *gr, const string &filename) out << endl; counter++; } - for(auto it = gr->pyramids.begin(); - it != gr->pyramids.end(); it++) { + for(auto it = gr->pyramids.begin(); it != gr->pyramids.end(); it++) { out << counter << " 7 2 0 26"; for(std::size_t i = 0; i < (*it)->getNumVertices(); i++) { MVertex *v = (*it)->getVertex(i); @@ -605,10 +593,7 @@ bool compare_hex_ptr_by_quality(Hex *a, Hex *b) Recombinator::~Recombinator() { - for(auto it = potential.begin(); - it != potential.end(); it++) { - delete *it; - } + for(auto it = potential.begin(); it != potential.end(); it++) { delete *it; } } void Recombinator::execute() @@ -617,8 +602,8 @@ void Recombinator::execute() // Backup the current mesh model->writeMSH("beforeyamakawa.msh"); - for(auto region_itr = model->firstRegion(); - region_itr != model->lastRegion(); region_itr++) { + for(auto region_itr = model->firstRegion(); region_itr != model->lastRegion(); + region_itr++) { GRegion *region = *region_itr; if(region->getNumMeshElements() > 0) { execute(region); } @@ -647,8 +632,7 @@ void Recombinator::print_all_potential_hex() const std::cout << "__________________________ START POT HEX LISTING ____________________ " << endl; - for(auto it = potential.begin(); - it != potential.end(); it++) { + for(auto it = potential.begin(); it != potential.end(); it++) { cout << "--- Potential hex : " << *(*it) << " " << (*it)->get_quality() << endl; } @@ -737,8 +721,7 @@ void Recombinator::pattern1() tet_mesh.vertices_around_vertices(p, q, r, bin4); remove_values_from_set(bin4, added); - for(auto it4 = bin4.begin(); - it4 != bin4.end(); it4++) { + for(auto it4 = bin4.begin(); it4 != bin4.end(); it4++) { MVertex *s = *it4; Hex *hex = new Hex(a, b, q, c, d, p, s, r); @@ -832,7 +815,8 @@ void Recombinator::pattern3() MVertex *bA = find(a, c, b, d, verif2); MVertex *bB = find(a, c, d, b, verif2); - if(fA != nullptr && fB != nullptr && bA != nullptr && bB != nullptr && fA != fB && bA != bB) { + if(fA != nullptr && fB != nullptr && bA != nullptr && bB != nullptr && + fA != fB && bA != bB) { if(scalar(fA, fB, a, b) > scalar(fA, fB, b, c) && scalar(bA, bB, a, b) > scalar(bA, bB, b, c)) { MVertex *p = nullptr; @@ -935,8 +919,7 @@ void add_hex_to_region(GRegion *region, const Hex &hex) bool Recombinator::are_all_tets_free(const std::set<MElement *> &tets) const { - for(auto it = tets.begin(); it != tets.end(); - it++) { + for(auto it = tets.begin(); it != tets.end(); it++) { MElement *tet = *it; auto it2 = markings.find(tet); if(it2->second == true) { return false; } @@ -946,8 +929,7 @@ bool Recombinator::are_all_tets_free(const std::set<MElement *> &tets) const void Recombinator::mark_tets(const std::set<MElement *> &tets) { - for(auto it = tets.begin(); it != tets.end(); - ++it) { + for(auto it = tets.begin(); it != tets.end(); ++it) { auto it2 = markings.find(*it); it2->second = true; } @@ -956,8 +938,7 @@ void Recombinator::mark_tets(const std::set<MElement *> &tets) void remove_slivers(std::set<MElement *> &tets, const Hex &hex, std::set<MElement *> &slivers) { - for(auto it = tets.begin(); it != tets.end(); - ++it) { + for(auto it = tets.begin(); it != tets.end(); ++it) { if(is_combinatorially_sliver(*it, hex)) { slivers.insert(*it); tets.erase(it); @@ -1077,8 +1058,7 @@ void Recombinator::build_tuples() std::vector<GFace *> faces = current_region->faces(); - for(auto it = faces.begin(); it != faces.end(); - it++) { + for(auto it = faces.begin(); it != faces.end(); it++) { GFace *gf = *it; for(unsigned int i = 0; i < gf->getNumMeshElements(); i++) { @@ -1124,8 +1104,7 @@ void Recombinator::create_quads_on_boundary() void Recombinator::delete_quad_triangles_in_boundary() const { std::vector<GFace *> faces = current_region->faces(); - for(auto it = faces.begin(); it != faces.end(); - it++) { + for(auto it = faces.begin(); it != faces.end(); it++) { GFace *gf = *it; std::vector<MElement *> triangles_to_keep; triangles_to_keep.reserve(gf->triangles.size()); @@ -5209,8 +5188,7 @@ void export_the_clique_graphviz_format(cliques_compatibility_graph<T> &cl, multimap<int, int> done; // export all hex - auto itgraph = - cl.begin_graph(); + auto itgraph = cl.begin_graph(); typename cliques_compatibility_graph<T>::graph_data::const_iterator itgraphdata; @@ -5244,8 +5222,7 @@ void export_the_clique_graphviz_format(cliques_compatibility_graph<T> &cl, bool found = false; pair<multimap<int, int>::iterator, multimap<int, int>::iterator> range = done.equal_range(num1); - for(auto it = range.first; it != range.second; - it++) { + for(auto it = range.first; it != range.second; it++) { if(it->second == num2) { found = true; break; @@ -5301,8 +5278,7 @@ void clique_stop_criteria<T>::export_corresponding_mesh( set<MElement *> hexs; map<MVertex *, int> vertices; int counterv = 1; - auto it = - hex_to_tet.begin(); + auto it = hex_to_tet.begin(); for(; it != hex_to_tet.end(); it++) { auto itt = it->second.begin(); for(; itt != it->second.end(); itt++) { @@ -5315,10 +5291,8 @@ void clique_stop_criteria<T>::export_corresponding_mesh( } // create MHexahedron, remove included tets from set "tets" - for(auto it = clique.begin(); - it != clique.end(); it++) { - auto itfind = - hex_to_tet.find(*it); + for(auto it = clique.begin(); it != clique.end(); it++) { + auto itfind = hex_to_tet.find(*it); if(itfind == hex_to_tet.end()) { cout << "clique_stop_criteria::void export_corresponding_mesh : not " "found !!!" @@ -5326,8 +5300,8 @@ void clique_stop_criteria<T>::export_corresponding_mesh( throw; } // remove tets - for(auto ittet = itfind->second.begin(); - ittet != itfind->second.end(); ittet++) { + for(auto ittet = itfind->second.begin(); ittet != itfind->second.end(); + ittet++) { tets.erase(*ittet); } // create MHexahedron @@ -5357,8 +5331,7 @@ void clique_stop_criteria<T>::export_corresponding_mesh( << "$Nodes" << endl << vertices.size() << endl; // write vertices - for(auto it = vertices.begin(); it != vertices.end(); - it++) { + for(auto it = vertices.begin(); it != vertices.end(); it++) { out << it->second << " " << it->first->x() << " " << it->first->y() << " " << it->first->z() << endl; outtets << it->second << " " << it->first->x() << " " << it->first->y() @@ -5415,18 +5388,16 @@ bool clique_stop_criteria<T>::stop(const graph_data_no_hash &clique) const set<MElement *> thetets; // set<MElement*> slivers; - for(auto it = clique.begin(); - it != clique.end(); it++) { - auto itfind = - hex_to_tet.find(*it); + for(auto it = clique.begin(); it != clique.end(); it++) { + auto itfind = hex_to_tet.find(*it); if(itfind == hex_to_tet.end()) { cout << "clique_stop_criteria::bool stop : not found !!!" << endl; throw; } // total += (itfind->second.size()); // cout << "volumes=" << endl; - for(auto ittet = itfind->second.begin(); - ittet != itfind->second.end(); ittet++) { + for(auto ittet = itfind->second.begin(); ittet != itfind->second.end(); + ittet++) { // set<MElement*>::iterator itfindtet = thetets.find(*ittet); // if (itfindtet!=thetets.end()){ // cout << "Tet " << *ittet << " already done !!!" << endl; @@ -5439,16 +5410,14 @@ bool clique_stop_criteria<T>::stop(const graph_data_no_hash &clique) const // to be sure, adding volume criteria... vector<double> volumes; - for(auto it = thetets.begin(); it != thetets.end(); - it++) { + for(auto it = thetets.begin(); it != thetets.end(); it++) { volumes.push_back((*it)->getVolume()); } int meanvolume = (std::accumulate(volumes.begin(), volumes.end(), 0)) / volumes.size(); int nb_slivers = 0; double threshold = 1.e-3 * meanvolume; - for(auto it = thetets.begin(); it != thetets.end(); - it++) { + for(auto it = thetets.begin(); it != thetets.end(); it++) { if((*it)->getVolume() < threshold) { nb_slivers++; } } @@ -5545,8 +5514,7 @@ template <class T> void cliques_compatibility_graph<T>::store_clique(int n) } } if(store_it) { - auto itstore = - allQ.insert(make_pair(Q.size(), set<T>())); + auto itstore = allQ.insert(make_pair(Q.size(), set<T>())); itstore->second.insert(Q.begin(), Q.end()); // for (typename graph_data_no_hash::iterator it = Q.begin(); it != Q.end(); // it++) { @@ -5687,8 +5655,7 @@ void cliques_compatibility_graph<T>::choose_u(const graph_data &subgraph, T &u, hash_key &u_key) { double valuemax = -DBL_MAX; - for(auto it = subgraph.begin(); - it != subgraph.end(); it++) { + for(auto it = subgraph.begin(); it != subgraph.end(); it++) { double value = function_to_maximize_for_u(it->second, it->first, subgraph); if(value > valuemax) { valuemax = value; @@ -5740,8 +5707,7 @@ double cliques_compatibility_graph<T>::function_to_maximize_for_u( const T &u, const hash_key &u_key, const graph_data &subgraph) { int counter = 0; - for(auto it = subgraph.begin(); - it != subgraph.end(); it++) { + for(auto it = subgraph.begin(); it != subgraph.end(); it++) { if((it->second) == u) continue; if(compatibility(u, u_key, it->second, it->first)) counter++; } @@ -5765,8 +5731,8 @@ bool cliques_compatibility_graph<T>::compatibility(const T &u, // Check if v is in u data pair<typename graph_data::const_iterator, typename graph_data::const_iterator> range_vkey = itfind_u->second.second.equal_range(v_key); - for(auto itfind_v = range_vkey.first; - itfind_v != range_vkey.second; itfind_v++) { + for(auto itfind_v = range_vkey.first; itfind_v != range_vkey.second; + itfind_v++) { if(itfind_v->second == v) { return true; } } return false; @@ -5830,8 +5796,7 @@ bool PEEntity::hasVertex(MVertex *v) const bool PEEntity::same_vertices(const PEEntity *t) const { - for(auto it = vertices.begin(); - it != vertices.end(); it++) { + for(auto it = vertices.begin(); it != vertices.end(); it++) { if(!(t->hasVertex(*it))) return false; } return true; @@ -5967,8 +5932,7 @@ void Recombinator_Graph::fill_tet_to_hex_table(Hex *hex) // deviennent b c d a, on a une rotation et un hex tout pourri... mais qui a // même hash et mêmes noeuds ?!?! now, check if the hex already exists... if(!bypass) { - auto itfind = - find_the_created_potential_hex(hex, created_potential_hex); + auto itfind = find_the_created_potential_hex(hex, created_potential_hex); if(itfind != created_potential_hex.end()) { delete hex; if(very_verbose) @@ -5999,10 +5963,8 @@ void Recombinator_Graph::fill_tet_to_hex_table(Hex *hex) } int count = 0; - auto - it_face = faces_temp.begin(); - auto - it_faceen = faces_temp.end(); + auto it_face = faces_temp.begin(); + auto it_faceen = faces_temp.end(); for(; it_face != it_faceen; it_face++) // counting if(it_face->second.second == 1) count++; @@ -6097,8 +6059,8 @@ Recombinator_Graph::~Recombinator_Graph() for(auto it = triangular_faces.begin(); it != triangular_faces.end(); it++) { delete it->second; } - for(auto it = edges_and_diagonals.begin(); - it != edges_and_diagonals.end(); it++) { + for(auto it = edges_and_diagonals.begin(); it != edges_and_diagonals.end(); + it++) { delete it->second; } @@ -6135,8 +6097,7 @@ void Recombinator_Graph::createBlossomInfo(GRegion *gr) cout << "recover blossom info" << endl; - for(auto it = faces.begin(); it != faces.end(); - it++) { + for(auto it = faces.begin(); it != faces.end(); it++) { gf = *it; auto it_quad = gf->quadrangles.begin(); @@ -6782,9 +6743,7 @@ Recombinator_Graph::find_the_triangle( std::multimap<unsigned long long, pair<PETriangle *, int> >::iterator, std::multimap<unsigned long long, pair<PETriangle *, int> >::iterator> range = list.equal_range(t->get_hash()); - for(auto it = - range.first; - it != range.second; it++) { + for(auto it = range.first; it != range.second; it++) { PETriangle *candidate = it->second.first; if(candidate->same_vertices(t)) { it->second.second++; @@ -6859,8 +6818,7 @@ void Recombinator_Graph::export_direct_neighbor_table(int max) void print_stats_graph(const Recombinator_Graph::graph &in) { int total = 0; - for(auto it = in.begin(); it != in.end(); - it++) { + for(auto it = in.begin(); it != in.end(); it++) { total += it->second.second.size(); } size_t nb_entries = in.size(); @@ -6885,9 +6843,7 @@ void Recombinator_Graph::create_losses_graph(GRegion *gr) // common) but DO NOT pass the compatibility tests) void Recombinator_Graph::create_direct_neighbors_incompatibility_graph() { - for(auto it_hex = - hex_to_tet.begin(); - it_hex != hex_to_tet.end(); it_hex++) { + for(auto it_hex = hex_to_tet.begin(); it_hex != hex_to_tet.end(); it_hex++) { Hex *hex = it_hex->first; if(is_not_good_enough(hex)) { // Why is it even there in the first place? JP @@ -6908,13 +6864,12 @@ void Recombinator_Graph::create_direct_neighbors_incompatibility_graph() std::vector<Hex *> visited_hex; // Check compatibility with the that share an facet with hex const std::set<PETriangle *> &hex_faces = hex_to_faces[hex]; - for(auto it_faces = hex_faces.begin(); - it_faces != hex_faces.end(); it_faces++) { + for(auto it_faces = hex_faces.begin(); it_faces != hex_faces.end(); + it_faces++) { PETriangle *face = *it_faces; const std::set<Hex *> &hex_sharing_triangle = faces_to_hex[face]; - for(auto it_neighbors = - hex_sharing_triangle.begin(); + for(auto it_neighbors = hex_sharing_triangle.begin(); it_neighbors != hex_sharing_triangle.end(); it_neighbors++) { Hex *other_hex = *it_neighbors; if(other_hex == hex) continue; @@ -6933,12 +6888,11 @@ void Recombinator_Graph::create_direct_neighbors_incompatibility_graph() // change following... const std::set<PELine *> &hex_edges = hex_to_edges[hex]; - for(auto it_line = hex_edges.begin(); - it_line != hex_edges.end(); it_line++) { + for(auto it_line = hex_edges.begin(); it_line != hex_edges.end(); + it_line++) { PELine *line = *it_line; const std::set<Hex *> &hex_sharing_edge = edges_to_hex[line]; - for(auto it_neighbors = - hex_sharing_edge.begin(); + for(auto it_neighbors = hex_sharing_edge.begin(); it_neighbors != hex_sharing_edge.end(); it_neighbors++) { Hex *other_hex = *it_neighbors; if(other_hex == hex) continue; @@ -7007,8 +6961,7 @@ void Recombinator_Graph::add_face( v.push_back(b); v.push_back(c); PETriangle *q = new PETriangle(v); - auto itfind = - find_the_triangle(q, f); + auto itfind = find_the_triangle(q, f); if(itfind == f.end()) { f.insert(make_pair(q->get_hash(), make_pair(q, 1))); } else { delete q; @@ -7133,13 +7086,11 @@ void Recombinator_Graph::compute_hex_ranks() { create_faces_connectivity(); - for(auto it = hex_to_faces.begin(); - it != hex_to_faces.end(); it++) { + for(auto it = hex_to_faces.begin(); it != hex_to_faces.end(); it++) { Hex *hex = it->first; // Count the number of facets on boundary for the hex int boundary_count = 0.; - for(auto itf = it->second.begin(); - itf != it->second.end(); itf++) { + for(auto itf = it->second.begin(); itf != it->second.end(); itf++) { PETriangle *face = *itf; if(faces_connectivity[face] == 1) boundary_count += 1.; } @@ -7154,9 +7105,7 @@ void Recombinator_Graph::compute_hex_ranks() // Complex way to get the number of tets around a triangular facet void Recombinator_Graph::create_faces_connectivity() { - for(auto it_tet = - tet_to_hex.begin(); - it_tet != tet_to_hex.end(); it_tet++) { + for(auto it_tet = tet_to_hex.begin(); it_tet != tet_to_hex.end(); it_tet++) { add_face_connectivity(it_tet->first, 0, 1, 2); add_face_connectivity(it_tet->first, 0, 1, 3); add_face_connectivity(it_tet->first, 0, 2, 3); @@ -7183,12 +7132,10 @@ void Recombinator_Graph::compute_hex_ranks_blossom() { create_faces_connectivity(); - for(auto it = hex_to_faces.begin(); - it != hex_to_faces.end(); it++) { + for(auto it = hex_to_faces.begin(); it != hex_to_faces.end(); it++) { Hex *hex = it->first; double nb_faces_on_boundary = 0.; - for(auto face = it->second.begin(); - face != it->second.end(); face++) { + for(auto face = it->second.begin(); face != it->second.end(); face++) { if(faces_connectivity[*face] == 1) nb_faces_on_boundary += 1.; } auto itfind = hex_ranks.find(hex); diff --git a/contrib/domhex/yamakawa.h b/contrib/domhex/yamakawa.h index f0c6a369f115eb385d95ef0565c2b7e66b0b7f76..1ffb80da657bebba55fc1842fcdbfd69a20cf83b 100644 --- a/contrib/domhex/yamakawa.h +++ b/contrib/domhex/yamakawa.h @@ -206,15 +206,15 @@ private: public: Tuple() - : vertex1(nullptr), vertex2(nullptr), vertex3(nullptr), element(nullptr), gf(nullptr), - hash(0) + : vertex1(nullptr), vertex2(nullptr), vertex3(nullptr), element(nullptr), + gf(nullptr), hash(0) { } Tuple(MVertex *const a, MVertex *const b, MVertex *const c, MElement *const element2, GFace *const gf2) - : vertex1(nullptr), vertex2(nullptr), vertex3(nullptr), element(element2), gf(gf2), - hash(a->getNum() + b->getNum() + c->getNum()) + : vertex1(nullptr), vertex2(nullptr), vertex3(nullptr), element(element2), + gf(gf2), hash(a->getNum() + b->getNum() + c->getNum()) { MVertex *tmp[3] = {a, b, c}; std::sort(tmp, tmp + 3); @@ -224,8 +224,8 @@ public: } Tuple(MVertex *const a, MVertex *const b, MVertex *const c) - : vertex1(nullptr), vertex2(nullptr), vertex3(nullptr), element(nullptr), gf(nullptr), - hash(a->getNum() + b->getNum() + c->getNum()) + : vertex1(nullptr), vertex2(nullptr), vertex3(nullptr), element(nullptr), + gf(nullptr), hash(a->getNum() + b->getNum() + c->getNum()) { MVertex *tmp[3] = {a, b, c}; std::sort(tmp, tmp + 3); @@ -331,8 +331,7 @@ private: MVertex *b = tet->getVertex((j + 1) % 4); MVertex *c = tet->getVertex((j + 2) % 4); MVertex *d = tet->getVertex((j + 3) % 4); - auto it = - vertex_to_vertices_.find(a); + auto it = vertex_to_vertices_.find(a); if(it != vertex_to_vertices_.end()) { it->second.insert(b); it->second.insert(c); @@ -357,8 +356,7 @@ private: MElement *tet = region->getMeshElement(i); for(unsigned int j = 0; j < 4; j++) { MVertex *getVertex = tet->getVertex(j); - auto it = - vertex_to_elements_.find(getVertex); + auto it = vertex_to_elements_.find(getVertex); if(it != vertex_to_elements_.end()) { it->second.insert(tet); } else { std::set<MElement *> bin; diff --git a/contrib/mobile/androidUtils.cpp b/contrib/mobile/androidUtils.cpp index 042d6f017660fea88d3b0b2c14170b4801d6311d..fb0e70064b017576eb73cc1fc7d6c3db93dd9f97 100644 --- a/contrib/mobile/androidUtils.cpp +++ b/contrib/mobile/androidUtils.cpp @@ -343,17 +343,18 @@ JNIEXPORT jstring JNICALL Java_org_geuz_onelab_Gmsh_getAboutGetDP(JNIEnv *env, jclass c) { std::ostringstream sstream; - sstream << "<center><h3>GetDP</h3>" - << "Version " << GETDP_VERSION << " " - << "(<i>Build date:</i> " << GETDP_DATE << ")" - << "<p>Copyright (C) 1997-2021 Patrick Dular and Christophe " - "Geuzaine, University of Liège</p>" - << "<p><a href=\"https://getdp.info/CREDITS.txt\">Credits</a> " - << "and <a href=\"https://getdp.info/LICENSE.txt\">licensing " - "information</a></p>" - << "<p><i>Build options:</i> " << GETDP_CONFIG_OPTIONS << "</p>" - << "<p>Visit <a href=\"https://getdp.info\">https://getdp.info</a> for " - "more information</p></center>"; + sstream + << "<center><h3>GetDP</h3>" + << "Version " << GETDP_VERSION << " " + << "(<i>Build date:</i> " << GETDP_DATE << ")" + << "<p>Copyright (C) 1997-2021 Patrick Dular and Christophe " + "Geuzaine, University of Liège</p>" + << "<p><a href=\"https://getdp.info/CREDITS.txt\">Credits</a> " + << "and <a href=\"https://getdp.info/LICENSE.txt\">licensing " + "information</a></p>" + << "<p><i>Build options:</i> " << GETDP_CONFIG_OPTIONS << "</p>" + << "<p>Visit <a href=\"https://getdp.info\">https://getdp.info</a> for " + "more information</p></center>"; return env->NewStringUTF(sstream.str().c_str()); } } diff --git a/contrib/mobile/drawContext.cpp b/contrib/mobile/drawContext.cpp index 8faaa583b72d210db034b29bc0f0b73963ddae48..4fb577ea993acb5de162b5b5acf441a35a8b976e 100644 --- a/contrib/mobile/drawContext.cpp +++ b/contrib/mobile/drawContext.cpp @@ -939,8 +939,10 @@ void drawContext::drawSmallAxes() int drawContext::fix2dCoordinates(double *x, double *y) { - int ret = - (*x > 99999 && *y > 99999) ? 3 : (*y > 99999) ? 2 : (*x > 99999) ? 1 : 0; + int ret = (*x > 99999 && *y > 99999) ? 3 : + (*y > 99999) ? 2 : + (*x > 99999) ? 1 : + 0; if(*x < 0) // measure from right border *x = _right + *x; diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp index be9cefe4513b1d90b78574aee6019ef2113647d7..712a24f652f2bc37523f22c2d7b44dda97b761ea 100644 --- a/contrib/onelab/OnelabClients.cpp +++ b/contrib/onelab/OnelabClients.cpp @@ -11,35 +11,38 @@ #endif #if defined(WIN32) -static char dirSep='\\'; +static char dirSep = '\\'; static std::string cmdSep(" & "); static std::string removeCmd("del "); static std::string lsCmd("dir "); #else -static char dirSep='/'; +static char dirSep = '/'; static std::string cmdSep(" ; "); static std::string removeCmd("rm -rf "); static std::string lsCmd("ls "); #endif -class onelabMetaModelServer : public GmshServer{ - private: +class onelabMetaModelServer : public GmshServer { +private: localNetworkSolverClient *_client; - public: + +public: onelabMetaModelServer(localNetworkSolverClient *client) - : GmshServer(), _client(client) {} - ~onelabMetaModelServer(){} + : GmshServer(), _client(client) + { + } + ~onelabMetaModelServer() {} - int NonBlockingSystemCall(const std::string &exe, const std::string &args){ + int NonBlockingSystemCall(const std::string &exe, const std::string &args) + { std::cout << "Calling now : " << exe << " " << args << std::endl; return SystemCallExe(exe, args); } int NonBlockingWait(double waitint, double timeout, int socket) { double start = TimeOfDay(); - while(1){ - if(timeout > 0 && TimeOfDay() - start > timeout) - return 2; // timeout + while(1) { + if(timeout > 0 && TimeOfDay() - start > timeout) return 2; // timeout if(_client->getPid() < 0 /*|| (_client->getCommandLine().empty())*/) return 1; // process has been killed @@ -48,15 +51,15 @@ class onelabMetaModelServer : public GmshServer{ // return immediately, i.e., do polling) int ret = Select(0, 0, socket); - if(ret == 0){ // nothing available + if(ret == 0) { // nothing available // wait at most waitint seconds and respond to FLTK events - void (*waitFct)(double) = OLMsg::GetGuiWaitFunction(); - if(waitFct) waitFct(waitint); + void (*waitFct)(double) = OLMsg::GetGuiWaitFunction(); + if(waitFct) waitFct(waitint); } - else if(ret > 0){ + else if(ret > 0) { return 0; // data is there! } - else{ // ret<0 an error happened + else { // ret<0 an error happened _client->setPid(-1); return 1; } @@ -64,30 +67,30 @@ class onelabMetaModelServer : public GmshServer{ } }; -std::string localNetworkSolverClient::buildCommandLine(){ +std::string localNetworkSolverClient::buildCommandLine() +{ std::string command; command.assign(""); - if(!getWorkingDir().empty()) - command.append("cd " + getWorkingDir() + cmdSep); + if(!getWorkingDir().empty()) command.append("cd " + getWorkingDir() + cmdSep); command.append(QuoteExecPath(getCommandLine())); return command; } -std::string localNetworkSolverClient::appendArguments(){ - +std::string localNetworkSolverClient::appendArguments() +{ std::string action = getString("Action"); std::string checkCommand = getString("9CheckCommand"); std::string computeCommand = getString("9ComputeCommand"); std::string command; - if(action == "initialize"){ + if(action == "initialize") { command.assign(" " + getSocketSwitch() + " " + getName() + " %s"); } else if(action == "check") { - command.assign(" " + getString("Arguments") + " " + checkCommand) ; + command.assign(" " + getString("Arguments") + " " + checkCommand); command.append(" " + getSocketSwitch() + " \"" + getName() + "\" %s"); } - else if(action == "compute"){ + else if(action == "compute") { command.assign(" " + getString("Arguments") + " " + computeCommand); command.append(" " + getSocketSwitch() + " \"" + getName() + "\" %s"); } @@ -96,117 +99,121 @@ std::string localNetworkSolverClient::appendArguments(){ return command; } -bool localNetworkSolverClient::receiveMessage(){ +bool localNetworkSolverClient::receiveMessage() +{ double timer = TimeOfDay(); - if(!getGmshServer()){ + if(!getGmshServer()) { OLMsg::Error("Abnormal server termination (no valid server)"); return false; } int type, length, swap; - if(!getGmshServer()->ReceiveHeader(&type, &length, &swap)){ - OLMsg::Error("Abnormal server termination (did not receive message header)"); + if(!getGmshServer()->ReceiveHeader(&type, &length, &swap)) { + OLMsg::Error( + "Abnormal server termination (did not receive message header)"); return false; } else if(_socketMsg) - OLMsg::Info("Received header <%d>",type); + OLMsg::Info("Received header <%d>", type); std::string message(length, ' '); - if(!getGmshServer()->ReceiveMessage(length, &message[0])){ + if(!getGmshServer()->ReceiveMessage(length, &message[0])) { OLMsg::Error("Abnormal server termination (did not receive message body)r"); return false; } else if(_socketMsg) - OLMsg::Info("Received message <%s>",message.c_str()); - - switch (type) { - case GmshSocket::GMSH_START: - setPid(atoi(message.c_str())); - break; - case GmshSocket::GMSH_STOP: - setPid(-1); - break; - case GmshSocket::GMSH_PARAMETER: - { - std::string version, type, name; - onelab::parameter::getInfoFromChar(message, version, type, name); - if(onelab::parameter::version() != version){ - OLMsg::Error("OneLab version mismatch for %s (server: %s / client: %s)", - message.c_str(), onelab::parameter::version().c_str(), version.c_str()); - } - if(type == "number"){ - onelab::number p; p.fromChar(message); set(p); - } - else if(type == "string"){ - onelab::string p; p.fromChar(message); set(p); - } - else - OLMsg::Error("FIXME query not done for this parameter type: <%s>", - message.c_str()); + OLMsg::Info("Received message <%s>", message.c_str()); + + switch(type) { + case GmshSocket::GMSH_START: setPid(atoi(message.c_str())); break; + case GmshSocket::GMSH_STOP: setPid(-1); break; + case GmshSocket::GMSH_PARAMETER: { + std::string version, type, name; + onelab::parameter::getInfoFromChar(message, version, type, name); + if(onelab::parameter::version() != version) { + OLMsg::Error("OneLab version mismatch for %s (server: %s / client: %s)", + message.c_str(), onelab::parameter::version().c_str(), + version.c_str()); } - break; - case GmshSocket::GMSH_PARAMETER_QUERY: - { - std::string version, type, name, reply; - onelab::parameter::getInfoFromChar(message, version, type, name); - if(onelab::parameter::version() != version){ - OLMsg::Error("OneLab version mismatch for %s (server: %s / client: %s)", - message.c_str(), onelab::parameter::version().c_str(), version.c_str()); - } - else if(type == "number"){ - std::vector<onelab::number> par; get(par, name); - if(par.size() == 1) reply = par[0].toChar(); - } - else if(type == "string"){ - std::vector<onelab::string> par; get(par, name); - if(par.size() == 1) reply = par[0].toChar(); - } - else - OLMsg::Error("Unknown OneLab parameter type in query: %s", - type.c_str()); + if(type == "number") { + onelab::number p; + p.fromChar(message); + set(p); + } + else if(type == "string") { + onelab::string p; + p.fromChar(message); + set(p); + } + else + OLMsg::Error("FIXME query not done for this parameter type: <%s>", + message.c_str()); + } break; + case GmshSocket::GMSH_PARAMETER_QUERY: { + std::string version, type, name, reply; + onelab::parameter::getInfoFromChar(message, version, type, name); + if(onelab::parameter::version() != version) { + OLMsg::Error("OneLab version mismatch for %s (server: %s / client: %s)", + message.c_str(), onelab::parameter::version().c_str(), + version.c_str()); + } + else if(type == "number") { + std::vector<onelab::number> par; + get(par, name); + if(par.size() == 1) reply = par[0].toChar(); + } + else if(type == "string") { + std::vector<onelab::string> par; + get(par, name); + if(par.size() == 1) reply = par[0].toChar(); + } + else + OLMsg::Error("Unknown OneLab parameter type in query: %s", type.c_str()); - if(reply.size()){ - getGmshServer()->SendMessage(GmshSocket::GMSH_PARAMETER, - reply.size(), &reply[0]); - } - else{ - reply = "OneLab parameter '" + name + "' not found"; - getGmshServer()->SendMessage(GmshSocket::GMSH_INFO, reply.size(), &reply[0]); - } + if(reply.size()) { + getGmshServer()->SendMessage(GmshSocket::GMSH_PARAMETER, reply.size(), + &reply[0]); } - break; - case GmshSocket::GMSH_PARAMETER_QUERY_ALL: - { - std::string version, type, name, reply; - std::vector<std::string> replies; - onelab::parameter::getInfoFromChar(message, version, type, name); - if(onelab::parameter::version() != version){ - OLMsg::Error("OneLab version mismatch for %s (server: %s / client: %s)", - message.c_str(), onelab::parameter::version().c_str(), version.c_str()); - } - else if(type == "number"){ - std::vector<onelab::number> numbers; get(numbers); - for(std::vector<onelab::number>::iterator it = numbers.begin(); - it != numbers.end(); it++) replies.push_back((*it).toChar()); - } - else if(type == "string"){ - std::vector<onelab::string> strings; get(strings); - for(std::vector<onelab::string>::iterator it = strings.begin(); - it != strings.end(); it++) replies.push_back((*it).toChar()); - } - else - OLMsg::Error("Unknown OneLab parameter type in query: %s", - type.c_str()); - - for(unsigned int i = 0; i < replies.size(); i++) - getGmshServer()->SendMessage(GmshSocket::GMSH_PARAMETER_QUERY_ALL, - replies[i].size(), &replies[i][0]); - reply = "Sent all OneLab " + type + "s"; - getGmshServer()->SendMessage(GmshSocket::GMSH_PARAMETER_QUERY_END, - reply.size(), &reply[0]); + else { + reply = "OneLab parameter '" + name + "' not found"; + getGmshServer()->SendMessage(GmshSocket::GMSH_INFO, reply.size(), + &reply[0]); } - break; + } break; + case GmshSocket::GMSH_PARAMETER_QUERY_ALL: { + std::string version, type, name, reply; + std::vector<std::string> replies; + onelab::parameter::getInfoFromChar(message, version, type, name); + if(onelab::parameter::version() != version) { + OLMsg::Error("OneLab version mismatch for %s (server: %s / client: %s)", + message.c_str(), onelab::parameter::version().c_str(), + version.c_str()); + } + else if(type == "number") { + std::vector<onelab::number> numbers; + get(numbers); + for(std::vector<onelab::number>::iterator it = numbers.begin(); + it != numbers.end(); it++) + replies.push_back((*it).toChar()); + } + else if(type == "string") { + std::vector<onelab::string> strings; + get(strings); + for(std::vector<onelab::string>::iterator it = strings.begin(); + it != strings.end(); it++) + replies.push_back((*it).toChar()); + } + else + OLMsg::Error("Unknown OneLab parameter type in query: %s", type.c_str()); + + for(unsigned int i = 0; i < replies.size(); i++) + getGmshServer()->SendMessage(GmshSocket::GMSH_PARAMETER_QUERY_ALL, + replies[i].size(), &replies[i][0]); + reply = "Sent all OneLab " + type + "s"; + getGmshServer()->SendMessage(GmshSocket::GMSH_PARAMETER_QUERY_END, + reply.size(), &reply[0]); + } break; case GmshSocket::GMSH_PROGRESS: OLMsg::StatusBar(2, false, "%s %s", _name.c_str(), message.c_str()); break; @@ -222,8 +229,10 @@ bool localNetworkSolverClient::receiveMessage(){ case GmshSocket::GMSH_MERGE_FILE: // if(CTX::instance()->solver.autoMergeFile){ // unsigned int n = PView::list.size(); - // MergePostProcessingFile(message, CTX::instance()->solver.autoShowLastStep, - // CTX::instance()->solver.autoHideNewViews, true); + // MergePostProcessingFile(message, + // CTX::instance()->solver.autoShowLastStep, + // CTX::instance()->solver.autoHideNewViews, + // true); // drawContext::global()->draw(); // if(FlGui::available() && n != PView::list.size()){ // FlGui::instance()->rebuildTree(); @@ -235,57 +244,49 @@ bool localNetworkSolverClient::receiveMessage(){ // ParseString(message); // drawContext::global()->draw(); break; - case GmshSocket::GMSH_SPEED_TEST: - OLMsg::Info("got %d Mb message in %g seconds", - length / 1024 / 1024, TimeOfDay() - timer); - break; - case GmshSocket::GMSH_VERTEX_ARRAY: - { - // int n = PView::list.size(); - // PView::fillVertexArray(this, length, &message[0], swap); - // if(FlGui::available()) - // FlGui::instance()->updateViews(n != (int)PView::list.size()); - // drawContext::global()->draw(); - } + case GmshSocket::GMSH_SPEED_TEST: + OLMsg::Info("got %d Mb message in %g seconds", length / 1024 / 1024, + TimeOfDay() - timer); break; - case GmshSocket::GMSH_CONNECT: - { - // const std::string clientName = message; - // std::cout << "client name =" << clientName << std::endl; - // onelab::localNetworkClient *subClient = findClient(clientName); - // if (!subClient) { - // subClient = new gmshLocalNetworkClient(clientName, ""); - // } - // else - // std::cout << "Gmsh has " << addClient(subClient) << " clients\n"; - // subClient->getGmshServer()->LaunchClient(); - } - break; - case GmshSocket::GMSH_OLPARSE: - { + case GmshSocket::GMSH_VERTEX_ARRAY: { + // int n = PView::list.size(); + // PView::fillVertexArray(this, length, &message[0], swap); + // if(FlGui::available()) + // FlGui::instance()->updateViews(n != (int)PView::list.size()); + // drawContext::global()->draw(); + } break; + case GmshSocket::GMSH_CONNECT: { + // const std::string clientName = message; + // std::cout << "client name =" << clientName << std::endl; + // onelab::localNetworkClient *subClient = findClient(clientName); + // if (!subClient) { + // subClient = new gmshLocalNetworkClient(clientName, ""); + // } + // else + // std::cout << "Gmsh has " << addClient(subClient) << " clients\n"; + // subClient->getGmshServer()->LaunchClient(); + } break; + case GmshSocket::GMSH_OLPARSE: { #if defined(HAVE_ONELAB_METAMODEL) - localSolverClient *c = new InterfacedClient("OLParser","",""); - std::string ofileName = message ; - std::ofstream outfile(ofileName.c_str()); - if (outfile.is_open()) - c->convert_onefile(ofileName + ".ol",outfile); - else - OLMsg::Error("The file <%s> cannot be opened",ofileName.c_str()); - outfile.close(); - delete c; + localSolverClient *c = new InterfacedClient("OLParser", "", ""); + std::string ofileName = message; + std::ofstream outfile(ofileName.c_str()); + if(outfile.is_open()) + c->convert_onefile(ofileName + ".ol", outfile); + else + OLMsg::Error("The file <%s> cannot be opened", ofileName.c_str()); + outfile.close(); + delete c; #endif - } - break; - default: - OLMsg::Warning("Received unknown message type (%d)", type); - break; + } break; + default: OLMsg::Warning("Received unknown message type (%d)", type); break; } return true; } bool localNetworkSolverClient::run() { - //new_connection: + // new_connection: setPid(0); // Choose socket type (Unix or TCP/IP) @@ -301,14 +302,14 @@ bool localNetworkSolverClient::run() std::string sockname; std::ostringstream tmp; - if(!strstr(socketName.c_str(), ":")){ // Unix socket + if(!strstr(socketName.c_str(), ":")) { // Unix socket tmp << socketName << getId(); sockname = FixWindowsPath(tmp.str()); } - else{ // TCP/IP socket + else { // TCP/IP socket if(socketName.size() && socketName[0] == ':') tmp << GetHostName(); // prepend hostname if only the port number is given - tmp << socketName ; + tmp << socketName; sockname = tmp.str(); } @@ -326,38 +327,42 @@ bool localNetworkSolverClient::run() std::cout << "commandline = " << command << std::endl; int sock; - try{ - sock = socketConnection->Start(exe.c_str(), command.c_str(), sockname.c_str(), 10); - } - catch(const char *err){ + try { + sock = socketConnection->Start(exe.c_str(), command.c_str(), + sockname.c_str(), 10); + } catch(const char *err) { OLMsg::Error("%s (on socket '%s')", err, sockname.c_str()); sock = -1; } - if(sock < 0){ //could not establish connection: aborting + if(sock < 0) { // could not establish connection: aborting socketConnection->Shutdown(); delete socketConnection; OLMsg::Error("Connection failed on socket <%s>", sockname.c_str()); return false; } - OLMsg::StatusBar(2, true, "Now running client <%s> on socket <%d>", _name.c_str(), sock); - _socketMsg = OLMsg::GetOnelabNumber("SHOWSOCKETMESSAGES")?true:false; + OLMsg::StatusBar(2, true, "Now running client <%s> on socket <%d>", + _name.c_str(), sock); + _socketMsg = OLMsg::GetOnelabNumber("SHOWSOCKETMESSAGES") ? true : false; setGmshServer(socketConnection); while(1) { bool stop = false, haveData = false; - if(getPid() < 0) { stop = true; break; } - if(!getGmshServer()){ + if(getPid() < 0) { + stop = true; + break; + } + if(!getGmshServer()) { OLMsg::Error("Abnormal server termination (no valid server)"); stop = true; } - else if(!getGmshServer()->NonBlockingWait(0.001, 0., sock)){ + else if(!getGmshServer()->NonBlockingWait(0.001, 0., sock)) { haveData = true; } - else{// an error occurred + else { // an error occurred stop = true; } if(stop) break; @@ -381,7 +386,7 @@ bool localNetworkSolverClient::run() bool localNetworkSolverClient::kill() { if(getPid() > 0) { - if(KillProcess(getPid())){ + if(KillProcess(getPid())) { OLMsg::Info("Killed '%s' (pid %d)", _name.c_str(), getPid()); setPid(-1); return true; @@ -393,31 +398,35 @@ bool localNetworkSolverClient::kill() // client LOCALSOLVERCLIENT -const std::string localSolverClient::getString(const std::string what){ - std::string name=getName() + "/" + what; +const std::string localSolverClient::getString(const std::string what) +{ + std::string name = getName() + "/" + what; std::vector<onelab::string> strings; get(strings, name); if(strings.size()) return strings[0].getValue(); - else{ - //OLMsg::Info("Undefined parameter <%s> in getString", name.c_str()); + else { + // OLMsg::Info("Undefined parameter <%s> in getString", name.c_str()); return ""; } } -void localSolverClient::setAction(const std::string action){ - std::string name=getName() + "/Action"; +void localSolverClient::setAction(const std::string action) +{ + std::string name = getName() + "/Action"; onelab::string s(name, action); s.setVisible(false); s.setNeverChanged(true); set(s); } -const bool localSolverClient::getList(const std::string type, std::vector<std::string> &choices){ +const bool localSolverClient::getList(const std::string type, + std::vector<std::string> &choices) +{ std::vector<onelab::string> strings; get(strings, getName() + "/" + type); - if(strings.size()){ - choices= strings[0].getChoices(); + if(strings.size()) { + choices = strings[0].getChoices(); return true; } else @@ -426,29 +435,31 @@ const bool localSolverClient::getList(const std::string type, std::vector<std::s void localSolverClient::FixExecPath(const std::string &in) { - //only use with local clients + // only use with local clients std::string cmd; - std::vector<std::string> split=SplitFileName(in); + std::vector<std::string> split = SplitFileName(in); - if(split[2]==".app"){ + if(split[2] == ".app") { cmd.assign(in + "/Contents/MacOS/" + split[1]); setCommandLine(cmd); } #if !defined(WIN32) - //if(split[0].find("elmerfem") != std::string::npos){ - if(!split[1].compare("ElmerSolver") && split[2].empty() && split[0].size()){ + // if(split[0].find("elmerfem") != std::string::npos){ + if(!split[1].compare("ElmerSolver") && split[2].empty() && split[0].size()) { std::string fileName = getWorkingDir() + getName() + ".sh"; - std::string elmerHome=split[0].substr(0,split[0].size()-4); + std::string elmerHome = split[0].substr(0, split[0].size() - 4); std::ofstream outfile(fileName.c_str()); - if (outfile.is_open()){ + if(outfile.is_open()) { outfile << "#!/bin/bash" << std::endl; outfile << "export ELMER_HOME=\"" << elmerHome << "\"" << std::endl; - outfile << "export DYLD_LIBRARY_PATH=\".:$ELMER_HOME/lib:$DYLD_LIBRARY_PATH\"" << std::endl; + outfile + << "export DYLD_LIBRARY_PATH=\".:$ELMER_HOME/lib:$DYLD_LIBRARY_PATH\"" + << std::endl; outfile << in << std::endl; } else - OLMsg::Error("The file <%s> cannot be opened",fileName.c_str()); + OLMsg::Error("The file <%s> cannot be opened", fileName.c_str()); outfile.close(); chmod(fileName); setCommandLine(fileName); @@ -456,35 +467,36 @@ void localSolverClient::FixExecPath(const std::string &in) #endif } -bool localSolverClient::checkCommandLine(){ - bool success=true; +bool localSolverClient::checkCommandLine() +{ + bool success = true; OLMsg::Info("Check command line <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); + getCommandLine().c_str(), getName().c_str()); - if(getCommandLine().empty()){ + if(getCommandLine().empty()) { if(OLMsg::hasGmsh) { OLMsg::Error("No command line for client <%s>", getName().c_str()); return false; // restores control to gmsh } - else{ // asks the user in console mode - std::cout << "\nONELAB: Enter pathname of the executable file for <" << getName() << ">" << std::endl; + else { // asks the user in console mode + std::cout << "\nONELAB: Enter pathname of the executable file for <" + << getName() << ">" << std::endl; std::string cmdl; - std::getline (std::cin,cmdl); + std::getline(std::cin, cmdl); setCommandLine(cmdl); return checkCommandLine(); } } - else{ - if(!isRemote()) - FixExecPath(getCommandLine()); + else { + if(!isRemote()) FixExecPath(getCommandLine()); - if(isNative()){ // native clients checked by initializing + if(isNative()) { // native clients checked by initializing setAction("initialize"); - if(!run()){ // initializes native clients, false otherwise - success = false; + if(!run()) { // initializes native clients, false otherwise + success = false; } } - else{ + else { std::string commandLine; commandLine.assign(QuoteExecPath(getCommandLine())); @@ -493,47 +505,48 @@ bool localSolverClient::checkCommandLine(){ // resolve a possible linux link #if !defined(WIN32) - if(!success){ - char cbuf [1024]; - FILE *fp; - std::string cmd; - cmd.assign("which " + commandLine); - fp = POPEN(cmd.c_str(), "r"); - if(fgets(cbuf, 1024, fp) == NULL){ - PCLOSE(fp); - success=false; - } - else{ - commandLine.assign(sanitizeString(cbuf,"\n")); - success=true; - } - PCLOSE(fp); + if(!success) { + char cbuf[1024]; + FILE *fp; + std::string cmd; + cmd.assign("which " + commandLine); + fp = POPEN(cmd.c_str(), "r"); + if(fgets(cbuf, 1024, fp) == NULL) { + PCLOSE(fp); + success = false; + } + else { + commandLine.assign(sanitizeString(cbuf, "\n")); + success = true; + } + PCLOSE(fp); } #else - success=true; + success = true; #endif } } - if(success){ - OLMsg::SetVisible(getName()+"/CommandLine",false); - OLMsg::SetVisible(getName()+"/HostName",false); - OLMsg::SetVisible(getName()+"/RemoteDir",false); + if(success) { + OLMsg::SetVisible(getName() + "/CommandLine", false); + OLMsg::SetVisible(getName() + "/HostName", false); + OLMsg::SetVisible(getName() + "/RemoteDir", false); OLMsg::Info("Command line ok"); } - else{ + else { OLMsg::Error("Invalid commandline <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); - //setCommandLine(""); + getCommandLine().c_str(), getName().c_str()); + // setCommandLine(""); OLMsg::SetOnelabString(getName() + "/CommandLine", getCommandLine(), true); } return success; } -bool localSolverClient::buildRmCommand(std::string &cmd){ +bool localSolverClient::buildRmCommand(std::string &cmd) +{ std::vector<std::string> choices, split; - if(getList("OutputFiles",choices)){ + if(getList("OutputFiles", choices)) { cmd.assign(removeCmd); // defined in OnelabClients.h - for(unsigned int i = 0; i < choices.size(); i++){ + for(unsigned int i = 0; i < choices.size(); i++) { split = SplitOLFileName(choices[i]); cmd.append(split[1] + " "); } @@ -542,12 +555,13 @@ bool localSolverClient::buildRmCommand(std::string &cmd){ return false; } -void localSolverClient::addNumberChoice(std::string name, double val, bool readOnly) +void localSolverClient::addNumberChoice(std::string name, double val, + bool readOnly) { std::vector<double> choices; std::vector<onelab::number> ps; get(ps, name); - if(ps.size()){ + if(ps.size()) { choices = ps[0].getChoices(); ps[0].setReadOnly(readOnly); ps[0].setValue(val); @@ -555,35 +569,35 @@ void localSolverClient::addNumberChoice(std::string name, double val, bool readO ps[0].setChoices(choices); set(ps[0]); } - else{ + else { OLMsg::Error("The parameter <%s> does not exist", name.c_str()); } } void localSolverClient::PostArray(std::vector<std::string> choices) { - unsigned int i=0; - while( 4*(i+1) <= choices.size()){ - int lin= atof(choices[4*i+1].c_str())-1; - int col= atof(choices[4*i+2].c_str())-1; - std::string fileName = getWorkingDir()+choices[4*i]; - //checkIfPresent or make available locally - double val=find_in_array(lin,col,read_array(fileName,' ')); - std::string paramName = choices[4*i+3]; - addNumberChoice(paramName,val,true); - OLMsg::Info("Upload parameter <%s>=%e from file <%s>", - paramName.c_str(),val,fileName.c_str()); + unsigned int i = 0; + while(4 * (i + 1) <= choices.size()) { + int lin = atof(choices[4 * i + 1].c_str()) - 1; + int col = atof(choices[4 * i + 2].c_str()) - 1; + std::string fileName = getWorkingDir() + choices[4 * i]; + // checkIfPresent or make available locally + double val = find_in_array(lin, col, read_array(fileName, ' ')); + std::string paramName = choices[4 * i + 3]; + addNumberChoice(paramName, val, true); + OLMsg::Info("Upload parameter <%s>=%e from file <%s>", paramName.c_str(), + val, fileName.c_str()); i++; } } void localSolverClient::GmshMerge(std::vector<std::string> choices) { - for(unsigned int i = 0; i < choices.size(); i++){ - std::string fileName=getWorkingDir()+choices[i]; - //checkIfPresent or make available locally - if(checkIfPresent(fileName)){ - OLMsg::Info("Send merge request <%s>",fileName.c_str()); + for(unsigned int i = 0; i < choices.size(); i++) { + std::string fileName = getWorkingDir() + choices[i]; + // checkIfPresent or make available locally + if(checkIfPresent(fileName)) { + OLMsg::Info("Send merge request <%s>", fileName.c_str()); OLMsg::MergeFile(fileName); } } @@ -591,8 +605,9 @@ void localSolverClient::GmshMerge(std::vector<std::string> choices) // REMOTE CLIENT -bool remoteClient::checkCommandLine(const std::string &commandLine){ - bool success=true; +bool remoteClient::checkCommandLine(const std::string &commandLine) +{ + bool success = true; std::string cmd; cmd.assign("ssh " + getRemoteHost() + " 'mkdir -p " + getRemoteDir() + "'"); @@ -601,46 +616,49 @@ bool remoteClient::checkCommandLine(const std::string &commandLine){ cmd.assign(QuoteExecPath(commandLine)); // check whether the executable exists as a file - success=checkIfPresentRemote(commandLine); + success = checkIfPresentRemote(commandLine); // resolve a possible linux link #if !defined(WIN32) - if(!success){ - char cbuf [1024]; + if(!success) { + char cbuf[1024]; FILE *fp; std::string cmd; cmd.assign("ssh " + getRemoteHost() + " 'which " + commandLine + "'"); fp = POPEN(cmd.c_str(), "r"); if(fgets(cbuf, 1024, fp) == NULL) - success=false; + success = false; else - success=true; + success = true; PCLOSE(fp); } #endif return success; } -bool remoteClient::checkIfPresentRemote(const std::string &fileName){ +bool remoteClient::checkIfPresentRemote(const std::string &fileName) +{ std::string cmd; - char cbuf [1024]; + char cbuf[1024]; FILE *fp; - cmd.assign("ssh " + _remoteHost +" 'cd " +_remoteDir + "; "); + cmd.assign("ssh " + _remoteHost + " 'cd " + _remoteDir + "; "); cmd.append(lsCmd + fileName + " 2>/dev/null'"); - //std::cout << "check remote<" << cmd << ">" << std::endl; + // std::cout << "check remote<" << cmd << ">" << std::endl; fp = POPEN(cmd.c_str(), "r"); - if(fgets(cbuf, 1024, fp) == NULL){ - //OLMsg::Warning("The file <%s> is not present", fileName.c_str()); + if(fgets(cbuf, 1024, fp) == NULL) { + // OLMsg::Warning("The file <%s> is not present", fileName.c_str()); PCLOSE(fp); return false; } - //OLMsg::Info("The file <%s> is present", fileName.c_str()); + // OLMsg::Info("The file <%s> is present", fileName.c_str()); PCLOSE(fp); return true; } -bool remoteClient::syncInputFile(const std::string &wdir, const std::string &fileName){ +bool remoteClient::syncInputFile(const std::string &wdir, + const std::string &fileName) +{ std::string cmd; std::vector<std::string> split; @@ -649,68 +667,67 @@ bool remoteClient::syncInputFile(const std::string &wdir, const std::string &fil OLMsg::Info("Sync input file <%s>", split[1].c_str()); - if(split[2].size()){ // .ol file => local - if(checkIfPresent(localName)){ + if(split[2].size()) { // .ol file => local + if(checkIfPresent(localName)) { cmd.assign("rsync -e ssh -auv " + localName + " " + _remoteHost + ":"); - if(_remoteDir.size()) - cmd.append(_remoteDir); + if(_remoteDir.size()) cmd.append(_remoteDir); cmd.append(split[1]); SleepInSeconds(OLMsg::GetOnelabNumber("RSYNCDELAY")); return mySystem(cmd); } - else{ - //OLMsg::Error("The input file <%s> is not present", localName.c_str()); + else { + // OLMsg::Error("The input file <%s> is not present", localName.c_str()); return false; } } else { // not a .ol file, apply the "_" rule - if(split[0].size()){ // should be found local - if(checkIfPresent(localName)){ - cmd.assign("rsync -e ssh -auv " + localName + " " + _remoteHost +":"); - if(_remoteDir.size()) - cmd.append(_remoteDir); - cmd.append(split[1]); - - SleepInSeconds(OLMsg::GetOnelabNumber("RSYNCDELAY")); - return mySystem(cmd); + if(split[0].size()) { // should be found local + if(checkIfPresent(localName)) { + cmd.assign("rsync -e ssh -auv " + localName + " " + _remoteHost + ":"); + if(_remoteDir.size()) cmd.append(_remoteDir); + cmd.append(split[1]); + + SleepInSeconds(OLMsg::GetOnelabNumber("RSYNCDELAY")); + return mySystem(cmd); } - else{ - OLMsg::Error("The local input file <%s> is not present", - localName.c_str()); - return false; + else { + OLMsg::Error("The local input file <%s> is not present", + localName.c_str()); + return false; } } - else { //should be found remote - if(!checkIfPresentRemote(split[1])){ - OLMsg::Error("The remote input file <%s> is not present", - split[1].c_str()); - return false; + else { // should be found remote + if(!checkIfPresentRemote(split[1])) { + OLMsg::Error("The remote input file <%s> is not present", + split[1].c_str()); + return false; } else - return true; + return true; } } } -bool remoteClient::syncOutputFile(const std::string &wdir, const std::string &fileName){ +bool remoteClient::syncOutputFile(const std::string &wdir, + const std::string &fileName) +{ std::string cmd; std::vector<std::string> split; split = SplitOLFileName(fileName); - //std::string localName = wdir + split[1]; + // std::string localName = wdir + split[1]; OLMsg::Info("Sync output file <%s>", split[1].c_str()); - if(checkIfPresentRemote(split[1])){ - if(split[0].size()){ // the file must be copied back on local host + if(checkIfPresentRemote(split[1])) { + if(split[0].size()) { // the file must be copied back on local host cmd.assign("rsync -e ssh -auv " + _remoteHost + ":"); - if(_remoteDir.size()) - cmd.append(_remoteDir); + if(_remoteDir.size()) cmd.append(_remoteDir); cmd.append(split[1]); if(wdir.size()) - cmd.append(" " + wdir); + cmd.append(" " + wdir); else - cmd.append(" ."); + cmd.append(" ."); SleepInSeconds(OLMsg::GetOnelabNumber("RSYNCDELAY")); return mySystem(cmd); } @@ -723,57 +740,65 @@ bool remoteClient::syncOutputFile(const std::string &wdir, const std::string &fi void MetaModel::construct() { OLMsg::Info("===== CONSTRUCTING"); - std::string fileName = getWorkingDir() + genericNameFromArgs + onelabExtension; + std::string fileName = + getWorkingDir() + genericNameFromArgs + onelabExtension; openOnelabBlock(); parse_onefile(fileName); closeOnelabBlock(); saveCommandLines(); - //onelab::server::instance()->setChanged(true, getName()); + // onelab::server::instance()->setChanged(true, getName()); } -void MetaModel::analyze() { +void MetaModel::analyze() +{ OLMsg::Info("===== ANALYZING"); - std::string fileName = getWorkingDir() + genericNameFromArgs + onelabExtension; + std::string fileName = + getWorkingDir() + genericNameFromArgs + onelabExtension; openOnelabBlock(); OLMsg::Info("Parse file <%s> %s", fileName.c_str(), - parse_onefile(fileName)?"done":"failed"); + parse_onefile(fileName) ? "done" : "failed"); closeOnelabBlock(); } -void MetaModel::compute() { +void MetaModel::compute() +{ OLMsg::Info("===== COMPUTING"); - std::string fileName = getWorkingDir() + genericNameFromArgs + onelabExtension; + std::string fileName = + getWorkingDir() + genericNameFromArgs + onelabExtension; openOnelabBlock(); OLMsg::Info("Parse file <%s> %s", fileName.c_str(), - parse_onefile(fileName)?"done":"failed"); + parse_onefile(fileName) ? "done" : "failed"); closeOnelabBlock(); onelab::server::instance()->setChanged(false); } -void MetaModel::registerClient(const std::string &name, const std::string &type, const std::string &cmdl, const std::string &host, const std::string &rdir) { +void MetaModel::registerClient(const std::string &name, const std::string &type, + const std::string &cmdl, const std::string &host, + const std::string &rdir) +{ localSolverClient *c; // Clients are assigned by default the same (local) working dir // as the MetaModel, i.e. the working dir from args // A working (local relative) subdir (useful to organize submodels) // can be defined with the command: client.workingSubdir(subdir) - if(host.empty() || !host.compare("localhost")){ //local client - if(!type.compare(0,6,"interf")) - c= new InterfacedClient(name,cmdl,getWorkingDir()); - else if(!type.compare(0,6,"native")) - c= new NativeClient(name,cmdl,getWorkingDir()); - else if(!type.compare(0,6,"encaps")) - c= new EncapsulatedClient(name,cmdl,getWorkingDir()); + if(host.empty() || !host.compare("localhost")) { // local client + if(!type.compare(0, 6, "interf")) + c = new InterfacedClient(name, cmdl, getWorkingDir()); + else if(!type.compare(0, 6, "native")) + c = new NativeClient(name, cmdl, getWorkingDir()); + else if(!type.compare(0, 6, "encaps")) + c = new EncapsulatedClient(name, cmdl, getWorkingDir()); else OLMsg::Error("Unknown client type", type.c_str()); } - else{ // remote client - if(!type.compare(0,6,"interf")) - c= new RemoteInterfacedClient(name,cmdl,getWorkingDir(),host,rdir); - else if(!type.compare(0,6,"native")) - c= new RemoteNativeClient(name,cmdl,getWorkingDir(),host,rdir); - else if(!type.compare(0,6,"encaps")) - c= new RemoteEncapsulatedClient(name,cmdl,getWorkingDir(),host,rdir); + else { // remote client + if(!type.compare(0, 6, "interf")) + c = new RemoteInterfacedClient(name, cmdl, getWorkingDir(), host, rdir); + else if(!type.compare(0, 6, "native")) + c = new RemoteNativeClient(name, cmdl, getWorkingDir(), host, rdir); + else if(!type.compare(0, 6, "encaps")) + c = new RemoteEncapsulatedClient(name, cmdl, getWorkingDir(), host, rdir); else OLMsg::Error("Unknown remote client type", type.c_str()); } @@ -782,64 +807,67 @@ void MetaModel::registerClient(const std::string &name, const std::string &type, void MetaModel::PostArray(std::vector<std::string> choices) { - unsigned int i=0; - while( 4*(i+1) <= choices.size()){ - int lin= atof(choices[4*i+1].c_str())-1; - int col= atof(choices[4*i+2].c_str())-1; + unsigned int i = 0; + while(4 * (i + 1) <= choices.size()) { + int lin = atof(choices[4 * i + 1].c_str()) - 1; + int col = atof(choices[4 * i + 2].c_str()) - 1; std::string fileName = - OLMsg::GetOnelabString("Arguments/WorkingDir")+choices[4*i]; - double val=find_in_array(lin,col,read_array(fileName,' ')); - addNumberChoice(choices[4*i+3],val); - OLMsg::Info("PostArray <%s>=%e",choices[4*i+3].c_str(),val); + OLMsg::GetOnelabString("Arguments/WorkingDir") + choices[4 * i]; + double val = find_in_array(lin, col, read_array(fileName, ' ')); + addNumberChoice(choices[4 * i + 3], val); + OLMsg::Info("PostArray <%s>=%e", choices[4 * i + 3].c_str(), val); i++; } } // INTERFACED client -void InterfacedClient::analyze() { +void InterfacedClient::analyze() +{ std::vector<std::string> choices, split; OLMsg::Info("Analyzes <%s> changed=%d", getName().c_str(), - onelab::server::instance()->getChanged(getName())); + onelab::server::instance()->getChanged(getName())); setAction("check"); getList("InputFiles", choices); - for(unsigned int i = 0; i < choices.size(); i++){ + for(unsigned int i = 0; i < choices.size(); i++) { split = SplitOLFileName(choices[i]); - if(split[2].size()){ // if .ol file + if(split[2].size()) { // if .ol file std::string fileName = getWorkingDir() + split[1] + split[2]; if(!checkIfPresent(fileName)) - OLMsg::Error("The file <%s> is not present",fileName.c_str()); + OLMsg::Error("The file <%s> is not present", fileName.c_str()); OLMsg::Info("Parse file <%s> %s", fileName.c_str(), - parse_onefile(fileName)?"done":"failed"); + parse_onefile(fileName) ? "done" : "failed"); } } convert(); } -void InterfacedClient::convert() { +void InterfacedClient::convert() +{ std::vector<std::string> choices, split; getList("InputFiles", choices); - for(unsigned int i = 0; i < choices.size(); i++){ + for(unsigned int i = 0; i < choices.size(); i++) { split = SplitOLFileName(choices[i]); - if(split[2].size()){ // if .ol file + if(split[2].size()) { // if .ol file std::string fileName = getWorkingDir() + split[1] + split[2]; - std::string ofileName = getWorkingDir() + split[1] ; + std::string ofileName = getWorkingDir() + split[1]; if(!checkIfPresent(fileName)) - OLMsg::Error("The file <%s> is not present",fileName.c_str()); + OLMsg::Error("The file <%s> is not present", fileName.c_str()); std::ofstream outfile(ofileName.c_str()); - if (outfile.is_open()) - convert_onefile(fileName,outfile); + if(outfile.is_open()) + convert_onefile(fileName, outfile); else - OLMsg::Error("The file <%s> cannot be opened",ofileName.c_str()); + OLMsg::Error("The file <%s> cannot be opened", ofileName.c_str()); outfile.close(); } } } -void InterfacedClient::compute(){ +void InterfacedClient::compute() +{ std::vector<std::string> choices, split; analyze(); @@ -847,48 +875,49 @@ void InterfacedClient::compute(){ OLMsg::Info("Computes <%s>", getName().c_str()); setAction("compute"); - if(getList("InputFiles",choices)){ - for(unsigned int i = 0; i < choices.size(); i++){ + if(getList("InputFiles", choices)) { + for(unsigned int i = 0; i < choices.size(); i++) { split = SplitOLFileName(choices[i]); std::string fileName = getWorkingDir() + split[1]; if(!checkIfPresent(fileName)) - OLMsg::Error("The file <%s> is not present",fileName.c_str()); + OLMsg::Error("The file <%s> is not present", fileName.c_str()); } } - std::string cdcmd=""; - if(getWorkingDir().size()) - cdcmd.assign("cd " + getWorkingDir() + cmdSep); + std::string cdcmd = ""; + if(getWorkingDir().size()) cdcmd.assign("cd " + getWorkingDir() + cmdSep); - std::string rmcmd=""; + std::string rmcmd = ""; if(buildRmCommand(rmcmd)) mySystem(cdcmd + rmcmd); std::string cmd; cmd.assign(QuoteExecPath(getCommandLine()) + " " + getString("Arguments")); mySystem(cdcmd + cmd); - if(getList("OutputFiles", choices)){ - for(unsigned int i = 0; i < choices.size(); i++){ + if(getList("OutputFiles", choices)) { + for(unsigned int i = 0; i < choices.size(); i++) { split = SplitOLFileName(choices[i]); std::string fileName = getWorkingDir() + split[1]; if(!checkIfPresent(fileName)) - OLMsg::Error("The file <%s> is not present",fileName.c_str()); + OLMsg::Error("The file <%s> is not present", fileName.c_str()); } } } // NATIVE Client -void NativeClient::analyze() { +void NativeClient::analyze() +{ OLMsg::Info("Analyzes <%s> changed=%d", getName().c_str(), - onelab::server::instance()->getChanged(getName())); + onelab::server::instance()->getChanged(getName())); setAction("check"); if(!run()) OLMsg::Error("Invalid commandline <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); + getCommandLine().c_str(), getName().c_str()); } -void NativeClient::compute() { +void NativeClient::compute() +{ std::vector<std::string> choices, split; analyze(); @@ -896,32 +925,31 @@ void NativeClient::compute() { OLMsg::Info("Computes <%s>", getName().c_str()); setAction("compute"); - if(getList("InputFiles",choices)){ - for(unsigned int i = 0; i < choices.size(); i++){ + if(getList("InputFiles", choices)) { + for(unsigned int i = 0; i < choices.size(); i++) { split = SplitOLFileName(choices[i]); std::string fileName = getWorkingDir() + split[1]; if(!checkIfPresent(fileName)) - OLMsg::Error("The file <%s> is not present",fileName.c_str()); + OLMsg::Error("The file <%s> is not present", fileName.c_str()); } } - std::string cdcmd=""; - if(getWorkingDir().size()) - cdcmd.append("cd " + getWorkingDir() + cmdSep); + std::string cdcmd = ""; + if(getWorkingDir().size()) cdcmd.append("cd " + getWorkingDir() + cmdSep); - std::string rmcmd=""; + std::string rmcmd = ""; if(buildRmCommand(rmcmd)) mySystem(cdcmd + rmcmd); if(!run()) OLMsg::Error("Invalid commandline <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); + getCommandLine().c_str(), getName().c_str()); - if(getList("OutputFiles",choices)){ - for(unsigned int i = 0; i < choices.size(); i++){ + if(getList("OutputFiles", choices)) { + for(unsigned int i = 0; i < choices.size(); i++) { split = SplitOLFileName(choices[i]); std::string fileName = getWorkingDir() + split[1]; if(!checkIfPresent(fileName)) - OLMsg::Error("The file <%s> is not present",fileName.c_str()); + OLMsg::Error("The file <%s> is not present", fileName.c_str()); } } } @@ -930,55 +958,59 @@ void NativeClient::compute() { // EncapsulatedClient's are InterfacedClient's called via the loader // so that Gmsh sees them as a localNetworkClient -void EncapsulatedClient::analyze() { +void EncapsulatedClient::analyze() +{ std::vector<std::string> choices, split; OLMsg::Info("Analyzes <%s> changed=%d", getName().c_str(), - onelab::server::instance()->getChanged(getName())); + onelab::server::instance()->getChanged(getName())); setAction("check"); getList("InputFiles", choices); - for(unsigned int i = 0; i < choices.size(); i++){ + for(unsigned int i = 0; i < choices.size(); i++) { split = SplitOLFileName(choices[i]); - if(split[2].size()){ // if .ol file + if(split[2].size()) { // if .ol file std::string fileName = getWorkingDir() + split[1] + split[2]; if(!checkIfPresent(fileName)) - OLMsg::Error("The file <%s> is not present",fileName.c_str()); + OLMsg::Error("The file <%s> is not present", fileName.c_str()); OLMsg::Info("Parse file <%s> %s", fileName.c_str(), - parse_onefile(fileName)?"done":"failed"); + parse_onefile(fileName) ? "done" : "failed"); } } convert(); } -void EncapsulatedClient::convert() { +void EncapsulatedClient::convert() +{ std::vector<std::string> choices, split; getList("InputFiles", choices); - for(unsigned int i = 0; i < choices.size(); i++){ + for(unsigned int i = 0; i < choices.size(); i++) { split = SplitOLFileName(choices[i]); - if(split[2].size()){ // if .ol file + if(split[2].size()) { // if .ol file std::string fileName = getWorkingDir() + split[1] + split[2]; - std::string ofileName = getWorkingDir() + split[1] ; + std::string ofileName = getWorkingDir() + split[1]; if(!checkIfPresent(fileName)) - OLMsg::Error("The file <%s> is not present",fileName.c_str()); + OLMsg::Error("The file <%s> is not present", fileName.c_str()); std::ofstream outfile(ofileName.c_str()); - if (outfile.is_open()) - convert_onefile(fileName, outfile); + if(outfile.is_open()) + convert_onefile(fileName, outfile); else - OLMsg::Error("The file <%s> cannot be opened",ofileName.c_str()); + OLMsg::Error("The file <%s> cannot be opened", ofileName.c_str()); outfile.close(); } } } -std::string EncapsulatedClient::buildCommandLine(){ - std::string cmd=OLMsg::GetOnelabString("LoaderPathName"); - OLMsg::Info("Loader pathname=<%s>",cmd.c_str()); +std::string EncapsulatedClient::buildCommandLine() +{ + std::string cmd = OLMsg::GetOnelabString("LoaderPathName"); + OLMsg::Info("Loader pathname=<%s>", cmd.c_str()); return cmd; } -void EncapsulatedClient::compute(){ +void EncapsulatedClient::compute() +{ std::vector<std::string> choices, split; analyze(); @@ -986,20 +1018,19 @@ void EncapsulatedClient::compute(){ OLMsg::Info("Computes <%s>", getName().c_str()); setAction("compute"); - if(getList("InputFiles",choices)){ - for(unsigned int i = 0; i < choices.size(); i++){ - split = SplitOLFileName(choices[i]); + if(getList("InputFiles", choices)) { + for(unsigned int i = 0; i < choices.size(); i++) { + split = SplitOLFileName(choices[i]); std::string fileName = getWorkingDir() + split[1]; if(!checkIfPresent(fileName)) - OLMsg::Error("The file <%s> is not present",fileName.c_str()); + OLMsg::Error("The file <%s> is not present", fileName.c_str()); } } - std::string cdcmd=""; - if(getWorkingDir().size()) - cdcmd.append("cd " + getWorkingDir() + cmdSep); + std::string cdcmd = ""; + if(getWorkingDir().size()) cdcmd.append("cd " + getWorkingDir() + cmdSep); - std::string rmcmd=""; + std::string rmcmd = ""; if(buildRmCommand(rmcmd)) mySystem(cdcmd + rmcmd); // the client command line is built and stored in a onelab parameter @@ -1007,45 +1038,46 @@ void EncapsulatedClient::compute(){ cmd.assign(cdcmd); cmd.append(QuoteExecPath(getCommandLine()) + " " + getString("Arguments")); OLMsg::SetOnelabString(getName() + "/FullCmdLine", cmd, false); - OLMsg::Info("Command line=<%s>",cmd.c_str()); + OLMsg::Info("Command line=<%s>", cmd.c_str()); if(!run()) // localNetworkClient::run() is called OLMsg::Error("Invalid commandline <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); + getCommandLine().c_str(), getName().c_str()); - if(getList("OutputFiles",choices)){ - for(unsigned int i = 0; i < choices.size(); i++){ + if(getList("OutputFiles", choices)) { + for(unsigned int i = 0; i < choices.size(); i++) { split = SplitOLFileName(choices[i]); std::string fileName = getWorkingDir() + split[1]; if(!checkIfPresent(fileName)) - OLMsg::Error("The file <%s> is not present",fileName.c_str()); + OLMsg::Error("The file <%s> is not present", fileName.c_str()); } } } // REMOTE INTERFACED Client -bool RemoteInterfacedClient::checkCommandLine(){ +bool RemoteInterfacedClient::checkCommandLine() +{ bool success; OLMsg::Info("Check command line <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); - if(getCommandLine().empty()) - return false; + getCommandLine().c_str(), getName().c_str()); + if(getCommandLine().empty()) return false; success = remoteClient::checkCommandLine(getCommandLine()); - if(success){ - OLMsg::SetOnelabString(getName()+"/CommandLine",getCommandLine(),false); + if(success) { + OLMsg::SetOnelabString(getName() + "/CommandLine", getCommandLine(), false); OLMsg::Info("Command line ok"); } - else{ - //setCommandLine(""); + else { + // setCommandLine(""); OLMsg::SetOnelabString(getName() + "/CommandLine", getCommandLine(), true); OLMsg::Error("Invalid command line <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); + getCommandLine().c_str(), getName().c_str()); } return success; } -void RemoteInterfacedClient::compute(){ +void RemoteInterfacedClient::compute() +{ std::vector<std::string> choices; analyze(); @@ -1053,94 +1085,88 @@ void RemoteInterfacedClient::compute(){ OLMsg::Info("Computes <%s>", getName().c_str()); setAction("compute"); - if(getList("InputFiles",choices)){ + if(getList("InputFiles", choices)) { for(unsigned int i = 0; i < choices.size(); i++) - if(syncInputFile(getWorkingDir(), choices[i])) - OLMsg::Info("ok"); + if(syncInputFile(getWorkingDir(), choices[i])) OLMsg::Info("ok"); } - std::string rmcmd=""; - if(buildRmCommand(rmcmd)){ + std::string rmcmd = ""; + if(buildRmCommand(rmcmd)) { std::string cdcmd; - //remove files on local machine - if(getWorkingDir().size()) - cdcmd.assign("cd " + getWorkingDir() + cmdSep); + // remove files on local machine + if(getWorkingDir().size()) cdcmd.assign("cd " + getWorkingDir() + cmdSep); mySystem(cdcmd + rmcmd); - //remove files on distant machine - if(getRemoteDir().size()) - cdcmd.assign("cd " + getRemoteDir() + cmdSep); + // remove files on distant machine + if(getRemoteDir().size()) cdcmd.assign("cd " + getRemoteDir() + cmdSep); mySystem("ssh " + getRemoteHost() + " '" + cdcmd + rmcmd + "'"); } std::string cmd; cmd.assign("ssh " + getRemoteHost() + " '"); - if(getRemoteDir().size()) - cmd.append("cd " + getRemoteDir() + cmdSep); + if(getRemoteDir().size()) cmd.append("cd " + getRemoteDir() + cmdSep); cmd.append(" " + QuoteExecPath(getCommandLine())); cmd.append(" " + getString("Arguments") + " '"); mySystem(cmd); - if(getList("OutputFiles",choices)){ + if(getList("OutputFiles", choices)) { for(unsigned int i = 0; i < choices.size(); i++) - if(syncOutputFile(getWorkingDir(), choices[i])) - OLMsg::Info("ok"); + if(syncOutputFile(getWorkingDir(), choices[i])) OLMsg::Info("ok"); } } - // REMOTE NATIVE Client -std::string RemoteNativeClient::buildCommandLine(){ +std::string RemoteNativeClient::buildCommandLine() +{ std::string command; command.assign("incomp_ssh -f " + getRemoteHost() + " '"); - if(getRemoteDir().size()) - command.append("cd " + getRemoteDir() + cmdSep); + if(getRemoteDir().size()) command.append("cd " + getRemoteDir() + cmdSep); command.append(" " + QuoteExecPath(getCommandLine()) + " "); return command; } -bool RemoteNativeClient::checkCommandLine(){ +bool RemoteNativeClient::checkCommandLine() +{ bool success; OLMsg::Info("Check command line <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); - if(getCommandLine().empty()) - return false; + getCommandLine().c_str(), getName().c_str()); + if(getCommandLine().empty()) return false; success = remoteClient::checkCommandLine(getCommandLine()); - if(success){ - OLMsg::SetOnelabString(getName()+"/CommandLine",getCommandLine(),false); + if(success) { + OLMsg::SetOnelabString(getName() + "/CommandLine", getCommandLine(), false); OLMsg::Info("Command line ok"); } - else{ - //setCommandLine(""); + else { + // setCommandLine(""); OLMsg::SetOnelabString(getName() + "/CommandLine", getCommandLine(), true); OLMsg::Error("Invalid command line <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); + getCommandLine().c_str(), getName().c_str()); } return success; } -void RemoteNativeClient::analyze(){ - std::string cmd,rmcmd; +void RemoteNativeClient::analyze() +{ + std::string cmd, rmcmd; std::vector<std::string> choices; OLMsg::Info("Analyzes <%s> changed=%d", getName().c_str(), - onelab::server::instance()->getChanged(getName())); + onelab::server::instance()->getChanged(getName())); setAction("check"); - if(getList("InputFiles",choices)){ + if(getList("InputFiles", choices)) { for(unsigned int i = 0; i < choices.size(); i++) - if(syncInputFile(getWorkingDir(), choices[i])) - OLMsg::Info("ok"); + if(syncInputFile(getWorkingDir(), choices[i])) OLMsg::Info("ok"); } if(!run()) OLMsg::Error("Invalid commandline <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); + getCommandLine().c_str(), getName().c_str()); } - -void RemoteNativeClient::compute(){ +void RemoteNativeClient::compute() +{ std::vector<std::string> choices; analyze(); @@ -1148,71 +1174,68 @@ void RemoteNativeClient::compute(){ OLMsg::Info("Computes <%s>", getName().c_str()); setAction("compute"); - if(getList("InputFiles",choices)){ + if(getList("InputFiles", choices)) { for(unsigned int i = 0; i < choices.size(); i++) - if(syncInputFile(getWorkingDir(), choices[i])) - OLMsg::Info("ok"); + if(syncInputFile(getWorkingDir(), choices[i])) OLMsg::Info("ok"); } - std::string rmcmd=""; - if(buildRmCommand(rmcmd)){ + std::string rmcmd = ""; + if(buildRmCommand(rmcmd)) { std::string cdcmd; - //remove files on local machine - if(getWorkingDir().size()) - cdcmd.assign("cd " + getWorkingDir() + cmdSep); + // remove files on local machine + if(getWorkingDir().size()) cdcmd.assign("cd " + getWorkingDir() + cmdSep); mySystem(cdcmd + rmcmd); - //remove files on distant machine - if(getRemoteDir().size()) - cdcmd.assign("cd " + getRemoteDir() + cmdSep); + // remove files on distant machine + if(getRemoteDir().size()) cdcmd.assign("cd " + getRemoteDir() + cmdSep); mySystem("ssh " + getRemoteHost() + " '" + cdcmd + rmcmd + "'"); } if(!run()) OLMsg::Error("Invalid commandline <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); + getCommandLine().c_str(), getName().c_str()); - if(getList("OutputFiles",choices)){ + if(getList("OutputFiles", choices)) { for(unsigned int i = 0; i < choices.size(); i++) - if(syncOutputFile(getWorkingDir(), choices[i])) - OLMsg::Info("ok"); + if(syncOutputFile(getWorkingDir(), choices[i])) OLMsg::Info("ok"); } } - // REMOTE ENCAPSULATED Client // bool RemoteEncapsulatedClient::checkCommandLine(){ // return remoteClient::checkCommandLine(getCommandLine()); // } -bool RemoteEncapsulatedClient::checkCommandLine(){ +bool RemoteEncapsulatedClient::checkCommandLine() +{ bool success; OLMsg::Info("Check command line <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); - if(getCommandLine().empty()) - return false; + getCommandLine().c_str(), getName().c_str()); + if(getCommandLine().empty()) return false; success = remoteClient::checkCommandLine(getCommandLine()); - if(success){ - OLMsg::SetOnelabString(getName()+"/CommandLine",getCommandLine(),false); + if(success) { + OLMsg::SetOnelabString(getName() + "/CommandLine", getCommandLine(), false); OLMsg::Info("Command line ok"); } - else{ - // setCommandLine(""); + else { + // setCommandLine(""); OLMsg::SetOnelabString(getName() + "/CommandLine", getCommandLine(), true); OLMsg::Error("Invalid command line <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); + getCommandLine().c_str(), getName().c_str()); } return success; } -std::string RemoteEncapsulatedClient::buildCommandLine(){ - std::string cmd=OLMsg::GetOnelabString("LoaderPathName"); - OLMsg::Info("Loader pathname=<%s>",cmd.c_str()); +std::string RemoteEncapsulatedClient::buildCommandLine() +{ + std::string cmd = OLMsg::GetOnelabString("LoaderPathName"); + OLMsg::Info("Loader pathname=<%s>", cmd.c_str()); return cmd; } -void RemoteEncapsulatedClient::compute(){ +void RemoteEncapsulatedClient::compute() +{ std::vector<std::string> choices; analyze(); @@ -1220,67 +1243,63 @@ void RemoteEncapsulatedClient::compute(){ OLMsg::Info("Computes <%s>", getName().c_str()); setAction("compute"); - if(getList("InputFiles",choices)){ + if(getList("InputFiles", choices)) { for(unsigned int i = 0; i < choices.size(); i++) - if(syncInputFile(getWorkingDir(), choices[i])) - OLMsg::Info("ok"); + if(syncInputFile(getWorkingDir(), choices[i])) OLMsg::Info("ok"); } - std::string rmcmd=""; - if(buildRmCommand(rmcmd)){ + std::string rmcmd = ""; + if(buildRmCommand(rmcmd)) { std::string cdcmd; - //remove files on local machine - if(getWorkingDir().size()) - cdcmd.assign("cd " + getWorkingDir() + cmdSep); + // remove files on local machine + if(getWorkingDir().size()) cdcmd.assign("cd " + getWorkingDir() + cmdSep); mySystem(cdcmd + rmcmd); - //remove files on distant machine - if(getRemoteDir().size()) - cdcmd.assign("cd " + getRemoteDir() + cmdSep); + // remove files on distant machine + if(getRemoteDir().size()) cdcmd.assign("cd " + getRemoteDir() + cmdSep); mySystem("ssh " + getRemoteHost() + " '" + cdcmd + rmcmd + "'"); } // the client command line is built and stored in a onelab parameter std::string cmd; cmd.assign("ssh " + getRemoteHost() + " '"); - if(getRemoteDir().size()) - cmd.append("cd " + getRemoteDir() + cmdSep); + if(getRemoteDir().size()) cmd.append("cd " + getRemoteDir() + cmdSep); cmd.append(" " + QuoteExecPath(getCommandLine())); cmd.append(" " + getString("Arguments") + " '"); - OLMsg::SetOnelabString(getName()+"/FullCmdLine",cmd,false); + OLMsg::SetOnelabString(getName() + "/FullCmdLine", cmd, false); - OLMsg::Info("Command line=<%s>",cmd.c_str()); + OLMsg::Info("Command line=<%s>", cmd.c_str()); - if(!run()) // localNetworkClient::run() is called + if(!run()) // localNetworkClient::run() is called OLMsg::Error("Invalid commandline <%s> for client <%s>", - getCommandLine().c_str(), getName().c_str()); + getCommandLine().c_str(), getName().c_str()); - if(getList("OutputFiles",choices)){ + if(getList("OutputFiles", choices)) { for(unsigned int i = 0; i < choices.size(); i++) - if(syncOutputFile(getWorkingDir(), choices[i])) - OLMsg::Info("ok"); + if(syncOutputFile(getWorkingDir(), choices[i])) OLMsg::Info("ok"); } } - - // ONELAB additional TOOLS (no access to server, no messages) -std::string itoa(const int i){ +std::string itoa(const int i) +{ std::ostringstream tmp; - tmp << i ; + tmp << i; return tmp.str(); } -std::string ftoa(const double x){ +std::string ftoa(const double x) +{ std::stringstream Num; Num << x; return Num.str(); } -int mySystem(std::string commandLine){ - //Don't use OLMsg::Info here otherwise the message appears twice - //in the Gmsh message window. +int mySystem(std::string commandLine) +{ + // Don't use OLMsg::Info here otherwise the message appears twice + // in the Gmsh message window. if(OLMsg::GetVerbosity()) std::cout << "Onelab: Calling <" << commandLine << ">" << std::endl; return SystemCall(commandLine.c_str(), true); @@ -1292,21 +1311,23 @@ int mySystem(std::string commandLine){ #include <io.h> #endif -bool checkIfPresent(std::string fileName){ +bool checkIfPresent(std::string fileName) +{ struct stat buf; - if (!stat(fileName.c_str(), &buf)) + if(!stat(fileName.c_str(), &buf)) return true; else return false; } -bool chmod(std::string fileName){ +bool chmod(std::string fileName) +{ struct stat info; stat(fileName.c_str(), &info); // chmod u=rwx #if defined(WIN32) - if (_chmod(fileName.c_str(), _S_IREAD | _S_IWRITE) != 0){ + if(_chmod(fileName.c_str(), _S_IREAD | _S_IWRITE) != 0) { #else - if (chmod(fileName.c_str(), S_IRWXU) != 0){ + if(chmod(fileName.c_str(), S_IRWXU) != 0) { #endif perror("chmod() error"); return false; @@ -1319,7 +1340,8 @@ bool chmod(std::string fileName){ #if !defined(WIN32) #include <unistd.h> #include <pwd.h> -std::string getUserHomedir(){ +std::string getUserHomedir() +{ struct passwd *pw = getpwuid(getuid()); std::string str(pw->pw_dir); str.append("/"); @@ -1334,8 +1356,7 @@ std::string sanitizeString(const std::string &in, const std::string &forbidden) { std::string out; for(unsigned int i = 0; i < in.size(); i++) - if ( forbidden.find(in[i]) == std::string::npos) - out.push_back(in[i]); + if(forbidden.find(in[i]) == std::string::npos) out.push_back(in[i]); return out; } @@ -1343,24 +1364,19 @@ std::string sanitize(const std::string &in) { std::string out, forbidden(" ();\n"); for(unsigned int i = 0; i < in.size(); i++) - if ( forbidden.find(in[i]) == std::string::npos) - out.push_back(in[i]); + if(forbidden.find(in[i]) == std::string::npos) out.push_back(in[i]); return out; } -std::string quote(const std::string &in){ - return "\"" + in + "\""; -} +std::string quote(const std::string &in) { return "\"" + in + "\""; } std::string unquote(const std::string &in) { if(in.empty()) return ""; - size_t pos0=in.find_first_not_of(" "); - size_t pos=in.find_last_not_of(" "); - if( (pos0 != std::string::npos) && (!in.compare(pos0,1,"\""))) - pos0++; - if( (pos != std::string::npos) && (!in.compare(pos,1,"\""))) - pos--; - return in.substr(pos0,pos-pos0+1); + size_t pos0 = in.find_first_not_of(" "); + size_t pos = in.find_last_not_of(" "); + if((pos0 != std::string::npos) && (!in.compare(pos0, 1, "\""))) pos0++; + if((pos != std::string::npos) && (!in.compare(pos, 1, "\""))) pos--; + return in.substr(pos0, pos - pos0 + 1); } std::string FixWindowsQuotes(const std::string &in) @@ -1383,10 +1399,10 @@ std::string QuoteExecPath(const std::string &in) std::string removeBlanks(const std::string &in) { - size_t pos0=in.find_first_not_of(" \t"); - size_t pos=in.find_last_not_of(" \t"); - if( (pos0 != std::string::npos) && (pos != std::string::npos)) - return in.substr(pos0, pos-pos0+1); + size_t pos0 = in.find_first_not_of(" \t"); + size_t pos = in.find_last_not_of(" \t"); + if((pos0 != std::string::npos) && (pos != std::string::npos)) + return in.substr(pos0, pos - pos0 + 1); else return ""; } @@ -1395,17 +1411,18 @@ std::vector<std::string> SplitOLFileName(const std::string &in) { // returns [local file tag, baseName, ol extension] size_t posb = in.find(onelabExtension); - size_t posa = in.find(localFileTag) + localFileTag.size() ; + size_t posa = in.find(localFileTag) + localFileTag.size(); - if(posb != in.size()-onelabExtension.size()) posb=in.size(); + if(posb != in.size() - onelabExtension.size()) posb = in.size(); if(posa != localFileTag.size()) posa = 0; std::vector<std::string> s(3); s[0] = in.substr(0, posa); - s[1] = in.substr(posa, posb-posa); - s[2] = in.substr(posb, in.size()-posb); + s[1] = in.substr(posa, posb - posa); + s[2] = in.substr(posb, in.size() - posb); - //std::cout << "FHF in=<" << s[0] << "|" << s[1] << "|" << s[2] << ">" << std::endl; + // std::cout << "FHF in=<" << s[0] << "|" << s[1] << "|" << s[2] << ">" << + // std::endl; return s; } @@ -1414,25 +1431,25 @@ std::vector<std::string> SplitOLHostName(const std::string &in) // returns [ hostname, directory] std::vector<std::string> s(2); size_t pos = in.find(":"); - if(pos == std::string::npos){ + if(pos == std::string::npos) { s[0] = in; s[1] = ""; } - else{ - s[0] = in.substr(0,pos); - s[1] = FixPathName(in.substr(pos+1,in.size()-pos-1)); + else { + s[0] = in.substr(0, pos); + s[1] = FixPathName(in.substr(pos + 1, in.size() - pos - 1)); } - //std::cout << "FHF in=<" << s[0] << "|" << s[1] << std::endl; + // std::cout << "FHF in=<" << s[0] << "|" << s[1] << std::endl; return s; } std::string FixOLPath(const std::string &in) { std::string out = in; - if(out.size()){ + if(out.size()) { size_t pos = out.find_last_not_of(" 0123456789"); - if((pos != std::string::npos) && (out.compare(pos,1,"/"))) - out.insert(pos,"/"); + if((pos != std::string::npos) && (out.compare(pos, 1, "/"))) + out.insert(pos, "/"); } return out; } @@ -1441,11 +1458,12 @@ std::string FixPathName(const std::string &in) { std::string out = in; if(out.size()) - if(out[out.size()-1] != dirSep) out.push_back(dirSep); + if(out[out.size() - 1] != dirSep) out.push_back(dirSep); return out; } -// std::vector <double> extract_column(const unsigned int col, const array data){ +// std::vector <double> extract_column(const unsigned int col, const array +// data){ // std::vector<double> column; // for(unsigned int i=0; i<data.size(); i++) // if(col<=data[i].size()) @@ -1455,37 +1473,39 @@ std::string FixPathName(const std::string &in) // return column; // } -double find_in_array(int lin, int col, const std::vector <std::vector <double> > &data){ - if(data.size()){ - if(lin<0) lin=(int)data.size()-1; - if(lin<(int)data.size()){ - if ( col>=0 && col<(int)data[lin].size() ) - return data[lin][col]; +double find_in_array(int lin, int col, + const std::vector<std::vector<double> > &data) +{ + if(data.size()) { + if(lin < 0) lin = (int)data.size() - 1; + if(lin < (int)data.size()) { + if(col >= 0 && col < (int)data[lin].size()) return data[lin][col]; } } - OLMsg::Error("Find in array: (%d,%d) out of range",lin,col); - return(0); + OLMsg::Error("Find in array: (%d,%d) out of range", lin, col); + return (0); } -array read_array(std::string fileName, char sep){ +array read_array(std::string fileName, char sep) +{ std::ifstream infile(sanitize(fileName).c_str()); - std::vector <std::vector <double> > array; + std::vector<std::vector<double> > array; - size_t deb,end; + size_t deb, end; double temp; - while (infile){ + while(infile) { std::string s; - if (!getline( infile, s )) break; - std::vector <double> record; - end=0; - while ( (deb=s.find_first_not_of(" \t\n", end)) != std::string::npos ) { - end=s.find_first_of(" \t\n",deb); - temp=atof( s.substr(deb,end).c_str() ); - record.push_back( temp ); + if(!getline(infile, s)) break; + std::vector<double> record; + end = 0; + while((deb = s.find_first_not_of(" \t\n", end)) != std::string::npos) { + end = s.find_first_of(" \t\n", deb); + temp = atof(s.substr(deb, end).c_str()); + record.push_back(temp); } - array.push_back( record ); + array.push_back(record); } - if (!infile.eof()){ + if(!infile.eof()) { OLMsg::Error("Error reading array\n"); array.resize(0); } diff --git a/contrib/onelab/OnelabClients.h b/contrib/onelab/OnelabClients.h index 4f9642304cdb8bcd67dabb5135fa5c07d9e345fa..f91e2db2bdedddb10679ca673989e8cf88ddf682 100644 --- a/contrib/onelab/OnelabClients.h +++ b/contrib/onelab/OnelabClients.h @@ -21,7 +21,7 @@ static std::string onelabExtension(".ol"); static std::string localFileTag("_"); // Possible actions for clients -enum parseMode {REGISTER, ANALYZE, COMPUTE, EXIT}; +enum parseMode { REGISTER, ANALYZE, COMPUTE, EXIT }; // TOOLS @@ -33,8 +33,7 @@ int mySystem(std::string commandLine); std::string getCurrentWorkdir(); std::string getUserHomedir(); std::string sanitize(const std::string &in); -std::string sanitizeString(const std::string &in, - const std::string &forbidden); +std::string sanitizeString(const std::string &in, const std::string &forbidden); std::string removeBlanks(const std::string &in); std::vector<std::string> SplitOLFileName(const std::string &in); std::vector<std::string> SplitOLHostName(const std::string &in); @@ -45,28 +44,30 @@ std::string QuoteExecPath(const std::string &in); std::string unquote(const std::string &in); // Parser TOOLS -int enclosed(const std::string &in, std::vector<std::string> &arguments, size_t &end); -int extract(const std::string &in, std::string ¶mName, std::string &action, std::vector<std::string> &arguments); -std::string extractExpandPattern(const std::string& str); +int enclosed(const std::string &in, std::vector<std::string> &arguments, + size_t &end); +int extract(const std::string &in, std::string ¶mName, std::string &action, + std::vector<std::string> &arguments); +std::string extractExpandPattern(const std::string &str); -typedef std::vector <std::vector <double> > array; +typedef std::vector<std::vector<double> > array; array read_array(std::string fileName, char sep); -double find_in_array(int i, int j, const std::vector <std::vector <double> > &data); +double find_in_array(int i, int j, + const std::vector<std::vector<double> > &data); -static std::string getShortName(const std::string &name) { +static std::string getShortName(const std::string &name) +{ std::string s = name; // remove path std::string::size_type last = name.find_last_of('/'); - if(last != std::string::npos) - s = name.substr(last + 1); + if(last != std::string::npos) s = name.substr(last + 1); // remove starting numbers - while(s.size() && s[0] >= '0' && s[0] <= '9') - s = s.substr(1); + while(s.size() && s[0] >= '0' && s[0] <= '9') s = s.substr(1); return s; } -class ShortNameLessThan{ - public: +class ShortNameLessThan { +public: bool operator()(const std::string p1, const std::string p2) const { return getShortName(p1) < getShortName(p2); @@ -106,8 +107,8 @@ NativeClient, RemoteINterfacedClient InterfacedClient, RemoteInterfacesClient Encapsulated, RemoteEncapsulated */ -class localSolverClient : public onelab::localClient{ - private: +class localSolverClient : public onelab::localClient { +private: std::string _commandLine; std::string _workingDir; bool _remote; @@ -115,66 +116,67 @@ class localSolverClient : public onelab::localClient{ bool _onelabBlock; std::set<std::string, ShortNameLessThan> _parameters; std::string longName(const std::string name); - public: - localSolverClient(const std::string &name, const std::string &cmdl, - const std::string &wdir) - : onelab::localClient(name), _commandLine(cmdl), _workingDir(wdir), - _remote(false), _active(0), _onelabBlock(false) { + +public: + localSolverClient(const std::string &name, const std::string &cmdl, + const std::string &wdir) + : onelab::localClient(name), _commandLine(cmdl), _workingDir(wdir), + _remote(false), _active(0), _onelabBlock(false) + { } - virtual ~localSolverClient(){} - const std::string &getCommandLine(){ return _commandLine; } + virtual ~localSolverClient() {} + const std::string &getCommandLine() { return _commandLine; } const std::string &getWorkingDir() { return _workingDir; } - virtual void setCommandLine(const std::string &s){ _commandLine = s; } - virtual void setWorkingDir(const std::string &s){ _workingDir = s; } + virtual void setCommandLine(const std::string &s) { _commandLine = s; } + virtual void setWorkingDir(const std::string &s) { _workingDir = s; } void setAction(const std::string action); const std::string getString(const std::string what); - const bool getList(const std::string type, - std::vector<std::string> &choices); + const bool getList(const std::string type, std::vector<std::string> &choices); const bool isRemote() { return _remote; } - const void setRemote(bool flag){ _remote = flag; } + const void setRemote(bool flag) { _remote = flag; } const bool isActive() { return (bool)_active; } - const void setActive(int val) { _active=val; } + const void setActive(int val) { _active = val; } int getActive() { return _active; } virtual std::string toChar(); // parser commands void modify_tags(const std::string lab, const std::string com); const bool isOnelabBlock() { return _onelabBlock; } - const void openOnelabBlock() { _onelabBlock=true; } - const void closeOnelabBlock() { _onelabBlock=false; } + const void openOnelabBlock() { _onelabBlock = true; } + const void closeOnelabBlock() { _onelabBlock = false; } std::string resolveString(const std::string &line); std::string resolveGetVal(std::string line); bool resolveLogicExpr(std::vector<std::string> arguments); bool resolveRange(const std::string &in, std::vector<double> &arguments); - void parse_sentence(std::string line) ; - void parse_oneline(std::string line, std::ifstream &infile) ; - bool parse_block(std::ifstream &infile) ; - bool parse_ifstatement(std::ifstream &infile, bool condition) ; - bool parse_onefile(std::string ifileName, bool mandatory=true); + void parse_sentence(std::string line); + void parse_oneline(std::string line, std::ifstream &infile); + bool parse_block(std::ifstream &infile); + bool parse_ifstatement(std::ifstream &infile, bool condition); + bool parse_onefile(std::string ifileName, bool mandatory = true); void convert_oneline(std::string line, std::ifstream &infile, - std::ofstream &outfile); - bool convert_ifstatement(std::ifstream &infile, - std::ofstream &outfile, bool condition) ; + std::ofstream &outfile); + bool convert_ifstatement(std::ifstream &infile, std::ofstream &outfile, + bool condition); void convert_onefile(std::string ifileName, std::ofstream &outfile); virtual void client_sentence(const std::string &name, - const std::string &action, - const std::vector<std::string> &arguments); + const std::string &action, + const std::vector<std::string> &arguments); // execution bool buildRmCommand(std::string &cmd); virtual bool isNative() { return false; } void FixExecPath(const std::string &in); virtual bool checkCommandLine(); - virtual void analyze() =0; - virtual void compute() =0; - void addNumberChoice(std::string name, double val, bool readOnly=false); + virtual void analyze() = 0; + virtual void compute() = 0; + void addNumberChoice(std::string name, double val, bool readOnly = false); void PostArray(std::vector<std::string> choices); void GmshMerge(std::vector<std::string> choices); }; -class localNetworkSolverClient : public localSolverClient{ - private: +class localNetworkSolverClient : public localSolverClient { +private: // command line option to specify socket std::string _socketSwitch; // pid of the remote network client @@ -183,18 +185,22 @@ class localNetworkSolverClient : public localSolverClient{ GmshServer *_gmshServer; // flag indicating whether socket communication should be monitored bool _socketMsg; - public: - localNetworkSolverClient(const std::string &name, const std::string &cmdl, const std::string &wdir) - : localSolverClient(name,cmdl,wdir), _socketSwitch("-onelab"), - _pid(-1), _gmshServer(0), _socketMsg(false) {} - virtual ~localNetworkSolverClient(){} - virtual bool isNetworkClient(){ return true; } - const std::string &getSocketSwitch(){ return _socketSwitch; } - void setSocketSwitch(const std::string &s){ _socketSwitch = s; } - int getPid(){ return _pid; } - void setPid(int pid){ _pid = pid; } - GmshServer *getGmshServer(){ return _gmshServer; } - void setGmshServer(GmshServer *server){ _gmshServer = server; } + +public: + localNetworkSolverClient(const std::string &name, const std::string &cmdl, + const std::string &wdir) + : localSolverClient(name, cmdl, wdir), _socketSwitch("-onelab"), _pid(-1), + _gmshServer(0), _socketMsg(false) + { + } + virtual ~localNetworkSolverClient() {} + virtual bool isNetworkClient() { return true; } + const std::string &getSocketSwitch() { return _socketSwitch; } + void setSocketSwitch(const std::string &s) { _socketSwitch = s; } + int getPid() { return _pid; } + void setPid(int pid) { _pid = pid; } + GmshServer *getGmshServer() { return _gmshServer; } + void setGmshServer(GmshServer *server) { _gmshServer = server; } bool receiveMessage(); bool isNative() { return true; } @@ -203,18 +209,21 @@ class localNetworkSolverClient : public localSolverClient{ virtual bool run(); virtual bool kill(); - virtual void analyze() =0; - virtual void compute() =0; + virtual void analyze() = 0; + virtual void compute() = 0; }; class remoteClient { - private: +private: std::string _remoteHost; std::string _remoteDir; - public: - remoteClient(const std::string &host, const std::string &rdir) - : _remoteHost(host), _remoteDir(rdir) {} - ~remoteClient(){} + +public: + remoteClient(const std::string &host, const std::string &rdir) + : _remoteHost(host), _remoteDir(rdir) + { + } + ~remoteClient() {} const std::string &getRemoteHost() const { return _remoteHost; } const std::string &getRemoteDir() const { return _remoteDir; } @@ -228,46 +237,55 @@ class remoteClient { // ONELAB CLIENTS class MetaModel : public localSolverClient { - private: +private: // clients in order of appearance in the metamodel std::vector<localSolverClient *> _clients; // action performed at this metamodel call parseMode _todo; // remains false as long as the successive clients need no recomputation bool _started; - public: - MetaModel(const std::string &cmdl, const std::string &wdir, const std::string &cname, const std::string &fname) - : localSolverClient(cname,cmdl,wdir){ + +public: + MetaModel(const std::string &cmdl, const std::string &wdir, + const std::string &cname, const std::string &fname) + : localSolverClient(cname, cmdl, wdir) + { clientName = cname; genericNameFromArgs = fname.size() ? fname : cmdl; setWorkingDir(wdir); // wdir from args - _todo=REGISTER; - _started=false; + _todo = REGISTER; + _started = false; construct(); } - ~MetaModel(){} - typedef std::vector<localSolverClient*>::iterator citer; - void setTodo(const parseMode x) { _todo=x; } + ~MetaModel() {} + typedef std::vector<localSolverClient *>::iterator citer; + void setTodo(const parseMode x) { _todo = x; } parseMode getTodo() { return _todo; } - bool isTodo(const parseMode x) { return (_todo==x);} - bool isStarted(bool x) { _started = _started || x; return _started; } - citer firstClient(){ return _clients.begin(); } - citer lastClient(){ return _clients.end(); } + bool isTodo(const parseMode x) { return (_todo == x); } + bool isStarted(bool x) + { + _started = _started || x; + return _started; + } + citer firstClient() { return _clients.begin(); } + citer lastClient() { return _clients.end(); } int getNumClients() { return _clients.size(); }; void registerClient(const std::string &name, const std::string &type, - const std::string &cmdl, const std::string &host, - const std::string &rdir); + const std::string &cmdl, const std::string &host, + const std::string &rdir); bool checkCommandLines(); void saveCommandLines(); bool findCommandLine(const std::string &client, const std::string &host); - localSolverClient *findClientByName(std::string name){ - for(unsigned int i=0; i<_clients.size(); i++) + localSolverClient *findClientByName(std::string name) + { + for(unsigned int i = 0; i < _clients.size(); i++) if(_clients[i]->getName() == name) return _clients[i]; return 0; } - void showClientStatus(){ - for (citer it=firstClient(); it<lastClient(); it++){ + void showClientStatus() + { + for(citer it = firstClient(); it < lastClient(); it++) { bool changed = onelab::server::instance()->getChanged((*it)->getName()); std::cout << "(" << changed << ") " << (*it)->getName() << std::endl; } @@ -275,8 +293,8 @@ class MetaModel : public localSolverClient { std::string genericNameFromArgs, clientName; void client_sentence(const std::string &name, const std::string &action, - const std::vector<std::string> &arguments); - std::string toChar(){ return "";} + const std::vector<std::string> &arguments); + std::string toChar() { return ""; } void PostArray(std::vector<std::string> choices); void construct(); void analyze(); @@ -285,10 +303,13 @@ class MetaModel : public localSolverClient { class InterfacedClient : public localSolverClient { // n'utilise pas localNetworkSolverClient::run mais client::run() - public: - InterfacedClient(const std::string &name, const std::string &cmdl, const std::string &wdir) - : localSolverClient(name,cmdl,wdir) {} - ~InterfacedClient(){} +public: + InterfacedClient(const std::string &name, const std::string &cmdl, + const std::string &wdir) + : localSolverClient(name, cmdl, wdir) + { + } + ~InterfacedClient() {} void analyze(); void convert(); @@ -297,21 +318,26 @@ class InterfacedClient : public localSolverClient { class NativeClient : public localNetworkSolverClient { public: - NativeClient(const std::string &name, const std::string &cmdl, const std::string &wdir) - : localNetworkSolverClient(name,cmdl,wdir) {} - ~NativeClient(){} + NativeClient(const std::string &name, const std::string &cmdl, + const std::string &wdir) + : localNetworkSolverClient(name, cmdl, wdir) + { + } + ~NativeClient() {} virtual void analyze(); virtual void compute(); }; - -class EncapsulatedClient : public localNetworkSolverClient{ - public: - EncapsulatedClient(const std::string &name, const std::string &cmdl, const std::string &wdir) : localNetworkSolverClient(name,cmdl,wdir) { +class EncapsulatedClient : public localNetworkSolverClient { +public: + EncapsulatedClient(const std::string &name, const std::string &cmdl, + const std::string &wdir) + : localNetworkSolverClient(name, cmdl, wdir) + { setSocketSwitch("-lol"); } - ~EncapsulatedClient(){} + ~EncapsulatedClient() {} std::string buildCommandLine(); void analyze(); @@ -319,44 +345,58 @@ class EncapsulatedClient : public localNetworkSolverClient{ void compute(); }; - -class RemoteInterfacedClient : public InterfacedClient, public remoteClient { +class RemoteInterfacedClient + : public InterfacedClient + , public remoteClient { public: - RemoteInterfacedClient(const std::string &name, const std::string &cmdl, const std::string &wdir, const std::string &host, const std::string &rdir) - : InterfacedClient(name,cmdl,wdir), remoteClient(host,rdir) { + RemoteInterfacedClient(const std::string &name, const std::string &cmdl, + const std::string &wdir, const std::string &host, + const std::string &rdir) + : InterfacedClient(name, cmdl, wdir), remoteClient(host, rdir) + { setRemote(true); } - ~RemoteInterfacedClient(){} + ~RemoteInterfacedClient() {} bool checkCommandLine(); // uses InterfacedClient::analyze() - void compute() ; + void compute(); }; -class RemoteNativeClient : public NativeClient, public remoteClient { +class RemoteNativeClient + : public NativeClient + , public remoteClient { public: - RemoteNativeClient(const std::string &name, const std::string &cmdl, const std::string &wdir, const std::string &host, const std::string &rdir) - : NativeClient(name,cmdl,wdir), remoteClient(host,rdir) { + RemoteNativeClient(const std::string &name, const std::string &cmdl, + const std::string &wdir, const std::string &host, + const std::string &rdir) + : NativeClient(name, cmdl, wdir), remoteClient(host, rdir) + { setRemote(true); } - ~RemoteNativeClient(){} + ~RemoteNativeClient() {} std::string buildCommandLine(); bool checkCommandLine(); void analyze(); - void compute() ; + void compute(); }; -class RemoteEncapsulatedClient : public EncapsulatedClient, public remoteClient { +class RemoteEncapsulatedClient + : public EncapsulatedClient + , public remoteClient { public: - RemoteEncapsulatedClient(const std::string &name, const std::string &cmdl, const std::string &wdir, const std::string &host, const std::string &rdir) - : EncapsulatedClient(name,cmdl,wdir), remoteClient(host,rdir) { + RemoteEncapsulatedClient(const std::string &name, const std::string &cmdl, + const std::string &wdir, const std::string &host, + const std::string &rdir) + : EncapsulatedClient(name, cmdl, wdir), remoteClient(host, rdir) + { setRemote(true); } - ~RemoteEncapsulatedClient(){} + ~RemoteEncapsulatedClient() {} std::string buildCommandLine(); bool checkCommandLine(); - void compute() ; + void compute(); }; #endif diff --git a/contrib/onelab/OnelabMessage.cpp b/contrib/onelab/OnelabMessage.cpp index c8cfe681ccfae3077acd8cb3009c24b3c5db89b8..f9e4ebf41641a9b5735ee0e536f330aafa6bf6db 100644 --- a/contrib/onelab/OnelabMessage.cpp +++ b/contrib/onelab/OnelabMessage.cpp @@ -14,7 +14,7 @@ #define ALWAYS_TRUE 1 -//onelab::remoteNetworkClient *OLMsg::loader = 0; +// onelab::remoteNetworkClient *OLMsg::loader = 0; int OLMsg::_commRank = 0; int OLMsg::_commSize = 1; @@ -29,17 +29,17 @@ std::string OLMsg::_commandLine; std::string OLMsg::_launchDate; GmshClient *OLMsg::_client = 0; onelab::client *OLMsg::_onelabClient = 0; -bool OLMsg::hasGmsh=false; +bool OLMsg::hasGmsh = false; std::set<std::string, fullNameLessThan> OLMsg::_fullNameDict; void (*OLMsg::gui_wait_fct)(double time) = 0; -#if defined(_MSC_VER) && (_MSC_VER >= 1310) //NET 2003 +#if defined(_MSC_VER) && (_MSC_VER >= 1310) // NET 2003 #define vsnprintf _vsnprintf #else #if defined(HAVE_NO_VSNPRINTF) static int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) { - if(strlen(fmt) > size - 1){ // just copy the format + if(strlen(fmt) > size - 1) { // just copy the format strncpy(str, fmt, size - 1); str[size - 1] = '\0'; return size; @@ -49,8 +49,6 @@ static int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) #endif #endif - - void OLMsg::Init(int argc, char **argv) { time_t now; @@ -58,7 +56,7 @@ void OLMsg::Init(int argc, char **argv) _launchDate = ctime(&now); _launchDate.resize(_launchDate.size() - 1); _commandLine.clear(); - for(int i = 0; i < argc; i++){ + for(int i = 0; i < argc; i++) { if(i) _commandLine += " "; _commandLine += argv[i]; } @@ -66,9 +64,7 @@ void OLMsg::Init(int argc, char **argv) void OLMsg::Exit(int level) { - if(level){ - exit(level); - } + if(level) { exit(level); } exit(_errorCount); } @@ -82,22 +78,21 @@ void OLMsg::Fatal(const char *fmt, ...) vsnprintf(str, sizeof(str), fmt, args); va_end(args); - //if(_callback) (*_callback)("Fatal", str); - //if(_client) _client->Error(str); + // if(_callback) (*_callback)("Fatal", str); + // if(_client) _client->Error(str); - if(_onelabClient && OLMsg::hasGmsh) - _onelabClient->sendError(str); + if(_onelabClient && OLMsg::hasGmsh) _onelabClient->sendError(str); - if(ALWAYS_TRUE){ + if(ALWAYS_TRUE) { if(_commSize > 1) fprintf(stderr, "Fatal : [On processor %d] %s\n", _commRank, str); else fprintf(stderr, "Fatal : %s\n", str); - fflush(stderr); + fflush(stderr); } - //FinalizeClient(); + // FinalizeClient(); FinalizeOnelab(); - //delete loader; + // delete loader; Exit(1); } @@ -113,12 +108,11 @@ void OLMsg::Error(const char *fmt, ...) vsnprintf(str, sizeof(str), fmt, args); va_end(args); - //if(_callback) (*_callback)("Error", str); - //if(_client) _client->Error(str); - if(_onelabClient && OLMsg::hasGmsh) - _onelabClient->sendError(str); + // if(_callback) (*_callback)("Error", str); + // if(_client) _client->Error(str); + if(_onelabClient && OLMsg::hasGmsh) _onelabClient->sendError(str); - if(ALWAYS_TRUE){ + if(ALWAYS_TRUE) { if(_commSize > 1) fprintf(stderr, "Error : [On processor %d] %s\n", _commRank, str); else @@ -139,12 +133,11 @@ void OLMsg::Warning(const char *fmt, ...) vsnprintf(str, sizeof(str), fmt, args); va_end(args); - //if(_callback) (*_callback)("Warning", str); - //if(_client) _client->Warning(str); - if(_onelabClient && OLMsg::hasGmsh) - _onelabClient->sendWarning(str); + // if(_callback) (*_callback)("Warning", str); + // if(_client) _client->Warning(str); + if(_onelabClient && OLMsg::hasGmsh) _onelabClient->sendWarning(str); - if(ALWAYS_TRUE){ + if(ALWAYS_TRUE) { fprintf(stderr, "Warning : %s\n", str); fflush(stderr); } @@ -160,12 +153,11 @@ void OLMsg::Info(const char *fmt, ...) vsnprintf(str, sizeof(str), fmt, args); va_end(args); - //if(_callback) (*_callback)("Info", str); - //if(_client) _client->Info(str); - if(_onelabClient && OLMsg::hasGmsh) - _onelabClient->sendInfo(str); + // if(_callback) (*_callback)("Info", str); + // if(_client) _client->Info(str); + if(_onelabClient && OLMsg::hasGmsh) _onelabClient->sendInfo(str); - if(ALWAYS_TRUE){ + if(ALWAYS_TRUE) { fprintf(stdout, "Onelab : %s\n", str); fflush(stdout); } @@ -194,12 +186,11 @@ void OLMsg::Direct(int level, const char *fmt, ...) vsnprintf(str, sizeof(str), fmt, args); va_end(args); - //if(_callback) (*_callback)("Direct", str); - //if(_client) _client->Info(str); - if(_onelabClient && OLMsg::hasGmsh) - _onelabClient->sendInfo(str); + // if(_callback) (*_callback)("Direct", str); + // if(_client) _client->Info(str); + if(_onelabClient && OLMsg::hasGmsh) _onelabClient->sendInfo(str); - if(ALWAYS_TRUE){ + if(ALWAYS_TRUE) { fprintf(stdout, "%s\n", str); fflush(stdout); } @@ -216,13 +207,12 @@ void OLMsg::StatusBar(int num, bool log, const char *fmt, ...) vsnprintf(str, sizeof(str), fmt, args); va_end(args); - //if(_callback && log) (*_callback)("Info", str); - //if(_client && log) _client->Info(str); + // if(_callback && log) (*_callback)("Info", str); + // if(_client && log) _client->Info(str); - if(_onelabClient && OLMsg::hasGmsh) - _onelabClient->sendInfo(str); + if(_onelabClient && OLMsg::hasGmsh) _onelabClient->sendInfo(str); - if(log && ALWAYS_TRUE){ + if(log && ALWAYS_TRUE) { fprintf(stdout, "Info : %s\n", str); fflush(stdout); } @@ -235,30 +225,25 @@ void OLMsg::InitializeOnelab(const std::string &name) OLMsg::hasGmsh = OLMsg::GetOnelabNumber("IsMetamodel"); } -void OLMsg::SetGuiWaitFunction(void (*fct)(double time)){ - gui_wait_fct = fct; -} -void (*OLMsg::GetGuiWaitFunction())(double){ - return gui_wait_fct; -} +void OLMsg::SetGuiWaitFunction(void (*fct)(double time)) { gui_wait_fct = fct; } +void (*OLMsg::GetGuiWaitFunction())(double) { return gui_wait_fct; } double OLMsg::GetOnelabNumber(std::string name) { - if(_onelabClient){ + if(_onelabClient) { std::vector<onelab::number> ps; _onelabClient->get(ps, name); - if(ps.size()) - return ps[0].getValue(); + if(ps.size()) return ps[0].getValue(); } return 0; } void OLMsg::GetOnelabNumber(std::string name, double *val) { - if(_onelabClient){ + if(_onelabClient) { std::vector<onelab::number> ps; _onelabClient->get(ps, name); - if(ps.size()){ + if(ps.size()) { *val = ps[0].getValue(); return; } @@ -268,10 +253,10 @@ void OLMsg::GetOnelabNumber(std::string name, double *val) void OLMsg::SetOnelabNumber(std::string name, double val, bool visible) { - if(_onelabClient){ + if(_onelabClient) { std::vector<onelab::number> numbers; _onelabClient->get(numbers, name); - if(numbers.empty()){ + if(numbers.empty()) { numbers.resize(1); numbers[0].setName(name); } @@ -283,22 +268,23 @@ void OLMsg::SetOnelabNumber(std::string name, double val, bool visible) std::string OLMsg::GetOnelabString(std::string name) { - std::string str=""; - if(_onelabClient){ + std::string str = ""; + if(_onelabClient) { std::vector<onelab::string> ps; _onelabClient->get(ps, name); - if(ps.size() && ps[0].getValue().size()) - str = ps[0].getValue(); + if(ps.size() && ps[0].getValue().size()) str = ps[0].getValue(); } return str; } -bool OLMsg::GetOnelabChoices(std::string name, std::vector<std::string> &choices){ - if(_onelabClient){ +bool OLMsg::GetOnelabChoices(std::string name, + std::vector<std::string> &choices) +{ + if(_onelabClient) { std::vector<onelab::string> ps; _onelabClient->get(ps, name); - if(ps.size() && ps[0].getValue().size()){ - choices=ps[0].getChoices(); + if(ps.size() && ps[0].getValue().size()) { + choices = ps[0].getChoices(); return true; } } @@ -307,130 +293,139 @@ bool OLMsg::GetOnelabChoices(std::string name, std::vector<std::string> &choices void OLMsg::SetOnelabString(std::string name, std::string val, bool visible) { - if(_onelabClient){ + if(_onelabClient) { std::vector<onelab::string> strings; _onelabClient->get(strings, name); - if(strings.empty()){ + if(strings.empty()) { strings.resize(1); strings[0].setName(name); } strings[0].setValue(val); strings[0].setVisible(visible); - strings[0].setAttribute("NotInDb","True"); + strings[0].setAttribute("NotInDb", "True"); _onelabClient->set(strings[0]); } } void OLMsg::SetVisible(std::string name, bool visible) { - if(_onelabClient){ + if(_onelabClient) { std::vector<onelab::string> strings; _onelabClient->get(strings, name); - if(strings.size()){ + if(strings.size()) { strings[0].setVisible(visible); _onelabClient->set(strings[0]); } } } -void OLMsg::SetOnelabAttributeString(std::string name, - std::string attrib,std::string val){ - if(_onelabClient){ +void OLMsg::SetOnelabAttributeString(std::string name, std::string attrib, + std::string val) +{ + if(_onelabClient) { std::vector<onelab::string> ps; _onelabClient->get(ps, name); - if(ps.size()){ - ps[0].setAttribute(attrib,val); - } + if(ps.size()) { ps[0].setAttribute(attrib, val); } } } -std::string OLMsg::GetOnelabAttributeString(std::string name,std::string attrib){ - std::string str=""; - if(_onelabClient){ +std::string OLMsg::GetOnelabAttributeString(std::string name, + std::string attrib) +{ + std::string str = ""; + if(_onelabClient) { std::vector<onelab::string> ps; _onelabClient->get(ps, name); - if(ps.size()) - str = ps[0].getAttribute(attrib); + if(ps.size()) str = ps[0].getAttribute(attrib); } return str; } -std::string OLMsg::GetOnelabAttributeNumber(std::string name,std::string attrib){ - std::string str=""; - if(_onelabClient){ +std::string OLMsg::GetOnelabAttributeNumber(std::string name, + std::string attrib) +{ + std::string str = ""; + if(_onelabClient) { std::vector<onelab::number> ps; _onelabClient->get(ps, name); - if(ps.size()) - str = ps[0].getAttribute(attrib); + if(ps.size()) str = ps[0].getAttribute(attrib); } return str; } -int fullNameLessThan::compareFullNames(const std::string a, const std::string b) const{ +int fullNameLessThan::compareFullNames(const std::string a, + const std::string b) const +{ std::string::const_iterator ita, itb; // Compares the strings a and b // One-digit numbers at the beginning of the string // or directly following the separator '/' are ignored - ita = a.begin(); itb = b.begin(); + ita = a.begin(); + itb = b.begin(); // ignore a possible initial one-digit number - if( (ita < a.end()) && (*ita >= '0') && (*ita <= '9')) ita++; - if( (itb < b.end()) && (*itb >= '0') && (*itb <= '9')) itb++; - - while( (ita < a.end()) && (itb < b.end())) { - if(*ita == *itb){ - if(*ita == '/'){ // hence *itb == '/' - ita++; if( (ita < a.end()) && (*ita >= '0') && (*ita <= '9')) ita++; - itb++; if( (itb < b.end()) && (*itb >= '0') && (*itb <= '9')) itb++; + if((ita < a.end()) && (*ita >= '0') && (*ita <= '9')) ita++; + if((itb < b.end()) && (*itb >= '0') && (*itb <= '9')) itb++; + + while((ita < a.end()) && (itb < b.end())) { + if(*ita == *itb) { + if(*ita == '/') { // hence *itb == '/' + ita++; + if((ita < a.end()) && (*ita >= '0') && (*ita <= '9')) ita++; + itb++; + if((itb < b.end()) && (*itb >= '0') && (*itb <= '9')) itb++; } - else{ - ita++; - itb++; + else { + ita++; + itb++; } } else { // mismatched character found - return *ita < *itb ; + return *ita < *itb; } } // either string is at end() return !(itb == b.end()); } -void OLMsg::recordFullName(const std::string &name){ +void OLMsg::recordFullName(const std::string &name) +{ OLMsg::_fullNameDict.insert(name); } -std::string OLMsg::obtainFullName(const std::string &name){ +std::string OLMsg::obtainFullName(const std::string &name) +{ std::set<std::string, fullNameLessThan>::iterator it; // fullNameLessThan* comp=new fullNameLessThan; // std::cout << "Dict=" << OLMsg::_fullNameDict.size() << std::endl; // std::cout << "Looking for " << name << std::endl; - // for ( it=OLMsg::_fullNameDict.begin() ; it != OLMsg::_fullNameDict.end(); it++ ) - // std::cout << *it << " <" << comp->operator()(*it,name) << ">" << std::endl; + // for ( it=OLMsg::_fullNameDict.begin() ; it != OLMsg::_fullNameDict.end(); + // it++ ) + // std::cout << *it << " <" << comp->operator()(*it,name) << ">" << + // std::endl; // std::cout << std::endl; it = OLMsg::_fullNameDict.find(name); - if(it == OLMsg::_fullNameDict.end()){ - return name; - } - else{ + if(it == OLMsg::_fullNameDict.end()) { return name; } + else { return *it; } } -void OLMsg::MergeFile(const std::string &name){ - //Sends files (geo, pos, msh) to Gmsh - //The parameter Gmsh/MergedGeo ensures that the geometry is sent once. - if(_onelabClient){ - if(name.find(".geo") != std::string::npos){ - if(GetOnelabString("Gmsh/MergedGeo").empty()){ - SetOnelabString("Gmsh/MergedGeo",name,false); - Info("Merge a geometry <%s> to Gmsh", name.c_str()); - _onelabClient->sendMergeFileRequest(name); +void OLMsg::MergeFile(const std::string &name) +{ + // Sends files (geo, pos, msh) to Gmsh + // The parameter Gmsh/MergedGeo ensures that the geometry is sent once. + if(_onelabClient) { + if(name.find(".geo") != std::string::npos) { + if(GetOnelabString("Gmsh/MergedGeo").empty()) { + SetOnelabString("Gmsh/MergedGeo", name, false); + Info("Merge a geometry <%s> to Gmsh", name.c_str()); + _onelabClient->sendMergeFileRequest(name); } } - else{ + else { Info("Merge <%s> to Gmsh", name.c_str()); _onelabClient->sendMergeFileRequest(name); } @@ -439,9 +434,9 @@ void OLMsg::MergeFile(const std::string &name){ OLMsg::Info("Not connected to Gmsh"); } - -void OLMsg::FinalizeOnelab(){ - if(_onelabClient){ +void OLMsg::FinalizeOnelab() +{ + if(_onelabClient) { delete _onelabClient; _onelabClient = 0; _client = 0; diff --git a/contrib/onelab/OnelabMessage.h b/contrib/onelab/OnelabMessage.h index 5347d9d8160edb7eb8e3c5492399653b95646b34..b748e8a5010b32ba541896c9206fe859989c8681 100644 --- a/contrib/onelab/OnelabMessage.h +++ b/contrib/onelab/OnelabMessage.h @@ -16,25 +16,26 @@ class GmshClient; #ifndef GMSH_MESSAGE_H // the external message handler -class GmshMessage{ - public: - GmshMessage(){} - virtual ~GmshMessage(){} - virtual void operator()(std::string level, std::string message){} +class GmshMessage { +public: + GmshMessage() {} + virtual ~GmshMessage() {} + virtual void operator()(std::string level, std::string message) {} }; #endif -class fullNameLessThan{ +class fullNameLessThan { public: int compareFullNames(const std::string a, const std::string b) const; - bool operator()(const std::string p1, const std::string p2) const{ - return compareFullNames(p1,p2); + bool operator()(const std::string p1, const std::string p2) const + { + return compareFullNames(p1, p2); } }; // a class to manage messages class OLMsg { - private: +private: // current cpu number and total number of cpus static int _commRank, _commSize; // verbosity level (0: silent except fatal errors, 1: +errors, 2: @@ -58,7 +59,8 @@ class OLMsg { static std::set<std::string, fullNameLessThan> _fullNameDict; // Gmsh wait function static void (*gui_wait_fct)(double time); - public: + +public: OLMsg() {} static void Init(int argc, char **argv); static void Exit(int level); @@ -71,8 +73,8 @@ class OLMsg { /* static int GetNumThreads(); */ /* static int GetMaxThreads(); */ /* static int GetThreadNum(); */ - static void SetVerbosity(int val){ _verbosity = val; } - static int GetVerbosity(){ return _verbosity; } + static void SetVerbosity(int val) { _verbosity = val; } + static int GetVerbosity() { return _verbosity; } /* static std::string GetLaunchDate(){ return _launchDate; } */ /* static std::string GetCommandLineArgs(){ return _commandLine; } */ static void Fatal(const char *fmt, ...); @@ -84,52 +86,64 @@ class OLMsg { static void StatusBar(int num, bool log, const char *fmt, ...); static void Debug(const char *fmt, ...); static void ProgressMeter(int n, int N, const char *fmt, ...); - static void ProgressMeter(int n, int N){ ProgressMeter(n, N, ""); } - static void SetProgressMeterStep(int step){ _progressMeterStep = step; } - static void ResetProgressMeter(){ if(!_commRank) _progressMeterCurrent = 0; } - static double &Timer(std::string str){ return _timers[str]; } + static void ProgressMeter(int n, int N) { ProgressMeter(n, N, ""); } + static void SetProgressMeterStep(int step) { _progressMeterStep = step; } + static void ResetProgressMeter() + { + if(!_commRank) _progressMeterCurrent = 0; + } + static double &Timer(std::string str) { return _timers[str]; } static void PrintTimers(); - static void ResetErrorCounter(){ _warningCount = 0; _errorCount = 0; } + static void ResetErrorCounter() + { + _warningCount = 0; + _errorCount = 0; + } static void PrintErrorCounter(const char *title); - static int GetErrorCount(){ return _errorCount; } + static int GetErrorCount() { return _errorCount; } static double GetValue(const char *text, double defaultval); static std::string GetString(const char *text, std::string defaultval); static int GetAnswer(const char *question, int defaultval, const char *zero, - const char *one, const char *two=0); - //static void InitClient(std::string sockname); - //static void FinalizeClient(); - static GmshClient *GetClient(){ return _client; } + const char *one, const char *two = 0); + // static void InitClient(std::string sockname); + // static void FinalizeClient(); + static GmshClient *GetClient() { return _client; } - //static void SetLoaderName(const std::string &name){ _loaderName = name; } - //static std::string GetLoaderName(){ return _loaderName; } + // static void SetLoaderName(const std::string &name){ _loaderName = name; } + // static std::string GetLoaderName(){ return _loaderName; } static void SetGuiWaitFunction(void (*fct)(double time)); static void (*GetGuiWaitFunction())(double); - static void SetOnelabClient(onelab::client *client){ _onelabClient = client;} + static void SetOnelabClient(onelab::client *client) + { + _onelabClient = client; + } static void InitializeOnelab(const std::string &name); static void FinalizeOnelab(); - static void SetOnelabNumber(std::string name, double val, bool visible=true); + static void SetOnelabNumber(std::string name, double val, + bool visible = true); static void GetOnelabNumber(std::string name, double *val); static double GetOnelabNumber(std::string name); - static void SetOnelabString(std::string name, std::string val, bool visible=true); + static void SetOnelabString(std::string name, std::string val, + bool visible = true); static std::string GetOnelabString(std::string name); static void SetVisible(std::string name, bool visible); - static void SetOnelabAttributeString(std::string name, - std::string attrib,std::string val); - static std::string GetOnelabAttributeString(std::string name,std::string attrib); + static void SetOnelabAttributeString(std::string name, std::string attrib, + std::string val); + static std::string GetOnelabAttributeString(std::string name, + std::string attrib); static std::string GetOnelabAttributeNumber(std::string name, - std::string attrib); - //static std::vector<std::string> GetOnelabChoices(std::string name); - static bool GetOnelabChoices(std::string name, std::vector<std::string> &choices); - static void ExchangeOnelabParameter(const std::string &key, - std::vector<double> &val, - std::map<std::string, - std::vector<double> > &fopt, - std::map<std::string, - std::vector<std::string> > &copt); + std::string attrib); + // static std::vector<std::string> GetOnelabChoices(std::string name); + static bool GetOnelabChoices(std::string name, + std::vector<std::string> &choices); + static void ExchangeOnelabParameter( + const std::string &key, std::vector<double> &val, + std::map<std::string, std::vector<double> > &fopt, + std::map<std::string, std::vector<std::string> > &copt); static void MergeFile(const std::string &name); static bool hasGmsh; static void recordFullName(const std::string &name); diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp index 39e4def700bf4bd0c07e52d6d46476b8f6d67799..171a662de9c92ac712fc9c23a863b30cea941694 100644 --- a/contrib/onelab/OnelabParser.cpp +++ b/contrib/onelab/OnelabParser.cpp @@ -6,62 +6,65 @@ // reserved keywords for the onelab parser -namespace olkey{ +namespace olkey { static std::string deflabel("onelab.tags"); static std::string label("OL."), comment("#"), separator(";"); - static std::string line(label+"line"); - static std::string begin(label+"block"); - static std::string end(label+"endblock"); - static std::string include(label+"include"); - static std::string message(label+"msg"); - static std::string showParam(label+"show"); - static std::string showGmsh(label+"merge"); - static std::string dump(label+"dump"); - static std::string ifcond(label+"if"); - static std::string iftrue(label+"iftrue"), ifntrue(label+"ifntrue"); - static std::string olelse(label+"else"), olendif(label+"endif"); - static std::string getValue(label+"get"); - static std::string mathex(label+"eval"); -} + static std::string line(label + "line"); + static std::string begin(label + "block"); + static std::string end(label + "endblock"); + static std::string include(label + "include"); + static std::string message(label + "msg"); + static std::string showParam(label + "show"); + static std::string showGmsh(label + "merge"); + static std::string dump(label + "dump"); + static std::string ifcond(label + "if"); + static std::string iftrue(label + "iftrue"), ifntrue(label + "ifntrue"); + static std::string olelse(label + "else"), olendif(label + "endif"); + static std::string getValue(label + "get"); + static std::string mathex(label + "eval"); +} // namespace olkey // Client member functions defined here because they use parser commands -bool MetaModel::findCommandLine(const std::string &client, const std::string &host){ +bool MetaModel::findCommandLine(const std::string &client, + const std::string &host) +{ std::string fileName; size_t pos; - //std::cout << "FHF search cmdl: " << client << " , " << host << std::endl; + // std::cout << "FHF search cmdl: " << client << " , " << host << std::endl; fileName = getWorkingDir() + genericNameFromArgs + onelabExtension + ".save"; std::ifstream infile(fileName.c_str()); - if(infile.is_open()){ - while(infile.good()){ + if(infile.is_open()) { + while(infile.good()) { std::string line; - getline(infile,line); - if( (pos=line.find(olkey::separator)) != std::string::npos){ - std::string name, action; - std::vector<std::string> args; - extract(line.substr(0,pos),name,action,args); - // (name, action, args) = client.commandLine(cmdl{,rhost{,rdir}}) - std::string cmdl="", rhost="localhost", rdir=""; - cmdl = args[0]; - if(args.size() > 1) rhost= args[1]; - if(args.size() > 2) rdir = args[2]; - - if(name == client){ - if( (host.empty() && (rhost != "localhost" )) || - (host.size() && (rhost == host)) ) { - OLMsg::SetOnelabString(name + "/CommandLine", cmdl, false); - if(rhost.compare("localhost")){ - OLMsg::SetOnelabString(name + "/HostName", rhost, false); - if(rdir.size()) - OLMsg::SetOnelabString(name + "/RemoteDir", rdir, false); - } - //std::cout << "FHF found cmdl: " << cmdl << "," << rhost << std::endl; - return true; - } - } + getline(infile, line); + if((pos = line.find(olkey::separator)) != std::string::npos) { + std::string name, action; + std::vector<std::string> args; + extract(line.substr(0, pos), name, action, args); + // (name, action, args) = client.commandLine(cmdl{,rhost{,rdir}}) + std::string cmdl = "", rhost = "localhost", rdir = ""; + cmdl = args[0]; + if(args.size() > 1) rhost = args[1]; + if(args.size() > 2) rdir = args[2]; + + if(name == client) { + if((host.empty() && (rhost != "localhost")) || + (host.size() && (rhost == host))) { + OLMsg::SetOnelabString(name + "/CommandLine", cmdl, false); + if(rhost.compare("localhost")) { + OLMsg::SetOnelabString(name + "/HostName", rhost, false); + if(rdir.size()) + OLMsg::SetOnelabString(name + "/RemoteDir", rdir, false); + } + // std::cout << "FHF found cmdl: " << cmdl << "," << rhost << + // std::endl; + return true; + } + } } } } @@ -69,15 +72,16 @@ bool MetaModel::findCommandLine(const std::string &client, const std::string &ho return false; } -std::string localSolverClient::toChar(){ +std::string localSolverClient::toChar() +{ std::ostringstream sstream; - if(getCommandLine().size()){ + if(getCommandLine().size()) { sstream << getName() << ".commandLine(" << getCommandLine(); - std::string host=OLMsg::GetOnelabString(getName() + "/HostName"); + std::string host = OLMsg::GetOnelabString(getName() + "/HostName"); if(host.size() && host.compare("localhost")) { - sstream << "," << host ; - std::string rdir=OLMsg::GetOnelabString(getName() + "/RemoteDir"); + sstream << "," << host; + std::string rdir = OLMsg::GetOnelabString(getName() + "/RemoteDir"); if(rdir.size()) sstream << "," << rdir; } sstream << ");" << std::endl; @@ -85,185 +89,186 @@ std::string localSolverClient::toChar(){ return sstream.str(); } -void MetaModel::saveCommandLines(){ +void MetaModel::saveCommandLines() +{ std::vector<std::string> arguments, buffer; std::string fileName; fileName = getWorkingDir() + genericNameFromArgs + onelabExtension + ".save"; std::ifstream infile(fileName.c_str()); - if(infile.is_open()){ - while(infile.good()){ + if(infile.is_open()) { + while(infile.good()) { std::string line; - getline(infile,line); + getline(infile, line); size_t pos; - if( (pos=line.find(olkey::separator)) != std::string::npos){ - std::string name, action; - std::vector<std::string> args; - extract(line.substr(0,pos),name,action,args); - std::string host = OLMsg::GetOnelabString(name + "/HostName"); - std::string rhost=(args.size()>=2)?args[1]:""; - bool keep = rhost.compare(host); - if(keep) buffer.push_back(line); + if((pos = line.find(olkey::separator)) != std::string::npos) { + std::string name, action; + std::vector<std::string> args; + extract(line.substr(0, pos), name, action, args); + std::string host = OLMsg::GetOnelabString(name + "/HostName"); + std::string rhost = (args.size() >= 2) ? args[1] : ""; + bool keep = rhost.compare(host); + if(keep) buffer.push_back(line); } } } else - OLMsg::Warning("The file <%s> cannot be opened",fileName.c_str()); + OLMsg::Warning("The file <%s> cannot be opened", fileName.c_str()); infile.close(); - //save client command lines + // save client command lines std::ofstream outfile(fileName.c_str()); - if(outfile.is_open()){ - for(citer it = _clients.begin(); it != _clients.end(); it++){ - outfile << (*it)->toChar(); + if(outfile.is_open()) { + for(citer it = _clients.begin(); it != _clients.end(); it++) { + outfile << (*it)->toChar(); } for(std::vector<std::string>::const_iterator it = buffer.begin(); - it != buffer.end(); it++){ + it != buffer.end(); it++) { outfile << (*it) << std::endl; } } else - OLMsg::Error("The file <%s> cannot be opened",fileName.c_str()); + OLMsg::Error("The file <%s> cannot be opened", fileName.c_str()); outfile.close(); } - int enclosed(const std::string &in, std::vector<std::string> &arguments, - size_t &end){ + size_t &end) +{ // syntax: (arguments[Ø], arguments[1], ... , arguments[n]) // arguments[i] may contain parenthesis size_t pos, cursor; arguments.resize(0); - pos=0; + pos = 0; if(in[pos] != '(') { - OLMsg::Error("Syntax error: <%s>",in.c_str()); + OLMsg::Error("Syntax error: <%s>", in.c_str()); return 0; } pos++; // skips '(' - int count=1; + int count = 1; cursor = pos; - do{ + do { if(in[pos] == '(') count++; else if(in[pos] == ')') count--; else if(in[pos] == ',') { - if(count == 1){ - arguments.push_back(removeBlanks(in.substr(cursor,pos-cursor))); - cursor=pos+1; // skips ',' + if(count == 1) { + arguments.push_back(removeBlanks(in.substr(cursor, pos - cursor))); + cursor = pos + 1; // skips ',' } - else{ - // ignore this comma + else { + // ignore this comma } } pos++; - } while( count && (pos < in.size()) ); + } while(count && (pos < in.size())); // count is 0 when the closing brace has been found. - if(count && pos == in.size()){ - OLMsg::Error("Syntax error: <%s>",in.c_str()); + if(count && pos == in.size()) { + OLMsg::Error("Syntax error: <%s>", in.c_str()); return 0; } else - arguments.push_back(removeBlanks(in.substr(cursor,pos-1-cursor))); - end=pos; + arguments.push_back(removeBlanks(in.substr(cursor, pos - 1 - cursor))); + end = pos; return arguments.size(); } - -int extract(const std::string &in, std::string ¶mName, - std::string &action, std::vector<std::string> &arguments){ +int extract(const std::string &in, std::string ¶mName, std::string &action, + std::vector<std::string> &arguments) +{ // syntax: paramName.action( arg1, arg2, ... ) size_t pos, cursor; - cursor=0; - if ( (pos=in.find(".",cursor)) == std::string::npos ){ - OLMsg::Error("Syntax error: <%s>",in.c_str()); - return 0; + cursor = 0; + if((pos = in.find(".", cursor)) == std::string::npos) { + OLMsg::Error("Syntax error: <%s>", in.c_str()); + return 0; } else - paramName.assign(sanitize(in.substr(cursor,pos-cursor))); - cursor = pos+1; // skips '.' - if ( (pos=in.find("(",cursor)) == std::string::npos ){ - OLMsg::Error("Syntax error: <%s>",in.c_str()); - return 0; + paramName.assign(sanitize(in.substr(cursor, pos - cursor))); + cursor = pos + 1; // skips '.' + if((pos = in.find("(", cursor)) == std::string::npos) { + OLMsg::Error("Syntax error: <%s>", in.c_str()); + return 0; } else - action.assign(sanitize(in.substr(cursor,pos-cursor))); + action.assign(sanitize(in.substr(cursor, pos - cursor))); cursor = pos; - int NumArg = enclosed(in.substr(cursor),arguments,pos); - //std::cout << "FHF=" << in.substr(cursor+pos) << std::endl; - if((in.find_first_not_of(" \t",cursor+pos+1)) != std::string::npos){ + int NumArg = enclosed(in.substr(cursor), arguments, pos); + // std::cout << "FHF=" << in.substr(cursor+pos) << std::endl; + if((in.find_first_not_of(" \t", cursor + pos + 1)) != std::string::npos) { OLMsg::Error("Syntax error in <%s> (forgot a %s ?)", - in.substr(cursor+pos+1).c_str(),olkey::separator.c_str()); + in.substr(cursor + pos + 1).c_str(), olkey::separator.c_str()); return 0; } - if(!NumArg) - OLMsg::Error("Syntax error: <%s>",in.c_str()); + if(!NumArg) OLMsg::Error("Syntax error: <%s>", in.c_str()); return NumArg; } -int extractLogic(const std::string &in, std::vector<std::string> &arguments){ +int extractLogic(const std::string &in, std::vector<std::string> &arguments) +{ // syntax: ( argument[0], argument[1]\in{<,>,<=,>=,==,!=}, arguments[2]) size_t pos, cursor; arguments.resize(0); - cursor=0; - if ( (pos=in.find("(",cursor)) == std::string::npos ){ - OLMsg::Error("Syntax error: <%s>",in.c_str()); - return 0; + cursor = 0; + if((pos = in.find("(", cursor)) == std::string::npos) { + OLMsg::Error("Syntax error: <%s>", in.c_str()); + return 0; } - unsigned int count=1; + unsigned int count = 1; pos++; // skips '(' - cursor=pos; - do{ - if(in[pos]=='(') count++; - if(in[pos]==')') count--; - if( (in[pos]=='<') || (in[pos]=='=') || (in[pos]=='>') || (in[pos]=='!') ){ - arguments.push_back(removeBlanks(in.substr(cursor,pos-cursor))); - if(count!=1) - OLMsg::Error("Syntax error: <%s>",in.c_str()); - cursor=pos; - if(in[pos+1]=='='){ - arguments.push_back(in.substr(cursor,2)); - pos++; + cursor = pos; + do { + if(in[pos] == '(') count++; + if(in[pos] == ')') count--; + if((in[pos] == '<') || (in[pos] == '=') || (in[pos] == '>') || + (in[pos] == '!')) { + arguments.push_back(removeBlanks(in.substr(cursor, pos - cursor))); + if(count != 1) OLMsg::Error("Syntax error: <%s>", in.c_str()); + cursor = pos; + if(in[pos + 1] == '=') { + arguments.push_back(in.substr(cursor, 2)); + pos++; } - else{ - arguments.push_back(in.substr(cursor,1)); + else { + arguments.push_back(in.substr(cursor, 1)); } - cursor=pos+1; + cursor = pos + 1; } pos++; - } while( count && (pos!=std::string::npos) ); + } while(count && (pos != std::string::npos)); // count is 0 when the closing brace is found. if(count) - OLMsg::Error("Syntax error: mismatched parenthesis in <%s>",in.c_str()); + OLMsg::Error("Syntax error: mismatched parenthesis in <%s>", in.c_str()); else - arguments.push_back(removeBlanks(in.substr(cursor,pos-1-cursor))); + arguments.push_back(removeBlanks(in.substr(cursor, pos - 1 - cursor))); - if((arguments.size()!=1) && (arguments.size()!=3)) - OLMsg::Error("Syntax error: <%s>",in.c_str()); + if((arguments.size() != 1) && (arguments.size() != 3)) + OLMsg::Error("Syntax error: <%s>", in.c_str()); return arguments.size(); } -std::string extractExpandPattern(const std::string& str){ +std::string extractExpandPattern(const std::string &str) +{ size_t posa, posb; - posa=str.find_first_of("\"\'<"); - posb=str.find_last_of("\"\'>"); - std::string pattern=str.substr(posa+1,posb-posa-1); - posa=pattern.find("comma"); - if(posa!=std::string::npos) - pattern.replace(posa,5,","); - if(pattern.size()!=3) - OLMsg::Error("Incorrect expand pattern <%s>", - str.c_str()); + posa = str.find_first_of("\"\'<"); + posb = str.find_last_of("\"\'>"); + std::string pattern = str.substr(posa + 1, posb - posa - 1); + posa = pattern.find("comma"); + if(posa != std::string::npos) pattern.replace(posa, 5, ","); + if(pattern.size() != 3) + OLMsg::Error("Incorrect expand pattern <%s>", str.c_str()); return pattern; } -std::string localSolverClient::longName(const std::string name){ +std::string localSolverClient::longName(const std::string name) +{ std::set<std::string, ShortNameLessThan>::iterator it; std::string fullName; if((it = _parameters.find(name)) != _parameters.end()) @@ -273,25 +278,26 @@ std::string localSolverClient::longName(const std::string name){ return fullName; } -std::string localSolverClient::resolveString(const std::string &line) { - //looks for the first OL.get() statement, - //returns a onelab::string value from the server, if any, or "" otherwise - //if no OL.get() statement found, returns line unchanged. +std::string localSolverClient::resolveString(const std::string &line) +{ + // looks for the first OL.get() statement, + // returns a onelab::string value from the server, if any, or "" otherwise + // if no OL.get() statement found, returns line unchanged. std::vector<onelab::string> strings; std::vector<std::string> arguments; - size_t pos,cursor; - - if((pos=line.find(olkey::getValue)) != std::string::npos){ - cursor = pos+olkey::getValue.length(); - int NumArg=enclosed(line.substr(cursor),arguments,pos); - if(NumArg<1){ - OLMsg::Error("Misformed %s statement: <%s>", - olkey::getValue.c_str(),line.c_str()); + size_t pos, cursor; + + if((pos = line.find(olkey::getValue)) != std::string::npos) { + cursor = pos + olkey::getValue.length(); + int NumArg = enclosed(line.substr(cursor), arguments, pos); + if(NumArg < 1) { + OLMsg::Error("Misformed %s statement: <%s>", olkey::getValue.c_str(), + line.c_str()); return "??"; } - std::string paramName=longName(arguments[0]); - get(strings,paramName); - if (strings.size()) + std::string paramName = longName(arguments[0]); + get(strings, paramName); + if(strings.size()) return strings[0].getValue(); else return ""; @@ -299,10 +305,11 @@ std::string localSolverClient::resolveString(const std::string &line) { return line; } -std::string localSolverClient::resolveGetVal(std::string line) { - //looks for OL.get() statements, substitute values from server - //then evaluate the resulting string with mathex. - //OL.get(name +std::string localSolverClient::resolveGetVal(std::string line) +{ + // looks for OL.get() statements, substitute values from server + // then evaluate the resulting string with mathex. + // OL.get(name // {, {choices|range}.{size|comp|expand|index}|attributes.get(args)}) std::vector<onelab::number> numbers; std::vector<onelab::string> strings; @@ -310,182 +317,177 @@ std::string localSolverClient::resolveGetVal(std::string line) { std::string buff; size_t pos, pos0, cursor; - cursor=0; - while ( (pos=line.find(olkey::getValue,cursor)) != std::string::npos){ - pos0=pos; // for further use - cursor = pos+olkey::getValue.length(); - int NumArg=enclosed(line.substr(cursor),arguments,pos); - if(NumArg<1){ - OLMsg::Error("Misformed %s statement: <%s>", - olkey::getValue.c_str(),line.c_str()); + cursor = 0; + while((pos = line.find(olkey::getValue, cursor)) != std::string::npos) { + pos0 = pos; // for further use + cursor = pos + olkey::getValue.length(); + int NumArg = enclosed(line.substr(cursor), arguments, pos); + if(NumArg < 1) { + OLMsg::Error("Misformed %s statement: <%s>", olkey::getValue.c_str(), + line.c_str()); return "??"; } - std::string paramName=longName(arguments[0]); - get(numbers,paramName); - if (numbers.size()){ + std::string paramName = longName(arguments[0]); + get(numbers, paramName); + if(numbers.size()) { std::stringstream Num; - if(NumArg==1){ - Num << numbers[0].getValue(); - buff.assign(Num.str()); + if(NumArg == 1) { + Num << numbers[0].getValue(); + buff.assign(Num.str()); } - else if(NumArg==2){ - std::string name, action; - std::vector<std::string> args; - extract(arguments[1],name,action,args); - if(!name.compare("choices")) { - std::vector<double> choices=numbers[0].getChoices(); - if(!action.compare("size")) { - buff.assign(ftoa(choices.size())); - } - else if(!action.compare("begin")) { - buff.assign(ftoa(*choices.begin())); - } - else if(!action.compare("rbegin")) { - buff.assign(ftoa(*choices.rbegin())); - } - else if(!action.compare("comp")) { - int i=atoi(args[0].c_str()); - if( (i>=0) && (i<(int)choices.size()) ) - Num << choices[i]; - buff.assign(ftoa(choices[i])); - } - else if(!action.compare("expand")) { - std::string pattern; - pattern.assign(extractExpandPattern(args[0])); - // OLMsg::Info("Expand parameter <%s> with pattern <%s>", - // paramName.c_str(),pattern.c_str()); - buff.assign(1,pattern[0]); - for(std::vector<double>::iterator it = choices.begin(); - it != choices.end(); it++){ - if(it != choices.begin()) - buff.append(1,pattern[1]); - buff.append(ftoa(*it)); - } - buff.append(1,pattern[2]); - } - else if(!action.compare("index")) { - Num << numbers[0].getIndex(); - buff.assign(Num.str()); - } - else - OLMsg::Error("Unknown action <%s> in %s statement", - action.c_str(),olkey::getValue.c_str()); - } - else if(!name.compare("range")) { - double stp=numbers[0].getStep(); - double min=numbers[0].getMin(); - double max=numbers[0].getMax(); - - if( (stp == 0) || - (min == -onelab::parameter::maxNumber()) || - (max == onelab::parameter::maxNumber()) ) - OLMsg::Error("Invalid range description for parameter <%s>", - paramName.c_str()); - if(!action.compare("size")) { - buff.assign(ftoa(fabs((max-min)/stp))); - } - else if(!action.compare("comp")) { - int i= atof(args[0].c_str()); - if(stp > 0) - Num << min+i*stp; - else if(stp < 0) - Num << max-i*stp; - } - else if(!action.compare("expand")) { - } - else - OLMsg::Error("Unknown action <%s> in %s statement", - action.c_str(),olkey::getValue.c_str()); - } - else if(!name.compare(0,6,"attrib")) { - if(!action.compare("get")) { - buff.assign(numbers[0].getAttribute(args[0])); - } - } + else if(NumArg == 2) { + std::string name, action; + std::vector<std::string> args; + extract(arguments[1], name, action, args); + if(!name.compare("choices")) { + std::vector<double> choices = numbers[0].getChoices(); + if(!action.compare("size")) { buff.assign(ftoa(choices.size())); } + else if(!action.compare("begin")) { + buff.assign(ftoa(*choices.begin())); + } + else if(!action.compare("rbegin")) { + buff.assign(ftoa(*choices.rbegin())); + } + else if(!action.compare("comp")) { + int i = atoi(args[0].c_str()); + if((i >= 0) && (i < (int)choices.size())) Num << choices[i]; + buff.assign(ftoa(choices[i])); + } + else if(!action.compare("expand")) { + std::string pattern; + pattern.assign(extractExpandPattern(args[0])); + // OLMsg::Info("Expand parameter <%s> with pattern <%s>", + // paramName.c_str(),pattern.c_str()); + buff.assign(1, pattern[0]); + for(std::vector<double>::iterator it = choices.begin(); + it != choices.end(); it++) { + if(it != choices.begin()) buff.append(1, pattern[1]); + buff.append(ftoa(*it)); + } + buff.append(1, pattern[2]); + } + else if(!action.compare("index")) { + Num << numbers[0].getIndex(); + buff.assign(Num.str()); + } + else + OLMsg::Error("Unknown action <%s> in %s statement", action.c_str(), + olkey::getValue.c_str()); + } + else if(!name.compare("range")) { + double stp = numbers[0].getStep(); + double min = numbers[0].getMin(); + double max = numbers[0].getMax(); + + if((stp == 0) || (min == -onelab::parameter::maxNumber()) || + (max == onelab::parameter::maxNumber())) + OLMsg::Error("Invalid range description for parameter <%s>", + paramName.c_str()); + if(!action.compare("size")) { + buff.assign(ftoa(fabs((max - min) / stp))); + } + else if(!action.compare("comp")) { + int i = atof(args[0].c_str()); + if(stp > 0) + Num << min + i * stp; + else if(stp < 0) + Num << max - i * stp; + } + else if(!action.compare("expand")) { + } + else + OLMsg::Error("Unknown action <%s> in %s statement", action.c_str(), + olkey::getValue.c_str()); + } + else if(!name.compare(0, 6, "attrib")) { + if(!action.compare("get")) { + buff.assign(numbers[0].getAttribute(args[0])); + } + } } } - else{ - get(strings,paramName); - if (strings.size()) - buff.assign(strings[0].getValue()); - else{ - OLMsg::Error("resolveGetVal: unknown variable: <%s>",paramName.c_str()); - return "??"; + else { + get(strings, paramName); + if(strings.size()) + buff.assign(strings[0].getValue()); + else { + OLMsg::Error("resolveGetVal: unknown variable: <%s>", + paramName.c_str()); + return "??"; } } - line.replace(pos0,cursor+pos-pos0,buff); - cursor=pos0+buff.length(); + line.replace(pos0, cursor + pos - pos0, buff); + cursor = pos0 + buff.length(); } // Check now wheter the line contains OL.eval's and resolve them - cursor=0; - while ( (pos=line.find(olkey::mathex,cursor)) != std::string::npos){ - size_t pos0=pos; - cursor=pos+olkey::mathex.length(); - if(enclosed(line.substr(cursor),arguments,pos) != 1){ - OLMsg::Error("Misformed %s statement: <%s>", - olkey::mathex.c_str(),line.c_str()); + cursor = 0; + while((pos = line.find(olkey::mathex, cursor)) != std::string::npos) { + size_t pos0 = pos; + cursor = pos + olkey::mathex.length(); + if(enclosed(line.substr(cursor), arguments, pos) != 1) { + OLMsg::Error("Misformed %s statement: <%s>", olkey::mathex.c_str(), + line.c_str()); return "??"; } - //std::cout << "MathEx evaluates now <"<< arguments[0]<< "> " << std::endl; - smlib::mathex* mathExp = new smlib::mathex(); + // std::cout << "MathEx evaluates now <"<< arguments[0]<< "> " << std::endl; + smlib::mathex *mathExp = new smlib::mathex(); mathExp->expression(arguments[0]); - double val=mathExp->eval(); - //std::cout << "MathEx <" << arguments[0] << "> ="<< val << std::endl; - line.replace(pos0,cursor+pos-pos0,ftoa(val)); + double val = mathExp->eval(); + // std::cout << "MathEx <" << arguments[0] << "> ="<< val << std::endl; + line.replace(pos0, cursor + pos - pos0, ftoa(val)); } // Check now wheter the line still contains OL. - if ( (pos=line.find(olkey::label)) != std::string::npos) - OLMsg::Error("Unidentified onelab command in <%s>",line.c_str()); + if((pos = line.find(olkey::label)) != std::string::npos) + OLMsg::Error("Unidentified onelab command in <%s>", line.c_str()); return line; } -bool localSolverClient::resolveLogicExpr(std::vector<std::string> arguments) { +bool localSolverClient::resolveLogicExpr(std::vector<std::string> arguments) +{ std::vector<onelab::number> numbers; double val1, val2; - std::string str1,str2; - bool condition=false; + std::string str1, str2; + bool condition = false; - if(arguments.size()==1){ + if(arguments.size() == 1) { str1.assign(resolveString(arguments[0])); - if(str1.size()) - return true; - val1 = atof( resolveGetVal(arguments[0]).c_str() ); + if(str1.size()) return true; + val1 = atof(resolveGetVal(arguments[0]).c_str()); return (bool)val1; } - else if(arguments.size()==3){ - + else if(arguments.size() == 3) { str1.assign(resolveString(arguments[0])); str2.assign(resolveString(arguments[2])); - if(str1.size() && str2.size()){ - if (!arguments[1].compare("==")) - condition = !str1.compare(str2); - else if (!arguments[1].compare("!=")) - condition = str1.compare(str2); + if(str1.size() && str2.size()) { + if(!arguments[1].compare("==")) + condition = !str1.compare(str2); + else if(!arguments[1].compare("!=")) + condition = str1.compare(str2); else - OLMsg::Error("Unknown logical operator <%s> for strings", - arguments[1].c_str()); + OLMsg::Error("Unknown logical operator <%s> for strings", + arguments[1].c_str()); } - else{ - val1 = atof( resolveGetVal(arguments[0]).c_str() ); - val2 = atof( resolveGetVal(arguments[2]).c_str() ); + else { + val1 = atof(resolveGetVal(arguments[0]).c_str()); + val2 = atof(resolveGetVal(arguments[2]).c_str()); if(!arguments[1].compare("<")) - condition = (val1<val2); - else if (!arguments[1].compare("<=")) - condition = (val1<=val2); - else if (!arguments[1].compare(">")) - condition = (val1>val2); - else if (!arguments[1].compare(">=")) - condition = (val1>=val2); - else if (!arguments[1].compare("==")) - condition = (val1==val2); - else if (!arguments[1].compare("!=")) - condition = (val1!=val2); + condition = (val1 < val2); + else if(!arguments[1].compare("<=")) + condition = (val1 <= val2); + else if(!arguments[1].compare(">")) + condition = (val1 > val2); + else if(!arguments[1].compare(">=")) + condition = (val1 >= val2); + else if(!arguments[1].compare("==")) + condition = (val1 == val2); + else if(!arguments[1].compare("!=")) + condition = (val1 != val2); else - OLMsg::Error("Unknown logical operator <%s>", arguments[1].c_str()); + OLMsg::Error("Unknown logical operator <%s>", arguments[1].c_str()); } } else @@ -493,727 +495,731 @@ bool localSolverClient::resolveLogicExpr(std::vector<std::string> arguments) { return condition; } -bool localSolverClient::resolveRange(const std::string &in, std::vector<double> &arguments){ +bool localSolverClient::resolveRange(const std::string &in, + std::vector<double> &arguments) +{ // syntax: a:b:c or a:b|n with a,b,c numbers and n integer double val; size_t pos, cursor; arguments.resize(0); - cursor=0; - if ( (pos=in.find(":",cursor)) == std::string::npos ){ - OLMsg::Error("Syntax error in range <%s>",in.c_str()); - return 0; + cursor = 0; + if((pos = in.find(":", cursor)) == std::string::npos) { + OLMsg::Error("Syntax error in range <%s>", in.c_str()); + return 0; } - else{ - val=atof(resolveGetVal(in.substr(cursor,pos-cursor)).c_str()); + else { + val = atof(resolveGetVal(in.substr(cursor, pos - cursor)).c_str()); arguments.push_back(val); } - cursor = pos+1; // skips ':' - if ( (pos=in.find(":",cursor)) != std::string::npos ){ - //arguments.push_back(atof(in.substr(cursor,pos-cursor).c_str())); - //arguments.push_back(atof(in.substr(pos+1).c_str())); - val=atof(resolveGetVal(in.substr(cursor,pos-cursor)).c_str()); + cursor = pos + 1; // skips ':' + if((pos = in.find(":", cursor)) != std::string::npos) { + // arguments.push_back(atof(in.substr(cursor,pos-cursor).c_str())); + // arguments.push_back(atof(in.substr(pos+1).c_str())); + val = atof(resolveGetVal(in.substr(cursor, pos - cursor)).c_str()); arguments.push_back(val); - val=atof(resolveGetVal(in.substr(pos+1)).c_str()); + val = atof(resolveGetVal(in.substr(pos + 1)).c_str()); arguments.push_back(val); } - else if ( (pos=in.find("|",cursor)) != std::string::npos ){ + else if((pos = in.find("|", cursor)) != std::string::npos) { // arguments.push_back(atof(in.substr(cursor,pos-cursor).c_str())); // double NumStep = atof(in.substr(pos+1).c_str()); - //arguments.push_back((arguments[1]-arguments[0])/((NumStep==0)?1:NumStep)); - val=atof(resolveGetVal(in.substr(cursor,pos-cursor)).c_str()); + // arguments.push_back((arguments[1]-arguments[0])/((NumStep==0)?1:NumStep)); + val = atof(resolveGetVal(in.substr(cursor, pos - cursor)).c_str()); arguments.push_back(val); - double NumStep = atof(in.substr(pos+1).c_str()); - arguments.push_back((arguments[1]-arguments[0])/((NumStep==0)?1:NumStep)); + double NumStep = atof(in.substr(pos + 1).c_str()); + arguments.push_back((arguments[1] - arguments[0]) / + ((NumStep == 0) ? 1 : NumStep)); } else - OLMsg::Error("Syntax error in range <%s>",in.c_str()); - return (arguments.size()==3); + OLMsg::Error("Syntax error in range <%s>", in.c_str()); + return (arguments.size() == 3); } -void localSolverClient::parse_sentence(std::string line) { - size_t pos,cursor; - std::string name,action,path; +void localSolverClient::parse_sentence(std::string line) +{ + size_t pos, cursor; + std::string name, action, path; std::vector<std::string> arguments; std::vector<onelab::number> numbers; std::vector<onelab::string> strings; cursor = 0; - while ( (pos=line.find(olkey::separator,cursor)) != std::string::npos){ + while((pos = line.find(olkey::separator, cursor)) != std::string::npos) { std::string name, action; - //std::cout << "line=" << line << std::endl; + // std::cout << "line=" << line << std::endl; - extract(line.substr(cursor,pos-cursor),name,action,arguments); + extract(line.substr(cursor, pos - cursor), name, action, arguments); if(!action.compare("number")) { // syntax: paramName.number(val,path,help,range(optional)) - double val=0.0; - if(arguments.size()>1) - name.assign(FixOLPath(arguments[1]) + name); + double val = 0.0; + if(arguments.size() > 1) name.assign(FixOLPath(arguments[1]) + name); _parameters.insert(name); OLMsg::recordFullName(name); get(numbers, name); - if(numbers.empty()){ - numbers.resize(1); - numbers[0].setName(name); - if(arguments[0].empty()){ - numbers[0].setReadOnly(true); - numbers[0].setNeverChanged(true); - } - else - val=atof(resolveGetVal(arguments[0]).c_str()); - numbers[0].setValue(val); + if(numbers.empty()) { + numbers.resize(1); + numbers[0].setName(name); + if(arguments[0].empty()) { + numbers[0].setReadOnly(true); + numbers[0].setNeverChanged(true); + } + else + val = atof(resolveGetVal(arguments[0]).c_str()); + numbers[0].setValue(val); } // else if(arguments[0].empty()) // resets read only parameters // numbers[0].setValue(val); - if(arguments.size()>2) - numbers[0].setLabel(unquote(arguments[2])); - if(arguments.size()>3){ - std::vector<double> bounds; - if (resolveRange(arguments[3],bounds)){ - numbers[0].setMin(bounds[0]); - numbers[0].setMax(bounds[1]); - numbers[0].setStep(bounds[2]); - } + if(arguments.size() > 2) numbers[0].setLabel(unquote(arguments[2])); + if(arguments.size() > 3) { + std::vector<double> bounds; + if(resolveRange(arguments[3], bounds)) { + numbers[0].setMin(bounds[0]); + numbers[0].setMax(bounds[1]); + numbers[0].setStep(bounds[2]); + } } set(numbers[0]); } else if(!action.compare("string")) { // syntax: paramName.string(val,path,help) std::string val = ""; - if(arguments.size()>1) - name.assign(FixOLPath(arguments[1]) + name); // append path + if(arguments.size() > 1) + name.assign(FixOLPath(arguments[1]) + name); // append path _parameters.insert(name); OLMsg::recordFullName(name); get(strings, name); - if(strings.empty()){ - strings.resize(1); - strings[0].setName(name); - if(arguments[0].empty()){ - strings[0].setReadOnly(true); - strings[0].setNeverChanged(true); - } - else - val=resolveGetVal(arguments[0]); - strings[0].setValue(val); + if(strings.empty()) { + strings.resize(1); + strings[0].setName(name); + if(arguments[0].empty()) { + strings[0].setReadOnly(true); + strings[0].setNeverChanged(true); + } + else + val = resolveGetVal(arguments[0]); + strings[0].setValue(val); } // choices list is reset std::vector<std::string> choices; strings[0].setChoices(choices); - if(arguments.size()>2) strings[0].setLabel(unquote(arguments[2])); + if(arguments.size() > 2) strings[0].setLabel(unquote(arguments[2])); set(strings[0]); } else if(!action.compare("radioButton")) { // syntax: paramName.radioButton(val,path,label) - double val=0; + double val = 0; if(arguments[0].empty()) - OLMsg::Error("No value given for param <%s>",name.c_str()); + OLMsg::Error("No value given for param <%s>", name.c_str()); else - val=atof(arguments[0].c_str()); - if(arguments.size()>1) - name.assign(FixOLPath(arguments[1]) + name); + val = atof(arguments[0].c_str()); + if(arguments.size() > 1) name.assign(FixOLPath(arguments[1]) + name); _parameters.insert(name); OLMsg::recordFullName(name); get(numbers, name); - if(numbers.size()){ - val = numbers[0].getValue(); // use value from server + if(numbers.size()) { + val = numbers[0].getValue(); // use value from server } - else{ - numbers.resize(1); - numbers[0].setName(name); - numbers[0].setValue(val); + else { + numbers.resize(1); + numbers[0].setName(name); + numbers[0].setValue(val); } - if(arguments.size()>2) - numbers[0].setLabel(unquote(arguments[2])); + if(arguments.size() > 2) numbers[0].setLabel(unquote(arguments[2])); std::vector<double> choices; choices.push_back(0); choices.push_back(1); numbers[0].setChoices(choices); set(numbers[0]); } - else if(!action.compare("range")){ + else if(!action.compare("range")) { // set the range of an existing number // syntax: paramName.range({a:b:c|a:b#n|min,max,step}) if(arguments[0].empty()) - OLMsg::Error("No argument given for MinMax <%s>",name.c_str()); - else{ - name.assign(longName(name)); - get(numbers,name); - if(numbers.size()){ // parameter must exist - if(arguments.size()==1){ - std::vector<double> bounds; - if (resolveRange(arguments[0],bounds)){ - numbers[0].setMin(bounds[0]); - numbers[0].setMax(bounds[1]); - numbers[0].setStep(bounds[2]); - } - } - else if(arguments.size()==3){ - numbers[0].setMin(atof(arguments[0].c_str())); - numbers[0].setMax(atof(arguments[1].c_str())); - numbers[0].setStep(atof(arguments[2].c_str())); - } - else - OLMsg::Error("Wrong number of arguments for range <%s>", - name.c_str()); - set(numbers[0]); - } - else - OLMsg::Error("The parameter <%s> does not exist",name.c_str()); + OLMsg::Error("No argument given for MinMax <%s>", name.c_str()); + else { + name.assign(longName(name)); + get(numbers, name); + if(numbers.size()) { // parameter must exist + if(arguments.size() == 1) { + std::vector<double> bounds; + if(resolveRange(arguments[0], bounds)) { + numbers[0].setMin(bounds[0]); + numbers[0].setMax(bounds[1]); + numbers[0].setStep(bounds[2]); + } + } + else if(arguments.size() == 3) { + numbers[0].setMin(atof(arguments[0].c_str())); + numbers[0].setMax(atof(arguments[1].c_str())); + numbers[0].setStep(atof(arguments[2].c_str())); + } + else + OLMsg::Error("Wrong number of arguments for range <%s>", + name.c_str()); + set(numbers[0]); + } + else + OLMsg::Error("The parameter <%s> does not exist", name.c_str()); } } - else if(!action.compare("withinRange")){ + else if(!action.compare("withinRange")) { // ensure the value is in the prescribed range name.assign(longName(name)); - get(numbers,name); - if(numbers.size()){ // parameter must exist - if( (numbers[0].getMin() != -onelab::parameter::maxNumber()) && - (numbers[0].getValue() < numbers[0].getMin()) ) - numbers[0].setValue(numbers[0].getMin()); - if( (numbers[0].getMax() != onelab::parameter::maxNumber()) && - (numbers[0].getValue() > numbers[0].getMax()) ) - numbers[0].setValue(numbers[0].getMax()); - set(numbers[0]); + get(numbers, name); + if(numbers.size()) { // parameter must exist + if((numbers[0].getMin() != -onelab::parameter::maxNumber()) && + (numbers[0].getValue() < numbers[0].getMin())) + numbers[0].setValue(numbers[0].getMin()); + if((numbers[0].getMax() != onelab::parameter::maxNumber()) && + (numbers[0].getValue() > numbers[0].getMax())) + numbers[0].setValue(numbers[0].getMax()); + set(numbers[0]); } else - OLMsg::Error("The parameter <%s> does not exist",name.c_str()); + OLMsg::Error("The parameter <%s> does not exist", name.c_str()); } - else if(!action.compare("setValue")){ + else if(!action.compare("setValue")) { // a set request together with a setReadOnly(1) forces // the value on server to be changed. name.assign(longName(name)); - get(numbers,name); - if(numbers.size()){ - if(arguments[0].size()) - numbers[0].setValue(atof(resolveGetVal(arguments[0]).c_str())); - numbers[0].setReadOnly(1); - set(numbers[0]); + get(numbers, name); + if(numbers.size()) { + if(arguments[0].size()) + numbers[0].setValue(atof(resolveGetVal(arguments[0]).c_str())); + numbers[0].setReadOnly(1); + set(numbers[0]); } - else{ - get(strings,name); - if(strings.size()){ - if(arguments[0].empty()) // resets an empty string - strings[0].setValue(""); - else - strings[0].setValue(arguments[0]); - strings[0].setReadOnly(1); - set(strings[0]); - } - else - OLMsg::Error("The parameter <%s> does not exist",name.c_str()); + else { + get(strings, name); + if(strings.size()) { + if(arguments[0].empty()) // resets an empty string + strings[0].setValue(""); + else + strings[0].setValue(arguments[0]); + strings[0].setReadOnly(1); + set(strings[0]); + } + else + OLMsg::Error("The parameter <%s> does not exist", name.c_str()); } } - else if(!action.compare("resetChoices")){ + else if(!action.compare("resetChoices")) { name.assign(longName(name)); - get(numbers,name); - - if(numbers.size()){ // parameter must exist - std::vector<double> choices; - numbers[0].setChoices(choices); - std::map<double, std::string> valuelabels; - numbers[0].setValueLabels(valuelabels); - set(numbers[0]); + get(numbers, name); + + if(numbers.size()) { // parameter must exist + std::vector<double> choices; + numbers[0].setChoices(choices); + std::map<double, std::string> valuelabels; + numbers[0].setValueLabels(valuelabels); + set(numbers[0]); } - else{ - get(strings,name); - if(strings.size()){ - std::vector<std::string> choices; - strings[0].setChoices(choices); - set(strings[0]); - } - else{ - OLMsg::Error("The parameter <%s> does not exist",name.c_str()); - } + else { + get(strings, name); + if(strings.size()) { + std::vector<std::string> choices; + strings[0].setChoices(choices); + set(strings[0]); + } + else { + OLMsg::Error("The parameter <%s> does not exist", name.c_str()); + } } } - else if(!action.compare("addChoices")){ + else if(!action.compare("addChoices")) { name.assign(longName(name)); - get(numbers,name); - if(numbers.size()){ // parameter must exist - std::vector<double> choices=numbers[0].getChoices(); - for(unsigned int i = 0; i < arguments.size(); i++){ - double val=atof(resolveGetVal(arguments[i]).c_str()); - //if(std::find(choices.begin(),choices.end(),val)==choices.end()) - choices.push_back(val); - } - numbers[0].setChoices(choices); - set(numbers[0]); + get(numbers, name); + if(numbers.size()) { // parameter must exist + std::vector<double> choices = numbers[0].getChoices(); + for(unsigned int i = 0; i < arguments.size(); i++) { + double val = atof(resolveGetVal(arguments[i]).c_str()); + // if(std::find(choices.begin(),choices.end(),val)==choices.end()) + choices.push_back(val); + } + numbers[0].setChoices(choices); + set(numbers[0]); } - else{ - get(strings,name); - if(strings.size()){ - std::vector<std::string> choices=strings[0].getChoices(); - for(unsigned int i = 0; i < arguments.size(); i++) - if(std::find(choices.begin(),choices.end(), - arguments[i])==choices.end()) - choices.push_back(arguments[i]); - strings[0].setChoices(choices); - set(strings[0]); - } - else{ - OLMsg::Error("The parameter <%s> does not exist",name.c_str()); - } + else { + get(strings, name); + if(strings.size()) { + std::vector<std::string> choices = strings[0].getChoices(); + for(unsigned int i = 0; i < arguments.size(); i++) + if(std::find(choices.begin(), choices.end(), arguments[i]) == + choices.end()) + choices.push_back(arguments[i]); + strings[0].setChoices(choices); + set(strings[0]); + } + else { + OLMsg::Error("The parameter <%s> does not exist", name.c_str()); + } } } - else if(!action.compare("valueLabels")){ + else if(!action.compare("valueLabels")) { name.assign(longName(name)); - get(numbers,name); - if(numbers.size()){ // parameter must exist - if(arguments.size() % 2){ - OLMsg::Error("Nb of labels does not match nb of choices for <%s>", - name.c_str()); - } - else{ - std::vector<double> choices=numbers[0].getChoices(); - for(unsigned int i = 0; i < arguments.size(); i=i+2){ - double val=atof(resolveGetVal(arguments[i]).c_str()); - if(std::find(choices.begin(),choices.end(),val)==choices.end()) - choices.push_back(val); - numbers[0].setValueLabel(val,unquote(arguments[i+1])); - } - numbers[0].setChoices(choices); - set(numbers[0]); - } + get(numbers, name); + if(numbers.size()) { // parameter must exist + if(arguments.size() % 2) { + OLMsg::Error("Nb of labels does not match nb of choices for <%s>", + name.c_str()); + } + else { + std::vector<double> choices = numbers[0].getChoices(); + for(unsigned int i = 0; i < arguments.size(); i = i + 2) { + double val = atof(resolveGetVal(arguments[i]).c_str()); + if(std::find(choices.begin(), choices.end(), val) == choices.end()) + choices.push_back(val); + numbers[0].setValueLabel(val, unquote(arguments[i + 1])); + } + numbers[0].setChoices(choices); + set(numbers[0]); + } } else - OLMsg::Error("The number <%s> does not exist",name.c_str()); + OLMsg::Error("The number <%s> does not exist", name.c_str()); } - else if(!action.compare("setVisible")){ + else if(!action.compare("setVisible")) { if(arguments[0].empty()) - OLMsg::Error("Missing argument SetVisible <%s>",name.c_str()); - else{ - name.assign(longName(name)); - get(numbers,name); - if(numbers.size()){ - numbers[0].setVisible(atof(resolveGetVal(arguments[0]).c_str())); - set(numbers[0]); - } - else{ - get(strings,name); - if(strings.size()){ - strings[0].setVisible(atof(resolveGetVal(arguments[0]).c_str())); - set(strings[0]); - } - else{ - OLMsg::Error("The parameter <%s> does not exist",name.c_str()); - } - } + OLMsg::Error("Missing argument SetVisible <%s>", name.c_str()); + else { + name.assign(longName(name)); + get(numbers, name); + if(numbers.size()) { + numbers[0].setVisible(atof(resolveGetVal(arguments[0]).c_str())); + set(numbers[0]); + } + else { + get(strings, name); + if(strings.size()) { + strings[0].setVisible(atof(resolveGetVal(arguments[0]).c_str())); + set(strings[0]); + } + else { + OLMsg::Error("The parameter <%s> does not exist", name.c_str()); + } + } } } - else if(!action.compare("setReadOnly")){ + else if(!action.compare("setReadOnly")) { if(arguments[0].empty()) - OLMsg::Error("Missing argument SetReadOnly <%s>",name.c_str()); - else{ - name.assign(longName(name)); - get(numbers,name); - if(numbers.size()){ - numbers[0].setReadOnly(atof(resolveGetVal(arguments[0]).c_str())); - set(numbers[0]); - } - else{ - get(strings,name); - if(strings.size()){ - strings[0].setReadOnly(atof(resolveGetVal(arguments[0]).c_str())); - set(strings[0]); - } - else{ - OLMsg::Error("The parameter <%s> does not exist",name.c_str()); - } - } + OLMsg::Error("Missing argument SetReadOnly <%s>", name.c_str()); + else { + name.assign(longName(name)); + get(numbers, name); + if(numbers.size()) { + numbers[0].setReadOnly(atof(resolveGetVal(arguments[0]).c_str())); + set(numbers[0]); + } + else { + get(strings, name); + if(strings.size()) { + strings[0].setReadOnly(atof(resolveGetVal(arguments[0]).c_str())); + set(strings[0]); + } + else { + OLMsg::Error("The parameter <%s> does not exist", name.c_str()); + } + } } } - else if(!action.compare("layout")){ + else if(!action.compare("layout")) { name.assign(longName(name)); - get(numbers,name); - if(numbers.size()){ - numbers[0].setReadOnly(0); - numbers[0].setAttribute("Highlight","Ivory"); - set(numbers[0]); + get(numbers, name); + if(numbers.size()) { + numbers[0].setReadOnly(0); + numbers[0].setAttribute("Highlight", "Ivory"); + set(numbers[0]); } - else{ - get(strings,name); - if(strings.size()){ - strings[0].setReadOnly(0); - strings[0].setAttribute("Highlight","Ivory"); - set(strings[0]); - } - else{ - OLMsg::Error("The parameter <%s> does not exist",name.c_str()); - } + else { + get(strings, name); + if(strings.size()) { + strings[0].setReadOnly(0); + strings[0].setAttribute("Highlight", "Ivory"); + set(strings[0]); + } + else { + OLMsg::Error("The parameter <%s> does not exist", name.c_str()); + } } } - else if(!action.compare("setAttribute")){ - if(arguments.size() !=2 ) - OLMsg::Error("SetAttribute <%s> needs two arguments %d", - name.c_str(), arguments.size()); - else{ - name.assign(longName(name)); - get(numbers,name); - if(numbers.size()){ - numbers[0].setAttribute(arguments[0].c_str(), - resolveGetVal(arguments[1]).c_str()); - set(numbers[0]); - } - else{ - get(strings,name); - if(strings.size()){ - strings[0].setAttribute(arguments[0].c_str(),arguments[1].c_str()); - set(strings[0]); - } - else{ - OLMsg::Error("The parameter <%s> does not exist",name.c_str()); - } - } + else if(!action.compare("setAttribute")) { + if(arguments.size() != 2) + OLMsg::Error("SetAttribute <%s> needs two arguments %d", name.c_str(), + arguments.size()); + else { + name.assign(longName(name)); + get(numbers, name); + if(numbers.size()) { + numbers[0].setAttribute(arguments[0].c_str(), + resolveGetVal(arguments[1]).c_str()); + set(numbers[0]); + } + else { + get(strings, name); + if(strings.size()) { + strings[0].setAttribute(arguments[0].c_str(), arguments[1].c_str()); + set(strings[0]); + } + else { + OLMsg::Error("The parameter <%s> does not exist", name.c_str()); + } + } } } - else{ - client_sentence(name,action,arguments); + else { + client_sentence(name, action, arguments); } - cursor=pos+1; + cursor = pos + 1; } // check whether - if((line.find_first_not_of(" \t",cursor)) != std::string::npos){ + if((line.find_first_not_of(" \t", cursor)) != std::string::npos) { OLMsg::Error("Syntax error in <%s> (forgot a %s ?)", - line.substr(cursor).c_str(),olkey::separator.c_str()); + line.substr(cursor).c_str(), olkey::separator.c_str()); } } -void localSolverClient::modify_tags(const std::string lab, const std::string com){ - bool changed=false; - if(lab.compare(olkey::label) && lab.size()){ - changed=true; +void localSolverClient::modify_tags(const std::string lab, + const std::string com) +{ + bool changed = false; + if(lab.compare(olkey::label) && lab.size()) { + changed = true; olkey::label.assign(lab); - olkey::line.assign(olkey::label+"line"); - olkey::begin.assign(olkey::label+"block"); - olkey::end.assign(olkey::label+"endblock"); - olkey::include.assign(olkey::label+"include"); - olkey::message.assign(olkey::label+"msg"); - olkey::showParam.assign(olkey::label+"show"); - olkey::showGmsh.assign(olkey::label+"merge"); - olkey::dump.assign(olkey::label+"dump"); - olkey::ifcond.assign(olkey::label+"if"); - olkey::iftrue.assign(olkey::label+"iftrue"); - olkey::ifntrue.assign(olkey::label+"ifntrue"); - olkey::olelse.assign(olkey::label+"else"); - olkey::olendif.assign(olkey::label+"endif"); - olkey::getValue.assign(olkey::label+"get"); - olkey::mathex.assign(olkey::label+"eval"); - } - if(com.compare(olkey::comment) && com.size()){ - changed=true; + olkey::line.assign(olkey::label + "line"); + olkey::begin.assign(olkey::label + "block"); + olkey::end.assign(olkey::label + "endblock"); + olkey::include.assign(olkey::label + "include"); + olkey::message.assign(olkey::label + "msg"); + olkey::showParam.assign(olkey::label + "show"); + olkey::showGmsh.assign(olkey::label + "merge"); + olkey::dump.assign(olkey::label + "dump"); + olkey::ifcond.assign(olkey::label + "if"); + olkey::iftrue.assign(olkey::label + "iftrue"); + olkey::ifntrue.assign(olkey::label + "ifntrue"); + olkey::olelse.assign(olkey::label + "else"); + olkey::olendif.assign(olkey::label + "endif"); + olkey::getValue.assign(olkey::label + "get"); + olkey::mathex.assign(olkey::label + "eval"); + } + if(com.compare(olkey::comment) && com.size()) { + changed = true; olkey::comment.assign(com); } if(changed) - OLMsg::Info("Using now onelab tags <%s,%s>", - olkey::label.c_str(), olkey::comment.c_str()); + OLMsg::Info("Using now onelab tags <%s,%s>", olkey::label.c_str(), + olkey::comment.c_str()); } -void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) { - size_t pos,cursor; +void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) +{ + size_t pos, cursor; std::vector<std::string> arguments; std::vector<onelab::number> numbers; std::vector<onelab::string> strings; - if((pos=line.find_first_not_of(" \t"))==std::string::npos){ + if((pos = line.find_first_not_of(" \t")) == std::string::npos) { // empty line, skip } - else if(!line.compare(pos,olkey::comment.size(),olkey::comment)){ + else if(!line.compare(pos, olkey::comment.size(), olkey::comment)) { // commented out line, skip } - else if ( (pos=line.find(olkey::deflabel)) != std::string::npos){ + else if((pos = line.find(olkey::deflabel)) != std::string::npos) { // onelab.tags(label,comment); // onelab.tags(); -> reset to default - cursor = pos+olkey::deflabel.length(); - int NumArg=enclosed(line.substr(cursor),arguments,pos); - if((NumArg==1) && arguments[0].empty()) - modify_tags("",""); - else if(NumArg==2) - modify_tags(arguments[0],arguments[1]); + cursor = pos + olkey::deflabel.length(); + int NumArg = enclosed(line.substr(cursor), arguments, pos); + if((NumArg == 1) && arguments[0].empty()) + modify_tags("", ""); + else if(NumArg == 2) + modify_tags(arguments[0], arguments[1]); else OLMsg::Error("Misformed <%s> statement", olkey::deflabel.c_str()); } - else if( (pos=line.find(olkey::begin)) != std::string::npos) { + else if((pos = line.find(olkey::begin)) != std::string::npos) { // onelab.block - if (!parse_block(infile)) - OLMsg::Error("Misformed <%s> block <%s>", - olkey::begin.c_str(),olkey::end.c_str()); + if(!parse_block(infile)) + OLMsg::Error("Misformed <%s> block <%s>", olkey::begin.c_str(), + olkey::end.c_str()); } - else if ( (pos=line.find(olkey::iftrue)) != std::string::npos) { + else if((pos = line.find(olkey::iftrue)) != std::string::npos) { // onelab.iftrue - cursor = pos+olkey::iftrue.length(); + cursor = pos + olkey::iftrue.length(); bool condition = false; - if(enclosed(line.substr(cursor),arguments,pos)<1) - OLMsg::Error("Misformed <%s> statement: (%s)", - olkey::iftrue.c_str(),line.c_str()); - else{ - get(strings,longName(arguments[0])); - if (strings.size()) - condition= true; - else{ - get(numbers,longName(arguments[0])); - if (numbers.size()) - condition = (bool) numbers[0].getValue(); - else - OLMsg::Error("Unknown parameter <%s> in <%s> statement", - arguments[0].c_str(),olkey::iftrue.c_str()); + if(enclosed(line.substr(cursor), arguments, pos) < 1) + OLMsg::Error("Misformed <%s> statement: (%s)", olkey::iftrue.c_str(), + line.c_str()); + else { + get(strings, longName(arguments[0])); + if(strings.size()) + condition = true; + else { + get(numbers, longName(arguments[0])); + if(numbers.size()) + condition = (bool)numbers[0].getValue(); + else + OLMsg::Error("Unknown parameter <%s> in <%s> statement", + arguments[0].c_str(), olkey::iftrue.c_str()); } - if (!parse_ifstatement(infile,condition)) - OLMsg::Error("Misformed <%s> statement: <%s>", - olkey::iftrue.c_str(),arguments[0].c_str()); + if(!parse_ifstatement(infile, condition)) + OLMsg::Error("Misformed <%s> statement: <%s>", olkey::iftrue.c_str(), + arguments[0].c_str()); } } - else if ( (pos=line.find(olkey::ifntrue)) != std::string::npos) { + else if((pos = line.find(olkey::ifntrue)) != std::string::npos) { // onelab.ifntrue - cursor = pos+olkey::ifntrue.length(); + cursor = pos + olkey::ifntrue.length(); bool condition = false; - if(enclosed(line.substr(cursor),arguments,pos)<1) - OLMsg::Error("Misformed <%s> statement: (%s)", - olkey::ifntrue.c_str(),line.c_str()); - else{ - get(strings,longName(arguments[0])); - if (strings.size()) - condition= true; - else{ - get(numbers,longName(arguments[0])); - if (numbers.size()) - condition = (bool) numbers[0].getValue(); - else{ - condition=false; - // OLMsg::Warning("Unknown parameter <%s> in <%s> statement", - // arguments[0].c_str(),olkey::ifntrue.c_str()); - } + if(enclosed(line.substr(cursor), arguments, pos) < 1) + OLMsg::Error("Misformed <%s> statement: (%s)", olkey::ifntrue.c_str(), + line.c_str()); + else { + get(strings, longName(arguments[0])); + if(strings.size()) + condition = true; + else { + get(numbers, longName(arguments[0])); + if(numbers.size()) + condition = (bool)numbers[0].getValue(); + else { + condition = false; + // OLMsg::Warning("Unknown parameter <%s> in <%s> statement", + // arguments[0].c_str(),olkey::ifntrue.c_str()); + } } - if (!parse_ifstatement(infile,!condition)) - OLMsg::Error("Misformed <%s> statement: <%s>", - olkey::ifntrue.c_str(),arguments[0].c_str()); + if(!parse_ifstatement(infile, !condition)) + OLMsg::Error("Misformed <%s> statement: <%s>", olkey::ifntrue.c_str(), + arguments[0].c_str()); } } - else if ( (pos=line.find(olkey::ifcond)) != std::string::npos) { + else if((pos = line.find(olkey::ifcond)) != std::string::npos) { // onelab.ifcond - cursor = pos+olkey::ifcond.length(); - extractLogic(line.substr(cursor),arguments); - bool condition= resolveLogicExpr(arguments); - if (!parse_ifstatement(infile,condition)){ - OLMsg::Error("Misformed %s statement: <%s>", - olkey::ifcond.c_str(), line.c_str()); + cursor = pos + olkey::ifcond.length(); + extractLogic(line.substr(cursor), arguments); + bool condition = resolveLogicExpr(arguments); + if(!parse_ifstatement(infile, condition)) { + OLMsg::Error("Misformed %s statement: <%s>", olkey::ifcond.c_str(), + line.c_str()); } } - else if ( (pos=line.find(olkey::include)) != std::string::npos) { + else if((pos = line.find(olkey::include)) != std::string::npos) { // onelab.include - cursor = pos+olkey::include.length(); - if(enclosed(line.substr(cursor),arguments,pos)<1) - OLMsg::Error("Misformed <%s> statement: (%s)", - olkey::include.c_str(),line.c_str()); - else{ + cursor = pos + olkey::include.length(); + if(enclosed(line.substr(cursor), arguments, pos) < 1) + OLMsg::Error("Misformed <%s> statement: (%s)", olkey::include.c_str(), + line.c_str()); + else { std::string filename = getWorkingDir() + resolveGetVal(arguments[0]); OLMsg::Info("Parse file <%s> %s", filename.c_str(), - parse_onefile(filename)?"done":"failed"); + parse_onefile(filename) ? "done" : "failed"); } } - else if ( (pos=line.find(olkey::message)) != std::string::npos) { + else if((pos = line.find(olkey::message)) != std::string::npos) { // onelab.message - cursor = pos+olkey::message.length(); - if(enclosed(line.substr(cursor),arguments,pos)<1) - OLMsg::Error("Misformed <%s> statement: (%s)", - olkey::message.c_str(),line.c_str()); - else{ + cursor = pos + olkey::message.length(); + if(enclosed(line.substr(cursor), arguments, pos) < 1) + OLMsg::Error("Misformed <%s> statement: (%s)", olkey::message.c_str(), + line.c_str()); + else { std::string msg = resolveGetVal(arguments[0]); - OLMsg::Info("%s",msg.c_str()); + OLMsg::Info("%s", msg.c_str()); } } - else if ( (pos=line.find(olkey::showParam)) != std::string::npos) { + else if((pos = line.find(olkey::showParam)) != std::string::npos) { // onelab.showParam - cursor = pos+olkey::showParam.length(); - if(enclosed(line.substr(cursor),arguments,pos)<1) - OLMsg::Error("Misformed <%s> statement: (%s)", - olkey::showParam.c_str(),line.c_str()); - for(unsigned int i = 0; i < arguments.size(); i++){ - std::string lname=longName(arguments[i]); + cursor = pos + olkey::showParam.length(); + if(enclosed(line.substr(cursor), arguments, pos) < 1) + OLMsg::Error("Misformed <%s> statement: (%s)", olkey::showParam.c_str(), + line.c_str()); + for(unsigned int i = 0; i < arguments.size(); i++) { + std::string lname = longName(arguments[i]); std::string msg; - get(numbers,lname); - if (numbers.size()) - msg.assign(numbers[0].toChar()); - else{ - get(strings,lname); - if (strings.size()) - msg.assign(strings[0].toChar()); - else - OLMsg::Error("Unknown parameter <%s> in <%s> statement", - arguments[i].c_str(),olkey::showParam.c_str()); + get(numbers, lname); + if(numbers.size()) + msg.assign(numbers[0].toChar()); + else { + get(strings, lname); + if(strings.size()) + msg.assign(strings[0].toChar()); + else + OLMsg::Error("Unknown parameter <%s> in <%s> statement", + arguments[i].c_str(), olkey::showParam.c_str()); } for(unsigned int j = 0; j < msg.size(); j++) - if(msg[j] == onelab::parameter::charSep()) msg[j] = '|'; - OLMsg::Info("%s",msg.c_str()); + if(msg[j] == onelab::parameter::charSep()) msg[j] = '|'; + OLMsg::Info("%s", msg.c_str()); } } - else if ( (pos=line.find(olkey::showGmsh)) != std::string::npos) { + else if((pos = line.find(olkey::showGmsh)) != std::string::npos) { // onelab.showGmsh - cursor = pos+olkey::showGmsh.length(); - if(enclosed(line.substr(cursor),arguments,pos)<1) - OLMsg::Error("Misformed <%s> statement: (%s)", - olkey::showGmsh.c_str(),line.c_str()); - else{ - std::string fileName=resolveGetVal(arguments[0]); + cursor = pos + olkey::showGmsh.length(); + if(enclosed(line.substr(cursor), arguments, pos) < 1) + OLMsg::Error("Misformed <%s> statement: (%s)", olkey::showGmsh.c_str(), + line.c_str()); + else { + std::string fileName = resolveGetVal(arguments[0]); OLMsg::MergeFile(getWorkingDir() + fileName); } } - else if ( (pos=line.find(olkey::dump)) != std::string::npos) { + else if((pos = line.find(olkey::dump)) != std::string::npos) { // onelab.dump - cursor = pos+olkey::dump.length(); - if(enclosed(line.substr(cursor),arguments,pos)<1){ - OLMsg::Error("Misformed <%s> statement: (%s)", - olkey::dump.c_str(),line.c_str()); + cursor = pos + olkey::dump.length(); + if(enclosed(line.substr(cursor), arguments, pos) < 1) { + OLMsg::Error("Misformed <%s> statement: (%s)", olkey::dump.c_str(), + line.c_str()); } - else{ + else { FILE *fp = fopen(resolveGetVal(arguments[0]).c_str(), "wb"); - if(fp){ + if(fp) { onelab::server::instance()->toFile(fp); fclose(fp); } } } - else if( isOnelabBlock() || - ( !isOnelabBlock() && - ((pos=line.find(olkey::line)) != std::string::npos)) ){ + else if(isOnelabBlock() || + (!isOnelabBlock() && + ((pos = line.find(olkey::line)) != std::string::npos))) { // either any line with no "OL." within a onelabBlock or a line // introduced by a "onelab.line" tag not within a onelabBlock - std::string cmds="",cmd; + std::string cmds = "", cmd; size_t posa, posb; int NbLines = 1; bool err = false, terminated = false; - do{ + do { // skip tag 'olkey::line' if any - if( (pos=line.find(olkey::line)) != std::string::npos) - posa=pos + olkey::line.size(); + if((pos = line.find(olkey::line)) != std::string::npos) + posa = pos + olkey::line.size(); else - posa=0; + posa = 0; // skip trailing comments if any - posb=line.find(olkey::comment); - if(posb==std::string::npos) - cmd.assign(line.substr(posa)); + posb = line.find(olkey::comment); + if(posb == std::string::npos) + cmd.assign(line.substr(posa)); else - cmd.assign(line.substr(posa,posb-posa)); + cmd.assign(line.substr(posa, posb - posa)); cmds.append(cmd); // check whether "cmd" ends with "olkey::separator" - pos=cmd.find_last_of(olkey::separator); + pos = cmd.find_last_of(olkey::separator); terminated = (pos != std::string::npos); - //std::cout << "cmds=<" << cmds << ">" << terminated << std::endl; - - if(!terminated){ - // not found olkey::separator => append the next nonempty line - while(infile.good()){ - getline (infile,line); - NbLines++; // command should not span over more than 20 nonempty lines - if(line.find_first_not_of(" \t") != std::string::npos) - break; - } - - if(infile.good()){ - // check that no OL. commands is found except OL.get or OL.eval - if((pos=line.find(olkey::getValue)) != std::string::npos){ - err = false; - } - else if((pos=line.find(olkey::mathex)) != std::string::npos){ - err = false; - } - else if((pos=line.find(olkey::end)) != std::string::npos){ - err = true; - closeOnelabBlock(); - } - else if((pos=line.find(olkey::label)) != std::string::npos){ - err = true; - } - } + // std::cout << "cmds=<" << cmds << ">" << terminated << std::endl; + + if(!terminated) { + // not found olkey::separator => append the next nonempty line + while(infile.good()) { + getline(infile, line); + NbLines++; // command should not span over more than 20 nonempty lines + if(line.find_first_not_of(" \t") != std::string::npos) break; + } + + if(infile.good()) { + // check that no OL. commands is found except OL.get or OL.eval + if((pos = line.find(olkey::getValue)) != std::string::npos) { + err = false; + } + else if((pos = line.find(olkey::mathex)) != std::string::npos) { + err = false; + } + else if((pos = line.find(olkey::end)) != std::string::npos) { + err = true; + closeOnelabBlock(); + } + else if((pos = line.find(olkey::label)) != std::string::npos) { + err = true; + } + } } - } while (infile.good() && !err && !terminated && NbLines <= 20); + } while(infile.good() && !err && !terminated && NbLines <= 20); - if(!terminated){ + if(!terminated) { if(NbLines >= 20) - OLMsg::Error("Command <%s> should not span over more than 20 lines", - cmds.c_str()); + OLMsg::Error("Command <%s> should not span over more than 20 lines", + cmds.c_str()); else - OLMsg::Error("Unterminated command <%s>", cmds.c_str()); + OLMsg::Error("Unterminated command <%s>", cmds.c_str()); return; } else parse_sentence(cmds); } - else if ( (pos=line.find(olkey::getValue)) != std::string::npos) { + else if((pos = line.find(olkey::getValue)) != std::string::npos) { // onelab.getValue: nothing to do } - else if ( (pos=line.find(olkey::mathex)) != std::string::npos) { + else if((pos = line.find(olkey::mathex)) != std::string::npos) { // onelab.mathex: nothing to do } - else if( (pos=line.find(olkey::label)) != std::string::npos) { - OLMsg::Error("Unknown ONELAB keyword in <%s>",line.c_str()); + else if((pos = line.find(olkey::label)) != std::string::npos) { + OLMsg::Error("Unknown ONELAB keyword in <%s>", line.c_str()); } - else{ + else { // not a onelab line, skip } } -bool localSolverClient::parse_block(std::ifstream &infile) { +bool localSolverClient::parse_block(std::ifstream &infile) +{ size_t pos; std::string line; openOnelabBlock(); - while (infile.good()){ - getline (infile,line); - if ((pos=line.find_first_not_of(" \t")) == std::string::npos) + while(infile.good()) { + getline(infile, line); + if((pos = line.find_first_not_of(" \t")) == std::string::npos) continue; // skip empty line - if ((pos=line.find(olkey::end)) != std::string::npos){ + if((pos = line.find(olkey::end)) != std::string::npos) { closeOnelabBlock(); return true; } - parse_oneline(line,infile); + parse_oneline(line, infile); } return false; } -bool localSolverClient::parse_ifstatement(std::ifstream &infile, - bool condition) { +bool localSolverClient::parse_ifstatement(std::ifstream &infile, bool condition) +{ int level; size_t pos; std::string line; - bool trueclause=true; - level=1; - while ( infile.good() && level) { - getline (infile,line); - if ( ((pos=line.find(olkey::olelse)) != std::string::npos) && (level==1) ) - trueclause=false; - else if ( (pos=line.find(olkey::olendif)) != std::string::npos) + bool trueclause = true; + level = 1; + while(infile.good() && level) { + getline(infile, line); + if(((pos = line.find(olkey::olelse)) != std::string::npos) && (level == 1)) + trueclause = false; + else if((pos = line.find(olkey::olendif)) != std::string::npos) level--; - else if ( !(trueclause ^ condition) ) // xor bitwise operator - parse_oneline(line,infile); + else if(!(trueclause ^ condition)) // xor bitwise operator + parse_oneline(line, infile); else { // check for opening if statements - if ( (pos=line.find(olkey::iftrue)) != std::string::npos) - level++; - else if ( (pos=line.find(olkey::ifntrue)) != std::string::npos) - level++; - else if ( (pos=line.find(olkey::ifcond)) != std::string::npos) - level++; + if((pos = line.find(olkey::iftrue)) != std::string::npos) + level++; + else if((pos = line.find(olkey::ifntrue)) != std::string::npos) + level++; + else if((pos = line.find(olkey::ifcond)) != std::string::npos) + level++; } } - return level?false:true ; + return level ? false : true; } -bool localSolverClient::parse_onefile(std::string fileName, bool mandatory) { +bool localSolverClient::parse_onefile(std::string fileName, bool mandatory) +{ std::ifstream infile(fileName.c_str()); - if (infile.is_open()){ - while (infile.good()){ + if(infile.is_open()) { + while(infile.good()) { std::string line; - getline(infile,line); - parse_oneline(line,infile); + getline(infile, line); + parse_oneline(line, infile); } infile.close(); return true; } - else{ + else { return !mandatory; // if(mandatory) // OLMsg::Error("The file <%s> does not exist",fileName.c_str()); @@ -1222,475 +1228,488 @@ bool localSolverClient::parse_onefile(std::string fileName, bool mandatory) { } } -bool localSolverClient::convert_ifstatement(std::ifstream &infile, std::ofstream &outfile, bool condition) { +bool localSolverClient::convert_ifstatement(std::ifstream &infile, + std::ofstream &outfile, + bool condition) +{ int level; size_t pos; std::string line; - bool trueclause=true; - level=1; - while ( infile.good() && level) { - getline (infile,line); - if ( ((pos=line.find(olkey::olelse)) != std::string::npos) && (level==1) ) - trueclause=false; - else if ( (pos=line.find(olkey::olendif)) != std::string::npos) - level--; - else if ( !(trueclause ^ condition) ) // xor bitwise operator - convert_oneline(line,infile,outfile); + bool trueclause = true; + level = 1; + while(infile.good() && level) { + getline(infile, line); + if(((pos = line.find(olkey::olelse)) != std::string::npos) && (level == 1)) + trueclause = false; + else if((pos = line.find(olkey::olendif)) != std::string::npos) + level--; + else if(!(trueclause ^ condition)) // xor bitwise operator + convert_oneline(line, infile, outfile); else { // check for opening if statements - if ( (pos=line.find(olkey::iftrue)) != std::string::npos) - level++; - else if ( (pos=line.find(olkey::ifntrue)) != std::string::npos) - level++; - else if ( (pos=line.find(olkey::ifcond)) != std::string::npos) - level++; + if((pos = line.find(olkey::iftrue)) != std::string::npos) + level++; + else if((pos = line.find(olkey::ifntrue)) != std::string::npos) + level++; + else if((pos = line.find(olkey::ifcond)) != std::string::npos) + level++; } } - return level?false:true ; + return level ? false : true; } -void localSolverClient::convert_oneline(std::string line, std::ifstream &infile, std::ofstream &outfile) { - size_t pos,cursor; +void localSolverClient::convert_oneline(std::string line, std::ifstream &infile, + std::ofstream &outfile) +{ + size_t pos, cursor; std::vector<std::string> arguments; std::vector<onelab::number> numbers; std::vector<onelab::string> strings; - if((pos=line.find_first_not_of(" \t"))==std::string::npos){ + if((pos = line.find_first_not_of(" \t")) == std::string::npos) { // empty line, we keep them outfile << line << std::endl; } - else if(!line.compare(pos,olkey::comment.size(),olkey::comment)){ + else if(!line.compare(pos, olkey::comment.size(), olkey::comment)) { // commented out, skip the line } - else if ( (pos=line.find(olkey::deflabel)) != std::string::npos){ + else if((pos = line.find(olkey::deflabel)) != std::string::npos) { // onelab.tags(label,comment,separator) - cursor = pos+olkey::deflabel.length(); - int NumArg=enclosed(line.substr(cursor),arguments,pos); - if(NumArg==0) - modify_tags("",""); - else if(NumArg==2) - modify_tags(arguments[0],arguments[1]); + cursor = pos + olkey::deflabel.length(); + int NumArg = enclosed(line.substr(cursor), arguments, pos); + if(NumArg == 0) + modify_tags("", ""); + else if(NumArg == 2) + modify_tags(arguments[0], arguments[1]); else OLMsg::Error("Misformed <%s> statement", olkey::deflabel.c_str()); } - else if( (pos=line.find(olkey::begin)) != std::string::npos) { + else if((pos = line.find(olkey::begin)) != std::string::npos) { // onelab.begin - while (infile.good()){ - getline (infile,line); - if( (pos=line.find(olkey::end)) != std::string::npos) return; + while(infile.good()) { + getline(infile, line); + if((pos = line.find(olkey::end)) != std::string::npos) return; } - OLMsg::Error("Misformed <%s> block <%s>", - olkey::begin.c_str(),olkey::end.c_str()); + OLMsg::Error("Misformed <%s> block <%s>", olkey::begin.c_str(), + olkey::end.c_str()); } - else if ( (pos=line.find(olkey::iftrue)) != std::string::npos) { + else if((pos = line.find(olkey::iftrue)) != std::string::npos) { // onelab.iftrue - cursor = pos+olkey::iftrue.length(); + cursor = pos + olkey::iftrue.length(); bool condition = false; - if(enclosed(line.substr(cursor),arguments,pos)<1) - OLMsg::Error("Misformed <%s> statement: (%s)", - olkey::iftrue.c_str(),line.c_str()); - else{ - get(strings,longName(arguments[0])); - if (strings.size()) - condition = strings[0].getValue().size(); - else{ - get(numbers,longName(arguments[0])); - if (numbers.size()) - condition = (bool) numbers[0].getValue(); - else{ - OLMsg::Warning("Unknown parameter <%s> in <%s> statement", - arguments[0].c_str(),olkey::iftrue.c_str()); - } + if(enclosed(line.substr(cursor), arguments, pos) < 1) + OLMsg::Error("Misformed <%s> statement: (%s)", olkey::iftrue.c_str(), + line.c_str()); + else { + get(strings, longName(arguments[0])); + if(strings.size()) + condition = strings[0].getValue().size(); + else { + get(numbers, longName(arguments[0])); + if(numbers.size()) + condition = (bool)numbers[0].getValue(); + else { + OLMsg::Warning("Unknown parameter <%s> in <%s> statement", + arguments[0].c_str(), olkey::iftrue.c_str()); + } } - if (!convert_ifstatement(infile,outfile,condition)) - OLMsg::Error("Misformed <%s> statement: %s", - olkey::iftrue.c_str(),arguments[0].c_str()); + if(!convert_ifstatement(infile, outfile, condition)) + OLMsg::Error("Misformed <%s> statement: %s", olkey::iftrue.c_str(), + arguments[0].c_str()); } } - else if ( (pos=line.find(olkey::ifntrue)) != std::string::npos) { + else if((pos = line.find(olkey::ifntrue)) != std::string::npos) { // onelab.ifntrue - cursor = pos+olkey::ifntrue.length(); + cursor = pos + olkey::ifntrue.length(); bool condition = false; - if(enclosed(line.substr(cursor),arguments,pos)<1) - OLMsg::Error("Misformed <%s> statement: (%s)", - olkey::ifntrue.c_str(),line.c_str()); - else{ - get(strings,longName(arguments[0])); - if (strings.size()) - condition = strings[0].getValue().size(); - else{ - get(numbers,longName(arguments[0])); - if (numbers.size()) - condition = (bool) numbers[0].getValue(); - else{ - OLMsg::Warning("Unknown parameter <%s> in <%s> statement", - arguments[0].c_str(),olkey::ifntrue.c_str()); - } + if(enclosed(line.substr(cursor), arguments, pos) < 1) + OLMsg::Error("Misformed <%s> statement: (%s)", olkey::ifntrue.c_str(), + line.c_str()); + else { + get(strings, longName(arguments[0])); + if(strings.size()) + condition = strings[0].getValue().size(); + else { + get(numbers, longName(arguments[0])); + if(numbers.size()) + condition = (bool)numbers[0].getValue(); + else { + OLMsg::Warning("Unknown parameter <%s> in <%s> statement", + arguments[0].c_str(), olkey::ifntrue.c_str()); + } } - if (!convert_ifstatement(infile,outfile,!condition)) - OLMsg::Error("Misformed <%s> statement: %s", - olkey::ifntrue.c_str(),arguments[0].c_str()); + if(!convert_ifstatement(infile, outfile, !condition)) + OLMsg::Error("Misformed <%s> statement: %s", olkey::ifntrue.c_str(), + arguments[0].c_str()); } } - else if ( (pos=line.find(olkey::ifcond)) != std::string::npos) { + else if((pos = line.find(olkey::ifcond)) != std::string::npos) { // onelab.ifcond - cursor = pos+olkey::ifcond.length(); - extractLogic(line.substr(cursor),arguments); - bool condition= resolveLogicExpr(arguments); - if (!convert_ifstatement(infile,outfile,condition)) - OLMsg::Error("Misformed %s statement: <%s>", - olkey::ifcond.c_str(),line.c_str()); - } - else if ( (pos=line.find(olkey::include)) != std::string::npos) { + cursor = pos + olkey::ifcond.length(); + extractLogic(line.substr(cursor), arguments); + bool condition = resolveLogicExpr(arguments); + if(!convert_ifstatement(infile, outfile, condition)) + OLMsg::Error("Misformed %s statement: <%s>", olkey::ifcond.c_str(), + line.c_str()); + } + else if((pos = line.find(olkey::include)) != std::string::npos) { // onelab.include - cursor = pos+olkey::include.length(); - if(enclosed(line.substr(cursor),arguments,pos)<1) - OLMsg::Error("Misformed <%s> statement: (%s)", - olkey::include.c_str(),line.c_str()); - else{ + cursor = pos + olkey::include.length(); + if(enclosed(line.substr(cursor), arguments, pos) < 1) + OLMsg::Error("Misformed <%s> statement: (%s)", olkey::include.c_str(), + line.c_str()); + else { std::string filename = getWorkingDir() + resolveGetVal(arguments[0]); convert_onefile(filename, outfile); } } - else if ( (pos=line.find(olkey::message)) != std::string::npos) { + else if((pos = line.find(olkey::message)) != std::string::npos) { // onelab.message - cursor = pos+olkey::message.length(); - if(enclosed(line.substr(cursor),arguments,pos)<1) - OLMsg::Error("Misformed <%s> statement: (%s)", - olkey::message.c_str(),line.c_str()); - else{ + cursor = pos + olkey::message.length(); + if(enclosed(line.substr(cursor), arguments, pos) < 1) + OLMsg::Error("Misformed <%s> statement: (%s)", olkey::message.c_str(), + line.c_str()); + else { std::string msg = resolveGetVal(arguments[0]); - OLMsg::Info("%s",msg.c_str()); + OLMsg::Info("%s", msg.c_str()); } } - else if ( (pos=line.find(olkey::getValue)) != std::string::npos) { + else if((pos = line.find(olkey::getValue)) != std::string::npos) { outfile << resolveGetVal(line) << std::endl; } - else if ( (pos=line.find(olkey::label)) != std::string::npos){ - OLMsg::Error("Unidentified onelab command in <%s>",line.c_str()); + else if((pos = line.find(olkey::label)) != std::string::npos) { + OLMsg::Error("Unidentified onelab command in <%s>", line.c_str()); } - else{ + else { outfile << line << std::endl; } } -void preProcess(const std::string &client, const std::string &fullName){ +void preProcess(const std::string &client, const std::string &fullName) +{ std::vector<std::string> split = SplitOLFileName(fullName); - std::string ifileName = split[1] + split[2] ; // remove heading "_" if any - std::string ofileName = split[0] + split[1] ; // remove trailing ".ol" + std::string ifileName = split[1] + split[2]; // remove heading "_" if any + std::string ofileName = split[0] + split[1]; // remove trailing ".ol" - std::string workDir = SplitFileName(split[1]) [0]; + std::string workDir = SplitFileName(split[1])[0]; localSolverClient *c = new InterfacedClient(client, "", workDir); - std::ifstream infile(ifileName.c_str()); - if( infile.is_open()) { + std::ifstream infile(ifileName.c_str()); + if(infile.is_open()) { std::ofstream outfile(ofileName.c_str()); if(outfile.is_open()) { - OLMsg::Info("Preprocess file <%s> into <%s>",ifileName.c_str(), ofileName.c_str()); - while ( infile.good() ) { - std::string line; - getline (infile,line); - c->convert_oneline(line,infile,outfile); + OLMsg::Info("Preprocess file <%s> into <%s>", ifileName.c_str(), + ofileName.c_str()); + while(infile.good()) { + std::string line; + getline(infile, line); + c->convert_oneline(line, infile, outfile); } outfile.close(); } else - OLMsg::Error("The file <%s> cannot be opened",ofileName.c_str()); + OLMsg::Error("The file <%s> cannot be opened", ofileName.c_str()); infile.close(); } else - OLMsg::Error("The file <%s> cannot be opened",ifileName.c_str()); + OLMsg::Error("The file <%s> cannot be opened", ifileName.c_str()); delete c; } -void localSolverClient::convert_onefile(std::string fileName, std::ofstream &outfile) { +void localSolverClient::convert_onefile(std::string fileName, + std::ofstream &outfile) +{ std::ifstream infile(fileName.c_str()); - if (infile.is_open()){ - OLMsg::Info("Convert file <%s>",fileName.c_str()); - while ( infile.good() ) { + if(infile.is_open()) { + OLMsg::Info("Convert file <%s>", fileName.c_str()); + while(infile.good()) { std::string line; - getline (infile,line); - convert_oneline(line,infile,outfile); + getline(infile, line); + convert_oneline(line, infile, outfile); } infile.close(); } else - OLMsg::Error("The file <%s> cannot be opened",fileName.c_str()); + OLMsg::Error("The file <%s> cannot be opened", fileName.c_str()); } -void localSolverClient::client_sentence(const std::string &name, - const std::string &action, - const std::vector<std::string> &arguments) { - OLMsg::Error("The action <%s> is unknown in this context",action.c_str()); +void localSolverClient::client_sentence( + const std::string &name, const std::string &action, + const std::vector<std::string> &arguments) +{ + OLMsg::Error("The action <%s> is unknown in this context", action.c_str()); } void MetaModel::client_sentence(const std::string &name, - const std::string &action, - const std::vector<std::string> &arguments){ + const std::string &action, + const std::vector<std::string> &arguments) +{ std::vector<onelab::string> strings; - if(!action.compare("register")){ - if(isTodo(REGISTER)){ - std::string type="",cmdl="",host="",rdir=""; + if(!action.compare("register")) { + if(isTodo(REGISTER)) { + std::string type = "", cmdl = "", host = "", rdir = ""; // syntax name.register([interf...|native]{,cmdl}) ; - if(!findClientByName(name)){ - OLMsg::Info("Define client <%s>", name.c_str()); - if(arguments.size()>=1) type.assign(resolveGetVal(arguments[0])); - if(arguments.size()>=2) cmdl.assign(resolveGetVal(arguments[1])); - if(arguments.size()>=3) - OLMsg::Warning("Unused arguments for client <%s>", name.c_str()); - - // if argument 'cmdl' is empty, - // 1. look on server for one remote host cmdl - // defined by a previous .remote() sentence - // 2. look in the .save file for a local host cmdl - // 3. create an empty parameter restore control to the GUI - - host = OLMsg::GetOnelabString(name + "/HostName"); - rdir = OLMsg::GetOnelabString(name + "/RemoteDir"); - if(cmdl.empty()) - cmdl = OLMsg::GetOnelabString(name + "/CommandLine"); - - if(cmdl.empty()) { - host="localhost"; - if(findCommandLine(name,host)) - cmdl = OLMsg::GetOnelabString(name + "/CommandLine"); - } - if(cmdl.empty()) { - if(OLMsg::hasGmsh){ - onelab::string str; - str.setName(name + "/CommandLine"); - str.setKind("file"); - str.setVisible(true); - str.setAttribute("Highlight","Ivory"); - set(str); - OLMsg::Error("No commandline found for client <%s>", - name.c_str()); - } - else{ // asks the user in console mode - std::cout << "\nONELAB: Enter pathname of the executable file for <" << name << ">" << std::endl; - std::getline (std::cin,cmdl); - OLMsg::SetOnelabString(name + "/CommandLine",cmdl); - } - } - registerClient(name,type,cmdl,host,rdir); + if(!findClientByName(name)) { + OLMsg::Info("Define client <%s>", name.c_str()); + if(arguments.size() >= 1) type.assign(resolveGetVal(arguments[0])); + if(arguments.size() >= 2) cmdl.assign(resolveGetVal(arguments[1])); + if(arguments.size() >= 3) + OLMsg::Warning("Unused arguments for client <%s>", name.c_str()); + + // if argument 'cmdl' is empty, + // 1. look on server for one remote host cmdl + // defined by a previous .remote() sentence + // 2. look in the .save file for a local host cmdl + // 3. create an empty parameter restore control to the GUI + + host = OLMsg::GetOnelabString(name + "/HostName"); + rdir = OLMsg::GetOnelabString(name + "/RemoteDir"); + if(cmdl.empty()) cmdl = OLMsg::GetOnelabString(name + "/CommandLine"); + + if(cmdl.empty()) { + host = "localhost"; + if(findCommandLine(name, host)) + cmdl = OLMsg::GetOnelabString(name + "/CommandLine"); + } + if(cmdl.empty()) { + if(OLMsg::hasGmsh) { + onelab::string str; + str.setName(name + "/CommandLine"); + str.setKind("file"); + str.setVisible(true); + str.setAttribute("Highlight", "Ivory"); + set(str); + OLMsg::Error("No commandline found for client <%s>", name.c_str()); + } + else { // asks the user in console mode + std::cout << "\nONELAB: Enter pathname of the executable file for <" + << name << ">" << std::endl; + std::getline(std::cin, cmdl); + OLMsg::SetOnelabString(name + "/CommandLine", cmdl); + } + } + registerClient(name, type, cmdl, host, rdir); } else - OLMsg::Error("Redefinition of client <%s>", name.c_str()); + OLMsg::Error("Redefinition of client <%s>", name.c_str()); } } - else if(!action.compare("remote") || !action.compare("hostname")){ - if(isTodo(REGISTER)){ - std::string host="",rdir=""; - if(arguments.size()>=1) host.assign(resolveGetVal(arguments[0])); - if(arguments.size()>=2) rdir.assign(resolveGetVal(arguments[1])); - if(arguments.size()>=3) - OLMsg::Warning("Unused arguments for client <%s>", name.c_str()); - - if(host.size()){ - OLMsg::SetOnelabString(name + "/HostName", host, false); - if(rdir.size()) - OLMsg::SetOnelabString(name + "/RemoteDir", rdir, false); + else if(!action.compare("remote") || !action.compare("hostname")) { + if(isTodo(REGISTER)) { + std::string host = "", rdir = ""; + if(arguments.size() >= 1) host.assign(resolveGetVal(arguments[0])); + if(arguments.size() >= 2) rdir.assign(resolveGetVal(arguments[1])); + if(arguments.size() >= 3) + OLMsg::Warning("Unused arguments for client <%s>", name.c_str()); + + if(host.size()) { + OLMsg::SetOnelabString(name + "/HostName", host, false); + if(rdir.size()) + OLMsg::SetOnelabString(name + "/RemoteDir", rdir, false); } - else{ - std::string in = OLMsg::GetOnelabString(name + "/HostName"); - if(in.size()){ - std::vector<std::string> split = SplitOLHostName(in); - host = split[0]; - rdir = split[1]; - OLMsg::SetOnelabString(name + "/HostName", host, false); - if(rdir.size()) - OLMsg::SetOnelabString(name + "/RemoteDir", rdir, false); - } - if(!findCommandLine(name,host)){ - if(OLMsg::hasGmsh){ - onelab::string str; - str.setName(name + "/HostName"); - str.setVisible(true); - str.setAttribute("Highlight","Ivory"); - set(str); - OLMsg::Error("No hostname found for remote client <%s>",name.c_str()); - } - else{ // asks the user in console mode - std::cout << "\nONELAB: Enter remote host for <" << name << "> (name@host:dir)" << std::endl; - std::string in; - std::getline (std::cin,in); - if(in.size()){ - std::vector<std::string> split = SplitOLHostName(in); - OLMsg::SetOnelabString(name + "/HostName", split[0], false); - if(split[1].size()) - OLMsg::SetOnelabString(name + "/RemoteDir", split[1], false); - } - } - } + else { + std::string in = OLMsg::GetOnelabString(name + "/HostName"); + if(in.size()) { + std::vector<std::string> split = SplitOLHostName(in); + host = split[0]; + rdir = split[1]; + OLMsg::SetOnelabString(name + "/HostName", host, false); + if(rdir.size()) + OLMsg::SetOnelabString(name + "/RemoteDir", rdir, false); + } + if(!findCommandLine(name, host)) { + if(OLMsg::hasGmsh) { + onelab::string str; + str.setName(name + "/HostName"); + str.setVisible(true); + str.setAttribute("Highlight", "Ivory"); + set(str); + OLMsg::Error("No hostname found for remote client <%s>", + name.c_str()); + } + else { // asks the user in console mode + std::cout << "\nONELAB: Enter remote host for <" << name + << "> (name@host:dir)" << std::endl; + std::string in; + std::getline(std::cin, in); + if(in.size()) { + std::vector<std::string> split = SplitOLHostName(in); + OLMsg::SetOnelabString(name + "/HostName", split[0], false); + if(split[1].size()) + OLMsg::SetOnelabString(name + "/RemoteDir", split[1], false); + } + } + } } } } - else if(!action.compare("workingSubdir")){ + else if(!action.compare("workingSubdir")) { localSolverClient *c; - if((c=findClientByName(name))) + if((c = findClientByName(name))) c->setWorkingDir(c->getWorkingDir() + arguments[0]); else OLMsg::Error("Unknown client <%s>", name.c_str()); } - else if(!action.compare("active")){ + else if(!action.compare("active")) { localSolverClient *c; - if(arguments[0].size()){ - if((c=findClientByName(name))){ - c->setActive(atof( resolveGetVal(arguments[0]).c_str() )); - //onelab::server::instance()->setChanged(true, c->getName()); + if(arguments[0].size()) { + if((c = findClientByName(name))) { + c->setActive(atof(resolveGetVal(arguments[0]).c_str())); + // onelab::server::instance()->setChanged(true, c->getName()); } else - OLMsg::Error("Unknown client <%s>", name.c_str()); + OLMsg::Error("Unknown client <%s>", name.c_str()); } else OLMsg::Error("No argument for <%s.Active> statement", name.c_str()); } - else if(!action.compare("in")){ - if(isTodo(REGISTER)){ + else if(!action.compare("in")) { + if(isTodo(REGISTER)) { get(strings, name + "/InputFiles"); - if(strings.empty()){ - strings.resize(1); - strings[0].setName(name + "/InputFiles"); + if(strings.empty()) { + strings.resize(1); + strings[0].setName(name + "/InputFiles"); } strings[0].setKind("file"); strings[0].setVisible(false); std::vector<std::string> choices; - if(arguments[0].size()){ - for(unsigned int i = 0; i < arguments.size(); i++){ - std::string fileName=resolveGetVal(arguments[i]); - if(std::find(choices.begin(),choices.end(),fileName)==choices.end()) - choices.push_back(fileName); - } - strings[0].setValue(resolveGetVal(arguments[0])); + if(arguments[0].size()) { + for(unsigned int i = 0; i < arguments.size(); i++) { + std::string fileName = resolveGetVal(arguments[i]); + if(std::find(choices.begin(), choices.end(), fileName) == + choices.end()) + choices.push_back(fileName); + } + strings[0].setValue(resolveGetVal(arguments[0])); } strings[0].setChoices(choices); set(strings[0]); } } - else if(!action.compare("out")){ - if(isTodo(REGISTER)){ + else if(!action.compare("out")) { + if(isTodo(REGISTER)) { get(strings, name + "/OutputFiles"); - if(strings.empty()){ - strings.resize(1); - strings[0].setName(name + "/OutputFiles"); + if(strings.empty()) { + strings.resize(1); + strings[0].setName(name + "/OutputFiles"); } strings[0].setKind("file"); strings[0].setVisible(false); std::vector<std::string> choices; - if(arguments[0].size()){ - for(unsigned int i = 0; i < arguments.size(); i++){ - std::string fileName=resolveGetVal(arguments[i]); - if(std::find(choices.begin(),choices.end(),fileName)==choices.end()) - choices.push_back(fileName); - } - strings[0].setValue(resolveGetVal(arguments[0])); + if(arguments[0].size()) { + for(unsigned int i = 0; i < arguments.size(); i++) { + std::string fileName = resolveGetVal(arguments[i]); + if(std::find(choices.begin(), choices.end(), fileName) == + choices.end()) + choices.push_back(fileName); + } + strings[0].setValue(resolveGetVal(arguments[0])); } strings[0].setChoices(choices); set(strings[0]); } } - else if(!action.compare("run")){ - if(isTodo(REGISTER)){ - if(arguments[0].size()){ - get(strings, name + "/Arguments"); - if(strings.empty()){ - strings.resize(1); - strings[0].setName(name + "/Arguments"); - } - strings[0].setValue(resolveGetVal(arguments[0])); - strings[0].setVisible(false); - set(strings[0]); + else if(!action.compare("run")) { + if(isTodo(REGISTER)) { + if(arguments[0].size()) { + get(strings, name + "/Arguments"); + if(strings.empty()) { + strings.resize(1); + strings[0].setName(name + "/Arguments"); + } + strings[0].setValue(resolveGetVal(arguments[0])); + strings[0].setVisible(false); + set(strings[0]); } - if(!OLMsg::GetErrorCount()){ - localSolverClient *c; - if((c=findClientByName(name))) - if(c->checkCommandLine()) - c->analyze(); + if(!OLMsg::GetErrorCount()) { + localSolverClient *c; + if((c = findClientByName(name))) + if(c->checkCommandLine()) c->analyze(); } } - else if(isTodo(ANALYZE)){ + else if(isTodo(ANALYZE)) { localSolverClient *c; - if((c=findClientByName(name))) c->analyze(); + if((c = findClientByName(name))) c->analyze(); } - else if(isTodo(COMPUTE)){ + else if(isTodo(COMPUTE)) { localSolverClient *c; - if((c=findClientByName(name))){ - - //onelab::server::instance()->setChanged(false, getName()); - bool changed = onelab::server::instance()->getChanged(c->getName()); - bool started = isStarted(changed); - - // if(OLMsg::GetVerbosity()) - // std::cout << c->getName() << " active=" - // << c->getActive() << " changed=" - // << changed << " started=" - // << started << " errors=" << OLMsg::GetErrorCount() << std::endl; - if(c->getActive() || started) c->compute(); + if((c = findClientByName(name))) { + // onelab::server::instance()->setChanged(false, getName()); + bool changed = onelab::server::instance()->getChanged(c->getName()); + bool started = isStarted(changed); + + // if(OLMsg::GetVerbosity()) + // std::cout << c->getName() << " active=" + // << c->getActive() << " changed=" + // << changed << " started=" + // << started << " errors=" << OLMsg::GetErrorCount() << std::endl; + if(c->getActive() || started) c->compute(); } } } - else if(!action.compare("up")){ - if(arguments.size()%4==0){ - if(isTodo(REGISTER)){ - } - else if(isTodo(COMPUTE) && !OLMsg::GetErrorCount()){ - std::vector<std::string> choices; - for(unsigned int i = 0; i < arguments.size(); i++){ - std::string str=resolveGetVal(arguments[i]); - OLMsg::recordFullName(str); - choices.push_back(str); - } - localSolverClient *c; - if((c=findClientByName(name))) c->PostArray(choices); + else if(!action.compare("up")) { + if(arguments.size() % 4 == 0) { + if(isTodo(REGISTER)) {} + else if(isTodo(COMPUTE) && !OLMsg::GetErrorCount()) { + std::vector<std::string> choices; + for(unsigned int i = 0; i < arguments.size(); i++) { + std::string str = resolveGetVal(arguments[i]); + OLMsg::recordFullName(str); + choices.push_back(str); + } + localSolverClient *c; + if((c = findClientByName(name))) c->PostArray(choices); } } else - OLMsg::Error("Wrong number of arguments <%d> for <%s>", - arguments.size(), action.c_str()); + OLMsg::Error("Wrong number of arguments <%d> for <%s>", arguments.size(), + action.c_str()); } - else if(!action.compare("alwaysCompute") || !action.compare("preCompute")){ - if(isTodo(REGISTER)){ + else if(!action.compare("alwaysCompute") || !action.compare("preCompute")) { + if(isTodo(REGISTER)) { localSolverClient *c; - if((c=findClientByName(name))){ - c->compute(); - //onelab::server::instance()->setChanged(false, c->getName()); + if((c = findClientByName(name))) { + c->compute(); + // onelab::server::instance()->setChanged(false, c->getName()); } else - OLMsg::Error("Unknown client <%s>", name.c_str()); + OLMsg::Error("Unknown client <%s>", name.c_str()); } } - else if(!action.compare("merge")){ - if( arguments.size() && isTodo(COMPUTE) && !OLMsg::GetErrorCount() && (OLMsg::hasGmsh)){ + else if(!action.compare("merge")) { + if(arguments.size() && isTodo(COMPUTE) && !OLMsg::GetErrorCount() && + (OLMsg::hasGmsh)) { std::vector<std::string> choices; - for(unsigned int i = 0; i < arguments.size(); i++){ - choices.push_back(resolveGetVal(arguments[i])); + for(unsigned int i = 0; i < arguments.size(); i++) { + choices.push_back(resolveGetVal(arguments[i])); } localSolverClient *c; - if((c=findClientByName(name))) { - c->GmshMerge(choices); - OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom",1,false); + if((c = findClientByName(name))) { + c->GmshMerge(choices); + OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom", 1, false); } else - OLMsg::Error("Unknown client <%s>", name.c_str()); + OLMsg::Error("Unknown client <%s>", name.c_str()); } } - else if(!action.compare("frontPage")){ - if( isTodo(REGISTER) && OLMsg::hasGmsh && arguments.size() && !OLMsg::GetErrorCount()){ + else if(!action.compare("frontPage")) { + if(isTodo(REGISTER) && OLMsg::hasGmsh && arguments.size() && + !OLMsg::GetErrorCount()) { std::vector<std::string> choices; - for(unsigned int i = 0; i < arguments.size(); i++){ - choices.push_back(resolveGetVal(arguments[i])); + for(unsigned int i = 0; i < arguments.size(); i++) { + choices.push_back(resolveGetVal(arguments[i])); } localSolverClient *c; - if((c=findClientByName(name))) { - c->GmshMerge(choices); - OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom",1,false); + if((c = findClientByName(name))) { + c->GmshMerge(choices); + OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom", 1, false); } else - OLMsg::Error("Unknown client <%s>", name.c_str()); + OLMsg::Error("Unknown client <%s>", name.c_str()); } } - else if(!action.compare("clientStatus")){ + else if(!action.compare("clientStatus")) { showClientStatus(); } else diff --git a/contrib/onelab/loader.cpp b/contrib/onelab/loader.cpp index f40a51cd8589d12e8f45dbed4c3ab404b77eab43..1b47dcd72b82c02ffb427da97d3d3a6beb8930ae 100644 --- a/contrib/onelab/loader.cpp +++ b/contrib/onelab/loader.cpp @@ -11,35 +11,33 @@ void initializeLoop(const std::string &level) bool changed = false; std::vector<onelab::number> numbers; onelab::server::instance()->get(numbers); - for(unsigned int i = 0; i < numbers.size(); i++){ - - if(numbers[i].getAttribute("Loop") == level){ - if(numbers[i].getChoices().size() > 1){ - numbers[i].setIndex(0); - numbers[i].setValue(numbers[i].getChoices()[0]); - onelab::server::instance()->set(numbers[i]); - changed = true; + for(unsigned int i = 0; i < numbers.size(); i++) { + if(numbers[i].getAttribute("Loop") == level) { + if(numbers[i].getChoices().size() > 1) { + numbers[i].setIndex(0); + numbers[i].setValue(numbers[i].getChoices()[0]); + onelab::server::instance()->set(numbers[i]); + changed = true; } - else if(numbers[i].getStep() > 0){ - if(numbers[i].getMin() != -onelab::parameter::maxNumber()){ - numbers[i].setValue(numbers[i].getMin()); - onelab::server::instance()->set(numbers[i]); - changed = true; - } + else if(numbers[i].getStep() > 0) { + if(numbers[i].getMin() != -onelab::parameter::maxNumber()) { + numbers[i].setValue(numbers[i].getMin()); + onelab::server::instance()->set(numbers[i]); + changed = true; + } } - else if(numbers[i].getStep() < 0){ - if(numbers[i].getMax() != onelab::parameter::maxNumber()){ - numbers[i].setValue(numbers[i].getMax()); - onelab::server::instance()->set(numbers[i]); - changed = true; - } + else if(numbers[i].getStep() < 0) { + if(numbers[i].getMax() != onelab::parameter::maxNumber()) { + numbers[i].setValue(numbers[i].getMax()); + onelab::server::instance()->set(numbers[i]); + changed = true; + } } } } // force this to make sure that we remesh, even if a mesh exists and // we did not actually change a Gmsh parameter - if(changed) - onelab::server::instance()->setChanged(true, "Gmsh"); + if(changed) onelab::server::instance()->setChanged(true, "Gmsh"); } void initializeLoops() { @@ -53,40 +51,40 @@ bool incrementLoop(const std::string &level) bool recompute = false, loop = false; std::vector<onelab::number> numbers; onelab::server::instance()->get(numbers); - for(unsigned int i = 0; i < numbers.size(); i++){ - if(numbers[i].getAttribute("Loop") == level){ + for(unsigned int i = 0; i < numbers.size(); i++) { + if(numbers[i].getAttribute("Loop") == level) { loop = true; - if(numbers[i].getChoices().size() > 1){ - int j = numbers[i].getIndex() + 1; - if((j >= 0) && (j < (int)numbers[i].getChoices().size())){ - numbers[i].setValue(numbers[i].getChoices()[j]); - numbers[i].setIndex(j); - onelab::server::instance()->set(numbers[i]); - OLMsg::Info("Recomputing with %dth choice %s=%g", j, - numbers[i].getName().c_str(), numbers[i].getValue()); - recompute = true; - } + if(numbers[i].getChoices().size() > 1) { + int j = numbers[i].getIndex() + 1; + if((j >= 0) && (j < (int)numbers[i].getChoices().size())) { + numbers[i].setValue(numbers[i].getChoices()[j]); + numbers[i].setIndex(j); + onelab::server::instance()->set(numbers[i]); + OLMsg::Info("Recomputing with %dth choice %s=%g", j, + numbers[i].getName().c_str(), numbers[i].getValue()); + recompute = true; + } } - else if(numbers[i].getStep() > 0){ - if(numbers[i].getMax() != onelab::parameter::maxNumber() && - numbers[i].getValue() < numbers[i].getMax()){ - numbers[i].setValue(numbers[i].getValue() + numbers[i].getStep()); - onelab::server::instance()->set(numbers[i]); - OLMsg::Info("Recomputing with new step %s=%g", - numbers[i].getName().c_str(), numbers[i].getValue()); - recompute = true; - } + else if(numbers[i].getStep() > 0) { + if(numbers[i].getMax() != onelab::parameter::maxNumber() && + numbers[i].getValue() < numbers[i].getMax()) { + numbers[i].setValue(numbers[i].getValue() + numbers[i].getStep()); + onelab::server::instance()->set(numbers[i]); + OLMsg::Info("Recomputing with new step %s=%g", + numbers[i].getName().c_str(), numbers[i].getValue()); + recompute = true; + } } - else if(numbers[i].getStep() < 0){ - if(numbers[i].getMin() != -onelab::parameter::maxNumber() && - numbers[i].getValue() > numbers[i].getMin()){ - numbers[i].setValue(numbers[i].getValue() + numbers[i].getStep()); - onelab::server::instance()->set(numbers[i]); - OLMsg::Info("Recomputing with new step %s=%g", - numbers[i].getName().c_str(), numbers[i].getValue()); - recompute = true; - } + else if(numbers[i].getStep() < 0) { + if(numbers[i].getMin() != -onelab::parameter::maxNumber() && + numbers[i].getValue() > numbers[i].getMin()) { + numbers[i].setValue(numbers[i].getValue() + numbers[i].getStep()); + onelab::server::instance()->set(numbers[i]); + OLMsg::Info("Recomputing with new step %s=%g", + numbers[i].getName().c_str(), numbers[i].getValue()); + recompute = true; + } } } } @@ -100,13 +98,17 @@ bool incrementLoop(const std::string &level) bool incrementLoops() { bool ret = false; - if(incrementLoop("3")) ret = true; - else if(incrementLoop("2")) ret = true; - else if(incrementLoop("1")) ret = true; + if(incrementLoop("3")) + ret = true; + else if(incrementLoop("2")) + ret = true; + else if(incrementLoop("1")) + ret = true; return ret; } -std::string stateToChar(){ +std::string stateToChar() +{ std::vector<onelab::number> numbers; std::ostringstream sstream; onelab::server::instance()->get(numbers); @@ -116,10 +118,11 @@ std::string stateToChar(){ return sstream.str(); } -std::string showParamSpace(){ - std::vector<std::string> parameters=onelab::server::instance()->toChar(); - std::string db = "ONELAB parameter space: size=" - + itoa(onelab::server::instance()->getNumParameters()) + "\n"; +std::string showParamSpace() +{ + std::vector<std::string> parameters = onelab::server::instance()->toChar(); + std::string db = "ONELAB parameter space: size=" + + itoa(onelab::server::instance()->getNumParameters()) + "\n"; for(unsigned int i = 0; i < parameters.size(); i++) db.append(parameters[i] + '\n'); for(unsigned int i = 0; i < db.size(); i++) @@ -127,175 +130,184 @@ std::string showParamSpace(){ return db.c_str(); } -std::string showClientStatus(){ +std::string showClientStatus() +{ std::ostringstream sstream; std::string name; std::cout << "\nONELAB: Present state of the onelab clients" << std::endl; for(onelab::server::citer it = onelab::server::instance()->firstClient(); - it != onelab::server::instance()->lastClient(); it++){ + it != onelab::server::instance()->lastClient(); it++) { name.assign(it->first); sstream << "<" << onelab::server::instance()->getChanged(name) << "> " - << name << std::endl; + << name << std::endl; } return sstream.str(); } - -bool menu() { - int choice, counter1=0, counter2=0; +bool menu() +{ + int choice, counter1 = 0, counter2 = 0; std::vector<onelab::number> numbers; std::vector<onelab::string> strings; do { - std::cout << "\nONELAB: menu" << std::endl ; - std::cout << " 1- View parameter space\n 2- Client status\n 3- Set value\n 4- Analyze\n 5- Compute\n 6- Loop\n 7- Quit metamodel" << std::endl; - choice=0; + std::cout << "\nONELAB: menu" << std::endl; + std::cout << " 1- View parameter space\n 2- Client status\n 3- Set value\n " + "4- Analyze\n 5- Compute\n 6- Loop\n 7- Quit metamodel" + << std::endl; + choice = 0; std::string mystr; - while( (choice<1 || choice>7) && ++counter1<10 ) { + while((choice < 1 || choice > 7) && ++counter1 < 10) { std::cout << "\nONELAB: your choice? "; - std::getline (std::cin, mystr); + std::getline(std::cin, mystr); std::stringstream myStream(mystr); - if (myStream >> choice) break; + if(myStream >> choice) break; std::cout << "Invalid choice" << std::endl; } std::cout << "Your choice is <" << choice << ">" << std::endl; - if (choice==1){ + if(choice == 1) { std::cout << showParamSpace(); - choice=0; + choice = 0; } - if (choice==2){ + if(choice == 2) { std::cout << showClientStatus(); - choice=0; + choice = 0; } - else if (choice==3){ + else if(choice == 3) { std::string name; - std::cout << "ONELAB: Variable name? "; std::cin >> name; - onelab::server::instance()->get(numbers,name); - if (numbers.size()) { - float fval; - std::cout << "ONELAB: Value? "; std::cin >> fval; - numbers[0].setValue(fval); - bool allowed = onelab::server::instance()->set(numbers[0]); + std::cout << "ONELAB: Variable name? "; + std::cin >> name; + onelab::server::instance()->get(numbers, name); + if(numbers.size()) { + float fval; + std::cout << "ONELAB: Value? "; + std::cin >> fval; + numbers[0].setValue(fval); + bool allowed = onelab::server::instance()->set(numbers[0]); } - else{ - onelab::server::instance()->get(strings,name); - if (strings.size()) { - std::string sval; - std::cout << "ONELAB: Value? "; std::cin >> sval; - strings[0].setValue(sval); - onelab::server::instance()->set(strings[0]); - } - else - std::cout << "ONELAB: The variable " << name - << " is not defined" << std::endl; + else { + onelab::server::instance()->get(strings, name); + if(strings.size()) { + std::string sval; + std::cout << "ONELAB: Value? "; + std::cin >> sval; + strings[0].setValue(sval); + onelab::server::instance()->set(strings[0]); + } + else + std::cout << "ONELAB: The variable " << name << " is not defined" + << std::endl; } - choice=0; + choice = 0; } - else if (choice==4){ + else if(choice == 4) { metamodel("check"); - choice=0; + choice = 0; } - else if (choice==5){ + else if(choice == 5) { metamodel("compute"); - choice=0; + choice = 0; } - else if (choice==6){ + else if(choice == 6) { initializeLoops(); - do{ - metamodel("compute"); - }while(incrementLoops()); - choice=0; + do { + metamodel("compute"); + } while(incrementLoops()); + choice = 0; } - else if (choice==7) + else if(choice == 7) exit(1); else - choice=0; - } while(!choice && ++counter2<20); + choice = 0; + } while(!choice && ++counter2 < 20); } -void PrintUsage(const char *name){ +void PrintUsage(const char *name) +{ printf("\nUsage: %s [-a -i -h -v int] modelName\n", name); exit(1); } -int main(int argc, char *argv[]){ - bool launchMenu=false; +int main(int argc, char *argv[]) +{ + bool launchMenu = false; int i = 1; - std::string caseName="", todo="compute", modelName="", workingDir=""; + std::string caseName = "", todo = "compute", modelName = "", workingDir = ""; onelab::remoteNetworkClient *client = 0; while(i < argc) { if(argv[i][0] == '-') { if(!strcmp(argv[i] + 1, "a")) { i++; - todo="check"; + todo = "check"; } else if(!strcmp(argv[i] + 1, "i")) { - i++; - launchMenu=true; + i++; + launchMenu = true; } else if(!strcmp(argv[i] + 1, "lol")) { - //loader used to call non-native clients (type=encapsulated) - std::string clientName=argv[i+1]; - client = new onelab::remoteNetworkClient(clientName,argv[i+2]); - if(client){ - std::string action, cmd; + // loader used to call non-native clients (type=encapsulated) + std::string clientName = argv[i + 1]; + client = new onelab::remoteNetworkClient(clientName, argv[i + 2]); + if(client) { + std::string action, cmd; - std::vector<onelab::string> ps; - client->get(ps,clientName+"/Action"); - if(ps.size() && ps[0].getValue().size()) - action.assign(ps[0].getValue()); + std::vector<onelab::string> ps; + client->get(ps, clientName + "/Action"); + if(ps.size() && ps[0].getValue().size()) + action.assign(ps[0].getValue()); - if(!action.compare("compute")){ - std::vector<onelab::string> ps; - client->get(ps,clientName+"/FullCmdLine"); - if(ps.size() && ps[0].getValue().size()) - cmd.assign(ps[0].getValue()); + if(!action.compare("compute")) { + std::vector<onelab::string> ps; + client->get(ps, clientName + "/FullCmdLine"); + if(ps.size() && ps[0].getValue().size()) + cmd.assign(ps[0].getValue()); - if(cmd.size()){ - OLMsg::Info("Loader calls <%s>",cmd.c_str()); - SystemCall(cmd.c_str(),true); //true->blocking - } - else - OLMsg::Info("No full command line found for <%s>", - clientName.c_str()); - //OLMsg::Info("Stopping client <%s>", clientName.c_str()); - } - delete client; - } - exit(1); + if(cmd.size()) { + OLMsg::Info("Loader calls <%s>", cmd.c_str()); + SystemCall(cmd.c_str(), true); // true->blocking + } + else + OLMsg::Info("No full command line found for <%s>", + clientName.c_str()); + // OLMsg::Info("Stopping client <%s>", clientName.c_str()); + } + delete client; + } + exit(1); } else if(!strcmp(argv[i] + 1, "onelab")) { - //loader used as a test native client - client = new onelab::remoteNetworkClient(argv[i+1],argv[i+2]); - if(!client){ - std::cout << "I have no client\n"; - exit(1); - } - std::vector<onelab::string> strings; - client->get(strings,client->getName()+"/9CheckCommand"); - if(strings.empty()){ // initialize - onelab::string s(client->getName()+"/9CheckCommand","-a"); - client->set(s); - onelab::number o(client->getName()+"/Initialized",1); - client->set(o); - } - else{ - std::cout << "I am initialized: CheckCommand=<" - << strings[0].getValue() << ">" << std::endl; - onelab::number o("alpha",123456); - client->set(o); - client->get(strings,"MESSAGE"); - if(strings.size()){ - std::cout << "I have to tell you: " << strings[0].getValue() << std::endl; - } - std::cout << "Now sleeping for 5s\n"; - SleepInSeconds(5); - std::cout << "Awake again\n"; - } - delete client; - return 0; + // loader used as a test native client + client = new onelab::remoteNetworkClient(argv[i + 1], argv[i + 2]); + if(!client) { + std::cout << "I have no client\n"; + exit(1); + } + std::vector<onelab::string> strings; + client->get(strings, client->getName() + "/9CheckCommand"); + if(strings.empty()) { // initialize + onelab::string s(client->getName() + "/9CheckCommand", "-a"); + client->set(s); + onelab::number o(client->getName() + "/Initialized", 1); + client->set(o); + } + else { + std::cout << "I am initialized: CheckCommand=<" + << strings[0].getValue() << ">" << std::endl; + onelab::number o("alpha", 123456); + client->set(o); + client->get(strings, "MESSAGE"); + if(strings.size()) { + std::cout << "I have to tell you: " << strings[0].getValue() + << std::endl; + } + std::cout << "Now sleeping for 5s\n"; + SleepInSeconds(5); + std::cout << "Awake again\n"; + } + delete client; + return 0; } else if(!strcmp(argv[i] + 1, "v")) { i++; @@ -305,16 +317,15 @@ int main(int argc, char *argv[]){ OLMsg::Fatal("Missing number"); } else { - i++; - PrintUsage(argv[0]); + i++; + PrintUsage(argv[0]); } } else { - caseName=argv[i]; + caseName = argv[i]; modelName.assign(SplitFileName(caseName)[1]); workingDir.assign(SplitFileName(caseName)[0]); - if(workingDir.empty()) - workingDir.assign(getCurrentWorkdir()); + if(workingDir.empty()) workingDir.assign(getCurrentWorkdir()); i++; } } @@ -323,9 +334,9 @@ int main(int argc, char *argv[]){ OLMsg::Fatal("No valid input model name <%s>.", caseName.c_str()); OLMsg::InitializeOnelab("onelab"); - if(argc) OLMsg::SetOnelabString("LoaderPathName",argv[0]); - OLMsg::SetOnelabString("Arguments/FileName",modelName); - OLMsg::SetOnelabString("Arguments/WorkingDir",workingDir); + if(argc) OLMsg::SetOnelabString("LoaderPathName", argv[0]); + OLMsg::SetOnelabString("Arguments/FileName", modelName); + OLMsg::SetOnelabString("Arguments/WorkingDir", workingDir); if(launchMenu) menu(); @@ -334,4 +345,3 @@ int main(int argc, char *argv[]){ OLMsg::FinalizeOnelab(); } - diff --git a/contrib/onelab/metamodel.cpp b/contrib/onelab/metamodel.cpp index b2717d2b39b00a8e06f16d7a38a1e71e8ca8f59a..fa9d52857e46d4cbe3d52a0f1ecf065769679b7b 100644 --- a/contrib/onelab/metamodel.cpp +++ b/contrib/onelab/metamodel.cpp @@ -3,44 +3,51 @@ /* PYTHON functions */ -void modelName(const std::string &name, const std::string &wdir=""){ +void modelName(const std::string &name, const std::string &wdir = "") +{ OLMsg::InitializeOnelab("onelab"); - OLMsg::SetOnelabString("Arguments/FileName",name); - OLMsg::SetOnelabString("Arguments/WorkingDir",wdir); + OLMsg::SetOnelabString("Arguments/FileName", name); + OLMsg::SetOnelabString("Arguments/WorkingDir", wdir); OLMsg::SetVerbosity(0); } -void setNumber(const std::string &name, const double value){ +void setNumber(const std::string &name, const double value) +{ OLMsg::SetOnelabNumber(name, value); } -void setString(const std::string &name, const std::string &value){ +void setString(const std::string &name, const std::string &value) +{ OLMsg::SetOnelabString(name, value); } -double getNumber(const std::string &name){ +double getNumber(const std::string &name) +{ return OLMsg::GetOnelabNumber(name); } -std::string getString(const std::string &name){ +std::string getString(const std::string &name) +{ return OLMsg::GetOnelabString(name); } - /* Interface Gmsh - Metamodels */ -void initializeMetamodel(const std::string &loaderName, onelab::client *olclient, void (*gui_wait_fct)(double time), const int verbosity) +void initializeMetamodel(const std::string &loaderName, + onelab::client *olclient, + void (*gui_wait_fct)(double time), const int verbosity) { - //called by "metamodel_cb" - //copies the Msg::_onelabClient to OLMsg::_onelabClient - //This pointer refers to an object of class localGmsh() (cf GmshMessage.cpp) - //which is a onelab::client with sone Gmsh features (merge and messages). - //Initilizes also the wait function the Gmsh Gui - //so that Gmsh windows may remain active during client computations. + // called by "metamodel_cb" + // copies the Msg::_onelabClient to OLMsg::_onelabClient + // This pointer refers to an object of class localGmsh() (cf GmshMessage.cpp) + // which is a onelab::client with sone Gmsh features (merge and messages). + // Initilizes also the wait function the Gmsh Gui + // so that Gmsh windows may remain active during client computations. OLMsg::SetOnelabClient(olclient); - OLMsg::SetOnelabString("LoaderPathName",loaderName,false); + OLMsg::SetOnelabString("LoaderPathName", loaderName, false); OLMsg::SetGuiWaitFunction(gui_wait_fct); OLMsg::SetVerbosity(verbosity); } -int metamodel(const std::string &action){ +int metamodel(const std::string &action) +{ int errors; OLMsg::Info("Start metamodel"); @@ -54,46 +61,45 @@ int metamodel(const std::string &action){ parseMode todo; if(action == "compute") todo = COMPUTE; - else{ + else { todo = ANALYZE; } - OLMsg::SetOnelabNumber("Metamodel/Action",todo,false); + OLMsg::SetOnelabNumber("Metamodel/Action", todo, false); - MetaModel *myModel = - new MetaModel("meta", workingDir, "meta", modelName); + MetaModel *myModel = new MetaModel("meta", workingDir, "meta", modelName); myModel->setTodo(todo); if(OLMsg::GetErrorCount()) myModel->setTodo(EXIT); - if(OLMsg::GetOnelabNumber("LOGFILES")){ + if(OLMsg::GetOnelabNumber("LOGFILES")) { std::string mystdout = FixWindowsQuotes(workingDir + "stdout.txt"); std::string mystderr = FixWindowsQuotes(workingDir + "stderr.txt"); - OLMsg::Info("Redirecting stdout into <%s>",mystdout.c_str()); - OLMsg::Info("Redirecting stderr into <%s>",mystderr.c_str()); - if(!freopen(mystdout.c_str(),"w",stdout)) return 0; - if(!freopen(mystderr.c_str(),"w",stderr)) return 0; + OLMsg::Info("Redirecting stdout into <%s>", mystdout.c_str()); + OLMsg::Info("Redirecting stderr into <%s>", mystderr.c_str()); + if(!freopen(mystdout.c_str(), "w", stdout)) return 0; + if(!freopen(mystderr.c_str(), "w", stderr)) return 0; } - if( myModel->isTodo(ANALYZE)){ - //myModel->analyze(); the constructor myModel makes the analysis + if(myModel->isTodo(ANALYZE)) { + // myModel->analyze(); the constructor myModel makes the analysis } - else if( myModel->isTodo(COMPUTE)){ + else if(myModel->isTodo(COMPUTE)) { myModel->compute(); } - else if( myModel->isTodo(EXIT)){ + else if(myModel->isTodo(EXIT)) { } else OLMsg::Error("Main: Unknown Action <%d>", todo); delete myModel; - if((errors=OLMsg::GetErrorCount())){ - OLMsg::Error("Leave metamodel - %d errors",errors); + if((errors = OLMsg::GetErrorCount())) { + OLMsg::Error("Leave metamodel - %d errors", errors); OLMsg::Info("===== O N E L A B ====="); return 0; } - int reload=OLMsg::GetOnelabNumber("Gmsh/NeedReloadGeom"); - OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom",0,false); + int reload = OLMsg::GetOnelabNumber("Gmsh/NeedReloadGeom"); + OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom", 0, false); OLMsg::Info("Leave metamodel - need reload=%d", reload); OLMsg::Info("===== O N E L A B ====="); diff --git a/contrib/onelab/metamodel.h b/contrib/onelab/metamodel.h index 5c9ef16700780f9f72bef38e3831c55279cfd689..925d79ec2db5ec271892489fc3d4879275720770 100644 --- a/contrib/onelab/metamodel.h +++ b/contrib/onelab/metamodel.h @@ -8,10 +8,13 @@ #include <string> -namespace onelab{ class client; } +namespace onelab { + class client; +} int metamodel(const std::string &todo); -void initializeMetamodel(const std::string &, onelab::client *, void (*wait)(double time), const int verbosity); +void initializeMetamodel(const std::string &, onelab::client *, + void (*wait)(double time), const int verbosity); /* PYTHON functions */ diff --git a/contrib/onelab/myOS.cpp b/contrib/onelab/myOS.cpp index 0c6c185f824667977930b070dc814890ed48e20f..fe709a568fb448e4d1613c73832c2570f7fe30d1 100644 --- a/contrib/onelab/myOS.cpp +++ b/contrib/onelab/myOS.cpp @@ -29,7 +29,7 @@ #endif #if defined(__APPLE__) -#define RUSAGE_SELF 0 +#define RUSAGE_SELF 0 #define RUSAGE_CHILDREN -1 #endif @@ -82,7 +82,7 @@ static void GetResources(double *s, long *mem) *mem = (long)r.ru_maxrss; #else FILETIME creation, exit, kernel, user; - if(GetProcessTimes(GetCurrentProcess(), &creation, &exit, &kernel, &user)){ + if(GetProcessTimes(GetCurrentProcess(), &creation, &exit, &kernel, &user)) { *s = 1.e-7 * 4294967296. * (double)user.dwHighDateTime + 1.e-7 * (double)user.dwLowDateTime; } @@ -92,7 +92,7 @@ static void GetResources(double *s, long *mem) void CheckResources() { -#if !defined (WIN32) || defined(__CYGWIN__) +#if !defined(WIN32) || defined(__CYGWIN__) static struct rlimit r; getrlimit(RLIMIT_STACK, &r); @@ -100,8 +100,9 @@ void CheckResources() // Try to get at least 16 MB of stack. Running with too small a stack // can cause crashes in the recursive calls (e.g. for tet // classification in 3D Delaunay) - if(r.rlim_cur < 16 * 1024 * 1024){ - OLMsg::Info("Increasing process stack size (%d kB < 16 MB)", r.rlim_cur / 1024); + if(r.rlim_cur < 16 * 1024 * 1024) { + OLMsg::Info("Increasing process stack size (%d kB < 16 MB)", + r.rlim_cur / 1024); r.rlim_cur = r.rlim_max; setrlimit(RLIMIT_STACK, &r); } @@ -163,11 +164,10 @@ int StatFile(const std::string &fileName) int KillProcess(int pid) { #if !defined(WIN32) || defined(__CYGWIN__) - if(kill(pid, 9)) - return 0; + if(kill(pid, 9)) return 0; #else HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, pid); - if(!TerminateProcess(hProc, 0)){ + if(!TerminateProcess(hProc, 0)) { CloseHandle(hProc); return 0; } @@ -183,22 +183,21 @@ int SystemCall(const std::string &command, bool blocking) memset(&suInfo, 0, sizeof(suInfo)); suInfo.cb = sizeof(suInfo); OLMsg::Info("Calling <%s>", command.c_str()); - if(blocking){ - CreateProcess(NULL, (char*)command.c_str(), NULL, NULL, FALSE, - NORMAL_PRIORITY_CLASS, NULL, NULL, - &suInfo, &prInfo); + if(blocking) { + CreateProcess(NULL, (char *)command.c_str(), NULL, NULL, FALSE, + NORMAL_PRIORITY_CLASS, NULL, NULL, &suInfo, &prInfo); // wait until child process exits. WaitForSingleObject(prInfo.hProcess, INFINITE); // close process and thread handles. CloseHandle(prInfo.hProcess); CloseHandle(prInfo.hThread); } - else{ + else { // DETACHED_PROCESS removes the console // (useful if the program to launch is a console-mode exe) - CreateProcess(NULL, (char*)command.c_str(), NULL, NULL, FALSE, - NORMAL_PRIORITY_CLASS|DETACHED_PROCESS, NULL, NULL, - &suInfo, &prInfo); + CreateProcess(NULL, (char *)command.c_str(), NULL, NULL, FALSE, + NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, NULL, &suInfo, + &prInfo); } return 0; #else @@ -217,12 +216,13 @@ int SystemCall(const std::string &command, bool blocking) #define MAXPATHLEN 1024 #endif -std::string getCurrentWorkdir(){ +std::string getCurrentWorkdir() +{ char path[MAXPATHLEN]; if(!getcwd(path, MAXPATHLEN)) return ""; std::string str = path; - //match the convention of SplitFileName that delivers directory path - //endig with a directory separator + // match the convention of SplitFileName that delivers directory path + // endig with a directory separator #if defined(WIN32) str.append("\\"); #else diff --git a/contrib/onelab/myOS.h b/contrib/onelab/myOS.h index 26d49f2fd405bb1d93502aaf79abc6636850d63c..ebffcadf022222871da1fb97c46ce63f33e76fb7 100644 --- a/contrib/onelab/myOS.h +++ b/contrib/onelab/myOS.h @@ -19,7 +19,7 @@ std::string GetHostName(); int UnlinkFile(const std::string &fileName); int StatFile(const std::string &fileName); int KillProcess(int pid); -int SystemCall(const std::string &command, bool blocking=false); +int SystemCall(const std::string &command, bool blocking = false); std::string getCurrentWorkdir(); #endif diff --git a/tutorial/c++/t13.cpp b/tutorial/c++/t13.cpp index da7ee7a7452eaca0dfe6781a497212ca0af784c7..d470c2a9058d9715358427958c5de95279c7be20 100644 --- a/tutorial/c++/t13.cpp +++ b/tutorial/c++/t13.cpp @@ -30,7 +30,6 @@ int main(int argc, char **argv) // along sharp geometrical features. This will create new discrete surfaces, // curves and points. - // Angle between two triangles above which an edge is considered as sharp: double angle = 40; diff --git a/tutorial/c++/t14.cpp b/tutorial/c++/t14.cpp index cffa683626138cf75d47e8776da1e84fe3a52303..5167249d95475f325a3ddace6107952fd00832ce 100644 --- a/tutorial/c++/t14.cpp +++ b/tutorial/c++/t14.cpp @@ -77,8 +77,8 @@ int main(int argc, char **argv) gmsh::model::setPhysicalName(3, domain_physical_tag, "Whole domain"); // Four "terminals" of the model - std::vector<int> terminal_tags = {e[3].second, e[5].second, - e[7].second, e[9].second}; + std::vector<int> terminal_tags = {e[3].second, e[5].second, e[7].second, + e[9].second}; int terminals_physical_tag = 2001; gmsh::model::addPhysicalGroup(2, terminal_tags, terminals_physical_tag); gmsh::model::setPhysicalName(2, terminals_physical_tag, "Terminals"); @@ -88,11 +88,11 @@ int main(int argc, char **argv) gmsh::model::getBoundary({{3, domain_tag}}, boundary_dimtags, false, false); std::vector<int> boundary_tags, complement_tags; - for(auto e: boundary_dimtags) { + for(auto e : boundary_dimtags) { complement_tags.push_back(e.second); boundary_tags.push_back(e.second); } - for(auto t: terminal_tags) { + for(auto t : terminal_tags) { auto it = std::find(complement_tags.begin(), complement_tags.end(), t); if(it != complement_tags.end()) complement_tags.erase(it); } diff --git a/tutorial/c++/t18.cpp b/tutorial/c++/t18.cpp index cc928c093938e937f00a884d4f0ddf8eb9803d6e..53acd3b9ac1360530b7826af36e655ac56c0fc12 100644 --- a/tutorial/c++/t18.cpp +++ b/tutorial/c++/t18.cpp @@ -107,11 +107,11 @@ int main(int argc, char **argv) std::vector<std::pair<int, int> > sxmin; gmsh::model::getEntitiesInBoundingBox(2 - eps, -eps, -eps, 2 + eps, 1 + eps, 1 + eps, sxmin, 2); - for(auto i: sxmin) { + for(auto i : sxmin) { // Then we get the bounding box of each left surface double xmin, ymin, zmin, xmax, ymax, zmax; - gmsh::model::getBoundingBox(i.first, i.second, xmin, ymin, - zmin, xmax, ymax, zmax); + gmsh::model::getBoundingBox(i.first, i.second, xmin, ymin, zmin, xmax, ymax, + zmax); // We translate the bounding box to the right and look for surfaces inside // it: std::vector<std::pair<int, int> > sxmax; @@ -119,18 +119,17 @@ int main(int argc, char **argv) zmin - eps, xmax + eps + 1, ymax + eps, zmax + eps, sxmax, 2); // For all the matches, we compare the corresponding bounding boxes... - for(auto j: sxmax) { + for(auto j : sxmax) { double xmin2, ymin2, zmin2, xmax2, ymax2, zmax2; - gmsh::model::getBoundingBox(j.first, j.second, xmin2, ymin2, - zmin2, xmax2, ymax2, zmax2); + gmsh::model::getBoundingBox(j.first, j.second, xmin2, ymin2, zmin2, xmax2, + ymax2, zmax2); xmin2 -= 1; xmax2 -= 1; // ...and if they match, we apply the periodicity constraint if(std::abs(xmin2 - xmin) < eps && std::abs(xmax2 - xmax) < eps && std::abs(ymin2 - ymin) < eps && std::abs(ymax2 - ymax) < eps && std::abs(zmin2 - zmin) < eps && std::abs(zmax2 - zmax) < eps) { - gmsh::model::mesh::setPeriodic(2, {j.second}, {i.second}, - translation); + gmsh::model::mesh::setPeriodic(2, {j.second}, {i.second}, translation); } } } diff --git a/tutorial/c++/t19.cpp b/tutorial/c++/t19.cpp index 69c5b1a4c52b77261f3af966f3e724c936ed156f..84fa79e194f5ddd5ee0a5ef84a01bdfd0be1b77e 100644 --- a/tutorial/c++/t19.cpp +++ b/tutorial/c++/t19.cpp @@ -51,7 +51,7 @@ int main(int argc, char **argv) std::vector<std::pair<int, int> > e; gmsh::model::getBoundary(f, e, false); std::vector<int> c; - for(auto i: e) c.push_back(abs(i.second)); + for(auto i : e) c.push_back(abs(i.second)); gmsh::model::occ::fillet({out[0].second}, c, {0.1}, out); gmsh::model::occ::synchronize(); diff --git a/tutorial/c++/t20.cpp b/tutorial/c++/t20.cpp index 886a6502dfbf01d948edfa4f063d1f005765c391..1a0b52ce1032ce1afed1ee787498f102779e4269 100644 --- a/tutorial/c++/t20.cpp +++ b/tutorial/c++/t20.cpp @@ -61,10 +61,10 @@ int main(int argc, char **argv) std::vector<std::pair<int, int> > s; s.push_back({2, gmsh::model::occ::addRectangle(xmin, ymin, zmin, L, H)}); if(dir == "X") { - gmsh::model::occ::rotate({s[0]}, xmin, ymin, zmin, 0, 1, 0, -M_PI/2); + gmsh::model::occ::rotate({s[0]}, xmin, ymin, zmin, 0, 1, 0, -M_PI / 2); } else if(dir == "Y") { - gmsh::model::occ::rotate({s[0]}, xmin, ymin, zmin, 1, 0, 0, M_PI/2); + gmsh::model::occ::rotate({s[0]}, xmin, ymin, zmin, 1, 0, 0, M_PI / 2); } double tx = (dir == "X") ? dx / N : 0; double ty = (dir == "Y") ? dy / N : 0; diff --git a/tutorial/c++/t21.cpp b/tutorial/c++/t21.cpp index b7186ca8d630a48b9e69bc75968674b958436d7e..e3d551bab5df7999187e5a200413cca337143062 100644 --- a/tutorial/c++/t21.cpp +++ b/tutorial/c++/t21.cpp @@ -106,7 +106,7 @@ int main(int argc, char **argv) std::vector<std::pair<int, int> > entities; gmsh::model::getEntities(entities); - for(auto e: entities) { + for(auto e : entities) { std::vector<int> partitions; gmsh::model::getPartitions(e.first, e.second, partitions); if(partitions.size()) { @@ -115,7 +115,7 @@ int main(int argc, char **argv) std::cout << "Entity (" << e.first << "," << e.second << ") " << "of type " << type << "\n"; std::cout << " - Partition(s):"; - for(auto p: partitions) std::cout << " " << p; + for(auto p : partitions) std::cout << " " << p; std::cout << "\n"; int pdim, ptag; gmsh::model::getParent(e.first, e.second, pdim, ptag); @@ -123,8 +123,7 @@ int main(int argc, char **argv) std::vector<std::pair<int, int> > bnd; gmsh::model::getBoundary({e}, bnd); std::cout << " - Boundary:"; - for(auto b: bnd) - std::cout << " (" << b.first << "," << b.second << ")"; + for(auto b : bnd) std::cout << " (" << b.first << "," << b.second << ")"; std::cout << "\n"; } } diff --git a/tutorial/c++/t5.cpp b/tutorial/c++/t5.cpp index e9b68bc69096cffacdbb15cd14e64b04de383a5d..4f520a687c958eb200b11bcd70fff3081c08679f 100644 --- a/tutorial/c++/t5.cpp +++ b/tutorial/c++/t5.cpp @@ -203,7 +203,8 @@ int main(int argc, char **argv) // gmsh::option::setNumber("Mesh.MeshOnlyVisible", 1); // Meshing algorithms can changed globally using options: - gmsh::option::setNumber("Mesh.Algorithm", 6); // Frontal-Delaunay for 2D meshes + gmsh::option::setNumber("Mesh.Algorithm", + 6); // Frontal-Delaunay for 2D meshes // They can also be set for individual surfaces, e.g. for using `MeshAdapt' on // surface 1: diff --git a/tutorial/c++/t7.cpp b/tutorial/c++/t7.cpp index 49e278c53e6b7a572707644a6d70d34191f77077..6e2bdcc07d3669de6991375a5b85bc3ea715411d 100644 --- a/tutorial/c++/t7.cpp +++ b/tutorial/c++/t7.cpp @@ -25,10 +25,11 @@ int main(int argc, char **argv) return 0; } - // If the post-processing view was model-based instead of list-based (i.e. if it - // was based on an actual mesh), we would need to create a new model to contain - // the geometry so that meshing it does not destroy the background mesh. It's not - // necessary here since the view is list-based, but it does no harm: + // If the post-processing view was model-based instead of list-based (i.e. if + // it was based on an actual mesh), we would need to create a new model to + // contain the geometry so that meshing it does not destroy the background + // mesh. It's not necessary here since the view is list-based, but it does no + // harm: gmsh::model::add("t7"); // Create a simple rectangular geometry: diff --git a/tutorial/c++/x1.cpp b/tutorial/c++/x1.cpp index 54737e341351bfb706da63b26a2fffeab012a93b..0ea090db0bca742a77cf6ea5ec7e6631f16a6386 100644 --- a/tutorial/c++/x1.cpp +++ b/tutorial/c++/x1.cpp @@ -96,8 +96,7 @@ int main(int argc, char **argv) // * Number of mesh nodes and elements: int numElem = 0; - for(auto &tags : elemTags) - numElem += tags.size(); + for(auto &tags : elemTags) numElem += tags.size(); std::cout << " - Mesh has " << nodeTags.size() << " nodes and " << numElem << " elements\n"; @@ -134,8 +133,7 @@ int main(int argc, char **argv) gmsh::model::getPartitions(dim, tag, partitions); if(partitions.size()) { std::cout << " - Partition tags:"; - for(auto part : partitions) - std::cout << " " << part; + for(auto part : partitions) std::cout << " " << part; int parentDim, parentTag; gmsh::model::getParent(dim, tag, parentDim, parentTag); std::cout << " - parent entity (" << parentDim << "," << parentTag @@ -147,8 +145,8 @@ int main(int argc, char **argv) std::string name; int d, order, numv, numpv; std::vector<double> param; - gmsh::model::mesh::getElementProperties(elemType, name, d, order, - numv, param, numpv); + gmsh::model::mesh::getElementProperties(elemType, name, d, order, numv, + param, numpv); std::cout << " - Element type: " << name << ", order " << order << "\n"; std::cout << " with " << numv << " nodes in param coord: ("; for(auto p : param) std::cout << p << " "; diff --git a/tutorial/c++/x2.cpp b/tutorial/c++/x2.cpp index e83a39cd1492faf5ba364b44bcb166f670f6d1a1..2d67ec461796aa3d87de5e1821723ef3454e04d7 100644 --- a/tutorial/c++/x2.cpp +++ b/tutorial/c++/x2.cpp @@ -150,11 +150,9 @@ int main(int argc, char **argv) int NN = 30; std::vector<std::pair<int, int> > tmp; gmsh::model::getEntities(tmp, 1); - for(auto c: tmp) { - gmsh::model::mesh::setTransfiniteCurve(c.second, NN); - } + for(auto c : tmp) { gmsh::model::mesh::setTransfiniteCurve(c.second, NN); } gmsh::model::getEntities(tmp, 2); - for(auto s: tmp) { + for(auto s : tmp) { gmsh::model::mesh::setTransfiniteSurface(s.second); gmsh::model::mesh::setRecombine(s.first, s.second); gmsh::model::mesh::setSmoothing(s.first, s.second, 100); diff --git a/tutorial/c++/x3.cpp b/tutorial/c++/x3.cpp index 452f5783ebfb1cf9c80abb5460c445249a8af031..6e2ea35b57b87da417a65732f5b77cb89cf924c9 100644 --- a/tutorial/c++/x3.cpp +++ b/tutorial/c++/x3.cpp @@ -36,10 +36,10 @@ int main(int argc, char **argv) // each step if there are several time steps). // Let's create two triangles... - std::vector<double> triangle1 = - {0., 1., 1., // x coordinates of the 3 triangle nodes - 0., 0., 1., // y coordinates of the 3 triangle nodes - 0., 0., 0.}; // z coordinates of the 3 triangle nodes + std::vector<double> triangle1 = { + 0., 1., 1., // x coordinates of the 3 triangle nodes + 0., 0., 1., // y coordinates of the 3 triangle nodes + 0., 0., 0.}; // z coordinates of the 3 triangle nodes std::vector<double> triangle2 = {0., 1., 0., 0., 1., 1., 0., 0., 0.}; // ... and append values for 10 time steps @@ -63,15 +63,13 @@ int main(int argc, char **argv) // difference beeing the type (starting with "V" for vector fields and "T" for // tensor fields) and the number of components. For example a vector field on // a line element can be added as follows: - std::vector<double> line = - {0., 1., // x coordinate of the 2 line nodes - 1.2, 1.2, // y coordinate of the 2 line nodes - 0., 0.}; // z coordinate of the 2 line nodes + std::vector<double> line = {0., 1., // x coordinate of the 2 line nodes + 1.2, 1.2, // y coordinate of the 2 line nodes + 0., 0.}; // z coordinate of the 2 line nodes for(int step = 0; step < 10; step++) { // 3 vector components for each node (2 nodes here), for each step - line.insert(line.end(), {10. + step, 0., 0., - 10. + step, 0., 0.}); + line.insert(line.end(), {10. + step, 0., 0., 10. + step, 0., 0.}); } gmsh::view::addListData(t1, "VL", 1, line); @@ -115,10 +113,10 @@ int main(int argc, char **argv) int t2 = gmsh::view::add("Second order quad"); // Set the node coordinates: - std::vector<double> quad = - {0., 1., 1., 0., // x coordinates of the 4 quadrangle nodes - -1.2, -1.2, -0.2, -0.2, // y coordinates of the 4 quadrangle nodes - 0., 0., 0., 0.}; // z coordinates of the 4 quadrangle nodes + std::vector<double> quad = { + 0., 1., 1., 0., // x coordinates of the 4 quadrangle nodes + -1.2, -1.2, -0.2, -0.2, // y coordinates of the 4 quadrangle nodes + 0., 0., 0., 0.}; // z coordinates of the 4 quadrangle nodes // Add nine values that will be interpolated by second order basis functions quad.insert(quad.end(), {1., 1., 1., 1., 3., 3., 3., 3., -3.}); @@ -127,25 +125,17 @@ int main(int argc, char **argv) // basis functions: f[i](u, v, w) = sum_(j = 0, ..., d - 1) c[i][j] u^e[j][0] // v^e[j][1] w^e[j][2], i = 0, ..., d-1, with u, v, w the coordinates in the // reference element: - gmsh::view::setInterpolationMatrices(t2, "Quadrangle", 9, - {0, 0, 0.25, 0, 0, -0.25, -0.25, 0, 0.25, - 0, 0, 0.25, 0, 0, -0.25, 0.25, 0, -0.25, - 0, 0, 0.25, 0, 0, 0.25, 0.25, 0, 0.25, - 0, 0, 0.25, 0, 0, 0.25, -0.25, 0, -0.25, - 0, 0, -0.5, 0.5, 0, 0.5, 0, -0.5, 0, - 0, 0.5, -0.5, 0, 0.5, 0, -0.5, 0, 0, - 0, 0, -0.5, 0.5, 0, -0.5, 0, 0.5, 0, - 0, 0.5, -0.5, 0, -0.5, 0, 0.5, 0, 0, - 1, -1, 1, -1, 0, 0, 0, 0, 0}, - {0, 0, 0, - 2, 0, 0, - 2, 2, 0, - 0, 2, 0, - 1, 0, 0, - 2, 1, 0, - 1, 2, 0, - 0, 1, 0, - 1, 1, 0}); + gmsh::view::setInterpolationMatrices( + t2, "Quadrangle", 9, + {0, 0, 0.25, 0, 0, -0.25, -0.25, 0, 0.25, 0, 0, 0.25, + 0, 0, -0.25, 0.25, 0, -0.25, 0, 0, 0.25, 0, 0, 0.25, + 0.25, 0, 0.25, 0, 0, 0.25, 0, 0, 0.25, -0.25, 0, -0.25, + 0, 0, -0.5, 0.5, 0, 0.5, 0, -0.5, 0, 0, 0.5, -0.5, + 0, 0.5, 0, -0.5, 0, 0, 0, 0, -0.5, 0.5, 0, -0.5, + 0, 0.5, 0, 0, 0.5, -0.5, 0, -0.5, 0, 0.5, 0, 0, + 1, -1, 1, -1, 0, 0, 0, 0, 0}, + {0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 2, 0, 1, 0, + 0, 2, 1, 0, 1, 2, 0, 0, 1, 0, 1, 1, 0}); // Note that two additional interpolation matrices could also be provided to // interpolate the geometry, i.e. to interpolate curved elements. diff --git a/tutorial/c++/x4.cpp b/tutorial/c++/x4.cpp index 5a28246c058e20d1d51a9eed5ba69c7405b55ba2..da5a23c5cbc7cde19d17c788a62abff305447b49 100644 --- a/tutorial/c++/x4.cpp +++ b/tutorial/c++/x4.cpp @@ -32,10 +32,9 @@ int main(int argc, char **argv) // node-based data: int t1 = gmsh::view::add("A model-based view"); for(int step = 0; step < 10; step++) { - gmsh::view::addHomogeneousModelData - (t1, step, "simple model", "NodeData", - {1, 2, 3, 4}, // tags of nodes - {10., 10., 12. + step, 13. + step}); // data, per node + gmsh::view::addHomogeneousModelData( + t1, step, "simple model", "NodeData", {1, 2, 3, 4}, // tags of nodes + {10., 10., 12. + step, 13. + step}); // data, per node } // Besided node-based data, which result in continuous fields, one can also @@ -44,9 +43,8 @@ int main(int argc, char **argv) int t2 = gmsh::view::add("A discontinuous model-based view"); for(int step = 0; step < 10; step++) { gmsh::view::addHomogeneousModelData( - t2, step, "simple model", "ElementNodeData", - {1, 2}, // tags of elements - {10., 10., 12. + step, 14., 15., 13. + step}); // data per element nodes + t2, step, "simple model", "ElementNodeData", {1, 2}, // tags of elements + {10., 10., 12. + step, 14., 15., 13. + step}); // data per element nodes } // Constant per element datasets can also be created using "ElementData". Note @@ -69,8 +67,8 @@ int main(int argc, char **argv) std::vector<double> val; for(std::size_t i = 0; i < coord.size(); i += 3) val.push_back(step * coord[i]); - gmsh::view::addHomogeneousModelData - (t1, step, "another model", "NodeData", nodes, val); + gmsh::view::addHomogeneousModelData(t1, step, "another model", "NodeData", + nodes, val); } // This feature allows to create seamless animations for time-dependent