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