Salome HOME
Merge from V6_main_20120808 08Aug12
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.h
1 // Copyright (C) 2007-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 // ---
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 // Map Face Entry / InternalEnforcedVertices
122 typedef std::map< TEntry, bool > TFaceEntryInternalVerticesMap;
123
124 typedef struct
125 {
126   int     myTopology, myVerbosity;
127   int     myPhysicalMesh, myGeometricMesh;
128   double  myAngleMeshS, myAngleMeshC, myGradation;
129   double  myPhySize, myGeoMin, myGeoMax, myPhyMin,myPhyMax;
130   bool    myAllowQuadrangles, myDecimesh,mySmpsurface,mySmpedge,mySmppoint,myEnforcedVertex,myInternalEnforcedVerticesAllFaces;
131   bool    myPreCADMergeEdges, myPreCADRemoveNanoEdges, myPreCADDiscardInput;
132   double  myPreCADEpsNano;
133 //   bool    myGMFFileMode;
134   std::string myGMFFileName, myInternalEnforcedVerticesAllFacesGroup;
135   TEnfVertexList enfVertexList;
136   TFaceEntryEnfVertexListMap faceEntryEnfVertexListMap;
137   /* TODO GROUPS
138   TGroupNameEnfVertexListMap groupNameEnfVertexListMap;
139   */
140   QString myName;
141 } BlsurfHypothesisData;
142
143
144
145 // class BLSURFPluginGUI_ObjectReferenceParamWdg: public StdMeshersGUI_ObjectReferenceParamWdg
146 // {
147 //   Q_OBJECT
148 // public:
149 //   BLSURFPluginGUI_ObjectReferenceParamWdg( SUIT_SelectionFilter* filter, 
150 //                                          QWidget*              parent,
151 //                                          bool                  multiSelection=false);
152 //   BLSURFPluginGUI_ObjectReferenceParamWdg( MeshObjectType objType,
153 //                                          QWidget*       parent,
154 //                                          bool           multiSelection=false);
155 //   ~BLSURFPluginGUI_ObjectReferenceParamWdg();
156 // 
157 // private:
158 //   void init();
159 //   
160 // public slots:
161 //   void activateSelectionOnly();
162 //   void deactivateSelectionOnly();
163 //   void setActivationStatus(bool status);
164 // };
165
166 /*!
167  * \brief Class for creation of BLSURF hypotheses
168 */
169 class BLSURFPLUGIN_GUI_EXPORT BLSURFPluginGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator
170 {
171   Q_OBJECT
172
173 public:
174   BLSURFPluginGUI_HypothesisCreator( const QString& );
175   virtual ~BLSURFPluginGUI_HypothesisCreator();
176
177   virtual bool        checkParams(QString& msg) const;
178   virtual QString     helpPage() const;
179
180 protected:
181   virtual QFrame*     buildFrame    ();
182   virtual void        retrieveParams() const;
183   virtual QString     storeParams   () const;
184
185   virtual QString     caption() const;
186   virtual QPixmap     icon() const;
187   virtual QString     type() const;
188
189 protected slots:
190   void                onPhysicalMeshChanged();
191   void                onGeometricMeshChanged();
192   void                onAddOption();
193   void                onDeleteOption();
194   void                onChooseGMFFile();
195   void                onOptionChosenInPopup( QAction* );
196   void                onTopologyChanged( int );
197   void                onMapGeomContentModified();
198   void                onSmpItemClicked( QTreeWidgetItem *, int );
199   void                onSmpTabChanged(int);
200   void                onAttractorClicked(int);
201   void                onConstSizeClicked(int);
202   void                onAddMap();
203   void                onRemoveMap();
204   void                onModifyMap();
205   void                onSetSizeMap(QTreeWidgetItem *, int);
206
207   QTreeWidgetItem*    addEnforcedFace(std::string theFaceEntry, std::string theFaceName);
208
209   void                addEnforcedVertex(QTreeWidgetItem * theFaceItem, double x=0, double y=0, double z=0, 
210                                         std::string vertexName = "", std::string geomEntry = "", std::string groupName = "");
211   
212   void                onAddEnforcedVertices();
213   void                onRemoveEnforcedVertex();
214   void                synchronizeCoords();
215   void                updateEnforcedVertexValues(QTreeWidgetItem* , int );
216   void                onSelectEnforcedVertex();
217 //   void                deactivateSelection(QWidget*, QWidget*);
218   void                clearEnforcedVertexWidgets();
219   void                onInternalVerticesClicked(int);
220
221 private:
222   bool                readParamsFromHypo( BlsurfHypothesisData& ) const;
223   QString             readParamsFromWidgets( BlsurfHypothesisData& ) const;
224   bool                storeParamsToHypo( const BlsurfHypothesisData& ) const;
225   bool                sizeMapsValidation();
226   bool                sizeMapValidationFromRow(int,bool displayError = true);
227   bool                sizeMapValidationFromEntry(QString,bool displayError = true);
228   GeomSelectionTools* getGeomSelectionTool();
229   GEOM::GEOM_Gen_var  getGeomEngine();
230   //void                insertElementType( TopAbs_ShapeEnum );
231   void                insertElement( GEOM::GEOM_Object_var, bool modify = false );
232   void                insertAttractor(GEOM::GEOM_Object_var, GEOM::GEOM_Object_var, bool modify = false);
233   int                 findRowFromEntry(QString entry);
234   CORBA::Object_var   entryToObject(QString entry);
235   static LightApp_SelectionMgr* selectionMgr();
236
237 private:
238   QWidget*            myStdGroup;
239   QLineEdit*          myName;
240   QComboBox*          myPhysicalMesh;
241   SMESHGUI_SpinBox*   myPhySize;
242   SMESHGUI_SpinBox*   myPhyMin;
243   SMESHGUI_SpinBox*   myPhyMax;
244   QComboBox*          myGeometricMesh;
245   SMESHGUI_SpinBox*   myAngleMeshS;
246   SMESHGUI_SpinBox*   myAngleMeshC;
247   SMESHGUI_SpinBox*   myGeoMin;
248   SMESHGUI_SpinBox*   myGeoMax;
249   SMESHGUI_SpinBox*   myGradation;
250   QCheckBox*          myAllowQuadrangles;
251   QCheckBox*          myDecimesh;
252
253   QWidget*            myAdvGroup;
254   QComboBox*          myTopology;
255   QGroupBox*          myPreCADGroupBox;
256   QCheckBox*          myPreCADMergeEdges;
257   QCheckBox*          myPreCADRemoveNanoEdges;
258   QCheckBox*          myPreCADDiscardInput;
259   SMESHGUI_SpinBox*   myPreCADEpsNano;
260   QSpinBox*           myVerbosity;
261   QTableWidget*       myOptionTable;
262   QLineEdit*          myGMFFileName;
263 //   QCheckBox*          myGMFFileMode;
264
265   // Sizemap widgets
266   QWidget             *mySmpGroup;
267   QTreeWidget         *mySizeMapTable;
268   QPushButton         *addMapButton;
269   QPushButton         *removeMapButton;
270   QPushButton         *modifyMapButton;
271   QTabWidget          *smpTab; 
272   QWidget             *myAttractorGroup;
273   QWidget             *mySmpStdGroup;
274   QCheckBox           *myAttractorCheck;
275   QCheckBox           *myConstSizeCheck;
276   QGroupBox           *myDistanceGroup;
277 //   QGroupBox           *myParamsGroup;
278 //   QWidget             *myParamsGroup;
279   SMESHGUI_SpinBox    *myAttSizeSpin;
280   SMESHGUI_SpinBox    *myAttDistSpin;
281   SMESHGUI_SpinBox    *myAttDistSpin2;
282   SMESHGUI_SpinBox    *mySmpSizeSpin;
283   QLabel              *myAttDistLabel;
284   QLabel              *myAttDistLabel2;
285   QLabel              *myAttSizeLabel;
286   // Selection widgets for size maps
287   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg1;
288   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg2;
289   StdMeshersGUI_ObjectReferenceParamWdg *myAttSelWdg;
290   StdMeshersGUI_ObjectReferenceParamWdg *myDistSelWdg;
291   GEOM::GEOM_Object_var                  mySMapObject;
292   GEOM::GEOM_Object_var                  myAttObject;
293   GEOM::GEOM_Object_var                  myDistObject;
294   
295   
296   
297   
298   QWidget*            myEnfGroup;
299 //    TODO FACE AND VERTEX SELECTION
300   StdMeshersGUI_ObjectReferenceParamWdg *myEnfFaceWdg;
301   GEOM::GEOM_Object_var myEnfFace;
302   StdMeshersGUI_ObjectReferenceParamWdg *myEnfVertexWdg;
303   GEOM::GEOM_Object_var myEnfVertex;
304
305 //   DlgBlSurfHyp_Enforced* myEnforcedVertexWidget;
306   QTreeWidget*        myEnforcedTreeWidget;
307   SMESHGUI_SpinBox*   myXCoord;
308   SMESHGUI_SpinBox*   myYCoord;
309   SMESHGUI_SpinBox*   myZCoord;
310
311   QLineEdit*          myGroupName;
312 //   QGroupBox*          makeGroupsCheck;
313 //   QCheckBox*          myGlobalGroupName;
314
315   QPushButton*        addVertexButton;
316   QPushButton*        removeVertexButton;
317
318   QCheckBox           *myInternalEnforcedVerticesAllFaces;
319   QLineEdit           *myInternalEnforcedVerticesAllFacesGroup;
320
321   // map =  entry , size map
322   QMap<QString, QString>          mySMPMap;           // Map <face entry, size>
323   QMap<QString, QString>          myATTMap;           // Map <face entry, att. entry>
324   QMap<QString, double>           myDistMap;          // Map <entry,distance with constant size> 
325   QMap<QString, double>           myAttDistMap;       // Map <entry, influence distance> 
326   QMap<QString, TopAbs_ShapeEnum> mySMPShapeTypeMap;
327   GeomSelectionTools*             GeomToolSelected;
328   LightApp_SelectionMgr*          aSel;
329
330   BLSURFPlugin::string_array_var myOptions, myPreCADOptions;
331
332   PyObject *          main_mod;
333   PyObject *          main_dict;
334 };
335
336
337 class EnforcedTreeWidgetDelegate : public QItemDelegate
338 {
339     Q_OBJECT
340
341 public:
342   EnforcedTreeWidgetDelegate(QObject *parent = 0);
343
344   QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
345                         const QModelIndex &index) const;
346
347   void setEditorData(QWidget *editor, const QModelIndex &index) const;
348   void setModelData(QWidget *editor, QAbstractItemModel *model,
349                     const QModelIndex &index) const;
350
351   void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
352                     const QModelIndex &index) const;
353
354   bool vertexExists(QAbstractItemModel *model, const QModelIndex &index, QString value) const;
355 };
356
357 #endif // BLSURFPLUGINGUI_HypothesisCreator_H