Skip to content

Commit ecabe06

Browse files
authored
Merge pull request #4054 from Autodesk/bailp/EMSUSD-1971/job-context-marco-order
EMSUSD-1971 Make job context UI registeration be order-neutral
2 parents 4dff870 + 51d6db5 commit ecabe06

File tree

3 files changed

+101
-94
lines changed

3 files changed

+101
-94
lines changed

lib/mayaUsd/fileio/jobContextRegistry.cpp

+90-65
Original file line numberDiff line numberDiff line change
@@ -62,34 +62,39 @@ void UsdMayaJobContextRegistry::RegisterExportJobContext(
6262
bool fromPython)
6363
{
6464
TF_DEBUG(PXRUSDMAYA_REGISTRY).Msg("Registering export job context %s.\n", jobContext.c_str());
65+
6566
TfToken key(jobContext);
66-
ContextInfo newInfo { key, TfToken(niceName), TfToken(description), enablerFct, {}, {} };
67-
auto itFound = _jobContextReg.find(newInfo);
67+
ContextInfo newInfo { key, TfToken(niceName), TfToken(description) };
68+
newInfo.exportEnablerCallback = enablerFct;
69+
70+
auto itFound = _jobContextReg.find(newInfo);
6871
if (itFound == _jobContextReg.end()) {
6972
_jobContextReg.insert(newInfo);
7073
UsdMaya_RegistryHelper::AddUnloader(
71-
[key]() {
72-
ContextInfo toErase { key, {}, {}, {}, {}, {} };
73-
_jobContextReg.erase(toErase);
74-
},
75-
fromPython);
74+
[key]() { _jobContextReg.erase(ContextInfo { key }); }, fromPython);
7675
} else {
77-
if (!itFound->exportEnablerCallback) {
78-
if (niceName != itFound->niceName) {
79-
TF_CODING_ERROR(
80-
"Export enabler has differing nice name: %s != %s",
81-
niceName.c_str(),
82-
itFound->niceName.GetText());
83-
}
84-
// Fill the export part:
85-
ContextInfo updatedInfo(*itFound);
86-
updatedInfo.exportDescription = TfToken(description);
87-
updatedInfo.exportEnablerCallback = enablerFct;
88-
_jobContextReg.erase(updatedInfo);
89-
_jobContextReg.insert(updatedInfo);
90-
} else {
76+
if (itFound->exportEnablerCallback) {
9177
TF_CODING_ERROR("Multiple enablers for export job context %s", jobContext.c_str());
9278
}
79+
80+
if (itFound->niceName.size() > 0 && niceName != itFound->niceName) {
81+
TF_CODING_ERROR(
82+
"Export enabler has differing nice name: %s != %s",
83+
niceName.c_str(),
84+
itFound->niceName.GetText());
85+
}
86+
87+
// Note: the container for the plugin info is a set so it cannot be modified.
88+
// We need to copy the entry, modify the copy, remove the old entry and
89+
// insert the newly updated entry.
90+
ContextInfo updatedInfo(*itFound);
91+
if (niceName.size() > 0)
92+
updatedInfo.niceName = TfToken(niceName);
93+
if (description.size() > 0)
94+
updatedInfo.exportDescription = TfToken(description);
95+
updatedInfo.exportEnablerCallback = enablerFct;
96+
_jobContextReg.erase(updatedInfo);
97+
_jobContextReg.insert(updatedInfo);
9398
}
9499
}
95100

@@ -98,22 +103,27 @@ void UsdMayaJobContextRegistry::SetExportOptionsUI(
98103
UIFn uiFct,
99104
bool fromPython)
100105
{
101-
const ContextInfo key { TfToken(jobContext), {}, {}, {}, {}, {} };
102-
auto iter = _jobContextReg.find(key);
103-
if (iter == _jobContextReg.end()) {
104-
TF_CODING_ERROR("Export job context %s does not exists", jobContext.c_str());
105-
return;
106-
}
106+
TF_DEBUG(PXRUSDMAYA_REGISTRY).Msg("Adding export job context %s UI.\n", jobContext.c_str());
107107

108-
// Note: the container for the plugin info is a set so it cannot be modified.
109-
// We need to copy the entry, modify the copy, remove the old entry and
110-
// insert the newly updated entry.
108+
TfToken key(jobContext);
109+
ContextInfo newInfo { key };
110+
newInfo.exportUICallback = uiFct;
111111

112-
ContextInfo updatedInfo(*iter);
113-
updatedInfo.exportUICallback = uiFct;
114-
UsdMaya_RegistryHelper::AddUnloader([key]() { _jobContextReg.erase(key); }, fromPython);
115-
_jobContextReg.erase(iter);
116-
_jobContextReg.insert(updatedInfo);
112+
auto itFound = _jobContextReg.find(newInfo);
113+
if (itFound == _jobContextReg.end()) {
114+
_jobContextReg.insert(newInfo);
115+
UsdMaya_RegistryHelper::AddUnloader(
116+
[key]() { _jobContextReg.erase(ContextInfo { key }); }, fromPython);
117+
} else {
118+
// Note: the container for the plugin info is a set so it cannot be modified.
119+
// We need to copy the entry, modify the copy, remove the old entry and
120+
// insert the newly updated entry.
121+
122+
ContextInfo updatedInfo(*itFound);
123+
updatedInfo.exportUICallback = uiFct;
124+
_jobContextReg.erase(itFound);
125+
_jobContextReg.insert(updatedInfo);
126+
}
117127
}
118128

119129
void UsdMayaJobContextRegistry::RegisterImportJobContext(
@@ -124,9 +134,12 @@ void UsdMayaJobContextRegistry::RegisterImportJobContext(
124134
bool fromPython)
125135
{
126136
TF_DEBUG(PXRUSDMAYA_REGISTRY).Msg("Registering import job context %s.\n", jobContext.c_str());
137+
127138
TfToken key(jobContext);
128-
ContextInfo newInfo { key, TfToken(niceName), {}, {}, TfToken(description), enablerFct };
129-
auto itFound = _jobContextReg.find(newInfo);
139+
ContextInfo newInfo { key, TfToken(niceName), {}, {}, {}, TfToken(description) };
140+
newInfo.importEnablerCallback = enablerFct;
141+
142+
auto itFound = _jobContextReg.find(newInfo);
130143
if (itFound == _jobContextReg.end()) {
131144
_jobContextReg.insert(newInfo);
132145
UsdMaya_RegistryHelper::AddUnloader(
@@ -136,22 +149,29 @@ void UsdMayaJobContextRegistry::RegisterImportJobContext(
136149
},
137150
fromPython);
138151
} else {
139-
if (!itFound->importEnablerCallback) {
140-
if (niceName != itFound->niceName) {
141-
TF_CODING_ERROR(
142-
"Import enabler has differing nice name: %s != %s",
143-
niceName.c_str(),
144-
itFound->niceName.GetText());
145-
}
146-
// Fill the import part:
147-
ContextInfo updatedInfo(*itFound);
148-
updatedInfo.importDescription = TfToken(description);
149-
updatedInfo.importEnablerCallback = enablerFct;
150-
_jobContextReg.erase(updatedInfo);
151-
_jobContextReg.insert(updatedInfo);
152-
} else {
152+
if (itFound->importEnablerCallback) {
153153
TF_CODING_ERROR("Multiple enablers for import job context %s", jobContext.c_str());
154154
}
155+
156+
if (itFound->niceName.size() > 0 && niceName.size() > 0 && niceName != itFound->niceName) {
157+
TF_CODING_ERROR(
158+
"Import enabler has differing nice name: %s != %s",
159+
niceName.c_str(),
160+
itFound->niceName.GetText());
161+
}
162+
163+
// Note: the container for the plugin info is a set so it cannot be modified.
164+
// We need to copy the entry, modify the copy, remove the old entry and
165+
// insert the newly updated entry.
166+
167+
ContextInfo updatedInfo(*itFound);
168+
if (niceName.size() > 0)
169+
updatedInfo.niceName = TfToken(niceName);
170+
if (description.size() > 0)
171+
updatedInfo.importDescription = TfToken(description);
172+
updatedInfo.importEnablerCallback = enablerFct;
173+
_jobContextReg.erase(updatedInfo);
174+
_jobContextReg.insert(updatedInfo);
155175
}
156176
}
157177

@@ -160,22 +180,27 @@ void UsdMayaJobContextRegistry::SetImportOptionsUI(
160180
UIFn uiFct,
161181
bool fromPython)
162182
{
163-
const ContextInfo key { TfToken(jobContext), {}, {}, {}, {}, {} };
164-
auto iter = _jobContextReg.find(key);
165-
if (iter == _jobContextReg.end()) {
166-
TF_CODING_ERROR("Import job context %s does not exist", jobContext.c_str());
167-
return;
168-
}
183+
TF_DEBUG(PXRUSDMAYA_REGISTRY).Msg("Adding import job context %s UI.\n", jobContext.c_str());
169184

170-
// Note: the container for the plugin info is a set so it cannot be modified.
171-
// We need to copy the entry, modify the copy, remove the old entry and
172-
// insert the newly updated entry.
185+
TfToken key(jobContext);
186+
ContextInfo newInfo { key, {}, {}, {}, {}, {}, {}, uiFct };
187+
newInfo.importUICallback = uiFct;
173188

174-
ContextInfo updatedInfo(*iter);
175-
updatedInfo.importUICallback = uiFct;
176-
UsdMaya_RegistryHelper::AddUnloader([key]() { _jobContextReg.erase(key); }, fromPython);
177-
_jobContextReg.erase(iter);
178-
_jobContextReg.insert(updatedInfo);
189+
auto itFound = _jobContextReg.find(newInfo);
190+
if (itFound == _jobContextReg.end()) {
191+
_jobContextReg.insert(newInfo);
192+
UsdMaya_RegistryHelper::AddUnloader(
193+
[key]() { _jobContextReg.erase(ContextInfo { key }); }, fromPython);
194+
} else {
195+
// Note: the container for the plugin info is a set so it cannot be modified.
196+
// We need to copy the entry, modify the copy, remove the old entry and
197+
// insert the newly updated entry.
198+
199+
ContextInfo updatedInfo(*itFound);
200+
updatedInfo.importUICallback = uiFct;
201+
_jobContextReg.erase(itFound);
202+
_jobContextReg.insert(updatedInfo);
203+
}
179204
}
180205

181206
TfTokenVector UsdMayaJobContextRegistry::_ListJobContexts()

lib/mayaUsd/fileio/jobContextRegistry.h

-18
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,6 @@ class UsdMayaJobContextRegistry : public TfWeakBase
104104
TfToken importDescription;
105105
EnablerFn importEnablerCallback;
106106
UIFn importUICallback;
107-
108-
ContextInfo() = default;
109-
110-
ContextInfo(
111-
const TfToken& jc,
112-
const TfToken& nn,
113-
const TfToken& edsc,
114-
EnablerFn eef,
115-
const TfToken& idsc,
116-
EnablerFn ief)
117-
: jobContext(jc)
118-
, niceName(nn)
119-
, exportDescription(edsc)
120-
, exportEnablerCallback(eef)
121-
, importDescription(idsc)
122-
, importEnablerCallback(ief)
123-
{
124-
}
125107
};
126108

127109
/// Gets the conversion information associated with \p jobContext on export and import

test/lib/usd/plugin/nullApiExporter.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,6 @@ REGISTER_EXPORT_JOB_CONTEXT_FCT(
102102
return extraArgs;
103103
}
104104

105-
REGISTER_EXPORT_JOB_CONTEXT_FCT(
106-
Curly,
107-
"Curly's special",
108-
"Test coverage of error handling part deux")
109-
{
110-
VtDictionary extraArgs;
111-
// Incorrect type:
112-
extraArgs[UsdMayaJobExportArgsTokens->apiSchema] = VtValue(std::string("testApi"));
113-
return extraArgs;
114-
}
115-
116105
REGISTER_EXPORT_JOB_CONTEXT_UI_FCT(Curly)
117106
{
118107
VtDictionary forcedSettings;
@@ -129,6 +118,17 @@ REGISTER_EXPORT_JOB_CONTEXT_UI_FCT(Curly)
129118
return forcedSettings;
130119
}
131120

121+
REGISTER_EXPORT_JOB_CONTEXT_FCT(
122+
Curly,
123+
"Curly's special",
124+
"Test coverage of error handling part deux")
125+
{
126+
VtDictionary extraArgs;
127+
// Incorrect type:
128+
extraArgs[UsdMayaJobExportArgsTokens->apiSchema] = VtValue(std::string("testApi"));
129+
return extraArgs;
130+
}
131+
132132
REGISTER_EXPORT_JOB_CONTEXT_FCT(Moe, "Moe's special", "Test coverage of error handling part funf")
133133
{
134134
VtDictionary extraArgs;

0 commit comments

Comments
 (0)