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 "SMESH_PythonDump.hxx"
36 #include "SMDS_MeshFace.hxx"
37 #include "SMDS_MeshVolume.hxx"
39 #include <TopExp_Explorer.hxx>
41 #include <TopoDS_Face.hxx>
46 using SMESH::TPythonDump;
48 //=======================================================================
49 //function : dumpErrorCode
51 //=======================================================================
53 static void addErrorCode(const char* thePyCommand)
55 TPythonDump() << "if (isDone != 1):";
56 TPythonDump() << "\tprint '" << thePyCommand << " :', pattern.GetErrorCode()";
59 //=============================================================================
61 * SMESH_Gen_i::GetPattern
63 * Create pattern mapper
65 //=============================================================================
67 SMESH::SMESH_Pattern_ptr SMESH_Gen_i::GetPattern()
69 // Update Python script
70 TPythonDump() << "pattern = " << this << ".GetPattern()";
72 SMESH_Pattern_i* i = new SMESH_Pattern_i( this );
73 SMESH::SMESH_Pattern_var anObj = i->_this();
77 //=======================================================================
78 //function : SMESH_Pattern_i
80 //=======================================================================
82 SMESH_Pattern_i::SMESH_Pattern_i( SMESH_Gen_i* theGen_i ):
87 //=======================================================================
90 //=======================================================================
92 ::SMESH_Mesh* SMESH_Pattern_i::getMesh( SMESH::SMESH_Mesh_ptr & theMesh )
94 SMESH_Mesh_i* anImplPtr =
95 dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( theMesh ).in() );
97 return & anImplPtr->GetImpl();
102 //=======================================================================
103 //function : LoadFromFile
105 //=======================================================================
107 CORBA::Boolean SMESH_Pattern_i::LoadFromFile(const char* theFileContents)
109 // Update Python script
110 TPythonDump() << "isDone = pattern.LoadFromFile(" << theFileContents << ")";
111 addErrorCode( "LoadFromFile" );
113 return myPattern.Load( theFileContents );
116 //=======================================================================
117 //function : LoadFromFace
119 //=======================================================================
121 CORBA::Boolean SMESH_Pattern_i::LoadFromFace(SMESH::SMESH_Mesh_ptr theMesh,
122 GEOM::GEOM_Object_ptr theFace,
123 CORBA::Boolean theProject)
125 if ( theMesh->_is_nil() || theFace->_is_nil() )
128 ::SMESH_Mesh* aMesh = getMesh( theMesh );
132 TopoDS_Shape aFace = myGen->GeomObjectToShape( theFace );
133 if ( aFace.IsNull() || aFace.ShapeType() != TopAbs_FACE )
136 // Update Python script
137 TPythonDump() << "isDone = pattern.LoadFromFace( " << theMesh << ", "
138 << theFace << ", " << theProject << " )";
139 addErrorCode( "LoadFromFace" );
141 return myPattern.Load( aMesh, TopoDS::Face( aFace ), theProject );
144 //=======================================================================
145 //function : LoadFrom3DBlock
147 //=======================================================================
149 CORBA::Boolean SMESH_Pattern_i::LoadFrom3DBlock(SMESH::SMESH_Mesh_ptr theMesh,
150 GEOM::GEOM_Object_ptr theBlock)
152 if ( theMesh->_is_nil() || theBlock->_is_nil() )
155 ::SMESH_Mesh* aMesh = getMesh( theMesh );
159 TopoDS_Shape aShape = myGen->GeomObjectToShape( theBlock );
160 if ( aShape.IsNull())
163 TopExp_Explorer exp ( aShape, TopAbs_SHELL );
167 // Update Python script
168 TPythonDump() << "isDone = pattern.LoadFrom3DBlock( " << theMesh << ", " << theBlock << " )";
169 addErrorCode( "LoadFrom3DBlock" );
171 return myPattern.Load( aMesh, TopoDS::Shell( exp.Current() ));
174 //=======================================================================
175 //function : ApplyToFace
177 //=======================================================================
179 SMESH::point_array* SMESH_Pattern_i::ApplyToFace(GEOM::GEOM_Object_ptr theFace,
180 GEOM::GEOM_Object_ptr theVertexOnKeyPoint1,
181 CORBA::Boolean theReverse)
183 SMESH::point_array_var points = new SMESH::point_array;
184 list<const gp_XYZ *> xyzList;
186 TopoDS_Shape F = myGen->GeomObjectToShape( theFace );
187 TopoDS_Shape V = myGen->GeomObjectToShape( theVertexOnKeyPoint1 );
189 if (!F.IsNull() && F.ShapeType() == TopAbs_FACE &&
190 !V.IsNull() && V.ShapeType() == TopAbs_VERTEX
192 myPattern.Apply( TopoDS::Face( F ), TopoDS::Vertex( V ), theReverse ) &&
193 myPattern.GetMappedPoints( xyzList ))
195 points->length( xyzList.size() );
196 list<const gp_XYZ *>::iterator xyzIt = xyzList.begin();
197 for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) {
198 SMESH::PointStruct & p = points[ i++ ];
199 (*xyzIt)->Coord( p.x, p.y, p.z );
203 // Update Python script
204 TPythonDump() << "pattern.ApplyToFace( " << theFace << ", "
205 << theVertexOnKeyPoint1 << ", " << theReverse << " )";
207 return points._retn();
210 //=======================================================================
211 //function : ApplyTo3DBlock
213 //=======================================================================
215 SMESH::point_array* SMESH_Pattern_i::ApplyTo3DBlock(GEOM::GEOM_Object_ptr theBlock,
216 GEOM::GEOM_Object_ptr theVertex000,
217 GEOM::GEOM_Object_ptr theVertex001)
219 SMESH::point_array_var points = new SMESH::point_array;
220 list<const gp_XYZ *> xyzList;
222 TopExp_Explorer exp( myGen->GeomObjectToShape( theBlock ), TopAbs_SHELL );
223 TopoDS_Shape V000 = myGen->GeomObjectToShape( theVertex000 );
224 TopoDS_Shape V001 = myGen->GeomObjectToShape( theVertex001 );
227 !V000.IsNull() && V000.ShapeType() == TopAbs_VERTEX &&
228 !V001.IsNull() && V001.ShapeType() == TopAbs_VERTEX
230 myPattern.Apply(TopoDS::Shell( exp.Current() ),
231 TopoDS::Vertex( V000 ),
232 TopoDS::Vertex( V001 )) &&
233 myPattern.GetMappedPoints( xyzList ))
235 points->length( xyzList.size() );
236 list<const gp_XYZ *>::iterator xyzIt = xyzList.begin();
237 for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) {
238 SMESH::PointStruct & p = points[ i++ ];
239 (*xyzIt)->Coord( p.x, p.y, p.z );
243 // Update Python script
244 TPythonDump() << "pattern.ApplyTo3DBlock( " << theBlock << ", "
245 << theVertex000 << ", " << theVertex001 << " )";
247 return points._retn();
250 //=======================================================================
251 //function : ApplyToMeshFaces
253 //=======================================================================
256 SMESH_Pattern_i::ApplyToMeshFaces(SMESH::SMESH_Mesh_ptr theMesh,
257 const SMESH::long_array& theFacesIDs,
258 CORBA::Long theNodeIndexOnKeyPoint1,
259 CORBA::Boolean theReverse)
261 SMESH::point_array_var points = new SMESH::point_array;
263 ::SMESH_Mesh* aMesh = getMesh( theMesh );
265 return points._retn();
267 list<const gp_XYZ *> xyzList;
268 set<const SMDS_MeshFace*> fset;
269 for (int i = 0; i < theFacesIDs.length(); i++)
271 CORBA::Long index = theFacesIDs[i];
272 const SMDS_MeshElement * elem = aMesh->GetMeshDS()->FindElement(index);
273 if ( elem && elem->GetType() == SMDSAbs_Face )
274 fset.insert( static_cast<const SMDS_MeshFace *>( elem ));
276 if (myPattern.Apply( fset, theNodeIndexOnKeyPoint1, theReverse ) &&
277 myPattern.GetMappedPoints( xyzList ))
279 points->length( xyzList.size() );
280 list<const gp_XYZ *>::iterator xyzIt = xyzList.begin();
281 for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) {
282 SMESH::PointStruct & p = points[ i++ ];
283 (*xyzIt)->Coord( p.x, p.y, p.z );
287 // Update Python script
288 TPythonDump() << "pattern.ApplyToMeshFaces( " << theMesh << ", "
289 << theFacesIDs << ", "
290 << theNodeIndexOnKeyPoint1 << ", " << theReverse << " )";
292 return points._retn();
295 //=======================================================================
296 //function : ApplyToHexahedrons
298 //=======================================================================
301 SMESH_Pattern_i::ApplyToHexahedrons(SMESH::SMESH_Mesh_ptr theMesh,
302 const SMESH::long_array& theVolumesIDs,
303 CORBA::Long theNode000Index,
304 CORBA::Long theNode001Index)
306 SMESH::point_array_var points = new SMESH::point_array;
308 ::SMESH_Mesh* aMesh = getMesh( theMesh );
310 return points._retn();
312 list<const gp_XYZ *> xyzList;
313 set<const SMDS_MeshVolume*> vset;
314 for (int i = 0; i < theVolumesIDs.length(); i++)
316 CORBA::Long index = theVolumesIDs[i];
317 const SMDS_MeshElement * elem = aMesh->GetMeshDS()->FindElement(index);
318 if ( elem && elem->GetType() == SMDSAbs_Volume && elem->NbNodes() == 8 )
319 vset.insert( static_cast<const SMDS_MeshVolume *>( elem ));
321 if (myPattern.Apply( vset, theNode000Index, theNode001Index ) &&
322 myPattern.GetMappedPoints( xyzList ))
324 points->length( xyzList.size() );
325 list<const gp_XYZ *>::iterator xyzIt = xyzList.begin();
326 for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) {
327 SMESH::PointStruct & p = points[ i++ ];
328 (*xyzIt)->Coord( p.x, p.y, p.z );
332 // Update Python script
333 TPythonDump() << "pattern.ApplyToHexahedrons( " << theMesh << ", "
334 << theVolumesIDs << ", "
335 << theNode000Index << ", " << theNode001Index << " )";
337 return points._retn();
340 //=======================================================================
341 //function : MakeMesh
343 //=======================================================================
345 CORBA::Boolean SMESH_Pattern_i::MakeMesh (SMESH::SMESH_Mesh_ptr theMesh,
346 const CORBA::Boolean CreatePolygons,
347 const CORBA::Boolean CreatePolyedrs)
349 ::SMESH_Mesh* aMesh = getMesh( theMesh );
353 // Update Python script
354 TPythonDump() << "isDone = pattern.MakeMesh( " << theMesh << ", "
355 << CreatePolygons << ", " << CreatePolyedrs << " )";
356 addErrorCode( "MakeMesh" );
358 return myPattern.MakeMesh( aMesh, CreatePolygons, CreatePolyedrs );
361 //=======================================================================
362 //function : GetString
364 //=======================================================================
366 char* SMESH_Pattern_i::GetString()
369 myPattern.Save( os );
371 return CORBA::string_dup( os.str().c_str() );
374 //=======================================================================
377 //=======================================================================
379 CORBA::Boolean SMESH_Pattern_i::Is2D()
381 return myPattern.Is2D();
384 //=======================================================================
385 //function : GetPoints
387 //=======================================================================
389 SMESH::point_array* SMESH_Pattern_i::GetPoints()
391 SMESH::point_array_var points = new SMESH::point_array;
392 list<const gp_XYZ *> xyzList;
394 if (myPattern.GetPoints( xyzList ))
396 points->length( xyzList.size() );
397 list<const gp_XYZ *>::iterator xyzIt = xyzList.begin();
398 for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) {
399 SMESH::PointStruct & p = points[ i++ ];
400 (*xyzIt)->Coord( p.x, p.y, p.z );
404 return points._retn();
407 //=======================================================================
408 //function : GetKeyPoints
410 //=======================================================================
412 SMESH::long_array* SMESH_Pattern_i::GetKeyPoints()
414 SMESH::long_array_var ids = new SMESH::long_array;
415 if ( myPattern.IsLoaded() ) {
416 const list< int > & idList = myPattern.GetKeyPointIDs();
417 ids->length( idList.size() );
418 list< int >::const_iterator iIt = idList.begin();
419 for ( int i = 0; iIt != idList.end(); iIt++, i++ )
425 //=======================================================================
426 //function : GetElementPoints
428 //=======================================================================
430 SMESH::array_of_long_array* SMESH_Pattern_i::GetElementPoints(CORBA::Boolean applied)
432 SMESH::array_of_long_array_var arrayOfArray = new SMESH::array_of_long_array;
434 const list< list< int > >& listOfIdList = myPattern.GetElementPointIDs(applied);
435 arrayOfArray->length( listOfIdList.size() );
436 list< list< int > >::const_iterator llIt = listOfIdList.begin();
437 for ( int i = 0 ; llIt != listOfIdList.end(); llIt++, i++ )
439 const list< int > & idList = (*llIt);
440 SMESH::long_array& ids = arrayOfArray[ i ];
441 ids.length( idList.size() );
442 list< int >::const_iterator iIt = idList.begin();
443 for ( int j = 0; iIt != idList.end(); iIt++, j++ )
446 return arrayOfArray._retn();
449 //=======================================================================
450 //function : GetErrorCode
452 //=======================================================================
454 #define RETCASE(enm) case ::SMESH_Pattern::enm: return SMESH::SMESH_Pattern::enm;
456 SMESH::SMESH_Pattern::ErrorCode SMESH_Pattern_i::GetErrorCode()
458 switch ( myPattern.GetErrorCode() ) {
460 RETCASE( ERR_READ_NB_POINTS );
461 RETCASE( ERR_READ_POINT_COORDS );
462 RETCASE( ERR_READ_TOO_FEW_POINTS );
463 RETCASE( ERR_READ_3D_COORD );
464 RETCASE( ERR_READ_NO_KEYPOINT );
465 RETCASE( ERR_READ_BAD_INDEX );
466 RETCASE( ERR_READ_ELEM_POINTS );
467 RETCASE( ERR_READ_NO_ELEMS );
468 RETCASE( ERR_READ_BAD_KEY_POINT );
469 RETCASE( ERR_SAVE_NOT_LOADED );
470 RETCASE( ERR_LOAD_EMPTY_SUBMESH );
471 RETCASE( ERR_LOADF_NARROW_FACE );
472 RETCASE( ERR_LOADF_CLOSED_FACE );
473 RETCASE( ERR_LOADV_BAD_SHAPE );
474 RETCASE( ERR_LOADV_COMPUTE_PARAMS );
475 RETCASE( ERR_APPL_NOT_LOADED );
476 RETCASE( ERR_APPL_BAD_DIMENTION );
477 RETCASE( ERR_APPL_BAD_NB_VERTICES );
478 RETCASE( ERR_APPLF_BAD_TOPOLOGY );
479 RETCASE( ERR_APPLF_BAD_VERTEX );
480 RETCASE( ERR_APPLF_INTERNAL_EEROR );
481 RETCASE( ERR_APPLV_BAD_SHAPE );
482 RETCASE( ERR_MAKEM_NOT_COMPUTED );
485 return SMESH::SMESH_Pattern::ERR_OK;