]> Creatis software - creaImageIO.git/commitdiff
Added Add DataBase event.
authorFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Tue, 28 Apr 2009 09:36:18 +0000 (09:36 +0000)
committerFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Tue, 28 Apr 2009 09:36:18 +0000 (09:36 +0000)
src2/creaImageIOGimmick.cpp
src2/creaImageIOGimmick.h
src2/creaImageIOWxGimmickView.cpp
src2/creaImageIOWxGimmickView.h

index 01e49bd352d5a29bc655e57420fb98b71c89c57b..2d759d0b29a2862547278e8aac7a379ae0e51d4f 100644 (file)
@@ -30,48 +30,19 @@ namespace creaImageIO
   //==============================================================
   void Gimmick::Initialize()
   {
+         std::string i_nameDB = "Local database";
     // Create the UserSettings dir if does not exist
     CreateUserSettingsDirectory();
     // Sets the current directory to the home dir
     mCurrentDirectory =  GetHomeDirectory();
        mSynchronizer=0;
 
-    // Create local database handler
-    mLocalDatabase = new SQLiteTreeHandler(GetLocalDatabasePath());
-    // Add it to the TreeHandlerMap
-    mTreeHandlerMap["Local database"] = mLocalDatabase;
+       std::string dbpath = GetLocalDatabasePath();
     // Create or open local database
-    if (! boost::filesystem::exists( GetLocalDatabasePath() ) )
-      {
-       std::string mess = "Local database '";
-       mess += GetLocalDatabasePath();
-       mess += "' does not exist : creating it";
-       GimmickMessage(1,mess<<std::endl);
-       
-       // CREATING DEFAULT DB STRUCTURE
-//     mLocalDatabase->GetTree().GetDescriptor().CreateDefault();
-       mLocalDatabase->GetTree().GetDescriptor().createDescriptorfromFile(mCurrentDirectory + "\\.gimmick\\localdatabase_Descriptor.txt");
-       
-       if ( ! mLocalDatabase->Create(true) )
-         {
-           GimmickError("ERROR CREATING '"<<GetLocalDatabasePath()<<"'");
-         }
-       mLocalDatabase->SetAttribute(0,"Name","Local database");
-      }
-    else 
-      {
-       /// Open and test it
-       GimmickMessage(1,"Opening local database '"
-                      <<GetLocalDatabasePath()<<"' "
-                      <<std::endl);
-       if ( ! mLocalDatabase->Open(true) )
-         {
-           GimmickError("ERROR OPENING '"<<GetLocalDatabasePath()<<"'");
-         }
-       
-      }
-
-
+       mLocalDatabase = createDB( mCurrentDirectory + "\\.gimmick\\localdatabase_Descriptor.txt", dbpath);
+    // Add it to the TreeHandlerMap
+    mTreeHandlerMap[i_nameDB] = mLocalDatabase;
+    
        // Creates files and directories database
     mTimestampDatabase = new TimestampDatabaseHandler(GetTimestampDatabasePath());
     // Create or open local database
@@ -102,13 +73,66 @@ namespace creaImageIO
       }
 
   }
-  //================================================================
+
+   ///////////////////////////////////////////////////////////////////////
+   // add DB to TreeHandler Map                                                                                        //
+   // @param i_name : DB name                                                                              //
+   // @param i_location : DB location                                                              //
+   // return : -                                                                                                               //
+  ///////////////////////////////////////////////////////////////////////
+       void Gimmick::addDB(std::string &i_name, std::string &i_location)
+       {
+               mTreeHandlerMap[i_name] = new SQLiteTreeHandler(i_location);
+       }
+
+  ///////////////////////////////////////////////////////////////////////////
+  // create a DB from a attributes descriptor file for medical images      //
+  // @param i_locDesc : location of descriptor file                                               //
+  // @param i_locDB : location of DB                                                                      //
+  // return : the SQLiteTreeHandler object on DB                                                  //
+       /////////////////////////////////////////////////////////////////////////
+  SQLiteTreeHandler *Gimmick::createDB(std::string &i_locDesc, std::string &i_locDB)
+  {
+      SQLiteTreeHandler *sqlTreeH = new SQLiteTreeHandler(i_locDB);
+    // Create or open local database
+    if (! boost::filesystem::exists(i_locDB) )
+     {
+         std::string mess = "Local database '";
+         mess += i_locDB;
+         mess += "' does not exist : creating it";
+         GimmickMessage(1,mess<<std::endl);
+         
+                // CREATING DB STRUCTURE
+         sqlTreeH->GetTree().GetDescriptor().createDescriptorfromFile(i_locDesc);
+         if ( ! sqlTreeH->Create(true) )
+                {
+                       GimmickError("ERROR CREATING '"<<i_locDB<<"'");
+         }
+         sqlTreeH->SetAttribute(0,"Name","i_name");
+        }
+        else 
+        {
+               /// Open and test it
+               GimmickMessage(1,"Opening local database '" <<i_locDB<< "' " << std::endl);
+        if ( !sqlTreeH->Open(true) )
+               {
+                       GimmickError("ERROR OPENING '"<<i_locDB<<"'");
+               }
+      }
+        return sqlTreeH;
+  }
 
 
   //==============================================================
   void Gimmick::Finalize()
   {
-    delete mLocalDatabase;
+         // delete SQLiteTreeHandler Object
+          for( TreeHandlerMapType::const_iterator it = mTreeHandlerMap.begin();
+           it!= mTreeHandlerMap.end(); ++it)
+          {
+                  delete it->second;
+          }
        delete mTimestampDatabase;
   }
   //==============================================================
index 5b6606ce679a18acfb36eb829c49281748e57f61..b7fd64741dd2a1edd37fdb7da7f7c7f947fce298 100644 (file)
@@ -97,7 +97,12 @@ namespace creaImageIO
 
     /// Prints the tree handled by the handler
     void Print(const std::string& handler);
+       
+       ///create a DB from a given descriptor file and for a specific location
+       SQLiteTreeHandler *createDB(std::string &i_locDesc, std::string &i_locDB);
 
+       // add an existent DB 
+       void addDB(std::string &i_nameDB, std::string &i_locationDB);
 
     /// Returns the TreeHandler with a given name
     TreeHandler* GetTreeHandler(const std::string& name) const;
index 5b87845400cd574b220c6011c5294055a1d05f05..70c845c9a611c0442fbc666812734b1b5c3301da 100644 (file)
@@ -637,6 +637,35 @@ namespace creaImageIO
     mess << times;
     */
     wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
+  }
+
+  void WxGimmickView::OnAddDB(wxCommandEvent& event)
+  {
+    
+         //Select DB
+         long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
+         std::string wc("*.sqlite3*");
+         wxFileDialog* FD = new wxFileDialog( 0, 
+                                        _T("Select file"),
+                                        _T(""),
+                                        _T(""),
+                                        crea::std2wx(wc),
+                                        style,
+                                        wxDefaultPosition);
+    
+    if (FD->ShowModal()==wxID_OK)
+       {
+               wxBusyCursor busy;
+               wxArrayString files;
+               FD->GetPaths(files);
+               for(int i = 0; i< files.size(); i++)
+               {
+               //      gimmick->addDB("remote_" + i.c_str(),files[i]);
+               //      AddTreeHandler(gimmick->getTreeHandlerMap("remote_" + i.c_str()));
+               }
+       }
+    
+               
   }
 
    //=================================================
@@ -646,6 +675,7 @@ namespace creaImageIO
     EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
     EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
        EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
+       EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
   END_EVENT_TABLE()
   //=================================================
 
index 302698fa701f382e55f30ac5ce556c86765bd792..7dd38c9c73feb3c4640f552f553477cbcc3c6ae1 100644 (file)
@@ -116,6 +116,9 @@ namespace creaImageIO
     void OnAddProgress( Gimmick::AddProgress& );
     /// Called upon to refresh the viewer once there are no actions to be done
     void OnInternalIdle();
+
+       // callback to add a database
+       void OnAddDB(wxCommandEvent& event);
     
     /// Progress dialog
     wxProgressDialog* mProgressDialog;