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
18 KiB

15 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 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-2017 KiCad Developers, see change_log.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. /**
  26. * @file class_libentry.h
  27. * @brief Class LIB_PIN definition.
  28. */
  29. #ifndef CLASS_PIN_H
  30. #define CLASS_PIN_H
  31. class SCH_COMPONENT;
  32. #include <eda_rect.h>
  33. #include <lib_draw_item.h>
  34. #include "pin_shape.h"
  35. #include "pin_type.h"
  36. #include "class_libentry.h"
  37. // Circle diameter drawn at the active end of pins:
  38. #define TARGET_PIN_RADIUS 15
  39. // Pin visibility flag bit:
  40. #define PIN_INVISIBLE 1 // Set makes pin invisible
  41. /**
  42. * The component library pin object orientations.
  43. */
  44. enum DrawPinOrient {
  45. PIN_RIGHT = 'R',
  46. PIN_LEFT = 'L',
  47. PIN_UP = 'U',
  48. PIN_DOWN = 'D'
  49. };
  50. enum LibPinDrawFlags {
  51. PIN_DRAW_TEXTS = 1,
  52. PIN_DRAW_DANGLING = 2, // Draw this pin with a 'dangling' indicator
  53. PIN_DANGLING_HIDDEN = 4, // Draw (only!) the dangling indicator if the pin is hidden
  54. PIN_DRAW_ELECTRICAL_TYPE_NAME = 8 // Draw the pin electrical type name
  55. // used only in component editor and component viewer
  56. };
  57. class LIB_PIN : public LIB_ITEM
  58. {
  59. // Unlike most of the other LIB_ITEMs, the SetXXX() routines on LIB_PINs are at the UI
  60. // level, performing additional pin checking, multi-pin editing, and setting the modified
  61. // flag. So the LEGACY_PLUGIN_CACHE needs direct access to the member variables.
  62. friend class SCH_LEGACY_PLUGIN_CACHE;
  63. wxPoint m_position; ///< Position of the pin.
  64. int m_length; ///< Length of the pin.
  65. int m_orientation; ///< Pin orientation (Up, Down, Left, Right)
  66. GRAPHIC_PINSHAPE m_shape; ///< Shape drawn around pin
  67. int m_width; ///< Line width of the pin.
  68. ELECTRICAL_PINTYPE m_type; ///< Electrical type of the pin. See enum ELECTRICAL_PINTYPE.
  69. int m_attributes; ///< Set bit 0 to indicate pin is invisible.
  70. wxString m_name;
  71. wxString m_number;
  72. int m_numTextSize;
  73. int m_nameTextSize; ///< Pin num and Pin name sizes
  74. /**
  75. * Draw a pin, with or without the pin texts
  76. *
  77. * @param aPanel DrawPanel to use (can be null) mainly used for clipping purposes.
  78. * @param aDC Device Context (can be null)
  79. * @param aOffset Offset to draw
  80. * @param aColor COLOR4D::UNSPECIFIED to use the normal body item color, or else use this color
  81. * @param aDrawMode GR_OR, GR_XOR, ...
  82. * @param aData = used here as uintptr_t containing bitwise OR'd flags:
  83. * PIN_DRAW_TEXTS, -- false to draw only pin shape, useful for fast mode
  84. * PIN_DRAW_DANGLING, -- true to draw the pin with its target
  85. * PIN_DANGLING_HIDDEN -- draw the target even if the pin is hidden
  86. * PIN_DRAW_ELECTRICAL_TYPE_NAME -- Draw the pin electrical type name
  87. * @param aTransform Transform Matrix (rotation, mirror ..)
  88. */
  89. void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
  90. COLOR4D aColor, GR_DRAWMODE aDrawMode, void* aData,
  91. const TRANSFORM& aTransform ) override;
  92. public:
  93. LIB_PIN( LIB_PART* aParent );
  94. // Do not create a copy constructor. The one generated by the compiler is adequate.
  95. ~LIB_PIN() { }
  96. wxString GetClass() const override
  97. {
  98. return wxT( "LIB_PIN" );
  99. }
  100. wxString GetTypeName() override
  101. {
  102. return _( "Pin" );
  103. }
  104. #if defined(DEBUG)
  105. void Show( int nestLevel, std::ostream& os ) const override;
  106. #endif
  107. bool HitTest( const wxPoint& aPosition ) const override;
  108. bool HitTest( const wxPoint &aPosRef, int aThreshold, const TRANSFORM& aTransform ) const override;
  109. void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
  110. /**
  111. * Display pin info (given by GetMsgPanelInfo) and add some info related to aComponent
  112. * (schematic pin position, and sheet path)
  113. * @param aList is the message list to fill
  114. * @param aComponent is the component which "owns" the pin
  115. */
  116. void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList,
  117. SCH_COMPONENT* aComponent );
  118. bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ) override;
  119. /* Cannot use a default parameter here as it will not be compatible with the virtual. */
  120. const EDA_RECT GetBoundingBox() const override { return GetBoundingBox( false ); }
  121. /**
  122. * @param aIncludeInvisibles - if false, do not include labels for invisible pins
  123. * in the calculation.
  124. */
  125. const EDA_RECT GetBoundingBox( bool aIncludeInvisibles ) const;
  126. /**
  127. * @return The pin end position for a component in the normal orientation.
  128. */
  129. wxPoint PinEndPoint() const;
  130. /**
  131. * Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT),
  132. * according to its orientation and the matrix transform (rot, mirror) \a aTransform.
  133. *
  134. * @param aTransform Transform matrix
  135. */
  136. int PinDrawOrient( const TRANSFORM& aTransform ) const;
  137. const wxString& GetName() const
  138. {
  139. return m_name;
  140. }
  141. /**
  142. * Set the pin name.
  143. *
  144. * This will also all of the pin names marked by EnableEditMode().
  145. *
  146. * @param aName New pin name.
  147. * @param aTestOtherPins determines if other pins need to be updated
  148. */
  149. void SetName( const wxString& aName, bool aTestOtherPins = true );
  150. /**
  151. * Set the \a aSize of the pin name text.
  152. *
  153. * This will also update the text size of the name of the pins marked
  154. * by EnableEditMode().
  155. *
  156. * @param aSize The text size of the pin name in schematic units ( mils ).
  157. * @param aTestOtherPins determines if other pins need to be updated
  158. */
  159. void SetNameTextSize( int aSize, bool aTestOtherPins = true );
  160. int GetNameTextSize() const { return m_nameTextSize; }
  161. const wxString& GetNumber() const
  162. {
  163. return m_number;
  164. }
  165. /**
  166. * Set the pin number.
  167. *
  168. * Others pin numbers marked by EnableEditMode() are not modified
  169. * because each pin has its own number
  170. * @param aNumber New pin number.
  171. */
  172. void SetNumber( const wxString& aNumber );
  173. /**
  174. * Set the size of the pin number text.
  175. *
  176. * This will also update the text size of the number of the pins marked
  177. * by EnableEditMode().
  178. *
  179. * @param aSize The text size of the pin number in schematic units ( mils ).
  180. * @param aTestOtherPins determines if other pins need to be updated
  181. */
  182. void SetNumberTextSize( int aSize, bool aTestOtherPins = true );
  183. int GetNumberTextSize() const { return m_numTextSize; }
  184. int GetOrientation() const { return m_orientation; }
  185. /**
  186. * Set orientation on the pin.
  187. *
  188. * This will also update the orientation of the pins marked by EnableEditMode().
  189. *
  190. * @param aOrientation - The orientation of the pin.
  191. * @param aTestOtherPins determines if other pins need to be updated
  192. */
  193. void SetOrientation( int aOrientation, bool aTestOtherPins = true );
  194. void Rotate() override;
  195. GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
  196. /**
  197. * Set the shape of the pin to \a aShape.
  198. *
  199. * This will also update the draw style of the pins marked by EnableEditMode().
  200. *
  201. * @param aShape - The draw shape of the pin. See enum GRAPHIC_PINSHAPE.
  202. */
  203. void SetShape( GRAPHIC_PINSHAPE aShape );
  204. /**
  205. * Get the electrical type of the pin.
  206. *
  207. * @return The electrical type of the pin (see enum ELECTRICAL_PINTYPE for values).
  208. */
  209. ELECTRICAL_PINTYPE GetType() const { return m_type; }
  210. /**
  211. * return a string giving the electrical type of a pin.
  212. * Can be used when a known, not translated name is needed (for instance in net lists)
  213. * @param aType is the electrical type (see enum ELECTRICAL_PINTYPE )
  214. * @return The electrical name for a pin type (see enun MsgPinElectricType for names).
  215. */
  216. static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
  217. /**
  218. * return a string giving the electrical type of the pin.
  219. * Can be used when a known, not translated name is needed (for instance in net lists)
  220. * @return The canonical electrical name of the pin.
  221. */
  222. wxString const GetCanonicalElectricalTypeName() const
  223. {
  224. return GetCanonicalElectricalTypeName( m_type );
  225. }
  226. /**
  227. * return a translated string for messages giving the electrical type of the pin.
  228. * @return The electrical name of the pin.
  229. */
  230. wxString const GetElectricalTypeName() const
  231. {
  232. return GetText( m_type );
  233. }
  234. /**
  235. * Set the electrical type of the pin.
  236. *
  237. * This will also update the electrical type of the pins marked by
  238. * EnableEditMode().
  239. *
  240. * @param aType - The electrical type of the pin(see enun ELECTRICAL_PINTYPE for values).
  241. * @param aTestOtherPins determines if other pins need to be updated
  242. */
  243. void SetType( ELECTRICAL_PINTYPE aType, bool aTestOtherPins = true );
  244. /**
  245. * Set the pin length.
  246. *
  247. * This will also update the length of the pins marked by EnableEditMode().
  248. *
  249. * @param aLength - The length of the pin in mils.
  250. * @param aTestOtherPins determines if other pins need to be updated
  251. */
  252. void SetLength( int aLength, bool aTestOtherPins = true );
  253. int GetLength() { return m_length; }
  254. /**
  255. * Set the pin part number.
  256. *
  257. * If the pin is changed from not common to common to all parts, any
  258. * linked pins will be removed from the parent component.
  259. *
  260. * @param aPart - Number of the part the pin belongs to. Set to zero to
  261. * make pin common to all parts in a multi-part component.
  262. */
  263. void SetPartNumber( int aPart );
  264. /** Get the pin part number. */
  265. int GetPartNumber() const { return m_Unit; }
  266. /**
  267. * Set the body style (conversion) of the pin.
  268. *
  269. * If the pin is changed from not common to common to all body styles, any
  270. * linked pins will be removed from the parent component.
  271. *
  272. * @param aConversion - Body style of the pin. Set to zero to make pin
  273. * common to all body styles.
  274. */
  275. void SetConversion( int aConversion );
  276. /**
  277. * Set or clear the visibility flag for the pin.
  278. *
  279. * This will also update the visibility of the pins marked by
  280. * EnableEditMode().
  281. *
  282. * @param aVisible - True to make the pin visible or false to hide the pin.
  283. */
  284. void SetVisible( bool aVisible );
  285. /**
  286. * Enable or clear pin editing mode.
  287. *
  288. * The pin editing mode marks or unmarks all pins common to this
  289. * pin object for further editing. If any of the pin modification
  290. * methods are called after enabling the editing mode, all pins
  291. * marked for editing will have the same attribute changed. The
  292. * only case were this is not true making this pin common to all
  293. * parts or body styles in the component. See SetCommonToAllParts()
  294. * and SetCommonToAllBodyStyles() for more information.
  295. *
  296. * @param aEnable = true marks all common pins for editing mode. False
  297. * clears the editing mode.
  298. * @param aEditPinByPin == true enables the edit pin by pin mode.
  299. * aEditPinByPin == false enables the pin edit coupling between pins at the same location
  300. * if aEnable == false, aEditPinByPin is not used
  301. */
  302. void EnableEditMode( bool aEnable, bool aEditPinByPin = false );
  303. /**
  304. * Return the visibility status of the draw object.
  305. *
  306. * @return True if draw object is visible otherwise false.
  307. */
  308. bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
  309. /**
  310. * Return whether this pin forms an implicit power connection: i.e., is hidden
  311. * and of type POWER_IN.
  312. */
  313. bool IsPowerConnection() const {
  314. return (
  315. ( !IsVisible() && GetType() == PIN_POWER_IN )
  316. ||
  317. ( (LIB_PART*)GetParent()->IsPower() && GetType() == PIN_POWER_IN )
  318. ) ; }
  319. int GetPenSize() const override;
  320. /**
  321. * Draw the pin symbol without text.
  322. * If \a aColor != 0, draw with \a aColor, else with the normal pin color.
  323. */
  324. void DrawPinSymbol( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
  325. int aOrientation, GR_DRAWMODE aDrawMode,
  326. COLOR4D aColor = COLOR4D::UNSPECIFIED,
  327. bool aDrawDangling = true,
  328. bool aOnlyTarget = false );
  329. /**
  330. * Put the pin number and pin text info, given the pin line coordinates.
  331. * The line must be vertical or horizontal.
  332. * If DrawPinName == false the pin name is not printed.
  333. * If DrawPinNum = false the pin number is not printed.
  334. * If TextInside then the text is been put inside,otherwise all is drawn outside.
  335. * Pin Name: substring between '~' is negated
  336. * DrawMode = GR_OR, XOR ...
  337. */
  338. void DrawPinTexts( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
  339. int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName,
  340. COLOR4D aColor, GR_DRAWMODE aDrawMode );
  341. /**
  342. * Draw the electrical type text of the pin (only for the footprint editor)
  343. * aDrawMode = GR_OR, XOR ...
  344. */
  345. void DrawPinElectricalTypeName( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
  346. int aOrientation, COLOR4D aColor, GR_DRAWMODE aDrawMode );
  347. /**
  348. * Plot the pin number and pin text info, given the pin line coordinates.
  349. * Same as DrawPinTexts((), but output is the plotter
  350. * The line must be vertical or horizontal.
  351. * If TextInside then the text is been put inside (moving from x1, y1 in
  352. * the opposite direction to x2,y2), otherwise all is drawn outside.
  353. */
  354. void PlotPinTexts( PLOTTER *aPlotter,
  355. wxPoint& aPosition,
  356. int aOrientation,
  357. int aTextInside,
  358. bool aDrawPinNum,
  359. bool aDrawPinName,
  360. int aWidth );
  361. void PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation );
  362. /**
  363. * Get a list of pin orientation names.
  364. *
  365. * @return List of valid pin orientation names.
  366. */
  367. static wxArrayString GetOrientationNames();
  368. /**
  369. * Get a list of pin orientation bitmaps for menus and dialogs.
  370. *
  371. * @return List of valid pin orientation bitmaps symbols in .xpm format
  372. */
  373. static const BITMAP_DEF* GetOrientationSymbols();
  374. /**
  375. * Get the orientation code by index used to set the pin orientation.
  376. *
  377. * @param aIndex - The index of the orientation code to look up.
  378. * @return Orientation code if index is valid. Returns right
  379. * orientation on index error.
  380. */
  381. static int GetOrientationCode( int aIndex );
  382. /**
  383. * Get the index of the orientation code.
  384. *
  385. * @param aCode - The orientation code to look up.
  386. * @return The index of the orientation code if found. Otherwise,
  387. * return wxNOT_FOUND.
  388. */
  389. static int GetOrientationIndex( int aCode );
  390. void SetOffset( const wxPoint& aOffset ) override;
  391. bool Inside( EDA_RECT& aRect ) const override;
  392. void Move( const wxPoint& aPosition ) override;
  393. wxPoint GetPosition() const override { return m_position; }
  394. /**
  395. * move this and all linked pins to the new position
  396. * used in pin editing.
  397. * use SetPinPosition to set the position of this only
  398. * @param aPosition is the new position of this and linked pins
  399. */
  400. void SetPinPosition( wxPoint aPosition );
  401. void MirrorHorizontal( const wxPoint& aCenter ) override;
  402. void MirrorVertical( const wxPoint& aCenter ) override;
  403. void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
  404. void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
  405. const TRANSFORM& aTransform ) override;
  406. int GetWidth() const override { return m_width; }
  407. void SetWidth( int aWidth ) override;
  408. BITMAP_DEF GetMenuImage() const override;
  409. wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
  410. EDA_ITEM* Clone() const override;
  411. void CalcEdit( const wxPoint& aPosition ) override;
  412. private:
  413. /**
  414. * Build the pin basic info to display in message panel.
  415. * they are pin info without the actual pin position, which
  416. * is not known in schematic without knowing the parent component
  417. */
  418. void getMsgPanelInfoBase( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList );
  419. /**
  420. * @copydoc LIB_ITEM::compare()
  421. *
  422. * The pin specific sort order is as follows:
  423. * - Pin number.
  424. * - Pin name, case insensitive compare.
  425. * - Pin horizontal (X) position.
  426. * - Pin vertical (Y) position.
  427. */
  428. int compare( const LIB_ITEM& aOther ) const override;
  429. };
  430. #endif // CLASS_PIN_H