Salome HOME
Merge multi-study removal branch.
[modules/smesh.git] / src / SMESH_SWIG / ex02_cube2primitive.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 # =======================================
25 #
26 import salome
27 salome.salome_init()
28 import GEOM
29 from salome.geom import geomBuilder
30 geompy = geomBuilder.New()
31
32 import SMESH, SALOMEDS
33 from salome.smesh import smeshBuilder
34 smesh =  smeshBuilder.New()
35
36 # Geometry
37 # ========
38
39 # A small cube centered and put on a great cube build by primitive geometric functionalities
40
41 # Values
42 # ------
43
44 ox = 0
45 oy = 0
46 oz = 0
47
48 arete = 10
49
50 # Points
51 # ------
52
53 blockPoint111 = geompy.MakeVertex(ox      , oy, oz)
54 blockPoint211 = geompy.MakeVertex(ox+arete, oy, oz)
55 blockPoint112 = geompy.MakeVertex(ox      , oy, oz+arete)
56 blockPoint212 = geompy.MakeVertex(ox+arete, oy, oz+arete)
57
58 # Face and solid
59 # --------------
60
61 blockFace1 = geompy.MakeQuad4Vertices(blockPoint111, blockPoint211, blockPoint212, blockPoint112)
62
63 blockSolid11  = geompy.MakePrismVecH(blockFace1, geompy.MakeVectorDXDYDZ(0, 1, 0), arete)
64
65 # Translations
66 # ------------
67
68 blockSolid21  = geompy.MakeTranslation(blockSolid11, arete, 0, 0)
69 blockSolid31  = geompy.MakeTranslation(blockSolid21, arete, 0, 0)
70
71 blockSolid12  = geompy.MakeTranslation(blockSolid11, 0, 0, arete)
72 blockSolid22  = geompy.MakeTranslation(blockSolid12, arete, 0, 0)
73 blockSolid32  = geompy.MakeTranslation(blockSolid22, arete, 0, 0)
74
75 blockSolid13  = geompy.MakeTranslation(blockSolid12, 0, 0, arete)
76 blockSolid23  = geompy.MakeTranslation(blockSolid13, arete, 0, 0)
77 blockSolid33  = geompy.MakeTranslation(blockSolid23, arete, 0, 0)
78
79 blockSolid111 = geompy.MakeTranslation(blockSolid22, 0, arete, 0)
80
81 # Compound and glue
82 # -----------------
83
84 c_l = []
85 c_l.append(blockSolid11)
86 c_l.append(blockSolid21)
87 c_l.append(blockSolid31)
88 c_l.append(blockSolid12)
89 c_l.append(blockSolid22)
90 c_l.append(blockSolid32)
91 c_l.append(blockSolid13)
92 c_l.append(blockSolid23)
93 c_l.append(blockSolid33)
94 c_l.append(blockSolid111)
95
96 c_cpd = geompy.MakeCompound(c_l)
97
98 piece = geompy.MakeGlueFaces(c_cpd, 1.e-5)
99
100 # Add in study
101 # ------------
102
103 piece_id = geompy.addToStudy(piece, "ex02_cube2primitive")
104
105 # Meshing
106 # =======
107
108 # Create hexahedrical mesh on piece
109 # ---------------------------------
110
111 hexa = smesh.Mesh(piece, "ex02_cube2primitive:hexa")
112
113 algo = hexa.Segment()
114 algo.LocalLength(1)
115
116 hexa.Quadrangle()
117
118 hexa.Hexahedron()
119
120 # Compute the mesh
121 # ----------------
122
123 hexa.Compute()
124
125 # Update object browser
126 # ---------------------
127
128 salome.sg.updateObjBrowser()