00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __PI_EditScriptedParms__
00020 #define __PI_EditScriptedParms__
00021
00022 #include "PI_API.h"
00023 #include <UT/UT_Color.h>
00024 #include <UT/UT_String.h>
00025 #include <UT/UT_StringArray.h>
00026 #include <UT/UT_PtrArray.h>
00027 #include <CH/CH_ExprLanguage.h>
00028 #include <PRM/PRM_Type.h>
00029 #include <OP/OP_Node.h>
00030
00031 class UT_IntArray;
00032 class UT_SymbolTable;
00033 class PRM_Template;
00034 class PRM_SpareData;
00035 class PRM_Parm;
00036 class PRM_Range;
00037 class PRM_ChoiceList;
00038 class PRM_ScriptImports;
00039 class OP_Operator;
00040 class PI_EditScriptedParms;
00041 class pi_GroupData;
00042
00043 #define PI_MAX_SCRIPT_PARM_SIZE 16
00044 #define PI_FOLDER_DEFAULTNAME "folder0"
00045
00046 typedef enum {
00047 PI_MENU_NORMAL = 0,
00048 PI_MENU_MINI = 1,
00049 PI_MENU_REPLACE = 2,
00050 PI_MENU_TOGGLE = 3
00051 } PI_EditScriptedParmMenuType;
00052
00053 typedef enum {
00054 PI_MENU_NONE = 0,
00055 PI_MENU_ITEMS = 1,
00056 PI_MENU_SCRIPT = 2
00057 } PI_EditScriptedParmMenuEnable;
00058
00059 typedef enum {
00060 PI_FOLDER_TAB,
00061 PI_FOLDER_RADIO,
00062 PI_FOLDER_IMPORT,
00063 PI_FOLDER_MULTILIST,
00064 PI_FOLDER_MULTISCROLL,
00065 PI_FOLDER_MULTISWITCHER,
00066 PI_FOLDER_ENDOFFOLDER,
00067 PI_FOLDER_NOTAFOLDER
00068 } PI_EditScriptedParmFolderType;
00069
00070 class PI_API PI_EditScriptedParmMenu
00071 {
00072 public:
00073 PI_EditScriptedParmMenu() {}
00074 PI_EditScriptedParmMenu( PI_EditScriptedParmMenu const& other );
00075
00076 bool isValidChoice() const
00077 {
00078 return myToken.isstring() || myLabel.isstring();
00079 }
00080 UT_String myToken;
00081 UT_String myLabel;
00082 };
00083
00084 class PI_API PI_EditScriptedParm
00085 {
00086 public:
00087 PI_EditScriptedParm();
00088 PI_EditScriptedParm(const PRM_Template &tplate, OP_Node *node,
00089 bool init_auto_links=true);
00090 PI_EditScriptedParm(PI_EditScriptedParmFolderType ftype);
00091 PI_EditScriptedParm(const PI_EditScriptedParm &src);
00092 ~PI_EditScriptedParm();
00093
00094 void setType(const char *type)
00095 {
00096 myType.harden(type);
00097 myCachedTypeIndex = -2;
00098 }
00099 const UT_String &getType() const { return myType; }
00100
00101 void changeTypeToRampColor();
00102 void changeTypeToRampFloat();
00103
00104
00105
00106
00107 void copyDefaultValuesFromParm(PRM_Parm *parm, int subidx);
00108
00109
00110
00111
00112 void setAutolinksToCurrentLinks(OP_Node *node, int subidx);
00113
00114
00115
00116
00117
00118
00119 void addParametersToAutolink(const UT_StringArray &parms,
00120 const char *nodepath,
00121 bool linkinvisibles,
00122 PI_EditScriptedParms *owner,
00123 UT_StringArray &errors);
00124
00125 void setRange(const PRM_Range &range);
00126
00127 int save(ostream &os, int indent, OP_Operator *op,
00128 const PI_EditScriptedParm *nextparm,
00129 bool in_import_block);
00130 int saveSelectors(ostream &os, const char *tokeni,
00131 OP_Operator *op);
00132 void saveSpareData(ostream &os,
00133 const char *tokeni,
00134 bool skip_import_data);
00135 void saveSpareValue(ostream &os, const char *tokeni,
00136 const char *spare_token);
00137
00138 void dump(ostream &os);
00139
00140 int getNMenu() const { return myMenu.entries(); }
00141 void addMenu(const char *token = 0, const char *label = 0);
00142 void moveMenu(int idx);
00143 void destroyMenu(int idx);
00144 int checkNullMenu();
00145 void clearMenuItems();
00146
00147 void setMenu(const PRM_ChoiceList *menu, bool minimenu);
00148
00149
00150
00151
00152
00153 int getParmTypeIdxForChannels() const;
00154
00155 void setSize(int size);
00156
00157
00158 void buildChannelNames(UT_StringArray &ch) const;
00159
00160
00161
00162
00163
00164 const UT_PtrArray<const char *> &getChannelNames() const;
00165
00166
00167
00168
00169 void extractGroupSpareData(const PRM_SpareData *ref,
00170 int index);
00171
00172
00173 void mergeSpareData(const PRM_SpareData *srcsparedata);
00174
00175 const char *getSpareValue(const char *token) const;
00176 void setSpareValue(const char *token, const char *value);
00177 void copySpareValue(const char *token,
00178 const PRM_SpareData &ref);
00179
00180 const char *getCallbackData() const;
00181 void setCallbackData(const char *value);
00182 CH_ScriptLanguage getCallbackLanguage() const;
00183 void setCallbackLanguage(CH_ScriptLanguage language);
00184
00185 const char *getOpFilter() const;
00186 void setOpFilter(const char *value);
00187 void setOpFilter(const PRM_SpareData *spareptr);
00188 const char *getRManType() const;
00189 void setRManType(const char *value);
00190 int getMultiStartOffset() const;
00191 void setMultiStartOffset(int value);
00192 void setRampColorType(UT_ColorType color_type);
00193 UT_ColorType getRampColorType() const;
00194 const char *getRampBasisVar() const;
00195 void setRampBasisVar(const char *value);
00196 const char *getRampKeysVar() const;
00197 void setRampKeysVar(const char *value);
00198 const char *getRampValuesVar() const;
00199 void setRampValuesVar(const char *value);
00200 const char *getImportSource() const;
00201 void setImportSource(const char *value);
00202 const char *getImportToken() const;
00203 void setImportToken(const char *value);
00204 const char *getImportMask() const;
00205 void setImportMask(const char *value);
00206 bool getImportEnable() const;
00207 void setImportEnable(bool value);
00208 bool getExportDisable() const;
00209 void setExportDisable(bool value);
00210 bool getUnquotedFlag() const;
00211 void setUnquotedFlag(bool value);
00212 bool getIsGroupStart() const;
00213 bool getIsGroupEnd() const;
00214 bool getIsGroupParm() const;
00215 bool getIsMultiParm() const;
00216 bool getIsRampParm() const;
00217 bool getIsRampParmColor() const;
00218 bool getIsRampParmFloat() const;
00219 bool getIsFileParm() const;
00220 bool getIsBasicStringParm() const;
00221
00222 const char *getRampBasisDefault() const;
00223 void setRampBasisDefault(const char *value);
00224 bool getRampShowControlsDefault() const;
00225 void setRampShowControlsDefault(bool value);
00226
00227 void clearRampDefaults();
00228
00229 const char *getFileChooserMode() const;
00230 void setFileChooserMode(const char *value);
00231
00232
00233 static const char *getScriptType(const PRM_Type &ptype,
00234 PRM_TypeExtended etype,
00235 PRM_MultiType mtype, int size);
00236
00237 static bool parmTypeUsesOpFilter(const char *type);
00238
00239 static const char *getExportDisableToken();
00240
00241 UT_String myName;
00242 UT_String myLabel;
00243 bool myUseLabel;
00244 UT_String myClass;
00245 UT_String myCategory;
00246 int myGroupID;
00247 bool myInvisible;
00248 int myExport;
00249 int mySize;
00250 UT_String myDefaults[PI_MAX_SCRIPT_PARM_SIZE];
00251 CH_ExprLanguage myDefaultExprLanguage;
00252 int myRangeEnable;
00253 float myRange[2];
00254 bool myRangeLock[2];
00255 PI_EditScriptedParmMenuEnable myMenuEnable;
00256 PI_EditScriptedParmMenuType myMenuType;
00257 PI_EditScriptedParmFolderType myFolderType;
00258 UT_String myMenuScript;
00259 CH_ScriptLanguage myMenuScriptLanguage;
00260 int myDoAutolink[PI_MAX_SCRIPT_PARM_SIZE];
00261 UT_String myAutolink[PI_MAX_SCRIPT_PARM_SIZE];
00262 UT_String myOldAutolink[PI_MAX_SCRIPT_PARM_SIZE];
00263 UT_String myDisable;
00264 UT_String myHelpText;
00265 UT_PtrArray<PI_EditScriptedParmMenu *> myMenu;
00266 PRM_SpareData *mySpareData;
00267 bool myJoinNextFlag;
00268 bool myTabBreak;
00269 bool myReserved;
00270
00271 class PI_API PI_ParmType {
00272 public:
00273 const char *myLabel;
00274 const char *myDSToken;
00275 PRM_Type myType;
00276 const char *myIcon;
00277 int myExport;
00278 int mySize;
00279 int myMenu;
00280 int myString;
00281 int myRange;
00282 float myMin, myMax;
00283 const char *myDefault;
00284 const char *mySuffix[PI_MAX_SCRIPT_PARM_SIZE];
00285 int myUseFloatDefs;
00286 };
00287 static PI_ParmType theParmTypes[];
00288
00289 private:
00290 void defaultInit();
00291 void initMenu(const PRM_ChoiceList *menu, bool minimenu);
00292
00293 void updateChannelNameCache(int parmtypeidx) const;
00294 void rebuildChannelNameCache(int parmtypeidx) const;
00295
00296 UT_String myType;
00297 mutable int myCachedTypeIndex;
00298
00299
00300
00301 mutable UT_PtrArray<const char *> myCachedChannelNames;
00302 mutable UT_String myChannelCacheToken;
00303 mutable int myChannelCacheTypeIndex;
00304
00305 };
00306
00307 typedef UT_PtrArray<PI_EditScriptedParm *> PI_EditScriptedParmArray;
00308
00309 class PI_API PI_EditScriptedParms
00310 {
00311 public:
00312 PI_EditScriptedParms();
00313
00314 PI_EditScriptedParms(OP_Node *node,
00315 bool add_reserved_parms,
00316 bool init_auto_links);
00317
00318 PI_EditScriptedParms(OP_Operator *op,
00319 OP_Node *node,
00320 bool add_reserved_parms);
00321
00322
00323
00324 PI_EditScriptedParms(OP_Node *node,
00325 UT_IStream &is,
00326 bool spareparms,
00327 bool skip_reserved,
00328 bool init_auto_links);
00329
00330
00331
00332 PI_EditScriptedParms(OP_Node *node,
00333 const PRM_Template *tplate,
00334 bool spareparms,
00335 bool skip_reserved,
00336 bool init_auto_links);
00337
00338 PI_EditScriptedParms(const PI_EditScriptedParms &src);
00339 ~PI_EditScriptedParms();
00340
00341
00342
00343
00344
00345
00346
00347 void mergeParms(const PI_EditScriptedParms &src);
00348
00349
00350 void clearParms();
00351
00352
00353 int save(ostream &os, UT_String &warnings);
00354
00355
00356 void dump(ostream &os);
00357
00358
00359
00360
00361 void compile();
00362
00363
00364 PI_EditScriptedParmArray &getParms() { return myParms; }
00365 int getNParms() const;
00366 PI_EditScriptedParm *getParm(int i);
00367 int getParmIndexWithName(const char *name);
00368 PI_EditScriptedParm *getParmWithName(const char *name);
00369 int getParmIndex(PI_EditScriptedParm *p);
00370 PI_EditScriptedParm *getFolderWithLabel(const char *label);
00371
00372
00373
00374 int getNestedFolderIndex(
00375 const UT_StringArray &folder_labels);
00376
00377
00378
00379 void getContainingFolders(
00380 int parm_index,
00381 UT_PtrArray<PI_EditScriptedParm *> &result);
00382
00383
00384 PI_EditScriptedParm *getParmWithAutolink(const char *channelpath,
00385 const char *nodepath,
00386 int *linkedsubidx = 0);
00387
00388
00389
00390 int getMatchingGroupParm(int parm) const;
00391
00392
00393
00394 bool getIsFirstPage(int parm) const;
00395
00396
00397
00398 int getParentGroupParm(int parm);
00399
00400
00401 int getNMenu(int parm);
00402 PI_EditScriptedParmMenu *getMenu(int parm, int i);
00403 const char *getMenuScript(int parm);
00404
00405
00406
00407
00408 bool isParmMoveAllowed(int first, int last, int offset);
00409
00410
00411 void addParm(PI_EditScriptedParm *parm);
00412 bool moveParms(int first, int last, int offset);
00413 void moveParms(const UT_IntArray &movingparms, int destpos);
00414
00415
00416
00417
00418 void insertMultiParmTemplates(const PRM_Template *tplate,
00419 const char *parentparmname,
00420 const OP_Node *linktonode,
00421 const char *nameprefix,
00422 const char *labelprefix,
00423 int insertat);
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435 void permuteParms(int first,
00436 const UT_IntArray &permutation);
00437
00438
00439
00440
00441 int removeParms(int first, int last);
00442
00443
00444
00445 void removeInvalidJoins();
00446
00447
00448 void copyDefaultsFromNode(OP_Node *node);
00449
00450 int checkReservedName(const char *name) const;
00451 bool containsReservedParm() const;
00452 void initializeReserveNames(OP_Parameters *node);
00453 void initializeReserveFlags();
00454 void makeSafeParmName(PI_EditScriptedParm *parm,
00455 UT_String &parmname,
00456 const UT_SymbolTable *extrareserved,
00457 bool checkexistingparms);
00458
00459
00460
00461 void setAutolinksToCurrentLinks();
00462
00463
00464
00465
00466
00467
00468 void addParametersToAutolinks(PI_EditScriptedParm &destparm,
00469 const UT_StringArray &parms,
00470 const char *nodepath,
00471 bool linkinvisibles,
00472 PI_EditScriptedParmArray &changedparms,
00473 UT_StringArray &errors);
00474
00475
00476
00477
00478 void fixParmNamesForInstanceLevel();
00479
00480
00481
00482
00483 void applyAutoLinks(UT_StringArray &errors,
00484 OP_NodeList &changednodes,
00485 UT_IntArray &changedparms);
00486
00487
00488
00489
00490 void updateNodesFromApplyAutoLinks(
00491 OP_NodeList &changednodes,
00492 UT_IntArray &changedparms);
00493
00494
00495
00496
00497 bool updateAutoLinksForNameChange(
00498 const UT_String &refnodepath,
00499 const UT_String &oldpath,
00500 const UT_String &newpath);
00501
00502
00503
00504
00505 OP_Node *getNode() const;
00506
00507
00508
00509 static void buildMultiparmInfo(OP_Node *refnode);
00510 static void clearMultiparmInfo();
00511 static void lockMultiparmInfo();
00512 static void releaseMultiparmInfo();
00513 static const UT_SymbolTable &getBuiltMultiparmInfo();
00514
00515 private:
00516
00517
00518
00519 const PRM_Template *getBaseParmTemplates() const;
00520
00521
00522 const PRM_Template *getBaseParmTemplate(const char *parmname) const;
00523
00524
00525
00526 void buildMParmInst(PI_EditScriptedParm *skipparm,
00527 UT_StringArray &mparminst,
00528 UT_IntArray &mparmlvl) const;
00529
00530
00531
00532 int getMultiParmInstanceLevel(
00533 PI_EditScriptedParm *parm) const;
00534
00535
00536
00537
00538 bool conflictsWithTemplate(const PRM_Template *tplate,
00539 const UT_StringArray &mparmtplates,
00540 const UT_StringArray &channels,
00541 const UT_StringArray &mparminst,
00542 const UT_IntArray &mparmlvl) const;
00543
00544 void createImportGroups(int offset,
00545 UT_RefArray<pi_GroupData> &gstack,
00546 const PRM_ScriptImports *imports,
00547 int &import_index);
00548 void createImportGroupsBeforeGroupEnd(
00549 int offset, int depth,
00550 int switcher_index, int folder,
00551 const PRM_ScriptImports *imports,
00552 int &import_index);
00553 void createParms(const PRM_Template *tplates,
00554 const PRM_ScriptImports *imports,
00555 bool skip_reserved,
00556 bool init_auto_links=true);
00557 void createParms(UT_PtrArray<const PRM_Template *> &tplates,
00558 const PRM_ScriptImports *imports,
00559 bool skip_reserved,
00560 bool init_auto_links=true);
00561 void removeInvalidGroups(int startpos);
00562
00563 void saveGroupHeader(ostream &os, int index,
00564 int &glevel,
00565 int &import_depth,
00566 bool &in_import_block);
00567 void saveGroupFooter(ostream &os, int index,
00568 int &glevel,
00569 int &import_depth,
00570 bool &in_import_block);
00571 void saveImportHeader(ostream &os, int index,
00572 int &glevel,
00573 int &import_depth,
00574 bool &in_import_block);
00575 void saveImportFooter(ostream &os, int index,
00576 int &glevel,
00577 int &import_depth,
00578 bool &in_import_block);
00579 void saveMultiParmHeader(ostream &os, int index,
00580 int &glevel,
00581 int &import_depth,
00582 bool &in_import_block);
00583 void saveMultiParmFooter(ostream &os, int index,
00584 int &glevel,
00585 int &import_depth,
00586 bool &in_import_block);
00587
00588 PI_EditScriptedParmArray myParms;
00589 UT_SymbolTable myReservedParmNames;
00590 OP_Operator *myOp;
00591 int myNodeId;
00592 bool myIsEditingSpareParms;
00593 };
00594
00595 #endif
00596