36 #include <qmessagebox.h>
40 using std::runtime_error;
44 using namespace hippodraw;
61 const string xml (
".xml" );
62 const string tnt (
".tnt" );
65 #define STRING_CLEAR_DEFECT
68 #ifdef STRING_CLEAR_DEFECT
87 const string root (
".root" );
94 const string fits (
".fits" );
99 const string gzfits (
".fits.gz" );
112 #ifdef STRING_CLEAR_DEFECT
123 const string fits (
".fits" );
128 const string gzfits (
".fits.gz" );
143 const string xml (
".xml" );
144 const string tnt (
".tnt" );
147 #define STRING_CLEAR_DEFECT
150 #ifdef STRING_CLEAR_DEFECT
199 return suffix ==
".root";
206 return suffix ==
".fits";
213 return suffix ==
".gz";
228 #if QT_VERSION < 0x040000
231 = Q3FileDialog::getSaveFileName ( QString::null,
236 "Save data source to file ...",
239 if ( filename == QString::null )
return tmp;
241 if (( filename.
endsWith (
".tnt" ) == false ) &&
242 ( filename.
endsWith (
".fits" ) == false ) &&
243 ( filename.
endsWith (
".fits.gz" )==false ))
247 if ( extname ==
"FITS ntuples(*.fits)" )
251 else if (extname ==
"Compressed FITS ntuples(*.fits.gz)")
253 filename+=
".fits.gz";
265 if ( yes ==
false )
break;
267 string message (
"File exists. \n\n" );
268 message +=
"Over write existing file?";
274 if ( result == QMessageBox::Yes )
break;
277 string name = filename.
latin1();
302 controller -> createNTuple ( filename );
304 catch (
const std::exception & e )
307 QString message(
"Unable to open file\n" );
308 message.
append(e.what ());
328 fits_file = controller ->
openFile ( fn );
329 if ( fits_file != 0 ) yes =
true;
343 const vector < string > & dups = source -> getDuplicatedLabels ();
344 if ( dups.empty () == false ) {
345 QString message (
"This data source contains two or more columns with\n"
346 "the same label. The offending labels were\n\n" );
347 for (
unsigned int i = 0;
i < dups.size();
i++ ) {
348 message += dups[
i].c_str();
351 message +=
"\nThe first column encountered will be used";
365 unsigned int index = 0;
368 const vector < string > & names
369 = controller -> getNTupleNames ( filename );
371 if ( names.size () > 1 ) {
372 if ( names.size () >= 2 ) {
374 dialog -> setNames ( names );
375 int retval = dialog -> exec ();
377 if ( retval == QDialog::Accepted ) {
378 index = dialog -> selectedItem ();
381 if ( retval == QDialog::Rejected )
return;
390 controller -> createNTuple ( filename, names [ index ], index );
393 catch (
const runtime_error & e ) {
410 unsigned int index = 0;
413 const vector < string > & tree_names
414 = controller -> getNTupleNames ( filename );
415 if ( tree_names.size () > 1 ) {
417 dialog -> setNames ( tree_names );
419 int retval = dialog -> exec ();
421 if ( retval == QDialog::Rejected )
return;
422 index = dialog -> selectedItem ();
425 if ( tree_names.empty () ) {
426 string message (
"There were no ntuple objects found in this file." );
427 message +=
"\nFile not opened.";
439 controller -> createNTuple ( filename, tree_names[index] );
442 catch (
const runtime_error & e ) {
459 const string tuple_name =
462 -> getSelectedDataSourceName ();
468 catch (
const std::exception & e ) {
469 QString message (
"An error occurred in writing file.\n\n" );
475 QMessageBox::NoButton,
476 QMessageBox::NoButton );
485 const string tuple_name =
488 -> getSelectedDataSourceName ();
495 catch (
const std::exception & e ) {
496 QString message (
"An error occurred in writing file.\n\n" );
502 QMessageBox::NoButton,
503 QMessageBox::NoButton );
hippodraw::QtFileDialog class interface
void openRootTuple(const std::string &filename, QWidget *parent)
Opens a ROOT DataSource file.
void writeNTupleToFile(const DataSource *ntuple, const std::string &filename)
Write a DataSource to a FITS file as binary table.
hippodraw::CanvasWindow class interface.
static FitsController * instance()
Returns the singleton instance of the FitsController.
static bool isFitsFile(const std::string &filename)
Returns true if the file filename is a FITS file.
hippodraw::RootController class interface.
static bool isFitsSuffix(const std::string &suffix)
Returns true if suffix is one corresponding to FITS DataSource file.
FitsFile * openFile(const std::string &file)
Opens the named file, if not already opened.
int writeNTupleToFile(DataSource *source, const std::string &filename)
Writes the DataSource source to a file given by filename.
hippodraw::WindowController class interface
A derived class of ListDialogBase class which is generated by the Qt designer.
void checkDuplicateLabels(const DataSource *source, QWidget *)
Checks for duplicate column labels in the DataSource source.
hippodraw::DataSource class interface.
hippodraw::Inspector class interface.
static bool isTextSuffix(const std::string &suffix)
Returns true if suffix is one corresponding to text NTuple file.
static const std::string & createExportFilter()
Creates a filter for exporting DataSource to file.
static const std::string & getDocSuffix()
Returns the suffix for a document.
static const std::string s_data_suffix
The file name suffix used for the application's text data source files.
static WindowController * instance()
Returns the application instance.
endsWith(const QString &s, bool cs=TRUE) const
static const std::string & getTextSuffix()
Returns the suffix for a text data source files.
Wrapper class to CFITSIO.
hippodraw::FitsController class interface.
void saveTextTuple(const std::string &filename, QWidget *parent)
Save a text file.
A singleton class that is the interface between GUI and the NTuple objects.
static std::string s_open_filter
The open file filter.
void openFitsTuple(const std::string &filename, QWidget *parent)
Opens a FITS DataSource file.
static const std::string & createBrowseFilter()
Creates the open file filter.
static NTupleController * instance()
Returns the pointer to the singleton instance.
static const std::string s_doc_suffix
The file name suffix used for the application's document files.
hippodraw::ListDialog class interface
void saveFitsTuple(const std::string &filename, QWidget *parent)
Save a FITS file.
QtFileDialog()
The constructor.
static bool isDocSuffix(const std::string &suffix)
Returns true if suffix is one corresponding to document file.
A Controller class for FITS files.
static const std::string & createDocumentFilter()
Creates a filter for saving a document.
getSaveFileName(const QString &startWith=QString::null, const QString &filter=QString::null, QWidget *parent=0, const char *name=0, const QString &caption=QString::null, QString *selectedFilter=0, bool resolveSymlinks=TRUE)
critical(QWidget *parent, const QString &caption, const QString &text, int button0, int button1, int button2=0)
static std::string getExportTupleFilename(QWidget *widget)
Returns a filename for exporting a DataSource.
static RootController * instance()
Returns the singleton instance of the RootController.
warning(QWidget *parent, const QString &caption, const QString &text, int button0, int button1, int button2=0)
static bool isZippedFitsSuffix(const std::string &suffix)
Returns true if the file filename is a compressed FITS file.
hippodraw::NTupleController class interface
static const std::string & createOpenFilter()
Creates the open file filter.
DataSourceController class interface.
A Controller class for ROOT files.
static bool isRootSuffix(const std::string &suffix)
Returns true if suffix is one corresponding to ROOT DataSource files.
static void openTextTuple(const std::string &filename)
Opens a text NTuple file.
Base class for DataSource.