]> SALOME platform Git repositories - plugins/blsurfplugin.git/blob - src/GUI/BLSURFPluginGUI_HypothesisCreator.h
Salome HOME
22625: [CEA 1195] Several attractors per face
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.h
1 // Copyright (C) 2007-2014  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;
167   double  myGradation, myAngleMesh, myChordalError;
168   bool    myAnisotropic, myRemoveTinyEdges, myForceBadElementRemoval;
169   double  myAnisotropicRatio, myTinyEdgeLength, myBadElementAspectRatio;
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 BLSURF 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                onOptionChosenInPopup( QAction* );
214   // Sizemap tab
215   void                onMapGeomContentModified();
216   void                onSmpItemClicked( QTreeWidgetItem *, int );
217   void                onTabChanged(int);
218   void                onAttractorClicked(int);
219   void                onConstSizeClicked(int);
220   void                onAddMap();
221   void                onRemoveMap();
222   void                onModifyMap();
223   void                onSetSizeMap(QTreeWidgetItem *, int);
224   // Enforced vertices tab
225   QTreeWidgetItem*    addEnforcedFace(std::string theFaceEntry, std::string theFaceName);
226   void                addEnforcedVertex(QTreeWidgetItem * theFaceItem, double x=0, double y=0, double z=0, 
227                                         std::string vertexName = "", std::string geomEntry = "", std::string groupName = "");
228   void                onAddEnforcedVertices();
229   void                onRemoveEnforcedVertex();
230   void                synchronizeCoords();
231   void                updateEnforcedVertexValues(QTreeWidgetItem* , int );
232   void                onSelectEnforcedVertex();
233 //   void                deactivateSelection(QWidget*, QWidget*);
234   void                clearEnforcedVertexWidgets();
235   void                onInternalVerticesClicked(int);
236   // Periodicity tab
237   void                onPeriodicityByVerticesChecked(bool);
238 //  void                onPeriodicityRadioButtonChanged();
239   void                onAddPeriodicity();
240   void                onRemovePeriodicity();
241   void                onPeriodicityTreeClicked(QTreeWidgetItem*, int);
242   void                onPeriodicityContentModified();
243
244 private:
245   bool                readParamsFromHypo( BlsurfHypothesisData& ) const;
246   QString             readParamsFromWidgets( BlsurfHypothesisData& ) const;
247   bool                storeParamsToHypo( const BlsurfHypothesisData& ) const;
248   bool                sizeMapsValidation();
249   bool                sizeMapValidationFromRow(int,bool displayError = true);
250   bool                sizeMapValidationFromEntry(QString,bool displayError = true);
251   GeomSelectionTools* getGeomSelectionTool() const;
252   GEOM::GEOM_Gen_var  getGeomEngine();
253   //void                insertElementType( TopAbs_ShapeEnum );
254   bool                insertElement( GEOM::GEOM_Object_var, bool modify = false );
255   bool                insertAttractor(GEOM::GEOM_Object_var, GEOM::GEOM_Object_var, bool modify = false);
256   int                 findRowFromEntry(QString entry);
257   CORBA::Object_var   entryToObject(QString entry);
258   static LightApp_SelectionMgr* selectionMgr();
259   void                avoidSimultaneousSelection(ListOfWidgets &myCustomWidgets) const;
260   void                AddPreCadSequenceToVector(BlsurfHypothesisData& h_data, BLSURFPlugin::TPeriodicityList_var preCadFacePeriodicityVector, bool onFace) const;
261
262 private:
263   
264   QTabWidget*             myTabWidget;
265   QWidget*                myStdGroup;
266   BLSURFPluginGUI_StdWidget* myStdWidget;
267   QLineEdit*              myName;
268
269   QWidget*                myAdvGroup;
270   BLSURFPluginGUI_AdvWidget* myAdvWidget;
271
272   // Sizemap widgets
273   QWidget                 *mySmpGroup;
274   QTreeWidget             *mySizeMapTable;
275   QPushButton             *addMapButton;
276   QPushButton             *removeMapButton;
277   QPushButton             *modifyMapButton;
278   QTabWidget              *smpTab; 
279   QWidget                 *myAttractorGroup;
280   QWidget                 *mySmpStdGroup;
281   QCheckBox               *myAttractorCheck;
282   QCheckBox               *myConstSizeCheck;
283   QGroupBox               *myDistanceGroup;
284 //   QGroupBox               *myParamsGroup;
285 //   QWidget                 *myParamsGroup;
286   SMESHGUI_SpinBox        *myAttSizeSpin;
287   SMESHGUI_SpinBox        *myAttDistSpin;
288   SMESHGUI_SpinBox        *myAttDistSpin2;
289   SMESHGUI_SpinBox        *mySmpSizeSpin;
290   QLabel                  *myAttDistLabel;
291   QLabel                  *myAttDistLabel2;
292   QLabel                  *myAttSizeLabel;
293   // Selection widgets for size maps
294   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg1;
295   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg2;
296   StdMeshersGUI_ObjectReferenceParamWdg *myAttSelWdg;
297   StdMeshersGUI_ObjectReferenceParamWdg *myDistSelWdg;
298   GEOM::GEOM_Object_var                  mySMapObject;
299   GEOM::GEOM_Object_var                  myAttObject;
300   GEOM::GEOM_Object_var                  myDistObject;
301   
302   
303   
304   
305   QWidget*            myEnfGroup;
306 //    TODO FACE AND VERTEX SELECTION
307   StdMeshersGUI_ObjectReferenceParamWdg *myEnfFaceWdg;
308   GEOM::GEOM_Object_var myEnfFace;
309   StdMeshersGUI_ObjectReferenceParamWdg *myEnfVertexWdg;
310   GEOM::GEOM_Object_var myEnfVertex;
311
312 //   DlgBlSurfHyp_Enforced* myEnforcedVertexWidget;
313   QTreeWidget*        myEnforcedTreeWidget;
314   SMESHGUI_SpinBox*   myXCoord;
315   SMESHGUI_SpinBox*   myYCoord;
316   SMESHGUI_SpinBox*   myZCoord;
317
318   QLineEdit*          myGroupName;
319 //   QGroupBox*          makeGroupsCheck;
320 //   QCheckBox*          myGlobalGroupName;
321
322   QPushButton*        addVertexButton;
323   QPushButton*        removeVertexButton;
324
325   QCheckBox           *myInternalEnforcedVerticesAllFaces;
326   QLineEdit           *myInternalEnforcedVerticesAllFacesGroup;
327
328   // map =  entry , size map
329   QMap<QString, QString>          mySMPMap;           // Map <face entry, size>
330   QMap<QString, TAttractorVec >   myATTMap;           // Map <face entry, att. entry, etc>
331   // QMap<QString, double>           myDistMap;          // Map <entry,distance with constant size> 
332   // QMap<QString, double>           myAttDistMap;       // Map <entry, influence distance> 
333   QMap<QString, TopAbs_ShapeEnum> mySMPShapeTypeMap;
334   GeomSelectionTools*             GeomToolSelected;
335   LightApp_SelectionMgr*          aSel;
336
337   // Periodicity
338   QWidget* myPeriodicityGroup;
339   QSplitter* myPeriodicitySplitter;
340   QTreeWidget* myPeriodicityTreeWidget;
341   QWidget* myPeriodicityRightWidget;
342   QGridLayout* myPeriodicityRightGridLayout;
343   QGroupBox* myPeriodicityGroupBox1;
344   QGroupBox* myPeriodicityGroupBox2;
345   QGridLayout* aPeriodicityLayout1;
346   QGridLayout* myPeriodicityGroupBox1Layout;
347   QGridLayout* myPeriodicityGroupBox2Layout;
348   QRadioButton* myPeriodicityOnFaceRadioButton;
349   QRadioButton* myPeriodicityOnEdgeRadioButton;
350   QLabel* myPeriodicityMainSourceLabel;
351   QLabel* myPeriodicityMainTargetLabel;
352   QLabel* myPeriodicitySourceLabel;
353   QLabel* myPeriodicityTargetLabel;
354   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicitySourceFaceWdg;
355 //  StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicitySourceEdgeWdg;
356   GEOM::GEOM_Object_var myPeriodicityFace;
357   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityTargetFaceWdg;
358 //  StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityTargetEdgeWdg;
359   GEOM::GEOM_Object_var myPeriodicityEdge;
360   QLabel* myPeriodicityP1SourceLabel;
361   QLabel* myPeriodicityP2SourceLabel;
362   QLabel* myPeriodicityP3SourceLabel;
363   QLabel* myPeriodicityP1TargetLabel;
364   QLabel* myPeriodicityP2TargetLabel;
365   QLabel* myPeriodicityP3TargetLabel;
366   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP1SourceWdg;
367   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP2SourceWdg;
368   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP3SourceWdg;
369   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP1TargetWdg;
370   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP2TargetWdg;
371   StdMeshersGUI_ObjectReferenceParamWdg* myPeriodicityP3TargetWdg;
372   ListOfWidgets myPeriodicitySelectionWidgets;
373   QPushButton* myPeriodicityAddButton;
374   QPushButton* myPeriodicityRemoveButton;
375   QSpacerItem* myPeriodicityVerticalSpacer;
376
377   BLSURFPlugin::string_array_var myOptions, myPreCADOptions;
378
379   PyObject *          main_mod;
380   PyObject *          main_dict;
381 };
382
383
384 class EnforcedTreeWidgetDelegate : public QItemDelegate
385 {
386     Q_OBJECT
387
388 public:
389   EnforcedTreeWidgetDelegate(QObject *parent = 0);
390
391   QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
392                         const QModelIndex &index) const;
393
394   void setEditorData(QWidget *editor, const QModelIndex &index) const;
395   void setModelData(QWidget *editor, QAbstractItemModel *model,
396                     const QModelIndex &index) const;
397
398   void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
399                     const QModelIndex &index) const;
400
401   bool vertexExists(QAbstractItemModel *model, const QModelIndex &index, QString value) const;
402 };
403
404 #endif // BLSURFPLUGINGUI_HypothesisCreator_H