#include #include #include using namespace crea; // Icons #include "icons/accept.xpm" #include "icons/add.xpm" #include "icons/folder-down.xpm" #include "icons/page-down.xpm" #include "icons/remove.xpm" #include "icons/database-add.xpm" #include "icons/help.xpm" #include namespace creaImageIO { //====================================================================== // The ids of the different tools enum { TOOL_ADDFILES_ID = 1, TOOL_ADDDIR_ID = 2, TOOL_REMOVE_ID = 3, TOOL_ADDDATABASE_ID = 4, TOOL_HELP_ID = 5 }; //====================================================================== //================================================================ // const int icon_number = 7; // Icon ids typedef enum { Icon_accept, Icon_add, Icon_folder_down, Icon_page_down, Icon_remove, Icon_database_add, Icon_help } icon_id; //================================================================ //================================================================ /* const icon_id Icon[5] = { Icon_Database, Icon_Patient, Icon_Study, Icon_Series, Icon_Image }; */ //================================================================ //====================================================================== // CTor WxGimmickView::WxGimmickView(Gimmick* gimmick, wxWindow *parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, int min_dim, int max_dim, int number_of_threads) : wxPanel(parent,id,pos,size), GimmickView(gimmick, number_of_threads), mProgressDialog(0), mConstructed(false) { GimmickDebugMessage(1,"WxGimmickView::WxGimmickView" <GetHomeDirectory()); // Connect the AddProgress callback gimmick->ConnectAddProgressObserver ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) ); // Create the list of icons (mIcon) CreateIconList(); // Global sizer wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); // Create the tool bar CreateToolBar(); sizer->Add( mToolBar ,0, wxGROW ,0); // Split part below toolbar into notebook for views and panel // for preview, messages... mSplitter = new wxSplitterWindow( this , -1); // Notebook mNotebook = new wxNotebook(mSplitter, -1,wxDefaultPosition, wxDefaultSize, 0); //Gimmick mGimmick=gimmick; mSelectionMaxDimension= max_dim; mSelectionMinDimension= min_dim; // Create the views CreateTreeViews(); // Bottom panel mBottomPanel = new wxPanel(mSplitter,-1); wxBoxSizer *bottom_sizer = new wxBoxSizer(wxHORIZONTAL); mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Status: Welcome to Gimmick!")); bottom_sizer->Add(mText,1,wxGROW,0); // Previewer mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize ); mViewer->SetMovieSize(1); mViewer->SetImage(0,GetDefaultImage()); bottom_sizer->Add(mViewer,1,wxGROW,0); // mViewer->Show(); mBottomPanel->SetSizer(bottom_sizer); // Splitting int hsize = size.GetHeight(); int top_minsize = 450; int bottom_minsize = 50; mSplitter->SetMinimumPaneSize( bottom_minsize ); mSplitter->SplitHorizontally( mNotebook, mBottomPanel, top_minsize); sizer->Add( mSplitter,1,wxGROW ,0); SetSizer( sizer ); SetAutoLayout(true); Layout(); mConstructed = true; } //====================================================================== //====================================================================== /// Destructor WxGimmickView::~WxGimmickView() { GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView" <AddTool( TOOL_ADDFILES_ID, _T("Add file(s)"), mIcon->GetBitmap(Icon_page_down), _T("Add one or more file to database") ); mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID, _T("Add folder"), mIcon->GetBitmap(Icon_folder_down), _T("Add the content of a folder to database") ); mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID, _T("Remove"), mIcon->GetBitmap(Icon_remove), _T("Remove selected items") ); mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID, _T("Open database"), mIcon->GetBitmap(Icon_database_add), _T("Open a local or distant database") ); mToolHelp = mToolBar->AddTool( TOOL_HELP_ID, _T("Help"), mIcon->GetBitmap(Icon_help), _T("Open help window") ); //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL) mToolBar->Realize(); } //====================================================================== //====================================================================== /// Create the tree view for TreeHandler provided void WxGimmickView::CreateTreeView( TreeHandler* h) { std::string name(h->GetTree().GetAttribute("Name")); GimmickMessage(2,"Creating the tree view for '"<< name<<"'"<AddPage( view, crea::std2wx(name) ); } //====================================================================== /// Returns the selected Images so that they comply with the given parameter(4D) void WxGimmickView::GetSelectedImages(std::vector& s, int dim) { int level=GetTreeViewMap()["Local database"]->GetNumberOfLevels(); std::vector im=GetTreeViewMap()["Local database"]->GetSelected(level+1); ReadImagesNotThreaded(s,im,dim); } //====================================================================== /// Returns the selected Images so that they comply with the given parameter(4D) void WxGimmickView::GetSelectedFiles(std::vector& s) { GetTreeViewMap()["Local database"]->GetSelectedAsString(s); } //================================================= void WxGimmickView::CreateIconList() { // Size of the icons; int size = 24; wxIcon icons[20]; // should correspond to Icon_xxx enum icons[Icon_accept] = wxIcon(accept_xpm); icons[Icon_add] = wxIcon(add_xpm); icons[Icon_folder_down] = wxIcon(folder_down_xpm); icons[Icon_page_down] = wxIcon(page_down_xpm); icons[Icon_remove] = wxIcon(remove_xpm); icons[Icon_database_add] = wxIcon(database_add_xpm); icons[Icon_help] = wxIcon(help_xpm); // unsigned int NbIcons = 8; // Make an image list containing small icons mIcon = new wxImageList(size,size,true); // Make all icons the same size = size of the first one int sizeOrig = icons[0].GetWidth(); for ( size_t i = 0; i < icon_number; i++ ) { if ( size == sizeOrig ) { mIcon->Add(icons[i]); } else { mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size))); } } } //================================================= //================================================= void WxGimmickView::OnAddFiles(wxCommandEvent& event) { long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE; std::string wc("*.*"); 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); unsigned int i; std::vector filenames; for (i=0;iAddFiles("Local database",filenames); mProgressDialog->Pulse(_T("Updating view...")); UpdateTreeViewLevel("Local database",1); delete mProgressDialog; DisplayAddSummary(); } } //================================================= //================================================= void WxGimmickView::OnAddDir(wxCommandEvent& event) { long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST; wxDirDialog* FD = new wxDirDialog( 0, _T("Select directory"), mCurrentDirectory, style); if (FD->ShowModal()==wxID_OK) { bool recurse = false; if (wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES) { recurse = true; } 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(); } } //================================================= //================================================= void WxGimmickView::OnSelectionChange(std::vector& sel) { GimmickDebugMessage(5, "WxGimmickView::OnSelectionChange" <SetLabel(_T("Status: ")+crea::std2wx(GetMessage())); if(valid) { ReadImageThreaded(sel); } else { mViewer->SetMovieSize(1); mViewer->SetImage(0,GetDefaultImage()); // mViewer->Hide(); } } //================================================== //================================================== ///Reads Images (Threaded) void WxGimmickView::ReadImageThreaded(std::vector sel) { GimmickDebugMessage(5, "ReadImageThreaded" <SetMovieSize(sel.size());//ClearImages(); //First load the selected images mCurImageItemToShow = sel.front(); int index = 0; std::vector::iterator selected; for(selected=sel.begin();selected!=sel.end();++selected) { GimmickDebugMessage(5, "Requesting image from selected " <<(*selected)->GetAttribute("FullFileName") < up; GetTreeViewMap()["Local database"]->GetNodes(up,true); std::vector::iterator iterUp; for(iterUp=up.begin();iterUp!=up.end();++iterUp) { GimmickDebugMessage(5, "Requesting image from neighbors up " <<(*iterUp)->GetAttribute("FullFileName") < down; GetTreeViewMap()["Local database"]->GetNodes(down,false); std::vector::iterator iterDown; for(iterDown=down.begin();iterDown!=down.end();++iterDown) { GimmickDebugMessage(5, "Requesting image from neighbors down " <<(*iterDown)->GetAttribute("FullFileName") <GetNumberOfLevels(); // std::vector sel=GetTreeViewMap()["Local database"]->GetSelected(level+1); /* GimmickDebugMessage(5, "Processing Images. Lock Started" <=0) { mViewer->SetImage(index,image); } } UnqueueNext(); } ClearQueue(); MultiThreadImageReaderEventUnlock(); /* GimmickDebugMessage(5, "Processing Images. Lock Ended" <SetMovieSize(1); mViewer->SetImage(0,GetDefaultImage()); first_time = false; } // GimmickMessage(1,"WxGimmickView : Refresh viewer"<RefreshIfNecessary()) { // mViewer->Refresh(); // mViewer->SetFocus(); } } //================================================== //================================================== void WxGimmickView::ClearSelection() { mViewer->SetMovieSize(1); mViewer->SetImage(0,GetDefaultImage()); mViewer->RefreshIfNecessary(); } //================================================= //================================================= void WxGimmickView::OnRemove(wxCommandEvent& event) { //TODO Select current tree handler wxBusyCursor busy; GetTreeViewMap()["Local database"]->RemoveSelected(1); ClearSelection(); } //================================================= //================================================= /// AddProgress Gimmick callback void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p) { char mess[200]; sprintf(mess,"%i dirs - %i files - %i handled - %i added", p.GetNumberScannedDirs(), p.GetNumberScannedFiles(), p.GetNumberHandledFiles(), p.GetNumberAddedFiles()); // std::cout << "OnAddProgress "<Pulse(s)) { p.SetStop(); } // std::cout << "OnAddProgress ok"<GetAddProgress(); std::stringstream mess; mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n"; mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n"; mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n"; mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n"; /* char times[500]; sprintf(times,"Time to parse dir \t\t: %ld ms \t%d°/o\nTime to read files info \t: %ld ms \t%d°/o\nTime to update structs \t: %ld ms \t%d°/o\nTime to update database \t: %ld ms \t%d°/o\nTotal time \t\t\t: %ld ms", summary.parse_time, (int)( summary.parse_time*100./summary.total_time), summary.file_scan_time, (int)(summary.file_scan_time*100./summary.total_time), summary.update_structs_time, (int)(summary.update_structs_time*100./summary.total_time), summary.update_database_time, (int)(summary.update_database_time*100./summary.total_time), summary.total_time ); mess << times; */ wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this); } //================================================= //================================================= BEGIN_EVENT_TABLE(WxGimmickView, wxPanel) EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles) EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir) EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove) END_EVENT_TABLE() //================================================= } // EO namespace creaImageIO