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.

516 lines
16 KiB

15 years ago
15 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-2011 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 class_libentry.h
  26. * @brief Class LIB_PIN definition.
  27. */
  28. #ifndef CLASS_PIN_H
  29. #define CLASS_PIN_H
  30. #include <lib_draw_item.h>
  31. #define TARGET_PIN_RADIUS 12 /* Circle diameter drawn at the active end of pins */
  32. #define PIN_LENGTH 300 /* Default Length of each pin to be drawn. */
  33. #if defined(KICAD_GOST)
  34. #define INVERT_PIN_RADIUS 20 /* Radius of inverted pin circle. */
  35. #else
  36. #define INVERT_PIN_RADIUS 35 /* Radius of inverted pin circle. */
  37. #endif
  38. #define CLOCK_PIN_DIM 40 /* Dim of clock pin symbol. */
  39. #define IEEE_SYMBOL_PIN_DIM 40 /* Dim of special pin symbol. */
  40. #define NONLOGIC_PIN_DIM 30 /* Dim of nonlogic pin symbol (X). */
  41. /**
  42. * The component library pin object electrical types used in ERC tests.
  43. */
  44. enum ElectricPinType {
  45. PIN_INPUT,
  46. PIN_OUTPUT,
  47. PIN_BIDI,
  48. PIN_TRISTATE,
  49. PIN_PASSIVE,
  50. PIN_UNSPECIFIED,
  51. PIN_POWER_IN,
  52. PIN_POWER_OUT,
  53. PIN_OPENCOLLECTOR,
  54. PIN_OPENEMITTER,
  55. PIN_NC, /* No connect */
  56. PIN_NMAX /* End of List (no used as pin type) */
  57. };
  58. /* Electrical pin type names. */
  59. extern const wxChar* MsgPinElectricType[];
  60. /* Pin visibility flag bit. */
  61. #define PIN_INVISIBLE 1 /* Set makes pin invisible */
  62. /**
  63. * The component library pin object drawing shapes.
  64. */
  65. enum DrawPinShape {
  66. NONE = 0,
  67. INVERT = 1,
  68. CLOCK = 2,
  69. LOWLEVEL_IN = 4,
  70. LOWLEVEL_OUT = 8,
  71. CLOCK_FALL = 0x10, /* this is common form for inverted clock in Eastern Block */
  72. NONLOGIC = 0x20
  73. };
  74. /**
  75. * The component library pin object orientations.
  76. */
  77. enum DrawPinOrient {
  78. PIN_RIGHT = 'R',
  79. PIN_LEFT = 'L',
  80. PIN_UP = 'U',
  81. PIN_DOWN = 'D'
  82. };
  83. class LIB_PIN : public LIB_ITEM
  84. {
  85. wxPoint m_position; ///< Position of the pin.
  86. int m_length; ///< Length of the pin.
  87. int m_orientation; ///< Pin orientation (Up, Down, Left, Right)
  88. int m_shape; ///< Bitwise ORed of pin shapes (see enum DrawPinShape)
  89. int m_width; ///< Line width of the pin.
  90. int m_type; ///< Electrical type of the pin. See enum ElectricPinType.
  91. int m_attributes; ///< Set bit 0 to indicate pin is invisible.
  92. wxString m_name;
  93. long m_number; ///< Pin number defined as 4 ASCII characters like "12", "anod",
  94. ///< "G6", or "12". It is stored as "12\0\0" and does not
  95. ///< depend on endian type.
  96. int m_numTextSize;
  97. int m_nameTextSize; /* Pin num and Pin name sizes */
  98. void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
  99. EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode, void* aData,
  100. const TRANSFORM& aTransform );
  101. public:
  102. LIB_PIN( LIB_COMPONENT* aParent );
  103. // Do not create a copy constructor. The one generated by the compiler is adequate.
  104. ~LIB_PIN() { }
  105. wxString GetClass() const
  106. {
  107. return wxT( "LIB_PIN" );
  108. }
  109. #if defined(DEBUG)
  110. void Show( int nestLevel, std::ostream& os ) const; // virtual override
  111. #endif
  112. bool Save( OUTPUTFORMATTER& aFormatter );
  113. bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
  114. bool HitTest( const wxPoint& aPosition );
  115. bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform );
  116. void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
  117. bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
  118. EDA_RECT GetBoundingBox() const;
  119. /**
  120. * Function ReturnPinEndPoint
  121. *
  122. * @return The pin end position for a component in the normal orientation.
  123. */
  124. wxPoint ReturnPinEndPoint() const;
  125. /**
  126. * Function ReturnPinDrawOrient
  127. * returns the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT),
  128. * according to its orientation and the matrix transform (rot, mirror) \a aTransform
  129. *
  130. * @param aTransform Transform matrix
  131. */
  132. int ReturnPinDrawOrient( const TRANSFORM& aTransform ) const;
  133. /**
  134. * Fill a string buffer with pin number.
  135. *
  136. * Pin numbers are coded as a long or 4 ASCII characters. Used to print
  137. * or draw the pin number.
  138. *
  139. * @param aStringBuffer - the wxString to store the pin num as an unicode string
  140. */
  141. void ReturnPinStringNum( wxString& aStringBuffer ) const;
  142. long GetNumber() const { return m_number; }
  143. wxString GetNumberString() const { return ReturnPinStringNum( m_number ); }
  144. /**
  145. * Function ReturnPinStringNum (static function)
  146. * Pin num is coded as a long or 4 ascii chars
  147. * @param aPinNum = a long containing a pin num
  148. * @return aStringBuffer = the wxString to store the pin num as an
  149. * unicode string
  150. */
  151. static wxString ReturnPinStringNum( long aPinNum );
  152. /**
  153. * Function SetPinNumFromString
  154. * fill the pin number buffer with \a aBuffer.
  155. */
  156. void SetPinNumFromString( wxString& aBuffer );
  157. wxString GetName() const { return m_name; }
  158. /**
  159. * Set the pin name.
  160. *
  161. * This will also all of the pin names marked by EnableEditMode().
  162. *
  163. * @param aName New pin name.
  164. */
  165. void SetName( const wxString& aName );
  166. /**
  167. * Set the \a aSize of the pin name text.
  168. *
  169. * This will also update the text size of the name of the pins marked
  170. * by EnableEditMode().
  171. *
  172. * @param aSize The text size of the pin name in schematic units ( mils ).
  173. */
  174. void SetNameTextSize( int aSize );
  175. int GetNameTextSize() const { return m_nameTextSize; }
  176. /**
  177. * Set the pin number.
  178. *
  179. * Others pin numbers marked by EnableEditMode() are not modified
  180. * because each pin has its own number
  181. * @param aNumber New pin number.
  182. */
  183. void SetNumber( const wxString& aNumber );
  184. /**
  185. * Set the size of the pin number text.
  186. *
  187. * This will also update the text size of the number of the pins marked
  188. * by EnableEditMode().
  189. *
  190. * @param aSize The text size of the pin number in schematic units ( mils ).
  191. */
  192. void SetNumberTextSize( int aSize );
  193. int GetNumberTextSize() const { return m_numTextSize; }
  194. int GetOrientation() const { return m_orientation; }
  195. /**
  196. * Set orientation on the pin.
  197. *
  198. * This will also update the orientation of the pins marked by EnableEditMode().
  199. *
  200. * @param aOrientation - The orientation of the pin.
  201. */
  202. void SetOrientation( int aOrientation );
  203. void Rotate();
  204. int GetShape() const { return m_shape; }
  205. /**
  206. * Set the shape of the pin to \a aShape.
  207. *
  208. * This will also update the draw style of the pins marked by EnableEditMode().
  209. *
  210. * @param aShape - The draw shape of the pin. See enum DrawPinShape.
  211. */
  212. void SetShape( int aShape );
  213. /**
  214. * Get the electrical type of the pin.
  215. *
  216. * @return The electrical type of the pin (see enun ElectricPinType for values).
  217. */
  218. int GetType() const { return m_type; }
  219. /**
  220. * return a string giving the electrical type of the pin.
  221. *
  222. * @return The electrical name of the pin (see enun MsgPinElectricType for names).
  223. */
  224. wxString GetTypeString() const { return MsgPinElectricType[m_type]; }
  225. /**
  226. * Set the electrical type of the pin.
  227. *
  228. * This will also update the electrical type of the pins marked by
  229. * EnableEditMode().
  230. *
  231. * @param aType - The electrical type of the pin(see enun ElectricPinType for values).
  232. */
  233. void SetType( int aType );
  234. /**
  235. * Set the pin length.
  236. *
  237. * This will also update the length of the pins marked by EnableEditMode().
  238. *
  239. * @param aLength - The length of the pin in mils.
  240. */
  241. void SetLength( int aLength );
  242. int GetLength() { return m_length; }
  243. /**
  244. * Set the pin part number.
  245. *
  246. * If the pin is changed from not common to common to all parts, any
  247. * linked pins will be removed from the parent component.
  248. *
  249. * @param aPart - Number of the part the pin belongs to. Set to zero to
  250. * make pin common to all parts in a multi-part component.
  251. */
  252. void SetPartNumber( int aPart );
  253. /**
  254. * Set the body style (conversion) of the pin.
  255. *
  256. * If the pin is changed from not common to common to all body styles, any
  257. * linked pins will be removed from the parent component.
  258. *
  259. * @param aConversion - Body style of the pin. Set to zero to make pin
  260. * common to all body styles.
  261. */
  262. void SetConversion( int aConversion );
  263. /**
  264. * Set or clear the visibility flag for the pin.
  265. *
  266. * This will also update the visibility of the pins marked by
  267. * EnableEditMode().
  268. *
  269. * @param aVisible - True to make the pin visible or false to hide the pin.
  270. */
  271. void SetVisible( bool aVisible );
  272. /**
  273. * Enable or clear pin editing mode.
  274. *
  275. * The pin editing mode marks or unmarks all pins common to this
  276. * pin object for further editing. If any of the pin modification
  277. * methods are called after enabling the editing mode, all pins
  278. * marked for editing will have the same attribute changed. The
  279. * only case were this is not true making this pin common to all
  280. * parts or body styles in the component. See SetCommonToAllParts()
  281. * and SetCommonToAllBodyStyles() for more information.
  282. *
  283. * @param aEnable True marks all common pins for editing mode. False
  284. * clears the editing mode.
  285. * @param aEditPinByPin Enables the edit pin by pin mode.
  286. */
  287. void EnableEditMode( bool aEnable, bool aEditPinByPin = false );
  288. /**
  289. * Return the visibility status of the draw object.
  290. *
  291. * @return True if draw object is visible otherwise false.
  292. */
  293. bool IsVisible() { return ( m_attributes & PIN_INVISIBLE ) == 0; }
  294. int GetPenSize() const;
  295. /**
  296. * Function DrawPinSymbol
  297. * Draw the pin symbol without text.
  298. * If \a aColor != 0, draw with \a aColor, else with the normal pin color.
  299. */
  300. void DrawPinSymbol( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
  301. int aOrientation, GR_DRAWMODE aDrawMode,
  302. EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
  303. /**
  304. * Function DrawPinTexts
  305. * puts the pin number and pin text info, given the pin line coordinates.
  306. * The line must be vertical or horizontal. If PinText == NULL nothing is printed.
  307. * If PinNum = 0 no number is printed. The current zoom factor is taken into account.
  308. * If TextInside then the text is been put inside,otherwise all is drawn outside.
  309. * Pin Name: substring between '~' is negated
  310. * DrawMode = GR_OR, XOR ...
  311. */
  312. void DrawPinTexts( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
  313. int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName,
  314. EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode );
  315. /**
  316. * Function PlotPinTexts
  317. * plots the pin number and pin text info, given the pin line coordinates.
  318. * Same as DrawPinTexts((), but output is the plotter
  319. * The line must be vertical or horizontal.
  320. * If PinNext == NULL nothing is printed.
  321. * Current Zoom factor is taken into account.
  322. * If TextInside then the text is been put inside (moving from x1, y1 in
  323. * the opposite direction to x2,y2), otherwise all is drawn outside.
  324. */
  325. void PlotPinTexts( PLOTTER *aPlotter,
  326. wxPoint& aPosition,
  327. int aOrientation,
  328. int aTextInside,
  329. bool aDrawPinNum,
  330. bool aDrawPinName,
  331. int aWidth );
  332. void PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation );
  333. /**
  334. * Get a list of pin orientation names.
  335. *
  336. * @return List of valid pin orientation names.
  337. */
  338. static wxArrayString GetOrientationNames();
  339. /**
  340. * Get a list of pin orientation bitmaps for menus and dialogs.
  341. *
  342. * @return List of valid pin orientation bitmaps symbols in .xpm format
  343. */
  344. static const BITMAP_DEF* GetOrientationSymbols();
  345. /**
  346. * Get the orientation code by index used to set the pin orientation.
  347. *
  348. * @param aIndex - The index of the orientation code to look up.
  349. * @return Orientation code if index is valid. Returns right
  350. * orientation on index error.
  351. */
  352. static int GetOrientationCode( int aIndex );
  353. /**
  354. * Get the index of the orientation code.
  355. *
  356. * @param aCode - The orientation code to look up.
  357. * @return The index of the orientation code if found. Otherwise,
  358. * return wxNOT_FOUND.
  359. */
  360. static int GetOrientationCodeIndex( int aCode );
  361. /**
  362. * Get a list of pin draw style names.
  363. *
  364. * @return List of valid pin draw style names.
  365. */
  366. static wxArrayString GetStyleNames();
  367. /**
  368. * Get a list of pin styles bitmaps for menus and dialogs.
  369. *
  370. * @return List of valid pin electrical type bitmaps symbols in .xpm format.
  371. */
  372. static const BITMAP_DEF* GetStyleSymbols();
  373. /**
  374. * Get the pin draw style code by index used to set the pin draw style.
  375. *
  376. * @param aIndex - The index of the pin draw style code to look up.
  377. * @return Pin draw style code if index is valid. Returns NONE
  378. * style on index error.
  379. */
  380. static int GetStyleCode( int aIndex );
  381. /**
  382. * Get the index of the pin draw style code.
  383. *
  384. * @param aCode - The pin draw style code to look up.
  385. * @return The index of the pin draw style code if found. Otherwise,
  386. * return wxNOT_FOUND.
  387. */
  388. static int GetStyleCodeIndex( int aCode );
  389. /**
  390. * Get a list of pin electrical type names.
  391. *
  392. * @return List of valid pin electrical type names.
  393. */
  394. static wxArrayString GetElectricalTypeNames();
  395. /**
  396. * Get a list of pin electrical bitmaps for menus and dialogs.
  397. *
  398. * @return List of valid pin electrical type bitmaps symbols in .xpm format
  399. */
  400. static const BITMAP_DEF* GetElectricalTypeSymbols();
  401. void SetOffset( const wxPoint& aOffset );
  402. bool Inside( EDA_RECT& aRect ) const;
  403. void Move( const wxPoint& aPosition );
  404. wxPoint GetPosition() const { return m_position; }
  405. void MirrorHorizontal( const wxPoint& aCenter );
  406. void MirrorVertical( const wxPoint& aCenter );
  407. void Rotate( const wxPoint& aCenter, bool aRotateCCW = true );
  408. void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
  409. const TRANSFORM& aTransform );
  410. int GetWidth() const { return m_width; }
  411. void SetWidth( int aWidth );
  412. BITMAP_DEF GetMenuImage() const;
  413. wxString GetSelectMenuText() const;
  414. EDA_ITEM* Clone() const;
  415. private:
  416. /**
  417. * @copydoc LIB_ITEM::compare()
  418. *
  419. * The pin specific sort order is as follows:
  420. * - Pin number.
  421. * - Pin name, case insensitive compare.
  422. * - Pin horizontal (X) position.
  423. * - Pin vertical (Y) position.
  424. */
  425. int compare( const LIB_ITEM& aOther ) const;
  426. };
  427. #endif // CLASS_PIN_H