2
// Copyright 2016 Pixar
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:
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.
14
// You may obtain a copy of the Apache License at
16
// http://www.apache.org/licenses/LICENSE-2.0
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.
24
#include "usdMaya/primWriterRegistry.h"
25
#include "usdMaya/debugCodes.h"
26
#include "usdMaya/registryHelper.h"
28
#include "pxr/base/tf/staticTokens.h"
29
#include "pxr/base/tf/stl.h"
31
#include <boost/assign.hpp>
33
TF_DEFINE_PRIVATE_TOKENS(_tokens,
38
typedef std::map<std::string, PxrUsdMayaPrimWriterRegistry::WriterFn> _Registry;
39
static _Registry _reg;
43
PxrUsdMayaPrimWriterRegistry::Register(
44
const std::string& mayaTypeName,
45
PxrUsdMayaPrimWriterRegistry::WriterFn fn)
47
TF_DEBUG(PXRUSDMAYA_REGISTRY).Msg(
48
"Registering UsdMayaPrimWriter for maya type %s.\n", mayaTypeName.c_str());
50
std::pair< _Registry::iterator, bool> insertStatus =
51
_reg.insert(std::make_pair(mayaTypeName, fn));
52
if (not insertStatus.second) {
53
TF_CODING_ERROR("Multiple writer for type %s", mayaTypeName.c_str());
54
insertStatus.first->second = fn;
59
PxrUsdMayaPrimWriterRegistry::WriterFn
60
PxrUsdMayaPrimWriterRegistry::Find(
61
const std::string& mayaTypeName)
63
TfRegistryManager::GetInstance().SubscribeTo<PxrUsdMayaPrimWriterRegistry>();
65
// unfortunately, usdTypeName is diff from the tfTypeName which we use to
66
// register. do the conversion here.
68
if (TfMapLookup(_reg, mayaTypeName, &ret)) {
72
static std::vector<TfToken> SCOPE = boost::assign::list_of
73
(_tokens->UsdMaya)(_tokens->PrimWriter);
74
PxrUsdMaya_RegistryHelper::FindAndLoadMayaPlug(SCOPE, mayaTypeName);
76
// ideally something just registered itself. if not, we at least put it in
77
// the registry in case we encounter it again.
78
if (not TfMapLookup(_reg, mayaTypeName, &ret)) {
79
TF_DEBUG(PXRUSDMAYA_REGISTRY).Msg(
80
"No usdMaya writer plugin for maya type %s. No maya plugin found.\n",
81
mayaTypeName.c_str());
82
_reg[mayaTypeName] = NULL;