guicommon/RunDialogMachineListener.hpp

Go to the documentation of this file.
00001 /*
00002   This file is part of OpenFLUID software
00003   Copyright (c) 2007-2010 INRA-Montpellier SupAgro
00004 
00005 
00006  == GNU General Public License Usage ==
00007 
00008   OpenFLUID is free software: you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation, either version 3 of the License, or
00011   (at your option) any later version.
00012 
00013   OpenFLUID is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017 
00018   You should have received a copy of the GNU General Public License
00019   along with OpenFLUID.  If not, see <http://www.gnu.org/licenses/>.
00020 
00021   In addition, as a special exception, INRA gives You the additional right
00022   to dynamically link the code of OpenFLUID with code not covered
00023   under the GNU General Public License ("Non-GPL Code") and to distribute
00024   linked combinations including the two, subject to the limitations in this
00025   paragraph. Non-GPL Code permitted under this exception must only link to
00026   the code of OpenFLUID dynamically through the OpenFLUID libraries
00027   interfaces, and only for building OpenFLUID plugins. The files of
00028   Non-GPL Code may be link to the OpenFLUID libraries without causing the
00029   resulting work to be covered by the GNU General Public License. You must
00030   obey the GNU General Public License in all respects for all of the
00031   OpenFLUID code and other code used in conjunction with OpenFLUID
00032   except the Non-GPL Code covered by this exception. If you modify
00033   this OpenFLUID, you may extend this exception to your version of the file,
00034   but you are not obligated to do so. If you do not wish to provide this
00035   exception without modification, you must delete this exception statement
00036   from your version and license this OpenFLUID solely under the GPL without
00037   exception.
00038 
00039 
00040  == Other Usage ==
00041 
00042   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00043   license, and requires a written agreement between You and INRA.
00044   Licensees for Other Usage of OpenFLUID may use this file in accordance
00045   with the terms contained in the written agreement between You and INRA.
00046 */
00047 
00056 #ifndef __RUNDIALOGMACHINELISTENER_HPP__
00057 #define __RUNDIALOGMACHINELISTENER_HPP__
00058 
00059 
00060 #include <openfluid/machine/MachineListener.hpp>
00061 #include <gtkmm.h>
00062 #include <glibmm/i18n.h>
00063 
00064 #include <openfluid/dllexport.hpp>
00065 #include <openfluid/guicommon/RunStatusWidget.hpp>
00066 
00067 
00068 namespace openfluid { namespace guicommon {
00069 
00070 // =====================================================================
00071 // =====================================================================
00072 
00073 
00074 class DLLEXPORT RunDialogMachineListener : public openfluid::machine::MachineListener
00075 {
00076   private:
00077     unsigned int m_CurrentStep;
00078     std::string m_CurrentStepStr;
00079     unsigned int m_CurrentFunction;
00080 
00081     unsigned int m_TotalSteps;
00082     unsigned int m_TotalFunctions;
00083 
00084     RunStatusWidget* mp_RunStatusWidget;
00085 
00086     Gtk::TextView* mp_DetailsTextView;
00087     Glib::RefPtr<Gtk::TextBuffer> m_RefDetailsTextBuffer;
00088 
00089     unsigned int m_CurrentPreSim;
00090     unsigned int m_CurrentInit;
00091     unsigned int m_CurrentFinal;
00092     unsigned int m_TotalTotal;
00093 
00094 
00095     std::string getStatusStr(const openfluid::base::Listener::Status& Status)
00096     {
00097       switch (Status)
00098       {
00099         case openfluid::machine::MachineListener::OK :
00100           return _("[OK]"); break;
00101         case openfluid::machine::MachineListener::WARNING :
00102           return _("[Warning]");break;
00103         default : return _("[Error]"); break;
00104 
00105       }
00106     }
00107 
00108 
00109     inline void refreshWidgets()
00110     {
00111       while(Gtk::Main::events_pending()) Gtk::Main::iteration();
00112     }
00113 
00114 
00115     inline void appendToTextBuffer(const std::string& Str)
00116     {
00117       m_RefDetailsTextBuffer->insert(m_RefDetailsTextBuffer->end(), Str);
00118       mp_DetailsTextView->scroll_to_mark(m_RefDetailsTextBuffer->get_insert(),0);
00119       refreshWidgets();
00120     }
00121 
00122 
00123     inline double computeCurrentFraction()
00124     {
00125       return (double(m_CurrentPreSim + m_CurrentInit + (m_CurrentStep+1) + m_CurrentFinal)/double(m_TotalTotal));
00126     }
00127 
00128 
00129     inline void updateProgressBar()
00130     {
00131       mp_RunStatusWidget->setProgressFraction(computeCurrentFraction());
00132       refreshWidgets();
00133     }
00134 
00135 
00136 
00137 
00138   public:
00139 
00140     RunDialogMachineListener() {};
00141 
00142     ~RunDialogMachineListener() {};
00143 
00144     void setWidgets(RunStatusWidget* RStatusWidget,
00145                     Gtk::TextView* DetailsTextView)
00146     {
00147       mp_RunStatusWidget = RStatusWidget;
00148       mp_DetailsTextView = DetailsTextView;
00149       m_RefDetailsTextBuffer = mp_DetailsTextView->get_buffer();
00150     };
00151 
00152 
00153     void setInfos(const unsigned int& TotalFunctions, const unsigned int& TotalSteps)
00154     {
00155       m_TotalFunctions = TotalFunctions;
00156 
00157       m_TotalSteps = TotalSteps;
00158 
00159       m_TotalTotal = 3 + m_TotalFunctions + m_TotalSteps + m_TotalFunctions;
00160       m_CurrentPreSim = 0;
00161       m_CurrentInit = 0;
00162       m_CurrentStep = 0;
00163       m_CurrentFinal = 0;
00164     }
00165 
00166 
00167     void onInitParams()
00168     {
00169       mp_RunStatusWidget->setPresimRunning();
00170     };
00171 
00172     virtual void onFunctionInitParams(const std::string& FunctionID)
00173     {
00174       appendToTextBuffer("<initParams> " + FunctionID);
00175     };
00176 
00177     void onFunctionInitParamsDone(const openfluid::base::Listener::Status& Status,
00178                                   const std::string& /*FunctionID*/)
00179     {
00180       appendToTextBuffer("  " + getStatusStr(Status) + "\n");
00181     };
00182 
00183 
00184     virtual void onInitParamsDone(const openfluid::base::Listener::Status& /*Status*/)
00185     {
00186       m_CurrentPreSim = 1;
00187       updateProgressBar();
00188     };
00189 
00190 
00191 
00192     void onFunctionPrepareData(const std::string& FunctionID)
00193     {
00194       appendToTextBuffer("<prepareData> " + FunctionID);
00195 
00196     };
00197 
00198     void onFunctionPrepareDataDone(const openfluid::base::Listener::Status& Status,
00199                                           const std::string& /*FunctionID*/)
00200     {
00201       appendToTextBuffer("  " + getStatusStr(Status) +"\n");
00202     };
00203 
00204 
00205     virtual void onPrepareDataDone(const openfluid::base::Listener::Status& /*Status*/)
00206     {
00207       m_CurrentPreSim = 2;
00208       updateProgressBar();
00209 
00210     };
00211 
00212 
00213     virtual void onFunctionCheckConsistency(const std::string& FunctionID)
00214     {
00215       appendToTextBuffer("<checkConsistency> " + FunctionID);
00216     };
00217 
00218     void onFunctionCheckConsistencyDone(const openfluid::base::Listener::Status& Status,
00219                                           const std::string& /*FunctionID*/)
00220     {
00221       appendToTextBuffer("  " + getStatusStr(Status) +"\n");
00222     };
00223 
00224 
00225     void onCheckConsistencyDone(const openfluid::base::Listener::Status& /*Status*/)
00226     {
00227       m_CurrentPreSim = 3;
00228       updateProgressBar();
00229       mp_RunStatusWidget->setPresimDone();
00230     };
00231 
00232 
00233     void onInitializeRun()
00234     {
00235       m_CurrentInit = 0;
00236       mp_RunStatusWidget->setInitRunning();
00237       refreshWidgets();
00238     };
00239 
00240     void onFunctionInitializeRun(const std::string& FunctionID)
00241     {
00242       appendToTextBuffer("<initializeRun> " + FunctionID);
00243     }
00244 
00245     void onFunctionInitializeRunDone(const openfluid::base::Listener::Status& Status,
00246                                           const std::string& /*FunctionID*/)
00247     {
00248       m_CurrentInit++;
00249       appendToTextBuffer("  " + getStatusStr(Status) +"\n");
00250       updateProgressBar();
00251     };
00252 
00253 
00254     void onInitializeRunDone(const openfluid::base::Listener::Status& /*Status*/)
00255     {
00256       mp_RunStatusWidget->setInitDone();
00257       refreshWidgets();
00258     };
00259 
00260 
00261     void onBeforeRunSteps()
00262     {
00263       m_CurrentStep = 0;
00264       openfluid::tools::ConvertValue(m_CurrentStep,&m_CurrentStepStr);
00265       mp_RunStatusWidget->setRunstepRunning();
00266       updateProgressBar();
00267     };
00268 
00269     void onRunStep(const openfluid::base::SimulationStatus* SimStatus)
00270     {
00271       m_CurrentStep = SimStatus->getCurrentStep();
00272       openfluid::tools::ConvertValue(m_CurrentStep,&m_CurrentStepStr);
00273       updateProgressBar();
00274     };
00275 
00276     void onFunctionRunStep(const std::string& FunctionID)
00277     {
00278       appendToTextBuffer("<runStep("+m_CurrentStepStr+")> " + FunctionID);
00279     };
00280 
00281 
00282     void onFunctionRunStepDone(const openfluid::base::Listener::Status& Status,
00283                                const std::string& /*FunctionID*/)
00284     {
00285       appendToTextBuffer("  " + getStatusStr(Status) +"\n");
00286     };
00287 
00288 
00289     void onRunStepDone(const openfluid::base::Listener::Status& /*Status*/)
00290     {
00291       mp_RunStatusWidget->updateCurrentStep(m_CurrentStepStr);
00292       mp_RunStatusWidget->setRunstepRunning();
00293       updateProgressBar();
00294     };
00295 
00296 
00297     void onAfterRunSteps()
00298     {
00299       refreshWidgets();
00300     };
00301 
00302     void onFinalizeRun()
00303     {
00304       m_CurrentFinal = 0;
00305       mp_RunStatusWidget->setRunstepDone();
00306       mp_RunStatusWidget->setFinalRunning();
00307       updateProgressBar();
00308     };
00309 
00310     void onFunctionFinalizeRun(const std::string& FunctionID)
00311     {
00312       appendToTextBuffer("<finalizeRun> " + FunctionID);
00313     }
00314 
00315 
00316     virtual void onFunctionFinalizeRunDone(const openfluid::base::Listener::Status& Status,
00317                                           const std::string& /*FunctionID*/)
00318     {
00319       m_CurrentFinal++;
00320       appendToTextBuffer("  " + getStatusStr(Status) +"\n");
00321       updateProgressBar();
00322     };
00323 
00324     virtual void onFinalizeRunDone(const openfluid::base::Listener::Status& /*Status*/)
00325     {
00326       mp_RunStatusWidget->setProgressFraction(1.0);
00327       mp_RunStatusWidget->setFinalDone();
00328       updateProgressBar();
00329     };
00330 
00331 };
00332 
00333 } } //namespaces
00334 
00335 
00336 
00337 #endif /* __RUNDIALOGMACHINELISTENER_HPP__ */

Generated using Doxygen 1.7.3
Creative Commons License Creative Commons By-NC-ND license