1 // Copyright (C) 2007-2022 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 <SMESHDS_Mesh.hxx>
26 #include <SMESH_Actor.h>
28 SMESHGUI_PreVisualObj::SMESHGUI_PreVisualObj()
30 myMesh = new SMESHDS_Mesh(0,true);
33 SMDS_Mesh* SMESHGUI_PreVisualObj::GetMesh() const
38 bool SMESHGUI_PreVisualObj::Update( int /*theIsClear*/)
43 void SMESHGUI_PreVisualObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
45 if ( theFunctor ) theFunctor->SetMesh( GetMesh() );
48 int SMESHGUI_PreVisualObj::GetElemDimension( const smIdType theObjId )
50 if ( const SMDS_MeshElement* anElem = myMesh->FindElement( theObjId ))
52 switch ( anElem->GetType() )
54 case SMDSAbs_Edge : return 1;
55 case SMDSAbs_Face : return 2;
56 case SMDSAbs_Volume: return 3;
57 // case SMDSAbs_0DElement : return 0;
58 // case SMDSAbs_Ball : return 0;
65 smIdType SMESHGUI_PreVisualObj::GetNbEntities( const SMDSAbs_ElementType theType ) const
67 return myMesh->GetMeshInfo().NbElements( theType );
70 SMESH::SMESH_Mesh_ptr SMESHGUI_PreVisualObj::GetMeshServer()
72 return SMESH::SMESH_Mesh::_nil();
75 //=================================================================================
76 // function : GetEdgeNodes
77 // purpose : Retrieve ids of nodes from edge of elements ( edge is numbered from 1 )
78 //=================================================================================
80 bool SMESHGUI_PreVisualObj::GetEdgeNodes( const smIdType theElemId,
83 smIdType& theNodeId2 ) const
85 const SMDS_MeshElement* e = myMesh->FindElement( theElemId );
86 if ( !e || e->GetType() != SMDSAbs_Face )
89 int nbNodes = e->NbCornerNodes();
90 if ( theEdgeNum < 0 || theEdgeNum > nbNodes )
93 theNodeId1 = e->GetNode( theEdgeNum-1 )->GetID();
94 theNodeId2 = e->GetNode( theEdgeNum % nbNodes )->GetID();
99 bool SMESHGUI_PreVisualObj::IsValid() const
101 return GetNbEntities( SMDSAbs_All ) > 0;
104 vtkUnstructuredGrid* SMESHGUI_PreVisualObj::GetUnstructuredGrid()
106 return myMesh->GetGrid();
110 vtkIdType SMESHGUI_PreVisualObj::GetNodeObjId( vtkIdType theVTKID )
112 const SMDS_MeshNode* aNode = myMesh->FindNodeVtk( theVTKID );
113 return aNode ? aNode->GetID() : -1;
116 vtkIdType SMESHGUI_PreVisualObj::GetNodeVTKId( vtkIdType theObjID )
118 const SMDS_MeshNode* aNode = myMesh->FindNode( theObjID );
119 return aNode ? aNode->GetID() : -1;
122 vtkIdType SMESHGUI_PreVisualObj::GetElemObjId( vtkIdType theVTKID )
124 return this->GetMesh()->FromVtkToSmds(theVTKID);
127 vtkIdType SMESHGUI_PreVisualObj::GetElemVTKId( vtkIdType theObjID )
129 const SMDS_MeshElement* e = myMesh->FindElement(theObjID);
130 return e ? e->GetVtkID() : -1;
133 void SMESHGUI_PreVisualObj::ClearEntitiesFlags()
135 myEntitiesState = SMESH_Actor::eAllEntity;
136 myEntitiesFlag = false;
139 bool SMESHGUI_PreVisualObj::GetEntitiesFlag()
141 return myEntitiesFlag;
144 unsigned int SMESHGUI_PreVisualObj::GetEntitiesState()
146 return myEntitiesState;