00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __SIM_OptionsUser_h__
00015 #define __SIM_OptionsUser_h__
00016
00017 #include "SIM_API.h"
00018 #include "SIM_Options.h"
00019
00020 #include <UT/UT_IStream.h>
00021 #include <UT/UT_Ramp.h>
00022
00023 class SIM_Data;
00024
00025
00026
00027
00028
00029 class SIM_API SIM_OptionsUser
00030 {
00031 public:
00032 SIM_OptionsUser(SIM_Data *owner);
00033 virtual ~SIM_OptionsUser();
00034
00035
00036
00037 void optionChanged(const char *name);
00038
00039 protected:
00040 const SIM_Options &getOptions() const;
00041 SIM_Options &getOptions();
00042
00043 virtual void optionChangedSubclass(const char *name);
00044
00045 private:
00046 SIM_Data *myOwner;
00047 SIM_Options myOptions;
00048 };
00049
00050 #define GET_DATA_FUNC_I(DataName, FuncName) \
00051 int64 get##FuncName() const \
00052 { return getOptions().getOptionI(DataName); }
00053 #define GET_DATA_FUNC_E(DataName, FuncName, EnumType) \
00054 EnumType get##FuncName() const \
00055 { return static_cast<EnumType> \
00056 (getOptions().getOptionI(DataName)); }
00057 #define GET_DATA_FUNC_B(DataName, FuncName) \
00058 bool get##FuncName() const \
00059 { return getOptions().getOptionB(DataName); }
00060 #define GET_DATA_FUNC_F(DataName, FuncName) \
00061 fpreal64 get##FuncName() const \
00062 { return getOptions().getOptionF(DataName); }
00063
00064 #define GET_DATA_FUNC_RAMP(DataName, FuncName) \
00065 bool get##FuncName(UT_Ramp &ramp) const \
00066 { UT_String rs; \
00067 getOptions().getOptionS(DataName, rs); \
00068 UT_IStream is((const char *) rs, rs.length(), UT_ISTREAM_ASCII); \
00069 return ramp.load(is); } \
00070 }
00071
00072 #define _BUILD_SIM_OPTION_GETTERS(DataName, FuncName, BaseType, Accessor) \
00073 const BaseType##D get##FuncName##D() const \
00074 { return getOptions().getOption##Accessor(DataName); } \
00075 const BaseType##F get##FuncName##F() const \
00076 { return getOptions().getOption##Accessor(DataName); } \
00077 const BaseType##F get##FuncName() const \
00078 { return getOptions().getOption##Accessor(DataName); }
00079
00080 #define GET_DATA_FUNC_V2(DataName, FuncName) \
00081 _BUILD_SIM_OPTION_GETTERS(DataName, FuncName, UT_Vector2, V2);
00082 #define GET_DATA_FUNC_V2D(DataName, FuncName) \
00083 _BUILD_SIM_OPTION_GETTERS(DataName, FuncName, UT_Vector2D, V2);
00084 #define GET_DATA_FUNC_UV(DataName, FuncName) \
00085 _BUILD_SIM_OPTION_GETTERS(DataName, FuncName, UT_Vector2, V2);
00086 #define GET_DATA_FUNC_V3(DataName, FuncName) \
00087 _BUILD_SIM_OPTION_GETTERS(DataName, FuncName, UT_Vector3, V3);
00088 #define GET_DATA_FUNC_V3D(DataName, FuncName) \
00089 _BUILD_SIM_OPTION_GETTERS(DataName, FuncName, UT_Vector3D, V3);
00090 #define GET_DATA_FUNC_UVW(DataName, FuncName) \
00091 _BUILD_SIM_OPTION_GETTERS(DataName, FuncName, UT_Vector3, V3);
00092 #define GET_DATA_FUNC_V4(DataName, FuncName) \
00093 _BUILD_SIM_OPTION_GETTERS(DataName, FuncName, UT_Vector4, V4);
00094 #define GET_DATA_FUNC_V4D(DataName, FuncName) \
00095 _BUILD_SIM_OPTION_GETTERS(DataName, FuncName, UT_Vector4D, V4);
00096 #define GET_DATA_FUNC_Q(DataName, FuncName) \
00097 _BUILD_SIM_OPTION_GETTERS(DataName, FuncName, UT_Quaternion, Q);
00098 #define GET_DATA_FUNC_QD(DataName, FuncName) \
00099 _BUILD_SIM_OPTION_GETTERS(DataName, FuncName, UT_QuaternionD, Q);
00100 #define GET_DATA_FUNC_M3(DataName, FuncName) \
00101 _BUILD_SIM_OPTION_GETTERS(DataName, FuncName, UT_Matrix3, M3);
00102 #define GET_DATA_FUNC_M4(DataName, FuncName) \
00103 _BUILD_SIM_OPTION_GETTERS(DataName, FuncName, UT_Matrix4, M4);
00104 #define GET_DATA_FUNC_S(DataName, FuncName) \
00105 void get##FuncName(UT_String &value) const \
00106 { getOptions().getOptionS(DataName, value); }
00107
00108 #define _BUILD_SIM_OPTION_GUIDE_GETTERS(DataName, FuncName, Default, BaseType, Accessor) \
00109 const BaseType##D get##FuncName##D(const SIM_Options &options) const \
00110 { return options.hasOption(DataName) \
00111 ? options.getOption##Accessor(DataName) \
00112 : BaseType##D Default; \
00113 } \
00114 const BaseType##F get##FuncName##F(const SIM_Options &options) const \
00115 { return options.hasOption(DataName) \
00116 ? options.getOption##Accessor(DataName) \
00117 : BaseType##D Default; \
00118 } \
00119 const BaseType##F get##FuncName(const SIM_Options &options) const \
00120 { return options.hasOption(DataName) \
00121 ? options.getOption##Accessor(DataName) \
00122 : BaseType##D Default; \
00123 }
00124
00125 #define GET_GUIDE_FUNC_I(DataName, FuncName, Default) \
00126 int64 get##FuncName(const SIM_Options &options) const \
00127 { return options.hasOption(DataName) \
00128 ? options.getOptionI(DataName) \
00129 : Default; \
00130 }
00131 #define GET_GUIDE_FUNC_E(DataName, FuncName, EnumType, Default) \
00132 EnumType get##FuncName(const SIM_Options &options) const \
00133 { return static_cast<EnumType> (options.hasOption(DataName) \
00134 ? options.getOptionI(DataName) \
00135 : Default); \
00136 }
00137 #define GET_GUIDE_FUNC_B(DataName, FuncName, Default) \
00138 bool get##FuncName(const SIM_Options &options) const \
00139 { return options.hasOption(DataName) \
00140 ? options.getOptionB(DataName) \
00141 : Default; \
00142 }
00143 #define GET_GUIDE_FUNC_F(DataName, FuncName, Default) \
00144 fpreal64 get##FuncName(const SIM_Options &options) const \
00145 { return options.hasOption(DataName) \
00146 ? options.getOptionF(DataName) \
00147 : Default; \
00148 }
00149 #define GET_GUIDE_FUNC_V2(DataName, FuncName, Default) \
00150 _BUILD_SIM_OPTION_GUIDE_GETTERS(DataName, FuncName, Default, UT_Vector2, V2)
00151 #define GET_GUIDE_FUNC_V3(DataName, FuncName, Default) \
00152 _BUILD_SIM_OPTION_GUIDE_GETTERS(DataName, FuncName, Default, UT_Vector3, V3)
00153 #define GET_GUIDE_FUNC_V4(DataName, FuncName, Default) \
00154 _BUILD_SIM_OPTION_GUIDE_GETTERS(DataName, FuncName, Default, UT_Vector4, V4)
00155
00156 #define GET_GUIDE_FUNC_S(DataName, FuncName, Default) \
00157 void get##FuncName(UT_String &value, const SIM_Options &options) const \
00158 { if (options.hasOption(DataName)) \
00159 options.getOptionS(DataName, value); \
00160 else \
00161 value = Default; \
00162 }
00163
00164 #define GET_GUIDE_FUNC_RAMP(DataName, FuncName) \
00165 bool get##FuncName(UT_Ramp &ramp, const SIM_Options &options) const \
00166 { if (options.hasOption(DataName)) \
00167 { UT_String rs; \
00168 options.getOptionS(DataName, rs); \
00169 UT_IStream is((const char *) rs, rs.length(), UT_ISTREAM_ASCII); \
00170 return ramp.load(is); } \
00171 return false; \
00172 }
00173
00174 #define SET_DATA_FUNC_I(DataName, FuncName) \
00175 void set##FuncName(const int64 value) \
00176 { getOptions().setOptionI(DataName, value); }
00177 #define SET_DATA_FUNC_E(DataName, FuncName, EnumType) \
00178 void set##FuncName(const EnumType value) \
00179 { getOptions().setOptionI(DataName, \
00180 static_cast<int>(value)); }
00181 #define SET_DATA_FUNC_B(DataName, FuncName) \
00182 void set##FuncName(const bool value) \
00183 { getOptions().setOptionB(DataName, value); }
00184 #define SET_DATA_FUNC_F(DataName, FuncName) \
00185 void set##FuncName(const fpreal64 value) \
00186 { getOptions().setOptionF(DataName, value); }
00187 #define SET_DATA_FUNC_V2(DataName, FuncName) \
00188 void set##FuncName(const UT_Vector2F &value) \
00189 { getOptions().setOptionV2(DataName, value); } \
00190 void set##FuncName(const UT_Vector2D &value) \
00191 { getOptions().setOptionV2(DataName, value); }
00192 #define SET_DATA_FUNC_UV(DataName, FuncName) \
00193 void set##FuncName(const UT_Vector2F &value) \
00194 { getOptions().setOptionUV(DataName, value); } \
00195 void set##FuncName(const UT_Vector2D &value) \
00196 { getOptions().setOptionUV(DataName, value); }
00197 #define SET_DATA_FUNC_V3(DataName, FuncName) \
00198 void set##FuncName(const UT_Vector3F &value) \
00199 { getOptions().setOptionV3(DataName, value); } \
00200 void set##FuncName(const UT_Vector3D &value) \
00201 { getOptions().setOptionV3(DataName, value); }
00202 #define SET_DATA_FUNC_UVW(DataName, FuncName) \
00203 void set##FuncName(const UT_Vector3F &value) \
00204 { getOptions().setOptionUVW(DataName, value); } \
00205 void set##FuncName(const UT_Vector3D &value) \
00206 { getOptions().setOptionUVW(DataName, value); }
00207 #define SET_DATA_FUNC_V4(DataName, FuncName) \
00208 void set##FuncName(const UT_Vector4F &value) \
00209 { getOptions().setOptionV4(DataName, value); } \
00210 void set##FuncName(const UT_Vector4D &value) \
00211 { getOptions().setOptionV4(DataName, value); }
00212 #define SET_DATA_FUNC_Q(DataName, FuncName) \
00213 void set##FuncName(const UT_QuaternionF &value) \
00214 { getOptions().setOptionQ(DataName, value); } \
00215 void set##FuncName(const UT_QuaternionD &value) \
00216 { getOptions().setOptionQ(DataName, value); }
00217 #define SET_DATA_FUNC_M3(DataName, FuncName) \
00218 void set##FuncName(const UT_Matrix3F &value) \
00219 { getOptions().setOptionM3(DataName, value); } \
00220 void set##FuncName(const UT_Matrix3D &value) \
00221 { getOptions().setOptionM3(DataName, value); }
00222 #define SET_DATA_FUNC_M4(DataName, FuncName) \
00223 void set##FuncName(const UT_Matrix4F &value) \
00224 { getOptions().setOptionM4(DataName, value); } \
00225 void set##FuncName(const UT_Matrix4D &value) \
00226 { getOptions().setOptionM4(DataName, value); }
00227 #define SET_DATA_FUNC_S(DataName, FuncName) \
00228 void set##FuncName(const UT_String &value) \
00229 { getOptions().setOptionS(DataName, value); }
00230
00231 #define SET_DATA_FUNC_RAMP(DataName, FuncName) \
00232 void set##FuncName(const UT_Ramp &ramp) const \
00233 { UT_OStrStream os; \
00234 ramp.save(os); \
00235 os << ends; \
00236 getOptions().setOptionS(DataName, os.str()); \
00237 os.rdbuf()->freeze(0); \
00238 }
00239
00240 #define GETSET_DATA_FUNCS_I(DataName, FuncName) \
00241 GET_DATA_FUNC_I(DataName, FuncName) \
00242 SET_DATA_FUNC_I(DataName, FuncName)
00243 #define GETSET_DATA_FUNCS_E(DataName, FuncName, EnumType) \
00244 GET_DATA_FUNC_E(DataName, FuncName, EnumType) \
00245 SET_DATA_FUNC_E(DataName, FuncName, EnumType)
00246 #define GETSET_DATA_FUNCS_B(DataName, FuncName) \
00247 GET_DATA_FUNC_B(DataName, FuncName) \
00248 SET_DATA_FUNC_B(DataName, FuncName)
00249 #define GETSET_DATA_FUNCS_F(DataName, FuncName) \
00250 GET_DATA_FUNC_F(DataName, FuncName) \
00251 SET_DATA_FUNC_F(DataName, FuncName)
00252 #define GETSET_DATA_FUNCS_V2(DataName, FuncName) \
00253 GET_DATA_FUNC_V2(DataName, FuncName) \
00254 SET_DATA_FUNC_V2(DataName, FuncName)
00255 #define GETSET_DATA_FUNCS_UV(DataName, FuncName) \
00256 GET_DATA_FUNC_UV(DataName, FuncName) \
00257 SET_DATA_FUNC_UV(DataName, FuncName)
00258 #define GETSET_DATA_FUNCS_V3(DataName, FuncName) \
00259 GET_DATA_FUNC_V3(DataName, FuncName) \
00260 SET_DATA_FUNC_V3(DataName, FuncName)
00261 #define GETSET_DATA_FUNCS_UVW(DataName, FuncName) \
00262 GET_DATA_FUNC_UVW(DataName, FuncName) \
00263 SET_DATA_FUNC_UVW(DataName, FuncName)
00264 #define GETSET_DATA_FUNCS_V4(DataName, FuncName) \
00265 GET_DATA_FUNC_V4(DataName, FuncName) \
00266 SET_DATA_FUNC_V4(DataName, FuncName)
00267 #define GETSET_DATA_FUNCS_Q(DataName, FuncName) \
00268 GET_DATA_FUNC_Q(DataName, FuncName) \
00269 SET_DATA_FUNC_Q(DataName, FuncName)
00270 #define GETSET_DATA_FUNCS_M3(DataName, FuncName) \
00271 GET_DATA_FUNC_M3(DataName, FuncName) \
00272 SET_DATA_FUNC_M3(DataName, FuncName)
00273 #define GETSET_DATA_FUNCS_M4(DataName, FuncName) \
00274 GET_DATA_FUNC_M4(DataName, FuncName) \
00275 SET_DATA_FUNC_M4(DataName, FuncName)
00276 #define GETSET_DATA_FUNCS_S(DataName, FuncName) \
00277 GET_DATA_FUNC_S(DataName, FuncName) \
00278 SET_DATA_FUNC_S(DataName, FuncName)
00279 #define GETSET_DATA_FUNCS_RAMP(DataName, FuncName) \
00280 GET_DATA_FUNC_RAMP(DataName, FuncName) \
00281 SET_DATA_FUNC_RAMP(DataName, FuncName)
00282
00283 #endif
00284