GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoDBTraceManager.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 
35 #include "QGoDBTraceManager.h"
36 #include <iostream>
37 #include <sstream>
38 #include <QMenu>
39 #include <QMessageBox>
40 
42  QObject(iParent), m_SelectedCollectionData(NULL),
43  m_SelectedColorData(NULL), m_CurrentTimePoint(NULL), m_Table(NULL),
44  m_CollectionOfTraces(NULL), m_DatabaseConnector(NULL),
45  m_IsColorCodingOn(false), m_IsShowOnlyCurrentTimePointOn(false)
46 {
47 }
48 //-------------------------------------------------------------------------
49 
50 //-------------------------------------------------------------------------
52 {
53  if ( this->m_CollectionOfTraces )
54  {
55  delete this->m_CollectionOfTraces;
56  }
57 }
58 //-------------------------------------------------------------------------
59 
60 //-------------------------------------------------------------------------
61 void QGoDBTraceManager::SetInfo(unsigned int iImgSessionID, QWidget *iParent)
62 {
64  this->m_TraceNameID = this->GetTheNameIDFromName(this->m_TraceName);
67 
69  this->m_TraceName,
70  this->m_CollectionOf,
71  iImgSessionID);
72 
73  this->m_Table = new QGoTableWidget(iParent);
74  QObject::connect( this->m_Table, SIGNAL( CheckedRowsChanged(int) ),
75  this, SLOT( UpdateHighlightedElementsInVisuContainer(int) ) );
76  QObject::connect( this->m_Table, SIGNAL( VisibleRowsChanged(int) ),
77  this, SLOT( UpdateVisibleElementsInVisuContainer(int) ) );
78 
79  QObject::connect( this->m_Table, SIGNAL(customContextMenuRequested (const QPoint &) ),
80  this, SLOT( CreateContextMenu ( const QPoint &) ) );
81 
82  this->m_ImgSessionID = iImgSessionID;
83 }
84 
85 //-------------------------------------------------------------------------
86 
87 //-------------------------------------------------------------------------
88 std::string QGoDBTraceManager::GetTheNameIDFromName(std::string iName)
89 {
90  std::string oNameID = iName;
91 
92  oNameID += "ID";
93  return oNameID;
94 }
95 
96 //-------------------------------------------------------------------------
97 
98 //-------------------------------------------------------------------------
100 {
101  return this->m_Table;
102 }
103 
104 //-------------------------------------------------------------------------
105 
106 //-------------------------------------------------------------------------
108  vtkMySQLDatabase *iDatabaseConnector)
109 {
110  return MaxValueForOneColumnInTable( iDatabaseConnector,
111  this->m_TraceNameID, this->m_TraceName, "ImagingSessionID",
112  ConvertToString< unsigned int >(this->m_ImgSessionID) );
113 }
114 
115 //-------------------------------------------------------------------------
116 
117 //-------------------------------------------------------------------------
119 {
120  QMenu *ContextMenu = new QMenu;
121 
122  this->AddActionsContextMenu(ContextMenu);
123  ContextMenu->exec( this->m_Table->mapToGlobal(iPos) );
124 }
125 
126 //-------------------------------------------------------------------------
127 
128 //-------------------------------------------------------------------------
130 {
131  this->AddGeneralActionsContextMenu(iMenu);
132 }
133 
134 //-------------------------------------------------------------------------
135 
136 //-------------------------------------------------------------------------
138 {
139  m_CheckedTracesMenu = new QMenu( tr("With the checked %1s").arg( this->m_TraceName.c_str() ) );
140  m_CheckedTracesMenu->addAction( tr("Delete them"),
141  this, SLOT( DeleteTracesFromContextMenu() ) );
142  //m_CheckedTracesMenu->addAction( tr("Add to selected %1 %2").arg(
143  // this->m_CollectionName.c_str() )
144  // .arg(this->m_SelectedCollectionData->first.c_str()),
145  // this, SLOT( AddToSelectedCollection() ) );
146  m_CheckedTracesMenu->addAction( tr("Change their color to the selected one : %1")
147  .arg( this->m_SelectedColorData->first.c_str() ),
148  this, SLOT( ChangeTraceColor() ) );
149  iMenu->addAction( this->m_CheckedTracesMenu->menuAction() );
150 
151  QMenu *SelectedTracesMenu = new QMenu( tr("With the selected %1s").arg( this->m_TraceName.c_str() ) );
152  SelectedTracesMenu->addAction( tr("Check the selected %1s")
153  .arg( this->m_TraceName.c_str() ), this, SLOT( CheckSelectedRows() ) );
154  SelectedTracesMenu->addAction( tr("Uncheck the selected %1s")
155  .arg( this->m_TraceName.c_str() ), this, SLOT( UncheckSelectedRows() ) );
156  SelectedTracesMenu->addAction( tr("Show the selected %1s")
157  .arg( this->m_TraceName.c_str() ), this, SLOT( ShowSelectedRows() ) );
158  SelectedTracesMenu->addAction( tr("Hide the selected %1s")
159  .arg( this->m_TraceName.c_str() ), this, SLOT( HideSelectedRows() ) );
160 
161  iMenu->addAction( SelectedTracesMenu->menuAction() );
162 
163  QMenu *ColorMenu = new QMenu( tr("Change color of your %1s").arg( this->m_TraceName.c_str() ) );
164 
165  ColorMenu->addAction( tr("To the selected color for the checked %1s")
166  .arg( this->m_TraceName.c_str() ),
167  this, SLOT( ChangeTraceColor() ) );
168 
169  QAction *ColorCoding = new QAction(tr("Based on the selected column"), ColorMenu);
170  ColorCoding->setCheckable(true);
171  ColorCoding->setChecked(m_IsColorCodingOn);
172  QObject::connect( ColorCoding, SIGNAL( triggered (bool) ), this, SLOT( SetColorCoding(bool) ) );
173  ColorMenu->addAction(ColorCoding);
174  iMenu->addAction( ColorMenu->menuAction() );
175 
176  iMenu->addAction( tr("Copy Selection"),
177  this->m_Table, SLOT( CopySelection() ) );
178  iMenu->addAction( tr("Copy table"), this->m_Table, SLOT( CopyTable() ) );
179 }
180 
181 //-------------------------------------------------------------------------
182 
183 //-------------------------------------------------------------------------
185 {
187  //for the time being, as we don't use lineages
188  iMenu->addAction( tr("Go to this %1")
189  .arg( this->m_TraceName.c_str() ),
190  this, SLOT( GoToTheTrace() ) );
191  QAction *ShowCurrentTimePoint = new QAction(tr("Show only in the table the %1 for the current timepoint")
192  .arg( this->m_TraceName.c_str() ), iMenu);
193  ShowCurrentTimePoint->setCheckable(true);
194  ShowCurrentTimePoint->setChecked(this->m_IsShowOnlyCurrentTimePointOn);
195  QObject::connect( ShowCurrentTimePoint,
196  SIGNAL( triggered (bool) ),
197  this,
198  SLOT( ShowOnlyRowsForCurrentTimePoint(bool) ) );
199  iMenu->addAction(ShowCurrentTimePoint);
202 }
203 
204 //-------------------------------------------------------------------------
205 
206 //------------------------------------------------------------------------
208 {
209  this->m_CheckedTracesMenu->addAction( tr("Add to selected %1 %2")
210  .arg( this->m_CollectionName.c_str() )
211  .arg( this->m_SelectedCollectionData->first.c_str() ),
212  this, SLOT( AddToSelectedCollection() ) );
213 
214  this->m_CheckedTracesMenu->addAction( tr("Create a new %1 from checked %2s")
215  .arg( this->m_CollectionName.c_str() )
216  .arg( this->m_TraceName.c_str() ),
217  this, SLOT( CreateCorrespondingCollection() ) );
218 }
219 
220 //-------------------------------------------------------------------------
221 
222 //-------------------------------------------------------------------------
224 {
226  this->m_TraceNameID, Qt::Checked);
227 }
228 
229 //-------------------------------------------------------------------------
230 
231 //------------------------------------------------------------------------
233 {
235  this->m_TraceNameID, Qt::Unchecked);
236 }
237 
238 //-------------------------------------------------------------------------
239 
240 //------------------------------------------------------------------------
242 {
244  this->m_TraceNameID, Qt::Checked);
245 }
246 
247 //-------------------------------------------------------------------------
248 
249 //------------------------------------------------------------------------
251 {
253  this->m_TraceNameID, Qt::Unchecked);
254 }
255 
256 //-------------------------------------------------------------------------
257 
258 //------------------------------------------------------------------------
260 {
261  //as it impacts also the collectionof, a signal has to be emitted:
262  //but not for contourManager (no collectionof) where ChangeTraceColor()
263  //is then reimplemented
264  emit TraceColorToChange();
265 }
266 
267 //-------------------------------------------------------------------------
268 
269 //------------------------------------------------------------------------
270 std::list< unsigned int >
272  vtkMySQLDatabase *iDatabaseConnector,
273  const std::list< unsigned int > & iListTraces)
274 {
276  iDatabaseConnector, iListTraces);
277 }
278 
279 //-------------------------------------------------------------------------
280 
281 //------------------------------------------------------------------------
282 std::list< unsigned int >
284  vtkMySQLDatabase *iDatabaseConnector,
285  const std::list< unsigned int > & iListCollectionIDs)
286 {
287  return this->m_CollectionOfTraces->GetTraceIDsBelongingToCollectionID(iDatabaseConnector,
288  iListCollectionIDs);
289 }
290 
291 //-------------------------------------------------------------------------
292 
293 //------------------------------------------------------------------------
294 void
296 DisplayInfoForExistingTraces(vtkMySQLDatabase * iDatabaseConnector,
297  const std::list< unsigned int > & iListTraces)
298 {
299  this->m_Table->setSortingEnabled(false);
300  std::list< unsigned int >::const_iterator iter = iListTraces.begin();
301  while ( iter != iListTraces.end() )
302  {
303  this->DisplayInfoForExistingTrace(iDatabaseConnector, *iter);
304  ++iter;
305  }
306  this->m_Table->setSortingEnabled(true);
307 }
308 
309 //-------------------------------------------------------------------------
310 
311 //------------------------------------------------------------------------
313  const std::list<unsigned int> & iListTracesIDToDelete)
314 {
315 
316  if ( iListTracesIDToDelete.empty() )
317  {
318  QMessageBox msgBox;
319  msgBox.setText(
320  tr("Please check at least one %1 to be deleted")
321  .arg( this->m_TraceName.c_str() ) );
322  msgBox.exec();
323  return false;
324  }
325  else
326  {
327  switch( QMessageBox::warning(this->m_Table, tr(""),
328  tr("Are you sure you want to delete\n"
329  "permanently the selected %1s?").arg( this->m_TraceName.c_str() ),
330  QMessageBox::Yes | QMessageBox::No,
331  QMessageBox::No))
332  {
333  case QMessageBox::Yes:
334  return true;
335  case QMessageBox::No:
336  return false;
337  default:
338  return false;
339  }
340  }
341 }
342 //-------------------------------------------------------------------------
343 
344 //------------------------------------------------------------------------
346 {
347  std::list< unsigned int > ListTracesIDToDelete =
348  this->GetListHighlightedIDs();
349 
350  if (this->CheckThatThereAreTracesToDelete(ListTracesIDToDelete) )
351  {
352  //as it impacts also on the collection and the collectionOf,
353  //a signal has to be emitted for another traceManager:
354  emit CheckedTracesToDelete();
355  }
356 }
357 
358 //-------------------------------------------------------------------------
359 
360 //------------------------------------------------------------------------
361 void
362 QGoDBTraceManager::UpdateCollectionID(vtkMySQLDatabase *iDatabaseConnector,
363  const std::list< unsigned int > & iListTracesIDs,
364  int iCollectionID)
365 {
367  iCollectionID, iDatabaseConnector);
368  this->DisplayInfoForExistingTraces(iDatabaseConnector, iListTracesIDs);
369 }
370 
371 //-------------------------------------------------------------------------
372 
373 //------------------------------------------------------------------------
374 std::list< unsigned int >
376  vtkMySQLDatabase *iDatabaseConnector,
377  const std::list< unsigned int > & iListTracesIDs)
378 {
380  iDatabaseConnector, iListTracesIDs);
381 }
382 
383 //-------------------------------------------------------------------------
384 
385 //------------------------------------------------------------------------
386 void
387 QGoDBTraceManager::UpdateBoundingBoxes(vtkMySQLDatabase *iDatabaseConnector,
388  const std::list< unsigned int > & iListTracesIDs,
389  bool UpdateTW)
390 {
391  this->m_CollectionOfTraces->RecalculateDBBoundingBox(iDatabaseConnector, iListTracesIDs);
392 
393  if ( UpdateTW )
394  {
395  this->DisplayInfoForExistingTraces(iDatabaseConnector, iListTracesIDs);
396  }
397 }
398 
399 //-------------------------------------------------------------------------
400 
401 //------------------------------------------------------------------------
403 {
404  qreal r, g, b, a;
405 
406  iColor.getRgbF(&r, &g, &b, &a);
407  double *rgba = new double[4];
408  rgba[0] = static_cast< double >( r );
409  rgba[1] = static_cast< double >( g );
410  rgba[2] = static_cast< double >( b );
411  rgba[3] = static_cast< double >( a );
412  return rgba;
413 }
414 
415 //-------------------------------------------------------------------------
416 
417 //------------------------------------------------------------------------
418 std::list< QGoDBTraceManager::NameWithColorData >
420  vtkMySQLDatabase *iDatabaseConnector, std::string & ioIDToSelect)
421 {
422  ioIDToSelect = this->m_LastSelectedTraceAsCollection;
423 
425  iDatabaseConnector);
426 }
427 
428 //-------------------------------------------------------------------------
429 
430 //------------------------------------------------------------------------
431 void QGoDBTraceManager::CheckTheTraceInTW(unsigned int iTraceID,
432  Qt::CheckState iState)
433 {
434  this->m_Table->SetCheckStateForTraceID(iTraceID,
435  this->m_TraceName, iState, false);
436 }
437 
438 //-------------------------------------------------------------------------
439 
440 //------------------------------------------------------------------------
441 void QGoDBTraceManager::ShowTheTraceInTW(unsigned int iTraceID,
442  Qt::CheckState iState)
443 {
444  this->m_Table->SetVisibleStateForTraceID(iTraceID,
445  this->m_TraceName, iState, false);
446 }
447 
448 //-------------------------------------------------------------------------
449 
450 //------------------------------------------------------------------------
452 {
453  std::list< unsigned int > ListCheckedTraces =
454  this->GetListHighlightedIDs();
455  if ( ListCheckedTraces.size() != 1 )
456  {
457  QMessageBox msgBox;
458  msgBox.setText(
459  tr("Please select one and only one %1 to go to")
460  .arg( this->m_TraceName.c_str() ) );
461  msgBox.exec();
462  return;
463  }
464  GoDBCoordinateRow CoordCenter =
465  this->m_Table->GetCoordinateCenterBoundingBox(ListCheckedTraces.front(),
466  this->m_TraceName);
467 
468  emit NeedToGoToTheLocation( CoordCenter.GetMapValue<int>("XCoord"),
469  CoordCenter.GetMapValue<int>("YCoord"),
470  CoordCenter.GetMapValue<int>("ZCoord"),
471  CoordCenter.GetMapValue<int>("TCoord") );
472 }
473 //-------------------------------------------------------------------------
474 
475 //-------------------------------------------------------------------------
477 {
478  std::list< unsigned int > ListCheckedTraces =
479  this->GetListHighlightedIDs();
480  if ( ListCheckedTraces.empty() )
481  {
482  QMessageBox msgBox;
483  msgBox.setText(
484  tr("Please select at least one %1 to create the %2")
485  .arg( this->m_TraceName.c_str() )
486  .arg( this->m_CollectionName.c_str() ) );
487  msgBox.exec();
488  return;
489  }
490  emit NewCollectionFromCheckedTraces(ListCheckedTraces);
491 }
492 
493 //-------------------------------------------------------------------------
494 
495 //-------------------------------------------------------------------------
496 
498  int iYCoord, int iZCoord, int iTCoord)
499 {
500  GoDBCoordinateRow coord;
501 
502  coord.SetField< unsigned int >("XCoord", iXCoord);
503  coord.SetField< unsigned int >("YCoord", iYCoord);
504  coord.SetField< unsigned int >("ZCoord", iZCoord);
505  coord.SetField< unsigned int >("TCoord", iTCoord);
506  return coord;
507 }
508 
509 //-------------------------------------------------------------------------
510 
511 //-------------------------------------------------------------------------
513 {
514  std::list< unsigned int > ListCheckedTraces = this->GetListHighlightedIDs();
515  if ( ListCheckedTraces.empty() )
516  {
517  QMessageBox msgBox;
518  msgBox.setText(
519  tr("Please check at least one %1 to be part of the %2")
520  .arg( this->m_TraceName.c_str() )
521  .arg( this->m_CollectionName.c_str() ) );
522  msgBox.exec();
523  return;
524  }
526  this->GetListHighlightedIDs() );
527 }
528 
529 //-------------------------------------------------------------------------
530 
531 //-------------------------------------------------------------------------
533  vtkMySQLDatabase *iDatabaseConnector, int iNumberOfTraceIDs)
534 {
536  iDatabaseConnector, iNumberOfTraceIDs);
537 }
538 
539 //-------------------------------------------------------------------------
540 
541 //-------------------------------------------------------------------------
543  vtkMySQLDatabase *iDatabaseConnector)
544 {
545  this->m_DatabaseConnector = iDatabaseConnector;
546 }
547 
548 //-------------------------------------------------------------------------
549 
550 //-------------------------------------------------------------------------
552 {
553  this->m_SelectedCollectionData = iCollectionData;
554 }
555 
556 //-------------------------------------------------------------------------
557 
558 //-------------------------------------------------------------------------
560 {
561  this->m_CurrentTimePoint = iTimePoint;
562 }
563 
564 //-------------------------------------------------------------------------
565 
566 //-------------------------------------------------------------------------
568 {
569  this->m_SelectedColorData = iColorData;
570 }
571 
572 //-------------------------------------------------------------------------
573 
574 //-------------------------------------------------------------------------
576 {
577  this->m_IsShowOnlyCurrentTimePointOn = IsChecked;
578 
579  if ( IsChecked )
580  {
582  }
583  else
584  {
585  this->m_Table->ShowAllRows();
586  }
587 }
588 
589 //-------------------------------------------------------------------------
590 
591 //-------------------------------------------------------------------------
593 {
594  if ( this->m_IsShowOnlyCurrentTimePointOn )
595  {
597  }
598 }
599 //-------------------------------------------------------------------------
600 
601 //-------------------------------------------------------------------------
603 {
605  this->m_SelectedCollectionData->first;
606 }
607 //-------------------------------------------------------------------------