OneSpace Modeling: Color highlighting in the structure browser
;; -*-Lisp-*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Description: Highlights objects in browser using special colors
;; Author: Claus Brod
;; Language: Lisp
;;
;; (C) Copyright 2003 Claus Brod, all rights reserved
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
(in-package :clausbrod.de)
(use-package :oli)
(defun my-color-interrogator (node name)
(declare (ignore name))
(let* ((objname (BrowserNode-objPname node))
(objlist (oli:sd-string-split (BrowserNode-objPath node) "\""))
(objpath (if (> (length objlist) 1) (second objlist) (first objlist)))
(obj (oli:sd-pathname-to-obj objpath))
)
(if (oli:sd-string-match-pattern-p "*Lochblech*" objname)
"#ff0000"
(if (oli:sd-string-match-pattern-p "*Distanz*" objname)
"#0f0ff0"
)
)
)
)
(sd-browser-add-interrogator "parcel-gbrowser"
:interrogator-type :text-color
:interrogator-func 'my-color-interrogator)
I'll have to admit that I was hesitant to actually publish the above code.
Why? Mostly because adding interrogators to a browser can have a significantly
adverse effect on performance in the browser - so use this sparingly.
The code above adds a so-called
interrogator to the structure browser.
In this case, the interrogator is of type
:text-color
, i.e. it is called
by the browser code whenever the browser needs to find out which color
to use for the current entry. This feature can be used to highlight
"special" objects in the browser.
The definition of "special" is different for any user. The example code
is quite dumb; it simply highlights all objects which have the substrings
"Lochblech" or "Distanz" in their names.
Again, interrogators are called quite often by the browser, so they should
be short and sweet. In fact, the above code already violates this rule.
If somebody finds a better way to decode the browser object node path
than by doing string processing, please let me know.
--
ClausBrod
Indeed that code does too much. Take this as a replacement:
(defun my-color-interrogator (node name)
(declare (ignore name))
(if (oli:sd-string-match-pattern-p "*Lochblech*" (BrowserNode-objPname node))
"#ff0000"
(if (oli:sd-string-match-pattern-p "*Distanz*" (BrowserNode-objPname node))
"#0f0ff0"
)
)
)
Only the Objname was used. I also removed the LET statement: I think that 2 times to read a value out of structure is better, because it avoids some lisp garbage (memory consumption).
--
DerWolfgang - 12 Nov 2004
Thanks Wolfgang! Your code is of course infinitely better! I have merged in your changes
and
attached the resulting code as a Lisp file.
I will keep the above discussion as it is, though, because it is valuable in how
it develops a better solution from the original proposal. Thanks again!
--
ClausBrod - 15 Nov 2004
I implemented a :text-color interrogator to highlight objects that lacked a Model Name (useful for us in a ModelManager environment) but in OSDM 2006 now there are pseudo-folders which return a BrowserNode-objPath of their Owner, and it is difficult in general to tell directly what class of object a given BrowserNode represents. Basically, we can see a Name and a path... is there any other information we can get that would help identify what class or type of object is being listed by the browser? Or in the case of a pseudo-folder, what type of items it "contains" ???
--
TomBower - 25 Aug 2006
Unfortunately, I am not aware of a way to inquire the type of object from the browser node.
But then, I wasn't involved in adding pseudo-folders and don't know too much about them, so
I'd suggest to check with
CoCreate support.
--
ClausBrod - 04 Sep 2006
to top