X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src2%2FcreaImageIOWxTreeView.cpp;h=18ced63630fae13fc05b87a03b46e45ed8587939;hb=cac026929f2431aa4a966bf9ae3c8ff263f5dd63;hp=8f0e1f5ad000f8cfde982fab15c68c1a1aee2b65;hpb=60257912f98339ad44b500d6d4b700cca8e8daa9;p=creaImageIO.git diff --git a/src2/creaImageIOWxTreeView.cpp b/src2/creaImageIOWxTreeView.cpp index 8f0e1f5..18ced63 100644 --- a/src2/creaImageIOWxTreeView.cpp +++ b/src2/creaImageIOWxTreeView.cpp @@ -82,7 +82,7 @@ namespace creaImageIO // Global sizer wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL); - int ctrl_style = wxLC_REPORT | /*wxLC_VRULES |*/ wxLC_EDIT_LABELS; + int ctrl_style = wxLC_REPORT | wxLC_VRULES; int col_style = wxLIST_FORMAT_LEFT; // Creating the ListCtrl for the levels > 0 (not for Root level) @@ -111,23 +111,27 @@ namespace creaImageIO level.wxCtrl = ctrl; level.wxSplitter->Initialize(ctrl); + // Create the first column : number of children + if(iGetTree().GetNumberOfLevels()-1) + { + std::string title = "#"; + if (iGetTree().GetNumberOfLevels()-1) + { + title += handler->GetTree().GetLevelDescriptor(i+1).GetName(); + if (title[title.size()-1]!='s') + title += "s"; + } + ctrl->InsertColumn(0,crea::std2wx(title),col_style); + } + // Create the columns : one for each attribute of the level - int col = 0; + int col = 1; tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a; for (a = handler->GetTree().GetAttributeDescriptorList(i).begin(); a != handler->GetTree().GetAttributeDescriptorList(i).end(); ++a) { - if(col==0) - { - wxListItem it; - it.SetTextColour(*wxRED); - it.SetText(_T("#C")); - - ctrl->InsertColumn(col,it); - col++; - } - + GimmickDebugMessage(5,"Creating column "<GetName() <Append(wxID_ANY, _T("&Sort ascending")); + wxMenuItem* m2=menu->Append(wxID_ANY, _T("&Sort descending")); + wxMenuItem* m3=menu->Append(wxID_ANY, _T("&Filter")); + mAscendingID=m1->GetId(); + mDescendingID=m2->GetId(); + mFilterID=m3->GetId(); + Connect( mAscendingID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnPopupSort) ); + Connect( mDescendingID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnPopupSort) ); + Connect( mFilterID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnPopupFilter) ); + +#endif // wxUSE_MENUS + /// Initialize the first level splitter @@ -152,7 +171,8 @@ namespace creaImageIO mLastSelected=0; mDirection=true; mSelectionMade=false; - CreateColorPalette(); + mProcess=true; + //CreateColorPalette(); UpdateLevel(1); SetSizer( sizer ); @@ -292,99 +312,91 @@ namespace creaImageIO GetCtrl(l)->DeleteAllItems(); std::vector::iterator i; - //Adds the first item (filter) - GetCtrl(l)->InsertItem(0, "Filter:"); - for (i=sel.begin(); i!=sel.end(); ++i) + + //Adds the first item (filter) + + for (i=sel.begin(); i!=sel.end(); ++i) { GimmickDebugMessage(2, "adding children of '" <<(*i)->GetLabel() - <<"'"<InsertItem(0, _T("")); GetTreeHandler()->LoadChildren(*i,1); tree::Node::ChildrenListType::reverse_iterator j; for (j = (*i)->GetChildrenList().rbegin(); j!= (*i)->GetChildrenList().rend(); ++j) { - wxListItem item; - item.SetMask(wxLIST_MASK_STATE | + wxListItem* item= new wxListItem; + item->SetMask(wxLIST_MASK_STATE | wxLIST_MASK_TEXT | // wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | // wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT ); - + ItemData* data = new ItemData; data->node = *j; - item.SetId(_id); + item->SetId(_id); data->id = _id; - item.SetData(data); + item->SetData(data); _id++; - long id=GetCtrl(l)->InsertItem(item); + //Setting first column (number of children) std::ostringstream oss; - int n= GetTreeHandler()->GetNumberOfChildren(*j); + int n= 0; //GetTreeHandler()->GetNumberOfChildren(*j); oss << n; std::string s(oss.str()); - item.SetText( crea::std2wx(s)); - - //Setting the color according to the parent - if(l==0) - { - item.SetBackgroundColour(wxColourDatabase().Find(mColorPalette[colorId])); - mColorMap.insert(NodeColorPair(*j,wxColourDatabase().Find(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]); - } - + item->SetText( crea::std2wx(s)); - item.SetColumn(0); - GetCtrl(l)->SetItem(item); + item->SetColumn(0); + GetCtrl(l)->InsertItem(*item); + //GetCtrl(l)->SetItem(item); //Setting other attributes - for (int k=1; kGetColumnCount(); k++) + if(levelGetColumnCount(); k++) { - - std::string val = (*j)->GetAttribute(mLevelList[l].key[k-1]); - if (val.size()==0) val = "?"; - item.SetText( crea::std2wx(val)); - item.SetColumn(k); - GetCtrl(l)->SetItem(item); - } + std::string val = (*j)->GetAttribute(mLevelList[l].key[k-1]); + if (val.size()==0) val = "?"; + item->SetText( crea::std2wx(val)); + item->SetColumn(k); + GetCtrl(l)->SetItem(*item); + // Unefficient + // GetCtrl(l)->RefreshItem(*item); + } + } + else + { + for (int k=0; kGetColumnCount(); k++) + { + std::string val = (*j)->GetAttribute(mLevelList[l].key[k]); + if (val.size()==0) val = "?"; + item->SetText( crea::std2wx(val)); + item->SetColumn(k); + GetCtrl(l)->SetItem(*item); + // GetCtrl(l)->RefreshItem(*item); + } + } + } + GetCtrl(l)->DeleteItem(0); } GetCtrl(l)->Show(); - - if (levelGetTree().GetLabel() <<" view : item selected " <ClearSelection(); - } - if (level==mLevelList.size()-2) SelectLowerLevel(); - if (level==mLevelList.size()-1) ValidateSelectedImages (); - } + /* + if(event.m_itemIndex!=0) + {*/ + + if(levelClearSelection(); + } + // Select all images if the selection is at series level + if (level==mLevelList.size()-2) SelectLowerLevel(); + // Validate selected images if the selection is at image level + if (level==(mLevelList.size()-1)&&mProcess) + { + if(event.GetEventType()==10145) + { + ValidateSelectedImages (true); + } else - { - if(event.GetEventType()==10145) - { - - GetCtrl(level)->SetItemText(0,crea::std2wx("")); - GetCtrl(level)->EditLabel(event.m_itemIndex); - } - - } - + { + ValidateSelectedImages (false); + } + } + //SetColor(level,event.m_itemIndex); + /*} + else + { + if(event.GetEventType()==10145) + { + + GetCtrl(level)->SetItemText(0,crea::std2wx("")); + GetCtrl(level)->EditLabel(event.m_itemIndex); + } + + }*/ + + } //================================================================ @@ -450,46 +483,169 @@ namespace creaImageIO { long item = -1; int level=mLevelList.size()-1; + for ( ;; ) { item = GetCtrl(level)->GetNextItem(item, wxLIST_NEXT_ALL); if ( item == -1 ) break; - if(item!=0) + + if(item==(GetCtrl(level)->GetItemCount()-1)) + { + mProcess=true; + } + else { + mProcess=false; + } + + /*if(item!=0) + {*/ 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); - } + //} + } } + + //================================================================ //================================================================ + void WxTreeView::OnMouseClick(wxMouseEvent& event) + { + if (event.ButtonDown()) + { + } + std::cout<<"HELLO WORLD"<GetScreenPosition().x; + clientpt.y = wxGetMousePosition().y - this->GetScreenPosition().y; + senderCtrl = event.GetEventObject(); + unsigned int level = 0; + for (level = 0; levelGetColumnWidth(i); + } + for(int i=0;iGetSashPosition(); + } + clientpt.y+=level*2; */ + if(level==mLevelList.size()-1) + { + mColumnSelected+=1; + PopupMenu(menu, clientpt); + } + else if(mColumnSelected!=0) + { + PopupMenu(menu, clientpt); + } + + } + //================================================================ + void WxTreeView::OnPopupFilter(wxCommandEvent& event) + { + wxBusyCursor busy; + GimmickDebugMessage(7, + "WxTreeView::OnEndLabelEdit" + < items; + bool in=false; + int del=0; + for ( ;; ) + { + it = GetCtrl(level)->GetNextItem(it, + wxLIST_NEXT_ALL); + if ( it == -1 ) + break; + + long adr = GetCtrl(level)->GetItemData(it); + tree::Node* nod = ((ItemData*)adr)->node; + att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected-1]); + + + if(att.find(filter)>900) + { + + if(!in) + { + in=true; + } + else + { + del+=1; + } + + items.push_back(it-del); + } + + } + std::vector::iterator iter; + for(iter=items.begin();iter!=items.end();++iter) + { + GetCtrl(level)->DeleteItem(*iter); + } + GetGimmickView()->ClearSelection(); + } + //================================================================ + + //================================================================ + void WxTreeView::OnPopupSort(wxCommandEvent& event) + { wxBusyCursor busy; - + unsigned int level = 0; + for (level = 0; levelDeleteItem(0); + //GetCtrl(level)->DeleteItem(0); //Sets the data for the items to be sorted std::string att; unsigned int ty=0; @@ -499,6 +655,7 @@ namespace creaImageIO //Gets current item data long adr = GetCtrl(level)->GetItemData(i); + //Extracts the node and the type of attribute tree::Node* nod = ((ItemData*)adr)->node; if(i==0) @@ -531,7 +688,6 @@ namespace creaImageIO GetCtrl(level)->SortItems(CompareFunctionStrings, 0); } - mDirection=false; } else { @@ -543,7 +699,6 @@ namespace creaImageIO { GetCtrl(level)->SortItems(CompareFunctionStrings, 1); } - mDirection=true; } //Resets original data @@ -592,80 +747,19 @@ namespace creaImageIO | wxLIST_MASK_TEXT |wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT); } - GetCtrl(level)->InsertItem(0,"Filter:"); + //GetCtrl(level)->InsertItem(0,_T("Filter:")); } } + //================================================================ - void WxTreeView::OnBeginLabelEdit(wxListEvent& event) - { - GimmickDebugMessage(7, - "WxTreeView::OnBeginLabelEdit" - <GetNextItem(it, - wxLIST_NEXT_ALL); - if ( it == -1 ) - break; - if(it!=0) - { - long adr = GetCtrl(level)->GetItemData(it); - for (int j=1;jGetColumnCount()-1&&!contains;j++) - { - tree::Node* nod = ((ItemData*)adr)->node; - att=(*nod).GetAttribute(mLevelList[level].key[j-1]); - - if(att.find(filter)<900) - { - contains=true; - } - } - if(!contains) - { - GetCtrl(level)->DeleteItem(it); - } - } - } - GetGimmickView()->ClearSelection(); - //GetCtrl(level)->DeleteAllItems(); - - } - //================================================================ - void WxTreeView::ValidateSelectedImages() + void WxTreeView::ValidateSelectedImages(bool isSelection) { GimmickDebugMessage(7, "WxTreeView::ValidateSelectedImages" < sel(GetSelected(mLevelList.size()+1)); - GetGimmickView()->OnSelectionChange(sel); + GetGimmickView()->OnSelectionChange(sel,isSelection,(mLastSelected-1), mProcess); } //================================================================ @@ -720,6 +814,43 @@ 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() { @@ -793,7 +924,7 @@ namespace creaImageIO } //================================================================ - BEGIN_EVENT_TABLE(WxTreeView, wxPanel) + BEGIN_EVENT_TABLE(WxTreeView, wxPanel) /* EVT_SIZE(MyFrame::OnSize) @@ -834,10 +965,10 @@ END_EVENT_TABLE() BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag) EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag) - */ + EVT_LIST_BEGIN_LABEL_EDIT(-1, WxTreeView::OnBeginLabelEdit) EVT_LIST_END_LABEL_EDIT(-1, WxTreeView::OnEndLabelEdit) - /* + EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem) EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, MyListCtrl::OnDeleteAllItems) #if WXWIN_COMPATIBILITY_2_4 @@ -852,10 +983,12 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown) EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated) EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused) - - EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnColRightClick) - */ +*/ + EVT_LIST_COL_RIGHT_CLICK(-1, WxTreeView::OnColClick) + EVT_LIST_COL_CLICK(-1, WxTreeView::OnColClick) + + //EVT_LEFT_DOWN(WxTreeView::OnMouseClick) /* EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnColBeginDrag) EVT_LIST_COL_DRAGGING(LIST_CTRL, MyListCtrl::OnColDragging)