Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/smesh.git] / src / OBJECT / SMESH_Object.h
1 //  SMESH OBJECT : interactive object for SMESH visualization
2 //
3 //  Copyright (C) 2003  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. 
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_Object.h
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 #ifndef SMESH_OBJECT_H
30 #define SMESH_OBJECT_H
31
32 // IDL Headers
33 #include "SALOMEconfig.h"
34 #include CORBA_SERVER_HEADER(SMESH_Mesh)
35 #include CORBA_SERVER_HEADER(SMESH_Group)
36
37 #include <map>
38 #include <list>
39 #include <boost/shared_ptr.hpp>
40 #include <vtkSystemIncludes.h>
41
42 #include "SMESH_Controls.hxx"
43
44 class vtkUnstructuredGrid;
45 class vtkPoints;
46 class SALOME_ExtractUnstructuredGrid;
47
48 class SMESH_Actor;
49 class SMDS_Mesh;
50 class SMDS_MeshNode;
51 class SMDS_MeshElement;
52
53 class SMESH_VisualObj;
54 typedef boost::shared_ptr<SMESH_VisualObj> TVisualObjPtr;
55
56
57 /*
58   Class       : SMESH_VisualObj
59   Description : Base class for all mesh objects to be visuilised
60 */
61 class SMESH_VisualObj
62 {
63 protected:
64
65   typedef std::list<const SMDS_MeshElement*>   TEntityList;
66   typedef std::map<vtkIdType,vtkIdType>  TMapOfIds;
67   
68 public:
69                             SMESH_VisualObj();
70   virtual                   ~SMESH_VisualObj();
71   
72   virtual void              Update( int theIsClear = true ) = 0;
73   virtual void              UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor ) = 0;
74   virtual int               GetElemDimension( const int theObjId ) = 0;
75
76   virtual int               GetNbEntities( const SMESH::ElementType) const = 0;
77   virtual int               GetEntities( const SMESH::ElementType, TEntityList& ) const = 0;
78   virtual bool              IsNodePrs() const = 0;
79   virtual SMDS_Mesh*        GetMesh() const = 0;
80
81   bool                      GetEdgeNodes( const int theElemId,
82                                           const int theEdgeNum,
83                                           int&      theNodeId1,
84                                           int&      theNodeId2 ) const;
85
86   vtkUnstructuredGrid*      GetUnstructuredGrid() { return myGrid; }
87   
88   vtkIdType                 GetNodeObjId( int theVTKID );
89   vtkIdType                 GetNodeVTKId( int theObjID );
90   vtkIdType                 GetElemObjId( int theVTKID );
91   vtkIdType                 GetElemVTKId( int theObjID );
92   
93 protected:
94
95   void                      createPoints( vtkPoints* );
96   void                      buildPrs();
97   void                      buildNodePrs();
98   void                      buildElemPrs();
99   
100 private:                                   
101
102   TMapOfIds                 mySMDS2VTKNodes;
103   TMapOfIds                 myVTK2SMDSNodes;
104   TMapOfIds                 mySMDS2VTKElems;
105   TMapOfIds                 myVTK2SMDSElems;
106
107   vtkUnstructuredGrid*      myGrid;
108 };
109
110
111 /*
112   Class       : SMESH_MeshObj
113   Description : Class for visualisation of mesh
114 */
115
116 class SMESH_MeshObj: public SMESH_VisualObj
117 {
118 public:
119
120                             SMESH_MeshObj( SMESH::SMESH_Mesh_ptr );
121   virtual                   ~SMESH_MeshObj();
122   
123   virtual void              Update( int theIsClear = true );
124   
125   virtual int               GetNbEntities( const SMESH::ElementType) const;
126   virtual int               GetEntities( const SMESH::ElementType, TEntityList& ) const;
127   virtual bool              IsNodePrs() const;
128
129   virtual int               GetElemDimension( const int theObjId );
130
131   virtual void              UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor );
132   
133   SMESH::SMESH_Mesh_ptr     GetMeshServer() { return myMeshServer.in(); }
134   SMDS_Mesh*                GetMesh() const { return myMesh; }
135
136 protected:
137
138   SMESH::SMESH_Mesh_var     myMeshServer;
139   SMDS_Mesh*                myMesh;
140 };
141
142
143 /*
144   Class       : SMESH_SubMeshObj
145   Description : Base class for visualisation of submeshes and groups
146 */
147
148 class SMESH_SubMeshObj: public SMESH_VisualObj
149 {
150 public:
151
152                             SMESH_SubMeshObj(SMESH_MeshObj* theMeshObj);
153   virtual                   ~SMESH_SubMeshObj();
154
155   virtual void              Update( int theIsClear = true );
156   
157   virtual void              UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor );
158   virtual int               GetElemDimension( const int theObjId );
159   virtual SMDS_Mesh*        GetMesh() const { return myMeshObj->GetMesh(); }
160   
161 protected:
162
163   SMESH_MeshObj*            myMeshObj;
164 };
165
166
167 /*
168   Class       : SMESH_GroupObj
169   Description : Class for visualisation of groups
170 */
171
172 class SMESH_GroupObj: public SMESH_SubMeshObj
173 {
174 public:
175                             SMESH_GroupObj( SMESH::SMESH_GroupBase_ptr, SMESH_MeshObj* );
176   virtual                   ~SMESH_GroupObj();
177
178   virtual int               GetNbEntities( const SMESH::ElementType) const;
179   virtual int               GetEntities( const SMESH::ElementType, TEntityList& ) const;
180   virtual bool              IsNodePrs() const;
181
182 private:
183
184   SMESH::SMESH_GroupBase_var    myGroupServer;
185 };
186
187
188 /*
189   Class       : SMESH_subMeshObj
190   Description : Class for visualisation of submeshes
191 */
192
193 class SMESH_subMeshObj : public SMESH_SubMeshObj
194 {
195 public:
196
197                             SMESH_subMeshObj( SMESH::SMESH_subMesh_ptr, 
198                                               SMESH_MeshObj* );
199   virtual                   ~SMESH_subMeshObj();
200
201   virtual int               GetNbEntities( const SMESH::ElementType) const;
202   virtual int               GetEntities( const SMESH::ElementType, TEntityList& ) const;
203   virtual bool              IsNodePrs() const;    
204   
205 protected:
206
207   SMESH::SMESH_subMesh_var  mySubMeshServer;
208 };
209
210
211 extern void WriteUnstructuredGrid(vtkUnstructuredGrid* theGrid, const char* theFileName);
212
213
214 #endif