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.

110 lines
3.1 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 CERN
  5. * @author Tomasz Wlostowski <tomasz.wlostowski@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. #ifndef __GRID_HELPER_H
  25. #define __GRID_HELPER_H
  26. #include <vector>
  27. #include <math/vector2d.h>
  28. #include <core/optional.h>
  29. #include <origin_viewitem.h>
  30. #include <layers_id_colors_and_visibility.h>
  31. #include <geometry/seg.h>
  32. class PCB_BASE_FRAME;
  33. class GRID_HELPER {
  34. public:
  35. GRID_HELPER( PCB_BASE_FRAME* aFrame );
  36. ~GRID_HELPER();
  37. void SetGrid( int aSize );
  38. void SetOrigin( const VECTOR2I& aOrigin );
  39. VECTOR2I GetGrid() const;
  40. VECTOR2I GetOrigin() const;
  41. void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ), bool aEnableDiagonal = false );
  42. VECTOR2I Align( const VECTOR2I& aPoint ) const;
  43. VECTOR2I AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg );
  44. VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, BOARD_ITEM* aItem );
  45. VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem );
  46. private:
  47. enum ANCHOR_FLAGS {
  48. CORNER = 0x1,
  49. OUTLINE = 0x2,
  50. SNAPPABLE = 0x4,
  51. ORIGIN = 0x8
  52. };
  53. struct ANCHOR
  54. {
  55. ANCHOR( VECTOR2I aPos, int aFlags = CORNER | SNAPPABLE, BOARD_ITEM* aItem = NULL ):
  56. pos( aPos ), flags( aFlags ), item( aItem ) {} ;
  57. VECTOR2I pos;
  58. int flags;
  59. BOARD_ITEM* item;
  60. double Distance( const VECTOR2I& aP ) const
  61. {
  62. return ( aP - pos ).EuclideanNorm();
  63. }
  64. //bool CanSnapItem( const BOARD_ITEM* aItem ) const;
  65. };
  66. std::vector<ANCHOR> m_anchors;
  67. std::set<BOARD_ITEM*> queryVisible( const BOX2I& aArea ) const;
  68. void addAnchor( const VECTOR2I& aPos, int aFlags = CORNER | SNAPPABLE, BOARD_ITEM* aItem = NULL )
  69. {
  70. m_anchors.push_back( ANCHOR( aPos, aFlags, aItem ) );
  71. }
  72. ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags, LSET aMatchLayers );
  73. void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos );
  74. void clearAnchors()
  75. {
  76. m_anchors.clear();
  77. }
  78. PCB_BASE_FRAME* m_frame;
  79. OPT<VECTOR2I> m_auxAxis;
  80. bool m_diagonalAuxAxesEnable;
  81. KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint, m_viewAxis;
  82. };
  83. #endif