Salome HOME
Merge remote-tracking branch 'remotes/origin/occ/compounds_processing'
[modules/shaper.git] / src / ConnectorAPI / Test / TestShaperStudy1.py
1 # Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 import sys
21 import salome
22
23 salome.salome_init()
24
25 ###
26 ### SHAPER component
27 ###
28
29 from SketchAPI import *
30
31 from salome.shaper import model
32
33 model.begin()
34 partSet = model.moduleDocument()
35 Part_1 = model.addPart(partSet)
36 Part_1_doc = Part_1.document()
37 model.addParameter(Part_1_doc, "r", "15")
38 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
39 SketchCircle_1 = Sketch_1.addCircle(25, 25, 15)
40 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
41 SketchPoint_1 = SketchProjection_1.createdFeature()
42 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchCircle_1.center(), SketchAPI_Point(SketchPoint_1).coordinates(), 25)
43 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchCircle_1.center(), SketchAPI_Point(SketchPoint_1).coordinates(), 25)
44 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], "r")
45 model.do()
46 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r")], model.selection(), 10, 0)
47 model.do()
48
49 Part_2 = model.addPart(partSet)
50 Part_2_doc = Part_2.document()
51 Sketch_2 = model.addSketch(Part_2_doc, model.defaultPlane("XOY"))
52 SketchLine_1 = Sketch_2.addLine(-5.176380902051512, 19.31851652579896, 19.31851652579829, -5.176380902058602)
53 SketchLine_2 = Sketch_2.addLine(19.31851652579829, -5.176380902058602, -14.14213562374638, -14.14213562374059)
54 SketchConstraintCoincidence_1 = Sketch_2.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
55 SketchLine_3 = Sketch_2.addLine(-14.14213562374638, -14.14213562374059, -5.176380902051512, 19.31851652579896)
56 SketchConstraintCoincidence_2 = Sketch_2.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
57 SketchConstraintCoincidence_3 = Sketch_2.setCoincident(SketchLine_1.startPoint(), SketchLine_3.endPoint())
58 SketchConstraintEqual_1 = Sketch_2.setEqual(SketchLine_1.result(), SketchLine_3.result())
59 SketchConstraintEqual_2 = Sketch_2.setEqual(SketchLine_1.result(), SketchLine_2.result())
60 SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
61 SketchPoint_2 = SketchProjection_2.createdFeature()
62 SketchConstraintDistance_1 = Sketch_2.setDistance(SketchLine_2.startPoint(), SketchAPI_Point(SketchPoint_2).coordinates(), 20, True)
63 SketchConstraintDistance_2 = Sketch_2.setDistance(SketchLine_3.endPoint(), SketchAPI_Point(SketchPoint_2).coordinates(), 20, True)
64 SketchConstraintDistance_3 = Sketch_2.setDistance(SketchLine_3.startPoint(), SketchAPI_Point(SketchPoint_2).coordinates(), 20, True)
65 SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "PartSet/OX"), False)
66 SketchLine_4 = SketchProjection_3.createdFeature()
67 SketchConstraintAngle_1 = Sketch_2.setAngle(SketchLine_3.result(), SketchLine_4.result(), 75)
68 model.do()
69 Extrusion_2 = model.addExtrusion(Part_2_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_3r-SketchLine_2r-SketchLine_1r")], model.selection(), 30, 0)
70 Fillet_1 = model.addFillet(Part_2_doc, [model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]")], 2)
71 model.do()
72
73 Part_3 = model.addPart(partSet)
74 Part_3_doc = Part_3.document()
75 Sketch_3 = model.addSketch(Part_3_doc, model.defaultPlane("XOZ"))
76 SketchLine_5 = Sketch_3.addLine(52.5, 35, 22.5, 35)
77 SketchLine_6 = Sketch_3.addLine(22.5, 35, 22.5, 15)
78 SketchLine_7 = Sketch_3.addLine(22.5, 15, 52.5, 15)
79 SketchLine_8 = Sketch_3.addLine(52.5, 15, 52.5, 35)
80 SketchConstraintCoincidence_4 = Sketch_3.setCoincident(SketchLine_8.endPoint(), SketchLine_5.startPoint())
81 SketchConstraintCoincidence_5 = Sketch_3.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
82 SketchConstraintCoincidence_6 = Sketch_3.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
83 SketchConstraintCoincidence_7 = Sketch_3.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
84 SketchConstraintHorizontal_1 = Sketch_3.setHorizontal(SketchLine_5.result())
85 SketchConstraintVertical_1 = Sketch_3.setVertical(SketchLine_6.result())
86 SketchConstraintHorizontal_2 = Sketch_3.setHorizontal(SketchLine_7.result())
87 SketchConstraintVertical_2 = Sketch_3.setVertical(SketchLine_8.result())
88 SketchLine_9 = Sketch_3.addLine(0, 0, 52.5, 35)
89 SketchLine_9.setAuxiliary(True)
90 SketchProjection_4 = Sketch_3.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
91 SketchPoint_3 = SketchProjection_4.createdFeature()
92 SketchConstraintCoincidence_8 = Sketch_3.setCoincident(SketchLine_9.startPoint(), SketchPoint_3.result())
93 SketchConstraintCoincidence_9 = Sketch_3.setCoincident(SketchLine_5.startPoint(), SketchLine_9.endPoint())
94 SketchConstraintCoincidence_10 = Sketch_3.setCoincident(SketchLine_6.endPoint(), SketchLine_9.result())
95 SketchConstraintLength_1 = Sketch_3.setLength(SketchLine_8.result(), 20)
96 SketchConstraintLength_2 = Sketch_3.setLength(SketchLine_5.result(), 30)
97 SketchConstraintDistanceVertical_2 = Sketch_3.setVerticalDistance(SketchLine_7.endPoint(), SketchAPI_Point(SketchPoint_3).coordinates(), 15)
98 model.do()
99 Revolution_1 = model.addRevolution(Part_3_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f")], model.selection("EDGE", "PartSet/OX"), 45, 0)
100 model.end()
101
102 ###
103 ### SHAPERSTUDY component
104 ###
105
106 if 'model' in globals():
107   model.publishToShaperStudy()
108 import SHAPERSTUDY
109 Extrusion_1_1, = SHAPERSTUDY.shape(model.featureStringId(Extrusion_1))
110 Fillet_1_1, = SHAPERSTUDY.shape(model.featureStringId(Fillet_1))
111 Revolution_1_1, = SHAPERSTUDY.shape(model.featureStringId(Revolution_1))
112 ###
113 ### SMESH component
114 ###
115
116 import  SMESH, SALOMEDS
117 from salome.smesh import smeshBuilder
118
119 smesh = smeshBuilder.New()
120 #smesh.SetEnablePublish( False ) # Set to False to avoid publish in study if not needed or in some particular situations:
121                                  # multiples meshes built in parallel, complex and numerous mesh edition (performance)
122
123 Mesh_1 = smesh.Mesh(Fillet_1_1)
124 Regular_1D = Mesh_1.Segment()
125 Number_of_Segments_1 = Regular_1D.NumberOfSegments(7,None,[])
126 MEFISTO_2D = Mesh_1.Triangle(algo=smeshBuilder.MEFISTO)
127 Max_Element_Area_1 = MEFISTO_2D.MaxElementArea(20)
128 isDone = Mesh_1.Compute()
129 assert(isDone)
130 Mesh_2 = smesh.Mesh(Extrusion_1_1)
131 Cartesian_3D = Mesh_2.BodyFitted()
132 Body_Fitting_Parameters_1 = Cartesian_3D.SetGrid([ [ '4.3589' ], [ 0, 1 ]],[ [ '4.3589' ], [ 0, 1 ]],[ [ '4.3589' ], [ 0, 1 ]],4,0)
133 Body_Fitting_Parameters_1.SetFixedPoint( SMESH.PointStruct ( 0, 0, 0 ), 1 )
134 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 )) )
135 isDone = Mesh_2.Compute()
136 assert(isDone)
137 Mesh_3 = smesh.Mesh(Revolution_1_1)
138 status = Mesh_3.AddHypothesis(Number_of_Segments_1)
139 Regular_1D_1 = Mesh_3.Segment()
140 isDone = Mesh_3.Compute()
141 assert(isDone)
142
143 ## Set names of Mesh objects
144 smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
145 smesh.SetName(MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D')
146 smesh.SetName(Cartesian_3D.GetAlgorithm(), 'Cartesian_3D')
147 smesh.SetName(Mesh_1.GetMesh(), 'Mesh_1')
148 smesh.SetName(Mesh_2.GetMesh(), 'Mesh_2')
149 smesh.SetName(Mesh_3.GetMesh(), 'Mesh_3')
150 smesh.SetName(Body_Fitting_Parameters_1, 'Body Fitting Parameters_1')
151 smesh.SetName(Max_Element_Area_1, 'Max. Element Area_1')
152 smesh.SetName(Number_of_Segments_1, 'Number of Segments_1')
153
154 # check the SHAPER study objects generated names
155 assert(Extrusion_1_1.GetName() == "Extrusion_1_1")
156 assert(Fillet_1_1.GetName() == "Fillet_1_1")
157 assert(Revolution_1_1.GetName() == "Revolution_1_1")
158 # check the smesh mesh is computed correctly
159 assert(Mesh_1.NbNodes() == 235)
160 assert(Mesh_2.NbNodes() == 168)
161 assert(Mesh_3.NbNodes() == 80)