Salome HOME
SALOME PAL V1_4_1
[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 #include CORBA_SERVER_HEADER(SMESH_Filter)
37
38 #include <map>
39 #include <list>
40 #include <boost/shared_ptr.hpp>
41 #include <vtkSystemIncludes.h>
42
43 class vtkUnstructuredGrid;
44 class vtkPoints;
45 class SALOME_ExtractUnstructuredGrid;
46
47 class SMESH_Actor;
48 class SMDS_Mesh;
49 class SMDS_MeshNode;
50 class SMDS_MeshElement;
51
52 class SMESH_VisualObj;
53 typedef boost::shared_ptr<SMESH_VisualObj> TVisualObjPtr;
54
55
56 /*
57   Class       : SMESH_VisualObj
58   Description : Base class for all mesh objects to be visuilised
59 */
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( SMESH::Functor_ptr 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
80   vtkUnstructuredGrid*      GetUnstructuredGrid() { return myGrid; }
81   
82   vtkIdType                 GetNodeObjId( int theVTKID );
83   vtkIdType                 GetNodeVTKId( int theObjID );
84   vtkIdType                 GetElemObjId( int theVTKID );
85   vtkIdType                 GetElemVTKId( int theObjID );
86   
87 protected:
88
89   void                      createPoints( vtkPoints* );
90   void                      buildPrs();
91   void                      buildNodePrs();
92   void                      buildElemPrs();
93   
94 private:
95
96   TMapOfIds                 mySMDS2VTKNodes;
97   TMapOfIds                 myVTK2SMDSNodes;
98   TMapOfIds                 mySMDS2VTKElems;
99   TMapOfIds                 myVTK2SMDSElems;
100
101   vtkUnstructuredGrid*      myGrid;
102 };
103
104
105 /*
106   Class       : SMESH_MeshObj
107   Description : Class for visualisation of mesh
108 */
109
110 class SMESH_MeshObj: public SMESH_VisualObj
111 {
112 public:
113
114                             SMESH_MeshObj( SMESH::SMESH_Mesh_ptr );
115   virtual                   ~SMESH_MeshObj();
116   
117   virtual void              Update( int theIsClear = true );
118   
119   virtual int               GetNbEntities( const SMESH::ElementType) const;
120   virtual int               GetEntities( const SMESH::ElementType, TEntityList& ) const;
121   virtual bool              IsNodePrs() const;
122
123   virtual int               GetElemDimension( const int theObjId );
124
125   virtual void              UpdateFunctor( SMESH::Functor_ptr f );
126   
127   SMESH::SMESH_Mesh_ptr     GetMeshServer() { return myMeshServer.in(); }
128   SMDS_Mesh*                GetMesh()       { return myMesh; }
129
130 protected:
131
132   SMESH::SMESH_Mesh_var     myMeshServer;
133   SMDS_Mesh*                myMesh;
134 };
135
136
137 /*
138   Class       : SMESH_SubMeshObj
139   Description : Base class for visualisation of submeshes and groups
140 */
141
142 class SMESH_SubMeshObj: public SMESH_VisualObj
143 {
144 public:
145
146                             SMESH_SubMeshObj(SMESH_MeshObj* theMeshObj);
147   virtual                   ~SMESH_SubMeshObj();
148
149   virtual void              Update( int theIsClear = true );
150   
151   virtual void              UpdateFunctor( SMESH::Functor_ptr );
152   virtual int               GetElemDimension( const int theObjId );
153   
154 protected:
155
156   SMESH_MeshObj*            myMeshObj;
157 };
158
159
160 /*
161   Class       : SMESH_GroupObj
162   Description : Class for visualisation of groups
163 */
164
165 class SMESH_GroupObj: public SMESH_SubMeshObj
166 {
167 public:
168                             SMESH_GroupObj( SMESH::SMESH_Group_ptr, SMESH_MeshObj* );
169   virtual                   ~SMESH_GroupObj();
170
171   virtual int               GetNbEntities( const SMESH::ElementType) const;
172   virtual int               GetEntities( const SMESH::ElementType, TEntityList& ) const;
173   virtual bool              IsNodePrs() const;
174
175 private:
176
177   SMESH::SMESH_Group_var    myGroupServer;
178 };
179
180
181 /*
182   Class       : SMESH_subMeshObj
183   Description : Class for visualisation of submeshes
184 */
185
186 class SMESH_subMeshObj : public SMESH_SubMeshObj
187 {
188 public:
189
190                             SMESH_subMeshObj( SMESH::SMESH_subMesh_ptr, 
191                                               SMESH_MeshObj* );
192   virtual                   ~SMESH_subMeshObj();
193
194   virtual int               GetNbEntities( const SMESH::ElementType) const;
195   virtual int               GetEntities( const SMESH::ElementType, TEntityList& ) const;
196   virtual bool              IsNodePrs() const;    
197   
198 protected:
199
200   SMESH::SMESH_subMesh_var  mySubMeshServer;
201 };
202
203
204 extern void WriteUnstructuredGrid(vtkUnstructuredGrid* theGrid, const char* theFileName);
205
206
207 #endif