home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / cad / cadence / 594 < prev    next >
Encoding:
Text File  |  1993-01-22  |  18.3 KB  |  704 lines

  1. Newsgroups: comp.cad.cadence
  2. Path: sparky!uunet!Cadence.COM!keiths
  3. From: keiths@Cadence.COM (Keith Sabine)
  4. Subject: Re: getting all cellviews
  5. Message-ID: <1993Jan22.084731.23928@Cadence.COM>
  6. Sender: Keith Sabine
  7. Organization: Cadence Design Systems, Inc.
  8. References: <1993Jan12.172646.14372@venus.ic.cmc.ca> <1993Jan12.231425.15484@analog.com> <1993Jan13.154724.22700@venus.ic.cmc.ca>
  9. Distribution: can
  10. Date: Fri, 22 Jan 1993 08:47:31 GMT
  11. Lines: 691
  12.  
  13. It's often difficult to find your way around the database in skill,
  14. so here's a handy little skill utility to browse through just about
  15. anything  - lists, defstructs, database objects etc. Just load it
  16. and either invoke with a cellview in the current window or call it
  17. directly with the object you want to browse e.g. a database object.
  18. It brings up a browser window, clicking with the left button expands 
  19. an object, clicking with the right button unexpands the object, 
  20. clicking with the middle button gives you some other options.
  21. Happy hacking!
  22.  
  23. Keith.
  24.  
  25.  
  26.  
  27. ;----------------------------------------------------------------------------;
  28.  
  29. /*
  30. Function     : dataBrowser.il
  31. Title        : A database browser
  32. Author        : Keith Sabine [Cadence Bracknell UK]
  33.           With additions by Ian Dobinson [Cadence Consulting, Abingdon]
  34. Date        : 21th October 1992
  35. Revision    : 1.3
  36. SW release    : 4.2.1
  37. Prerequesites    : none
  38. Synopsis    : This functionality allows graphical viewing of the 
  39.           properties and attributes of SKILL objects.
  40.  
  41. User's guide    : none
  42. Description    : Load this file and type 'brDataBrowser'. You need to have
  43.         : a cellview open in the current window. Alternatively,
  44.         : type 'brDataBrowser(cv)' where cv is a database pointer
  45.         : to a cellview, or a design management object, or a list.
  46. */
  47.  
  48.  
  49. /*
  50.  * Global variables controling whether values of leaf cell objects
  51.  * are displayed on the browser.
  52.  */
  53. brShowValues = t
  54.  
  55. /*
  56.  * Create the menus for the browser.
  57.  */
  58. hiCreateMenu('brMenu "Commands"
  59.  
  60.     list(
  61.     ; Close Browser.
  62.     hiCreateMenuItem(
  63.         ?name 'closeHandle
  64.         ?itemText "Close browser"
  65.         ?callback "brCloseBrowser()"
  66.     )
  67.  
  68.     ; Centre the browser in the window.
  69.     hiCreateMenuItem(
  70.         ?name 'centreHandle
  71.         ?itemText "Centre"
  72.         ?callback "brCentre(dagGetCurrentTool())"
  73.     )
  74.  
  75.     ; Switch on
  76.     brClearValuesMenuItem = hiCreateMenuItem(
  77.         ?name 'noShowValues
  78.         ?itemText "Don't Show Values"
  79.         ?callback "brClearShowValues()"
  80.     )
  81.     )
  82. )
  83.  
  84. brShowValuesMenuItem = hiCreateMenuItem(
  85.         ?name 'showValues
  86.         ?itemText "Show Values"
  87.         ?callback "brSetShowValues()"
  88.     )
  89.  
  90.  
  91. /*******************************************************************************
  92.  * brCloseBrowser()
  93.  *
  94.  * Close down the browser.
  95.  * Callback for the close function on the top level menu.
  96.  ******************************************************************************/
  97. procedure( brCloseBrowser()
  98.  
  99.     hiCloseWindow(dagGetCurrentTool()->window)
  100.  
  101. ) ; end procedure brCloseBrowser
  102.  
  103.  
  104. /*******************************************************************************
  105.  * brSetShowValues()
  106.  *
  107.  * Set the global controlling showing of leaf cell values, and then
  108.  * swap the menus on the command menu.
  109.  ******************************************************************************/
  110. procedure( brSetShowValues()
  111.  
  112.     brShowValues = t
  113.     hiDeleteMenuItem(brMenu 'showValues)
  114.     hiAddMenuItem(brMenu brClearValuesMenuItem)
  115.  
  116. ) ; end procedure brSetShowValues
  117.  
  118.  
  119. /*******************************************************************************
  120.  * brClearShowValues()
  121.  *
  122.  * Clear the global controlling showing of leaf cell values, and then
  123.  * swap the menus on the command menu.
  124.  ******************************************************************************/
  125. procedure( brClearShowValues()
  126.  
  127.     brShowValues = nil
  128.     hiDeleteMenuItem(brMenu 'noShowValues)
  129.     hiAddMenuItem(brMenu brShowValuesMenuItem)
  130.  
  131. ) ; end procedure brClearShowValues
  132.  
  133.  
  134. /*******************************************************************************
  135.  * brPrintAttributes(node)
  136.  *
  137.  * Print attributes of a node
  138.  ******************************************************************************/
  139. procedure(brPrintAttributes(node)
  140.  
  141.     let( (obj attribs)
  142.  
  143.     obj = node->obj
  144.     cond(
  145.  
  146.         (!obj
  147.             printf("nil\n")
  148.         )
  149.  
  150.         (dbobjectp(obj)
  151.  
  152.             printf("\n%s--------------------------------------\n"
  153.                "------------------------------------------")
  154.             printf("\nattributes of %s:\n\n" brGetDBName(obj))
  155.             attribs = cdr(obj~>??)
  156.         while(attribs
  157.             printf("%-32s : " car(attribs))
  158.             print(cadr(attribs))
  159.             printf("\n")
  160.             attribs = cddr(attribs)
  161.         )
  162.             printf("\n%s--------------------------------------\n"
  163.                "------------------------------------------")
  164.  
  165.         )
  166.  
  167.         (t
  168.         printf("Sorry - not a database object (%L)." typep(obj))
  169.         )
  170.  
  171.     ) ; end cond
  172.  
  173.     ) ; end let
  174.  
  175. ) ; end procedure brPrintAttributes
  176.  
  177.  
  178. /*******************************************************************************
  179.  * brPrintProperties(node)
  180.  *
  181.  * print properties of a node
  182.  ******************************************************************************/
  183. procedure(printProperties(node)
  184.  
  185.     let( (obj)
  186.  
  187.     obj = node->obj
  188.     if(dbobjectp(obj) then
  189.         printf("\n%s--------------------------------------\n"
  190.            "------------------------------------------")
  191.         printf("\nproperties of %s:\n\n" obj~>objType)
  192.         foreach(prop obj~>prop
  193.         printf("%-32s :  " prop~>name)
  194.         print(prop~>value)
  195.         printf("  (%s)\n" prop~>valueType)
  196.         )
  197.         printf("\n%s--------------------------------------\n"
  198.            "------------------------------------------")
  199.     else
  200.         printf("Sorry - not a database object\n")
  201.     )
  202.  
  203.     ) ; end let
  204.  
  205. ) ; end procedure printProperties
  206.  
  207.  
  208. /*******************************************************************************
  209.  * brEditProps(node)
  210.  *
  211.  * Edit properties of a node.
  212.  ******************************************************************************/
  213. procedure(brEditProps(node)
  214.  
  215.     if(dbobjectp(node->obj)
  216.         hiEditPropList(node->obj)
  217.     ; else
  218.     printf("Sorry - can only edit properties of a database object.\n")
  219.     )
  220.  
  221. ) ; end procedure brEditProps
  222.  
  223.  
  224. /*******************************************************************************
  225.  * brShowValue(node)
  226.  *
  227.  * Show value associated with a leaf node.
  228.  ******************************************************************************/
  229. procedure( brShowValue(node)
  230.  
  231.     printf("Value is: %L\n" node->obj)
  232.  
  233. ) ; end brShowValue
  234.  
  235.  
  236. /*******************************************************************************
  237.  * brExpandObjNew(startNode)
  238.  *
  239.  * Expand a node into a new browser.
  240.  ******************************************************************************/
  241. procedure( brExpandObjNew(startNode)
  242.  
  243.     brDataBrowser(startNode->obj startNode->name)
  244.  
  245. ) ; end procedure brExpandObjNew
  246.  
  247.  
  248. /*******************************************************************************
  249.  * beUnexpandNode(startNode)
  250.  *
  251.  * Unexpand node
  252.  ******************************************************************************/
  253. procedure( beUnexpandNode(startNode)
  254.  
  255.     mapc('dagDestroyNode startNode->childObjects)
  256.  
  257. ) ; end beUnexpandNode
  258.  
  259.  
  260. /*******************************************************************************
  261.  * brDeleteObject(node)
  262.  *
  263.  * Attempt to delete the given object.
  264.  ******************************************************************************/
  265. procedure(brDeleteObject(node)
  266.  
  267.     when( hiDisplayModalDBox( 'brBox
  268.             "Deleting a database object"
  269.             "Do you REALLY want to do this?"
  270.             "" "" )
  271.  
  272.     printf("Deleting object type %L " node->obj~>objType)
  273.     cond(
  274.  
  275.         (node->obj~>cellName
  276.             printf("%s" node->obj~>cellName)
  277.         )
  278.  
  279.         (node->obj~>name
  280.         printf("%s" node->obj~>name)
  281.         )
  282.  
  283.     ) ; end cond
  284.  
  285.     printf("\n")
  286.  
  287.     ; Try to delete the object.
  288.     if(errset(dbDeleteObject(node->obj)) then
  289.  
  290.         /* Delete the children from the display. */
  291.         foreach( child node->childObjects
  292.             dagDestroyNode(child)
  293.         )
  294.  
  295.         /* Delete the node itself. */
  296.         dagDestroyNode(node)
  297.  
  298.     else
  299.  
  300.         printf("Sorry - could not delete this object.\n")
  301.  
  302.     ) ; end i
  303.  
  304.     ) ; end when
  305.  
  306. ) ; end procedure brDeleteObject
  307.  
  308.  
  309. /*******************************************************************************
  310.  * brExpandNode(startNode)
  311.  *
  312.  * Expand node into objects
  313.  ******************************************************************************/
  314. procedure( brExpandNode(startNode )
  315.     let( (obj node entries names name count)
  316.  
  317.     ; go through list of objects and create their nodes
  318.     ; first destroy any child nodes...
  319.  
  320.       foreach( child startNode->childObjects
  321.             dagDestroyNode(child)
  322.       )
  323.  
  324.      obj = startNode->obj
  325.  
  326.     when(startNode->expandable
  327.         ; Expand the object into names and values.
  328.         entries = brExpandObject(obj)
  329.         count = 1
  330.     
  331.         ; Convert the values into nodes.
  332.         foreach(entry entries
  333.  
  334.         ; If we have already had the name in this expansion, then
  335.         ; we prefix it with a count, otherwise actions will be applied
  336.         ; to the wrong object.
  337.         name = car(entry)
  338.         when(member(name names)
  339.             name = sprintf(nil "%d_%s" count++ name)
  340.         )
  341.         names = cons(name names)
  342.     
  343.         ; Create the node.
  344.         node = dagCreateNode(name 
  345.             cond( (dbobjectp(cadr(entry)) brDBObjectClass)
  346.               (caddr(entry) brObjectClass)
  347.               (t brNonExpandObjectClass)))
  348.         node->obj = cadr(entry)
  349.         node->expandable = caddr(entry)
  350.  
  351.         ; Set the colour.
  352.         if(dbobjectp(cadr(entry))
  353.             node->textColor = brRedColor
  354.         ; else
  355.         if(caddr(entry)
  356.             node->textColor = brBlueColor
  357.         ; else
  358.             node->textColor = brBlackColor
  359.         ))
  360.  
  361.         ; Link the node to its parent.
  362.         dagLinkParentToChild(startNode node)
  363.     
  364.         ) ; end foreach 
  365.  
  366.     ) ; end when
  367.     
  368.     ) ; end let
  369.  
  370. ) ; end procedure brExpandNode
  371.  
  372.  
  373. /*******************************************************************************
  374.  * beExpandObject(val)
  375.  *
  376.  * Expand a general object, according to its type.
  377.  ******************************************************************************/
  378. procedure( brExpandObject(val)
  379.  
  380.     caseq(typep(val)
  381.  
  382.     (dbobject brExpandDBObject(val))
  383.  
  384.     (list brExpandList(val))
  385.  
  386.     ((wtype other) brExpandUserType(val))
  387.  
  388.     (array brExpandArray(val))
  389.  
  390.     (t
  391.         when(defstructp(val)
  392.         brExpandUserType(val)
  393.         )
  394.     )
  395.  
  396.     ) ; end caseq
  397.  
  398. ) ; end procedure brExpandObject
  399.  
  400.  
  401. /*******************************************************************************
  402.  * beExpandCBObject(dbId)->expansionList
  403.  *
  404.  * Convert a db object into its expansion entries.
  405.  ******************************************************************************/
  406. procedure(brExpandDBObject(dbId)
  407.  
  408.     let( (objList objNames)
  409.  
  410.     objList = cdr(dbId~>??)
  411.     /* Convert to an assoc type list. */
  412.     while(objList
  413.         if(brExpandable(cadr(objList))
  414.             objNames = cons(list(get_pname(car(objList))
  415.                  cadr(objList)
  416.                  t) objNames)
  417.         ; else
  418.         objNames = cons(list(sprintf(nil "%s %s %L" 
  419.                     get_pname(car(objList)) 
  420.                     if(brShowValues "-" "")
  421.                     if(brShowValues cadr(objList) ""))
  422.                 cadr(objList) nil) objNames)
  423.         )
  424.         objList = cddr(objList)
  425.     )
  426.  
  427.     objNames
  428.  
  429.     ) ; end let
  430.  
  431. ) ; end procedure brExpandDBObject
  432.  
  433.  
  434. /*******************************************************************************
  435.  * beExpandList(list)
  436.  *
  437.  * Expand list into nodes
  438.  ******************************************************************************/
  439. procedure( brExpandList( list )
  440.  
  441.     /* Take each element, get a name, and whether expandable, and
  442.        build the result list.
  443.     */
  444.     foreach(mapcar element list
  445.     list(brGetName(element) element brExpandable(element))
  446.     )
  447.  
  448. ) ; end procedure brExpandList
  449.  
  450.  
  451. /*******************************************************************************
  452.  * beExpandArray(arr)
  453.  *
  454.  * Expand list into nodes
  455.  ******************************************************************************/
  456. procedure( brExpandArray( arr )
  457.  
  458.     let( (res val)
  459.  
  460.     for(i 0 length(arr)-1
  461.         unless((val = arrayref(arr i)) == 'unbound
  462.         res = cons(list(sprintf(nil "%d - %L" i brGetName(val)) 
  463.                     val brExpandable(val)) 
  464.                res)
  465.         )
  466.     )
  467.  
  468.     reverse(res)
  469.  
  470.     ) ; end let
  471.  
  472. ) ; end procedure brExpandArray
  473.  
  474.  
  475. /*******************************************************************************
  476.  * brExpandUserType(obj)->expansionList
  477.  *
  478.  * Expand a 'user type', such as a window, menu, or defstruct type object.
  479.  * This means picking objects from the ->?? structure.
  480.  ******************************************************************************/
  481. procedure(brExpandUserType(dbId)
  482.  
  483.     let( (objList objNames)
  484.  
  485.     if(typep(objList) == 'wtype
  486.         objList = plist(dbId)
  487.     ; else
  488.         objList = dbId->??
  489.     )
  490.     /* Convert to an assoc type list. */
  491.     while(objList
  492.         if(brExpandable(cadr(objList))
  493.             objNames = cons(list(get_pname(car(objList))
  494.                  cadr(objList)
  495.                  t) objNames)
  496.         ; else
  497.         objNames = cons(list(sprintf(nil "%s %s %L" 
  498.                     get_pname(car(objList)) 
  499.                     if(brShowValues "-" "")
  500.                     if(brShowValues cadr(objList) ""))
  501.                 cadr(objList) nil) objNames)
  502.         )
  503.         objList = cddr(objList)
  504.     )
  505.  
  506.     objNames
  507.  
  508.     ) ; end let
  509.  
  510. ) ; end procedure brExpandUserType
  511.  
  512.  
  513. /*******************************************************************************
  514.  * brDataBrowser([d_cv] [t_rootName])
  515.  *
  516.  * Main entry point to the browser.
  517.  * The arguments are both optional, and are the object to expand, and the
  518.  * name to use for the top level object. The later is used when expanding
  519.  * an object into a new browser, and is not expected to be used by the
  520.  * user.
  521.  ******************************************************************************/
  522. procedure( brDataBrowser(@optional cv rootName)
  523. let( (rootNode firstNode browser expandable dbObj)
  524.  
  525.     unless(cv
  526.     cv = hiGetCurrentWindow()->cellView
  527.     )
  528.  
  529.     unless(boundp('brObjectClass) && brObjectClass
  530.  
  531.     ; create brObjectClass, used for display of objects
  532.     brObjectClass = dagCreateClass("brObjectClass")
  533.     
  534.     ; valid actions for obj...
  535.     dagAddActionToObject( '("expand object" "brExpandNode" 
  536.                 "dagGetCurrentObject()" "mouseLeft" t) 
  537.                 brObjectClass)
  538.     dagAddActionToObject( '("unexpand object" "beUnexpandNode"
  539.                 "dagGetCurrentObject()" "mouseRight" t) 
  540.                 brObjectClass)
  541.     dagAddActionToObject( '("expand to new browser" "brExpandObjNew"
  542.                 "dagGetCurrentObject()" "mouseRight" t) 
  543.                 brObjectClass)
  544.  
  545.     brDBObjectClass = dagCreateClass("brDBObjectClass")
  546.     ; valid actions for obj...
  547.     dagAddActionToObject( '("expand object" "brExpandNode" 
  548.                 "dagGetCurrentObject()" "mouseLeft" t) 
  549.                 brDBObjectClass)
  550.     dagAddActionToObject( '("unexpand object" "beUnexpandNode"
  551.                 "dagGetCurrentObject()" "mouseRight" t) 
  552.                 brDBObjectClass)
  553.     dagAddActionToObject( '("expand to new browser" "brExpandObjNew"
  554.                 "dagGetCurrentObject()" "mouseRight" t) 
  555.                 brDBObjectClass)
  556.     dagAddActionToObject( '("show attributes" "brPrintAttributes" 
  557.                 "dagGetCurrentObject()" "" t) brDBObjectClass)
  558.     dagAddActionToObject( '("show properties" "printProperties" 
  559.                 "dagGetCurrentObject()" "" t) brDBObjectClass)
  560.     dagAddActionToObject( '("edit properties" "brEditProps" 
  561.                 "dagGetCurrentObject()" "" t) brDBObjectClass)
  562.     dagAddActionToObject( '("delete" "brDeleteObject" 
  563.                 "dagGetCurrentObject()" "" t) brDBObjectClass)
  564.  
  565.     brNonExpandObjectClass = dagCreateClass("brNonExpandObjectClass")
  566.     dagAddActionToObject( '("Show Value" "brShowValue" 
  567.                 "dagGetCurrentObject()" "mouseLeft" t) 
  568.                 brNonExpandObjectClass)
  569.  
  570.         ; Set up colors.
  571.         brRedColor   = hiMatchColorByName("red")
  572.         brBlackColor = hiMatchColorByName("black")
  573.         brBlueColor = hiMatchColorByName("blue")
  574.  
  575.     ) ; end unless
  576.     
  577.     ; now setup root node, doesn't matter which class.
  578.     firstNode = dagCreateNode("" brObjectClass)
  579.  
  580.     ; set the value
  581.     firstNode->obj = cv
  582.  
  583.     ; open the browser, same size as library browser...
  584.     browser = dagOpenTool( hiMatchColorByName("white") list(200:200 500:700) 
  585.              firstNode "database browser" "help")
  586.     browser->horizontal = t
  587.     browser->textOnly = t
  588.     browser->showLabels = t
  589.     browser->labelJustification = 'centerLeft
  590.     browser->scaleToFit = nil
  591.     browser->anchorObject = firstNode
  592.     browser->rootNode = firstNode
  593.     browser->anchorTo = 'centerLeft
  594.     browser->placer = dagFindPlacer("versionPlacer")
  595.     unless(rootName rootName = brGetName(cv))
  596.  
  597.     expandable = brExpandable(cv)
  598.     dbObj = dbobjectp(cv)
  599.     rootNode = dagCreateNode(rootName 
  600.         cond( (dbObj brDBObjectClass) (expandable brObjectClass)
  601.             (t brNonExpandObjectClass)))
  602.     dagLinkParentToChild( firstNode rootNode)          
  603.     rootNode->obj = cv  
  604.     firstNode->invisible = t  
  605.     rootNode->expandable = expandable                            
  606.     rootNode->textColor = if(dbObj brRedColor 
  607.                   if(expandable brBlueColor brBlackColor))
  608.  
  609.     ; redraw the browser with the above options...
  610.     dagDisplayTool(browser)
  611.  
  612.     hiInsertBannerMenu(browser->window 'brMenu 0)
  613.  
  614. )) ; end procedure brDataBrowser
  615.  
  616.  
  617. /*******************************************************************************
  618.  * brGetName(obj)->name
  619.  *
  620.  * Get a name for an object.
  621.  ******************************************************************************/
  622. procedure(brGetName(obj)
  623.  
  624.     caseq(typep(obj)
  625.  
  626.         (dbobject
  627.         sprintf(nil "%s" brGetDBName(obj))
  628.     )
  629.  
  630.     (string
  631.         sprintf(nil "'%s'" obj)
  632.     )
  633.  
  634.     (wtype
  635.         sprintf(nil "window %d" obj->windowNum)
  636.     )
  637.  
  638.     (list
  639.         "<list>"
  640.     )
  641.  
  642.     (t
  643.         sprintf(nil "<%L> %L" typep(obj) if(brShowValues obj ""))
  644.     )
  645.  
  646.     ) ; end caseq
  647.  
  648. ) ; end procedure brGetName
  649.  
  650.  
  651. /*******************************************************************************
  652.  * brGetDBName(obj)->name
  653.  *
  654.  * Get the name of a db object.
  655.  ******************************************************************************/
  656. procedure( brGetDBName(obj)
  657.  
  658.     case(obj~>objType
  659.  
  660.     ("cellView" sprintf(nil "(cv) %s %s" obj~>cellName obj~>viewName))
  661.  
  662.     (("lib" "cell" "view" "prop") 
  663.         sprintf(nil "(%s) %L " obj~>objType obj~>name))
  664.  
  665.     ("cellview" sprintf(nil "(cv) %s %s" obj~>cell~>name obj~>view~>name))
  666.  
  667.     ("version" sprintf(nil "(v) %L.%L" obj~>primaryIndex
  668.                 obj~>secondaryIndex))
  669.  
  670.     ("LP" sprintf(nil "%s %s" obj~>layerName obj~>purpose))
  671.  
  672.     (t obj~>name || "<>")
  673.  
  674.     ) ; end case
  675.  
  676. ) ; end procedure brGetDBName
  677.  
  678.  
  679. /*******************************************************************************
  680.  * brExpandable(obj)->t/nil
  681.  *
  682.  * Whether an object type is expandable.
  683.  ******************************************************************************/
  684. procedure(brExpandable(obj)
  685.  
  686.     (memq(typep(obj) '(list dbobject wtype other array)) && obj) ||
  687.     defstructp(obj)
  688.  
  689. ) ; end procedure brExpandable
  690.  
  691.  
  692. /*******************************************************************************
  693.  * brCentre(tool)
  694.  *
  695.  * Centre the browser.
  696.  ******************************************************************************/
  697. procedure(brCentre(tool)
  698.  
  699.     tool->anchorObject = tool->rootNode
  700.     tool->anchorTo = 'centerLeft
  701.  
  702. ) ; end brCentre
  703.  
  704.