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.

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