1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #include "pxr/pxr.h"
25 #include "pxr/usd/usd/notice.h"
26 #include "pxr/usd/usd/stage.h"
27 #include "pxr/base/tf/stl.h"
28
29 #include <boost/iterator/transform_iterator.hpp>
30
31 using boost::make_transform_iterator;
32
33 PXR_NAMESPACE_OPEN_SCOPE
34
35 // Register the notice class
TF_REGISTRY_FUNCTION(TfType)36 TF_REGISTRY_FUNCTION(TfType)
37 {
38 TfType::Define<UsdNotice::StageNotice, TfType::Bases<TfNotice> >();
39
40 TfType::Define<
41 UsdNotice::StageContentsChanged,
42 TfType::Bases<UsdNotice::StageNotice> >();
43
44 TfType::Define<
45 UsdNotice::StageEditTargetChanged,
46 TfType::Bases<UsdNotice::StageNotice> >();
47
48 TfType::Define<
49 UsdNotice::ObjectsChanged,
50 TfType::Bases<UsdNotice::StageNotice> >();
51
52 TfType::Define<
53 UsdNotice::LayerMutingChanged,
54 TfType::Bases<UsdNotice::StageNotice> >();
55 }
56
57
StageNotice(const UsdStageWeakPtr & stage)58 UsdNotice::StageNotice::StageNotice(const UsdStageWeakPtr& stage) :
59 _stage(stage)
60 {
61 }
62
~StageNotice()63 UsdNotice::StageNotice::~StageNotice() {}
64
~StageContentsChanged()65 UsdNotice::StageContentsChanged::~StageContentsChanged() {}
66
~StageEditTargetChanged()67 UsdNotice::StageEditTargetChanged::~StageEditTargetChanged() {}
68
~LayerMutingChanged()69 UsdNotice::LayerMutingChanged::~LayerMutingChanged() {}
70
71 TfTokenVector
GetChangedFields() const72 UsdNotice::ObjectsChanged::PathRange::const_iterator::GetChangedFields() const
73 {
74 TfTokenVector fields;
75 for (const SdfChangeList::Entry* entry : base()->second) {
76 fields.insert(fields.end(),
77 make_transform_iterator(entry->infoChanged.begin(), TfGet<0>()),
78 make_transform_iterator(entry->infoChanged.end(), TfGet<0>()));
79 }
80
81 std::sort(fields.begin(), fields.end());
82 fields.erase(std::unique(fields.begin(), fields.end()), fields.end());
83 return fields;
84 }
85
86 bool
HasChangedFields() const87 UsdNotice::ObjectsChanged::PathRange::const_iterator::HasChangedFields() const
88 {
89 for (const SdfChangeList::Entry* entry : base()->second) {
90 if (!entry->infoChanged.empty()) {
91 return true;
92 }
93 }
94 return false;
95 }
96
~ObjectsChanged()97 UsdNotice::ObjectsChanged::~ObjectsChanged() {}
98
99 bool
ResyncedObject(const UsdObject & obj) const100 UsdNotice::ObjectsChanged::ResyncedObject(const UsdObject &obj) const
101 {
102 // XXX: We don't need the longest prefix here, we just need to know if
103 // a prefix exists in the map.
104 return SdfPathFindLongestPrefix(
105 *_resyncChanges, obj.GetPath()) != _resyncChanges->end();
106 }
107
108 bool
ChangedInfoOnly(const UsdObject & obj) const109 UsdNotice::ObjectsChanged::ChangedInfoOnly(const UsdObject &obj) const
110 {
111 // XXX: We don't need the longest prefix here, we just need to know if
112 // a prefix exists in the map.
113 return SdfPathFindLongestPrefix(
114 *_infoChanges, obj.GetPath()) != _infoChanges->end();
115 }
116
117 UsdNotice::ObjectsChanged::PathRange
GetResyncedPaths() const118 UsdNotice::ObjectsChanged::GetResyncedPaths() const
119 {
120 return PathRange(_resyncChanges);
121 }
122
123 UsdNotice::ObjectsChanged::PathRange
GetChangedInfoOnlyPaths() const124 UsdNotice::ObjectsChanged::GetChangedInfoOnlyPaths() const
125 {
126 return PathRange(_infoChanges);
127 }
128
129 TfTokenVector
GetChangedFields(const UsdObject & obj) const130 UsdNotice::ObjectsChanged::GetChangedFields(const UsdObject &obj) const
131 {
132 return GetChangedFields(obj.GetPath());
133 }
134
135 TfTokenVector
GetChangedFields(const SdfPath & path) const136 UsdNotice::ObjectsChanged::GetChangedFields(const SdfPath &path) const
137 {
138 PathRange range = GetResyncedPaths();
139 PathRange::const_iterator it = range.find(path);
140 if (it != range.end()) {
141 return it.GetChangedFields();
142 }
143
144 range = GetChangedInfoOnlyPaths();
145 it = range.find(path);
146 if (it != range.end()) {
147 return it.GetChangedFields();
148 }
149
150 return TfTokenVector();
151 }
152
153 bool
HasChangedFields(const UsdObject & obj) const154 UsdNotice::ObjectsChanged::HasChangedFields(const UsdObject &obj) const
155 {
156 return HasChangedFields(obj.GetPath());
157 }
158
159 bool
HasChangedFields(const SdfPath & path) const160 UsdNotice::ObjectsChanged::HasChangedFields(const SdfPath &path) const
161 {
162 PathRange range = GetResyncedPaths();
163 PathRange::const_iterator it = range.find(path);
164 if (it != range.end()) {
165 return it.HasChangedFields();
166 }
167
168 range = GetChangedInfoOnlyPaths();
169 it = range.find(path);
170 if (it != range.end()) {
171 return it.HasChangedFields();
172 }
173
174 return false;
175 }
176
177 PXR_NAMESPACE_CLOSE_SCOPE
178
179