Upgrade Conical Box
This commit is contained in:
parent
6ca5ffdea7
commit
29b5a12af3
@ -18,6 +18,7 @@
|
|||||||
<param name="d1" type="float" min="30.0" max="1000.0" _gui-text="Diameter small circle">100.0</param>
|
<param name="d1" type="float" min="30.0" max="1000.0" _gui-text="Diameter small circle">100.0</param>
|
||||||
<param name="d2" type="float" min="31.0" max="1000.0" _gui-text="Diameter large circle">150.0</param>
|
<param name="d2" type="float" min="31.0" max="1000.0" _gui-text="Diameter large circle">150.0</param>
|
||||||
<param name="zc" type="float" min="15.0" max="1000.0" _gui-text="Cone height">50.0</param>
|
<param name="zc" type="float" min="15.0" max="1000.0" _gui-text="Cone height">50.0</param>
|
||||||
|
<param name="nb_pieces" type="int" min="1" max="100" _gui-text="# pieces for cone">1</param>
|
||||||
<param name="inner_size" type="boolean" _gui-text="Internal dimensions">true</param>
|
<param name="inner_size" type="boolean" _gui-text="Internal dimensions">true</param>
|
||||||
<effect>
|
<effect>
|
||||||
<object-type>all</object-type>
|
<object-type>all</object-type>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# We will use the inkex module with the predefined Effect base class.
|
||||||
import inkex
|
import inkex
|
||||||
import math
|
import math
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
@ -34,7 +35,7 @@ class inkcape_polar:
|
|||||||
etree.SubElement(self.group, inkex.addNS('path', 'svg'), line_attribs)
|
etree.SubElement(self.group, inkex.addNS('path', 'svg'), line_attribs)
|
||||||
|
|
||||||
class CurvedSurface:
|
class CurvedSurface:
|
||||||
def __init__(self, L1, L2, nombre_pas, angle_par_pas, taille_exacte_pas, epaisseur, parent, xOffset, yOffset):
|
def __init__(self, L1, L2, nombre_pas, angle_par_pas, taille_exacte_pas, nb_parts, epaisseur, parent, xOffset, yOffset):
|
||||||
self.L1 = L1
|
self.L1 = L1
|
||||||
self.L2 = L2
|
self.L2 = L2
|
||||||
self.nombre_pas = nombre_pas
|
self.nombre_pas = nombre_pas
|
||||||
@ -42,7 +43,9 @@ class CurvedSurface:
|
|||||||
self.taille_exacte_pas = taille_exacte_pas
|
self.taille_exacte_pas = taille_exacte_pas
|
||||||
self.epaisseur = epaisseur
|
self.epaisseur = epaisseur
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.Offset = (xOffset, yOffset)
|
self.OffsetX = xOffset
|
||||||
|
self.OffsetY = yOffset
|
||||||
|
self.nb_parts = nb_parts
|
||||||
|
|
||||||
def genere_element_1(self, angle):
|
def genere_element_1(self, angle):
|
||||||
path = inkcape_polar(self.Offset, self.group)
|
path = inkcape_polar(self.Offset, self.group)
|
||||||
@ -184,18 +187,25 @@ class CurvedSurface:
|
|||||||
|
|
||||||
|
|
||||||
def GeneratePaths(self):
|
def GeneratePaths(self):
|
||||||
group = etree.SubElement(self.parent, 'g')
|
|
||||||
self.group = group
|
|
||||||
#Taille traits courts et longs entre les dents
|
#Taille traits courts et longs entre les dents
|
||||||
self.TailleTraitCourt = (self.L2 - self.L1) / 6 - 1
|
self.TailleTraitCourt = (self.L2 - self.L1) / 6 - 1
|
||||||
self.TailleTraitLong = (self.L2 - self.L1- 2) / 3
|
self.TailleTraitLong = (self.L2 - self.L1- 2) / 3
|
||||||
|
pas_par_bloc = int(self.nombre_pas/self.nb_parts)
|
||||||
#genere les pas du "flex"
|
#genere les pas du "flex"
|
||||||
current_pas = 0
|
for i in range(self.nb_parts):
|
||||||
self.genere_pas_debut()
|
group = etree.SubElement(self.parent, 'g')
|
||||||
while current_pas < self.nombre_pas:
|
self.group = group
|
||||||
self.genere_pas(current_pas)
|
current_pas = 0
|
||||||
current_pas += 1
|
pas_pour_ce_bloc = pas_par_bloc
|
||||||
self.genere_pas_fin(current_pas)
|
self.Offset = (self.OffsetX, self.OffsetY)
|
||||||
|
self.OffsetX += self.L2*2+ 5
|
||||||
|
if i == self.nb_parts - 1:
|
||||||
|
pas_pour_ce_bloc = self.nombre_pas - i * pas_par_bloc
|
||||||
|
self.genere_pas_debut()
|
||||||
|
while current_pas < pas_pour_ce_bloc:
|
||||||
|
self.genere_pas(current_pas)
|
||||||
|
current_pas += 1
|
||||||
|
self.genere_pas_fin(pas_pour_ce_bloc)
|
||||||
|
|
||||||
def gen_cercle(diametre, nombre_pas, epaisseur, xOffset, yOffset, parent):
|
def gen_cercle(diametre, nombre_pas, epaisseur, xOffset, yOffset, parent):
|
||||||
group = etree.SubElement(parent, 'g')
|
group = etree.SubElement(parent, 'g')
|
||||||
@ -216,21 +226,34 @@ def gen_cercle(diametre, nombre_pas, epaisseur, xOffset, yOffset, parent):
|
|||||||
path.GenPath()
|
path.GenPath()
|
||||||
|
|
||||||
class ConicalBox(inkex.Effect):
|
class ConicalBox(inkex.Effect):
|
||||||
|
"""
|
||||||
|
Creates a new layer with the drawings for a parametrically generaded box.
|
||||||
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
inkex.Effect.__init__(self)
|
inkex.Effect.__init__(self)
|
||||||
self.knownUnits = ['in', 'pt', 'px', 'mm', 'cm', 'm', 'km', 'pc', 'yd', 'ft']
|
self.knownUnits = ['in', 'pt', 'px', 'mm', 'cm', 'm', 'km', 'pc', 'yd', 'ft']
|
||||||
|
|
||||||
self.arg_parser.add_argument('--unit', default = 'mm', help = 'Unit, should be one of ')
|
self.arg_parser.add_argument('--unit', default = 'mm', help = 'Unit, should be one of ')
|
||||||
self.arg_parser.add_argument('--thickness', type = float, default = '3.0', help = 'Material thickness')
|
self.arg_parser.add_argument('--thickness', type = float, default = 3.0, help = 'Material thickness')
|
||||||
self.arg_parser.add_argument('--d1', type = float, default = '50.0', help = 'Small circle diameter')
|
self.arg_parser.add_argument('--d1', type = float, default = 50.0, help = 'Small circle diameter')
|
||||||
self.arg_parser.add_argument('--d2', type = float, default = '100.0', help = 'Large circle diameter')
|
self.arg_parser.add_argument('--d2', type = float, default = 100.0, help = 'Large circle diameter')
|
||||||
self.arg_parser.add_argument('--zc', type = float, default = '50.0', help = 'Cone height')
|
self.arg_parser.add_argument('--zc', type = float, default = 50.0, help = 'Cone height')
|
||||||
self.arg_parser.add_argument('--inner_size', type = inkex.Boolean, default = 'true', help = 'Dimensions are internal')
|
self.arg_parser.add_argument('--nb_pieces', type = int, default = 1, help = '# pieces for cone')
|
||||||
|
self.arg_parser.add_argument('--inner_size', type = inkex.Boolean, default = True, help = 'Dimensions are internal')
|
||||||
|
|
||||||
def unittouu(self, unit):
|
try:
|
||||||
return self.svg.unittouu(unit)
|
inkex.Effect.unittouu # unitouu has moved since Inkscape 0.91
|
||||||
|
except AttributeError:
|
||||||
|
try:
|
||||||
|
def unittouu(self, unit):
|
||||||
|
return inkex.unittouu(unit)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
def effect(self):
|
def effect(self):
|
||||||
|
"""
|
||||||
|
Draws a conic box, based on provided parameters
|
||||||
|
"""
|
||||||
|
|
||||||
# input sanity check
|
# input sanity check
|
||||||
error = False
|
error = False
|
||||||
if self.options.zc < 15:
|
if self.options.zc < 15:
|
||||||
@ -252,11 +275,15 @@ class ConicalBox(inkex.Effect):
|
|||||||
if error:
|
if error:
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
|
||||||
# convert units
|
# convert units
|
||||||
unit = self.options.unit
|
unit = self.options.unit
|
||||||
d1 = self.svg.unittouu(str(self.options.d1) + unit)
|
d1 = self.svg.unittouu(str(self.options.d1) + unit)
|
||||||
d2 = self.svg.unittouu(str(self.options.d2) + unit)
|
d2 = self.svg.unittouu(str(self.options.d2) + unit)
|
||||||
zc = self.svg.unittouu(str(self.options.zc) + unit)
|
zc = self.svg.unittouu(str(self.options.zc) + unit)
|
||||||
|
|
||||||
|
nb_parts = self.options.nb_pieces
|
||||||
|
|
||||||
thickness = self.svg.unittouu(str(self.options.thickness) + unit)
|
thickness = self.svg.unittouu(str(self.options.thickness) + unit)
|
||||||
#Si prend dimensions externes, corrige les tailles
|
#Si prend dimensions externes, corrige les tailles
|
||||||
if self.options.inner_size == False:
|
if self.options.inner_size == False:
|
||||||
@ -281,8 +308,8 @@ class ConicalBox(inkex.Effect):
|
|||||||
#calcul nombre de pas (sauf premeirs et derniers) pour D1, avec 2*2 mm par pas
|
#calcul nombre de pas (sauf premeirs et derniers) pour D1, avec 2*2 mm par pas
|
||||||
nombre_pas = round((d1 * math.pi - 6) / 4)
|
nombre_pas = round((d1 * math.pi - 6) / 4)
|
||||||
#calcul angle par pas, ajoute 1.5 pour tenir compte des premiers et derniers pas qui font 3/4 de pas.
|
#calcul angle par pas, ajoute 1.5 pour tenir compte des premiers et derniers pas qui font 3/4 de pas.
|
||||||
angle_par_pas = alpha / (nombre_pas+1.5)
|
angle_par_pas = alpha / (nombre_pas+1.5*nb_parts)
|
||||||
taille_exacte_pas = math.pi * d1 / (nombre_pas+1.5)
|
taille_exacte_pas = math.pi * d1 / (nombre_pas+1.5*nb_parts)
|
||||||
|
|
||||||
# do not put elements right at the edge of the page.
|
# do not put elements right at the edge of the page.
|
||||||
# Drawing will max left will be L2*cos(alpha) - thickness
|
# Drawing will max left will be L2*cos(alpha) - thickness
|
||||||
@ -312,7 +339,7 @@ class ConicalBox(inkex.Effect):
|
|||||||
ymax = (L2+thickness)*math.sin(alpha)
|
ymax = (L2+thickness)*math.sin(alpha)
|
||||||
|
|
||||||
#dessine la partie "souple"
|
#dessine la partie "souple"
|
||||||
PartieSouple = CurvedSurface(L1, L2, nombre_pas, angle_par_pas, taille_exacte_pas, thickness, layer, xOffset, yOffset)
|
PartieSouple = CurvedSurface(L1, L2, nombre_pas, angle_par_pas, taille_exacte_pas, nb_parts, thickness, layer, xOffset, yOffset)
|
||||||
PartieSouple.GeneratePaths()
|
PartieSouple.GeneratePaths()
|
||||||
#génère maintenant le path du grand cercle
|
#génère maintenant le path du grand cercle
|
||||||
#Un pas de plus pour les cercles, pour tenir compte du début et de la fin
|
#Un pas de plus pour les cercles, pour tenir compte du début et de la fin
|
||||||
@ -322,4 +349,5 @@ class ConicalBox(inkex.Effect):
|
|||||||
#puis pour le petit cercle
|
#puis pour le petit cercle
|
||||||
gen_cercle(d1, nombre_pas, thickness, -xmax - d1/2 + xOffset + 10, d1/2 + yOffset - ymin + 10, layer)
|
gen_cercle(d1, nombre_pas, thickness, -xmax - d1/2 + xOffset + 10, d1/2 + yOffset - ymin + 10, layer)
|
||||||
|
|
||||||
|
# Create effect instance and apply it.
|
||||||
ConicalBox().run()
|
ConicalBox().run()
|
Reference in New Issue
Block a user