CoCreate 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



When asked for a TWiki account, use your own or the default TWikiGuest account.
The other issue we discovered with a :text-color interrogator is that once you have one, it masks the normal color behavior of standard Modeling (e.g. an invalid custom feature won't turn red any longer). This needs to be changed so that user-developed code can overlay on top of standard behavior, not replace it.

-- TomBower - 17 Sep 2009


to top

I Attachment sort Action Size Date Who Comment
browsercolors.lsp manage 0.8 K 04 Jan 2006 - 19:28 ClausBrod browsercolors.lsp

You are here: CoCreateModeling > OsdmMacros > MacroStructureBrowser

r1.10 - 17 Sep 2009 - 15:43 - TomBower to top

CoCreateModeling
CoCreate ModelingRSS
FAQ
  Introduction
  Hardware
  Operating system
  Memory management
  File handling
  Installation
  Licensing
  Graphics
  App. knowhow
  Lisp
    Learning
    Programming
    Debugging
    DDE
    Compiler
    Customization
  Troubleshooting
  Links
Code examples
Viewbench
News
Changes
Index
Search
Impressum
Home

  • My links
  • Show me topics of interest

TWiki

Welcome


TWiki Web TWiki Web Home Changes Topics Index Search


TWiki Webs Atari Blog Main OneSpaceModeling? Sandbox TWiki TWiki Webs Atari Blog Main OneSpaceModeling? Sandbox TWiki

Jump:

Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback