Salome HOME
647e50ebc6111299680e735ce5612fc334b53112
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.h
1 // Copyright (C) 2007-2022  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 StdMeshersGUI_SubShapeSelectorWdg;
99 // class DlgBlSurfHyp_Enforced;
100
101 // Name
102 typedef std::string TEnfName;
103 // Entry
104 typedef std::string TEntry;
105 // List of entries
106 typedef std::set<TEntry> TEntryList;
107 // Enforced vertex = 3 coordinates
108 typedef std::vector<double> TEnfVertexCoords;
109 // List of enforced vertices
110 typedef std::set< TEnfVertexCoords > TEnfVertexCoordsList;
111 // Enforced vertex
112 struct TEnfVertex{
113   TEnfName name;
114   TEntry geomEntry;
115   TEnfVertexCoords coords;
116   TEnfName grpName;
117 };
118 // Attractor
119 struct TAttractor{
120   std::string attEntry;
121   double      startSize;
122   double      infDist;
123   double      constDist;
124   TAttractor( const char* theAttEntry, double theStartSize, double theInfDist, double theConstDist)
125     : attEntry( theAttEntry ),
126       startSize( theStartSize ),
127       infDist( theInfDist ),
128       constDist( theConstDist )
129   {}
130   void SetToDelete() { startSize = -1; }
131   bool IsToDelete() const { return startSize < 0; }
132 };
133 typedef std::vector< TAttractor > TAttractorVec;
134
135 struct CompareEnfVertices
136 {
137   bool operator () (const TEnfVertex* e1, const TEnfVertex* e2) const {
138     if (e1 && e2) {
139       if (e1->coords.size() && e2->coords.size())
140         return (e1->coords < e2->coords);
141       else
142         return (e1->geomEntry < e2->geomEntry);
143     }
144     return false;
145   }
146 };
147
148 // List of enforced vertices
149 typedef std::set< TEnfVertex*, CompareEnfVertices > TEnfVertexList;
150
151 // Map Face Entry / List of enforced vertices
152 typedef std::map< TEntry, TEnfVertexList > TFaceEntryEnfVertexListMap;
153
154 // Map Face Entry / InternalEnforcedVertices
155 typedef std::map< TEntry, bool > TFaceEntryInternalVerticesMap;
156
157 // PreCad Face and Edge periodicity
158 typedef std::vector<std::string> TPreCadPeriodicity;
159 typedef std::vector< TPreCadPeriodicity > TPreCadPeriodicityVector;
160
161 typedef struct
162 {
163   int     myTopology, myVerbosity;
164   int     myPhysicalMesh, myGeometricMesh;
165   double  myPhySize, myMinSize, myMaxSize;
166   bool    myPhySizeRel, myMinSizeRel, myMaxSizeRel;
167   bool    myUseMinSize, myUseMaxSize, myUseGradation, myUseVolumeGradation;
168   double  myGradation, myVolumeGradation, myAngleMesh, myChordalError;
169   bool    myAnisotropic, myOptimiseTinyEdges, myRemoveTinyEdges, myForceBadElementRemoval, myCorrectSurfaceIntersection;
170   double  myAnisotropicRatio, myTinyEdgeLength, myTinyEdgeOptimisLength, myBadElementAspectRatio, myCorrectSurfaceIntersectionMaxCost;
171   bool    myOptimizeMesh, myQuadraticMesh;
172   bool    mySmpsurface,mySmpedge,mySmppoint,myEnforcedVertex,myInternalEnforcedVerticesAllFaces;
173   int     myElementType;
174   bool    myUseSurfaceProximity;
175   int     myNbSurfaceProximityLayers;
176   double  mySurfaceProximityRatio;
177   bool    myUseVolumeProximity;
178   int     myNbVolumeProximityLayers;
179   double  myVolumeProximityRatio;
180   // bool    myPreCADMergeEdges, myPreCADProcess3DTopology, myPreCADDiscardInput;
181 //   bool    myGMFFileMode;
182   std::string myGMFFileName, myInternalEnforcedVerticesAllFacesGroup;
183   TEnfVertexList enfVertexList;
184   TFaceEntryEnfVertexListMap faceEntryEnfVertexListMap;
185   /* TODO GROUPS
186   TGroupNameEnfVertexListMap groupNameEnfVertexListMap;
187   */
188   TPreCadPeriodicityVector preCadPeriodicityVector;
189   QStringList hyperpatches, hyperEntries;
190   QString myName;
191 } BlsurfHypothesisData;
192
193
194 /*!
195  * \brief Class for creation of MG-CADSurf hypotheses
196 */
197 class BLSURFPLUGIN_GUI_EXPORT BLSURFPluginGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator
198 {
199   Q_OBJECT
200
201 public:
202   BLSURFPluginGUI_HypothesisCreator( const QString& );
203   virtual ~BLSURFPluginGUI_HypothesisCreator();
204
205   virtual bool        checkParams(QString& msg) const;
206   virtual QString     helpPage() const;
207
208 protected:
209   virtual QFrame*     buildFrame    ();
210   virtual void        retrieveParams() const;
211   virtual QString     storeParams   () const;
212
213   virtual QString     caption() const;
214   virtual QPixmap     icon() const;
215   virtual QString     type() const;
216
217 protected slots:
218   void                onStateChange();
219   // Advanced tab
220   void                onAddOption();
221   void                onChangeOptionName( int, int );
222   // Sizemap tab
223   void                onMapGeomContentModified();
224   void                onSmpItemClicked( QTreeWidgetItem *, int );
225   void                onTabChanged(int);
226   void                onAttractorClicked(int);
227   void                onConstSizeClicked(int);
228   void                onAddMap();
229   void                onRemoveMap();
230   void                onModifyMap();
231   void                onSetSizeMap(QTreeWidgetItem *, int);
232   // Enforced vertices tab
233   QTreeWidgetItem*    addEnforcedFace(std::string theFaceEntry, std::string theFaceName);
234   void                addEnforcedVertex(double x=0, double y=0, double z=0, 
235                                         std::string vertexName = "",
236                                         std::string geomEntry = "",
237                                         std::string groupName = "");
238   void                onAddEnforcedVertices();
239   void                onRemoveEnforcedVertex();
240   void                synchronizeCoords();
241   void                updateEnforcedVertexValues(QTreeWidgetItem* , int );
242   void                onSelectEnforcedVertex();
243   void                clearEnforcedVertexWidgets();
244   void                onInternalVerticesClicked(int);
245   // Enforced mesh tab
246   void                onAddEnforcedMesh();
247   void                onRemoveEnforcedMesh();
248   void                onEnforcedMeshSelected();
249   void                onEnfMeshTableSelected();
250   // Periodicity tab
251   void                onPeriodicityByVerticesChecked(bool);
252   void                onAddPeriodicity();
253   void                onRemovePeriodicity();
254   void                onPeriodicityTreeClicked(QTreeWidgetItem*, int);
255   void                onPeriodicityContentModified();
256   // HyperPatch tab
257   void                onHyPatchFaceSelection(bool);
258   void                onHyPatchGroupSelection(bool);
259   void                onHyPatchSelectionChanged();
260   void                onHyPatchAdd();
261   void                onHyPatchRemove();
262
263 private:
264   bool                readParamsFromHypo( BlsurfHypothesisData& ) const;
265   QString             readParamsFromWidgets( BlsurfHypothesisData& ) const;
266   bool                storeParamsToHypo( const BlsurfHypothesisData& ) const;
267   bool                sizeMapsValidation();
268   bool                sizeMapValidationFromRow(int,bool displayError = true);
269   bool                sizeMapValidationFromEntry(QString,bool displayError = true);
270   GeomSelectionTools* getGeomSelectionTool() const;
271   GEOM::GEOM_Gen_var  getGeomEngine();
272   bool                insertElement( GEOM::GEOM_Object_var, bool modify = false );
273   bool                insertAttractor(GEOM::GEOM_Object_var, GEOM::GEOM_Object_var, bool modify = false);
274   int                 findRowFromEntry(QString entry);
275   CORBA::Object_var   entryToObject(QString entry);
276   static LightApp_SelectionMgr* selectionMgr();
277   void                avoidSimultaneousSelection(ListOfWidgets &myCustomWidgets) const;
278   void                AddPreCadSequenceToVector(BlsurfHypothesisData& h_data, BLSURFPlugin::TPeriodicityList_var preCadFacePeriodicityVector, bool onFace) const;
279   void                addHyPatchToTable(const QString& tags, const QString& entries);
280   bool                hasGeom() const;
281
282   void                addEnforcedMesh( SMESH::SMESH_IDSource_ptr mesh, const QString& groupName );
283
284 private:
285   
286   QTabWidget*             myTabWidget;
287   QWidget*                myStdGroup;
288   BLSURFPluginGUI_StdWidget* myStdWidget;
289   QLineEdit*              myName;
290
291   QWidget*                myAdvGroup;
292   BLSURFPluginGUI_AdvWidget* myAdvWidget;
293
294   // Sizemap widgets
295   QWidget                 *mySmpGroup;
296   QTreeWidget             *mySizeMapTable;
297   QPushButton             *addMapButton;
298   QPushButton             *removeMapButton;
299   QPushButton             *modifyMapButton;
300   QTabWidget              *smpTab; 
301   QWidget                 *myAttractorGroup;
302   QWidget                 *mySmpStdGroup;
303   QCheckBox               *myAttractorCheck;
304   QCheckBox               *myConstSizeCheck;
305   QGroupBox               *myDistanceGroup;
306 //   QGroupBox               *myParamsGroup;
307 //   QWidget                 *myParamsGroup;
308   SMESHGUI_SpinBox        *myAttSizeSpin;
309   SMESHGUI_SpinBox        *myAttDistSpin;
310   SMESHGUI_SpinBox        *myAttDistSpin2;
311   SMESHGUI_SpinBox        *mySmpSizeSpin;
312   QLabel                  *myAttDistLabel;
313   QLabel                  *myAttDistLabel2;
314   QLabel                  *myAttSizeLabel;
315   // Selection widgets for size maps
316   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg1;
317   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg2;
318   StdMeshersGUI_ObjectReferenceParamWdg *myAttSelWdg;
319   StdMeshersGUI_ObjectReferenceParamWdg *myDistSelWdg;
320   GEOM::GEOM_Object_var                  mySMapObject;
321   GEOM::GEOM_Object_var                  myAttObject;
322   GEOM::GEOM_Object_var                  myDistObject;
323   
324   
325   
326   
327   QWidget*            myEnfGroup;
328   StdMeshersGUI_ObjectReferenceParamWdg *myEnfFaceWdg;
329   GEOM::GEOM_Object_var myEnfFace;
330   StdMeshersGUI_ObjectReferenceParamWdg *myEnfVertexWdg;
331   GEOM::GEOM_Object_var myEnfVertex;
332
333   QTreeWidget*        myEnforcedTreeWidget;
334   SMESHGUI_SpinBox*   myXCoord;
335   SMESHGUI_SpinBox*   myYCoord;
336   SMESHGUI_SpinBox*   myZCoord;
337
338   QLineEdit*          myGroupName;
339
340   QPushButton*        addVertexButton;
341   QPushButton*        removeVertexButton;
342
343   QCheckBox           *myInternalEnforcedVerticesAllFaces;
344   QLineEdit           *myInternalEnforcedVerticesAllFacesGroup;
345
346
347   // Enforced meshes
348   QWidget*             myEnfMeshGroup;
349   StdMeshersGUI_ObjectReferenceParamWdg *myEnfMeshWdg;
350   QTableWidget*        myEnfMeshTableWdg;
351   QLineEdit*           myEnforcedGroupName;
352   QPushButton*         myAddEnfMeshButton;
353   QPushButton*         myRemoveEnfMeshButton;
354
355
356
357   // map =  entry , size map
358   QMap<QString, QString>          mySMPMap;           // Map <face entry, size>
359   QMap<QString, TAttractorVec >   myATTMap;           // Map <face entry, att. entry, etc>
360   QMap<QString, TopAbs_ShapeEnum> mySMPShapeTypeMap;
361   GeomSelectionTools*             GeomToolSelected;
362   LightApp_SelectionMgr*          aSel;
363
364   // Periodicity
365   QWidget*      myPeriodicityGroup;
366   QSplitter*    myPeriodicitySplitter;
367   QTreeWidget*  myPeriodicityTreeWidget;
368   QWidget*      myPeriodicityRightWidget;
369   QGridLayout*  myPeriodicityRightGridLayout;
370   QGroupBox*    myPeriodicityGroupBox1;
371   QGroupBox*    myPeriodicityGroupBox2;
372   QGridLayout* aPeriodicityLayout1;
373   QGridLayout*  myPeriodicityGroupBox1Layout;
374   QGridLayout*  myPeriodicityGroupBox2Layout;
375   QRadioButton* myPeriodicityOnFaceRadioButton;
376   QRadioButton* myPeriodicityOnEdgeRadioButton;
377   QLabel*       myPeriodicityMainSourceLabel;
378   QLabel*       myPeriodicityMainTargetLabel;
379   QLabel*       myPeriodicitySourceLabel;
380   QLabel*       myPeriodicityTargetLabel;
381   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicitySourceFaceWdg;
382   GEOM::GEOM_Object_var myPeriodicityFace;
383   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityTargetFaceWdg;
384   GEOM::GEOM_Object_var myPeriodicityEdge;
385   QLabel*       myPeriodicityP1SourceLabel;
386   QLabel*       myPeriodicityP2SourceLabel;
387   QLabel*       myPeriodicityP3SourceLabel;
388   QLabel*       myPeriodicityP1TargetLabel;
389   QLabel*       myPeriodicityP2TargetLabel;
390   QLabel*       myPeriodicityP3TargetLabel;
391   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP1SourceWdg;
392   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP2SourceWdg;
393   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP3SourceWdg;
394   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP1TargetWdg;
395   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP2TargetWdg;
396   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP3TargetWdg;
397   ListOfWidgets myPeriodicitySelectionWidgets;
398   QPushButton*  myPeriodicityAddButton;
399   QPushButton*  myPeriodicityRemoveButton;
400   QSpacerItem*  myPeriodicityVerticalSpacer;
401
402   QTableWidget*                      myHyPatchTable;
403   StdMeshersGUI_SubShapeSelectorWdg* myHyPatchFaceSelector;
404   QLineEdit*                         myHyPatchTagsLE;
405   QPushButton*                       myHyPatchFaceSelBtn;
406   QPushButton*                       myHyPatchGroupSelBtn;
407
408   BLSURFPlugin::string_array_var myOptions, myPreCADOptions, myCustomOptions;
409
410   PyObject *          main_mod;
411   PyObject *          main_dict;
412 };
413
414
415 class EnforcedTreeWidgetDelegate : public QItemDelegate
416 {
417   Q_OBJECT
418
419 public:
420   EnforcedTreeWidgetDelegate(QObject *parent = 0);
421
422   QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem & option,
423                         const QModelIndex &index) const;
424
425   void setEditorData(QWidget *editor, const QModelIndex &index) const;
426   void setModelData(QWidget *editor, QAbstractItemModel *model,
427                     const QModelIndex &index) const;
428
429   void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
430                             const QModelIndex &index) const;
431
432   bool vertexExists(QAbstractItemModel *model, const QModelIndex &index, QString value) const;
433 };
434
435 #endif // BLSURFPLUGINGUI_HypothesisCreator_H