Salome HOME
0021347: [CEA 497] Visualisation into SMESH and VISU of hexagonal prism cells (MED_OC...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshInfo.h
1 // Copyright (C) 2007-2011  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.
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 //  File   : SMESHGUI_MeshInfo.h
23 //  Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
24
25 #ifndef SMESHGUI_MESHINFO_H
26 #define SMESHGUI_MESHINFO_H
27
28 #include "SMESH_SMESHGUI.hxx"
29 #include <SALOME_InteractiveObject.hxx>
30
31 #include <QFrame>
32 #include <QDialog>
33 #include <QList>
34 #include <QMap>
35 #include <QSet>
36 #include <QTreeWidget>
37 #include <QVector>
38
39 #include <SALOMEconfig.h>
40 #include CORBA_SERVER_HEADER(SMESH_Mesh)
41 #include CORBA_SERVER_HEADER(SMESH_Group)
42
43 class QButtonGroup;
44 class QLabel;
45 class QLineEdit;
46 class QPushButton;
47 class QTabWidget;
48 class QTextBrowser;
49 class SMESH_Actor;
50 class SMDS_MeshNode;
51 class SMDS_MeshElement;
52
53 class SMESHGUI_EXPORT SMESHGUI_MeshInfo : public QFrame
54 {
55   Q_OBJECT;
56   
57   enum {
58     iName,
59     iObject,
60     iNodesStart,
61     iNodes,
62     iNodesEnd,
63     iElementsStart = iNodesEnd, 
64     iElements,
65     i0DStart,
66     i0D,
67     i0DEnd,
68     i1DStart       = i0DEnd,
69     i1D,
70     i1DEnd,
71     i2DStart       = i1DEnd,
72     i2D,
73     i2DTriangles,
74     i2DQuadrangles,
75     i2DPolygons,
76     i2DEnd,
77     i3DStart       = i2DEnd,
78     i3D,
79     i3DTetrahedrons,
80     i3DHexahedrons,
81     i3DPyramids,
82     i3DPrisms,
83     i3DHexaPrisms,
84     i3DPolyhedrons,
85     i3DEnd,
86     iElementsEnd   = i3DEnd
87   };
88
89   enum {
90     iSingle = 1,
91     iTotal  = iSingle,
92     iLinear,
93     iQuadratic
94   };
95
96   typedef QList<QWidget*> wlist;
97   typedef QVector<wlist>  iwlist;
98
99 public:
100   SMESHGUI_MeshInfo( QWidget* = 0 );
101   ~SMESHGUI_MeshInfo();
102
103   void     showInfo( SMESH::SMESH_IDSource_ptr );
104   void     clear();
105
106 private:
107   enum { Bold = 0x01, Italic = 0x02 };
108
109   QLabel*  createField();
110   QWidget* createLine();
111   void     setFontAttributes( QWidget*, int, bool = true );
112   void     setFieldsVisible( int, int, bool );
113
114 private:
115   iwlist   myWidgets;
116 };
117
118 class SMESHGUI_EXPORT SMESHGUI_ElemInfo : public QWidget
119 {
120   Q_OBJECT;
121
122 public:
123   SMESHGUI_ElemInfo( QWidget* = 0 );
124   ~SMESHGUI_ElemInfo();
125
126   void         setSource( SMESH_Actor* );
127   void         showInfo( long, bool );
128   void         showInfo( QSet<long>, bool );
129   void         clear();
130
131 protected:
132   struct XYZ
133   {
134     double myX, myY, myZ;
135     XYZ() { myX = myY = myZ = 0.0; }
136     void add( double x, double y, double z ) { myX += x; myY += y; myZ += z; }
137     void divide( double a ) { if ( a != 0.) { myX /= a; myY /= a; myZ /= a; } }
138     double x() const  { return myX; }
139     double y() const  { return myY; }
140     double z() const  { return myZ; }
141   };
142   typedef QMap< int, QList<int> > Connectivity;
143
144   QWidget*     frame() const;
145   SMESH_Actor* actor() const;
146   bool         isElements() const;
147
148   virtual void information( const QList<long>& ) = 0;
149   virtual void clearInternal();
150
151   Connectivity nodeConnectivity( const SMDS_MeshNode* );
152   QString      formatConnectivity( Connectivity, int );
153   XYZ          gravityCenter( const SMDS_MeshElement* );
154
155 private slots:
156   void         showPrevious();
157   void         showNext();
158   void         updateControls();
159
160 private:
161   SMESH_Actor*     myActor;
162   QList<long>      myIDs;
163   int              myIsElement;
164   QWidget*         myFrame;
165   QWidget*         myExtra;
166   QLabel*          myCurrent;
167   QPushButton*     myPrev;
168   QPushButton*     myNext;
169   int              myIndex;
170 };
171
172 class SMESHGUI_EXPORT SMESHGUI_SimpleElemInfo : public SMESHGUI_ElemInfo
173 {
174 public:
175   SMESHGUI_SimpleElemInfo( QWidget* = 0 );
176
177 protected:
178   void          information( const QList<long>& );
179   void          clearInternal();
180
181 private:
182   QTextBrowser* myInfo;
183 };
184
185 class SMESHGUI_EXPORT SMESHGUI_TreeElemInfo : public SMESHGUI_ElemInfo
186 {
187   class ItemDelegate;
188
189   enum { Bold = 0x01, All = 0x80 };
190
191 public:
192   SMESHGUI_TreeElemInfo( QWidget* = 0 );
193
194 protected:
195   void             information( const QList<long>& );
196   void             clearInternal();
197
198 private:
199   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 0 );
200   
201 private:
202   QTreeWidget*     myInfo;
203 };
204
205 class GrpComputor: public QObject
206 {
207   Q_OBJECT;
208
209 public:
210   GrpComputor( SMESH::SMESH_GroupBase_ptr, QTreeWidgetItem*, QObject* );
211
212 public slots:
213   void compute();
214
215 private:
216   SMESH::SMESH_GroupBase_var myGroup;
217   QTreeWidgetItem*           myItem;
218 };
219
220 class SMESHGUI_EXPORT SMESHGUI_AddInfo : public QTreeWidget
221 {
222   Q_OBJECT;
223
224   enum { Bold = 0x01, All = 0x80 };
225
226 public:
227   SMESHGUI_AddInfo( QWidget* = 0 );
228   ~SMESHGUI_AddInfo();
229
230   void             showInfo( SMESH::SMESH_IDSource_ptr );
231   //  void             clear();
232
233 private:
234   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 0 );
235   void             meshInfo( SMESH::SMESH_Mesh_ptr, QTreeWidgetItem* );
236   void             subMeshInfo( SMESH::SMESH_subMesh_ptr, QTreeWidgetItem* );
237   void             groupInfo( SMESH::SMESH_GroupBase_ptr, QTreeWidgetItem* );
238
239 private:
240   QList<GrpComputor*> myComputors;
241 };
242
243 class SMESHGUI_EXPORT SMESHGUI_MeshInfoDlg : public QDialog
244
245   Q_OBJECT;
246
247   enum { NodeMode, ElemMode };
248
249 public:
250   //! Information type
251   enum { 
252     BaseInfo,  //!< base mesh information
253     ElemInfo,  //!< mesh element information
254     AddInfo    //!< additional information
255   };
256
257   SMESHGUI_MeshInfoDlg( QWidget* = 0, int = BaseInfo );
258   ~SMESHGUI_MeshInfoDlg();
259
260   void showInfo( const Handle(SALOME_InteractiveObject)& );
261   void reject();
262
263 protected:
264   void keyPressEvent( QKeyEvent* );
265   void enterEvent( QEvent* );
266
267 private slots:
268   void help();
269   void updateSelection();
270   void updateInfo();
271   void activate();
272   void deactivate();
273   void modeChanged();
274   void idChanged();
275
276 private:
277   QTabWidget*        myTabWidget;
278   SMESHGUI_MeshInfo* myBaseInfo;
279   QButtonGroup*      myMode;
280   QLineEdit*         myID;
281   SMESHGUI_ElemInfo* myElemInfo;   
282   SMESHGUI_AddInfo*  myAddInfo;
283   SMESH_Actor*       myActor;
284 };
285
286 #endif // SMESHGUI_MESHINFO_H