id
int64 0
45.1k
| file_name
stringlengths 4
68
| file_path
stringlengths 14
193
| content
stringlengths 32
9.62M
| size
int64 32
9.62M
| language
stringclasses 1
value | extension
stringclasses 6
values | total_lines
int64 1
136k
| avg_line_length
float64 3
903k
| max_line_length
int64 3
4.51M
| alphanum_fraction
float64 0
1
| repo_name
stringclasses 779
values | repo_stars
int64 0
882
| repo_forks
int64 0
108
| repo_open_issues
int64 0
90
| repo_license
stringclasses 8
values | repo_extraction_date
stringclasses 146
values | sha
stringlengths 64
64
| __index_level_0__
int64 0
45.1k
| exdup_ids_cmlisp_stkv2
sequencelengths 1
47
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
11,693 | relatio16.lisp | lambdamikel_VISCO/src/GEOMETRY/relatio16.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GEOMETRY; Base: 10 -*-
(in-package geometry)
(define-condition geom-error (simple-error)
((descr :initarg :descr :accessor descr)))
(defgeneric mark-obj (obj value)
(:documentation "Mark object with value."))
(defgeneric primary-p (obj)
(:documentation "Returns T, if obj is no part of any other object."))
(defgeneric component-p (obj1 obj2)
(:documentation "If obj1 is a direct or indirect part of obj2, returns T."))
(defgeneric get-all-masters (obj)
(:documentation "Returns all objects which have obj as a component object (part)."))
(defgeneric get-direct-components (obj)
(:documentation "Returns all objects which are a direct component of obj."))
(defgeneric common-root-p (obj1 obj2)
(:documentation "Returns T if obj1 and obj2 are both components of the same object."))
(defgeneric point-=-p (point1 point2)
(:documentation "Returns T if point1 and point2 have the same position."))
(defgeneric line-=-p (line1 line2)
(:documentation "Returns T if line1 and line2 are congruent."))
(defgeneric point->=-p (point1 point2)
(:documentation "Returns T if point1 is right and above point2."))
(defgeneric point-<=-p (point1 point2)
(:documentation "Returns T if point1 is left and below point2."))
(defgeneric x (point)
(:documentation "Returns the x position of point with respect to *matrix*"))
(defgeneric y (point)
(:documentation "Returns the y position of point with respect to *matrix*"))
(defgeneric delete-object (obj &key)
(:method-combination progn)
(:documentation "Delete object from *objects-with-relations* and all stored relations."))
#|
(defgeneric translate (matrix xtrans ytrans)
(:documentation "Translate matrix by (xtrans,ytrans)."))
(defgeneric scale (matrix sx sy)
(:documentation "Scale matrix by (sx,sy)."))
(defgeneric rotate (matrix rot)
(:documentation "Rotate matrix by rot."))
|#
(defgeneric compose (matrix1 matrix2)
(:documentation "Multiply matrix1 with matrix2. Returns the modified matrix1."))
(defgeneric joins-p (line1 line2)
(:documentation "Returns T, if line1 and line2 have a common point (point-=-p)."))
(defgeneric parallel-p (line1 line2)
(:documentation "Determine whether line1 and line2 are parallel."))
(defgeneric upright-p (line1 line2)
(:documentation "Determine whether line1 and line2 are upright."))
(defgeneric ccw (point1 point2 point3)
(:documentation "Counterclockwise way from point1 over point2 to point3. See Sedgewick for details!"))
#|
(defgeneric angle-between (line1 line2)
(:documentation "Calculate the angle between line1 and line2."))
|#
(defgeneric distance-between (obj1 obj2 &key sqrt sx sy)
(:documentation "Calculate the smallest distance between obj1 and obj2."))
(defgeneric global-orientation (line)
(:documentation "Calculate the angle between the x-axis and the line."))
(defgeneric calculate-intersection-point (line1 line2)
(:documentation "Returns (x,y) intersection point (if a zero dimensional intersection between
line1 and line2 holds)."))
(defgeneric calculate-intersection-line (line1 line2)
(:documentation "Returns (x1,y1,x2,y2) intersection line (if a one dimensional intersection between
line1 and line2 holds)."))
(defgeneric calculate-area (polygon)
(:documentation "Calulates the area of the polygon."))
(defgeneric make-point (class-symbol x y &rest initargs)
(:documentation "Make a point of class class-symbol."))
(defgeneric make-line (class-symbol p1 p2 &rest initargs)
(:documentation "Make a line of class class-symbol."))
(defgeneric make-chain (class-symbol segment-list &rest initargs)
(:documentation "Make a chain of class class-symbol."))
(defgeneric make-polygon (class-symbol segment-list &rest initargs)
(:documentation "Make a polygon of class class-symbol."))
(defgeneric make-aggregate (class-symbol part-list &rest initargs)
(:documentation "Make a aggregate of class class-symbol."))
;;;
;;; Various Spatial Relations for Polygons, Lines and Points
;;;
(defconstant +big-int+ 10000)
(defparameter *matrix* nil)
(defparameter *mark-counter* 0)
(defun get-new-mark ()
(incf *mark-counter*))
;;;
;;;
;;;
(defpersistentclass bounding-box-mixin () ; abstrakt
((pmin :initarg :pmin :writer (setf pmin) :initform nil)
(pmax :initarg :pmax :writer (setf pmax) :initform nil)
(pcenter :initarg :pcenter :writer (setf pcenter) :initform nil)
(radius :initarg :radius :writer (setf radius) :initform nil)
(last-trafo-id :accessor last-trafo-id :initarg :last-trafo-id
:initform (if *matrix* (trafo-id *matrix*) -2))
(bounding-box-p :initform t :initarg :bounding-box-p :accessor bounding-box-p)))
(defpersistentclass bounding-box (bounding-box-mixin) ; instantiierbar, aber NICHT TRANSFORMIERBAR !!!
((pmin :reader pmin)
(pmax :reader pmax)
(pcenter :reader pcenter)
(radius :reader radius)))
;;;
;;;
;;;
(defvar *id-counter* 0)
(defpersistentclass geom-thing () ; abstrakt
((part-of :initform nil :initarg :part-of :accessor part-of)
(id :accessor id :initform (incf *id-counter*))
(class-of-internal-points :accessor class-of-internal-points
:initarg :class-of-internal-points
:initform 'geom-point)
(affected-by-matrix-p :accessor affected-by-matrix-p :initform t :initarg :affected-by-matrix-p)
;;; bei Punkten: T <=> nicht von Matrix beruehrt
;;; bei anderen Objekten: entscheidet, ob bei Bedarf neu erzeugte berechnete Punkte (centroid obj)
;;; das Flag gesetzt bekommen oder nicht
(check-p :accessor check-p :initarg :check-p :initform t)
(bound-to :accessor bound-to :initform nil)
(cp-flag :accessor cp-flag :initform nil)
(mark-value :accessor mark-value :initform nil)))
(defpersistentclass geom-point (geom-thing)
((x :writer (setf x) :initarg :x)
(y :writer (setf y) :initarg :y)
(centroid-of :accessor centroid-of :initarg :centroid-of :initform nil)
(pcenter-of :accessor pcenter-of :initarg :pcenter-of :initform nil)
(p1-of :accessor p1-of :initarg :p1-of :initform nil)
(p2-of :accessor p2-of :initarg :p2-of :initform nil)))
(defmethod pcenter ((obj geom-point))
obj)
(defpersistentclass geom-line (geom-thing bounding-box-mixin)
((p1 :initarg :p1 :accessor p1)
(p2 :initarg :p2 :accessor p2)
(point-list :accessor point-list)
(centroid-p :initform t :initarg :centroid-p :accessor centroid-p)
(centroid :initform nil :initarg :centroid :writer (setf centroid))))
(defpersistentclass geom-chain-or-polygon (geom-thing bounding-box-mixin)
((segments :initarg :segments :accessor segments)
(centroid :initform nil :initarg :centroid :writer (setf centroid))
(centroid-p :initform t :initarg :centroid-p :accessor centroid-p)
(point-list :accessor point-list :initarg :point-list)))
(defpersistentclass geom-polygon (geom-chain-or-polygon)
())
(defpersistentclass geom-chain (geom-chain-or-polygon)
((p1 :initarg :p1 :accessor p1)
(p2 :initarg :p2 :accessor p2)))
(defpersistentclass geom-aggregate (geom-thing bounding-box-mixin)
((has-parts :initarg :has-parts :accessor has-parts)
(centroid-p :initform t :initarg :centroid-p :accessor centroid-p)
(centroid :initform nil :initarg :centroid :writer (setf centroid))))
;;;
;;;
;;;
(defmethod trafo-id ((obj null))
-1)
(defmethod pmin ((obj bounding-box-mixin))
(with-slots (pmin last-trafo-id) obj
(unless (and pmin (= last-trafo-id (trafo-id *matrix*)))
(recalculate-bounding-box obj))
pmin))
(defmethod pmax ((obj bounding-box-mixin))
(with-slots (pmax last-trafo-id) obj
(unless (and pmax (= last-trafo-id (trafo-id *matrix*)))
(recalculate-bounding-box obj))
pmax))
(defmethod pcenter ((obj bounding-box-mixin))
(with-slots (pcenter last-trafo-id) obj
(unless (and pcenter (= last-trafo-id (trafo-id *matrix*)))
(recalculate-bounding-box obj))
pcenter))
(defmethod radius ((obj bounding-box-mixin))
(with-slots (radius last-trafo-id) obj
(unless (and radius (= last-trafo-id (trafo-id *matrix*)))
(recalculate-bounding-box obj))
radius))
;;;
;;;
;;;
(defmethod bb-width ((obj bounding-box-mixin))
(- (x (pmax obj)) (x (pmin obj))))
(defmethod bb-height ((obj bounding-box-mixin))
(- (y (pmax obj)) (y (pmin obj))))
;;;
;;;
;;;
(defun check-for-centroid (obj)
(with-slots (centroid) obj
(unless centroid
(calculate-centroid obj))
centroid))
(defmethod centroid ((obj geom-line))
(check-for-centroid obj))
(defmethod centroid ((obj geom-chain-or-polygon))
(check-for-centroid obj))
(defmethod centroid ((obj geom-aggregate))
(check-for-centroid obj))
;;;
;;;
;;;
(defmethod print-object ((obj geom-thing) stream)
(format stream "#<~A ~A>"
(type-of obj)
(id obj)))
;;;
;;;
;;;
(defmethod mark-object ((obj geom-thing) value)
(setf (mark-value obj) value))
;;;
;;;
;;;
(defmethod point-=-p ((p1 geom-point) (p2 geom-point))
(or (eq p1 p2)
(and (=-eps (x p1) (x p2))
(=-eps (y p1) (y p2)))))
(defmethod point->=-p ((p1 geom-point) (p2 geom-point))
(and (>=-eps (x p1) (x p2))
(>=-eps (y p1) (y p2))))
(defmethod point-<=-p ((p1 geom-point) (p2 geom-point))
(and (<=-eps (x p1) (x p2))
(<=-eps (y p1) (y p2))))
;;;
;;;
;;;
(defmethod line-=-p ((l1 geom-line) (l2 geom-line))
(or (eq l1 l2)
(and (point-=-p (p1 l1) (p1 l2))
(point-=-p (p2 l1) (p2 l2)))
(and (point-=-p (p1 l1) (p2 l2))
(point-=-p (p2 l1) (p1 l2)))))
;;;
;;;
;;;
(defmethod x ((point geom-point))
(with-slots (x y affected-by-matrix-p) point
(if (and *matrix* affected-by-matrix-p)
(with-slots (a b tx) *matrix*
(+ (* a x) (* b y) tx))
x)))
(defmethod y ((point geom-point))
(with-slots (x y affected-by-matrix-p) point
(if (and *matrix* affected-by-matrix-p)
(with-slots (c d ty) *matrix*
(+ (* c x) (* d y) ty))
y)))
;;;
;;;
;;;
(defvar *trafo-id* 0)
(defpersistentclass matrix ()
((trafo-id :accessor trafo-id :initform (incf *trafo-id*))
; z.B. muss die BB nach Rotationen
; neuberechnet werden (=> Id aendert sich)
(a :accessor a :initarg :a :initform 1)
(b :accessor b :initarg :b :initform 0)
(tx :accessor tx :initarg :tx :initform 0)
(c :accessor c :initarg :c :initform 0)
(d :accessor d :initarg :d :initform 1)
(ty :accessor ty :initarg :ty :initform 0)))
(defmacro make-matrix (&rest rest)
`(make-instance 'matrix ,@rest))
(defmacro reset (matrix)
`(with-slots (trafo-id a b tx c d ty) ,matrix
(setf trafo-id (incf *trafo-id*))
(setf a 1
b 0
tx 0
c 0
d 1
ty 0)
,matrix))
(defmacro translate (matrix x y)
`(with-slots (trafo-id tx ty) ,matrix
(setf trafo-id (incf *trafo-id*))
(incf tx ,x)
(incf ty ,y)
,matrix))
(defmacro scale (matrix sx sy)
(let ((sx1 sx)
(sy1 sy))
`(with-slots (trafo-id a b c d tx ty) ,matrix
(setf trafo-id (incf *trafo-id*))
(psetf a (* a ,sx1)
b (* b ,sx1)
tx (* tx ,sx1)
ty (* ty ,sy1)
c (* c ,sy1)
d (* d ,sy1))
,matrix)))
(defmacro rotate (matrix r)
`(let ((rot ,r))
(with-slots (trafo-id a b c d tx ty) ,matrix
(let ((pcos (cos rot))
(msin (- (sin rot)))
(psin (sin rot)))
(setf trafo-id (incf *trafo-id*))
(psetf
a (+ (* a pcos) (* c msin))
b (+ (* b pcos) (* d msin))
tx (+ (* tx pcos) (* ty msin))
c (+ (* a psin) (* c pcos))
d (+ (* b psin) (* d pcos))
ty (+ (* tx psin) (* ty pcos)))
,matrix))))
(defmacro with-matrix ((matrix) &body body)
`(let ((*matrix* ,matrix))
,@body))
(defmacro with-no-matrix-at-all (&body body)
`(let ((*matrix* nil))
,@body))
;;;
;;;
;;;
(defmacro with-saved-matrix ((matrix) &body body)
(let ((a (gensym))
(b (gensym))
(tx (gensym))
(c (gensym))
(d (gensym))
(ty (gensym)))
`(let ((,a (a ,matrix))
(,b (b ,matrix))
(,c (c ,matrix))
(,d (d ,matrix))
(,tx (tx ,matrix))
(,ty (ty ,matrix)))
(prog1
(progn
,@body)
(with-slots (a b c d tx ty) ,matrix
(setf a ,a
b ,b
c ,c
d ,d
tx ,tx
ty ,ty))))))
(defmacro with-translation ((tx ty) &body body)
`(if *matrix*
(with-saved-matrix (*matrix*)
(translate *matrix* ,tx ,ty)
,@body)
(let ((*matrix* (make-matrix :tx ,tx :ty ,ty)))
,@body)))
(defmacro with-scaling ((sx sy) &body body)
`(if *matrix*
(with-saved-matrix (*matrix*)
(scale *matrix* ,sx ,sy)
,@body)
(let ((*matrix* (make-matrix :a ,sx :d ,sy)))
,@body)))
(defmacro with-rotation ((rot) &body body)
`(if *matrix*
(with-saved-matrix (*matrix*)
(rotate *matrix* ,rot)
,@body)
(let ((*matrix* (make-matrix)))
(rotate *matrix* ,rot)
,@body)))
;;;
;;;
(defmethod ccw ((p0 geom-point) (p1 geom-point) (p2 geom-point))
(let* ((x0 (x p0))
(x1 (x p1))
(x2 (x p2))
(y0 (y p0))
(y1 (y p1))
(y2 (y p2)))
(ccw* x0 y0 x1 y1 x2 y2)))
(defun ccw* (x0 y0 x1 y1 x2 y2)
(let* ((dx1 (- x1 x0))
(dy1 (- y1 y0))
(dx2 (- x2 x0))
(dy2 (- y2 y0)))
(cond ((> (* dx1 dy2) (* dy1 dx2)) 1)
((< (* dx1 dy2) (* dy1 dx2)) -1)
((or (< (* dx1 dx2) 0)
(< (* dy1 dy2) 0))
-1)
((< (+ (* dx1 dx1) (* dy1 dy1))
(+ (* dx2 dx2) (* dy2 dy2)))
1)
(t 0))))
;;;
;;; Konstruktoren
;;;
(defun make-bounding-box (xmin ymin xmax ymax &rest initargs) ; externe Dienstleistung
(apply #'make-instance 'bounding-box
:xmin xmin :ymin ymin
:xmax xmax :ymax ymax
initargs))
;;;
;;;
;;;
(defmethod make-point ((class (eql 'geom-point))
x y &rest initargs)
(apply #'make-instance class
:x x :y y
initargs))
(defmethod make-line ((class (eql 'geom-line))
p1 p2 &rest initargs
&key (check-p t) (affected-by-matrix-p t)
&allow-other-keys)
(when (and check-p (point-=-p p1 p2))
(error 'geom-error :descr "Bad line!"))
(apply #'make-instance class
:p1 p1
:p2 p2
:affected-by-matrix-p affected-by-matrix-p
initargs))
(defmethod make-chain ((class (eql 'geom-chain))
segment-list
&rest initargs
&key (check-p t) (affected-by-matrix-p t)
must-be-simple-p
&allow-other-keys)
(when (and check-p
(not (segment-list-ok-p segment-list 'chain must-be-simple-p)))
(error 'geom-error :descr "Bad chain!"))
(apply #'make-instance class
:segments segment-list
:affected-by-matrix-p affected-by-matrix-p
initargs))
(defmethod make-polygon ((class (eql 'geom-polygon))
segment-list
&rest initargs
&key (check-p t) (affected-by-matrix-p t)
must-be-simple-p
&allow-other-keys)
(when (and check-p
(not (segment-list-ok-p segment-list 'polygon must-be-simple-p)))
(error 'geom-error :descr "Bad polygon!"))
(apply #'make-instance class
:segments segment-list
:affected-by-matrix-p affected-by-matrix-p
initargs))
(defmethod make-aggregate ((class (eql 'geom-aggregate))
has-parts
&rest initargs
&key (check-p t) (affected-by-matrix-p t)
&allow-other-keys)
(when (and check-p (not has-parts))
(error 'geom-error :descr "Bad aggregate!"))
(apply #'make-instance class
:has-parts has-parts
:affected-by-matrix-p affected-by-matrix-p
initargs))
;;;
;;;
;;;
(defun bb (xmin ymin xmax ymax &rest initargs)
(apply #'make-bounding-box xmin ymin xmax ymax initargs))
(defun p (x y &rest initargs)
(apply #'make-point 'geom-point x y initargs))
(defun l (p1 p2 &rest initargs)
(apply #'make-line 'geom-line p1 p2 initargs))
(defun chain (segment-list &rest initargs)
(apply #'make-chain 'geom-chain segment-list initargs))
(defun chain-from-xy-list (xy-list &rest initargs)
(let ((points
(mapcar #'(lambda (c)
(p (first c)
(second c)))
xy-list)))
(apply #'chain
(mapcar #'(lambda (p1 p2)
(l p1 p2))
points (rest points))
initargs)))
(defun poly (segment-list &rest initargs)
(apply #'make-polygon 'geom-polygon segment-list initargs))
(defun agg (has-parts &rest initargs)
(apply #'make-aggregate 'geom-aggregate has-parts initargs))
;;;
;;;
;;;
(defmethod joins-p ((i geom-line) (j geom-line))
"joins-p(i,j) <=> haben mind. einen wertgleichen oder identischen Endpunkt"
(or (and (point-=-p (p1 i) (p1 j)))
(and (point-=-p (p1 i) (p2 j)))
(and (point-=-p (p2 i) (p1 j)))
(and (point-=-p (p2 i) (p2 j)))))
;;;
;;;
;;;
(defun segment-list-ok-p (segments type must-be-simple-p)
"Bedingung: mind. 2 Segmente, keine (wert)gleichen Strecken, keine Selbstueberschneidungen"
(let ((first (first segments))
(last (first (last segments)))
(n (length segments)))
(and (>= n 2)
(=> (eq type 'polygon)
(>= n 3))
(every #'(lambda (i)
(= (count i segments) 1))
segments)
(if (eq type 'chain)
(and (every #'(lambda (i j)
(joins-p i j))
segments (rest segments))
(=> (> n 2)
(not (joins-p (first segments)
(first (last segments))))))
(and (every #'(lambda (i j)
(joins-p i j))
(cons last segments) segments)
(every #'(lambda (i)
(= 2 (count-if #'(lambda (j)
(and (not (eq i j))
(joins-p i j)))
segments)))
segments)))
(=> must-be-simple-p
(every #'(lambda (i)
(let ((count ; Schnitte zaehlen
(count-if
#'(lambda (j)
(and (not (eq i j))
(intersects-p i j)))
segments)))
(if (or (eq first i) (eq last i)) ; erstes od. letztes Segment ?
(if (eq type 'chain)
(= count 1)
(= count 2))
(= count 2))))
segments)))))
;;;
;;;
;;;
(defmethod initialize-instance :after ((chain-or-polygon geom-chain-or-polygon)
&rest initargs &key (hierarchicly-p t))
(declare (ignore initargs))
(with-slots (segments) chain-or-polygon
(setf (point-list chain-or-polygon)
(let* ((first (first segments))
(second (second segments))
(points
(if (or (point-=-p (p1 first)
(p1 second))
(point-=-p (p1 first)
(p2 second)))
(list (p2 first))
(list (p1 first)))))
(loop as segment in segments
do
(progn (pushnew (p1 segment) points :test #'point-=-p)
(pushnew (p2 segment) points :test #'point-=-p)))
(nreverse points)))
(let ((points (point-list chain-or-polygon)))
#|
(if (typep chain-or-polygon 'geom-chain)
(mapc #'(lambda (s p1 p2)
(setf (p1 s) p1
(p2 s) p2))
segments
points
(rest points))
(mapc #'(lambda (s p1 p2)
(setf (p1 s) p1
(p2 s) p2))
segments
(append points (list (first points)))
(append (rest points) (list (first points)))))
|#
(when (and (typep chain-or-polygon 'geom-chain)
hierarchicly-p)
(let ((p1 (first points))
(p2 (first (last points))))
(setf (p1 chain-or-polygon) p1
(p2 chain-or-polygon) p2)
(push chain-or-polygon (p1-of p1))
(push chain-or-polygon (p2-of p2))))
(when hierarchicly-p
(dolist (segment segments)
(push chain-or-polygon (part-of segment)))))))
(defmethod delete-object progn ((obj geom-chain-or-polygon) &key)
(dolist (segment (segments obj))
(setf (part-of segment)
(delete obj (part-of segment))))
(when (typep obj 'geom-chain)
(let ((p1 (p1 obj))
(p2 (p2 obj)))
(setf (p1-of p1)
(delete obj (p1-of p1)))
(setf (p2-of p2)
(delete obj (p2-of p2))))))
;;;
;;;
;;;
(defmethod initialize-instance :after ((line geom-line)
&rest initargs
&key (hierarchicly-p t))
(declare (ignore initargs))
(with-slots (p1 p2 point-list) line
(setf point-list (list p1 p2))
(when hierarchicly-p
(push line (part-of p1))
(push line (part-of p2))
(push line (p1-of p1))
(push line (p2-of p2)))))
(defmethod delete-object progn ((obj geom-line) &key)
(let ((p1 (p1 obj))
(p2 (p2 obj)))
(setf (p1-of p1)
(delete obj (p1-of p1)))
(setf (p2-of p2)
(delete obj (p2-of p2)))
(setf (part-of p1)
(delete obj (part-of p1)))
(setf (part-of p2)
(delete obj (part-of p2)))))
;;;
;;;
;;;
(defmethod initialize-instance :after ((agg geom-aggregate)
&rest initargs
&key (hierarchicly-p t))
(declare (ignore initargs))
(when hierarchicly-p
(with-slots (has-parts) agg
(dolist (part has-parts)
(push agg (part-of part))))))
(defmethod delete-object progn ((obj geom-aggregate) &key)
(dolist (part (has-parts obj))
(setf (part-of part)
(delete obj (part-of part)))))
;;;
;;;
;;;
(defmethod initialize-instance :after ((bounding-box bounding-box)
&rest initargs
&key xmin ymin xmax ymax)
(declare (ignore initargs))
(setf (pmin bounding-box)
(make-point 'geom-point
(min xmin xmax)
(min ymin ymax)
:affected-by-matrix-p nil))
(setf (pmax bounding-box)
(make-point 'geom-point
(max xmin xmax)
(max ymin ymax)
:affected-by-matrix-p nil))
(setf (radius bounding-box)
(sqrt
(+ (expt (/ (- xmax xmin) 2) 2)
(expt (/ (- ymax ymin) 2) 2))))
(setf (pcenter bounding-box)
(make-point 'geom-point
(/ (+ xmin xmax) 2)
(/ (+ ymin ymax) 2)
:affected-by-matrix-p nil)))
;;;
;;;
;;;
(defmethod (setf centroid) :after (centroid (master geom-thing))
(push master
(centroid-of centroid)))
(defmethod (setf pcenter) :after (center (master bounding-box-mixin))
(push master
(pcenter-of center)))
(defun centroid-of-pointlist (pointlist)
(let ((n (length pointlist)))
(values (/ (reduce #'+ (mapcar #'x pointlist)) n)
(/ (reduce #'+ (mapcar #'y pointlist)) n))))
(defmethod calculate-centroid ((obj geom-line))
(when (centroid-p obj)
(multiple-value-bind (x y)
(centroid-of-pointlist
(list (p1 obj) (p2 obj)))
(setf (centroid obj)
(make-point (class-of-internal-points obj)
x y
:affected-by-matrix-p
(affected-by-matrix-p obj))))))
(defmethod calculate-centroid ((obj geom-chain-or-polygon))
(when (centroid-p obj)
(multiple-value-bind (x y)
(centroid-of-pointlist
(point-list obj))
(setf (centroid obj)
(make-point (class-of-internal-points obj)
x y
:affected-by-matrix-p
(affected-by-matrix-p obj))))))
(defmethod calculate-centroid ((obj geom-aggregate))
(when (centroid-p obj)
(multiple-value-bind (x y)
(centroid-of-pointlist
(mapcar #'centroid (has-parts obj)))
(setf (centroid obj)
(make-point (class-of-internal-points obj)
x y
:affected-by-matrix-p
(affected-by-matrix-p obj))))))
;;;
;;;
;;;
(defmethod calculate-bounding-box :after ((obj bounding-box-mixin)
&key reuse-internal-points-p)
(when (bounding-box-p obj)
(with-slots (radius pmin pmax pcenter) obj
(let ((xc (/ (+ (x pmin) (x pmax)) 2))
(yc (/ (+ (y pmin) (y pmax)) 2)))
(if (and reuse-internal-points-p pcenter)
(with-slots (x y) pcenter
(setf xc x
yc y))
(setf (pcenter obj) ; weg. Writer-After-Methode !
(make-point
(class-of-internal-points obj)
xc yc
:affected-by-matrix-p nil)))
(setf radius
(sqrt
(+ (expt (/ (- (x pmax) (x pmin)) 2) 2)
(expt (/ (- (y pmax) (y pmin)) 2) 2))))))))
(defmethod calculate-bounding-box ((obj geom-line)
&key reuse-internal-points-p)
(when (bounding-box-p obj)
(with-slots (pmin pmax p1 p2) obj
(let ((xmax (max (x p1) (x p2)))
(ymax (max (y p1) (y p2)))
(xmin (min (x p1) (x p2)))
(ymin (min (y p1) (y p2))))
(if (and reuse-internal-points-p pmin pmax)
(setf (x pmax) xmax
(y pmax) ymax
(x pmin) xmin
(y pmin) ymin)
(setf pmax (make-point
(class-of-internal-points obj)
xmax ymax
:affected-by-matrix-p nil)
pmin (make-point
(class-of-internal-points obj)
xmin ymin
:affected-by-matrix-p nil)))))))
(defmethod calculate-bounding-box-for-complex-object ((obj bounding-box-mixin) parts
&key reuse-internal-points-p)
(when (bounding-box-p obj)
(with-slots (pmin pmax) obj
(let ((xmin nil)
(ymin nil)
(xmax nil)
(ymax nil))
(dolist (part parts)
(dolist (point
(if (typep part 'bounding-box-mixin)
(list (pmin part)
(pmax part))
(list part)))
(let ((x (x point))
(y (y point)))
(when (or (not xmin) (< x xmin)) (setf xmin x))
(when (or (not xmax) (> x xmax)) (setf xmax x))
(when (or (not ymin) (< y ymin)) (setf ymin y))
(when (or (not ymax) (> y ymax)) (setf ymax y)))))
(if (and reuse-internal-points-p pmin pmax)
(setf (x pmin) xmin
(y pmin) ymin
(x pmax) xmax
(y pmax) ymax)
(setf pmin (make-point (class-of-internal-points obj)
xmin ymin
:affected-by-matrix-p nil)
pmax (make-point (class-of-internal-points obj)
xmax ymax
:affected-by-matrix-p nil)))))))
(defmethod calculate-bounding-box ((obj geom-chain-or-polygon)
&key reuse-internal-points-p)
(calculate-bounding-box-for-complex-object obj (segments obj)
:reuse-internal-points-p reuse-internal-points-p))
(defmethod calculate-bounding-box ((obj geom-aggregate)
&key reuse-internal-points-p)
(calculate-bounding-box-for-complex-object obj (has-parts obj)
:reuse-internal-points-p reuse-internal-points-p))
;;;
;;;
;;;
(defmethod recalculate-bounding-box ((obj bounding-box-mixin))
(calculate-bounding-box obj :reuse-internal-points-p t)
(setf (last-trafo-id obj) (trafo-id *matrix*)))
;;;
;;;
;;;
(defmethod invalidate-bounding-box ((obj bounding-box-mixin))
(setf (last-trafo-id obj) -2))
(defmethod invalidate-bounding-box ((obj geom-chain-or-polygon))
(dolist (segment (segments obj))
(invalidate-bounding-box segment))
(call-next-method))
(defmethod invalidate-bounding-box ((obj geom-aggregate))
(dolist (part (has-parts obj))
(invalidate-bounding-box part))
(call-next-method))
;;;
;;;
;;;
(defmethod parallel-p ((line1 geom-line) (line2 geom-line))
(let ((dx1 (- (x (p1 line1)) (x (p2 line1))))
(dx2 (- (x (p1 line2)) (x (p2 line2))))
(dy1 (- (y (p1 line1)) (y (p2 line1))))
(dy2 (- (y (p1 line2)) (y (p2 line2)))))
(or (zerop-eps (- (* dx1 dy2) (* dx2 dy1)))
(zerop-eps (- (* dx2 dy1) (* dx1 dy2))))))
(defmethod upright-p ((line1 geom-line) (line2 geom-line))
(let ((dx1 (- (x (p1 line1)) (x (p2 line1))))
(dx2 (- (x (p1 line2)) (x (p2 line2))))
(dy1 (- (y (p1 line1)) (y (p2 line1))))
(dy2 (- (y (p1 line2)) (y (p2 line2)))))
(zerop-eps
(+ (* dx1 dx2) (* dy1 dy2)))))
;;;
;;;
;;;
(defmethod calculate-intersection-point ((line1 geom-line) (line2 geom-line))
(when (member (calculate-relation line1 line2)
'(crosses touches))
(let* ((x1l1 (x (p1 line1)))
(y1l1 (y (p1 line1)))
(x2l1 (x (p2 line1)))
(y2l1 (y (p2 line1)))
(x1l2 (x (p1 line2)))
(y1l2 (y (p1 line2)))
(x2l2 (x (p2 line2)))
(y2l2 (y (p2 line2)))
(m1 (if (= x2l1 x1l1) 'infinit (/ (- y2l1 y1l1) (- x2l1 x1l1))))
(m2 (if (= x2l2 x1l2) 'infinit (/ (- y2l2 y1l2) (- x2l2 x1l2)))))
(cond
((or (and (eq m1 'infinit)
(eq m2 'infinit))
(and (not (or (eq m1 'infinit)
(eq m2 'infinit))) ; (= ..) schuetzen
(= m1 m2)))
(let ((p
(if (or (point-=-p (p1 line1)
(p1 line2))
(point-=-p (p1 line1)
(p2 line2)))
(p1 line1)
(p2 line1))))
(values (x p) (y p))))
((eq m1 'infinit)
(let* ((xs x2l1)
(ys (+ y1l2 (* m2 (- xs x1l2)))))
(values xs ys)))
((eq m2 'infinit)
(let* ((xs x2l2)
(ys (+ y1l1 (* m1 (- xs x1l1)))))
(values xs ys)))
(t
(let* ((xs (/ (- (* m1 x1l1) (* m2 x1l2) (- y1l1 y1l2))
(- m1 m2)))
(ys (+ y1l1 (* m1 (- xs x1l1)))))
(values xs ys)))))))
(defmethod calculate-intersection-line ((line1 geom-line) (line2 geom-line))
(let* ((x1l1 (x (p1 line1)))
(y1l1 (y (p1 line1)))
(x2l1 (x (p2 line1)))
(y2l1 (y (p2 line1)))
(x1l2 (x (p1 line2)))
(y1l2 (y (p1 line2)))
(x2l2 (x (p2 line2)))
(y2l2 (y (p2 line2))))
(multiple-value-bind (rel l1p1-l2 l1p2-l2 l2p1-l1 l2p2-l1)
(calculate-relation line1 line2 :detailed t)
(case rel
(equal (values x1l1 y1l1 x2l1 y2l1))
((inside covered-by) (values x1l1 y1l1 x2l1 y2l1))
((contains covers) (values x1l2 y1l2 x2l2 y2l2))
(overlaps (cond ((and l1p1-l2 l2p1-l1)
(values x1l1 y1l1 x1l2 y1l2))
((and l1p1-l2 l2p2-l1)
(values x1l1 y1l1 x2l2 y2l2))
((and l1p2-l2 l2p1-l1)
(values x2l1 y2l1 x1l2 y1l2))
((and l1p2-l2 l2p2-l1)
(values x2l1 y2l1 x2l2 y2l2))))))))
;;;
;;;
;;;
(defun distance-between* (x1 y1 x2 y2 &key (sqrt t) (sx 1) (sy 1))
(let* ((dx (/ (- x2 x1) sx))
(dy (/ (- y2 y1) sy)))
(if sqrt
(sqrt (+ (* dx dx) (* dy dy)))
(+ (* dx dx) (* dy dy)))))
(defmethod distance-between-xy ((x number) (y number)
(point geom-point)
&key (sqrt t) (sx 1) (sy 1))
(distance-between* x y (x point) (y point)
:sqrt sqrt :sx sx :sy sy))
(defmethod distance-between ((point1 geom-point)
(point2 geom-point)
&key (sqrt t) (sx 1) (sy 1))
(distance-between* (x point1) (y point1)
(x point2) (y point2)
:sqrt sqrt :sx sx :sy sy))
(defun distance-between-point-and-line (px py
lx1 ly1
lx2 ly2
&key (sqrt t) (sx 1) (sy 1))
(flet ((betw-0-and-1 (number)
(and (not (minusp number))
(<= number 1.0))))
(let* ((ax (/ (- lx2 lx1) sx))
(ay (/ (- ly2 ly1) sy))
(dx (/ (- lx1 px) sx))
(dy (/ (- ly1 py) sy))
(a2 (+ (* ax ax) (* ay ay)))
(scalar
(if (zerop-eps a2)
+big-int+
(/ (+ (* ax (- dx))
(* ay (- dy)))
a2)))
(x (+ dx
(* scalar ax)))
(y (+ dy
(* scalar ay)))
(res
(if (betw-0-and-1 scalar)
(+ (* x x) (* y y))
(min (distance-between* px py lx1 ly1 :sqrt nil :sx sx :sy sy)
(distance-between* px py lx2 ly2 :sqrt nil :sx sx :sy sy)))))
(if sqrt
(sqrt res)
res))))
(defmethod distance-between ((point geom-point)
(line geom-line)
&key (sqrt t) (sx 1) (sy 1))
(distance-between-point-and-line (x point)
(y point)
(x (p1 line))
(y (p1 line))
(x (p2 line))
(y (p2 line))
:sqrt sqrt :sx sx :sy sy))
(defmethod distance-between-xy ((x number) (y number)
(line geom-line)
&key (sqrt t) (sx 1) (sy 1))
(distance-between-point-and-line x
y
(x (p1 line))
(y (p1 line))
(x (p2 line))
(y (p2 line))
:sqrt sqrt :sx sx :sy sy))
(defmethod distance-between ((line geom-line)
(point geom-point)
&key (sqrt t) (sx 1) (sy 1))
(distance-between point line :sqrt sqrt :sx sx :sy sy))
(defmethod distance-between ((line1 geom-line)
(line2 geom-line)
&key (sqrt t) (sx 1) (sy 1))
(let* ((d1
(distance-between (p1 line1) line2 :sqrt sqrt :sx sx :sy sy))
(d2
(distance-between (p2 line1) line2 :sqrt sqrt :sx sx :sy sy))
(d3
(distance-between (p1 line2) line1 :sqrt sqrt :sx sx :sy sy))
(d4
(distance-between (p2 line2) line1 :sqrt sqrt :sx sx :sy sy)))
(if (intersects-p line1 line2)
0
(min d1 d2 d3 d4))))
(defmethod distance-between ((line geom-line)
(poly geom-chain-or-polygon)
&key (sqrt t) (sx 1) (sy 1))
(loop as i in (segments poly) minimize
(distance-between i line :sqrt sqrt :sx sx :sy sy)))
(defmethod distance-between ((poly geom-chain-or-polygon)
(line geom-line)
&key (sqrt t) (sx 1) (sy 1))
(distance-between line poly :sqrt sqrt :sx sx :sy sy))
(defmethod distance-between ((poly1 geom-chain-or-polygon)
(poly2 geom-chain-or-polygon)
&key (sqrt t) (sx 1) (sy 1))
(loop as i in (segments poly1) minimize
(distance-between i poly2 :sqrt sqrt :sx sx :sy sy)))
(defmethod distance-between ((point geom-point)
(poly geom-chain-or-polygon)
&key (sqrt t) (sx 1) (sy 1))
(loop as i in (segments poly) minimize
(distance-between point i :sqrt sqrt :sx sx :sy sy)))
(defmethod distance-between-xy ((x number) (y number)
(poly geom-chain-or-polygon)
&key (sqrt t) (sx 1) (sy 1))
(loop as i in (segments poly) minimize
(distance-between-xy x y i :sqrt sqrt :sx sx :sy sy)))
(defmethod distance-between ((poly geom-chain-or-polygon)
(point geom-point)
&key (sqrt t) (sx 1) (sy 1))
(distance-between point poly :sqrt sqrt :sx sx :sy sy))
;;;
;;;
;;;
(defun angle-between* (x1 y1 x2 y2)
(let* ((dx (- x2 x1))
(dy (- y2 y1))
(phi
(phase (complex dx dy))))
(if (minusp phi)
(+ +2pi+ phi)
phi)))
(defun distance-and-orientation* (x1 y1 x2 y2)
(multiple-value-call
#'values
(distance-between* x1 y1 x2 y2)
(angle-between* x1 y1 x2 y2)))
(defun normalize (angle)
(mod angle +2pi+))
(defun angle-difference (a b)
(min
(normalize
(- a b))
(normalize
(- b a))))
;;;
;;;
;;;
(defmethod length-of-line ((line geom-line))
(distance-between (p1 line) (p2 line)))
(defmethod global-orientation ((line geom-line))
(angle-between* (x (p1 line)) (y (p1 line)) (x (p2 line)) (y (p2 line))))
#|
(defmethod angle-between ((line1 geom-line) (line2 geom-line))
"Draw line1 around nearest point w.r.t. line2 counterclockwise and measure angle!"
(let* ((d11 (distance-between (p1 line1) (p1 line2)))
(d21 (distance-between (p2 line1) (p1 line2)))
(d12 (distance-between (p1 line1) (p2 line2)))
(d22 (distance-between (p2 line1) (p2 line2)))
(dmin (min d11 d21 d12 d22)))
(multiple-value-bind (as ae bs be)
(cond ((= dmin d11) (values (p1 line1) (p2 line1) (p1 line2) (p2 line2)))
((= dmin d12) (values (p1 line1) (p2 line1) (p2 line2) (p1 line2)))
((= dmin d21) (values (p2 line1) (p1 line1) (p1 line2) (p2 line2)))
((= dmin d22) (values (p2 line1) (p1 line1) (p2 line2) (p1 line2))))
(normalize (- (angle-between* (x as) (y as) (x ae) (y ae))
(angle-between* (x bs) (y bs) (x be) (y be)))))))
|#
;;;
;;;
;;;
(defmethod calculate-area ((obj geom-polygon))
(with-slots (point-list) obj
(let ((f 0)
(first (first point-list))
(last (first (last point-list))))
(mapc #'(lambda (pj pj+1 pj-1)
(let ((xj (x pj))
(yj+1 (y pj+1))
(yj-1 (y pj-1)))
(incf f (* xj (- yj+1 yj-1)))))
point-list
(append (rest point-list) (list first))
(cons last point-list))
(/ f 2))))
;;;
;;;
;;;
(defun det-0-vecs (x1 y1 x2 y2)
(- (* x1 y2)
(* x2 y1)))
(defun det (x1s y1s x1e y1e
x2s y2s x2e y2e)
(let ((x1 (- x1e x1s))
(y1 (- y1e y1s))
(x2 (- x2e x2s))
(y2 (- y2e y2s)))
(- (* x1 y2)
(* x2 y1))))
(defun my-asin (length-of-a length-of-hypothenuse signum-x signum-y)
(let ((angle (asin (/ length-of-a
length-of-hypothenuse))))
(cond ((and (plusp signum-x) (plusp signum-y)) angle)
((and (minusp signum-x) (plusp signum-y)) (- pi angle))
((and (minusp signum-x) (minusp signum-y)) (- (* 3/2 pi) angle))
(t (- +2pi+ angle)))))
(defun proportional-2-point (o1x o1y a1x a1y
o2x o2y a2x a2b)
(let* ((rot (normalize (- (angle-between* o2x o2y a2x a2b)
(angle-between* o1x o1y a1x a1y))))
(scale (/ (distance-between* o2x o2y a2x a2b)
(distance-between* o1x o1y a1x a1y))))
(values scale rot)))
#| fehlerhaft !
(defun fixed-sy-2-point (o1x o1y a1x a1y
o2x o2y a2x a2y)
(labels ((do-it (o1x o1y a1x a1y
o2x o2y a2x a2y inv-p)
(let ((x (- a1x o1x))
(y (- a1y o1y))
(a (- a2x o2x))
(b (- a2y o2y)))
(unless (zerop x)
(let* ((r1 (sqrt (+ (* a a) (* b b))))
(alpha
(my-asin y
r1
(signum x) (signum y)))
(cos-alpha (cos alpha)))
(unless (zerop cos-alpha)
(let* ((alpha2 (angle-between* o2x o2y a2x a2y))
(gamma (- alpha2 alpha))
(sx (abs (/ (+ a (* (sin gamma) y))
(* x (cos gamma))))))
(multiple-value-bind (sx gamma)
(if inv-p
(progn (princ "!")
(values (/ 1 sx) (- gamma)))
(values sx gamma))
(let ((m (make-matrix))
(o1 (p o1x o1y))
(a1 (p a1x a1y)))
(with-matrix (m)
(reset m)
(translate m (- o1x) (- o1y))
(scale m sx 1)
(rotate m gamma)
(translate m o2x o2y)
(mapc #'(lambda (l)
(format t "~% ~A ~A -> ~A ~A" (first l) (second l) (third l) (fourth l)))
(list (list (x o1) (y o1) o2x o2y)
(list (x a1) (y a1) a2x a2y)))))
(values sx gamma)))))))))
(let* ((a (- a2x o2x))
(b (- a2y o2y))
(y (- a1y o1y)))
(if (< (abs y) (sqrt (+ (* a a) (* b b))))
(do-it o1x o1y a1x a1y
o2x o2y a2x a2y nil)
(do-it
o2x o2y a2x a2y
o1x o1y a1x a1y t)))))
|#
| 37,078 | Common Lisp | .lisp | 1,132 | 28.091873 | 104 | 0.613439 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 8c84cc85830d574f5b890bd085435995be5d45aa7eb134a4d56c3e8e58ba5948 | 11,693 | [
-1
] |
11,694 | box-relations.lisp | lambdamikel_VISCO/src/GEOMETRY/box-relations.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GEOMETRY; Base: 10 -*-
(in-package geometry)
(defgeneric point-truly-inside-box-p (point box)
(:documentation "Determine if point is contained by box. If point lies on the border of the box,
returns NIL."))
(defgeneric point-truly-outside-box-p (point box)
(:documentation "Determine if point is outside box. If point lies on the border of the box,
returns NIL."))
(defgeneric box-inside-box-p (box1 box2)
(:documentation "Determine whether box1 is inside box2. If box1 touches box2 from the inside,
returns T."))
(defgeneric box-truly-inside-box-p (box1 box2)
(:documentation "Determine whether box1 is inside box2. If box1 touches box2 from the inside,
returns NIL."))
(defgeneric box-overlaps-box-p (box1 box2)
(:documentation "Determine whether box1 overlaps box2. If only the borders intersect, but not their
interiors, returns T."))
(defgeneric box-truly-overlaps-box-p (box1 box2)
(:documentation "Determine whether box1 overlaps box2. If only the borders intersect, but not their
interiors, returns NIL."))
(defgeneric box-touches-box-p (box1 box2)
(:documentation "Determine whether box1 touches box2. This is the case, if
only the borders of the boxes intersect, but not their interiors."))
(defgeneric line-intersects-box-border-p (line box)
(:documentation "Determine whether line intersects the border of box. Intersections between the
interior and the line will be ignorerd."))
(defgeneric enlarged-box-overlaps-box-p (obj box r)
(:documentation "Enlarge box in all directions by R and determine wheter box and the bounding box of
obj are overlapping."))
;;;
;;; BOX-Relationen
;;;
(defun point-truly-inside-box-p* (x y box)
(and (< (x (pmin box)) x (x (pmax box)))
(< (y (pmin box)) y (y (pmax box)))))
(defmethod point-truly-inside-box-p ((point geom-point) (box bounding-box-mixin))
(point-truly-inside-box-p* (x point) (y point) box))
(defun point-truly-outside-box-p* (x y box)
(or (> x (x (pmax box)))
(< x (x (pmin box)))
(> y (y (pmax box)))
(< y (y (pmin box)))))
(defmethod point-truly-outside-box-p ((point geom-point) (box bounding-box-mixin))
(point-truly-outside-box-p (x point) (y point) box))
;;;
;;;
;;;
(defun box-inside-box-p* (xmin1 ymin1 xmax1 ymax1
xmin2 ymin2 xmax2 ymax2)
(and (>= xmin1 xmin2)
(>= ymin1 ymin2)
(<= xmax1 xmax2)
(<= ymax1 ymax2)))
(defmethod box-inside-box-p ((box1 bounding-box-mixin) (box2 bounding-box-mixin))
(box-inside-box-p* (x (pmin box1))
(y (pmin box1))
(x (pmax box1))
(y (pmax box1))
(x (pmin box2))
(y (pmin box2))
(x (pmax box2))
(y (pmax box2))))
;;;
;;;
;;;
(defun box-truly-inside-box-p* (xmin1 ymin1 xmax1 ymax1
xmin2 ymin2 xmax2 ymax2)
(and (> xmin1 xmin2)
(> ymin1 ymin2)
(< xmax1 xmax2)
(< ymax1 ymax2)))
(defmethod box-truly-inside-box-p ((box1 bounding-box-mixin) (box2 bounding-box-mixin))
(box-truly-inside-box-p* (x (pmin box1))
(y (pmin box1))
(x (pmax box1))
(y (pmax box1))
(x (pmin box2))
(y (pmin box2))
(x (pmax box2))
(y (pmax box2))))
;;;
;;;
;;;
(defun box-overlaps-box-p* (xmin1 ymin1 xmax1 ymax1
xmin2 ymin2 xmax2 ymax2)
(and (<= xmin2 xmax1)
(<= ymin2 ymax1)
(>= xmax2 xmin1)
(>= ymax2 ymin1)))
(defmethod box-overlaps-box-p ((box1 bounding-box-mixin) (box2 bounding-box-mixin))
(box-overlaps-box-p* (x (pmin box1))
(y (pmin box1))
(x (pmax box1))
(y (pmax box1))
(x (pmin box2))
(y (pmin box2))
(x (pmax box2))
(y (pmax box2))))
;;;
;;;
;;;
(defun box-truly-overlaps-box-p* (xmin1 ymin1 xmax1 ymax1
xmin2 ymin2 xmax2 ymax2)
(and (< xmin2 xmax1)
(< ymin2 ymax1)
(> xmax2 xmin1)
(> ymax2 ymin1)))
(defmethod box-truly-overlaps-box-p ((box1 bounding-box-mixin) (box2 bounding-box-mixin))
(box-truly-overlaps-box-p* (x (pmin box1))
(y (pmin box1))
(x (pmax box1))
(y (pmax box1))
(x (pmin box2))
(y (pmin box2))
(x (pmax box2))
(y (pmax box2))))
;;;
;;;
;;;
(defun box-touches-box-p* (xmin1 ymin1 xmax1 ymax1
xmin2 ymin2 xmax2 ymax2)
(and (not (box-truly-overlaps-box-p* xmin1 ymin1 xmax1 ymax1
xmin2 ymin2 xmax2 ymax2))
(box-overlaps-box-p* xmin1 ymin1 xmax1 ymax1
xmin2 ymin2 xmax2 ymax2)))
(defmethod box-touches-box-p ((box1 bounding-box-mixin) (box2 bounding-box-mixin))
(box-touches-box-p* (x (pmin box1))
(y (pmin box1))
(x (pmax box1))
(y (pmax box1))
(x (pmin box2))
(y (pmin box2))
(x (pmax box2))
(y (pmax box2))))
;;;
;;;
;;;
(defun line-intersects-box-border-p* (x1 y1 x2 y2 b)
(let ((xmin (x (pmin b)))
(ymin (y (pmin b)))
(xmax (x (pmax b)))
(ymax (y (pmax b))))
(labels ((code (x y)
(let ((bit1 (< x xmin))
(bit2 (> x xmax))
(bit3 (< y ymin))
(bit4 (> y ymax)))
(values bit1 bit2 bit3 bit4))))
(multiple-value-bind (c1 c2 c3 c4)
(code x1 y1)
(multiple-value-bind (ca cb cc cd)
(code x2 y2)
(and (not
(or (and c1 ca) ; ein gemeinsames Bit ? (OR ...) => VOLLSTAENDIG UNSICHTBAR
(and c2 cb)
(and c3 cc)
(and c4 cd)))
(=> (not (or c1 c2 c3 c4 ca cb cc cd)) ; vollst. innen
(or (= x1 xmin) ; liegt auf Rand ?
(= x1 xmax)
(= x2 xmin)
(= x2 xmax)
(= y1 ymin)
(= y1 ymax)
(= y2 ymin)
(= y2 ymax)))))))))
(defmethod line-intersects-box-border-p ((line geom-line) (box bounding-box-mixin))
(and
(=> (and (bounding-box-p line)
(bounding-box-p box))
(box-overlaps-box-p line box))
(line-intersects-box-border-p* (x (p1 line))
(y (p1 line))
(x (p2 line))
(y (p2 line))
box)))
;;;
;;;
;;;
(defmethod enlarged-box-overlaps-box-p ((box1 bounding-box-mixin)
(box2 bounding-box-mixin) r)
(box-overlaps-box-p* (- (x (pmin box1)) r) (- (y (pmin box1)) r)
(+ (x (pmax box1)) r) (+ (y (pmax box1)) r)
(x (pmin box2)) (y (pmin box2))
(x (pmax box2)) (y (pmax box2))))
| 6,348 | Common Lisp | .lisp | 185 | 28.762162 | 102 | 0.610458 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 9308eef5520f965352a3bff4a5c17d6da745f26ffc2d77d0f2c42e93f64fb01c | 11,694 | [
-1
] |
11,695 | equal.lisp | lambdamikel_VISCO/src/GEOMETRY/equal.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GEOMETRY; Base: 10 -*-
(in-package geometry)
(defgeneric equal-p (obj1 obj2)
(:documentation "Returns t, if both objects are semantically equivalent."))
;;;
;;; Equal-Relation
;;;
(defmethod equal-p ((obj1 geom-thing) (obj2 geom-thing))
nil)
(defmethod equal-p ((obj1 geom-point) (obj2 geom-point))
(point-=-p obj1 obj2))
(defmethod equal-p ((obj1 geom-line) (obj2 geom-line))
(line-=-p obj1 obj2))
(defmethod equal-for-complex-objects-p ((obj1 geom-thing) (obj2 geom-thing)
(access-fn function))
(and (= (length (funcall access-fn obj1))
(length (funcall access-fn obj2)))
(every #'(lambda (i)
(= 1
(count-if #'(lambda (j)
(equal-p i j))
(funcall access-fn obj2))))
(funcall access-fn obj1))))
(defmethod equal-p ((obj1 geom-chain-or-polygon) (obj2 geom-chain-or-polygon))
(equal-for-complex-objects-p obj1 obj2 #'segments))
(defmethod equal-p ((obj1 geom-aggregate) (obj2 geom-aggregate))
(equal-for-complex-objects-p obj1 obj2 #'has-parts))
| 1,081 | Common Lisp | .lisp | 27 | 36 | 78 | 0.676015 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 3726a9e6e5afa51a99629c372ce1785ffaa9e8c486fadd2c09cecd21611cae10 | 11,695 | [
-1
] |
11,696 | tree-structure.lisp | lambdamikel_VISCO/src/GEOMETRY/tree-structure.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GEOMETRY; Base: 10 -*-
(in-package geometry)
(defmethod primary-p ((obj geom-thing))
(null (part-of obj)))
;;;
;;;
;;;
(defmethod component-p ((component geom-thing)
(master geom-thing))
nil)
(defmethod component-p ((component geom-point)
(master geom-line))
(or (eq (p1 master) component)
(eq (p2 master) component)))
(defmethod component-p ((component geom-thing)
(master geom-chain-or-polygon))
(or (member component (segments master))
(some #'(lambda (segment)
(component-p component segment))
(segments master))))
(defmethod component-p ((component geom-thing)
(master geom-aggregate))
(or (member component (has-parts master))
(some #'(lambda (part)
(component-p component part))
(has-parts master))))
;;;
;;;
;;;
(defun for-each-master-holds-p (obj fn)
(if obj
(every #'(lambda (master)
(and (funcall fn master)
(for-each-master-holds-p master fn)))
(part-of obj))
t))
(defun for-each-component-holds-p (obj fn)
(if obj
(every #'(lambda (comp)
(and (funcall fn comp)
(for-each-component-holds-p comp fn)))
(get-direct-components obj))
t))
(defun for-some-master-holds-p (obj fn)
(if obj
(some #'(lambda (master)
(or (funcall fn master)
(for-some-master-holds-p master fn)))
(part-of obj))
nil))
(defun for-some-component-holds-p (obj fn)
(if obj
(some #'(lambda (comp)
(or (funcall fn comp)
(for-some-component-holds-p comp fn)))
(get-direct-components obj))
nil))
;;;
;;;
;;;
(defun get-already-present-direct-master (&rest components)
(let ((i
(reduce #'intersection
(mapcar #'part-of components))))
(if (null (rest i))
(first i)
(error 'geom-error :descr "More than one master object!"))))
(defun get-topmost-common-master (&rest components)
(reduce #'intersection
(mapcar #'get-topmost-master components)))
(defun get-topmost-master (obj)
(let ((res nil))
(labels ((do-it (obj)
(let ((masters (part-of obj)))
(if masters
(dolist (master masters)
(do-it master))
(pushnew obj res)))))
(do-it obj)
res)))
(defun get-direct-common-master (&rest components)
(reduce #'intersection
(mapcar #'part-of components)))
(defun get-direct-common-master-from-list (components)
(reduce #'intersection
(mapcar #'part-of components)))
;;;
;;;
;;;
(defmethod get-direct-components ((obj geom-thing))
nil)
(defmethod get-direct-components ((obj geom-line))
(point-list obj))
(defmethod get-direct-components ((obj geom-chain-or-polygon))
(segments obj))
(defmethod get-direct-components ((obj geom-aggregate))
(has-parts obj))
;;;
;;;
;;;
(defmethod get-all-masters ((obj geom-thing))
(let ((res nil))
(dolist (master (part-of obj))
(setf res
(nconc (cons master (get-all-masters master)) res)))
res))
(defmethod get-all-components ((obj geom-thing))
(let ((res nil))
(dolist (part (get-direct-components obj))
(setf res
(nconc (cons part (get-all-components part)) res)))
res))
#|
(defmethod get-all-masters ((obj geom-point))
(cons obj
(mapcan #'get-all-masters
(append (centroid-of obj)
(pcenter-of obj)
(part-of obj)))))
|#
;;;
;;;
;;;
(defmethod common-root-p ((obj1 geom-thing) (obj2 geom-thing))
(or (eq obj1 obj2)
(intersection
(get-all-masters obj1)
(get-all-masters obj2))))
(defun for-each-parent-execute (obj fn)
(when obj
(funcall fn obj)
(dolist (master (part-of obj))
(for-each-parent-execute master fn))))
#|
(defmethod common-root-p ((obj1 geom-thing) (obj2 geom-thing))
(labels ((for-each-parent-execute (obj fn)
(funcall fn obj)
(mapc #'(lambda (slot)
(dolist (ma (funcall slot obj))
(for-each-parent-execute ma fn)))
(typecase obj
(geom-point
(list #'part-of #'centroid-of #'pcenter-of))
(t (list #'part-of))))
nil)
(set-it (obj value)
(for-each-parent-execute obj
#'(lambda (obj)
(with-slots (cp-flag) obj
(setf cp-flag value)))))
(test-it (obj value)
(for-each-parent-execute obj
#'(lambda (obj)
(with-slots (cp-flag) obj
(when (and (numberp cp-flag)
(= cp-flag value))
(return-from test-it t)))))))
(let ((value (get-new-mark)))
(set-it obj1 value)
(test-it obj2 value))))
|#
| 4,512 | Common Lisp | .lisp | 161 | 23.515528 | 77 | 0.631212 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 7362db541fb7a9643a439a0393203e114ceca924433c7cf6d28a00168254a377 | 11,696 | [
-1
] |
11,697 | epsilon2.lisp | lambdamikel_VISCO/src/GEOMETRY/epsilon2.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GEOMETRY; Base: 10 -*-
(in-package geometry)
(defgeneric inside-epsilon-p (obj1 obj2 radius &key epsilon-a epsilon-b)
(:documentation "Determine whether obj1 lies inside the epsilon-enclosure
of radius of object obj2."))
;;;
;;;
;;;
(defconstant +granularity+ 2)
(defmethod make-arc ((pfrom geom-point)
(pto geom-point)
xc yc)
(multiple-value-bind (radius from)
(distance-and-orientation* xc yc (x pfrom) (y pfrom))
(multiple-value-bind (radius1 to)
(distance-and-orientation* xc yc (x pto) (y pto))
(if (=-eps radius radius1 0.00001)
(let* ((lastp pfrom)
(collect nil)
(diff (normalize (- to from)))
(fac (/ diff +granularity+))
(res
(dotimes (i (1- +granularity+) collect)
(let* ((angle (+ from (* (1+ i) fac)))
(x (+ xc (* radius (cos angle))))
(y (+ yc (* radius (sin angle)))))
(let ((p (p x y)))
(push
(l lastp p)
collect)
(setf lastp p))))))
(append (reverse res)
(list
(l lastp pto))))
(error "Bad points!")))))
(defun make-circle (x y radius)
(let* ((lastp nil)
(firstx nil)
(firsty nil)
(collect nil)
(fac (/ (* 2 pi) +granularity+))
(res
(dotimes (i +granularity+ collect)
(let* ((angle (* i fac))
(x (+ x (* radius (cos angle))))
(y (+ y (* radius (sin angle)))))
(let ((p (p x y)))
(if lastp
(push
(l lastp p)
collect)
(setf firstx x
firsty y))
(setf lastp p))))))
(cons (l
lastp
(p firstx firsty))
res)))
(defmethod create-epsilon-enclosure ((obj geom-point) (radius number))
(make-circle (x obj) (y obj) radius))
(defmethod get-epsilon-enclosure-relevant-points ((obj geom-line) (radius number))
(multiple-value-bind (p1fx p1fy
p1tx p1ty
p2fx p2fy
p2tx p2ty)
(get-epsilon-enclosure-relevant-points* obj radius)
(let ((p1f (p p1fx p1fy))
(p1t (p p1tx p1ty))
(p2f (p p2fx p2fy))
(p2t (p p2tx p2ty)))
(values p1f p1t p2f p2t))))
(defmethod get-epsilon-enclosure-relevant-points* ((obj geom-line) (radius number))
(with-slots (p1 p2) obj
(let ((alpha (global-orientation obj)))
(labels ((calc-pf (x y)
(values (- x (* radius (sin alpha)))
(+ y (* radius (cos alpha)))))
(calc-pt (x y)
(values (+ x (* radius (sin alpha)))
(- y (* radius (cos alpha))))))
(multiple-value-bind (p1fx p1fy)
(calc-pf (x p1) (y p1))
(multiple-value-bind (p1tx p1ty)
(calc-pt (x p1) (y p1))
(multiple-value-bind (p2fx p2fy)
(calc-pf (x p2) (y p2))
(multiple-value-bind (p2tx p2ty)
(calc-pt (x p2) (y p2))
(values p1fx p1fy
p1tx p1ty
p2fx p2fy
p2tx p2ty)))))))))
(defmethod create-epsilon-enclosure ((obj geom-line) (radius number))
(with-slots (p1 p2) obj
(multiple-value-bind (p1f p1t p2f p2t)
(get-epsilon-enclosure-relevant-points obj radius)
(poly
(append
(make-arc p1f p1t (x p1) (y p1))
(list (l p1t p2t))
(make-arc p2t p2f (x p2) (y p2))
(list (l p2f p1f)))))))
#| nicht notwendig (und auch nicht korrekt)...
(defmethod create-epsilon-enclosure ((obj geom-chain) (radius number))
(with-slots (segments) obj
(let ((lines nil)
(first-segment (first segments))
(last-segment (first (last segments))))
(mapc #'(lambda (i j)
(multiple-value-bind (p1fi p1ti p2fi p2ti)
(get-epsilon-enclosure-relevant-points i radius)
(multiple-value-bind (p1fj p1tj p2fj p2tj)
(get-epsilon-enclosure-relevant-points j radius)
(let ((li (l p1ti p2ti))
(lj (l p1tj p2tj)))
(cond ((crosses-p li lj)
(multiple-value-bind (ix iy)
(calculate-intersection-point li lj)
(let ((ip (p ix iy)))
(push (l p1ti ip) lines)
(push (l ip p2tj) lines))))
((point-=-p p2ti p1tj)
(push (l p1ti p2tj) lines))
(t (push li lines)
(setf lines
(append (reverse (make-arc p2ti p1tj (x (p2 i)) (y (p2 i)))) lines))
(push lj lines)))))))
segments (rest segments))
(multiple-value-bind (p1f p1t p2f p2t)
(get-epsilon-enclosure-relevant-points last-segment radius)
(setf lines
(append (reverse (make-arc p2t p2f (x (p2 last-segment)) (y (p2 last-segment)))) lines)))
(mapc #'(lambda (i j)
(multiple-value-bind (p1fi p1ti p2fi p2ti)
(get-epsilon-enclosure-relevant-points i radius)
(multiple-value-bind (p1fj p1tj p2fj p2tj)
(get-epsilon-enclosure-relevant-points j radius)
(let ((li (l p2fi p1fi))
(lj (l p2fj p1fj)))
(cond ((crosses-p li lj)
(multiple-value-bind (ix iy)
(calculate-intersection-point li lj)
(let ((ip (p ix iy)))
(push (l p2fi ip) lines)
(push (l ip p1fj) lines))))
((point-=-p p1fi p2fj)
(push (l p2fi p1fj) lines))
(t (push li lines)
(setf lines
(append (reverse (make-arc p1fi p2fj (x (p1 i)) (y (p1 i)))) lines))
(push lj lines)))))))
(reverse segments) (rest (reverse segments)))
(multiple-value-bind (p1f p1t p2f p2t)
(get-epsilon-enclosure-relevant-points first-segment radius)
(setf lines
(append (reverse (make-arc p1f p1t (x (p1 first-segment)) (y (p1 first-segment)))) lines)))
(reverse lines))))
|#
;;;
;;;
;;;
(defmethod inside-epsilon-p ((obj1 geom-point) (obj2 geom-thing) radius &key (epsilon-a 1) (epsilon-b 1))
(let ((radius (* radius radius)))
(<= (distance-between obj1 obj2 :sqrt nil :sx epsilon-a :sy epsilon-b) radius)))
(defmethod inside-epsilon-p* ((x number) (y number) (obj geom-thing) radius &key (epsilon-a 1) (epsilon-b 1))
(let ((radius (* radius radius)))
(<= (distance-between-xy x y obj :sqrt nil :sx epsilon-a :sy epsilon-b) radius)))
;;;
;;;
;;;
(defmethod inside-epsilon-p ((obj1 geom-line) (obj2 geom-point) radius &key (epsilon-a 1) (epsilon-b 1))
(let ((radius (* radius radius)))
(and (<= (distance-between (p1 obj1) obj2 :sqrt nil :sx epsilon-a :sy epsilon-b) radius)
(<= (distance-between (p2 obj1) obj2 :sqrt nil :sx epsilon-a :sy epsilon-b) radius))))
(defmethod inside-epsilon-p ((obj1 geom-line) (obj2 geom-line) radius &key (epsilon-a 1) (epsilon-b 1))
(let ((radius (* radius radius)))
(and (<= (distance-between (p1 obj1) obj2 :sqrt nil :sx epsilon-a :sy epsilon-b) radius)
(<= (distance-between (p2 obj1) obj2 :sqrt nil :sx epsilon-a :sy epsilon-b) radius))))
(defmethod inside-epsilon-p ((obj1 geom-line) (obj2 geom-chain-or-polygon) radius &key (epsilon-a 1) (epsilon-b 1))
(let ((radius (* radius radius)))
(labels ((do-it (x1 y1 x2 y2 mindist)
(if (< (distance-between* x1 y1 x2 y2 :sqrt nil :sx epsilon-a :sy epsilon-b) mindist)
t
(let ((mx (/ (+ x1 x2) 2))
(my (/ (+ y1 y2) 2)))
(and (some #'(lambda (segment)
(<= (distance-between-point-and-line mx my
(x (p1 segment))
(y (p1 segment))
(x (p2 segment))
(y (p2 segment))
:sqrt nil
:sx epsilon-a :sy epsilon-b)
radius))
(segments obj2))
(do-it x1 y1 mx my mindist)
(do-it mx my x2 y2 mindist))))))
(and (<= (distance-between (p1 obj1) obj2 :sqrt nil :sx epsilon-a :sy epsilon-b) radius)
(<= (distance-between (p2 obj1) obj2 :sqrt nil :sx epsilon-a :sy epsilon-b) radius)
(do-it (x (p1 obj1)) (y (p1 obj1))
(x (p2 obj1)) (y (p2 obj1))
(/ (length-of-line obj1) 20)))))) ; 20 Teilstrecken untersuchen!
;;;
;;;
;;;
(defmethod inside-epsilon-p ((obj1 geom-chain-or-polygon) (obj2 geom-point) radius &key (epsilon-a 1) (epsilon-b 1))
(let ((radius (* radius radius)))
(every #'(lambda (p)
(<= (distance-between p obj2 :sqrt nil :sx epsilon-a :sy epsilon-b) radius))
(point-list obj1))))
(defmethod inside-epsilon-p ((obj1 geom-chain-or-polygon) (obj2 geom-line) radius &key (epsilon-a 1) (epsilon-b 1))
(let ((radius (* radius radius)))
(every #'(lambda (p)
(<= (distance-between p obj2 :sqrt nil :sx epsilon-a :sy epsilon-b) radius))
(point-list obj1))))
(defmethod inside-epsilon-p ((obj1 geom-chain-or-polygon) (obj2 geom-chain-or-polygon) radius &key (epsilon-a 1) (epsilon-b 1))
(every #'(lambda (s)
(inside-epsilon-p obj1 s radius :epsilon-a epsilon-a :epsilon-b epsilon-b))
(segments obj2)))
| 8,435 | Common Lisp | .lisp | 219 | 32.863014 | 127 | 0.609304 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | ec3654710c4ede1bea40f3a7b9ab6e1d9cae32f4534d87f87e076a275ba5c262 | 11,697 | [
-1
] |
11,698 | interse4.lisp | lambdamikel_VISCO/src/GEOMETRY/interse4.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GEOMETRY; Base: 10 -*-
(in-package geometry)
(defgeneric lies-on-p (point obj)
(:documentation "Determine whether point lies on obj.
If obj is a polygon, this means the border of obj.
The point may conincide with one of the component points of obj => T."))
(defgeneric lies-on-p* (x y obj)
(:documentation "Determine whether point (x,y) lies on obj.
If obj is a polygon, this means the border of obj.
The point may conincide with one of the component points of obj => T."))
(defgeneric intersects-p (obj1 obj2)
(:documentation "Determine whether obj1 and obj2 intersect. If one of the objects is a polygon (or both),
only the border is considered, not the interior. A point obj1 intersects-p an obj2 (line, polygon or chain),
if lies-on-p holds."))
(defgeneric touches-p (line1 line2)
(:documentation "Determine whether line1 and line2 have only one common intersection point. Line1 and
line2 may not cross each other. A joins-p relation may be a touches-p relation."))
(defgeneric crosses-p (line obj)
(:documentation "Determine whether line crosses obj. There must be exactly one common
intersection point. This point may not coincide with one of the component points of line or obj.
No joins-p relation can ever be a crosses-p relation. touches-p and crosses-p are disjoint."))
(defgeneric 1d-intersects-p (line1 line2)
(:documentation "Determine whether line1 and line2 are parallel and share a common piece of a line.
A joins-p relations may be a 1d-intersects-p relation. Crosses-p, touches-p and 1d-intersects-p are
disjoint."))
;;;
;;; intersects-p(line1,line2) => touches-p \/ crosses-p \/ 1d-intersects-p
;;;
(defgeneric 0d-touches-p (line poly-or-chain)
(:documentation "Determine whether there is a poly-or-chain segment which touches-p the line.
Also, no crosses-p relation between line and poly-or-chain may hold."))
(defgeneric 1d-touches-p (line poly-or-chain)
(:documentation "Determine whether there is a poly-or-chain segment which 1d-intersects-p the line.
Also, no crosses-p relation between line and poly-or-chain may hold."))
;;;
;;; LIES-ON
;;;
(defmethod lies-on-p* (x y (line geom-line))
(or
(zerop (ccw* (x (p1 line))
(y (p1 line))
(x (p2 line))
(y (p2 line))
x y))
(zerop (ccw* (x (p2 line))
(y (p2 line))
(x (p1 line))
(y (p1 line))
x y))))
(defmethod lies-on-p ((point geom-point) (line geom-line))
(or
(zerop (ccw (p1 line) (p2 line) point))
(zerop (ccw (p2 line) (p1 line) point))))
;;;
;;; INTERSECTS
;;;
(defmethod intersects-p ((point geom-point) (line geom-line))
(lies-on-p point line))
(defmethod intersects-p ((line geom-line) (point geom-point))
(lies-on-p point line))
;;;
;;; LIES-ON
;;;
(defmethod lies-on-p* (x y (poly-or-chain geom-chain-or-polygon))
(some #'(lambda (segment)
(lies-on-p* x y segment))
(segments poly-or-chain)))
(defmethod lies-on-p ((point geom-point) (poly-or-chain geom-chain-or-polygon))
(some #'(lambda (segment)
(lies-on-p point segment))
(segments poly-or-chain)))
;;;
;;; INTERSECTS
;;;
(defmethod intersects-p ((point geom-point) (poly-or-chain geom-chain-or-polygon))
(lies-on-p point poly-or-chain))
(defmethod intersects-p ((poly-or-chain geom-chain-or-polygon) (point geom-point))
(lies-on-p point poly-or-chain))
;;;
;;;
;;;
(defun intersects-p* (xs1 ys1 xe1 ye1
xs2 ys2 xe2 ye2)
(let* ((a (ccw* xs1 ys1
xe1 ye1
xs2 ys2))
(b (ccw* xs1 ys1
xe1 ye1
xe2 ye2))
(c (ccw* xs2 ys2
xe2 ye2
xs1 ys1))
(d (ccw* xs2 ys2
xe2 ye2
xe1 ye1)))
(and
(<= (* a b) 0.0) (<= (* c d) 0.0))))
(defun crosses-p* (xs1 ys1 xe1 ye1
xs2 ys2 xe2 ye2)
(let* ((a (ccw* xs1 ys1
xe1 ye1
xs2 ys2))
(b (ccw* xs1 ys1
xe1 ye1
xe2 ye2))
(c (ccw* xs2 ys2
xe2 ye2
xs1 ys1))
(d (ccw* xs2 ys2
xe2 ye2
xe1 ye1)))
(when (and (<= (* a b) 0.0) (<= (* c d) 0.0)) ; Schnitt liegt vor
(not (or (zerop a)
(zerop b)
(zerop c)
(zerop d)
(zerop (ccw* xe1 ye1
xs1 ys1
xs2 ys2))
(zerop (ccw* xe1 ye1
xs1 ys1
xe2 ye2))
(zerop (ccw* xe2 ye2
xs2 ys2
xs1 ys1))
(zerop (ccw* xe2 ye2
xs2 ys2
xe1 ye1)))))))
;;;
;;; INTERSECTS
;;;
(defmethod intersects-p ((l1 geom-line) (l2 geom-line))
(and (=> (and (bounding-box-p l1)
(bounding-box-p l2))
(box-overlaps-box-p l1 l2))
(let* ((l1p1 (p1 l1))
(l2p1 (p1 l2))
(l1p2 (p2 l1))
(l2p2 (p2 l2))
(a (ccw l1p1 l1p2 l2p1))
(b (ccw l1p1 l1p2 l2p2))
(c (ccw l2p1 l2p2 l1p1))
(d (ccw l2p1 l2p2 l1p2)))
(and
(<= (* a b) 0.0) (<= (* c d) 0.0)))))
;;;
;;; CROSSES
;;;
(defmethod crosses-p ((l1 geom-line) (l2 geom-line)) ; "X" oder "+"
(and (=> (and (bounding-box-p l1)
(bounding-box-p l2))
(box-truly-overlaps-box-p l1 l2))
(let* ((l1p1 (p1 l1))
(l2p1 (p1 l2))
(l1p2 (p2 l1))
(l2p2 (p2 l2))
(a (ccw l1p1 l1p2 l2p1))
(a1 (ccw l1p2 l1p1 l2p1))
(b (ccw l1p1 l1p2 l2p2))
(b1 (ccw l1p2 l1p1 l2p2))
(c (ccw l2p1 l2p2 l1p1))
(c1 (ccw l2p2 l2p1 l1p1))
(d (ccw l2p1 l2p2 l1p2))
(d1 (ccw l2p2 l2p1 l1p2)))
(and (not (or (zerop a)
(zerop a1)
(zerop b)
(zerop b1)
(zerop c)
(zerop c1)
(zerop d)
(zerop d1)))
(<= (* a b) 0) (<= (* c d) 0)))))
;;;
;;; TOUCHES
;;;
(defmethod touches-p ((l1 geom-line) (l2 geom-line)) ; z.B. meets ("--"), aber auch "T" oder "\/"
(and (=> (and (bounding-box-p l1)
(bounding-box-p l2))
(box-overlaps-box-p l1 l2))
(let ((l1p1-l2 (lies-on-p (p1 l1) l2))
(l1p2-l2 (lies-on-p (p2 l1) l2))
(l2p1-l1 (lies-on-p (p1 l2) l1))
(l2p2-l1 (lies-on-p (p2 l2) l1)))
(or (and l1p1-l2 (not l1p2-l2) (not l2p1-l1) (not l2p2-l1)) ; "T"-Faelle
(and (not l1p1-l2) l1p2-l2 (not l2p1-l1) (not l2p2-l1))
(and (not l1p1-l2) (not l1p2-l2) l2p1-l1 (not l2p2-l1))
(and (not l1p1-l2) (not l1p2-l2) (not l2p1-l1) l2p2-l1)
(and (joins-p l1 l2) ; "--" und "\/"-Faelle
(not (or (and l1p1-l2 l1p2-l2) ; 1d-schnitte ausschliessen
(and l2p1-l1 l2p2-l1))))))))
;;;
;;; 1D-INTERSECTS
;;;
(defmethod 1d-intersects-p ((l1 geom-line) (l2 geom-line)) ; overlaps, contains, covers, equal + Inverse
(and (=> (and (bounding-box-p l1)
(bounding-box-p l2))
(box-truly-overlaps-box-p l1 l2))
(let ((l1p1-l2 (lies-on-p (p1 l1) l2))
(l1p2-l2 (lies-on-p (p2 l1) l2))
(l2p1-l1 (lies-on-p (p1 l2) l1))
(l2p2-l1 (lies-on-p (p2 l2) l1)))
(or (and l1p1-l2 (not l1p2-l2) l2p1-l1 (not l2p2-l1) ; overlaps-faelle
(not (point-=-p (p1 l1) (p1 l2)))) ; touches ausschliessen
(and l1p1-l2 (not l1p2-l2) (not l2p1-l1) l2p2-l1
(not (point-=-p (p1 l1) (p2 l2))))
(and (not l1p1-l2) l1p2-l2 l2p1-l1 (not l2p2-l1)
(not (point-=-p (p2 l1) (p1 l2))))
(and (not l1p1-l2) l1p2-l2 (not l2p1-l1) l2p2-l1
(not (point-=-p (p2 l1) (p2 l2))))
(and l1p1-l2 l1p2-l2 (not l2p1-l1) (not l2p2-l1)) ; l1 contains l2
(and (not l1p1-l2) (not l1p2-l2) l2p1-l1 l2p2-l1)
(and l1p1-l2 l1p2-l2 l2p1-l1 l2p2-l1) ; equal
(and l1p1-l2 (not l1p2-l2) l2p1-l1 l2p2-l1) ; l1 covers l2
(and (not l1p1-l2) l1p2-l2 l2p1-l1 l2p2-l1)
(and l1p1-l2 l1p2-l2 l2p1-l1 (not l2p2-l1)) ; l2 covers l1
(and l1p1-l2 l1p2-l2 (not l2p1-l1) l2p2-l1)))))
;;;
;;; INTERSECTS
;;;
(defmethod intersects-p ((line geom-line) (poly-or-chain geom-chain-or-polygon))
(and (=> (and (bounding-box-p line)
(bounding-box-p poly-or-chain))
(box-overlaps-box-p line poly-or-chain))
(some #'(lambda (segment)
(intersects-p line segment))
(segments poly-or-chain))))
(defmethod intersects-p ((poly-or-chain geom-chain-or-polygon) (line geom-line))
(intersects-p line poly-or-chain))
;;;
;;; CROSSES
;;;
(defmethod crosses-p ((line geom-line) (poly-or-chain geom-chain-or-polygon))
(and (=> (and (bounding-box-p line)
(bounding-box-p poly-or-chain))
(box-overlaps-box-p line poly-or-chain))
(some #'(lambda (segment)
(crosses-p line segment))
(segments poly-or-chain))))
;;;
;;; 0D-TOUCHES
;;;
(defmethod 0d-touches-p ((line geom-line) (poly-or-chain geom-chain-or-polygon))
(and (=> (and (bounding-box-p line)
(bounding-box-p poly-or-chain))
(box-overlaps-box-p line poly-or-chain))
(some #'(lambda (segment)
(touches-p line segment))
(segments poly-or-chain))
(not (crosses-p line poly-or-chain))))
(defmethod 0d-touches-p ((poly-or-chain geom-chain-or-polygon) (line geom-line))
(0d-touches-p line poly-or-chain))
;;;
;;; 1D-TOUCHES
;;;
(defmethod 1d-touches-p ((line geom-line) (poly-or-chain geom-chain-or-polygon))
(and (=> (and (bounding-box-p line)
(bounding-box-p poly-or-chain))
(box-overlaps-box-p line poly-or-chain))
(some #'(lambda (segment)
(1d-intersects-p line segment))
(segments poly-or-chain))
(not (crosses-p line poly-or-chain))))
(defmethod 1d-touches-p ((poly-or-chain geom-chain-or-polygon) (line geom-line))
(1d-touches-p line poly-or-chain))
;;;
;;; INTERSECTS
;;;
(defmethod intersects-p ((poly-or-chain1 geom-chain-or-polygon) (poly-or-chain2 geom-chain-or-polygon))
(and (=> (and (bounding-box-p poly-or-chain1)
(bounding-box-p poly-or-chain2))
(box-overlaps-box-p poly-or-chain1 poly-or-chain2))
(some #'(lambda (segment)
(intersects-p poly-or-chain1 segment))
(segments poly-or-chain2))))
| 9,873 | Common Lisp | .lisp | 275 | 31.029091 | 108 | 0.615279 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 92f756da63c5c4c9dee23f99d242ec3177197d3db287e31f3204064f59332473 | 11,698 | [
-1
] |
11,699 | inside3.lisp | lambdamikel_VISCO/src/GEOMETRY/inside3.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GEOMETRY; Base: 10 -*-
(in-package geometry)
(defgeneric inside-p (obj1 obj2)
(:documentation "Determine whether obj2 contains obj1. If obj1 touches obj2 from the inside,
returns NIL."))
(defgeneric outside-p (obj1 obj2)
(:documentation "Determine whether obj1 is outside of obj2. If obj1 touches obj2, returns NIL."))
(defgeneric inside-p* (x y obj)
(:documentation "Determine whether obj contains point (x,y). If (x,y) lies on border of obj,
returns NIL."))
(defgeneric outside-p* (x y obj)
(:documentation "Determine whether (x y) is outside of obj. If (x,y) lies on border of obj,
returns NIL."))
;;;
;;; Inside-Relation
;;;
(defparameter *cur-line* ; willkuerlich gewaehlt
(l
(p 0 0)
(p 1 1)
:bounding-box-p nil))
(defparameter *test-beam* ; willkuerlich gewaehlt
(l
(p 0 0)
(p 1 1)
:bounding-box-p nil))
(defun count-intersections* (x y polygon)
(let* ((points (point-list polygon))
(count 0)
(from-point nil)
(cur-point nil)
(mark-point '?)
(flag nil))
(setf
(x (p1 *test-beam*)) x
(y (p1 *test-beam*)) y
(x (p2 *test-beam*)) +big-int+
(y (p2 *test-beam*)) y)
(loop until (eq mark-point 'stop)
do ; einmal ganz rum
(setf cur-point (first points)
points (rest points))
(when (null points)
(setf points (point-list polygon)))
(when (eq cur-point mark-point)
(setf mark-point 'stop))
(cond ((and (= y (y cur-point)) ; Zeit sparen...
(<= x (x cur-point))
(lies-on-p cur-point *test-beam*))
(setf flag t))
(t
(if (not from-point) ; noch kein erster Pkt. gefunden
(progn
(setf mark-point cur-point) ; merken => einmal rum!
(setf flag nil)
(setf from-point cur-point))
(progn
(cond (flag ; es lagen Punkte zwischen from-point und cur-point a.d. Teststrahl
(when (or (<= (y from-point) y (y cur-point))
(>= (y from-point) y (y cur-point)))
(incf count)))
(t ; es lagen keine Pkt. a.d. Teststrahl
(setf (p1 *cur-line*) from-point)
(setf (p2 *cur-line*) cur-point)
(let ((p1c (p1 *cur-line*))
(p2c (p2 *cur-line*))
(p1t (p1 *test-beam*))
(p2t (p2 *test-beam*)))
(when (not (and (= (x p1c) (x p2c) x)))
(when (intersects-p* (x p1c) (y p1c) (x p2c) (y p2c)
(slot-value p1t 'x) (slot-value p1t 'y)
(slot-value p2t 'x) (slot-value p2t 'y))
(incf count))))))
(setf flag nil)
(setf from-point cur-point))))))
count))
(defun count-intersections (point polygon)
(count-intersections* (x point) (y point) polygon))
;;;
;;; ACHTUNG: ALLE INSIDE/OUTSIDE-RELATIONEN SIND "TRULY"-INSIDE => RAND GEHOERT NICHT DAZU !!!
;;;
(defmethod inside-p* (x y (polygon geom-polygon))
(and
(=> (bounding-box-p polygon)
(point-truly-inside-box-p* x y polygon))
(not (lies-on-p* x y polygon))
(oddp (count-intersections* x y polygon))))
(defmethod inside-p ((point geom-point) (polygon geom-polygon))
(inside-p* (x point) (y point) polygon))
(defmethod outside-p* (x y (polygon geom-polygon))
(or
(and (bounding-box-p polygon)
(point-truly-outside-box-p* x y polygon))
(and
(not (lies-on-p* x y polygon))
(evenp (count-intersections* x y polygon)))))
(defmethod outside-p ((point geom-point) (polygon geom-polygon))
(outside-p* (x point) (y point) polygon))
;;;
;;;
;;;
(defmethod inside-p ((line geom-line) (poly geom-polygon))
(and (=> (and (bounding-box-p line)
(bounding-box-p poly))
(box-truly-inside-box-p line poly))
(not (intersects-p line poly))
(inside-p (p1 line) poly)
(inside-p (p2 line) poly)))
(defmethod outside-p ((line geom-line) (poly geom-polygon))
(or (and (bounding-box-p line)
(bounding-box-p poly)
(not (box-overlaps-box-p line poly)))
(and (not (intersects-p line poly))
(outside-p (p1 line) poly)
(outside-p (p2 line) poly))))
;;;
;;;
;;;
(defmethod inside-p ((poly-or-chain geom-chain-or-polygon) (poly geom-polygon))
(and (=> (and (bounding-box-p poly-or-chain)
(bounding-box-p poly))
(box-truly-inside-box-p poly-or-chain poly))
(every #'(lambda (segment)
(inside-p segment poly))
(segments poly-or-chain))))
(defmethod outside-p ((poly-or-chain geom-chain-or-polygon) (poly geom-polygon))
(or (and (bounding-box-p poly-or-chain)
(bounding-box-p poly)
(not (box-overlaps-box-p poly-or-chain poly)))
(every #'(lambda (segment)
(outside-p segment poly))
(segments poly-or-chain))))
| 4,708 | Common Lisp | .lisp | 132 | 30.356061 | 99 | 0.624107 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 21a4f61b553237565dd899c94b6b203df4c15234afc4cdde83afd10c1bb5788a | 11,699 | [
-1
] |
11,700 | reldef3.lisp | lambdamikel_VISCO/src/GEOMETRY/reldef3.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GEOMETRY; Base: 10 -*-
(in-package geometry)
(defgeneric calculate-relation (obj1 obj2 &rest rest)
(:documentation "Recognizes various spatial relationships between obj1 and obj2."))
;;;
;;; Punkt-Relationen (Punkt ist erstes Argument)
;;;
(defun inverse (rel)
(case rel
(contains 'inside)
(inside 'contains)
(covered-by 'covers)
(covers 'covered-by)
(otherwise rel)))
(defmethod calculate-relation ((p geom-point) (l geom-line) &rest rest)
(declare (ignore rest))
(if (lies-on-p p l)
'lies-on
'disjoint))
(defmethod calculate-relation ((l geom-line) (p geom-point) &rest rest)
(declare (ignore rest))
(inverse
(calculate-relation p l)))
;;;
;;; Strecken-Relationen (Strecke ist erstes Argument)
;;;
(defmethod calculate-relation ((l1 geom-line) (l2 geom-line) &key (detailed nil))
(if (and (bounding-box-p l1)
(bounding-box-p l2)
(not (box-overlaps-box-p l1 l2)))
'disjoint
(let* ((l1p1 (p1 l1))
(l2p1 (p1 l2))
(l1p2 (p2 l1))
(l2p2 (p2 l2))
(a (ccw l1p1 l1p2 l2p1))
(b (ccw l1p1 l1p2 l2p2))
(c (ccw l2p1 l2p2 l1p1))
(d (ccw l2p1 l2p2 l1p2)))
(cond ((and (<= (* a b) 0.0) (<= (* c d) 0.0)) ; Schnitt liegt vor
(let* ((l1p1-l2 (lies-on-p (p1 l1) l2))
(l1p2-l2 (lies-on-p (p2 l1) l2))
(l2p1-l1 (lies-on-p (p1 l2) l1))
(l2p2-l1 (lies-on-p (p2 l2) l1))
(n (+ (if l1p1-l2 1 0)
(if l1p2-l2 1 0)
(if l2p1-l1 1 0)
(if l2p2-l1 1 0))))
(let ((res
(ecase n
(0 'crosses) ; "X"
(1 'touches) ; "T"
(3
(if detailed
(if (and l1p1-l2 l1p2-l2)
'covered-by
'covers)
'1d-intersects)) ; "covers", "covered-by"
(4 'equal)
(2 (if (joins-p l1 l2)
'touches ; "--", "\/"
(if detailed
(if (and l1p1-l2 l1p2-l2)
'inside
(if (and l2p1-l1 l2p2-l1)
'contains
'overlaps))
'1d-intersects)))))) ; "contains", "inside", "overlaps"
(if detailed
(values res l1p1-l2 l1p2-l2 l2p1-l1 l2p2-l1)
res))))
(t 'disjoint)))))
| 2,172 | Common Lisp | .lisp | 72 | 24.541667 | 85 | 0.574458 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 346e1f3dec943b37d1d8c7962dbfc26da9d28dafe118c7eb522bdce3d7119087 | 11,700 | [
-1
] |
11,701 | os2.lisp | lambdamikel_VISCO/src/DB/os2.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: DATABASE; Base: 10 -*-
(in-package database)
(defparameter *os*
'(("*** Strassen-Splitter ***" 8888 linie 1 1)
("Zollgrenze" 75 17 text 1 20)
("Abrenzung der BAB, usw. geg. Ausfahrt, unsichtbar" 3105 linie 1 3)
("Abgrenzung flaechenhafter Gewaesser, unsichtbar" 5005 linie 1 13)
("Abgrenzung zu anderen Ebenen, unsichtbar" 3805 linie 1 5)
("Acker" 4114 flaeche 1 18)
("AKN-Bahn" 3548 symbol 4 6)
("AKN-Bahn, oberirdisch" 3241 linie 1 10)
("AKN-Bahn, oberirdisch" (3241 2002) linie 1 11)
("AKN-Station" 3248 symbol 1 10)
("Auffahrt auf BAB, BAB-aehnlich, B" 3152 linie 1 3)
("Auffahrt auf BAB, BAB-aehnlich, B unter Eb 6 und 7" 3852 1 5)
("Autobahn-Anschluss" 3517 text 4 2)
("Autobahnkreuz" 3507 text 4 2)
("B-Symbol (Bundesstrassenschild)" 3138 symbol-mit-text 1 2)
("BAB" 3114 flaeche 1 3)
("BAB unter Eb. 6 und 7" 3814 flaeche 1 5)
("BAB-aehnlich" 3124 flaeche 1 3)
("BAB-aehnlich unter Eb. 6 und 7" 3824 flaeche 1 5)
("BAB-aehnlich, Mittellinie" 3123 linie 1 3)
("BAB-aehnlich, Mittellinie" (3123 2002) linie 1 2)
("BAB-aehnlich, Mittellinie unter Eb 6 und 7" 3823 linie 1 4)
("BAB-aehnlich, Randbegrenzung" 3122 linie 1 3)
("BAB-aehnlich, Randbegrenzung unter Eb 6 und 7" 3822 linie 1 5)
("BAB-Anschlusstelle" 3157 text 1 2)
("BAB-Kreuz" 3117 text 1 2)
("BAB-Mittellinie" 3113 linie 1 2)
("BAB-Mittellinie" (3113 2002) linie 1 3)
("BAB-Mittellinie unter Eb 6 und 7" 3813 linie 1 4)
("BAB-Randbegrenzung" 3112 linie 1 3)
("BAB-Randbegrenzung unter Eb 6 und 7" linie 1 5)
("BAB-Schild" 3568 symbol-mit-text 4 6)
("BAB-Symbol" 3118 symbol-mit-text 1 2)
("BAB-Tunnel, Randbegrenzung" 3612 linie 1 2)
("Bahnbetriebsgelaende" 3264 flaeche 1 11)
("Baublockgrenze" 7291 linie 2 10)
("Baublockgrenze, im Gewaesser" 7295 linie 2 10)
("Baublocknummer" 7297 text 2 20)
("Baublockzusammengehoerigkeit" 7298 symbol 2 12)
("Berg-Hoehenzahl" 7309 text 1 18)
("Bergname" 7307 text 1 18)
("Bezirksgrenzband, Abgrenzung aussen (60 m)" 7222 linie 2 21)
("Bezirksgrenzband, Abgrenzung Mitte (30 m)" 7223 linie 2 21)
("Bezirksgrenze" 7221 linie 2 3)
("Bezirksgrenze, Grenzband 1" 7224 flaeche 2 21)
("Bezirksgrenze, Grenzband 2" 7226 flaeche 2 21)
("Bezirksname" 7227 text 1 24)
("Blattschnitt (Bearbeitungsgrenze fuer Schrift)" 1131 linie 1 24)
("Brachflaeche" 4404 flaeche 1 18)
("Bruecke" 3009 linie 1 6)
("Brueckenname" 3007 text 1 6)
("Bundesbahn, unterirdisch" (3711 2002) linie 1 11)
("Bundesbahn, oberirdisch" 3211 linie 1 10)
("Bundesbahn, oberirdisch" (3211 2002) linie 1 11)
("Bundesbahn, unterirdisch" 3711 linie 1 10)
("Bundesstrasse" 3134 flaeche 1 3)
("Bundesstrasse" 3132 linie 1 3)
("Bundesstrasse" 3558 symbol-mit-text 4 6)
("Bundesstrasse unter Eb 6 und 7" 3834 flaeche 1 5)
("Bundesstrasse unter Eb 6 und 7" 3832 linie 1 5)
("Busendhaltestelle" 3206 symbol-mit-text 3 10)
("Buslinie" 3201 linie 3 10)
("Buslinien-Nummer" 3204 text 3 10)
("Busstation" 3200 symbol 3 10)
("Campingplatz" 2244 flaeche 1 18)
("Campingplatz" 2248 symbol 1 18)
("Deich, Damm" 4011 linie 1 18)
("Deich, Damm" 4018 symbol-an-linie 1 18)
("Denkmal" 9308 symbol 1 19)
("DGK-5-Bezeichnung" 1118 text 1 1)
("Dock" 5724 flaeche 1 13)
("Dock" 5721 linie 1 13)
("Europastrasse" 3578 symbol-mit-text 4 6)
("Europastrasse (Schild)" 3109 symbol-mit-text 1 2)
("Fernsehturm" 9418 symbol 1 19)
("Feuerwehr" 8271 symbol 1 19)
("Feuerwehr" 8558 symbol 4 6)
("flaechenhafte Gewaesserbegr., schiffbar, unt. Ebene 6 und 7" 5302 linie 1 15)
("flaechenhafte Gewaesserbegr., nicht schiffbar, unt. Ebene 6 und 7" 5402 linie 1 15)
("flaechenh. Gewaesserbegr., nicht schiffbar" 5202 linie 1 13)
("flaechenh. Gewaesserbegr., schiffbar" 5102 linie 1 13)
("Fliessrichtungspfeil" 5018 symbol 1 12)
("Flughafen" 3318 symbol 1 25)
("Flughafen- topographie" 3309 linie 1 25)
("Fluss, nicht schiffbar" 5234 flaeche 1 13)
("Fluss, nicht schiffbar, unter Eb 6 und 7" 5434 flaeche 1 15)
("Fluss, schiffbar" 5134 flaeche 1 13)
("Fluss, schiffbar, unter Eb 6 und 7" 5334 flaeche 1 15)
("Freihafengrenze" 7511 linie 1 20)
("Friedhof" 2254 flaeche 1 18)
("Friedhof" 2258 symbol 1 18)
("Friedhof fuer Nichtchristen" 2256 symbol 1 18)
("Friedhofsname" 2257 text 1 18)
("Funkmast" 9408 symbol 1 19)
("Fussgaengerzone" 3194 flaeche 1 7)
("Gehoelz" 4254 flaeche 1 18)
("Gemeinde/Stadtteil" 7527 text 4 3)
("Gemeindegrenze" 7271 linie 2 8)
("Gemeindename (auch Name einer Samtgemeinde)" 7277 text 2 18)
("Gewaechshaus" 4154 flaeche 1 18)
("Gewaesser" 5517 text 4 5)
("Gewaessername" 5017 text 1 12)
("Gitterpunkte fuer das Einpassen von Vorlagen" 1119 punkt 2 1)
("GK-Gitterlinie 1 km" 1121 linie 2 1)
("GK-Gitterlinie 2 km" 1111 linie 2 1)
("Grenzen einer Mitgliedsgemeinde einer Samtgemeinde" 7276 linie 2 8)
("Grenze statistisches Gebiet" 7281 linie 2 9)
("Grenze statistisches Gebiet, gleichz. Ortsteilgr." (7281 7215) linie 2 11)
("Grenze statistisches Gebiet, im Gewaesser" 7285 linie 2 9)
("Hafen" 5254 flaeche 1 13)
("Hafen unter Eb 6 und 7" 5354 flaeche 1 15)
("Hafengebietsgrenze (Zustaendigkeit Strom- und Hafenbau)" 7652 linie 2 27)
("Hauptverkehrsstrasse, Tunnel" 3642 linie 1 2)
("Hauptverkehrsstrasse" 3142 linie 1 3)
("Hauptverkehrsstrasse unter Eb 6 und 7" 3842 linie 1 5)
("Hausnummer" 2327 text 1 19)
("Heide" 4344 flaeche 1 18)
("Heide" 4348 symbol 1 18)
("Hilfslinie" 0000 linie 1 6)
("Hochspannungsleitung" 9001 linie 1 22)
("Hochspannungsleitung" 9007 text 1 22)
("Hochspannungsmast" 9008 symbol 1 22)
("Hochspannungspfeil" 9018 symbol 1 22)
("Hochwasserschutzanlage (nicht Deich 4011/18!)" 5821 linie 1 12)
("Industrie/Gewerbe" 2140 flaeche 1 17)
("Kanal, nicht schiffbar" 5244 flaeche 1 13)
("Kanal, nicht schiffbar, unter Eb 6 und 7" 5444 flaeche 1 15)
("Kanal, schiffbar" 5144 flaeche 1 13)
("Kanal, schiffbar, unter Eb 6 und 7" 5344 flaeche 1 15)
("Kapelle" 8141 symbol 1 19)
("Kilometrierung BAB, BAB-aehnlich" 3108 symbol 1 2)
("Kilometrierung BAB, BAB-aehnlich" 3107 text 1 2)
("Kirche" 8140 symbol 1 19)
("Kirche" 8540 symbol 4 6)
("Kleingarten" 2234 flaeche 1 18)
("Kleingarten" 2238 symbol 1 18)
("Kleingartennummer(-name)" 2237 text 1 18)
("Kontur fuer oeffentliches Gebaeude" 2312 linie 1 19)
("Krankenhaus" 8151 symbol 1 19)
("Kreisgrenze" 7261 linie 2 7)
("Kreisname" 7267 test 2 17)
("Kuestenbereich" 4334 flaeche 1 18)
("Kuestenbereich" 4338 symbol-an-linie 1 18)
("Landesgrenzband, Abgrenzung aussen (100 m)" 7212 linie 2 21)
("Landesgrenzband, Abgrenzung Mitte (50 m)" 7213 linie 2 21)
("Landesgrenze" 7211 linie 2 2)
("Landesgrenze, Grenzband 1" 7214 flaeche 2 21)
("Landesgrenze, Grenzband 2" 7216 flaeche 2 21)
("Landschaftsname" 7217 text 1 18)
("Landungsbruecke, Anlegestelle" 5831 linie 1 12)
("Landungsbruecke, Anlegestelle" (5831 2002) linie 1 13)
("Laubbaum" 4218 symbol 1 18)
("Laubholz" 4268 symbol 1 18)
("Laubwald" 4214 flaeche 1 18)
("linienh. Kanal, Graben, schiffbar, unter Eb 6 und 7" (5321 2002) linie 1 15)
("linienh. Kanal, Graben, nicht schiffbar, unter Eb 6 und 7" 5421 linie 1 14)
("linienh. Kanal, Graben, nicht schiffbar, unter Eb 6 und 7" (5421 2002) linie 1 15)
("linienh. Kanal, Graben, schiffbar, unter Eb 6 und 7" 5321 linie 1 14)
("linienh. Bach, nicht schiffbar" 5211 linie 1 12)
("linienh. Bach, nicht schiffbar" (5211 2002) linie 1 13)
("linienh. Bach, nicht schiffbar, unter Eb 6 und 7" 5411 linie 1 14)
("linienh. Bach, nicht schiffbar, unter Eb 6 und 7" (5411 2002) linie 1 15)
("linienh. Kanal, Graben, nicht schiffbar" (5221 2002) linie 1 13)
("linienh. Kanal, Graben, nicht schiffbar" 5221 linie 1 12)
("linienh. Kanal, Graben, schiffbar" 5121 linie 1 12)
("linienh. Kanal, Graben, schiffbar" (5121 2002) linie 1 13)
("Mischwald" 4234 flaeche 1 18)
("Mole" 5841 linie 1 13)
("Moor, Sumpf" 4314 flaeche 1 18)
("Moor, Sumpf" 4318 symbol 1 18)
("Nadelbaum" 4228 symbol 1 18)
("Nadelholz" 4258 symbol 1 18)
("Nadelwald" 4223 flaeche 1 18)
("Name des Naturschutzgebiets" 7427 text 1 23)
("Name einer Mitgliedsgemeinde einer Samtgemeinde" 7270 text 2 18)
("Name fuer Kai, Hoeft, Anlegestelle" 5837 text 1 12)
("Name wichtiger oeffentlicher Gebaeude" 2317 text 1 19)
("Naturschutzgebietsgrenze" 7422 linie 1 23)
("Nebenbahn (Hafenb., Rangieranl. usw.), unterirdisch" 3751 linie 1 10)
("Nebenbahn (Hafenb., Rangieranl. usw.), oberirdisch" 3251 linie 1 10)
("Nebenbahn (Hafenb., Rangieranl. usw.), oberirdisch" (3251 2002) linie 1 11)
("Nummer eines statistischen Gebiets" 7287 text 2 19)
("Nutzungsartengrenze, unsichtbar" 9005 linie 1 16)
("Nutzungsartengrenze" 2002 linie 1 16)
("Obstanbau" 4134 flaeche 1 18)
("Ortsamtsgebietsgrenze" 7231 linie 2 4)
("Ortsamtsgebietsname" 7237 text 2 14)
("Ortschaften/Ortsteil" 7557 text 4 3)
("Ortsteilgrenze" 7251 linie 2 6)
("Ortsteilname" 7257 text 2 16)
("Ortsteilnummer" 7259 text 2 26)
("oeffentliches Gebaeude" 2314 flaeche 1 19)
("P+R-Symbol" 3208 symbol 1 10)
("Park, mit Einzelsymbolen" 2224 flaeche 1 18)
("Parksname" 2227 text 1 18)
("Parkplatz" 3100 flaeche 1 9)
("Platz, z.B. Marktplatz, Rastplatz, Festplatz" 3104 flaeche 1 9)
("Platzname" 3106 text 1 9)
("Polizei" 8171 symbol 1 19)
("Postamt" 8113 symbol 1 19)
("Ring 1-3 (Schild)" 3148 symbol-mit-text 1 2)
("S-Bahn" 3528 symbol 4 6)
("S-Bahn, oberirdisch" 3221 linie 1 10)
("S-Bahn, oberirdisch" (3221 2002) linie 1 11)
("S-Bahn, unterirdisch" 3721 linie 1 10)
("S-Bahn, unterirdisch" (3721 2002) linie 1 11)
("S-Bahn-Station" 3228 symbol 1 10)
("Samtgemeindegrenze" 7279 linie 2 8)
("Sandbank" 5714 flaeche 1 13)
("Schiffahrtslinie" 3411 linie 1 12)
("Schiffsverkehr (Be- und Entladen)" 3424 flaeche 1 13)
("Schleuse" 5811 linie 1 12)
("Schleusenname" 5817 text 1 12)
("See, nicht schiffbar" 5264 flaeche 1 13)
("See, nicht schiffbar, unter Eb 6 und 7" 5464 flaeche 1 15)
("See, schiffbar" 5164 flaeche 1 13)
("See, schiffbar, unter Eb 6 und 7" 5364 flaeche 1 15)
("Seegras" 4358 symbol 1 18)
("Segelflughafen" 3328 symbol 1 25)
("Sonderbezeichnung (z.B. Wandsbek-Gartenstadt)" 7207 text 2 22)
("Sonstige Strasse" 3162 linie 1 7)
("Sontige Strasse, Tunnel" 3662 linie 1 6)
("Sportplatz" 2218 symbol 1 18)
("Sportplatzbegrenzung" 2212 linie 1 18)
("Sportplatzinnenflaeche" 2214 flaeche 1 18)
("Sportplatzname" 2217 text 1 18)
("Stadtteilgrenze" 7241 linie 2 5)
("Stadtteilname" 7247 text 2 15)
("Stationsname" 3207 text 1 10)
("Strassenname, BAB-aehnlich" 3127 text 1 2)
("Strassenname, Bundesstrasse" 3137 text 1 2)
("Strassenname, Hauptverkehrsstrasse" 3147 text 1 2)
("Strassenname" 3167 1 6)
("Teich, nicht schiffbar" 5274 flaeche 1 13)
("Teich, nicht schiffbar, unter Eb 6 und 7" 5474 flaeche 1 15)
("topographische Grenze" 4002 linie 1 16)
("Treppe" 3168 symbol 1 6)
("Treppenbegrenzung" 3171 linie 1 6)
("U-Bahn" 3538 symbol 4 6)
("U-Bahn, oberirdisch" 3231 linie 1 10)
("U-Bahn, oberirdisch" (3231 2002) 1 11)
("U-Bahn, unterirdisch" 3731 linie 1 10)
("U-Bahn, unterirdisch" (3731 2002) linie 1 11)
("U-Bahn-Station" 3238 symbol 1 10)
("Verkehrsbegleitgruen" 4004 flaeche 1 18)
("Wanderweg" 9803 linie 1 27)
("Wanderwegbezeichnung" 9808 symbol 1 27)
("Watt" 5214 flaeche 1 6)
("Weg, Hintegrund in Flaechenfarbe" 3182 linie 1 6)
("Wiese, Weide" 4124 flaeche 1 18)
("Wiese, Weide" 4128 symbol 1 18)
("Wohnen" 2110 flaeche 1 17)
("Zoo" 2264 flaeche 1 18)
("Zustandsbezeichnung, z.B. Container-Terminal, o.ae." 7337 text 1 18)
("zusaetzliche Topographie (keine Nutzungsgrenze)" 9002 linie 1 16)))
(setf *os*
(sort *os*
'string< :key #'(lambda (i) (string-upcase (first i)))))
;;;
;;;
;;;
(defparameter *how-to-interpret-os*
'( ;;; Top Level Polygone = FL => in Segmente zerlegen, Polygone finden
;;; die einzigen "ganzen" Objekte
;;; Format:
;;; 1: OS 2: Name 3: SQD-Typ(en) 4: transformierte(r) DB-Typ(en) 5: Konstruktor-Funktion(en)
;;;
(nil nil PG db-point pg-create-point)
(3147 "Strassenname" TX map-text tx-create-map-text)
(3207 "Stationsname" TX map-text tx-create-map-text)
(2317 "Name von wichtigem oeffentlichen Gebaeude" TX map-text tx-create-map-text)
(5017 "Gewaessername" TX map-text tx-create-map-text)
(2327 "Hausnummer" TX map-text tx-create-map-text)
(3167 "Strassenname" TX map-text tx-create-map-text)
(4114 "Acker" FL db-polygon fl-create-containing-polygon)
(2110 "Wohngebiet" FL db-polygon fl-create-containing-polygon)
(4124 "Wiese/Weide" FL db-polygon fl-create-containing-polygon)
(4004 "Verkehrsbegleitgruen" FL db-polygon fl-create-containing-polygon)
(5274 "Teich" FL db-polygon fl-create-containing-polygon)
(2214 "Sportplatz" FL db-polygon fl-create-containing-polygon)
(3104 "Marktplatz" FL db-polygon fl-create-containing-polygon)
(2224 "Parkplatz" FL db-polygon fl-create-containing-polygon)
(2224 "Park" FL db-polygon fl-create-containing-polygon)
(2314 "Schule" FL db-polygon fl-create-containing-polygon)
(2234 "Kleingartengebiet" FL db-polygon fl-create-containing-polygon)
(2140 "Gewerbegebiet" FL db-polygon fl-create-containing-polygon)
(2254 "Friedhof" FL db-polygon fl-create-containing-polygon)
(4404 "Brachflaeche" FL db-polygon fl-create-containing-polygon)
(3114 "BAB" FL db-line fl-do-nothing)
;;; Top Level Linien = SN oder LI => alle SN in Segmente zerlegen (=> Ketten bilden ?)
;;; xxx* = Teilstueck von "xxx" (z.B. Segment = Teilstueck eines Baches,
;;; oder Segment = Teilstueck des Randes eines Polygones)
(5211 "Bach*" (LI BO SN) db-linie
(li-create-line bo-create-line sn-create-segment-list))
(3182 "Weg*" (LI BO SN) db-linie
(li-create-line bo-create-line sn-create-segment-list))
(3231 "oberird. U-Bahn*" (LI BO SN) db-linie
(li-create-line bo-create-line sn-create-segment-list))
(3731 "unterird. U-Bahn*" (LI BO SN) db-linie
(li-create-line bo-create-line sn-create-segment-list))
;;; Flaechenbildungskomponenten (SN od. LI) =>
;;; evtl. SN-Ketten dekomponieren, spaeter evtl. Strassen rekonstruieren (=> Ketten)
((3231 2002) "oberird. U-Bahn*" (LI BO SN) db-line
(li-create-line bo-create-line sn-create-segment-list))
((3731 2002) "unterird. U-Bahn*" (LI BO SN) db-line
(li-create-line bo-create-line sn-create-segment-list))
(3162 "Sonstige Strasse*" (LI BO SN) db-line
(li-create-line bo-create-line sn-create-segment-list))
(3142 "Hauptverkehrsstrassse*" (LI BO SN) db-line
(li-create-line bo-create-line sn-create-segment-list))
(3112 "BAB*" (LI BO SN) db-line
(li-create-line bo-create-line sn-create-segment-list)) ; Randteil der BAB-FL
(3105 "BAB*" (LI BO SN) db-line
(li-create-line bo-create-line sn-create-segment-list)) ; "unsichtbare" Abgrenzung
(3152 "BAB-Auffahrt*" (LI BO SN) db-line
(li-create-line bo-create-line sn-create-segment-list))
(2002 "Nutzungsartengrenze*" (LI BO SN) db-line
(li-create-line bo-create-line sn-create-segment-list))
(2212 "Sportplatz*" (LI BO SN) db-line
(li-create-line bo-create-line sn-create-segment-list))
((5211 2002) "Bach*" (LI BO SN) db-line
(li-create-line bo-create-line sn-create-segment-list))
(2312 "Schule*" (LI BO SN) db-line
(li-create-line bo-create-line sn-create-segment-list))
(5202 "Teich* (Ufer)" (LI BO SN) db-line
(li-create-line bo-create-line sn-create-segment-list)) ; Ufer ?
;;; Symbole werden teilw. als "interessante" Objekte uminterpretiert
;;; um den Datenmangel zu entschaerfen
(8140 "Kirche" SY db-polygon sy-create-church) ; erzeuge ein Kirchen-Polygon
(4128 "Baum" SY db-point sy-create-point) ; Wiese/Weide Symbol => 1 Baum
(3238 "U-Bahn-Station" SY db-point sy-create-point)
(8113 "Postamt" SY db-polygon sy-create-postoffice)
(4318 "Moorloch" SY db-polygon sy-create-hole) ; Moor/Sumpf Symbol => 1 Moorloch
(4268 "Baum" SY db-point sy-create-point) ; Laubholz Symbol => 1 Baum
(4218 "Laubbaum" SY db-point sy-create-point)
(2238 "Kleingarten" SY db-polygon sy-create-allotment) ; Symbol => 1 Kleingartenhaeusschen
(8141 "Kapelle" SY db-polygon sy-create-chapel)
(2258 "Grab" SY db-point sy-create-point) ; Friedhof => 1 Grab
(8172 "Feuerwehr" SY db-polygon sy-create-firestation)))
;;;
;;;
;;;
(defparameter *os-to-name*
(make-hash-table :test #'equal))
(defparameter *os-to-item*
(make-hash-table :test #'equal))
(defparameter *interpreted-os*
(make-hash-table :test #'equal))
(dolist (item *os*)
(let ((name (first item))
(os (second item))
#| (etyp (third item))
(tafel (fourth item))
(ebene (fifth item)) |# )
(let ((os (if (listp os) os (list os))))
(setf (gethash os *os-to-name*) name)
(setf (gethash os *os-to-item*) item))))
(dolist (item *how-to-interpret-os*)
(let ((os (first item))
#| (name (second item))
(sqd-type (third item)) ; SQD Element-Typ : listp oder symbolp
(db-type (fourth item)) ; DB-Typ des transformierten Elementes
(what-to-do (nthcdr 4 item))) |# )
(let ((os (if (listp os) os (list os))))
(setf (gethash os *interpreted-os*) item))))
(defun lookup-os (os)
(gethash (if (listp os) os
(list os))
*os-to-item*))
(defun lookup-interpreted-os (os)
(gethash (if (listp os) os
(list os))
*interpreted-os*))
;;;
;;;
;;;
(defun recognized-os-p (os)
(lookup-interpreted-os os))
(defun get-db-transform-function (os sqd-type) ; sqd-typ IN { li, sn, pg, } etc.
(let* ((item (lookup-interpreted-os os))
(possible-sqd-types (third item)))
(if (consp possible-sqd-types)
(or (symbol-function
(nth (position sqd-type possible-sqd-types)
(fifth item)))
(error "No db-transform function!"))
(if (eq sqd-type possible-sqd-types)
(symbol-function (fifth item))
(error "No db-transform function!")))))
#|
(defun get-renamed-os (os)
(intern (second (lookup-interpreted-os os))))
|#
| 19,739 | Common Lisp | .lisp | 396 | 42.474747 | 98 | 0.655399 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 9278c630d0c1073173b3d2a7376ad3f7d0422cfda733edf385f50b0811c6df45 | 11,701 | [
-1
] |
11,702 | fonts.lisp | lambdamikel_VISCO/src/DB/fonts.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: FONTS; Base: 10 -*-
(cl:in-package fonts)
;;;
;;;
;;;
(defparameter *char-to-font-function*
(make-hash-table))
(defmacro compile-character (char)
(princ char) (terpri)
(let* ((namex (first char))
(name
(typecase namex
(string
(elt namex 0))
(character namex)))
(vectors (second char))
(measures (third char))
(x-measures (first measures))
#| (y-measures (second measures)) |#
(xstart (first x-measures))
(xend (second x-measures))
#| (ystart (first y-measures))
(yend (second y-measures)) |#
(delta (abs (- xstart xend)))
(code nil)
(dummy-var1 (gensym))
(dummy-var2 (gensym))
(dummy-var3 (gensym)))
(dolist (line vectors)
(let* ((p1 (first line))
(p2 (second line))
(x1 (- (first p1) xstart))
(x2 (- (first p2) xstart))
(y1 (- (second p1)))
(y2 (- (second p2))))
(push
`(draw-line*
stream
(+ xoff ,x1) (+ yoff ,y1) (+ xoff ,x2) (+ yoff ,y2))
code)))
`(progn
(setf (gethash ,(char-code name) *char-to-font-function*)
#'(lambda (stream xoff yoff)
(let ((,dummy-var1 stream)
(,dummy-var2 xoff)
(,dummy-var3 yoff))
(declare (ignore ,dummy-var1 ,dummy-var2 ,dummy-var3))
(progn
,@code
,delta)))))))
(defmacro compile-font ()
(let ((code nil))
(dolist (char
(eval-when (:compile-toplevel :load-toplevel :execute)
(with-open-file (stream
"visco:fonts;char3n"
:direction :input)
(read stream))))
(push `(compile-character ,char) code))
`(progn
,@code)))
(compile-font)
(defparameter *y-to-x* 1.5)
(defun draw-vector-text (string stream)
(let ((x 0))
(with-scaling (stream 1.0 *y-to-x*)
(dotimes (i (length string))
(let* ((char-code (char-code (elt string i)))
(fn (gethash char-code *char-to-font-function*)))
(incf x 0.3)
(incf x
(if fn
(funcall
fn
stream x 1.2)
(funcall (gethash (char-code #\space)
*char-to-font-function*)
stream x 1.2))))))))
| 2,152 | Common Lisp | .lisp | 78 | 22.064103 | 74 | 0.577811 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 2592c611370380d358db7b782b2866ecca6125af2d4a4f0a43a40d768ca37b76 | 11,702 | [
-1
] |
11,703 | gui-aux.lisp | lambdamikel_VISCO/src/DB/gui-aux.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: DATABASE; Base: 10 -*-
(in-package database)
#+:mcl
(defun file-selector (title directory pattern &key save)
(declare (ignore title))
(loop
(let ((pathname
(ccl:catch-cancel
(if (not save)
(ccl:choose-file-dialog :directory directory)
(ccl:choose-new-file-dialog :directory directory)))))
(cond ((eq pathname :cancel)
(return nil))
((string-equal (pathname-type pathname) pattern)
(return pathname))
(t (ccl:message-dialog
(format nil "Required File Extension: ~A" pattern)))))))
#+:allegro
(defun file-selector (title directory pattern &key (save nil))
(with-application-frame (frame)
(loop
(let ((file (namestring
(select-file frame
:pattern (concatenate 'string "*." pattern)
:title title
:directory (namestring
(truename directory))))))
(if file
(when (and file (not (string= "" file)))
(cond ((char= (elt file
(1- (length file)))
#\/)
(notify-user frame
"You must select a file, not a directory!"
:style :error))
((not (string= (subseq file (- (length file) (length pattern)))
pattern))
(notify-user frame
(format nil "Required File Extension: ~A" pattern)
:style :error))
(save
(when (cl-user:=> (probe-file file)
(notify-user frame
(format nil "Overwrite ~A?" file)
:style :warning))
(return file)))
((and (not save)
(probe-file file))
(return file))
(t
(notify-user frame
(format nil "File ~A does not exist" file)
:style :error))))
(return nil))))))
#+:mcl
(defmacro mcl-pane (&body body)
`(outlining ()
,@body))
(defun inverse-highlighter (type record stream state)
(declare (ignore state type))
(multiple-value-bind (xoff yoff)
(convert-from-relative-to-absolute-coordinates
stream (output-record-parent record))
(with-bounding-rectangle* (left top right bottom) record
(draw-rectangle* stream
(+ left xoff) (+ top yoff)
(+ right xoff) (+ bottom yoff)
:ink +flipping-ink+))))
(defmacro with-centering ((stream) &body body)
(let ((x (gensym)))
`(multiple-value-bind (,x)
(window-inside-size ,stream)
(formatting-table (stream)
(formatting-row (stream)
(formatting-cell (stream :align-x :center
:align-y :center
:min-width ,x)
,@body)))
(terpri stream))))
(defmacro with-border ((stream &key (offset 0)) &body body)
(let ((or (gensym)))
`(let ((,or
(with-output-to-output-record (,stream)
,@body)))
(draw-rectangle* ,stream
(- (bounding-rectangle-min-x ,or) ,offset)
(- (bounding-rectangle-min-y ,or) ,offset)
(+ (bounding-rectangle-max-x ,or) ,offset)
(+ (bounding-rectangle-max-y ,or) ,offset)
:line-dashes '(1 1)
:filled nil)
,@body)))
(defmacro draw-marker* (stream x y radius &rest args)
`(let ((x ,x)
(y ,y)
(r ,radius))
(clim:draw-rectangle* ,stream
(- x r)
(- y r)
(+ x r)
(+ y r)
:line-thickness 1
:filled nil ,@args)
(clim:draw-line* stream
(- x r)
(- y r)
(+ x r)
(+ y r)
:line-thickness 1
,@args)
(clim:draw-line* stream
(- x r)
(+ y r)
(+ x r)
(- y r)
:line-thickness 1
,@args)))
(defun get-size-of-graphic (stream fn)
(let ((or
(with-output-to-output-record (stream)
(funcall fn))))
(values
(bounding-rectangle-width or)
(bounding-rectangle-height or))))
| 4,252 | Common Lisp | .lisp | 124 | 23.459677 | 84 | 0.503158 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 60f7d0818010b76ccfa3db39fd84d05e60abd5430e2b3d419c7c3a72f0593ce6 | 11,703 | [
-1
] |
11,704 | map-viewer3.lisp | lambdamikel_VISCO/src/DB/map-viewer3.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: DATABASE; Base: 10 -*-
(in-package database)
(defvar *map-viewer-frame*)
(defvar *image-map* nil)
(defconstant +info-text-style+
(make-text-style :serif :roman :small))
(defconstant +text-height+ 10)
(defconstant +command-listener-text-style+
(make-text-style
:sans-serif :roman :normal))
(defconstant +map-viewer-text-style+
(make-text-style :sans-serif
:roman
:normal))
;;;
;;;
;;;
(defconstant +ink-bound-to+
(make-rgb-color 1.0 0.1 0.2))
(defconstant +grayed-item-ts+
(parse-text-style '(:sans-serif nil :small)))
(defconstant +grayed-item-i+
(make-gray-color 0.7))
(defconstant +selected-item-ts+
(parse-text-style '(:sans-serif (:bold :italic) :small)))
(defconstant +selected-item-i+
(make-gray-color 0.0))
(defconstant +unselected-item-ts+
(parse-text-style '(:sans-serif :bold :small)))
(defconstant +unselected-item-i+
(make-gray-color 0.4))
;;;
;;;
;;;
(defparameter *unknown-os-keys* nil)
(defparameter *highlight-line-thickness* 3)
;;;
;;;
;;;
(defparameter *display-binding-names-mode* nil)
(defparameter *warn-mode* nil)
(defparameter *decompose-mode* nil)
(defparameter *autotracking-mode* nil)
(defparameter *display-map-text-mode* nil)
(defparameter *display-nodes-mode* nil)
(defparameter *sensitive-objects-mode* t)
(defparameter *single-box-mode* nil)
(defmethod dont-display ((obj t))
t)
;;;
;;;
;;;
(defmethod label-pos ((obj geom-thing))
(values (x (pcenter obj)) (y (pcenter obj))))
(defmacro with-map-viewer-frame ((name) &body body)
`(let ((,name *map-viewer-frame*))
,@body))
(defmethod highlight ((obj t))
t)
(defmethod unhighlight ((obj t))
t)
(defmethod highlight ((obj db-object))
(setf (bound-to obj) t))
(defmethod unhighlight ((obj db-object))
(setf (bound-to obj) nil))
(defun unhighlight-all ()
(with-map-viewer-frame (frame)
(with-slots (db) frame
(when db
(dolist (obj (objects db))
(unhighlight obj))))))
(defun highlight-all (list)
(dolist (obj list)
(highlight obj)))
;;;
;;;
;;;
(define-presentation-type os-key-item ())
(define-presentation-type current-map-range ())
;;;
;;;
;;;
#+:mcl
(progn
(define-gesture-name :adjust :pointer-button (:left :shift))
(define-gesture-name :unselect-os-keys-of-object :pointer-button (:left :shift))
(define-gesture-name :unselect-all-but-os-keys-of-object :pointer-button (:left :control))
(define-gesture-name :hide-object :pointer-button (:left :meta)))
#+:allegro
(progn
(define-gesture-name :adjust :pointer-button (:middle))
(define-gesture-name :unselect-os-keys-of-object :pointer-button (:left :shift))
(define-gesture-name :unselect-all-but-os-keys-of-object :pointer-button (:middle :shift))
(define-gesture-name :hide-object :pointer-button (:right :shift)))
;;;
;;;
;;;
(defpersistentclass map-text ()
((matrix :accessor matrix :initarg :matrix :not-persistent)
(text :accessor text :initarg :text)
(bbox :accessor bbox :not-persistent)
(tx :accessor tx :initarg :tx)
(ty :accessor ty :initarg :ty)
(h :accessor h :initarg :h)
(w :accessor w :initarg :w)))
(defmethod initialize-instance :after ((obj map-text) &rest initargs)
(declare (ignore initargs))
(init obj))
(defmethod initialize-loaded-persistent-object ((obj map-text))
(init obj))
(defmethod init ((obj map-text))
(with-slots (h tx ty w matrix) obj
(let* ((sx (/ h 4))
(sy (/ h 4))
(r (geometry::deg-to-rad w))
(trans1 (make-translation-transformation tx ty))
(trans2 (make-scaling-transformation sx sy))
(trans3 (make-rotation-transformation r))
(transx (compose-transformations trans2 trans3)))
(setf matrix
(compose-transformations trans1 transx))))
(with-map-viewer-frame (map-viewer-frame)
(with-slots (text-objects) map-viewer-frame
(let ((stream (get-frame-pane map-viewer-frame 'display)))
(multiple-value-bind (xf yf xt yt)
(bounding-rectangle*
(with-output-to-output-record (stream)
(let ((*display-map-text-mode* t))
(draw obj stream))))
(setf (bbox obj)
(bb xf yf xt yt))
(push obj text-objects))))))
;;;
;;;
;;;
(define-command-table file-table
:menu (("Load SQD Map" :command (com-load-sqd-map))
("divide1" :divider nil)
("Load Map" :command (com-load-map))
("Save Map" :command (com-save-map))
("divide2" :divider nil)
("Install Image Map" :command (com-install-image-map))
("divide3" :divider nil)
("Quit" :command (com-quit))))
(define-command-table map-table
:menu (("Kill Bindings" :command (com-kill-bindings))
("Clear Display" :command (com-clear-display))
("Reset Map" :command (com-reset-map))
("Redraw Map" :command (com-redraw))
("Show Map Infos" :command (com-show-map-infos))
#+:allegro ("Print Whole Map" :command (com-print-whole-map))))
(define-command-table keys-table
:menu (("Undo Nothing" :command (com-undo))
("divide1" :divider nil)
("Lookup Key" :command (com-lookup-os-key))
("Select All Keys" :command (com-select-all-os-keys))
("Unselect All Keys" :command (com-unselect-all-os-keys))
#+:allegro ("divide2" :divider nil)
#+:allegro ("Print Keylist" :command (com-print-keylist))))
(define-command-table spatial-table
:menu (("Highlight Intersecting Objects" :command (com-highlight-intersecting-objects*))
("Highlight Containing Objects" :command (com-highlight-containing-objects*))
("Highlight Contained Objects" :command (com-highlight-contained-objects*))))
;;;
;;;
;;;
(defun generate-name-for-undo-command ()
(remove-command-from-command-table
'com-undo 'keys-table)
(with-map-viewer-frame (map-viewer-frame)
(with-slots (unselect-stack) map-viewer-frame
(let ((first (first unselect-stack)))
(if first
(add-command-to-command-table 'com-undo
'keys-table
:menu (list
(if (typep first 'db-object)
(format nil "Undo Hide ~A"
(id first))
"Undo Last Selection")
:after :start))
(add-command-to-command-table 'com-undo
'keys-table
:menu (list
"Undo Nothing"
:after :start)))))))
(defun register-selected-keys-for-undo ()
(with-map-viewer-frame (map-viewer-frame)
(with-slots (unselect-stack selected-os-keys) map-viewer-frame
(push (copy-list selected-os-keys) unselect-stack)
(generate-name-for-undo-command))))
(defun register-hide-for-undo (object)
(with-map-viewer-frame (map-viewer-frame)
(with-slots (unselect-stack) map-viewer-frame
(push object unselect-stack)
(generate-name-for-undo-command))))
;;;
;;;
;;;
(defclass overview-pane
(application-pane)
())
(defclass display-pane
(application-pane)
())
(define-application-frame map-viewer ()
( (db :initform nil)
(text-objects :initform nil)
(map-filename :initform nil)
(unselect-stack :initform nil)
(current-map-range :initform nil :accessor current-map-range)
(current-map-radius :initform 100)
(current-map-position :initform nil)
(current-map-transformation :initform nil)
(overview-pattern :initform nil)
(old-overview-vp-width :initform nil)
(old-overview-vp-height :initform nil)
(overview-transformation :initform nil)
(present-os-keys :initform nil)
(selected-os-keys :initform nil))
(:command-table (map-viewer
:inherit-from (file-table map-table keys-table spatial-table)
:menu (("File" :menu file-table)
("Map" :menu map-table)
("Key Control" :menu keys-table)
("Spatial Querying" :menu spatial-table))))
(:panes
(display (make-pane 'display-pane
:scroll-bars nil
:end-of-line-action :allow
:end-of-page-action :allow
:textcursor nil))
(button-undo (make-pane 'push-button
:label "Undo"
:activate-callback 'button-undo))
(button-kill-bindings (make-pane 'push-button
:label #+:allegro "Kill Bindings" #+:mcl "Kill Bs"
:activate-callback 'button-kill-bindings))
(button-clear (make-pane 'push-button
:label "Clear"
:activate-callback 'button-clear))
(button-redraw (make-pane 'push-button
:label "Redraw"
:activate-callback 'button-redraw))
(button-infos (make-pane 'push-button
:label "Infos"
:activate-callback 'button-infos))
(button-reset (make-pane 'push-button
:label "Reset"
:activate-callback 'button-reset))
(overview (make-pane 'overview-pane
:scroll-bars nil
:end-of-line-action :allow
:end-of-page-action :allow
:textcursor nil
:display-after-commands nil
:display-function #'draw-overview))
(infos :application
:label "Map Infos"
:textcursor nil
:end-of-line-action :allow
:end-of-page-action :allow
:text-style +info-text-style+
:scroll-bars :both)
(coordinates :application
:label "Map Coordinates"
:textcursor nil
:end-of-line-action :allow
:end-of-page-action :allow
:text-style +info-text-style+
:scroll-bars nil
:display-function #'show-coordinates)
(buttons :accept-values
:scroll-bars nil
:min-height :compute :height :compute :max-height :compute
:display-function
`(accept-values-pane-displayer
:displayer ,#'(lambda (frame stream)
(accept-buttons
frame stream))))
(os-selector :application
:incremental-redisplay t
:scroll-bars :both
:end-of-line-action :allow
:end-of-page-action :allow
:display-function #'accept-os-selection)
(command :interactor
:label nil
:text-style +command-listener-text-style+
:scroll-bars :vertical
:min-height '(4 :line)
:max-height '(4 :line)
:height '(4 :line))
(pointer-documentation-pane
(make-clim-stream-pane :type 'pointer-documentation-pane
:foreground +white+
:background +black+
:text-style (make-text-style
:sans-serif :bold :small)
:scroll-bars nil
:min-height '(1 :line)
:max-height '(1 :line)
:height '(1 :line))))
(:layouts
(:default
(vertically ()
#+:allegro buttons
#+:mcl (mcl-pane buttons)
(horizontally ()
#+:allegro
(1/4 os-selector)
#+:mcl
(1/4 (mcl-pane os-selector))
(2/4
#+:allegro
(vertically ()
(outlining ()
(labelling (:label "Current Map")
display))
(30 (horizontally ()
(1/6 button-undo)
(1/6 button-kill-bindings)
(1/6 button-clear)
(1/6 button-reset)
(1/6 button-redraw)
(1/6 button-infos))))
#+:mcl
(vertically ()
(mcl-pane
(labelling (:label "Current Map")
display))
(mcl-pane
(horizontally ()
(1/6 button-undo)
(1/6 button-kill-bindings)
(1/6 button-clear)
(1/6 button-reset)
(1/6 button-redraw)
(1/6 button-infos)))))
(1/4
#+:allegro
(vertically ()
(1/7 coordinates)
(3/7 (outlining ()
(labelling (:label "Map Overview")
overview)))
(3/7 infos))
#+:mcl
(vertically ()
(1/7 (mcl-pane coordinates))
(3/7 (mcl-pane overview))
(3/7 (mcl-pane infos)))))
#+:allegro
command
#+:mcl
(mcl-pane command)
#+:allegro
pointer-documentation-pane
#+:mcl
(mcl-pane pointer-documentation-pane)))))
;;;
;;;
;;;
(defun button-kill-bindings (button)
(declare (ignore button))
(com-kill-bindings))
(defun button-undo (button)
(declare (ignore button))
(com-undo))
(defun button-clear (button)
(declare (ignore button))
(com-clear-display))
(defun button-redraw (button)
(declare (ignore button))
(com-redraw))
(defun button-infos (button)
(declare (ignore button))
(com-show-map-infos))
(defun button-reset (button)
(declare (ignore button))
(com-reset-map))
;;;
;;;
;;;
(define-map-viewer-command (com-reset-map :name "Reset Map")
()
(reset-map-range)
(com-redraw))
(define-map-viewer-command (com-kill-bindings :name "Kill Bindings")
()
(unhighlight-all)
(com-clear-display)
(com-redraw))
;;;
;;;
;;;
(define-map-viewer-command (com-undo :name "Undo")
()
(with-map-viewer-frame (map-viewer-frame)
(with-slots (unselect-stack selected-os-keys) map-viewer-frame
(let ((first (pop unselect-stack)))
(when first
(cond ((typep first 'db-object) ; undo hide object
(setf (dont-display first) nil)
(com-clear-display)
(com-draw-current-map))
(t
(setf selected-os-keys first)))
(generate-name-for-undo-command)
(com-draw-current-map)
(redisplay-frame-pane map-viewer-frame 'os-selector))))))
(defmethod accept-buttons ((frame map-viewer) stream)
(let ((changed nil))
(formatting-table (stream :x-spacing '(2 :character))
(formatting-row (stream)
(formatting-cell (stream :align-x :center)
(multiple-value-bind (bool ptype changed1)
(accept 'boolean
:prompt "Autotracking"
:stream stream :default *autotracking-mode*
:query-identifier 'autotracking)
(declare (ignore ptype))
(setf changed (or changed changed1))
(when changed1 (setf *autotracking-mode* bool))))
(formatting-cell (stream :align-x :center)
(multiple-value-bind (bool ptype changed2)
(accept 'boolean
:prompt "Map Text"
:stream stream :default *display-map-text-mode*
:query-identifier 'display-text)
(declare (ignore ptype))
(setf changed (or changed changed2))
(when changed2 (setf *display-map-text-mode* bool))))
(formatting-cell (stream :align-x :center)
(multiple-value-bind (bool ptype changed3)
(accept 'boolean
:prompt "Nodes"
:stream stream :default *display-nodes-mode*
:query-identifier 'display-nodes)
(declare (ignore ptype))
(setf changed (or changed changed3))
(when changed3 (setf *display-nodes-mode* bool))))
(formatting-cell (stream :align-x :center)
(multiple-value-bind (bool ptype changed4)
(accept 'boolean
:prompt "Sensitive Objects"
:stream stream :default *sensitive-objects-mode*
:query-identifier 'sensitive-objects-mode)
(declare (ignore ptype))
(setf changed (or changed changed4))
(when changed4 (setf *sensitive-objects-mode* bool))))
(formatting-cell (stream :align-x :center)
(multiple-value-bind (bool ptype changed5)
(accept 'boolean
:prompt "Single Boxes"
:stream stream :default (and *sensitive-objects-mode* *single-box-mode*)
:query-identifier 'single-box-mode)
(declare (ignore ptype))
(setf changed (or changed changed5))
(when changed5
(setf *single-box-mode*
(if bool :position nil)))))
(formatting-cell (stream :align-x :center)
(multiple-value-bind (bool ptype changed6)
(accept 'boolean
:prompt "Warnings"
:stream stream :default *warn-mode*
:query-identifier 'warn-mode)
(declare (ignore ptype))
(setf changed (or changed changed6))
(when changed6 (setf *warn-mode* bool))))
(formatting-cell (stream :align-x :center)
(multiple-value-bind (bool ptype changed7)
(accept 'boolean
:prompt "Decompose"
:stream stream :default *decompose-mode*
:query-identifier 'decompose-mode)
(declare (ignore ptype))
(setf changed (or changed changed7))
(when changed7 (setf *decompose-mode* bool))))
(formatting-cell (stream :align-x :center)
(multiple-value-bind (bool ptype changed8)
(accept 'boolean
:prompt "Show Bindings"
:stream stream :default *display-binding-names-mode*
:query-identifier 'display-bindings)
(declare (ignore ptype))
(setf changed (or changed changed8))
(when changed8 (setf *display-binding-names-mode* bool))))
(when (and changed *autotracking-mode*)
(com-draw-current-map))))))
(defmethod accept-os-selection ((frame map-viewer) stream)
(with-map-viewer-frame (map-viewer-frame)
(let ((y 0))
(flet ((set-item (item)
(let ((item (lookup-os item)))
(draw-text* stream
(format nil "~A ~A ~A" (first item) (second item)
(let ((third (third item)))
(if (listp third)
third
(list third))))
0 y)))
(set-unknown-item (item)
(draw-text* stream
(format nil "??? ~A ???" item)
0 y)))
(with-slots (present-os-keys selected-os-keys) map-viewer-frame
(dolist (item *unknown-os-keys*)
(incf y 14)
(let ((selected (member item selected-os-keys :test #'equal)))
(updating-output (stream :unique-id item
:cache-value (list y selected)
:cache-test #'equal)
(with-output-as-presentation
(stream item 'os-key-item)
(if selected
(with-drawing-options (stream :text-style +selected-item-ts+
:ink +selected-item-i+)
(set-unknown-item
item))
(with-drawing-options (stream :text-style +unselected-item-ts+
:ink +unselected-item-i+)
(set-unknown-item item)))))))
(dolist (item *os*)
(let ((item (second item)))
(incf y 14)
(let ((selected (member item selected-os-keys :test #'equal)))
(updating-output (stream :unique-id item
:cache-value (list y selected)
:cache-test #'equal)
(if (member item present-os-keys :test #'equalp)
(with-output-as-presentation
(stream item 'os-key-item)
(if selected
(with-drawing-options (stream :text-style +selected-item-ts+
:ink +selected-item-i+)
(set-item item))
(with-drawing-options (stream :text-style +unselected-item-ts+
:ink +unselected-item-i+)
(set-item item))))
(with-drawing-options (stream :text-style +grayed-item-ts+
:ink +grayed-item-i+)
(set-item item))))))))))))
;;;
;;;
;;;
(define-map-viewer-command (com-select-os-key-item :name "Select Key")
((object 'os-key-item))
(with-map-viewer-frame (map-viewer-frame)
(with-slots (present-os-keys selected-os-keys) map-viewer-frame
(setf selected-os-keys
(if (member object selected-os-keys :test #'equalp)
(remove object selected-os-keys :test #'equalp)
(cons object selected-os-keys)))
(when *autotracking-mode*
(com-draw-current-map)))))
(define-presentation-to-command-translator select-os-key-item
(os-key-item com-select-os-key-item map-viewer
:gesture :select)
(object)
(list object))
;;;
;;;
;;;
(define-map-viewer-command (com-select-all-os-keys :name "Select All Keys")
()
(with-map-viewer-frame (map-viewer-frame)
(with-slots (present-os-keys selected-os-keys) map-viewer-frame
(register-selected-keys-for-undo)
(setf selected-os-keys present-os-keys)
(com-draw-current-map))))
(define-map-viewer-command (com-unselect-all-os-keys :name "Unselect All Keys")
()
(with-map-viewer-frame (map-viewer-frame)
(with-slots (present-os-keys selected-os-keys) map-viewer-frame
(register-selected-keys-for-undo)
(setf selected-os-keys nil)
(com-draw-current-map))))
;;;
;;;
;;;
(define-map-viewer-command (com-unselect-os-keys-of-object :name "Unselect OS Keys Of Object")
((object 'db-object))
(with-map-viewer-frame (map-viewer-frame)
(with-slots (present-os-keys selected-os-keys) map-viewer-frame
(register-selected-keys-for-undo)
(dolist (os (all-os object))
(setf selected-os-keys
(delete os selected-os-keys :test #'equalp)))
(com-draw-current-map))))
(define-map-viewer-command (com-unselect-all-but-os-keys-of-object :name "Unselect All But OS Keys Of Object")
((object 'db-object))
(with-map-viewer-frame (map-viewer-frame)
(with-slots (present-os-keys selected-os-keys) map-viewer-frame
(register-selected-keys-for-undo)
(setf selected-os-keys
(all-os object))
(com-draw-current-map))))
(define-presentation-to-command-translator unselect-os-keys-of-object
(db-object com-unselect-os-keys-of-object map-viewer
:gesture :unselect-os-keys-of-object)
(object)
(list object))
(define-presentation-to-command-translator unselect-all-but-os-keys-of-object
(db-object com-unselect-all-but-os-keys-of-object map-viewer
:gesture :unselect-all-but-os-keys-of-object)
(object)
(list object))
;;;
;;;
;;;
(define-map-viewer-command (com-lookup-os-key :name "Lookup OS Key")
()
(with-map-viewer-frame (map-viewer-frame)
(with-slots (unselect-stack) map-viewer-frame
(let* ((stream (get-frame-pane map-viewer-frame 'display))
(os-number
(accepting-values (stream :own-window t :label "Lookup OS Key:")
(accept 'integer :stream stream :view 'gadget-dialog-view))))
(window-clear *standard-output*)
(terpri)
(format t " ~A~%"
(lookup-os os-number))))))
;;;
;;;
;;;
(define-map-viewer-command (com-hide-object :name "Hide Object")
((object 'db-object))
(register-hide-for-undo object)
(setf (dont-display object) t)
(com-clear-display)
(com-draw-current-map))
(define-presentation-to-command-translator hide-object
(db-object com-hide-object map-viewer
:gesture :hide-object)
(object)
(list object))
;;;
;;;
;;;
(defun show-current-map-range (&key (record t)
(coordinates t)
stream
transformation)
(with-map-viewer-frame (frame)
(let ((stream (or stream (get-frame-pane frame 'overview))))
(with-slots (db overview-transformation
current-map-range
current-map-position current-map-radius) frame
(flet ((draw-it ()
(with-drawing-options (stream :transformation
(or transformation overview-transformation))
(draw-circle* stream
(first current-map-position)
(second current-map-position)
(- current-map-radius 4)
:ink +flipping-ink+
:line-thickness 2
:filled nil)
(draw-rectangle* stream
(x (pmin current-map-range))
(y (pmin current-map-range))
(x (pmax current-map-range))
(y (pmax current-map-range))
:line-thickness 2
:ink +flipping-ink+
:filled t))))
(when db
(when coordinates
(show-coordinates frame (get-frame-pane frame 'coordinates)))
(if record
(with-output-as-presentation (stream current-map-range
'current-map-range)
(draw-it))
(with-output-recording-options (stream :draw t :record nil)
(draw-it)))))))))
(define-map-viewer-command (com-adjust-map-center :name "Adjust Map Center")
((object 'current-map-range))
(declare (ignore object))
(adjust-map-center))
(define-map-viewer-command (com-adjust-map-extent :name "Adjust Map Extent")
((object 'current-map-range))
(declare (ignore object))
(adjust-map-extent))
(define-presentation-to-command-translator adjust-map-center
(current-map-range com-adjust-map-center map-viewer
:gesture :select)
(object)
(list object))
(define-presentation-to-command-translator adjust-map-extent
(current-map-range com-adjust-map-extent map-viewer
:gesture :adjust)
(object)
(list object))
(defmethod set-current-map-position-and-radius (xcenter ycenter r)
(with-map-viewer-frame (frame)
(with-slots (current-map-position current-map-radius) frame
(setf current-map-position
(list xcenter ycenter))
(setf current-map-radius r))
(let ((*autotracking-mode* nil))
(adjust-current-map-range))))
(defun full-map-range ()
(with-map-viewer-frame (frame)
(with-slots (db current-map-range) frame
(when db
(with-slots (xmin ymin xmax ymax) (spatial-index db)
(setf current-map-range
(make-bounding-box xmin ymin xmax ymax)))
(recalculate-transformation (get-frame-pane frame 'display))))))
(defun reset-map-range ()
(with-map-viewer-frame (frame)
(with-slots (db current-map-radius current-map-position) frame
(when db
(with-slots (xmin ymin xmax ymax) (spatial-index db)
(setf current-map-radius (floor (- xmax xmin) 5))
(setf current-map-position
(list (floor (+ xmin xmax) 2)
(floor (+ ymin ymax) 2)))
(let ((*autotracking-mode* nil))
(adjust-current-map-range)))))))
(defun adjust-current-map-range ()
(with-map-viewer-frame (frame)
(with-slots (current-map-range
current-map-position current-map-radius) frame
(let ((xcenter (first current-map-position))
(ycenter (second current-map-position)))
(if (not current-map-range)
(setf current-map-range
(make-bounding-box
(- xcenter current-map-radius) (- ycenter current-map-radius)
(+ xcenter current-map-radius) (+ ycenter current-map-radius)))
(with-slots (pmin pmax) current-map-range
(setf (x pmin) (- xcenter current-map-radius)
(y pmin) (- ycenter current-map-radius)
(x pmax) (+ xcenter current-map-radius)
(y pmax) (+ ycenter current-map-radius))))
(recalculate-transformation (get-frame-pane frame 'display))
(when *autotracking-mode*
(com-draw-current-map))))))
(defun adjust-map-center ()
(with-map-viewer-frame (map-viewer-frame)
(let ((stream (get-frame-pane map-viewer-frame 'overview)))
(with-slots (current-map-position
db
old-overview-vp-width
old-overview-vp-height) map-viewer-frame
(when db
(block track-pointer
(with-output-recording-options (stream :draw t :record nil)
(tracking-pointer (stream)
(:pointer-motion (x y)
(with-slots (xmin ymin xmax ymax) (spatial-index db)
(let* ((xscale (/ old-overview-vp-width (- xmax xmin)))
(yscale (/ old-overview-vp-height (- ymax ymin)))
(xcenter
(+ xmin (* (/ 1 xscale) x)))
(ycenter
(+ ymax (* (- (/ 1 yscale)) y))))
(show-current-map-range :record nil)
(setf current-map-position
(list xcenter ycenter))
(adjust-current-map-range)
(show-current-map-range :record nil))))
(:pointer-button-press ()
(return-from track-pointer))))))))))
(defun adjust-map-extent ()
(with-map-viewer-frame (map-viewer-frame)
(let ((stream (get-frame-pane map-viewer-frame 'overview)))
(with-slots (current-map-radius
current-map-position
db
old-overview-vp-width
old-overview-vp-height) map-viewer-frame
(when db
(block track-pointer
(with-output-recording-options (stream :draw t :record nil)
(tracking-pointer (stream)
(:pointer-motion (x y)
(with-slots (xmin ymin xmax ymax) (spatial-index db)
(let* ((xscale (/ old-overview-vp-width (- xmax xmin)))
(yscale (/ old-overview-vp-height (- ymax ymin)))
(xcenter (first current-map-position))
(ycenter (second current-map-position))
(xr
(- xcenter (+ xmin (* (/ 1 xscale) x))))
(yr
(- ycenter (+ ymax (* (- (/ 1 yscale)) y))))
(r (sqrt (+ (* xr xr) (* yr yr)))))
(unless (zerop r)
(show-current-map-range :record nil)
(setf current-map-radius r)
(adjust-current-map-range)
(show-current-map-range :record nil)))))
(:pointer-button-press ()
(return-from track-pointer))))))))))
(defmethod show-coordinates ((frame map-viewer) stream)
(with-slots (current-map-range db) frame
(when db
(window-clear stream)
(terpri stream)
(with-slots (xmin ymin xmax ymax) (spatial-index db)
(format stream " Full Map: (~A,~A) - (~A,~A)"
(round xmin) (round ymin)
(round xmax) (round ymax)))
(terpri stream)
(with-slots (pmin pmax) current-map-range
(format stream " Map Range: (~A,~A) - (~A,~A)"
(round (x pmin)) (round (y pmin))
(round (x pmax)) (round (y pmax)))
(terpri stream)
(let ((size (abs (round (- (x pmin) (x pmax))))))
(format stream " Range: ~A * ~A meters" size size))))))
;;;
;;;
;;;
(defun selectedp (object)
(with-map-viewer-frame (map-viewer-frame)
(with-slots (selected-os-keys) map-viewer-frame
(some #'(lambda (os)
(member os selected-os-keys :test #'equal))
(all-os object)))))
(defmethod draw-current-map ((frame map-viewer) stream &key
overview
show-types-p
(clear-p t) (show-bindings t))
(with-slots (current-map-range
current-map-transformation
selected-os-keys db text-objects) frame
(with-slots (pmin pmax) current-map-range
(when clear-p (window-clear stream))
(when db
(with-drawing-options (stream :transformation current-map-transformation
:clipping-region
(make-bounding-rectangle (x pmin) (y pmin)
(x pmax) (y pmax)))
(with-selected-objects (cur-obj current-map-range
(primary-p cur-obj) :inside)
(when (not (dont-display cur-obj))
(cond
((or
(and *decompose-mode*
(typep cur-obj 'db-polygon))
(selectedp cur-obj))
(draw cur-obj stream
:show-bindings show-bindings
:overview overview
:show-types-p show-types-p))
(t (when *warn-mode* (warn "~%Object not drawn! ~A" cur-obj))))))
(dolist (cur-obj text-objects)
(when (box-overlaps-box-p (bbox cur-obj)
current-map-range)
(draw cur-obj stream :overview overview))))))))
(defun draw-current-map-to-foreign-stream (stream &key width height show-bindings
show-types-p
overview)
(with-map-viewer-frame (map-viewer)
(recalculate-transformation stream :width width :height height)
(draw-current-map map-viewer stream :show-bindings show-bindings
:clear-p nil
:show-types-p show-types-p
:overview overview)
(recalculate-transformation (get-frame-pane map-viewer 'display))))
#+(and mcl antiker-mac)
(defmethod draw-overview ((frame map-viewer) stream)
(with-slots (overview-pattern current-map-range
overview-transformation
db) frame
(show-current-map-range)))
(defmethod draw-overview ((frame map-viewer) stream)
(with-slots (overview-pattern current-map-range
overview-transformation
db) frame
(when db
(multiple-value-bind (viewport-width viewport-height)
(bounding-rectangle-size (bounding-rectangle (window-viewport stream)))
(unless overview-pattern
(setf overview-pattern
(with-output-to-pixmap (stream
(sheet-medium (get-frame-pane frame 'overview))
:width viewport-width
:height viewport-height)
(with-drawing-options (stream :transformation overview-transformation)
(let ((*display-nodes-mode* nil))
(dolist (obj (objects db))
(when (primary-p obj)
(draw obj stream :overview t))))))))
(draw-pixmap* stream
overview-pattern
0 0)
(show-current-map-range)))))
;;;
;;;
;;;
(defmethod draw :around ((object db-object) stream &key show-bindings
show-types-p)
(labels ((draw-it ()
(if *sensitive-objects-mode*
(with-output-as-presentation
(stream object (type-of object)
:single-box *single-box-mode* :allow-sensitive-inferiors t)
(call-next-method))
(call-next-method))))
(if (consp show-bindings)
(let* ((entry (assoc object show-bindings))
(text1 (second entry))
(text2 (third entry)))
(if text1
(with-drawing-options (stream :ink +ink-bound-to+
:line-thickness *highlight-line-thickness*)
(draw-it)
(when *display-binding-names-mode*
(multiple-value-bind (lx ly)
(label-pos object)
(draw-text* stream
(format nil "~A" text1)
lx ly)))
(when show-types-p
(multiple-value-bind (lx ly)
(label-pos object)
(let ((i ly))
(dolist (os-text text2)
(draw-text* stream
(format nil "~A" os-text)
lx i)
(incf i +text-height+)))))
(draw-it))
(draw-it)))
(if show-bindings
(if (bound-to object)
(with-drawing-options (stream :ink +ink-bound-to+
:line-thickness *highlight-line-thickness*)
(draw-it)
(when (and (not (eq (bound-to object) t))
*display-binding-names-mode*)
(multiple-value-bind (lx ly)
(label-pos object)
(draw-text* stream
(format nil "~A" (bound-to object))
lx ly))))
(with-drawing-options (stream :ink +black+)
(draw-it)))
(with-drawing-options (stream :ink +black+)
(draw-it))))))
(defmethod draw ((object t) stream &key &allow-other-keys)
(declare (ignore stream))
())
(defun draw-chain-or-polygon (object stream &key overview show-bindings)
(if *decompose-mode*
(progn
(when (and (selectedp object)
(not overview))
(draw-marker* stream
(x (pcenter object))
(y (pcenter object))
5
:ink +magenta+))
(dolist (segment (segments object))
(when (not (dont-display segment))
(when (selectedp segment)
(draw segment stream
:show-bindings show-bindings
:overview overview)))))
(when (selectedp object)
(unless overview
(draw-marker* stream
(x (pcenter object))
(y (pcenter object))
5
:ink +magenta+))
(dolist (segment (segments object))
(when (not (dont-display segment))
(draw segment stream
:show-bindings show-bindings
:overview overview))))))
(defmethod draw ((object db-line) stream &key overview show-bindings)
(with-slots (p1 p2) object
(draw-line*
stream
(x p1) (y p1)
(x p2) (y p2))
(when *display-nodes-mode*
(draw p1 stream :overview overview :show-bindings show-bindings)
(draw p2 stream :overview overview :show-bindings show-bindings))))
(defmethod draw ((object db-chain) stream &key overview show-bindings &allow-other-keys)
(draw-chain-or-polygon object stream :overview overview :show-bindings show-bindings))
(defmethod draw ((object db-polygon) stream &key overview show-bindings &allow-other-keys)
(draw-chain-or-polygon object stream :overview overview :show-bindings show-bindings))
(defmethod draw ((object db-point) stream &key &allow-other-keys)
(with-slots (x y name) object
(if (primary-p object)
(progn
(draw-circle*
stream
x y 8
:filled nil)
(draw-circle*
stream
x y 5
:filled t))
(draw-circle*
stream
x y (if (bound-to object)
8
4)
:filled t))))
(defmethod draw ((object map-text) stream &key &allow-other-keys)
(when *display-map-text-mode*
(with-drawing-options (stream :transformation (matrix object)
:ink +blue+)
(with-slots (text) object
(draw-vector-text text stream)))))
;;;
;;;
;;;
(defmethod run-frame-top-level :before ((frame map-viewer) &key)
(initialize-map-viewer frame))
(defmethod frame-standard-input ((frame map-viewer))
(get-frame-pane frame 'command))
(defmethod frame-standard-output ((frame map-viewer))
(get-frame-pane frame 'infos))
(defmethod frame-error-output ((frame map-viewer))
(get-frame-pane frame 'infos))
(defmethod initialize-map-viewer ((frame map-viewer))
(setf *unknown-os-keys* nil))
;;;
;;;
;;;
(defmethod measure-and-draw-map ((frame map-viewer))
(with-slots (overview-transformation
present-os-keys
overview-pattern
current-map-position current-map-radius db) frame
(with-slots (xmin ymin xmax ymax) (spatial-index db)
(window-clear *standard-output*)
(setf overview-pattern nil)
(setf present-os-keys nil)
(setf *unknown-os-keys* nil)
(labels ((insert-os-key (object)
(dolist (item (all-os object))
(if (lookup-os item)
(pushnew item
present-os-keys)
(pushnew item
*unknown-os-keys*)))
(if (or (typep object 'db-polygon)
(typep object 'db-chain))
(dolist (object (segments object))
(insert-os-key object)))))
(dolist (obj (objects db))
(insert-os-key obj))
(show-map-infos)
(change-os-key-selection)
(recalculate-transformation (get-frame-pane frame 'overview) :force t)
(reset-map-range)
(com-draw-current-map)
(draw-overview frame (get-frame-pane frame 'overview))))))
(defmethod recalculate-transformation (sheet &key width height)
(with-map-viewer-frame (map-viewer-frame)
(with-slots (db current-map-range current-map-transformation) map-viewer-frame
(when db
(let* ((vbb
(window-viewport sheet))
(vb-width
(or width (bounding-rectangle-width vbb)))
(vb-height
(or height (bounding-rectangle-height vbb)))
(xscale (/ vb-width (- (x (pmax current-map-range)) (x (pmin current-map-range)))))
(yscale (/ vb-height (- (y (pmax current-map-range)) (y (pmin current-map-range)))))
(trans1 (make-translation-transformation (- (x (pmin current-map-range)))
(- (y (pmax current-map-range)))))
(trans2 (make-scaling-transformation
xscale
(- yscale)))
(trans
(compose-transformations trans2 trans1)))
(setf current-map-transformation trans))))))
(defmethod recalculate-transformation ((pane overview-pane) &key force)
(with-map-viewer-frame (map-viewer-frame)
(with-slots (db
overview-transformation
old-overview-vp-width
old-overview-vp-height) map-viewer-frame
(when db
(with-slots (xmin ymin xmax ymax) (spatial-index db)
(let* ((vpbb
(window-viewport
(get-frame-pane map-viewer-frame 'overview)))
(vp-width
(bounding-rectangle-width vpbb))
(vp-height
(bounding-rectangle-height vpbb)))
(when (or force
(not old-overview-vp-width) (not old-overview-vp-height)
(not (and (= old-overview-vp-width vp-width)
(= old-overview-vp-height vp-height))))
(let*
((trans1 (make-translation-transformation (- xmin) (- ymax)))
(trans2 (make-scaling-transformation
(/ vp-width (- xmax xmin))
(- (/ vp-height (- ymax ymin)))))
(trans (compose-transformations trans2 trans1)))
(setf old-overview-vp-width vp-width
old-overview-vp-height vp-height)
(setf overview-transformation trans)))))))))
(defmethod calculate-transformation ((pane application-pane))
(with-map-viewer-frame (map-viewer-frame)
(with-slots (db) map-viewer-frame
(when db
(with-slots (xmin ymin xmax ymax) (spatial-index db)
(let* ((vpbb
(window-viewport pane))
(vp-width
(bounding-rectangle-width vpbb))
(vp-height
(bounding-rectangle-height vpbb))
(trans1 (make-translation-transformation (- xmin) (- ymax)))
(trans2 (make-scaling-transformation
(/ vp-width (- xmax xmin))
(- (/ vp-height (- ymax ymin))))))
(compose-transformations trans2 trans1)))))))
;;;
;;;
;;;
(define-map-viewer-command (com-show-map-infos :name "Show Map Infos")
()
(window-clear *standard-output*)
(show-map-infos))
(defun show-map-infos (&optional (stream *standard-output*))
(with-map-viewer-frame (map-viewer-frame)
(with-slots (map-filename db
present-os-keys) map-viewer-frame
(when db
(fresh-line stream)
(terpri stream)
(format stream " Infos For Map ~A:~%" map-filename)
(format stream " ~A Objects Loaded, ~%" (length (objects db)))
(format stream " ~A Unknown Object OS Keys,~%" (length *unknown-os-keys*))
(format stream " ~A Known Object OS Keys. " (length present-os-keys))))))
;;;
;;;
;;;
(define-map-viewer-command (com-load-sqd-map :name "Load SQD Map")
()
(with-map-viewer-frame (map-viewer-frame)
(let ((file (file-selector "Load SQD Map" "visco:maps;" "sqd")))
(when file
(with-slots (db map-filename text-objects) map-viewer-frame
(setf text-objects nil)
(setf db (make-db-from-sqd-file file))
(setf map-filename file)
(measure-and-draw-map map-viewer-frame))))))
(defun change-os-key-selection ()
(with-map-viewer-frame (map-viewer-frame)
(with-slots (present-os-keys selected-os-keys) map-viewer-frame
(setf selected-os-keys present-os-keys))))
;;;
;;;
;;;
(define-map-viewer-command (com-load-map :name "Load Map")
()
(with-map-viewer-frame (map-viewer-frame)
(let ((file (file-selector "Load Map" "visco:maps;" "db")))
(when file
(with-slots (db map-filename text-objects) map-viewer-frame
(let ((loaded-objects
(load-persistent-object file)))
(setf *image-map* loaded-objects)
(setf db (first loaded-objects))
(install-as-current-db (first loaded-objects))
(setf text-objects (second loaded-objects))
(setf map-filename file)
(measure-and-draw-map map-viewer-frame)))))))
(define-map-viewer-command (com-install-image-map :name "Install Image Map")
()
(with-map-viewer-frame (map-viewer-frame)
(with-slots (db map-filename text-objects) map-viewer-frame
(let ((loaded-objects *image-map*))
(when loaded-objects
(setf db (first loaded-objects))
(install-as-current-db (first loaded-objects))
(setf text-objects (second loaded-objects))
(setf map-filename "Image Map")
(measure-and-draw-map map-viewer-frame))))))
(define-map-viewer-command (com-save-map :name "Save Map")
()
(with-map-viewer-frame (map-viewer-frame)
(let ((file (file-selector "Save Map" "visco:maps;" "db" :save t)))
(when file
(with-slots (db text-objects) map-viewer-frame
(make-object-persistent (list db text-objects)
file))))))
;;;
;;;
;;;
(defun com-draw-current-map ()
(with-map-viewer-frame (map-viewer-frame)
(draw-current-map map-viewer-frame (get-frame-pane map-viewer-frame 'display))))
;;;
;;;
;;;
(define-map-viewer-command (com-describe-object :name "Describe Object")
((object 'db-object))
(labels ((describe-this-object (object level &key slave)
(dolist (os (all-os object))
(multiple-value-bind (string found)
(lookup-os os)
(my-format *standard-output* level
"~A "
(if found
(first string)
"Unknown Object!"))))
(when (and (not slave)
(or (typep object 'db-chain)
(typep object 'db-polygon)))
(fresh-line *standard-output*)
(my-format *standard-output* level "Has Segments:")
(dolist (segment (segments object))
(terpri *standard-output*)
(describe-this-object segment (1+ level)
:slave slave)))
(when (and slave (part-of object))
(dolist (part (part-of object))
(fresh-line *standard-output*)
(my-format *standard-output* level "Part Of:~%")
(describe-this-object part (1+ level)
:slave slave)))))
(window-clear *standard-output*)
(terpri)
(describe-this-object object 0
:slave
(part-of object))))
(define-presentation-to-command-translator describe
((db-object) com-describe-object map-viewer
:gesture :select)
(object)
(list object))
;;;
;;;
;;;
(define-map-viewer-command (com-clear-display :name "Clear Map Display")
()
(with-map-viewer-frame (map-viewer-frame)
(let ((stream (get-frame-pane map-viewer-frame 'display)))
(window-clear stream))))
(define-map-viewer-command (com-redraw :name "Redraw Current Map")
()
(with-map-viewer-frame (frame)
(redisplay-frame-pane frame 'overview)
(com-clear-display)
(com-draw-current-map)))
;;;
;;;
;;;
#+:allegro
(define-map-viewer-command (com-print-whole-map :name "Print Whole Map")
()
(with-map-viewer-frame (map-viewer-frame)
(with-open-stream
(pipe (excl:run-shell-command (format nil "lpr -P~A -h" '|r131_hp|)
:input :stream :wait nil))
(with-output-to-postscript-stream (stream pipe
:orientation :landscape
:scale-to-fit t)
(let ((*sensitive-objects-mode* nil))
(draw-current-map map-viewer-frame stream :clear-p nil))))))
#+:allegro
(define-map-viewer-command (com-print-keylist :name "Print Keylist")
()
(with-map-viewer-frame (map-viewer-frame)
(with-slots (present-os-keys map-filename) map-viewer-frame
(with-open-stream
(pipe (excl:run-shell-command (format nil "lpr -P~A -h" '|r131_hp|)
:input :stream :wait nil))
(with-output-to-postscript-stream (stream pipe
:orientation :landscape
:scale-to-fit t)
(format stream "OS Keylist For File ~A." map-filename)
(show-map-infos stream)
(format stream "~%~%Known OS Keys:~%~%")
(dolist (item present-os-keys)
(princ item stream)
(terpri stream))
(format stream "~%Unknown OS Keys:~%~%")
(dolist (item *unknown-os-keys*)
(princ item stream)
(terpri stream)))))))
;;;
;;;
;;;
(define-map-viewer-command (com-quit :name "Quit")
()
(with-map-viewer-frame (map-viewer-frame)
(let ((yes-or-no (notify-user map-viewer-frame
"Quit selected! Are you sure?"
:style :question)))
(when yes-or-no
(frame-exit map-viewer-frame)))))
;;;
;;;
;;;
(define-map-viewer-command (com-highlight-intersecting-objects* :name "Highlight Intersecting Objects")
()
(let ((object
(accept 'db-object)))
(show-intersecting-objects object)))
(define-map-viewer-command (com-highlight-intersecting-objects)
((object 'db-object :gesture nil))
(show-intersecting-objects object))
(defmethod show-intersecting-objects ((object db-object))
(highlight-all
(intersects object))
(com-draw-current-map))
;;;
;;;
;;;
(define-map-viewer-command (com-highlight-containing-objects* :name "Highlight Containing Objects")
()
(let ((object
(accept 'db-object)))
(show-containing-objects object)))
(define-map-viewer-command (com-highlight-containing-objects)
((object 'db-object :gesture nil))
(show-containing-objects object))
(defmethod show-containing-objects ((object db-object))
(highlight-all
(inside object))
(com-draw-current-map))
;;;
;;;
;;;
(define-map-viewer-command (com-highlight-contained-objects* :name "Highlight Contained Objects")
()
(let ((object
(accept 'db-polygon)))
(show-contained-objects object)))
(define-map-viewer-command (com-highlight-contained-objects)
((object 'db-polygon :gesture nil))
(show-contained-objects object))
(defmethod show-contained-objects ((object db-object))
(highlight-all
(contains object))
(com-draw-current-map))
;;;
;;;
;;;
#|
(defmethod resize-sheet :after ((sheet display-pane) width height)
(declare (ignore width height))
(recalculate-transformation sheet)
(com-draw-current-map))
(defmethod resize-sheet :after ((sheet overview-pane) width height)
(declare (ignore width height))
(recalculate-transformation sheet)
(draw-overview (pane-frame sheet) sheet))
|#
(defun map-viewer (&key (force t)
(process t)
left
top width height
&allow-other-keys)
(let ((port (find-port)))
#+:allegro
(setf (clim:text-style-mapping port
+map-viewer-text-style+)
"-*-lucida-medium-r-normal-*-12-*-*-*-*-*-*-*")
(when (or force (null *map-viewer-frame*))
(unless left
(multiple-value-bind (screen-width screen-height)
(bounding-rectangle-size
(sheet-region (find-graft :port port)))
(setf left 0
top 0
width screen-width
height screen-height)))
#+:Allegro
(if process
(mp:process-run-function
"Map-Viewer"
#'(lambda ()
(setf *map-viewer-frame*
(make-application-frame
'map-viewer
:left (+ 40 left)
:top (+ 40 top)
:width (- width 80)
:height (- height 80)))
(run-frame-top-level *map-viewer-frame*)))
(run-frame-top-level *map-viewer-frame*))
#+:mcl
(if process
(ccl:process-run-function
"Map Viewer"
#'(lambda ()
(run-frame-top-level *map-viewer-frame*)))
(run-frame-top-level *map-viewer-frame*))
#-(or :Allegro :mcl)
(run-frame-top-level *map-viewer-frame*)
*map-viewer-frame*)))
| 48,508 | Common Lisp | .lisp | 1,400 | 28.943571 | 110 | 0.649407 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 9fb6babc86ef403d0addfa90e952b81b4cd9d3ffd8f8ddbc57e9332769216380 | 11,704 | [
-1
] |
11,705 | db8.lisp | lambdamikel_VISCO/src/DB/db8.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: DATABASE; Base: 10 -*-
(in-package database)
(defparameter *cur-db* nil)
;;;
;;;
;;;
(defpersistentclass db ()
((objects :accessor objects :initarg :objects :initform nil)
(spatial-index :accessor spatial-index :initarg :spatial-index :initform nil)
(name :accessor name :initarg :name)))
;;;
;;;
;;;
(defmethod install-as-current-db ((obj db))
(setf *cur-db* obj)
(when (spatial-index obj)
(install-as-current-index
(spatial-index obj)))
*cur-db*)
(defmethod reset-db ((obj db))
(with-slots (objects spatial-index) obj
(setf objects nil)
(reset-spatial-index spatial-index)))
(defmethod store-db ((obj db))
(with-slots (objects name) obj
(make-object-persistent (list obj)
(format nil "~A.db" name))
t))
(defun load-db (fn)
(setf *cur-db* nil)
(install-as-current-db
(first (load-persistent-object fn))))
(defun make-db-from-sqd-file (fn)
(let ((db
(install-as-current-db
(make-instance 'db :name fn))))
(read-sqd-file fn)
(dolist (elem (elements (spatial-index db)))
(when (and (typep elem 'si-geom-thing-with-relations)
(not (typep elem 'db-object))
(not (typep elem 'geom-point))) ; loesche alle Objekte nicht DB-Objekte (bis auf SI-Punkte)
(delete-object elem)))
(calculate-inside-relations (objects db))
db))
(defun get-current-db ()
*cur-db*)
;;;
;;; DB-Objekte
;;;
(defpersistentclass db-object (si-geom-thing-with-relations) ; abstrakt
((dont-display :accessor dont-display :initarg :dont-display :initform nil)
(all-os :accessor all-os :initarg :all-os :initform nil) ; Liste von OS-Schluesseln
(enum :accessor enum :initarg :enum :initform nil)
(line-no :accessor line-no :initarg :line-no :initform nil)))
(defmethod print-object ((obj db-object) stream)
(format stream "#<~A ~A ~A>"
(type-of obj)
(enum obj)
(all-os obj)))
;;;
;;;
;;;
(defpersistentclass db-point (db-object si-geom-point-with-relations)
())
(defpersistentclass db-line (db-object si-geom-line-with-relations)
())
(defpersistentclass db-chain (db-object si-geom-chain-with-relations)
())
(defpersistentclass db-polygon (db-object si-geom-polygon-with-relations)
())
#|
(defpersistentclass db-aggregate (...)
())
|#
;;;
;;;
;;;
(defmethod update-instance-for-different-class :after ((old si-geom-thing-with-relations)
(new db-object)
&key (os nil)
&allow-other-keys)
(when os
(pushnew os (all-os new)))
(unless (typep old 'db-object)
(push new (objects *cur-db*))))
;;;
;;;
;;;
(defmethod make-point ((class (eql 'db-point))
x y &rest initargs)
(let ((point
(apply #'make-point 'si-geom-point-with-relations x y
:affected-by-matrix-p nil
initargs)))
(apply #'change-class point 'db-point :allow-other-keys t initargs)))
(defun db-p (x y &rest initargs)
(apply #'make-point 'db-point x y initargs))
;;;
;;;
;;;
(defmethod make-line ((class (eql 'db-line))
p1 p2 &rest initargs)
(let ((line
(apply #'make-line 'si-geom-line-with-relations p1 p2
:affected-by-matrix-p nil
initargs)))
(centroid line) ; "call-if-needed"-Berechnung anstossen
(pcenter line) ; s.o.
(apply #'change-class line 'db-line :allow-other-keys t initargs)))
(defun db-l (p1 p2 &rest initargs)
(apply #'make-line 'db-line p1 p2 initargs))
;;;
;;;
;;;
(defmethod make-chain ((class (eql 'db-chain))
segment-list
&rest initargs)
(let ((chain
(apply #'make-chain 'si-geom-chain-with-relations segment-list
:affected-by-matrix-p nil
initargs)))
(centroid chain) ; "call-if-needed"-Berechnung anstossen
(pcenter chain) ; s.o.
(apply #'change-class chain 'db-chain :allow-other-keys t initargs)))
(defun db-chain (segment-list &rest initargs)
(apply #'make-chain 'db-chain segment-list initargs))
(defmethod make-polygon ((class (eql 'db-polygon))
segment-list
&rest initargs)
(let ((polygon
(apply #'make-polygon 'si-geom-polygon-with-relations segment-list
:affected-by-matrix-p nil
initargs)))
(centroid polygon) ; "call-if-needed"-Berechnung anstossen
(pcenter polygon) ; s.o.
(apply #'change-class polygon 'db-polygon :allow-other-keys t initargs)))
(defun db-poly (segment-list &rest initargs)
(apply #'make-polygon 'db-polygon segment-list initargs))
#|
(defun make-db-aggregate (objects &optional (os nil) (line-no nil))
(make-instance 'db-aggregate :components objects :os os :line-no line-no))
|#
;;;
;;;
;;;
(defun set-client-bb (xmin ymin xmax ymax) ; wird vom SQD-Reader aufgerufen => Bounding Box!
(setf (spatial-index *cur-db*)
(init-spatial-index xmin ymin xmax ymax)))
;;;
;;; Schnittstelle zum SQD-Reader: dieser ruft die transform-sqd...-Routinen auf!
;;;
;;; ACHTUNG!
(defun get-renamed-os (os)
os)
(defun transform-sqd-pg (enum line-no os x y)
(let ((fn (get-db-transform-function os 'pg))
(os (get-renamed-os os)))
(funcall fn os x y line-no enum)))
(defun transform-sqd-kr (enum line-no os x y r)
(declare (ignore r))
(let ((fn (get-db-transform-function os 'kr))
(os (get-renamed-os os)))
(funcall fn os x y line-no enum)))
(defun transform-sqd-sy (enum line-no os x y text)
(let ((fn (get-db-transform-function os 'sy))
(os (get-renamed-os os)))
(funcall fn os x y line-no enum text)))
(defun transform-sqd-tx (enum line-no os tx ty h w text)
(let ((fn (get-db-transform-function os 'tx))
(os (get-renamed-os os)))
(funcall fn os tx ty h w text line-no enum)))
(defun transform-sqd-li (enum line-no os ps pe)
(let ((fn (get-db-transform-function os 'li))
(os (get-renamed-os os)))
(funcall fn os ps pe line-no enum)))
(defun transform-sqd-sn (enum line-no os ps pe points)
(let ((fn (get-db-transform-function os 'sn))
(os (get-renamed-os os)))
(funcall fn os ps pe points line-no enum)))
(defun transform-sqd-bo (enum line-no os x y r w ps pe)
(let ((fn (get-db-transform-function os 'bo))
(os (get-renamed-os os)))
(funcall fn os ps pe x y r w line-no enum)))
(defun transform-sqd-fl (enum line-no os components)
(let ((fn (get-db-transform-function os 'fl))
(os (get-renamed-os os)))
(funcall fn os components line-no enum)))
;;;
;;; TX-Konstruktoren
;;;
(defun tx-create-map-text (os tx ty h w text line-no enum)
(declare (ignore enum line-no os))
(make-instance 'map-text
:tx tx :ty ty
:h h :w w
:text text))
;;;
;;; PG-Konstruktoren
;;;
(defun pg-create-point (os x y line-no enum)
(db-p x y :os os :line-no line-no :enum enum))
;;;
;;; LI-Konstruktoren
;;;
(defun li-create-line (os ps pe line-no enum)
(db-l ps pe :os os :line-no line-no :enum enum))
;;;
;;; BO-Konstruktoren
;;;
(defun bo-create-line (os ps pe x y r w line-no enum)
(declare (ignore w r x y))
(db-l ps pe :os os :line-no line-no :enum enum))
;;;
;;; SN-Konstruktoren
;;;
(defun sn-create-segment-list (os ps pe points line-no enum)
(let* ((points (transform-xy-list points)))
(if points
(append
(list (db-l
ps
(db-p (first (first points))
(second (first points)))
:os os :line-no line-no :enum enum))
(mapcar #'(lambda (p1 p2)
(db-l
(db-p (first p1) (second p1))
(db-p (first p2) (second p2))
:os os :line-no line-no :enum enum))
points (rest points))
(list (db-l
(db-p (first (first (last points)))
(second (first (last points))))
pe
:os os :line-no line-no :enum enum)))
(db-l
ps pe
:os os :line-no line-no :enum enum))))
;;;
;;; FL-Konstruktoren
;;;
(defun fl-create-containing-polygon (os components line-no enum)
(let ((polygons
(create-polygons
(mapcan #'(lambda (i)
(if (listp i) ; zerlegte Kette ?
i
(list i)))
components)))
(db-polygons nil))
(dolist (i polygons) ; gibt es Polygon j, das i enthaelt ? => i verwerfen
(unless (some #'(lambda (j)
(and (not (eq i j)) ; Arbeit sparen
(inside-p i j)))
polygons)
(push (db-poly (segments i)
:os os
:line-no line-no
:enum enum)
db-polygons)))
db-polygons))
(defun fl-do-nothing (os components line-no enum)
(declare (ignore os components line-no enum))
nil) ; da die Segmente schon angelegt wurden => alles ok
;;;
;;; SY-Konstruktoren
;;;
(defun sy-create-point (os x y line-no enum txt)
(declare (ignore txt))
(db-p x y :os os :line-no line-no :enum enum))
(defun sy-create-church (os x y line-no enum txt)
(declare (ignore txt))
(db-p x y :os os :line-no line-no :enum enum))
(defun sy-create-postoffice (os x y line-no enum txt)
(declare (ignore txt))
(db-p x y :os os :line-no line-no :enum enum))
(defun sy-create-hole (os x y line-no enum txt)
(declare (ignore txt))
(db-p x y :os os :line-no line-no :enum enum))
(defun sy-create-allotment (os x y line-no enum txt)
(declare (ignore txt))
(db-p x y :os os :line-no line-no :enum enum))
(defun sy-create-chapel (os x y line-no enum txt)
(declare (ignore txt))
(db-p x y :os os :line-no line-no :enum enum))
(defun sy-create-firestation (os x y line-no enum txt)
(declare (ignore txt))
(db-p x y :os os :line-no line-no :enum enum))
;;;
;;; Hilfsfunktionen
;;;
(defun create-polygons (components)
(let ((poly-segments (list (first components)))
(components (rest components)))
(catch 'done
(loop
(catch 'next
(progn
(dolist (i components)
(let ((j (first poly-segments)))
(when (joins-p i j)
(push i poly-segments)
(setf components (delete i components))
(throw 'next nil))))
(throw 'done nil)))))
(let ((poly
(make-polygon 'si-geom-polygon-with-relations poly-segments :affected-by-matrix-p nil)))
(if components
(cons poly
(create-polygons components))
(list poly)))))
| 9,948 | Common Lisp | .lisp | 311 | 28.237942 | 94 | 0.656555 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | d3acd40d02bd265986f21a73ebdd51c6a9e356f0441e62dc067a9a6c73e30aed | 11,705 | [
-1
] |
11,706 | query-result3.lisp | lambdamikel_VISCO/src/GUI/query-result3.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
;;;
;;;
;;;
(defun show-search-progress (percent &key force-p)
(with-visco-inspector-frame (frame)
(let* ((stream (get-frame-pane frame 'progress-bar))
(time (get-universal-time)))
(with-slots (last-percent last-time) frame
(when (or (not last-percent)
(and (not (= last-percent percent))
(or force-p
(> (- time last-time) 1))))
(multiple-value-bind (width height)
(window-inside-size stream)
(with-output-recording-options (stream :draw t :record nil)
(when last-percent
(draw-rectangle* stream 0 0 (* last-percent width) height
:ink +background-ink+))
(setf last-percent percent)
(draw-rectangle* stream 0 0 (* percent width) height
:ink +red+)
(setf last-time time))))))))
(defmacro with-pretty-map-output (&body body)
`(let ((database::*display-map-text-mode* nil)
(database::*display-binding-names-mode* nil)
(database::*display-nodes-mode* nil)
(database::*sensitive-objects-mode* nil))
,@body))
;;;
;;;
;;;
(eval-when (:compile-toplevel :load-toplevel :execute)
(defclass query-result ()
((bindings :accessor bindings :initarg :bindings)
(selected :accessor selected :initform nil)
(map-radius :accessor map-radius :initarg :map-radius)
(map-xcenter :accessor map-xcenter :initarg :map-xcenter)
(map-ycenter :accessor map-ycenter :initarg :map-ycenter)))
(defclass query-page ()
((objects :accessor objects :initarg :objects :initform nil)))
)
(defmethod full ((obj query-page))
(= (length (objects obj))
(* +x-no-of-thumbnails+
+y-no-of-thumbnails+)))
(defun make-new-page ()
(with-visco-inspector-frame (frame)
(let ((obj (make-instance 'query-page)))
(pushend obj (pages frame))
(setf (active-page frame) obj)
(setf (selected-page frame) obj)
(update-buttons)
obj)))
(defun get-position (obj)
(with-visco-inspector-frame (frame)
(when (and obj (selected-page frame))
(let ((pos (position obj (objects (selected-page frame)))))
(when pos
(multiple-value-bind (w h)
(thumbnail-size frame)
(let ((y (floor pos +x-no-of-thumbnails+))
(x (mod pos +x-no-of-thumbnails+)))
(values (+ (* w x) +spacing+)
(+ (* h y) +spacing+)
(- (* w (1+ x)) +spacing+)
(- (* h (1+ y)) +spacing+)))))))))
(defmethod thumbnail-size ((frame visco-inspector))
(multiple-value-bind (width height)
(window-inside-size (get-frame-pane frame 'query-results))
(values (/ (- width 1) +x-no-of-thumbnails+)
(/ (- height 1) +y-no-of-thumbnails+))))
(defmethod draw-result ((result query-result) stream w h &key full-view)
(set-current-map-position-and-radius (map-xcenter result)
(map-ycenter result)
(+ (map-radius result) 50))
(labels ((draw-it ()
(when *draw-thumbnails*
(with-pretty-map-output
(with-output-recording-options (stream :draw t
:record #+visco-demo-mode t)
(draw-current-map-to-foreign-stream stream
:overview t
:width w
:height h
:show-types-p t
:show-bindings (bindings result)))))))
(if (not full-view)
(with-output-as-presentation (stream result 'query-result
:single-box t
:allow-sensitive-inferiors nil)
(draw-rectangle* stream 1 1 (1- w) (1- h)
:ink (if (selected result)
+yellow+
+background-ink+))
(draw-it)
(draw-rectangle* stream 0 0 w h
:filled nil))
(draw-it))))
(defmethod draw-thumbnail ((result query-result))
(with-visco-inspector-frame (frame)
(let ((stream (get-frame-pane frame 'query-results)))
(multiple-value-bind (xf yf xt yt)
(get-position result)
(with-translation (stream xf yf)
(draw-result result stream (- xt xf) (- yt yf)))))))
(define-presentation-method highlight-presentation ((obj query-result) record stream state)
(declare (ignore state))
(let* ((obj (presentation-object record)))
(multiple-value-bind (xf yf xt yt)
(get-position obj)
(when xf ; get-position kann NIL liefern
(draw-rectangle* stream
xf yf xt yt
:filled nil
:ink +flipping-ink+
:line-thickness 10)))))
(defmethod object-selected-position-test ((obj query-result) record x y)
(declare (ignore record))
(multiple-value-bind (xf yf xt yt)
(get-position obj)
(when xf
(and (<= xf x xt)
(<= yf y yt)))))
(defun get-page-nr ()
(with-visco-inspector-frame (frame)
(if (selected-page frame)
(1+ (position (selected-page frame) (pages frame)))
0)))
;;;
;;;
;;;
(defun abort-search (button)
(declare (ignore button))
(setf query-compiler::*abort-search* t))
(defun previous-page (button)
(declare (ignore button))
(with-visco-inspector-frame (frame)
(when (selected-page frame)
(let ((pos (position (selected-page frame) (pages frame))))
(unless (zerop pos)
(setf (selected-page frame)
(nth (1- pos) (pages frame)))
(update-buttons))))))
(defun next-page (button)
(declare (ignore button))
(with-visco-inspector-frame (frame)
(let ((rest (rest (member (selected-page frame) (pages frame)))))
(when rest
(setf (selected-page frame) (first rest))
(update-buttons)))))
(defun delete-all-pages (button)
(declare (ignore button))
(with-visco-inspector-frame (frame)
(setf (pages frame) nil
(active-page frame) nil
(selected-page frame) nil)
(update-buttons)))
(defun delete-page (button)
(declare (ignore button))
(with-visco-inspector-frame (frame)
(when (selected-page frame)
(setf (pages frame)
(delete (selected-page frame)
(pages frame)))
(setf (selected-page frame)
(first (pages frame)))
(update-buttons))))
(defun delete-selected (button)
(declare (ignore button))
(with-visco-inspector-frame (frame)
(when (selected-page frame)
(dolist (obj (remove-if-not #'selected (objects (selected-page frame))))
(setf (objects (selected-page frame))
(delete obj (objects (selected-page frame)))))
(if (objects (selected-page frame))
(update-buttons)
(delete-page +button-delete-page+)))))
(defun delete-unselected (button)
(declare (ignore button))
(with-visco-inspector-frame (frame)
(when (selected-page frame)
(dolist (obj (remove-if #'selected (objects (selected-page frame))))
(setf (objects (selected-page frame))
(delete obj (objects (selected-page frame)))))
(if (objects (selected-page frame))
(update-buttons)
(delete-page +button-delete-page+)))))
(defun unselect-all (button)
(declare (ignore button))
(with-visco-inspector-frame (frame)
(when (selected-page frame)
(dolist (obj (objects (selected-page frame)))
(setf (selected obj) nil))
(update-buttons))))
(defun button-draw-thumbnails (button value)
(declare (ignore button))
(setf *draw-thumbnails* value))
(defun button-permutations (button value)
(declare (ignore button))
(setf *permutations* value))
;;;
;;;
;;;
(defun lock-buttons ()
(dolist (button (list +button-previous+ +button-next+
+button-delete-all-pages+ +button-delete-page+
+button-delete-selected+ +button-delete-unselected+
+button-unselect-all+))
(deactivate-gadget button))
(setf *searching-active* t))
(defun unlock-buttons ()
(setf *searching-active* nil)
(update-buttons)
(show-search-progress 0 :force-p t))
(defun update-buttons ()
(with-visco-inspector-frame (frame)
(unless *searching-active*
(cond ((pages frame)
(let ((nr (get-page-nr)))
(if (= 1 nr)
(deactivate-gadget +button-previous+)
(activate-gadget +button-previous+))
(if (= nr (length (pages frame)))
(deactivate-gadget +button-next+)
(activate-gadget +button-next+))
(activate-gadget +button-delete-selected+)
(activate-gadget +button-delete-unselected+)
(activate-gadget +button-delete-page+)
(activate-gadget +button-delete-all-pages+)
(activate-gadget +button-unselect-all+)))
(t (deactivate-gadget +button-previous+)
(deactivate-gadget +button-next+)
(deactivate-gadget +button-delete-all-pages+)
(deactivate-gadget +button-delete-page+)
(deactivate-gadget +button-delete-selected+)
(deactivate-gadget +button-delete-unselected+)
(deactivate-gadget +button-unselect-all+))))
(window-clear (get-frame-pane frame 'query-results))
(redisplay-frame-pane frame (get-frame-pane frame 'page-nr) :force-p t)
(draw-query-results frame (get-frame-pane frame 'query-results))))
(defmethod show-page-nr ((frame visco-inspector) stream)
#-visco-demo-mode (format stream " ~A /~% ~A" (get-page-nr) (length (pages frame)))
#+visco-demo-mode (format stream " Page No. ~A of ~A Pages." (get-page-nr) (length (pages frame))))
;;;
;;;
;;;
(defun make-query-result ()
(with-visco-inspector-frame (inspector-frame)
(let* ((query (get-current-query))
(objects
(remove-if-not #'matches-with-database-object-p
(visco-objects query)))
(bindings
(mapcan #'(lambda (visco-object)
(when (primary-p visco-object)
(if (and (typep visco-object 'rubberband)
(typep (bound-to visco-object) 'geom-chain))
(segments (bound-to visco-object))
(list (bound-to visco-object)))))
objects)))
(when (or *permutations*
(not
(some #'(lambda (match)
(set-equal bindings match))
(all-matches inspector-frame))))
(push bindings (all-matches inspector-frame))
(when (or (not (active-page inspector-frame))
(full (active-page inspector-frame)))
(make-new-page))
(let* ((agg (make-aggregate 'geom-aggregate
(mapcar #'bound-to objects)
:hierarchicly-p nil))
(xcenter (x (pcenter agg)))
(ycenter (y (pcenter agg)))
(radius (max (+ 30 (/ (- (x (pmax agg)) (x (pmin agg))) 2))
(+ 30 (/ (- (y (pmax agg)) (y (pmin agg))) 2))))
(res-object (make-instance 'query-result
:bindings
(mapcan #'(lambda (visco-object)
(if (and (typep visco-object 'rubberband)
(typep (bound-to visco-object) 'geom-chain))
(mapcar #'(lambda (segment)
(list segment
visco-object
(mapcar #'(lambda (os)
(first (lookup-os os)))
(all-os segment))))
(segments (bound-to visco-object)))
(list (list (bound-to visco-object)
visco-object
(mapcar #'(lambda (os)
(first (lookup-os os)))
(all-os (bound-to visco-object)))))))
objects)
:map-radius radius
:map-xcenter xcenter
:map-ycenter ycenter)))
(pushend res-object (objects (active-page inspector-frame)))
(when (eq (selected-page inspector-frame)
(active-page inspector-frame))
(draw-thumbnail res-object)))))))
;;;
;;;
;;;
(defmethod draw-selected-query-result ((frame visco-inspector) stream)
(let ((result (selected-query-result frame)))
(multiple-value-bind (w h)
(window-inside-size (get-frame-pane frame 'selected-query-result))
(when result
(let ((*draw-thumbnails* t))
(draw-result result stream (- w 2) (- h 2) :full-view t))))))
(defmethod draw-query-results ((frame visco-inspector) stream)
(declare (ignore stream))
(when (selected-page frame)
(dolist (result (objects (selected-page frame)))
(draw-thumbnail result))))
;;;
;;;
;;;
(define-visco-inspector-command (com-inspect-query-result)
((object 'query-result))
(with-visco-inspector-frame (frame)
(setf (selected-query-result frame) object)
(dolist (obj (objects (get-current-db)))
(setf (bound-to obj) nil))
(dolist (binding (bindings object))
(setf (bound-to (first binding)) (second binding)))))
(define-presentation-to-command-translator inspect-query-result
(query-result
com-inspect-query-result visco-inspector
:tester (() (not *searching-active*))
:echo nil
:maintain-history nil
:gesture :select)
(object)
(list object))
;;;
;;;
;;;
(define-visco-inspector-command (com-select-query-result)
((object 'query-result))
(setf (selected object) (not (selected object)))
(com-inspect-query-result object)
(draw-thumbnail object))
(define-presentation-to-command-translator select-query-result
(query-result
com-select-query-result visco-inspector
:echo nil
:tester (() (not *searching-active*))
:maintain-history nil
:gesture :move)
(object)
(list object))
;;;
;;;
;;;
#+(and mcl antiker-mac)
(defmethod draw-overview ((frame visco-inspector) stream)
nil)
(defmethod draw-overview ((frame visco-inspector) stream)
(with-slots (overview-pattern current-map-range
overview-transformation) frame
(multiple-value-bind (width height)
(bounding-rectangle-size (bounding-rectangle (window-viewport stream)))
(when (get-current-db)
(cond (overview-pattern
(draw-pixmap* stream
overview-pattern
0 0)
(database::show-current-map-range :record t
:coordinates nil
:stream stream
:transformation (database::calculate-transformation stream)))
(t (setf overview-pattern
(with-output-to-pixmap (stream2
(sheet-medium stream)
:width width
:height height)
(with-pretty-map-output
(database::unhighlight-all)
(database::full-map-range)
(database::recalculate-transformation stream :width width :height height)
(database::with-map-viewer-frame (map-viewer)
(database::draw-current-map map-viewer stream2
:overview t
:clear-p nil)))))
(draw-pixmap* stream
overview-pattern
0 0)))))))
| 14,239 | Common Lisp | .lisp | 391 | 30.14578 | 101 | 0.634137 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | b3409168c29f7a8fa21fe40bde664f171eb7415a07545ac45d1c5802c3fd0561 | 11,706 | [
-1
] |
11,707 | mover7.lisp | lambdamikel_VISCO/src/GUI/mover7.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
;;;
;;;
;;;
(defun moveable-object-p (object)
(and (typep object
'(or #| gui-label |#
gui-semantics-label
gui-at-most-label
gui-orientation-arrow
gui-relative-orientation-circle
gui-point
gui-line
gui-chain-or-polygon
gui-drawn-enclosure))
(typecase object
(gui-point (not (and (typep object 'possible-operator-result-mixin)
(res-of-operators object))))
((or gui-line gui-chain-or-polygon)
(not (some #'(lambda (part)
(and (typep part 'possible-operator-result-mixin)
(res-of-operators part)))
(point-list object))))
(otherwise t))))
(define-visco-command (com-move :name nil)
((object 'gui-object) (x 'number) (y 'number))
(with-visco-frame (visco)
(let ((focus (current-focus visco)))
(prepare-to-move)
(multiple-value-bind (xc yc)
(xy-to-grid x y)
(interactive-move object xc yc))
(set-current-focus-to (find-named-history-entry (name focus)))
(refresh))))
(define-visco-command (com-move* :name "Move")
()
(let ((obj (accept '(and gui-object
(satisfies moveable-object-p))
:prompt "Select Object To Move")))
(multiple-value-bind (x y)
(stream-pointer-position (with-visco-frame (visco)
(get-frame-pane visco 'display)))
(com-move obj x y))))
(defmethod command-enabled ((command (eql 'com-move*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(and (get-current-query)
(some #'moveable-object-p (visco-objects (get-current-query)))))
(defun prepare-to-move ()
(let ((vr *visualized-relations*))
(setf *sceleton-view* t
*visualized-relations* nil)
(refresh)
(setf *sceleton-view* nil
*visualized-relations* vr)))
;;;
;;;
;;;
(define-presentation-to-command-translator move
(gui-object
com-move visco
:documentation ((object stream) (format stream "Move ~A" object))
:tester ((object)
(moveable-object-p object))
:echo nil
:maintain-history nil
:gesture :move)
(object x y)
(list object x y))
(define-presentation-to-command-translator move-label
(gui-query-object
com-move visco
:documentation ((object stream) (format stream "Move ~A" (status-label object)))
:echo nil
:maintain-history nil
:gesture nil)
(object x y)
(list (status-label object) x y))
;;;
;;;
;;;
(defmethod interactive-move ((object gui-label) xc yc)
(with-visco-frame (visco)
(let ((stream (get-frame-pane visco 'display))
(x-off (x-off object))
(y-off (y-off object)))
(flet ((exit-code ()
(setf (x-off object) x-off
(y-off object) y-off)
(return-from interactive-move)))
(with-output-recording-options (stream :draw t :record nil)
(tracking-pointer (stream)
(:pointer-motion (x y)
(multiple-value-bind (x y)
(xy-to-grid x y)
(draw object stream :handling-active t)
(setf (x-off object) (+ (- x xc ) x-off)
(y-off object) (+ (- y yc) y-off))
(draw object stream :handling-active t)))
(:keyboard (character)
(when (and (characterp character)
(char-equal character #\q))
(exit-code)))
(:pointer-button-press (event)
(if (= (pointer-event-button event)
+pointer-right-button+)
(exit-code)
(progn
(register-undo-information (format nil "Move ~A" object))
(execute
(register-history-entry
""
`(let* ((obj (find-named-visco-object ,(name (object object))))
(label ,(typecase object
(gui-status-label '(status-label obj))
(gui-semantics-label '(semantics-label obj))
(gui-at-most-label '(at-most-label obj)))))
(setf (x-off label) ,(x-off object)
(y-off label) ,(y-off object))
obj)
(list (object object))))
(return))))))))))
;;;
;;;
;;;
(defmethod interactive-move ((object gui-orientation-arrow) xc yc)
(declare (ignore xc yc))
(with-visco-frame (visco)
(let* ((stream (get-frame-pane visco 'display))
(master (object object))
(old-alpha (alpha-off object))
(old-r (r object))
(old-rho-off (rho-off object))
(old-r-off (r-off object))
(alpha-master (if (typep master 'geom-line)
(global-orientation master)
0)))
(labels ((exit-code ()
(setf (r object) old-r
(alpha-off object) old-alpha
(rho-off object) old-rho-off
(r-off object) old-r-off)
(return-from interactive-move)))
(with-output-recording-options (stream :draw t :record nil)
(tracking-pointer (stream)
(:pointer-motion (x y)
(multiple-value-bind (x y)
(xy-to-grid x y)
(draw object stream :handling-active t)
(multiple-value-bind (ox oy)
(get-origin-for object)
(multiple-value-bind (r alpha)
(distance-and-orientation* ox oy
x y)
(setf (r object) r
(alpha-off object) (- alpha alpha-master))))
(draw object stream :handling-active t)))
(:keyboard (character)
(when (and (characterp character)
(char-equal character #\q))
(exit-code)))
(:pointer-button-press (event x y)
(cond ((= (pointer-event-button event)
+pointer-right-button+)
(exit-code))
((and (= (pointer-event-button event)
+pointer-left-button+)
(= (event-modifier-state event)
+shift-key+))
(draw object stream :handling-active t)
(set-origin-to object x y)
(draw object stream :handling-active t))
((and (= (pointer-event-button event)
+pointer-left-button+))
(register-undo-information (format nil "Move ~A" object))
(execute
(register-history-entry
""
`(let* ((obj (find-named-visco-object ,(name (object object))))
(arrow (orientation-arrow obj)))
(setf (r arrow) ,(r object))
(setf (r-off arrow) ,(r-off object)
(rho-off arrow) ,(rho-off object))
(setf (alpha-off arrow) ,(alpha-off object))
obj)
(list (object object))))
(return))))))))))
;;;
;;;
;;;
(defmethod interactive-move ((object gui-relative-orientation-circle) xc yc)
(declare (ignore xc yc))
(let ((obj1 (object1 object))
(obj2 (object2 object)))
(gui-delete-object object nil)
(gui-set-relative-orientation-constraint obj1 obj2)
(pop-undo-stack)
(set-undo-operation-description-to (format nil "Move ~A" object))))
;;;
;;;
;;;
(defmethod interactive-move ((object gui-point) xc yc)
(interactive-mover object
(list object) xc yc))
(defmethod interactive-move ((object gui-line) xc yc)
(interactive-mover object
(list (p1 object)
(p2 object))
xc yc))
(defmethod interactive-move ((object gui-chain-or-polygon) xc yc)
(interactive-mover object
(point-list object)
xc yc))
;;;
;;;
;;;
(defun interactive-mover (object point-list xc yc)
(with-visco-frame (visco)
(let ((stream (get-frame-pane visco 'display)))
(register-undo-information (format nil "Move ~A" object))
(let* ((direct-masters (remove-duplicates
(mapcan #'(lambda (point)
(copy-list (part-of point)))
point-list)))
(circles (remove-duplicates
(mapcan #'relative-orientation-circles
(remove-if-not #'(lambda (obj)
(typep obj 'atomic-rubberband))
direct-masters))))
(roots (remove-duplicates
(mapcan #'(lambda (segment)
(copy-list (part-of segment)))
direct-masters)))
(x-offsets (mapcar #'(lambda (point)
(- xc (x point)))
point-list))
(y-offsets (mapcar #'(lambda (point)
(- yc (y point)))
point-list))
(org-coords (mapcar #'(lambda (point) (list (x point) (y point)))
point-list)))
(with-output-recording-options (stream :draw t :record nil)
(labels ((draw-it ()
(dolist (master direct-masters)
(draw master stream
:draw-relative-orientation-circles nil
:draw-component-objects nil
:handling-active t))
(dolist (root roots)
(draw (status-label root) stream
:handling-active t)
(when (semantics root)
(draw (semantics-label root) stream
:handling-active t))
(when (at-most-constraint root)
(draw (at-most-label root) stream
:handling-active t)))
(dolist (circle circles)
(draw circle stream
:handling-active t))
(dolist (point point-list)
(setf (already-drawn point) nil)
(draw point stream :handling-active t))))
(if (not (tracking-pointer (stream)
(:pointer-motion (x y)
(multiple-value-bind (x y)
(xy-to-grid x y)
(when (every #'(lambda (point xoff yoff)
(inside-p* (- x xoff)
(- y yoff)
(on-transparency point)))
point-list x-offsets y-offsets)
(draw-it)
(mapc #'(lambda (point xoff yoff)
(setf (x point) (- x xoff)
(y point) (- y yoff)))
point-list x-offsets y-offsets)
(dolist (master direct-masters)
(calculate-bounding-box master))
(dolist (root roots)
(calculate-centroid root))
(draw-it))))
(:keyboard (character)
(when (and (characterp character)
(char-equal character #\q))
(return nil)))
(:pointer-button-press (event)
(if (= (pointer-event-button event)
+pointer-right-button+)
(return nil)
(return t)))))
(progn
(pop-undo-stack)
(mapc #'(lambda (org-coord point)
(setf (x point) (first org-coord)
(y point) (second org-coord)))
org-coords point-list)
(dolist (master direct-masters)
(calculate-bounding-box master)))
(unless (change-query-from-to
(loop as point in point-list collect (history-entry point))
(loop as point in point-list collect
(get-history-entry-for point
:transparency (on-transparency point)
:x (x point)
:y (y point)
:description (operation-descr (history-entry point))
:transparency (on-transparency point)
:ink-rgb-list (ink-rgb-list point)
:name (name point)
:status (status point))))
(pop-undo-stack)))))))))
(defun find-closest-point (xc yc point-list)
(let ((min-dist nil)
(min-point nil))
(dolist (point point-list)
(let ((d (distance-between* xc yc (x point) (y point))))
(when (or (not min-dist)
(< d min-dist))
(setf min-dist d
min-point point))))
min-point))
(defmethod interactive-move ((object gui-drawn-enclosure) xc yc)
(with-visco-frame (visco)
(let* ((stream (get-frame-pane visco 'display))
(point-list (point-list object))
(closest-point (find-closest-point xc yc (cons (centroid object) point-list)))
(modify-single-point (unless (eq closest-point (centroid object))
closest-point)))
(register-undo-information (format nil "Move ~A" object))
(let* ((xylist nil)
(x-offsets (mapcar #'(lambda (point)
(- xc (x point)))
point-list))
(y-offsets (mapcar #'(lambda (point)
(- yc (y point)))
point-list))
(org-coords (mapcar #'(lambda (point) (list (x point) (y point)))
point-list)))
(with-output-recording-options (stream :draw t :record nil)
(if (not (tracking-pointer (stream)
(:pointer-motion (x y)
(multiple-value-bind (x y)
(xy-to-grid x y)
(if modify-single-point
(when (inside-p* x y (on-transparency object))
(draw object stream :handling-active t)
(setf (x modify-single-point) x
(y modify-single-point) y)
(setf xylist
(mapcan #'(lambda (point)
(list (x point)
(y point)))
point-list))
(setf (drawable-pointlist object)
(get-drawable-pointlist-for object))
(draw object stream :handling-active t))
(when (every #'(lambda (point xoff yoff)
(declare (ignore point))
(inside-p* (- x xoff)
(- y yoff)
(on-transparency object)))
point-list x-offsets y-offsets)
(draw object stream :handling-active t)
(setf xylist
(mapcan #'(lambda (point xoff yoff)
(progn (setf (x point) (- x xoff)
(y point) (- y yoff)))
(list (x point)
(y point)))
point-list x-offsets y-offsets))
(setf (drawable-pointlist object)
(get-drawable-pointlist-for object))
(draw object stream :handling-active t)))))
(:keyboard (character)
(when (and (characterp character)
(char-equal character #\q))
(return nil)))
(:pointer-button-press (event)
(if (= (pointer-event-button event)
+pointer-right-button+)
(return nil))
(return t))))
(progn
(pop-undo-stack)
(mapc #'(lambda (org-coord point)
(setf (x point) (first org-coord)
(y point) (second org-coord)))
org-coords point-list)
(setf (drawable-pointlist object)
(get-drawable-pointlist-for object)))
(unless (change-query-from-to (history-entry object)
(get-history-entry-for object
:description (operation-descr (history-entry object))
:transparency (on-transparency object)
:pattern-id (pattern-id object)
:opaque-p (opaque-p object)
:ink-rgb-list (ink-rgb-list object)
:name (name object)
:negated-p (negated-p object)
:pointlist xylist))
(pop-undo-stack))))))))
| 15,519 | Common Lisp | .lisp | 403 | 27.243176 | 106 | 0.539888 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 094ec7b266a2f49f374e53cc0a3ee693738732bd75fe5685650730374d02ae2a | 11,707 | [
-1
] |
11,708 | operators9.lisp | lambdamikel_VISCO/src/GUI/operators9.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
(define-presentation-translator execute-selected-command
(gui-object command visco :tester ((object)
(and *operator-mode*
(first-argument-acceptable-p (command *operator-mode*)
object)))
:documentation ((stream)
(and *operator-mode*
(format stream "~A" (first (doc *operator-mode*)))))
:gesture :apply-operator)
(object)
`(,(command *operator-mode*) ,object))
(defun command-enabled-p (command-name-symbol)
(let ((query (get-current-query)))
(and query
(some #'(lambda (object1)
(and (first-argument-acceptable-p command-name-symbol
object1)
(=> (binary-command-p command-name-symbol)
(some #'(lambda (object2)
(second-argument-acceptable-p command-name-symbol
object1
object2))
(remove object1 (visco-objects query))))))
(visco-objects query)))))
(defun binary-command-p (name)
(member name '(com-create-intersection-point com-create-intersection-point*
com-set-relative-orientation-constraint com-set-relative-orientation-constraint*)))
(defun accept-first-command-arg ()
(with-visco-frame (visco)
(redisplay-frame-pane visco 'display)
(redraw-buttons)
(accept `(and gui-object
(satisfies first-arg-ok-p))
:prompt "Select First Argument")))
;;;
;;;
;;;
(defmethod first-argument-acceptable-p ((op symbol) (obj gui-object))
nil)
(defmethod second-argument-acceptable-p ((op symbol)
(obj1 gui-object)
(obj2 gui-object))
nil)
(defun first-arg-ok-p (obj)
(and *operator-mode*
(first-argument-acceptable-p (command *operator-mode*) obj)))
(defvar *first-arg* nil)
(defun second-arg-ok-p (obj)
(and *operator-mode*
(second-argument-acceptable-p (command *operator-mode*) *first-arg* obj)))
;;;
;;;
;;;
(define-visco-command (com-create-centroid :name "Create Centroid")
((obj `(and gui-object
(satisfies first-arg-ok-p))))
(register-undo-information nil)
(multiple-value-bind (res he)
(execute
(register-constructor-history-entry
""
`(let ((res (apply-create-centroid (find-named-visco-object ,(name obj))
',*point-status* ,*point-mode*
:name ,(get-next-name))))
(when (and res (not (eq res 'not-applicable)))
res))
(list obj)))
(if res
(let ((descr
(format nil "Create Centroid ~A Of ~A" res obj)))
(setf (operation-descr he) descr)
(set-undo-operation-description-to descr)
(set-current-focus-to-newest-history-entry))
(progn (beep) (delete-history-entry he)
(pop-undo-stack))))
(refresh))
(defmethod first-argument-acceptable-p ((op (eql 'com-create-centroid)) (obj gui-object))
(and *point-status*
*point-mode*
(create-centroid-applicable-p obj *point-status* *point-mode*)))
(defmethod command-enabled ((command (eql 'com-create-centroid)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p command))
(defmethod command-enabled ((command (eql 'com-create-centroid*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p 'com-create-centroid))
(define-visco-command (com-create-centroid* :name "Create Centroid")
nil
(let ((*operator-mode* *button-create-centroid*))
(com-create-centroid (accept-first-command-arg)))
(redraw-buttons))
;;;
;;;
;;;
(define-visco-command (com-create-intersection-point :name "Create Intersection Point")
((obj1 `(and gui-object
(satisfies first-arg-ok))))
(let ((*first-arg* obj1))
(let ((obj2
(accept `(and gui-object
(satisfies second-arg-ok-p))
:prompt " Select Second Argument")))
(register-undo-information nil)
(multiple-value-bind (res he)
(execute
(register-constructor-history-entry
""
`(let ((res (apply-create-intersection-point
(find-named-visco-object ,(name obj1))
(find-named-visco-object ,(name obj2))
',*point-status* ,*point-mode*
:name ,(get-next-name))))
(when (and res (not (eq res 'not-applicable)))
res))
(list obj1 obj2)))
(if res
(let ((descr (format nil "Create Intersection Point ~A Of ~A And ~A"
res obj1 obj2)))
(setf (operation-descr he) descr)
(set-undo-operation-description-to descr)
(set-current-focus-to-newest-history-entry))
(progn (beep) (delete-history-entry he)
(pop-undo-stack))))))
(refresh))
(defmethod first-argument-acceptable-p ((op (eql 'com-create-intersection-point))
(obj1 gui-object))
(and *point-status*
*point-mode*
(some #'(lambda (obj2)
(second-argument-acceptable-p op
obj1 obj2))
(visco-objects (get-current-query)))))
(defmethod second-argument-acceptable-p ((op (eql 'com-create-intersection-point))
(obj1 gui-object)
(obj2 gui-object))
(create-intersection-point-applicable-p obj1 obj2
*point-status*
*point-mode*))
(defmethod command-enabled ((command (eql 'com-create-intersection-point)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p command))
(defmethod command-enabled ((command (eql 'com-create-intersection-point*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p 'com-create-intersection-point))
(define-visco-command (com-create-intersection-point* :name "Create Intersection Point")
nil
(let ((*operator-mode* *button-create-intersection-point*))
(com-create-intersection-point (accept-first-command-arg)))
(redraw-buttons))
;;;
;;;
;;;
(define-visco-command (com-create-inner-enclosure :name "Create Inner Enclosure")
((obj `(and gui-object
(satisfies first-arg-ok-p))))
(register-undo-information nil)
(multiple-value-bind (res he)
(execute
(register-constructor-history-entry
""
`(let ((res (apply-create-inner-enclosure (find-named-visco-object ,(name obj))
,*opaque-enclosures-p*
:pattern-id ,(get-next-pattern-id)
:ink-rgb-list (quote ,(calculate-color-for-inner-enclosure obj)))))
(when (and res (not (eq res 'not-applicable)))
res))
(list obj)))
(if res
(let ((descr (format nil "Create ~A" res)))
(setf (operation-descr he) descr)
(set-undo-operation-description-to descr)
(set-current-focus-to-newest-history-entry))
(progn (beep) (delete-history-entry he)
(pop-undo-stack))))
(refresh))
(defmethod first-argument-acceptable-p ((op (eql 'com-create-inner-enclosure)) (obj gui-object))
(create-inner-enclosure-applicable-p obj *opaque-enclosures-p*))
(defmethod command-enabled ((command (eql 'com-create-inner-enclosure)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p command))
(defmethod command-enabled ((command (eql 'com-create-inner-enclosure*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p 'com-create-inner-enclosure))
(define-visco-command (com-create-inner-enclosure* :name "Create Inner Enclosure")
nil
(let ((*operator-mode* *button-create-inner-enclosure*))
(com-create-inner-enclosure (accept-first-command-arg)))
(redraw-buttons))
;;;
;;;
;;;
(define-visco-command (com-create-outer-enclosure :name "Create Outer Enclosure")
((obj `(and gui-object
(satisfies first-arg-ok-p))))
(register-undo-information nil)
(multiple-value-bind (res he)
(execute
(register-constructor-history-entry
""
`(let ((res (apply-create-outer-enclosure (find-named-visco-object ,(name obj))
,*opaque-enclosures-p*
:ink-rgb-list (quote ,(calculate-color-for-outer-enclosure obj))
:pattern-id ,(get-next-pattern-id))))
(when (and res (not (eq res 'not-applicable)))
res))
(list obj)))
(if res
(let ((descr (format nil "Create ~A" res)))
(setf (operation-descr he) descr)
(set-undo-operation-description-to descr)
(set-current-focus-to-newest-history-entry))
(progn (beep)
(delete-history-entry he)
(pop-undo-stack))))
(refresh))
(defmethod first-argument-acceptable-p ((op (eql 'com-create-outer-enclosure)) (obj gui-object))
(create-outer-enclosure-applicable-p obj *opaque-enclosures-p*))
(defmethod command-enabled ((command (eql 'com-create-outer-enclosure)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p command))
(defmethod command-enabled ((command (eql 'com-create-outer-enclosure*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p 'com-create-outer-enclosure))
(define-visco-command (com-create-outer-enclosure* :name "Create Outer Enclosure")
nil
(let ((*operator-mode* *button-create-outer-enclosure*))
(com-create-outer-enclosure (accept-first-command-arg)))
(redraw-buttons))
;;;
;;;
;;;
(define-visco-command (com-create-epsilon-enclosure :name "Create Epsilon Enclosure")
((obj `(and gui-object
(satisfies first-arg-ok-p))))
(with-visco-frame (visco)
(with-visco-buttons-frame (buttons)
(let ((stream (get-frame-pane visco 'display)))
(register-undo-information nil)
(let ((res (apply-create-epsilon-enclosure obj 0 *opaque-enclosures-p*)))
(if (and res (not (eq res 'not-applicable)))
(labels ((draw-it ()
(draw res stream :handling-active t)))
(draw-it)
(if (tracking-pointer (stream)
(:pointer-motion (x y)
(multiple-value-bind (x y)
(xy-to-grid x y)
(draw-it)
(let ((radius
(distance-between-xy x y obj)))
(when (create-epsilon-enclosure-applicable-p obj radius *opaque-enclosures-p*)
(setf (radius res) radius)))
(draw-it)
(redisplay-frame-pane buttons 'option-buttons)))
(:keyboard (character)
(when (and (characterp character)
(char-equal character #\q))
(return nil)))
(:pointer-button-press (event)
(if (= (pointer-event-button event)
+pointer-right-button+)
(return nil)
(return obj))))
(progn
(delete-object res)
(multiple-value-bind (res he)
(execute
(register-constructor-history-entry
""
`(let ((res (apply-create-epsilon-enclosure
(find-named-visco-object ,(name obj))
,(radius res)
,*opaque-enclosures-p*
:ink-rgb-list (quote ,(calculate-color-for-epsilon-enclosure obj))
:pattern-id ,(pattern-id res))))
(when (and res (not (eq res 'not-applicable)))
res))
(list obj)))
(let ((descr (format nil "Create ~A" res)))
(setf (operation-descr he) descr)
(set-undo-operation-description-to descr)
(set-current-focus-to-newest-history-entry))))
(progn
(delete-object res)
(pop (undo-stack visco)))))
(pop-undo-stack))))))
(refresh))
(defmethod first-argument-acceptable-p ((op (eql 'com-create-epsilon-enclosure)) (obj gui-object))
(create-epsilon-enclosure-applicable-p obj 0 *opaque-enclosures-p*))
(defmethod command-enabled ((command (eql 'com-create-epsilon-enclosure)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p command))
(defmethod command-enabled ((command (eql 'com-create-epsilon-enclosure*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p 'com-create-epsilon-enclosure))
(define-visco-command (com-create-epsilon-enclosure* :name "Create Epsilon Enclosure")
nil
(let ((*operator-mode* *button-create-epsilon-enclosure*))
(com-create-epsilon-enclosure (accept-first-command-arg)))
(redraw-buttons))
;;;
;;;
;;;
(define-visco-command (com-create-inverse-drawn-enclosure :name "Create Inverse Constant Enclosure")
((obj `(and gui-object
(satisfies first-arg-ok-p))))
(register-undo-information nil)
(multiple-value-bind (res he)
(execute
(register-constructor-history-entry
""
`(let ((res (apply-create-drawn-enclosure
(find-named-visco-object ,(name (on-transparency obj)))
(list ,@(segments obj))
,(opaque-p obj)
:ink-rgb-list (quote ,(calculate-color-for-drawn-enclosure obj))
:negated-p ,(not (negated-p obj)))))
(when (and res (not (eq res 'not-applicable)))
res))
nil))
(if res
(let ((descr (format nil "Create Inverse ~A Of ~A" res obj)))
(setf (operation-descr he) descr)
(set-undo-operation-description-to descr)
(set-current-focus-to he))
(progn (beep) (delete-history-entry he)
(pop-undo-stack))))
(refresh))
(defmethod first-argument-acceptable-p ((op (eql 'com-create-inverse-drawn-enclosure)) (obj gui-object))
(typep obj 'gui-drawn-enclosure))
(defmethod command-enabled ((command (eql 'com-create-inverse-drawn-enclosure)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p command))
(defmethod command-enabled ((command (eql 'com-create-inverse-drawn-enclosure*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p 'com-create-inverse-drawn-enclosure))
(define-visco-command (com-create-inverse-drawn-enclosure* :name "Create Inverse Constant Enclosure")
nil
(let ((*operator-mode* *button-create-inverse-drawn-enclosure*))
(com-create-inverse-drawn-enclosure (accept-first-command-arg)))
(redraw-buttons))
;;;
;;;
;;;
(define-visco-command (com-set-semantics :name "Set Semantics")
((obj `(and gui-object
(satisfies first-arg-ok-p))))
(with-visco-frame (visco)
(let* ((stream (get-frame-pane visco 'display))
(semantics
(accepting-values (stream :own-window t
:label (format nil "Semantics Of ~A" obj))
(accept `((subset-completion
,*os*
:value-key ,#'second
:test ,#'equal)
:name-key ,#'(lambda (item)
(format nil "~A ~A ~A" (first item) (second item) (third item))))
:prompt "Select A Subset Of"
:stream stream
:view `(list-pane-view :value ,(semantics obj)
:visible-items 20))))
(descr
(if semantics
(format nil "Set Semantics Of ~A" obj)
(format nil "Delete Semantics Of ~A" obj))))
(register-undo-information descr)
(multiple-value-bind (res he)
(execute
(register-history-entry
descr
(if semantics
`(let ((res (apply-set-semantics (find-named-visco-object ,(name obj))
',semantics)))
(when (and res (not (eq res 'not-applicable)))
res))
`(let ((res (apply-delete-semantics (find-named-visco-object ,(name obj)))))
(when (and res (not (eq res 'not-applicable)))
(reinitialize (semantics-label res)))))
(list obj)))
(unless res
(beep)
(delete-history-entry he)
(pop-undo-stack)))))
(refresh))
(defmethod first-argument-acceptable-p ((op (eql 'com-set-semantics)) (obj gui-object))
(and (typep obj 'gui-query-object)
(matches-with-database-object-p obj)))
(defmethod command-enabled ((command (eql 'com-set-semantics)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p command))
(defmethod command-enabled ((command (eql 'com-set-semantics*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p 'com-set-semantics))
(define-visco-command (com-set-semantics* :name "Set Semantics")
nil
(let ((*operator-mode* *button-set-semantics*))
(com-set-semantics (accept-first-command-arg)))
(redraw-buttons))
;;;
;;;
;;;
(define-visco-command (com-set-at-most-constraint :name "Set At Most Constraint")
((obj `(and gui-object
(satisfies first-arg-ok-p))))
(with-visco-frame (visco)
(let* ((stream (get-frame-pane visco 'display))
(at-most
(accepting-values (stream :own-window t
:label (format nil "Set At Most Constraint Of ~A" obj))
(accept 'integer
:prompt "Enter At Most Constraint"
:stream stream
:view 'text-field-view)))
(descr
(if at-most
(format nil "Set At Most Constraint Of ~A To ~A" obj at-most)
(format nil "Delete At Most Constraint Of ~A" obj))))
(register-undo-information descr)
(multiple-value-bind (res he)
(execute
(register-history-entry
descr
(if at-most
`(let ((res (apply-set-at-most-constraint (find-named-visco-object ,(name obj))
,at-most)))
(when (and res (not (eq res 'not-applicable)))
res))
`(let ((res (apply-delete-at-most-constraint
(find-named-visco-object ,(name obj)))))
(when (and res (not (eq res 'not-applicable)))
(reinitialize (at-most-label res)))))
(list obj)))
(unless res
(beep)
(delete-history-entry he)
(pop-undo-stack)))))
(refresh))
(defmethod first-argument-acceptable-p ((op (eql 'com-set-at-most-constraint)) (obj gui-object))
(and (or (typep obj 'gui-rubberband)
(and (typep obj 'gui-chain-or-polygon)
(some #'(lambda (segment)
(and (typep segment 'rubberband)
(not (typep segment 'atomic-rubberband))))
(segments obj))))))
(defmethod command-enabled ((command (eql 'com-set-at-most-constraint)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p command))
(defmethod command-enabled ((command (eql 'com-set-at-most-constraint*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p 'com-set-at-most-constraint))
(define-visco-command (com-set-at-most-constraint* :name "Set At Most Constraint")
nil
(let ((*operator-mode* *button-set-at-most-constraint*))
(com-set-at-most-constraint (accept-first-command-arg)))
(redraw-buttons))
;;;
;;;
;;;
(define-visco-command (com-set-orientation-constraint :name "Set Orientation Constraint")
((obj `(and gui-object
(satisfies first-arg-ok-p))))
(let ((descr
(format nil "Set Orientation Constraint Of ~A" obj)))
(register-undo-information descr)
(multiple-value-bind (res he)
(execute
(register-history-entry
descr
`(let ((res (apply-set-orientation-constraint (find-named-visco-object ,(name obj))
'(0))))
(when (and res (not (eq res 'not-applicable)))
res))
(list obj)))
(unless res
(beep)
(delete-history-entry he)
(pop-undo-stack))))
(refresh))
(defmethod first-argument-acceptable-p ((op (eql 'com-set-orientation-constraint)) (obj gui-object))
(and (set-orientation-constraint-applicable-p obj (list 0))
(not (orientation-constraint obj))))
(defmethod command-enabled ((command (eql 'com-set-orientation-constraint)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p command))
(defmethod command-enabled ((command (eql 'com-set-orientation-constraint*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p 'com-set-orientation-constraint))
(define-visco-command (com-set-orientation-constraint* :name "Set Orientation Constraint")
nil
(let ((*operator-mode* *button-set-orientation-constraint*))
(com-set-orientation-constraint (accept-first-command-arg)))
(redraw-buttons))
;;;
;;;
;;;
(defmethod first-argument-acceptable-p ((op (eql 'com-set-orientation-constraint-mark)) (obj gui-visco-object))
(and (typep obj 'orientation-constraint-mixin)
(orientation-constraint obj)))
(defmethod first-argument-acceptable-p ((op (eql 'com-set-orientation-constraint-mark)) (obj gui-orientation-arrow))
(first-argument-acceptable-p op (object obj)))
(defmethod command-enabled ((command (eql 'com-set-orientation-constraint-mark)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p command))
(defmethod command-enabled ((command (eql 'com-set-orientation-constraint-mark*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p 'com-set-orientation-constraint-mark))
(define-visco-command (com-set-orientation-constraint-mark* :name "Set Orientation Constraint Mark")
nil
(let ((*operator-mode* *button-create-orientation-constraint-mark*))
(com-set-orientation-constraint-mark (accept-first-command-arg)))
(redraw-buttons))
(define-visco-command (com-set-orientation-constraint-mark :name "Set Orientation Constraint Mark")
((object `(and gui-object
(satisfies first-arg-ok-p))))
(create-orientation-constraint-mark object))
(defmethod create-orientation-constraint-mark ((object gui-orientation-arrow))
(create-orientation-constraint-mark (object object)))
(defmethod create-orientation-constraint-mark ((object gui-visco-object))
(with-visco-frame (visco)
(let* ((stream (get-frame-pane visco 'display))
(constraint (orientation-constraint object))
(alpha (if (typep object 'geom-line)
(global-orientation object) 0))
(old-r (r (orientation-arrow object))))
(flet ((exit-code ()
(setf (r (orientation-arrow object)) old-r)
(apply-set-orientation-constraint object constraint)
(pop-undo-stack)))
(register-undo-information
(format nil "Set Mark Of Orientation Constraint Of ~A" object))
(with-output-recording-options (stream :draw t :record nil)
(prepare-to-move)
(tracking-pointer (stream)
(:pointer-motion (x y)
(multiple-value-bind (x y)
(xy-to-grid x y)
(draw (orientation-arrow object) stream :handling-active t)
(multiple-value-bind (xc yc)
(get-origin-for (orientation-arrow object))
(multiple-value-bind (r alpha2)
(distance-and-orientation* xc yc
x y)
(apply-set-orientation-constraint object
(cons (normalize
(- alpha2 alpha
(alpha-off
(orientation-arrow object))))
constraint))
(setf (r (orientation-arrow object)) r))
(draw (orientation-arrow object) stream :handling-active t))))
(:keyboard (character)
(when (and (characterp character)
(char-equal character #\q))
(exit-code)
(return)))
(:pointer-button-press (event)
(if (= (pointer-event-button event)
+pointer-right-button+)
(exit-code)
(multiple-value-bind (res he)
(execute
(register-history-entry
""
`(let ((obj (find-named-visco-object ,(name object))))
(when obj
(let ((arrow (orientation-arrow obj))
(res
(apply-set-orientation-constraint obj
',(orientation-constraint object))))
(when (and res (not (eq res 'not-applicable)))
(setf (r-off arrow) ,(r-off (orientation-arrow object)))
(setf (rho-off arrow) ,(rho-off (orientation-arrow object)))
(setf (r arrow) ,(r (orientation-arrow object)))
(setf (alpha-off arrow)
,(alpha-off (orientation-arrow object)))
res))))
(list object)))
(unless res
(beep)
(delete-history-entry he)
(pop-undo-stack))))
(return)))))))
(refresh))
;;;
;;;
;;;
(defmethod first-argument-acceptable-p ((op (eql 'com-set-orientation-constraint-intervall))
(obj gui-visco-object))
(and (typep obj 'orientation-constraint-mixin)
(orientation-constraint obj)))
(defmethod first-argument-acceptable-p ((op (eql 'com-set-orientation-constraint-intervall))
(obj gui-orientation-arrow))
(first-argument-acceptable-p op (object obj)))
(defmethod command-enabled ((command (eql 'com-set-orientation-constraint-intervall)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p command))
(defmethod command-enabled ((command (eql 'com-set-orientation-constraint-intervall*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p 'com-set-orientation-constraint-intervall))
(define-visco-command (com-set-orientation-constraint-intervall* :name "Set Orientation Constraint Intervall")
nil
(let ((*operator-mode* *button-create-orientation-constraint-intervall*))
(com-set-orientation-constraint-intervall (accept-first-command-arg)))
(redraw-buttons))
(define-visco-command (com-set-orientation-constraint-intervall :name "Set Orientation Constraint Intervall")
((object `(and gui-object
(satisfies first-arg-ok-p))))
(create-orientation-constraint-intervall object))
(defmethod create-orientation-constraint-intervall ((object gui-orientation-arrow))
(create-orientation-constraint-intervall (object object)))
(defmethod create-orientation-constraint-intervall ((object gui-query-object))
(with-visco-frame (visco)
(let* ((stream (get-frame-pane visco 'display))
(constraint (orientation-constraint object))
(alpha (if (typep object 'geom-line)
(global-orientation object) 0))
(old-r (r (orientation-arrow object)))
(first nil)
(angle nil)
(focus (current-focus visco)))
(flet ((exit-code ()
(setf (r (orientation-arrow object)) old-r)
(apply-set-orientation-constraint object constraint)
(pop-undo-stack)
(set-current-focus-to (find-named-history-entry (name focus)))
(return-from create-orientation-constraint-intervall)))
(register-undo-information
(format nil "Set Intervall Of Orientation Constraint Of ~A" object))
(with-output-recording-options (stream :draw t :record nil)
(prepare-to-move)
(tracking-pointer (stream)
(:pointer-motion (x y)
(multiple-value-bind (x y)
(xy-to-grid x y)
(draw (orientation-arrow object) stream :handling-active t)
(multiple-value-bind (xc yc)
(get-origin-for (orientation-arrow object))
(multiple-value-bind (r alpha2)
(distance-and-orientation* xc yc
x y)
(setf angle (normalize
(- alpha2 alpha
(alpha-off
(orientation-arrow object)))))
(apply-set-orientation-constraint object
(if first
(cons
(list angle first)
constraint)
(cons angle
constraint)))
(setf (r (orientation-arrow object)) r)))
(draw (orientation-arrow object) stream :handling-active t)))
(:keyboard (character)
(when (and (characterp character)
(char-equal character #\q))
(exit-code)))
(:pointer-button-press (event)
(if (= (pointer-event-button event)
+pointer-right-button+)
(exit-code)
(if first
(multiple-value-bind (res he)
(execute
(register-history-entry
""
`(let ((obj (find-named-visco-object ,(name object))))
(when obj
(let ((arrow (orientation-arrow obj))
(res
(apply-set-orientation-constraint obj
',(orientation-constraint object))))
(when (and res (not (eq res 'not-applicable)))
(setf (r-off arrow) ,(r-off (orientation-arrow object)))
(setf (rho-off arrow) ,(rho-off (orientation-arrow object)))
(setf (r arrow) ,(r (orientation-arrow object)))
(setf (alpha-off arrow)
,(alpha-off (orientation-arrow object)))
res))))
(list object)))
(unless res
(beep)
(delete-history-entry he)
(pop-undo-stack))
(return))
(setf first angle)))))))))
(refresh))
;;;
;;;
;;;
(defmethod gui-set-relative-orientation-constraint ((obj1 gui-atomic-rubberband) (obj2 gui-atomic-rubberband))
(with-visco-frame (visco)
(let ((stream (get-frame-pane visco 'display)))
(multiple-value-bind (ix iy)
(calculate-intersection-point obj1 obj2)
(let ((circle
(make-instance 'gui-relative-orientation-circle
:dont-initialize t
:object1 obj1
:object2 obj2
:allowed-derivation 0))
(alpha 0)
(r 30))
(let ((descr
(format nil "Set Relative Orientation Constraint Between ~A And ~A" obj1 obj2)))
(with-output-recording-options (stream :draw t :record nil)
(prepare-to-move)
(draw circle stream :handling-active t)
(when
(tracking-pointer (stream)
(:pointer-motion (x y)
(multiple-value-bind (x y)
(xy-to-grid x y)
(draw circle stream :handling-active t)
(multiple-value-bind (r2 alpha2)
(distance-and-orientation* ix iy
x y)
(setf alpha alpha2)
(setf r r2)
(setf (r circle) r)
(setf (allowed-derivation circle) alpha))
(draw circle stream :handling-active t)))
(:keyboard (character)
(when (and (characterp character)
(char-equal character #\q))
(return nil)))
(:pointer-button-press (event)
(if (= (pointer-event-button event)
+pointer-right-button+)
(return nil)
(return t))))
(register-undo-information descr)
(multiple-value-bind (res he)
(execute
(register-history-entry
descr
`(let* ((obj1 (find-named-visco-object ,(max (name obj1)
(name obj2))))
(obj2 (find-named-visco-object ,(min (name obj1)
(name obj2))))
(res (apply-set-relative-orientation-constraint
obj1 obj2 ,alpha)))
(when (and res (not (eq res 'not-applicable)))
(make-instance 'gui-relative-orientation-circle
:object1 obj1
:object2 obj2
:r ,r
:allowed-derivation ,alpha)
res))
(list obj1 obj2)))
(unless res
(beep)
(delete-history-entry he)
(pop-undo-stack))))))))))
(refresh))
(define-visco-command (com-set-relative-orientation-constraint :name "Set Relative Orientation Constraint")
((obj1 `(and gui-object
(satisfies first-arg-ok))))
(let ((*first-arg* obj1))
(let ((obj2
(accept `(and gui-object
(satisfies second-arg-ok-p))
:prompt " Select Second Argument")))
(gui-set-relative-orientation-constraint obj1 obj2))))
(defmethod first-argument-acceptable-p ((op (eql 'com-set-relative-orientation-constraint)) (obj1 gui-object))
(and (typep obj1 'gui-atomic-rubberband)
(some #'(lambda (obj2)
(second-argument-acceptable-p op
obj1 obj2))
(visco-objects (get-current-query)))))
(defmethod second-argument-acceptable-p ((op (eql 'com-set-relative-orientation-constraint))
(obj1 gui-object)
(obj2 gui-object))
(set-relative-orientation-constraint-applicable-p obj1 obj2 0))
(defmethod command-enabled ((command (eql 'com-set-relative-orientation-constraint)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p command))
(defmethod command-enabled ((command (eql 'com-set-relative-orientation-constraint*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p 'com-set-relative-orientation-constraint))
(define-visco-command (com-set-relative-orientation-constraint* :name "Set Relative Orientation Constraint")
nil
(let ((*operator-mode* *button-create-relative-orientation-constraint*))
(com-set-relative-orientation-constraint (accept-first-command-arg)))
(redraw-buttons))
;;;
;;;
;;;
(define-visco-command (com-set-transparency-properties :name "Set Transparency Properties")
((obj `(and gui-object
(satisfies first-arg-ok-p))))
(let ((descr
(format nil "Set Properties Of ~A" obj)))
(register-undo-information descr)
(with-visco-frame (visco)
(let ((stream (get-frame-pane visco 'display))
(minw (if (sxmin obj)
(write-to-string (* (sxmin obj) (width obj)))
"NIL"))
(maxw (if (sxmax obj)
(write-to-string (* (sxmax obj) (width obj)))
"NIL"))
(minh (if (symin obj)
(write-to-string (* (symin obj) (height obj)))
"NIL"))
(maxh (if (symax obj)
(write-to-string (* (symax obj) (height obj)))
"NIL"))
(proportional (sxsy-constraint obj)))
(loop
(accepting-values (stream :own-window t :label "Set Transparency Properties")
(terpri stream)
(multiple-value-bind (string)
(accept 'string
:stream stream
:query-identifier 'wmin
:prompt "Min Width (or NIL)"
:default minw)
(setf minw string))
(terpri stream)
(multiple-value-bind (string)
(accept 'string
:stream stream
:query-identifier 'wmax
:prompt "Max Width (or NIL)"
:default maxw)
(setf maxw string))
(terpri stream)
(terpri stream)
(multiple-value-bind (string)
(accept 'string
:stream stream
:prompt "Min Height (or NIL)"
:query-identifier 'hmin
:default minh)
(setf minh string))
(terpri stream)
(multiple-value-bind (string)
(accept 'string
:stream stream
:prompt "Max Height (or NIL)"
:query-identifier 'hmax
:default maxh)
(setf maxh string))
(terpri stream)
(terpri stream)
(multiple-value-bind (bool)
(accept 'boolean
:stream stream
:prompt "Proportional"
:default proportional)
(setf proportional bool)))
(when (and (typep (read-from-string minw) '(or number null))
(typep (read-from-string maxw) '(or number null))
(typep (read-from-string minh) '(or number null))
(typep (read-from-string maxh) '(or number null)))
(return)))
(setf minw (read-from-string minw)
maxw (read-from-string maxw)
minh (read-from-string minh)
maxh (read-from-string maxh))
(let ((new-history-entry
(register-history-entry
descr
`(apply-set-transparency-properties
(find-named-visco-object ,(name obj))
,minw ,maxw
,minh ,maxh
,(when proportional 1.0))
(list obj))))
(multiple-value-bind (res he)
(execute new-history-entry)
(unless res
(beep)
(delete-history-entry he)
(pop-undo-stack)))))))
(refresh))
(defmethod first-argument-acceptable-p ((op (eql 'com-set-transparency-properties)) (obj gui-transparency))
t)
(defmethod command-enabled ((command (eql 'com-set-transparency-properties)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p command))
(defmethod command-enabled ((command (eql 'com-set-transparency-properties*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled-p 'com-set-transparency-properties))
(define-visco-command (com-set-transparency-properties* :name "Set Transparency Properties")
nil
(let ((*operator-mode* *button-set-transparency-properties*))
(com-set-transparency-properties (accept-first-command-arg)))
(redraw-buttons))
;;;
;;;
;;;
(define-command-table operator-table
:menu (("Create Centroid (S, Chain, Poly)" :command (com-create-centroid*))
("Create Intersection Point (S x S)" :command (com-create-intersection-point*))
("divide1" :divider nil)
("Create Inverse Constant Enclosure (E)" :command (com-create-inverse-drawn-enclosure*))
("Create Inner Enclosure (Poly)" :command (com-create-inner-enclosure*))
("Create Outer Enclosure (Poly)" :command (com-create-outer-enclosure*))
("Create Epsilon Enclosure (P, S, Chain, Poly)" :command (com-create-epsilon-enclosure*))
("divide3" :divider nil)
("divide4" :divider nil)
("Set Semantics (P, S, Chain, Poly)" :command (com-set-semantics*))
("divide5" :divider nil)
("Set At Most Constraint (R, Chain, Poly)" :command (com-set-at-most-constraint*))
("divide6" :divider nil)
("Set Orientation Constraint (O, B, AR)" :command (com-set-orientation-constraint*))
("Set Orientation Constraint Mark (OC)" :command (com-set-orientation-constraint-mark*))
("Set Orientation Constraint Intervall (OC)" :command (com-set-orientation-constraint-intervall*))
("divide7" :divider nil)
("Set Relative Orientation Constraint ((B/AR) x (B/AR))"
:command (com-set-relative-orientation-constraint*))
("divide8" :divider nil)
("Set Transparency Properties (T)" :command (com-set-transparency-properties*))))
| 37,693 | Common Lisp | .lisp | 944 | 33.041314 | 116 | 0.63946 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 878172f20009f57e5517f4484c92c3cb388b6e6c9ea7ae407a27a7971ce76133 | 11,708 | [
-1
] |
11,709 | control7.lisp | lambdamikel_VISCO/src/GUI/control7.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
(defconstant +current-focus-entry-text-style+
(parse-text-style '(:sans-serif (:bold :italic) :small)))
(defconstant +focus-entry-text-style+
(parse-text-style '(:sans-serif nil :small)))
(defconstant +current-focus-entry-ink+
+red+)
(defconstant +current-transparency-entry-ink+
+blue+)
(defconstant +focus-entry-ink+
+black+)
(define-presentation-method highlight-presentation ((type history-entry) record stream state)
(inverse-highlighter type record stream state))
(defun accept-control-buttons (frame stream)
(let ((line 1))
(labels ((draw-it (op line level focus-p transparency-p)
(with-drawing-options (stream :text-style
(cond (focus-p
+current-focus-entry-text-style+)
(t +focus-entry-text-style+))
:ink
(cond (focus-p
+current-focus-entry-ink+)
(transparency-p
+current-transparency-entry-ink+)
(t +focus-entry-ink+)))
(draw-text* stream
(format nil
"Step ~A: ~A"
line
op)
(* 10 (1- level)) (* line 14)))))
(dolist (entry (history frame))
(when (typep entry 'visually-relevant-history-entry)
(let* ((obj
(and (typep entry 'visually-relevant-history-entry)
(object-to-draw entry)))
(level (typecase (and (typep entry 'constructor-history-entry)
obj)
(gui-transparency 1)
(gui-point (if (primary-p obj) 2
(if (every #'primary-p (part-of obj))
3
4)))
(gui-line (if (primary-p obj)
2
3))
(otherwise 2)))
(focus-p (eq (current-focus frame) entry))
(transparency-p (and (typep obj 'gui-transparency)
(current-transparency-is-transparency-p obj))))
(updating-output (stream :unique-id entry
:cache-value (list level focus-p transparency-p line entry)
:cache-test #'equal)
(with-output-as-presentation
(stream entry 'history-entry)
(draw-it (operation-descr entry)
line
level
focus-p
transparency-p)))
(incf line)))))))
;;;
;;;
;;;
(defun delete-objects (objects)
(dolist (obj objects)
(delete-object obj)))
(defun pop-undo-stack ()
(with-visco-frame (visco)
(prog1
(pop (undo-stack visco))
(generate-name-for-undo-and-redo-command))))
(defun pop-redo-stack ()
(with-visco-frame (visco)
(prog1
(pop (redo-stack visco))
(generate-name-for-undo-and-redo-command))))
(defun get-state (descr)
(with-visco-frame (visco)
(list (copy-list (history visco))
(get-button-state)
(and (current-focus visco)
(name (current-focus visco)))
(and (current-transparency visco)
(name (current-transparency visco)))
descr)))
(defun install-previous-state (state)
(reconstruct-history
(first state))
(install-button-state (second state))
(when (third state)
(set-current-focus-to (find-named-history-entry
(third state))))
(when (fourth state)
(set-current-transparency-to (find-named-visco-object
(fourth state)))))
;;;
;;;
;;;
(defun register-undo-information (descr)
(with-visco-frame (visco)
(push (get-state descr)
(undo-stack visco))
(when descr
(generate-name-for-undo-and-redo-command))))
(defun set-undo-operation-description-to (descr)
(with-visco-frame (visco)
(setf (fifth (first (undo-stack visco)))
descr)
(when descr (generate-name-for-undo-and-redo-command))))
(defun undo ()
(with-visco-frame (visco)
(let ((undo-info
(pop-undo-stack)))
(if undo-info
(progn
(push (get-state (fifth undo-info))
(redo-stack visco))
(install-previous-state undo-info)
(format t "Undoing ~A~%"
(fifth undo-info)))
(progn
(beep)
(format t "No More Undo Information!~%"))))
(generate-name-for-undo-and-redo-command)))
(defun redo ()
(let ((redo-info
(pop-redo-stack)))
(if redo-info
(progn
(register-undo-information
(fifth redo-info))
(install-previous-state redo-info)
(format t "Redoing ~A~%"
(fifth redo-info)))
(progn
(beep)
(format t "No More Redo Information!~%"))))
(generate-name-for-undo-and-redo-command))
;;;
;;;
;;;
(defun reconstruct-history (history &key (give-up-after-first-try nil))
(with-visco-frame (visco)
(let ((history (copy-list history))
(old-history (copy-list (history visco)))
(new-objects nil)
(old-objects
(copy-list (visco-objects (get-current-query))))
(focus (current-focus visco)))
(delete-objects old-objects)
(prog1
(dolist (history-entry history t)
#| (princ (source history-entry)) (terpri) |#
(let ((res (execute history-entry)))
(if res
(push res new-objects)
(progn
(unless give-up-after-first-try
(setf (visco-objects (current-query visco))
old-objects)
(setf (history visco) old-history)
(setf history old-history)
(reconstruct-query :give-up-after-first-try t)
(when focus
(set-current-focus-to focus)))
(beep)
(format t "~%*** ERROR ***~%Not Reconstructable!~%")
(return-from reconstruct-history nil)))))
(setf (history visco) history)))))
(defun reconstruct-query (&key (give-up-after-first-try nil))
(with-visco-frame (visco)
(reconstruct-history (history visco)
:give-up-after-first-try
give-up-after-first-try)))
(defmethod substitute-history-entry-with ((old history-entry) (new history-entry))
(with-visco-frame (visco)
(setf (history visco)
(nsubstitute new
old
(history visco))
(name new)
(name old))))
(defmethod change-query-from-to ((old history-entry)
(new history-entry))
(with-visco-frame (visco)
(delete-history-entry new)
(let ((history (copy-list (history visco))))
(setf (name new) (name old))
(setf history
(nsubstitute new old history))
(reconstruct-history history))))
(defmethod change-query-from-to ((old list)
(new list))
(with-visco-frame (visco)
(delete-history-entries new)
(let ((history (copy-list (history visco))))
(mapc #'(lambda (ohe nhe)
(setf (name nhe) (name ohe)))
old new)
(mapc #'(lambda (ohe nhe)
(setf history
(nsubstitute nhe ohe history)))
old new)
(reconstruct-history history))))
;;;
;;;
;;;
(defun generate-name-for-undo-and-redo-command ()
(with-visco-frame (visco)
(remove-command-from-command-table
'com-undo* 'control-table)
(remove-command-from-command-table
'com-redo* 'control-table)
(let* ((undo (first (undo-stack visco)))
(redo (first (redo-stack visco)))
(undo-name
(if undo (format nil "Undo ~A" (fifth undo))
"Undo"))
(redo-name
(if redo (format nil "Redo ~A" (fifth redo))
"Redo")))
(add-command-to-command-table 'com-undo*
'control-table
:menu (list undo-name
:after :start))
(add-command-to-command-table 'com-redo*
'control-table
:menu (list redo-name
:after undo-name)))))
(define-visco-command (com-undo* :name "Undo")
nil
(undo))
(defmethod command-enabled ((obj (eql 'com-undo*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(with-visco-frame (visco)
(and visco
(undo-stack visco))))
;;;
;;;
;;;
(define-visco-command (com-redo* :name "Redo")
nil
(redo))
(defmethod command-enabled ((obj (eql 'com-redo*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(with-visco-frame (visco)
(and visco
(redo-stack visco))))
;;;
;;;
;;;
(define-visco-command (com-set-current-focus-to :name nil)
((object 'history-entry))
(set-current-focus-to object)
(refresh))
(define-visco-command (com-set-current-focus-to* :name "Set Current Focus To")
()
(let ((obj (accept '(and gui-visco-object
(satisfies history-entry))
:prompt "Select Current Focus Object")))
(com-set-current-focus-to (history-entry obj))))
(defmethod command-enabled ((obj (eql 'com-set-current-focus-to*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(command-enabled 'com-set-current-focus-to frame))
(define-presentation-to-command-translator set-current-focus-to
(gui-visco-object com-set-current-focus-to visco
:gesture :set-focus
:documentation ((object stream)
(format stream "Set Current Focus To ~A" object))
:tester ((object) (history-entry object)))
(object)
(list (history-entry object)))
(define-presentation-to-command-translator set-current-focus-to2
(history-entry com-set-current-focus-to visco
:documentation ((object stream)
(format stream "Set Current Focus To ~A" object))
:gesture :select)
(object)
(list object))
;;;
;;;
;;;
(define-visco-command (com-set-current-transparency-to :name nil)
((object 'gui-transparency))
(set-current-transparency-to object))
(define-visco-command (com-set-current-transparency-to* :name "Set Current Transparency To")
()
(let ((obj (accept 'gui-transparency
:prompt "Select Current Transparency")))
(set-current-transparency-to obj)))
(defmethod command-enabled ((obj (eql 'com-set-current-transparency-to*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(with-visco-frame (visco)
(and visco
(some #'(lambda (obj)
(typep obj 'gui-transparency))
(visco-objects (current-query visco))))))
(define-presentation-to-command-translator set-current-transparency-to
(gui-transparency com-set-current-transparency-to visco
:gesture :set-transparency
:documentation ((object stream)
(format stream "Set Current Transparency To ~A" object)))
(object)
(list object))
(define-presentation-to-command-translator set-current-transparency-to2
(constructor-history-entry com-set-current-transparency-to visco
:gesture :set-transparency
:documentation ((object stream)
(format stream "Set Current Transparency To ~A"
(object-to-draw object)))
:tester ((object) (typep (object-to-draw object) 'gui-transparency)))
(object)
(list (object-to-draw object)))
;;;
;;;
;;;
(defmethod delete-object-applicable-p ((obj gui-object))
nil)
(defmethod delete-object-applicable-p ((obj gui-visco-object))
(=> (typep obj 'geom-thing) (primary-p obj)))
(defmethod delete-object-applicable-p ((obj gui-orientation-arrow))
t)
(defmethod delete-object-applicable-p ((obj gui-semantics-label))
t)
(defmethod delete-object-applicable-p ((obj gui-at-most-label))
t)
(defmethod delete-object-applicable-p ((obj gui-relative-orientation-circle))
t)
;;;
;;;
;;;
(define-visco-command (com-delete :name nil)
((object 'gui-object) (delete-component-objects-p 'boolean))
(gui-delete-object object delete-component-objects-p))
(defmethod gui-delete-object ((object gui-visco-object) delete-component-objects-p)
(with-visco-frame (visco)
(register-undo-information
(format nil "Delete ~A" object))
(let ((old-history (copy-list (history visco)))
(focus (current-focus visco)))
(delete-object object :delete-component-objects-p delete-component-objects-p)
(if (reconstruct-history (history visco) :give-up-after-first-try t)
(progn
(set-object-modes)
(set-current-focus-to-newest-history-entry)
(when (typep object 'gui-transparency)
(set-current-transparency-to-newest-transparency)))
(progn
(pop-undo-stack)
(reconstruct-history old-history)
(set-current-focus-to focus)))))
(refresh))
(defmethod command-enabled ((obj (eql 'com-delete*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(with-visco-frame (visco)
(and visco
(some #'(lambda (obj)
(delete-object-applicable-p obj))
(visco-objects (current-query visco))))))
(define-visco-command (com-delete* :name "Delete Object")
()
(let ((obj (accept '(and gui-object
(satisfies delete-object-applicable-p))
:prompt "Select Object To Delete")))
(com-delete obj t)))
(define-presentation-to-command-translator delete
(gui-object com-delete visco
:gesture :delete
:priority 1
:documentation ((object stream)
(format stream "Delete ~A" object))
:tester ((object)
(delete-object-applicable-p object))
:maintain-history nil
:echo nil)
(object)
(list object t))
;;;
;;;
;;;
(defmethod gui-delete-object ((object gui-orientation-arrow) delete-component-objects-p)
(declare (ignore delete-component-objects-p))
(register-undo-information
(format nil "Delete ~A" object))
(execute
(register-history-entry
""
`(let ((res (apply-delete-orientation-constraint
(find-named-visco-object ,(name (object object))))))
(when (and res (not (eq res 'not-applicable)))
(reinitialize (orientation-arrow res))
res))
(list (object object))))
(refresh))
(defmethod gui-delete-object ((object gui-semantics-label) delete-component-objects-p)
(declare (ignore delete-component-objects-p))
(register-undo-information
(format nil "Delete ~A" object))
(execute
(register-history-entry
""
`(let ((res (apply-delete-semantics
(find-named-visco-object ,(name (object object))))))
(when (and res (not (eq res 'not-applicable)))
(reinitialize (semantics-label res))
res))
(list (object object))))
(refresh))
(defmethod gui-delete-object ((object gui-at-most-label) delete-component-objects-p)
(declare (ignore delete-component-objects-p))
(register-undo-information
(format nil "Delete ~A" object))
(execute
(register-history-entry
""
`(let ((res (apply-delete-at-most-constraint
(find-named-visco-object ,(name (object object))))))
(when (and res (not (eq res 'not-applicable)))
(reinitialize (at-most-label res))
res))
(list (object object))))
(refresh))
(defmethod gui-delete-object ((object gui-relative-orientation-circle) delete-component-objects-p)
(declare (ignore delete-component-objects-p))
(register-undo-information
(format nil "Delete ~A" object))
(execute
(register-history-entry
""
`(let* ((obj1 (find-named-visco-object ,(max (name (object1 object))
(name (object2 object)))))
(obj2 (find-named-visco-object ,(min (name (object1 object))
(name (object2 object)))))
(res (apply-delete-relative-orientation-constraint
obj1 obj2)))
(when (and res (not (eq res 'not-applicable)))
(dolist (circle (relative-orientation-circles obj1))
(when (or (and (eq (object1 circle) obj1)
(eq (object2 circle) obj2))
(and (eq (object2 circle) obj1)
(eq (object1 circle) obj2)))
(delete-object circle)))
res))
(list (object1 object) (object2 object))))
(refresh))
;;;
;;;
;;;
(defun delete-history-entry-applicable-p (he)
(when (typep he '(or visually-relevant-history-entry constructor-history-entry))
(let ((obj (object-to-draw he)))
(and (typep obj 'visco-object)
(=> (typep obj 'geom-thing) (primary-p obj))
(=> (typep obj 'transparency) (not (transparency-query-objects-and-enclosures obj)))
(=> (typep obj 'possible-operator-argument-mixin)
(not (arg-of-operators obj)))))))
(define-visco-command (com-delete-history-entry :name nil)
((object 'history-entry))
(com-delete (object-to-draw object) nil)
(set-undo-operation-description-to
(format nil "Delete History Entry ~A" object)))
(defmethod command-enabled ((obj (eql 'com-delete-history-entry*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(with-visco-frame (visco)
(and visco
(some #'(lambda (obj)
(delete-history-entry-applicable-p obj))
(history visco)))))
(define-visco-command (com-delete-history-entry* :name "Delete History Entry")
()
(let ((obj (accept '(and (or visually-relevant-history-entry
constructor-history-entry)
(satisfies delete-history-entry-applicable-p))
:prompt "Select History Entry To Delete")))
(com-delete-history-entry obj)))
(define-presentation-to-command-translator delete-history-entry
(history-entry com-delete-history-entry
visco
:gesture :delete
:maintain-history nil
:documentation ((object stream)
(format stream "Delete ~A" object))
:tester ((object)
(delete-history-entry-applicable-p object))
:echo nil)
(object)
(list object))
;;;
;;;
;;;
(define-visco-command (com-inactivate-object :name nil)
((object 'gui-visco-object))
(setf (inactive object) t)
(refresh))
(defun not-inactivated-p (obj)
(not (inactive obj)))
(define-visco-command (com-inactivate-object* :name "Inactivate Object")
()
(let ((obj (accept '(and gui-visco-object
(satisfies not-inactivated-p))
:prompt "Select Object To Inactivate")))
(com-inactivate-object obj)))
(defmethod command-enabled ((obj (eql 'com-inactivate-object*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(some #'(lambda (obj)
(not (inactive obj)))
(visco-objects (current-query frame))))
#|
(define-presentation-to-command-translator inactivate-object
(gui-visco-object com-inactivate-object visco
:gesture :inactivate)
(object)
(list object))
|#
;;;
;;;
;;;
(defun inactivated-p (obj)
(inactive obj))
(define-visco-command (com-reactivate-object* :name "Reactivate Object")
()
(with-visco-frame (visco)
(setf *ignore-inactive-flag* t)
(redisplay-frame-pane visco 'display :force-p t)
(setf *ignore-inactive-flag* nil)
(let ((obj (accept '(and gui-visco-object
(satisfies inactivated-p))
:prompt "Select Inactivated Object To Reactivate")))
(setf (inactive obj) nil)
(refresh))))
(defmethod command-enabled ((obj (eql 'com-reactivate-object*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(some #'(lambda (obj)
(inactive obj))
(visco-objects (current-query frame))))
;;;
;;;
;;;
(define-visco-command (com-recreate :name "Recreate")
((obj 'gui-query-object-or-enclosure))
(with-visco-frame (visco)
(register-undo-information
(format nil "Recreate ~A" obj))
(let ((focus (current-focus visco))
(new-history-entry
(etypecase obj
(gui-drawn-enclosure (get-history-entry-for
obj
:pointlist (mapcan #'(lambda (p)
(list (x p) (y p)))
(point-list obj))
:negated-p (negated-p obj)
:name (name obj)
:description (operation-descr (history-entry obj))
:transparency (on-transparency obj)
:opaque-p *opaque-enclosures-p*
:pattern-id (pattern-id obj)))
(gui-point (get-history-entry-for
(or *point-mode* obj)
:name (name obj)
:description (operation-descr (history-entry obj))
:status (or *point-status* (status obj))
:transparency (on-transparency obj)
:x (x obj)
:y (y obj)))
(gui-line (get-history-entry-for
(or *segment-mode* obj)
:name (name obj)
:description (operation-descr (history-entry obj))
:status (or *segment-status* (status obj))
:p1 (p1 obj)
:p2 (p2 obj)
:transparency (on-transparency obj)))
(gui-chain-or-polygon (get-history-entry-for
obj
:name (name obj)
:description (operation-descr (history-entry obj))
:status *chain-or-polygon-status*
:segments (segments obj)
:transparency (on-transparency obj))))))
(if (change-query-from-to (history-entry obj)
new-history-entry)
(set-current-focus-to (find-named-history-entry (name focus)))
(pop-undo-stack)))
(refresh)))
(defun recreateable-object-p (obj)
(and (typep obj 'gui-query-object-or-enclosure)
(etypecase obj
(gui-enclosure t)
(gui-point (and (or *point-mode* *point-status*)
(not (and (typep obj 'possible-operator-result-mixin)
(res-of-operators obj)))))
(gui-line (or *segment-mode* *segment-status*))
(gui-chain-or-polygon *chain-or-polygon-status*))))
(defmethod command-enabled ((command (eql 'com-recreate*)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(and (get-current-query)
(some #'recreateable-object-p (visco-objects (get-current-query)))))
(define-visco-command (com-recreate* :name "Recreate")
nil
(let ((obj (accept '(and gui-visco-object
(satisfies recreateable-object-p))
:prompt "Select Object To Recreate")))
(com-recreate obj)))
;;;
;;;
;;;
(define-command-table control-table
:menu (("Undo" :command (com-undo*))
("Redo" :command (com-redo*))
("divide1" :divider nil)
("Move Object (Shift Left)" :command (com-move*))
("Recreate Object" :command (com-recreate*))
("divide2" :divider nil)
("Inactivate Object" :command (com-inactivate-object*))
("Reactivate Object" :command (com-reactivate-object*))
("divide3" :divider nil)
("Set Current Focus To Object (Shift Middle)" :command (com-set-current-focus-to*))
("Set Current Transparency To Transparency (Control Middle)" :command (com-set-current-transparency-to*))
("divide4" :divider nil)
("Delete Object (Middle)" :command (com-delete*))
("Delete History Entry (Middle)" :command (com-delete-history-entry*))))
| 21,848 | Common Lisp | .lisp | 634 | 29.195584 | 109 | 0.656162 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 1958227970dc273edca01b255cd2c270054565445e8f2c9f459621675e9fa9a6 | 11,709 | [
-1
] |
11,710 | draw15.lisp | lambdamikel_VISCO/src/GUI/draw15.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
(defconstant +label-text-style+
(parse-text-style '(:sans-serif nil :very-small)))
(defconstant +highlighted-label-text-style+
(parse-text-style '(:sans-serif (:bold :italic) :small)))
(defconstant +at-most-label-text-style+
(parse-text-style '(:sans-serif nil :very-large)))
(defconstant +at-most-highlighted-label-text-style+
(parse-text-style '(:sans-serif (:bold :italic) :huge)))
(defconstant +object-without-disjoint-and-intersects-relations-ink+ (make-gray-color 0.7))
(defconstant +my-yellow+ (make-rgb-color 1 0.5 0.2))
(defconstant +overlapping-line-dashes+ '(3 5))
(defconstant +transparency-properties-dashes+ '(2 2))
(defconstant +beam-thickness+ 2)
(defconstant +rubberband-thickness+ 1)
(defconstant +rubberband-waveness+ 3)
(defconstant +marble-size+ 5)
(defconstant +nail-size+ 5)
(defconstant +bullet-size+ 4)
(defconstant +arrow-head-size+ 5)
(defconstant +marble-gravity+ 10)
(defconstant +nail-gravity+ 10)
(defconstant +line-gravity+ 15)
(defconstant +drawn-enclosure-gravity+ 30)
(defconstant +chain-and-polygon-gravity+ 30)
(defconstant +ar-1st-arrow-offset+ 12) ; ar = atomic rubberband
(defconstant +ar-2nd-arrow-offset+ 17)
(defconstant +two-guiding-lines-length+ 20) ; fwo = transparency without origin
(defconstant +chain-and-polygon-icon-gravity+ 10)
(defconstant +oc-gravity+ 10)
(defconstant +bullet-gravity+ 10)
(defconstant +marble-highlight+ 10)
(defconstant +nail-highlight+ 10)
(defconstant +line-highlight+ 6)
(defconstant +transparency-highlight+ 5)
(defconstant +enclosure-highlight+ 2)
(defconstant +chain-and-polygon-icon-highlight+ 6)
(defconstant +oc-highlight+ 3)
(defconstant +bullet-highlight+ 5)
(defconstant +intervall-highlight+ 2)
(defconstant +arrow-head-highlight+ 10)
(defconstant +label-text-style-line-height+ 10)
(defconstant +transparency-arrow-length+ 15)
;;;
;;;
;;;
(defgeneric draw (obj stream &key &allow-other-keys))
(defmethod draw :around ((obj gui-object) stream
&key
ink
(top-level t)
subobjects-draw-only-gravity-field
(draw-component-objects t)
(draw-relative-orientation-circles t)
(single-box (typep obj '(or gui-enclosure gui-transparency)))
(draw-label t)
border-for
(gravity-field t)
handling-active
highlight
(allow-sensitive-inferiors t)
(draw-chain-or-polygon-icon-p t)
label-x
label-y
(output-recording t))
(let ((gravity-field (and (not handling-active)
(not highlight)
gravity-field)))
(labels ((do-it ()
(with-visco-frame (visco)
(labels ((do-it ()
(with-drawing-options
(stream
:ink
(cond ((and border-for
(not (eq border-for 'focus)))
(ecase border-for
(intersects +my-yellow+)
(inside/contains
(if (typep obj 'gui-enclosure)
(inside-ink obj)
+yellow+))
(disjoint +blue+)))
((or handling-active
highlight
*sceleton-view*)
+flipping-ink+)
((eq (current-transparency visco) obj)
(current-transparency-ink obj))
(t (if (and (typep obj '(or gui-point
gui-line))
(ignore-disjoint-and-intersects-relations-p obj))
+object-without-disjoint-and-intersects-relations-ink+
(or ink (ink obj))))))
(apply #'call-next-method obj stream
:ink ink
:top-level top-level
:subobjects-draw-only-gravity-field subobjects-draw-only-gravity-field
:draw-component-objects draw-component-objects
:draw-relative-orientation-circles draw-relative-orientation-circles
:single-box single-box
:draw-label draw-label
:border-for border-for
:gravity-field gravity-field
:handling-active handling-active
:highlight highlight
:allow-sensitive-inferiors allow-sensitive-inferiors
:draw-chain-or-polygon-icon-p draw-chain-or-polygon-icon-p
:label-x label-x
:label-y label-y
:output-recording output-recording
nil))))
(if (and top-level
(eq border-for 'focus))
(with-border (stream :offset 5)
(do-it))
(do-it))))))
(if (and output-recording (or *ignore-inactive-flag*
(not (inactive obj))))
(with-output-as-presentation
(stream obj (type-of obj)
:single-box single-box
:allow-sensitive-inferiors allow-sensitive-inferiors)
(do-it))
(with-output-recording-options (stream :draw t :record nil)
(do-it))))))
(defmethod draw-label ((obj gui-label) stream &key highlight
label-x
label-y
handling-active
(label-text-style +label-text-style+)
(highlighted-label-text-style +highlighted-label-text-style+)
(label-text-style-line-height +label-text-style-line-height+))
(multiple-value-bind (x y)
(get-label-origin-for (object obj))
(let ((x (or label-x (+ x (x-off obj))))
(y (or label-y (+ y (y-off obj)))))
(labels ((draw-it ()
(let ((line y))
(dolist (string (text obj))
(draw-text* stream
string
x line)
(incf line label-text-style-line-height)))))
(when highlight
(with-drawing-options (stream
:ink (when (or handling-active highlight)
+flipping-ink+)
:text-style
(case highlight
(:highlight label-text-style)
(otherwise highlighted-label-text-style)))
(draw-it)))
(with-drawing-options (stream
:ink (when (or handling-active highlight)
+flipping-ink+)
:text-style
(case highlight
(:highlight highlighted-label-text-style)
(otherwise label-text-style)))
(draw-it))))))
(defmethod draw-label* (text x y stream &key (label-text-style +label-text-style+)
(label-text-style-line-height +label-text-style-line-height+))
(with-drawing-options (stream
:text-style
label-text-style)
(let ((line y))
(dolist (string text)
(draw-text* stream
string
x line)
(incf line label-text-style-line-height)))))
(defun draw-arrow-head (stream p dir-fac rot &rest args)
(apply #'draw-arrow-head* stream (x p) (y p) dir-fac rot args))
(defun draw-arrow-head* (stream x y dir-fac rot &key (offset 0)
(filled t)
(arrow-head-size +arrow-head-size+))
(let ((trans
(make-rotation-transformation*
rot x y)))
(with-drawing-options (stream :transformation trans)
(let* ((x (+ x offset))
(x1 x)
(y1 (+ y arrow-head-size))
(x2 (+ x (* dir-fac arrow-head-size)))
(y2 y)
(x3 x)
(y3 (- y arrow-head-size)))
(draw-polygon* stream (list x1 y1 x2 y2 x3 y3)
:filled filled)))))
(defmethod draw-gui-line ((obj gui-line) stream r
&rest args
&key (draw-component-objects t)
&allow-other-keys)
(unless (already-drawn obj)
(draw-line* stream
(x (p1 obj))
(y (p1 obj))
(x (p2 obj))
(y (p2 obj))
:line-dashes (when (1d-intersects-other-lines-p obj)
+overlapping-line-dashes+)
:line-thickness r))
(when draw-component-objects
(apply #'draw (p1 obj) stream :top-level nil args)
(apply #'draw (p2 obj) stream :top-level nil args)))
(defmethod draw-gui-rubberband ((obj gui-line) stream r
&rest args
&key (draw-component-objects t)
&allow-other-keys)
(unless (already-drawn obj)
(let* ((l (/ (length-of-line obj) 9))
(intersects (1d-intersects-other-lines-p obj) )
(alpha (global-orientation obj))
(alpha-orth1 (+ alpha +pi/2+))
(alpha-orth2 (- alpha +pi/2+))
(xs (x (p1 obj)))
(ys (y (p1 obj)))
(xe (x (p2 obj)))
(ye (y (p2 obj)))
(xi (* l (cos alpha)))
(yi (* l (sin alpha)))
(xii-orth1 (* +rubberband-waveness+ (cos alpha-orth1)))
(xii-orth2 (* +rubberband-waveness+ (cos alpha-orth2)))
(yii-orth1 (* +rubberband-waveness+ (sin alpha-orth1)))
(yii-orth2 (* +rubberband-waveness+ (sin alpha-orth2)))
(lx xs)
(ly ys)
(cx xs)
(cy ys))
(dotimes (n 8)
(incf cx xi)
(incf cy yi)
(let ((x (+ cx (if (evenp n) xii-orth1 xii-orth2)))
(y (+ cy (if (evenp n) yii-orth1 yii-orth2))))
(draw-line* stream lx ly x y
:line-thickness r
:line-dashes (when intersects
+overlapping-line-dashes+))
(setf lx x
ly y)))
(draw-line* stream
lx ly xe ye
:line-thickness r
:line-dashes (when intersects
+overlapping-line-dashes+))
(draw-line* stream
xs ys xe ye
:line-thickness r
:line-dashes (when intersects
+overlapping-line-dashes+))))
(when draw-component-objects
(apply #'draw (p1 obj) stream :top-level nil args)
(apply #'draw (p2 obj) stream :top-level nil args)))
(defmethod draw-gravity-field ((obj geom-point) stream r)
(draw-circle* stream (x obj) (y obj) r
:ink +transparent-ink+
:filled t))
(defmethod draw-gravity-field ((obj geom-line) stream r)
(draw-gravity-field-for-line stream
(x (p1 obj))
(y (p1 obj))
(x (p2 obj))
(y (p2 obj))
r))
(defun draw-gravity-field-for-line (stream x1 y1 x2 y2 r)
(draw-line* stream x1 y1 x2 y2
:line-thickness r
:ink +transparent-ink+))
(defun draw-gravity-field-for-circle (stream x y radius r)
(draw-circle* stream x y radius
:line-thickness r
:filled nil
:ink +transparent-ink+))
;;;
;;;
;;;
(defun draw-epsilon-body (obj r stream &rest args)
(multiple-value-bind (p1fx p1fy
p1tx p1ty
p2fx p2fy
p2tx p2ty)
(get-epsilon-enclosure-relevant-points* obj r)
(apply #'draw-polygon* stream (list
p1fx p1fy
p2fx p2fy
p2tx p2ty
p1tx p1ty
p1fx p1fy)
args)))
(defun draw-epsilon-circle (obj r stream &rest args)
(apply #'draw-circle* stream
(x obj) (y obj)
r args))
(defun draw-epsilon-segment (obj r stream &rest args)
(apply #'draw-epsilon-circle (p1 obj) r stream args)
(apply #'draw-epsilon-circle (p2 obj) r stream args)
(apply #'draw-epsilon-body obj r stream args))
;;;
;;;
;;;
(defgeneric highlight (obj stream state)
(:method-combination progn))
(defmethod highlight progn ((obj gui-chain-or-polygon) stream state)
(dolist (segment (segments obj))
(draw segment stream :draw-component-objects nil :highlight state
:output-recording nil))
(dolist (point (point-list obj))
(draw point stream :highlight state
:output-recording nil))
(draw (status-label obj) stream :highlight state :output-recording nil)
(when (at-most-constraint obj)
(draw (at-most-label obj) stream :highlight state :output-recording nil)))
(defmethod highlight progn ((obj gui-object) stream state)
(unless (typep obj 'gui-chain-or-polygon)
(draw obj stream :highlight state
:output-recording nil)))
;;;
;;;
;;;
(defmethod object-selected-position-test ((obj gui-enclosure) record x y)
(declare (ignore record))
(asg-inside-p* x y obj))
(define-presentation-method highlight-presentation ((obj gui-chain-or-polygon) record stream state)
(highlight (presentation-object record) stream state))
(define-presentation-method highlight-presentation ((obj gui-label) record stream state)
(highlight (presentation-object record) stream state))
(define-presentation-method highlight-presentation ((obj gui-point) record stream state)
(highlight (presentation-object record) stream state))
(define-presentation-method highlight-presentation ((obj gui-line) record stream state)
(highlight (presentation-object record) stream state))
(define-presentation-method highlight-presentation ((obj gui-transparency) record stream state)
(highlight (presentation-object record) stream state))
(define-presentation-method highlight-presentation ((obj gui-orientation-arrow) record stream state)
(highlight (presentation-object record) stream state))
(define-presentation-method highlight-presentation ((obj gui-relative-orientation-circle) record stream state)
(highlight (presentation-object record) stream state))
;;;
;;;
;;;
(defmethod get-label-origin-for ((obj gui-point))
(values (x obj) (y obj)))
(defmethod get-label-origin-for ((obj gui-transparency))
(values (x (pcenter obj)) (y (pcenter obj))))
(defmethod get-label-origin-for ((obj gui-line))
(values (x (pcenter obj)) (y (pcenter obj))))
(defmethod get-label-origin-for ((obj gui-chain-or-polygon))
(values (x (centroid obj)) (y (centroid obj))))
(defmethod get-label-origin-for ((obj gui-drawn-enclosure))
(values (x (centroid obj)) (y (centroid obj))))
(defmethod get-label-origin-for ((obj gui-derived-enclosure))
(get-label-origin-for (arg-object obj)))
;;;
;;;
;;;
(defmethod draw ((obj gui-status-label) stream
&key handling-active highlight label-x label-y
gravity-field draw-chain-or-polygon-icon-p)
(setf (text obj)
(list
(if (and (typep (object obj) 'possible-operator-result-mixin)
(res-of-operators (object obj)))
(concatenate 'string (get-status-string (status (object obj))) " (D)")
(get-status-string (status (object obj))))))
(draw-label obj stream
:handling-active handling-active
:highlight highlight
:label-x label-x :label-y label-y)
(labels ((draw-it ()
(let ((object (object obj)))
(multiple-value-bind (x y)
(get-label-origin-for object)
(when (typep object 'gui-chain-or-polygon)
(with-translation (stream (or label-x
(+ (x-off obj) x 20))
(or label-y
(+ (y-off obj) y 20)))
(with-scaling (stream 0.1)
(with-translation (stream (- x) (- y))
(dolist (segment (segments object))
(draw-line* stream
(x (p1 segment))
(y (p1 segment))
(x (p2 segment))
(y (p2 segment))
:line-thickness (when highlight +chain-and-polygon-icon-highlight+))
(when gravity-field
(draw-gravity-field-for-line stream
(x (p1 segment))
(y (p1 segment))
(x (p2 segment))
(y (p2 segment))
+chain-and-polygon-icon-gravity+)))))))))))
(when draw-chain-or-polygon-icon-p
(draw-it))))
(defmethod draw ((obj gui-semantics-label) stream &key highlight handling-active label-x label-y)
(setf (text obj)
(mapcar #'(lambda (s) (first (lookup-os s))) (semantics (object obj))))
(draw-label obj stream
:highlight highlight
:handling-active handling-active
:label-x label-x :label-y label-y))
(defmethod draw ((obj gui-at-most-label) stream &key highlight handling-active label-x label-y)
(setf (text obj)
(list (format nil "~A" (at-most-constraint (object obj)))))
(draw-label obj stream
:highlight highlight
:handling-active handling-active
:label-x label-x :label-y label-y
:label-text-style +at-most-label-text-style+
:highlighted-label-text-style +at-most-highlighted-label-text-style+))
(defmethod draw ((obj gui-orientation-arrow) stream &key highlight gravity-field)
(multiple-value-bind (x y)
(get-origin-for obj)
(let* ((alpha (+ (alpha-off obj)
(if (typep (object obj) 'geom-line)
(global-orientation (object obj))
0)))
(r (r obj))
(r-offset 3))
(labels ((draw-scale-mark (mark)
(let ((x (+ x (* (cos (+ alpha mark)) r)))
(y (+ y (* (sin (+ alpha mark)) r))))
(draw-circle* stream
x y
(if highlight
+bullet-highlight+
+bullet-size+)))))
(let ((x1 (+ x (* (cos alpha) (- r 5))))
(y1 (+ y (* (sin alpha) (- r 5)))))
(draw-line* stream
x y
x1 y1
:line-thickness (when highlight +oc-highlight+))
(draw-arrow-head* stream
x1 y1
1.0 alpha
:offset (- +arrow-head-size+)
:arrow-head-size (if highlight
+arrow-head-highlight+
+arrow-head-size+))
(when gravity-field
(draw-gravity-field-for-line stream
x y
x1 y1
+oc-gravity+))
(let ((cs (orientation-constraint (object obj))))
(unless (and (null (rest cs))
(numberp (first cs))
(zerop (first cs)))
(draw-circle* stream
x y r
:filled nil
:line-thickness (when highlight +oc-highlight+))
(when gravity-field
(draw-gravity-field-for-circle stream
x y r +oc-gravity+))
(dolist (entry cs)
(if (listp entry)
(progn
(draw-circle* stream x y (+ r r-offset)
:end-angle (- +2pi+ (+ alpha (first entry)))
:start-angle (- +2pi+ (+ alpha (second entry)))
:line-thickness (when highlight +oc-highlight+)
:filled nil)
(draw-circle* stream x y (+ r r-offset)
:end-angle (- +2pi+ (+ alpha pi (first entry)))
:start-angle (- +2pi+ (+ alpha pi (second entry)))
:line-thickness (when highlight +oc-highlight+)
:filled nil))
(progn
(draw-scale-mark (+ pi entry))
(draw-scale-mark entry)))))))))))
(defmethod draw ((obj gui-relative-orientation-circle) stream &key highlight gravity-field )
(let* ((obj1 (object1 obj))
(obj2 (object2 obj))
(r (r obj))
(r-offset 3)
(w (/ (allowed-derivation obj) 2))
(alpha1 (global-orientation obj1))
(alpha2 (global-orientation obj2)))
(multiple-value-bind (x y)
(calculate-intersection-point obj1 obj2)
(when (and x y)
(draw-circle* stream
x y r
:filled nil
:line-thickness (when highlight +oc-highlight+))
(when gravity-field
(draw-gravity-field-for-circle stream x y r +oc-gravity+))
(labels ((draw-it (alpha)
(if (=-eps w 0)
(draw-circle* stream
(+ x (* (cos alpha) r))
(+ y (* (sin alpha) r))
(if highlight
+bullet-highlight+
+bullet-size+))
(draw-circle* stream x y (+ r r-offset)
:end-angle (- +2pi+ (- alpha w))
:start-angle (- +2pi+ (+ alpha w))
:line-thickness (when highlight +oc-highlight+)
:filled nil))))
(with-drawing-options (stream :line-thickness 2)
(draw-it alpha1)
(incf r-offset 2)
(draw-it (+ pi alpha1)))
(incf r-offset 2)
(draw-it alpha2)
(incf r-offset 2)
(draw-it (+ pi alpha2)))))))
;;;
;;;
;;;
(defmethod draw :after ((obj gui-query-object) stream &rest args &key (draw-label t) (output-recording t))
(labels ((draw-it ()
(apply #'draw (status-label obj) stream
:top-level nil
args)
(when (semantics obj)
(apply #'draw (semantics-label obj) stream
:border-for nil
:ink nil
:top-level nil
args))))
(when (and draw-label
(not (already-drawn obj)))
(if output-recording
(with-output-as-presentation (stream obj (type-of obj))
(draw-it))
(draw-it)))))
(defmethod draw :after ((obj orientation-constraint-mixin) stream &rest args &key (output-recording t))
(labels ((draw-it ()
(apply #'draw (orientation-arrow obj) stream
:border-for nil
:ink nil
:top-level nil
args)))
(when (and (orientation-constraint obj)
(not (already-drawn obj)))
(if output-recording
(with-output-as-presentation (stream obj (type-of obj))
(draw-it))
(draw-it)))))
(defmethod draw :after ((obj at-most-constraint-mixin) stream &rest args &key (draw-label t) (output-recording t))
(labels ((draw-it ()
(apply #'draw (at-most-label obj) stream
:border-for nil
:ink nil
:top-level nil
args)))
(when (and draw-label
(at-most-constraint obj)
(not (already-drawn obj)))
(if output-recording
(with-output-as-presentation (stream obj (type-of obj))
(draw-it))
(draw-it)))))
(defmethod draw :after ((obj gui-atomic-rubberband) stream &rest args &key (output-recording t)
(draw-relative-orientation-circles t)
highlight)
(labels ((draw-it ()
(dolist (circle (relative-orientation-circles obj))
(when (eq obj (object1 circle))
(apply #'draw circle stream
:border-for nil
:ink nil
:top-level nil args)))))
(when (and (relative-orientation-circles obj)
draw-relative-orientation-circles
(not highlight)
(not (already-drawn obj)))
(if output-recording
(with-output-as-presentation (stream obj (type-of obj))
(draw-it))
(draw-it)))))
;;;
;;;
;;;
(defmethod draw ((obj gui-transparency) stream &key highlight)
(labels ((draw-it (r)
(draw-rectangle* stream
(x (pmin obj))
(y (pmin obj))
(x (pmax obj))
(y (pmax obj))
:line-thickness r
:filled nil)
(let* ((xmin (x (pmin obj)))
(ymin (y (pmin obj)))
(xmax (x (pmax obj)))
(ymax (y (pmax obj)))
(xmiddle (/ (+ xmin xmax) 2))
(ymiddle (/ (+ ymin ymax) 2))
(sxt (sx-type obj))
(syt (sy-type obj)))
(with-drawing-options (stream :line-dashes +transparency-properties-dashes+)
(when (height obj)
(if (or (not syt)
(and (symin obj)
(symax obj)
(= (symin obj)
(symax obj))))
(draw-text* stream (format nil "~A m."
(round (height obj)))
(+ xmin 4) (- ymiddle 4))
(draw-text* stream (format nil "~A ... ~A"
(if (symin obj)
(format nil "~A m." (round (* (symin obj) (height obj))))
"0")
(if (symax obj)
(format nil "~A m." (round (* (symax obj) (height obj))))
"infinity"))
(+ xmin 4) (- ymiddle 4))))
(when (width obj)
(if (or (not sxt)
(and (sxmin obj)
(sxmax obj)
(= (sxmin obj)
(sxmax obj))))
(draw-text* stream (format nil "~A m."
(round (width obj)))
(+ xmiddle 4)
(- ymax 4))
(draw-text* stream (format nil "~A ... ~A"
(if (sxmin obj)
(format nil "~A m." (round (* (sxmin obj) (width obj))))
"0")
(if (sxmax obj)
(format nil "~A m." (round (* (sxmax obj) (width obj))))
"infinity"))
(+ xmiddle 4)
(- ymax 4))))
(when sxt
(when (=> (sxmax obj)
(not (= 1.0 (sxmax obj))))
(draw-arrow* stream
xmin ymiddle
(- xmin +transparency-arrow-length+) ymiddle)
(draw-arrow* stream
xmax ymiddle
(+ xmax +transparency-arrow-length+) ymiddle))
(when (=> (sxmin obj)
(not (= 1.0 (sxmin obj))))
(draw-arrow* stream
xmin ymiddle
(+ xmin +transparency-arrow-length+) ymiddle)
(draw-arrow* stream
xmax ymiddle
(- xmax +transparency-arrow-length+) ymiddle)))
(when syt
(when (=> (symax obj)
(not (= 1.0 (symax obj))))
(draw-arrow* stream
xmiddle ymin
xmiddle (- ymin +transparency-arrow-length+))
(draw-arrow* stream
xmiddle ymax
xmiddle (+ ymax +transparency-arrow-length+)))
(when (=> (symin obj)
(not (= 1.0 (symin obj))))
(draw-arrow* stream
xmiddle ymin
xmiddle (+ ymin +transparency-arrow-length+))
(draw-arrow* stream
xmiddle ymax
xmiddle (- ymax +transparency-arrow-length+))))
(when (sxsy-constraint obj)
(if (origin obj)
(progn
(draw-line* stream
(x (origin obj))
(y (origin obj))
xmin ymin)
(draw-line* stream
(x (origin obj))
(y (origin obj))
xmin ymax)
(draw-line* stream
(x (origin obj))
(y (origin obj))
xmax ymin)
(draw-line* stream
(x (origin obj))
(y (origin obj))
xmax ymax))
(progn
(draw-line* stream
xmin ymin
(+ xmin +two-guiding-lines-length+)
(+ ymin +two-guiding-lines-length+))
(draw-line* stream
xmin ymax
(+ xmin +two-guiding-lines-length+)
(- ymax +two-guiding-lines-length+))
(draw-line* stream
xmax ymin
(- xmax +two-guiding-lines-length+)
(+ ymin +two-guiding-lines-length+))
(draw-line* stream
xmax ymax
(- xmax +two-guiding-lines-length+)
(- ymax +two-guiding-lines-length+)))))))))
(if highlight
(draw-it +transparency-highlight+)
(draw-it 0))))
;;;
;;;
;;;
(defmethod draw ((obj gui-marble) stream
&key top-level gravity-field subobjects-draw-only-gravity-field highlight)
(labels ((draw-it (r)
(when (or (not (already-drawn obj))
top-level
(and (not top-level)
(not subobjects-draw-only-gravity-field)))
(draw-circle* stream (x obj) (y obj) r
:filled nil))))
(if highlight
(draw-it +marble-highlight+)
(progn
(when gravity-field
(draw-gravity-field obj stream +marble-gravity+))
(draw-it +marble-size+)))))
(defmethod draw ((obj gui-nail) stream
&key top-level gravity-field subobjects-draw-only-gravity-field highlight)
(labels ((draw-it (r)
(when (or (not (already-drawn obj))
top-level
(and (not top-level)
(not subobjects-draw-only-gravity-field)))
(draw-marker* stream (x obj) (y obj) r))))
(if highlight
(draw-it +nail-highlight+)
(progn
(when gravity-field
(draw-gravity-field obj stream +nail-gravity+))
(draw-it +nail-size+)))))
(defmethod draw ((obj gui-origin) stream
&key top-level gravity-field subobjects-draw-only-gravity-field highlight)
(labels ((draw-it (r)
(when (or (not (already-drawn obj))
top-level
(and (not top-level)
(not subobjects-draw-only-gravity-field)))
(draw-rectangle* stream
(- (x obj) r)
(- (y obj) r)
(+ (x obj) r)
(+ (y obj) r)
:filled t))))
(if highlight
(draw-it +nail-highlight+)
(progn
(when gravity-field
(draw-gravity-field obj stream +nail-gravity+))
(draw-it +nail-size+)))))
;;;
;;;
;;;
(defmethod draw ((obj gui-beam) stream &rest args &key highlight gravity-field)
(if highlight
(apply #'draw-gui-line obj stream (+ +beam-thickness+ +line-highlight+) args)
(progn
(when gravity-field
(draw-gravity-field obj stream +line-gravity+))
(apply #'draw-gui-line obj stream +beam-thickness+ args))))
(defmethod draw ((obj gui-atomic-rubberband) stream &rest args &key highlight gravity-field)
(unless (already-drawn obj)
(let ((alpha (geometry::global-orientation obj)))
(draw-arrow-head stream (p1 obj) -1.0 alpha :offset +ar-1st-arrow-offset+ :filled nil)
(draw-arrow-head stream (p2 obj) -1.0 (+ pi alpha) :offset +ar-1st-arrow-offset+ :filled nil)
(draw-arrow-head stream (p1 obj) 1 alpha :offset +ar-2nd-arrow-offset+ :filled nil)
(draw-arrow-head stream (p2 obj) 1 (+ pi alpha) :offset +ar-2nd-arrow-offset+ :filled nil)))
(if highlight
(apply #'draw-gui-line obj stream +line-highlight+ args)
(progn
(when gravity-field
(draw-gravity-field obj stream +line-gravity+))
(apply #'draw-gui-line obj stream +rubberband-thickness+ args))))
(defmethod draw ((obj gui-atomic->=-rubberband) stream &rest args &key highlight gravity-field)
(unless (already-drawn obj)
(let ((alpha (geometry::global-orientation obj)))
(draw-arrow-head stream (p1 obj) -1 alpha :offset +ar-1st-arrow-offset+ :filled nil)
(draw-arrow-head stream (p2 obj) -1 (+ pi alpha) :offset +ar-1st-arrow-offset+ :filled nil)))
(if highlight
(apply #'draw-gui-line obj stream +line-highlight+ args)
(progn
(when gravity-field
(draw-gravity-field obj stream +line-gravity+))
(apply #'draw-gui-line obj stream +rubberband-thickness+ args))))
(defmethod draw ((obj gui-atomic-<=-rubberband) stream &rest args &key highlight gravity-field)
(unless (already-drawn obj)
(let ((alpha (geometry::global-orientation obj)))
(draw-arrow-head stream (p1 obj) 1 alpha :offset +ar-1st-arrow-offset+ :filled nil)
(draw-arrow-head stream (p2 obj) 1 (+ pi alpha) :offset +ar-1st-arrow-offset+ :filled nil)))
(if highlight
(apply #'draw-gui-line obj stream +line-highlight+ args)
(progn
(when gravity-field
(draw-gravity-field obj stream +line-gravity+))
(apply #'draw-gui-line obj stream +rubberband-thickness+ args))))
(defmethod draw ((obj gui-rubberband) stream &rest args &key highlight gravity-field)
(if highlight
(apply #'draw-gui-line obj stream (+ +rubberband-thickness+ +line-highlight+) args)
(progn
(when gravity-field
(draw-gravity-field obj stream +line-gravity+))
(apply #'draw-gui-rubberband obj stream +rubberband-thickness+ args))))
;;;
;;;
;;;
(defmethod draw ((obj gui-chain-or-polygon) stream &rest args
&key gravity-field draw-component-objects)
(unless (already-drawn obj)
(when gravity-field
(dolist (segment (segments obj))
(draw-gravity-field segment stream +chain-and-polygon-gravity+)))
(dolist (segment (segments obj))
(if draw-component-objects
(apply #'draw segment stream :single-box nil :top-level nil args)
(draw-line* stream
(x (p1 segment))
(y (p1 segment))
(x (p2 segment))
(y (p2 segment)))))))
;;;
;;;
;;;
(defmethod draw ((obj gui-enclosure) stream &key)
(draw-polygon* stream
(drawable-pointlist obj)
:closed t))
(defmethod draw ((obj gui-epsilon-enclosure) stream &key)
(let ((r (radius obj))
(obj (arg-object obj)))
(typecase obj
(point
(draw-epsilon-circle obj r stream ))
(line
(draw-epsilon-segment obj r stream))
(chain-or-polygon
(dolist (segment (segments obj))
(draw-epsilon-body segment r stream))
(dolist (point (point-list obj))
(draw-epsilon-circle point r stream))))))
| 29,713 | Common Lisp | .lisp | 847 | 29.134593 | 114 | 0.62942 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 130605f8bd83ffdea35f74bc11d7a654f71c8e481a64a7e06a6a1d30845c42eb | 11,710 | [
-1
] |
11,711 | classes10.lisp | lambdamikel_VISCO/src/GUI/classes10.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
;;;
;;;
;;;
(defpersistentclass gui-object ()
((tick :accessor tick :initform (incf *tick-counter*))
(already-drawn :accessor already-drawn :initform nil)
(history-entry :accessor history-entry :initform nil
:initarg :history-entry)
(ink :accessor ink :initarg :ink :initform +black+
:not-persistent)
(ink-rgb-list :accessor ink-rgb-list :initform (list 0 0 0)
:initarg :ink-rgb-list)
(inactive :accessor inactive :initarg :inactive :initform nil)))
(defmethod initialize-loaded-persistent-object :after ((obj gui-object))
(when (slot-boundp obj 'ink-rgb-list)
(setf (ink obj)
(apply #'make-rgb-color (ink-rgb-list obj)))))
(defmethod tick-object ((obj gui-object))
(incf (tick obj)))
;;;
;;;
;;;
(defpersistentclass gui-label (gui-object)
((x-off :accessor x-off :initform 10 :initarg :x-off)
(y-off :accessor y-off :initform 10 :initarg :y-off)
(text :accessor text :initform nil :initarg :text)
(object :accessor object :initform nil :initarg :object)))
(defmethod reinitialize ((obj gui-label))
(setf (x-off obj) 10
(y-off obj) 10))
(defmethod print-object ((obj gui-label) stream)
(format stream "~A Of ~A"
(etypecase obj
(gui-status-label "Status Label")
(gui-semantics-label "Semantics Label")
(gui-at-most-label "At Most Label"))
(object obj)))
(defpersistentclass gui-status-label (gui-label)
nil)
(defpersistentclass gui-semantics-label (gui-label)
((ink-rgb-list
:initform
#+visco-demo-mode
(list 0 0 0)
#-visco-demo-mode
(list 1 0 0))))
(defpersistentclass gui-at-most-label (gui-label)
((ink-rgb-list
:initform
#+visco-demo-mode
(list 0 0 0)
#-visco-demo-mode
(list 1 0 0))))
;;;
;;;
;;;
(defpersistentclass gui-orientation-arrow (gui-object)
((object :accessor object :initform nil :initarg :object)
(rho-off :accessor rho-off :initform pi :initarg :rho-off) ; Offset in Polarcoordinaten
(r-off :accessor r-off :initform 0 :initarg :r-off)
(r :accessor r :initform 30 :initarg :r)
(alpha-off :accessor alpha-off :initform +pi/2+ :initarg :alpha-off)
(ink-rgb-list :initform (list 1 0 0))))
(defmethod reinitialize ((obj gui-orientation-arrow))
(setf (rho-off obj) pi
(r-off obj) 0
(r obj) 30
(alpha-off obj) +pi/2+))
(defmethod print-object ((obj gui-orientation-arrow) stream)
(format stream "Orientation Constraint Of ~A"
(object obj)))
(defmethod get-origin-for ((obj gui-orientation-arrow))
(multiple-value-bind (x y)
(get-label-origin-for (object obj))
(typecase (object obj)
(line
(let* ((alpha (+ (rho-off obj)
(global-orientation (object obj))))
(length (/ (distance-between (p1 (object obj))
(p2 (object obj)))
2))
(x (+ x (* length (r-off obj)
(cos alpha))))
(y (+ y (* length (r-off obj)
(sin alpha)))))
(values x y)))
(otherwise
(let* ((alpha (rho-off obj))
(x (+ x (* (r-off obj)
(cos alpha))))
(y (+ y (* (r-off obj)
(sin alpha)))))
(values x y))))))
(defmethod set-origin-to ((obj gui-orientation-arrow) xo yo)
(multiple-value-bind (x y)
(get-label-origin-for (object obj))
(typecase (object obj)
(line
(multiple-value-bind (r alpha)
(distance-and-orientation* x y xo yo)
(setf (r-off obj)
(/ r (/ (distance-between (p1 (object obj))
(p2 (object obj))) 2))
(rho-off obj)
(- alpha
(global-orientation (object obj))))))
(otherwise
(multiple-value-bind (r alpha)
(distance-and-orientation* x y xo yo)
(setf (r-off obj) r
(rho-off obj) alpha))))))
;;;
;;;
;;;
(defpersistentclass gui-relative-orientation-circle (gui-object)
((object1 :accessor object1 :initform nil :initarg :object1)
(object2 :accessor object2 :initform nil :initarg :object2)
(r :accessor r :initform 20 :initarg :r)
(allowed-derivation :accessor allowed-derivation :initform 0 :initarg :allowed-derivation)
(ink-rgb-list :initform (list 1 0 1))))
(defmethod reinitialize ((obj gui-relative-orientation-circle))
(setf (r obj) 20
(allowed-derivation obj) 0))
(defmethod print-object ((obj gui-relative-orientation-circle) stream)
(format stream "Rel. Orient. Constr. Between ~A And ~A"
(object1 obj)
(object2 obj)))
;;;
;;;
;;;
(defpersistentclass gui-visco-object (gui-object visco-object)
((dummy-p :accessor dummy-p :initarg :dummy-p :initform nil)))
(defmethod print-object ((obj gui-visco-object) stream)
(let ((descr (subseq (format nil "~A"
(type-of obj))
4)))
(if (name obj)
(format stream "~A-~A"
descr
(name obj))
(format stream "~A" descr))))
(defpersistentclass gui-query-object-or-enclosure (gui-visco-object query-object-or-enclosure)
((label-line-counter :initform 0 :accessor label-line-counter)))
(defpersistentclass gui-query (gui-object query)
())
(defpersistentclass gui-transparency (gui-visco-object transparency)
((current-transparency-ink :accessor current-transparency-ink :initarg :current-transparency-ink
:initform +blue+
:not-persistent)
(properties-set :accessor properties-set :initform nil)))
(defmethod initialize-loaded-persistent-object :after ((obj gui-transparency))
(setf (current-transparency-ink obj)
+blue+))
(defpersistentclass gui-query-object (gui-query-object-or-enclosure query-object)
((status-label :accessor status-label :initform (make-instance 'gui-status-label))
(semantics-label :accessor semantics-label :initform (make-instance 'gui-semantics-label))))
(defpersistentclass gui-at-least-1d-query-object (gui-query-object at-least-1d-query-object)
())
(defpersistentclass gui-point (gui-query-object point)
())
(defpersistentclass gui-marble (gui-point marble)
())
(defpersistentclass gui-nail (gui-point nail)
())
(defpersistentclass gui-origin (gui-nail origin)
((orientation-arrow :accessor orientation-arrow :initform (make-instance 'gui-orientation-arrow))))
(defpersistentclass gui-line (gui-at-least-1d-query-object line)
())
(defpersistentclass gui-rubberband (gui-line rubberband)
((at-most-label :accessor at-most-label :initform (make-instance 'gui-at-most-label))))
(defpersistentclass gui-atomic-rubberband (gui-line atomic-rubberband)
((orientation-arrow :accessor orientation-arrow :initform (make-instance 'gui-orientation-arrow))
(relative-orientation-circles :accessor relative-orientation-circles :initform nil)))
(defpersistentclass gui-atomic-<=-rubberband (gui-atomic-rubberband atomic-<=-rubberband)
())
(defpersistentclass gui-atomic->=-rubberband (gui-atomic-rubberband atomic->=-rubberband)
())
(defpersistentclass gui-beam (gui-atomic-rubberband beam)
())
(defpersistentclass gui-chain-or-polygon (gui-at-least-1d-query-object chain-or-polygon)
((orientation-arrow :accessor orientation-arrow :initform (make-instance 'gui-orientation-arrow))
(at-most-label :accessor at-most-label :initform (make-instance 'gui-at-most-label))))
(defpersistentclass gui-chain (gui-chain-or-polygon chain)
())
(defpersistentclass gui-polygon (gui-chain-or-polygon polygon)
())
(defpersistentclass gui-enclosure (gui-query-object-or-enclosure enclosure) ; abstrakt
((inside-ink :accessor inside-ink :initarg :inside-ink
:not-persistent)
(pattern-id :accessor pattern-id :initarg :pattern-id :initform nil)
(at-most-label :accessor at-most-label :initform (make-instance 'gui-at-most-label))))
(defmethod initialize-loaded-persistent-object :after ((obj gui-enclosure))
(setf (ink obj)
(get-pattern-in (apply #'make-rgb-color (ink-rgb-list obj))
:opaque-p (opaque-p obj)
:pattern-id (pattern-id obj)))
(setf (inside-ink obj)
(get-pattern-in +green+ :opaque-p (opaque-p obj)
:pattern-id (pattern-id obj))))
(defpersistentclass gui-derived-enclosure (gui-enclosure derived-enclosure)
())
(defpersistentclass gui-drawn-enclosure (gui-enclosure drawn-enclosure)
((drawable-pointlist :accessor drawable-pointlist :initarg :drawable-pointlist)))
(defpersistentclass gui-inner-enclosure (gui-derived-enclosure inner-enclosure)
((drawable-pointlist :accessor drawable-pointlist :initarg :drawable-pointlist)))
(defpersistentclass gui-outer-enclosure (gui-derived-enclosure outer-enclosure)
((drawable-pointlist :accessor drawable-pointlist :initarg :drawable-pointlist)))
(defpersistentclass gui-epsilon-enclosure (gui-derived-enclosure epsilon-enclosure)
())
(defpersistentclass gui-epsilon-p-enclosure (gui-epsilon-enclosure epsilon-p-enclosure)
())
(defpersistentclass gui-epsilon-m-enclosure (gui-epsilon-enclosure epsilon-m-enclosure)
())
;;;
;;;
;;;
(defun find-named-visco-object (name)
(or (find name (visco-objects
(get-current-query))
:key #'name)
(error "~A not found!" name)))
(defun find-named-history-entry (name)
(with-visco-frame (visco)
(or (find name (history visco)
:key #'name)
(error "~A not found!" name))))
;;;
;;;
;;;
(defpersistentclass history-entry ()
((name :accessor name :initarg :name :initform (incf *history-name-counter*))
(operation-descr :accessor operation-descr :initarg :operation-descr)
(source :accessor source :initarg :source)
(code :accessor code :initarg :code
:not-persistent)
(arg-objects :accessor arg-objects :initarg :arg-objects :initform nil)))
(defpersistentclass visually-relevant-history-entry (history-entry)
((object-to-draw :accessor object-to-draw :initarg :object-to-draw :initform nil)))
(defpersistentclass constructor-history-entry (visually-relevant-history-entry)
())
(defmethod print-object ((obj history-entry) stream)
(format stream "~A"
(operation-descr obj)))
;;;
;;;
;;;
(defmethod make-history-entry ((operation-descr string)
(code list)
(args list) &key name (class 'history-entry))
(let ((obj (make-instance class
:operation-descr operation-descr
:source code
:arg-objects (mapcar #'name args)
#| :code (compile nil
`(lambda ()
,code))))) |# )))
(when name
(setf (name obj) name))
obj))
(defmethod make-constructor-history-entry ((operation-descr string)
(code list)
(args list) &key name)
(make-history-entry operation-descr code args :name name :class 'constructor-history-entry))
(defmethod make-visually-relevant-history-entry ((operation-descr string)
(code list)
(args list) &key name)
(make-history-entry operation-descr code args :name name :class 'visually-relevant-history-entry))
(defmethod register ((entry history-entry))
(with-visco-frame (visco)
(pushend entry (history visco))
entry))
(defmethod register-history-entry ((operation-descr string)
(code list)
(args list) &key name)
(register (make-history-entry operation-descr code args :name name)))
(defmethod register-visually-relevant-history-entry ((operation-descr string)
(code list)
(args list) &key name)
(register (make-visually-relevant-history-entry operation-descr code args :name name)))
(defmethod register-constructor-history-entry ((operation-descr string)
(code list)
(args list) &key name)
(register (make-constructor-history-entry operation-descr code args :name name)))
(defmethod delete-history-entry ((entry history-entry))
(with-visco-frame (visco)
(setf (history visco)
(delete entry (history visco)))))
(defmethod delete-history-entries ((entries list))
(dolist (entry entries)
(delete-history-entry entry)))
;;;
;;;
;;;
(defmethod initialize-loaded-persistent-object :after ((history-entry history-entry))
(setf (code history-entry)
#| (compile nil |#
(source history-entry)))
;;;
;;;
;;;
#|
(defmethod execute ((history-entry history-entry))
(values (ignore-errors
(eval (source history-entry)))
history-entry))
|#
(defmethod execute ((history-entry history-entry))
(values
(eval (source history-entry))
history-entry))
(defmethod execute :around ((history-entry visually-relevant-history-entry))
(let ((res (call-next-method)))
(cond (res
(setf (object-to-draw history-entry) res
(history-entry res) history-entry)
(values res history-entry))
(t
(values nil history-entry)))))
(defun get-status-string (symbol)
(case symbol
(db "DB")
(db-component "DB-C")
(universe "U")
(otherwise "")))
| 12,610 | Common Lisp | .lisp | 326 | 34.56135 | 101 | 0.703518 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | c165d633de2e4e4fd08243e2e80c81fc6a231d5dd9b1166c14e9b0a4d670d7a0 | 11,711 | [
-1
] |
11,712 | option-buttons4.lisp | lambdamikel_VISCO/src/GUI/option-buttons4.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
(defun accept-option-buttons (frame stream)
(declare (ignore frame))
(with-centering (stream)
(format stream "The Grid Is"))
(with-centering (stream)
(multiple-value-bind (int ptype changed)
(accept 'completion
:stream stream
:query-identifier 'grid-resolution
:default *grid-resolution*
:prompt nil
:view `(option-pane-view :items (off 5 10 20 30 40 50)
:value ,*grid-resolution*
:name-key ,#'(lambda (item)
(case item
(off "Off")
(otherwise (format nil "On, Stepsize ~A" item))))
:value-key ,#'(lambda (item)
(and (numberp item) item))))
(declare (ignore ptype))
(when changed (setf *grid-resolution* int))))
(with-centering (stream)
(format stream "New Enclosures Are"))
(with-centering (stream)
(multiple-value-bind (bool ptype changed)
(accept 'completion
:query-identifier 'enclosures
:prompt nil
:stream stream
:default *opaque-enclosures-p*
:view `(option-pane-view :items (opaque translucent)
:value-key ,#'(lambda (sym)
(eq sym 'opaque))
:value ,*opaque-enclosures-p*))
(declare (ignore ptype))
(when changed
(setf *opaque-enclosures-p* bool)
(reinitialize *button-drawn-enclosure*))))
(with-centering (stream)
(format stream "Component Relations (I & D)"))
(with-centering (stream)
(multiple-value-bind (bool ptype changed)
(accept 'boolean
:query-identifier 'ignore-relations
:prompt nil
:stream stream
:default (not *ignore-disjoint-and-intersects-component-relations-p*))
(declare (ignore ptype))
(when changed
(setf *ignore-disjoint-and-intersects-component-relations-p* (not bool)))))
(with-centering (stream)
(format stream "Display Options"))
(with-visco-frame (visco)
(with-centering (stream)
(formatting-table (stream)
(formatting-row (stream)
(formatting-cell (stream :align-x :center)
(multiple-value-bind (set ptype changed)
(accept `((subset-completion (Intersects Inside/Contains Disjoint)))
:stream stream
:default *visualized-relations*
:prompt nil
:view `(list-pane-view :value ,*visualized-relations*))
(declare (ignore ptype))
(when changed
(setf *visualized-relations* set)
(redisplay-frame-pane visco 'display :force-p t))))
(formatting-cell (stream :align-x :center)
(multiple-value-bind (bool ptype changed)
(accept 'boolean
:prompt "Focus"
:stream stream
:default *focus-box*)
(declare (ignore ptype))
(when changed
(setf *focus-box* bool)
(redisplay-frame-pane visco 'display :force-p t)))))))))
| 2,749 | Common Lisp | .lisp | 79 | 29.658228 | 76 | 0.674621 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 8c8e74948b8616f8f9bf24dcc196332fa4e35267cd8499814bac4888f12939b9 | 11,712 | [
-1
] |
11,713 | specials.lisp | lambdamikel_VISCO/src/GUI/specials.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
;;;
;;;
;;;
(defparameter *tick-counter* 0)
(defparameter *history-name-counter* 0)
;;;
;;;
;;;
(defparameter *visco-frame* nil)
(defparameter *visco-buttons-frame* nil)
(defparameter *visco-inspector-frame* nil)
(defparameter *dummies* nil)
(defparameter *searching-active* nil)
(defparameter *buttons* nil)
(defparameter *draw-thumbnails* t)
(defparameter *permutations* nil)
(defparameter *focus-box* t)
(defparameter *visualized-relations* nil)
(defparameter *grid-resolution* 10)
(defparameter *opaque-enclosures-p* t)
(defparameter *ignore-disjoint-and-intersects-component-relations-p* nil)
(defparameter *ignore-inactive-flag* nil)
(defparameter *sceleton-view* nil)
;;;
;;;
;;;
(defparameter *object-buttons* nil)
(defparameter *creating-active* nil)
(defparameter *primary-mode* nil)
(defparameter *segment-mode* nil)
(defparameter *point-mode* nil)
(defvar *button-transparency* )
(defvar *button-origin*)
(defvar *button-nail*)
(defvar *button-marble*)
(defvar *button-atomic-rubberband*)
(defvar *button-atomic-<=-rubberband* )
(defvar *button-atomic->=-rubberband*)
(defvar *button-rubberband*)
(defvar *button-beam*)
(defvar *button-chain* )
(defvar *button-polygon* )
(defvar *button-drawn-enclosure*)
;;;
;;;
;;;
(defparameter *operator-buttons* nil)
(defparameter *operator-mode* nil)
(defvar *button-no-operator*)
(defvar *button-create-centroid*)
(defvar *button-create-intersection-point*)
(defvar *button-create-inverse-drawn-enclosure*)
(defvar *button-create-inner-enclosure*)
(defvar *button-create-outer-enclosure*)
(defvar *button-create-epsilon-enclosure*)
(defvar *button-recreate*)
(defvar *button-set-semantics*)
(defvar *button-set-at-most-constraint*)
(defvar *button-set-orientation-constraint*)
(defvar *button-create-orientation-constraint-mark*)
(defvar *button-create-orientation-constraint-intervall*)
(defvar *button-create-relative-orientation-constraint*)
(defvar *button-set-transparency-properties*)
;;;
;;;
;;;
(defparameter *point-status* nil)
(defparameter *segment-status* nil)
(defparameter *chain-or-polygon-status* nil)
(defparameter *status-buttons* nil)
(defvar *button-point-status-db*)
(defvar *button-segment-status-db*)
(defvar *button-chain-or-polygon-status-db*)
(defvar *button-point-status-db-component*)
(defvar *button-segment-status-db-component*)
(defvar *button-chain-or-polygon-status-db-component*)
(defvar *button-point-status-universe*)
(defvar *button-segment-status-universe*)
(defvar *button-chain-or-polygon-status-universe*)
(defvar *point-buttons*)
(defvar *segment-buttons*)
(defvar *chain-or-polygon-buttons*)
| 2,715 | Common Lisp | .lisp | 84 | 30.880952 | 73 | 0.77264 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | b3329a18c514fd9712205bc2d68f75a1ac8fba848a025f5ebe0c58490fa71dab | 11,713 | [
-1
] |
11,714 | constructors5.lisp | lambdamikel_VISCO/src/GUI/constructors5.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
;;;
;;; Konstruktoren
;;;
(defun make-visco-gui-query ()
(make-instance 'gui-query))
;;;
;;;
;;;
(defmethod make-visco-marble ((transparency gui-transparency) (status symbol) (x number) (y number) &rest initargs)
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-marble :allow-other-keys t initargs)))
(defmethod make-visco-nail ((transparency gui-transparency) (status symbol) (x number) (y number) &rest initargs)
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-nail :allow-other-keys t initargs)))
(defmethod make-visco-origin ((transparency gui-transparency) (status symbol) (x number) (y number) &rest initargs)
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-origin :allow-other-keys t initargs)))
;;;
;;;
;;;
(defmethod change-class ((obj geom-point) (type (eql 'marble)) &rest initargs)
(apply #'change-class obj 'gui-marble :allow-other-keys t initargs))
(defmethod change-class ((obj geom-point) (type (eql 'nail)) &rest initargs)
(apply #'change-class obj 'gui-nail :allow-other-keys t initargs))
(defmethod change-class ((obj geom-point) (type (eql 'origin)) &rest initargs)
(apply #'change-class obj 'gui-origin :allow-other-keys t initargs))
(defmethod change-class ((obj geom-line) (type (eql 'rubberband)) &rest initargs)
(apply #'change-class obj 'gui-rubberband :allow-other-keys t initargs))
(defmethod change-class ((obj geom-line) (type (eql 'atomic-rubberband)) &rest initargs)
(apply #'change-class obj 'gui-atomic-rubberband :allow-other-keys t initargs))
(defmethod change-class ((obj geom-line) (type (eql 'atomic-<=-rubberband)) &rest initargs)
(apply #'change-class obj 'gui-atomic-<=-rubberband :allow-other-keys t initargs))
(defmethod change-class ((obj geom-line) (type (eql 'atomic->=-rubberband)) &rest initargs)
(apply #'change-class obj 'gui-atomic->=-rubberband :allow-other-keys t initargs))
(defmethod change-class ((obj geom-line) (type (eql 'beam)) &rest initargs)
(apply #'change-class obj 'gui-beam :allow-other-keys t initargs))
;;;
;;;
;;;
(defmethod make-visco-rubberband ((transparency gui-transparency) (status symbol) (p1 point) (p2 point) &rest initargs)
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-rubberband :allow-other-keys t initargs)))
(defmethod make-visco-atomic-rubberband ((transparency gui-transparency) (status symbol) (p1 point) (p2 point) &rest initargs)
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-atomic-rubberband :allow-other-keys t initargs)))
(defmethod make-visco-atomic-<=-rubberband ((transparency gui-transparency) (status symbol) (p1 point) (p2 point) &rest initargs)
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-atomic-<=-rubberband :allow-other-keys t initargs)))
(defmethod make-visco-atomic->=-rubberband ((transparency gui-transparency) (status symbol) (p1 point) (p2 point) &rest initargs)
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-atomic->=-rubberband initargs)))
(defmethod make-visco-beam ((transparency gui-transparency) (status symbol) (p1 point) (p2 point) &rest initargs)
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-beam :allow-other-keys t initargs)))
;;;
;;;
;;;
(defmethod make-visco-chain ((transparency gui-transparency) (status symbol) (segments list) &rest initargs)
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-chain :allow-other-keys t initargs)))
(defmethod make-visco-polygon ((transparency gui-transparency) (status symbol) (segments list) &rest initargs)
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-polygon :allow-other-keys t initargs)))
;;;
;;;
;;;
(defmethod make-visco-drawn-enclosure ((transparency gui-transparency) (segments list) opaque-p &rest initargs)
(declare (ignore opaque-p))
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-drawn-enclosure :allow-other-keys t initargs)))
(defmethod make-visco-inner-enclosure ((arg gui-polygon) opaque-p &rest initargs)
(declare (ignore opaque-p))
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-inner-enclosure :allow-other-keys t initargs)))
(defmethod make-visco-outer-enclosure ((arg gui-polygon) opaque-p &rest initargs)
(declare (ignore opaque-p))
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-outer-enclosure :allow-other-keys t initargs)))
(defmethod make-visco-epsilon-enclosure ((arg gui-query-object) (radius number) opaque-p &rest initargs)
(declare (ignore opaque-p))
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-epsilon-enclosure :allow-other-keys t initargs)))
(defmethod make-visco-epsilon-p-enclosure ((arg gui-polygon) (radius number) opaque-p &rest initargs)
(declare (ignore opaque-p))
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-epsilon-p-enclosure :allow-other-keys t initargs)))
(defmethod make-visco-epsilon-m-enclosure ((transparency gui-polygon) (radius number) opaque-p &rest initargs)
(declare (ignore opaque-p))
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-epsilon-m-enclosure :allow-other-keys t initargs)))
;;;
;;;
;;;
(defmethod make-visco-transparency ((query gui-query) xmin ymin xmax ymax &rest initargs)
(declare (ignore xmin ymin xmax ymax))
(let ((obj (call-next-method)))
(apply #'change-class obj 'gui-transparency :allow-other-keys t initargs)))
;;;
;;;
;;;
(defmethod initialize-instance :after ((new gui-object) &rest initargs)
(declare (ignore initargs))
(setf (ink new)
(apply #'make-rgb-color (ink-rgb-list new))))
(defmethod update-instance-for-different-class :after (old
(new gui-object)
&rest initargs)
(declare (ignore initargs))
(unless (typep old 'gui-object)
(unless (ink-rgb-list new)
(setf (ink-rgb-list new)
(calculate-gray-color new)))
(setf (ink new)
(apply #'make-rgb-color (ink-rgb-list new)))))
(defmethod update-instance-for-different-class :after (old
(new gui-query-object)
&rest initargs)
(declare (ignore initargs))
(unless (typep old 'gui-object)
(setf (object (status-label new)) new)
(setf (object (semantics-label new)) new)))
(defmethod update-instance-for-different-class :after (old
(new gui-enclosure)
&rest initargs)
(declare (ignore initargs))
(unless (typep old 'gui-object)
(multiple-value-bind (pattern id)
(get-pattern-in (apply #'make-rgb-color (ink-rgb-list new))
:pattern-id (pattern-id new)
:opaque-p (opaque-p new))
(setf (ink new) pattern)
(setf (pattern-id new)
id)
(when (typep new '(or gui-drawn-enclosure
gui-inner-enclosure
gui-outer-enclosure))
(setf (drawable-pointlist new)
(get-drawable-pointlist-for new)))
(setf (inside-ink new)
(get-pattern-in (apply #'make-rgb-color (list 0 (/ (apply #'+ (ink-rgb-list new)) 3) 0))
:pattern-id (pattern-id new)
:opaque-p (opaque-p new))))
(setf (object (at-most-label new)) new)))
(defmethod update-instance-for-different-class :after (old
(new gui-transparency)
&rest initargs)
(declare (ignore initargs))
(unless (typep old 'gui-object)
(set-current-transparency-to new))
#| (setf (object (properties new)) new)) |# )
(defmethod update-instance-for-different-class :after (old
(new gui-atomic-rubberband)
&rest initargs)
(declare (ignore initargs))
(unless (typep old 'gui-object)
(setf (object (orientation-arrow new)) new)))
(defmethod update-instance-for-different-class :after (old
(new gui-origin)
&rest initargs)
(declare (ignore initargs))
(unless (typep old 'gui-object)
(setf (object (orientation-arrow new)) new)))
(defmethod update-instance-for-different-class :after (old
(new gui-rubberband)
&rest initargs)
(declare (ignore initargs))
(unless (typep old 'gui-object)
(setf (object (at-most-label new)) new)))
(defmethod update-instance-for-different-class :after (old
(new gui-chain-or-polygon)
&rest initargs)
(declare (ignore initargs))
(unless (typep old 'gui-object)
(setf (object (at-most-label new)) new)
(setf (object (orientation-arrow new)) new)))
;;;
;;;
;;;
(defmethod initialize-instance :after ((obj gui-relative-orientation-circle) &rest initargs)
(declare (ignore initargs))
(push obj (relative-orientation-circles (object1 obj)))
(push obj (relative-orientation-circles (object2 obj))))
;;;
;;;
;;;
(defmethod delete-object progn ((obj gui-visco-object) &key &allow-other-keys)
(with-visco-frame (visco)
(dolist (entry (history visco))
(when (and (eq (type-of entry) 'history-entry)
(member (name obj) (arg-objects entry)))
(setf (history visco)
(delete entry
(history visco)))))
(setf (history visco)
(delete (history-entry obj)
(history visco)))
(when (eq (current-focus visco) (history-entry obj))
(set-current-focus-to nil))))
(defmethod delete-object progn ((obj gui-transparency) &key &allow-other-keys)
(with-visco-frame (visco)
(when (eq (current-transparency visco) obj)
(set-current-transparency-to nil))))
;;;
;;;
;;;
(defmethod delete-object progn ((obj gui-object) &key &allow-other-keys)
nil)
(defmethod delete-object progn ((obj gui-relative-orientation-circle) &key &allow-other-keys)
(setf (relative-orientation-circles (object1 obj))
(delete obj (relative-orientation-circles (object1 obj))))
(setf (relative-orientation-circles (object2 obj))
(delete obj (relative-orientation-circles (object2 obj)))))
;;;
;;;
;;;
(defun get-negated-drawable-pointlist (points xmin ymin xmax ymax)
(let ((x1 (first points))
(y1 (second points)))
(append points
(list x1 y1)
(list xmin ymin)
(list xmin ymax)
(list xmax ymax)
(list xmax ymin)
(list xmin ymin))))
(defmethod get-negated-drawable-pointlist-for ((obj geom-polygon))
(let* ((transparency (on-transparency obj))
(xmin (x (pmin transparency)))
(ymin (y (pmin transparency)))
(xmax (x (pmax transparency)))
(ymax (y (pmax transparency))))
(get-negated-drawable-pointlist (mapcan #'(lambda (p)
(list (x p) (y p)))
(point-list obj))
xmin ymin xmax ymax)))
(defmethod get-drawable-pointlist-for ((obj geom-polygon))
(mapcan #'(lambda (p)
(list (x p) (y p)))
(point-list obj)))
(defmethod get-drawable-pointlist-for ((obj gui-drawn-enclosure))
(if (negated-p obj)
(get-negated-drawable-pointlist-for obj)
(call-next-method)))
(defmethod get-drawable-pointlist-for ((obj gui-inner-enclosure))
(get-drawable-pointlist-for (polygon obj)))
(defmethod get-drawable-pointlist-for ((obj gui-outer-enclosure))
(let* ((transparency (on-transparency obj))
(xmin (x (pmin transparency)))
(ymin (y (pmin transparency)))
(xmax (x (pmax transparency)))
(ymax (y (pmax transparency))))
(get-negated-drawable-pointlist
(get-drawable-pointlist-for (polygon obj))
xmin ymin xmax ymax)))
| 11,300 | Common Lisp | .lisp | 256 | 40.058594 | 129 | 0.694069 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 698078924b7f97cd3eabebb1a5daf649c514ed4843c2a2fc5a34bb1f27f43f9d | 11,714 | [
-1
] |
11,715 | buttons.lisp | lambdamikel_VISCO/src/GUI/buttons.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
(defconstant +button-text-style+
(parse-text-style '(:sans-serif nil :large)))
(defconstant +on-ink+
+yellow+)
(defconstant +grayed-on-ink+
(make-grid-in +yellow+ +background-ink+))
(defconstant +activated-ink+
+green+)
(defconstant +grayed-activated-ink+
(make-grid-in +green+ +background-ink+))
(defconstant +not-activated-ink+
(make-gray-color 0.8))
;;;
;;;
;;;
(defclass button (gui-object) ; abstrakt
((on :accessor on :initform nil :initarg :on)
(deactivated :accessor deactivated :initform nil :initarg :deactivated)
(id :accessor id :initform nil :initarg :id)
(tester :accessor tester :initform #'yes :initarg :tester)
(valid :accessor valid :initform #'yes :initarg :valid)
(when-selected :accessor when-selected :initform #'toggle :initarg :when-selected)
(when-action-begins :accessor when-action-begins :initform #'yes :initarg :when-action-begins)
(when-action-ends :accessor when-action-ends :initform #'yes :initarg :when-action-ends)
(initialize :accessor initialize :initform #'yes :initarg :initialize)
(doc :accessor doc :initform "No documentation available" :initarg :doc)))
(defclass icon-button (button) ; abstrakt
((icon :accessor icon :initarg :icon)
(scale-fac :accessor scale-fac :initarg :scale-fac :initform 0.8)))
(defclass text-button (button) ; abstrakt
((text :accessor text :initarg :text)))
;;;
;;;
;;;
(defun get-button-for-icon (icon &optional (buttons *buttons*))
(find icon buttons :key #'(lambda (obj)
(when (typep obj 'icon-button)
(icon obj)))))
(defmethod initialize-instance :after ((obj button) &rest initargs)
(declare (ignore initargs))
(push obj *buttons*)
(funcall (initialize obj) obj))
(defmethod reinitialize ((obj button))
(funcall (initialize obj) obj))
;;;
;;;
;;;
(defmethod inform-button-action-ends ((button button))
(funcall (when-action-ends button) button))
(defmethod inform-button-action-begins ((button button))
(funcall (when-action-begins button) button))
(defmethod deactivate ((button button))
(setf (deactivated button) t))
(defmethod deactivate ((buttons list))
(dolist (button buttons)
(deactivate button)))
(defmethod activate ((button button))
(setf (deactivated button) nil))
(defmethod activate ((buttons list))
(dolist (button buttons)
(activate button)))
(defmethod toggle ((button button))
(setf (on button)
(not (on button))))
(defmethod switch-on ((button button))
(setf (on button) t))
(defmethod switch-off ((button button))
(setf (on button) nil))
(defmethod switch-off ((buttons list))
(dolist (button buttons)
(switch-off button)))
(defmethod switch-on ((buttons list))
(dolist (button buttons)
(switch-on button)))
(defmethod toggle ((buttons list))
(dolist (button buttons)
(toggle button)))
;;;
;;;
;;;
(defmethod valid-p ((button button))
(funcall (valid button) button))
;;;
;;;
;;;
(defun get-button-state ()
(list *primary-mode*
*segment-mode*
*point-mode*
*point-status*
*segment-status*
*chain-or-polygon-status*
(mapcar #'deactivated *buttons*)
(mapcar #'on *buttons*)))
(defun install-button-state (state)
(setf *primary-mode* (first state)
*segment-mode* (second state)
*point-mode* (third state)
*point-status* (fourth state)
*segment-status* (fifth state)
*chain-or-polygon-status* (sixth state))
(mapc #'(lambda (flag button)
(if flag
(deactivate button)
(activate button)))
(seventh state) *buttons*)
(mapc #'(lambda (flag button)
(setf (on button) flag))
(eighth state) *buttons*)
(redraw-buttons))
;;;
;;;
;;;
(defmethod draw-button :before ((button button) stream cell-size)
(let* ((half-cell-size (/ cell-size 2)))
(draw-rectangle* stream
(- half-cell-size)
(- half-cell-size)
half-cell-size
half-cell-size
:filled t
:ink
(let ((active (funcall (tester button) button))
(deactivated (deactivated button))
(on (on button)))
(if (not deactivated)
(if on
(if active
+on-ink+
+grayed-on-ink+)
(if active
+activated-ink+
+not-activated-ink+))
(if on
+grayed-on-ink+
(if active
+grayed-activated-ink+
+not-activated-ink+)))))
(draw-rectangle* stream
(- half-cell-size)
(- half-cell-size)
half-cell-size
half-cell-size
:filled nil)))
(defmethod draw-button ((button button) stream cell-size)
(declare (ignore stream cell-size))
nil)
(defmethod underlabel-button ((button button) stream cell-size)
(declare (ignore stream cell-size))
nil)
(defmethod output-draw-button ((button button) stream cell-size)
(declare (ignore stream cell-size))
nil)
(defun accept-buttons (buttons rows columns frame stream &key width height
(x-spacing 4)
(y-spacing 4))
(declare (ignore frame))
(#+:allegro excl:without-interrupts
#+:mcl ccl:without-interrupts
(let* ((cell-size 50)
(x1 nil)
(y1 nil)
(x2 nil)
(y2 nil))
(labels ((draw-it (button sx sy)
(let* ((or
(with-output-to-output-record (stream)
(output-draw-button button stream cell-size)))
(width (bounding-rectangle-width or))
(height (bounding-rectangle-height or)))
(with-scaling (stream (* sx (/ cell-size width))
(* sy (/ cell-size height)))
(output-draw-button button stream cell-size)
(underlabel-button button stream cell-size)))))
(multiple-value-bind (xc yc)
(stream-cursor-position stream)
(multiple-value-bind (x y)
(multiple-value-bind (a b)
(window-inside-size stream)
(values (or width (- a xc))
(or height (- b yc))))
(let ((sx (/ x (+ (* columns cell-size)
(* columns x-spacing))))
(sy (/ y (+ (* rows cell-size)
(* rows y-spacing))))
(xcoord nil)
(ycoord nil))
(dotimes (i rows)
(dotimes (j columns)
(setf xcoord (+ xc (* x-spacing j) (* cell-size sx j))
ycoord (+ yc (* y-spacing i) (* cell-size sy i)))
(let* ((button (pop buttons)))
(stream-set-cursor-position stream xcoord ycoord)
(with-room-for-graphics (stream)
(declare (ignore stream))
(draw-it button sx sy)))
(when (and (= (1+ i) rows) (zerop j))
(setf x1 xcoord
y1 (+ ycoord (* cell-size sy))))
(when (and (zerop i) (= (1+ j) columns))
(setf x2 (+ xcoord (* cell-size sx))
y2 ycoord))))
(values x1 y1
x2 y2))))))))
;;;
;;;
;;;
(define-visco-buttons-command (com-select-mode :name nil)
((object 'button))
#| (excl:without-interrupts |#
(funcall (when-selected object)
object))
(define-presentation-to-command-translator select-mode
(button com-select-mode visco-buttons
:gesture :select
:tester ((object) (and (not (deactivated object))
(funcall (tester object) object)))
:echo nil :maintain-history nil
:documentation ((stream object)
(let ((doc (doc object)))
(etypecase doc
(string (princ doc stream))
(list (princ (first doc) stream))))))
(object)
(list object))
| 7,306 | Common Lisp | .lisp | 227 | 27.537445 | 97 | 0.652665 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 58b7a787a9f0b45ee1214d78342d8cecb1fa2c419f7fd6b55caafd703f201a18 | 11,715 | [
-1
] |
11,716 | frame9.lisp | lambdamikel_VISCO/src/GUI/frame9.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
(defconstant +x-no-of-thumbnails+
#-visco-demo-mode 8
#+visco-demo-mode 4)
(defconstant +y-no-of-thumbnails+
#-visco-demo-mode 8
#+visco-demo-mode 4)
(defconstant +spacing+ 10)
(defconstant +visco-text-style+
(make-text-style :sans-serif
:roman
:normal))
(defconstant +info-text-style+
(make-text-style :serif :roman :small))
(defconstant +command-listener-text-style+
(make-text-style
:sans-serif :roman :normal))
(defconstant +inspector-text-style+
(make-text-style :fix nil :small))
(defconstant +pointer-doc-text-style+
(make-text-style :sans-serif :bold :small))
(defvar +button-abort+)
(defvar +button-draw-thumbnails+)
(defvar +button-permutations+)
(defvar +button-next+)
(defvar +button-previous+)
(defvar +button-delete-all-pages+)
(defvar +button-delete-page+)
(defvar +button-delete-selected+)
(defvar +button-delete-unselected+)
(defvar +button-unselect-all+)
;;;
;;;
;;;
(defmethod output-record-refined-position-test ((record standard-presentation) x y)
(let ((obj (presentation-object record)))
(if (typep obj '(or gui-enclosure query-result))
(object-selected-position-test obj record x y)
(call-next-method))))
;;;
;;;
;;;
(define-application-frame visco-buttons ()
()
(:panes
(pointer-documentation-pane
(make-clim-stream-pane :type 'pointer-documentation-pane
:foreground +white+
:background +black+
:text-style +pointer-doc-text-style+
:scroll-bars nil
:min-height '(1 :line)
:max-height '(1 :line)
:height '(1 :line)))
(object-buttons :application
:label "VISCO Objects"
:incremental-redisplay t
:borders nil
:scroll-bars nil
:textcursor nil
:initial-cursor-visibility :inactive
:display-function #'accept-object-buttons)
(operator-buttons :application
:label "VISCO Operators"
:incremental-redisplay t
:scroll-bars nil
:textcursor nil
:initial-cursor-visibility :inactive
:display-function #'accept-choose-operator)
(option-buttons :accept-values
:label "VISCO Options"
:scroll-bars nil
:display-function
`(accept-values-pane-displayer
:displayer ,#'(lambda (frame stream)
(accept-option-buttons
frame stream)))))
(:layouts
(:default
(vertically ()
#+:mcl
(mcl-pane pointer-documentation-pane)
#+:allegro
pointer-documentation-pane
#+:mcl
(vertically ()
(7/14 (mcl-pane object-buttons))
(3/14 (mcl-pane operator-buttons))
(4/14 (mcl-pane option-buttons)))
#+:allegro
(vertically ()
(7/14 object-buttons)
(3/14 operator-buttons)
(4/14 option-buttons))))))
(define-application-frame visco ()
((history :accessor history :initform nil)
(undo-stack :accessor undo-stack :initform nil)
(redo-stack :accessor redo-stack :initform nil)
(current-focus :accessor current-focus :initform nil)
(current-query :accessor current-query :initform (make-visco-gui-query))
(current-transparency :accessor current-transparency :initform nil))
(:command-table (visco
:inherit-from (file-table query-table)
:menu (("File" :menu file-table)
("Control" :menu control-table)
("Operators" :menu operator-table)
("Query" :menu query-table))))
(:panes
(display :application
:label "VISCO Query"
:scroll-bars nil
:end-of-line-action :allow
:end-of-page-action :allow
:textcursor nil
:incremental-redisplay t
:display-function #'draw-display)
(infos :application
:label "VISCO Infos"
:end-of-line-action :allow
:text-style +info-text-style+
:scroll-bars :both)
(control :application
:incremental-redisplay t
:label "VISCO Control"
:scroll-bars :both
:end-of-line-action :allow
:display-function #'accept-control-buttons)
(command :interactor
:label nil
:text-style +command-listener-text-style+
:scroll-bars :vertical
:min-height '(4 :line)
:max-height '(4 :line)
:height '(4 :line))
(pointer-documentation-pane
(make-clim-stream-pane :type 'pointer-documentation-pane
:foreground +white+
:background +black+
:text-style +pointer-doc-text-style+
:scroll-bars nil
:min-height '(1 :line)
:max-height '(1 :line)
:height '(1 :line))))
(:layouts
(:default
#+:allegro
(vertically ()
(horizontally ()
(3/4 display)
(1/4 (vertically ()
(1/2 infos)
(1/2 control))))
command
pointer-documentation-pane)
#+:mcl
(vertically ()
(horizontally ()
(3/4 (mcl-pane display))
(1/4 (vertically ()
(1/2 (mcl-pane infos))
(1/2 (mcl-pane control)))))
(mcl-pane command)
(mcl-pane pointer-documentation-pane)))))
(defclass overview-pane
(application-pane)
())
(define-application-frame visco-inspector ()
((pages :accessor pages :initform nil)
(selected-page :accessor selected-page :initform nil)
(active-page :accessor active-page :initform nil)
(selected-query-result :accessor selected-query-result :initform nil)
(all-matches :accessor all-matches :initform nil)
(last-percent :initform nil)
(last-time :initform nil)
#+visco-demo-mode
(overview-pattern :initform nil)
)
(:panes
(query-results :application
:label
#-visco-demo-mode "VISCO Query Results"
#+visco-demo-mode nil
:initial-cursor-visibility :inactive
:display-after-commands nil
:textcusor nil
:scroll-bars nil
:display-function #'draw-query-results)
(selected-query-result :application
:label "VISCO Inspect Query Result"
:initial-cursor-visibility :inactive
:textcusor nil
:scroll-bars nil
:display-function #'draw-selected-query-result)
#+visco-demo-mode
(overview (make-pane 'overview-pane
:scroll-bars nil
:end-of-line-action :allow
:end-of-page-action :allow
:textcursor nil
:display-function #'draw-overview))
(inspector :application
:label "VISCO Compiler Infos"
:text-style +inspector-text-style+
:scroll-bars :both
:textcursor nil
:initial-cursor-visibility :inactive
:end-of-line-action :allow
:end-of-page-action :allow)
(progress-bar :application
:label nil
:borders nil
:scroll-bars nil
:textcursor nil
:initial-cursor-visibility :inactive)
(button-abort (setf +button-abort+
(make-pane 'push-button
:label "Abort Search"
:activate-callback 'abort-search)))
(button-permutations (setf +button-permutations+
(make-pane 'toggle-button
:value *permutations*
:label "Permutations"
:value-changed-callback 'button-permutations)))
(button-draw-thumbnails (setf +button-draw-thumbnails+
(make-pane 'toggle-button
:value *draw-thumbnails*
:label "Draw QRs"
:value-changed-callback 'button-draw-thumbnails)))
(button-previous (setf +button-previous+
(make-pane 'push-button
:label "<< Previous Page <<"
:activate-callback 'previous-page)))
(button-next (setf +button-next+
(make-pane 'push-button
:label ">> Next Page >>"
:activate-callback 'next-page)))
(button-delete-all-pages (setf +button-delete-all-pages+
(make-pane 'push-button
:label "Delete All Pages"
:activate-callback 'delete-all-pages)))
(button-delete-page (setf +button-delete-page+
(make-pane 'push-button
:label "Delete Page"
:activate-callback 'delete-page)))
(button-delete-selected (setf +button-delete-selected+
(make-pane 'push-button
:label "Delete Selected"
:activate-callback 'delete-selected)))
(button-delete-unselected (setf +button-delete-unselected+
(make-pane 'push-button
:label "Delete Unselected"
:activate-callback 'delete-unselected)))
(button-unselect-all (setf +button-unselect-all+
(make-pane 'push-button
:label "Unselect All"
:activate-callback 'unselect-all)))
(page-nr :application
:label nil
:borders nil
:scroll-bars nil
:textcursor nil
:initial-cursor-visibility :inactive
:display-function #'show-page-nr))
(:layouts
(:default
#+(and (not visco-demo-mode) allegro)
(vertically ()
(1/2
(horizontally ()
(1/2 (vertically ()
query-results
(15 progress-bar)
(30 (horizontally ()
(6/10 button-abort)
(2/10 button-permutations)
(2/10 button-draw-thumbnails)))
(30 (horizontally ()
(3/10 button-previous)
(3/10 button-next)
(3/10 button-unselect-all)
(1/10 page-nr)))
(30 (horizontally ()
(1/4 button-delete-page)
(1/4 button-delete-all-pages)
(1/4 button-delete-selected)
(1/4 button-delete-unselected)))))
(1/2 selected-query-result)))
(1/2 inspector))
#+(and (not visco-demo-mode) mcl) ; NOT TESTED !
(vertically ()
(1/2
(horizontally ()
(1/2 (vertically ()
query-results
progress-bar
(horizontally ()
(6/10 button-abort)
(2/10 button-permutations)
(2/10 button-draw-thumbnails))
(horizontally ()
(3/10 button-previous)
(3/10 button-next)
(3/10 button-unselect-all)
(1/10 page-nr))
(horizontally ()
(1/4 button-delete-page)
(1/4 button-delete-all-pages)
(1/4 button-delete-selected)
(1/4 button-delete-unselected))))
(1/2 selected-query-result)))
(1/2 inspector))
#+(and visco-demo-mode allegro)
(horizontally ()
(1/2 (labelling (:label "VISCO Query Results")
(vertically ()
(15 progress-bar)
(30 button-abort)
(30 (horizontally ()
(1/2 button-previous)
(1/2 button-next)))
(30 page-nr)
query-results
(30 (horizontally ()
(1/2 button-delete-page)
(1/2 button-delete-all-pages)))
(30 (horizontally ()
(1/3 button-unselect-all)
(1/3 button-delete-selected)
(1/3 button-delete-unselected)))
(30 (horizontally ()
(1/2 button-permutations)
(1/2 button-draw-thumbnails))))))
(1/2
(vertically ()
(1/2 selected-query-result)
(1/2 (outlining ()
(labelling (:label "VISCO Map Overview")
overview))))))
#+(and visco-demo-mode mcl)
(horizontally ()
(1/2 (vertically ()
(outlining ()
(labelling (:label "VISCO Query Results")
(vertically ()
(15 progress-bar)
button-abort
(horizontally ()
(1/2 button-previous)
(1/2 button-next))
(15 page-nr))))
(outlining () query-results)
(outlining ()
(vertically ()
(horizontally ()
(1/2 button-delete-page)
(1/2 button-delete-all-pages))
(horizontally ()
(1/3 button-unselect-all)
(1/3 button-delete-selected)
(1/3 button-delete-unselected))
(horizontally ()
(1/2 button-permutations)
(1/2 button-draw-thumbnails))))))
(1/2
(vertically ()
(1/2 (outlining () selected-query-result))
(1/2 (outlining ()
(labelling (:label "VISCO Map Overview")
overview)))))))))
;;;
;;;
;;;
(defun get-current-query ()
(with-visco-frame (visco)
(and visco (current-query visco))))
(defun get-current-transparency ()
(with-visco-frame (visco)
(and visco (current-transparency visco))))
(defmethod set-current-transparency-to ((obj gui-transparency))
(with-visco-frame (visco)
(setf (current-transparency visco) obj)))
(defmethod set-current-transparency-to ((obj null))
(with-visco-frame (visco)
(setf (current-transparency visco) nil)))
(defun set-current-focus-to-newest-history-entry ()
(with-visco-frame (visco)
(let ((he (get-latest-history-entry)))
(when he
(setf (current-focus visco) he)))))
(defun current-focus-on-newest-history-entry-p ()
(with-visco-frame (visco)
(let ((he (get-latest-history-entry)))
(eq (current-focus visco) he))))
(defmethod set-current-focus-to ((obj history-entry))
(with-visco-frame (visco)
(setf (current-focus visco) obj)))
(defmethod set-current-focus-to ((obj null))
(with-visco-frame (visco)
(setf (current-focus visco) nil)))
(defun get-latest-history-entry ()
(with-visco-frame (visco)
(first (last (remove-if-not #'(lambda (he)
(typep he 'visually-relevant-history-entry))
(history visco))))))
;;;
;;;
;;;
(defmethod current-transparency-is-transparency-p ((transparency gui-transparency))
(with-visco-frame (visco)
(eq (current-transparency visco) transparency)))
(defun set-current-transparency-to-newest-transparency ()
(with-visco-frame (visco)
(setf (current-transparency visco)
(find-if #'(lambda (obj)
(typep obj
'gui-transparency))
(visco-objects (current-query visco))
:from-end t))))
(defun get-youngest-object (objects)
(when objects
(find-named-visco-object
(apply #'min (mapcar #'name objects)))))
(defun get-youngest-object-older-than (objects object)
(when objects
(dolist (obj objects)
(unless (minusp (- (name obj) (name object)))
(return obj)))))
(defmethod get-history-entry-before ((entry history-entry))
(with-visco-frame (visco)
(let ((pos (position entry (history visco))))
(when (and pos (not (zerop pos)))
(nth (1- pos) (history visco))))))
;;;
;;;
;;;
#+:allegro
(progn
(define-gesture-name :create :pointer-button :left)
(define-gesture-name :apply-operator :pointer-button (:control :left))
(define-gesture-name :delete :pointer-button :middle)
(define-gesture-name :move :pointer-button (:shift :left))
(define-gesture-name :set-focus :pointer-button (:shift :middle))
(define-gesture-name :set-transparency :pointer-button (:control :middle))
(define-gesture-name :switch-button-off :pointer-button (:middle)))
#+:mcl
(progn
(define-gesture-name :create :pointer-button :left)
(define-gesture-name :apply-operator :pointer-button (:control :left))
(define-gesture-name :delete :pointer-button (:meta :left))
(define-gesture-name :move :pointer-button (:shift :left))
; (define-gesture-name :set-focus :pointer-button (:shift :middle))
; (define-gesture-name :set-transparency :pointer-button (:control :middle))
(define-gesture-name :switch-button-off :pointer-button (:shift :left)))
;;;
;;;
;;;
(defvar *frame-standard-output* nil)
(defmethod frame-standard-input ((frame visco))
(get-frame-pane frame 'command))
(defmethod frame-standard-output ((frame visco))
(or *frame-standard-output*
(get-frame-pane frame 'infos)))
(defmethod frame-error-output ((frame visco))
(get-frame-pane frame 'infos))
;;;
;;;
;;;
#+:allegro
(define-presentation-translator my-testing-command->command-translator
(command command visco :tester ((object frame) (command-enabled (first object) frame)))
(object)
object)
(defmethod run-frame-top-level :before ((frame visco-buttons) &key)
(mapc #'release-dummy *dummies*)
(initialize-object-buttons)
(initialize-status-buttons)
(initialize-operator-buttons))
#+:allegro
(defmethod run-frame-top-level :before ((frame visco) &key)
(generate-name-for-undo-and-redo-command)
(let ((translators (find-presentation-translators 'command 'command 'visco)))
(delete (second translators) translators)))
(defmethod run-frame-top-level :before ((frame visco-inspector) &key)
(lock-buttons)
(deactivate-gadget +button-abort+))
;;;
;;;
;;;
(defun draw-display (frame stream)
(let ((history (history frame)))
(let* ((current-focus (current-focus frame))
(focus-visco-object
(when (typep current-focus 'constructor-history-entry)
(object-to-draw current-focus))))
(loop
(let* ((history-entry (pop history)))
(if history-entry
(when (typep history-entry 'visually-relevant-history-entry)
(let* ((obj (object-to-draw history-entry))
(focus-p
(eq history-entry current-focus))
(current-transparency-p
(and (typep obj 'gui-transparency)
(current-transparency-is-transparency-p obj))))
(if (and focus-visco-object
(not focus-p)
(typep focus-visco-object 'constraints-mixin)
(typep obj 'constraints-mixin))
(let ((constraint
(dolist (cs-type *visualized-relations* nil)
(when (=> (or (eq cs-type 'intersects)
(eq cs-type 'disjoint))
(and (=> (typep focus-visco-object '(or point line))
(not (ignore-disjoint-and-intersects-relations-p focus-visco-object)))
(=> (typep obj '(or point line))
(not (ignore-disjoint-and-intersects-relations-p obj)))))
(let ((look-for (case cs-type
(inside/contains '(inside contains))
(otherwise (list cs-type)))))
(when (dolist (cs-type look-for nil)
(when (find-constraint cs-type focus-visco-object obj)
(return t)))
(return cs-type)))))))
(updating-output (stream :unique-id history-entry
:cache-value (list (tick obj)
focus-p
current-transparency-p
constraint)
:cache-test #'equal)
(if constraint
(draw obj stream
:border-for constraint
:subobjects-draw-only-gravity-field t)
(draw obj stream
:subobjects-draw-only-gravity-field t))))
(updating-output (stream :unique-id history-entry
:cache-value (list (tick obj)
focus-p
current-transparency-p)
:cache-test #'equal)
(draw obj stream
:subobjects-draw-only-gravity-field t
:border-for (when (and focus-p
*focus-box*)
'focus))))
(setf (already-drawn obj) t)
(when focus-p
(return))))
(return))))
(dolist (he (history frame))
(when (typep he 'visually-relevant-history-entry)
(setf (already-drawn (object-to-draw he)) nil))))))
;;;
;;;
;;;
(defun redraw-buttons ()
(with-visco-buttons-frame (buttons)
(redisplay-frame-pane buttons (get-frame-pane buttons 'object-buttons))
(update-operator-button)))
;;;
;;;
;;;
(defvar *visco-process* nil)
(defvar *visco-buttons-process* nil)
(defvar *visco-inspector-process* nil)
(defun kill-visco-processes ()
(progn
(when *visco-process*
(#+:allegro mp:process-kill #+:mcl ccl:process-kill *visco-process*))
(when *visco-inspector-process*
(#+:allegro mp:process-kill #+:mcl ccl:process-kill *visco-inspector-process*))
(when *visco-buttons-process*
(#+:allegro mp:process-kill #+:mcl ccl:process-kill *visco-buttons-process*))))
(defun visco ()
(let ((port (find-port)))
#+:allegro
(setf (clim:text-style-mapping port
+visco-text-style+)
"-*-lucida-medium-r-normal-*-12-*-*-*-*-*-*-*")
(multiple-value-bind (width height)
(bounding-rectangle-size
(sheet-region (find-graft :port port)))
(kill-visco-processes)
(setf *visco-process*
(#+:allegro mp:process-run-function
#+:mcl ccl:process-run-function
"Visco"
#'(lambda ()
(setf *visco-frame*
(make-application-frame
'visco
:pretty-name "VISCO"
:left 10
:top 20
:width (- width 230)
:height (- height 30)))
(run-frame-top-level *visco-frame*))))
(setf *visco-inspector-process*
(#+:allegro mp:process-run-function
#+:mcl ccl:process-run-function
"Visco Inspector"
#'(lambda ()
#+(and (not visco-demo-mode) allegro)
(setf *visco-inspector-frame*
(make-application-frame
'visco-inspector
:pretty-name "VISCO Inspector"
:left 10
:top 10
:width (- width 250)
:height 820))
#+(and visco-demo-mode allegro)
(setf *visco-inspector-frame*
(make-application-frame
'visco-inspector
:width width
:height height
:pretty-name "VISCO Inspector"))
#+(and visco-demo-mode mcl)
(setf *visco-inspector-frame*
(make-application-frame
'visco-inspector
:left 10
:top 20
:width (- width 20)
:height (- height 30)
:pretty-name "VISCO Inspector"))
(run-frame-top-level *visco-inspector-frame*))))
(setf *visco-buttons-process*
(#+:allegro mp:process-run-function
#+:mcl ccl:process-run-function
"Visco Buttons"
#'(lambda ()
(setf *visco-buttons-frame*
(make-application-frame
'visco-buttons
:pretty-name "VISCO Buttons"
:left (- width 210)
:top 20
:width 200
:height (- height 30)))
(run-frame-top-level *visco-buttons-frame*)))))))
| 21,132 | Common Lisp | .lisp | 643 | 26.832037 | 91 | 0.644125 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 8e5a13f7f7fbba810123dbc9e771f9f8dc3e2588743180d5f32f1608b882b740 | 11,716 | [
-1
] |
11,717 | other-commands2.lisp | lambdamikel_VISCO/src/GUI/other-commands2.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
#+:allegro
(define-visco-command (com-print-query :name "Print Query")
()
(with-open-stream
(pipe (excl:run-shell-command (format nil "lpr -P~A -h" '|r131_hp|)
:input :stream :wait nil))
(with-output-to-postscript-stream (stream pipe
:orientation :landscape
:scale-to-fit t)
(dolist (obj (visco-objects (get-current-query)))
(draw obj stream)))))
#+:allegro
(defmethod command-enabled ((obj (eql 'com-print-query)) (frame visco))
(with-visco-frame (visco)
(and visco
(visco-objects (current-query visco)))))
;;;
;;;
;;;
(define-visco-command (com-save-query :name nil)
nil
(with-visco-frame (visco)
(let ((file (file-selector "Save Query" "visco:queries;" "vis" :save t)))
(when file
(with-slots (history undo-stack current-focus
current-query current-transparency) visco
(make-object-persistent (list history undo-stack current-focus
current-query current-transparency
(get-button-state))
file))))))
(defmethod command-enabled ((obj (eql 'com-save-query)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(with-visco-frame (visco)
(and visco
(visco-objects (current-query visco)))))
(define-visco-command (com-load-query :name nil)
nil
(with-visco-frame (visco)
(let ((file (file-selector "Load Query" "visco:queries;" "vis")))
(when file
(with-slots (history undo-stack current-focus
current-query current-transparency) visco
(let ((result
(load-persistent-object file)))
(setf history (first result)
undo-stack (second result)
current-focus (third result)
current-query (fourth result)
current-transparency (fifth result))
(install-button-state (sixth result))
(refresh)))))))
(define-visco-command (com-quit :name "Quit")
()
(with-visco-frame (visco)
(let ((yes-or-no (notify-user visco
"Quit selected! Are you sure?"
:style :question)))
(when yes-or-no
(kill-visco-processes)))))
;;;
;;;
;;;
(define-visco-command (com-execute-query :name "Execute Query")
()
(with-visco-inspector-frame (inspector)
(handler-case
#+visco-demo-mode
(let (#+:MCL (ccl::*suppress-compiler-warnings* t))
(compile-query (get-current-query)
:infos nil
:debug nil
:check-for-abort t))
#-visco-demo-mode
(let* ((*standard-output*
(get-frame-pane inspector 'inspector))
(*error-output* *standard-output*)
(*print-case* :downcase))
(window-clear *standard-output*)
(with-output-as-presentation (*standard-output* nil 'null)
(compile-query (get-current-query)
:debug nil
:check-for-abort t)))
(error (error)
(format t "~%*** ERROR ***~%Can't Compile: Bad Query!~%")
(error error) ; remove this in the final version !!!
(beep))
(:no-error (res)
(declare (ignore res))
(make-new-page)
(setf (all-matches inspector) nil)
(lock-buttons)
(activate-gadget +button-abort+)
(execute-query (get-current-query))
(deactivate-gadget +button-abort+)
(unlock-buttons)))))
(defmethod command-enabled ((obj (eql 'com-execute-query)) (frame visco)
#+:mcl &optional #+:mcl unused)
#+:mcl (declare (ignore unused))
(with-visco-frame (visco)
(and visco
(visco-objects (current-query visco))
(get-current-db))))
;;;
;;;
;;;
(define-visco-command (com-get-query-semantics :name "Get Query Semantics")
()
(with-visco-inspector-frame (inspector)
(handler-case
#+visco-demo-mode
(pprint (prog1 (get-query-semantics (get-current-query))
(terpri) (terpri)))
#-visco-demo-mode
(let* ((*standard-output*
(get-frame-pane inspector 'inspector))
(*error-output* *standard-output*)
(*print-case* :downcase)
(*package* (find-package 'query-compiler))
(*print-case* :downcase))
(window-clear *standard-output*)
(with-output-as-presentation (*standard-output* nil 'null)
(pprint (prog1 (get-query-semantics (get-current-query))
(terpri) (terpri)))))
(error ()
(format t "~%*** ERROR ***~%No Semantics: Bad Query!~%")
(beep)))))
;;;
;;;
;;;
(define-command-table file-table
:menu (("Load Query" :command (com-load-query))
("Save Query" :command (com-save-query))
#+:allegro ("divide1" :divider nil)
#+:allegro ("Print Query" :command (com-print-query))
("divide2" :divider nil)
("Quit" :command (com-quit))))
(define-command-table query-table
:menu (("Execute Query" :command (com-execute-query))
("Get Query Semantics" :command (com-get-query-semantics))))
;;;
;;;
;;;
(define-visco-command (refresh :name "Refresh")
()
(with-visco-frame (visco)
(set-object-modes)
(redisplay-frame-pane visco 'display :force-p t)))
(defun ready ()
(show-search-progress 1 :force-p t)
(make-query-result))
| 5,455 | Common Lisp | .lisp | 153 | 28.091503 | 77 | 0.593632 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 36de2ab2de7349b6f50a14fb6dcb3d67086936c329c7e8a7034242a56edfd15a | 11,717 | [
-1
] |
11,718 | operator-buttons6.lisp | lambdamikel_VISCO/src/GUI/operator-buttons6.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
(defconstant +ink-arg-object+ +black+)
(defconstant +ink-res-object+ +red+)
(defconstant +operator-button-text-style+
(make-text-style
:sans-serif nil :very-small))
(defclass operator-button (button)
((draw-function :accessor draw-function
:initform #'(lambda (button stream cell-size)
(declare (ignore button stream cell-size))
nil)
:initarg :draw-function)
(redraw-when :accessor redraw-when :initform #'no :initarg :redraw-when)
(command :accessor command :initform nil :initarg :command)
(scale-fac :accessor scale-fac :initarg :scale-fac :initform 0.8)
(when-selected :initform #'choose-operator)))
;;;
;;;
;;;
(defmethod initialize-instance :after ((obj operator-button) &rest initargs)
(declare (ignore initargs))
(pushend obj *operator-buttons*))
(defun make-operator-button (draw-function &rest args)
(apply #'make-instance 'operator-button :draw-function draw-function args))
(defun initialize-operator-buttons ()
(switch-off *operator-buttons*)
(setf *operator-mode* *button-no-operator*))
(defmethod output-draw-button ((button operator-button) stream cell-size)
(let ((tester (funcall (tester button) button)))
(when (and (on button) (not tester))
(switch-off button)
(setf *operator-mode* nil))
(updating-output (stream
:cache-value (list button
(on button)
(funcall (redraw-when button) button))
:cache-test #'equal)
(with-output-as-presentation
(stream button 'operator-button
:single-box t
:allow-sensitive-inferiors nil)
(draw-button button stream cell-size)))))
(defmethod underlabel-button ((button operator-button) stream cell-size)
(let ((half-cell-size (/ cell-size 2)))
(with-output-as-presentation
(stream button 'operator-button
:single-box t
:allow-sensitive-inferiors nil)
(with-drawing-options (stream
:text-style
+operator-button-text-style+)
(let ((doc (if (stringp (doc button))
(list (doc button))
(doc button)))
(y-off 10))
(dolist (line doc)
(draw-text* stream line
(- half-cell-size)
(- (- half-cell-size) y-off))
(incf y-off 7)))))))
(defmethod draw-button ((button operator-button) stream cell-size)
(with-scaling (stream (scale-fac button))
(funcall (draw-function button) button stream cell-size)))
(defun choose-operator (current-button)
(declare (ignore current-button))
(with-visco-buttons-frame (buttons)
(with-visco-frame (visco)
(let ((res-op (menu-choose (mapcar #'(lambda (button)
(list button
:documentation (first (doc button))
:active (command-enabled (command button) visco)))
(remove *button-no-operator*
*operator-buttons*))
:n-columns 3
:pointer-documentation (get-frame-pane buttons 'pointer-documentation-pane)
:printer
#'(lambda (item stream)
(let ((button (first item)))
(formatting-table (stream)
(formatting-column (stream)
(formatting-cell (stream)
(with-scaling (stream 1 -1)
(with-output-as-presentation (stream button
(type-of button)
:single-box t
:allow-sensitive-inferiors nil)
(draw-button button stream 50))))
(formatting-cell (stream :align-x :center)
(with-drawing-options (stream
:text-style
+operator-button-text-style+)
(draw-text* stream (second (doc button)) 0 0))))))))))
(when res-op
(switch-off *operator-buttons*)
(switch-on res-op)
(setf *operator-mode* res-op))))))
(defun accept-choose-operator (frame stream)
(multiple-value-bind (w h)
(window-inside-size stream)
(terpri stream)
(with-centering (stream)
(accept-buttons (list *operator-mode*)
1 1 frame stream
:width (- w (/ w 3))
:height (- h (/ h 3))))))
(defun update-operator-button ()
(with-visco-frame (visco)
(with-visco-buttons-frame (visco-buttons)
(when (not (eq *operator-mode* *button-no-operator*))
(setf (on *operator-mode*)
(command-enabled (command *operator-mode*) visco))
(redisplay-frame-pane visco-buttons 'operator-buttons)))))
;;;
;;;
;;;
(let ((text-style
(parse-text-style '(:sans-serif nil :huge))))
(defparameter *button-no-operator*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button cell-size))
(with-drawing-options (stream
:text-style
text-style)
(draw-circle* stream 0 0 20 :filled nil)
(draw-circle* stream 0 0 15 :filled nil)
(draw-text* stream "?"
-5 -9)))
:tester #'yes
:doc '("No Operator Selected"))))
(defparameter *button-create-centroid*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button))
(let ((hcs (/ cell-size 2)))
(draw-rectangle* stream
(- hcs) (- hcs)
hcs hcs
:ink +ink-arg-object+
:filled nil))
(when *point-mode*
(draw *point-mode* stream
:ink +ink-res-object+
:label-x 0
:label-y -20)))
:redraw-when #'(lambda (button)
(declare (ignore button))
(list *point-mode*
*point-status*))
:command 'com-create-centroid
:doc `("Create Centroid" "S, Chain, Poly")))
(defparameter *button-create-intersection-point*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button))
(let ((hcs (/ cell-size 2)))
(draw-line* stream
(- hcs) (- hcs)
hcs hcs
:ink +ink-arg-object+)
(draw-line* stream
(- hcs) hcs
hcs (- hcs)
:ink +ink-arg-object+))
(when *point-mode*
(draw *point-mode* stream
:ink +ink-res-object+
:label-x 0
:label-y -20)))
:redraw-when #'(lambda (button)
(declare (ignore button))
(list *point-mode*
*point-status*))
:command 'com-create-intersection-point
:doc '("Create Intersection Point" "S x S")))
(let* ((outer-enclosure
(make-instance 'gui-outer-enclosure
:drawable-pointlist
(get-negated-drawable-pointlist
(get-drawable-pointlist-for (get-expanded-polygon (icon *button-polygon*) 4))
-32 -32 32 32)
:dont-initialize t)))
(defparameter *button-create-inverse-drawn-enclosure*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button))
(let ((a (/ cell-size 2)))
(draw (icon *button-drawn-enclosure*) stream
:ink
(if *opaque-enclosures-p*
+ink-res-object+
(make-grid-in +ink-res-object+)))
(draw outer-enclosure stream :ink +ink-arg-object+)
(draw-arrow* stream (- a) (- a) -4 -4 :ink +white+)
(draw-arrow* stream a a 4 4 :ink +white+)))
:scale-fac 0.7
:redraw-when #'(lambda (button)
(declare (ignore button))
(list *opaque-enclosures-p*))
:command 'com-create-inverse-drawn-enclosure
:doc '("Create Inverse Constant Enclosure" "E"))))
(let* ((polygon (icon *button-polygon*))
(inner-enclosure
(make-instance 'gui-inner-enclosure :arg-object polygon
:drawable-pointlist
(get-drawable-pointlist-for (get-shrinked-polygon (icon *button-polygon*) 4))
:dont-initialize t))
(outer-enclosure
(make-instance 'gui-outer-enclosure :arg-object polygon
:drawable-pointlist
(get-negated-drawable-pointlist
(get-drawable-pointlist-for (get-expanded-polygon (icon *button-polygon*) 4))
-32 -32 32 32)
:dont-initialize t)))
(defparameter *button-create-inner-enclosure*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button cell-size))
(draw polygon stream
:ink +ink-arg-object+
:gravity-field nil
:draw-component-objects nil
:draw-label nil)
(draw inner-enclosure stream
:ink
(if *opaque-enclosures-p*
+ink-res-object+
(make-grid-in +ink-res-object+))))
:redraw-when #'(lambda (button)
(declare (ignore button))
(list *opaque-enclosures-p*))
:command 'com-create-inner-enclosure
:doc '("Create Inner Enclosure" "Poly")))
(defparameter *button-create-outer-enclosure*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button cell-size))
(draw polygon stream
:ink +ink-arg-object+
:gravity-field nil
:draw-component-objects nil
:draw-label nil)
(draw outer-enclosure stream
:ink
(if *opaque-enclosures-p*
+ink-res-object+
(make-grid-in +ink-res-object+))))
:redraw-when #'(lambda (button)
(declare (ignore button))
(list *opaque-enclosures-p*))
:scale-fac 0.7
:command 'com-create-outer-enclosure
:doc '("Create Outer Enclosure" "Poly"))))
(let* ((line
(make-instance 'gui-beam
:p1 (p -25 -25)
:p2 (p 25 25)
:dont-initialize t))
(epsilon-enclosure (make-instance 'gui-epsilon-enclosure
:arg-object line
:radius 10
:dont-initialize t)))
(defparameter *button-create-epsilon-enclosure*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button cell-size))
(draw epsilon-enclosure stream
:ink
(if *opaque-enclosures-p*
+ink-res-object+
(make-grid-in +ink-res-object+)))
(draw line stream
:ink +ink-arg-object+
:gravity-field nil
:draw-component-objects nil
:draw-label nil))
:redraw-when #'(lambda (button)
(declare (ignore button))
(list *opaque-enclosures-p*))
:scale-fac 0.6
:command 'com-create-epsilon-enclosure
:doc '("Create Epsilon Enclosure" "P, S, Chain, Poly"))))
#|
(let ((text-style
(parse-text-style '(:sans-serif nil :huge))))
(defparameter *button-recreate*
(make-operator-button #'(lambda (button stream cell-size)
(draw-circle* stream 0 0 20 :filled nil)
(draw-circle* stream 0 0 15 :filled nil)
(draw-label* '("!") -3 -7 stream
:label-text-style text-style))
:scale-fac 1.0
:command 'com-recreate
:doc "Recreate")))
|#
;;;
;;;
;;;
(let ((text-style
(parse-text-style '(:sans-serif nil :large))))
(defparameter *button-set-semantics*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button))
(let ((hcs (/ cell-size 2)))
(draw-polygon* stream
(list -20 -12 -15 -5 10 4 15 18)
:filled nil
:closed nil
:ink +ink-arg-object+)
(draw-text* stream "River"
(- hcs) (- hcs)
:ink +ink-res-object+
:text-style text-style)))
:command 'com-set-semantics
:doc '("Set Semantics" "P, S, Chain, Poly"))))
(let ((text-style
(parse-text-style '(:sans-serif nil :huge))))
(defparameter *button-set-at-most-constraint*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button))
(let ((hcs (/ cell-size 2)))
(draw-text* stream "3"
-5 -10
:ink +ink-res-object+
:text-style text-style)
(draw-line* stream (- hcs) (- hcs) hcs hcs
:ink +ink-arg-object+)))
:command 'com-set-at-most-constraint
:doc '("Set At Most Constraint" "R, Chain, Poly"))))
(let ((arrow (make-instance 'gui-orientation-arrow
:alpha-off (- +pi/2+ (/ pi 4))
:dont-initialize t
:object (make-instance 'gui-beam :dont-initialize t
:p1 (p -25 -25)
:p2 (p 25 25)
:orientation-constraint (list 0)))))
(defparameter *button-set-orientation-constraint*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button))
(let ((hcs (/ cell-size 2)))
(setf (r arrow) hcs)
(draw arrow stream :ink +ink-res-object+)
(draw-line* stream (- hcs) (- hcs) hcs hcs
:ink +ink-arg-object+)))
:command 'com-set-orientation-constraint
:doc '("Set Orientation Constraint" "O, B, AR"))))
(let ((arrow (make-instance 'gui-orientation-arrow
:r 20
:dont-initialize t
:alpha-off (- +pi/2+ (/ pi 4))
:object (make-instance 'gui-beam :dont-initialize t
:p1 (p -25 -25)
:p2 (p 25 25)
:orientation-constraint (list 0 0.0001))))) ; 0.0001 = Trick
(defparameter *button-create-orientation-constraint-mark*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button cell-size))
(draw arrow stream :ink +ink-arg-object+)
(draw-circle* stream 20 0 +bullet-size+ :ink +ink-res-object+)
(draw-circle* stream -20 0 +bullet-size+ :ink +ink-res-object+))
:command 'com-set-orientation-constraint-mark
:doc '("Set Orientation Constraint Mark" "OC")))
(defparameter *button-create-orientation-constraint-intervall*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button cell-size))
(draw arrow stream :ink +ink-arg-object+)
(draw-circle* stream 0 0 23
:start-angle (- pi (* 1/8 pi))
:end-angle (+ pi (* 1/8 pi))
:ink +ink-res-object+
:filled nil)
(draw-circle* stream 0 0 23
:start-angle (- +2pi+ (* 1/8 pi))
:end-angle (+ +2pi+ (* 1/8 pi))
:ink +ink-res-object+
:filled nil))
:command 'com-set-orientation-constraint-intervall
:doc '("Set Orientation Constraint Intervall" "OC"))))
(let ((circle (make-instance 'gui-relative-orientation-circle
:r 20
:dont-initialize t
:allowed-derivation 0
:object1 (l (p (- 10) (- 10)) (p 10 10))
:object2 (l (p (- 10) 10) (p 10 (- 10))))))
(defparameter *button-create-relative-orientation-constraint*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button))
(let ((hcs (/ cell-size 2)))
(draw-line* stream (- hcs) (- hcs) hcs hcs :ink +ink-arg-object+)
(draw-line* stream (- hcs) hcs hcs (- hcs) :ink +ink-arg-object+)
(draw circle stream :ink +ink-res-object+)))
:command 'com-set-relative-orientation-constraint
:doc '("Set Rel. Orient. Constraint" "(B / AR) x (B / AR)"))))
(defparameter *button-set-transparency-properties*
(make-operator-button #'(lambda (button stream cell-size)
(declare (ignore button))
(let ((hcs (/ cell-size 2)))
(draw-rectangle* stream
(- hcs) (- hcs) hcs hcs
:filled nil
:ink +ink-arg-object+)
(draw-text* stream
"100 m." (+ 5 (- hcs)) 0
:ink +ink-res-object+)))
:command 'com-set-transparency-properties
:doc '("Set Transparency Properties" "T")))
| 15,337 | Common Lisp | .lisp | 400 | 30.59 | 115 | 0.604102 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | d44337ff7a0a1b803476d3860f7061b723c80f9bf3b8a5c521c2641108fd43a5 | 11,718 | [
-1
] |
11,719 | status-buttons7.lisp | lambdamikel_VISCO/src/GUI/status-buttons7.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
(defvar *last-pushed-button* nil)
(defclass status-button (text-button)
())
;;;
;;;
;;;
(defvar +legal-combinations+ nil)
(defmethod initialize-instance :after ((obj status-button) &rest initargs)
(declare (ignore initargs))
(push obj *status-buttons*))
(defun initialize-status-buttons ()
(switch-off *status-buttons*)
(activate *status-buttons*)
(setf *point-status* nil
*segment-status* nil
*chain-or-polygon-status* nil))
(defun make-status-button (text &rest args)
(apply #'make-instance 'status-button :text text args))
;;;
;;;
;;;
(defun point-status-selected (button)
(switch-on button)
(setf *point-status* (id button))
(select-legal-combination button))
(defun segment-status-selected (button)
(switch-on button)
(setf *segment-status* (id button))
(select-legal-combination button))
(defun chain-or-polygon-status-selected (button)
(switch-on button)
(setf *chain-or-polygon-status* (id button))
(select-legal-combination button))
;;;
;;;
;;;
(defun point-status-tester (button)
(let ((res
(let ((*point-status*
(id button)))
(find-next-combination button))))
(and res
(not (equal (list *point-status*
*segment-status*
*chain-or-polygon-status*)
res)))))
(defun segment-status-tester (button)
(let ((res
(let ((*segment-status*
(id button)))
(find-next-combination button))))
(and res
(not (equal (list *point-status*
*segment-status*
*chain-or-polygon-status*)
res)))))
(defun chain-or-polygon-status-tester (button)
(let ((res
(let ((*chain-or-polygon-status*
(id button)))
(find-next-combination button))))
(and res
(not (equal (list *point-status*
*segment-status*
*chain-or-polygon-status*)
res)))))
;;;
;;;
;;;
(defun smaller-p (a b)
(case b
(universe t)
(db (eq a 'db-component))
(db-component (eq a 'db-component))))
(defun legal-combination-p ()
(and (=> *segment-status*
(=> *point-status* (smaller-p *point-status* *segment-status*)))
(=> *chain-or-polygon-status*
(and (=> *point-status*
(smaller-p *point-status* *chain-or-polygon-status*))
(=> *segment-status*
(smaller-p *segment-status* *chain-or-polygon-status*))))))
(defun select-legal-combination (button)
(let ((same-button-pushed-twice
(eq *last-pushed-button* button)))
(if (and (not same-button-pushed-twice)
(legal-combination-p))
(select-current-combination)
(select-combination
(find-next-combination button
:keep-as-much-as-possible-p
(not same-button-pushed-twice))))
(setf *last-pushed-button* button)))
(defun select-current-combination ()
(select-combination (list *point-status*
*segment-status*
*chain-or-polygon-status*)))
(defun select-combination (comb)
(dolist (button *status-buttons*)
(switch-off button))
(setf *point-status* (first comb)
*segment-status* (second comb)
*chain-or-polygon-status* (third comb))
(dolist (button (list *button-origin* *button-nail* *button-marble*))
(setf (status (icon button)) *point-status*))
(dolist (button (list *button-rubberband* *button-beam*
*button-atomic-rubberband* *button-atomic-<=-rubberband*
*button-atomic->=-rubberband*))
(setf (status (icon button)) *segment-status*))
(dolist (button (list *button-chain* *button-polygon*))
(setf (status (icon button)) *chain-or-polygon-status*))
(mapc #'(lambda (status-var buttons)
(when status-var
(dolist (button buttons)
(when (eq (id button) status-var)
(switch-on button)))))
(list *point-status*
*segment-status*
*chain-or-polygon-status*)
(list *point-buttons*
*segment-buttons*
*chain-or-polygon-buttons*))
(set-object-modes))
(defun find-next-combination (button &key keep-as-much-as-possible-p)
(let* ((res
(loop as comb in +legal-combinations+
when (cond ((member button *point-buttons*)
(eq (first comb)
*point-status*))
((member button *segment-buttons*)
(eq (second comb)
*segment-status*))
((member button *chain-or-polygon-buttons*)
(eq (third comb)
*chain-or-polygon-status*)))
collect comb))
(pos (position (list *point-status*
*segment-status*
*chain-or-polygon-status*)
res
:test #'equal))
(res2 (if pos
(if keep-as-much-as-possible-p
(list (nth pos res))
(circle-subseq res (1+ pos) (+ 3 pos)))
res)))
(values (first res2)
(rest res2))))
;;;
;;;
;;;
(defparameter *button-point-status-db*
(make-status-button "DB"
:id 'db
:tester #'point-status-tester
:when-selected #'point-status-selected
:doc "Primary DB Point"))
(defparameter *button-segment-status-db*
(make-status-button "DB"
:id 'db
:tester #'segment-status-tester
:when-selected #'segment-status-selected
:doc "Primary DB Segment"))
(defparameter *button-chain-or-polygon-status-db*
(make-status-button "DB"
:id 'db
:tester #'chain-or-polygon-status-tester
:when-selected #'chain-or-polygon-status-selected
:doc "Primary DB Chain / Polygon"))
(defparameter *button-point-status-db-component*
(make-status-button "DB-C"
:id 'db-component
:tester #'point-status-tester
:when-selected #'point-status-selected
:doc "DB Point"))
(defparameter *button-segment-status-db-component*
(make-status-button "DB-C"
:id 'db-component
:tester #'segment-status-tester
:when-selected #'segment-status-selected
:doc "DB Segment"))
(defparameter *button-chain-or-polygon-status-db-component*
(make-status-button "DB-C"
:id 'db-component
:tester #'chain-or-polygon-status-tester
:when-selected #'chain-or-polygon-status-selected
:doc "DB Chain / Polygon"))
(defparameter *button-point-status-universe*
(make-status-button "U"
:id 'universe
:tester #'point-status-tester
:when-selected #'point-status-selected
:doc "UNIVERSE Points"))
(defparameter *button-segment-status-universe*
(make-status-button "U"
:id 'universe
:tester #'segment-status-tester
:when-selected #'segment-status-selected
:doc "UNIVERSE Segment"))
(defparameter *button-chain-or-polygon-status-universe*
(make-status-button "U"
:id 'universe
:tester #'chain-or-polygon-status-tester
:when-selected #'chain-or-polygon-status-selected
:doc "UNIVERSE Chain / Polygon"))
;;;
;;;
;;;
(defparameter *point-buttons* (list *button-point-status-db*
*button-point-status-db-component*
*button-point-status-universe*))
(defparameter *segment-buttons* (list *button-segment-status-db*
*button-segment-status-db-component*
*button-segment-status-universe*))
(defparameter *chain-or-polygon-buttons* (list *button-chain-or-polygon-status-db*
*button-chain-or-polygon-status-db-component*
*button-chain-or-polygon-status-universe*))
;;;
;;;
;;;
(defmethod output-draw-button ((button status-button) stream cell-size)
(updating-output (stream
:cache-value (list (on button)
(deactivated button)
(funcall (tester button) button))
:cache-test #'equal)
(with-output-as-presentation
(stream button 'status-button
:single-box t
:allow-sensitive-inferiors nil)
(draw-button button stream cell-size))))
(defmethod draw-button ((button status-button) stream cell-size)
(declare (ignore cell-size))
(draw-text* stream
(text button)
-20 -10
:text-style +button-text-style+))
;;;
;;;
;;;
(define-visco-buttons-command (com-switch-off :name nil)
((object 'status-button))
(when (on object)
(cond ((member object *point-buttons*)
(setf *point-status* nil))
((member object *segment-buttons*)
(setf *segment-status* nil))
((member object *chain-or-polygon-buttons*)
(setf *chain-or-polygon-status* nil)))
(setf *last-pushed-button* nil)
(if (legal-combination-p)
(select-current-combination)
(select-legal-combination object))))
(define-presentation-to-command-translator switch-off
(status-button com-switch-off visco-buttons
:gesture :switch-button-off
:tester ((object) (on object))
:echo nil :maintain-history nil)
(object)
(list object))
;;;
;;;
;;;
(let ((status-types '(db db-component universe nil)))
(dolist (*point-status* status-types)
(dolist (*segment-status* status-types)
(dolist (*chain-or-polygon-status* status-types)
(when (legal-combination-p)
(push (list *point-status*
*segment-status*
*chain-or-polygon-status*)
+legal-combinations+))))))
| 8,797 | Common Lisp | .lisp | 274 | 27.616788 | 82 | 0.672506 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 5fe27380ecb6a0f02a7044d005c728704460951d44849518f58d9e069015d821 | 11,719 | [
-1
] |
11,720 | object-buttons5.lisp | lambdamikel_VISCO/src/GUI/object-buttons5.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
(defclass object-button (icon-button)
((tester :initform #'standard-tester)
(when-action-begins :initform #'creating-begins)
(when-action-ends :initform #'creating-ends)))
(defmethod when-selected ((button object-button))
#'(lambda (button)
(funcall (slot-value button 'when-selected) button)
(set-object-modes)))
(defmethod standard-tester ((button button))
(if (on button)
(=> (eq *primary-mode*
(icon button))
(not *creating-active*))
(valid-p button)))
;;;
;;;
;;;
(defmethod initialize-instance :after ((obj object-button) &rest initargs)
(declare (ignore initargs))
(push obj *object-buttons*)
(when (slot-exists-p (icon obj) 'status)
(setf (object (status-label (icon obj))) (icon obj))))
(defun initialize-object-buttons ()
(setf *creating-active* nil)
(switch-off *object-buttons*)
(setf (on *button-transparency*) t)
(activate *object-buttons*)
(setf *primary-mode* (icon *button-transparency*)
*point-mode* nil
*segment-mode* nil)
(dolist (button *object-buttons*)
(when (slot-exists-p (icon button) 'status)
(setf (status (icon button)) nil))))
(defmethod inform-button-action-begins :after ((button object-button))
(redraw-buttons))
(defun make-object-button (icon &rest args)
(apply #'make-instance 'object-button :icon icon args))
;;;
;;;
;;;
(defun set-object-modes ()
(labels ((get-activated-buttons (buttons)
(find-if #'(lambda (button)
(and (on button)
(not (deactivated button))
(valid-p button)))
buttons)))
(setf *point-mode*
(let ((button
(get-activated-buttons
(list *button-nail* *button-marble* *button-origin*))))
(and button (icon button))))
(setf *segment-mode*
(let ((button
(get-activated-buttons
(list *button-beam* *button-atomic-rubberband*
*button-atomic-<=-rubberband* *button-atomic->=-rubberband*
*button-rubberband*))))
(and button (icon button))))
(setf *primary-mode*
(let ((button
(get-activated-buttons
*object-buttons*)))
(and button (icon button))))
(dotimes (i 4)
(dolist (button *object-buttons*)
(when (and (on button)
(not (valid-p button)))
(switch-off button))))
(redraw-buttons)))
;;;
;;;
;;;
(defmethod line-validator ((button button))
(and (get-current-transparency)
*segment-status*))
(defmethod chain-or-polygon-validator ((button button))
(and (get-current-transparency)
*chain-or-polygon-status*))
;;;
;;;
;;;
(defun creating-begins (button)
(declare (ignore button))
(dolist (button *object-buttons*)
(when (or (and (typep *primary-mode* 'gui-point)
(not (typep (icon button) 'gui-point)))
(and (typep *primary-mode* 'gui-line)
(typep (icon button) 'gui-chain-or-polygon))
(and (typep *primary-mode* 'gui-transparency)
(not (typep (icon button) 'gui-transparency)))
(and (typep *primary-mode* 'gui-drawn-enclosure)
(not (typep (icon button) 'gui-drawn-enclosure))))
(deactivate button)))
(set-object-modes)
(setf *creating-active* t))
(defun creating-ends (button)
(when (and (=> (typep (icon button) 'gui-point)
(eq *point-mode* *primary-mode*))
(=> (typep (icon button) 'gui-line)
(eq *segment-mode* *primary-mode*)))
(activate *object-buttons*)
(setf *creating-active* nil)))
;;;
;;;
;;;
(defparameter *button-transparency*
(make-object-button
(make-instance 'gui-transparency
:segments nil
:pmin (p -15 -15)
:pmax (p 15 15)
:bounding-box-p nil
:dont-initialize t)
:valid #'(lambda (button)
(declare (ignore button))
(get-current-query))
:when-selected #'(lambda (button)
(switch-off (remove button *object-buttons*))
(toggle button))
:doc "Transparency (T)"))
;;;
;;;
;;;
(defparameter *button-origin*
(make-object-button (make-instance 'gui-origin :x 0 :y 0 :dont-initialize t)
:when-action-ends #'(lambda (button)
(creating-ends button)
(toggle button)
(toggle *button-nail*)
(set-object-modes))
:valid #'(lambda (button)
(declare (ignore button))
(let ((transparency (get-current-transparency)))
(and transparency
*point-status*
(not
(some #'(lambda (dummy)
(and (typep dummy 'gui-origin)
(eq (dummy-p dummy) 'locked)))
*dummies*))
(not (origin transparency)))))
:when-selected #'(lambda (button)
(toggle button)
(switch-off (list *button-marble*
*button-nail*
*button-transparency*
*button-drawn-enclosure*)))
:doc "Origin (O)"))
(defparameter *button-nail*
(make-object-button (make-instance 'gui-nail :x 0 :y 0 :dont-initialize t)
:valid #'(lambda (button)
(declare (ignore button))
(let ((transparency (get-current-transparency)))
(and transparency
*point-status*)))
:when-selected #'(lambda (button)
(toggle button)
(switch-off (list *button-origin*
*button-marble*
*button-transparency*
*button-drawn-enclosure*)))
:doc "Nail (N, P)"))
(defparameter *button-marble*
(make-object-button (make-instance 'gui-marble :x 0 :y 0 :dont-initialize t)
:valid #'(lambda (button)
(declare (ignore button))
(let ((transparency (get-current-transparency)))
(and transparency
*point-status*
(some #'(lambda (obj)
(typep obj 'enclosure))
(transparency-query-objects-and-enclosures transparency)))))
:when-selected #'(lambda (button)
(toggle button)
(switch-off (list *button-nail*
*button-origin*
*button-transparency*
*button-drawn-enclosure*)))
:doc "Marble (M, P)"))
;;;
;;;
;;;
(let ((p1 (p -25 -25))
(p2 (p 25 25)))
(defparameter *button-atomic-rubberband*
(make-object-button
(make-instance 'gui-atomic-rubberband
:p1 p1
:p2 p2
:dont-initialize t)
:valid #'line-validator
:when-selected #'(lambda (button)
(toggle button)
(switch-off (list *button-transparency*
*button-rubberband*
*button-beam*
*button-atomic->=-rubberband*
*button-atomic-<=-rubberband*
*button-drawn-enclosure*)))
:doc "Atomic Rubberband (AR, S)"))
(defparameter *button-atomic-<=-rubberband*
(make-object-button
(make-instance 'gui-atomic-<=-rubberband
:p1 p1
:p2 p2
:dont-initialize t)
:valid #'line-validator
:when-selected #'(lambda (button)
(toggle button)
(switch-off (list *button-transparency*
*button-rubberband*
*button-beam*
*button-atomic-rubberband*
*button-atomic->=-rubberband*
*button-drawn-enclosure*)))
:doc "Atomic <= Rubberband (AR, S)"))
(defparameter *button-atomic->=-rubberband*
(make-object-button
(make-instance 'gui-atomic->=-rubberband
:p1 p1
:p2 p2
:dont-initialize t)
:valid #'line-validator
:when-selected #'(lambda (button)
(toggle button)
(switch-off (list *button-transparency*
*button-rubberband*
*button-beam*
*button-atomic-rubberband*
*button-atomic-<=-rubberband*
*button-drawn-enclosure*)))
:doc "Atomic >= Rubberband (AR, S)"))
(defparameter *button-rubberband*
(make-object-button
(make-instance 'gui-rubberband
:p1 p1
:p2 p2
:dont-initialize t)
:valid #'(lambda (button)
(and (line-validator button)
(eq *point-status* 'db-component)))
:when-selected #'(lambda (button)
(toggle button)
(switch-off (list *button-transparency*
*button-beam*
*button-atomic-rubberband*
*button-atomic->=-rubberband*
*button-atomic-<=-rubberband*
*button-drawn-enclosure*)))
:doc "Rubberband (R, S)"))
(defparameter *button-beam*
(make-object-button (make-instance 'gui-beam
:p1 p1
:p2 p2
:dont-initialize t)
:valid #'line-validator
:when-selected #'(lambda (button)
(toggle button)
(switch-off (list *button-transparency*
*button-rubberband*
*button-atomic-rubberband*
*button-atomic->=-rubberband*
*button-atomic-<=-rubberband*
*button-drawn-enclosure*)))
:doc "Beam (B, S)")))
(let* ((p1 (p -25 0))
(p2 (p 0 -25))
(p3 (p 25 0))
(p4 (p 0 25))
(p5 (p 0 0))
(s1 (l p1 p2))
(s2 (l p2 p3))
(s3 (l p3 p4))
(s4 (l p4 p5))
(s5 (l p5 p1)))
(defparameter *button-chain*
(make-object-button
(make-instance 'gui-chain
:segments (list s1 s2 s3 s4)
:point-list (list p1 p2 p3 p4 p5)
:dont-initialize t)
:valid #'chain-or-polygon-validator
:when-selected #'(lambda (button)
(toggle button)
(switch-off (list *button-transparency*
*button-drawn-enclosure*
*button-polygon*)))
:doc "Chain"))
(defparameter *button-polygon*
(make-object-button
(make-instance 'gui-polygon
:segments (list s1 s2 s3 s4 s5)
:point-list (list p1 p2 p3 p4 p5)
:dont-initialize t)
:valid #'chain-or-polygon-validator
:when-selected #'(lambda (button)
(toggle button)
(switch-off (list *button-transparency*
*button-drawn-enclosure*
*button-chain*)))
:doc "Polygon (Poly)"))
(defparameter *button-drawn-enclosure*
(make-object-button
(let ((obj
(make-instance 'gui-drawn-enclosure
:on-transparency nil
:segments (list s1 s2 s3 s4 s5)
:point-list (list p1 p2 p3 p4 p5)
:dont-initialize t)))
(setf (drawable-pointlist obj)
(get-drawable-pointlist-for obj))
obj)
:valid #'(lambda (button)
(declare (ignore button))
(get-current-transparency))
:when-selected #'(lambda (button)
(switch-off (remove button *object-buttons*))
(toggle button))
:doc "Enclosure (E)"
:initialize #'(lambda (button)
(setf (ink (icon button))
(if *opaque-enclosures-p*
(make-gray-color 0.4)
(make-grid-in +black+)))
(tick-object button)))))
;;;
;;;
;;;
(defun accept-object-buttons (frame stream)
(multiple-value-bind (w h)
(window-inside-size stream)
(let ((w (/ w 3))
(h (/ (- h 15) 9)))
(stream-set-cursor-position stream 4 0)
(let ((x nil)
(y nil))
(with-centering (stream)
(multiple-value-bind (xlu ylu xro yro)
(accept-buttons (list
*button-transparency* *button-drawn-enclosure*)
1 2 frame stream
:width (* w 2)
:height h)
(declare (ignore xro yro))
(setf x xlu
y (+ 4 ylu))))
(stream-set-cursor-position stream x (+ y 2 (* h 2)))
(multiple-value-bind (xlu1 ylu1 xro1 yro1)
(accept-buttons (list *button-origin*
*button-nail*
*button-marble*)
3 1 frame stream
:width w
:height (* h 3))
(declare (ignore ylu1 yro1))
(stream-set-cursor-position stream (+ 4 xro1) y)
(multiple-value-bind (xlu2 ylu2 xro2 yro2)
(accept-buttons (list *button-beam*
*button-atomic-<=-rubberband*
*button-atomic->=-rubberband*
*button-atomic-rubberband*
*button-rubberband*)
5 1 frame stream
:width w
:height (* 5 h))
(declare (ignore yro2 xlu2))
(stream-set-cursor-position stream (+ 4 xro2) (+ y 2 (* h 3)))
(accept-buttons (list *button-chain*
*button-polygon*)
2 1 frame stream
:width w
:height (* 2 h))
(stream-set-cursor-position stream xlu1 (+ 8 ylu2))
(accept-buttons (reverse *status-buttons*)
3 3 frame stream
:width (* 3 w)
:height (* 3 h))))))))
;;;
;;;
;;;
(defmethod output-draw-button ((button object-button) stream cell-size)
(updating-output (stream
:cache-value (list (on button)
(deactivated button)
(funcall (tester button) button)
(tick button)
(when (slot-exists-p (icon button) 'status)
(status (icon button))))
:cache-test #'equal)
(with-output-as-presentation
(stream button 'object-button
:single-box t
:allow-sensitive-inferiors nil)
(draw-button button stream cell-size))))
(defmethod draw-button ((button object-button) stream cell-size)
(let ((half-cell-size (/ cell-size 2)))
(with-scaling (stream (scale-fac button)
(scale-fac button))
(draw (icon button) stream
:label-x (- half-cell-size)
:label-y (+ (- half-cell-size) 35)
:draw-chain-or-polygon-icon-p nil
:gravity-field nil
:draw-component-objects nil))))
| 13,054 | Common Lisp | .lisp | 407 | 25.547912 | 83 | 0.608404 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | de02c266aaf64d568eca45861052d9991f1bb9c31438ad14f2f380b54e9d8a5a | 11,720 | [
-1
] |
11,721 | creators7.lisp | lambdamikel_VISCO/src/GUI/creators7.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
(defun xy-to-grid (x y)
(if *grid-resolution*
(values
(* *grid-resolution* (floor x *grid-resolution*))
(* *grid-resolution* (floor y *grid-resolution*)))
(values x y)))
(defmethod get-create-description ((object gui-query-object-or-enclosure))
(format nil "Create ~A"
object))
(defmethod get-create-description ((object gui-transparency))
(format nil "Create ~A" object))
;;;
;;;
;;;
(define-visco-command (com-create-object-from-position :name nil)
((x 'number) (y 'number))
(register-undo-information nil)
(inform-button-action-begins
(get-button-for-icon *primary-mode*))
(let ((object (interactive-create *primary-mode* (list x y))))
(if object
(set-undo-operation-description-to (get-create-description object))
(pop-undo-stack)))
(inform-button-action-ends
(get-button-for-icon *primary-mode*))
(set-current-focus-to-newest-history-entry)
(set-object-modes)
(refresh))
(define-visco-command (com-create-object-from-point :name nil)
((object 'gui-point))
(register-undo-information nil)
(inform-button-action-begins
(get-button-for-icon *primary-mode*))
(let ((object (interactive-create *primary-mode* object)))
(if object
(set-undo-operation-description-to (get-create-description object))
(pop-undo-stack)))
(inform-button-action-ends
(get-button-for-icon *primary-mode*))
(set-current-focus-to-newest-history-entry)
(set-object-modes)
(refresh))
;;;
;;;
;;;
(defun point-acceptable-p (point)
(let ((cf (get-current-transparency)))
(and (eq cf (on-transparency point))
(current-focus-on-newest-history-entry-p)
(=> *point-mode*
(or (typep point (type-of *point-mode*))
(change-status-applicable-p point *point-status*)))
(fully-visible-p point))))
;;;
;;;
;;;
(define-presentation-to-command-translator create-transparency
(blank-area com-create-object-from-position visco
:gesture :select
:documentation ((stream) (format stream "Create ~A" *primary-mode*))
:tester (()
(and *primary-mode*
(typep *primary-mode* 'gui-transparency)))
:echo nil :maintain-history nil)
(x y)
(with-visco-frame (visco)
(multiple-value-bind (x y)
(xy-to-grid x y)
(stream-set-pointer-position (get-frame-pane visco 'display) x y)
(list x y))))
(define-presentation-to-command-translator create-object-from-point
(gui-point com-create-object-from-point visco
:documentation ((object stream)
(format stream "Create ~A From ~A On ~A"
*primary-mode*
object
(with-visco-frame (visco)
(current-transparency visco))))
:gesture :create
:tester ((object)
(and *primary-mode*
(not (typep *primary-mode* 'gui-point))
(point-acceptable-p object)))
:echo nil :maintain-history nil)
(object)
(list object))
(define-presentation-to-command-translator create-object-on-transparency-or-enclosure
((or gui-transparency gui-enclosure) com-create-object-from-position visco
:gesture :select
:documentation ((object stream)
(if (typep *primary-mode* 'gui-transparency)
(format stream "Create ~A" *primary-mode*)
(format stream "Create ~A On ~A"
*primary-mode*
(on-transparency object))))
:tester ((x y object)
(let ((cf (get-current-transparency)))
(and *primary-mode*
(current-focus-on-newest-history-entry-p)
cf
#| (=> (typep *primary-mode* '(or gui-line gui-chain-or-polygon))
*point-mode*) |#
(=> (typep object 'gui-transparency)
(=> *point-mode*
(and (point-truly-inside-box-p* x y cf)
(eq object cf))))
(=> *point-mode*
(status-of-point-object-ok-p *point-status*
(typecase *point-mode*
(gui-marble 'marble)
(gui-nail 'nail))
nil))
(=> (typep object 'gui-enclosure)
(eq (on-transparency object) cf))
(=> (typep *point-mode* 'gui-marble)
(find-if #'(lambda (obj)
(and (typep obj 'gui-enclosure)
(asg-inside-p* x y obj)))
(transparency-query-objects-and-enclosures cf))))))
:echo nil :maintain-history nil)
(x y)
(with-visco-frame (visco)
(multiple-value-bind (x y)
(xy-to-grid x y)
(stream-set-pointer-position (get-frame-pane visco 'display) x y)
(list x y))))
;;;
;;;
;;;
(defgeneric get-history-entry-for (dummy &key &allow-other-keys) ;v.h. no &rest
(:method-combination standard))
(defmethod get-history-entry-for :around ((dummy gui-visco-object) &key (register-p t) description )
(let ((entry (call-next-method)))
(when register-p
(register entry))
(when description
(setf (operation-descr entry)
description))
entry))
(defmethod get-history-entry-for ((dummy gui-transparency) &key name x1 y1 x2 y2)
(make-constructor-history-entry
""
`(create ,dummy
:x1 ,x1 :y1 ,y1
:x2 ,x2 :y2 ,y2
:name ,(or name (get-next-name)))
nil))
(defmethod get-history-entry-for ((dummy gui-point) &key status name transparency x y)
(make-constructor-history-entry
""
`(create ,dummy
:transparency (find-named-visco-object ,(name transparency))
:x ,x
:y ,y
:status ',status
:name ,(or name (get-next-name)))
(list transparency)))
(defmethod get-history-entry-for ((dummy gui-line) &key status name transparency p1 p2 ignore-disjoint-and-intersects-component-relations-p)
(make-constructor-history-entry
""
`(create ,dummy
:transparency (find-named-visco-object ,(name transparency))
:p1 (find-named-visco-object ,(name p1))
:p2 (find-named-visco-object ,(name p2))
:ignore-disjoint-and-intersects-component-relations-p ,ignore-disjoint-and-intersects-component-relations-p
:status ',status
:name ,(or name (get-next-name)))
(list p1 p2 transparency)))
(defmethod get-history-entry-for ((dummy gui-drawn-enclosure) &key opaque-p pattern-id
ink-rgb-list
negated-p
name transparency pointlist)
(make-constructor-history-entry
""
`(create ,dummy
:name ,(or name (get-next-name))
:transparency (find-named-visco-object ,(name transparency))
:pattern-id ,(or pattern-id (get-next-pattern-id))
:ink-rgb-list (quote ,(or ink-rgb-list
(calculate-color-for-drawn-enclosure dummy)))
:negated-p ,negated-p
:opaque-p ,opaque-p
:pointlist ',pointlist)
(list transparency)))
(defmethod get-history-entry-for ((dummy gui-chain-or-polygon)
&key status
name transparency segments
ignore-disjoint-and-intersects-component-relations-p)
(make-constructor-history-entry
""
`(create ,dummy
:transparency (find-named-visco-object ,(name transparency))
:ignore-disjoint-and-intersects-component-relations-p ,ignore-disjoint-and-intersects-component-relations-p
:segments (mapcar #'find-named-visco-object
',(mapcar #'name
(reverse segments)))
:status ',status
:name ,(or name (get-next-name)))
(cons transparency segments)))
;;;
;;;
;;;
(defmethod create-and-execute-history-entry ((obj gui-visco-object) &rest args)
(multiple-value-bind (obj history-entry)
(execute (apply #'get-history-entry-for obj args))
(if obj
(progn
(setf (operation-descr history-entry)
(get-create-description obj))
obj)
(delete-history-entry history-entry))
(set-current-focus-to-newest-history-entry)
(redisplay-frame-pane (with-visco-frame (visco) visco) 'control)
obj))
;;;
;;;
;;;
(defgeneric create (obj &key &allow-other-keys) ;v.h. no &rest
(:method-combination standard))
(defmethod create :around ((obj gui-visco-object) &rest args &key name)
(declare (ignore args))
(let ((new (call-next-method)))
(when (and new (not (eq new 'not-applicable)))
(when name
(setf (name new) name))
new)))
(defmethod create ((obj gui-transparency) &key x1 y1 x2 y2 &allow-other-keys)
(apply-create-transparency (get-current-query) x1 y1 x2 y2))
(defmethod create ((obj gui-nail) &key status transparency x y)
(apply-create-nail transparency status x y nil))
(defmethod create ((obj gui-marble) &key status transparency x y)
(apply-create-marble transparency status x y nil))
(defmethod create ((obj gui-origin) &key status transparency x y)
(apply-create-origin transparency status x y nil))
(defmethod create ((obj gui-rubberband) &key status transparency p1 p2 ignore-disjoint-and-intersects-component-relations-p)
(apply-create-rubberband transparency status p1 p2 :ignore-disjoint-and-intersects-component-relations-p ignore-disjoint-and-intersects-component-relations-p))
(defmethod create ((obj gui-beam) &key status transparency p1 p2 ignore-disjoint-and-intersects-component-relations-p)
(apply-create-beam transparency status p1 p2 :ignore-disjoint-and-intersects-component-relations-p ignore-disjoint-and-intersects-component-relations-p))
(defmethod create ((obj gui-atomic-rubberband) &key status transparency p1 p2 ignore-disjoint-and-intersects-component-relations-p)
(apply-create-atomic-rubberband transparency status p1 p2 :ignore-disjoint-and-intersects-component-relations-p ignore-disjoint-and-intersects-component-relations-p))
(defmethod create ((obj gui-atomic-<=-rubberband) &key status transparency p1 p2 ignore-disjoint-and-intersects-component-relations-p)
(apply-create-atomic-<=-rubberband transparency status p1 p2 :ignore-disjoint-and-intersects-component-relations-p ignore-disjoint-and-intersects-component-relations-p))
(defmethod create ((obj gui-atomic->=-rubberband) &key status transparency p1 p2 ignore-disjoint-and-intersects-component-relations-p)
(apply-create-atomic->=-rubberband transparency status p1 p2 :ignore-disjoint-and-intersects-component-relations-p ignore-disjoint-and-intersects-component-relations-p))
(defmethod create ((obj gui-polygon) &key status transparency segments ignore-disjoint-and-intersects-component-relations-p)
(apply-create-polygon transparency status segments :ignore-disjoint-and-intersects-component-relations-p ignore-disjoint-and-intersects-component-relations-p))
(defmethod create ((obj gui-chain) &key status transparency segments ignore-disjoint-and-intersects-component-relations-p)
(apply-create-chain transparency status segments :ignore-disjoint-and-intersects-component-relations-p ignore-disjoint-and-intersects-component-relations-p))
(defmethod create ((obj gui-drawn-enclosure) &key negated-p ink-rgb-list pattern-id opaque-p transparency pointlist)
(let* ((pointlist2
(mapcar #'(lambda (point)
(p (first point)
(second point)))
(transform-xy-list pointlist)))
(segments
(mapcar #'(lambda (p1 p2)
(l p1 p2))
(cons (first (last pointlist2))
pointlist2)
pointlist2)))
(apply-create-drawn-enclosure transparency segments opaque-p :pattern-id pattern-id
:ink-rgb-list ink-rgb-list
:negated-p negated-p)))
;;;
;;;
;;;
(defmethod set-point-attributes ((dummy gui-point) (transparency gui-transparency) x y)
(setf (x dummy) x
(y dummy) y
(on-transparency dummy) transparency
(part-of dummy) nil
(status dummy) *point-status*)
dummy)
(defmethod set-line-attributes ((dummy gui-line) (transparency gui-transparency) (p1 gui-point) (p2 gui-point))
(setf (p1 dummy) p1
(p2 dummy) p2
(on-transparency dummy) transparency
(part-of dummy) nil
(status dummy) *segment-status*)
(calculate-bounding-box dummy)
dummy)
(defmethod set-chain-or-polygon-attributes ((dummy gui-chain-or-polygon) (transparency gui-transparency) (segments list))
(setf (segments dummy) segments
(on-transparency dummy) transparency
(part-of dummy) nil
(status dummy) *chain-or-polygon-status*
(point-list dummy)
(append (mapcar #'p1 segments)
(list (p2 (first (last segments))))))
(calculate-centroid dummy)
(calculate-bounding-box dummy)
dummy)
;;;
;;;
;;;
(defclass no-object ()
nil)
(defclass no-point (no-object geom-point gui-visco-object)
nil)
(defclass no-segment (no-object geom-line gui-visco-object)
nil)
(defmethod draw ((obj no-point) stream &rest args)
(declare (ignore args))
(with-output-recording-options (stream :draw t :record nil)
(draw-text* stream "?" (x obj) (y obj) :ink +flipping-ink+)))
(defmethod draw ((obj no-segment) stream &rest args)
(declare (ignore args))
(with-output-recording-options (stream :draw t :record nil)
(draw-line* stream
(x (p1 obj)) (y (p1 obj))
(x (p2 obj)) (y (p2 obj))
:ink +flipping-ink+
:line-dashes '(1 1))))
(defparameter *no-point-mode* (make-instance 'no-point :dont-initialize t))
(defparameter *no-segment-mode* (make-instance 'no-segment :dont-initialize t))
;;;
;;;
;;;
(defmethod dummy-create ((object no-point) &key x y)
(let* ((dummy (get-and-lock-dummy (type-of object))))
(setf (x dummy) x
(y dummy) y)
dummy))
(defmethod dummy-create ((object no-segment) &key p1 p2)
(let* ((dummy (get-and-lock-dummy (type-of object))))
(setf (p1 dummy) p1
(p2 dummy) p2)
dummy))
;;;
;;;
;;;
(defmethod dummy-create ((object gui-origin) &key x y)
(let* ((transparency (get-current-transparency))
(dummy (get-and-lock-dummy (type-of object))))
(if (create-origin-applicable-p transparency *point-status* x y nil)
(set-point-attributes dummy transparency x y)
(progn (release-dummy dummy) nil))))
(defmethod dummy-create ((object gui-nail) &key x y)
(let* ((transparency (get-current-transparency))
(dummy (get-and-lock-dummy (type-of object))))
(if (create-nail-applicable-p transparency *point-status* x y nil)
(set-point-attributes dummy transparency x y)
(progn (release-dummy dummy) nil))))
(defmethod dummy-create ((object gui-marble) &key x y)
(let* ((transparency (get-current-transparency))
(dummy (get-and-lock-dummy (type-of object))))
(if (create-marble-applicable-p transparency *point-status* x y nil)
(set-point-attributes dummy transparency x y)
(progn (release-dummy dummy) nil))))
(defmethod dummy-create ((object gui-rubberband) &key p1 p2)
(let* ((transparency (get-current-transparency))
(dummy (get-and-lock-dummy (type-of object))))
(if (create-rubberband-applicable-p transparency *segment-status* p1 p2)
(set-line-attributes dummy transparency p1 p2)
(progn (release-dummy dummy) nil))))
(defmethod dummy-create ((object gui-atomic-rubberband) &key p1 p2)
(let* ((transparency (get-current-transparency))
(dummy (get-and-lock-dummy (type-of object))))
(if (create-atomic-rubberband-applicable-p transparency *segment-status* p1 p2)
(set-line-attributes dummy transparency p1 p2)
(progn (release-dummy dummy) nil))))
(defmethod dummy-create ((object gui-atomic-<=-rubberband) &key p1 p2)
(let* ((transparency (get-current-transparency))
(dummy (get-and-lock-dummy (type-of object))))
(if (create-atomic-<=-rubberband-applicable-p transparency *segment-status* p1 p2)
(set-line-attributes dummy transparency p1 p2)
(progn (release-dummy dummy) nil))))
(defmethod dummy-create ((object gui-atomic->=-rubberband) &key p1 p2)
(let* ((transparency (get-current-transparency))
(dummy (get-and-lock-dummy (type-of object))))
(if (create-atomic->=-rubberband-applicable-p transparency *segment-status* p1 p2)
(set-line-attributes dummy transparency p1 p2)
(progn (release-dummy dummy) nil))))
(defmethod dummy-create ((object gui-beam) &key p1 p2)
(let* ((transparency (get-current-transparency))
(dummy (get-and-lock-dummy (type-of object))))
(if (create-beam-applicable-p transparency *segment-status* p1 p2)
(set-line-attributes dummy transparency p1 p2)
(progn (release-dummy dummy) nil))))
(defmethod dummy-create ((object gui-chain) &key segments)
(let* ((transparency (get-current-transparency))
(dummy (get-and-lock-dummy (type-of object))))
(if (and (segment-list-ok-p segments 'chain nil)
(status-of-chain-or-polygon-object-ok-p *chain-or-polygon-status* 'chain segments))
#| (create-chain-applicable-p transparency *chain-or-polygon-status* segments) |#
(set-chain-or-polygon-attributes dummy transparency segments)
(progn (release-dummy dummy) nil))))
;;;
;;;
;;;
(defun get-and-lock-dummy (obj-symbol)
(let ((obj2
(find-if #'(lambda (obj)
(and (eq (type-of obj) obj-symbol)
(not (eq (dummy-p obj) 'locked))))
*dummies*)))
(if obj2
(progn
(lock-dummy obj2)
obj2)
(error "No more dummies!"))))
(defun lock-dummy (dummy)
(setf (dummy-p dummy) 'locked))
(defun release-dummy (dummy)
(setf (dummy-p dummy) t))
(setf *dummies*
(apply #'append
(append (loop as i from 1 to 5 collect
(list (make-instance 'gui-origin :dummy-p t :dont-initialize t)
(make-instance 'gui-marble :dummy-p t :dont-initialize t)
(make-instance 'gui-nail :dummy-p t :dont-initialize t)))
(loop as i from 1 to 5 collect
(list
(make-instance 'gui-beam :dummy-p t :bounding-box-p t :dont-initialize t)
(make-instance 'gui-rubberband :dummy-p t :bounding-box-p t :dont-initialize t)
(make-instance 'gui-atomic-rubberband :dummy-p t :bounding-box-p t :dont-initialize t)
(make-instance 'gui-atomic-<=-rubberband :dummy-p t :bounding-box-p t :dont-initialize t)
(make-instance 'gui-atomic->=-rubberband :dummy-p t :bounding-box-p t :dont-initialize t)))
(loop as i from 1 to 3 collect
(list
(make-instance 'gui-chain :dummy-p t :bounding-box-p t :dont-initialize t)
(make-instance 'gui-polygon :dummy-p t :bounding-box-p t :dont-initialize t)))
(loop as i from 1 to 3 collect
(list
(make-instance 'no-point :dummy-p t :dont-initialize t)
(make-instance 'no-segment :dummy-p t :bounding-box-p t :dont-initialize t))))))
(dolist (dummy *dummies*)
(when (typep dummy 'gui-query-object)
(setf (object (status-label dummy)) dummy
(query dummy) nil)))
;;;
;;;
;;;
(defmethod interactive-create ((obj gui-transparency) (point list) &key &allow-other-keys)
(let* ((x1 (first point))
(y1 (second point))
(x2 x1)
(y2 y1))
(with-visco-frame (visco)
(let ((stream (get-frame-pane visco 'display)))
(labels ((draw-it ()
(draw-rectangle* stream
x1 y1
x2 y2
:ink +flipping-ink+
:filled nil)))
(with-output-recording-options (stream :draw t :record nil)
(tracking-pointer (stream)
(:pointer-motion (x y)
(multiple-value-bind (x y)
(xy-to-grid x y)
(draw-it)
(setf x2 x
y2 y)
(draw-it)))
(:keyboard (character)
(when (and (characterp character)
(char-equal character #\q))
(return)))
(:pointer-button-press (event)
(if (= (pointer-event-button event)
+pointer-right-button+)
(return)
(let ((obj (create-and-execute-history-entry *primary-mode*
:x1 x1 :y1 y1 :x2 x2 :y2 y2
)))
(if (not obj)
(beep)
(return obj))))))))))))
(defmethod interactive-create ((obj gui-point) (point list) &key create-component-points-p &allow-other-keys)
(interactive-point-creator obj point :create-component-points-p create-component-points-p))
(defmethod interactive-create ((obj no-point) (point list) &key create-component-points-p &allow-other-keys)
(interactive-point-creator obj point :create-component-points-p create-component-points-p))
(defmethod interactive-create ((obj gui-line) point &key create-component-lines-p &allow-other-keys)
(interactive-line-creator point :create-component-lines-p create-component-lines-p))
(defmethod interactive-create ((obj no-segment) point &key create-component-lines-p &allow-other-keys)
(interactive-line-creator point :create-component-lines-p create-component-lines-p))
(defmethod interactive-create ((obj gui-chain-or-polygon) point &key &allow-other-keys)
(interactive-chain-or-poly-creator point))
(defmethod interactive-create ((obj drawn-enclosure) (point list) &key &allow-other-keys)
(interactive-drawn-enclosure-creator point))
;;;
;;;
;;;
(defmethod interactive-point-creator ((obj geom-point) (point list) &key create-component-points-p
&allow-other-keys) ; geom-point wg. no-point
(with-visco-frame (visco)
(let ((stream (get-frame-pane visco 'display)))
(let ((point nil)
(object nil))
(with-output-recording-options (stream :draw t :record nil)
(tracking-pointer (stream)
(:pointer-motion (x y)
(multiple-value-bind (x y)
(xy-to-grid x y)
(with-input-context ('gui-point :override t)
nil
(let ((presentation
(find-innermost-applicable-presentation *input-context*
stream x y
:frame visco)))
(unhighlight-highlighted-presentation stream)
(setf object nil)
(when presentation
(let ((po (presentation-object presentation)))
(when (point-acceptable-p po)
(set-highlighted-presentation stream presentation)
(setf object po))))))
(when (and point (dummy-p point))
(draw point stream :handling-active t :output-recording nil))
(setf point
(or object (dummy-create (or *point-mode* *no-point-mode*) :x x :y y)))
(when (and point (dummy-p point))
(release-dummy point)
(draw point stream :handling-active t :output-recording nil))))
(:keyboard (character)
(when (and (characterp character)
(char-equal character #\q))
(return)))
(:pointer-button-press (event)
(if (= (pointer-event-button event)
+pointer-right-button+)
(return)
(if (and point (not (typep point 'no-point))
(=> (not (dummy-p point)) create-component-points-p))
(if (not (dummy-p point))
(return point)
(let ((point
(create-and-execute-history-entry point
:transparency (get-current-transparency)
:status *point-status*
:x (x point) :y (y point))))
(if (not point)
(beep)
(progn
(return point)))))
(beep))))))))))
(defmethod interactive-line-creator ((p1 list) &key create-component-lines-p)
(let ((obj (interactive-create (or *point-mode* *no-point-mode*) p1
:create-component-points-p t)))
(when obj
(inform-button-action-ends
(get-button-for-icon *point-mode*))
(multiple-value-bind (res event key)
(interactive-line-creator obj
:create-component-lines-p create-component-lines-p)
(unless res
(delete-object obj))
(values res event key)))))
(defmethod interactive-line-creator ((p1 geom-point) &key create-component-lines-p)
(with-visco-frame (visco)
(let ((stream (get-frame-pane visco 'display)))
(redisplay-frame-pane visco 'display)
(when p1
(with-output-recording-options (stream :draw t :record nil)
(let ((line nil)
(lastline nil)
(line-valid nil)
(p2 nil)
(lastp2 nil)
(object nil))
(labels ((draw-it (line)
(when (dummy-p line)
(draw line stream :handling-active t :output-recording nil
:draw-component-objects nil))
(when (dummy-p (p2 line))
(draw (p2 line) stream :handling-active t :output-recording nil)))
(erase-it ()
(draw-it line))
(release-all ()
(when (and p2 (dummy-p p2))
(release-dummy p2))
(when (and line (dummy-p line))
(release-dummy line))
(erase-it)
(unhighlight-highlighted-presentation stream)))
(tracking-pointer (stream :context-type 'gui-point)
(:pointer-motion (x y)
(multiple-value-bind (x y)
(xy-to-grid x y)
(with-input-context ('gui-point :override t)
nil
(let ((presentation
(find-innermost-applicable-presentation *input-context*
stream x y
:frame visco)))
(unhighlight-highlighted-presentation stream)
(setf object nil)
(when presentation
(let ((po (presentation-object presentation)))
(when (point-acceptable-p po)
(set-highlighted-presentation stream presentation)
(setf object po))))))
(let ((newp2 (or object
(dummy-create (or *point-mode* *no-point-mode*)
:x x :y y))))
(setf line-valid nil)
(when newp2
(let ((newline
(or (when create-component-lines-p
(let ((master (get-direct-common-master p1 newp2)))
(when (and (null (rest master))
(first master)
(not (dummy-p (first master))))
(first master))))
(dummy-create (or (when (not (typep newp2 'no-point))
*segment-mode*)
*no-segment-mode*)
:p1 p1 :p2 newp2))))
(if newline
(progn
(setf line-valid
(not (typep newline 'no-segment)))
(setf lastline line
line newline
lastp2 p2
p2 newp2)
(when (and lastline
(dummy-p lastline))
(release-dummy lastline))
(when (and lastp2
(dummy-p lastp2))
(release-dummy lastp2))
(when line
(when lastline (draw-it lastline))
(unless (eq lastline line)
(draw-it line))))
(when (dummy-p newp2)
(release-dummy newp2))))))))
(:keyboard (character)
(flet ((exit (val)
(release-all)
(return (values nil nil val))))
(if (and (characterp character)
(char-equal character #\q))
(exit :quit)
(when (typep character 'keyboard-event)
(let ((keysym (keyboard-event-key-name character)))
(when (eq keysym :rubout)
(exit keysym)))))))
(:pointer-button-press (event)
(if (= (pointer-event-button event)
+pointer-right-button+)
(progn
(release-all)
(return (values nil event nil)))
(when p2
(if (and line line-valid)
(progn
(release-all)
(when (dummy-p line)
(setf p2
(if (dummy-p p2)
(create-and-execute-history-entry p2 :x (x p2) :y (y p2)
:transparency (get-current-transparency)
:status (status p2))
p2)
line
(create-and-execute-history-entry line
:transparency (get-current-transparency)
:p1 p1 :p2 p2
:status *segment-status*
:ignore-disjoint-and-intersects-component-relations-p
*ignore-disjoint-and-intersects-component-relations-p*)))
(return
(values line event nil)))
(beep)))))))))))))
(defmethod interactive-chain-or-poly-creator ((p1 list))
(let ((obj (interactive-create (or *point-mode* *no-point-mode*) p1
:create-component-points-p t)))
(when obj
(inform-button-action-ends
(get-button-for-icon *point-mode*))
(let ((res (interactive-chain-or-poly-creator obj)))
(unless res
(delete-object obj))
res))))
(defmethod interactive-chain-or-poly-creator ((p1 gui-point))
(with-visco-frame (visco)
(let ((first-point p1)
(lines nil)
(objects (copy-list (visco-objects (get-current-query)))))
(labels ((delete-it (object)
(unless (member object objects)
(delete-object object :delete-component-objects-p nil))
(dolist (p (get-direct-components object))
(when (and (not (member p objects))
(primary-p p))
(delete-object p)))
(set-current-focus-to-newest-history-entry)
(redisplay-frame-pane visco 'display)
(redisplay-frame-pane visco 'control))
(exit-code ()
(mapc #'(lambda (line)
(unless (member line objects)
(delete-object line :delete-component-objects-p nil))
(dolist (p (get-direct-components line))
(unless (member p objects)
(delete-object p))))
lines)
(when (dummy-p first-point)
(release-dummy first-point))
(return-from interactive-chain-or-poly-creator)))
(loop
(multiple-value-bind (line event key)
(interactive-create (or *segment-mode*
*no-segment-mode*)
p1
:create-component-lines-p t)
(redisplay-frame-pane visco 'display)
(when (dummy-p first-point)
(lock-dummy first-point))
(if key
(case key
(:rubout
(let* ((delete (pop lines))
(first (first lines)))
(if delete
(progn
(delete-it delete)
(if first
(if (point-=-p p1 (p2 delete))
(setf p1 (p1 delete))
(setf p1 (p2 delete)))
(setf p1 first-point)))
(beep))))
(:quit (exit-code)))
(let ((button (pointer-event-button event))
#+:mcl
(modifier (event-modifier-state event)))
(cond (
#+:allegro (= button +pointer-middle-button+)
#+:mcl (and (= button +pointer-left-button+)
(= modifier +shift-key+))
(if (and line
(not
(member line lines)))
(progn
(push line lines)
(let ((obj
(create-and-execute-history-entry *primary-mode*
:transparency (get-current-transparency)
:segments (reverse lines)
:status *chain-or-polygon-status*
:ignore-disjoint-and-intersects-component-relations-p
*ignore-disjoint-and-intersects-component-relations-p*)))
(if obj
(progn
(when (dummy-p first-point)
(release-dummy first-point))
(return obj))
(progn
(pop lines)
(unless (member line lines)
(delete-it line))
(beep)))))
(when line
(unless (member line lines)
(delete-it line))
(beep))))
((= button +pointer-left-button+)
(if (and line
(not
(member line lines)))
(progn
(push line lines)
(let ((dummy
(dummy-create (icon *button-chain*)
:segments (reverse lines))))
(if (=> (> (length lines) 1)
dummy)
(progn
(when dummy (release-dummy dummy))
(if (eq p1 (p1 line))
(setf p1 (p2 line))
(setf p1 (p1 line))))
(progn
(delete-it (pop lines))
(beep)))))
(when line
(beep))))
((= button +pointer-right-button+)
(exit-code)))))))))))
(defmethod interactive-drawn-enclosure-creator ((p1 list))
(with-visco-frame (visco)
(let* ((stream (get-frame-pane visco 'display))
(pointx (first p1))
(pointy (second p1))
(points (list pointx pointy)))
(flet ((draw-it ()
(if (rest (rest points))
(draw-polygon* stream
(cons pointx (cons pointy points))
:filled t
:ink +flipping-ink+
:closed t)
(draw-line* stream
(first p1) (second p1)
pointx pointy
:ink +flipping-ink+))))
(with-output-recording-options (stream :draw t :record nil)
(tracking-pointer (stream)
(:pointer-motion (x y)
(multiple-value-bind (x y)
(xy-to-grid x y)
(when (inside-p* x y (get-current-transparency))
(draw-it)
(setf pointx x
pointy y)
(draw-it))))
(:keyboard (character)
(if (and (characterp character)
(char-equal character #\q))
(return)
(when (typep character 'keyboard-event)
(let ((keysym (keyboard-event-key-name character)))
(when (eq keysym
:rubout)
(if (rest (rest points))
(progn
(draw-it)
(pop points)
(pop points)
(draw-it))
(beep)))))))
(:pointer-button-press (event)
(let ((button (pointer-event-button event))
#+:mcl
(modifier (event-modifier-state event)))
(cond ((= button +pointer-right-button+)
(return))
(
#+:allegro
(= button +pointer-middle-button+)
#+:mcl
(and (= button +pointer-left-button+)
(= modifier +shift-key+))
(push pointy points)
(push pointx points)
(let* ((enclosure
(create-and-execute-history-entry
*primary-mode*
:transparency (get-current-transparency)
:pointlist points
:opaque-p *opaque-enclosures-p*)))
(if enclosure
(return enclosure)
(progn
(pop points)
(pop points)
(beep)))))
((= button +pointer-left-button+)
(unless (cddr points)
(draw-it))
(push pointy points)
(push pointx points)))))))))))
| 34,261 | Common Lisp | .lisp | 858 | 31.911422 | 171 | 0.619565 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | dc0db7478b17f20fdaa3fb27b0d79d79984199274fa24f3788dcd74c19964c0b | 11,721 | [
-1
] |
11,722 | macros.lisp | lambdamikel_VISCO/src/GUI/macros.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
(defmacro with-visco-frame ((name) &body body)
`(let ((,name *visco-frame*))
,@body))
(defmacro with-visco-buttons-frame ((name) &body body)
`(let ((,name *visco-buttons-frame*))
,@body))
(defmacro with-visco-inspector-frame ((name) &body body)
`(let ((,name *visco-inspector-frame*))
,@body))
| 412 | Common Lisp | .lisp | 11 | 33.909091 | 72 | 0.642132 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 9e9753e8779205737f4dcf2ecf0c34e6045d47e14517264fd1663a10a8a61bc1 | 11,722 | [
-1
] |
11,723 | patterns3.lisp | lambdamikel_VISCO/src/GUI/patterns3.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
;;;
;;;
;;;
(defvar *arrays*)
(defvar *array-ring*)
(defconstant +grid+
(make-array '(8 8)
:initial-contents '((1 0 1 0 1 0 1 0)
(0 1 0 1 0 1 0 1)
(1 0 1 0 1 0 1 0)
(0 1 0 1 0 1 0 1)
(1 0 1 0 1 0 1 0)
(0 1 0 1 0 1 0 1)
(1 0 1 0 1 0 1 0)
(0 1 0 1 0 1 0 1))))
(defmethod calculate-gray-color ((obj gui-object))
(list 0 0 0))
(defun random-gray-color ()
(let ((col
(+ 0.5 (/ (random 31) 100))))
(list col col col)))
(defun random-color ()
(let ((col
(+ 0.5 (/ (random 31) 100))))
(list col 0 col)))
(defmethod calculate-color ((obj gui-enclosure))
(random-gray-color))
(defmethod calculate-color-for-drawn-enclosure ((obj gui-drawn-enclosure))
(random-gray-color))
(defmethod calculate-color-for-inner-enclosure ((obj gui-polygon))
(random-color))
(defmethod calculate-color-for-outer-enclosure ((obj gui-polygon))
(random-color))
(defmethod calculate-color-for-epsilon-enclosure ((obj gui-query-object))
(random-color))
(defun make-grid-in (color &optional (background-ink +transparent-ink+))
(make-rectangular-tile
(make-pattern +grid+
(list color
background-ink))
8 8))
(defun get-gray-pattern-in (col &key (opaque-p *opaque-enclosures-p*)
pattern-id)
(get-pattern-in (make-gray-color (first col)) :opaque-p opaque-p :pattern-id pattern-id))
(defun get-pattern-in (col &key (opaque-p *opaque-enclosures-p*)
pattern-id)
(if opaque-p
col
(let ((array
(if pattern-id
(let ((pattern
(nth pattern-id *arrays*)))
(setf *array-ring*
(nthcdr (1+ (position pattern *array-ring*))
*array-ring*))
pattern)
(pop *array-ring*))))
(values
(make-pattern-in col
array
opaque-p)
(position array *arrays*)))))
(defun get-next-pattern-id ()
(position (first *array-ring*) *arrays*))
(defun make-pattern-in (col array opaque-p)
(make-rectangular-tile
(make-pattern array
(list (if opaque-p
+background-ink+
+transparent-ink+)
col))
8 8))
(defun make-inverse-pattern-in (col array opaque-p)
(make-rectangular-tile
(make-pattern
(let* ((x (first (array-dimensions array)))
(y (second (array-dimensions array)))
(array2 (make-array (list x y))))
(dotimes (x x)
(dotimes (y y)
(setf (aref array2 x y)
(- 1 (aref array x y)))))
array2)
(list (if opaque-p
+background-ink+
+transparent-ink+)
col))
8 8))
(defun inverse-pattern (pattern col opaque-p)
(make-inverse-pattern-in
col
(slot-value (slot-value pattern 'design) 'array)
opaque-p))
(defparameter *arrays*
(list
(make-array '(8 8)
:initial-contents
'((1 0 0 0 1 0 0 0)
(0 1 0 0 0 1 0 0)
(0 0 1 0 0 0 1 0)
(0 0 0 1 0 0 0 1)
(1 0 0 0 1 0 0 0)
(0 1 0 0 0 1 0 0)
(0 0 1 0 0 0 1 0)
(0 0 0 1 0 0 0 1)))
(make-array '(8 8)
:initial-contents
'((1 0 0 0 1 0 0 0)
(0 1 0 0 0 1 0 0)
(0 0 1 0 0 0 1 0)
(0 0 0 1 0 0 0 1)
(0 0 1 0 0 0 1 0)
(0 1 0 0 0 1 0 0)
(1 0 0 0 1 0 0 0)
(0 0 0 1 0 0 0 1)))
(make-array '(8 8)
:initial-contents
'((0 0 0 1 0 0 0 1)
(0 0 1 0 0 0 1 0)
(0 1 0 0 0 1 0 0)
(1 0 0 0 1 0 0 0)
(0 0 0 1 0 0 0 1)
(0 0 1 0 0 0 1 0)
(0 1 0 0 0 1 0 0)
(1 0 0 0 1 0 0 0)))
(make-array '(8 8)
:initial-contents
'((1 0 0 0 1 0 0 0)
(1 0 0 0 1 0 0 0)
(0 1 0 0 0 1 0 0)
(0 1 0 0 0 1 0 0)
(0 0 1 0 0 0 1 0)
(0 0 1 0 0 0 1 0)
(0 0 0 1 0 0 0 1)
(0 0 0 1 0 0 0 1)))
(make-array '(8 8)
:initial-contents
'((0 0 0 1 0 0 0 1)
(0 0 0 1 0 0 0 1)
(0 0 1 0 0 0 1 0)
(0 0 1 0 0 0 1 0)
(0 1 0 0 0 1 0 0)
(0 1 0 0 0 1 0 0)
(1 0 0 0 1 0 0 0)
(1 0 0 0 1 0 0 0)))
(make-array '(8 8)
:initial-contents
'((0 0 0 1 0 0 0 0)
(0 0 1 0 1 0 0 0)
(0 1 0 0 0 1 0 0)
(1 0 0 0 0 0 1 0)
(0 0 0 0 0 1 0 0)
(0 0 0 0 1 0 0 0)
(0 0 0 1 0 0 0 0)
(0 0 1 0 0 0 0 0)))
(make-array '(8 8)
:initial-contents
'((0 0 0 0 1 0 0 0)
(1 0 0 0 0 0 0 0)
(0 0 0 0 0 1 0 0)
(0 1 0 0 0 0 0 0)
(0 0 0 0 0 0 1 0)
(0 0 1 0 0 0 0 0)
(0 0 0 0 0 0 0 1)
(0 0 0 1 0 0 0 0)))))
#|
(defun generate-random-array ()
(labels ((check-neighbourhood (arr x y radius)
(dotimes (xi (1+ (* 2 radius)))
(dotimes (yi (1+ (* 2 radius)))
(let ((x (mod (+ x (- xi radius)) 8))
(y (mod (+ y (- yi radius)) 8)))
(unless (zerop (aref arr x y))
(return-from check-neighbourhood nil)))))
t))
(let ((arr (make-array '(8 8) :initial-element 0))
(counter 0))
(loop while (< counter 4) do
(let ((x (random 8))
(y (random 8)))
(when (check-neighbourhood arr x y 2)
(setf (aref arr x y) 1)
(incf counter))))
arr)))
(defparameter *arrays*
(loop as i from 1 to 100 collect (generate-random-array)))
|#
(defparameter *array-ring*
(let ((x (copy-list *arrays*)))
(setf (rest (last x)) x)))
| 5,234 | Common Lisp | .lisp | 192 | 21.973958 | 91 | 0.546185 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 05f0e24ddb63bbe183b85e7060e0dc82ac10e93aa90605e28d5a6c65ad8b5b41 | 11,723 | [
-1
] |
11,724 | patterns4.lisp | lambdamikel_VISCO/src/GUI/patterns4.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: GUI; Base: 10 -*-
(in-package gui)
;;;
;;;
;;;
(defvar *arrays*)
(defvar *array-ring*)
(defconstant +grid+
(make-array '(8 8)
:initial-contents '((1 0 1 0 1 0 1 0)
(0 1 0 1 0 1 0 1)
(1 0 1 0 1 0 1 0)
(0 1 0 1 0 1 0 1)
(1 0 1 0 1 0 1 0)
(0 1 0 1 0 1 0 1)
(1 0 1 0 1 0 1 0)
(0 1 0 1 0 1 0 1))))
#+visco-demo-mode
(defvar *colors*
(list (list 0.8 0.2 0)
(list 0 0 1)))
#+visco-demo-mode
(defvar *color-ring*)
(defmethod calculate-gray-color ((obj gui-object))
(list 0 0 0))
(defun random-gray-color ()
(let ((col
(+ 0.5 (/ (random 31) 100))))
(list col col col)))
(defun random-color ()
(let ((col
(+ 0.5 (/ (random 31) 100))))
(list col 0 col)))
(defmethod calculate-color ((obj gui-enclosure))
(random-gray-color))
(defmethod calculate-color-for-drawn-enclosure ((obj gui-drawn-enclosure))
(random-gray-color))
(defmethod calculate-color-for-inner-enclosure ((obj gui-polygon))
(random-color))
(defmethod calculate-color-for-outer-enclosure ((obj gui-polygon))
(random-color))
#-visco-demo-mode
(defmethod calculate-color-for-epsilon-enclosure ((obj gui-query-object))
(random-color))
#+visco-demo-mode
(defmethod calculate-color-for-epsilon-enclosure ((obj gui-query-object))
(pop *color-ring*))
(defun make-grid-in (color &optional (background-ink +transparent-ink+))
(make-rectangular-tile
(make-pattern +grid+
(list color
background-ink))
8 8))
(defun get-gray-pattern-in (col &key (opaque-p *opaque-enclosures-p*)
pattern-id)
(get-pattern-in (make-gray-color (first col)) :opaque-p opaque-p :pattern-id pattern-id))
(defun get-pattern-in (col &key (opaque-p *opaque-enclosures-p*)
pattern-id)
(if opaque-p
col
(let ((array
(if pattern-id
(let ((pattern
(nth pattern-id *arrays*)))
(setf *array-ring*
(nthcdr (1+ (position pattern *array-ring*))
*array-ring*))
pattern)
(pop *array-ring*))))
(values
(make-pattern-in col
array
opaque-p)
(position array *arrays*)))))
(defun get-next-pattern-id ()
(position (first *array-ring*) *arrays*))
(defun make-pattern-in (col array opaque-p)
(make-rectangular-tile
(make-pattern array
(list (if opaque-p
+background-ink+
+transparent-ink+)
col))
8 8))
(defun make-inverse-pattern-in (col array opaque-p)
(make-rectangular-tile
(make-pattern
(let* ((x (first (array-dimensions array)))
(y (second (array-dimensions array)))
(array2 (make-array (list x y))))
(dotimes (x x)
(dotimes (y y)
(setf (aref array2 x y)
(- 1 (aref array x y)))))
array2)
(list (if opaque-p
+background-ink+
+transparent-ink+)
col))
8 8))
(defun inverse-pattern (pattern col opaque-p)
(make-inverse-pattern-in
col
(slot-value (slot-value pattern 'design) 'array)
opaque-p))
(defparameter *arrays*
(list
#|
(make-array '(8 8)
:initial-contents
'((1 0 0 0 1 0 0 0)
(0 1 0 0 0 1 0 0)
(0 0 1 0 0 0 1 0)
(0 0 0 1 0 0 0 1)
(1 0 0 0 1 0 0 0)
(0 1 0 0 0 1 0 0)
(0 0 1 0 0 0 1 0)
(0 0 0 1 0 0 0 1)))
(make-array '(8 8)
:initial-contents
'((1 0 0 0 1 0 0 0)
(0 1 0 0 0 1 0 0)
(0 0 1 0 0 0 1 0)
(0 0 0 1 0 0 0 1)
(0 0 1 0 0 0 1 0)
(0 1 0 0 0 1 0 0)
(1 0 0 0 1 0 0 0)
(0 0 0 1 0 0 0 1)))
(make-array '(8 8)
:initial-contents
'((0 0 0 1 0 0 0 1)
(0 0 1 0 0 0 1 0)
(0 1 0 0 0 1 0 0)
(1 0 0 0 1 0 0 0)
(0 0 0 1 0 0 0 1)
(0 0 1 0 0 0 1 0)
(0 1 0 0 0 1 0 0)
(1 0 0 0 1 0 0 0)))
(make-array '(8 8)
:initial-contents
'((1 0 0 0 1 0 0 0)
(1 0 0 0 1 0 0 0)
(0 1 0 0 0 1 0 0)
(0 1 0 0 0 1 0 0)
(0 0 1 0 0 0 1 0)
(0 0 1 0 0 0 1 0)
(0 0 0 1 0 0 0 1)
(0 0 0 1 0 0 0 1)))
(make-array '(8 8)
:initial-contents
'((0 0 0 1 0 0 0 1)
(0 0 0 1 0 0 0 1)
(0 0 1 0 0 0 1 0)
(0 0 1 0 0 0 1 0)
(0 1 0 0 0 1 0 0)
(0 1 0 0 0 1 0 0)
(1 0 0 0 1 0 0 0)
(1 0 0 0 1 0 0 0)))
(make-array '(8 8)
:initial-contents
'((0 0 0 1 0 0 0 0)
(0 0 1 0 1 0 0 0)
(0 1 0 0 0 1 0 0)
(1 0 0 0 0 0 1 0)
(0 0 0 0 0 1 0 0)
(0 0 0 0 1 0 0 0)
(0 0 0 1 0 0 0 0)
(0 0 1 0 0 0 0 0)))
|#
(make-array '(8 8)
:initial-contents
'((0 0 0 0 0 0 0 1)
(0 0 0 0 0 0 1 0)
(0 0 0 0 0 1 0 0)
(0 0 0 0 1 0 0 0)
(0 0 0 1 0 0 0 0)
(0 0 1 0 0 0 0 0)
(0 1 0 0 0 0 0 0)
(1 0 0 0 0 0 0 0)))
(make-array '(8 8)
:initial-contents
'((0 0 0 0 1 0 0 0)
(1 0 0 0 0 0 0 0)
(0 0 0 0 0 1 0 0)
(0 1 0 0 0 0 0 0)
(0 0 0 0 0 0 1 0)
(0 0 1 0 0 0 0 0)
(0 0 0 0 0 0 0 1)
(0 0 0 1 0 0 0 0)))))
#|
(defun generate-random-array ()
(labels ((check-neighbourhood (arr x y radius)
(dotimes (xi (1+ (* 2 radius)))
(dotimes (yi (1+ (* 2 radius)))
(let ((x (mod (+ x (- xi radius)) 8))
(y (mod (+ y (- yi radius)) 8)))
(unless (zerop (aref arr x y))
(return-from check-neighbourhood nil)))))
t))
(let ((arr (make-array '(8 8) :initial-element 0))
(counter 0))
(loop while (< counter 4) do
(let ((x (random 8))
(y (random 8)))
(when (check-neighbourhood arr x y 2)
(setf (aref arr x y) 1)
(incf counter))))
arr)))
(defparameter *arrays*
(loop as i from 1 to 100 collect (generate-random-array)))
|#
#+visco-demo-mode
(defparameter *array-ring*
(let ((x (copy-list *arrays*)))
(setf (rest (last x)) x)))
#+visco-demo-mode
(defparameter *color-ring*
(let ((x (copy-list *colors*)))
(setf (rest (last x)) x)))
| 5,894 | Common Lisp | .lisp | 219 | 21.680365 | 91 | 0.547129 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 7e420fd9319d704a023c3fb25e66a119d667a50daca12ba6173c0c6c54996810 | 11,724 | [
-1
] |
11,725 | obj-w-rel5.lisp | lambdamikel_VISCO/src/objects-with-relations/obj-w-rel5.lisp | ;;; -*- Mode: Lisp; Syntax: Ansi-Common-Lisp; Package: OBJECTS-WITH-RELATIONS; Base: 10 -*-
(in-package objects-with-relations)
(defgeneric calculate-relations (obj)
(:documentation "Calculate all interesting spatial relations to (and from) obj. Clients should specialize
this function and establish the relation by calling store-intersection-between or store-inside-between."))
(defgeneric remove-all-relations (obj)
(:documentation "Remove all relations for obj."))
(defgeneric store-intersection-between (obj1 obj2)
(:documentation "Store intersects relation between obj1 and obj2."))
(defgeneric store-inside-between (obj1 obj2)
(:documentation "Store inside relation between obj1 and obj2."))
(defgeneric delete-intersection-between (obj1 obj2)
(:documentation "Delete intersects relation between obj1 and obj2."))
(defgeneric delete-inside-between (obj1 obj2)
(:documentation "Delete inside relation between obj1 and obj2."))
;;;
;;;
;;;
(defparameter *objects-with-relations* nil)
(defpersistentclass geom-thing-with-relations (geom-thing)
((inside :accessor inside :initform nil)
(intersects :accessor intersects :initarg :intersects :initform nil))) ; alle Schnitte
;;;
;;; Achtung: disjoint implizit vorhanden => keine Rel(a,b) eingetr. <=> disjoint(a,b)
;;;
(defpersistentclass at-least-1d-geom-thing-with-relations (geom-thing-with-relations)
((intersects-points :accessor intersects-points :initarg :intersects-points :initform nil)
(intersects-lines :accessor intersects-lines :initarg :intersects-lines :initform nil)
(intersects-chains :accessor intersects-chains :initarg :intersects-chains :initform nil)
(intersects-polygons :accessor intersects-polygons :initarg :intersects-polygons :initform nil)))
;;;
;;;
;;;
(defpersistentclass geom-point-with-relations (geom-thing-with-relations geom-point)
((intersects-lines :accessor intersects-lines :initarg :intersects-lines :initform nil)
(intersects-chains :accessor intersects-chains :initarg :intersects-chains :initform nil)
(intersects-polygons :accessor intersects-polygons :initarg :intersects-polygons :initform nil)))
(defpersistentclass geom-line-with-relations (at-least-1d-geom-thing-with-relations
geom-line)
())
(defpersistentclass geom-chain-or-polygon-with-relations (at-least-1d-geom-thing-with-relations
geom-chain-or-polygon)
())
(defpersistentclass geom-chain-with-relations (geom-chain-or-polygon-with-relations
geom-chain)
())
(defpersistentclass geom-polygon-with-relations (geom-chain-or-polygon-with-relations
geom-polygon)
((contains :accessor contains :initarg :contains :initform nil)
(contains-points :accessor contains-points :initarg :contains-points :initform nil)
(contains-lines :accessor contains-lines :initarg :contains-lines :initform nil)
(contains-chains :accessor contains-chains :initarg :contains-chains :initform nil)
(contains-polygons :accessor contains-polygons :initarg :contains-polygons :initform nil)))
#|
(defpersistentclass geom-aggregate-with-relations (at-least-1d-geom-thing-with-relations
geom-aggregate)
())
|#
;;;
;;;
;;;
(defmethod calculate-relations ((obj geom-thing-with-relations))
"This function should be specialized by clients!"
(dolist (obj2 *objects-with-relations*)
(cond ((intersects-p obj obj2)
(store-intersection-between obj obj2))
((inside-p obj obj2)
(store-inside-between obj obj2)))))
(defmethod initialize-instance :after ((obj geom-thing-with-relations) &rest initargs)
(declare (ignore initargs))
(calculate-relations obj)
(push obj *objects-with-relations*))
(defmethod delete-object progn ((obj geom-thing-with-relations) &key)
(setf *objects-with-relations*
(delete obj *objects-with-relations*))
(remove-all-relations obj))
;;;
;;;
;;;
(defmethod remove-all-relations ((obj geom-thing-with-relations))
(dolist (i (intersects obj))
(delete-intersection-between i obj)))
(defmethod remove-all-relations :after ((obj geom-polygon-with-relations))
(dolist (c (contains obj))
(delete-inside-between c obj)))
;;;
;;; INTERSECTS-Relation
;;;
(defmethod store-intersection-between ((obj1 geom-thing-with-relations)
(obj2 geom-thing-with-relations))
(pushnew obj2 (intersects obj1))
(pushnew obj1 (intersects obj2)))
;;;
;;; fuer Punkte:
;;;
(defmethod store-intersection-between :after ((obj1 geom-point-with-relations)
(obj2 geom-line-with-relations))
(pushnew obj2 (intersects-lines obj1))
(pushnew obj1 (intersects-points obj2)))
(defmethod store-intersection-between :after ((obj1 geom-point-with-relations)
(obj2 geom-chain-with-relations))
(pushnew obj2 (intersects-chains obj1))
(pushnew obj1 (intersects-points obj2)))
(defmethod store-intersection-between :after ((obj1 geom-point-with-relations)
(obj2 geom-polygon-with-relations))
(pushnew obj2 (intersects-polygons obj1))
(pushnew obj1 (intersects-points obj2)))
;;;
;;; fuer Linien:
;;;
(defmethod store-intersection-between :after ((obj1 geom-line-with-relations)
(obj2 geom-point-with-relations))
(pushnew obj2 (intersects-points obj1))
(pushnew obj1 (intersects-lines obj2)))
(defmethod store-intersection-between :after ((obj1 geom-line-with-relations)
(obj2 geom-line-with-relations))
(pushnew obj2 (intersects-lines obj1))
(pushnew obj1 (intersects-lines obj2)))
(defmethod store-intersection-between :after ((obj1 geom-line-with-relations)
(obj2 geom-chain-with-relations))
(pushnew obj2 (intersects-chains obj1))
(pushnew obj1 (intersects-lines obj2)))
(defmethod store-intersection-between :after ((obj1 geom-line-with-relations)
(obj2 geom-polygon-with-relations))
(pushnew obj2 (intersects-polygons obj1))
(pushnew obj1 (intersects-lines obj2)))
;;;
;;; fuer Ketten:
;;;
(defmethod store-intersection-between :after ((obj1 geom-chain-with-relations)
(obj2 geom-point-with-relations))
(pushnew obj2 (intersects-points obj1))
(pushnew obj1 (intersects-chains obj2)))
(defmethod store-intersection-between :after ((obj1 geom-chain-with-relations)
(obj2 geom-line-with-relations))
(pushnew obj2 (intersects-lines obj1))
(pushnew obj1 (intersects-chains obj2)))
(defmethod store-intersection-between :after ((obj1 geom-chain-with-relations)
(obj2 geom-chain-with-relations))
(pushnew obj2 (intersects-chains obj1))
(pushnew obj1 (intersects-chains obj2)))
(defmethod store-intersection-between :after ((obj1 geom-chain-with-relations)
(obj2 geom-polygon-with-relations))
(pushnew obj2 (intersects-polygons obj1))
(pushnew obj1 (intersects-chains obj2)))
;;;
;;; fuer Polygone:
;;;
(defmethod store-intersection-between :after ((obj1 geom-polygon-with-relations)
(obj2 geom-point-with-relations))
(pushnew obj2 (intersects-points obj1))
(pushnew obj1 (intersects-polygons obj2)))
(defmethod store-intersection-between :after ((obj1 geom-polygon-with-relations)
(obj2 geom-line-with-relations))
(pushnew obj2 (intersects-lines obj1))
(pushnew obj1 (intersects-polygons obj2)))
(defmethod store-intersection-between :after ((obj1 geom-polygon-with-relations)
(obj2 geom-chain-with-relations))
(pushnew obj2 (intersects-chains obj1))
(pushnew obj1 (intersects-polygons obj2)))
(defmethod store-intersection-between :after ((obj1 geom-polygon-with-relations)
(obj2 geom-polygon-with-relations))
(pushnew obj2 (intersects-polygons obj1))
(pushnew obj1 (intersects-polygons obj2)))
;;;
;;;
;;;
(defmethod delete-intersection-between ((obj1 geom-thing-with-relations)
(obj2 geom-thing-with-relations))
(setf (intersects obj1) (delete obj2 (intersects obj1))
(intersects obj2) (delete obj1 (intersects obj2))))
;;;
;;; fuer Punkte:
;;;
(defmethod delete-intersection-between :after ((obj1 geom-point-with-relations)
(obj2 geom-line-with-relations))
(setf (intersects-lines obj1) (delete obj2 (intersects-lines obj1))
(intersects-points obj2) (delete obj1 (intersects-points obj2))))
(defmethod delete-intersection-between :after ((obj1 geom-point-with-relations)
(obj2 geom-chain-with-relations))
(setf (intersects-chains obj1) (delete obj2 (intersects-chains obj1))
(intersects-points obj2) (delete obj1 (intersects-points obj2))))
(defmethod delete-intersection-between :after ((obj1 geom-point-with-relations)
(obj2 geom-polygon-with-relations))
(setf (intersects-polygons obj1) (delete obj2 (intersects-polygons obj1))
(intersects-points obj2) (delete obj1 (intersects-points obj2))))
;;;
;;; fuer Linien:
;;;
(defmethod delete-intersection-between :after ((obj1 geom-line-with-relations)
(obj2 geom-point-with-relations))
(setf (intersects-points obj1) (delete obj2 (intersects-points obj1))
(intersects-lines obj2) (delete obj1 (intersects-lines obj2))))
(defmethod delete-intersection-between :after ((obj1 geom-line-with-relations)
(obj2 geom-line-with-relations))
(setf (intersects-lines obj1) (delete obj2 (intersects-lines obj1))
(intersects-lines obj2) (delete obj1 (intersects-lines obj2))))
(defmethod delete-intersection-between :after ((obj1 geom-line-with-relations)
(obj2 geom-chain-with-relations))
(setf (intersects-chains obj1) (delete obj2 (intersects-chains obj1))
(intersects-lines obj2) (delete obj1 (intersects-lines obj2))))
(defmethod delete-intersection-between :after ((obj1 geom-line-with-relations)
(obj2 geom-polygon-with-relations))
(setf (intersects-polygons obj1) (delete obj2 (intersects-polygons obj1))
(intersects-lines obj2) (delete obj1 (intersects-lines obj2))))
;;;
;;; fuer Ketten:
;;;
(defmethod delete-intersection-between :after ((obj1 geom-chain-with-relations)
(obj2 geom-point-with-relations))
(setf (intersects-points obj1) (delete obj2 (intersects-points obj1))
(intersects-chains obj2) (delete obj1 (intersects-chains obj2))))
(defmethod delete-intersection-between :after ((obj1 geom-chain-with-relations)
(obj2 geom-line-with-relations))
(setf (intersects-lines obj1) (delete obj2 (intersects-lines obj1))
(intersects-chains obj2) (delete obj1 (intersects-chains obj2))))
(defmethod delete-intersection-between :after ((obj1 geom-chain-with-relations)
(obj2 geom-chain-with-relations))
(setf (intersects-chains obj1) (delete obj2 (intersects-chains obj1))
(intersects-chains obj2) (delete obj1 (intersects-chains obj2))))
(defmethod delete-intersection-between :after ((obj1 geom-chain-with-relations)
(obj2 geom-polygon-with-relations))
(setf (intersects-polygons obj1) (delete obj2 (intersects-polygons obj1))
(intersects-chains obj2) (delete obj1 (intersects-chains obj2))))
;;;
;;; fuer Polygone:
;;;
(defmethod delete-intersection-between :after ((obj1 geom-polygon-with-relations)
(obj2 geom-point-with-relations))
(setf (intersects-points obj1) (delete obj2 (intersects-points obj1))
(intersects-polygons obj2) (delete obj1 (intersects-polygons obj2))))
(defmethod delete-intersection-between :after ((obj1 geom-polygon-with-relations)
(obj2 geom-line-with-relations))
(setf (intersects-lines obj1) (delete obj2 (intersects-lines obj1))
(intersects-polygons obj2) (delete obj1 (intersects-polygons obj2))))
(defmethod delete-intersection-between :after ((obj1 geom-polygon-with-relations)
(obj2 geom-chain-with-relations))
(setf (intersects-chains obj1) (delete obj2 (intersects-chains obj1))
(intersects-polygons obj2) (delete obj1 (intersects-polygons obj2))))
(defmethod delete-intersection-between :after ((obj1 geom-polygon-with-relations)
(obj2 geom-polygon-with-relations))
(setf (intersects-polygons obj1) (delete obj2 (intersects-polygons obj1))
(intersects-polygons obj2) (delete obj1 (intersects-polygons obj2))))
;;;
;;; INSIDE-Relation
;;;
(defmethod store-inside-between ((obj1 geom-thing-with-relations)
(obj2 geom-polygon-with-relations))
(pushnew obj2 (inside obj1))
(pushnew obj1 (contains obj2)))
;;;
;;;
;;;
(defmethod store-inside-between :after ((obj1 geom-point-with-relations)
(obj2 geom-polygon-with-relations))
(pushnew obj1 (contains-points obj2)))
(defmethod store-inside-between :after ((obj1 geom-line-with-relations)
(obj2 geom-polygon-with-relations))
(pushnew obj1 (contains-lines obj2)))
(defmethod store-inside-between :after ((obj1 geom-chain-with-relations)
(obj2 geom-polygon-with-relations))
(pushnew obj1 (contains-chains obj2)))
(defmethod store-inside-between :after ((obj1 geom-polygon-with-relations)
(obj2 geom-polygon-with-relations))
(pushnew obj1 (contains-polygons obj2)))
;;;
;;;
;;;
(defmethod delete-inside-between :after ((obj1 geom-thing-with-relations)
(obj2 geom-polygon-with-relations))
(setf (inside obj1) (delete obj2 (inside obj1))
(contains obj2) (delete obj1 (contains obj2))))
;;;
;;;
;;;
(defmethod delete-inside-between :after ((obj1 geom-point-with-relations)
(obj2 geom-polygon-with-relations))
(setf (contains-points obj2) (delete obj1 (contains-points obj2))))
(defmethod delete-inside-between :after ((obj1 geom-line-with-relations)
(obj2 geom-polygon-with-relations))
(setf (contains-lines obj2) (delete obj1 (contains-lines obj2))))
(defmethod delete-inside-between :after ((obj1 geom-chain-with-relations)
(obj2 geom-polygon-with-relations))
(setf (contains-chains obj2) (delete obj1 (contains-chains obj2))))
(defmethod delete-inside-between :after ((obj1 geom-polygon-with-relations)
(obj2 geom-polygon-with-relations))
(setf (contains-polygons obj2) (delete obj1 (contains-polygons obj2))))
| 13,910 | Common Lisp | .lisp | 287 | 44.41115 | 107 | 0.74168 | lambdamikel/VISCO | 9 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | b650ea45b679025c7d61a0a9fe388fce2b3a5e7202acbf2f4302a8c289731647 | 11,725 | [
-1
] |
11,799 | package.lisp | MULCH-dev_MULCH/package.lisp | ;;;; This file is part of MULCH.
;;;;
;;;;MULCH is free software: you can redistribute it and/or modify
;;;;it under the terms of the GNU General Public License as published by
;;;;the Free Software Foundation, either version 3 of the License, or
;;;;(at your option) any later version.
;;;;
;;;;MULCH 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 General Public License for more details.
;;;;
;;;;You should have received a copy of the GNU General Public License
;;;;along with MULCH. If not, see <http://www.gnu.org/licenses/>.
;;;; package.lisp
(defpackage #:mulch
(:use #:cl))
| 733 | Common Lisp | .lisp | 17 | 41.823529 | 72 | 0.729313 | MULCH-dev/MULCH | 9 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 2d9f3d2c75b4e070c07a59689436686274a04c41081eb36595c3027d03259053 | 11,799 | [
-1
] |
11,800 | main.lisp | MULCH-dev_MULCH/main.lisp | ;;;; This file is part of MULCH.
;;;;
;;;;MULCH is free software: you can redistribute it and/or modify
;;;;it under the terms of the GNU General Public License as published by
;;;;the Free Software Foundation, either version 3 of the License, or
;;;;(at your option) any later version.
;;;;
;;;;MULCH 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 General Public License for more details.
;;;;
;;;;You should have received a copy of the GNU General Public License
;;;;along with MULCH. If not, see <http://www.gnu.org/licenses/>.
;;;; main.lisp
(in-package #:mulch)
;;; "MULCH" goes here. Hacks and glory await!
(dolist (files ("server.lisp" "structs.lisp" "io.lisp") (load files))) | 831 | Common Lisp | .lisp | 17 | 47.764706 | 113 | 0.725369 | MULCH-dev/MULCH | 9 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | fd42daab6eeae4ebf5603104eff75355524948abf359dc58ce6a121ad75fae10 | 11,800 | [
-1
] |
11,801 | structs.lisp | MULCH-dev_MULCH/structs.lisp | #| This file is part of MULCH.
MULCH is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. |# #|
MULCH 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 General Public License for more details.
You should have received a copy of the GNU General Public License
;along with MULCH. If not, see <http://www.gnu.org/licenses/>.|#
;structs.lisp
;Rooms, people, objects...
(defstruct locale key name light north east south west northeast southwest northwest southeast players objects)
;Key identifies it for me.
;Name is the name associated with it in-game, so while key could be "living-room-1", name would be "Fred Foobar's Living Room"
;! Put this in a hash table, just like users!
(defparameter *rooms* (make-hash-table))
;Create an analogous objects-at
(defun players-at ()
(let ((player-list ()))
(labels ((players-at-indiv (room vals)
(maphash #'(lambda (players-i vals)
(if (equalp (player-location players-i) (locale-name room))
(cons players-i player-list))) *users*)
(setf (locale-players room) player-list)))
(maphash #'players-at-indiv *rooms*))))
;;Maybe a hash table wasn't the *best* idea. I don't seem to be doing anything with the values
(defstruct player
name
password
gender
species
char-class
(health 500)
(mana 100)
(level 0)
(experience 0)
stream
(location *starting-location*)
(saved-location *starting-location*)
conviction
charisma
credibility
strength
dexterity
(inventory ()))
;Objects-at will probably have a cleaner design--I'll make an alist of objects and their locations, so it'll be easier to go through it...
;Also, write a function that dolists through the players and if their experience is above, say, 100, then incf their level and setf the experience to their experience minus 100. Have this running at all times.
(defun find-player-from-stream (stream)
(labels ((find-player-from-stream-aux (players-i vals)
(if (equalp (player-stream players-i) stream)
players-i)))
(maphash #'find-player-from-stream-aux *users*)))
| 2,381 | Common Lisp | .lisp | 54 | 40.759259 | 209 | 0.741126 | MULCH-dev/MULCH | 9 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | da50b463a7409d2a7dd89bea081445e240a0ba1fc539db37936e95c5f7cb5b0e | 11,801 | [
-1
] |
11,802 | MULCH.asd | MULCH-dev_MULCH/MULCH.asd | ;;;; This file is part of MULCH.
;;;;
;;;;MULCH is free software: you can redistribute it and/or modify
;;;;it under the terms of the GNU General Public License as published by
;;;;the Free Software Foundation, either version 3 of the License, or
;;;;(at your option) any later version.
;;;;
;;;;MULCH 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 General Public License for more details.
;;;;
;;;;You should have received a copy of the GNU General Public License
;;;;along with MULCH. If not, see <http://www.gnu.org/licenses/>.
;;;; MULCH.asd
(asdf:defsystem #:mulch
:serial t
:depends-on (#:usocket #:ironclad) ;Once I find a good time library, or how to work with CL's internal time stuff, I'll probably add that here
:components ((:file "package")
(:file "main")
(:file "server")
(:file "structs")
(:file "io")))
| 1,013 | Common Lisp | .asd | 23 | 40.956522 | 144 | 0.693009 | MULCH-dev/MULCH | 9 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:49 AM (Europe/Amsterdam) | 0d5d4c38490bf54ba7d20dc79671e88af84380b53f5d7b18d0373170ded4aaf7 | 11,802 | [
-1
] |
11,821 | ircd.lisp | davazp_cl-ircd/ircd.lisp | ;;; cl-ircd.lisp --- A Common Lisp IRC Server
;;; Copyright (C) 2012, 2014 David Vázquez
;; This file is part of cl-ircd.
;;
;; cl-ircd is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; cl-ircd 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 General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with cl-ircd. If not, see <http://www.gnu.org/licenses/>.
(defpackage :cl-ircd
(:use :cl :cl-ircd-system)
(:nicknames :ircd)
(:export #:start-server #:stop-server))
(in-package :cl-ircd)
(defvar *servername* "clircd")
(defvar *server*)
;;; Return X if it is a list, or a list whose single element is X
;;; otherwise.
(defun mklist (x)
(if (listp x) x (list x)))
;;; Map FUNCTION on list and append the resulting lists.
(defun mappend (function list)
(reduce #'append (mapcar function list)))
(defun first-line (string)
(with-input-from-string (in string)
(read-line in nil)))
;;; Remove X from PLACE and set the result in PLACE again.
(defmacro removef (x place)
(let ((placevar (gensym))
(valuevar (gensym)))
`(let ((,valuevar ,x)
(,placevar ,place))
(setf ,place (remove ,valuevar ,placevar)))))
;;; Compare two characters case-insensitively.
(defun char-ci= (char1 char2)
(char= (char-upcase char1) (char-upcase char2)))
;;; Compare two strings case-insensitively.
(defun string-ci= (string1 string2)
(every #'char-ci= string1 string2))
;;; Check if CHAR is a whitespace (newline or space).
(defun whitespacep (char)
(or (char= char #\newline) (char= char #\space)))
;;; Read characters from STREAM until it finds a space, then discard
;;; all the remainder spaces.
(defun parse (stream)
(with-output-to-string (out)
(loop
for ch = (peek-char nil stream nil)
until (or (null ch) (whitespacep ch))
do (write-char (read-char stream) out))
(loop
for ch = (peek-char nil stream nil)
while (and ch (whitespacep ch))
do (read-char stream))))
;;; Classes
(defclass server ()
((port
:initarg :port
:reader server-port)
(uptime
:initarg :uptime
:initform (get-universal-time)
:reader server-uptime)
(nicknames
:initform (make-hash-table :test #'equalp)
:reader server-nicknames)
(users
:initform nil
:type list
:accessor server-users)
(channels
:initform (make-hash-table :test #'equalp)
:reader server-channels)
(socket
:initarg :socket
:reader server-socket)))
(defun server-channel-list (&optional (server *server*))
(let ((result nil))
(maphash (lambda (key value)
(declare (ignore key))
(push value result))
(server-channels server))
result))
(defclass channel ()
((name
:initarg :name
:reader channel-name)
(topic
:initarg :topic
:initform nil
:type (or null string)
:accessor channel-topic)
(users
:initform nil
:type list
:accessor channel-users)))
(defmethod print-object ((x channel) stream)
(print-unreadable-object (x stream :type t)
(write (channel-name x) :stream stream)))
(defclass client ()
((nickname
:type (or string null)
:initform nil
:accessor user-nickname)
(socket
:initarg :socket
:reader user-socket)
(hostname
:type string
:accessor user-hostname)))
(defclass user (client)
((username
:type string
:accessor user-username)
(registered-p
:initform nil
:type boolean
:accessor user-registered-p)
(channels
:initform nil
:type list
:accessor user-channels)
(realname
:type string
:accessor user-realname)
(input-buffer
:initform (make-string-output-stream)
:reader user-input-buffer)
(last-activity
:initform (get-universal-time)
:type integer
:accessor last-activity)))
(defun start-server (&key (port 6667) (host usocket:*wildcard-host*))
(let* ((socket (usocket:socket-listen host port :reuse-address t :backlog 20))
(server (make-instance 'server :port port :socket socket)))
(bt:make-thread (lambda () (loop (accept-connection server)))
:name "IRCD Acceptor")
(bt:make-thread (lambda () (loop (handle-event server)))
:name "IRCD Event processor")
(setf *server* server)))
(defun stop-server ()
(ignore-errors
(usocket:socket-close (server-socket *server*)))
(dolist (user (server-users *server*))
(ignore-errors
(usocket:socket-close (user-socket user)))))
(defun accept-connection (server)
(ignore-errors
(let ((socket (usocket:socket-accept (server-socket server))))
(push (make-instance 'user :socket socket) (server-users server)))))
(defvar *user*)
(defun handle-event (server)
(let ((sockets (mapcar #'user-socket (server-users server))))
(cond
;; If there are not users, then go to sleep.
((null sockets)
(sleep 1))
(t
(usocket:wait-for-input sockets :timeout 5 :ready-only t)
(dolist (user (server-users server))
(let ((*user* user))
;; Collect data in the input buffer of the user until newline
;; is found. Then process the input line.
(with-slots (socket input-buffer) user
(let ((stream (usocket:socket-stream socket)))
(handler-case
(loop for ch = (read-char-no-hang stream) while ch do
(if (char= ch #\newline)
(let ((line (string-right-trim #(#\Return) (get-output-stream-string input-buffer))))
(process-input user line))
(write-char ch input-buffer)))
(error ()
(irc-quit)))))))))))
(defvar *command-table*
(make-hash-table :test #'equalp))
(defmacro define-command (name args &body body)
(let ((funcname (concatenate 'string "IRC-" (prin1-to-string name))))
`(progn (defun ,(intern funcname) ,args ,@body)
(setf (gethash ,(prin1-to-string name) *command-table*) ',(intern funcname)))))
(defun parse-input-arguments* (in)
(loop
for ch = (peek-char nil in nil) while ch
collect (if (char= ch #\:)
(progn (read-char in)
(if (not (peek-char nil in nil nil))
""
(read-line in nil)))
(parse in))))
(defun parse-input-arguments (string)
(with-input-from-string (in string)
(parse-input-arguments* in)))
(defun parse-input-line (string)
(with-input-from-string (in string)
(values (and (char= (peek-char nil in) #\:)
(progn (read-char in) (parse in)))
(parse in)
(parse-input-arguments* in))))
(defun parse-list (string)
(when (and string (plusp (length string)))
(loop
for begin = 0 then (1+ end)
for end = (position #\, string :start begin)
collect (subseq string begin end)
while end)))
;;; Send a message: SOURCE COMMAND ARGUMENTS... to RECIPIENTS.
(defun message (recipients source command &rest arguments)
(dolist (recipient (mklist recipients))
(let ((stream ( usocket:socket-stream (user-socket recipient))))
(when (output-stream-p stream)
(let ((stream (make-broadcast-stream *standard-output* stream)))
(when source
(format stream ":~a " source))
(if (numberp command)
(format stream "~3,'0d" command)
(princ command stream))
(loop for (arg more) on arguments
while more do (format stream " ~a" arg)
finally (format stream " ~@[~*:~]~a" (or (find #\space arg) (string= arg "")) arg))
(write-char #\Return stream)
(terpri stream)
(force-output stream))))))
;;; Send a message: <server> COMMAND <user> ARGUMENTS to the user.
(defun rpl (command &rest arguments)
(apply #'message *user* *servername* command (user-nickname *user*) arguments))
;;; Send a message: user COMMAND ARGUMENTS... to RECIPIENTS.
(defun propagate (recipients command &rest arguments)
(let ((source
(format nil "~a!~a@~a"
(user-nickname *user*)
(user-username *user*)
(user-hostname *user*))))
(apply #'message recipients source command arguments)))
(defun visible-users (user)
(delete-duplicates (mappend #'channel-users (user-channels user))))
(defun process-input (user line)
(format t "<< ~a~%" line)
(when (string= line "")
(return-from process-input))
(multiple-value-bind (source command args)
(parse-input-line line)
(declare (ignorable source))
(setf (last-activity user) (get-universal-time))
(unless (or (user-registered-p *user*)
(find command '("USER" "PASS" "NICK" "PING") :test #'string-ci=))
(err-notregistered))
(let ((handler (gethash command *command-table*)))
(if handler
(with-simple-restart (discard-message "Discard message.")
(catch 'abort-command
(apply handler args)))
(err-unknowncommand :command command)))))
(defun abort-command ()
(throw 'abort-command nil))
;;; IRC Commands
(defun ip-to-string (ip)
(format nil "~a.~a.~a.~a" (aref ip 0) (aref ip 1) (aref ip 2) (aref ip 3)))
(defun timestamp-string (timestamp)
(multiple-value-bind (second minute hour date month year dow daylight timezone)
(decode-universal-time timestamp 0)
(declare (ignore daylight timezone))
(let ((days #("Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"))
(months #("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec")))
(format nil "~a ~a ~d ~d at ~2,'0d:~2,'0d:~2,'0d GMT" (aref days dow) (aref months month)
date year hour minute second))))
(defun try-to-register-user ()
(when (and (slot-boundp *user* 'nickname)
(slot-boundp *user* 'username)
(not (user-registered-p *user*)))
(setf (user-registered-p *user*) t)
(rpl-welcome :nick (user-nickname *user*)
:user (user-username *user*)
:host (user-hostname *user*))
(rpl-yourhost :servername *servername*
:ver *software*)
(rpl-created :date (timestamp-string (server-uptime *server*)))
(rpl-myinfo :servername *servername*
:version *software*
:available-user-modes "i"
:available-channel-modes "o")
;; Send MOTD
(cond
((probe-file "MOTD")
(rpl-motdstart :server *servername*)
(with-open-file (in "MOTD")
(loop
for line = (read-line in nil)
while line
do (loop
for begin = 0 then end
for end = (min (length line) (+ begin 80))
while (< begin end)
do (rpl-motd :text (subseq line begin end)))))
(rpl-endofmotd))
(t
(err-nomotd)))))
;;; Registration commands
(define-command pass (password)
(declare (ignorable password)))
(define-command nick (name)
(with-slots (nicknames) *server*
(when (and (user-registered-p *user*)
(string= name (user-nickname *user*)))
(return-from irc-nick))
;; If the new nickname already exists
(when (gethash name nicknames)
(message *user* *servername* 433 "*" name "Nickname is already in use")
(return-from irc-nick))
;; Register the nickname and propagate it if it is a change.
(remhash (user-nickname *user*) nicknames)
(when (user-registered-p *user*)
(propagate (adjoin *user* (visible-users *user*)) "NICK" name))
(setf (user-nickname *user*) name)
(setf (gethash name (server-nicknames *server*)) *user*)
(try-to-register-user)))
(define-command user (username hostname servername realname)
(declare (ignore hostname servername))
(setf (user-username *user*) username)
(setf (user-realname *user*) realname)
(setf (user-hostname *user*) (ip-to-string (usocket:get-peer-address (user-socket *user*))))
(try-to-register-user))
;;; Channel commands
(defun find-channel (channel-name)
(gethash channel-name (server-channels *server*)))
(defun create-channel (channel-name)
(or (find-channel channel-name)
(let ((channel (make-instance 'channel :name channel-name)))
(setf (gethash channel-name (server-channels *server*)) channel)
channel)))
(defun join-1 (channel-name &optional password)
(declare (ignorable password))
(let ((channel (create-channel channel-name)))
(push *user* (channel-users channel))
(push channel (user-channels *user*))
(propagate (channel-users channel) "JOIN" channel-name)
(if (channel-topic channel)
(rpl-topic :channel channel-name :topic (channel-topic channel))
(rpl-notopic :channel channel-name))
(irc-names channel-name)))
(define-command join (channel-list &optional pass-list)
(when (string= channel-list "0")
(return-from irc-join))
(let ((channels (parse-list channel-list))
(passwds (and pass-list (parse-list channel-list))))
(loop
for channel-name in channels
for passwd-tail = passwds then (cdr passwd-tail)
for passwd = (car passwd-tail)
do (join-1 channel-name passwd))))
(defun part (channel)
(removef channel (user-channels *user*))
(removef *user* (channel-users channel)))
(define-command part (channel-list &optional message)
(dolist (channame (parse-list channel-list))
(let ((channel (find-channel channame)))
(apply #'propagate (channel-users channel) "PART" (channel-name channel) (mklist message))
(part channel))))
(define-command names (&optional channame-list target)
(declare (ignore target))
;; TODO: If CHANNEL-NAME is omitted, list all the channels.
(when channame-list
(let ((channels (remove nil (mapcar #'find-channel (parse-list channame-list)))))
(dolist (channel channels)
(let* ((name (channel-name channel))
;; :<servername> 353 nickname = channel-name :<nicknames>....\r\n
(width (- 512 (length *servername*) 12 (length (user-nickname *user*)) (length name)))
(remainder width)
(nicknames nil))
(dolist (user (channel-users channel))
(when (< remainder (length (user-nickname user)))
(rpl 353 "=" name (format nil "~{~a~^ ~}" nicknames)) ; RPL_NAMREPLY
(setf nicknames nil)
(setf remainder width))
(decf remainder (1+ (length (user-nickname user))))
(push (user-nickname user) nicknames))
(when nicknames
(rpl 353 "=" name (format nil "~{~a~^ ~}" nicknames))) ; RPL_NAMREPLY
(rpl 366 name "End of NAMES list") ; RPL_ENDOFNAMES
)))))
(define-command list (&optional channels target)
(declare (ignore target))
(let ((list (if (and channels (plusp (length channels)))
(mapcar #'find-channel (parse-list channels))
(server-channel-list))))
(rpl-liststart)
(dolist (item list)
(rpl-list :channel (channel-name item)
:n-visible (length (channel-users item))
:topic (channel-topic item)))
(rpl-listend)))
(define-command mode (target &optional mode)
(declare (ignore target mode)))
(define-command topic (channame &optional message)
(let ((channel (find-channel channame)))
(when channel
(if (null message)
(rpl-topic :channel channame :topic (channel-topic channel))
(let ((newtopic (if (string= message "") nil message)))
(setf (channel-topic channel) newtopic)
(propagate (channel-users channel) "TOPIC" channame message))))))
;;; Message commands
(defun find-user (nickname)
(gethash nickname (server-nicknames *server*)))
(defun list-of-users (string)
(if (find (char string 0) "#")
(let ((channel (find-channel string)))
(if channel
(channel-users channel)))
(list (find-user string))))
(define-command privmsg (recipient message)
(let ((users (list-of-users recipient)))
(if (null users)
(err-nosuchnick :nickname recipient)
(propagate (remove *user* users) "PRIVMSG" recipient message))))
(define-command notice (recipient message)
(let ((users (list-of-users recipient)))
(if (null users)
(err-nosuchnick :nickname recipient)
(propagate (remove *user* users) "NOTICE" recipient message))))
;;; Misc
(define-command ping (server1 &optional server2)
(declare (ignore server2))
(message *user* nil "PONG" server1))
(define-command quit (&optional message)
(ignore-errors
(apply #'propagate (visible-users *user*) "QUIT" (mklist message)))
(ignore-errors
(message *user* "ERROR"
(format nil "Closing Link: ~a ~@[~a~]"
(user-hostname *user*)
message)))
(removef *user* (server-users *server*))
(mapc #'part (user-channels *user*))
(remhash (user-nickname *user*) (server-nicknames *server*))
(ignore-errors
(usocket:socket-close (user-socket *user*))))
;;; cl-ircd.lisp ends here
| 17,565 | Common Lisp | .lisp | 443 | 33 | 113 | 0.630616 | davazp/cl-ircd | 8 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | ab589828bc85562a794277bf7371a6d24d1abb9c050c001c534eda03af662440 | 11,821 | [
-1
] |
11,822 | replies.lisp | davazp_cl-ircd/replies.lisp | ;;; replies.lisp ---
;;; Copyright 2014 David Vázquez
;; This file is part of cl-ircd.
;;
;; cl-ircd is free software: you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; cl-ircd 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
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with cl-ircd. If not, see <http://www.gnu.org/licenses/>.
(in-package :cl-ircd)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defun intern-docspec-variable (name)
(loop
for (from to) in '((#\space #\-) (#\# #\n))
do (setq name (nsubstitute to from name)))
(intern (string-upcase name)))
(defun read-docspec-variable (stream)
(with-output-to-string (var)
(loop
for ch = (read-char stream)
until (char= ch #\>)
do (write-char ch var))))
(defun convert-reply-docspec (string)
"Given a reply documentation spec, return two values:
- A list of symbols, which are variables that occur in the
specification. The symbol names are canonalized. See below for some
examples.
- A list of arguments for the reply. Each argument is in the form
(FMT ARGS) where FMT is a format-like control string and ARGS are
symbols from the previous list."
(when string
(let ((variable-occurences nil))
(with-open-stream (stream (make-string-output-stream))
(with-input-from-string (in string)
;; Collect variable ocurrences in the string, replacing
;; them by _~a_ format-like placeholders.
(loop
for ch = (read-char in nil)
while ch
do (if (char= ch #\<)
(let ((var (read-docspec-variable in)))
(push (intern-docspec-variable var) variable-occurences)
(write-string "~a" stream))
(write-char ch stream)))
(setq variable-occurences (nreverse variable-occurences))
;; Parse the resulting string as arguments of a IRC
;; message. Note it is done _after_ replacing variables,
;; because they could contain space and break the parser.
;; Each argument is matched with the variables it uses.
(values (remove-duplicates variable-occurences)
(mapcar (lambda (arg)
(let ((count (count #\~ arg)))
(prog1 (cons arg (subseq variable-occurences 0 count))
(setq variable-occurences (nthcdr count variable-occurences)))))
(parse-input-arguments (get-output-stream-string stream))))))))))
(defmacro defreply (code name &optional string abort)
(multiple-value-bind (variables format-arguments)
(convert-reply-docspec string)
`(defun ,name (&key ,@variables)
(declare (ignorable ,@variables))
(rpl ,(format nil "~3,'0d" code)
,@(mapcar (lambda (format-argument)
`(format nil "~?"
,(car format-argument)
(list ,@(cdr format-argument))))
format-arguments))
,(when abort `(abort-command)))))
(defmacro deferr (code name &optional string)
`(defreply ,code ,name ,string t))
;;; Command responses
;;; -----------------
(defreply 001 RPL-WELCOME ":Welcome to the Internet Relay Network <nick>!<user>@<host>")
(defreply 002 RPL-YOURHOST ":Your host is <servername>, running version <ver>")
(defreply 003 RPL-CREATED ":This server was created <date>")
(defreply 004 RPL-MYINFO "<servername> <version> <available user modes> <available channel modes>")
(defreply 005 RPL-BOUNCE ":Try server <server name>, port <port number>")
;; (defreply 302 RPL-USERHOST ":*1<reply> *( \" \" <reply> )")
;; (defreply 303 RPL-ISON ":*1<nick> *( \" \" <nick> )")
(defreply 301 RPL-AWAY "<nick> :<away message>")
(defreply 305 RPL-UNAWAY ":You are no longer marked as being away")
(defreply 306 RPL-NOWAWAY ":You have been marked as being away")
(defreply 311 RPL-WHOISUSER "<nick> <user> <host> * :<real name>")
(defreply 312 RPL-WHOISSERVER "<nick> <server> :<server info>")
(defreply 313 RPL-WHOISOPERATOR "<nick> :is an IRC operator")
(defreply 317 RPL-WHOISIDLE "<nick> <integer> :seconds idle")
(defreply 318 RPL-ENDOFWHOIS "<nick> :End of WHOIS list")
;; (defreply 319 RPL-WHOISCHANNELS "<nick> :*( ( \"@\" / \"+\" ) <channel> \" \" )")
(defreply 314 RPL-WHOWASUSER "<nick> <user> <host> * :<real name>")
(defreply 369 RPL-ENDOFWHOWAS "<nick> :End of WHOWAS")
(defreply 321 RPL-LISTSTART)
(defreply 322 RPL-LIST "<channel> <# visible> :<topic>")
(defreply 323 RPL-LISTEND ":End of LIST")
(defreply 325 RPL-UNIQOPIS "<channel> <nickname>")
(defreply 324 RPL-CHANNELMODEIS "<channel> <mode> <mode params>")
(defreply 331 RPL-NOTOPIC "<channel> :No topic is set")
(defreply 332 RPL-TOPIC "<channel> :<topic>")
(defreply 341 RPL-INVITING "<channel> <nick>")
(defreply 342 RPL-SUMMONING "<user> :Summoning user to IRC")
(defreply 346 RPL-INVITELIST "<channel> <invitemask>")
(defreply 347 RPL-ENDOFINVITELIST "<channel> :End of channel invite list")
(defreply 348 RPL-EXCEPTLIST "<channel> <exceptionmask>")
(defreply 349 RPL-ENDOFEXCEPTLIST "<channel> :End of channel exception list")
(defreply 351 RPL-VERSION "<version>.<debuglevel> <server> :<comments>")
;; (352 RPL-WHOREPLY "<channel> <user> <host> <server> <nick>
;; ( "H" / "G" > ["*"] [ ( "@" / "+" ) ]
;; :<hopcount> <real name>")
(defreply 315 RPL-ENDOFWHO "<name> :End of WHO list")
;; (353 RPL-NAMREPLY
;; "( "=" / "*" / "@" ) <channel>
;; :[ "@" / "+" ] <nick> *( " " [ "@" / "+" ] <nick> ))
(defreply 366 RPL-ENDOFNAMES "<channel> :End of NAMES list")
(defreply 364 RPL-LINKS "<mask> <server> :<hopcount> <server info>")
(defreply 365 RPL-ENDOFLINKS "<mask> :End of LINKS list")
(defreply 367 RPL-BANLIST "<channel> <banmask>")
(defreply 368 RPL-ENDOFBANLIST "<channel> :End of channel ban list")
(defreply 371 RPL-INFO ":<string>")
(defreply 374 RPL-ENDOFINFO ":End of INFO list")
(defreply 375 RPL-MOTDSTART ":- <server> Message of the day - ")
(defreply 372 RPL-MOTD ":- <text>")
(defreply 376 RPL-ENDOFMOTD ":End of MOTD command")
(defreply 381 RPL-YOUREOPER ":You are now an IRC operator")
(defreply 382 RPL-REHASHING "<config file> :Rehashing")
(defreply 383 RPL-YOURESERVICE "You are service <servicename>")
(defreply 391 RPL-TIME "<server> :<string showing server's local time>")
(defreply 392 RPL-USERSSTART ":UserID Terminal Host")
(defreply 393 RPL-USERS ":<username> <ttyline> <hostname>")
(defreply 394 RPL-ENDOFUSERS ":End of users")
(defreply 395 RPL-NOUSERS ":Nobody logged in")
(defreply 200 RPL-TRACELINK "Link <version & debug level> <destination> <next server> V<protocol version> <link uptime in seconds> <backstream sendq> <upstream sendq>")
(defreply 201 RPL-TRACECONNECTING "Try. <class> <server>")
(defreply 202 RPL-TRACEHANDSHAKE "H.S. <class> <server>")
(defreply 203 RPL-TRACEUNKNOWN "???? <class> [<client IP address in dot form>]")
(defreply 204 RPL-TRACEOPERATOR "Oper <class> <nick>")
(defreply 205 RPL-TRACEUSER "User <class> <nick>")
(defreply 206 RPL-TRACESERVER "Serv <class> <int>S <int>C <server> <nick!user|*!*>@<host|server> V<protocol version>")
(defreply 207 RPL-TRACESERVICE "Service <class> <name> <type> <active type>")
(defreply 208 RPL-TRACENEWTYPE "<newtype> 0 <client name>")
(defreply 209 RPL-TRACECLASS "Class <class> <count>")
(defreply 261 RPL-TRACELOG "File <logfile> <debug level>")
(defreply 262 RPL-TRACEEND "<server name> <version & debug level> :End of TRACE")
(defreply 211 RPL-STATSLINKINFO "<linkname> <sendq> <sent messages> <sent Kbytes> <received messages> <received Kbytes> <time open>")
(defreply 212 RPL-STATSCOMMANDS "<command> <count> <byte count> <remote count>")
(defreply 219 RPL-ENDOFSTATS "<stats letter> :End of STATS report")
(defreply 242 RPL-STATSUPTIME ":Server Up %d days %d:%02d:%02d")
(defreply 243 RPL-STATSOLINE "O <hostmask> * <name>")
(defreply 221 RPL-UMODEIS "<user mode string>")
(defreply 234 RPL-SERVLIST "<name> <server> <mask> <type> <hopcount> <info>")
(defreply 235 RPL-SERVLISTEND "<mask> <type> :End of service listing")
(defreply 251 RPL-LUSERCLIENT ":There are <integer> users and <integer> services on <integer> servers")
(defreply 252 RPL-LUSEROP "<integer> :operator(s) online")
(defreply 253 RPL-LUSERUNKNOWN "<integer> :unknown connection(s)")
(defreply 254 RPL-LUSERCHANNELS "<integer> :channels formed")
(defreply 255 RPL-LUSERME ":I have <integer> clients and <integer> servers")
(defreply 256 RPL-ADMINME "<server> :Administrative info")
(defreply 257 RPL-ADMINLOC1 ":<admin info>")
(defreply 258 RPL-ADMINLOC2 ":<admin info>")
(defreply 259 RPL-ADMINEMAIL ":<admin info>")
(defreply 263 RPL-TRYAGAIN "<command> :Please wait a while and try again.")
;;; Errors replies
;;; --------------
(defmacro deferr (code name &optional string)
`(defreply ,code ,name ,string t))
(deferr 401 ERR-NOSUCHNICK "<nickname> :No such nick/channel")
(deferr 402 ERR-NOSUCHSERVER "<server name> :No such server")
(deferr 403 ERR-NOSUCHCHANNEL "<channel name> :No such channel")
(deferr 404 ERR-CANNOTSENDTOCHAN "<channel name> :Cannot send to channel")
(deferr 405 ERR-TOOMANYCHANNELS "<channel name> :You have joined too many channels")
(deferr 406 ERR-WASNOSUCHNICK "<nickname> :There was no such nickname")
(deferr 407 ERR-TOOMANYTARGETS "<target> :<error code> recipients. <abort message>")
(deferr 408 ERR-NOSUCHSERVICE "<service name> :No such service")
(deferr 409 ERR-NOORIGIN ":No origin specified")
(deferr 411 ERR-NORECIPIENT ":No recipient given (<command>)")
(deferr 412 ERR-NOTEXTTOSEND ":No text to send")
(deferr 413 ERR-NOTOPLEVEL "<mask> :No toplevel domain specified")
(deferr 414 ERR-WILDTOPLEVEL "<mask> :Wildcard in toplevel domain")
(deferr 415 ERR-BADMASK "<mask> :Bad Server/host mask")
(deferr 421 ERR-UNKNOWNCOMMAND "<command> :Unknown command")
(deferr 422 ERR-NOMOTD ":MOTD File is missing")
(deferr 423 ERR-NOADMININFO "<server> :No administrative info available")
(deferr 424 ERR-FILEERROR ":File error doing <file op> on <file>")
(deferr 431 ERR-NONICKNAMEGIVEN ":No nickname given")
(deferr 432 ERR-ERRONEUSNICKNAME "<nick> :Erroneous nickname")
(deferr 433 ERR-NICKNAMEINUSE "<nick> :Nickname is already in use")
(deferr 436 ERR-NICKCOLLISION "<nick> :Nickname collision KILL from <user>@<host>")
(deferr 437 ERR-UNAVAILRESOURCE "<nick/channel> :Nick/channel is temporarily unavailable")
(deferr 441 ERR-USERNOTINCHANNEL "<nick> <channel> :They aren't on that channel")
(deferr 442 ERR-NOTONCHANNEL "<channel> :You're not on that channel")
(deferr 443 ERR-USERONCHANNEL "<user> <channel> :is already on channel")
(deferr 444 ERR-NOLOGIN "<user> :User not logged in")
(deferr 445 ERR-SUMMONDISABLED ":SUMMON has been disabled")
(deferr 446 ERR-USERSDISABLED ":USERS has been disabled")
(deferr 451 ERR-NOTREGISTERED ":You have not registered")
(deferr 461 ERR-NEEDMOREPARAMS "<command> :Not enough parameters")
(deferr 462 ERR-ALREADYREGISTRED ":Unauthorized command (already registered)")
(deferr 463 ERR-NOPERMFORHOST ":Your host isn't among the privileged")
(deferr 464 ERR-PASSWDMISMATCH ":Password incorrect")
(deferr 465 ERR-YOUREBANNEDCREEP ":You are banned from this server")
(deferr 466 ERR-YOUWILLBEBANNED)
(deferr 467 ERR-KEYSET "<channel> :Channel key already set")
(deferr 471 ERR-CHANNELISFULL "<channel> :Cannot join channel (+l)")
(deferr 472 ERR-UNKNOWNMODE "<char> :is unknown mode char to me for <channel>")
(deferr 473 ERR-INVITEONLYCHAN "<channel> :Cannot join channel (+i)")
(deferr 474 ERR-BANNEDFROMCHAN "<channel> :Cannot join channel (+b)")
(deferr 475 ERR-BADCHANNELKEY "<channel> :Cannot join channel (+k)")
(deferr 476 ERR-BADCHANMASK "<channel> :Bad Channel Mask")
(deferr 477 ERR-NOCHANMODES "<channel> :Channel doesn't support modes")
(deferr 478 ERR-BANLISTFULL "<channel> <char> :Channel list is full")
(deferr 481 ERR-NOPRIVILEGES ":Permission Denied- You're not an IRC operator")
(deferr 482 ERR-CHANOPRIVSNEEDED "<channel> :You're not channel operator")
(deferr 483 ERR-CANTKILLSERVER ":You can't kill a server!")
(deferr 484 ERR-RESTRICTED ":Your connection is restricted!")
(deferr 485 ERR-UNIQOPPRIVSNEEDED ":You're not the original channel operator")
(deferr 491 ERR-NOOPERHOST ":No O-lines for your host")
(deferr 501 ERR-UMODEUNKNOWNFLAG ":Unknown MODE flag")
| 12,807 | Common Lisp | .lisp | 221 | 53.900452 | 168 | 0.694701 | davazp/cl-ircd | 8 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 7e89c255f5ece622f7f67d8684debc8e0d87467762aaac7c5b29952229bdac2c | 11,822 | [
-1
] |
11,823 | cl-ircd.asd | davazp_cl-ircd/cl-ircd.asd | ;;; cl-ircd.asd ---
;; This file is part of cl-ircd.
;;
;; cl-ircd is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; cl-ircd 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 General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with cl-ircd. If not, see <http://www.gnu.org/licenses/>.
(defpackage :cl-ircd-system
(:use :cl :asdf)
(:export #:*version* #:*software*))
(in-package :cl-ircd-system)
(defvar *version* "0.1")
(defvar *software* (format nil "cl-ircd-~a" *version*))
(defsystem :cl-ircd
:name "cl-ircd"
:description "Common Lisp IRC Server"
:version #.*version*
:depends-on (:usocket :bordeaux-threads)
:serial t
:components
((:static-file "README.org")
(:static-file "COPYING")
(:file "ircd")
(:file "replies")))
;;; cl-ircd.asd ends here
| 1,205 | Common Lisp | .asd | 33 | 33.878788 | 71 | 0.699828 | davazp/cl-ircd | 8 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 3216cc22b0275ad51a94db09757d77d55274b8da124f126391c4b8f9087f8401 | 11,823 | [
-1
] |
11,842 | lex.lisp | djr7C4_cl-lex/lex.lisp | ;;;; Defines the lexer generator.
;;;; Copyright (C) 2009 David J. Rosenbaum, email: [email protected]
;;;;
;;;; This program is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation, under version 3 of the License.
;;;;
;;;; This program 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 General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;;
;;;; Copyright (C) 2009 David J. Rosenbaum
;;;; This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
;;;; This is free software, and you are welcome to redistribute it
;;;; under certain conditions; for details see COPYING.
(in-package :cl-lex)
(defmacro with-gensyms ((&rest symbols) &body body)
"Replaces symbols in body with new symbols created by gensym. body is treated as an implicit progn."
`(let (,@(loop for symbol in symbols collect `(,symbol (gensym))))
,@body))
(defmacro define-string-lexer (name &body patterns)
"Defines a function that takes a string and keyword arguments for the start and end of the string and returns a closure
that takes no arguments and will return the next token each time it is called. When the input string is exhausted or no more
matches are found the closure will return nil. Each pattern must be a regular expression or a list of one regular
expression or a list containing a regular expression as the first element and the rest of the elements of the list forming
an implicit progn. If a pattern is a regular expression or a list of one element, then text in the string that matches the
regular expression is ignored. If a pattern is a list of two elements then when the regular expression matches text the
sub-strings that match each register in the regular expression are bound to the symbols that represent the registers. Any
text that matches named registers is bound to a variable with the same name as the register name. If the same name is used
for more than one register then subsequent have the appropriate index appended to their names. If a register is not named,
then text that matches it is bound to $i where i is the index of the register. The entire matching sub-string is bound to
$@. If no text matches a register then its variable is bound to nil. All symbols are interned in the current package when
the macro is expanded. The start and end variables passed to the function are accessible from inside the implicit progn's
from the patterns. Patterns are applied in the order they are provided and multiple patterns cannot be applied to the
same piece of text. Any text that is not matched to a pattern is skipped. The behavior of the regular expressions can be
modified by setting the appropriate variables in the cl-ppcre regex library."
(let (regexes forms (registers (list 0)) register-names (used-register-names (make-hash-table :test #'equal)))
(dolist (pattern patterns)
(multiple-value-bind (regex form)
(if (consp pattern)
(values (car pattern) `(progn ,@(cdr pattern)))
(values pattern nil))
(push regex regexes)
(push form forms)
(push (+ (car registers)
(progn
(push nil register-names)
(do ((i 0 (1+ i)) (open-backslash nil (and (null open-backslash) (char= (char regex i) #\\)))
(open-character-set nil (case (char regex i)
(#\[ (or open-character-set (not open-backslash)))
(#\] (and open-backslash open-character-set))
(t open-character-set)))
(open-parentheses nil (and (null open-backslash)
(null open-character-set)
(char= (char regex i) #\()))
(registers 0 (if open-parentheses
(progn
(if (char= (char regex i) #\?)
(let ((register-name-end (position #\> regex :start i)))
(if (and register-name-end
(< (+ i 3) (length regex))
(char= (char regex (1+ i)) #\<))
(push (do* ((j 1 (1+ j))
(register-base-name
(string-upcase
(subseq regex
(+ i 2)
(1+ (position-if (lambda (char)
(not (member char
'(#\0
#\1
#\2
#\3
#\4
#\5
#\6
#\7
#\8
#\9))))
regex
:from-end t
:end register-name-end)))))
(register-name (string-upcase
(subseq regex
(+ i 2)
register-name-end))
(format nil
"~a~d"
register-base-name
j)))
((not (gethash register-name used-register-names))
(setf (gethash register-name used-register-names) t)
register-name))
register-names)
(error "invalid named register in ~a" regex)))
(let ((register-name (format nil "$~d" (1+ registers))))
(setf (gethash register-name used-register-names) t)
(push register-name register-names)))
(1+ registers))
registers)))
((= i (length regex)) registers)))
1)
registers)))
(let ((total-registers (car registers)))
(setf regexes (nreverse regexes)
forms (nreverse forms)
registers (nreverse (cdr registers))
register-names (nreverse register-names))
(let ((combined-regex (apply #'concatenate (cons 'string (mapcar (lambda (regex)
(concatenate 'string "(" regex ")|"))
regexes)))))
(if (> (length combined-regex) 0)
(setf combined-regex (subseq combined-regex 0 (1- (length combined-regex)))))
(with-gensyms (scanner string start end match-start match-end register-starts register-ends)
`(let* ((cl-ppcre:*allow-named-registers* t) (,scanner (cl-ppcre:create-scanner ,combined-regex)))
(defun ,name (,string &key ((start ,start) 0) ((end ,end) (length ,string)))
(declare (ignorable ,start ,end))
(if (null ,end)
(setf ,end (length ,string)))
(lambda ()
,(if registers
`(loop
(multiple-value-bind (,match-start ,match-end ,register-starts ,register-ends)
(cl-ppcre:scan ,scanner ,string :start ,start :end ,end)
(declare (ignorable ,register-ends))
(if ,match-start
(progn
(if (eql ,match-start ,match-end)
(error "matched the empty string at position ~d, this will cause an infinite loop"
,match-start))
(setf ,start ,match-end)
(ecase (position-if #'identity ,register-starts)
,@(mapcar (lambda (register-start register-end form)
(let* ((local-register-names (mapcar (lambda (register-name)
(intern register-name))
(if (< (1+ register-start)
total-registers)
(subseq register-names
(1+ register-start)
register-end))))
(global-registers (loop
for j from (1+ register-start)
to total-registers collect j))
($@ (intern "$@")))
`(,register-start (let ((,$@ (subseq ,string
,match-start
,match-end))
,@(mapcar (lambda (local-register-name i)
`(,local-register-name
(if (aref ,register-starts ,i)
(subseq ,string
(aref
,register-starts
,i)
(aref
,register-ends
,i)))))
local-register-names
global-registers))
(declare (ignorable ,$@ ,@local-register-names))
,form))))
registers
(concatenate 'list (cdr registers) (list nil))
forms)))
(return)))))))))))))
(defun stream-lexer (read-source-line string-lexer opening-delimiter-p closing-delimiter-p &key (stream *standard-input*))
"Returns a closure that takes no arguments and will return each token from stream when called. read-source-line is a
function that takes an input stream and returns a line of the source. When EOF is encountered, read-source-line should
return t. string-lexer is a function that returns a lexer that behaves as if it was returned by a function defined using
define-string-lexer. opening-delimiter-p is a function that takes a character and returns true if it is an opening
delimiter and false otherwise. closing-delimiter-p is a function that takes a character. When there no more tokens are
left, nil is returned. nil is also returned when a newline is encountered and there are no open delimiters. If the
closure is called again after EOF has been encountered a condition of type end-of-file is signalled."
(let (eof line-lexer (open-delimiters 0) (update t))
(labels ((next-token ()
(multiple-value-bind (token value)
(funcall line-lexer)
(cond
((funcall opening-delimiter-p token) (incf open-delimiters))
((funcall closing-delimiter-p token) (decf open-delimiters)))
(values token value)))
(update-line-lexer ()
(let ((line (funcall read-source-line stream)))
(if (null line)
(setf eof t))
(setf line-lexer (funcall string-lexer line)))))
(lambda ()
(when update
(update-line-lexer)
(setf update nil))
(multiple-value-bind (token value)
(next-token)
(if token
(values token value)
(if eof
(error 'end-of-file :stream stream)
(if (> open-delimiters 0)
(progn
(update-line-lexer)
(next-token))
(progn
(setf update t
open-delimiters 0)
nil)))))))))
| 9,920 | Common Lisp | .lisp | 208 | 39.480769 | 125 | 0.635455 | djr7C4/cl-lex | 8 | 2 | 2 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | bd448863c6349891970cac38209e28ad93ebd8f844800ce1c043d3434080923f | 11,842 | [
-1
] |
11,843 | use.lisp | djr7C4_cl-lex/use.lisp | ;;;; Loads and uses all cl-lex packages in :cl-user.
;;;; Copyright (C) 2009 David J. Rosenbaum, email: [email protected]
;;;;
;;;; This program is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation, under version 3 of the License.
;;;;
;;;; This program 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 General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;;
;;;; Copyright (C) 2009 David J. Rosenbaum
;;;; This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
;;;; This is free software, and you are welcome to redistribute it
;;;; under certain conditions; for details see COPYING.
(in-package :cl-user)
(load (make-pathname :name "load" :type "lisp" :defaults *load-truename*))
(use-package :cl-lex)
| 1,121 | Common Lisp | .lisp | 22 | 49.863636 | 77 | 0.731996 | djr7C4/cl-lex | 8 | 2 | 2 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | c7a2f31f159dae928e0335f909b8737b7bb02060a403a28c5551ecbdc8c9f5d5 | 11,843 | [
-1
] |
11,844 | load.lisp | djr7C4_cl-lex/load.lisp | ;;;; Loads all files needed to run cl-lex code.
;;;; Copyright (C) 2009 David J. Rosenbaum, email: [email protected]
;;;;
;;;; This program is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation, under version 3 of the License.
;;;;
;;;; This program 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 General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;;
;;;; Copyright (C) 2009 David J. Rosenbaum
;;;; This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
;;;; This is free software, and you are welcome to redistribute it
;;;; under certain conditions; for details see COPYING.
(in-package :cl-user)
(let ((cl-lex-directory (make-pathname :name nil :type nil :defaults *load-truename*)))
(with-compilation-unit ()
(require :asdf)
(asdf:operate 'asdf:load-op :cl-ppcre)
(dolist (file '("packages" "lex"))
(load (make-pathname :name file :type "lisp" :defaults cl-lex-directory)))))
(provide :cl-lex)
| 1,339 | Common Lisp | .lisp | 27 | 47.740741 | 87 | 0.718869 | djr7C4/cl-lex | 8 | 2 | 2 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 27e23dc49aee55c34a40999850fce7621914342d5081099ee478dd66f5be97cc | 11,844 | [
-1
] |
11,845 | packages.lisp | djr7C4_cl-lex/packages.lisp | ;;;; Defines all cl-lex packages.
;;;; Copyright (C) 2009 David J. Rosenbaum, email: [email protected]
;;;;
;;;; This program is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation, under version 3 of the License.
;;;;
;;;; This program 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 General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;;
;;;; Copyright (C) 2009 David J. Rosenbaum
;;;; This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
;;;; This is free software, and you are welcome to redistribute it
;;;; under certain conditions; for details see COPYING.
(in-package :cl-user)
(defpackage :cl-lex
(:use :cl)
(:export :define-string-lexer
:stream-lexer))
| 1,090 | Common Lisp | .lisp | 24 | 44 | 77 | 0.730263 | djr7C4/cl-lex | 8 | 2 | 2 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 97c863550eea2b186d7a70d9daae7ced19d5296016bcafc410c305a903138a7d | 11,845 | [
-1
] |
11,846 | cl-lex.asd | djr7C4_cl-lex/cl-lex.asd | ;;;; ASDF System definition for cl-lex.
;;;; Copyright (C) 2009 David J. Rosenbaum, email: [email protected]
;;;;
;;;; This program is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation, under version 3 of the License.
;;;;
;;;; This program 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 General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;;
;;;; Copyright (C) 2009 David J. Rosenbaum
;;;; This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
;;;; This is free software, and you are welcome to redistribute it
;;;; under certain conditions; for details see COPYING.
(asdf:defsystem :cl-lex
:version "1.1.3"
:author "David J. Rosenbaum <[email protected]>"
:license "GPL3"
:description "Common Lisp macros for generating lexical analyzers"
:serial t
:components ((:file "packages")
(:file "lex"))
:depends-on ("cl-ppcre"))
| 1,265 | Common Lisp | .asd | 28 | 43.357143 | 77 | 0.72411 | djr7C4/cl-lex | 8 | 2 | 2 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 794e105460383ec921396ac8fb0d166bc05aa05d75e17e793146a29e0a608dca | 11,846 | [
-1
] |
11,867 | cacau-examples-hooks.lisp | noloop_cacau/examples/cacau-examples-hooks.lisp | (defpackage #:cacau-examples-hooks
(:use #:common-lisp
#:assert-p
#:cacau))
(in-package #:cacau-examples-hooks)
(defbefore-all "Before-all" () (format t ":suite-root's before-all~%"))
(defbefore-each "Before-each" () (format t ":suite-root's before-each~%"))
(defafter-each "After-each" () (format t ":suite-root's after-each~%"))
(defafter-all "After-all" () (format t ":suite-root's after-all~%~%"))
(defsuite :suite-with-before-all ()
(let ((x 0))
(defbefore-all "Before-all" () (setf x 1))
(deftest "Test-1" () (eql-p x 1))
(deftest "Test-2" () (eql-p x 1))))
(defsuite :suite-with-before-each ()
(let ((x 0))
(defbefore-each "Before-each" () (setf x 1))
(deftest "Test-1" () (eql-p x 1))
(deftest "Test-2" () (eql-p x 1))))
(defsuite :suite-with-after-each ()
(let ((x 0))
(defafter-each "After-each" () (setf x 1))
(deftest "Test-1" () (eql-p x 0))
(deftest "Test-2" () (eql-p x 1))))
(defsuite :suite-with-after-all ()
(let ((x 0))
(defafter-all "After-all" () (setf x 1))
(deftest "Test-1" () (eql-p x 0))
(deftest "Test-2" () (eql-p x 0))))
(run :colorful t)
(format t "~%")
;;;; hooks inheritance
;;;; ------------------------------------
;;; before-each
(defsuite :suite-1 ()
(defbefore-each "Before-each Suite-1" ()
(format t "run Before-each Suite-1~%"))
(deftest "Test-1" () (format t "run Test-1~%") (t-p t))
(defsuite :suite-1 ()
(defbefore-each "Before-each Suite-2" ()
(format t "run Before-each Suite-2~%"))
(deftest "Test-1" () (format t "run Test-2~%~%") (t-p t))))
(run :colorful t)
(format t "~%")
;;; after-each
(defsuite :suite-1 ()
(defafter-each "After-each Suite-1" ()
(format t "run After-each Suite-1~%~%"))
(deftest "Test-1" () (format t "run Test-1~%") (t-p t))
(defsuite :suite-1 ()
(defafter-each "After-each Suite-2" ()
(format t "run After-each Suite-2~%"))
(deftest "Test-1" () (format t "run Test-2~%") (t-p t))))
(run :colorful t)
(format t "~%")
;;;; hooks not inheritance
;;;; ------------------------------------
;;; before-all
(defsuite :suite-1 ()
(defbefore-all "Before-all Suite-1" ()
(format t "run Before-all Suite-1~%"))
(deftest "Test-1" () (format t "run Test-1~%") (t-p t))
(defsuite :suite-1 ()
(defbefore-all "Before-all Suite-2" ()
(format t "run Before-all Suite-2~%"))
(deftest "Test-1" () (format t "run Test-2~%~%") (t-p t))))
(run :colorful t)
(format t "~%")
;;; after-all
(defsuite :suite-1 ()
(defafter-all "After-all Suite-1" ()
(format t "run After-all Suite-1~%~%"))
(deftest "Test-1" () (format t "run Test-1~%") (t-p t))
(defsuite :suite-1 ()
(defafter-all "After-all Suite-2" ()
(format t "run After-all Suite-2~%"))
(deftest "Test-1" () (format t "run Test-2~%") (t-p t))))
(run :colorful t)
| 2,847 | Common Lisp | .lisp | 78 | 33.128205 | 74 | 0.570443 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | c7f89320dd618651db66e09084345c82a576f20e5aa9c2093f04b805c5b10401 | 11,867 | [
-1
] |
11,868 | cacau-examples-onlys.lisp | noloop_cacau/examples/cacau-examples-onlys.lisp | (defpackage #:cacau-examples-onlys
(:use #:common-lisp
#:assert-p
#:cacau))
(in-package #:cacau-examples-onlys)
(defsuite :suite-1 ()
(deftest "Test-1" (:only) (t-p t)) ;; run!
(deftest "Test-2" () (t-p t)))
(defsuite :suite-2 ()
(let ((x 0))
(deftest "Test-1" () (eql-p x 0))
(deftest "Test-2" () (t-p t))
(defsuite :suite-3 (:only)
(deftest "Test-1" () (t-p t)) ;; run!
(deftest "Test-2" () (t-p t))))) ;; run!
(run :colorful t)
| 483 | Common Lisp | .lisp | 16 | 25.9375 | 46 | 0.537797 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | a2a891b2501be6323db6366af5647883bd4ddccbf4484bf5682ecd07b8207e3a | 11,868 | [
-1
] |
11,869 | cacau-examples-skips.lisp | noloop_cacau/examples/cacau-examples-skips.lisp | (defpackage #:cacau-examples-skips
(:use #:common-lisp
#:assert-p
#:cacau))
(in-package #:cacau-examples-skips)
(defsuite :suite-1 ()
(deftest "Test-1" (:skip) (t-p t))
(deftest "Test-2" () (t-p t))) ;; run!
(defsuite :suite-2 (:skip)
(let ((x 0))
(deftest "Test-1" () (eql-p x 0))
(deftest "Test-2" () (t-p t))
(defsuite :suite-3 ()
(deftest "Test-1" () (t-p t))
(deftest "Test-2" () (t-p t)))))
(run :colorful t)
| 467 | Common Lisp | .lisp | 16 | 24.9375 | 40 | 0.543624 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 6c8776853795f7e6e639831efbb49bc1679f298450712284f027908c01fb9592 | 11,869 | [
-1
] |
11,870 | cacau-examples-reporters.lisp | noloop_cacau/examples/cacau-examples-reporters.lisp | (defpackage #:cacau-examples-reporters
(:use #:common-lisp
#:assert-p
#:cacau))
(in-package #:cacau-examples-reporters)
;;; :min
(defsuite :suite-1 ()
(deftest "Test-1" () (t-p t))
(deftest "Test-2" (:skip) (t-p t))
(deftest "Test-3" () (t-p nil)))
(run :colorful t) ;; or (run :colorful t :reporter :min)
(format t "~%")
;;; :list
(defsuite :suite-1 ()
(deftest "Test-1" () (t-p t))
(deftest "Test-2" (:skip) (t-p t))
(deftest "Test-3" () (t-p nil)))
(run :colorful t :reporter :list)
(format t "~%")
;;; :full
(defsuite :suite-1 ()
(deftest "Test-1" () (t-p t))
(deftest "Test-2" () (t-p t))
(deftest "Test-3" () (t-p nil)))
(run :colorful t :reporter :full)
(format t "~%")
;;; :full with :reporter-options
(defsuite :suite-1 ()
(deftest "Test-1" () (t-p t))
(deftest "Test-2" () (t-p t))
(deftest "Test-3" () (t-p nil)))
(run :colorful t
:reporter :full
:reporter-options
;; You can hide any options below
;; or change your order.
'(:tests-list
(:epilogue
(:running-suites
:running-tests
:only-suites
:only-tests
:skip-suites
:skip-tests
:total-suites
:total-tests
:passing
:failing
:errors
:run-start
:run-end
:run-duration
:completed-suites
:completed-tests))
:stack))
| 1,408 | Common Lisp | .lisp | 55 | 20.363636 | 56 | 0.551339 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 42778ce28911e9be2890733f4fd538edd58acf10a3b645865eb78eda00cee78f | 11,870 | [
-1
] |
11,871 | cacau-examples-async-test.lisp | noloop_cacau/examples/cacau-examples-async-test.lisp | (defpackage #:cacau-examples-async-test
(:use #:common-lisp
#:assert-p
#:cacau))
(in-package #:cacau-examples-async-test)
(defsuite :suite-1 ()
(let ((x 0))
;;; only call done
(defbefore-each "Before-each" ((:async done))
(setf x 1)
(funcall done))
;;; passing function catch error for done
(defafter-each "Before-each" ((:async done))
(funcall done (lambda () (setf x 1))))
;;; passing error for done
(defafter-all "after-all" ((:async done))
(handler-case (t-p nil)
(error (c)
(funcall done c))))
;;; only call done
(deftest "Test-1" ((:async done))
(funcall done))
;;; passing function catch error for done
(deftest "Test-2" ((:async done))
(funcall done (lambda () (t-p t))))
;;; passing error for done
(deftest "Test-3" ((:async done))
(handler-case (t-p nil)
(error (c)
(funcall done c))))
;;; call done as you want
(deftest "Test-4" ((:async something))
(funcall something))))
(run :colorful t
:reporter :full)
| 1,086 | Common Lisp | .lisp | 35 | 25.228571 | 49 | 0.581107 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 965a5ed7ba845c22e21ef467810e9baa17a17f8611431104ed01507c7d265e36 | 11,871 | [
-1
] |
11,872 | cacau-examples-quickstart.lisp | noloop_cacau/examples/cacau-examples-quickstart.lisp | (defpackage #:cacau-examples-quickstart
(:use #:common-lisp
#:assert-p
#:cacau))
(in-package #:cacau-examples-quickstart)
(deftest "Test-1" () (eql-p 1 1))
(deftest "Test-2" () (eql-p 2 2))
(deftest "Test-3" () (eql-p 3 3))
(run :colorful t)
| 263 | Common Lisp | .lisp | 9 | 25.888889 | 40 | 0.621514 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 4ea3eb978a580388968133329a6425f36497b3d332ccfb993d1c4493152b0582 | 11,872 | [
-1
] |
11,873 | cacau-examples-timeout.lisp | noloop_cacau/examples/cacau-examples-timeout.lisp | (defpackage #:cacau-examples-timeout
(:use #:common-lisp
#:assert-p
#:cacau))
(in-package #:cacau-examples-timeout)
;;; timeout-in-suites
(defsuite :suite-1 ((:timeout 0))
(deftest "Test-1" () (t-p t)) ;; Timeout Error: Time(0) extrapolated!
(deftest "Test-2" () (t-p t))) ;; Timeout Error: Time(0) extrapolated!
(run :colorful t
:reporter :full)
(format t "~%")
;;; timeout-in-hooks
(defsuite :suite-1 ()
(defbefore-all "Before-all" ((:timeout 0))) ;; Timeout Error: Time(0) extrapolated!
(deftest "Test-1" () (t-p t))
(deftest "Test-2" () (t-p t)))
(run :colorful t
:reporter :full)
(format t "~%")
;;; timeout-in-tests
(defsuite :suite-1 ()
(deftest "Test-1" ((:timeout 0)) (t-p t)) ;; Timeout Error: Time(0) extrapolated!
(deftest "Test-2" () (t-p t)))
(run :colorful t
:reporter :full)
(format t "~%")
;;; timeout-in-tests-with-suites-timeout-configured
(defsuite :suite-1 ((:timeout 0))
(deftest "Test-1" () (t-p t)) ;; Timeout Error: Time(0) extrapolated!
(deftest "Test-2" () (t-p t)) ;; Timeout Error: Time(0) extrapolated!
(defsuite :suite-2 ((:timeout 50000))
(deftest "Test-1" ((:timeout 0)) (t-p t)) ;; Timeout Error: Time(0) extrapolated!
(deftest "Test-2" () (t-p t))))
(run :colorful t
:reporter :full)
| 1,298 | Common Lisp | .lisp | 36 | 32.972222 | 85 | 0.623304 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 3220dfb6f4529212488c489e9754b947577cc10fdf9574b7999f17c64d6ad544 | 11,873 | [
-1
] |
11,874 | cacau-examples-interfaces.lisp | noloop_cacau/examples/cacau-examples-interfaces.lisp | (defpackage #:cacau-examples-interfaces
(:use #:common-lisp
#:assert-p
#:cacau))
(in-package #:cacau-examples-interfaces)
;;; cl
(defsuite :suite-1 ()
(let ((x 0))
(defbefore-all "Before-all Suite-1" () (setf x 1))
(defbefore-each "Before-each Suite-1" () (setf x 0))
(defafter-each "After-each Suite-1" () (setf x 1))
(defafter-all "After-all Suite-1" ((:async done))
(setf x 1)
(funcall done))
(deftest "Test-1" () (eql-p x 0))
(deftest "Test-2" ((:async done))
(funcall done (lambda () (eql-p x 0))))
(defsuite :suite-2 ()
(let ((x 0))
(deftest "Test-1" ((:async done))
(funcall done (lambda () (eql-p x 0))))
(deftest "Test-2" () (eql-p x 0))))))
(run :colorful t)
(format t "~%")
;;; bdd
(context
"Suite-1"
(lambda (&optional (x 0))
(before-all "Before-all Suite-1" (lambda () (setf x 1)))
(before-each "Before-each Suite-1" (lambda () (setf x 1)))
(after-each "After-each Suite-1" (lambda () (setf x 1)))
(after-all "After-all Suite-1" (lambda (done) (funcall done)) :async t)
(it "Test-1" (lambda () (eql-p x 1)))
(it "Test-2" (lambda () (incf x) (eql-p x 2)))
(context
"Suite-2"
(lambda (&optional (x 0))
(it "Test-1" (lambda () (incf x) (eql-p x 1)))
(it "Test-2" (lambda () (eql-p x 1)))
(context
"Suite-3"
(lambda (&optional (x 0))
(it "Test-1" (lambda () (incf x) (eql-p x 1)))
(it "Test-2" (lambda () (eql-p x 1)))))))))
(run :colorful t)
(format t "~%")
;;; tdd
(suite
"Suite-1"
(lambda (&optional (x 0))
(suite-setup "Suite-setup Suite-1" (lambda () (setf x 1)))
(test-setup "Test-setup Suite-1" (lambda () (setf x 1)))
(test-teardown "Test-teardown Suite-1" (lambda () (setf x 1)))
(suite-teardown "Suite-teardown Suite-1" (lambda (done) (funcall done)) :async t)
(test "Test-1" (lambda () (eql-p x 1)))
(test "Test-2" (lambda () (incf x) (eql-p x 2)))
(suite
"Suite-2"
(lambda (&optional (x 0))
(test "Test-1" (lambda () (incf x) (eql-p x 1)))
(test "Test-2" (lambda () (eql-p x 1)))
(suite
"Suite-3"
(lambda (&optional (x 0))
(test "Test-1" (lambda (done)
(incf x)
(funcall done (lambda () (eql-p x 1))))
:async t)
(test "Test-2" (lambda () (eql-p x 1)))))))))
(run :colorful t)
(format t "~%")
;;; no-spaghetti
(let ((x 0))
(in-plan :suite-1 ()) ;; or (in-suite :suite-1 ((:parent :suite-root)))
(defbefore-plan :before-plan-suite-1 () (setf x 1))
(deft :test-1 () (eql-p x 1))
(deft :test-2 ((:async done))
(incf x)
(funcall done (lambda () (eql-p x 2))))
(in-plan :suite-2 ((:parent :suite-1)))
(defafter-plan :after-plan-suite-2 ((:async done-hook)) (setf x 1) (funcall done-hook))
(deft :test-1 () (eql-p x 2))
(deft :test-2 () (incf x) (eql-p x 3))
(in-plan :suite-3 ((:parent :suite-2)))
(defbefore-t :before-t-suite-3 () (setf x 0))
(deft :test-1 () (incf x) (eql-p x 1))
(deft :test-2 () (eql-p x 0))
(in-plan :suite-4) ;; or (in-suite :suite-4 ((:parent :suite-root)))
(defafter-t :after-t-suite-4 () (setf x 0))
(deft :test-1 () (incf x) (eql-p x 2))
(deft :test-2 () (eql-p x 0)))
(run :colorful t)
| 3,303 | Common Lisp | .lisp | 92 | 30.836957 | 89 | 0.546137 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 284b574a43e5260fae07353925d682a201066d256d46d1f582d9a9b1346882ec | 11,874 | [
-1
] |
11,875 | cacau-examples-skips-onlys-rules.lisp | noloop_cacau/examples/cacau-examples-skips-onlys-rules.lisp | (defpackage #:cacau-examples-skips-onlys-rules
(:use #:common-lisp
#:assert-p
#:cacau))
(in-package #:cacau-examples-skips-onlys-rules)
;;; skip-test-precedes-only-test
(defsuite :suite-1 ()
(deftest "Test-1" (:only) (t-p t)) ;; run!
(deftest "Test-2" (:skip) (t-p t)))
(run :colorful t
:reporter :list)
(format t "~%")
;;; skip-test-precedes-only-suite
(defsuite :suite-1 (:only)
(deftest "Test-1" () (t-p t)) ;; run!
(deftest "Test-2" (:skip) (t-p t)))
(run :colorful t
:reporter :list)
(format t "~%")
;;; skip-only-suite-not-precedes-skip-suite
(defsuite :suite-1 (:only)
(deftest "Test-1" () (t-p t)) ;; run!
(deftest "Test-2" () (t-p t)) ;; run!
(defsuite :suite-2 (:skip)
(deftest "Test-1" () (t-p t))
(deftest "Test-2" () (t-p t))))
(run :colorful t
:reporter :list)
(format t "~%")
;;; skip-suite-precedes-only-test
;;; Attention here! Because before the cacau is isolating the "Test-1"
;;; and after is skipping the :suite-2, so it doesn't run any test.
(defsuite :suite-1 ()
(deftest "Test-1" () (t-p t))
(deftest "Test-2" () (t-p t))
(defsuite :suite-2 (:skip)
(deftest "Test-1" (:only) (t-p t))
(deftest "Test-2" () (t-p t))))
(run :colorful t
:reporter :list)
(format t "~%")
;;; skip-suite-precedes-only-suite
(defsuite :suite-1 (:skip)
(deftest "Test-1" () (t-p t))
(deftest "Test-2" () (t-p t))
(defsuite :suite-2 (:only)
(deftest "Test-1" () (t-p t))
(deftest "Test-2" () (t-p t))))
(run :colorful t
:reporter :list)
(format t "~%")
;;; skip-suite-precedes-only-test-and-only-suite
(defsuite :suite-1 (:skip)
(deftest "Test-1" () (t-p t))
(deftest "Test-2" (:only) (t-p t))
(defsuite :suite-2 (:only)
(deftest "Test-1" () (t-p t))
(deftest "Test-2" () (t-p t))))
(run :colorful t
:reporter :list)
| 1,835 | Common Lisp | .lisp | 60 | 27.583333 | 70 | 0.595588 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | ecd3de5fd3d907720d42b49e04cda1c150d2b4b2153f78c18bb721fe2618a1e1 | 11,875 | [
-1
] |
11,876 | cacau-examples-cl-debugger.lisp | noloop_cacau/examples/cacau-examples-cl-debugger.lisp | (defpackage #:cacau-examples-cl-debugger
(:use #:common-lisp
#:assert-p
#:cacau))
(in-package #:cacau-examples-cl-debugger)
(defsuite :suite-1 ()
(deftest "Test-1" () (t-p t))
(deftest "Test-2" () (t-p nil))
(deftest "Test-3" () (t-p t)))
(run :cl-debugger t)
| 287 | Common Lisp | .lisp | 10 | 25 | 41 | 0.60219 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 8182a17a159213dbf4fe7b04d8ac61a1e464b3206136b96c7cee73191b7e4ac3 | 11,876 | [
-1
] |
11,877 | cacau-examples-suites.lisp | noloop_cacau/examples/cacau-examples-suites.lisp | (defpackage #:cacau-examples-suites
(:use #:common-lisp
#:assert-p
#:cacau))
(in-package #:cacau-examples-suites)
(defsuite :suite-1 ()
(deftest "Test-1" () (t-p t))
(deftest "Test-2" () (t-p t)))
(defsuite :suite-2 ()
(let ((x 0))
(deftest "Test-1" () (eql-p x 0))
(deftest "Test-2" () (t-p t))
(defsuite :suite-3 ()
(deftest "Test-1" () (t-p t))
(deftest "Test-2" () (t-p t)))))
(run :colorful t)
| 451 | Common Lisp | .lisp | 16 | 23.9375 | 38 | 0.542923 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 39976ef4f652cbade6fcfcf8c59de3322c127d26ad6bc3ab4008281c557e807a | 11,877 | [
-1
] |
11,878 | cacau-examples-asdf-integration-test.lisp | noloop_cacau/examples/asdf-intregration/cacau-examples-asdf-integration-test.lisp | (defpackage #:cacau-examples-asdf-integration-test
(:use #:common-lisp
#:cacau
#:assert-p
#:cacau-examples-asdf-integration))
(in-package #:cacau-examples-asdf-integration-test)
(deftest "Test-add-multiplication" ()
(eql-p (add-multiplication 1 2) 5))
| 282 | Common Lisp | .lisp | 8 | 30.5 | 51 | 0.691176 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 09cc721bc76fc9274bc46ded0a69fca103b7bb68157b582d39772525b36bf963 | 11,878 | [
-1
] |
11,879 | cacau-examples-asdf-integration.lisp | noloop_cacau/examples/asdf-intregration/cacau-examples-asdf-integration.lisp | (defpackage #:cacau-examples-asdf-integration
(:use #:common-lisp)
(:export #:add-multiplication))
(in-package #:cacau-examples-asdf-integration)
(defun add-multiplication (a b)
(+ (* a a) (* b b)))
| 207 | Common Lisp | .lisp | 6 | 32.166667 | 46 | 0.698492 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | b8e1c9736a1fbb2a73f7e5af81857b35c921664737df71d2237e364954a58405 | 11,879 | [
-1
] |
11,880 | package.lisp | noloop_cacau/src/package.lisp | (defpackage #:noloop.cacau
(:use #:common-lisp)
(:nicknames #:cacau)
(:import-from #:eventbus
#:make-eventbus
#:once
#:on
#:emit)
(:import-from #:assertion-error
#:assertion-error
#:assertion-error-actual
#:assertion-error-expected
#:assertion-error-message
#:assertion-error-result
#:assertion-error-stack
#:get-stack-trace)
(:export #:make-runner
#:suite-root
#:add-child
#:create-test
#:create-suite
#:on-runner
#:once-runner
#:create-before-all
#:create-after-all
#:create-before-each
#:create-after-each
#:run-runner
#:result
#:run
#:cacau-runner
#:reset-runner
#:cl-debugger
#:common-create-before-all
#:common-create-after-all
#:common-create-before-each
#:common-create-after-each
#:common-create-suite
#:common-create-test
#:before-all
#:after-all
#:before-each
#:after-each
#:context
#:it
#:suite
#:test
#:suite-setup
#:suite-teardown
#:test-setup
#:test-teardown
#:defsuite
#:deftest
#:defbefore-all
#:defafter-all
#:defbefore-each
#:defafter-each
#:in-plan
#:defbefore-plan
#:defafter-plan
#:defbefore-t
#:defafter-t
#:deft))
| 1,731 | Common Lisp | .lisp | 63 | 15.47619 | 42 | 0.452909 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 5cfa386e10b39c630ca2afd2de4e1dfc412ece6b8b9e712728f54bca0d106031 | 11,880 | [
-1
] |
11,881 | utils.lisp | noloop_cacau/src/utils.lisp | (in-package #:noloop.cacau)
(defmacro with-gensyms (vars &body body)
`(let ,(loop for v in vars collect `(,v (gensym)))
,@body))
(defmacro create-hash (&rest fields)
"Example: (create-hash '((:a 1) (:b 2)))"
(let ((new-hash-table (gensym)))
`(let ((,new-hash-table (make-hash-table)))
(dolist (i ,@fields)
(setf (gethash (car i) ,new-hash-table) (cadr i)))
,new-hash-table)))
(defmacro setf-hash (hash &rest fields)
"Example: (let ((hash (make-hash-table :test 'eq)))
(setf-hash hash '((:a 1) (:b 2)))
hash)"
`(progn
(dolist (i ,@fields)
(setf (gethash (car i) ,hash) (cadr i)))
,hash))
(defmacro create-list-iterator (new-list)
"Creates a new lambda that returns the next item in the new-list reverted. Returns nil if there is not the next item in the list. Example:
(let* ((itens '(1 2))
(next-item (create-list-iterator itens)))
(print (funcall next-item))
(print (funcall next-item))
(print (funcall next-item)))
=>
1
2
NIL"
(with-gensyms (itens)
`(let ((,itens (reverse ,new-list)))
(lambda ()
(let ((current-item (car ,itens)))
(when (> (length ,itens) 0)
(setf ,itens (cdr ,itens))
current-item))))))
(defmacro defvar* (bindings)
`(progn
,@(mapcar #'(lambda (var)
(let ((var-list-p (listp var)))
(if var-list-p
(check-type (car var) symbol)
(check-type var symbol))
`(defvar
,(if (listp var)
(car var)
var)
,(if (listp var)
(cadr var)
nil))))
bindings)))
(defun string-ansi-color (stg color &key style background)
(let ((color (cond ((equal "black" color) "30")
((equal "red" color) "31")
((equal "green" color) "32")
((equal "yellow" color) "33")
((equal "blue" color) "34")
((equal "purple" color) "35")
((equal "cyan" color) "36")
((equal "white" color) "37")
(t "0")))
(style (cond ((equal "bold" style) "1;")
((equal "italic" style) "3;")
((equal "underline" style) "4;")
((equal "blink" style) "5;")
((equal "strick" style) "9;")
(t "")))
(background (cond ((equal "black" background) ";40")
((equal "red" background) ";41")
((equal "green" background) ";42")
((equal "yellow" background) ";43")
((equal "blue" background) ";44")
((equal "purple" background) ";45")
((equal "cyan" background) ";46")
((equal "white" background) ";47")
(t ""))))
(format nil (concatenate 'string "~c[" style color background "m" stg "~c[0m") #\ESC #\ESC)))
(defun read-yes ()
(find (read-line) '("yes" "y" "t") :test #'string-equal))
(defun string-if-not-string (value)
(if (typep value 'string)
value
(write-to-string value)))
| 3,391 | Common Lisp | .lisp | 84 | 27.845238 | 140 | 0.46695 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 179b65de1ff03ad0fe23f98a4eaa9b59ec8880bb293858830aa5e6115b7c6dfc | 11,881 | [
-1
] |
11,882 | cacau.lisp | noloop_cacau/src/cacau.lisp | (in-package #:noloop.cacau)
(let ((runner (make-runner)))
(defun cacau-runner () runner)
(defun reset-runner () (setf runner (make-runner)))
(defun create-reporter (runner name reporter-options)
(cond ((equal :min name) (reporter-min runner reporter-options))
((equal :list name) (reporter-list runner reporter-options))
((equal :full name) (reporter-full runner reporter-options))))
(defun cl-debugger (obj-runnable on-off)
"Attention that the slot cl-debugger-p is :allocation :class in runnable class."
(setf (cl-debugger-p obj-runnable) on-off))
(defun create-reporter-fn (old-runner colorful reporter reporter-options)
(unless (equal :off reporter)
(defun cacau-string-color (stg color &key style background)
(if colorful
(string-ansi-color stg color
:background background
:style style)
stg))
(create-reporter old-runner reporter reporter-options)))
(defun run (&key (reporter :min)
before-run
after-run
colorful
reporter-options
cl-debugger)
(let* ((old-runner runner)
(reporter-fn (create-reporter-fn old-runner
colorful
reporter
reporter-options))
(result nil))
(cl-debugger (suite-root old-runner) cl-debugger)
(when (typep before-run 'function)
(funcall before-run old-runner))
(once-runner old-runner :end
(lambda ()
(setf result (and (zerop (gethash :failing (result old-runner)))
(zerop (length (gethash :errors (result old-runner))))))
(when (typep after-run 'function)
(funcall after-run old-runner))
(when (typep reporter-fn 'function)
(funcall reporter-fn))))
(reset-runner)
(run-runner old-runner)
result)))
| 2,162 | Common Lisp | .lisp | 46 | 32.195652 | 95 | 0.542952 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | a0d6b9c513efc4c02ca41ac9731277ef624584e1d4bde54f1facd23c120207d6 | 11,882 | [
-1
] |
11,883 | asdf.lisp | noloop_cacau/src/asdf.lisp | (in-package #:cl-user)
(defpackage #:cacau-asdf
(:use #:common-lisp)
(:import-from #:asdf
#:cl-source-file
#:operation-done-p
#:load-op
#:compile-op)
(:export #:cacau-file
#:cacau-file-nd))
(in-package #:cacau-asdf)
(defclass cacau-file (cl-source-file) ())
(defmethod operation-done-p ((op load-op) (c cacau-file)) nil)
(defmethod operation-done-p ((op compile-op) (c cacau-file)) t)
(import 'cacau-file :asdf)
(defclass cacau-file-nd (cl-source-file) ())
(defmethod operation-done-p ((op load-op) (c cacau-file-nd)) nil)
(defmethod operation-done-p ((op compile-op) (c cacau-file-nd)) nil)
(import 'cacau-file-nd :asdf)
| 646 | Common Lisp | .lisp | 19 | 31.736842 | 68 | 0.688 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 513dc3ba9cd258ee1269fd9e752f230b9df0b6bbd68b1f22864317416556bb05 | 11,883 | [
-1
] |
11,884 | full.lisp | noloop_cacau/src/reporters/full.lisp | (in-package #:noloop.cacau)
(defun reporter-full (runner options)
(cacau-logo)
(when (or (some #'(lambda (i) (equal :tests-list i)) options)
(null options))
(suite-tests-list-events runner))
(lambda ()
(if (null options)
(full-epilogue (result runner) nil)
(dolist (i options)
(when (listp i)
(when (equal :epilogue (first i))
(full-epilogue (result runner) (second i))))))
(when (or (some #'(lambda (i) (equal :stack i)) options)
(null options))
(stack-test-errors (result runner)))))
| 590 | Common Lisp | .lisp | 16 | 29.375 | 63 | 0.58042 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | febd8f2347f336816e22479701a5a9c863ef2d229bba5bfbcd1c6ea1844633c7 | 11,884 | [
-1
] |
11,885 | min.lisp | noloop_cacau/src/reporters/min.lisp | (in-package #:noloop.cacau)
(defun reporter-min (runner options)
(declare (ignore options))
(lambda ()
(cacau-logo)
(epilogue (result runner))))
| 159 | Common Lisp | .lisp | 6 | 23.166667 | 36 | 0.688742 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | ae6fc5eb9355067d5d3dc4eeb7e32b82557952843f77bd03b5c4ce900f596f6d | 11,885 | [
-1
] |
11,886 | base.lisp | noloop_cacau/src/reporters/base.lisp | (in-package #:noloop.cacau)
(defun cacau-logo ()
(format t "~a~%~%" (cacau-string-color "<=> Cacau <=>" "red"
:background "yellow"
:style "underline")))
(defun separation-bar (&optional color)
(format t "~%~a~%" (cacau-string-color "-------------------------" color)))
(defun suite-tests-list-events (runner)
(let ((current-parent :suite-root)
(spaces ""))
(on-runner
runner
:suite-start
(lambda (suite)
(unless (equal :suite-root (name suite))
(format t "~a~%"
(concatenate 'string
(unless (equal current-parent (name (parent suite)))
(setf current-parent (name (parent suite)))
(setf spaces (concatenate 'string " ")))
(cacau-string-color (string-if-not-string (name suite)) "blue"))))))
(on-runner
runner
:suite-end
(lambda (suite)
(setf current-parent (unless (equal :suite-root (name suite))
(name (parent suite))))
(setf spaces (when (> (length spaces) 0) (subseq spaces 1)))))
(on-runner
runner
:pass
(lambda (test)
(format t "~a~%"
(concatenate 'string spaces
(cacau-string-color
(concatenate 'string " -> " (string-if-not-string (name test)))
"green")))))
(on-runner
runner
:fail
(lambda (test)
(format t "~a~%~a~%~a~%"
(cacau-string-color
(concatenate 'string
spaces
" <- "
(string-if-not-string (name test))
":")
"red" :style "underline")
(cacau-string-color "Error message:" "red" :style "underline")
(cacau-string-color (gethash :message (runnable-error test)) "white"))))))
(defun epilogue (runner-result)
(let ((passed-tests
(concatenate 'string (write-to-string (gethash :passing runner-result)) " passed"))
(failed-tests
(concatenate 'string (write-to-string (gethash :failing runner-result)) " failed")))
(format t "~a~a~a~%~%"
(cacau-string-color "From " "white")
(cacau-string-color (write-to-string (gethash :tests runner-result)) "blue")
(cacau-string-color " running tests: " "white"))
(format t "~a~%" (cacau-string-color passed-tests "green"))
(format t "~a~%" (cacau-string-color failed-tests "red"))))
(defun skipped (runner-result)
(when (> (gethash :skip-suites runner-result) 0)
(format t "~a~%" (cacau-string-color
(concatenate
'string
(write-to-string (gethash :skip-suites runner-result))
" suite"
(if (> (gethash :skip-suites runner-result) 1) "s" "")
" skipped")
"cyan")))
(when (> (gethash :skip-tests runner-result) 0)
(format t "~a~%" (cacau-string-color
(concatenate
'string
(write-to-string (gethash :skip-tests runner-result))
" test"
(if (> (gethash :skip-tests runner-result) 1) "s" "")
" skipped")
"cyan"))))
(defun create-format-gethash-text-color (runner-result)
(lambda (key text &optional color)
(format t "~a~%"
(cacau-string-color
(concatenate 'string
(write-to-string (gethash key runner-result))
text)
color))))
(defun custom-result (runner-result options)
(let ((format-color (create-format-gethash-text-color runner-result)))
(dolist (i options)
(cond ((equal :running-suites i)
(funcall format-color :suites " running suites" "blue"))
((equal :running-tests i)
(funcall format-color :tests " running tests" "blue"))
((equal :only-suites i)
(funcall format-color :only-suites " only suites" "purple"))
((equal :only-tests i)
(funcall format-color :only-tests " only tests" "purple"))
((equal :skip-suites i)
(funcall format-color :skip-suites " skip suites" "cyan"))
((equal :skip-tests i)
(funcall format-color :skip-tests " skip tests" "cyan"))
((equal :total-suites i)
(funcall format-color :total-suites " total suites" "white"))
((equal :total-tests i)
(funcall format-color :total-tests " total tests" "white"))
((equal :passing i)
(funcall format-color :passing " passed" "green"))
((equal :failing i)
(funcall format-color :failing " failed" "red"))
((equal :errors i)
(format t "~a~%" (cacau-string-color
(concatenate 'string
(write-to-string (length (gethash :errors runner-result)))
" errors")
"black")))
((equal :run-start i)
(funcall format-color :run-start " run start" "white"))
((equal :run-end i)
(funcall format-color :run-end " run end" "white"))
((equal :run-duration i)
(funcall format-color :run-duration " run duration" "yellow"))
((equal :completed-suites i)
(funcall format-color :completed-suites " completed suites" "green"))
((equal :completed-tests i)
(funcall format-color :completed-tests " completed tests" "green"))))))
(defun full-epilogue (runner-result options)
(format t "~%~a" (cacau-string-color "Epilogue" nil))
(separation-bar)
(if options
(custom-result runner-result options)
(custom-result
runner-result
'(:running-suites
:running-tests
:only-suites
:only-tests
:skip-suites
:skip-tests
:total-suites
:total-tests
:passing
:failing
:errors
:run-start
:run-end
:run-duration
:completed-suites
:completed-tests))))
(defun stack-test-errors (runner-result &key (reverse-list t))
(let ((errors (if reverse-list
(reverse (gethash :errors runner-result))
(gethash :errors runner-result))))
(when (> (length errors) 0)
(format t "~%~a" (cacau-string-color "Errors" "red")))
(dolist (test-err errors)
(separation-bar "red")
(format t "~a~%"
(cacau-string-color
(concatenate 'string
"Suite: "
(string-if-not-string (gethash :parent test-err)))
"red"))
(format t "~a~%"
(cacau-string-color
(concatenate 'string
"Test: "
(string-if-not-string (gethash :name test-err)))
"red"))
(format t "~a~%"
(cacau-string-color
(concatenate 'string
(format nil "Message:~%")
(string-if-not-string (gethash :message (gethash :error test-err))))
"red"))
(format t "~a" (cacau-string-color "Read Stack (y/n)? " "red"))
(when (read-yes)
(dolist (line (gethash :stack (gethash :error test-err)))
(format t "~a~%" (cacau-string-color (write-to-string line) "red")))))))
| 7,924 | Common Lisp | .lisp | 181 | 29.607735 | 102 | 0.494763 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 8cb898a7c23e5253f4480b7f5b7843ee746f7675c669416af71a8c71afba5753 | 11,886 | [
-1
] |
11,887 | list.lisp | noloop_cacau/src/reporters/list.lisp | (in-package #:noloop.cacau)
(defun reporter-list (runner options)
(declare (ignore options))
(cacau-logo)
(suite-tests-list-events runner)
(lambda ()
(separation-bar)
(epilogue (result runner))
(skipped (result runner))))
| 244 | Common Lisp | .lisp | 9 | 23.666667 | 37 | 0.699571 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 93b847c2c1ff248cde374590cb03eb3f0a5bb30c4eb4942f0b1a87984b13b2f4 | 11,887 | [
-1
] |
11,888 | runnable.lisp | noloop_cacau/src/kernel/runnable.lisp | (in-package #:noloop.cacau)
(defclass runnable ()
((name :initarg :name
:accessor name)
(fn :initarg :fn
:accessor fn)
(parent :initarg :parent
:accessor parent)
(runnable-error :initform nil
:accessor runnable-error)
(eventbus :initarg :eventbus
:accessor eventbus)
(timer :initform (make-timer)
:accessor timer)
(cl-debugger-p :initform nil
:accessor cl-debugger-p
:allocation :class)
(timeout :initarg :timeout
:initform -1
:accessor timeout)))
(defgeneric run-runnable (obj &optional fn)
(:documentation "Something must be run, such as a test suite that calls run-runnable from each tests, or running a hook."))
(defgeneric after-run (obj)
(:documentation "Something must be run after run-runnable."))
(defmethod done-runnable ((obj runnable))
(lambda (&optional arg)
"The done function accepts an optional argument, which can be either one error or function (useful for catch assertion-error)."
(cond ((typep arg 'assertion-error)
(setf (runnable-error obj) (setf-assertion-error obj arg)))
((typep arg 'error)
(setf (runnable-error obj) (setf-error obj (format nil "~a" arg))))
((typep arg 'function)
(try-fn obj arg)))
(after-run obj)))
(defmethod setf-assertion-error ((obj runnable) c)
(let ((error-hash (make-hash-table)))
(setf-hash error-hash
`((:actual ,(assertion-error-actual c))
(:expected ,(assertion-error-expected c))
(:message ,(assertion-error-message c))
(:result ,(assertion-error-result c))
(:stack ,(assertion-error-stack c))))
(setf (runnable-error obj) error-hash)))
(defmethod setf-error ((obj runnable) error-msg)
(let ((error-hash (make-hash-table)))
(setf-hash error-hash
`((:actual nil)
(:expected nil)
(:message ,error-msg)
(:result nil)
(:stack ,(get-stack-trace))))
(setf (runnable-error obj) error-hash)))
(defmethod try-fn ((obj runnable) try &key after-error-fn)
(handler-case (funcall try)
(assertion-error (c)
(when (cl-debugger-p obj)
(error c))
(setf-assertion-error obj c)
(when after-error-fn
(funcall after-error-fn)))
(error (c)
(when (cl-debugger-p obj)
(error c))
(setf-error obj (format nil "~a" c))
(when after-error-fn
(funcall after-error-fn)))))
(defmethod inherit-timeout ((obj runnable))
(unless (eq :suite-root (name obj))
(when (and (= (timeout obj) -1)
(/= (timeout (parent obj)) -1))
(setf (timeout obj) (timeout (parent obj)))
(start-timeout obj))))
(defmethod start-timeout ((obj runnable))
(when (/= (timeout obj) -1)
(setf (limit-ms (timer obj)) (timeout obj))
(start-timer (timer obj))))
(defmethod timeout-extrapolated-p ((obj runnable))
(let* ((result (extrapolated-p (timer obj))))
(when result
(setf-error
obj
(concatenate
'string
"Timeout Error: Time("
(write-to-string (limit-ms (timer obj)))
") extrapolated!")))
result))
| 3,298 | Common Lisp | .lisp | 87 | 29.954023 | 131 | 0.6 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 62b99eae0bf0ee414e5be6c5ce99d6d063669504a12ee9b8ef89b8619e0936f6 | 11,888 | [
-1
] |
11,889 | runner-listeners.lisp | noloop_cacau/src/kernel/runner-listeners.lisp | (in-package #:noloop.cacau)
(defun create-runner-listeners (runner)
(let ((result-hash (result runner))
(bus (eventbus runner)))
(setf-hash result-hash
`((:suites ,0)
(:tests ,0)
(:only-suites ,0)
(:only-tests ,0)
(:skip-suites ,0)
(:skip-tests ,0)
(:total-suites ,0)
(:total-tests ,0)
(:passing ,0)
(:failing ,0)
(:errors ,(list))
(:run-start ,0)
(:run-end ,0)
(:run-duration ,0)
(:completed-suites ,0)
(:completed-tests ,0)))
(on bus
:add-suite
(lambda (options)
(incf (gethash :total-suites result-hash))
(let ((only-p (second options))
(skip-p (fourth options)))
(cond (only-p (incf (gethash :only-suites result-hash)))
(skip-p (incf (gethash :skip-suites result-hash)))
(t (incf (gethash :suites result-hash)))))))
(on bus
:add-test
(lambda (options)
(incf (gethash :total-tests result-hash))
(let ((only-p (second options))
(skip-p (fourth options)))
(cond (only-p (incf (gethash :only-tests result-hash)))
(skip-p (incf (gethash :skip-tests result-hash)))
(t (incf (gethash :tests result-hash)))))))
(on bus
:pass
(lambda (test)
(declare (ignore test))
(incf (gethash :passing result-hash))))
(on bus
:fail
(lambda (test)
(declare (ignore test))
(incf (gethash :failing result-hash))))
(on bus
:suite-start
(lambda (suite)
(declare (ignore suite))))
(on bus
:suite-end
(lambda (suite)
(unless (abort-p runner)
(let* ((suite-root-p
(eq :suite-root (name suite)))
(suite-next-fn
(lambda ()
(if suite-root-p
(emit bus :run-end)
(progn (next-child (parent suite))
(incf (gethash :completed-suites result-hash)))))))
(if (suite-after-all suite)
(run-runnable (suite-after-all suite)
(lambda ()
(funcall suite-next-fn)))
(funcall suite-next-fn))))))
(on bus
:test-start
(lambda (test)
(declare (ignore test))))
(on bus
:new-error
(lambda (obj new-error)
(let ((error-hash (make-hash-table)))
(setf-hash error-hash
`((:name ,(name obj))
(:fn ,(fn obj))
(:parent ,(name (parent obj)))
(:error ,new-error)))
(push error-hash (gethash :errors result-hash)))))
(on bus
:test-end
(lambda (test)
(unless (abort-p runner)
(if (runnable-error test)
(progn
(emit bus :new-error test (runnable-error test))
(emit bus :fail test))
(emit bus :pass test))
(incf (gethash :completed-tests result-hash)))))
(on bus
:hook-end
(lambda (hook)
(when (runnable-error hook)
(emit bus :new-error hook (runnable-error hook))
(emit bus :run-abort))))
(once bus
:run-start
(lambda ()
(when (or (> (gethash :only-suites result-hash) 0)
(> (gethash :only-tests result-hash) 0))
(inherit-only-recursive (suite-root runner))
(remove-not-only-children-recursive (suite-root runner)))
(when (or (> (gethash :skip-suites result-hash) 0)
(> (gethash :skip-tests result-hash) 0))
(remove-skip-children-recursive (suite-root runner)))
(setf (gethash :suites result-hash)
(count-suites-recursive (itens (children (suite-root runner)))))
(when (zerop (setf (gethash :tests result-hash)
(count-tests-recursive (itens (children (suite-root runner))))))
(emit bus :run-end))
(setf (gethash :run-start result-hash) (get-internal-real-time))))
(once bus
:run-abort
(lambda ()
(setf (abort-p runner) t)
(emit bus :run-end)))
(once bus
:run-end
(lambda ()
(setf (gethash :run-end result-hash) (get-internal-real-time))
(let ((duration (- (gethash :run-end result-hash)
(gethash :run-start result-hash))))
(setf (gethash :run-duration result-hash)
(/ (if (<= duration 0) 1 duration)
internal-time-units-per-second)))
(emit bus :end)))))
| 5,134 | Common Lisp | .lisp | 131 | 24.89313 | 95 | 0.465354 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 186f1c32dda830d4c606c2635c2cc1b3b8b27b8361cc1cfcb210b840afa3e1ad | 11,889 | [
-1
] |
11,890 | hook.lisp | noloop_cacau/src/kernel/hook.lisp | (in-package #:noloop.cacau)
(defclass hook-class (runnable)
((async-p :initarg :async-p
:initform nil
:accessor async-p)
(pos-hook-fn :initform nil
:accessor pos-hook-fn)))
(defun make-hook (&key name fn async-p (timeout -1) eventbus)
(make-instance 'hook-class
:name name
:fn fn
:async-p async-p
:timeout timeout
:eventbus eventbus))
(defmethod run-runnable ((hook hook-class) &optional after-hook)
(setf (pos-hook-fn hook) after-hook)
(start-timeout hook)
(if (async-p hook)
(funcall (fn hook) (done-runnable hook))
(progn
(try-fn hook
(lambda () (funcall (fn hook)))
:after-error-fn
(lambda () (emit (eventbus hook) :run-abort hook)))
(after-run hook))))
(defmethod after-run ((hook hook-class))
(timeout-extrapolated-p hook)
(emit (eventbus hook) :hook-end hook)
(funcall (pos-hook-fn hook)))
| 994 | Common Lisp | .lisp | 29 | 26.482759 | 67 | 0.59375 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 9265dd0409de6f242dd24e42ecbbb425595f150b7921f4ed36751ba89e5f2c6c | 11,890 | [
-1
] |
11,891 | suite.lisp | noloop_cacau/src/kernel/suite.lisp | (in-package #:noloop.cacau)
(defclass suite-class (runnable)
((suite-before-all :initform nil
:accessor suite-before-all)
(suite-after-all :initform nil
:accessor suite-after-all)
(suite-before-each :initform nil
:accessor suite-before-each)
(suite-after-each :initform nil
:accessor suite-after-each)
(parents-before-each :initform (make-list-iterator)
:accessor parents-before-each)
(parents-after-each :initform (make-list-iterator)
:accessor parents-after-each)
(children :initform (make-list-iterator)
:accessor children)
(only-p :initarg :only-p
:initform nil
:accessor only-p)
(skip-p :initarg :skip-p
:initform nil
:accessor skip-p)))
(defun make-suite (&key name parent only-p skip-p (timeout -1) eventbus)
(make-instance 'suite-class
:name name
:parent parent
:only-p only-p
:skip-p skip-p
:timeout timeout
:eventbus eventbus))
(defmethod create-before-all ((suite suite-class) name fn &key async-p (timeout -1))
(setf (suite-before-all suite) (make-hook :name name
:fn fn
:async-p async-p
:timeout timeout
:eventbus (eventbus suite)))
(setf (parent (suite-before-all suite)) suite)
(suite-before-all suite))
(defmethod create-after-all ((suite suite-class) name fn &key async-p (timeout -1))
(setf (suite-after-all suite) (make-hook :name name
:fn fn
:async-p async-p
:timeout timeout
:eventbus (eventbus suite)))
(setf (parent (suite-after-all suite)) suite)
(suite-after-all suite))
(defmethod create-before-each ((suite suite-class) name fn &key async-p (timeout -1))
(setf (suite-before-each suite) (make-hook :name name
:fn fn
:async-p async-p
:timeout timeout
:eventbus (eventbus suite)))
(setf (parent (suite-before-each suite)) suite)
(suite-before-each suite))
(defmethod create-after-each ((suite suite-class) name fn &key async-p (timeout -1))
(setf (suite-after-each suite) (make-hook :name name
:fn fn
:async-p async-p
:timeout timeout
:eventbus (eventbus suite)))
(setf (parent (suite-after-each suite)) suite)
(suite-after-each suite))
(defmethod add-child ((suite suite-class) child)
(setf (parent child) suite)
(add (children suite) child)
child)
(defmethod run-runnable ((suite suite-class) &optional fn)
(declare (ignore fn))
(emit (eventbus suite) :suite-start suite)
(collect-before-each-recursive suite (parents-before-each suite))
(collect-after-each-recursive suite (parents-after-each suite))
(start-iterator-reverse (parents-after-each suite))
(start-iterator-reverse (children suite))
(inherit-timeout suite)
(start-timeout suite)
(if (suite-before-all suite)
(run-runnable (suite-before-all suite)
(lambda ()
(init-suite suite)))
(init-suite suite)))
(defmethod init-suite ((suite suite-class))
(if (empty-p (children suite))
(emit (eventbus suite) :suite-end suite)
(run-runnable (current-item (children suite)))))
(defmethod collect-before-each-recursive ((suite suite-class) parents-each)
(when (suite-before-each suite)
(add parents-each (suite-before-each suite)))
(unless (eq :suite-root (name suite))
(collect-before-each-recursive (parent suite) parents-each)))
(defmethod collect-after-each-recursive ((suite suite-class) parents-each)
(when (suite-after-each suite)
(add parents-each (suite-after-each suite)))
(unless (eq :suite-root (name suite))
(collect-after-each-recursive (parent suite) parents-each)))
(defmethod next-child ((suite suite-class))
(next (children suite))
(if (done-p (children suite))
(emit (eventbus suite) :suite-end suite)
(run-runnable (current-item (children suite)))))
(defmethod execute-suites-each ((suite suite-class) parents-each after-hook-fn)
(if (done-p parents-each)
(funcall after-hook-fn)
(if (last-p parents-each)
(run-runnable (current-item parents-each) after-hook-fn)
(run-runnable
(current-item parents-each)
(lambda ()
(next parents-each)
(execute-suites-each suite parents-each after-hook-fn))))))
(defmethod inherit-only-recursive ((suite suite-class))
(dolist (child (itens (children suite)))
(when (only-p suite)
(setf (only-p child) t))
(when (typep child 'suite-class)
(inherit-only-recursive child))))
(defmethod remove-not-only-children-recursive ((suite suite-class))
(setf (itens (children suite))
(remove-if-not
#'(lambda (child)
(when (typep child 'suite-class)
(remove-not-only-children-recursive child))
(when (has-only-recursive child)
(setf (only-p child) t)))
(itens (children suite)))))
(defun has-only-recursive (obj)
(cond ((typep obj 'test-class)
(only-p obj))
((typep obj 'suite-class)
(some #'(lambda (child)
(cond ((typep child 'test-class)
(only-p child))
((typep child 'suite-class)
(if (only-p child)
t
(has-only-recursive child)))))
(itens (children obj))))))
(defmethod remove-skip-children-recursive ((suite suite-class))
(setf (itens (children suite))
(remove-if
#'(lambda (child)
(when (typep child 'suite-class)
(remove-skip-children-recursive child))
(skip-p child))
(itens (children suite)))))
(defmethod count-tests-recursive (list)
(cond ((null list) 0)
((typep (first list) 'test-class)
(+ 1 (count-tests-recursive (rest list))))
((typep (first list) 'suite-class)
(+ (count-tests-recursive (itens (children (first list))))
(count-tests-recursive (rest list))))))
(defmethod count-suites-recursive (list)
(cond ((null list) 0)
((typep (first list) 'test-class)
(count-suites-recursive (rest list)))
((typep (first list) 'suite-class)
(count-suites-recursive (itens (children (first list))))
(+ 1 (count-suites-recursive (rest list))))))
(defmethod child-by-name ((suite suite-class) parent-name)
(dolist (child (itens (children suite)))
(when (typep child 'suite-class)
(if (equal parent-name (name child))
(return-from child-by-name child)
(return-from child-by-name (child-by-name child parent-name))))))
| 7,282 | Common Lisp | .lisp | 164 | 33.384146 | 85 | 0.582781 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | bfdfdcf92a847d157f6573958030b8679eb413b02a96fcd21fa0bd487a433d42 | 11,891 | [
-1
] |
11,892 | runner.lisp | noloop_cacau/src/kernel/runner.lisp | (in-package #:noloop.cacau)
(defclass runner ()
((eventbus :initform (make-eventbus)
:accessor eventbus)
(suite-root :initarg :suite-root
:accessor suite-root)
(abort-p :initform nil
:accessor abort-p)
(result :initform (make-hash-table)
:accessor result)
(current-suite :accessor current-suite)))
(defun make-runner ()
(let ((new-runner (make-instance 'runner)))
(setf (suite-root new-runner)
(make-suite :name :suite-root
:parent nil
:eventbus (eventbus new-runner)))
(create-runner-listeners new-runner)
(setf (current-suite new-runner) (suite-root new-runner))
new-runner))
(defmethod create-suite ((obj runner) name &key only-p skip-p (timeout -1))
(emit (eventbus obj) :add-suite (list :only-p only-p :skip-p skip-p))
(make-suite :name name
:only-p only-p
:skip-p skip-p
:timeout timeout
:eventbus (eventbus obj)))
(defmethod create-test ((obj runner) name fn &key async-p only-p skip-p (timeout -1))
(emit (eventbus obj) :add-test (list :only-p only-p :skip-p skip-p))
(make-test :name name
:fn fn
:async-p async-p
:only-p only-p
:skip-p skip-p
:timeout timeout
:eventbus (eventbus obj)))
(defmethod run-progress ((obj runner))
(let ((completed-tests (gethash :completed-tests (result obj)))
(tests-percent (/ (gethash :tests (result obj)) 100)))
(round (/ completed-tests
(if (= tests-percent 0)
1
tests-percent)))))
(defmethod once-runner ((obj runner) event-name fn)
(once (eventbus obj) event-name fn))
(defmethod on-runner ((obj runner) event-name fn)
(on (eventbus obj) event-name fn))
(defmethod run-runner ((obj runner))
(emit (eventbus obj) :run-start)
(run-runnable (suite-root obj)))
| 1,948 | Common Lisp | .lisp | 50 | 31.04 | 85 | 0.608788 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 69253d09ceca2022087ab32755a73b5d3a6f90be96e65f5720aeab66add6cd26 | 11,892 | [
-1
] |
11,893 | timer.lisp | noloop_cacau/src/kernel/timer.lisp | (in-package #:noloop.cacau)
(defclass timer-class ()
((limit-ms :initform -1
:initarg :limit-ms
:accessor limit-ms)
(start-ms :initform 0
:initarg :start-ms
:accessor start-ms)
(end-ms :initform 0
:accessor end-ms)
(duration-ms :initform 0
:accessor duration-ms)))
(defun make-timer ()
(make-instance 'timer-class))
(defmethod start-timer ((obj timer-class))
(setf (start-ms obj) (get-internal-real-time)))
(defmethod end-timer ((obj timer-class))
(setf (end-ms obj) (get-internal-real-time))
(let ((duration (- (end-ms obj)
(start-ms obj))))
(setf (duration-ms obj)
(/ (if (<= duration 0) 1 duration)
internal-time-units-per-second))))
(defmethod extrapolated-p ((obj timer-class))
(let ((limit (limit-ms obj)))
(if (= limit -1)
nil
(progn (end-timer obj)
(> (duration-ms obj) limit)))))
| 978 | Common Lisp | .lisp | 29 | 26.206897 | 49 | 0.576882 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 5d2358ee275f61d6aef15243c41c3be974d5652f5920537f17639d01ae3d5d30 | 11,893 | [
-1
] |
11,894 | list-iterator.lisp | noloop_cacau/src/kernel/list-iterator.lisp | (in-package #:noloop.cacau)
(defclass list-iterator ()
((itens :initform '()
:accessor itens)
(current-index :initform 0
:accessor current-index)))
(defun make-list-iterator ()
(make-instance 'list-iterator))
(defmethod add ((obj list-iterator) item)
(push item (itens obj)))
(defmethod start-iterator ((obj list-iterator))
(setf (current-index obj) 0))
(defmethod start-iterator-reverse ((obj list-iterator))
(let ((itens-reverse (reverse (itens obj))))
(setf (current-index obj) 0)
(setf (itens obj) itens-reverse)))
(defmethod next ((obj list-iterator))
(incf (current-index obj)))
(defmethod done-p ((obj list-iterator))
(>= (current-index obj) (length (itens obj))))
(defmethod last-p ((obj list-iterator))
(= (current-index obj) (- (length (itens obj)) 1)))
(defmethod current-item ((obj list-iterator))
(when (done-p obj)
(error "Iterator Out Of Bounds!"))
(nth (current-index obj) (itens obj)))
(defmethod empty-p ((obj list-iterator))
(<= (length (itens obj)) 0))
| 1,050 | Common Lisp | .lisp | 28 | 33.75 | 55 | 0.672601 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | c243e57bb9a83ece13db633240627bce7a00e6df20eddb1787a56aeda1da4b72 | 11,894 | [
-1
] |
11,895 | test.lisp | noloop_cacau/src/kernel/test.lisp | (in-package #:noloop.cacau)
(defclass test-class (runnable)
((async-p :initarg :async-p
:initform nil
:accessor async-p)
(only-p :initarg :only-p
:initform nil
:accessor only-p)
(skip-p :initarg :skip-p
:initform nil
:accessor skip-p)))
(defun make-test (&key name fn async-p only-p skip-p (timeout -1) eventbus)
(make-instance 'test-class
:name name
:fn fn
:async-p async-p
:only-p only-p
:skip-p skip-p
:timeout timeout
:eventbus eventbus))
(defmethod run-runnable ((test test-class) &optional fn)
(declare (ignore fn))
(emit (eventbus test) :test-start test)
(start-iterator (parents-before-each (parent test)))
(execute-suites-each
(parent test)
(parents-before-each (parent test))
(lambda ()
(inherit-timeout test)
(start-timeout test)
(if (async-p test)
(funcall (fn test) (done-runnable test))
(progn
(try-fn test (lambda () (funcall (fn test))))
(after-run test))))))
(defmethod after-run ((test test-class))
(start-iterator (parents-after-each (parent test)))
(execute-suites-each
(parent test)
(parents-after-each (parent test))
(lambda ()
(timeout-extrapolated-p test)
(emit (eventbus test) :test-end test)
(next-child (parent test)))))
| 1,422 | Common Lisp | .lisp | 44 | 25.090909 | 75 | 0.600874 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | b51e9503130caff0a70e85d745f88d2da91d627587b0260c0dc1f398a17c089d | 11,895 | [
-1
] |
11,896 | cl.lisp | noloop_cacau/src/interfaces/cl.lisp | (in-package #:noloop.cacau)
(defmacro defbefore-all (name options &body body)
(cond-options options
`(common-create-before-all
,name
,(if async-p
`(lambda (,async-done) ,@body)
`(lambda () ,@body))
:async-p ,async-p
:timeout ,timeout)))
(defmacro defafter-all (name options &body body)
(cond-options options
`(common-create-after-all
,name
,(if async-p
`(lambda (,async-done) ,@body)
`(lambda () ,@body))
:async-p ,async-p
:timeout ,timeout)))
(defmacro defbefore-each (name options &body body)
(cond-options options
`(common-create-before-each
,name
,(if async-p
`(lambda (,async-done) ,@body)
`(lambda () ,@body))
:async-p ,async-p
:timeout ,timeout)))
(defmacro defafter-each (name options &body body)
(cond-options options
`(common-create-after-each
,name
,(if async-p
`(lambda (,async-done) ,@body)
`(lambda () ,@body))
:async-p ,async-p
:timeout ,timeout)))
(defmacro defsuite (name options &body body)
(cond-options options
`(common-create-suite
,name
(lambda () ,@body)
:only-p ,only-p
:skip-p ,skip-p
:timeout ,timeout)))
(defmacro deftest (name options &body body)
(cond-options options
`(common-create-test
,name
,(if async-p
`(lambda (,async-done) ,@body)
`(lambda () ,@body))
:async-p ,async-p
:only-p ,only-p
:skip-p ,skip-p
:timeout ,timeout)))
| 1,575 | Common Lisp | .lisp | 56 | 21.5 | 50 | 0.577381 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 5909e4e151bb52aecddb5b60caf20a00e7ae11b527d0f4a5498a350e3b52e383 | 11,896 | [
-1
] |
11,897 | bdd.lisp | noloop_cacau/src/interfaces/bdd.lisp | (in-package #:noloop.cacau)
(defun before-all (name fn &key async (timeout -1))
(common-create-before-all name fn :async-p async :timeout timeout))
(defun after-all (name fn &key async (timeout -1))
(common-create-after-all name fn :async-p async :timeout timeout))
(defun before-each (name fn &key async (timeout -1))
(common-create-before-each name fn :async-p async :timeout timeout))
(defun after-each (name fn &key async (timeout -1))
(common-create-after-each name fn :async-p async :timeout timeout))
(defun context (name fn &key only skip (timeout -1))
(common-create-suite name fn :only-p only
:skip-p skip
:timeout timeout))
(defun it (name fn &key async only skip (timeout -1))
(common-create-test name fn :async-p async
:only-p only
:skip-p skip
:timeout timeout))
| 934 | Common Lisp | .lisp | 18 | 42.166667 | 70 | 0.622662 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | bc70a708372722246f5c8ba8edd7becc77e5fd9babfe8231da932eb2fae5514c | 11,897 | [
-1
] |
11,898 | tdd.lisp | noloop_cacau/src/interfaces/tdd.lisp | (in-package #:noloop.cacau)
(defun suite-setup (name fn &key async (timeout -1))
(common-create-before-all name fn :async-p async :timeout timeout))
(defun suite-teardown (name fn &key async (timeout -1))
(common-create-after-all name fn :async-p async :timeout timeout))
(defun test-setup (name fn &key async (timeout -1))
(common-create-before-each name fn :async-p async :timeout timeout))
(defun test-teardown (name fn &key async (timeout -1))
(common-create-after-each name fn :async-p async :timeout timeout))
(defun suite (name fn &key only skip (timeout -1))
(common-create-suite name fn :only-p only
:skip-p skip
:timeout timeout))
(defun test (name fn &key async only skip (timeout -1))
(common-create-test name fn :async-p async
:only-p only
:skip-p skip
:timeout timeout))
| 942 | Common Lisp | .lisp | 18 | 42.611111 | 70 | 0.625954 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 04194dbf925cb390bd2784584e15bbf4fec72f6a2d5acdb1d32886802a0f228a | 11,898 | [
-1
] |
11,899 | common.lisp | noloop_cacau/src/interfaces/common.lisp | (in-package #:noloop.cacau)
(defun common-create-before-all (name fn &key async-p (timeout -1))
(create-before-all (current-suite (cacau-runner)) name fn :async-p async-p :timeout timeout))
(defun common-create-after-all (name fn &key async-p (timeout -1))
(create-after-all (current-suite (cacau-runner)) name fn :async-p async-p :timeout timeout))
(defun common-create-before-each (name fn &key async-p (timeout -1))
(create-before-each (current-suite (cacau-runner)) name fn :async-p async-p :timeout timeout))
(defun common-create-after-each (name fn &key async-p (timeout -1))
(create-after-each (current-suite (cacau-runner)) name fn :async-p async-p :timeout timeout))
(defun common-create-suite (name fn &key (only-p nil) (skip-p nil) (timeout -1))
(let ((suite (create-suite (cacau-runner) name
:only-p only-p
:skip-p skip-p
:timeout timeout)))
(let ((old-current-suite (current-suite (cacau-runner))))
(add-child (current-suite (cacau-runner)) suite)
(setf (current-suite (cacau-runner)) suite)
(funcall fn)
(setf (current-suite (cacau-runner)) old-current-suite))
suite))
(defun common-create-suite-with-parent (name &key only-p skip-p (timeout -1) (parent :suite-root))
(let ((suite (create-suite (cacau-runner) name
:only-p only-p
:skip-p skip-p
:timeout timeout)))
(setf parent
(if (equal parent :suite-root)
(suite-root (cacau-runner))
(child-by-name (suite-root (cacau-runner)) parent)))
(add-child parent suite)
(setf (current-suite (cacau-runner)) suite)
suite))
(defun common-create-test (name fn &key async-p only-p skip-p (timeout -1))
(let ((test (create-test (cacau-runner) name fn
:async-p async-p
:only-p only-p
:skip-p skip-p
:timeout timeout)))
(add-child (current-suite (cacau-runner)) test)
test))
(defmacro cond-options (options &body body)
`(let ((only-p nil)
(skip-p nil)
(async-p nil)
(async-done nil)
(timeout -1)
(parent :suite-root))
(dolist (i ,options)
(cond ((equal :only i)
(setf only-p t))
((equal :skip i)
(setf skip-p t))
((listp i)
(cond ((equal :timeout (first i))
(setf timeout (second i)))
((equal :async (first i))
(progn (setf async-p t)
(setf async-done (second i))))
((equal :parent (first i))
(setf parent (second i)))))))
,@body))
| 2,824 | Common Lisp | .lisp | 61 | 34.803279 | 98 | 0.556443 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 5a7a875c20e4122b46000fac94f6d5250606d820236731654022f32c6956da15 | 11,899 | [
-1
] |
11,900 | no-spaghetti.lisp | noloop_cacau/src/interfaces/no-spaghetti.lisp | (in-package #:noloop.cacau)
(defmacro defbefore-plan (name options &body body)
(cond-options options
`(common-create-before-all
,name
,(if async-p
`(lambda (,async-done) ,@body)
`(lambda () ,@body))
:async-p ,async-p
:timeout ,timeout)))
(defmacro defafter-plan (name options &body body)
(cond-options options
`(common-create-after-all
,name
,(if async-p
`(lambda (,async-done) ,@body)
`(lambda () ,@body))
:async-p ,async-p
:timeout ,timeout)))
(defmacro defbefore-t (name options &body body)
(cond-options options
`(common-create-before-each
,name
,(if async-p
`(lambda (,async-done) ,@body)
`(lambda () ,@body))
:async-p ,async-p
:timeout ,timeout)))
(defmacro defafter-t (name options &body body)
(cond-options options
`(common-create-after-each
,name
,(if async-p
`(lambda (,async-done) ,@body)
`(lambda () ,@body))
:async-p ,async-p
:timeout ,timeout)))
(defmacro in-plan (name &optional (options ()))
(cond-options options
`(common-create-suite-with-parent
,name
:only-p ,only-p
:skip-p ,skip-p
:timeout ,timeout
:parent ,parent)))
(defmacro deft (name options &body body)
(cond-options options
`(common-create-test
,name
,(if async-p
`(lambda (,async-done) ,@body)
`(lambda () ,@body))
:async-p ,async-p
:only-p ,only-p
:skip-p ,skip-p
:timeout ,timeout)))
| 1,580 | Common Lisp | .lisp | 56 | 21.589286 | 50 | 0.577456 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 9e153281c8a32a34b8201668877d1e58c35b2ad2d135dd30f7b8382f27d56750 | 11,900 | [
-1
] |
11,901 | recursive-runner.lisp | noloop_cacau/t/recursive-runner.lisp | (defpackage #:noloop.cacau-test
(:use #:common-lisp
#:assert-p
#:cacau)
(:nicknames #:cacau-test))
(in-package #:noloop.cacau-test)
;;; How to use:
;;; (r-test :test-1 #'(lambda (done) (funcall done (= 1 3))))
;;; (r-test :test-2 #'(lambda (done) (funcall done (= 2 2))))
;;; (r-test :test-3 #'(lambda (done) (funcall done)))
;;; (r-run)
(let ((plan '()))
(defun r-test (name fn)
(push (list name fn) plan))
(defun next-test-class (plan-tests)
(let ((tests (reverse plan-tests)))
(lambda ()
(let* ((test (car tests))
(test-name (car test))
(test-fn (cadr test)))
(when (> (length tests) 0)
(setf tests (cdr tests))
(format t "Test ~a: " test-name)
(funcall test-fn #'recursive-done))))))
(defun next-results-class (plan-tests)
(let ((results '())
(plan-length (length plan-tests)))
(lambda (test-result)
(push test-result results)
(when (= (length results) plan-length)
(format t "Runner Result: ~a"
(every #'(lambda (el)
(eq t el))
results))))))
(defun r-run ()
(let ((next-test (next-test-class plan))
(next-results (next-results-class plan)))
(defun recursive-done (&optional (test nil test-supplied-p))
(let ((test-result nil))
(if test-supplied-p
(setf test-result test)
(setf test-result t))
(format t "~a~%" test-result)
(funcall next-test)
(funcall next-results test-result)))
(handler-case (funcall next-test)
(error (c)
(setf plan '())
(error c)))
(setf plan '()))))
| 1,771 | Common Lisp | .lisp | 50 | 26.54 | 66 | 0.520797 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 36aafa89be0cffa718629b014dcd439cd302fba952ac76ebaed4dfc44548df84 | 11,901 | [
-1
] |
11,902 | cl-test.lisp | noloop_cacau/t/interface/cl-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-cl-interface
(lambda (r-done)
(defsuite :suite-1 ()
(let ((x 0))
(defbefore-all "Before-all Suite-1" () (setf x 1))
(deftest "Test-1" () (eql-p x 1))
(deftest "Test-2" ((:async done))
(incf x)
(funcall done (lambda () (eql-p x 2))))
(defsuite :suite-2 ()
(let ((x 0))
(defafter-all "After-all Suite-2" ((:async done-hook)) (setf x 1) (funcall done-hook))
(deftest "Test-1" ((:async done))
(incf x)
(funcall done (lambda () (eql-p x 1))))
(deftest "Test-2" () (eql-p x 1))
(defsuite :suite-3 ()
(let ((x 0))
(defbefore-each "Before-each Suite-3" () (setf x 1))
(deftest "Test-1" () (incf x) (eql-p x 2))
(deftest "Test-2" () (eql-p x 1))))))))
(defsuite :suite-4 ()
(let ((x 0))
(defafter-each "After-each Suite-4" () (setf x 0))
(deftest "Test-1" () (incf x) (eql-p x 1))
(deftest "Test-2" ((:async done))
(funcall done (lambda () (eql-p x 0))))))
(run
:reporter :off
:after-run
(lambda (runner)
(let ((passing
(gethash :passing (result runner))))
(funcall r-done (eql 8 passing)))))))
(r-test
:test-cl-interface-timeout
(lambda (r-done)
(defsuite :suite-1 ((:timeout 0))
(let ((x 0))
(defbefore-all "Before-all Suite-1" ((:timeout 50000)) (setf x 1))
(deftest "Test-1" ((:timeout 50000)) (eql-p x 1))
(deftest "Test-2" ((:async done)) (incf x)
(funcall done (lambda () (eql-p x 2))))
(defsuite :suite-2 ()
(let ((x 0))
(defafter-all "After-all Suite-2" ((:timeout 50000) (:async done-hook)) (setf x 1) (funcall done-hook))
(deftest "Test-1" ((:async done))
(incf x)
(funcall done (lambda () (eql-p x 1))))
(deftest "Test-2" () (eql-p x 1))
(defsuite :suite-3 ()
(let ((x 0))
(defbefore-each "Before-each Suite-3" ((:timeout 50000)) (setf x 1))
(deftest "Test-1" ((:timeout 50000)) (incf x) (eql-p x 2))
(deftest "Test-2" () (eql-p x 1))))))))
(defsuite :suite-4 ()
(let ((x 0))
(defafter-each "After-each Suite-4" ((:timeout 50000)) (setf x 0))
(deftest "Test-1" () (incf x) (eql-p x 1))
(deftest "Test-2" ((:async done))
(funcall done (lambda () (eql-p x 0))))))
(run
:reporter :off
:after-run
(lambda (runner)
(let ((passing
(gethash :passing (result runner))))
(funcall r-done (eql 4 passing)))))))
(r-test
:test-cl-interface-skip-and-only
(lambda (r-done)
(defsuite :suite-1 (:only)
(let ((x 0))
(defbefore-all "Before-all Suite-1" () (setf x 1))
(deftest "Test-1" () (eql-p x 1))
(deftest "Test-2" ((:async done))
(incf x)
(funcall done (lambda () (eql-p x 2))))
(defsuite :suite-2 ()
(let ((x 0))
(defafter-all "After-all Suite-2" ((:async done-hook)) (setf x 1) (funcall done-hook))
(deftest "Test-1" ((:async done))
(incf x)
(funcall done (lambda () (eql-p x 1))))
(deftest "Test-2" (:skip) (eql-p x 1))
(defsuite :suite-3 (:skip)
(let ((x 0))
(defbefore-each "Before-each Suite-3" () (setf x 1))
(deftest "Test-1" () (incf x) (eql-p x 2))
(deftest "Test-2" () (eql-p x 1))))))))
(defsuite :suite-4 ()
(let ((x 0))
(defafter-each "After-each Suite-4" () (setf x 0))
(deftest "Test-1" () (incf x) (eql-p x 1))
(deftest "Test-2" (:only (:async done))
(funcall done (lambda () (eql-p x 0))))))
(run
:reporter :off
:after-run
(lambda (runner)
(let ((passing
(gethash :passing (result runner))))
(funcall r-done (eql 4 passing)))))))
| 4,004 | Common Lisp | .lisp | 105 | 29.352381 | 114 | 0.499101 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 2403de4c004f4c81588ca73cfa460ffbe7aea59522200ab27356ba7abbf55e1b | 11,902 | [
-1
] |
11,903 | bdd-test.lisp | noloop_cacau/t/interface/bdd-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-bdd-interface
(lambda (r-done)
(context
"Suite-1"
(lambda (&optional (x 0))
(before-all "Before-all Suite-1" (lambda () (setf x 1)))
(it "Test-1" (lambda () (eql-p x 1)))
(it "Test-2" (lambda () (incf x) (eql-p x 2)))
(context
"Suite-2"
(lambda (&optional (x 0))
(after-all "After-all Suite-2" (lambda (done-hook) (setf x 1) (funcall done-hook)) :async t)
(it "Test-1" (lambda () (incf x) (eql-p x 1)))
(it "Test-2" (lambda () (eql-p x 1)))
(context
"Suite-3"
(lambda (&optional (x 0))
(before-each "Before-each Suite-3" (lambda () (setf x 1)))
(it "Test-1" (lambda () (incf x) (eql-p x 2)))
(it "Test-2" (lambda () (eql-p x 1)))))))))
(context
"Suite-4"
(lambda ()
(let ((x 0))
(after-each "After-each Suite-4" (lambda () (setf x 0)))
(it "Test-1" (lambda () (incf x) (eql-p x 1)))
(it "Test-2" (lambda () (eql-p x 0))))))
(run
:reporter :off
:after-run
(lambda (runner)
(let ((passing
(gethash :passing (result runner))))
(funcall r-done (eql 8 passing)))))))
(r-test
:test-bdd-interface-timeout
(lambda (r-done)
(context
"Suite-1"
(lambda (&optional (x 0))
(before-all "Before-all Suite-1" (lambda () (setf x 1)))
(it "Test-1" (lambda () (eql-p x 1)) :timeout 50000)
(it "Test-2" (lambda () (incf x) (eql-p x 2)))
(context
"Suite-2"
(lambda (&optional (x 0))
(after-all "After-all Suite-2" (lambda (done-hook) (setf x 1) (funcall done-hook)) :async t)
(it "Test-1" (lambda () (incf x) (eql-p x 1)))
(it "Test-2" (lambda () (eql-p x 1)) :timeout 50000)
(context
"Suite-3"
(lambda (&optional (x 0))
(before-each "Before-each Suite-3" (lambda () (setf x 1)))
(it "Test-1" (lambda () (incf x) (eql-p x 2)))
(it "Test-2" (lambda () (eql-p x 1))))))))
:timeout 0)
(context
"Suite-4"
(lambda ()
(let ((x 0))
(after-each "After-each Suite-4" (lambda () (setf x 0)))
(it "Test-1" (lambda () (incf x) (eql-p x 1)))
(it "Test-2" (lambda () (eql-p x 0))))))
(run
:reporter :off
:after-run
(lambda (runner)
(let ((passing
(gethash :passing (result runner))))
(funcall r-done (eql 4 passing)))))))
(r-test
:test-bdd-interface-skip-and-only
(lambda (r-done)
(context
"Suite-1"
(lambda (&optional (x 0))
(before-all "Before-all Suite-1" (lambda () (setf x 1)))
(it "Test-1" (lambda () (eql-p x 1)))
(it "Test-2" (lambda () (incf x) (eql-p x 2)))
(context
"Suite-2"
(lambda (&optional (x 0))
(after-all "After-all Suite-2" (lambda (done-hook) (setf x 1) (funcall done-hook)) :async t)
(it "Test-1" (lambda () (incf x) (eql-p x 1)))
(it "Test-2" (lambda () (eql-p x 1)) :skip t)
(context
"Suite-3"
(lambda (&optional (x 0))
(before-each "Before-each Suite-3" (lambda () (setf x 1)))
(it "Test-1" (lambda (done)
(incf x)
(funcall done (lambda () (eql-p x 2))))
:async t)
(it "Test-2" (lambda () (eql-p x 1))))
:skip t))))
:only t)
(context
"Suite-4"
(lambda ()
(let ((x 0))
(after-each "After-each Suite-4" (lambda () (setf x 0)))
(it "Test-1" (lambda () (incf x) (eql-p x 1)) :only t)
(it "Test-2" (lambda () (eql-p x 0))))))
(run
:reporter :off
:after-run
(lambda (runner)
(let ((passing
(gethash :passing (result runner))))
(funcall r-done (eql 4 passing)))))))
| 3,858 | Common Lisp | .lisp | 112 | 26.669643 | 101 | 0.498129 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 825fa11680c8fa795a2eaa4cb1184d84a7a321a9bd38de7480fe2386f11199fb | 11,903 | [
-1
] |
11,904 | mix-test.lisp | noloop_cacau/t/interface/mix-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-interface-mix
(lambda (r-done)
(let ((x 0))
(context
:suite-1
(lambda ()
(before-all "Before-all Suite-1" (lambda () (setf x 1)))
(it "Test-1" (lambda (done) (funcall done (lambda () (eql-p x 1)))) :async t)
(it "Test-2" (lambda () (incf x) (eql-p x 2)))
(in-plan :suite-2 ((:parent :suite-1)))
(defafter-plan :after-plan-suite-2 ((:async done-hook)) (setf x 1) (funcall done-hook))
(deft :test-1 () (eql-p x 2))
(deft :test-2 () (incf x) (eql-p x 3))
(suite
"Suite-3"
(lambda (&optional (x 0))
(test-setup "Test-setup Suite-3" (lambda () (setf x 1)))
(test "Test-1" (lambda () (incf x) (eql-p x 2)))
(test "Test-2" (lambda () (eql-p x 1)))))))
(defsuite :suite-4 ()
(let ((x 0))
(defafter-each "After-each Suite-4" () (setf x 0))
(deftest "Test-1" () (incf x) (eql-p x 1))
(deftest "Test-2" ((:async done))
(funcall done (lambda () (eql-p x 0)))))))
(run
:reporter :off
:after-run
(lambda (runner)
(let ((passing
(gethash :passing (result runner))))
(funcall r-done (eql 8 passing)))))))
| 1,284 | Common Lisp | .lisp | 34 | 29.5 | 95 | 0.508914 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 557888da5663e486fa41520efb68b63ba9622e7bb9b322ad14d4d099d89a935b | 11,904 | [
-1
] |
11,905 | tdd-test.lisp | noloop_cacau/t/interface/tdd-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-new-tdd-interface
(lambda (r-done)
(suite
"Suite-1"
(lambda (&optional (x 0))
(suite-setup "Suite-setup Suite-1" (lambda () (setf x 1)))
(test "Test-1" (lambda () (eql-p x 1)))
(test "Test-2" (lambda () (incf x) (eql-p x 2)))
(suite
"Suite-2"
(lambda (&optional (x 0))
(suite-teardown "Suite-teardown Suite-2" (lambda (done-hook) (setf x 1) (funcall done-hook)) :async t)
(test "Test-1" (lambda () (incf x) (eql-p x 1)))
(test "Test-2" (lambda () (eql-p x 1)))
(suite
"Suite-3"
(lambda (&optional (x 0))
(test-setup "Test-setup Suite-3" (lambda () (setf x 1)))
(test "Test-1" (lambda (done)
(incf x)
(funcall done (lambda () (eql-p x 2))))
:async t)
(test "Test-2" (lambda () (eql-p x 1)))))))))
(suite
"Suite-4"
(lambda ()
(let ((x 0))
(test-teardown "Test-teardown Suite-4" (lambda () (setf x 0)))
(test "Test-1" (lambda () (incf x) (eql-p x 1)))
(test "Test-2" (lambda () (eql-p x 0))))))
(run
:reporter :off
:after-run
(lambda (runner)
(let ((passing
(gethash :passing (result runner))))
(funcall r-done (eql 8 passing)))))))
(r-test
:test-new-tdd-interface-timeout
(lambda (r-done)
(suite
"Suite-1"
(lambda (&optional (x 0))
(suite-setup "Suite-setup Suite-1" (lambda () (setf x 1)))
(test "Test-1" (lambda () (eql-p x 1)) :timeout 0)
(test "Test-2" (lambda () (incf x) (eql-p x 2)))
(suite
"Suite-2"
(lambda (&optional (x 0))
(suite-teardown "Suite-teardown Suite-2" (lambda (done-hook) (setf x 1) (funcall done-hook)) :async t)
(test "Test-1" (lambda () (incf x) (eql-p x 1)))
(test "Test-2" (lambda () (eql-p x 1)) :timeout 0)
(suite
"Suite-3"
(lambda (&optional (x 0))
(test-setup "Test-setup Suite-3" (lambda () (setf x 1)))
(test "Test-1" (lambda () (incf x) (eql-p x 2)) :timeout 0)
(test "Test-2" (lambda () (eql-p x 1))))))))
:timeout 50000)
(suite
"Suite-4"
(lambda ()
(let ((x 0))
(test-teardown "Test-teardown Suite-4" (lambda () (setf x 0)))
(test "Test-1" (lambda () (incf x) (eql-p x 1)))
(test "Test-2" (lambda () (eql-p x 0)) :timeout 0))))
(run
:reporter :off
:after-run
(lambda (runner)
(let ((passing
(gethash :passing (result runner))))
(funcall r-done (eql 4 passing)))))))
(r-test
:test-new-tdd-interface-skip-and-only
(lambda (r-done)
(suite
"Suite-1"
(lambda (&optional (x 0))
(suite-setup "Suite-setup Suite-1" (lambda () (setf x 1)))
(test "Test-1" (lambda () (eql-p x 1)))
(test "Test-2" (lambda () (incf x) (eql-p x 2)))
(suite
"Suite-2"
(lambda (&optional (x 0))
(suite-teardown "Suite-teardown Suite-2" (lambda (done-hook) (setf x 1) (funcall done-hook)) :async t)
(test "Test-1" (lambda () (incf x) (eql-p x 1)))
(test "Test-2" (lambda () (eql-p x 1)) :skip t)
(suite
"Suite-3"
(lambda (&optional (x 0))
(test-setup "Test-setup Suite-3" (lambda () (setf x 1)))
(test "Test-1" (lambda () (incf x) (eql-p x 2)))
(test "Test-2" (lambda () (eql-p x 1))))
:skip t))))
:only t)
(suite
"Suite-4"
(lambda ()
(let ((x 0))
(test-teardown "Test-teardown Suite-4" (lambda () (setf x 0)))
(test "Test-1" (lambda () (incf x) (eql-p x 1)) :only t)
(test "Test-2" (lambda () (eql-p x 0))))))
(run
:reporter :off
:after-run
(lambda (runner)
(let ((passing
(gethash :passing (result runner))))
(funcall r-done (eql 4 passing)))))))
| 3,966 | Common Lisp | .lisp | 112 | 27.580357 | 111 | 0.508312 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 79bda325db6bdc791bc8aabbca9e945b8754c6ed4b274e538a70bbe1f71fbf1a | 11,905 | [
-1
] |
11,906 | no-spaghetti-test.lisp | noloop_cacau/t/interface/no-spaghetti-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-no-spaghetti-interface
(lambda (r-done)
(let ((x 0))
(in-plan :suite-1 ()) ;; or (in-suite :suite-1 ((:parent :suite-root)))
(defbefore-plan :before-plan-suite-1 () (setf x 1))
(deft :test-1 () (eql-p x 1))
(deft :test-2 ((:async done))
(incf x)
(funcall done (lambda () (eql-p x 2))))
(in-plan :suite-2 ((:parent :suite-1)))
(defafter-plan :after-plan-suite-2 ((:async done-hook)) (setf x 1) (funcall done-hook))
(deft :test-1 () (eql-p x 2))
(deft :test-2 () (incf x) (eql-p x 3))
(in-plan :suite-3 ((:parent :suite-2)))
(defbefore-t :before-t-suite-3 () (setf x 0))
(deft :test-1 () (incf x) (eql-p x 1))
(deft :test-2 () (eql-p x 0))
(in-plan :suite-4) ;; or (in-suite :suite-4 ((:parent :suite-root)))
(defafter-t :after-t-suite-4 () (setf x 0))
(deft :test-1 () (incf x) (eql-p x 2))
(deft :test-2 () (eql-p x 0)))
(run
:reporter :off
:after-run
(lambda (runner)
(let ((passing
(gethash :passing (result runner))))
(funcall r-done (eql 8 passing)))))))
(r-test
:test-no-spaghetti-interface-timeout
(lambda (r-done)
(let ((x 0))
(in-plan :suite-1 ((:timeout 0)))
(defbefore-plan :before-plan-suite-1 () (setf x 1))
(deft :test-1 ((:timeout 50000)) (eql-p x 1))
(deft :test-2 ((:async done))
(incf x)
(funcall done (lambda () (eql-p x 2))))
(in-plan :suite-2 ((:parent :suite-1)))
(defafter-plan :after-plan-suite-2 ((:async done-hook)) (setf x 1) (funcall done-hook))
(deft :test-1 () (eql-p x 2))
(deft :test-2 () (incf x) (eql-p x 3))
(in-plan :suite-3 ((:parent :suite-2)))
(defbefore-t :before-t-suite-3 () (setf x 0))
(deft :test-1 () (incf x) (eql-p x 1))
(deft :test-2 ((:timeout 50000)) (eql-p x 0))
(in-plan :suite-4)
(defafter-t :after-t-suite-4 () (setf x 0))
(deft :test-1 () (incf x) (eql-p x 2))
(deft :test-2 () (eql-p x 0)))
(run
:reporter :off
:after-run
(lambda (runner)
(let ((passing
(gethash :passing (result runner))))
(funcall r-done (eql 4 passing)))))))
(r-test
:test-no-spaghetti-interface-skip-and-only
(lambda (r-done)
(let ((x 0))
(in-plan :suite-1 (:only))
(defbefore-plan :before-plan-suite-1 () (setf x 1))
(deft :test-1 ((:async done))
(funcall done (lambda () (eql-p x 1))))
(deft :test-2 () (incf x) (eql-p x 2))
(in-plan :suite-2 ((:parent :suite-1)))
(defafter-plan :after-plan-suite-2 ((:async done-hook)) (setf x 1) (funcall done-hook))
(deft :test-1 () (eql-p x 2))
(deft :test-2 (:skip) (incf x) (eql-p x 3))
(in-plan :suite-3 ((:parent :suite-2) :skip))
(defbefore-t :before-t-suite-3 () (setf x 0))
(deft :test-1 () (incf x) (eql-p x 1))
(deft :test-2 () (eql-p x 0))
(in-plan :suite-4)
(defafter-t :after-t-suite-4 () (setf x 0))
(deft :test-1 (:only) (incf x) (eql-p x 2))
(deft :test-2 () (eql-p x 0)))
(run
:reporter :off
:after-run
(lambda (runner)
(let ((passing
(gethash :passing (result runner))))
(funcall r-done (eql 4 passing)))))))
| 3,285 | Common Lisp | .lisp | 87 | 31.632184 | 92 | 0.546831 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 83c027360ad86e185321db2df737d5ff917702156f292e31e4bff07b1bde069b | 11,906 | [
-1
] |
11,907 | only-test.lisp | noloop_cacau/t/functional/only-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-not-only-test
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(test-2 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p t)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((completed-tests
(gethash :completed-tests (result runner-instance))))
(funcall r-done (eql 2 completed-tests)))))
(run-runner runner-instance))))
(r-test
:test-only-test
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(test-2 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(t-p nil))
:only-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 1 failing)))))
(run-runner runner-instance))))
(r-test
:test-only-test-with-two-only-tests
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(test-2 nil)
(test-3 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(t-p nil))
:only-p t)))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(t-p nil)))))
(setf test-3
(add-child suite-1
(create-test runner-instance
:test-3
(lambda ()
(t-p nil))
:only-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 2 failing)))))
(run-runner runner-instance))))
(r-test
:test-only-test-recursive-with-three-only-tests
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(t-p nil))
:only-p t)))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(t-p nil)))))
(add-child suite-1 suite-2)
(setf test-4
(add-child suite-2
(create-test runner-instance
:test-4
(lambda ()
(t-p nil))
:only-p t)))
(setf test-5
(add-child suite-2
(create-test runner-instance
:test-5
(lambda ()
(t-p nil)))))
(setf test-3
(add-child suite-1
(create-test runner-instance
:test-3
(lambda ()
(t-p nil))
:only-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 3 failing)))))
(run-runner runner-instance))))
(r-test
:test-only-test-recursive-with-two-suites-in-suite-root
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(suite-3 (create-suite runner-instance
:suite-3))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil)
(test-6 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(t-p nil))
:only-p t)))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(t-p nil)))))
(add-child suite-1 suite-2)
(setf test-4
(add-child suite-2
(create-test runner-instance
:test-4
(lambda ()
(t-p nil))
:only-p t)))
(setf test-5
(add-child suite-2
(create-test runner-instance
:test-5
(lambda ()
(t-p nil)))))
(setf test-3
(add-child suite-1
(create-test runner-instance
:test-3
(lambda ()
(t-p nil))
:only-p t)))
(add-child suite-root suite-3)
(setf test-6
(add-child suite-3
(create-test runner-instance
:test-6
(lambda ()
(t-p nil))
:only-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 4 failing)))))
(run-runner runner-instance))))
(r-test
:test-only-suite
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:only-p t))
(test-1 nil)
(test-2 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 2 failing)))))
(run-runner runner-instance))))
(r-test
:test-only-suite-recursive
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:only-p t))
(suite-2 (create-suite runner-instance
:suite-2))
(suite-3 (create-suite runner-instance
:suite-3))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil)))))
(setf test-4
(add-child suite-1
(create-test runner-instance
:test-4
(lambda () (t-p nil)))))
(add-child suite-root suite-3)
(setf test-5
(add-child suite-3
(create-test runner-instance
:test-5
(lambda () (t-p nil)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 4 failing)))))
(run-runner runner-instance))))
(r-test
:test-only-suite-recursive-with-one-only-test
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(suite-3 (create-suite runner-instance
:suite-3))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil)))))
(setf test-4
(add-child suite-1
(create-test runner-instance
:test-4
(lambda () (t-p nil))
:only-p t)))
(add-child suite-root suite-3)
(setf test-5
(add-child suite-3
(create-test runner-instance
:test-5
(lambda () (t-p nil)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 1 failing)))))
(run-runner runner-instance))))
(r-test
:test-only-suite-recursive-with-two-only-test
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(suite-3 (create-suite runner-instance
:suite-3))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil))
:only-p t)))
(setf test-4
(add-child suite-1
(create-test runner-instance
:test-4
(lambda () (t-p nil)))))
(add-child suite-root suite-3)
(setf test-5
(add-child suite-3
(create-test runner-instance
:test-5
(lambda () (t-p nil))
:only-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 2 failing)))))
(run-runner runner-instance))))
(r-test
:test-only-suite-recursive-with-two-only-suite
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:only-p t))
(suite-2 (create-suite runner-instance
:suite-2))
(suite-3 (create-suite runner-instance
:suite-3))
(suite-4 (create-suite runner-instance
:suite-4
:only-p t))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil)
(test-6 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil)))))
(setf test-4
(add-child suite-1
(create-test runner-instance
:test-4
(lambda () (t-p nil)))))
(add-child suite-root suite-3)
(setf test-5
(add-child suite-3
(create-test runner-instance
:test-5
(lambda () (t-p nil)))))
(add-child suite-3 suite-4)
(setf test-6
(add-child suite-4
(create-test runner-instance
:test-6
(lambda () (t-p nil)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 5 failing)))))
(run-runner runner-instance))))
(r-test
:test-only-suite-recursive-with-two-only-suite-and-three-only-test
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2
:only-p t))
(suite-3 (create-suite runner-instance
:suite-3))
(suite-4 (create-suite runner-instance
:suite-4
:only-p t))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil)
(test-6 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil))
:only-p t)))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil))
:only-p t)))
(setf test-4
(add-child suite-1
(create-test runner-instance
:test-4
(lambda () (t-p nil)))))
(add-child suite-root suite-3)
(setf test-5
(add-child suite-3
(create-test runner-instance
:test-5
(lambda () (t-p nil)))))
(add-child suite-3 suite-4)
(setf test-6
(add-child suite-4
(create-test runner-instance
:test-6
(lambda () (t-p nil))
:only-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 3 failing)))))
(run-runner runner-instance))))
| 20,506 | Common Lisp | .lisp | 531 | 19.52354 | 81 | 0.378751 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 419f06bd34dc5fba519bd79248f83f1cee2498c29adc1ac29dfadac1418a9ba3 | 11,907 | [
-1
] |
11,908 | after-all-test.lisp | noloop_cacau/t/functional/after-all-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-after-all
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(x 0))
(add-child suite-root suite-1)
(create-after-all suite-1
:after-all-suite-1
(lambda ()
(setf x 1)))
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 0))))
(once-runner runner-instance
:end
(lambda ()
(funcall r-done (eql x 1))))
(run-runner runner-instance))))
(r-test
:test-async-after-all
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(x 0))
(add-child suite-root suite-1)
(create-after-all suite-1
:after-all-suite-1
(lambda (hook-done)
(setf x 1)
(funcall hook-done))
:async-p t)
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 0))))
(once-runner runner-instance
:end
(lambda ()
(funcall r-done (eql x 1))))
(run-runner runner-instance))))
(r-test
:test-after-all-order
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(x 0))
(add-child suite-root suite-1)
(create-after-all suite-1
:after-all-suite-1
(lambda (hook-done)
(setf x 1)
(funcall hook-done))
:async-p t)
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 0))))
(add-child suite-1 suite-2)
(create-after-all suite-2
:after-all-suite-2
(lambda ()
(setf x 2)))
(add-child suite-2
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 0))))
(once-runner runner-instance
:end
(lambda ()
(funcall r-done (eql x 1))))
(run-runner runner-instance))))
(r-test
:test-after-all-recursive
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(suite-3 (create-suite runner-instance
:suite-2))
(x 0))
(add-child suite-root suite-1)
(create-after-all suite-1
:after-all-suite-1
(lambda (hook-done)
(incf x 1)
(funcall hook-done))
:async-p t)
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 0))))
(add-child suite-1 suite-2)
(create-after-all suite-2
:after-all-suite-2
(lambda ()
(incf x 1)))
(add-child suite-2
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 0))))
(add-child suite-root
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 1))))
(add-child suite-root suite-3)
(create-after-all suite-3
:after-all-suite-3
(lambda ()
(incf x 1)))
(add-child suite-3
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 1))))
(once-runner runner-instance
:end
(lambda ()
(funcall r-done (eql x 3))))
(run-runner runner-instance))))
| 5,039 | Common Lisp | .lisp | 140 | 19.128571 | 51 | 0.400409 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 5079d6b55c3a09302cea7ece94ce43ef9cb8c62a46ca63b881f623ff2d637c03 | 11,908 | [
-1
] |
11,909 | skip-test.lisp | noloop_cacau/t/functional/skip-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-skip-test
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(test-2 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil))
:skip-p t)))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 1 failing)))))
(run-runner runner-instance))))
(r-test
:test-skip-test-with-two-skip-tests
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(test-2 nil)
(test-3 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(t-p nil))
:skip-p t)))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(t-p nil))
:skip-p nil)))
(setf test-3
(add-child suite-1
(create-test runner-instance
:test-3
(lambda ()
(t-p nil))
:skip-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 1 failing)))))
(run-runner runner-instance))))
(r-test
:test-skip-test-recursive-with-three-skip-tests
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(t-p nil))
:skip-p t)))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(t-p nil)))))
(add-child suite-1 suite-2)
(setf test-4
(add-child suite-2
(create-test runner-instance
:test-4
(lambda ()
(t-p nil))
:skip-p t)))
(setf test-5
(add-child suite-2
(create-test runner-instance
:test-5
(lambda ()
(t-p nil)))))
(setf test-3
(add-child suite-1
(create-test runner-instance
:test-3
(lambda ()
(t-p nil))
:skip-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 2 failing)))))
(run-runner runner-instance))))
(r-test
:test-skip-test-recursive-with-two-suites-in-suite-root
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(suite-3 (create-suite runner-instance
:suite-3))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil)
(test-6 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(t-p nil))
:skip-p t)))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(t-p nil)))))
(add-child suite-1 suite-2)
(setf test-4
(add-child suite-2
(create-test runner-instance
:test-4
(lambda ()
(t-p nil))
:skip-p t)))
(setf test-5
(add-child suite-2
(create-test runner-instance
:test-5
(lambda ()
(t-p nil)))))
(setf test-3
(add-child suite-1
(create-test runner-instance
:test-3
(lambda ()
(t-p nil))
:skip-p t)))
(add-child suite-root suite-3)
(setf test-6
(add-child suite-3
(create-test runner-instance
:test-6
(lambda ()
(t-p nil))
:skip-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 2 failing)))))
(run-runner runner-instance))))
(r-test
:test-skip-suite
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:skip-p t))
(test-1 nil)
(test-2 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 0 failing)))))
(run-runner runner-instance))))
(r-test
:test-skip-suite-with-two-suites-in-suite-root
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:skip-p t))
(suite-2 (create-suite runner-instance
:suite-2))
(test-1 nil)
(test-2 nil)
(test-3 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(add-child suite-root suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 1 failing)))))
(run-runner runner-instance))))
(r-test
:test-skip-suite-recursive
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:skip-p t))
(suite-2 (create-suite runner-instance
:suite-2))
(suite-3 (create-suite runner-instance
:suite-3))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil)))))
(setf test-4
(add-child suite-1
(create-test runner-instance
:test-4
(lambda () (t-p nil)))))
(add-child suite-root suite-3)
(setf test-5
(add-child suite-3
(create-test runner-instance
:test-5
(lambda () (t-p nil)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 1 failing)))))
(run-runner runner-instance))))
(r-test
:test-skip-suite-recursive-with-one-skip-test
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(suite-3 (create-suite runner-instance
:suite-3))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil)))))
(setf test-4
(add-child suite-1
(create-test runner-instance
:test-4
(lambda () (t-p nil))
:skip-p t)))
(add-child suite-root suite-3)
(setf test-5
(add-child suite-3
(create-test runner-instance
:test-5
(lambda () (t-p nil)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 4 failing)))))
(run-runner runner-instance))))
(r-test
:test-skip-suite-recursive-with-two-skip-test
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(suite-3 (create-suite runner-instance
:suite-3))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil))
:skip-p t)))
(setf test-4
(add-child suite-1
(create-test runner-instance
:test-4
(lambda () (t-p nil)))))
(add-child suite-root suite-3)
(setf test-5
(add-child suite-3
(create-test runner-instance
:test-5
(lambda () (t-p nil))
:skip-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 3 failing)))))
(run-runner runner-instance))))
(r-test
:test-skip-suite-recursive-with-two-skip-suite
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:skip-p t))
(suite-2 (create-suite runner-instance
:suite-2))
(suite-3 (create-suite runner-instance
:suite-3))
(suite-4 (create-suite runner-instance
:suite-4
:skip-p t))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil)
(test-6 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil)))))
(setf test-4
(add-child suite-1
(create-test runner-instance
:test-4
(lambda () (t-p nil)))))
(add-child suite-root suite-3)
(setf test-5
(add-child suite-3
(create-test runner-instance
:test-5
(lambda () (t-p nil)))))
(add-child suite-3 suite-4)
(setf test-6
(add-child suite-4
(create-test runner-instance
:test-6
(lambda () (t-p nil)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 1 failing)))))
(run-runner runner-instance))))
(r-test
:test-skip-suite-recursive-with-two-skip-suite-and-three-skip-test
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2
:skip-p t))
(suite-3 (create-suite runner-instance
:suite-3))
(suite-4 (create-suite runner-instance
:suite-4
:skip-p t))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil)
(test-6 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil))
:skip-p t)))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil))
:skip-p t)))
(setf test-4
(add-child suite-1
(create-test runner-instance
:test-4
(lambda () (t-p nil)))))
(add-child suite-root suite-3)
(setf test-5
(add-child suite-3
(create-test runner-instance
:test-5
(lambda () (t-p nil)))))
(add-child suite-3 suite-4)
(setf test-6
(add-child suite-4
(create-test runner-instance
:test-6
(lambda () (t-p nil))
:skip-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 3 failing)))))
(run-runner runner-instance))))
| 20,883 | Common Lisp | .lisp | 540 | 19.583333 | 73 | 0.379273 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | a8ddbd7c168eadf45d77ad48f2d05dc9816f4840912b80f5f2ede97bce2dbfe2 | 11,909 | [
-1
] |
11,910 | before-each-test.lisp | noloop_cacau/t/functional/before-each-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-before-each
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(x 0))
(add-child suite-root suite-1)
(create-before-each suite-1
:before-each-suite-1
(lambda ()
(setf x 0)))
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(incf x 1)
(eql-p x 1))))
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(incf x 1)
(eql-p x 1))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 0 failing)))))
(run-runner runner-instance))))
(r-test
:test-async-before-each
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(x 0))
(add-child suite-root suite-1)
(create-before-each suite-1
:before-each-suite-1
(lambda (done-hook)
(setf x 0)
(funcall done-hook))
:async-p t)
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(incf x 1)
(eql-p x 1))))
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(incf x 1)
(eql-p x 1))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 0 failing)))))
(run-runner runner-instance))))
(r-test
:test-before-each-recursive
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(x 0))
(add-child suite-root suite-1)
(create-before-each suite-1
:before-each-suite-1
(lambda ()
(setf x 0)))
(add-child suite-1
(create-test runner-instance
:suite-1-test-1
(lambda ()
(incf x 1)
(eql-p x 1))))
(add-child suite-1
(create-test runner-instance
:suite-1-test-2
(lambda ()
(incf x 1)
(eql-p x 1))))
(add-child suite-1 suite-2)
(create-before-each suite-2
:before-each-suite-2
(lambda ()
(incf x 1)))
(add-child suite-2
(create-test runner-instance
:suite-2-test-1
(lambda ()
(incf x 1)
(eql-p x 2))))
(add-child suite-2
(create-test runner-instance
:suite-2-test-2
(lambda ()
(incf x 1)
(eql-p x 2))))
(add-child suite-1
(create-test runner-instance
:suite-1-test-3
(lambda ()
(incf x 1)
(eql-p x 1))))
(add-child suite-root
(create-test runner-instance
:suite-root-test-1
(lambda ()
(incf x 1)
(eql-p x 2))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 0 failing)))))
(run-runner runner-instance))))
| 4,991 | Common Lisp | .lisp | 130 | 19.007692 | 73 | 0.370393 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 2dcbf36bdbbf61af10c310fa7ec68261ceb355676fdba6453635684302b01bd8 | 11,910 | [
-1
] |
11,911 | skip-only-rule-test.lisp | noloop_cacau/t/functional/skip-only-rule-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-skip-only-rule-skip-test-precedes-only-test
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(test-2 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil))
:only-p t)))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil))
:skip-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance)))
(only-tests
(gethash :only-tests (result runner-instance)))
(skip-tests
(gethash :skip-tests (result runner-instance))))
(funcall r-done (and (eql 1 only-tests)
(eql 1 skip-tests)
(eql 1 failing))))))
(run-runner runner-instance))))
(r-test
:test-skip-only-rule-skip-test-precedes-only-test-recursive
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(test-1 nil)
(test-2 nil)
(test-3 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil))
:only-p t)))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil))
:skip-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance)))
(only-tests
(gethash :only-tests (result runner-instance)))
(skip-tests
(gethash :skip-tests (result runner-instance))))
(funcall r-done (and (eql 1 only-tests)
(eql 1 skip-tests)
(eql 1 failing))))))
(run-runner runner-instance))))
(r-test
:test-skip-only-rule-skip-test-precedes-only-suite
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:only-p t))
(suite-2 (create-suite runner-instance
:suite-2))
(test-1 nil)
(test-2 nil)
(test-3 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil))
:skip-p t)))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil))
:skip-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance)))
(only-suites
(gethash :only-suites (result runner-instance)))
(skip-tests
(gethash :skip-tests (result runner-instance))))
(funcall r-done (and (eql 1 only-suites)
(eql 2 skip-tests)
(eql 1 failing))))))
(run-runner runner-instance))))
(r-test
:test-skip-only-rule-skip-only-suite-not-precedes-skip-suite
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:only-p t))
(suite-2 (create-suite runner-instance
:suite-2
:skip-p t))
(test-1 nil)
(test-2 nil)
(test-3 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil))
:skip-p t)))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance)))
(only-suites
(gethash :only-suites (result runner-instance)))
(skip-tests
(gethash :skip-tests (result runner-instance)))
(skip-suites
(gethash :skip-suites (result runner-instance))))
(funcall r-done (and (eql 1 only-suites)
(eql 1 skip-tests)
(eql 1 skip-suites)
(eql 1 failing))))))
(run-runner runner-instance))))
(r-test
:test-skip-only-rule-skip-suite-precedes-only-test
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:skip-p t))
(suite-2 (create-suite runner-instance
:suite-2))
(test-1 nil)
(test-2 nil)
(test-3 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil))
:only-p t)))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance)))
(skip-suites
(gethash :skip-suites (result runner-instance))))
(funcall r-done (and (eql 1 skip-suites)
(eql 0 failing))))))
(run-runner runner-instance))))
(r-test
:test-skip-only-rule-skip-suite-precedes-only-suite
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:skip-p t))
(suite-2 (create-suite runner-instance
:suite-2
:only-p t))
(test-1 nil)
(test-2 nil)
(test-3 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance)))
(skip-suites
(gethash :skip-suites (result runner-instance))))
(funcall r-done (and (eql 1 skip-suites)
(eql 0 failing))))))
(run-runner runner-instance))))
(r-test
:test-skip-only-rule-skip-suite-precedes-only-test-and-only-suite
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:only-p t))
(suite-2 (create-suite runner-instance
:suite-2
:skip-p t))
(test-1 nil)
(test-2 nil)
(test-3 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda () (t-p nil)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p nil)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda () (t-p nil))
:only-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance)))
(only-suites
(gethash :only-suites (result runner-instance)))
(skip-suites
(gethash :skip-suites (result runner-instance))))
(funcall r-done (and (eql 1 only-suites)
(eql 1 skip-suites)
(eql 2 failing))))))
(run-runner runner-instance))))
| 12,589 | Common Lisp | .lisp | 300 | 21.753333 | 77 | 0.391255 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 315179ffb7f5aa3e2e0fbc01154bf60655dced77d7c6aeb8e4b36461b89d1765 | 11,911 | [
-1
] |
11,912 | after-each-test.lisp | noloop_cacau/t/functional/after-each-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-after-each
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(x 0))
(add-child suite-root suite-1)
(create-after-each suite-1
:after-each-suite-1
(lambda ()
(setf x 0)))
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(incf x 1)
(eql-p x 1))))
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(incf x 1)
(eql-p x 1))))
(once-runner runner-instance
:end
(lambda ()
(funcall r-done (eql x 0))))
(run-runner runner-instance))))
(r-test
:test-async-after-each
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(x 0))
(add-child suite-root suite-1)
(create-after-each suite-1
:after-each-suite-1
(lambda (done-hook)
(setf x 0)
(funcall done-hook))
:async-p t)
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(incf x 1)
(eql-p x 1))))
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(incf x 1)
(eql-p x 1))))
(once-runner runner-instance
:end
(lambda ()
(funcall r-done (eql x 0))))
(run-runner runner-instance))))
(r-test
:test-after-each-order
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(x 0))
(add-child suite-root suite-1)
(create-after-each suite-1
:after-each-suite-1
(lambda (hook-done)
(setf x 1)
(funcall hook-done))
:async-p t)
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 0))))
(add-child suite-1 suite-2)
(create-after-each suite-2
:after-each-suite-2
(lambda ()
(setf x 2)))
(add-child suite-2
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 0))))
(once-runner runner-instance
:end
(lambda ()
(funcall r-done (eql x 1))))
(run-runner runner-instance))))
(r-test
:test-after-each-recursive
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(x 0))
(add-child suite-root suite-1)
(create-after-each suite-1
:after-each-suite-1
(lambda (done-hook)
(incf x 1)
(funcall done-hook))
:async-p t)
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(incf x 1)
(eql-p x 1))))
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(incf x 1)
(eql-p x 3))))
(add-child suite-1 suite-2)
(create-after-each suite-2
:after-each-suite-2
(lambda ()
(setf x 0)))
(add-child suite-2
(create-test runner-instance
:test-1
(lambda (done-test)
(incf x 1)
(funcall done-test
(lambda ()
(eql-p x 5))))
:async-p t))
(add-child suite-2
(create-test runner-instance
:test-2
(lambda ()
(incf x 1))))
(add-child suite-1
(create-test runner-instance
:test-3
(lambda ()
(incf x 1)
(eql-p x 2))))
(once-runner runner-instance
:end
(lambda ()
(funcall r-done (eql x 3))))
(run-runner runner-instance))))
| 5,835 | Common Lisp | .lisp | 159 | 18.283019 | 56 | 0.373126 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | caf6b130552ee9c49b41b61cac84fc68f85f6090898154338c4a62c67d7dda01 | 11,912 | [
-1
] |
11,913 | runner-test.lisp | noloop_cacau/t/functional/runner-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-runner-create-test-sync
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance)))
(add-child suite-root
(create-test runner-instance
:test-1
(lambda ()
(= 1 1))))
(once-runner runner-instance
:end
(lambda ()
(funcall r-done)))
(run-runner runner-instance))))
(r-test
:test-runner-create-test-async
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance)))
(add-child suite-root
(create-test runner-instance
:test-1
(lambda (done)
(funcall done (lambda ()
(funcall r-done))))
:async-p t))
(once-runner runner-instance
:end
(lambda () ()))
(run-runner runner-instance))))
(r-test
:test-runner-create-suite
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1)))
(add-child suite-root suite-1)
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(= 1 1))))
(add-child suite-1
(create-test runner-instance
:test-2
(lambda (done)
(funcall done))
:async-p t))
(add-child suite-1
(create-test runner-instance
:test-3
(lambda ()
(= 1 1))))
(once-runner runner-instance
:end
(lambda ()
(funcall r-done)))
(run-runner runner-instance))))
(r-test
:test-runner-create-suite-recursive
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2)))
(add-child suite-root suite-1)
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(= 1 1))))
(add-child suite-1
(create-test runner-instance
:test-2
(lambda (done)
(funcall done))
:async-p t))
(add-child suite-1 suite-2)
(add-child suite-2
(create-test runner-instance
:test-1
(lambda ()
(= 1 1))
:async-p nil))
(add-child suite-2
(create-test runner-instance
:test-2
(lambda (done)
(funcall done))
:async-p t))
(once-runner runner-instance
:end
(lambda ()
(funcall r-done)))
(run-runner runner-instance))))
| 3,565 | Common Lisp | .lisp | 100 | 19.32 | 66 | 0.414162 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 0339ac6a75be766b3c64b8a9f9e5ca9a1388466499114c1c87ea89addb571ed7 | 11,913 | [
-1
] |
11,914 | suite-test.lisp | noloop_cacau/t/functional/suite-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-suite-with-suite-root-void
(lambda (r-done)
(let* ((runner-instance (make-runner)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 0 failing)))))
(run-runner runner-instance))))
(r-test
:test-suite-with-suite-root-with-suite-void
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1)))
(add-child suite-root suite-1)
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 0 failing)))))
(run-runner runner-instance))))
| 1,014 | Common Lisp | .lisp | 27 | 25.333333 | 73 | 0.517276 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 2a43f69667b86e182365e6ea566ecb58e91b45ee704434cef0230e373af484e8 | 11,914 | [
-1
] |
11,915 | test-test.lisp | noloop_cacau/t/functional/test-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-failing-async-test-done-whitout-arg
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(test-2 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda (done)
(funcall done (lambda () (t-p nil))))
:async-p t)))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda () (t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((passing
(gethash :passing (result runner-instance))))
(funcall r-done (eql 1 passing)))))
(run-runner runner-instance))))
(r-test
:test-failing-async-test-done-whit-arg-function
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(test-2 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(t-p t)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda (done)
(funcall done (lambda () (t-p nil))))
:async-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((passing
(gethash :passing (result runner-instance))))
(funcall r-done (eql 1 passing)))))
(run-runner runner-instance))))
(r-test
:test-failing-async-test-done-whit-arg-error
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(test-2 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(t-p t)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda (done)
(handler-case (t-p nil)
(error (c)
(funcall done c))))
:async-p t)))
(once-runner runner-instance
:end
(lambda ()
(let ((passing
(gethash :passing (result runner-instance))))
(funcall r-done (eql 1 passing)))))
(run-runner runner-instance))))
| 3,568 | Common Lisp | .lisp | 92 | 21.097826 | 74 | 0.40985 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 434507ff1372deab05ed25ad38ac76e5b60c9661e15ec330591aaa087e284ca2 | 11,915 | [
-1
] |
11,916 | timeout-test.lisp | noloop_cacau/t/functional/timeout-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-timeout-test
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t))
:timeout 0)))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 1 failing)))))
(run-runner runner-instance))))
(r-test
:test-timeout-suite
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:timeout 0))
(test-1 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 1 failing)))))
(run-runner runner-instance))))
(r-test
:test-timeout-suite-with-three-tests
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:timeout 0))
(test-1 nil)
(test-2 nil)
(test-3 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(setf test-3
(add-child suite-1
(create-test runner-instance
:test-3
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 3 failing)))))
(run-runner runner-instance))))
(r-test
:test-timeout-suite-recursive-with-five-tests
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:timeout 0))
(suite-2 (create-suite runner-instance
:suite-2))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(setf test-4
(add-child suite-2
(create-test runner-instance
:test-4
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(setf test-5
(add-child suite-1
(create-test runner-instance
:test-5
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 5 failing)))))
(run-runner runner-instance))))
(r-test
:test-timeout-suite-recursive-with-five-tests-one-test-reconfigured
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:timeout 0))
(suite-2 (create-suite runner-instance
:suite-2))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(setf test-4
(add-child suite-2
(create-test runner-instance
:test-4
(lambda ()
(loop for i upto 10 collect i)
(t-p t))
:timeout 50000)))
(setf test-5
(add-child suite-1
(create-test runner-instance
:test-5
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 4 failing)))))
(run-runner runner-instance))))
(r-test
:test-timeout-suite-recursive-with-five-tests-suite-2-reconfigured
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:timeout 0))
(suite-2 (create-suite runner-instance
:suite-2
:timeout 50000))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(setf test-4
(add-child suite-2
(create-test runner-instance
:test-4
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(setf test-5
(add-child suite-1
(create-test runner-instance
:test-5
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 3 failing)))))
(run-runner runner-instance))))
(r-test
:test-timeout-suite-recursive-with-five-tests-suite-2-reconfigured-with-one-test-reconfigured
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1
:timeout 0))
(suite-2 (create-suite runner-instance
:suite-2
:timeout 50000))
(test-1 nil)
(test-2 nil)
(test-3 nil)
(test-4 nil)
(test-5 nil))
(add-child suite-root suite-1)
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(setf test-2
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(add-child suite-1 suite-2)
(setf test-3
(add-child suite-2
(create-test runner-instance
:test-3
(lambda ()
(loop for i upto 10 collect i)
(t-p t))
:timeout 0)))
(setf test-4
(add-child suite-2
(create-test runner-instance
:test-4
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(setf test-5
(add-child suite-1
(create-test runner-instance
:test-5
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 4 failing)))))
(run-runner runner-instance))))
(r-test
:test-timeout-before-all
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(before-all-suite-1 nil))
(add-child suite-root suite-1)
(setf before-all-suite-1
(create-before-all suite-1
:before-all-suite-1
(lambda ()
(loop for i upto 10 collect i))
:timeout 0))
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-before-all-with-tests-in-suite-root
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(test-1 nil)
(before-all-suite-root nil))
(setf before-all-suite-root
(create-before-all suite-root
:before-all-suite-root
(lambda ()
(loop for i upto 10 collect i))
:timeout 0))
(setf test-1
(add-child suite-root
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-async-before-all
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(before-all-suite-1 nil))
(add-child suite-root suite-1)
(setf before-all-suite-1
(create-before-all suite-1
:before-all-suite-1
(lambda (done-hook)
(loop for i upto 10 collect i)
(funcall done-hook))
:async-p t
:timeout 0))
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-before-all-recursive
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(test-1 nil)
(test-2 nil)
(before-all-suite-1 nil)
(before-all-suite-2 nil))
(add-child suite-root suite-1)
(setf before-all-suite-1
(create-before-all suite-1
:before-all-suite-1
(lambda ()
(loop for i upto 10 collect i))
:timeout 50000))
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(add-child suite-1 suite-2)
(setf before-all-suite-2
(create-before-all suite-2
:before-all-suite-2
(lambda (done-hook)
(loop for i upto 10 collect i)
(funcall done-hook))
:async-p t
:timeout 0))
(setf test-2
(add-child suite-2
(create-test runner-instance
:test-2
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-after-all
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(after-all-suite-1 nil))
(add-child suite-root suite-1)
(setf after-all-suite-1
(create-after-all suite-1
:after-all-suite-1
(lambda ()
(loop for i upto 10 collect i))
:timeout 0))
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-after-all-with-tests-in-suite-root
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(test-1 nil)
(after-all-suite-root nil))
(setf after-all-suite-root
(create-after-all suite-root
:after-all-suite-root
(lambda ()
(loop for i upto 10 collect i))
:timeout 0))
(setf test-1
(add-child suite-root
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-async-after-all
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(after-all-suite-1 nil))
(add-child suite-root suite-1)
(setf after-all-suite-1
(create-after-all suite-1
:after-all-suite-1
(lambda (done-hook)
(loop for i upto 10 collect i)
(funcall done-hook))
:async-p t
:timeout 0))
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-after-all-recursive
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(test-1 nil)
(test-2 nil)
(after-all-suite-1 nil)
(after-all-suite-2 nil))
(add-child suite-root suite-1)
(setf after-all-suite-1
(create-after-all suite-1
:after-all-suite-1
(lambda ()
(loop for i upto 10 collect i))
:timeout 50000))
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(add-child suite-1 suite-2)
(setf after-all-suite-2
(create-after-all suite-2
:after-all-suite-2
(lambda (done-hook)
(loop for i upto 10 collect i)
(funcall done-hook))
:async-p t
:timeout 0))
(setf test-2
(add-child suite-2
(create-test runner-instance
:test-2
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-before-each
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(before-each-suite-1 nil))
(add-child suite-root suite-1)
(setf before-each-suite-1
(create-before-each suite-1
:before-each-suite-1
(lambda ()
(loop for i upto 10 collect i))
:timeout 0))
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-before-each-with-tests-in-suite-root
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(test-1 nil)
(before-each-suite-root nil))
(setf before-each-suite-root
(create-before-each suite-root
:before-each-suite-root
(lambda ()
(loop for i upto 10 collect i))
:timeout 0))
(setf test-1
(add-child suite-root
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-async-before-each
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(before-each-suite-1 nil))
(add-child suite-root suite-1)
(setf before-each-suite-1
(create-before-each suite-1
:before-each-suite-1
(lambda (done-hook)
(loop for i upto 10 collect i)
(funcall done-hook))
:async-p t
:timeout 0))
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-before-each-recursive
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(test-1 nil)
(test-2 nil)
(before-each-suite-1 nil)
(before-each-suite-2 nil))
(add-child suite-root suite-1)
(setf before-each-suite-1
(create-before-each suite-1
:before-each-suite-1
(lambda ()
(loop for i upto 10 collect i))
:timeout 50000))
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(add-child suite-1 suite-2)
(setf before-each-suite-2
(create-before-each suite-2
:before-each-suite-2
(lambda (done-hook)
(loop for i upto 10 collect i)
(funcall done-hook))
:async-p t
:timeout 0))
(setf test-2
(add-child suite-2
(create-test runner-instance
:test-2
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-after-each
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(after-each-suite-1 nil))
(add-child suite-root suite-1)
(setf after-each-suite-1
(create-after-each suite-1
:after-each-suite-1
(lambda ()
(loop for i upto 10 collect i))
:timeout 0))
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-after-each-with-tests-in-suite-root
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(test-1 nil)
(after-each-suite-root nil))
(setf after-each-suite-root
(create-after-each suite-root
:after-each-suite-1
(lambda ()
(loop for i upto 10 collect i))
:timeout 0))
(setf test-1
(add-child suite-root
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-async-after-each
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(test-1 nil)
(after-each-suite-1 nil))
(add-child suite-root suite-1)
(setf after-each-suite-1
(create-after-each suite-1
:after-each-suite-1
(lambda (done-hook)
(loop for i upto 10 collect i)
(funcall done-hook))
:async-p t
:timeout 0))
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
(r-test
:test-timeout-after-each-recursive
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(test-1 nil)
(test-2 nil)
(after-each-suite-1 nil)
(after-each-suite-2 nil))
(add-child suite-root suite-1)
(setf after-each-suite-1
(create-after-each suite-1
:after-each-suite-1
(lambda ()
(loop for i upto 10 collect i))
:timeout 0))
(setf test-1
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(add-child suite-1 suite-2)
(setf after-each-suite-2
(create-after-each suite-2
:after-each-suite-2
(lambda (done-hook)
(loop for i upto 10 collect i)
(funcall done-hook))
:async-p t
:timeout 50000))
(setf test-2
(add-child suite-2
(create-test runner-instance
:test-2
(lambda ()
(loop for i upto 10 collect i)
(t-p t)))))
(once-runner runner-instance
:end
(lambda ()
(let ((errors
(gethash :errors (result runner-instance))))
(funcall r-done (> (length errors) 0)))))
(run-runner runner-instance))))
| 36,000 | Common Lisp | .lisp | 885 | 20.857627 | 95 | 0.388263 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 198ca0a9d04e576d9052282801d4a8b9c448e0510499dd09897424f16a80654d | 11,916 | [
-1
] |
11,917 | before-all-test.lisp | noloop_cacau/t/functional/before-all-test.lisp | (in-package #:noloop.cacau-test)
(r-test
:test-before-all
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(x 0))
(add-child suite-root suite-1)
(create-before-all suite-1
:before-all-suite-1
(lambda ()
(setf x 1)))
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 1))))
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(eql-p x 1))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 0 failing)))))
(run-runner runner-instance))))
(r-test
:test-async-before-all
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(x 0))
(add-child suite-root suite-1)
(create-before-all suite-1
:before-all-suite-1
(lambda (done-hook)
(funcall done-hook (lambda ()
(setf x 1))))
:async-p t)
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 1))))
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(eql-p x 1))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 0 failing)))))
(run-runner runner-instance))))
(r-test
:test-before-all-recursive
(lambda (r-done)
(let* ((runner-instance (make-runner))
(suite-root (suite-root runner-instance))
(suite-1 (create-suite runner-instance
:suite-1))
(suite-2 (create-suite runner-instance
:suite-2))
(x 0))
(add-child suite-root suite-1)
(create-before-all suite-1
:before-all-suite-1
(lambda (done-hook)
(setf x 1)
(funcall done-hook))
:async-p t)
(add-child suite-1
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 1))))
(add-child suite-1
(create-test runner-instance
:test-2
(lambda ()
(eql-p x 1))))
(add-child suite-1 suite-2)
(create-before-all suite-2
:before-all-suite-2
(lambda (done-hook)
(incf x)
(funcall done-hook))
:async-p t)
(add-child suite-2
(create-test runner-instance
:test-1
(lambda ()
(eql-p x 2))))
(add-child suite-2
(create-test runner-instance
:test-2
(lambda ()
(eql-p x 2))))
(once-runner runner-instance
:end
(lambda ()
(let ((failing
(gethash :failing (result runner-instance))))
(funcall r-done (eql 0 failing)))))
(run-runner runner-instance))))
| 4,275 | Common Lisp | .lisp | 114 | 19.631579 | 73 | 0.394756 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 45c5e57afb45ea5c8836d03e7eaa566f2018b52627c71cbe02819d3f73f4d987 | 11,917 | [
-1
] |
11,918 | cacau-test.asd | noloop_cacau/cacau-test.asd | (defsystem :cacau-test
:author "noloop <[email protected]>"
:maintainer "noloop <[email protected]>"
:license "GPLv3"
:description "cacau Test."
:depends-on (:cacau :assert-p)
:defsystem-depends-on (:cacau-asdf)
:serial t
:components
((:module "t"
:components
((:file "recursive-runner")
(:module "functional"
:components
((:cacau-file "runner-test")
(:cacau-file "suite-test")
(:cacau-file "test-test")
(:cacau-file "before-all-test")
(:cacau-file "after-all-test")
(:cacau-file "before-each-test")
(:cacau-file "after-each-test")
(:cacau-file "timeout-test")
(:cacau-file "only-test")
(:cacau-file "skip-test")
(:cacau-file "skip-only-rule-test")))
(:module "interface"
:components
((:cacau-file "cl-test")
(:cacau-file "bdd-test")
(:cacau-file "tdd-test")
(:cacau-file "no-spaghetti-test")
(:cacau-file "mix-test")))
(:module "reporter"
:components
((:cacau-file "min-test")
(:cacau-file "list-test")
(:cacau-file "full-test"))))))
:perform (test-op (op c) (symbol-call :cacau-test '#:r-run)))
| 1,191 | Common Lisp | .asd | 38 | 25.131579 | 63 | 0.588184 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 8335b0d06e916b30793a32e7f33d424a38fbd4c0c1e5a119d1fa50829849e347 | 11,918 | [
-1
] |
11,919 | cacau.asd | noloop_cacau/cacau.asd | ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(defsystem :cacau
:author "noloop <[email protected]>"
:maintainer "noloop <[email protected]>"
:license "GPLv3"
:version "1.0.0"
:homepage "https://github.com/noloop/cacau"
:bug-tracker "https://github.com/noloop/cacau/issues"
:source-control (:git "[email protected]:noloop/cacau.git")
:description "Test Runner in Common Lisp."
:depends-on (:eventbus :assertion-error)
:serial t
:components ((:module "src"
:components
((:file "package")
(:file "utils")
(:module "kernel"
:components
((:file "timer")
(:file "runnable")
(:file "list-iterator")
(:file "test")
(:file "hook")
(:file "suite")
(:file "runner-listeners")
(:file "runner")))
(:module "reporters"
:components
((:file "base")
(:file "min")
(:file "list")
(:file "full")))
(:file "cacau")
(:module "interfaces"
:components
((:file "common")
(:file "cl")
(:file "bdd")
(:file "tdd")
(:file "no-spaghetti"))))))
:in-order-to ((test-op (test-op :cacau-test))))
| 1,488 | Common Lisp | .asd | 41 | 22.707317 | 59 | 0.441909 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 9de19dee13d7b14d9cca0403c3af29262f2756bc1dbd8eabac9bd9f6a661d80b | 11,919 | [
-1
] |
11,920 | cacau-examples-asdf-integration-test.asd | noloop_cacau/examples/asdf-intregration/cacau-examples-asdf-integration-test.asd | ;; Use cacau-file to load the file awalys that call test-system.
;; Use cacau-file-nd ("nd" of "never done") to load and compile the file awalys that call test-system.
(defsystem :cacau-examples-asdf-integration-test
:depends-on (:cacau-examples-asdf-integration
:cacau
:assert-p)
:defsystem-depends-on (:cacau-asdf)
:components ((:cacau-file "cacau-examples-asdf-integration-test"))
:perform (test-op (op c) (symbol-call :cacau '#:run)))
| 478 | Common Lisp | .asd | 9 | 47.777778 | 102 | 0.694444 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | c77cb40d6abd415641747b1305a5306c8c4059ee65d43d766cdfc154e1cf396a | 11,920 | [
-1
] |
11,921 | cacau-examples-asdf-integration.asd | noloop_cacau/examples/asdf-intregration/cacau-examples-asdf-integration.asd | ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(defsystem :cacau-examples-asdf-integration
:components ((:file "cacau-examples-asdf-integration"))
:in-order-to ((test-op (test-op :cacau-examples-asdf-integration-test))))
| 239 | Common Lisp | .asd | 4 | 57.5 | 75 | 0.709402 | noloop/cacau | 8 | 0 | 1 | GPL-3.0 | 9/19/2024, 11:26:57 AM (Europe/Amsterdam) | 6d58c99529d4b7a900dc857985c9c1d8d3000243af09c1bf1676b3a81e108298 | 11,921 | [
-1
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.