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.

143 lines
3.7 KiB

9 years ago
9 years ago
9 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 CERN
  5. * @author Maciej Suminski <maciej.suminski@cern.ch>
  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. /**
  26. * @file view_group.h
  27. * @brief VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
  28. * VIEW_GROUP does not take over ownership of the held items. The main purpose of this class is
  29. * to group items and draw them on a single layer (in particular the overlay).
  30. */
  31. #ifndef VIEW_GROUP_H_
  32. #define VIEW_GROUP_H_
  33. #include <view/view_item.h>
  34. #include <deque>
  35. namespace KIGFX
  36. {
  37. class VIEW_GROUP : public VIEW_ITEM
  38. {
  39. protected:
  40. typedef std::vector<VIEW_ITEM*> ITEMS;
  41. public:
  42. VIEW_GROUP( VIEW* aView = NULL );
  43. virtual ~VIEW_GROUP();
  44. /**
  45. * Function GetSize()
  46. * Returns the number of stored items.
  47. *
  48. * @return Number of stored items.
  49. */
  50. virtual unsigned int GetSize() const;
  51. /**
  52. * Function Add()
  53. * Adds an item to the group.
  54. *
  55. * @param aItem is the item to be added.
  56. */
  57. virtual void Add( VIEW_ITEM* aItem );
  58. /**
  59. * Function Remove()
  60. * Removes an item from the group.
  61. *
  62. * @param aItem is the item to be removed.
  63. */
  64. virtual void Remove( VIEW_ITEM* aItem );
  65. /**
  66. * Function Clear()
  67. * Removes all the stored items from the group.
  68. */
  69. virtual void Clear();
  70. virtual VIEW_ITEM* GetItem( unsigned int aIdx ) const;
  71. /**
  72. * Function ViewBBox()
  73. * Returns the bounding box for all stored items covering all its layers.
  74. *
  75. * @return The current bounding box
  76. */
  77. virtual const BOX2I ViewBBox() const override;
  78. /**
  79. * Function ViewDraw()
  80. * Draws all the stored items in the group on the given layer.
  81. *
  82. * @param aLayer is the layer which should be drawn.
  83. * @param aGal is the GAL that should be used for drawing.
  84. */
  85. virtual void ViewDraw( int aLayer, VIEW* aView ) const override;
  86. /**
  87. * Function ViewGetLayers()
  88. * Returns all the layers used by the stored items.
  89. *
  90. * @param aLayers[] is the output layer index array.
  91. * @param aCount is the number of layer indices in aLayers[].
  92. */
  93. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  94. /**
  95. * Function SetLayer()
  96. * Sets layer used to draw the group.
  97. *
  98. * @param aLayer is the layer used for drawing.
  99. */
  100. inline virtual void SetLayer( int aLayer )
  101. {
  102. m_layer = aLayer;
  103. }
  104. /**
  105. * Function FreeItems()
  106. * Frees all the items that were added to the group.
  107. */
  108. void FreeItems();
  109. protected:
  110. virtual const ITEMS updateDrawList() const;
  111. /// Layer on which the group is drawn
  112. int m_layer;
  113. protected:
  114. /// Container for storing VIEW_ITEMs
  115. ITEMS m_groupItems;
  116. private:
  117. void updateBbox();
  118. };
  119. } // namespace KIGFX
  120. #endif // VIEW_GROUP_H_