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.

120 lines
3.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 NBEE Embedded Systems SL, Miguel Angel Ajo <miguelangel@ajo.es>
  5. * Copyright The 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. /**
  25. * @file footprint_wizard.cpp
  26. * @brief Class FOOTPRINT_WIZARD and FOOTPRINT_WIZARD_LIST
  27. */
  28. #include "footprint_wizard.h"
  29. FOOTPRINT_WIZARD::~FOOTPRINT_WIZARD()
  30. {
  31. }
  32. void FOOTPRINT_WIZARD::register_wizard()
  33. {
  34. FOOTPRINT_WIZARD_LIST::register_wizard( this );
  35. }
  36. std::vector<FOOTPRINT_WIZARD*> FOOTPRINT_WIZARD_LIST::m_FootprintWizards;
  37. FOOTPRINT_WIZARD* FOOTPRINT_WIZARD_LIST::GetWizard( int aIndex )
  38. {
  39. return m_FootprintWizards[aIndex];
  40. }
  41. FOOTPRINT_WIZARD* FOOTPRINT_WIZARD_LIST::GetWizard( const wxString& aName )
  42. {
  43. int max = GetWizardsCount();
  44. for( int i = 0; i<max; i++ )
  45. {
  46. FOOTPRINT_WIZARD* wizard = GetWizard( i );
  47. wxString name = wizard->GetName();
  48. if( name.Cmp( aName )==0 )
  49. return wizard;
  50. }
  51. return nullptr;
  52. }
  53. int FOOTPRINT_WIZARD_LIST::GetWizardsCount()
  54. {
  55. return m_FootprintWizards.size();
  56. }
  57. void FOOTPRINT_WIZARD_LIST::register_wizard( FOOTPRINT_WIZARD* aWizard )
  58. {
  59. // Search for this entry do not register twice this wizard):
  60. for( int ii = 0; ii < GetWizardsCount(); ii++ )
  61. {
  62. if( aWizard == GetWizard( ii ) ) // Already registered
  63. return;
  64. }
  65. // Search for a wizard with the same name, and remove it if found
  66. for( int ii = 0; ii < GetWizardsCount(); ii++ )
  67. {
  68. FOOTPRINT_WIZARD* wizard = GetWizard( ii );
  69. if( wizard->GetName() == aWizard->GetName() )
  70. {
  71. m_FootprintWizards.erase( m_FootprintWizards.begin() + ii );
  72. delete wizard;
  73. break;
  74. }
  75. }
  76. m_FootprintWizards.push_back( aWizard );
  77. }
  78. bool FOOTPRINT_WIZARD_LIST::deregister_object( void* aObject )
  79. {
  80. int max = GetWizardsCount();
  81. for( int ii = 0; ii < max; ii++ )
  82. {
  83. FOOTPRINT_WIZARD* wizard = GetWizard( ii );
  84. if( wizard->GetObject() == aObject )
  85. {
  86. m_FootprintWizards.erase( m_FootprintWizards.begin() + ii );
  87. delete wizard;
  88. return true;
  89. }
  90. }
  91. return false;
  92. }