Salome HOME
f66a59000a28c11eeffcc178be8f6bf4fe72a8ef
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshInfo.h
1 // Copyright (C) 2007-2013  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 #include "SMESH_ControlsDef.hxx"
31
32 #include <Plot2d_Histogram.h>
33
34 #include <QFrame>
35 #include <QDialog>
36 #include <QList>
37 #include <QMap>
38 #include <QSet>
39 #include <QTreeWidget>
40 #include <QVector>
41
42 #include <SALOMEconfig.h>
43 #include CORBA_SERVER_HEADER(SMESH_Mesh)
44 #include CORBA_SERVER_HEADER(SMESH_Group)
45
46 class QButtonGroup;
47 class QContextMenuEvent;
48 class QLabel;
49 class QLineEdit;
50 class QPushButton;
51 class QTabWidget;
52 class QTextBrowser;
53 class SMESH_Actor;
54 class SMDS_MeshNode;
55 class SMDS_MeshElement;
56
57 class ExtraWidget;
58
59 class SMESHGUI_EXPORT SMESHGUI_MeshInfo : public QFrame
60 {
61   Q_OBJECT;
62   
63   enum {
64     iName,
65     iObject,
66     iNodesStart,
67     iNodes,
68     iNodesEnd,
69     iElementsStart = iNodesEnd, 
70     iElements,
71     iNbStart,
72     iNb,
73     iNbEnd,
74     i0DStart = iNbEnd,
75     i0D,
76     i0DEnd,
77     iBallsStart = i0DEnd,
78     iBalls,
79     iBallsEnd,
80     i1DStart       = iBallsEnd,
81     i1D,
82     i1DEnd,
83     i2DStart       = i1DEnd,
84     i2D,
85     i2DTriangles,
86     i2DQuadrangles,
87     i2DPolygons,
88     i2DEnd,
89     i3DStart       = i2DEnd,
90     i3D,
91     i3DTetrahedrons,
92     i3DHexahedrons,
93     i3DPyramids,
94     i3DPrisms,
95     i3DHexaPrisms,
96     i3DPolyhedrons,
97     i3DEnd,
98     iElementsEnd   = i3DEnd
99   };
100
101   enum {
102     iSingle = 1,
103     iTotal  = iSingle,
104     iLinear,
105     iQuadratic
106   };
107
108   typedef QList<QWidget*> wlist;
109   typedef QVector<wlist>  iwlist;
110
111 public:
112   SMESHGUI_MeshInfo( QWidget* = 0 );
113   ~SMESHGUI_MeshInfo();
114
115   void     showInfo( SMESH::SMESH_IDSource_ptr );
116   void     clear();
117   void     saveInfo( QTextStream &out );
118
119 private:
120   enum { Bold = 0x01, Italic = 0x02 };
121
122   QLabel*  createField();
123   QWidget* createLine();
124   void     setFontAttributes( QWidget*, int, bool = true );
125   void     setFieldsVisible( int, int, bool );
126
127 private slots:
128   void loadMesh();
129
130 private:
131   iwlist       myWidgets;
132   QPushButton* myLoadBtn;
133 };
134
135 class SMESHGUI_EXPORT SMESHGUI_ElemInfo : public QWidget
136 {
137   Q_OBJECT;
138
139 public:
140   SMESHGUI_ElemInfo( QWidget* = 0 );
141   ~SMESHGUI_ElemInfo();
142
143   void         setSource( SMESH_Actor* );
144   void         showInfo( long, bool );
145   void         showInfo( QSet<long>, bool );
146   void         clear();
147   virtual void saveInfo( QTextStream &out ) = 0;
148
149 protected:
150   struct XYZ
151   {
152     double myX, myY, myZ;
153     XYZ() { myX = myY = myZ = 0.0; }
154     void add( double x, double y, double z ) { myX += x; myY += y; myZ += z; }
155     void divide( double a ) { if ( a != 0.) { myX /= a; myY /= a; myZ /= a; } }
156     double x() const  { return myX; }
157     double y() const  { return myY; }
158     double z() const  { return myZ; }
159   };
160   typedef QMap< int, QList<int> > Connectivity;
161
162   QWidget*     frame() const;
163   SMESH_Actor* actor() const;
164   bool         isElements() const;
165
166   virtual void information( const QList<long>& ) = 0;
167   virtual void clearInternal();
168
169   Connectivity nodeConnectivity( const SMDS_MeshNode* );
170   QString      formatConnectivity( Connectivity, int );
171   XYZ          gravityCenter( const SMDS_MeshElement* );
172
173 signals:
174   void         itemInfo( int );
175   void         itemInfo( const QString& );
176
177 private slots:
178   void         showPrevious();
179   void         showNext();
180   void         updateControls();
181
182 private:
183   SMESH_Actor*     myActor;
184   QList<long>      myIDs;
185   int              myIsElement;
186   QWidget*         myFrame;
187   ExtraWidget*     myExtra;
188   int              myIndex;
189 };
190
191 class SMESHGUI_EXPORT SMESHGUI_SimpleElemInfo : public SMESHGUI_ElemInfo
192 {
193   Q_OBJECT
194
195 public:
196   SMESHGUI_SimpleElemInfo( QWidget* = 0 );
197   void          saveInfo( QTextStream &out );
198
199 protected:
200   void          information( const QList<long>& );
201   void          clearInternal();
202
203 private:
204   QTextBrowser* myInfo;
205 };
206
207 class SMESHGUI_EXPORT SMESHGUI_TreeElemInfo : public SMESHGUI_ElemInfo
208 {
209   Q_OBJECT;
210
211   class ItemDelegate;
212
213   enum { Bold = 0x01, All = 0x80 };
214
215 public:
216   SMESHGUI_TreeElemInfo( QWidget* = 0 );
217   void             saveInfo( QTextStream &out );
218
219 protected:
220   void             contextMenuEvent( QContextMenuEvent* e );
221   void             information( const QList<long>& );
222   void             clearInternal();
223
224 private slots:
225   void             itemDoubleClicked( QTreeWidgetItem*, int );
226   
227 private:
228   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 0 );
229   
230 private:
231   QTreeWidget*     myInfo;
232 };
233
234 class GrpComputor: public QObject
235 {
236   Q_OBJECT;
237
238 public:
239   GrpComputor( SMESH::SMESH_GroupBase_ptr, QTreeWidgetItem*, QObject* );
240   QTreeWidgetItem* getItem() { return myItem; }
241
242 public slots:
243   void compute();
244
245 private:
246   SMESH::SMESH_GroupBase_var myGroup;
247   QTreeWidgetItem*           myItem;
248 };
249
250 class SMESHGUI_EXPORT SMESHGUI_AddInfo : public QTreeWidget
251 {
252   Q_OBJECT;
253
254   enum { Bold = 0x01, All = 0x80 };
255
256 public:
257   SMESHGUI_AddInfo( QWidget* = 0 );
258   ~SMESHGUI_AddInfo();
259
260   void             showInfo( SMESH::SMESH_IDSource_ptr );
261   //  void             clear();
262   void             saveInfo( QTextStream &out );
263
264 private slots:
265   void             changeLoadToCompute();
266   void             showPreviousGroups();
267   void             showNextGroups();
268   void             showPreviousSubMeshes();
269   void             showNextSubMeshes();
270
271 private:
272   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 0 );
273   void             meshInfo( SMESH::SMESH_Mesh_ptr, QTreeWidgetItem* );
274   void             subMeshInfo( SMESH::SMESH_subMesh_ptr, QTreeWidgetItem* );
275   void             groupInfo( SMESH::SMESH_GroupBase_ptr, QTreeWidgetItem* );
276
277   void             showGroups();
278   void             showSubMeshes();
279
280 private:
281   QList<GrpComputor*>      myComputors;
282   SMESH::ListOfGroups_var  myGroups;
283   SMESH::submesh_array_var mySubMeshes;
284 };
285
286 class SMESHGUI_EXPORT SMESHGUI_CtrlInfo : public QFrame
287 {
288   Q_OBJECT;
289
290 public:
291   SMESHGUI_CtrlInfo( QWidget* = 0 );
292   ~SMESHGUI_CtrlInfo();
293
294   void              showInfo( SMESH::SMESH_IDSource_ptr );
295   void              saveInfo( QTextStream &out );
296
297 private:
298   QLabel*           createField();
299   QwtPlot*          createPlot( QWidget* );
300   void              setFontAttributes( QWidget* );
301   void              clearInternal();
302   int               nbElemsControl( SMESH::long_array_var&, SMESH::Controls::FunctorPtr );
303   Plot2d_Histogram* getHistogram( SMESH::long_array_var&, SMESH::Controls::NumericalFunctorPtr ); 
304
305 private slots:
306   void              computeFaceInfo();
307   void              computeVolumeInfo();
308
309 private:
310   QList<QLabel*> myWidgets;
311   QwtPlot*       myPlot;
312   QwtPlot*       myPlot3D;
313   QPushButton*   myComputeFaceBtn;
314   QPushButton*   myComputeVolumeBtn;
315 };
316
317 class SMESHGUI_EXPORT SMESHGUI_MeshInfoDlg : public QDialog
318
319   Q_OBJECT;
320
321   enum { NodeMode, ElemMode };
322
323 public:
324   //! Information type
325   enum { 
326     BaseInfo,  //!< base mesh information
327     ElemInfo,  //!< mesh element information
328     AddInfo,   //!< additional information
329     CtrlInfo //!< controls information
330   };
331
332   SMESHGUI_MeshInfoDlg( QWidget* = 0, int = BaseInfo );
333   ~SMESHGUI_MeshInfoDlg();
334
335   void showInfo( const Handle(SALOME_InteractiveObject)& );
336   void reject();
337
338 protected:
339   void keyPressEvent( QKeyEvent* );
340   void enterEvent( QEvent* );
341
342 private slots:
343   void help();
344   void updateSelection();
345   void updateInfo();
346   void activate();
347   void deactivate();
348   void modeChanged();
349   void idChanged();
350   void showItemInfo( int );
351   void showItemInfo( const QString& );
352   void dump();
353
354 private:
355   QTabWidget*        myTabWidget;
356   SMESHGUI_MeshInfo* myBaseInfo;
357   QButtonGroup*      myMode;
358   QLineEdit*         myID;
359   SMESHGUI_ElemInfo* myElemInfo;   
360   SMESHGUI_AddInfo*  myAddInfo;
361   SMESHGUI_CtrlInfo* myCtrlInfo;
362   SMESH_Actor*       myActor;
363 };
364
365 class SMESHGUI_EXPORT SMESHGUI_CtrlInfoDlg : public QDialog
366
367   Q_OBJECT;
368
369 public:
370   SMESHGUI_CtrlInfoDlg( QWidget* = 0 );
371   ~SMESHGUI_CtrlInfoDlg();
372
373   void showInfo( const Handle(SALOME_InteractiveObject)& );
374   void reject();
375
376 private slots:
377   void updateInfo();
378   void activate();
379   void deactivate();
380   void updateSelection();
381
382 private:
383   SMESHGUI_CtrlInfo*  myCtrlInfo;
384 };
385
386 #endif // SMESHGUI_MESHINFO_H