Parametrizise the drillbox

This commit is contained in:
jens persson 2021-05-16 20:35:01 +02:00 committed by Florian Festi
parent 22a50a6181
commit c86ae75712
1 changed files with 61 additions and 30 deletions

View File

@ -14,44 +14,78 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from boxes import * from boxes import Boxes, edges, Color
class DrillBox(Boxes): class DrillBox(Boxes):
"""Not yet parametrized box for drills from 1 to 12.5mm """A parametrized box for drills"""
in 0.5mm steps, 3 holes each size"""
def __init__(self): def __init__(self):
Boxes.__init__(self) Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings) self.addSettingsArgs(edges.FingerJointSettings)
self.x, self.y, self.h = 120, 240, 60 self.buildArgParser(sx="25*3", sy="60*4", h=60)
self.argparser.add_argument(
"--holes",
action="store",
type=int,
default=3,
help="Number of holes for each size",
)
self.argparser.add_argument(
"--firsthole",
action="store",
type=float,
default=1.0,
help="Smallest hole",
)
self.argparser.add_argument(
"--holeincrement",
action="store",
type=float,
default=.5,
help="increment between holes",
)
def holesx(self): def holesx(self):
self.fingerHolesAt(0, 5, self.x, angle=0) x = sum(self.sx)
self.fingerHolesAt(0, 25, self.x, angle=0) self.fingerHolesAt(0, 5, x, angle=0)
self.fingerHolesAt(0, 25, x, angle=0)
def holesy(self): def holesy(self):
self.fingerHolesAt(0, 5, self.y, angle=0) y = sum(self.sy)
self.fingerHolesAt(0, 25, self.y, angle=0) self.fingerHolesAt(0, 5, y, angle=0)
self.fingerHolesAt(0, 25, y, angle=0)
def drillholes(self): def drillholes(self, description=False):
for i in range(6): y = 0
for j in range(4): d = self.firsthole
for k in range(3): for dy in self.sy:
r = (12.5 - 2 * i - 0.5 * j) * 0.5 x = 0
self.hole(i * 20 + 10, j * 60 + k * 20 + 10, r + 0.05) for dx in self.sx:
iy = dy / self.holes
def descriptionText(self): for k in range(self.holes):
for i in range(4): self.hole(x + dx / 2, y + (k + 0.5) * iy, d + 0.05)
for j in range(6): if description:
self.rectangularHole(i * 60 + 30, 20 * j + 10, 58, 14 + 1 * j) self.rectangularHole(x + dx / 2, y + dy / 2, dx - 2, dy - 2)
d = 2.5 - 0.5 * i + 2 * j # TODO: make the "hole" green to indicate etching
self.text("%.1f" % d, i * 60 + 20, 19 * j + 6, self.text(
align="center", fontsize=6) "%.1f" % d,
x + 2,
y + 2,
270,
align="right",
fontsize=6,
color=Color.GREEN,
)
# TODO: make the fontsize dynamic to make the text fit in all cases
d += self.holeincrement
x += dx
y += dy
def render(self): def render(self):
x, y, h = self.x, self.y, self.h x = sum(self.sx)
t = self.thickness y = sum(self.sy)
h = self.h
self.edges["f"].settings.setValues(self.thickness, space=3, finger=3, surroundingspaces=1) self.edges["f"].settings.setValues(self.thickness, space=3, finger=3, surroundingspaces=1)
@ -60,9 +94,6 @@ in 0.5mm steps, 3 holes each size"""
self.rectangularWall(y, h, "FfeF", callback=[self.holesy]) self.rectangularWall(y, h, "FfeF", callback=[self.holesy])
self.rectangularWall(x, h, "FfeF", callback=[self.holesx], move="left up") self.rectangularWall(x, h, "FfeF", callback=[self.holesx], move="left up")
self.rectangularWall(x, y, "ffff", move="up") self.rectangularWall(x, y, "ffff", move="right")
self.rectangularWall(x, y, "ffff", callback=[self.drillholes], move="up") self.rectangularWall(x, y, "ffff", callback=[self.drillholes], move="right")
self.rectangularWall(x, y, "ffff", callback=[self.drillholes, self.descriptionText], move="up") self.rectangularWall(x, y, "ffff", callback=[lambda: self.drillholes(description=True)], move="right")