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.

128 lines
4.1 KiB

  1. /********************************/
  2. /* Graphic Body Item: Rectangle */
  3. /********************************/
  4. #ifndef _LIB_RECTANGLE_H_
  5. #define _LIB_RECTANGLE_H_
  6. #include "lib_draw_item.h"
  7. class LIB_RECTANGLE : public LIB_ITEM
  8. {
  9. wxPoint m_End; // Rectangle end point.
  10. wxPoint m_Pos; // Rectangle start point.
  11. int m_Width; // Line width
  12. bool m_isWidthLocked; // Flag: Keep width locked
  13. bool m_isHeightLocked; // Flag: Keep height locked
  14. bool m_isStartPointSelected; // Flag: is the upper left edge selected?
  15. /**
  16. * Draw the rectangle.
  17. */
  18. void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
  19. int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform );
  20. /**
  21. * Calculate the rectangle attributes relative to \a aPosition while editing.
  22. *
  23. * @param aPosition - Edit position in drawing units.
  24. */
  25. void calcEdit( const wxPoint& aPosition );
  26. public:
  27. public:
  28. LIB_RECTANGLE( LIB_COMPONENT * aParent );
  29. LIB_RECTANGLE( const LIB_RECTANGLE& aRect );
  30. ~LIB_RECTANGLE() { }
  31. virtual wxString GetClass() const
  32. {
  33. return wxT( "LIB_RECTANGLE" );
  34. }
  35. void SetEndPosition( const wxPoint& aPosition ) { m_End = aPosition; }
  36. /**
  37. * Write rectangle object out to a FILE in "*.lib" format.
  38. *
  39. * @param aFile - The FILE to write to.
  40. * @return - true if success writing else false.
  41. */
  42. virtual bool Save( FILE* aFile );
  43. virtual bool Load( char* aLine, wxString& aErrorMsg );
  44. /**
  45. * Test if the given point is within the bounds of this object.
  46. *
  47. * @param aPosition - A wxPoint to test
  48. * @return - true if a hit, else false
  49. */
  50. virtual bool HitTest( const wxPoint& aPosition );
  51. /**
  52. * @param aPosRef - a wxPoint to test
  53. * @param aThreshold - max distance to this object (usually the half
  54. * thickness of a line)
  55. * @param aTransform - the transform matrix
  56. * @return true if the point aPosRef is near this object
  57. */
  58. virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform );
  59. /**
  60. * @return the size of the "pen" that be used to draw or plot this item
  61. */
  62. virtual int GetPenSize( ) const;
  63. virtual EDA_RECT GetBoundingBox() const;
  64. virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
  65. /**
  66. * See LIB_ITEM::BeginEdit().
  67. */
  68. void BeginEdit( int aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) );
  69. /**
  70. * See LIB_ITEM::ContinueEdit().
  71. */
  72. bool ContinueEdit( const wxPoint aNextPoint );
  73. /**
  74. * See LIB_ITEM::AbortEdit().
  75. */
  76. void EndEdit( const wxPoint& aPosition, bool aAbort = false );
  77. virtual wxString GetSelectMenuText() const;
  78. virtual const char** GetMenuImage() const { return (const char**) add_rectangle_xpm; }
  79. protected:
  80. virtual EDA_ITEM* doClone() const;
  81. /**
  82. * Provide the rectangle draw object specific comparison.
  83. *
  84. * The sort order is as follows:
  85. * - Rectangle horizontal (X) start position.
  86. * - Rectangle vertical (Y) start position.
  87. * - Rectangle horizontal (X) end position.
  88. * - Rectangle vertical (Y) end position.
  89. */
  90. virtual int DoCompare( const LIB_ITEM& aOther ) const;
  91. virtual void DoOffset( const wxPoint& aOffset );
  92. virtual bool DoTestInside( EDA_RECT& aRect ) const;
  93. virtual void DoMove( const wxPoint& aPosition );
  94. virtual wxPoint DoGetPosition() const { return m_Pos; }
  95. virtual void DoMirrorHorizontal( const wxPoint& aCenter );
  96. virtual void DoMirrorVertical( const wxPoint& aCenter );
  97. virtual void DoRotate( const wxPoint& aCenter, bool aRotateCCW = true );
  98. virtual void DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
  99. const TRANSFORM& aTransform );
  100. virtual int DoGetWidth() const { return m_Width; }
  101. virtual void DoSetWidth( int aWidth ) { m_Width = aWidth; }
  102. };
  103. #endif // _LIB_RECTANGLE_H_