Changeset 2730

Show
Ignore:
Timestamp:
03/13/08 18:26:13 (10 months ago)
Author:
ksprotte
Message:

image-tree-handler now works

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/projects/bos/web/image-tree.lisp

    r2728 r2730  
    1717   (children :initarg :children :reader children))) 
    1818 
     19(defpersistent-class image-tree (image-tree-node) 
     20  ()) 
     21 
    1922(defmethod print-object ((object image-tree-node) stream) 
    2023  (print-unreadable-object (object stream :type t) 
     
    2427            (store-image-height object)))) 
    2528 
    26 (defun make-image-tree-node (image &key geo-rect children
     29(defun make-image-tree-node (image &key geo-rect children (class-name 'image-tree-node)
    2730  (destructuring-bind (geo-x geo-y geo-width geo-height) 
    2831      geo-rect 
    2932    (make-store-image :image image 
    3033                      :name (image-tree-node-unique-name) 
    31                       :class-name 'image-tree-nod
     34                      :class-name class-nam
    3235                      :initargs `(:geo-x ,geo-x 
    3336                                         :geo-y ,geo-y 
     
    3639                                         :children ,children)))) 
    3740 
    38 (defun children-sizes (width height &key (divisor 2)) 
     41(defun image-tree-node-less (a b) 
     42  (cond 
     43    ((< (geo-x a) (geo-x b)) t) 
     44    ((= (geo-x a) (geo-x b)) 
     45     (< (geo-y a) (geo-y b))) 
     46    (t nil))) 
     47 
     48(defun children-sizes (width height &key (divisor 3)) 
    3949  (flet ((divide-almost-equally (x) 
    4050           (multiple-value-bind (quotient remainder) 
     
    4858          (divide-almost-equally height)))) 
    4959 
    50  
    5160(defun map-children-rects (function left top width-heights) 
    5261  "Calls FUNCTION with (x y width height) for each of the sub-rectangles 
    5362specified by the start point LEFT, TOP and WIDTH-HEIGHTS of the sub-rectangles. 
    54 Collects the results into a list." 
     63Collects the results into an array of dimensions corresponding to WIDTH-HEIGHTS." 
    5564  (let (results) 
    5665    (destructuring-bind (widths heights) 
     
    6069          (dolist (h heights) 
    6170            (push (funcall function left safe-top w h) results) 
    62             (incf safe-top h))) 
     71            (incf safe-top h)))         
    6372        (incf left w))))) 
    64  
    6573 
    6674(defun make-image-tree (source-image geo-location &key (output-images-size 256)) 
     
    6977           (source-image-height (cl-gd:image-height source-image)) 
    7078           (scaler-x (/ source-image-width geo-width)) 
    71            (scaler-y (/ source-image-height geo-height))) 
     79           (scaler-y (/ source-image-height geo-height)) 
     80           (classes '(image-tree . #1=(image-tree-node . #1#)))) 
    7281      (labels ((image-point2geo-point (x y) 
    7382                 (list (+ (/ x scaler-x) geo-x) 
     
    8796                      (<= image-height output-images-size))) 
    8897               (%make-image-tree (image-x image-y image-width image-height) 
    89                  (let ((children (unless (image-small-enough image-width image-height) 
    90                                    (map-children-rects #'%make-image-tree 
    91                                                        image-x image-y 
    92                                                        (children-sizes image-width image-height))))) 
     98                 (let ((class (pop classes)) 
     99                       (children (unless (image-small-enough image-width image-height) 
     100                                   (sort 
     101                                    (map-children-rects #'%make-image-tree 
     102                                                        image-x image-y 
     103                                                        (children-sizes image-width image-height)) 
     104                                    #'image-tree-node-less)))) 
    93105                   (cl-gd:with-image (image output-images-size output-images-size t) 
    94106                     (cl-gd:copy-image source-image image 
     
    102114                                           :geo-rect (image-rect2geo-rect 
    103115                                                      (list image-x image-y image-width image-height)) 
    104                                            :children children))))) 
     116                                           :children children 
     117                                           :class-name class))))) 
    105118        (with-image-tree-node-counter 
    106119          (%make-image-tree 0 0 source-image-width source-image-height)))))) 
     
    116129|# 
    117130 
     131(defclass image-tree-handler (object-handler) 
     132  () 
     133  (:default-initargs :object-class 'image-tree-node)) 
     134 
     135 
     136(defun img-image-tree (object) 
     137  (html 
     138   ((:a :href (website-make-path *website* 
     139                                 (format nil "image-tree/~d" (store-object-id object)))) 
     140    ((:img :src (website-make-path *website* 
     141                                   (format nil "image/~d" (store-object-id object)))))))) 
     142 
     143(defmethod handle-object ((image-tree-handler image-tree-handler) (object image-tree-node)) 
     144  (with-bknr-page (:title (prin1-to-string object)) 
     145    (img-image-tree object) 
     146    (:table 
     147     (dolist (row (group-on (children object) :key #'geo-y :include-key nil)) 
     148       (html (:tr 
     149              (dolist (child row) 
     150                (html (:td (img-image-tree child)))))))))) 
     151 
  • trunk/projects/bos/web/webserver.lisp

    r2725 r2730  
    201201                                        ("/edit-sponsor" edit-sponsor-handler) 
    202202                                        ("/contract-kml" contract-kml-handler) 
     203                                        ("/image-tree" image-tree-handler) 
    203204                                        ("/contract-image" contract-image-handler) 
    204205                                        ("/contract" contract-handler) 
    205                                         ("/reports-xml" reports-xml-handler)                                    
     206                                        ("/reports-xml" reports-xml-handler)     
    206207                                        ("/complete-transfer" complete-transfer-handler) 
    207208                                        ("/edit-news" edit-news-handler)