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, MODULE_3D_SETTINGS *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 654 of file ifsg_api.cpp.

References SGNODE::AddChildNode().

655 {
656  if( NULL == aParent || NULL == aChild )
657  return false;
658 
659  return aParent->AddChildNode( aChild );
660 }
virtual bool AddChildNode(SGNODE *aNode)=0
bool S3D::AddSGNodeRef ( SGNODE aParent,
SGNODE aChild 
)

Definition at line 645 of file ifsg_api.cpp.

References SGNODE::AddRefNode().

646 {
647  if( NULL == aParent || NULL == aChild )
648  return false;
649 
650  return aParent->AddRefNode( aChild );
651 }
virtual bool AddRefNode(SGNODE *aNode)=0
void S3D::AssociateSGNodeWrapper ( SGNODE aObject,
SGNODE **  aRefPtr 
)

Definition at line 663 of file ifsg_api.cpp.

References SGNODE::AssociateWrapper().

664 {
665  if( NULL == aObject || NULL == aRefPtr || aObject != *aRefPtr )
666  return;
667 
668  aObject->AssociateWrapper( aRefPtr );
669 
670  return;
671 }
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 606 of file ifsg_api.cpp.

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

Referenced by create_vrml_shell().

607 {
608  glm::dvec3 tri = glm::dvec3( 0.0, 0.0, 0.0 );
609  glm::dvec3 pts[3];
610 
611  pts[0] = glm::dvec3( p1.x, p1.y, p1.z );
612  pts[1] = glm::dvec3( p2.x, p2.y, p2.z );
613  pts[2] = glm::dvec3( p3.x, p3.y, p3.z );
614 
615  // degenerate points are given a default 0, 0, 1 normal
616  if( S3D::degenerate( pts ) )
617  return SGVECTOR( 0.0, 0.0, 1.0 );
618 
619  // normal
620  tri = glm::cross( pts[1] - pts[0], pts[2] - pts[0] );
621  glm::normalize( tri );
622 
623  return SGVECTOR( tri.x, tri.y, tri.z );
624 }
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 536 of file ifsg_api.cpp.

References FREE_S3DMODEL().

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

537 {
538  if( NULL == aModel || NULL == *aModel )
539  return;
540 
541  S3DMODEL* m = *aModel;
542  S3D::FREE_S3DMODEL( *m );
543  delete m;
544  *aModel = NULL;
545 
546  return;
547 }
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 210 of file ifsg_api.cpp.

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

211 {
212  if( NULL == aNode )
213  {
214  #ifdef DEBUG
215  do {
216  std::ostringstream ostr;
217  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
218  ostr << BadNode;
219  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
220  } while( 0 );
221  #endif
222 
223  return;
224  }
225 
226  delete aNode;
227 
228  return;
229 }
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 557 of file ifsg_api.cpp.

References FREE_SMESH().

Referenced by GetModel().

558 {
559  S3D::FREE_SMESH( aMesh );
560  return;
561 }
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 550 of file ifsg_api.cpp.

References FREE_S3DMODEL().

551 {
552  S3D::FREE_S3DMODEL( aModel );
553  return;
554 }
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 587 of file ifsg_api.cpp.

References KICADSG_VERSION_MAJOR, KICADSG_VERSION_MINOR, KICADSG_VERSION_PATCH, and KICADSG_VERSION_REVISION.

589 {
590  if( Major )
591  *Major = KICADSG_VERSION_MAJOR;
592 
593  if( Minor )
594  *Minor = KICADSG_VERSION_MINOR;
595 
596  if( Revision )
597  *Revision = KICADSG_VERSION_REVISION;
598 
599  if( Patch )
600  *Patch = KICADSG_VERSION_PATCH;
601 
602  return;
603 }
#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 471 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().

472 {
473  if( NULL == aNode )
474  return NULL;
475 
476  if( aNode->GetNodeType() != S3D::SGTYPE_TRANSFORM )
477  return NULL;
478 
479  S3D::MATLIST materials;
480  std::vector< SMESH > meshes;
481 
482  // the materials list shall have a default color; although the VRML
483  // default is an opaque black, the default used here shall be a median
484  // gray in hopes that it may help highlight faulty models; this color is
485  // also typical of MCAD applications. When a model has no associated
486  // material color it shall be assigned the index 0.
487  SGAPPEARANCE app( NULL );
488  app.ambient = SGCOLOR( 0.6, 0.6, 0.6 );
489  app.diffuse = SGCOLOR( 0.6, 0.6, 0.6 );
490  app.specular = app.diffuse;
491  app.shininess = 0.05;
492  app.transparency = 0.0;
493 
494  materials.matorder.push_back( &app );
495  materials.matmap.insert( std::pair< SGAPPEARANCE const*, int >( &app, 0 ) );
496 
497  if( aNode->Prepare( NULL, materials, meshes ) )
498  {
499  if( meshes.empty() )
500  return NULL;
501 
502  S3DMODEL* model = S3D::New3DModel();
503 
504  // add all the materials
505  size_t j = materials.matorder.size();
506  SMATERIAL* lmat = new SMATERIAL[j];
507 
508  for( size_t i = 0; i < j; ++i )
509  formatMaterial( lmat[i], materials.matorder[i] );
510 
511  model->m_Materials = lmat;
512  model->m_MaterialsSize = j;
513 
514  // add all the meshes
515  j = meshes.size();
516  SMESH* lmesh = new SMESH[j];
517 
518  for( size_t i = 0; i < j; ++i )
519  lmesh[i] = meshes[i];
520 
521  model->m_Meshes = lmesh;
522  model->m_MeshesSize = j;
523 
524  return model;
525  }
526 
527  size_t j = meshes.size();
528 
529  for( size_t i = 0; i < j; ++i )
530  S3D::Free3DMesh( meshes[i] );
531 
532  return NULL;
533 }
SGLIB_API S3DMODEL * New3DModel(void)
Function New3DModel creates and initializes an S3DMODEL struct.
Definition: ifsg_api.cpp:564
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:557
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 636 of file ifsg_api.cpp.

References SGNODE::GetParent().

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

637 {
638  if( NULL == aNode )
639  return NULL;
640 
641  return aNode->GetParent();
642 }
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 627 of file ifsg_api.cpp.

References SGNODE::GetNodeType(), and SGTYPE_END.

628 {
629  if( NULL == aNode )
630  return SGTYPE_END;
631 
632  return aNode->GetNodeType();
633 }
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 572 of file ifsg_api.cpp.

References INIT_SMATERIAL().

573 {
574  S3D::INIT_SMATERIAL( aMat );
575  return;
576 }
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 579 of file ifsg_api.cpp.

References INIT_SMESH().

580 {
581  S3D::INIT_SMESH( aMesh );
582 
583  return;
584 }
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 564 of file ifsg_api.cpp.

References INIT_S3DMODEL().

Referenced by GetModel().

565 {
566  S3DMODEL* mp = new S3DMODEL;
567  S3D::INIT_S3DMODEL( *mp );
568  return mp;
569 }
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 321 of file ifsg_api.cpp.

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

Referenced by S3D_CACHE::loadCacheData().

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

References SGNODE::ReNameNodes().

189 {
190  if( NULL == aNode )
191  {
192  #ifdef DEBUG
193  do {
194  std::ostringstream ostr;
195  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
196  ostr << BadNode;
197  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
198  } while( 0 );
199  #endif
200 
201  return;
202  }
203 
204  aNode->ReNameNodes();
205 
206  return;
207 }
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 166 of file ifsg_api.cpp.

References SGNODE::ResetNodeIndex().

167 {
168  if( NULL == aNode )
169  {
170  #ifdef DEBUG
171  do {
172  std::ostringstream ostr;
173  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
174  ostr << BadNode;
175  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
176  } while( 0 );
177  #endif
178 
179  return;
180  }
181 
182  aNode->ResetNodeIndex();
183 
184  return;
185 }
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,
MODULE_3D_SETTINGS 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 232 of file ifsg_api.cpp.

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

Referenced by S3D_CACHE::saveCacheData().

234 {
235  if( NULL == aFileName || aFileName[0] == 0 )
236  return false;
237 
238  wxString ofile = wxString::FromUTF8Unchecked( aFileName );
239 
240  if( NULL == aNode )
241  {
242  #ifdef DEBUG
243  do {
244  std::ostringstream ostr;
245  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
246  ostr << BadNode;
247  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
248  } while( 0 );
249  #endif
250 
251  return false;
252  }
253 
254 
255  if( wxFileName::Exists( ofile ) )
256  {
257  if( !overwrite )
258  {
259  wxString errmsg;
260  errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
261  errmsg << " * [INFO] " << "file exists; not overwriting" << " '";
262  errmsg << aFileName << "'";
263  wxLogTrace( MASK_3D_SG, errmsg );
264 
265  return false;
266  }
267 
268  // make sure we make no attempt to write a directory
269  if( !wxFileName::FileExists( aFileName ) )
270  {
271  wxString errmsg;
272  errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
273  errmsg << " * [INFO] " << "specified path is a directory" << " '";
274  errmsg << aFileName << "'";
275  wxLogTrace( MASK_3D_SG, errmsg );
276  return false;
277  }
278  }
279 
280  OPEN_OSTREAM( output, aFileName );
281 
282  if( output.fail() )
283  {
284  wxString errmsg;
285  errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
286  errmsg << " * [INFO] " << "failed to open file" << " '" << aFileName << "'";
287  wxLogTrace( MASK_3D_SG, errmsg );
288  return false;
289  }
290 
291  output << "(" << SG_VERSION_TAG << ")";
292 
293  if( NULL != aPluginInfo && aPluginInfo[0] != 0 )
294  output << "(" << aPluginInfo << ")";
295  else
296  output << "(INTERNAL:0.0.0.0)";
297 
298  bool rval = aNode->WriteCache( output, NULL );
299  CLOSE_STREAM( output );
300 
301  if( !rval )
302  {
303  #ifdef DEBUG
304  do {
305  std::ostringstream ostr;
306  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
307  ostr << " * [INFO] problems encountered writing cache file '";
308  ostr << aFileName << "'";
309  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
310  } while( 0 );
311  #endif
312 
313  // delete the defective file
314  wxRemoveFile( ofile );
315  }
316 
317  return rval;
318 }
#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  wxString errmsg;
132  errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
133  errmsg << " * [INFO] " << "failed to open file" << " '" << filename << "'";
134  wxLogTrace( MASK_3D_SG, errmsg );
135  return false;
136  }
137 
138  op.imbue( std::locale( "C" ) );
139  op << "#VRML V2.0 utf8\n";
140 
141  if( renameNodes )
142  {
143  aTopNode->ResetNodeIndex();
144  aTopNode->ReNameNodes();
145  }
146 
147  aTopNode->WriteVRML( op, reuse );
148 
149  if( !op.fail() )
150  {
151  CLOSE_STREAM( op );
152  return true;
153  }
154 
155  CLOSE_STREAM( op );
156 
157  wxString errmsg;
158  errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
159  errmsg << " * [INFO] " << "problems encountered writing file" << " '" << filename << "'";
160  wxLogTrace( MASK_3D_SG, errmsg );
161 
162  return false;
163 }
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...