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.

203 lines
5.7 KiB

14 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-2015 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. /**
  26. * @file class_pcb_text.cpp
  27. * @brief Class TEXTE_PCB texts on copper or technical layers implementation
  28. */
  29. #include <fctsys.h>
  30. #include <gr_basic.h>
  31. #include <base_struct.h>
  32. #include <draw_graphic_text.h>
  33. #include <kicad_string.h>
  34. #include <trigo.h>
  35. #include <richio.h>
  36. #include <class_drawpanel.h>
  37. #include <macros.h>
  38. #include <pcb_edit_frame.h>
  39. #include <msgpanel.h>
  40. #include <base_units.h>
  41. #include <bitmaps.h>
  42. #include <class_board.h>
  43. #include <class_pcb_text.h>
  44. TEXTE_PCB::TEXTE_PCB( BOARD_ITEM* parent ) :
  45. BOARD_ITEM( parent, PCB_TEXT_T ),
  46. EDA_TEXT()
  47. {
  48. SetMultilineAllowed( true );
  49. }
  50. TEXTE_PCB::~TEXTE_PCB()
  51. {
  52. }
  53. void TEXTE_PCB::SetTextAngle( double aAngle )
  54. {
  55. EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) );
  56. }
  57. void TEXTE_PCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
  58. GR_DRAWMODE DrawMode, const wxPoint& offset )
  59. {
  60. wxASSERT( panel );
  61. if( !panel )
  62. return;
  63. BOARD* brd = GetBoard();
  64. if( brd->IsLayerVisible( m_Layer ) == false )
  65. return;
  66. auto frame = static_cast<PCB_EDIT_FRAME*>( panel->GetParent() );
  67. auto color = frame->Settings().Colors().GetLayerColor( m_Layer );
  68. EDA_DRAW_MODE_T fillmode = FILLED;
  69. PCB_DISPLAY_OPTIONS* displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
  70. if( displ_opts && displ_opts->m_DisplayDrawItemsFill == SKETCH )
  71. fillmode = SKETCH;
  72. // shade text if high contrast mode is active
  73. if( ( DrawMode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && displ_opts->m_ContrastModeDisplay )
  74. {
  75. PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
  76. if( !IsOnLayer( curr_layer ) )
  77. color = COLOR4D( DARKDARKGRAY );
  78. }
  79. COLOR4D anchor_color = COLOR4D::UNSPECIFIED;
  80. if( brd->IsElementVisible( LAYER_ANCHOR ) )
  81. anchor_color = frame->Settings().Colors().GetItemColor( LAYER_ANCHOR );
  82. EDA_TEXT::Draw( panel->GetClipBox(), DC, offset, color,
  83. DrawMode, fillmode, anchor_color );
  84. // Enable these line to draw the bounding box (debug tests purposes only)
  85. #if 0
  86. {
  87. EDA_RECT BoundaryBox = GetBoundingBox();
  88. GRRect( clipbox, DC, BoundaryBox, 0, BROWN );
  89. }
  90. #endif
  91. }
  92. void TEXTE_PCB::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
  93. {
  94. wxString msg;
  95. wxCHECK_RET( m_Parent != NULL, wxT( "TEXTE_PCB::GetMsgPanelInfo() m_Parent is NULL." ) );
  96. if( m_Parent->Type() == PCB_DIMENSION_T )
  97. aList.push_back( MSG_PANEL_ITEM( _( "Dimension" ), GetShownText(), DARKGREEN ) );
  98. else
  99. aList.push_back( MSG_PANEL_ITEM( _( "PCB Text" ), GetShownText(), DARKGREEN ) );
  100. aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), BLUE ) );
  101. if( !IsMirrored() )
  102. aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "No" ), DARKGREEN ) );
  103. else
  104. aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "Yes" ), DARKGREEN ) );
  105. msg.Printf( wxT( "%.1f" ), GetTextAngle() / 10.0 );
  106. aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, DARKGREEN ) );
  107. msg = MessageTextFromValue( aUnits, GetThickness() );
  108. aList.push_back( MSG_PANEL_ITEM( _( "Thickness" ), msg, MAGENTA ) );
  109. msg = MessageTextFromValue( aUnits, GetTextWidth() );
  110. aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, RED ) );
  111. msg = MessageTextFromValue( aUnits, GetTextHeight() );
  112. aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, RED ) );
  113. }
  114. const EDA_RECT TEXTE_PCB::GetBoundingBox() const
  115. {
  116. EDA_RECT rect = GetTextBox( -1, -1 );
  117. if( GetTextAngle() )
  118. rect = rect.GetBoundingBoxRotated( GetTextPos(), GetTextAngle() );
  119. return rect;
  120. }
  121. void TEXTE_PCB::Rotate( const wxPoint& aRotCentre, double aAngle )
  122. {
  123. wxPoint pt = GetTextPos();
  124. RotatePoint( &pt, aRotCentre, aAngle );
  125. SetTextPos( pt );
  126. SetTextAngle( GetTextAngle() + aAngle );
  127. }
  128. void TEXTE_PCB::Flip( const wxPoint& aCentre )
  129. {
  130. SetTextY( aCentre.y - ( GetTextPos().y - aCentre.y ) );
  131. int copperLayerCount = GetBoard()->GetCopperLayerCount();
  132. SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
  133. SetMirrored( !IsMirrored() );
  134. }
  135. wxString TEXTE_PCB::GetSelectMenuText( EDA_UNITS_T aUnits ) const
  136. {
  137. return wxString::Format( _( "Pcb Text \"%s\" on %s"), ShortenedShownText(), GetLayerName() );
  138. }
  139. BITMAP_DEF TEXTE_PCB::GetMenuImage() const
  140. {
  141. return text_xpm;
  142. }
  143. EDA_ITEM* TEXTE_PCB::Clone() const
  144. {
  145. return new TEXTE_PCB( *this );
  146. }
  147. void TEXTE_PCB::SwapData( BOARD_ITEM* aImage )
  148. {
  149. assert( aImage->Type() == PCB_TEXT_T );
  150. std::swap( *((TEXTE_PCB*) this), *((TEXTE_PCB*) aImage) );
  151. }