Salome HOME
475763191d3844df55a9f5962d64346530dda03e
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Hypotheses.h
1 // Copyright (C) 2007-2013  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.
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 signals:
76   void                         finished( int );
77
78 protected:
79   struct StdParam
80   {
81     QString    myName;
82     QVariant   myValue;
83     bool       isVariable;
84     QString    myText;
85     QByteArray myTextAsBytes;
86     StdParam() {
87       isVariable = false;
88     }
89     const char* text() const {
90       ((QByteArray&) myTextAsBytes) = myText.toLatin1(); return myTextAsBytes.constData();
91     }
92   };
93
94   typedef QList<StdParam>      ListOfStdParams;
95   typedef QList<QWidget*>      ListOfWidgets;
96
97   SMESH::SMESH_Hypothesis_var  hypothesis() const;
98   SMESH::SMESH_Hypothesis_var  initParamsHypothesis(const bool strict=false) const;
99   bool                         hasInitParamsHypothesis() const;
100   const ListOfWidgets&         widgets() const;
101   ListOfWidgets&               changeWidgets();
102   QtxDialog*                   dlg() const;
103   QString                      getVariableName(const char* methodName) const;
104
105   virtual QFrame*              buildFrame() = 0;
106           QFrame*              buildStdFrame();
107   virtual void                 retrieveParams() const = 0;
108   virtual QString              storeParams() const = 0;
109   virtual bool                 stdParams( ListOfStdParams& ) const;
110   bool                         getStdParamFromDlg( ListOfStdParams& ) const;
111   virtual QStringList          getVariablesFromDlg() const;
112   static  QString              stdParamValues( const ListOfStdParams& );
113   virtual void                 attuneStdWidget( QWidget*, const int ) const;
114   virtual QWidget*             getCustomWidget( const StdParam&, 
115                                                 QWidget*, const int ) const;
116   virtual bool                 getParamFromCustomWidget( StdParam&, QWidget* ) const;
117   virtual void                 valueChanged( QWidget* );
118   virtual QString              caption() const;
119   virtual QPixmap              icon() const;
120   virtual QString              type() const;
121
122 protected slots:
123   virtual void                 onValueChanged();
124
125 private slots:
126   virtual void                 onDialogFinished( int );
127
128 private:
129   void                         editHypothesis( SMESH::SMESH_Hypothesis_ptr, const QString&, QWidget*, QObject* obj, const QString& );
130
131 private:
132   SMESH::SMESH_Hypothesis_var  myHypo, myInitParamsHypo;
133   bool                         myToDeleteInitParamsHypo;
134   QString                      myHypName;
135   QString                      myHypType;
136   ListOfWidgets                myParamWidgets;
137   bool                         myIsCreate;
138   QtxDialog*                   myDlg;
139   QString                      myShapeEntry;
140   QString                      myMainShapeEntry;
141 };
142
143 class SMESHGUI_HypothesisDlg : public QtxDialog
144 {
145   Q_OBJECT
146
147 public:
148   SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator*, QWidget* );
149   virtual ~SMESHGUI_HypothesisDlg();
150
151   void setHIcon( const QPixmap& );
152   void setCustomFrame( QFrame* );
153   void setType( const QString& );
154
155 protected slots:
156   virtual void accept();
157   virtual void reject();
158   void onHelp(); 
159
160 private:
161   SMESHGUI_GenericHypothesisCreator* myCreator;
162   QLabel *myIconLabel, *myTypeLabel;
163   QString myHelpFileName;
164 };
165
166 /*!
167  * \brief Class containing information about hypothesis
168 */
169 class HypothesisData
170 {
171 public:
172   HypothesisData( const QString&, const QString&, const QString&,
173                   const QString&, const QString&, const QString&,
174                   const QList<int>&, const bool,
175                   const QStringList&, const QStringList&,
176                   const QStringList&, const QStringList&,
177                   const bool=true, const bool supportSub=false );
178
179   QString TypeName;        //!< hypothesis type name
180   QString PluginName;      //!< plugin name
181   QString ServerLibName;   //!< server library name
182   QString ClientLibName;   //!< client library name
183   QString Label;           //!< label
184   QString IconId;          //!< icon identifier
185   QList<int> Dim;          //!< list of supported dimensions (see SMESH::Dimension enumeration)
186   bool IsAux;              //!< TRUE if given hypothesis is auxiliary one, FALSE otherwise
187   bool IsNeedGeometry;     //!< TRUE if the algorithm works with shapes only, FALSE otherwise
188   bool IsSupportSubmeshes; //!< TRUE if the algo building all-dim elems supports submeshes
189
190   // for algorithm only: dependencies algo <-> algo and algo -> hypos
191   QStringList NeededHypos;  //!< list of obligatory hypotheses
192   QStringList OptionalHypos;//!< list of optional hypotheses
193   QStringList InputTypes;   //!< list of element types required as a prerequisite
194   QStringList OutputTypes;  //!< list of types of generated elements
195 };
196
197 /*!
198  * \brief Class containing set of hypotheses
199  *
200  * Actually it contains list of hypo types
201  */
202 class HypothesesSet
203 {
204 public:
205   HypothesesSet( const QString& );
206   HypothesesSet( const QString&, const QStringList&, const QStringList& );
207
208   QString name() const;
209   void set( bool, const QStringList& );
210   int count( bool ) const;
211
212   void setIsCustom( bool );
213   bool getIsCustom() const;
214   int maxDim() const;
215
216   bool isAlgo() const;
217
218   //this method sets internal index to -1, thus before any data access it is necessary to call next()
219   void init( bool );
220
221   bool more() const;
222   void next();
223   QString current() const;
224
225 private:
226   QStringList* list(bool) const;
227   QStringList* list() const;
228
229 private:
230   QString     myHypoSetName;
231   QStringList myHypoList, myAlgoList;
232   bool myIsAlgo, myIsCustom;
233   int myIndex;
234 };
235
236 #endif // SMESHGUI_HYPOTHESES_H