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"
35 #include "SMDS_MeshFace.hxx"
36 #include "SMDS_MeshVolume.hxx"
38 #include <TopExp_Explorer.hxx>
40 #include <TopoDS_Face.hxx>
45 // =============================================================================
46 //=============================================================================
48 // =============================================================================
49 * SMESH_Gen_i::GetPattern
51 * Create pattern mapper
53 //=============================================================================
55 SMESH::SMESH_Pattern_ptr SMESH_Gen_i::GetPattern()
57 SMESH_Pattern_i* i = new SMESH_Pattern_i( this );
58 SMESH::SMESH_Pattern_var anObj = i->_this();
62 //=======================================================================
63 //function : SMESH_Pattern_i
65 //=======================================================================
67 SMESH_Pattern_i::SMESH_Pattern_i( SMESH_Gen_i* theGen_i ):
72 //=======================================================================
75 //=======================================================================
77 ::SMESH_Mesh* SMESH_Pattern_i::getMesh( SMESH::SMESH_Mesh_ptr & theMesh )
79 SMESH_Mesh_i* anImplPtr =
80 dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( theMesh ).in() );
82 return & anImplPtr->GetImpl();
87 //=======================================================================
88 //function : LoadFromFile
90 //=======================================================================
92 CORBA::Boolean SMESH_Pattern_i::LoadFromFile(const char* theFileContents)
94 return myPattern.Load( theFileContents );
97 //=======================================================================
98 //function : LoadFromFace
100 //=======================================================================
102 CORBA::Boolean SMESH_Pattern_i::LoadFromFace(SMESH::SMESH_Mesh_ptr theMesh,
103 GEOM::GEOM_Object_ptr theFace,
104 CORBA::Boolean theProject)
106 if ( theMesh->_is_nil() || theFace->_is_nil() )
109 ::SMESH_Mesh* aMesh = getMesh( theMesh );
113 TopoDS_Face aFace = TopoDS::Face( myGen->GeomObjectToShape( theFace ));
114 if ( aFace.IsNull() )
117 return myPattern.Load( aMesh, aFace, theProject );
120 //=======================================================================
121 //function : LoadFrom3DBlock
123 //=======================================================================
125 CORBA::Boolean SMESH_Pattern_i::LoadFrom3DBlock(SMESH::SMESH_Mesh_ptr theMesh,
126 GEOM::GEOM_Object_ptr theBlock)
128 if ( theMesh->_is_nil() || theBlock->_is_nil() )
131 ::SMESH_Mesh* aMesh = getMesh( theMesh );
135 TopoDS_Shape aShape = myGen->GeomObjectToShape( theBlock );
136 if ( aShape.IsNull())
139 TopExp_Explorer exp ( aShape, TopAbs_SHELL );
143 return myPattern.Load( aMesh, TopoDS::Shell( exp.Current() ));
146 //=======================================================================
147 //function : ApplyToFace
149 //=======================================================================
151 SMESH::point_array* SMESH_Pattern_i::ApplyToFace(GEOM::GEOM_Object_ptr theFace,
152 GEOM::GEOM_Object_ptr theVertexOnKeyPoint1,
153 CORBA::Boolean theReverse)
155 SMESH::point_array_var points = new SMESH::point_array;
156 list<const gp_XYZ *> xyzList;
158 TopoDS_Shape F = myGen->GeomObjectToShape( theFace );
159 TopoDS_Shape V = myGen->GeomObjectToShape( theVertexOnKeyPoint1 );
161 if (!F.IsNull() && F.ShapeType() == TopAbs_FACE &&
162 !V.IsNull() && V.ShapeType() == TopAbs_VERTEX
164 myPattern.Apply( TopoDS::Face( F ), TopoDS::Vertex( V ), theReverse ) &&
165 myPattern.GetMappedPoints( xyzList ))
167 points->length( xyzList.size() );
168 list<const gp_XYZ *>::iterator xyzIt = xyzList.begin();
169 for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) {
170 SMESH::PointStruct & p = points[ i++ ];
171 (*xyzIt)->Coord( p.x, p.y, p.z );
175 return points._retn();
178 //=======================================================================
179 //function : ApplyTo3DBlock
181 //=======================================================================
183 SMESH::point_array* SMESH_Pattern_i::ApplyTo3DBlock(GEOM::GEOM_Object_ptr theBlock,
184 GEOM::GEOM_Object_ptr theVertex000,
185 GEOM::GEOM_Object_ptr theVertex001)
187 SMESH::point_array_var points = new SMESH::point_array;
188 list<const gp_XYZ *> xyzList;
190 TopExp_Explorer exp( myGen->GeomObjectToShape( theBlock ), TopAbs_SHELL );
191 TopoDS_Shape V000 = myGen->GeomObjectToShape( theVertex000 );
192 TopoDS_Shape V001 = myGen->GeomObjectToShape( theVertex001 );
195 !V000.IsNull() && V000.ShapeType() == TopAbs_VERTEX &&
196 !V001.IsNull() && V001.ShapeType() == TopAbs_VERTEX
198 myPattern.Apply(TopoDS::Shell( exp.Current() ),
199 TopoDS::Vertex( V000 ),
200 TopoDS::Vertex( V001 )) &&
201 myPattern.GetMappedPoints( xyzList ))
203 points->length( xyzList.size() );
204 list<const gp_XYZ *>::iterator xyzIt = xyzList.begin();
205 for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) {
206 SMESH::PointStruct & p = points[ i++ ];
207 (*xyzIt)->Coord( p.x, p.y, p.z );
211 return points._retn();
214 //=======================================================================
215 //function : ApplyToMeshFaces
217 //=======================================================================
220 SMESH_Pattern_i::ApplyToMeshFaces(SMESH::SMESH_Mesh_ptr theMesh,
221 const SMESH::long_array& theFacesIDs,
222 CORBA::Long theNodeIndexOnKeyPoint1,
223 CORBA::Boolean theReverse)
225 SMESH::point_array_var points = new SMESH::point_array;
227 ::SMESH_Mesh* aMesh = getMesh( theMesh );
229 return points._retn();
231 list<const gp_XYZ *> xyzList;
232 set<const SMDS_MeshFace*> fset;
233 for (int i = 0; i < theFacesIDs.length(); i++)
235 CORBA::Long index = theFacesIDs[i];
236 const SMDS_MeshElement * elem = aMesh->GetMeshDS()->FindElement(index);
237 if ( elem && elem->GetType() == SMDSAbs_Face )
238 fset.insert( static_cast<const SMDS_MeshFace *>( elem ));
240 if (myPattern.Apply( fset, theNodeIndexOnKeyPoint1, theReverse ) &&
241 myPattern.GetMappedPoints( xyzList ))
243 points->length( xyzList.size() );
244 list<const gp_XYZ *>::iterator xyzIt = xyzList.begin();
245 for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) {
246 SMESH::PointStruct & p = points[ i++ ];
247 (*xyzIt)->Coord( p.x, p.y, p.z );
251 return points._retn();
254 //=======================================================================
255 //function : ApplyToHexahedrons
257 //=======================================================================
260 SMESH_Pattern_i::ApplyToHexahedrons(SMESH::SMESH_Mesh_ptr theMesh,
261 const SMESH::long_array& theVolumesIDs,
262 CORBA::Long theNode000Index,
263 CORBA::Long theNode001Index)
265 SMESH::point_array_var points = new SMESH::point_array;
267 ::SMESH_Mesh* aMesh = getMesh( theMesh );
269 return points._retn();
271 list<const gp_XYZ *> xyzList;
272 set<const SMDS_MeshVolume*> vset;
273 for (int i = 0; i < theVolumesIDs.length(); i++)
275 CORBA::Long index = theVolumesIDs[i];
276 const SMDS_MeshElement * elem = aMesh->GetMeshDS()->FindElement(index);
277 if ( elem && elem->GetType() == SMDSAbs_Volume && elem->NbNodes() == 8 )
278 vset.insert( static_cast<const SMDS_MeshVolume *>( elem ));
280 if (myPattern.Apply( vset, theNode000Index, theNode001Index ) &&
281 myPattern.GetMappedPoints( xyzList ))
283 points->length( xyzList.size() );
284 list<const gp_XYZ *>::iterator xyzIt = xyzList.begin();
285 for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) {
286 SMESH::PointStruct & p = points[ i++ ];
287 (*xyzIt)->Coord( p.x, p.y, p.z );
291 return points._retn();
294 //=======================================================================
295 //function : MakeMesh
297 //=======================================================================
299 CORBA::Boolean SMESH_Pattern_i::MakeMesh (SMESH::SMESH_Mesh_ptr theMesh,
300 const CORBA::Boolean CreatePolygons,
301 const CORBA::Boolean CreatePolyedrs)
303 ::SMESH_Mesh* aMesh = getMesh( theMesh );
307 return myPattern.MakeMesh( aMesh, CreatePolygons, CreatePolyedrs );
310 //=======================================================================
311 //function : GetString
313 //=======================================================================
315 char* SMESH_Pattern_i::GetString()
318 myPattern.Save( os );
320 return CORBA::string_dup( os.str().c_str() );
323 //=======================================================================
326 //=======================================================================
328 CORBA::Boolean SMESH_Pattern_i::Is2D()
330 return myPattern.Is2D();
333 //=======================================================================
334 //function : GetPoints
336 //=======================================================================
338 SMESH::point_array* SMESH_Pattern_i::GetPoints()
340 SMESH::point_array_var points = new SMESH::point_array;
341 list<const gp_XYZ *> xyzList;
343 if (myPattern.GetPoints( xyzList ))
345 points->length( xyzList.size() );
346 list<const gp_XYZ *>::iterator xyzIt = xyzList.begin();
347 for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) {
348 SMESH::PointStruct & p = points[ i++ ];
349 (*xyzIt)->Coord( p.x, p.y, p.z );
353 return points._retn();
356 //=======================================================================
357 //function : GetKeyPoints
359 //=======================================================================
361 SMESH::long_array* SMESH_Pattern_i::GetKeyPoints()
363 SMESH::long_array_var ids = new SMESH::long_array;
364 if ( myPattern.IsLoaded() ) {
365 const list< int > & idList = myPattern.GetKeyPointIDs();
366 ids->length( idList.size() );
367 list< int >::const_iterator iIt = idList.begin();
368 for ( int i = 0; iIt != idList.end(); iIt++, i++ )
374 //=======================================================================
375 //function : GetElementPoints
377 //=======================================================================
379 SMESH::array_of_long_array* SMESH_Pattern_i::GetElementPoints(CORBA::Boolean applied)
381 SMESH::array_of_long_array_var arrayOfArray = new SMESH::array_of_long_array;
383 const list< list< int > >& listOfIdList = myPattern.GetElementPointIDs(applied);
384 arrayOfArray->length( listOfIdList.size() );
385 list< list< int > >::const_iterator llIt = listOfIdList.begin();
386 for ( int i = 0 ; llIt != listOfIdList.end(); llIt++, i++ )
388 const list< int > & idList = (*llIt);
389 SMESH::long_array& ids = arrayOfArray[ i ];
390 ids.length( idList.size() );
391 list< int >::const_iterator iIt = idList.begin();
392 for ( int j = 0; iIt != idList.end(); iIt++, j++ )
395 return arrayOfArray._retn();
398 //=======================================================================
399 //function : GetErrorCode
401 //=======================================================================
403 #define RETCASE(enm) case ::SMESH_Pattern::enm: return SMESH::SMESH_Pattern::enm;
405 SMESH::SMESH_Pattern::ErrorCode SMESH_Pattern_i::GetErrorCode()
407 switch ( myPattern.GetErrorCode() ) {
409 RETCASE( ERR_READ_NB_POINTS );
410 RETCASE( ERR_READ_POINT_COORDS );
411 RETCASE( ERR_READ_TOO_FEW_POINTS );
412 RETCASE( ERR_READ_3D_COORD );
413 RETCASE( ERR_READ_NO_KEYPOINT );
414 RETCASE( ERR_READ_BAD_INDEX );
415 RETCASE( ERR_READ_ELEM_POINTS );
416 RETCASE( ERR_READ_NO_ELEMS );
417 RETCASE( ERR_READ_BAD_KEY_POINT );
418 RETCASE( ERR_SAVE_NOT_LOADED );
419 RETCASE( ERR_LOAD_EMPTY_SUBMESH );
420 RETCASE( ERR_LOADF_NARROW_FACE );
421 RETCASE( ERR_LOADF_CLOSED_FACE );
422 RETCASE( ERR_LOADV_BAD_SHAPE );
423 RETCASE( ERR_LOADV_COMPUTE_PARAMS );
424 RETCASE( ERR_APPL_NOT_LOADED );
425 RETCASE( ERR_APPL_BAD_DIMENTION );
426 RETCASE( ERR_APPL_BAD_NB_VERTICES );
427 RETCASE( ERR_APPLF_BAD_TOPOLOGY );
428 RETCASE( ERR_APPLF_BAD_VERTEX );
429 RETCASE( ERR_APPLF_INTERNAL_EEROR );
430 RETCASE( ERR_APPLV_BAD_SHAPE );
431 RETCASE( ERR_MAKEM_NOT_COMPUTED );
434 return SMESH::SMESH_Pattern::ERR_OK;