• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. How to get item parent in a Tree?

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 14576
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to get item parent in a Tree?

MedAn
MedAn over 8 years ago

Hi all!

Could you pls. explain how to work with Tree?

For example I have created Tree and some items in it.

But if I try to get parent or treeItems - all time I have warnings: *WARNING* hiGetTree: bad tree item description.
On the forum I found how to get description, in this case we must use: eval(item)->description. But how we can get parent of item?
For example I want to see treeItems, I type: dprint(hiGetTreeItems(catTree))

and in result: 

*WARNING* hiGetTreeItems: bad tree description.
hiGetTreeItems(catTree) = nil

foreach(item selItems
   dprint(eval(item)->??)
   println(hiGetTree(item))
);

(eval(item)->??) = (_expandedSelectionIcon nil _expandedIcon nil _activeUT _description ("-----" "pcell DRC") _selectionIcon nil _labelIcon nil hiFieldSym backSubItem1)
*WARNING* hiGetTree: bad tree item description.

foreach(item selItems
println(hiGetTreeParent(item))
);

*WARNING* hiGetTreeParent: bad tree description.
nil

And the same situation with expand, by default all items in the tree are collapsed, I try to expand it  hiExpandTreeItem(item t); but without results

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 8 years ago

    You probably want to be using hiGetTreeItemParent rather than hiGetTreeParent - although you may need that too. You would start from the parent of the item, and this may return the parent tree, and then you might need to ge the parent of that to find the item above it. 

    See this modified version of my abTreeExample code (which I think is elsewhere on the forums) which I inserted an extra level of tree hierarchy. To use it, open a layout with a bunch of shapes and use:

    abTreeExample(geGetEditCellView()~>shapes)

    Then look in particular at the abTreeExampleSelectCB function to see what happens when you select something.

    It's rather hard to answer your specific question though without seeing your code.

    Regards,

    Andrew.

    /* abTreeExample.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Feb 16, 2010 
    Modified   
    By         
    
    Hacked to add in an extra level of hierarchy for investigating
    parents, and also some selection callbacks etc (that was added a while
    ago)
    ***************************************************
    
    SCCS Info: @(#) abTreeExample.il 02/16/10.11:37:50 1.1
    
    */
    
    /****************************************************************
    *                                                               *
    *                 (abCreateTreeExample shapes)                  *
    *                                                               *
    *    Given a list of db objects (e.g. shapes) create a tree     *
    * representation of the data in a form called abTreeExampleForm *
    *                                                               *
    ****************************************************************/
    
    (defun abCreateTreeExample (shapes)
      (let (tree subTreeLookup (shapeNum 1) objType bBox treeItem
                 select delete info subTree treeField extraTree extraTreeItem)
        ;--------------------------------------------------------------------
        ; Create a table to store the trees for each type of object encountered
        ;--------------------------------------------------------------------
        (setq subTreeLookup (makeTable 'subTreeLookup nil))
        ;--------------------------------------------------------------------
        ; Then traverse the shapes (doesn't have to just be shapes - any db object
        ; will do) and add an item for each
        ;--------------------------------------------------------------------
        (foreach shape shapes
                 (setq objType (dbGetq shape objType))
                 ;-----------------------------------------------------------
                 ; Find the existing tree, or create a new one
                 ;-----------------------------------------------------------
                 (setq subTree 
                       (or 
                         (arrayref subTreeLookup objType)
                         (setarray subTreeLookup objType
                                   (hiCreateTree (concat objType 'tree))
                                   )
                         ))
                 (setq bBox (dbGetq shape bBox))
                 ;-----------------------------------------------------------
                 ; Add an item to the appropriate shape tree for this
                 ; object
                 ;-----------------------------------------------------------
                 (setq extraTreeItem 
                       (hiCreateTreeItem (concat 'extraitem shapeNum)
                                         (list (sprintf nil "extra %d" shapeNum))))
                 (setq extraTree (hiCreateTree (concat 'extra shapeNum)))
                 (hiItemInsertTree extraTreeItem extraTree)
                 (hiTreeAppendItem subTree extraTreeItem)
                 (hiTreeAppendItem
                   extraTree
                   (hiCreateTreeItem (concat 'shape shapeNum)
                                     (list (sprintf nil "Shape %d" shapeNum)
                                           (dbGetq shape layerName)
                                           (dbGetq shape purpose)
                                           (xCoord (lowerLeft bBox))
                                           (yCoord (lowerLeft bBox))
                                           (xCoord (upperRight bBox))
                                           (yCoord (upperRight bBox))
                                           )
                                     ;(list "instance-add.png" 16 16)
                                     )
                   )
                 (postincrement shapeNum)
                 )
        ;--------------------------------------------------------------------
        ; Now create the main tree
        ;--------------------------------------------------------------------
        (setq tree (hiCreateTree 'shapes))
        (foreach shapeType subTreeLookup
                 (setq treeItem
                   (hiCreateTreeItem 
                     (concat shapeType)
                     (list shapeType)
                     )
                   )
                 (hiTreeAppendItem shapes treeItem)
                 (hiItemInsertTree treeItem (arrayref subTreeLookup shapeType))
                 )
        ;--------------------------------------------------------------------
        ; And the tree field itself
        ;--------------------------------------------------------------------
        (setq treeField
              (hiCreateTreeTable
                ?name 'treeField
                ?title "Shapes"
                ?titleAlignment 'center
                ?callback 'abTreeExampleSelectCB
                ?expandCallback "abTreeExampleExpandCB"
                ?headers (list
                           (list "Type" 125 'left 'string t)
                           (list "Layer" 80 'left 'string t)
                           (list "Purpose" 80 'left 'string t)
                           (list "LLX" 80 'left 'float t)
                           (list "LLY" 80 'left 'float t)
                           (list "URX" 80 'left 'float t)
                           (list "URY" 80 'left 'float t)
                           )
                ?choice tree
                )
              )
        ;--------------------------------------------------------------------
        ; Now create the context menu
        ;--------------------------------------------------------------------
        (setq select
              (hiCreateMenuItem
                ?name 'select
                ?itemText "Select"
                )
              )
        (setq delete
              (hiCreateMenuItem
                ?name 'delete
                ?itemText "Delete"
                )
              )
        (setq info
              (hiCreateMenuItem
                ?name 'info
                ?itemText "Delete"
                )
              )
        (hiCreateMenu
          'abTreeExampleMenu
          "Tree Item"
          (list select delete info)
          )
        ;--------------------------------------------------------------------
        ; Attach the context menu to the field
        ;--------------------------------------------------------------------
        (putpropq treeField abTreeExampleMenu hiContextMenu)
        (putpropq treeField 'abTreeExampleMenuContextCB hiShowContextMenuCallback)
        ;--------------------------------------------------------------------
        ; Then finally create the form
        ;--------------------------------------------------------------------
        (hiCreateAppForm
          ?name 'abTreeExampleForm
          ?formTitle "Tree Example"
          ?fields (list
                    (list treeField 5:5 610:400 20)
                    )
          ?initialSize 620:420
          ?attachmentList (list
                            hicLeftPositionSet|hicRightPositionSet|
                            hicTopPositionSet|hicBottomPositionSet
                            )
          ) ; hiCreateAppForm
        (putpropq (getq abTreeExampleForm treeField) 
            'abTreeExampleDoubleCB hiDoubleClickCallback)
        abTreeExampleForm
        ) ; let
      ) ; defun abCreateTreeExampleForm
    
    /***************************************************************
    *                                                              *
    *      (abTreeExampleMenuContextCB menu form field item)       *
    *                                                              *
    *                Callback for the context menu                 *
    *                                                              *
    ***************************************************************/
    
    (defun abTreeExampleMenuContextCB (menu form field item)
      (printf "Context Menu called: %L %L %L %L\n"
              menu form field item)
      (printf "Value of tree is %L\n"
              (getq (get form field) value))
      )
    
    /***************************************************************
    *                                                              *
    *                   (abTreeExample objects)                    *
    *                                                              *
    *                       Main entry point                       *
    *                                                              *
    ***************************************************************/
    
    (defun abTreeExample (objects)
      (abCreateTreeExample objects)
      (hiInstantiateForm abTreeExampleForm)
      (foreach treeItem (hiGetTreeItems (getq (getq abTreeExampleForm treeField) choice))
          (hiExpandTreeItem treeItem t)
          )
      (hiDisplayForm abTreeExampleForm)
      )
    
    (defun abTreeExampleSelectCB (@rest args)
      (printf "Callback called with these arguments: %L\n" args)
      (printf "Called, %d objects\n" length(abTreeExampleForm->treeField->value))
      (let (parentTrees parentTreeStruct parentItems parentItemStruct
                        itemStruct)
        (foreach item (cadr args)
          (setq itemStruct (eval item))
          (setq parentTrees (hiGetTreeItemParent itemStruct))
          ; these will be the parent trees (not tree items)
          (foreach parentTree parentTrees
                   ;---------------------------------------------------------
                   ; The top level items report a parentTree, but it's not
                   ; bound to a variable. However, this wouldn't be very useful
                   ; anyway, since there's no item above it (just the tree table
                   ; field itself). Could get that via the first arg to the callback
                   ; and go to hiGetCurrentForm()->treeField->choice
                   ;---------------------------------------------------------
                   (when (boundp parentTree)
                     (setq parentTreeStruct (eval parentTree))
                     (setq parentItems (hiGetTreeParent parentTreeStruct))
                     (foreach parentItem parentItems
                              (setq parentItemStruct (eval parentItem))
                              (printf "Parent item is %L, description %L\n"
                                      parentItem 
                                      (hiGetTreeItemDescription parentItemStruct)
                                      )
                              (hiSetTreeItemDescription 
                                parentItemStruct
                                (list (strcat "modified " (getCurrentTime)))
                                )
                              )
                     )
                   )
          )
        )
      )
    
      (defun abTreeExampleDoubleCB (@rest args)
        (printf "Double Callback called with these arguments: %L\n" args)
        (printf "Called, %d objects\n" length(abTreeExampleForm->treeField->value))
        hiRegTimer(sprintf(nil "(hiExpandTreeItem '%s nil)" (caddr args)) 1)
        )
    
    
    (defun abTreeExampleExpandCB (@rest args)
      (printf "Expand Callback called with these arguments: %L\n" args)
      )
    
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 8 years ago

    You probably want to be using hiGetTreeItemParent rather than hiGetTreeParent - although you may need that too. You would start from the parent of the item, and this may return the parent tree, and then you might need to ge the parent of that to find the item above it. 

    See this modified version of my abTreeExample code (which I think is elsewhere on the forums) which I inserted an extra level of tree hierarchy. To use it, open a layout with a bunch of shapes and use:

    abTreeExample(geGetEditCellView()~>shapes)

    Then look in particular at the abTreeExampleSelectCB function to see what happens when you select something.

    It's rather hard to answer your specific question though without seeing your code.

    Regards,

    Andrew.

    /* abTreeExample.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Feb 16, 2010 
    Modified   
    By         
    
    Hacked to add in an extra level of hierarchy for investigating
    parents, and also some selection callbacks etc (that was added a while
    ago)
    ***************************************************
    
    SCCS Info: @(#) abTreeExample.il 02/16/10.11:37:50 1.1
    
    */
    
    /****************************************************************
    *                                                               *
    *                 (abCreateTreeExample shapes)                  *
    *                                                               *
    *    Given a list of db objects (e.g. shapes) create a tree     *
    * representation of the data in a form called abTreeExampleForm *
    *                                                               *
    ****************************************************************/
    
    (defun abCreateTreeExample (shapes)
      (let (tree subTreeLookup (shapeNum 1) objType bBox treeItem
                 select delete info subTree treeField extraTree extraTreeItem)
        ;--------------------------------------------------------------------
        ; Create a table to store the trees for each type of object encountered
        ;--------------------------------------------------------------------
        (setq subTreeLookup (makeTable 'subTreeLookup nil))
        ;--------------------------------------------------------------------
        ; Then traverse the shapes (doesn't have to just be shapes - any db object
        ; will do) and add an item for each
        ;--------------------------------------------------------------------
        (foreach shape shapes
                 (setq objType (dbGetq shape objType))
                 ;-----------------------------------------------------------
                 ; Find the existing tree, or create a new one
                 ;-----------------------------------------------------------
                 (setq subTree 
                       (or 
                         (arrayref subTreeLookup objType)
                         (setarray subTreeLookup objType
                                   (hiCreateTree (concat objType 'tree))
                                   )
                         ))
                 (setq bBox (dbGetq shape bBox))
                 ;-----------------------------------------------------------
                 ; Add an item to the appropriate shape tree for this
                 ; object
                 ;-----------------------------------------------------------
                 (setq extraTreeItem 
                       (hiCreateTreeItem (concat 'extraitem shapeNum)
                                         (list (sprintf nil "extra %d" shapeNum))))
                 (setq extraTree (hiCreateTree (concat 'extra shapeNum)))
                 (hiItemInsertTree extraTreeItem extraTree)
                 (hiTreeAppendItem subTree extraTreeItem)
                 (hiTreeAppendItem
                   extraTree
                   (hiCreateTreeItem (concat 'shape shapeNum)
                                     (list (sprintf nil "Shape %d" shapeNum)
                                           (dbGetq shape layerName)
                                           (dbGetq shape purpose)
                                           (xCoord (lowerLeft bBox))
                                           (yCoord (lowerLeft bBox))
                                           (xCoord (upperRight bBox))
                                           (yCoord (upperRight bBox))
                                           )
                                     ;(list "instance-add.png" 16 16)
                                     )
                   )
                 (postincrement shapeNum)
                 )
        ;--------------------------------------------------------------------
        ; Now create the main tree
        ;--------------------------------------------------------------------
        (setq tree (hiCreateTree 'shapes))
        (foreach shapeType subTreeLookup
                 (setq treeItem
                   (hiCreateTreeItem 
                     (concat shapeType)
                     (list shapeType)
                     )
                   )
                 (hiTreeAppendItem shapes treeItem)
                 (hiItemInsertTree treeItem (arrayref subTreeLookup shapeType))
                 )
        ;--------------------------------------------------------------------
        ; And the tree field itself
        ;--------------------------------------------------------------------
        (setq treeField
              (hiCreateTreeTable
                ?name 'treeField
                ?title "Shapes"
                ?titleAlignment 'center
                ?callback 'abTreeExampleSelectCB
                ?expandCallback "abTreeExampleExpandCB"
                ?headers (list
                           (list "Type" 125 'left 'string t)
                           (list "Layer" 80 'left 'string t)
                           (list "Purpose" 80 'left 'string t)
                           (list "LLX" 80 'left 'float t)
                           (list "LLY" 80 'left 'float t)
                           (list "URX" 80 'left 'float t)
                           (list "URY" 80 'left 'float t)
                           )
                ?choice tree
                )
              )
        ;--------------------------------------------------------------------
        ; Now create the context menu
        ;--------------------------------------------------------------------
        (setq select
              (hiCreateMenuItem
                ?name 'select
                ?itemText "Select"
                )
              )
        (setq delete
              (hiCreateMenuItem
                ?name 'delete
                ?itemText "Delete"
                )
              )
        (setq info
              (hiCreateMenuItem
                ?name 'info
                ?itemText "Delete"
                )
              )
        (hiCreateMenu
          'abTreeExampleMenu
          "Tree Item"
          (list select delete info)
          )
        ;--------------------------------------------------------------------
        ; Attach the context menu to the field
        ;--------------------------------------------------------------------
        (putpropq treeField abTreeExampleMenu hiContextMenu)
        (putpropq treeField 'abTreeExampleMenuContextCB hiShowContextMenuCallback)
        ;--------------------------------------------------------------------
        ; Then finally create the form
        ;--------------------------------------------------------------------
        (hiCreateAppForm
          ?name 'abTreeExampleForm
          ?formTitle "Tree Example"
          ?fields (list
                    (list treeField 5:5 610:400 20)
                    )
          ?initialSize 620:420
          ?attachmentList (list
                            hicLeftPositionSet|hicRightPositionSet|
                            hicTopPositionSet|hicBottomPositionSet
                            )
          ) ; hiCreateAppForm
        (putpropq (getq abTreeExampleForm treeField) 
            'abTreeExampleDoubleCB hiDoubleClickCallback)
        abTreeExampleForm
        ) ; let
      ) ; defun abCreateTreeExampleForm
    
    /***************************************************************
    *                                                              *
    *      (abTreeExampleMenuContextCB menu form field item)       *
    *                                                              *
    *                Callback for the context menu                 *
    *                                                              *
    ***************************************************************/
    
    (defun abTreeExampleMenuContextCB (menu form field item)
      (printf "Context Menu called: %L %L %L %L\n"
              menu form field item)
      (printf "Value of tree is %L\n"
              (getq (get form field) value))
      )
    
    /***************************************************************
    *                                                              *
    *                   (abTreeExample objects)                    *
    *                                                              *
    *                       Main entry point                       *
    *                                                              *
    ***************************************************************/
    
    (defun abTreeExample (objects)
      (abCreateTreeExample objects)
      (hiInstantiateForm abTreeExampleForm)
      (foreach treeItem (hiGetTreeItems (getq (getq abTreeExampleForm treeField) choice))
          (hiExpandTreeItem treeItem t)
          )
      (hiDisplayForm abTreeExampleForm)
      )
    
    (defun abTreeExampleSelectCB (@rest args)
      (printf "Callback called with these arguments: %L\n" args)
      (printf "Called, %d objects\n" length(abTreeExampleForm->treeField->value))
      (let (parentTrees parentTreeStruct parentItems parentItemStruct
                        itemStruct)
        (foreach item (cadr args)
          (setq itemStruct (eval item))
          (setq parentTrees (hiGetTreeItemParent itemStruct))
          ; these will be the parent trees (not tree items)
          (foreach parentTree parentTrees
                   ;---------------------------------------------------------
                   ; The top level items report a parentTree, but it's not
                   ; bound to a variable. However, this wouldn't be very useful
                   ; anyway, since there's no item above it (just the tree table
                   ; field itself). Could get that via the first arg to the callback
                   ; and go to hiGetCurrentForm()->treeField->choice
                   ;---------------------------------------------------------
                   (when (boundp parentTree)
                     (setq parentTreeStruct (eval parentTree))
                     (setq parentItems (hiGetTreeParent parentTreeStruct))
                     (foreach parentItem parentItems
                              (setq parentItemStruct (eval parentItem))
                              (printf "Parent item is %L, description %L\n"
                                      parentItem 
                                      (hiGetTreeItemDescription parentItemStruct)
                                      )
                              (hiSetTreeItemDescription 
                                parentItemStruct
                                (list (strcat "modified " (getCurrentTime)))
                                )
                              )
                     )
                   )
          )
        )
      )
    
      (defun abTreeExampleDoubleCB (@rest args)
        (printf "Double Callback called with these arguments: %L\n" args)
        (printf "Called, %d objects\n" length(abTreeExampleForm->treeField->value))
        hiRegTimer(sprintf(nil "(hiExpandTreeItem '%s nil)" (caddr args)) 1)
        )
    
    
    (defun abTreeExampleExpandCB (@rest args)
      (printf "Expand Callback called with these arguments: %L\n" args)
      )
    
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information