/// Concrete derivative of GimmickView which implements a wxWidgets-based view
class WxGimmickView : public wxPanel, virtual public GimmickView
- {
- public:
-
- typedef int EventType;
-
- /// Ctor
- WxGimmickView(Gimmick*,
- wxWindow *parent,
- const wxWindowID id,
- const wxPoint& pos, const wxSize& size,
- int min_dim = GIMMICK_2D_IMAGE_SELECTION,
- int max_dim = GIMMICK_3D_IMAGE_SELECTION,
- int number_of_threads = 0);
- /// Virtual destructor
- virtual ~WxGimmickView();
-
- /// Returns the selected files
- ///(overloaded from GimmickView)
- void GetSelectedFiles(std::vector<std::string>& s);
- /// Returns the selected Images so that they comply with the given parameter(4D)
- //(overloaded from GimmickView)
- void GetSelectedImages(std::vector<vtkImageData*>& s, int dim);
- /// Returns the images indicated by the filenames in the vector so that they comply with the given parameter(dim)
- //(overloaded from GimmickView)
- void GetImages(int dim, std::vector<std::string> files, std::vector<vtkImageData*>& s);
- /// Callback called when a selection from a TreeView has changed
- //(overloaded from GimmickView)
- void OnSelectionChange(std::vector<tree::Node*>& s, bool isSelection, int selection, bool mProcess);
- ///Stops the player
- void StopPlayer(){mViewer->StopPlayer();}
- ///Resets the default image
- void ClearSelection();
-
-
- ///Sends a request to read the currently selected node and the ones that surround it.
- void ReadImageThreaded(std::vector<tree::Node*> sel);
-
-
- protected:
- /// Creates the tool bar
- void CreateToolBar();
-
- /// Create the tree view for TreeHandler provided
- /// (overloaded from GimmickView)
- void CreateTreeView( TreeHandler* );
-
-
- private:
- /// Is set to true at the end of constructor
- /// (in order to lock callbacks from threaded objects or event
- /// before everything is ok)
- bool mConstructed;
- /// The ToolBar and the tools
- wxToolBar* mToolBar;
- wxToolBarToolBase* mToolAddFile;
- wxToolBarToolBase* mToolAddDir;
- wxToolBarToolBase* mToolRemove;
- wxToolBarToolBase* mToolAddDatabase;
- wxToolBarToolBase* mToolHelp;
-
- wxSplitterWindow* mSplitter;
- wxPanel* mBottomPanel;
- wxStaticText * mText;
- wxNotebook* mNotebook;
-
- /// The list of icons
- wxImageList * mIcon;
- void CreateIconList();
-
- Gimmick * mGimmick;
- /// Callback for adding files
- void OnAddFiles(wxCommandEvent& event);
- /// Callback for adding dir
- void OnAddDir(wxCommandEvent& event);
- /// Callback for removing files
- void OnRemove(wxCommandEvent& event);
-
- /// Display a message box with the last addition statistics
- void DisplayAddSummary();
-
-
- /// AddProgress Gimmick callback
- void OnAddProgress( Gimmick::AddProgress& );
- /// Called upon to refresh the viewer once there are no actions to be done
- void OnInternalIdle();
-
- /// Progress dialog
- wxProgressDialog* mProgressDialog;
- ///The selection's maximum dimension
- int mSelectionMaxDimension;
- ///The selection's minimum dimension
- int mSelectionMinDimension;
- ///Image previewer
- WxViewer* mViewer;
- ///Currently Displayed Node
- tree::Node* mCurImageItemToShow;
- //Pointer holders for images to be shown
- std::vector<ImagePointerHolder*> pointers;
-
-
- wxString mCurrentDirectory;
-
- DECLARE_EVENT_TABLE()
- };
- // EO class WxGimmickView
- //=====================================================================
+ {
+ public:
+
+ typedef int EventType;
+
+ /// Ctor
+ WxGimmickView(Gimmick*,
+ wxWindow *parent,
+ const wxWindowID id,
+ const wxPoint& pos, const wxSize& size,
+ int min_dim = GIMMICK_2D_IMAGE_SELECTION,
+ int max_dim = GIMMICK_3D_IMAGE_SELECTION,
+ int number_of_threads = 0);
+ /// Virtual destructor
+ virtual ~WxGimmickView();
+
+ /// Returns the selected files
+ ///(overloaded from GimmickView)
+ void GetSelectedFiles(std::vector<std::string>& s);
+
+ /// Returns the selected Images so that they comply with the
+ /// given parameter(4D) (overloaded from GimmickView)
+ void GetSelectedImages(std::vector<vtkImageData*>& s, int dim);
+
+ /// Returns the images indicated by the filenames in the vector
+ /// so that they comply with the given parameter(dim)
+ //(overloaded from GimmickView)
+ void GetImages(int dim, const std::vector<std::string>& files,
+ std::vector<vtkImageData*>& s);
+
+ /// Callback called when a selection from a TreeView has changed
+ //(overloaded from GimmickView)
+ void OnSelectionChange(const std::vector<tree::Node*>& s,
+ bool isSelection, int selection, bool mProcess);
+ ///Stops the player
+ void StopPlayer(){mViewer->StopPlayer();}
+ ///Resets the default image
+ void ClearSelection();
+
+
+ ///Sends a request to read the currently selected node and the ones that surround it.
+ void ReadImageThreaded(const std::vector<tree::Node*>& sel);
+
+
+ protected:
+ /// Creates the tool bar
+ void CreateToolBar();
+
+ /// Create the tree view for TreeHandler provided
+ /// (overloaded from GimmickView)
+ void CreateTreeView( TreeHandler* );
+
+
+ private:
+ /// Is set to true at the end of constructor
+ /// (in order to lock callbacks from threaded objects or event
+ /// before everything is ok)
+ bool mConstructed;
+ /// The ToolBar and the tools
+ wxToolBar* mToolBar;
+ wxToolBarToolBase* mToolAddFile;
+ wxToolBarToolBase* mToolAddDir;
+ wxToolBarToolBase* mToolRemove;
+ wxToolBarToolBase* mToolAddDatabase;
+ wxToolBarToolBase* mToolHelp;
+
+ wxSplitterWindow* mSplitter;
+ wxPanel* mBottomPanel;
+ wxStaticText * mText;
+ wxNotebook* mNotebook;
+
+ /// The list of icons
+ wxImageList * mIcon;
+ void CreateIconList();
+
+ Gimmick * mGimmick;
+ /// Callback for adding files
+ void OnAddFiles(wxCommandEvent& event);
+ /// Callback for adding dir
+ void OnAddDir(wxCommandEvent& event);
+ /// Callback for removing files
+ void OnRemove(wxCommandEvent& event);
+
+ /// Display a message box with the last addition statistics
+ void DisplayAddSummary();
+
+
+ /// AddProgress Gimmick callback
+ void OnAddProgress( Gimmick::AddProgress& );
+ /// Called upon to refresh the viewer once there are no actions to be done
+ void OnInternalIdle();
+
+ /// Progress dialog
+ wxProgressDialog* mProgressDialog;
+ ///The selection's maximum dimension
+ int mSelectionMaxDimension;
+ ///The selection's minimum dimension
+ int mSelectionMinDimension;
+ ///Image previewer
+ WxViewer* mViewer;
+ ///Currently Displayed Node
+ tree::Node* mCurImageItemToShow;
+ //Pointer holders for images to be shown
+ std::vector<ImagePointerHolder*> pointers;
+
+
+ wxString mCurrentDirectory;
+
+ DECLARE_EVENT_TABLE()
+ };
+ // EO class WxGimmickView
+ //=====================================================================
+
-
/*
#include <creaImageIOSystem.h>
#include <wx/splitter.h>
#include <wx/gdicmn.h>
+
+const std::string void_string("");
+
+//=====================================================================
+namespace creaImageIO
+{
+ //=====================================================================
+ /// Data stored by the list items
+ struct ItemData
+ {
+ ItemData() : node(0), id(-1), attr(&void_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;
+ };
+ //=====================================================================
+}
+//=====================================================================
+
+//=====================================================================
///Comparing function for ordering algorithm. Takes parameters as strings.
int wxCALLBACK CompareFunctionStrings(long item1, long item2, long sortData)
{
- std::string s1((char*)((long*)item1)[1]);
- std::string s2((char*)((long*)item2)[1]);
- if(sortData==1)
- {
- // inverse the order
- if (s1 < s2)
- return 1;
- if (s1 > s2)
- return -1;
-
- return 0;
- }
- else
- {
- if (s1 < s2)
- return -1;
- if (s1 > s2)
- return 1;
-
- return 0;
+ creaImageIO::ItemData* data1 = (creaImageIO::ItemData*)item1;
+ creaImageIO::ItemData* data2 = (creaImageIO::ItemData*)item2;
- }
-
+ const std::string& s1(*(data1->attr));
+ const std::string& s2(*(data2->attr));
+ if(sortData==1)
+ {
+ // inverse the order
+ if (s1 < s2)
+ return 1;
+ if (s1 > s2)
+ return -1;
+
+ return 0;
+ }
+ else
+ {
+ if (s1 < s2)
+ return -1;
+ if (s1 > s2)
+ return 1;
+
+ return 0;
+
+ }
}
+//=====================================================================
+//=====================================================================
///Comparing function for ordering algorithm. Takes parameters as ints.
int wxCALLBACK CompareFunctionInts(long item1, long item2, long sortData)
{
- int val1=atoi((char*)((long*)item1)[1]);
- int val2=atoi((char*)((long*)item2)[1]);
- if(sortData==1)
- {
- // inverse the order
- if (val1 < val2)
- return 1;
- if (val1 > val2)
- return -1;
+ creaImageIO::ItemData* data1 = (creaImageIO::ItemData*)item1;
+ creaImageIO::ItemData* data2 = (creaImageIO::ItemData*)item2;
- return 0;
- }
- else
- {
- if (val1 < val2)
- return -1;
- if (val1 > val2)
- return 1;
+ const std::string& s1(*(data1->attr));
+ const std::string& s2(*(data2->attr));
- return 0;
+ int val1=atoi(s1.c_str());
+ int val2=atoi(s2.c_str());
- }
-
+ if(sortData==1)
+ {
+ // inverse the order
+ if (val1 < val2)
+ return 1;
+ if (val1 > val2)
+ return -1;
+
+ return 0;
+ }
+ else
+ {
+ if (val1 < val2)
+ return -1;
+ if (val1 > val2)
+ return 1;
+
+ return 0;
+
+ }
+
}
+//=====================================================================
+
+
+//=====================================================================
namespace creaImageIO
{
//=====================================================================
GimmickDebugMessage(5,"Creating view for level "<<i
<<std::endl);
LevelType level;
+ level.SelectedUpToDate = true;
+ level.SortColumn = 0;
// If the first level : parent = this
wxWindow* sparent = this;
++a)
{
- GimmickDebugMessage(5,"Creating column "<<col<<" : "
+ GimmickDebugMessage(5,"Creating column "<<col<<" : "
<<a->GetName()
<<std::endl);
-
- if(a->GetFlags()!=creaImageIO::tree::AttributeDescriptor::PRIVATE)
- {
-
+
+ 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";
-
- }
+ {
+ title = "#";
+ title += handler->GetTree().GetLevelDescriptor(i+1).GetName();
+ if (title[title.size()-1]!='s')
+ title += "s";
+
+ }
else
- {
- title=a->GetName();
- }
+ {
+ title=a->GetName();
+ }
+
ctrl->InsertColumn(col,
- crea::std2wx(title),
- col_style);
+ crea::std2wx(title),
+ col_style);
level.key.push_back(a->GetKey());
+
// ctrl->SetColumnWidth(col, wxLIST_AUTOSIZE );
+
col++;
- }
+ }
}
#endif // wxUSE_MENUS
- /// Initialize the first level splitter
-
- sizer->Add( mLevelList[0].wxSplitter ,1, wxGROW ,0);
- mColumnSelected=1;
+ /// Initialize the first level splitter
+
+ sizer->Add( mLevelList[0].wxSplitter ,1, wxGROW ,0);
+ // mColumnSelected=1;
mLastSelected=0;
mLastLevel=0;
- mDirection=true;
- mSelectionMade=false;
- mProcess=true;
+ // mDirection=true;
+
+ mIgnoreSelectedChanged = false;
+
//CreateColorPalette();
UpdateLevel(1);
//=====================================================================
+
//=====================================================================
- struct ItemData
- {
- tree::Node* node;
- int id;
- };
-
- //=====================================================================
- std::vector<tree::Node*> WxTreeView::GetSelected(int level)
+ const std::vector<tree::Node*>& WxTreeView::GetSelected(int level)
{
+ // if (GetSelectedUpToDate(level))
+
int l = level - 1;
// the selection of upper level
- std::vector<tree::Node*> sel;
-
+ std::vector<tree::Node*>& sel(mLevelList[level-1].Selected);
+ sel.clear();
+
if (level == 1)
{
sel.push_back(GetTreeHandler()->GetTree().GetTree());
}
}
- return sel;
+ // return mLevelList[level-1].Selected;
+ return sel;
}
//=====================================================================
+ //=====================================================================
///Removes selected nodes on last selected level
+ // NOT SPECIFIC
void WxTreeView::RemoveSelected()
{
- mLastLevel+=1;
- std::vector<tree::Node*> sel=GetSelected(mLastLevel+1);
- bool erase=false;
- std::stringstream out;
- std::string levelName=GetTreeHandler()->GetTree().GetLevelDescriptor(mLastLevel).GetName();
- out<<"Delete ";
- out<<sel.size();
- if(sel.size()>1&&levelName.at(levelName.size()-1)!='s')
- {
- out<<" "<<levelName;
- out<<"s?";
- }
- else
- {
- out<<" "<<GetTreeHandler()->GetTree().GetLevelDescriptor(mLastLevel).GetName()<<"?";
- }
- if (wxMessageBox(crea::std2wx(out.str()),
- _T("Remove Files"),
- wxYES_NO,this ) == wxYES)
- {
- erase = true;
- }
- if(erase)
+ mLastLevel+=1;
+ const std::vector<tree::Node*>& sel=GetSelected(mLastLevel+1);
+ bool erase=false;
+ std::stringstream out;
+ std::string levelName=GetTreeHandler()->GetTree().GetLevelDescriptor(mLastLevel).GetName();
+ out<<"Delete ";
+ out<<sel.size();
+ if(sel.size()>1&&levelName.at(levelName.size()-1)!='s')
+ {
+ out<<" "<<levelName;
+ out<<"s?";
+ }
+ else
+ {
+ out<<" "<<GetTreeHandler()->GetTree().GetLevelDescriptor(mLastLevel).GetName()<<"?";
+ }
+ if (wxMessageBox(crea::std2wx(out.str()),
+ _T("Remove Files"),
+ wxYES_NO,this ) == wxYES)
+ {
+ erase = true;
+ }
+ if(erase)
{
- bool needRefresh=false;
- std::vector<tree::Node*>::iterator i;
- for (i=sel.begin(); i!=sel.end(); ++i)
- {
- GimmickMessage(1,
- "deleting '"
- <<(*i)->GetLabel()
- <<"'"<<mLastLevel
- <<std::endl);
- if((*i)->GetParent()->GetNumberOfChildren()<2)
- {
- needRefresh=true;
- }
- GetTreeHandler()->Remove(*i);
- }
-
- if(needRefresh && mLastLevel>1)
- {
+ bool needRefresh=false;
+ std::vector<tree::Node*>::const_iterator i;
+ for (i=sel.begin(); i!=sel.end(); ++i)
+ {
+ GimmickMessage(1,
+ "deleting '"
+ <<(*i)->GetLabel()
+ <<"'"<<mLastLevel
+ <<std::endl);
+ if((*i)->GetParent()->GetNumberOfChildren()<2)
+ {
+ needRefresh=true;
+ }
+ GetTreeHandler()->Remove(*i);
+ }
+
+ if(needRefresh && mLastLevel>1)
+ {
UpdateLevel(mLastLevel-2);
- }
- else if(mLastLevel>1)
- {
+ }
+ else if(mLastLevel>1)
+ {
UpdateLevel(mLastLevel-1);
- }
- else
- {
+ }
+ else
+ {
UpdateLevel(mLastLevel);
- }
+ }
}
-
- }
-
+ }
+
+
//=====================================================================
//=====================================================================
- /// Updates a level of the view (adds or removes children, proganizes, etc.)
+ /// Updates a level of the view (adds or removes children, etc.)
void WxTreeView::UpdateLevel( int level )
{
GimmickDebugMessage(1,
GetTreeHandler()->GetTree().GetLabel()
- <<" view : updating level "<<level
+ <<"WxTreeView::UpdateLevel(level "
+ <<level
+ <<")"
<<std::endl);
wxBusyCursor busy;
}
//=====================================================================
+ //=====================================================================
/// Recursive method called upon by UpdateLevel to refresh all windows
void WxTreeView::RecursiveUpdateLevel( int level )
{
- GimmickDebugMessage(2,
+ GimmickDebugMessage(1,
GetTreeHandler()->GetTree().GetLabel()
- <<" view : updating level (recursive)"<<level
- <<std::endl);
-
+ <<"WxTreeView::RecursiveUpdateLevel(level "
+ <<level
+ <<")"<<std::endl);
+
- std::vector<tree::Node*> sel=GetSelected(level);
+ const std::vector<tree::Node*>& sel(GetSelected(level));
- int l = level - 1;
+ int l = level - 1;
// to speed up inserting we hide the control temporarily
GetCtrl(l)->Hide();
GetCtrl(l)->DeleteAllItems();
- std::vector<tree::Node*>::iterator i;
-
- for (i=sel.begin(); i!=sel.end(); ++i)
+ std::vector<tree::Node*>::const_iterator i;
+
+ for (i=sel.begin(); i!=sel.end(); ++i)
{
GimmickDebugMessage(2,
"adding children of '"
int _id=1;
//Adds items and sets their attributes
- GetCtrl(l)->InsertItem(0, _T(""));
+ //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= new wxListItem;
+ wxListItem* item= new wxListItem;
item->SetMask(wxLIST_MASK_STATE |
- wxLIST_MASK_TEXT |
- // wxLIST_MASK_IMAGE |
- wxLIST_MASK_DATA |
+ wxLIST_MASK_TEXT |
+ // wxLIST_MASK_IMAGE |
+ wxLIST_MASK_DATA |
// wxLIST_MASK_WIDTH |
- wxLIST_MASK_FORMAT
- );
-
+ wxLIST_MASK_FORMAT
+ );
+
ItemData* data = new ItemData;
- data->node = *j;
- item->SetId(_id);
-
- data->id = _id;
+ data->node = *j;
+ item->SetId(_id);
+
+ data->id = _id;
item->SetData(data);
- _id++;
- GetCtrl(l)->InsertItem(*item);
-
- //Setting attributes
-
- for (int k=0; k<GetCtrl(l)->GetColumnCount(); k++)
+ _id++;
+ GetCtrl(l)->InsertItem(*item);
+
+ //Setting attributes
+
+ for (int k=0; k<GetCtrl(l)->GetColumnCount(); 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);
+ 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)->DeleteItem(0);
}
+
+ SortLevel(l);
GetCtrl(l)->Show();
-
+
+
+
}
//=====================================================================
//================================================================
- void WxTreeView::OnSelectedChanged(wxListEvent& event)
+ void WxTreeView::OnItemDeSelected(wxListEvent& event)
{
GimmickDebugMessage(1,
GetTreeHandler()->GetTree().GetLabel()
- <<" view : item selected "
- <<std::endl);
+ <<" WxTreeView::OnItemDeselected"<<std::endl);
+ // retrieve the level
+ wxObject* obj = event.GetEventObject();
+ unsigned int level = 0;
+ for (level = 0; level<mLevelList.size(); ++level)
+ {
+ if ( GetCtrl(level) == obj ) break;
+ }
+ SetSelectedUpToDate(level,false);
+ }
+ //================================================================
+
+ //================================================================
+ void WxTreeView::OnItemSelected(wxListEvent& event)
+ {
+ GimmickDebugMessage(1,
+ GetTreeHandler()->GetTree().GetLabel()
+ <<" WxTreeView::OnItemSelected"<<std::endl);
+
+ if (mIgnoreSelectedChanged)
+ {
+ GimmickDebugMessage(1,
+ " mIgnoreSelectedChanged true: returning"
+ <<std::endl);
+ return;
+ }
+
+
wxListItem info;
info.m_itemId = event.m_itemIndex;
GetGimmickView()->ClearSelection();
}
// Select all images if the selection is at series level
- if (level==mLevelList.size()-2) SelectLowerLevel();
+ if (level==mLevelList.size()-2) SelectAll(level+1);
// Validate selected images if the selection is at image level
- if (level==(mLevelList.size()-1)&&mProcess)
+ if (level==(mLevelList.size()-1)) //&&mProcess)
{
if(event.GetEventType()==10145)
{
//================================================================
//================================================================
- void WxTreeView::SelectLowerLevel()
+ void WxTreeView::SelectAll(int level)
{
- long item = -1;
- int level=mLevelList.size()-1;
+ long item = -1;
+ // int level=mLevelList.size()-1;
for ( ;; )
- {
- item = GetCtrl(level)->GetNextItem(item,
- wxLIST_NEXT_ALL);
+ {
+ 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);
- }
+ break;
+
+ if(item==(GetCtrl(level)->GetItemCount()-1))
+ {
+ mIgnoreSelectedChanged = false;//mProcess=true;
+ }
+ else
+ {
+ 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);
+ }
}
//================================================================
void WxTreeView::OnColClick(wxListEvent& event)
{
- mColumnSelected=event.m_col;
- 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)
- {
+ mColumnSelected = event.m_col;
+ 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)
+ {
if ( GetCtrl(level) == senderCtrl ) break;
- }
- PopupMenu(menu, clientpt);
-
+ }
+ PopupMenu(menu, clientpt);
+
}
//================================================================
void WxTreeView::OnPopupFilter(wxCommandEvent& event)
{
- wxBusyCursor busy;
- GimmickDebugMessage(7,
+ 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) == 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();
+ wxObject* ctrl = event.GetEventObject();
+ unsigned int level = 0;
+ for (level = 0; level<mLevelList.size(); ++level)
+ {
+ 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;
- }
+ wxBusyCursor busy;
+ unsigned int level = 0;
+ for (level = 0; level<mLevelList.size(); ++level)
+ {
+ if ( GetCtrl(level) == senderCtrl ) break;
+ }
+ mLevelList[level].SortColumn = mColumnSelected;
- OnSort(level);
+ if(event.GetId()==mAscendingID)
+ {
+ mLevelList[level].SortAscending = true;
+ }
+ else if(event.GetId()==mDescendingID)
+ {
+ mLevelList[level].SortAscending = false;
+ }
+
+ SortLevel(level);
}
//================================================================
- void WxTreeView::OnSort(int level)
+
+ //================================================================
+ void WxTreeView::SortLevel(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;
- int n = GetCtrl(level)->GetItemCount();
- for (int i = 0; i < n; i++)
- {
-
- //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]).DecodeType(ty);
- }
- //Obtains the organizing attribute
- att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected]);
-
- char* d= new char [att.size()+1];
- strcpy (d, att.c_str());
-
- //Creates array
- long* lp= new long[2];
- lp[0]=adr;
- lp[1]=(long)d;
-
- //Sets it as the data
- GetCtrl(level)->SetItemData(i,(long)lp);
- }
-
- if(mDirection)
- {
- if(ty==1)
- {
- GetCtrl(level)->SortItems(CompareFunctionInts, 0);
- }
- else
- {
- GetCtrl(level)->SortItems(CompareFunctionStrings, 0);
- }
-
- }
- else
- {
- if(ty==1)
- {
- GetCtrl(level)->SortItems(CompareFunctionInts, 1);
- }
- else
- {
- GetCtrl(level)->SortItems(CompareFunctionStrings, 1);
- }
- }
+ GimmickDebugMessage(1,
+ "WxTreeView::SortLevel("
+ <<level<<")"
+ <<std::endl);
+ //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;
+ int nbselected = 0;
+ int n = GetCtrl(level)->GetItemCount();
+ for (int i = 0; i < n; i++)
+ {
+
+ //Gets current item data
+ ItemData* data = (ItemData*)GetCtrl(level)->GetItemData(i);
+
+ //Extracts the node and the type of attribute
+ tree::Node* nod = data->node;
+ if(i==0)
+ {
+ (*nod).GetAttributeDescriptor
+ (mLevelList[level].key[mLevelList[level].SortColumn])
+ .DecodeType( ty );
+ }
+ //Obtains the organizing attribute
+ data->attr = & (*nod).GetAttribute
+ (mLevelList[level].key[mLevelList[level].SortColumn]);
+ //Selected ?
+ data->selected = false;
+ if (GetCtrl(level)->GetItemState(i,wxLIST_STATE_SELECTED)>0)
+ {
+ data->selected = true;
+ nbselected++;
+ }
- //Resets original data
- long it = -1;
- for ( ;; )
- {
- it = GetCtrl(level)->GetNextItem(it,
- 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;
-
- }
+ }
+ GimmickDebugMessage(1,
+ "WxTreeView::OnSort : "
+ <<nbselected<<" selected before sorting"
+ <<std::endl);
+
+ mIgnoreSelectedChanged = true;
+ //
+ if (mLevelList[level].SortAscending)
+ {
+
+ if(ty==1)
+ {
+ GetCtrl(level)->SortItems(CompareFunctionInts, 0);
+ }
+ else
+ {
+ GetCtrl(level)->SortItems(CompareFunctionStrings, 0);
+ }
- }
+ }
+ else
+ {
+ if(ty==1)
+ {
+ GetCtrl(level)->SortItems(CompareFunctionInts, 1);
+ }
+ else
+ {
+ GetCtrl(level)->SortItems(CompareFunctionStrings, 1);
+ }
+ }
+
+ // Reselects the unselected
+ n = GetCtrl(level)->GetItemCount();
+ int after = 0;
+ for (int i = 0; i < n; i++)
+ {
+
+ //Gets current item data
+ ItemData* data = (ItemData*)GetCtrl(level)->GetItemData(i);
+
+ // long item = -1;
+ // for ( ;; )
+ // {
+ // item = GetCtrl(level)->GetNextItem(item,wxLIST_NEXT_ALL);
+ // if ( item == -1 ) break;
+ //Gets current item data
+ // ItemData* data = (ItemData*)GetCtrl(level)->GetItemData(item);
+ // was selected ?
+
+ if (data->selected)
+ {
+ nbselected--;
+ if (nbselected==0)
+ {
+ // if it is the last one we must process the selection
+ mIgnoreSelectedChanged = false;
+ }
+ GetCtrl(level)->SetItemState(i,
+ wxLIST_STATE_SELECTED,
+ wxLIST_MASK_STATE
+ | wxLIST_MASK_TEXT
+ | wxLIST_MASK_IMAGE
+ | wxLIST_MASK_DATA
+ | wxLIST_MASK_WIDTH
+ | wxLIST_MASK_FORMAT);
+ }
+ if (GetCtrl(level)->GetItemState(i,wxLIST_STATE_SELECTED)>0)
+ {
+ after++;
+ }
+
+
+ }
+ mIgnoreSelectedChanged = false;
+ GimmickDebugMessage(1,
+ "WxTreeView::SortLevel : "
+ <<after<<" selected after sorting"
+ <<std::endl);
+
+ }
+ //================================================================
+
+
//================================================================
void WxTreeView::ValidateSelectedImages(bool isSelection)
{
GimmickDebugMessage(7,
"WxTreeView::ValidateSelectedImages"
<<std::endl);
- std::vector<tree::Node*> sel(GetSelected(mLevelList.size()+1));
- GetGimmickView()->OnSelectionChange(sel,isSelection,(mLastSelected-1), mProcess);
+ const std::vector<tree::Node*>& sel(GetSelected(mLevelList.size()+1));
+ GetGimmickView()->OnSelectionChange(sel,
+ isSelection,(mLastSelected-1),
+ !mIgnoreSelectedChanged);
}
//================================================================
}
}
+ //================================================================
//================================================================
+ // Should be in another place : not specific !
void WxTreeView::GetSelectedAsString(std::vector<std::string>&s)
{
- int level=mLevelList.size();
- std::vector<tree::Node*> sel=GetSelected(level+1);
- std::vector<tree::Node*>::iterator i;
-
+ int level=mLevelList.size();
+ const std::vector<tree::Node*>& sel=GetSelected(level+1);
+ std::vector<tree::Node*>::const_iterator i;
+
for (i=sel.begin(); i!=sel.end(); ++i)
{
- std::string filename=(*i)->GetAttribute("FullFileName");
- s.push_back(filename);
- }
+ std::string filename=(*i)->GetAttribute("FullFileName");
+ s.push_back(filename);
+ }
}
//================================================================
EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo)
#endif
*/
- EVT_LIST_ITEM_SELECTED(-1, WxTreeView::OnSelectedChanged)
+ EVT_LIST_ITEM_SELECTED(-1, WxTreeView::OnItemSelected)
- EVT_LIST_ITEM_DESELECTED(-1, WxTreeView::OnSelectedChanged)
+ EVT_LIST_ITEM_DESELECTED(-1, WxTreeView::OnItemDeSelected)
/*
EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
/// Updates the view of a level given the selected items of upper level
virtual void UpdateLevel( int );
- ///Removes selected nodes on given level
- virtual void RemoveSelected();
-
- /// Callback for selection change
- void OnSelectedChanged(wxListEvent& event);
+ ///Removes selected nodes on given level
+ virtual void RemoveSelected();
+
+ /// Callback for item selection
+ void OnItemSelected(wxListEvent& event);
- /// Callback for column click
+ /// Callback for item deselection
+ void OnItemDeSelected(wxListEvent& event);
+
+ /// Callback for column click
void OnColClick(wxListEvent& event);
-
- /// Callback when the user needs the items sorted
- void OnPopupSort(wxCommandEvent& event);
-
- ///Callback when the user need the items filtered
- void OnPopupFilter(wxCommandEvent& event);
-
- ///Callback on mouse click
- void OnMouseClick(wxMouseEvent& event);
-
-
+
+ /// Callback when the user needs the items sorted
+ void OnPopupSort(wxCommandEvent& event);
+
+ ///Callback when the user need the items filtered
+ void OnPopupFilter(wxCommandEvent& event);
+
+ ///Callback on mouse click
+ void OnMouseClick(wxMouseEvent& event);
+
+ /// Actual processing of item selection/deselection
+ /// Called by OnItemSelected and OnItemDeSelected
+ // void ProcessItem
private:
/// The struct holding the data for one level
/// Holds the wx control and other data
wxListCtrl* wxCtrl;
wxSplitterWindow* wxSplitter;
std::vector<std::string> key;
+ // The vector of currently selected nodes of the level
+ std::vector<tree::Node*> Selected;
+ // True iff the vector Selected is up to date
+ bool SelectedUpToDate;
+ // The column used for sorting
+ unsigned int SortColumn;
+ ///Boolean that defines the direction of the sort
+ ///True is ascending order and false is descending
+ bool SortAscending;
+ //
};
/// The vector of levels : one for each level of the tree
std::vector<LevelType> mLevelList;
wxListCtrl* GetCtrl(int l) { return mLevelList[l].wxCtrl; }
/// return the wxSplitter of one level
wxSplitterWindow* GetSplitter(int l) { return mLevelList[l].wxSplitter; }
- //Returns the maximum number of levels
- int GetNumberOfLevels(){ return mLevelList.size(); }
- /// Gets the user selected data from the level passed as a parameter
- std::vector<tree::Node*> GetSelected(int level);
- ///Validates the selected images
+ //Returns the maximum number of levels
+ int GetNumberOfLevels(){ return mLevelList.size(); }
+ /// Gets the user selected data from the level passed as a parameter
+ /// Updates the vector if necessary
+ const std::vector<tree::Node*>& GetSelected(int level);
+ /// Set the bool SelectedUpToDate for level l
+ void SetSelectedUpToDate(int l, bool v) { mLevelList[l].SelectedUpToDate = v; }
+ /// Get the bool SelectedUpToDate for level l
+ bool GetSelectedUpToDate(int l) { return mLevelList[l].SelectedUpToDate; }
+ ///Validates the selected images
void ValidateSelectedImages(bool isSelection);
- ///Gets selected filenames
- void GetSelectedAsString(std::vector<std::string>&s);
- /// Gets the next nodes on the list, be it up(true) or down(false).
+ ///Gets selected filenames
+ void GetSelectedAsString(std::vector<std::string>&s);
+ /// Gets the next nodes on the list, be it up(true) or down(false).
void GetNodes(std::vector<tree::Node*>& nodes, bool direction);
/// Updates the view of a level given the selected items of upper level
/// Recursive method
virtual void RecursiveUpdateLevel( int );
- ///Sets the color of a selected item
- void SetColor(int level, int item);
- ///Creates the color palette for the first level
- void CreateColorPalette();
- ///Selects the lowest level (images)
- void SelectLowerLevel();
- ///Sorts items
- void OnSort(int level);
-
-
-
+ ///Sets the color of a selected item
+ void SetColor(int level, int item);
+ ///Creates the color palette for the first level
+ void CreateColorPalette();
+ ///Selects all the elements of a level
+ void SelectAll(int level);
+ ///UnSelects all the elements of a level
+ void UnSelectAll(int level);
+
+ /// Sorts the level
+ void SortLevel(int level);
+
/// Currently Selected Column
- int mColumnSelected;
- ///Boolean that defines the direction of the organization
- ///True is ascending order and false is descending
- bool mDirection;
- ///The last selected item on the list
- long mLastSelected;
- ///The color map
- typedef std::map<tree::Node*,wxColour> ColorMap;
- typedef std::pair<tree::Node*,wxColour> NodeColorPair;
+ int mColumnSelected;
+ ///The last selected item on the list
+ long mLastSelected;
+ ///The color map
+ typedef std::map<tree::Node*,wxColour> ColorMap;
+ typedef std::pair<tree::Node*,wxColour> NodeColorPair;
ColorMap mColorMap;
- ///Initial color palette
- std::vector<std::string> mColorPalette;
- ///Boolean declaring if the last level selection has been made
- bool mSelectionMade;
- bool mProcess;
- wxMenu* menu;
- wxObject* senderCtrl;
- int mAscendingID;
- int mDescendingID;
- int mFilterID;
- unsigned int mLastLevel;
+ ///Initial color palette
+ std::vector<std::string> mColorPalette;
+
+ wxMenu* menu;
+ wxObject* senderCtrl;
+ int mAscendingID;
+ int mDescendingID;
+ int mFilterID;
+ unsigned int mLastLevel;
+
+ // If set to true then OnSelectedChanged returns immediately.
+ // Used to do avoid useless process during multiple selections
+ // or sorting
+ bool mIgnoreSelectedChanged;
+
DECLARE_EVENT_TABLE()
};