FreeCAD

Форк
0
/
TestPathUtil.py 
117 строк · 4.9 Кб
1
# -*- coding: utf-8 -*-
2
# ***************************************************************************
3
# *   Copyright (c) 2017 sliptonic <shopinthewoods@gmail.com>               *
4
# *                                                                         *
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.                                 *
10
# *                                                                         *
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.                  *
15
# *                                                                         *
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  *
19
# *   USA                                                                   *
20
# *                                                                         *
21
# ***************************************************************************
22

23
import FreeCAD
24
import Path.Base.Util as PathUtil
25
import TestSketcherApp
26

27
from Tests.PathTestUtils import PathTestBase
28

29

30
class TestPathUtil(PathTestBase):
31
    def setUp(self):
32
        self.doc = FreeCAD.newDocument("TestPathUtils")
33

34
    def tearDown(self):
35
        FreeCAD.closeDocument("TestPathUtils")
36

37
    def test00(self):
38
        """Check that isValidBaseObject detects solids."""
39
        box = self.doc.addObject("Part::Box", "Box")
40
        cylinder = self.doc.addObject("Part::Cylinder", "Cylinder")
41
        self.doc.recompute()
42
        self.assertTrue(PathUtil.isValidBaseObject(box))
43
        self.assertTrue(PathUtil.isValidBaseObject(cylinder))
44

45
    def test01(self):
46
        """Check that isValidBaseObject detects PDs."""
47
        body = self.doc.addObject("PartDesign::Body", "Body")
48
        box = self.doc.addObject("PartDesign::AdditiveBox", "Box")
49
        body.addObject(box)
50
        self.doc.recompute()
51
        self.assertTrue(PathUtil.isValidBaseObject(body))
52

53
    def test02(self):
54
        """Check that isValidBaseObject detects compounds."""
55
        box = self.doc.addObject("Part::Box", "Box")
56
        box.Length = 10
57
        box.Width = 10
58
        box.Height = 1
59
        box.Placement = FreeCAD.Placement(
60
            FreeCAD.Vector(-5, -5, 0), FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), 0)
61
        )
62
        cyl = self.doc.addObject("Part::Cylinder", "Cylinder")
63
        cyl.Radius = 1
64
        cyl.Height = 10
65
        box.Placement = FreeCAD.Placement(
66
            FreeCAD.Vector(0, 0, -5), FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), 0)
67
        )
68
        cut = self.doc.addObject("Part::Cut", "Cut")
69
        cut.Base = box
70
        cut.Tool = cyl
71
        self.doc.recompute()
72
        self.assertTrue(PathUtil.isValidBaseObject(cut))
73

74
    def test03(self):
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)
80
        self.doc.recompute()
81
        pad = self.doc.addObject("PartDesign::Pad", "Pad")
82
        body.addObject(pad)
83
        pad.Profile = sketch
84
        self.doc.recompute()
85

86
        # the body is a solid
87
        self.assertTrue(PathUtil.isValidBaseObject(body))
88

89
        # the pad inside the body cannot be used due to the linking constraints
90
        self.assertFalse(PathUtil.isValidBaseObject(pad))
91

92
        # the sketch is no good neither
93
        self.assertFalse(PathUtil.isValidBaseObject(sketch))
94

95
    def test04(self):
96
        """Check that Part is handled correctly."""
97
        part = self.doc.addObject("App::Part", "Part")
98

99
        # an empty part is not a valid base object
100
        self.assertFalse(PathUtil.isValidBaseObject(part))
101

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")
104
        part.addObject(fp)
105
        self.assertFalse(PathUtil.isValidBaseObject(part))
106

107
        # create a valid base object
108
        box = self.doc.addObject("Part::Box", "Box")
109
        self.doc.recompute()
110
        self.assertTrue(PathUtil.isValidBaseObject(box))
111

112
        # a part with at least one valid object is valid
113
        part.addObject(box)
114
        self.assertTrue(PathUtil.isValidBaseObject(part))
115

116
        # however, the object itself is no longer valid
117
        self.assertFalse(PathUtil.isValidBaseObject(box))
118

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.