Skip to content

Commit 0111b09

Browse files
committed
Some adds to bezier console arcs.
1 parent 99794b9 commit 0111b09

File tree

3 files changed

+90
-49
lines changed

3 files changed

+90
-49
lines changed

bezier-console.py

+76-42
Original file line numberDiff line numberDiff line change
@@ -122,61 +122,95 @@ def arc_on_two_points_and_slope(self,st,end,slope) :
122122
a = (st-c).cross(slope)
123123
return Arc(st,end,c,a)
124124

125+
def get_arg_comb(self,s,args):
126+
s = list(s)
127+
args = {"x":x,"y":y,"a":a,"r":r,"i":i,"j":j,"l":l}
128+
for i in args:
129+
if (args[i] == None and i in s or
130+
args[i] != None and i not in s) :
131+
return False
132+
return True
125133

126134
def get_arc_param(self,x,y,a,r,i,j,l) :
127135
st = self.p
128-
129-
if a==None and r==None and i==None and j==None and l==None :
136+
c = None
137+
# asume not enought params use slope.
138+
if x !=None or y!=None:
130139
# using two points and slope.
131-
if x==None and y==None : error("To few parametersfor arc. Command: %s"%self.command)
132140
end = P(x if x!=None else self.p.x, y if y!=None else self.p.y)
133141
return self.arc_on_two_points_and_slope(self.p,end,self.slope)
142+
143+
if a != None :
144+
if l !=None :
145+
r = l/a/2
146+
if r != None :
147+
c = self.p+self.slope.ccw()*r
148+
if i != None or j != None :
149+
c = P(i if i!=None else self.p.x, j if j!=None else self.p.y)
150+
if c != None :
151+
end = (self.p - c).rotate(a) + c
152+
return self.arc_on_two_points_and_slope(self.p,end,self.slope)
153+
154+
if l != None :
155+
if i != None or j != None :
156+
c = P(i if i!=None else self.p.x, j if j!=None else self.p.y)
157+
r = (self.p - c).mag()
158+
if r != None :
159+
a = l/r/2
160+
return get_arc_param(None, None, a, r, None, None, None)
161+
162+
error("To few parametersfor arc. Command: %s"%self.command)
134163

135-
164+
136165
def draw_arc(self,x,y,a,r,i,j,l) :
137166
st = self.p
138167
arc = self.get_arc_param(x,y,a,r,i,j,l)
139-
warn(arc)
168+
#warn(arc)
140169
self.path.join(arc.to_csp())
141170

142-
def parse_command(self, a) :
143-
if a.strip() == "" : return
144-
r = re.match("\s*([almhvALMHV])?\s*([alxyrijALXYRIJ\d\.\-\s]*)",a)
145-
self.command = a
171+
def parse_command(self, command) :
172+
if command.strip() == "" : return
173+
self.command = command
174+
r = re.match("\s*([almhvALMHV]?)\s*((\s*[alxyrijdALXYRIJD]\s*\-?[\d\.]+)*)\s*", command)
146175
if not r:
147-
error("Cannot parse command: \"%s\""% a)
148-
else :
149-
t,params = r.groups()
150-
if t == None or t == "" :
151-
t = self.last_command
152-
# parse the parameters
153-
x,y,a,l,r,i,j = None, None, None, None, None, None, None
154-
try:
155-
self.slope = self.path.slope(-1,-1,1)
156-
except:
157-
self.slope = P(1.,0.)
158-
for p in re.findall("([alxyrijALXYRIJ])\s*(\-?\d*\.?\d*)",params) :
159-
#warn(p)
160-
p = list(p)
161-
if p[0] == "A" : a = -float(p[1])/180*pi
162-
elif p[0] == "a" : a = self.slope.angle() -float(p[1])/180*pi
163-
else : p[1] = float(p[1])*self.options.units
164-
if p[0] == "x" : x = self.p.x + p[1]
165-
elif p[0] == "X" : x = p[1]
166-
elif p[0] == "y" : y = self.p.y - p[1]
167-
elif p[0] == "Y" : y = - p[1]
168-
elif p[0] == "i" : i = self.p.x + p[1]
169-
elif p[0] == "I" : I = p[1]
170-
elif p[0] == "j" : j = self.p.y - p[1]
171-
elif p[0] == "J" : J = -p[1]
172-
elif p[0] in ("r","R") : r = -p[1]
173-
elif p[0] in ("l","L") : l = p[1]
174-
175-
# exec command
176-
if t in ("l","L") : self.draw_line(x,y,a,l)
177-
if t in ("a","A") : self.draw_arc(x,y,a,r,i,j,l)
178-
if t in ("m","M") : self.move_to(x,y,a,l)
179-
self.last_command = t
176+
error("Cannot parse command: \"%s\""% command)
177+
178+
r = re.match("\s*([almhvALMHV])\s*([alxyrijdALXYRIJD].*)", command)
179+
if r :
180+
warn(r.groups())
181+
t, command = r.groups()
182+
else :
183+
t = self.last_command
184+
185+
# parse the parameters
186+
x,y,a,l,r,i,j = None, None, None, None, None, None, None
187+
try:
188+
self.slope = self.path.slope(-1,-1,1)
189+
except:
190+
self.slope = P(1.,0.)
191+
for p in re.findall("([alxyrijALXYRIJ])\s*(\-?\d*\.?\d*)", command) :
192+
#warn(p)
193+
p = list(p)
194+
if p[0] == "A" : a = -float(p[1])/180*pi
195+
elif p[0] == "a" : a = self.slope.angle() -float(p[1])/180*pi
196+
else : p[1] = float(p[1])*self.options.units
197+
if p[0] == "x" : x = self.p.x + p[1]
198+
elif p[0] == "X" : x = p[1]
199+
elif p[0] == "y" : y = self.p.y - p[1]
200+
elif p[0] == "Y" : y = - p[1]
201+
elif p[0] == "i" : i = self.p.x + p[1]
202+
elif p[0] == "I" : I = p[1]
203+
elif p[0] == "j" : j = self.p.y - p[1]
204+
elif p[0] == "J" : J = -p[1]
205+
elif p[0] in ("r","R") : r = p[1]
206+
elif p[0] in ("d","D") : r = p[1]/2
207+
elif p[0] in ("l","L") : l = p[1]
208+
209+
# exec command
210+
if t in ("l","L") : self.draw_line(x,y,a,l)
211+
if t in ("a","A") : self.draw_arc(x,y,a,r,i,j,l)
212+
if t in ("m","M") : self.move_to(x,y,a,l)
213+
self.last_command = t
180214

181215
def effect(self) :
182216
if self.options.silent :

gcodetools-dev.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -4910,12 +4910,12 @@ def __init__(self):
49104910
"penetration feed":100.,
49114911
"depth step":1.,
49124912
"feed":400.,
4913-
"in trajectotry":"",
4914-
"out trajectotry":"",
4913+
"in trajectory":"",
4914+
"out trajectory":"",
49154915
"gcode before path":"",
49164916
"gcode after path":"",
49174917
"sog":"",
4918-
"spinlde rpm":"",
4918+
"spindle rpm":"",
49194919
"CW or CCW":"",
49204920
"tool change gcode":" ",
49214921
"4th axis meaning": " ",
@@ -4935,12 +4935,12 @@ def __init__(self):
49354935
'penetration feed',
49364936
"passing feed",
49374937
'depth step',
4938-
"in trajectotry",
4939-
"out trajectotry",
4938+
"in trajectory",
4939+
"out trajectory",
49404940
"gcode before path",
49414941
"gcode after path",
49424942
"sog",
4943-
"spinlde rpm",
4943+
"spindle rpm",
49444944
"CW or CCW",
49454945
"tool change gcode",
49464946
]
@@ -5265,7 +5265,8 @@ def get_tangent_knife_turn_gcode(s,si,tool,current_a, depth, penetration_feed) :
52655265
if tool != self.last_used_tool :
52665266
g += ( "(Change tool to %s)\n" % re.sub("\"'\(\)\\\\"," ",tool["name"]) ) + tool["tool change gcode"] + "\n"
52675267
self.last_used_tool = tool
5268-
5268+
if "" != self.tool["spindle rpm"] :
5269+
gcode += "S%s\n" % (self.tool["spindle rpm"])
52695270
lg, zs, f = 'G00', self.options.Zsafe, " F%f"%tool['feed']
52705271
current_a = None
52715272
go_to_safe_distance = "G00" + c([None,None,zs]) + "\n"
@@ -7528,6 +7529,8 @@ def lathe(self):
75287529
self.tool["feed"] = float(self.tool["feed"])
75297530
self.tool["fine feed"] = float(self.tool["fine feed"] if "fine feed" in self.tool else self.tool["feed"])
75307531
gcode += ( "(Change tool to %s)\n" % re.sub("\"'\(\)\\\\"," ",self.tool["name"]) ) + self.tool["tool change gcode"] + "\n"
7532+
if "" != self.tool["spindle rpm"] :
7533+
gcode += "S%s\n" % (self.tool["spindle rpm"])
75317534

75327535
for path in paths[layer]:
75337536
csp = self.transform_csp(cubicsuperpath.parsePath(path.get("d")),layer)

points.py

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def dot(self, other): return self.x * other.x + self.y * other.y
2929
def cross(self, other): return self.x * other.y - self.y * other.x
3030

3131
def rot(self, theta):
32+
c = cos(theta)
33+
s = sin(theta)
34+
return P(self.x * c - self.y * s, self.x * s + self.y * c)
35+
def rotate(self, theta):
3236
c = cos(theta)
3337
s = sin(theta)
3438
return P(self.x * c - self.y * s, self.x * s + self.y * c)

0 commit comments

Comments
 (0)