KiCad PCB EDA Suite
S3D Namespace Reference

Classes

struct  MATLIST
 

Enumerations

enum  SGTYPES {
  SGTYPE_TRANSFORM = 0, SGTYPE_APPEARANCE, SGTYPE_COLORS, SGTYPE_COLORINDEX,
  SGTYPE_FACESET, SGTYPE_COORDS, SGTYPE_COORDINDEX, SGTYPE_NORMALS,
  SGTYPE_SHAPE, SGTYPE_END
}
 

Functions

bool Select3DModel (wxWindow *aParent, S3D_CACHE *aCache, wxString &prevModelSelectDir, int &prevModelWildcard, FP_3DMODEL *aModel)
 
bool Configure3DPaths (wxWindow *aParent, FILENAME_RESOLVER *aResolver)
 
bool degenerate (glm::dvec3 *pts) noexcept
 
bool CalcTriangleNormals (std::vector< SGPOINT > coords, std::vector< int > &index, std::vector< SGVECTOR > &norms)
 
void FormatFloat (std::string &result, double value)
 
void FormatOrientation (std::string &result, const SGVECTOR &axis, double rotation)
 
void FormatPoint (std::string &result, const SGPOINT &point)
 
void FormatVector (std::string &result, const SGVECTOR &aVector)
 
void FormatColor (std::string &result, const SGCOLOR &aColor)
 
bool WritePoint (std::ostream &aFile, const SGPOINT &aPoint)
 
bool WriteVector (std::ostream &aFile, const SGVECTOR &aVector)
 
bool WriteColor (std::ostream &aFile, const SGCOLOR &aColor)
 
S3D::SGTYPES ReadTag (std::istream &aFile, std::string &aName)
 Read the text tag of a binary cache file which is the NodeTag and unique ID number combined. More...
 
bool ReadPoint (std::istream &aFile, SGPOINT &aPoint)
 
bool ReadVector (std::istream &aFile, SGVECTOR &aVector)
 
bool ReadColor (std::istream &aFile, SGCOLOR &aColor)
 
char const * GetNodeTypeName (S3D::SGTYPES aType) noexcept
 Return the name of the given type of node. More...
 
bool GetMatIndex (MATLIST &aList, SGNODE *aNode, int &aIndex)
 
void INIT_SMATERIAL (SMATERIAL &aMaterial)
 
void INIT_SMESH (SMESH &aMesh) noexcept
 
void INIT_S3DMODEL (S3DMODEL &aModel) noexcept
 
void FREE_SMESH (SMESH &aMesh) noexcept
 
void FREE_S3DMODEL (S3DMODEL &aModel)
 
SGLIB_API void GetLibVersion (unsigned char *Major, unsigned char *Minor, unsigned char *Patch, unsigned char *Revision) noexcept
 Function GetLibVersion retrieves version information of the kicad_3dsg library. More...
 
SGLIB_API S3D::SGTYPES GetSGNodeType (SGNODE *aNode)
 
SGLIB_API SGNODEGetSGNodeParent (SGNODE *aNode)
 
SGLIB_API bool AddSGNodeRef (SGNODE *aParent, SGNODE *aChild)
 
SGLIB_API bool AddSGNodeChild (SGNODE *aParent, SGNODE *aChild)
 
SGLIB_API void AssociateSGNodeWrapper (SGNODE *aObject, SGNODE **aRefPtr)
 
SGLIB_API SGVECTOR CalcTriNorm (const SGPOINT &p1, const SGPOINT &p2, const SGPOINT &p3)
 Function CalcTriNorm returns the normal vector of a triangle described by vertices p1, p2, p3. More...
 
SGLIB_API bool WriteCache (const char *aFileName, bool overwrite, SGNODE *aNode, const char *aPluginInfo)
 Function WriteCache writes the SGNODE tree to a binary cache file. More...
 
SGLIB_API SGNODEReadCache (const char *aFileName, void *aPluginMgr, bool(*aTagCheck)(const char *, void *))
 Function ReadCache reads a binary cache file and creates an SGNODE tree. More...
 
SGLIB_API bool WriteVRML (const char *filename, bool overwrite, SGNODE *aTopNode, bool reuse, bool renameNodes)
 Function WriteVRML writes out the given node and its subnodes to a VRML2 file. More...
 
SGLIB_API void ResetNodeIndex (SGNODE *aNode)
 Function ResetNodeIndex resets the global SG* class indices. More...
 
SGLIB_API void RenameNodes (SGNODE *aNode)
 Function RenameNodes renames a node and all children nodes based on the current values of the global SG* class indices. More...
 
SGLIB_API void DestroyNode (SGNODE *aNode) noexcept
 Function DestroyNode deletes the given SG* class node. More...
 
SGLIB_API S3DMODELGetModel (SCENEGRAPH *aNode)
 Function GetModel creates an S3DMODEL representation of aNode (raw data, no transforms) More...
 
SGLIB_API void Destroy3DModel (S3DMODEL **aModel)
 Function Destroy3DModel frees memory used by an S3DMODEL structure and sets the pointer to the structure to NULL. More...
 
SGLIB_API void Free3DModel (S3DMODEL &aModel)
 Function Free3DModel frees memory used internally by an S3DMODEL structure. More...
 
SGLIB_API void Free3DMesh (SMESH &aMesh)
 Function Free3DMesh frees memory used internally by an SMESH structure. More...
 
SGLIB_API S3DMODELNew3DModel (void)
 Function New3DModel creates and initializes an S3DMODEL struct. More...
 
SGLIB_API void Init3DMaterial (SMATERIAL &aMat)
 Function Init3DMaterial initializes an SMATERIAL struct. More...
 
SGLIB_API void Init3DMesh (SMESH &aMesh)
 Function Init3DMesh creates and initializes an SMESH struct. More...
 

Enumeration Type Documentation

◆ SGTYPES

Enumerator
SGTYPE_TRANSFORM 
SGTYPE_APPEARANCE 
SGTYPE_COLORS 
SGTYPE_COLORINDEX 
SGTYPE_FACESET 
SGTYPE_COORDS 
SGTYPE_COORDINDEX 
SGTYPE_NORMALS 
SGTYPE_SHAPE 
SGTYPE_END 

Definition at line 34 of file sg_types.h.

Function Documentation

◆ AddSGNodeChild()

bool S3D::AddSGNodeChild ( SGNODE aParent,
SGNODE aChild 
)

◆ AddSGNodeRef()

bool S3D::AddSGNodeRef ( SGNODE aParent,
SGNODE aChild 
)

◆ AssociateSGNodeWrapper()

void S3D::AssociateSGNodeWrapper ( SGNODE aObject,
SGNODE **  aRefPtr 
)

Definition at line 519 of file ifsg_api.cpp.

520 {
521  if( nullptr == aObject || nullptr == aRefPtr || aObject != *aRefPtr )
522  return;
523 
524  aObject->AssociateWrapper( aRefPtr );
525 }
void AssociateWrapper(SGNODE **aWrapperRef) noexcept
Associate this object with a handle to itself.
Definition: sg_node.cpp:205

References SGNODE::AssociateWrapper().

◆ CalcTriangleNormals()

bool S3D::CalcTriangleNormals ( std::vector< SGPOINT coords,
std::vector< int > &  index,
std::vector< SGVECTOR > &  norms 
)

Definition at line 352 of file sg_helpers.cpp.

354 {
355  size_t vsize = coords.size();
356 
357  if( vsize < 3 )
358  {
359  wxLogTrace( MASK_3D_SG,
360  "%s:%s:%d * [INFO] invalid vertex set (fewer than 3 vertices)",
361  __FILE__, __FUNCTION__, __LINE__ );
362 
363  return false;
364  }
365 
366  size_t isize = index.size();
367 
368  if( 0 != isize % 3 || index.empty() )
369  {
370  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] invalid index set (not multiple of 3)",
371  __FILE__, __FUNCTION__, __LINE__ );
372 
373  return false;
374  }
375 
376  if( !norms.empty() )
377  {
378  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] normals set is not empty",
379  __FILE__, __FUNCTION__, __LINE__ );
380 
381  return false;
382  }
383 
384  std::map< int, std::list< glm::dvec3 > >vmap;
385 
386  int p1, p2, p3;
387 
388  // create the map of indices to facet sets
389  for( size_t i = 0; i < isize; )
390  {
391  p1 = index[i++];
392  p2 = index[i++];
393  p3 = index[i++];
394 
395  if( p1 < 0 || p1 >= (int)vsize || p2 < 0 || p2 >= (int)vsize || p3 < 0 || p3 >= (int)vsize )
396  {
397 #ifdef DEBUG
398  std::ostringstream ostr;
399  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
400  ostr << " * [INFO] invalid index set; index out of bounds";
401  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
402 #endif
403 
404  return false;
405  }
406 
407  glm::dvec3 tri;
408  glm::dvec3 trip[3];
409  trip[0] = glm::dvec3( coords[p1].x, coords[p1].y, coords[p1].z );
410  trip[1] = glm::dvec3( coords[p2].x, coords[p2].y, coords[p2].z );
411  trip[2] = glm::dvec3( coords[p3].x, coords[p3].y, coords[p3].z );
412  calcTriad( trip, tri );
413 
414  std::map< int, std::list< glm::dvec3 > >::iterator ip = vmap.find( p1 );
415 
416  if( ip != vmap.end() )
417  {
418  ip->second.push_back( tri );
419  }
420  else
421  {
422  vmap.insert( std::pair < int, std::list < glm::dvec3 > >
423  ( p1, std::list < glm::dvec3 >( 1, tri ) ) );
424  }
425 
426  ip = vmap.find( p2 );
427 
428  if( ip != vmap.end() )
429  {
430  ip->second.push_back( tri );
431  }
432  else
433  {
434  vmap.insert( std::pair < int, std::list < glm::dvec3 > >
435  ( p2, std::list < glm::dvec3 >( 1, tri ) ) );
436  }
437 
438  ip = vmap.find( p3 );
439 
440  if( ip != vmap.end() )
441  {
442  ip->second.push_back( tri );
443  }
444  else
445  {
446  vmap.insert( std::pair < int, std::list < glm::dvec3 > >
447  ( p3, std::list < glm::dvec3 >( 1, tri ) ) );
448  }
449  }
450 
451  std::map< int, std::list< glm::dvec3 > >::iterator sM = vmap.begin();
452  std::map< int, std::list< glm::dvec3 > >::iterator eM = vmap.end();
453  size_t idx = 0;
454 
455  while( sM != eM )
456  {
457  size_t item = sM->first;
458 
459  // assign any skipped coordinates a normal of (0,0,1)
460  while( item > idx )
461  {
462  norms.emplace_back( 0, 0, 1 );
463  ++idx;
464  }
465 
466  std::list< glm::dvec3 >::iterator sT = sM->second.begin();
467  std::list< glm::dvec3 >::iterator eT = sM->second.end();
468  glm::dvec3 norm( 0.0, 0.0, 0.0 );
469 
470  while( sT != eT )
471  {
472  norm += *sT;
473  ++sT;
474  }
475 
476  norms.emplace_back( norm.x, norm.y, norm.z );
477 
478  ++idx;
479  ++sM;
480  }
481 
482  if( norms.size() != coords.size() )
483  {
484  wxLogTrace( MASK_3D_SG,
485  "%s:%s:%d * [BUG] number of normals does not equal number of vertices",
486  __FILE__, __FUNCTION__, __LINE__ );
487 
488  return false;
489  }
490 
491  return true;
492 }
static void calcTriad(glm::dvec3 *pts, glm::dvec3 &tri)
Definition: sg_helpers.cpp:338

References calcTriad().

Referenced by SGCOORDS::CalcNormals().

◆ CalcTriNorm()

SGVECTOR S3D::CalcTriNorm ( const SGPOINT p1,
const SGPOINT p2,
const SGPOINT p3 
)

Function CalcTriNorm returns the normal vector of a triangle described by vertices p1, p2, p3.

Definition at line 462 of file ifsg_api.cpp.

463 {
464  glm::dvec3 tri = glm::dvec3( 0.0, 0.0, 0.0 );
465  glm::dvec3 pts[3];
466 
467  pts[0] = glm::dvec3( p1.x, p1.y, p1.z );
468  pts[1] = glm::dvec3( p2.x, p2.y, p2.z );
469  pts[2] = glm::dvec3( p3.x, p3.y, p3.z );
470 
471  // degenerate points are given a default 0, 0, 1 normal
472  if( S3D::degenerate( pts ) )
473  return SGVECTOR( 0.0, 0.0, 1.0 );
474 
475  // normal
476  tri = glm::cross( pts[1] - pts[0], pts[2] - pts[0] );
477  glm::normalize( tri );
478 
479  return SGVECTOR( tri.x, tri.y, tri.z );
480 }
double x
Definition: sg_base.h:70
bool degenerate(glm::dvec3 *pts) noexcept
Definition: sg_helpers.cpp:309
double y
Definition: sg_base.h:71
double z
Definition: sg_base.h:72

References degenerate(), SGPOINT::x, SGPOINT::y, and SGPOINT::z.

Referenced by EXPORTER_PCB_VRML::create_vrml_shell(), and vrmlToSG().

◆ Configure3DPaths()

bool S3D::Configure3DPaths ( wxWindow *  aParent,
FILENAME_RESOLVER aResolver 
)

Definition at line 46 of file 3d_cache_dialogs.cpp.

47 {
48  DIALOG_CONFIGURE_PATHS dlg( aParent, aResolver );
49 
50  // Use QuasiModal so that HTML help window will work
51  return( dlg.ShowQuasiModal() == wxID_OK );
52 }

References DIALOG_SHIM::ShowQuasiModal().

Referenced by DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::Cfg3DPath(), DIALOG_FOOTPRINT_PROPERTIES::Cfg3DPath(), and DLG_SELECT_3DMODEL::Cfg3DPaths().

◆ degenerate()

bool S3D::degenerate ( glm::dvec3 *  pts)
noexcept

Definition at line 309 of file sg_helpers.cpp.

310 {
311  double dx, dy, dz;
312 
313  dx = pts[1].x - pts[0].x;
314  dy = pts[1].y - pts[0].y;
315  dz = pts[1].z - pts[0].z;
316 
317  if( ( dx*dx + dy*dy + dz*dz ) < 1e-15 )
318  return true;
319 
320  dx = pts[2].x - pts[0].x;
321  dy = pts[2].y - pts[0].y;
322  dz = pts[2].z - pts[0].z;
323 
324  if( ( dx*dx + dy*dy + dz*dz ) < 1e-15 )
325  return true;
326 
327  dx = pts[2].x - pts[1].x;
328  dy = pts[2].y - pts[1].y;
329  dz = pts[2].z - pts[1].z;
330 
331  if( ( dx*dx + dy*dy + dz*dz ) < 1e-15 )
332  return true;
333 
334  return false;
335 }

Referenced by calcTriad(), and CalcTriNorm().

◆ Destroy3DModel()

void S3D::Destroy3DModel ( S3DMODEL **  aModel)

Function Destroy3DModel frees memory used by an S3DMODEL structure and sets the pointer to the structure to NULL.

Definition at line 401 of file ifsg_api.cpp.

402 {
403  if( nullptr == aModel || nullptr == *aModel )
404  return;
405 
406  S3DMODEL* m = *aModel;
407  S3D::FREE_S3DMODEL( *m );
408  delete m;
409  *aModel = nullptr;
410 }
void FREE_S3DMODEL(S3DMODEL &aModel)
Definition: sg_node.cpp:324
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90

References FREE_S3DMODEL().

Referenced by S3D_CACHE::load(), and S3D_CACHE_ENTRY::~S3D_CACHE_ENTRY().

◆ DestroyNode()

void S3D::DestroyNode ( SGNODE aNode)
noexcept

Function DestroyNode deletes the given SG* class node.

This function makes it possible to safely delete an SG* node without associating the node with its corresponding IFSG* wrapper.

Definition at line 148 of file ifsg_api.cpp.

149 {
150  wxCHECK( aNode, /* void */ );
151 
152  delete aNode;
153 }

Referenced by S3D_CACHE::load(), S3D_CACHE::loadCacheData(), WRL1MATERIAL::Reclaim(), DATA::~DATA(), EXPORTER_PCB_VRML::~EXPORTER_PCB_VRML(), WRL1MATERIAL::~WRL1MATERIAL(), and WRL2BASE::~WRL2BASE().

◆ FormatColor()

void S3D::FormatColor ( std::string &  result,
const SGCOLOR aColor 
)

Definition at line 135 of file sg_helpers.cpp.

136 {
137  float R, G, B;
138  aColor.GetColor( R, G, B );
139  FormatFloat( result, R );
140 
141  std::string tmp;
142  FormatFloat( tmp, G );
143  result.append( " " );
144  result.append( tmp );
145 
146  FormatFloat( tmp, B );
147  result.append( " " );
148  result.append( tmp );
149 }
#define G(x, y, z)
Definition: md5_hash.cpp:16
void GetColor(float &aRedVal, float &aGreenVal, float &aBlueVal) const noexcept
Definition: sg_base.cpp:59
void FormatFloat(std::string &result, double value)
Definition: sg_helpers.cpp:37

References FormatFloat(), G, and SGCOLOR::GetColor().

Referenced by SGCOLORS::WriteVRML().

◆ FormatFloat()

void S3D::FormatFloat ( std::string &  result,
double  value 
)

Definition at line 37 of file sg_helpers.cpp.

38 {
39  if( value < 1e-8 && value > -1e-8 )
40  {
41  result = "0";
42  return;
43  }
44 
45  // note: many VRML implementations use float so we use the max.
46  // precision here of 8 digits.
47  std::ostringstream out;
48  out << std::setprecision( 8 ) << value;
49 
50  result = out.str();
51 
52  size_t p = result.find( '.' );
53 
54  // trim trailing 0 if appropriate
55  if( std::string::npos == p )
56  return;
57 
58  p = result.find_first_of( "eE" );
59 
60  if( std::string::npos == p )
61  {
62  while( '0' == *( result.rbegin() ) )
63  result.erase( result.size() - 1 );
64 
65  return;
66  }
67 
68  if( '0' != result.at( p - 1 ) )
69  return;
70 
71  // trim all 0 to the left of 'p'
72  std::string tmp = result.substr( p );
73  result = result.substr( 0, p );
74 
75  while( '0' == *( result.rbegin() ) )
76  result.erase( result.size() - 1 );
77 
78  result.append( tmp );
79 }

Referenced by FormatColor(), FormatOrientation(), FormatPoint(), FormatVector(), and SGAPPEARANCE::WriteVRML().

◆ FormatOrientation()

void S3D::FormatOrientation ( std::string &  result,
const SGVECTOR axis,
double  rotation 
)

Definition at line 82 of file sg_helpers.cpp.

83 {
84  double aX;
85  double aY;
86  double aZ;
87 
88  axis.GetVector( aX, aY, aZ );
89  FormatFloat( result, aX );
90  std::string tmp;
91  FormatFloat( tmp, aY );
92  result.append( " " );
93  result.append( tmp );
94  FormatFloat( tmp, aZ );
95  result.append( " " );
96  result.append( tmp );
97  FormatFloat( tmp, rotation );
98  result.append( " " );
99  result.append( tmp );
100 }
void FormatFloat(std::string &result, double value)
Definition: sg_helpers.cpp:37
void GetVector(double &aXVal, double &aYVal, double &aZVal) const noexcept
Definition: sg_base.cpp:225

References FormatFloat(), and SGVECTOR::GetVector().

Referenced by SCENEGRAPH::WriteVRML().

◆ FormatPoint()

void S3D::FormatPoint ( std::string &  result,
const SGPOINT point 
)

Definition at line 103 of file sg_helpers.cpp.

104 {
105  FormatFloat( result, point.x );
106 
107  std::string tmp;
108  FormatFloat( tmp, point.y );
109  result.append( " " );
110  result.append( tmp );
111 
112  FormatFloat( tmp, point.z );
113  result.append( " " );
114  result.append( tmp );
115 }
double x
Definition: sg_base.h:70
double y
Definition: sg_base.h:71
void FormatFloat(std::string &result, double value)
Definition: sg_helpers.cpp:37
double z
Definition: sg_base.h:72

References FormatFloat(), SGPOINT::x, SGPOINT::y, and SGPOINT::z.

Referenced by SCENEGRAPH::WriteVRML(), and SGCOORDS::WriteVRML().

◆ FormatVector()

void S3D::FormatVector ( std::string &  result,
const SGVECTOR aVector 
)

Definition at line 118 of file sg_helpers.cpp.

119 {
120  double X, Y, Z;
121  aVector.GetVector( X, Y, Z );
122  FormatFloat( result, X );
123 
124  std::string tmp;
125  FormatFloat( tmp, Y );
126  result.append( " " );
127  result.append( tmp );
128 
129  FormatFloat( tmp, Z );
130  result.append( " " );
131  result.append( tmp );
132 }
void FormatFloat(std::string &result, double value)
Definition: sg_helpers.cpp:37
void GetVector(double &aXVal, double &aYVal, double &aZVal) const noexcept
Definition: sg_base.cpp:225

References FormatFloat(), and SGVECTOR::GetVector().

Referenced by SGNORMALS::WriteVRML().

◆ Free3DMesh()

void S3D::Free3DMesh ( SMESH aMesh)

Function Free3DMesh frees memory used internally by an SMESH structure.

Definition at line 419 of file ifsg_api.cpp.

420 {
421  S3D::FREE_SMESH( aMesh );
422 }
void FREE_SMESH(SMESH &aMesh) noexcept
Definition: sg_node.cpp:286

References FREE_SMESH().

Referenced by GetModel().

◆ Free3DModel()

SGLIB_API void S3D::Free3DModel ( S3DMODEL aModel)

Function Free3DModel frees memory used internally by an S3DMODEL structure.

Definition at line 413 of file ifsg_api.cpp.

414 {
415  S3D::FREE_S3DMODEL( aModel );
416 }
void FREE_S3DMODEL(S3DMODEL &aModel)
Definition: sg_node.cpp:324

References FREE_S3DMODEL().

◆ FREE_S3DMODEL()

void S3D::FREE_S3DMODEL ( S3DMODEL aModel)

Definition at line 324 of file sg_node.cpp.

325 {
326  if( nullptr != aModel.m_Materials )
327  {
328  delete [] aModel.m_Materials;
329  aModel.m_Materials = nullptr;
330  }
331 
332  aModel.m_MaterialsSize = 0;
333 
334  if( nullptr != aModel.m_Meshes )
335  {
336  for( unsigned int i = 0; i < aModel.m_MeshesSize; ++i )
337  FREE_SMESH( aModel.m_Meshes[i] );
338 
339  delete [] aModel.m_Meshes;
340  aModel.m_Meshes = nullptr;
341  }
342 
343  aModel.m_MeshesSize = 0;
344 }
SMESH * m_Meshes
The meshes list of this model.
Definition: c3dmodel.h:93
unsigned int m_MaterialsSize
Number of materials in the material array.
Definition: c3dmodel.h:95
SMATERIAL * m_Materials
The materials list of this model.
Definition: c3dmodel.h:96
void FREE_SMESH(SMESH &aMesh) noexcept
Definition: sg_node.cpp:286
unsigned int m_MeshesSize
Number of meshes in the array.
Definition: c3dmodel.h:92

References FREE_SMESH(), S3DMODEL::m_Materials, S3DMODEL::m_MaterialsSize, S3DMODEL::m_Meshes, and S3DMODEL::m_MeshesSize.

Referenced by Destroy3DModel(), and Free3DModel().

◆ FREE_SMESH()

void S3D::FREE_SMESH ( SMESH aMesh)
noexcept

Definition at line 286 of file sg_node.cpp.

287 {
288  if( nullptr != aMesh.m_Positions )
289  {
290  delete [] aMesh.m_Positions;
291  aMesh.m_Positions = nullptr;
292  }
293 
294  if( nullptr != aMesh.m_Normals )
295  {
296  delete [] aMesh.m_Normals;
297  aMesh.m_Normals = nullptr;
298  }
299 
300  if( nullptr != aMesh.m_Texcoords )
301  {
302  delete [] aMesh.m_Texcoords;
303  aMesh.m_Texcoords = nullptr;
304  }
305 
306  if( nullptr != aMesh.m_Color )
307  {
308  delete [] aMesh.m_Color;
309  aMesh.m_Color = nullptr;
310  }
311 
312  if( nullptr != aMesh.m_FaceIdx )
313  {
314  delete [] aMesh.m_FaceIdx;
315  aMesh.m_FaceIdx = nullptr;
316  }
317 
318  aMesh.m_VertexSize = 0;
319  aMesh.m_FaceIdxSize = 0;
320  aMesh.m_MaterialIdx = 0;
321 }
SFVEC3F * m_Normals
Vertex normals array.
Definition: c3dmodel.h:80
SFVEC3F * m_Positions
Vertex position array.
Definition: c3dmodel.h:79
unsigned int m_FaceIdxSize
Number of elements of the m_FaceIdx array.
Definition: c3dmodel.h:83
unsigned int m_VertexSize
Number of vertex in the arrays.
Definition: c3dmodel.h:78
SFVEC2F * m_Texcoords
Vertex texture coordinates array, can be NULL.
Definition: c3dmodel.h:81
SFVEC3F * m_Color
Vertex color array, can be NULL.
Definition: c3dmodel.h:82
unsigned int m_MaterialIdx
Material Index to be used in this mesh (must be < m_MaterialsSize )
Definition: c3dmodel.h:85
unsigned int * m_FaceIdx
Triangle Face Indexes.
Definition: c3dmodel.h:84

Referenced by Free3DMesh(), and FREE_S3DMODEL().

◆ GetLibVersion()

void S3D::GetLibVersion ( unsigned char *  Major,
unsigned char *  Minor,
unsigned char *  Patch,
unsigned char *  Revision 
)
noexcept

Function GetLibVersion retrieves version information of the kicad_3dsg library.

Definition at line 445 of file ifsg_api.cpp.

447 {
448  if( Major )
449  *Major = KICADSG_VERSION_MAJOR;
450 
451  if( Minor )
452  *Minor = KICADSG_VERSION_MINOR;
453 
454  if( Revision )
455  *Revision = KICADSG_VERSION_REVISION;
456 
457  if( Patch )
458  *Patch = KICADSG_VERSION_PATCH;
459 }
#define KICADSG_VERSION_MAJOR
Definition: sg_version.h:33
#define KICADSG_VERSION_REVISION
Definition: sg_version.h:36
#define KICADSG_VERSION_PATCH
Definition: sg_version.h:35
#define KICADSG_VERSION_MINOR
Definition: sg_version.h:34

References KICADSG_VERSION_MAJOR, KICADSG_VERSION_MINOR, KICADSG_VERSION_PATCH, and KICADSG_VERSION_REVISION.

◆ GetMatIndex()

bool S3D::GetMatIndex ( MATLIST aList,
SGNODE aNode,
int &  aIndex 
)

Definition at line 243 of file sg_node.cpp.

244 {
245  aIndex = 0;
246 
247  wxCHECK( aNode && S3D::SGTYPE_APPEARANCE == aNode->GetNodeType(), false );
248 
249  SGAPPEARANCE* node = (SGAPPEARANCE*)aNode;
250 
251  std::map< SGAPPEARANCE const*, int >::iterator it = aList.matmap.find( node );
252 
253  if( it != aList.matmap.end() )
254  {
255  aIndex = it->second;
256  return true;
257  }
258 
259  int idx = (int)aList.matorder.size();
260  aList.matorder.push_back( node );
261  aList.matmap.insert( std::pair< SGAPPEARANCE const*, int >( node, idx ) );
262  aIndex = idx;
263 
264  return true;
265 }
Defines the generic material appearance of a scenegraph object.
Definition: sg_appearance.h:37
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104

References SGNODE::GetNodeType(), S3D::MATLIST::matmap, S3D::MATLIST::matorder, and SGTYPE_APPEARANCE.

Referenced by SGSHAPE::Prepare().

◆ GetModel()

S3DMODEL * S3D::GetModel ( SCENEGRAPH aNode)

Function GetModel creates an S3DMODEL representation of aNode (raw data, no transforms)

Parameters
aNodeis the node to be transcribed into an S3DMODEL representation
Returns
an S3DMODEL representation of aNode on success, otherwise NULL

Definition at line 336 of file ifsg_api.cpp.

337 {
338  if( nullptr == aNode )
339  return nullptr;
340 
341  if( aNode->GetNodeType() != S3D::SGTYPE_TRANSFORM )
342  return nullptr;
343 
344  S3D::MATLIST materials;
345  std::vector< SMESH > meshes;
346 
347  // the materials list shall have a default color; although the VRML
348  // default is an opaque black, the default used here shall be a median
349  // gray in hopes that it may help highlight faulty models; this color is
350  // also typical of MCAD applications. When a model has no associated
351  // material color it shall be assigned the index 0.
352  SGAPPEARANCE app( nullptr );
353  app.ambient = SGCOLOR( 0.6f, 0.6f, 0.6f );
354  app.diffuse = SGCOLOR( 0.6f, 0.6f, 0.6f );
355  app.specular = app.diffuse;
356  app.shininess = 0.05f;
357  app.transparency = 0.0f;
358 
359  materials.matorder.push_back( &app );
360  materials.matmap.insert( std::pair< SGAPPEARANCE const*, int >( &app, 0 ) );
361 
362  if( aNode->Prepare( nullptr, materials, meshes ) )
363  {
364  if( meshes.empty() )
365  return nullptr;
366 
367  S3DMODEL* model = S3D::New3DModel();
368 
369  // add all the materials
370  size_t j = materials.matorder.size();
371  SMATERIAL* lmat = new SMATERIAL[j];
372 
373  for( size_t i = 0; i < j; ++i )
374  formatMaterial( lmat[i], materials.matorder[i] );
375 
376  model->m_Materials = lmat;
377  model->m_MaterialsSize = j;
378 
379  // add all the meshes
380  j = meshes.size();
381  SMESH* lmesh = new SMESH[j];
382 
383  for( size_t i = 0; i < j; ++i )
384  lmesh[i] = meshes[i];
385 
386  model->m_Meshes = lmesh;
387  model->m_MeshesSize = j;
388 
389  return model;
390  }
391 
392  size_t j = meshes.size();
393 
394  for( size_t i = 0; i < j; ++i )
395  S3D::Free3DMesh( meshes[i] );
396 
397  return nullptr;
398 }
SGLIB_API S3DMODEL * New3DModel(void)
Function New3DModel creates and initializes an S3DMODEL struct.
Definition: ifsg_api.cpp:425
std::map< SGAPPEARANCE const *, int > matmap
Definition: sg_node.h:57
Per-vertex normal/color/texcoors structure.
Definition: c3dmodel.h:76
SMESH * m_Meshes
The meshes list of this model.
Definition: c3dmodel.h:93
static void formatMaterial(SMATERIAL &mat, SGAPPEARANCE const *app)
Definition: ifsg_api.cpp:44
unsigned int m_MaterialsSize
Number of materials in the material array.
Definition: c3dmodel.h:95
std::vector< SGAPPEARANCE const * > matorder
Definition: sg_node.h:56
SMATERIAL * m_Materials
The materials list of this model.
Definition: c3dmodel.h:96
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90
unsigned int m_MeshesSize
Number of meshes in the array.
Definition: c3dmodel.h:92
Defines the generic material appearance of a scenegraph object.
Definition: sg_appearance.h:37
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104
bool Prepare(const glm::dmat4 *aTransform, S3D::MATLIST &materials, std::vector< SMESH > &meshes)
Definition: scenegraph.cpp:639
SGLIB_API void Free3DMesh(SMESH &aMesh)
Function Free3DMesh frees memory used internally by an SMESH structure.
Definition: ifsg_api.cpp:419

References SGAPPEARANCE::ambient, SGAPPEARANCE::diffuse, formatMaterial(), Free3DMesh(), SGNODE::GetNodeType(), S3DMODEL::m_Materials, S3DMODEL::m_MaterialsSize, S3DMODEL::m_Meshes, S3DMODEL::m_MeshesSize, S3D::MATLIST::matmap, S3D::MATLIST::matorder, New3DModel(), SCENEGRAPH::Prepare(), SGTYPE_TRANSFORM, SGAPPEARANCE::shininess, SGAPPEARANCE::specular, and SGAPPEARANCE::transparency.

Referenced by S3D_CACHE::GetModel(), PCB_VIEWER_TOOLS::MeasureTool(), and PCB_BASE_EDIT_FRAME::PutDataInPreviousState().

◆ GetNodeTypeName()

char const * S3D::GetNodeTypeName ( S3D::SGTYPES  aType)
noexcept

Return the name of the given type of node.

Definition at line 53 of file sg_node.cpp.

54 {
55  return node_names[aType].c_str();
56 }
static const std::string node_names[S3D::SGTYPE_END+1]
Definition: sg_node.cpp:36

References node_names.

Referenced by ReadTag().

◆ GetSGNodeParent()

◆ GetSGNodeType()

◆ Init3DMaterial()

void S3D::Init3DMaterial ( SMATERIAL aMat)

Function Init3DMaterial initializes an SMATERIAL struct.

Definition at line 433 of file ifsg_api.cpp.

434 {
435  S3D::INIT_SMATERIAL( aMat );
436 }
void INIT_SMATERIAL(SMATERIAL &aMaterial)
Definition: sg_node.cpp:268

References INIT_SMATERIAL().

◆ Init3DMesh()

void S3D::Init3DMesh ( SMESH aMesh)

Function Init3DMesh creates and initializes an SMESH struct.

Definition at line 439 of file ifsg_api.cpp.

440 {
441  S3D::INIT_SMESH( aMesh );
442 }
void INIT_SMESH(SMESH &aMesh) noexcept
Definition: sg_node.cpp:274

References INIT_SMESH().

◆ INIT_S3DMODEL()

void S3D::INIT_S3DMODEL ( S3DMODEL aModel)
noexcept

Definition at line 280 of file sg_node.cpp.

281 {
282  aModel = {};
283 }

Referenced by New3DModel().

◆ INIT_SMATERIAL()

void S3D::INIT_SMATERIAL ( SMATERIAL aMaterial)

Definition at line 268 of file sg_node.cpp.

269 {
270  aMaterial = {};
271 }

Referenced by Init3DMaterial().

◆ INIT_SMESH()

void S3D::INIT_SMESH ( SMESH aMesh)
noexcept

Definition at line 274 of file sg_node.cpp.

275 {
276  aMesh = {};
277 }

Referenced by Init3DMesh(), and SGSHAPE::Prepare().

◆ New3DModel()

S3DMODEL * S3D::New3DModel ( void  )

Function New3DModel creates and initializes an S3DMODEL struct.

Definition at line 425 of file ifsg_api.cpp.

426 {
427  S3DMODEL* mp = new S3DMODEL;
428  S3D::INIT_S3DMODEL( *mp );
429  return mp;
430 }
void INIT_S3DMODEL(S3DMODEL &aModel) noexcept
Definition: sg_node.cpp:280
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90

References INIT_S3DMODEL().

Referenced by GetModel().

◆ ReadCache()

SGNODE * S3D::ReadCache ( const char *  aFileName,
void *  aPluginMgr,
bool(*)(const char *, void *)  aTagCheck 
)

Function ReadCache reads a binary cache file and creates an SGNODE tree.

Parameters
aFileNameis the name of the binary cache file to be read
Returns
NULL on failure, on success a pointer to the top level SCENEGRAPH node; if desired this node can be associated with an IFSG_TRANSFORM wrapper via the IFSG_TRANSFORM::Attach() function.

Definition at line 219 of file ifsg_api.cpp.

221 {
222  if( nullptr == aFileName || aFileName[0] == 0 )
223  return nullptr;
224 
225  wxString ofile = wxString::FromUTF8Unchecked( aFileName );
226 
227  if( !wxFileName::FileExists( aFileName ) )
228  {
229  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] no such file '%s'",
230  __FILE__, __FUNCTION__, __LINE__, aFileName );
231 
232  return nullptr;
233  }
234 
235  SGNODE* np = new SCENEGRAPH( nullptr );
236 
237  OPEN_ISTREAM( file, aFileName );
238 
239  if( file.fail() )
240  {
241  delete np;
242 
243  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] failed to open file '%s'",
244  __FILE__, __FUNCTION__, __LINE__, aFileName );
245 
246  return nullptr;
247  }
248 
249  // from SG_VERSION_TAG 1, read the version tag; if it's not the expected tag
250  // then we fail to read the cache file
251  do
252  {
253  std::string name;
254  char schar;
255  file.get( schar );
256 
257  if( '(' != schar )
258  {
259  wxLogTrace( MASK_3D_SG,
260  "%s:%s:%d * [INFO] corrupt data; missing left parenthesis at position '%d'",
261  __FILE__, __FUNCTION__, __LINE__, static_cast<int>( file.tellg() ) );
262 
263  CLOSE_STREAM( file );
264  return nullptr;
265  }
266 
267  file.get( schar );
268 
269  while( ')' != schar && file.good() )
270  {
271  name.push_back( schar );
272  file.get( schar );
273  }
274 
275  if( name.compare( SG_VERSION_TAG ) )
276  {
277  CLOSE_STREAM( file );
278  return nullptr;
279  }
280 
281  } while( 0 );
282 
283  // from SG_VERSION_TAG 2, read the PluginInfo string and check that it matches
284  // version tag; if it's not the expected tag then we fail to read the file
285  do
286  {
287  std::string name;
288  char schar;
289  file.get( schar );
290 
291  if( '(' != schar )
292  {
293  wxLogTrace( MASK_3D_SG,
294  "%s:%s:%d * [INFO] corrupt data; missing left parenthesis at position '%d'",
295  __FILE__, __FUNCTION__, __LINE__, static_cast<int>( file.tellg() ) );
296 
297  CLOSE_STREAM( file );
298  return nullptr;
299  }
300 
301  file.get( schar );
302 
303  while( ')' != schar && file.good() )
304  {
305  name.push_back( schar );
306  file.get( schar );
307  }
308 
309  // check the plugin tag
310  if( nullptr != aTagCheck && nullptr != aPluginMgr
311  && !aTagCheck( name.c_str(), aPluginMgr ) )
312  {
313  CLOSE_STREAM( file );
314  return nullptr;
315  }
316 
317  } while( 0 );
318 
319  bool rval = np->ReadCache( file, nullptr );
320  CLOSE_STREAM( file );
321 
322  if( !rval )
323  {
324  delete np;
325 
326  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] problems encountered reading cache file '%s'",
327  __FILE__, __FUNCTION__, __LINE__, aFileName );
328 
329  return nullptr;
330  }
331 
332  return np;
333 }
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
virtual bool ReadCache(std::istream &aFile, SGNODE *parentNode)=0
Reads binary format data from a cache file.
#define SG_VERSION_TAG
Definition: ifsg_api.cpp:41
const char * name
Definition: DXF_plotter.cpp:59
#define OPEN_ISTREAM(var, name)
Define the basic data set required to represent a 3D model.
Definition: scenegraph.h:44
#define CLOSE_STREAM(var)

References CLOSE_STREAM, name, OPEN_ISTREAM, SGNODE::ReadCache(), and SG_VERSION_TAG.

Referenced by S3D_CACHE::loadCacheData().

◆ ReadColor()

bool S3D::ReadColor ( std::istream &  aFile,
SGCOLOR aColor 
)

Definition at line 294 of file sg_helpers.cpp.

295 {
296  float r, g, b;
297  aFile.read( (char*) &r, sizeof( float ) );
298  aFile.read( (char*) &g, sizeof( float ) );
299  aFile.read( (char*) &b, sizeof( float ) );
300  aColor.SetColor( r, g, b );
301 
302  if( aFile.fail() )
303  return false;
304 
305  return true;
306 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85

References SGCOLOR::SetColor().

Referenced by SGCOLORS::ReadCache(), and SGAPPEARANCE::ReadCache().

◆ ReadPoint()

bool S3D::ReadPoint ( std::istream &  aFile,
SGPOINT aPoint 
)

Definition at line 266 of file sg_helpers.cpp.

267 {
268  aFile.read( (char*) &aPoint.x, sizeof( aPoint.x ) );
269  aFile.read( (char*) &aPoint.y, sizeof( aPoint.y ) );
270  aFile.read( (char*) &aPoint.z, sizeof( aPoint.z ) );
271 
272  if( aFile.fail() )
273  return false;
274 
275  return true;
276 }
double x
Definition: sg_base.h:70
double y
Definition: sg_base.h:71
double z
Definition: sg_base.h:72

References SGPOINT::x, SGPOINT::y, and SGPOINT::z.

Referenced by SCENEGRAPH::ReadCache(), and SGCOORDS::ReadCache().

◆ ReadTag()

S3D::SGTYPES S3D::ReadTag ( std::istream &  aFile,
std::string &  aName 
)

Read the text tag of a binary cache file which is the NodeTag and unique ID number combined.

Parameters
aFileis a binary file open for reading.
aNamewill hold the tag name on successful return.
Returns
will be the NodeType which the tag represents or S3D::SGTYPES::SGTYPE_END on failure.

Definition at line 195 of file sg_helpers.cpp.

196 {
197  char schar;
198  aFile.get( schar );
199 
200  if( '[' != schar )
201  {
202  wxLogTrace( MASK_3D_SG,
203  "%s:%s:%d * [INFO] corrupt data; missing left bracket at position %d",
204  __FILE__, __FUNCTION__, __LINE__, static_cast<int>( aFile.tellg() ) );
205 
206  return S3D::SGTYPE_END;
207  }
208 
209  std::string name;
210  aFile.get( schar );
211 
212  while( ']' != schar && aFile.good() )
213  {
214  name.push_back( schar );
215  aFile.get( schar );
216  }
217 
218  if( schar != ']' )
219  {
220  wxLogTrace( MASK_3D_SG,
221  "%s:%s:%d * [INFO] corrupt data; could not find right bracket",
222  __FILE__, __FUNCTION__, __LINE__ );
223 
224  return S3D::SGTYPE_END;
225  }
226 
227  aName = name;
228  size_t upos = name.find( '_' );
229 
230  if( std::string::npos == upos )
231  {
232  wxLogTrace( MASK_3D_SG,
233  "%s:%s:%d * [INFO] corrupt data; no underscore in name '%s'",
234  __FILE__, __FUNCTION__, __LINE__, name );
235 
236  return S3D::SGTYPE_END;
237  }
238 
239  name = name.substr( 0, upos );
240  S3D::SGTYPES types[S3D::SGTYPE_END] = {
250  };
251 
252  for( int i = 0; i < S3D::SGTYPE_END; ++i )
253  {
254  if( !name.compare( S3D::GetNodeTypeName( types[i] ) ) )
255  return types[i];
256  }
257 
258  wxLogTrace( MASK_3D_SG,
259  "%s:%s:%d * [INFO] corrupt data; no node type matching '%s'",
260  __FILE__, __FUNCTION__, __LINE__, name );
261 
262  return S3D::SGTYPE_END;
263 }
SGTYPES
Definition: sg_types.h:34
const char * name
Definition: DXF_plotter.cpp:59
char const * GetNodeTypeName(S3D::SGTYPES aType) noexcept
Return the name of the given type of node.
Definition: sg_node.cpp:53

References GetNodeTypeName(), name, SGTYPE_APPEARANCE, SGTYPE_COLORINDEX, SGTYPE_COLORS, SGTYPE_COORDINDEX, SGTYPE_COORDS, SGTYPE_END, SGTYPE_FACESET, SGTYPE_NORMALS, SGTYPE_SHAPE, and SGTYPE_TRANSFORM.

Referenced by SGSHAPE::ReadCache(), SCENEGRAPH::ReadCache(), and SGFACESET::ReadCache().

◆ ReadVector()

bool S3D::ReadVector ( std::istream &  aFile,
SGVECTOR aVector 
)

Definition at line 279 of file sg_helpers.cpp.

280 {
281  double x, y, z;
282  aFile.read( (char*) &x, sizeof( double ) );
283  aFile.read( (char*) &y, sizeof( double ) );
284  aFile.read( (char*) &z, sizeof( double ) );
285  aVector.SetVector( x, y, z );
286 
287  if( aFile.fail() )
288  return false;
289 
290  return true;
291 }
void SetVector(double aXVal, double aYVal, double aZVal)
Definition: sg_base.cpp:233

References SGVECTOR::SetVector().

Referenced by SGNORMALS::ReadCache(), and SCENEGRAPH::ReadCache().

◆ RenameNodes()

void S3D::RenameNodes ( SGNODE aNode)

Function RenameNodes renames a node and all children nodes based on the current values of the global SG* class indices.

Parameters
aNodeis a top level node

Definition at line 140 of file ifsg_api.cpp.

141 {
142  wxCHECK( aNode, /* void */ );
143 
144  aNode->ReNameNodes();
145 }
virtual void ReNameNodes(void)=0
Rename a node and all its child nodes in preparation for write operations.

References SGNODE::ReNameNodes().

◆ ResetNodeIndex()

void S3D::ResetNodeIndex ( SGNODE aNode)

Function ResetNodeIndex resets the global SG* class indices.

Parameters
aNodemay be any valid SGNODE

Definition at line 132 of file ifsg_api.cpp.

133 {
134  wxCHECK( aNode, /* void */ );
135 
136  aNode->ResetNodeIndex();
137 }
void ResetNodeIndex(void) noexcept
Reset the global SG* node indices in preparation for write operations.
Definition: sg_node.cpp:236

References SGNODE::ResetNodeIndex().

◆ Select3DModel()

bool S3D::Select3DModel ( wxWindow *  aParent,
S3D_CACHE aCache,
wxString &  prevModelSelectDir,
int &  prevModelWildcard,
FP_3DMODEL aModel 
)

Definition at line 33 of file 3d_cache_dialogs.cpp.

35 {
36  if( NULL == aModel )
37  return false;
38 
39  DLG_SELECT_3DMODEL dm( aParent, aCache, aModel, prevModelSelectDir, prevModelWildcard );
40 
41  // Use QuasiModal so that Configure3DPaths (and its help window) will work
42  return dm.ShowQuasiModal() == wxID_OK;
43 }
#define NULL

References NULL, and DIALOG_SHIM::ShowQuasiModal().

Referenced by DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnAdd3DModel(), and DIALOG_FOOTPRINT_PROPERTIES::OnAdd3DModel().

◆ WriteCache()

bool S3D::WriteCache ( const char *  aFileName,
bool  overwrite,
SGNODE aNode,
const char *  aPluginInfo 
)

Function WriteCache writes the SGNODE tree to a binary cache file.

Parameters
aFileNameis the name of the file to write
overwritemust be set to true to overwrite an existing file
aNodeis any node within the node tree which is to be written
Returns
true on success

Definition at line 156 of file ifsg_api.cpp.

158 {
159  if( nullptr == aFileName || aFileName[0] == 0 )
160  return false;
161 
162  wxString ofile = wxString::FromUTF8Unchecked( aFileName );
163 
164  wxCHECK( aNode, false );
165 
166  if( wxFileName::Exists( ofile ) )
167  {
168  if( !overwrite )
169  {
170  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] file exists not overwriting '%s'",
171  __FILE__, __FUNCTION__, __LINE__, aFileName );
172 
173  return false;
174  }
175 
176  // make sure we make no attempt to write a directory
177  if( !wxFileName::FileExists( aFileName ) )
178  {
179  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] specified path is a directory '%s'",
180  __FILE__, __FUNCTION__, __LINE__, aFileName );
181 
182  return false;
183  }
184  }
185 
186  OPEN_OSTREAM( output, aFileName );
187 
188  if( output.fail() )
189  {
190  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] failed to open file '%s'",
191  __FILE__, __FUNCTION__, __LINE__, aFileName );
192 
193  return false;
194  }
195 
196  output << "(" << SG_VERSION_TAG << ")";
197 
198  if( nullptr != aPluginInfo && aPluginInfo[0] != 0 )
199  output << "(" << aPluginInfo << ")";
200  else
201  output << "(INTERNAL:0.0.0.0)";
202 
203  bool rval = aNode->WriteCache( output, nullptr );
204  CLOSE_STREAM( output );
205 
206  if( !rval )
207  {
208  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] problems encountered writing cache file '%s'",
209  __FILE__, __FUNCTION__, __LINE__, aFileName );
210 
211  // delete the defective file
212  wxRemoveFile( ofile );
213  }
214 
215  return rval;
216 }
#define OPEN_OSTREAM(var, name)
#define SG_VERSION_TAG
Definition: ifsg_api.cpp:41
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Write this node's data to a binary cache file.
#define CLOSE_STREAM(var)

References CLOSE_STREAM, OPEN_OSTREAM, SG_VERSION_TAG, and SGNODE::WriteCache().

Referenced by S3D_CACHE::saveCacheData().

◆ WriteColor()

bool S3D::WriteColor ( std::ostream &  aFile,
const SGCOLOR aColor 
)

Definition at line 180 of file sg_helpers.cpp.

181 {
182  float r, g, b;
183  aColor.GetColor( r, g, b );
184  aFile.write( (char*) &r, sizeof( float ) );
185  aFile.write( (char*) &g, sizeof( float ) );
186  aFile.write( (char*) &b, sizeof( float ) );
187 
188  if( aFile.fail() )
189  return false;
190 
191  return true;
192 }
void GetColor(float &aRedVal, float &aGreenVal, float &aBlueVal) const noexcept
Definition: sg_base.cpp:59

References SGCOLOR::GetColor().

Referenced by SGCOLORS::WriteCache(), and SGAPPEARANCE::WriteCache().

◆ WritePoint()

bool S3D::WritePoint ( std::ostream &  aFile,
const SGPOINT aPoint 
)

Definition at line 152 of file sg_helpers.cpp.

153 {
154  aFile.write( (char*) &aPoint.x, sizeof( aPoint.x ) );
155  aFile.write( (char*) &aPoint.y, sizeof( aPoint.y ) );
156  aFile.write( (char*) &aPoint.z, sizeof( aPoint.z ) );
157 
158  if( aFile.fail() )
159  return false;
160 
161  return true;
162 }
double x
Definition: sg_base.h:70
double y
Definition: sg_base.h:71
double z
Definition: sg_base.h:72

References SGPOINT::x, SGPOINT::y, and SGPOINT::z.

Referenced by SCENEGRAPH::WriteCache(), and SGCOORDS::WriteCache().

◆ WriteVector()

bool S3D::WriteVector ( std::ostream &  aFile,
const SGVECTOR aVector 
)

Definition at line 165 of file sg_helpers.cpp.

166 {
167  double x, y, z;
168  aVector.GetVector( x, y, z );
169  aFile.write( (char*) &x, sizeof( double ) );
170  aFile.write( (char*) &y, sizeof( double ) );
171  aFile.write( (char*) &z, sizeof( double ) );
172 
173  if( aFile.fail() )
174  return false;
175 
176  return true;
177 }
void GetVector(double &aXVal, double &aYVal, double &aZVal) const noexcept
Definition: sg_base.cpp:225

References SGVECTOR::GetVector().

Referenced by SGNORMALS::WriteCache(), and SCENEGRAPH::WriteCache().

◆ WriteVRML()

bool S3D::WriteVRML ( const char *  filename,
bool  overwrite,
SGNODE aTopNode,
bool  reuse,
bool  renameNodes 
)

Function WriteVRML writes out the given node and its subnodes to a VRML2 file.

Parameters
filenameis the name of the output file
overwriteshould be set to true to overwrite an existing VRML file
aTopNodeis a pointer to a SCENEGRAPH object representing the VRML scene
reuseshould be set to true to make use of VRML DEF/USE features
Returns
true on success

Definition at line 76 of file ifsg_api.cpp.

78 {
79  if( nullptr == filename || filename[0] == 0 )
80  return false;
81 
82  wxString ofile = wxString::FromUTF8Unchecked( filename );
83 
84  if( wxFileName::Exists( ofile ) )
85  {
86  if( !overwrite )
87  return false;
88 
89  // make sure we make no attempt to write a directory
90  if( !wxFileName::FileExists( ofile ) )
91  return false;
92  }
93 
94  wxCHECK( aTopNode && aTopNode->GetNodeType() == S3D::SGTYPE_TRANSFORM, false );
95 
96  OPEN_OSTREAM( op, filename );
97 
98  if( op.fail() )
99  {
100  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] failed to open file '%s'",
101  __FILE__, __FUNCTION__, __LINE__, filename );
102 
103  return false;
104  }
105 
106  op.imbue( std::locale::classic() );
107  op << "#VRML V2.0 utf8\n";
108 
109  if( renameNodes )
110  {
111  aTopNode->ResetNodeIndex();
112  aTopNode->ReNameNodes();
113  }
114 
115  aTopNode->WriteVRML( op, reuse );
116 
117  if( !op.fail() )
118  {
119  CLOSE_STREAM( op );
120  return true;
121  }
122 
123  CLOSE_STREAM( op );
124 
125  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] problems encountered writing file '%s'",
126  __FILE__, __FUNCTION__, __LINE__, filename );
127 
128  return false;
129 }
virtual void ReNameNodes(void)=0
Rename a node and all its child nodes in preparation for write operations.
void ResetNodeIndex(void) noexcept
Reset the global SG* node indices in preparation for write operations.
Definition: sg_node.cpp:236
#define OPEN_OSTREAM(var, name)
#define CLOSE_STREAM(var)
virtual bool WriteVRML(std::ostream &aFile, bool aReuseFlag)=0
Writes this node's data to a VRML file.
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104

References CLOSE_STREAM, SGNODE::GetNodeType(), OPEN_OSTREAM, SGNODE::ReNameNodes(), SGNODE::ResetNodeIndex(), SGTYPE_TRANSFORM, and SGNODE::WriteVRML().

Referenced by EXPORTER_PCB_VRML::ExportVrmlFootprint(), Load(), LoadModel(), LoadVRML(), and EXPORTER_PCB_VRML::writeLayers().