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.

1303 lines
44 KiB

* 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
* 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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 1992-2022 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. #include <base_units.h>
  26. #include <pgm_base.h>
  27. #include <sch_draw_panel.h>
  28. #include <sch_edit_frame.h>
  29. #include <symbol_edit_frame.h>
  30. #include <lib_pin.h>
  31. #include <settings/settings_manager.h>
  32. #include <symbol_editor/symbol_editor_settings.h>
  33. #include <trigo.h>
  34. #include <string_utils.h>
  35. #include "sch_painter.h"
  36. // small margin in internal units between the pin text and the pin line
  37. #define PIN_TEXT_MARGIN 4
  38. const wxString LIB_PIN::GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType )
  39. {
  40. // These strings are the canonical name of the electrictal type
  41. // Not translated, no space in name, only ASCII chars.
  42. // to use when the string name must be known and well defined
  43. // must have same order than enum ELECTRICAL_PINTYPE (see lib_pin.h)
  44. static const wxChar* msgPinElectricType[] =
  45. {
  46. wxT( "input" ),
  47. wxT( "output" ),
  48. wxT( "bidirectional" ),
  49. wxT( "tri_state" ),
  50. wxT( "passive" ),
  51. wxT( "free" ),
  52. wxT( "unspecified" ),
  53. wxT( "power_in" ),
  54. wxT( "power_out" ),
  55. wxT( "open_collector" ),
  56. wxT( "open_emitter" ),
  57. wxT( "no_connect" )
  58. };
  59. return msgPinElectricType[static_cast<int>( aType )];
  60. }
  61. /// Utility for getting the size of the 'internal' pin decorators (as a radius)
  62. // i.e. the clock symbols (falling clock is actually external but is of
  63. // the same kind)
  64. static int internalPinDecoSize( const RENDER_SETTINGS* aSettings, const LIB_PIN &aPin )
  65. {
  66. const KIGFX::SCH_RENDER_SETTINGS* settings = static_cast<const KIGFX::SCH_RENDER_SETTINGS*>( aSettings );
  67. if( settings && settings->m_PinSymbolSize )
  68. return settings->m_PinSymbolSize;
  69. return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
  70. }
  71. /// Utility for getting the size of the 'external' pin decorators (as a radius)
  72. // i.e. the negation circle, the polarity 'slopes' and the nonlogic
  73. // marker
  74. static int externalPinDecoSize( const RENDER_SETTINGS* aSettings, const LIB_PIN &aPin )
  75. {
  76. const KIGFX::SCH_RENDER_SETTINGS* settings = static_cast<const KIGFX::SCH_RENDER_SETTINGS*>( aSettings );
  77. if( settings && settings->m_PinSymbolSize )
  78. return settings->m_PinSymbolSize;
  79. return aPin.GetNumberTextSize() / 2;
  80. }
  81. LIB_PIN::LIB_PIN( LIB_SYMBOL* aParent ) :
  82. LIB_ITEM( LIB_PIN_T, aParent ),
  83. m_orientation( PIN_RIGHT ),
  84. m_shape( GRAPHIC_PINSHAPE::LINE ),
  85. m_type( ELECTRICAL_PINTYPE::PT_UNSPECIFIED ),
  86. m_attributes( 0 )
  87. {
  88. // Use the application settings for pin sizes if exists.
  89. // pgm can be nullptr when running a shared lib from a script, not from a kicad appl
  90. PGM_BASE* pgm = PgmOrNull();
  91. if( pgm )
  92. {
  93. auto* settings = pgm->GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
  94. m_length = Mils2iu( settings->m_Defaults.pin_length );
  95. m_numTextSize = Mils2iu( settings->m_Defaults.pin_num_size );
  96. m_nameTextSize = Mils2iu( settings->m_Defaults.pin_name_size );
  97. }
  98. else // Use hardcoded eeschema defaults: symbol_editor settings are not existing.
  99. {
  100. m_length = Mils2iu( DEFAULT_PIN_LENGTH );
  101. m_numTextSize = Mils2iu( DEFAULT_PINNUM_SIZE );
  102. m_nameTextSize = Mils2iu( DEFAULT_PINNAME_SIZE );
  103. }
  104. }
  105. LIB_PIN::LIB_PIN( LIB_SYMBOL* aParent, const wxString& aName, const wxString& aNumber,
  106. int aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength, int aNameTextSize,
  107. int aNumTextSize, int aConvert, const VECTOR2I& aPos, int aUnit ) :
  108. LIB_ITEM( LIB_PIN_T, aParent ),
  109. m_position( aPos ),
  110. m_length( aLength ),
  111. m_orientation( aOrientation ),
  112. m_shape( GRAPHIC_PINSHAPE::LINE ),
  113. m_type( aPinType ),
  114. m_attributes( 0 ),
  115. m_numTextSize( aNumTextSize ),
  116. m_nameTextSize( aNameTextSize )
  117. {
  118. SetName( aName );
  119. SetNumber( aNumber );
  120. SetUnit( aUnit );
  121. SetConvert( aConvert );
  122. }
  123. bool LIB_PIN::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
  124. {
  125. BOX2I rect = GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
  126. return rect.Inflate( aAccuracy ).Contains( aPosition );
  127. }
  128. bool LIB_PIN::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
  129. {
  130. if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
  131. return false;
  132. BOX2I sel = aRect;
  133. if ( aAccuracy )
  134. sel.Inflate( aAccuracy );
  135. if( aContained )
  136. return sel.Contains( GetBoundingBox( false, false, false ) );
  137. return sel.Intersects( GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ) );
  138. }
  139. int LIB_PIN::GetPenWidth() const
  140. {
  141. return 0;
  142. }
  143. KIFONT::FONT* LIB_PIN::GetDrawFont() const
  144. {
  145. return KIFONT::FONT::GetFont( GetDefaultFont(), false, false );
  146. }
  147. wxString LIB_PIN::GetShownName() const
  148. {
  149. if( m_name == "~" )
  150. return wxEmptyString;
  151. else
  152. return m_name;
  153. }
  154. VECTOR2I LIB_PIN::GetPinRoot() const
  155. {
  156. switch( m_orientation )
  157. {
  158. default:
  159. case PIN_RIGHT: return VECTOR2I( m_position.x + m_length, -( m_position.y ) );
  160. case PIN_LEFT: return VECTOR2I( m_position.x - m_length, -( m_position.y ) );
  161. case PIN_UP: return VECTOR2I( m_position.x, -( m_position.y + m_length ) );
  162. case PIN_DOWN: return VECTOR2I( m_position.x, -( m_position.y - m_length ) );
  163. }
  164. }
  165. void LIB_PIN::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
  166. const TRANSFORM& aTransform )
  167. {
  168. LIB_SYMBOL_OPTIONS* opts = (LIB_SYMBOL_OPTIONS*) aData;
  169. bool drawHiddenFields = opts ? opts->draw_hidden_fields : false;
  170. bool showPinType = opts ? opts->show_elec_type : false;
  171. bool show_connect_point = opts ? opts->show_connect_point : false;
  172. LIB_SYMBOL* part = GetParent();
  173. wxCHECK( part && opts, /* void */ );
  174. /* Calculate pin orient taking in account the symbol orientation. */
  175. int orient = PinDrawOrient( aTransform );
  176. /* Calculate the pin position */
  177. VECTOR2I pos1 = aTransform.TransformCoordinate( m_position ) + aOffset;
  178. if( IsVisible() || drawHiddenFields )
  179. {
  180. printPinSymbol( aSettings, pos1, orient );
  181. printPinTexts( aSettings, pos1, orient, part->GetPinNameOffset(),
  182. opts->force_draw_pin_text || part->ShowPinNumbers(),
  183. opts->force_draw_pin_text || part->ShowPinNames() );
  184. if( showPinType )
  185. printPinElectricalTypeName( aSettings, pos1, orient );
  186. if( show_connect_point
  187. && m_type != ELECTRICAL_PINTYPE::PT_NC
  188. && m_type != ELECTRICAL_PINTYPE::PT_NIC )
  189. {
  190. wxDC* DC = aSettings->GetPrintDC();
  191. COLOR4D color = aSettings->GetLayerColor( IsVisible() ? LAYER_PIN : LAYER_HIDDEN );
  192. GRCircle( DC, pos1, TARGET_PIN_RADIUS, 0, color );
  193. }
  194. }
  195. }
  196. void LIB_PIN::printPinSymbol( const RENDER_SETTINGS* aSettings, const VECTOR2I& aPos, int aOrient )
  197. {
  198. wxDC* DC = aSettings->GetPrintDC();
  199. int MapX1, MapY1, x1, y1;
  200. int width = GetEffectivePenWidth( aSettings );
  201. int posX = aPos.x, posY = aPos.y, len = m_length;
  202. COLOR4D color = aSettings->GetLayerColor( IsVisible() ? LAYER_PIN : LAYER_HIDDEN );
  203. MapX1 = MapY1 = 0;
  204. x1 = posX;
  205. y1 = posY;
  206. switch( aOrient )
  207. {
  208. case PIN_UP: y1 = posY - len; MapY1 = 1; break;
  209. case PIN_DOWN: y1 = posY + len; MapY1 = -1; break;
  210. case PIN_LEFT: x1 = posX - len; MapX1 = 1; break;
  211. case PIN_RIGHT: x1 = posX + len; MapX1 = -1; break;
  212. }
  213. if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK )
  214. {
  215. const int radius = externalPinDecoSize( aSettings, *this );
  216. GRCircle( DC, VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius, width, color );
  217. GRMoveTo( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 );
  218. GRLineTo( DC, posX, posY, width, color );
  219. }
  220. else
  221. {
  222. GRMoveTo( x1, y1 );
  223. GRLineTo( DC, posX, posY, width, color );
  224. }
  225. // Draw the clock shape (>)inside the symbol
  226. if( m_shape == GRAPHIC_PINSHAPE::CLOCK
  227. || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK
  228. || m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK
  229. || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
  230. {
  231. const int clock_size = internalPinDecoSize( aSettings, *this );
  232. if( MapY1 == 0 ) /* MapX1 = +- 1 */
  233. {
  234. GRMoveTo( x1, y1 + clock_size );
  235. GRLineTo( DC, x1 - MapX1 * clock_size * 2, y1, width, color );
  236. GRLineTo( DC, x1, y1 - clock_size, width, color );
  237. }
  238. else /* MapX1 = 0 */
  239. {
  240. GRMoveTo( x1 + clock_size, y1 );
  241. GRLineTo( DC, x1, y1 - MapY1 * clock_size * 2, width, color );
  242. GRLineTo( DC, x1 - clock_size, y1, width, color );
  243. }
  244. }
  245. // Draw the active low (or H to L active transition)
  246. if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW
  247. || m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK
  248. || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
  249. {
  250. const int deco_size = externalPinDecoSize( aSettings, *this );
  251. if( MapY1 == 0 ) /* MapX1 = +- 1 */
  252. {
  253. GRMoveTo( x1 + MapX1 * deco_size * 2, y1 );
  254. GRLineTo( DC, x1 + MapX1 * deco_size * 2, y1 - deco_size * 2, width, color );
  255. GRLineTo( DC, x1, y1, width, color );
  256. }
  257. else /* MapX1 = 0 */
  258. {
  259. GRMoveTo( x1, y1 + MapY1 * deco_size * 2 );
  260. GRLineTo( DC, x1 - deco_size * 2, y1 + MapY1 * deco_size * 2, width, color );
  261. GRLineTo( DC, x1, y1, width, color );
  262. }
  263. }
  264. if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
  265. {
  266. const int deco_size = externalPinDecoSize( aSettings, *this );
  267. if( MapY1 == 0 ) /* MapX1 = +- 1 */
  268. {
  269. GRMoveTo( x1, y1 - deco_size * 2 );
  270. GRLineTo( DC, x1 + MapX1 * deco_size * 2, y1, width, color );
  271. }
  272. else /* MapX1 = 0 */
  273. {
  274. GRMoveTo( x1 - deco_size * 2, y1 );
  275. GRLineTo( DC, x1, y1 + MapY1 * deco_size * 2, width, color );
  276. }
  277. }
  278. else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
  279. {
  280. const int deco_size = externalPinDecoSize( aSettings, *this );
  281. GRMoveTo( x1 - (MapX1 + MapY1) * deco_size, y1 - (MapY1 - MapX1) * deco_size );
  282. GRLineTo( DC, x1 + (MapX1 + MapY1) * deco_size, y1 + ( MapY1 - MapX1 ) * deco_size, width,
  283. color );
  284. GRMoveTo( x1 - (MapX1 - MapY1) * deco_size, y1 - (MapY1 + MapX1) * deco_size );
  285. GRLineTo( DC, x1 + (MapX1 - MapY1) * deco_size, y1 + ( MapY1 + MapX1 ) * deco_size, width,
  286. color );
  287. }
  288. if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
  289. {
  290. const int deco_size = TARGET_PIN_RADIUS;
  291. GRLine( DC, posX - deco_size, posY - deco_size, posX + deco_size, posY + deco_size, width,
  292. color );
  293. GRLine( DC, posX + deco_size, posY - deco_size, posX - deco_size, posY + deco_size, width,
  294. color );
  295. }
  296. }
  297. void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos, int aPinOrient,
  298. int aTextInside, bool aDrawPinNum, bool aDrawPinName )
  299. {
  300. if( !aDrawPinName && !aDrawPinNum )
  301. return;
  302. int x, y;
  303. wxDC* DC = aSettings->GetPrintDC();
  304. KIFONT::FONT* font = GetDrawFont();
  305. wxSize pinNameSize( m_nameTextSize, m_nameTextSize );
  306. wxSize pinNumSize( m_numTextSize, m_numTextSize );
  307. int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, true ),
  308. aSettings->GetDefaultPenWidth() );
  309. int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, true ),
  310. aSettings->GetDefaultPenWidth() );
  311. int name_offset = Mils2iu( PIN_TEXT_MARGIN ) + namePenWidth;
  312. int num_offset = Mils2iu( PIN_TEXT_MARGIN ) + numPenWidth;
  313. /* Get the num and name colors */
  314. COLOR4D NameColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNAM : LAYER_HIDDEN );
  315. COLOR4D NumColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNUM : LAYER_HIDDEN );
  316. int x1 = aPinPos.x;
  317. int y1 = aPinPos.y;
  318. switch( aPinOrient )
  319. {
  320. case PIN_UP: y1 -= m_length; break;
  321. case PIN_DOWN: y1 += m_length; break;
  322. case PIN_LEFT: x1 -= m_length; break;
  323. case PIN_RIGHT: x1 += m_length; break;
  324. }
  325. wxString name = GetShownName();
  326. wxString number = GetShownNumber();
  327. if( name.IsEmpty() )
  328. aDrawPinName = false;
  329. if( number.IsEmpty() )
  330. aDrawPinNum = false;
  331. if( aTextInside ) // Draw the text inside, but the pin numbers outside.
  332. {
  333. if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
  334. {
  335. // It is an horizontal line
  336. if( aDrawPinName )
  337. {
  338. if( aPinOrient == PIN_RIGHT )
  339. {
  340. x = x1 + aTextInside;
  341. GRPrintText( DC, VECTOR2I( x, y1 ), NameColor, name, ANGLE_HORIZONTAL,
  342. pinNameSize, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER,
  343. namePenWidth, false, false, font );
  344. }
  345. else // Orient == PIN_LEFT
  346. {
  347. x = x1 - aTextInside;
  348. GRPrintText( DC, VECTOR2I( x, y1 ), NameColor, name, ANGLE_HORIZONTAL,
  349. pinNameSize, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER,
  350. namePenWidth, false, false, font );
  351. }
  352. }
  353. if( aDrawPinNum )
  354. {
  355. GRPrintText( DC, VECTOR2I(( x1 + aPinPos.x) / 2, y1 - num_offset ), NumColor,
  356. number, ANGLE_HORIZONTAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER,
  357. GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font );
  358. }
  359. }
  360. else /* Its a vertical line. */
  361. {
  362. // Text is drawn from bottom to top (i.e. to negative value for Y axis)
  363. if( aPinOrient == PIN_DOWN )
  364. {
  365. y = y1 + aTextInside;
  366. if( aDrawPinName )
  367. {
  368. GRPrintText( DC, VECTOR2I( x1, y ), NameColor, name, ANGLE_VERTICAL,
  369. pinNameSize, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER,
  370. namePenWidth, false, false, font );
  371. }
  372. if( aDrawPinNum )
  373. {
  374. GRPrintText( DC, VECTOR2I( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor,
  375. number, ANGLE_VERTICAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER,
  376. GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font );
  377. }
  378. }
  379. else /* PIN_UP */
  380. {
  381. y = y1 - aTextInside;
  382. if( aDrawPinName )
  383. {
  384. GRPrintText( DC, VECTOR2I( x1, y ), NameColor, name, ANGLE_VERTICAL,
  385. pinNameSize, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER,
  386. namePenWidth, false, false, font );
  387. }
  388. if( aDrawPinNum )
  389. {
  390. GRPrintText( DC, VECTOR2I( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor,
  391. number, ANGLE_VERTICAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER,
  392. GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font );
  393. }
  394. }
  395. }
  396. }
  397. else /**** Draw num & text pin outside ****/
  398. {
  399. if( ( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
  400. {
  401. /* Its an horizontal line. */
  402. if( aDrawPinName )
  403. {
  404. x = ( x1 + aPinPos.x) / 2;
  405. GRPrintText( DC, VECTOR2I( x, y1 - name_offset ), NameColor, name, ANGLE_HORIZONTAL,
  406. pinNameSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM,
  407. namePenWidth, false, false, font );
  408. }
  409. if( aDrawPinNum )
  410. {
  411. x = ( x1 + aPinPos.x) / 2;
  412. GRPrintText( DC, VECTOR2I( x, y1 + num_offset ), NumColor, number, ANGLE_HORIZONTAL,
  413. pinNumSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP,
  414. numPenWidth, false, false, font );
  415. }
  416. }
  417. else /* Its a vertical line. */
  418. {
  419. if( aDrawPinName )
  420. {
  421. y = ( y1 + aPinPos.y) / 2;
  422. GRPrintText( DC, VECTOR2I( x1 - name_offset, y ), NameColor, name, ANGLE_VERTICAL,
  423. pinNameSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM,
  424. namePenWidth, false, false, font );
  425. }
  426. if( aDrawPinNum )
  427. {
  428. GRPrintText( DC, VECTOR2I( x1 + num_offset, ( y1 + aPinPos.y) / 2 ), NumColor,
  429. number, ANGLE_VERTICAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER,
  430. GR_TEXT_V_ALIGN_TOP, numPenWidth, false, false, font );
  431. }
  432. }
  433. }
  434. }
  435. void LIB_PIN::printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECTOR2I& aPosition,
  436. int aOrientation )
  437. {
  438. wxDC* DC = aSettings->GetPrintDC();
  439. wxString typeName = GetElectricalTypeName();
  440. // Use a reasonable (small) size to draw the text
  441. int textSize = ( m_nameTextSize * 3 ) / 4;
  442. #define ETXT_MAX_SIZE Millimeter2iu( 0.7 )
  443. if( textSize > ETXT_MAX_SIZE )
  444. textSize = ETXT_MAX_SIZE;
  445. // Use a reasonable pen size to draw the text
  446. int pensize = textSize/6;
  447. // Get a suitable color
  448. COLOR4D color = aSettings->GetLayerColor( IsVisible() ? LAYER_PRIVATE_NOTES : LAYER_HIDDEN );
  449. VECTOR2I txtpos = aPosition;
  450. int offset = Millimeter2iu( 0.4 );
  451. GR_TEXT_H_ALIGN_T hjustify = GR_TEXT_H_ALIGN_LEFT;
  452. EDA_ANGLE orient = ANGLE_HORIZONTAL;
  453. switch( aOrientation )
  454. {
  455. case PIN_UP:
  456. txtpos.y += offset;
  457. orient = ANGLE_VERTICAL;
  458. hjustify = GR_TEXT_H_ALIGN_RIGHT;
  459. break;
  460. case PIN_DOWN:
  461. txtpos.y -= offset;
  462. orient = ANGLE_VERTICAL;
  463. break;
  464. case PIN_LEFT:
  465. txtpos.x += offset;
  466. break;
  467. case PIN_RIGHT:
  468. txtpos.x -= offset;
  469. hjustify = GR_TEXT_H_ALIGN_RIGHT;
  470. break;
  471. }
  472. GRPrintText( DC, txtpos, color, typeName, orient, wxSize( textSize, textSize ), hjustify,
  473. GR_TEXT_V_ALIGN_CENTER, pensize, false, false, GetDrawFont() );
  474. }
  475. void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const VECTOR2I& aPosition, int aOrientation ) const
  476. {
  477. int MapX1, MapY1, x1, y1;
  478. COLOR4D color = aPlotter->RenderSettings()->GetLayerColor( LAYER_PIN );
  479. int penWidth = GetEffectivePenWidth( aPlotter->RenderSettings() );
  480. aPlotter->SetColor( color );
  481. aPlotter->SetCurrentLineWidth( penWidth );
  482. MapX1 = MapY1 = 0;
  483. x1 = aPosition.x; y1 = aPosition.y;
  484. switch( aOrientation )
  485. {
  486. case PIN_UP: y1 = aPosition.y - m_length; MapY1 = 1; break;
  487. case PIN_DOWN: y1 = aPosition.y + m_length; MapY1 = -1; break;
  488. case PIN_LEFT: x1 = aPosition.x - m_length; MapX1 = 1; break;
  489. case PIN_RIGHT: x1 = aPosition.x + m_length; MapX1 = -1; break;
  490. }
  491. if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK )
  492. {
  493. const int radius = externalPinDecoSize( aPlotter->RenderSettings(), *this );
  494. aPlotter->Circle( VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius * 2,
  495. FILL_T::NO_FILL, penWidth );
  496. aPlotter->MoveTo( VECTOR2I( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ) );
  497. aPlotter->FinishTo( aPosition );
  498. }
  499. else if( m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK )
  500. {
  501. const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
  502. if( MapY1 == 0 ) /* MapX1 = +- 1 */
  503. {
  504. aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
  505. aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
  506. aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
  507. }
  508. else /* MapX1 = 0 */
  509. {
  510. aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
  511. aPlotter->LineTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
  512. aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
  513. }
  514. aPlotter->MoveTo( VECTOR2I( MapX1 * deco_size * 2 + x1, MapY1 * deco_size * 2 + y1 ) );
  515. aPlotter->FinishTo( aPosition );
  516. }
  517. else
  518. {
  519. aPlotter->MoveTo( VECTOR2I( x1, y1 ) );
  520. aPlotter->FinishTo( aPosition );
  521. }
  522. if( m_shape == GRAPHIC_PINSHAPE::CLOCK
  523. || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK
  524. || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
  525. {
  526. const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
  527. if( MapY1 == 0 ) /* MapX1 = +- 1 */
  528. {
  529. aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
  530. aPlotter->LineTo( VECTOR2I( x1 - MapX1 * deco_size * 2, y1 ) );
  531. aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
  532. }
  533. else /* MapX1 = 0 */
  534. {
  535. aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
  536. aPlotter->LineTo( VECTOR2I( x1, y1 - MapY1 * deco_size * 2 ) );
  537. aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
  538. }
  539. }
  540. if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW
  541. || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
  542. {
  543. const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
  544. if( MapY1 == 0 ) /* MapX1 = +- 1 */
  545. {
  546. aPlotter->MoveTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
  547. aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 - deco_size * 2 ) );
  548. aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
  549. }
  550. else /* MapX1 = 0 */
  551. {
  552. aPlotter->MoveTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
  553. aPlotter->LineTo( VECTOR2I( x1 - deco_size * 2, y1 + MapY1 * deco_size * 2 ) );
  554. aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
  555. }
  556. }
  557. if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
  558. {
  559. const int symbol_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
  560. if( MapY1 == 0 ) /* MapX1 = +- 1 */
  561. {
  562. aPlotter->MoveTo( VECTOR2I( x1, y1 - symbol_size * 2 ) );
  563. aPlotter->FinishTo( VECTOR2I( x1 + MapX1 * symbol_size * 2, y1 ) );
  564. }
  565. else /* MapX1 = 0 */
  566. {
  567. aPlotter->MoveTo( VECTOR2I( x1 - symbol_size * 2, y1 ) );
  568. aPlotter->FinishTo( VECTOR2I( x1, y1 + MapY1 * symbol_size * 2 ) );
  569. }
  570. }
  571. else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
  572. {
  573. const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
  574. aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 + MapY1 ) * deco_size,
  575. y1 - ( MapY1 - MapX1 ) * deco_size ) );
  576. aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 + MapY1 ) * deco_size,
  577. y1 + ( MapY1 - MapX1 ) * deco_size ) );
  578. aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 - MapY1 ) * deco_size,
  579. y1 - ( MapY1 + MapX1 ) * deco_size ) );
  580. aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 - MapY1 ) * deco_size,
  581. y1 + ( MapY1 + MapX1 ) * deco_size ) );
  582. }
  583. if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
  584. {
  585. const int deco_size = TARGET_PIN_RADIUS;
  586. const int ex1 = aPosition.x;
  587. const int ey1 = aPosition.y;
  588. aPlotter->MoveTo( VECTOR2I( ex1 - deco_size, ey1 - deco_size ) );
  589. aPlotter->FinishTo( VECTOR2I( ex1 + deco_size, ey1 + deco_size ) );
  590. aPlotter->MoveTo( VECTOR2I( ex1 + deco_size, ey1 - deco_size ) );
  591. aPlotter->FinishTo( VECTOR2I( ex1 - deco_size, ey1 + deco_size ) );
  592. }
  593. }
  594. void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, const VECTOR2I& aPinPos, int aPinOrient,
  595. int aTextInside, bool aDrawPinNum, bool aDrawPinName ) const
  596. {
  597. wxString name = GetShownName();
  598. wxString number = GetShownNumber();
  599. if( name.IsEmpty() )
  600. aDrawPinName = false;
  601. if( number.IsEmpty() )
  602. aDrawPinNum = false;
  603. if( !aDrawPinNum && !aDrawPinName )
  604. return;
  605. int x, y;
  606. int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, true ),
  607. aPlotter->RenderSettings()->GetDefaultPenWidth() );
  608. int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, true ),
  609. aPlotter->RenderSettings()->GetDefaultPenWidth() );
  610. int name_offset = Mils2iu( PIN_TEXT_MARGIN ) + namePenWidth;
  611. int num_offset = Mils2iu( PIN_TEXT_MARGIN ) + numPenWidth;
  612. /* Get the num and name colors */
  613. COLOR4D nameColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_PINNAM );
  614. COLOR4D numColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_PINNUM );
  615. int x1 = aPinPos.x;
  616. int y1 = aPinPos.y;
  617. switch( aPinOrient )
  618. {
  619. case PIN_UP: y1 -= m_length; break;
  620. case PIN_DOWN: y1 += m_length; break;
  621. case PIN_LEFT: x1 -= m_length; break;
  622. case PIN_RIGHT: x1 += m_length; break;
  623. }
  624. auto plotText =
  625. [&]( int px, int py, const COLOR4D& color, const wxString& text, const EDA_ANGLE& angle,
  626. int size, GR_TEXT_H_ALIGN_T hJustify, GR_TEXT_V_ALIGN_T vJustify, int penWidth )
  627. {
  628. aPlotter->Text( VECTOR2I( px, py ), color, text, angle, VECTOR2I( size, size ),
  629. hJustify, vJustify, penWidth, false, false, false, GetDrawFont() );
  630. };
  631. /* Draw the text inside, but the pin numbers outside. */
  632. if( aTextInside )
  633. {
  634. if( ( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) ) /* Its an horizontal line. */
  635. {
  636. if( aDrawPinName )
  637. {
  638. GR_TEXT_H_ALIGN_T hjustify;
  639. if( aPinOrient == PIN_RIGHT )
  640. {
  641. x = x1 + aTextInside;
  642. hjustify = GR_TEXT_H_ALIGN_LEFT;
  643. }
  644. else // orient == PIN_LEFT
  645. {
  646. x = x1 - aTextInside;
  647. hjustify = GR_TEXT_H_ALIGN_RIGHT;
  648. }
  649. plotText( x, y1, nameColor, name, ANGLE_HORIZONTAL, m_nameTextSize, hjustify,
  650. GR_TEXT_V_ALIGN_CENTER, namePenWidth );
  651. }
  652. if( aDrawPinNum )
  653. {
  654. plotText( ( x1 + aPinPos.x) / 2, y1 - num_offset, numColor, number,
  655. ANGLE_HORIZONTAL, m_numTextSize, GR_TEXT_H_ALIGN_CENTER,
  656. GR_TEXT_V_ALIGN_BOTTOM, numPenWidth );
  657. }
  658. }
  659. else /* Its a vertical line. */
  660. {
  661. if( aPinOrient == PIN_DOWN )
  662. {
  663. y = y1 + aTextInside;
  664. if( aDrawPinName )
  665. {
  666. plotText( x1, y, nameColor, name, ANGLE_VERTICAL, m_nameTextSize,
  667. GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER, namePenWidth );
  668. }
  669. if( aDrawPinNum )
  670. {
  671. plotText( x1 - num_offset, ( y1 + aPinPos.y) / 2, numColor, number,
  672. ANGLE_VERTICAL, m_numTextSize, GR_TEXT_H_ALIGN_CENTER,
  673. GR_TEXT_V_ALIGN_BOTTOM, numPenWidth );
  674. }
  675. }
  676. else /* PIN_UP */
  677. {
  678. y = y1 - aTextInside;
  679. if( aDrawPinName )
  680. {
  681. plotText( x1, y, nameColor, name, ANGLE_VERTICAL, m_nameTextSize,
  682. GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER, namePenWidth );
  683. }
  684. if( aDrawPinNum )
  685. {
  686. plotText( x1 - num_offset, ( y1 + aPinPos.y) / 2, numColor, number,
  687. ANGLE_VERTICAL, m_numTextSize, GR_TEXT_H_ALIGN_CENTER,
  688. GR_TEXT_V_ALIGN_BOTTOM, numPenWidth );
  689. }
  690. }
  691. }
  692. }
  693. else /* Draw num & text pin outside */
  694. {
  695. if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
  696. {
  697. /* Its an horizontal line. */
  698. if( aDrawPinName )
  699. {
  700. x = ( x1 + aPinPos.x) / 2;
  701. plotText( x, y1 - name_offset, nameColor, name, ANGLE_HORIZONTAL, m_nameTextSize,
  702. GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM, namePenWidth );
  703. }
  704. if( aDrawPinNum )
  705. {
  706. x = ( x1 + aPinPos.x ) / 2;
  707. plotText( x, y1 + num_offset, numColor, number, ANGLE_HORIZONTAL, m_numTextSize,
  708. GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP, numPenWidth );
  709. }
  710. }
  711. else /* Its a vertical line. */
  712. {
  713. if( aDrawPinName )
  714. {
  715. y = ( y1 + aPinPos.y ) / 2;
  716. plotText( x1 - name_offset, y, nameColor, name, ANGLE_VERTICAL, m_nameTextSize,
  717. GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM, namePenWidth );
  718. }
  719. if( aDrawPinNum )
  720. {
  721. plotText( x1 + num_offset, ( y1 + aPinPos.y ) / 2, numColor, number, ANGLE_VERTICAL,
  722. m_numTextSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP, numPenWidth );
  723. }
  724. }
  725. }
  726. }
  727. int LIB_PIN::PinDrawOrient( const TRANSFORM& aTransform ) const
  728. {
  729. int orient;
  730. VECTOR2I end; // position of pin end starting at 0,0 according to its orientation, length = 1
  731. switch( m_orientation )
  732. {
  733. case PIN_UP: end.y = 1; break;
  734. case PIN_DOWN: end.y = -1; break;
  735. case PIN_LEFT: end.x = -1; break;
  736. case PIN_RIGHT: end.x = 1; break;
  737. }
  738. // = pos of end point, according to the symbol orientation.
  739. end = aTransform.TransformCoordinate( end );
  740. orient = PIN_UP;
  741. if( end.x == 0 )
  742. {
  743. if( end.y > 0 )
  744. orient = PIN_DOWN;
  745. }
  746. else
  747. {
  748. orient = PIN_RIGHT;
  749. if( end.x < 0 )
  750. orient = PIN_LEFT;
  751. }
  752. return orient;
  753. }
  754. EDA_ITEM* LIB_PIN::Clone() const
  755. {
  756. return new LIB_PIN( *this );
  757. }
  758. int LIB_PIN::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
  759. {
  760. wxASSERT( aOther.Type() == LIB_PIN_T );
  761. int retv = LIB_ITEM::compare( aOther, aCompareFlags );
  762. if( retv )
  763. return retv;
  764. const LIB_PIN* tmp = (LIB_PIN*) &aOther;
  765. // When comparing units, we do not compare the part numbers. If everything else is
  766. // identical, then we can just renumber the parts for the inherited symbol.
  767. if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_number != tmp->m_number )
  768. return m_number.Cmp( tmp->m_number );
  769. int result = m_name.CmpNoCase( tmp->m_name );
  770. if( result )
  771. return result;
  772. if( m_position.x != tmp->m_position.x )
  773. return m_position.x - tmp->m_position.x;
  774. if( m_position.y != tmp->m_position.y )
  775. return m_position.y - tmp->m_position.y;
  776. if( m_length != tmp->m_length )
  777. return m_length - tmp->m_length;
  778. if( m_orientation != tmp->m_orientation )
  779. return m_orientation - tmp->m_orientation;
  780. if( m_shape != tmp->m_shape )
  781. return static_cast<int>( m_shape ) - static_cast<int>( tmp->m_shape );
  782. if( m_type != tmp->m_type )
  783. return static_cast<int>( m_type ) - static_cast<int>( tmp->m_type );
  784. if( m_attributes != tmp->m_attributes )
  785. return m_attributes - tmp->m_attributes;
  786. if( m_numTextSize != tmp->m_numTextSize )
  787. return m_numTextSize - tmp->m_numTextSize;
  788. if( m_nameTextSize != tmp->m_nameTextSize )
  789. return m_nameTextSize - tmp->m_nameTextSize;
  790. if( m_alternates.size() != tmp->m_alternates.size() )
  791. return m_alternates.size() - tmp->m_alternates.size();
  792. auto lhsItem = m_alternates.begin();
  793. auto rhsItem = tmp->m_alternates.begin();
  794. while( lhsItem != m_alternates.end() )
  795. {
  796. const ALT& lhsAlt = lhsItem->second;
  797. const ALT& rhsAlt = rhsItem->second;
  798. retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name );
  799. if( retv )
  800. return retv;
  801. if( lhsAlt.m_Type != rhsAlt.m_Type )
  802. return static_cast<int>( lhsAlt.m_Type ) - static_cast<int>( rhsAlt.m_Type );
  803. if( lhsAlt.m_Shape != rhsAlt.m_Shape )
  804. return static_cast<int>( lhsAlt.m_Shape ) - static_cast<int>( rhsAlt.m_Shape );
  805. ++lhsItem;
  806. ++rhsItem;
  807. }
  808. return 0;
  809. }
  810. void LIB_PIN::ChangeLength( int aLength )
  811. {
  812. int lengthChange = m_length - aLength;
  813. int offsetX = 0;
  814. int offsetY = 0;
  815. switch( m_orientation )
  816. {
  817. case PIN_RIGHT:
  818. offsetX = lengthChange;
  819. break;
  820. case PIN_LEFT:
  821. offsetX = -1 * lengthChange;
  822. break;
  823. case PIN_UP:
  824. offsetY = lengthChange;
  825. break;
  826. case PIN_DOWN:
  827. offsetY = -1 * lengthChange;
  828. break;
  829. }
  830. wxPoint offset = wxPoint( offsetX, offsetY );
  831. Offset( offset );
  832. m_length = aLength;
  833. }
  834. void LIB_PIN::Offset( const VECTOR2I& aOffset )
  835. {
  836. m_position += aOffset;
  837. }
  838. void LIB_PIN::MoveTo( const VECTOR2I& aNewPosition )
  839. {
  840. if( m_position != aNewPosition )
  841. {
  842. m_position = aNewPosition;
  843. SetModified();
  844. }
  845. }
  846. void LIB_PIN::MirrorHorizontal( const VECTOR2I& aCenter )
  847. {
  848. m_position.x -= aCenter.x;
  849. m_position.x *= -1;
  850. m_position.x += aCenter.x;
  851. if( m_orientation == PIN_RIGHT )
  852. m_orientation = PIN_LEFT;
  853. else if( m_orientation == PIN_LEFT )
  854. m_orientation = PIN_RIGHT;
  855. }
  856. void LIB_PIN::MirrorVertical( const VECTOR2I& aCenter )
  857. {
  858. m_position.y -= aCenter.y;
  859. m_position.y *= -1;
  860. m_position.y += aCenter.y;
  861. if( m_orientation == PIN_UP )
  862. m_orientation = PIN_DOWN;
  863. else if( m_orientation == PIN_DOWN )
  864. m_orientation = PIN_UP;
  865. }
  866. void LIB_PIN::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
  867. {
  868. EDA_ANGLE rot_angle = aRotateCCW ? -ANGLE_90 : ANGLE_90;
  869. RotatePoint( m_position, aCenter, rot_angle );
  870. if( aRotateCCW )
  871. {
  872. switch( m_orientation )
  873. {
  874. case PIN_RIGHT: m_orientation = PIN_UP; break;
  875. case PIN_UP: m_orientation = PIN_LEFT; break;
  876. case PIN_LEFT: m_orientation = PIN_DOWN; break;
  877. case PIN_DOWN: m_orientation = PIN_RIGHT; break;
  878. }
  879. }
  880. else
  881. {
  882. switch( m_orientation )
  883. {
  884. case PIN_RIGHT: m_orientation = PIN_DOWN; break;
  885. case PIN_UP: m_orientation = PIN_RIGHT; break;
  886. case PIN_LEFT: m_orientation = PIN_UP; break;
  887. case PIN_DOWN: m_orientation = PIN_LEFT; break;
  888. }
  889. }
  890. }
  891. void LIB_PIN::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
  892. const TRANSFORM& aTransform ) const
  893. {
  894. if( !IsVisible() || aBackground )
  895. return;
  896. int orient = PinDrawOrient( aTransform );
  897. VECTOR2I pos = aTransform.TransformCoordinate( m_position ) + aOffset;
  898. PlotSymbol( aPlotter, pos, orient );
  899. PlotPinTexts( aPlotter, pos, orient, GetParent()->GetPinNameOffset(),
  900. GetParent()->ShowPinNumbers(), GetParent()->ShowPinNames() );
  901. }
  902. void LIB_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  903. {
  904. EDA_UNITS units = aFrame->GetUserUnits();
  905. LIB_ITEM::GetMsgPanelInfo( aFrame, aList );
  906. aList.emplace_back( _( "Name" ), UnescapeString( GetShownName() ) );
  907. aList.emplace_back( _( "Number" ), GetShownNumber() );
  908. aList.emplace_back( _( "Type" ), ElectricalPinTypeGetText( m_type ) );
  909. aList.emplace_back( _( "Style" ), PinShapeGetText( m_shape ) );
  910. aList.emplace_back( _( "Style" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
  911. // Display pin length
  912. aList.emplace_back( _( "Length" ), MessageTextFromValue( units, m_length, true ) );
  913. int i = PinOrientationIndex( m_orientation );
  914. aList.emplace_back( _( "Orientation" ), PinOrientationName( (unsigned) i ) );
  915. VECTOR2I pinpos = GetPosition();
  916. pinpos.y = -pinpos.y; // Display coords are top to bottom; lib item coords are bottom to top
  917. aList.emplace_back( _( "Pos X" ), MessageTextFromValue( units, pinpos.x, true ) );
  918. aList.emplace_back( _( "Pos Y" ), MessageTextFromValue( units, pinpos.y, true ) );
  919. }
  920. const BOX2I LIB_PIN::ViewBBox() const
  921. {
  922. return GetBoundingBox( false, true, true );
  923. }
  924. void LIB_PIN::ViewGetLayers( int aLayers[], int& aCount ) const
  925. {
  926. aCount = 3;
  927. aLayers[0] = LAYER_DANGLING; // We don't really show dangling vs non-dangling (since there
  928. // are no connections in the symbol editor), but it's still
  929. // a good visual indication of which end of the pin is which.
  930. aLayers[1] = LAYER_DEVICE;
  931. aLayers[2] = LAYER_SELECTION_SHADOWS;
  932. }
  933. const BOX2I LIB_PIN::GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNameAndNumber,
  934. bool aIncludeElectricalType ) const
  935. {
  936. KIFONT::FONT* font = KIFONT::FONT::GetFont( Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>()->m_Appearance.default_font );
  937. BOX2I bbox;
  938. VECTOR2I begin;
  939. VECTOR2I end;
  940. int nameTextOffset = 0;
  941. int nameTextLength = 0;
  942. int nameTextHeight = 0;
  943. int numberTextLength = 0;
  944. int numberTextHeight = 0;
  945. int typeTextLength = 0;
  946. wxString name = GetShownName();
  947. wxString number = GetShownNumber();
  948. bool includeName = aIncludeNameAndNumber && !name.IsEmpty();
  949. bool includeNumber = aIncludeNameAndNumber && !number.IsEmpty();
  950. bool includeType = aIncludeElectricalType;
  951. int minsizeV = TARGET_PIN_RADIUS;
  952. int penWidth = GetPenWidth();
  953. if( !aIncludeInvisiblePins && !IsVisible() )
  954. {
  955. includeName = false;
  956. includeType = false;
  957. }
  958. if( GetParent() )
  959. {
  960. if( GetParent()->ShowPinNames() )
  961. nameTextOffset = GetParent()->GetPinNameOffset();
  962. else
  963. includeName = false;
  964. if( !GetParent()->ShowPinNumbers() )
  965. includeNumber = false;
  966. }
  967. if( includeNumber )
  968. {
  969. VECTOR2D fontSize( m_numTextSize, m_numTextSize );
  970. VECTOR2I numSize = font->StringBoundaryLimits( number, fontSize, penWidth, false, false );
  971. numberTextLength = numSize.x;
  972. numberTextHeight = numSize.y;
  973. }
  974. if( includeName )
  975. {
  976. VECTOR2D fontSize( m_nameTextSize, m_nameTextSize );
  977. VECTOR2I nameSize = font->StringBoundaryLimits( name, fontSize, penWidth, false, false );
  978. nameTextLength = nameSize.x + nameTextOffset;
  979. nameTextHeight = nameSize.y + Mils2iu( PIN_TEXT_MARGIN );
  980. }
  981. if( includeType )
  982. {
  983. double fontSize = std::max( m_nameTextSize * 3 / 4, Millimeter2iu( 0.7 ) );
  984. VECTOR2I typeTextSize = font->StringBoundaryLimits( GetElectricalTypeName(),
  985. VECTOR2D( fontSize, fontSize ),
  986. fontSize / 8.0, false, false );
  987. typeTextLength = typeTextSize.x + Mils2iu( PIN_TEXT_MARGIN ) + TARGET_PIN_RADIUS;
  988. minsizeV = std::max( minsizeV, typeTextSize.y / 2 );
  989. }
  990. // First, calculate boundary box corners position
  991. if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK )
  992. minsizeV = std::max( TARGET_PIN_RADIUS, externalPinDecoSize( nullptr, *this ) );
  993. // calculate top left corner position
  994. // for the default pin orientation (PIN_RIGHT)
  995. begin.y = std::max( minsizeV, numberTextHeight + Mils2iu( PIN_TEXT_MARGIN ) );
  996. begin.x = std::min( -typeTextLength, m_length - ( numberTextLength / 2) );
  997. // calculate bottom right corner position and adjust top left corner position
  998. if( nameTextOffset ) // for values > 0, pin name is inside the body
  999. {
  1000. end.x = m_length + nameTextLength;
  1001. end.y = std::min( -minsizeV, -nameTextHeight / 2 );
  1002. }
  1003. else // if value == 0:
  1004. // pin name is outside the body, and above the pin line
  1005. // pin num is below the pin line
  1006. {
  1007. end.x = std::max( m_length, nameTextLength );
  1008. end.y = -begin.y;
  1009. begin.y = std::max( minsizeV, nameTextHeight );
  1010. }
  1011. // Now, calculate boundary box corners position for the actual pin orientation
  1012. int orient = PinDrawOrient( DefaultTransform );
  1013. /* Calculate the pin position */
  1014. switch( orient )
  1015. {
  1016. case PIN_UP:
  1017. // Pin is rotated and texts positions are mirrored
  1018. RotatePoint( begin, VECTOR2I( 0, 0 ), -ANGLE_90 );
  1019. RotatePoint( end, VECTOR2I( 0, 0 ), -ANGLE_90 );
  1020. break;
  1021. case PIN_DOWN:
  1022. RotatePoint( begin, VECTOR2I( 0, 0 ), ANGLE_90 );
  1023. RotatePoint( end, VECTOR2I( 0, 0 ), ANGLE_90 );
  1024. begin.x = -begin.x;
  1025. end.x = -end.x;
  1026. break;
  1027. case PIN_LEFT:
  1028. begin.x = -begin.x;
  1029. end.x = -end.x;
  1030. break;
  1031. case PIN_RIGHT:
  1032. break;
  1033. }
  1034. begin += m_position;
  1035. end += m_position;
  1036. bbox.SetOrigin( begin );
  1037. bbox.SetEnd( end );
  1038. bbox.Normalize();
  1039. bbox.Inflate( ( GetPenWidth() / 2 ) + 1 );
  1040. // Draw Y axis is reversed in schematic:
  1041. bbox.RevertYAxis();
  1042. return bbox;
  1043. }
  1044. BITMAPS LIB_PIN::GetMenuImage() const
  1045. {
  1046. return ElectricalPinTypeGetBitmap( m_type );
  1047. }
  1048. wxString LIB_PIN::GetSelectMenuText( EDA_UNITS aUnits ) const
  1049. {
  1050. if( !m_name.IsEmpty() )
  1051. {
  1052. return wxString::Format( _( "Pin %s [%s, %s, %s]" ),
  1053. GetShownNumber(),
  1054. UnescapeString( GetShownName() ),
  1055. GetElectricalTypeName(),
  1056. PinShapeGetText( m_shape ) );
  1057. }
  1058. else
  1059. {
  1060. return wxString::Format( _( "Pin %s [%s, %s]" ),
  1061. GetShownNumber(),
  1062. GetElectricalTypeName(),
  1063. PinShapeGetText( m_shape ) );
  1064. }
  1065. }
  1066. #if defined(DEBUG)
  1067. void LIB_PIN::Show( int nestLevel, std::ostream& os ) const
  1068. {
  1069. NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
  1070. << " num=\"" << m_number.mb_str()
  1071. << '"' << "/>\n";
  1072. // NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
  1073. }
  1074. #endif
  1075. void LIB_PIN::CalcEdit( const VECTOR2I& aPosition )
  1076. {
  1077. if( IsMoving() )
  1078. MoveTo( aPosition );
  1079. }