]> SALOME platform Git repositories - plugins/blsurfplugin.git/blob - src/GUI/BLSURFPluginGUI_HypothesisCreator.h
Salome HOME
Porting to OCCT 7.8.0
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.h
1 // Copyright (C) 2007-2024  CEA, EDF
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 #include <Python.h>
50 #ifdef WIN32
51 // E.A. : On windows with python 2.6, there is a conflict
52 // E.A. : between pymath.h and Standard_math.h which define
53 // E.A. : some same symbols : acosh, asinh, ...
54 #include <Standard_Real.hxx>
55 #include <pymath.h>
56 #endif
57
58 #include <QItemDelegate>
59
60 #include <SMESHGUI_Hypotheses.h>
61 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
62 #include <SALOMEconfig.h>
63 #include <cstring>
64 #include <map>
65 #include <set>
66 #include <vector>
67 #include <TopAbs_ShapeEnum.hxx>
68 #include <GeomSelectionTools.h>
69 #include <GEOM_Client.hxx>
70 #include CORBA_SERVER_HEADER(BLSURFPlugin_Algorithm)
71
72 class QGroupBox;
73 class QComboBox;
74 class QCheckBox;
75 class QLineEdit;
76 class QRadioButton;
77 class QTableWidget;
78 class QTreeWidget;
79 class QModelIndex;
80 class QSpinBox;
81 class QDoubleSpinBox;
82 class QMenu;
83 class QAction;
84 class QTreeWidgetItem;
85 class QTableWidgetItem;
86 class QObject;
87 class QSplitter;
88 class QGridLayout;
89 class QVBoxLayout;
90 class QSpacerItem;
91
92 class SMESHGUI_SpinBox;
93 class SMESH_NumberFilter;
94 class LightApp_SelectionMgr;
95 class BLSURFPluginGUI_StdWidget;
96 class BLSURFPluginGUI_AdvWidget;
97 class StdMeshersGUI_SubShapeSelectorWdg;
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    mySmpsurface,mySmpedge,mySmppoint,myEnforcedVertex,myInternalEnforcedVerticesAllFaces;
172   int     myElementType;
173   bool    myUseSurfaceProximity;
174   int     myNbSurfaceProximityLayers;
175   double  mySurfaceProximityRatio;
176   bool    myUseVolumeProximity;
177   int     myNbVolumeProximityLayers;
178   double  myVolumeProximityRatio;
179   // bool    myPreCADMergeEdges, myPreCADProcess3DTopology, myPreCADDiscardInput;
180 //   bool    myGMFFileMode;
181   std::string myGMFFileName, myInternalEnforcedVerticesAllFacesGroup;
182   TEnfVertexList enfVertexList;
183   TFaceEntryEnfVertexListMap faceEntryEnfVertexListMap;
184   /* TODO GROUPS
185   TGroupNameEnfVertexListMap groupNameEnfVertexListMap;
186   */
187   TPreCadPeriodicityVector preCadPeriodicityVector;
188   QStringList hyperpatches, hyperEntries;
189   QString myName;
190 } BlsurfHypothesisData;
191
192
193 /*!
194  * \brief Class for creation of MG-CADSurf hypotheses
195 */
196 class BLSURFPLUGIN_GUI_EXPORT BLSURFPluginGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator
197 {
198   Q_OBJECT
199
200 public:
201   BLSURFPluginGUI_HypothesisCreator( const QString& );
202   virtual ~BLSURFPluginGUI_HypothesisCreator();
203
204   virtual bool        checkParams(QString& msg) const;
205   virtual QString     helpPage() const;
206
207 protected:
208   virtual QFrame*     buildFrame    ();
209   virtual void        retrieveParams() const;
210   virtual QString     storeParams   () const;
211
212   virtual QString     caption() const;
213   virtual QPixmap     icon() const;
214   virtual QString     type() const;
215
216 protected slots:
217   void                onStateChange();
218   // Advanced tab
219   void                onAddOption();
220   void                onChangeOptionName( int, int );
221   // Sizemap tab
222   void                onMapGeomContentModified();
223   void                onSmpItemClicked( QTreeWidgetItem *, int );
224   void                onTabChanged(int);
225   void                onAttractorClicked(int);
226   void                onConstSizeClicked(int);
227   void                onAddMap();
228   void                onRemoveMap();
229   void                onModifyMap();
230   void                onSetSizeMap(QTreeWidgetItem *, int);
231   // Enforced vertices tab
232   QTreeWidgetItem*    addEnforcedFace(std::string theFaceEntry, std::string theFaceName);
233   void                addEnforcedVertex(double x=0, double y=0, double z=0, 
234                                         std::string vertexName = "",
235                                         std::string geomEntry = "",
236                                         std::string groupName = "");
237   void                onAddEnforcedVertices();
238   void                onRemoveEnforcedVertex();
239   void                synchronizeCoords();
240   void                updateEnforcedVertexValues(QTreeWidgetItem* , int );
241   void                onSelectEnforcedVertex();
242   void                clearEnforcedVertexWidgets();
243   void                onInternalVerticesClicked(int);
244   // Enforced mesh tab
245   void                onAddEnforcedMesh();
246   void                onRemoveEnforcedMesh();
247   void                onEnforcedMeshSelected();
248   void                onEnfMeshTableSelected();
249   // Periodicity tab
250   void                onPeriodicityByVerticesChecked(bool);
251   void                onAddPeriodicity();
252   void                onRemovePeriodicity();
253   void                onPeriodicityTreeClicked(QTreeWidgetItem*, int);
254   void                onPeriodicityContentModified();
255   // HyperPatch tab
256   void                onHyPatchFaceSelection(bool);
257   void                onHyPatchGroupSelection(bool);
258   void                onHyPatchSelectionChanged();
259   void                onHyPatchAdd();
260   void                onHyPatchRemove();
261
262 private:
263   bool                readParamsFromHypo( BlsurfHypothesisData& ) const;
264   QString             readParamsFromWidgets( BlsurfHypothesisData& ) const;
265   bool                storeParamsToHypo( const BlsurfHypothesisData& ) const;
266   bool                sizeMapsValidation();
267   bool                sizeMapValidationFromRow(int,bool displayError = true);
268   bool                sizeMapValidationFromEntry(QString,bool displayError = true);
269   GeomSelectionTools* getGeomSelectionTool() const;
270   GEOM::GEOM_Gen_var  getGeomEngine();
271   bool                insertElement( GEOM::GEOM_Object_var, bool modify = false );
272   bool                insertAttractor(GEOM::GEOM_Object_var, GEOM::GEOM_Object_var, bool modify = false);
273   int                 findRowFromEntry(QString entry);
274   CORBA::Object_var   entryToObject(QString entry);
275   static LightApp_SelectionMgr* selectionMgr();
276   void                avoidSimultaneousSelection(ListOfWidgets &myCustomWidgets) const;
277   void                AddPreCadSequenceToVector(BlsurfHypothesisData& h_data, BLSURFPlugin::TPeriodicityList_var preCadFacePeriodicityVector, bool onFace) const;
278   void                addHyPatchToTable(const QString& tags, const QString& entries);
279   bool                hasGeom() const;
280
281   void                addEnforcedMesh( SMESH::SMESH_IDSource_ptr mesh, const QString& groupName );
282
283 private:
284   
285   QTabWidget*             myTabWidget;
286   QWidget*                myStdGroup;
287   BLSURFPluginGUI_StdWidget* myStdWidget;
288   QLineEdit*              myName;
289
290   QWidget*                myAdvGroup;
291   BLSURFPluginGUI_AdvWidget* myAdvWidget;
292
293   // Sizemap widgets
294   QWidget                 *mySmpGroup;
295   QTreeWidget             *mySizeMapTable;
296   QPushButton             *addMapButton;
297   QPushButton             *removeMapButton;
298   QPushButton             *modifyMapButton;
299   QTabWidget              *smpTab; 
300   QWidget                 *myAttractorGroup;
301   QWidget                 *mySmpStdGroup;
302   QCheckBox               *myAttractorCheck;
303   QCheckBox               *myConstSizeCheck;
304   QGroupBox               *myDistanceGroup;
305 //   QGroupBox               *myParamsGroup;
306 //   QWidget                 *myParamsGroup;
307   SMESHGUI_SpinBox        *myAttSizeSpin;
308   SMESHGUI_SpinBox        *myAttDistSpin;
309   SMESHGUI_SpinBox        *myAttDistSpin2;
310   SMESHGUI_SpinBox        *mySmpSizeSpin;
311   QLabel                  *myAttDistLabel;
312   QLabel                  *myAttDistLabel2;
313   QLabel                  *myAttSizeLabel;
314   // Selection widgets for size maps
315   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg1;
316   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg2;
317   StdMeshersGUI_ObjectReferenceParamWdg *myAttSelWdg;
318   StdMeshersGUI_ObjectReferenceParamWdg *myDistSelWdg;
319   GEOM::GEOM_Object_var                  mySMapObject;
320   GEOM::GEOM_Object_var                  myAttObject;
321   GEOM::GEOM_Object_var                  myDistObject;
322   
323   
324   
325   
326   QWidget*            myEnfGroup;
327   StdMeshersGUI_ObjectReferenceParamWdg *myEnfFaceWdg;
328   GEOM::GEOM_Object_var myEnfFace;
329   StdMeshersGUI_ObjectReferenceParamWdg *myEnfVertexWdg;
330   GEOM::GEOM_Object_var myEnfVertex;
331
332   QTreeWidget*        myEnforcedTreeWidget;
333   SMESHGUI_SpinBox*   myXCoord;
334   SMESHGUI_SpinBox*   myYCoord;
335   SMESHGUI_SpinBox*   myZCoord;
336
337   QLineEdit*          myGroupName;
338
339   QPushButton*        addVertexButton;
340   QPushButton*        removeVertexButton;
341
342   QCheckBox           *myInternalEnforcedVerticesAllFaces;
343   QLineEdit           *myInternalEnforcedVerticesAllFacesGroup;
344
345
346   // Enforced meshes
347   QWidget*             myEnfMeshGroup;
348   StdMeshersGUI_ObjectReferenceParamWdg *myEnfMeshWdg;
349   QTableWidget*        myEnfMeshTableWdg;
350   QLineEdit*           myEnforcedGroupName;
351   QPushButton*         myAddEnfMeshButton;
352   QPushButton*         myRemoveEnfMeshButton;
353
354
355
356   // map =  entry , size map
357   QMap<QString, QString>          mySMPMap;           // Map <face entry, size>
358   QMap<QString, TAttractorVec >   myATTMap;           // Map <face entry, att. entry, etc>
359   QMap<QString, TopAbs_ShapeEnum> mySMPShapeTypeMap;
360   GeomSelectionTools*             GeomToolSelected;
361   LightApp_SelectionMgr*          aSel;
362
363   // Periodicity
364   QWidget*      myPeriodicityGroup;
365   QSplitter*    myPeriodicitySplitter;
366   QTreeWidget*  myPeriodicityTreeWidget;
367   QWidget*      myPeriodicityRightWidget;
368   QGridLayout*  myPeriodicityRightGridLayout;
369   QGroupBox*    myPeriodicityGroupBox1;
370   QGroupBox*    myPeriodicityGroupBox2;
371   QGridLayout* aPeriodicityLayout1;
372   QGridLayout*  myPeriodicityGroupBox1Layout;
373   QGridLayout*  myPeriodicityGroupBox2Layout;
374   QRadioButton* myPeriodicityOnFaceRadioButton;
375   QRadioButton* myPeriodicityOnEdgeRadioButton;
376   QLabel*       myPeriodicityMainSourceLabel;
377   QLabel*       myPeriodicityMainTargetLabel;
378   QLabel*       myPeriodicitySourceLabel;
379   QLabel*       myPeriodicityTargetLabel;
380   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicitySourceFaceWdg;
381   GEOM::GEOM_Object_var myPeriodicityFace;
382   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityTargetFaceWdg;
383   GEOM::GEOM_Object_var myPeriodicityEdge;
384   QLabel*       myPeriodicityP1SourceLabel;
385   QLabel*       myPeriodicityP2SourceLabel;
386   QLabel*       myPeriodicityP3SourceLabel;
387   QLabel*       myPeriodicityP1TargetLabel;
388   QLabel*       myPeriodicityP2TargetLabel;
389   QLabel*       myPeriodicityP3TargetLabel;
390   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP1SourceWdg;
391   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP2SourceWdg;
392   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP3SourceWdg;
393   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP1TargetWdg;
394   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP2TargetWdg;
395   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP3TargetWdg;
396   ListOfWidgets myPeriodicitySelectionWidgets;
397   QPushButton*  myPeriodicityAddButton;
398   QPushButton*  myPeriodicityRemoveButton;
399   QSpacerItem*  myPeriodicityVerticalSpacer;
400
401   QTableWidget*                      myHyPatchTable;
402   StdMeshersGUI_SubShapeSelectorWdg* myHyPatchFaceSelector;
403   QLineEdit*                         myHyPatchTagsLE;
404   QPushButton*                       myHyPatchFaceSelBtn;
405   QPushButton*                       myHyPatchGroupSelBtn;
406
407   BLSURFPlugin::string_array_var myOptions, myPreCADOptions, myCustomOptions;
408
409   PyObject *          main_mod;
410   PyObject *          main_dict;
411 };
412
413
414 class EnforcedTreeWidgetDelegate : public QItemDelegate
415 {
416   Q_OBJECT
417
418 public:
419   EnforcedTreeWidgetDelegate(QObject *parent = 0);
420
421   QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem & option,
422                         const QModelIndex &index) const;
423
424   void setEditorData(QWidget *editor, const QModelIndex &index) const;
425   void setModelData(QWidget *editor, QAbstractItemModel *model,
426                     const QModelIndex &index) const;
427
428   void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
429                             const QModelIndex &index) const;
430
431   bool vertexExists(QAbstractItemModel *model, const QModelIndex &index, QString value) const;
432 };
433
434 #endif // BLSURFPLUGINGUI_HypothesisCreator_H