GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoCreateImgSessionPage.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 =========================================================================*/
35 #include "QueryDataBaseHelper.h"
37 #include "GoDBImgSessionRow.h"
38 #include "GoDBImageRow.h"
39 #include "GoDBCoordinateRow.h"
40 #include "GoDBChannelRow.h"
41 #include "GoDBColorRow.h"
42 #include "GoDBRecordSetHelper.h"
43 #include "itkMegaCaptureImport.h"
44 #include "ConvertToStringHelper.h"
46 
47 #include <QGridLayout>
48 #include <QFileDialog>
49 #include <QDateTime>
50 #include <QMessageBox>
51 #include <iostream>
52 
54  QWizardPage(iParent)
55 {
56  QFont tfont;
57 
58  tfont.setBold(false);
59  this->setFont(tfont);
60 
61  textNewImgSessionName = new QLabel( tr("Name of the New Imaging Session*: ") );
64  textDescription = new QLabel( tr("Description:") );
65  lineDescription = new QTextEditChild(this, 1000);
66  textChoiceMicroscope = new QLabel( tr("Choose the Microscope used*:") );
68  BrowseButton = new QPushButton("&Browse", this);
69  QLabel *textBrowseButton = new QLabel( tr("Select only 1 file\nfrom the Image Set*:") );
70  lineFilename = new QTextEdit;
71  AddMicroscopeButton = new QPushButton(tr("Add Microscope"), this);
72 
73  QGridLayout *gridlayout = new QGridLayout;
74  gridlayout->addWidget(textNewImgSessionName, 0, 0);
75  gridlayout->addWidget(lineNewImgSessionName, 0, 1);
76  gridlayout->addWidget(textDescription, 1, 0);
77  gridlayout->addWidget(lineDescription, 1, 1);
78  gridlayout->addWidget(textChoiceMicroscope, 2, 0);
79  gridlayout->addWidget(ChoiceMicroscope, 2, 1);
80  gridlayout->addWidget(AddMicroscopeButton, 2, 2);
81 
82  QGridLayout *BrowseButtonLayout = new QGridLayout;
83  BrowseButtonLayout->addWidget(BrowseButton, 0, 2);
84  BrowseButtonLayout->addWidget(textBrowseButton, 0, 0);
85  BrowseButtonLayout->addWidget(lineFilename, 0, 1);
86  BrowseButtonLayout->setColumnStretch (0, 2);
87  BrowseButtonLayout->setColumnStretch (1, 4);
88  BrowseButtonLayout->setColumnStretch (2, 1);
89 
90  QVBoxLayout *vlayout = new QVBoxLayout;
91 
92  vlayout->addLayout(gridlayout);
93  vlayout->addLayout(BrowseButtonLayout);
94  setLayout(vlayout);
95 
96  FirstImage = new QFileInfo;
97  QObject::connect( this->BrowseButton, SIGNAL( clicked() ),
98  this, SLOT( SelectImages() ) );
99  QObject::connect( AddMicroscopeButton, SIGNAL( clicked() ),
100  this, SLOT( AddMicroscopes() ) );
101 }
102 
103 //-------------------------------------------------------------------------
104 
105 //-------------------------------------------------------------------------
107 {
108  delete FirstImage;
109 }
110 
111 //-------------------------------------------------------------------------
112 
113 //-------------------------------------------------------------------------
115 {
116  lineFilename->clear();
118  setSubTitle(
119  tr("Import a new dataset for the project '%1'\n (*fields are required) and click on 'Finish' to load them:")
120  .arg( field("ProjectName").toString() ) );
121 
122  this->UpdateListMicroscopes();
123 }
124 
125 //-------------------------------------------------------------------------
126 
127 //-------------------------------------------------------------------------
129 {
131  this, tr("Import Image"), "", tr("Images (*.png *.bmp *.jpg *.jpeg *tif *.tiff *.mha *.mhd *.img *.lsm)") );
132 
133  lineFilename->setText(filename);
134  FirstImage->setFile(filename);
135 }
136 
137 //-------------------------------------------------------------------------
138 
139 //-------------------------------------------------------------------------
141 {
142  QStringList ListMicroscopes;
143 
144  std::vector< std::string > vectListMicroscopes =
145  ListAllValuesForOneColumn(m_DatabaseConnector, "Name", "microscope");
146 
147  if ( !vectListMicroscopes.empty() )
148  {
149  for ( unsigned int i = 0; i < vectListMicroscopes.size(); ++i )
150  {
151  ListMicroscopes.append( vectListMicroscopes[i].c_str() );
152  }
153  }
154 
155  return ListMicroscopes;
156 }
157 
158 //-------------------------------------------------------------------------
159 
160 //-------------------------------------------------------------------------
161 int QGoCreateImgSessionPage::CreateImgSession(vtkMySQLDatabase *DatabaseConnector)
162 {
163  std::string m_ProjectName = field("ProjectName").toString().toStdString();
164  int TimeInterval = m_HeaderFileInfo.m_TimeInterval;
165  float RealPixelHeight = m_HeaderFileInfo.m_VoxelSizeX;
166  float RealPixelWidth = m_HeaderFileInfo.m_VoxelSizeY;
167  float RealPixelDepth = m_HeaderFileInfo.m_VoxelSizeZ;
168  unsigned int XImageSize = m_HeaderFileInfo.m_DimensionX;
169  unsigned int YImageSize = m_HeaderFileInfo.m_DimensionY;
170  float XTileOverlap = 0; //todo get it from the header file
171  float YTileOverlap = 0; //todo get it from the header file
172  float ZTileOverlap = 0; //todo get it from the header file
173 
174  std::string CreationDateTime = m_HeaderFileInfo.m_CreationDate;
175 
176  GoDBImgSessionRow myNewImgSession;
177 
178  myNewImgSession.SetField( "Name", lineNewImgSessionName->displayText().toStdString() );
179  myNewImgSession.SetField( "Description", this->lineDescription->toPlainText().toStdString() );
180  myNewImgSession.SetField("ImagesTimeInterval", TimeInterval);
181  myNewImgSession.SetField("RealPixelDepth", RealPixelDepth);
182  myNewImgSession.SetField("RealPixelHeight", RealPixelHeight);
183  myNewImgSession.SetField("RealPixelWidth", RealPixelWidth);
184  myNewImgSession.SetField("ProjectName", m_ProjectName);
185  myNewImgSession.SetField( "MicroscopeName", ChoiceMicroscope->currentText().toStdString() );
186  myNewImgSession.SetField("CreationDate", CreationDateTime);
187  myNewImgSession.SetField("XImageSize", XImageSize);
188  myNewImgSession.SetField("YImageSize", YImageSize);
189  myNewImgSession.SetField("XTileOverlap", XTileOverlap);
190  myNewImgSession.SetField("YTileOverlap", YTileOverlap);
191  myNewImgSession.SetField("ZTileOverlap", ZTileOverlap);
192 
193  int ExistingImgSession = myNewImgSession.DoesThisImagingSessionExist(DatabaseConnector);
194  //if this is not a duplicate, the ExistingImgSession is = -1, so it is OK
195  //to record it in the DB:
196  if ( ExistingImgSession == -1 )
197  {
198  return AddOnlyOneNewObjectInTable< GoDBImgSessionRow >(DatabaseConnector,
199  "imagingsession", myNewImgSession, "ImagingSessionID");
200  }
201  //if the img session already exists, the function will return -1:
202  return -1;
203 }
204 
205 //-------------------------------------------------------------------------
206 
207 //-------------------------------------------------------------------------
209 {
210  if ( lineNewImgSessionName->displayText() == "" )
211  {
212  QMessageBox msgBox;
213  msgBox.setText(
214  tr("Please make sure that all the required fields (*) are not empty.") );
215  msgBox.exec();
216  return false;
217  }
218  if ( lineNewImgSessionName->displayText() != "" )
219  {
220  std::vector< std::string > ProjectNameTaken = ListSpecificValuesForOneColumn(
221  m_DatabaseConnector, "imagingsession", "Name", "Name",
222  lineNewImgSessionName->displayText().toStdString() );
223  if ( ProjectNameTaken.size() != 0 )
224  {
225  QMessageBox msgBox;
226  msgBox.setText(
227  tr("This name is already taken for an existing Imaging Session.\nPlease select another one.") );
228  msgBox.exec();
229  return false;
230  }
231  if ( ChoiceMicroscope->currentText() == "" )
232  {
233  QMessageBox msgBox;
234  msgBox.setText( tr("Please choose a microscope for your imaging session.") );
235  msgBox.exec();
236  return false;
237  }
238  }
240  {
241  QMessageBox msgBox;
242  msgBox.setText(
243  tr("The images you selected are of an old megacapture format, not supported by this database.") );
244  msgBox.exec();
245  }
246 
247  //if all the info filled by the user are ok, try to save the info into the
248  // database:
249  bool cleanFileToBeImported = SaveInfoInDatabase();
250  if(!cleanFileToBeImported)
251  {
252  return cleanFileToBeImported;
253  }
254 
256  setField( "ImgSessionName", lineNewImgSessionName->text() );
257  return true;
258 }
259 
260 //-------------------------------------------------------------------------
261 
262 //-------------------------------------------------------------------------
264 {
266 }
267 
268 //-------------------------------------------------------------------------
269 
270 //-------------------------------------------------------------------------
271 void QGoCreateImgSessionPage::ImportImages(vtkMySQLDatabase *DatabaseConnector)
272 {
273  if ( DatabaseConnector != 0 )
274  {
275  try
276  {
277  //Create a Record Set with all the images to be saved in the DB:
278  typedef GoDBRecordSet< GoDBImageRow > myRecordSetType;
279  myRecordSetType *RecordSet = new myRecordSetType;
280  RecordSet->SetConnector(DatabaseConnector);
281  RecordSet->SetTableName("image");
282 
284  filelist = GetMultiIndexFileContainer();
285 
286  m_PCoordMin = filelist.get< m_PCoord >().begin()->m_PCoord;
287  m_PCoordMax = filelist.get< m_PCoord >().rbegin()->m_PCoord;
288 
289  m_RCoordMin = filelist.get< m_RCoord >().begin()->m_RCoord;
290  m_RCoordMax = filelist.get< m_RCoord >().rbegin()->m_RCoord;
291 
292  m_CCoordMin = filelist.get< m_CCoord >().begin()->m_CCoord;
293  m_CCoordMax = filelist.get< m_CCoord >().rbegin()->m_CCoord;
294 
295  m_XTileCoordMin = filelist.get< m_XTileCoord >().begin()->m_XTileCoord;
296  m_XTileCoordMax = filelist.get< m_XTileCoord >().rbegin()->m_XTileCoord;
297 
298  m_YTileCoordMin = filelist.get< m_YTileCoord >().begin()->m_YTileCoord;
299  m_YTileCoordMax = filelist.get< m_YTileCoord >().rbegin()->m_YTileCoord;
300 
301  m_ZTileCoordMin = filelist.get< m_ZTileCoord >().begin()->m_ZTileCoord;
302  m_ZTileCoordMax = filelist.get< m_ZTileCoord >().rbegin()->m_ZTileCoord;
303 
304  m_TCoordMin = filelist.get< m_TCoord >().begin()->m_TCoord;
305  m_TCoordMax = filelist.get< m_TCoord >().rbegin()->m_TCoord;
306 
307  m_ZCoordMin = filelist.get< m_ZCoord >().begin()->m_ZCoord;
308  m_ZCoordMax = filelist.get< m_ZCoord >().rbegin()->m_ZCoord;
309 
310  MultiIndexContainerIteratorType f_it = filelist.begin();
311  MultiIndexContainerIteratorType f_end = filelist.end();
312 
313  while ( f_it != f_end )
314  {
315  GoDBImageRow Image = CreateImage( DatabaseConnector, f_it,
316  field("ImgSessionID").toInt() );
317  RecordSet->AddObject(Image);
318  ++f_it;
319  }
320 
321  //Save all the images in the recordset in the Database:
322  if ( !RecordSet->SaveInDB() )
323  {
324  std::cout << "The images have not been saved in the DB" << std::endl;
325  std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
326  std::cout << std::endl;
327  return;
328  }
329  delete RecordSet;
330  }
331  catch ( const itk::ExceptionObject & e )
332  {
333  std::cerr << " caught an ITK exception: " << std::endl;
334  e.Print(std::cerr);
335  return;
336  }
337  catch ( const std::exception & e )
338  {
339  std::cerr << " caught an std exception: " << std::endl;
340  std::cerr << e.what() << std::endl;
341  return;
342  }
343  catch ( ... )
344  {
345  std::cerr << " caught an unknown exception!" << std::endl;
346  return;
347  }
348  }
349 }
350 
351 //-------------------------------------------------------------------------
352 
353 //-------------------------------------------------------------------------
355 {
356  try
357  {
358  // will throw an itk exceptio if an error occurs
359  m_importFileInfoList = itk::MegaCaptureImport::New();
360  m_importFileInfoList->SetFileName( iNewfilename.toAscii().data() );
361 
362 // QProgressBar pBar;
363  //importFileInfoList->SetProgressBar( &pBar );
364  m_importFileInfoList->Update();
365 
366  //Get the headerfile once the headerfilename is gotten
367  //from megacapture import:
368  std::string HeaderFilename = m_importFileInfoList->GetHeaderFilename();
369  m_HeaderFileInfo.SetFileName(HeaderFilename);
371  }
372  catch ( const itk::ExceptionObject & e )
373  {
374  std::cerr << " caught an ITK exception: " << std::endl;
375  e.Print(std::cerr);
376  return false;
377  }
378  catch ( const std::exception & e )
379  {
380  std::cerr << " caught an std exception: " << std::endl;
381  std::cerr << e.what() << std::endl;
382  return false;
383  }
384  catch ( std::string & e )
385  {
386  std::cerr << " caught an exception: " << std::endl;
387  std::cerr << e << std::endl;
388  return false;
389  }
390  catch ( ... )
391  {
392  std::cerr << " caught an unknown exception!" << std::endl;
393  return false;
394  }
395  return true;
396 }
397 
398 //-------------------------------------------------------------------------
399 
400 //-------------------------------------------------------------------------
401 void QGoCreateImgSessionPage::CreateChannels(vtkMySQLDatabase *DatabaseConnector,
402  int ImagingSessionID)
403 {
404  //creation of the record set to be filled with all the new channels to save in
405  // DB:
406  typedef GoDBRecordSet< GoDBChannelRow > myRecordSetType;
407  myRecordSetType *RecordSet = new myRecordSetType;
408  RecordSet->SetConnector(DatabaseConnector);
409  RecordSet->SetTableName("channel");
410 
411  std::cout << "m_HeaderFileInfo.m_NumberOfChannels: "
412  << m_HeaderFileInfo.m_NumberOfChannels << std::endl;
413 
414  for ( unsigned int i = 0; i < m_HeaderFileInfo.m_NumberOfChannels; i++ )
415  {
416  //for each channel, the color first has to be created from the headerfile
417  //into the DB:
418  GoDBColorRow myNewColor;
419  std::string StringChannelNumber = ConvertToString< int >(i);
420  std::string ChannelName = "Channel " + StringChannelNumber;
421  std::string ColorName = "ColorFor";
422  ColorName += ChannelName;
424  int Red = m_HeaderFileInfo.m_ChannelColor[i][0];
425  int Green = m_HeaderFileInfo.m_ChannelColor[i][1];
426  int Blue = m_HeaderFileInfo.m_ChannelColor[i][2];
427  int Alpha = 255;
428 
429  myNewColor.SetField("Name", ColorName);
430  myNewColor.SetField("Red", Red);
431  myNewColor.SetField("Green", Green);
432  myNewColor.SetField("Blue", Blue);
433  myNewColor.SetField("Alpha", Alpha);
434 
435  int ColorID = myNewColor.SaveInDB(DatabaseConnector);
436 
437  //creation of the corresponding channel:
438  GoDBChannelRow myNewChannel;
439 
440  myNewChannel.SetField("ColorID", ColorID);
441  myNewChannel.SetField("Name", ChannelName);
442  myNewChannel.SetField("ImagingSessionID", ImagingSessionID);
443  myNewChannel.SetField("ChannelNumber", i);
444  myNewChannel.SetField("NumberOfBits", m_HeaderFileInfo.m_ChannelDepth);
445  RecordSet->AddObject(myNewChannel);
446  }
447  RecordSet->SaveInDB();
448 }
449 
450 //-------------------------------------------------------------------------
451 
452 //-------------------------------------------------------------------------
453 int QGoCreateImgSessionPage::CreateImageCoordMin(vtkMySQLDatabase *DatabaseConnector,
455 {
456  GoDBCoordinateRow myNewImageCoordMin;
457 
458  myNewImageCoordMin.SetField("PCoord", It->m_PCoord);
459  myNewImageCoordMin.SetField("RCoord", It->m_RCoord);
460  myNewImageCoordMin.SetField("CCoord", It->m_CCoord);
461  myNewImageCoordMin.SetField("XTileCoord", It->m_XTileCoord);
462  myNewImageCoordMin.SetField("YTileCoord", It->m_YTileCoord);
463  myNewImageCoordMin.SetField("ZTileCoord", It->m_ZTileCoord);
464  myNewImageCoordMin.SetField("XCoord", It->m_XCoord);
465  myNewImageCoordMin.SetField("YCoord", It->m_YCoord);
466  myNewImageCoordMin.SetField("ZCoord", It->m_ZCoord);
467  myNewImageCoordMin.SetField("TCoord", It->m_TCoord);
468 
469  /*std::map< std::string, std::string >::iterator
470  IterNewCoord = myNewImageCoordMin.MapBegin();
471  std::map< std::string, std::string >::iterator
472  IterNewCoordEnd = myNewImageCoordMin.MapEnd();
473 
474  std::map< std::string, std::string >::iterator
475  IterMinCoord = m_ImgSessionCoordMin.MapBegin();
476  std::map< std::string, std::string >::iterator
477  IterMaxCoord = m_ImgSessionCoordMax.MapBegin();
478 
479  while ( IterNewCoord != IterNewCoordEnd )
480  {
481  IterMinCoord->second =
482  ConvertToString< int >( std::min( temp,
483  atoi( IterMinCoord->second.c_str() ) ) );
484  IterMaxCoord->second =
485  ConvertToString< int >( std::max( temp,
486  atoi( IterMaxCoord->second.c_str() ) ) );
487  ++IterMinCoord;
488  ++IterNewCoord;
489  ++IterMaxCoord;
490  }*/
491 
492  return myNewImageCoordMin.SaveInDB(DatabaseConnector);
493 }
494 
495 //-------------------------------------------------------------------------
496 
497 //-------------------------------------------------------------------------
498 int QGoCreateImgSessionPage::FindChannelIDForImage(vtkMySQLDatabase *DatabaseConnector,
499  int ImagingSessionID, int ChannelNumber)
500 {
501  std::vector< FieldWithValue > Conditions(2);
502  FieldWithValue ImgSession = { "ImagingSessionID", ConvertToString< int >(ImagingSessionID), "=" };
503  FieldWithValue Channel = { "ChannelNumber", ConvertToString< int >(ChannelNumber), "=" };
504  Conditions[0] = ImgSession;
505  Conditions[1] = Channel;
506 
507  return FindOneID(DatabaseConnector, "channel", "channelID", Conditions);
508 }
509 
510 //-------------------------------------------------------------------------
511 
512 //-------------------------------------------------------------------------
513 GoDBImageRow QGoCreateImgSessionPage::CreateImage(vtkMySQLDatabase *DatabaseConnector,
514  MultiIndexContainerIteratorType It, int ImagingSessionID)
515 {
516  GoDBImageRow myNewImage;
517 
518  myNewImage.SetField("ImagingSessionID", ImagingSessionID);
519  myNewImage.SetField( "CoordIDMin", CreateImageCoordMin(DatabaseConnector, It) );
520  myNewImage.SetField("Filename", It->m_Filename);
521 
522  //find the channelID for the image which corresponds to the channel number
523  //found in the filename (m_Channel):
525  ImagingSessionID, It->m_Channel);
526  if ( channel == -1 )
527  {
528  std::cout << "The channel doesn't exist in the DB" << std::endl;
529  std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
530  std::cout << std::endl;
531  return myNewImage;
532  }
533 
534  myNewImage.SetField("ChannelID", channel);
535  return myNewImage;
536 }
537 
538 //-------------------------------------------------------------------------
539 
540 //-------------------------------------------------------------------------
542  vtkMySQLDatabase *DatabaseConnector, int ImagingSessionID)
543 {
544  std::string imgsessionid = ConvertToString< int >(ImagingSessionID);
545 
546  int XImageSize = m_HeaderFileInfo.m_DimensionX;
547  int YImageSize = m_HeaderFileInfo.m_DimensionY;
548 
557  m_ImgSessionCoordMax.SetField("XCoord", XImageSize);
558  m_ImgSessionCoordMax.SetField("YCoord", YImageSize);
559 
560  //add a new coordinate to enter the info for ImgSession CoordMax
561  int CoordIDMax = m_ImgSessionCoordMax.SaveInDB(DatabaseConnector);
562 
563  //update the CoordMaxID in Imgsession with the new created coordinate
564  UpdateValueInDB(DatabaseConnector,
565  "imagingsession",
566  "CoordIDMax",
567  ConvertToString< int >(CoordIDMax),
568  "ImagingSessionID",
569  imgsessionid);
570 
579  m_ImgSessionCoordMin.SetField("XCoord", 0);
580  m_ImgSessionCoordMin.SetField("YCoord", 0);
581 
582  //add a new coordinate to enter the info for ImgSession CoordMin
583  int CoordIDMin = m_ImgSessionCoordMin.SaveInDB(DatabaseConnector);
584 
585  //update the CoordMaxID in Imgsession with the new created coordinate
586  UpdateValueInDB(DatabaseConnector,
587  "imagingsession",
588  "CoordIDMin",
589  ConvertToString< int >(CoordIDMin),
590  "ImagingSessionID",
591  imgsessionid);
592 }
593 
594 //-------------------------------------------------------------------------
595 
596 //-------------------------------------------------------------------------
598 {
599  std::string Server = field("ServerName").toString().toStdString();
600  std::string User = field("User").toString().toStdString();
601  std::string Password = field("Password").toString().toStdString();
602  std::string DBName = field("DBName").toString().toStdString();
603 
604  m_DatabaseConnector = OpenDatabaseConnection(Server, User, Password, DBName);
605 }
606 
607 //-------------------------------------------------------------------------
608 
609 //-------------------------------------------------------------------------
611 {
612  /*First, get the info from the filenames and the headerfile: */
613  bool cleanFileToBeImported =
615  if(!cleanFileToBeImported)
616  {
617  QMessageBox msgBox;
618  msgBox.setText( tr("The images you try to import are corrupted.") );
619  msgBox.exec();
620  return false;
621  }
622 
623  /*Second, save in the DB the related ImagingSession as it is not possible to
624  save in DB the images without knowing the corresponding ImagingSessionID:*/
625  int ImgSessionID = CreateImgSession(m_DatabaseConnector);
626  setField("ImgSessionID", ImgSessionID);
627  if ( ImgSessionID != -1 )
628  {
629  QString ImgSessionName = lineNewImgSessionName->displayText();
630  //setField("ImgSessionName",ImgSessionName);
631 
632  /*Save in the DB the channels corresponding to the ImagingSession and
633  to the channelnumber of the images:*/
634  CreateChannels( m_DatabaseConnector, field("ImgSessionID").toInt() );
635 
636  /*Record all the images from the image set into the DB, and fill the
637  ImgSessionCoordMin and Max with the values related to the images:*/
638  ImportImages(m_DatabaseConnector); //,lineFilename->toPlainText());
639 
640  //Update CoordMin and CoordMax for ImagingSession:
641  CreateImgSessionCoord( m_DatabaseConnector, field("ImgSessionID").toInt() );
642  return true;
643  }
644 
645  QMessageBox msgBox;
646  msgBox.setText(
647  tr("The images imported already belongs to an existing Imaging Session.") );
648  msgBox.exec();
649  return false;
650 }
651 
652 //-------------------------------------------------------------------------
653 
654 //-------------------------------------------------------------------------
657 {
658  if ( m_importFileInfoList.IsNotNull() )
659  {
660  return m_importFileInfoList->GetOutput();
661  }
662  else
663  {
665  }
666 }
667 
668 //-------------------------------------------------------------------------
669 
670 //-------------------------------------------------------------------------
671 std::string
673 {
674  return m_importFileInfoList->GetHeaderFilename();
675 }
676 
677 //-------------------------------------------------------------------------
678 
679 //-------------------------------------------------------------------------
681 {
682  QGoDBInitCreateMicroscopePage *CreateMicroscopePage =
684 
685  CreateMicroscopePage->SetDatabaseVariables(
686  field("User").toString().toStdString(),
687  field("Password").toString().toStdString() );
688  CreateMicroscopePage->show();
689  QObject::connect( CreateMicroscopePage, SIGNAL( NewAuthorCreated() ),
690  this, SLOT( UpdateListMicroscopes() ) );
691 }
692 
693 //-------------------------------------------------------------------------
694 
695 //-------------------------------------------------------------------------
697 {
700 }
void CreateImgSessionCoord(vtkMySQLDatabase *DatabaseConnector, int ImagingSessionID)
create into the DB the coordinates corresponding to the CoordID Min and Max for the Imaging Session a...
std::string toStdString() const
GoDBCoordinateRow m_ImgSessionCoordMax
in the QTextEdit class, there is no method to have a restriction on the number of characters the user...
std::vector< std::vector< int > > m_ChannelColor
QStringList GetListMicroscopes()
get the list of the existing microscopes registered in the DB
void addWidget(QWidget *widget, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
manages a map with keys matching fields of the gofiguredatabase ImgSession table and values of the ma...
void setSubTitle(const QString &subTitle)
void setFile(const QString &file)
bool CloseDatabaseConnection(vtkMySQLDatabase *DatabaseConnector)
return true if the connection has been closed, false if the connection was already closed ...
GoDBCoordinateRow m_ImgSessionCoordMin
void clear()
vtkMySQLDatabase * OpenDatabaseConnection(std::string ServerName, std::string login, std::string Password, std::string DBName)
QString toPlainText() const
manages a map with keys matching fields of the gofiguredatabase Coordinate table and values of the ma...
QGoCreateImgSessionPage(QWidget *parent=0)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool ImportInfoFromMegacapture(QString newfilename)
fill m_importFileInfoList from the filenames of the images and m_HeaderFileInfo from the header file ...
void clear()
void setField(const QString &name, const QVariant &value)
void UpdateValueInDB(vtkMySQLDatabase *DatabaseConnector, std::string iTableName, std::string iColumnName, std::string iNewValue, std::string iField, std::vector< unsigned int > iVectIDs)
GoFigureFileInfoHelperMultiIndexContainer::iterator MultiIndexContainerIteratorType
this class manages the map with the keys matching the fields of the Color gofiguredatabase table and ...
Definition: GoDBColorRow.h:51
int SaveInDB(vtkMySQLDatabase *DatabaseConnector)
save the coordinate in the database and return the ID of the new created coordinate or the ID of the ...
void setBold(bool enable)
virtual int SaveInDB(vtkMySQLDatabase *iDatabaseConnector)
Pure Virtual :check if the entity already exists in the DB, if yes, return the existing ID...
void append(const T &value)
void setLayout(QLayout *layout)
std::vector< std::string > ListAllValuesForOneColumn(vtkMySQLDatabase *DatabaseConnector, const std::string &ColumnName, const std::string &TableName, std::string OrderByColumnName)
SELECT ColumnName from TableName ORDER BY OrderbyColumnName.
GoDBImageRow CreateImage(vtkMySQLDatabase *DatabaseConnector, MultiIndexContainerIteratorType It, int ImagingSessionID)
return a GoDBImageRow filled with all the data corresponding
GoFigureFileInfoHelperMultiIndexContainer GetMultiIndexFileContainer()
void setText(const QString &text)
int CreateImgSession(vtkMySQLDatabase *DatabaseConnector)
create a new imaging session into the DB with the information filled by the user and collected from t...
std::vector< std::string > ListSpecificValuesForOneColumn(vtkMySQLDatabase *iDatabaseConnector, const std::string &TableName, const std::string &ColumnName, const std::string &field, const std::string &value, bool ExcludeZero)
SELECT ColumnName FROM TableName WHERE field = value and ColumnName &lt;&gt; 0 (if excludezero) ...
int FindOneID(vtkMySQLDatabase *DatabaseConnector, const std::string &TableName, const std::string &ColumnName, const std::string &field, const std::string &value)
SELECT ColumnName FROM TableName WHERE field = value.
manages a map with keys matching fields of the gofiguredatabase Image table and values of the map mat...
Definition: GoDBImageRow.h:48
void SetConnector(vtkMySQLDatabase *iDatabaseConnector)
MegaCaptureHeaderReader m_HeaderFileInfo
QVariant field(const QString &name) const
void setFont(const QFont &)
void SetFileName(const std::string &iFileName)
void ImportImages(vtkMySQLDatabase *DatabaseConnector)
create the imaging session, all the channels into the DB, then the images selected by the user and at...
void SetField(const std::string &key, const T &value)
convert the value into a string and assign it to the key in the map
Definition: GoDBRow.h:73
void setColumnStretch(int column, int stretch)
itk::MegaCaptureImport::Pointer m_importFileInfoList
static bool IsNewMegaCapture(const std::string &iFilename)
return true if the filename is of new megacapture format, false if it is the old one ...
boost::multi_index::multi_index_container< GoFigureFileInfoHelper, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::tag< m_PCoord >, >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< m_RCoord >, >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< m_CCoord >, >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< m_XTileCoord >, >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< m_YTileCoord >, >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< m_ZTileCoord >, >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< m_ZCoord >, >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< m_Channel >, >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< m_TCoord >, > >> GoFigureFileInfoHelperMultiIndexContainer
void CreateChannels(vtkMySQLDatabase *DatabaseConnector, int ImagingSessionID)
create the channels and their corresponding colors in the database, from the data gotten from the hea...
manages a map with keys matching fields of the gofiguredatabase Channel table and values of the map m...
char * data()
int CreateImageCoordMin(vtkMySQLDatabase *DatabaseConnector, MultiIndexContainerIteratorType It)
create the coordinate CoordMin in the DB, check and update if its values are less than the other Coor...
void addItems(const QStringList &texts)
void show()
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
int DoesThisImagingSessionExist(vtkMySQLDatabase *DatabaseConnector)
return the ImgSessionID of the imaging session with the same date+time of creation and microscope alr...
void SetDatabaseVariables(std::string iUser, std::string iPassword)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setText(const QString &text)
QString toString() const
vtkMySQLDatabase * m_DatabaseConnector
int FindChannelIDForImage(vtkMySQLDatabase *DatabaseConnector, int ImagingSessionID, int ChannelNumber)
return the ChannelID from the DB corresponding to the imaging session and to the channel number given...
QByteArray toAscii() const
void addLayout(QLayout *layout, int stretch)
void setMaxLength(int)