CMS 3D CMS Logo

IgStudioDriver Class Reference

#include <Iguana/Studio/interface/IgStudioDriver.h>

Inheritance diagram for IgStudioDriver:

IgDriver

List of all members.

Public Member Functions

 IgStudioDriver (IgState *state)
virtual IgSitemainSite (void) const
virtual QWidget * mainWindow (void) const
virtual int run (void)
 Run the application.
virtual IgStatestate (void) const

Static Public Member Functions

static const char * catalogLabel (void)

Protected Member Functions

virtual void loadSettings (void)
virtual void setupMainWindow (void)
virtual bool setupSession (QString sessionType)

Private Member Functions

std::vector< std::string > getAliases (const std::string &name, const std::string &type)

Private Attributes

IgSitem_mainSite
QWidget * m_mainWindow
IgStudioSetupExtensionm_setup
IgStatem_state


Detailed Description

Definition at line 25 of file IgStudioDriver.h.


Constructor & Destructor Documentation

IgStudioDriver::IgStudioDriver ( IgState state  ) 

Definition at line 74 of file IgStudioDriver.cc.

References ASSERT, IgExtensionDB::get(), and m_state.

00075     : m_state (state),
00076       m_setup (0),
00077       m_mainSite (0),
00078       m_mainWindow (0)
00079 {
00080     ASSERT (m_state);
00081     IgExtensionDB::get ()->create ("Services/Global/Config", m_state);
00082 }


Member Function Documentation

const char * IgStudioDriver::catalogLabel ( void   )  [static]

Definition at line 71 of file IgStudioDriver.cc.

00072 { return "IGUANA"; }

std::vector< std::string > IgStudioDriver::getAliases ( const std::string &  name,
const std::string &  type 
) [private]

Definition at line 394 of file IgStudioDriver.cc.

References index.

Referenced by setupSession().

00395 {
00396   std::vector<std::string> aliases;
00397   if (name.substr (0, type.length ()) != type){ return aliases; }
00398   QString substr (&name[type.length ()]);
00399   QRegExp search (";\\s+");
00400   while (!substr.isEmpty ())
00401   {
00402     int index = substr.find(search);
00403     if (index == 0)
00404     { substr = substr.mid (index+search.matchedLength ()); }
00405     else if (index > 0)
00406     {
00407       aliases.push_back (substr.left (index).latin1());
00408       substr = substr.mid (index+search.matchedLength ());
00409     }
00410     else
00411     {
00412       aliases.push_back (substr.latin1());
00413       substr="";
00414     }
00415   }
00416   return aliases;
00417 }

void IgStudioDriver::loadSettings ( void   )  [protected, virtual]

Definition at line 188 of file IgStudioDriver.cc.

Referenced by run().

00189 {
00190     // FIXME: load parameters and environment settings, preferences
00191 }

IgSite * IgStudioDriver::mainSite ( void   )  const [virtual]

Definition at line 85 of file IgStudioDriver.cc.

References m_mainSite.

Referenced by IgOIVExtension::setup().

00086 { return m_mainSite; }

QWidget * IgStudioDriver::mainWindow ( void   )  const [virtual]

Definition at line 89 of file IgStudioDriver.cc.

References m_mainWindow.

Referenced by IgDocument::setName().

00090 { return m_mainWindow; }

int IgStudioDriver::run ( void   )  [virtual]

Run the application.

Returns:
Program exit code, like main would.

Implements IgDriver.

Definition at line 97 of file IgStudioDriver.cc.

References arg, IgArgsElement::arg(), IgArgsElement::args(), IgArgsElement::argv(), dbtoconf::conf, aod_PYTHIA_cfg::fileName, IgArgsElement::find(), DBSPlugin::get(), IgEnvsElement::getEnv(), IgConfigElement::getValue(), loadSettings(), m_setup, m_state, setupMainWindow(), and setupSession().

00098 {
00099     // Qt scales screen fonts by point size (1/72 inches), not pixel
00100     // size; the default is 12pt Helvetica.  To get pixel size font,
00101     // the point size is scaled by the real monitor resolution if it
00102     // is known.  Thus, on a 100 DPI screen (when correctly reported
00103     // by X) Qt will use 16-pixel fonts.  I don't know about you but
00104     // on my screen that just looks plain ugly, so we just tell Qt to
00105     // ignore to X11 on monitor resolution.
00106     //
00107     // You should also make sure you do not have ISO 10646 (Unicode)
00108     // fonts installed on your X11 server, at least not before any of
00109     // the normal fonts (at least as of Qt 3.0.1).  They tend to have
00110     // much larger vertical size (e.g. 20 vs. 15 pixels), presumably
00111     // to accommodate complex scripts like ideographs.  We don't use
00112     // any such characters in the GUI, so things look quite odd.
00113     // (FIXME: Alternatively tell Qt to not use the 10646 variants of
00114     // the fonts -- can we?)
00115 #if !defined WIN32 && !defined QT_MACOSX_VERSION
00116     if (! ::getenv ("IGUANA_KEEP_X11_RESOLUTION"))
00117     {
00118         QPaintDevice::x11SetAppDpiX (72);
00119         QPaintDevice::x11SetAppDpiY (72);
00120     }
00121 #endif //WIN32
00122 
00123     // Initialise Qt
00124     IgArgsElement       *args = IgArgsElement::get (m_state);
00125     IgEnvsElement       *envs = IgEnvsElement::get (m_state);
00126     IgConfigElement     *conf = IgConfigElement::get (m_state);
00127     QApplication        qapp (args->args (), args->argv ());
00128     QApplication::setOverrideCursor (Qt::waitCursor);
00129     
00130     // Show splash screen
00131     QSplashScreen *splash = new QSplashScreen(QPixmap (IGUANA_SPLASH));
00132     splash->show();
00133 
00134     // Load environment
00135     // and update message on the splash screen
00136     loadSettings ();
00137     splash->message ("Loaded settings");
00138     qApp->processEvents ();    
00139 
00140     // Setup main window
00141     // and update message on the splash screen
00142     setupMainWindow ();
00143     splash->message ("Set up main window");
00144     qApp->processEvents ();    
00145 
00146     // Delete splash screen and restore cursor   
00147     splash->clear ();
00148     QApplication::restoreOverrideCursor ();
00149     delete splash;
00150 
00151     QString sessionType ("");
00152     std::string ext ("");
00153     
00154     std::vector<std::string> arg;
00155     arg.push_back ("--iguana-session");
00156     arg.push_back ("-is");
00157     
00158     if (args->find (arg, ext)
00159         || conf->getValue("/Iguana/Setup/Session", ext)
00160         || envs->getEnv ("IGUANA_SETUP", ext))
00161         sessionType = ext.c_str ();
00162 
00163     // Put CMSSW session as a default one if cfg or root file
00164     // is given as an argument
00165     if (sessionType.isEmpty () && (args->args () == 2))
00166     {
00167         std::string fileName (args->arg (1));
00168         if ((fileName.size () > 2 && fileName.substr (fileName.size () - 3) == ".py")
00169             || (fileName.size () > 3 && fileName.substr (fileName.size () - 4) == ".cfg") 
00170             || (fileName.size() > 4 && fileName.substr (fileName.size () - 5) == ".root"))
00171         {
00172             sessionType = "CMSSW";
00173         }
00174     }
00175     
00176     
00177     // Pick a session driver once we run  
00178     if (! setupSession (sessionType))
00179         return EXIT_FAILURE;
00180 
00181     // Run the application.  (FIXME: always in separate thread?)
00182     IgQtAppLoopService::get (m_state)->run ();
00183     delete m_setup;
00184     return EXIT_SUCCESS;
00185 }

void IgStudioDriver::setupMainWindow ( void   )  [protected, virtual]

Definition at line 194 of file IgStudioDriver.cc.

References ASSERT, dbtoconf::conf, DBSPlugin::get(), IgConfigElement::getValue(), IgImageIDs::IMAGE_ID_AUTO_PRINT, IgImageIDs::IMAGE_ID_CONTROL_CENTRE, IgImageIDs::IMAGE_ID_GRID, IgImageIDs::IMAGE_ID_HOME, IgImageIDs::IMAGE_ID_INVERSE, IgImageIDs::IMAGE_ID_ORTHO, IgImageIDs::IMAGE_ID_PERSPECTIVE, IgImageIDs::IMAGE_ID_PICK, IgImageIDs::IMAGE_ID_PRINT, IgImageIDs::IMAGE_ID_PRINT_DEFAULT_VIEWS, IgImageIDs::IMAGE_ID_SAVE_AS, IgImageIDs::IMAGE_ID_SEEK, IgImageIDs::IMAGE_ID_SET_HOME, IgImageIDs::IMAGE_ID_VIEW, IgImageIDs::IMAGE_ID_VIEW_ALL, IgImageIDs::IMAGE_ID_XZ_SMALL, IgImageIDs::IMAGE_ID_YX_SMALL, IgImageIDs::IMAGE_ID_YX_SMALL_COL, IgImageIDs::IMAGE_ID_YZ_SMALL, IgImageIDs::IMAGE_ID_ZOOM_MINUS, IgImageIDs::IMAGE_ID_ZOOM_PLUS, IgQtAppExtensions::install(), m_mainSite, m_mainWindow, m_state, IgQtAppImageService::registerImage(), IgQtSite::selfFrom(), IgConfigElement::setPrefix(), x, and y.

Referenced by run().

00195 {
00196     // Set main window; set its window attributes early, it may pop up
00197     // at some point even though we haven't asked for it yet.  (FIXME:
00198     // set icon) (FIXME: set style only if no -style arg given!) (FIXME:
00199     // it's braindead to use sitedb to create the site, do it directly)
00200     m_mainSite = new IgQMainWindowSite (m_state, 0);
00201     m_mainWindow = IgQtSite::selfFrom (m_mainSite);
00202     qApp->setMainWidget (m_mainWindow);
00203 #ifndef QT_MACOSX_VERSION // not on mac
00204     qApp->setStyle (new QWindowsStyle);
00205 #endif
00206 
00207     IgQtAppExtensions::install (m_state, m_mainWindow);
00208     ASSERT (IgQtAppLoopService::get (m_state));
00209 
00210     // FIXME: Need a better way to setup state
00211     new IgSelectionService (m_state);
00212     new IgQtObjectMenuService (m_state);
00213     new IgQtAppActiveService (m_state);
00214     new IgDocumentDataManager (m_state);
00215     new IgModelManager (m_state);
00216     IgQtAppImageService *is = new IgQtAppImageService (m_state);
00217     is->registerImage (autoprint_xpm, IgImageIDs::IMAGE_ID_AUTO_PRINT);
00218     is->registerImage (fileprint, IgImageIDs::IMAGE_ID_PRINT);
00219     is->registerImage (filesave, IgImageIDs::IMAGE_ID_SAVE_AS);
00220     is->registerImage (control_centre_xpm, IgImageIDs::IMAGE_ID_CONTROL_CENTRE);
00221     is->registerImage (yz_small_xpm, IgImageIDs::IMAGE_ID_YZ_SMALL);    
00222     is->registerImage (yx_small_xpm, IgImageIDs::IMAGE_ID_YX_SMALL);    
00223     is->registerImage (xz_small_xpm, IgImageIDs::IMAGE_ID_XZ_SMALL);    
00224     is->registerImage (yx_small_col_xpm, IgImageIDs::IMAGE_ID_YX_SMALL_COL);    
00225     is->registerImage (inverse_xpm, IgImageIDs::IMAGE_ID_INVERSE);
00226     is->registerImage (zoom_plus_xpm, IgImageIDs::IMAGE_ID_ZOOM_PLUS);
00227     is->registerImage (zoom_minus_xpm, IgImageIDs::IMAGE_ID_ZOOM_MINUS);
00228     is->registerImage (grid_xpm, IgImageIDs::IMAGE_ID_GRID);
00229     is->registerImage (home_xpm, IgImageIDs::IMAGE_ID_HOME);
00230     is->registerImage (set_home_xpm, IgImageIDs::IMAGE_ID_SET_HOME);
00231     is->registerImage (ortho_xpm, IgImageIDs::IMAGE_ID_ORTHO);
00232     is->registerImage (perspective_xpm, IgImageIDs::IMAGE_ID_PERSPECTIVE);
00233     is->registerImage (view_all_xpm, IgImageIDs::IMAGE_ID_VIEW_ALL);
00234     is->registerImage (perspective_xpm, IgImageIDs::IMAGE_ID_PERSPECTIVE);
00235     is->registerImage (pick_xpm, IgImageIDs::IMAGE_ID_PICK);
00236     is->registerImage (view_xpm, IgImageIDs::IMAGE_ID_VIEW);
00237     is->registerImage (seek_xpm, IgImageIDs::IMAGE_ID_SEEK);
00238     is->registerImage (print_views_xpm, IgImageIDs::IMAGE_ID_PRINT_DEFAULT_VIEWS);
00239     
00240     IgConfigElement     *conf = IgConfigElement::get (m_state);
00241     ASSERT (conf);
00242     
00243     conf->setPrefix ("/Iguana/Setup");
00244     std::string caption("IGUANA");
00245     conf->getValue("Caption", caption);
00246     m_mainWindow->setCaption (caption.c_str());
00247     
00248     unsigned int x = 1000, y=760;
00249     conf->getValue("Size/X", x);
00250     conf->getValue("Size/Y", y);
00251     m_mainWindow->resize (x, y);
00252 
00253     // FIXME: add standard menu items like quit, ...
00254     // FIXME: add standard tool bar buttons
00255 
00256     // Now auto-load all other GUI extensions.
00257     ASSERT (IgPluginLoader::get (m_state));
00258     IgPluginLoader::get (m_state)->load (m_state, "Extensions/Qt GUI/", true);
00259 
00260     // Make it visible
00261     m_mainWindow->show ();
00262 }

bool IgStudioDriver::setupSession ( QString  sessionType  )  [protected, virtual]

Definition at line 265 of file IgStudioDriver.cc.

References arg, ASSERT, IgPluginFactory< I >::begin(), cmsPerfCommons::configs, hlt_scaler_cfg::critical, IgPluginFactory< I >::end(), IgExtensionDB::get(), getAliases(), i, prof2calltree::last, IgStudioSetup::m_configs, m_setup, m_state, prof2calltree::prefix, and dummy::select().

Referenced by run().

00266 {
00267     // FIXME: Use own plug-in category
00268     ASSERT (! m_setup);
00269 
00270     std::string prefix ("Services/Studio/Session Types/");
00271     std::string preferred;
00272     
00273     // Build list of available session drivers (FIXME: remember last?)
00274     IgExtensionDB::Iterator ext = IgExtensionDB::get ()->begin ();
00275     IgExtensionDB::Iterator last = IgExtensionDB::get ()->end ();
00276 
00277     if (! sessionType.isEmpty ()) 
00278     {
00279         bool found = false;
00280         for ( ; (ext != last) && (!found); ++ext)
00281         {
00282           std::string fullname = (*ext)->name();
00283           std::vector<std::string> aliases = getAliases (fullname, prefix);
00284           
00285           for (unsigned int i = 0; i < aliases.size (); i++)
00286           {
00287             if (aliases [i] == sessionType.latin1() )
00288             {
00289               preferred = fullname;
00290               found = true;
00291               break;
00292             }
00293           }
00294         }
00295           
00296         if (!found)
00297         {
00298             QMessageBox::information (0, "IGUANA Setup", QString ("<p>IGUANA_SETUP environment variable"
00299                                                                   " is set to <b>\"%1\"</b>. This session type"
00300                                                                   " is not available.</p>"
00301                                                                   "<p>Please select one from the next setup"
00302                                                                   " page.").arg (sessionType));
00303             sessionType = "";
00304         }
00305     }
00306 
00307     if (sessionType.isEmpty ()) 
00308     {
00309         // Create the setup window
00310         IgStudioSetup *setup = new IgStudioSetup (qApp->mainWidget (), 0, true);
00311         QListBox          *configs = setup->m_configs;
00312 
00313         ext = IgExtensionDB::get ()->begin ();
00314         int select = 0;
00315 
00316         std::map <std::string , std::string> aliasesMap;
00317         for ( ; ext != last; ++ext)
00318         {
00319           std::string fullname = (*ext)->name();
00320           std::vector<std::string> aliases = getAliases (fullname, prefix);
00321           
00322           for(unsigned int i = 0; i < aliases.size (); i++)
00323             aliasesMap [aliases [i]] = fullname;
00324           
00325           if (aliases.size ())
00326           {
00327             configs->insertItem (aliases [0].c_str ());
00328             if (! preferred.empty () && fullname == preferred)
00329               select = configs->count ()-1;
00330           }
00331         }
00332 
00333         if (! configs->count ())
00334         {
00335             QMessageBox::critical (0, "IGUANA", "<p>You do not seem to have any"
00336                                    " IGUANA session configurations available in"
00337                                    " your system at the moment (cf. ``iguana"
00338                                    " --list'', $IGUANA_PLUGINS).  I cannot"
00339                                    " continue without one.</p>"
00340                                    "<p>Please correct the above problem and try"
00341                                    " again.");
00342             delete setup;
00343             return false;
00344         }
00345 
00346         configs->setCurrentItem (select);
00347         preferred = "";
00348 
00349         // Let the user select the driver
00350         if (setup->exec () != QDialog::Accepted || configs->currentItem () == -1)
00351         {
00352             delete setup;
00353             return false;
00354         }
00355 
00356         preferred = aliasesMap[ configs->currentText ().latin1 () ];
00357         delete setup;
00358     }
00359     
00360     // Instantiate the selected session driver
00361     ASSERT (! preferred.empty ());
00362     IgStudioSetupExtension      *sext = 0;
00363     IgExtension                 *newext = 0;
00364 
00365     try
00366     {
00367         // Try to instantiate it
00368         QApplication::setOverrideCursor (Qt::waitCursor);
00369         newext = IgExtensionDB::get ()->create (preferred, m_state);
00370 
00371         // Make sure we got what we expect
00372         ASSERT (newext);
00373         ASSERT (dynamic_cast<IgStudioSetupExtension *> (newext));
00374         sext = static_cast<IgStudioSetupExtension *> (newext);
00375         QApplication::restoreOverrideCursor ();
00376 
00377         // Try to set it up; if fails, take short cut out
00378         if (! sext->setup (this))
00379             throw 1;
00380     }
00381     // FIXME: too broad...
00382     catch (...)
00383     {
00384         QApplication::restoreOverrideCursor ();
00385         delete newext;
00386         return false;
00387     }
00388 
00389     m_setup = sext;
00390     return true;
00391 }

IgState * IgStudioDriver::state ( void   )  const [virtual]

Definition at line 93 of file IgStudioDriver.cc.

References m_state.

00094 { return m_state; }


Member Data Documentation

IgSite* IgStudioDriver::m_mainSite [private]

Definition at line 50 of file IgStudioDriver.h.

Referenced by mainSite(), and setupMainWindow().

QWidget* IgStudioDriver::m_mainWindow [private]

Definition at line 51 of file IgStudioDriver.h.

Referenced by mainWindow(), and setupMainWindow().

IgStudioSetupExtension* IgStudioDriver::m_setup [private]

Definition at line 49 of file IgStudioDriver.h.

Referenced by run(), and setupSession().

IgState* IgStudioDriver::m_state [private]

Definition at line 48 of file IgStudioDriver.h.

Referenced by IgStudioDriver(), run(), setupMainWindow(), setupSession(), and state().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:25:47 2009 for CMSSW by  doxygen 1.5.4