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