Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:43

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWViewBase
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Thu Feb 21 14:43:19 EST 2008
0011 //
0012 
0013 // system include files
0014 #include <stdexcept>
0015 #include <iostream>
0016 #include "TGFileDialog.h"
0017 
0018 // user include files
0019 #include "Fireworks/Core/interface/FWViewBase.h"
0020 
0021 //
0022 // constants, enums and typedefs
0023 //
0024 
0025 //
0026 // static data member definitions
0027 //
0028 
0029 //
0030 // constructors and destructor
0031 //
0032 FWViewBase::FWViewBase(FWViewType::EType type, unsigned int iVersion)
0033     : FWConfigurableParameterizable(iVersion), m_type(type) {}
0034 
0035 // FWViewBase::FWViewBase(const FWViewBase& rhs)
0036 // {
0037 //    // do actual copying here;
0038 // }
0039 
0040 FWViewBase::~FWViewBase() {}
0041 
0042 //
0043 // assignment operators
0044 //
0045 // const FWViewBase& FWViewBase::operator=(const FWViewBase& rhs)
0046 // {
0047 //   //An exception safe implementation is
0048 //   FWViewBase temp(rhs);
0049 //   swap(rhs);
0050 //
0051 //   return *this;
0052 // }
0053 
0054 //
0055 // member functions
0056 //
0057 void FWViewBase::destroy() { beingDestroyed_(this); }
0058 
0059 //
0060 // const member functions
0061 //
0062 void FWViewBase::promptForSaveImageTo(TGFrame* iParent) const {
0063   if (typeId() < FWViewType::kTable) {
0064     try {
0065       static TString dir(".");
0066       const char* kImageExportTypes[] = {"PNG",
0067                                          "*.png",
0068                                          "GIF",
0069                                          "*.gif",
0070                                          "JPEG",
0071                                          "*.jpg",
0072                                          "PDF",
0073                                          "*.pdf",
0074                                          "Encapsulated PostScript",
0075                                          "*.eps",
0076                                          nullptr,
0077                                          nullptr};
0078 
0079       TGFileInfo fi;
0080       fi.fFileTypes = kImageExportTypes;
0081       fi.fIniDir = StrDup(dir);
0082       new TGFileDialog(gClient->GetDefaultRoot(), iParent, kFDSave, &fi);
0083       dir = fi.fIniDir;
0084       if (fi.fFilename != nullptr) {
0085         std::string name = fi.fFilename;
0086         // fi.fFileTypeIdx points to the name of the file type
0087         // selected in the drop-down menu, so fi.fFileTypeIdx gives us
0088         // the extension
0089         std::string ext = kImageExportTypes[fi.fFileTypeIdx + 1] + 1;
0090         if (name.find(ext) == name.npos)
0091           name += ext;
0092         saveImageTo(name);
0093       }
0094     } catch (std::runtime_error& e) {
0095       std::cout << e.what() << std::endl;
0096     }
0097   } else {
0098     saveImageTo("dummy");
0099   }
0100 }
0101 
0102 FWViewContextMenuHandlerBase* FWViewBase::contextMenuHandler() const { return nullptr; }
0103 
0104 //
0105 // static member functions
0106 //
0107 const std::string& FWViewBase::typeName() const { return m_type.name(); }