process.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 8598 $                                                         *
00038  *   $Author: kremer $                                                      *
00039  *   $Date: 2010-02-23 15:09:09 +0100 (Di, 23. Feb 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS Core - IMPLEMENTATION
00049 //
00050 //=============================================================================
00051 
00052 
00053 //== INCLUDES =================================================================
00054 
00055 #include "Core.hh"
00056 
00057 #include <OpenFlipper/widgets/processManagerWidget/BlockingWidget.hh>
00058 
00059 //== IMPLEMENTATION ==========================================================
00060 
00061 
00062 // A job has been started by a plugin
00063 void Core::slotStartJob( QString _jobId, QString _description , int _min , int _max, bool _blocking) {
00064   std::cerr << "StartJob: " << _jobId.toStdString() << " " << _description.toStdString() << " " << _min << " " << _max  << " " << _blocking <<std::endl;
00065 
00066   // Create job information
00067   JobInfo* info        = new JobInfo();
00068   info->id             = _jobId;
00069   info->description    = _description;
00070   info->currentStep    =  0;
00071   info->minSteps       = _min;
00072   info->maxSteps       = _max;
00073   info->blocking       = _blocking;
00074 
00075   // Add job to local job list
00076   currentJobs.push_back(info);
00077 
00078   // Don't show process status in process manager
00079   // if blocking is enabled
00080   if(_blocking) {
00081           // Create blocking widget
00082           BlockingWidget* widget = new BlockingWidget(_jobId, _description,
00083                           _min, _max);
00084 
00085           // Connect cancel button to local slot for further treatment
00086           connect(widget,       SIGNAL(cancelRequested(QString)),
00087                           this,     SLOT(slotJobCancelRequested(QString)));
00088 
00089           info->blockingWidget = widget;
00090 
00091           // Show blocking widget
00092           widget->show();
00093 
00094   } else {
00095           // Create process manager window if it has not been created before
00096           if(!processManager_) {
00097                   processManager_ = new ProcessManagerWidget();
00098       
00099                   // Connect cancel buttons to local slot for further treatment
00100                   connect(processManager_, SIGNAL(cancelJobRequested(QString)),
00101                                   this,            SLOT(slotJobCancelRequested(QString)));
00102           }
00103 
00104           // Add new item
00105           processManager_->addJob(_jobId, _description, _min, _max);
00106 
00107           // Show window
00108           processManager_->show();
00109   }
00110 }
00111 
00112 //-----------------------------------------------------------------------------
00113 bool Core::getJob(QString _jobId, int& _index) {
00114   
00115   for ( int i = 0 ; i < currentJobs.size() ; ++i) {
00116       if ( currentJobs[i]->id == _jobId ) {
00117         _index = i;
00118         return true;
00119       }
00120   }
00121   
00122   emit log(LOGERR,tr("Unable to find Job %1.").arg(_jobId));
00123   _index = -1;
00124   return false;
00125 }
00126 
00127 //-----------------------------------------------------------------------------
00128 
00129 // A job state has been updated by a plugin
00130 void Core::slotSetJobState(QString _jobId, int _value ) {
00131   int id;
00132   
00133   if (  getJob(_jobId, id) ) {
00134     currentJobs[id]->currentStep = _value;
00135 
00136     // Update gui
00137     if(!currentJobs[id]->blocking)
00138         processManager_->updateStatus(_jobId, _value);
00139     else {
00140         BlockingWidget* w = 0;
00141         w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
00142         if(w != 0) {
00143                 w->updateStatus(_value);
00144         }
00145     }
00146   }
00147 }
00148 
00149 //-----------------------------------------------------------------------------
00150 
00151 // A job's caption has been updated by a plugin
00152 void Core::slotSetJobName(QString _jobId, QString _name ) {
00153     int id;
00154     
00155     if (  getJob(_jobId, id) ) {
00156         currentJobs[id]->id = _name;
00157 
00158         // Update gui
00159         if(!currentJobs[id]->blocking)
00160                 processManager_->setJobName(_jobId, _name);
00161         else {
00162                 BlockingWidget* w = 0;
00163                 w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
00164                 if(w != 0) {
00165                         w->setJobId(_name);
00166                 }
00167         }
00168     }
00169 }
00170 //-----------------------------------------------------------------------------
00171 
00172 // A job's widget's status text has been updated by a plugin
00173 void Core::slotSetJobDescription(QString _jobId, QString _text ) {
00174     int id;
00175     
00176     if (  getJob(_jobId, id) ) {
00177         currentJobs[id]->description = _text;
00178 
00179         // Update gui
00180         if(!currentJobs[id]->blocking)
00181                 processManager_->setJobDescription(_jobId, _text);
00182         else {
00183                 BlockingWidget* w = 0;
00184                 w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
00185             if(w != 0) {
00186                 w->setJobDescription(_text);
00187             }
00188         }
00189     }
00190 }
00191 
00192 //-----------------------------------------------------------------------------
00193 
00194 // A job state has been canceled by a plugin
00195 void Core::slotCancelJob(QString _jobId ) {
00196   int id;
00197   
00198   if (  getJob(_jobId, id) ) {
00199 
00200         // Update gui
00201         if(!currentJobs[id]->blocking)
00202                 processManager_->removeJob(_jobId);
00203         else {
00204                 BlockingWidget* w = 0;
00205                 w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
00206                 if(w != 0) {
00207                         w->hide();
00208                         delete w;
00209                 }
00210         }
00211 
00212         currentJobs.removeAt(id);
00213   }
00214 }
00215 
00216 //-----------------------------------------------------------------------------
00217 
00218 // A job state has been finished by a plugin
00219 void Core::slotFinishJob(QString _jobId ) {
00220   int id;
00221   
00222   if (  getJob(_jobId, id) ) {
00223 
00224         // Update gui
00225         if(!currentJobs[id]->blocking)
00226                 processManager_->removeJob(_jobId);
00227         else {
00228                 BlockingWidget* w = 0;
00229                 w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
00230                 if(w != 0) {
00231                         w->hide();
00232                         delete w;
00233                 }
00234         }
00235 
00236     currentJobs.removeAt(id);
00237   }
00238 }
00239 
00240 //-----------------------------------------------------------------------------
00241 
00242 // A job will be canceled by user request
00243 void Core::slotJobCancelRequested(QString /*_jobId*/) {
00244     
00245     // Cancel job still to be implemented...
00246         std::cerr << "Cancel requested!" << std::endl;
00247 }
00248 
00249 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .