(deftool ("cimtool" "tool") ((facility "microlab") (database 'ml))
  "This is the cimTOOL" 
  (title "Picasso:  Facility Manager") 
  (region '(9 158 510 420))
  (package-search-list ("cimtool"))
  (frames ((start-frame ("main-frame" . "frame"))))
  (start-frame start-frame)
  (static-variables 
   data-loaded
   util-list equip-list space-list junct-list lot-list eq-run-map
   junct-kind-list eq-junct-list connect-list
   vertex-list wall-list label-list
   junct-tab junct-kind-tab 
   selected-items
   unsel-equip unsel-util unsel-junct unsel-space unsel-lot
   sel-equip sel-util sel-junct sel-space sel-lot
;;   (intro-disk (video:make-indexed-video-disk
;;	           :file (picasso-path "lib/video/cim-disk/ml.index")))
;;   (equip-disk (video:make-indexed-video-disk
;;		   :file (picasso-path "lib/video/cim-disk/equip.index")))
   )
  (constants
   (bw (black-and-white-display-p))
   (util-color (if #!bw "white" "red"))
   (equip-color (if #!bw "white" "green"))
   (junct-color (if #!bw "white" "magenta"))
   (space-color (if #!bw "white" "cyan")))
  (init-code 
   (progn
    ;; Load the raw data
    (unless #!data-loaded
	    (format t "Reading database...~%")
	    (clear-sgg-arg-list)
	    (load-fmdb #!database #!facility #?equip-list #?eq-junct-list 
		       #?connect-list #?util-list #?junct-list #?junct-kind-list
		       #?space-list #?vertex-list #?wall-list #?label-list
		       #?lot-list #?eq-run-map)
	    
	    ;; Delete the junctions that are equipment junct
	    (setf #!junct-list (delete-dup-junct #!junct-list #!eq-junct-list))
	    (setf #!junct-list (nconc #!junct-list #!eq-junct-list))
	    
	    ;; Build hash tables...
	    (build-table #!junct-list #?junct-tab)
	    (build-table #!junct-kind-list #?junct-kind-tab)
	    
	    ;; Figure out geometric data for conenctions, junctions
	    (format t "Resolving connections...~%")
	    (resolve-connections #!connect-list #!junct-tab)
	    (format t "Resolving utilities...~%")
	    (resolve-utils #!util-list #!connect-list)
	    (format t "Resolving junctions...~%")
	    (resolve-juncts #!junct-list #!junct-kind-tab)
	    (when video:*real-player-p*
		  (format t "Starting disk...~%")
		  (video:connect-player)
		  (video:start-disc)
		  ;; Got to do the intro disk here, too!
		  (format t "Finding equipment pictures...~%")
		  (dolist (eq #!equip-list)
			  (find-picture-keys #!equip-disk eq)))
	    (format t "Done loading data...~%~%")
	    (setf #!data-loaded t)
	    ))))

#-cimtool-support
(load-picasso "lib/po/cimtool/support-code")
