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 #ifndef __PRM_Template__
00026 #define __PRM_Template__
00027
00028 #include "PRM_API.h"
00029 #include <SYS/SYS_Types.h>
00030 #include <UT/UT_IntArray.h>
00031 #include <UT/UT_PtrArray.h>
00032 #include <UT/UT_String.h>
00033 #include "PRM_Callback.h"
00034 #include "PRM_Conditional.h"
00035 #include "PRM_Name.h"
00036 #include "PRM_Type.h"
00037
00038 #define PRM_TYPE_IS_SWITCHER(type) (type.isSwitcher())
00039
00040 #define PRM_IS_JOIN(parm) (parm.getTypeExtended() == PRM_TYPE_TOGGLE_JOIN || \
00041 parm.getTypeExtended() == PRM_TYPE_JOIN_PAIR)
00042
00043 class PRM_ChoiceList;
00044 class PRM_Range;
00045 class PRM_Default;
00046 class PRM_Template;
00047 class PRM_SpareData;
00048
00049 PRM_API extern PRM_ChoiceList PRMtoggleMenu;
00050
00051 class PRM_API PRM_Template
00052 {
00053 public:
00054
00055
00056
00057
00058
00059 enum PRM_Export
00060 {
00061 PRM_EXPORT_MIN,
00062 PRM_EXPORT_MED,
00063 PRM_EXPORT_MAX,
00064 PRM_EXPORT_TBX
00065 };
00066
00067 enum
00068 {
00069
00070
00071
00072
00073 MAX_VECTOR_SIZE = 31
00074 };
00075
00076
00077 PRM_Template(PRM_Type thetype = PRM_LIST_TERMINATOR,
00078 int thevectorsize = 1,
00079 PRM_Name *thenameptr = 0,
00080 PRM_Default *thedefaults = 0,
00081 PRM_ChoiceList *thechoicelistptr = 0,
00082 PRM_Range *therangeptr = 0,
00083 PRM_Callback thecallbackfunc = 0,
00084 PRM_SpareData *thespareptr = 0,
00085 int theparmgroup = 1,
00086 const char *thehelptext = 0,
00087 PRM_ConditionalBase *thecondptr = 0);
00088
00089
00090 PRM_Template(PRM_Type thetype,
00091 PRM_Export theexportlevel,
00092 int thevectorsize = 1,
00093 PRM_Name *thenameptr = 0,
00094 PRM_Default *thedefaults = 0,
00095 PRM_ChoiceList *thechoicelistptr = 0,
00096 PRM_Range *therangeptr = 0,
00097 PRM_Callback thecallbackfunc = 0,
00098 PRM_SpareData *thespareptr = 0,
00099 int theparmgroup = 1,
00100 const char *thehelptext = 0,
00101 PRM_ConditionalBase *thecondptr = 0);
00102
00103
00104 PRM_Template(PRM_Type thetype,
00105 PRM_TypeExtended thetype_ext,
00106 int thevectorsize = 1,
00107 PRM_Name *thenameptr = 0,
00108 PRM_Default *thedefaults = 0,
00109 PRM_ChoiceList *thechoicelistptr = 0,
00110 PRM_Range *therangeptr = 0,
00111 PRM_Callback thecallbackfunc = 0,
00112 PRM_SpareData *thespareptr = 0,
00113 int theparmgroup = 1,
00114 const char *thehelptext = 0,
00115 PRM_ConditionalBase *thecondptr = 0);
00116
00117
00118 PRM_Template(PRM_Type thetype,
00119 PRM_TypeExtended thetype_ext,
00120 PRM_Export theexportlevel,
00121 int thevectorsize = 1,
00122 PRM_Name *thenameptr = 0,
00123 PRM_Default *thedefaults = 0,
00124 PRM_ChoiceList *thechoicelistptr = 0,
00125 PRM_Range *therangeptr = 0,
00126 PRM_Callback thecallbackfunc = 0,
00127 PRM_SpareData *thespareptr = 0,
00128 int theparmgroup = 1,
00129 const char *thehelptext = 0,
00130 PRM_ConditionalBase *thecondptr = 0);
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 PRM_Template(PRM_MultiType thetype,
00148 PRM_Template *thetemplates,
00149 PRM_Export theexportlevel,
00150 fpreal multisize,
00151 PRM_Name *thenameptr,
00152 PRM_Default *thedefaultsize = 0,
00153 PRM_Range *thedefaultrange = 0,
00154 PRM_SpareData *thespareptr = 0,
00155 const char *thehelptext = 0,
00156 PRM_ConditionalBase *thecondptr = 0,
00157 PRM_Callback thecallbackfunc = 0
00158 );
00159
00160 PRM_Template(PRM_MultiType thetype,
00161 PRM_Template *thetemplates,
00162 fpreal multisize,
00163 PRM_Name *thenameptr,
00164 PRM_Default *thedefaultsize = 0,
00165 PRM_Range *thedefaultrange = 0,
00166 PRM_SpareData *thespareptr = 0,
00167 const char *thehelptext = 0,
00168 PRM_ConditionalBase *thecondptr = 0,
00169 PRM_Callback thecallbackfunc = 0
00170 );
00171 PRM_Template(const PRM_Template &src);
00172 ~PRM_Template();
00173
00174 const PRM_Template &operator=(const PRM_Template &src);
00175
00176 void initialize(PRM_Type thetype,
00177 PRM_TypeExtended thetype_ext,
00178 PRM_Export theexportlevel,
00179 int thevectorsize,
00180 PRM_Name *thenameptr,
00181 PRM_Default *thedefaults,
00182 PRM_ChoiceList *thechoicelistptr,
00183 PRM_Range *therangeptr,
00184 PRM_Callback thecallbackfunc,
00185 PRM_SpareData *thespareptr,
00186 int theparmgroup,
00187 const char *thehelptext,
00188 PRM_ConditionalBase *thecondptr);
00189
00190 void initMulti(PRM_MultiType thetype,
00191 PRM_Template *thetemplates,
00192 PRM_Export theexportlevel,
00193 fpreal multisize,
00194 PRM_Name *thenameptr,
00195 PRM_Default *thedefaultsize,
00196 PRM_Range *thedefaultrange,
00197 PRM_Callback thecallbackfunc,
00198 PRM_SpareData *thespareptr,
00199 const char *thehelptext,
00200 PRM_ConditionalBase *thecondptr
00201 );
00202
00203
00204
00205 void assign(const PRM_Template &src, int thevectorsize,
00206 PRM_Default *thedefaults);
00207
00208 const PRM_Type &getType() const { return myType; }
00209 PRM_MultiType getMultiType() const { return myMultiType; }
00210 bool isMultiType() const;
00211 bool isRampType() const;
00212 bool isRampTypeColor() const;
00213 PRM_TypeExtended getTypeExtended() const { return myTypeExtended; }
00214 int getVectorSize() const { return myVectorSize; }
00215 fpreal getMultiSize() const { return myMultiSize; }
00216 void setNamePtr(PRM_Name *name) { myNamePtr = name; }
00217 PRM_Name *getNamePtr() { return myNamePtr; }
00218 const PRM_Name *getNamePtr() const { return myNamePtr; }
00219 PRM_SpareData *getSparePtr() { return mySparePtr; }
00220 const PRM_SpareData *getSparePtr() const { return mySparePtr; }
00221 PRM_SpareData *getOrCreateSparePtr();
00222 PRM_Conditional *getConditionalPtr(PRM_ConditionalType type)
00223 { return myConditionalPtr?myConditionalPtr->getConditional(type):NULL;}
00224
00225 const PRM_Conditional *getConditionalPtr(PRM_ConditionalType type) const
00226 { return myConditionalPtr?myConditionalPtr->getConditional(type):NULL;}
00227 PRM_ConditionalBase *getConditionalBasePtr()
00228 { return myConditionalPtr; }
00229 const PRM_ConditionalBase *getConditionalBasePtr() const
00230 { return myConditionalPtr; }
00231
00232 PRM_Conditional SYS_DEPRECATED *getDisablePtr()
00233 { return getConditionalPtr(PRM_CONDTYPE_DISABLE); }
00234 const PRM_Conditional SYS_DEPRECATED *getDisablePtr() const
00235 { return getConditionalPtr(PRM_CONDTYPE_DISABLE); }
00236 const PRM_ChoiceList *getChoiceListPtr() const
00237 {
00238 const PRM_ChoiceList *list;
00239 if (!myChoiceListPtr &&
00240 (myType & PRM_TYPE_ORDINAL) &&
00241 (myType & PRM_TYPE_TOGGLE))
00242 list = &PRMtoggleMenu;
00243 else
00244 list = myChoiceListPtr;
00245 return list;
00246 }
00247 PRM_ChoiceList *getChoiceListPtr()
00248 {
00249 PRM_ChoiceList *list;
00250 if (!myChoiceListPtr &&
00251 (myType & PRM_TYPE_ORDINAL) &&
00252 (myType & PRM_TYPE_TOGGLE))
00253 list = &PRMtoggleMenu;
00254 else
00255 list = myChoiceListPtr;
00256 return list;
00257 }
00258 void setChoiceListPtr(PRM_ChoiceList *list)
00259 {
00260 myChoiceListPtr = list;
00261 }
00262 const PRM_Range *getRangePtr() const { return myRangePtr; }
00263 PRM_Range *getRangePtr() { return myRangePtr; }
00264 PRM_Callback getCallback() const { return myCallbackFunc; }
00265 void setCallback(PRM_Callback callback)
00266 { myCallbackFunc = callback; }
00267 const UT_String &getHelpText() const { return myHelpText; }
00268 unsigned int getAutoScopeField();
00269
00270 const PRM_Template *getMultiParmTemplate() const
00271 { return myMultiParmTemplate; }
00272 PRM_Template *getMultiParmTemplate()
00273 { return myMultiParmTemplate; }
00274 void setMultiParmTemplate(PRM_Template *tplate)
00275 { myMultiParmTemplate = tplate; }
00276 int getMultiStartOffset() const;
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 static bool matchMultiInstance(const char *name,
00288 const char *multi_name,
00289 int start_offset,
00290 int &index,
00291 const UT_IntArray *instance_index);
00292
00293 PRM_Default *getDefault(int index)
00294 {
00295 return (index >= 0 && index < myVectorSize)
00296 ? myDefaults(index) : 0;
00297 }
00298 const PRM_Default *getDefault(int index) const
00299 {
00300 return (index >= 0 && index < myVectorSize)
00301 ? myDefaults(index) : 0;
00302 }
00303 PRM_Default *getFactoryDefaults() const
00304 {
00305 return myFactoryDefaults;
00306 }
00307 void setFactoryDefaults(PRM_Default *defaults)
00308 {
00309 myFactoryDefaults = defaults;
00310 }
00311 void restoreFactoryDefaults();
00312 void setFloatDefault(int index, fpreal v);
00313 void setOrdinalDefault(int index, int v);
00314 void setStringDefault(int index, const char *v);
00315 void setDefault(int index, const PRM_Default &d);
00316
00317
00318
00319
00320
00321
00322
00323 void setNoResim(bool noresim);
00324 void setNoCook(bool nocook);
00325
00326
00327
00328
00329 bool setNoCook(const PRM_SpareData *spare,
00330 bool force=false);
00331 void setBaseParm(bool baseparm);
00332 void setInvisible(bool invisible);
00333 bool getInvisible() const
00334 { return (myType & PRM_TYPE_INVISIBLE) != 0; }
00335 void setJoinNext(bool joinnext);
00336
00337 void setTypeExtended(PRM_TypeExtended type_ext)
00338 { myTypeExtended = type_ext; }
00339
00340 PRM_Export exportLevel() const
00341 { return (PRM_Export)myExportLevel; }
00342 void setExportLevel(PRM_Export level)
00343 { myExportLevel = (unsigned char)level; }
00344 int getParmGroup() const { return (int)myParmGroup; }
00345
00346
00347 int findSubIndex(const char *thechannelname);
00348
00349 void getChannelToken(UT_String &thestrref,
00350 int theindex) const;
00351 void getChannelLabel(UT_String &thestrref,
00352 int theindex) const;
00353 void getToken(UT_String &thestrref) const
00354 {
00355 thestrref = myNamePtr->getToken();
00356 }
00357 void getLabel(UT_String &thestrref) const
00358 {
00359 thestrref = myNamePtr->getLabel();
00360 }
00361
00362 int getExpressionFlag() const
00363 {
00364 return myNamePtr->getExpressionFlag();
00365 }
00366
00367
00368
00369 const char *getToken() const
00370 {
00371 return myNamePtr->getToken();
00372 }
00373 const char *getLabel() const
00374 {
00375 return myNamePtr->getLabel();
00376 }
00377 unsigned getTokenHash() const
00378 {
00379 return myNamePtr->getHash();
00380 }
00381
00382
00383
00384
00385
00386
00387
00388
00389 static int countTemplates(
00390 const PRM_Template *templates,
00391 bool for_switcher = false,
00392 bool for_joins = false,
00393 bool for_rows = false);
00394
00395
00396 static int getTemplateIndexByToken(
00397 const PRM_Template *templates,
00398 const char * token);
00399
00400
00401
00402 static const PRM_Template *getEndOfSwitcher(
00403 const PRM_Template *templates);
00404
00405
00406 static void getSwitcherStats(
00407 const PRM_Template *templates,
00408 UT_IntArray &numswitchersonpages,
00409 UT_IntArray &numnonswitchersonpages);
00410
00411 static bool getEnclosingSwitcherFolder(
00412 const PRM_Template *tplates,
00413 const int index,
00414 int &switcher, int &folder);
00415
00416
00417
00418 bool isAutomaticallyGeneratedChoiceList() const;
00419
00420
00421
00422 int findSwitcherFolderWithLabel(
00423 const char *label) const;
00424
00425 private:
00426 void clearOurData();
00427 void buildChannelNames() const;
00428 void buildChannelName(UT_String &str, int index) const;
00429 void setAutoScopeField();
00430
00431 PRM_Type myType;
00432 PRM_MultiType myMultiType;
00433 PRM_TypeExtended myTypeExtended;
00434 int myVectorSize;
00435 PRM_Name *myNamePtr;
00436 UT_PtrArray<PRM_Default *> myDefaults;
00437 PRM_Default *myFactoryDefaults;
00438 PRM_ChoiceList *myChoiceListPtr;
00439 PRM_Range *myRangePtr;
00440 PRM_Callback myCallbackFunc;
00441 PRM_SpareData *mySparePtr;
00442 PRM_ConditionalBase *myConditionalPtr;
00443 unsigned char myExportLevel;
00444 unsigned char myParmGroup;
00445 unsigned int myAutoScopeField;
00446 PRM_Template *myMultiParmTemplate;
00447 fpreal myMultiSize;
00448 UT_String myHelpText;
00449 mutable char **myChannelNames;
00450 };
00451
00452 #endif