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