Salome HOME
3b44baedd20fed1bff2dcb7372109b447181ff63
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshInfo.h
1 // Copyright (C) 2007-2012  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.
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 <SALOME_InteractiveObject.hxx>
30
31 #include <QFrame>
32 #include <QDialog>
33 #include <QList>
34 #include <QMap>
35 #include <QSet>
36 #include <QTreeWidget>
37 #include <QVector>
38
39 #include <SALOMEconfig.h>
40 #include CORBA_SERVER_HEADER(SMESH_Mesh)
41 #include CORBA_SERVER_HEADER(SMESH_Group)
42
43 class QButtonGroup;
44 class QContextMenuEvent;
45 class QLabel;
46 class QLineEdit;
47 class QPushButton;
48 class QTabWidget;
49 class QTextBrowser;
50 class SMESH_Actor;
51 class SMDS_MeshNode;
52 class SMDS_MeshElement;
53
54 class ExtraWidget;
55
56 class SMESHGUI_EXPORT SMESHGUI_MeshInfo : public QFrame
57 {
58   Q_OBJECT;
59   
60   enum {
61     iName,
62     iObject,
63     iNodesStart,
64     iNodes,
65     iNodesEnd,
66     iElementsStart = iNodesEnd, 
67     iElements,
68     i0DStart,
69     i0D,
70     i0DEnd,
71     iBallsStart = i0DEnd,
72     iBalls,
73     iBallsEnd,
74     i1DStart       = iBallsEnd,
75     i1D,
76     i1DEnd,
77     i2DStart       = i1DEnd,
78     i2D,
79     i2DTriangles,
80     i2DQuadrangles,
81     i2DPolygons,
82     i2DEnd,
83     i3DStart       = i2DEnd,
84     i3D,
85     i3DTetrahedrons,
86     i3DHexahedrons,
87     i3DPyramids,
88     i3DPrisms,
89     i3DHexaPrisms,
90     i3DPolyhedrons,
91     i3DEnd,
92     iElementsEnd   = i3DEnd
93   };
94
95   enum {
96     iSingle = 1,
97     iTotal  = iSingle,
98     iLinear,
99     iQuadratic
100   };
101
102   typedef QList<QWidget*> wlist;
103   typedef QVector<wlist>  iwlist;
104
105 public:
106   SMESHGUI_MeshInfo( QWidget* = 0 );
107   ~SMESHGUI_MeshInfo();
108
109   void     showInfo( SMESH::SMESH_IDSource_ptr );
110   void     clear();
111
112 private:
113   enum { Bold = 0x01, Italic = 0x02 };
114
115   QLabel*  createField();
116   QWidget* createLine();
117   void     setFontAttributes( QWidget*, int, bool = true );
118   void     setFieldsVisible( int, int, bool );
119
120 private slots:
121   void loadMesh();
122
123 private:
124   iwlist       myWidgets;
125   QPushButton* myLoadBtn;
126 };
127
128 class SMESHGUI_EXPORT SMESHGUI_ElemInfo : public QWidget
129 {
130   Q_OBJECT;
131
132 public:
133   SMESHGUI_ElemInfo( QWidget* = 0 );
134   ~SMESHGUI_ElemInfo();
135
136   void         setSource( SMESH_Actor* );
137   void         showInfo( long, bool );
138   void         showInfo( QSet<long>, bool );
139   void         clear();
140
141 protected:
142   struct XYZ
143   {
144     double myX, myY, myZ;
145     XYZ() { myX = myY = myZ = 0.0; }
146     void add( double x, double y, double z ) { myX += x; myY += y; myZ += z; }
147     void divide( double a ) { if ( a != 0.) { myX /= a; myY /= a; myZ /= a; } }
148     double x() const  { return myX; }
149     double y() const  { return myY; }
150     double z() const  { return myZ; }
151   };
152   typedef QMap< int, QList<int> > Connectivity;
153
154   QWidget*     frame() const;
155   SMESH_Actor* actor() const;
156   bool         isElements() const;
157
158   virtual void information( const QList<long>& ) = 0;
159   virtual void clearInternal();
160
161   Connectivity nodeConnectivity( const SMDS_MeshNode* );
162   QString      formatConnectivity( Connectivity, int );
163   XYZ          gravityCenter( const SMDS_MeshElement* );
164
165 signals:
166   void         itemInfo( int );
167   void         itemInfo( const QString& );
168
169 private slots:
170   void         showPrevious();
171   void         showNext();
172   void         updateControls();
173
174 private:
175   SMESH_Actor*     myActor;
176   QList<long>      myIDs;
177   int              myIsElement;
178   QWidget*         myFrame;
179   ExtraWidget*     myExtra;
180   int              myIndex;
181 };
182
183 class SMESHGUI_EXPORT SMESHGUI_SimpleElemInfo : public SMESHGUI_ElemInfo
184 {
185   Q_OBJECT
186
187 public:
188   SMESHGUI_SimpleElemInfo( QWidget* = 0 );
189
190 protected:
191   void          information( const QList<long>& );
192   void          clearInternal();
193
194 private:
195   QTextBrowser* myInfo;
196 };
197
198 class SMESHGUI_EXPORT SMESHGUI_TreeElemInfo : public SMESHGUI_ElemInfo
199 {
200   Q_OBJECT;
201
202   class ItemDelegate;
203
204   enum { Bold = 0x01, All = 0x80 };
205
206 public:
207   SMESHGUI_TreeElemInfo( QWidget* = 0 );
208
209 protected:
210   void             contextMenuEvent( QContextMenuEvent* e );
211   void             information( const QList<long>& );
212   void             clearInternal();
213
214 private slots:
215   void             itemDoubleClicked( QTreeWidgetItem*, int );
216   
217 private:
218   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 0 );
219   
220 private:
221   QTreeWidget*     myInfo;
222 };
223
224 class GrpComputor: public QObject
225 {
226   Q_OBJECT;
227
228 public:
229   GrpComputor( SMESH::SMESH_GroupBase_ptr, QTreeWidgetItem*, QObject* );
230   QTreeWidgetItem* getItem() { return myItem; }
231
232 public slots:
233   void compute();
234
235 private:
236   SMESH::SMESH_GroupBase_var myGroup;
237   QTreeWidgetItem*           myItem;
238 };
239
240 class SMESHGUI_EXPORT SMESHGUI_AddInfo : public QTreeWidget
241 {
242   Q_OBJECT;
243
244   enum { Bold = 0x01, All = 0x80 };
245
246 public:
247   SMESHGUI_AddInfo( QWidget* = 0 );
248   ~SMESHGUI_AddInfo();
249
250   void             showInfo( SMESH::SMESH_IDSource_ptr );
251   //  void             clear();
252
253 private slots:
254   void             changeLoadToCompute();
255   void             showPreviousGroups();
256   void             showNextGroups();
257   void             showPreviousSubMeshes();
258   void             showNextSubMeshes();
259
260 private:
261   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 0 );
262   void             meshInfo( SMESH::SMESH_Mesh_ptr, QTreeWidgetItem* );
263   void             subMeshInfo( SMESH::SMESH_subMesh_ptr, QTreeWidgetItem* );
264   void             groupInfo( SMESH::SMESH_GroupBase_ptr, QTreeWidgetItem* );
265
266   void             showGroups();
267   void             showSubMeshes();
268
269 private:
270   QList<GrpComputor*>      myComputors;
271   SMESH::ListOfGroups_var  myGroups;
272   SMESH::submesh_array_var mySubMeshes;
273 };
274
275 class SMESHGUI_EXPORT SMESHGUI_MeshInfoDlg : public QDialog
276
277   Q_OBJECT;
278
279   enum { NodeMode, ElemMode };
280
281 public:
282   //! Information type
283   enum { 
284     BaseInfo,  //!< base mesh information
285     ElemInfo,  //!< mesh element information
286     AddInfo    //!< additional information
287   };
288
289   SMESHGUI_MeshInfoDlg( QWidget* = 0, int = BaseInfo );
290   ~SMESHGUI_MeshInfoDlg();
291
292   void showInfo( const Handle(SALOME_InteractiveObject)& );
293   void reject();
294
295 protected:
296   void keyPressEvent( QKeyEvent* );
297   void enterEvent( QEvent* );
298
299 private slots:
300   void help();
301   void updateSelection();
302   void updateInfo();
303   void activate();
304   void deactivate();
305   void modeChanged();
306   void idChanged();
307   void showItemInfo( int );
308   void showItemInfo( const QString& );
309
310 private:
311   QTabWidget*        myTabWidget;
312   SMESHGUI_MeshInfo* myBaseInfo;
313   QButtonGroup*      myMode;
314   QLineEdit*         myID;
315   SMESHGUI_ElemInfo* myElemInfo;   
316   SMESHGUI_AddInfo*  myAddInfo;
317   SMESH_Actor*       myActor;
318 };
319
320 #endif // SMESHGUI_MESHINFO_H