Salome HOME
Merge from V6_main 13/12/2012
[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 QRadioButton;
69 class QTableWidget;
70 class QTreeWidget;
71 class QModelIndex;
72 class QSpinBox;
73 class QDoubleSpinBox;
74 class QMenu;
75 class QAction;
76 class QTreeWidgetItem;
77 class QTableWidgetItem;
78 class QObject;
79
80 class SMESHGUI_SpinBox;
81 class LightApp_SelectionMgr;
82 class BLSURFPluginGUI_StdWidget;
83 class BLSURFPluginGUI_AdvWidget;
84 // class DlgBlSurfHyp_Enforced;
85
86 // Name
87 typedef std::string TEnfName;
88 // Entry
89 typedef std::string TEntry;
90 // List of entries
91 typedef std::set<TEntry> TEntryList;
92 // Enforced vertex = 3 coordinates
93 typedef std::vector<double> TEnfVertexCoords;
94 // List of enforced vertices
95 typedef std::set< TEnfVertexCoords > TEnfVertexCoordsList;
96 // Enforced vertex
97 struct TEnfVertex{
98   TEnfName name;
99   TEntry geomEntry;
100   TEnfVertexCoords coords;
101   TEnfName grpName;
102 };
103
104
105 struct CompareEnfVertices
106 {
107   bool operator () (const TEnfVertex* e1, const TEnfVertex* e2) const {
108     if (e1 && e2) {
109       if (e1->coords.size() && e2->coords.size())
110         return (e1->coords < e2->coords);
111       else
112         return (e1->geomEntry < e2->geomEntry);
113     }
114     return false;
115   }
116 };
117
118 // List of enforced vertices
119 typedef std::set< TEnfVertex*, CompareEnfVertices > TEnfVertexList;
120
121 // Map Face Entry / List of enforced vertices
122 typedef std::map< TEntry, TEnfVertexList > TFaceEntryEnfVertexListMap;
123
124 // Map Face Entry / InternalEnforcedVertices
125 typedef std::map< TEntry, bool > TFaceEntryInternalVerticesMap;
126
127 typedef struct
128 {
129   int     myTopology, myVerbosity;
130   int     myPhysicalMesh, myGeometricMesh;
131   double  myPhySize, myMinSize, myMaxSize;
132   bool    myPhySizeRel, myMinSizeRel, myMaxSizeRel;
133   bool    myUseMinSize, myUseMaxSize;
134   double  myGradation, myAngleMesh, myChordalError;
135   bool    myAnisotropic, myRemoveTinyEdges, myForceBadElementRemoval;
136   double  myAnisotropicRatio, myTinyEdgeLength, myBadElementAspectRatio;
137   bool    myOptimizeMesh, myQuadraticMesh;
138   bool    myAllowQuadrangles, mySmpsurface,mySmpedge,mySmppoint,myEnforcedVertex,myInternalEnforcedVerticesAllFaces;
139   bool    myPreCADMergeEdges, myPreCADProcess3DTopology, myPreCADDiscardInput;
140 //   bool    myGMFFileMode;
141   std::string myGMFFileName, myInternalEnforcedVerticesAllFacesGroup;
142   TEnfVertexList enfVertexList;
143   TFaceEntryEnfVertexListMap faceEntryEnfVertexListMap;
144   /* TODO GROUPS
145   TGroupNameEnfVertexListMap groupNameEnfVertexListMap;
146   */
147   QString myName;
148 } BlsurfHypothesisData;
149
150
151 /*!
152  * \brief Class for creation of BLSURF hypotheses
153 */
154 class BLSURFPLUGIN_GUI_EXPORT BLSURFPluginGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator
155 {
156   Q_OBJECT
157
158 public:
159   BLSURFPluginGUI_HypothesisCreator( const QString& );
160   virtual ~BLSURFPluginGUI_HypothesisCreator();
161
162   virtual bool        checkParams(QString& msg) const;
163   virtual QString     helpPage() const;
164
165 protected:
166   virtual QFrame*     buildFrame    ();
167   virtual void        retrieveParams() const;
168   virtual QString     storeParams   () const;
169
170   virtual QString     caption() const;
171   virtual QPixmap     icon() const;
172   virtual QString     type() const;
173
174 protected slots:
175   // Advanced tab
176   void                onAddOption();
177   void                onDeleteOption();
178   void                onOptionChosenInPopup( QAction* );
179   // Sizemap tab
180   void                onMapGeomContentModified();
181   void                onSmpItemClicked( QTreeWidgetItem *, int );
182   void                onSmpTabChanged(int);
183   void                onAttractorClicked(int);
184   void                onConstSizeClicked(int);
185   void                onAddMap();
186   void                onRemoveMap();
187   void                onModifyMap();
188   void                onSetSizeMap(QTreeWidgetItem *, int);
189   // Enforced vertices tab
190   QTreeWidgetItem*    addEnforcedFace(std::string theFaceEntry, std::string theFaceName);
191   void                addEnforcedVertex(QTreeWidgetItem * theFaceItem, double x=0, double y=0, double z=0, 
192                                         std::string vertexName = "", std::string geomEntry = "", std::string groupName = "");
193   void                onAddEnforcedVertices();
194   void                onRemoveEnforcedVertex();
195   void                synchronizeCoords();
196   void                updateEnforcedVertexValues(QTreeWidgetItem* , int );
197   void                onSelectEnforcedVertex();
198 //   void                deactivateSelection(QWidget*, QWidget*);
199   void                clearEnforcedVertexWidgets();
200   void                onInternalVerticesClicked(int);
201
202 private:
203   bool                readParamsFromHypo( BlsurfHypothesisData& ) const;
204   QString             readParamsFromWidgets( BlsurfHypothesisData& ) const;
205   bool                storeParamsToHypo( const BlsurfHypothesisData& ) const;
206   bool                sizeMapsValidation();
207   bool                sizeMapValidationFromRow(int,bool displayError = true);
208   bool                sizeMapValidationFromEntry(QString,bool displayError = true);
209   GeomSelectionTools* getGeomSelectionTool();
210   GEOM::GEOM_Gen_var  getGeomEngine();
211   //void                insertElementType( TopAbs_ShapeEnum );
212   void                insertElement( GEOM::GEOM_Object_var, bool modify = false );
213   void                insertAttractor(GEOM::GEOM_Object_var, GEOM::GEOM_Object_var, bool modify = false);
214   int                 findRowFromEntry(QString entry);
215   CORBA::Object_var   entryToObject(QString entry);
216   static LightApp_SelectionMgr* selectionMgr();
217
218 private:
219   
220   QWidget*                myStdGroup;
221   BLSURFPluginGUI_StdWidget* myStdWidget;
222   QLineEdit*              myName;
223
224   QWidget*                myAdvGroup;
225   BLSURFPluginGUI_AdvWidget* myAdvWidget;
226
227   // Sizemap widgets
228   QWidget                 *mySmpGroup;
229   QTreeWidget             *mySizeMapTable;
230   QPushButton             *addMapButton;
231   QPushButton             *removeMapButton;
232   QPushButton             *modifyMapButton;
233   QTabWidget              *smpTab; 
234   QWidget                 *myAttractorGroup;
235   QWidget                 *mySmpStdGroup;
236   QCheckBox               *myAttractorCheck;
237   QCheckBox               *myConstSizeCheck;
238   QGroupBox               *myDistanceGroup;
239 //   QGroupBox               *myParamsGroup;
240 //   QWidget                 *myParamsGroup;
241   SMESHGUI_SpinBox        *myAttSizeSpin;
242   SMESHGUI_SpinBox        *myAttDistSpin;
243   SMESHGUI_SpinBox        *myAttDistSpin2;
244   SMESHGUI_SpinBox        *mySmpSizeSpin;
245   QLabel                  *myAttDistLabel;
246   QLabel                  *myAttDistLabel2;
247   QLabel                  *myAttSizeLabel;
248   // Selection widgets for size maps
249   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg1;
250   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg2;
251   StdMeshersGUI_ObjectReferenceParamWdg *myAttSelWdg;
252   StdMeshersGUI_ObjectReferenceParamWdg *myDistSelWdg;
253   GEOM::GEOM_Object_var                  mySMapObject;
254   GEOM::GEOM_Object_var                  myAttObject;
255   GEOM::GEOM_Object_var                  myDistObject;
256   
257   
258   
259   
260   QWidget*            myEnfGroup;
261 //    TODO FACE AND VERTEX SELECTION
262   StdMeshersGUI_ObjectReferenceParamWdg *myEnfFaceWdg;
263   GEOM::GEOM_Object_var myEnfFace;
264   StdMeshersGUI_ObjectReferenceParamWdg *myEnfVertexWdg;
265   GEOM::GEOM_Object_var myEnfVertex;
266
267 //   DlgBlSurfHyp_Enforced* myEnforcedVertexWidget;
268   QTreeWidget*        myEnforcedTreeWidget;
269   SMESHGUI_SpinBox*   myXCoord;
270   SMESHGUI_SpinBox*   myYCoord;
271   SMESHGUI_SpinBox*   myZCoord;
272
273   QLineEdit*          myGroupName;
274 //   QGroupBox*          makeGroupsCheck;
275 //   QCheckBox*          myGlobalGroupName;
276
277   QPushButton*        addVertexButton;
278   QPushButton*        removeVertexButton;
279
280   QCheckBox           *myInternalEnforcedVerticesAllFaces;
281   QLineEdit           *myInternalEnforcedVerticesAllFacesGroup;
282
283   // map =  entry , size map
284   QMap<QString, QString>          mySMPMap;           // Map <face entry, size>
285   QMap<QString, QString>          myATTMap;           // Map <face entry, att. entry>
286   QMap<QString, double>           myDistMap;          // Map <entry,distance with constant size> 
287   QMap<QString, double>           myAttDistMap;       // Map <entry, influence distance> 
288   QMap<QString, TopAbs_ShapeEnum> mySMPShapeTypeMap;
289   GeomSelectionTools*             GeomToolSelected;
290   LightApp_SelectionMgr*          aSel;
291
292   BLSURFPlugin::string_array_var myOptions, myPreCADOptions;
293
294   PyObject *          main_mod;
295   PyObject *          main_dict;
296 };
297
298
299 class EnforcedTreeWidgetDelegate : public QItemDelegate
300 {
301     Q_OBJECT
302
303 public:
304   EnforcedTreeWidgetDelegate(QObject *parent = 0);
305
306   QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
307                         const QModelIndex &index) const;
308
309   void setEditorData(QWidget *editor, const QModelIndex &index) const;
310   void setModelData(QWidget *editor, QAbstractItemModel *model,
311                     const QModelIndex &index) const;
312
313   void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
314                     const QModelIndex &index) const;
315
316   bool vertexExists(QAbstractItemModel *model, const QModelIndex &index, QString value) const;
317 };
318
319 #endif // BLSURFPLUGINGUI_HypothesisCreator_H