Exports a "+" shaped compound box and then imports it again. :param importType: The type of file we're importing (STEP, STL, etc) :param fileName: The path and name of the file to write to
(self, importType, fileName)
| 49 | self.assertAlmostEqual(importedShape.findSolid().Volume(), 6) |
| 50 | |
| 51 | def importCompound(self, importType, fileName): |
| 52 | """ |
| 53 | Exports a "+" shaped compound box and then imports it again. |
| 54 | :param importType: The type of file we're importing (STEP, STL, etc) |
| 55 | :param fileName: The path and name of the file to write to |
| 56 | """ |
| 57 | # We first need to build a simple shape to export |
| 58 | b1 = Workplane("XY").box(1, 2, 3).val() |
| 59 | b2 = Workplane("XZ").box(1, 2, 3).val() |
| 60 | shape = Compound.makeCompound([b1, b2]) |
| 61 | |
| 62 | if importType == importers.ImportTypes.STEP: |
| 63 | # Export the shape to a temporary file |
| 64 | shape.exportStep(fileName) |
| 65 | elif importType == importers.ImportTypes.BREP: |
| 66 | shape.exportBrep(fileName) |
| 67 | elif importType == importers.ImportTypes.BIN: |
| 68 | shape.exportBin(fileName) |
| 69 | |
| 70 | # Reimport the shape from the new file |
| 71 | importedShape = importers.importShape(importType, fileName) |
| 72 | |
| 73 | # Check to make sure we got the shapes we expected. |
| 74 | self.assertTrue(importedShape.val().isValid()) |
| 75 | self.assertEqual(importedShape.val().ShapeType(), "Compound") |
| 76 | self.assertEqual(len(importedShape.objects), 1) |
| 77 | |
| 78 | # Check the number of faces and vertices per face to make sure we have |
| 79 | # two boxes. |
| 80 | self.assertNFacesAndNVertices(importedShape, (2, 2, 2), (8, 8, 8)) |
| 81 | |
| 82 | # Check that the volume is the independent sum of the two boxes' 6mm^2 |
| 83 | # volumes. |
| 84 | self.assertAlmostEqual(importedShape.findSolid().Volume(), 12) |
| 85 | |
| 86 | # Join the boxes together and ensure that they are geometrically where |
| 87 | # we expected them to be. This should be a workplane containing a |
| 88 | # compound composed of a single Solid. |
| 89 | fusedShape = Workplane("XY").newObject(importedShape.val().fuse()) |
| 90 | |
| 91 | # Check to make sure we got a valid shape |
| 92 | self.assertTrue(fusedShape.val().isValid()) |
| 93 | |
| 94 | # Check the number of faces and vertices per face to make sure we have |
| 95 | # two boxes. |
| 96 | self.assertNFacesAndNVertices(fusedShape, (5, 3, 3), (12, 12, 12)) |
| 97 | |
| 98 | # Check that the volume accounts for the overlap of the two shapes. |
| 99 | self.assertAlmostEqual(fusedShape.findSolid().Volume(), 8) |
| 100 | |
| 101 | def assertNFacesAndNVertices(self, workplane, nFacesXYZ, nVerticesXYZ): |
| 102 | """ |
no test coverage detected