00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CH_Collection_h__
00021 #define __CH_Collection_h__
00022
00023 #include "CH_API.h"
00024 #include "CH_EventManager.h"
00025 #include "CH_Manager.h"
00026 #include "CH_ExprLanguage.h"
00027 #include <iostream.h>
00028 #include <SYS/SYS_Types.h>
00029 #include <UT/UT_String.h>
00030 #include <UT/UT_PtrArray.h>
00031 #include <UT/UT_SymbolTable.h>
00032 #include <UT/UT_Packet.h>
00033 #include <UT/UT_ThreadSpecificValue.h>
00034 #include <EXPR/EX_Error.h>
00035
00036 class CH_Channel;
00037 class CH_Collection;
00038 class CH_LocalVariable;
00039
00040 class UT_XformOrder;
00041
00042 typedef enum {
00043 CH_OS,
00044 CH_CH,
00045 CH_LT,
00046 CH_IT,
00047 CH_OT,
00048 CH_LIT,
00049 CH_LOT,
00050 CH_PREV_IT,
00051 CH_NEXT_OT,
00052 CH__SEGP,
00053 CH__PSEGP,
00054 CH__NSEGP,
00055 CH_IV,
00056 CH_OV,
00057 CH_IM,
00058 CH_OM,
00059 CH_IA,
00060 CH_OA
00061 } CH_LOCAL_VARIABLE;
00062
00063 enum {
00064 CH_LOCAL_VARIABLE_TABLE_INDEX = 1
00065 };
00066
00067
00068
00069 class OP_Channels;
00070
00071 class CH_API CH_CollectionIterator
00072 {
00073
00074
00075
00076 public:
00077 CH_CollectionIterator(UT_IStream &is, int binary);
00078 bool begin(UT_String &path);
00079 bool end();
00080 bool nextCollection(UT_String &path);
00081
00082 private:
00083 UT_IStream *curr_is;
00084 int is_binary;
00085 };
00086
00087 class CH_API CH_Collection : public UT_SymbolTable
00088 {
00089 public:
00090 CH_Collection(CH_Manager *manager);
00091 CH_Collection(CH_Manager *manager, const CH_Collection &from);
00092 virtual ~CH_Collection();
00093
00094 SETUPCLASSPACKETID("CH_Collection");
00095
00096 CH_Manager *getManager() const { return myManager; }
00097 float getTolerance() const { return myManager->getTolerance(); }
00098
00099 virtual int canAccess(uint mask) const;
00100 virtual int canAccessChannel(uint mask, const CH_Channel *chp) const;
00101
00102
00103
00104
00105
00106 const CH_Channel *getChannel(const char *name) const;
00107 CH_Channel *getChannel(const char *name);
00108 const CH_Channel *getChannel(int idx) const { return myChannels(idx); }
00109 CH_Channel *getChannel(int idx) { return myChannels(idx); }
00110 const CH_Channel *getChannel(const UT_String &name) const
00111 {
00112 return getChannel((const char *)name);
00113 }
00114 CH_Channel *getChannel(const UT_String &name)
00115 {
00116 return getChannel((const char *)name);
00117 }
00118
00119 int getChannels(CH_ChannelList &chans,
00120 int scope=0) const;
00121
00122 int getChannels(CH_ChannelList &chans,
00123 const char *pattern) const;
00124
00125 int getChannelNames(CH_NameList &list, int scope=0) const;
00126 int getChannelCount(int scoped = 0) const;
00127
00128
00129
00130
00131 virtual CH_Collection *findCollection(const char *path) const = 0;
00132 CH_Channel *findChannel (const char *path) const;
00133 CH_Channel *findOrCreateChannel (const char *path);
00134
00135
00136
00137
00138
00139 CH_Channel *addChannel(const char *name);
00140 CH_Channel *addChannel(CH_Channel *chp);
00141
00142 CH_Channel *dupChannel(const char *name);
00143 virtual CH_Channel *dupChannel(const CH_Channel &from);
00144
00145
00146
00147
00148 virtual int rename(const char *from_name, const char *to_name,
00149 const char *to_alias);
00150 virtual int rename(CH_Channel *from, const char *to_name,
00151 const char *to_alias);
00152
00153 void deleteChannel(const char *name);
00154 void deleteChannel(CH_Channel *chp);
00155 int deleteChannels();
00156
00157
00158
00159
00160 float evaluate(CH_Channel *chp, float time,
00161 bool no_disabling , int thread);
00162 void evaluate(CH_Channel *chp, float from, float to,
00163 float *vals, int nsamples,
00164 bool no_disabling ,
00165 bool use_cache , int thread);
00166 void evaluateString(UT_String &result,
00167 CH_Channel *chp, float time,
00168 int thread);
00169
00170
00171
00172
00173
00174 void unresolveLocalVars(int thread);
00175
00176
00177
00178
00179 virtual void getFullPath(UT_String &path) const = 0;
00180 void getFullPath(const CH_Channel *chp, UT_String &p,
00181 bool use_alias=false) const;
00182
00183
00184
00185
00186
00187
00188 void channelFind(const char *path, CHfindCallBack callback,
00189 void *data = 0) const;
00190
00191
00192
00193 void findString(const char *word, bool fullword,
00194 bool usewildcards, CHfindCallBack callback,
00195 void *data = 0);
00196 int findString(const char *word, bool fullword,
00197 bool usewildcards) const;
00198 int changeString(const char *from, const char *to,
00199 bool fullword, int thread);
00200
00201
00202
00203
00204
00205 virtual const UT_String &getName() const = 0;
00206
00207 virtual int getUniqueId() const;
00208 virtual CH_Collection * lookupCollection(int id) const;
00209
00210 virtual const CH_Collection *getParent() const = 0;
00211 virtual CH_Collection *getParent() = 0;
00212
00213 virtual const CH_Collection *getChild(const char *name) const = 0;
00214 virtual CH_Collection *getChild(const char *name) = 0;
00215
00216
00217
00218 virtual int getChildren(CH_NameList &names) const =0;
00219 virtual int getChildren(CH_CollectionList &grps) const =0;
00220
00221
00222 virtual void getVariableValue(int table, int index, UT_String &str,
00223 int thread);
00224 virtual float getVariableValue(int table, int index, int thread);
00225 virtual void *getVariableData(int table, int index, int thread);
00226
00227 virtual const CH_LocalVariable *resolveVariable(const char *name, int &tab);
00228
00229
00230
00231
00232 int save(ostream &os, int binary, bool compiled, int scope,
00233 const CH_ChannelList *channels = NULL) const;
00234 int saveToFile(const char *nm) const;
00235
00236 bool load(UT_IStream &is, const char *path = 0,
00237 const CH_LoadInfo *load_info = 0,
00238 CH_ChannelList *loadedChannels = 0,
00239 bool delete_keys = false);
00240 int loadFromFile(const char *nm);
00241
00242
00243
00244
00245 float findKey(float gtime, int dir) const;
00246 virtual void saveKeyFrameForUndo(CH_Channel *chp, float gtime) = 0;
00247
00248
00249
00250
00251 int getChanged() const { return myModifiedFlag; }
00252 virtual void setChanged(CH_CHANGE_TYPE how, void *data=0);
00253
00254 void setExpose( bool onoff );
00255 bool getExpose() const { return myExpose; }
00256
00257
00258
00259
00260 void clearAndDestroy();
00261
00262
00263
00264
00265 float getGlueIV(int thread) const;
00266 void getGlueTime(float &t, float &t0, float &t1,
00267 float &v0, float &v1, int thread) const;
00268 void getGlueSlope(float *m0, float *m1,
00269 float *a0, float *a1, int thread) const;
00270
00271 void setEvalChannel(CH_Channel *chp, int thraed,
00272 const char *name = NULL);
00273 void setEvalChannel(CH_Channel *chp, const char *name,
00274 CH_Channel *&old_chp,
00275 const char *&old_name,
00276 int thread);
00277 const CH_Channel *getEvalChannel(int thread) const
00278 { return myThreadSpecificData.getValueForThread(thread).myEvalChannel; }
00279 CH_Channel *getEvalChannel(int thread)
00280 { return myThreadSpecificData.getValueForThread(thread).myEvalChannel; }
00281 const char *getEvalChannelName(int thread) const
00282 { return
00283 myThreadSpecificData.getValueForThread(thread).myEvalChannelName; }
00284 void getEvalChannelAndName(CH_Channel *&chp,
00285 const char *&name,
00286 int thread) const
00287 {myThreadSpecificData.getValueForThread(thread).getEvalChannel(chp,name);}
00288
00289 void initManager(CH_Manager *manager);
00290
00291 float getGlobalStart() const
00292 { return myManager->getGlobalStart(); }
00293 float getGlobalEnd() const
00294 { return myManager->getGlobalEnd(); }
00295
00296
00297
00298
00299
00300
00301 bool getCollectionRange(float &start, float &end,
00302 bool &timedep, int thread);
00303
00304 void addDynamicVariables(CH_LocalVariable *table)
00305 { myVariables[3] = table; }
00306
00307
00308
00309
00310
00311
00312 void addedParamDependency();
00313 void removeParamDependency();
00314
00315
00316
00317
00318 virtual void getXformOrder(UT_XformOrder &xord, CH_Channel *chp);
00319
00320 bool getExternal() const
00321 { return myExternal; }
00322 void setExternal(bool yesno)
00323 { myExternal = yesno; }
00324
00325
00326
00327 bool setChannelAlias(CH_Channel &chp, const char *alias);
00328
00329
00330 static bool isValidChannelName(const char *s);
00331
00332
00333
00334 virtual OP_Channels *castToOPChannels() { return 0; }
00335 virtual const OP_Channels *castToOPChannels() const { return 0; }
00336
00337
00338 virtual void addLocalVarDependency(int table, int index,
00339 void *ref_id);
00340
00341 CH_ExprLanguage getExprLanguage() const;
00342 void setExprLanguage(CH_ExprLanguage language);
00343
00344 protected:
00345 class CH_API ch_ThreadSpecificData
00346 {
00347 public:
00348 ch_ThreadSpecificData() : myEvalChannel(0), myEvalChannelName(0) {}
00349
00350 void setEvalChannel(CH_Channel *chp, const char *name = NULL);
00351 void setEvalChannel(CH_Channel *chp, const char *name,
00352 CH_Channel *&old_chp, const char *&old_name)
00353 {
00354 getEvalChannel(old_chp, old_name);
00355 setEvalChannel(chp, name);
00356 }
00357 void getEvalChannel(CH_Channel *&chp, const char *&name) const
00358 {
00359 chp = myEvalChannel;
00360 name = myEvalChannelName;
00361 }
00362
00363 CH_Channel *myEvalChannel;
00364 const char *myEvalChannelName;
00365 };
00366
00367
00368
00369
00370 SYS_FORCE_INLINE void
00371 checkEvaluationError(const CH_Channel *chp, int thread) const
00372 {
00373 int err = ev_GetErrNo(thread);
00374 if (err != EV_NOERROR)
00375 evaluationError(chp, err, thread);
00376 }
00377
00378 virtual void addErrorToErrorManager(const char *type, int code,
00379 const char *msg=0) const;
00380
00381 void addLocalVariables(CH_LocalVariable *table)
00382 { myVariables[2] = table; }
00383 const CH_Collection *getRoot() const;
00384
00385
00386
00387 const CH_ChannelList *getChannels() const { return &myChannels; }
00388
00389 virtual void notifyChannelRenameDependents(const char *old_name,
00390 const char *new_name);
00391
00392
00393 CH_Manager *myManager;
00394 CH_LocalVariable *myVariables[4];
00395 CH_ChannelList myChannels;
00396 UT_ThreadSpecificValue<ch_ThreadSpecificData> myThreadSpecificData;
00397 UT_SymbolTable *myChannelAliasesTable;
00398
00399 int myModifiedFlag;
00400
00401 CH_ExprLanguage myExprLanguage;
00402
00403 char myParamDependent;
00404
00405 bool myExternal;
00406 bool myExpose;
00407
00408 private:
00409
00410
00411 void evaluationError(const CH_Channel *chp, int err,
00412 int thread) const;
00413
00414 void deleteChannel(unsigned index);
00415 CH_Channel * loadChannelRange(UT_IStream &is, const char *name,
00416 const CH_LoadInfo &load_info);
00417
00418 friend class CH_Manager;
00419 };
00420
00421 CH_API extern void
00422 CHcollectionsToOPchannels( CH_CollectionList const& collections,
00423 UT_PtrArray< OP_Channels* > &op_channels );
00424
00425 #endif