CustusX  2023.01.05-dev+develop.0da12
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxPipelineWidget.h"
13 #include "cxHelperWidgets.h"
14 
16 #include <QtWidgets>
17 #include "cxLogger.h"
18 #include "cxTypeConversions.h"
19 #include "cxDataSelectWidget.h"
20 #include "cxSettings.h"
21 
22 namespace cx
23 {
24 
25 PipelineWidgetFilterLine::PipelineWidgetFilterLine(QWidget* parent, FilterPtr filter, QButtonGroup* buttonGroup) :
26  BaseWidget(parent, "PipelineWidgetFilterLine", "PipelineWidgetFilterLine"),
27  mFilter(filter)
28 {
29  QHBoxLayout* layout = new QHBoxLayout(this);
30  connect(this, SIGNAL(requestRunFilter()), this, SLOT(requestRunFilterSlot()));
31 
32  mRadioButton = new QRadioButton(this);
33  buttonGroup->addButton(mRadioButton);
34  connect(mRadioButton, SIGNAL(toggled(bool)), this, SLOT(radioButtonSelectedSlot(bool)));
35  layout->addWidget(mRadioButton);
36  layout->setMargin(0);
37  layout->setSpacing(2);
38 
39  mAlgoNameLabel = new QLabel(QString("<b>%1</b>").arg(mFilter->getName()), this);
40  mAlgoNameLabel->setToolTip(mFilter->getHelp());
41  layout->addWidget(mAlgoNameLabel);
42 
45  layout->addWidget(mTimedAlgorithmProgressBar, 1);
46 
47  mAction = this->createAction(this,
48  QIcon(":/icons/open_icon_library/arrow-right-3.png"),
49  "Run Filter", "",
50  SIGNAL(requestRunFilter()),
51  NULL);
52  mAction->setData(mFilter->getUid());
53 
54  CXSmallToolButton* button = new CXSmallToolButton();
55  button->setObjectName("RunFilterButton");
56  button->setDefaultAction(mAction);
57  layout->addWidget(button);
58 
59 }
60 
61 void PipelineWidgetFilterLine::requestRunFilterSlot()
62 {
63  mRadioButton->setChecked(true);
64 }
65 
66 void PipelineWidgetFilterLine::radioButtonSelectedSlot(bool on)
67 {
68  if (!on)
69  return;
70 
71  emit filterSelected(mFilter->getUid());
72 }
73 
75 {
76  QWidget::mousePressEvent(event);
77 
78  mRadioButton->setChecked(true);
79 }
80 
84 
85 PipelineWidget::PipelineWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget* parent, PipelinePtr pipeline) :
86  BaseWidget(parent, "PipelineWidget", "Pipeline"),
87  mPipeline(pipeline)
88 {
89  this->setToolTip("Run a series of filters");
90  FilterGroupPtr filters = mPipeline->getFilters();
91  std::vector<SelectDataStringPropertyBasePtr> nodes = mPipeline->getNodes();
92  if (filters->size()+1 != nodes.size())
93  reportError("Filter/Node mismatch");
94 
95  QVBoxLayout* topLayout = new QVBoxLayout(this);
96  mButtonGroup = new QButtonGroup(this);
97 
98  struct Inner
99  {
100  static QHBoxLayout* addHMargin(QWidget* base)
101  {
102  QHBoxLayout* layout = new QHBoxLayout;
103  layout->addWidget(base);
104  layout->setContentsMargins(4,0,4,0);
105  return layout;
106  }
107  };
108 
109  for (unsigned i=0; i<filters->size(); ++i)
110  {
111  topLayout->addLayout(Inner::addHMargin(new DataSelectWidget(viewService, patientModelService, this, nodes[i])));
112 
113  PipelineWidgetFilterLine* algoLine = new PipelineWidgetFilterLine(this, filters->get(i), mButtonGroup);
114  connect(algoLine, SIGNAL(requestRunFilter()), this, SLOT(runFilterSlot()));
115  connect(algoLine, SIGNAL(filterSelected(QString)), this, SLOT(filterSelectedSlot(QString)));
116  algoLine->mTimedAlgorithmProgressBar->attach(mPipeline->getTimedAlgorithm(filters->get(i)->getUid()));
117 
118  mAlgoLines.push_back(algoLine);
119  QFrame* frame = this->wrapInFrame(algoLine);
120  frame->layout()->setContentsMargins(4,4,4,4); // nice on linux
121  frame->setObjectName("FilterBackground");
122  topLayout->addWidget(frame);
123  }
124  topLayout->addLayout(Inner::addHMargin(new DataSelectWidget(viewService, patientModelService, this, nodes.back())));
125 
126  topLayout->addSpacing(12);
127 
128  mSetupWidget = new CompactFilterSetupWidget(viewService, patientModelService, this, filters->getOptions(), true);
129  topLayout->addWidget(mSetupWidget);
130 
131  topLayout->addStretch();
132 
133  this->filterSelectedSlot(filters->get(0)->getUid());
134 }
135 
136 
137 void PipelineWidget::filterSelectedSlot(QString uid)
138 {
139  FilterPtr filter = mPipeline->getFilters()->get(uid);
140  mSetupWidget->setFilter(filter);
141 
142  for (unsigned i=0; i<mAlgoLines.size(); ++i)
143  if (mAlgoLines[i]->mFilter->getUid()==uid)
144  mAlgoLines[i]->mRadioButton->setChecked(true);
145 }
146 
147 void PipelineWidget::runFilterSlot()
148 {
149  PipelineWidgetFilterLine* line = dynamic_cast<PipelineWidgetFilterLine*>(sender());
150 
151  if (!line)
152  return;
153 
154  mPipeline->execute(line->mFilter->getUid());
155 }
156 
157 
158 } // namespace cx
void reportError(QString msg)
Definition: cxLogger.cpp:71
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:129
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:65
void attach(TimedAlgorithmPtr algorithm)
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
TimedAlgorithmProgressBar * mTimedAlgorithmProgressBar
PipelineWidgetFilterLine(QWidget *parent, FilterPtr filter, QButtonGroup *buttonGroup)
void filterSelected(QString uid)
Namespace for all CustusX production code.
boost::shared_ptr< Pipeline > PipelinePtr
Definition: cxPipeline.h:146