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.

216 lines
5.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2023 Alex Shvartzkop <dudesuchamazing@gmail.com>
  5. * Copyright (C) 2023 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 <pcb_generator.h>
  25. PCB_GENERATOR::PCB_GENERATOR( BOARD_ITEM* aParent, PCB_LAYER_ID aLayer ) :
  26. PCB_GROUP( aParent, PCB_GENERATOR_T, aLayer )
  27. {
  28. }
  29. PCB_GENERATOR::~PCB_GENERATOR()
  30. {
  31. }
  32. void PCB_GENERATOR::EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
  33. BOARD_COMMIT* aCommit )
  34. {
  35. aCommit->Modify( this );
  36. }
  37. void PCB_GENERATOR::EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
  38. BOARD_COMMIT* aCommit, const wxString& aCommitMsg, int aCommitFlags )
  39. {
  40. aCommit->Push( aCommitMsg, aCommitFlags );
  41. }
  42. void PCB_GENERATOR::EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
  43. BOARD_COMMIT* aCommit )
  44. {
  45. aCommit->Revert();
  46. }
  47. void PCB_GENERATOR::Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
  48. BOARD_COMMIT* aCommit )
  49. {
  50. aCommit->Remove( this );
  51. }
  52. bool PCB_GENERATOR::Update( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
  53. BOARD_COMMIT* aCommit )
  54. {
  55. return true;
  56. }
  57. std::vector<EDA_ITEM*> PCB_GENERATOR::GetPreviewItems( GENERATOR_TOOL* aTool,
  58. PCB_BASE_EDIT_FRAME* aFrame,
  59. bool aStatusItemsOnly )
  60. {
  61. return std::vector<EDA_ITEM*>();
  62. }
  63. bool PCB_GENERATOR::MakeEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints ) const
  64. {
  65. return true;
  66. }
  67. bool PCB_GENERATOR::UpdateFromEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints,
  68. BOARD_COMMIT* aCommit )
  69. {
  70. return true;
  71. }
  72. bool PCB_GENERATOR::UpdateEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints )
  73. {
  74. return true;
  75. }
  76. const BOX2I PCB_GENERATOR::GetBoundingBox() const
  77. {
  78. BOX2I bbox;
  79. return bbox;
  80. }
  81. void PCB_GENERATOR::Move( const VECTOR2I& aMoveVector )
  82. {
  83. m_origin += aMoveVector;
  84. PCB_GROUP::Move( aMoveVector );
  85. }
  86. bool PCB_GENERATOR::AddItem( BOARD_ITEM* aItem )
  87. {
  88. // Items can only be in one group at a time
  89. if( aItem->GetParentGroup() )
  90. aItem->GetParentGroup()->RemoveItem( aItem );
  91. m_items.insert( aItem );
  92. aItem->SetParentGroup( this );
  93. return true;
  94. }
  95. LSET PCB_GENERATOR::GetLayerSet() const
  96. {
  97. return PCB_GROUP::GetLayerSet() | LSET( GetLayer() );
  98. }
  99. void PCB_GENERATOR::SetLayer( PCB_LAYER_ID aLayer )
  100. {
  101. m_layer = aLayer;
  102. }
  103. wxString PCB_GENERATOR::GetGeneratorType() const
  104. {
  105. return m_generatorType;
  106. }
  107. const STRING_ANY_MAP PCB_GENERATOR::GetProperties() const
  108. {
  109. STRING_ANY_MAP props( pcbIUScale.IU_PER_MM );
  110. #ifdef GENERATOR_ORDER
  111. props.set( "update_order", m_updateOrder );
  112. #endif
  113. props.set( "origin", m_origin );
  114. return props;
  115. }
  116. void PCB_GENERATOR::SetProperties( const STRING_ANY_MAP& aProps )
  117. {
  118. #ifdef GENERATOR_ORDER
  119. aProps.get_to( "update_order", m_updateOrder );
  120. #endif
  121. aProps.get_to( "origin", m_origin );
  122. }
  123. std::vector<std::pair<wxString, wxVariant>> PCB_GENERATOR::GetRowData()
  124. {
  125. #ifdef GENERATOR_ORDER
  126. return { { _HKI( "Update Order" ), wxString::FromCDouble( GetUpdateOrder() ) } };
  127. #else
  128. return { {} };
  129. #endif
  130. }
  131. wxString PCB_GENERATOR::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
  132. {
  133. return wxString( _( "Generator" ) );
  134. }
  135. wxString PCB_GENERATOR::GetClass() const
  136. {
  137. return wxS( "PCB_GENERATOR" );
  138. }
  139. bool PCB_GENERATOR::ClassOf( const EDA_ITEM* aItem )
  140. {
  141. return aItem && PCB_GENERATOR_T == aItem->Type();
  142. }
  143. #ifdef GENERATOR_ORDER
  144. static struct PCB_GENERATOR_DESC
  145. {
  146. PCB_GENERATOR_DESC()
  147. {
  148. PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
  149. REGISTER_TYPE( PCB_GENERATOR );
  150. propMgr.AddTypeCast( new TYPE_CAST<PCB_GENERATOR, BOARD_ITEM> );
  151. propMgr.InheritsAfter( TYPE_HASH( PCB_GENERATOR ), TYPE_HASH( BOARD_ITEM ) );
  152. const wxString groupTab = _HKI( "Generator Properties" );
  153. propMgr.AddProperty( new PROPERTY<PCB_GENERATOR, int>( _HKI( "Update Order" ),
  154. &PCB_GENERATOR::SetUpdateOrder,
  155. &PCB_GENERATOR::GetUpdateOrder ),
  156. groupTab );
  157. }
  158. } _PCB_GENERATOR_DESC;
  159. #endif