iparamb.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: iparamb.h
00004 
00005     DESCRIPTION: Interface to Parameter blocks
00006 
00007     CREATED BY: Rolf Berteig
00008 
00009     HISTORY: created 1/25/95
00010 
00011  *> Copyright (c) 1994, All Rights Reserved.
00012  **********************************************************************/
00013 
00014 #pragma once
00015 
00016 #include "maxheap.h"
00017 #include "ref.h"
00018 #include "ioapi.h"
00019 // forward declaration
00020 class Control;
00021 class Point3;
00022 class Color;
00023 
00024 class UserType : public ReferenceTarget {
00025     public:     
00026         virtual ~UserType() {};
00027         virtual Control* CreateController()=0;
00028         virtual BOOL operator==( const UserType& t )=0;
00029         virtual UserType& operator=( const UserType& t )=0;     
00030     };
00031 
00032 
00033 // Built in data types
00034 #include "paramtype.h"
00035 
00036 // Chunk IDs for loading/saving
00037 #define PB_COUNT_CHUNK          0x0001
00038 #define PB_PARAM_CHUNK          0x0002
00039 #define PB_INDEX_CHUNK          0x0003
00040 #define PB_ANIMATABLE_CHUNK     0x0004
00041 #define PB_VERSION_CHUNK        0x0005
00042 #define PB_LOCKED_CHUNK         0x0006
00043 #define PB_FLOAT_CHUNK          (TYPE_FLOAT + 0x100)
00044 #define PB_INT_CHUNK            (TYPE_INT + 0x100)
00045 #define PB_RGBA_CHUNK           (TYPE_RGBA + 0x100)
00046 #define PB_POINT3_CHUNK         (TYPE_POINT3 + 0x100)
00047 #define PB_BOOL_CHUNK           (TYPE_BOOL + 0x100)
00048 
00049 #define PB_TYPE_CHUNK           0x0200
00050 #define PB_TYPE_FLOAT_CHUNK     (PB_TYPE_CHUNK + TYPE_FLOAT)
00051 #define PB_TYPE_INT_CHUNK       (PB_TYPE_CHUNK + TYPE_INT)
00052 #define PB_TYPE_RGBA_CHUNK      (PB_TYPE_CHUNK + TYPE_RGBA)
00053 #define PB_TYPE_POINT3_CHUNK    (PB_TYPE_CHUNK + TYPE_POINT3)
00054 #define PB_TYPE_BOOL_CHUNK      (PB_TYPE_CHUNK + TYPE_BOOL)
00055 #define PB_TYPE_USER_CHUNK      (PB_TYPE_CHUNK + TYPE_USER)
00056 
00057 
00058 // When a client of a param block receives the \ref REFMSG_GET_PARAM_NAME
00059 // message, the partID field is set to point at one of these structures.
00060 // The client should fill in the parameter name.
00071 class GetParamName: public MaxHeapOperators {
00072     public:
00073         MSTR name;
00074         int index;
00076         GetParamName(MSTR n,int i) { name=n;index=i; }
00077     };
00078 
00079 // When a client of a param block receives the \ref REFMSG_GET_PARAM_DIM
00080 // message, the partID field is set to point at one of these structs.
00081 // The client should set dim to point at it's dim descriptor.
00093 class GetParamDim: public MaxHeapOperators {
00094     public:
00095         ParamDimension *dim;
00096         int index;
00098         GetParamDim(int i) {index=i;dim=NULL;}
00099     };
00100 
00101 
00102 // To create a parameter block, pass an array of these descriptors
00103 // into the Create function. 
00104 // Items in the parameter block can be refered to by index. The 
00105 // index is derived from the order in which the descriptors appear
00106 // in the array. If a parameter is a UserType, then a pointer to a 
00107 // new UserType must be passed in. The parameter block will be responsible
00108 // for deleting it when it is done with it.
00109 
00128 class ParamBlockDesc {
00129     public:
00130         ParamType type;
00131         UserType *user; 
00132         BOOL animatable;
00133     };
00134 
00135 // This version of the descriptor has an ID for each parameter.
00165 class ParamBlockDescID {
00166     public:
00167         ParamType type;
00168         UserType *user; 
00169         BOOL animatable;
00170         DWORD id;
00171     };
00172 
00173 class IParamBlock;
00174 
00175 // This class represents a virtual array of parameters.
00176 // Parameter blocks are one such implementation of this class, but
00177 // it can also be useful to implement a class that abstracts non-
00178 // parameter block variables. 
00179 //
00180 // The ParamMap class (see IParamM.h) uses this base class so that
00181 // a ParamMap can be used to control UI for not only parameter blocks
00182 // but variables stored outside of parameter blocks.
00195 #pragma warning(push)
00196 #pragma warning(disable:4100)
00197 class IParamArray : public MaxHeapOperators {
00198     public:
00211         virtual BOOL SetValue( int i, TimeValue t, float v ) {return FALSE;}
00213         virtual BOOL SetValue( int i, TimeValue t, int v ) {return FALSE;}
00215         virtual BOOL SetValue( int i, TimeValue t, Point3& v ) {return FALSE;}
00216         
00232         virtual BOOL GetValue( int i, TimeValue t, float &v, Interval &ivalid ) {return FALSE;}
00234         virtual BOOL GetValue( int i, TimeValue t, int &v, Interval &ivalid ) {return FALSE;}
00236         virtual BOOL GetValue( int i, TimeValue t, Point3 &v, Interval &ivalid ) {return FALSE;}
00237     
00238         // If it is a param block, this will get a pointer to it, otherwise it will return NULL.
00239         // Note that casting won't work because of multiple iheritance.
00245         virtual IParamBlock *GetParamBlock() {return NULL;}
00246 
00247         // Checks to see if a keyframe exists for the given parameter at the given time
00260         virtual BOOL KeyFrameAtTime(int i, TimeValue t) {return FALSE;}
00261     };
00262 #pragma warning(pop)
00263 
00270 class IParamBlock :             
00271             public ReferenceTarget,
00272             public IParamArray {
00273     public:
00274         // Get's the super class of a parameters controller
00279         virtual SClass_ID GetAnimParamControlType(int anim)=0;
00280 
00281         // Get the param type
00287         virtual ParamType GetParameterType(int i)=0;
00288 
00289         // one for each known type
00305         virtual BOOL SetValue( int i, TimeValue t, float v )=0;
00307         virtual BOOL SetValue( int i, TimeValue t, int v )=0;       
00309         virtual BOOL SetValue( int i, TimeValue t, Point3& v )=0;       
00311         virtual BOOL SetValue( int i, TimeValue t, Color& v )=0; // uses Point3 controller
00312         
00313         // one for each known type
00366         virtual BOOL GetValue( int i, TimeValue t, float &v, Interval &ivalid )=0;
00368         virtual BOOL GetValue( int i, TimeValue t, int &v, Interval &ivalid )=0;
00370         virtual BOOL GetValue( int i, TimeValue t, Point3 &v, Interval &ivalid )=0;
00372         virtual BOOL GetValue( int i, TimeValue t, Color &v, Interval &ivalid )=0; // uses Point3 Controller
00373 
00374         virtual Color  GetColor(int i, TimeValue t=0)=0;
00375         virtual Point3 GetPoint3(int i, TimeValue t=0)=0;
00376         virtual int    GetInt(int i, TimeValue t=0)=0;
00377         virtual float  GetFloat(int i, TimeValue t=0)=0;
00378 
00381         virtual DWORD GetVersion()=0;
00382         virtual int NumParams()=0;
00383 
00389         virtual void RemoveController(int i)=0;
00395         virtual Control* GetController(int i)=0;
00405         virtual void SetController(int i, Control *c, BOOL preserveFrame0Value=TRUE)=0;
00411         virtual void SwapControllers(int j, int k )=0;
00412 
00413         // Given the parameter index, what is the refNum?
00420         virtual int GetRefNum(int paramNum)=0;
00421 
00422         // Given the parameter index what is the animNum?
00428         virtual int GetAnimNum(int paramNum)=0;
00429 
00430         // Given the animNum what is the parameter index?
00436         virtual int AnimNumToParamNum(int animNum)=0;
00437 
00438         // Inherited from IParamArray
00439         IParamBlock *GetParamBlock() {return this;}
00440                 
00441         // This is only for use in a RescaleWorldUnits() implementation:
00442         // The param block implementation of RescaleWorldUnits scales only tracks
00443         // that have dimension type = stdWorldDim. If letting the param block handle 
00444         // the rescaling is not sufficient, call this on just the parameters you need to rescale.
00457         virtual void RescaleParam(int paramNum, float f)=0;
00458 
00459         // When a NotifyRefChanged is received from a param block, you 
00460         // can call this method to find out which parameter generated the notify.
00481         virtual int LastNotifyParamNum()=0;
00482         };
00483 
00484 
00494 CoreExport IParamBlock *CreateParameterBlock(ParamBlockDesc *pdesc, int count);
00495 
00496 // Note: version must fit into 16 bits. (5/20/97)
00515 CoreExport IParamBlock *CreateParameterBlock(ParamBlockDescID *pdesc, int count, DWORD version);
00516 
00517 // This creates a new parameter block, based on an existing parameter block of
00518 // a later version. The new parameter block inherits any parameters from
00519 // the old parameter block whose parameter IDs match.
00538 CoreExport IParamBlock *UpdateParameterBlock(
00539     ParamBlockDescID *pdescOld, int oldCount, IParamBlock *oldPB,
00540     ParamBlockDescID *pdescNew, int newCount, DWORD newVersion);
00541 
00542 
00543 // ----------------------------------------------------------
00544 // A handy post load call back for fixing up parameter blocks.
00545 
00546 // This structure describes a version of the parameter block.
00557 class ParamVersionDesc: public MaxHeapOperators {
00558     public:
00559         ParamBlockDescID *desc;
00560         int count;
00561         DWORD version;
00570         ParamVersionDesc(ParamBlockDescID *d,int c,int v) {desc=d;count=c;version=v;}
00571     };
00572 
00573 // This will look up the version of the loaded callback and 
00574 // fix it up so it matches the current version.
00575 // NOTE: this thing deletes itself when it's done.
00583 class ParamBlockPLCB : public PostLoadCallback {
00584     public:
00585         ParamVersionDesc *versions;
00586         int count;
00587         ParamVersionDesc *cur;      
00588         ReferenceTarget *targ;
00589         int pbRefNum;
00590 
00607         ParamBlockPLCB(
00608             ParamVersionDesc *v,int cnt,ParamVersionDesc *c,
00609             ReferenceTarget *t,int refNum)
00610             {versions=v;count=cnt;cur=c;targ=t;pbRefNum=refNum;}
00611         CoreExport void proc(ILoad *iload);
00612         int Priority() { return 0; }
00613         CoreExport INT_PTR Execute(int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0);
00614     };
00615 
00616 
00617 
00618