~popey/+junk/usd

« back to all changes in this revision

Viewing changes to USD/third_party/maya/lib/usdMaya/primWriterRegistry.cpp

  • Committer: Alan Pope
  • Date: 2016-09-29 12:05:28 UTC
  • Revision ID: alan@popey.com-20160929120528-32j3uk1x0dgaorip
Initial attempt to snap

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "usdMaya/primWriterRegistry.h"
 
25
#include "usdMaya/debugCodes.h"
 
26
#include "usdMaya/registryHelper.h"
 
27
 
 
28
#include "pxr/base/tf/staticTokens.h"
 
29
#include "pxr/base/tf/stl.h"
 
30
 
 
31
#include <boost/assign.hpp>
 
32
 
 
33
TF_DEFINE_PRIVATE_TOKENS(_tokens,
 
34
    (UsdMaya)
 
35
        (PrimWriter)
 
36
);
 
37
 
 
38
typedef std::map<std::string, PxrUsdMayaPrimWriterRegistry::WriterFn> _Registry;
 
39
static _Registry _reg;
 
40
 
 
41
/* static */
 
42
void 
 
43
PxrUsdMayaPrimWriterRegistry::Register(
 
44
        const std::string& mayaTypeName,
 
45
        PxrUsdMayaPrimWriterRegistry::WriterFn fn)
 
46
{
 
47
    TF_DEBUG(PXRUSDMAYA_REGISTRY).Msg(
 
48
            "Registering UsdMayaPrimWriter for maya type %s.\n", mayaTypeName.c_str());
 
49
 
 
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;
 
55
    }
 
56
}
 
57
 
 
58
/* static */
 
59
PxrUsdMayaPrimWriterRegistry::WriterFn
 
60
PxrUsdMayaPrimWriterRegistry::Find(
 
61
        const std::string& mayaTypeName)
 
62
{
 
63
    TfRegistryManager::GetInstance().SubscribeTo<PxrUsdMayaPrimWriterRegistry>();
 
64
 
 
65
    // unfortunately, usdTypeName is diff from the tfTypeName which we use to
 
66
    // register.  do the conversion here.
 
67
    WriterFn ret = NULL;
 
68
    if (TfMapLookup(_reg, mayaTypeName, &ret)) {
 
69
        return ret;
 
70
    }
 
71
 
 
72
    static std::vector<TfToken> SCOPE = boost::assign::list_of
 
73
        (_tokens->UsdMaya)(_tokens->PrimWriter);
 
74
    PxrUsdMaya_RegistryHelper::FindAndLoadMayaPlug(SCOPE, mayaTypeName);
 
75
 
 
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;
 
83
    }
 
84
    return ret;
 
85
}
 
86