00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef PCL_MODELER_PARAMETER_H_
00037 #define PCL_MODELER_PARAMETER_H_
00038
00039 #include <map>
00040 #include <string>
00041
00042 #include <boost/any.hpp>
00043 #include <pcl/apps/modeler/qt.h>
00044
00045
00046 namespace pcl
00047 {
00048 namespace modeler
00049 {
00050 class Parameter
00051 {
00052 public:
00053 Parameter(const std::string& name, const std::string& description, const boost::any& value):
00054 name_(name), description_(description), default_value_(value), current_value_(value){}
00055 ~Parameter(void) {}
00056
00057 const std::string&
00058 getName() const {return name_;}
00059
00060 const std::string&
00061 getDescription()const {return description_;}
00062
00063 void
00064 setDefaultValue(const boost::any& value)
00065 {
00066 default_value_ = value;
00067 }
00068
00069 void
00070 reset() {current_value_ = default_value_;}
00071
00072 virtual std::string
00073 valueTip() = 0;
00074
00075 virtual QWidget*
00076 createEditor(QWidget *parent) = 0;
00077
00078 virtual void
00079 setEditorData(QWidget *editor) = 0;
00080
00081 virtual void
00082 setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index);
00083
00084 virtual std::pair<QVariant, int>
00085 toModelData() = 0;
00086
00087 protected:
00088 virtual void
00089 getEditorData(QWidget *editor) = 0;
00090
00091 std::string name_;
00092 std::string description_;
00093 boost::any default_value_;
00094 boost::any current_value_;
00095 };
00096
00097 class BoolParameter : public Parameter
00098 {
00099 public:
00100 BoolParameter(const std::string& name, const std::string& description, bool value):
00101 Parameter(name, description, value){}
00102 ~BoolParameter(){}
00103
00104 operator bool() const {return boost::any_cast<bool>(current_value_);}
00105
00106 virtual std::string
00107 valueTip();
00108
00109 virtual QWidget*
00110 createEditor(QWidget *parent);
00111
00112 virtual void
00113 setEditorData(QWidget *editor);
00114
00115 virtual std::pair<QVariant, int>
00116 toModelData();
00117
00118 protected:
00119 virtual void
00120 getEditorData(QWidget *editor);
00121 };
00122
00123 class IntParameter : public Parameter
00124 {
00125 public:
00126 IntParameter(const std::string& name, const std::string& description, int value, int low, int high, int step=1):
00127 Parameter(name, description, value), low_(low), high_(high), step_(step){}
00128 virtual ~IntParameter(){}
00129
00130 operator int() const {return boost::any_cast<int>(current_value_);}
00131
00132 virtual std::string
00133 valueTip();
00134
00135 virtual QWidget*
00136 createEditor(QWidget *parent);
00137
00138 virtual void
00139 setEditorData(QWidget *editor);
00140
00141 virtual std::pair<QVariant, int>
00142 toModelData();
00143
00144 void
00145 setLow(int low)
00146 {
00147 low_ = low;
00148 }
00149
00150 void
00151 setHigh(int high)
00152 {
00153 high_ = high;
00154 }
00155
00156 void
00157 setStep(int step)
00158 {
00159 step_ = step;
00160 }
00161
00162 protected:
00163 virtual void
00164 getEditorData(QWidget *editor);
00165
00166 int low_;
00167 int high_;
00168 int step_;
00169 };
00170
00171 template <class T>
00172 class EnumParameter : public Parameter
00173 {
00174 public:
00175 EnumParameter(const std::string& name, const std::string& description, T value, const std::map<T, std::string>& candidates):
00176 Parameter(name, description, value), candidates_(candidates){}
00177 ~EnumParameter(){}
00178
00179 operator T() const {return boost::any_cast<T>(current_value_);}
00180
00181 virtual std::string
00182 valueTip();
00183
00184 virtual QWidget*
00185 createEditor(QWidget *parent);
00186
00187 virtual void
00188 setEditorData(QWidget *editor);
00189
00190 virtual std::pair<QVariant, int>
00191 toModelData();
00192
00193 protected:
00194 virtual void
00195 getEditorData(QWidget *editor);
00196
00197 const std::map<T, std::string> candidates_;
00198 };
00199
00200 class DoubleParameter : public Parameter
00201 {
00202 public:
00203 DoubleParameter(const std::string& name, const std::string& description, double value, double low, double high, double step=0.01):
00204 Parameter(name, description, value), low_(low), high_(high), step_(step){}
00205 virtual ~DoubleParameter(){}
00206
00207 operator double() const {return boost::any_cast<double>(current_value_);}
00208
00209 virtual std::string
00210 valueTip();
00211
00212 virtual QWidget*
00213 createEditor(QWidget *parent);
00214
00215 virtual void
00216 setEditorData(QWidget *editor);
00217
00218 virtual std::pair<QVariant, int>
00219 toModelData();
00220
00221 void
00222 setLow(double low)
00223 {
00224 low_ = low;
00225 }
00226
00227 void
00228 setHigh(double high)
00229 {
00230 high_ = high;
00231 }
00232
00233 void
00234 setStep(double step)
00235 {
00236 step_ = step;
00237 }
00238
00239 protected:
00240 virtual void
00241 getEditorData(QWidget *editor);
00242
00243 double low_;
00244 double high_;
00245 double step_;
00246 };
00247
00248 class ColorParameter : public Parameter
00249 {
00250 public:
00251 ColorParameter(const std::string& name, const std::string& description, QColor value):
00252 Parameter(name, description, value){}
00253 ~ColorParameter(){}
00254
00255 operator QColor() const {return boost::any_cast<QColor>(current_value_);}
00256
00257 virtual std::string
00258 valueTip();
00259
00260 virtual QWidget*
00261 createEditor(QWidget *parent);
00262
00263 virtual void
00264 setEditorData(QWidget *editor);
00265
00266 virtual std::pair<QVariant, int>
00267 toModelData();
00268
00269 protected:
00270 virtual void
00271 getEditorData(QWidget *editor);
00272
00273 };
00274 }
00275 }
00276
00277 #endif // PCL_MODELER_PARAMETER_H_