X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FwxCDMProjectsTreeCtrl.cxx;h=d0bbafb67534d17273a5a9bced6ca492631de45e;hb=bae167768b5d3ccae6ec9b04c844d80e0368a52d;hp=5ba578e77c5bbbb46d0aa872933cb6bccca3b850;hpb=e2223b619fa37daaf6103b34b39e789efc1a0b94;p=crea.git diff --git a/lib/creaDevManagerLib/wxCDMProjectsTreeCtrl.cxx b/lib/creaDevManagerLib/wxCDMProjectsTreeCtrl.cxx index 5ba578e..d0bbafb 100755 --- a/lib/creaDevManagerLib/wxCDMProjectsTreeCtrl.cxx +++ b/lib/creaDevManagerLib/wxCDMProjectsTreeCtrl.cxx @@ -23,7 +23,7 @@ # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-B license and that you accept its terms. # ------------------------------------------------------------------------ -*/ + */ /* @@ -34,8 +34,27 @@ */ #include "wxCDMProjectsTreeCtrl.h" -#include "creaDevManagerIds.h" + #include +#include + +#include + +#include "creaDevManagerIds.h" +#include "images/AIcon20.xpm" +#include "images/ApIcon20.xpm" +#include "images/BBIcon20.xpm" +#include "images/BBSIcon20.xpm" +#include "images/BBGIcon20.xpm" +#include "images/CIcon20.xpm" +#include "images/CFIcon20.xpm" +#include "images/CMIcon20.xpm" +#include "images/FdIcon20.xpm" +#include "images/FlIcon20.xpm" +#include "images/LbIcon20.xpm" +#include "images/LIcon20.xpm" +#include "images/PrIcon20.xpm" +#include "images/PkIcon20.xpm" wxCDMProjectsTreeCtrl::wxCDMProjectsTreeCtrl( wxWindow *parent, @@ -65,37 +84,185 @@ bool wxCDMProjectsTreeCtrl::Create( ) { wxTreeCtrl::Create (parent, id, pos, size, style, validator, name); - wxTreeItemId rootIndex = this-> AddRoot(_("Open Projects")); + + this->DeleteAllItems(); + + wxImageList* images = new wxImageList(20, 20, true); + this->ID_AIcon = images->Add(wxIcon(AIcon20)); + this->ID_ApIcon = images->Add(wxIcon(ApIcon20)); + this->ID_BBIcon = images->Add(wxIcon(BBIcon20)); + this->ID_BBGIcon = images->Add(wxIcon(BBGIcon20)); + this->ID_BBSIcon = images->Add(wxIcon(BBSIcon20)); + this->ID_Cicon = images->Add(wxIcon(CIcon20)); + this->ID_CMIcon = images->Add(wxIcon(CMIcon20)); + this->ID_FdIcon = images->Add(wxIcon(FdIcon20)); + this->ID_FlIcon = images->Add(wxIcon(FlIcon20)); + this->ID_CFIcon = images->Add(wxIcon(CFIcon20)); + this->ID_LbIcon = images->Add(wxIcon(LbIcon20)); + this->ID_LIcon = images->Add(wxIcon(LIcon20)); + this->ID_PrIcon = images->Add(wxIcon(PrIcon20)); + this->ID_PkIcon = images->Add(wxIcon(PkIcon20)); + this->AssignImageList(images); + + wxTreeItemId rootIndex = this->AddRoot(wxT("No Open Project"), this->ID_Cicon, this->ID_Cicon); + this->Update(); return TRUE; } -void wxCDMProjectsTreeCtrl::BuildTree(const modelCDMProjectsTree& projectsTree) +void wxCDMProjectsTreeCtrl::BuildTree(std::map< wxCDMTreeItemId, modelCDMIProjectTreeNode* >& modelElements, modelCDMProject* projectTree) { + this->Unselect(); + std::cout << "building tree" << std::endl; this->DeleteAllItems(); - wxTreeItemId rootIndex = this-> AddRoot(_("Open Projects")); - std::cout << "Building TreeCtrl for " << projectsTree.projectRoot.GetName() << std::endl; - wxTreeItemId parentIndex = this-> AppendItem(rootIndex, wxString(projectsTree.projectRoot.GetName().c_str(), wxConvUTF8)); - this->BuildTree(projectsTree.projectRoot.GetChildren(), parentIndex); + modelElements.clear(); + if(projectTree != NULL) + { + projectTree->SetId(this->AddRoot(crea::std2wx(projectTree->GetName()), this->ID_PrIcon)); + + modelElements[projectTree->GetId()] = projectTree; - this->Expand(rootIndex); + std::cout << "Building TreeCtrl for " << projectTree->GetName() << std::endl; + this->BuildTree(projectTree->GetChildren(), modelElements, projectTree->GetId()); - this->Update(); + this->Expand(projectTree->GetId().GetWxId()); + + this->Update(); + } + else + { + wxTreeItemId rootIndex = this-> AddRoot(_("No Open Project"), this->ID_Cicon); + } } -void wxCDMProjectsTreeCtrl::BuildTree(const std::vector& projectsTree, wxTreeItemId parent) +void wxCDMProjectsTreeCtrl::BuildTree(const std::vector& treeNodes, std::map< wxCDMTreeItemId, modelCDMIProjectTreeNode* >& modelElements, const wxCDMTreeItemId& parent) { - for (int i = 0; i < projectsTree.size(); i++) - { - //cout << projectsTree[i].GetName() << endl; - wxTreeItemId parentNodeIndex; - wxString nodeName((projectsTree[i].GetName()).c_str(), wxConvUTF8); - parentNodeIndex = this->AppendItem(parent, nodeName); - - std::vector innerChildren = projectsTree[i].GetChildren(); - if(innerChildren.size() > 0) + for (int i = 0; i < (int)(treeNodes.size()); i++) + { + //cout << projectsTree[i].GetName() << endl; + if(treeNodes[i] != NULL) + { + int idIcon = GetIconId(treeNodes[i]); + wxString nodeName((treeNodes[i]->GetName()).c_str(), wxConvUTF8); + treeNodes[i]->SetId(wxCDMTreeItemId(this->AppendItem(parent.GetWxId(), nodeName, idIcon))); + + modelElements[treeNodes[i]->GetId()] = treeNodes[i]; + + std::vector innerChildren = treeNodes[i]->GetChildren(); + if(innerChildren.size() > 0) + { + this->BuildTree(innerChildren, modelElements, treeNodes[i]->GetId()); + } + } + + } +} + +int wxCDMProjectsTreeCtrl::GetIconId(modelCDMIProjectTreeNode* node) +{ + modelCDMIProjectTreeNode* element = dynamic_cast(node); + if(element != NULL) + { + return this->ID_PrIcon; + } + else { - this->BuildTree(innerChildren, parentNodeIndex); + element = dynamic_cast(node); + if(element != NULL) + { + return this->ID_ApIcon; + } + else + { + element = dynamic_cast(node); + if(element != NULL) + { + return this->ID_AIcon; + } + else + { + element = dynamic_cast(node); + if(element != NULL) + { + return this->ID_LbIcon; + } + else + { + element = dynamic_cast(node); + if(element != NULL) + { + return this->ID_LIcon; + } + else + { + element = dynamic_cast(node); + if(element != NULL) + { + return this->ID_PkIcon; + } + else + { + element = dynamic_cast(node); + if(element != NULL) + { + return this->ID_BBIcon; + } + else + { + element = dynamic_cast(node); + if(element != NULL) + { + return this->ID_CMIcon; + } + else + { + element = dynamic_cast(node); + if(element != NULL) + { + return this->ID_CFIcon; + } + else + { + element = dynamic_cast(node); + if(element != NULL) + { + return this->ID_BBSIcon; + } + else + { + element = dynamic_cast(node); + if(element != NULL) + { + return this->ID_BBGIcon; + } + else + { + element = dynamic_cast(node); + if(element != NULL) + { + return this->ID_FdIcon; + } + else + { + element = dynamic_cast(node); + if(element != NULL) + { + return this->ID_FlIcon; + } + else + { + return this->ID_Cicon; + } + } + } + } + } + } + } + } + } + } + } + } } - } }