CMS 3D CMS Logo

IgDocumentData.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/Studio/interface/IgDocumentData.h"
00004 #include "Iguana/Framework/interface/IgDocumentDataRoot.h"
00005 #include "Iguana/Framework/interface/IgTwig.h"
00006 
00007 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00008 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00009 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00010 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00011 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00012 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00013 
00014 IG_DEFINE_STATE_ELEMENT (IgDocumentData, "Services/Studio/Document Data");
00015 
00016 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00017 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00018 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00019 
00020 IgDocumentData::IgDocumentData (IgState *state, IgDocument *owner)
00021     : m_state (state),
00022       m_document (owner)
00023 {
00024     ASSERT (m_state);
00025     // FIXME: temporarly removing the check, until IgDocument returns
00026     // Qt free.
00027     // ASSERT (m_document);
00028     m_state->put (s_key, this);
00029 }
00030 
00031 IgDocumentData::~IgDocumentData (void)
00032 {
00033     ASSERT (m_state);
00034     //FIXME: assertion not needed.
00035     //ASSERT (m_document);
00036 
00037     for (TwigMap::iterator i = m_rootMap.begin ();
00038          i != m_rootMap.end ();
00039          i++)
00040     {   
00041         delete i->second;
00042     }
00043     
00044     m_state->detach (s_key);
00045 }
00046 
00047 IgDocument *
00048 IgDocumentData::document (void)
00049 {
00050     ASSERT (m_state);
00051     ASSERT (m_document);
00052 
00053     return m_document;
00054 }
00055 
00056 
00057 IgSimpleTwig *
00058 IgDocumentData::root (const std::string &name /*= ""*/, bool create)
00059 {
00060     ASSERT (m_state);
00061     // FIXME: needs proper fixing. Document should be Qt-less and also
00062     // the web application should create one.    
00063     // ASSERT (m_document);
00064     
00065     std::string n = name;
00066     if (n.size () == 0)
00067         n = IgDocumentDataRoot::getCurrentRoot ();
00068 
00069     TwigMap::iterator i = m_rootMap.find (n);
00070     
00071     if (i == m_rootMap.end ())
00072     {
00073         IgSimpleTwig *twig = 0;
00074         
00075         if (create)
00076         {
00077             twig = new IgSimpleTwig ("Objects");
00078             m_rootMap[n] = twig;
00079         }
00080         return twig;
00081     }
00082     return i->second;
00083 }
00084 
00085 void
00086 IgDocumentData::root (IgSimpleTwig *twig, 
00087                       const std::string &rootName /*= ""*/)
00088 {
00089     ASSERT (twig);
00090     std::string n = rootName;
00091     if (n.size () == 0)
00092         n = IgDocumentDataRoot::getCurrentRoot ();
00093     m_rootMap[n] = twig; 
00094 }
00095 
00096 IgSimpleTwig *
00097 IgDocumentData::add (const std::string &name, const std::string &rootName)
00098 {
00099     // FIXME: Create subtree paths (breaking at `/' letters)?
00100     // FIXME: Notify document about changes?
00101     ASSERT (m_state);
00102     // NOTE: assertion not needed.
00103     //ASSERT (m_document);
00104 
00105     return new IgSimpleTwig (root (rootName, true), name);
00106 }
00107 
00108 IgTwig *
00109 IgDocumentData::find (const std::string &name, const std::string &rootName)
00110 {
00111     // FIXME: Search subtree path (breaking at `/' letters)?
00112     // FIXME: Notify document about changes?
00113     // FIXME: Provide special root twig that always notifies
00114     //  document about changes and add a protocol for twigs
00115     //  to notify their parents when they add children.
00116     ASSERT (m_state);
00117     // NOTE: Assertion not needed?
00118     //ASSERT (m_document);
00119     IgSimpleTwig *parent = root (rootName, true);
00120     for (unsigned i = 0; i < parent->children (); ++i)
00121     {
00122         IgTwig *child = parent->child (i);
00123         if (child->name () == name)
00124             return child;
00125     }
00126     return 0;
00127 }
00128 
00129 IgDocumentData::TwigMap::const_iterator
00130 IgDocumentData::begin (void)
00131 {
00132     return m_rootMap.begin ();    
00133 }
00134 
00135 IgDocumentData::TwigMap::const_iterator
00136 IgDocumentData::end (void)
00137 {
00138     return m_rootMap.end ();
00139 }

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