Salome HOME
ae22e5ac0eb3947e95722d16d34c611d9550e74d
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshInfo.h
1 //  Copyright (C) 2007-2010  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 <QVector>
36
37 #include <SALOMEconfig.h>
38 #include CORBA_SERVER_HEADER(SMESH_Mesh)
39
40 class QButtonGroup;
41 class QLabel;
42 class QLineEdit;
43 class QTabWidget;
44 class QTextBrowser;
45 class QTreeWidget;
46 class QTreeWidgetItem;
47 class SMESH_Actor;
48 class SMDS_MeshNode;
49 class SMDS_MeshElement;
50
51 class SMESHGUI_EXPORT SMESHGUI_MeshInfo : public QFrame
52 {
53   Q_OBJECT;
54   
55   enum {
56     iName,
57     iObject,
58     iNodesStart,
59     iNodes,
60     iNodesEnd,
61     iElementsStart = iNodesEnd, 
62     iElements,
63     i0DStart,
64     i0D,
65     i0DEnd,
66     i1DStart       = i0DEnd,
67     i1D,
68     i1DEnd,
69     i2DStart       = i1DEnd,
70     i2D,
71     i2DTriangles,
72     i2DQuadrangles,
73     i2DPolygons,
74     i2DEnd,
75     i3DStart       = i2DEnd,
76     i3D,
77     i3DTetrahedrons,
78     i3DHexahedrons,
79     i3DPyramids,
80     i3DPrisms,
81     i3DPolyhedrons,
82     i3DEnd,
83     iElementsEnd   = i3DEnd
84   };
85
86   enum {
87     iSingle = 1,
88     iTotal  = iSingle,
89     iLinear,
90     iQuadratic
91   };
92
93   typedef QList<QWidget*> wlist;
94   typedef QVector<wlist>  iwlist;
95
96 public:
97   SMESHGUI_MeshInfo( QWidget* = 0 );
98   ~SMESHGUI_MeshInfo();
99
100   void     showInfo( SMESH::SMESH_IDSource_ptr );
101   void     clear();
102
103 private:
104   enum { Bold = 0x01, Italic = 0x02 };
105
106   QLabel*  createField();
107   QWidget* createLine();
108   void     setFontAttributes( QWidget*, int, bool = true );
109   void     setFieldsVisible( int, int, bool );
110
111 private:
112   iwlist   myWidgets;
113 };
114
115 class SMESHGUI_EXPORT SMESHGUI_ElemInfo : public QWidget
116 {
117   Q_OBJECT;
118
119 public:
120   SMESHGUI_ElemInfo( QWidget* = 0 );
121   ~SMESHGUI_ElemInfo();
122
123   void         setSource( SMESH_Actor* );
124   virtual void showInfo( long, bool );
125   virtual void clear() = 0;
126
127 protected:
128   struct XYZ
129   {
130     double myX, myY, myZ;
131     XYZ() { myX = myY = myZ = 0.0; }
132     void add( double x, double y, double z ) { myX += x; myY += y; myZ += z; }
133     void divide( double a ) { if ( a != 0.) { myX /= a; myY /= a; myZ /= a; } }
134     double x() const  { return myX; }
135     double y() const  { return myY; }
136     double z() const  { return myZ; }
137   };
138   typedef QMap< int, QList<int> > Connectivity;
139
140   Connectivity nodeConnectivity( const SMDS_MeshNode* );
141   QString      formatConnectivity( Connectivity, int );
142   XYZ          gravityCenter( const SMDS_MeshElement* );
143
144 protected:
145   SMESH_Actor* myActor;
146   long         myID;
147   int          myIsElement;
148 };
149
150 class SMESHGUI_EXPORT SMESHGUI_SimpleElemInfo : public SMESHGUI_ElemInfo
151 {
152 public:
153   SMESHGUI_SimpleElemInfo( QWidget* = 0 );
154
155   void          showInfo( long, bool );
156   void          clear();
157
158 private:
159   QTextBrowser* myInfo;
160 };
161
162 class SMESHGUI_EXPORT SMESHGUI_TreeElemInfo : public SMESHGUI_ElemInfo
163 {
164   class ItemDelegate;
165
166 public:
167   SMESHGUI_TreeElemInfo( QWidget* = 0 );
168
169   void             showInfo( long, bool );
170   void             clear();
171
172 private:
173   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 100 );
174   
175 private:
176   QTreeWidget*     myInfo;
177 };
178
179 class SMESHGUI_EXPORT SMESHGUI_MeshInfoDlg : public QDialog
180
181   Q_OBJECT;
182
183   enum { NodeMode, ElemMode };
184
185 public:
186   //! Information type
187   enum { 
188     BaseInfo,  //!< base mesh information
189     ElemInfo   //!< mesh element information
190   };
191
192   SMESHGUI_MeshInfoDlg( QWidget* = 0, int = BaseInfo );
193   ~SMESHGUI_MeshInfoDlg();
194
195   void showInfo( const Handle(SALOME_InteractiveObject)& );
196   void reject();
197
198 protected:
199   void keyPressEvent( QKeyEvent* );
200   void enterEvent( QEvent* );
201
202 private slots:
203   void help();
204   void updateSelection();
205   void updateInfo();
206   void activate();
207   void deactivate();
208   void modeChanged();
209   void idChanged();
210
211 private:
212   QTabWidget*        myTabWidget;
213   SMESHGUI_MeshInfo* myBaseInfo;
214   QButtonGroup*      myMode;
215   QLineEdit*         myID;
216   SMESHGUI_ElemInfo* myElemInfo;   
217   SMESH_Actor*       myActor;
218 };
219
220 #endif // SMESHGUI_MESHINFO_H