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