fix center absolute

This commit is contained in:
Mats van Reenen 2020-07-29 11:45:39 +02:00
parent b0601fcc95
commit 076bc30775
3 changed files with 75 additions and 16 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
/models
*.step
*.stl

View File

@ -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)

View File

@ -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):