1 // Copyright (C) 2007-2016 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 #include "SMESHGUI_PreVisualObj.h"
25 #include <SMDS_Mesh.hxx>
26 #include <SMESH_Actor.h>
28 SMESHGUI_PreVisualObj::SMESHGUI_PreVisualObj()
30 myMesh = new SMDS_Mesh();
33 bool SMESHGUI_PreVisualObj::Update( int theIsClear = true )
38 void SMESHGUI_PreVisualObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
40 if ( theFunctor ) theFunctor->SetMesh( GetMesh() );
43 int SMESHGUI_PreVisualObj::GetElemDimension( const int theObjId )
45 if ( const SMDS_MeshElement* anElem = myMesh->FindElement( theObjId ))
47 switch ( anElem->GetType() )
49 case SMDSAbs_Edge : return 1;
50 case SMDSAbs_Face : return 2;
51 case SMDSAbs_Volume: return 3;
52 // case SMDSAbs_0DElement : return 0;
53 // case SMDSAbs_Ball : return 0;
60 int SMESHGUI_PreVisualObj::GetNbEntities( const SMDSAbs_ElementType theType ) const
62 return myMesh->GetMeshInfo().NbElements( theType );
65 SMESH::SMESH_Mesh_ptr SMESHGUI_PreVisualObj::GetMeshServer()
67 return SMESH::SMESH_Mesh::_nil();
70 //=================================================================================
71 // function : GetEdgeNodes
72 // purpose : Retrieve ids of nodes from edge of elements ( edge is numbered from 1 )
73 //=================================================================================
75 bool SMESHGUI_PreVisualObj::GetEdgeNodes( const int theElemId,
78 int& theNodeId2 ) const
80 const SMDS_MeshElement* e = myMesh->FindElement( theElemId );
81 if ( !e || e->GetType() != SMDSAbs_Face )
84 int nbNodes = e->NbCornerNodes();
85 if ( theEdgeNum < 0 || theEdgeNum > nbNodes )
88 theNodeId1 = e->GetNode( theEdgeNum-1 )->GetID();
89 theNodeId2 = e->GetNode( theEdgeNum % nbNodes )->GetID();
94 bool SMESHGUI_PreVisualObj::IsValid() const
96 return GetNbEntities( SMDSAbs_All ) > 0;
99 vtkUnstructuredGrid* SMESHGUI_PreVisualObj::GetUnstructuredGrid()
101 return myMesh->getGrid();
105 vtkIdType SMESHGUI_PreVisualObj::GetNodeObjId( int theVTKID )
107 const SMDS_MeshNode* aNode = myMesh->FindNodeVtk( theVTKID );
108 return aNode ? aNode->GetID() : -1;
111 vtkIdType SMESHGUI_PreVisualObj::GetNodeVTKId( int theObjID )
113 const SMDS_MeshNode* aNode = myMesh->FindNode( theObjID );
114 return aNode ? aNode->GetID() : -1;
117 vtkIdType SMESHGUI_PreVisualObj::GetElemObjId( int theVTKID )
119 return this->GetMesh()->fromVtkToSmds(theVTKID);
122 vtkIdType SMESHGUI_PreVisualObj::GetElemVTKId( int theObjID )
124 const SMDS_MeshElement* e = myMesh->FindElement(theObjID);
125 return e ? e->getVtkId() : -1;
128 void SMESHGUI_PreVisualObj::ClearEntitiesFlags()
130 myEntitiesState = SMESH_Actor::eAllEntity;
131 myEntitiesFlag = false;
134 bool SMESHGUI_PreVisualObj::GetEntitiesFlag()
136 return myEntitiesFlag;
139 unsigned int SMESHGUI_PreVisualObj::GetEntitiesState()
141 return myEntitiesState;