This commit is contained in:
Mario Voigt 2021-10-17 23:24:32 +02:00
parent 2b8e15b3d7
commit 0d91114305
3 changed files with 130 additions and 110 deletions

View File

@ -20,7 +20,6 @@
<param name="creationunit" type="optiongroup" appearance="combo" gui-text="Creation Units"> <param name="creationunit" type="optiongroup" appearance="combo" gui-text="Creation Units">
<option value="mm">mm</option> <option value="mm">mm</option>
<option value="cm">cm</option> <option value="cm">cm</option>
<option value="m">m</option>
<option value="in">in</option> <option value="in">in</option>
<option value="pt">pt</option> <option value="pt">pt</option>
<option value="px">px</option> <option value="px">px</option>
@ -44,7 +43,6 @@
<param name="length_filter_unit" type="optiongroup" appearance="combo" gui-text="Length filter unit"> <param name="length_filter_unit" type="optiongroup" appearance="combo" gui-text="Length filter unit">
<option value="mm">mm</option> <option value="mm">mm</option>
<option value="cm">cm</option> <option value="cm">cm</option>
<option value="m">m</option>
<option value="in">in</option> <option value="in">in</option>
<option value="pt">pt</option> <option value="pt">pt</option>
<option value="px">px</option> <option value="px">px</option>

View File

@ -4,18 +4,20 @@
<id>fablabchemnitz.de.join_paths</id> <id>fablabchemnitz.de.join_paths</id>
<param name="tab" type="notebook"> <param name="tab" type="notebook">
<page name="subdividePath" gui-text="Join Paths / Create Tabs And Dimples"> <page name="subdividePath" gui-text="Join Paths / Create Tabs And Dimples">
<label appearance="header">Join Paths</label>
<param name="optimized" type="bool" gui-text="Optimized joining">true</param> <param name="optimized" type="bool" gui-text="Optimized joining">true</param>
<param name="margin" type="float" min="0.0001" max="99999.0000" precision="4" gui-text="Merge margin">0.0100</param> <param name="margin" type="float" min="0.0001" max="99999.0000" precision="4" gui-text="Merge margin">0.0100</param>
<label appearance="header">Create Tabs And Dimples</label> <label appearance="header">Create Tabs And Dimples</label>
<label>Enable to insert dimples (pressfit noses) into the gaps (instead regular straight lines)</label> <label>Enable to insert dimples (pressfit noses) into the gaps (instead regular straight lines)</label>
<param name="add_dimples" type="bool" gui-text="Create dimples">false</param> <param name="add_dimples" type="bool" gui-text="Create dimples">false</param>
<param name="dimples_to_group" type="bool" gui-text="Unify into single group">false</param>
<param name="dimple_type" type="optiongroup" appearance="combo" gui-text="Dimple type"> <param name="dimple_type" type="optiongroup" appearance="combo" gui-text="Dimple type">
<option value="peaks">peaks</option> <option value="peaks">peaks</option>
<option value="arcs">arcs</option> <option value="arcs">arcs</option>
<option value="tabs">tabs</option> <option value="tabs">tabs</option>
</param> </param>
<param name="draw_dimple_centers" type="bool" gui-text="Draw dimple centers">false</param> <param name="draw_dimple_centers" type="bool" gui-text="Draw dimple centers">false</param>
<param name="dimple_invert" type="bool" gui-text="Invert dimples">false</param> <param name="dimple_invert" type="bool" gui-text="Invert dimple sides">false</param>
<param name="draw_both_sides" type="bool" gui-text="Draw both sides">false</param> <param name="draw_both_sides" type="bool" gui-text="Draw both sides">false</param>
<param name="dimple_height_mode" type="optiongroup" appearance="combo" gui-text="Height by ..."> <param name="dimple_height_mode" type="optiongroup" appearance="combo" gui-text="Height by ...">
<option value="by_height">by height</option> <option value="by_height">by height</option>
@ -31,7 +33,17 @@
<option value="pt">pt</option> <option value="pt">pt</option>
<option value="px">px</option> <option value="px">px</option>
</param> </param>
<param name="dimples_to_group" type="bool" gui-text="Unify into single group">false</param> <label appearance="header">Dimple gap filter</label>
<param name="dimple_gap_filter" type="bool" gui-text="Apply min/max filter">false</param>
<param name="dimple_min_gap" type="float" min="0.000" max="99999.000" precision="3" gui-text="Min">1</param>
<param name="dimple_max_gap" type="float" min="0.000" max="99999.000" precision="3" gui-text="Max">40</param>
<param name="dimple_gap_filter_units" gui-text="Filter units" type="optiongroup" appearance="combo">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="in">in</option>
<option value="pt">pt</option>
<option value="px">px</option>
</param>
</page> </page>
<page name="desc" gui-text="Help"> <page name="desc" gui-text="Help">
<label xml:space="preserve">This effect joins the Bezier curves, with straight line segments. If the end nodes are close enough, they are merged into a single one. With the optimized option selected, the new curve starts from the top most curve from the selection. The curves are then joined based on the distance of their closest end point to the previous curve. <label xml:space="preserve">This effect joins the Bezier curves, with straight line segments. If the end nodes are close enough, they are merged into a single one. With the optimized option selected, the new curve starts from the top most curve from the selection. The curves are then joined based on the distance of their closest end point to the previous curve.

View File

@ -134,11 +134,18 @@ class JoinPaths(inkex.EffectExtension):
pars.add_argument("--dimple_height", type=float, default=4) pars.add_argument("--dimple_height", type=float, default=4)
pars.add_argument("--dimple_angle", type=float, default=45) pars.add_argument("--dimple_angle", type=float, default=45)
pars.add_argument("--dimple_tab_angle", type=float, default=45) pars.add_argument("--dimple_tab_angle", type=float, default=45)
pars.add_argument("--dimple_gap_filter", type=inkex.Boolean, default=False)
pars.add_argument("--dimple_min_gap", type=float, default=1)
pars.add_argument("--dimple_max_gap", type=float, default=40)
pars.add_argument("--dimple_gap_filter_units", default="mm")
pars.add_argument("--dimple_height_units", default="mm") pars.add_argument("--dimple_height_units", default="mm")
pars.add_argument("--tab", default="sampling", help="Tab") pars.add_argument("--tab", default="sampling", help="Tab")
def effect(self): def effect(self):
selections = self.svg.selected selections = self.svg.selected
if len(self.svg.selected) == 0:
self.msg('Please select some paths first.')
return
pathNodes = self.document.xpath('//svg:path',namespaces=inkex.NSS) pathNodes = self.document.xpath('//svg:path',namespaces=inkex.NSS)
paths = {p.get('id'): getPartsFromCubicSuper(CubicSuperPath(p.get('d'))) for p in pathNodes } paths = {p.get('id'): getPartsFromCubicSuper(CubicSuperPath(p.get('d'))) for p in pathNodes }
#paths.keys() Order disturbed #paths.keys() Order disturbed
@ -191,76 +198,62 @@ class JoinPaths(inkex.EffectExtension):
dx2 = p2[0]-p1[0] dx2 = p2[0]-p1[0]
dy2 = p2[1]-p1[1] dy2 = p2[1]-p1[1]
dist2 = math.sqrt(dx2*dx2 + dy2*dy2) dist2 = math.sqrt(dx2*dx2 + dy2*dy2)
if dx2 == 0: if dx2 == 0:
slope=sys.float_info.max #vertical slope=sys.float_info.max #vertical
else: else:
slope=(p2[1] - p1[1]) / dx2 slope=(p2[1] - p1[1]) / dx2
slope_angle = 90 + math.degrees(math.atan(slope)) slope_angle = 90 + math.degrees(math.atan(slope))
if (self.options.dimple_gap_filter is True \
if self.options.dimple_height_mode == "by_height": and dist2 >= self.svg.unittouu(str(self.options.dimple_min_gap) + self.options.dimple_gap_filter_units) \
dimple_height = self.svg.unittouu(str(self.options.dimple_height) + self.options.dimple_height_units) and dist2 < self.svg.unittouu(str(self.options.dimple_max_gap) + self.options.dimple_gap_filter_units)
else: ) \
dimple_height = dist * math.sin(math.radians(self.options.dimple_angle)) or self.options.dimple_gap_filter is False:
if self.options.dimple_height_mode == "by_height":
x3 = midPoint[0] + (dimple_height)*dy dimple_height = self.svg.unittouu(str(self.options.dimple_height) + self.options.dimple_height_units)
y3 = midPoint[1] - (dimple_height)*dx
x4 = midPoint[0] - (dimple_height)*dy
y4 = midPoint[1] + (dimple_height)*dx
dimple_style = {'stroke': '#0000FF', 'fill': 'none', 'stroke-width': str(self.svg.unittouu('1px'))}
if self.options.draw_dimple_centers is True:
#add a new dimple center cross (4 segments)
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_center_perp1')))
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(midPoint[0], midPoint[1], x3, y3))
line.style = dimple_style
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_center_perp2')))
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(midPoint[0], midPoint[1], x4, y4))
line.style = dimple_style
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_center_join1')))
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(p1[0], p1[1], midPoint[0], midPoint[1]))
line.style = dimple_style
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_center_join1')))
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(midPoint[0], midPoint[1], p2[0], p2[1]))
line.style = dimple_style
if self.options.dimple_type == "peaks":
if self.options.dimple_invert is True:
x5 = x3
y5 = y3
x3 = x4
y3 = y4
x4 = x5
y4 = y5
#add a new dimple center
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_peak')))
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(p1[0], p1[1], x3, y3, p2[0], p2[1]))
line.style = dimple_style
if self.options.draw_both_sides is True:
#add a new opposite dimple center
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_peak')))
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(p1[0], p1[1], x4, y4, p2[0], p2[1]))
line.style = dimple_style
elif self.options.dimple_type == "arcs":
ellipse = dimpleGroup.add(inkex.Ellipse(id=self.svg.get_unique_id('dimple_arc')))
ellipse.set('transform', "rotate({:0.6f} {:0.6f} {:0.6f})".format(slope_angle, midPoint[0], midPoint[1]))
ellipse.set('sodipodi:arc-type', "arc")
ellipse.set('sodipodi:type', "arc")
ellipse.set('sodipodi:cx', "{:0.6f}".format(midPoint[0]))
ellipse.set('sodipodi:cy', "{:0.6f}".format(midPoint[1]))
ellipse.set('sodipodi:rx', "{:0.6f}".format(dimple_height))
ellipse.set('sodipodi:ry', "{:0.6f}".format(dist2 / 2))
if self.options.dimple_invert is True:
ellipse.set('sodipodi:start', "{:0.6f}".format(math.radians(90.0)))
ellipse.set('sodipodi:end', "{:0.6f}".format(math.radians(270.0)))
else: else:
ellipse.set('sodipodi:start', "{:0.6f}".format(math.radians(270.0))) dimple_height = dist * math.sin(math.radians(self.options.dimple_angle))
ellipse.set('sodipodi:end', "{:0.6f}".format(math.radians(90.0)))
ellipse.style = dimple_style x3 = midPoint[0] + (dimple_height)*dy
y3 = midPoint[1] - (dimple_height)*dx
if self.options.draw_both_sides is True: x4 = midPoint[0] - (dimple_height)*dy
y4 = midPoint[1] + (dimple_height)*dx
dimple_style = {'stroke': '#0000FF', 'fill': 'none', 'stroke-width': str(self.svg.unittouu('1px'))}
if self.options.draw_dimple_centers is True:
#add a new dimple center cross (4 segments)
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_center_perp1')))
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(midPoint[0], midPoint[1], x3, y3))
line.style = dimple_style
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_center_perp2')))
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(midPoint[0], midPoint[1], x4, y4))
line.style = dimple_style
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_center_join1')))
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(p1[0], p1[1], midPoint[0], midPoint[1]))
line.style = dimple_style
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_center_join1')))
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(midPoint[0], midPoint[1], p2[0], p2[1]))
line.style = dimple_style
if self.options.dimple_type == "peaks":
if self.options.dimple_invert is True:
x5 = x3
y5 = y3
x3 = x4
y3 = y4
x4 = x5
y4 = y5
#add a new dimple center
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_peak')))
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(p1[0], p1[1], x3, y3, p2[0], p2[1]))
line.style = dimple_style
if self.options.draw_both_sides is True:
#add a new opposite dimple center
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_peak')))
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(p1[0], p1[1], x4, y4, p2[0], p2[1]))
line.style = dimple_style
elif self.options.dimple_type == "arcs":
ellipse = dimpleGroup.add(inkex.Ellipse(id=self.svg.get_unique_id('dimple_arc'))) ellipse = dimpleGroup.add(inkex.Ellipse(id=self.svg.get_unique_id('dimple_arc')))
ellipse.set('transform', "rotate({:0.6f} {:0.6f} {:0.6f})".format(slope_angle, midPoint[0], midPoint[1])) ellipse.set('transform', "rotate({:0.6f} {:0.6f} {:0.6f})".format(slope_angle, midPoint[0], midPoint[1]))
ellipse.set('sodipodi:arc-type', "arc") ellipse.set('sodipodi:arc-type', "arc")
@ -269,51 +262,68 @@ class JoinPaths(inkex.EffectExtension):
ellipse.set('sodipodi:cy', "{:0.6f}".format(midPoint[1])) ellipse.set('sodipodi:cy', "{:0.6f}".format(midPoint[1]))
ellipse.set('sodipodi:rx', "{:0.6f}".format(dimple_height)) ellipse.set('sodipodi:rx', "{:0.6f}".format(dimple_height))
ellipse.set('sodipodi:ry', "{:0.6f}".format(dist2 / 2)) ellipse.set('sodipodi:ry', "{:0.6f}".format(dist2 / 2))
if self.options.dimple_invert is True: if self.options.dimple_invert is True:
ellipse.set('sodipodi:start', "{:0.6f}".format(math.radians(270.0))) ellipse.set('sodipodi:start', "{:0.6f}".format(math.radians(90.0)))
ellipse.set('sodipodi:end', "{:0.6f}".format(math.radians(90.0))) ellipse.set('sodipodi:end', "{:0.6f}".format(math.radians(270.0)))
else: else:
ellipse.set('sodipodi:start', "{:0.6f}".format(math.radians(90.0))) ellipse.set('sodipodi:start', "{:0.6f}".format(math.radians(270.0)))
ellipse.set('sodipodi:end', "{:0.6f}".format(math.radians(270.0))) ellipse.set('sodipodi:end', "{:0.6f}".format(math.radians(90.0)))
ellipse.style = dimple_style ellipse.style = dimple_style
elif self.options.dimple_type == "tabs": if self.options.draw_both_sides is True:
pbottom1 = [p1[0] + (dimple_height)*dy, p1[1] - (dimple_height)*dx] ellipse = dimpleGroup.add(inkex.Ellipse(id=self.svg.get_unique_id('dimple_arc')))
pbottom2 = [p2[0] + (dimple_height)*dy, p2[1] - (dimple_height)*dx] ellipse.set('transform', "rotate({:0.6f} {:0.6f} {:0.6f})".format(slope_angle, midPoint[0], midPoint[1]))
ptop1 = [p1[0] - (dimple_height)*dy, p1[1] + (dimple_height)*dx] ellipse.set('sodipodi:arc-type', "arc")
ptop2 = [p2[0] - (dimple_height)*dy, p2[1] + (dimple_height)*dx] ellipse.set('sodipodi:type', "arc")
ellipse.set('sodipodi:cx', "{:0.6f}".format(midPoint[0]))
l_hypo = dimple_height / (math.cos(math.radians(90.0 - self.options.dimple_tab_angle))) ellipse.set('sodipodi:cy', "{:0.6f}".format(midPoint[1]))
pbottom1 = rotate(p1, [p1[0] + l_hypo * dx, p1[1] + l_hypo * dy], math.radians(-self.options.dimple_tab_angle)) ellipse.set('sodipodi:rx', "{:0.6f}".format(dimple_height))
pbottom2 = rotate(p2, [p2[0] - l_hypo * dx, p2[1] - l_hypo * dy], math.radians(-360.0 + self.options.dimple_tab_angle)) ellipse.set('sodipodi:ry', "{:0.6f}".format(dist2 / 2))
ptop1 = rotate(p1, [p1[0] + l_hypo * dx, p1[1] + l_hypo * dy], math.radians(self.options.dimple_tab_angle)) if self.options.dimple_invert is True:
ptop2 = rotate(p2, [p2[0] - l_hypo * dx, p2[1] - l_hypo * dy], math.radians(360.0 - self.options.dimple_tab_angle)) ellipse.set('sodipodi:start', "{:0.6f}".format(math.radians(270.0)))
ellipse.set('sodipodi:end', "{:0.6f}".format(math.radians(90.0)))
else:
if self.options.dimple_invert is True: ellipse.set('sodipodi:start', "{:0.6f}".format(math.radians(90.0)))
ptemp1 = pbottom1 ellipse.set('sodipodi:end', "{:0.6f}".format(math.radians(270.0)))
ptemp2 = pbottom2 ellipse.style = dimple_style
pbottom1 = ptop1
pbottom2 = ptop2 elif self.options.dimple_type == "tabs":
ptop1 = ptemp1 pbottom1 = [p1[0] + (dimple_height)*dy, p1[1] - (dimple_height)*dx]
ptop2 = ptemp2 pbottom2 = [p2[0] + (dimple_height)*dy, p2[1] - (dimple_height)*dx]
ptop1 = [p1[0] - (dimple_height)*dy, p1[1] + (dimple_height)*dx]
ptop2 = [p2[0] - (dimple_height)*dy, p2[1] + (dimple_height)*dx]
l_hypo = dimple_height / (math.cos(math.radians(90.0 - self.options.dimple_tab_angle)))
pbottom1 = rotate(p1, [p1[0] + l_hypo * dx, p1[1] + l_hypo * dy], math.radians(-self.options.dimple_tab_angle))
pbottom2 = rotate(p2, [p2[0] - l_hypo * dx, p2[1] - l_hypo * dy], math.radians(-360.0 + self.options.dimple_tab_angle))
ptop1 = rotate(p1, [p1[0] + l_hypo * dx, p1[1] + l_hypo * dy], math.radians(self.options.dimple_tab_angle))
ptop2 = rotate(p2, [p2[0] - l_hypo * dx, p2[1] - l_hypo * dy], math.radians(360.0 - self.options.dimple_tab_angle))
#add a new tab
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_tab'))) if self.options.dimple_invert is True:
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format( ptemp1 = pbottom1
p1[0], p1[1], pbottom1[0], pbottom1[1], pbottom2[0], pbottom2[1], p2[0], p2[1])) ptemp2 = pbottom2
line.style = dimple_style pbottom1 = ptop1
if self.options.draw_both_sides is True: pbottom2 = ptop2
ptop1 = ptemp1
ptop2 = ptemp2
#add a new tab
line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_tab'))) line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_tab')))
line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format( line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(
p1[0], p1[1], ptop1[0], ptop1[1], ptop2[0], ptop2[1], p2[0], p2[1])) p1[0], p1[1], pbottom1[0], pbottom1[1], pbottom2[0], pbottom2[1], p2[0], p2[1]))
line.style = dimple_style line.style = dimple_style
if self.options.draw_both_sides is True:
#cleanup groups line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_tab')))
if len(dimpleGroup) == 1: ##move up child if group has only one child line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(
for child in dimpleGroup: p1[0], p1[1], ptop1[0], ptop1[1], ptop2[0], ptop2[1], p2[0], p2[1]))
dimpleGroup.getparent().insert(elem.getparent().index(elem), child) line.style = dimple_style
dimpleGroup.delete() #delete the empty group now
#cleanup groups
if len(dimpleGroup) == 1: ##move up child if group has only one child
for child in dimpleGroup:
dimpleGroup.getparent().insert(elem.getparent().index(elem), child)
dimpleGroup.delete() #delete the empty group now
else: else:
newParts[-1].append([newParts[-1][-1][-1], newParts[-1][-1][-1], start, start]) newParts[-1].append([newParts[-1][-1][-1], newParts[-1][-1][-1], start, start])