Salome HOME
Fix invalid Python dump of ExportUNV()
[modules/smesh.git] / test / shaper_smesh_groups_without_session.py
1
2 """
3 Check that creating a mesh on a shaperstudy object does not raise orb not found in GetExistingSubObjects.
4 It is called in SMESH GUI on Create mesh's Apply, in SMESHGUI_MeshOp::createSubMeshOnInternalEdges.
5 We explicitly call GetExistingSubObjects here to be able to test it in python.
6 """
7
8 import sys
9 import salome
10
11 salome.standalone()
12 salome.salome_init()
13
14 ###
15 ### SHAPER component
16 ###
17
18 from salome.shaper import model
19
20 model.begin()
21 partSet = model.moduleDocument()
22
23 ### Create Part
24 Part_1 = model.addPart(partSet)
25 Part_1_doc = Part_1.document()
26
27 ### Create Box
28 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
29
30 ### Create Group
31 Group_1 = model.addGroup(Part_1_doc, "Edges", [model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Bottom]")])
32 Group_1.setName("edge_ox")
33 Group_1.result().setName("edge_ox")
34
35 ### Create Group
36 Group_2 = model.addGroup(Part_1_doc, "Edges", [model.selection("EDGE", "[Box_1_1/Back][Box_1_1/Left]")])
37 Group_2.setName("edge_oz")
38 Group_2.result().setName("edge_oz")
39
40 model.end()
41
42 ###
43 ### SHAPERSTUDY component
44 ###
45
46 model.publishToShaperStudy()
47 import SHAPERSTUDY
48 Box_1_1, edge_ox, edge_oz = SHAPERSTUDY.shape(model.featureStringId(Box_1))
49
50 ###
51 ### SMESH component
52 ###
53
54 import  SMESH, SALOMEDS
55 from salome.smesh import smeshBuilder
56
57 smesh = smeshBuilder.New()
58 #smesh.SetEnablePublish( False ) # Set to False to avoid publish in study if not needed or in some particular situations:
59                                  # multiples meshes built in parallel, complex and numerous mesh edition (performance)
60
61 Mesh_1 = smesh.Mesh(Box_1_1)
62 Mesh_1.Segment().LocalLength(5)
63 Mesh_1.Triangle()
64
65 if not Mesh_1.Compute():
66   raise Exception("Error when computing Mesh_1")
67
68 edge_ox_1 = Mesh_1.GroupOnGeom(edge_ox,'edge_ox',SMESH.EDGE)
69 edge_oz_1 = Mesh_1.GroupOnGeom(edge_oz,'edge_oz',SMESH.EDGE)
70
71 # check that ObjectToSObject works (called in GetExistingSubObjects)
72 Box_1_1_sobj = salome.ObjectToSObject(Box_1_1)
73 if not Box_1_1_sobj:
74   raise Exception("No SObject for Box_1_1")
75
76 # check that GetExistingSubObjects works (called in SMESHGUI_MeshOp::createSubMeshOnInternalEdges)
77 shaperBuilder = salome.lcc.FindOrLoadComponent("FactoryServer","SHAPERSTUDY")
78 sOp = shaperBuilder.GetIShapesOperations()
79 geomGroups = sOp.GetExistingSubObjects(Box_1_1, True)
80
81 assert(len(geomGroups)==2)
82
83 assert(Mesh_1.GetMesh().NbTriangles()>16)