[Solved] Tree control: Child of a child - How to?

Started by Peter2 · 2014-11-12 16:04 UTC · 10 replies · SMF topic #2194

Based on the examples of "Tree.lsp" I tried to create a tree "on_initialize"  -> result:  :'( :'(

I'm sure it is simple, but I can not figure it out. Here is the working fragment with "Parent - Child", but I'm not able to create "Parent - Child - Child":

    (setq P10 (dcl_Tree_AddParent spdrs_Haupt_tree "Abbruch" 9 -1 9))
    (setq P20 (dcl_Tree_AddParent spdrs_Haupt_tree "Betriebsartenstecker" 10 -1 10))
    (dcl_Tree_AddChild spdrs_Haupt_tree
        (list
            (list P20 "a child" 4 5)
            (list P20 "should be a parent from three children" 4 5)
        )
    )
    (setq P30 (dcl_Tree_AddParent spdrs_Haupt_tree "Kondensator" 10 -1 10))



Other question:
Trees can be created "with lists" and "without lists". It seem to me that there is also another behaviour of the "uParentItems" and "strKey" - right?


; mode with lists and setq
    (setq P20 (dcl_Tree_AddParent spdrs_Haupt_tree "Betriebsartenstecker" 10 -1 10))
    (dcl_Tree_AddChild spdrs_Haupt_tree
        (list
            (list P20 "von oben" 4 5)
            (list P20 "von unten" 4 5)
        )
    )
; -------------
; mode withOUT lists and setq
    (dcl_Tree_AddParent spdrs_Haupt_tree "Kontakt hoch" "xx" 10 -1 10)
    (dcl_Tree_AddChild spdrs_Haupt_tree
        '(
            ("xx" "Öffner" "x1" 4 5)
            ("xx" "Öffner angezogen" "x2" 4 5)
        )
    )

Hi, Peter2,

try this:


(dcl_Tree_AddParent control "Parent" "ParentKey" 1 1 1)
(dcl-Tree-AddChild control (list (list "ParentKey" "Child1" "Child1Key" 1 1 1) (list "ParentKey" "Child2" "Child2Key" 1 1 1)
                                (list "Child1Key" "Child1_1" "Child1_1Key" 1 1 1) (list "Child2Key" "Child2_1" "Child2_1Key" 1 1 1)))


uParentItem is only used in German help ("u" from Hungary notation for usual for not strongly typed arguments).
The parent item value can be a handle of the parent. I've never used that since I had some troubles in ancient ObjectDCL.
I only used strings (AutoCAD entity handle (GC 5)) or even combinations of letters and database key (letters to divide between nodetypes).
I hope the sample above will answer your question or help a little bit.

Regards, Fred
Hi, me again.

Your sample

    (dcl_Tree_AddChild spdrs_Haupt_tree
        '(
            ("xx" "Öffner" "x1" 4 5)
            ("xx" "Öffner angezogen" "x2" 4 5)
        )
    )
uses quotes. I remember that somewhere was written, that the argument values should be evaluated before.
Regards, Fred
Hi Fred

thanks.

Your first post shows me that my first code, using the "setq-list-mode"
(setq P20 (dcl_Tree_AddParent spdrs_Haupt_tree "Betriebsartenstecker" 10 -1 10))
    (dcl_Tree_AddChild spdrs_Haupt_tree
        (list
            (list P20 "a child" 4 5)
is not able to use "Parent-IDs" and has another behaviour then the "quoted-mode".

Right?

author=Fred Tomke link=topic=2194.msg10995#msg10995 date=1415816275 wrote:
...Your sample...uses quotes. I remember that somewhere was written, that the argument values should be evaluated before....

?? Hmmm - what's the conclusion of this?
@ Peter2:
The English Help for dcl_Tree_AddChild is quite clear and answers all of your questions.

To add children to a child you have to either store the handle of the child (from the Help: The return value is the unique handle of the new item if only one child item is added) or supply the 'key' argument when you create the child (see Fred's example). This handle or key can then be used to create the child's children with a subsequent call to dcl_Tree_AddChild.

Your second example uses a list as well. And the fact that you can use use key strings instead of handles is mentioned in the Help: ParentItem [as Handle or String].

@ Fred:
I don't think there is anything to evaluate in the list of Peter2's second example. It can be used without any problem.
author=roy_043 link=topic=2194.msg11000#msg11000 date=1415818346 wrote:
@ Fred:
I don't think there is anything to evaluate in the list of Peter2's second example. It can be used without any problem.


Hi, I've just written what was mentioned in the past: quoted lists may lead into errors. Quoted lists are not evaluated in my memory, but I may be wrong.
If it works for you, then ignore my hint.

Fred
author=Peter2 link=topic=2194.msg10992#msg10992 date=1415808254 wrote:
...I'm sure it is simple, but I can not figure it out. Here is the working fragment with "Parent - Child", but I'm not able to create "Parent - Child - Child": ...

Looking back to my first question I would say my basic problem was to understand the hierarchy - ;"Is every entry which has a child also a parent?"

a) Parent - Parent -  Parent - Child
b) Parent - Child - Child - Child

Now I know that b) is correct, and maybe this hint could be added to the help-file.
Is every entry which has a child also a parent?
Yes.

I would say that c) is correct:
c) Parent -> Child/Parent -> Child/Parent -> Child
author=roy_043 link=topic=2194.msg11024#msg11024 date=1416227891 wrote:
I would say that c) is correct:
c) Parent -> Child/Parent -> Child/Parent -> Child


Yes - in the sense of genealogy, but you have to select between "dcl_Tree_AddChild/dcl_Tree_AddParent"  ;)
Maybe the dcl-Tree-AddParent method would be better named dcl-Tree-AddTopLevelParent.
author=owenwengerd link=topic=2194.msg11028#msg11028 date=1416239795 wrote:
Maybe the dcl-Tree-AddParent method would be better named dcl-Tree-AddTopLevelParent.

Or only "dcl-tree-AddTopLevel" without "parent" ..