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