Salome HOME
eabede8b3ca0f758161c2fa0c76415608026f52b
[modules/smesh.git] / src / OBJECT / SMESH_ObjectDef.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_OBJECTDEF_H
30 #define SMESH_OBJECTDEF_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
40 #include "SMESH_Controls.hxx"
41 #include "SMESH_Object.h"
42
43 class vtkPoints;
44 class SALOME_ExtractUnstructuredGrid;
45
46 class SMESH_Actor;
47 class SMDS_MeshNode;
48 class SMDS_MeshElement;
49
50 /*
51   Class       : SMESH_VisualObj
52   Description : Base class for all mesh objects to be visuilised
53 */
54 class SMESH_VisualObjDef: public SMESH_VisualObj
55 {
56 protected:
57
58   typedef std::list<const SMDS_MeshElement*>   TEntityList;
59   typedef std::map<vtkIdType,vtkIdType>  TMapOfIds;
60   
61 public:
62                             SMESH_VisualObjDef();
63   virtual                   ~SMESH_VisualObjDef();
64   
65   virtual void              Update( int theIsClear = true ) = 0;
66   virtual void              UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor ) = 0;
67   virtual int               GetElemDimension( const int theObjId ) = 0;
68
69   virtual int               GetNbEntities( const SMDSAbs_ElementType theType) const = 0;
70   virtual int               GetEntities( const SMDSAbs_ElementType, TEntityList& ) const = 0;
71   virtual bool              IsNodePrs() const = 0;
72   virtual SMDS_Mesh*        GetMesh() const = 0;
73
74   virtual bool              GetEdgeNodes( const int theElemId,
75                                           const int theEdgeNum,
76                                           int&      theNodeId1,
77                                           int&      theNodeId2 ) const;
78
79   virtual vtkUnstructuredGrid* GetUnstructuredGrid() { return myGrid; }
80   
81   virtual vtkIdType         GetNodeObjId( int theVTKID );
82   virtual vtkIdType         GetNodeVTKId( int theObjID );
83   virtual vtkIdType         GetElemObjId( int theVTKID );
84   virtual vtkIdType         GetElemVTKId( int theObjID );
85   
86 protected:
87
88   void                      createPoints( vtkPoints* );
89   void                      buildPrs();
90   void                      buildNodePrs();
91   void                      buildElemPrs();
92   
93 private:                                   
94
95   TMapOfIds                 mySMDS2VTKNodes;
96   TMapOfIds                 myVTK2SMDSNodes;
97   TMapOfIds                 mySMDS2VTKElems;
98   TMapOfIds                 myVTK2SMDSElems;
99
100   vtkUnstructuredGrid*      myGrid;
101 };
102
103
104 /*
105   Class       : SMESH_MeshObj
106   Description : Class for visualisation of mesh
107 */
108
109 class SMESH_MeshObj: public SMESH_VisualObjDef
110 {
111 public:
112
113                             SMESH_MeshObj( SMESH::SMESH_Mesh_ptr );
114   virtual                   ~SMESH_MeshObj();
115   
116   virtual void              Update( int theIsClear = true );
117   
118   virtual int               GetNbEntities( const SMDSAbs_ElementType) const;
119   virtual int               GetEntities( const SMDSAbs_ElementType, TEntityList& ) const;
120   virtual bool              IsNodePrs() const;
121
122   virtual int               GetElemDimension( const int theObjId );
123
124   virtual void              UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor );
125   
126   SMESH::SMESH_Mesh_ptr     GetMeshServer() { return myMeshServer.in(); }
127   SMDS_Mesh*                GetMesh() const { return myMesh; }
128
129 protected:
130
131   SMESH::SMESH_Mesh_var     myMeshServer;
132   SMDS_Mesh*                myMesh;
133 };
134
135
136 /*
137   Class       : SMESH_SubMeshObj
138   Description : Base class for visualisation of submeshes and groups
139 */
140
141 class SMESH_SubMeshObj: public SMESH_VisualObjDef
142 {
143 public:
144
145                             SMESH_SubMeshObj(SMESH_MeshObj* theMeshObj);
146   virtual                   ~SMESH_SubMeshObj();
147
148   virtual void              Update( int theIsClear = true );
149   
150   virtual void              UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor );
151   virtual int               GetElemDimension( const int theObjId );
152   virtual SMDS_Mesh*        GetMesh() const { return myMeshObj->GetMesh(); }
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_GroupBase_ptr, SMESH_MeshObj* );
169   virtual                   ~SMESH_GroupObj();
170
171   virtual int               GetNbEntities( const SMDSAbs_ElementType) const;
172   virtual int               GetEntities( const SMDSAbs_ElementType, TEntityList& ) const;
173   virtual bool              IsNodePrs() const;
174
175 private:
176
177   SMESH::SMESH_GroupBase_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 SMDSAbs_ElementType) const;
195   virtual int               GetEntities( const SMDSAbs_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