KiCad PCB EDA Suite
S3D Namespace Reference

Classes

struct  MATLIST
 
struct  rsort_wxString
 

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, S3D_INFO *aModel)
 
bool Configure3DPaths (wxWindow *aParent, S3D_FILENAME_RESOLVER *aResolver)
 
bool degenerate (glm::dvec3 *pts)
 
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)
 Function ReadTag reads 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)
 Function GetNodeTypeName returns 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)
 
void INIT_S3DMODEL (S3DMODEL &aModel)
 
void FREE_SMESH (SMESH &aMesh)
 
void FREE_S3DMODEL (S3DMODEL &aModel)
 
SGLIB_API void GetLibVersion (unsigned char *Major, unsigned char *Minor, unsigned char *Patch, unsigned char *Revision)
 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)
 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

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

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

Definition at line 661 of file ifsg_api.cpp.

References SGNODE::AddChildNode().

662 {
663  if( NULL == aParent || NULL == aChild )
664  return false;
665 
666  return aParent->AddChildNode( aChild );
667 }
virtual bool AddChildNode(SGNODE *aNode)=0
bool S3D::AddSGNodeRef ( SGNODE aParent,
SGNODE aChild 
)

Definition at line 652 of file ifsg_api.cpp.

References SGNODE::AddRefNode().

653 {
654  if( NULL == aParent || NULL == aChild )
655  return false;
656 
657  return aParent->AddRefNode( aChild );
658 }
virtual bool AddRefNode(SGNODE *aNode)=0
void S3D::AssociateSGNodeWrapper ( SGNODE aObject,
SGNODE **  aRefPtr 
)

Definition at line 670 of file ifsg_api.cpp.

References SGNODE::AssociateWrapper().

671 {
672  if( NULL == aObject || NULL == aRefPtr || aObject != *aRefPtr )
673  return;
674 
675  aObject->AssociateWrapper( aRefPtr );
676 
677  return;
678 }
void AssociateWrapper(SGNODE **aWrapperRef)
Function AssociateWrapper associates this object with a handle to itself; this handle is typically he...
Definition: sg_node.cpp:219
bool S3D::CalcTriangleNormals ( std::vector< SGPOINT coords,
std::vector< int > &  index,
std::vector< SGVECTOR > &  norms 
)

Definition at line 384 of file sg_helpers.cpp.

References calcTriad().

Referenced by SGCOORDS::CalcNormals().

386 {
387  size_t vsize = coords.size();
388 
389  if( vsize < 3 )
390  {
391  #ifdef DEBUG
392  std::ostringstream ostr;
393  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
394  ostr << " * [INFO] invalid vertex set (fewer than 3 vertices)";
395  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
396  #endif
397 
398  return false;
399  }
400 
401  size_t isize = index.size();
402 
403  if( 0 != isize % 3 || index.empty() )
404  {
405  #ifdef DEBUG
406  std::ostringstream ostr;
407  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
408  ostr << " * [INFO] invalid index set (not multiple of 3)";
409  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
410  #endif
411 
412  return false;
413  }
414 
415  if( !norms.empty() )
416  {
417  #ifdef DEBUG
418  std::ostringstream ostr;
419  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
420  ostr << " * [INFO] normals set is not empty";
421  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
422  #endif
423 
424  return false;
425  }
426 
427  std::map< int, std::list< glm::dvec3 > >vmap;
428 
429  int p1, p2, p3;
430 
431  // create the map of indices to facet sets
432  for( size_t i = 0; i < isize; )
433  {
434  p1 = index[i++];
435  p2 = index[i++];
436  p3 = index[i++];
437 
438  if( p1 < 0 || p1 >= (int)vsize || p2 < 0 || p2 >= (int)vsize ||
439  p3 < 0 || p3 >= (int)vsize )
440  {
441  #ifdef DEBUG
442  std::ostringstream ostr;
443  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
444  ostr << " * [INFO] invalid index set; index out of bounds";
445  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
446  #endif
447 
448  return false;
449  }
450 
451  glm::dvec3 tri;
452  glm::dvec3 trip[3];
453  trip[0] = glm::dvec3( coords[p1].x, coords[p1].y, coords[p1].z );
454  trip[1] = glm::dvec3( coords[p2].x, coords[p2].y, coords[p2].z );
455  trip[2] = glm::dvec3( coords[p3].x, coords[p3].y, coords[p3].z );
456  calcTriad( trip, tri );
457 
458  std::map< int, std::list< glm::dvec3 > >::iterator ip = vmap.find( p1 );
459 
460  if( ip != vmap.end() )
461  {
462  ip->second.push_back( tri );
463  }
464  else
465  {
466  vmap.insert( std::pair < int, std::list < glm::dvec3 > >
467  ( p1, std::list < glm::dvec3 >( 1, tri ) ) );
468  }
469 
470  ip = vmap.find( p2 );
471 
472  if( ip != vmap.end() )
473  {
474  ip->second.push_back( tri );
475  }
476  else
477  {
478  vmap.insert( std::pair < int, std::list < glm::dvec3 > >
479  ( p2, std::list < glm::dvec3 >( 1, tri ) ) );
480  }
481 
482  ip = vmap.find( p3 );
483 
484  if( ip != vmap.end() )
485  {
486  ip->second.push_back( tri );
487  }
488  else
489  {
490  vmap.insert( std::pair < int, std::list < glm::dvec3 > >
491  ( p3, std::list < glm::dvec3 >( 1, tri ) ) );
492  }
493  }
494 
495  std::map< int, std::list< glm::dvec3 > >::iterator sM = vmap.begin();
496  std::map< int, std::list< glm::dvec3 > >::iterator eM = vmap.end();
497  size_t idx = 0;
498 
499  while( sM != eM )
500  {
501  size_t item = sM->first;
502 
503  // assign any skipped coordinates a normal of (0,0,1)
504  while( item > idx )
505  {
506  norms.push_back( SGVECTOR( 0, 0, 1 ) );
507  ++idx;
508  }
509 
510  std::list< glm::dvec3 >::iterator sT = sM->second.begin();
511  std::list< glm::dvec3 >::iterator eT = sM->second.end();
512  glm::dvec3 norm( 0.0, 0.0, 0.0 );
513 
514  while( sT != eT )
515  {
516  norm += *sT;
517  ++sT;
518  }
519 
520  norms.push_back( SGVECTOR( norm.x, norm.y, norm.z ) );
521 
522  ++idx;
523  ++sM;
524  }
525 
526  if( norms.size() != coords.size() )
527  {
528  #ifdef DEBUG
529  std::ostringstream ostr;
530  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
531  ostr << " * [BUG] number of normals does not equal number of vertices";
532  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
533  #endif
534 
535  return false;
536  }
537 
538  return true;
539 }
static void calcTriad(glm::dvec3 *pts, glm::dvec3 &tri)
Definition: sg_helpers.cpp:368
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 613 of file ifsg_api.cpp.

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

Referenced by create_vrml_shell().

614 {
615  glm::dvec3 tri = glm::dvec3( 0.0, 0.0, 0.0 );
616  glm::dvec3 pts[3];
617 
618  pts[0] = glm::dvec3( p1.x, p1.y, p1.z );
619  pts[1] = glm::dvec3( p2.x, p2.y, p2.z );
620  pts[2] = glm::dvec3( p3.x, p3.y, p3.z );
621 
622  // degenerate points are given a default 0, 0, 1 normal
623  if( S3D::degenerate( pts ) )
624  return SGVECTOR( 0.0, 0.0, 1.0 );
625 
626  // normal
627  tri = glm::cross( pts[1] - pts[0], pts[2] - pts[0] );
628  glm::normalize( tri );
629 
630  return SGVECTOR( tri.x, tri.y, tri.z );
631 }
double x
Definition: sg_base.h:70
double y
Definition: sg_base.h:71
double z
Definition: sg_base.h:72
bool degenerate(glm::dvec3 *pts)
Definition: sg_helpers.cpp:339
bool S3D::Configure3DPaths ( wxWindow *  aParent,
S3D_FILENAME_RESOLVER aResolver 
)

Definition at line 54 of file 3d_cache_dialogs.cpp.

Referenced by DIALOG_MODULE_MODULE_EDITOR::Cfg3DPath(), DIALOG_MODULE_BOARD_EDITOR::Cfg3DPath(), and DLG_SELECT_3DMODEL::Cfg3DPaths().

55 {
56  DLG_3D_PATH_CONFIG* dp = new DLG_3D_PATH_CONFIG( aParent, aResolver );
57 
58  if( wxID_OK == dp->ShowModal() )
59  {
60  delete dp;
61  return true;
62  }
63 
64  delete dp;
65  return false;
66 }
bool S3D::degenerate ( glm::dvec3 *  pts)

Definition at line 339 of file sg_helpers.cpp.

Referenced by calcTriad(), and CalcTriNorm().

340 {
341  double dx, dy, dz;
342 
343  dx = pts[1].x - pts[0].x;
344  dy = pts[1].y - pts[0].y;
345  dz = pts[1].z - pts[0].z;
346 
347  if( ( dx*dx + dy*dy + dz*dz ) < 1e-15 )
348  return true;
349 
350  dx = pts[2].x - pts[0].x;
351  dy = pts[2].y - pts[0].y;
352  dz = pts[2].z - pts[0].z;
353 
354  if( ( dx*dx + dy*dy + dz*dz ) < 1e-15 )
355  return true;
356 
357  dx = pts[2].x - pts[1].x;
358  dy = pts[2].y - pts[1].y;
359  dz = pts[2].z - pts[1].z;
360 
361  if( ( dx*dx + dy*dy + dz*dz ) < 1e-15 )
362  return true;
363 
364  return false;
365 };
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 543 of file ifsg_api.cpp.

References FREE_S3DMODEL().

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

544 {
545  if( NULL == aModel || NULL == *aModel )
546  return;
547 
548  S3DMODEL* m = *aModel;
549  S3D::FREE_S3DMODEL( *m );
550  delete m;
551  *aModel = NULL;
552 
553  return;
554 }
void FREE_S3DMODEL(S3DMODEL &aModel)
Definition: sg_node.cpp:420
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90
void S3D::DestroyNode ( SGNODE aNode)

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

Referenced by S3D_CACHE::load(), S3D_CACHE::loadCacheData(), and MODEL_VRML::~MODEL_VRML().

215 {
216  if( NULL == aNode )
217  {
218  #ifdef DEBUG
219  do {
220  std::ostringstream ostr;
221  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
222  ostr << BadNode;
223  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
224  } while( 0 );
225  #endif
226 
227  return;
228  }
229 
230  delete aNode;
231 
232  return;
233 }
void S3D::FormatColor ( std::string &  result,
const SGCOLOR aColor 
)

Definition at line 146 of file sg_helpers.cpp.

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

Referenced by SGCOLORS::WriteVRML().

147 {
148  float R, G, B;
149  aColor.GetColor( R, G, B );
150  FormatFloat( result, R );
151 
152  std::string tmp;
153  FormatFloat( tmp, G );
154  result.append( " " );
155  result.append( tmp );
156 
157  FormatFloat( tmp, B );
158  result.append( " " );
159  result.append( tmp );
160 
161  return;
162 }
void FormatFloat(std::string &result, double value)
Definition: sg_helpers.cpp:37
void GetColor(float &aRedVal, float &aGreenVal, float &aBlueVal) const
Definition: sg_base.cpp:65
void S3D::FormatFloat ( std::string &  result,
double  value 
)

Definition at line 37 of file sg_helpers.cpp.

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

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 
56  if( std::string::npos == p )
57  return;
58 
59  p = result.find_first_of( "eE" );
60 
61  if( std::string::npos == p )
62  {
63  while( '0' == *(result.rbegin()) )
64  result.erase( result.size() - 1 );
65 
66  return;
67  }
68 
69  if( '0' != result.at( p -1 ) )
70  return;
71 
72  // trim all 0 to the left of 'p'
73  std::string tmp = result.substr( p );
74  result = result.substr( 0, p );
75 
76  while( '0' == *(result.rbegin()) )
77  result.erase( result.size() - 1 );
78 
79  result.append( tmp );
80 
81  return;
82 }
void S3D::FormatOrientation ( std::string &  result,
const SGVECTOR axis,
double  rotation 
)

Definition at line 85 of file sg_helpers.cpp.

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

Referenced by SCENEGRAPH::WriteVRML().

86 {
87  double aX;
88  double aY;
89  double aZ;
90 
91  axis.GetVector( aX, aY, aZ );
92  FormatFloat( result, aX );
93  std::string tmp;
94  FormatFloat( tmp, aY );
95  result.append( " " );
96  result.append( tmp );
97  FormatFloat( tmp, aZ );
98  result.append( " " );
99  result.append( tmp );
100  FormatFloat( tmp, rotation );
101  result.append( " " );
102  result.append( tmp );
103 
104  return;
105 }
void FormatFloat(std::string &result, double value)
Definition: sg_helpers.cpp:37
void GetVector(double &aXVal, double &aYVal, double &aZVal) const
Definition: sg_base.cpp:283
void S3D::FormatPoint ( std::string &  result,
const SGPOINT point 
)

Definition at line 108 of file sg_helpers.cpp.

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

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

109 {
110  FormatFloat( result, point.x );
111 
112  std::string tmp;
113  FormatFloat( tmp, point.y );
114  result.append( " " );
115  result.append( tmp );
116 
117  FormatFloat( tmp, point.z );
118  result.append( " " );
119  result.append( tmp );
120 
121  return;
122 }
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
void S3D::FormatVector ( std::string &  result,
const SGVECTOR aVector 
)

Definition at line 126 of file sg_helpers.cpp.

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

Referenced by SGNORMALS::WriteVRML().

127 {
128  double X, Y, Z;
129  aVector.GetVector( X, Y, Z );
130  FormatFloat( result, X );
131 
132  std::string tmp;
133  FormatFloat( tmp, Y );
134  result.append( " " );
135  result.append( tmp );
136 
137  FormatFloat( tmp, Z );
138  result.append( " " );
139  result.append( tmp );
140 
141  return;
142 }
void FormatFloat(std::string &result, double value)
Definition: sg_helpers.cpp:37
void GetVector(double &aXVal, double &aYVal, double &aZVal) const
Definition: sg_base.cpp:283
void S3D::Free3DMesh ( SMESH aMesh)

Function Free3DMesh frees memory used internally by an SMESH structure.

Definition at line 564 of file ifsg_api.cpp.

References FREE_SMESH().

Referenced by GetModel().

565 {
566  S3D::FREE_SMESH( aMesh );
567  return;
568 }
void FREE_SMESH(SMESH &aMesh)
Definition: sg_node.cpp:380
SGLIB_API void S3D::Free3DModel ( S3DMODEL aModel)

Function Free3DModel frees memory used internally by an S3DMODEL structure.

Definition at line 557 of file ifsg_api.cpp.

References FREE_S3DMODEL().

558 {
559  S3D::FREE_S3DMODEL( aModel );
560  return;
561 }
void FREE_S3DMODEL(S3DMODEL &aModel)
Definition: sg_node.cpp:420
void S3D::FREE_S3DMODEL ( S3DMODEL aModel)

Definition at line 420 of file sg_node.cpp.

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

Referenced by Destroy3DModel(), and Free3DModel().

421 {
422  if( NULL != aModel.m_Materials )
423  {
424  delete [] aModel.m_Materials;
425  aModel.m_Materials = NULL;
426  }
427 
428  aModel.m_MaterialsSize = 0;
429 
430  if( NULL != aModel.m_Meshes )
431  {
432  for( unsigned int i = 0; i < aModel.m_MeshesSize; ++i )
433  FREE_SMESH( aModel.m_Meshes[i] );
434 
435  delete [] aModel.m_Meshes;
436  aModel.m_Meshes = NULL;
437  }
438 
439  aModel.m_MeshesSize = 0;
440 
441  return;
442 }
SMESH * m_Meshes
The meshes list of this model.
Definition: c3dmodel.h:93
void FREE_SMESH(SMESH &aMesh)
Definition: sg_node.cpp:380
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
unsigned int m_MeshesSize
Number of meshes in the array.
Definition: c3dmodel.h:92
void S3D::FREE_SMESH ( SMESH aMesh)

Definition at line 380 of file sg_node.cpp.

References SMESH::m_Color, SMESH::m_FaceIdx, SMESH::m_FaceIdxSize, SMESH::m_MaterialIdx, SMESH::m_Normals, SMESH::m_Positions, SMESH::m_Texcoords, and SMESH::m_VertexSize.

Referenced by Free3DMesh(), and FREE_S3DMODEL().

381 {
382  if( NULL != aMesh.m_Positions )
383  {
384  delete [] aMesh.m_Positions;
385  aMesh.m_Positions = NULL;
386  }
387 
388  if( NULL != aMesh.m_Normals )
389  {
390  delete [] aMesh.m_Normals;
391  aMesh.m_Normals = NULL;
392  }
393 
394  if( NULL != aMesh.m_Texcoords )
395  {
396  delete [] aMesh.m_Texcoords;
397  aMesh.m_Texcoords = NULL;
398  }
399 
400  if( NULL != aMesh.m_Color )
401  {
402  delete [] aMesh.m_Color;
403  aMesh.m_Color = NULL;
404  }
405 
406  if( NULL != aMesh.m_FaceIdx )
407  {
408  delete [] aMesh.m_FaceIdx;
409  aMesh.m_FaceIdx = NULL;
410  }
411 
412  aMesh.m_VertexSize = 0;
413  aMesh.m_FaceIdxSize = 0;
414  aMesh.m_MaterialIdx = 0;
415 
416  return;
417 }
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
void S3D::GetLibVersion ( unsigned char *  Major,
unsigned char *  Minor,
unsigned char *  Patch,
unsigned char *  Revision 
)

Function GetLibVersion retrieves version information of the kicad_3dsg library.

Definition at line 594 of file ifsg_api.cpp.

References KICADSG_VERSION_MAJOR, KICADSG_VERSION_MINOR, KICADSG_VERSION_PATCH, and KICADSG_VERSION_REVISION.

596 {
597  if( Major )
598  *Major = KICADSG_VERSION_MAJOR;
599 
600  if( Minor )
601  *Minor = KICADSG_VERSION_MINOR;
602 
603  if( Revision )
604  *Revision = KICADSG_VERSION_REVISION;
605 
606  if( Patch )
607  *Patch = KICADSG_VERSION_PATCH;
608 
609  return;
610 }
#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
bool S3D::GetMatIndex ( MATLIST aList,
SGNODE aNode,
int &  aIndex 
)

Definition at line 313 of file sg_node.cpp.

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

Referenced by SGSHAPE::Prepare().

314 {
315  aIndex = 0;
316 
317  if( NULL == aNode || S3D::SGTYPE_APPEARANCE != aNode->GetNodeType() )
318  {
319  #ifdef DEBUG
320  std::ostringstream ostr;
321  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__;
322  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
323  ostr.str( "" );
324 
325  if( NULL == aNode )
326  {
327  wxLogTrace( MASK_3D_SG, " * [BUG] aNode is NULL\n" );
328  }
329  else
330  {
331  ostr << " * [BUG] invalid node type (" << aNode->GetNodeType();
332  ostr << "), expected " << S3D::SGTYPE_APPEARANCE;
333  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
334  }
335  #endif
336 
337  return false;
338  }
339 
340  SGAPPEARANCE* node = (SGAPPEARANCE*)aNode;
341 
342  std::map< SGAPPEARANCE const*, int >::iterator it = aList.matmap.find( node );
343 
344  if( it != aList.matmap.end() )
345  {
346  aIndex = it->second;
347  return true;
348  }
349 
350  int idx = (int)aList.matorder.size();
351  aList.matorder.push_back( node );
352  aList.matmap.insert( std::pair< SGAPPEARANCE const*, int >( node, idx ) );
353  aIndex = idx;
354 
355  return true;
356 }
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
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 478 of file ifsg_api.cpp.

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(), and PCB_BASE_EDIT_FRAME::PutDataInPreviousState().

479 {
480  if( NULL == aNode )
481  return NULL;
482 
483  if( aNode->GetNodeType() != S3D::SGTYPE_TRANSFORM )
484  return NULL;
485 
486  S3D::MATLIST materials;
487  std::vector< SMESH > meshes;
488 
489  // the materials list shall have a default color; although the VRML
490  // default is an opaque black, the default used here shall be a median
491  // gray in hopes that it may help highlight faulty models; this color is
492  // also typical of MCAD applications. When a model has no associated
493  // material color it shall be assigned the index 0.
494  SGAPPEARANCE app( NULL );
495  app.ambient = SGCOLOR( 0.6, 0.6, 0.6 );
496  app.diffuse = SGCOLOR( 0.6, 0.6, 0.6 );
497  app.specular = app.diffuse;
498  app.shininess = 0.05;
499  app.transparency = 0.0;
500 
501  materials.matorder.push_back( &app );
502  materials.matmap.insert( std::pair< SGAPPEARANCE const*, int >( &app, 0 ) );
503 
504  if( aNode->Prepare( NULL, materials, meshes ) )
505  {
506  if( meshes.empty() )
507  return NULL;
508 
509  S3DMODEL* model = S3D::New3DModel();
510 
511  // add all the materials
512  size_t j = materials.matorder.size();
513  SMATERIAL* lmat = new SMATERIAL[j];
514 
515  for( size_t i = 0; i < j; ++i )
516  formatMaterial( lmat[i], materials.matorder[i] );
517 
518  model->m_Materials = lmat;
519  model->m_MaterialsSize = j;
520 
521  // add all the meshes
522  j = meshes.size();
523  SMESH* lmesh = new SMESH[j];
524 
525  for( size_t i = 0; i < j; ++i )
526  lmesh[i] = meshes[i];
527 
528  model->m_Meshes = lmesh;
529  model->m_MeshesSize = j;
530 
531  return model;
532  }
533 
534  size_t j = meshes.size();
535 
536  for( size_t i = 0; i < j; ++i )
537  S3D::Free3DMesh( meshes[i] );
538 
539  return NULL;
540 }
SGLIB_API S3DMODEL * New3DModel(void)
Function New3DModel creates and initializes an S3DMODEL struct.
Definition: ifsg_api.cpp:571
std::map< SGAPPEARANCE const *, int > matmap
Definition: sg_node.h:58
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
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:47
unsigned int m_MaterialsSize
Number of materials in the material array.
Definition: c3dmodel.h:95
std::vector< SGAPPEARANCE const * > matorder
Definition: sg_node.h:57
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
bool Prepare(const glm::dmat4 *aTransform, S3D::MATLIST &materials, std::vector< SMESH > &meshes)
Definition: scenegraph.cpp:737
SGLIB_API void Free3DMesh(SMESH &aMesh)
Function Free3DMesh frees memory used internally by an SMESH structure.
Definition: ifsg_api.cpp:564
char const * S3D::GetNodeTypeName ( S3D::SGTYPES  aType)

Function GetNodeTypeName returns the name of the given type of node.

Definition at line 51 of file sg_node.cpp.

References node_names.

Referenced by ReadTag().

52 {
53  return node_names[aType].c_str();
54 }
static const std::string node_names[S3D::SGTYPE_END+1]
Definition: sg_node.cpp:34
SGNODE * S3D::GetSGNodeParent ( SGNODE aNode)

Definition at line 643 of file ifsg_api.cpp.

References SGNODE::GetParent().

Referenced by create_vrml_plane(), create_vrml_shell(), export_vrml_module(), and MODEL_VRML::~MODEL_VRML().

644 {
645  if( NULL == aNode )
646  return NULL;
647 
648  return aNode->GetParent();
649 }
SGNODE * GetParent(void) const
Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no...
Definition: sg_node.cpp:114
S3D::SGTYPES S3D::GetSGNodeType ( SGNODE aNode)

Definition at line 634 of file ifsg_api.cpp.

References SGNODE::GetNodeType(), and SGTYPE_END.

635 {
636  if( NULL == aNode )
637  return SGTYPE_END;
638 
639  return aNode->GetNodeType();
640 }
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
void S3D::Init3DMaterial ( SMATERIAL aMat)

Function Init3DMaterial initializes an SMATERIAL struct.

Definition at line 579 of file ifsg_api.cpp.

References INIT_SMATERIAL().

580 {
581  S3D::INIT_SMATERIAL( aMat );
582  return;
583 }
void INIT_SMATERIAL(SMATERIAL &aMaterial)
Definition: sg_node.cpp:359
void S3D::Init3DMesh ( SMESH aMesh)

Function Init3DMesh creates and initializes an SMESH struct.

Definition at line 586 of file ifsg_api.cpp.

References INIT_SMESH().

587 {
588  S3D::INIT_SMESH( aMesh );
589 
590  return;
591 }
void INIT_SMESH(SMESH &aMesh)
Definition: sg_node.cpp:366
void S3D::INIT_S3DMODEL ( S3DMODEL aModel)

Definition at line 373 of file sg_node.cpp.

Referenced by New3DModel().

374 {
375  memset( &aModel, 0, sizeof( aModel ) );
376  return;
377 }
void S3D::INIT_SMATERIAL ( SMATERIAL aMaterial)

Definition at line 359 of file sg_node.cpp.

Referenced by Init3DMaterial().

360 {
361  memset( &aMaterial, 0, sizeof( aMaterial ) );
362  return;
363 }
void S3D::INIT_SMESH ( SMESH aMesh)

Definition at line 366 of file sg_node.cpp.

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

367 {
368  memset( &aMesh, 0, sizeof( aMesh ) );
369  return;
370 }
S3DMODEL * S3D::New3DModel ( void  )

Function New3DModel creates and initializes an S3DMODEL struct.

Definition at line 571 of file ifsg_api.cpp.

References INIT_S3DMODEL().

Referenced by GetModel().

572 {
573  S3DMODEL* mp = new S3DMODEL;
574  S3D::INIT_S3DMODEL( *mp );
575  return mp;
576 }
void INIT_S3DMODEL(S3DMODEL &aModel)
Definition: sg_node.cpp:373
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90
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 328 of file ifsg_api.cpp.

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

Referenced by S3D_CACHE::loadCacheData().

330 {
331  if( NULL == aFileName || aFileName[0] == 0 )
332  return NULL;
333 
334  wxString ofile = wxString::FromUTF8Unchecked( aFileName );
335 
336  if( !wxFileName::FileExists( aFileName ) )
337  {
338  std::ostringstream ostr;
339  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
340  wxString errmsg = _( "no such file" );
341  ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
342  ostr << aFileName << "'";
343  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
344 
345  return NULL;
346  }
347 
348  SGNODE* np = new SCENEGRAPH( NULL );
349 
350  if( NULL == np )
351  {
352  #ifdef DEBUG
353  do {
354  std::ostringstream ostr;
355  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
356  ostr << " * [INFO] failed to instantiate SCENEGRAPH";
357  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
358  } while( 0 );
359  #endif
360 
361  return NULL;
362  }
363 
364  OPEN_ISTREAM( file, aFileName );
365 
366  if( file.fail() )
367  {
368  delete np;
369  std::ostringstream ostr;
370  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
371  wxString errmsg = _( "failed to open file" );
372  ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
373  ostr << aFileName << "'";
374  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
375  return NULL;
376  }
377 
378  // from SG_VERSION_TAG 1, read the version tag; if it's not the expected tag
379  // then we fail to read the cache file
380  do
381  {
382  std::string name;
383  char schar;
384  file.get( schar );
385 
386  if( '(' != schar )
387  {
388  #ifdef DEBUG
389  do {
390  std::ostringstream ostr;
391  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
392  ostr << " * [INFO] corrupt data; missing left parenthesis at position ";
393  ostr << file.tellg();
394  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
395  } while( 0 );
396  #endif
397 
398  CLOSE_STREAM( file );
399  return NULL;
400  }
401 
402  file.get( schar );
403 
404  while( ')' != schar && file.good() )
405  {
406  name.push_back( schar );
407  file.get( schar );
408  }
409 
410  if( name.compare( SG_VERSION_TAG ) )
411  {
412  CLOSE_STREAM( file );
413  return NULL;
414  }
415 
416  } while( 0 );
417 
418  // from SG_VERSION_TAG 2, read the PluginInfo string and check that it matches
419  // version tag; if it's not the expected tag then we fail to read the file
420  do
421  {
422  std::string name;
423  char schar;
424  file.get( schar );
425 
426  if( '(' != schar )
427  {
428  #ifdef DEBUG
429  do {
430  std::ostringstream ostr;
431  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
432  ostr << " * [INFO] corrupt data; missing left parenthesis at position ";
433  ostr << file.tellg();
434  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
435  } while( 0 );
436  #endif
437 
438  CLOSE_STREAM( file );
439  return NULL;
440  }
441 
442  file.get( schar );
443 
444  while( ')' != schar && file.good() )
445  {
446  name.push_back( schar );
447  file.get( schar );
448  }
449 
450  // check the plugin tag
451  if( NULL != aTagCheck && NULL != aPluginMgr && !aTagCheck( name.c_str(), aPluginMgr ) )
452  {
453  CLOSE_STREAM( file );
454  return NULL;
455  }
456 
457  } while( 0 );
458 
459  bool rval = np->ReadCache( file, NULL );
460  CLOSE_STREAM( file );
461 
462  if( !rval )
463  {
464  delete np;
465  std::ostringstream ostr;
466  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
467  wxString errmsg = "problems encountered reading cache file";
468  ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
469  ostr << aFileName << "'";
470  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
471  return NULL;
472  }
473 
474  return np;
475 }
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
virtual bool ReadCache(std::istream &aFile, SGNODE *parentNode)=0
Function ReadCache Reads binary format data from a cache file.
#define SG_VERSION_TAG
Definition: ifsg_api.cpp:44
#define OPEN_ISTREAM(var, name)
const char * name
#define CLOSE_STREAM(var)
bool S3D::ReadColor ( std::istream &  aFile,
SGCOLOR aColor 
)

Definition at line 324 of file sg_helpers.cpp.

References SGCOLOR::SetColor().

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

325 {
326  float r, g, b;
327  aFile.read( (char*)&r, sizeof(float) );
328  aFile.read( (char*)&g, sizeof(float) );
329  aFile.read( (char*)&b, sizeof(float) );
330  aColor.SetColor( r, g, b );
331 
332  if( aFile.fail() )
333  return false;
334 
335  return true;
336 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
bool S3D::ReadPoint ( std::istream &  aFile,
SGPOINT aPoint 
)

Definition at line 296 of file sg_helpers.cpp.

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

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

297 {
298  aFile.read( (char*)&aPoint.x, sizeof( aPoint.x ) );
299  aFile.read( (char*)&aPoint.y, sizeof( aPoint.y ) );
300  aFile.read( (char*)&aPoint.z, sizeof( aPoint.z ) );
301 
302  if( aFile.fail() )
303  return false;
304 
305  return true;
306 }
double x
Definition: sg_base.h:70
double y
Definition: sg_base.h:71
double z
Definition: sg_base.h:72
S3D::SGTYPES S3D::ReadTag ( std::istream &  aFile,
std::string &  aName 
)

Function ReadTag reads 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 208 of file sg_helpers.cpp.

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(), SGFACESET::ReadCache(), and SCENEGRAPH::ReadCache().

209 {
210  char schar;
211  aFile.get( schar );
212 
213  if( '[' != schar )
214  {
215  #ifdef DEBUG
216  std::ostringstream ostr;
217  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
218  ostr << " * [INFO] corrupt data; missing left bracket at position ";
219  ostr << aFile.tellg();
220  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
221  #endif
222 
223  return S3D::SGTYPE_END;
224  }
225 
226  std::string name;
227  aFile.get( schar );
228 
229  while( ']' != schar && aFile.good() )
230  {
231  name.push_back( schar );
232  aFile.get( schar );
233  }
234 
235  if( schar != ']' )
236  {
237  #ifdef DEBUG
238  std::ostringstream ostr;
239  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
240  ostr << " * [INFO] corrupt data; could not find right bracket";
241  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
242  #endif
243 
244  return S3D::SGTYPE_END;
245  }
246 
247  aName = name;
248  size_t upos = name.find( '_' );
249 
250  if( std::string::npos == upos )
251  {
252  #ifdef DEBUG
253  std::ostringstream ostr;
254  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
255  ostr << " * [INFO] corrupt data; no underscore in name '";
256  ostr << name << "'";
257  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
258  #endif
259 
260  return S3D::SGTYPE_END;
261  }
262 
263  name = name.substr( 0, upos );
264  S3D::SGTYPES types[S3D::SGTYPE_END] = {
274  };
275 
276  for( int i = 0; i < S3D::SGTYPE_END; ++i )
277  {
278  if( !name.compare( S3D::GetNodeTypeName( types[i] ) ) )
279  return types[i];
280  }
281 
282  #ifdef DEBUG
283  do {
284  std::ostringstream ostr;
285  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
286  ostr << " * [INFO] corrupt data; no node type matching '";
287  ostr << name << "'";
288  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
289  } while( 0 );
290  #endif
291 
292  return S3D::SGTYPE_END;
293 }
SGTYPES
Definition: sg_types.h:34
const char * name
char const * GetNodeTypeName(S3D::SGTYPES aType)
Function GetNodeTypeName returns the name of the given type of node.
Definition: sg_node.cpp:51
bool S3D::ReadVector ( std::istream &  aFile,
SGVECTOR aVector 
)

Definition at line 309 of file sg_helpers.cpp.

References SGVECTOR::SetVector().

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

310 {
311  double x, y, z;
312  aFile.read( (char*)&x, sizeof(double) );
313  aFile.read( (char*)&y, sizeof(double) );
314  aFile.read( (char*)&z, sizeof(double) );
315  aVector.SetVector( x, y, z );
316 
317  if( aFile.fail() )
318  return false;
319 
320  return true;
321 }
void SetVector(double aXVal, double aYVal, double aZVal)
Definition: sg_base.cpp:292
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 192 of file ifsg_api.cpp.

References SGNODE::ReNameNodes().

193 {
194  if( NULL == aNode )
195  {
196  #ifdef DEBUG
197  do {
198  std::ostringstream ostr;
199  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
200  ostr << BadNode;
201  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
202  } while( 0 );
203  #endif
204 
205  return;
206  }
207 
208  aNode->ReNameNodes();
209 
210  return;
211 }
virtual void ReNameNodes(void)=0
Function ReNameNodes renames a node and all its child nodes in preparation for Write() operations...
void S3D::ResetNodeIndex ( SGNODE aNode)

Function ResetNodeIndex resets the global SG* class indices.

Parameters
aNodemay be any valid SGNODE

Definition at line 170 of file ifsg_api.cpp.

References SGNODE::ResetNodeIndex().

171 {
172  if( NULL == aNode )
173  {
174  #ifdef DEBUG
175  do {
176  std::ostringstream ostr;
177  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
178  ostr << BadNode;
179  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
180  } while( 0 );
181  #endif
182 
183  return;
184  }
185 
186  aNode->ResetNodeIndex();
187 
188  return;
189 }
void ResetNodeIndex(void)
Function ResetNodeIndex resets the global SG* node indices in preparation for Write() operations...
Definition: sg_node.cpp:304
bool S3D::Select3DModel ( wxWindow *  aParent,
S3D_CACHE aCache,
wxString &  prevModelSelectDir,
int &  prevModelWildcard,
S3D_INFO aModel 
)

Definition at line 34 of file 3d_cache_dialogs.cpp.

Referenced by DIALOG_MODULE_MODULE_EDITOR::BrowseAndAdd3DShapeFile(), and DIALOG_MODULE_BOARD_EDITOR::BrowseAndAdd3DShapeFile().

36 {
37  if( NULL == aModel )
38  return false;
39 
40  DLG_SELECT_3DMODEL* dm = new DLG_SELECT_3DMODEL( aParent, aCache, aModel,
41  prevModelSelectDir, prevModelWildcard );
42 
43  if( wxID_OK == dm->ShowModal() )
44  {
45  delete dm;
46  return true;
47  }
48 
49  delete dm;
50  return false;
51 }
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 236 of file ifsg_api.cpp.

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

Referenced by S3D_CACHE::saveCacheData().

238 {
239  if( NULL == aFileName || aFileName[0] == 0 )
240  return false;
241 
242  wxString ofile = wxString::FromUTF8Unchecked( aFileName );
243 
244  if( NULL == aNode )
245  {
246  #ifdef DEBUG
247  do {
248  std::ostringstream ostr;
249  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
250  ostr << BadNode;
251  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
252  } while( 0 );
253  #endif
254 
255  return false;
256  }
257 
258 
259  if( wxFileName::Exists( ofile ) )
260  {
261  if( !overwrite )
262  {
263  std::ostringstream ostr;
264  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
265  wxString errmsg = _( "file exists; not overwriting" );
266  ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
267  ostr << aFileName << "'";
268  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
269 
270  return false;
271  }
272 
273  // make sure we make no attempt to write a directory
274  if( !wxFileName::FileExists( aFileName ) )
275  {
276  std::ostringstream ostr;
277  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
278  wxString errmsg = _( "specified path is a directory" );
279  ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
280  ostr << aFileName << "'";
281  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
282  return false;
283  }
284  }
285 
286  OPEN_OSTREAM( output, aFileName );
287 
288  if( output.fail() )
289  {
290  std::ostringstream ostr;
291  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
292  wxString errmsg = _( "failed to open file" );
293  ostr << " * [INFO] " << errmsg.ToUTF8() << " '" << aFileName << "'";
294  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
295  return false;
296  }
297 
298  output << "(" << SG_VERSION_TAG << ")";
299 
300  if( NULL != aPluginInfo && aPluginInfo[0] != 0 )
301  output << "(" << aPluginInfo << ")";
302  else
303  output << "(INTERNAL:0.0.0.0)";
304 
305  bool rval = aNode->WriteCache( output, NULL );
306  CLOSE_STREAM( output );
307 
308  if( !rval )
309  {
310  #ifdef DEBUG
311  do {
312  std::ostringstream ostr;
313  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
314  ostr << " * [INFO] problems encountered writing cache file '";
315  ostr << aFileName << "'";
316  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
317  } while( 0 );
318  #endif
319 
320  // delete the defective file
321  wxRemoveFile( ofile );
322  }
323 
324  return rval;
325 }
#define OPEN_OSTREAM(var, name)
#define SG_VERSION_TAG
Definition: ifsg_api.cpp:44
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Function WriteCache write's this node's data to a binary cache file; the data includes all data of ch...
#define CLOSE_STREAM(var)
bool S3D::WriteColor ( std::ostream &  aFile,
const SGCOLOR aColor 
)

Definition at line 193 of file sg_helpers.cpp.

References SGCOLOR::GetColor().

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

194 {
195  float r, g, b;
196  aColor.GetColor( r, g, b );
197  aFile.write( (char*)&r, sizeof(float) );
198  aFile.write( (char*)&g, sizeof(float) );
199  aFile.write( (char*)&b, sizeof(float) );
200 
201  if( aFile.fail() )
202  return false;
203 
204  return true;
205 }
void GetColor(float &aRedVal, float &aGreenVal, float &aBlueVal) const
Definition: sg_base.cpp:65
bool S3D::WritePoint ( std::ostream &  aFile,
const SGPOINT aPoint 
)

Definition at line 165 of file sg_helpers.cpp.

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

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

166 {
167  aFile.write( (char*)&aPoint.x, sizeof(aPoint.x) );
168  aFile.write( (char*)&aPoint.y, sizeof(aPoint.y) );
169  aFile.write( (char*)&aPoint.z, sizeof(aPoint.z) );
170 
171  if( aFile.fail() )
172  return false;
173 
174  return true;
175 }
double x
Definition: sg_base.h:70
double y
Definition: sg_base.h:71
double z
Definition: sg_base.h:72
bool S3D::WriteVector ( std::ostream &  aFile,
const SGVECTOR aVector 
)

Definition at line 178 of file sg_helpers.cpp.

References SGVECTOR::GetVector().

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

179 {
180  double x, y, z;
181  aVector.GetVector( x, y, z );
182  aFile.write( (char*)&x, sizeof(double) );
183  aFile.write( (char*)&y, sizeof(double) );
184  aFile.write( (char*)&z, sizeof(double) );
185 
186  if( aFile.fail() )
187  return false;
188 
189  return true;
190 }
void GetVector(double &aXVal, double &aYVal, double &aZVal) const
Definition: sg_base.cpp:283
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 81 of file ifsg_api.cpp.

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

Referenced by export_vrml_module(), and write_layers().

83 {
84  if( NULL == filename || filename[0] == 0 )
85  return false;
86 
87  wxString ofile = wxString::FromUTF8Unchecked( filename );
88 
89  if( wxFileName::Exists( ofile ) )
90  {
91  if( !overwrite )
92  return false;
93 
94  // make sure we make no attempt to write a directory
95  if( !wxFileName::FileExists( ofile ) )
96  return false;
97  }
98 
99  if( NULL == aTopNode )
100  {
101  #ifdef DEBUG
102  do {
103  std::ostringstream ostr;
104  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
105  ostr << " * [BUG] NULL pointer passed for aTopNode";
106  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
107  } while( 0 );
108  #endif
109 
110  return false;
111  }
112 
113  if( S3D::SGTYPE_TRANSFORM != aTopNode->GetNodeType() )
114  {
115  #ifdef DEBUG
116  do {
117  std::ostringstream ostr;
118  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
119  ostr << " * [BUG] aTopNode is not a SCENEGRAPH object";
120  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
121  } while( 0 );
122  #endif
123 
124  return false;
125  }
126 
127  OPEN_OSTREAM( op, filename );
128 
129  if( op.fail() )
130  {
131  std::ostringstream ostr;
132  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
133  wxString errmsg = _( "failed to open file" );
134  ostr << " * [INFO] " << errmsg.ToUTF8() << " '" << filename << "'";
135  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
136  return false;
137  }
138 
139  op.imbue( std::locale( "C" ) );
140  op << "#VRML V2.0 utf8\n";
141 
142  if( renameNodes )
143  {
144  aTopNode->ResetNodeIndex();
145  aTopNode->ReNameNodes();
146  }
147 
148  aTopNode->WriteVRML( op, reuse );
149 
150  if( !op.fail() )
151  {
152  CLOSE_STREAM( op );
153  return true;
154  }
155 
156  CLOSE_STREAM( op );
157 
158  do {
159  std::ostringstream ostr;
160  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
161  wxString errmsg = _( "problems encountered writing file" );
162  ostr << " * [INFO] " << errmsg.ToUTF8() << " '" << filename << "'";
163  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
164  } while( 0 );
165 
166  return false;
167 }
virtual void ReNameNodes(void)=0
Function ReNameNodes renames a node and all its child nodes in preparation for Write() operations...
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
#define OPEN_OSTREAM(var, name)
#define CLOSE_STREAM(var)
void ResetNodeIndex(void)
Function ResetNodeIndex resets the global SG* node indices in preparation for Write() operations...
Definition: sg_node.cpp:304
virtual bool WriteVRML(std::ostream &aFile, bool aReuseFlag)=0
Function WriteVRML writes this node's data to a VRML file; this includes all data of child and refere...