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