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