]> SALOME platform Git repositories - modules/shaper.git/blob - src/ConnectorAPI/Test/TestShaperStudy3.py
Salome HOME
Merge branch 'occ/shaper2smesh'
[modules/shaper.git] / src / ConnectorAPI / Test / TestShaperStudy3.py
1 #!/usr/bin/env python
2
3 ###
4 ### This file is generated automatically by SALOME v9.4.0 with dump python functionality
5 ###
6
7 import os
8 import sys
9 import salome
10
11 salome.salome_init()
12
13 #=========================================================================
14 # A function to get the XAO file path
15 #=========================================================================
16 def getPath(path):
17     shapes_dir = os.path.join(os.getenv("DATA_DIR"), "Shapes")
18     return os.path.join(shapes_dir, path)
19
20 ###
21 ### SHAPER component
22 ###
23
24 from salome.shaper import model
25
26 model.begin()
27 partSet = model.moduleDocument()
28 Part_1 = model.addPart(partSet)
29 Part_1_doc = Part_1.document()
30 Param_H = model.addParameter(Part_1_doc, "h", "20")
31 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
32 SketchLine_1 = Sketch_1.addLine(75.09305815883349, 77.46634028730745, 23.30071943952229, 77.46634028730745)
33 SketchLine_2 = Sketch_1.addLine(23.30071943952229, 77.46634028730745, 23.30071943952229, 23.93663846925804)
34 SketchLine_3 = Sketch_1.addLine(23.30071943952229, 23.93663846925804, 75.09305815883349, 23.93663846925804)
35 SketchLine_4 = Sketch_1.addLine(75.09305815883349, 23.93663846925804, 75.09305815883349, 77.46634028730745)
36 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
37 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
38 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
39 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
40 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
41 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
42 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
43 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
44 model.do()
45 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f")], model.selection(), "h", 0)
46
47 model.end()
48
49 ###
50 ### SHAPERSTUDY component
51 ###
52
53 if 'model' in globals():
54   model.publishToShaperStudy()
55 import SHAPERSTUDY
56 Extrusion_1_1, = SHAPERSTUDY.shape(model.featureStringId(Extrusion_1))
57 Extrusion_1_1_1, = SHAPERSTUDY.archive(Extrusion_1_1, getPath("Xao/TestShaperStudy2.xao"))
58 ###
59 ### SMESH component
60 ###
61
62 import  SMESH, SALOMEDS
63 from salome.smesh import smeshBuilder
64
65 smesh = smeshBuilder.New()
66 #smesh.SetEnablePublish( False ) # Set to False to avoid publish in study if not needed or in some particular situations:
67                                  # multiples meshes built in parallel, complex and numerous mesh edition (performance)
68
69 Mesh_1 = smesh.Mesh(Extrusion_1_1)
70 Cartesian_3D = Mesh_1.BodyFitted()
71 Body_Fitting_Parameters_1 = Cartesian_3D.SetGrid([ [ '7.71225' ], [ 0, 1 ]],[ [ '7.71225' ], [ 0, 1 ]],[ [ '7.71225' ], [ 0, 1 ]],4,0)
72 Body_Fitting_Parameters_1.SetFixedPoint( SMESH.PointStruct ( 0, 0, 0 ), 1 )
73 Body_Fitting_Parameters_1.SetAxesDirs( SMESH.DirStruct( SMESH.PointStruct ( 1, 0, 0 )), SMESH.DirStruct( SMESH.PointStruct ( 0, 1, 0 )), SMESH.DirStruct( SMESH.PointStruct ( 0, 0, 1 )) )
74 isDone = Mesh_1.Compute()
75 Mesh_2 = smesh.Mesh(Extrusion_1_1)
76 Regular_1D = Mesh_2.Segment()
77 Number_of_Segments_1 = Regular_1D.NumberOfSegments(7)
78 MEFISTO_2D = Mesh_2.Triangle(algo=smeshBuilder.MEFISTO)
79 Max_Element_Area_1 = MEFISTO_2D.MaxElementArea(20)
80 SHAPERSTUDY.breakLinkForSubElements(salome.ObjectToSObject(Mesh_2.GetMesh()), Extrusion_1_1_1)
81 Mesh_2.GetMesh().ReplaceShape( Extrusion_1_1_1 )
82 isDone = Mesh_2.Compute()
83
84
85 ## Set names of Mesh objects
86 smesh.SetName(Cartesian_3D.GetAlgorithm(), 'Cartesian_3D')
87 smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
88 smesh.SetName(MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D')
89 smesh.SetName(Mesh_1.GetMesh(), 'Mesh_1')
90 smesh.SetName(Mesh_2.GetMesh(), 'Mesh_2')
91 smesh.SetName(Max_Element_Area_1, 'Max. Element Area_1')
92 smesh.SetName(Body_Fitting_Parameters_1, 'Body Fitting Parameters_1')
93 smesh.SetName(Number_of_Segments_1, 'Number of Segments_1')
94
95 # check on update of the initial box Mesh_1 computed on it is changed, Mesh_2 on dead shape is unchanged
96 aNb1 = Mesh_1.NbElements()
97 aNb2 = Mesh_2.NbElements()
98 model.begin()
99 Param_H.setValue(50)
100 model.end()
101 model.publishToShaperStudy()
102 assert(Mesh_1.Compute())
103 assert(Mesh_1.NbElements() > aNb1)
104 assert(Mesh_2.Compute())
105 assert(Mesh_2.NbElements() == aNb2)