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.

315 lines
11 KiB

15 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
  5. * Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #ifndef CLASS_PIN_H
  26. #define CLASS_PIN_H
  27. #include <lib_item.h>
  28. #include <pin_type.h>
  29. #include <lib_symbol.h>
  30. // Circle diameter drawn at the active end of pins:
  31. #define TARGET_PIN_RADIUS schIUScale.MilsToIU( 15 )
  32. // Pin visibility flag bit:
  33. #define PIN_INVISIBLE 1 // Set makes pin invisible
  34. /**
  35. * The symbol library pin object orientations.
  36. */
  37. enum DrawPinOrient {
  38. PIN_RIGHT = 'R',
  39. PIN_LEFT = 'L',
  40. PIN_UP = 'U',
  41. PIN_DOWN = 'D'
  42. };
  43. class LIB_PIN : public LIB_ITEM
  44. {
  45. public:
  46. struct ALT
  47. {
  48. wxString m_Name;
  49. GRAPHIC_PINSHAPE m_Shape; // Shape drawn around pin
  50. ELECTRICAL_PINTYPE m_Type; // Electrical type of the pin.
  51. };
  52. ~LIB_PIN() { }
  53. wxString GetClass() const override
  54. {
  55. return wxT( "LIB_PIN" );
  56. }
  57. wxString GetTypeName() const override
  58. {
  59. return _( "Pin" );
  60. }
  61. int GetOrientation() const { return m_orientation; }
  62. void SetOrientation( int aOrientation ) { m_orientation = aOrientation; }
  63. GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
  64. void SetShape( GRAPHIC_PINSHAPE aShape ) { m_shape = aShape; }
  65. int GetLength() const { return m_length; }
  66. void SetLength( int aLength ) { m_length = aLength; }
  67. /**
  68. * Change the length of a pin and adjust its position based on orientation.
  69. *
  70. * @param aLength New length of pin
  71. */
  72. void ChangeLength( int aLength );
  73. ELECTRICAL_PINTYPE GetType() const { return m_type; }
  74. void SetType( ELECTRICAL_PINTYPE aType ) { m_type = aType; }
  75. wxString const GetCanonicalElectricalTypeName() const
  76. {
  77. return GetCanonicalElectricalTypeName( m_type );
  78. }
  79. wxString const GetElectricalTypeName() const
  80. {
  81. return ElectricalPinTypeGetText( m_type );
  82. }
  83. bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
  84. void SetVisible( bool aVisible )
  85. {
  86. if( aVisible )
  87. m_attributes &= ~PIN_INVISIBLE;
  88. else
  89. m_attributes |= PIN_INVISIBLE;
  90. }
  91. const wxString& GetName() const { return m_name; }
  92. wxString GetShownName() const;
  93. void SetName( const wxString& aName )
  94. {
  95. m_name = aName;
  96. // pin name string does not support spaces
  97. m_name.Replace( wxT( " " ), wxT( "_" ) );
  98. }
  99. const wxString& GetNumber() const { return m_number; }
  100. wxString GetShownNumber() const { return m_number; }
  101. void SetNumber( const wxString& aNumber )
  102. {
  103. m_number = aNumber;
  104. // pin number string does not support spaces
  105. m_number.Replace( wxT( " " ), wxT( "_" ) );
  106. }
  107. int GetNameTextSize() const { return m_nameTextSize; }
  108. void SetNameTextSize( int aSize ) { m_nameTextSize = aSize; }
  109. int GetNumberTextSize() const { return m_numTextSize; }
  110. void SetNumberTextSize( int aSize ) { m_numTextSize = aSize; }
  111. std::map<wxString, ALT>& GetAlternates() { return m_alternates; }
  112. ALT GetAlt( const wxString& aAlt ) { return m_alternates[ aAlt ]; }
  113. /**
  114. * Print a pin, with or without the pin texts
  115. *
  116. * @param aOffset Offset to draw
  117. * @param aData = used here as a boolean indicating whether or not to draw the pin
  118. * electrical types
  119. * @param aTransform Transform Matrix (rotation, mirror ..)
  120. */
  121. void print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
  122. const TRANSFORM& aTransform, bool aDimmed ) override;
  123. /**
  124. * Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT),
  125. * according to its orientation and the matrix transform (rot, mirror) \a aTransform.
  126. *
  127. * @param aTransform Transform matrix
  128. */
  129. int PinDrawOrient( const TRANSFORM& aTransform ) const;
  130. LIB_PIN( LIB_SYMBOL* aParent );
  131. LIB_PIN( LIB_SYMBOL* aParent, const wxString& aName, const wxString& aNumber, int aOrientation,
  132. ELECTRICAL_PINTYPE aPinType, int aLength, int aNameTextSize, int aNumTextSize,
  133. int aConvert, const VECTOR2I& aPos, int aUnit );
  134. // Do not create a copy constructor. The one generated by the compiler is adequate.
  135. // No, LIB_PINs don't really have operating poinst. But we draw SCH_PINs through their LIB_PIN
  136. // counterparts, so here we are....
  137. const wxString& GetOperatingPoint() const { return m_operatingPoint; }
  138. void SetOperatingPoint( const wxString& aText ) { m_operatingPoint = aText; }
  139. #if defined(DEBUG)
  140. void Show( int nestLevel, std::ostream& os ) const override;
  141. #endif
  142. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  143. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  144. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  145. const BOX2I ViewBBox() const override;
  146. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  147. /* Cannot use a default parameter here as it will not be compatible with the virtual. */
  148. const BOX2I GetBoundingBox() const override { return GetBoundingBox( false, true, false ); }
  149. /**
  150. * @param aIncludeInvisibles - if false, do not include labels for invisible pins
  151. * in the calculation.
  152. */
  153. const BOX2I GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNameAndNumber,
  154. bool aIncludeElectricalType ) const;
  155. /**
  156. * Return whether this pin forms a global power connection: i.e., is part of
  157. * a power symbol and of type POWER_IN, or is a legacy invisible global
  158. * power pin on a symbol.
  159. */
  160. bool IsGlobalPower() const
  161. {
  162. return GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN
  163. && ( !IsVisible() || (LIB_SYMBOL*) GetParent()->IsPower() );
  164. }
  165. int GetPenWidth() const override;
  166. /**
  167. * Plot the pin number and pin text info, given the pin line coordinates.
  168. * Same as DrawPinTexts((), but output is the plotter
  169. * The line must be vertical or horizontal.
  170. * If TextInside then the text is been put inside (moving from x1, y1 in
  171. * the opposite direction to x2,y2), otherwise all is drawn outside.
  172. */
  173. void PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, int aPinOrient, int aTextInside,
  174. bool aDrawPinNum, bool aDrawPinName, bool aDimmed ) const;
  175. void PlotSymbol( PLOTTER *aPlotter, const VECTOR2I &aPosition, int aOrientation,
  176. bool aDimmed ) const;
  177. void Offset( const VECTOR2I& aOffset ) override;
  178. void MoveTo( const VECTOR2I& aNewPosition ) override;
  179. VECTOR2I GetPosition() const override { return m_position; }
  180. void SetPosition( const VECTOR2I& aPos ) override { m_position = aPos; }
  181. VECTOR2I GetPinRoot() const;
  182. void MirrorHorizontal( const VECTOR2I& aCenter ) override;
  183. void MirrorVertical( const VECTOR2I& aCenter ) override;
  184. void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override;
  185. void Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
  186. const TRANSFORM& aTransform, bool aDimmed ) const override;
  187. BITMAPS GetMenuImage() const override;
  188. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
  189. EDA_ITEM* Clone() const override;
  190. void CalcEdit( const VECTOR2I& aPosition ) override;
  191. /**
  192. * Return a string giving the electrical type of a pin.
  193. *
  194. * Can be used when a known, not translated name is needed (for instance in net lists)
  195. *
  196. * @param aType is the electrical type (see enum ELECTRICAL_PINTYPE )
  197. * @return The electrical name for a pin type (see enun MsgPinElectricType for names).
  198. */
  199. static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
  200. protected:
  201. /**
  202. * Print the pin symbol without text.
  203. * If \a aColor != 0, draw with \a aColor, else with the normal pin color.
  204. */
  205. void printPinSymbol( const RENDER_SETTINGS *aSettings, const VECTOR2I &aPos, int aOrientation,
  206. bool aDimmed );
  207. /**
  208. * Put the pin number and pin text info, given the pin line coordinates.
  209. * The line must be vertical or horizontal.
  210. * If aDrawPinName == false the pin name is not printed.
  211. * If aDrawPinNum = false the pin number is not printed.
  212. * If aTextInside then the text is been put inside,otherwise all is drawn outside.
  213. * Pin Name: substring between '~' is negated
  214. */
  215. void printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos, int aPinOrient,
  216. int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed );
  217. /**
  218. * Draw the electrical type text of the pin (only for the footprint editor)
  219. */
  220. void printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECTOR2I& aPosition,
  221. int aOrientation, bool aDimmed );
  222. private:
  223. /**
  224. * @copydoc LIB_ITEM::compare()
  225. *
  226. * The pin specific sort order is as follows:
  227. * - Pin number.
  228. * - Pin name, case insensitive compare.
  229. * - Pin horizontal (X) position.
  230. * - Pin vertical (Y) position.
  231. */
  232. int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
  233. protected:
  234. VECTOR2I m_position; // Position of the pin.
  235. int m_length; // Length of the pin.
  236. int m_orientation; // Pin orientation (Up, Down, Left, Right)
  237. GRAPHIC_PINSHAPE m_shape; // Shape drawn around pin
  238. ELECTRICAL_PINTYPE m_type; // Electrical type of the pin.
  239. int m_attributes; // Set bit 0 to indicate pin is invisible.
  240. wxString m_name;
  241. wxString m_number;
  242. int m_numTextSize; // Pin num and Pin name sizes
  243. int m_nameTextSize;
  244. std::map<wxString, ALT> m_alternates; // Map of alternate name to ALT structure
  245. wxString m_operatingPoint; // No, LIB_PINs don't really have operating points.
  246. // But we draw SCH_PINs through their LIB_PIN
  247. // counterparts, so here we are....
  248. };
  249. #endif // CLASS_PIN_H