def testDXF(self): exporters.export(self._box().section(), "out.dxf") with self.assertRaises(ValueError): exporters.export(self._box().val(), "out.dxf") s1 = (Workplane("XZ").polygon(10, 10).ellipse( 1, 2).extrude(1).edges("|Y").fillet(1).section()) exporters.dxf.exportDXF(s1, "res1.dxf") s1_i = importers.importDXF("res1.dxf") self.assertAlmostEqual(s1.val().Area(), s1_i.val().Area(), 6) self.assertAlmostEqual(s1.edges().size(), s1_i.edges().size()) pts = [(0, 0), (0, 0.5), (1, 1)] s2 = (Workplane().spline(pts).close().extrude(1).edges("|Z").fillet( 0.1).section()) exporters.dxf.exportDXF(s2, "res2.dxf") s2_i = importers.importDXF("res2.dxf") self.assertAlmostEqual(s2.val().Area(), s2_i.val().Area(), 6) self.assertAlmostEqual(s2.edges().size(), s2_i.edges().size()) s3 = (Workplane("XY").ellipseArc( 1, 2, 0, 180).close().extrude(1).edges("|Z").fillet(0.1).section()) exporters.dxf.exportDXF(s3, "res3.dxf") s3_i = importers.importDXF("res3.dxf") self.assertAlmostEqual(s3.val().Area(), s3_i.val().Area(), 6) self.assertAlmostEqual(s3.edges().size(), s3_i.edges().size())
def testImportDXF(self): """ Test DXF import with various tolerances. """ filename = os.path.join(testdataDir, "gear.dxf") obj = importers.importDXF(filename) self.assertFalse(obj.val().isValid()) obj = importers.importDXF(filename, tol=1e-3) self.assertTrue(obj.val().isValid()) self.assertEqual(obj.faces().size(), 1) self.assertEqual(obj.wires().size(), 2) obj = obj.wires().toPending().extrude(1) self.assertTrue(obj.val().isValid()) self.assertEqual(obj.solids().size(), 1) obj = importers.importShape(importers.ImportTypes.DXF, filename, tol=1e-3) self.assertTrue(obj.val().isValid()) # additional files to test more DXF entities filename = os.path.join(testdataDir, "MC 12x31.dxf") obj = importers.importDXF(filename) self.assertTrue(obj.val().isValid()) filename = os.path.join(testdataDir, "1001.dxf") obj = importers.importDXF(filename) self.assertTrue(obj.val().isValid())
def testImportDXF(self): """ Test DXF import with various tolerances. """ filename = os.path.join(testdataDir, "gear.dxf") obj = importers.importDXF(filename) self.assertFalse(obj.val().isValid()) obj = importers.importDXF(filename, tol=1e-3) self.assertTrue(obj.val().isValid()) self.assertEqual(obj.faces().size(), 1) self.assertEqual(obj.wires().size(), 2) obj = obj.wires().toPending().extrude(1) self.assertTrue(obj.val().isValid()) self.assertEqual(obj.solids().size(), 1) obj = importers.importShape(importers.ImportTypes.DXF, filename, tol=1e-3) self.assertTrue(obj.val().isValid()) # additional files to test more DXF entities filename = os.path.join(testdataDir, "MC 12x31.dxf") obj = importers.importDXF(filename) self.assertTrue(obj.val().isValid()) filename = os.path.join(testdataDir, "1001.dxf") obj = importers.importDXF(filename) self.assertTrue(obj.val().isValid()) # test spline import filename = os.path.join(testdataDir, "spline.dxf") obj = importers.importDXF(filename, tol=1) self.assertTrue(obj.val().isValid()) self.assertEqual(obj.faces().size(), 1) self.assertEqual(obj.wires().size(), 2) # test rational spline import filename = os.path.join(testdataDir, "rational_spline.dxf") obj = importers.importDXF(filename) self.assertTrue(obj.val().isValid()) self.assertEqual(obj.faces().size(), 1) self.assertEqual(obj.edges().size(), 1) # importing of a complex shape exported from Inkscape filename = os.path.join(testdataDir, "genshi.dxf") obj = importers.importDXF(filename) self.assertTrue(obj.val().isValid()) self.assertEqual(obj.faces().size(), 1)
def testDXF(self): exporters.export(self._box().section(), "out.dxf") with self.assertRaises(ValueError): exporters.export(self._box().val(), "out.dxf") s1 = (Workplane("XZ").polygon(10, 10).ellipse( 1, 2).extrude(1).edges("|Y").fillet(1).section()) exporters.dxf.exportDXF(s1, "res1.dxf") s1_i = importers.importDXF("res1.dxf") self.assertAlmostEqual(s1.val().Area(), s1_i.val().Area(), 6) self.assertAlmostEqual(s1.edges().size(), s1_i.edges().size()) pts = [(0, 0), (0, 0.5), (1, 1)] s2 = (Workplane().spline(pts).close().extrude(1).edges("|Z").fillet( 0.1).section()) exporters.dxf.exportDXF(s2, "res2.dxf") s2_i = importers.importDXF("res2.dxf") self.assertAlmostEqual(s2.val().Area(), s2_i.val().Area(), 6) self.assertAlmostEqual(s2.edges().size(), s2_i.edges().size()) s3 = (Workplane("XY").ellipseArc( 1, 2, 0, 180).close().extrude(1).edges("|Z").fillet(0.1).section()) exporters.dxf.exportDXF(s3, "res3.dxf") s3_i = importers.importDXF("res3.dxf") self.assertAlmostEqual(s3.val().Area(), s3_i.val().Area(), 6) self.assertAlmostEqual(s3.edges().size(), s3_i.edges().size()) cyl = Workplane("XY").circle(22).extrude(10, both=True).translate( (-50, 0, 0)) s4 = Workplane("XY").box(80, 60, 5).cut(cyl).section() exporters.dxf.exportDXF(s4, "res4.dxf") s4_i = importers.importDXF("res4.dxf") self.assertAlmostEqual(s4.val().Area(), s4_i.val().Area(), 6) self.assertAlmostEqual(s4.edges().size(), s4_i.edges().size()) # test periodic spline w = Workplane().spline([(1, 1), (2, 2), (3, 2), (3, 1)], periodic=True) exporters.dxf.exportDXF(w, "res5.dxf") w_i = importers.importDXF("res5.dxf") self.assertAlmostEqual(w.val().Length(), w_i.wires().val().Length(), 6) # test rational spline c = Edge.makeCircle(1) adaptor = c._geomAdaptor() curve = GeomConvert.CurveToBSplineCurve_s(adaptor.Curve().Curve()) e = Workplane().add(Edge(BRepBuilderAPI_MakeEdge(curve).Shape())) exporters.dxf.exportDXF(e, "res6.dxf") e_i = importers.importDXF("res6.dxf") self.assertAlmostEqual(e.val().Length(), e_i.wires().val().Length(), 6) # test non-planar section s5 = (Workplane().spline([ (0, 0), (1, 0), (1, 1), (0, 1) ]).close().extrude(1, both=True).translate((-3, -4, 0))) s5.plane = Plane(origin=(0, 0.1, 0.5), normal=(0.05, 0.05, 1)) s5 = s5.section() exporters.dxf.exportDXF(s5, "res7.dxf") s5_i = importers.importDXF("res7.dxf") self.assertAlmostEqual(s5.val().Area(), s5_i.val().Area(), 4)
def testImportDXF(self): """ Test DXF import with various tolerances. """ filename = os.path.join(testdataDir, "gear.dxf") obj = importers.importDXF(filename) self.assertFalse(obj.val().isValid()) obj = importers.importDXF(filename, tol=1e-3) self.assertTrue(obj.val().isValid()) self.assertEqual(obj.faces().size(), 1) self.assertEqual(obj.wires().size(), 2) obj = obj.wires().toPending().extrude(1) self.assertTrue(obj.val().isValid()) self.assertEqual(obj.solids().size(), 1) obj = importers.importShape(importers.ImportTypes.DXF, filename, tol=1e-3) self.assertTrue(obj.val().isValid()) # additional files to test more DXF entities filename = os.path.join(testdataDir, "MC 12x31.dxf") obj = importers.importDXF(filename) self.assertTrue(obj.val().isValid()) filename = os.path.join(testdataDir, "1001.dxf") obj = importers.importDXF(filename) self.assertTrue(obj.val().isValid()) # test spline import filename = os.path.join(testdataDir, "spline.dxf") obj = importers.importDXF(filename, tol=1) self.assertTrue(obj.val().isValid()) self.assertEqual(obj.faces().size(), 1) self.assertEqual(obj.wires().size(), 2) # test rational spline import filename = os.path.join(testdataDir, "rational_spline.dxf") obj = importers.importDXF(filename) self.assertTrue(obj.val().isValid()) self.assertEqual(obj.faces().size(), 1) self.assertEqual(obj.edges().size(), 1) # importing of a complex shape exported from Inkscape filename = os.path.join(testdataDir, "genshi.dxf") obj = importers.importDXF(filename) self.assertTrue(obj.val().isValid()) self.assertEqual(obj.faces().size(), 1) # test layer filtering filename = os.path.join(testdataDir, "three_layers.dxf") obj = importers.importDXF(filename, exclude=["Layer2"]) self.assertTrue(obj.val().isValid()) self.assertEqual(obj.faces().size(), 2) self.assertEqual(obj.wires().size(), 2) # test dxf extrusion into the third dimension extrusion_value = 15.0 tmp = obj.wires() tmp.ctx.pendingWires = tmp.vals() threed = tmp.extrude(extrusion_value) self.assertEqual(threed.findSolid().BoundingBox().zlen, extrusion_value)