Salome HOME
Fixing of bug concerning the mesh info dialog after compute with quadratic elements
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshInfo.h
1 // Copyright (C) 2007-2014  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 #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     iBiQuadratic
113   };
114
115   typedef QList<QWidget*> wlist;
116   typedef QVector<wlist>  iwlist;
117
118 public:
119   SMESHGUI_MeshInfo( QWidget* = 0 );
120   ~SMESHGUI_MeshInfo();
121
122   void     showInfo( SMESH::SMESH_IDSource_ptr );
123   void     clear();
124   void     saveInfo( QTextStream &out );
125
126 private:
127   enum { Bold = 0x01, Italic = 0x02 };
128
129   QLabel*  createField();
130   QWidget* createLine();
131   void     setFontAttributes( QWidget*, int, bool = true );
132   void     setFieldsVisible( int, int, bool );
133
134 private slots:
135   void loadMesh();
136
137 private:
138   iwlist       myWidgets;
139   QPushButton* myLoadBtn;
140 };
141
142 class SMESHGUI_EXPORT SMESHGUI_ElemInfo : public QWidget
143 {
144   Q_OBJECT;
145
146 public:
147   SMESHGUI_ElemInfo( QWidget* = 0 );
148   ~SMESHGUI_ElemInfo();
149
150   void         setSource( SMESH_Actor* );
151   void         showInfo( long, bool );
152   void         showInfo( QSet<long>, bool );
153   void         clear();
154   virtual void saveInfo( QTextStream &out ) = 0;
155
156 protected:
157   struct XYZ
158   {
159     double myX, myY, myZ;
160     XYZ() { myX = myY = myZ = 0.0; }
161     void add( double x, double y, double z ) { myX += x; myY += y; myZ += z; }
162     void divide( double a ) { if ( a != 0.) { myX /= a; myY /= a; myZ /= a; } }
163     double x() const  { return myX; }
164     double y() const  { return myY; }
165     double z() const  { return myZ; }
166   };
167   typedef QMap< int, QList<int> > Connectivity;
168
169   QWidget*     frame() const;
170   SMESH_Actor* actor() const;
171   bool         isElements() const;
172
173   virtual void information( const QList<long>& ) = 0;
174   virtual void clearInternal();
175
176   Connectivity nodeConnectivity( const SMDS_MeshNode* );
177   QString      formatConnectivity( Connectivity, int );
178   XYZ          gravityCenter( const SMDS_MeshElement* );
179
180 signals:
181   void         itemInfo( int );
182   void         itemInfo( const QString& );
183
184 private slots:
185   void         showPrevious();
186   void         showNext();
187   void         updateControls();
188
189 private:
190   SMESH_Actor*     myActor;
191   QList<long>      myIDs;
192   int              myIsElement;
193   QWidget*         myFrame;
194   ExtraWidget*     myExtra;
195   int              myIndex;
196 };
197
198 class SMESHGUI_EXPORT SMESHGUI_SimpleElemInfo : public SMESHGUI_ElemInfo
199 {
200   Q_OBJECT
201
202 public:
203   SMESHGUI_SimpleElemInfo( QWidget* = 0 );
204   void          saveInfo( QTextStream &out );
205
206 protected:
207   void          information( const QList<long>& );
208   void          clearInternal();
209
210 private:
211   QTextBrowser* myInfo;
212 };
213
214 class SMESHGUI_EXPORT SMESHGUI_TreeElemInfo : public SMESHGUI_ElemInfo
215 {
216   Q_OBJECT;
217
218   class ItemDelegate;
219
220   enum { Bold = 0x01, All = 0x80 };
221
222 public:
223   SMESHGUI_TreeElemInfo( QWidget* = 0 );
224   void             saveInfo( QTextStream &out );
225
226 protected:
227   void             contextMenuEvent( QContextMenuEvent* e );
228   void             information( const QList<long>& );
229   void             clearInternal();
230
231 private slots:
232   void             itemDoubleClicked( QTreeWidgetItem*, int );
233   
234 private:
235   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 0 );
236   
237 private:
238   QTreeWidget*     myInfo;
239 };
240
241 class GrpComputor: public QObject
242 {
243   Q_OBJECT;
244
245 public:
246   GrpComputor( SMESH::SMESH_GroupBase_ptr, QTreeWidgetItem*, QObject* );
247   QTreeWidgetItem* getItem() { return myItem; }
248
249 public slots:
250   void compute();
251
252 private:
253   SMESH::SMESH_GroupBase_var myGroup;
254   QTreeWidgetItem*           myItem;
255 };
256
257 class SMESHGUI_EXPORT SMESHGUI_AddInfo : public QTreeWidget
258 {
259   Q_OBJECT;
260
261   enum { Bold = 0x01, All = 0x80 };
262
263 public:
264   SMESHGUI_AddInfo( QWidget* = 0 );
265   ~SMESHGUI_AddInfo();
266
267   void             showInfo( SMESH::SMESH_IDSource_ptr );
268   //  void             clear();
269   void             saveInfo( QTextStream &out );
270
271 private slots:
272   void             changeLoadToCompute();
273   void             showPreviousGroups();
274   void             showNextGroups();
275   void             showPreviousSubMeshes();
276   void             showNextSubMeshes();
277
278 private:
279   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 0 );
280   void             meshInfo( SMESH::SMESH_Mesh_ptr, QTreeWidgetItem* );
281   void             subMeshInfo( SMESH::SMESH_subMesh_ptr, QTreeWidgetItem* );
282   void             groupInfo( SMESH::SMESH_GroupBase_ptr, QTreeWidgetItem* );
283
284   void             showGroups();
285   void             showSubMeshes();
286
287 private:
288   QList<GrpComputor*>      myComputors;
289   SMESH::ListOfGroups_var  myGroups;
290   SMESH::submesh_array_var mySubMeshes;
291 };
292
293 class SMESHGUI_EXPORT SMESHGUI_CtrlInfo : public QFrame
294 {
295   Q_OBJECT;
296
297 public:
298   SMESHGUI_CtrlInfo( QWidget* = 0 );
299   ~SMESHGUI_CtrlInfo();
300
301   void                  showInfo( SMESH::SMESH_IDSource_ptr );
302   void                  saveInfo( QTextStream &out );
303
304 private:
305   enum ObjectType { Mesh, SubMesh, Group };
306   QLabel*               createField();
307   QwtPlot*              createPlot( QWidget* );
308   void                  setFontAttributes( QWidget* );
309   void                  clearInternal();
310   Plot2d_Histogram*     getHistogram( SMESH::NumericalFunctor_ptr functor );
311   void                  computeNb( int ft, int iBut, int iWdg );
312
313 private slots:
314   void                  computeAspectRatio();
315   void                  computeAspectRatio3D();
316   void                  computeFreeNodesInfo();
317   void                  computeDoubleNodesInfo();
318   void                  computeDoubleEdgesInfo();
319   void                  computeDoubleFacesInfo();
320   void                  computeOverConstrainedFacesInfo();
321   void                  computeDoubleVolumesInfo();
322   void                  computeOverConstrainedVolumesInfo();
323   void                  setTolerance( const double theTolerance );
324   
325
326 private:
327   typedef SALOME::GenericObj_wrap< SMESH::Predicate >        TPredicate;
328   typedef SALOME::GenericObj_wrap< SMESH::NumericalFunctor > TNumFunctor;
329   SMESH::SMESH_IDSource_var myObject;
330   ObjectType                myObjectType;
331   SMESHGUI_SpinBox*         myToleranceWidget;
332   QList<QLabel*>            myWidgets;
333   QGridLayout*              myMainLayout;
334   QwtPlot*                  myPlot;
335   QwtPlot*                  myPlot3D;
336   QList<QAbstractButton*>   myButtons;
337   QList<TPredicate>         myPredicates;
338   TNumFunctor               myAspectRatio, myAspectRatio3D;
339 };
340
341 class SMESHGUI_EXPORT SMESHGUI_MeshInfoDlg : public QDialog
342
343   Q_OBJECT;
344
345   enum { NodeMode, ElemMode };
346
347 public:
348   //! Information type
349   enum { 
350     BaseInfo,  //!< base mesh information
351     ElemInfo,  //!< mesh element information
352     AddInfo,   //!< additional information
353     CtrlInfo //!< controls information
354   };
355
356   SMESHGUI_MeshInfoDlg( QWidget* = 0, int = BaseInfo );
357   ~SMESHGUI_MeshInfoDlg();
358
359   void showInfo( const Handle(SALOME_InteractiveObject)& );
360   void reject();
361
362 protected:
363   void keyPressEvent( QKeyEvent* );
364   void enterEvent( QEvent* );
365
366 private slots:
367   void help();
368   void updateSelection();
369   void updateInfo();
370   void activate();
371   void deactivate();
372   void modeChanged();
373   void idChanged();
374   void showItemInfo( int );
375   void showItemInfo( const QString& );
376   void dump();
377
378 private:
379   QTabWidget*        myTabWidget;
380   SMESHGUI_MeshInfo* myBaseInfo;
381   QButtonGroup*      myMode;
382   QLineEdit*         myID;
383   SMESHGUI_ElemInfo* myElemInfo;   
384   SMESHGUI_AddInfo*  myAddInfo;
385   SMESHGUI_CtrlInfo* myCtrlInfo;
386   SMESH_Actor*       myActor;
387 };
388
389 class SMESHGUI_EXPORT SMESHGUI_CtrlInfoDlg : public QDialog
390
391   Q_OBJECT;
392
393 public:
394   SMESHGUI_CtrlInfoDlg( QWidget* = 0 );
395   ~SMESHGUI_CtrlInfoDlg();
396
397   void showInfo( const Handle(SALOME_InteractiveObject)& );
398   void reject();
399
400 private slots:
401   void updateInfo();
402   void activate();
403   void deactivate();
404   void updateSelection();
405   void help();
406   void dump();
407
408 private:
409   SMESHGUI_CtrlInfo*  myCtrlInfo;
410 };
411
412 #endif // SMESHGUI_MESHINFO_H