Salome HOME
0022480: EDF 2773 SMESH: Automatic update in SMESH
[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             nodeInfo( const SMDS_MeshNode*, int, int, QTreeWidgetItem* );
230   void             clearInternal();
231
232 private slots:
233   void             itemDoubleClicked( QTreeWidgetItem*, int );
234   
235 private:
236   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 0 );
237   
238 private:
239   QTreeWidget*     myInfo;
240 };
241
242 class GrpComputor: public QObject
243 {
244   Q_OBJECT;
245
246 public:
247   GrpComputor( SMESH::SMESH_GroupBase_ptr, QTreeWidgetItem*, QObject* );
248   QTreeWidgetItem* getItem() { return myItem; }
249
250 public slots:
251   void compute();
252
253 private:
254   SMESH::SMESH_GroupBase_var myGroup;
255   QTreeWidgetItem*           myItem;
256 };
257
258 class SMESHGUI_EXPORT SMESHGUI_AddInfo : public QTreeWidget
259 {
260   Q_OBJECT;
261
262   enum { Bold = 0x01, All = 0x80 };
263
264 public:
265   SMESHGUI_AddInfo( QWidget* = 0 );
266   ~SMESHGUI_AddInfo();
267
268   void             showInfo( SMESH::SMESH_IDSource_ptr );
269   //  void             clear();
270   void             saveInfo( QTextStream &out );
271
272 private slots:
273   void             changeLoadToCompute();
274   void             showPreviousGroups();
275   void             showNextGroups();
276   void             showPreviousSubMeshes();
277   void             showNextSubMeshes();
278
279 private:
280   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 0 );
281   void             meshInfo( SMESH::SMESH_Mesh_ptr, QTreeWidgetItem* );
282   void             subMeshInfo( SMESH::SMESH_subMesh_ptr, QTreeWidgetItem* );
283   void             groupInfo( SMESH::SMESH_GroupBase_ptr, QTreeWidgetItem* );
284
285   void             showGroups();
286   void             showSubMeshes();
287
288 private:
289   QList<GrpComputor*>      myComputors;
290   SMESH::ListOfGroups_var  myGroups;
291   SMESH::submesh_array_var mySubMeshes;
292 };
293
294 class SMESHGUI_EXPORT SMESHGUI_CtrlInfo : public QFrame
295 {
296   Q_OBJECT;
297
298 public:
299   SMESHGUI_CtrlInfo( QWidget* = 0 );
300   ~SMESHGUI_CtrlInfo();
301
302   void                  showInfo( SMESH::SMESH_IDSource_ptr );
303   void                  saveInfo( QTextStream &out );
304
305 private:
306   enum ObjectType { Mesh, SubMesh, Group };
307   QLabel*               createField();
308   QwtPlot*              createPlot( QWidget* );
309   void                  setFontAttributes( QWidget* );
310   void                  clearInternal();
311   Plot2d_Histogram*     getHistogram( SMESH::NumericalFunctor_ptr functor );
312   void                  computeNb( int ft, int iBut, int iWdg );
313
314 private slots:
315   void                  computeAspectRatio();
316   void                  computeAspectRatio3D();
317   void                  computeFreeNodesInfo();
318   void                  computeDoubleNodesInfo();
319   void                  computeDoubleEdgesInfo();
320   void                  computeDoubleFacesInfo();
321   void                  computeOverConstrainedFacesInfo();
322   void                  computeDoubleVolumesInfo();
323   void                  computeOverConstrainedVolumesInfo();
324   void                  setTolerance( const double theTolerance );
325   
326
327 private:
328   typedef SALOME::GenericObj_wrap< SMESH::Predicate >        TPredicate;
329   typedef SALOME::GenericObj_wrap< SMESH::NumericalFunctor > TNumFunctor;
330   SMESH::SMESH_IDSource_var myObject;
331   ObjectType                myObjectType;
332   SMESHGUI_SpinBox*         myToleranceWidget;
333   QList<QLabel*>            myWidgets;
334   QGridLayout*              myMainLayout;
335   QwtPlot*                  myPlot;
336   QwtPlot*                  myPlot3D;
337   QList<QAbstractButton*>   myButtons;
338   QList<TPredicate>         myPredicates;
339   TNumFunctor               myAspectRatio, myAspectRatio3D;
340 };
341
342 class SMESHGUI_EXPORT SMESHGUI_MeshInfoDlg : public QDialog
343
344   Q_OBJECT;
345
346   enum { NodeMode, ElemMode };
347
348 public:
349   //! Information type
350   enum { 
351     BaseInfo,  //!< base mesh information
352     ElemInfo,  //!< mesh element information
353     AddInfo,   //!< additional information
354     CtrlInfo //!< controls information
355   };
356
357   SMESHGUI_MeshInfoDlg( QWidget* = 0, int = BaseInfo );
358   ~SMESHGUI_MeshInfoDlg();
359
360   void showInfo( const Handle(SALOME_InteractiveObject)& );
361   void reject();
362
363 protected:
364   void keyPressEvent( QKeyEvent* );
365   void enterEvent( QEvent* );
366
367 private slots:
368   void help();
369   void updateSelection();
370   void updateInfo();
371   void activate();
372   void deactivate();
373   void modeChanged();
374   void idChanged();
375   void showItemInfo( int );
376   void showItemInfo( const QString& );
377   void dump();
378
379 private:
380   QTabWidget*        myTabWidget;
381   SMESHGUI_MeshInfo* myBaseInfo;
382   QButtonGroup*      myMode;
383   QLineEdit*         myID;
384   SMESHGUI_ElemInfo* myElemInfo;   
385   SMESHGUI_AddInfo*  myAddInfo;
386   SMESHGUI_CtrlInfo* myCtrlInfo;
387   SMESH_Actor*       myActor;
388 };
389
390 class SMESHGUI_EXPORT SMESHGUI_CtrlInfoDlg : public QDialog
391
392   Q_OBJECT;
393
394 public:
395   SMESHGUI_CtrlInfoDlg( QWidget* = 0 );
396   ~SMESHGUI_CtrlInfoDlg();
397
398   void showInfo( const Handle(SALOME_InteractiveObject)& );
399   void reject();
400
401 private slots:
402   void updateInfo();
403   void activate();
404   void deactivate();
405   void updateSelection();
406   void help();
407   void dump();
408
409 private:
410   SMESHGUI_CtrlInfo*  myCtrlInfo;
411 };
412
413 #endif // SMESHGUI_MESHINFO_H