#include <creaImageIOGimmickView.h>
#include <creaImageIOSystem.h>
#include <wx/splitter.h>
+#include <wx/gdicmn.h>
///Comparing function for ordering algorithm. Takes parameters as strings.
int wxCALLBACK CompareFunctionStrings(long item1, long item2, long sortData)
{
if (i>1) sparent = mLevelList[i-2].wxSplitter;
level.wxSplitter = new wxSplitterWindow( sparent , -1);
+ if(i!=1)
+ {
+ level.wxSplitter->Show(false);
+ }
// level.wxSplitter->SetMinimumPaneSize(100);
wxListCtrl* ctrl = new wxListCtrl(level.wxSplitter,
level.wxCtrl = ctrl;
level.wxSplitter->Initialize(ctrl);
+
// Create the columns : one for each attribute of the level
int col = 0;
-
+ std::string title;
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 "<<col<<" : "
<<a->GetName()
<<std::endl);
+
+ if(a->GetFlags()!=creaImageIO::tree::AttributeDescriptor::PRIVATE)
+ {
+
+ if(a->GetName()=="UNKNOWN")
+ {
+ title = "#";
+ title += handler->GetTree().GetLevelDescriptor(i+1).GetName();
+ if (title[title.size()-1]!='s')
+ title += "s";
+
+ }
+ else
+ {
+ title=a->GetName();
+ }
ctrl->InsertColumn(col,
- crea::std2wx(a->GetName()),
+ crea::std2wx(title),
col_style);
level.key.push_back(a->GetKey());
// ctrl->SetColumnWidth(col, wxLIST_AUTOSIZE );
col++;
-
+ }
}
mLevelList.push_back(level);
}
+#if wxUSE_MENUS
+
+ menu =new wxMenu;
+ wxMenuItem* m1=menu->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
mColumnSelected=1;
mLastSelected=0;
mDirection=true;
+ mSelectionMade=false;
+ mProcess=true;
+ //CreateColorPalette();
UpdateLevel(1);
SetSizer( sizer );
GetCtrl(l)->DeleteAllItems();
std::vector<tree::Node*>::iterator i;
- for (i=sel.begin(); i!=sel.end(); ++i)
+
+ for (i=sel.begin(); i!=sel.end(); ++i)
{
GimmickDebugMessage(2,
"adding children of '"
<<(*i)->GetLabel()
- <<"'"<<level
+ <<"'"
<<std::endl);
- int _id=0;
- int r=100;
- int g=100;
- int b=100;
- //Adds columns
+ int _id=1;
+
+ //Adds items and sets their attributes
+ GetCtrl(l)->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);
-
- std::ostringstream oss;
- int n= GetTreeHandler()->GetNumberOfChildren(*j);
-
- oss << n;
- std::string s(oss.str());
-
+ GetCtrl(l)->InsertItem(*item);
- item.SetText( crea::std2wx(s));
- // item.SetTextColour(*wxRED);
+ //Setting attributes
- //Setting the color according to the parent
- /*
- if(l==0)
- {
- item.SetBackgroundColour(wxColour(r,g,b));
- mColorMap.insert(NodeColorPair(*j,wxColour(r,g,b)));
- }
- else if(l!=mLevelList.size()-1)
- {
- item.SetBackgroundColour(mColorMap[*i]);
- mColorMap.insert(NodeColorPair(*j,mColorMap[*i]));
- }
- else
- {
- item.SetBackgroundColour(mColorMap[*i]);
- }
- r+=20;
- g+=20;
- b+=20;*/
-
- item.SetColumn(0);
-
- //Sets the last level as selected....How to make it select only the first time?
- //if (level==mLevelList.size()) item.SetState(wxLIST_STATE_SELECTED);
-
- GetCtrl(l)->SetItem(item);
-
- // GetCtrl(l)->SetItem(id,0, crea::std2wx(s));
- // GetCtrl(l)->SetColumnWidth(0, wxLIST_AUTOSIZE );
-
- for (int k=1; k<GetCtrl(l)->GetColumnCount(); k++)
+ for (int k=0; k<GetCtrl(l)->GetColumnCount(); 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 );
-
- }
-
+ 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)->DeleteItem(0);
}
GetCtrl(l)->Show();
-
-
- if (level<mLevelList.size()) UpdateLevel(level+1);
+
}
//=====================================================================
GetTreeHandler()->GetTree().GetLabel()
<<" view : item selected "
<<std::endl);
-
+
wxListItem info;
info.m_itemId = event.m_itemIndex;
- mLastSelected=event.m_itemIndex;
-
+ mLastSelected = event.m_itemIndex;
// retrieve the level
wxObject* obj = event.GetEventObject();
unsigned int level = 0;
GimmickDebugMessage(1,
" Level "<<level+1
<<std::endl);
+
+ // Update the children level (if selection not at last level)
+ if (level<mLevelList.size()-1)
+ {
+ UpdateLevel( level + 2 );
+ // Reset the viewer setting the default image
+ GetGimmickView()->ClearSelection();
+ }
+ // 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
+ {
+ ValidateSelectedImages (false);
+ }
+ }
+
+ }
+ //================================================================
-
- mSelected=GetSelected(level+2);
-
- if (level<mLevelList.size()-1) UpdateLevel( level + 2 );
-
- if (level==mLevelList.size()-1) ValidateSelectedImages ();
+ //================================================================
+ 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==(GetCtrl(level)->GetItemCount()-1))
+ {
+ mProcess=true;
+ }
+ else
+ {
+ 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);
+ }
}
+
+ //================================================================
//================================================================
-//================================================================
void WxTreeView::OnColClick(wxListEvent& event)
- {
- //Obtain the column name and the level that needs to be organized
+ {
mColumnSelected=event.m_col;
- GimmickDebugMessage(1,
- " Column selected: " <<event.m_col
- <<std::endl);
-
- if(mColumnSelected!=0)
+ wxPoint clientpt;
+ clientpt.x = wxGetMousePosition().x - this->GetScreenPosition().x;
+ clientpt.y = wxGetMousePosition().y - this->GetScreenPosition().y;
+ senderCtrl = event.GetEventObject();
+ unsigned int level = 0;
+ for (level = 0; level<mLevelList.size(); ++level)
{
- wxObject* ctrl = event.GetEventObject();
+ if ( GetCtrl(level) == senderCtrl ) break;
+ }
+ PopupMenu(menu, clientpt);
+
+ }
+
+ //================================================================
+ //================================================================
+
+ void WxTreeView::OnPopupFilter(wxCommandEvent& event)
+ {
+ wxBusyCursor busy;
+ GimmickDebugMessage(7,
+ "WxTreeView::OnEndLabelEdit"
+ <<std::endl);
+ wxObject* ctrl = event.GetEventObject();
unsigned int level = 0;
for (level = 0; level<mLevelList.size(); ++level)
{
- if ( GetCtrl(level) == ctrl ) break;
+ if ( GetCtrl(level) == senderCtrl ) break;
}
+ std::string filter = crea::wx2std(wxGetTextFromUser(_T("Enter the filter to apply"), _T("Filter On Column")));
+
+ std::string att;
+ long it = -1;
UpdateLevel(level+1);
+ std::vector<long> 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]);
+
+
+ if(att.find(filter)>900)
+ {
+
+ if(!in)
+ {
+ in=true;
+ }
+ else
+ {
+ del+=1;
+ }
+
+ items.push_back(it-del);
+ }
+
+ }
+ std::vector<long>::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; level<mLevelList.size(); ++level)
+ {
+ if ( GetCtrl(level) == senderCtrl ) break;
+ }
+ if(event.GetId()==mAscendingID)
+ {
+ mDirection=true;
+ }
+ else if(event.GetId()==mDescendingID)
+ {
+ mDirection=false;
+ }
+
+ OnSort(level);
+ }
+ //================================================================
+ void WxTreeView::OnSort(int level)
+ {
+ //Obtain the column name and the level that needs to be organized
+
int l = level - 1;
-
//Sets the data for the items to be sorted
std::string att;
unsigned int ty=0;
//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)
{
- (*nod).GetAttributeDescriptor(mLevelList[level].key[mColumnSelected-1]).DecodeType(ty);
+ (*nod).GetAttributeDescriptor(mLevelList[level].key[mColumnSelected]).DecodeType(ty);
}
//Obtains the organizing attribute
- att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected-1]);
+ att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected]);
char* d= new char [att.size()+1];
strcpy (d, att.c_str());
GetCtrl(level)->SortItems(CompareFunctionStrings, 0);
}
- mDirection=false;
}
else
{
{
GetCtrl(level)->SortItems(CompareFunctionStrings, 1);
}
- mDirection=true;
}
//Resets original data
+
std::vector<tree::Node*>::iterator selection;
std::vector<long> change;
long it = -1;
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;
- for(selection=mSelected.begin();selection!=mSelected.end();++selection)
- {
- if((*selection)->GetAttribute("ID").compare(n->GetAttribute("ID"))==0)
- {
- change.push_back(it);
- }
- }
+ tree::Node* n= ((ItemData*)((long*)item)[0])->node;
}
- std::vector<long>::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);
-
- }
- }
}
+
//================================================================
-
-
- //================================================================
- void WxTreeView::ValidateSelectedImages()
+ void WxTreeView::ValidateSelectedImages(bool isSelection)
{
GimmickDebugMessage(7,
"WxTreeView::ValidateSelectedImages"
<<std::endl);
std::vector<tree::Node*> sel(GetSelected(mLevelList.size()+1));
- GetGimmickView()->OnSelectionChange(sel);
- /*
- //Send an event telling wether the selection is valid or not
- wxCommandEvent event( 0, GetId() );
- event.SetEventObject( this );
- std::vector<tree::Node*> sel=GetSelected((mLevelList.size()+1));
- event.SetClientData(&sel);
- GetEventHandler()->ProcessEvent( event );
- */
- //
+ GetGimmickView()->OnSelectionChange(sel,isSelection,(mLastSelected-1), mProcess);
+
}
//================================================================
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;
std::string filename=(*i)->GetAttribute("FullFileName");
s.push_back(filename);
}
+ }
+
+ //================================================================
+ 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");
+
+
}
//================================================================
- BEGIN_EVENT_TABLE(WxTreeView, wxPanel)
+ BEGIN_EVENT_TABLE(WxTreeView, wxPanel)
/*
EVT_SIZE(MyFrame::OnSize)
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
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)