2013-04-14 18:39:47 -04:00
|
|
|
from cadquery import *
|
2017-05-14 12:52:12 +02:00
|
|
|
from OCC.gp import gp_Vec
|
2013-04-14 18:39:47 -04:00
|
|
|
import unittest
|
|
|
|
import sys
|
2013-04-27 23:49:41 -07:00
|
|
|
import os
|
2013-04-14 18:39:47 -04:00
|
|
|
|
2017-09-17 00:57:12 +02:00
|
|
|
|
2013-04-14 18:39:47 -04:00
|
|
|
def readFileAsString(fileName):
|
2017-09-17 00:57:12 +02:00
|
|
|
f = open(fileName, 'r')
|
2013-04-14 18:39:47 -04:00
|
|
|
s = f.read()
|
|
|
|
f.close()
|
|
|
|
return s
|
|
|
|
|
2015-04-13 16:47:18 -04:00
|
|
|
|
|
|
|
def writeStringToFile(strToWrite, fileName):
|
|
|
|
f = open(fileName, 'w')
|
2013-04-14 18:39:47 -04:00
|
|
|
f.write(strToWrite)
|
|
|
|
f.close()
|
2013-04-27 23:49:41 -07:00
|
|
|
|
2013-04-14 18:39:47 -04:00
|
|
|
|
|
|
|
def makeUnitSquareWire():
|
2017-05-14 12:52:12 +02:00
|
|
|
V = Vector
|
|
|
|
return Wire.makePolygon([V(0, 0, 0), V(1, 0, 0), V(1, 1, 0), V(0, 1, 0), V(0, 0, 0)])
|
2015-04-13 16:47:18 -04:00
|
|
|
|
2013-04-14 18:39:47 -04:00
|
|
|
|
|
|
|
def makeUnitCube():
|
|
|
|
return makeCube(1.0)
|
|
|
|
|
2015-04-13 16:47:18 -04:00
|
|
|
|
2013-04-14 18:39:47 -04:00
|
|
|
def makeCube(size):
|
2015-04-13 16:47:18 -04:00
|
|
|
return Solid.makeBox(size, size, size)
|
|
|
|
|
2013-04-14 18:39:47 -04:00
|
|
|
|
|
|
|
def toTuple(v):
|
2015-04-13 16:47:18 -04:00
|
|
|
"""convert a vector or a vertex to a 3-tuple: x,y,z"""
|
2017-05-14 12:52:12 +02:00
|
|
|
if type(v) == gp_Vec:
|
|
|
|
return (v.X(), v.Y(), v.Z())
|
2013-04-14 18:39:47 -04:00
|
|
|
elif type(v) == Vector:
|
|
|
|
return v.toTuple()
|
|
|
|
else:
|
2017-09-17 00:57:12 +02:00
|
|
|
raise RuntimeError(
|
|
|
|
"dont know how to convert type %s to tuple" % str(type(v)))
|
2013-04-14 18:39:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
class BaseTest(unittest.TestCase):
|
|
|
|
|
2015-04-13 16:47:18 -04:00
|
|
|
def assertTupleAlmostEquals(self, expected, actual, places):
|
|
|
|
for i, j in zip(actual, expected):
|
2017-09-17 00:57:12 +02:00
|
|
|
self.assertAlmostEqual(i, j, places)
|
|
|
|
|
2013-04-16 22:29:06 -04:00
|
|
|
|
2017-09-17 00:57:12 +02:00
|
|
|
__all__ = ['TestCadObjects', 'TestCadQuery', 'TestCQSelectors', 'TestWorkplanes',
|
|
|
|
'TestExporters', 'TestCQSelectors', 'TestImporters', 'TestCQGI']
|