GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoPrintDatabase.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 "QGoPrintDatabase.h"
35 
36 #include <QStringList>
37 #include <QWidget>
38 #include <QDialog>
39 #include <QInputDialog>
40 #include <QFileDialog>
41 #include <QTableWidgetItem>
42 #include <QMessageBox>
43 #include <QMenu>
44 #include <QCloseEvent>
45 #include <QPixmap>
46 #include <QStatusBar>
47 
48 #include <iostream>
49 
50 #include "vtkActor.h"
51 #include "vtkMySQLDatabase.h"
52 #include "vtkSQLQuery.h"
53 #include "vtkStringArray.h"
54 #include "vtkStdString.h"
55 
56 #include "QGoTableWidget.h"
57 #include "GoDBRecordSet.h"
58 #include "GoDBRecordSetHelper.h"
59 #include "GoDBContourRow.h"
60 #include "GoDBMeshRow.h"
61 #include "GoDBTrackRow.h"
62 #include "GoDBLineageRow.h"
63 #include "GoDBCoordinateRow.h"
64 #include "GoDBColorRow.h"
65 #include "QueryDataBaseHelper.h"
66 #include "ConvertToStringHelper.h"
68 #include "GoDBExport.h"
69 #include "GoDBImport.h"
70 
71 #include "ContourMeshContainer.h"
72 #include "QGoTrackEditingWidget.h"
73 
74 //--------------------------------------------------------------------------
76  QGoDockWidget(iParent),
77  m_ContoursManager(NULL),
78  m_MeshesManager(NULL),
79  m_TracksManager(NULL),
80  m_LineagesManager(NULL),
81  m_DatabaseConnector(NULL),
82  m_IsDatabaseUsed(false),
83  m_ReeditMode(false),
84  m_MeshGenerationMode(false)
85 {
86  this->SetUpUi();
87 
88  this->m_CellTypeManager = new QGoDBCellTypeManager(this);
89 
91 
92  this->m_ColorManager = new QGoDBColorManager(this);
93  this->m_SelectedTimePoint = new int;
94 
97 
98  QObject::connect( this, SIGNAL( customContextMenuRequested(const QPoint &) ),
99  this, SLOT( CreateContextMenu(const QPoint &) ) );
100 
101  QObject::connect( this->m_TraceSettingsWidget, SIGNAL( TraceChanged( int ) ),
102  this, SLOT( TheTraceHasChanged( int ) ) );
103 
104  QObject::connect( this->m_TraceSettingsWidgetForToolBar, SIGNAL( TraceChanged( int ) ),
105  this, SLOT( TheTraceHasChanged( int ) ) );
106 }
107 
108 //--------------------------------------------------------------------------
109 
110 //--------------------------------------------------------------------------
112 {
113  if ( m_SelectedTimePoint )
114  {
115  delete m_SelectedTimePoint;
116  }
117  // Need to release memory allocated for contours, meshes, tracks and lineages
118  // contours
119  if ( m_ContoursManager )
120  {
121  delete m_ContoursManager;
122  }
123  // meshes
124  if ( m_MeshesManager )
125  {
126  delete m_MeshesManager;
127  }
128  // tracks
129  if ( m_TracksManager )
130  {
131  delete m_TracksManager;
132  }
133  // lineages
134  if (m_LineagesManager)
135  {
136  delete m_LineagesManager;
137  }
138 }
139 
140 //--------------------------------------------------------------------------
141 
142 //--------------------------------------------------------------------------
144 {
145  this->m_ToggleAction->setToolTip(tr("Show/hide the table widget"));
146  QIcon TableWidgetIcon;
147  TableWidgetIcon.addPixmap(QPixmap( QString::fromUtf8(":/fig/TableWidget.png") ),
148  QIcon::Normal, QIcon::Off);
149  this->m_ToggleAction->setIcon(TableWidgetIcon);
150 
151  this->m_TraceSettingsWidget =
152  new QGoTraceSettingsWidget(this);
153 
154  QWidget* Widget = new QWidget;
155  QVBoxLayout* verticalLayout = new QVBoxLayout(Widget);
156  this->m_StackedTables = new QStackedWidget(Widget);
157 
158  verticalLayout->addWidget(this->m_TraceSettingsWidget);
159  this->m_TraceSettingsWidget->setVisible(false);
160  this->m_TraceSettingsVisible = false;
161 
162  verticalLayout->addWidget(this->m_StackedTables);
163  Widget->setLayout(verticalLayout);
164  this->setContextMenuPolicy(Qt::CustomContextMenu);
165  this->setWidget(Widget);
167 }
168 //--------------------------------------------------------------------------
169 
170 //--------------------------------------------------------------------------
172  const std::string & iNameDB, const std::string & iServer,
173  const std::string & iUser, const std::string & iPassword,
174  const unsigned int & iImgSessionID, const std::string & iImgSessionName)
175 {
176  m_Server = iServer;
177  m_User = iUser;
178  m_Password = iPassword;
179  m_DBName = iNameDB;
180  m_ImgSessionID = iImgSessionID;
181  m_ImgSessionName = iImgSessionName;
182 
183  this->SetTracesManager();
184  this->m_BookmarkManager = new QGoDBBookmarkManager(this, this->m_ImgSessionID);
185  QObject::connect( this->m_BookmarkManager, SIGNAL( ListBookmarksChanged() ),
186  this, SIGNAL( OpenBookmarksToUpdate() ) );
187 
189  this->SetTSListCollectionID();
190  emit DBVariablesSet();
191 }
192 
193 //--------------------------------------------------------------------------
194 
195 //--------------------------------------------------------------------------
197 {
198  if ( m_DatabaseConnector == NULL )
199  {
202  }
203 }
204 
205 //--------------------------------------------------------------------------
206 
207 //--------------------------------------------------------------------------
209 {
211  {
212  this->m_DatabaseConnector = NULL;
213  }
214 }
215 
216 //--------------------------------------------------------------------------
217 
218 //--------------------------------------------------------------------------
219 void QGoPrintDatabase::FillTableFromDatabase(const unsigned int& iThreshold)
220 {
221  bool limitedMemory = ( iThreshold != std::numeric_limits< unsigned int >::max() );
222 
224  // Get number of meshes to be loaded
225  unsigned int nbOfTraces = NumberOfElementForGivenImagingSessionAndTrace(
226  this->m_DatabaseConnector,
227  this->m_ImgSessionID,
228  "mesh");
229 
230  if( ( nbOfTraces <= iThreshold ) || !limitedMemory )
231  {
232  this->m_VisibleTimePoints.clear();
234  }
235  else
236  {
237  // if there are more than 5000 meshes, only load 3 time points in
238  // memory
239 
240  this->m_VisibleTimePoints.resize(3);
242  }
243 
245 
246  QString title = QString("Table for: %1 ").arg( m_ImgSessionName.c_str() );
247  this->setWindowTitle(title);
248 
253 
254  m_IsDatabaseUsed = true;
255  emit PrintDBReady();
256 }
257 
258 //--------------------------------------------------------------------------
259 
260 //--------------------------------------------------------------------------
262 {
263  return this->m_TraceSettingsWidget->GetTraceName();
264 }
265 
266 //-------------------------------------------------------------------------
267 
268 //-------------------------------------------------------------------------
269 void
271  unsigned int iYCoordMin,
272  unsigned int iZCoordMin,
273  unsigned int iTCoord,
274  unsigned int iXCoordMax,
275  unsigned int iYCoordMax,
276  unsigned int iZCoordMax,
277  vtkPolyData *iContourNodes)
278 {
280  unsigned int ContourID;
281  if ( !this->m_ReeditMode )
282  {
283  ContourID = this->m_ContoursManager->SaveNewContourFromVisu(iTCoord,
284  iXCoordMin,
285  iYCoordMin,
286  iZCoordMin,
287  iXCoordMax,
288  iYCoordMax,
289  iZCoordMax,
290  iContourNodes,
291  this->m_DatabaseConnector,
292  1);
293  }
294  else
295  {
297  iXCoordMin, iYCoordMin, iZCoordMin, iTCoord, iXCoordMax, iYCoordMax, iZCoordMax,
298  iContourNodes, this->m_DatabaseConnector);
299  this->m_ReeditMode = false;
300  }
301 
302  std::list< unsigned int > ListContours;
303  ListContours.push_back(ContourID);
304  std::list< unsigned int > ListMeshes =
305  this->m_ContoursManager->GetListCollectionIDs(this->m_DatabaseConnector, ListContours);
306  if ( !ListMeshes.empty() )
307  {
308  this->m_MeshesManager->UpdateBoundingBoxes(this->m_DatabaseConnector, ListMeshes);
309  }
311 }
312 
313 //-------------------------------------------------------------------------
314 
315 //-------------------------------------------------------------------------
316 void
318  unsigned int iYCoordMin,
319  unsigned int iZCoordMin,
320  unsigned int iXCoordMax,
321  unsigned int iYCoordMax,
322  unsigned int iZCoordMax,
323  int iTCoord,
324  vtkPolyData *iMeshNodes,
325  GoFigureMeshAttributes *iMeshAttributes,
326  int iTrackID)
327 {
329  if ( !this->m_MeshGenerationMode)
330  {
331  unsigned int TrackID = 0;
332 
333  if(iTrackID != -1)
334  {
335  TrackID = iTrackID;
336  }
337  else
338  {
340  }
341 
342  //check that there isn't an existing mesh with the same timepoint in the
343  // track,if so, set its trackID to 0:
346  QString MessageToPrint = this->m_MeshesManager->CheckExistingMeshesForTheTrack(TrackID,
347  this->m_DatabaseConnector,
348  iTCoord);
349  if ( MessageToPrint != "" )
350  {
351  // remove old mesh from track average volume
352  int kickedMeshID = MessageToPrint.toInt();
353  double volume = this->m_MeshesManager->GetVolume(kickedMeshID);
354  this->m_TracksManager->AddVolume(TrackID, (-1)*volume);
355  // write message
356  MessageToPrint =
357  tr(
358  "Warning: existing mesh at this timepoint for this track !!The track of the mesh with the meshID %1 has been reassigned to 0")
359  .arg(kickedMeshID);
360  emit PrintMessage(MessageToPrint);
361  }
362  std::list<unsigned int> MotherTrackDivisionToUpdate;
363  MessageToPrint = this->m_TracksManager->CheckMeshCanBeAddedToTrack(this->m_DatabaseConnector, TrackID,
364  *this->m_SelectedTimePoint, MotherTrackDivisionToUpdate).c_str();
365  unsigned int NewMeshID;
366  if (!MessageToPrint.isEmpty() )
367  {
368  emit PrintMessage(MessageToPrint);
369  NewMeshID = this->m_MeshesManager->SaveNewMeshWithNoTrackFromVisu(iXCoordMin,
370  iYCoordMin,
371  iZCoordMin,
372  iXCoordMax,
373  iYCoordMax,
374  iZCoordMax,
375  iTCoord,
376  iMeshNodes,
377  this->m_DatabaseConnector,
378  iMeshAttributes);
379  this->CloseDBConnection();
380  return;
381  }
382 
383  NewMeshID = this->m_MeshesManager->SaveNewMeshFromVisu(iXCoordMin,
384  iYCoordMin,
385  iZCoordMin,
386  iXCoordMax,
387  iYCoordMax,
388  iZCoordMax,
389  iTCoord,
390  iMeshNodes,
391  this->m_DatabaseConnector,
392  iMeshAttributes,
393  TrackID);
394 
395  std::list< unsigned int > ListNewMeshes;
396  ListNewMeshes.push_back(NewMeshID);
397  //here update the CurrentElement for trackContainer with the data from the
398  // database corresponding to the selected trackID:
399  // this->m_TracksManager->UpdateCurrentElementTrackContainer(TrackID);
400  //update the bounding box and the visu for the tracks:
401  std::list< unsigned int > trackIDs = this->m_MeshesManager->GetListCollectionIDs(this->m_DatabaseConnector,
402  ListNewMeshes);
403 
404  // old nb of points in map track structure
405  this->m_TracksManager->AddVolume(TrackID, iMeshAttributes->m_Volume);
406 
407  // new nb of point in map track structure
409  trackIDs);
410 
411  if (!MotherTrackDivisionToUpdate.empty() )
412  {
413  this->m_TracksManager->UpdateDivisions(MotherTrackDivisionToUpdate);
414  }
415  }
416  else //for mesh generated from contours:
417  {
418  this->m_MeshesManager->SaveGeneratedMeshFromVisu(iXCoordMin,
419  iYCoordMin,
420  iZCoordMin,
421  iXCoordMax,
422  iYCoordMax,
423  iZCoordMax,
424  iMeshNodes,
425  this->m_DatabaseConnector,
426  iMeshAttributes);
427  //as the mesh is generated from contours, there is no TrackID associated.
428  this->m_MeshGenerationMode = false;
429  }
431 }
432 
433 //-------------------------------------------------------------------------
434 
435 //-------------------------------------------------------------------------
437 {
438  /*this->OpenDBConnection();
439  unsigned int TrackID = this->m_TraceWidget->GetCurrentSelectedCollectionID();
440  QString MessageToPrint = this->m_MeshesManager->CheckExistingMeshesForTheTrack(TrackID,
441  this->m_DatabaseConnector);
442  if ( MessageToPrint != "" )
443  {
444  emit PrintMessage(MessageToPrint);
445  }
446 
447  unsigned int MeshID = this->m_MeshesManager->CreateNewMeshWithNoContourNoPoints(
448  this->m_DatabaseConnector);
449  std::list< unsigned int > ListLastCreatedContours =
450  this->m_ContoursManager->GetLastCreatedTracesIDs(this->m_DatabaseConnector, iNumberOfContours);
451  this->AddCheckedTracesToCollection< QGoDBContourManager, QGoDBMeshManager >(
452  this->m_ContoursManager, this->m_MeshesManager, MeshID, ListLastCreatedContours);
453 
454  std::list< unsigned int > ListNewMeshes;
455  ListNewMeshes.push_back(MeshID);
456  std::list< unsigned int > trackIDs = this->m_MeshesManager->GetListCollectionIDs(this->m_DatabaseConnector,
457  ListNewMeshes);
458  //here update the CurrentElement for trackContainer with the data from the
459  // database corresponding to the selected trackID:
460  //update the bounding box and the visu for the tracks:
461  this->m_TracksManager->UpdateBoundingBoxes(
462  this->m_DatabaseConnector,
463  trackIDs);
464  this->SetTSListCollectionID(); // need to reload the list of trackIDs as
465  // normally, the new added mesh from create
466  // mesh with no
467  //contour will add the new meshid in the TSList...
468  this->CloseDBConnection();*/
469 }
470 
471 //-------------------------------------------------------------------------
472 
473 //-------------------------------------------------------------------------
475  unsigned int iXCoordMin,
476  unsigned int iYCoordMin,
477  unsigned int iZCoordMin,
478  unsigned int iXCoordMax,
479  unsigned int iYCoordMax,
480  unsigned int iZCoordMax,
481  vtkPolyData *iTraceNodes)
482 {
483  /*this->OpenDBConnection();
484  unsigned int ContourID = this->m_ContoursManager->SaveNewContourFromVisu(
485  iXCoordMin, iYCoordMin, iZCoordMin,
486  iXCoordMax, iYCoordMax, iZCoordMax, iTraceNodes,
487  this->m_DatabaseConnector, 0);
488  this->CloseDBConnection();
489  return ContourID;*/
490  return 0;
491 }
492 
493 //-------------------------------------------------------------------------
494 
495 //-------------------------------------------------------------------------
497 {
498  return m_IsDatabaseUsed;
499 }
500 
501 //-------------------------------------------------------------------------
502 
503 //-------------------------------------------------------------------------
504 std::list< QGoPrintDatabase::ItemColorComboboxData >
505 QGoPrintDatabase::GetListCollectionIDFromDB(vtkMySQLDatabase *iDatabaseConnector,
506  std::string & ioIDToSelect)
507 {
508  std::list< ItemColorComboboxData > EmptyList = std::list< ItemColorComboboxData >();
509  std::string TraceName = this->m_TraceSettingsWidget->GetTraceName();
510  if ( TraceName == "contour" )
511  {
512  return this->m_MeshesManager->GetAllTraceIDsWithColor(iDatabaseConnector, ioIDToSelect);
513  }
514  if ( TraceName == "mesh" )
515  {
516  return this->m_TracksManager->GetAllTraceIDsWithColor(iDatabaseConnector, ioIDToSelect);
517  }
518  return EmptyList;
519 }
520 
521 //-------------------------------------------------------------------------
522 
523 //-------------------------------------------------------------------------
525 {
526  this->OpenDBConnection();
527 
528  std::string TraceName = this->m_TraceSettingsWidget->GetTraceName();
529  if ( TraceName != "contour" && TraceName != "mesh" )
530  {
531  return;
532  }
533  else
534  {
535  unsigned int NewCollectionID = 0;
536  if ( TraceName == "contour" )
537  {
538  NewCollectionID =
540  this->m_DatabaseConnector);
541  }
542  if ( TraceName == "mesh" )
543  {
544  NewCollectionID =
546  this->m_DatabaseConnector);
547  }
548  ItemColorComboboxData NewCollectionData;
549  NewCollectionData.first = ConvertToString< unsigned int >(NewCollectionID);
550  NewCollectionData.second = this->m_TraceSettingsWidget->GetPointerColorData()->second;
551  }
552 
553  this->CloseDBConnection();
554 }
555 
556 //-------------------------------------------------------------------------
557 
558 //-------------------------------------------------------------------------
559 void QGoPrintDatabase::AddBookmark(int iXCoord, int iYCoord,
560  int iZCoord, int iTCoord)
561 {
562  GoDBCoordinateRow BookmarkCoord;
563 
564  BookmarkCoord.SetField< int >("XCoord", iXCoord);
565  BookmarkCoord.SetField< int >("YCoord", iYCoord);
566  BookmarkCoord.SetField< int >("ZCoord", iZCoord);
567  BookmarkCoord.SetField< int >("TCoord", iTCoord);
568 
569  this->OpenDBConnection();
570  int BookmarkCoordID = BookmarkCoord.SaveInDB(this->m_DatabaseConnector);
571  this->m_BookmarkManager->AddABookmark(BookmarkCoordID, this->m_DatabaseConnector);
572  this->CloseDBConnection();
573 }
574 
575 //-------------------------------------------------------------------------
576 
577 //-------------------------------------------------------------------------
579 {
580  this->OpenDBConnection();
581  NamesDescrContainerType ListBookmarks =
583  this->CloseDBConnection();
584  return ListBookmarks;
585 }
586 
587 //-------------------------------------------------------------------------
588 
589 //-------------------------------------------------------------------------
591  std::string iName)
592 {
593  this->OpenDBConnection();
594  GoDBCoordinateRow Coord = this->m_BookmarkManager->
595  GetCoordinatesForBookmark(this->m_DatabaseConnector, iName);
596  this->CloseDBConnection();
597  return Coord;
598 }
599 
600 //-------------------------------------------------------------------------
601 
602 //-------------------------------------------------------------------------
604 {
605  this->OpenDBConnection();
607  this->CloseDBConnection();
608 }
609 
610 //-------------------------------------------------------------------------
611 
612 //-------------------------------------------------------------------------
614 {
615  *this->m_SelectedTimePoint = iTimePoint;
616  if ( !this->m_Server.empty() ) //if empty, the database variables are not
617  //been set up yet.
618  {
619  if ( this->m_TraceSettingsWidget->GetTraceName() == "contour" )
620  {
621  //if we change the timepoint, the list of meshes will be different from
622  // the previous one, so, initialize the list is needed (no pre-selected
623  // collection)
624  this->SetTSListCollectionID();
626  }
627  if ( this->m_TraceSettingsWidget->GetTraceName() == "mesh" )
628  {
630  }
631  }
632 }
633 
634 //-------------------------------------------------------------------------
635 
636 //-------------------------------------------------------------------------
638 {
639  this->m_StackedTables->setCurrentIndex(iIndex);
640  this->SetTSListCollectionID();
641 }
642 
643 //-------------------------------------------------------------------------
644 
645 //-------------------------------------------------------------------------
646 /*void QGoPrintDatabase::SetTable(std::string iTablename)
647 {
648  int Index = 0;
649 
650  if ( iTablename == "mesh" )
651  {
652  Index = 1;
653  }
654  if ( iTablename == "track" )
655  {
656  Index = 2;
657  }
658  if ( iTablename == "lineage" )
659  {
660  Index = 3;
661  }
662  this->m_StackedTables->setCurrentIndex(Index);
663 }*/
664 
665 //-------------------------------------------------------------------------
666 
667 //-------------------------------------------------------------------------
669 {
670  if ( iTableName == "contour" )
671  {
673  }
674  if ( iTableName == "mesh" )
675  {
677  }
678 }
679 
680 //-------------------------------------------------------------------------
681 
682 //-------------------------------------------------------------------------
684 {
686  tr("Save Contour Export File"), "", tr("TextFile (*.txt)") );
687 
688  if ( !p.isNull() )
689  {
690  if ( !p.endsWith(".txt") )
691  {
692  p.append( QString(".txt") );
693  }
694  QFileInfo pathInfo(p);
695  std::string filename = p.toStdString();
696 
697  GoDBExport ExportHelper(this->m_Server, this->m_User,
698  this->m_Password, this->m_ImgSessionID, filename);
699  ExportHelper.ExportContours();
700  }
701 }
702 
703 //-------------------------------------------------------------------------
704 
705 //-------------------------------------------------------------------------
707 {
709  tr("Save Contour Export File"), "", tr("TextFile (*.txt)") );
710 
711  if ( !p.isNull() )
712  {
713  if ( !p.endsWith(".txt") )
714  {
715  p.append( QString(".txt") );
716  }
717 
718  QFileInfo pathInfo(p);
719  std::string filename = p.toStdString();
720 
721  GoDBExport ExportHelper(this->m_Server, this->m_User,
722  this->m_Password, this->m_ImgSessionID, filename);
723  ExportHelper.ExportMeshes();
724  }
725 }
726 
727 //-------------------------------------------------------------------------
728 
729 //-------------------------------------------------------------------------
731 {
733  tr("Open Contours Export File"), "",
734  tr("TextFile (*.txt)") );
735 
736  QStringList::Iterator it = p.begin();
737 
738  //refactoring
739  while ( it != p.end() )
740  {
741  emit PrintMessage( tr("Warning: Close and reopen your imagingsession once the import is done !!") );
742  QFileInfo pathInfo(*it);
743  std::string filename = (*it).toStdString();
744  //import into the database:
745  GoDBImport ImportHelper(this->m_Server, this->m_User,
746  this->m_Password, this->m_ImgSessionID, filename,
747  *this->m_SelectedTimePoint);
748  ImportHelper.ImportContours();
749 
750  std::vector< int > NewContourIDs = ImportHelper.GetVectorNewContourIDs();
751  std::vector< int > NewMeshIDs = ImportHelper.GetVectorNewMeshIDs();
752  std::vector< int > NewTrackIDs = ImportHelper.GetVectorNewTracksIDs();
753 
754  this->OpenDBConnection();
756  this->m_DatabaseConnector);
758  this->m_DatabaseConnector);
760  this->m_DatabaseConnector);
761  this->CloseDBConnection();
762  //as in the import contours file, there are data such as colors,celltype
763  //and subcelltype, the lists may have been updated in the database:
765 
766  ++it;
767  }
768 }
769 
770 //-------------------------------------------------------------------------
771 
772 //-------------------------------------------------------------------------
774 {
776  tr("Open Meshes Export Files"), "",
777  tr("TextFile (*.txt)") );
778 
779  if( p.size() != 0 )
780  {
781  emit PrintMessage( tr("Warning: Close and reopen your imagingsession once the import is done !!") );
782  }
783 
784 #if HAS_OPENMP
785 #pragma omp for
786 #endif
787  for( int i = 0; i < p.size(); i++ )
788  {
789  QFileInfo pathInfo( p[i] );
790  std::string filename = ( p[i] ).toStdString();
791  //import into the database:
792  GoDBImport ImportHelper(this->m_Server, this->m_User,
793  this->m_Password, this->m_ImgSessionID, filename,
794  *this->m_SelectedTimePoint);
795  ImportHelper.ImportMeshes();
796 
797 // std::vector< int > NewMeshIDs = ImportHelper.GetVectorNewMeshIDs();
798 // std::vector< int > NewTrackIDs = ImportHelper.GetVectorNewTracksIDs();
799 
800 // this->OpenDBConnection();
801 // this->m_MeshesManager->UpdateTWAndContainerForImportedTraces(NewMeshIDs,
802 // this->m_DatabaseConnector);
803 // this->m_TracksManager->UpdateTWAndContainerForImportedTraces(NewTrackIDs,
804 // this->m_DatabaseConnector);
805 // this->CloseDBConnection();
806 // this->InitializeTheComboboxesNotTraceRelated();
807  }
808 }
809 
810 //-------------------------------------------------------------------------
811 
812 //-------------------------------------------------------------------------
813 std::vector< int > QGoPrintDatabase::ImportTracks()
814 {
816  tr("Open Tracks Export File"), "",
817  tr("TextFile (*.txt)") );
818 
819  std::vector< int > NewTrackIDs = std::vector< int >();
820 
821  if ( !p.isNull() )
822  {
823  emit PrintMessage( tr("Warning: Close and reopen your imagingsession once the import is done !!") );
824  QFileInfo pathInfo(p);
825  std::string filename = p.toStdString();
826  //import into the database:
827  GoDBImport ImportHelper(this->m_Server, this->m_User,
828  this->m_Password, this->m_ImgSessionID, filename,
829  *this->m_SelectedTimePoint);
830  ImportHelper.ImportTracks();
831 
832  std::vector< int > NewMeshIDs = ImportHelper.GetVectorNewMeshIDs();
833  NewTrackIDs = ImportHelper.GetVectorNewTracksIDs();
834 
835  this->OpenDBConnection();
837  this->m_DatabaseConnector);
839  this->m_DatabaseConnector);
840  this->CloseDBConnection();
842  }
843  return NewTrackIDs;
844 }
845 
846 //-------------------------------------------------------------------------
847 
848 //-------------------------------------------------------------------------
849 //******related to TraceManualEditingDockWidget:****************************
851 {
852  return this->m_TraceSettingsWidget;
853 }
854 
855 //-------------------------------------------------------------------------
856 
857 //-------------------------------------------------------------------------
859 {
860  return this->m_TraceSettingsWidgetForToolBar;
861 }
862 //-------------------------------------------------------------------------
863 
864 //-------------------------------------------------------------------------
866 {
876 
877  QObject::connect(this->m_TraceSettingsWidget->m_SelectedTrace, SIGNAL(currentIndexChanged (int) ),
878  this->m_TraceSettingsWidgetForToolBar->m_SelectedTrace, SLOT(setCurrentIndex(int) ) );
879  QObject::connect(this->m_TraceSettingsWidget->m_SelectedColorComboBox, SIGNAL(currentIndexChanged (int) ),
880  this->m_TraceSettingsWidgetForToolBar->m_SelectedColorComboBox, SLOT(setCurrentIndex(int) ) );
881  QObject::connect(this->m_TraceSettingsWidget->m_ChoseCellType, SIGNAL(currentIndexChanged (int) ),
882  this->m_TraceSettingsWidgetForToolBar->m_ChoseCellType, SLOT(setCurrentIndex(int) ) );
883  QObject::connect(this->m_TraceSettingsWidget->m_ChoseSubCellType, SIGNAL(currentIndexChanged (int) ),
884  this->m_TraceSettingsWidgetForToolBar->m_ChoseSubCellType, SLOT(setCurrentIndex(int) ) );
885  QObject::connect(this->m_TraceSettingsWidget->m_CollectionColorComboBox, SIGNAL(currentIndexChanged (int) ),
886  this->m_TraceSettingsWidgetForToolBar->m_CollectionColorComboBox, SLOT(setCurrentIndex(int) ) );
887 
888  QObject::connect(this->m_TraceSettingsWidgetForToolBar->m_SelectedTrace, SIGNAL(currentIndexChanged (int) ),
889  this->m_TraceSettingsWidget->m_SelectedTrace, SLOT(setCurrentIndex(int) ) );
890  QObject::connect(this->m_TraceSettingsWidgetForToolBar->m_SelectedColorComboBox, SIGNAL(currentIndexChanged (int) ),
891  this->m_TraceSettingsWidget->m_SelectedColorComboBox, SLOT(setCurrentIndex(int) ) );
892  QObject::connect(this->m_TraceSettingsWidgetForToolBar->m_ChoseCellType, SIGNAL(currentIndexChanged (int) ),
893  this->m_TraceSettingsWidget->m_ChoseCellType, SLOT(setCurrentIndex(int) ) );
894  QObject::connect(this->m_TraceSettingsWidgetForToolBar->m_ChoseSubCellType, SIGNAL(currentIndexChanged (int) ),
895  this->m_TraceSettingsWidget->m_ChoseSubCellType, SLOT(setCurrentIndex(int) ) );
896  QObject::connect(this->m_TraceSettingsWidgetForToolBar->m_CollectionColorComboBox, SIGNAL(currentIndexChanged (int) ),
897  this->m_TraceSettingsWidget->m_CollectionColorComboBox, SLOT(setCurrentIndex(int) ) );
898 
900  this->m_TraceSettingsWidgetForToolBar, SLOT(SetSelectedPointersToNull() ) );
901 
903  this->m_TraceSettingsWidget, SLOT(SetSelectedPointersToNull() ) );
904 
905  QObject::connect( this, SIGNAL(topLevelChanged(bool) ),
906  this, SLOT(ShowHideTraceSettingsFromContextMenu(bool) ) );
907 }
908 //--------------------------------------------------------------------------
909 
910 //--------------------------------------------------------------------------
912  QGoTraceSettingsWidget* iTraceSettingsWidget)
913 {
914  QObject::connect( iTraceSettingsWidget,
915  SIGNAL( AddNewColor() ),
916  this,
917  SLOT( AddNewColor() ) );
918 
919  QObject::connect( iTraceSettingsWidget,
920  SIGNAL( DeleteColor() ),
921  this,
922  SLOT( DeleteColor() ) );
923 
924  QObject::connect( iTraceSettingsWidget,
925  SIGNAL( NewCollectionToBeCreated() ),
926  this,
928 
929  QObject::connect( iTraceSettingsWidget,
930  SIGNAL( AddANewCellType() ),
931  this,
932  SLOT( AddNewCellType() ) );
933  QObject::connect( iTraceSettingsWidget,
934  SIGNAL( AddANewSubCellType() ),
935  this,
936  SLOT( AddNewSubCellType() ) );
937 
938  QObject::connect( iTraceSettingsWidget,
939  SIGNAL( DeleteCellType() ),
940  this,
941  SLOT( DeleteCellType() ) );
942 
943  QObject::connect( iTraceSettingsWidget,
944  SIGNAL( DeleteSubCellType() ),
945  this,
946  SLOT( DeleteSubCellType() ) );
947 }
948 
949 //-------------------------------------------------------------------------
950 
951 //-------------------------------------------------------------------------
953 {
954  std::string PreviousTraceName = this->m_TraceSettingsWidget->GetTraceName();
955  if (PreviousTraceName != iTraceName)
956  {
957  this->UpdateSelectedCollectionForTableWidget(PreviousTraceName);
958  this->m_TraceSettingsWidget->SetCurrentTraceName(iTraceName);
959  }
960 }
961 
962 //-------------------------------------------------------------------------
963 
964 //-------------------------------------------------------------------------
966 {
967  this->SetTSListColors();
968  this->SetTSListCellTypes();
969  this->SetTSListSubCellTypes();
970 }
971 
972 //-------------------------------------------------------------------------
973 
974 //-------------------------------------------------------------------------
975 void QGoPrintDatabase::SetTSListColors(std::string iNewColorToSelect)
976 {
977  this->OpenDBConnection();
978  this->blockSignals(true);
980  this->m_ColorManager->GetListExistingColors(this->m_DatabaseConnector),
981  iNewColorToSelect);
983  this->m_ColorManager->GetListExistingColors(this->m_DatabaseConnector),
984  iNewColorToSelect);
985  this->blockSignals(false);
986  this->CloseDBConnection();
987 }
988 
989 //-------------------------------------------------------------------------
990 
991 //-------------------------------------------------------------------------
993 {
994  this->OpenDBConnection();
996  this->m_ColorManager->GetListExistingColors(this->m_DatabaseConnector) );
998  this->m_ColorManager->GetListExistingColors(this->m_DatabaseConnector) );
999  this->CloseDBConnection();
1000 }
1001 
1002 //-------------------------------------------------------------------------
1003 
1004 //-------------------------------------------------------------------------
1006 {
1007  //std::string TraceName = this->InWhichTableAreWe();
1008  //if (TraceName == "contour" || TraceName == "mesh")
1009  // {
1010  this->OpenDBConnection();
1011  std::string IDToSelect;
1012  std::list< ItemColorComboboxData > ListCollectionID =
1013  this->GetListCollectionIDFromDB(this->m_DatabaseConnector, IDToSelect);
1014  this->m_TraceSettingsWidget->SetListCollectionID(ListCollectionID, IDToSelect);
1015  this->m_TraceSettingsWidgetForToolBar->SetListCollectionID(ListCollectionID, IDToSelect);
1016  this->CloseDBConnection();
1017  // }
1018 }
1019 
1020 //-------------------------------------------------------------------------
1021 
1022 //-------------------------------------------------------------------------
1023 void QGoPrintDatabase::SetTSListCellTypes(std::string iCellTypeToSelect)
1024 {
1025  this->OpenDBConnection();
1027  this->m_CellTypeManager->GetListExistingEntities(this->m_DatabaseConnector),
1028  iCellTypeToSelect);
1030  this->m_CellTypeManager->GetListExistingEntities(this->m_DatabaseConnector),
1031  iCellTypeToSelect);
1032  this->CloseDBConnection();
1033 }
1034 
1035 //-------------------------------------------------------------------------
1036 
1037 //-------------------------------------------------------------------------
1039 {
1040  this->OpenDBConnection();
1042  this->m_CellTypeManager->GetListExistingEntities(this->m_DatabaseConnector) );
1044  this->m_CellTypeManager->GetListExistingEntities(this->m_DatabaseConnector) );
1045  this->CloseDBConnection();
1046 }
1047 
1048 //-------------------------------------------------------------------------
1049 
1050 //-------------------------------------------------------------------------
1051 void QGoPrintDatabase::SetTSListSubCellTypes(std::string iSubCellTypeToSelect)
1052 {
1053  this->OpenDBConnection();
1055  this->m_SubCellTypeManager->GetListExistingEntities(this->m_DatabaseConnector),
1056  iSubCellTypeToSelect);
1058  this->m_SubCellTypeManager->GetListExistingEntities(this->m_DatabaseConnector),
1059  iSubCellTypeToSelect);
1060  this->CloseDBConnection();
1061 }
1062 
1063 //-------------------------------------------------------------------------
1064 
1065 //-------------------------------------------------------------------------
1067 {
1068  this->OpenDBConnection();
1070  this->m_SubCellTypeManager->GetListExistingEntities(this->m_DatabaseConnector) );
1072  this->m_SubCellTypeManager->GetListExistingEntities(this->m_DatabaseConnector) );
1073  this->CloseDBConnection();
1074 }
1075 
1076 //-------------------------------------------------------------------------
1077 
1078 //-------------------------------------------------------------------------
1080 {
1081  this->OpenDBConnection();
1082  std::string NewCellType = this->m_CellTypeManager->AddAnEntity(
1083  this->m_DatabaseConnector);
1084  if ( !NewCellType.empty() )
1085  {
1086  this->SetTSListCellTypes(NewCellType);
1087  }
1088  else //if the NewCellType is empty, go to the last selected one:
1089  {
1092  }
1093  this->CloseDBConnection();
1094 }
1095 
1096 //-------------------------------------------------------------------------
1097 
1098 //-------------------------------------------------------------------------
1100 {
1101  this->OpenDBConnection();
1102  std::string NewSubCellType =
1104  if ( !NewSubCellType.empty() )
1105  {
1106  this->SetTSListSubCellTypes(NewSubCellType);
1107  }
1108  else //if the NewSubCellType is empty, go to the last selected one:
1109  {
1112  }
1113  this->CloseDBConnection();
1114 }
1115 
1116 //-------------------------------------------------------------------------
1117 
1118 //-------------------------------------------------------------------------
1120 {
1121  this->OpenDBConnection();
1123  this->m_DatabaseConnector);
1124  if ( !NewColor.first.empty() )
1125  {
1126  this->SetTSListColors(NewColor.first);
1127  }
1128  else //if the NewColor name is empty, go to the last selected one:
1129  {
1132  }
1133  this->CloseDBConnection();
1134 }
1135 
1136 //-------------------------------------------------------------------------
1137 
1138 //-------------------------------------------------------------------------
1140 {
1141  this->OpenDBConnection();
1142  if ( this->m_CellTypeManager->DeleteEntity(this->m_DatabaseConnector) )
1143  {
1145  }
1146  else //if the user cancelled, go to the last selected one:
1147  {
1150  }
1151  this->CloseDBConnection();
1152 }
1153 
1154 //-------------------------------------------------------------------------
1155 
1156 //-------------------------------------------------------------------------
1158 {
1159  this->OpenDBConnection();
1160  if ( this->m_ColorManager->DeleteEntity(this->m_DatabaseConnector) )
1161  {
1163  }
1164  else //if the user cancelled, go to the last selected one:
1165  {
1168  }
1169  this->CloseDBConnection();
1170 }
1171 
1172 //-------------------------------------------------------------------------
1173 
1174 //-------------------------------------------------------------------------
1176 {
1177  this->OpenDBConnection();
1178  if ( this->m_SubCellTypeManager->DeleteEntity(this->m_DatabaseConnector) )
1179  {
1181  }
1182  else //if the user cancelled, go to the last selected one:
1183  {
1186  }
1187  this->CloseDBConnection();
1188 }
1189 
1190 //*********************RELATED TO QGODBTRACEMANAGER**************************
1191 
1193  vtkMySQLDatabase *iDatabaseConnector)
1194 {
1196  iDatabaseConnector);
1198  iDatabaseConnector);
1200  iDatabaseConnector);
1201  this->m_TracksManager->LoadInfoVisuContainerForTrackFamilies(iDatabaseConnector);
1203  iDatabaseConnector);
1204 }
1205 
1206 //-------------------------------------------------------------------------
1207 
1208 //-------------------------------------------------------------------------
1209 
1211  vtkMySQLDatabase *iDatabaseConnector)
1212 {
1213  m_VisibleTimePoints.clear();
1214 
1215  if(*this->m_SelectedTimePoint>0)
1216  {
1217  m_VisibleTimePoints.push_back(*this->m_SelectedTimePoint-1);
1218  }
1219 
1220  m_VisibleTimePoints.push_back(*this->m_SelectedTimePoint);
1221  m_VisibleTimePoints.push_back(*this->m_SelectedTimePoint+1);
1222 
1223  this->m_ContoursManager->
1224  DisplayInfoAndLoadVisuContainerForAllContoursForSpecificTPs(
1225  iDatabaseConnector,
1227  this->m_MeshesManager->
1228  DisplayInfoAndLoadVisuContainerForAllMeshesForSpecificTPs(iDatabaseConnector,
1231  iDatabaseConnector);
1232  this->m_TracksManager->LoadInfoVisuContainerForTrackFamilies(iDatabaseConnector);
1234  iDatabaseConnector);
1235 }
1236 
1237 //-------------------------------------------------------------------------
1238 
1239 //-------------------------------------------------------------------------
1241  vtkMySQLDatabase *iDatabaseConnector, std::list<unsigned int> iListTimePoints)
1242 {
1244  iDatabaseConnector, iListTimePoints);
1246  iDatabaseConnector, iListTimePoints);
1247 }
1248 
1249 //-------------------------------------------------------------------------
1250 
1251 //-------------------------------------------------------------------------
1253 {
1254  QMenu *ContextMenu = new QMenu;
1255 
1256  QAction *TraceSettings = new QAction(tr("TraceSettings"), ContextMenu);
1257  TraceSettings->setCheckable(true);
1258  TraceSettings->setChecked(this->m_TraceSettingsVisible);
1259 
1260  QObject::connect( TraceSettings, SIGNAL( triggered (bool) ), this,
1261  SLOT( ShowHideTraceSettingsFromContextMenu(bool) ) );
1262 
1263  ContextMenu->addAction(TraceSettings);
1264 
1265  ContextMenu->exec( this->mapToGlobal(iPos) );
1266 }
1267 
1268 //--------------------------------------------------------------------------
1269 
1270 //--------------------------------------------------------------------------
1272 {
1273  this->DeleteCheckedTraces< QGoDBContourManager, QGoDBMeshManager, QGoDBContourManager >(
1275 }
1276 
1277 //--------------------------------------------------------------------------
1278 
1279 //--------------------------------------------------------------------------
1281 {
1282  // upade average mesh volume over a track
1283  // get IDs
1284  std::list< std::pair<unsigned int, double> > temp_list =
1286  // update tracks volumes
1287  this->m_TracksManager->RemoveVolumes(temp_list);
1288 
1289  this->DeleteCheckedTraces< QGoDBMeshManager, QGoDBTrackManager, QGoDBContourManager >(
1290  this->m_MeshesManager, this->m_TracksManager, this->m_ContoursManager);
1291 }
1292 
1293 //--------------------------------------------------------------------------
1294 
1295 //--------------------------------------------------------------------------
1297 {
1298  this->DeleteCheckedTraces< QGoDBTrackManager, QGoDBLineageManager, QGoDBMeshManager >(
1299  this->m_TracksManager, this->m_LineagesManager, this->m_MeshesManager);
1300 }
1301 
1302 //--------------------------------------------------------------------------
1303 
1304 //--------------------------------------------------------------------------
1306 {
1307  this->DeleteCheckedTraces< QGoDBLineageManager, QGoDBLineageManager, QGoDBTrackManager >(
1308  this->m_LineagesManager, this->m_LineagesManager, this->m_TracksManager, true);
1309 }
1310 
1311 //--------------------------------------------------------------------------
1312 
1313 //--------------------------------------------------------------------------
1315 {
1316  this->ChangeTraceColor< QGoDBMeshManager, QGoDBContourManager >(
1317  this->m_MeshesManager, this->m_ContoursManager);
1318 }
1319 
1320 //--------------------------------------------------------------------------
1321 
1322 //--------------------------------------------------------------------------
1324 {
1325  this->ChangeTraceColor< QGoDBTrackManager, QGoDBMeshManager >(
1326  this->m_TracksManager, this->m_MeshesManager);
1327 }
1328 
1329 //-------------------------------------------------------------------------
1330 
1331 //--------------------------------------------------------------------------
1333 {
1334  this->ChangeTraceColor< QGoDBLineageManager, QGoDBTrackManager >(
1335  this->m_LineagesManager, this->m_TracksManager);
1336 }
1337 
1338 //-------------------------------------------------------------------------
1339 
1340 //-------------------------------------------------------------------------
1342  iMeshAttributes, unsigned int iMeshID)
1343 {
1345  iMeshAttributes, iMeshID);
1346 }
1347 
1348 //--------------------------------------------------------------------------
1349 
1350 //--------------------------------------------------------------------------
1352  iTrackAttributes, unsigned int iTrackID)
1353 {
1354  // straight forward values from track polydata
1356  iTrackAttributes, iTrackID);
1357  // other values from mesh
1358  // do sth for the average volume
1359  // do everything here but should be optimized later on
1360  // calculate average volume
1361  //std::list< std::pair<int, double> > list =this->m_MeshesManager->GetAverageVolumePerTrack();
1362  //modify structure (which will update table!)
1363  //this->m_TracksManager->SetAverageVolumePerTrack(list);
1364 }
1365 
1366 //--------------------------------------------------------------------------
1367 
1368 //--------------------------------------------------------------------------
1369 void
1371 {
1373 }
1374 
1375 //--------------------------------------------------------------------------
1376 
1377 //--------------------------------------------------------------------------
1378 void
1380 {
1382 }
1383 
1384 //--------------------------------------------------------------------------
1385 
1386 //--------------------------------------------------------------------------
1387 void
1389 {
1392  SIGNAL ( NeedMeshesInfoForImportedTrack(unsigned int) ),
1393  this,
1394  SLOT ( PassMeshesInfoForImportedTrack(unsigned int) ) );
1395 }
1396 
1397 //--------------------------------------------------------------------------
1398 
1399 //--------------------------------------------------------------------------
1400 void
1402  TrackContainer *iTrackContainer)
1403 {
1405  iTrackContainer);
1406 }
1407 
1408 //--------------------------------------------------------------------------
1409 
1410 //--------------------------------------------------------------------------
1412 {
1413  this->SetContoursManager();
1414  this->SetMeshesManager();
1415  this->SetTracksManager();
1416  this->SetLineagesManager();
1417 }
1418 
1419 //--------------------------------------------------------------------------
1420 
1421 //--------------------------------------------------------------------------
1423 {
1427 
1428  QObject::connect( this->m_ContoursManager, SIGNAL( NeedToGetDatabaseConnection() ),
1429  this, SLOT( PassDBConnectionToContoursManager() ) );
1430  QObject::connect( this->m_ContoursManager, SIGNAL( CheckedTracesToDelete() ),
1431  this, SLOT( DeleteCheckedContours() ) );
1433  SIGNAL( NeedToGoToTheLocation(int, int, int, int) ),
1434  this, SIGNAL( NeedToGoToTheLocation(int, int, int, int) ) );
1436  SIGNAL( TraceToReEdit(unsigned int) ),
1437  this,
1438  SLOT( ReEditTrace(unsigned int) ) );
1440  SIGNAL( NewCollectionFromCheckedTraces(std::list< unsigned int > ) ),
1441  this,
1442  SLOT( CreateNewMeshFromCheckedContours(std::list< unsigned int > ) ) );
1444  SIGNAL( CheckedTracesToAddToSelectedCollection(
1445  std::list< unsigned int > ) ), this,
1446  SLOT( AddCheckedContoursToSelectedMesh(std::list< unsigned int > ) ) );
1448  SIGNAL( DBConnectionNotNeededAnymore() ),
1449  this,
1450  SLOT( CloseDBConnection() ) );
1452  SIGNAL( PrintMessage(QString, int) ),
1453  this,
1454  SIGNAL( PrintMessage(QString, int) ) );
1455 
1460 }
1461 
1462 //--------------------------------------------------------------------------
1463 
1464 //--------------------------------------------------------------------------
1466 {
1467  this->m_MeshesManager = new QGoDBMeshManager(m_ImgSessionID, this);
1468 
1469  QObject::connect( this->m_MeshesManager, SIGNAL( NeedToGetDatabaseConnection() ),
1470  this, SLOT( PassDBConnectionToMeshesManager() ) );
1472  SIGNAL( TraceColorToChange() ),
1473  this, SLOT( ChangeMeshColor() ) );
1474  QObject::connect( this->m_MeshesManager, SIGNAL( CheckedTracesToDelete() ),
1475  this, SLOT( DeleteCheckedMeshes() ) );
1477  SIGNAL( NeedToGoToTheLocation(int, int, int, int) ),
1478  this, SIGNAL( NeedToGoToTheLocation(int, int, int, int) ) );
1480  SIGNAL ( NewCollectionFromCheckedTraces(std::list< unsigned int > ) ),
1481  this,
1482  SLOT( CreateNewTrackFromListMeshes(std::list< unsigned int > ) ) );
1484  SIGNAL( CheckedTracesToAddToSelectedCollection(
1485  std::list< unsigned int > ) ), this,
1486  SLOT( AddCheckedMeshesToSelectedTrack(std::list< unsigned int > ) ) );
1488  SIGNAL( DBConnectionNotNeededAnymore() ),
1489  this,
1490  SLOT( CloseDBConnection() ) );
1492  SIGNAL( AddNewTraceIDInTS(std::pair< std::string, QColor > ) ),
1493  this->m_TraceSettingsWidget,
1494  SLOT( AddANewCollectionID(std::pair< std::string, QColor > ) ) );
1496  SIGNAL( AddNewTraceIDInTS(std::pair< std::string, QColor > ) ),
1498  SLOT( AddANewCollectionID(std::pair< std::string, QColor > ) ) );
1500  SIGNAL( PrintMessage(QString, int) ),
1501  this,
1502  SIGNAL( PrintMessage(QString, int) ) );
1503 
1504  //related to traceEditingWidget and meshes_manager (celltype + subcelltype +
1505  // collectionData + colordata):
1514 }
1515 
1516 //--------------------------------------------------------------------------
1517 
1518 //--------------------------------------------------------------------------
1520 {
1522 
1524  SIGNAL( TraceColorToChange() ),
1525  this, SLOT( ChangeTrackColor() ) );
1526  QObject::connect( this->m_TracksManager, SIGNAL( CheckedTracesToDelete() ),
1527  this, SLOT( DeleteCheckedTracks() ) );
1528  QObject::connect( this->m_TracksManager, SIGNAL( NeedToGetDatabaseConnection() ),
1529  this, SLOT( PassDBConnectionToTracksManager() ) );
1531  SIGNAL( NeedToGoToTheRealLocation(double, double, double, int) ),
1532  this, SIGNAL( NeedToGoToTheRealLocation(double, double, double, int) ) );
1534  SIGNAL( DBConnectionNotNeededAnymore() ),
1535  this,
1536  SLOT( CloseDBConnection() ) );
1537  QObject::connect( this->m_TracksManager, SIGNAL( NeedToGetDatabaseConnection() ),
1538  this, SLOT( PassDBConnectionToTracksManager() ) );
1540  SIGNAL( DBConnectionNotNeededAnymore() ),
1541  this,
1542  SLOT( CloseDBConnection() ) );
1544  SIGNAL( TrackToSplit(unsigned int, std::list< unsigned int > ) ),
1545  this,
1546  SLOT( SplitTheTrack(unsigned int,
1547  std::list< unsigned int > ) ) );
1549  SIGNAL( TrackIDToBeModifiedWithWidget(std::list< unsigned int > ) ),
1550  this,
1551  SLOT( SplitMergeTracksWithWidget(std::list< unsigned int > ) ) );
1553  SIGNAL( MeshesToAddToTrack(std::list< unsigned int >, unsigned int) ),
1554  this,
1555  SLOT( AddListMeshesToATrack(std::list< unsigned int >, unsigned int) ) );
1557  SIGNAL( AddNewTraceIDInTS(std::pair< std::string, QColor > ) ),
1558  this->m_TraceSettingsWidget,
1559  SLOT( AddANewCollectionID(std::pair< std::string, QColor > ) ) );
1561  SIGNAL( AddNewTraceIDInTS(std::pair< std::string, QColor > ) ),
1563  SLOT( AddANewCollectionID(std::pair< std::string, QColor > ) ) );
1565  SIGNAL( PrintMessage(QString, int) ),
1566  this,
1567  SIGNAL( PrintMessage(QString, int) ) );
1568 
1570  SIGNAL(CheckedTracksToAddToSelectedLineage(
1571  std::list< unsigned int >, unsigned int,
1572  std::list<unsigned int> ) ), this,
1573  SLOT( AddCheckedTracksToSelectedLineage(std::list< unsigned int >, unsigned int,
1574  std::list<unsigned int> ) ) );
1575 
1577  SIGNAL ( NewLineageToCreateFromTracks( std::list<unsigned int>, unsigned int,
1578  std::list<unsigned int> )),
1579  this,
1580  SLOT( CreateNewLineageFromTracks(std::list< unsigned int >, unsigned int,
1581  std::list<unsigned int> ) ) );
1582 
1586 }
1587 
1588 //--------------------------------------------------------------------------
1589 
1590 //--------------------------------------------------------------------------
1592 {
1594 
1596  SIGNAL( NeedToGetDatabaseConnection() ),
1597  this,
1600  SIGNAL( DBConnectionNotNeededAnymore() ),
1601  this,
1602  SLOT( CloseDBConnection() ) );
1604  SIGNAL( CheckedTracesToDelete() ),
1605  this,
1606  SLOT( DeleteCheckedLineages() ) );
1607  /*
1608  \todo Nicolas - change color
1609  */
1610 
1612  SIGNAL( TraceColorToChange() ),
1613  this,
1614  SLOT( ChangeLineageColor() ) );
1615 
1617 }
1618 //--------------------------------------------------------------------------
1619 
1620 //--------------------------------------------------------------------------
1622 {
1623  this->OpenDBConnection();
1625 }
1626 
1627 //--------------------------------------------------------------------------
1628 
1629 //--------------------------------------------------------------------------
1631 {
1632  this->OpenDBConnection();
1634 }
1635 
1636 //--------------------------------------------------------------------------
1637 
1638 //--------------------------------------------------------------------------
1640 {
1641  this->OpenDBConnection();
1643 }
1644 
1645 //--------------------------------------------------------------------------
1646 
1647 //--------------------------------------------------------------------------
1649 {
1650  this->OpenDBConnection();
1652 }
1653 
1654 //--------------------------------------------------------------------------
1655 
1656 //--------------------------------------------------------------------------
1657 void QGoPrintDatabase::ReEditTrace(unsigned int iTraceID)
1658 {
1659  this->m_ReeditMode = true;
1660  emit TraceToReEdit(iTraceID);
1661 }
1662 
1663 //--------------------------------------------------------------------------
1664 
1665 //--------------------------------------------------------------------------
1667 {
1668  std::list< unsigned int > TrackIDs;
1669  TrackIDs.push_back(iTrackID);
1670  this->OpenDBConnection();
1671  //get the meshesID that have iTrackID as a collectionID:
1672  std::list< unsigned int > ListMeshesIDs =
1674  this->m_DatabaseConnector, TrackIDs);
1675 
1676  if ( !ListMeshesIDs.empty() )
1677  {
1678  //get the coordinate info from the meshes:
1679  std::map< unsigned int, double * > MeshesInfo = this->m_MeshesManager->
1680  GetMeshesInfoForImportedMesh(ListMeshesIDs);
1681  if ( !MeshesInfo.empty() )
1682  {
1683  //pass the coordinate info from the meshes in order to calculate the
1684  //points/string of the track:
1686  MeshesInfo, this->m_DatabaseConnector);
1687  }
1688  }
1689  this->CloseDBConnection();
1690 }
1691 
1692 //--------------------------------------------------------------------------
1693 
1694 //--------------------------------------------------------------------------
1695 void QGoPrintDatabase::SplitTheTrack(unsigned int iTrackID,
1696  std::list< unsigned int > iListMeshIDs)
1697 {
1698  this->OpenDBConnection();
1699  std::list< unsigned int > ListMeshesForNewTrack =
1701  iTrackID, this->m_DatabaseConnector, iListMeshIDs);
1702  if(ListMeshesForNewTrack.size() != 0)
1703  {
1704  this->CreateNewTrackFromListMeshes(ListMeshesForNewTrack);
1705  }
1706  this->CloseDBConnection();
1707 }
1708 
1709 //--------------------------------------------------------------------------
1710 
1711 //--------------------------------------------------------------------------
1713  std::list< unsigned int > iListCheckedMeshes)
1714 {
1715  this->OpenDBConnection();
1716  unsigned int NewTrackID =
1718  this->m_DatabaseConnector);
1719  std::list< std::pair<unsigned int, double> > temp;
1720 
1721  std::list< unsigned int > ListMeshToBelongToTheTrack;
1722  std::list< unsigned int > ListMeshToReassign;
1723 
1724  std::string MessageToPrint =
1726  this->m_DatabaseConnector, iListCheckedMeshes,
1727  ListMeshToBelongToTheTrack, ListMeshToReassign);
1728 
1729  // remove all meshes from previous track avg_volume, from mesh ID
1730  temp = this->m_MeshesManager->GetListVolumes(ListMeshToBelongToTheTrack);
1731  // update tracks volumes
1732  // do remove add at same time?
1733  this->m_TracksManager->RemoveVolumes(temp);
1734 
1735  // strategy:
1736  // 1-delete previous division
1737  // 2-create new track
1738  // 3-create new division
1739  // therefore we ensure to have a correct lineage tree
1740 
1741  // Get old track mother and 2 daughters from database
1742  unsigned int oldMotherID = 0;
1743  unsigned int oldTrackID = 0;
1744  unsigned int newTrackID = NewTrackID;
1745  unsigned int oldDaughter = 0;
1746 
1747  std::list< std::pair<unsigned int, double> >::const_iterator it =
1748  temp.begin();
1749  if(it != temp.end())
1750  {
1751  oldTrackID = (*it).first;
1752  }
1753 
1754  // get track family from daughter
1755  std::vector<unsigned int> family =
1756  this->m_TracksManager->GetTrackFamily(this->m_DatabaseConnector, oldTrackID);
1757  // if track belongs to a lineage
1758  if(family.size() > 0)
1759  {
1760  oldMotherID = family[1];
1761  if(family[2] == oldTrackID)
1762  {
1763  oldDaughter = family[3];
1764  }
1765  else
1766  {
1767  oldDaughter = family[2];
1768  }
1769  // Delete old track mother division
1770  std::list<unsigned int> oldList;
1771  oldList.push_back(oldMotherID);
1772  this->m_TracksManager->DeleteTheDivisions(oldList);
1773  }
1774 
1775  //at that moment, do nothing for the checked meshes not selected to be part of
1776  // the track
1777  if ( MessageToPrint != "" )
1778  {
1779  emit PrintMessage( MessageToPrint.c_str() );
1780  }
1781 
1782  // remove all meshes from previous track avg_volume, from mesh ID
1783  //temp = this->m_MeshesManager->GetListVolumes(ListMeshToBelongToTheTrack);
1784  // update tracks volumes
1785  this->m_TracksManager->AddVolumes(temp, NewTrackID);
1786  this->AddCheckedTracesToCollection< QGoDBMeshManager, QGoDBTrackManager >(
1787  this->m_MeshesManager, this->m_TracksManager,
1788  NewTrackID, ListMeshToBelongToTheTrack);
1789 
1790  // if track belongs to a lineage
1791  if(family.size() > 0)
1792  {
1793  // Create division old mother and new daughter
1794  std::list<unsigned int> newdaughter;
1795  newdaughter.push_back(oldMotherID);
1796  newdaughter.push_back(oldDaughter);
1797  newdaughter.push_back(newTrackID);
1798  this->m_TracksManager->CreateCorrespondingTrackFamily(newdaughter);
1799  }
1800 
1801  this->CloseDBConnection();
1802 }
1803 
1804 //--------------------------------------------------------------------------
1805 
1806 //--------------------------------------------------------------------------
1808  std::list< std::list< unsigned int > > iListsCheckedMeshes)
1809 {
1810  std::list< std::list< unsigned int > >::iterator iter = iListsCheckedMeshes.begin();
1811  while ( iter != iListsCheckedMeshes.end() )
1812  {
1814  ++iter;
1815  }
1816 }
1817 
1818 //--------------------------------------------------------------------------
1819 
1820 //--------------------------------------------------------------------------
1821 
1823  std::list< unsigned int > iListCheckedContours)
1824 {
1825  this->OpenDBConnection();
1826  unsigned int NewMeshID =
1828  this->m_DatabaseConnector);
1829 
1830  this->AddCheckedTracesToCollection< QGoDBContourManager, QGoDBMeshManager >(
1831  this->m_ContoursManager, this->m_MeshesManager,
1832  NewMeshID, iListCheckedContours);
1833 
1834  this->m_MeshGenerationMode = true;
1835  emit NewMeshToGenerate(iListCheckedContours, NewMeshID);
1836  this->CloseDBConnection();
1837 }
1838 
1839 //--------------------------------------------------------------------------
1840 
1841 //--------------------------------------------------------------------------
1843  std::list< unsigned int > iListCheckedTracks, unsigned int iTrackRoot,
1844  std::list< unsigned int > iListLineagesToDelete)
1845 {
1846  this->OpenDBConnection();
1847  unsigned int NewLineageID =
1849  this->m_DatabaseConnector, iTrackRoot);
1850 
1852  (iListCheckedTracks, NewLineageID, iListLineagesToDelete);
1853 
1854  this->CloseDBConnection();
1855 }
1856 //--------------------------------------------------------------------------
1857 
1858 //--------------------------------------------------------------------------
1859 void QGoPrintDatabase::AddCheckedContoursToSelectedMesh(std::list< unsigned int > iListCheckedContours)
1860 {
1861  this->OpenDBConnection();
1862  this->AddCheckedTracesToCollection< QGoDBContourManager, QGoDBMeshManager >
1863  (this->m_ContoursManager, this->m_MeshesManager,
1864  this->m_TraceSettingsWidget->GetCurrentSelectedCollectionID(), iListCheckedContours);
1865  this->CloseDBConnection();
1866 }
1867 
1868 //--------------------------------------------------------------------------
1869 
1870 //--------------------------------------------------------------------------
1871 void
1873 AddListMeshesToATrack(std::list< unsigned int > iListMeshes, unsigned int iTrackID)
1874 {
1875  this->OpenDBConnection();
1876  std::list< unsigned int > ListMeshToBelongToTheTrack;
1877  std::list< unsigned int > ListNullMeshToBelongToTheTrack;
1878  std::list< std::pair<unsigned int, double> > temp;
1879 
1880  if ( iTrackID == 0 )
1881  {
1882  ListMeshToBelongToTheTrack = iListMeshes;
1883  }
1884  else
1885  {
1886  // list the meshes which will not be moved
1887  // i.e. if we try to move 2 points belonging to T0,
1888  // the smallest ID will not move
1889  std::list< unsigned int > ListMeshToReassign;
1890  std::string MessageToPrint =
1892  this->m_DatabaseConnector, iListMeshes,
1893  ListMeshToBelongToTheTrack, ListMeshToReassign);
1894 
1895  // remove all meshes from previous track avg_volume, from mesh ID
1896  temp = this->m_MeshesManager->GetListVolumes(ListMeshToBelongToTheTrack);
1897  // update tracks volumes
1898  this->m_TracksManager->RemoveVolumes(temp);
1899 
1900  // if there is already a mesh at the same time point in the track,
1901  // change the mesh's track id to 0
1902  MessageToPrint +=
1904  iTrackID, this->m_DatabaseConnector,
1905  ListMeshToBelongToTheTrack, ListNullMeshToBelongToTheTrack).toStdString();
1906 
1907  // remove meshes assigned to 0
1908  temp = this->m_MeshesManager->GetListVolumes(ListNullMeshToBelongToTheTrack);
1909  this->m_TracksManager->RemoveVolumes(temp, iTrackID);
1910  // add meshes to next track average volume, from Mesh ID
1911  temp = this->m_MeshesManager->GetListVolumes(ListMeshToBelongToTheTrack);
1912  this->m_TracksManager->AddVolumes(temp, iTrackID);
1913 
1914  if ( MessageToPrint != "" )
1915  {
1916  emit PrintMessage( MessageToPrint.c_str() );
1917  }
1918  }
1919 
1920  // assign meshes to the track since we have cleaned the track now
1921  this->AddCheckedTracesToCollection< QGoDBMeshManager, QGoDBTrackManager >(
1922  this->m_MeshesManager, this->m_TracksManager,
1923  iTrackID, ListMeshToBelongToTheTrack);
1924 
1925  // update the visualization container!
1926  this->m_MeshesManager->ModifyTrackIDInVisuContainer(iTrackID,
1927  ListMeshToBelongToTheTrack,
1928  ListNullMeshToBelongToTheTrack);
1929 
1930  this->CloseDBConnection();
1931 }
1932 
1933 //--------------------------------------------------------------------------
1934 
1935 //--------------------------------------------------------------------------
1937  std::map< unsigned int, std::list< unsigned int > > iListMeshesWithTracks)
1938 {
1939  std::map< unsigned int, std::list< unsigned int > >::iterator iter =
1940  iListMeshesWithTracks.begin();
1941  while ( iter != iListMeshesWithTracks.end() )
1942  {
1943  AddListMeshesToATrack(iter->second, iter->first);
1944  ++iter;
1945  }
1946 }
1947 
1948 //--------------------------------------------------------------------------
1949 
1950 //--------------------------------------------------------------------------
1951 void QGoPrintDatabase::AddCheckedMeshesToSelectedTrack(std::list< unsigned int > iListCheckedMeshes)
1952 {
1953  unsigned int SelectedTrackID =
1955 
1956  this->AddListMeshesToATrack(iListCheckedMeshes, SelectedTrackID);
1957 }
1958 
1959 //--------------------------------------------------------------------------
1960 
1961 //--------------------------------------------------------------------------
1963  std::list< unsigned int > iTrackIDs)
1964 {
1965  this->OpenDBConnection();
1966  MeshContainer *MeshContainerTemp = this->m_MeshesManager->
1967  GetMeshesInfoFromDBAndCreateContainerForVisu(
1968  this->m_DatabaseConnector, iTrackIDs);
1969 
1970  QGoTrackEditingWidget *win = new QGoTrackEditingWidget(MeshContainerTemp);
1971  win->init();
1972 
1973  if ( win->exec() )
1974  {
1975  std::list< std::list< unsigned int > > ListTracksToCreate =
1977  std::map< unsigned int, std::list< unsigned int > > ListTracksToUpdate =
1979  //std::list< unsigned int > ListTracksToDelete =
1980  // win->GetListOfTracksToBeDeleted();
1981  if ( !ListTracksToCreate.empty() )
1982  {
1983  this->CreateNewTrackFromListMeshes(ListTracksToCreate);
1984  }
1985  if ( !ListTracksToUpdate.empty() )
1986  {
1987  this->AddListMeshesToATrack(ListTracksToUpdate);
1988  }
1989  /*if ( !ListTracksToDelete.empty() )
1990  {
1991  this->DeleteListTraces< QGoDBTrackManager, QGoDBMeshManager, QGoDBMeshManager >(
1992  this->m_TracksManager, this->m_MeshesManager, this->m_MeshesManager,
1993  ListTracksToDelete);
1994  }*/
1995  }
1996  delete win;
1997 }
1998 //--------------------------------------------------------------------------
1999 
2000 //--------------------------------------------------------------------------
2002  std::list<unsigned int> iListDaughters, unsigned int iLineageID,
2003  std::list<unsigned int> iListLineagesToDelete)
2004 {
2005  if (!iListLineagesToDelete.empty() )
2006  {
2007  this->DeleteListTraces< QGoDBLineageManager, QGoDBLineageManager > (
2009  iListLineagesToDelete, true);
2010  }
2011 
2012  if (!iListDaughters.empty() )
2013  {
2014  this->OpenDBConnection();
2015 
2016  this->AddCheckedTracesToCollection< QGoDBTrackManager, QGoDBLineageManager >(
2017  this->m_TracksManager, this->m_LineagesManager, iLineageID, iListDaughters);
2018 
2019  this->CloseDBConnection();
2020  }
2021 }
2022 //--------------------------------------------------------------------------
2023 
2024 //--------------------------------------------------------------------------
2026 {
2027  this->m_TraceSettingsWidget->setVisible(isVisible);
2029 }
2030 //--------------------------------------------------------------------------
2031 
2032 //--------------------------------------------------------------------------
2034  {
2035  if (!this->isVisible() )
2036  {
2037  return true;
2038  }
2039  if(this->isFloating())
2040  {
2041  return false;
2042  }
2043  return !this->m_TraceSettingsVisible;
2044  }
2045 //--------------------------------------------------------------------------
2046 
2047 //--------------------------------------------------------------------------
2048 std::list<unsigned int>
2051  const unsigned int& iNewTimePoint)
2052 {
2053  this->OpenDBConnection();
2054 
2055  if(this->m_VisibleTimePoints.size() > 0)
2056  {
2057  // list to be removed
2058  std::list<unsigned int> listToRemove;
2059  listToRemove = m_VisibleTimePoints;
2060  // iterator
2061  std::list<unsigned int>::iterator it_listToRemove = listToRemove.begin();
2062 
2063  // list to be added
2064  std::list<unsigned int> listToAdd;
2065  if(iNewTimePoint>0)
2066  {
2067  listToAdd.push_back(iNewTimePoint-1);
2068  }
2069  listToAdd.push_back(iNewTimePoint);
2070  listToAdd.push_back(iNewTimePoint+1);
2071  // iterator
2072  std::list<unsigned int>::iterator it_listToAdd = listToAdd.begin();
2073  m_VisibleTimePoints = listToAdd;
2074 
2075  // list common t points
2076  std::list<unsigned int> listCommonT;
2077  while(it_listToRemove != listToRemove.end())
2078  {
2079  while(it_listToAdd != listToAdd.end())
2080  {
2081  if(*it_listToRemove == *it_listToAdd)
2082  {
2089  listCommonT.push_back(*it_listToRemove);
2090  }
2091  ++it_listToAdd;
2092  }
2093  it_listToAdd = listToAdd.begin();
2094  ++it_listToRemove;
2095  }
2096 
2097  // remove common t points
2098  // iterator
2099  std::list<unsigned int>::iterator it_listCommonT = listCommonT.begin();
2100  while(it_listCommonT != listCommonT.end())
2101  {
2102  listToRemove.remove(*it_listCommonT);
2103  listToAdd.remove(*it_listCommonT);
2104  ++it_listCommonT;
2105  }
2106 
2107  // remove time points
2108  if(listToRemove.size() > 0)
2109  {
2111  this->m_DatabaseConnector, listToRemove);
2113  this->m_DatabaseConnector, listToRemove);
2114  }
2115 
2116 
2117  // add time points
2118  if(listToAdd.size() > 0)
2119  {
2120  this->m_ContoursManager->
2121  DisplayInfoAndLoadVisuContainerForAllContoursForSpecificTPs(
2122  this->m_DatabaseConnector,
2123  listToAdd);
2124  this->m_MeshesManager->
2125  DisplayInfoAndLoadVisuContainerForAllMeshesForSpecificTPs(
2126  this->m_DatabaseConnector,
2127  listToAdd);
2128  }
2129 
2130  this->CloseDBConnection();
2131  return listToAdd;
2132  }
2133 
2134  return this->m_VisibleTimePoints;
2135 
2136 }
2137 //--------------------------------------------------------------------------
2138 
2139 //--------------------------------------------------------------------------
2140 std::list<unsigned int>
2143 {
2144  return m_VisibleTimePoints;
2145 }
2146 //--------------------------------------------------------------------------
2147 
2148 //--------------------------------------------------------------------------
2149 int
2151 GetNumberOfElementForTraceAndTimePoint(std::string iTrace, int iTimePoint)
2152 {
2153  this->OpenDBConnection();
2155  this->m_DatabaseConnector,
2156  this->m_ImgSessionID,
2157  iTrace,
2158  iTimePoint);
2159  this->CloseDBConnection();
2160  return test;
2161 }