2009-03-15 20:21 UTC
I am using a Tree control for an operational program. The key of each node is also used to create a dictionary xrecord. If one desires to delete a node from the Tree, the control manages removing the descendants automatically. But wait! There are xrecords that need to be deleted as well. Since the keys of the tree nodes were designed to be the same as the keys of the xrecords, all we need is a list of keys belonging to the selected node.
Here is the first working version I came up with:
;;returns selected node and descendants
(defun tcam:getTreeBranch (cntrlName / rslt)
(tcam:BranchBug (dcl_Tree_GetSelectedItem cntrlName))
(reverse rslt)
)
(defun tcam:BranchBug (nodekey / childkey sibkey tmpkey)
(setq tmpkey nodekey
rslt (cons nodekey rslt))
(if (dcl_Tree_ItemHasChildren cntrlName nodekey)
(cond
((setq childkey (dcl_tree_getfirstchilditem cntrlName nodekey))
(tcam:BranchBug childkey)
(setq tmpkey childkey)
(while
(setq sibkey (dcl_tree_getnextsiblingitem cntrlName tmpkey))
(tcam:BranchBug sibkey)
(setq tmpkey sibkey))))))
;***proof***
;Select Setup node
(tcam:getTreeBranch Onset_Outline_Tree)
("Setup{" "Setup{Info"
"Setup{Datum"
"Setup{Material"
"Setup{Machine"
"Setup{Tools"
)
;Select Pgm node
(tcam:getTreeBranch Onset_Outline_Tree)
("Pgm {"
"Pgm {BoreHole {"
"Pgm {BoreHole {SpotDrill "
"Pgm {BoreHole {Drill "
"Pgm {BoreHole {Bore "
"Pgm {Pocket {"
"Pgm {Pocket {Rough "
"Pgm {Pocket {Finish "
"Pgm {Pocket {EdgeBreak "
)
Here is the first working version I came up with:
;;returns selected node and descendants
(defun tcam:getTreeBranch (cntrlName / rslt)
(tcam:BranchBug (dcl_Tree_GetSelectedItem cntrlName))
(reverse rslt)
)
(defun tcam:BranchBug (nodekey / childkey sibkey tmpkey)
(setq tmpkey nodekey
rslt (cons nodekey rslt))
(if (dcl_Tree_ItemHasChildren cntrlName nodekey)
(cond
((setq childkey (dcl_tree_getfirstchilditem cntrlName nodekey))
(tcam:BranchBug childkey)
(setq tmpkey childkey)
(while
(setq sibkey (dcl_tree_getnextsiblingitem cntrlName tmpkey))
(tcam:BranchBug sibkey)
(setq tmpkey sibkey))))))
;***proof***
;Select Setup node
(tcam:getTreeBranch Onset_Outline_Tree)
("Setup{" "Setup{Info"
"Setup{Datum"
"Setup{Material"
"Setup{Machine"
"Setup{Tools"
)
;Select Pgm node
(tcam:getTreeBranch Onset_Outline_Tree)
("Pgm {"
"Pgm {BoreHole {"
"Pgm {BoreHole {SpotDrill "
"Pgm {BoreHole {Drill "
"Pgm {BoreHole {Bore "
"Pgm {Pocket {"
"Pgm {Pocket {Rough "
"Pgm {Pocket {Finish "
"Pgm {Pocket {EdgeBreak "
)

