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.

250 lines
6.2 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. #include <core/mirror.h>
  26. #include <board.h>
  27. PCB_GENERATOR::PCB_GENERATOR( BOARD_ITEM* aParent, PCB_LAYER_ID aLayer ) :
  28. PCB_GROUP( aParent, PCB_GENERATOR_T, aLayer )
  29. {
  30. }
  31. PCB_GENERATOR::~PCB_GENERATOR()
  32. {
  33. }
  34. PCB_GENERATOR* PCB_GENERATOR::DeepClone() const
  35. {
  36. // Use copy constructor to get the same uuid and other fields
  37. PCB_GENERATOR* newGenerator = static_cast<PCB_GENERATOR*>( Clone() );
  38. newGenerator->m_items.clear();
  39. for( BOARD_ITEM* member : m_items )
  40. {
  41. if( member->Type() == PCB_GROUP_T )
  42. newGenerator->AddItem( static_cast<PCB_GROUP*>( member )->DeepClone() );
  43. else
  44. newGenerator->AddItem( static_cast<BOARD_ITEM*>( member->Clone() ) );
  45. }
  46. return newGenerator;
  47. }
  48. void PCB_GENERATOR::EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit )
  49. {
  50. aCommit->Modify( this );
  51. }
  52. void PCB_GENERATOR::EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit,
  53. const wxString& aCommitMsg, int aCommitFlags )
  54. {
  55. aCommit->Push( aCommitMsg, aCommitFlags );
  56. }
  57. void PCB_GENERATOR::EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit )
  58. {
  59. aCommit->Revert();
  60. }
  61. void PCB_GENERATOR::Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit )
  62. {
  63. aCommit->Remove( this );
  64. }
  65. bool PCB_GENERATOR::Update( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit )
  66. {
  67. return true;
  68. }
  69. std::vector<EDA_ITEM*> PCB_GENERATOR::GetPreviewItems( GENERATOR_TOOL* aTool,
  70. PCB_BASE_EDIT_FRAME* aFrame,
  71. bool aStatusItemsOnly )
  72. {
  73. return std::vector<EDA_ITEM*>();
  74. }
  75. bool PCB_GENERATOR::MakeEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints ) const
  76. {
  77. return true;
  78. }
  79. bool PCB_GENERATOR::UpdateFromEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints,
  80. BOARD_COMMIT* aCommit )
  81. {
  82. return true;
  83. }
  84. bool PCB_GENERATOR::UpdateEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints )
  85. {
  86. return true;
  87. }
  88. const BOX2I PCB_GENERATOR::GetBoundingBox() const
  89. {
  90. BOX2I bbox;
  91. return bbox;
  92. }
  93. void PCB_GENERATOR::Move( const VECTOR2I& aMoveVector )
  94. {
  95. m_origin += aMoveVector;
  96. PCB_GROUP::Move( aMoveVector );
  97. }
  98. void PCB_GENERATOR::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
  99. {
  100. RotatePoint( m_origin, aRotCentre, aAngle );
  101. PCB_GROUP::Rotate( aRotCentre, aAngle );
  102. }
  103. void PCB_GENERATOR::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
  104. {
  105. if( aFlipLeftRight )
  106. MIRROR( m_origin.x, aCentre.x );
  107. else
  108. MIRROR( m_origin.y, aCentre.y );
  109. SetLayer( FlipLayer( GetLayer(), GetBoard()->GetCopperLayerCount() ) );
  110. PCB_GROUP::Flip( aCentre, aFlipLeftRight );
  111. }
  112. bool PCB_GENERATOR::AddItem( BOARD_ITEM* aItem )
  113. {
  114. // Items can only be in one group at a time
  115. if( aItem->GetParentGroup() )
  116. aItem->GetParentGroup()->RemoveItem( aItem );
  117. m_items.insert( aItem );
  118. aItem->SetParentGroup( this );
  119. return true;
  120. }
  121. LSET PCB_GENERATOR::GetLayerSet() const
  122. {
  123. return PCB_GROUP::GetLayerSet() | LSET( GetLayer() );
  124. }
  125. void PCB_GENERATOR::SetLayer( PCB_LAYER_ID aLayer )
  126. {
  127. m_layer = aLayer;
  128. }
  129. wxString PCB_GENERATOR::GetGeneratorType() const
  130. {
  131. return m_generatorType;
  132. }
  133. const STRING_ANY_MAP PCB_GENERATOR::GetProperties() const
  134. {
  135. STRING_ANY_MAP props( pcbIUScale.IU_PER_MM );
  136. #ifdef GENERATOR_ORDER
  137. props.set( "update_order", m_updateOrder );
  138. #endif
  139. props.set( "origin", m_origin );
  140. return props;
  141. }
  142. void PCB_GENERATOR::SetProperties( const STRING_ANY_MAP& aProps )
  143. {
  144. #ifdef GENERATOR_ORDER
  145. aProps.get_to( "update_order", m_updateOrder );
  146. #endif
  147. aProps.get_to( "origin", m_origin );
  148. }
  149. std::vector<std::pair<wxString, wxVariant>> PCB_GENERATOR::GetRowData()
  150. {
  151. #ifdef GENERATOR_ORDER
  152. return { { _HKI( "Update Order" ), wxString::FromCDouble( GetUpdateOrder() ) } };
  153. #else
  154. return { {} };
  155. #endif
  156. }
  157. wxString PCB_GENERATOR::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
  158. {
  159. return wxString( _( "Generator" ) );
  160. }
  161. wxString PCB_GENERATOR::GetClass() const
  162. {
  163. return wxS( "PCB_GENERATOR" );
  164. }
  165. bool PCB_GENERATOR::ClassOf( const EDA_ITEM* aItem )
  166. {
  167. return aItem && PCB_GENERATOR_T == aItem->Type();
  168. }
  169. #ifdef GENERATOR_ORDER
  170. static struct PCB_GENERATOR_DESC
  171. {
  172. PCB_GENERATOR_DESC()
  173. {
  174. PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
  175. REGISTER_TYPE( PCB_GENERATOR );
  176. propMgr.AddTypeCast( new TYPE_CAST<PCB_GENERATOR, BOARD_ITEM> );
  177. propMgr.InheritsAfter( TYPE_HASH( PCB_GENERATOR ), TYPE_HASH( BOARD_ITEM ) );
  178. const wxString groupTab = _HKI( "Generator Properties" );
  179. propMgr.AddProperty( new PROPERTY<PCB_GENERATOR, int>( _HKI( "Update Order" ),
  180. &PCB_GENERATOR::SetUpdateOrder,
  181. &PCB_GENERATOR::GetUpdateOrder ),
  182. groupTab );
  183. }
  184. } _PCB_GENERATOR_DESC;
  185. #endif