CustusX  15.3.3-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxPipelineWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxPipelineWidget.h"
34 #include "cxHelperWidgets.h"
35 
37 #include <QtWidgets>
38 #include "cxLogger.h"
39 #include "cxTypeConversions.h"
40 #include "cxDataSelectWidget.h"
41 #include "cxSettings.h"
42 
43 namespace cx
44 {
45 
46 PipelineWidgetFilterLine::PipelineWidgetFilterLine(QWidget* parent, FilterPtr filter, QButtonGroup* buttonGroup) :
47  BaseWidget(parent, "PipelineWidgetFilterLine", "PipelineWidgetFilterLine"),
48  mFilter(filter)
49 {
50  QHBoxLayout* layout = new QHBoxLayout(this);
51  connect(this, SIGNAL(requestRunFilter()), this, SLOT(requestRunFilterSlot()));
52 
53  mRadioButton = new QRadioButton(this);
54  buttonGroup->addButton(mRadioButton);
55  connect(mRadioButton, SIGNAL(toggled(bool)), this, SLOT(radioButtonSelectedSlot(bool)));
56  layout->addWidget(mRadioButton);
57  layout->setMargin(0);
58  layout->setSpacing(2);
59 
60  mAlgoNameLabel = new QLabel(QString("<b>%1</b>").arg(mFilter->getName()), this);
61  mAlgoNameLabel->setToolTip(mFilter->getHelp());
62  layout->addWidget(mAlgoNameLabel);
63 
66  layout->addWidget(mTimedAlgorithmProgressBar, 1);
67 
68  mAction = this->createAction(this,
69  QIcon(":/icons/open_icon_library/arrow-right-3.png"),
70  "Run Filter", "",
71  SIGNAL(requestRunFilter()),
72  NULL);
73  mAction->setData(mFilter->getUid());
74 
75  CXSmallToolButton* button = new CXSmallToolButton();
76  button->setObjectName("RunFilterButton");
77  button->setDefaultAction(mAction);
78  layout->addWidget(button);
79 
80 }
81 
82 void PipelineWidgetFilterLine::requestRunFilterSlot()
83 {
84  mRadioButton->setChecked(true);
85 }
86 
87 void PipelineWidgetFilterLine::radioButtonSelectedSlot(bool on)
88 {
89  if (!on)
90  return;
91 
92  emit filterSelected(mFilter->getUid());
93 }
94 
96 {
97  QWidget::mousePressEvent(event);
98 
99  mRadioButton->setChecked(true);
100 }
101 
103 {
104  return QString("");
105 }
106 
110 
111 PipelineWidget::PipelineWidget(VisualizationServicePtr visualizationService, PatientModelServicePtr patientModelService, QWidget* parent, PipelinePtr pipeline) :
112  BaseWidget(parent, "PipelineWidget", "Pipeline"),
113  mPipeline(pipeline)
114 {
115  FilterGroupPtr filters = mPipeline->getFilters();
116  std::vector<SelectDataStringPropertyBasePtr> nodes = mPipeline->getNodes();
117  if (filters->size()+1 != nodes.size())
118  reportError("Filter/Node mismatch");
119 
120  QVBoxLayout* topLayout = new QVBoxLayout(this);
121  mButtonGroup = new QButtonGroup(this);
122 
123  struct Inner
124  {
125  static QHBoxLayout* addHMargin(QWidget* base)
126  {
127  QHBoxLayout* layout = new QHBoxLayout;
128  layout->addWidget(base);
129  layout->setContentsMargins(4,0,4,0);
130  return layout;
131  }
132  };
133 
134  for (unsigned i=0; i<filters->size(); ++i)
135  {
136  topLayout->addLayout(Inner::addHMargin(new DataSelectWidget(visualizationService, patientModelService, this, nodes[i])));
137 
138  PipelineWidgetFilterLine* algoLine = new PipelineWidgetFilterLine(this, filters->get(i), mButtonGroup);
139  connect(algoLine, SIGNAL(requestRunFilter()), this, SLOT(runFilterSlot()));
140  connect(algoLine, SIGNAL(filterSelected(QString)), this, SLOT(filterSelectedSlot(QString)));
141  algoLine->mTimedAlgorithmProgressBar->attach(mPipeline->getTimedAlgorithm(filters->get(i)->getUid()));
142 
143  mAlgoLines.push_back(algoLine);
144  QFrame* frame = this->wrapInFrame(algoLine);
145  frame->layout()->setContentsMargins(4,4,4,4); // nice on linux
146  frame->setObjectName("FilterBackground");
147  topLayout->addWidget(frame);
148  }
149  topLayout->addLayout(Inner::addHMargin(new DataSelectWidget(visualizationService, patientModelService, this, nodes.back())));
150 
151  topLayout->addSpacing(12);
152 
153  mSetupWidget = new CompactFilterSetupWidget(visualizationService, patientModelService, this, filters->getOptions(), true);
154  topLayout->addWidget(mSetupWidget);
155 
156  topLayout->addStretch();
157 
158  this->filterSelectedSlot(filters->get(0)->getUid());
159 }
160 
161 
162 void PipelineWidget::filterSelectedSlot(QString uid)
163 {
164  FilterPtr filter = mPipeline->getFilters()->get(uid);
165  mSetupWidget->setFilter(filter);
166 
167  for (unsigned i=0; i<mAlgoLines.size(); ++i)
168  if (mAlgoLines[i]->mFilter->getUid()==uid)
169  mAlgoLines[i]->mRadioButton->setChecked(true);
170 }
171 
172 void PipelineWidget::runFilterSlot()
173 {
174  PipelineWidgetFilterLine* line = dynamic_cast<PipelineWidgetFilterLine*>(sender());
175 
176  if (!line)
177  return;
178 
179  mPipeline->execute(line->mFilter->getUid());
180 }
181 
183 {
184  return QString("<html>"
185  "<h3>Pipeline Widget.</h3>"
186  "<p>Run a series of filters.</p>"
187  "</html>");
188 }
189 
190 
191 } // namespace cx
void reportError(QString msg)
Definition: cxLogger.cpp:92
Helper widget for displaying the input/output/options part of a Filter. Intended to be included in ot...
Show progress for a TimedBaseAlgorithm.
QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
QAction * createAction(QObject *parent, QIcon iconName, QString text, QString tip, T slot, QLayout *layout=NULL, QToolButton *button=new QToolButton())
Definition: cxBaseWidget.h:130
PipelineWidget(VisualizationServicePtr visualizationService, PatientModelServicePtr patientModelService, QWidget *parent, PipelinePtr pipeline)
QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
boost::shared_ptr< class Filter > FilterPtr
boost::shared_ptr< class VisualizationService > VisualizationServicePtr
Definition: cxRegServices.h:43
CXFrame * wrapInFrame(QWidget *base)
virtual void mousePressEvent(QMouseEvent *event)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
boost::shared_ptr< FilterGroup > FilterGroupPtr
Definition: cxFilterGroup.h:86
void attach(TimedAlgorithmPtr algorithm)
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
TimedAlgorithmProgressBar * mTimedAlgorithmProgressBar
PipelineWidgetFilterLine(QWidget *parent, FilterPtr filter, QButtonGroup *buttonGroup)
void filterSelected(QString uid)
boost::shared_ptr< Pipeline > PipelinePtr
Definition: cxPipeline.h:167