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.

126 lines
4.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2004-2019 KiCad Developers, see change_log.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 _LIB_POLYLINE_H_
  25. #define _LIB_POLYLINE_H_
  26. #include <lib_draw_item.h>
  27. class LIB_POLYLINE : public LIB_ITEM
  28. {
  29. int m_Width; // Line width
  30. std::vector<wxPoint> m_PolyPoints; // list of points (>= 2)
  31. void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void* aData,
  32. const TRANSFORM& aTransform ) override;
  33. public:
  34. LIB_POLYLINE( LIB_PART * aParent );
  35. // Do not create a copy constructor. The one generated by the compiler is adequate.
  36. ~LIB_POLYLINE() { }
  37. wxString GetClass() const override
  38. {
  39. return wxT( "LIB_POLYLINE" );
  40. }
  41. wxString GetTypeName() override
  42. {
  43. return _( "PolyLine" );
  44. }
  45. void ClearPoints() { m_PolyPoints.clear(); }
  46. void Reserve( size_t aPointCount ) { m_PolyPoints.reserve( aPointCount ); }
  47. void AddPoint( const wxPoint& aPoint );
  48. const std::vector< wxPoint >& GetPolyPoints() const { return m_PolyPoints; }
  49. /**
  50. * Delete the segment at \a aPosition.
  51. */
  52. void DeleteSegment( const wxPoint aPosition );
  53. void AddCorner( const wxPoint& aPosition );
  54. void RemoveCorner( int aIdx );
  55. /**
  56. * @return the number of corners
  57. */
  58. unsigned GetCornerCount() const { return m_PolyPoints.size(); }
  59. bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
  60. bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
  61. const EDA_RECT GetBoundingBox() const override;
  62. int GetPenSize( ) const override;
  63. void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
  64. void BeginEdit( const wxPoint aStartPoint ) override;
  65. void CalcEdit( const wxPoint& aPosition ) override;
  66. bool ContinueEdit( const wxPoint aNextPoint ) override;
  67. void EndEdit() override;
  68. void Offset( const wxPoint& aOffset ) override;
  69. bool Inside( EDA_RECT& aRect ) const override;
  70. void MoveTo( const wxPoint& aPosition ) override;
  71. wxPoint GetPosition() const override { return m_PolyPoints[0]; }
  72. void MirrorHorizontal( const wxPoint& aCenter ) override;
  73. void MirrorVertical( const wxPoint& aCenter ) override;
  74. void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
  75. void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
  76. const TRANSFORM& aTransform ) override;
  77. int GetWidth() const override { return m_Width; }
  78. void SetWidth( int aWidth ) override { m_Width = aWidth; }
  79. wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
  80. BITMAP_DEF GetMenuImage() const override;
  81. EDA_ITEM* Clone() const override;
  82. private:
  83. /**
  84. * @copydoc LIB_ITEM::compare()
  85. *
  86. * The sort order for specific to each polyline segment point is as follows:
  87. * - Line segment point horizontal (X) position.
  88. * - Line segment point vertical (Y) position.
  89. */
  90. int compare( const LIB_ITEM& aOther ) const override;
  91. };
  92. #endif // _LIB_POLYLINE_H_