Commit 99af761d authored by CAMP C++ Builder's avatar CAMP C++ Builder

API enhancements: QtJobProcessor and pipelinewindows

* new QtJobProcessor singleton: used to execute jobs in the Qt thread
* CampvisApplication now has a map to obtain the window for a pipeline
parent ddfa21e1
......@@ -28,6 +28,7 @@ FILE(GLOB CampvisApplicationForms
)
SET(CampvisApplicationToBeMocced
qtjobprocessor.h
gui/mainwindow.h
gui/datacontainerinspectorcanvas.h
gui/datacontainerinspectorwidget.h
......
......@@ -48,6 +48,7 @@
#include "core/pipeline/visualizationprocessor.h"
#include "modules/pipelinefactory.h"
#include "qtjobprocessor.h"
#ifdef CAMPVIS_HAS_SCRIPTING
#include "scripting/gen_pipelineregistration.h"
......@@ -77,6 +78,7 @@ namespace campvis {
OpenGLJobProcessor::init();
SimpleJobProcessor::init();
QtJobProcessor::init();
}
CampVisApplication::~CampVisApplication() {
......@@ -259,7 +261,9 @@ namespace campvis {
PipelineRecord pr = { pipeline, painter };
_pipelines.push_back(pr);
_mainWindow->addVisualizationPipelineWidget(name, canvas);
if (!hide) {
_pipelineWindows[pipeline] = _mainWindow->addVisualizationPipelineWidget(name, canvas);
}
// initialize context (GLEW) and pipeline in OpenGL thread)
GLJobProc.enqueueJob(
......
......@@ -157,6 +157,8 @@ namespace campvis {
/// All pipelines
std::vector<PipelineRecord> _pipelines;
std::map<AbstractPipeline *, MdiDockableWindow *> _pipelineWindows;
/// All DataContainers
std::vector<DataContainer*> _dataContainers;
......
......@@ -295,11 +295,12 @@ namespace campvis {
_scriptingConsoleWidget->deinit();
}
void MainWindow::addVisualizationPipelineWidget(const std::string& name, QWidget* canvas) {
MdiDockableWindow * MainWindow::addVisualizationPipelineWidget(const std::string& name, QWidget* canvas) {
MdiDockableWindow* dockableWindow = _mdiArea->addWidget(canvas);
QString windowTitle = QString::fromStdString(name);
dockableWindow->setWindowTitle(windowTitle);
dockableWindow->show();
return dockableWindow;
}
QDockWidget* MainWindow::dockPrimaryWidget(const std::string& name, QWidget* widget) {
......
......@@ -89,7 +89,7 @@ namespace campvis {
* \param name the name of the visualization pipeline
* \param canvas the pipeline's canvas
*/
void addVisualizationPipelineWidget(const std::string& name, QWidget* canvas);
MdiDockableWindow * addVisualizationPipelineWidget(const std::string& name, QWidget* canvas);
protected:
/**
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#include "qtjobprocessor.h"
namespace campvis {
QtJobProcessor::QtJobProcessor()
: QWidget()
{
connect(this, SIGNAL(newJobSignal(AbstractJob *)), this, SLOT(onJobArrived(AbstractJob *)));
}
QtJobProcessor::~QtJobProcessor()
{
}
void QtJobProcessor::enqueueJob(AbstractJob * job) {
emit newJobSignal(job);
}
void QtJobProcessor::enqueueJob(std::function<void(void)> fn)
{
emit newJobSignal(makeJobOnHeap(fn));
}
void QtJobProcessor::onJobArrived(AbstractJob * job)
{
tgtAssert(job, "Job must not be null!");
std::cout << "Job processed." << std::endl;
(*job)();
delete job;
}
}
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#ifndef QTJOBPROCESSOR_H__
#define QTJOBPROCESSOR_H__
#include "core/tools/job.h"
#include "tgt/singleton.h"
#include <QWidget>
#include <functional>
namespace campvis {
/**
* Job processor class for campvis
*/
class QtJobProcessor : public QWidget, public tgt::Singleton<QtJobProcessor> {
Q_OBJECT;
public:
QtJobProcessor();
virtual ~QtJobProcessor();
void enqueueJob(AbstractJob * job);
void enqueueJob(std::function<void(void)> fn);
signals:
void newJobSignal(AbstractJob * job);
private slots:
void onJobArrived(AbstractJob * job);
};
}
#define QtJobProc tgt::Singleton<campvis::QtJobProcessor>::getRef()
#endif // QTJOBPROCESSOR_H__
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