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