//==============================================================
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
}
}
- //================================================================
+
+ ///////////////////////////////////////////////////////////////////////
+ // 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;
}
//==============================================================
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()));
+ }
+ }
+
+
}
//=================================================
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()
//=================================================