2
# ***************************************************************************
3
# * Copyright (c) 2017 sliptonic <shopinthewoods@gmail.com> *
5
# * This program is free software; you can redistribute it and/or modify *
6
# * it under the terms of the GNU Lesser General Public License (LGPL) *
7
# * as published by the Free Software Foundation; either version 2 of *
8
# * the License, or (at your option) any later version. *
9
# * for detail see the LICENCE text file. *
11
# * This program is distributed in the hope that it will be useful, *
12
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
# * GNU Library General Public License for more details. *
16
# * You should have received a copy of the GNU Library General Public *
17
# * License along with this program; if not, write to the Free Software *
18
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
21
# ***************************************************************************
24
import Path.Base.Util as PathUtil
27
from Tests.PathTestUtils import PathTestBase
30
class TestPathUtil(PathTestBase):
32
self.doc = FreeCAD.newDocument("TestPathUtils")
35
FreeCAD.closeDocument("TestPathUtils")
38
"""Check that isValidBaseObject detects solids."""
39
box = self.doc.addObject("Part::Box", "Box")
40
cylinder = self.doc.addObject("Part::Cylinder", "Cylinder")
42
self.assertTrue(PathUtil.isValidBaseObject(box))
43
self.assertTrue(PathUtil.isValidBaseObject(cylinder))
46
"""Check that isValidBaseObject detects PDs."""
47
body = self.doc.addObject("PartDesign::Body", "Body")
48
box = self.doc.addObject("PartDesign::AdditiveBox", "Box")
51
self.assertTrue(PathUtil.isValidBaseObject(body))
54
"""Check that isValidBaseObject detects compounds."""
55
box = self.doc.addObject("Part::Box", "Box")
59
box.Placement = FreeCAD.Placement(
60
FreeCAD.Vector(-5, -5, 0), FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), 0)
62
cyl = self.doc.addObject("Part::Cylinder", "Cylinder")
65
box.Placement = FreeCAD.Placement(
66
FreeCAD.Vector(0, 0, -5), FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), 0)
68
cut = self.doc.addObject("Part::Cut", "Cut")
72
self.assertTrue(PathUtil.isValidBaseObject(cut))
75
"""Check that isValidBaseObject ignores sketches."""
76
body = self.doc.addObject("PartDesign::Body", "Body")
77
sketch = self.doc.addObject("Sketcher::SketchObject", "Sketch")
78
body.addObject(sketch)
79
TestSketcherApp.CreateSlotPlateSet(sketch)
81
pad = self.doc.addObject("PartDesign::Pad", "Pad")
87
self.assertTrue(PathUtil.isValidBaseObject(body))
89
# the pad inside the body cannot be used due to the linking constraints
90
self.assertFalse(PathUtil.isValidBaseObject(pad))
92
# the sketch is no good neither
93
self.assertFalse(PathUtil.isValidBaseObject(sketch))
96
"""Check that Part is handled correctly."""
97
part = self.doc.addObject("App::Part", "Part")
99
# an empty part is not a valid base object
100
self.assertFalse(PathUtil.isValidBaseObject(part))
102
# a non-empty part where none of the objects have a shape, is no good either
103
fp = self.doc.addObject("App::FeaturePython", "Feature")
105
self.assertFalse(PathUtil.isValidBaseObject(part))
107
# create a valid base object
108
box = self.doc.addObject("Part::Box", "Box")
110
self.assertTrue(PathUtil.isValidBaseObject(box))
112
# a part with at least one valid object is valid
114
self.assertTrue(PathUtil.isValidBaseObject(part))
116
# however, the object itself is no longer valid
117
self.assertFalse(PathUtil.isValidBaseObject(box))