]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOWxTreeView.cpp
move directory
[creaImageIO.git] / src2 / creaImageIOWxTreeView.cpp
index 2fced885b158ecc2844ab93c8bb70ebe10625778..86850e4192e795c7691f69567ea2f7dab904860e 100644 (file)
@@ -4,27 +4,14 @@
 #include <wx/splitter.h>
 #include <wx/gdicmn.h>
 #include <boost/date_time/gregorian/gregorian.hpp>
-
-const std::string empty_string("");
-
+#include <creaImageIOGimmick.h>
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
 //=====================================================================
 namespace creaImageIO
 {
-  //=====================================================================
-  /// Data stored by the list items
-  struct ItemData
-  {
-    ItemData() : node(0), id(-1), attr(&empty_string) {}
-    // The corresponding Node
-    tree::Node* node;
-    // The id ?
-    int id;
-    // The pointer on the current attribute string to sort on
-    const std::string* attr;
-    // Was the item previously selected ?
-    // Useful for reselecting the item after sort
-    bool selected;
-  };
+
   //=====================================================================
 }
 //=====================================================================
@@ -122,7 +109,7 @@ namespace creaImageIO
     //    mSplitter = new wxSplitterWindow( this , -1);
 
     // Global sizer
-    wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
+    msizer = new wxBoxSizer(wxHORIZONTAL);
     
     int ctrl_style = wxLC_REPORT | wxLC_VRULES;
     int col_style = wxLIST_FORMAT_LEFT;
@@ -221,25 +208,35 @@ namespace creaImageIO
        Connect( mFilterID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnPopupFilter) );
 
 
+       ////SubMenuItem EXPORT
+       subExportMenu = new wxMenu;
+       wxMenuItem *subExp1 = subExportMenu->Append(wxID_ANY, _T("&Export to Storage"));
+       Connect( subExp1->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnExportToStorage) );
 
        //ItemMenu
        menuItem =new wxMenu;
        wxMenuItem* m1Item=menuItem->Append(wxID_ANY, _T("&Anonymize"));
        wxMenuItem* m2Item=menuItem->Append(wxID_ANY, _T("&Local Copy"));
        wxMenuItem* m3Item=menuItem->Append(wxID_ANY, _T("&Edit Fields"));
-       
+       wxMenuItem* m4Item=menuItem->Append(wxID_ANY, _T("&Display Dicom Tags"));
+       menuItem->AppendSubMenu(subExportMenu, wxT("&Export"));
+
        mAnonymizingID=m1Item->GetId();
        mLocalCopyID=m2Item->GetId();
        mEditFieldID=m3Item->GetId();
+       mDumpID=m4Item->GetId();
+       
        //Connect( mAnonymizingID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnAnonymize) );
        Connect( mLocalCopyID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnLocalCopy) );
        Connect( mEditFieldID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnEditField) );
+       Connect( mDumpID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnDumpTags) );
        
+
        
 #endif // wxUSE_MENUS
        /// Initialize the first level splitter
          
-       sizer->Add( mLevelList[0].wxSplitter ,1, wxGROW  ,0);
+       msizer->Add( mLevelList[0].wxSplitter ,1, wxGROW  ,0);
        //      mColumnSelected=1;
        mLastSelected=0;
        mLastLevel=0;
@@ -250,7 +247,7 @@ namespace creaImageIO
        //CreateColorPalette();
     UpdateLevel(1);
 
-    SetSizer( sizer );     
+    SetSizer( msizer );     
     SetAutoLayout(true);
     Layout();
 
@@ -263,6 +260,9 @@ namespace creaImageIO
   {
     GimmickDebugMessage(1,"WxTreeView::~WxTreeView"
                        <<std::endl);
+       delete menu;
+       delete menuItem;
+
   }
   //=====================================================================
   
@@ -271,11 +271,18 @@ namespace creaImageIO
   //=====================================================================
   const std::vector<tree::Node*>& WxTreeView::GetSelected(int level)
   {
+         std::vector<tree::Node*>& sel = mLevelList[0].Selected;
     //  if (GetSelectedUpToDate(level)) 
     int l = level - 1;
     // the selection of upper level
-       std::vector<tree::Node*>& sel(mLevelList[l].Selected);
-    sel.clear();
+       if(mLevelList.size() == level -1)
+                sel = mLevelList.back().Selected;
+       else
+                 sel=  mLevelList[l].Selected;
+       if (sel.size() > 0)
+       {
+               sel.clear();
+       }
          if (level == 1) 
       {
        sel.push_back(GetTreeHandler()->GetTree().GetTree());
@@ -341,15 +348,17 @@ namespace creaImageIO
   //=====================================================================
   ///Removes selected nodes on last selected level
    // NOT SPECIFIC 
-  void WxTreeView::RemoveSelected()
+  void WxTreeView::RemoveSelected(std::string &i_save)
   {
-         unsigned int tempLevel = mLastLevel;
+        bool erase=false;
+        
+        unsigned int tempLevel = mLastLevel;
     mLastLevel+=1;
     const std::vector<tree::Node*>& sel=GetSelected(mLastLevel+1);
        // if no selection, no remove action.
     if(sel.size() != 0)
        {
-           bool erase=false;
+       
            std::stringstream out;
            std::string levelName=GetTreeHandler()->GetTree().GetLevelDescriptor(mLastLevel).GetName();
            out<<"Delete ";
@@ -385,9 +394,9 @@ namespace creaImageIO
                          {
                            needRefresh=true;
                          }
-                         tree::Node* n= (tree::Node*)(*i);
+                         //tree::Node* n = new (tree::Node*)(*i);
                          GetTreeHandler()->LoadChildren((*i),4);
-                         GetGimmickView()->AddIgnoreFile(n);
+                         GetGimmickView()->AddIgnoreFile(*i);
                          GetTreeHandler()->Remove(*i);
                      }
                    
@@ -411,6 +420,17 @@ namespace creaImageIO
                mLastLevel = tempLevel;
        }
     
+       if (erase && mLastLevel == 1 && i_save == "0")
+       {
+       
+               RemoveAlertDlg *dial = new RemoveAlertDlg(this,  crea::std2wx("Remove files"), wxSize(370,100));
+               //dial->ShowModal();
+               if (dial->ShowModal() == wxID_OK)
+               {
+                       i_save = dial->isChecked() == false? "0" : "1";
+               }
+               
+       }
   }
   
   
@@ -492,13 +512,13 @@ namespace creaImageIO
                         wxLIST_MASK_FORMAT
                         );
            
-           ItemData* data = new ItemData;
+               ItemData* data = new ItemData();
            data->node = *j;
            data->id = _id;
-           
+               
            item.SetId(_id);
            item.SetData(data);
-           
+
            _id++;
            GetCtrl(l)->InsertItem(item);
            
@@ -539,13 +559,15 @@ namespace creaImageIO
                  }
                else
                  {
-                   
+                   if (val.size()==0) val = "?";
                  }
-               if (val.size()==0) val = "?";
+               if (val.size()==0) val = "X";
                item.SetText( crea::std2wx(val));
                item.SetColumn(k);
-               GetCtrl(l)->SetItem(item);
-             } 
+                 
+                 GetCtrl(l)->SetItem(item);
+                 }
+               item.Clear();
            
          }
       }
@@ -618,7 +640,8 @@ namespace creaImageIO
        GetGimmickView()->ClearSelection();
       }
     // Select all images if the selection is at series level
-    if (level==mLevelList.size()-2) SelectAll(level+1);
+    if (level==mLevelList.size()-2) 
+               SelectAll(level+1);
     // Validate selected images if the selection is at image level
     if (level==(mLevelList.size()-1)) //&&mProcess) 
       {
@@ -656,7 +679,7 @@ namespace creaImageIO
            mIgnoreSelectedChanged = true;//    mProcess=false;
          }
        GetCtrl(level)->SetItemState(item,wxLIST_STATE_SELECTED, wxLIST_MASK_STATE 
-                                    | wxLIST_MASK_TEXT |wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT);
+                                    | wxLIST_MASK_TEXT |wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT);
       }
   }
 
@@ -855,6 +878,46 @@ namespace creaImageIO
        GetGimmickView()->CreateEditFieldsDialog(node,names,keys);
        }
   }
+
+  //================================================================
+
+  //================================================================
+
+  void WxTreeView::OnExportToStorage(wxCommandEvent &event)
+  {
+       std::vector<std::string> filesname;
+       std::vector<tree::Node*> nodes;
+       nodes.push_back(((ItemData*)GetCtrl(mLastRightLevel)->GetItemData(mLastRightSelected))->node);
+       GetFilenamesAsString(nodes,filesname);
+       GetGimmickView()->ExportToStorage(filesname);
+  }
+
+  //================================================================
+
+  //================================================================
+
+  void WxTreeView::OnDumpTags(wxCommandEvent &event)
+  {
+         if(mLastRightSelected!=-1)
+       {
+               tree::Node* node=((ItemData*)GetCtrl(mLastRightLevel)->GetItemData(mLastRightSelected))->node;
+               tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
+               std::vector<std::string> names;
+               std::vector<std::string> keys;
+               for (a  = GetTreeHandler()->GetTree().GetAttributeDescriptorList(mLastRightLevel+1).begin();
+                        a != GetTreeHandler()->GetTree().GetAttributeDescriptorList(mLastRightLevel+1).end();
+                        ++a)
+                       {
+                               if(a->GetKey()=="FullFileName")
+                               {
+                                       GetGimmickView()->DumpTags(node->GetAttribute("FullFileName"));
+                                       return;
+                               }
+                       }
+         }
+  }
+  
+
   //================================================================
 
   //================================================================
@@ -1040,8 +1103,8 @@ namespace creaImageIO
          if(event.GetKeyCode() == WXK_DELETE)
          {
                   wxBusyCursor busy;
-                 
-                  RemoveSelected();
+                  std::string temp = "0";
+                  RemoveSelected(temp);
                   GetGimmickView()->ClearSelection();
          }
                  
@@ -1084,114 +1147,6 @@ namespace creaImageIO
   }
 
    //================================================================
-  void WxTreeView::SetColor(int l, int item)
-  {
-         int colorId=12;
-         GetCtrl(l)->SetItemTextColour(item, wxColourDatabase().Find
-                  (crea::std2wx(mColorPalette[colorId])));
-         GetCtrl(l)->SetItemState(item,wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED);  /*
-         int colorId=0;
-         //Setting the color according to the parent
-               if(l==0)
-               {
-               item.SetBackgroundColour
-                 (wxColourDatabase().Find
-                  (crea::std2wx(mColorPalette[colorId]))); 
-               mColorMap.insert
-                 (NodeColorPair
-                  (*j,wxColourDatabase().Find
-                   (crea::std2wx(mColorPalette[colorId]))));
-               if(colorId<64)
-                 {
-                   colorId++;
-                 }
-               else
-                       {
-                         colorId=0;
-                       }
-               }
-               else if(l!=mLevelList.size()-1)
-                 {
-                   item.SetBackgroundColour(mColorMap[*i]); 
-                       mColorMap.insert(NodeColorPair(*j,mColorMap[*i]));
-               }
-               else
-               {
-                       item.SetBackgroundColour(mColorMap[*i]); 
-               }*/
-  }
-  //================================================================
-  void WxTreeView::CreateColorPalette()
-  {
-  GimmickDebugMessage(6,"WxTreeView::CreateColorPalette");
-  mColorPalette.push_back("WHITE");
-  mColorPalette.push_back("LIGHT GREY");
-  mColorPalette.push_back("AQUAMARINE");
-  mColorPalette.push_back("MEDIUM FOREST GREEN");
-  mColorPalette.push_back("INDIAN RED");
-  mColorPalette.push_back("KHAKI");
-  mColorPalette.push_back("ORANGE");
-  mColorPalette.push_back("LIGHT BLUE");
-  mColorPalette.push_back("LIGHT STEEL BLUE");
-  mColorPalette.push_back("PINK");
-  mColorPalette.push_back("PLUM");
-  mColorPalette.push_back("PURPLE");
-  mColorPalette.push_back("RED");
-  mColorPalette.push_back("SEA GREEN");
-  mColorPalette.push_back("SIENNA");
-  mColorPalette.push_back("SKY BLUE");
-  mColorPalette.push_back("SLATE BLUE");
-  mColorPalette.push_back("SPRING GREEN");
-  mColorPalette.push_back("TAN");
-  mColorPalette.push_back("THISTLE");
-  mColorPalette.push_back("TURQUOISE");
-  mColorPalette.push_back("VIOLET");
-  mColorPalette.push_back("VIOLET RED");
-  mColorPalette.push_back("WHEAT");
-  mColorPalette.push_back("YELLOW");
-  mColorPalette.push_back("YELLOW GREEN");
-  mColorPalette.push_back("BLUE");
-  mColorPalette.push_back("BLUE VIOLET");
-  mColorPalette.push_back("BROWN");
-  mColorPalette.push_back("CADET BLUE");
-  mColorPalette.push_back("CORAL");
-  mColorPalette.push_back("CORNFLOWER BLUE");
-  mColorPalette.push_back("CYAN");
-  mColorPalette.push_back("DARK GREY");
-  mColorPalette.push_back("DARK GREEN");
-  mColorPalette.push_back("DARK OLIVE GREEN");
-  mColorPalette.push_back("DARK ORCHID");
-  mColorPalette.push_back("DARK SLATE BLUE");
-  mColorPalette.push_back("DARK SLATE GREY");
-  mColorPalette.push_back("DARK TURQUOISE");
-  mColorPalette.push_back("FIREBRICK");
-  mColorPalette.push_back("FOREST GREEN");
-  mColorPalette.push_back("GOLD");
-  mColorPalette.push_back("GOLDENROD");
-  mColorPalette.push_back("GREY");
-  mColorPalette.push_back("GREEN");
-  mColorPalette.push_back("GREEN YELLOW");
-  mColorPalette.push_back("LIME GREEN");
-  mColorPalette.push_back("MAGENTA");
-  mColorPalette.push_back("MAROON");
-  mColorPalette.push_back("MEDIUM AQUAMARINE");
-  mColorPalette.push_back("MEDIUM BLUE");
-  mColorPalette.push_back("MEDIUM GOLDENROD");
-  mColorPalette.push_back("MEDIUM ORCHID");
-  mColorPalette.push_back("MEDIUM SEA GREEN");
-  mColorPalette.push_back("MEDIUM SLATE BLUE");
-  mColorPalette.push_back("MEDIUM SPRING GREEN");
-  mColorPalette.push_back("MEDIUM TURQUOISE");
-  mColorPalette.push_back("MEDIUM VIOLET RED");
-  mColorPalette.push_back("MIDNIGHT BLUE");
-  mColorPalette.push_back("NAVY");
-  mColorPalette.push_back("ORANGE RED");
-  mColorPalette.push_back("ORCHID, PALE GREEN");
-  mColorPalette.push_back("STEEL BLUE");
-  mColorPalette.push_back("BLACK");
-
-
-  }
 
    //================================================================
   void WxTreeView::GetAttributes(std::vector<std::string>& areShown, std::vector<std::string>& notShown, int level)
@@ -1281,6 +1236,47 @@ namespace creaImageIO
 
          return !found;
   }
+ //================================================================
+  //================================================================
+
+       RemoveAlertDlg::RemoveAlertDlg(wxWindow *parent, 
+                                              wxString title,    
+                                                  const wxSize& size)
+ :   wxDialog( parent, 
+                 wxID_ANY, 
+                 title,
+                 wxDefaultPosition,
+                 size,
+                 wxDEFAULT_DIALOG_STYLE)
+       {
+           wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
+
+               //std::string out("To reload deleted patient, you should synchronize your database before.");  // JPR
+               //wxTextCtrl *text = new wxTextCtrl(this, wxID_ANY,crea::std2wx(out),wxDefaultPosition, wxSize(500,20));
+               wxTextCtrl *text = new wxTextCtrl(this, wxID_ANY,
+                                       _T("To reload deleted patient, you should synchronize your database before."),
+                                       wxDefaultPosition, wxSize(500,20));
+               mcheck = new wxCheckBox(this, 5478, _T("Do not display this warning again!"));
+               Connect( mcheck->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &RemoveAlertDlg::onCheck ); 
+               wxSizer* buttonsSizer = this->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
+               
+               topsizer->Add(text);
+               topsizer->Add(mcheck,0,wxGROW);
+               topsizer->Add(buttonsSizer,0,wxGROW);
+               SetSizer(topsizer, true);
+               mSave = false;
+               Layout();
+       }
+       RemoveAlertDlg::~RemoveAlertDlg(){};
+       bool RemoveAlertDlg::isChecked()
+       {
+               return mSave;
+       }
+       void RemoveAlertDlg::onCheck(wxCommandEvent &Event)
+       {
+               mSave = mcheck->IsChecked();
+       }
+       
 
   //================================================================
   //================================================================