Salome HOME
Merge branch 'occ/24009'
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MgAdaptDlg.h
1 // Copyright (C) 2020-2021  CEA/DEN, EDF R&D
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, or (at your option) any later version.
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 #ifndef MG_ADAPTGUI_HXX
21 #define MG_ADAPTGUI_HXX
22
23 // Qt includes
24 #include <QDialog>
25 #include <QTreeWidget>
26 #include <QItemDelegate>
27
28 #include <map>
29
30 #include <SALOMEconfig.h>
31 #include CORBA_SERVER_HEADER(MG_ADAPT)
32 #include <SALOME_GenericObj_wrap.hxx>
33
34 class SalomeApp_Module;
35
36 class QButtonGroup;
37 class QLineEdit;
38 class QGroupBox;
39 class QRadioButton;
40 class QLabel;
41 class QCheckBox;
42 class QGridLayout;
43 class QTabWidget;
44 class QDoubleSpinBox;
45 class QSpacerItem;
46 class QSpinBox;
47 class QTreeWidgetItem;
48 class QHBoxLayout;
49 class QComboBox;
50
51 class SMESHGUI_MgAdaptArguments;
52 class MgAdaptAdvWidgetTreeWidget;
53 class MgAdaptAdvWidget;
54
55 enum ADAPTATION_MODE{
56   SURFACE,
57   VOLUME,
58   BOTH
59 };
60
61 //=================================================================================
62 // class    : SMESHGUI_MgAdaptDlg
63 // purpose  :
64 //=================================================================================
65 class  SMESHGUI_MgAdaptDlg : public QDialog
66 {
67   Q_OBJECT
68 public:
69   //! Property type
70   enum Mode { Arguments, AdvancedOptions};
71   SMESHGUI_MgAdaptDlg( SalomeApp_Module*, SMESH::MG_ADAPT_ptr, QWidget* parent= 0,bool isCreation = true );
72   ~SMESHGUI_MgAdaptDlg();
73
74   void buildDlg();
75   void reject();
76   bool checkParams(QString& msg) ;
77   //~void setModel(MgAdapt*);
78   SMESH::MG_ADAPT_ptr getModel() const;
79
80 public slots:
81
82 protected slots:
83   virtual bool PushOnApply();
84
85 private slots:
86   virtual void PushOnHelp();
87   virtual void PushOnOK();
88
89 protected :
90
91   SMESHGUI_MgAdaptArguments* myArgs;
92   MgAdaptAdvWidget*          myAdvOpt;
93
94   bool readParamsFromHypo( ) const ;
95   bool readParamsFromWidgets( ) ;
96   bool storeParamsToHypo( const SMESH::MgAdaptHypothesisData & ) const;
97
98 private:
99
100   SalomeApp_Module*              mySMESHGUI;
101   QTabWidget*                    myTabWidget;
102
103   SMESH::MgAdaptHypothesisData_var           myData;
104   SALOME::GenericObj_wrap< SMESH::MG_ADAPT > model;
105
106 };
107
108 class  SMESHGUI_MgAdaptArguments : public QWidget
109 {
110   Q_OBJECT
111 public:
112   //! Property type
113   enum Mode { Mesh, Browser};
114   enum SIZEMAP { Local, Background, Constant};
115   SMESHGUI_MgAdaptArguments( QWidget* parent);
116   ~SMESHGUI_MgAdaptArguments();
117   void setMode( const Mode, const SIZEMAP );
118
119   QString myFileInDir;
120   QString myFileOutDir;
121   QString myFileSizeMapDir;
122   QGroupBox*    aMeshIn ;
123   QRadioButton* aMedfile;
124   QRadioButton* aBrowser ;
125   QLineEdit* aBrowserObject;
126   QPushButton* selectMedFilebutton ;
127   QSpacerItem* hspacer;
128   QLineEdit* selectMedFileLineEdit ;
129   QButtonGroup* meshInGroup ;
130   QGridLayout* meshIn ;
131
132   QGroupBox*    aMeshOut ;
133   QLabel* meshName;
134   QLineEdit* meshNameLineEdit;
135   QSpacerItem* secondHspacer;
136   QCheckBox* medFileCheckBox;
137   QPushButton* selectOutMedFilebutton;
138   QLineEdit* selectOutMedFileLineEdit;
139   QSpacerItem* thirdHspacer;
140   QCheckBox* publishOut;
141   QGridLayout* meshOut ;
142
143   QGroupBox*    sizeMapDefinition ;
144   QRadioButton* localButton;
145   QRadioButton* backgroundButton ;
146   QRadioButton* constantButton ;
147   QLabel* medFileBackground;
148   QPushButton* selectMedFileBackgroundbutton;
149   QLineEdit* selectMedFileBackgroundLineEdit;
150   QLabel* valueLabel;
151   QDoubleSpinBox* dvalue;
152   QButtonGroup* sizeMapDefGroup ;
153   QGridLayout* sizeMapDefGroupLayout;
154
155
156   QGroupBox* sizeMapField;
157   QLabel* fieldName;
158   QComboBox* fieldNameCmb;
159   QRadioButton* noTimeStep;
160   QRadioButton* lastTimeStep ;
161   QRadioButton* chosenTimeStep;
162   QLabel* timeStepLabel;
163   QSpinBox* timeStep;
164   QLabel* rankLabel;
165   QSpinBox* rankSpinBox;
166   QButtonGroup* timeStepGroup;
167   QGridLayout* sizeMapFieldGroupLayout;
168
169 signals:
170   void updateSelection();
171   void toExportMED(const char *);
172   void meshDimSignal(ADAPTATION_MODE aMode);
173 public slots:
174
175 protected slots:
176
177 private slots:
178   void modeChanged( int);
179   void sizeMapDefChanged(int);
180   void timeStepGroupChanged(int timeStepType, bool disableOther = false, int vmax = 0);
181   void onSelectMedFilebuttonClicked();
182   void clear();
183   void onMedFileCheckBox(int);
184   void onPublishOut(int);
185   void onSelectOutMedFilebutton();
186   void onSelectMedFileBackgroundbutton();
187   void onLocalSelected(QString);
188   void onNoTimeStep(bool disableOther = false);
189   void onLastTimeStep(bool disableOther = false);
190   void onChosenTimeStep(bool disableOther = false, int vmax = 0);
191   void visibleTimeStepRankLabel(bool visible);
192   void valueAdaptation ();
193
194 private:
195
196   QString getMedFileName(bool avertir);
197   int meshDim;
198   int meshDimBG;
199   std::map<QString, int> myFieldList;
200
201 };
202 enum {
203   OPTION_ID_COLUMN = 0,
204   OPTION_TYPE_COLUMN,
205   OPTION_NAME_COLUMN = 0,
206   OPTION_VALUE_COLUMN,
207   NB_COLUMNS,
208 };
209
210 //////////////////////////////////////////
211 // MgAdaptAdvWidget
212 //////////////////////////////////////////
213 class  MgAdaptAdvWidget : public QWidget
214 {
215   Q_OBJECT
216
217 public:
218   MgAdaptAdvWidget( QWidget* = 0, std::vector <std::string> * = nullptr, Qt::WindowFlags = 0 );
219   ~MgAdaptAdvWidget();
220   std::vector < std::string > *myOptions;
221   QGridLayout                 *gridLayout_4;
222   MgAdaptAdvWidgetTreeWidget  *myOptionTable;
223   QPushButton                 *addBtn;
224   QSpacerItem                 *horizontalSpacer;
225   QGroupBox                   *logGroupBox;
226   QGridLayout                 *gridLayout_2;
227   QGridLayout                 *gridLayout;
228   QLabel                      *workingDirectoryLabel;
229   QLineEdit                   *workingDirectoryLineEdit;
230   QPushButton                 *workingDirectoryPushButton;
231   QLabel                      *verboseLevelLabel;
232   QSpinBox                    *verboseLevelSpin;
233   QHBoxLayout                 *horizontalLayout;
234   QCheckBox                   *logInFileCheck;
235   QCheckBox                   *removeLogOnSuccessCheck;
236   QCheckBox                   *keepWorkingFilesCheck;
237
238   void AddOption( const char* name_value_type, bool isCustom = false );
239   void GetOptionAndValue( QTreeWidgetItem * tblRow, QString& option, QString& value, bool& dflt );
240   void setupWidget();
241
242 public slots:
243   void                onAddOption();
244   void itemChanged(QTreeWidgetItem * tblRow, int column);
245   void onMeshDimChanged(ADAPTATION_MODE aMode);
246 private slots:
247   void _onWorkingDirectoryPushButton();
248 private:
249   void setOptionValue(QString& option, QString& value);
250   std::map<QString, QTreeWidgetItem *> optionTreeWidgetItem;
251
252   QTreeWidgetItem* getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom);
253
254 };
255
256 enum { EDITABLE_ROLE = Qt::UserRole + 1, PARAM_NAME,
257        NAME_COL = 0, VALUE_COL
258      };
259
260 class  ItemDelegate: public QItemDelegate
261 {
262 public:
263
264   ItemDelegate(QObject* parent=0): QItemDelegate(parent) {}
265   QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const;
266 };
267
268 class  MgAdaptAdvWidgetTreeWidget : public QTreeWidget
269 {
270   Q_OBJECT
271 public:
272   MgAdaptAdvWidgetTreeWidget( QWidget* );
273
274 protected:
275   QModelIndex moveCursor( CursorAction, Qt::KeyboardModifiers );
276   void keyPressEvent( QKeyEvent* );
277 };
278
279 #endif // MG_ADAPTGUI_HXX