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