X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src2%2FcreaImageIOWxTreeView.cpp;h=8f0e1f5ad000f8cfde982fab15c68c1a1aee2b65;hb=60257912f98339ad44b500d6d4b700cca8e8daa9;hp=72b58fc97ca980af62eb4e18150d3d63549e98dd;hpb=6cac83c30fb8c3cd89c41685078eccff6e952a50;p=creaImageIO.git diff --git a/src2/creaImageIOWxTreeView.cpp b/src2/creaImageIOWxTreeView.cpp index 72b58fc..8f0e1f5 100644 --- a/src2/creaImageIOWxTreeView.cpp +++ b/src2/creaImageIOWxTreeView.cpp @@ -1,6 +1,8 @@ #include +#include #include #include +#include ///Comparing function for ordering algorithm. Takes parameters as strings. int wxCALLBACK CompareFunctionStrings(long item1, long item2, long sortData) { @@ -62,10 +64,11 @@ namespace creaImageIO //===================================================================== // CTor WxTreeView::WxTreeView(TreeHandler* handler, + GimmickView* gimmick, wxWindow* parent, const wxWindowID id) : wxPanel(parent,id), - TreeView(handler) + TreeView(handler,gimmick) { GimmickDebugMessage(1,"WxTreeView::WxTreeView" < 0 (not for Root level) @@ -110,7 +113,6 @@ namespace creaImageIO // Create the columns : one for each attribute of the level int col = 0; - tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a; for (a = handler->GetTree().GetAttributeDescriptorList(i).begin(); a != handler->GetTree().GetAttributeDescriptorList(i).end(); @@ -149,6 +151,8 @@ namespace creaImageIO mColumnSelected=1; mLastSelected=0; mDirection=true; + mSelectionMade=false; + CreateColorPalette(); UpdateLevel(1); SetSizer( sizer ); @@ -208,7 +212,7 @@ namespace creaImageIO } } } - + return sel; } @@ -288,6 +292,8 @@ 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) { GimmickDebugMessage(2, @@ -295,8 +301,12 @@ namespace creaImageIO <<(*i)->GetLabel() <<"'"<LoadChildren(*i,1); tree::Node::ChildrenListType::reverse_iterator j; for (j = (*i)->GetChildrenList().rbegin(); @@ -316,63 +326,66 @@ namespace creaImageIO data->node = *j; item.SetId(_id); - /* - std::string a=(*j)->GetAttribute(mLevelList[l].key[mColumnSelected-1]); - GimmickMessage(1, - "State Check: Att VAL" - <id = _id; item.SetData(data); _id++; - - long id = GetCtrl(l)->InsertItem(item); - + long id=GetCtrl(l)->InsertItem(item); + + //Setting first column (number of children) std::ostringstream oss; int n= GetTreeHandler()->GetNumberOfChildren(*j); - oss << n; std::string s(oss.str()); - - item.SetText( crea::std2wx(s)); - // item.SetTextColour(*wxRED); - // item.SetBackgroundColour(*wxBLACK); - item.SetColumn(0); - - //Sets the last level as selecte....How to make it select only the first time? - //if (level==mLevelList.size()) item.SetState(wxLIST_STATE_SELECTED); + + //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.SetColumn(0); GetCtrl(l)->SetItem(item); - // GetCtrl(l)->SetItem(id,0, crea::std2wx(s)); - // GetCtrl(l)->SetColumnWidth(0, wxLIST_AUTOSIZE ); - + //Setting other attributes for (int k=1; kGetColumnCount(); k++) { std::string val = (*j)->GetAttribute(mLevelList[l].key[k-1]); if (val.size()==0) val = "?"; item.SetText( crea::std2wx(val)); - // item.SetTextColour(*wxBLACK); - // item.SetBackgroundColour(*wxWHITE); item.SetColumn(k); - GetCtrl(l)->SetItem(item); - - // GetCtrl(l)->SetItem(id,k, crea::std2wx(val)); - // GetCtrl(l)->SetColumnWidth(k, wxLIST_AUTOSIZE ); - - } - + GetCtrl(l)->SetItem(item); + } } } GetCtrl(l)->Show(); - + if (levelClearSelection(); + } + if (level==mLevelList.size()-2) SelectLowerLevel(); + if (level==mLevelList.size()-1) ValidateSelectedImages (); + } + else + { + if(event.GetEventType()==10145) + { + + GetCtrl(level)->SetItemText(0,crea::std2wx("")); + GetCtrl(level)->EditLabel(event.m_itemIndex); + } + + } + + } + //================================================================ + + //================================================================ + void WxTreeView::SelectLowerLevel() + { + long item = -1; + int level=mLevelList.size()-1; + for ( ;; ) + { + item = GetCtrl(level)->GetNextItem(item, + wxLIST_NEXT_ALL); + if ( item == -1 ) + break; + 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::OnColClick(wxListEvent& event) { //Obtain the column name and the level that needs to be organized @@ -422,11 +485,11 @@ namespace creaImageIO { if ( GetCtrl(level) == ctrl ) break; } - UpdateLevel(level+1); + wxBusyCursor busy; int l = level - 1; - + GetCtrl(level)->DeleteItem(0); //Sets the data for the items to be sorted std::string att; unsigned int ty=0; @@ -484,7 +547,8 @@ namespace creaImageIO } //Resets original data - + std::vector::iterator selection; + std::vector change; long it = -1; for ( ;; ) { @@ -492,27 +556,122 @@ namespace creaImageIO wxLIST_NEXT_ALL); if ( it == -1 ) break; + //Gets current item data, extracts the node and resets it long item = GetCtrl(level)->GetItemData(it); GetCtrl(level)->SetItemData(it,((long*)item)[0]); + tree::Node* n= ((ItemData*)((long*)item)[0])->node; + if(levelGetAttribute("ID").compare(n->GetAttribute("ID"))==0) + { + change.push_back(it); + } + } + } + else + { + for(selection=mLastLevelSelected.begin();selection!=mLastLevelSelected.end();++selection) + { + if((*selection)->GetAttribute("ID").compare(n->GetAttribute("ID"))==0) + { + change.push_back(it); + } + } + } + } + //Resets the selected items + std::vector::iterator selectedIts; + for(selectedIts=change.begin();selectedIts!=change.end();++selectedIts) + { + GetCtrl(level)->SetItemState(*selectedIts,wxLIST_STATE_SELECTED, wxLIST_MASK_STATE + | wxLIST_MASK_TEXT |wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT); + + } + GetCtrl(level)->InsertItem(0,"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() { - //Send an event telling wether the selection is valid or not - wxCommandEvent event( 0, GetId() ); - event.SetEventObject( this ); - std::vector sel=GetSelected((mLevelList.size()+1)); - event.SetClientData(&sel); - GetEventHandler()->ProcessEvent( event ); + GimmickDebugMessage(7, + "WxTreeView::ValidateSelectedImages" + < sel(GetSelected(mLevelList.size()+1)); + GetGimmickView()->OnSelectionChange(sel); + } + //================================================================ + - //================================================================ + //================================================================ void WxTreeView::GetNodes(std::vector& nodes, bool direction) { long item = mLastSelected; @@ -533,11 +692,11 @@ namespace creaImageIO item = GetCtrl(level)->GetNextItem(item, wxLIST_NEXT_BELOW); } - if ( item == -1 ) + if ( item == -1 ) { break; } - if(GetCtrl(level)->GetItemState(item, wxLIST_STATE_SELECTED)==0) + if(GetCtrl(level)->GetItemState(item, wxLIST_STATE_SELECTED)==0 && item!=0) { adr = GetCtrl(level)->GetItemData(item); nod = ((ItemData*)adr)->node; @@ -559,6 +718,79 @@ namespace creaImageIO std::string filename=(*i)->GetAttribute("FullFileName"); s.push_back(filename); } + } + + //================================================================ + 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"); + + } //================================================================ BEGIN_EVENT_TABLE(WxTreeView, wxPanel) @@ -602,8 +834,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(LIST_CTRL, MyListCtrl::OnBeginLabelEdit) - EVT_LIST_END_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnEndLabelEdit) + */ + 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