MaterialX 1.38.10
Loading...
Searching...
No Matches
Property.h
Go to the documentation of this file.
1//
2// Copyright Contributors to the MaterialX Project
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#ifndef MATERIALX_PROPERTY_H
7#define MATERIALX_PROPERTY_H
8
11
13
14#include <MaterialXCore/Geom.h>
15
16MATERIALX_NAMESPACE_BEGIN
17
18class Property;
19class PropertyAssign;
20class PropertySet;
22
24using PropertyPtr = shared_ptr<Property>;
26using ConstPropertyPtr = shared_ptr<const Property>;
27
29using PropertyAssignPtr = shared_ptr<PropertyAssign>;
31using ConstPropertyAssignPtr = shared_ptr<const PropertyAssign>;
32
34using PropertySetPtr = shared_ptr<PropertySet>;
36using ConstPropertySetPtr = shared_ptr<const PropertySet>;
37
39using PropertySetAssignPtr = shared_ptr<PropertySetAssign>;
41using ConstPropertySetAssignPtr = shared_ptr<const PropertySetAssign>;
42
45class MX_CORE_API Property : public ValueElement
46{
47 public:
48 Property(ElementPtr parent, const string& name) :
49 ValueElement(parent, CATEGORY, name)
50 {
51 }
52 virtual ~Property() { }
53
54 public:
55 static const string CATEGORY;
56};
57
60class MX_CORE_API PropertyAssign : public ValueElement
61{
62 public:
63 PropertyAssign(ElementPtr parent, const string& name) :
64 ValueElement(parent, CATEGORY, name)
65 {
66 }
67 virtual ~PropertyAssign() { }
68
71
73 void setProperty(const string& property)
74 {
75 setAttribute(PROPERTY_ATTRIBUTE, property);
76 }
77
79 bool hasProperty() const
80 {
81 return hasAttribute(PROPERTY_ATTRIBUTE);
82 }
83
85 const string& getProperty() const
86 {
87 return getAttribute(PROPERTY_ATTRIBUTE);
88 }
89
93
95 void setGeom(const string& geom)
96 {
97 setAttribute(GEOM_ATTRIBUTE, geom);
98 }
99
101 bool hasGeom() const
102 {
103 return hasAttribute(GEOM_ATTRIBUTE);
104 }
105
107 const string& getGeom() const
108 {
109 return getAttribute(GEOM_ATTRIBUTE);
110 }
111
115
117 void setCollectionString(const string& collection)
118 {
119 setAttribute(COLLECTION_ATTRIBUTE, collection);
120 }
121
124 {
125 return hasAttribute(COLLECTION_ATTRIBUTE);
126 }
127
129 const string& getCollectionString() const
130 {
131 return getAttribute(COLLECTION_ATTRIBUTE);
132 }
133
135 void setCollection(ConstCollectionPtr collection);
136
138 CollectionPtr getCollection() const;
139
141
142 public:
143 static const string CATEGORY;
144 static const string PROPERTY_ATTRIBUTE;
145 static const string GEOM_ATTRIBUTE;
146 static const string COLLECTION_ATTRIBUTE;
147};
148
151class MX_CORE_API PropertySet : public Element
152{
153 public:
154 PropertySet(ElementPtr parent, const string& name) :
155 Element(parent, CATEGORY, name)
156 {
157 }
158 virtual ~PropertySet() { }
159
162
168 PropertyPtr addProperty(const string& name)
169 {
170 return addChild<Property>(name);
171 }
172
174 PropertyPtr getProperty(const string& name) const
175 {
176 return getChildOfType<Property>(name);
177 }
178
180 vector<PropertyPtr> getProperties() const
181 {
182 return getChildrenOfType<Property>();
183 }
184
186 void removeProperty(const string& name)
187 {
188 removeChildOfType<Property>(name);
189 }
190
194
197 template <class T> PropertyPtr setPropertyValue(const string& name,
198 const T& value,
199 const string& type = EMPTY_STRING)
200 {
201 PropertyPtr property = getChildOfType<Property>(name);
202 if (!property)
203 property = addProperty(name);
204 property->setValue(value, type);
205 return property;
206 }
207
212 ValuePtr getPropertyValue(const string& name) const
213 {
214 PropertyPtr property = getProperty(name);
215 return property ? property->getValue() : ValuePtr();
216 }
217
219
220 public:
221 static const string CATEGORY;
222};
223
226class MX_CORE_API PropertySetAssign : public GeomElement
227{
228 public:
229 PropertySetAssign(ElementPtr parent, const string& name) :
230 GeomElement(parent, CATEGORY, name)
231 {
232 }
233 virtual ~PropertySetAssign() { }
234
237
239 void setPropertySetString(const string& propertySet)
240 {
241 setAttribute(PROPERTY_SET_ATTRIBUTE, propertySet);
242 }
243
246 {
247 return hasAttribute(PROPERTY_SET_ATTRIBUTE);
248 }
249
251 const string& getPropertySetString() const
252 {
253 return getAttribute(PROPERTY_SET_ATTRIBUTE);
254 }
255
257 void setPropertySet(ConstPropertySetPtr propertySet);
258
260 PropertySetPtr getPropertySet() const;
261
263
264 public:
265 static const string CATEGORY;
266 static const string PROPERTY_SET_ATTRIBUTE;
267};
268
269MATERIALX_NAMESPACE_END
270
271#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:55
shared_ptr< Collection > CollectionPtr
A shared pointer to a Collection.
Definition: Geom.h:53
Import and export declarations for the Core library.
shared_ptr< const PropertySet > ConstPropertySetPtr
A shared pointer to a const PropertySet.
Definition: Property.h:36
shared_ptr< PropertySet > PropertySetPtr
A shared pointer to a PropertySet.
Definition: Property.h:34
shared_ptr< PropertySetAssign > PropertySetAssignPtr
A shared pointer to a PropertySetAssign.
Definition: Property.h:39
shared_ptr< PropertyAssign > PropertyAssignPtr
A shared pointer to a PropertyAssign.
Definition: Property.h:29
shared_ptr< Property > PropertyPtr
A shared pointer to a Property.
Definition: Property.h:24
shared_ptr< const PropertyAssign > ConstPropertyAssignPtr
A shared pointer to a const PropertyAssign.
Definition: Property.h:31
shared_ptr< const PropertySetAssign > ConstPropertySetAssignPtr
A shared pointer to a const PropertySetAssign.
Definition: Property.h:41
shared_ptr< const Property > ConstPropertyPtr
A shared pointer to a const Property.
Definition: Property.h:26
shared_ptr< Value > ValuePtr
A shared pointer to a Value.
Definition: Value.h:29
The base class for MaterialX elements.
Definition: Element.h:80
const string & getAttribute(const string &attrib) const
Return the value string of the given attribute.
Definition: Element.h:504
void setAttribute(const string &attrib, const string &value)
Set the value string of the given attribute.
Definition: Element.cpp:191
bool hasAttribute(const string &attrib) const
Return true if the given attribute is present.
Definition: Element.h:497
The base class for geometric elements, which support bindings to geometries and geometric collections...
Definition: Geom.h:144
A property assignment element within a Look.
Definition: Property.h:61
const string & getGeom() const
Return the geometry string of this element.
Definition: Property.h:107
const string & getProperty() const
Return the property string of this element.
Definition: Property.h:85
bool hasProperty() const
Return true if this element has a property string.
Definition: Property.h:79
const string & getCollectionString() const
Return the collection string of this element.
Definition: Property.h:129
void setGeom(const string &geom)
Set the geometry string of this element.
Definition: Property.h:95
bool hasCollectionString() const
Return true if this element has a collection string.
Definition: Property.h:123
bool hasGeom() const
Return true if this element has a geometry string.
Definition: Property.h:101
void setCollectionString(const string &collection)
Set the collection string of this element.
Definition: Property.h:117
void setProperty(const string &property)
Set the property string of this element.
Definition: Property.h:73
A property element within a PropertySet.
Definition: Property.h:46
A property set assignment element within a Look.
Definition: Property.h:227
const string & getPropertySetString() const
Return the property set string of this element.
Definition: Property.h:251
void setPropertySetString(const string &propertySet)
Set the property set string of this element.
Definition: Property.h:239
bool hasPropertySetString() const
Return true if this element has a property set string.
Definition: Property.h:245
A property set element within a Document.
Definition: Property.h:152
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:197
void removeProperty(const string &name)
Remove the Property with the given name, if present.
Definition: Property.h:186
vector< PropertyPtr > getProperties() const
Return a vector of all Property elements in the set.
Definition: Property.h:180
ValuePtr getPropertyValue(const string &name) const
Return the typed value of a property by its name.
Definition: Property.h:212
PropertyPtr getProperty(const string &name) const
Return the Property, if any, with the given name.
Definition: Property.h:174
PropertyPtr addProperty(const string &name)
Add a Property to the set.
Definition: Property.h:168
The base class for elements that support typed values.
Definition: Element.h:901