Salome HOME
843a37f5b66ff260cf9da0c478aaa619cbf062a9
[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* );
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
183   virtual void information( const QList<long>& ) = 0;
184   virtual void clearInternal();
185
186   Connectivity nodeConnectivity( const SMDS_MeshNode* );
187   QString      formatConnectivity( Connectivity, int );
188   XYZ          gravityCenter( const SMDS_MeshElement* );
189   XYZ          normal( const SMDS_MeshElement* );
190
191 signals:
192   void         itemInfo( int );
193   void         itemInfo( const QString& );
194
195 private slots:
196   void         showPrevious();
197   void         showNext();
198   void         updateControls();
199
200 private:
201   SMESH_Actor*     myActor;
202   QList<long>      myIDs;
203   int              myIsElement;
204   QWidget*         myFrame;
205   ExtraWidget*     myExtra;
206   int              myIndex;
207 };
208
209 class SMESHGUI_EXPORT SMESHGUI_SimpleElemInfo : public SMESHGUI_ElemInfo
210 {
211   Q_OBJECT
212
213 public:
214   SMESHGUI_SimpleElemInfo( QWidget* = 0 );
215   void          saveInfo( QTextStream &out );
216
217 protected:
218   void          information( const QList<long>& );
219   void          clearInternal();
220
221 private:
222   QTextBrowser* myInfo;
223 };
224
225 class SMESHGUI_EXPORT SMESHGUI_TreeElemInfo : public SMESHGUI_ElemInfo
226 {
227   Q_OBJECT;
228
229   class ItemDelegate;
230
231   enum { Bold = 0x01, All = 0x80 };
232
233 public:
234   SMESHGUI_TreeElemInfo( QWidget* = 0 );
235   void             saveInfo( QTextStream &out );
236
237 protected:
238   void             contextMenuEvent( QContextMenuEvent* e );
239   void             information( const QList<long>& );
240   void             nodeInfo( const SMDS_MeshNode*, int, int, QTreeWidgetItem* );
241   void             clearInternal();
242
243 private slots:
244   void             itemDoubleClicked( QTreeWidgetItem*, int );
245   
246 private:
247   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 0 );
248   
249 private:
250   QTreeWidget*     myInfo;
251 };
252
253 class GrpComputor: public QObject
254 {
255   Q_OBJECT;
256
257 public:
258   GrpComputor( SMESH::SMESH_GroupBase_ptr, QTreeWidgetItem*, QObject*, bool = false);
259   QTreeWidgetItem* getItem() { return myItem; }
260
261 public slots:
262   void compute();
263
264 private:
265   SMESH::SMESH_GroupBase_var myGroup;
266   QTreeWidgetItem*           myItem;
267   bool                       myToComputeSize;
268 };
269
270 class SMESHGUI_EXPORT SMESHGUI_AddInfo : public QTreeWidget
271 {
272   Q_OBJECT;
273
274   enum { Bold = 0x01, All = 0x80 };
275
276 public:
277   SMESHGUI_AddInfo( QWidget* = 0 );
278   ~SMESHGUI_AddInfo();
279
280   void             showInfo( SMESH::SMESH_IDSource_ptr );
281   //  void             clear();
282   void             saveInfo( QTextStream &out );
283
284 private slots:
285   void             changeLoadToCompute();
286   void             showPreviousGroups();
287   void             showNextGroups();
288   void             showPreviousSubMeshes();
289   void             showNextSubMeshes();
290
291 private:
292   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 0 );
293   void             meshInfo( SMESH::SMESH_Mesh_ptr, QTreeWidgetItem* );
294   void             subMeshInfo( SMESH::SMESH_subMesh_ptr, QTreeWidgetItem* );
295   void             groupInfo( SMESH::SMESH_GroupBase_ptr, QTreeWidgetItem* );
296
297   void             showGroups();
298   void             showSubMeshes();
299
300 private:
301   QList<GrpComputor*>      myComputors;
302   SMESH::ListOfGroups_var  myGroups;
303   SMESH::submesh_array_var mySubMeshes;
304 };
305
306 class SMESHGUI_EXPORT SMESHGUI_CtrlInfo : public QFrame
307 {
308   Q_OBJECT;
309
310 public:
311   SMESHGUI_CtrlInfo( QWidget* = 0 );
312   ~SMESHGUI_CtrlInfo();
313
314   void                  showInfo( SMESH::SMESH_IDSource_ptr );
315   void                  saveInfo( QTextStream &out );
316
317 private:
318   enum ObjectType { Mesh, SubMesh, Group };
319   QLabel*               createField();
320   QwtPlot*              createPlot( QWidget* );
321   void                  setFontAttributes( QWidget* );
322   void                  clearInternal();
323 #ifndef DISABLE_PLOT2DVIEWER
324   Plot2d_Histogram*     getHistogram( SMESH::NumericalFunctor_ptr functor );
325 #endif
326   void                  computeNb( int ft, int iBut, int iWdg );
327
328 private slots:
329   void                  computeAspectRatio();
330   void                  computeAspectRatio3D();
331   void                  computeFreeNodesInfo();
332   void                  computeNodesNbConnInfo();
333   void                  computeDoubleNodesInfo();
334   void                  computeDoubleEdgesInfo();
335   void                  computeDoubleFacesInfo();
336   void                  computeOverConstrainedFacesInfo();
337   void                  computeDoubleVolumesInfo();
338   void                  computeOverConstrainedVolumesInfo();
339   void                  setTolerance( const double theTolerance );
340   
341
342 private:
343   typedef SALOME::GenericObj_wrap< SMESH::Predicate >        TPredicate;
344   typedef SALOME::GenericObj_wrap< SMESH::NumericalFunctor > TNumFunctor;
345   SMESH::SMESH_IDSource_var myObject;
346   ObjectType                myObjectType;
347   SMESHGUI_SpinBox*         myToleranceWidget;
348   QList<QLabel*>            myWidgets;
349   QGridLayout*              myMainLayout;
350   QwtPlot*                  myPlot;
351   QwtPlot*                  myPlot3D;
352   QList<QAbstractButton*>   myButtons;
353   QList<TPredicate>         myPredicates;
354   TNumFunctor               myAspectRatio, myAspectRatio3D, myNodeConnFunctor;
355 };
356
357 class SMESHGUI_EXPORT SMESHGUI_MeshInfoDlg : public QDialog
358
359   Q_OBJECT;
360
361   enum { NodeMode, ElemMode };
362
363 public:
364   //! Information type
365   enum { 
366     BaseInfo,  //!< base mesh information
367     ElemInfo,  //!< mesh element information
368     AddInfo,   //!< additional information
369     CtrlInfo //!< controls information
370   };
371
372   SMESHGUI_MeshInfoDlg( QWidget* = 0, int = BaseInfo );
373   ~SMESHGUI_MeshInfoDlg();
374
375   void showInfo( const Handle(SALOME_InteractiveObject)& );
376   void reject();
377
378 protected:
379   void keyPressEvent( QKeyEvent* );
380   void enterEvent( QEvent* );
381
382 private slots:
383   void help();
384   void updateSelection();
385   void updateInfo();
386   void activate();
387   void deactivate();
388   void modeChanged();
389   void idChanged();
390   void idPreviewChange(bool);
391   void showItemInfo( int );
392   void showItemInfo( const QString& );
393   void dump();
394
395 private:
396   QTabWidget*                      myTabWidget;
397   SMESHGUI_MeshInfo*               myBaseInfo;
398   QButtonGroup*                    myMode;
399   QLineEdit*                       myID;
400   QCheckBox*                       myIDPreviewCheck;
401   SMESHGUI_IdPreview*              myIDPreview;
402   SMESHGUI_ElemInfo*               myElemInfo;   
403   SMESHGUI_AddInfo*                myAddInfo;
404   SMESHGUI_CtrlInfo*               myCtrlInfo;
405   SMESH_Actor*                     myActor;
406   Handle(SALOME_InteractiveObject) myIO;
407 };
408
409 class SMESHGUI_EXPORT SMESHGUI_CtrlInfoDlg : public QDialog
410
411   Q_OBJECT;
412
413 public:
414   SMESHGUI_CtrlInfoDlg( QWidget* = 0 );
415   ~SMESHGUI_CtrlInfoDlg();
416
417   void showInfo( const Handle(SALOME_InteractiveObject)& );
418   void reject();
419
420 private slots:
421   void updateInfo();
422   void activate();
423   void deactivate();
424   void updateSelection();
425   void help();
426   void dump();
427
428 private:
429   SMESHGUI_CtrlInfo*  myCtrlInfo;
430 };
431
432 #endif // SMESHGUI_MESHINFO_H