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.

165 lines
3.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
  5. * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <iostream>
  25. #include <sstream>
  26. #include <wx/log.h>
  27. #include "plugins/3dapi/ifsg_node.h"
  28. #include "3d_cache/sg/sg_node.h"
  29. #include "plugins/3dapi/ifsg_api.h"
  30. // collection of common error strings used by the wrappers
  31. char BadObject[] = " * [BUG] operating on an invalid wrapper (object may have been deleted)";
  32. char BadOperand[] = " * [BUG] parameter aNode is an invalid wrapper; its data may have been deleted";
  33. char BadParent[] = " * [BUG] invalid parent node (data may have been deleted)";
  34. char WrongParent[] = " * [BUG] parent node type is incompatible";
  35. IFSG_NODE::IFSG_NODE()
  36. {
  37. m_node = nullptr;
  38. }
  39. IFSG_NODE::~IFSG_NODE()
  40. {
  41. if( m_node )
  42. m_node->DisassociateWrapper( &m_node );
  43. }
  44. void IFSG_NODE::Destroy( void )
  45. {
  46. if( m_node )
  47. m_node->DisassociateWrapper( &m_node );
  48. delete m_node;
  49. m_node = nullptr;
  50. }
  51. SGNODE* IFSG_NODE::GetRawPtr( void ) noexcept
  52. {
  53. return m_node;
  54. }
  55. S3D::SGTYPES IFSG_NODE::GetNodeType( void ) const
  56. {
  57. wxCHECK( m_node, S3D::SGTYPE_END );
  58. return m_node->GetNodeType();
  59. }
  60. SGNODE* IFSG_NODE::GetParent( void ) const
  61. {
  62. wxCHECK( m_node, nullptr );
  63. return m_node->GetParent();
  64. }
  65. bool IFSG_NODE::SetParent( SGNODE* aParent )
  66. {
  67. wxCHECK( m_node, false );
  68. return m_node->SetParent( aParent );
  69. }
  70. const char* IFSG_NODE::GetName( void )
  71. {
  72. wxCHECK( m_node, nullptr );
  73. return m_node->GetName();
  74. }
  75. bool IFSG_NODE::SetName( const char* aName )
  76. {
  77. wxCHECK( m_node, false );
  78. m_node->SetName( aName );
  79. return true;
  80. }
  81. const char* IFSG_NODE::GetNodeTypeName( S3D::SGTYPES aNodeType ) const
  82. {
  83. wxCHECK( m_node, nullptr );
  84. return m_node->GetNodeTypeName( aNodeType );
  85. }
  86. SGNODE* IFSG_NODE::FindNode( const char* aNodeName )
  87. {
  88. wxCHECK( m_node, nullptr );
  89. return m_node->FindNode( aNodeName, nullptr );
  90. }
  91. bool IFSG_NODE::AddRefNode( SGNODE* aNode )
  92. {
  93. wxCHECK( m_node, false );
  94. return m_node->AddRefNode( aNode );
  95. }
  96. bool IFSG_NODE::AddRefNode( IFSG_NODE& aNode )
  97. {
  98. wxCHECK( m_node, false );
  99. SGNODE* np = aNode.GetRawPtr();
  100. wxCHECK( np, false );
  101. return m_node->AddRefNode( np );
  102. }
  103. bool IFSG_NODE::AddChildNode( SGNODE* aNode )
  104. {
  105. wxCHECK( m_node, false );
  106. return m_node->AddChildNode( aNode );
  107. }
  108. bool IFSG_NODE::AddChildNode( IFSG_NODE& aNode )
  109. {
  110. wxCHECK( m_node, false );
  111. SGNODE* np = aNode.GetRawPtr();
  112. wxCHECK( np, false );
  113. return m_node->AddChildNode( np );
  114. }