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 "SMDS_PolyhedralVolumeOfNodes.hxx"
33 #include "SMESH_Actor.h"
34 #include "SMESH_ControlsDef.hxx"
35 #include "SalomeApp_Application.h"
36 #include "VTKViewer_ExtractUnstructuredGrid.h"
37 #include "VTKViewer_CellLocationsArray.h"
39 #include CORBA_SERVER_HEADER(SMESH_Gen)
40 #include CORBA_SERVER_HEADER(SALOME_Exception)
43 #include <vtkIdList.h>
44 #include <vtkCellArray.h>
45 #include <vtkUnsignedCharArray.h>
47 #include <vtkUnstructuredGrid.h>
54 #include "utilities.h"
59 #define EXCEPTION(TYPE, MSG) {\
60 std::ostringstream aStream;\
61 aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\
62 throw TYPE(aStream.str());\
67 static int MYDEBUG = 0;
68 static int MYDEBUGWITHFILES = 0;
70 static int MYDEBUG = 0;
71 static int MYDEBUGWITHFILES = 0;
76 Class : SMESH_VisualObjDef
77 Description : Base class for all mesh objects to be visuilised
80 //=================================================================================
81 // function : getCellType
82 // purpose : Get type of VTK cell
83 //=================================================================================
84 static inline vtkIdType getCellType( const SMDSAbs_ElementType theType,
86 const int theNbNodes )
91 if( theNbNodes == 2 ) return VTK_LINE;
92 else if ( theNbNodes == 3 ) return VTK_QUADRATIC_EDGE;
93 else return VTK_EMPTY_CELL;
96 if (thePoly && theNbNodes>2 ) return VTK_POLYGON;
97 else if ( theNbNodes == 3 ) return VTK_TRIANGLE;
98 else if ( theNbNodes == 4 ) return VTK_QUAD;
99 else if ( theNbNodes == 6 ) return VTK_QUADRATIC_TRIANGLE;
100 else if ( theNbNodes == 8 ) return VTK_QUADRATIC_QUAD;
101 else return VTK_EMPTY_CELL;
104 if (thePoly && theNbNodes>3 ) return VTK_CONVEX_POINT_SET;
105 else if ( theNbNodes == 4 ) return VTK_TETRA;
106 else if ( theNbNodes == 5 ) return VTK_PYRAMID;
107 else if ( theNbNodes == 6 ) return VTK_WEDGE;
108 else if ( theNbNodes == 8 ) return VTK_HEXAHEDRON;
109 else if ( theNbNodes == 10 ) {
110 return VTK_QUADRATIC_TETRA;
112 else if ( theNbNodes == 20 ) {
113 return VTK_QUADRATIC_HEXAHEDRON;
115 else if ( theNbNodes==13 || theNbNodes==15 ) {
116 return VTK_CONVEX_POINT_SET;
118 else return VTK_EMPTY_CELL;
120 default: return VTK_EMPTY_CELL;
124 //=================================================================================
125 // functions : SMESH_VisualObjDef
126 // purpose : Constructor
127 //=================================================================================
128 SMESH_VisualObjDef::SMESH_VisualObjDef()
130 myGrid = vtkUnstructuredGrid::New();
132 SMESH_VisualObjDef::~SMESH_VisualObjDef()
135 MESSAGE( "~SMESH_MeshObj - myGrid->GetReferenceCount() = " << myGrid->GetReferenceCount() );
139 //=================================================================================
140 // functions : GetNodeObjId, GetNodeVTKId, GetElemObjId, GetElemVTKId
141 // purpose : Methods for retrieving VTK IDs by SMDS IDs and vice versa
142 //=================================================================================
143 vtkIdType SMESH_VisualObjDef::GetNodeObjId( int theVTKID )
145 return myVTK2SMDSNodes.find(theVTKID) == myVTK2SMDSNodes.end() ? -1 : myVTK2SMDSNodes[theVTKID];
148 vtkIdType SMESH_VisualObjDef::GetNodeVTKId( int theObjID )
150 return mySMDS2VTKNodes.find(theObjID) == mySMDS2VTKNodes.end() ? -1 : mySMDS2VTKNodes[theObjID];
153 vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID )
155 return myVTK2SMDSElems.find(theVTKID) == myVTK2SMDSElems.end() ? -1 : myVTK2SMDSElems[theVTKID];
158 vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID )
160 return mySMDS2VTKElems.find(theObjID) == mySMDS2VTKElems.end() ? -1 : mySMDS2VTKElems[theObjID];
163 //=================================================================================
164 // function : SMESH_VisualObjDef::createPoints
165 // purpose : Create points from nodes
166 //=================================================================================
167 void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints )
169 if ( thePoints == 0 )
173 vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes );
174 thePoints->SetNumberOfPoints( nbNodes );
178 TEntityList::const_iterator anIter;
179 for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter )
181 const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter);
184 thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() );
185 int anId = aNode->GetID();
186 mySMDS2VTKNodes.insert( TMapOfIds::value_type( anId, nbPoints ) );
187 myVTK2SMDSNodes.insert( TMapOfIds::value_type( nbPoints, anId ) );
192 if ( nbPoints != nbNodes )
193 thePoints->SetNumberOfPoints( nbPoints );
196 //=================================================================================
197 // function : buildPrs
198 // purpose : create VTK cells( fill unstructured grid )
199 //=================================================================================
200 void SMESH_VisualObjDef::buildPrs()
204 mySMDS2VTKNodes.clear();
205 myVTK2SMDSNodes.clear();
206 mySMDS2VTKElems.clear();
207 myVTK2SMDSElems.clear();
214 catch( const std::exception& exc )
216 INFOS("Follow exception was cought:\n\t"<<exc.what());
220 INFOS("Unknown exception was cought !!!");
223 if( MYDEBUG ) MESSAGE( "Update - myGrid->GetNumberOfCells() = "<<myGrid->GetNumberOfCells() );
224 if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"/tmp/buildPrs" );
227 //=================================================================================
228 // function : buildNodePrs
229 // purpose : create VTK cells for nodes
230 //=================================================================================
231 void SMESH_VisualObjDef::buildNodePrs()
233 vtkPoints* aPoints = vtkPoints::New();
234 createPoints( aPoints );
235 myGrid->SetPoints( aPoints );
238 myGrid->SetCells( 0, 0, 0 );
241 //=================================================================================
242 // function : buildElemPrs
243 // purpose : Create VTK cells for elements
244 //=================================================================================
247 typedef std::vector<const SMDS_MeshElement*> TConnect;
249 int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter,
250 TConnect& theConnect)
253 for(; theNodesIter->more();)
254 theConnect.push_back(theNodesIter->next());
255 return theConnect.size();
259 void SetId(vtkIdList *theIdList,
260 const SMESH_VisualObjDef::TMapOfIds& theSMDS2VTKNodes,
261 const TConnect& theConnect,
265 theIdList->SetId(thePosition,theSMDS2VTKNodes.find(theConnect[theId]->GetID())->second);
271 void SMESH_VisualObjDef::buildElemPrs()
275 vtkPoints* aPoints = vtkPoints::New();
276 createPoints( aPoints );
277 myGrid->SetPoints( aPoints );
281 MESSAGE("Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints());
283 // Calculate cells size
285 static SMDSAbs_ElementType aTypes[ 3 ] = { SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume };
288 map<SMDSAbs_ElementType,int> nbEnts;
289 map<SMDSAbs_ElementType,TEntityList> anEnts;
291 for ( int i = 0; i <= 2; i++ )
292 nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] );
294 vtkIdType aCellsSize = 3 * nbEnts[ SMDSAbs_Edge ];
296 for ( int i = 1; i <= 2; i++ ) // iterate through faces and volumes
298 if ( nbEnts[ aTypes[ i ] ] )
300 const TEntityList& aList = anEnts[ aTypes[ i ] ];
301 TEntityList::const_iterator anIter;
302 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
303 aCellsSize += (*anIter)->NbNodes() + 1;
307 vtkIdType aNbCells = nbEnts[ SMDSAbs_Edge ] + nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ];
310 MESSAGE( "Update - aNbCells = "<<aNbCells<<"; aCellsSize = "<<aCellsSize );
314 vtkCellArray* aConnectivity = vtkCellArray::New();
315 aConnectivity->Allocate( aCellsSize, 0 );
317 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
318 aCellTypesArray->SetNumberOfComponents( 1 );
319 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
321 vtkIdList *anIdList = vtkIdList::New();
325 aConnect.reserve(VTK_CELL_SIZE);
327 for ( int i = 0; i <= 2; i++ ) // iterate through edges, faces and volumes
329 if( nbEnts[ aTypes[ i ] ] > 0 )
331 const SMDSAbs_ElementType& aType = aTypes[ i ];
332 const TEntityList& aList = anEnts[ aType ];
333 TEntityList::const_iterator anIter;
334 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
336 const SMDS_MeshElement* anElem = *anIter;
338 vtkIdType aNbNodes = anElem->NbNodes();
339 anIdList->SetNumberOfIds( aNbNodes );
341 int anId = anElem->GetID();
343 mySMDS2VTKElems.insert( TMapOfIds::value_type( anId, iElem ) );
344 myVTK2SMDSElems.insert( TMapOfIds::value_type( iElem, anId ) );
346 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
348 case SMDSAbs_Volume:{
350 std::vector<int> aConnectivities;
351 // Convertions connectivities from SMDS to VTK
352 if (anElem->IsPoly() && aNbNodes > 3) { // POLYEDRE
354 if ( const SMDS_PolyhedralVolumeOfNodes* ph =
355 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem))
357 aNbNodes = GetConnect(ph->uniqueNodesIterator(),aConnect);
358 anIdList->SetNumberOfIds( aNbNodes );
360 for (int k = 0; k < aNbNodes; k++)
361 aConnectivities.push_back(k);
363 } else if (aNbNodes == 4) {
364 static int anIds[] = {0,2,1,3};
365 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
367 } else if (aNbNodes == 5) {
368 static int anIds[] = {0,3,2,1,4};
369 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
371 } else if (aNbNodes == 6) {
372 static int anIds[] = {0,1,2,3,4,5};
373 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
376 else if (aNbNodes == 8) {
377 static int anIds[] = {0,3,2,1,4,7,6,5};
378 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
381 else if (aNbNodes == 10) {
382 static int anIds[] = {0,2,1,3,6,5,4,7,9,8};
383 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
385 else if (aNbNodes == 13) {
386 static int anIds[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
387 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
389 else if (aNbNodes == 15) {
390 static int anIds[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
391 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
392 //for (int k = 0; k < aNbNodes; k++) {
393 // int nn = aConnectivities[k];
394 // const SMDS_MeshNode* N = static_cast<const SMDS_MeshNode*> (aConnect[nn]);
395 // cout<<"k="<<k<<" N("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
398 else if (aNbNodes == 20) {
399 static int anIds[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
400 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
405 if ( aConnect.empty() )
406 GetConnect(aNodesIter,aConnect);
408 if (aConnectivities.size() > 0) {
409 for (vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++)
410 SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]);
415 for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ){
416 const SMDS_MeshElement* aNode = aNodesIter->next();
417 anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] );
421 aConnectivity->InsertNextCell( anIdList );
422 aCellTypesArray->InsertNextValue( getCellType( aType, anElem->IsPoly(), aNbNodes ) );
429 // Insert cells in grid
431 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
432 aCellLocationsArray->SetNumberOfComponents( 1 );
433 aCellLocationsArray->SetNumberOfTuples( aNbCells );
435 aConnectivity->InitTraversal();
436 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
437 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
439 myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
441 aCellLocationsArray->Delete();
442 aCellTypesArray->Delete();
443 aConnectivity->Delete();
447 //=================================================================================
448 // function : GetEdgeNodes
449 // purpose : Retrieve ids of nodes from edge of elements ( edge is numbered from 1 )
450 //=================================================================================
451 bool SMESH_VisualObjDef::GetEdgeNodes( const int theElemId,
452 const int theEdgeNum,
454 int& theNodeId2 ) const
456 const SMDS_Mesh* aMesh = GetMesh();
460 const SMDS_MeshElement* anElem = aMesh->FindElement( theElemId );
464 int nbNodes = anElem->NbNodes();
466 if ( theEdgeNum < 0 || theEdgeNum > 3 || nbNodes != 3 && nbNodes != 4 || theEdgeNum > nbNodes )
469 int anIds[ nbNodes ];
470 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
472 while( anIter->more() )
473 anIds[ i++ ] = anIter->next()->GetID();
475 if ( theEdgeNum < nbNodes - 1 )
477 theNodeId1 = anIds[ theEdgeNum ];
478 theNodeId2 = anIds[ theEdgeNum + 1 ];
482 theNodeId1 = anIds[ nbNodes - 1 ];
483 theNodeId2 = anIds[ 0 ];
490 Class : SMESH_MeshObj
491 Description : Class for visualisation of mesh
494 //=================================================================================
495 // function : SMESH_MeshObj
496 // purpose : Constructor
497 //=================================================================================
498 SMESH_MeshObj::SMESH_MeshObj(SMESH::SMESH_Mesh_ptr theMesh):
499 myClient(SalomeApp_Application::orb(),theMesh)
502 MESSAGE("SMESH_MeshObj - this = "<<this<<"; theMesh->_is_nil() = "<<theMesh->_is_nil());
505 //=================================================================================
506 // function : ~SMESH_MeshObj
507 // purpose : Destructor
508 //=================================================================================
509 SMESH_MeshObj::~SMESH_MeshObj()
512 MESSAGE("SMESH_MeshObj - this = "<<this<<"\n");
515 //=================================================================================
517 // purpose : Update mesh and fill grid with new values if necessary
518 //=================================================================================
519 void SMESH_MeshObj::Update( int theIsClear )
521 // Update SMDS_Mesh on client part
522 if ( myClient.Update(theIsClear) )
523 buildPrs(); // Fill unstructured grid
526 //=================================================================================
527 // function : GetElemDimension
528 // purpose : Get dimension of element
529 //=================================================================================
530 int SMESH_MeshObj::GetElemDimension( const int theObjId )
532 const SMDS_MeshElement* anElem = myClient->FindElement( theObjId );
536 int aType = anElem->GetType();
539 case SMDSAbs_Edge : return 1;
540 case SMDSAbs_Face : return 2;
541 case SMDSAbs_Volume: return 3;
546 //=================================================================================
547 // function : GetEntities
548 // purpose : Get entities of specified type. Return number of entities
549 //=================================================================================
550 int SMESH_MeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
556 return myClient->NbNodes();
561 return myClient->NbEdges();
566 return myClient->NbFaces();
571 return myClient->NbVolumes();
580 int SMESH_MeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theObjs ) const
588 SMDS_NodeIteratorPtr anIter = myClient->nodesIterator();
589 while ( anIter->more() ) theObjs.push_back( anIter->next() );
594 SMDS_EdgeIteratorPtr anIter = myClient->edgesIterator();
595 while ( anIter->more() ) theObjs.push_back( anIter->next() );
600 SMDS_FaceIteratorPtr anIter = myClient->facesIterator();
601 while ( anIter->more() ) theObjs.push_back( anIter->next() );
606 SMDS_VolumeIteratorPtr anIter = myClient->volumesIterator();
607 while ( anIter->more() ) theObjs.push_back( anIter->next() );
614 return theObjs.size();
617 //=================================================================================
618 // function : UpdateFunctor
619 // purpose : Update functor in accordance with current mesh
620 //=================================================================================
621 void SMESH_MeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
623 theFunctor->SetMesh( GetMesh() );
626 //=================================================================================
627 // function : IsNodePrs
628 // purpose : Return true if node presentation is used
629 //=================================================================================
630 bool SMESH_MeshObj::IsNodePrs() const
632 return myClient->NbEdges() == 0 &&myClient->NbFaces() == 0 && myClient->NbVolumes() == 0 ;
637 Class : SMESH_SubMeshObj
638 Description : Base class for visualisation of submeshes and groups
641 //=================================================================================
642 // function : SMESH_SubMeshObj
643 // purpose : Constructor
644 //=================================================================================
645 SMESH_SubMeshObj::SMESH_SubMeshObj( SMESH_MeshObj* theMeshObj )
647 if ( MYDEBUG ) MESSAGE( "SMESH_SubMeshObj - theMeshObj = " << theMeshObj );
649 myMeshObj = theMeshObj;
652 SMESH_SubMeshObj::~SMESH_SubMeshObj()
656 //=================================================================================
657 // function : GetElemDimension
658 // purpose : Get dimension of element
659 //=================================================================================
660 int SMESH_SubMeshObj::GetElemDimension( const int theObjId )
662 return myMeshObj == 0 ? 0 : myMeshObj->GetElemDimension( theObjId );
665 //=================================================================================
666 // function : UpdateFunctor
667 // purpose : Update functor in accordance with current mesh
668 //=================================================================================
669 void SMESH_SubMeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
671 theFunctor->SetMesh( myMeshObj->GetMesh() );
674 //=================================================================================
676 // purpose : Update mesh object and fill grid with new values
677 //=================================================================================
678 void SMESH_SubMeshObj::Update( int theIsClear )
680 myMeshObj->Update( theIsClear );
686 Class : SMESH_GroupObj
687 Description : Class for visualisation of groups
690 //=================================================================================
691 // function : SMESH_GroupObj
692 // purpose : Constructor
693 //=================================================================================
694 SMESH_GroupObj::SMESH_GroupObj( SMESH::SMESH_GroupBase_ptr theGroup,
695 SMESH_MeshObj* theMeshObj )
696 : SMESH_SubMeshObj( theMeshObj ),
697 myGroupServer( SMESH::SMESH_GroupBase::_duplicate(theGroup) )
699 if ( MYDEBUG ) MESSAGE("SMESH_GroupObj - theGroup->_is_nil() = "<<theGroup->_is_nil());
700 myGroupServer->Register();
703 SMESH_GroupObj::~SMESH_GroupObj()
705 if ( MYDEBUG ) MESSAGE("~SMESH_GroupObj");
706 myGroupServer->Destroy();
709 //=================================================================================
710 // function : IsNodePrs
711 // purpose : Return true if node presentation is used
712 //=================================================================================
713 bool SMESH_GroupObj::IsNodePrs() const
715 return myGroupServer->GetType() == SMESH::NODE;
718 //=================================================================================
719 // function : getNodesFromElems
720 // purpose : Retrieve nodes from elements
721 //=================================================================================
722 static int getNodesFromElems( SMESH::long_array_var& theElemIds,
723 const SMDS_Mesh* theMesh,
724 std::list<const SMDS_MeshElement*>& theResList )
726 set<const SMDS_MeshElement*> aNodeSet;
728 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
730 const SMDS_MeshElement* anElem = theMesh->FindElement( theElemIds[ i ] );
733 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
734 while ( anIter->more() )
736 const SMDS_MeshElement* aNode = anIter->next();
738 aNodeSet.insert( aNode );
743 set<const SMDS_MeshElement*>::const_iterator anIter;
744 for ( anIter = aNodeSet.begin(); anIter != aNodeSet.end(); ++anIter )
745 theResList.push_back( *anIter );
747 return theResList.size();
750 //=================================================================================
751 // function : getPointers
752 // purpose : Get std::list<const SMDS_MeshElement*> from list of IDs
753 //=================================================================================
754 static int getPointers( const SMDSAbs_ElementType theRequestType,
755 SMESH::long_array_var& theElemIds,
756 const SMDS_Mesh* theMesh,
757 std::list<const SMDS_MeshElement*>& theResList )
759 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
761 const SMDS_MeshElement* anElem = theRequestType == SMDSAbs_Node
762 ? theMesh->FindNode( theElemIds[ i ] ) : theMesh->FindElement( theElemIds[ i ] );
765 theResList.push_back( anElem );
768 return theResList.size();
772 //=================================================================================
773 // function : GetEntities
774 // purpose : Get entities of specified type. Return number of entities
775 //=================================================================================
776 int SMESH_GroupObj::GetNbEntities( const SMDSAbs_ElementType theType) const
778 if(SMDSAbs_ElementType(myGroupServer->GetType()) == theType){
779 return myGroupServer->Size();
784 int SMESH_GroupObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
787 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
789 if ( myGroupServer->Size() == 0 || aMesh == 0 )
792 SMDSAbs_ElementType aGrpType = SMDSAbs_ElementType(myGroupServer->GetType());
793 SMESH::long_array_var anIds = myGroupServer->GetListOfID();
795 if ( aGrpType == theType )
796 return getPointers( theType, anIds, aMesh, theResList );
797 else if ( theType == SMDSAbs_Node )
798 return getNodesFromElems( anIds, aMesh, theResList );
806 Class : SMESH_subMeshObj
807 Description : Class for visualisation of submeshes
810 //=================================================================================
811 // function : SMESH_subMeshObj
812 // purpose : Constructor
813 //=================================================================================
814 SMESH_subMeshObj::SMESH_subMeshObj( SMESH::SMESH_subMesh_ptr theSubMesh,
815 SMESH_MeshObj* theMeshObj )
816 : SMESH_SubMeshObj( theMeshObj ),
817 mySubMeshServer( SMESH::SMESH_subMesh::_duplicate( theSubMesh ) )
819 if ( MYDEBUG ) MESSAGE( "SMESH_subMeshObj - theSubMesh->_is_nil() = " << theSubMesh->_is_nil() );
821 mySubMeshServer->Register();
824 SMESH_subMeshObj::~SMESH_subMeshObj()
826 if ( MYDEBUG ) MESSAGE( "~SMESH_subMeshObj" );
827 mySubMeshServer->Destroy();
830 //=================================================================================
831 // function : GetEntities
832 // purpose : Get entities of specified type. Return number of entities
833 //=================================================================================
834 int SMESH_subMeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
840 return mySubMeshServer->GetNumberOfNodes( false );
847 SMESH::long_array_var anIds =
848 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
849 return anIds->length();
857 int SMESH_subMeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
861 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
865 bool isNodal = IsNodePrs();
869 if ( theType == SMDSAbs_Node )
871 SMESH::long_array_var anIds = mySubMeshServer->GetNodesId();
872 return getPointers( SMDSAbs_Node, anIds, aMesh, theResList );
877 if ( theType == SMDSAbs_Node )
879 SMESH::long_array_var anIds = mySubMeshServer->GetElementsId();
880 return getNodesFromElems( anIds, aMesh, theResList );
884 SMESH::long_array_var anIds =
885 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
886 return getPointers( theType, anIds, aMesh, theResList );
893 //=================================================================================
894 // function : IsNodePrs
895 // purpose : Return true if node presentation is used
896 //=================================================================================
897 bool SMESH_subMeshObj::IsNodePrs() const
899 return mySubMeshServer->GetNumberOfElements() == 0;