1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2017, assimp team
6
7All rights reserved.
8
9Redistribution and use of this software in source and binary forms,
10with or without modification, are permitted provided that the
11following conditions are met:
12
13* Redistributions of source code must retain the above
14 copyright notice, this list of conditions and the
15 following disclaimer.
16
17* Redistributions in binary form must reproduce the above
18 copyright notice, this list of conditions and the
19 following disclaimer in the documentation and/or other
20 materials provided with the distribution.
21
22* Neither the name of the assimp team, nor the names of its
23 contributors may be used to endorse or promote products
24 derived from this software without specific prior
25 written permission of the assimp team.
26
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39----------------------------------------------------------------------
40*/
41
42/** @file FBXDocumentUtil.cpp
43 * @brief Implementation of the FBX DOM utility functions declared in FBXDocumentUtil.h
44 */
45
46#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
47
48#include "FBXParser.h"
49#include "FBXDocument.h"
50#include "FBXUtil.h"
51#include "FBXDocumentUtil.h"
52#include "FBXProperties.h"
53
54
55namespace Assimp {
56namespace FBX {
57namespace Util {
58
59// ------------------------------------------------------------------------------------------------
60// signal DOM construction error, this is always unrecoverable. Throws DeadlyImportError.
61void DOMError(const std::string& message, const Token& token)
62{
63 throw DeadlyImportError(Util::AddTokenText("FBX-DOM",message,&token));
64}
65
66// ------------------------------------------------------------------------------------------------
67void DOMError(const std::string& message, const Element* element /*= NULL*/)
68{
69 if(element) {
70 DOMError(message,element->KeyToken());
71 }
72 throw DeadlyImportError("FBX-DOM " + message);
73}
74
75
76// ------------------------------------------------------------------------------------------------
77// print warning, do return
78void DOMWarning(const std::string& message, const Token& token)
79{
80 if(DefaultLogger::get()) {
81 DefaultLogger::get()->warn(Util::AddTokenText("FBX-DOM",message,&token));
82 }
83}
84
85// ------------------------------------------------------------------------------------------------
86void DOMWarning(const std::string& message, const Element* element /*= NULL*/)
87{
88 if(element) {
89 DOMWarning(message,element->KeyToken());
90 return;
91 }
92 if(DefaultLogger::get()) {
93 DefaultLogger::get()->warn("FBX-DOM: " + message);
94 }
95}
96
97
98// ------------------------------------------------------------------------------------------------
99// fetch a property table and the corresponding property template
100std::shared_ptr<const PropertyTable> GetPropertyTable(const Document& doc,
101 const std::string& templateName,
102 const Element &element,
103 const Scope& sc,
104 bool no_warn /*= false*/)
105{
106 const Element* const Properties70 = sc["Properties70"];
107 std::shared_ptr<const PropertyTable> templateProps = std::shared_ptr<const PropertyTable>(
108 static_cast<const PropertyTable*>(NULL));
109
110 if(templateName.length()) {
111 PropertyTemplateMap::const_iterator it = doc.Templates().find(templateName);
112 if(it != doc.Templates().end()) {
113 templateProps = (*it).second;
114 }
115 }
116
117 if(!Properties70) {
118 if(!no_warn) {
119 DOMWarning("property table (Properties70) not found",&element);
120 }
121 if(templateProps) {
122 return templateProps;
123 }
124 else {
125 return std::make_shared<const PropertyTable>();
126 }
127 }
128 return std::make_shared<const PropertyTable>(*Properties70,templateProps);
129}
130} // !Util
131} // !FBX
132} // !Assimp
133
134#endif
135