-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrill.lisp
97 lines (78 loc) · 1.98 KB
/
drill.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
(in-package :gcode)
(defparameter *pcb-tool*
(make-instance 'tool
:diameter 1
:number 7
:feed-xy 600
:feed-z 240
:depth 2.2))
(defparameter *engrave-tool*
(make-instance 'tool
:diameter 1
:number 9
:feed-xy 600
:feed-z 240
:depth 1.5))
(defun pcb (file outfile)
(program-to-file
(with-program ("pcb")
(with-tool (*pcb-tool*)
(tool-up)
(home)
(load-file
file)))
outfile :order '("drills" "mill" "bridge-cut")))
#+nil
(defun test-file ()
(with-program ("file-tool")
(with-tool (*pcb-tool*)
(tool-up)
(home)
(load-file
"/Users/manuel/siff-svn/ruinwesen/eagle/midicommand/minicommand-ioboard.lisp"))))
(defvar *drills*)
(defvar *eagle-drills-p* t)
(defvar *eagle-vias-p* nil)
(defun add-drill (&key x y diameter type)
(when *eagle-drills-p*
(push (list x y diameter type) *drills*)))
(defun add-via (&key x y diameter)
(when *eagle-vias-p*
(push (list x y diameter) *drills*)))
(defun square (x)
(* x x))
(defun distance (x1 y1 x2 y2)
(sqrt (+
(square (- x1 x2))
(square (- y1 y2)))))
(defun nearest-drill (x y drills)
(let ((distances
(sort
(mapcar #'(lambda (drill)
(cons (distance x y (first drill) (second drill))
(copy-tree drill)))
drills)
#'< :key #'first)))
(cdr (first distances))))
(defun drill-direction (x1 y1 x2 y2)
(let ((direction nil))
(cond ((> x2 x1) (push :right direction))
((< x2 x1) (push :left direction)))
(cond ((> y2 y1) (push :up direction))
((< y2 y1) (push :down direction)))
direction))
(defun sort-drills ()
*drills*)
(defmacro with-drills (() &rest body)
`(let ((*drills*))
,@body
(let ((*drills* (sort-drills)))
(with-named-pass ("drills")
(dolist (drill *drills*)
(drill :x (first drill)
:y (second drill) ;; XXXX invert!!!
:diameter (third drill)))))))
(defun optimize-test-file ()
(let ((program (test-file)))
(optimize-program-pass program "drills")
program))