43 #pragma warning(disable: 4996)
48 #include "icons/accept.xpm"
49 #include "icons/add.xpm"
50 #include "icons/folder-down.xpm"
51 #include "icons/page-down.xpm"
52 #include "icons/remove.xpm"
53 #include "icons/database-add.xpm"
54 #include "icons/create-database.xpm"
55 #include "icons/help.xpm"
56 #include "icons/synchronize.xpm"
57 #include "icons/settings.xpm"
58 #include "icons/tools.xpm"
61 #include <wx/imaglist.h>
62 #include <wx/popupwin.h>
63 #include<boost/filesystem/operations.hpp>
64 #if defined(BUILD_BRUKER)
65 #include "bruker2dicom.h"
128 WxGimmickView::WxGimmickView(boost::shared_ptr<Gimmick> gimmick,
135 int number_of_threads)
136 : wxPanel(parent,id,pos,size),
148 gimmick->ConnectAddProgressObserver
155 msizer =
new wxBoxSizer(wxVERTICAL);
163 mSplitter =
new wxSplitterWindow(
this , -1);
167 -1, wxDefaultPosition, wxDefaultSize, 0);
205 int hsize = size.GetHeight();
207 int top_minsize = 450;
208 int bottom_minsize = 50;
210 mSplitter->SetMinimumPaneSize( bottom_minsize );
248 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
249 mToolBar =
new wxToolBar(
this,-1,wxDefaultPosition,wxDefaultSize,
255 _T(
"Add one or more file to database")
260 _T(
"Add the content of a folder to database")
265 _T(
"Open a local or distant database")
270 _T(
"Remove selected items")
275 _T(
"Synchronizes the database with disk")
280 _T(
"Open help window")
283 _T(
"System settings"),
285 _T(
"Allows the modification of various system settings")
290 _T(
"Applies tools to images")
293 _T(
"Create database"),
295 _T(
"Create DB from an Attributes Descriptor file")
297 #if defined(BUILD_PACS)
299 _T(
"PACS Connection,"),
301 _T(
"Echo, Find and Get to a PACS")
317 name<<
"'"<<std::endl);
326 mNotebook->AddPage( view, crea::std2wx(name) );
333 std::vector<std::string> files;
338 std::string db_name = crea::wx2std(
mNotebook->GetPageText(
mNotebook->GetSelection()));
347 std::vector<std::string> files;
348 std::string db_name = crea::wx2std(
mNotebook->GetPageText(
mNotebook->GetSelection()));
358 bool mult,
const std::string out_model)
361 std::vector<std::string> files;
362 std::string db_name = crea::wx2std(
mNotebook->GetPageText(
mNotebook->GetSelection()));
367 bool bsingle =
isSingle(files.front());
372 if (asking ==
"true")
377 sscanf(dim.c_str(),
"%d",&idim);
379 if (dlg->ShowModal() == wxID_OK)
393 sscanf(dim.c_str(),
"%d",&i_dim_out);
403 else if( i_attr.size() == 1 && i_attr.front() ==
"ALL")
406 Oattr.inside.push_back(
"ALL");
408 else if( (i_attr.size() == 1 && i_attr.front() !=
"ALL")
409 || (i_attr.size() >1) )
411 mGimmick->fillVectInfos(i_attr, Oattr);
419 std::vector<std::string> sort_files(files);
421 if( !out_model.empty() )
428 if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) )
435 readImages(outG, sort_files, Oattr, i_dim_out, zspacing);
455 const std::vector<std::string>& files,
456 std::vector<vtkImageData*>& s)
485 mIcon =
new wxImageList(size,size,
true);
488 int sizeOrig = icons[0].GetWidth();
491 if ( size == sizeOrig )
493 mIcon->Add(icons[i]);
497 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
508 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
510 wxFileDialog* FD =
new wxFileDialog( 0,
518 if (FD->ShowModal()==wxID_OK)
525 std::vector<std::string> filenames;
526 for (i=0;i<files.GetCount();++i)
528 filenames.push_back(wx2std(files[i]));
533 new wxProgressDialog(_T(
"Adding file(s)"),
561 std::string name = crea::wx2std(
mNotebook->GetCurrentPage()->GetName());
562 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
565 _T(
"Select directory"),
569 if (FD->ShowModal()==wxID_OK)
572 std::string dirname = wx2std (FD->GetPath());
576 recurse = wxMessageBox(_T(
"Recurse into sub-directories ?"), _T(
"Scan directory"), wxYES_NO,
this ) == wxYES ?
true :
false;
580 wxString title(_T(
"Adding directory"));
582 title = _T(
"Adding directory (recursive)");
584 new wxProgressDialog(_T(
"Adding directory"),
615 if ( !boost::filesystem::exists( dirpath ) )
return nb;
616 boost::filesystem::directory_iterator end_itr;
617 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
620 if ( boost::filesystem::is_directory(itr->status()) )
639 boost::filesystem::directory_iterator iter(i_name), end_iter;
641 for(; iter != end_iter; ++iter)
643 if(boost::filesystem::is_directory(*iter))
656 "WxGimmickView::OnSelectionChange"
670 std::vector<tree::Node*>::const_iterator i;
671 for(i=sel.begin();i!=sel.end()&&
valid;++i)
687 std::vector<tree::Node*>::const_iterator i;
688 for(i=sel.begin();i!=sel.end()&&
valid;++i)
717 int prio = maxprio + 2000;
725 std::vector<tree::Node*>::const_iterator selected;
726 for(selected=sel.begin();selected!=sel.end();++selected)
729 "Requesting image from selected "
730 <<(*selected)->GetAttribute(
"FullFileName")
743 std::vector<tree::Node*> up;
745 std::vector<tree::Node*>::iterator iterUp;
746 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
749 "Requesting image from neighbors up "
750 <<(*iterUp)->GetAttribute(
"FullFileName")
757 if (prio == maxprio)
break;
762 std::vector<tree::Node*> down;
764 std::vector<tree::Node*>::iterator iterDown;
765 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
768 "Requesting image from neighbors down "
769 <<(*iterDown)->GetAttribute(
"FullFileName")
776 if (prio == maxprio)
break;
795 void WxGimmickView::OnInternalIdle()
798 static bool first_time =
true;
859 wxMessageBox(std2wx(
"The selected files have been copied"),_T(
"Copy files"),wxOK,
this);
865 mProgressDialog =
new wxProgressDialog(_T(
"Adding directory"),_T(
""),1000,
870 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
884 const wxString choices[] = { _T(
"Check database for files deletion and addition and give a report."),
885 _T(
"Check database for files deletion, addition and attributes change. Then give a report."),
886 _T(
"Repair database (remove deleted files and add new files)."),
887 _T(
"Repair database (remove deleted files, add new files and reset changed attributes).") } ;
889 wxSingleChoiceDialog dialog(
this,
890 _T(
"Select one of the following synchronization actions:\n")
891 _T(
"Please note that, due to the heavy amount of operations required, this action might take a while."),
892 _T(
"Synchronization Settings"),
893 WXSIZEOF(choices), choices);
897 if (dialog.ShowModal() == wxID_OK)
900 int sel=dialog.GetSelection();
902 bool checkAttributes=
false;
903 if(sel==2 || sel==3){repair=
true;}
904 if(sel==1 || sel==3){checkAttributes=
true;}
905 std::string mess=
mGimmick->Synchronize(crea::wx2std(
mNotebook->GetPageText(
mNotebook->GetSelection())),repair, checkAttributes);
906 wxMessageBox(std2wx(mess),_T(
"Synchronization result"),wxOK,
this);
907 if(sel==2 || sel==3){
918 wxDialog* dial=
new wxDialog (
this,-1,_T(
"System Settings"),wxDefaultPosition, wxSize(450,220));
919 wxBoxSizer *siz =
new wxBoxSizer(wxVERTICAL);
921 wxNotebook* nb=
new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
923 siz->Add( nb,1,wxGROW ,0);
969 wxDialog* dial =
new wxDialog (
this,-1,_T(
"Tools"),wxDefaultPosition, wxSize(550,350));
971 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
972 wxNotebook* nb=
new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
973 wxBoxSizer *dialSizer =
new wxBoxSizer(wxVERTICAL);
974 dialSizer->Add(nb,1,wxGROW,0);
975 dialSizer->Add(buttonsSizer,0,wxGROW);
977 #if defined(BUILD_BRUKER)
980 nb->AddPage( gimmickTools, _T(
"Bruker Image Reader") );
983 dial->SetSizer(dialSizer,
true);
987 if (dial->GetReturnCode() == wxID_OK)
989 #if defined(BUILD_BRUKER)
990 if (nb->GetSelection()==0)
992 std::string inputDir = crea::wx2std(gimmickTools->
getInputDir());
993 std::string outputDir = crea::wx2std(gimmickTools->
getOutputDir());
997 if (inputDir.compare(
"")!=0 && outputDir.compare(
"")!=0)
999 if ( wxMessageBox(_T(
"Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
1000 _T(
"Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
1003 b2d.SetInputDirectory(inputDir);
1004 b2d.SetOutputDirectory(outputDir);
1005 b2d.SetConvertModeToDicom();
1010 std::cout <<
"after addToDB" << std::endl;
1011 mProgressDialog =
new wxProgressDialog(_T(
"Adding directory"),_T(
""),1000,
1016 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
1017 std::cout <<
"after new wxProgressDialog" << std::endl;
1019 std::cout <<
"after gimmickTools->getOutputDir[" <<
mCurrentDirectory << std::endl;
1021 std::cout <<
"after mGimmick->AddDir" << std::endl;
1023 std::cout <<
"after mProgressDialog->Pulse" << std::endl;
1025 std::cout <<
"after UpdateTreeViewLevel" << std::endl;
1027 std::cout <<
"after delete mProgressDialog" << std::endl;
1029 std::cout <<
"after dDisplayAddSummary" << std::endl;
1035 wxMessageBox(_T(
"One or both of the directory fields are empty"),_T(
"Empty Fields"),wxOK,
this);
1038 delete gimmickTools;
1064 nb->AddPage( customConfig, crea::std2wx(
"Customize Configuration") );
1072 nb->AddPage( pacs, crea::std2wx(
"Connect to PACS") );
1076 nb->AddPage( cdWatch, crea::std2wx(
"CD/DVD") );
1079 std::vector<std::string> shown;
1080 std::vector<std::string> nShown;
1084 nb->AddPage( attSelection, crea::std2wx(
"Selection of Attributes") );
1089 std::vector<std::string>& nShown,
int level)
1098 std::vector<std::string> n=nShown;
1103 const std::string& dbPath,
1104 const std::string& syncEvent,
1105 const std::string& syncFreq)
1133 wxString title(_T(
"Adding drive"));
1135 new wxProgressDialog(_T(
"Adding drive"),
1179 wxDialog* dial=
new wxDialog (
this,-1,crea::std2wx(
"Edit Fields for node "+node->
GetLabel()),wxDefaultPosition, wxSize(350,155));
1180 wxBoxSizer *siz =
new wxBoxSizer(wxVERTICAL);
1183 siz->Add( ef,1,wxGROW ,0);
1184 dial->SetSizer(siz);
1200 std::vector<std::string> storages;
1201 Gimmick::TreeHandlerMapType::iterator it =
mGimmick->GetTreeHandlerMap().begin();
1202 for(;it !=
mGimmick->GetTreeHandlerMap().end(); it++)
1204 storages.push_back(it->first);
1212 new wxProgressDialog(_T(
"Adding file(s)"),
1223 mGimmick->AddFiles(storage,i_filenames);
1245 sprintf(mess,
"%i dirs : %i files :\n %i handled - %i added",
1251 wxString s(wxString::From8BitData(mess));
1268 std::stringstream mess(
mGimmick->getSummary());
1271 mess <<
"time to scan :" << difftime(end,
mstart) <<
"sec";
1272 wxMessageBox(std2wx(mess.str()),_T(
"Addition result"),wxOK,
this);
1283 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1284 std::string wc(
"*.sqlite3*");
1285 wxFileDialog* FD =
new wxFileDialog( 0,
1293 if (FD->ShowModal()==wxID_OK)
1296 wxArrayString files;
1297 FD->GetPaths(files);
1298 std::stringstream st;
1299 for(
int i = 0; i< files.size(); i++)
1302 size_t pos = files[i].find_last_of(_T(
"\\"));
1303 std::string name = crea::wx2std(files[i].substr(pos+1));
1304 pos = name.find_last_of(
".");
1305 name = name.substr(0,pos);
1307 mGimmick->addDB(name, crea::wx2std(files[i]));
1322 DescriptorPan->Layout();
1329 size_t pos = file.find_last_of(
"\\");
1330 std::string name = file.substr(pos+1);
1331 std::string directory = file.substr(0,pos);
1332 pos = name.find_last_of(
".");
1333 name = name.substr(0,pos);
1335 directory +=
"\\" + name +
".sqlite3";
1337 mGimmick->createDB(name, file,directory);