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.

199 lines
5.5 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-2012 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 <wxstruct.h>
  31. #include <gr_basic.h>
  32. #include <base_struct.h>
  33. #include <drawtxt.h>
  34. #include <kicad_string.h>
  35. #include <trigo.h>
  36. #include <colors_selection.h>
  37. #include <richio.h>
  38. #include <class_drawpanel.h>
  39. #include <macros.h>
  40. #include <msgpanel.h>
  41. #include <base_units.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. m_MultilineAllowed = true;
  49. }
  50. TEXTE_PCB:: ~TEXTE_PCB()
  51. {
  52. }
  53. void TEXTE_PCB::Copy( TEXTE_PCB* source )
  54. {
  55. m_Parent = source->m_Parent;
  56. Pback = Pnext = NULL;
  57. m_Mirror = source->m_Mirror;
  58. m_Size = source->m_Size;
  59. m_Orient = source->m_Orient;
  60. m_Pos = source->m_Pos;
  61. m_Layer = source->m_Layer;
  62. m_Thickness = source->m_Thickness;
  63. m_Attributs = source->m_Attributs;
  64. m_Italic = source->m_Italic;
  65. m_Bold = source->m_Bold;
  66. m_HJustify = source->m_HJustify;
  67. m_VJustify = source->m_VJustify;
  68. m_MultilineAllowed = m_MultilineAllowed;
  69. m_Text = source->m_Text;
  70. }
  71. void TEXTE_PCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
  72. GR_DRAWMODE DrawMode, const wxPoint& offset )
  73. {
  74. BOARD* brd = GetBoard();
  75. if( brd->IsLayerVisible( m_Layer ) == false )
  76. return;
  77. EDA_COLOR_T color = brd->GetLayerColor( m_Layer );
  78. EDA_DRAW_MODE_T fillmode = FILLED;
  79. if( DisplayOpt.DisplayDrawItems == SKETCH )
  80. fillmode = SKETCH;
  81. EDA_COLOR_T anchor_color = UNSPECIFIED_COLOR;
  82. if( brd->IsElementVisible( ANCHOR_VISIBLE ) )
  83. anchor_color = brd->GetVisibleElementColor( ANCHOR_VISIBLE );
  84. EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
  85. EDA_TEXT::Draw( clipbox, DC, offset, color,
  86. DrawMode, fillmode, anchor_color );
  87. // Enable these line to draw the bounding box (debug tests purposes only)
  88. #if 0
  89. {
  90. EDA_RECT BoundaryBox = GetBoundingBox();
  91. GRRect( clipbox, DC, BoundaryBox, 0, BROWN );
  92. }
  93. #endif
  94. }
  95. void TEXTE_PCB::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
  96. {
  97. wxString msg;
  98. #if defined(__WXDEBUG__)
  99. BOARD_ITEM* parent = (BOARD_ITEM*) m_Parent;
  100. wxASSERT( parent );
  101. BOARD* board;
  102. if( parent->Type() == PCB_DIMENSION_T )
  103. board = (BOARD*) parent->GetParent();
  104. else
  105. board = (BOARD*) parent;
  106. wxASSERT( board );
  107. #endif
  108. if( m_Parent && m_Parent->Type() == PCB_DIMENSION_T )
  109. aList.push_back( MSG_PANEL_ITEM( _( "Dimension" ), GetShownText(), DARKGREEN ) );
  110. else
  111. aList.push_back( MSG_PANEL_ITEM( _( "PCB Text" ), GetShownText(), DARKGREEN ) );
  112. aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), BLUE ) );
  113. if( !m_Mirror )
  114. aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "No" ), DARKGREEN ) );
  115. else
  116. aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "Yes" ), DARKGREEN ) );
  117. msg.Printf( wxT( "%.1f" ), m_Orient / 10.0 );
  118. aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, DARKGREEN ) );
  119. msg = ::CoordinateToString( m_Thickness );
  120. aList.push_back( MSG_PANEL_ITEM( _( "Thickness" ), msg, MAGENTA ) );
  121. msg = ::CoordinateToString( m_Size.x );
  122. aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, RED ) );
  123. msg = ::CoordinateToString( m_Size.y );
  124. aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, RED ) );
  125. }
  126. const EDA_RECT TEXTE_PCB::GetBoundingBox() const
  127. {
  128. EDA_RECT rect = GetTextBox( -1, -1 );
  129. if( m_Orient )
  130. rect = rect.GetBoundingBoxRotated( m_Pos, m_Orient );
  131. return rect;
  132. }
  133. void TEXTE_PCB::Rotate( const wxPoint& aRotCentre, double aAngle )
  134. {
  135. RotatePoint( &m_Pos, aRotCentre, aAngle );
  136. m_Orient += aAngle;
  137. NORMALIZE_ANGLE_360( m_Orient );
  138. }
  139. void TEXTE_PCB::Flip(const wxPoint& aCentre )
  140. {
  141. m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
  142. SetLayer( FlipLayer( GetLayer() ) );
  143. m_Mirror = !m_Mirror;
  144. }
  145. wxString TEXTE_PCB::GetSelectMenuText() const
  146. {
  147. wxString text;
  148. text.Printf( _( "Pcb Text \"%s\" on %s"),
  149. GetChars ( ShortenedShownText() ), GetChars( GetLayerName() ) );
  150. return text;
  151. }
  152. EDA_ITEM* TEXTE_PCB::Clone() const
  153. {
  154. return new TEXTE_PCB( *this );
  155. }