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