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.

707 lines
21 KiB

5 years ago
2 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <google/protobuf/any.pb.h>
  26. #include <advanced_config.h>
  27. #include <pcb_edit_frame.h>
  28. #include <base_units.h>
  29. #include <bitmaps.h>
  30. #include <board.h>
  31. #include <board_design_settings.h>
  32. #include <core/mirror.h>
  33. #include <footprint.h>
  34. #include <pcb_text.h>
  35. #include <pcb_painter.h>
  36. #include <trigo.h>
  37. #include <string_utils.h>
  38. #include <geometry/shape_compound.h>
  39. #include <callback_gal.h>
  40. #include <convert_basic_shapes_to_polygon.h>
  41. #include <api/api_enums.h>
  42. #include <api/api_utils.h>
  43. #include <api/board/board_types.pb.h>
  44. using namespace kiapi::common;
  45. PCB_TEXT::PCB_TEXT( BOARD_ITEM* parent, KICAD_T idtype ) :
  46. BOARD_ITEM( parent, idtype ),
  47. EDA_TEXT( pcbIUScale )
  48. {
  49. SetMultilineAllowed( true );
  50. }
  51. PCB_TEXT::PCB_TEXT( FOOTPRINT* aParent, KICAD_T idtype) :
  52. BOARD_ITEM( aParent, idtype ),
  53. EDA_TEXT( pcbIUScale )
  54. {
  55. SetKeepUpright( true );
  56. // Set text thickness to a default value
  57. SetTextThickness( pcbIUScale.mmToIU( DEFAULT_TEXT_WIDTH ) );
  58. SetLayer( F_SilkS );
  59. if( aParent )
  60. {
  61. SetTextPos( aParent->GetPosition() );
  62. // N.B. Do not automatically set text effects
  63. // These are optional in the file format and so need to be defaulted
  64. // to off.
  65. if( IsBackLayer( aParent->GetLayer() ) )
  66. SetLayer( B_SilkS );
  67. }
  68. }
  69. PCB_TEXT::~PCB_TEXT()
  70. {
  71. }
  72. void PCB_TEXT::Serialize( google::protobuf::Any &aContainer ) const
  73. {
  74. kiapi::board::types::Text boardText;
  75. boardText.set_layer( ToProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( GetLayer() ) );
  76. kiapi::common::types::Text& text = *boardText.mutable_text();
  77. text.mutable_id()->set_value( m_Uuid.AsStdString() );
  78. text.mutable_position()->set_x_nm( GetPosition().x );
  79. text.mutable_position()->set_y_nm( GetPosition().y );
  80. text.set_text( GetText().ToStdString() );
  81. text.set_hyperlink( GetHyperlink().ToStdString() );
  82. text.set_locked( IsLocked() ? types::LockedState::LS_LOCKED
  83. : types::LockedState::LS_UNLOCKED );
  84. kiapi::common::types::TextAttributes* attrs = text.mutable_attributes();
  85. if( GetFont() )
  86. attrs->set_font_name( GetFont()->GetName().ToStdString() );
  87. attrs->set_horizontal_alignment(
  88. ToProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>( GetHorizJustify() ) );
  89. attrs->set_vertical_alignment(
  90. ToProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>( GetVertJustify() ) );
  91. attrs->mutable_angle()->set_value_degrees( GetTextAngleDegrees() );
  92. attrs->set_line_spacing( GetLineSpacing() );
  93. attrs->mutable_stroke_width()->set_value_nm( GetTextThickness() );
  94. attrs->set_italic( IsItalic() );
  95. attrs->set_bold( IsBold() );
  96. attrs->set_underlined( GetAttributes().m_Underlined );
  97. attrs->set_visible( IsVisible() );
  98. attrs->set_mirrored( IsMirrored() );
  99. attrs->set_multiline( IsMultilineAllowed() );
  100. attrs->set_keep_upright( IsKeepUpright() );
  101. attrs->mutable_size()->set_x_nm( GetTextSize().x );
  102. attrs->mutable_size()->set_y_nm( GetTextSize().y );
  103. text.set_knockout( IsKnockout() );
  104. aContainer.PackFrom( boardText );
  105. }
  106. bool PCB_TEXT::Deserialize( const google::protobuf::Any &aContainer )
  107. {
  108. kiapi::board::types::Text textWrapper;
  109. if( !aContainer.UnpackTo( &textWrapper ) )
  110. return false;
  111. SetLayer( FromProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( textWrapper.layer() ) );
  112. const kiapi::common::types::Text& text = textWrapper.text();
  113. const_cast<KIID&>( m_Uuid ) = KIID( text.id().value() );
  114. SetPosition( VECTOR2I( text.position().x_nm(), text.position().y_nm() ) );
  115. SetLocked( text.locked() == kiapi::common::types::LockedState::LS_LOCKED );
  116. SetText( wxString( text.text().c_str(), wxConvUTF8 ) );
  117. SetHyperlink( wxString( text.hyperlink().c_str(), wxConvUTF8 ) );
  118. SetIsKnockout( text.knockout() );
  119. if( text.has_attributes() )
  120. {
  121. TEXT_ATTRIBUTES attrs = GetAttributes();
  122. attrs.m_Bold = text.attributes().bold();
  123. attrs.m_Italic = text.attributes().italic();
  124. attrs.m_Underlined = text.attributes().underlined();
  125. attrs.m_Visible = text.attributes().visible();
  126. attrs.m_Mirrored = text.attributes().mirrored();
  127. attrs.m_Multiline = text.attributes().multiline();
  128. attrs.m_KeepUpright = text.attributes().keep_upright();
  129. attrs.m_Size = VECTOR2I( text.attributes().size().x_nm(), text.attributes().size().y_nm() );
  130. if( !text.attributes().font_name().empty() )
  131. {
  132. attrs.m_Font = KIFONT::FONT::GetFont(
  133. wxString( text.attributes().font_name().c_str(), wxConvUTF8 ), attrs.m_Bold,
  134. attrs.m_Italic );
  135. }
  136. attrs.m_Angle = EDA_ANGLE( text.attributes().angle().value_degrees(), DEGREES_T );
  137. attrs.m_LineSpacing = text.attributes().line_spacing();
  138. attrs.m_StrokeWidth = text.attributes().stroke_width().value_nm();
  139. attrs.m_Halign = FromProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>(
  140. text.attributes().horizontal_alignment() );
  141. attrs.m_Valign = FromProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>(
  142. text.attributes().vertical_alignment() );
  143. SetAttributes( attrs );
  144. }
  145. return true;
  146. }
  147. wxString PCB_TEXT::GetShownText( bool aAllowExtraText, int aDepth ) const
  148. {
  149. const FOOTPRINT* parentFootprint = GetParentFootprint();
  150. const BOARD* board = GetBoard();
  151. std::function<bool( wxString* )> resolver =
  152. [&]( wxString* token ) -> bool
  153. {
  154. if( parentFootprint && parentFootprint->ResolveTextVar( token, aDepth + 1 ) )
  155. return true;
  156. if( token->IsSameAs( wxT( "LAYER" ) ) )
  157. {
  158. *token = GetLayerName();
  159. return true;
  160. }
  161. if( board->ResolveTextVar( token, aDepth + 1 ) )
  162. return true;
  163. return false;
  164. };
  165. wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
  166. if( HasTextVars() )
  167. {
  168. if( aDepth < ADVANCED_CFG::GetCfg().m_ResolveTextRecursionDepth )
  169. text = ExpandTextVars( text, &resolver );
  170. }
  171. return text;
  172. }
  173. bool PCB_TEXT::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
  174. {
  175. return BOARD_ITEM::Matches( UnescapeString( GetText() ), aSearchData );
  176. }
  177. EDA_ANGLE PCB_TEXT::GetDrawRotation() const
  178. {
  179. EDA_ANGLE rotation = GetTextAngle();
  180. if( GetParentFootprint() && IsKeepUpright() )
  181. {
  182. // Keep angle between ]-90..90] deg. Otherwise the text is not easy to read
  183. while( rotation > ANGLE_90 )
  184. rotation -= ANGLE_180;
  185. while( rotation <= -ANGLE_90 )
  186. rotation += ANGLE_180;
  187. }
  188. else
  189. {
  190. rotation.Normalize();
  191. }
  192. return rotation;
  193. }
  194. const BOX2I PCB_TEXT::ViewBBox() const
  195. {
  196. return GetBoundingBox();
  197. }
  198. void PCB_TEXT::ViewGetLayers( int aLayers[], int& aCount ) const
  199. {
  200. if( GetParentFootprint() == nullptr || IsVisible() )
  201. aLayers[0] = GetLayer();
  202. else
  203. aLayers[0] = LAYER_HIDDEN_TEXT;
  204. aCount = 1;
  205. if( IsLocked() )
  206. aLayers[ aCount++ ] = LAYER_LOCKED_ITEM_SHADOW;
  207. }
  208. double PCB_TEXT::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
  209. {
  210. constexpr double HIDE = std::numeric_limits<double>::max();
  211. if( !aView )
  212. return 0.0;
  213. KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( aView->GetPainter() );
  214. KIGFX::PCB_RENDER_SETTINGS* renderSettings = painter->GetSettings();
  215. // Hidden text gets put on the LAYER_HIDDEN_TEXT for rendering, but
  216. // should only render if its native layer is visible.
  217. if( !aView->IsLayerVisible( GetLayer() ) )
  218. return HIDE;
  219. if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
  220. {
  221. // Hide shadow on dimmed tracks
  222. if( renderSettings->GetHighContrast() )
  223. {
  224. if( m_layer != renderSettings->GetPrimaryHighContrastLayer() )
  225. return HIDE;
  226. }
  227. }
  228. if( FOOTPRINT* parentFP = GetParentFootprint() )
  229. {
  230. // Handle Render tab switches
  231. if( GetText() == wxT( "${VALUE}" ) )
  232. {
  233. if( !aView->IsLayerVisible( LAYER_FP_VALUES ) )
  234. return HIDE;
  235. }
  236. if( GetText() == wxT( "${REFERENCE}" ) )
  237. {
  238. if( !aView->IsLayerVisible( LAYER_FP_REFERENCES ) )
  239. return HIDE;
  240. }
  241. if( parentFP->GetLayer() == F_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_FR ) )
  242. return HIDE;
  243. if( parentFP->GetLayer() == B_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_BK ) )
  244. return HIDE;
  245. if( !aView->IsLayerVisible( LAYER_FP_TEXT ) )
  246. return HIDE;
  247. }
  248. return 0.0;
  249. }
  250. void PCB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  251. {
  252. FOOTPRINT* parentFP = GetParentFootprint();
  253. if( parentFP && aFrame->GetName() == PCB_EDIT_FRAME_NAME )
  254. aList.emplace_back( _( "Footprint" ), parentFP->GetReference() );
  255. // Don't use GetShownText() here; we want to show the user the variable references
  256. if( parentFP )
  257. aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
  258. else
  259. aList.emplace_back( _( "PCB Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
  260. if( parentFP )
  261. aList.emplace_back( _( "Type" ), GetTextTypeDescription() );
  262. if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
  263. aList.emplace_back( _( "Status" ), _( "Locked" ) );
  264. if( parentFP )
  265. aList.emplace_back( _( "Display" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
  266. aList.emplace_back( _( "Layer" ), GetLayerName() );
  267. aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) );
  268. aList.emplace_back( _( "Angle" ), wxString::Format( wxT( "%g" ), GetTextAngle().AsDegrees() ) );
  269. aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
  270. aList.emplace_back( _( "Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) );
  271. aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
  272. aList.emplace_back( _( "Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) );
  273. }
  274. int PCB_TEXT::getKnockoutMargin() const
  275. {
  276. return GetKnockoutTextMargin( VECTOR2I( GetTextWidth(), GetTextHeight() ), GetTextThickness() );
  277. }
  278. void PCB_TEXT::StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings )
  279. {
  280. SetTextSize( settings.GetTextSize( GetLayer() ) );
  281. SetTextThickness( settings.GetTextThickness( GetLayer() ) );
  282. SetItalic( settings.GetTextItalic( GetLayer() ) );
  283. SetKeepUpright( settings.GetTextUpright( GetLayer() ) );
  284. SetMirrored( IsBackLayer( GetLayer() ) );
  285. }
  286. void PCB_TEXT::KeepUpright()
  287. {
  288. if( !IsKeepUpright() )
  289. return;
  290. EDA_ANGLE newAngle = GetTextAngle();
  291. newAngle.Normalize();
  292. bool needsFlipped = newAngle >= ANGLE_180;
  293. if( needsFlipped )
  294. {
  295. SetHorizJustify( static_cast<GR_TEXT_H_ALIGN_T>( -GetHorizJustify() ) );
  296. SetVertJustify( static_cast<GR_TEXT_V_ALIGN_T>( -GetVertJustify() ) );
  297. SetTextAngle( GetTextAngle() + ANGLE_180 );
  298. }
  299. }
  300. const BOX2I PCB_TEXT::GetBoundingBox() const
  301. {
  302. EDA_ANGLE angle = GetDrawRotation();
  303. BOX2I rect = GetTextBox();
  304. if( IsKnockout() )
  305. rect.Inflate( getKnockoutMargin() );
  306. if( !angle.IsZero() )
  307. rect = rect.GetBoundingBoxRotated( GetTextPos(), angle );
  308. return rect;
  309. }
  310. bool PCB_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
  311. {
  312. int accuracy = aAccuracy;
  313. if( IsKnockout() )
  314. accuracy += GetKnockoutTextMargin( GetTextSize(), GetTextThickness() );
  315. return EDA_TEXT::TextHitTest( aPoint, accuracy );
  316. }
  317. bool PCB_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
  318. {
  319. BOX2I rect = aRect;
  320. rect.Inflate( aAccuracy );
  321. if( aContains )
  322. return rect.Contains( GetBoundingBox() );
  323. return rect.Intersects( GetBoundingBox() );
  324. }
  325. void PCB_TEXT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
  326. {
  327. VECTOR2I pt = GetTextPos();
  328. RotatePoint( pt, aRotCentre, aAngle );
  329. SetTextPos( pt );
  330. EDA_ANGLE new_angle = GetTextAngle() + aAngle;
  331. new_angle.Normalize180();
  332. SetTextAngle( new_angle );
  333. }
  334. void PCB_TEXT::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis )
  335. {
  336. // the position and justification are mirrored, but not the text itself
  337. if( aMirrorAroundXAxis )
  338. {
  339. if( GetTextAngle() == ANGLE_VERTICAL )
  340. SetHorizJustify( (GR_TEXT_H_ALIGN_T) -GetHorizJustify() );
  341. SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) );
  342. }
  343. else
  344. {
  345. if( GetTextAngle() == ANGLE_HORIZONTAL )
  346. SetHorizJustify( (GR_TEXT_H_ALIGN_T) -GetHorizJustify() );
  347. SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) );
  348. }
  349. }
  350. void PCB_TEXT::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
  351. {
  352. if( aFlipLeftRight )
  353. {
  354. SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) );
  355. SetTextAngle( -GetTextAngle() );
  356. }
  357. else
  358. {
  359. SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) );
  360. SetTextAngle( ANGLE_180 - GetTextAngle() );
  361. }
  362. SetLayer( GetBoard()->FlipLayer( GetLayer() ) );
  363. if( IsSideSpecific() )
  364. SetMirrored( !IsMirrored() );
  365. }
  366. wxString PCB_TEXT::GetTextTypeDescription() const
  367. {
  368. return _( "Text" );
  369. }
  370. wxString PCB_TEXT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
  371. {
  372. wxString content = aFull ? GetShownText( false ) : KIUI::EllipsizeMenuText( GetText() );
  373. if( FOOTPRINT* parentFP = GetParentFootprint() )
  374. {
  375. wxString ref = parentFP->GetReference();
  376. return wxString::Format( _( "Footprint text of %s (%s)" ), ref, content );
  377. }
  378. return wxString::Format( _( "PCB text '%s' on %s" ), content, GetLayerName() );
  379. }
  380. BITMAPS PCB_TEXT::GetMenuImage() const
  381. {
  382. return BITMAPS::text;
  383. }
  384. EDA_ITEM* PCB_TEXT::Clone() const
  385. {
  386. return new PCB_TEXT( *this );
  387. }
  388. void PCB_TEXT::swapData( BOARD_ITEM* aImage )
  389. {
  390. assert( aImage->Type() == PCB_TEXT_T );
  391. std::swap( *((PCB_TEXT*) this), *((PCB_TEXT*) aImage) );
  392. }
  393. std::shared_ptr<SHAPE> PCB_TEXT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
  394. {
  395. if( IsKnockout() )
  396. {
  397. SHAPE_POLY_SET poly;
  398. TransformTextToPolySet( poly, 0, GetBoard()->GetDesignSettings().m_MaxError, ERROR_INSIDE );
  399. return std::make_shared<SHAPE_POLY_SET>( poly );
  400. }
  401. return GetEffectiveTextShape();
  402. }
  403. void PCB_TEXT::buildBoundingHull( SHAPE_POLY_SET* aBuffer, const SHAPE_POLY_SET& aRenderedText,
  404. int aClearance ) const
  405. {
  406. SHAPE_POLY_SET poly( aRenderedText );
  407. poly.Rotate( -GetDrawRotation(), GetDrawPos() );
  408. BOX2I rect = poly.BBox( aClearance );
  409. VECTOR2I corners[4];
  410. corners[0].x = rect.GetOrigin().x;
  411. corners[0].y = rect.GetOrigin().y;
  412. corners[1].y = corners[0].y;
  413. corners[1].x = rect.GetRight();
  414. corners[2].x = corners[1].x;
  415. corners[2].y = rect.GetBottom();
  416. corners[3].y = corners[2].y;
  417. corners[3].x = corners[0].x;
  418. aBuffer->NewOutline();
  419. for( VECTOR2I& corner : corners )
  420. {
  421. RotatePoint( corner, GetDrawPos(), GetDrawRotation() );
  422. aBuffer->Append( corner.x, corner.y );
  423. }
  424. }
  425. void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, int aMaxError,
  426. ERROR_LOC aErrorLoc ) const
  427. {
  428. KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
  429. KIFONT::FONT* font = getDrawFont();
  430. int penWidth = GetEffectiveTextPenWidth();
  431. TEXT_ATTRIBUTES attrs = GetAttributes();
  432. attrs.m_Angle = GetDrawRotation();
  433. // The polygonal shape of a text can have many basic shapes, so combining these shapes can
  434. // be very useful to create a final shape with a lot less vertices to speedup calculations.
  435. // Simplify shapes is not usually always efficient, but in this case it is.
  436. SHAPE_POLY_SET textShape;
  437. CALLBACK_GAL callback_gal( empty_opts,
  438. // Stroke callback
  439. [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
  440. {
  441. TransformOvalToPolygon( textShape, aPt1, aPt2, penWidth, aMaxError, aErrorLoc );
  442. },
  443. // Triangulation callback
  444. [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
  445. {
  446. textShape.NewOutline();
  447. for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
  448. textShape.Append( point.x, point.y );
  449. } );
  450. font->Draw( &callback_gal, GetShownText( true ), GetTextPos(), attrs, GetFontMetrics() );
  451. textShape.Simplify( SHAPE_POLY_SET::PM_FAST );
  452. if( IsKnockout() )
  453. {
  454. SHAPE_POLY_SET finalPoly;
  455. int margin = GetKnockoutTextMargin( attrs.m_Size, penWidth );
  456. buildBoundingHull( &finalPoly, textShape, margin + aClearance );
  457. finalPoly.BooleanSubtract( textShape, SHAPE_POLY_SET::PM_FAST );
  458. aBuffer.Append( finalPoly );
  459. }
  460. else
  461. {
  462. if( aClearance > 0 || aErrorLoc == ERROR_OUTSIDE )
  463. {
  464. if( aErrorLoc == ERROR_OUTSIDE )
  465. aClearance += aMaxError;
  466. textShape.Inflate( aClearance, CORNER_STRATEGY::ROUND_ALL_CORNERS, aMaxError );
  467. }
  468. aBuffer.Append( textShape );
  469. }
  470. }
  471. void PCB_TEXT::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
  472. int aClearance, int aMaxError, ERROR_LOC aErrorLoc,
  473. bool aIgnoreLineWidth ) const
  474. {
  475. SHAPE_POLY_SET poly;
  476. TransformTextToPolySet( poly, 0, aMaxError, aErrorLoc );
  477. buildBoundingHull( &aBuffer, poly, aClearance );
  478. }
  479. bool PCB_TEXT::operator==( const BOARD_ITEM& aBoardItem ) const
  480. {
  481. if( aBoardItem.Type() != Type() )
  482. return false;
  483. const PCB_TEXT& other = static_cast<const PCB_TEXT&>( aBoardItem );
  484. return *this == other;
  485. }
  486. bool PCB_TEXT::operator==( const PCB_TEXT& aOther ) const
  487. {
  488. return EDA_TEXT::operator==( aOther );
  489. }
  490. double PCB_TEXT::Similarity( const BOARD_ITEM& aOther ) const
  491. {
  492. if( aOther.Type() != Type() )
  493. return 0.0;
  494. const PCB_TEXT& other = static_cast<const PCB_TEXT&>( aOther );
  495. return EDA_TEXT::Similarity( other );
  496. }
  497. static struct PCB_TEXT_DESC
  498. {
  499. PCB_TEXT_DESC()
  500. {
  501. PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
  502. REGISTER_TYPE( PCB_TEXT );
  503. propMgr.AddTypeCast( new TYPE_CAST<PCB_TEXT, BOARD_ITEM> );
  504. propMgr.AddTypeCast( new TYPE_CAST<PCB_TEXT, EDA_TEXT> );
  505. propMgr.InheritsAfter( TYPE_HASH( PCB_TEXT ), TYPE_HASH( BOARD_ITEM ) );
  506. propMgr.InheritsAfter( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ) );
  507. propMgr.Mask( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Color" ) );
  508. propMgr.AddProperty( new PROPERTY<PCB_TEXT, bool, BOARD_ITEM>( _HKI( "Knockout" ),
  509. &BOARD_ITEM::SetIsKnockout, &BOARD_ITEM::IsKnockout ),
  510. _HKI( "Text Properties" ) );
  511. propMgr.AddProperty( new PROPERTY<PCB_TEXT, bool, EDA_TEXT>( _HKI( "Keep Upright" ),
  512. &PCB_TEXT::SetKeepUpright, &PCB_TEXT::IsKeepUpright ),
  513. _HKI( "Text Properties" ) );
  514. auto isFootprintText =
  515. []( INSPECTABLE* aItem ) -> bool
  516. {
  517. if( PCB_TEXT* text = dynamic_cast<PCB_TEXT*>( aItem ) )
  518. return text->GetParentFootprint();
  519. return false;
  520. };
  521. propMgr.OverrideAvailability( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ),
  522. _HKI( "Visible" ), isFootprintText );
  523. propMgr.OverrideAvailability( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ),
  524. _HKI( "Keep Upright" ), isFootprintText );
  525. propMgr.OverrideAvailability( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ),
  526. _HKI( "Hyperlink" ),
  527. []( INSPECTABLE* aItem ) { return false; } );
  528. }
  529. } _PCB_TEXT_DESC;