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.

196 lines
6.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 Joshua Redstone redstone at 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. /**
  25. * @file pcb_group.h
  26. * @brief Class to handle a set of BOARD_ITEMs.
  27. */
  28. #ifndef CLASS_PCB_GROUP_H_
  29. #define CLASS_PCB_GROUP_H_
  30. #include <board_commit.h>
  31. #include <board_item.h>
  32. #include <eda_group.h>
  33. #include <lset.h>
  34. #include <unordered_set>
  35. namespace KIGFX
  36. {
  37. class VIEW;
  38. }
  39. /**
  40. * A set of BOARD_ITEMs (i.e., without duplicates).
  41. *
  42. * The group parent is always board, not logical parent group. The group is transparent
  43. * container - e.g., its position is derived from the position of its members. A selection
  44. * containing a group implicitly contains its members. However other operations on sets of
  45. * items, like committing, updating the view, etc the set is explicit.
  46. */
  47. class PCB_GROUP : public BOARD_ITEM, public EDA_GROUP
  48. {
  49. public:
  50. PCB_GROUP( BOARD_ITEM* aParent );
  51. void Serialize( google::protobuf::Any &aContainer ) const override;
  52. bool Deserialize( const google::protobuf::Any &aContainer ) override;
  53. EDA_ITEM* AsEdaItem() override { return this; }
  54. static inline bool ClassOf( const EDA_ITEM* aItem )
  55. {
  56. return aItem && PCB_GROUP_T == aItem->Type();
  57. }
  58. wxString GetClass() const override
  59. {
  60. return wxT( "PCB_GROUP" );
  61. }
  62. std::unordered_set<BOARD_ITEM*> GetBoardItems() const;
  63. /*
  64. * Search for highest level group inside of aScope, containing item.
  65. *
  66. * @param aScope restricts the search to groups within the group scope.
  67. * @param isFootprintEditor true if we should stop promoting at the footprint level
  68. * @return group inside of aScope, containing item, if exists, otherwise, nullptr
  69. */
  70. static EDA_GROUP* TopLevelGroup( BOARD_ITEM* aItem, EDA_GROUP* aScope, bool isFootprintEditor );
  71. static bool WithinScope( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor );
  72. double Similarity( const BOARD_ITEM& aOther ) const override;
  73. bool operator==( const PCB_GROUP& aOther ) const;
  74. bool operator==( const BOARD_ITEM& aBoardItem ) const override;
  75. #if defined( DEBUG )
  76. void Show( int nestLevel, std::ostream& os ) const override
  77. {
  78. ShowDummy( os );
  79. }
  80. #endif
  81. /// @copydoc EDA_ITEM::GetPosition
  82. VECTOR2I GetPosition() const override;
  83. /// @copydoc EDA_ITEM::SetPosition
  84. void SetPosition( const VECTOR2I& aNewpos ) override;
  85. /// @copydoc BOARD_ITEM::GetLayerSet
  86. LSET GetLayerSet() const override;
  87. /// @copydoc BOARD_ITEM::SetLayer
  88. void SetLayer( PCB_LAYER_ID aLayer ) override
  89. {
  90. // NOP
  91. }
  92. bool IsOnCopperLayer() const override
  93. {
  94. // A group might have members on a copper layer, but isn't itself on any layer.
  95. return false;
  96. }
  97. void SetLocked( bool aLocked ) override;
  98. /// @copydoc EDA_ITEM::Clone
  99. EDA_ITEM* Clone() const override;
  100. /*
  101. * Clone this and all descendants
  102. */
  103. PCB_GROUP* DeepClone() const;
  104. /*
  105. * Duplicate this and all descendants
  106. *
  107. * @param addToParentGroup if the original is part of a group then the new member will also
  108. * be added to said group
  109. */
  110. PCB_GROUP* DeepDuplicate( bool addToParentGroup, BOARD_COMMIT* aCommit = nullptr ) const;
  111. /// @copydoc BOARD_ITEM::IsOnLayer
  112. bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
  113. /// @copydoc EDA_ITEM::HitTest
  114. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  115. /// @copydoc EDA_ITEM::HitTest
  116. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  117. /// @copydoc EDA_ITEM::GetBoundingBox
  118. const BOX2I GetBoundingBox() const override;
  119. // @copydoc BOARD_ITEM::GetEffectiveShape
  120. std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
  121. FLASHING aFlash = FLASHING::DEFAULT ) const override;
  122. /// @copydoc EDA_ITEM::Visit
  123. INSPECT_RESULT Visit( INSPECTOR aInspector, void* aTestData,
  124. const std::vector<KICAD_T>& aScanTypes ) override;
  125. /// @copydoc VIEW_ITEM::ViewGetLayers
  126. std::vector<int> ViewGetLayers() const override;
  127. /// @copydoc VIEW_ITEM::ViewGetLOD
  128. double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
  129. /// @copydoc BOARD_ITEM::Move
  130. void Move( const VECTOR2I& aMoveVector ) override;
  131. /// @copydoc BOARD_ITEM::Rotate
  132. void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
  133. /// @copydoc BOARD_ITEM::Flip
  134. void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
  135. /// @copydoc BOARD_ITEM::Mirror
  136. void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
  137. /// @copydoc EDA_ITEM::GetItemDescription
  138. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
  139. /// @copydoc EDA_ITEM::GetMenuImage
  140. BITMAPS GetMenuImage() const override;
  141. /// @copydoc EDA_ITEM::GetMsgPanelInfo
  142. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  143. /// @copydoc EDA_ITEM::Matches
  144. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
  145. ///< @copydoc BOARD_ITEM::RunOnChildren
  146. void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const override;
  147. protected:
  148. PCB_GROUP( BOARD_ITEM* aParent, KICAD_T idtype, PCB_LAYER_ID aLayer = F_Cu );
  149. /// @copydoc BOARD_ITEM::swapData
  150. void swapData( BOARD_ITEM* aImage ) override;
  151. };
  152. #endif // CLASS_PCB_GROUP_H_