HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PRM_PresetInfo.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: PRM_PresetInfo.h ( OP Library, C++)
7  *
8  * COMMENTS: PresetInfo for an Operator type.
9  */
10 
11 #ifndef __PRM_PresetInfo__
12 #define __PRM_PresetInfo__
13 
14 #include "PRM_API.h"
15 #include <iosfwd>
16 #include <UT/UT_Pair.h>
17 #include <UT/UT_String.h>
18 #include <UT/UT_ValArray.h>
19 
20 class PRM_ParmList;
22 
25 
26 #define PRM_DEFAULT_PRESET "Permanent Defaults"
27 
29 public:
30  /// Subdir is the name of the sub directory where the preset file can be
31  /// found. Since presets can be also loaded from HDAs, subdir is synonymous
32  /// with the operator table name (eg "Object"), except it can contain
33  /// version which the constructor strips off (eg, "Object12.5.100",
34  /// used for operator state parm dialogs.
35  /// File is the preset file name, which is the same as the operator
36  /// type it applies to (eg "myhda" or "ns::hda::1.0), the file name
37  /// will be groomed to ensure it is a valid file name (eg, "myhda" or
38  /// "ns-hda-1.0". By providing the unaltered optype name, it is possible
39  /// to locate presets inside the HDA sections, which otherwise would be
40  /// more difficult for namespaced optypes.
41  PRM_PresetInfo(const char *subdir, const char *file);
42  virtual ~PRM_PresetInfo();
43 
44  void setIndexFile(const char *subdir);
45  void setNeedsRefresh();
46 
47  int getNumPresets();
48  const UT_String &getPresetName(int i);
49  const UT_String &getPresetPath(int i);
50  const UT_String &getPresetFile();
51  const UT_String &getPresetSection();
52  int getDefaultPreset();
53  int getPresetIndex(const char *presetname);
54 
55  bool deletePresetFromDir(const char *name,
56  const char *dir = 0);
57  bool savePresetToDir(PRM_ParmList *parmlist,
58  const char *name,
59  const char *dir);
60  bool loadPresetFile(PRM_ParmList *parmlist,
61  const char *filename);
62  bool savePresetFile(PRM_ParmList *parmlist,
63  const char *filename);
64 
65  // Should probably wrap these in an UT_ErrorManager::Scope so that they
66  // will not fail because some other non-related error still exists
67  // in the current UT_ErrorManager. We've had interesting problems
68  // like that before.
69  bool savePreset(PRM_ParmList *parmlist, std::ostream &os);
70  bool loadPreset(PRM_ParmList *parmlist, UT_IStream &is);
71 
72  // This function makes sure the file name ends with ".preset".
73  static void makeValidPresetFileName(UT_String &filename);
74 
75  static const UT_StringArray &getValidSaveDirs();
76 
77  // Handle loading of basic contents (channels, values)
78  static bool loadPresetContents(PRM_ParmList *parmlist,
79  const char *token, UT_IStream &is);
80 
81 private:
82  void clear();
83  void findAllPresets();
84  void refreshIfRequired();
85 
86  static int comparePresets(UT_StringPair * const *p1,
87  UT_StringPair * const *p2);
88 
89  UT_String mySubdir;
90  UT_String myIndexFile;
91  UT_String myPresetFile;
92  UT_String myPresetSection;
93  UT_StringPairList myPresets;
94  bool myNeedsRefresh;
95 };
96 
97 #endif
png_uint_32 i
Definition: png.h:2877
GLuint const GLchar * name
Definition: glcorearb.h:785
UT_Pair< UT_String, UT_String > UT_StringPair
UT_ValArray< UT_StringPair * > UT_StringPairList
#define PRM_API
Definition: PRM_API.h:10