HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_PropertyTable.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: (UT_PropertyTable.h, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef _UT_PropertyTable_
12 #define _UT_PropertyTable_
13 
14 #include "UT_API.h"
15 #include "UT_Options.h"
16 #include "UT_Map.h"
17 #include "UT_SharedPtr.h"
18 #include "UT_SymbolTable.h"
19 
20 /// This class represents a table of (mantra) properties. A property consists
21 /// of a name (the name used by mantra), a parm name (the name of the houdini
22 /// parameter that corresponds to the mantra property), the data type of the
23 /// property, and the default value of the property.
24 ///
25 /// This information is somewhat scattered right now, with the parameter
26 /// definition in the $HH/properties/soho/IFDmantra.ds file, the translation
27 /// from houdini to mantra names in $HH/soho/base/IFDmantra.py, and the
28 /// defaults as mantra understands them (which should but may not match
29 /// the defaults in the parameter definitions) in $RAY/RAY_Settings.C.
30 /// At some point all references to render properties should be through
31 /// this class.
32 ///
33 /// The property table is loaded from a JSON array where each item in the array
34 /// is a dictionary defining a property. The items to define the property are:
35 /// - "string class" (required): Specifies the rendering class of the
36 /// property (i.e. "renderer", "object" or "option")
37 /// - "string name" (required): The renderer name for the property
38 /// - "string hname" (required): The name of the Houdini parameter
39 /// - "<type> default" (required): The default value. This may be one of:
40 /// - bool
41 /// - number
42 /// - string
43 /// - array of numbers
44 /// - array of strings
45 /// - "string label" (optional): The label of the Houdini parameter
46 /// - "float min" (optional): Suggested minimum value for numeric types
47 /// - "float max" (optional): Suggested maximum value for numeric types
48 ///
50 {
51 public:
53 
54  UT_PropertyTable(const char *table_name);
56  const char *filename=nullptr);
58 
59  /// Return the load status of the table in the c-tor.
60  bool loadStatus() const { return myLoadStatus; }
61 
62  SYS_DEPRECATED(16.0) // Use size()
63  int getNumProps() const { return size(); }
64  SYS_DEPRECATED(16.0) // Use findRName()
65  int getPropIndex(const UT_StringRef &name)
66  { return findRName(name); }
67 
68  SYS_DEPRECATED(16.0)
69  const UT_StringHolder &getPropName(int i) const { return rname(i); }
70  SYS_DEPRECATED(16.0)
71  const UT_StringHolder &getPropLabel(int i) const { return label(i); }
72  SYS_DEPRECATED(16.0)
73  const UT_StringHolder &getPropParm(int i) const { return hname(i); }
74  SYS_DEPRECATED(16.0)
75  OptionEntryPtr getPropDefault(int i) const { return value(i);}
76  SYS_DEPRECATED(16.0)
77  fpreal getMin(int i) const { return minValue(i); }
78  SYS_DEPRECATED(16.0)
79  fpreal getMax(int i) const { return maxValue(i); }
80 
81  /// Find a property by the renderer property name. This will find names
82  /// like "global:lod", but also "lod". The first usage (with class
83  /// specifier) avoids name aliasing between different rendering classes.
84  /// The method returns @c -1 if the property isn't found.
85  int findRName(const UT_StringRef &name) const;
86  /// Find property by the Houdini parameter name
87  /// The method returns @c -1 if the parameter isn't found.
88  int findHName(const UT_StringRef &name) const;
89 
90  /// Number of properties stored in the table
91  exint size() const { return myProperties.size(); }
92  /// Return the class of the rendering property (i.e. "object")
93  const UT_StringHolder &rclass(int i) const;
94  /// Return the name of the rendering property (i.e. "coving")
95  const UT_StringHolder &rname(int i) const;
96  /// Return the name of the houdini parameter (i.e. "vm_coving")
97  const UT_StringHolder &hname(int i) const;
98  /// Return the label of the houdini parameter (i.e. "Coving")
99  const UT_StringHolder &label(int i) const;
100  /// Return the default value of the houdini parameter (i.e. 1)
101  OptionEntryPtr value(int i) const;
102  /// @{
103  /// For numeric values, return the expected range of the values. These is
104  /// typically a suggested range.
105  fpreal minValue(int i) const;
106  fpreal maxValue(int i) const;
107  /// @}
108 
109  /// Debug the settings
110  bool save(UT_JSONWriter &w, const UT_IntArray *select=nullptr) const;
111  void dump(const UT_IntArray *select=nullptr) const;
112 
113  /// Relatively lightweight representation of a subset of a UT_PropertyList.
115  {
116  public:
118  : myTable(table)
119  {
120  }
122 
123  /// @{
124  /// Interface to properties
125  exint size() const { return myProperties.size(); }
126  const UT_StringHolder &rclass(int i) const
127  { return myTable.rclass(map(i)); }
128  const UT_StringHolder &rname(int i) const
129  { return myTable.rname(map(i)); }
130  const UT_StringHolder &hname(int i) const
131  { return myTable.hname(map(i)); }
132  const UT_StringHolder &label(int i) const
133  { return myTable.label(map(i)); }
134  OptionEntryPtr value(int i) const
135  { return myTable.value(map(i)); }
136  fpreal minValue(int i) const
137  { return myTable.minValue(map(i)); }
138  fpreal maxValue(int i) const
139  { return myTable.maxValue(map(i)); }
140 
141  bool save(UT_JSONWriter &w) const
142  { return myTable.save(w, &myProperties); }
143  void dump() const
144  { return myTable.dump(&myProperties); }
145  /// @}
146 
147  /// Get the index in the parent table
148  exint parentIndex(int i) const { return map(i); }
149 
150  /// Add a property using the index from the base table
151  void appendProperty(int id) { myProperties.append(id); }
152 
153  private:
154  int map(int i) const
155  {
156  return i >= 0 && i < myProperties.size() ? myProperties(i) : -1;
157  }
158  const UT_PropertyTable &myTable;
159  UT_IntArray myProperties;
160  };
161 
163  { return getSubset(&name, 1); }
164  const PropertySubsetList &getSubset(const UT_StringRef names[],
165  exint arraylen);
166 
167 private:
168  bool doInclude(const UT_StringRef &filename);
169  bool load(UT_IStream &is);
170  bool load(UT_JSONParser &p,
171  const char *filename=nullptr);
172  const PropertySubsetList &buildSubset(const UT_StringRef names[],
173  exint arraylen,
174  const UT_StringHolder &key);
175 
176  using PropertySubsetListMap = UT_Map<UT_StringHolder, PropertySubsetList>;
177  class PropDef
178  {
179  public:
180 
181  PropDef(const UT_StringHolder &rclass, // Render class ("object")
182  const UT_StringHolder &rname, // Renderer name ("coving")
183  const UT_StringHolder &hname, // Houdini name ("vm_coving")
184  const UT_StringHolder &label, // Parm label ("Coving")
185  const OptionEntryPtr &value, // Default value
186  fpreal min=-SYS_FPREAL_MAX, // Min/Max range
188  : myRClass(rclass)
189  , myRName(rname)
190  , myHName(hname)
191  , myLabel(label)
192  , myValue(value)
193  , myMin(min)
194  , myMax(max)
195  {
196  if (!myLabel)
197  myLabel = myRName;
198  }
199 
200  /// Saves out a dictionary for the property
201  bool save(UT_JSONWriter &w,
202  UT_Int64Array &istore,
203  UT_Fpreal64Array &fstore,
204  UT_StringArray &sstore) const;
205 
206  const UT_StringHolder &rclass() const { return myRClass; }
207  const UT_StringHolder &rname() const { return myRName; }
208  const UT_StringHolder &hname() const { return myHName; }
209  const UT_StringHolder &label() const { return myLabel; }
210  const OptionEntryPtr &value() const { return myValue; }
211  fpreal minValue() const { return myMin; }
212  fpreal maxValue() const { return myMax; }
213 
214  UT_StringHolder myRClass;
215  UT_StringHolder myRName;
216  UT_StringHolder myHName;
217  UT_StringHolder myLabel;
218  OptionEntryPtr myValue;
219  fpreal myMin;
220  fpreal myMax;
221  };
222 
223  UT_Array<PropDef> myProperties;
224  UT_SymbolMap<int> myRNameMap;
225  UT_SymbolMap<int> myHNameMap;
226  PropertySubsetListMap mySubsets;
227  bool myLoadStatus;
228 };
229 
230 #endif
Relatively lightweight representation of a subset of a UT_PropertyList.
GT_API const UT_StringHolder filename
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
#define SYS_DEPRECATED(__V__)
const UT_StringHolder & rclass(int i) const
UT_SharedPtr< UT_OptionEntry > OptionEntryPtr
bool loadStatus() const
Return the load status of the table in the c-tor.
PropertySubsetList(const UT_PropertyTable &table)
bool save(UT_JSONWriter &w) const
const UT_StringHolder & hname(int i) const
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:75
#define UT_API
Definition: UT_API.h:13
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
png_uint_32 i
Definition: png.h:2877
GLsizeiptr size
Definition: glcorearb.h:663
exint parentIndex(int i) const
Get the index in the parent table.
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:28
int64 exint
Definition: SYS_Types.h:116
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:133
exint size() const
Number of properties stored in the table.
const UT_StringHolder & label(int i) const
GLuint const GLchar * name
Definition: glcorearb.h:785
OptionEntryPtr value(int i) const
void appendProperty(int id)
Add a property using the index from the base table.
#define SYS_FPREAL_MAX
Definition: SYS_Types.h:279
const UT_StringHolder & rname(int i) const
GLsizei const GLfloat * value
Definition: glcorearb.h:823
double fpreal
Definition: SYS_Types.h:270
typedef int
Definition: png.h:1175
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
const PropertySubsetList & getSubset(const UT_StringRef &name)
#define const
Definition: zconf.h:214
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:129