Salome HOME
Copyright update 2021
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Hypotheses.h
1 // Copyright (C) 2007-2021  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     void setNoName() { myName.clear(); } // ==> widget occupies both columns
96     bool hasName() const { return !myName.isEmpty(); }
97   };
98
99   typedef QList<StdParam>      ListOfStdParams;
100   typedef QList<QWidget*>      ListOfWidgets;
101
102   SMESH::SMESH_Hypothesis_var  hypothesis() const;
103   SMESH::SMESH_Hypothesis_var  initParamsHypothesis(const bool strict=false) const;
104   bool                         hasInitParamsHypothesis() const;
105   const ListOfWidgets&         widgets() const;
106   ListOfWidgets&               changeWidgets();
107   QLabel*                      getLabel(int i) const;
108   QtxDialog*                   dlg() const;
109   QString                      getVariableName(const char* methodName) const;
110
111   virtual QFrame*              buildFrame() = 0;
112           QFrame*              buildStdFrame();
113   virtual void                 retrieveParams() const = 0;
114   virtual QString              storeParams() const = 0;
115   virtual bool                 stdParams( ListOfStdParams& ) const;
116   bool                         getStdParamFromDlg( ListOfStdParams& ) const;
117   virtual QStringList          getVariablesFromDlg() const;
118   static  QString              stdParamValues( const ListOfStdParams& );
119   virtual void                 attuneStdWidget( QWidget*, const int ) const;
120   virtual QWidget*             getCustomWidget( const StdParam&, 
121                                                 QWidget*, const int ) const;
122   virtual QWidget*             getHelperWidget() const;
123   virtual bool                 getParamFromCustomWidget( StdParam&, QWidget* ) const;
124   virtual void                 valueChanged( QWidget* );
125   virtual QString              caption() const;
126   virtual QPixmap              icon() const;
127   virtual QString              type() const;
128
129 protected slots:
130   virtual void                 onValueChanged();
131
132 private slots:
133   virtual void                 onDialogFinished( int );
134
135 private:
136   void                         editHypothesis( SMESH::SMESH_Hypothesis_ptr, const QString&, QWidget*, QObject* obj, const QString& );
137
138 private:
139   SMESH::SMESH_Hypothesis_var  myHypo, myInitParamsHypo;
140   bool                         myToDeleteInitParamsHypo;
141   QString                      myHypName;
142   QString                      myHypType;
143   ListOfWidgets                myParamWidgets;
144   ListOfWidgets                myParamLabels;
145   bool                         myIsCreate;
146   bool                         myNoGeomMesh; //!< true for a mesh not based on geometry
147   QtxDialog*                   myDlg;
148   QString                      myShapeEntry;
149   QString                      myMainShapeEntry;
150 };
151
152 class SMESHGUI_HypothesisDlg : public QtxDialog
153 {
154   Q_OBJECT
155
156 public:
157   SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator*, QWidget* );
158   virtual ~SMESHGUI_HypothesisDlg();
159
160   void setHIcon( const QPixmap& );
161   void setCustomFrame( QFrame* );
162   void setType( const QString& );
163   void showEvent(QShowEvent *event);
164
165 protected slots:
166   virtual void accept();
167   virtual void reject();
168   void onHelp();
169
170  private:
171   SMESHGUI_GenericHypothesisCreator* myCreator;
172   QLabel *myIconLabel, *myTypeLabel;
173   QString myHelpFileName;
174 };
175
176 /*!
177  * \brief Information about a hypothesis
178  */
179 struct HypothesisData
180 {
181   HypothesisData( const QString&, const QString&, const QString&,
182                   const QString&, const QString&, const QString&,
183                   const QString&, const int, const int,
184                   const QList<int>&, const bool,
185                   const QStringList&, const QStringList&,
186                   const QStringList&, const QStringList&,
187                   const int, const bool supportSub );
188
189   QString TypeName;        //!< hypothesis type name
190   QString PluginName;      //!< plugin name
191   QString ServerLibName;   //!< server library name
192   QString ClientLibName;   //!< client library name
193   QString Label;           //!< label
194   QString IconId;          //!< icon identifier
195   QString Context;         //!< ["GLOBAL","LOCAL","ANY"(default)]
196   int     GroupID;         //!< group ID (staring from zero)
197   int     Priority;        //!< integer, priority within the group
198   QList<int> Dim;          //!< list of supported dimensions (see SMESH::Dimension enumeration)
199   bool IsAuxOrNeedHyp;     //!< TRUE if given HYPOTHESIS is auxiliary one, FALSE otherwise
200   //!<                          TRUE if given ALGORITHM can't work w/o hypotheses
201   int  IsNeedGeometry;     //!< 1 if the algorithm works with shapes only,
202   //!<                         -1 if the algorithm works without shapes only,
203   //!<                          0 if the algorithm works in both cases
204   bool IsSupportSubmeshes; //!< TRUE if the algorithm building all-dim elems supports sub-meshes
205
206   // for algorithm only: dependencies algo <-> algo and algo -> hypos
207   QStringList BasicHypos;   //!< list of basic hypotheses
208   QStringList OptionalHypos;//!< list of optional hypotheses
209   QStringList InputTypes;   //!< list of element types required as a prerequisite
210   QStringList OutputTypes;  //!< list of types of generated elements
211 };
212
213 /*!
214  * \brief Class containing set of hypotheses
215  *
216  * Actually it contains list of hypo types
217  */
218 class HypothesesSet
219 {
220 public:
221
222   enum SetType { MAIN, ALT, INTERN, NB_HYP_TYPES }; //!< hypos/algos type: main, alternative, internal-edges
223
224   //HypothesesSet( const QString& );
225   HypothesesSet( const QString& name,
226                  bool useCommonSize, bool isQuadDominated,
227                  const QStringList& mainHypos, const QStringList& mainAlgos,
228                  const QStringList& altHypos, const QStringList&  altAlgos,
229                  const QStringList& intHypos, const QStringList&  intAlgos );
230
231   QString name() const;
232   bool toUseCommonSize() const { return myUseCommonSize; }
233   bool isQuadDominated() const { return myQuadDominated; }
234   bool hasAlgo( SetType type ) const { return !myAlgoList[ type ].isEmpty(); }
235   //int count( bool, SetType ) const;
236
237   int maxDim() const;
238
239   void setIsCustom( bool );
240   bool getIsCustom() const;
241
242   void setAlgoAvailable( SetType type, bool isAvailable );
243   bool getAlgoAvailable( SetType type );
244
245   static SetType getPreferredHypType();
246   static const char* getCommonHypoSetHypoType();
247
248   //bool isAlgo() const;
249
250   // CASCADE-like iteration
251   void init( bool, SetType );
252   bool more() const;
253   void next();
254   QString current() const;
255
256 private:
257   QStringList* list(bool,SetType) const;
258   QStringList* list() const;
259
260 private:
261   bool        myUseCommonSize; // Average size is asked only and used to create default hypotheses
262   bool        myQuadDominated;
263   QString     myHypoSetName;
264   QStringList myHypoList[3], myAlgoList[3]; // per SetType
265   bool        myIsAlgoAvailable[3]; // current state depending on geometry etc
266
267   // iteration
268   SetType myHypType;
269   bool myIsAlgo, myIsCustom;
270   int myIndex;
271 };
272
273 #endif // SMESHGUI_HYPOTHESES_H