mainwindow.cpp 10 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
4
5
// 
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
8
9
//      Chair for Computer Aided Medical Procedures
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
schultezub's avatar
schultezub committed
10
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
// 
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// 
// ================================================================================================

30
31
32
#include "mainwindow.h"

#include "tgt/assert.h"
schultezub's avatar
schultezub committed
33
#include "application/campvisapplication.h"
34
#include "application/gui/datacontainerinspectorwidget.h"
35
#include "application/gui/datacontainerinspectorcanvas.h"
36
#include "application/gui/qtdatahandle.h"
37
#include "application/gui/visualizationpipelinewrapper.h"
38
39
#include "core/pipeline/abstractpipeline.h"
#include "core/pipeline/abstractprocessor.h"
40

41
#include <QMdiSubWindow>
42
#include <QScrollBar>
43

schultezub's avatar
schultezub committed
44
namespace campvis {
45

46
    MainWindow::MainWindow(CampVisApplication* application)
47
48
        : QMainWindow()
        , _application(application)
49
        , _mdiArea(0)
50
        , _pipelineWidget(0)
51
52
        , _propCollectionWidget(0)
        , _dcInspectorWidget(0)
53
        , _dcInspectorDock(0)
54
55
56
57
        , _btnExecute(0)
        , _btnShowDataContainerInspector(0)
        , _selectedPipeline(0)
        , _selectedProcessor(0)
58
        , _logViewer(0)
59
60
    {
        tgtAssert(_application != 0, "Application must not be 0.");
61
        ui.setupUi(this);
62
63
64
65
        setup();
    }

    MainWindow::~MainWindow() {
schultezub's avatar
schultezub committed
66
        _application->s_PipelinesChanged.disconnect(this);
67
        delete _dcInspectorWidget;
68
69
70
    }

    void MainWindow::setup() {
71
72
        qRegisterMetaType<QtDataHandle>("QtDataHandle");

73
        setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
74
        setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
75
        setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
76
        setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
77

78
        setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North);
79

80
81
82
83
        _mdiArea = new QMdiArea();
        _mdiArea->tileSubWindows();
        setCentralWidget(_mdiArea);

84
85
        _pipelineWidget = new PipelineTreeWidget();
        ui.pipelineTreeDock->setWidget(_pipelineWidget);
86

87
88
89
90
91
92
93
94
95
        _pipelinePropertiesScrollArea = new QScrollArea();
        _pipelinePropertiesScrollArea->setWidgetResizable(true);
        _pipelinePropertiesScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        _pipelinePropertiesScrollArea->setFrameStyle(QScrollArea::NoFrame);

        _pipelinePropertiesWidget = new QWidget();
        _pipelinePropertiesWidget->installEventFilter(this);
        _pipelinePropertiesScrollArea->setWidget(_pipelinePropertiesWidget);
        ui.pipelinePropertiesDock->setWidget(_pipelinePropertiesScrollArea);
96
97
98

        QVBoxLayout* rightLayout = new QVBoxLayout();
        rightLayout->setSpacing(4);
99
        _pipelinePropertiesWidget->setLayout(rightLayout);
100

101
        _btnExecute = new QPushButton("Execute Selected Pipeline/Processor");
102
103
        rightLayout->addWidget(_btnExecute);

104
        _btnShowDataContainerInspector = new QPushButton("Inspect DataContainer of Selected Pipeline");
105
        rightLayout->addWidget(_btnShowDataContainerInspector);
106

107
        _propCollectionWidget = new PropertyCollectionWidget();
108
        rightLayout->addWidget(_propCollectionWidget);
109
        rightLayout->addStretch();
110

111
        _logViewer = new LogViewerWidget();
112
        ui.logViewerDock->setWidget(_logViewer);
113

114
        _dcInspectorWidget = new DataContainerInspectorWidget();
115
116
117
118
119
120
121
122

        connect(
            this, SIGNAL(updatePipelineWidget(const std::vector<AbstractPipeline*>&)), 
            _pipelineWidget, SLOT(update(const std::vector<AbstractPipeline*>&)));
        connect(
            _pipelineWidget, SIGNAL(clicked(const QModelIndex&)), 
            this, SLOT(onPipelineWidgetItemClicked(const QModelIndex&)));
        connect(
123
124
            this, SIGNAL(updatePropCollectionWidget(HasPropertyCollection*, DataContainer*)),
            _propCollectionWidget, SLOT(updatePropCollection(HasPropertyCollection*, DataContainer*)));
125
126
127
128
129
130
        connect(
            _btnExecute, SIGNAL(clicked()), 
            this, SLOT(onBtnExecuteClicked()));
        connect(
            _btnShowDataContainerInspector, SIGNAL(clicked()), 
            this, SLOT(onBtnShowDataContainerInspectorClicked()));
131
132
133
        _application->s_PipelinesChanged.connect(this, &MainWindow::onPipelinesChanged);
    }

134
135
136
137
138
139
140
141
142
    bool MainWindow::eventFilter(QObject* watched, QEvent* event) {
        if (watched == _pipelinePropertiesWidget && event->type() == QEvent::Resize) {
            _pipelinePropertiesScrollArea->setMinimumWidth(_pipelinePropertiesWidget->minimumSizeHint().width() +
                                                           _pipelinePropertiesScrollArea->verticalScrollBar()->width());
        }

        return false;
    }

143
144
145
146
    void MainWindow::onPipelinesChanged() {
        emit updatePipelineWidget(_application->_pipelines);
    }

147
148
149
150
151
    void MainWindow::onPipelineWidgetItemClicked(const QModelIndex& index) {
        if (index.isValid()) {
            // Yak, this is so ugly - another reason why GUI programming sucks...
            QVariant item = index.data(Qt::UserRole);
            HasPropertyCollection* ptr = static_cast<HasPropertyCollection*>(item.value<void*>());
152
153
154
155
156

            if (AbstractPipeline* pipeline = dynamic_cast<AbstractPipeline*>(ptr)) {
            	_selectedPipeline = pipeline;
                _selectedProcessor = 0;
            }
schultezub's avatar
schultezub committed
157
158
            else if (AbstractProcessor* processor = dynamic_cast<AbstractProcessor*>(ptr)) {
                _selectedProcessor = processor;
159
160
161
162
163
164

                QVariant parentItem = index.parent().data(Qt::UserRole);
                HasPropertyCollection* pptr = static_cast<HasPropertyCollection*>(parentItem.value<void*>());
                if (AbstractPipeline* pipeline = dynamic_cast<AbstractPipeline*>(pptr)) {
                    _selectedPipeline = pipeline;
                }
schultezub's avatar
schultezub committed
165
            }
166
167

            emit updatePropCollectionWidget(ptr, &_selectedPipeline->getDataContainer());
168
169
        }
        else {
170
            emit updatePropCollectionWidget(0, 0);
171
172
173
        }
    }

174
175
176
177
    QSize MainWindow::sizeHint() const {
        return QSize(800, 450);
    }

178
179
180
181
    void MainWindow::onBtnExecuteClicked() {
        if (_selectedProcessor != 0 && _selectedPipeline != 0) {
            // this is not as trivial as it seems:
            // We need the pipeline, probably an OpenGL context...
182
            _selectedProcessor->invalidate(AbstractProcessor::INVALID_RESULT);
183
184
        }
        else if (_selectedPipeline != 0) {
185
186
187
            for (std::vector<AbstractProcessor*>::const_iterator it = _selectedPipeline->getProcessors().begin(); it != _selectedPipeline->getProcessors().end(); ++it) {
                (*it)->invalidate(AbstractProcessor::INVALID_RESULT);
            }
188
189
190
191
192
        }
    }

    void MainWindow::onBtnShowDataContainerInspectorClicked() {
        if (_selectedPipeline != 0) {
193
194
195
196
197
198
199
200
            if (_dcInspectorDock == 0) {
                _dcInspectorDock = dockPrimaryWidget("Data Container inspector", _dcInspectorWidget);
            } else {
                // Activate the dock's tab
                _dcInspectorDock->setVisible(true);
                _dcInspectorDock->raise();
            }

201
202
203
204
            _dcInspectorWidget->setDataContainer(&(_selectedPipeline->getDataContainer()));
        }
    }

205
    void MainWindow::init() {
206
207
        if (_dcInspectorWidget != 0)
            _dcInspectorWidget->init();
208

209
        _logViewer->init();
210
211
212
    }

    void MainWindow::deinit() {
213
214
        if (_dcInspectorWidget != 0)
            _dcInspectorWidget->deinit();
215

216
        _logViewer->deinit();
217
218
    }

219
220
    void MainWindow::addVisualizationPipelineWidget(const std::string& name, QWidget* canvas) {
        VisualizationPipelineWrapper* widget = new VisualizationPipelineWrapper(name, canvas, _mdiArea, this);
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
    }

    QDockWidget* MainWindow::dockPrimaryWidget(const std::string& name, QWidget* widget) {
        QDockWidget* dockWidget = new QDockWidget(QString::fromStdString(name));
        dockWidget->setWidget(widget);
        dockWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);

        if (_primaryDocks.empty()) {
            addDockWidget(Qt::TopDockWidgetArea, dockWidget);
        } else {
            tabifyDockWidget(_primaryDocks.back(), dockWidget);
            // Activate the dock's tab
            dockWidget->setVisible(true);
            dockWidget->raise();
        }

        _primaryDocks.push_back(dockWidget);
        return dockWidget;
239
240
    }

241
}