CMS 3D CMS Logo

Ig3DShapeManager.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/GLBrowsers/interface/Ig3DShapeManager.h"
00004 #include "Iguana/Framework/interface/IgState.h"
00005 #include "Iguana/Framework/interface/IgEnvsElement.h"
00006 #include <classlib/utils/DebugAids.h>
00007 #include <classlib/utils/Log.h>
00008 #include <classlib/iobase/Filename.h>
00009 #include <Inventor/nodes/SoNode.h>
00010 #include <Inventor/nodes/SoSeparator.h>
00011 #include <Inventor/SoInput.h>
00012 #include <Inventor/SoDB.h>
00013 #include <iostream>
00014 
00015 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00016 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00017 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00018 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00019 lat::logflag LFshapeManager = {0, "shapeManager", true, -1 };
00020 
00021 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00022 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00023 IG_DEFINE_STATE_ELEMENT (Ig3DShapeManager, "Services/Shape Manager");
00024 
00025 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00026 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00027 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00028 
00029 Ig3DShapeManager::Ig3DShapeManager (IgState *state)
00030     : m_state (state)
00031 {
00032     m_state->put (s_key, this);
00033 
00034     IgEnvsElement* envs = IgEnvsElement::get(m_state);
00035     std::vector<std::string> iguanaPath;
00036     if (envs->getEnv("IGUANA_PATH", iguanaPath))
00037     {
00038         for(size_t i=0; i<iguanaPath.size(); i++)
00039         {
00040             if (!iguanaPath[i].empty())
00041                 this->addSearchPath (iguanaPath[i]+"/share/ivs/");
00042         }
00043     }
00044 }
00045 
00046 Ig3DShapeManager::~Ig3DShapeManager (void)
00047 {
00048     m_state->detach (s_key);
00049 }
00050 
00051 SoNode *
00052 Ig3DShapeManager::lookup (const std::string &alias)
00053 {
00054     if (m_nodeMap.find (alias) == m_nodeMap.end ())
00055     {
00056         LOG (0, trace, LFshapeManager, 
00057              "Alias " << alias 
00058              << " not found. Adding it as if it was a filename" << std::endl);
00059         
00060         this->add (alias, alias);       
00061     }    
00062 
00063     SoNode *returnNode =  m_nodeMap[alias];    
00064     return returnNode;    
00065 }
00066 
00067 void
00068 Ig3DShapeManager::add (SoNode *node, const std::string &alias, bool /*save*/)
00069 {
00070     node->ref ();    
00071     m_nodeMap.insert (NodeMap::value_type (alias, node));    
00072 }
00073 
00074 void
00075 Ig3DShapeManager::add (const std::string &name, const std::string &alias)
00076 {
00077     lat::Filename filename (name);
00078     lat::Filename completeFilename;
00079     
00080     if (filename.isRelative ())
00081     {
00082         for (PathList::iterator i = m_pathList.begin ();
00083              i != m_pathList.end () 
00084              && completeFilename.empty ();
00085              i++)
00086         {
00087             std::string path = *i;
00088             lat::Filename tmpCompleteFilename
00089                 = path + filename.name ();
00090             LOG (0, trace, LFshapeManager, "Looking up for name "       
00091                  << tmpCompleteFilename.name () << std::endl);
00092             
00093             if (tmpCompleteFilename.exists ())
00094                 completeFilename = tmpCompleteFilename.name ();
00095         }       
00096     }
00097     else
00098     {
00099         if (filename.exists ())
00100             completeFilename = filename;        
00101     }
00102     
00103     LOG (0, trace, LFshapeManager, 
00104          "Loading file: " << completeFilename << std::endl);
00105     
00106     SoInput in;
00107     if (in.openFile (completeFilename))
00108     {
00109         SoNode *node = SoDB::readAll (&in);
00110         if (node)
00111         {
00112             this->add (node, alias, false);                 
00113         }           
00114     }   
00115     return;    
00116 }
00117 
00118 void
00119 Ig3DShapeManager::addAlias (const std::string &oldAlias, 
00120                             const std::string &newAlias)
00121 {
00122     if (m_nodeMap.find (oldAlias) != m_nodeMap.end ())
00123     {
00124         m_nodeMap.insert (NodeMap::value_type (newAlias, m_nodeMap[oldAlias])); 
00125     }    
00126 }
00127 
00128 
00129 void
00130 Ig3DShapeManager::addSearchPath (const std::string &path)
00131 {
00132     lat::Filename pathName (path);
00133     if (pathName.exists ())
00134         m_pathList.push_back (path);
00135     else
00136     {
00137         LOG (0, trace, LFshapeManager, 
00138              "Path not Added (no exists): " << path << std::endl);
00139     }
00140 }

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