]> Creatis software - creaImageIO.git/commitdiff
Correction sur le remove et sur la sélection du répertoire à scanner.
authorFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Wed, 15 Apr 2009 14:13:58 +0000 (14:13 +0000)
committerFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Wed, 15 Apr 2009 14:13:58 +0000 (14:13 +0000)
src2/creaImageIOSQLiteTreeHandler.cpp
src2/creaImageIOTreeNode.cpp
src2/creaImageIOTreeNode.h
src2/creaImageIOWxGimmickView.cpp
src2/creaImageIOWxGimmickView.h
src2/creaImageIOWxTreeView.cpp

index 8dcdd1795dcda95800944e9934bddd3f7c33200f..52042a21a097d8564bbae4950d2ed4ec8890dea8 100644 (file)
@@ -148,9 +148,7 @@ namespace creaImageIO
    tree::Node* parent=node->GetParent();
     if (parent)
       {
-       parent->RemoveChildrenFromList(node);
-       int nC=GetNumberOfChildren(parent);
-       nC=nC-1;
+       int nC = parent->RemoveChildrenFromList(node);
        if(nC>0)
        {       
                std::stringstream out;
@@ -869,10 +867,11 @@ namespace creaImageIO
     sql += GetTree().GetLevelDescriptor(n->GetLevel()).GetName();
     sql += " SET ";
     sql += key;
-    sql += "='";
+    sql += " = '";
     sql += value;
-    sql += "' WHERE ID=";
+    sql += "' WHERE ID = '";
     sql += n->GetAttribute("ID");
+       sql +="'";
     //    sql += " LIMIT 1";
     UPDATEDB(sql);
   }
@@ -977,7 +976,7 @@ namespace creaImageIO
     // Query DB
     int nb=0;
     int level = n->GetLevel();
-    
+
     if(level<GetTree().GetNumberOfLevels()&& level>0)
       {
        std::string query = "SELECT NumberOfChildren FROM ";
index 77ba50f5ade7ee2ee045662e4ea220b7ef9a09d3..faa0bf00cad7982493c084aeb17bce08a0464ee4 100644 (file)
@@ -130,7 +130,7 @@ namespace creaImageIO
     //=============================================================
 
     //=============================================================
-    void Node::RemoveChildrenFromList(Node* node)
+    int Node::RemoveChildrenFromList(Node* node)
     {
       ChildrenListType::iterator i = find(GetChildrenList().begin(),
                                          GetChildrenList().end(),
@@ -139,6 +139,7 @@ namespace creaImageIO
        {
          GetChildrenList().erase(i);
        }
+       return GetChildrenList().size();
     }
     //=============================================================
 
index c85a94471cbce6e4718e366f126a6d0aafcac14b..fca904ca53a216609933bf7459d121fed0cce84a 100644 (file)
@@ -81,7 +81,7 @@ namespace creaImageIO
       const ChildrenListType& GetChildrenList() const { return mChildren; }
 
       /// Remove the given children from the children list
-      void RemoveChildrenFromList(Node*);
+      int RemoveChildrenFromList(Node*);
 
 
       AttributeMapType& GetAttributeMap() { return mAttributeMap; }
@@ -111,7 +111,6 @@ namespace creaImageIO
       /// Sorts the children of the node 
       void SortChildren(const LexicographicalComparator&);
 
-
       virtual void Print() const;
       std::string GetLabel() const;
       /*
index f60480e8365f0762b610b088c582cd52d15eadba..f41ec3e5323fbe994e81226facd51a3d4d962d4e 100644 (file)
@@ -12,6 +12,7 @@ using namespace crea;
 #include "icons/help.xpm"
 
 #include <wx/imaglist.h>
+#include<boost/filesystem/operations.hpp>
 
 namespace creaImageIO
 {
@@ -348,40 +349,54 @@ namespace creaImageIO
     if (FD->ShowModal()==wxID_OK)
       {
        
-       bool recurse = false;
-
-       if (wxMessageBox(_T("Recurse into sub-directories ?"),
-                        _T("Scan directory"),
-                        wxYES_NO,this ) == wxYES)
-         {
-           recurse = true;
+                 std::string dirname = wx2std (FD->GetPath());
+                 bool recurse =  isNeedRecursive(dirname);
+                 if (recurse)
+                {
+             recurse = wxMessageBox(_T("Recurse into sub-directories ?"),  _T("Scan directory"),        wxYES_NO,this ) == wxYES ? true : false;
+                }
+               
+               wxBusyCursor busy;
+               wxString title(_T("Adding directory"));
+               if (recurse) 
+               title = _T("Adding directory (recursive)");
+               mProgressDialog = 
+               new wxProgressDialog(_T("Adding directory"),
+                                       _T(""),
+                                       1000,
+                                       this,
+                                       wxPD_ELAPSED_TIME |
+                                       //                             wxPD_ESTIMATED_TIME | 
+                                       //                             wxPD_REMAINING_TIME |
+                                       wxPD_CAN_ABORT );
+               
+               mCurrentDirectory = FD->GetPath();  
+               
+               // TO DO : select the current tree handler
+               mGimmick->AddDir("Local database",dirname,recurse);
+               
+               mProgressDialog->Pulse(_T("Updating view..."));
+               
+               UpdateTreeViewLevel("Local database",1);
+               delete mProgressDialog;
+               DisplayAddSummary();
          }
-       
-       wxBusyCursor busy;
-       wxString title(_T("Adding directory"));
-       if (recurse) 
-         title = _T("Adding directory (recursive)");
-       mProgressDialog = 
-         new wxProgressDialog(_T("Adding directory"),
-                              _T(""),
-                              1000,
-                              this,
-                              wxPD_ELAPSED_TIME |
-                              //                              wxPD_ESTIMATED_TIME | 
-                              //                              wxPD_REMAINING_TIME |
-                              wxPD_CAN_ABORT );
-       std::string dirname = wx2std (FD->GetPath()) ;
-       mCurrentDirectory = FD->GetPath();  
-       
-       // TO DO : select the current tree handler
-       mGimmick->AddDir("Local database",dirname,recurse);
-       
-       mProgressDialog->Pulse(_T("Updating view..."));
-       
-       UpdateTreeViewLevel("Local database",1);
-       delete mProgressDialog;
-       DisplayAddSummary();
-      }
+  }
+
+    //=================================================
+   // Test a directory to know if contains sub-directory to analyze
+  bool WxGimmickView::isNeedRecursive(std::string i_name)
+  {
+      boost::filesystem::directory_iterator iter(i_name), end_iter;
+         bool bfindir = false;
+                 for(; iter != end_iter; ++iter)
+                 {
+                         if(boost::filesystem::is_directory(*iter))
+                         {
+                                 return true;
+                         }
+                 }
+                 return false;
   }
   //=================================================
 
index 06966a5081a4666de1235e9a2f21cc27ee855d04..73b7d450ae152e522444d9ea160649d58ff092d9 100644 (file)
@@ -108,7 +108,9 @@ namespace creaImageIO
     
     /// Display a message box with the last addition statistics
     void DisplayAddSummary();
-    
+
+       /// Test a directory to know if contains sub-directory to analyze
+       bool isNeedRecursive(std::string i_name);
     
     /// AddProgress Gimmick callback
     void OnAddProgress( Gimmick::AddProgress& );
index 65669c8b1176faf5e1ad89c80d6b2de767e1f2fd..505bf80b21c02e22ac17d35c3315fa97b7856f8c 100644 (file)
@@ -474,10 +474,14 @@ namespace creaImageIO
                                GetCtrl(l)->InsertItem(item);
                            
                                //Setting attributes
-                           
-                               for (int k=0; k<GetCtrl(l)->GetColumnCount(); k++)
+                               for (int k=0; k<GetCtrl(l)->GetColumnCount(); ++k)                              
                                {
-                                       std::string val = (*j)->GetAttribute(mLevelList[l].key[k]);
+                                       std::string val;
+                                       //  Temporary correction : it works but no explanation about the problem FCY
+                                       if(k==0 && level <3)
+                                               val = (*j)->GetAttribute("NumberOfChildren");
+                                       else
+                                               val = (*j)->GetAttribute(mLevelList[l].key[k]);
                                        if(((*j)->GetAttributeDescriptor(mLevelList[l].key[k])).isDateEntry()) // Date
                                        {
                                                boost::gregorian::date d1(boost::gregorian::from_undelimited_string(val));