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 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)
 
bool Select3DModel (wxWindow *aParent, S3D_CACHE *aCache, wxString &prevModelSelectDir, int &prevModelWildcard, FP_3DMODEL *aModel)
 
bool Configure3DPaths (wxWindow *aParent, FILENAME_RESOLVER *aResolver)
 
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 521 of file ifsg_api.cpp.

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

References SGNODE::AssociateWrapper().

◆ CalcTriangleNormals()

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

Definition at line 353 of file sg_helpers.cpp.

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

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 464 of file ifsg_api.cpp.

465 {
466  glm::dvec3 tri = glm::dvec3( 0.0, 0.0, 0.0 );
467  glm::dvec3 pts[3];
468 
469  pts[0] = glm::dvec3( p1.x, p1.y, p1.z );
470  pts[1] = glm::dvec3( p2.x, p2.y, p2.z );
471  pts[2] = glm::dvec3( p3.x, p3.y, p3.z );
472 
473  // degenerate points are given a default 0, 0, 1 normal
474  if( S3D::degenerate( pts ) )
475  return SGVECTOR( 0.0, 0.0, 1.0 );
476 
477  // normal
478  tri = glm::cross( pts[1] - pts[0], pts[2] - pts[0] );
479  glm::normalize( tri );
480 
481  return SGVECTOR( tri.x, tri.y, tri.z );
482 }
double x
Definition: sg_base.h:70
bool degenerate(glm::dvec3 *pts) noexcept
Definition: sg_helpers.cpp:310
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 PANEL_FP_PROPERTIES_3D_MODEL::Cfg3DPath(), and DIALOG_SELECT_3DMODEL::Cfg3DPaths().

◆ degenerate()

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

Definition at line 310 of file sg_helpers.cpp.

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

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 403 of file ifsg_api.cpp.

404 {
405  if( nullptr == aModel || nullptr == *aModel )
406  return;
407 
408  S3DMODEL* m = *aModel;
409  S3D::FREE_S3DMODEL( *m );
410  delete m;
411  *aModel = nullptr;
412 }
void FREE_S3DMODEL(S3DMODEL &aModel)
Definition: sg_node.cpp:326
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 149 of file ifsg_api.cpp.

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

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 421 of file ifsg_api.cpp.

422 {
423  S3D::FREE_SMESH( aMesh );
424 }
void FREE_SMESH(SMESH &aMesh) noexcept
Definition: sg_node.cpp:288

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 415 of file ifsg_api.cpp.

416 {
417  S3D::FREE_S3DMODEL( aModel );
418 }
void FREE_S3DMODEL(S3DMODEL &aModel)
Definition: sg_node.cpp:326

References FREE_S3DMODEL().

◆ FREE_S3DMODEL()

void S3D::FREE_S3DMODEL ( S3DMODEL aModel)

Definition at line 326 of file sg_node.cpp.

327 {
328  if( nullptr != aModel.m_Materials )
329  {
330  delete [] aModel.m_Materials;
331  aModel.m_Materials = nullptr;
332  }
333 
334  aModel.m_MaterialsSize = 0;
335 
336  if( nullptr != aModel.m_Meshes )
337  {
338  for( unsigned int i = 0; i < aModel.m_MeshesSize; ++i )
339  FREE_SMESH( aModel.m_Meshes[i] );
340 
341  delete [] aModel.m_Meshes;
342  aModel.m_Meshes = nullptr;
343  }
344 
345  aModel.m_MeshesSize = 0;
346 }
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:288
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 288 of file sg_node.cpp.

289 {
290  if( nullptr != aMesh.m_Positions )
291  {
292  delete [] aMesh.m_Positions;
293  aMesh.m_Positions = nullptr;
294  }
295 
296  if( nullptr != aMesh.m_Normals )
297  {
298  delete [] aMesh.m_Normals;
299  aMesh.m_Normals = nullptr;
300  }
301 
302  if( nullptr != aMesh.m_Texcoords )
303  {
304  delete [] aMesh.m_Texcoords;
305  aMesh.m_Texcoords = nullptr;
306  }
307 
308  if( nullptr != aMesh.m_Color )
309  {
310  delete [] aMesh.m_Color;
311  aMesh.m_Color = nullptr;
312  }
313 
314  if( nullptr != aMesh.m_FaceIdx )
315  {
316  delete [] aMesh.m_FaceIdx;
317  aMesh.m_FaceIdx = nullptr;
318  }
319 
320  aMesh.m_VertexSize = 0;
321  aMesh.m_FaceIdxSize = 0;
322  aMesh.m_MaterialIdx = 0;
323 }
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 447 of file ifsg_api.cpp.

449 {
450  if( Major )
451  *Major = KICADSG_VERSION_MAJOR;
452 
453  if( Minor )
454  *Minor = KICADSG_VERSION_MINOR;
455 
456  if( Revision )
457  *Revision = KICADSG_VERSION_REVISION;
458 
459  if( Patch )
460  *Patch = KICADSG_VERSION_PATCH;
461 }
#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 245 of file sg_node.cpp.

246 {
247  aIndex = 0;
248 
249  wxCHECK( aNode && S3D::SGTYPE_APPEARANCE == aNode->GetNodeType(), false );
250 
251  SGAPPEARANCE* node = (SGAPPEARANCE*)aNode;
252 
253  std::map< SGAPPEARANCE const*, int >::iterator it = aList.matmap.find( node );
254 
255  if( it != aList.matmap.end() )
256  {
257  aIndex = it->second;
258  return true;
259  }
260 
261  int idx = (int)aList.matorder.size();
262  aList.matorder.push_back( node );
263  aList.matmap.insert( std::pair< SGAPPEARANCE const*, int >( node, idx ) );
264  aIndex = idx;
265 
266  return true;
267 }
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 338 of file ifsg_api.cpp.

339 {
340  if( nullptr == aNode )
341  return nullptr;
342 
343  if( aNode->GetNodeType() != S3D::SGTYPE_TRANSFORM )
344  return nullptr;
345 
346  S3D::MATLIST materials;
347  std::vector< SMESH > meshes;
348 
349  // the materials list shall have a default color; although the VRML
350  // default is an opaque black, the default used here shall be a median
351  // gray in hopes that it may help highlight faulty models; this color is
352  // also typical of MCAD applications. When a model has no associated
353  // material color it shall be assigned the index 0.
354  SGAPPEARANCE app( nullptr );
355  app.ambient = SGCOLOR( 0.6f, 0.6f, 0.6f );
356  app.diffuse = SGCOLOR( 0.6f, 0.6f, 0.6f );
357  app.specular = app.diffuse;
358  app.shininess = 0.05f;
359  app.transparency = 0.0f;
360 
361  materials.matorder.push_back( &app );
362  materials.matmap.insert( std::pair< SGAPPEARANCE const*, int >( &app, 0 ) );
363 
364  if( aNode->Prepare( nullptr, materials, meshes ) )
365  {
366  if( meshes.empty() )
367  return nullptr;
368 
369  S3DMODEL* model = S3D::New3DModel();
370 
371  // add all the materials
372  size_t j = materials.matorder.size();
373  SMATERIAL* lmat = new SMATERIAL[j];
374 
375  for( size_t i = 0; i < j; ++i )
376  formatMaterial( lmat[i], materials.matorder[i] );
377 
378  model->m_Materials = lmat;
379  model->m_MaterialsSize = j;
380 
381  // add all the meshes
382  j = meshes.size();
383  SMESH* lmesh = new SMESH[j];
384 
385  for( size_t i = 0; i < j; ++i )
386  lmesh[i] = meshes[i];
387 
388  model->m_Meshes = lmesh;
389  model->m_MeshesSize = j;
390 
391  return model;
392  }
393 
394  size_t j = meshes.size();
395 
396  for( size_t i = 0; i < j; ++i )
397  S3D::Free3DMesh( meshes[i] );
398 
399  return nullptr;
400 }
SGLIB_API S3DMODEL * New3DModel(void)
Function New3DModel creates and initializes an S3DMODEL struct.
Definition: ifsg_api.cpp:427
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:45
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:647
SGLIB_API void Free3DMesh(SMESH &aMesh)
Function Free3DMesh frees memory used internally by an SMESH structure.
Definition: ifsg_api.cpp:421

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 435 of file ifsg_api.cpp.

436 {
437  S3D::INIT_SMATERIAL( aMat );
438 }
void INIT_SMATERIAL(SMATERIAL &aMaterial)
Definition: sg_node.cpp:270

References INIT_SMATERIAL().

◆ Init3DMesh()

void S3D::Init3DMesh ( SMESH aMesh)

Function Init3DMesh creates and initializes an SMESH struct.

Definition at line 441 of file ifsg_api.cpp.

442 {
443  S3D::INIT_SMESH( aMesh );
444 }
void INIT_SMESH(SMESH &aMesh) noexcept
Definition: sg_node.cpp:276

References INIT_SMESH().

◆ INIT_S3DMODEL()

void S3D::INIT_S3DMODEL ( S3DMODEL aModel)
noexcept

Definition at line 282 of file sg_node.cpp.

283 {
284  aModel = {};
285 }

Referenced by New3DModel().

◆ INIT_SMATERIAL()

void S3D::INIT_SMATERIAL ( SMATERIAL aMaterial)

Definition at line 270 of file sg_node.cpp.

271 {
272  aMaterial = {};
273 }

Referenced by Init3DMaterial().

◆ INIT_SMESH()

void S3D::INIT_SMESH ( SMESH aMesh)
noexcept

Definition at line 276 of file sg_node.cpp.

277 {
278  aMesh = {};
279 }

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

◆ New3DModel()

S3DMODEL * S3D::New3DModel ( void  )

Function New3DModel creates and initializes an S3DMODEL struct.

Definition at line 427 of file ifsg_api.cpp.

428 {
429  S3DMODEL* mp = new S3DMODEL;
430  S3D::INIT_S3DMODEL( *mp );
431  return mp;
432 }
void INIT_S3DMODEL(S3DMODEL &aModel) noexcept
Definition: sg_node.cpp:282
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 221 of file ifsg_api.cpp.

223 {
224  if( nullptr == aFileName || aFileName[0] == 0 )
225  return nullptr;
226 
227  wxString ofile = wxString::FromUTF8Unchecked( aFileName );
228 
229  if( !wxFileName::FileExists( aFileName ) )
230  {
231  wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] no such file '%s'" ),
232  __FILE__, __FUNCTION__, __LINE__, aFileName );
233 
234  return nullptr;
235  }
236 
237  std::unique_ptr<SGNODE> np = std::make_unique<SCENEGRAPH>( nullptr );
238 
239  OPEN_ISTREAM( file, aFileName );
240 
241  if( file.fail() )
242  {
243  wxLogTrace( MASK_3D_SG, wxT( "%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, wxT( "%s:%s:%d * [INFO] corrupt data; missing left parenthesis"
260  " at position '%d'" ),
261  __FILE__, __FUNCTION__, __LINE__,
262  static_cast<int>( file.tellg() ) );
263 
264  CLOSE_STREAM( file );
265  return nullptr;
266  }
267 
268  file.get( schar );
269 
270  while( ')' != schar && file.good() )
271  {
272  name.push_back( schar );
273  file.get( schar );
274  }
275 
276  if( name.compare( SG_VERSION_TAG ) )
277  {
278  CLOSE_STREAM( file );
279  return nullptr;
280  }
281 
282  } while( 0 );
283 
284  // from SG_VERSION_TAG 2, read the PluginInfo string and check that it matches
285  // version tag; if it's not the expected tag then we fail to read the file
286  do
287  {
288  std::string name;
289  char schar;
290  file.get( schar );
291 
292  if( '(' != schar )
293  {
294  wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; missing left parenthesis"
295  " at position '%d'" ),
296  __FILE__, __FUNCTION__, __LINE__,
297  static_cast<int>( file.tellg() ) );
298 
299  CLOSE_STREAM( file );
300  return nullptr;
301  }
302 
303  file.get( schar );
304 
305  while( ')' != schar && file.good() )
306  {
307  name.push_back( schar );
308  file.get( schar );
309  }
310 
311  // check the plugin tag
312  if( nullptr != aTagCheck && nullptr != aPluginMgr
313  && !aTagCheck( name.c_str(), aPluginMgr ) )
314  {
315  CLOSE_STREAM( file );
316  return nullptr;
317  }
318 
319  } while( 0 );
320 
321  bool rval = np->ReadCache( file, nullptr );
322  CLOSE_STREAM( file );
323 
324  if( !rval )
325  {
326  wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] problems encountered reading cache file "
327  "'%s'" ),
328  __FILE__, __FUNCTION__, __LINE__,
329  aFileName );
330 
331  return nullptr;
332  }
333 
334  return np.release();
335 }
#define SG_VERSION_TAG
Definition: ifsg_api.cpp:42
const char * name
Definition: DXF_plotter.cpp:56
#define OPEN_ISTREAM(var, name)
#define CLOSE_STREAM(var)

References CLOSE_STREAM, name, OPEN_ISTREAM, and SG_VERSION_TAG.

Referenced by S3D_CACHE::loadCacheData().

◆ ReadColor()

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

Definition at line 295 of file sg_helpers.cpp.

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

References r, and SGCOLOR::SetColor().

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

◆ ReadPoint()

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

Definition at line 267 of file sg_helpers.cpp.

268 {
269  aFile.read( (char*) &aPoint.x, sizeof( aPoint.x ) );
270  aFile.read( (char*) &aPoint.y, sizeof( aPoint.y ) );
271  aFile.read( (char*) &aPoint.z, sizeof( aPoint.z ) );
272 
273  if( aFile.fail() )
274  return false;
275 
276  return true;
277 }
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, wxT( "%s:%s:%d * [INFO] corrupt data; missing left bracket at "
203  "position %d" ),
204  __FILE__, __FUNCTION__, __LINE__,
205  static_cast<int>( aFile.tellg() ) );
206 
207  return S3D::SGTYPE_END;
208  }
209 
210  std::string name;
211  aFile.get( schar );
212 
213  while( ']' != schar && aFile.good() )
214  {
215  name.push_back( schar );
216  aFile.get( schar );
217  }
218 
219  if( schar != ']' )
220  {
221  wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; could not find right "
222  "bracket" ),
223  __FILE__, __FUNCTION__, __LINE__ );
224 
225  return S3D::SGTYPE_END;
226  }
227 
228  aName = name;
229  size_t upos = name.find( '_' );
230 
231  if( std::string::npos == upos )
232  {
233  wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; no underscore in name '%s'" ),
234  __FILE__, __FUNCTION__, __LINE__,
235  name );
236 
237  return S3D::SGTYPE_END;
238  }
239 
240  name = name.substr( 0, upos );
241  S3D::SGTYPES types[S3D::SGTYPE_END] = {
251  };
252 
253  for( int i = 0; i < S3D::SGTYPE_END; ++i )
254  {
255  if( !name.compare( S3D::GetNodeTypeName( types[i] ) ) )
256  return types[i];
257  }
258 
259  wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; no node type matching '%s'" ),
260  __FILE__, __FUNCTION__, __LINE__,
261  name );
262 
263  return S3D::SGTYPE_END;
264 }
SGTYPES
Definition: sg_types.h:34
const char * name
Definition: DXF_plotter.cpp:56
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 280 of file sg_helpers.cpp.

281 {
282  double x, y, z;
283  aFile.read( (char*) &x, sizeof( double ) );
284  aFile.read( (char*) &y, sizeof( double ) );
285  aFile.read( (char*) &z, sizeof( double ) );
286  aVector.SetVector( x, y, z );
287 
288  if( aFile.fail() )
289  return false;
290 
291  return true;
292 }
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 141 of file ifsg_api.cpp.

142 {
143  wxCHECK( aNode, /* void */ );
144 
145  aNode->ReNameNodes();
146 }
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 133 of file ifsg_api.cpp.

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

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( nullptr == aModel )
37  return false;
38 
39  DIALOG_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 }

References DIALOG_SHIM::ShowQuasiModal().

Referenced by PANEL_FP_PROPERTIES_3D_MODEL::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 157 of file ifsg_api.cpp.

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

References SGCOLOR::GetColor(), and r.

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 77 of file ifsg_api.cpp.

79 {
80  if( nullptr == filename || filename[0] == 0 )
81  return false;
82 
83  wxString ofile = wxString::FromUTF8Unchecked( filename );
84 
85  if( wxFileName::Exists( ofile ) )
86  {
87  if( !overwrite )
88  return false;
89 
90  // make sure we make no attempt to write a directory
91  if( !wxFileName::FileExists( ofile ) )
92  return false;
93  }
94 
95  wxCHECK( aTopNode && aTopNode->GetNodeType() == S3D::SGTYPE_TRANSFORM, false );
96 
97  OPEN_OSTREAM( op, filename );
98 
99  if( op.fail() )
100  {
101  wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] failed to open file '%s'" ),
102  __FILE__, __FUNCTION__, __LINE__, filename );
103 
104  return false;
105  }
106 
107  op.imbue( std::locale::classic() );
108  op << "#VRML V2.0 utf8\n";
109 
110  if( renameNodes )
111  {
112  aTopNode->ResetNodeIndex();
113  aTopNode->ReNameNodes();
114  }
115 
116  aTopNode->WriteVRML( op, reuse );
117 
118  if( !op.fail() )
119  {
120  CLOSE_STREAM( op );
121  return true;
122  }
123 
124  CLOSE_STREAM( op );
125 
126  wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] problems encountered writing file '%s'" ),
127  __FILE__, __FUNCTION__, __LINE__, filename );
128 
129  return false;
130 }
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:238
#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().