1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_aParameter.h
28 #ifndef SMESHGUI_aParameter_H
29 #define SMESHGUI_aParameter_H
31 #include <boost/shared_ptr.hpp>
32 #include <qstringlist.h>
36 #include <SALOMEconfig.h>
37 #include CORBA_SERVER_HEADER(SMESH_Mesh)
40 class SMESHGUI_aParameter;
42 typedef boost::shared_ptr<SMESHGUI_aParameter> SMESHGUI_aParameterPtr;
45 * \brief This class is the base class of all parameters
47 class SMESHGUI_aParameter
50 SMESHGUI_aParameter(const QString& label):_label(label) {}
51 virtual ~SMESHGUI_aParameter();
53 enum Type { INT, DOUBLE, STRING, ENUM, BOOL, TABLE };
54 virtual Type GetType() const = 0;
55 virtual bool GetNewInt( int & Value ) const = 0;
56 virtual bool GetNewDouble( double & Value ) const = 0;
57 virtual bool GetNewText( QString & Value ) const = 0;
58 virtual void TakeValue( QWidget* ) = 0;
59 virtual QWidget* CreateWidget( QWidget* ) const = 0;
60 virtual void InitializeWidget( QWidget* ) const = 0;
63 * \brief Returns string representation of signal emitted when value in corrsponding widget is changed
65 virtual QString sigValueChanged() const;
67 QString & Label() { return _label; }
74 * \brief This class provides parameter with integer value
76 class SMESHGUI_intParameter: public SMESHGUI_aParameter
79 SMESHGUI_intParameter(const int initValue = 0,
80 const QString& label = QString::null,
82 const int top = 1000);
83 int & InitValue() { return _initValue; }
84 int & Top() { return _top; }
85 int & Bottom() { return _bottom; }
86 virtual Type GetType() const;
87 virtual bool GetNewInt( int & Value ) const;
88 virtual bool GetNewDouble( double & Value ) const;
89 virtual bool GetNewText( QString & Value ) const;
90 virtual void TakeValue( QWidget* );
91 virtual QWidget* CreateWidget( QWidget* ) const;
92 virtual void InitializeWidget( QWidget* ) const;
94 virtual QString sigValueChanged() const;
98 int _initValue, _newValue;
102 * \brief This class provides parameter with double value
104 class SMESHGUI_doubleParameter: public SMESHGUI_aParameter
107 SMESHGUI_doubleParameter(const double initValue = 0.0,
108 const QString& label = QString::null,
109 const double bottom = -1E6,
110 const double top = +1E6,
111 const double step = 1.0,
112 const int decimals = 3);
113 double & InitValue() { return _initValue; }
114 double & Top() { return _top; }
115 double & Bottom() { return _bottom; }
116 double & Step() { return _step; }
117 int & Decimals() { return _decimals; }
118 virtual Type GetType() const;
119 virtual bool GetNewInt( int & Value ) const;
120 virtual bool GetNewDouble( double & Value ) const;
121 virtual bool GetNewText( QString & Value ) const;
122 virtual QWidget* CreateWidget( QWidget* ) const;
123 virtual void InitializeWidget( QWidget* ) const;
124 virtual void TakeValue( QWidget* );
126 virtual QString sigValueChanged() const;
129 double _top, _bottom, _step;
130 double _initValue, _newValue;
135 * \brief This class provides parameter with string value
137 class SMESHGUI_strParameter: public SMESHGUI_aParameter
140 SMESHGUI_strParameter( const QString& initValue = "",
141 const QString& label = QString::null);
142 QString& InitValue() { return _initValue; }
143 virtual Type GetType() const;
144 virtual bool GetNewInt( int & Value ) const;
145 virtual bool GetNewDouble( double & Value ) const;
146 virtual bool GetNewText( QString & Value ) const;
147 virtual QWidget* CreateWidget( QWidget* ) const;
148 virtual void InitializeWidget( QWidget* ) const;
149 virtual void TakeValue( QWidget* );
151 virtual QString sigValueChanged() const;
154 QString _initValue, _newValue;
159 * \brief This class represents the base parameter which contains dependency of
160 * shown state of other parameters on value of current
162 class SMESHGUI_dependParameter: public SMESHGUI_aParameter
166 * \brief This map describes what parameters must be shown when this parameter has value as key
167 * The list contains some indices of parameters (for example, order in some list)
168 * Value is integer based 0. If map is empty, it means that there is no dependencies.
170 typedef QValueList< int > IntList;
171 typedef QMap< int, IntList > ShownMap;
174 SMESHGUI_dependParameter( const QString& = QString::null );
176 const ShownMap& shownMap() const;
177 ShownMap& shownMap();
184 * \brief This class represents parameter which can have value from fixed set
186 class SMESHGUI_enumParameter: public SMESHGUI_dependParameter
190 * \brief Creates parameter with set of values 'values', default value 'init' and title 'label'
191 * Every value can be described both by integer based 0 or by string value
193 SMESHGUI_enumParameter( const QStringList& values,
195 const QString& label = QString::null );
196 virtual ~SMESHGUI_enumParameter();
199 * \brief Returns count of possible values
203 int& InitValue() { return myInitValue; }
204 virtual Type GetType() const;
205 virtual bool GetNewInt( int& ) const;
206 virtual bool GetNewDouble( double& ) const;
207 virtual bool GetNewText( QString& ) const;
208 virtual QWidget* CreateWidget( QWidget* ) const;
209 virtual void InitializeWidget( QWidget* ) const;
210 virtual void TakeValue( QWidget* );
212 virtual QString sigValueChanged() const;
215 int myInitValue, myValue;
216 QStringList myValues;
221 * \brief This class represents parameter which can have value true or false
223 class SMESHGUI_boolParameter: public SMESHGUI_dependParameter
226 SMESHGUI_boolParameter( const bool = false,
227 const QString& = QString::null );
228 virtual ~SMESHGUI_boolParameter();
230 bool& InitValue() { return myInitValue; }
231 virtual Type GetType() const;
232 virtual bool GetNewInt( int& ) const;
233 virtual bool GetNewDouble( double& ) const;
234 virtual bool GetNewText( QString& ) const;
235 virtual QWidget* CreateWidget( QWidget* ) const;
236 virtual void InitializeWidget( QWidget* ) const;
237 virtual void TakeValue( QWidget* );
239 virtual QString sigValueChanged() const;
242 bool myInitValue, myValue;
249 * \brief This class represents custom table. It has only double values and
250 editor for every cell has validator
252 class SMESHGUI_Table : public QTable
257 SMESHGUI_Table( int numRows, int numCols, QWidget* = 0, const char* = 0 );
258 virtual ~SMESHGUI_Table();
261 * \brief Hides current editor of cell
265 virtual QSize sizeHint() const;
268 * \brief Returns parameters of double validator corresponding to cell (row,col)
270 void validator( const int row, const int col, double&, double&, int& );
273 * \brief Sets the double validator parameters to every cell in row range [rmin,rmax]
274 * and column range [cmin,cmax].
275 * If rmin=-1 then rmin is set to 0, if rmax=-1 then rmax = last row.
276 * Analogically cmin and cmax are set
278 void setValidator( const double, const double, const int,
279 const int rmin = -1, const int rmax = -1,
280 const int cmin = -1, const int cmax = -1 );
285 * \brief This class represents frame for table and buttons
287 class SMESHGUI_TableFrame : public QFrame
293 * \brief Values corresponding to buttons for table resize
295 typedef enum { ADD_COLUMN, REMOVE_COLUMN, ADD_ROW, REMOVE_ROW } Button;
298 SMESHGUI_TableFrame( QWidget* );
299 ~SMESHGUI_TableFrame();
301 SMESHGUI_Table* table() const;
304 * \brief Changes shown state of some button for table resize
306 void setShown( const Button, const bool );
309 * \brief Returns shown state of some button for table resize
311 bool isShown( const Button ) const;
314 QButton* button( const Button ) const;
317 void onButtonClicked();
321 * \brief This signal is emitted if some of button for table resize is clicked
322 * Second parameter is current column for ADD_COLUMN, REMOVE_COLUMN buttons
323 * and current row for ADD_ROW, REMOVE_ROW buttons. Take into account that
324 * this object resize table ( returned by table() ) automatically
326 void toEdit( SMESHGUI_TableFrame::Button, int );
329 QButton *myAddColumn, *myRemoveColumn, *myAddRow, *myRemoveRow;
330 SMESHGUI_Table* myTable;
335 * \brief This class represents parameter which can have two-dimensional array of values
337 class SMESHGUI_tableParameter: public QObject, public SMESHGUI_aParameter
343 * \brief Creates table parameter with default value 'init' and title 'label'.
344 * The default value means that by default the table is filled with default value
345 * and if new column or row is added then it is filled with default value
347 SMESHGUI_tableParameter( const double init = 0.0,
348 const QString& label = QString::null );
349 virtual ~SMESHGUI_tableParameter();
351 virtual Type GetType() const;
352 virtual bool GetNewInt( int& ) const;
353 virtual bool GetNewDouble( double& ) const;
354 virtual bool GetNewText( QString& ) const;
355 virtual QWidget* CreateWidget( QWidget* ) const;
356 virtual void InitializeWidget( QWidget* ) const;
357 virtual void TakeValue( QWidget* );
360 * \brief Updates look of widget in accordance with all parameters of this object
362 void update( QWidget* ) const;
365 * \brief Returns data taken from widget. Please don't forget to call TakeValue before.
367 void data( SMESH::double_array& ) const;
370 * \brief Sets data. The InitializeWidget must be called in order to change values in widget
372 void setData( const SMESH::double_array& );
375 * \brief Sets count of columns and updates widget
377 void setColCount( const int, QWidget* = 0 );
380 * \brief Sets count of rows and updates widget
382 void setRowCount( const int, QWidget* = 0 );
385 * \brief Binds count of columns to some parameter and updates widget. Take into account that
386 * if this parameter is changed, the update() must be called to resize table
388 void setColCount( const SMESHGUI_aParameterPtr, QWidget* = 0 );
391 * \brief Binds count of rows to some parameter and updates widget. Take into account that
392 * if this parameter is changed, the update() must be called to resize table
394 void setRowCount( const SMESHGUI_aParameterPtr, QWidget* = 0 );
397 * \brief Enables or disables to change count of columns by buttons
399 void setEditCols( const bool );
402 * \brief Enables or disables to change count of rows by buttons
404 void setEditRows( const bool );
406 virtual QString sigValueChanged() const;
408 void setValidator( const int col, const double, const double, const int );
409 void validator( const int col, double&, double&, int& ) const;
412 * \brief These methods allow to read and change name of column
414 void setColName( const int, const QString& );
415 QString colName( const int ) const;
418 void onEdit( SMESHGUI_TableFrame::Button, int );
421 void setItems( QWidget*, int = -1, int = -1, int = -1, int = -1 ) const;
430 typedef QMap<int, ValidatorInfo> ValidatorsMap;
433 int myColsInt, myRowsInt;
434 SMESHGUI_aParameterPtr myCols, myRows;
436 SMESH::double_array myData;
437 ValidatorsMap myValidators;
438 bool myEditCols, myEditRows;
439 QMap< int, QString > myColNames;
442 #endif // SMESHGUI_aParameter.h