|
From: Markus R. <rol...@us...> - 2007-04-15 11:48:54
|
Update of /cvsroot/simspark/simspark/contrib/rsgedit In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv12849 Modified Files: sparktree.cpp sparktree.h Log Message: - added method SelectLeaf that expands the SparkTree down to the given Leaf node and selects it Index: sparktree.h =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/sparktree.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** sparktree.h 15 Mar 2007 07:26:24 -0000 1.3 --- sparktree.h 15 Apr 2007 11:48:42 -0000 1.4 *************** *** 52,55 **** --- 52,56 ---- bool GetLocation(const wxTreeItemId id, wxString& location); + bool SelectLeaf(boost::weak_ptr<zeitgeist::Leaf> leaf); protected: Index: sparktree.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/sparktree.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sparktree.cpp 15 Mar 2007 07:26:24 -0000 1.4 --- sparktree.cpp 15 Apr 2007 11:48:41 -0000 1.5 *************** *** 26,29 **** --- 26,30 ---- #include <zeitgeist/leaf.h> + #include <zeitgeist/node.h> #include <zeitgeist/class.h> *************** *** 168,169 **** --- 169,265 ---- return true; } + + bool SparkTree::SelectLeaf(weak_ptr<Leaf> leaf) + { + if (leaf.expired()) + { + assert(false); + return false; + } + + // build parent chain + Leaf::TLeafList leafList; + leafList.push_back(leaf.lock()); + + weak_ptr<Leaf> curLeaf(leaf); + for (;;) + { + weak_ptr<Leaf> parent = curLeaf.lock()->GetParent(); + if (! parent.expired()) + { + leafList.push_back(parent.lock()); + curLeaf = parent; + } else + { + break; + } + } + + + if (leafList.size() <= 1) + { + return false; + } + + // pop root nodea + leafList.pop_back(); + + // expand nodes in reverse order + wxTreeItemId curItem = mRootId; + + for ( + Leaf::TLeafList::reverse_iterator iter = leafList.rbegin(); + iter != leafList.rend(); + ++iter + ) + { + CreateChildren(curItem); + mTree->Expand(curItem); + + weak_ptr<Leaf> leaf = (*iter); + if (leaf.expired()) + { + assert(false); + return false; + } + + wxTreeItemIdValue cookie; + wxTreeItemId item = mTree->GetFirstChild(curItem, cookie); + + bool foundChild = false; + + while (item.IsOk()) + { + ItemData* data = GetItemData(item); + if (data != 0) + { + weak_ptr<Leaf> child = data->leaf; + if (child.expired()) + { + assert(false); + return false; + } + + if (leaf.lock() == child.lock()) + { + curItem = item; + foundChild = true; + break; + } + } + + item = mTree->GetNextChild(item, cookie); + } + + if (! foundChild) + { + assert(false); + return false; + } + } + + mTree->SelectItem(curItem); + mTree->EnsureVisible(curItem); + + return true; + } |