]> Creatis software - creaImageIO.git/commitdiff
*** empty log message ***
authorguigues <guigues>
Wed, 11 Feb 2009 07:32:16 +0000 (07:32 +0000)
committerguigues <guigues>
Wed, 11 Feb 2009 07:32:16 +0000 (07:32 +0000)
appli/gimmick/main.cxx
src2/creaImageIOSQLiteTreeHandler.cpp
src2/creaImageIOSQLiteTreeHandler.h
src2/creaImageIOTree.h
src2/creaImageIOTreeAttributeDescriptor.h
src2/creaImageIOTreeDescriptor.cpp
src2/creaImageIOTreeHandler.h
src2/creaImageIOTreeNode.cpp
src2/creaImageIOTreeNode.h
src2/doxygen/CMakeLists.txt

index 7f21a164e767fce677bc168b63c6d9e98da2a39b..d90f0b8bcfa15f955261f571e2bef05c284c78d1 100644 (file)
@@ -1,8 +1,17 @@
 #include <creaImageIOGimmick.h>
+#include <creaMessageManager.h>
 
 int main(int argc, char* argv[])
 {
+  bool debug = false;
+  if(argc>1) 
+    {
+      debug = true;
+    }
+
   creaImageIO::Gimmick g;
+  g.SetDebugMode(debug);
+
   if (!g.Initialize()) return 1;
   if (!g.Finalize()) return 1;
   return 0;
index 4d0d49eae165825a158b77f9788857c54d07a3a1..e1a0307b3673093365844786789de7e0d589ac02 100644 (file)
@@ -50,22 +50,6 @@ namespace creaImageIO
   //=============================================================
   
 
-  //=============================================================
-  void SQLiteTreeHandler::BuildDefaultTreeDescription()
-  {
-    /*
-    for (int i = Node::Patient;
-        i <= Node::Image; 
-        ++i)
-      {
-       mNodeTypeDescription[i].BuildDefault(i);
-      }
-    */
-
-    // TODO : GetTree().GetDescription().LoadXML(FILE);
-  }
-  //=============================================================
-
   //=============================================================
   //  void SQLiteTreeHandler::Print() const 
   //  {
@@ -91,54 +75,6 @@ namespace creaImageIO
   */
   //=====================================================================
 
-  //=====================================================================
-  char* format_sql(const std::string& s)
-  { 
-    return sqlite3_mprintf("%q",s.c_str());
-  }
-  //=====================================================================
-
-  //  sqlite3_exec(db, zSQL, 0, 0, 0);
-  //  sqlite3_free(zSQL);
-  //   char* CHAIN = format_sql(QUER);         \
-//  sqlite3_free(CHAIN);                               \
-
-  //=====================================================================
-#define QUERYDB(QUER,RES)                                              \
-    try                                                                        \
-      {                                                                        \
-       GimmickMessage(2,"SQL: '"<<QUER<<"'"<<std::endl);               \
-       RES = mDB->execQuery(QUER.c_str());                             \
-      }                                                                        \
-    catch (CppSQLite3Exception& e)                                     \
-      {                                                                        \
-       std::cout << "SQLite query '"<<QUER<<"' : "                     \
-                 << e.errorCode() << ":"                               \
-                 << e.errorMessage()<<std::endl;                       \
-       creaError("SQLite query '"<<QUER<<"' : "                        \
-                 << e.errorCode() << ":"                               \
-                 << e.errorMessage() );                                \
-      }                                                                        \
-    
-  //=====================================================================
-  
-  //=====================================================================
-#define UPDATEDB(UP)                                                   \
-  try                                                                  \
-    {                                                                  \
-      GimmickMessage(2,"SQL: '"<<UP<<"'"<<std::endl);                  \
-      mDB->execDML(UP.c_str());                                                \
-    }                                                                  \
-  catch (CppSQLite3Exception& e)                                       \
-    {                                                                  \
-      std::cout << "SQLite update '"<<UP<<"' Error : "                 \
-               << e.errorCode() << ":"                                 \
-               << e.errorMessage()<<std::endl;                         \
-      creaError("SQLite update '"<<UP<<"' Error : "                    \
-               << e.errorCode() << ":"                                 \
-               << e.errorMessage() );                                  \
-    }                                                                  
-  //=====================================================================
 
   //=====================================================================
   bool SQLiteTreeHandler::Open(bool writable)
@@ -161,7 +97,7 @@ namespace creaImageIO
   //=====================================================================
   bool SQLiteTreeHandler::Close()
   {
-    return false;
+    return true;
   }
   //=====================================================================
 
@@ -198,8 +134,54 @@ namespace creaImageIO
 
 
   //===================================================================== 
-  int SQLiteTreeHandler::AddBranch( const std::map<std::string,std::string>& attr )
+  int SQLiteTreeHandler::AddBranch( const AttributeMapType& attr )
   {
+    tree::Node* parent = DBGetParent(attr);
+    for (int level = parent->GetLevel()+1;
+        level < GetTree().GetNumberOfLevels();
+        level++)
+      {
+       // Create Node
+       parent = new tree::Node(parent,attr);
+       
+       // Insert into DB
+       if (node->GetType()!=Node::Patient) 
+         node->SetFieldValue("PARENT_ID",parent_id);
+       
+       // Insert in DB
+       std::string val;
+       BuildSQLFieldsValues(node,val);
+       std::string insert("INSERT INTO ");
+       insert += std::string(SQLiteTreeHandlerStructure::Table(node->GetType())) 
+         + " " + val + ";";
+       //    std::cout << "** SQL = '"<<insert<<"'"<<std::endl;
+       UPDATEDB(insert);
+       //    std::cout << "** SQL OK"<<std::endl;
+       
+       // Store DB id of newly created node;
+       long lastrow = mDB->lastRowId();
+       std::stringstream ri;
+       ri << mDB->lastRowId();
+       node_id = ri.str();
+       //    std::cout << "LastRowId='"<<mDB->lastRowId()<<"' vs '"<<created_id<<"'"<<std::endl;
+       
+       node->SetFieldValue("ID",node_id);
+       /*
+       // Insert in TypeId map
+       TypeId ti;
+       ti.type = node->GetType();
+       ti.id = node_id;
+       mTypeIdToNodeMap[ti] = node;
+       //    std::cout << "== Insert TypeId ("<<ti.type<<","<<ti.id<<")"<<std::endl; 
+       // 
+       msw[2].Pause();
+       
+       if (node->GetType()==Node::Patient) summary.added_patients++;
+       if (node->GetType()==Node::Study) summary.added_studies++;
+       if (node->GetType()==Node::Series) summary.added_series++;
+       if (node->GetType()==Node::Image) summary.added_images++;
+       */
+      }
     return -1;
   }
   //===================================================================== 
@@ -218,10 +200,76 @@ namespace creaImageIO
 
 
 
+
+
+
+
+
+
+
+
+  //=====================================================================
+  // SQLite DB specific methods
+  //=====================================================================
+
+
+
+
+  //=====================================================================
+  char* format_sql(const std::string& s)
+  { 
+    return sqlite3_mprintf("%q",s.c_str());
+  }
+  //=====================================================================
+
+  //  sqlite3_exec(db, zSQL, 0, 0, 0);
+  //  sqlite3_free(zSQL);
+  //   char* CHAIN = format_sql(QUER);         \
+//  sqlite3_free(CHAIN);                               \
+
+  //=====================================================================
+#define QUERYDB(QUER,RES)                                              \
+    try                                                                        \
+      {                                                                        \
+       GimmickMessage(2,"SQL: '"<<QUER<<"'"<<std::endl);               \
+       RES = mDB->execQuery(QUER.c_str());                             \
+      }                                                                        \
+    catch (CppSQLite3Exception& e)                                     \
+      {                                                                        \
+       std::cout << "SQLite query '"<<QUER<<"' : "                     \
+                 << e.errorCode() << ":"                               \
+                 << e.errorMessage()<<std::endl;                       \
+       creaError("SQLite query '"<<QUER<<"' : "                        \
+                 << e.errorCode() << ":"                               \
+                 << e.errorMessage() );                                \
+      }                                                                        \
+    
+  //=====================================================================
+  
+  //=====================================================================
+#define UPDATEDB(UP)                                                   \
+  try                                                                  \
+    {                                                                  \
+      GimmickMessage(2,"SQL: '"<<UP<<"'"<<std::endl);                  \
+      mDB->execDML(UP.c_str());                                                \
+    }                                                                  \
+  catch (CppSQLite3Exception& e)                                       \
+    {                                                                  \
+      std::cout << "SQLite update '"<<UP<<"' Error : "                 \
+               << e.errorCode() << ":"                                 \
+               << e.errorMessage()<<std::endl;                         \
+      creaError("SQLite update '"<<UP<<"' Error : "                    \
+               << e.errorCode() << ":"                                 \
+               << e.errorMessage() );                                  \
+    }                                                                  
+  //=====================================================================
+
+
   //=====================================================================
   bool SQLiteTreeHandler::DBOpen()
   {
-    GimmickMessage(2,"Opening SQLite database '"<<GetFileName()<<std::endl);
+    GimmickMessage(1,"Opening SQLite database '"<<GetFileName()
+                  <<"' ... "<<std::endl);
     // OPENING FILE
     if (!boost::filesystem::exists(GetFileName())) 
       {
@@ -239,15 +287,14 @@ namespace creaImageIO
                  << e.errorMessage() << std::endl;
        return false;
       }
-    // TESTING STRUCTURE VALIDITY
-    if (!DBStructureIsValid())
+    // IMPORT TREE DESCRIPTION (AND TEST DB VALIDITY)
+    if (!DBImportTreeDescription())
       {
-       std::cerr << "Opening '"<<GetFileName()<<"' : "
-                 << " invalid database structure" << std::endl;
        return false;
       }
-    // IMPORTING NODE TYPE DESCRIPTIONS
-    DBImportTreeDescription();
+
+    GimmickMessage(1,"Opening SQLite database '"<<GetFileName()
+                  <<"' ... OK"<<std::endl);
     return true;
   }
   //=====================================================================
@@ -255,7 +302,8 @@ namespace creaImageIO
   //=====================================================================
   bool SQLiteTreeHandler::DBCreate()
   {
-    //    std::cout << "### Creating SQLite database '"<<GetFileName()<<std::endl;
+    GimmickMessage(1,"Creating SQLite database '"<<GetFileName()
+                  <<"' ... "<<std::endl);
 
     if (boost::filesystem::exists(GetFileName())) 
       {
@@ -288,60 +336,101 @@ namespace creaImageIO
        command += "( Name text )\n";
        UPDATEDB(command);
 
-       // Level 0
-       command = "INSERT INTO Levels (Name) VALUES ('";
-       command += GetTree().GetLevelDescriptor(0).GetName();
-       command += "')";
-       UPDATEDB(command);
-
-       command = "CREATE TABLE ";
-       command += GetTree().GetLevelDescriptor(0).GetName();
-       command += "\n(\nID INTEGER PRIMARY KEY";
-       AppendAttributesSQLDefinition(0,command);
-       command += "\n)";
-       UPDATEDB(command);
-       
-       // Iterate the other Levels
-       for (int l=1; l<GetTree().GetNumberOfLevels(); ++l)
+       // Iterate the Levels
+       for (int l=0; l<GetTree().GetNumberOfLevels(); ++l)
          {
            command = "INSERT INTO LEVELS (Name) VALUES ('";
            command += GetTree().GetLevelDescriptor(l).GetName();
            command += "')";
            UPDATEDB(command);
            
+           // Create table of level (for level>0, i.e. not Root)
+           if (l>0)
+             {
+               command = "CREATE TABLE ";
+               command += GetTree().GetLevelDescriptor(l).GetName();
+               command += "\n(\nID INTEGER PRIMARY KEY";
+               if (l>1) 
+                 {
+                   command += ",\nPARENT_ID int not null";     
+                 }
+               AppendAttributesSQLDefinition(l,command);
+               if (l>1) 
+                 {
+                   command += ",\nconstraint FK_PARENT foreign key (PARENT_ID) references ";
+                   command += GetTree().GetLevelDescriptor(l-1).GetName();
+                   command += "(ID) on delete restrict on update restrict";
+                 }
+               command += "\n)";
+               UPDATEDB(command);
+
+
+               // Add Attribute 'ID' to Description
+               GetTree().GetAttributeDescriptorList(l).push_back
+                 (AttributeDescriptor( "ID",
+                                       "Database Identifier",
+                                       0,0,
+                                       AttributeDescriptor::PRIVATE
+                                       ));
+
+               if (l>1) 
+                 {
+                   // Add Attribute 'PARENT_ID' to Description
+                   GetTree().GetAttributeDescriptorList(l).push_back
+                     (AttributeDescriptor( "PARENT_ID",
+                                           "Database Parent Identifier",
+                                           0,0,
+                                           AttributeDescriptor::PRIVATE
+                                           ));
+                 }
+               
+             }
+           
+           // Create table *_ATTRIBUTES
+           
            command = "CREATE TABLE ";
            command += GetTree().GetLevelDescriptor(l).GetName();
-           command += "\n(\nID INTEGER PRIMARY KEY,\nPARENT_ID int not null";  
-           AppendAttributesSQLDefinition(l,command);
-           command +=",\n";
-           command +="constraint FK_PARENT foreign key (PARENT_ID) references PATIENT(ID) on delete restrict on update restrict\n)";
+           command += "_Attributes\n(\n";
+           command += "Key text,\n";
+           command += "Name text,\n";      
+           command += "DicomGroup int,\n";
+           command += "DicomElement int,\n";       
+           command += "Flags int\n";       
+           command += "\n)";
            UPDATEDB(command);
+         
+  
+           // Fill the table *_ATTRIBUTES
+           LevelDescriptor::AttributeDescriptorListType::const_iterator i;
+           for (i  = GetTree().GetAttributeDescriptorList(l).begin();
+                i != GetTree().GetAttributeDescriptorList(l).end();
+                ++i)
+             {
+               
+               std::stringstream insert;
+               insert << "INSERT INTO "
+                      << GetTree().GetLevelDescriptor(l).GetName()
+                      << "_Attributes (Key,Name,DicomGroup,DicomElement,Flags) "
+                      << "VALUES ('"
+                      << i->GetKey() << "','"
+                      << i->GetName() << "',"
+                      << i->GetGroup() << ","
+                      << i->GetElement() << ","
+                      << i->GetFlags() << ");";
+               
+               UPDATEDB(insert.str());
+             }
          }
-       
-       // Create tables *_ATTRIBUTES
-       // and fill the tables *_ATTRIBUTES
-       DBExportTreeDescription();
-       
       }
     catch (std::exception)
       {
        return false;
       }
-    // LG : TEST
-    if (DBStructureIsValid())
-      {
-       //      std::cout << "*** DONE ***"<<std::endl;
-       //      mDBLoaded = true;
-       GetTree().SetChildrenLoaded(true);
-       return true;
-       
-      }
-    else 
-      {
-       //      std::cout << "*** AAAARRRRGGG ***"<<std::endl;
-       
-       return false;
-      }
+
+    GetTree().SetChildrenLoaded(true);
+    GimmickMessage(1,"Creating SQLite database '"<<GetFileName()
+                  <<"' ... OK"<<std::endl);
+    return true;
   }
   //=====================================================================
   
@@ -362,125 +451,202 @@ namespace creaImageIO
   }
   //=====================================================================
   
-  //=====================================================================
-  void SQLiteTreeHandler::DBExportTreeDescription()
-  {
-    for (int level=0; level<GetTree().GetNumberOfLevels(); ++level)
-      {
-       std::string command;
-       command = "CREATE TABLE ";
-       command += GetTree().GetLevelDescriptor(level).GetName();
-       command += "_Attributes\n(\n";
-       command += "Key text,\n";
-       command += "Name text,\n";          
-       command += "DicomGroup int,\n";
-       command += "DicomElement int,\n";           
-       command += "Flags int\n";           
-       command += "\n)";
-       UPDATEDB(command);
-       LevelDescriptor::AttributeDescriptorListType::const_iterator i;
-       for (i  = GetTree().GetAttributeDescriptorList(level).begin();
-            i != GetTree().GetAttributeDescriptorList(level).end();
-            ++i)
-         {
-           
-           std::stringstream insert;
-           insert << "INSERT INTO "
-                  << GetTree().GetLevelDescriptor(level).GetName()
-                  << "_Attributes (Key,Name,DicomGroup,DicomElement,Flags) "
-                  << "VALUES ('"
-                  << i->GetKey() << "','"
-                  << i->GetName() << "',"
-                  << i->GetGroup() << ","
-                  << i->GetElement() << ","
-                  << i->GetFlags() << ");";
-
-           UPDATEDB(insert.str());
-         }
-      }
-    
-  }
-  //=====================================================================
   
   //=====================================================================
-  void SQLiteTreeHandler::DBImportTreeDescription()
+  bool SQLiteTreeHandler::DBImportTreeDescription()
   {
-    GimmickMessage(3,"ImportTreeDescription"<<std::endl);
-    
-    //    tree::Description& desc = GetTree().GetDescription();
-    /*
+    GimmickMessage(1,"Importing tree description from database ..."
+                  <<std::endl);
 
-    for (Node::Type type=Node::Patient; 
-        type<=Node::Image; 
-        type++)
+    // Test table 'LEVELS' existence
+    if ( ! mDB->tableExists("LEVELS") )
       {
-       std::string query = "SELECT * FROM ";
-       query += SQLiteTreeHandlerStructure::Table(type);
-       query += "_FIELDS";
+       GimmickMessage(1,"!! ERROR : Table 'LEVELS' does not exist"
+                      <<std::endl);
+       return false;
+      }
 
-       //      std::cout << "** SQL = '"<<query<<"'"<<std::endl;
+    tree::Descriptor& desc = GetTree().GetDescriptor();
+    // clears the existing one
+    desc.GetLevelDescriptorList().clear();
+     
+    int nblevel = 0;
+    std::string query = "SELECT * FROM LEVELS";
+    CppSQLite3Query q;
+    QUERYDB(query,q);
+
+    while (!q.eof())
+      {
+       std::string name = q.getStringField(0);
+       GimmickMessage(2," * Importing level '"<<name<<"'"<<std::endl);
+       desc.GetLevelDescriptorList().push_back(LevelDescriptor(name));
+       nblevel++;
+       q.nextRow();
+      }   
+    
+    for (int level = 0; level < nblevel; ++level )
+      {
+       std::string table = GetTree().GetLevelDescriptor(level).GetName();
+       table += "_Attributes";
+       // Test table 'LEVELS' existence
+       if ( ! mDB->tableExists(table.c_str()) )
+         {
+           GimmickMessage(1,"!! ERROR : Table '"<<table<<"' does not exist"
+                          <<std::endl);
+           return false;
+         }
        
+       std::string query = "SELECT * FROM ";
+       query += table;
        CppSQLite3Query q;
        QUERYDB(query,q);
        
+       GimmickMessage(2," * Level '"
+                      <<GetTree().GetLevelDescriptor(level).GetName()
+                      <<"'"<<std::endl);
+
+       // Test that ID and PARENT_ID mandatory attributes exist
+       bool ID_found = false;
+       bool PARENT_ID_found = false;
+       if (level==0) ID_found = true;
+       if (level<=1) PARENT_ID_found = true;
 
        while (!q.eof())
          {
-           Field::Description d(q.getStringField(0), // Key
-                                q.getIntField(1), // Group
-                                q.getIntField(2), // Element 
-                                q.getStringField(3), // Name
-                                q.getIntField(4) // Flags
-                                );
-           GetNodeTypeDescription(type).GetFieldDescriptionMap()[d.key] = d;
-           //      std::cout << d << std::endl;
+           std::string key(q.getStringField(0));
+           std::string name(q.getStringField(1));
+           GimmickMessage(2,"  - Importing attribute '"<<key<<"' '"<<name
+                          <<"'"<<std::endl);
+           desc.GetAttributeDescriptorList(level).push_back
+             (AttributeDescriptor( key, // Key
+                                   name, // Name
+                                   q.getIntField(2), // Group
+                                   q.getIntField(3), // Element 
+                                   q.getIntField(4) // Flags
+                                   ));
+           if ( key == "ID" ) 
+             {
+               ID_found = true;
+             }
+           if ( key == "PARENT_ID" ) 
+             {
+               PARENT_ID_found = true;
+             }
            q.nextRow();
          }
+       
+       if ( ! (ID_found || PARENT_ID_found ) )
+         {
+           GimmickMessage(1,"!! ERROR : Table '"<<table
+                          <<"' does not contain mandatory attribute ID or PARENT_ID"
+                          <<std::endl);
+           return false;
+         }
       }
-    */
+
+    GimmickMessage(1,"Importing tree description from database ... OK"
+                  <<std::endl);
+    return true;
   }
   //=====================================================================
 
 
-    //=====================================================================
-  bool SQLiteTreeHandler::DBStructureIsValid()
+
+
+
+
+
+
+
+
+
+
+
+
+
+  //=====================================================================
+  tree::Node* SQLiteTreeHandler::DBGetParent( const AttributeMapType& attr) 
   {
-    bool success = true;
+    Node* parent = GetTree().GetTree();
+    bool go_down;
+    do 
+      {
+       go_down = false;
+       // Load the children of the current parent
+       DBLoadChildren(parent);
+       // Iterate the children 
+       tree::Node::ChildrenListType::const_iterator i;
+       for (i = parent->GetChildrenList().begin();
+            i!= parent->GetChildrenList().end();
+            ++i)
+         {
+           if ( (*i)->Matches( attr ) ) 
+             {
+               go_down = true;
+               parent = *i;
+             }
+         }     
+      }
+    while (go_down);
+    return parent;
+  }
+  //=====================================================================
 
-    // TO DO : TABLE WHICH STORES THE LEVELS
-    /*
-    
-    for (int i = SQLiteTreeHandlerStructure::TableBegin();
-        i    != SQLiteTreeHandlerStructure::TableEnd();++i)
+
+  //=====================================================================
+  int SQLiteTreeHandler::DBLoadChildren(tree::Node* parent, 
+                                       int numberoflevels)
+  {
+    int nbloaded = 0;
+    if (parent->GetChildrenLoaded()) return nbloaded;
+
+    // Query DB
+    int level = parent->GetLevel();
+    std::string query = "SELECT * FROM ";
+    query += GetTree().GetLevelDescriptor(level+1).GetName();
+    if (level>1)
       {
-       bool ok = mDB->tableExists(SQLiteTreeHandlerStructure::Table(i));
-       if (ok) 
+       query += " WHERE PARENT_ID='" + parent->UnsafeGetAttribute("ID") 
+         + "'";
+      }
+    CppSQLite3Query q;
+    QUERYDB(query,q);
+
+    while (!q.eof())
+      {
+       nbloaded++;
+       Node* n = new Node(parent);
+       for (int fld = 0; fld < q.numFields(); fld++)
          {
-           //      std::cout << "** Table "<<SQLiteTreeHandlerStructure::Table(i)
-           //                <<" exists"<<std::endl;
-           // TO DO : TEST MANDATORY FIELDS EXIST
+           n->UnsafeSetAttribute(q.fieldName(fld),q.getStringField(fld));          
          }
-       else 
+       /*
+       // Index 
+       TypeId ti;
+       ti.type = type;
+       ti.id = n->GetFieldValue("ID");    
+       mTypeIdToNodeMap[ti] = n;
+       */
+       // recurse 
+       if ( numberoflevels > 1 ) 
          {
-           //      std::cout << "** Table "<<SQLiteTreeHandlerStructure::Table(i)
-           //                <<" does *NOT* exist"<<std::endl;
-           success = false;
+           //  msw[2].Pause();
+           nbloaded += DBLoadChildren(n, numberoflevels-1);
+           //      msw[2].Resume();
          }
+       // next entry in db
+       q.nextRow();
       }
-    */
-    return success;
-  }  
-  //=====================================================================
 
-  /*
-  //=====================================================================
-  int SQLiteTreeHandler::DBLoadChildren(Node* parent, 
-                                       int maxlevel)
-  {
+    parent->SetChildrenLoaded(true);
+    
+    //    msw[2].Pause();
+    return nbloaded;
 
     //    std::cout << "SQLiteTreeHandler::DBLoadChildren("<<parent<<","<<maxlevel
-    //       << ")"<<std::endl;
+    //      << ")"<<std::endl;
+    /*
     int nbloaded = 0;
     if (parent == GetTree()) { parent = 0; }
     Node* xparent = parent;
@@ -548,6 +714,7 @@ namespace creaImageIO
     
     //    msw[2].Pause();
     return nbloaded;
+    */
   }
   //=====================================================================
 
@@ -555,7 +722,7 @@ namespace creaImageIO
 
 
 
-
+  /*
   //=====================================================================
   bool SQLiteTreeHandler::DBInsert(Node* alien_node,
                                   UpdateSummary& summary)
index 516910e61032be2c57b4e4d7b65fc843ee723868..a1a4f623bccd5ea830c4ffc63617a4eeb83681ff 100644 (file)
@@ -90,32 +90,38 @@ namespace creaImageIO
     /// returns the Level in the tree where the branch was connected 
     /// (-1 for error, 0 for top level, etc. ) 
     /// Of course the branch is loaded on exit
-    virtual int AddBranch
-    ( const std::map<std::string,std::string>& attr );
+    virtual int AddBranch( const AttributeMapType& attr );
     /// Removes the node and its descendants 
     virtual bool Remove(tree::Node*);
-    ///====================================================================
-
-
+    //====================================================================
+    
 
+    
   protected:
-    // Open 
+    //======================================================================
+    /// Open the database
     bool DBOpen();
-    void DBImportTreeDescription();
-
+    /// Import the Tree::Description from database (verifies the structure)
+    bool DBImportTreeDescription();
+    //======================================================================
+    //======================================================================
     // Creation
     /// Creates a new database on disk and the tables
     bool DBCreate();
-    /// Creates the default tree description for a new database
-    void BuildDefaultTreeDescription();
     /// Appends to string s the SQL command to create the attributes of a given level
     void AppendAttributesSQLDefinition(int level, std::string& s);
-    void DBExportTreeDescription();
-    //
+    //======================================================================
 
-    // Test
-    bool DBStructureIsValid();
+    //======================================================================
+    tree::Node* DBGetParent( const AttributeMapType& attr);
+    //======================================================================
 
+    //======================================================================
+    int DBLoadChildren( tree::Node* parent, int numberoflevels = 1);
+    //======================================================================
+
+    /*
+    /// 
     int DBQueryNumberOfChildren(tree::Node* n);
     
     // Insertion
@@ -154,7 +160,7 @@ namespace creaImageIO
 
     tree::Node* GetChildrenLike(tree::Node* internal_parent,
                               tree::Node* alien_node);
-
+    */
   private:
     /// The DB
     CppSQLite3DB* mDB;
@@ -165,6 +171,7 @@ namespace creaImageIO
     void SetWritable(bool w) { mWritable; }
     bool GetWritable() const { return mWritable; }
 
+    /*
     struct TypeId
     {
       int type;
@@ -178,6 +185,7 @@ namespace creaImageIO
     
     typedef std::map<TypeId,tree::Node*> TypeIdToNodeMapType;
     TypeIdToNodeMapType mTypeIdToNodeMap;
+    */
   };
   // EO class SQLiteTreeHandler
   //=======================================================================
index 854693d3409ab2e6f08c2d7db7a5f02d31518149..3a4ba0556a29cee0bbb889c825e1be87eb9bc4c1 100644 (file)
@@ -20,6 +20,8 @@ namespace creaImageIO
     
     //=====================================================================
     /// An attributed tree structure
+    /**
+     */
     class Tree : public Node
     {
     public:
index dc734bd62964469ef4d4600890d1366d5192866d..1a68bfa1f3e69c5593870cb86b5bda647516c8c9 100644 (file)
@@ -16,7 +16,7 @@ namespace creaImageIO
     public:
       /// Flags
       /// The attribute is hidden (not visible to user)
-      static const unsigned int HIDDEN;
+      static const unsigned int PRIVATE;
       /// The attribute enters in unique identifier constitution (KEY)
       static const unsigned int KEY;
       /// The attribute enters in label constitution (for printing)
@@ -27,6 +27,17 @@ namespace creaImageIO
        : mKey(""), mName(""), mGroup(0), mElement(0), mFlags(0)
       {
       }
+      /// Ctor with all explicitely
+      AttributeDescriptor(const std::string& key,
+                         const std::string& name,
+                         unsigned short group,
+                         unsigned short element,
+                         unsigned int flags)
+       : mKey(key), mName(name), mGroup(group), mElement(element), 
+         mFlags(flags)
+      {
+      }
+
       // Ctor with key, name and flags
       AttributeDescriptor(const std::string& key,
                          const std::string& name,
index 6c253ba1286a1f235a7d2e16cc882094a75d9723..c9a4e009c824ebf2b7051aa03254fd10d2c34780 100644 (file)
@@ -9,7 +9,7 @@ namespace creaImageIO
 
     //==================================================================
     /// The attribute is hidden (not visible to user)
-    const unsigned int AttributeDescriptor::HIDDEN = 1;
+    const unsigned int AttributeDescriptor::PRIVATE = 1;
     /// The attribute enters in unique identifier constitution (KEY)
     const unsigned int AttributeDescriptor::KEY = 2;
     const unsigned int AttributeDescriptor::LABEL = 4;
index c88bbc970921a9c62bf433c965d32d39537c20db..368c519c637e54fbe352ded1b3e16bb9ba056138 100644 (file)
@@ -87,12 +87,12 @@ namespace creaImageIO
     ///====================================================================
     /// WRITE METHODS : WORK ONLY IN WRITE MODE
     ///====================================================================
-    /// Adds a branch in the tree with the attributes provided
+    typedef tree::Node::AttributeMapType AttributeMapType;
+   /// Adds a branch in the tree with the attributes provided
     /// returns the Level in the tree where the branch was connected 
     /// (-1 for error, 0 for top level, etc. ) 
     /// Of course the branch is loaded on exit
-    virtual int AddBranch
-    ( const std::map<std::string,std::string>& attr ) { return -1; }
+    virtual int AddBranch( const AttributeMapType& ) { return -1; }
     /// Removes the node and its descendants 
     bool Remove(tree::Node*)  { return false; }
     ///====================================================================
index 8f03924236e30d7e0dd2b824d9d17e4a288028d2..6bb7d3a7d8bc42ce3d0eda23e3ef8332691f2171 100644 (file)
@@ -25,12 +25,35 @@ namespace creaImageIO
               a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
               ++a)
            {
-             UnsafeSetAttribute( a->GetName(), "" );
+             UnsafeSetAttribute( a->GetKey(), "" );
            }
        }
     }
     //=============================================================
 
+    //=============================================================
+    /// Ctor with parent and attributes map 
+    Node::Node(Node* parent, const AttributeMapType& attr)
+     : mParent(parent),
+       mData(0),
+       mChildrenLoaded(false)
+    {
+      if (parent) 
+       {
+         // Insert into parent's children list
+         parent->GetChildrenList().push_back(this);
+         // Initialize attributes
+         LevelDescriptor::AttributeDescriptorListType::const_iterator a;
+         for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
+              a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
+              ++a)
+           {
+             UnsafeSetAttribute( a->GetKey(), attr[a->GetKey()] );
+           }
+       }
+      
+    }
+    //=============================================================
 
 
     //=============================================================
@@ -85,16 +108,22 @@ namespace creaImageIO
     AttributeMapType::iterator i = mAttributeMap.find(k);
     if (i==mAttributeMap.end())
       {
-       std::cout<<"[Gimmick!] Node::SetAttribute : no attribute with name '"
+       std::cout<<"[Gimmick!] Node::SetAttribute : no attribute with key '"
                 <<k<<"'"<<std::endl;
-       creaError( "[Gimmick!] Node::SetAttribute : no attribute with name '"
+       creaError( "[Gimmick!] Node::SetAttribute : no attribute with key '"
                   <<k<<"'");
       }
     i->second = v;
   }
-  //=============================================================
-
+    //=============================================================
 
+    //=============================================================
+    bool Node::Matches(  const AttributeMapType& ) const
+    {
+      // TO DO 
+      return false;
+    }
+    //=============================================================
   }
 
 }
index 07b46cfb20efe18230ecf071bd23697ed205df90..a97925ec05b5b4e4f25493c29737b5847e4399d7 100644 (file)
@@ -31,8 +31,13 @@ namespace creaImageIO
     class Node
     {
     public:
+      typedef std::map<std::string,std::string> AttributeMapType;
+
+
       /// Ctor with parent
       Node(Node* parent);
+      /// Ctor with parent and attributes map 
+      Node(Node* parent, const AttributeMapType& );
       /// Virtual destructor
       virtual ~Node();
 
@@ -73,7 +78,6 @@ namespace creaImageIO
       /// Remove the given children from the children list
       void RemoveChildrenFromList(Node*);
 
-      typedef std::map<std::string,std::string> AttributeMapType;
 
       AttributeMapType& GetAttributeMap() { return mAttributeMap; }
       const AttributeMapType& GetAttributeMap() const { return mAttributeMap; }
@@ -90,7 +94,9 @@ namespace creaImageIO
       //      { return GetTypeDescription().GetFieldDescription(k); }
 
 
+      /// Returns true iff the KEY attributes of the node match those of the map provided
+      bool Matches( const AttributeMapType& ) const;
+
       /// Returns the node data casted into the type T
       template<class T> T GetData() const 
       { if (mData!=0) return dynamic_cast<T>(mData); return 0; }
index 6d19d78b40fc5f14722b6c817eed3b7f81f47e54..e21635286cae09b7a12baa5f53fd2ba0432d0963 100644 (file)
@@ -85,7 +85,7 @@ CONFIGURE_FILE(
 
 SET(INPUT 
   ${CMAKE_CURRENT_BINARY_DIR}/DoxyMainPage.txt
-  ${PROJECT_SOURCE_DIR}/src
+  ${PROJECT_SOURCE_DIR}/src2
 #  ${PROJECT_SOURCE_DIR}/appli
   )