00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __OP_OTLManager__
00020 #define __OP_OTLManager__
00021
00022 #include "OP_API.h"
00023 #include <UT/UT_IntArray.h>
00024 #include <UT/UT_StringArray.h>
00025 #include <UT/UT_SymbolTable.h>
00026 #include "OP_OTLLibrary.h"
00027 #include "OP_Operator.h"
00028
00029 class UT_WorkBuffer;
00030 class FS_IndexFile;
00031 class OP_Node;
00032 class OP_OperatorTable;
00033 class OP_OTLManagerSink;
00034
00035 #define OP_TYPEBARMODE_FULLMENU "fullmenu"
00036 #define OP_TYPEBARMODE_DISPLAYONLY "displayonly"
00037 #define OP_TYPEBARMODE_NONE "none"
00038
00039 class OP_API OP_OTLManager
00040 {
00041 public:
00042 OP_OTLManager();
00043 virtual ~OP_OTLManager();
00044
00045
00046 bool getSaveToHipFile() const;
00047 void setSaveToHipFile(bool savetohip);
00048 bool getSaveUnlockedToHipFile() const;
00049 void setSaveUnlockedToHipFile(bool saveunlockedtohip);
00050 bool getWarnOutOfDateOps() const;
00051 void setWarnOutOfDateOps(bool warn);
00052 bool getWarnDummyOpsOnLoad() const;
00053 void setWarnDummyOpsOnLoad(bool warn);
00054 bool getPreferLatestDate() const;
00055 void setPreferLatestDate(bool preferlatest);
00056 bool getPreferInternal() const;
00057 void setPreferInternal(bool preferinternal);
00058 bool getPreferIndexFile() const;
00059 void setPreferIndexFile(bool preferindexfile);
00060 bool getCreateBackups() const;
00061 void setCreateBackups(bool createbackups);
00062 bool getSafeguardOpDefs() const;
00063 void setSafeguardOpDefs(bool safeguardopdefs);
00064 bool getLeaveDefaultsUnchanged() const;
00065 void setLeaveDefaultsUnchanged(bool leavedefaultsunchanged);
00066 bool getUseOplibrariesFiles() const;
00067 void setUseOplibrariesFiles(bool useoplibrariesfiles);
00068 const UT_String &getOperatorTypeBarMode() const;
00069 void setOperatorTypeBarMode(const char *mode);
00070 const UT_StringArray&getAllowedOperatorTypeBarModes() const;
00071
00072
00073
00074
00075 bool loadOpLibrariesFile(UT_IStream &is,
00076 const char *metasrc, int &libpos);
00077
00078
00079
00080 bool saveInternalMetaFile(ostream &os,
00081 const char *prefix = 0) const;
00082
00083
00084
00085
00086
00087
00088
00089 void setLibraryPreference(const char *tablename,
00090 const char *opname,
00091 const char *libfile);
00092
00093
00094
00095
00096 void setLibraryPreferencesIfRequired(int index);
00097
00098
00099 const char *getLibraryPreference(const char *tablename,
00100 const char *opname) const;
00101
00102 void clearLibraryPreferences(bool refreshlibs);
00103
00104 bool loadLibraryPreferences(UT_IStream &is);
00105 void saveLibraryPreferences(ostream &os,
00106 bool includeinternal = true,
00107 bool protectstrings = false) const;
00108
00109
00110 const UT_String &getMetaSourceName(OP_OTLLibrary *lib,
00111 bool withpath = true) const;
00112 void getMetaSourceName(const char *metasrc,
00113 UT_String &metasrcname,
00114 bool withpath = true) const;
00115 bool setMetaSourceName(const char *metasrc,
00116 const char *metasrcname);
00117
00118
00119
00120
00121 bool getIsPerformingAtomicAddRemove() const;
00122
00123
00124
00125
00126 bool getIsPerformingRefreshAll() const;
00127
00128
00129 bool getIsCreatingNewHDA() const;
00130
00131
00132 void loadAutoOTLs();
00133 int findLibrary(const char *libfile,
00134 const char *metasrc = 0) const;
00135 int findNextLibrary(const char *libfile,
00136 int after) const;
00137 bool refreshLibrary(int index, bool force = true);
00138 bool removeLibrary(const char *libfile,
00139 const char *metasrc,
00140 bool changeoplibraries);
00141 bool removeMetaSource(const char *metasrc);
00142 void refreshAll(bool reloadOpLibraries);
00143
00144
00145
00146
00147
00148 OP_OTLLibrary *addLibrary(const char *libfile,
00149 const char *metasrc,
00150 bool changeoplibraries,
00151 bool installinternaliffail,
00152 UT_WorkBuffer &errors);
00153
00154
00155 int getNumLibraries() const;
00156 int getPreferredLibrary(const char *tablename,
00157 const char *opname);
00158 OP_OTLLibrary *getLibrary(int index) const;
00159
00160
00161
00162 int getLatestLibrary(const char *tablename,
00163 const char *opname,
00164 OP_OTLLibrary *tiegoesto = 0);
00165 bool getOutOfDateInternalOps(UT_StringArray &ops);
00166
00167
00168
00169 int getNextLibrary(const char *tablename,
00170 const char *opname,
00171 OP_OTLLibrary *startat);
00172
00173
00174
00175 bool addToLibrary(OP_OTLLibrary *lib,
00176 OP_OTLDefinition &definition,
00177 FS_IndexFile *deffile,
00178 bool dummydefinition = false) const;
00179 bool addToLibrary(const char *libfile,
00180 OP_OTLDefinition &definition,
00181 FS_IndexFile *deffile,
00182 bool dummydefinition = false);
00183
00184
00185
00186 bool mergeLibraries(const char *primary,
00187 const char *secondary);
00188
00189
00190
00191
00192
00193 bool addToInternalLibrary(OP_OTLLibrary *newlib);
00194 bool addToInternalLibrary(UT_IStream &is, int modtime);
00195
00196
00197
00198
00199 bool removeFromLibrary(const char *libfile,
00200 const UT_StringArray &ops);
00201
00202
00203
00204 bool touchDefinition(const char *libfile,
00205 const char *tablename,
00206 const char *opname,
00207 int newtime = -1);
00208
00209
00210
00211
00212 void modifyDefinitionToInternalPaths(
00213 OP_OTLDefinition &def,
00214 FS_IndexFile *deffile) const;
00215
00216
00217 void saveOpTypeFromNode( OP_Node *node, UT_String &errors );
00218
00219
00220
00221
00222 void updateContentsFromNode(FS_IndexFile *deffile,
00223 OP_Node *node,
00224 bool gzipcontents,
00225 bool compilebasic,
00226 bool compilevopnets,
00227 bool compilechannels,
00228 bool compilenodenames,
00229 const char *library);
00230
00231
00232 void updateDefinitionFromNode(FS_IndexFile *deffile,
00233 OP_Node *node,
00234 bool lockcontents,
00235 bool usedsparms,
00236 bool gzipcontents,
00237 bool savespareparms,
00238 const char *library);
00239
00240
00241 void setContentsCompression(FS_IndexFile *deffile,
00242 int gzipcontents);
00243
00244
00245 bool getComment(FS_IndexFile &deffile, UT_String &result);
00246 void setComment(FS_IndexFile *deffile, const char *comment);
00247 bool getVersion(FS_IndexFile &deffile, UT_String &result);
00248 void setVersion(FS_IndexFile *deffile, const char *version);
00249
00250
00251 void listLibraries(ostream &os) const;
00252 void listLibrariesWithDefinition(const char *tablename,
00253 const char *opname,
00254 ostream &os) const;
00255 void listOperators(const char *libfile, ostream &os) const;
00256 void listOperator(const char *libfile,
00257 const char *tablename,
00258 const char *opname,
00259 const char *format,
00260 ostream &os) const;
00261
00262
00263
00264 void getLibrariesWithDefinition(
00265 const char *tablename,
00266 const char *opname,
00267 UT_PtrArray<OP_OTLLibrary *> &list);
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 bool getAllMatchingOperators(const char *opmask,
00282 const OP_OTLLibrary *library,
00283 bool onlyotlops,
00284 UT_StringArray &results,
00285 UT_SymbolTable &resultstable) const;
00286
00287
00288 void addManagerSink(OP_OTLManagerSink *sink);
00289 void removeManagerSink(OP_OTLManagerSink *sink);
00290
00291
00292 bool checkValidNodeName(const char *name,
00293 OP_OperatorTable *table,
00294 UT_WorkBuffer &errors);
00295
00296 bool createOptype(const char *tablename,
00297 const char *opname,
00298 const char *oplabel,
00299 const char *installpath,
00300 int min, int max,
00301 const char *extradsinfo,
00302 const char *installmetasrc,
00303 const char *extrainfo,
00304 bool subnet,
00305 UT_WorkBuffer &errors);
00306
00307 static bool getHelpTemplateFile(UT_String &helptemplatefile);
00308 static void createDefaultOptypeName(OP_Node *fromnode,
00309 UT_String &name,
00310 UT_String &label);
00311 static void fullyQualifyLibFileName(const char *libfilebase,
00312 UT_String &libfile,
00313 const char *basedir = 0);
00314 void fullyQualifyMetaSrcName(const char *libfilebase,
00315 UT_String &libfile) const;
00316 void getSimplifiedPath(UT_String &destpath,
00317 const char *srcpath,
00318 const char *srcmeta) const;
00319
00320 bool canSavePreferences() const;
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 void pushFallbackLibraryContext();
00331 void popFallbackLibraryContext();
00332 void saveFallbackLibraryPaths(ostream &os,
00333 const OP_OperatorList &ops) const;
00334 bool loadFallbackLibraryPaths(UT_IStream &is);
00335 bool loadFallbackLibrary(const char *tablename,
00336 const char *opname);
00337
00338
00339
00340
00341
00342
00343
00344 void setDummyDefinition(const OP_OTLDefinition &definition,
00345 const FS_IndexFile *deffile);
00346 bool getDummyDefinition(const OP_Operator *op,
00347 FS_IndexFile *deffile) const;
00348 bool loadDummyDefinitions(UT_IStream &is, int modtime);
00349 void saveDummyDefinitions(ostream &os,
00350 const OP_OperatorList &ops) const;
00351
00352
00353 static void saveDefaultDialogScript(ostream &os,
00354 const char *opname,
00355 const char *oplabel,
00356 const char *extradsinfo);
00357
00358 static void saveDefaultCreationScript(ostream &os,
00359 const char *op,
00360 const char *table);
00361
00362
00363
00364
00365 void writeOutDefinitionContents(
00366 const OP_OTLDefinition &definition,
00367 FS_IndexFile & contents,
00368 ostream & os) const;
00369
00370
00371 void setFilters(const OP_OTLDefinition &definition,
00372 FS_IndexFile &contents) const;
00373
00374
00375
00376 void refreshLicenses();
00377
00378
00379
00380
00381
00382 const UT_String &getInternalTempFile() const;
00383
00384
00385
00386 bool hasNCAsset(const OP_OTLLibrary *lib);
00387
00388
00389
00390 void getNCAssets(const OP_OTLLibrary *lib,
00391 UT_IntArray & nc_assets);
00392
00393 private:
00394
00395 void notifySinksOfDefinitionsAdded(int libindex,
00396 UT_IntArray &defarray);
00397 void notifySinksOfDefinitionsRemoved(int libindex,
00398 UT_IntArray &defarray,
00399 OP_OTLLibrary *&preserve);
00400 void notifySinksOfSourceNamesChanged();
00401 void notifySinksOfLibraryAdded(OP_OTLLibrary *library);
00402 void notifySinksOfLibraryRemoved(OP_OTLLibrary *library);
00403 void notifySinksOfConfigurationChanged();
00404 void notifySinksOfLicensesChanged();
00405 void writeSimplifiedPath(ostream &os,
00406 const char *srcpath,
00407 const char *srcmeta,
00408 const char *prefix = 0) const;
00409
00410
00411 void setMetaSourceNameData(int pos, const char *metasrc,
00412 const char *metasrcname);
00413
00414
00415
00416
00417 bool saveMetaFile(const char *metafile,
00418 const char *skiplib,
00419 const char *addlib) const;
00420
00421
00422
00423 int addToMetaSource(const char *libfile,
00424 const char *metasrc,
00425 bool changeoplibraries);
00426
00427
00428 bool insertLibrary(OP_OTLLibrary *newlib, int before);
00429
00430 bool removeLibrary(int index);
00431
00432 void loadPreferences();
00433 void savePreferences();
00434
00435 void moveInternalToNewTempFile();
00436
00437
00438 void clearIfGoodDefinitionExists(OP_OTLLibrary *lib);
00439
00440 bool removeFromExternalLibrary(const char *libfile,
00441 const UT_StringArray &ops);
00442
00443
00444
00445 bool removeFromInternalLibrary(const UT_StringArray &ops);
00446
00447
00448
00449 bool touchExternalDefinition(const char *libfile,
00450 const char *tablename,
00451 const char *opname,
00452 int newtime);
00453 bool touchInternalDefinition(const char *tablename,
00454 const char *opname,
00455 int newtime);
00456
00457 void addFromOpLibrariesFile(const char *file,
00458 const char *metasrc,
00459 int &libpos);
00460
00461
00462 void setLibraryPreference(const char *tablename,
00463 const char *opname,
00464 const char *libfile,
00465 UT_IntArray *libstorefresh);
00466
00467
00468 void addFallbackLibraryPath(const char *tablename,
00469 const char *opname,
00470 const char *libfile);
00471 bool loadFallbackLibrary(UT_SymbolTable *context,
00472 const char *opsymbol,
00473 const char *tablename,
00474 const char *opname);
00475 void clearLibraryFallbacks(UT_SymbolTable *table);
00476
00477
00478 bool isNCAsset(FS_IndexFile * lib_file,
00479 const OP_OTLDefinition & def);
00480
00481
00482
00483
00484 static void deleteLibraries(void *data);
00485
00486 UT_PtrArray<OP_OTLLibrary *> myLibraries;
00487 UT_PtrArray<OP_OTLManagerSink *> myManagerSinks;
00488 UT_PtrArray<OP_OTLLibrary *> myLibrariesBeingRemoved;
00489 UT_String myInternalTempFile;
00490 UT_String myNewInternalTempFile;
00491 UT_StringArray myMetaSourcesWithNames;
00492 UT_StringArray myMetaSourceNames;
00493 UT_StringArray myMetaSourceNameWithPaths;
00494 UT_SymbolTable myLibraryPreferences;
00495 UT_PtrArray<UT_SymbolTable *> myLibraryFallbacks;
00496 OP_OTLLibrary myDummyDefinitions;
00497 UT_String myOperatorTypeBarMode;
00498 bool myIsPerformingAtomicAddRemove;
00499 bool myIsPerformingRefreshAll;
00500 bool mySaveToHipFile;
00501 bool mySaveUnlockedToHipFile;
00502 bool myWarnOutOfDateOps;
00503 bool myWarnDummyOpsOnLoad;
00504 bool myPreferLatestDateDefinition;
00505 bool myPreferInternalDefinition;
00506 bool myPreferIndexFileDefinition;
00507 bool myCreateBackups;
00508 bool mySafeguardOpDefs;
00509 bool myLeaveDefaultsUnchanged;
00510 bool myUseOplibrariesFiles;
00511 bool myIsCreatingNewHDA;
00512 };
00513
00514 class OP_API OP_OTLManagerSink
00515 {
00516 public:
00517 OP_OTLManagerSink() { }
00518 virtual ~OP_OTLManagerSink()
00519 { removeAllManagerSinks(); }
00520
00521 virtual void definitionsAdded(int ,
00522 UT_IntArray & ) { }
00523 virtual void definitionsRemoved(int ,
00524 UT_IntArray & ,
00525 OP_OTLLibrary *& ){ }
00526 virtual void sourceNamesChanged() { }
00527 virtual void libraryAdded(OP_OTLLibrary * ) { }
00528 virtual void libraryRemoved(OP_OTLLibrary * ) { }
00529 virtual void configurationChanged() { }
00530 virtual void licensesChanged() { }
00531
00532 void managerDeleted(OP_OTLManager *manager)
00533 { removeManagerSink(manager); }
00534
00535 protected:
00536 void addManagerSink(OP_OTLManager *manager)
00537 {
00538 if( !manager ) return;
00539 manager->addManagerSink(this);
00540 myManagers.append(manager, 1);
00541 }
00542 void removeManagerSink(OP_OTLManager *manager)
00543 {
00544 if( !manager ) return;
00545 manager->removeManagerSink(this);
00546 myManagers.remove(manager);
00547 }
00548 void removeAllManagerSinks()
00549 {
00550 for( int i = myManagers.entries(); i --> 0; )
00551 removeManagerSink(myManagers(i));
00552 }
00553
00554 private:
00555 UT_PtrArray<OP_OTLManager *> myManagers;
00556 };
00557
00558 #endif
00559