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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21// note: this was copied from the vrml1_separator class. the difference
22// between a separator and a group is that a group propagates its
23// current settings to its parent. While it would be possible to
24// implement the separator as a derived class, it is easy enough to
25// simply duplicate the code
26
27#include <iostream>
28#include <sstream>
29#include <wx/log.h>
30
31#include "vrml1_base.h"
32#include "vrml1_group.h"
34
35
36WRL1GROUP::WRL1GROUP( NAMEREGISTER* aDictionary ) : WRL1NODE( aDictionary )
37{
39}
40
41
42WRL1GROUP::WRL1GROUP( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
43 WRL1NODE( aDictionary )
44{
46 m_Parent = aParent;
47
48 if( nullptr != m_Parent )
49 m_Parent->AddChildNode( this );
50}
51
52
54{
55 wxLogTrace( traceVrmlPlugin,
56 wxT( " * [INFO] Destroying Group with %zu children, %zu references, and %zu "
57 "back pointers." ),
58 m_Children.size(), m_Refs.size(), m_BackPointers.size() );
59}
60
61
62bool WRL1GROUP::Read( WRLPROC& proc, WRL1BASE* aTopNode )
63{
64 if( nullptr == aTopNode )
65 {
66 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
67 " * [BUG] aTopNode is NULL" ),
68 __FILE__, __FUNCTION__, __LINE__ );
69
70 return false;
71 }
72
73 char tok = proc.Peek();
74
75 if( proc.eof() )
76 {
77 wxLogTrace( traceVrmlPlugin,
78 wxT( "%s:%s:%d\n"
79 " * [INFO] bad file format; unexpected eof %s." ),
80 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
81
82 return false;
83 }
84
85 if( '{' != tok )
86 {
87 wxLogTrace( traceVrmlPlugin,
88 wxT( "%s:%s:%d\n"
89 " * [INFO] bad file format; expecting '{' but got '%s' %s." ),
90 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
91
92 return false;
93 }
94
95 proc.Pop();
96
97 while( true )
98 {
99 if( proc.Peek() == '}' )
100 {
101 proc.Pop();
102 break;
103 }
104
105 if( !aTopNode->ReadNode( proc, this, nullptr ) )
106 {
107 wxLogTrace( traceVrmlPlugin,
108 wxT( "%s:%s:%d\n"
109 " * [INFO] bad file format; unexpected eof %s." ),
110 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
111
112 return false;
113 }
114
115 if( proc.Peek() == ',' )
116 proc.Pop();
117
118 } // while( true ) -- reading contents of Group{}
119
120 return true;
121}
122
123
125{
126 wxCHECK_MSG( m_Parent, nullptr, wxT( "Group has no parent." ) );
127
128 wxLogTrace( traceVrmlPlugin,
129 wxT( " * [INFO] Translating Group with %zu children, %zu references, %zu back "
130 "pointers, and %zu items." ),
131 m_Children.size(), m_Refs.size(), m_BackPointers.size(), m_Items.size() );
132
133 if( WRL1NODES::WRL1_BASE != m_Parent->GetNodeType() )
134 {
135 if( nullptr == sp )
136 {
139 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] bad model: no base data given." ) );
140
141 return nullptr;
142 }
143 }
144 else if( nullptr == sp )
145 {
146 m_current.Init();
147 sp = &m_current;
148 }
149
150 S3D::SGTYPES ptype = S3D::GetSGNodeType( aParent );
151
152 wxCHECK_MSG( nullptr == aParent && ptype == S3D::SGTYPE_TRANSFORM, nullptr,
153 wxString::Format(
154 wxT(" * [BUG] Group does not have a Transform parent (parent ID: %d" ),
155 ptype ) );
156
157 IFSG_TRANSFORM txNode( aParent );
158 bool hasContent = false;
159
160 std::list< WRL1NODE* >::iterator sI = m_Items.begin();
161 std::list< WRL1NODE* >::iterator eI = m_Items.end();
162
163 SGNODE* node = txNode.GetRawPtr();
164
165 while( sI != eI )
166 {
167 if( nullptr != (*sI)->TranslateToSG( node, sp ) )
168 hasContent = true;
169
170 ++sI;
171 }
172
173 if( !hasContent )
174 {
175 txNode.Destroy();
176 return nullptr;
177 }
178
179 return node;
180}
SGNODE * GetRawPtr(void) noexcept
Return the raw internal SGNODE pointer.
Definition ifsg_node.cpp:61
void Destroy(void)
Delete the object held by this wrapper.
Definition ifsg_node.cpp:51
The wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
The base class of all Scene Graph nodes.
Definition sg_node.h:71
Represent the top node of a VRML1 model.
Definition vrml1_base.h:42
bool ReadNode(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
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)
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override
virtual ~WRL1GROUP()
WRL1NODE(NAMEREGISTER *aDictionary)
WRL1NODES m_Type
Definition vrml1_node.h:223
std::list< WRL1NODE * > m_Items
Definition vrml1_node.h:229
WRL1STATUS m_current
Definition vrml1_node.h:232
std::list< WRL1NODE * > m_BackPointers
Definition vrml1_node.h:226
std::list< WRL1NODE * > m_Children
Definition vrml1_node.h:227
WRL1NODE * m_Parent
Definition vrml1_node.h:222
std::list< WRL1NODE * > m_Refs
Definition vrml1_node.h:228
void Pop(void)
Definition wrlproc.cpp:2031
char Peek(void)
Definition wrlproc.cpp:2003
bool eof(void)
Definition wrlproc.cpp:1950
std::string GetFilePosition() const
Definition wrlproc.cpp:1978
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition vrml.cpp:59
collects header files for all SG* wrappers and the API
SGLIB_API S3D::SGTYPES GetSGNodeType(SGNODE *aNode)
Definition ifsg_api.cpp:481
SGTYPES
Definition sg_types.h:32
@ SGTYPE_TRANSFORM
Definition sg_types.h:33
@ WRL1_GROUP
Definition wrltypes.h:62
@ WRL1_BASE
Definition wrltypes.h:53