KiCad PCB EDA Suite
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2009 Jean-Pierre Charras,
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
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  *
20  * or you may search the 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  */
25 #ifndef _SCH_LINE_H_
26 #define _SCH_LINE_H_
28 #include <sch_item.h>
37 class SCH_LINE : public SCH_ITEM
38 {
45 public:
47  static const enum wxPenStyle PenStyle[];
49  SCH_LINE( const wxPoint& pos = wxPoint( 0, 0 ), int layer = LAYER_NOTES );
51  SCH_LINE( const VECTOR2D& pos, int layer = LAYER_NOTES ) :
52  SCH_LINE( wxPoint( pos.x, pos.y ), layer )
53  {}
55  SCH_LINE( const SCH_LINE& aLine );
57  ~SCH_LINE() { }
59  static inline bool ClassOf( const EDA_ITEM* aItem )
60  {
61  return aItem && SCH_LINE_T == aItem->Type();
62  }
64  wxString GetClass() const override
65  {
66  return wxT( "SCH_LINE" );
67  }
69  bool IsType( const KICAD_T aScanTypes[] ) const override
70  {
71  if( SCH_ITEM::IsType( aScanTypes ) )
72  return true;
74  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
75  {
76  if( *p == SCH_LINE_LOCATE_WIRE_T && m_Layer == LAYER_WIRE )
77  return true;
78  else if ( *p == SCH_LINE_LOCATE_BUS_T && m_Layer == LAYER_BUS )
79  return true;
80  else if ( *p == SCH_LINE_LOCATE_GRAPHIC_LINE_T && m_Layer == LAYER_NOTES )
81  return true;
82  }
84  return false;
85  }
87  bool IsEndPoint( const wxPoint& aPoint ) const
88  {
89  return aPoint == m_start || aPoint == m_end;
90  }
92  bool IsNull() const { return m_start == m_end; }
94  wxPoint GetStartPoint() const { return m_start; }
95  void SetStartPoint( const wxPoint& aPosition ) { m_start = aPosition; }
97  wxPoint GetEndPoint() const { return m_end; }
98  void SetEndPoint( const wxPoint& aPosition ) { m_end = aPosition; }
102  void SetLineStyle( const PLOT_DASH_TYPE aStyle );
103  void SetLineStyle( const int aStyleId );
112  static const char* GetLineStyleName( PLOT_DASH_TYPE aStyle );
116  static PLOT_DASH_TYPE GetLineStyleByName( const wxString& aStyleName );
118  void SetLineColor( const COLOR4D& aColor );
120  void SetLineColor( const double r, const double g, const double b, const double a );
123  COLOR4D GetLineColor() const;
125  void SetLineWidth( const int aSize );
127  virtual bool HasLineStroke() const override { return true; }
128  virtual STROKE_PARAMS GetStroke() const override { return m_stroke; }
129  virtual void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
138  bool UsesDefaultStroke() const;
140  int GetLineSize() const { return m_stroke.GetWidth(); }
142  void ViewGetLayers( int aLayers[], int& aCount ) const override;
144  const EDA_RECT GetBoundingBox() const override;
149  double GetLength() const;
151  void Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
153  int GetPenWidth() const override;
155  void Move( const wxPoint& aMoveVector ) override;
156  void MoveStart( const wxPoint& aMoveVector );
157  void MoveEnd( const wxPoint& aMoveVector );
159  void MirrorX( int aXaxis_position ) override;
160  void MirrorY( int aYaxis_position ) override;
161  void Rotate( wxPoint aPosition ) override;
162  void RotateStart( wxPoint aPosition );
163  void RotateEnd( wxPoint aPosition );
175  SCH_LINE* MergeOverlap( SCH_LINE* aLine );
185  bool IsSameQuadrant( SCH_LINE* aLine, const wxPoint& aPosition );
187  bool IsParallel( SCH_LINE* aLine );
189  void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
191  bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
192  const SCH_SHEET_PATH* aPath = nullptr ) override;
194  bool IsStartDangling() const { return m_startIsDangling; }
195  bool IsEndDangling() const { return m_endIsDangling; }
196  bool IsDangling() const override { return m_startIsDangling || m_endIsDangling; }
198  bool IsConnectable() const override;
200  std::vector<wxPoint> GetConnectionPoints() const override;
202  void GetSelectedPoints( std::vector< wxPoint >& aPoints ) const;
204  bool CanConnect( const SCH_ITEM* aItem ) const override;
206  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
208  BITMAP_DEF GetMenuImage() const override;
210  bool operator <( const SCH_ITEM& aItem ) const override;
212  wxPoint GetPosition() const override { return m_start; }
213  void SetPosition( const wxPoint& aPosition ) override;
215  bool IsPointClickableAnchor( const wxPoint& aPos ) const override
216  {
217  return ( GetStartPoint() == aPos && IsStartDangling() )
218  || ( GetEndPoint() == aPos && IsEndDangling() );
219  }
221  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
222  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
224  void Plot( PLOTTER* aPlotter ) override;
226  EDA_ITEM* Clone() const override;
228  void SwapData( SCH_ITEM* aItem ) override;
230  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
232 #if defined(DEBUG)
233  void Show( int nestLevel, std::ostream& os ) const override;
234 #endif
241  bool IsGraphicLine() const;
248  bool IsWire() const;
250 private:
251  bool doIsConnected( const wxPoint& aPosition ) const override;
252 };
255 #endif // _SCH_LINE_H_
void Rotate(wxPoint aPosition) override
Rotate the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_line.cpp:348
Definition: common.h:200
SCH_LINE * MergeOverlap(SCH_LINE *aLine)
Check line against aLine to see if it overlaps and merge if it does.
Definition: sch_line.cpp:403
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Add the schematic item end points to aItemList if the item has end points.
Definition: sch_line.cpp:516
static const char * GetLineStyleName(PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:83
Definition: sch_item.h:199
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:208
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_line.h:64
bool IsGraphicLine() const
Returns if the line is a graphic (non electrical line)
Definition: sch_line.cpp:846
PNG memory record (file in memory).
Definition: bitmap_def.h:29
wxPoint GetStartPoint() const
Definition: sch_line.h:94
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
bool IsWire() const
Returns true if the line is a wire.
Definition: sch_line.cpp:852
bool m_endIsDangling
True if end point is not connected.
Definition: sch_line.h:40
virtual bool HasLineStroke() const override
Check if this schematic item has line stoke properties.
Definition: sch_line.h:127
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:269
void RotateEnd(wxPoint aPosition)
Definition: sch_line.cpp:361
void MoveStart(const wxPoint &aMoveVector)
Definition: sch_line.cpp:119
bool IsParallel(SCH_LINE *aLine)
Definition: sch_line.cpp:390
void Plot(PLOTTER *aPlotter) override
Plot the schematic item to aPlotter.
Definition: sch_line.cpp:765
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: sch_line.cpp:805
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_line.cpp:583
The base class for create windows for drawing purpose.
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_line.h:59
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_line.cpp:156
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_line.cpp:640
search types array terminator (End Of Types)
Definition: typeinfo.h:82
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: sch_line.cpp:711
void RotateStart(wxPoint aPosition)
Definition: sch_line.cpp:355
bool UsesDefaultStroke() const
Test if the SCH_LINE object uses the default stroke settings.
Definition: sch_line.cpp:858
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_line.cpp:108
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:98
bool IsConnectable() const override
Definition: sch_line.cpp:574
PLOT_DASH_TYPE GetDefaultStyle() const
Definition: sch_line.cpp:222
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:237
void MirrorX(int aXaxis_position) override
Mirror item relative to the X axis about aXaxis_position.
Definition: sch_line.cpp:334
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_line.cpp:677
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:246
bool IsNull() const
Definition: sch_line.h:92
bool IsEndDangling() const
Definition: sch_line.h:195
double GetLength() const
Definition: sch_line.cpp:181
void SetStartPoint(const wxPoint &aPosition)
Definition: sch_line.h:95
bool m_startIsDangling
True if start point is not connected.
Definition: sch_line.h:39
int GetPenWidth() const override
Definition: sch_line.cpp:275
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: eda_item.h:250
bool IsDangling() const override
Definition: sch_line.h:196
Definition: sch_line.h:57
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:187
bool IsEndPoint(const wxPoint &aPoint) const
Definition: sch_line.h:87
int GetWidth() const
Definition: sch_item.h:169
bool doIsConnected(const wxPoint &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_line.cpp:756
void GetSelectedPoints(std::vector< wxPoint > &aPoints) const
Definition: sch_line.cpp:630
static PLOT_DASH_TYPE GetLineStyleByName(const wxString &aStyleName)
Definition: sch_line.cpp:93
wxPoint m_end
Line end point.
Definition: sch_line.h:42
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_line.cpp:742
Line stroke properties.
Definition: sch_line.h:43
Enum for choosing dashed line type.
Definition: plotter.h:93
bool IsSameQuadrant(SCH_LINE *aLine, const wxPoint &aPosition)
Check if two lines are in the same quadrant as each other, using a reference point as the origin.
Definition: sch_line.cpp:367
Base plotter engine class.
Definition: plotter.h:120
int GetLineSize() const
Definition: sch_line.h:140
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_line.h:129
PLOT_DASH_TYPE GetEffectiveLineStyle() const
Definition: sch_line.cpp:255
static enum wxPenStyle PenStyle[]
Definition: sch_line.h:47
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_line.cpp:66
void MoveEnd(const wxPoint &aMoveVector)
Definition: sch_line.cpp:129
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_line.cpp:688
Simple container to manage line stroke parameters.
Definition: sch_item.h:153
wxPoint GetPosition() const override
Definition: sch_line.h:212
bool IsStartDangling() const
Definition: sch_line.h:194
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: eda_item.h:147
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:128
void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_line.cpp:317
void MirrorY(int aYaxis_position) override
Mirror item relative to the Y axis about aYaxis_position.
Definition: sch_line.cpp:341
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemList, const SCH_SHEET_PATH *aPath=nullptr) override
Test the schematic item to aItemList to check if it's dangling state has changed.
Definition: sch_line.cpp:534
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_line.cpp:164
bool IsPointClickableAnchor(const wxPoint &aPos) const override
Definition: sch_line.h:215
void SetPosition(const wxPoint &aPosition) override
Definition: sch_line.cpp:798
bool IsType(const KICAD_T aScanTypes[]) const override
Function IsType Checks whether the item is one of the listed types.
Definition: sch_line.h:69
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
wxPoint m_start
Line start point.
Definition: sch_line.h:41
SCH_LINE(const wxPoint &pos=wxPoint(0, 0), int layer=LAYER_NOTES)
Definition: sch_line.cpp:36
std::vector< wxPoint > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:624
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100
SCH_LINE(const VECTOR2D &pos, int layer=LAYER_NOTES)
Definition: sch_line.h:51
wxPoint GetEndPoint() const
Definition: sch_line.h:97