KiCad PCB EDA Suite
X3DPARSER Class Reference

#include <x3d.h>

Public Member Functions

SCENEGRAPHLoad (const wxString &aFileName)
 

Private Member Functions

bool getGroupingNodes (wxXmlNode *aNode, std::vector< wxXmlNode * > &aResult)
 Retrieve all permissible top-level nodes in an X3D/VRML file. More...
 

Detailed Description

Definition at line 36 of file x3d.h.

Member Function Documentation

◆ getGroupingNodes()

bool X3DPARSER::getGroupingNodes ( wxXmlNode *  aNode,
std::vector< wxXmlNode * > &  aResult 
)
private

Retrieve all permissible top-level nodes in an X3D/VRML file.

Definition at line 92 of file x3d.cpp.

93 {
94  aResult.clear();
95  wxXmlNode* scene = nullptr;
96 
97  for( wxXmlNode* child = aNode->GetChildren(); child != nullptr; child = child->GetNext() )
98  {
99  if( child->GetName() == "Scene" )
100  {
101  scene = child;
102  break;
103  }
104  }
105 
106  if( nullptr == scene )
107  return false;
108 
109  for( wxXmlNode* child = scene->GetChildren(); child != nullptr; child = child->GetNext() )
110  {
111  const wxString& name = child->GetName();
112 
113  if( name == "Transform" || name == "Switch" || name == "Group" )
114  aResult.push_back( child );
115  }
116 
117  if( aResult.empty() )
118  return false;
119 
120  return true;
121 }
const char * name
Definition: DXF_plotter.cpp:56

References name.

Referenced by Load().

◆ Load()

SCENEGRAPH * X3DPARSER::Load ( const wxString &  aFileName)

Definition at line 46 of file x3d.cpp.

47 {
48  wxFFileInputStream stream( aFileName );
49  wxXmlDocument doc;
50 
51  if( !stream.IsOk() || !doc.Load( stream ) )
52  return nullptr;
53 
54  if( doc.GetRoot()->GetName() != wxT( "X3D" ) )
55  return nullptr;
56 
57  NODE_LIST children; // VRML Grouping Nodes at top level
58 
59  if( !getGroupingNodes( doc.GetRoot(), children ) )
60  return nullptr;
61 
62  X3D_DICT dictionary; // dictionary for USE/DEF implementation
63  X3DNODE* topNode = new X3DTRANSFORM;
64  bool ok = false;
65 
66  for( NODE_LIST::iterator node_it = children.begin(); node_it != children.end(); ++node_it )
67  {
68  wxXmlNode* node = *node_it;
69  wxString name = node->GetName();
70 
71  if( name == "Transform" || name == "Group" )
72  {
73  // Read a Transform / Group
74  ok |= X3D::ReadTransform( node, topNode, dictionary );
75  }
76  else if( name == "Switch" )
77  {
78  ok |= X3D::ReadSwitch( node, topNode, dictionary );
79  }
80  }
81 
82  SCENEGRAPH* sp = nullptr;
83 
84  if( ok )
85  sp = (SCENEGRAPH*) topNode->TranslateToSG( nullptr );
86 
87  delete topNode;
88  return sp;
89 }
bool getGroupingNodes(wxXmlNode *aNode, std::vector< wxXmlNode * > &aResult)
Retrieve all permissible top-level nodes in an X3D/VRML file.
Definition: x3d.cpp:92
bool ReadTransform(wxXmlNode *aNode, X3DNODE *aParent, X3D_DICT &aDict)
Definition: x3d_ops.cpp:34
The base class of all X3D nodes.
Definition: x3d_base.h:74
virtual SGNODE * TranslateToSG(SGNODE *aParent)=0
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
std::vector< wxXmlNode * > NODE_LIST
Definition: x3d_base.h:42
const char * name
Definition: DXF_plotter.cpp:56
bool ReadSwitch(wxXmlNode *aNode, X3DNODE *aParent, X3D_DICT &aDict)
Definition: x3d_ops.cpp:72
Define the basic data set required to represent a 3D model.
Definition: scenegraph.h:44

References getGroupingNodes(), name, X3D::ReadSwitch(), X3D::ReadTransform(), and X3DNODE::TranslateToSG().

Referenced by LoadX3D().


The documentation for this class was generated from the following files: