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