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