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.

221 lines
6.7 KiB

7 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2004-2020 KiCad Developers, see change_log.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_bus_entry.h
  26. *
  27. */
  28. #ifndef _SCH_BUS_ENTRY_H_
  29. #define _SCH_BUS_ENTRY_H_
  30. #include <gal/color4d.h>
  31. #include <sch_item.h>
  32. #define TARGET_BUSENTRY_RADIUS Mils2iu( 12 ) // Circle diameter drawn at the ends
  33. /**
  34. * Base class for a bus or wire entry.
  35. */
  36. class SCH_BUS_ENTRY_BASE : public SCH_ITEM
  37. {
  38. public:
  39. SCH_BUS_ENTRY_BASE( KICAD_T aType, const wxPoint& pos = wxPoint( 0, 0 ), bool aFlipY = false );
  40. bool IsDanglingStart() const { return m_isDanglingStart; }
  41. bool IsDanglingEnd() const { return m_isDanglingEnd; }
  42. // Do not create a copy constructor. The one generated by the compiler is adequate.
  43. ~SCH_BUS_ENTRY_BASE() { }
  44. /**
  45. * Return true for items which are moved with the anchor point at mouse cursor
  46. * and false for items moved with no reference to anchor
  47. * @return false for a bus entry
  48. */
  49. bool IsMovableFromAnchorPoint() const override { return false; }
  50. wxPoint GetEnd() const;
  51. wxSize GetSize() const { return m_size; }
  52. void SetSize( const wxSize& aSize ) { m_size = aSize; }
  53. void SetPenWidth( int aWidth ) { m_stroke.SetWidth( aWidth ); }
  54. virtual bool HasLineStroke() const override { return true; }
  55. virtual STROKE_PARAMS GetStroke() const override { return m_stroke; }
  56. virtual void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
  57. PLOT_DASH_TYPE GetStrokeStyle() const;
  58. void SetStrokeStyle( PLOT_DASH_TYPE aStyle ) { m_stroke.SetPlotStyle( aStyle ); }
  59. COLOR4D GetStrokeColor() const;
  60. void SetStrokeColor( const COLOR4D& aColor ) { m_stroke.SetColor( aColor ); }
  61. void SwapData( SCH_ITEM* aItem ) override;
  62. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  63. void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
  64. const EDA_RECT GetBoundingBox() const override;
  65. void Move( const wxPoint& aMoveVector ) override
  66. {
  67. m_pos += aMoveVector;
  68. }
  69. void MirrorHorizontally( int aCenter ) override;
  70. void MirrorVertically( int aCenter ) override;
  71. void Rotate( wxPoint aPosition ) override;
  72. bool IsDangling() const override;
  73. bool IsConnectable() const override { return true; }
  74. std::vector<wxPoint> GetConnectionPoints() const override;
  75. wxPoint GetPosition() const override { return m_pos; }
  76. void SetPosition( const wxPoint& aPosition ) override { m_pos = aPosition; }
  77. bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
  78. bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
  79. void Plot( PLOTTER* aPlotter ) override;
  80. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  81. bool operator <( const SCH_ITEM& aItem ) const override;
  82. #if defined(DEBUG)
  83. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  84. #endif
  85. private:
  86. bool doIsConnected( const wxPoint& aPosition ) const override;
  87. protected:
  88. wxPoint m_pos;
  89. wxSize m_size;
  90. bool m_isDanglingStart;
  91. bool m_isDanglingEnd;
  92. STROKE_PARAMS m_stroke;
  93. };
  94. /**
  95. * Class for a wire to bus entry.
  96. */
  97. class SCH_BUS_WIRE_ENTRY : public SCH_BUS_ENTRY_BASE
  98. {
  99. public:
  100. SCH_BUS_WIRE_ENTRY( const wxPoint& pos = wxPoint( 0, 0 ), bool aFlipY = false );
  101. ~SCH_BUS_WIRE_ENTRY() { }
  102. static inline bool ClassOf( const EDA_ITEM* aItem )
  103. {
  104. return aItem && SCH_BUS_WIRE_ENTRY_T == aItem->Type();
  105. }
  106. wxString GetClass() const override
  107. {
  108. return wxT( "SCH_BUS_WIRE_ENTRY" );
  109. }
  110. int GetPenWidth() const override;
  111. void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) override;
  112. bool CanConnect( const SCH_ITEM* aItem ) const override
  113. {
  114. return aItem->Type() == SCH_LINE_T &&
  115. ( aItem->GetLayer() == LAYER_WIRE || aItem->GetLayer() == LAYER_BUS );
  116. }
  117. wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
  118. EDA_ITEM* Clone() const override;
  119. virtual bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override;
  120. BITMAP_DEF GetMenuImage() const override;
  121. bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
  122. const SCH_SHEET_PATH* aPath = nullptr ) override;
  123. /**
  124. * Pointer to the bus item (usually a bus wire) connected to this bus-wire
  125. * entry, if it is connected to one.
  126. */
  127. SCH_ITEM* m_connected_bus_item;
  128. };
  129. /**
  130. * Class for a bus to bus entry.
  131. */
  132. class SCH_BUS_BUS_ENTRY : public SCH_BUS_ENTRY_BASE
  133. {
  134. public:
  135. SCH_BUS_BUS_ENTRY( const wxPoint& pos = wxPoint( 0, 0 ), bool aFlipY = false );
  136. ~SCH_BUS_BUS_ENTRY() { }
  137. static inline bool ClassOf( const EDA_ITEM* aItem )
  138. {
  139. return aItem && SCH_BUS_BUS_ENTRY_T == aItem->Type();
  140. }
  141. wxString GetClass() const override
  142. {
  143. return wxT( "SCH_BUS_BUS_ENTRY" );
  144. }
  145. int GetPenWidth() const override;
  146. void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) override;
  147. bool CanConnect( const SCH_ITEM* aItem ) const override
  148. {
  149. return aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_BUS;
  150. }
  151. wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
  152. EDA_ITEM* Clone() const override;
  153. BITMAP_DEF GetMenuImage() const override;
  154. bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
  155. const SCH_SHEET_PATH* aPath = nullptr ) override;
  156. /**
  157. * Pointer to the bus items (usually bus wires) connected to this bus-bus
  158. * entry (either or both may be nullptr)
  159. */
  160. SCH_ITEM* m_connected_bus_items[2];
  161. };
  162. #endif // _SCH_BUS_ENTRY_H_