stuff/(Cad.py) Plotting with Z axis movement.py

Fri, 03 Jun 2016 10:05:45 +0200

author
mbayer
date
Fri, 03 Jun 2016 10:05:45 +0200
changeset 17
d93a721621bd
parent 0
ee535cb8fb1a
permissions
-rw-r--r--

remove pyc files

0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1 #!/usr/bin/env python
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3 # cad.py
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
4 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
5 # Neil Gershenfeld
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
6 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
7 # (c) Massachusetts Institute of Technology 2007
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
8 # Permission granted for experimental and personal use;
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
9 # license for commercial sale available from MIT.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
10 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
11 #Altered by R Parsons (AKA: Capo) to output gcode with the '.gcode' extension as opposed to '.g'.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
12 #Also the default variables were changed to metric values
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
13 DATE = "7/12/010"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
14
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
15 from numpy import *
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
16 import scipy.signal.signaltools
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
17 from string import *
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
18 from Tkinter import *
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
19 from tkFileDialog import *
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
20 import Image, ImageTk, ImageDraw, ImageFont, ImageOps
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
21 import os, struct
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
22 #import time
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
23
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
24 class point:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
25 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
26 # an xyz point
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
27 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
28 def __init__(self,x,y,z=0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
29 self.x = x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
30 self.y = y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
31 self.z = z
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
32
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
33 class cad_variables:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
34 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
35 # cad variables
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
36 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
37 def __init__(self):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
38 self.xmin = 0 # minimum x value to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
39 self.xmax = 0 # maximum x value to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
40 self.ymin = 0 # minimum y value to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
41 self.ymax = 0 # maximum y value to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
42 self.zmin = 0 # minimum z value to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
43 self.zmax = 0 # maximum z value to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
44 self.zlist = [] # z values to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
45 self.nx = 0 # number of x points to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
46 self.ny = 0 # number of y points to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
47 self.nz = 1 # number of z points to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
48 self.rz = 0 # perspective view z rotation (degrees)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
49 self.rx = 0 # perspective view x rotation (degrees)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
50 self.units = 'in' # file units
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
51 self.function = '0' # cad function
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
52 self.toolpaths = [] # toolpaths
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
53 self.x = [] # x triangulation
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
54 self.y = [] # y triangulation
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
55 self.z = [] # z triangulation
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
56 self.labels = [] # display labels
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
57 self.image_r = array(0) # red array
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
58 self.image_g = array(0) # green array
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
59 self.image_b = array(0) # blue array
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
60 self.image_min = 0 # image min value
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
61 self.image_max = 0 # image max value
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
62 self.stop = 0 # stop rendering
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
63 self.nplot = 200 # plot window size
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
64 self.inches_per_unit = 1 # file units
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
65 self.views = 'xyzr'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
66 self.cam = '' # CAM export type
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
67 self.editor_width = 30 # editor width
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
68 self.editor_height = 10 # editor height
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
69 def view(self,arg):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
70 global canvas_xy,canvas_yz,canvas_xz,canvas_xyz
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
71 if (arg == 'xy'):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
72 view_frame2.grid_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
73 view_frame3.grid_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
74 canvas_xy.grid_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
75 self.views = 'xy'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
76 self.nplot = 2*int(string_window_size.get()) # plot window size
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
77 canvas_xy = Canvas(view_frame2, width=self.nplot, height=self.nplot)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
78 imxy = Image.new("RGBX",(self.nplot,self.nplot),'black')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
79 image_xy = ImageTk.PhotoImage(imxy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
80 canvas_xy.create_image(self.nplot/2,self.nplot/2,image=image_xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
81 canvas_xy.bind('<Motion>',msg_xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
82 canvas_xy.grid(row=0,column=0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
83 view_frame2.grid(row=2,column=0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
84 elif (arg == 'xyzr'):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
85 view_frame2.grid_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
86 view_frame3.grid_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
87 canvas_xy.grid_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
88 canvas_yz.grid_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
89 canvas_xz.grid_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
90 canvas_xyz.grid_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
91 self.views = 'xyzr'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
92 self.nplot = int(string_window_size.get()) # plot window size
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
93 canvas_xy = Canvas(view_frame3, width=self.nplot, height=self.nplot)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
94 canvas_yz = Canvas(view_frame3, width=self.nplot, height=self.nplot)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
95 canvas_xz = Canvas(view_frame3, width=self.nplot, height=self.nplot)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
96 canvas_xyz = Canvas(view_frame3, width=self.nplot, height=cad.nplot)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
97 imxy = Image.new("RGBX",(self.nplot,self.nplot),'black')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
98 image_xy = ImageTk.PhotoImage(imxy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
99 canvas_xy.create_image(self.nplot/2,self.nplot/2,image=image_xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
100 canvas_xy.bind('<Motion>',msg_xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
101 canvas_xy.grid(row=0,column=0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
102 imyz = Image.new("RGBX",(self.nplot,self.nplot),'black')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
103 image_yz = ImageTk.PhotoImage(imyz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
104 canvas_yz.create_image(self.nplot/2,self.nplot/2,image=image_yz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
105 canvas_yz.bind('<Motion>',msg_yz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
106 canvas_yz.grid(row=0,column=1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
107 imxz = Image.new("RGBX",(self.nplot,self.nplot),'black')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
108 image_xz = ImageTk.PhotoImage(imxz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
109 canvas_xz.create_image(self.nplot/2,self.nplot/2,image=image_xz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
110 canvas_xz.bind('<Motion>',msg_xz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
111 canvas_xz.grid(row=1,column=0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
112 imxyz = Image.new("RGBX",(self.nplot,self.nplot),'black')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
113 image_xyz = ImageTk.PhotoImage(imxyz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
114 canvas_xyz.create_image(self.nplot/2,self.nplot/2,image=image_xyz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
115 canvas_xyz.bind('<Motion>',msg_nomsg)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
116 canvas_xyz.grid(row=1,column=1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
117 view_frame3.grid(row=2,column=0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
118 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
119 print "view not supported"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
120 def nxplot(self):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
121 xwidth = self.xmax - self.xmin
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
122 ywidth = self.ymax - self.ymin
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
123 zwidth = self.zmax - self.zmin
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
124 if ((xwidth >= ywidth) & (xwidth >= zwidth)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
125 n = int(self.nplot*xwidth/float(xwidth))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
126 elif ((ywidth >= xwidth) & (ywidth >= zwidth)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
127 n = int(self.nplot*xwidth/float(ywidth))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
128 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
129 n = int(self.nplot*xwidth/float(zwidth))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
130 return n
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
131 def nyplot(self):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
132 xwidth = self.xmax - self.xmin
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
133 ywidth = self.ymax - self.ymin
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
134 zwidth = self.zmax - self.zmin
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
135 if ((xwidth >= ywidth) & (xwidth >= zwidth)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
136 n = int(self.nplot*ywidth/float(xwidth))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
137 elif ((ywidth >= xwidth) & (ywidth >= zwidth)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
138 n = int(self.nplot*ywidth/float(ywidth))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
139 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
140 n = int(self.nplot*ywidth/float(zwidth))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
141 return n
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
142 def nzplot(self):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
143 xwidth = self.xmax - self.xmin
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
144 ywidth = self.ymax - self.ymin
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
145 zwidth = self.zmax - self.zmin
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
146 if ((xwidth >= ywidth) & (xwidth >= zwidth)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
147 n = int(self.nplot*zwidth/float(xwidth))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
148 elif ((ywidth >= xwidth) & (ywidth >= zwidth)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
149 n = int(self.nplot*zwidth/float(ywidth))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
150 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
151 n = int(self.nplot*zwidth/float(zwidth))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
152 return n
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
153
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
154 cad = cad_variables()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
155
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
156 class cad_text:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
157 def __init__(self,x,y,z=0,text='',size=10,color='#ff0000',anchor=CENTER):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
158 self.x = x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
159 self.y = y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
160 self.z = z
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
161 self.text = text
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
162 self.size = size
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
163 self.color = color
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
164 self.anchor = anchor
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
165
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
166 class im_class:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
167 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
168 # for PIL images
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
169 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
170 def __init__(self):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
171 self.xy = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
172 self.xz = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
173 self.yz = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
174 self.xyz = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
175 self.intensity_xy = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
176 self.intensity_xz = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
177 self.intensity_yz = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
178 self.intensity_xyz = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
179
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
180 im = im_class()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
181
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
182 class images_class:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
183 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
184 # for PhotoImages
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
185 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
186 def __init__(self):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
187 self.xy = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
188 self.xz = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
189 self.yz = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
190 self.xyz = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
191
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
192 images = images_class()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
193
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
194 class CA_states:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
195 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
196 # CA state definition class
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
197 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
198 def __init__(self):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
199 self.empty = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
200 self.interior = 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
201 self.edge = (1 << 1) # 2
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
202 self.north = (1 << 2) # 4
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
203 self.west = (2 << 2) # 8
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
204 self.east = (3 << 2) # 12
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
205 self.south = (4 << 2) # 16
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
206 self.stop = (5 << 2) # 20
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
207 self.corner = (6 << 2) # 24
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
208
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
209 class rule_table:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
210 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
211 # CA rule table class
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
212 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
213 # 0 = empty
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
214 # 1 = interior
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
215 # 2 = edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
216 # edge+direction = start
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
217 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
218 def __init__(self):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
219 self.table = zeros(2**(9*2),uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
220 self.s = CA_states()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
221 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
222 # 1 0:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
223 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
224 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
225 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
226 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
227 self.add_rule(0,1,1,1,1,1,1,1,1,self.s.north)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
228 # 101
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
229 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
230 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
231 self.add_rule(1,0,1,1,1,1,1,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
232 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
233 # 2 0's:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
234 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
235 # 001
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
236 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
237 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
238 self.add_rule(0,0,1,1,1,1,1,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
239 # 100
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
240 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
241 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
242 self.add_rule(1,0,0,1,1,1,1,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
243 # 010
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
244 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
245 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
246 self.add_rule(0,1,0,1,1,1,1,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
247 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
248 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
249 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
250 self.add_rule(0,1,1,1,1,0,1,1,1,self.s.south)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
251 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
252 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
253 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
254 self.add_rule(1,1,0,0,1,1,1,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
255 # 101
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
256 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
257 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
258 self.add_rule(1,0,1,0,1,1,1,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
259 # 101
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
260 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
261 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
262 self.add_rule(1,0,1,1,1,0,1,1,1,self.s.south)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
263 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
264 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
265 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
266 self.add_rule(0,1,1,1,1,1,1,1,0,self.s.corner)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
267 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
268 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
269 # 101
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
270 self.add_rule(0,1,1,1,1,1,1,0,1,self.s.north)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
271 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
272 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
273 # 101
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
274 self.add_rule(1,1,0,1,1,1,1,0,1,self.s.west)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
275 # 101
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
276 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
277 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
278 self.add_rule(1,0,1,1,1,1,1,1,0,self.s.south)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
279 # 101
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
280 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
281 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
282 self.add_rule(1,0,1,1,1,1,0,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
283 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
284 # 3 0's:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
285 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
286 # 001
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
287 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
288 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
289 self.add_rule(0,0,1,0,1,1,1,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
290 # 010
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
291 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
292 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
293 self.add_rule(0,1,0,0,1,1,1,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
294 # 010
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
295 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
296 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
297 self.add_rule(0,1,0,1,1,0,1,1,1,self.s.south)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
298 # 010
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
299 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
300 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
301 self.add_rule(0,1,0,1,1,1,0,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
302 # 010
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
303 # 111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
304 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
305 self.add_rule(0,1,0,1,1,1,1,1,0,self.s.south)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
306 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
307 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
308 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
309 self.add_rule(1,1,0,0,1,1,0,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
310 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
311 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
312 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
313 self.add_rule(0,1,1,1,1,0,1,1,0,self.s.south)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
314 # 101
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
315 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
316 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
317 self.add_rule(1,0,1,0,1,1,0,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
318 # 101
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
319 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
320 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
321 self.add_rule(1,0,1,1,1,0,1,1,0,self.s.south)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
322 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
323 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
324 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
325 self.add_rule(0,1,1,0,1,1,0,1,1,self.s.north)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
326 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
327 # 4 0's:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
328 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
329 # 001
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
330 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
331 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
332 self.add_rule(0,0,1,0,1,1,0,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
333 # 100
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
334 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
335 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
336 self.add_rule(1,0,0,1,1,0,1,1,0,self.s.south)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
337 # 010
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
338 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
339 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
340 self.add_rule(0,1,0,0,1,1,0,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
341 # 010
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
342 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
343 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
344 self.add_rule(0,1,0,1,1,0,1,1,0,self.s.south)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
345 # 001
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
346 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
347 # 110
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
348 self.add_rule(0,0,1,1,1,0,1,1,0,self.s.south)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
349 # 100
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
350 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
351 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
352 self.add_rule(1,0,0,0,1,1,0,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
353 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
354 # 5 0's:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
355 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
356 # 000
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
357 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
358 # 011
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
359 self.add_rule(0,0,0,0,1,1,0,1,1,self.s.east)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
360 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
361 # edge states
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
362 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
363 # 200
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
364 # 211
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
365 # 211
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
366 self.add_rule(2,0,0,2,1,1,2,1,1,self.s.east+self.s.edge)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
367 # 201
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
368 # 211
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
369 # 211
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
370 self.add_rule(2,0,1,2,1,1,2,1,1,self.s.east+self.s.edge)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
371 # 210
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
372 # 211
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
373 # 211
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
374 self.add_rule(2,1,0,2,1,1,2,1,1,self.s.east+self.s.edge)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
375 # 002
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
376 # 112
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
377 # 112
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
378 self.add_rule(0,0,2,1,1,2,1,1,2,self.s.stop)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
379 # 102
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
380 # 112
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
381 # 112
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
382 self.add_rule(1,0,2,1,1,2,1,1,2,self.s.stop)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
383 # 002
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
384 # 112
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
385 # 102
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
386 self.add_rule(0,0,2,1,1,2,1,0,2,self.s.stop)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
387 # 012
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
388 # 112
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
389 # 112
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
390 self.add_rule(0,1,2,1,1,2,1,1,2,self.s.stop)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
391 # 012
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
392 # 112
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
393 # 102
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
394 self.add_rule(0,1,2,1,1,2,1,0,2,self.s.stop)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
395
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
396 def add_rule(self,nw,nn,ne,ww,cc,ee,sw,ss,se,rule):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
397 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
398 # add a CA rule, with rotations
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
399 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
400 s = CA_states()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
401 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
402 # add the rule
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
403 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
404 state = \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
405 (nw << 0) + (nn << 2) + (ne << 4) + \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
406 (ww << 6) + (cc << 8) + (ee << 10) + \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
407 (sw << 12) + (ss << 14) + (se << 16)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
408 self.table[state] = rule
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
409 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
410 # rotate 90 degrees
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
411 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
412 state = \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
413 (sw << 0) + (ww << 2) + (nw << 4) + \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
414 (ss << 6) + (cc << 8) + (nn << 10) + \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
415 (se << 12) + (ee << 14) + (ne << 16)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
416 if (rule == s.east):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
417 self.table[state] = s.south
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
418 elif (rule == s.south):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
419 self.table[state] = s.west
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
420 elif (rule == s.west):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
421 self.table[state] = s.north
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
422 elif (rule == s.north):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
423 self.table[state] = s.east
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
424 elif (rule == (s.east+s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
425 self.table[state] = s.south+s.edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
426 elif (rule == (s.south+s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
427 self.table[state] = s.west+s.edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
428 elif (rule == (s.west+s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
429 self.table[state] = s.north+s.edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
430 elif (rule == (s.north+s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
431 self.table[state] = s.east+s.edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
432 elif (rule == s.corner):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
433 self.table[state] = s.corner
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
434 elif (rule == s.stop):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
435 self.table[state] = s.stop
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
436 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
437 # rotate 180 degrees
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
438 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
439 state = \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
440 (se << 0) + (ss << 2) + (sw << 4) + \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
441 (ee << 6) + (cc << 8) + (ww << 10) + \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
442 (ne << 12) + (nn << 14) + (nw << 16)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
443 if (rule == s.east):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
444 self.table[state] = s.west
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
445 elif (rule == s.south):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
446 self.table[state] = s.north
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
447 elif (rule == s.west):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
448 self.table[state] = s.east
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
449 elif (rule == s.north):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
450 self.table[state] = s.south
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
451 elif (rule == (s.east+s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
452 self.table[state] = s.west+s.edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
453 elif (rule == (s.south+s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
454 self.table[state] = s.north+s.edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
455 elif (rule == (s.west+s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
456 self.table[state] = s.east+s.edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
457 elif (rule == (s.north+s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
458 self.table[state] = s.south+s.edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
459 elif (rule == s.corner):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
460 self.table[state] = s.corner
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
461 elif (rule == s.stop):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
462 self.table[state] = s.stop
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
463 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
464 # rotate 270 degrees
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
465 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
466 state = \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
467 (ne << 0) + (ee << 2) + (se << 4) + \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
468 (nn << 6) + (cc << 8) + (ss << 10) + \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
469 (nw << 12) + (ww << 14) + (sw << 16)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
470 if (rule == s.east):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
471 self.table[state] = s.north
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
472 elif (rule == s.south):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
473 self.table[state] = s.east
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
474 elif (rule == s.west):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
475 self.table[state] = s.south
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
476 elif (rule == s.north):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
477 self.table[state] = s.west
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
478 elif (rule == (s.east+s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
479 self.table[state] = s.north+s.edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
480 elif (rule == (s.south+s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
481 self.table[state] = s.east+s.edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
482 elif (rule == (s.west+s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
483 self.table[state] = s.south+s.edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
484 elif (rule == (s.north+s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
485 self.table[state] = s.west+s.edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
486 elif (rule == s.corner):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
487 self.table[state] = s.corner
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
488 elif (rule == s.stop):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
489 self.table[state] = s.stop
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
490
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
491 def evaluate_state(arr):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
492 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
493 # assemble the state bit strings
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
494 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
495 (ny, nx) = shape(arr)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
496 s = CA_states()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
497 nn = concatenate(([s.edge+zeros(nx,uint32)],arr[:(ny-1)]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
498 ss = concatenate((arr[1:],[s.edge+zeros(nx,uint32)]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
499 ww = concatenate((reshape(s.edge+zeros(ny,uint32),(ny,1)),arr[:,:(nx-1)]),1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
500 ee = concatenate((arr[:,1:],reshape(s.edge+zeros(ny,uint32),(ny,1))),1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
501 cc = arr
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
502 nw = concatenate(([s.edge+zeros(nx,uint32)],ww[:(ny-1)]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
503 ne = concatenate(([s.edge+zeros(nx,uint32)],ee[:(ny-1)]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
504 sw = concatenate((ww[1:],[s.edge+zeros(nx,uint32)]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
505 se = concatenate((ee[1:],[s.edge+zeros(nx,uint32)]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
506 state = (nw << 0) + (nn << 2) + (ne << 4) + \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
507 (ww << 6) + (cc << 8) + (ee << 10) + \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
508 (sw << 12) + (ss << 14) + (se << 16)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
509 return state
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
510
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
511 def vectorize_toolpaths(arr):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
512 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
513 # convert lattice toolpath directions to vectors
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
514 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
515 s = CA_states()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
516 toolpaths = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
517 max_dist = float(string_vector_error.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
518 start_sites = (arr == (s.north+s.edge)) | (arr == (s.south+s.edge)) | \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
519 (arr == (s.east+s.edge)) | (arr == (s.west+s.edge))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
520 num_start_sites = sum(sum(1.0*start_sites))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
521 path_sites = (arr == s.north) | (arr == s.south) | (arr == s.east) | \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
522 (arr == s.west)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
523 num_path_sites = sum(sum(1.0*path_sites))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
524 remaining_sites = num_start_sites + num_path_sites
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
525 while (remaining_sites != 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
526 #print remaining_sites
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
527 if (num_start_sites > 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
528 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
529 # begin segment on a start state
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
530 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
531 if (argmax(start_sites[0,:],axis=0) != 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
532 x = argmax(start_sites[0,:],axis=0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
533 y = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
534 elif (argmax(start_sites[:,0],axis=0) != 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
535 x = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
536 y = argmax(start_sites[:,0],axis=0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
537 elif (argmax(start_sites[-1,:],axis=0) != 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
538 x = argmax(start_sites[-1,:],axis=0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
539 y = cad.ny-1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
540 elif (argmax(start_sites[:,-1],axis=0) != 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
541 x = cad.nx-1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
542 y = argmax(start_sites[:,-1],axis=0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
543 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
544 print "error: internal start"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
545 sys.exit()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
546 #print "start from ",x,y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
547 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
548 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
549 # no start states; begin segment on upper-left boundary point
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
550 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
551 maxcols = argmax(path_sites,axis=1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
552 y = argmax(argmax(path_sites,axis=1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
553 x = maxcols[y]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
554 arr[y][x] += s.edge
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
555 #print "segment from ",x,y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
556 segment = [point(x,y)]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
557 vector = [point(x,y)]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
558 while 1:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
559 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
560 # follow path
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
561 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
562 y = vector[-1].y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
563 x = vector[-1].x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
564 state = arr[y][x]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
565 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
566 # if start state, set stop
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
567 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
568 if (state == (s.north + s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
569 state = s.north
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
570 arr[y][x] = s.stop
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
571 elif (state == (s.south + s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
572 state = s.south
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
573 arr[y][x] = s.stop
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
574 elif (state == (s.east + s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
575 state = s.east
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
576 arr[y][x] = s.stop
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
577 elif (state == (s.west + s.edge)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
578 state = s.west
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
579 arr[y][x] = s.stop
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
580 #print "x,y,state,arr: ",x,y,state,arr[y][x]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
581 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
582 # move if a valid direction
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
583 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
584 if (state == s.north):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
585 direction = "north"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
586 #print "north"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
587 ynew = y - 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
588 xnew = x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
589 elif (state == s.south):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
590 direction = "south"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
591 #print "south"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
592 ynew = y + 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
593 xnew = x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
594 elif (state == s.east):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
595 direction = "east"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
596 #print "east"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
597 ynew = y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
598 xnew = x + 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
599 elif (state == s.west):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
600 direction = "west"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
601 #print "west"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
602 ynew = y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
603 xnew = x - 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
604 elif (state == s.corner):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
605 #print "corner"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
606 if (direction == "east"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
607 #print "south"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
608 xnew = x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
609 ynew = y + 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
610 elif (direction == "west"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
611 #print "north"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
612 xnew = x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
613 ynew = y - 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
614 elif (direction == "north"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
615 #print "east"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
616 ynew = y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
617 xnew = x + 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
618 elif (direction == "south"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
619 #print "west"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
620 ynew = y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
621 xnew = x - 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
622 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
623 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
624 # not a valid direction, terminate segment on previous point
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
625 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
626 print "unexpected path termination at",x,y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
627 #sys.exit()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
628 segment.append(point(x,y))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
629 toolpaths.append(segment)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
630 arr[y][x] = s.interior
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
631 break
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
632 #print "xnew,ynew,snew",xnew,ynew,arr[ynew][xnew]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
633 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
634 # check if stop reached
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
635 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
636 if (arr[ynew][xnew] == s.stop):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
637 #print "stop at ",xnew,ynew
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
638 segment.append(point(xnew,ynew))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
639 toolpaths.extend([segment])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
640 if (state != s.corner):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
641 arr[y][x] = s.interior
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
642 arr[ynew][xnew] = s.interior
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
643 break
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
644 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
645 # find max transverse distance from vector to new point
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
646 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
647 dmax = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
648 dx = xnew - vector[0].x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
649 dy = ynew - vector[0].y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
650 norm = sqrt(dx**2 + dy**2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
651 nx = dy / norm
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
652 ny = -dx / norm
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
653 for i in range(len(vector)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
654 dx = vector[i].x - vector[0].x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
655 dy = vector[i].y - vector[0].y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
656 d = abs(nx*dx + ny*dy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
657 if (d > dmax):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
658 dmax = d
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
659 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
660 # start new vector if transverse distance > max_dist
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
661 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
662 if (dmax >= max_dist):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
663 #print "max at ",x,y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
664 segment.append(point(x,y))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
665 vector = [point(x,y)]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
666 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
667 # otherwise add point to vector
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
668 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
669 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
670 #print "add ",xnew,ynew
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
671 vector.append(point(xnew,ynew))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
672 if ((arr[y][x] != s.corner) & (arr[y][x] != s.stop)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
673 arr[y][x] = s.interior
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
674 start_sites = (arr == (s.north+s.edge)) | (arr == (s.south+s.edge)) | \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
675 (arr == (s.east+s.edge)) | (arr == (s.west+s.edge))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
676 num_start_sites = sum(sum(1.0*start_sites))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
677 path_sites = (arr == s.north) | (arr == s.south) | (arr == s.east) | \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
678 (arr == s.west)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
679 num_path_sites = sum(sum(1.0*path_sites))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
680 remaining_sites = num_start_sites + num_path_sites
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
681 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
682 # reverse segment order, to start from inside to out
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
683 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
684 newpaths = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
685 for segment in range(len(toolpaths)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
686 newpaths.append(toolpaths[-1-segment])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
687 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
688 return newpaths
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
689
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
690 def evaluate():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
691 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
692 # evaluate .cad program/image
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
693 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
694 if (len(widget_cad_text.get("1.0",END)) > 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
695 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
696 # .cad
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
697 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
698 cad.zlist = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
699 cad_text_string = widget_cad_text.get("1.0",END)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
700 exec cad_text_string in globals()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
701 widget_function_text.config(state=NORMAL)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
702 widget_function_text.delete("1.0",END)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
703 widget_function_text.insert("1.0",cad.function)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
704 widget_function_text.config(state=DISABLED)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
705 if (cad.image_r.size > 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
706 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
707 # image
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
708 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
709 cad.xmin = float(string_image_xmin.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
710 xwidth = float(string_image_xwidth.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
711 cad.xmax = cad.xmin + xwidth
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
712 cad.ymin = float(string_image_ymin.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
713 yheight = float(string_image_yheight.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
714 cad.ymax = cad.ymin + yheight
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
715 cad.image_min = float(string_image_min.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
716 cad.image_max = float(string_image_max.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
717 cad.zmin = float(string_image_zmin.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
718 cad.zmax = float(string_image_zmax.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
719 cad.nz = int(string_image_nz.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
720 cad.inches_per_unit = float(string_image_units.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
721
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
722 def render(view='xyzr'):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
723 render_stop_flag = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
724 cad.stop = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
725 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
726 # if .cad doesn't call render, delete windows and add stop button
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
727 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
728 if (find(widget_cad_text.get("1.0",END),"render(") == -1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
729 string_msg.set("render ...")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
730 widget_stop.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
731 delete_windows()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
732 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
733 # initialize variables
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
734 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
735 cad.toolpaths = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
736 rx = pi*cad.rx/180.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
737 rz = pi*cad.rz/180.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
738 r = rule_table()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
739 s = CA_states()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
740 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
741 # evaluate coordinate arrays
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
742 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
743 Xarray = outer(ones((cad.ny,1)),cad.xmin+(cad.xmax-cad.xmin)*arange(cad.nx)/(cad.nx-1.0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
744 Yarray = outer(cad.ymin+(cad.ymax-cad.ymin)*arange(cad.ny-1,-1,-1)/(cad.ny-1.0),ones((1,cad.nx)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
745 if (cad.zlist == []):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
746 if ((cad.nz == 1) & (cad.image_r.size != 1)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
747 cad.zlist = [cad.zmax]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
748 cad.view('xy')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
749 elif (cad.nz == 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
750 cad.zlist = [cad.zmin]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
751 cad.view('xy')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
752 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
753 cad.zlist = cad.zmin + (cad.zmax-cad.zmin)*arange(cad.nz)/(cad.nz-1.0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
754 cad.view('xyzr')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
755 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
756 cad.nz = len(cad.zlist)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
757 cad.zmin = cad.zlist[0]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
758 cad.zmax = cad.zlist[-1]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
759 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
760 # draw orthogonal views
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
761 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
762 X = Xarray
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
763 Y = Yarray
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
764 accum_r = zeros((cad.ny,cad.nx),uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
765 accum_g = zeros((cad.ny,cad.nx),uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
766 accum_b = zeros((cad.ny,cad.nx),uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
767 im.intensity_yz = zeros((cad.ny,cad.nz),uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
768 im.intensity_xz = zeros((cad.nz,cad.nx),uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
769 im.intensity_xyz = zeros((cad.nz,cad.nx),uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
770 for layer in range(cad.nz):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
771 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
772 # check render stop button
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
773 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
774 if (cad.stop == 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
775 break
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
776 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
777 # xy view
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
778 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
779 Z = cad.zlist[layer]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
780 string_msg.set("render z = %.3f"%Z)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
781 # root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
782 if (cad.image_r.size == 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
783 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
784 # .cad
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
785 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
786 array_r = eval(cad.function)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
787 array_g = array_r
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
788 array_b = array_r
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
789 if ((cad.zmax == cad.zmin) | (cad.nz == 1)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
790 zi = array([255],uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
791 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
792 zi = array([55.0 + 200.0*layer/(cad.nz-1.0)],uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
793 accum_r = where(((zi*array_r) > accum_r),(zi*array_r),accum_r)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
794 accum_g = where(((zi*array_g) > accum_g),(zi*array_g),accum_g)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
795 accum_b = where(((zi*array_b) > accum_b),(zi*array_b),accum_b)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
796 im.intensity_xy = (1 << 16)*accum_b + (1 << 8)*accum_g + (1 << 0)*accum_r
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
797 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
798 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
799 # bitmap
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
800 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
801 array_r = (cad.image_r[0,] >= (cad.image_min + (cad.image_max-cad.image_min)*(Z-cad.zmin)/float(cad.zmax-cad.zmin)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
802 array_g = (cad.image_g[0,] >= (cad.image_min + (cad.image_max-cad.image_min)*(Z-cad.zmin)/float(cad.zmax-cad.zmin)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
803 array_b = (cad.image_b[0,] >= (cad.image_min + (cad.image_max-cad.image_min)*(Z-cad.zmin)/float(cad.zmax-cad.zmin)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
804 image_z = int(cad.image_min + (cad.image_max-cad.image_min)*(Z-cad.zmin)/float(cad.zmax-cad.zmin))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
805 intensity_r = where((cad.image_r[0,] <= image_z),cad.image_r[0,],image_z)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
806 intensity_g = where((cad.image_g[0,] <= image_z),cad.image_g[0,],image_z)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
807 intensity_b = where((cad.image_b[0,] <= image_z),cad.image_b[0,],image_z)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
808 im.intensity_xy = (1 << 16)*intensity_b + (1 << 8)*intensity_g + (1 << 0)*intensity_r
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
809 im.xy = Image.fromarray(im.intensity_xy,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
810 im.xy_draw = ImageDraw.Draw(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
811 im.xy = im.xy.resize((cad.nxplot(),cad.nyplot()))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
812 images.xy = ImageTk.PhotoImage(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
813 canvas_xy.create_image(cad.nplot/2,cad.nplot/2,image=images.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
814 # root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
815 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
816 # find toolpaths if needed
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
817 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
818 ncontours = int(string_num_contours.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
819 if (ncontours == -1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
820 ncontours = 2**20 # a big number
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
821 cad.toolpaths.append([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
822 """
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
823 if (ncontours != 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
824 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
825 # grassfire convolve (to come)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
826 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
827 interior = (array_r | array_g | array_b)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
828 print shape(X[interior])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
829 conv_array = interior
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
830 """
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
831 for contour in range(ncontours):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
832 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
833 # check render stop button
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
834 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
835 if (cad.stop == 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
836 break
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
837 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
838 # convolve tool for contour
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
839 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
840 string_msg.set(" convolve tool ... ")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
841 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
842 # FFT convolve
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
843 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
844 # root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
845 tool_rad = float(string_tool_dia.get())/2.0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
846 tool_dia = float(string_tool_dia.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
847 tool_overlap = float(string_tool_overlap.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
848 kernel_rad = tool_rad + contour*tool_overlap*tool_dia
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
849 ikernel_rad = 1 + int(cad.nx*kernel_rad/(cad.xmax-cad.xmin))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
850 if (ikernel_rad > (((cad.nx/2),(cad.ny/2))[(cad.ny/2) > (cad.nx/2)])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
851 break
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
852 kx = 1+outer(ones((2*ikernel_rad,1)),arange(2*ikernel_rad))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
853 ky = 1+outer(arange(2*ikernel_rad),ones((1,2*ikernel_rad)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
854 k = (((kx-ikernel_rad)**2 + (ky-ikernel_rad)**2) < ikernel_rad**2).astype('uint32')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
855 interior = (array_r == s.interior).astype('uint32')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
856 #tstart = time.time()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
857 conv = scipy.signal.signaltools.fftconvolve(interior,k,mode='same')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
858 conv = where(conv > 0.01,s.interior,0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
859 conv_array = conv + (conv != s.interior)*array_r
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
860 #tend = time.time()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
861 #print 'convolve:',tend-tstart
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
862 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
863 # use CA rule table to find edge directions
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
864 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
865 string_msg.set(" follow edges ... ")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
866 # root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
867 state = evaluate_state(conv_array)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
868 toolpath = r.table[state]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
869 tool_array = toolpath + (toolpath == s.empty)*conv_array
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
870 tool_intensity = \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
871 ((0 << 16) + (0 << 8) + (0 << 0))*(tool_array == s.empty).astype('uint32') +\
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
872 ((255 << 16) + (255 << 8) + (255 << 0))*(tool_array == s.interior).astype('uint32') +\
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
873 (( 0 << 16) + ( 0 << 8) + (255 << 0))*(tool_array == s.north).astype('uint32') +\
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
874 (( 0 << 16) + (255 << 8) + ( 0 << 0))*(tool_array == s.south).astype('uint32') +\
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
875 ((255 << 16) + ( 0 << 8) + ( 0 << 0))*(tool_array == s.east).astype('uint32') +\
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
876 (( 0 << 16) + (255 << 8) + (255 << 0))*(tool_array == s.west ).astype('uint32') +\
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
877 ((128 << 16) + ( 0 << 8) + (128 << 0))*(tool_array == s.stop).astype('uint32')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
878
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
879 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
880 # show CA
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
881 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
882 """
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
883 im.xy = Image.fromarray(tool_intensity,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
884 im.xy = im.xy.resize((cad.nplot,cad.nplot))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
885 images.xy = ImageTk.PhotoImage(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
886 canvas_xy.create_image(cad.nplot/2,cad.nplot/2,image=images.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
887 """
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
888 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
889 # vectorize contour
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
890 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
891 #tstart = time.time()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
892 string_msg.set(" vectorize ... ")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
893 # root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
894 new_paths = vectorize_toolpaths(tool_array)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
895 if (len(new_paths) == 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
896 break
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
897 cad.toolpaths[layer].extend(new_paths)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
898 #tend = time.time()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
899 #print 'vector:',tend-tstart
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
900 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
901 # draw toolpath
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
902 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
903 im.xy_draw = ImageDraw.Draw(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
904 for segment in range(len(cad.toolpaths[layer])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
905 x = cad.nxplot()*(cad.toolpaths[layer][segment][0].x+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
906 y = cad.nyplot()*(cad.toolpaths[layer][segment][0].y+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
907 for vertex in range(1,len(cad.toolpaths[layer][segment])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
908 xnew = cad.nxplot()*(cad.toolpaths[layer][segment][vertex].x+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
909 ynew = cad.nyplot()*(cad.toolpaths[layer][segment][vertex].y+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
910 im.xy_draw.line([x,y,xnew,ynew],fill="#ffa0a0",width=1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
911 x = xnew
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
912 y = ynew
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
913 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
914 # show xy toolpath view
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
915 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
916 images.xy = ImageTk.PhotoImage(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
917 canvas_xy.create_image(cad.nplot/2,cad.nplot/2,image=images.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
918 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
919 # add send_to button
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
920 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
921 string_send_to_time.set("")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
922 send_to_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
923 # root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
924 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
925 # draw labels
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
926 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
927 for label in range(len(cad.labels)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
928 x = cad.nplot/2. + cad.nxplot()*(cad.labels[label].x-(cad.xmax+cad.xmin)/2.0)/(cad.xmax-cad.xmin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
929 y = cad.nplot/2. - cad.nyplot()*(cad.labels[label].y-(cad.ymax+cad.ymin)/2.0)/(cad.ymax-cad.ymin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
930 string = cad.labels[label].text
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
931 size = cad.labels[label].size
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
932 color = cad.labels[label].color
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
933 anch = cad.labels[label].anchor
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
934 canvas_xy.create_text(x,y,text=string,font=('arial',size,'bold'),fill=color,anchor=anch,justify=CENTER)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
935 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
936 # draw origin
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
937 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
938 x0 = cad.nplot/2. + cad.nxplot()*(0-(cad.xmax+cad.xmin)/2.)/(cad.xmax-cad.xmin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
939 y0 = cad.nplot/2. - cad.nyplot()*(0-(cad.ymax+cad.ymin)/2.)/(cad.ymax-cad.ymin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
940 dxy = .025*cad.nplot
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
941 canvas_xy.create_line([x0-dxy,y0,x0+dxy,y0],fill="green")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
942 canvas_xy.create_line([x0,y0-dxy,x0,y0+dxy],fill="green")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
943 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
944 # yz view
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
945 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
946 if (cad.views == 'xyzr'):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
947 accum_yz_r = zeros(cad.ny,uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
948 accum_yz_g = zeros(cad.ny,uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
949 accum_yz_b = zeros(cad.ny,uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
950 for vertex in range(cad.nx):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
951 xi = array([55.0 + 200.0*vertex/(cad.nx-1.0)],uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
952 slice_r = array_r[:,vertex]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
953 slice_g = array_g[:,vertex]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
954 slice_b = array_b[:,vertex]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
955 accum_yz_r = where(((xi*slice_r) >= accum_yz_r),(xi*slice_r),accum_yz_r)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
956 accum_yz_g = where(((xi*slice_g) >= accum_yz_g),(xi*slice_g),accum_yz_g)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
957 accum_yz_b = where(((xi*slice_b) >= accum_yz_b),(xi*slice_b),accum_yz_b)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
958 im.intensity_yz[:,layer] = (1 << 16)*accum_yz_b + (1 << 8)*accum_yz_g + (1 << 0)*accum_yz_r
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
959 im.yz = Image.fromarray(im.intensity_yz,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
960 im.yz = im.yz.transpose(Image.FLIP_LEFT_RIGHT)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
961 im.yz = im.yz.resize((cad.nzplot(),cad.nyplot()))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
962 images.yz = ImageTk.PhotoImage(im.yz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
963 canvas_yz.create_image(cad.nplot/2,cad.nplot/2,image=images.yz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
964 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
965 # draw origin
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
966 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
967 z0 = cad.nplot/2. - cad.nzplot()*(0-(cad.zmax+cad.zmin)/2.)/(cad.zmax-cad.zmin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
968 y0 = cad.nplot/2. - cad.nyplot()*(0-(cad.ymax+cad.ymin)/2.)/(cad.ymax-cad.ymin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
969 canvas_yz.create_line([z0-dxy,y0,z0+dxy,y0],fill="green")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
970 canvas_yz.create_line([z0,y0-dxy,z0,y0+dxy],fill="green")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
971 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
972 # xz view
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
973 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
974 if (cad.views == 'xyzr'):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
975 accum_xz_r = zeros(cad.nx,uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
976 accum_xz_g = zeros(cad.nx,uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
977 accum_xz_b = zeros(cad.nx,uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
978 for vertex in range(cad.ny):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
979 yi = array([55.0+200.0*vertex/(cad.ny-1.0)],uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
980 slice_r = array_r[vertex,:]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
981 slice_g = array_g[vertex,:]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
982 slice_b = array_b[vertex,:]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
983 accum_xz_r = where(((yi*slice_r) >= accum_xz_r),(yi*slice_r),accum_xz_r)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
984 accum_xz_g = where(((yi*slice_g) >= accum_xz_g),(yi*slice_g),accum_xz_g)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
985 accum_xz_b = where(((yi*slice_b) >= accum_xz_b),(yi*slice_b),accum_xz_b)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
986 im.intensity_xz[(cad.nz-1-layer),:] = (1 << 16)*accum_xz_b + (1 << 8)*accum_xz_g + (1 << 0)*accum_xz_r
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
987 im.xz = Image.fromarray(im.intensity_xz,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
988 im.xz = im.xz.resize((cad.nxplot(),cad.nzplot()))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
989 images.xz = ImageTk.PhotoImage(im.xz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
990 canvas_xz.create_image(cad.nplot/2,cad.nplot/2,image=images.xz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
991 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
992 # draw origin
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
993 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
994 x0 = cad.nplot/2. + cad.nxplot()*(0-(cad.xmax+cad.xmin)/2.)/(cad.xmax-cad.xmin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
995 z0 = cad.nplot/2. - cad.nzplot()*(0-(cad.zmax+cad.zmin)/2.)/(cad.zmax-cad.zmin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
996 canvas_xz.create_line([x0-dxy,z0,x0+dxy,z0],fill="green")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
997 canvas_xz.create_line([x0,z0-dxy,x0,z0+dxy],fill="green")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
998 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
999 # draw it
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1000 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1001 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1002 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1003 # rotated view
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1004 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1005 if ((cad.views == 'xyzr') & (cad.image_r.size == 1)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1006 accum = zeros((cad.ny,cad.nx),uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1007 for z in cad.zlist:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1008 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1009 # check render stop button
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1010 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1011 if (cad.stop == 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1012 break
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1013 string_msg.set("render z = %.3f"%z)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1014 dY = cos(rx)*(Yarray-(cad.ymax+cad.ymin)/2.0) - sin(rx)*(z-(cad.zmax+cad.zmin)/2.0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1015 Z = (cad.zmax+cad.zmin)/2.0 + sin(rx)*(Yarray-(cad.ymax+cad.ymin)/2.0) + cos(rx)*(z-(cad.zmax+cad.zmin)/2.0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1016 X = (cad.xmax+cad.xmin)/2.0 + cos(rz)*(Xarray-(cad.xmax+cad.xmin)/2.0) - sin(rz)*dY
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1017 Y = (cad.ymax+cad.ymin)/2.0 + sin(rz)*(Xarray-(cad.xmax+cad.xmin)/2.0) + cos(rz)*dY
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1018 arr = eval(cad.function)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1019 if (cad.zmax == cad.zmin):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1020 zi = array([255],uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1021 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1022 zi = array([55.0 + 200.0*(z-cad.zmin)/(cad.zmax-cad.zmin)],uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1023 accum = where(((zi*arr) > accum),(zi*arr),accum)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1024 im.intensity_xyz = ((1 << 16) + (1 << 8) + (1 << 0)) * accum
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1025 im.xyz = Image.fromarray(im.intensity_xyz,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1026 im.xyz = im.xyz.resize((cad.nxplot(),cad.nyplot()))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1027 images.xyz = ImageTk.PhotoImage(im.xyz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1028 canvas_xyz.create_image(cad.nplot/2,cad.nplot/2,image=images.xyz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1029 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1030 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1031 # return
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1032 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1033 cad.zwrite = cad.zlist
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1034 cad.zlist = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1035 widget_stop.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1036 string_msg.set("done")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1037 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1038 return
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1039
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1040 def draw_toolpath():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1041 im.xy = Image.new("RGBX",(cad.nxplot(),cad.nyplot()),'white')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1042 im.xy_draw = ImageDraw.Draw(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1043 for layer in range(len(cad.toolpaths)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1044 for segment in range(len(cad.toolpaths[layer])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1045 x = cad.nxplot()*(cad.toolpaths[layer][segment][0].x+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1046 y = cad.nyplot()*(cad.toolpaths[layer][segment][0].y+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1047 for vertex in range(1,len(cad.toolpaths[layer][segment])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1048 xnew = cad.nxplot()*(cad.toolpaths[layer][segment][vertex].x+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1049 ynew = cad.nyplot()*(cad.toolpaths[layer][segment][vertex].y+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1050 im.xy_draw.line([x,y,xnew,ynew],fill="black")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1051 x = xnew
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1052 y = ynew
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1053 images.xy = ImageTk.PhotoImage(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1054 canvas_xy.create_image(cad.nplot/2,cad.nplot/2,image=images.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1055
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1056 def delete_windows():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1057 im.xy = Image.new("RGBX",(cad.nplot,cad.nplot),'black')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1058 images.xy = ImageTk.PhotoImage(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1059 canvas_xy.create_image(cad.nplot/2,cad.nplot/2,image=images.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1060 im.yz = Image.new("RGBX",(cad.nplot,cad.nplot),'black')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1061 images.yz = ImageTk.PhotoImage(im.yz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1062 canvas_yz.create_image(cad.nplot/2,cad.nplot/2,image=images.yz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1063 im.xz = Image.new("RGBX",(cad.nplot,cad.nplot),'black')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1064 images.xz = ImageTk.PhotoImage(im.xz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1065 canvas_xz.create_image(cad.nplot/2,cad.nplot/2,image=images.xz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1066 im.xyz = Image.new("RGBX",(cad.nplot,cad.nplot),'black')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1067 images.xyz = ImageTk.PhotoImage(im.xyz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1068 canvas_xyz.create_image(cad.nplot/2,cad.nplot/2,image=images.xyz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1069 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1070
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1071 def select_cad():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1072 image_x_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1073 image_y_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1074 image_z_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1075 image_intensity_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1076 image_units_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1077 image_invert_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1078 cad_input_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1079 widget_cad_text.delete("1.0",END)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1080 widget_cad_text.insert("1.0",cad_template)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1081 editor_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1082 cad.image = array(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1083 cad_input_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1084 cad.toolpaths = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1085 string_num_contours.set('0')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1086 widget_cad_save.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1087 delete_windows()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1088
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1089 def select_image():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1090 editor_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1091 cad_input_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1092 image_x_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1093 image_y_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1094 image_z_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1095 image_intensity_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1096 image_units_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1097 image_invert_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1098 cad_input_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1099 cad.toolpaths = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1100 string_num_contours.set('0')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1101 widget_cad_save.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1102 delete_windows()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1103
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1104 def input_open():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1105 filename = askopenfilename()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1106 string_input_file.set(filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1107 if (find(filename,'.cad') != -1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1108 cad_load(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1109 elif ((find(filename,'.jpg') != -1) | (find(filename,'.JPG') != -1) |
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1110 (find(filename,'.png') != -1) | (find(filename,'.PNG') != -1) |
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1111 (find(filename,'.gif') != -1) | (find(filename,'.GIF') != -1)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1112 widget_cad_text.delete("1.0",END)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1113 image_load(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1114 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1115 string_msg.set("unsupported input file format")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1116 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1117
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1118 def cad_load(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1119 global cad
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1120 cad = cad_variables()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1121 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1122 select_cad()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1123 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1124 input_file = open(input_file_name,'rb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1125 cad_text_string = input_file.read()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1126 widget_cad_text.delete("1.0",END)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1127 widget_cad_text.insert("1.0",cad_text_string)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1128 input_file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1129 cad.toolpaths = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1130 cad.image = array(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1131 cad.nz = 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1132 string_num_contours.set('0')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1133 evaluate()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1134 if (find(widget_cad_text.get("1.0",END),"render(") == -1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1135 render()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1136
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1137 def image_load(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1138 global cad
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1139 cad = cad_variables()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1140 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1141 select_image()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1142 function_string_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1143 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1144 input_file = open(input_file_name,'rb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1145 input_file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1146 cad.toolpaths = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1147 string_num_contours.set('0')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1148 image = Image.open(input_file_name)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1149 num_layers = 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1150 while 1: # check number of layers
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1151 try:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1152 image.seek(image.tell()+1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1153 num_layers += 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1154 except:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1155 break
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1156 image = Image.open(input_file_name)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1157 if image.mode != "RGBX":
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1158 image = image.convert("RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1159 (cad.nx,cad.ny) = image.size
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1160 info = image.info
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1161 if ('dpi' in info):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1162 (xdpi,ydpi) = info['dpi']
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1163 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1164 xdpi = cad.nx
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1165 ydpi = xdpi
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1166 string_image_nx.set(" nx = "+str(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1167 string_image_ny.set(" ny = "+str(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1168 cad.nz = 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1169 string_image_nz.set(str(cad.nz))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1170 cad.xmin = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1171 string_image_xmin.set('0')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1172 cad.xmax = cad.nx/float(xdpi)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1173 string_image_xwidth.set(str(cad.xmax-cad.xmin))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1174 cad.ymin = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1175 string_image_ymin.set('0')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1176 cad.ymax = cad.ny/float(ydpi)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1177 string_image_yheight.set(str(cad.ymax-cad.ymin))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1178 cad.zmin = -.005
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1179 string_image_zmin.set('-0.05')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1180 cad.zmax = 0.05
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1181 string_image_zmax.set('0.05')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1182 cad.inches_per_unit = 1.0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1183 string_image_units.set('25.4')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1184 data = zeros((num_layers,cad.nx*cad.ny,3),uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1185 data[0,] = array(image.convert("RGB").getdata(),uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1186 for layer in range(1,num_layers):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1187 image.seek(image.tell()+1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1188 data[layer,] = array(image.convert("RGB").getdata(),uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1189 cad.image_r = array(data[:,:,0],uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1190 cad.image_r = cad.image_r.reshape((num_layers,cad.ny,cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1191 cad.image_g = array(data[:,:,1],uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1192 cad.image_g = cad.image_g.reshape((num_layers,cad.ny,cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1193 cad.image_b = array(data[:,:,2],uint32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1194 cad.image_b = cad.image_b.reshape((num_layers,cad.ny,cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1195 cad.image_min = 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1196 string_image_min.set(str(cad.image_min))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1197 cad.image_max = 255
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1198 string_image_max.set(str(cad.image_max))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1199 evaluate()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1200 render()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1201
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1202 def invert_image(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1203 cad.image_r = 255 - cad.image_r
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1204 cad.image_g = 255 - cad.image_g
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1205 cad.image_b = 255 - cad.image_b
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1206 evaluate()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1207 render()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1208
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1209 def cad_save(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1210 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1211 input_file = open(input_file_name,'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1212 cad_text_string = widget_cad_text.get("1.0",END)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1213 input_file.write(cad_text_string)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1214 input_file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1215 string_msg.set(input_file_name+" saved")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1216 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1217
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1218 def render_button(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1219 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1220 cad.cam = ''
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1221 if (cad.image_r.size == 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1222 function_string_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1223 cad.toolpaths = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1224 string_num_contours.set('0')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1225 evaluate()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1226 if (find(widget_cad_text.get("1.0",END),"render(") == -1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1227 render()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1228
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1229 def render_stop(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1230 cad.stop = 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1231 widget_stop.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1232
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1233 def cam(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1234 function_string_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1235 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1236 string_num_contours.set('1')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1237 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1238
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1239 def contour(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1240 evaluate()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1241 if (find(widget_cad_text.get("1.0",END),"render(") == -1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1242 render()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1243
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1244 def triangulate(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1245 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1246 # triangulate for STL
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1247 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1248 # evaluate .cad
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1249 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1250 evaluate()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1251 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1252 # initialize variables
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1253 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1254 render_stop_flag = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1255 cad.stop = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1256 widget_stop.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1257 delete_windows()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1258 cad.toolpaths = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1259 cad.zwrite = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1260 cad.x = zeros(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1261 cad.y = zeros(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1262 cad.z = zeros(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1263 ixlr = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1264 iylrs = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1265 iylre = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1266 izlr = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1267 ixfbs = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1268 ixfbe = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1269 iyfb = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1270 izfb = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1271 ixtbs = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1272 ixtbe = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1273 iytb = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1274 iztb = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1275 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1276 # evaluate coordinate arrays
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1277 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1278 (IY,IX) = indices((cad.ny,cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1279 IY = IY[::-1,:]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1280 X = cad.xmin+(cad.xmax-cad.xmin)*IX/(cad.nx-1.0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1281 Y = cad.ymin+(cad.ymax-cad.ymin)*IY/(cad.ny-1.0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1282 cad.zwrite = cad.zmin + (cad.zmax-cad.zmin)*arange(cad.nz)/(cad.nz-1.0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1283 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1284 # set up drawing images
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1285 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1286 im.xy = Image.new("RGBX",(cad.nxplot(),cad.nyplot()),'white')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1287 im.xy_draw = ImageDraw.Draw(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1288 im.xz = Image.new("RGBX",(cad.nxplot(),cad.nzplot()),'white')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1289 im.xz_draw = ImageDraw.Draw(im.xz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1290 im.yz = Image.new("RGBX",(cad.nzplot(),cad.nyplot()),'white')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1291 im.yz_draw = ImageDraw.Draw(im.yz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1292 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1293 # loop over layers
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1294 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1295 Z = cad.zwrite[0]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1296 array0 = eval(cad.function)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1297 Z = cad.zwrite[1]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1298 array1 = eval(cad.function)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1299 for layer in range(2,len(cad.zwrite)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1300 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1301 # check render stop button
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1302 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1303 if (cad.stop == 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1304 break
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1305 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1306 # evaluate new layer
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1307 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1308 Z = cad.zwrite[layer]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1309 string_msg.set("triangulate z = %.3f"%Z)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1310 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1311 array2 = eval(cad.function)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1312 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1313 # find left faces and merge y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1314 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1315 elements = hstack((reshape((array1[:,0] == True),(cad.ny,1)),((array1[:,1:] == True) & (array1[:,:-1] == False))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1316 starts = vstack((((elements[:-1,:] == True) & (elements[1:,:] == False)),reshape((elements[-1,:] == True),(1,cad.nx))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1317 ends = vstack((reshape((elements[0,:] == True),(1,cad.nx)),((elements[1:,:] == True) & (elements[:-1,:] == False))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1318 IY_t = transpose(IY) # for starts and ends to be read in same row
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1319 IX_t = transpose(IX)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1320 starts_t = transpose(starts)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1321 ends_t = transpose(ends)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1322 ixlr = append(ixlr,IX_t[starts_t])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1323 iylrs = append(iylrs,IY_t[starts_t])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1324 iylre = append(iylre,1+IY_t[ends_t])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1325 izlr = append(izlr,(layer-1)*ones(len(IX_t[starts_t])))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1326 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1327 # find right faces and merge y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1328 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1329 elements = hstack((((array1[:,1:] == False) & (array1[:,:-1] == True)),reshape((array1[:,1] == True),(cad.ny,1))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1330 starts = vstack((((elements[:-1,:] == True) & (elements[1:,:] == False)),reshape((elements[-1,:] == True),(1,cad.nx))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1331 ends = vstack((reshape((elements[0,:] == True),(1,cad.nx)),((elements[1:,:] == True) & (elements[:-1,:] == False))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1332 IY_t = transpose(IY) # for starts and ends to be read in same row
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1333 IX_t = transpose(IX)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1334 starts_t = transpose(starts)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1335 ends_t = transpose(ends)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1336 ixlr = append(ixlr,1+IX_t[starts_t])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1337 iylre = append(iylre,IY_t[starts_t])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1338 iylrs = append(iylrs,1+IY_t[ends_t])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1339 izlr = append(izlr,(layer-1)*ones(len(IX_t[starts_t])))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1340 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1341 # find front faces and merge x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1342 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1343 elements = vstack((((array1[:-1,:] == True) & (array1[1:,:] == False)),reshape((array1[0,:] == True),(1,cad.nx))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1344 starts = hstack((reshape((elements[:,0] == True),(cad.ny,1)),((elements[:,1:] == True) & (elements[:,:-1] == False))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1345 ends = hstack((((elements[:,:-1] == True) & (elements[:,1:] == False)),reshape((elements[:,-1] == True),(cad.ny,1))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1346 ixfbs = append(ixfbs,IX[starts])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1347 ixfbe = append(ixfbe,1+IX[ends])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1348 iyfb = append(iyfb,IY[starts])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1349 izfb = append(izfb,(layer-1)*ones(len(IX[starts])))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1350 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1351 # find back faces and merge x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1352 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1353 elements = vstack((reshape((array1[-1,:] == True),(1,cad.nx)),((array1[1:,:] == True) & (array1[:-1,:] == False))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1354 starts = hstack((reshape((elements[:,0] == True),(cad.ny,1)),((elements[:,1:] == True) & (elements[:,:-1] == False))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1355 ends = hstack((((elements[:,:-1] == True) & (elements[:,1:] == False)),reshape((elements[:,-1] == True),(cad.ny,1))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1356 ixfbe = append(ixfbe,IX[starts])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1357 ixfbs = append(ixfbs,1+IX[ends])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1358 iyfb = append(iyfb,1+IY[starts])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1359 izfb = append(izfb,(layer-1)*ones(len(IX[starts])))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1360 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1361 # find top faces and merge x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1362 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1363 elements = ((array2 == False) & (array1 == True))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1364 starts = hstack((reshape((elements[:,0] == True),(cad.ny,1)),((elements[:,1:] == True) & (elements[:,:-1] == False))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1365 ends = hstack((((elements[:,:-1] == True) & (elements[:,1:] == False)),reshape((elements[:,-1] == True),(cad.ny,1))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1366 ixtbs = append(ixtbs,IX[starts])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1367 ixtbe = append(ixtbe,1+IX[ends])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1368 iytb = append(iytb,IY[starts])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1369 iztb = append(iztb,layer*ones(len(IX[starts])))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1370 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1371 # find bottom faces and merge x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1372 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1373 elements = ((array0 == False) & (array1 == True))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1374 starts = hstack((reshape((elements[:,0] == True),(cad.ny,1)),((elements[:,1:] == True) & (elements[:,:-1] == False))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1375 ends = hstack((((elements[:,:-1] == True) & (elements[:,1:] == False)),reshape((elements[:,-1] == True),(cad.ny,1))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1376 ixtbe = append(ixtbe,IX[starts])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1377 ixtbs = append(ixtbs,1+IX[ends])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1378 iytb = append(iytb,IY[starts])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1379 iztb = append(iztb,(layer-1)*ones(len(IX[starts])))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1380 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1381 # push array stack
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1382 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1383 array0 = array1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1384 array1 = array2
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1385 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1386 # z merge front/back faces
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1387 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1388 index = lexsort(keys=(izfb,ixfbe,ixfbs,iyfb))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1389 merge = (iyfb[index[1:]] == iyfb[index[:-1]]) & \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1390 (ixfbe[index[1:]] == ixfbe[index[:-1]]) & \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1391 (ixfbs[index[1:]] == ixfbs[index[:-1]]) & \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1392 ((izfb[index[1:]] - izfb[index[:-1]]) == 1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1393 merge = append(False,merge).astype(bool_)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1394 starts = ((merge[1:] == True) & (merge[:-1] == False))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1395 starts = append(starts,False).astype(bool_)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1396 ends = ((merge[1:] == False) & (merge[:-1] == True))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1397 if (merge[-1] == True):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1398 ends = append(ends,True)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1399 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1400 ends = append(ends,False)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1401 ends = ends.astype(bool_)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1402 xs = ixfbs[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1403 xe = ixfbe[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1404 y = iyfb[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1405 zs = izfb[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1406 ze = izfb[index][ends | ~(merge | starts)]+1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1407 cad.x = ravel(transpose(vstack((xs,xe,xs,xs,xe,xe))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1408 cad.y = ravel(transpose(vstack((y,y,y,y,y,y))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1409 cad.z = ravel(transpose(vstack((zs,ze,ze,zs,zs,ze))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1410 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1411 # z merge left/right faces
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1412 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1413 index = lexsort(keys=(izlr,iylre,iylrs,ixlr))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1414 merge = (ixlr[index[1:]] == ixlr[index[:-1]]) & \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1415 (iylre[index[1:]] == iylre[index[:-1]]) & \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1416 (iylrs[index[1:]] == iylrs[index[:-1]]) & \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1417 ((izlr[index[1:]] - izlr[index[:-1]]) == 1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1418 merge = append(False,merge).astype(bool_)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1419 starts = ((merge[1:] == True) & (merge[:-1] == False))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1420 starts = append(starts,False).astype(bool_)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1421 ends = ((merge[1:] == False) & (merge[:-1] == True))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1422 if (merge[-1] == True):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1423 ends = append(ends,True)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1424 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1425 ends = append(ends,False)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1426 ends = ends.astype(bool_)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1427 x = ixlr[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1428 ys = iylrs[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1429 ye = iylre[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1430 zs = izlr[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1431 ze = izlr[index][ends | ~(merge | starts)]+1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1432 cad.x = append(cad.x,ravel(transpose(vstack((x,x,x,x,x,x)))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1433 cad.y = append(cad.y,ravel(transpose(vstack((ys,ye,ys,ys,ye,ye)))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1434 cad.z = append(cad.z,ravel(transpose(vstack((zs,ze,ze,zs,zs,ze)))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1435 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1436 # y merge top/bottom faces
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1437 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1438 index = lexsort(keys=(iytb,ixtbe,ixtbs,iztb))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1439 merge = (iztb[index[1:]] == iztb[index[:-1]]) & \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1440 (ixtbe[index[1:]] == ixtbe[index[:-1]]) & \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1441 (ixtbs[index[1:]] == ixtbs[index[:-1]]) & \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1442 ((iytb[index[1:]] - iytb[index[:-1]]) == 1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1443 merge = append(False,merge).astype(bool_)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1444 starts = ((merge[1:] == True) & (merge[:-1] == False))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1445 starts = append(starts,False).astype(bool_)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1446 ends = ((merge[1:] == False) & (merge[:-1] == True))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1447 if (merge[-1] == True):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1448 ends = append(ends,True)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1449 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1450 ends = append(ends,False)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1451 ends = ends.astype(bool_)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1452 xs = ixtbs[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1453 xe = ixtbe[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1454 ys = iytb[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1455 ye = iytb[index][ends | ~(merge | starts)]+1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1456 z = iztb[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1457 cad.x = append(cad.x,ravel(transpose(vstack((xs,xe,xs,xs,xe,xe)))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1458 cad.y = append(cad.y,ravel(transpose(vstack((ys,ye,ye,ys,ys,ye)))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1459 cad.z = append(cad.z,ravel(transpose(vstack((z,z,z,z,z,z)))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1460 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1461 # draw triangulation
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1462 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1463 widget_stop.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1464 string_msg.set("draw ...")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1465 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1466 N = len(cad.x)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1467 for i in range(0,N,3):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1468 string_msg.set("draw triangle %d/%d"%(i/3,N/3))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1469 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1470 x0 = cad.nxplot()*(cad.x[i]+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1471 y0 = cad.nyplot()*(cad.ny-cad.y[i]+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1472 z0 = cad.nzplot()*(cad.nz-cad.z[i]+0.5)/float(cad.nz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1473 x1 = cad.nxplot()*(cad.x[i+1]+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1474 y1 = cad.nyplot()*(cad.ny-cad.y[i+1]+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1475 z1 = cad.nzplot()*(cad.nz-cad.z[i+1]+0.5)/float(cad.nz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1476 x2 = cad.nxplot()*(cad.x[i+2]+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1477 y2 = cad.nyplot()*(cad.ny-cad.y[i+2]+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1478 z2 = cad.nzplot()*(cad.nz-cad.z[i+2]+0.5)/float(cad.nz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1479 im.xy_draw.line([x0,y0,x1,y1,x2,y2,x0,y0],fill="black")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1480 im.xz_draw.line([x0,z0,x1,z1,x2,z2,x0,z0],fill="black")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1481 im.yz_draw.line([z0,y0,z1,y1,z2,y2,z0,y0],fill="black")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1482 images.xy = ImageTk.PhotoImage(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1483 images.xz = ImageTk.PhotoImage(im.xz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1484 images.yz = ImageTk.PhotoImage(im.yz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1485 canvas_xy.create_image(cad.nplot/2,cad.nplot/2,image=images.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1486 canvas_xz.create_image(cad.nplot/2,cad.nplot/2,image=images.xz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1487 canvas_yz.create_image(cad.nplot/2,cad.nplot/2,image=images.yz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1488 im.xyz = Image.new("RGBX",(cad.nplot,cad.nplot),'white')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1489 images.xyz = ImageTk.PhotoImage(im.xyz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1490 canvas_xyz.create_image(cad.nplot/2,cad.nplot/2,image=images.xyz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1491 string_msg.set("done")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1492 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1493
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1494 def flash(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1495 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1496 # convert to Gerber flashes
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1497 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1498 # evaluate .cad
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1499 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1500 evaluate()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1501 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1502 # initialize variables
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1503 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1504 render_stop_flag = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1505 cad.stop = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1506 widget_stop.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1507 delete_windows()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1508 cad.toolpaths = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1509 cad.zwrite = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1510 cad.x = zeros(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1511 cad.y = zeros(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1512 cad.z = zeros(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1513 ixs = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1514 ixe = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1515 iy = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1516 iz = array([])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1517 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1518 # evaluate coordinate arrays
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1519 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1520 (IY,IX) = indices((cad.ny,cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1521 IY = IY[::-1,:]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1522 IZ = arange(cad.nz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1523 X = cad.xmin+(cad.xmax-cad.xmin)*IX/(cad.nx-1.0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1524 Y = cad.ymin+(cad.ymax-cad.ymin)*IY/(cad.ny-1.0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1525 if (cad.zwrite == []):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1526 if (cad.nz > 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1527 cad.zwrite = cad.zmin + (cad.zmax-cad.zmin)*arange(cad.nz)/(cad.nz-1.0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1528 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1529 cad.zwrite = [cad.zmin]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1530 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1531 # set up drawing image
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1532 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1533 im.xy = Image.new("RGBX",(cad.nxplot(),cad.nyplot()),'white')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1534 im.xy_draw = ImageDraw.Draw(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1535 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1536 # loop over layers
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1537 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1538 for layer in range(len(cad.zwrite)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1539 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1540 # check render stop button
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1541 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1542 if (cad.stop == 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1543 break
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1544 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1545 # evaluate layer
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1546 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1547 Z = cad.zwrite[layer]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1548 string_msg.set("convert z = %.3f"%Z)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1549 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1550 elements = eval(cad.function)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1551 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1552 # merge x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1553 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1554 starts = hstack((reshape((elements[:,0] == TRUE),(cad.ny,1)),((elements[:,1:] == TRUE) & (elements[:,:-1] == FALSE))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1555 ends = hstack((((elements[:,:-1] == TRUE) & (elements[:,1:] == FALSE)),reshape((elements[:,-1] == TRUE),(cad.ny,1))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1556 ixs = append(ixs,IX[starts])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1557 ixe = append(ixe,1+IX[ends])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1558 iy = append(iy,IY[starts])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1559 iz = append(iz,IZ[layer-1]*ones(len(IX[starts])))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1560 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1561 # merge y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1562 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1563 index = lexsort(keys=(iy,ixe,ixs,iz))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1564 merge = (iz[index[1:]] == iz[index[:-1]]) & \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1565 (ixe[index[1:]] == ixe[index[:-1]]) & \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1566 (ixs[index[1:]] == ixs[index[:-1]]) & \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1567 ((iy[index[1:]] - iy[index[:-1]]) == 1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1568 merge = append(FALSE,merge).astype(bool_)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1569 starts = ((merge[1:] == TRUE) & (merge[:-1] == FALSE))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1570 starts = append(starts,FALSE).astype(bool_)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1571 ends = ((merge[1:] == FALSE) & (merge[:-1] == TRUE))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1572 if (merge[-1] == TRUE):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1573 ends = append(ends,TRUE)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1574 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1575 ends = append(ends,FALSE)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1576 ends = ends.astype(bool_)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1577 xs = ixs[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1578 xe = ixe[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1579 ys = iy[index][starts | ~merge]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1580 ye = iy[index][ends | ~(merge | starts)]+1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1581 cad.x = ravel(transpose(vstack((xs,xe))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1582 cad.y = ravel(transpose(vstack((ys,ye))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1583 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1584 # draw flashes
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1585 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1586 widget_stop.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1587 cad.view('xy')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1588 string_msg.set("draw ...")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1589 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1590 N = len(cad.x)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1591 for i in range(0,N,2):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1592 string_msg.set("draw flash %d/%d"%(i/4,N/4))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1593 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1594 x0 = cad.nxplot()*(cad.x[i]+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1595 y0 = cad.nyplot()*(cad.ny-cad.y[i]+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1596 x1 = cad.nxplot()*(cad.x[i]+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1597 y1 = cad.nyplot()*(cad.ny-cad.y[i+1]+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1598 x2 = cad.nxplot()*(cad.x[i+1]+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1599 y2 = cad.nyplot()*(cad.ny-cad.y[i+1]+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1600 x3 = cad.nxplot()*(cad.x[i+1]+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1601 y3 = cad.nyplot()*(cad.ny-cad.y[i]+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1602 im.xy_draw.line([x0,y0,x1,y1,x2,y2,x3,y3,x0,y0],fill="black")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1603 images.xy = ImageTk.PhotoImage(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1604 canvas_xy.create_image(cad.nplot/2,cad.nplot/2,image=images.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1605 string_msg.set("done")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1606 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1607
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1608 def select_epi():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1609 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1610 string_cam_file.set(input_file_name[0:-4]+'.epi')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1611 cad.cam = 'epi'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1612 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1613 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1614 cam_vector_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1615 cam_dia_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1616 cam_contour_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1617 laser_frame1.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1618 if ((cad.nz > 1) | (cad.image_r.size > 1)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1619 laser_frame2.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1620 laser_frame3.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1621 string_laser_rate.set("2500")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1622 string_laser_power.set("90")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1623 string_laser_speed.set("50")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1624 string_laser_min_power.set("10")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1625 string_laser_max_power.set("100")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1626 string_tool_dia.set("0.01")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1627 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1628
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1629 def select_camm():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1630 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1631 string_cam_file.set(input_file_name[0:-4]+'.camm')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1632 cad.cam = 'camm'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1633 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1634 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1635 cam_vector_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1636 cam_dia_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1637 cam_contour_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1638 cut_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1639 string_cut_force.set("45")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1640 string_cut_velocity.set("2")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1641 string_tool_dia.set("0.01")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1642 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1643
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1644 def select_ps():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1645 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1646 string_cam_file.set(input_file_name[0:-4]+'.ps')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1647 cad.cam = 'ps'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1648 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1649 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1650 cam_vector_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1651 cam_dia_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1652 cam_contour_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1653 fill_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1654 string_tool_dia.set("0.0")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1655 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1656
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1657 def select_ord():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1658 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1659 string_cam_file.set(input_file_name[0:-4]+'.ord')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1660 cad.cam = 'ord'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1661 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1662 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1663 cam_vector_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1664 cam_dia_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1665 cam_contour_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1666 string_tool_dia.set("0.01")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1667 waterjet_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1668 string_lead_in.set("0.05")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1669 string_quality.set("-3")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1670 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1671
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1672 def select_g():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1673 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1674 string_cam_file.set(input_file_name[0:-4]+'.gcode')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1675 cad.cam = 'g'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1676 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1677 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1678 cam_vector_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1679 string_tool_dia.set("0.0156")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1680 cam_dia_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1681 cam_contour_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1682 string_g_feed_rate.set("20")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1683 string_g_spindle_speed.set("5000")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1684 string_g_tool.set("1")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1685 integer_g_cool.set("0")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1686 g_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1687 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1688
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1689 def select_rml():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1690 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1691 string_cam_file.set(input_file_name[0:-4]+'.rml')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1692 cad.cam = 'rml'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1693 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1694 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1695 cam_vector_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1696 cam_dia_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1697 cam_contour_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1698 speed_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1699 rml_move_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1700 string_tool_dia.set("0.0156")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1701 string_xy_speed.set("4")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1702 string_z_speed.set("4")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1703 string_rml_x_move.set("1")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1704 string_rml_y_move.set("1")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1705 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1706
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1707 def select_sbp():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1708 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1709 string_cam_file.set(input_file_name[0:-4]+'.sbp')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1710 cad.cam = 'sbp'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1711 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1712 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1713 cam_vector_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1714 cam_dia_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1715 cam_contour_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1716 jog_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1717 speed_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1718 string_tool_dia.set("0.125")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1719 string_xy_speed.set("1.1")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1720 string_z_speed.set("1.1")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1721 string_jog_xy_speed.set("7")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1722 string_jog_z_speed.set("7")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1723 string_jog_z.set(".25")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1724 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1725
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1726 def select_oms():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1727 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1728 string_cam_file.set(input_file_name[0:-4]+'.oms')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1729 cad.cam = 'oms'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1730 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1731 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1732 cam_vector_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1733 cam_dia_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1734 cam_contour_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1735 excimer_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1736 string_pulse_period.set("10000")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1737 string_tool_dia.set("0.001")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1738 string_cut_vel.set("0.1")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1739 string_cut_accel.set("5.0")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1740 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1741
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1742 def select_dxf():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1743 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1744 string_cam_file.set(input_file_name[0:-4]+'.dxf')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1745 cad.cam = 'dxf'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1746 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1747 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1748 cam_vector_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1749 cam_dia_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1750 cam_contour_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1751 string_tool_dia.set("0.0")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1752 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1753
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1754 def select_uni():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1755 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1756 string_cam_file.set(input_file_name[0:-4]+'.uni')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1757 cad.cam = 'uni'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1758 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1759 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1760 cam_vector_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1761 cam_dia_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1762 cam_contour_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1763 laser_frame1.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1764 if ((cad.nz > 1) | (cad.image_r.size > 1)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1765 laser_frame2.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1766 string_laser_rate.set("500")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1767 string_laser_power.set("60")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1768 string_laser_speed.set("15")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1769 string_tool_dia.set("0.01")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1770 string_laser_min_power.set("10")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1771 string_laser_max_power.set("100")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1772 string_vector_error.set('1.1')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1773 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1774
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1775 def select_jpg():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1776 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1777 string_cam_file.set(input_file_name[0:-4]+'.jpg')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1778 cad.cam = 'jpg'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1779 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1780 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1781 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1782
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1783 def select_png():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1784 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1785 string_cam_file.set(input_file_name[0:-4]+'.png')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1786 cad.cam = 'png'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1787 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1788 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1789 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1790
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1791 def select_stl():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1792 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1793 string_cam_file.set(input_file_name[0:-4]+'.stl')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1794 cad.cam = 'stl'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1795 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1796 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1797 STL_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1798 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1799
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1800 def select_gerber():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1801 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1802 string_cam_file.set(input_file_name[0:-4]+'.grb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1803 cad.cam = 'grb'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1804 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1805 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1806 Gerber_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1807 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1808
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1809 def select_excellon():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1810 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1811 string_cam_file.set(input_file_name[0:-4]+'.drl')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1812 cad.cam = 'drl'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1813 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1814 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1815 Excellon_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1816 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1817
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1818 def select_ca():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1819 input_file_name = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1820 string_cam_file.set(input_file_name[0:-4]+'.ca')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1821 cad.cam = 'ca'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1822 cam_pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1823 cam_file_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1824 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1825
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1826 def cam_pack_forget():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1827 cam_file_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1828 cam_vector_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1829 cam_dia_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1830 cam_contour_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1831 laser_frame1.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1832 laser_frame2.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1833 laser_frame3.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1834 cut_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1835 speed_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1836 jog_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1837 rml_move_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1838 waterjet_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1839 excimer_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1840 STL_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1841 Gerber_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1842 Excellon_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1843 fill_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1844 g_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1845 send_to_frame.pack_forget()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1846
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1847 def save_cam(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1848 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1849 # write toolpath
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1850 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1851 if (cad.cam == "epi"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1852 write_epi()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1853 elif (cad.cam == "camm"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1854 write_camm()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1855 elif (cad.cam == "ps"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1856 write_ps()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1857 elif (cad.cam == "ord"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1858 write_ord()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1859 elif (cad.cam == "g"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1860 write_G()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1861 elif (cad.cam == "rml"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1862 write_rml()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1863 elif (cad.cam == "sbp"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1864 write_sbp()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1865 elif (cad.cam == "oms"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1866 write_oms()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1867 elif (cad.cam == "dxf"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1868 write_dxf()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1869 elif (cad.cam == "uni"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1870 write_uni()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1871 elif (cad.cam == "jpg"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1872 write_jpg()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1873 elif (cad.cam == "png"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1874 write_png()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1875 elif (cad.cam == "stl"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1876 write_stl()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1877 elif (cad.cam == "grb"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1878 write_gerber()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1879 elif (cad.cam == "drl"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1880 write_excellon()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1881 elif (cad.cam == "ca"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1882 write_ca()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1883 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1884 string_msg.set("unsupported output file format")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1885 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1886
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1887 def write_epi():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1888 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1889 # Epilog lasercutter output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1890 # todo: try 1200 DPI
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1891 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1892 units = 600*cad.inches_per_unit
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1893 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1894 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1895 if (integer_laser_autofocus.get() == 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1896 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1897 # init with autofocus off
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1898 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1899 file.write("%-12345X@PJL JOB NAME="+string_cam_file.get()+"\r\nE@PJL ENTER LANGUAGE=PCL\r\n&y0A&l0U&l0Z&u600D*p0X*p0Y*t600R*r0F&y50P&z50S*r6600T*r5100S*r1A*rC%1BIN;XR"+string_laser_rate.get()+";YP"+string_laser_power.get()+";ZS"+string_laser_speed.get()+";")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1900 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1901 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1902 # init with autofocus on
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1903 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1904 file.write("%-12345X@PJL JOB NAME="+string_cam_file.get()+"\r\nE@PJL ENTER LANGUAGE=PCL\r\n&y1A&l0U&l0Z&u600D*p0X*p0Y*t600R*r0F&y50P&z50S*r6600T*r5100S*r1A*rC%1BIN;XR"+string_laser_rate.get()+";YP"+string_laser_power.get()+";ZS"+string_laser_speed.get()+";")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1905 power = float(string_laser_power.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1906 min_power = float(string_laser_min_power.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1907 max_power = float(string_laser_max_power.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1908 for layer in range(len(cad.toolpaths)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1909 if ((len(cad.zwrite) > 1) & (len(cad.toolpaths[layer]) > 0)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1910 fraction = (cad.zwrite[layer]-cad.zwrite[0])/(cad.zwrite[-1]-cad.zwrite[0])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1911 layer_power = min_power + fraction*(max_power-min_power)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1912 file.write("YP%f;"%layer_power)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1913 for segment in range(len(cad.toolpaths[layer])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1914 x = int(units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][0].x+0.5)/float(cad.nx)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1915 y = int(units*(-cad.ymin - ((cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][0].y)+0.5)/float(cad.ny))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1916 file.write("PU"+str(x)+","+str(y)+";")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1917 for vertex in range(1,len(cad.toolpaths[layer][segment])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1918 x = int(units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][vertex].x+0.5)/float(cad.nx)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1919 y = int(units*(-cad.ymin - ((cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][vertex].y)+0.5)/float(cad.ny))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1920 file.write("PD"+str(x)+","+str(y)+";")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1921 file.write("%0B%1BPUE%-12345X@PJL EOJ \r\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1922 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1923 draw_toolpath()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1924 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1925 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1926
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1927 def write_camm():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1928 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1929 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1930 units = 1016*cad.inches_per_unit
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1931 file.write("PA;PA;!ST1;!FS"+string_cut_force.get()+";VS"+string_cut_velocity.get()+";")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1932 for layer in range(len(cad.toolpaths)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1933 for segment in range(len(cad.toolpaths[layer])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1934 x = int(units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][0].x+0.5)/float(cad.nx)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1935 y = int(units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][0].y)+0.5)/float(cad.ny)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1936 file.write("PU"+str(x)+","+str(y)+";")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1937 for vertex in range(1,len(cad.toolpaths[layer][segment])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1938 x = int(units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][vertex].x+0.5)/float(cad.nx)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1939 y = int(units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][vertex].y)+0.5)/float(cad.ny)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1940 file.write("PD"+str(x)+","+str(y)+";")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1941 file.write("PU0,0;")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1942 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1943 draw_toolpath()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1944 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1945 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1946
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1947 def write_ps():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1948 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1949 # Postscript output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1950 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1951 units = cad.inches_per_unit
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1952 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1953 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1954 file.write("%! cad.py output\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1955 file.write("%%%%BoundingBox: 0 0 %.3f %.3f\n"%
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1956 (72.0*(cad.xmax-cad.xmin),72.0*(cad.ymax-cad.ymin)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1957 file.write("/m {moveto} def\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1958 file.write("/l {lineto} def\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1959 file.write("72 72 scale\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1960 file.write(".005 setlinewidth\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1961 file.write("%f %f translate\n"%(0.5,0.5))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1962 for layer in range(len(cad.toolpaths)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1963 for segment in range(len(cad.toolpaths[layer])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1964 x = units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][0].x+0.5)/float(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1965 y = units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][0].y)+0.5)/float(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1966 file.write("%f %f m\n"%(x,y))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1967 for vertex in range(1,len(cad.toolpaths[layer][segment])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1968 x = units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][vertex].x+0.5)/float(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1969 y = units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][vertex].y)+0.5)/float(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1970 file.write("%f %f l\n"%(x,y))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1971 if (integer_fill.get() == 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1972 file.write("stroke\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1973 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1974 file.write("fill\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1975 file.write("showpage\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1976 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1977 draw_toolpath()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1978 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1979 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1980
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1981 def write_ord():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1982 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1983 # OMAX waterjet output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1984 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1985 units = cad.inches_per_unit
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1986 lead_in = float(string_lead_in.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1987 quality = int(string_quality.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1988 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1989 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1990 xlead = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1991 ylead = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1992 for layer in range(len(cad.toolpaths)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1993 for segment in range(len(cad.toolpaths[layer])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1994 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1995 # calculate and write lead-in
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1996 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1997 x0 = units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][0].x+0.5)/float(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1998 y0 = units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][0].y)+0.5)/float(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
1999 x1 = units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][1].x+0.5)/float(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2000 y1 = units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][1].y)+0.5)/float(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2001 dx = x1 - x0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2002 dy = y1 - y0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2003 norm_x = -dy
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2004 norm_y = dx
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2005 norm = sqrt(norm_x**2 + norm_y**2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2006 norm_x = norm_x/norm
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2007 norm_y = norm_y/norm
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2008 xlead.append(x0 + norm_x*lead_in)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2009 ylead.append(y0 + norm_y*lead_in)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2010 file.write("%f, %f, 0, %d\n"%(xlead[segment],ylead[segment],quality))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2011 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2012 # loop over segment
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2013 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2014 for vertex in range(len(cad.toolpaths[layer][segment])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2015 x = units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][vertex].x+0.5)/float(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2016 y = units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][vertex].y)+0.5)/float(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2017 file.write("%f, %f, 0, %d\n"%(x,y,quality))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2018 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2019 # write lead-out
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2020 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2021 file.write("%f, %f, 0, 0\n"%(x0,y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2022 file.write("%f, %f, 0, 0\n"%(xlead[segment],ylead[segment]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2023 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2024 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2025 # draw toolpath with lead-in/out
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2026 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2027 im.xy = Image.new("RGBX",(cad.nxplot(),cad.nyplot()),'white')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2028 im.xy_draw = ImageDraw.Draw(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2029 for layer in range(len(cad.toolpaths)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2030 for segment in range(len(cad.toolpaths[layer])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2031 x = cad.nxplot()*(cad.toolpaths[layer][segment][0].x+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2032 y = cad.nyplot()*(cad.toolpaths[layer][segment][0].y+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2033 xl = cad.nxplot()*(xlead[segment]-cad.xmin)/(cad.xmax-cad.xmin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2034 yl = cad.nyplot()-cad.nyplot()*(ylead[segment]-cad.ymin)/(cad.ymax-cad.ymin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2035 im.xy_draw.line([xl,yl,x,y],fill="black")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2036 for vertex in range(1,len(cad.toolpaths[layer][segment])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2037 xnew = cad.nxplot()*(cad.toolpaths[layer][segment][vertex].x+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2038 ynew = cad.nyplot()*(cad.toolpaths[layer][segment][vertex].y+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2039 im.xy_draw.line([x,y,xnew,ynew],fill="black")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2040 x = xnew
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2041 y = ynew
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2042 images.xy = ImageTk.PhotoImage(im.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2043 canvas_xy.create_image(cad.nplot/2,cad.nplot/2,image=images.xy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2044 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2045 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2046
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2047 def distance(x1, y1, x2, y2):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2048 return sqrt((x1-x2)**2+(y1-y2)**2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2049
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2050 def write_G():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2051 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2052 # G code output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2053 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2054 units = cad.inches_per_unit
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2055 zup = units*cad.zmax
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2056 feed_rate = float(string_g_feed_rate.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2057 spindle_speed = float(string_g_spindle_speed.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2058 coolant = integer_g_cool.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2059 tool = int(string_g_tool.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2060 if (cad.nz == 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2061 cad.zwrite = [cad.zmin]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2062 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2063 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2064 file.write("""(---------------------------------------------------------------)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2065 (---------------------------------------------------------------)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2066 (Start of sheet header)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2067 G21 (metric ftw)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2068 G90 (absolute mode)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2069 G92 X0 Y0 Z0 (zero all axes)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2070 G92 Z0.00 F150.00 (go up to printing level)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2071 M106 (pen down)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2072 G4 P120 (wait 120ms)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2073 M300 S50 (pen up)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2074 G4 P120 (wait 120ms)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2075 M18 (disengage drives)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2076 M01 (Was registration test successful?)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2077 (while drives are disengaged, adjustments can be made to position)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2078 M17 (engage drives if YES, and continue)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2079 (End of sheet header)\n""")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2080 dxy = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2081 dz = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2082 xold = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2083 yold = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2084 for layer in range(len(cad.zwrite)-1,-1,-1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2085 zdown = units*cad.zwrite[layer]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2086 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2087 # follow toolpaths CCW, for CW tool motion
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2088 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2089 unsorted_segments = cad.toolpaths[layer]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2090 sorted_segments = []
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2091 if len(unsorted_segments) > 0:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2092 sorted_segments.append(unsorted_segments.pop(0)) #starts with the first path in the list
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2093 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2094 print "empty path --- strange"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2095
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2096 while len(unsorted_segments) > 0:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2097 #find closest start to the the last sorted segment start
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2098 min_dist = 99999
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2099 min_dist_index = None
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2100 for i in range(len(unsorted_segments)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2101 dist = distance(sorted_segments[-1][0].x, sorted_segments[-1][0].y,
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2102 unsorted_segments[i][0].x, unsorted_segments[i][0].y)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2103 if dist < min_dist:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2104 min_dist = dist
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2105 min_dist_index = i
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2106
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2107 #print "min_dist: %d index: %d" % (min_dist, min_dist_index)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2108 sorted_segments.append(unsorted_segments.pop(min_dist_index))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2109
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2110 for segment in range(len(sorted_segments)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2111
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2112 x = units*(cad.xmin + (cad.xmax-cad.xmin)*(sorted_segments[segment][0].x+0.5)/float(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2113 y = units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-sorted_segments[segment][0].y)+0.5)/float(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2114 file.write("G1 X%0.4f "%x+"Y%0.4f "%y+"Z%0.4f"%zup+" F2000.00\n") # rapid motion
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2115 file.write("G1 Z%0.4f "%zdown+" F300.00\n") # linear motion
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2116 dxy += sqrt((xold-x)**2+(yold-y)**2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2117 xold = x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2118 yold = y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2119 dz += zup-zdown
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2120 for vertex in range(1,len(sorted_segments[segment])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2121 x = units*(cad.xmin + (cad.xmax-cad.xmin)*(sorted_segments[segment][vertex].x+0.5)/float(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2122 y = units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-sorted_segments[segment][vertex].y)+0.5)/float(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2123 file.write("G1 X%0.4f "%x+"Y%0.4f"%y+" F2000.00\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2124 dxy += sqrt((xold-x)**2+(yold-y)**2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2125 xold = x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2126 yold = y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2127 file.write("""(Start of sheet footer.)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2128 M107
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2129 G4 P120 (wait 120ms)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2130 G0 X0 Y0 Z15 F3500.00 (go to position for retrieving platform -- increase Z to Z25 or similar if you have trouble avoiding tool)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2131 G4 P300 (wait 300ms)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2132 M01 (Have you retrieved the print?)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2133 (machine halts until 'okay')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2134 G4 P120 (if yes continue, pause 120ms before ... )
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2135 G0 Z0 F3500.00 (return to start position of current sheet)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2136 G4 P300 (wait 300ms)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2137 M18 (disengage drives)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2138 (End of sheet footer)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2139
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2140 M01 (Printing on the next sheet?)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2141 (yes, if dropping the default .1 mm to next sheet; no, if you will print again on same sheet)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2142 G0 Z-0.10 F3500.00 (drop 0.1mm to next sheet)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2143
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2144 (Paste in further sheets below)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2145 (---------------------------------------------------------------)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2146 (---------------------------------------------------------------)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2147 """)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2148 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2149 print "Path length: %f" % dxy
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2150 time = (dxy/feed_rate + dz/feed_rate)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2151 string_send_to_time.set(" estimated time: %.1f minutes"%time)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2152 draw_toolpath()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2153 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2154 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2155
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2156 def write_rml():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2157 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2158 # Roland Modela output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2159 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2160 units = 1016*cad.inches_per_unit # 40/mm
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2161 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2162 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2163 file.write("PA;PA;VS"+string_xy_speed.get()+";!VZ"+string_z_speed.get()+";!MC1;")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2164 zup = cad.zmax
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2165 izup = int(units*zup)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2166 if (cad.nz == 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2167 cad.zwrite = [cad.zmin]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2168 xy_speed = float(string_xy_speed.get()) # mm/s
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2169 z_speed = float(string_z_speed.get()) # mm/s
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2170 dxy = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2171 dz = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2172 xold = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2173 yold = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2174 for layer in range(len(cad.zwrite)-1,-1,-1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2175 zdown = cad.zwrite[layer]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2176 izdown = int(units*zdown)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2177 file.write("!PZ"+str(izdown)+","+str(izup)+";")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2178 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2179 # follow toolpaths CCW, for CW tool motion
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2180 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2181 for segment in range(len(cad.toolpaths[layer])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2182 x = int(units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][0].x+0.5)/float(cad.nx)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2183 y = int(units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][0].y)+0.5)/float(cad.ny)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2184 file.write("PU"+str(x)+","+str(y)+";")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2185 dxy += sqrt((xold-x)**2+(yold-y)**2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2186 xold = x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2187 yold = y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2188 dz += izup-izdown
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2189 for vertex in range(1,len(cad.toolpaths[layer][segment])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2190 x = int(units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][vertex].x+0.5)/float(cad.nx)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2191 y = int(units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][vertex].y)+0.5)/float(cad.ny)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2192 file.write("PD"+str(x)+","+str(y)+";")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2193 dxy += sqrt((xold-x)**2+(yold-y)**2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2194 xold = x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2195 yold = y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2196 file.write("PU"+str(x)+","+str(y)+";!MC0;")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2197 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2198 # file padding hack for end-of-file buffering problems
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2199 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2200 for i in range(1000):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2201 file.write("!MC0;")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2202 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2203 time = ((dxy/40.0)/xy_speed + (dz/40.0)/z_speed)/60.0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2204 string_send_to_time.set(" estimated time: %.1f minutes"%time)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2205 draw_toolpath()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2206 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2207 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2208
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2209 def rml_move(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2210 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2211 # move Roland Modela
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2212 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2213 units = 1016*cad.inches_per_unit # 40/mm
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2214 x = float(string_rml_x_move.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2215 y = float(string_rml_y_move.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2216 ix = int(units*x)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2217 iy = int(units*y)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2218 filename = "move.rml"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2219 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2220 file.write("PA;PA;!PZ0,400;VS10;!VZ10;!MC0;PU%d,%d;!MC0;"%(ix,iy))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2221 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2222 send_to_file("move.rml")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2223 os.remove("move.rml")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2224
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2225 def write_sbp():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2226 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2227 # ShopBot output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2228 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2229 units = cad.inches_per_unit
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2230 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2231 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2232 file.write("SA\r\n") # set to absolute distances
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2233 file.write("SO,1,1\r\n") # set output number 1 to on
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2234 file.write("pause 2\r\n") # let spindle come up to speed
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2235 xy_speed = units*float(string_xy_speed.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2236 z_speed = units*float(string_z_speed.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2237 file.write("MS %f,%f\r\n"%(xy_speed,z_speed)) # set xy,z speed
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2238 jog_xy_speed = units*float(string_jog_xy_speed.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2239 jog_z_speed = units*float(string_jog_z_speed.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2240 file.write("JS %f,%f\r\n"%(jog_xy_speed,jog_z_speed)) # set jog xy,z speed
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2241 zup = units*float(string_jog_z.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2242 dxy = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2243 dz = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2244 xold = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2245 yold = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2246 for layer in range(len(cad.zwrite)-1,-1,-1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2247 zdown = cad.zwrite[layer]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2248 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2249 # follow toolpaths CCW, for CW tool motion
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2250 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2251 for segment in range(len(cad.toolpaths[layer])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2252 x = units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][0].x+0.5)/float(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2253 y = units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][0].y)+0.5)/float(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2254 file.write("JZ %f\r\n"%zup)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2255 file.write("J2 %f,%f\r\n"%(x,y))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2256 file.write("MZ %f\r\n"%zdown)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2257 dxy += sqrt((xold-x)**2+(yold-y)**2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2258 xold = x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2259 yold = y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2260 dz += zup-zdown
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2261 for vertex in range(1,len(cad.toolpaths[layer][segment])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2262 x = units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][vertex].x+0.5)/float(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2263 y = units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][vertex].y)+0.5)/float(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2264 file.write("M2 %f,%f\r\n"%(x,y))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2265 dxy += sqrt((xold-x)**2+(yold-y)**2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2266 xold = x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2267 yold = y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2268 file.write("JZ %f\r\n"%zup)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2269 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2270 time = (dxy/xy_speed + dz/z_speed)/60.0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2271 string_send_to_time.set(" estimated time: %.1f minutes"%time)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2272 draw_toolpath()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2273 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2274 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2275
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2276 def write_oms():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2277 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2278 # Resonetics excimer micromachining center output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2279 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2280 units = 25.4*cad.inches_per_unit
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2281 pulseperiod = float(string_pulse_period.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2282 cutvel = float(string_cut_vel.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2283 cutaccel = float(string_cut_accel.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2284 slewvel = 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2285 slewaccel = 5
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2286 settle = 100
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2287 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2288 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2289 file.write("AA LP0,0,0,0,0\n") # set origin
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2290 file.write("PP%d\n"%pulseperiod) # set pulse period
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2291 for layer in range(len(cad.toolpaths)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2292 for segment in range(len(cad.toolpaths[layer])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2293 x = units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][0].x+0.5)/float(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2294 y = units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][0].y)+0.5)/float(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2295 file.write("VL%.1f,%.1f\n"%(slewvel,slewvel))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2296 file.write("AC%.1f,%.1f\n"%(slewaccel,slewaccel))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2297 file.write("MA%f,%f\n"%(x,y))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2298 file.write("VL%.1f,%.1f\n"%(cutvel,cutvel))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2299 file.write("AC%.1f,%.1f\n"%(cutaccel,cutaccel))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2300 file.write("WT%d\n"%settle) # wait to settle
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2301 for vertex in range(1,len(cad.toolpaths[layer][segment])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2302 x = units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][vertex].x+0.5)/float(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2303 y = units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][vertex].y)+0.5)/float(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2304 file.write("CutAbs %f,%f\n"%(x,y))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2305 file.write("END\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2306 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2307 draw_toolpath()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2308 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2309 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2310
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2311 def write_dxf():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2312 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2313 # DXF output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2314 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2315 units = cad.inches_per_unit
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2316 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2317 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2318 file.write("999\nDXF written by cad.py\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2319 file.write("0\nSECTION\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2320 file.write("2\nHEADER\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2321 file.write("9\n$EXTMIN\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2322 file.write("10\n%f\n"%cad.xmin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2323 file.write("20\n%f\n"%cad.ymin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2324 file.write("9\n$EXTMAX\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2325 file.write("10\n%f\n"%cad.xmax)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2326 file.write("20\n%f\n"%cad.ymax)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2327 file.write("0\nENDSEC\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2328 file.write("0\nSECTION\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2329 file.write("2\nTABLES\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2330 file.write("0\nTABLE\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2331 file.write("2\nLTYPE\n70\n1\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2332 file.write("0\nLTYPE\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2333 file.write("2\nCONTINUOUS\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2334 file.write("70\n64\n3\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2335 file.write("Solid line\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2336 file.write("72\n65\n73\n0\n40\n0.000000\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2337 file.write("0\nENDTAB\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2338 file.write("0\nTABLE\n2\nLAYER\n70\n1\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2339 file.write("0\nLAYER\n2\ndefault\n70\n64\n62\n7\n6\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2340 file.write("CONTINUOUS\n0\nENDTAB\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2341 file.write("0\nENDSEC\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2342 file.write("0\nSECTION\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2343 file.write("2\nBLOCKS\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2344 file.write("0\nENDSEC\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2345 file.write("0\nSECTION\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2346 file.write("2\nENTITIES\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2347 for layer in range(len(cad.toolpaths)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2348 for segment in range(len(cad.toolpaths[layer])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2349 for vertex in range(1,len(cad.toolpaths[layer][segment])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2350 x0 = units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][vertex-1].x+0.5)/float(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2351 y0 = units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][vertex-1].y)+0.5)/float(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2352 x1 = units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][vertex].x+0.5)/float(cad.nx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2353 y1 = units*(cad.ymin + (cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][vertex].y)+0.5)/float(cad.ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2354 file.write("0\nLINE\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2355 file.write("10\n%f\n"%x0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2356 file.write("20\n%f\n"%y0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2357 file.write("11\n%f\n"%x1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2358 file.write("21\n%f\n"%y1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2359 file.write("0\nENDSEC\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2360 file.write("0\nEOF\n")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2361 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2362 draw_toolpath()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2363 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2364 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2365
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2366 def write_uni():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2367 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2368 # Universal lasercutter output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2369 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2370 units = 1000*cad.inches_per_unit
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2371 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2372 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2373 file.write("Z") # initialize
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2374 file.write("t%s~;"%filename) # title
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2375 file.write("IN;DF;PS0;DT~") # initialize
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2376 ppibyte = int(float(string_laser_rate.get())/10)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2377 file.write("s%c"%ppibyte) # PPI
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2378 speed_hibyte = int(648*float(string_laser_speed.get()))/256
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2379 speed_lobyte = int(648*float(string_laser_speed.get()))%256
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2380 file.write("v%c%c"%(speed_hibyte,speed_lobyte)) # speed
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2381 power = float(string_laser_power.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2382 min_power = float(string_laser_min_power.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2383 max_power = float(string_laser_max_power.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2384 power_hibyte = (320*int(power))/256
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2385 power_lobyte = (320*int(power))%256
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2386 file.write("p%c%c"%(power_hibyte,power_lobyte)) # power
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2387 file.write("a%c"%2) # air assist on high
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2388 for layer in range(len(cad.toolpaths)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2389 if ((len(cad.zwrite) > 1) & (len(cad.toolpaths[layer]) > 0)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2390 fraction = (cad.zwrite[layer]-cad.zwrite[0])/(cad.zwrite[-1]-cad.zwrite[0])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2391 layer_power = min_power + fraction*(max_power-min_power)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2392 power_hibyte = (320*int(layer_power))/256
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2393 power_lobyte = (320*int(layer_power))%256
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2394 file.write("p%c%c"%(power_hibyte,power_lobyte)) # power
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2395 for segment in range(len(cad.toolpaths[layer])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2396 x = int(units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][0].x+0.5)/float(cad.nx)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2397 y = int(units*(cad.ymin + ((cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][0].y)+0.5)/float(cad.ny))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2398 file.write("PU;PA"+str(x)+","+str(y)+";PD;")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2399 for vertex in range(1,len(cad.toolpaths[layer][segment])):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2400 x = int(units*(cad.xmin + (cad.xmax-cad.xmin)*(cad.toolpaths[layer][segment][vertex].x+0.5)/float(cad.nx)))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2401 y = int(units*(cad.ymin + ((cad.ymax-cad.ymin)*((cad.ny-cad.toolpaths[layer][segment][vertex].y)+0.5)/float(cad.ny))))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2402 file.write("PA"+str(x)+","+str(y)+";")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2403 file.write("e") # end of file
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2404 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2405 draw_toolpath()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2406 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2407 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2408
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2409 def write_jpg():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2410 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2411 # JPG image output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2412 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2413 if (cad.views == "xy"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2414 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2415 im.xy = Image.fromarray(im.intensity_xy,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2416 im_rgb_xy = im.xy.convert("RGB")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2417 dpi = int(cad.nx/float(cad.xmax-cad.xmin))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2418 im_rgb_xy.save(filename,dpi=(dpi,dpi))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2419 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2420 elif (cad.views == "xyzr"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2421 border = 5
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2422 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2423 im.xy = Image.fromarray(im.intensity_xy,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2424 im.xz = Image.fromarray(im.intensity_xz,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2425 im.yz = Image.fromarray(im.intensity_yz,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2426 im.yz = im.yz.transpose(Image.FLIP_LEFT_RIGHT)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2427 im.xyz = Image.fromarray(im.intensity_xyz,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2428 (nx,ny) = im.xy.size
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2429 ny = (nx*cad.nyplot())/cad.nxplot()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2430 nz = (nx*cad.nzplot())/cad.nxplot()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2431 im.xy = im.xy.resize((nx,ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2432 im.yz = im.yz.resize((nz,ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2433 im.xz = im.xz.resize((nx,nz))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2434 im.xyz = im.xyz.resize((nx,ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2435 im_rgb_xy = im.xy.convert("RGB")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2436 im_rgb_xz = im.xz.convert("RGB")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2437 im_rgb_yz = im.yz.convert("RGB")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2438 im_rgb_xyz = im.xyz.convert("RGB")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2439 img = Image.new("RGB",(nx+border+nx,ny+border+ny),"white")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2440 img.paste(im_rgb_xy,(0,0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2441 img.paste(im_rgb_xz,(0,border+ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2442 img.paste(im_rgb_yz,(border+nx,0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2443 img.paste(im_rgb_xyz,(border+nx,border+ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2444 img.save(filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2445 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2446 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2447 string_msg.set("unknown view")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2448
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2449 def write_png():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2450 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2451 # PNG image output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2452 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2453 if (cad.views == "xy"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2454 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2455 im.xy = Image.fromarray(im.intensity_xy,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2456 im_rgb_xy = im.xy.convert("RGB")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2457 dpi = int(cad.nx/float(cad.xmax-cad.xmin))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2458 im_rgb_xy.save(filename,dpi=(dpi,dpi))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2459 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2460 elif (cad.views == "xyzr"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2461 border = 5
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2462 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2463 im.xy = Image.fromarray(im.intensity_xy,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2464 im.xz = Image.fromarray(im.intensity_xz,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2465 im.yz = Image.fromarray(im.intensity_yz,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2466 im.yz = im.yz.transpose(Image.FLIP_LEFT_RIGHT)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2467 im.xyz = Image.fromarray(im.intensity_xyz,mode="RGBX")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2468 (nx,ny) = im.xy.size
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2469 ny = (nx*cad.nyplot())/cad.nxplot()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2470 nz = (nx*cad.nzplot())/cad.nxplot()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2471 im.xy = im.xy.resize((nx,ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2472 im.yz = im.yz.resize((nz,ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2473 im.xz = im.xz.resize((nx,nz))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2474 im.xyz = im.xyz.resize((nx,ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2475 im_rgb_xy = im.xy.convert("RGB")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2476 im_rgb_xz = im.xz.convert("RGB")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2477 im_rgb_yz = im.yz.convert("RGB")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2478 im_rgb_xyz = im.xyz.convert("RGB")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2479 img = Image.new("RGB",(nx+border+nx,ny+border+ny),"white")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2480 img.paste(im_rgb_xy,(0,0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2481 img.paste(im_rgb_xz,(0,border+ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2482 img.paste(im_rgb_yz,(border+nx,0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2483 img.paste(im_rgb_xyz,(border+nx,border+ny))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2484 img.save(filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2485 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2486 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2487 string_msg.set("unknown view")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2488
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2489 def write_stl():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2490 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2491 # STL output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2492 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2493 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2494 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2495 units = cad.inches_per_unit
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2496 x = cad.xmin+(cad.xmax-cad.xmin)*(cad.x+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2497 y = cad.ymin+(cad.ymax-cad.ymin)*(cad.y+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2498 z = cad.zmin+(cad.zmax-cad.zmin)*(cad.z+0.5)/float(cad.nz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2499 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2500 # header
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2501 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2502 file.write('cad.py')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2503 file.write('a'*74)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2504 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2505 # length
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2506 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2507 N = len(cad.x)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2508 file.write(struct.pack('L',N/3))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2509 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2510 # triangles
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2511 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2512 for i in range(0,N,3):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2513 string_msg.set("write triangle %d/%d"%(i/3,N/3))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2514 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2515 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2516 # normals
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2517 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2518 file.write(struct.pack('f',0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2519 file.write(struct.pack('f',0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2520 file.write(struct.pack('f',0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2521 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2522 # vertices
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2523 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2524 file.write(struct.pack('f',x[i]*units))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2525 file.write(struct.pack('f',y[i]*units))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2526 file.write(struct.pack('f',z[i]*units))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2527 file.write(struct.pack('f',x[i+1]*units))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2528 file.write(struct.pack('f',y[i+1]*units))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2529 file.write(struct.pack('f',z[i+1]*units))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2530 file.write(struct.pack('f',x[i+2]*units))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2531 file.write(struct.pack('f',y[i+2]*units))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2532 file.write(struct.pack('f',z[i+2]*units))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2533 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2534 # padding
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2535 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2536 file.write(struct.pack('xx'))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2537 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2538 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2539 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2540
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2541 def write_gerber():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2542 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2543 # Gerber (RS-274X) output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2544 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2545 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2546 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2547 units = cad.inches_per_unit
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2548 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2549 # write parameters
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2550 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2551 file.write("%FSLAX24Y24*%\n") # leading zeros omitted, absolute coordinates, 2.4
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2552 file.write("%MOIN*%\n") # inches units
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2553 file.write("%OFA0B0*%\n") # no offset
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2554 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2555 # find and write apertures
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2556 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2557 ixs = cad.x[::2]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2558 xs = cad.xmin+(cad.xmax-cad.xmin)*(ixs+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2559 ixe = cad.x[1::2]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2560 xe = cad.xmin+(cad.xmax-cad.xmin)*(ixe+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2561 idx = ixe - ixs
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2562 dx = xe - xs
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2563 iys = cad.y[::2]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2564 ys = cad.ymin+(cad.ymax-cad.ymin)*(iys+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2565 iye = cad.y[1::2]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2566 ye = cad.ymin+(cad.ymax-cad.ymin)*(iye+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2567 idy = iye - iys
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2568 dy = ye - ys
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2569 mins = where((idx < idy),idx,idy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2570 uniques = unique(mins)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2571 apertures = (cad.xmax-cad.xmin)*uniques/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2572 index = searchsorted(uniques,mins)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2573 for i in range(len(uniques)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2574 file.write("%%ADD%dR,%.4fX%.4f*%%\n"%(i+10,apertures[i],apertures[i]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2575 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2576 # write flashes
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2577 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2578 coords = arange(len(mins))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2579 for i in range(len(uniques)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2580 file.write("D%d*\n"%(i+10))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2581 coord = coords[index == i]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2582 delta = apertures[i]/2.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2583 ixs = (10000*(xs+delta)).astype(int32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2584 ixe = (10000*(xe-delta)).astype(int32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2585 iys = (10000*(ys+delta)).astype(int32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2586 iye = (10000*(ye-delta)).astype(int32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2587 for j in range(len(coord)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2588 n = coord[j]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2589 if (idx[n] == idy[n]):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2590 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2591 # flash
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2592 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2593 file.write('X%dY%dD03*\n'%(ixs[n],iys[n]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2594 elif (idx[n] > idy[n]):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2595 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2596 # stroke horizontal
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2597 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2598 file.write('X%dY%dD02*\n'%(ixs[n],iys[n]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2599 file.write('X%dY%dD01*\n'%(ixe[n],iys[n]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2600 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2601 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2602 # stroke vertical
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2603 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2604 file.write('X%dY%dD02*\n'%(ixs[n],iys[n]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2605 file.write('X%dY%dD01*\n'%(ixs[n],iye[n]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2606 file.write("M02*\n") # end of file
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2607 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2608 string_msg.set("wrote %s (RS-274X)"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2609 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2610
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2611 def write_excellon():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2612 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2613 # Excellon (RS-) output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2614 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2615 """
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2616 % Rewind and Stop
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2617 X#Y# Move and Drill
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2618 T# Tool Selection
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2619 M30 End of Program
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2620 M00 End of Program
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2621 R#X#Y# Repeat Hole
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2622 G05, G81 Select Drill Mode
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2623 G90 Absolute Mode
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2624 G91 Incremental Mode
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2625 G92 X#Y# Set Zero
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2626 G93 X#Y# Set Zero
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2627 M48 Program Header to first "%"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2628 M72 English-Imperial Mode
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2629
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2630 """
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2631 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2632 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2633 units = cad.inches_per_unit
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2634 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2635 # write parameters
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2636 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2637 file.write("%FSLAX24Y24*%\n") # leading zeros omitted, absolute coordinates, 2.4
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2638 file.write("%MOIN*%\n") # inches units
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2639 file.write("%OFA0B0*%\n") # no offset
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2640 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2641 # find and write apertures
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2642 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2643 ixs = cad.x[::2]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2644 xs = cad.xmin+(cad.xmax-cad.xmin)*(ixs+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2645 ixe = cad.x[1::2]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2646 xe = cad.xmin+(cad.xmax-cad.xmin)*(ixe+0.5)/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2647 idx = ixe - ixs
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2648 dx = xe - xs
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2649 iys = cad.y[::2]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2650 ys = cad.ymin+(cad.ymax-cad.ymin)*(iys+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2651 iye = cad.y[1::2]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2652 ye = cad.ymin+(cad.ymax-cad.ymin)*(iye+0.5)/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2653 idy = iye - iys
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2654 dy = ye - ys
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2655 mins = where((idx < idy),idx,idy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2656 uniques = unique(mins)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2657 apertures = (cad.xmax-cad.xmin)*uniques/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2658 index = searchsorted(uniques,mins)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2659 for i in range(len(uniques)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2660 file.write("%%ADD%dR,%.4fX%.4f*%%\n"%(i+10,apertures[i],apertures[i]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2661 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2662 # write flashes
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2663 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2664 coords = arange(len(mins))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2665 for i in range(len(uniques)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2666 file.write("D%d*\n"%(i+10))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2667 coord = coords[index == i]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2668 delta = apertures[i]/2.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2669 ixs = (10000*(xs+delta)).astype(int32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2670 ixe = (10000*(xe-delta)).astype(int32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2671 iys = (10000*(ys+delta)).astype(int32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2672 iye = (10000*(ye-delta)).astype(int32)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2673 for j in range(len(coord)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2674 n = coord[j]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2675 if (idx[n] == idy[n]):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2676 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2677 # flash
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2678 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2679 file.write('X%dY%dD03*\n'%(ixs[n],iys[n]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2680 elif (idx[n] > idy[n]):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2681 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2682 # stroke horizontal
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2683 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2684 file.write('X%dY%dD02*\n'%(ixs[n],iys[n]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2685 file.write('X%dY%dD01*\n'%(ixe[n],iys[n]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2686 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2687 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2688 # stroke vertical
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2689 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2690 file.write('X%dY%dD02*\n'%(ixs[n],iys[n]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2691 file.write('X%dY%dD01*\n'%(ixs[n],iye[n]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2692 file.write("M02*\n") # end of file
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2693 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2694 string_msg.set("wrote %s (RS-274X)"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2695 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2696
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2697 def write_ca():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2698 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2699 # CA output
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2700 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2701 filename = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2702 file = open(filename, 'wb')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2703 file.write(chr(0xB9)) # magic number 0xB9
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2704 file.write(chr(ca.nx/256)) # x size
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2705 file.write(chr(ca.nx%256)) #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2706 file.write(chr(ca.ny/256)) # y size
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2707 file.write(chr(ca.ny%256)) #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2708 file.write(chr(4)) # LED sub-array x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2709 file.write(chr(2)) # LED sub-array y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2710 for y in range(ca.nx):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2711 for x in range(ca.nx):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2712 if (ca.in1[y,x] == ca.E):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2713 config = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2714 elif (ca.in1[y,x] == ca.NE):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2715 config = 1
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2716 elif (ca.in1[y,x] == ca.N):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2717 config = 2
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2718 elif (ca.in1[y,x] == ca.NW):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2719 config = 3
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2720 elif (ca.in1[y,x] == ca.W):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2721 config = 4
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2722 elif (ca.in1[y,x] == ca.SW):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2723 config = 5
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2724 elif (ca.in1[y,x] == ca.S):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2725 config = 6
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2726 elif (ca.in1[y,x] == ca.SE):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2727 config = 7
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2728 elif (ca.in1[y,x] == ca.empty): # XOR W W for empty
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2729 config = 4
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2730 if (ca.in2[y,x] == ca.E):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2731 config += 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2732 elif (ca.in2[y,x] == ca.NE):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2733 config += (1 << 3)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2734 elif (ca.in2[y,x] == ca.N):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2735 config += (2 << 3)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2736 elif (ca.in2[y,x] == ca.NW):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2737 config += (3 << 3)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2738 elif (ca.in2[y,x] == ca.W):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2739 config += (4 << 3)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2740 elif (ca.in2[y,x] == ca.SW):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2741 config += (5 << 3)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2742 elif (ca.in2[y,x] == ca.S):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2743 config += (6 << 3)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2744 elif (ca.in2[y,x] == ca.SE):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2745 config += (7 << 3)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2746 elif (ca.in2[y,x] == ca.empty): # XOR W W for empty
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2747 config += (4 << 3)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2748 if (ca.gates[y,x] == ca.AND):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2749 config += 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2750 elif (ca.gates[y,x] == ca.OR):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2751 config += (1 << 6)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2752 elif (ca.gates[y,x] == ca.XOR):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2753 config += (2 << 6)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2754 elif (ca.gates[y,x] == ca.NAND):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2755 config += (3 << 6)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2756 elif (ca.gates[y,x] == ca.empty): # XOR W W for empty
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2757 config += (2 << 6)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2758 file.write(chr(config))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2759 for y in range(ca.ny):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2760 for x in range((ca.nx/8)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2761 state = \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2762 (ca.states[y,8*x+0] << 7) \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2763 + (ca.states[y,8*x+1] << 6) \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2764 + (ca.states[y,8*x+2] << 5) \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2765 + (ca.states[y,8*x+3] << 4) \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2766 + (ca.states[y,8*x+4] << 3) \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2767 + (ca.states[y,8*x+5] << 2) \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2768 + (ca.states[y,8*x+6] << 1) \
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2769 + (ca.states[y,8*x+7] << 0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2770 file.write(chr(state))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2771 if ((ca.nx%8) != 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2772 x = cad.nx/8
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2773 state = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2774 for i in range((ca.nx%8)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2775 state += (ca.states[y,8*x+i] << (7-i))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2776 file.write(chr(state))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2777 file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2778 string_msg.set("wrote %s"%filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2779 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2780
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2781 def msg_xy(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2782 x = (cad.xmin+cad.xmax)/2. + (cad.xmax-cad.xmin)*(1+event.x-cad.nplot/2.)/float(cad.nxplot())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2783 y = (cad.ymin+cad.ymax)/2. + (cad.ymin-cad.ymax)*(1+event.y-cad.nplot/2.)/float(cad.nyplot())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2784 string_msg.set("x = %.2f y = %.2f"%(x,y))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2785
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2786 def msg_yz(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2787 if (cad.nz > 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2788 y = (cad.ymin+cad.ymax)/2. + (cad.ymin-cad.ymax)*(1+event.y-cad.nplot/2.)/float(cad.nyplot())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2789 z = (cad.zmin+cad.zmax)/2. + (cad.zmin-cad.zmax)*(1+event.x-cad.nplot/2.)/float(cad.nzplot())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2790 string_msg.set("y = %.2f z = %.2f"%(y,z))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2791 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2792 string_msg.set("")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2793
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2794 def msg_xz(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2795 if (cad.nz > 1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2796 x = (cad.xmin+cad.xmax)/2. + (cad.xmax-cad.xmin)*(1+event.x-cad.nplot/2.)/float(cad.nxplot())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2797 z = (cad.zmin+cad.zmax)/2. + (cad.zmin-cad.zmax)*(1+event.y-cad.nplot/2.)/float(cad.nzplot())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2798 string_msg.set("x = %.2f z = %.2f"%(x,z))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2799 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2800 string_msg.set("")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2801
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2802 def msg_nomsg(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2803 string_msg.set("")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2804
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2805 def image_min_x(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2806 cad.xmin = float(string_image_xmin.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2807 xwidth = float(string_image_xwidth.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2808 cad.xmax = cad.xmin + xwidth
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2809 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2810
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2811 def image_min_y(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2812 cad.ymin = float(string_image_ymin.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2813 yheight = float(string_image_yheight.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2814 cad.ymax = cad.ymin + yheight
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2815 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2816
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2817 def image_scale_x(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2818 yheight = float(string_image_yheight.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2819 xwidth = yheight*cad.nx/float(cad.ny)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2820 cad.xmax = cad.xmin + xwidth
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2821 string_image_xwidth.set(str(xwidth))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2822 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2823
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2824 def image_scale_y(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2825 xwidth = float(string_image_xwidth.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2826 yheight = xwidth*cad.ny/float(cad.nx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2827 cad.ymax = cad.ymin + yheight
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2828 string_image_yheight.set(str(yheight))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2829 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2830
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2831 def send_to(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2832 save_cam(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2833 cam_file_name = string_cam_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2834 send_to_file(cam_file_name)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2835
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2836 def send_to_file(cam_file_name):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2837 cad_path = os.path.dirname(sys.argv[0])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2838 if (sys.argv[0] == "cad.py"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2839 cfg_path = "cad.cfg"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2840 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2841 cfg_path = os.path.dirname(sys.argv[0])+"/cad.cfg"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2842 try:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2843 config_file = open(cfg_path, 'r')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2844 except:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2845 string_msg.set(cfg_path+" not found")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2846 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2847 return()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2848 dot = find(cam_file_name,".")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2849 while 1:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2850 new_dot = find(cam_file_name,".",dot+1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2851 if (new_dot == -1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2852 break
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2853 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2854 dot = new_dot
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2855 suffix = cam_file_name[dot+1:]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2856 while 1:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2857 line = config_file.readline()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2858 if (find(line,suffix) == 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2859 string_msg.set("sending "+cam_file_name+" ...")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2860 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2861 quote1 = find(line,"'")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2862 quote2 = find(line,"'",quote1+1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2863 cmd = line[(quote1+1):quote2]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2864 if (os.name == 'nt'):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2865 cam_file_name = replace(cam_file_name,'/','\\')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2866 cmd = replace(cmd,'file','"'+cam_file_name+'"')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2867 os.system(cmd)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2868 string_msg.set(cam_file_name+" sent")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2869 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2870 config_file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2871 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2872 return()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2873 elif (line == ""):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2874 string_msg.set(suffix+" driver not defined in "+cfg_path)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2875 config_file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2876 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2877 return()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2878
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2879 def resize_window(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2880 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2881 # resize drawing windows
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2882 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2883 cad.nplot = int(string_window_size.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2884 cad.view(cad.views)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2885 render()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2886
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2887 def resize_editor(event):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2888 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2889 # resize editing windows
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2890 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2891 cad.editor_height = int(string_editor_height.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2892 widget_cad_text.config(height=cad.editor_height)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2893 cad.editor_width = int(string_editor_width.get())
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2894 widget_cad_text.config(width=cad.editor_width)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2895 widget_function_text.config(width=cad.editor_width)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2896 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2897
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2898 def reload():
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2899 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2900 # reload input file
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2901 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2902 filename = string_input_file.get()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2903 if (find(filename,'.cad') != -1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2904 cad_load(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2905 elif ((find(filename,'.jpg') != -1) | (find(filename,'.JPG') != -1) |
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2906 (find(filename,'.png') != -1) | (find(filename,'.PNG') != -1) |
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2907 (find(filename,'.gif') != -1) | (find(filename,'.GIF') != -1)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2908 widget_cad_text.delete("1.0",END)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2909 image_load(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2910 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2911 string_msg.set("unsupported input file format")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2912 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2913
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2914 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2915 # set up GUI
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2916 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2917 root = Tk()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2918 root.title('cad.py')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2919 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2920 # message frame
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2921 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2922 msg_frame = Frame(root)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2923 string_msg = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2924 widget_msg = Label(msg_frame, textvariable = string_msg)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2925 widget_msg.pack(side='right')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2926 Label(msg_frame, text=" ").pack(side='right')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2927 widget_stop = Button(msg_frame, text='stop', borderwidth=2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2928 widget_stop.bind('<Button-1>',render_stop)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2929 msg_frame.grid(row=0,column=0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2930 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2931 # size frame
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2932 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2933 size_frame = Frame(root)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2934 Label(size_frame, text="window size: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2935 string_window_size = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2936 string_window_size.set(str(cad.nplot))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2937 widget_window_size = Entry(size_frame, width=4, bg='white', textvariable=string_window_size)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2938 widget_window_size.bind('<Return>',resize_window)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2939 widget_window_size.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2940 Label(size_frame, text=" editor width: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2941 string_editor_width = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2942 string_editor_width.set(str(cad.editor_width))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2943 widget_editor_width = Entry(size_frame, width=3, bg='white', textvariable=string_editor_width)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2944 widget_editor_width.bind('<Return>',resize_editor)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2945 widget_editor_width.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2946 Label(size_frame, text=" height: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2947 string_editor_height = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2948 string_editor_height.set(str(cad.editor_height))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2949 widget_editor_height = Entry(size_frame, width=3, bg='white', textvariable=string_editor_height)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2950 widget_editor_height.bind('<Return>',resize_editor)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2951 widget_editor_height.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2952 size_frame.grid(row=0,column=1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2953 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2954 # view frame
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2955 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2956 view_frame2 = Frame(root)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2957 view_frame3 = Frame(root)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2958 canvas_xy = Canvas(view_frame3)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2959 canvas_xz = Canvas(view_frame3)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2960 canvas_yz = Canvas(view_frame3)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2961 canvas_xyz = Canvas(view_frame3)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2962 cad.view('xyzr')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2963 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2964 # I/O frame
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2965 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2966 io_frame = Frame(root)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2967 io_frame.grid(row=2,column=1,sticky=N)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2968 #cad_frame.bind('<Motion>',msg_nomsg)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2969 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2970 # input frame
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2971 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2972 input_frame = Frame(io_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2973 input_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2974 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2975 # .cad editor
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2976 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2977 editor_frame = Frame(input_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2978 widget_text_yscrollbar = Scrollbar(editor_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2979 widget_cad_text = Text(editor_frame, bg='white', bd=5, width=cad.editor_width, height=cad.editor_height, yscrollcommand=widget_text_yscrollbar.set)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2980 widget_cad_text.grid(row=1,column=1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2981 widget_text_yscrollbar.grid(row=1,column=2,sticky=N+S)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2982 widget_text_yscrollbar.config(command=widget_cad_text.yview)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2983 widget_cad_text.bind('<Motion>',msg_nomsg)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2984 editor_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2985 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2986 # input file
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2987 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2988 cad_input_frame = Frame(input_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2989 widget_input_file = Button(cad_input_frame, text="input:",command=input_open)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2990 widget_input_file.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2991 string_input_file = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2992 string_input_file.set('out.cad')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2993 widget_cad = Entry(cad_input_frame, width=17, bg='white', textvariable=string_input_file)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2994 widget_cad.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2995 Label(cad_input_frame, text=" ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2996 widget_cad_save = Button(cad_input_frame, text="save")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2997 widget_cad_save.bind('<Button-1>',cad_save)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2998 widget_cad_save.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
2999 Label(cad_input_frame, text=" ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3000 widget_reload = Button(cad_input_frame, text="reload",command=reload)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3001 widget_reload.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3002 cad_input_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3003 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3004 # image x
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3005 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3006 image_x_frame = Frame(input_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3007 Label(image_x_frame, text="x min: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3008 string_image_xmin = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3009 widget_image_xmin = Entry(image_x_frame, width=6, bg='white', textvariable=string_image_xmin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3010 widget_image_xmin.bind('<Return>',image_min_x)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3011 widget_image_xmin.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3012 Label(image_x_frame, text=" x width: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3013 string_image_xwidth = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3014 widget_image_xwidth = Entry(image_x_frame, width=6, bg='white', textvariable=string_image_xwidth)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3015 widget_image_xwidth.bind('<Return>',image_scale_y)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3016 widget_image_xwidth.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3017 string_image_nx = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3018 Label(image_x_frame, textvariable = string_image_nx).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3019 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3020 # image y
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3021 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3022 image_y_frame = Frame(input_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3023 Label(image_y_frame, text="y min: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3024 string_image_ymin = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3025 widget_image_ymin = Entry(image_y_frame, width=6, bg='white', textvariable=string_image_ymin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3026 widget_image_ymin.bind('<Return>',image_min_y)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3027 widget_image_ymin.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3028 Label(image_y_frame, text=" y height: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3029 string_image_yheight = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3030 widget_image_yheight = Entry(image_y_frame, width=6, bg='white', textvariable=string_image_yheight)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3031 widget_image_yheight.bind('<Return>',image_scale_x)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3032 widget_image_yheight.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3033 string_image_ny = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3034 Label(image_y_frame, textvariable = string_image_ny).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3035 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3036 # image z
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3037 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3038 image_z_frame = Frame(input_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3039 Label(image_z_frame, text="z min: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3040 string_image_zmin = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3041 widget_image_zmin = Entry(image_z_frame, width=6, bg='white', textvariable=string_image_zmin)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3042 widget_image_zmin.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3043 Label(image_z_frame, text=" z max: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3044 string_image_zmax = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3045 widget_image_zmax = Entry(image_z_frame, width=6, bg='white', textvariable=string_image_zmax)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3046 widget_image_zmax.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3047 Label(image_z_frame, text=" nz: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3048 string_image_nz = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3049 widget_image_nz = Entry(image_z_frame, width=6, bg='white', textvariable=string_image_nz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3050 widget_image_nz.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3051 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3052 # image intensity
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3053 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3054 image_intensity_frame = Frame(input_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3055 Label(image_intensity_frame, text="intensity min: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3056 string_image_min = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3057 widget_image_min = Entry(image_intensity_frame, width=6, bg='white', textvariable=string_image_min)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3058 widget_image_min.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3059 Label(image_intensity_frame, text=" intensity max: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3060 string_image_max = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3061 widget_image_max = Entry(image_intensity_frame, width=6, bg='white', textvariable=string_image_max)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3062 widget_image_max.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3063 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3064 # image units
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3065 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3066 image_units_frame = Frame(input_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3067 Label(image_units_frame, text="inches per unit: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3068 string_image_units = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3069 widget_image_units = Entry(image_units_frame, width=6, bg='white', textvariable=string_image_units)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3070 widget_image_units.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3071 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3072 # image invert
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3073 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3074 image_invert_frame = Frame(input_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3075 Label(image_invert_frame, text=" ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3076 widget_image_invert = Button(image_invert_frame, text="invert image")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3077 widget_image_invert.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3078 widget_image_invert.bind('<Button-1>',invert_image)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3079 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3080 # output frame
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3081 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3082 output_frame = Frame(io_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3083 output_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3084 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3085 # controls
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3086 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3087 control_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3088 widget_render = Button(control_frame, text="render")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3089 widget_render.bind('<Button-1>',render_button)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3090 widget_render.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3091 Label(control_frame, text=" ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3092 canvas_logo = Canvas(control_frame, width=26, height=26, background="white")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3093 canvas_logo.create_oval(2,2,8,8,fill="red",outline="")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3094 canvas_logo.create_rectangle(11,2,17,8,fill="blue",outline="")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3095 canvas_logo.create_rectangle(20,2,26,8,fill="blue",outline="")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3096 canvas_logo.create_rectangle(2,11,8,17,fill="blue",outline="")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3097 canvas_logo.create_oval(10,10,16,16,fill="red",outline="")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3098 canvas_logo.create_rectangle(20,11,26,17,fill="blue",outline="")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3099 canvas_logo.create_rectangle(2,20,8,26,fill="blue",outline="")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3100 canvas_logo.create_rectangle(11,20,17,26,fill="blue",outline="")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3101 canvas_logo.create_rectangle(20,20,26,26,fill="blue",outline="")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3102 canvas_logo.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3103 control_text = " cad.py (%s) "%DATE
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3104 Label(control_frame, text=control_text).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3105 widget_cam = Button(control_frame, text="cam")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3106 widget_cam.bind('<Button-1>',cam)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3107 widget_cam.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3108 Label(control_frame, text=" ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3109 widget_quit = Button(control_frame, text="quit", command='exit')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3110 widget_quit.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3111 control_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3112 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3113 # function string
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3114 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3115 function_string_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3116 Label(function_string_frame, text="function:").grid(row=1,column=1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3117 widget_function_yscrollbar = Scrollbar(function_string_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3118 widget_function_text = Text(function_string_frame, bg='white', bd=5, width=cad.editor_width, height=12, yscrollcommand=widget_function_yscrollbar.set, state=DISABLED)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3119 widget_function_text.grid(row=2,column=1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3120 widget_function_yscrollbar.grid(row=2,column=2,sticky=N+S)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3121 widget_function_yscrollbar.config(command=widget_function_text.yview)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3122 function_string_frame.pack()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3123 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3124 # CAM file
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3125 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3126 cam_file_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3127 widget_cam_menu_button = Menubutton(cam_file_frame,text="output format", relief=RAISED)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3128 widget_cam_menu_button.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3129 widget_cam_menu = Menu(widget_cam_menu_button)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3130 widget_cam_menu.add_command(label='.epi (Epilog)',command=select_epi)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3131 widget_cam_menu.add_command(label='.camm (CAMM)',command=select_camm)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3132 widget_cam_menu.add_command(label='.rml (Modela)',command=select_rml)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3133 widget_cam_menu.add_command(label='.sbp (ShopBot)',command=select_sbp)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3134 widget_cam_menu.add_command(label='.gcode (Gcode)',command=select_g)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3135 widget_cam_menu.add_command(label='.ps (Postscript)',command=select_ps)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3136 widget_cam_menu.add_command(label='.ord (OMAX)',command=select_ord)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3137 widget_cam_menu.add_command(label='.oms (Resonetics)',command=select_oms)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3138 widget_cam_menu.add_command(label='.grb (Gerber)',command=select_gerber)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3139 widget_cam_menu.add_command(label='.drl (Excellon)',command=select_excellon)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3140 widget_cam_menu.add_command(label='.stl (STL)',command=select_stl)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3141 widget_cam_menu.add_command(label='.dxf (DXF)',command=select_dxf)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3142 widget_cam_menu.add_command(label='.jpg (JPG)',command=select_jpg)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3143 widget_cam_menu.add_command(label='.png (PNG)',command=select_png)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3144 widget_cam_menu.add_command(label='.ca (CA)',command=select_ca)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3145 widget_cam_menu.add_command(label='.uni (Universal)',command=select_uni)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3146 widget_cam_menu.add_command(label='.epb (Epilog bitmap)',state=DISABLED)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3147 widget_cam_menu_button['menu'] = widget_cam_menu
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3148 Label(cam_file_frame, text=" output file: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3149 string_cam_file = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3150 widget_cam_file = Entry(cam_file_frame, width=12, bg='white', textvariable=string_cam_file)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3151 widget_cam_file.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3152 Label(cam_file_frame, text=" ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3153 widget_cam_save = Button(cam_file_frame, text="save")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3154 widget_cam_save.bind('<Button-1>',save_cam)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3155 widget_cam_save.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3156 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3157 # vectorization
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3158 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3159 cam_vector_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3160 Label(cam_vector_frame, text="maximum vector fit error (lattice units): ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3161 string_vector_error = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3162 string_vector_error.set('.75')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3163 widget_vector_error = Entry(cam_vector_frame, width=6, bg='white', textvariable=string_vector_error)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3164 widget_vector_error.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3165 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3166 # tool
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3167 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3168 cam_dia_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3169 Label(cam_dia_frame, text="tool diameter: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3170 string_tool_dia = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3171 string_tool_dia.set('0')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3172 widget_tool_dia = Entry(cam_dia_frame, width=6, bg='white', textvariable=string_tool_dia)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3173 widget_tool_dia.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3174 Label(cam_dia_frame, text=" tool overlap: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3175 string_tool_overlap = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3176 string_tool_overlap.set('0.5')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3177 widget_tool_overlap = Entry(cam_dia_frame, width=6, bg='white', textvariable=string_tool_overlap)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3178 widget_tool_overlap.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3179 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3180 # contour
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3181 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3182 cam_contour_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3183 Label(cam_contour_frame, text=" # contours (-1 for max): ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3184 string_num_contours = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3185 string_num_contours.set('0')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3186 widget_num_contours = Entry(cam_contour_frame, width=6, bg='white', textvariable=string_num_contours)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3187 widget_num_contours.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3188 Label(cam_contour_frame, text=" ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3189 widget_cam_contour = Button(cam_contour_frame, text="contour")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3190 widget_cam_contour.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3191 widget_cam_contour.bind('<Button-1>',contour)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3192 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3193 # laser power
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3194 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3195 laser_frame1 = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3196 Label(laser_frame1, text=" power:").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3197 string_laser_power = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3198 Entry(laser_frame1, width=6, bg='white', textvariable=string_laser_power).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3199 Label(laser_frame1, text=" speed:").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3200 string_laser_speed = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3201 Entry(laser_frame1, width=6, bg='white', textvariable=string_laser_speed).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3202 Label(laser_frame1, text=" rate: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3203 string_laser_rate = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3204 Entry(laser_frame1, width=6, bg='white', textvariable=string_laser_rate).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3205 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3206 # power range
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3207 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3208 laser_frame2 = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3209 Label(laser_frame2, text=" min power:").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3210 string_laser_min_power = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3211 Entry(laser_frame2, width=6, bg='white', textvariable=string_laser_min_power).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3212 Label(laser_frame2, text="% max power:").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3213 string_laser_max_power = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3214 Entry(laser_frame2, width=6, bg='white', textvariable=string_laser_max_power).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3215 Label(laser_frame2, text="%").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3216 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3217 # autofocus
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3218 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3219 laser_frame3 = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3220 integer_laser_autofocus = IntVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3221 widget_autofocus = Checkbutton(laser_frame3, text="Auto Focus", variable=integer_laser_autofocus).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3222 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3223 # cutting
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3224 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3225 cut_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3226 Label(cut_frame, text="force: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3227 string_cut_force = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3228 Entry(cut_frame, width=6, bg='white', textvariable=string_cut_force).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3229 Label(cut_frame, text=" velocity:").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3230 string_cut_velocity = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3231 Entry(cut_frame, width=6, bg='white', textvariable=string_cut_velocity).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3232 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3233 # speed
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3234 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3235 speed_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3236 Label(speed_frame, text="xy speed:").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3237 string_xy_speed = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3238 Entry(speed_frame, width=4, bg='white', textvariable=string_xy_speed).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3239 Label(speed_frame, text=" z speed:").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3240 string_z_speed = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3241 Entry(speed_frame, width=4, bg='white', textvariable=string_z_speed).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3242 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3243 # jog
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3244 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3245 jog_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3246 Label(jog_frame, text="jog xy speed:").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3247 string_jog_xy_speed = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3248 Entry(jog_frame, width=4, bg='white', textvariable=string_jog_xy_speed).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3249 Label(jog_frame, text=" z speed:").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3250 string_jog_z_speed = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3251 Entry(jog_frame, width=4, bg='white', textvariable=string_jog_z_speed).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3252 Label(jog_frame, text=" z:").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3253 string_jog_z = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3254 Entry(jog_frame, width=4, bg='white', textvariable=string_jog_z).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3255 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3256 # RML move
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3257 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3258 rml_move_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3259 Label(rml_move_frame, text="x: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3260 string_rml_x_move = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3261 Entry(rml_move_frame, width=6, bg='white', textvariable=string_rml_x_move).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3262 Label(rml_move_frame, text=" y: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3263 string_rml_y_move = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3264 Entry(rml_move_frame, width=6, bg='white', textvariable=string_rml_y_move).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3265 Label(rml_move_frame, text=" ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3266 widget_rml_move = Button(rml_move_frame, text="move")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3267 widget_rml_move.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3268 widget_rml_move.bind('<Button-1>',rml_move)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3269 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3270 # G codes
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3271 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3272 g_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3273 Label(g_frame, text=" feed rate:").pack(side="left")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3274 string_g_feed_rate = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3275 Entry(g_frame, width=6, textvariable=string_g_feed_rate).pack(side="left")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3276 Label(g_frame, text=" spindle speed:").pack(side="left")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3277 string_g_spindle_speed = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3278 Entry(g_frame, width=6, textvariable=string_g_spindle_speed).pack(side="left")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3279 Label(g_frame, text=" tool:").pack(side="left")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3280 string_g_tool = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3281 Entry(g_frame, width=3, textvariable=string_g_tool).pack(side="left")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3282 integer_g_cool = IntVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3283 widget_g_cool = Checkbutton(g_frame, text="coolant", variable=integer_g_cool)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3284 widget_g_cool.pack(side="left")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3285 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3286 # waterjet
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3287 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3288 waterjet_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3289 Label(waterjet_frame,text="lead-in/out: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3290 string_lead_in = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3291 widget_lead_in = Entry(waterjet_frame, width=4, bg='white', textvariable=string_lead_in)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3292 widget_lead_in.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3293 Label(waterjet_frame,text="quality: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3294 string_quality = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3295 widget_quality = Entry(waterjet_frame, width=4, bg='white', textvariable=string_quality)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3296 widget_quality.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3297 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3298 # excimer
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3299 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3300 excimer_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3301 Label(excimer_frame,text="period (usec): ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3302 string_pulse_period = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3303 widget_pulse_period = Entry(excimer_frame, width=5, bg='white', textvariable=string_pulse_period)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3304 widget_pulse_period.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3305 Label(excimer_frame,text="velocity: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3306 string_cut_vel = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3307 widget_cut_vel = Entry(excimer_frame, width=4, bg='white', textvariable=string_cut_vel)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3308 widget_cut_vel.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3309 Label(excimer_frame,text="acceleration: ").pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3310 string_cut_accel = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3311 widget_cut_accel = Entry(excimer_frame, width=4, bg='white', textvariable=string_cut_accel)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3312 widget_cut_accel.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3313 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3314 # STL
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3315 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3316 STL_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3317 widget_STL_triangulate = Button(STL_frame, text="triangulate")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3318 widget_STL_triangulate.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3319 widget_STL_triangulate.bind('<Button-1>',triangulate)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3320 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3321 # Gerber
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3322 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3323 Gerber_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3324 widget_Gerber_convert = Button(Gerber_frame, text="convert")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3325 widget_Gerber_convert.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3326 widget_Gerber_convert.bind('<Button-1>',flash)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3327 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3328 # Excellon
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3329 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3330 Excellon_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3331 widget_Excellon_convert = Button(Excellon_frame, text="convert")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3332 widget_Excellon_convert.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3333 widget_Excellon_convert.bind('<Button-1>',flash)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3334 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3335 # filling
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3336 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3337 fill_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3338 integer_fill = IntVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3339 widget_fill = Checkbutton(fill_frame, text="fill polygons", variable=integer_fill).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3340 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3341 # send to
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3342 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3343 send_to_frame = Frame(output_frame)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3344 widget_send_to = Button(send_to_frame, text="send to machine")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3345 widget_send_to.bind('<Button-1>',send_to)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3346 widget_send_to.pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3347 string_send_to_time = StringVar()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3348 string_send_to_time.set("")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3349 Label(send_to_frame,textvariable=string_send_to_time).pack(side='left')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3350
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3351 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3352 # define .cad template
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3353 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3354 cad_template = """#
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3355 # .cad template
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3356 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3357
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3358 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3359 # define shapes and transformation
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3360 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3361 # circle(x0, y0, r)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3362 # cylinder(x0, y0, z0, z1, r)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3363 # cone(x0, y0, z0, z1, r0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3364 # sphere(x0, y0, z0, r)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3365 # torus(x0, y0, z0, r0, r1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3366 # rectangle(x0, x1, y0, y1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3367 # cube(x0, x1, y0, y1, z0, z1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3368 # right_triangle(x0, y0, h)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3369 # triangle(x0, y0, x1, y1, x2, y2) (points in clockwise order)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3370 # pyramid(x0, x1, y0, y1, z0, z1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3371 # function(Z_of_XY)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3372 # functions(upper_Z_of_XY,lower_Z_of_XY)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3373 # add(part1, part2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3374 # subtract(part1, part2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3375 # intersect(part1, part2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3376 # move(part,dx,dy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3377 # translate(part,dx,dy,dz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3378 # rotate(part, angle)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3379 # rotate_x(part, angle)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3380 # rotate_y(part, angle)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3381 # rotate_z(part, angle)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3382 # rotate_90(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3383 # rotate_180(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3384 # rotate_270(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3385 # reflect_x(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3386 # reflect_y(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3387 # reflect_z(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3388 # reflect_xy(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3389 # reflect_xz(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3390 # reflect_yz(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3391 # scale_x(part, x0, sx)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3392 # scale_y(part, y0, sy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3393 # scale_z(part, z0, sz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3394 # scale_xy(part, x0, y0, sxy)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3395 # scale_xyz(part, x0, y0, z0, sxyz)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3396 # coscale_x_y(part, x0, y0, y1, angle0, angle1, amplitude, offset)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3397 # coscale_x_z(part, x0, z0, z1, angle0, angle1, amplitude, offset)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3398 # coscale_xy_z(part, x0, y0, z0, z1, angle0, angle1, amplitude, offset)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3399 # taper_x_y(part, x0, y0, y1, s0, s1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3400 # taper_x_z(part, x0, z0, z1, s0, s1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3401 # taper_xy_z(part, x0, y0, z0, z1, s0, s1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3402 # shear_x_y(part, y0, y1, dx0, dx1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3403 # shear_x_z(part, z0, z1, dx0, dx1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3404 # (more to come)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3405
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3406 def circle(x0, y0, r):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3407 part = "(((X-x0)**2 + (Y-y0)**2) <= r**2)"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3408 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3409 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3410 part = replace(part,'r',str(r))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3411 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3412
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3413 def cylinder(x0, y0, z0, z1, r):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3414 part = "(((X-x0)**2 + (Y-y0)**2 <= r**2) & (Z >= z0) & (Z <= z1))"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3415 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3416 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3417 part = replace(part,'z0',str(z0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3418 part = replace(part,'z1',str(z1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3419 part = replace(part,'r',str(r))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3420 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3421
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3422 def cone(x0, y0, z0, z1, r0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3423 part = cylinder(x0, y0, z0, z1, r0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3424 part = taper_xy_z(part, x0, y0, z0, z1, 1.0, 0.0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3425 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3426
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3427 def sphere(x0, y0, z0, r):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3428 part = "(((X-x0)**2 + (Y-y0)**2 + (Z-z0)**2) <= r**2)"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3429 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3430 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3431 part = replace(part,'z0',str(z0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3432 part = replace(part,'r',str(r))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3433 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3434
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3435 def torus(x0, y0, z0, r0, r1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3436 part = "(((r0 - sqrt((X-x0)**2 + (Y-y0)**2))**2 + (Z-z0)**2) <= r1**2)"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3437 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3438 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3439 part = replace(part,'z0',str(z0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3440 part = replace(part,'r0',str(r0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3441 part = replace(part,'r1',str(r1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3442 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3443
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3444 def rectangle(x0, x1, y0, y1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3445 part = "((X >= x0) & (X <= x1) & (Y >= y0) & (Y <= y1))"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3446 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3447 part = replace(part,'x1',str(x1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3448 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3449 part = replace(part,'y1',str(y1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3450 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3451
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3452 def cube(x0, x1, y0, y1, z0, z1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3453 part = "((X >= x0) & (X <= x1) & (Y >= y0) & (Y <= y1) & (Z >= z0) & (Z <= z1))"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3454 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3455 part = replace(part,'x1',str(x1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3456 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3457 part = replace(part,'y1',str(y1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3458 part = replace(part,'z0',str(z0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3459 part = replace(part,'z1',str(z1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3460 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3461
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3462 def right_triangle(x0, y0, h):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3463 part = "((X > x0) & (X < x0 + h - (Y-y0)) & (Y > y0))"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3464 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3465 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3466 part = replace(part,'h',str(h))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3467 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3468
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3469 def triangle(x0, y0, x1, y1, x2, y2): # points in clockwise order
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3470 part = "((((y1-y0)*(X-x0)-(x1-x0)*(Y-y0)) >= 0) & (((y2-y1)*(X-x1)-(x2-x1)*(Y-y1)) >= 0) & (((y0-y2)*(X-x2)-(x0-x2)*(Y-y2)) >= 0))"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3471 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3472 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3473 part = replace(part,'x1',str(x1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3474 part = replace(part,'y1',str(y1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3475 part = replace(part,'x2',str(x2))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3476 part = replace(part,'y2',str(y2))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3477 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3478
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3479 def pyramid(x0, x1, y0, y1, z0, z1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3480 part = cube(x0, x1, y0, y1, z0, z1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3481 part = taper_xy_z(part, (x0+x1)/2., (y0+y1)/2., z0, z1, 1.0, 0.0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3482 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3483
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3484 def function(Z_of_XY):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3485 part = '(Z <= '+Z_of_XY+')'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3486 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3487
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3488 def functions(upper_Z_of_XY,lower_Z_of_XY):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3489 part = '(Z <= '+upper_Z_of_XY+') & (Z >= '+lower_Z_of_XY+')'
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3490 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3491
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3492 def add(part1, part2):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3493 part = "part1 | part2"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3494 part = replace(part,'part1',part1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3495 part = replace(part,'part2',part2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3496 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3497
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3498 def subtract(part1, part2):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3499 part = "(part1) & ~(part2)"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3500 part = replace(part,'part1',part1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3501 part = replace(part,'part2',part2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3502 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3503
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3504 def intersect(part1, part2):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3505 part = "(part1) & (part2)"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3506 part = replace(part,'part1',part1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3507 part = replace(part,'part2',part2)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3508 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3509
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3510 def move(part,dx,dy):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3511 part = replace(part,'X','(X-'+str(dx)+')')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3512 part = replace(part,'Y','(Y-'+str(dy)+')')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3513 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3514
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3515 def translate(part,dx,dy,dz):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3516 part = replace(part,'X','(X-'+str(dx)+')')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3517 part = replace(part,'Y','(Y-'+str(dy)+')')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3518 part = replace(part,'Z','(Z-'+str(dz)+')')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3519 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3520
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3521 def rotate(part, angle):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3522 angle = angle*pi/180
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3523 part = replace(part,'X','(cos(angle)*X+sin(angle)*y)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3524 part = replace(part,'Y','(-sin(angle)*X+cos(angle)*y)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3525 part = replace(part,'y','Y')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3526 part = replace(part,'angle',str(angle))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3527 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3528
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3529 def rotate_x(part, angle):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3530 angle = angle*pi/180
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3531 part = replace(part,'Y','(cos(angle)*Y+sin(angle)*z)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3532 part = replace(part,'Z','(-sin(angle)*Y+cos(angle)*z)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3533 part = replace(part,'z','Z')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3534 part = replace(part,'angle',str(angle))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3535 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3536
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3537 def rotate_y(part, angle):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3538 angle = angle*pi/180
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3539 part = replace(part,'X','(cos(angle)*X+sin(angle)*z)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3540 part = replace(part,'Z','(-sin(angle)*X+cos(angle)*z)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3541 part = replace(part,'z','Z')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3542 part = replace(part,'angle',str(angle))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3543 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3544
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3545 def rotate_z(part, angle):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3546 angle = angle*pi/180
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3547 part = replace(part,'X','(cos(angle)*X+sin(angle)*y)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3548 part = replace(part,'Y','(-sin(angle)*X+cos(angle)*y)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3549 part = replace(part,'y','Y')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3550 part = replace(part,'angle',str(angle))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3551 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3552
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3553 def rotate_90(part):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3554 part = reflect_xy(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3555 part = reflect_y(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3556 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3557
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3558 def rotate_180(part):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3559 part = reflect_xy(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3560 part = reflect_y(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3561 part = reflect_xy(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3562 part = reflect_y(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3563 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3564
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3565 def rotate_270(part):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3566 part = reflect_xy(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3567 part = reflect_y(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3568 part = reflect_xy(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3569 part = reflect_y(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3570 part = reflect_xy(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3571 part = reflect_y(part)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3572 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3573
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3574 def reflect_x(part):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3575 part = replace(part,'X','(-X)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3576 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3577
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3578 def reflect_y(part):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3579 part = replace(part,'Y','(-Y)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3580 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3581
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3582 def reflect_z(part):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3583 part = replace(part,'Z','(-Z)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3584 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3585
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3586 def reflect_xy(part):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3587 part = replace(part,'X','temp')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3588 part = replace(part,'Y','X')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3589 part = replace(part,'temp','Y')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3590 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3591
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3592 def reflect_xz(part):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3593 part = replace(part,'X','temp')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3594 part = replace(part,'Z','X')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3595 part = replace(part,'temp','Z')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3596 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3597
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3598 def reflect_yz(part):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3599 part = replace(part,'Y','temp')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3600 part = replace(part,'Z','Y')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3601 part = replace(part,'temp','Z')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3602 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3603
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3604 def scale_x(part, x0, sx):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3605 part = replace(part,'X','(x0 + (X-x0)/sx)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3606 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3607 part = replace(part,'sx',str(sx))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3608 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3609
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3610 def scale_y(part, y0, sy):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3611 part = replace(part,'Y','(y0 + (Y-y0)/sy)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3612 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3613 part = replace(part,'sy',str(sy))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3614 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3615
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3616 def scale_z(part, z0, sz):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3617 part = replace(part,'Z','(z0 + (Z-z0)/sz)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3618 part = replace(part,'z0',str(z0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3619 part = replace(part,'sz',str(sz))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3620 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3621
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3622 def scale_xy(part, x0, y0, sxy):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3623 part = replace(part,'X','(x0 + (X-x0)/sxy)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3624 part = replace(part,'Y','(y0 + (Y-y0)/sxy)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3625 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3626 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3627 part = replace(part,'sxy',str(sxy))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3628 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3629
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3630 def scale_xyz(part, x0, y0, z0, sxyz):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3631 part = replace(part,'X','(x0 + (X-x0)/sxyz)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3632 part = replace(part,'Y','(y0 + (Y-y0)/sxyz)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3633 part = replace(part,'Z','(z0 + (Z-z0)/sxyz)')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3634 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3635 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3636 part = replace(part,'z0',str(z0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3637 part = replace(part,'sxyz',str(sxyz))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3638 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3639
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3640 def coscale_x_y(part, x0, y0, y1, angle0, angle1, amplitude, offset):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3641 phase0 = pi*angle0/180.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3642 phase1 = pi*angle1/180.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3643 part = replace(part,'X','(x0 + (X-x0)/(offset + amplitude*cos(phase0 + (phase1-phase0)*(Y-y0)/(y1-y0))))')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3644 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3645 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3646 part = replace(part,'y1',str(y1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3647 part = replace(part,'phase0',str(phase0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3648 part = replace(part,'phase1',str(phase1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3649 part = replace(part,'amplitude',str(amplitude))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3650 part = replace(part,'offset',str(offset))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3651 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3652
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3653 def coscale_x_z(part, x0, z0, z1, angle0, angle1, amplitude, offset):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3654 phase0 = pi*angle0/180.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3655 phase1 = pi*angle1/180.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3656 part = replace(part,'X','(x0 + (X-x0)/(offset + amplitude*cos(phase0 + (phase1-phase0)*(Z-z0)/(z1-z0))))')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3657 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3658 part = replace(part,'z0',str(z0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3659 part = replace(part,'z1',str(z1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3660 part = replace(part,'phase0',str(phase0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3661 part = replace(part,'phase1',str(phase1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3662 part = replace(part,'amplitude',str(amplitude))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3663 part = replace(part,'offset',str(offset))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3664 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3665
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3666 def coscale_xy_z(part, x0, y0, z0, z1, angle0, angle1, amplitude, offset):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3667 phase0 = pi*angle0/180.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3668 phase1 = pi*angle1/180.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3669 part = replace(part,'X','(x0 + (X-x0)/(offset + amplitude*cos(phase0 + (phase1-phase0)*(Z-z0)/(z1-z0))))')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3670 part = replace(part,'Y','(y0 + (Y-y0)/(offset + amplitude*cos(phase0 + (phase1-phase0)*(Z-z0)/(z1-z0))))')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3671 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3672 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3673 part = replace(part,'z0',str(z0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3674 part = replace(part,'z1',str(z1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3675 part = replace(part,'phase0',str(phase0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3676 part = replace(part,'phase1',str(phase1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3677 part = replace(part,'amplitude',str(amplitude))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3678 part = replace(part,'offset',str(offset))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3679 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3680
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3681 def taper_x_y(part, x0, y0, y1, s0, s1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3682 part = replace(part,'X','(x0 + (X-x0)*(y1-y0)/(s1*(Y-y0) + s0*(y1-Y)))')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3683 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3684 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3685 part = replace(part,'y1',str(y1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3686 part = replace(part,'s0',str(s0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3687 part = replace(part,'s1',str(s1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3688 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3689
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3690 def taper_x_z(part, x0, z0, z1, s0, s1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3691 part = replace(part,'X','(x0 + (X-x0)*(z1-z0)/(s1*(Z-z0) + s0*(z1-Z)))')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3692 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3693 part = replace(part,'z0',str(z0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3694 part = replace(part,'z1',str(z1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3695 part = replace(part,'s0',str(s0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3696 part = replace(part,'s1',str(s1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3697 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3698
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3699 def taper_xy_z(part, x0, y0, z0, z1, s0, s1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3700 part = replace(part,'X','(x0 + (X-x0)*(z1-z0)/(s1*(Z-z0) + s0*(z1-Z)))')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3701 part = replace(part,'Y','(y0 + (Y-y0)*(z1-z0)/(s1*(Z-z0) + s0*(z1-Z)))')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3702 part = replace(part,'x0',str(x0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3703 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3704 part = replace(part,'z0',str(z0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3705 part = replace(part,'z1',str(z1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3706 part = replace(part,'s0',str(s0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3707 part = replace(part,'s1',str(s1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3708 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3709
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3710 def shear_x_y(part, y0, y1, dx0, dx1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3711 part = replace(part,'X','(X - dx0 - (dx1-dx0)*(Y-y0)/(y1-y0))')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3712 part = replace(part,'y0',str(y0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3713 part = replace(part,'y1',str(y1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3714 part = replace(part,'dx0',str(dx0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3715 part = replace(part,'dx1',str(dx1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3716 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3717
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3718 def shear_x_z(part, z0, z1, dx0, dx1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3719 part = replace(part,'X','(X - dx0 - (dx1-dx0)*(Z-z0)/(z1-z0))')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3720 part = replace(part,'z0',str(z0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3721 part = replace(part,'z1',str(z1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3722 part = replace(part,'dx0',str(dx0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3723 part = replace(part,'dx1',str(dx1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3724 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3725
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3726 def coshear_x_z(part, z0, z1, angle0, angle1, amplitude, offset):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3727 phase0 = pi*angle0/180.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3728 phase1 = pi*angle1/180.
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3729 part = replace(part,'X','(X - offset - amplitude*cos(phase0 + (phase1-phase0)*(Z-z0)/(z1-z0)))')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3730 part = replace(part,'z0',str(z0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3731 part = replace(part,'z1',str(z1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3732 part = replace(part,'phase0',str(phase0))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3733 part = replace(part,'phase1',str(phase1))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3734 part = replace(part,'amplitude',str(amplitude))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3735 part = replace(part,'offset',str(offset))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3736 return part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3737
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3738 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3739 # define part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3740 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3741
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3742 d = .5
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3743 teapot = cylinder(0,0,-d,d,d)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3744 teapot = coscale_xy_z(teapot,0,0,-d,d,-90,90,.5,.75)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3745
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3746 handle = torus(0,0,0,3.5*d/5.,d/10.)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3747 handle = reflect_xz(handle)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3748 handle = reflect_xy(handle)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3749 handle = scale_x(handle,0,.75)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3750 handle = scale_y(handle,0,3)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3751 handle = translate(handle,-6*d/5.,0,0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3752 teapot = add(teapot,handle)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3753
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3754 spout = torus(2.1*d,-.2*d,0,1.1*d,.2*d)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3755 spout = reflect_yz(spout)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3756 spout = intersect(spout,cube(-3*d,1.8*d,-3*d,3*d,0,3*d))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3757 teapot = add(teapot,spout)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3758
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3759 interior = cylinder(0,0,.1-d,.1+d,d-.1)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3760 interior = coscale_xy_z(interior,0,0,-d,d,-90,90,.5,.75)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3761 teapot = subtract(teapot,interior)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3762
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3763 spout_interior = torus(2.1*d,-.2*d,0,1.1*d,.15*d)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3764 spout_interior = reflect_yz(spout_interior)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3765 spout_interior = intersect(spout_interior,cube(-3*d,1.8*d,-3*d,3*d,0,3*d))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3766 teapot = subtract(teapot,spout_interior)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3767
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3768 part = teapot
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3769
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3770 part = subtract(part,cube(0,3*d,-3*d,0,-3*d,3*d))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3771
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3772 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3773 # define limits and parameters
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3774 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3775
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3776 width = 2.5
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3777 x0 = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3778 y0 = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3779 z0 = 0
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3780 cad.xmin = x0-width/2. # min x to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3781 cad.xmax = x0+width/2. # max x to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3782 cad.ymin = y0-width/2. # min y to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3783 cad.ymax = y0+width/2. # max y to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3784 #cad.zmin = z0-width/4. # min z to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3785 #cad.zmax = z0+width/4. # max x to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3786 cad.zmin = z0-width/4. # min z to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3787 cad.zmax = z0+width/4. # max x to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3788 cad.rx = 30 # x view rotation (degrees)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3789 cad.rz = 20 # z view rotation (degrees)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3790 dpi = 100 # rendering resolution
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3791 cad.nx = int(dpi*(cad.xmax-cad.xmin)) # x points to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3792 cad.ny = int(dpi*(cad.ymax-cad.ymin)) # y points to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3793 cad.nz = int(dpi*(cad.zmax-cad.zmin)) # z points to render
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3794 cad.inches_per_unit = 1.0 # use inch units
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3795
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3796 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3797 # assign part to cad.function
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3798 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3799
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3800 cad.function = part
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3801
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3802 """
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3803
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3804 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3805 # check config file for window parameters
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3806 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3807
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3808 cad_path = os.path.dirname(sys.argv[0])
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3809 if (sys.argv[0] == "cad.py"):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3810 cfg_path = "cad.cfg"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3811 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3812 cfg_path = os.path.dirname(sys.argv[0])+"/cad.cfg"
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3813 try:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3814 config_file = open(cfg_path, 'r')
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3815 string_msg.set("found "+cfg_path)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3816 while 1:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3817 line = config_file.readline()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3818 if (find(line,"window size:") == 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3819 string_window_size.set(int(line[12:]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3820 elif (find(line,"editor width:") == 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3821 string_editor_width.set(int(line[13:]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3822 elif (find(line,"editor height:") == 0):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3823 string_editor_height.set(int(line[14:]))
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3824 elif (line == ""):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3825 break
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3826 config_file.close()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3827 resize_editor(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3828 except:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3829 string_msg.set(cfg_path+" not found")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3830
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3831 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3832 # read input file if on command line, otherwise use template
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3833 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3834
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3835 if len(sys.argv) == 2:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3836 filename = sys.argv[1]
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3837 string_input_file.set(filename)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3838 if (find(filename,'.cad') != -1):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3839 cad_load(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3840 elif ((find(filename,'.jpg') != -1) | (find(filename,'.JPG') != -1) |
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3841 (find(filename,'.png') != -1) | (find(filename,'.PNG') != -1) |
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3842 (find(filename,'.gif') != -1) | (find(filename,'.GIF') != -1)):
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3843 widget_cad_text.delete("1.0",END)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3844 image_load(0)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3845 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3846 string_msg.set("unsupported input file format")
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3847 root.update()
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3848 else:
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3849 widget_cad_text.insert("1.0",cad_template)
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3850
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3851 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3852 # start GUI
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3853 #
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3854
ee535cb8fb1a added some stuff for reference
mbayer
parents:
diff changeset
3855 root.mainloop()

mercurial