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.

706 lines
20 KiB

5 years ago
1 year 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 The 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 <geometry/geometry_utils.h>
  40. #include <callback_gal.h>
  41. #include <convert_basic_shapes_to_polygon.h>
  42. #include <api/api_enums.h>
  43. #include <api/api_utils.h>
  44. #include <api/board/board_types.pb.h>
  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. // N.B. Do not automatically set text effects
  57. // These are optional in the file format and so need to be defaulted to off.
  58. SetLayer( F_SilkS );
  59. if( aParent )
  60. {
  61. SetTextPos( aParent->GetPosition() );
  62. if( IsBackLayer( aParent->GetLayer() ) )
  63. SetLayer( B_SilkS );
  64. }
  65. }
  66. PCB_TEXT::~PCB_TEXT()
  67. {
  68. }
  69. void PCB_TEXT::CopyFrom( const BOARD_ITEM* aOther )
  70. {
  71. wxCHECK( aOther && aOther->Type() == PCB_TEXT_T, /* void */ );
  72. *this = *static_cast<const PCB_TEXT*>( aOther );
  73. }
  74. void PCB_TEXT::Serialize( google::protobuf::Any &aContainer ) const
  75. {
  76. using namespace kiapi::common;
  77. kiapi::board::types::BoardText boardText;
  78. boardText.mutable_id()->set_value( m_Uuid.AsStdString() );
  79. boardText.set_layer( ToProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( GetLayer() ) );
  80. boardText.set_knockout( IsKnockout() );
  81. boardText.set_locked( IsLocked() ? types::LockedState::LS_LOCKED
  82. : types::LockedState::LS_UNLOCKED );
  83. google::protobuf::Any any;
  84. EDA_TEXT::Serialize( any );
  85. any.UnpackTo( boardText.mutable_text() );
  86. // Some of the common Text message fields are not stored in EDA_TEXT
  87. types::Text* text = boardText.mutable_text();
  88. PackVector2( *text->mutable_position(), GetPosition() );
  89. aContainer.PackFrom( boardText );
  90. }
  91. bool PCB_TEXT::Deserialize( const google::protobuf::Any &aContainer )
  92. {
  93. using namespace kiapi::common;
  94. kiapi::board::types::BoardText boardText;
  95. if( !aContainer.UnpackTo( &boardText ) )
  96. return false;
  97. SetLayer( FromProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( boardText.layer() ) );
  98. const_cast<KIID&>( m_Uuid ) = KIID( boardText.id().value() );
  99. SetIsKnockout( boardText.knockout() );
  100. SetLocked( boardText.locked() == types::LockedState::LS_LOCKED );
  101. google::protobuf::Any any;
  102. any.PackFrom( boardText.text() );
  103. EDA_TEXT::Deserialize( any );
  104. const types::Text& text = boardText.text();
  105. SetPosition( UnpackVector2( text.position() ) );
  106. return true;
  107. }
  108. wxString PCB_TEXT::GetShownText( bool aAllowExtraText, int aDepth ) const
  109. {
  110. const FOOTPRINT* parentFootprint = GetParentFootprint();
  111. const BOARD* board = GetBoard();
  112. std::function<bool( wxString* )> resolver =
  113. [&]( wxString* token ) -> bool
  114. {
  115. if( token->IsSameAs( wxT( "LAYER" ) ) )
  116. {
  117. *token = GetLayerName();
  118. return true;
  119. }
  120. if( parentFootprint && parentFootprint->ResolveTextVar( token, aDepth + 1 ) )
  121. return true;
  122. // board can be null in some cases when saving a footprint in FP editor
  123. if( board && board->ResolveTextVar( token, aDepth + 1 ) )
  124. return true;
  125. return false;
  126. };
  127. wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
  128. if( HasTextVars() )
  129. {
  130. if( aDepth < ADVANCED_CFG::GetCfg().m_ResolveTextRecursionDepth )
  131. text = ExpandTextVars( text, &resolver );
  132. }
  133. if( text.Contains( wxT( "@{" ) ) )
  134. text = EvaluateText( text );
  135. return text;
  136. }
  137. bool PCB_TEXT::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
  138. {
  139. return BOARD_ITEM::Matches( UnescapeString( GetText() ), aSearchData );
  140. }
  141. EDA_ANGLE PCB_TEXT::GetDrawRotation() const
  142. {
  143. EDA_ANGLE rotation = GetTextAngle();
  144. if( GetParentFootprint() && IsKeepUpright() )
  145. {
  146. // Keep angle between ]-90..90] deg. Otherwise the text is not easy to read
  147. while( rotation > ANGLE_90 )
  148. rotation -= ANGLE_180;
  149. while( rotation <= -ANGLE_90 )
  150. rotation += ANGLE_180;
  151. }
  152. else
  153. {
  154. rotation.Normalize();
  155. }
  156. return rotation;
  157. }
  158. const BOX2I PCB_TEXT::ViewBBox() const
  159. {
  160. return GetBoundingBox();
  161. }
  162. std::vector<int> PCB_TEXT::ViewGetLayers() const
  163. {
  164. if( IsLocked() || ( GetParentFootprint() && GetParentFootprint()->IsLocked() ) )
  165. return { GetLayer(), LAYER_LOCKED_ITEM_SHADOW };
  166. return { GetLayer() };
  167. }
  168. double PCB_TEXT::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
  169. {
  170. if( !aView )
  171. return LOD_SHOW;
  172. KIGFX::PCB_PAINTER& painter = static_cast<KIGFX::PCB_PAINTER&>( *aView->GetPainter() );
  173. KIGFX::PCB_RENDER_SETTINGS& renderSettings = *painter.GetSettings();
  174. if( !aView->IsLayerVisible( GetLayer() ) )
  175. return LOD_HIDE;
  176. if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
  177. {
  178. // Hide shadow on dimmed tracks
  179. if( renderSettings.GetHighContrast() )
  180. {
  181. if( m_layer != renderSettings.GetPrimaryHighContrastLayer() )
  182. return LOD_HIDE;
  183. }
  184. }
  185. if( FOOTPRINT* parentFP = GetParentFootprint() )
  186. {
  187. // Handle Render tab switches
  188. if( GetText() == wxT( "${VALUE}" ) )
  189. {
  190. if( !aView->IsLayerVisible( LAYER_FP_VALUES ) )
  191. return LOD_HIDE;
  192. }
  193. if( GetText() == wxT( "${REFERENCE}" ) )
  194. {
  195. if( !aView->IsLayerVisible( LAYER_FP_REFERENCES ) )
  196. return LOD_HIDE;
  197. }
  198. if( parentFP->GetLayer() == F_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_FR ) )
  199. return LOD_HIDE;
  200. if( parentFP->GetLayer() == B_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_BK ) )
  201. return LOD_HIDE;
  202. if( !aView->IsLayerVisible( LAYER_FP_TEXT ) )
  203. return LOD_HIDE;
  204. }
  205. return LOD_SHOW;
  206. }
  207. void PCB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  208. {
  209. FOOTPRINT* parentFP = GetParentFootprint();
  210. if( parentFP && aFrame->GetName() == PCB_EDIT_FRAME_NAME )
  211. aList.emplace_back( _( "Footprint" ), parentFP->GetReference() );
  212. // Don't use GetShownText() here; we want to show the user the variable references
  213. if( parentFP )
  214. aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
  215. else
  216. aList.emplace_back( _( "PCB Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
  217. if( parentFP )
  218. aList.emplace_back( _( "Type" ), GetTextTypeDescription() );
  219. if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
  220. aList.emplace_back( _( "Status" ), _( "Locked" ) );
  221. aList.emplace_back( _( "Layer" ), GetLayerName() );
  222. aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) );
  223. aList.emplace_back( _( "Angle" ), wxString::Format( wxT( "%g" ), GetTextAngle().AsDegrees() ) );
  224. aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
  225. if( GetTextThickness() )
  226. aList.emplace_back( _( "Text Thickness" ), aFrame->MessageTextFromValue( GetEffectiveTextPenWidth() ) );
  227. else
  228. aList.emplace_back( _( "Text Thickness" ), _( "Auto" ) );
  229. aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
  230. aList.emplace_back( _( "Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) );
  231. }
  232. int PCB_TEXT::getKnockoutMargin() const
  233. {
  234. return GetKnockoutTextMargin( VECTOR2I( GetTextWidth(), GetTextHeight() ), GetEffectiveTextPenWidth() );
  235. }
  236. void PCB_TEXT::StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings )
  237. {
  238. SetTextSize( settings.GetTextSize( GetLayer() ) );
  239. SetTextThickness( settings.GetTextThickness( GetLayer() ) );
  240. SetItalic( settings.GetTextItalic( GetLayer() ) );
  241. SetKeepUpright( settings.GetTextUpright( GetLayer() ) );
  242. if( BOARD* board = GetBoard() )
  243. SetMirrored( board->IsBackLayer( GetLayer() ) );
  244. else
  245. SetMirrored( IsBackLayer( GetLayer() ) );
  246. }
  247. void PCB_TEXT::KeepUpright()
  248. {
  249. if( !IsKeepUpright() )
  250. return;
  251. EDA_ANGLE newAngle = GetTextAngle();
  252. newAngle.Normalize();
  253. bool needsFlipped = newAngle >= ANGLE_180;
  254. if( needsFlipped )
  255. {
  256. SetHorizJustify( static_cast<GR_TEXT_H_ALIGN_T>( -GetHorizJustify() ) );
  257. SetVertJustify( static_cast<GR_TEXT_V_ALIGN_T>( -GetVertJustify() ) );
  258. newAngle += ANGLE_180;
  259. newAngle.Normalize();
  260. SetTextAngle( newAngle );
  261. }
  262. }
  263. const BOX2I PCB_TEXT::GetBoundingBox() const
  264. {
  265. EDA_ANGLE angle = GetDrawRotation();
  266. BOX2I rect = GetTextBox( nullptr );
  267. if( IsKnockout() )
  268. rect.Inflate( getKnockoutMargin() );
  269. if( !angle.IsZero() )
  270. rect = rect.GetBoundingBoxRotated( GetTextPos(), angle );
  271. return rect;
  272. }
  273. bool PCB_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
  274. {
  275. int accuracy = aAccuracy;
  276. if( IsKnockout() )
  277. accuracy += GetKnockoutTextMargin( GetTextSize(), GetEffectiveTextPenWidth() );
  278. return EDA_TEXT::TextHitTest( aPoint, accuracy );
  279. }
  280. bool PCB_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
  281. {
  282. BOX2I rect = aRect;
  283. rect.Inflate( aAccuracy );
  284. if( aContains )
  285. return rect.Contains( GetBoundingBox() );
  286. return rect.Intersects( GetBoundingBox() );
  287. }
  288. bool PCB_TEXT::TextHitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
  289. {
  290. BOX2I rect = GetTextBox( nullptr );
  291. if( IsKnockout() )
  292. rect.Inflate( getKnockoutMargin() );
  293. return KIGEOM::BoxHitTest( aPoly, rect, GetDrawRotation(), GetDrawPos(), aContained );
  294. }
  295. void PCB_TEXT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
  296. {
  297. VECTOR2I pt = GetTextPos();
  298. RotatePoint( pt, aRotCentre, aAngle );
  299. SetTextPos( pt );
  300. EDA_ANGLE new_angle = GetTextAngle() + aAngle;
  301. new_angle.Normalize();
  302. SetTextAngle( new_angle );
  303. }
  304. void PCB_TEXT::Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
  305. {
  306. // the position and justification are mirrored, but not the text itself
  307. if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
  308. {
  309. if( GetTextAngle() == ANGLE_VERTICAL )
  310. SetHorizJustify( (GR_TEXT_H_ALIGN_T) -GetHorizJustify() );
  311. SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) );
  312. }
  313. else
  314. {
  315. if( GetTextAngle() == ANGLE_HORIZONTAL )
  316. SetHorizJustify( (GR_TEXT_H_ALIGN_T) -GetHorizJustify() );
  317. SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) );
  318. }
  319. }
  320. void PCB_TEXT::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
  321. {
  322. if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
  323. {
  324. SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) );
  325. SetTextAngle( -GetTextAngle() );
  326. }
  327. else
  328. {
  329. SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) );
  330. SetTextAngle( ANGLE_180 - GetTextAngle() );
  331. }
  332. SetLayer( GetBoard()->FlipLayer( GetLayer() ) );
  333. if( IsSideSpecific() )
  334. SetMirrored( !IsMirrored() );
  335. }
  336. wxString PCB_TEXT::GetTextTypeDescription() const
  337. {
  338. return _( "Text" );
  339. }
  340. wxString PCB_TEXT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
  341. {
  342. wxString content = aFull ? GetShownText( false ) : KIUI::EllipsizeMenuText( GetText() );
  343. if( FOOTPRINT* parentFP = GetParentFootprint() )
  344. {
  345. wxString ref = parentFP->GetReference();
  346. return wxString::Format( _( "Footprint text of %s (%s)" ), ref, content );
  347. }
  348. return wxString::Format( _( "PCB text '%s' on %s" ), content, GetLayerName() );
  349. }
  350. BITMAPS PCB_TEXT::GetMenuImage() const
  351. {
  352. return BITMAPS::text;
  353. }
  354. EDA_ITEM* PCB_TEXT::Clone() const
  355. {
  356. return new PCB_TEXT( *this );
  357. }
  358. void PCB_TEXT::swapData( BOARD_ITEM* aImage )
  359. {
  360. assert( aImage->Type() == PCB_TEXT_T );
  361. std::swap( *((PCB_TEXT*) this), *((PCB_TEXT*) aImage) );
  362. }
  363. std::shared_ptr<SHAPE> PCB_TEXT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
  364. {
  365. if( IsKnockout() )
  366. {
  367. SHAPE_POLY_SET poly;
  368. TransformTextToPolySet( poly, 0, GetMaxError(), ERROR_INSIDE );
  369. return std::make_shared<SHAPE_POLY_SET>( std::move( poly ) );
  370. }
  371. return GetEffectiveTextShape();
  372. }
  373. SHAPE_POLY_SET PCB_TEXT::GetKnockoutCache( const KIFONT::FONT* aFont, const wxString& forResolvedText,
  374. int aMaxError ) const
  375. {
  376. TEXT_ATTRIBUTES attrs = GetAttributes();
  377. EDA_ANGLE drawAngle = GetDrawRotation();
  378. VECTOR2I drawPos = GetDrawPos();
  379. if( m_knockout_cache.IsEmpty()
  380. || m_knockout_cache_text_attrs != attrs
  381. || m_knockout_cache_text != forResolvedText
  382. || m_knockout_cache_angle != drawAngle )
  383. {
  384. m_knockout_cache.RemoveAllContours();
  385. TransformTextToPolySet( m_knockout_cache, 0, aMaxError, ERROR_INSIDE );
  386. m_knockout_cache.Fracture();
  387. m_knockout_cache_text_attrs = attrs;
  388. m_knockout_cache_angle = drawAngle;
  389. m_knockout_cache_text = forResolvedText;
  390. m_knockout_cache_pos = drawPos;
  391. }
  392. else if( m_knockout_cache_pos != drawPos )
  393. {
  394. m_knockout_cache.Move( drawPos - m_knockout_cache_pos );
  395. m_knockout_cache_pos = drawPos;
  396. }
  397. return m_knockout_cache;
  398. }
  399. void PCB_TEXT::buildBoundingHull( SHAPE_POLY_SET* aBuffer, const SHAPE_POLY_SET& aRenderedText,
  400. int aClearance ) const
  401. {
  402. SHAPE_POLY_SET poly( aRenderedText );
  403. poly.Rotate( -GetDrawRotation(), GetDrawPos() );
  404. BOX2I rect = poly.BBox( aClearance );
  405. VECTOR2I corners[4];
  406. corners[0].x = rect.GetOrigin().x;
  407. corners[0].y = rect.GetOrigin().y;
  408. corners[1].y = corners[0].y;
  409. corners[1].x = rect.GetRight();
  410. corners[2].x = corners[1].x;
  411. corners[2].y = rect.GetBottom();
  412. corners[3].y = corners[2].y;
  413. corners[3].x = corners[0].x;
  414. aBuffer->NewOutline();
  415. for( VECTOR2I& corner : corners )
  416. {
  417. RotatePoint( corner, GetDrawPos(), GetDrawRotation() );
  418. aBuffer->Append( corner.x, corner.y );
  419. }
  420. }
  421. void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, int aMaxError,
  422. ERROR_LOC aErrorLoc ) const
  423. {
  424. KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
  425. KIFONT::FONT* font = GetDrawFont( nullptr );
  426. int penWidth = GetEffectiveTextPenWidth();
  427. TEXT_ATTRIBUTES attrs = GetAttributes();
  428. wxString shownText = GetShownText( true );
  429. attrs.m_Angle = GetDrawRotation();
  430. // The polygonal shape of a text can have many basic shapes, so combining these shapes can
  431. // be very useful to create a final shape with a lot less vertices to speedup calculations.
  432. // Simplify shapes is not usually always efficient, but in this case it is.
  433. SHAPE_POLY_SET textShape;
  434. CALLBACK_GAL callback_gal( empty_opts,
  435. // Stroke callback
  436. [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
  437. {
  438. TransformOvalToPolygon( textShape, aPt1, aPt2, penWidth, aMaxError, aErrorLoc );
  439. },
  440. // Triangulation callback
  441. [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
  442. {
  443. textShape.NewOutline();
  444. for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
  445. textShape.Append( point.x, point.y );
  446. } );
  447. if( auto* cache = GetRenderCache( font, shownText ) )
  448. callback_gal.DrawGlyphs( *cache );
  449. else
  450. font->Draw( &callback_gal, shownText, GetTextPos(), attrs, GetFontMetrics() );
  451. textShape.Simplify();
  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 );
  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( "Keep Upright" ), isFootprintText );
  523. propMgr.Mask( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
  524. }
  525. } _PCB_TEXT_DESC;