assembly.lisp 20.4 KB
Newer Older
Dave Cooper's avatar
Dave Cooper committed
1
;;
2
;; Copyright 2014 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
;;
;; 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

33
34
35
36
o make Update! work properly for pre-made object expression.

o allow input of required input-slots. 

Dave Cooper's avatar
Dave Cooper committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|#


(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
53

Dave Cooper's avatar
Dave Cooper committed
54
55
   
   (uri-static-gwl-styles (when (the use-jquery?) (string-append (the uri-static-gwl) "style/")))
Dave Cooper's avatar
Dave Cooper committed
56

Dave Cooper's avatar
Dave Cooper committed
57
58
59
60
61
62
63
   
   (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")))
   
64
65
66
67
68
69
70

   #+nil
   (tatu-update-function 
    #'(lambda()
	(format t "~%~%At 1~%~%")
        (the root-object update!)
	(mapsend (list (the tree) (the inspector) (the viewport)) :update!)))
Dave Cooper's avatar
Dave Cooper committed
71
   
72
   #+nil
Dave Cooper's avatar
Dave Cooper committed
73
74
75
76
77
   (tatu-update-function 
    #'(lambda() 
        (the (set-slot! :root-object (the root-object)))
        (the tree update!)))
   
78
79
80
   (use-jquery? (the have-valid-instance-and-inputs?))
   (use-raphael? (the have-valid-instance-and-inputs?))
   (use-x3dom? (the have-valid-instance-and-inputs?))
81

82
83
   (root-object-type 'null-part :settable)
   
84
   )
Dave Cooper's avatar
Dave Cooper committed
85
86
87

  :computed-slots
  (
88
89
   (use-cookie? nil)
   (fixed-url-prefix nil)
90

Dave Cooper's avatar
Dave Cooper committed
91
92
93
94
   (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)))

95
96
97
98
   (have-valid-instance-and-inputs? (and (the have-valid-instance?)
					 (the required-inputs-satisfied?)))

   (additional-header-content (when (the have-valid-instance-and-inputs?)
Dave Cooper's avatar
Dave Cooper committed
99
                                (the ta2-style-view)))
Dave Cooper's avatar
Dave Cooper committed
100
   
Dave Cooper's avatar
Dave Cooper committed
101
102
103
104
   (ta2-style-view (with-cl-who-string ()
                     ((:link :type "text/css" :rel "stylesheet" 
                             :href (the uri-style-sheet)))))
   
105
   #+nil
Dave Cooper's avatar
Dave Cooper committed
106
107
108
109
110
111
112
113
114
   (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
115
   
116
   
Dave Cooper's avatar
Dave Cooper committed
117
118
119
120
121
122
123
124
125
126
127
128
129
   
   (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)
   

130
131
   (required-inputs-satisfied? (the required-inputs-form satisfied?))

Dave Cooper's avatar
Dave Cooper committed
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
   )

  :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))))
   
   
166
167
168
169
   (required-inputs-form :type 'required-inputs-form 
			 :root-object (the root-object-object)
			 :tatu-root self)

Dave Cooper's avatar
Dave Cooper committed
170
171
172
173
174
175
176
177
   (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)
178
179
        (the (gdl-ajax-call
	      ;;:bashee (list :%rp% '(:root-object))
Dave Cooper's avatar
Dave Cooper committed
180
              :function-key :perform-action!
181
182
183
184
              :arguments (list nil
			       :tasty-root self
			       :root-object-rootpath (the-object object root-path))))))

Dave Cooper's avatar
Dave Cooper committed
185
186
187
   
   
   (viewport :type 'viewport
188
             :pass-down (root-object)
Dave Cooper's avatar
Dave Cooper committed
189
190
191
192
193
194
             :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)
195
196
197
198
199
200
201
202
             :onclick-function
	     #'(lambda(object)
		 (the (gdl-ajax-call
		       :function-key :perform-action!
		       :arguments (list nil
					:tasty-root self
					:root-object-rootpath (the-object object root-path))
		       :null-event? (member (the-child image-format) (list :x3d :x3dom)))))
Dave Cooper's avatar
Dave Cooper committed
203
204
205
206
207
208
209
             :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)
210
              :tatu-root self)
Dave Cooper's avatar
Dave Cooper committed
211
212

   (viewport-status-object :type 'status-object
213
			   :respondent self
Dave Cooper's avatar
Dave Cooper committed
214
215
216
                           :status-message (the viewport digitation-mode))
   
   (image-status-object :type 'status-object
217
			:respondent self
Dave Cooper's avatar
Dave Cooper committed
218
219
220
                        :status-message (the viewport image-format))
   
   (tree-status-object :type 'status-object
221
		       :respondent self
Dave Cooper's avatar
Dave Cooper committed
222
223
224
225
226
227
228
229
230
                       :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
231
                            :inner-html (with-cl-who-string ()
Dave Cooper's avatar
Dave Cooper committed
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
                                         (: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!)
287
288
289
    (the refresh-tasty-panes!)
    ;;(the root-object update!)
    ;;(the tree update!)
Dave Cooper's avatar
Dave Cooper committed
290
    )
291
292
293
294

   (refresh-tasty-panes!
    ()
    (mapsend (list (the tree) (the inspector) (the viewport)) :update!))
Dave Cooper's avatar
Dave Cooper committed
295
   
296
297

   #+nil
Dave Cooper's avatar
Dave Cooper committed
298
299
300
301
302
303
   (make-root-instance
    (type)
    (the (set-slot! :root-object-type
                    (let ((*package* (find-package (the package-default))))
                      (read-safe-string type)))))

304
305
306
307
308
309
310
311
312

   (make-root-instance
    (type)
    (let* ((type (let ((*package* (find-package (the package-default))))
		   (read-safe-string type)))
	   (object (make-object type :strings-for-display (format nil "~s" type))))
      (the (set-root! object))))


Dave Cooper's avatar
Dave Cooper committed
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
   (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!
348
349
    (&optional object &key tasty-root root-object-rootpath 
	    kids-error (click-mode (the click-mode value)))
Dave Cooper's avatar
Dave Cooper committed
350
    (when *debug?* (print-variables (the-object object root-path) click-mode))
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371

    (let ((object (or object
		      (the-object tasty-root root-object
				  (follow-root-path root-object-rootpath)))))

      (print-variables object click-mode)

      (print-variables (the inspector node-root-path)
		       (the inspector node))

      (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)))
Dave Cooper's avatar
Dave Cooper committed
372
      
373
374
375
	(:break 
	 (set-self object)
	 (let ((*package* (symbol-package (the-object object root type))))
Dave Cooper's avatar
Dave Cooper committed
376
                
377
	   (format t "~&
Dave Cooper's avatar
Dave Cooper committed
378
~aSelf is now set to to ~s, you may use command-line interaction....~%~%" 
379
380
		   (if kids-error
		       (format nil "~&
Dave Cooper's avatar
Dave Cooper committed
381
382
383
384
NOTE: Children cannot expand -- evaluate (the children) to reproduce the error. 
The error was: ~a

" 
385
			       kids-error) "") object)))
Dave Cooper's avatar
Dave Cooper committed
386
      
387
388
389
390
391
392
	;;(:uh (the viewport (set-sheet-object! object)))
      
	)

      (print-variables (the inspector node-root-path)
		       (the inspector node))
Dave Cooper's avatar
Dave Cooper committed
393
394
395
396
397
398
399
400
401
402
403
404
      
      ))))




(define-lens (html-format assembly)()
  
  :output-functions
  ((main-sheet-body 
    ()
    
405
406
407
408
409
410
411
412
413
414
415
416
417
    (cond ((and (the have-valid-instance?)
		(the required-inputs-satisfied?))
	   (write-the ui-sheet))
	  ((the have-valid-instance?)
	   (write-the required-inputs-form))
	  (t (write-the part-type-form main-sheet))))

 
   (required-inputs-form 
    ()
    (write-the required-inputs-form main-sheet))

  
Dave Cooper's avatar
Dave Cooper committed
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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
   (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")
468
469
470
          ((:div :class "ui-widget-content" 
		 :style (format nil "background-color: ~a" (or (getf *colors-default* :background) "#fafafa")))
		 (str (the tree main-div)))
Dave Cooper's avatar
Dave Cooper committed
471
472
473
474
475
          ((:div :class "footer ui-widget-header") 
           "Click-mode:" (str (the tree-status-object main-div)))
          )
         
         ((:div :class "outer-north ui-widget pane")
476
477
	  ((:div :onmouseover "InnerLayout.allowOverflow(this)")
	   (str (the menu-section main-div))))
Dave Cooper's avatar
Dave Cooper committed
478
479
480
481
         
         ((:div :class "outer-south ui-widget pane")
          ((:div :class "footer ui-widget-header")
           ((:span :class "fltrt") 
482
483
484
            "powered by " 
	    ((:a :href "http://www.genworks.com" :target "_new") "Genworks GDL")
	    (str (if (glisp:featurep :smlib) ", " " and "))
485
486
487
488
489
490
	    ((:a :href "http://www.quicklisp.org" :target "_new")"Quicklisp")
	    (if (glisp:featurep :smlib) 
		(progn
		  (str ", and ")
		  (htm ((:a :href "http://www.smlib.com" :target "_new") "SMLib")))
		""))
Dave Cooper's avatar
Dave Cooper committed
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
           ((: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
539
540