KiCad PCB EDA Suite
Loading...
Searching...
No Matches
vrml1_group.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015-2016 Cirilo Bernardo <[email protected]>
5 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25// note: this was copied from the vrml1_separator class. the difference
26// between a separator and a group is that a group propagates its
27// current settings to its parent. While it would be possible to
28// implement the separator as a derived class, it is easy enough to
29// simply duplicate the code
30
31#include <iostream>
32#include <sstream>
33#include <wx/log.h>
34
35#include "vrml1_base.h"
36#include "vrml1_group.h"
38
39
40WRL1GROUP::WRL1GROUP( NAMEREGISTER* aDictionary ) : WRL1NODE( aDictionary )
41{
42 m_Type = WRL1NODES::WRL1_GROUP;
43}
44
45
46WRL1GROUP::WRL1GROUP( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
47 WRL1NODE( aDictionary )
48{
49 m_Type = WRL1NODES::WRL1_GROUP;
50 m_Parent = aParent;
51
52 if( nullptr != m_Parent )
53 m_Parent->AddChildNode( this );
54}
55
56
58{
59 wxLogTrace( traceVrmlPlugin,
60 wxT( " * [INFO] Destroying Group with %zu children, %zu references, and %zu "
61 "back pointers." ),
62 m_Children.size(), m_Refs.size(), m_BackPointers.size() );
63}
64
65
66bool WRL1GROUP::Read( WRLPROC& proc, WRL1BASE* aTopNode )
67{
68 if( nullptr == aTopNode )
69 {
70 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
71 " * [BUG] aTopNode is NULL" ),
72 __FILE__, __FUNCTION__, __LINE__ );
73
74 return false;
75 }
76
77 char tok = proc.Peek();
78
79 if( proc.eof() )
80 {
81 wxLogTrace( traceVrmlPlugin,
82 wxT( "%s:%s:%d\n"
83 " * [INFO] bad file format; unexpected eof %s." ),
84 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
85
86 return false;
87 }
88
89 if( '{' != tok )
90 {
91 wxLogTrace( traceVrmlPlugin,
92 wxT( "%s:%s:%d\n"
93 " * [INFO] bad file format; expecting '{' but got '%s' %s." ),
94 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
95
96 return false;
97 }
98
99 proc.Pop();
100
101 while( true )
102 {
103 if( proc.Peek() == '}' )
104 {
105 proc.Pop();
106 break;
107 }
108
109 if( !aTopNode->ReadNode( proc, this, nullptr ) )
110 {
111 wxLogTrace( traceVrmlPlugin,
112 wxT( "%s:%s:%d\n"
113 " * [INFO] bad file format; unexpected eof %s." ),
114 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
115
116 return false;
117 }
118
119 if( proc.Peek() == ',' )
120 proc.Pop();
121
122 } // while( true ) -- reading contents of Group{}
123
124 return true;
125}
126
127
129{
130 wxCHECK_MSG( m_Parent, nullptr, wxT( "Group has no parent." ) );
131
132 wxLogTrace( traceVrmlPlugin,
133 wxT( " * [INFO] Translating Group with %zu children, %zu references, %zu back "
134 "pointers, and %zu items." ),
135 m_Children.size(), m_Refs.size(), m_BackPointers.size(), m_Items.size() );
136
137 if( WRL1NODES::WRL1_BASE != m_Parent->GetNodeType() )
138 {
139 if( nullptr == sp )
140 {
143 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] bad model: no base data given." ) );
144
145 return nullptr;
146 }
147 }
148 else if( nullptr == sp )
149 {
150 m_current.Init();
151 sp = &m_current;
152 }
153
154 S3D::SGTYPES ptype = S3D::GetSGNodeType( aParent );
155
156 wxCHECK_MSG( nullptr == aParent && ptype == S3D::SGTYPE_TRANSFORM, nullptr,
157 wxString::Format(
158 wxT(" * [BUG] Group does not have a Transform parent (parent ID: %d" ),
159 ptype ) );
160
161 IFSG_TRANSFORM txNode( aParent );
162 bool hasContent = false;
163
164 std::list< WRL1NODE* >::iterator sI = m_Items.begin();
165 std::list< WRL1NODE* >::iterator eI = m_Items.end();
166
167 SGNODE* node = txNode.GetRawPtr();
168
169 while( sI != eI )
170 {
171 if( nullptr != (*sI)->TranslateToSG( node, sp ) )
172 hasContent = true;
173
174 ++sI;
175 }
176
177 if( !hasContent )
178 {
179 txNode.Destroy();
180 return nullptr;
181 }
182
183 return node;
184}
SGNODE * GetRawPtr(void) noexcept
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:65
void Destroy(void)
Function Destroy deletes the object held by this wrapper.
Definition: ifsg_node.cpp:55
IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
The base class of all Scene Graph nodes.
Definition: sg_node.h:75
Represent the top node of a VRML1 model.
Definition: vrml1_base.h:46
bool ReadNode(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
Definition: vrml1_base.cpp:200
SGNODE * TranslateToSG(SGNODE *aParent, WRL1STATUS *sp) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
WRL1GROUP(NAMEREGISTER *aDictionary)
Definition: vrml1_group.cpp:40
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override
Definition: vrml1_group.cpp:66
virtual ~WRL1GROUP()
Definition: vrml1_group.cpp:57
The base class of all VRML1 nodes.
Definition: vrml1_node.h:117
WRL1NODES m_Type
Definition: vrml1_node.h:227
std::list< WRL1NODE * > m_Items
Definition: vrml1_node.h:233
WRL1STATUS m_current
Definition: vrml1_node.h:236
virtual bool AddChildNode(WRL1NODE *aNode)
Definition: vrml1_node.cpp:376
std::list< WRL1NODE * > m_BackPointers
Definition: vrml1_node.h:230
std::list< WRL1NODE * > m_Children
Definition: vrml1_node.h:231
WRL1NODE * m_Parent
Definition: vrml1_node.h:226
std::list< WRL1NODE * > m_Refs
Definition: vrml1_node.h:232
WRL1NODES GetNodeType(void) const
Return the type of this node instance.
Definition: vrml1_node.cpp:254
void Pop(void)
Definition: wrlproc.cpp:2035
char Peek(void)
Definition: wrlproc.cpp:2007
bool eof(void)
Definition: wrlproc.cpp:1954
std::string GetFilePosition() const
Definition: wrlproc.cpp:1982
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63
collects header files for all SG* wrappers and the API
SGLIB_API S3D::SGTYPES GetSGNodeType(SGNODE *aNode)
Definition: ifsg_api.cpp:485
SGTYPES
Definition: sg_types.h:35
@ SGTYPE_TRANSFORM
Definition: sg_types.h:36
void Init()
Definition: vrml1_node.h:74