]> SALOME platform Git repositories - plugins/blsurfplugin.git/blob - src/GUI/BLSURFPluginGUI_HypothesisCreator.h
Salome HOME
Add full-quadrangles support, available since MeshGems v2.5
[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 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   long    myElementType;
174   // bool    myPreCADMergeEdges, myPreCADProcess3DTopology, myPreCADDiscardInput;
175 //   bool    myGMFFileMode;
176   std::string myGMFFileName, myInternalEnforcedVerticesAllFacesGroup;
177   TEnfVertexList enfVertexList;
178   TFaceEntryEnfVertexListMap faceEntryEnfVertexListMap;
179   /* TODO GROUPS
180   TGroupNameEnfVertexListMap groupNameEnfVertexListMap;
181   */
182   TPreCadPeriodicityVector preCadPeriodicityVector;
183   QStringList hyperpatches;
184   QString myName;
185 } BlsurfHypothesisData;
186
187
188 /*!
189  * \brief Class for creation of MG-CADSurf hypotheses
190 */
191 class BLSURFPLUGIN_GUI_EXPORT BLSURFPluginGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator
192 {
193   Q_OBJECT
194
195 public:
196   BLSURFPluginGUI_HypothesisCreator( const QString& );
197   virtual ~BLSURFPluginGUI_HypothesisCreator();
198
199   virtual bool        checkParams(QString& msg) const;
200   virtual QString     helpPage() const;
201
202 protected:
203   virtual QFrame*     buildFrame    ();
204   virtual void        retrieveParams() const;
205   virtual QString     storeParams   () const;
206
207   virtual QString     caption() const;
208   virtual QPixmap     icon() const;
209   virtual QString     type() const;
210
211 protected slots:
212   void                onStateChange();
213   // Advanced tab
214   void                onAddOption();
215   void                onChangeOptionName( int, int );
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 = "",
230                                         std::string geomEntry = "",
231                                         std::string groupName = "");
232   void                onAddEnforcedVertices();
233   void                onRemoveEnforcedVertex();
234   void                synchronizeCoords();
235   void                updateEnforcedVertexValues(QTreeWidgetItem* , int );
236   void                onSelectEnforcedVertex();
237   void                clearEnforcedVertexWidgets();
238   void                onInternalVerticesClicked(int);
239   // Periodicity tab
240   void                onPeriodicityByVerticesChecked(bool);
241   void                onAddPeriodicity();
242   void                onRemovePeriodicity();
243   void                onPeriodicityTreeClicked(QTreeWidgetItem*, int);
244   void                onPeriodicityContentModified();
245   // HyperPatch tab
246   void                onHyPatchFaceSelection(bool);
247   void                onHyPatchGroupSelection(bool);
248   void                onHyPatchSelectionChanged();
249   void                onHyPatchAdd();
250   void                onHyPatchRemove();
251
252 private:
253   bool                readParamsFromHypo( BlsurfHypothesisData& ) const;
254   QString             readParamsFromWidgets( BlsurfHypothesisData& ) const;
255   bool                storeParamsToHypo( const BlsurfHypothesisData& ) const;
256   bool                sizeMapsValidation();
257   bool                sizeMapValidationFromRow(int,bool displayError = true);
258   bool                sizeMapValidationFromEntry(QString,bool displayError = true);
259   GeomSelectionTools* getGeomSelectionTool() const;
260   GEOM::GEOM_Gen_var  getGeomEngine();
261   bool                insertElement( GEOM::GEOM_Object_var, bool modify = false );
262   bool                insertAttractor(GEOM::GEOM_Object_var, GEOM::GEOM_Object_var, bool modify = false);
263   int                 findRowFromEntry(QString entry);
264   CORBA::Object_var   entryToObject(QString entry);
265   static LightApp_SelectionMgr* selectionMgr();
266   void                avoidSimultaneousSelection(ListOfWidgets &myCustomWidgets) const;
267   void                AddPreCadSequenceToVector(BlsurfHypothesisData& h_data, BLSURFPlugin::TPeriodicityList_var preCadFacePeriodicityVector, bool onFace) const;
268   void                addHyPatchToTable(const QString& tags);
269   bool                hasGeom() const;
270
271 private:
272   
273   QTabWidget*             myTabWidget;
274   QWidget*                myStdGroup;
275   BLSURFPluginGUI_StdWidget* myStdWidget;
276   QLineEdit*              myName;
277
278   QWidget*                myAdvGroup;
279   BLSURFPluginGUI_AdvWidget* myAdvWidget;
280
281   // Sizemap widgets
282   QWidget                 *mySmpGroup;
283   QTreeWidget             *mySizeMapTable;
284   QPushButton             *addMapButton;
285   QPushButton             *removeMapButton;
286   QPushButton             *modifyMapButton;
287   QTabWidget              *smpTab; 
288   QWidget                 *myAttractorGroup;
289   QWidget                 *mySmpStdGroup;
290   QCheckBox               *myAttractorCheck;
291   QCheckBox               *myConstSizeCheck;
292   QGroupBox               *myDistanceGroup;
293 //   QGroupBox               *myParamsGroup;
294 //   QWidget                 *myParamsGroup;
295   SMESHGUI_SpinBox        *myAttSizeSpin;
296   SMESHGUI_SpinBox        *myAttDistSpin;
297   SMESHGUI_SpinBox        *myAttDistSpin2;
298   SMESHGUI_SpinBox        *mySmpSizeSpin;
299   QLabel                  *myAttDistLabel;
300   QLabel                  *myAttDistLabel2;
301   QLabel                  *myAttSizeLabel;
302   // Selection widgets for size maps
303   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg1;
304   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg2;
305   StdMeshersGUI_ObjectReferenceParamWdg *myAttSelWdg;
306   StdMeshersGUI_ObjectReferenceParamWdg *myDistSelWdg;
307   GEOM::GEOM_Object_var                  mySMapObject;
308   GEOM::GEOM_Object_var                  myAttObject;
309   GEOM::GEOM_Object_var                  myDistObject;
310   
311   
312   
313   
314   QWidget*            myEnfGroup;
315   StdMeshersGUI_ObjectReferenceParamWdg *myEnfFaceWdg;
316   GEOM::GEOM_Object_var myEnfFace;
317   StdMeshersGUI_ObjectReferenceParamWdg *myEnfVertexWdg;
318   GEOM::GEOM_Object_var myEnfVertex;
319
320   QTreeWidget*        myEnforcedTreeWidget;
321   SMESHGUI_SpinBox*   myXCoord;
322   SMESHGUI_SpinBox*   myYCoord;
323   SMESHGUI_SpinBox*   myZCoord;
324
325   QLineEdit*          myGroupName;
326
327   QPushButton*        addVertexButton;
328   QPushButton*        removeVertexButton;
329
330   QCheckBox           *myInternalEnforcedVerticesAllFaces;
331   QLineEdit           *myInternalEnforcedVerticesAllFacesGroup;
332
333   // map =  entry , size map
334   QMap<QString, QString>          mySMPMap;           // Map <face entry, size>
335   QMap<QString, TAttractorVec >   myATTMap;           // Map <face entry, att. entry, etc>
336   QMap<QString, TopAbs_ShapeEnum> mySMPShapeTypeMap;
337   GeomSelectionTools*             GeomToolSelected;
338   LightApp_SelectionMgr*          aSel;
339
340   // Periodicity
341   QWidget*      myPeriodicityGroup;
342   QSplitter*    myPeriodicitySplitter;
343   QTreeWidget*  myPeriodicityTreeWidget;
344   QWidget*      myPeriodicityRightWidget;
345   QGridLayout*  myPeriodicityRightGridLayout;
346   QGroupBox*    myPeriodicityGroupBox1;
347   QGroupBox*    myPeriodicityGroupBox2;
348   QGridLayout* aPeriodicityLayout1;
349   QGridLayout*  myPeriodicityGroupBox1Layout;
350   QGridLayout*  myPeriodicityGroupBox2Layout;
351   QRadioButton* myPeriodicityOnFaceRadioButton;
352   QRadioButton* myPeriodicityOnEdgeRadioButton;
353   QLabel*       myPeriodicityMainSourceLabel;
354   QLabel*       myPeriodicityMainTargetLabel;
355   QLabel*       myPeriodicitySourceLabel;
356   QLabel*       myPeriodicityTargetLabel;
357   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicitySourceFaceWdg;
358   GEOM::GEOM_Object_var myPeriodicityFace;
359   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityTargetFaceWdg;
360   GEOM::GEOM_Object_var myPeriodicityEdge;
361   QLabel*       myPeriodicityP1SourceLabel;
362   QLabel*       myPeriodicityP2SourceLabel;
363   QLabel*       myPeriodicityP3SourceLabel;
364   QLabel*       myPeriodicityP1TargetLabel;
365   QLabel*       myPeriodicityP2TargetLabel;
366   QLabel*       myPeriodicityP3TargetLabel;
367   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP1SourceWdg;
368   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP2SourceWdg;
369   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP3SourceWdg;
370   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP1TargetWdg;
371   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP2TargetWdg;
372   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP3TargetWdg;
373   ListOfWidgets myPeriodicitySelectionWidgets;
374   QPushButton*  myPeriodicityAddButton;
375   QPushButton*  myPeriodicityRemoveButton;
376   QSpacerItem*  myPeriodicityVerticalSpacer;
377
378   QTableWidget*                      myHyPatchTable;
379   StdMeshersGUI_SubShapeSelectorWdg* myHyPatchFaceSelector;
380   QLineEdit*                         myHyPatchTagsLE;
381   QPushButton*                       myHyPatchFaceSelBtn;
382   QPushButton*                       myHyPatchGroupSelBtn;
383
384   BLSURFPlugin::string_array_var myOptions, myPreCADOptions, myCustomOptions;
385
386   PyObject *          main_mod;
387   PyObject *          main_dict;
388 };
389
390
391 class EnforcedTreeWidgetDelegate : public QItemDelegate
392 {
393     Q_OBJECT
394
395 public:
396   EnforcedTreeWidgetDelegate(QObject *parent = 0);
397
398   QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
399                         const QModelIndex &index) const;
400
401   void setEditorData(QWidget *editor, const QModelIndex &index) const;
402   void setModelData(QWidget *editor, QAbstractItemModel *model,
403                     const QModelIndex &index) const;
404
405   void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
406                     const QModelIndex &index) const;
407
408   bool vertexExists(QAbstractItemModel *model, const QModelIndex &index, QString value) const;
409 };
410
411 #endif // BLSURFPLUGINGUI_HypothesisCreator_H