X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src2%2FcreaImageIOWxTreeView.cpp;h=b583a7c0775f48d08515030467e4b3efb97ea8ce;hb=da80530068246081505e9649523d10e8da8e6acd;hp=cb8f81df99ba4f7b76efd86347f771d6ec40e5d2;hpb=8de9d3ee075fab84401989d770a73b8dc57442fd;p=creaImageIO.git diff --git a/src2/creaImageIOWxTreeView.cpp b/src2/creaImageIOWxTreeView.cpp index cb8f81d..b583a7c 100644 --- a/src2/creaImageIOWxTreeView.cpp +++ b/src2/creaImageIOWxTreeView.cpp @@ -5,26 +5,11 @@ #include #include -const std::string empty_string(""); //===================================================================== 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; - }; + //===================================================================== } //===================================================================== @@ -226,11 +211,14 @@ 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 Fields")); mAnonymizingID=m1Item->GetId(); mLocalCopyID=m2Item->GetId(); + mEditFieldID=m3Item->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) ); #endif // wxUSE_MENUS @@ -260,6 +248,9 @@ namespace creaImageIO { GimmickDebugMessage(1,"WxTreeView::~WxTreeView" <& WxTreeView::GetSelected(int level) { + std::vector& sel = mLevelList[0].Selected; // if (GetSelectedUpToDate(level)) int l = level - 1; // the selection of upper level - std::vector& sel(mLevelList[l].Selected); - std::cout< 0) + { + sel.clear(); + } if (level == 1) { sel.push_back(GetTreeHandler()->GetTree().GetTree()); @@ -383,9 +380,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); } @@ -490,13 +487,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); @@ -537,13 +534,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(); } } @@ -616,7 +615,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) { @@ -654,7 +654,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); } } @@ -677,17 +677,24 @@ namespace creaImageIO } + //================================================================ + //================================================================ + void WxTreeView::OnItemMenu(wxListEvent &event) { wxPoint clientpt; clientpt.x = wxGetMousePosition().x - this->GetScreenPosition().x; clientpt.y = wxGetMousePosition().y - this->GetScreenPosition().y; - senderCtrl = event.GetEventObject(); + senderCtrl = event.GetEventObject(); unsigned int level = 0; for (level = 0; levelHitTest(wxPoint(0,clientpt.y-8),flag,ptr); PopupMenu(menuItem, clientpt); } @@ -821,6 +828,30 @@ 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 names; + std::vector 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); + } } //================================================================ @@ -1051,114 +1082,97 @@ namespace creaImageIO } //================================================================ - void WxTreeView::SetColor(int l, int item) + + //================================================================ + void WxTreeView::GetAttributes(std::vector& areShown, std::vector& notShown, int level) { - 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])); + 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()); } - else - { - item.SetBackgroundColour(mColorMap[*i]); - }*/ + } + notShown=mLevelList[level-1].notShownAtts; } + //================================================================ - void WxTreeView::CreateColorPalette() + void WxTreeView::SetNonVisibleAttributes(const std::vector& notShown, int nlevel) { - 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"); + mLevelList[nlevel].notShownAtts=notShown; + } + //================================================================ + void WxTreeView::CreateCtrl(std::vector& 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 ns=mLevelList[level-1].notShownAtts; + std::vector::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) /*