KiCad PCB EDA Suite
Loading...
Searching...
No Matches
vrml1_separator.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#include <iostream>
26#include <sstream>
27#include <wx/log.h>
28
29#include "vrml1_base.h"
30#include "vrml1_separator.h"
32
33
34WRL1SEPARATOR::WRL1SEPARATOR( NAMEREGISTER* aDictionary ) : WRL1NODE( aDictionary )
35{
36 m_Type = WRL1NODES::WRL1_SEPARATOR;
37}
38
39
41 WRL1NODE( aDictionary )
42{
43 m_Type = WRL1NODES::WRL1_SEPARATOR;
44 m_Parent = aParent;
45
46 if( nullptr != m_Parent )
47 m_Parent->AddChildNode( this );
48}
49
50
52{
53 wxLogTrace( traceVrmlPlugin,
54 wxT( " * [INFO] Destroying Separator with %zu children %zu references, and %zu "
55 "back pointers." ),
56 m_Children.size(), m_Refs.size(), m_BackPointers.size() );
57}
58
59
60bool WRL1SEPARATOR::Read( WRLPROC& proc, WRL1BASE* aTopNode )
61{
62 wxCHECK_MSG( aTopNode, false, wxT( "Invalid top node." ) );
63
64 char tok = proc.Peek();
65
66 if( proc.eof() )
67 {
68 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
69 " * [INFO] bad file format; unexpected eof %s." ),
70 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
71
72 return false;
73 }
74
75 if( '{' != tok )
76 {
77 wxLogTrace( traceVrmlPlugin,
78 wxT( "%s:%s:%d\n"
79 " * [INFO] bad file format; expecting '{' but got '%s' %s." ),
80 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
81
82 return false;
83 }
84
85 proc.Pop();
86
87 while( true )
88 {
89 if( proc.Peek() == '}' )
90 {
91 proc.Pop();
92 break;
93 }
94
95 if( !aTopNode->ReadNode( proc, this, nullptr ) )
96 {
97 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
98 " * [INFO] bad file format; unexpected eof %s." ),
99 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
100
101 return false;
102 }
103
104 if( proc.Peek() == ',' )
105 proc.Pop();
106
107 } // while( true ) -- reading contents of Separator{}
108
109 return true;
110}
111
112
114{
115 wxCHECK_MSG( m_Parent, nullptr, wxT( "Separator has no parent." ) );
116
117 wxLogTrace( traceVrmlPlugin,
118 wxT( " * [INFO] Translating Separator with %zu children, %zu references, and "
119 "%zu back pointers (%zu total items)." ),
120 m_Children.size(), m_Refs.size(), m_BackPointers.size(), m_Items.size() );
121
122 if( sp != nullptr )
123 m_current = *sp;
124 else
125 m_current.Init();
126
127 S3D::SGTYPES ptype = S3D::GetSGNodeType( aParent );
128
129 wxCHECK_MSG( aParent && ( ptype == S3D::SGTYPE_TRANSFORM ), nullptr,
130 wxString::Format( wxT( "Separator does not have a Transform parent (parent "
131 "ID: %d)." ), ptype ) );
132
133 IFSG_TRANSFORM txNode( aParent );
134 bool hasContent = false;
135
136 std::list< WRL1NODE* >::iterator sI = m_Items.begin();
137 std::list< WRL1NODE* >::iterator eI = m_Items.end();
138
139 SGNODE* node = txNode.GetRawPtr();
140
141 while( sI != eI )
142 {
143 if( nullptr != (*sI)->TranslateToSG( node, &m_current ) )
144 hasContent = true;
145
146 ++sI;
147 }
148
149 if( !hasContent )
150 {
151 txNode.Destroy();
152 return nullptr;
153 }
154
155 return node;
156}
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
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
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override
virtual ~WRL1SEPARATOR()
WRL1SEPARATOR(NAMEREGISTER *aDictionary)
SGNODE * TranslateToSG(SGNODE *aParent, WRL1STATUS *sp) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
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