#!/bin/python import cadquery as cq import base64 import subprocess import math from mathobjects import * pannelSize = Vec(400, 300, 5) tool = 4 def drowOnPos(f, pos, fn): f = f.center(pos.x - f.plane.origin[0], pos.y - f.plane.origin[1], pos.z - f.plane.origin[2]) return fn(f) def rectWitchInsideRadius(f, w, h, r): cs = math.sqrt(2) * r f = f.center(w/2 - cs, h/2 - cs) f = f.threePointArc((cs, 0), (cs, -cs)) f = f.lineTo(cs, -(h - cs)) f = f.threePointArc((cs, -h), (0, -h)) f = f.lineTo(-(w - 2*cs), -h) f = f.threePointArc((-(w-cs), -h), (-(w-cs), -(h-cs))) f = f.lineTo(-(w-cs), -cs) f = f.threePointArc((-(w-cs), 0), (-(w-2*cs), 0)) f = f.close() f = f.center(-w/2 + cs, -h/2 + cs) return f def holeWithFlets(f, r, fw): fl = math.sqrt(math.pow(r, 2) - math.pow(fw/2, 2)) f = f.center(fw/2, fl/2) f = f.threePointArc((-fw/2, r - fl/2), (-fw, 0)) f = f.lineTo(-fw, -fl) f = f.threePointArc((-fw/2, -(fl/2 + r)), (0, -fl)) f = f.close() f = f.center(-fw/2, -fl/2) return f def femailBananaConnHole(f): return holeWithFlets(f, 6, 10.5) def LPSCut(f): global pannelSize, tool displaySize = (77, 39) clearence = 15 connPoss = [displaySize[0]/3, displaySize[1]/2 + 30] # display f = f.center(0, 10) f = rectWitchInsideRadius(f, displaySize[0], displaySize[1], tool/2) # connectors f = f.center(connPoss[0], -connPoss[1]) f = femailBananaConnHole(f) f = f.center(-2*connPoss[0], 0) f = femailBananaConnHole(f) # f = f.center() return f def LPSText(f): f = f.rect(95, 50) def frontPannle(): global pannelSize f = cq.Workplane('XZ') LPSPos = Vec(125, 0, 100) f = f.rect(pannelSize.x, pannelSize.z) f = drowOnPos(f, LPSPos, LPSCut) f = f.extrude(pannelSize.y) f = drowOnPos(f, LPSPos, LPSText) return f f = frontPannle() cq.exporters.exportShape(f, 'STEP', open('front.step', 'w')) subprocess.run(["/usr/lib64/freecad/bin/FreeCAD", './front.step']) # svg = f.toSvg().encode('ascii') # svg = base64.b64encode(svg) # url = 'data:image/svg+xml;base64,' + svg.decode('ascii') # subprocess.run(["firefox", url])