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.

109 lines
3.2 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 CERN
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #ifndef PREVIEW_ITEMS_SELECTION_AREA_H
  27. #define PREVIEW_ITEMS_SELECTION_AREA_H
  28. #include <preview_items/simple_overlay_item.h>
  29. #include <geometry/shape_line_chain.h>
  30. #include <tool/selection_tool.h>
  31. namespace KIGFX
  32. {
  33. class GAL;
  34. namespace PREVIEW
  35. {
  36. /**
  37. * Represent a selection area (currently a rectangle) in a VIEW, drawn corner-to-corner between
  38. * two points.
  39. *
  40. * This is useful when selecting a rectangular area, for lasso-select or zooming, for example.
  41. */
  42. class SELECTION_AREA : public SIMPLE_OVERLAY_ITEM
  43. {
  44. public:
  45. static const int SelectionLayer = LAYER_GP_OVERLAY;
  46. SELECTION_AREA();
  47. const BOX2I ViewBBox() const override;
  48. ///< Set the origin of the rectangle (the fixed corner)
  49. void SetOrigin( const VECTOR2I& aOrigin )
  50. {
  51. m_origin = aOrigin;
  52. }
  53. /**
  54. * Set the current end of the rectangle (the corner that moves with the cursor.
  55. */
  56. void SetEnd( const VECTOR2I& aEnd )
  57. {
  58. m_end = aEnd;
  59. }
  60. /**
  61. * @return string "SELECTION_AREA"
  62. */
  63. wxString GetClass() const override
  64. {
  65. return wxT( "SELECTION_AREA" );
  66. }
  67. VECTOR2I GetOrigin() const { return m_origin; }
  68. VECTOR2I GetEnd() const { return m_end; }
  69. void SetAdditive( bool aAdditive ) { m_additive = aAdditive; }
  70. void SetSubtractive( bool aSubtractive ) { m_subtractive = aSubtractive; }
  71. void SetExclusiveOr( bool aExclusiveOr ) { m_exclusiveOr = aExclusiveOr; }
  72. void SetMode( SELECTION_MODE aMode ) { m_mode = aMode; }
  73. SELECTION_MODE GetMode() const { return m_mode; }
  74. void SetPoly( SHAPE_LINE_CHAIN& aPoly ) { m_shape_poly = aPoly; }
  75. SHAPE_LINE_CHAIN& GetPoly() { return m_shape_poly; }
  76. void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override final;
  77. private:
  78. bool m_additive;
  79. bool m_subtractive;
  80. bool m_exclusiveOr;
  81. SELECTION_MODE m_mode;
  82. VECTOR2I m_origin, m_end; // Used for box selection
  83. SHAPE_LINE_CHAIN m_shape_poly; // Used for lasso selection
  84. };
  85. } // PREVIEW
  86. } // KIGFX
  87. #endif // PREVIEW_ITEMS_SELECTION_AREA_H