viewport.lisp 11.5 KB
Newer Older
1
2
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
;;
;; Copyright 2002, 2009 Genworks International and Genworks BV 
;;
;; 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/>.
;; 


(in-package :tasty)



(define-object viewport (base-ajax-graphics-sheet)
  
  :input-slots
  (tatu-root root-object 
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
	     
	     (vector-graphics-onclick? (not (eql (the digitation-mode) :select-object)))
	     
	     (color nil)
	     
	     (line-thickness-selected nil)
	     
	     onclick-function
	     
	     (inspected-object nil)
	     
	     (display-list-object-roots 
	      (let (result)
		;;(the recompute?)
		(maphash #'(lambda(root-path value)
			     (declare (ignore value))
Dave Cooper's avatar
Dave Cooper committed
47
48
49
			     (push (if (listp root-path)
				       (the root-object (follow-root-path root-path))
				       root-path) result))
50
51
52
53
54
55
56
57
58
59
60
61
62
63
			 (the view-object-roots-root-paths-hash)) (nreverse result)))
	     
	     
	     (display-list-objects 
	      (let (result)
		(the recompute?)
		(maphash #'(lambda(root-path value)
			     (declare (ignore value))
			     (push (the root-object (follow-root-path root-path)) result))
			 (the view-objects-root-paths-hash)) (nreverse result)))
	     
	     (image-format-default :raphael)
	     
	     )
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

  
  
  :computed-slots
  (;;(dom-id "ta2viewport")
   
   (use-bsplines? (the use-bsplines-checkbox value))
   
   (js-to-eval (when (eql (the image-format) :raphael)
                 (the raphael-string)))
   
   (recompute? nil :settable)
   
   (respondent (the tatu-root))
   
   

   ;;
   ;; FLAG -- consider changing back to a list so we can preserve ordering.
   ;;
   (view-object-roots-root-paths-hash (make-hash-table :test #'equalp 
                                                       #+allegro :values #+allegro nil) :settable)

   

   
   (view-objects-root-paths-hash (make-hash-table :test #'equalp 
                                                  #+allegro :values #+allegro nil) :settable)
   

   

   (display-controls-root-path-hash (make-hash-table :test #'equalp) :settable)
   
   (display-controls-hash (let ((ht (make-hash-table)))
                            (maphash #'(lambda(root-path plist)
                                         (setf (gethash (the root-object (follow-root-path root-path)) ht) plist))
                                     (the display-controls-root-path-hash)) ht))
   
   
   (operations-list nil :settable)
   
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
   )
  
  
  
  :hidden-objects
  ((clear-button :type 'button-form-control 
                 :label "Clear!"
                 :onclick (the (gdl-ajax-call :function-key :clear!)))
   
   (use-bsplines-checkbox :type 'checkbox-form-control
                          :default *use-bsplines-for-vrml?*
                          :prompt "Use Bsplines for VRML?")
   
   )

  
  :functions
  (
   ;;
   ;; FLAG -- consider changing back to list here and on add-node!, to
   ;; preserve ordering.
   ;;
   (add-leaves!
    (object) 
Dave Cooper's avatar
Dave Cooper committed
131
    
132
133
    (the (add-display-controls! object))
    (let ((hash (the view-object-roots-root-paths-hash))
Dave Cooper's avatar
Dave Cooper committed
134
	  (root-path (the-object object root-path)))
135
136
      
      (the (set-slot! :view-object-roots-root-paths-hash
Dave Cooper's avatar
Dave Cooper committed
137
138
		      (progn (unless (second (multiple-value-list (gethash root-path hash)))
			       (setf (gethash root-path hash) t)) hash))))
139
140
    
    (the (set-slot! :operations-list 
Dave Cooper's avatar
Dave Cooper committed
141
142
		    (append (the operations-list)
			    (list (list :operation :add-leaves :object object))))))
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
   
   
   (enter-debugger!
    ()
    
    (when (typep (the image-url) 'error)
      (let ((object (getf (lastcar (the operations-list)) :object)))
        (set-self object)
        (let ((*package* (symbol-package (the-object object root type))))
          
          (let ((no-trap? (member :notrap net.aserve::*debug-current*)))
            (unless no-trap? 
              (net.aserve::debug-on :notrap)
              (format t "~&Disabling AllegroServe error trapping (i.e. enabling debugging) 
  -- you can re-enable it with (net.aserve::debug-off :notrap)~%")
              (net.aserve::debug-on :notrap)))
          
          (break (the image-url))))))
161
   
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
   
   (pop-operation!
    ()
    (let ((item (lastcar (the operations-list))))
      (let ((operation (getf item :operation))
            (object (getf item :object)))
        (ecase operation
          (:add-leaves (the (delete-leaves! object)))
          (:add-leaves* (dolist (leaf (the-object object leaves))
                          (the (delete-leaves! leaf))))
          (:add-node (the (delete-node! object))))))
    (the (set-slot! :operations-list (butlast (the operations-list)))))

   
   
   (add-leaves*!
    (object)
    (the (add-display-controls! object))
    (dolist (leaf (the-object object leaves)) (the (add-node! leaf)))
    (the (set-slot! :operations-list 
                    (append (the operations-list)
                            (list (list :operation :add-leaves* :object object))))))
   
185
186
187
188
189
   
   (leaves-displayed? 
    (object)
    (gethash (the-object (first (the-object object leaves)) root-path)
	     (the view-objects-root-paths-hash)))
190

191
192
193
194
195
   (toggle-leaves*!
    (object)
    (if (the (leaves-displayed? object))
	(the (add-leaves*! object))
	(the (delete-leaves! object))))
196
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
   
   (delete-node!
    (object)
    (let ((display-controls-hash (the display-controls-root-path-hash))
          (root-path (the-object object root-path)))

      (the (clear-from-hash! :view-objects-root-paths-hash root-path))
      
      (the (set-slot! :display-controls-root-path-hash
                      (progn
                        (maphash #'(lambda(key val)
                                     (declare (ignore val))
                                     (when (and (<= (length root-path) (length key))
                                                (equalp (reverse root-path) (subseq (reverse key) 0 
                                                                                    (length root-path))))
                                       (remhash key display-controls-hash))) display-controls-hash) 
                        display-controls-hash)))))
   
   (delete-leaves!
    (object)
    (let ((display-controls-hash (the display-controls-root-path-hash))
          (root-path (the-object object root-path)))

      (dolist (hash-slot-key (list :view-object-roots-root-paths-hash
                                   :view-objects-root-paths-hash))
        (the (clear-from-hash! hash-slot-key root-path)))
      
      (the (set-slot! :display-controls-root-path-hash
                      (progn
                        (maphash #'(lambda(key val)
                                     (declare (ignore val))
                                     (when (and (<= (length root-path) (length key))
                                                (equalp (reverse root-path) (subseq (reverse key) 0 
                                                                                    (length root-path))))
                                       (remhash key display-controls-hash))) display-controls-hash) 
                        display-controls-hash)))))

   (clear-from-hash!
    (slot-key root-path)
    (let ((hash (the (evaluate slot-key))))
      (the (set-slot! slot-key
                      (progn
                        (maphash #'(lambda(key val)
                                     (declare (ignore val))
                                     (when (or (and (<= (length root-path) (length key))
                                                    (equalp (reverse root-path) 
                                                            (subseq (reverse key) 0 (length root-path)))))
                                       (remhash key hash))) hash) hash)))))
   
   (draw-leaves! 
    (object)     
    (the clear!) (the (add-leaves! object)))
   
   (add-node!
    (object)     
    (the (add-display-controls! object))
    (let ((hash (the view-objects-root-paths-hash))
          (root-path (the-object object root-path)))
      (the (set-slot! :view-objects-root-paths-hash
                      (progn (setf (gethash root-path hash) t) hash))))
    (the (set-slot! :operations-list 
                    (append (the operations-list)
                            (list (list :operation :add-node :object object))))))

   (draw-node! 
    (object)     
    (the clear!) (the (add-node! object)))
   
   (add-display-controls!
    (object)
    (let ((hash (the display-controls-root-path-hash))
          (root-path (the-object object root-path)))
      (the (set-slot! :display-controls-root-path-hash
                      (progn (let ((color (the color))
                                   (line-thickness (the line-thickness-selected)))
                               
                               (if (or color line-thickness)
                                   (setf (gethash root-path hash) 
274
275
276
					 (list :line-thickness line-thickness
					       :color (the color)))
				   (when (gethash root-path hash) (remhash root-path hash))))
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
                             hash)))))
   
   (clear! () 
           (the (clear-display-controls!)) (the (clear-view-object-roots!)) (the (clear-view-objects!)))
   
   (clear-display-controls!
    () (let ((hash (the display-controls-root-path-hash)))
         (the (set-slot! :display-controls-root-path-hash (progn (clrhash hash) hash)))))
   
   (clear-view-object-roots!
    () (let ((hash (the view-object-roots-root-paths-hash)))
         (the (set-slot! :view-object-roots-root-paths-hash (progn (clrhash hash) hash)))))
   
   (clear-view-objects!
    () (let ((hash (the view-objects-root-paths-hash)))
         (the (set-slot! :view-objects-root-paths-hash (progn (clrhash hash) hash)))))
   
   
   
   (set-object-to-inspect!
    (object)
    (the inspector (set-object! object)))
   
   ;;
   ;; FLAG! -- SvdE @ 14-08-09 -- new functionality to be added for tasty beta release:
   ;; refresh viewport by redrawing all nodes from
   ;; :view-objects-root-paths-hash with default display-controls. Button in menu.lisp is present and linked.
   ;;
   (set-display-defaults!
    ()
    )
   
   ))


(define-lens (html-format viewport)()
  :output-functions
  (
315
   (inner-html
316
317
318
319
320
    ()

    (with-cl-who ()
      (let ((*display-controls* (the display-controls-hash)))
        (let ((image-format (if (the 2d-boxes?) (the image-format) :png)))
321
          (ecase image-format
322
323
324
325
326
327
328
329
330
331
332
            (:links (the (write-geometry-links)))
            (:raphael (write-the vector-graphics))
            ((:png :jpeg) (write-the raster-graphics))
            (:vrml (the (write-embedded-vrml-world :include-view-controls? nil)))
            (:x3d (the (write-embedded-x3d-world :include-view-controls? nil)))
            (:x3dom (the (write-embedded-x3dom-world :include-view-controls? nil))))))))))





333
334