Salome HOME
Update copyright
[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 <QVector>
37
38 #include <SALOMEconfig.h>
39 #include CORBA_SERVER_HEADER(SMESH_Mesh)
40
41 class QButtonGroup;
42 class QLabel;
43 class QLineEdit;
44 class QPushButton;
45 class QTabWidget;
46 class QTextBrowser;
47 class QTreeWidget;
48 class QTreeWidgetItem;
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 public:
189   SMESHGUI_TreeElemInfo( QWidget* = 0 );
190
191 protected:
192   void             information( const QList<long>& );
193   void             clearInternal();
194
195 private:
196   QTreeWidgetItem* createItem( QTreeWidgetItem* = 0, int = 100 );
197   
198 private:
199   QTreeWidget*     myInfo;
200 };
201
202 class SMESHGUI_EXPORT SMESHGUI_MeshInfoDlg : public QDialog
203
204   Q_OBJECT;
205
206   enum { NodeMode, ElemMode };
207
208 public:
209   //! Information type
210   enum { 
211     BaseInfo,  //!< base mesh information
212     ElemInfo   //!< mesh element information
213   };
214
215   SMESHGUI_MeshInfoDlg( QWidget* = 0, int = BaseInfo );
216   ~SMESHGUI_MeshInfoDlg();
217
218   void showInfo( const Handle(SALOME_InteractiveObject)& );
219   void reject();
220
221 protected:
222   void keyPressEvent( QKeyEvent* );
223   void enterEvent( QEvent* );
224
225 private slots:
226   void help();
227   void updateSelection();
228   void updateInfo();
229   void activate();
230   void deactivate();
231   void modeChanged();
232   void idChanged();
233
234 private:
235   QTabWidget*        myTabWidget;
236   SMESHGUI_MeshInfo* myBaseInfo;
237   QButtonGroup*      myMode;
238   QLineEdit*         myID;
239   SMESHGUI_ElemInfo* myElemInfo;   
240   SMESH_Actor*       myActor;
241 };
242
243 #endif // SMESHGUI_MESHINFO_H