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.

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