00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __VOP_Node_h__
00020 #define __VOP_Node_h__
00021
00022 #include <set>
00023 #include <map>
00024
00025 #include "VOP_API.h"
00026 #include "VOP_Error.h"
00027 #include "VOP_Language.h"
00028 #include "VOP_TypeInfo.h"
00029 #include "VOP_OperatorInfo.h"
00030 #include "VOP_OutputInfoManager.h"
00031 #include <OP/OP_Network.h>
00032 #include <UT/UT_BitArray.h>
00033 #include <UT/UT_PtrArray.h>
00034 #include <vector>
00035
00036 #define FLAG_OPT_LOW 'L'
00037 #define FLAG_OPT_MEDIUM 'M'
00038 #define FLAG_OPT_HIGH 'H'
00039 #define VOP_DEBUG_FLAG 'D'
00040
00041
00042
00043 #define VOP_PARMORDER_NAME "parmorder"
00044 #define VOP_GLOBAL_NODE_NAME "global"
00045 #define VOP_ILLUM_NODE_NAME "illuminance"
00046 #define VOP_PARM_NODE_NAME "parameter"
00047 #define VOP_CONST_NODE_NAME "constant"
00048 #define VOP_PARMRAMP_NODE_NAME "rampparm"
00049 #define VOP_INLINE_CODE_NODE_NAME "inline"
00050 #define VOP_COLLECT_NODE_NAME "collect"
00051 #define VOP_RSL_PREFIX "rsl_"
00052 #define VOP_VARIABLE_INOUT_MAX 2048
00053
00054 class VOP_Node;
00055 class VOP_GlobalVarData;
00056 class VOP_ParmGenerator;
00057 class VOP_AutoConvert;
00058 class VOP_CodeVarMapperContext;
00059 class VOP_CodeParmList;
00060
00061 extern "C" {
00062 SYS_VISIBILITY_EXPORT extern void newVopOperator(OP_OperatorTable *table);
00063 };
00064
00065 typedef UT_PtrArray<VOP_Node *> VOP_NodeList;
00066 typedef UT_PtrArray<VOP_GlobalVarData *> VOP_GlobalVarList;
00067 typedef UT_PtrArray<VOP_ParmGenerator *> VOP_ParmGeneratorList;
00068
00069 struct VOP_AutoConvertInfo
00070 {
00071
00072 VOP_AutoConvert* myACNode;
00073 int myIndex;
00074 };
00075 typedef std::vector < VOP_AutoConvertInfo > TAutoConvertInfos;
00076
00077 typedef std::set < int > TIntSet;
00078 struct VOP_MergeNodeInfo
00079 {
00080 VOP_Node* myNode;
00081 TIntSet myInputIndices;
00082 };
00083 typedef std::map <VOP_Node*, VOP_MergeNodeInfo> TMergeNodeInfos;
00084
00085 class VOP_API VOP_VarInfo
00086 {
00087 public:
00088 VOP_VarInfo() : myDescription( UT_String::ALWAYS_DEEP ) {}
00089
00090 UT_String myDescription;
00091 VOP_ContextType myContextType;
00092 int myVarIndex;
00093 VOP_TypeInfo myTypeInfo;
00094 bool myReadable;
00095 bool myWritable;
00096 bool myIlluminanceVar;
00097 };
00098
00099 class VOP_API VOP_GlobalVarData
00100 {
00101 public:
00102 VOP_GlobalVarData( const char * name, const VOP_VarInfo & info );
00103 ~VOP_GlobalVarData();
00104 void appendInfo( const VOP_VarInfo & info );
00105
00106 const UT_String & getName() const
00107 { return myName; }
00108
00109 const UT_String & getDescription( VOP_ContextType type ) const;
00110 const VOP_TypeInfo & getTypeInfo( VOP_ContextType type ) const;
00111 int getVarIndex( VOP_ContextType type ) const;
00112 bool isReadable( VOP_ContextType type ) const;
00113 bool isWriteable( VOP_ContextType type ) const;
00114 bool isIlluminance( VOP_ContextType type ) const;
00115 bool isValidInContext( VOP_ContextType type ) const;
00116
00117 private:
00118 template<typename T> T getInfoMember( VOP_ContextType ctx_type,
00119 T VOP_VarInfo::*member,
00120 T default_val ) const;
00121 template<typename T> const T &getInfoMemberRef( VOP_ContextType ctx_type,
00122 T VOP_VarInfo::*member,
00123 const T & default_val ) const;
00124 int getIndexForContextType( VOP_ContextType type) const;
00125
00126 private:
00127 UT_String myName;
00128 UT_RefArray<VOP_VarInfo> myInfos;
00129 };
00130
00131 class VOP_API VOP_OutputNameEditorSource
00132 {
00133 public:
00134 virtual ~VOP_OutputNameEditorSource();
00135 virtual int getNumInputsFromParent() const = 0;
00136 virtual void NAMEFROMPARM(UT_String &str, int idx) const = 0;
00137 virtual void LABELFROMPARM(UT_String &str, int idx) const = 0;
00138 virtual void setNAMEFROMPARM(UT_String &str, int idx) = 0;
00139 virtual void setLABELFROMPARM(UT_String &str, int idx) = 0;
00140 };
00141
00142 class VOP_API VOP_Node : public OP_Network
00143 {
00144 public:
00145 virtual const char *getChildType() const;
00146 virtual const char *getOpType() const;
00147
00148 virtual OP_OpTypeId getChildTypeID() const;
00149 virtual OP_OpTypeId getOpTypeID() const;
00150
00151
00152 virtual OP_DATA_TYPE getCookedDataType() const;
00153
00154
00155
00156 virtual void opChanged(OP_EventType reason, void *data=0);
00157 virtual void referencedParmChanged(int pi);
00158
00159 static void buildOperatorTable(OP_OperatorTable &table);
00160
00161
00162
00163
00164 virtual void getParameterBlock(UT_String &parmstr,
00165 const char *shader_contexts);
00166
00167
00168 virtual void getParameterDeclaration(UT_String &parmdecl,
00169 const VOP_Language *language,
00170 const VOP_ContextType *type);
00171 virtual void getPragmas(UT_String &pragmastr,
00172 VOP_ContextType context_type);
00173 virtual void getOuterCode(UT_String &codestr);
00174 virtual void getCode(UT_String &codestr,
00175 VOP_CodeVarMapperContext *context=NULL);
00176 virtual bool getParmConstantString(const char *parmname,
00177 VOP_Type type,
00178 UT_String &str,
00179 bool expand_string,
00180 const VOP_Language *l=0);
00181
00182
00183
00184
00185 virtual void getPostSubnetCode(UT_String &post_code);
00186
00187
00188 virtual bool getIsParmGenerator() const;
00189
00190
00191
00192
00193
00194
00195 virtual bool getExportParm(VOP_ContextType context_type,
00196 UT_String &varname);
00197
00198
00199
00200 virtual void initializeNode();
00201
00202
00203
00204 virtual void ensureParametersAreValid();
00205 static void incrementVariableName(UT_String &varname);
00206
00207
00208
00209 virtual void getOutputName(UT_String &out, int idx) const;
00210 virtual int getOutputFromName(const UT_String &out) const;
00211 VOP_Type getOutputType(int idx);
00212 void getOutputTypeInfo(VOP_TypeInfo &type_info, int idx);
00213 VOP_Type getNamedOutputType(const OP_ConnectorId& output_name);
00214 void getNamedOutputTypeInfo(VOP_TypeInfo &type_info,
00215 const OP_ConnectorId& output_name);
00216
00217
00218
00219 virtual void getInputName(UT_String &in, int idx) const;
00220 virtual int getInputFromName(const UT_String &in) const;
00221
00222
00223 VOP_Type getInputType(int idx);
00224 void getInputTypeInfo(VOP_TypeInfo &type_info, int idx);
00225 VOP_Type getNamedInputType(const OP_ConnectorId& input_name);
00226 void getNamedInputTypeInfo(VOP_TypeInfo &type_info,
00227 const OP_ConnectorId& input_name);
00228
00229
00230
00231 virtual bool getIsVisible(int idx);
00232
00233
00234
00235 virtual void getAllowedInputTypes(unsigned idx,
00236 VOP_VopTypeArray &voptypes);
00237
00238
00239
00240
00241
00242
00243
00244
00245 virtual bool getCurrentSignatureName(UT_String &name);
00246
00247
00248
00249 virtual bool areOutputVariablesFixed(VOP_ContextType context_type);
00250 virtual void getFixedOutputVariable(UT_String &var, int idx);
00251
00252
00253
00254
00255
00256
00257
00258 virtual void getVariablesImportedFromParentSubnet(
00259 UT_StringArray & ref_vars );
00260
00261
00262
00263
00264
00265 void mergeInputNodeList(VOP_NodeList &nodes,
00266 TMergeNodeInfos &merge_infos);
00267
00268
00269
00270
00271
00272 static void deleteAutoConvertNodesIn(VOP_NodeList& nodes);
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 virtual bool forceCodeGenerationOfInputs(
00286 VOP_ContextType context_type,
00287 bool essential) const;
00288
00289
00290
00291 virtual bool getIsEncapsulatedShader() const;
00292
00293 virtual void updateEncapsulatedParameters(const VOP_CodeParmList &parms);
00294
00295
00296
00297
00298 virtual bool getEncapsulatedShaderName(UT_WorkBuffer &name) const;
00299
00300
00301 virtual bool getEncapsulatedShaderPath(UT_WorkBuffer &name) const;
00302
00303
00304
00305
00306 virtual bool getIsScriptedShader();
00307
00308
00309 virtual bool getScriptedShaderName(UT_WorkBuffer &name);
00310
00311
00312
00313
00314
00315
00316 const UT_SymbolTable*getGlobalVariables() const;
00317 const UT_SymbolTable*getLocalVariables() const;
00318 const UT_SymbolTable*getLocalChannels() const;
00319 void setTables(const UT_SymbolTable *globals,
00320 UT_SymbolTable *locals,
00321 UT_SymbolTable *channels);
00322 void setTablesFromVop(VOP_Node *vop);
00323 void addLocalVariable(const char *varname,
00324 VOP_ParmGenerator *definer);
00325 void deleteLocalVariable(const char *varname);
00326 void getSortedGlobalVariableList(VOP_GlobalVarList &vars,
00327 VOP_ContextType type,
00328 bool mustBeReadable,
00329 bool mustBeWritable);
00330
00331
00332
00333 virtual void setExtraFlag(char flag, int onoff);
00334 int setInOutLOD(int level, int inoff);
00335 int getInOutLOD(int level) const;
00336 static int &getLODPref() { return theLODPref; }
00337 static void setLODPref(int value);
00338
00339
00340
00341 virtual OP_ERROR setInput(unsigned idx, OP_Node *op,
00342 unsigned outputIdx = 0);
00343 virtual OP_ERROR setInputReference(unsigned idx, const char *label,
00344 int keeppos, unsigned outputIdx = 0);
00345
00346 virtual OP_ERROR setNamedInput(const OP_ConnectorId& input_name, OP_Node *op,
00347 const OP_ConnectorId* output_name = NULL);
00348 virtual OP_ERROR setNamedInputReference(const OP_ConnectorId& input_name,
00349 const char *label, int, const OP_ConnectorId* output_name = NULL);
00350
00351
00352
00353
00354 virtual void moveInput(int srcidx, int dstidx,
00355 bool forcesubnet = false);
00356
00357
00358
00359
00360
00361
00362 virtual bool isConnected(int inputidx, bool recursive);
00363
00364
00365 virtual VOP_OutputNameEditorSource *getOutputNameEditorSource()
00366 { return 0; }
00367
00368
00369
00370
00371
00372
00373 virtual VOP_Node *getSubnetOutputNode() const;
00374
00375
00376 virtual bool isSubnetInput() const
00377 { return false; }
00378
00379
00380
00381
00382 VOP_Node *insertParmGenerator(int inputidx, bool makeparmnode);
00383 VOP_Node *insertNode(int inputidx, const char* nodetype, bool connect_to_input, const char* undo_string = NULL);
00384
00385
00386
00387
00388
00389 virtual VOP_ParmGenerator *getInsertParmGeneratorSource(int inputidx);
00390
00391
00392
00393 void insertParmGeneratorsForAllInputs(bool makeparmnodes);
00394
00395
00396
00397
00398 virtual void getParmNameFromInput(UT_String &parmname,
00399 int inputidx) const;
00400
00401
00402
00403
00404
00405
00406 bool outputDefaultParmDefinition(ostream &os, int idx);
00407
00408 virtual void saveDialogScriptExtraInfo(ostream &os);
00409
00410
00411 bool saveParmValues(ostream &os);
00412
00413 bool loadParmValues(UT_IStream &is);
00414
00415
00416
00417 virtual VOP_Node *getRealDefinition()
00418 { return 0; }
00419
00420 const VOP_Language *getLanguage() const
00421 { return myLanguage; }
00422
00423
00424 virtual fpreal getW() const;
00425
00426 virtual fpreal getH() const;
00427
00428 virtual fpreal getYOffset() const;
00429
00430
00431
00432
00433 virtual void clearInterrupted();
00434
00435
00436
00437
00438
00439
00440
00441 void getDisplayedButtonCount(bool input_flag,
00442 int &count,
00443 bool &ellipsis) const;
00444
00445
00446 static void cacheAllParmNames(OP_Node *root);
00447
00448 static void recalculateAllParmDefiners(OP_Node *root);
00449
00450
00451 virtual bool willAutoconvertInputType(int input_idx);
00452
00453
00454
00455
00456
00457 VOP_Type getAutoConvertTargetType(int input_idx);
00458
00459
00460
00461
00462 VOP_Type getAutoConvertTypeFromType(int input_idx, VOP_Type source_type);
00463
00464
00465 void addAutoConvertNodePointer(VOP_AutoConvert* ac_node, int input_index);
00466 void clearAutoConvertInfos(void);
00467 VOP_AutoConvert* getAutoConvertNode(int input_idx);
00468 int getNumAutoConvertNodes(void);
00469
00470
00471
00472
00473
00474
00475 VOP_OutputInfoManager* getOutputInfoManager(void);
00476
00477
00478
00479 void appendOutputOverrideCode(UT_String& str_code);
00480
00481
00482
00483
00484 bool needToExecute(void);
00485
00486
00487 void onNodeChange(OP_EventType type);
00488
00489 virtual OP_ERROR save(ostream &os, const OP_SaveFlags &flags,
00490 const char *path_prefix = "");
00491 virtual bool load(UT_IStream &is, const char *ext="",
00492 const char *path=0);
00493
00494
00495
00496
00497
00498 virtual bool allowReservingParm(PRM_Parm* parm);
00499
00500
00501 virtual int getDebug() const;
00502
00503 virtual int setDebug(int on_off);
00504
00505 void getSubOutputAndSubInputs(OP_Node *&outputnode,
00506 OP_NodeList &inputnodes) const;
00507
00508 void hideInput(int input_index, bool hide);
00509 void setReferenceTargetDefaults(int input_index, bool do_set);
00510 bool getAllowEditingParmDefaults(int input_index);
00511
00512
00513
00514
00515
00516 VEX_ContextType getVexContextType() const;
00517
00518
00519
00520
00521
00522 RSL_ContextType getRslContextType() const;
00523
00524
00525
00526
00527 bool isSingleContextType() const;
00528
00529
00530
00531
00532
00533
00534 VOP_ContextType getShaderContextType() const;
00535
00536
00537
00538
00539
00540
00541 bool acceptsTypeForCodeGeneration(VOP_ContextType t) const;
00542
00543
00544
00545
00546 virtual bool providesShaderCode();
00547
00548
00549
00550
00551
00552 VOP_Node *verifyProcedural(VOP_Type type);
00553
00554
00555
00556
00557
00558 virtual void getFixedParameterMap(UT_StringArray &parmmap);
00559
00560
00561
00562
00563
00564 virtual void getShaderInputMap(UT_StringArray &inputmap);
00565
00566
00567 virtual const PRM_Template *getShaderParmTemplates();
00568
00569
00570
00571
00572 bool deleteIndependentInputNodes(int input_index);
00573
00574 void getInputsRecursive(OP_NodeList& nodes_out);
00575 bool doesDependOnlyOn(VOP_Node* other_node, int max_connections, bool recurse);
00576
00577
00578
00579
00580
00581 void getParmInputs(VOP_ParmGeneratorList &parm_vops);
00582
00583
00584
00585 VOP_Node *findSimpleInput(int index);
00586
00587
00588
00589 virtual VOP_Node *findSimpleInputFromOutput(int output_index)
00590 { return this; }
00591
00592
00593
00594 virtual void findSimpleInputCandidatesFromOutput(int output_index,
00595 UT_IntArray & input_indices )
00596 { input_indices.clear(); }
00597
00598
00599
00600 bool isExternalShader();
00601
00602
00603
00604
00605
00606 virtual bool runCreateScript();
00607
00608 void updateInputFlagsFromOperator(VOP_OperatorInfo *type_info,
00609 bool keep_visible);
00610
00611 virtual void onCreated(void);
00612
00613 void hideNamedInput(const OP_ConnectorId& connector_name, bool hide);
00614
00615
00616
00617 virtual void getAllowedNamedInputTypes(const OP_ConnectorId& input_name,
00618 VOP_VopTypeArray &voptypes);
00619
00620 VOP_Type getNamedAutoConvertTargetType(const OP_ConnectorId& input_name);
00621 VOP_Type getNamedAutoConvertTypeFromType(const OP_ConnectorId& input_name, VOP_Type source_type);
00622 virtual bool willAutoconvertNamedInputType(const OP_ConnectorId& input_name);
00623 VOP_Node *insertNamedNode(const OP_ConnectorId& input_name, const char* nodetype, bool connect_to_input, const char* undo_string = NULL);
00624
00625 void setDisableAutoInputDelete(bool value)
00626 { myDisableInputAutodelete = value; }
00627
00628 protected:
00629 VOP_Node(OP_Network *parent, const char *name, OP_Operator *entry);
00630 virtual ~VOP_Node();
00631
00632 virtual void getNodeSpecificInfoText(OP_Context &context,
00633 OP_NodeInfoParms &iparms);
00634
00635 virtual void deleteCookedData();
00636 virtual int saveCookedData(ostream &, OP_Context &,
00637 int binary = 0);
00638 virtual int saveCookedData(const char *, OP_Context &);
00639 virtual const char *getFileExtension(int) const;
00640
00641 virtual OP_ERROR cookMe(OP_Context &);
00642 virtual OP_ERROR bypassMe(OP_Context &, int &);
00643
00644 virtual void preOpChanged(OP_EventType, void *)
00645 { }
00646 virtual void postOpChanged(OP_EventType, void *)
00647 { }
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664 virtual VOP_ContextType getSpecificShaderContextType() const;
00665
00666
00667
00668 virtual void getTypesForCodeGeneration(
00669 VOP_ContextTypeList & types ) const;
00670
00671
00672
00673
00674 virtual void getOutputNameSubclass(UT_String &out, int idx) const;
00675 virtual void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info,
00676 int idx);
00677
00678 virtual VOP_Type getOutputTypeSubclass(int idx);
00679
00680
00681
00682
00683 virtual void getInputNameSubclass(UT_String &in, int idx) const;
00684 virtual int getInputFromNameSubclass(const UT_String &in) const;
00685 virtual void getInputTypeInfoSubclass(VOP_TypeInfo &type_info,
00686 int idx);
00687
00688 virtual VOP_Type getInputTypeSubclass(int idx);
00689 virtual bool getIsVisibleSubclass(int idx);
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703 bool getInputTypeInfoFromInputNode(
00704 VOP_TypeInfo &type_info, int idx,
00705 bool grow_inputs_to_idx = false);
00706
00707
00708
00709
00710
00711
00712 virtual void getAllowedInputTypesSubclass(unsigned idx,
00713 VOP_VopTypeArray &voptypes);
00714
00715
00716
00717
00718 virtual bool getRequiresInputParameters() const;
00719
00720 void addError(VOP_ErrorCodes code, const char *msg=0)
00721 { UTaddError("VOP", code, msg); }
00722 void addMessage(VOP_ErrorCodes code, const char *msg=0)
00723 { UTaddMessage("VOP", code, msg); }
00724 void addWarning(VOP_ErrorCodes code, const char *msg=0)
00725 { UTaddWarning("VOP", code, msg); }
00726 void addFatal(VOP_ErrorCodes code, const char *msg=0)
00727 { UTaddFatal("VOP", code, msg); }
00728
00729
00730 static void rewireInputs(OP_Network *parent, OP_NodeList &inputs,
00731 int srcidx, int dstidx);
00732
00733 const VOP_Language *myLanguage;
00734
00735 virtual void getAdditionalUndoNodes(const OP_NodeList& orig_list, OP_NodeList& nodes_for_input_undo);
00736
00737
00738 virtual OP_ERROR saveIntrinsic(ostream &os, const OP_SaveFlags &flags);
00739 virtual bool loadPacket(UT_IStream &is, short class_id,
00740 short sig, const char *path = 0);
00741 virtual bool loadPacket(UT_IStream &is,
00742 const char *token, const char *path = 0);
00743
00744
00745
00746 virtual int getLatestVopVersion() const { return 0; }
00747
00748 void getInputsRecursiveHelper(OP_NodeList& nodes_out, UT_RefArray<int> &array);
00749
00750 bool doesDependOnlyOnHelper(VOP_Node* other_node, int max_connections,
00751 bool recurse, UT_RefArray<int> &array);
00752
00753 virtual void onInputAllocated(OP_Input* new_input, int index);
00754
00755 virtual void finishedLoadingNetwork(bool is_child_call=false);
00756
00757 int myVopVersion;
00758
00759 private:
00760
00761 bool getIncludeIllumVars() const;
00762
00763
00764
00765
00766
00767 void propagateOpChangeToCodeGenerator(
00768 OP_EventType reason) const;
00769
00770
00771 void reportRecursiveLoopError();
00772
00773 const UT_SymbolTable*myGlobalVariables;
00774 UT_SymbolTable *myLocalVariables;
00775 UT_SymbolTable *myLocalChannels;
00776 long myLatestOpChangedId;
00777 bool myMakingInputList;
00778 bool myIsSearchingForParmInputs;
00779 bool myDisableInputAutodelete;
00780 mutable UT_BitArray myGettingInputName;
00781 mutable UT_BitArray myGettingInputTypeInfo;
00782 mutable UT_BitArray myGettingIsVisible;
00783 mutable UT_BitArray myGettingAllowedInputTypes;
00784 mutable UT_BitArray myGettingOutputName;
00785 mutable UT_BitArray myGettingOutputTypeInfo;
00786 mutable int myOutputNodeId;
00787
00788 static VOP_Node *theOriginalOpChanged;
00789 static long theLatestOpChangedId;
00790 static int theLODPref;
00791
00792 TAutoConvertInfos myAutoConvertInfos;
00793 VOP_OutputInfoManager myOutputInfos;
00794
00795 UT_SymbolTable myCachedOutputNames;
00796 UT_PtrArray< VOP_TypeInfo* > myCachedOutputTypeInfos;
00797 };
00798
00799 #endif