GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoPrintDatabase.h
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 #ifndef __QGoPrintDatabase_h
35 #define __QGoPrintDatabase_h
36 
37 #include <QDockWidget>
38 #include <QTableWidget>
39 #include <QColor>
40 #include <string>
41 #include <QStackedWidget>
42 #include "MegaVTK2Configure.h"
43 #include "GoDBRecordSet.h"
44 #include "GoDBContourRow.h"
45 #include "vtkMySQLDatabase.h"
46 #include "vtkPolyData.h"
47 #include "GoDBTraceInfoForVisu.h"
48 #include "ContourMeshStructure.h"
49 #include "TraceInfoStructure.h"
50 #include "QGoDBBookmarkManager.h"
51 #include "QGoGUILibConfigure.h"
52 #include "GoFigureMeshAttributes.h"
53 #include "QGoTraceSettingsWidget.h"
54 #include "QGoDBCellTypeManager.h"
56 #include "QGoDBColorManager.h"
57 #include "QGoDBMeshManager.h"
58 #include "QGoDBContourManager.h"
59 #include "QGoDBTrackManager.h"
60 #include "QGoDBLineageManager.h"
61 #include "ContourContainer.h"
62 #include "MeshContainer.h"
63 #include "TrackContainer.h"
64 #include "QGoDockWidget.h"
76 class QGOGUILIB_EXPORT QGoPrintDatabase:public QGoDockWidget
77 {
78  Q_OBJECT
79 public:
80 
82  explicit QGoPrintDatabase(QWidget *iParent = 0);
83 
85  virtual ~QGoPrintDatabase();
86 
90  typedef std::pair< int, QColor > IDWithColorData;
91 
93  void SetDatabaseVariables(
94  const std::string & iNameDB, const std::string & iServer,
95  const std::string & iUser, const std::string & iPassword,
96  const unsigned int & iImgSessionID, const std::string & iImgSessionName);
97 
101  void FillTableFromDatabase( const unsigned int& iTreshold);
102 
104  std::vector< ContourMeshStructure > GetContoursForAGivenTimepoint(
105  unsigned int iTimePoint);
106 
108  std::vector< ContourMeshStructure > GetMeshesForAGivenTimepoint(
109  unsigned int iTimePoint);
110 
117  void SaveContoursFromVisuInDB(unsigned int iXCoordMin,
118  unsigned int iYCoordMin, unsigned int iZCoordMin, unsigned int iTCoord,
119  unsigned int iXCoordMax, unsigned int iYCoordMax, unsigned int iZCoordMax,
120  vtkPolyData *iContourNodes);
121 
130  void SaveMeshFromVisuInDB(unsigned int iXCoordMin,
131  unsigned int iYCoordMin,
132  unsigned int iZCoordMin,
133  unsigned int iXCoordMax,
134  unsigned int iYCoordMax,
135  unsigned int iZCoordMax,
136  int iTCoord,
137  vtkPolyData *iMeshNodes,
138  GoFigureMeshAttributes *iMeshAttributes,
139  int iTrackID = -1);
140 
153  unsigned int SaveNewContourForMeshToContours(unsigned int iXCoordMin,
154  unsigned int iYCoordMin,
155  unsigned int iZCoordMin,
156  unsigned int iXCoordMax,
157  unsigned int iYCoordMax,
158  unsigned int iZCoordMax,
159  vtkPolyData *iTraceNodes);
160 
161  void AddBookmark(int iXCoord, int iYCoord,
162  int iZCoord, int iTCoord);
163 
166  std::string InWhichTableAreWe();
167 
168  NamesDescrContainerType GetListBookmarks();
169 
170  GoDBCoordinateRow GetCoordinateForBookmark(std::string iName);
171 
174  bool IsDatabaseUsed();
175 
176  //QAction * toggleViewAction();
177 
182  void ImportContours();
183 
188  void ImportMeshes();
189 
196  std::vector<int> ImportTracks();
197 
204  void PrintVolumeAreaForMesh(GoFigureMeshAttributes *
205  iMeshAttributes, unsigned int iMeshID);
206 
213  void PrintCalculatedValuesForTrack(GoFigureTrackAttributes *
214  iTrackAttributes, unsigned int iTrackID);
215 
217  QGoTraceSettingsWidget* GetTraceSettingsWidget();
218 
219  QGoTraceSettingsWidget* GetTraceSettingsWidgetForToolBar();
220 
227  void SetTraceNameForTableWidget(std::string iTraceName);
228 
231  void InitializeTheComboboxesNotTraceRelated();
232 
239  void SetContoursContainer(ContourContainer *iContoursContainer);
240 
247  void SetMeshesContainer(MeshContainer *iMeshesContainer);
248 
255  void SetTracksContainer(TrackContainer *iContainer);
256 
264  void SetLineagesContainers(LineageContainer *iContainer,
265  TrackContainer *iTrackContainer);
266 
271  bool NeedTraceSettingsToolBarVisible();
272 
279  std::list<unsigned int> UpdateTableWidgetAndContainersForGivenTimePoint(
280  const unsigned int& iNewTimePoint);
281 
282  std::list<unsigned int> GetVisibleTimePoints();
283 
284  int GetNumberOfElementForTraceAndTimePoint(std::string iTrace, int iTimePoint);
285 
286 public slots:
287  void DeleteBookmarks();
288 
289  //void SetTable(std::string iTablename);
290 
291  void ExportContours();
292 
293  void ExportMeshes();
294 
295  void UpdateSelectedTimePoint(int iTimePoint);
296 
297  void SaveNewMeshForMeshToContours(int iNumberOfContours);
298 
299 signals:
300  void PrintDBReady();
301 
302  void DBVariablesSet();
303 
304  void TraceToReEdit(unsigned int);
305 
306  void OpenBookmarksToUpdate();
307 
308  void NewMeshToGenerate(std::list< unsigned int > ListContourIDs, int iNewMeshID);
309 
314  void NeedToGoToTheLocation(int XCoord, int YCoord, int ZCoord, int TCoord);
315 
316  void NeedToGoToTheRealLocation(double XCoord, double YCoord, double ZCoord, int TCoord);
317 
318  void PrintMessage(QString iMessage, int iTimeOut = 0);
319 
320 protected:
321  //related to 3dwt:
324 
325  //related to TraceSettings Widget:
331 
337 
338  //Database variables:
339  vtkMySQLDatabase* m_DatabaseConnector;
340  std::string m_Server;
341  std::string m_User;
342  std::string m_Password;
343  std::string m_DBName;
344  unsigned int m_ImgSessionID;
345  std::string m_ImgSessionName;
347 
351 
352  void OpenDBConnection();
353 
354  void SetUpUi();
355 
360  void SetConnectionsBetweenTheInstancesOfTraceSettings();
364  void SetContoursManager();
365 
369  void SetMeshesManager();
370 
374  void SetTracksManager();
375 
379  void SetLineagesManager();
380 
381  //******************Methods related to Trace Settings Editing Widget***********
382 
387  void CreateConnectionsForTraceSettingsWidget(QGoTraceSettingsWidget* iTraceSettingsWidget);
388 
395  void SetTSListCellTypes(std::string iCellTypeToSelect = "");
396 
402  void SetTSListCellTypesWithPreviousSelectedOne();
403 
410  void SetTSListSubCellTypes(std::string iSubCellTypeToSelect = "");
411 
417  void SetTSListSubCellTypesWithPreviousSelectedOne();
418 
425  void SetTSListColors(std::string iColorToSelect = "");
426 
432  void SetTSListColorsWithPreviousSelectedOne();
433 
434  //******************End of Methods related to Trace Settings Editing
435  // Widget***********
436 
442  std::list< ItemColorComboboxData > GetListCollectionIDFromDB(
443  vtkMySQLDatabase *iDatabaseConnector, std::string & ioIDToSelect);
444 
445  //void closeEvent(QCloseEvent *event);
446 
450  void SetTracesManager();
451 
457  void GetContentAndDisplayAllTracesInfo(vtkMySQLDatabase *iDatabaseConnector);
458 
459  void GetContentAndDisplayAllTracesInfoFor3TPs(vtkMySQLDatabase *iDatabaseConnector);
460 
461  void RemoveTracesFromListTimePoints(
462  vtkMySQLDatabase *iDatabaseConnector, std::list<unsigned int> iListTimePoints);
463 
471  /*template< typename T >
472  QColor GetQColorFromTraceRow(T iTraceRow, vtkMySQLDatabase *iDatabaseConnector)
473  {
474  GoDBColorRow ColorRow;
475 
476  ColorRow.SetValuesForSpecificID(iTraceRow.GetMapValue<int>("ColorID"),
477  iDatabaseConnector);
478  QColor Color( ColorRow.GetMapValue<int>("Red"),
479  ColorRow.GetMapValue<int>("Green"),
480  ColorRow.GetMapValue<int>("Blue"),
481  ColorRow.GetMapValue<int>("Alpha") );
482  return Color;
483  }
484 */
491  template< typename T >
492  void SetTheColorForTheRow(T & ioRow, QColor iColor)
493  {
494  ioRow.SetField( "Red", iColor.red() );
495  ioRow.SetField( "Green", iColor.green() );
496  ioRow.SetField( "Blue", iColor.blue() );
497  ioRow.SetField( "Alpha", iColor.alpha() );
498  }
499 
508  template< typename TTrace, typename TCollection >
509  void ChangeTraceColor(TTrace *iTraceManager,
510  TCollection *iCollectionOfManager)
511  {
512  this->OpenDBConnection();
513  //update everything for the traces and get the list of collection ID they
514  //are collection of:
515  std::list< unsigned int > ListCollectionOfIDsToUpdate =
516  iTraceManager->UpdateTheTracesColor(this->m_DatabaseConnector);//, *this->m_SelectedColorData);
517  iCollectionOfManager->DisplayInfoForExistingTraces(this->m_DatabaseConnector,
518  ListCollectionOfIDsToUpdate);
519  this->CloseDBConnection();
520  }
521 
535  template< typename TTrace, typename TCollection, typename TCollectionOf >
536  void DeleteCheckedTraces(TTrace *iTraceManager,
537  TCollection *iCollectionManager, TCollectionOf *iCollectionOfManager,
538  bool lineage = false)
539  //bool track = false)
540  {
541  std::list< unsigned int > ListTracesToDelete =
542  iTraceManager->GetListHighlightedIDs();
543  std::list<unsigned int> ListCollectionsIDs =
544  this->UpdateCollectionDataForTracesToBeDeleted<TTrace, TCollectionOf>
545  (iTraceManager, iCollectionOfManager, ListTracesToDelete);
546  this->OpenDBConnection();
547  iTraceManager->DeleteCheckedTraces(this->m_DatabaseConnector);
548 
549  if ( !ListCollectionsIDs.empty() || !lineage )
550  {
551  this->OpenDBConnection(); //in some cases the DeleteCheckedTraces closes the connection
552  iCollectionManager->UpdateBoundingBoxes(this->m_DatabaseConnector, ListCollectionsIDs);
553  }
554  this->CloseDBConnection();
555  }
556 
569  template< typename TTrace, typename TCollection, typename TCollectionOf >
570  void DeleteListTraces(TTrace *iTraceManager,
571  TCollection *iCollectionManager, TCollectionOf *iCollectionOfManager,
572  std::list<unsigned int> iListTracesToDelete,
573  bool lineage = false)
574  {
575  std::list<unsigned int> ListCollectionsIDs =
576  this->UpdateCollectionDataForTracesToBeDeleted<TTrace, TCollectionOf>
577  (iTraceManager, iCollectionOfManager, iListTracesToDelete);
578  this->OpenDBConnection();
579  iTraceManager->DeleteListTraces(this->m_DatabaseConnector, iListTracesToDelete);
580 
581  if ( !ListCollectionsIDs.empty() || !lineage )
582  {
583  iCollectionManager->UpdateBoundingBoxes(this->m_DatabaseConnector, ListCollectionsIDs);
584  }
585  this->CloseDBConnection();
586  }
595  template< typename TTrace, typename TCollectionOf >
596  std::list<unsigned int> UpdateCollectionDataForTracesToBeDeleted(TTrace *iTraceManager,
597  TCollectionOf *iCollectionOfManager,
598  std::list<unsigned int> iListTracesToDelete)
599  {
600  this->OpenDBConnection();
601  //need to get all the needed data from the traces before deleting them:
602  std::list< unsigned int > ListCollectionsIDs =
603  iTraceManager->GetListCollectionIDs(this->m_DatabaseConnector, iListTracesToDelete);
604  std::list< unsigned int > ListTracesAsCollectionOf =
605  iTraceManager->GetListTracesIDsFromThisCollectionOf(this->m_DatabaseConnector,
606  iListTracesToDelete);
607  if ( !ListTracesAsCollectionOf.empty() )
608  {
609  iCollectionOfManager->UpdateCollectionID(this->m_DatabaseConnector,
610  ListTracesAsCollectionOf, 0);
611  }
612  this->CloseDBConnection();
613  return ListCollectionsIDs;
614  }
626  template< typename TTrace, typename TCollection >
628  TTrace *iTraceManager,
629  TCollection *iCollectionManager, unsigned int iCollectionID,
630  std::list< unsigned int > iListCheckedTraces)
631  {
632  this->OpenDBConnection();
633  //get the list of CollectionIDs that will be updated:
634  std::list< unsigned int > ListCollectionIDsToUpdate =
635  iTraceManager->GetListCollectionIDs(this->m_DatabaseConnector,
636  iListCheckedTraces);
637 
638  iTraceManager->UpdateCollectionID(this->m_DatabaseConnector,
639  iListCheckedTraces, iCollectionID);
640 
641  if (iCollectionID != 0)
642  {
643  ListCollectionIDsToUpdate.push_back(iCollectionID);
644  }
645  iCollectionManager->UpdateBoundingBoxes(this->m_DatabaseConnector,
646  ListCollectionIDsToUpdate);
647  this->CloseDBConnection();
648  }
649 
650  void UpdateSelectedCollectionForTableWidget(std::string iTableName);
651 
652 //-------------------------------------------------------------------------
653 
654 //-------------------------------------------------------------------------
655 protected slots:
656  void CreateContextMenu(const QPoint & iPos);
657 
662  void ShowHideTraceSettingsFromContextMenu(bool isVisible);
663 
667  void TheTraceHasChanged(int iIndex);
668 
676  void SetTSListCollectionID();
677 
681  void PassDBConnectionToContoursManager();
682 
686  void PassDBConnectionToMeshesManager();
687 
691  void PassDBConnectionToTracksManager();
692 
696  void PassDBConnectionToLineagesManager();
697 
698  void CloseDBConnection();
703  void ChangeMeshColor();
704 
709  void ChangeTrackColor();
710 
715  void ChangeLineageColor();
716 
721  void DeleteCheckedContours();
722 
727  void DeleteCheckedMeshes();
728 
733  void DeleteCheckedTracks();
734 
739  void DeleteCheckedLineages();
740 
746  void CreateNewTrackFromListMeshes(std::list< unsigned int > iListMeshes);
747 
751  void CreateNewTrackFromListMeshes(
752  std::list<std::list<unsigned int> > iListsCheckedMeshes);
753 
761  void CreateNewMeshFromCheckedContours(std::list< unsigned int > iListCheckedContours);
762 
770  void CreateNewLineageFromTracks(std::list< unsigned int > iListCheckedTracks,
771  unsigned int iTrackIDRoot, std::list<unsigned int> iLineagesToDelete);
772 
779  void AddCheckedContoursToSelectedMesh(std::list< unsigned int > iListCheckedContours);
780 
787  void AddCheckedMeshesToSelectedTrack(std::list< unsigned int > iListCheckedMeshes);
788 
797  void AddCheckedTracksToSelectedLineage(
798  std::list<unsigned int> iListDaughters, unsigned int iLineageID,
799  std::list<unsigned int> iListLineagesToDelete);
800 
805  void ReEditTrace(unsigned int iTraceID);
806 
813  void PassMeshesInfoForImportedTrack(unsigned int iTrackID);
814 
821  void SplitTheTrack(unsigned int iTrackID, std::list<unsigned int> iListMeshIDs);
822 
830  void SplitMergeTracksWithWidget(std::list<unsigned int> iTrackIDs);
831 
839  void AddListMeshesToATrack(std::list< unsigned int > iListMeshes, unsigned int iTrackID);
840 
844  void AddListMeshesToATrack(
845  std::map<unsigned int, std::list<unsigned int> > iListMeshesWithTracks);
846 
847  //*********************Slots for
848  // TraceManualEditingWidget:**************************
853  void SaveNewCollectionFromTraceWidgetInDBAndTW();
854 
860  void AddNewCellType();
861 
867  void AddNewSubCellType();
868 
874  void AddNewColor();
875 
882  void DeleteCellType();
883 
890  void DeleteSubCellType();
891 
898  void DeleteColor();
899 
900  //**********************End TraceSettingsWidget slots // related****************
901 private:
902  std::list<unsigned int> m_VisibleTimePoints;
903  Q_DISABLE_COPY(QGoPrintDatabase);
904 };
905 
906 #endif
manages all the database components: table widget, trace settings editing widdet, QGoDBTraceManager...
the QGoDBBookmarkManager manages the interactions between the user and the database for the Bookmark ...
GoDBTableWidgetContainer::TWContainerType TWContainerType
the QGoDBSubCellTypeManager manages the interactions between the user and the database for the SubCel...
QGoDBBookmarkManager * m_BookmarkManager
void DeleteCheckedTraces(TTrace *iTraceManager, TCollection *iCollectionManager, TCollectionOf *iCollectionOfManager, bool lineage=false)
delete the checked traces from the database,TW,visu container, udpate the collectionof collectionID i...
void AddCheckedTracesToCollection(TTrace *iTraceManager, TCollection *iCollectionManager, unsigned int iCollectionID, std::list< unsigned int > iListCheckedTraces)
change the collectionIDs to iCollectionID for the traces in iListCheckedTraces, and update the boundi...
QGoDBBookmarkManager::NamesDescrContainerType NamesDescrContainerType
QGoDBMeshManager * m_MeshesManager
std::list< unsigned int > m_VisibleTimePoints
manages a map with keys matching fields of the gofiguredatabase Coordinate table and values of the ma...
QGoDBContourManager * m_ContoursManager
GoDBCollectionOfTraces::TWContainerType TWContainerType
std::string m_Server
QStackedWidget * m_StackedTables
int red() const
Wraps a boost::multi_index_container of ContourMeshStructure. This class is specialized for the means...
QGoDBTrackManager * m_TracksManager
This class manages the database queries, the table widget and the data from the database in the Conta...
QGoTraceSettingsWidget::ItemColorComboboxData ItemColorComboboxData
QGoDBCellTypeManager * m_CellTypeManager
unsigned int m_ImgSessionID
int alpha() const
std::string m_DBName
QGoDBLineageManager * m_LineagesManager
void ChangeTraceColor(TTrace *iTraceManager, TCollection *iCollectionOfManager)
update the color for the checked traces and the rows in the table widget for the collectionOf ...
int green() const
QGoTraceSettingsWidget * m_TraceSettingsWidgetForToolBar
Wraps a boost multi index container of LineageStructure. This class intends to synchronize Lineage re...
std::string m_Password
std::list< unsigned int > UpdateCollectionDataForTracesToBeDeleted(TTrace *iTraceManager, TCollectionOf *iCollectionOfManager, std::list< unsigned int > iListTracesToDelete)
udpate the collectionof collectionID in database and TW
QGoDBColorManager * m_ColorManager
vtkMySQLDatabase * m_DatabaseConnector
this class contains all the comboboxes for collectionID,color, celltypes and subcelltypes, and displays the trace and collection name.
int blue() const
std::pair< int, QColor > IDWithColorData
std::vector< std::pair< std::string, std::string > > NamesDescrContainerType
std::string m_ImgSessionName
Wraps a boost::multi_index_container of ContourMeshStructure. This class is specialized for the means...
Definition: MeshContainer.h:46
QGoColorComboBox::ItemColorComboboxData ItemColorComboboxData
the QGoDBCellTypeManager manages the interactions between the user and the database for the celltype ...
void SetTheColorForTheRow(T &ioRow, QColor iColor)
get the RGB Alpha values from the iTraceRow and set a QColor with them
Wraps a boost multi index container of TrackStructure. This class intends to synchronize Track repres...
QGoDBSubCellTypeManager * m_SubCellTypeManager
This class manages the database queries, the table widget and the data from the database in the Conta...
inherits from Qt QDockWidget.toggle action reimplemented in order the state is saved when changing ta...
Definition: QGoDockWidget.h:47
the QGoDBColorManager manages the interactions between the user and the database for the color DBTabl...
QGoTraceSettingsWidget * m_TraceSettingsWidget
This class manages the database queries, the table widget and the data from the database in the Conta...
This class manages the database queries, the table widget and the data from the database in the Conta...
void DeleteListTraces(TTrace *iTraceManager, TCollection *iCollectionManager, TCollectionOf *iCollectionOfManager, std::list< unsigned int > iListTracesToDelete, bool lineage=false)
delete the traces of iListTracesToDelete from the database,TW, visu container, udpate the collectiono...