GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoModesManagerWidget.cxx
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  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  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 #include "QGoModesManagerWidget.h"
35 #include <QLabel>
36 #include <QColor>
37 
38 QGoModesManagerWidget::QGoModesManagerWidget(std::vector<QString> iVectChannels,
39  QStringList iListTimePoints, QWidget *iParent)
40  :QWidget(iParent), m_ManualModeManager(NULL)
41 {
42  this->Initialize(iVectChannels, iListTimePoints);
43 }
44 //-------------------------------------------------------------------------
45 
46 //-------------------------------------------------------------------------
48 {
49 }
50 //-------------------------------------------------------------------------
51 
52 //-------------------------------------------------------------------------
53 void QGoModesManagerWidget::Initialize(std::vector<QString> iVectChannels,
54  QStringList iListTimePoints)
55 {
56  this->m_ModeAlreadyCleaned = false;
57  this->m_VBoxLayout = new QVBoxLayout;
58  this->m_ModeComboBox = new QComboBox(this);
59 
60  QHBoxLayout* ModeLayout = new QHBoxLayout;
61  QLabel* ModeLabel = new QLabel(tr("Mode:"), this);
62  ModeLayout->addWidget(ModeLabel);
63  ModeLayout->addWidget(this->m_ModeComboBox);
64 
65  this->m_VBoxLayout->addLayout(ModeLayout);
66 
67  this->m_ModeWidgets = new QStackedWidget;
68  this->m_VBoxLayout->addWidget(this->m_ModeWidgets);
69 
70  this->setLayout(this->m_VBoxLayout);
71  this->m_VBoxLayout->setSizeConstraint(QLayout::SetFixedSize);
72 
73  //add default modes:
74  this->m_SemiAutoAlgoManagerWidget = new
75  QGoAlgorithmsManagerWidget("SemiAutomatic", this, iVectChannels,
76  iListTimePoints);
78 
79  this->m_AutoAlgoManagerWidget = new
80  QGoAlgorithmsManagerWidget("Automatic",this, iVectChannels,
81  iListTimePoints);
83 
84  m_ModesWhoNeedSeeds.append("SemiAutomatic");
85  m_ModesWhoNeedSeeds.append("Automatic");
86 
87  QObject::connect(this->m_ModeComboBox, SIGNAL(activated(int)),
88  this, SLOT(SetTheRightMode(int)));
89 
91  this, SIGNAL(ResetClicked() ) );
92 
94  this, SIGNAL(ResetClicked() ) );
95 
96 }
97 //-------------------------------------------------------------------------
98 
99 //-------------------------------------------------------------------------
101  std::string iModeName, QWidget* iWidget, bool ModeNeedSeeds )
102 {
103  int Index = 0;
104  if (iWidget != 0)
105  {
106  this->m_ModeWidgets->addWidget(iWidget);
107  Index = this->m_ModeWidgets->indexOf(iWidget);
108  }
109  this->m_ModeComboBox->insertItem(Index,iModeName.c_str());
110 
111  if (ModeNeedSeeds)
112  {
113  this->m_ModesWhoNeedSeeds.append(iModeName.c_str() );
114  }
115 }
116 //-------------------------------------------------------------------------
117 
118 //-------------------------------------------------------------------------
120  QGoAlgorithmsManagerWidget* iAlgoManagerWidget, bool ModeNeedSeeds,
121  int iDefaultIndex)
122 {
123  this->AddWidgetWithModeName(iAlgoManagerWidget->GetModeName(),
124  iAlgoManagerWidget, ModeNeedSeeds);
125  iAlgoManagerWidget->SetCurrentIndex(iDefaultIndex);
126 }
127 //-------------------------------------------------------------------------
128 
129 //-------------------------------------------------------------------------
131 {
132  if (!this->m_AutoAlgoManagerWidget->HasMethod())
133  {
134  this->m_ModeComboBox->removeItem(
135  this->m_ModeComboBox->findText("Automatic") );
137  }
139  {
140  this->m_ModeComboBox->removeItem(
141  this->m_ModeComboBox->findText("SemiAutomatic") );
143  }
144 }
145 //-------------------------------------------------------------------------
146 
147 //-------------------------------------------------------------------------
149  QGoAlgorithmWidget* iAlgoWidget)
150 {
151  this->m_SemiAutoAlgoManagerWidget->AddMethod(iAlgoWidget);
152 }
153 //-------------------------------------------------------------------------
154 
155 //-------------------------------------------------------------------------
157  QGoAlgorithmWidget* iAlgoWidget)
158 {
159  this->m_AutoAlgoManagerWidget->AddMethod(iAlgoWidget);
160 }
161 //-------------------------------------------------------------------------
162 
163 //-------------------------------------------------------------------------
165  QStringList iListTimePoint, bool ModeNeedSeeds)
166 {
167  std::vector<QString> Channels = std::vector<QString>();
169  "Manual",this, Channels, iListTimePoint, true, false);
170  this->m_ManualModeManager->AddWidgetForOnlyOneMethod(iWidget);
171  this->AddAlgoManagerWidget(this->m_ManualModeManager, ModeNeedSeeds);
172 }
173 //-------------------------------------------------------------------------
174 
175 //-------------------------------------------------------------------------
177 {
178  QGoAlgorithmsManagerWidget* CurrentWidget =
179  dynamic_cast<QGoAlgorithmsManagerWidget*>
180  (this->m_ModeWidgets->currentWidget());
181  return CurrentWidget->GetCurrentImageName();
182 }
183 //-------------------------------------------------------------------------
184 
185 //-------------------------------------------------------------------------
187 {
188  QGoAlgorithmsManagerWidget* CurrentWidget =
189  dynamic_cast<QGoAlgorithmsManagerWidget*>
190  (this->m_ModeWidgets->currentWidget());
191  return CurrentWidget->GetSelectedTimePoint();
192 }
193 //-------------------------------------------------------------------------
194 
195 //-------------------------------------------------------------------------
197 {
198  QGoAlgorithmsManagerWidget* CurrentWidget =
199  dynamic_cast<QGoAlgorithmsManagerWidget*>
200  (this->m_ModeWidgets->currentWidget());
201  return CurrentWidget->IsInvertChecked();
202 }
203 //-------------------------------------------------------------------------
204 
205 //-------------------------------------------------------------------------
207 {
209  {
210  this->CheckDefaultModes();
211  m_ModeAlreadyCleaned = true;
212  }
213 
214  if (iIndex != -1)
215  {
216  this->m_ModeWidgets->setCurrentIndex(iIndex);
217  }
218 
219  if (this->m_ModesWhoNeedSeeds.indexOf(
220  this->m_ModeComboBox->currentText() ) != -1)
221  {
222  emit SetSeedInteractorBehaviour(true);
223  }
224  else
225  {
226  emit SetSeedInteractorBehaviour(false);
227  }
228 }
229 //-------------------------------------------------------------------------
230 
231 //-------------------------------------------------------------------------
233 {
234  this->m_AutoAlgoManagerWidget->SetTSliceForClassicView(tr("%1").arg(iTimePoint) );
235  this->m_SemiAutoAlgoManagerWidget->SetTSliceForClassicView(tr("%1").arg(iTimePoint) );
236  if (this->m_ManualModeManager)
237  {
238  this->m_ManualModeManager->SetTSliceForClassicView(tr("%1").arg(iTimePoint) );
239  }
240 
241 }
242 //-------------------------------------------------------------------------
243 
244 //-------------------------------------------------------------------------
246  QHash<QString, QColor> iListTimePoints, int iChannelNumber)
247 {
249  iListTimePoints, iChannelNumber);
251  iListTimePoints, iChannelNumber);
252  if (this->m_ManualModeManager)
253  {
255  iListTimePoints, iChannelNumber);
256  }
257 }
258 //-------------------------------------------------------------------------
259 
260 //-------------------------------------------------------------------------
262 {
263  return this->m_ModeComboBox->currentText().toStdString();
264 }