Salome HOME
23370: [CEA 632] Impose enforced vertices without indicate the face on which the...
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.h
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 // akl: avoid compilation warning on Linux : "_POSIX_C_SOURCE" and "_XOPEN_SOURCE" are redefined
31 #ifdef _POSIX_C_SOURCE
32 #undef _POSIX_C_SOURCE
33 #endif
34
35 #ifdef _XOPEN_SOURCE
36 #undef _XOPEN_SOURCE
37 #endif
38
39 #ifdef WIN32
40   #if defined BLSURFPLUGIN_GUI_EXPORTS || defined BLSURFPluginGUI_EXPORTS
41     #define BLSURFPLUGIN_GUI_EXPORT __declspec( dllexport )
42   #else
43     #define BLSURFPLUGIN_GUI_EXPORT __declspec( dllimport )
44   #endif
45 #else
46   #define BLSURFPLUGIN_GUI_EXPORT
47 #endif
48
49 #ifdef WIN32
50 // E.A. : On windows with python 2.6, there is a conflict
51 // E.A. : between pymath.h and Standard_math.h which define
52 // E.A. : some same symbols : acosh, asinh, ...
53 #include <Standard_math.hxx>
54 #include <pymath.h>
55 #endif
56
57 #include <Python.h>
58
59 #include <QItemDelegate>
60
61 #include <SMESHGUI_Hypotheses.h>
62 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
63 #include <SALOMEconfig.h>
64 #include <cstring>
65 #include <map>
66 #include <set>
67 #include <vector>
68 #include <TopAbs_ShapeEnum.hxx>
69 #include <GeomSelectionTools.h>
70 #include <GEOM_Client.hxx>
71 #include CORBA_SERVER_HEADER(BLSURFPlugin_Algorithm)
72
73 class QGroupBox;
74 class QComboBox;
75 class QCheckBox;
76 class QLineEdit;
77 class QRadioButton;
78 class QTableWidget;
79 class QTreeWidget;
80 class QModelIndex;
81 class QSpinBox;
82 class QDoubleSpinBox;
83 class QMenu;
84 class QAction;
85 class QTreeWidgetItem;
86 class QTableWidgetItem;
87 class QObject;
88 class QSplitter;
89 class QGridLayout;
90 class QVBoxLayout;
91 class QSpacerItem;
92
93 class SMESHGUI_SpinBox;
94 class SMESH_NumberFilter;
95 class LightApp_SelectionMgr;
96 class BLSURFPluginGUI_StdWidget;
97 class BLSURFPluginGUI_AdvWidget;
98 // class DlgBlSurfHyp_Enforced;
99
100 // Name
101 typedef std::string TEnfName;
102 // Entry
103 typedef std::string TEntry;
104 // List of entries
105 typedef std::set<TEntry> TEntryList;
106 // Enforced vertex = 3 coordinates
107 typedef std::vector<double> TEnfVertexCoords;
108 // List of enforced vertices
109 typedef std::set< TEnfVertexCoords > TEnfVertexCoordsList;
110 // Enforced vertex
111 struct TEnfVertex{
112   TEnfName name;
113   TEntry geomEntry;
114   TEnfVertexCoords coords;
115   TEnfName grpName;
116 };
117 // Attractor
118 struct TAttractor{
119   std::string attEntry;
120   double      startSize;
121   double      infDist;
122   double      constDist;
123   TAttractor( const char* theAttEntry, double theStartSize, double theInfDist, double theConstDist)
124     : attEntry( theAttEntry ),
125       startSize( theStartSize ),
126       infDist( theInfDist ),
127       constDist( theConstDist )
128   {}
129   void SetToDelete() { startSize = -1; }
130   bool IsToDelete() const { return startSize < 0; }
131 };
132 typedef std::vector< TAttractor > TAttractorVec;
133
134 struct CompareEnfVertices
135 {
136   bool operator () (const TEnfVertex* e1, const TEnfVertex* e2) const {
137     if (e1 && e2) {
138       if (e1->coords.size() && e2->coords.size())
139         return (e1->coords < e2->coords);
140       else
141         return (e1->geomEntry < e2->geomEntry);
142     }
143     return false;
144   }
145 };
146
147 // List of enforced vertices
148 typedef std::set< TEnfVertex*, CompareEnfVertices > TEnfVertexList;
149
150 // Map Face Entry / List of enforced vertices
151 typedef std::map< TEntry, TEnfVertexList > TFaceEntryEnfVertexListMap;
152
153 // Map Face Entry / InternalEnforcedVertices
154 typedef std::map< TEntry, bool > TFaceEntryInternalVerticesMap;
155
156 // PreCad Face and Edge periodicity
157 typedef std::vector<std::string> TPreCadPeriodicity;
158 typedef std::vector< TPreCadPeriodicity > TPreCadPeriodicityVector;
159
160 typedef struct
161 {
162   int     myTopology, myVerbosity;
163   int     myPhysicalMesh, myGeometricMesh;
164   double  myPhySize, myMinSize, myMaxSize;
165   bool    myPhySizeRel, myMinSizeRel, myMaxSizeRel;
166   bool    myUseMinSize, myUseMaxSize, myUseGradation, myUseVolumeGradation;
167   double  myGradation, myVolumeGradation, myAngleMesh, myChordalError;
168   bool    myAnisotropic, myOptimiseTinyEdges, myRemoveTinyEdges, myForceBadElementRemoval, myCorrectSurfaceIntersection;
169   double  myAnisotropicRatio, myTinyEdgeLength, myTinyEdgeOptimisLength, myBadElementAspectRatio, myCorrectSurfaceIntersectionMaxCost;
170   bool    myOptimizeMesh, myQuadraticMesh;
171   bool    myAllowQuadrangles, mySmpsurface,mySmpedge,mySmppoint,myEnforcedVertex,myInternalEnforcedVerticesAllFaces;
172   // bool    myPreCADMergeEdges, myPreCADProcess3DTopology, myPreCADDiscardInput;
173 //   bool    myGMFFileMode;
174   std::string myGMFFileName, myInternalEnforcedVerticesAllFacesGroup;
175   TEnfVertexList enfVertexList;
176   TFaceEntryEnfVertexListMap faceEntryEnfVertexListMap;
177   /* TODO GROUPS
178   TGroupNameEnfVertexListMap groupNameEnfVertexListMap;
179   */
180   TPreCadPeriodicityVector preCadPeriodicityVector;
181   QString myName;
182 } BlsurfHypothesisData;
183
184
185 /*!
186  * \brief Class for creation of MG-CADSurf hypotheses
187 */
188 class BLSURFPLUGIN_GUI_EXPORT BLSURFPluginGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator
189 {
190   Q_OBJECT
191
192 public:
193   BLSURFPluginGUI_HypothesisCreator( const QString& );
194   virtual ~BLSURFPluginGUI_HypothesisCreator();
195
196   virtual bool        checkParams(QString& msg) const;
197   virtual QString     helpPage() const;
198
199 protected:
200   virtual QFrame*     buildFrame    ();
201   virtual void        retrieveParams() const;
202   virtual QString     storeParams   () const;
203
204   virtual QString     caption() const;
205   virtual QPixmap     icon() const;
206   virtual QString     type() const;
207
208 protected slots:
209   void                onStateChange();
210   // Advanced tab
211   void                onAddOption();
212 //  void                onDeleteOption();
213 //  void                onEditOption( int, int );
214   void                onChangeOptionName( int, int );
215 //  void                onOptionChosenInPopup( QAction* );
216   // Sizemap tab
217   void                onMapGeomContentModified();
218   void                onSmpItemClicked( QTreeWidgetItem *, int );
219   void                onTabChanged(int);
220   void                onAttractorClicked(int);
221   void                onConstSizeClicked(int);
222   void                onAddMap();
223   void                onRemoveMap();
224   void                onModifyMap();
225   void                onSetSizeMap(QTreeWidgetItem *, int);
226   // Enforced vertices tab
227   QTreeWidgetItem*    addEnforcedFace(std::string theFaceEntry, std::string theFaceName);
228   void                addEnforcedVertex(double x=0, double y=0, double z=0, 
229                                         std::string vertexName = "", std::string geomEntry = "", std::string groupName = "");
230   void                onAddEnforcedVertices();
231   void                onRemoveEnforcedVertex();
232   void                synchronizeCoords();
233   void                updateEnforcedVertexValues(QTreeWidgetItem* , int );
234   void                onSelectEnforcedVertex();
235 //   void                deactivateSelection(QWidget*, QWidget*);
236   void                clearEnforcedVertexWidgets();
237   void                onInternalVerticesClicked(int);
238   // Periodicity tab
239   void                onPeriodicityByVerticesChecked(bool);
240 //  void                onPeriodicityRadioButtonChanged();
241   void                onAddPeriodicity();
242   void                onRemovePeriodicity();
243   void                onPeriodicityTreeClicked(QTreeWidgetItem*, int);
244   void                onPeriodicityContentModified();
245
246 private:
247   bool                readParamsFromHypo( BlsurfHypothesisData& ) const;
248   QString             readParamsFromWidgets( BlsurfHypothesisData& ) const;
249   bool                storeParamsToHypo( const BlsurfHypothesisData& ) const;
250   bool                sizeMapsValidation();
251   bool                sizeMapValidationFromRow(int,bool displayError = true);
252   bool                sizeMapValidationFromEntry(QString,bool displayError = true);
253   GeomSelectionTools* getGeomSelectionTool() const;
254   GEOM::GEOM_Gen_var  getGeomEngine();
255   //void                insertElementType( TopAbs_ShapeEnum );
256   bool                insertElement( GEOM::GEOM_Object_var, bool modify = false );
257   bool                insertAttractor(GEOM::GEOM_Object_var, GEOM::GEOM_Object_var, bool modify = false);
258   int                 findRowFromEntry(QString entry);
259   CORBA::Object_var   entryToObject(QString entry);
260   static LightApp_SelectionMgr* selectionMgr();
261   void                avoidSimultaneousSelection(ListOfWidgets &myCustomWidgets) const;
262   void                AddPreCadSequenceToVector(BlsurfHypothesisData& h_data, BLSURFPlugin::TPeriodicityList_var preCadFacePeriodicityVector, bool onFace) const;
263
264 private:
265   
266   QTabWidget*             myTabWidget;
267   QWidget*                myStdGroup;
268   BLSURFPluginGUI_StdWidget* myStdWidget;
269   QLineEdit*              myName;
270
271   QWidget*                myAdvGroup;
272   BLSURFPluginGUI_AdvWidget* myAdvWidget;
273
274   // Sizemap widgets
275   QWidget                 *mySmpGroup;
276   QTreeWidget             *mySizeMapTable;
277   QPushButton             *addMapButton;
278   QPushButton             *removeMapButton;
279   QPushButton             *modifyMapButton;
280   QTabWidget              *smpTab; 
281   QWidget                 *myAttractorGroup;
282   QWidget                 *mySmpStdGroup;
283   QCheckBox               *myAttractorCheck;
284   QCheckBox               *myConstSizeCheck;
285   QGroupBox               *myDistanceGroup;
286 //   QGroupBox               *myParamsGroup;
287 //   QWidget                 *myParamsGroup;
288   SMESHGUI_SpinBox        *myAttSizeSpin;
289   SMESHGUI_SpinBox        *myAttDistSpin;
290   SMESHGUI_SpinBox        *myAttDistSpin2;
291   SMESHGUI_SpinBox        *mySmpSizeSpin;
292   QLabel                  *myAttDistLabel;
293   QLabel                  *myAttDistLabel2;
294   QLabel                  *myAttSizeLabel;
295   // Selection widgets for size maps
296   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg1;
297   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg2;
298   StdMeshersGUI_ObjectReferenceParamWdg *myAttSelWdg;
299   StdMeshersGUI_ObjectReferenceParamWdg *myDistSelWdg;
300   GEOM::GEOM_Object_var                  mySMapObject;
301   GEOM::GEOM_Object_var                  myAttObject;
302   GEOM::GEOM_Object_var                  myDistObject;
303   
304   
305   
306   
307   QWidget*            myEnfGroup;
308 //    TODO FACE AND VERTEX SELECTION
309   StdMeshersGUI_ObjectReferenceParamWdg *myEnfFaceWdg;
310   GEOM::GEOM_Object_var myEnfFace;
311   StdMeshersGUI_ObjectReferenceParamWdg *myEnfVertexWdg;
312   GEOM::GEOM_Object_var myEnfVertex;
313
314 //   DlgBlSurfHyp_Enforced* myEnforcedVertexWidget;
315   QTreeWidget*        myEnforcedTreeWidget;
316   SMESHGUI_SpinBox*   myXCoord;
317   SMESHGUI_SpinBox*   myYCoord;
318   SMESHGUI_SpinBox*   myZCoord;
319
320   QLineEdit*          myGroupName;
321 //   QGroupBox*          makeGroupsCheck;
322 //   QCheckBox*          myGlobalGroupName;
323
324   QPushButton*        addVertexButton;
325   QPushButton*        removeVertexButton;
326
327   QCheckBox           *myInternalEnforcedVerticesAllFaces;
328   QLineEdit           *myInternalEnforcedVerticesAllFacesGroup;
329
330   // map =  entry , size map
331   QMap<QString, QString>          mySMPMap;           // Map <face entry, size>
332   QMap<QString, TAttractorVec >   myATTMap;           // Map <face entry, att. entry, etc>
333   // QMap<QString, double>           myDistMap;          // Map <entry,distance with constant size> 
334   // QMap<QString, double>           myAttDistMap;       // Map <entry, influence distance> 
335   QMap<QString, TopAbs_ShapeEnum> mySMPShapeTypeMap;
336   GeomSelectionTools*             GeomToolSelected;
337   LightApp_SelectionMgr*          aSel;
338
339   // Periodicity
340   QWidget* myPeriodicityGroup;
341   QSplitter* myPeriodicitySplitter;
342   QTreeWidget* myPeriodicityTreeWidget;
343   QWidget* myPeriodicityRightWidget;
344   QGridLayout* myPeriodicityRightGridLayout;
345   QGroupBox* myPeriodicityGroupBox1;
346   QGroupBox* myPeriodicityGroupBox2;
347   QGridLayout* aPeriodicityLayout1;
348   QGridLayout* myPeriodicityGroupBox1Layout;
349   QGridLayout* myPeriodicityGroupBox2Layout;
350   QRadioButton* myPeriodicityOnFaceRadioButton;
351   QRadioButton* myPeriodicityOnEdgeRadioButton;
352   QLabel* myPeriodicityMainSourceLabel;
353   QLabel* myPeriodicityMainTargetLabel;
354   QLabel* myPeriodicitySourceLabel;
355   QLabel* myPeriodicityTargetLabel;
356   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicitySourceFaceWdg;
357 //  StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicitySourceEdgeWdg;
358   GEOM::GEOM_Object_var myPeriodicityFace;
359   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityTargetFaceWdg;
360 //  StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityTargetEdgeWdg;
361   GEOM::GEOM_Object_var myPeriodicityEdge;
362   QLabel* myPeriodicityP1SourceLabel;
363   QLabel* myPeriodicityP2SourceLabel;
364   QLabel* myPeriodicityP3SourceLabel;
365   QLabel* myPeriodicityP1TargetLabel;
366   QLabel* myPeriodicityP2TargetLabel;
367   QLabel* myPeriodicityP3TargetLabel;
368   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP1SourceWdg;
369   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP2SourceWdg;
370   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP3SourceWdg;
371   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP1TargetWdg;
372   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP2TargetWdg;
373   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP3TargetWdg;
374   ListOfWidgets myPeriodicitySelectionWidgets;
375   QPushButton* myPeriodicityAddButton;
376   QPushButton* myPeriodicityRemoveButton;
377   QSpacerItem* myPeriodicityVerticalSpacer;
378
379   BLSURFPlugin::string_array_var myOptions, myPreCADOptions, myCustomOptions;
380
381   PyObject *          main_mod;
382   PyObject *          main_dict;
383 };
384
385
386 class EnforcedTreeWidgetDelegate : public QItemDelegate
387 {
388     Q_OBJECT
389
390 public:
391   EnforcedTreeWidgetDelegate(QObject *parent = 0);
392
393   QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
394                         const QModelIndex &index) const;
395
396   void setEditorData(QWidget *editor, const QModelIndex &index) const;
397   void setModelData(QWidget *editor, QAbstractItemModel *model,
398                     const QModelIndex &index) const;
399
400   void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
401                     const QModelIndex &index) const;
402
403   bool vertexExists(QAbstractItemModel *model, const QModelIndex &index, QString value) const;
404 };
405
406 #endif // BLSURFPLUGINGUI_HypothesisCreator_H