PDN: Add tests for Boolean, MultiTransform, Primitives, Shapebinder

This commit is contained in:
Kurt Kremitzki
2017-07-25 05:17:17 -05:00
committed by wmayer
parent 31ef895be3
commit b5682d92ed
7 changed files with 395 additions and 4 deletions

View File

@@ -155,14 +155,18 @@ SET(PartDesign_Scripts
Scripts/Spring.py
PartDesignTests/__init__.py
PartDesignTests/TestDatum.py
PartDesignTests/TestShapeBinder.py
PartDesignTests/TestPad.py
PartDesignTests/TestPocket.py
PartDesignTests/TestRevolve.py
PartDesignTests/TestLoft.py
PartDesignTests/TestPipe.py
PartDesignTests/TestPrimitive.py
PartDesignTests/TestMirrored.py
PartDesignTests/TestLinearPattern.py
PartDesignTests/TestPolarPattern.py
PartDesignTests/TestMultiTransform.py
PartDesignTests/TestBoolean.py
PartDesignTests/TestFillet.py
PartDesignTests/TestChamfer.py
PartDesignTests/TestDraft.py

View File

@@ -35,14 +35,18 @@ INSTALL(
FILES
PartDesignTests/__init__.py
PartDesignTests/TestDatum.py
PartDesignTests/TestShapeBinder.py
PartDesignTests/TestPad.py
PartDesignTests/TestPocket.py
PartDesignTests/TestRevolve.py
PartDesignTests/TestLoft.py
PartDesignTests/TestPipe.py
PartDesignTests/TestPrimitive.py
PartDesignTests/TestMirrored.py
PartDesignTests/TestLinearPattern.py
PartDesignTests/TestPolarPattern.py
PartDesignTests/TestMultiTransform.py
PartDesignTests/TestBoolean.py
PartDesignTests/TestFillet.py
PartDesignTests/TestChamfer.py
PartDesignTests/TestDraft.py

View File

@@ -0,0 +1,107 @@
# (c) Juergen Riegel (FreeCAD@juergen-riegel.net) 2011 LGPL *
# *
# This file is part of the FreeCAD CAx development system. *
# *
# This program is free software; you can redistribute it and/or modify *
# it under the terms of the GNU Lesser General Public License (LGPL) *
# as published by the Free Software Foundation; either version 2 of *
# the License, or (at your option) any later version. *
# for detail see the LICENCE text file. *
# *
# FreeCAD is distributed in the hope that it will be useful, *
# but WITHOUT ANY WARRANTY; without even the implied warranty of *
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# GNU Library General Public License for more details. *
# *
# You should have received a copy of the GNU Library General Public *
# License along with FreeCAD; if not, write to the Free Software *
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# USA *
#**************************************************************************
import unittest
import FreeCAD
App = FreeCAD
class TestBoolean(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("PartDesignTestBoolean")
def testBooleanFuseCase(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Box = self.Doc.addObject('PartDesign::AdditiveBox','Box')
self.Box.Length=10
self.Box.Width=10
self.Box.Height=10
self.Body.addObject(self.Box)
self.Doc.recompute()
self.Body001 = self.Doc.addObject('PartDesign::Body','Body001')
self.Box001 = self.Doc.addObject('PartDesign::AdditiveBox','Box001')
self.Box001.Length=10
self.Box001.Width=10
self.Box001.Height=10
self.Box001.Placement.Base = App.Vector(-5,0,0)
self.Body001.addObject(self.Box001)
self.Doc.recompute()
self.BooleanFuse = self.Doc.addObject('PartDesign::Boolean','BooleanFuse')
self.Body001.addObject(self.BooleanFuse)
self.Doc.recompute()
self.BooleanFuse.Bodies = [self.Body,]
self.BooleanFuse.Type = 0
self.Doc.recompute()
self.assertAlmostEqual(self.BooleanFuse.Shape.Volume, 1500)
def testBooleanCutCase(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Box = self.Doc.addObject('PartDesign::AdditiveBox','Box')
self.Box.Length=10
self.Box.Width=10
self.Box.Height=10
self.Body.addObject(self.Box)
self.Doc.recompute()
self.Body001 = self.Doc.addObject('PartDesign::Body','Body001')
self.Box001 = self.Doc.addObject('PartDesign::AdditiveBox','Box001')
self.Box001.Length=10
self.Box001.Width=10
self.Box001.Height=10
self.Box001.Placement.Base = App.Vector(-5,0,0)
self.Body001.addObject(self.Box001)
self.Doc.recompute()
self.BooleanCut = self.Doc.addObject('PartDesign::Boolean','BooleanCut')
self.Body001.addObject(self.BooleanCut)
self.Doc.recompute()
self.BooleanCut.Bodies = [self.Body,]
self.BooleanCut.Type = 1
self.Doc.recompute()
self.assertAlmostEqual(self.BooleanCut.Shape.Volume, 500)
def testBooleanCommonCase(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Box = self.Doc.addObject('PartDesign::AdditiveBox','Box')
self.Box.Length=10
self.Box.Width=10
self.Box.Height=10
self.Body.addObject(self.Box)
self.Doc.recompute()
self.Body001 = self.Doc.addObject('PartDesign::Body','Body001')
self.Box001 = self.Doc.addObject('PartDesign::AdditiveBox','Box001')
self.Box001.Length=10
self.Box001.Width=10
self.Box001.Height=10
self.Box001.Placement.Base = App.Vector(-5,0,0)
self.Body001.addObject(self.Box001)
self.Doc.recompute()
self.BooleanCommon = self.Doc.addObject('PartDesign::Boolean','BooleanCommon')
self.Body001.addObject(self.BooleanCommon)
self.Doc.recompute()
self.BooleanCommon.Bodies = [self.Body,]
self.BooleanCommon.Type = 2
self.Doc.recompute()
self.assertAlmostEqual(self.BooleanCommon.Shape.Volume, 500)
def tearDown(self):
#closing doc
FreeCAD.closeDocument("PartDesignTestBoolean")
#print ("omit closing document for debugging")

View File

@@ -0,0 +1,68 @@
# (c) Juergen Riegel (FreeCAD@juergen-riegel.net) 2011 LGPL *
# *
# This file is part of the FreeCAD CAx development system. *
# *
# This program is free software; you can redistribute it and/or modify *
# it under the terms of the GNU Lesser General Public License (LGPL) *
# as published by the Free Software Foundation; either version 2 of *
# the License, or (at your option) any later version. *
# for detail see the LICENCE text file. *
# *
# FreeCAD is distributed in the hope that it will be useful, *
# but WITHOUT ANY WARRANTY; without even the implied warranty of *
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# GNU Library General Public License for more details. *
# *
# You should have received a copy of the GNU Library General Public *
# License along with FreeCAD; if not, write to the Free Software *
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# USA *
#**************************************************************************
import unittest
import FreeCAD
import TestSketcherApp
App = FreeCAD
class TestMultiTransform(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("PartDesignTestMultiTransform")
def testMultiTransform(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
# Make first offset cube Pad
self.PadSketch = self.Doc.addObject('Sketcher::SketchObject', 'SketchPad')
self.Body.addObject(self.PadSketch)
TestSketcherApp.CreateRectangleSketch(self.PadSketch, (0, 0), (10, 10))
self.Doc.recompute()
self.Pad = self.Doc.addObject("PartDesign::Pad", "Pad")
self.Body.addObject(self.Pad)
self.Pad.Profile = self.PadSketch
self.Pad.Length = 10
self.Doc.recompute()
self.MultiTransform = self.Doc.addObject("PartDesign::MultiTransform","MultiTransform")
self.Doc.recompute()
self.MultiTransform.Originals = [self.Pad]
self.MultiTransform.Shape = self.Pad.Shape
self.Body.addObject(self.MultiTransform)
self.Doc.recompute()
self.Mirrored = self.Doc.addObject("PartDesign::Mirrored","Mirrored")
self.Mirrored.MirrorPlane = (self.PadSketch, ["H_Axis"])
self.LinearPattern = self.Doc.addObject("PartDesign::LinearPattern","LinearPattern")
self.LinearPattern.Direction = (self.PadSketch, ["H_Axis"])
self.LinearPattern.Length = 20
self.LinearPattern.Occurrences = 3
self.PolarPattern = self.Doc.addObject("PartDesign::PolarPattern","PolarPattern")
self.PolarPattern.Axis = (self.PadSketch, ["N_Axis"])
self.PolarPattern.Angle = 360
self.PolarPattern.Occurrences = 4
self.MultiTransform.Transformations = [self.Mirrored,self.LinearPattern,self.PolarPattern]
self.Doc.recompute()
self.assertAlmostEqual(self.MultiTransform.Shape.Volume, 20000)
def tearDown(self):
#closing doc
FreeCAD.closeDocument("PartDesignTestMultiTransform")
#print ("omit closing document for debugging")

View File

@@ -0,0 +1,159 @@
# (c) Juergen Riegel (FreeCAD@juergen-riegel.net) 2011 LGPL *
# *
# This file is part of the FreeCAD CAx development system. *
# *
# This program is free software; you can redistribute it and/or modify *
# it under the terms of the GNU Lesser General Public License (LGPL) *
# as published by the Free Software Foundation; either version 2 of *
# the License, or (at your option) any later version. *
# for detail see the LICENCE text file. *
# *
# FreeCAD is distributed in the hope that it will be useful, *
# but WITHOUT ANY WARRANTY; without even the implied warranty of *
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# GNU Library General Public License for more details. *
# *
# You should have received a copy of the GNU Library General Public *
# License along with FreeCAD; if not, write to the Free Software *
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# USA *
#**************************************************************************
from math import pi, sqrt
import unittest
import FreeCAD
class TestPrimitive(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("PartDesignTestPrimitive")
def testPrimitiveBox(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Box = self.Doc.addObject('PartDesign::AdditiveBox','Box')
self.Box.Length = 11
self.Box.Width = 11
self.Box.Height = 11
self.Body.addObject(self.Box)
self.Doc.recompute()
self.Box001 = self.Doc.addObject('PartDesign::SubtractiveBox','Box001')
self.Box001.Length = 10
self.Box001.Width = 10
self.Box001.Height = 10
self.Body.addObject(self.Box001)
self.Doc.recompute()
self.assertAlmostEqual(self.Box001.Shape.Volume, 11**3-10**3)
def testPrimitiveCylinder(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Cylinder = self.Doc.addObject('PartDesign::AdditiveCylinder','Cylinder')
self.Cylinder.Radius = 11
self.Cylinder.Height = 10
self.Cylinder.Angle = 360
self.Body.addObject(self.Cylinder)
self.Doc.recompute()
self.Cylinder001 = self.Doc.addObject('PartDesign::SubtractiveCylinder','Cylinder001')
self.Cylinder001.Radius = 10
self.Cylinder001.Height = 10
self.Cylinder001.Angle = 360
self.Body.addObject(self.Cylinder001)
self.Doc.recompute()
self.assertAlmostEqual(self.Cylinder001.Shape.Volume, pi * 10 * (11**2 - 10**2))
def testPrimitiveSphere(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Sphere = self.Doc.addObject('PartDesign::AdditiveSphere','Sphere')
self.Sphere.Radius = 6
self.Body.addObject(self.Sphere)
self.Doc.recompute()
self.Sphere001 = self.Doc.addObject('PartDesign::SubtractiveSphere','Sphere001')
self.Sphere001.Radius = 5
self.Body.addObject(self.Sphere001)
self.Doc.recompute()
self.assertAlmostEqual(self.Sphere001.Shape.Volume, 4/3.0 * pi * (6**3 - 5**3))
def testPrimitiveCone(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Cone = self.Doc.addObject('PartDesign::AdditiveCone','Cone')
self.Cone.Radius1 = 0
self.Cone.Radius2 = 4
self.Cone.Height = 10
self.Body.addObject(self.Cone)
self.Doc.recompute()
self.Cone001 = self.Doc.addObject('PartDesign::SubtractiveCone','Cone')
self.Cone001.Radius1 = 0
self.Cone001.Radius2 = 3
self.Cone001.Height = 10
self.Body.addObject(self.Cone001)
self.Doc.recompute()
self.assertAlmostEqual(self.Cone001.Shape.Volume, 1/3.0 * pi * 10 * (4**2 - 3**2))
def testPrimitiveEllipsoid(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Ellipsoid = self.Doc.addObject('PartDesign::AdditiveEllipsoid','Ellipsoid')
self.Ellipsoid.Radius1 = 2
self.Ellipsoid.Radius2 = 4
self.Body.addObject(self.Ellipsoid)
self.Doc.recompute()
self.Ellipsoid001 = self.Doc.addObject('PartDesign::SubtractiveEllipsoid','Ellipsoid001')
self.Ellipsoid001.Radius1 = 2
self.Ellipsoid001.Radius2 = 3
self.Body.addObject(self.Ellipsoid001)
self.Doc.recompute()
self.assertAlmostEqual(self.Ellipsoid001.Shape.Volume, 4/3.0 * pi * 2 * (4**2 - 3**2), places=1)
def testPrimitiveTorus(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Torus = self.Doc.addObject('PartDesign::AdditiveTorus','Torus')
self.Torus.Radius1 = 10
self.Torus.Radius2 = 4
self.Body.addObject(self.Torus)
self.Doc.recompute()
self.Torus001 = self.Doc.addObject('PartDesign::SubtractiveTorus','Torus001')
self.Torus001.Radius1 = 10
self.Torus001.Radius2 = 3
self.Body.addObject(self.Torus001)
self.Doc.recompute()
self.assertAlmostEqual(self.Torus001.Shape.Volume, 2 * pi**2 * 10 * (4**2 - 3**2))
def testPrimitivePrism(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Prism = self.Doc.addObject('PartDesign::AdditivePrism','Prism')
self.Prism.Polygon = 6
self.Prism.Circumradius = 4
self.Prism.Height = 10
self.Body.addObject(self.Prism)
self.Doc.recompute()
self.Prism001 = self.Doc.addObject('PartDesign::SubtractivePrism','Prism001')
self.Prism001.Polygon = 6
self.Prism001.Circumradius = 3
self.Prism001.Height = 10
self.Body.addObject(self.Prism001)
self.Doc.recompute()
self.assertAlmostEqual(self.Prism001.Shape.Volume, 3*sqrt(3)/2.0 * 10 * (4**2 - 3**2))
def testPrimitiveWedge(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Wedge = self.Doc.addObject('PartDesign::AdditiveWedge','Wedge')
self.Wedge.X2min = 5
self.Wedge.X2max = 5
self.Wedge.Z2min = 0
self.Wedge.Z2max = 10
self.Body.addObject(self.Wedge)
self.Doc.recompute()
self.Wedge001 = self.Doc.addObject('PartDesign::SubtractiveWedge','Wedge001')
self.Wedge001.Xmin = 1
self.Wedge001.Xmax = 9
self.Wedge001.Ymax = 9
self.Wedge001.X2min = 5
self.Wedge001.X2max = 5
self.Wedge001.Z2min = 0
self.Wedge001.Z2max = 10
self.Body.addObject(self.Wedge001)
self.Doc.recompute()
self.assertAlmostEqual(self.Wedge001.Shape.Volume, 1/2.0 * (10*10 - 9*8) * 10)
def tearDown(self):
#closing doc
FreeCAD.closeDocument("PartDesignTestPrimitive")
#print ("omit closing document for debugging")

View File

@@ -0,0 +1,49 @@
# (c) Juergen Riegel (FreeCAD@juergen-riegel.net) 2011 LGPL *
# *
# This file is part of the FreeCAD CAx development system. *
# *
# This program is free software; you can redistribute it and/or modify *
# it under the terms of the GNU Lesser General Public License (LGPL) *
# as published by the Free Software Foundation; either version 2 of *
# the License, or (at your option) any later version. *
# for detail see the LICENCE text file. *
# *
# FreeCAD is distributed in the hope that it will be useful, *
# but WITHOUT ANY WARRANTY; without even the implied warranty of *
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# GNU Library General Public License for more details. *
# *
# You should have received a copy of the GNU Library General Public *
# License along with FreeCAD; if not, write to the Free Software *
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# USA *
#**************************************************************************
import unittest
import FreeCAD
class TestShapeBinder(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("PartDesignTestShapeBinder")
def testTwoBodyShapeBinderCase(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Box = self.Doc.addObject('PartDesign::AdditiveBox','Box')
self.Box.Length=1
self.Box.Width=1
self.Box.Height=1
self.Body.addObject(self.Box)
self.Doc.recompute()
self.Body001 = self.Doc.addObject('PartDesign::Body','Body001')
self.ShapeBinder = self.Doc.addObject('PartDesign::ShapeBinder','ShapeBinder')
self.ShapeBinder.Support = [(self.Box, 'Face1')]
self.Body001.addObject(self.ShapeBinder)
self.Doc.recompute()
self.assertIn('Box', self.ShapeBinder.OutList[0].Label)
self.assertIn('Body001', self.ShapeBinder.InList[0].Label)
def tearDown(self):
#closing doc
FreeCAD.closeDocument("PartDesignTestShapeBinder")
#print ("omit closing document for debugging")

View File

@@ -25,7 +25,7 @@
# datum tools
from PartDesignTests.TestDatum import TestDatumPoint, TestDatumLine, TestDatumPlane
#from PartDesignTests.TestShapeBinder import TestShapeBinder
from PartDesignTests.TestShapeBinder import TestShapeBinder
# additive/subtractive features & primitives
from PartDesignTests.TestPad import TestPad
@@ -33,14 +33,14 @@ from PartDesignTests.TestPocket import TestPocket
from PartDesignTests.TestRevolve import TestRevolve
from PartDesignTests.TestPipe import TestPipe
from PartDesignTests.TestLoft import TestLoft
#from PartDesignTests.TestPrimitive import TestPrimitive
from PartDesignTests.TestPrimitive import TestPrimitive
# transformations and boolean
from PartDesignTests.TestMirrored import TestMirrored
from PartDesignTests.TestLinearPattern import TestLinearPattern
from PartDesignTests.TestPolarPattern import TestPolarPattern
#from PartDesignTests.TestMultiTransform import TestMultiTransform
#from PartDesignTests.TestBoolean import TestBoolean
from PartDesignTests.TestMultiTransform import TestMultiTransform
from PartDesignTests.TestBoolean import TestBoolean
# dressup features
from PartDesignTests.TestFillet import TestFillet