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.

262 lines
8.8 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 The 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_BUS_ENTRY_H_
  25. #define _SCH_BUS_ENTRY_H_
  26. #include <gal/color4d.h>
  27. #include <sch_item.h>
  28. #define TARGET_BUSENTRY_RADIUS schIUScale.MilsToIU( 12 ) // Circle diameter drawn at the ends
  29. /**
  30. * Base class for a bus or wire entry.
  31. */
  32. class SCH_BUS_ENTRY_BASE : public SCH_ITEM
  33. {
  34. public:
  35. SCH_BUS_ENTRY_BASE( KICAD_T aType, const VECTOR2I& pos = VECTOR2I( 0, 0 ),
  36. bool aFlipY = false );
  37. bool IsStartDangling() const { return m_isStartDangling; }
  38. bool IsEndDangling() const { return m_isEndDangling; }
  39. void SetEndDangling( bool aDanglingState ) { m_isEndDangling = aDanglingState; }
  40. // Do not create a copy constructor. The one generated by the compiler is adequate.
  41. ~SCH_BUS_ENTRY_BASE() { }
  42. void SetLastResolvedState( const SCH_ITEM* aItem ) override
  43. {
  44. const SCH_BUS_ENTRY_BASE* aEntry = dynamic_cast<const SCH_BUS_ENTRY_BASE*>( aItem );
  45. if( aEntry )
  46. {
  47. m_lastResolvedWidth = aEntry->m_lastResolvedWidth;
  48. m_lastResolvedLineStyle = aEntry->m_lastResolvedLineStyle;
  49. m_lastResolvedColor = aEntry->m_lastResolvedColor;
  50. }
  51. }
  52. /**
  53. * Return true for items which are moved with the anchor point at mouse cursor
  54. * and false for items moved with no reference to anchor
  55. * @return false for a bus entry
  56. */
  57. bool IsMovableFromAnchorPoint() const override { return false; }
  58. VECTOR2I GetEnd() const;
  59. VECTOR2I GetSize() const { return m_size; }
  60. void SetSize( const VECTOR2I& aSize ) { m_size = aSize; }
  61. // Base class getter unused; necessary for property to compile
  62. int GetPenWidth() const override;
  63. void SetPenWidth( int aWidth );
  64. virtual bool HasLineStroke() const override { return true; }
  65. virtual STROKE_PARAMS GetStroke() const override { return m_stroke; }
  66. virtual void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
  67. void SetLineStyle( LINE_STYLE aStyle );
  68. LINE_STYLE GetEffectiveLineStyle() const;
  69. // Special Getter/Setters for properties panel. Required because it uses WIRE_STYLE instead
  70. // of LINE_STYLE. (The two enums are identical, but we expose "default" in the WIRE_STYLE
  71. // property while we don't with the LINE_STYLE property.)
  72. void SetWireStyle( WIRE_STYLE aStyle ) { SetLineStyle( (LINE_STYLE) aStyle ); }
  73. WIRE_STYLE GetWireStyle() const { return (WIRE_STYLE) GetStroke().GetLineStyle(); }
  74. COLOR4D GetBusEntryColor() const;
  75. void SetBusEntryColor( const COLOR4D& aColor );
  76. void swapData( SCH_ITEM* aItem ) override;
  77. std::vector<int> ViewGetLayers() const override;
  78. const BOX2I GetBoundingBox() const override;
  79. void Move( const VECTOR2I& aMoveVector ) override
  80. {
  81. m_pos += aMoveVector;
  82. }
  83. void MirrorHorizontally( int aCenter ) override;
  84. void MirrorVertically( int aCenter ) override;
  85. void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
  86. bool IsDangling() const override;
  87. bool IsConnectable() const override { return true; }
  88. bool HasConnectivityChanges( const SCH_ITEM* aItem,
  89. const SCH_SHEET_PATH* aInstance = nullptr ) const override;
  90. std::vector<VECTOR2I> GetConnectionPoints() const override;
  91. VECTOR2I GetPosition() const override { return m_pos; }
  92. void SetPosition( const VECTOR2I& aPosition ) override { m_pos = aPosition; }
  93. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  94. bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
  95. {
  96. return ( GetPosition() == aPos && IsStartDangling() )
  97. || ( GetEnd() == aPos && IsEndDangling() );
  98. }
  99. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  100. void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
  101. int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
  102. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  103. bool operator <( const SCH_ITEM& aItem ) const override;
  104. double Similarity( const SCH_ITEM& aItem ) const override;
  105. bool operator==( const SCH_ITEM& aItem ) const override;
  106. #if defined(DEBUG)
  107. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  108. #endif
  109. private:
  110. bool doIsConnected( const VECTOR2I& aPosition ) const override;
  111. protected:
  112. VECTOR2I m_pos;
  113. VECTOR2I m_size;
  114. bool m_isStartDangling;
  115. bool m_isEndDangling;
  116. STROKE_PARAMS m_stroke;
  117. // If real-time connectivity gets disabled (due to being too slow on a particular
  118. // design), we can no longer rely on getting the NetClass to find netclass-specific
  119. // linestyles, linewidths and colors.
  120. mutable LINE_STYLE m_lastResolvedLineStyle;
  121. mutable int m_lastResolvedWidth;
  122. mutable COLOR4D m_lastResolvedColor;
  123. };
  124. /**
  125. * Class for a wire to bus entry.
  126. */
  127. class SCH_BUS_WIRE_ENTRY : public SCH_BUS_ENTRY_BASE
  128. {
  129. public:
  130. SCH_BUS_WIRE_ENTRY( const VECTOR2I& pos = VECTOR2I( 0, 0 ), bool aFlipY = false );
  131. SCH_BUS_WIRE_ENTRY( const VECTOR2I& pos, int aQuadrant );
  132. ~SCH_BUS_WIRE_ENTRY() { }
  133. static inline bool ClassOf( const EDA_ITEM* aItem )
  134. {
  135. return aItem && SCH_BUS_WIRE_ENTRY_T == aItem->Type();
  136. }
  137. wxString GetClass() const override
  138. {
  139. return wxT( "SCH_BUS_WIRE_ENTRY" );
  140. }
  141. int GetPenWidth() const override;
  142. void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) override;
  143. bool CanConnect( const SCH_ITEM* aItem ) const override
  144. {
  145. return aItem->Type() == SCH_LINE_T &&
  146. ( aItem->GetLayer() == LAYER_WIRE || aItem->GetLayer() == LAYER_BUS );
  147. }
  148. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
  149. EDA_ITEM* Clone() const override;
  150. virtual bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override;
  151. BITMAPS GetMenuImage() const override;
  152. bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemListByType,
  153. std::vector<DANGLING_END_ITEM>& aItemListByPos,
  154. const SCH_SHEET_PATH* aPath = nullptr ) override;
  155. /**
  156. * Pointer to the bus item (usually a bus wire) connected to this bus-wire
  157. * entry, if it is connected to one.
  158. */
  159. SCH_ITEM* m_connected_bus_item;
  160. };
  161. /**
  162. * Class for a bus to bus entry.
  163. */
  164. class SCH_BUS_BUS_ENTRY : public SCH_BUS_ENTRY_BASE
  165. {
  166. public:
  167. SCH_BUS_BUS_ENTRY( const VECTOR2I& pos = VECTOR2I( 0, 0 ), bool aFlipY = false );
  168. ~SCH_BUS_BUS_ENTRY() { }
  169. static inline bool ClassOf( const EDA_ITEM* aItem )
  170. {
  171. return aItem && SCH_BUS_BUS_ENTRY_T == aItem->Type();
  172. }
  173. wxString GetClass() const override
  174. {
  175. return wxT( "SCH_BUS_BUS_ENTRY" );
  176. }
  177. int GetPenWidth() const override;
  178. void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) override;
  179. bool CanConnect( const SCH_ITEM* aItem ) const override
  180. {
  181. return aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_BUS;
  182. }
  183. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
  184. EDA_ITEM* Clone() const override;
  185. BITMAPS GetMenuImage() const override;
  186. bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemListByType,
  187. std::vector<DANGLING_END_ITEM>& aItemListByPos,
  188. const SCH_SHEET_PATH* aPath = nullptr ) override;
  189. /**
  190. * Pointer to the bus items (usually bus wires) connected to this bus-bus
  191. * entry (either or both may be nullptr)
  192. */
  193. SCH_ITEM* m_connected_bus_items[2];
  194. };
  195. #endif // _SCH_BUS_ENTRY_H_