1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_Pattern_i.cxx
25 // Created : Fri Aug 20 16:15:49 2004
26 // Author : Edward AGAPOV (eap)
29 #include "SMESH_Pattern_i.hxx"
31 #include "GEOM_Client.hxx"
32 #include "SMESH_Gen_i.hxx"
33 #include "SMESH_Mesh.hxx"
34 #include "SMESH_Mesh_i.hxx"
36 #include <TopExp_Explorer.hxx>
38 #include <TopoDS_Face.hxx>
42 //=============================================================================
44 * SMESH_Gen_i::GetPattern
46 * Create pattern mapper
48 //=============================================================================
50 SMESH::SMESH_Pattern_ptr SMESH_Gen_i::GetPattern()
52 SMESH_Pattern_i* i = new SMESH_Pattern_i( this );
53 SMESH::SMESH_Pattern_var anObj = i->_this();
57 //=======================================================================
58 //function : SMESH_Pattern_i
60 //=======================================================================
62 SMESH_Pattern_i::SMESH_Pattern_i( SMESH_Gen_i* theGen_i ):
67 //=======================================================================
70 //=======================================================================
72 TopoDS_Shape SMESH_Pattern_i::getShape( GEOM::GEOM_Object_ptr & theGeomObject )
74 return myGen->GetShapeReader()->GetShape( SMESH_Gen_i::GetGeomEngine(), theGeomObject );
77 //=======================================================================
80 //=======================================================================
82 ::SMESH_Mesh* SMESH_Pattern_i::getMesh( SMESH::SMESH_Mesh_ptr & theMesh )
84 SMESH_Mesh_i* anImplPtr =
85 dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( theMesh ).in() );
87 return & anImplPtr->GetImpl();
92 //=======================================================================
93 //function : LoadFromFile
95 //=======================================================================
97 CORBA::Boolean SMESH_Pattern_i::LoadFromFile(const char* theFileContents)
99 return myPattern.Load( theFileContents );
102 //=======================================================================
103 //function : LoadFromFace
105 //=======================================================================
107 CORBA::Boolean SMESH_Pattern_i::LoadFromFace(SMESH::SMESH_Mesh_ptr theMesh,
108 GEOM::GEOM_Object_ptr theFace,
109 CORBA::Boolean theProject)
111 if ( theMesh->_is_nil() || theFace->_is_nil() )
114 ::SMESH_Mesh* aMesh = getMesh( theMesh );
118 TopoDS_Face aFace = TopoDS::Face( getShape( theFace ));
119 if ( aFace.IsNull() )
122 return myPattern.Load( aMesh, aFace, theProject );
125 //=======================================================================
126 //function : LoadFrom3DBlock
128 //=======================================================================
130 CORBA::Boolean SMESH_Pattern_i::LoadFrom3DBlock(SMESH::SMESH_Mesh_ptr theMesh,
131 GEOM::GEOM_Object_ptr theBlock)
133 if ( theMesh->_is_nil() || theBlock->_is_nil() )
136 ::SMESH_Mesh* aMesh = getMesh( theMesh );
140 TopoDS_Shape aShape = getShape( theBlock );
141 if ( aShape.IsNull())
144 TopExp_Explorer exp ( aShape, TopAbs_SHELL );
148 return myPattern.Load( aMesh, TopoDS::Shell( exp.Current() ));
151 //=======================================================================
152 //function : ApplyToFace
154 //=======================================================================
156 SMESH::point_array* SMESH_Pattern_i::ApplyToFace(GEOM::GEOM_Object_ptr theFace,
157 GEOM::GEOM_Object_ptr theVertexOnKeyPoint1,
158 CORBA::Boolean theReverse)
160 SMESH::point_array_var points = new SMESH::point_array;
161 list<const gp_XYZ *> xyzList;
163 TopoDS_Shape F = getShape( theFace );
164 TopoDS_Shape V = getShape( theVertexOnKeyPoint1 );
166 if (!F.IsNull() && F.ShapeType() == TopAbs_FACE &&
167 !V.IsNull() && V.ShapeType() == TopAbs_VERTEX
169 myPattern.Apply( TopoDS::Face( F ), TopoDS::Vertex( V ), theReverse ) &&
170 myPattern.GetMappedPoints( xyzList ))
172 points->length( xyzList.size() );
173 list<const gp_XYZ *>::iterator xyzIt = xyzList.begin();
174 for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) {
175 SMESH::PointStruct & p = points[ i++ ];
176 (*xyzIt)->Coord( p.x, p.y, p.z );
180 return points._retn();
183 //=======================================================================
184 //function : ApplyTo3DBlock
186 //=======================================================================
188 SMESH::point_array* SMESH_Pattern_i::ApplyTo3DBlock(GEOM::GEOM_Object_ptr theBlock,
189 GEOM::GEOM_Object_ptr theVertex000,
190 GEOM::GEOM_Object_ptr theVertex001)
192 SMESH::point_array_var points = new SMESH::point_array;
193 list<const gp_XYZ *> xyzList;
195 TopExp_Explorer exp( getShape( theBlock ), TopAbs_SHELL );
196 TopoDS_Shape V000 = getShape( theVertex000 );
197 TopoDS_Shape V001 = getShape( theVertex001 );
200 !V000.IsNull() && V000.ShapeType() == TopAbs_VERTEX &&
201 !V001.IsNull() && V001.ShapeType() == TopAbs_VERTEX
203 myPattern.Apply(TopoDS::Shell( exp.Current() ),
204 TopoDS::Vertex( V000 ),
205 TopoDS::Vertex( V001 )) &&
206 myPattern.GetMappedPoints( xyzList ))
208 points->length( xyzList.size() );
209 list<const gp_XYZ *>::iterator xyzIt = xyzList.begin();
210 for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) {
211 SMESH::PointStruct & p = points[ i++ ];
212 (*xyzIt)->Coord( p.x, p.y, p.z );
216 return points._retn();
219 //=======================================================================
220 //function : MakeMesh
222 //=======================================================================
224 CORBA::Boolean SMESH_Pattern_i::MakeMesh(SMESH::SMESH_Mesh_ptr theMesh)
226 ::SMESH_Mesh* aMesh = getMesh( theMesh );
230 return myPattern.MakeMesh( aMesh );
233 //=======================================================================
234 //function : GetString
236 //=======================================================================
238 char* SMESH_Pattern_i::GetString()
241 myPattern.Save( os );
243 return CORBA::string_dup( os.str().c_str() );
246 //=======================================================================
249 //=======================================================================
251 CORBA::Boolean SMESH_Pattern_i::Is2D()
253 return myPattern.Is2D();
256 //=======================================================================
257 //function : GetPoints
259 //=======================================================================
261 SMESH::point_array* SMESH_Pattern_i::GetPoints()
263 SMESH::point_array_var points = new SMESH::point_array;
264 list<const gp_XYZ *> xyzList;
266 if (myPattern.GetPoints( xyzList ))
268 points->length( xyzList.size() );
269 list<const gp_XYZ *>::iterator xyzIt = xyzList.begin();
270 for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) {
271 SMESH::PointStruct & p = points[ i++ ];
272 (*xyzIt)->Coord( p.x, p.y, p.z );
276 return points._retn();
279 //=======================================================================
280 //function : GetKeyPoints
282 //=======================================================================
284 SMESH::long_array* SMESH_Pattern_i::GetKeyPoints()
286 SMESH::long_array_var ids = new SMESH::long_array;
287 if ( myPattern.IsLoaded() ) {
288 const list< int > & idList = myPattern.GetKeyPointIDs();
289 ids->length( idList.size() );
290 list< int >::const_iterator iIt = idList.begin();
291 for ( int i = 0; iIt != idList.end(); iIt++, i++ )
297 //=======================================================================
298 //function : GetElementPoints
300 //=======================================================================
302 SMESH::array_of_long_array* SMESH_Pattern_i::GetElementPoints()
304 SMESH::array_of_long_array_var arrayOfArray = new SMESH::array_of_long_array;
306 const list< list< int > >& listOfIdList = myPattern.GetElementPointIDs();
307 arrayOfArray->length( listOfIdList.size() );
308 list< list< int > >::const_iterator llIt = listOfIdList.begin();
309 for ( int i = 0 ; llIt != listOfIdList.end(); llIt++, i++ )
311 const list< int > & idList = (*llIt);
312 SMESH::long_array& ids = arrayOfArray[ i ];
313 ids.length( idList.size() );
314 list< int >::const_iterator iIt = idList.begin();
315 for ( int j = 0; iIt != idList.end(); iIt++, j++ )
318 return arrayOfArray._retn();
321 //=======================================================================
322 //function : GetErrorCode
324 //=======================================================================
326 #define RETCASE(enm) case ::SMESH_Pattern::enm: return SMESH::SMESH_Pattern::enm;
328 SMESH::SMESH_Pattern::ErrorCode SMESH_Pattern_i::GetErrorCode()
330 switch ( myPattern.GetErrorCode() ) {
332 RETCASE( ERR_READ_NB_POINTS );
333 RETCASE( ERR_READ_POINT_COORDS );
334 RETCASE( ERR_READ_TOO_FEW_POINTS );
335 RETCASE( ERR_READ_3D_COORD );
336 RETCASE( ERR_READ_NO_KEYPOINT );
337 RETCASE( ERR_READ_BAD_INDEX );
338 RETCASE( ERR_READ_ELEM_POINTS );
339 RETCASE( ERR_READ_NO_ELEMS );
340 RETCASE( ERR_READ_BAD_KEY_POINT );
341 RETCASE( ERR_SAVE_NOT_LOADED );
342 RETCASE( ERR_LOAD_EMPTY_SUBMESH );
343 RETCASE( ERR_LOADF_NARROW_FACE );
344 RETCASE( ERR_LOADF_CLOSED_FACE );
345 RETCASE( ERR_LOADV_BAD_SHAPE );
346 RETCASE( ERR_LOADV_COMPUTE_PARAMS );
347 RETCASE( ERR_APPL_NOT_LOADED );
348 RETCASE( ERR_APPL_BAD_DIMENTION );
349 RETCASE( ERR_APPL_BAD_NB_VERTICES );
350 RETCASE( ERR_APPLF_BAD_TOPOLOGY );
351 RETCASE( ERR_APPLF_BAD_VERTEX );
352 RETCASE( ERR_APPLF_INTERNAL_EEROR );
353 RETCASE( ERR_APPLV_BAD_SHAPE );
354 RETCASE( ERR_MAKEM_NOT_COMPUTED );
357 return SMESH::SMESH_Pattern::ERR_OK;