CMS 3D CMS Logo

CMSSW_4_4_3_patch1/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.14 2010/11/04 22:38:55 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    try {
00077       static TString dir(".");
00078       const char *  kImageExportTypes[] = {"PNG",                     "*.png",
00079                                            "GIF",                     "*.gif",
00080                                            "JPEG",                    "*.jpg",
00081                                            "PDF",                     "*.pdf",
00082                                            "Encapsulated PostScript", "*.eps",
00083                                            0, 0};
00084 
00085       TGFileInfo fi;
00086       fi.fFileTypes = kImageExportTypes;
00087       fi.fIniDir    = StrDup(dir);
00088       new TGFileDialog(gClient->GetDefaultRoot(), iParent,
00089                        kFDSave,&fi);
00090       dir = fi.fIniDir;
00091       if (fi.fFilename != 0) {
00092          std::string name = fi.fFilename;
00093          // fi.fFileTypeIdx points to the name of the file type
00094          // selected in the drop-down menu, so fi.fFileTypeIdx gives us
00095          // the extension
00096          std::string ext = kImageExportTypes[fi.fFileTypeIdx + 1] + 1;
00097          if (name.find(ext) == name.npos)
00098             name += ext;
00099          saveImageTo(name);
00100       }
00101    }
00102    catch (std::runtime_error &e) { std::cout << e.what() << std::endl; }
00103 }
00104 
00105 FWViewContextMenuHandlerBase* 
00106 FWViewBase::contextMenuHandler() const {
00107    return 0;
00108 }
00109 
00110 //
00111 // static member functions
00112 //
00113 const std::string& 
00114 FWViewBase::typeName() const
00115 {
00116    return m_type.name();
00117 }