From 5907890ea2427e96be5bb61f11f10b892920a1ad Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Fri, 5 Mar 2010 07:17:08 +0000 Subject: [PATCH] better fix for skipping empty steps --- Common/OpenFile.cpp | 37 +++++++++++++++++++++++-------------- Fltk/graphicWindow.cpp | 30 +++++++++++++++--------------- Fltk/graphicWindow.h | 2 +- Post/PViewData.h | 2 +- 4 files changed, 40 insertions(+), 31 deletions(-) diff --git a/Common/OpenFile.cpp b/Common/OpenFile.cpp index 48dadea507..485582410a 100644 --- a/Common/OpenFile.cpp +++ b/Common/OpenFile.cpp @@ -7,6 +7,7 @@ #include <string.h> #include "GmshConfig.h" #include "GmshMessage.h" +#include "Options.h" #include "Geo.h" #include "GModel.h" #include "Numeric.h" @@ -341,20 +342,14 @@ int MergeFile(std::string fileName, bool warnIfMissing) if(!strncmp(header, "$PTS", 4) || !strncmp(header, "$NO", 3) || !strncmp(header, "$PARA", 5) || !strncmp(header, "$ELM", 4) || !strncmp(header, "$MeshFormat", 11) || !strncmp(header, "$Comments", 9)) { - - // MATCHER - if(CTX::instance()->geom.matchGeomAndMesh && !GModel::current()->empty() ) { - GModel* current_mod = GModel::current(); - GModel* tmp_model = new GModel(); - tmp_model->readMSH(fileName); - int match_status = GeomMeshMatcher::instance()->match(current_mod, tmp_model); - - if (match_status) + // mesh matcher + if(CTX::instance()->geom.matchGeomAndMesh && !GModel::current()->empty()){ + GModel* tmp = new GModel(); + tmp->readMSH(fileName); + if(GeomMeshMatcher::instance()->match(GModel::current(), tmp)) fileName = "out.msh"; - delete tmp_model; + delete tmp; } - // MATCHER END - status = GModel::current()->readMSH(fileName); #if defined(HAVE_POST) if(status > 1) status = PView::readMSH(fileName); @@ -383,8 +378,22 @@ int MergeFile(std::string fileName, bool warnIfMissing) CTX::instance()->mesh.changed = ENT_ALL; #if defined(HAVE_FLTK) && defined(HAVE_POST) - if(FlGui::available()) - FlGui::instance()->updateViews(numViewsBefore != (int)PView::list.size()); + if(FlGui::available()){ + bool newViews = numViewsBefore != (int)PView::list.size(); + if(newViews){ + // go directly to the first non-empty step + for(unsigned int i = 0; i < PView::list.size(); i++){ + for(int j = 0; j < (int)opt_view_nb_timestep(i, GMSH_GET, 0); j++){ + int step = (int)opt_view_timestep(i, GMSH_GET, 0); + if(PView::list[i]->getData()->hasTimeStep(step)) + break; + else + opt_view_timestep(i, GMSH_SET | GMSH_GUI, step + 1); + } + } + } + FlGui::instance()->updateViews(newViews); + } #endif if(!status) Msg::Error("Error loading '%s'", fileName.c_str()); diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp index 867ebbae9b..5bd6f70c0b 100644 --- a/Fltk/graphicWindow.cpp +++ b/Fltk/graphicWindow.cpp @@ -220,7 +220,7 @@ void status_options_cb(Fl_Widget *w, void *data) static int stop_anim = 0, view_in_cycle = -1; -void status_play_manual(int time, int step) +void status_play_manual(int time, int incr) { // avoid firing this routine recursively (can happen e.g when // keeping the finger down on the arrow key: if the system generates @@ -232,32 +232,32 @@ void status_play_manual(int time, int step) if(time) { for(unsigned int i = 0; i < PView::list.size(); i++){ if(opt_view_visible(i, GMSH_GET, 0)){ - // skip any empty steps (useful when merging only some steps) - int newStep = (int)opt_view_timestep(i, GMSH_GET, 0) + step; - int totalSteps = (int)opt_view_nb_timestep(i, GMSH_GET, 0); - for(int j = 0; j < totalSteps; j++){ - if(PView::list[i]->getData()->hasTimeStep(newStep)) + // 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++){ + if(PView::list[i]->getData()->hasTimeStep(step)) break; else - newStep += step; - if(newStep < 0) newStep = totalSteps - 1; - if(newStep > totalSteps - 1) newStep = 0; + step += incr; + if(step < 0) step = numSteps - 1; + if(step > numSteps - 1) step = 0; } - opt_view_timestep(i, GMSH_SET | GMSH_GUI, newStep); + opt_view_timestep(i, GMSH_SET | GMSH_GUI, step); } } } else { // hide all views except view_in_cycle - if(step > 0) { - if((view_in_cycle += step) >= (int)PView::list.size()) + if(incr > 0) { + if((view_in_cycle += incr) >= (int)PView::list.size()) view_in_cycle = 0; - for(int i = 0; i < (int)PView::list.size(); i += step) + for(int i = 0; i < (int)PView::list.size(); i += incr) opt_view_visible(i, GMSH_SET | GMSH_GUI, (i == view_in_cycle)); } else { - if((view_in_cycle += step) < 0) + if((view_in_cycle += incr) < 0) view_in_cycle = PView::list.size() - 1; - for(int i = PView::list.size() - 1; i >= 0; i += step) + for(int i = PView::list.size() - 1; i >= 0; i += incr) opt_view_visible(i, GMSH_SET | GMSH_GUI, (i == view_in_cycle)); } } diff --git a/Fltk/graphicWindow.h b/Fltk/graphicWindow.h index 9661e24732..5e2b536069 100644 --- a/Fltk/graphicWindow.h +++ b/Fltk/graphicWindow.h @@ -36,6 +36,6 @@ class graphicWindow{ void status_xyz1p_cb(Fl_Widget *w, void *data); void status_options_cb(Fl_Widget *w, void *data); -void status_play_manual(int time, int step); +void status_play_manual(int time, int incr); #endif diff --git a/Post/PViewData.h b/Post/PViewData.h index d2a8987c36..e1bc38187a 100644 --- a/Post/PViewData.h +++ b/Post/PViewData.h @@ -163,7 +163,7 @@ class PViewData { bool checkVisibility=false){ return false; } // check if the data has the given step/partition/etc. - virtual bool hasTimeStep(int step){ return step < getNumTimeSteps(); } + virtual bool hasTimeStep(int step){ return step >= 0 && step < getNumTimeSteps(); } virtual bool hasPartition(int part){ return false; } virtual bool hasMultipleMeshes(){ return false; } virtual bool hasModel(GModel *model, int step=-1){ return false; } -- GitLab