stuff/(Cad.py) Plotting with solenoid or Laser.py

Wed, 20 Jan 2021 11:37:03 +0100

author
mdd
date
Wed, 20 Jan 2021 11:37:03 +0100
changeset 48
3c27b4ee6fec
parent 0
ee535cb8fb1a
permissions
-rw-r--r--

reimplemented lasercutter changes

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

mercurial