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