1 // SMESH OBJECT : interactive object for SMESH visualization
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Grid.cxx
25 // Author : Nicolas REJNERI
28 #include "SMESH_ObjectDef.h"
29 #include "SMESH_ActorUtils.h"
31 #include "SMDS_Mesh.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 )
90 if( theNbNodes == 2 ) return VTK_LINE;
91 else if ( theNbNodes == 3 ) return VTK_QUADRATIC_EDGE;
92 else return VTK_EMPTY_CELL;
95 if (thePoly && theNbNodes>2 ) return VTK_POLYGON;
96 else if ( theNbNodes == 3 ) return VTK_TRIANGLE;
97 else if ( theNbNodes == 4 ) return VTK_QUAD;
98 else if ( theNbNodes == 6 ) return VTK_QUADRATIC_TRIANGLE;
99 else if ( theNbNodes == 8 ) return VTK_QUADRATIC_QUAD;
100 else return VTK_EMPTY_CELL;
103 if (thePoly && theNbNodes>3 ) return VTK_CONVEX_POINT_SET;
104 else if ( theNbNodes == 4 ) return VTK_TETRA;
105 else if ( theNbNodes == 5 ) return VTK_PYRAMID;
106 else if ( theNbNodes == 6 ) return VTK_WEDGE;
107 else if ( theNbNodes == 8 ) return VTK_HEXAHEDRON;
108 else if ( theNbNodes == 10 ) {
109 return VTK_QUADRATIC_TETRA;
111 else if ( theNbNodes == 20 ) {
112 return VTK_QUADRATIC_HEXAHEDRON;
114 else if ( theNbNodes==13 || theNbNodes==15 ) {
115 return VTK_CONVEX_POINT_SET;
117 else return VTK_EMPTY_CELL;
119 default: return VTK_EMPTY_CELL;
123 //=================================================================================
124 // functions : SMESH_VisualObjDef
125 // purpose : Constructor
126 //=================================================================================
127 SMESH_VisualObjDef::SMESH_VisualObjDef()
129 myGrid = vtkUnstructuredGrid::New();
131 SMESH_VisualObjDef::~SMESH_VisualObjDef()
134 MESSAGE( "~SMESH_MeshObj - myGrid->GetReferenceCount() = " << myGrid->GetReferenceCount() );
138 //=================================================================================
139 // functions : GetNodeObjId, GetNodeVTKId, GetElemObjId, GetElemVTKId
140 // purpose : Methods for retrieving VTK IDs by SMDS IDs and vice versa
141 //=================================================================================
142 vtkIdType SMESH_VisualObjDef::GetNodeObjId( int theVTKID )
144 return myVTK2SMDSNodes.find(theVTKID) == myVTK2SMDSNodes.end() ? -1 : myVTK2SMDSNodes[theVTKID];
147 vtkIdType SMESH_VisualObjDef::GetNodeVTKId( int theObjID )
149 return mySMDS2VTKNodes.find(theObjID) == mySMDS2VTKNodes.end() ? -1 : mySMDS2VTKNodes[theObjID];
152 vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID )
154 return myVTK2SMDSElems.find(theVTKID) == myVTK2SMDSElems.end() ? -1 : myVTK2SMDSElems[theVTKID];
157 vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID )
159 return mySMDS2VTKElems.find(theObjID) == mySMDS2VTKElems.end() ? -1 : mySMDS2VTKElems[theObjID];
162 //=================================================================================
163 // function : SMESH_VisualObjDef::createPoints
164 // purpose : Create points from nodes
165 //=================================================================================
166 void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints )
168 if ( thePoints == 0 )
172 vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes );
173 thePoints->SetNumberOfPoints( nbNodes );
177 TEntityList::const_iterator anIter;
178 for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter )
180 const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter);
183 thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() );
184 int anId = aNode->GetID();
185 mySMDS2VTKNodes.insert( TMapOfIds::value_type( anId, nbPoints ) );
186 myVTK2SMDSNodes.insert( TMapOfIds::value_type( nbPoints, anId ) );
191 if ( nbPoints != nbNodes )
192 thePoints->SetNumberOfPoints( nbPoints );
195 //=================================================================================
196 // function : buildPrs
197 // purpose : create VTK cells( fill unstructured grid )
198 //=================================================================================
199 void SMESH_VisualObjDef::buildPrs()
203 mySMDS2VTKNodes.clear();
204 myVTK2SMDSNodes.clear();
205 mySMDS2VTKElems.clear();
206 myVTK2SMDSElems.clear();
213 catch( const std::exception& exc )
215 INFOS("Follow exception was cought:\n\t"<<exc.what());
219 INFOS("Unknown exception was cought !!!");
222 if( MYDEBUG ) MESSAGE( "Update - myGrid->GetNumberOfCells() = "<<myGrid->GetNumberOfCells() );
223 if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"/tmp/buildPrs" );
226 //=================================================================================
227 // function : buildNodePrs
228 // purpose : create VTK cells for nodes
229 //=================================================================================
230 void SMESH_VisualObjDef::buildNodePrs()
232 vtkPoints* aPoints = vtkPoints::New();
233 createPoints( aPoints );
234 myGrid->SetPoints( aPoints );
237 myGrid->SetCells( 0, 0, 0 );
240 //=================================================================================
241 // function : buildElemPrs
242 // purpose : Create VTK cells for elements
243 //=================================================================================
246 typedef std::vector<const SMDS_MeshElement*> TConnect;
248 int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter,
249 TConnect& theConnect)
252 for(; theNodesIter->more();)
253 theConnect.push_back(theNodesIter->next());
254 return theConnect.size();
258 void SetId(vtkIdList *theIdList,
259 const SMESH_VisualObjDef::TMapOfIds& theSMDS2VTKNodes,
260 const TConnect& theConnect,
264 theIdList->SetId(thePosition,theSMDS2VTKNodes.find(theConnect[theId]->GetID())->second);
270 void SMESH_VisualObjDef::buildElemPrs()
274 vtkPoints* aPoints = vtkPoints::New();
275 createPoints( aPoints );
276 myGrid->SetPoints( aPoints );
280 MESSAGE("Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints());
282 // Calculate cells size
284 static SMDSAbs_ElementType aTypes[ 3 ] = { SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume };
287 map<SMDSAbs_ElementType,int> nbEnts;
288 map<SMDSAbs_ElementType,TEntityList> anEnts;
290 for ( int i = 0; i <= 2; i++ )
291 nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] );
293 vtkIdType aCellsSize = 3 * nbEnts[ SMDSAbs_Edge ];
295 for ( int i = 1; i <= 2; i++ ) // iterate through faces and volumes
297 if ( nbEnts[ aTypes[ i ] ] )
299 const TEntityList& aList = anEnts[ aTypes[ i ] ];
300 TEntityList::const_iterator anIter;
301 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
302 aCellsSize += (*anIter)->NbNodes() + 1;
306 vtkIdType aNbCells = nbEnts[ SMDSAbs_Edge ] + nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ];
309 MESSAGE( "Update - aNbCells = "<<aNbCells<<"; aCellsSize = "<<aCellsSize );
313 vtkCellArray* aConnectivity = vtkCellArray::New();
314 aConnectivity->Allocate( aCellsSize, 0 );
316 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
317 aCellTypesArray->SetNumberOfComponents( 1 );
318 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
320 vtkIdList *anIdList = vtkIdList::New();
324 aConnect.reserve(VTK_CELL_SIZE);
326 for ( int i = 0; i <= 2; i++ ) // iterate through edges, faces and volumes
328 if( nbEnts[ aTypes[ i ] ] > 0 )
330 const SMDSAbs_ElementType& aType = aTypes[ i ];
331 const TEntityList& aList = anEnts[ aType ];
332 TEntityList::const_iterator anIter;
333 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
335 const SMDS_MeshElement* anElem = *anIter;
337 vtkIdType aNbNodes = anElem->NbNodes();
338 anIdList->SetNumberOfIds( aNbNodes );
340 int anId = anElem->GetID();
342 mySMDS2VTKElems.insert( TMapOfIds::value_type( anId, iElem ) );
343 myVTK2SMDSElems.insert( TMapOfIds::value_type( iElem, anId ) );
345 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
347 case SMDSAbs_Volume:{
348 std::vector<int> aConnectivities;
349 GetConnect(aNodesIter,aConnect);
350 // Convertions connectivities from SMDS to VTK
351 if (anElem->IsPoly() && aNbNodes > 3) { // POLYEDRE
352 for (int k = 0; k < aNbNodes; k++) {
353 aConnectivities.push_back(k);
356 } else if (aNbNodes == 4) {
357 static int anIds[] = {0,2,1,3};
358 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
360 } else if (aNbNodes == 5) {
361 static int anIds[] = {0,3,2,1,4};
362 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
364 } else if (aNbNodes == 6) {
365 static int anIds[] = {0,1,2,3,4,5};
366 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
369 else if (aNbNodes == 8) {
370 static int anIds[] = {0,3,2,1,4,7,6,5};
371 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
374 else if (aNbNodes == 10) {
375 static int anIds[] = {0,2,1,3,6,5,4,7,9,8};
376 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
378 else if (aNbNodes == 13) {
379 static int anIds[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
380 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
382 else if (aNbNodes == 15) {
383 static int anIds[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
384 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
385 //for (int k = 0; k < aNbNodes; k++) {
386 // int nn = aConnectivities[k];
387 // const SMDS_MeshNode* N = static_cast<const SMDS_MeshNode*> (aConnect[nn]);
388 // cout<<"k="<<k<<" N("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
391 else if (aNbNodes == 20) {
392 static int anIds[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
393 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
398 if (aConnectivities.size() > 0) {
399 for (vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++)
400 SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]);
405 for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ){
406 const SMDS_MeshElement* aNode = aNodesIter->next();
407 anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] );
411 aConnectivity->InsertNextCell( anIdList );
412 aCellTypesArray->InsertNextValue( getCellType( aType, anElem->IsPoly(), aNbNodes ) );
419 // Insert cells in grid
421 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
422 aCellLocationsArray->SetNumberOfComponents( 1 );
423 aCellLocationsArray->SetNumberOfTuples( aNbCells );
425 aConnectivity->InitTraversal();
426 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
427 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
429 myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
431 aCellLocationsArray->Delete();
432 aCellTypesArray->Delete();
433 aConnectivity->Delete();
437 //=================================================================================
438 // function : GetEdgeNodes
439 // purpose : Retrieve ids of nodes from edge of elements ( edge is numbered from 1 )
440 //=================================================================================
441 bool SMESH_VisualObjDef::GetEdgeNodes( const int theElemId,
442 const int theEdgeNum,
444 int& theNodeId2 ) const
446 const SMDS_Mesh* aMesh = GetMesh();
450 const SMDS_MeshElement* anElem = aMesh->FindElement( theElemId );
454 int nbNodes = anElem->NbNodes();
456 if ( theEdgeNum < 0 || theEdgeNum > 3 || nbNodes != 3 && nbNodes != 4 || theEdgeNum > nbNodes )
459 int anIds[ nbNodes ];
460 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
462 while( anIter->more() )
463 anIds[ i++ ] = anIter->next()->GetID();
465 if ( theEdgeNum < nbNodes - 1 )
467 theNodeId1 = anIds[ theEdgeNum ];
468 theNodeId2 = anIds[ theEdgeNum + 1 ];
472 theNodeId1 = anIds[ nbNodes - 1 ];
473 theNodeId2 = anIds[ 0 ];
480 Class : SMESH_MeshObj
481 Description : Class for visualisation of mesh
484 //=================================================================================
485 // function : SMESH_MeshObj
486 // purpose : Constructor
487 //=================================================================================
488 SMESH_MeshObj::SMESH_MeshObj(SMESH::SMESH_Mesh_ptr theMesh):
489 myClient(SalomeApp_Application::orb(),theMesh)
492 MESSAGE("SMESH_MeshObj - this = "<<this<<"; theMesh->_is_nil() = "<<theMesh->_is_nil());
495 //=================================================================================
496 // function : ~SMESH_MeshObj
497 // purpose : Destructor
498 //=================================================================================
499 SMESH_MeshObj::~SMESH_MeshObj()
502 MESSAGE("SMESH_MeshObj - this = "<<this<<"\n");
505 //=================================================================================
507 // purpose : Update mesh and fill grid with new values if necessary
508 //=================================================================================
509 void SMESH_MeshObj::Update( int theIsClear )
511 // Update SMDS_Mesh on client part
512 if ( myClient.Update(theIsClear) )
513 buildPrs(); // Fill unstructured grid
516 //=================================================================================
517 // function : GetElemDimension
518 // purpose : Get dimension of element
519 //=================================================================================
520 int SMESH_MeshObj::GetElemDimension( const int theObjId )
522 const SMDS_MeshElement* anElem = myClient->FindElement( theObjId );
526 int aType = anElem->GetType();
529 case SMDSAbs_Edge : return 1;
530 case SMDSAbs_Face : return 2;
531 case SMDSAbs_Volume: return 3;
536 //=================================================================================
537 // function : GetEntities
538 // purpose : Get entities of specified type. Return number of entities
539 //=================================================================================
540 int SMESH_MeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
546 return myClient->NbNodes();
551 return myClient->NbEdges();
556 return myClient->NbFaces();
561 return myClient->NbVolumes();
570 int SMESH_MeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theObjs ) const
578 SMDS_NodeIteratorPtr anIter = myClient->nodesIterator();
579 while ( anIter->more() ) theObjs.push_back( anIter->next() );
584 SMDS_EdgeIteratorPtr anIter = myClient->edgesIterator();
585 while ( anIter->more() ) theObjs.push_back( anIter->next() );
590 SMDS_FaceIteratorPtr anIter = myClient->facesIterator();
591 while ( anIter->more() ) theObjs.push_back( anIter->next() );
596 SMDS_VolumeIteratorPtr anIter = myClient->volumesIterator();
597 while ( anIter->more() ) theObjs.push_back( anIter->next() );
604 return theObjs.size();
607 //=================================================================================
608 // function : UpdateFunctor
609 // purpose : Update functor in accordance with current mesh
610 //=================================================================================
611 void SMESH_MeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
613 theFunctor->SetMesh( GetMesh() );
616 //=================================================================================
617 // function : IsNodePrs
618 // purpose : Return true if node presentation is used
619 //=================================================================================
620 bool SMESH_MeshObj::IsNodePrs() const
622 return myClient->NbEdges() == 0 &&myClient->NbFaces() == 0 && myClient->NbVolumes() == 0 ;
627 Class : SMESH_SubMeshObj
628 Description : Base class for visualisation of submeshes and groups
631 //=================================================================================
632 // function : SMESH_SubMeshObj
633 // purpose : Constructor
634 //=================================================================================
635 SMESH_SubMeshObj::SMESH_SubMeshObj( SMESH_MeshObj* theMeshObj )
637 if ( MYDEBUG ) MESSAGE( "SMESH_SubMeshObj - theMeshObj = " << theMeshObj );
639 myMeshObj = theMeshObj;
642 SMESH_SubMeshObj::~SMESH_SubMeshObj()
646 //=================================================================================
647 // function : GetElemDimension
648 // purpose : Get dimension of element
649 //=================================================================================
650 int SMESH_SubMeshObj::GetElemDimension( const int theObjId )
652 return myMeshObj == 0 ? 0 : myMeshObj->GetElemDimension( theObjId );
655 //=================================================================================
656 // function : UpdateFunctor
657 // purpose : Update functor in accordance with current mesh
658 //=================================================================================
659 void SMESH_SubMeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
661 theFunctor->SetMesh( myMeshObj->GetMesh() );
664 //=================================================================================
666 // purpose : Update mesh object and fill grid with new values
667 //=================================================================================
668 void SMESH_SubMeshObj::Update( int theIsClear )
670 myMeshObj->Update( theIsClear );
676 Class : SMESH_GroupObj
677 Description : Class for visualisation of groups
680 //=================================================================================
681 // function : SMESH_GroupObj
682 // purpose : Constructor
683 //=================================================================================
684 SMESH_GroupObj::SMESH_GroupObj( SMESH::SMESH_GroupBase_ptr theGroup,
685 SMESH_MeshObj* theMeshObj )
686 : SMESH_SubMeshObj( theMeshObj ),
687 myGroupServer( SMESH::SMESH_GroupBase::_duplicate(theGroup) )
689 if ( MYDEBUG ) MESSAGE("SMESH_GroupObj - theGroup->_is_nil() = "<<theGroup->_is_nil());
690 myGroupServer->Register();
693 SMESH_GroupObj::~SMESH_GroupObj()
695 if ( MYDEBUG ) MESSAGE("~SMESH_GroupObj");
696 myGroupServer->Destroy();
699 //=================================================================================
700 // function : IsNodePrs
701 // purpose : Return true if node presentation is used
702 //=================================================================================
703 bool SMESH_GroupObj::IsNodePrs() const
705 return myGroupServer->GetType() == SMESH::NODE;
708 //=================================================================================
709 // function : getNodesFromElems
710 // purpose : Retrieve nodes from elements
711 //=================================================================================
712 static int getNodesFromElems( SMESH::long_array_var& theElemIds,
713 const SMDS_Mesh* theMesh,
714 std::list<const SMDS_MeshElement*>& theResList )
716 set<const SMDS_MeshElement*> aNodeSet;
718 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
720 const SMDS_MeshElement* anElem = theMesh->FindElement( theElemIds[ i ] );
723 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
724 while ( anIter->more() )
726 const SMDS_MeshElement* aNode = anIter->next();
728 aNodeSet.insert( aNode );
733 set<const SMDS_MeshElement*>::const_iterator anIter;
734 for ( anIter = aNodeSet.begin(); anIter != aNodeSet.end(); ++anIter )
735 theResList.push_back( *anIter );
737 return theResList.size();
740 //=================================================================================
741 // function : getPointers
742 // purpose : Get std::list<const SMDS_MeshElement*> from list of IDs
743 //=================================================================================
744 static int getPointers( const SMDSAbs_ElementType theRequestType,
745 SMESH::long_array_var& theElemIds,
746 const SMDS_Mesh* theMesh,
747 std::list<const SMDS_MeshElement*>& theResList )
749 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
751 const SMDS_MeshElement* anElem = theRequestType == SMDSAbs_Node
752 ? theMesh->FindNode( theElemIds[ i ] ) : theMesh->FindElement( theElemIds[ i ] );
755 theResList.push_back( anElem );
758 return theResList.size();
762 //=================================================================================
763 // function : GetEntities
764 // purpose : Get entities of specified type. Return number of entities
765 //=================================================================================
766 int SMESH_GroupObj::GetNbEntities( const SMDSAbs_ElementType theType) const
768 if(SMDSAbs_ElementType(myGroupServer->GetType()) == theType){
769 return myGroupServer->Size();
774 int SMESH_GroupObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
777 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
779 if ( myGroupServer->Size() == 0 || aMesh == 0 )
782 SMDSAbs_ElementType aGrpType = SMDSAbs_ElementType(myGroupServer->GetType());
783 SMESH::long_array_var anIds = myGroupServer->GetListOfID();
785 if ( aGrpType == theType )
786 return getPointers( theType, anIds, aMesh, theResList );
787 else if ( theType == SMDSAbs_Node )
788 return getNodesFromElems( anIds, aMesh, theResList );
796 Class : SMESH_subMeshObj
797 Description : Class for visualisation of submeshes
800 //=================================================================================
801 // function : SMESH_subMeshObj
802 // purpose : Constructor
803 //=================================================================================
804 SMESH_subMeshObj::SMESH_subMeshObj( SMESH::SMESH_subMesh_ptr theSubMesh,
805 SMESH_MeshObj* theMeshObj )
806 : SMESH_SubMeshObj( theMeshObj ),
807 mySubMeshServer( SMESH::SMESH_subMesh::_duplicate( theSubMesh ) )
809 if ( MYDEBUG ) MESSAGE( "SMESH_subMeshObj - theSubMesh->_is_nil() = " << theSubMesh->_is_nil() );
811 mySubMeshServer->Register();
814 SMESH_subMeshObj::~SMESH_subMeshObj()
816 if ( MYDEBUG ) MESSAGE( "~SMESH_subMeshObj" );
817 mySubMeshServer->Destroy();
820 //=================================================================================
821 // function : GetEntities
822 // purpose : Get entities of specified type. Return number of entities
823 //=================================================================================
824 int SMESH_subMeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
830 return mySubMeshServer->GetNumberOfNodes( false );
837 SMESH::long_array_var anIds =
838 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
839 return anIds->length();
847 int SMESH_subMeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
851 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
855 bool isNodal = IsNodePrs();
859 if ( theType == SMDSAbs_Node )
861 SMESH::long_array_var anIds = mySubMeshServer->GetNodesId();
862 return getPointers( SMDSAbs_Node, anIds, aMesh, theResList );
867 if ( theType == SMDSAbs_Node )
869 SMESH::long_array_var anIds = mySubMeshServer->GetElementsId();
870 return getNodesFromElems( anIds, aMesh, theResList );
874 SMESH::long_array_var anIds =
875 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
876 return getPointers( theType, anIds, aMesh, theResList );
883 //=================================================================================
884 // function : IsNodePrs
885 // purpose : Return true if node presentation is used
886 //=================================================================================
887 bool SMESH_subMeshObj::IsNodePrs() const
889 return mySubMeshServer->GetNumberOfElements() == 0;