CMS 3D CMS Logo

IgModelManager.h

Go to the documentation of this file.
00001 #ifndef IGUANA_STUDIO_IG_MODEL_MANAGER_H
00002 # define IGUANA_STUDIO_IG_MODEL_MANAGER_H
00003 
00004 //<<<<<< INCLUDES                                                       >>>>>>
00005 
00006 #include "Iguana/Studio/interface/IgDocumentData.h"
00007 #include "Iguana/Studio/interface/IgDocumentDataManager.h"
00008 #include "Iguana/Framework/interface/IgDocumentDataRoot.h"
00009 
00010 //<<<<<< PUBLIC DEFINES                                                 >>>>>>
00011 //<<<<<< PUBLIC CONSTANTS                                               >>>>>>
00012 //<<<<<< PUBLIC TYPES                                                   >>>>>>
00013 
00014 class IgModel;
00015 
00016 //<<<<<< PUBLIC VARIABLES                                               >>>>>>
00017 //<<<<<< PUBLIC FUNCTIONS                                               >>>>>>
00018 //<<<<<< CLASS DECLARATIONS                                             >>>>>>
00019 
00020 // REMINDER: used to initialize system before creating Ig3DBaseModels.
00021 // Ig3DSystem::init (m_state, 
00022 //                IgQtSite::selfFrom (site)->topLevelWidget ());
00023 
00024 class IGUANA_STUDIO_API IgModelManager : public IgStateElement
00025 {
00026     IG_DECLARE_STATE_ELEMENT (IgModelManager);
00027 public:
00028     IgModelManager (IgState *m_state);
00029     ~IgModelManager (void);
00030     
00031     // implicit copy constructor
00032     // implicit assignment operator
00033     // implicit destructor
00034 
00035     typedef std::map<std::string, std::vector<IgModel *> > ModelList;
00036     
00040     template <class T>
00041     bool lookup (T **model, std::string name = "")
00042     {
00043         *model = 0;
00044         if (name.size () == 0)
00045             name = IgDocumentDataRoot::getCurrentRoot ();
00046             
00047         ModelList::iterator i =  m_models.find (name);
00048         
00049         if (i != m_models.end ())
00050         {
00051             for (std::vector<IgModel *>::iterator j = i->second.begin ();
00052                  j != i->second.end (); j++)
00053             {
00054                 *model = dynamic_cast<T*> (*j);
00055                 if (*model)
00056                     return true;
00057             }
00058         }
00059         return false;
00060     }
00061     
00062     template <class T>
00063     IgState* lookup (IgState *state, T **model, std::string name = "")
00064     {
00065         if (name.size () == 0)
00066             name = IgDocumentDataRoot::getCurrentRoot ();
00067         lookup (model, name);
00068             
00069         state = IgDocumentDataManager::get (state ? state : m_state)->
00070                    lookup(state, name);
00071         
00072         if (!*model)
00073         {
00074             *model = new T (state);
00075             m_models[name].push_back (*model);
00076         }
00077         return state;
00078     }
00079 
00080     template <class T>
00081     std::vector<std::string> roots (T */* model */)
00082     {
00083         std::vector<std::string> names;
00084             
00085         for (ModelList::iterator i = m_models.begin ();
00086              i != m_models.end (); i++)
00087         {
00088             for (std::vector<IgModel *>::iterator j = i->second.begin ();
00089                  j != i->second.end (); j++)
00090             {
00091                 if (dynamic_cast<T*> (*j))
00092                 {
00093                     names.push_back (i->first);
00094                     break;
00095                 }
00096             }
00097        }
00098             
00099        return names;
00100     }
00101         
00102     void add (IgState *state, IgModel* model, std::string name = "");
00103     std::vector<std::string> roots (void);
00104     IgState* state (void);
00105 
00106 private:
00107     IgState     *m_state;
00108     ModelList   m_models;
00109 };
00110 
00111 //<<<<<< INLINE PUBLIC FUNCTIONS                                        >>>>>>
00112 //<<<<<< INLINE MEMBER FUNCTIONS                                        >>>>>>
00113 
00114 #endif // IGUANA_STUDIO_IG_MODEL_MANAGER_H

Generated on Tue Jun 9 17:38:48 2009 for CMSSW by  doxygen 1.5.4