;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                               for CoCreate SolidDesigner
;;  Description:
;;      inquire UWGM Status as color for structure browser
;;
;;  Reference  : https://ww3.cad.de/foren/ubb/Forum29/HTML/004580.shtml
;;  Docu       : https://support.ptc.com/help/creo_elements_direct/r20.7.0.0/advanced_documentation/integration_kit/reference/wgm_attribute.html
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  Filename   : cadde-29-004580a.lsp
;;  Version    : 1.0 version by der_Wolfgang
;;               1.1 added german and spanish as additional languages
;;               1.2 added italian as additional language + fixed to use the LIFECYLE state + use only 3D parts+assys
;;  Created    : Wed Apr  9 18:34:04 CEST 2025
;;  Modified   : Wed Apr 30 12:58:19 CEST 2025
;;  Author     : der_Wolfgang@forum@cad.de
;;  Download   : cad.de ?
;;  SD-Version : developed with PE80
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(in-package :cadde-wt)
(use-package :oli)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; gets an obj = 3D-sel-item
;;  inquire the UWGM LIFE CYCLE status and map it to a color
;;
;; TODO need to be adjust to available LC Status and your language
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun uwgm-inq-color-by-obj-lc-status (obj)
  (let ((wt-status (sd-string-upcase (or (sd-uwgm-inq-system-attribute obj "PTC_WM_LIFECYCLE_STATE") ""))))
    (cond
      ((equal wt-status "RELEASED")     "#22AA22")  ;; green
      ((equal wt-status "IN WORK")      "#FF9999")  ;; light red
      ((equal wt-status "IN CREATION")  "#99FF99")  ;; light green
      ((equal wt-status "UNDER REVIEW") "#FF8080")  ;; orange
      ((equal wt-status "LOCKED")       "#DD0000")  ;; red

      ;; for best performance place your language to the top and comment other languages
      ((equal wt-status "Rilasciato"              "#22AA22")  ;; green
      ((equal wt-status "In fase di elaborazione" "#FF9999")  ;; light red
      ((equal wt-status "In esame"                "#FF8080")  ;; orange
      ((equal wt-status "Bloccato"                "#DD0000")  ;; red

      ; ;; for best performance place your language to the top
      ; ((equal wt-status "Freigegeben")     "#22AA22")  ;; green
      ; ((equal wt-status "Wird bearbeitet") "#FF9999")  ;; light red
      ; ((equal wt-status "In Prüfung")      "#FF8080")  ;; orange
      ; ((equal wt-status "Gesperrt")        "#DD0000")  ;; red

      ; ;; for best performance place your language to the top
      ; ((equal wt-status "Liberado")          "#22AA22")  ;; green
      ; ((equal wt-status "En curso")          "#FF9999")  ;; light red
      ; ((equal wt-status "Revisión en curso") "#FF8080")  ;; orange
      ; ((equal wt-status "Bloqueado")         "#DD0000")  ;; red

      (T "#555555") ;; anything else ..  light grey
      ) ;; end cond
    ) ;; end let
  ) ;; end defun

(defun uwgm-get-browser-lc-status-color (node name)
  (declare (ignore name))
  (when (sd-is-pseudo-folder-node-p (BrowserNode-NODEID node))
    (setq node (first (sd-query-browser name :GET-CHILDREN node)))) ;; don't like it that much
  (let* ((objname (BrowserNode-objPname node))
         (objlist (sd-string-split (BrowserNode-objPath node) "\"")) ;;;;   \" )) feature name?
         (objpath (if (> (length objlist) 1) (second objlist) (first objlist)))
         (obj (sd-pathname-to-obj objpath))
         )
  (if (and (sel_item-p obj)
           (or (sd-inq-part-p obj)     ;; only for those objects we do store in Database
               (sd-inq-assembly-p obj)
               )
             )
    (uwgm-inq-color-by-obj-lc-status obj)
    ;;
    NIL ;; default color: means black in most cases
    )
    ) ;; end let
  ) ;; end defun

;; now let's configure it to use the new function
(sd-browser-add-interrogator "parcel-gbrowser"
  :interrogator-type :text-color
  :interrogator-func 'uwgm-get-browser-lc-status-color
  )