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.

144 lines
4.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013-2017 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. #ifndef __POINT_EDITOR_H
  25. #define __POINT_EDITOR_H
  26. #include <tool/tool_interactive.h>
  27. #include "edit_points.h"
  28. #include <status_popup.h>
  29. #include <memory>
  30. class SELECTION_TOOL;
  31. class SHAPE_POLY_SET;
  32. /**
  33. * Class POINT_EDITOR
  34. *
  35. * Tool that displays edit points allowing to modify items by dragging the points.
  36. */
  37. class POINT_EDITOR : public PCB_TOOL
  38. {
  39. public:
  40. POINT_EDITOR();
  41. /// @copydoc TOOL_INTERACTIVE::Reset()
  42. void Reset( RESET_REASON aReason ) override;
  43. /// @copydoc TOOL_INTERACTIVE::Init()
  44. bool Init() override;
  45. /**
  46. * Function OnSelected()
  47. *
  48. * Change selection event handler.
  49. */
  50. int OnSelectionChange( const TOOL_EVENT& aEvent );
  51. ///> Sets up handlers for various events.
  52. void setTransitions() override;
  53. private:
  54. ///> Selection tool used for obtaining selected items
  55. SELECTION_TOOL* m_selectionTool;
  56. ///> Currently edited point, NULL if there is none.
  57. EDIT_POINT* m_editedPoint;
  58. ///> Original position for the current drag point.
  59. EDIT_POINT m_original;
  60. ///> Currently available edit points.
  61. std::shared_ptr<EDIT_POINTS> m_editPoints;
  62. // Alternative constraint, enabled while a modifier key is held
  63. std::shared_ptr<EDIT_CONSTRAINT<EDIT_POINT> > m_altConstraint;
  64. // EDIT_POINT for alternative constraint mode
  65. EDIT_POINT m_altConstrainer;
  66. // Flag indicating whether the selected zone needs to be refilled
  67. bool m_refill;
  68. std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
  69. ///> Updates item's points with edit points.
  70. void updateItem() const;
  71. ///> Applies the last changes to the edited item.
  72. void finishItem();
  73. /**
  74. * Validates a polygon and restores it to its original version if available.
  75. * @param aModified is the polygon to be checked.
  76. * @param aOriginal is the original copy that will be used to restore its state.
  77. * @return True if polygon is valid.
  78. */
  79. bool validatePolygon( SHAPE_POLY_SET& aModified, const SHAPE_POLY_SET* aOriginal = nullptr ) const;
  80. ///> Updates edit points with item's points.
  81. void updatePoints();
  82. ///> Updates which point is being edited.
  83. void updateEditedPoint( const TOOL_EVENT& aEvent );
  84. ///> Sets the current point being edited. NULL means none.
  85. void setEditedPoint( EDIT_POINT* aPoint );
  86. ///> Returns true if aPoint is the currently modified point.
  87. inline bool isModified( const EDIT_POINT& aPoint ) const
  88. {
  89. return m_editedPoint == &aPoint;
  90. }
  91. ///> Sets up an alternative constraint (typically enabled upon a modifier key being pressed).
  92. void setAltConstraint( bool aEnabled );
  93. ///> Returns a point that should be used as a constrainer for 45 degrees mode.
  94. EDIT_POINT get45DegConstrainer() const;
  95. ///> Adds a new edit point on a zone outline/line.
  96. void addCorner( const VECTOR2I& aPoint );
  97. ///> Removes a corner.
  98. void removeCorner( EDIT_POINT* aPoint );
  99. ///> Condition to display "Create corner" context menu entry.
  100. static bool addCornerCondition( const SELECTION& aSelection );
  101. ///> Determine if the tool can currently add a corner to the given item
  102. static bool canAddCorner( const EDA_ITEM& aItem );
  103. ///> Condition to display "Remove corner" context menu entry.
  104. bool removeCornerCondition( const SELECTION& aSelection );
  105. /// TOOL_ACTION handlers
  106. int addCorner( const TOOL_EVENT& aEvent );
  107. int removeCorner( const TOOL_EVENT& aEvent );
  108. int modifiedSelection( const TOOL_EVENT& aEvent );
  109. };
  110. #endif