MaterialX 1.38.2
Property.h
Go to the documentation of this file.
1//
2// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3// All rights reserved. See LICENSE.txt for license.
4//
5
6#ifndef MATERIALX_PROPERTY_H
7#define MATERIALX_PROPERTY_H
8
11
13
14#include <MaterialXCore/Geom.h>
15
16namespace MaterialX
17{
18
19class Property;
20class PropertyAssign;
21class PropertySet;
22class PropertySetAssign;
23
25using PropertyPtr = shared_ptr<Property>;
27using ConstPropertyPtr = shared_ptr<const Property>;
28
30using PropertyAssignPtr = shared_ptr<PropertyAssign>;
32using ConstPropertyAssignPtr = shared_ptr<const PropertyAssign>;
33
35using PropertySetPtr = shared_ptr<PropertySet>;
37using ConstPropertySetPtr = shared_ptr<const PropertySet>;
38
40using PropertySetAssignPtr = shared_ptr<PropertySetAssign>;
42using ConstPropertySetAssignPtr = shared_ptr<const PropertySetAssign>;
43
46class MX_CORE_API Property : public ValueElement
47{
48 public:
49 Property(ElementPtr parent, const string& name) :
50 ValueElement(parent, CATEGORY, name)
51 {
52 }
53 virtual ~Property() { }
54
55 public:
56 static const string CATEGORY;
57};
58
61class MX_CORE_API PropertyAssign : public ValueElement
62{
63 public:
64 PropertyAssign(ElementPtr parent, const string& name) :
65 ValueElement(parent, CATEGORY, name)
66 {
67 }
68 virtual ~PropertyAssign() { }
69
72
74 void setProperty(const string& property)
75 {
76 setAttribute(PROPERTY_ATTRIBUTE, property);
77 }
78
80 bool hasProperty() const
81 {
82 return hasAttribute(PROPERTY_ATTRIBUTE);
83 }
84
86 const string& getProperty() const
87 {
88 return getAttribute(PROPERTY_ATTRIBUTE);
89 }
90
94
96 void setGeom(const string& geom)
97 {
98 setAttribute(GEOM_ATTRIBUTE, geom);
99 }
100
102 bool hasGeom() const
103 {
104 return hasAttribute(GEOM_ATTRIBUTE);
105 }
106
108 const string& getGeom() const
109 {
110 return getAttribute(GEOM_ATTRIBUTE);
111 }
112
116
118 void setCollectionString(const string& collection)
119 {
120 setAttribute(COLLECTION_ATTRIBUTE, collection);
121 }
122
125 {
126 return hasAttribute(COLLECTION_ATTRIBUTE);
127 }
128
130 const string& getCollectionString() const
131 {
132 return getAttribute(COLLECTION_ATTRIBUTE);
133 }
134
136 void setCollection(ConstCollectionPtr collection);
137
139 CollectionPtr getCollection() const;
140
142
143 public:
144 static const string CATEGORY;
145 static const string PROPERTY_ATTRIBUTE;
146 static const string GEOM_ATTRIBUTE;
147 static const string COLLECTION_ATTRIBUTE;
148};
149
152class MX_CORE_API PropertySet : public Element
153{
154 public:
155 PropertySet(ElementPtr parent, const string& name) :
156 Element(parent, CATEGORY, name)
157 {
158 }
159 virtual ~PropertySet() { }
160
163
169 PropertyPtr addProperty(const string& name)
170 {
171 return addChild<Property>(name);
172 }
173
175 PropertyPtr getProperty(const string& name) const
176 {
177 return getChildOfType<Property>(name);
178 }
179
181 vector<PropertyPtr> getProperties() const
182 {
183 return getChildrenOfType<Property>();
184 }
185
187 void removeProperty(const string& name)
188 {
189 removeChildOfType<Property>(name);
190 }
191
195
198 template<class T> PropertyPtr setPropertyValue(const string& name,
199 const T& value,
200 const string& type = EMPTY_STRING)
201 {
202 PropertyPtr property = getChildOfType<Property>(name);
203 if (!property)
204 property = addProperty(name);
205 property->setValue(value, type);
206 return property;
207 }
208
213 ValuePtr getPropertyValue(const string& name) const
214 {
215 PropertyPtr property = getProperty(name);
216 return property ? property->getValue() : ValuePtr();
217 }
218
220
221public:
222 static const string CATEGORY;
223};
224
227class MX_CORE_API PropertySetAssign : public GeomElement
228{
229 public:
230 PropertySetAssign(ElementPtr parent, const string& name) :
231 GeomElement(parent, CATEGORY, name)
232 {
233 }
234 virtual ~PropertySetAssign() { }
235
238
240 void setPropertySetString(const string& propertySet)
241 {
242 setAttribute(PROPERTY_SET_ATTRIBUTE, propertySet);
243 }
244
247 {
248 return hasAttribute(PROPERTY_SET_ATTRIBUTE);
249 }
250
252 const string& getPropertySetString() const
253 {
254 return getAttribute(PROPERTY_SET_ATTRIBUTE);
255 }
256
258 void setPropertySet(ConstPropertySetPtr propertySet);
259
261 PropertySetPtr getPropertySet() const;
262
264
265 public:
266 static const string CATEGORY;
267 static const string PROPERTY_SET_ATTRIBUTE;
268};
269
270} // namespace MaterialX
271
272#endif
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
Geometric element subclasses.
shared_ptr< const Collection > ConstCollectionPtr
A shared pointer to a const Collection.
Definition: Geom.h:56
shared_ptr< Collection > CollectionPtr
A shared pointer to a Collection.
Definition: Geom.h:54
Import and export declarations for the Core library.
shared_ptr< const PropertySet > ConstPropertySetPtr
A shared pointer to a const PropertySet.
Definition: Property.h:37
shared_ptr< PropertySet > PropertySetPtr
A shared pointer to a PropertySet.
Definition: Property.h:35
shared_ptr< PropertySetAssign > PropertySetAssignPtr
A shared pointer to a PropertySetAssign.
Definition: Property.h:40
shared_ptr< PropertyAssign > PropertyAssignPtr
A shared pointer to a PropertyAssign.
Definition: Property.h:30
shared_ptr< Property > PropertyPtr
A shared pointer to a Property.
Definition: Property.h:25
shared_ptr< const PropertyAssign > ConstPropertyAssignPtr
A shared pointer to a const PropertyAssign.
Definition: Property.h:32
shared_ptr< const PropertySetAssign > ConstPropertySetAssignPtr
A shared pointer to a const PropertySetAssign.
Definition: Property.h:42
shared_ptr< const Property > ConstPropertyPtr
A shared pointer to a const Property.
Definition: Property.h:27
shared_ptr< Value > ValuePtr
A shared pointer to a Value.
Definition: Value.h:30
The base class for MaterialX elements.
Definition: Element.h:75
The base class for geometric elements, which support bindings to geometries and geometric collections...
Definition: Geom.h:154
A property assignment element within a Look.
Definition: Property.h:62
const string & getGeom() const
Return the geometry string of this element.
Definition: Property.h:108
const string & getProperty() const
Return the property string of this element.
Definition: Property.h:86
bool hasProperty() const
Return true if this element has a property string.
Definition: Property.h:80
const string & getCollectionString() const
Return the collection string of this element.
Definition: Property.h:130
void setGeom(const string &geom)
Set the geometry string of this element.
Definition: Property.h:96
bool hasCollectionString() const
Return true if this element has a collection string.
Definition: Property.h:124
bool hasGeom() const
Return true if this element has a geometry string.
Definition: Property.h:102
void setCollectionString(const string &collection)
Set the collection string of this element.
Definition: Property.h:118
void setProperty(const string &property)
Set the property string of this element.
Definition: Property.h:74
A property element within a PropertySet.
Definition: Property.h:47
A property set assignment element within a Look.
Definition: Property.h:228
const string & getPropertySetString() const
Return the property set string of this element.
Definition: Property.h:252
void setPropertySetString(const string &propertySet)
Set the property set string of this element.
Definition: Property.h:240
bool hasPropertySetString() const
Return true if this element has a property set string.
Definition: Property.h:246
A property set element within a Document.
Definition: Property.h:153
PropertyPtr setPropertyValue(const string &name, const T &value, const string &type=EMPTY_STRING)
Set the typed value of a property by its name, creating a child element to hold the property if neede...
Definition: Property.h:198
void removeProperty(const string &name)
Remove the Property with the given name, if present.
Definition: Property.h:187
vector< PropertyPtr > getProperties() const
Return a vector of all Property elements in the set.
Definition: Property.h:181
ValuePtr getPropertyValue(const string &name) const
Return the typed value of a property by its name.
Definition: Property.h:213
PropertyPtr getProperty(const string &name) const
Return the Property, if any, with the given name.
Definition: Property.h:175
PropertyPtr addProperty(const string &name)
Add a Property to the set.
Definition: Property.h:169
The base class for elements that support typed values.
Definition: Element.h:899