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.

104 lines
3.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 CERN
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  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 PL_POINT_EDITOR_H
  25. #define PL_POINT_EDITOR_H
  26. #include <tool/tool_interactive.h>
  27. #include <tool/edit_points.h>
  28. #include <tool/selection.h>
  29. #include <tool/tool_menu.h>
  30. class PL_SELECTION_TOOL;
  31. class PL_EDITOR_FRAME;
  32. /**
  33. * Tool that displays edit points allowing to modify items by dragging the points.
  34. */
  35. class PL_POINT_EDITOR : public TOOL_INTERACTIVE
  36. {
  37. public:
  38. PL_POINT_EDITOR();
  39. /// @copydoc TOOL_INTERACTIVE::Reset()
  40. void Reset( RESET_REASON aReason ) override;
  41. /// @copydoc TOOL_INTERACTIVE::Init()
  42. bool Init() override;
  43. int Main( const TOOL_EVENT& aEvent );
  44. /**
  45. * Indicate the cursor is over an edit point. Used to coordinate cursor shapes with
  46. * other tools.
  47. */
  48. bool HasPoint() { return m_editedPoint != nullptr; }
  49. ///< Set up handlers for various events.
  50. void setTransitions() override;
  51. private:
  52. ///< Update item's points with edit points.
  53. void updateItem() const;
  54. ///< Update edit points with item's points.
  55. void updatePoints();
  56. ///< Update which point is being edited.
  57. void updateEditedPoint( const TOOL_EVENT& aEvent );
  58. ///< Set the current point being edited. NULL means none.
  59. void setEditedPoint( EDIT_POINT* aPoint );
  60. ///< Return true if aPoint is the currently modified point.
  61. inline bool isModified( const EDIT_POINT& aPoint ) const
  62. {
  63. return m_editedPoint == &aPoint;
  64. }
  65. inline int getEditedPointIndex() const
  66. {
  67. for( unsigned i = 0; i < m_editPoints->PointsSize(); ++i )
  68. {
  69. if( m_editedPoint == &m_editPoints->Point( i ) )
  70. return i;
  71. }
  72. return wxNOT_FOUND;
  73. }
  74. int modifiedSelection( const TOOL_EVENT& aEvent );
  75. private:
  76. PL_EDITOR_FRAME* m_frame;
  77. PL_SELECTION_TOOL* m_selectionTool;
  78. ///< Currently edited point, NULL if there is none.
  79. EDIT_POINT* m_editedPoint;
  80. ///< Currently available edit points.
  81. std::shared_ptr<EDIT_POINTS> m_editPoints;
  82. };
  83. #endif // PL_POINT_EDITOR_H