Salome HOME
Show free RAM while computing the mesh
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ComputeDlg.h
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File   : SMESHGUI_ComputeDlg.h
21 // Author : Edward AGAPOV, Open CASCADE S.A.S.
22 //
23 #ifndef SMESHGUI_COMPUTEDLG_H
24 #define SMESHGUI_COMPUTEDLG_H
25
26 // SMESH includes
27 #include "SMESH_SMESHGUI.hxx"
28
29 #include "SMESHGUI_Dialog.h"
30 #include "SMESHGUI_Operation.h"
31
32 // SALOME GUI includes
33 #include <SALOME_InteractiveObject.hxx>
34
35 // Qt includes
36 #include <QMap>
37 #include <QList>
38 #include <QPointer>
39 #include <QGroupBox>
40 #include <QThread>
41
42 // IDL includes
43 #include <SALOMEconfig.h>
44 #include CORBA_SERVER_HEADER(SMESH_Gen)
45 #include CORBA_SERVER_HEADER(SMESH_Mesh)
46
47 class QFrame;
48 class QPushButton;
49 class QTableWidget;
50 class QLabel;
51 class QtxComboBox;
52 class SMESHGUI_ComputeDlg;
53 class SMESHGUI_MeshInfosBox;
54 class SMESHGUI_PrecomputeDlg;
55 class SMESHGUI_MeshEditPreview;
56
57 namespace SMESH
58 {
59   class TShapeDisplayer;
60 }
61
62 /*!
63  * \brief Base operation to compute a mesh and show computation errors
64  */
65 class SMESHGUI_EXPORT SMESHGUI_BaseComputeOp: public SMESHGUI_Operation
66 {
67   Q_OBJECT
68
69 public:
70   SMESHGUI_BaseComputeOp();
71   virtual ~SMESHGUI_BaseComputeOp();
72
73   SMESH::SMESH_Mesh_ptr          getMesh();
74
75 protected:
76   virtual void                   startOperation();
77   virtual void                   stopOperation();
78
79   SMESHGUI_ComputeDlg*           computeDlg() const;
80   void                           computeMesh();
81   void                           showComputeResult( const bool,
82                                                     const bool,
83                                                     SMESH::compute_error_array_var&,
84                                                     const bool,
85                                                     const QString& );
86   SMESHGUI_ComputeDlg*           evaluateDlg() const;
87   void                           evaluateMesh();
88   void                           showEvaluateResult(const SMESH::long_array& theRes,
89                                                     const bool,
90                                                     const bool,
91                                                     SMESH::compute_error_array_var&,
92                                                     const bool,
93                                                     const QString&);
94
95   virtual bool                   isValid( SUIT_Operation* theOp ) const;
96     
97 protected slots:
98   virtual bool                   onApply();
99   void                           onPreviewShape();
100   void                           onPublishShape();
101   void                           onShowBadMesh();
102   void                           onGroupOfBadMesh();
103   void                           currentCellChanged();
104
105 private:
106   QTableWidget*                  table();
107
108 private:
109   QPointer<SMESHGUI_ComputeDlg>  myCompDlg;
110
111 protected:
112   SMESH::SMESH_Mesh_var            myMesh;
113   GEOM::GEOM_Object_var            myMainShape;
114   SMESH::TShapeDisplayer*          myTShapeDisplayer;
115   SMESHGUI_MeshEditPreview*        myBadMeshDisplayer;
116   Handle(SALOME_InteractiveObject) myIObject;
117 };
118
119 /*!
120  * \brief Operation to compute a mesh and show computation errors
121  */
122 class SMESHGUI_EXPORT SMESHGUI_ComputeOp: public SMESHGUI_BaseComputeOp
123 {
124   Q_OBJECT
125
126 public:
127   SMESHGUI_ComputeOp();
128   virtual ~SMESHGUI_ComputeOp();
129
130   virtual LightApp_Dialog*       dlg() const;
131
132 protected:
133   virtual void                   startOperation();
134
135 protected slots:
136 };
137
138 class SMESHGUI_MeshOrderMgr;
139
140 /*!
141  * \brief Operation to preview and compute a mesh and show computation errors
142  */
143 class SMESHGUI_EXPORT SMESHGUI_PrecomputeOp: public SMESHGUI_BaseComputeOp
144 {
145   Q_OBJECT
146
147 public:
148   SMESHGUI_PrecomputeOp();
149   virtual ~SMESHGUI_PrecomputeOp();
150
151   virtual LightApp_Dialog*       dlg() const;
152
153   /**
154    * \brief returns map of assigned algorithms modes
155    */
156   static void                    getAssignedAlgos(_PTR(SObject) theMesh,
157                                                   QMap<int,int>& theModeMap);
158
159 protected:
160   virtual void                   startOperation();
161   virtual void                   stopOperation();
162   virtual void                   resumeOperation();
163
164   virtual void                   initDialog();
165
166 protected slots:
167   virtual void                   onCancel();
168
169 private slots:
170   void                           onPreview();
171   void                           onCompute();
172
173 private:
174   //! private fields
175   QMap< int, int >               myMapShapeId;
176   QPointer<LightApp_Dialog>      myActiveDlg;
177   QPointer<SMESHGUI_PrecomputeDlg> myDlg;
178   SMESHGUI_MeshEditPreview*      myPreviewDisplayer;
179   //! fields for mesh order
180   typedef QList<int>             TListOfInt;
181   typedef QList<TListOfInt>      TListOfListOfInt;
182   TListOfListOfInt               myPrevOrder;
183   SMESHGUI_MeshOrderMgr*         myOrderMgr;
184 };
185
186 /*!
187  * \brief Operation to evaluate a mesh and show result
188  */
189 class SMESHGUI_EXPORT SMESHGUI_EvaluateOp: public SMESHGUI_BaseComputeOp
190 {
191   Q_OBJECT
192
193 public:
194   SMESHGUI_EvaluateOp();
195   virtual ~SMESHGUI_EvaluateOp();
196
197   virtual LightApp_Dialog*       dlg() const;
198
199 protected:
200   virtual void                   startOperation();
201
202 protected slots:
203 };
204
205 /*!
206  * \brief Dialog to compute a mesh and show computation errors
207  */
208
209 class SMESHGUI_EXPORT SMESHGUI_ComputeDlg : public SMESHGUI_Dialog
210 {
211   Q_OBJECT
212
213 public:
214   SMESHGUI_ComputeDlg( QWidget*, bool );
215   virtual ~SMESHGUI_ComputeDlg();
216
217 protected:
218   QFrame*                      createMainFrame( QWidget*, bool );
219
220   QLabel*                      myMeshName;
221   QGroupBox*                   myMemoryLackGroup;
222   QGroupBox*                   myCompErrorGroup;
223   QGroupBox*                   myHypErrorGroup;
224   QLabel*                      myHypErrorLabel;
225   QLabel*                      myWarningLabel;
226   QTableWidget*                myTable;
227   QPushButton*                 myShowBtn;
228   QPushButton*                 myPublishBtn;
229   QPushButton*                 myBadMeshBtn;
230   QPushButton*                 myBadMeshToGroupBtn;
231
232   SMESHGUI_MeshInfosBox*       myBriefInfo;
233   SMESHGUI_MeshInfosBox*       myFullInfo;
234
235   friend class SMESHGUI_BaseComputeOp;
236   friend class SMESHGUI_PrecomputeOp;
237 };
238
239 class SMESHGUI_MeshOrderBox;
240
241 /*!
242  * \brief Dialog to preview and compute a mesh and show computation errors
243  */
244
245 class SMESHGUI_EXPORT SMESHGUI_PrecomputeDlg : public SMESHGUI_Dialog
246 {
247   Q_OBJECT
248
249 public:
250   SMESHGUI_PrecomputeDlg( QWidget* );
251   virtual ~SMESHGUI_PrecomputeDlg();
252   
253   void                         setPreviewModes( const QList<int>& );
254   int                          getPreviewMode() const;
255   
256   SMESHGUI_MeshOrderBox*       getMeshOrderBox() const;
257
258 signals:
259   void                         preview();
260
261 private:
262   SMESHGUI_MeshOrderBox*       myOrderBox;
263   QPushButton*                 myPreviewBtn;
264   QtxComboBox*                 myPreviewMode;
265 };
266
267 /*!
268  * \brief Thread to launch computation
269  */
270
271 class SMESHGUI_EXPORT SMESHGUI_ComputeDlg_QThread : public QThread
272 {
273   Q_OBJECT
274     
275 public:
276   SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var  gen,
277                               SMESH::SMESH_Mesh_var mesh,
278                               GEOM::GEOM_Object_var mainShape);
279   bool                   result();
280   void                   cancel();
281   SMESH::SMESH_Mesh_var& getMesh() { return myMesh; }
282
283 protected:
284   void run();
285   
286 private:
287   SMESH::SMESH_Gen_var  myGen;
288   SMESH::SMESH_Mesh_var myMesh;
289   GEOM::GEOM_Object_var myMainShape;
290   bool                  myResult;
291 };
292
293 /*!
294  * \brief Dialog to display Cancel button
295  */
296
297 class SMESHGUI_EXPORT SMESHGUI_ComputeDlg_QThreadQDialog : public QDialog
298 {
299   Q_OBJECT
300     
301 public:
302   SMESHGUI_ComputeDlg_QThreadQDialog(QWidget *             parent,
303                                      SMESH::SMESH_Gen_var  gen,
304                                      SMESH::SMESH_Mesh_var mesh,
305                                      GEOM::GEOM_Object_var mainShape);
306   bool result();
307   
308 protected:
309   void timerEvent(QTimerEvent *timer);
310   void closeEvent(QCloseEvent *event);
311   
312 private slots:
313   void onCancel();
314   
315 private:
316   SMESHGUI_ComputeDlg_QThread qthread;
317   QPushButton *               cancelButton;
318   QLabel *                    nbNodesLabel;
319   QLabel *                    nbElemsLabel;
320   QLabel *                    freeRAMLabel;
321 };
322
323 #endif // SMESHGUI_COMPUTEDLG_H