assembly.lisp 18.3 KB
Newer Older
Dave Cooper's avatar
Dave Cooper committed
1
;;
2
;; Copyright 2002, 2009, 2012 Genworks International
Dave Cooper's avatar
Dave Cooper committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
;;
;; This source file is part of the General-purpose Declarative
;; Language project (GDL).
;;
;; This source file contains free software: you can redistribute it
;; and/or modify it under the terms of the GNU Affero General Public
;; License as published by the Free Software Foundation, either
;; version 3 of the License, or (at your option) any later version.
;; 
;; This source file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; Affero General Public License for more details.
;; 
;; You should have received a copy of the GNU Affero General Public
;; License along with this source file.  If not, see
;; <http://www.gnu.org/licenses/>.
;;


#|

To do:

o Add direct buttons back to viewport

o support for multiple viewports

o filter inspector slots to local slots

|#


(in-package :tasty)

(define-object assembly (base-ajax-sheet)
  
  :input-slots
  ((root-object (the root-object-object) :settable)
   
   (initial-tree-depth 1)
   (package-default :gdl-user)
   (inspector-relative-font-size "-1")
   (viewport-dimensions (list :width 800 :length 550) :settable)
   
   (uri-static-gwl "/static/gwl/")
Dave Cooper's avatar
Dave Cooper committed
49

Dave Cooper's avatar
Dave Cooper committed
50 51
   
   (uri-static-gwl-styles (when (the use-jquery?) (string-append (the uri-static-gwl) "style/")))
Dave Cooper's avatar
Dave Cooper committed
52

Dave Cooper's avatar
Dave Cooper committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
   
   (uri-static-gwl-images (when (the use-jquery?) (string-append (the uri-static-gwl) "images/")))
   
   (uri-static-gwl-unpix (when (the use-jquery?) (string-append (the uri-static-gwl) "tasty-unpix/")))
   
   (uri-style-sheet (when (the use-jquery?) (string-append (the uri-static-gwl-styles) "tasty-layout.css")))
   
   
   (tatu-update-function 
    #'(lambda() 
        (the (set-slot! :root-object (the root-object)))
        (the tree update!)))
   
   (use-jquery? (the have-valid-instance?))
   (use-raphael? (the have-valid-instance?)))

  :computed-slots
  (
   (ui-specific-layout-js (when (the use-jquery?) "/static/gwl/js/tasty-initlayout-3.js"))
   
   (have-valid-instance? (not (typep (the root-object) 'null-part)))

   (additional-header-content (when (the have-valid-instance?)
                                (the ta2-style-view)))
Dave Cooper's avatar
Dave Cooper committed
77
   
Dave Cooper's avatar
Dave Cooper committed
78 79 80 81
   (ta2-style-view (with-cl-who-string ()
                     ((:link :type "text/css" :rel "stylesheet" 
                             :href (the uri-style-sheet)))))
   
82
   #+nil
Dave Cooper's avatar
Dave Cooper committed
83 84 85 86 87 88 89 90 91
   (html-sections (remove nil
			  (list (the tree) 
				(the tree-status-object) 
				(the viewport) 
				(the inspector)
				(the viewport-status-object) 
				(the image-status-object)
				(the menu-section)
				)))
Dave Cooper's avatar
Dave Cooper committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
   
   (root-object-type 'null-part :settable)
   
   (at-true-root? (typep (the root-object parent) 'assembly))

   ;;
   ;; FLAG - this should come from color palette.
   ;;
   ;;(color-selected nil :settable)
   
   (color-selected (the menu-section color))

   ;;(color-selected :red)
   

   )

  :hidden-objects
  (
   (click-mode :type 'menu-form-control
               :size 1
               :default :inspect
               :onchange (the (gdl-ajax-call :form-controls (list (the-child))))
               :choice-plist (list :inspect "Inspect object (I)"
                                   :add-leaves "Add Leaves (AL)"
                                   :add-node "Add Node (AN)"
                                   :draw-node "Draw Node (DN)"
                                   :add-leaves* "Add Leaves indiv. (AL*)"
                                   :draw-leaves "Draw Leaves (DL)"
                                   :delete-leaves "Clear Leaves (CL)"
                                   :break "Set self to Object (B)"
                                   :set-root "Set root to Object (SR)"
                                   ))
   
   (root-object-object :type (the root-object-type)
                       :tree-root (the-child)
                       :root (the-child)
                       :$$ta2-object self
                       :strings-for-display (format nil "~s" (the root-object-type)))

   
   (part-type-form :type 'part-type-form
                   :pass-down (package-default)
                   :tatu-root self
                   :set-root-function #'(lambda(object) (the (set-root! object)))
                   :make-instance-function #'(lambda(type) 
                                               (the (make-root-instance type))))
   
   
   (tree
    :type 'tree:newertree
    ;;:type 'tree:tree
    :display-controls-hash (the viewport display-controls-hash)
    :target-object (the root-object)
    ;;:show-onmouseover-buttons? nil
    :onclick-function 
    #'(lambda(object)
        (the (gdl-ajax-call 
              :function-key :perform-action!
              :arguments (list object)))))
   
   
   (viewport :type 'viewport
155
             :pass-down (root-object)
Dave Cooper's avatar
Dave Cooper committed
156 157 158 159 160 161 162 163 164
             :line-thickness-selected (the menu-section line-thickness-selected)
             :color (the menu-section color)
             :inspected-object (the inspector node)
             :length (getf (the viewport-dimensions) 
                           :length (getf (the viewport-dimensions) :height))
             :width (getf (the viewport-dimensions) :width)
             :onclick-function #'(lambda(object)
                                   (the (gdl-ajax-call 
                                         :function-key :perform-action!
165 166 167
                                         :arguments (list object)
					 :one-arg? (member (the-child image-format) (list :x3d :x3dom))
					 )))
Dave Cooper's avatar
Dave Cooper committed
168 169 170 171 172 173 174
             :tatu-root self)
   
   (inspector :type 'inspector
              :pass-down (root-object)
              :click-mode (the click-mode value)
              :relative-font-size (the inspector-relative-font-size)
              :display-controls-hash (the viewport display-controls-hash)
175
              :tatu-root self)
Dave Cooper's avatar
Dave Cooper committed
176 177

   (viewport-status-object :type 'status-object
178
			   :respondent self
Dave Cooper's avatar
Dave Cooper committed
179 180 181
                           :status-message (the viewport digitation-mode))
   
   (image-status-object :type 'status-object
182
			:respondent self
Dave Cooper's avatar
Dave Cooper committed
183 184 185
                        :status-message (the viewport image-format))
   
   (tree-status-object :type 'status-object
186
		       :respondent self
Dave Cooper's avatar
Dave Cooper committed
187 188 189 190 191 192 193 194 195
                       :status-message (getf (the click-mode choice-plist) (the click-mode :value)))
   
   (menu-section :type 'menu-section
                 :tatu-root self
                 :pass-down (uri-static-gwl-images uri-static-gwl-unpix at-true-root?))
   
   
   
   (footer-ui-widget-header :type 'sheet-section
196
                            :inner-html (with-cl-who-string ()
Dave Cooper's avatar
Dave Cooper committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
                                         (:span "Click-mode: " (str (the viewport-status-object main-div))
                                                " | Image format: [" 
                                                
                                                (if (eql (the viewport image-format) :raphael)
                                                    (str (the image-status-object main-div))
                                                  (htm ((:a :href (ecase (the viewport image-format)
                                                                    ((:jpeg :png) (the viewport image-url))
                                                                    (:vrml (the viewport vrml-url))
                                                                    (:x3d (the viewport x3d-url))
                                                                    (:x3dom (the viewport x3d-url))
                                                                    )) 
                                                        (str (the image-status-object main-div))))) 
                                                "]" 
                                                
                                                
                                                (when (eql (the viewport digitation-mode) :report-point)
                                                  (if (the viewport digitized-point)
                                                      (str (format nil " | Clicked: [~{~a~^,~}]" (let ((x (get-x (the viewport digitized-point)))
                                                                                                 (y (get-y (the viewport digitized-point)))
                                                                                                 (z (get-z (the viewport digitized-point))))
                                                                                            (list (number-round x 2)
                                                                                                  (number-round y 2)
                                                                                                  (number-round z 2)))))
                                                    (htm " | Please Select a Point")))
                                                
                                                (when (eql (the viewport digitation-mode) :measure-distance)
                                                  (cond 
                                                   ((the viewport digitized-distance)
                                                    (htm
                                                     " | total: " (str (format nil "~4,2f," (getf (the viewport digitized-distance) :total)))
                                                     " x:" (str (format nil "~4,2f," (getf (the viewport digitized-distance) :x)))
                                                     " y:" (str (format nil "~4,2f," (getf (the viewport digitized-distance) :y)))
                                                     " z:" (str (format nil "~4,2f" (getf (the viewport digitized-distance) :z)))))
                                                   ((null (the viewport digitized-point))
                                                    (htm " | Please Select the First Point"))
                                                   (t (htm " | Please Select the Second Point"))))
                                                
                                                
                                                (when (eql (the viewport digitation-mode) :select-object)
                                                  (htm " | Mouse Over to Highlight and Click to Select Object to Inspect"))))))
                                                  

  
  :functions
  (
   (set-self! (object) (set-self object))
   
   (update-object! (object) 
                   (let ((root-object (the root-object)))
                     (the-object object update!)
                     (the-object object (set-slot! :root-object root-object))))
   
   (update-root-object!
    ()
    (the root-object update!)
    (the tree update!)
    )
   
   (make-root-instance
    (type)
    (the (set-slot! :root-object-type
                    (let ((*package* (find-package (the package-default))))
                      (read-safe-string type)))))

   (set-root!
    (object)
    (when (typep object 'base-html-sheet) 
      (the-object object (set-slot! :$$ta2-object self)))
    (the (set-slot! :root-object object)))
   
   (update-node! 
    (object)
    ;;
    ;; FLAG -- factor out repeated code between here and click-mode.lisp.
    ;;
    (let ((standalone? (not (eql (the root) (the root-object root)))))
      (if standalone?
          (progn
            (when object  (the-object object update!))
            (funcall (the tatu-update-function))
            (the viewport (toggle-view-toggle!)))
        (let ((root (the root))
              (tatu-root-path (the root-path)))
          (when object (the-object object update!))
          (the-object root (follow-root-path tatu-root-path) 
                      viewport toggle-view-toggle!)
          (list :go-to (the-object root (follow-root-path tatu-root-path)))))))
   
   (up-root!
    ()
    (unless (the at-true-root?)
      (the (set-slot! :root-object (the root-object parent)))))
   
   (reset-root!
    ()
    (unless (the at-true-root?)
      (the (set-slot! :root-object (the root-object-object)))))
   
   (perform-action!
    (object &key kids-error (click-mode (the click-mode value)))
    (when *debug?* (print-variables (the-object object root-path) click-mode))
    (ecase click-mode
      (:inspect (the inspector (set-object! object)))
      (:reset-root (the (reset-root! object)))
      (:set-root (the (set-root! object)))
      (:update-node (the (update-node! object)))
      (:draw-leaves (the viewport (draw-leaves! object)))
      (:draw-node (the viewport (draw-node! object)))
      (:add-leaves (the viewport (add-leaves! object)))
      (:add-leaves* (the viewport (add-leaves*! object)))
      (:delete-leaves (the viewport (delete-leaves! object)))
      (:add-node (the viewport (add-node! object)))
      
      (:break 
       (set-self object)
       (let ((*package* (symbol-package (the-object object root type))))
                
         (format t "~&
~aSelf is now set to to ~s, you may use command-line interaction....~%~%" 
                 (if kids-error
                     (format nil "~&
NOTE: Children cannot expand -- evaluate (the children) to reproduce the error. 
The error was: ~a

" 
                             kids-error) "") object)))
      
      ;;(:uh (the viewport (set-sheet-object! object)))
      
      ))))




(define-lens (html-format assembly)()
  
  :output-functions
  ((main-sheet-body 
    ()
    
    (if (the have-valid-instance?)
        (write-the ui-sheet)
      (write-the part-type-form main-sheet)))
   
   (ui-sheet
    ()
    (with-cl-who (:indent t) 
      ;; This is the content of the Body of the basic
      ;; tasty layout Outer layout: center (has a Layout), west (has
      ;; additional Layout), north (menu), south (footer) Inner layout
      ;; in outer-center: center (main viewport), east (auxilary
      ;; views+help), north (contexthelp), west (inspector in 3 panes
      ;; side by side) Inner layout in outer-west: center (main tree),
      ;; south (inspector when traditional ta layout selected)
      
      ((:div :id "loader-message")
        ((:span :class "ui-icon ui-icon info" style"float: left; margin: 0.3em;")
       (:span "Application is Loading")))
      
      ((:div :id "tabs" :class "page-layout-center")
       
       
       ((:ul :id "TabButtons" :class "pane")
        (:li ((:a :href "#ApplicationLayout")(:span "Application")))
        (:li ((:a :href "#Documentation")(:span "Documentation")))
        )
       
       ;; wrap tab-panels in ui-layout-content div 
       ((:div :id "TabPanelsContainer" :class "pane")
        
        ;; TAB #1 
        ((:div :id "ApplicationLayout")
         
         ((:div :id "InnerLayout" :class "outer-center pane")
          
          ((:div :class "inner-center ui-widget pane")
           ((:div :class "header ui-widget-header")"Viewport")
           ((:div :class "ui-widget-content")(str (the viewport main-div)))
           ((:div :class "footer ui-widget-header")
                    
            (str (the footer-ui-widget-header main-div))))
          
          
          ((:div :class "inner-west ui-widget pane")
           ((:div :class "header ui-widget-header")"Inspector")
           ((:div :class "ui-widget-content")
            (str (the inspector main-div))))
          
          ((:div :class "inner-north ui-widget pane")
           ((:div :class "header ui-widget-header")"Inner North")
           ((:div :class "ui-widget-content")(:span "Inner North"))))
         
         ((:div :class "outer-west ui-widget pane")
          ((:div :class "header ui-widget-header")"Tree")
          ((:div :class "ui-widget-content")(str (the tree main-div)))
          ((:div :class "footer ui-widget-header") 
           "Click-mode:" (str (the tree-status-object main-div)))
          )
         
         ((:div :class "outer-north ui-widget pane")
397 398
	  ((:div :onmouseover "InnerLayout.allowOverflow(this)")
	   (str (the menu-section main-div))))
Dave Cooper's avatar
Dave Cooper committed
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
         
         ((:div :class "outer-south ui-widget pane")
          ((:div :class "footer ui-widget-header")
           ((:span :class "fltrt") 
            "powered by " ((:a :href "http://www.genworks.com" :target "_new")"Genworks GDL")
            "- empowered by " ((:a :href "http://www.ke-works.com" :target "_new")"KE-works"))
           ((:span) "GDL status: ")
           ((:span :id "gdlStatus")"Done.")
           (when *tasty-developing?*
             (htm            
              (:span " | ")
              (:span

               ((:span :onclick (the (gdl-ajax-call :function-key :update-object!
                                                    :arguments (list self)))
                       :title "Full Update of Tasty Browser and Object in Tree (for tasty development)"
                       :style "color: blue; cursor: pointer;") "Update!")
               " | "
               ((:span :onclick (the (gdl-ajax-call :function-key :set-self!
                                                    :arguments (list self)))
                       :title "Set self to this tasty object (for tasty development)"
                       :style "color: blue; cursor: pointer;") "Set Self!"))

              
              ;;(write-the development-links)
              
              ;;(write-the break-link) (htm " | ")(write-the update-full-link)

              ))
           
           #+nil
           (when (typep (the root-object) 'base-html-sheet)
             (htm (:span " | ")
                  ((:a :href (the root-object url)) "Visit UI")))))

         
         ((:div :class "outer-east ui-widget pane")
          ((:div :class "header ui-widget-header")"Auxiliary")
          ((:div :class "ui-widget-content")(:span "Auxiliary Pane Content"))
          
          )
         
         );; #ApplicationLayout 
        
        ;; TAB #2 
        ((:div :id "Documentation" :class "ui-tabs-hide pane")
         ((:iframe :class "ui-widget-content" :src "/yadd" :width "100%" :height "500px"))
         )
        
        );; END TabPanelsContainer 
       
       )
      
      ))))
Dave Cooper's avatar
Dave Cooper committed
453 454