forked from autodesk-forks/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProperty.h
219 lines (179 loc) · 5.64 KB
/
Property.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//
// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
// All rights reserved. See LICENSE.txt for license.
//
#ifndef MATERIALX_PROPERTY_H
#define MATERIALX_PROPERTY_H
/// @file
/// Property element subclasses
#include <MaterialXCore/Library.h>
#include <MaterialXCore/Geom.h>
namespace MaterialX
{
class Property;
class PropertyAssign;
class PropertySet;
class PropertySetAssign;
/// A shared pointer to a Property
using PropertyPtr = shared_ptr<Property>;
/// A shared pointer to a const Property
using ConstPropertyPtr = shared_ptr<const Property>;
/// A shared pointer to a PropertyAssign
using PropertyAssignPtr = shared_ptr<PropertyAssign>;
/// A shared pointer to a const PropertyAssign
using ConstPropertyAssignPtr = shared_ptr<const PropertyAssign>;
/// A shared pointer to a PropertySet
using PropertySetPtr = shared_ptr<PropertySet>;
/// A shared pointer to a const PropertySet
using ConstPropertySetPtr = shared_ptr<const PropertySet>;
/// A shared pointer to a PropertySetAssign
using PropertySetAssignPtr = shared_ptr<PropertySetAssign>;
/// A shared pointer to a const PropertySetAssign
using ConstPropertySetAssignPtr = shared_ptr<const PropertySetAssign>;
/// @class Property
/// A property element within a PropertySet.
class Property : public ValueElement
{
public:
Property(ElementPtr parent, const string& name) :
ValueElement(parent, CATEGORY, name)
{
}
virtual ~Property() { }
public:
static const string CATEGORY;
};
/// @class PropertyAssign
/// A property assignment element within a Look.
class PropertyAssign : public ValueElement
{
public:
PropertyAssign(ElementPtr parent, const string& name) :
ValueElement(parent, CATEGORY, name)
{
}
virtual ~PropertyAssign() { }
/// @name Geometry
/// @{
/// Set the geometry string of this element.
void setGeom(const string& geom)
{
setAttribute(GEOM_ATTRIBUTE, geom);
}
/// Return true if this element has a geometry string.
bool hasGeom() const
{
return hasAttribute(GEOM_ATTRIBUTE);
}
/// Return the geometry string of this element.
const string& getGeom() const
{
return getAttribute(GEOM_ATTRIBUTE);
}
/// @}
/// @name Collection
/// @{
/// Set the collection string of this element.
void setCollectionString(const string& collection)
{
setAttribute(COLLECTION_ATTRIBUTE, collection);
}
/// Return true if this element has a collection string.
bool hasCollectionString() const
{
return hasAttribute(COLLECTION_ATTRIBUTE);
}
/// Return the collection string of this element.
const string& getCollectionString() const
{
return getAttribute(COLLECTION_ATTRIBUTE);
}
/// Assign a Collection to this element.
void setCollection(ConstCollectionPtr collection);
/// Return the Collection that is assigned to this element.
CollectionPtr getCollection() const;
/// @}
public:
static const string CATEGORY;
static const string GEOM_ATTRIBUTE;
static const string COLLECTION_ATTRIBUTE;
};
/// @class PropertySet
/// A property set element within a Document.
class PropertySet : public Element
{
public:
PropertySet(ElementPtr parent, const string& name) :
Element(parent, CATEGORY, name)
{
}
virtual ~PropertySet() { }
/// @name Properties
/// @{
/// Add a Property to the set.
/// @param name The name of the new Property.
/// If no name is specified, then a unique name will automatically be
/// generated.
/// @return A shared pointer to the new Property.
PropertyPtr addProperty(const string& name)
{
return addChild<Property>(name);
}
/// Return the Property, if any, with the given name.
PropertyPtr getProperty(const string& name) const
{
return getChildOfType<Property>(name);
}
/// Return a vector of all Property elements in the set.
vector<PropertyPtr> getProperties() const
{
return getChildrenOfType<Property>();
}
/// Remove the Property with the given name, if present.
void removeProperty(const string& name)
{
removeChildOfType<Property>(name);
}
/// @}
/// @name Values
/// @{
/// Set the typed value of a property by its name, creating a child element
/// to hold the property if needed.
template<class T> PropertyPtr setPropertyValue(const string& name,
const T& value,
const string& type = EMPTY_STRING)
{
PropertyPtr property = getChildOfType<Property>(name);
if (!property)
property = addProperty(name);
property->setValue(value, type);
return property;
}
/// Return the typed value of a property by its name.
/// @param name The name of the property to be evaluated.
/// @return If the given property is found, then a shared pointer to its
/// value is returned; otherwise, an empty shared pointer is returned.
ValuePtr getPropertyValue(const string& name) const
{
PropertyPtr property = getProperty(name);
return property ? property->getValue() : ValuePtr();
}
/// @}
public:
static const string CATEGORY;
};
/// @class PropertySetAssign
/// A property set assignment element within a Look.
class PropertySetAssign : public GeomElement
{
public:
PropertySetAssign(ElementPtr parent, const string& name) :
GeomElement(parent, CATEGORY, name)
{
}
virtual ~PropertySetAssign() { }
public:
static const string CATEGORY;
};
} // namespace MaterialX
#endif