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.

214 lines
5.8 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 = nullptr;
  70. if( panel )
  71. {
  72. displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
  73. }
  74. if( displ_opts && displ_opts->m_DisplayDrawItemsFill == SKETCH )
  75. fillmode = SKETCH;
  76. // shade text if high contrast mode is active
  77. if( ( DrawMode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && displ_opts->m_ContrastModeDisplay )
  78. {
  79. PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
  80. if( !IsOnLayer( curr_layer ) )
  81. color = COLOR4D( DARKDARKGRAY );
  82. }
  83. COLOR4D anchor_color = COLOR4D::UNSPECIFIED;
  84. if( brd->IsElementVisible( LAYER_ANCHOR ) )
  85. anchor_color = frame->Settings().Colors().GetItemColor( LAYER_ANCHOR );
  86. EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
  87. EDA_TEXT::Draw( clipbox, DC, offset, color,
  88. DrawMode, fillmode, anchor_color );
  89. // Enable these line to draw the bounding box (debug tests purposes only)
  90. #if 0
  91. {
  92. EDA_RECT BoundaryBox = GetBoundingBox();
  93. GRRect( clipbox, DC, BoundaryBox, 0, BROWN );
  94. }
  95. #endif
  96. }
  97. void TEXTE_PCB::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
  98. {
  99. wxString msg;
  100. wxCHECK_RET( m_Parent != NULL, wxT( "TEXTE_PCB::GetMsgPanelInfo() m_Parent is NULL." ) );
  101. if( m_Parent->Type() == PCB_DIMENSION_T )
  102. aList.push_back( MSG_PANEL_ITEM( _( "Dimension" ), GetShownText(), DARKGREEN ) );
  103. else
  104. aList.push_back( MSG_PANEL_ITEM( _( "PCB Text" ), GetShownText(), DARKGREEN ) );
  105. aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), BLUE ) );
  106. if( !IsMirrored() )
  107. aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "No" ), DARKGREEN ) );
  108. else
  109. aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "Yes" ), DARKGREEN ) );
  110. msg.Printf( wxT( "%.1f" ), GetTextAngle() / 10.0 );
  111. aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, DARKGREEN ) );
  112. msg = ::CoordinateToString( GetThickness() );
  113. aList.push_back( MSG_PANEL_ITEM( _( "Thickness" ), msg, MAGENTA ) );
  114. msg = ::CoordinateToString( GetTextWidth() );
  115. aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, RED ) );
  116. msg = ::CoordinateToString( GetTextHeight() );
  117. aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, RED ) );
  118. }
  119. const EDA_RECT TEXTE_PCB::GetBoundingBox() const
  120. {
  121. EDA_RECT rect = GetTextBox( -1, -1 );
  122. if( GetTextAngle() )
  123. rect = rect.GetBoundingBoxRotated( GetTextPos(), GetTextAngle() );
  124. return rect;
  125. }
  126. void TEXTE_PCB::Rotate( const wxPoint& aRotCentre, double aAngle )
  127. {
  128. wxPoint pt = GetTextPos();
  129. RotatePoint( &pt, aRotCentre, aAngle );
  130. SetTextPos( pt );
  131. SetTextAngle( GetTextAngle() + aAngle );
  132. }
  133. void TEXTE_PCB::Flip( const wxPoint& aCentre )
  134. {
  135. SetTextY( aCentre.y - ( GetTextPos().y - aCentre.y ) );
  136. int copperLayerCount = GetBoard()->GetCopperLayerCount();
  137. SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
  138. SetMirrored( !IsMirrored() );
  139. }
  140. wxString TEXTE_PCB::GetSelectMenuText() const
  141. {
  142. wxString text;
  143. text.Printf( _( "Pcb Text \"%s\" on %s"),
  144. GetChars ( ShortenedShownText() ), GetChars( GetLayerName() ) );
  145. return text;
  146. }
  147. BITMAP_DEF TEXTE_PCB::GetMenuImage() const
  148. {
  149. return text_xpm;
  150. }
  151. EDA_ITEM* TEXTE_PCB::Clone() const
  152. {
  153. return new TEXTE_PCB( *this );
  154. }
  155. void TEXTE_PCB::SwapData( BOARD_ITEM* aImage )
  156. {
  157. assert( aImage->Type() == PCB_TEXT_T );
  158. std::swap( *((TEXTE_PCB*) this), *((TEXTE_PCB*) aImage) );
  159. }