Commit b748b9bd authored by Jan Möbius's avatar Jan Möbius

First version of the process interface

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@7305 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 7cdd66b6
......@@ -53,10 +53,19 @@
#define PROCESSINTERFACE_HH
#include <QtGui>
#include <QProgressDialog>
#include <OpenFlipper/threads/OpenFlipperThread.hh>
/**
/** \brief Interface class controlling threadding in OpenFlipper
*
*
* Example:\n
* OpenFlipperThread* thread = new OpenFlipperThread(name() + "unique id"); // Create your thread containing a unique id \n
* connect(thread,SIGNAL( state(QString, int)), this,SIGNAL(setJobState(QString, int))); // connect your threads state info to the global one \n
* connect(thread,SIGNAL( finished(QString)), this,SIGNAL(finishJob(QString))); // connect your threads finish info to the global one ( you can do the same for a local one ) \n
* connect(thread,SIGNAL( function()), this,SLOT(testFunctionThread()),Qt::DirectConnection); // You can directly give a slot of your app that gets called \n
* emit startJob( name() + "1", "Description" , 0 , 100 , false); // Tell the core about your thread
* thread->start(); // start execution
*/
class ProcessInterface {
......@@ -78,8 +87,10 @@ class ProcessInterface {
*
* min and max define the range your status values will be in.
*
* blocking will define, if user interaction with the core should still be possible
*
*/
virtual void startJob( QString /*_jobId*/, QString /*_description */, int /*_min*/ , int /*_max*/ ) {};
virtual void startJob( QString /*_jobId*/, QString /*_description */, int /*_min*/ , int /*_max*/ , bool /*_blocking */ = false) {};
/** \brief update job state
*
......
......@@ -74,6 +74,7 @@
#include <QDockWidget>
#include <QVector>
#include <QProgressDialog>
#include <QtScript/QScriptEngine>
#include <QtScript/QtScript>
......@@ -105,6 +106,8 @@
#include <ACG/Scenegraph/CoordsysNode.hh>
#include <ACG/Scenegraph/GridNode.hh>
#include <OpenFlipper/threads/JobInfo.hh>
//== CLASS DEFINITION =========================================================
struct fileTypes {
......@@ -907,20 +910,28 @@ private:
private:
QList< JobInfo* > currentJobs;
/// Find a job in the jobslist
bool getJob(QString _jobId, int& _index);
private slots:
// A job has been started by a plugin
void slotStartJob( QString _jobId, QString _description , int _min , int _max );
/// A job has been started by a plugin
void slotStartJob( QString _jobId, QString _description , int _min , int _max,bool _blocking );
// A job state has been updated by a plugin
/// A job state has been updated by a plugin
void slotSetJobState(QString _jobId, int _value );
// A job state has been canceled by a plugin
/// A job state has been canceled by a plugin
void slotCancelJob(QString _jobId );
// A job state has been finished by a plugin
/// A job state has been finished by a plugin
void slotFinishJob(QString _jobId );
/// Called by dialogs if cancel button is pressed
void slotJobCancelButtons();
signals:
void jobCanceled( QString _jobId );
......
......@@ -970,9 +970,9 @@ void Core::loadPlugin(QString filename, bool silent){
if ( processPlugin ) {
supported = supported + "Process ";
if ( checkSignal(plugin,"startJob(QString,QString,int,int)" ) )
connect(plugin , SIGNAL(startJob(QString, QString,int,int)),
this , SLOT( slotStartJob(QString, QString,int,int) ) ,Qt::DirectConnection );
if ( checkSignal(plugin,"startJob(QString,QString,int,int,bool)" ) )
connect(plugin , SIGNAL(startJob(QString, QString,int,int,bool)),
this , SLOT( slotStartJob(QString, QString,int,int,bool) ) ,Qt::DirectConnection );
else
emit log(LOGERR,"Process Interface defined but no startJob signal found!");
......
......@@ -58,29 +58,96 @@
// A job has been started by a plugin
void Core::slotStartJob( QString _jobId, QString _description , int _min , int _max ) {
std::cerr << "slotStartJob" << std::endl;
void Core::slotStartJob( QString _jobId, QString _description , int _min , int _max, bool _blocking) {
std::cerr << "StartJob: " << _jobId.toStdString() << " " << _description.toStdString() << " " << _min << " " << _max << " " << _blocking <<std::endl;
JobInfo* info = new JobInfo();
info->jobId = _jobId;
info->description = _description;
info->min = _min;
info->max = _max;
info->blocking = _blocking;
info->progressDialog = new QProgressDialog(coreWidget_);
info->progressDialog->setLabelText(_description);
info->progressDialog->setMinimum(_min);
info->progressDialog->setMaximum(_max);
info->progressDialog->setValue(_min);
info->progressDialog->resize(300,130);
info->progressDialog->setMinimumDuration(1);
if ( _blocking )
info->progressDialog->setWindowModality(Qt::WindowModal);
connect( info->progressDialog, SIGNAL(canceled()),
this,SLOT(slotJobCancelButtons()));
currentJobs.push_back(info);
}
//-----------------------------------------------------------------------------
bool Core::getJob(QString _jobId, int& _index) {
for ( int i = 0 ; i < currentJobs.size() ; ++i) {
if ( currentJobs[i]->jobId == _jobId ) {
_index = i;
return true;
}
}
emit log(LOGERR,tr("Unable to find Job %1.").arg(_jobId));
_index = -1;
return false;
}
//-----------------------------------------------------------------------------
// A job state has been updated by a plugin
void Core::slotSetJobState(QString _jobId, int _value ) {
std::cerr << "slotSetJobState" << std::endl;
int id;
if ( getJob(_jobId, id) ) {
currentJobs[id]->currentState = _value;
currentJobs[id]->progressDialog->setValue(_value);
}
}
//-----------------------------------------------------------------------------
// A job state has been canceled by a plugin
void Core::slotCancelJob(QString _jobId ) {
std::cerr << "slotCancelJob" << std::endl;
int id;
if ( getJob(_jobId, id) ) {
currentJobs[id]->progressDialog->reset();
currentJobs[id]->progressDialog->hide();
delete currentJobs[id]->progressDialog;
currentJobs.removeAt(id);
}
}
//-----------------------------------------------------------------------------
// A job state has been finished by a plugin
void Core::slotFinishJob(QString _jobId ) {
std::cerr << "slotFinishJob" << std::endl;
int id;
if ( getJob(_jobId, id) ) {
currentJobs[id]->progressDialog->reset();
currentJobs[id]->progressDialog->hide();
delete currentJobs[id]->progressDialog;
currentJobs.removeAt(id);
}
}
// The user canceled a job
void Core::slotJobCancelButtons( ) {
for ( int i = 0 ; i < currentJobs.size() ; ++i) {
if ( currentJobs[i]->progressDialog == sender() ) {
QString id = currentJobs[i]->jobId;
slotCancelJob(id);
emit jobCanceled( id );
}
}
}
......
......@@ -20,6 +20,7 @@ set (directories
../BasePlugin
../ACGHelper
../common
../threads
../common/bsp
../INIFile
../widgets/glWidget
......
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 5074 $
// $Author: wilden $
// $Date: 2009-02-25 18:27:57 +0100 (Mi, 25. Feb 2009) $
//
//=============================================================================
#include "JobInfo.hh"
#include <iostream>
JobInfo::JobInfo() :
jobId(""),
description(""),
currentState(0),
min(0),
max(100),
blocking(false),
progressDialog(0)
{
}
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 5074 $
// $Author: wilden $
// $Date: 2009-02-25 18:27:57 +0100 (Mi, 25. Feb 2009) $
//
//=============================================================================
#ifndef OPENFLIPPERJOBINFO_HH
#define OPENFLIPPERJOBINFO_HH
#include <QProgressDialog>
#include <OpenFlipper/common/GlobalDefines.hh>
/** \brief Job Information class
*
* This class stores information about currently running tasks in OpenFlipper
*/
class DLLEXPORT JobInfo {
public:
JobInfo();
public:
QString jobId;
QString description;
int currentState;
int min;
int max;
bool blocking;
QProgressDialog* progressDialog;
};
#endif //OPENFLIPPERJOBINFO_HH
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 5074 $
// $Author: wilden $
// $Date: 2009-02-25 18:27:57 +0100 (Mi, 25. Feb 2009) $
//
//=============================================================================
#include "OpenFlipperThread.hh"
#include <iostream>
OpenFlipperThread::OpenFlipperThread( QString _jobId ) :
jobId_(_jobId)
{
}
OpenFlipperThread::~OpenFlipperThread() {
}
void OpenFlipperThread::run()
{
std::cerr << "Start Function" << std::endl;
// This starts the function in our local thread if DirectConnection is used!
emit function();
// Emit a message that our job is finished
emit finished(jobId_);
std::cerr << "Done " << std::endl;
// start event loop of thread
// exec();
}
void OpenFlipperThread::cancel() {
std::cerr << "Cancel not implemented" << std::endl;
}
void OpenFlipperThread::slotCancel( QString _jobId) {
if ( _jobId == jobId_ )
cancel();
}
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 5074 $
// $Author: wilden $
// $Date: 2009-02-25 18:27:57 +0100 (Mi, 25. Feb 2009) $
//
//=============================================================================
#ifndef OPENFLIPPERTHREAD_HH
#define OPENFLIPPERTHREAD_HH
#include <QThread>
#include <QProgressDialog>
#include <OpenFlipper/common/GlobalDefines.hh>
class DLLEXPORT OpenFlipperThread : public QThread
{
Q_OBJECT
public:
OpenFlipperThread( QString _jobId );
~OpenFlipperThread();
/** \brief Main processing
*
* Connect a function to the function() signal ( DirectConnection!!! )
* Or reimplement this function
*/
virtual void run();
/** Reimplement this if you have to take care about how your process is canceled
*/
virtual void cancel();
private:
QString jobId_;
public slots:
/** Call this slot with the correct job id to abort processing
* This directly calls cancel()
* This is only usefull when you derived from this class, as other jobs might not react on this slot
*/
void slotCancel( QString _jobId);
signals:
/// Emit this signal to tell the core about your job status
void state( QString _jobId, int _state );
/// This signal is emitted if your job has finished
void finished( QString _jobId );
/** The thread directly calls this function. You do not have to derive from OpenFlipperThread ( although this is
* necessary to update the core about your progress via state().
* You can also connect one of your slots using \n
* connect( OpenFlipperThread ,SIGNAL(function()),YourPlugin,SLOT(YourSlot(),Qt::DirectConnection) );\n
* The default implementation will call your slot inside the given thread and the core will still respond.
* However you should only use this function if you Dont know how long your job takes. \n
* Otherwise you should reimplement the run() function of OpenFlipperThread.
*/
void function();
};
#endif //OPENFLIPPERTHREAD_HH
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment