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 
00062 #include <glibmm/i18n.h>
00063 
00064 #include <gtkmm/textview.h>
00065 #include <gtkmm/main.h>
00066 
00067 #include <openfluid/dllexport.hpp>
00068 #include <openfluid/guicommon/RunStatusWidget.hpp>
00069 
00070 
00071 namespace openfluid { namespace guicommon {
00072 
00073 // =====================================================================
00074 // =====================================================================
00075 
00076 
00077 class DLLEXPORT RunDialogMachineListener : public openfluid::machine::MachineListener
00078 {
00079   private:
00080     unsigned int m_CurrentStep;
00081     std::string m_CurrentStepStr;
00082     unsigned int m_CurrentFunction;
00083 
00084     unsigned int m_TotalSteps;
00085     unsigned int m_TotalFunctions;
00086 
00087     RunStatusWidget* mp_RunStatusWidget;
00088 
00089     Gtk::TextView* mp_DetailsTextView;
00090     Glib::RefPtr<Gtk::TextBuffer> m_RefDetailsTextBuffer;
00091 
00092     unsigned int m_CurrentPreSim;
00093     unsigned int m_CurrentInit;
00094     unsigned int m_CurrentFinal;
00095     unsigned int m_TotalTotal;
00096 
00097 
00098     std::string getStatusStr(const openfluid::base::Listener::Status& Status)
00099     {
00100       switch (Status)
00101       {
00102         case openfluid::machine::MachineListener::OK :
00103           return _("[OK]"); break;
00104         case openfluid::machine::MachineListener::WARNING :
00105           return _("[Warning]");break;
00106         default : return _("[Error]"); break;
00107 
00108       }
00109     }
00110 
00111 
00112     inline void refreshWidgets()
00113     {
00114       while(Gtk::Main::events_pending()) Gtk::Main::iteration();
00115     }
00116 
00117 
00118     inline void appendToTextBuffer(const std::string& Str)
00119     {
00120       m_RefDetailsTextBuffer->insert(m_RefDetailsTextBuffer->end(), Str);
00121       mp_DetailsTextView->scroll_to_mark(m_RefDetailsTextBuffer->get_insert(),0);
00122       refreshWidgets();
00123     }
00124 
00125 
00126     inline double computeCurrentFraction()
00127     {
00128       return (double(m_CurrentPreSim + m_CurrentInit + (m_CurrentStep+1) + m_CurrentFinal)/double(m_TotalTotal));
00129     }
00130 
00131 
00132     inline void updateProgressBar()
00133     {
00134       mp_RunStatusWidget->setProgressFraction(computeCurrentFraction());
00135       refreshWidgets();
00136     }
00137 
00138 
00139 
00140 
00141   public:
00142 
00143     RunDialogMachineListener() {};
00144 
00145     ~RunDialogMachineListener() {};
00146 
00147     void setWidgets(RunStatusWidget* RStatusWidget,
00148                     Gtk::TextView* DetailsTextView)
00149     {
00150       mp_RunStatusWidget = RStatusWidget;
00151       mp_DetailsTextView = DetailsTextView;
00152       m_RefDetailsTextBuffer = mp_DetailsTextView->get_buffer();
00153     };
00154 
00155 
00156     void setInfos(const unsigned int& TotalFunctions, const unsigned int& TotalSteps)
00157     {
00158       m_TotalFunctions = TotalFunctions;
00159 
00160       m_TotalSteps = TotalSteps;
00161 
00162       m_TotalTotal = 3 + m_TotalFunctions + m_TotalSteps + m_TotalFunctions;
00163       m_CurrentPreSim = 0;
00164       m_CurrentInit = 0;
00165       m_CurrentStep = 0;
00166       m_CurrentFinal = 0;
00167     }
00168 
00169 
00170     void onInitParams()
00171     {
00172       mp_RunStatusWidget->setPresimRunning();
00173     };
00174 
00175     virtual void onFunctionInitParams(const std::string& FunctionID)
00176     {
00177       appendToTextBuffer("<initParams> " + FunctionID);
00178     };
00179 
00180     void onFunctionInitParamsDone(const openfluid::base::Listener::Status& Status,
00181                                   const std::string& /*FunctionID*/)
00182     {
00183       appendToTextBuffer("  " + getStatusStr(Status) + "\n");
00184     };
00185 
00186 
00187     virtual void onInitParamsDone(const openfluid::base::Listener::Status& /*Status*/)
00188     {
00189       m_CurrentPreSim = 1;
00190       updateProgressBar();
00191     };
00192 
00193 
00194 
00195     void onFunctionPrepareData(const std::string& FunctionID)
00196     {
00197       appendToTextBuffer("<prepareData> " + FunctionID);
00198 
00199     };
00200 
00201     void onFunctionPrepareDataDone(const openfluid::base::Listener::Status& Status,
00202                                           const std::string& /*FunctionID*/)
00203     {
00204       appendToTextBuffer("  " + getStatusStr(Status) +"\n");
00205     };
00206 
00207 
00208     virtual void onPrepareDataDone(const openfluid::base::Listener::Status& /*Status*/)
00209     {
00210       m_CurrentPreSim = 2;
00211       updateProgressBar();
00212 
00213     };
00214 
00215 
00216     virtual void onFunctionCheckConsistency(const std::string& FunctionID)
00217     {
00218       appendToTextBuffer("<checkConsistency> " + FunctionID);
00219     };
00220 
00221     void onFunctionCheckConsistencyDone(const openfluid::base::Listener::Status& Status,
00222                                           const std::string& /*FunctionID*/)
00223     {
00224       appendToTextBuffer("  " + getStatusStr(Status) +"\n");
00225     };
00226 
00227 
00228     void onCheckConsistencyDone(const openfluid::base::Listener::Status& /*Status*/)
00229     {
00230       m_CurrentPreSim = 3;
00231       updateProgressBar();
00232       mp_RunStatusWidget->setPresimDone();
00233     };
00234 
00235 
00236     void onInitializeRun()
00237     {
00238       m_CurrentInit = 0;
00239       mp_RunStatusWidget->setInitRunning();
00240       refreshWidgets();
00241     };
00242 
00243     void onFunctionInitializeRun(const std::string& FunctionID)
00244     {
00245       appendToTextBuffer("<initializeRun> " + FunctionID);
00246     }
00247 
00248     void onFunctionInitializeRunDone(const openfluid::base::Listener::Status& Status,
00249                                           const std::string& /*FunctionID*/)
00250     {
00251       m_CurrentInit++;
00252       appendToTextBuffer("  " + getStatusStr(Status) +"\n");
00253       updateProgressBar();
00254     };
00255 
00256 
00257     void onInitializeRunDone(const openfluid::base::Listener::Status& /*Status*/)
00258     {
00259       mp_RunStatusWidget->setInitDone();
00260       refreshWidgets();
00261     };
00262 
00263 
00264     void onBeforeRunSteps()
00265     {
00266       m_CurrentStep = 0;
00267       openfluid::tools::ConvertValue(m_CurrentStep,&m_CurrentStepStr);
00268       mp_RunStatusWidget->setRunstepRunning();
00269       updateProgressBar();
00270     };
00271 
00272     void onRunStep(const openfluid::base::SimulationStatus* SimStatus)
00273     {
00274       m_CurrentStep = SimStatus->getCurrentStep();
00275       openfluid::tools::ConvertValue(m_CurrentStep,&m_CurrentStepStr);
00276       updateProgressBar();
00277     };
00278 
00279     void onFunctionRunStep(const std::string& FunctionID)
00280     {
00281       appendToTextBuffer("<runStep("+m_CurrentStepStr+")> " + FunctionID);
00282     };
00283 
00284 
00285     void onFunctionRunStepDone(const openfluid::base::Listener::Status& Status,
00286                                const std::string& /*FunctionID*/)
00287     {
00288       appendToTextBuffer("  " + getStatusStr(Status) +"\n");
00289     };
00290 
00291 
00292     void onRunStepDone(const openfluid::base::Listener::Status& /*Status*/)
00293     {
00294       mp_RunStatusWidget->updateCurrentStep(m_CurrentStepStr);
00295       mp_RunStatusWidget->setRunstepRunning();
00296       updateProgressBar();
00297     };
00298 
00299 
00300     void onAfterRunSteps()
00301     {
00302       refreshWidgets();
00303     };
00304 
00305     void onFinalizeRun()
00306     {
00307       m_CurrentFinal = 0;
00308       mp_RunStatusWidget->setRunstepDone();
00309       mp_RunStatusWidget->setFinalRunning();
00310       updateProgressBar();
00311     };
00312 
00313     void onFunctionFinalizeRun(const std::string& FunctionID)
00314     {
00315       appendToTextBuffer("<finalizeRun> " + FunctionID);
00316     }
00317 
00318 
00319     virtual void onFunctionFinalizeRunDone(const openfluid::base::Listener::Status& Status,
00320                                           const std::string& /*FunctionID*/)
00321     {
00322       m_CurrentFinal++;
00323       appendToTextBuffer("  " + getStatusStr(Status) +"\n");
00324       updateProgressBar();
00325     };
00326 
00327     virtual void onFinalizeRunDone(const openfluid::base::Listener::Status& /*Status*/)
00328     {
00329       mp_RunStatusWidget->setProgressFraction(1.0);
00330       mp_RunStatusWidget->setFinalDone();
00331       updateProgressBar();
00332     };
00333 
00334 };
00335 
00336 } } //namespaces
00337 
00338 
00339 
00340 #endif /* __RUNDIALOGMACHINELISTENER_HPP__ */

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