You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
4.7 KiB

17 years ago
17 years ago
17 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. /**
  24. * @file 3d_class.cpp
  25. */
  26. #include <fctsys.h>
  27. #include "3d_viewer.h"
  28. #include "3d_struct.h"
  29. #include "modelparsers.h"
  30. void S3D_MASTER::Insert( S3D_MATERIAL* aMaterial )
  31. {
  32. aMaterial->SetNext( m_Materials );
  33. m_Materials = aMaterial;
  34. }
  35. void S3D_MASTER::Copy( S3D_MASTER* pattern )
  36. {
  37. SetShape3DName( pattern->GetShape3DName() );
  38. m_MatScale = pattern->m_MatScale;
  39. m_MatRotation = pattern->m_MatRotation;
  40. m_MatPosition = pattern->m_MatPosition;
  41. m_3D_Drawings = NULL;
  42. m_Materials = NULL;
  43. }
  44. S3D_MASTER::S3D_MASTER( EDA_ITEM* aParent ) :
  45. EDA_ITEM( aParent, NOT_USED )
  46. {
  47. m_MatScale.x = m_MatScale.y = m_MatScale.z = 1.0;
  48. m_3D_Drawings = NULL;
  49. m_Materials = NULL;
  50. m_parser = NULL;
  51. m_ShapeType = FILE3D_NONE;
  52. m_use_modelfile_diffuseColor = true;
  53. m_use_modelfile_emissiveColor = true;
  54. m_use_modelfile_specularColor = true;
  55. m_use_modelfile_ambientIntensity = true;
  56. m_use_modelfile_transparency = true;
  57. m_use_modelfile_shininess = true;
  58. }
  59. S3D_MASTER:: ~S3D_MASTER()
  60. {
  61. STRUCT_3D_SHAPE* next;
  62. S3D_MATERIAL* nextmat;
  63. for( ; m_3D_Drawings != NULL; m_3D_Drawings = next )
  64. {
  65. next = m_3D_Drawings->Next();
  66. delete m_3D_Drawings;
  67. m_3D_Drawings = 0;
  68. }
  69. for( ; m_Materials != NULL; m_Materials = nextmat )
  70. {
  71. nextmat = m_Materials->Next();
  72. delete m_Materials;
  73. m_Materials = NULL;
  74. }
  75. }
  76. bool S3D_MASTER::Is3DType( enum FILE3D_TYPE aShapeType )
  77. {
  78. // type 'none' is not valid and will always return false
  79. if( aShapeType == FILE3D_NONE )
  80. return false;
  81. // no one is interested if we have no file
  82. if( m_Shape3DName.empty() )
  83. return false;
  84. if( aShapeType == m_ShapeType )
  85. return true;
  86. return false;
  87. }
  88. void S3D_MASTER::SetShape3DName( const wxString& aShapeName )
  89. {
  90. m_ShapeType = FILE3D_NONE;
  91. m_Shape3DName = aShapeName;
  92. if( m_Shape3DName.empty() )
  93. return;
  94. wxFileName fn = m_Shape3DName;
  95. m_Shape3DNameExtension = fn.GetExt();
  96. if( m_Shape3DNameExtension == wxT( "wrl" ) ||
  97. m_Shape3DNameExtension == wxT( "x3d" ) )
  98. m_ShapeType = FILE3D_VRML;
  99. else if( m_Shape3DNameExtension == wxT( "idf" ) )
  100. m_ShapeType = FILE3D_IDF;
  101. else
  102. m_ShapeType = FILE3D_UNKNOWN;
  103. // Expand any environment variables embedded in footprint's m_Shape3DName field.
  104. // To ensure compatibility with most of footprint's m_Shape3DName field,
  105. // if the m_Shape3DName is not an absolute path the default path
  106. // given by the environment variable KISYS3DMOD will be used
  107. if( m_Shape3DName.StartsWith( wxT("${") ) )
  108. m_Shape3DFullFilename = wxExpandEnvVars( m_Shape3DName );
  109. else
  110. m_Shape3DFullFilename = m_Shape3DName;
  111. wxFileName fnFull( m_Shape3DFullFilename );
  112. if( !( fnFull.IsAbsolute() || m_Shape3DFullFilename.StartsWith( wxT(".") ) ) )
  113. {
  114. wxString default_path;
  115. wxGetEnv( KISYS3DMOD, &default_path );
  116. if( !( default_path.IsEmpty() ) )
  117. {
  118. if( !default_path.EndsWith( wxT("/") ) && !default_path.EndsWith( wxT("\\") ) )
  119. default_path += wxT("/");
  120. m_Shape3DFullFilename = default_path + m_Shape3DFullFilename;
  121. }
  122. }
  123. return;
  124. }
  125. const wxString S3D_MASTER::GetShape3DFullFilename()
  126. {
  127. return m_Shape3DFullFilename;
  128. }
  129. const wxString S3D_MASTER::GetShape3DExtension()
  130. {
  131. return m_Shape3DNameExtension;
  132. }
  133. STRUCT_3D_SHAPE::STRUCT_3D_SHAPE( EDA_ITEM* aParent ) :
  134. EDA_ITEM( aParent, NOT_USED )
  135. {
  136. m_3D_Coord = NULL;
  137. m_3D_CoordIndex = NULL;
  138. m_3D_Points = 0;
  139. }
  140. STRUCT_3D_SHAPE:: ~STRUCT_3D_SHAPE()
  141. {
  142. delete m_3D_Coord;
  143. delete m_3D_CoordIndex;
  144. }