Salome HOME
Update copyright
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.h
1 // Copyright (C) 2007-2011  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 "StdMeshersGUI_ObjectReferenceParamWdg.h"
54 #include <SALOMEconfig.h>
55 #include <cstring>
56 #include <map>
57 #include <set>
58 #include <vector>
59 #include <TopAbs_ShapeEnum.hxx>
60 #include <GeomSelectionTools.h>
61 #include <GEOM_Client.hxx>
62 #include CORBA_SERVER_HEADER(BLSURFPlugin_Algorithm)
63
64 class QGroupBox;
65 class QComboBox;
66 class QCheckBox;
67 class QLineEdit;
68 class QTableWidget;
69 class QTreeWidget;
70 class QModelIndex;
71 class QSpinBox;
72 class QDoubleSpinBox;
73 class QMenu;
74 class QAction;
75 class QTreeWidgetItem;
76 class QTableWidgetItem;
77 class QObject;
78
79 class SMESHGUI_SpinBox;
80 class LightApp_SelectionMgr;
81 // class DlgBlSurfHyp_Enforced;
82
83 // Name
84 typedef std::string TEnfName;
85 // Entry
86 typedef std::string TEntry;
87 // List of entries
88 typedef std::set<TEntry> TEntryList;
89 // Enforced vertex = 3 coordinates
90 typedef std::vector<double> TEnfVertexCoords;
91 // List of enforced vertices
92 typedef std::set< TEnfVertexCoords > TEnfVertexCoordsList;
93 // Enforced vertex
94 struct TEnfVertex{
95   TEnfName name;
96   TEntry geomEntry;
97   TEnfVertexCoords coords;
98   TEnfName grpName;
99 };
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 // Map Face Entry / List of enforced vertices
119 typedef std::map< TEntry, TEnfVertexList > TFaceEntryEnfVertexListMap;
120
121 typedef struct
122 {
123   int     myTopology, myVerbosity;
124   int     myPhysicalMesh, myGeometricMesh;
125   double  myAngleMeshS, myAngleMeshC, myGradation;
126   double  myPhySize, myGeoMin, myGeoMax, myPhyMin,myPhyMax;
127   bool    myAllowQuadrangles, myDecimesh,mySmpsurface,mySmpedge,mySmppoint,myEnforcedVertex;
128   TEnfVertexList enfVertexList;
129   TFaceEntryEnfVertexListMap faceEntryEnfVertexListMap;
130   /* TODO GROUPS
131   TGroupNameEnfVertexListMap groupNameEnfVertexListMap;
132   */
133   QString myName;
134 } BlsurfHypothesisData;
135
136
137
138 // class BLSURFPluginGUI_ObjectReferenceParamWdg: public StdMeshersGUI_ObjectReferenceParamWdg
139 // {
140 //   Q_OBJECT
141 // public:
142 //   BLSURFPluginGUI_ObjectReferenceParamWdg( SUIT_SelectionFilter* filter, 
143 //                                          QWidget*              parent,
144 //                                          bool                  multiSelection=false);
145 //   BLSURFPluginGUI_ObjectReferenceParamWdg( MeshObjectType objType,
146 //                                          QWidget*       parent,
147 //                                          bool           multiSelection=false);
148 //   ~BLSURFPluginGUI_ObjectReferenceParamWdg();
149 // 
150 // private:
151 //   void init();
152 //   
153 // public slots:
154 //   void activateSelectionOnly();
155 //   void deactivateSelectionOnly();
156 //   void setActivationStatus(bool status);
157 // };
158
159 /*!
160  * \brief Class for creation of BLSURF hypotheses
161 */
162 class BLSURFPLUGIN_GUI_EXPORT BLSURFPluginGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator
163 {
164   Q_OBJECT
165
166 public:
167   BLSURFPluginGUI_HypothesisCreator( const QString& );
168   virtual ~BLSURFPluginGUI_HypothesisCreator();
169
170   virtual bool        checkParams() const;
171   virtual QString     helpPage() const;
172   //void                insertElementType( TopAbs_ShapeEnum );
173   void                insertElement( GEOM::GEOM_Object_var, bool modify = false );
174   void                insertAttractor(GEOM::GEOM_Object_var, GEOM::GEOM_Object_var, bool modify = false);
175   int                 findRowFromEntry(QString entry);
176   CORBA::Object_var   entryToObject(QString entry);
177   static LightApp_SelectionMgr* selectionMgr();
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                onPhysicalMeshChanged();
190   void                onGeometricMeshChanged();
191   void                onAddOption();
192   void                onDeleteOption();
193   void                onOptionChosenInPopup( QAction* );
194   void                onMapGeomContentModified();
195   void                onSmpItemClicked( QTreeWidgetItem *, int );
196   void                onSmpTabChanged(int);
197   void                onAttractorClicked(int);
198   void                onConstSizeClicked(int);
199   void                onAddMap();
200   void                onRemoveMap();
201   void                onModifyMap();
202   void                onSetSizeMap(QTreeWidgetItem *, int);
203
204   void                addEnforcedVertex(std::string theFaceEntry, std::string theFaceName, double x=0, double y=0, double z=0, 
205                                         std::string vertexName = "", std::string geomEntry = "", std::string groupName = "");
206   void                onAddEnforcedVertices();
207   void                onRemoveEnforcedVertex();
208   void                synchronizeCoords();
209   void                updateEnforcedVertexValues(QTreeWidgetItem* , int );
210   void                onSelectEnforcedVertex();
211   void                deactivateSelection(QWidget*, QWidget*);
212   void                clearEnforcedVertexWidgets();
213
214 private:
215   bool                readParamsFromHypo( BlsurfHypothesisData& ) const;
216   QString             readParamsFromWidgets( BlsurfHypothesisData& ) const;
217   bool                storeParamsToHypo( const BlsurfHypothesisData& ) const;
218   bool                sizeMapsValidation();
219   bool                sizeMapValidationFromRow(int,bool displayError = true);
220   bool                sizeMapValidationFromEntry(QString,bool displayError = true);
221   GeomSelectionTools* getGeomSelectionTool();
222   GEOM::GEOM_Gen_var  getGeomEngine();
223
224 private:
225   QWidget*            myStdGroup;
226   QLineEdit*          myName;
227   QComboBox*          myPhysicalMesh;
228   SMESHGUI_SpinBox*   myPhySize;
229   SMESHGUI_SpinBox*   myPhyMin;
230   SMESHGUI_SpinBox*   myPhyMax;
231   QComboBox*          myGeometricMesh;
232   SMESHGUI_SpinBox*   myAngleMeshS;
233   SMESHGUI_SpinBox*   myAngleMeshC;
234   SMESHGUI_SpinBox*   myGeoMin;
235   SMESHGUI_SpinBox*   myGeoMax;
236   SMESHGUI_SpinBox*   myGradation;
237   QCheckBox*          myAllowQuadrangles;
238   QCheckBox*          myDecimesh;
239
240   QWidget*            myAdvGroup;
241   QComboBox*          myTopology;
242   QSpinBox*           myVerbosity;
243   QTableWidget*       myOptionTable;
244
245   // Sizemap widgets
246   QWidget             *mySmpGroup;
247   QTreeWidget         *mySizeMapTable;
248   QPushButton         *addMapButton;
249   QPushButton         *removeMapButton;
250   QPushButton         *modifyMapButton;
251   QTabWidget          *smpTab; 
252   QWidget             *myAttractorGroup;
253   QWidget             *mySmpStdGroup;
254   QCheckBox           *myAttractorCheck;
255   QCheckBox           *myConstSizeCheck;
256   QGroupBox           *myDistanceGroup;
257 //   QGroupBox           *myParamsGroup;
258 //   QWidget             *myParamsGroup;
259   SMESHGUI_SpinBox    *myAttSizeSpin;
260   SMESHGUI_SpinBox    *myAttDistSpin;
261   SMESHGUI_SpinBox    *myAttDistSpin2;
262   SMESHGUI_SpinBox    *mySmpSizeSpin;
263   QLabel              *myAttDistLabel;
264   QLabel              *myAttDistLabel2;
265   QLabel              *myAttSizeLabel;
266   // Selection widgets for size maps
267   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg1;
268   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg2;
269   StdMeshersGUI_ObjectReferenceParamWdg *myAttSelWdg;
270   StdMeshersGUI_ObjectReferenceParamWdg *myDistSelWdg;
271   GEOM::GEOM_Object_var                  mySMapObject;
272   GEOM::GEOM_Object_var                  myAttObject;
273   GEOM::GEOM_Object_var                  myDistObject;
274   
275   
276   
277   
278   QWidget*            myEnfGroup;
279 //    TODO FACE AND VERTEX SELECTION
280   StdMeshersGUI_ObjectReferenceParamWdg *myEnfFaceWdg;
281   GEOM::GEOM_Object_var myEnfFace;
282   StdMeshersGUI_ObjectReferenceParamWdg *myEnfVertexWdg;
283   GEOM::GEOM_Object_var myEnfVertex;
284
285 //   DlgBlSurfHyp_Enforced* myEnforcedVertexWidget;
286   QTreeWidget*        myEnforcedTreeWidget;
287   SMESHGUI_SpinBox*   myXCoord;
288   SMESHGUI_SpinBox*   myYCoord;
289   SMESHGUI_SpinBox*   myZCoord;
290
291   QLineEdit*          myGroupName;
292   QGroupBox*          makeGroupsCheck;
293   QLineEdit*          myGlobalGroupName;
294
295   QPushButton*        addVertexButton;
296   QPushButton*        removeVertexButton;
297
298   // map =  entry , size map
299   QMap<QString, QString>          mySMPMap;           // Map <face entry, size>
300   QMap<QString, QString>          myATTMap;           // Map <face entry, att. entry>
301   QMap<QString, double>           myDistMap;          // Map <entry,distance with constant size> 
302   QMap<QString, double>           myAttDistMap;       // Map <entry, influence distance> 
303   QMap<QString, TopAbs_ShapeEnum> mySMPShapeTypeMap;
304   GeomSelectionTools*             GeomToolSelected;
305   LightApp_SelectionMgr*          aSel;
306
307   BLSURFPlugin::string_array_var myOptions;
308
309   PyObject *          main_mod;
310   PyObject *          main_dict;
311 };
312
313
314 class EnforcedTreeWidgetDelegate : public QItemDelegate
315 {
316     Q_OBJECT
317
318 public:
319   EnforcedTreeWidgetDelegate(QObject *parent = 0);
320
321   QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
322                         const QModelIndex &index) const;
323
324   void setEditorData(QWidget *editor, const QModelIndex &index) const;
325   void setModelData(QWidget *editor, QAbstractItemModel *model,
326                     const QModelIndex &index) const;
327
328   void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
329                     const QModelIndex &index) const;
330
331   bool vertexExists(QAbstractItemModel *model, const QModelIndex &index, QString value) const;
332 };
333
334 #endif // BLSURFPLUGINGUI_HypothesisCreator_H