Skip to content

Commit 5b550ac

Browse files
committed
possible add_nodes
1 parent f7f0d29 commit 5b550ac

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.py[cod]
2+
*~

gcodetools-dev.py

+43-24
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,10 @@ def cp_to_list(self,i) :
20192019

20202020
def l(self, i) :
20212021
return cspseglength( self.cp_to_list(i), self.cp_to_list(i+1), tolerance=0.001 )
2022-
2022+
2023+
def l_at_t(self, i, t) :
2024+
return CSPsubpath(self.headi(i,t)).l(0)
2025+
20232026
def t_at_l(self, i, l, self_l=None, tolerance=0.001) :
20242027
if self_l == None : self_l = self.l(i)
20252028
if self_l == 0 : return 0.
@@ -2093,9 +2096,8 @@ def cut_head_l(self,l):
20932096
def cut_tail_l(self,l):
20942097
return self.headl(self.length()-l)
20952098

2096-
2097-
def split(self,i,t=.5) :
2098-
sp1,sp2 = self.cp_to_list(i), self.cp_to_list(i+1)
2099+
def split_seg(sp1,sp2) :
2100+
# return P(sp1) P(sp2) P(sp3)
20992101
[x1,y1],[x2,y2],[x3,y3],[x4,y4] = sp1[1], sp1[2], sp2[0], sp2[1]
21002102
x12 = x1+(x2-x1)*t
21012103
y12 = y1+(y2-y1)*t
@@ -2110,6 +2112,26 @@ def split(self,i,t=.5) :
21102112
x = x1223+(x2334-x1223)*t
21112113
y = y1223+(y2334-y1223)*t
21122114
return [[P(sp1[0]),P(sp1[1]),P(x12,y12)], [P(x1223,y1223),P(x,y),P(x2334,y2334)], [P(x34,y34),P(sp2[1]),P(sp2[2])]]
2115+
2116+
def split(self,i,t=.5) :
2117+
sp1,sp2 = self.cp_to_list(i), self.cp_to_list(i+1)
2118+
return split_seg(sp1,sp2)
2119+
2120+
def add_nodes(self, num=None, l=None) :
2121+
pass
2122+
2123+
def add_nodes_i(self, i, num=None, l=None) :
2124+
# Will change total number of points!
2125+
# Will influence i!!!
2126+
L = self.l(i)
2127+
if num == None :
2128+
num = ceil(L/l)
2129+
l = L/num
2130+
sp1,sp2 = self.cp_to_list(i), self.cp_to_list(i+1)
2131+
points = []
2132+
for j in range(num) :
2133+
self.points[i,i+2] = self.split(i,self.t_at_l(i,l))
2134+
i += 1
21132135

21142136
def transform(self, matrix) :
21152137
if matrix == [] : return
@@ -4203,17 +4225,6 @@ def __init__(self):
42034225
self.OptionParser.add_option("", "--bender-tolerance", action="store", type="float", dest="bender_tolerance", default=10., help="Bender angle tolerance")
42044226
self.OptionParser.add_option("", "--bender-step", action="store", type="float", dest="bender_step", default=10., help="Bender distance step")
42054227

4206-
if asin(slope.cross(lslope)) < self.options.bender_tolerance :
4207-
lslope = slope
4208-
li = i
4209-
lt = t
4210-
# make bending!
4211-
a = asin(slope.cross(lslope))
4212-
bend(a, i,t, li,lt)
4213-
l += self.options.bender_step
4214-
4215-
4216-
42174228
self.OptionParser.add_option("", "--in-out-path", action="store", type="inkbool", dest="in_out_path", default=True, help="Create in-out paths")
42184229
self.OptionParser.add_option("", "--in-out-path-do-not-add-reference-point", action="store", type="inkbool", dest="in_out_path_do_not_add_reference_point", default=False, help="Just add reference in-out point")
42194230
self.OptionParser.add_option("", "--in-out-path-point-max-dist", action="store", type="float", dest="in_out_path_point_max_dist", default=10., help="In-out path max distance to reference point")
@@ -7186,8 +7197,10 @@ def update(self) :
71867197
################################################################################
71877198
def bender(self):
71887199
def bend(a,i,t,li,lt) :
7189-
gcode += "(Push %s mm)"%(subpath.l(i,t)-subpath.l(li,lt))
7190-
gcode += "(Bend %s degrees)"%(asin(a.cross(la))/pi*180)
7200+
gcode = ""
7201+
gcode += "(Push %s mm)\n"%(subpath.l_at_t(i,t)-subpath.l_at_t(li,lt))
7202+
gcode += "(Bend %s degrees)\n\n"%(a/pi*180)
7203+
return gcode
71917204

71927205
gcode = ''
71937206
if self.selected_paths == {} and self.options.auto_select_paths:
@@ -7197,28 +7210,34 @@ def bend(a,i,t,li,lt) :
71977210
paths = self.selected_paths
71987211
for layer in self.layers :
71997212
if layer in paths :
7213+
self.set_tool(layer)
7214+
self.tool = self.tools[layer][0]
72007215
for path in paths[layer] :
72017216
csp = CSP(path)
72027217
for subpath in csp.items :
72037218
# here comes the bender
7219+
fetch_point(subpath, )
7220+
72047221
gcode += self.tool['gcode before path']+"\n"
7222+
#split subpath to len
72057223
la = subpath.slope(0,0)
72067224
li =0
72077225
lt = 0
7226+
lslope = None
72087227
for i in range(len(subpath.points)-1) :
72097228
l = 0
72107229
t = 0
72117230
while t<=1 :
72127231
lt = t
7213-
t = subpath.t_at_l(self, i, l, self_l=None, tolerance=0.001) :
7232+
t = subpath.t_at_l(i, l)
72147233
slope = subpath.slope(i,t)
7215-
if asin(slope.cross(lslope)) < self.options.bender_tolerance :
7234+
if lslope==None or asin(slope.cross(lslope)) < self.options.bender_tolerance :
72167235
lslope = slope
72177236
li = i
72187237
lt = t
72197238
# make bending!
72207239
a = asin(slope.cross(lslope))
7221-
bend(a, i,t, li,lt)
7240+
gcode += bend(a, i,t, li,lt)
72227241
l += self.options.bender_step
72237242
#bend at the end of segment
72247243
slope = subpath.slope(i,1)
@@ -7227,12 +7246,12 @@ def bend(a,i,t,li,lt) :
72277246
lt = t
72287247
# make bending!
72297248
a = asin(slope.cross(lslope))
7230-
bend(a, i,t, li,lt)
7249+
gcode += bend(a, i,t, li,lt)
72317250

72327251
gcode += self.tool['gcode after path']+"\n"
7233-
7234-
72357252

7253+
if not self.check_dir() : return
7254+
self.export_gcode(gcode)
72367255

72377256

72387257
################################################################################
@@ -7591,7 +7610,7 @@ def effect(self) :
75917610
else:
75927611
# Get all Gcodetools data from the scene.
75937612
self.get_info()
7594-
if self.options.active_tab in ['"dxfpoints"','"path-to-gcode"', '"area_fill"', '"area"', '"area_artefacts"', '"engraving"', '"lathe"', '"graffiti"', '"plasma-prepare-path"', '"box-prepare-path"']:
7613+
if self.options.active_tab in ['"dxfpoints"','"path-to-gcode"', '"area_fill"', '"area"', '"area_artefacts"', '"engraving"', '"lathe"', '"graffiti"', '"plasma-prepare-path"', '"box-prepare-path"', '"bender"']:
75957614
if self.orientation_points == {} :
75967615
self.error(_("Orientation points have not been defined! A default set of orientation points has been automatically added."),"warning")
75977616
self.orientation( self.layers[min(1,len(self.layers)-1)] )

points.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ def near(self, b, tolerance=None ) :
5151
if tolerance==None : tolerance = 1e-7
5252
return (self-b).l2() < tolerance
5353
def copy(self) : return P(self.x,self.y)
54-
54+
def __getitem__(self, i):
55+
return (self.x if i==0 else self.y if i==1 else None)

0 commit comments

Comments
 (0)