]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOWxTreeView.cpp
Added attribute selection functionality.
[creaImageIO.git] / src2 / creaImageIOWxTreeView.cpp
index cf6f1eb70e93fedc1883c960ae68214183af1215..2fced885b158ecc2844ab93c8bb70ebe10625778 100644 (file)
@@ -226,7 +226,7 @@ namespace creaImageIO
        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 field"));
+       wxMenuItem* m3Item=menuItem->Append(wxID_ANY, _T("&Edit Fields"));
        
        mAnonymizingID=m1Item->GetId();
        mLocalCopyID=m2Item->GetId();
@@ -679,6 +679,9 @@ namespace creaImageIO
     
   }
 
+   //================================================================
+  //================================================================
+
   void WxTreeView::OnItemMenu(wxListEvent &event)
   {
         wxPoint clientpt;
@@ -691,9 +694,9 @@ namespace creaImageIO
                if ( GetCtrl(level) == senderCtrl ) break;
       }
          long* ptr=0;
-         int flag=wxLIST_HITTEST_ONITEM;
-         long itemId=GetCtrl(level)->HitTest(clientpt,flag,ptr);
-         std::cout<<itemId<<std::endl;
+         int flag;
+         mLastRightLevel=level;
+         mLastRightSelected=GetCtrl(level)->HitTest(wxPoint(0,clientpt.y-8),flag,ptr);
     PopupMenu(menuItem, clientpt);
     
   }
@@ -833,9 +836,24 @@ namespace creaImageIO
    //================================================================
   void WxTreeView::OnEditField(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->GetFlags()==creaImageIO::tree::AttributeDescriptor::EDITABLE)
+           {
+                       names.push_back(a->GetName());
+                       keys.push_back(a->GetKey());
+               }
+       }
+       GetGimmickView()->CreateEditFieldsDialog(node,names,keys);
+       }
   }
   //================================================================
 
@@ -1174,6 +1192,97 @@ namespace creaImageIO
 
 
   }
+
+   //================================================================
+  void WxTreeView::GetAttributes(std::vector<std::string>& areShown, std::vector<std::string>& notShown, int level)
+  {
+         areShown.clear();
+         notShown.clear();
+       tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
+       for (a  = GetTreeHandler()->GetTree().GetAttributeDescriptorList(level).begin();
+            a != GetTreeHandler()->GetTree().GetAttributeDescriptorList(level).end();
+            ++a)
+       {
+               if(a->GetFlags()==creaImageIO::tree::AttributeDescriptor::EDITABLE && IsAttributeVisible(a->GetName(),level))
+           {
+                       areShown.push_back(a->GetName());
+               }
+       }
+       notShown=mLevelList[level-1].notShownAtts;
+  }
+
+  //================================================================
+  void WxTreeView::SetNonVisibleAttributes(const std::vector<std::string>& notShown, int nlevel)
+  {
+       mLevelList[nlevel].notShownAtts=notShown;
+  }
+
+  //================================================================
+   void WxTreeView::CreateCtrl(std::vector<std::string>& notShown, int nlevel)
+  {
+       int ctrl_style = wxLC_REPORT | wxLC_VRULES;
+    int col_style = wxLIST_FORMAT_LEFT;
+       LevelType level;
+       mLevelList[nlevel].SelectedUpToDate = true;
+       mLevelList[nlevel].SortColumn = 0;
+       mLevelList[nlevel].key.clear();
+       
+       mLevelList[nlevel].wxCtrl = new wxListCtrl(mLevelList[nlevel].wxSplitter,
+                                         nlevel,
+                                         wxDefaultPosition, 
+                                         wxDefaultSize,
+                                         ctrl_style);
+       wxWindow* oldWin=mLevelList[nlevel].wxSplitter->GetWindow1();
+       mLevelList[nlevel].wxSplitter->ReplaceWindow(oldWin,mLevelList[nlevel].wxCtrl);
+       mLevelList[nlevel].wxSplitter->Initialize(mLevelList[nlevel].wxCtrl);
+   
+       // Create the columns : one for each attribute of the level
+       int col = 0;
+       std::string title;
+
+       tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
+       for (a  = GetTreeHandler()->GetTree().GetAttributeDescriptorList(nlevel+1).begin();
+            a != GetTreeHandler()->GetTree().GetAttributeDescriptorList(nlevel+1).end();
+            ++a)
+
+       {   
+           if(a->GetFlags()!=creaImageIO::tree::AttributeDescriptor::PRIVATE && IsAttributeVisible(a->GetName(),nlevel+1))
+             {
+                 title=a->GetName();
+                 std::string temp = a->GetKey();
+                 if (temp.compare("ID") != 0)
+                 {
+                       mLevelList[nlevel].wxCtrl->InsertColumn(col, 
+                                       crea::std2wx(title),
+                                       col_style);
+                       col++;
+                 }
+               mLevelList[nlevel].key.push_back(a->GetKey());
+             }
+               
+         }
+       oldWin->Destroy();
+       UpdateLevel(1);
+       }
+
+   //================================================================
+  bool WxTreeView::IsAttributeVisible(const std::string& val, int level)
+  {
+         std::vector<std::string> ns=mLevelList[level-1].notShownAtts;
+         std::vector<std::string>::iterator it;
+         bool found=false;
+         for(it=ns.begin();it!=ns.end()&&!found;++it)
+         {
+                 if(val.compare(*it)==0)
+                 {
+                         found=true;
+                 }
+         }
+
+         return !found;
+  }
+
+  //================================================================
   //================================================================
   BEGIN_EVENT_TABLE(WxTreeView, wxPanel)   
   /*