1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH OBJECT : interactive object for SMESH visualization
23 // File : SMESH_Grid.cxx
24 // Author : Nicolas REJNERI
27 #include "SMESH_ObjectDef.h"
28 #include "SMESH_ActorUtils.h"
30 #include "SMDS_Mesh.hxx"
31 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
32 #include "SMESH_Actor.h"
33 #include "SMESH_ControlsDef.hxx"
34 #include "SalomeApp_Application.h"
35 #include "VTKViewer_ExtractUnstructuredGrid.h"
36 #include "VTKViewer_CellLocationsArray.h"
38 #include CORBA_SERVER_HEADER(SMESH_Gen)
39 #include CORBA_SERVER_HEADER(SALOME_Exception)
42 #include <vtkIdList.h>
43 #include <vtkCellArray.h>
44 #include <vtkUnsignedCharArray.h>
46 #include <vtkUnstructuredGrid.h>
53 #include "utilities.h"
58 #define EXCEPTION(TYPE, MSG) {\
59 std::ostringstream aStream;\
60 aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\
61 throw TYPE(aStream.str());\
66 static int MYDEBUG = 0;
67 static int MYDEBUGWITHFILES = 0;
69 static int MYDEBUG = 0;
70 static int MYDEBUGWITHFILES = 0;
75 Class : SMESH_VisualObjDef
76 Description : Base class for all mesh objects to be visuilised
79 //=================================================================================
80 // function : getCellType
81 // purpose : Get type of VTK cell
82 //=================================================================================
83 static inline vtkIdType getCellType( const SMDSAbs_ElementType theType,
85 const int theNbNodes )
89 case SMDSAbs_0DElement:
93 if( theNbNodes == 2 ) return VTK_LINE;
94 else if ( theNbNodes == 3 ) return VTK_QUADRATIC_EDGE;
95 else return VTK_EMPTY_CELL;
98 if (thePoly && theNbNodes>2 ) return VTK_POLYGON;
99 else if ( theNbNodes == 3 ) return VTK_TRIANGLE;
100 else if ( theNbNodes == 4 ) return VTK_QUAD;
101 else if ( theNbNodes == 6 ) return VTK_QUADRATIC_TRIANGLE;
102 else if ( theNbNodes == 8 ) return VTK_QUADRATIC_QUAD;
103 else return VTK_EMPTY_CELL;
106 if (thePoly && theNbNodes>3 ) return VTK_CONVEX_POINT_SET;
107 else if ( theNbNodes == 4 ) return VTK_TETRA;
108 else if ( theNbNodes == 5 ) return VTK_PYRAMID;
109 else if ( theNbNodes == 6 ) return VTK_WEDGE;
110 else if ( theNbNodes == 8 ) return VTK_HEXAHEDRON;
111 else if ( theNbNodes == 10 ) {
112 return VTK_QUADRATIC_TETRA;
114 else if ( theNbNodes == 20 ) {
115 return VTK_QUADRATIC_HEXAHEDRON;
117 else if ( theNbNodes == 15 ) {
118 return VTK_QUADRATIC_WEDGE;
120 else if ( theNbNodes==13 ) {
121 return VTK_CONVEX_POINT_SET;
123 else return VTK_EMPTY_CELL;
125 default: return VTK_EMPTY_CELL;
129 //=================================================================================
130 // functions : SMESH_VisualObjDef
131 // purpose : Constructor
132 //=================================================================================
133 SMESH_VisualObjDef::SMESH_VisualObjDef()
135 myGrid = vtkUnstructuredGrid::New();
137 SMESH_VisualObjDef::~SMESH_VisualObjDef()
140 MESSAGE( "~SMESH_MeshObj - myGrid->GetReferenceCount() = " << myGrid->GetReferenceCount() );
144 //=================================================================================
145 // functions : GetNodeObjId, GetNodeVTKId, GetElemObjId, GetElemVTKId
146 // purpose : Methods for retrieving VTK IDs by SMDS IDs and vice versa
147 //=================================================================================
148 vtkIdType SMESH_VisualObjDef::GetNodeObjId( int theVTKID )
150 TMapOfIds::const_iterator i = myVTK2SMDSNodes.find(theVTKID);
151 return i == myVTK2SMDSNodes.end() ? -1 : i->second;
154 vtkIdType SMESH_VisualObjDef::GetNodeVTKId( int theObjID )
156 TMapOfIds::const_iterator i = mySMDS2VTKNodes.find(theObjID);
157 return i == mySMDS2VTKNodes.end() ? -1 : i->second;
160 vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID )
162 TMapOfIds::const_iterator i = myVTK2SMDSElems.find(theVTKID);
163 return i == myVTK2SMDSElems.end() ? -1 : i->second;
166 vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID )
168 TMapOfIds::const_iterator i = mySMDS2VTKElems.find(theObjID);
169 return i == mySMDS2VTKElems.end() ? -1 : i->second;
172 //=================================================================================
173 // function : SMESH_VisualObjDef::createPoints
174 // purpose : Create points from nodes
175 //=================================================================================
176 void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints )
178 if ( thePoints == 0 )
182 vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes );
183 thePoints->SetNumberOfPoints( nbNodes );
187 TEntityList::const_iterator anIter;
188 for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter )
190 const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter);
193 thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() );
194 int anId = aNode->GetID();
195 mySMDS2VTKNodes.insert( TMapOfIds::value_type( anId, nbPoints ) );
196 myVTK2SMDSNodes.insert( TMapOfIds::value_type( nbPoints, anId ) );
201 if ( nbPoints != nbNodes )
202 thePoints->SetNumberOfPoints( nbPoints );
205 //=================================================================================
206 // function : buildPrs
207 // purpose : create VTK cells( fill unstructured grid )
208 //=================================================================================
209 void SMESH_VisualObjDef::buildPrs()
213 mySMDS2VTKNodes.clear();
214 myVTK2SMDSNodes.clear();
215 mySMDS2VTKElems.clear();
216 myVTK2SMDSElems.clear();
225 mySMDS2VTKNodes.clear();
226 myVTK2SMDSNodes.clear();
227 mySMDS2VTKElems.clear();
228 myVTK2SMDSElems.clear();
230 myGrid->SetPoints( 0 );
231 myGrid->SetCells( 0, 0, 0 );
235 if( MYDEBUG ) MESSAGE( "Update - myGrid->GetNumberOfCells() = "<<myGrid->GetNumberOfCells() );
236 if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"/tmp/buildPrs" );
239 //=================================================================================
240 // function : buildNodePrs
241 // purpose : create VTK cells for nodes
242 //=================================================================================
243 void SMESH_VisualObjDef::buildNodePrs()
245 // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
246 // so check remaining memory size for safety
247 SMDS_Mesh::CheckMemory(); // PAL16631
248 vtkPoints* aPoints = vtkPoints::New();
249 createPoints( aPoints );
250 SMDS_Mesh::CheckMemory();
251 myGrid->SetPoints( aPoints );
254 myGrid->SetCells( 0, 0, 0 );
257 //=================================================================================
258 // function : buildElemPrs
259 // purpose : Create VTK cells for elements
260 //=================================================================================
263 typedef std::vector<const SMDS_MeshElement*> TConnect;
265 int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter,
266 TConnect& theConnect)
269 for(; theNodesIter->more();)
270 theConnect.push_back(theNodesIter->next());
271 return theConnect.size();
275 void SetId(vtkIdList *theIdList,
276 const SMESH_VisualObjDef::TMapOfIds& theSMDS2VTKNodes,
277 const TConnect& theConnect,
281 theIdList->SetId(thePosition,theSMDS2VTKNodes.find(theConnect[theId]->GetID())->second);
287 void SMESH_VisualObjDef::buildElemPrs()
291 vtkPoints* aPoints = vtkPoints::New();
292 createPoints( aPoints );
293 myGrid->SetPoints( aPoints );
297 MESSAGE("Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints());
299 // Calculate cells size
301 static SMDSAbs_ElementType aTypes[ 4 ] =
302 { SMDSAbs_0DElement, SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume };
305 map<SMDSAbs_ElementType,int> nbEnts;
306 map<SMDSAbs_ElementType,TEntityList> anEnts;
308 for ( int i = 0; i <= 3; i++ )
309 nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] );
311 // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
312 // so check remaining memory size for safety
313 SMDS_Mesh::CheckMemory(); // PAL16631
315 vtkIdType aCellsSize = 2 * nbEnts[ SMDSAbs_0DElement ] + 3 * nbEnts[ SMDSAbs_Edge ];
317 for ( int i = 2; i <= 3; i++ ) // iterate through faces and volumes
319 if ( nbEnts[ aTypes[ i ] ] )
321 const TEntityList& aList = anEnts[ aTypes[ i ] ];
322 TEntityList::const_iterator anIter;
323 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
324 aCellsSize += (*anIter)->NbNodes() + 1;
328 vtkIdType aNbCells = nbEnts[ SMDSAbs_0DElement ] + nbEnts[ SMDSAbs_Edge ] +
329 nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ];
332 MESSAGE( "Update - aNbCells = "<<aNbCells<<"; aCellsSize = "<<aCellsSize );
336 vtkCellArray* aConnectivity = vtkCellArray::New();
337 aConnectivity->Allocate( aCellsSize, 0 );
339 SMDS_Mesh::CheckMemory(); // PAL16631
341 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
342 aCellTypesArray->SetNumberOfComponents( 1 );
343 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
345 SMDS_Mesh::CheckMemory(); // PAL16631
347 vtkIdList *anIdList = vtkIdList::New();
351 aConnect.reserve(VTK_CELL_SIZE);
353 SMDS_Mesh::CheckMemory(); // PAL16631
355 for ( int i = 0; i <= 3; i++ ) // iterate through 0d elements, edges, faces and volumes
357 if ( nbEnts[ aTypes[ i ] ] > 0 )
359 const SMDSAbs_ElementType& aType = aTypes[ i ];
360 const TEntityList& aList = anEnts[ aType ];
361 TEntityList::const_iterator anIter;
362 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
364 const SMDS_MeshElement* anElem = *anIter;
366 vtkIdType aNbNodes = anElem->NbNodes();
367 anIdList->SetNumberOfIds( aNbNodes );
369 int anId = anElem->GetID();
371 mySMDS2VTKElems.insert( TMapOfIds::value_type( anId, iElem ) );
372 myVTK2SMDSElems.insert( TMapOfIds::value_type( iElem, anId ) );
374 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
376 case SMDSAbs_Volume:{
378 std::vector<int> aConnectivities;
379 // Convertions connectivities from SMDS to VTK
380 if (anElem->IsPoly() && aNbNodes > 3) { // POLYEDRE
382 if ( const SMDS_PolyhedralVolumeOfNodes* ph =
383 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem))
385 aNbNodes = GetConnect(ph->uniqueNodesIterator(),aConnect);
386 anIdList->SetNumberOfIds( aNbNodes );
388 for (int k = 0; k < aNbNodes; k++)
389 aConnectivities.push_back(k);
391 } else if (aNbNodes == 4) {
392 static int anIds[] = {0,2,1,3};
393 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
395 } else if (aNbNodes == 5) {
396 static int anIds[] = {0,3,2,1,4};
397 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
399 } else if (aNbNodes == 6) {
400 static int anIds[] = {0,1,2,3,4,5};
401 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
404 else if (aNbNodes == 8) {
405 static int anIds[] = {0,3,2,1,4,7,6,5};
406 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
409 else if (aNbNodes == 10) {
410 static int anIds[] = {0,2,1,3,6,5,4,7,9,8};
411 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
413 else if (aNbNodes == 13) {
414 static int anIds[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
415 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
417 else if (aNbNodes == 15) {
418 //static int anIds[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
419 static int anIds[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
420 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
421 //for (int k = 0; k < aNbNodes; k++) {
422 // int nn = aConnectivities[k];
423 // const SMDS_MeshNode* N = static_cast<const SMDS_MeshNode*> (aConnect[nn]);
424 // cout<<"k="<<k<<" N("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
427 else if (aNbNodes == 20) {
428 static int anIds[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
429 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
434 if ( aConnect.empty() )
435 GetConnect(aNodesIter,aConnect);
437 if (aConnectivities.size() > 0) {
438 for (vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++)
439 SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]);
444 for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ){
445 const SMDS_MeshElement* aNode = aNodesIter->next();
446 anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] );
450 aConnectivity->InsertNextCell( anIdList );
451 aCellTypesArray->InsertNextValue( getCellType( aType, anElem->IsPoly(), aNbNodes ) );
456 SMDS_Mesh::CheckMemory(); // PAL16631
459 // Insert cells in grid
461 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
462 aCellLocationsArray->SetNumberOfComponents( 1 );
463 aCellLocationsArray->SetNumberOfTuples( aNbCells );
465 SMDS_Mesh::CheckMemory(); // PAL16631
467 aConnectivity->InitTraversal();
468 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
469 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
471 myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
473 aCellLocationsArray->Delete();
474 aCellTypesArray->Delete();
475 aConnectivity->Delete();
478 SMDS_Mesh::CheckMemory(); // PAL16631
481 //=================================================================================
482 // function : GetEdgeNodes
483 // purpose : Retrieve ids of nodes from edge of elements ( edge is numbered from 1 )
484 //=================================================================================
485 bool SMESH_VisualObjDef::GetEdgeNodes( const int theElemId,
486 const int theEdgeNum,
488 int& theNodeId2 ) const
490 const SMDS_Mesh* aMesh = GetMesh();
494 const SMDS_MeshElement* anElem = aMesh->FindElement( theElemId );
498 int nbNodes = anElem->NbNodes();
500 if ( theEdgeNum < 0 || theEdgeNum > 3 || nbNodes != 3 && nbNodes != 4 || theEdgeNum > nbNodes )
503 vector<int> anIds( nbNodes );
504 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
506 while( anIter->more() )
507 anIds[ i++ ] = anIter->next()->GetID();
509 if ( theEdgeNum < nbNodes - 1 )
511 theNodeId1 = anIds[ theEdgeNum ];
512 theNodeId2 = anIds[ theEdgeNum + 1 ];
516 theNodeId1 = anIds[ nbNodes - 1 ];
517 theNodeId2 = anIds[ 0 ];
523 //=================================================================================
524 // function : IsValid
525 // purpose : Return true if there are some entities
526 //=================================================================================
527 bool SMESH_VisualObjDef::IsValid() const
529 return GetNbEntities(SMDSAbs_Node) > 0 ||
530 GetNbEntities(SMDSAbs_0DElement) > 0 ||
531 GetNbEntities(SMDSAbs_Edge) > 0 ||
532 GetNbEntities(SMDSAbs_Face) > 0 ||
533 GetNbEntities(SMDSAbs_Volume) > 0 ;
537 Class : SMESH_MeshObj
538 Description : Class for visualisation of mesh
541 //=================================================================================
542 // function : SMESH_MeshObj
543 // purpose : Constructor
544 //=================================================================================
545 SMESH_MeshObj::SMESH_MeshObj(SMESH::SMESH_Mesh_ptr theMesh):
546 myClient(SalomeApp_Application::orb(),theMesh)
549 MESSAGE("SMESH_MeshObj - this = "<<this<<"; theMesh->_is_nil() = "<<theMesh->_is_nil());
552 //=================================================================================
553 // function : ~SMESH_MeshObj
554 // purpose : Destructor
555 //=================================================================================
556 SMESH_MeshObj::~SMESH_MeshObj()
559 MESSAGE("SMESH_MeshObj - this = "<<this<<"\n");
562 //=================================================================================
564 // purpose : Update mesh and fill grid with new values if necessary
565 //=================================================================================
566 bool SMESH_MeshObj::Update( int theIsClear )
568 // Update SMDS_Mesh on client part
569 if ( myClient.Update(theIsClear) || GetUnstructuredGrid()->GetNumberOfPoints()==0) {
570 buildPrs(); // Fill unstructured grid
576 //=================================================================================
577 // function : GetElemDimension
578 // purpose : Get dimension of element
579 //=================================================================================
580 int SMESH_MeshObj::GetElemDimension( const int theObjId )
582 const SMDS_MeshElement* anElem = myClient->FindElement( theObjId );
586 int aType = anElem->GetType();
589 case SMDSAbs_0DElement : return 0;
590 case SMDSAbs_Edge : return 1;
591 case SMDSAbs_Face : return 2;
592 case SMDSAbs_Volume: return 3;
597 //=================================================================================
598 // function : GetEntities
599 // purpose : Get entities of specified type. Return number of entities
600 //=================================================================================
601 int SMESH_MeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
607 return myClient->NbNodes();
610 case SMDSAbs_0DElement:
612 return myClient->Nb0DElements();
617 return myClient->NbEdges();
622 return myClient->NbFaces();
627 return myClient->NbVolumes();
636 int SMESH_MeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theObjs ) const
644 SMDS_NodeIteratorPtr anIter = myClient->nodesIterator();
645 while ( anIter->more() ) theObjs.push_back( anIter->next() );
648 case SMDSAbs_0DElement:
650 SMDS_0DElementIteratorPtr anIter = myClient->elements0dIterator();
651 while ( anIter->more() ) theObjs.push_back( anIter->next() );
656 SMDS_EdgeIteratorPtr anIter = myClient->edgesIterator();
657 while ( anIter->more() ) theObjs.push_back( anIter->next() );
662 SMDS_FaceIteratorPtr anIter = myClient->facesIterator();
663 while ( anIter->more() ) theObjs.push_back( anIter->next() );
668 SMDS_VolumeIteratorPtr anIter = myClient->volumesIterator();
669 while ( anIter->more() ) theObjs.push_back( anIter->next() );
676 return theObjs.size();
679 //=================================================================================
680 // function : UpdateFunctor
681 // purpose : Update functor in accordance with current mesh
682 //=================================================================================
683 void SMESH_MeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
685 theFunctor->SetMesh( GetMesh() );
688 //=================================================================================
689 // function : IsNodePrs
690 // purpose : Return true if node presentation is used
691 //=================================================================================
692 bool SMESH_MeshObj::IsNodePrs() const
694 return myClient->Nb0DElements() == 0 && myClient->NbEdges() == 0 && myClient->NbFaces() == 0 && myClient->NbVolumes() == 0 ;
699 Class : SMESH_SubMeshObj
700 Description : Base class for visualisation of submeshes and groups
703 //=================================================================================
704 // function : SMESH_SubMeshObj
705 // purpose : Constructor
706 //=================================================================================
707 SMESH_SubMeshObj::SMESH_SubMeshObj( SMESH_MeshObj* theMeshObj )
709 if ( MYDEBUG ) MESSAGE( "SMESH_SubMeshObj - theMeshObj = " << theMeshObj );
711 myMeshObj = theMeshObj;
714 SMESH_SubMeshObj::~SMESH_SubMeshObj()
718 //=================================================================================
719 // function : GetElemDimension
720 // purpose : Get dimension of element
721 //=================================================================================
722 int SMESH_SubMeshObj::GetElemDimension( const int theObjId )
724 return myMeshObj == 0 ? 0 : myMeshObj->GetElemDimension( theObjId );
727 //=================================================================================
728 // function : UpdateFunctor
729 // purpose : Update functor in accordance with current mesh
730 //=================================================================================
731 void SMESH_SubMeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
733 theFunctor->SetMesh( myMeshObj->GetMesh() );
736 //=================================================================================
738 // purpose : Update mesh object and fill grid with new values
739 //=================================================================================
740 bool SMESH_SubMeshObj::Update( int theIsClear )
742 bool changed = myMeshObj->Update( theIsClear );
749 Class : SMESH_GroupObj
750 Description : Class for visualisation of groups
753 //=================================================================================
754 // function : SMESH_GroupObj
755 // purpose : Constructor
756 //=================================================================================
757 SMESH_GroupObj::SMESH_GroupObj( SMESH::SMESH_GroupBase_ptr theGroup,
758 SMESH_MeshObj* theMeshObj )
759 : SMESH_SubMeshObj( theMeshObj ),
760 myGroupServer( SMESH::SMESH_GroupBase::_duplicate(theGroup) )
762 if ( MYDEBUG ) MESSAGE("SMESH_GroupObj - theGroup->_is_nil() = "<<theGroup->_is_nil());
763 myGroupServer->Register();
766 SMESH_GroupObj::~SMESH_GroupObj()
768 if ( MYDEBUG ) MESSAGE("~SMESH_GroupObj");
769 myGroupServer->Destroy();
772 //=================================================================================
773 // function : IsNodePrs
774 // purpose : Return true if node presentation is used
775 //=================================================================================
776 bool SMESH_GroupObj::IsNodePrs() const
778 return myGroupServer->GetType() == SMESH::NODE;
781 //=================================================================================
782 // function : GetElementType
783 // purpose : Return type of elements of group
784 //=================================================================================
785 SMDSAbs_ElementType SMESH_GroupObj::GetElementType() const
787 return SMDSAbs_ElementType(myGroupServer->GetType());
790 //=================================================================================
791 // function : getNodesFromElems
792 // purpose : Retrieve nodes from elements
793 //=================================================================================
794 static int getNodesFromElems( SMESH::long_array_var& theElemIds,
795 const SMDS_Mesh* theMesh,
796 std::list<const SMDS_MeshElement*>& theResList )
798 set<const SMDS_MeshElement*> aNodeSet;
800 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
802 const SMDS_MeshElement* anElem = theMesh->FindElement( theElemIds[ i ] );
805 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
806 while ( anIter->more() )
808 const SMDS_MeshElement* aNode = anIter->next();
810 aNodeSet.insert( aNode );
815 set<const SMDS_MeshElement*>::const_iterator anIter;
816 for ( anIter = aNodeSet.begin(); anIter != aNodeSet.end(); ++anIter )
817 theResList.push_back( *anIter );
819 return theResList.size();
822 //=================================================================================
823 // function : getPointers
824 // purpose : Get std::list<const SMDS_MeshElement*> from list of IDs
825 //=================================================================================
826 static int getPointers( const SMDSAbs_ElementType theRequestType,
827 SMESH::long_array_var& theElemIds,
828 const SMDS_Mesh* theMesh,
829 std::list<const SMDS_MeshElement*>& theResList )
831 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
833 const SMDS_MeshElement* anElem = theRequestType == SMDSAbs_Node
834 ? theMesh->FindNode( theElemIds[ i ] ) : theMesh->FindElement( theElemIds[ i ] );
837 theResList.push_back( anElem );
840 return theResList.size();
844 //=================================================================================
845 // function : GetEntities
846 // purpose : Get entities of specified type. Return number of entities
847 //=================================================================================
848 int SMESH_GroupObj::GetNbEntities( const SMDSAbs_ElementType theType) const
850 if(SMDSAbs_ElementType(myGroupServer->GetType()) == theType){
851 return myGroupServer->Size();
856 int SMESH_GroupObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
859 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
861 if ( myGroupServer->Size() == 0 || aMesh == 0 )
864 SMDSAbs_ElementType aGrpType = SMDSAbs_ElementType(myGroupServer->GetType());
865 SMESH::long_array_var anIds = myGroupServer->GetListOfID();
867 if ( aGrpType == theType )
868 return getPointers( theType, anIds, aMesh, theResList );
869 else if ( theType == SMDSAbs_Node )
870 return getNodesFromElems( anIds, aMesh, theResList );
878 Class : SMESH_subMeshObj
879 Description : Class for visualisation of submeshes
882 //=================================================================================
883 // function : SMESH_subMeshObj
884 // purpose : Constructor
885 //=================================================================================
886 SMESH_subMeshObj::SMESH_subMeshObj( SMESH::SMESH_subMesh_ptr theSubMesh,
887 SMESH_MeshObj* theMeshObj )
888 : SMESH_SubMeshObj( theMeshObj ),
889 mySubMeshServer( SMESH::SMESH_subMesh::_duplicate( theSubMesh ) )
891 if ( MYDEBUG ) MESSAGE( "SMESH_subMeshObj - theSubMesh->_is_nil() = " << theSubMesh->_is_nil() );
893 mySubMeshServer->Register();
896 SMESH_subMeshObj::~SMESH_subMeshObj()
898 if ( MYDEBUG ) MESSAGE( "~SMESH_subMeshObj" );
899 mySubMeshServer->Destroy();
902 //=================================================================================
903 // function : GetEntities
904 // purpose : Get entities of specified type. Return number of entities
905 //=================================================================================
906 int SMESH_subMeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
912 return mySubMeshServer->GetNumberOfNodes( false );
915 case SMDSAbs_0DElement:
920 SMESH::long_array_var anIds =
921 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
922 return anIds->length();
930 int SMESH_subMeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
934 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
938 bool isNodal = IsNodePrs();
942 if ( theType == SMDSAbs_Node )
944 SMESH::long_array_var anIds = mySubMeshServer->GetNodesId();
945 return getPointers( SMDSAbs_Node, anIds, aMesh, theResList );
950 if ( theType == SMDSAbs_Node )
952 SMESH::long_array_var anIds = mySubMeshServer->GetElementsId();
953 return getNodesFromElems( anIds, aMesh, theResList );
957 SMESH::long_array_var anIds =
958 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
959 return getPointers( theType, anIds, aMesh, theResList );
966 //=================================================================================
967 // function : IsNodePrs
968 // purpose : Return true if node presentation is used
969 //=================================================================================
970 bool SMESH_subMeshObj::IsNodePrs() const
972 return mySubMeshServer->GetNumberOfElements() == 0;