Salome HOME
IPAL54585: Extrusion 3D algo fails with "OCC exception. Standard_NoSuchObject: NColle...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_PreVisualObj.cxx
1 // Copyright (C) 2007-2019  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 <SMESHDS_Mesh.hxx>
26 #include <SMESH_Actor.h>
27
28 SMESHGUI_PreVisualObj::SMESHGUI_PreVisualObj()
29 {
30   myMesh = new SMESHDS_Mesh(0,true);
31 }
32
33 SMDS_Mesh* SMESHGUI_PreVisualObj::GetMesh() const
34 {
35   return myMesh;
36 }
37
38 bool SMESHGUI_PreVisualObj::Update( int theIsClear = true )
39 {
40   return false;
41 }
42
43 void SMESHGUI_PreVisualObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
44 {
45   if ( theFunctor ) theFunctor->SetMesh( GetMesh() );
46 }
47
48 int SMESHGUI_PreVisualObj::GetElemDimension( const int theObjId )
49 {
50   if ( const SMDS_MeshElement* anElem = myMesh->FindElement( theObjId ))
51   {
52     switch ( anElem->GetType() )
53     {
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;
59     default            :     return 0;
60     }
61   }
62   return -1;
63 }
64
65 int SMESHGUI_PreVisualObj::GetNbEntities( const SMDSAbs_ElementType theType ) const
66 {
67   return myMesh->GetMeshInfo().NbElements( theType );
68 }
69
70 SMESH::SMESH_Mesh_ptr SMESHGUI_PreVisualObj::GetMeshServer()
71 {
72   return SMESH::SMESH_Mesh::_nil();
73 }
74
75 //=================================================================================
76 // function : GetEdgeNodes
77 // purpose  : Retrieve ids of nodes from edge of elements ( edge is numbered from 1 )
78 //=================================================================================
79
80 bool SMESHGUI_PreVisualObj::GetEdgeNodes( const int theElemId,
81                                           const int theEdgeNum,
82                                           int&      theNodeId1,
83                                           int&      theNodeId2 ) const
84 {
85   const SMDS_MeshElement* e = myMesh->FindElement( theElemId );
86   if ( !e || e->GetType() != SMDSAbs_Face )
87     return false;
88
89   int nbNodes = e->NbCornerNodes();
90   if ( theEdgeNum < 0 || theEdgeNum > nbNodes )
91     return false;
92
93   theNodeId1 = e->GetNode( theEdgeNum-1 )->GetID();
94   theNodeId2 = e->GetNode( theEdgeNum % nbNodes )->GetID();
95
96   return true;
97 }
98
99 bool SMESHGUI_PreVisualObj::IsValid() const
100 {
101   return GetNbEntities( SMDSAbs_All ) > 0;
102 }
103
104 vtkUnstructuredGrid* SMESHGUI_PreVisualObj::GetUnstructuredGrid()
105 {
106   return myMesh->GetGrid();
107 }
108
109
110 vtkIdType SMESHGUI_PreVisualObj::GetNodeObjId( int theVTKID )
111 {
112   const SMDS_MeshNode* aNode = myMesh->FindNodeVtk( theVTKID );
113   return aNode ? aNode->GetID() : -1;
114 }
115
116 vtkIdType SMESHGUI_PreVisualObj::GetNodeVTKId( int theObjID )
117 {
118   const SMDS_MeshNode* aNode = myMesh->FindNode( theObjID );
119   return aNode ? aNode->GetID() : -1;
120 }
121
122 vtkIdType SMESHGUI_PreVisualObj::GetElemObjId( int theVTKID )
123 {
124   return this->GetMesh()->FromVtkToSmds(theVTKID);
125 }
126
127 vtkIdType SMESHGUI_PreVisualObj::GetElemVTKId( int theObjID )
128 {
129   const SMDS_MeshElement* e = myMesh->FindElement(theObjID);
130   return e ? e->GetVtkID() : -1;
131 }
132
133 void SMESHGUI_PreVisualObj::ClearEntitiesFlags()
134 {
135   myEntitiesState = SMESH_Actor::eAllEntity;
136   myEntitiesFlag = false;
137 }
138
139 bool SMESHGUI_PreVisualObj::GetEntitiesFlag()
140 {
141   return myEntitiesFlag;
142 }
143
144 unsigned int SMESHGUI_PreVisualObj::GetEntitiesState()
145 {
146   return myEntitiesState;
147 }