GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoLsmToMegaExportDialog.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 
36 
37 #include <QFileDialog>
38 #include <QProgressDialog>
39 
40 //-------------------------------------------------------------------------
42  m_LsmName(""), m_MegaPath(""), m_FileFormatIsPNG(true), m_Counter(0)
43 {
44  this->setupUi(this);
45 
46  m_ProgressDialog = new QProgressDialog("Conversion in progress.", "Cancel", 0, 100, this);
47 
49 
50  QObject::connect( ConversionLsmToMegaThreadSend, SIGNAL( ConversionTerminatedSent() ),
51  this, SLOT( ConversionTerminatedReceived() ) );
52 
53  QObject::connect( ConversionLsmToMegaThreadSend, SIGNAL( InitialisationProgressSent() ), this,
55 
56  QObject::connect( ConversionLsmToMegaThreadSend, SIGNAL( ProgressSent() ), this, SLOT( ProgressReceived() ) );
57 
58  QObject::connect( m_ProgressDialog, SIGNAL( canceled() ), this, SLOT( CanceledReceived() ) );
59 }
60 
61 //-------------------------------------------------------------------------
62 
63 //-------------------------------------------------------------------------
66 {
68 }
69 
70 //-------------------------------------------------------------------------
71 
72 //-------------------------------------------------------------------------
73 void
75 {
77  tr("Select the LSM file to convert"), QDir::currentPath(),
78  tr("Image Files (*.lsm)") );
79 
80  QFileInfo fileInfo(m_LsmPath);
81 
82  m_LsmName = fileInfo.fileName();
83  m_LsmName.replace( QString(" "), QString("_") );
84 
85  // Write the lsm file name in the dialog window
86  lsmFileName->setText(m_LsmName);
87 }
88 
89 //-------------------------------------------------------------------------
90 
91 //-------------------------------------------------------------------------
92 void
94 {
95  m_MegaPath = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
96  QDir::homePath(), QFileDialog::ShowDirsOnly
97  | QFileDialog::DontResolveSymlinks);
98 
100 
101  megaFilePath->setText(m_MegaPath);
102 }
103 
104 //-------------------------------------------------------------------------
105 
106 //-------------------------------------------------------------------------
107 void
109 {
110  if ( index == 0 )
111  {
112  m_FileFormatIsPNG = true;
113  }
114  else
115  {
116  m_FileFormatIsPNG = false;
117  }
118 }
119 
120 //-------------------------------------------------------------------------
121 
122 //-------------------------------------------------------------------------
123 void
125 {
128  {
130  std::cerr << "Please select good path for lsm and megacapture" << std::endl;
131  }
132  else
133  {
134  // Disable everything
135  this->lsmFileName->setEnabled(false);
136  this->megaFilePath->setEnabled(false);
137  this->selectLsmFile->setEnabled(false);
138  this->selectMegaPath->setEnabled(false);
139  this->outputFormat->setEnabled(false);
140  this->convert->setEnabled(false);
141  this->label->setEnabled(false);
142  this->selectLSMLabel->setEnabled(false);
143  this->megaFilePath_2->setEnabled(false);
144  this->outputFormatLabel->setEnabled(false);
145  this->label_2->setEnabled(false);
146 
147  this->convertLabel->setText( tr("READS LSM READERS") );
148 
149  // Set conversion parameters
151  if ( !m_FileFormatIsPNG )
152  {
153  filetype = GoFigure::TIFF;
154  }
155 
156  // Remove extension
157  m_LsmName.replace( QString(".lsm"), QString("_lsm") );
158 
159  // conversion fonction called from there to enable progress bar
164 
166  }
167 }
168 
169 //-------------------------------------------------------------------------
170 
171 //-------------------------------------------------------------------------
172 void
174 {
178  this->accept();
179 }
180 
181 //-------------------------------------------------------------------------
185 //-------------------------------------------------------------------------
186 void
188 {
189  this->convertLabel->setText( tr("CONVERSION in PROGRESS") );
190 
191  int sizeProgressBar = ConversionLsmToMegaThreadSend->GetNumberOfPoints();
192 
193  // if starts at 0 strange things happen...
194  m_Counter = 1;
195 
196  // sizeProgressBar because
197  // +1 because m_Counter starts at 1
198  // +1 to prevent that the dialoProgressWindow automatically close
199  // then re-open when 100% reached
200  m_ProgressDialog->setRange(0, sizeProgressBar + 5);
202 }
203 
204 //-------------------------------------------------------------------------
205 
206 //-------------------------------------------------------------------------
207 void
209 {
210  m_Counter++;
212 }
213 
214 //-------------------------------------------------------------------------
215 
216 //-------------------------------------------------------------------------
217 void
219 {
223 }
224 
225 //-------------------------------------------------------------------------
std::string toStdString() const
void on_outputFormat_activated(int index)
Select the output format.
void on_selectLsmFile_clicked()
Get the name of the lsm file selected.
QString getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, QFlags< QFileDialog::Option > options)
void setupUi(QWidget *widget)
void InitialisationProgressReceived()
Catch thread, initialize the progress bar.
int size() const
QString currentPath()
QString homePath()
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isNull() const
void start(Priority priority)
void setValue(int progress)
QString & insert(int position, QChar ch)
void SetMegaPath(std::string iMegaPath)
Set the path of the MegaCapture file to create.
QString fileName() const
void terminate()
int GetNumberOfPoints()
Returns the number of signals to be sent for the progress bar.
bool isEmpty() const
void CanceledReceived()
Catch thread, cancel the conversion.
void on_convert_clicked()
Disable buttons and send thread to launch conversion.
void SetOutputFileType(const GoFigure::FileType &iFileType)
Set the output file type.
void setRange(int minimum, int maximum)
virtual void accept()
void on_selectMegaPath_clicked()
Get the location to store MegaCapture file.
QString & replace(int position, int n, QChar after)
ConversionLsmToMegaThread * ConversionLsmToMegaThreadSend
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
void ProgressReceived()
Catch thread, update the progress bar content.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void SetBaseName(std::string iBaseName)
Set the base name of the LSM file to convert.
QGoLsmToMegaExportDialog(QWidget *parent=0)
Constructor.
void SetLsmPath(std::string iLsmPath)
Set the path to the LSM file to convert and initialise LSM reader.
void exit(int returnCode)
void ConversionTerminatedReceived()
Catch thread, close progress bar and dialog box.