Fraxinus  16.5.0-fx-rc1
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 
105 
107  BaseWidget(parent, "PipelineWidget", "Pipeline"),
108  mPipeline(pipeline)
109 {
110  this->setToolTip("Run a series of filters");
111  FilterGroupPtr filters = mPipeline->getFilters();
112  std::vector<SelectDataStringPropertyBasePtr> nodes = mPipeline->getNodes();
113  if (filters->size()+1 != nodes.size())
114  reportError("Filter/Node mismatch");
115 
116  QVBoxLayout* topLayout = new QVBoxLayout(this);
117  mButtonGroup = new QButtonGroup(this);
118 
119  struct Inner
120  {
121  static QHBoxLayout* addHMargin(QWidget* base)
122  {
123  QHBoxLayout* layout = new QHBoxLayout;
124  layout->addWidget(base);
125  layout->setContentsMargins(4,0,4,0);
126  return layout;
127  }
128  };
129 
130  for (unsigned i=0; i<filters->size(); ++i)
131  {
132  topLayout->addLayout(Inner::addHMargin(new DataSelectWidget(viewService, patientModelService, this, nodes[i])));
133 
134  PipelineWidgetFilterLine* algoLine = new PipelineWidgetFilterLine(this, filters->get(i), mButtonGroup);
135  connect(algoLine, SIGNAL(requestRunFilter()), this, SLOT(runFilterSlot()));
136  connect(algoLine, SIGNAL(filterSelected(QString)), this, SLOT(filterSelectedSlot(QString)));
137  algoLine->mTimedAlgorithmProgressBar->attach(mPipeline->getTimedAlgorithm(filters->get(i)->getUid()));
138 
139  mAlgoLines.push_back(algoLine);
140  QFrame* frame = this->wrapInFrame(algoLine);
141  frame->layout()->setContentsMargins(4,4,4,4); // nice on linux
142  frame->setObjectName("FilterBackground");
143  topLayout->addWidget(frame);
144  }
145  topLayout->addLayout(Inner::addHMargin(new DataSelectWidget(viewService, patientModelService, this, nodes.back())));
146 
147  topLayout->addSpacing(12);
148 
149  mSetupWidget = new CompactFilterSetupWidget(viewService, patientModelService, this, filters->getOptions(), true);
150  topLayout->addWidget(mSetupWidget);
151 
152  topLayout->addStretch();
153 
154  this->filterSelectedSlot(filters->get(0)->getUid());
155 }
156 
157 
158 void PipelineWidget::filterSelectedSlot(QString uid)
159 {
160  FilterPtr filter = mPipeline->getFilters()->get(uid);
161  mSetupWidget->setFilter(filter);
162 
163  for (unsigned i=0; i<mAlgoLines.size(); ++i)
164  if (mAlgoLines[i]->mFilter->getUid()==uid)
165  mAlgoLines[i]->mRadioButton->setChecked(true);
166 }
167 
168 void PipelineWidget::runFilterSlot()
169 {
170  PipelineWidgetFilterLine* line = dynamic_cast<PipelineWidgetFilterLine*>(sender());
171 
172  if (!line)
173  return;
174 
175  mPipeline->execute(line->mFilter->getUid());
176 }
177 
178 
179 } // namespace cx
void reportError(QString msg)
Definition: cxLogger.cpp:92
PipelineWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PipelinePtr pipeline)
Helper widget for displaying the input/output/options part of a Filter. Intended to be included in ot...
boost::shared_ptr< class ViewService > ViewServicePtr
Show progress for a TimedBaseAlgorithm.
QAction * createAction(QObject *parent, QIcon iconName, QString text, QString tip, T slot, QLayout *layout=NULL, QToolButton *button=new QToolButton())
Definition: cxBaseWidget.h:149
boost::shared_ptr< class Filter > FilterPtr
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
cxLogicManager_EXPORT ViewServicePtr viewService()
TimedAlgorithmProgressBar * mTimedAlgorithmProgressBar
PipelineWidgetFilterLine(QWidget *parent, FilterPtr filter, QButtonGroup *buttonGroup)
void filterSelected(QString uid)
boost::shared_ptr< Pipeline > PipelinePtr
Definition: cxPipeline.h:167