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.

83 lines
2.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 CERN
  5. * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  6. * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #ifndef EE_GRID_HELPER_H
  26. #define EE_GRID_HELPER_H
  27. #include <math/vector2d.h>
  28. #include <origin_viewitem.h>
  29. #include <tool/grid_helper.h>
  30. #include <ee_selection.h>
  31. class SCH_ITEM;
  32. enum EE_GRID_HELPER_LAYERS : int
  33. {
  34. LAYER_ANY = SCH_LAYER_ID_END + 1,
  35. LAYER_CONNECTABLE,
  36. LAYER_GRAPHICS
  37. };
  38. class EE_GRID_HELPER : public GRID_HELPER
  39. {
  40. public:
  41. EE_GRID_HELPER( TOOL_MANAGER* aToolMgr );
  42. /**
  43. * Function GetSnapped
  44. * If the EE_GRID_HELPER has highlighted a snap point (target shown), this function
  45. * will return a pointer to the item to which it snapped.
  46. *
  47. * @return NULL if not snapped. Pointer to snapped item otherwise
  48. */
  49. SCH_ITEM* GetSnapped() const;
  50. VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, int aLayer, const EE_SELECTION& aItems );
  51. VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, int aLayer, SCH_ITEM* aDraggedItem );
  52. VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, int aLayer, const EE_SELECTION& aSkip = {} );
  53. private:
  54. std::set<SCH_ITEM*> queryVisible( const BOX2I& aArea, const EE_SELECTION& aSkipList ) const;
  55. ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags, int aMatchLayer );
  56. /**
  57. * Insert the local anchor points in to the grid helper for the specified
  58. * schematic item, given the reference point and the direction of use for the point.
  59. *
  60. * @param aItem The schematic item for which to compute the anchors
  61. * @param aRefPos The point for which to compute the anchors (if used by the symbol)
  62. * @param aFrom Is this for an anchor that is designating a source point (aFrom=true) or not
  63. * @param aIncludeText if true will compute anchors for text items
  64. */
  65. void computeAnchors( SCH_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom = false,
  66. bool aIncludeText = false );
  67. };
  68. #endif