Salome HOME
Merge remote branch 'origin/V8_5_asterstudy'
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_PreVisualObj.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "SMESHGUI_PreVisualObj.h"
24
25 #include <SMDS_Mesh.hxx>
26 #include <SMESH_Actor.h>
27
28 SMESHGUI_PreVisualObj::SMESHGUI_PreVisualObj()
29 {
30   myMesh = new SMDS_Mesh();
31 }
32
33 bool SMESHGUI_PreVisualObj::Update( int theIsClear = true )
34 {
35   return false;
36 }
37
38 void SMESHGUI_PreVisualObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
39 {
40   if ( theFunctor ) theFunctor->SetMesh( GetMesh() );
41 }
42
43 int SMESHGUI_PreVisualObj::GetElemDimension( const int theObjId )
44 {
45   if ( const SMDS_MeshElement* anElem = myMesh->FindElement( theObjId ))
46   {
47     switch ( anElem->GetType() )
48     {
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;
54     default            :     return 0;
55     }
56   }
57   return -1;
58 }
59
60 int SMESHGUI_PreVisualObj::GetNbEntities( const SMDSAbs_ElementType theType ) const
61 {
62   return myMesh->GetMeshInfo().NbElements( theType );
63 }
64
65 SMESH::SMESH_Mesh_ptr SMESHGUI_PreVisualObj::GetMeshServer()
66 {
67   return SMESH::SMESH_Mesh::_nil();
68 }
69
70 //=================================================================================
71 // function : GetEdgeNodes
72 // purpose  : Retrieve ids of nodes from edge of elements ( edge is numbered from 1 )
73 //=================================================================================
74
75 bool SMESHGUI_PreVisualObj::GetEdgeNodes( const int theElemId,
76                                           const int theEdgeNum,
77                                           int&      theNodeId1,
78                                           int&      theNodeId2 ) const
79 {
80   const SMDS_MeshElement* e = myMesh->FindElement( theElemId );
81   if ( !e || e->GetType() != SMDSAbs_Face )
82     return false;
83
84   int nbNodes = e->NbCornerNodes();
85   if ( theEdgeNum < 0 || theEdgeNum > nbNodes )
86     return false;
87
88   theNodeId1 = e->GetNode( theEdgeNum-1 )->GetID();
89   theNodeId2 = e->GetNode( theEdgeNum % nbNodes )->GetID();
90
91   return true;
92 }
93
94 bool SMESHGUI_PreVisualObj::IsValid() const
95 {
96   return GetNbEntities( SMDSAbs_All ) > 0;
97 }
98
99 vtkUnstructuredGrid* SMESHGUI_PreVisualObj::GetUnstructuredGrid()
100 {
101   return myMesh->GetGrid();
102 }
103
104
105 vtkIdType SMESHGUI_PreVisualObj::GetNodeObjId( int theVTKID )
106 {
107   const SMDS_MeshNode* aNode = myMesh->FindNodeVtk( theVTKID );
108   return aNode ? aNode->GetID() : -1;
109 }
110
111 vtkIdType SMESHGUI_PreVisualObj::GetNodeVTKId( int theObjID )
112 {
113   const SMDS_MeshNode* aNode = myMesh->FindNode( theObjID );
114   return aNode ? aNode->GetID() : -1;
115 }
116
117 vtkIdType SMESHGUI_PreVisualObj::GetElemObjId( int theVTKID )
118 {
119   return this->GetMesh()->FromVtkToSmds(theVTKID);
120 }
121
122 vtkIdType SMESHGUI_PreVisualObj::GetElemVTKId( int theObjID )
123 {
124   const SMDS_MeshElement* e = myMesh->FindElement(theObjID);
125   return e ? e->GetVtkID() : -1;
126 }
127
128 void SMESHGUI_PreVisualObj::ClearEntitiesFlags()
129 {
130   myEntitiesState = SMESH_Actor::eAllEntity;
131   myEntitiesFlag = false;
132 }
133
134 bool SMESHGUI_PreVisualObj::GetEntitiesFlag()
135 {
136   return myEntitiesFlag;
137 }
138
139 unsigned int SMESHGUI_PreVisualObj::GetEntitiesState()
140 {
141   return myEntitiesState;
142 }