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