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.

207 lines
6.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 1992-2017 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. /**
  25. * @file sch_line.h
  26. */
  27. #ifndef _SCH_LINE_H_
  28. #define _SCH_LINE_H_
  29. #include <sch_item_struct.h>
  30. class NETLIST_OBJECT_LIST;
  31. /**
  32. * Segment description base class to describe items which have 2 end points (track, wire,
  33. * draw line ...)
  34. */
  35. class SCH_LINE : public SCH_ITEM
  36. {
  37. bool m_startIsDangling; ///< True if start point is not connected.
  38. bool m_endIsDangling; ///< True if end point is not connected.
  39. wxPoint m_start; ///< Line start point
  40. wxPoint m_end; ///< Line end point
  41. int m_size; ///< Line pensize
  42. int m_style; ///< Line style
  43. COLOR4D m_color; ///< Line color
  44. public:
  45. static const enum wxPenStyle PenStyle[];
  46. SCH_LINE( const wxPoint& pos = wxPoint( 0, 0 ), int layer = LAYER_NOTES );
  47. SCH_LINE( const SCH_LINE& aLine );
  48. ~SCH_LINE() { }
  49. SCH_LINE* Next() const { return (SCH_LINE*) Pnext; }
  50. SCH_LINE* Back() const { return (SCH_LINE*) Pback; }
  51. wxString GetClass() const override
  52. {
  53. return wxT( "SCH_LINE" );
  54. }
  55. bool IsEndPoint( const wxPoint& aPoint ) const
  56. {
  57. return aPoint == m_start || aPoint == m_end;
  58. }
  59. bool IsNull() const { return m_start == m_end; }
  60. wxPoint GetStartPoint() const { return m_start; }
  61. void SetStartPoint( const wxPoint& aPosition ) { m_start = aPosition; }
  62. wxPoint GetEndPoint() const { return m_end; }
  63. void SetEndPoint( const wxPoint& aPosition ) { m_end = aPosition; }
  64. int GetDefaultStyle() const;
  65. void SetLineStyle( const int aStyle );
  66. int GetLineStyle() const;
  67. /// @return the style name from the style id
  68. /// (mainly to write it in .sch file
  69. static const char* GetLineStyleName( int aStyle );
  70. /// @return the style id from the style name
  71. /// (mainly to read style from .sch file
  72. static int GetLineStyleInternalId( const wxString& aStyleName );
  73. void SetLineColor( const COLOR4D aColor );
  74. void SetLineColor( const double r, const double g, const double b, const double a );
  75. COLOR4D GetLineColor() const;
  76. COLOR4D GetDefaultColor() const;
  77. int GetDefaultWidth() const;
  78. void SetLineWidth( const int aSize );
  79. int GetLineSize() const { return m_size; }
  80. const EDA_RECT GetBoundingBox() const override;
  81. /**
  82. * Function GetLength
  83. * @return The length of the line segment.
  84. */
  85. double GetLength() const;
  86. void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
  87. GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override;
  88. int GetPenSize() const override;
  89. void Move( const wxPoint& aMoveVector ) override;
  90. void MirrorX( int aXaxis_position ) override;
  91. void MirrorY( int aYaxis_position ) override;
  92. void Rotate( wxPoint aPosition ) override;
  93. /**
  94. * Check line against \a aLine to see if it overlaps and merge if it does.
  95. *
  96. * This method will return an equivalent of the union of line and \a aLine if the
  97. * two lines overlap. This method is used to merge multiple line segments into a single
  98. * line.
  99. *
  100. * @param aLine - Line to compare.
  101. * @return New line that combines the two or NULL on non-overlapping segments.
  102. */
  103. EDA_ITEM* MergeOverlap( SCH_LINE* aLine );
  104. /**
  105. * Check if two lines are in the same quadrant as each other, using a reference point as
  106. * the origin
  107. *
  108. * @param aLine - Line to compare
  109. * @param aPosition - Point to reference against lines
  110. * @return true if lines are mostly in different quadrants of aPosition, false otherwise
  111. */
  112. bool IsSameQuadrant( SCH_LINE* aLine, const wxPoint& aPosition );
  113. bool IsParallel( SCH_LINE* aLine );
  114. void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
  115. bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList ) override;
  116. bool IsStartDangling() const { return m_startIsDangling; }
  117. bool IsEndDangling() const { return m_endIsDangling; }
  118. bool IsDangling() const override { return m_startIsDangling || m_endIsDangling; }
  119. bool IsSelectStateChanged( const wxRect& aRect ) override;
  120. bool IsConnectable() const override;
  121. void GetConnectionPoints(std::vector< wxPoint >& aPoints ) const override;
  122. bool CanConnect( const SCH_ITEM* aItem ) const override;
  123. wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
  124. BITMAP_DEF GetMenuImage() const override;
  125. void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems, SCH_SHEET_PATH* aSheetPath ) override;
  126. bool operator <( const SCH_ITEM& aItem ) const override;
  127. wxPoint GetPosition() const override { return m_start; }
  128. void SetPosition( const wxPoint& aPosition ) override;
  129. bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
  130. bool HitTest( const EDA_RECT& aRect, bool aContained = false, int aAccuracy = 0 ) const override;
  131. void Plot( PLOTTER* aPlotter ) override;
  132. wxPoint MidPoint();
  133. EDA_ITEM* Clone() const override;
  134. void SwapData( SCH_ITEM* aItem ) override;
  135. #if defined(DEBUG)
  136. void Show( int nestLevel, std::ostream& os ) const override;
  137. #endif
  138. private:
  139. bool doIsConnected( const wxPoint& aPosition ) const override;
  140. };
  141. #endif // _SCH_LINE_H_