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