Salome HOME
updated copyright message
[plugins/ghs3dplugin.git] / src / GUI / GHS3DPluginGUI_HypothesisCreator.h
1 // Copyright (C) 2004-2023  CEA, EDF
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 //  GHS3DPlugin GUI: GUI for plugged-in mesher GHS3DPlugin
21 //  File   : GHS3DPluginGUI_HypothesisCreator.h
22 //  Author : Michael Zorin
23 //  Module : GHS3DPlugin
24 //
25 #ifndef GHS3DPLUGINGUI_HypothesisCreator_HeaderFile
26 #define GHS3DPLUGINGUI_HypothesisCreator_HeaderFile
27
28 #ifdef WIN32
29   #if defined GHS3DPluginGUI_EXPORTS
30     #define GHS3DPLUGINGUI_EXPORT __declspec( dllexport )
31   #else
32     #define GHS3DPLUGINGUI_EXPORT __declspec( dllimport )
33   #endif
34 #else
35   #define GHS3DPLUGINGUI_EXPORT
36 #endif
37
38 #include <SMESHGUI_Hypotheses.h>
39 #include <GeomSelectionTools.h>
40 #include <TopAbs_ShapeEnum.hxx>
41
42 #include <QItemDelegate>
43 #include <map>
44 #include <vector>
45 #include <set>
46 #include <GEOM_Client.hxx>
47 #include CORBA_SERVER_HEADER(GHS3DPlugin_Algorithm)
48 #include CORBA_SERVER_HEADER(SMESH_Gen)
49 #include CORBA_SERVER_HEADER(SMESH_Mesh)
50
51 class QWidget;
52 class QButtonGroup;
53 class QComboBox;
54 class QCheckBox;
55 class QLineEdit;
56 class QSpinBox;
57 class QTableWidget;
58 class QTableWidgetItem;
59 class QHeaderView;
60 class QGroupBox;
61
62 class GHS3DPluginGUI_AdvWidget;
63 class LightApp_SelectionMgr;
64 class SMESHGUI_SpinBox;
65 class SUIT_SelectionFilter;
66 class SalomeApp_IntSpinBox;
67 class StdMeshersGUI_ObjectReferenceParamWdg;
68
69 class QTEnfVertex
70 {
71
72 public:
73   QTEnfVertex(double size, double x=0., double y=0., double z=0., QString name="", QString geomEntry="", QString groupName="", bool isCompound = false);
74
75 private:
76   bool operator == (const QTEnfVertex* other) const {
77     if (other) {
78       if (this->coords.size() && other->coords.size())
79         return (this->coords == other->coords);
80       else
81         return (this->geomEntry == other->geomEntry);
82     }
83   }
84   
85   QString name;
86   QString geomEntry;
87   bool isCompound;
88   QString groupName;
89   double size;
90   std::vector<double> coords;
91 };
92
93 typedef QList< QTEnfVertex* > QEnfVertexList;
94
95 // Enforced vertex
96 struct TEnfVertex{
97   std::string name;
98   std::string geomEntry;
99   bool isCompound;
100   std::vector<double> coords;
101   std::string groupName;
102   double size;
103 };
104
105 struct CompareEnfVertices
106 {
107   bool operator () (const TEnfVertex* e1, const TEnfVertex* e2) const {
108     if (e1 && e2) {
109       if (e1->coords.size() && e2->coords.size())
110         return (e1->coords < e2->coords);
111       else
112         return (e1->geomEntry < e2->geomEntry);
113     }
114     return false;
115   }
116 };
117
118 // List of enforced vertices
119 typedef std::set< TEnfVertex*, CompareEnfVertices > TEnfVertexList;
120
121 // Enforced mesh
122 struct TEnfMesh{
123   std::string name;
124   std::string entry;
125   int elementType;
126   std::string groupName;
127 };
128
129 struct CompareEnfMeshes
130 {
131   bool operator () (const TEnfMesh* e1, const TEnfMesh* e2) const {
132     if (e1 && e2) {
133       if (e1->entry == e2->entry)
134         return (e1->elementType < e2->elementType);
135       else
136         return (e1->entry < e2->entry);
137     }
138     else
139       return false;
140   }
141 };
142 // List of enforced meshes
143 typedef std::set< TEnfMesh*, CompareEnfMeshes > TEnfMeshList;
144
145 typedef struct
146 {
147   int     myOptimizationLevel;
148   double  myMinSize, myMaxSize, myMinSizeDefault, myMaxSizeDefault;
149   double  myGradation;
150   int     myNbProximityLayers;
151   bool    myUseMinSize, myUseMaxSize, myUseGradation, myUseProximity;
152   bool    myToMeshHoles, myToMakeGroupsOfDomains;
153   bool    myToCreateNewNodes,myBoundaryRecovery,myFEMCorrection,myRemoveInitialCentralPoint,
154           myKeepFiles,myLogInStandardOutput, myRemoveLogOnSuccess;
155   float   myInitialMemory, myMaximumMemory;
156   QString myName,myWorkingDir;
157   short   myVerboseLevel;
158   TEnfVertexList myEnforcedVertices;
159   TEnfMeshList myEnforcedMeshes;
160   short   myAlgorithm, myNumOfThreads, myPthreadMode, myParallelMode;
161   bool    myUseNumOfThreads;
162
163   int myOptimization, mySplitOverConstrained, myPThreadsMode, myNumberOfThreads;
164   bool mySmoothOffSlivers;
165
166 } GHS3DHypothesisData;
167
168 /*!
169   \brief Class for creation of GHS3D2D and GHS3D3D hypotheses
170 */
171 class GHS3DPLUGINGUI_EXPORT GHS3DPluginGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator
172 {
173   Q_OBJECT
174
175 public:
176   GHS3DPluginGUI_HypothesisCreator( const QString& );
177   virtual ~GHS3DPluginGUI_HypothesisCreator();
178
179   virtual bool     checkParams(QString& msg) const;
180   virtual QString  helpPage() const;
181
182 protected:
183   virtual QFrame*  buildFrame    ();
184   virtual void     retrieveParams() const;
185   virtual QString  storeParams   () const;
186
187   virtual QString  caption() const;
188   virtual QPixmap  icon() const;
189   virtual QString  type() const;
190
191 protected slots:
192   void                onAddOption();
193   void                onToMeshHoles(bool);
194   void                onDirBtnClicked();
195   void                updateWidgets();
196   
197   void                addEnforcedVertex(double x=0, double y=0, double z=0, double size = 0,
198                                         std::string vertexName = "", std::string geomEntry = "", std::string groupName = "",
199                                         bool isCompound = false);
200   void                onAddEnforcedVertex();
201   void                onRemoveEnforcedVertex();
202   void                synchronizeCoords();
203   void                updateEnforcedVertexValues(QTableWidgetItem* );
204   void                onSelectEnforcedVertex();
205   void                clearEnforcedVertexWidgets();
206   void                checkVertexIsDefined();
207   void                clearEnfVertexSelection();
208   
209   void                addEnforcedMesh(std::string name, std::string entry, int elementType, std::string groupName = "");
210   void                onAddEnforcedMesh();
211   void                onRemoveEnforcedMesh();
212   //void                synchronizeEnforcedMesh();
213   void                checkEnfMeshIsDefined();
214   void                onRadioButtonSelect();
215   void                onNumOfThreadsCheck();
216   
217 signals:
218   void                vertexDefined(bool);
219   void                enfMeshDefined(bool);
220   
221 private:
222   bool                readParamsFromHypo( GHS3DHypothesisData& ) const;
223   bool                readParamsFromWidgets( GHS3DHypothesisData& ) const;
224   bool                storeParamsToHypo( const GHS3DHypothesisData& ) const;
225   GeomSelectionTools* getGeomSelectionTool();
226   GEOM::GEOM_Gen_var  getGeomEngine();
227   bool                isOptimization() const;
228
229 private:
230   QWidget*              myStdGroup;
231   QLineEdit*            myName;
232   // main
233   QComboBox*            myOptimizationLevelCombo;
234   QCheckBox*            myMinSizeCheck;
235   QCheckBox*            myMaxSizeCheck;
236   SMESHGUI_SpinBox*     myMinSizeSpin;
237   SMESHGUI_SpinBox*     myMaxSizeSpin;
238   QCheckBox*            myNumOfThreadsCheck;
239   SalomeApp_IntSpinBox* myNumOfThreadsSpin;
240   mutable double        myMinSizeDefault, myMaxSizeDefault;
241   // proximity
242   QCheckBox*            myGradationCheck;
243   SMESHGUI_SpinBox*     myGradationSpin;
244   QGroupBox*            myUseProximityGroup;
245   SalomeApp_IntSpinBox* myNbProximityLayers;
246   // other
247   QCheckBox*            myToMakeGroupsOfDomains;
248   QCheckBox*            myToMeshHolesCheck;
249
250   QComboBox*            myOptimizationCombo;
251   QComboBox*            mySplitOverConstrainedCombo;
252   QComboBox*            myPThreadsModeCombo;
253   SalomeApp_IntSpinBox* myNumberOfThreadsSpin;
254   QCheckBox*            mySmoothOffSliversCheck;
255   QCheckBox*            myCreateNewNodesCheck;
256   QComboBox*            myPthreadMode;
257   QComboBox*            myParallelMode;
258   QButtonGroup*         myRadioBottomGroup;
259
260   QWidget*                  myAdvGroup;
261   GHS3DPluginGUI_AdvWidget* myAdvWidget;
262   mutable GHS3DPlugin::string_array_var myOptions, myCustomOptions;
263
264   
265   QWidget*              myEnfGroup;
266   QPixmap               iconVertex, iconCompound;
267   StdMeshersGUI_ObjectReferenceParamWdg *myEnfVertexWdg;
268   GEOM::GEOM_Object_var myEnfVertex;
269   QTableWidget*         myEnforcedTableWidget;
270   SMESHGUI_SpinBox*     myXCoord;
271   SMESHGUI_SpinBox*     myYCoord;
272   SMESHGUI_SpinBox*     myZCoord;
273   SMESHGUI_SpinBox*     mySizeValue;
274   QLineEdit*            myGroupName;
275   QPushButton*          addVertexButton;
276   QPushButton*          removeVertexButton;
277   
278   QWidget*              myEnfMeshGroup;
279   StdMeshersGUI_ObjectReferenceParamWdg *myEnfMeshWdg;
280   QComboBox*            myEnfMeshConstraint;
281   QStringList           myEnfMeshConstraintLabels;
282   QTableWidget*         myEnforcedMeshTableWidget;
283   QLineEdit*            myMeshGroupName;
284   QPushButton*          addEnfMeshButton;
285   QPushButton*          removeEnfMeshButton;
286   
287   GeomSelectionTools*     GeomToolSelected;
288 };
289
290 class EnforcedVertexTableWidgetDelegate : public QItemDelegate
291 {
292     Q_OBJECT
293
294 public:
295   EnforcedVertexTableWidgetDelegate(QObject *parent = 0);
296
297   QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
298                       const QModelIndex &index) const;
299
300   void setEditorData(QWidget *editor, const QModelIndex &index) const;
301   void setModelData(QWidget *editor, QAbstractItemModel *model,
302                   const QModelIndex &index) const;
303
304   void updateEditorGeometry(QWidget *editor,
305       const QStyleOptionViewItem &option, const QModelIndex &index) const;
306
307   bool vertexExists(QAbstractItemModel *model, const QModelIndex &index, QString value) const;
308 };
309
310 class EnforcedMeshTableWidgetDelegate : public QItemDelegate
311 {
312     Q_OBJECT
313
314 public:
315   EnforcedMeshTableWidgetDelegate(QObject *parent = 0);
316
317   QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
318                       const QModelIndex &index) const;
319
320   void setEditorData(QWidget *editor, const QModelIndex &index) const;
321   void setModelData(QWidget *editor, QAbstractItemModel *model,
322                   const QModelIndex &index) const;
323
324   void updateEditorGeometry(QWidget *editor,
325       const QStyleOptionViewItem &option, const QModelIndex &index) const;
326 };
327
328 #endif