1 // Copyright (C) 2007-2019 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, or (at your option) any later version.
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
23 // SMESH OBJECT : interactive object for SMESH visualization
24 // File : SMESH_Grid.cxx
25 // Author : Nicolas REJNERI
28 #include "SMESH_ObjectDef.h"
29 #include "SMESH_ActorUtils.h"
31 #include "SMDS_BallElement.hxx"
32 #include "SMDS_Mesh.hxx"
33 #include "SMDS_MeshCell.hxx"
34 #include "SMESHDS_Mesh.hxx"
35 #include "SMESHDS_Script.hxx"
36 #include "SMESH_Actor.h"
37 #include "SMESH_ControlsDef.hxx"
39 #include <SalomeApp_Application.h>
40 #include <VTKViewer_ExtractUnstructuredGrid.h>
41 #include <VTKViewer_CellLocationsArray.h>
43 #include CORBA_SERVER_HEADER(SMESH_Gen)
44 #include CORBA_SERVER_HEADER(SALOME_Exception)
47 #include <vtkIdList.h>
48 #include <vtkCellArray.h>
49 #include <vtkUnsignedCharArray.h>
50 #include <vtkCellData.h>
51 #include <vtkUnstructuredGrid.h>
58 #include <utilities.h>
63 #define EXCEPTION(TYPE, MSG) {\
64 std::ostringstream aStream;\
65 aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\
66 throw TYPE(aStream.str());\
71 static int MYDEBUG = 0;
72 static int MYDEBUGWITHFILES = 0;//1;
74 static int MYDEBUG = 0;
75 static int MYDEBUGWITHFILES = 0;
80 Class : SMESH_VisualObjDef
81 Description : Base class for all mesh objects to be visuilised
83 //=================================================================================
84 // functions : SMESH_VisualObjDef
85 // purpose : Constructor
86 //=================================================================================
87 SMESH_VisualObjDef::SMESH_VisualObjDef()
89 if ( MYDEBUG ) MESSAGE("-------------------------------SMESH_VisualObjDef::SMESH_VisualObjDef");
90 myGrid = vtkUnstructuredGrid::New();
93 SMESH::GetEntitiesFromObject(NULL);
95 SMESH_VisualObjDef::~SMESH_VisualObjDef()
97 if ( MYDEBUG ) MESSAGE("--------------------------------SMESH_VisualObjDef::~SMESH_VisualObjDef");
98 if ( MYDEBUG ) MESSAGE( "myGrid->GetReferenceCount() = " << myGrid->GetReferenceCount() );
102 //=================================================================================
103 // functions : GetNodeObjId, GetNodeVTKId, GetElemObjId, GetElemVTKId
104 // purpose : Methods for retrieving VTK IDs by SMDS IDs and vice versa
105 //=================================================================================
106 vtkIdType SMESH_VisualObjDef::GetNodeObjId( int theVTKID )
110 TMapOfIds::const_iterator i = myVTK2SMDSNodes.find(theVTKID);
111 return i == myVTK2SMDSNodes.end() ? -1 : i->second;
113 const SMDS_MeshNode* aNode = 0;
114 if( this->GetMesh() )
115 aNode = this->GetMesh()->FindNodeVtk( theVTKID );
117 return aNode ? aNode->GetID() : -1;
120 vtkIdType SMESH_VisualObjDef::GetNodeVTKId( int theObjID )
124 TMapOfIds::const_iterator i = mySMDS2VTKNodes.find(theObjID);
125 return i == mySMDS2VTKNodes.end() ? -1 : i->second;
128 const SMDS_MeshNode* aNode = 0;
129 if( this->GetMesh() ) {
130 aNode = this->GetMesh()->FindNode(theObjID);
132 return aNode ? aNode->GetVtkID() : -1;
135 vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID )
139 TMapOfIds::const_iterator i = myVTK2SMDSElems.find(theVTKID);
140 return i == myVTK2SMDSElems.end() ? -1 : i->second;
142 return this->GetMesh()->FromVtkToSmds(theVTKID);
145 vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID )
149 TMapOfIds::const_iterator i = mySMDS2VTKElems.find(theObjID);
150 return i == mySMDS2VTKElems.end() ? -1 : i->second;
153 const SMDS_MeshElement* e = 0;
154 if ( this->GetMesh() )
155 e = this->GetMesh()->FindElement(theObjID);
157 return e ? e->GetVtkID() : -1;
160 //=================================================================================
161 // function : SMESH_VisualObjDef::createPoints
162 // purpose : Create points from nodes
163 //=================================================================================
164 /*! fills a vtkPoints structure for a submesh.
165 * fills a std::list of SMDS_MeshElements*, then extract the points.
166 * fills also conversion id maps between SMDS and VTK.
168 void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints )
170 if ( thePoints == 0 )
174 vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes );
175 thePoints->SetNumberOfPoints( nbNodes );
179 TEntityList::const_iterator anIter;
180 for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter )
182 const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter);
185 thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() );
186 int anId = aNode->GetID();
187 mySMDS2VTKNodes.insert( mySMDS2VTKNodes.end(), std::make_pair( anId, nbPoints ));
188 myVTK2SMDSNodes.insert( myVTK2SMDSNodes.end(), std::make_pair( nbPoints, anId ));
193 if ( nbPoints != nbNodes )
194 thePoints->SetNumberOfPoints( nbPoints );
197 //=================================================================================
198 // function : buildPrs
199 // purpose : create VTK cells( fill unstructured grid )
200 //=================================================================================
201 void SMESH_VisualObjDef::buildPrs(bool buildGrid)
203 if ( MYDEBUG ) MESSAGE("---------------------------SMESH_VisualObjDef::buildPrs " << buildGrid);
209 mySMDS2VTKNodes.clear();
210 myVTK2SMDSNodes.clear();
211 mySMDS2VTKElems.clear();
212 myVTK2SMDSElems.clear();
221 mySMDS2VTKNodes.clear();
222 myVTK2SMDSNodes.clear();
223 mySMDS2VTKElems.clear();
224 myVTK2SMDSElems.clear();
226 myGrid->SetPoints( 0 );
227 myGrid->SetCells( 0, 0, 0, 0, 0 );
234 if (!GetMesh()->IsCompacted())
236 NulData(); // detach from the SMDS grid to allow immediate memory de-allocation in compactMesh()
237 if ( MYDEBUG ) MESSAGE("*** buildPrs ==> compactMesh!");
238 GetMesh()->CompactMesh();
239 if ( SMESHDS_Mesh* m = dynamic_cast<SMESHDS_Mesh*>( GetMesh() )) // IPAL53915
240 m->GetScript()->SetModified(false); // drop IsModified set in compactMesh()
242 vtkUnstructuredGrid *theGrid = GetMesh()->GetGrid();
243 updateEntitiesFlags();
244 myGrid->ShallowCopy(theGrid);
245 //MESSAGE(myGrid->GetReferenceCount());
246 //MESSAGE( "Update - myGrid->GetNumberOfCells() = "<<myGrid->GetNumberOfCells() );
247 //MESSAGE( "Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints() );
248 if( MYDEBUGWITHFILES ) {
249 SMESH::WriteUnstructuredGrid( myGrid,"myPrs.vtu" );
254 //=================================================================================
255 // function : buildNodePrs
256 // purpose : create VTK cells for nodes
257 //=================================================================================
259 void SMESH_VisualObjDef::buildNodePrs()
261 // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
262 // so check remaining memory size for safety
263 SMDS_Mesh::CheckMemory(); // PAL16631
264 vtkPoints* aPoints = vtkPoints::New();
265 createPoints( aPoints );
266 SMDS_Mesh::CheckMemory();
267 myGrid->SetPoints( aPoints );
270 myGrid->SetCells( 0, 0, 0, 0, 0 );
273 //=================================================================================
274 // function : buildElemPrs
275 // purpose : Create VTK cells for elements
276 //=================================================================================
279 typedef std::vector<const SMDS_MeshElement*> TConnect;
281 int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter,
282 TConnect& theConnect)
285 for(; theNodesIter->more();)
286 theConnect.push_back(theNodesIter->next());
287 return theConnect.size();
291 void SetId(vtkIdList *theIdList,
292 const SMESH_VisualObjDef::TMapOfIds& theSMDS2VTKNodes,
293 const TConnect& theConnect,
297 theIdList->SetId(thePosition,theSMDS2VTKNodes.find(theConnect[theId]->GetID())->second);
303 void SMESH_VisualObjDef::buildElemPrs()
307 vtkPoints* aPoints = vtkPoints::New();
308 createPoints( aPoints );
309 myGrid->SetPoints( aPoints );
313 MESSAGE("Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints());
315 // Calculate cells size
317 const int nbTypes = 5;
318 static SMDSAbs_ElementType aTypes[ nbTypes ] =
319 { SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume, SMDSAbs_Ball, SMDSAbs_0DElement };
322 map<SMDSAbs_ElementType,int> nbEnts;
323 map<SMDSAbs_ElementType,TEntityList> anEnts;
325 vtkIdType aNbCells = 0;
327 for ( int i = 0; i < nbTypes; i++ )
329 nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] );
330 aNbCells += nbEnts[ aTypes [ i ]];
332 // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
333 // so check remaining memory size for safety
334 SMDS_Mesh::CheckMemory(); // PAL16631
336 vtkIdType aCellsSize = 2 * nbEnts[ SMDSAbs_0DElement ] + 3 * nbEnts[ SMDSAbs_Edge ];
337 aCellsSize += 2 * nbEnts[ SMDSAbs_Ball ];
339 for ( int i = 1; i <= 2; i++ ) // iterate through faces and volumes
341 if ( nbEnts[ aTypes[ i ] ] )
343 const TEntityList& aList = anEnts[ aTypes[ i ] ];
344 TEntityList::const_iterator anIter;
345 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter ) {
346 if((*anIter)->GetEntityType() != SMDSEntity_Polyhedra &&
347 (*anIter)->GetEntityType() != SMDSEntity_Quad_Polyhedra) {
348 aCellsSize += (*anIter)->NbNodes() + 1;
350 // Special case for the VTK_POLYHEDRON:
351 // itsinput cellArray is of special format.
352 // [nCellFaces, nFace0Pts, i, j, k, nFace1Pts, i, j, k, ...]
354 if ( const SMDS_MeshVolume* ph = SMDS_Mesh::DownCast<SMDS_MeshVolume>( *anIter )) {
355 int nbFaces = ph->NbFaces();
356 aCellsSize += (1 + ph->NbFaces());
357 for( int i = 1; i <= nbFaces; i++ )
358 aCellsSize += ph->NbFaceNodes(i);
365 MESSAGE( "Update - aNbCells = "<<aNbCells<<"; aCellsSize = "<<aCellsSize );
369 vtkCellArray* aConnectivity = vtkCellArray::New();
370 aConnectivity->Allocate( aCellsSize, 0 );
372 SMDS_Mesh::CheckMemory(); // PAL16631
374 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
375 aCellTypesArray->SetNumberOfComponents( 1 );
376 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
378 SMDS_Mesh::CheckMemory(); // PAL16631
380 vtkIdList *anIdList = vtkIdList::New();
384 aConnect.reserve(VTK_CELL_SIZE);
386 SMDS_Mesh::CheckMemory(); // PAL16631
387 bool hasBalls = nbEnts[ SMDSAbs_Ball ] > 0;
388 vtkDataArray* aScalars = 0;
390 aScalars = vtkDataArray::CreateDataArray(VTK_DOUBLE);
391 aScalars->SetNumberOfComponents(1);
392 aScalars->SetNumberOfTuples(aNbCells);
394 for ( int i = 0; i < nbTypes; i++ ) // iterate through all types of elements
396 if ( nbEnts[ aTypes[ i ] ] > 0 ) {
398 const SMDSAbs_ElementType& aType = aTypes[ i ];
399 const TEntityList& aList = anEnts[ aType ];
400 TEntityList::const_iterator anIter;
401 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
403 const SMDS_MeshElement* anElem = *anIter;
405 vtkIdType aNbNodes = anElem->NbNodes();
406 anIdList->SetNumberOfIds( aNbNodes );
407 const vtkIdType vtkElemType = SMDS_MeshCell::toVtkType( anElem->GetEntityType() );
409 int anId = anElem->GetID();
411 mySMDS2VTKElems.insert( mySMDS2VTKElems.end(), std::make_pair( anId, iElem ));
412 myVTK2SMDSElems.insert( myVTK2SMDSElems.end(), std::make_pair( iElem, anId ));
414 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
416 // Convert connectivities from SMDS to VTK
418 if (aType == SMDSAbs_Volume && anElem->IsPoly() && aNbNodes > 3) { // POLYEDRE
420 if ( const SMDS_MeshVolume* ph = SMDS_Mesh::DownCast<SMDS_MeshVolume>( anElem )) {
421 int nbFaces = ph->NbFaces();
422 anIdList->InsertNextId(nbFaces);
423 for( int i = 1; i <= nbFaces; i++ ) {
424 anIdList->InsertNextId(ph->NbFaceNodes(i));
425 for(int j = 1; j <= ph->NbFaceNodes(i); j++) {
426 if ( const SMDS_MeshNode* n = ph->GetFaceNode( i, j ))
427 anIdList->InsertNextId( mySMDS2VTKNodes[ n->GetID() ]);
433 const std::vector<int>& aConnectivities =
434 SMDS_MeshCell::toVtkOrder( VTKCellType( vtkElemType ));
435 if (aConnectivities.size() > 0) {
437 GetConnect(aNodesIter,aConnect);
438 for (vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++)
439 SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]);
442 for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ){
443 const SMDS_MeshElement* aNode = aNodesIter->next();
444 anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] );
449 vtkIdType aCurId = aConnectivity->InsertNextCell( anIdList );
450 aCellTypesArray->InsertNextValue( vtkElemType );
452 //Store diameters of the balls
455 if (const SMDS_BallElement* ball = SMDS_Mesh::DownCast<SMDS_BallElement>(anElem) )
456 aDiam = ball->GetDiameter();
457 aScalars->SetTuple(aCurId,&aDiam);
463 SMDS_Mesh::CheckMemory(); // PAL16631
466 // Insert cells in grid
468 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
469 aCellLocationsArray->SetNumberOfComponents( 1 );
470 aCellLocationsArray->SetNumberOfTuples( aNbCells );
472 SMDS_Mesh::CheckMemory(); // PAL16631
474 aConnectivity->InitTraversal();
475 vtkIdType const *pts(nullptr);
476 for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
477 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
479 myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
480 myGrid->GetCellData()->SetScalars(aScalars);
482 aCellLocationsArray->Delete();
483 aCellTypesArray->Delete();
484 aConnectivity->Delete();
487 SMDS_Mesh::CheckMemory(); // PAL16631
490 //=================================================================================
491 // function : GetEdgeNodes
492 // purpose : Retrieve ids of nodes from edge of elements ( edge is numbered from 0 )
493 //=================================================================================
494 bool SMESH_VisualObjDef::GetEdgeNodes( const int theElemId,
495 const int theEdgeNum,
497 int& theNodeId2 ) const
499 const SMDS_Mesh* aMesh = GetMesh();
503 const SMDS_MeshElement* anElem = aMesh->FindElement( theElemId );
507 int nbNodes = anElem->NbCornerNodes();
509 if (( theEdgeNum < 0 || theEdgeNum > 3 ) ||
510 ( nbNodes != 3 && nbNodes != 4 ) ||
511 ( theEdgeNum >= nbNodes ))
514 theNodeId1 = anElem->GetNode( theEdgeNum )->GetID();
515 theNodeId2 = anElem->GetNode(( theEdgeNum + 1 ) % nbNodes )->GetID();
520 vtkUnstructuredGrid* SMESH_VisualObjDef::GetUnstructuredGrid()
522 if ( !myLocalGrid && ( !GetMesh()->IsCompacted() || // !IsCompacted() is needed ???
523 GetMesh()->GetGrid()->GetMTime() > myGrid->GetMTime() ))
525 NulData(); // detach from the SMDS grid to allow immediate memory de-allocation in CompactMesh()
526 GetMesh()->CompactMesh();
527 if ( SMESHDS_Mesh* m = dynamic_cast<SMESHDS_Mesh*>( GetMesh() )) // IPAL53915
528 m->GetScript()->SetModified(false); // drop IsModified set in CompactMesh()
529 updateEntitiesFlags();
530 vtkUnstructuredGrid *theGrid = GetMesh()->GetGrid();
531 myGrid->ShallowCopy(theGrid);
537 //=================================================================================
538 // function : IsValid
539 // purpose : Return true if there are some entities
540 //=================================================================================
541 bool SMESH_VisualObjDef::IsValid() const
543 return ( GetNbEntities(SMDSAbs_0DElement) > 0 ||
544 GetNbEntities(SMDSAbs_Ball ) > 0 ||
545 GetNbEntities(SMDSAbs_Edge ) > 0 ||
546 GetNbEntities(SMDSAbs_Face ) > 0 ||
547 GetNbEntities(SMDSAbs_Volume ) > 0 ||
548 GetNbEntities(SMDSAbs_Node ) > 0 );
551 //=================================================================================
552 // function : updateEntitiesFlags
553 // purpose : Update entities flags
554 //=================================================================================
555 void SMESH_VisualObjDef::updateEntitiesFlags()
557 unsigned int tmp = myEntitiesState;
558 ClearEntitiesFlags();
560 map<SMDSAbs_ElementType,int> entities = SMESH::GetEntitiesFromObject(this);
563 if( myEntitiesCache[SMDSAbs_0DElement] != 0 ||
564 myEntitiesCache[SMDSAbs_0DElement] >= entities[SMDSAbs_0DElement] )
565 myEntitiesState &= ~SMESH_Actor::e0DElements;
567 if( myEntitiesCache[SMDSAbs_Ball] != 0 ||
568 myEntitiesCache[SMDSAbs_Ball] >= entities[SMDSAbs_Ball] )
569 myEntitiesState &= ~SMESH_Actor::eBallElem;
571 if( myEntitiesCache[SMDSAbs_Edge] != 0 ||
572 myEntitiesCache[SMDSAbs_Edge] >= entities[SMDSAbs_Edge] )
573 myEntitiesState &= ~SMESH_Actor::eEdges;
575 if( myEntitiesCache[SMDSAbs_Face] != 0 ||
576 myEntitiesCache[SMDSAbs_Face] >= entities[SMDSAbs_Face] )
577 myEntitiesState &= ~SMESH_Actor::eFaces;
579 if( myEntitiesCache[SMDSAbs_Volume] != 0 ||
580 myEntitiesCache[SMDSAbs_Volume] >= entities[SMDSAbs_Volume] )
581 myEntitiesState &= ~SMESH_Actor::eVolumes;
583 if( tmp != myEntitiesState ) {
584 myEntitiesFlag = true;
587 myEntitiesCache = entities;
590 //=================================================================================
591 // function : ClearEntitiesFlags
592 // purpose : Clear the entities flags
593 //=================================================================================
594 void SMESH_VisualObjDef::ClearEntitiesFlags()
596 myEntitiesState = SMESH_Actor::eAllEntity;
597 myEntitiesFlag = false;
600 //=================================================================================
601 // function : GetEntitiesFlag
602 // purpose : Return the entities flag
603 //=================================================================================
604 bool SMESH_VisualObjDef::GetEntitiesFlag()
606 return myEntitiesFlag;
609 //=================================================================================
610 // function : GetEntitiesState
611 // purpose : Return the entities state
612 //=================================================================================
613 unsigned int SMESH_VisualObjDef::GetEntitiesState()
615 return myEntitiesState;
619 Class : SMESH_MeshObj
620 Description : Class for visualisation of mesh
623 //=================================================================================
624 // function : SMESH_MeshObj
625 // purpose : Constructor
626 //=================================================================================
627 SMESH_MeshObj::SMESH_MeshObj(SMESH::SMESH_Mesh_ptr theMesh):
628 myClient(SalomeApp_Application::orb(),theMesh)
632 MESSAGE("SMESH_MeshObj - this = "<<this<<"; theMesh->_is_nil() = "<<theMesh->_is_nil());
635 //=================================================================================
636 // function : ~SMESH_MeshObj
637 // purpose : Destructor
638 //=================================================================================
639 SMESH_MeshObj::~SMESH_MeshObj()
642 MESSAGE("SMESH_MeshObj - this = "<<this<<"\n");
644 myEmptyGrid->Delete();
647 //=================================================================================
649 // purpose : Update mesh and fill grid with new values if necessary
650 //=================================================================================
651 bool SMESH_MeshObj::Update( int theIsClear )
653 // Update SMDS_Mesh on client part
654 if ( MYDEBUG ) MESSAGE("SMESH_MeshObj::Update " << this);
655 if ( myClient.Update(theIsClear) || GetUnstructuredGrid()->GetNumberOfPoints()==0) {
656 if ( MYDEBUG ) MESSAGE("buildPrs");
657 buildPrs(); // Fill unstructured grid
663 bool SMESH_MeshObj::NulData()
665 if ( MYDEBUG ) MESSAGE ("SMESH_MeshObj::NulData() =============================================");
668 myEmptyGrid = SMDS_UnstructuredGrid::New();
669 myEmptyGrid->Initialize();
670 myEmptyGrid->Allocate();
671 vtkPoints* points = vtkPoints::New();
672 points->SetNumberOfPoints(0);
673 myEmptyGrid->SetPoints( points );
675 //myEmptyGrid->BuildLinks();
677 myGrid->ShallowCopy(myEmptyGrid);
680 //=================================================================================
681 // function : GetElemDimension
682 // purpose : Get dimension of element
683 //=================================================================================
684 int SMESH_MeshObj::GetElemDimension( const int theObjId )
686 const SMDS_MeshElement* anElem = myClient->FindElement( theObjId );
690 int aType = anElem->GetType();
693 case SMDSAbs_0DElement : return 0;
694 case SMDSAbs_Ball : return 0;
695 case SMDSAbs_Edge : return 1;
696 case SMDSAbs_Face : return 2;
697 case SMDSAbs_Volume: return 3;
702 //=================================================================================
703 // function : GetEntities
704 // purpose : Get entities of specified type. Return number of entities
705 //=================================================================================
706 int SMESH_MeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
712 return myClient->NbNodes();
715 case SMDSAbs_0DElement:
717 return myClient->Nb0DElements();
721 return myClient->NbBalls();
726 return myClient->NbEdges();
731 return myClient->NbFaces();
736 return myClient->NbVolumes();
745 int SMESH_MeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theObjs ) const
753 SMDS_NodeIteratorPtr anIter = myClient->nodesIterator();
754 while ( anIter->more() ) theObjs.push_back( anIter->next() );
757 case SMDSAbs_0DElement:
759 SMDS_ElemIteratorPtr anIter = myClient->elementsIterator(SMDSAbs_0DElement);
760 while ( anIter->more() ) theObjs.push_back( anIter->next() );
765 SMDS_ElemIteratorPtr anIter = myClient->elementGeomIterator(SMDSGeom_BALL);
766 while ( anIter->more() ) theObjs.push_back( anIter->next() );
771 SMDS_EdgeIteratorPtr anIter = myClient->edgesIterator();
772 while ( anIter->more() ) theObjs.push_back( anIter->next() );
777 SMDS_FaceIteratorPtr anIter = myClient->facesIterator();
778 while ( anIter->more() ) theObjs.push_back( anIter->next() );
783 SMDS_VolumeIteratorPtr anIter = myClient->volumesIterator();
784 while ( anIter->more() ) theObjs.push_back( anIter->next() );
791 return theObjs.size();
794 //=================================================================================
795 // function : UpdateFunctor
796 // purpose : Update functor in accordance with current mesh
797 //=================================================================================
798 void SMESH_MeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
800 theFunctor->SetMesh( GetMesh() );
803 //=================================================================================
804 // function : IsNodePrs
805 // purpose : Return true if node presentation is used
806 //=================================================================================
807 bool SMESH_MeshObj::IsNodePrs() const
809 return myClient->Nb0DElements() + myClient->NbEdges() + myClient->NbFaces() + myClient->NbVolumes() + myClient->NbBalls() == 0 ;
814 Class : SMESH_SubMeshObj
815 Description : Base class for visualisation of submeshes and groups
818 //=================================================================================
819 // function : SMESH_SubMeshObj
820 // purpose : Constructor
821 //=================================================================================
822 SMESH_SubMeshObj::SMESH_SubMeshObj( SMESH_MeshObj* theMeshObj )
824 if ( MYDEBUG ) MESSAGE( "SMESH_SubMeshObj - theMeshObj = " << theMeshObj );
826 myMeshObj = theMeshObj;
829 SMESH_SubMeshObj::~SMESH_SubMeshObj()
833 //=================================================================================
834 // function : GetElemDimension
835 // purpose : Get dimension of element
836 //=================================================================================
837 int SMESH_SubMeshObj::GetElemDimension( const int theObjId )
839 return myMeshObj == 0 ? 0 : myMeshObj->GetElemDimension( theObjId );
842 //=================================================================================
843 // function : UpdateFunctor
844 // purpose : Update functor in accordance with current mesh
845 //=================================================================================
847 void SMESH_SubMeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
849 theFunctor->SetMesh( myMeshObj->GetMesh() );
852 //=================================================================================
854 // purpose : Update mesh object and fill grid with new values
855 //=================================================================================
856 bool SMESH_SubMeshObj::Update( int theIsClear )
858 if ( MYDEBUG ) MESSAGE("SMESH_SubMeshObj::Update " << this)
859 bool changed = myMeshObj->Update( theIsClear );
866 Class : SMESH_GroupObj
867 Description : Class for visualisation of groups
870 //=================================================================================
871 // function : SMESH_GroupObj
872 // purpose : Constructor
873 //=================================================================================
874 SMESH_GroupObj::SMESH_GroupObj( SMESH::SMESH_GroupBase_ptr theGroup,
875 SMESH_MeshObj* theMeshObj )
876 : SMESH_SubMeshObj( theMeshObj ),
877 myGroupServer( SMESH::SMESH_GroupBase::_duplicate(theGroup) )
879 if ( MYDEBUG ) MESSAGE("SMESH_GroupObj - theGroup->_is_nil() = "<<theGroup->_is_nil());
880 myGroupServer->Register();
883 SMESH_GroupObj::~SMESH_GroupObj()
885 if ( MYDEBUG ) MESSAGE("~SMESH_GroupObj");
886 myGroupServer->UnRegister();
889 //=================================================================================
890 // function : IsNodePrs
891 // purpose : Return true if node presentation is used
892 //=================================================================================
893 bool SMESH_GroupObj::IsNodePrs() const
895 return myGroupServer->GetType() == SMESH::NODE;
898 //=================================================================================
899 // function : GetElementType
900 // purpose : Return type of elements of group
901 //=================================================================================
902 SMDSAbs_ElementType SMESH_GroupObj::GetElementType() const
904 return SMDSAbs_ElementType(myGroupServer->GetType());
907 //=================================================================================
908 // function : getNodesFromElems
909 // purpose : Retrieve nodes from elements
910 //=================================================================================
911 static int getNodesFromElems( SMESH::long_array_var& theElemIds,
912 const SMDS_Mesh* theMesh,
913 std::list<const SMDS_MeshElement*>& theResList )
915 set<const SMDS_MeshElement*> aNodeSet;
917 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
919 const SMDS_MeshElement* anElem = theMesh->FindElement( theElemIds[ i ] );
922 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
923 while ( anIter->more() )
925 const SMDS_MeshElement* aNode = anIter->next();
927 aNodeSet.insert( aNode );
932 set<const SMDS_MeshElement*>::const_iterator anIter;
933 for ( anIter = aNodeSet.begin(); anIter != aNodeSet.end(); ++anIter )
934 theResList.push_back( *anIter );
936 return theResList.size();
939 //=================================================================================
940 // function : getPointers
941 // purpose : Get std::list<const SMDS_MeshElement*> from list of IDs
942 //=================================================================================
943 static int getPointers( const SMDSAbs_ElementType theRequestType,
944 SMESH::long_array_var& theElemIds,
945 const SMDS_Mesh* theMesh,
946 std::list<const SMDS_MeshElement*>& theResList )
948 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
950 const SMDS_MeshElement* anElem = theRequestType == SMDSAbs_Node
951 ? theMesh->FindNode( theElemIds[ i ] ) : theMesh->FindElement( theElemIds[ i ] );
954 theResList.push_back( anElem );
957 return theResList.size();
961 //=================================================================================
962 // function : GetEntities
963 // purpose : Get entities of specified type. Return number of entities
964 //=================================================================================
965 int SMESH_GroupObj::GetNbEntities( const SMDSAbs_ElementType theType) const
967 if(SMDSAbs_ElementType(myGroupServer->GetType()) == theType) {
968 return myGroupServer->Size();
970 if ( theType == SMDSAbs_Node ) {
971 return myGroupServer->GetNumberOfNodes();
976 int SMESH_GroupObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
979 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
984 SMDSAbs_ElementType aGrpType = SMDSAbs_ElementType(myGroupServer->GetType());
985 if ( aGrpType != theType && theType != SMDSAbs_Node )
988 SMESH::long_array_var anIds = myGroupServer->GetListOfID();
989 if ( anIds->length() == 0 )
992 if ( aGrpType == theType )
993 return getPointers( theType, anIds, aMesh, theResList );
994 else if ( theType == SMDSAbs_Node )
995 return getNodesFromElems( anIds, aMesh, theResList );
1003 Class : SMESH_subMeshObj
1004 Description : Class for visualisation of submeshes
1007 //=================================================================================
1008 // function : SMESH_subMeshObj
1009 // purpose : Constructor
1010 //=================================================================================
1011 SMESH_subMeshObj::SMESH_subMeshObj( SMESH::SMESH_subMesh_ptr theSubMesh,
1012 SMESH_MeshObj* theMeshObj )
1013 : SMESH_SubMeshObj( theMeshObj ),
1014 mySubMeshServer( SMESH::SMESH_subMesh::_duplicate( theSubMesh ) )
1016 if ( MYDEBUG ) MESSAGE( "SMESH_subMeshObj - theSubMesh->_is_nil() = " << theSubMesh->_is_nil() );
1018 mySubMeshServer->Register();
1021 SMESH_subMeshObj::~SMESH_subMeshObj()
1023 if ( MYDEBUG ) MESSAGE( "~SMESH_subMeshObj" );
1024 mySubMeshServer->UnRegister();
1027 //=================================================================================
1028 // function : GetEntities
1029 // purpose : Get entities of specified type. Return number of entities
1030 //=================================================================================
1031 int SMESH_subMeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
1037 return mySubMeshServer->GetNumberOfNodes( /*all=*/true );
1041 case SMDSAbs_0DElement:
1044 case SMDSAbs_Volume:
1046 SMESH::long_array_var anIds =
1047 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
1048 return anIds->length();
1056 int SMESH_subMeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
1060 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
1064 bool isNodal = IsNodePrs();
1068 if ( theType == SMDSAbs_Node )
1070 SMESH::long_array_var anIds = mySubMeshServer->GetNodesId();
1071 return getPointers( SMDSAbs_Node, anIds, aMesh, theResList );
1076 if ( theType == SMDSAbs_Node )
1078 SMESH::long_array_var anIds = mySubMeshServer->GetElementsId();
1079 return getNodesFromElems( anIds, aMesh, theResList );
1083 SMESH::long_array_var anIds =
1084 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
1085 return getPointers( theType, anIds, aMesh, theResList );
1092 //=================================================================================
1093 // function : IsNodePrs
1094 // purpose : Return true if node presentation is used
1095 //=================================================================================
1096 bool SMESH_subMeshObj::IsNodePrs() const
1098 return mySubMeshServer->GetNumberOfElements() == 0;