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