From 076bc30775e57bcc93af2d72360c78f79e509354 Mon Sep 17 00:00:00 2001 From: Mats van Reenen Date: Wed, 29 Jul 2020 11:45:39 +0200 Subject: [PATCH] fix center absolute --- .gitignore | 1 + front.py | 56 +++++++++++++++++++++++++++++++++++++++++--------- mathobjects.py | 34 ++++++++++++++++++++++++------ 3 files changed, 75 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 4e49371..e10f94e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ +/models *.step *.stl diff --git a/front.py b/front.py index 050fa01..92fa229 100755 --- a/front.py +++ b/front.py @@ -6,12 +6,32 @@ import subprocess import math from mathobjects import * -pannelSize = Vec(400, 300, 5) +pannelSize = Vec(400, 5, 300) 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 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 @@ -40,6 +60,12 @@ def holeWithFlets(f, r, fw): def femailBananaConnHole(f): return holeWithFlets(f, 6, 10.5) + + +# ======================================================================== +# == Lab power suply (LPS) =============================================== +# ======================================================================== + def LPSCut(f): global pannelSize, tool displaySize = (77, 39) @@ -61,30 +87,40 @@ def LPSCut(f): def LPSText(f): f = f.rect(95, 50) + return f + +# ======================================================================== +# == front pannel ======================================================== +# ======================================================================== + def frontPannle(): global pannelSize f = cq.Workplane('XZ') - LPSPos = Vec(125, 0, 100) + LPSPos = Vec(125, 100) f = f.rect(pannelSize.x, pannelSize.z) - f = drowOnPos(f, LPSPos, LPSCut) + f = centerAbs(f, LPSPos, 'XZ') + f = LPSCut(f) f = f.extrude(pannelSize.y) - f = drowOnPos(f, LPSPos, LPSText) + # f = centerAbs(f, LPSPos, 'XZ') + # f = LPSText(f) return f + + + f = frontPannle() -cq.exporters.exportShape(f, 'STEP', open('front.step', 'w')) - -subprocess.run(["/usr/lib64/freecad/bin/FreeCAD", './front.step']) +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) diff --git a/mathobjects.py b/mathobjects.py index ff02823..6c455a9 100755 --- a/mathobjects.py +++ b/mathobjects.py @@ -684,15 +684,15 @@ class Vec: def __add__(self, other): if isinstance(other, Vec): n = Vec() - n.x = self.y + other.z - n.y = self.z + other.x - n.z = self.x + other.y + n.x = self.x + other.x + n.y = self.y + other.y + n.z = self.z + other.z return n elif isinstance(other, (tuple, list)): n = Vec() - n.x = self.y + other[0] - n.y = self.z + other[1] - n.z = self.x + other[2] + n.x = self.x + other[0] + n.y = self.y + other[1] + n.z = self.z + other[2] return n elif isinstance(other, (float, int)): n = Vec(self.cartesian()) @@ -702,6 +702,27 @@ class Vec: print('WARNING: tried to add Vec with ' + str(type(other))) return other + def __sub__(self, other): + if isinstance(other, Vec): + n = Vec() + n.x = self.x - other.x + n.y = self.y - other.y + n.z = self.z - other.z + return n + elif isinstance(other, (tuple, list)): + n = Vec() + n.x = self.x - other[0] + n.y = self.y - other[1] + n.z = self.z - other[2] + return n + elif isinstance(other, (float, int)): + n = Vec(self.cartesian()) + n.length(self.length() - other) + return n + else: + print('WARNING: tried to add Vec with ' + str(type(other))) + return other + def __setitem__(self, index, value): if(index == 0): self.x = value @@ -724,6 +745,7 @@ class Vec: def __str__(self): return "Vec" + str(self.cartesian()) + #TODO: allow compare length of Vec with number def __lt__(self, other): return self.length() < other.length() def __le__(self, other):