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 template <typename FPREAL_TYPE>
00241 bool load(UT_IStream &is, const char *path = 0,
00242 const CH_LoadInfo *load_info = 0,
00243 CH_ChannelList *loadedChannels = 0,
00244 bool delete_keys = false);
00245 int loadFromFile(const char *nm);
00246
00247
00248
00249
00250 float findKey(float gtime, int dir) const;
00251 virtual void saveKeyFrameForUndo(CH_Channel *chp, float gtime) = 0;
00252
00253
00254
00255
00256 int getChanged() const { return myModifiedFlag; }
00257 virtual void setChanged(CH_CHANGE_TYPE how, void *data=0);
00258
00259 void setExpose( bool onoff );
00260 bool getExpose() const { return myExpose; }
00261
00262
00263
00264
00265 void clearAndDestroy();
00266
00267
00268
00269
00270 float getGlueIV(int thread) const;
00271 void getGlueTime(float &t, float &t0, float &t1,
00272 float &v0, float &v1, int thread) const;
00273 void getGlueSlope(float *m0, float *m1,
00274 float *a0, float *a1, int thread) const;
00275
00276 void setEvalChannel(CH_Channel *chp, int thraed,
00277 const char *name = NULL);
00278 void setEvalChannel(CH_Channel *chp, const char *name,
00279 CH_Channel *&old_chp,
00280 const char *&old_name,
00281 int thread);
00282 const CH_Channel *getEvalChannel(int thread) const
00283 { return myThreadSpecificData.getValueForThread(thread).myEvalChannel; }
00284 CH_Channel *getEvalChannel(int thread)
00285 { return myThreadSpecificData.getValueForThread(thread).myEvalChannel; }
00286 const char *getEvalChannelName(int thread) const
00287 { return
00288 myThreadSpecificData.getValueForThread(thread).myEvalChannelName; }
00289 void getEvalChannelAndName(CH_Channel *&chp,
00290 const char *&name,
00291 int thread) const
00292 {myThreadSpecificData.getValueForThread(thread).getEvalChannel(chp,name);}
00293
00294 void initManager(CH_Manager *manager);
00295
00296 float getGlobalStart() const
00297 { return myManager->getGlobalStart(); }
00298 float getGlobalEnd() const
00299 { return myManager->getGlobalEnd(); }
00300
00301
00302
00303
00304
00305
00306 bool getCollectionRange(float &start, float &end,
00307 bool &timedep, int thread);
00308
00309 void addDynamicVariables(CH_LocalVariable *table)
00310 { myVariables[3] = table; }
00311
00312
00313
00314
00315
00316
00317 void addedParamDependency();
00318 void removeParamDependency();
00319
00320
00321
00322
00323 virtual void getXformOrder(UT_XformOrder &xord, CH_Channel *chp);
00324
00325 bool getExternal() const
00326 { return myExternal; }
00327 void setExternal(bool yesno)
00328 { myExternal = yesno; }
00329
00330
00331
00332 bool setChannelAlias(CH_Channel &chp, const char *alias);
00333
00334
00335 static bool isValidChannelName(const char *s);
00336
00337
00338
00339 virtual OP_Channels *castToOPChannels() { return 0; }
00340 virtual const OP_Channels *castToOPChannels() const { return 0; }
00341
00342
00343 virtual void addLocalVarDependency(int table, int index,
00344 void *ref_id);
00345
00346 CH_ExprLanguage getExprLanguage() const;
00347 void setExprLanguage(CH_ExprLanguage language);
00348
00349 protected:
00350 class CH_API ch_ThreadSpecificData
00351 {
00352 public:
00353 ch_ThreadSpecificData() : myEvalChannel(0), myEvalChannelName(0) {}
00354
00355 void setEvalChannel(CH_Channel *chp, const char *name = NULL);
00356 void setEvalChannel(CH_Channel *chp, const char *name,
00357 CH_Channel *&old_chp, const char *&old_name)
00358 {
00359 getEvalChannel(old_chp, old_name);
00360 setEvalChannel(chp, name);
00361 }
00362 void getEvalChannel(CH_Channel *&chp, const char *&name) const
00363 {
00364 chp = myEvalChannel;
00365 name = myEvalChannelName;
00366 }
00367
00368 CH_Channel *myEvalChannel;
00369 const char *myEvalChannelName;
00370 };
00371
00372
00373
00374
00375 SYS_FORCE_INLINE void
00376 checkEvaluationError(const CH_Channel *chp, int thread) const
00377 {
00378 int err = ev_GetErrNo(thread);
00379 if (err != EV_NOERROR)
00380 evaluationError(chp, err, thread);
00381 }
00382
00383 virtual void addErrorToErrorManager(const char *type, int code,
00384 const char *msg=0) const;
00385
00386 void addLocalVariables(CH_LocalVariable *table)
00387 { myVariables[2] = table; }
00388 const CH_Collection *getRoot() const;
00389
00390
00391
00392 const CH_ChannelList *getChannels() const { return &myChannels; }
00393
00394 virtual void notifyChannelRenameDependents(const char *old_name,
00395 const char *new_name);
00396
00397
00398 CH_Manager *myManager;
00399 CH_LocalVariable *myVariables[4];
00400 CH_ChannelList myChannels;
00401 UT_ThreadSpecificValue<ch_ThreadSpecificData> myThreadSpecificData;
00402 UT_SymbolTable *myChannelAliasesTable;
00403
00404 int myModifiedFlag;
00405
00406 CH_ExprLanguage myExprLanguage;
00407
00408 char myParamDependent;
00409
00410 bool myExternal;
00411 bool myExpose;
00412
00413 private:
00414
00415
00416 void evaluationError(const CH_Channel *chp, int err,
00417 int thread) const;
00418
00419 void deleteChannel(unsigned index);
00420
00421 template <typename FPREAL_TYPE>
00422 CH_Channel * loadChannelRange(UT_IStream &is, const char *name,
00423 const CH_LoadInfo &load_info);
00424
00425 friend class CH_Manager;
00426 };
00427
00428 CH_API extern void
00429 CHcollectionsToOPchannels( CH_CollectionList const& collections,
00430 UT_PtrArray< OP_Channels* > &op_channels );
00431
00432 #endif