Revision: 44612
          http://brlcad.svn.sourceforge.net/brlcad/?rev=44612&view=rev
Author:   davidloman
Date:     2011-05-12 15:19:49 +0000 (Thu, 12 May 2011)

Log Message:
-----------
Work on making the paths for db objects work correctly.  Now objects show up in 
manifest with correct paths, rather than appearing to all be at TOP

Modified Paths:
--------------
    rt^3/trunk/include/MinimalDatabase.h
    rt^3/trunk/src/libge/MinimalDatabase.cxx
    rt^3/trunk/src/libge/MinimalObject.cxx

Modified: rt^3/trunk/include/MinimalDatabase.h
===================================================================
--- rt^3/trunk/include/MinimalDatabase.h        2011-05-12 12:04:48 UTC (rev 
44611)
+++ rt^3/trunk/include/MinimalDatabase.h        2011-05-12 15:19:49 UTC (rev 
44612)
@@ -39,6 +39,16 @@
 #include <iostream>
 
 namespace BRLCAD {
+
+       /* Need a simple super class to expose constructor */
+       class MinimalCombination: public BRLCAD::Combination {
+       protected:
+               MinimalCombination(resource* resp, directory* pDir, 
rt_db_internal* ip,
+                               db_i* dbip): BRLCAD::Combination(resp, pDir,ip, 
dbip) {};
+               friend class MinimalDatabase;
+       };
+
+
        class MinimalDatabase : public MemoryDatabase {
        public:
                MinimalDatabase() throw(bad_alloc);
@@ -62,15 +72,30 @@
                std::list<MinimalObject*>* getAllObjects();
                std::list<MinimalObject*>* getAllTopObjects();
 
+       std::list<MinimalObject*>* getAllObjs();
+       std::list<MinimalObject*>* getAllObjsBelow(const std::string 
objectName);
+       void getAllObjsBelowRecursor(const std::string, const char*,
+                       std::list<MinimalObject*>*) ;
+       void treeNodeRecursor(const BRLCAD::Combination::ConstTreeNode&,
+                       const std::string, std::list<MinimalObject*>*);
+
+       struct bu_external* buildExternal(struct directory*, struct db_i*);
+       MinimalObject* buildMinimalObject(std::string, std::string, struct 
bu_external*);
+
        private:
-               /// Performs database object look ups, but copies the contents 
into a bu_external which it returns
-               bu_external* GetExternal(const char* objectName) const;
+       /// Performs database object look ups, but copies the contents into a 
bu_external which it returns
+       bu_external* GetExternal(const char* objectName);
 
-               void _searchNode(BRLCAD::Combination::ConstTreeNode node, 
std::list<MinimalObject*>* list);
+       void _searchNode(BRLCAD::Combination::ConstTreeNode node,
+                       std::list<MinimalObject*>* list);
 
-               std::string currentFilePath;
+       std::string currentFilePath;
+
+
+
        };
 }
+
 #endif /* __MINIMALDATABASE_H__ */
 
 /*

Modified: rt^3/trunk/src/libge/MinimalDatabase.cxx
===================================================================
--- rt^3/trunk/src/libge/MinimalDatabase.cxx    2011-05-12 12:04:48 UTC (rev 
44611)
+++ rt^3/trunk/src/libge/MinimalDatabase.cxx    2011-05-12 15:19:49 UTC (rev 
44612)
@@ -45,6 +45,27 @@
 }
 
 MinimalDatabase::~MinimalDatabase(void) throw() {
+    if (m_wdbp != 0) {
+        if (!BU_SETJUMP)
+            wdb_close(m_wdbp);
+
+        BU_UNSETJUMP;
+        m_wdbp = NULL;
+    }
+
+    if (m_rtip != 0) {
+        if (!BU_SETJUMP)
+            rt_free_rti(m_rtip);
+
+        BU_UNSETJUMP;
+        m_rtip = NULL;
+    }
+
+    if (m_resp != 0) {
+        rt_clean_resource_complete(0, m_resp);
+        bu_free(m_resp, "BRLCAD::ConstDatabase::~ConstDatabase::m_resp");
+        m_resp = NULL;
+    }
 }
 
 MinimalObject*
@@ -158,12 +179,48 @@
        return objs;
 }
 
-bu_external*
-MinimalDatabase::GetExternal
+
+std::list<MinimalObject*>*
+MinimalDatabase::getAllObjs()
+{
+       std::list<MinimalObject*>* objList = new std::list<MinimalObject*>();
+
+       ConstDatabase::TopObjectIterator it = this->FirstTopObject();
+       std::string name = "";
+
+       while (it.Good()) {
+               name = it.Name();
+               if (name.length() > 0)
+                       this->getAllObjsBelowRecursor(this->currentFilePath + 
"/", name.c_str(), objList);
+               ++it;
+       }
+
+       return objList;
+}
+
+
+std::list<MinimalObject*>*
+MinimalDatabase::getAllObjsBelow
 (
-    const char*     objectName
-) const {
+       const std::string objectName
+) {
+       std::list<MinimalObject*>* objList = new std::list<MinimalObject*>();
+
+       if (objectName.length() > 0)
+               this->getAllObjsBelowRecursor(this->currentFilePath + "/", 
objectName.c_str(), objList);
+
+       return objList;
+}
+
+void
+MinimalDatabase::getAllObjsBelowRecursor
+(
+       const std::string currentPath,
+       const char*     objectName,
+       std::list<MinimalObject*>* objList
+)  {
        bu_external* ext = NULL;
+       MinimalObject* obj = NULL;
 
     if (m_rtip != 0) {
         if (!BU_SETJUMP) {
@@ -171,22 +228,112 @@
                 directory* pDir = db_lookup(m_rtip->rti_dbip, objectName, 
LOOKUP_NOISE);
 
                 if (pDir != RT_DIR_NULL) {
-                    /* Check to see if passed in ext was malloced */
-                    if (ext == NULL)
-                       ext = 
(bu_external*)bu_calloc(sizeof(bu_external),1,"GetExternal bu_external calloc");
+                    rt_db_internal intern;
+                    int            id = rt_db_get_internal(&intern, pDir, 
m_rtip->rti_dbip, 0, m_resp);
 
-                       int rVal = db_get_external(ext, pDir, 
this->m_rtip->rti_dbip);
+                    try {
+                                               ext = buildExternal(pDir, 
m_rtip->rti_dbip);
 
-                       if (rVal < 0) {
+                                               if (ext == NULL) {
+                                                       std::cout << 
"buildExternal FAILED\n";
+                                               } else {
+                                                       obj = 
this->buildMinimalObject(currentPath, objectName, ext);
+                                                       if (ext == NULL) {
+                                                               std::cout << 
"buildMinimalObject FAILED\n";
+                                                       } else {
+
+                                                               /* Add to list 
*/
+                                                               
objList->push_back(obj);
+
+                                                               /* Recurse on 
combs */
+                                                               if (id == 
ID_COMBINATION) {
+                                                                       
MinimalCombination comb (m_resp, pDir, &intern, m_rtip->rti_dbip);
+                                                                       
std::string newPath = currentPath + "/" + objectName;
+
+                                                                       
treeNodeRecursor(comb.Tree(), newPath, objList);
+                                                               }
+                                                       }
+                                               }
+                    }
+                    catch(...) {
                         BU_UNSETJUMP;
-                               bu_free(ext, "Freeing bu_external due to 
error.");
-                               return ext;
-                       }
+                        rt_db_free_internal(&intern);
+                        throw;
+                    }
+
+                    rt_db_free_internal(&intern);
                 }
             }
         }
+
         BU_UNSETJUMP;
     }
+}
+
+
+void
+MinimalDatabase::treeNodeRecursor
+(
+               const BRLCAD::Combination::ConstTreeNode& node,
+               const std::string currentPath,
+               std::list<MinimalObject*>* objList
+) {
+    switch (node.Operation()) {
+        case BRLCAD::Combination::ConstTreeNode::Union:
+        case BRLCAD::Combination::ConstTreeNode::Intersection:
+        case BRLCAD::Combination::ConstTreeNode::Subtraction:
+        case BRLCAD::Combination::ConstTreeNode::ExclusiveOr:
+               treeNodeRecursor(node.LeftOperand(), currentPath, objList);
+               treeNodeRecursor(node.RightOperand(), currentPath, objList);
+            break;
+
+        case BRLCAD::Combination::ConstTreeNode::Not:
+               treeNodeRecursor(node.Operand(), currentPath, objList);
+            break;
+
+        case BRLCAD::Combination::ConstTreeNode::Leaf:
+               std::string nodeName = node.Name();
+                       this->getAllObjsBelowRecursor(currentPath, 
nodeName.c_str(), objList);
+    }
+
+}
+
+struct bu_external*
+MinimalDatabase::buildExternal(struct directory* pDir, struct db_i* dbip) {
+       bu_external* ext = 
(bu_external*)bu_calloc(sizeof(bu_external),1,"GetExternal bu_external calloc");
+
+       int rVal = db_get_external(ext, pDir, dbip);
+
+       if (rVal < 0) {
+               bu_free(ext, "Freeing bu_external due to error.");
+               return NULL;
+       }
+       return ext;
+}
+
+MinimalObject*
+MinimalDatabase::buildMinimalObject(std::string path, std::string objName, 
bu_external* ext)
+{
+       return new MinimalObject(path, objName, ext);
+}
+
+bu_external*
+MinimalDatabase::GetExternal
+(
+    const char*     objectName
+) {
+       bu_external* ext = NULL;
+
+    if (m_rtip != 0) {
+        if (!BU_SETJUMP) {
+            if ((objectName != 0) && (strlen(objectName) > 0)) {
+                directory* pDir = db_lookup(m_rtip->rti_dbip, objectName, 
LOOKUP_NOISE);
+                if (pDir != RT_DIR_NULL)
+                       ext = this->buildExternal(pDir, this->m_rtip->rti_dbip);
+            }
+        }
+        BU_UNSETJUMP;
+    }
     return ext;
 }
 

Modified: rt^3/trunk/src/libge/MinimalObject.cxx
===================================================================
--- rt^3/trunk/src/libge/MinimalObject.cxx      2011-05-12 12:04:48 UTC (rev 
44611)
+++ rt^3/trunk/src/libge/MinimalObject.cxx      2011-05-12 15:19:49 UTC (rev 
44612)
@@ -31,12 +31,10 @@
 
 MinimalObject::MinimalObject(
                std::string filePath, std::string objName, bu_external* ext
-) : ext(ext), filePath(filePath), objName(objName){}
+) : ext(ext), filePath(filePath), objName(objName) {}
 
-MinimalObject::~MinimalObject(void) {
+MinimalObject::~MinimalObject(void){}
 
-}
-
 bu_external*
 MinimalObject::getBuExternal()
 {
@@ -54,6 +52,7 @@
 {
        return this->objName;
 }
+
 std::string
 MinimalObject::getFullRepoPath()
 {
@@ -63,6 +62,7 @@
        fullPath += this->getObjectName(); /* obj name in file */
        return fullPath;
 }
+
 void
 MinimalObject::printObjState()
 {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to