Salome HOME
Update copyrights
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Hypotheses.h
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_Hypotheses.h
25 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
26 //
27 #ifndef SMESHGUI_HYPOTHESES_H
28 #define SMESHGUI_HYPOTHESES_H
29
30 // SMESH includes
31 #include "SMESH_SMESHGUI.hxx"
32 #include "SMESHGUI_HypothesesUtils.h"
33
34 // Qt includes
35 #include <QtxDialog.h>
36 #include <QVariant>
37
38 // IDL includes
39 #include <SALOMEconfig.h>
40 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
41
42 class QEventLoop;
43
44 /*!
45  * \brief Auxiliary class for creation of hypotheses
46 */
47 class SMESHGUI_EXPORT SMESHGUI_GenericHypothesisCreator : public QObject
48 {
49   Q_OBJECT
50
51 public:
52   SMESHGUI_GenericHypothesisCreator( const QString& );
53   virtual ~SMESHGUI_GenericHypothesisCreator();
54
55   void                         create( SMESH::SMESH_Hypothesis_ptr,
56                                        const QString&, QWidget*, QObject*, const QString& );
57   void                         create( bool, const QString&, QWidget*, QObject*, const QString& );
58   void                         edit( SMESH::SMESH_Hypothesis_ptr, const QString&, QWidget*, QObject*, const QString& );
59   void                         setInitParamsHypothesis(SMESH::SMESH_Hypothesis_ptr);
60
61   virtual bool                 checkParams( QString& ) const;
62   virtual void                 onReject();
63   virtual QString              helpPage() const;
64
65   QString                      hypType() const;
66   QString                      hypName() const;
67   bool                         isCreation() const;
68   
69   QString                      getShapeEntry() const { return myShapeEntry; }
70   void                         setShapeEntry( const QString& theEntry );
71
72   QString                      getMainShapeEntry() const { return myMainShapeEntry; }
73   void                         setMainShapeEntry( const QString& theEntry ) { myMainShapeEntry = theEntry; }
74
75   void                         setNoGeomMesh( const bool noGeom ) { myNoGeomMesh = noGeom; }
76   bool                         getNoGeomMesh() const { return myNoGeomMesh; }
77
78 signals:
79   void                         finished( int );
80
81 protected:
82   struct StdParam
83   {
84     QString    myName;
85     QVariant   myValue;
86     bool       isVariable;
87     QString    myText;
88     QByteArray myTextAsBytes;
89     StdParam() {
90       isVariable = false;
91     }
92     const char* text() const {
93       ((QByteArray&) myTextAsBytes) = myText.toUtf8(); return myTextAsBytes.constData();
94     }
95   };
96
97   typedef QList<StdParam>      ListOfStdParams;
98   typedef QList<QWidget*>      ListOfWidgets;
99
100   SMESH::SMESH_Hypothesis_var  hypothesis() const;
101   SMESH::SMESH_Hypothesis_var  initParamsHypothesis(const bool strict=false) const;
102   bool                         hasInitParamsHypothesis() const;
103   const ListOfWidgets&         widgets() const;
104   ListOfWidgets&               changeWidgets();
105   QLabel*                      getLabel(int i) const;
106   QtxDialog*                   dlg() const;
107   QString                      getVariableName(const char* methodName) const;
108
109   virtual QFrame*              buildFrame() = 0;
110           QFrame*              buildStdFrame();
111   virtual void                 retrieveParams() const = 0;
112   virtual QString              storeParams() const = 0;
113   virtual bool                 stdParams( ListOfStdParams& ) const;
114   bool                         getStdParamFromDlg( ListOfStdParams& ) const;
115   virtual QStringList          getVariablesFromDlg() const;
116   static  QString              stdParamValues( const ListOfStdParams& );
117   virtual void                 attuneStdWidget( QWidget*, const int ) const;
118   virtual QWidget*             getCustomWidget( const StdParam&, 
119                                                 QWidget*, const int ) const;
120   virtual QWidget*             getHelperWidget() const;
121   virtual bool                 getParamFromCustomWidget( StdParam&, QWidget* ) const;
122   virtual void                 valueChanged( QWidget* );
123   virtual QString              caption() const;
124   virtual QPixmap              icon() const;
125   virtual QString              type() const;
126
127 protected slots:
128   virtual void                 onValueChanged();
129
130 private slots:
131   virtual void                 onDialogFinished( int );
132
133 private:
134   void                         editHypothesis( SMESH::SMESH_Hypothesis_ptr, const QString&, QWidget*, QObject* obj, const QString& );
135
136 private:
137   SMESH::SMESH_Hypothesis_var  myHypo, myInitParamsHypo;
138   bool                         myToDeleteInitParamsHypo;
139   QString                      myHypName;
140   QString                      myHypType;
141   ListOfWidgets                myParamWidgets;
142   ListOfWidgets                myParamLabels;
143   bool                         myIsCreate;
144   bool                         myNoGeomMesh; //!< true for a mesh not based on geometry
145   QtxDialog*                   myDlg;
146   QString                      myShapeEntry;
147   QString                      myMainShapeEntry;
148 };
149
150 class SMESHGUI_HypothesisDlg : public QtxDialog
151 {
152   Q_OBJECT
153
154 public:
155   SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator*, QWidget* );
156   virtual ~SMESHGUI_HypothesisDlg();
157
158   void setHIcon( const QPixmap& );
159   void setCustomFrame( QFrame* );
160   void setType( const QString& );
161
162 protected slots:
163   virtual void accept();
164   virtual void reject();
165   void onHelp();
166
167  private:
168   SMESHGUI_GenericHypothesisCreator* myCreator;
169   QLabel *myIconLabel, *myTypeLabel;
170   QString myHelpFileName;
171 };
172
173 /*!
174  * \brief Information about a hypothesis
175  */
176 struct HypothesisData
177 {
178   HypothesisData( const QString&, const QString&, const QString&,
179                   const QString&, const QString&, const QString&,
180                   const QString&, const int, const int,
181                   const QList<int>&, const bool,
182                   const QStringList&, const QStringList&,
183                   const QStringList&, const QStringList&,
184                   const int, const bool supportSub );
185
186   QString TypeName;        //!< hypothesis type name
187   QString PluginName;      //!< plugin name
188   QString ServerLibName;   //!< server library name
189   QString ClientLibName;   //!< client library name
190   QString Label;           //!< label
191   QString IconId;          //!< icon identifier
192   QString Context;         //!< ["GLOBAL","LOCAL","ANY"(default)]
193   int     GroupID;         //!< group ID (staring from zero)
194   int     Priority;        //!< integer, priority within the group
195   QList<int> Dim;          //!< list of supported dimensions (see SMESH::Dimension enumeration)
196   bool IsAuxOrNeedHyp;     //!< TRUE if given HYPOTHESIS is auxiliary one, FALSE otherwise
197   //!<                          TRUE if given ALGORITHM can't work w/o hypotheses
198   int  IsNeedGeometry;     //!< 1 if the algorithm works with shapes only,
199   //!<                         -1 if the algorithm works without shapes only,
200   //!<                          0 if the algorithm works in both cases
201   bool IsSupportSubmeshes; //!< TRUE if the algorithm building all-dim elems supports sub-meshes
202
203   // for algorithm only: dependencies algo <-> algo and algo -> hypos
204   QStringList BasicHypos;   //!< list of basic hypotheses
205   QStringList OptionalHypos;//!< list of optional hypotheses
206   QStringList InputTypes;   //!< list of element types required as a prerequisite
207   QStringList OutputTypes;  //!< list of types of generated elements
208 };
209
210 /*!
211  * \brief Class containing set of hypotheses
212  *
213  * Actually it contains list of hypo types
214  */
215 class HypothesesSet
216 {
217 public:
218   HypothesesSet( const QString& );
219   HypothesesSet( const QString&, const QStringList&, const QStringList& );
220
221   QString name() const;
222   void set( bool, const QStringList& );
223   int count( bool ) const;
224
225   void setIsCustom( bool );
226   bool getIsCustom() const;
227   int maxDim() const;
228
229   bool isAlgo() const;
230
231   //this method sets internal index to -1, thus before any data access it is necessary to call next()
232   void init( bool );
233
234   bool more() const;
235   void next();
236   QString current() const;
237
238 private:
239   QStringList* list(bool) const;
240   QStringList* list() const;
241
242 private:
243   QString     myHypoSetName;
244   QStringList myHypoList, myAlgoList;
245   bool myIsAlgo, myIsCustom;
246   int myIndex;
247 };
248
249 #endif // SMESHGUI_HYPOTHESES_H