CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Fireworks/Core/src/FWViewBase.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWViewBase
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Thu Feb 21 14:43:19 EST 2008
00011 // $Id: FWViewBase.cc,v 1.16 2013/04/05 21:04:18 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 #include <stdexcept>
00016 #include <iostream>
00017 #include "TGFileDialog.h"
00018 
00019 // user include files
00020 #include "Fireworks/Core/interface/FWViewBase.h"
00021 
00022 
00023 //
00024 // constants, enums and typedefs
00025 //
00026 
00027 //
00028 // static data member definitions
00029 //
00030 
00031 //
00032 // constructors and destructor
00033 //
00034 FWViewBase::FWViewBase(FWViewType::EType type, unsigned int iVersion) :
00035    FWConfigurableParameterizable(iVersion),
00036    m_type(type)
00037 {
00038 }
00039 
00040 // FWViewBase::FWViewBase(const FWViewBase& rhs)
00041 // {
00042 //    // do actual copying here;
00043 // }
00044 
00045 FWViewBase::~FWViewBase()
00046 {
00047 }
00048 
00049 //
00050 // assignment operators
00051 //
00052 // const FWViewBase& FWViewBase::operator=(const FWViewBase& rhs)
00053 // {
00054 //   //An exception safe implementation is
00055 //   FWViewBase temp(rhs);
00056 //   swap(rhs);
00057 //
00058 //   return *this;
00059 // }
00060 
00061 //
00062 // member functions
00063 //
00064 void
00065 FWViewBase::destroy()
00066 {
00067    beingDestroyed_(this);
00068 }
00069 
00070 //
00071 // const member functions
00072 //
00073 void
00074 FWViewBase::promptForSaveImageTo(TGFrame* iParent) const
00075 {
00076    if (typeId() < FWViewType::kTable)
00077    {
00078    try {
00079       static TString dir(".");
00080       const char *  kImageExportTypes[] = {"PNG",                     "*.png",
00081                                            "GIF",                     "*.gif",
00082                                            "JPEG",                    "*.jpg",
00083                                            "PDF",                     "*.pdf",
00084                                            "Encapsulated PostScript", "*.eps",
00085                                            0, 0};
00086 
00087       TGFileInfo fi;
00088       fi.fFileTypes = kImageExportTypes;
00089       fi.fIniDir    = StrDup(dir);
00090       new TGFileDialog(gClient->GetDefaultRoot(), iParent,
00091                        kFDSave,&fi);
00092       dir = fi.fIniDir;
00093       if (fi.fFilename != 0) {
00094          std::string name = fi.fFilename;
00095          // fi.fFileTypeIdx points to the name of the file type
00096          // selected in the drop-down menu, so fi.fFileTypeIdx gives us
00097          // the extension
00098          std::string ext = kImageExportTypes[fi.fFileTypeIdx + 1] + 1;
00099          if (name.find(ext) == name.npos)
00100             name += ext;
00101          saveImageTo(name);
00102       }
00103    }
00104    catch (std::runtime_error &e) { std::cout << e.what() << std::endl; }
00105    }
00106    else
00107    {
00108       saveImageTo("dummy");
00109    }
00110 }
00111 
00112 FWViewContextMenuHandlerBase* 
00113 FWViewBase::contextMenuHandler() const {
00114    return 0;
00115 }
00116 
00117 //
00118 // static member functions
00119 //
00120 const std::string& 
00121 FWViewBase::typeName() const
00122 {
00123    return m_type.name();
00124 }