/
TestMirrored.py
93 lines (87 loc) · 4.43 KB
/
TestMirrored.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# (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
class TestMirrored(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("PartDesignTestMirrored")
def testMirroredSketchCase(self):
"""
Creates a unit cube cornered at the origin and mirrors it about the Y axis.
This operation should create a rectangular prism with volume 2.0.
"""
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Rect = self.Doc.addObject('Sketcher::SketchObject','Rect')
self.Body.addObject(self.Rect)
TestSketcherApp.CreateRectangleSketch(self.Rect, (0, 0), (1, 1))
self.Doc.recompute()
self.Pad = self.Doc.addObject("PartDesign::Pad","Pad")
self.Pad.Profile = self.Rect
self.Pad.Length = 1
self.Body.addObject(self.Pad)
self.Doc.recompute()
self.Mirrored = self.Doc.addObject("PartDesign::Mirrored","Mirrored")
self.Mirrored.Originals = [self.Pad]
self.Mirrored.MirrorPlane = (self.Rect, ["V_Axis"])
self.Body.addObject(self.Mirrored)
self.Doc.recompute()
self.assertAlmostEqual(self.Mirrored.Shape.Volume, 2.0)
def testMirroredPrimitiveCase(self):
"""
Tests the same mirroring scenario as in the sketch case,
but is designed to ensure the same end result occurs with
a different base object.
"""
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.Mirrored = self.Doc.addObject("PartDesign::Mirrored", "Mirrored")
self.Mirrored.Originals = [self.Box]
self.Mirrored.MirrorPlane = (self.Doc.XY_Plane, [""])
self.Body.addObject(self.Mirrored)
self.Doc.recompute()
self.assertAlmostEqual(self.Mirrored.Shape.Volume, 2.0)
def testMirroredOffsetFailureCase(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Rect = self.Doc.addObject('Sketcher::SketchObject','Rect')
self.Body.addObject(self.Rect)
TestSketcherApp.CreateRectangleSketch(self.Rect, (0, 1), (1, 1))
self.Doc.recompute()
self.Pad = self.Doc.addObject("PartDesign::Pad","Pad")
self.Pad.Profile = self.Rect
self.Pad.Length = 1
self.Body.addObject(self.Pad)
self.Doc.recompute()
self.Mirrored = self.Doc.addObject("PartDesign::Mirrored","Mirrored")
self.Mirrored.Originals = [self.Pad]
self.Mirrored.MirrorPlane = (self.Rect, ["H_Axis"])
self.Body.addObject(self.Mirrored)
self.Doc.recompute()
self.assertEqual(self.Mirrored.State, ["Invalid"])
def tearDown(self):
#closing doc
FreeCAD.closeDocument("PartDesignTestMirrored")
#print ("omit closing document for debugging")