This repository has been archived on 2025-01-25. You can view files and clone it, but cannot push or open issues or pull requests.
labvoeding-front/front.py
2020-07-29 11:45:39 +02:00

131 lines
2.9 KiB
Python
Executable File

#!/bin/python
import cadquery as cq
import base64
import subprocess
import math
from mathobjects import *
pannelSize = Vec(400, 5, 300)
tool = 4
def getPlaneCorts(plane, vec):
plane = plane.lower()
if(plane == 'xy'):
return Vec(vec.x, vec.y)
if(plane == 'xz'):
return Vec(vec.x, vec.z)
if(plane == 'yx'):
return Vec(vec.y, vec.x)
if(plane == 'yz'):
return Vec(vec.y, vec.z)
if(plane == 'zx'):
return Vec(vec.z, vec.x)
if(plane == 'zy'):
return Vec(vec.z, vec.y)
def centerAbs(f, pos, plane):
relative = pos - getPlaneCorts(plane, f.plane.origin)
return f.center(relative.x, relative.y)
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)
# ========================================================================
# == Lab power suply (LPS) ===============================================
# ========================================================================
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)
return f
# ========================================================================
# == front pannel ========================================================
# ========================================================================
def frontPannle():
global pannelSize
f = cq.Workplane('XZ')
LPSPos = Vec(125, 100)
f = f.rect(pannelSize.x, pannelSize.z)
f = centerAbs(f, LPSPos, 'XZ')
f = LPSCut(f)
f = f.extrude(pannelSize.y)
# f = centerAbs(f, LPSPos, 'XZ')
# f = LPSText(f)
return f
f = frontPannle()
cq.exporters.exportShape(f, 'STEP', open('./models/front.step', 'w'))
subprocess.run(["/usr/lib64/freecad/bin/FreeCAD", './models/front.step'])
# svg = f.toSvg().encode('ascii')
# svg = base64.b64encode(svg)
# url = 'data:image/svg+xml;base64,' + svg.decode('ascii')
# subprocess.run(["firefox", url])