|
| 1 | +import math |
| 2 | +import os |
| 3 | +import pyMagix3D as Mgx3D |
| 4 | +import pytest |
| 5 | + |
| 6 | +step_file_name = "mambo/Basic/B18.step" |
| 7 | + |
| 8 | +def assertPoint(tm, name, x, y, z): |
| 9 | + p = tm.getCoord(name) |
| 10 | + assert math.isclose(p.getX(), x, rel_tol=1e-10) |
| 11 | + assert math.isclose(p.getY(), y, rel_tol=1e-10) |
| 12 | + assert math.isclose(p.getZ(), z, rel_tol=1e-10) |
| 13 | + |
| 14 | +# Issue 225 : Le bloc créé par boite englobante d'un volume peut avoir de mauvaises dimensions |
| 15 | +def test_issue225(capfd): |
| 16 | + ctx = Mgx3D.getStdContext() |
| 17 | + ctx.clearSession() # Clean the session after the previous test |
| 18 | + gm = ctx.getGeomManager() |
| 19 | + tm = ctx.getTopoManager () |
| 20 | + |
| 21 | + magix3d_test_data_dir = os.environ['MAGIX3D_TEST_DATA_DIR'] |
| 22 | + full_path = os.path.join(magix3d_test_data_dir, step_file_name) |
| 23 | + |
| 24 | + ctx.setLengthUnit(Mgx3D.Unit.centimeter) |
| 25 | + gm.importSTEP(full_path) |
| 26 | + assert gm.getNbVolumes()==1 |
| 27 | + tm.newFreeTopoOnGeometry("Vol0000") |
| 28 | + assert math.isclose(tm.getEdgeLength("Ar0002"), 0.1, abs_tol=1e-7) #0.1 |
| 29 | + assert math.isclose(tm.getEdgeLength("Ar0007"), 0.1, abs_tol=1e-7) #0.10003610119179525 |
| 30 | + assert math.isclose(tm.getEdgeLength("Ar0009"), 0.05, abs_tol=1e-7) #0.05000000000000623 |
| 31 | + |
| 32 | +# Issue 262 : Le bloc créé par boite englobante d'un volume peut avoir de mauvaises dimensions |
| 33 | +# la création d'un bloc sur une sphère crée un bloc plat |
| 34 | +def test_issue262(): |
| 35 | + ctx = Mgx3D.getStdContext() |
| 36 | + ctx.clearSession() # Clean the session after the previous test |
| 37 | + gm = ctx.getGeomManager() |
| 38 | + tm = ctx.getTopoManager() |
| 39 | + # Création du volume Vol0000 |
| 40 | + gm.newSphere (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Portion.ENTIER) |
| 41 | + # Création d'un bloc topologique structuré sans projection (Vol0000) |
| 42 | + tm.newFreeTopoOnGeometry ("Vol0000") |
| 43 | + |
| 44 | + assertPoint(tm, "Som0000", -1, -1, -1) |
| 45 | + assertPoint(tm, "Som0007", 1, 1, 1) |
| 46 | + |
| 47 | + # Annulation de : Création d'un bloc topologique structuré sans projection (Vol0000) |
| 48 | + ctx.undo() |
| 49 | + # Création d'un bloc unitaire mis dans le groupe AAA |
| 50 | + ctx.getTopoManager().newFreeBoundedTopoInGroup ("AAA", 3, ["Vol0000"]) |
| 51 | + |
| 52 | + assertPoint(tm, "Som0000", -1, -1, -1) |
| 53 | + assertPoint(tm, "Som0007", 1, 1, 1) |
| 54 | + |
| 55 | +def test_freeboundedtopoForPoints(): |
| 56 | + ctx = Mgx3D.getStdContext() |
| 57 | + ctx.clearSession() # Clean the session after the previous test |
| 58 | + gm = ctx.getGeomManager () |
| 59 | + tm = ctx.getTopoManager () |
| 60 | + |
| 61 | + gm.newVertex(Mgx3D.Point(-1.8, -.7, 1.2)) |
| 62 | + gm.newVertex(Mgx3D.Point(-.7, .45, -.1)) |
| 63 | + tm.newFreeBoundedTopoInGroup ("aaa", 3, ["Pt0000","Pt0001"]) |
| 64 | + assertPoint(tm, "Som0007", -0.7, 0.45, 1.2) |
| 65 | + |
| 66 | +def test_freeboundedtopoForSphere(): |
| 67 | + ctx = Mgx3D.getStdContext() |
| 68 | + ctx.clearSession() # Clean the session after the previous test |
| 69 | + gm = ctx.getGeomManager () |
| 70 | + tm = ctx.getTopoManager () |
| 71 | + |
| 72 | + gm.newSphere (Mgx3D.Point(0, 0, 0), 1, 150) |
| 73 | + tm.newFreeTopoOnGeometry ("Vol0000") |
| 74 | + assertPoint(tm, "Som0007", 1.0, 1.0, 1.0) |
| 75 | + |
| 76 | +def test_freeboundedtopoForCylinder(): |
| 77 | + ctx = Mgx3D.getStdContext() |
| 78 | + ctx.clearSession() # Clean the session after the previous test |
| 79 | + gm = ctx.getGeomManager () |
| 80 | + tm = ctx.getTopoManager () |
| 81 | + |
| 82 | + gm.newCylinder (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Vector(10, 0, 0), 360) |
| 83 | + tm.newFreeTopoOnGeometry ("Vol0000") |
| 84 | + assertPoint(tm, "Som0007", 10, 1.0, 1.0) |
| 85 | + |
| 86 | +def test_bounding_box_with_scale(): |
| 87 | + ctx = Mgx3D.getStdContext() |
| 88 | + ctx.clearSession() # Clean the session after the previous test |
| 89 | + gm = ctx.getGeomManager () |
| 90 | + tm = ctx.getTopoManager () |
| 91 | + |
| 92 | + gm.newSphere (Mgx3D.Point(0, 0, 0), 1, 125) |
| 93 | + gm.scaleAll(10, 20, 10) |
| 94 | + tm.newFreeTopoOnGeometry ("Vol0000") |
| 95 | + assertPoint(tm, "Som0007", 10.0, 20.0, 10.0) |
0 commit comments