]> SALOME platform Git repositories - plugins/blsurfplugin.git/blob - src/GUI/BLSURFPluginGUI_HypothesisCreator.h
Salome HOME
+ <source>ZERO_VALUE_OF</source>
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.h
1 // Copyright (C) 2007-2013  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.
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 WNT
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
89 class SMESHGUI_SpinBox;
90 class LightApp_SelectionMgr;
91 class BLSURFPluginGUI_StdWidget;
92 class BLSURFPluginGUI_AdvWidget;
93 // class DlgBlSurfHyp_Enforced;
94
95 // Name
96 typedef std::string TEnfName;
97 // Entry
98 typedef std::string TEntry;
99 // List of entries
100 typedef std::set<TEntry> TEntryList;
101 // Enforced vertex = 3 coordinates
102 typedef std::vector<double> TEnfVertexCoords;
103 // List of enforced vertices
104 typedef std::set< TEnfVertexCoords > TEnfVertexCoordsList;
105 // Enforced vertex
106 struct TEnfVertex{
107   TEnfName name;
108   TEntry geomEntry;
109   TEnfVertexCoords coords;
110   TEnfName grpName;
111 };
112
113
114 struct CompareEnfVertices
115 {
116   bool operator () (const TEnfVertex* e1, const TEnfVertex* e2) const {
117     if (e1 && e2) {
118       if (e1->coords.size() && e2->coords.size())
119         return (e1->coords < e2->coords);
120       else
121         return (e1->geomEntry < e2->geomEntry);
122     }
123     return false;
124   }
125 };
126
127 // List of enforced vertices
128 typedef std::set< TEnfVertex*, CompareEnfVertices > TEnfVertexList;
129
130 // Map Face Entry / List of enforced vertices
131 typedef std::map< TEntry, TEnfVertexList > TFaceEntryEnfVertexListMap;
132
133 // Map Face Entry / InternalEnforcedVertices
134 typedef std::map< TEntry, bool > TFaceEntryInternalVerticesMap;
135
136 typedef struct
137 {
138   int     myTopology, myVerbosity;
139   int     myPhysicalMesh, myGeometricMesh;
140   double  myPhySize, myMinSize, myMaxSize;
141   bool    myPhySizeRel, myMinSizeRel, myMaxSizeRel;
142   bool    myUseMinSize, myUseMaxSize;
143   double  myGradation, myAngleMesh, myChordalError;
144   bool    myAnisotropic, myRemoveTinyEdges, myForceBadElementRemoval;
145   double  myAnisotropicRatio, myTinyEdgeLength, myBadElementAspectRatio;
146   bool    myOptimizeMesh, myQuadraticMesh;
147   bool    myAllowQuadrangles, mySmpsurface,mySmpedge,mySmppoint,myEnforcedVertex,myInternalEnforcedVerticesAllFaces;
148   bool    myPreCADMergeEdges, myPreCADProcess3DTopology, myPreCADDiscardInput;
149 //   bool    myGMFFileMode;
150   std::string myGMFFileName, myInternalEnforcedVerticesAllFacesGroup;
151   TEnfVertexList enfVertexList;
152   TFaceEntryEnfVertexListMap faceEntryEnfVertexListMap;
153   /* TODO GROUPS
154   TGroupNameEnfVertexListMap groupNameEnfVertexListMap;
155   */
156   QString myName;
157 } BlsurfHypothesisData;
158
159
160 /*!
161  * \brief Class for creation of BLSURF hypotheses
162 */
163 class BLSURFPLUGIN_GUI_EXPORT BLSURFPluginGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator
164 {
165   Q_OBJECT
166
167 public:
168   BLSURFPluginGUI_HypothesisCreator( const QString& );
169   virtual ~BLSURFPluginGUI_HypothesisCreator();
170
171   virtual bool        checkParams(QString& msg) const;
172   virtual QString     helpPage() const;
173
174 protected:
175   virtual QFrame*     buildFrame    ();
176   virtual void        retrieveParams() const;
177   virtual QString     storeParams   () const;
178
179   virtual QString     caption() const;
180   virtual QPixmap     icon() const;
181   virtual QString     type() const;
182
183 protected slots:
184   // Advanced tab
185   void                onAddOption();
186   void                onDeleteOption();
187   void                onOptionChosenInPopup( QAction* );
188   // Sizemap tab
189   void                onMapGeomContentModified();
190   void                onSmpItemClicked( QTreeWidgetItem *, int );
191   void                onSmpTabChanged(int);
192   void                onAttractorClicked(int);
193   void                onConstSizeClicked(int);
194   void                onAddMap();
195   void                onRemoveMap();
196   void                onModifyMap();
197   void                onSetSizeMap(QTreeWidgetItem *, int);
198   // Enforced vertices tab
199   QTreeWidgetItem*    addEnforcedFace(std::string theFaceEntry, std::string theFaceName);
200   void                addEnforcedVertex(QTreeWidgetItem * theFaceItem, double x=0, double y=0, double z=0, 
201                                         std::string vertexName = "", std::string geomEntry = "", std::string groupName = "");
202   void                onAddEnforcedVertices();
203   void                onRemoveEnforcedVertex();
204   void                synchronizeCoords();
205   void                updateEnforcedVertexValues(QTreeWidgetItem* , int );
206   void                onSelectEnforcedVertex();
207 //   void                deactivateSelection(QWidget*, QWidget*);
208   void                clearEnforcedVertexWidgets();
209   void                onInternalVerticesClicked(int);
210
211 private:
212   bool                readParamsFromHypo( BlsurfHypothesisData& ) const;
213   QString             readParamsFromWidgets( BlsurfHypothesisData& ) const;
214   bool                storeParamsToHypo( const BlsurfHypothesisData& ) const;
215   bool                sizeMapsValidation();
216   bool                sizeMapValidationFromRow(int,bool displayError = true);
217   bool                sizeMapValidationFromEntry(QString,bool displayError = true);
218   GeomSelectionTools* getGeomSelectionTool();
219   GEOM::GEOM_Gen_var  getGeomEngine();
220   //void                insertElementType( TopAbs_ShapeEnum );
221   bool                insertElement( GEOM::GEOM_Object_var, bool modify = false );
222   bool                insertAttractor(GEOM::GEOM_Object_var, GEOM::GEOM_Object_var, bool modify = false);
223   int                 findRowFromEntry(QString entry);
224   CORBA::Object_var   entryToObject(QString entry);
225   static LightApp_SelectionMgr* selectionMgr();
226
227 private:
228   
229   QTabWidget*             myTabWidget;
230   QWidget*                myStdGroup;
231   BLSURFPluginGUI_StdWidget* myStdWidget;
232   QLineEdit*              myName;
233
234   QWidget*                myAdvGroup;
235   BLSURFPluginGUI_AdvWidget* myAdvWidget;
236
237   // Sizemap widgets
238   QWidget                 *mySmpGroup;
239   QTreeWidget             *mySizeMapTable;
240   QPushButton             *addMapButton;
241   QPushButton             *removeMapButton;
242   QPushButton             *modifyMapButton;
243   QTabWidget              *smpTab; 
244   QWidget                 *myAttractorGroup;
245   QWidget                 *mySmpStdGroup;
246   QCheckBox               *myAttractorCheck;
247   QCheckBox               *myConstSizeCheck;
248   QGroupBox               *myDistanceGroup;
249 //   QGroupBox               *myParamsGroup;
250 //   QWidget                 *myParamsGroup;
251   SMESHGUI_SpinBox        *myAttSizeSpin;
252   SMESHGUI_SpinBox        *myAttDistSpin;
253   SMESHGUI_SpinBox        *myAttDistSpin2;
254   SMESHGUI_SpinBox        *mySmpSizeSpin;
255   QLabel                  *myAttDistLabel;
256   QLabel                  *myAttDistLabel2;
257   QLabel                  *myAttSizeLabel;
258   // Selection widgets for size maps
259   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg1;
260   StdMeshersGUI_ObjectReferenceParamWdg *myGeomSelWdg2;
261   StdMeshersGUI_ObjectReferenceParamWdg *myAttSelWdg;
262   StdMeshersGUI_ObjectReferenceParamWdg *myDistSelWdg;
263   GEOM::GEOM_Object_var                  mySMapObject;
264   GEOM::GEOM_Object_var                  myAttObject;
265   GEOM::GEOM_Object_var                  myDistObject;
266   
267   
268   
269   
270   QWidget*            myEnfGroup;
271 //    TODO FACE AND VERTEX SELECTION
272   StdMeshersGUI_ObjectReferenceParamWdg *myEnfFaceWdg;
273   GEOM::GEOM_Object_var myEnfFace;
274   StdMeshersGUI_ObjectReferenceParamWdg *myEnfVertexWdg;
275   GEOM::GEOM_Object_var myEnfVertex;
276
277 //   DlgBlSurfHyp_Enforced* myEnforcedVertexWidget;
278   QTreeWidget*        myEnforcedTreeWidget;
279   SMESHGUI_SpinBox*   myXCoord;
280   SMESHGUI_SpinBox*   myYCoord;
281   SMESHGUI_SpinBox*   myZCoord;
282
283   QLineEdit*          myGroupName;
284 //   QGroupBox*          makeGroupsCheck;
285 //   QCheckBox*          myGlobalGroupName;
286
287   QPushButton*        addVertexButton;
288   QPushButton*        removeVertexButton;
289
290   QCheckBox           *myInternalEnforcedVerticesAllFaces;
291   QLineEdit           *myInternalEnforcedVerticesAllFacesGroup;
292
293   // map =  entry , size map
294   QMap<QString, QString>          mySMPMap;           // Map <face entry, size>
295   QMap<QString, QString>          myATTMap;           // Map <face entry, att. entry>
296   QMap<QString, double>           myDistMap;          // Map <entry,distance with constant size> 
297   QMap<QString, double>           myAttDistMap;       // Map <entry, influence distance> 
298   QMap<QString, TopAbs_ShapeEnum> mySMPShapeTypeMap;
299   GeomSelectionTools*             GeomToolSelected;
300   LightApp_SelectionMgr*          aSel;
301
302   BLSURFPlugin::string_array_var myOptions, myPreCADOptions;
303
304   PyObject *          main_mod;
305   PyObject *          main_dict;
306 };
307
308
309 class EnforcedTreeWidgetDelegate : public QItemDelegate
310 {
311     Q_OBJECT
312
313 public:
314   EnforcedTreeWidgetDelegate(QObject *parent = 0);
315
316   QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
317                         const QModelIndex &index) const;
318
319   void setEditorData(QWidget *editor, const QModelIndex &index) const;
320   void setModelData(QWidget *editor, QAbstractItemModel *model,
321                     const QModelIndex &index) const;
322
323   void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
324                     const QModelIndex &index) const;
325
326   bool vertexExists(QAbstractItemModel *model, const QModelIndex &index, QString value) const;
327 };
328
329 #endif // BLSURFPLUGINGUI_HypothesisCreator_H