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.

274 lines
9.2 KiB

7 years ago
  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-2020 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 _SCH_LINE_H_
  25. #define _SCH_LINE_H_
  26. #include <sch_item.h>
  27. class NETLIST_OBJECT_LIST;
  28. /**
  29. * Segment description base class to describe items which have 2 end points (track, wire,
  30. * draw line ...)
  31. */
  32. class SCH_LINE : public SCH_ITEM
  33. {
  34. bool m_startIsDangling; ///< True if start point is not connected.
  35. bool m_endIsDangling; ///< True if end point is not connected.
  36. wxPoint m_start; ///< Line start point
  37. wxPoint m_end; ///< Line end point
  38. STROKE_PARAMS m_stroke; ///< Line stroke properties.
  39. public:
  40. static const enum wxPenStyle PenStyle[];
  41. SCH_LINE( const wxPoint& pos = wxPoint( 0, 0 ), int layer = LAYER_NOTES );
  42. SCH_LINE( const VECTOR2D& pos, int layer = LAYER_NOTES ) :
  43. SCH_LINE( wxPoint( pos.x, pos.y ), layer )
  44. {}
  45. SCH_LINE( const SCH_LINE& aLine );
  46. ~SCH_LINE() { }
  47. static inline bool ClassOf( const EDA_ITEM* aItem )
  48. {
  49. return aItem && SCH_LINE_T == aItem->Type();
  50. }
  51. wxString GetClass() const override
  52. {
  53. return wxT( "SCH_LINE" );
  54. }
  55. bool IsType( const KICAD_T aScanTypes[] ) const override
  56. {
  57. if( SCH_ITEM::IsType( aScanTypes ) )
  58. return true;
  59. for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
  60. {
  61. if( *p == SCH_LINE_LOCATE_WIRE_T && m_layer == LAYER_WIRE )
  62. return true;
  63. else if ( *p == SCH_LINE_LOCATE_BUS_T && m_layer == LAYER_BUS )
  64. return true;
  65. else if ( *p == SCH_LINE_LOCATE_GRAPHIC_LINE_T && m_layer == LAYER_NOTES )
  66. return true;
  67. }
  68. return false;
  69. }
  70. bool IsEndPoint( const wxPoint& aPoint ) const
  71. {
  72. return aPoint == m_start || aPoint == m_end;
  73. }
  74. bool IsNull() const { return m_start == m_end; }
  75. wxPoint GetStartPoint() const { return m_start; }
  76. void SetStartPoint( const wxPoint& aPosition ) { m_start = aPosition; }
  77. wxPoint GetEndPoint() const { return m_end; }
  78. void SetEndPoint( const wxPoint& aPosition ) { m_end = aPosition; }
  79. PLOT_DASH_TYPE GetDefaultStyle() const;
  80. void SetLineStyle( const PLOT_DASH_TYPE aStyle );
  81. void SetLineStyle( const int aStyleId );
  82. PLOT_DASH_TYPE GetLineStyle() const;
  83. /// @return the style that the line should be drawn in
  84. /// this might be set on the line or inherited from the line's netclass
  85. PLOT_DASH_TYPE GetEffectiveLineStyle() const;
  86. /// @return the style name from the style id
  87. /// (mainly to write it in .sch file)
  88. static const char* GetLineStyleName( PLOT_DASH_TYPE aStyle );
  89. /// @return the style id from the style name
  90. /// (mainly to read style from .sch file)
  91. static PLOT_DASH_TYPE GetLineStyleByName( const wxString& aStyleName );
  92. void SetLineColor( const COLOR4D& aColor );
  93. void SetLineColor( const double r, const double g, const double b, const double a );
  94. /// Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line
  95. COLOR4D GetLineColor() const;
  96. void SetLineWidth( const int aSize );
  97. virtual bool HasLineStroke() const override { return true; }
  98. virtual STROKE_PARAMS GetStroke() const override { return m_stroke; }
  99. virtual void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
  100. bool IsStrokeEquivalent( const SCH_LINE* aLine )
  101. {
  102. if( m_stroke.GetWidth() != aLine->GetStroke().GetWidth() )
  103. return false;
  104. if( m_stroke.GetColor() != aLine->GetStroke().GetColor() )
  105. return false;
  106. PLOT_DASH_TYPE style_a = m_stroke.GetPlotStyle();
  107. PLOT_DASH_TYPE style_b = aLine->GetStroke().GetPlotStyle();
  108. return style_a == style_b
  109. || ( style_a == PLOT_DASH_TYPE::DEFAULT && style_b == PLOT_DASH_TYPE::SOLID )
  110. || ( style_a == PLOT_DASH_TYPE::SOLID && style_b == PLOT_DASH_TYPE::DEFAULT );
  111. }
  112. /**
  113. * Test if the #SCH_LINE object uses the default stroke settings.
  114. *
  115. * The stroke settings include the line width, style, and color.
  116. *
  117. * @return True if the #SCH_LINE object uses the default stroke settings.
  118. */
  119. bool UsesDefaultStroke() const;
  120. int GetLineSize() const { return m_stroke.GetWidth(); }
  121. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  122. const EDA_RECT GetBoundingBox() const override;
  123. /**
  124. * @return The length of the line segment.
  125. */
  126. double GetLength() const;
  127. void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
  128. int GetPenWidth() const override;
  129. void Move( const wxPoint& aMoveVector ) override;
  130. void MoveStart( const wxPoint& aMoveVector );
  131. void MoveEnd( const wxPoint& aMoveVector );
  132. void MirrorX( int aXaxis_position ) override;
  133. void MirrorY( int aYaxis_position ) override;
  134. void Rotate( wxPoint aPosition ) override;
  135. void RotateStart( wxPoint aPosition );
  136. void RotateEnd( wxPoint aPosition );
  137. /**
  138. * Check line against \a aLine to see if it overlaps and merge if it does.
  139. *
  140. * This method will return an equivalent of the union of line and \a aLine if the
  141. * two lines overlap. This method is used to merge multiple line segments into a single
  142. * line.
  143. *
  144. * @param aScreen - the current screen
  145. * @param aLine - Line to compare.
  146. * @param aCheckJunctions - indicates we need to check for a junction if the two segments
  147. * are colinear and touch
  148. * @return New line that combines the two or NULL on non-overlapping segments.
  149. */
  150. SCH_LINE* MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions );
  151. /**
  152. * Check if two lines are in the same quadrant as each other, using a reference point as
  153. * the origin
  154. *
  155. * @param aLine - Line to compare
  156. * @param aPosition - Point to reference against lines
  157. * @return true if lines are mostly in different quadrants of aPosition, false otherwise
  158. */
  159. bool IsSameQuadrant( SCH_LINE* aLine, const wxPoint& aPosition );
  160. bool IsParallel( SCH_LINE* aLine );
  161. void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
  162. bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
  163. const SCH_SHEET_PATH* aPath = nullptr ) override;
  164. bool IsStartDangling() const { return m_startIsDangling; }
  165. bool IsEndDangling() const { return m_endIsDangling; }
  166. bool IsDangling() const override { return m_startIsDangling || m_endIsDangling; }
  167. bool IsConnectable() const override;
  168. std::vector<wxPoint> GetConnectionPoints() const override;
  169. void GetSelectedPoints( std::vector< wxPoint >& aPoints ) const;
  170. bool CanConnect( const SCH_ITEM* aItem ) const override;
  171. wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
  172. BITMAP_DEF GetMenuImage() const override;
  173. bool operator <( const SCH_ITEM& aItem ) const override;
  174. wxPoint GetPosition() const override { return m_start; }
  175. void SetPosition( const wxPoint& aPosition ) override;
  176. bool IsPointClickableAnchor( const wxPoint& aPos ) const override
  177. {
  178. return ( GetStartPoint() == aPos && IsStartDangling() )
  179. || ( GetEndPoint() == aPos && IsEndDangling() );
  180. }
  181. bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
  182. bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
  183. void Plot( PLOTTER* aPlotter ) override;
  184. EDA_ITEM* Clone() const override;
  185. void SwapData( SCH_ITEM* aItem ) override;
  186. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  187. #if defined(DEBUG)
  188. void Show( int nestLevel, std::ostream& os ) const override;
  189. #endif
  190. /**
  191. * Returns if the line is a graphic (non electrical line)
  192. *
  193. * Currently, anything on the internal NOTES layer is a graphic line
  194. */
  195. bool IsGraphicLine() const;
  196. /**
  197. * Returns true if the line is a wire.
  198. *
  199. * @return true if this line is on the wire layer.
  200. */
  201. bool IsWire() const;
  202. private:
  203. bool doIsConnected( const wxPoint& aPosition ) const override;
  204. };
  205. #endif // _SCH_LINE_H_