1 | /* |
2 | Open Asset Import Library (assimp) |
3 | ---------------------------------------------------------------------- |
4 | |
5 | Copyright (c) 2006-2017, assimp team |
6 | |
7 | All rights reserved. |
8 | |
9 | Redistribution and use of this software in source and binary forms, |
10 | with or without modification, are permitted provided that the |
11 | following 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 | |
27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | |
39 | ---------------------------------------------------------------------- |
40 | */ |
41 | /// \file X3DImporter_Networking.cpp |
42 | /// \brief Parsing data from nodes of "Networking" set of X3D. |
43 | /// \date 2015-2016 |
44 | /// \author smal.root@gmail.com |
45 | |
46 | #ifndef ASSIMP_BUILD_NO_X3D_IMPORTER |
47 | |
48 | #include "X3DImporter.hpp" |
49 | #include "X3DImporter_Macro.hpp" |
50 | |
51 | // Header files, Assimp. |
52 | #include <assimp/DefaultIOSystem.h> |
53 | |
54 | //#include <regex> |
55 | |
56 | namespace Assimp |
57 | { |
58 | |
59 | //static std::regex pattern_parentDir(R"((^|/)[^/]+/../)"); |
60 | static std::string parentDir("/../" ); |
61 | |
62 | // <Inline |
63 | // DEF="" ID |
64 | // USE="" IDREF |
65 | // bboxCenter="0 0 0" SFVec3f [initializeOnly] |
66 | // bboxSize="-1 -1 -1" SFVec3f [initializeOnly] |
67 | // load="true" SFBool [inputOutput] |
68 | // url="" MFString [inputOutput] |
69 | // /> |
70 | void X3DImporter::ParseNode_Networking_Inline() |
71 | { |
72 | std::string def, use; |
73 | bool load = true; |
74 | std::list<std::string> url; |
75 | |
76 | MACRO_ATTRREAD_LOOPBEG; |
77 | MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use); |
78 | MACRO_ATTRREAD_CHECK_RET("load" , load, XML_ReadNode_GetAttrVal_AsBool); |
79 | MACRO_ATTRREAD_CHECK_REF("url" , url, XML_ReadNode_GetAttrVal_AsListS); |
80 | MACRO_ATTRREAD_LOOPEND; |
81 | |
82 | // if "USE" defined then find already defined element. |
83 | if(!use.empty()) |
84 | { |
85 | CX3DImporter_NodeElement* ne; |
86 | |
87 | MACRO_USE_CHECKANDAPPLY(def, use, ENET_Group, ne); |
88 | } |
89 | else |
90 | { |
91 | ParseHelper_Group_Begin(true);// create new grouping element and go deeper if node has children. |
92 | // at this place new group mode created and made current, so we can name it. |
93 | if(!def.empty()) NodeElement_Cur->ID = def; |
94 | |
95 | if(load && (url.size() > 0)) |
96 | { |
97 | std::string full_path = mpIOHandler->CurrentDirectory() + url.front(); |
98 | |
99 | //full_path = std::regex_replace(full_path, pattern_parentDir, "$1"); |
100 | for (std::string::size_type pos = full_path.find(parentDir); pos != std::string::npos; pos = full_path.find(parentDir, pos)) { |
101 | if (pos > 0) { |
102 | std::string::size_type pos2 = full_path.rfind('/', pos - 1); |
103 | if (pos2 != std::string::npos) { |
104 | full_path.erase(pos2, pos - pos2 + 3); |
105 | pos = pos2; |
106 | } |
107 | else { |
108 | full_path.erase(0, pos + 4); |
109 | pos = 0; |
110 | } |
111 | } |
112 | else { |
113 | pos += 3; |
114 | } |
115 | } |
116 | // Attribute "url" can contain list of strings. But we need only one - first. |
117 | std::string::size_type slashPos = full_path.find_last_of("\\/" ); |
118 | mpIOHandler->PushDirectory(slashPos == std::string::npos ? std::string() : full_path.substr(0, slashPos + 1)); |
119 | ParseFile(full_path, mpIOHandler); |
120 | mpIOHandler->PopDirectory(); |
121 | } |
122 | |
123 | // check for X3DMetadataObject childs. |
124 | if(!mReader->isEmptyElement()) ParseNode_Metadata(NodeElement_Cur, "Inline" ); |
125 | |
126 | // exit from node in that place |
127 | ParseHelper_Node_Exit(); |
128 | }// if(!use.empty()) else |
129 | } |
130 | |
131 | }// namespace Assimp |
132 | |
133 | #endif // !ASSIMP_BUILD_NO_X3D_IMPORTER |
134 | |