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.

711 lines
22 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <advanced_config.h>
  24. #include <base_units.h>
  25. #include <pgm_base.h>
  26. #include <sch_edit_frame.h>
  27. #include <plotters/plotter.h>
  28. #include <widgets/msgpanel.h>
  29. #include <bitmaps.h>
  30. #include <string_utils.h>
  31. #include <schematic.h>
  32. #include <settings/color_settings.h>
  33. #include <sch_painter.h>
  34. #include <wx/log.h>
  35. #include <dialogs/html_message_box.h>
  36. #include <project/project_file.h>
  37. #include <trigo.h>
  38. #include <sch_textbox.h>
  39. #include <tools/sch_navigate_tool.h>
  40. SCH_TEXTBOX::SCH_TEXTBOX( SCH_LAYER_ID aLayer, int aLineWidth, FILL_T aFillType,
  41. const wxString& aText, KICAD_T aType ) :
  42. SCH_SHAPE( SHAPE_T::RECTANGLE, aLayer, aLineWidth, aFillType, aType ),
  43. EDA_TEXT( schIUScale, aText )
  44. {
  45. m_layer = aLayer;
  46. SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
  47. SetVertJustify( GR_TEXT_V_ALIGN_TOP );
  48. SetMultilineAllowed( true );
  49. m_excludedFromSim = false;
  50. int defaultMargin = GetLegacyTextMargin();
  51. m_marginLeft = defaultMargin;
  52. m_marginTop = defaultMargin;
  53. m_marginRight = defaultMargin;
  54. m_marginBottom = defaultMargin;
  55. }
  56. SCH_TEXTBOX::SCH_TEXTBOX( const SCH_TEXTBOX& aText ) :
  57. SCH_SHAPE( aText ),
  58. EDA_TEXT( aText )
  59. {
  60. m_excludedFromSim = aText.m_excludedFromSim;
  61. m_marginLeft = aText.m_marginLeft;
  62. m_marginTop = aText.m_marginTop;
  63. m_marginRight = aText.m_marginRight;
  64. m_marginBottom = aText.m_marginBottom;
  65. }
  66. int SCH_TEXTBOX::GetLegacyTextMargin() const
  67. {
  68. if( m_layer == LAYER_DEVICE )
  69. return KiROUND( GetTextSize().y * 0.8 );
  70. else
  71. return KiROUND( GetStroke().GetWidth() / 2.0 ) + KiROUND( GetTextSize().y * 0.75 );
  72. }
  73. void SCH_TEXTBOX::MirrorHorizontally( int aCenter )
  74. {
  75. SCH_SHAPE::MirrorHorizontally( aCenter );
  76. // Text is NOT really mirrored; it just has its justification flipped
  77. if( GetTextAngle() == ANGLE_HORIZONTAL )
  78. {
  79. if( GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT )
  80. SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
  81. else if( GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
  82. SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
  83. }
  84. }
  85. void SCH_TEXTBOX::MirrorVertically( int aCenter )
  86. {
  87. SCH_SHAPE::MirrorVertically( aCenter );
  88. // Text is NOT really mirrored; it just has its justification flipped
  89. if( GetTextAngle() == ANGLE_VERTICAL )
  90. {
  91. if( GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT )
  92. SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
  93. else if( GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
  94. SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
  95. }
  96. }
  97. void SCH_TEXTBOX::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
  98. {
  99. SCH_SHAPE::Rotate( aCenter, aRotateCCW );
  100. SetTextAngle( GetTextAngle() == ANGLE_VERTICAL ? ANGLE_HORIZONTAL : ANGLE_VERTICAL );
  101. }
  102. void SCH_TEXTBOX::Rotate90( bool aClockwise )
  103. {
  104. SetTextAngle( GetTextAngle() == ANGLE_VERTICAL ? ANGLE_HORIZONTAL : ANGLE_VERTICAL );
  105. }
  106. VECTOR2I SCH_TEXTBOX::GetDrawPos() const
  107. {
  108. BOX2I bbox = BOX2I( m_start, m_end - m_start );
  109. bbox.Normalize();
  110. VECTOR2I pos( bbox.GetLeft() + m_marginLeft, bbox.GetBottom() - m_marginBottom );
  111. if( GetTextAngle().IsVertical() )
  112. {
  113. switch( GetHorizJustify() )
  114. {
  115. case GR_TEXT_H_ALIGN_LEFT:
  116. pos.y = bbox.GetBottom() - m_marginBottom;
  117. break;
  118. case GR_TEXT_H_ALIGN_CENTER:
  119. pos.y = ( bbox.GetTop() + bbox.GetBottom() ) / 2;
  120. break;
  121. case GR_TEXT_H_ALIGN_RIGHT:
  122. pos.y = bbox.GetTop() + m_marginTop;
  123. break;
  124. case GR_TEXT_H_ALIGN_INDETERMINATE:
  125. wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
  126. break;
  127. }
  128. switch( GetVertJustify() )
  129. {
  130. case GR_TEXT_V_ALIGN_TOP:
  131. pos.x = bbox.GetLeft() + m_marginLeft;
  132. break;
  133. case GR_TEXT_V_ALIGN_CENTER:
  134. pos.x = ( bbox.GetLeft() + bbox.GetRight() ) / 2;
  135. break;
  136. case GR_TEXT_V_ALIGN_BOTTOM:
  137. pos.x = bbox.GetRight() - m_marginRight;
  138. break;
  139. case GR_TEXT_V_ALIGN_INDETERMINATE:
  140. wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
  141. break;
  142. }
  143. }
  144. else
  145. {
  146. switch( GetHorizJustify() )
  147. {
  148. case GR_TEXT_H_ALIGN_LEFT:
  149. pos.x = bbox.GetLeft() + m_marginLeft;
  150. break;
  151. case GR_TEXT_H_ALIGN_CENTER:
  152. pos.x = ( bbox.GetLeft() + bbox.GetRight() ) / 2;
  153. break;
  154. case GR_TEXT_H_ALIGN_RIGHT:
  155. pos.x = bbox.GetRight() - m_marginRight;
  156. break;
  157. case GR_TEXT_H_ALIGN_INDETERMINATE:
  158. wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
  159. break;
  160. }
  161. switch( GetVertJustify() )
  162. {
  163. case GR_TEXT_V_ALIGN_TOP:
  164. pos.y = bbox.GetTop() + m_marginTop;
  165. break;
  166. case GR_TEXT_V_ALIGN_CENTER:
  167. pos.y = ( bbox.GetTop() + bbox.GetBottom() ) / 2;
  168. break;
  169. case GR_TEXT_V_ALIGN_BOTTOM:
  170. pos.y = bbox.GetBottom() - m_marginBottom;
  171. break;
  172. case GR_TEXT_V_ALIGN_INDETERMINATE:
  173. wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
  174. break;
  175. }
  176. }
  177. return pos;
  178. }
  179. void SCH_TEXTBOX::SwapData( SCH_ITEM* aItem )
  180. {
  181. SCH_SHAPE::SwapData( aItem );
  182. SCH_TEXTBOX* item = static_cast<SCH_TEXTBOX*>( aItem );
  183. std::swap( m_layer, item->m_layer );
  184. std::swap( m_marginLeft, item->m_marginLeft );
  185. std::swap( m_marginTop, item->m_marginTop );
  186. std::swap( m_marginRight, item->m_marginRight );
  187. std::swap( m_marginBottom, item->m_marginBottom );
  188. SwapText( *item );
  189. SwapAttributes( *item );
  190. }
  191. bool SCH_TEXTBOX::operator<( const SCH_ITEM& aItem ) const
  192. {
  193. if( Type() != aItem.Type() )
  194. return Type() < aItem.Type();
  195. auto other = static_cast<const SCH_TEXTBOX*>( &aItem );
  196. if( GetLayer() != other->GetLayer() )
  197. return GetLayer() < other->GetLayer();
  198. if( GetPosition().x != other->GetPosition().x )
  199. return GetPosition().x < other->GetPosition().x;
  200. if( GetPosition().y != other->GetPosition().y )
  201. return GetPosition().y < other->GetPosition().y;
  202. if( GetMarginLeft() != other->GetMarginLeft() )
  203. return GetMarginLeft() < other->GetMarginLeft();
  204. if( GetMarginTop() != other->GetMarginTop() )
  205. return GetMarginTop() < other->GetMarginTop();
  206. if( GetMarginRight() != other->GetMarginRight() )
  207. return GetMarginRight() < other->GetMarginRight();
  208. if( GetMarginBottom() != other->GetMarginBottom() )
  209. return GetMarginBottom() < other->GetMarginBottom();
  210. if( GetExcludedFromSim() != other->GetExcludedFromSim() )
  211. return GetExcludedFromSim() - other->GetExcludedFromSim();
  212. return GetText() < other->GetText();
  213. }
  214. KIFONT::FONT* SCH_TEXTBOX::GetDrawFont( const RENDER_SETTINGS* aSettings ) const
  215. {
  216. KIFONT::FONT* font = EDA_TEXT::GetFont();
  217. if( !font )
  218. font = KIFONT::FONT::GetFont( GetDefaultFont( aSettings ), IsBold(), IsItalic() );
  219. return font;
  220. }
  221. void SCH_TEXTBOX::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
  222. const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
  223. {
  224. if( IsPrivate() )
  225. return;
  226. wxDC* DC = aSettings->GetPrintDC();
  227. int penWidth = GetEffectivePenWidth( aSettings );
  228. bool blackAndWhiteMode = GetGRForceBlackPenState();
  229. VECTOR2I pt1 = GetStart();
  230. VECTOR2I pt2 = GetEnd();
  231. COLOR4D color = GetStroke().GetColor();
  232. COLOR4D bg = aSettings->GetBackgroundColor();
  233. LINE_STYLE lineStyle = GetStroke().GetLineStyle();
  234. if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
  235. bg = COLOR4D::WHITE;
  236. if( GetFillMode() == FILL_T::FILLED_WITH_COLOR && !blackAndWhiteMode && !aForceNoFill )
  237. GRFilledRect( DC, pt1, pt2, 0, GetFillColor(), GetFillColor() );
  238. if( penWidth > 0 )
  239. {
  240. penWidth = std::max( penWidth, aSettings->GetMinPenWidth() );
  241. if( blackAndWhiteMode || color == COLOR4D::UNSPECIFIED )
  242. color = aSettings->GetLayerColor( m_layer );
  243. if( aDimmed )
  244. {
  245. color.Desaturate( );
  246. color = color.Mix( bg, 0.5f );
  247. }
  248. if( lineStyle == LINE_STYLE::DEFAULT )
  249. lineStyle = LINE_STYLE::SOLID;
  250. if( lineStyle == LINE_STYLE::SOLID )
  251. {
  252. GRRect( DC, pt1, pt2, penWidth, color );
  253. }
  254. else
  255. {
  256. std::vector<SHAPE*> shapes = MakeEffectiveShapes( true );
  257. for( SHAPE* shape : shapes )
  258. {
  259. STROKE_PARAMS::Stroke( shape, lineStyle, penWidth, aSettings,
  260. [&]( const VECTOR2I& a, const VECTOR2I& b )
  261. {
  262. VECTOR2I ptA = aSettings->TransformCoordinate( a ) + aOffset;
  263. VECTOR2I ptB = aSettings->TransformCoordinate( b ) + aOffset;
  264. GRLine( DC, ptA.x, ptA.y, ptB.x, ptB.y, penWidth, color );
  265. } );
  266. }
  267. for( SHAPE* shape : shapes )
  268. delete shape;
  269. }
  270. }
  271. color = GetTextColor();
  272. if( blackAndWhiteMode || color == COLOR4D::UNSPECIFIED )
  273. color = aSettings->GetLayerColor( m_layer );
  274. if( aDimmed )
  275. {
  276. color.Desaturate( );
  277. color = color.Mix( bg, 0.5f );
  278. }
  279. EDA_TEXT::Print( aSettings, aOffset, color );
  280. }
  281. wxString SCH_TEXTBOX::GetShownText( const RENDER_SETTINGS* aSettings, const SCH_SHEET_PATH* aPath,
  282. bool aAllowExtraText, int aDepth ) const
  283. {
  284. SCH_SHEET* sheet = nullptr;
  285. if( aPath )
  286. sheet = aPath->Last();
  287. std::function<bool( wxString* )> textResolver =
  288. [&]( wxString* token ) -> bool
  289. {
  290. if( sheet )
  291. {
  292. if( sheet->ResolveTextVar( aPath, token, aDepth + 1 ) )
  293. return true;
  294. }
  295. return false;
  296. };
  297. wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
  298. if( HasTextVars() )
  299. {
  300. if( aDepth < ADVANCED_CFG::GetCfg().m_ResolveTextRecursionDepth )
  301. text = ExpandTextVars( text, &textResolver );
  302. }
  303. VECTOR2I size = GetEnd() - GetStart();
  304. int colWidth;
  305. if( GetTextAngle().IsVertical() )
  306. colWidth = abs( size.y ) - ( GetMarginTop() + GetMarginBottom() );
  307. else
  308. colWidth = abs( size.x ) - ( GetMarginLeft() + GetMarginRight() );
  309. GetDrawFont( aSettings )->LinebreakText( text, colWidth, GetTextSize(), GetEffectiveTextPenWidth(),
  310. IsBold(), IsItalic() );
  311. return text;
  312. }
  313. bool SCH_TEXTBOX::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
  314. {
  315. BOX2I rect = GetBoundingBox();
  316. rect.Inflate( aAccuracy );
  317. return rect.Contains( aPosition );
  318. }
  319. bool SCH_TEXTBOX::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
  320. {
  321. BOX2I rect = aRect;
  322. rect.Inflate( aAccuracy );
  323. if( aContained )
  324. return rect.Contains( GetBoundingBox() );
  325. return rect.Intersects( GetBoundingBox() );
  326. }
  327. bool SCH_TEXTBOX::IsHypertext() const
  328. {
  329. if( HasHyperlink() )
  330. return true;
  331. return IsURL( GetShownText( false ) );
  332. }
  333. void SCH_TEXTBOX::DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const
  334. {
  335. wxCHECK_MSG( IsHypertext(), /* void */,
  336. wxT( "Calling a hypertext menu on a SCH_TEXTBOX with no hyperlink?" ) );
  337. SCH_NAVIGATE_TOOL* navTool = aFrame->GetToolManager()->GetTool<SCH_NAVIGATE_TOOL>();
  338. if( HasHyperlink() )
  339. navTool->HypertextCommand( m_hyperlink );
  340. else
  341. navTool->HypertextCommand( GetShownText( false ) );
  342. }
  343. wxString SCH_TEXTBOX::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
  344. {
  345. return wxString::Format( _( "Text Box" ) );
  346. }
  347. BITMAPS SCH_TEXTBOX::GetMenuImage() const
  348. {
  349. return BITMAPS::add_textbox;
  350. }
  351. void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
  352. int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
  353. {
  354. if( IsPrivate() )
  355. return;
  356. SCH_SHAPE::Plot( aPlotter, aBackground, aPlotOpts, aUnit, aBodyStyle, aOffset, aDimmed );
  357. if( aBackground )
  358. return;
  359. SCH_SHEET_PATH* sheet = Schematic() ? &Schematic()->CurrentSheet() : nullptr;
  360. SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
  361. int penWidth = GetEffectivePenWidth( renderSettings );
  362. COLOR4D color = GetStroke().GetColor();
  363. COLOR4D bg = renderSettings->GetBackgroundColor();
  364. KIFONT::FONT* font = GetDrawFont( renderSettings );
  365. color = GetTextColor();
  366. if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
  367. color = renderSettings->GetLayerColor( m_layer );
  368. if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
  369. bg = COLOR4D::WHITE;
  370. if( aDimmed )
  371. {
  372. color.Desaturate( );
  373. color = color.Mix( bg, 0.5f );
  374. }
  375. penWidth = GetEffectiveTextPenWidth( renderSettings->GetDefaultPenWidth() );
  376. penWidth = std::max( penWidth, renderSettings->GetMinPenWidth() );
  377. aPlotter->SetCurrentLineWidth( penWidth );
  378. TEXT_ATTRIBUTES attrs;
  379. std::vector<VECTOR2I> positions;
  380. wxArrayString strings_list;
  381. wxStringSplit( GetShownText( renderSettings, sheet, true ), strings_list, '\n' );
  382. positions.reserve( strings_list.Count() );
  383. if( renderSettings->m_Transform != TRANSFORM() || aOffset != VECTOR2I() )
  384. {
  385. SCH_TEXTBOX temp( *this );
  386. if( renderSettings->m_Transform.y1 )
  387. {
  388. temp.SetTextAngle( temp.GetTextAngle() == ANGLE_HORIZONTAL ? ANGLE_VERTICAL
  389. : ANGLE_HORIZONTAL );
  390. }
  391. temp.SetStart( renderSettings->TransformCoordinate( m_start ) + aOffset );
  392. temp.SetEnd( renderSettings->TransformCoordinate( m_end ) + aOffset );
  393. attrs = temp.GetAttributes();
  394. temp.GetLinePositions( renderSettings, positions, (int) strings_list.Count() );
  395. }
  396. else
  397. {
  398. attrs = GetAttributes();
  399. GetLinePositions( renderSettings, positions, (int) strings_list.Count() );
  400. }
  401. attrs.m_StrokeWidth = penWidth;
  402. attrs.m_Multiline = false;
  403. for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
  404. {
  405. aPlotter->PlotText( positions[ii], color, strings_list.Item( ii ), attrs, font,
  406. GetFontMetrics() );
  407. }
  408. if( HasHyperlink() )
  409. aPlotter->HyperlinkBox( GetBoundingBox(), GetHyperlink() );
  410. }
  411. void SCH_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  412. {
  413. // Don't use GetShownText() here; we want to show the user the variable references
  414. aList.emplace_back( _( "Text Box" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
  415. if( m_excludedFromSim )
  416. aList.emplace_back( _( "Exclude from" ), _( "Simulation" ) );
  417. aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
  418. wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
  419. int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0;
  420. aList.emplace_back( _( "Style" ), textStyle[style] );
  421. aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
  422. aList.emplace_back( _( "Box Width" ),
  423. aFrame->MessageTextFromValue( std::abs( GetEnd().x - GetStart().x ) ) );
  424. aList.emplace_back( _( "Box Height" ),
  425. aFrame->MessageTextFromValue( std::abs( GetEnd().y - GetStart().y ) ) );
  426. m_stroke.GetMsgPanelInfo( aFrame, aList );
  427. }
  428. bool SCH_TEXTBOX::operator==( const SCH_ITEM& aOther ) const
  429. {
  430. if( Type() != aOther.Type() )
  431. return false;
  432. const SCH_TEXTBOX& other = static_cast<const SCH_TEXTBOX&>( aOther );
  433. if( m_excludedFromSim != other.m_excludedFromSim )
  434. return false;
  435. if( GetMarginLeft() != other.GetMarginLeft() )
  436. return false;
  437. if( GetMarginTop() != other.GetMarginTop() )
  438. return false;
  439. if( GetMarginRight() != other.GetMarginRight() )
  440. return false;
  441. if( GetMarginBottom() != other.GetMarginBottom() )
  442. return false;
  443. return SCH_SHAPE::operator==( aOther ) && EDA_TEXT::operator==( other );
  444. }
  445. double SCH_TEXTBOX::Similarity( const SCH_ITEM& aOther ) const
  446. {
  447. if( m_Uuid == aOther.m_Uuid )
  448. return 1.0;
  449. if( aOther.Type() != Type() )
  450. return 0.0;
  451. auto other = static_cast<const SCH_TEXTBOX&>( aOther );
  452. double similarity = SimilarityBase( other );
  453. if( m_excludedFromSim != other.m_excludedFromSim )
  454. similarity *= 0.9;
  455. if( GetMarginLeft() != other.GetMarginLeft() )
  456. similarity *= 0.9;
  457. if( GetMarginTop() != other.GetMarginTop() )
  458. similarity *= 0.9;
  459. if( GetMarginRight() != other.GetMarginRight() )
  460. similarity *= 0.9;
  461. if( GetMarginBottom() != other.GetMarginBottom() )
  462. similarity *= 0.9;
  463. similarity *= SCH_SHAPE::Similarity( aOther );
  464. similarity *= EDA_TEXT::Similarity( other );
  465. return similarity;
  466. }
  467. int SCH_TEXTBOX::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
  468. {
  469. wxASSERT( aOther.Type() == SCH_TEXTBOX_T );
  470. int retv = SCH_SHAPE::compare( aOther, aCompareFlags );
  471. if( retv )
  472. return retv;
  473. const SCH_TEXTBOX* tmp = static_cast<const SCH_TEXTBOX*>( &aOther );
  474. int result = GetText().CmpNoCase( tmp->GetText() );
  475. if( result != 0 )
  476. return result;
  477. if( GetTextWidth() != tmp->GetTextWidth() )
  478. return GetTextWidth() - tmp->GetTextWidth();
  479. if( GetTextHeight() != tmp->GetTextHeight() )
  480. return GetTextHeight() - tmp->GetTextHeight();
  481. if( IsBold() != tmp->IsBold() )
  482. return IsBold() - tmp->IsBold();
  483. if( IsItalic() != tmp->IsItalic() )
  484. return IsItalic() - tmp->IsItalic();
  485. if( GetHorizJustify() != tmp->GetHorizJustify() )
  486. return GetHorizJustify() - tmp->GetHorizJustify();
  487. if( GetTextAngle().AsTenthsOfADegree() != tmp->GetTextAngle().AsTenthsOfADegree() )
  488. return GetTextAngle().AsTenthsOfADegree() - tmp->GetTextAngle().AsTenthsOfADegree();
  489. if( GetMarginLeft() != tmp->GetMarginLeft() )
  490. return GetMarginLeft() - tmp->GetMarginLeft();
  491. if( GetMarginTop() != tmp->GetMarginTop() )
  492. return GetMarginTop() - tmp->GetMarginTop();
  493. if( GetMarginRight() != tmp->GetMarginRight() )
  494. return GetMarginRight() - tmp->GetMarginRight();
  495. if( GetMarginBottom() != tmp->GetMarginBottom() )
  496. return GetMarginBottom() - tmp->GetMarginBottom();
  497. return 0;
  498. }
  499. static struct SCH_TEXTBOX_DESC
  500. {
  501. SCH_TEXTBOX_DESC()
  502. {
  503. PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
  504. REGISTER_TYPE( SCH_TEXTBOX );
  505. propMgr.AddTypeCast( new TYPE_CAST<SCH_TEXTBOX, SCH_SHAPE> );
  506. propMgr.AddTypeCast( new TYPE_CAST<SCH_TEXTBOX, EDA_SHAPE> );
  507. propMgr.AddTypeCast( new TYPE_CAST<SCH_TEXTBOX, EDA_TEXT> );
  508. propMgr.InheritsAfter( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( SCH_SHAPE ) );
  509. propMgr.InheritsAfter( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( EDA_SHAPE ) );
  510. propMgr.InheritsAfter( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( EDA_TEXT ) );
  511. propMgr.Mask( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Shape" ) );
  512. propMgr.Mask( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
  513. propMgr.Mask( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
  514. propMgr.Mask( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
  515. const wxString marginProps = _( "Margins" );
  516. propMgr.AddProperty( new PROPERTY<SCH_TEXTBOX, int>( _HKI( "Margin Left" ),
  517. &SCH_TEXTBOX::SetMarginLeft, &SCH_TEXTBOX::GetMarginLeft,
  518. PROPERTY_DISPLAY::PT_SIZE ),
  519. marginProps );
  520. propMgr.AddProperty( new PROPERTY<SCH_TEXTBOX, int>( _HKI( "Margin Top" ),
  521. &SCH_TEXTBOX::SetMarginTop, &SCH_TEXTBOX::GetMarginTop,
  522. PROPERTY_DISPLAY::PT_SIZE ),
  523. marginProps );
  524. propMgr.AddProperty( new PROPERTY<SCH_TEXTBOX, int>( _HKI( "Margin Right" ),
  525. &SCH_TEXTBOX::SetMarginRight, &SCH_TEXTBOX::GetMarginRight,
  526. PROPERTY_DISPLAY::PT_SIZE ),
  527. marginProps );
  528. propMgr.AddProperty( new PROPERTY<SCH_TEXTBOX, int>( _HKI( "Margin Bottom" ),
  529. &SCH_TEXTBOX::SetMarginBottom, &SCH_TEXTBOX::GetMarginBottom,
  530. PROPERTY_DISPLAY::PT_SIZE ),
  531. marginProps );
  532. propMgr.AddProperty( new PROPERTY<SCH_TEXTBOX, int>( _HKI( "Text Size" ),
  533. &SCH_TEXTBOX::SetSchTextSize, &SCH_TEXTBOX::GetSchTextSize,
  534. PROPERTY_DISPLAY::PT_SIZE ),
  535. _HKI( "Text Properties" ) );
  536. propMgr.Mask( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
  537. }
  538. } _SCH_TEXTBOX_DESC;