Salome HOME
c0743212fd03055802eb93adda534cce9d20e6cc
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.h
1 //  Copyright (C) 2007-2010  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 // ---
21 // File    : BLSURFPluginGUI_HypothesisCreator.h
22 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
23 //           & Aurelien ALLEAUME (DISTENE)
24 //           Size maps developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
25 // ---
26 //
27 #ifndef BLSURFPLUGINGUI_HypothesisCreator_H
28 #define BLSURFPLUGINGUI_HypothesisCreator_H
29
30 #ifdef WIN32
31   #if defined BLSURFPLUGIN_GUI_EXPORTS || defined BLSURFPluginGUI_EXPORTS
32     #define BLSURFPLUGIN_GUI_EXPORT __declspec( dllexport )
33   #else
34     #define BLSURFPLUGIN_GUI_EXPORT __declspec( dllimport )
35   #endif
36 #else
37   #define BLSURFPLUGIN_GUI_EXPORT
38 #endif
39
40 #ifdef WNT
41 // E.A. : On windows with python 2.6, there is a conflict
42 // E.A. : between pymath.h and Standard_math.h which define
43 // E.A. : some same symbols : acosh, asinh, ...
44 #include <Standard_math.hxx>
45 #include <pymath.h>
46 #endif
47
48 #include <Python.h>
49
50 #include <QItemDelegate>
51
52 #include <SMESHGUI_Hypotheses.h>
53 #include <SALOMEconfig.h>
54 #include <cstring>
55 #include <map>
56 #include <set>
57 #include <vector>
58 #include <TopAbs_ShapeEnum.hxx>
59 #include <GeomSelectionTools.h>
60 #include CORBA_SERVER_HEADER(BLSURFPlugin_Algorithm)
61
62 class QGroupBox;
63 class QComboBox;
64 class QCheckBox;
65 class QLineEdit;
66 class QTableWidget;
67 class QTreeWidget;
68 class QModelIndex;
69 class QSpinBox;
70 class QMenu;
71 class QAction;
72 class QTreeWidgetItem;
73
74 class SalomeApp_DoubleSpinBox;
75 class LightApp_SelectionMgr;
76
77 typedef struct
78 {
79   int     myTopology, myVerbosity;
80   int     myPhysicalMesh, myGeometricMesh;
81   double  myAngleMeshS, myAngleMeshC, myGradation;
82   QString myPhySize, myGeoMin, myGeoMax, myPhyMin,myPhyMax;
83   bool    myAllowQuadrangles, myDecimesh,mySmpsurface,mySmpedge,mySmppoint,myEnforcedVertex;
84   std::map<std::string, std::set<std::vector<double> > > enfVertMap;
85   QString myName;
86 } BlsurfHypothesisData;
87
88
89 /*!
90  * \brief Class for creation of BLSURF hypotheses
91 */
92 class BLSURFPLUGIN_GUI_EXPORT BLSURFPluginGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator
93 {
94   Q_OBJECT
95
96 public:
97   BLSURFPluginGUI_HypothesisCreator( const QString& );
98   virtual ~BLSURFPluginGUI_HypothesisCreator();
99
100   virtual bool        checkParams() const;
101   virtual QString     helpPage() const;
102   void                insertElementType( TopAbs_ShapeEnum );
103   static LightApp_SelectionMgr* selectionMgr();
104
105 protected:
106   virtual QFrame*     buildFrame    ();
107   virtual void        retrieveParams() const;
108   virtual QString     storeParams   () const;
109   
110   virtual QString     caption() const;
111   virtual QPixmap     icon() const;
112   virtual QString     type() const;
113
114 protected slots:
115   void                onPhysicalMeshChanged();
116   void                onGeometricMeshChanged();
117   void                onAddOption();
118   void                onDeleteOption();
119   void                onOptionChosenInPopup( QAction* );
120 //  void                onAddAttractor();
121   void                onAddMapOnSurface();
122   void                onAddMapOnEdge();
123   void                onAddMapOnPoint();
124   void                onRemoveMap();
125   void                onSetSizeMap(int,int);
126
127   void                addEnforcedVertex(std::string, std::string, double, double, double);
128   void                onAddEnforcedVertices();
129   void                onRemoveEnforcedVertex();
130   void                synchronizeCoords();
131   void                update(QTreeWidgetItem* , int );
132
133 private:
134   bool                readParamsFromHypo( BlsurfHypothesisData& ) const;
135   QString             readParamsFromWidgets( BlsurfHypothesisData& ) const;
136   bool                storeParamsToHypo( const BlsurfHypothesisData& ) const;
137   bool                sizeMapsValidation();
138   bool                sizeMapValidationFromRow(int,bool displayError = true);
139   bool                sizeMapValidationFromEntry(QString,bool displayError = true);
140   GeomSelectionTools* getGeomSelectionTool();
141
142 private:
143   QWidget*            myStdGroup;
144   QLineEdit*          myName;
145   QComboBox*          myPhysicalMesh;
146   QLineEdit*          myPhySize;
147   QLineEdit*          myPhyMin;
148   QLineEdit*          myPhyMax;
149   QComboBox*          myGeometricMesh;
150   SalomeApp_DoubleSpinBox*   myAngleMeshS;
151   SalomeApp_DoubleSpinBox*   myAngleMeshC;
152   QLineEdit*          myGeoMin;
153   QLineEdit*          myGeoMax;
154   SalomeApp_DoubleSpinBox*   myGradation;
155   QCheckBox*          myAllowQuadrangles;
156   QCheckBox*          myDecimesh;
157
158   QWidget*            myAdvGroup;
159   QComboBox*          myTopology;
160   QSpinBox*           myVerbosity;
161   QTableWidget*       myOptionTable;
162
163   QWidget             *mySmpGroup;
164   QTableWidget        *mySizeMapTable;
165   QPushButton         *addAttractorButton;
166   QPushButton         *addSurfaceButton;
167   QPushButton         *addEdgeButton;
168   QPushButton         *addPointButton;
169   QPushButton         *removeButton;
170
171   QWidget*            myEnfGroup;
172   QTreeWidget*        myEnforcedTreeWidget;
173   QLineEdit*          myXCoord;
174   QLineEdit*          myYCoord;
175   QLineEdit*          myZCoord;
176   QPushButton*        addVertexButton;
177   QPushButton*        removeVertexButton;
178
179   // map =  entry , size map
180   QMap<QString, QString>          mySMPMap;
181   QMap<QString, TopAbs_ShapeEnum> mySMPShapeTypeMap;
182   GeomSelectionTools*             GeomToolSelected;
183   LightApp_SelectionMgr*          aSel;
184
185   BLSURFPlugin::string_array_var myOptions;
186
187   PyObject *          main_mod;
188   PyObject *          main_dict;
189 };
190
191
192 class EnforcedTreeWidgetDelegate : public QItemDelegate
193 {
194     Q_OBJECT
195
196 public:
197   EnforcedTreeWidgetDelegate(QObject *parent = 0);
198
199   QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
200                         const QModelIndex &index) const;
201
202   void setEditorData(QWidget *editor, const QModelIndex &index) const;
203   void setModelData(QWidget *editor, QAbstractItemModel *model,
204                     const QModelIndex &index) const;
205
206   void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
207                     const QModelIndex &index) const;
208   
209   bool vertexExists(QAbstractItemModel *model, const QModelIndex &index, QString value) const;
210 };
211
212 #endif // BLSURFPLUGINGUI_HypothesisCreator_H