| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | import unittest |
| |
|
| | import FreeCAD |
| | from pivy import coin |
| |
|
| | 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.setObjects( |
| | [ |
| | 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.setObjects( |
| | [ |
| | 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.setObjects( |
| | [ |
| | self.Body, |
| | ] |
| | ) |
| | self.BooleanCommon.Type = 2 |
| | self.Doc.recompute() |
| | self.assertAlmostEqual(self.BooleanCommon.Shape.Volume, 500) |
| |
|
| | def testBooleanSelectUI(self): |
| | if not App.GuiUp: |
| | return |
| | |
| | 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.Body002 = self.Doc.addObject("PartDesign::Body", "Body002") |
| | self.BooleanFuse = self.Doc.addObject("PartDesign::Boolean", "BooleanFuse") |
| | self.BooleanFuse.Group = [self.Body, self.Body001] |
| | self.BooleanFuse.ViewObject.Display = ( |
| | "Result" |
| | ) |
| | self.Body002.addObject(self.BooleanFuse) |
| | self.Doc.recompute() |
| | |
| | App.Gui.Selection.addSelection("", self.Body002.Name, "Face2") |
| | App.Gui.Selection.addSelection("", self.Body002.Name, "Face6") |
| | App.Gui.Selection.addSelection("", self.Body002.Name, "Face10") |
| | App.Gui.Selection.addSelection("", self.Body002.Name, "Face3") |
| | App.Gui.Selection.addSelection("", self.Body002.Name, "Face7") |
| | App.Gui.Selection.addSelection("", self.Body002.Name, "Face11") |
| | App.Gui.Selection.addSelection("", "Body002", "Face14") |
| | App.Gui.updateGui() |
| | |
| | self.assertEqual(len(App.Gui.Selection.getSelectionEx("", 0)[0].SubElementNames), 7) |
| | self.assertEqual( |
| | App.Gui.Selection.getSelectionEx("", 0)[0].SubElementNames[0][-8:], |
| | ",F.Face2", |
| | ) |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | def tearDown(self): |
| | if hasattr(App, "KeepTestDoc") and App.KeepTestDoc: |
| | return |
| | |
| | FreeCAD.closeDocument("PartDesignTestBoolean") |
| |
|