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.

163 lines
5.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. /**
  24. * @file sch_group.h
  25. * @brief Class to handle a set of SCH_ITEMs.
  26. */
  27. #ifndef CLASS_SCH_GROUP_H_
  28. #define CLASS_SCH_GROUP_H_
  29. #include <eda_group.h>
  30. #include <sch_commit.h>
  31. #include <sch_item.h>
  32. #include <lset.h>
  33. #include <unordered_set>
  34. namespace KIGFX
  35. {
  36. class VIEW;
  37. }
  38. /**
  39. * A set of SCH_ITEMs (i.e., without duplicates).
  40. *
  41. * The group parent is always sheet, not logical parent group. The group is transparent
  42. * container - e.g., its position is derived from the position of its members. A selection
  43. * containing a group implicitly contains its members. However other operations on sets of
  44. * items, like committing, updating the view, etc the set is explicit.
  45. */
  46. class SCH_GROUP : public SCH_ITEM, public EDA_GROUP
  47. {
  48. public:
  49. SCH_GROUP();
  50. SCH_GROUP( SCH_ITEM* aParent );
  51. SCH_GROUP( SCH_SCREEN* aParent );
  52. EDA_ITEM* AsEdaItem() override { return this; }
  53. static inline bool ClassOf( const EDA_ITEM* aItem ) { return aItem && SCH_GROUP_T == aItem->Type(); }
  54. wxString GetClass() const override { return wxT( "SCH_GROUP" ); }
  55. std::unordered_set<SCH_ITEM*> GetSchItems() const;
  56. /*
  57. * Search for highest level group inside of aScope, containing item.
  58. *
  59. * @param aScope restricts the search to groups within the group scope.
  60. * @param isSymbolEditor true if we should stop promoting at the symbol level
  61. * @return group inside of aScope, containing item, if exists, otherwise, nullptr
  62. */
  63. static EDA_GROUP* TopLevelGroup( SCH_ITEM* aItem, EDA_GROUP* aScope, bool isSymbolEditor );
  64. static bool WithinScope( SCH_ITEM* aItem, SCH_GROUP* aScope, bool isSymbolEditor );
  65. double Similarity( const SCH_ITEM& aOther ) const override;
  66. bool operator==( const SCH_GROUP& aOther ) const;
  67. bool operator==( const SCH_ITEM& aSchItem ) const override;
  68. #if defined( DEBUG )
  69. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  70. #endif
  71. /// @copydoc EDA_ITEM::GetPosition
  72. VECTOR2I GetPosition() const override;
  73. /// @copydoc EDA_ITEM::SetPosition
  74. void SetPosition( const VECTOR2I& aNewpos ) override;
  75. /// @copydoc EDA_ITEM::Clone
  76. EDA_ITEM* Clone() const override;
  77. /*
  78. * Clone this and all descendants
  79. */
  80. SCH_GROUP* DeepClone() const;
  81. /*
  82. * Duplicate this and all descendants
  83. *
  84. * @param addToParentGroup if the original is part of a group then the new member will also
  85. * be added to said group
  86. */
  87. SCH_GROUP* DeepDuplicate( bool addToParentGroup, SCH_COMMIT* aCommit = nullptr ) const;
  88. /// @copydoc EDA_ITEM::HitTest
  89. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  90. /// @copydoc EDA_ITEM::HitTest
  91. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  92. /// @copydoc EDA_ITEM::GetBoundingBox
  93. const BOX2I GetBoundingBox() const override;
  94. /// @copydoc EDA_ITEM::Visit
  95. INSPECT_RESULT Visit( INSPECTOR aInspector, void* aTestData,
  96. const std::vector<KICAD_T>& aScanTypes ) override;
  97. /// @copydoc VIEW_ITEM::ViewGetLayers
  98. std::vector<int> ViewGetLayers() const override;
  99. /// @copydoc VIEW_ITEM::ViewGetLOD
  100. double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
  101. /// @copydoc SCH_ITEM::Move
  102. void Move( const VECTOR2I& aMoveVector ) override;
  103. /// @copydoc SCH_ITEM::Rotate
  104. void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
  105. /// @copydoc SCH_ITEM::MirrorHorizontally
  106. void MirrorHorizontally( int aCenter ) override;
  107. /// @copydoc SCH_ITEM::MirrorVertically
  108. void MirrorVertically( int aCenter ) override;
  109. void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
  110. int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
  111. /// @copydoc EDA_ITEM::GetItemDescription
  112. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
  113. /// @copydoc EDA_ITEM::GetMenuImage
  114. BITMAPS GetMenuImage() const override;
  115. /// @copydoc EDA_ITEM::GetMsgPanelInfo
  116. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  117. /// @copydoc EDA_ITEM::Matches
  118. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
  119. ///< @copydoc SCH_ITEM::RunOnChildren
  120. void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction, RECURSE_MODE aMode ) override;
  121. /// @copydoc SCH_ITEM::swapData
  122. void swapData( SCH_ITEM* aImage ) override;
  123. };
  124. #endif