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.

219 lines
6.1 KiB

14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2018 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 <fctsys.h>
  26. #include <gr_basic.h>
  27. #include <bitmaps.h>
  28. #include <base_units.h>
  29. #include <pcb_base_frame.h>
  30. #include <class_board.h>
  31. #include <class_marker_pcb.h>
  32. #include <layers_id_colors_and_visibility.h>
  33. #include <settings/color_settings.h>
  34. #include <settings/settings_manager.h>
  35. #include <widgets/ui_common.h>
  36. #include <pgm_base.h>
  37. #include <drc/drc_item.h>
  38. /// Factor to convert the maker unit shape to internal units:
  39. #define SCALING_FACTOR Millimeter2iu( 0.1 )
  40. MARKER_PCB::MARKER_PCB( std::shared_ptr<RC_ITEM> aItem, const wxPoint& aPosition ) :
  41. BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add()
  42. MARKER_BASE( SCALING_FACTOR, aItem )
  43. {
  44. if( m_rcItem )
  45. m_rcItem->SetParent( this );
  46. m_Pos = aPosition;
  47. }
  48. /* destructor */
  49. MARKER_PCB::~MARKER_PCB()
  50. {
  51. }
  52. wxString MARKER_PCB::Serialize() const
  53. {
  54. return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
  55. m_rcItem->GetSettingsKey(),
  56. m_Pos.x,
  57. m_Pos.y,
  58. m_rcItem->GetMainItemID().AsString(),
  59. m_rcItem->GetAuxItemID().AsString() );
  60. }
  61. MARKER_PCB* MARKER_PCB::Deserialize( const wxString& data )
  62. {
  63. wxArrayString props = wxSplit( data, '|' );
  64. wxPoint markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
  65. (int) strtol( props[2].c_str(), nullptr, 10 ) );
  66. std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( props[0] );
  67. if( !drcItem )
  68. return nullptr;
  69. drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
  70. return new MARKER_PCB( drcItem, markerPos );
  71. }
  72. void MARKER_PCB::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  73. {
  74. aList.emplace_back( _( "Type" ), _( "Marker" ), DARKCYAN );
  75. aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage(), RED );
  76. wxString mainText;
  77. wxString auxText;
  78. EDA_ITEM* mainItem = nullptr;
  79. EDA_ITEM* auxItem = nullptr;
  80. if( m_rcItem->GetMainItemID() != niluuid )
  81. mainItem = aFrame->GetItem( m_rcItem->GetMainItemID() );
  82. if( m_rcItem->GetAuxItemID() != niluuid )
  83. auxItem = aFrame->GetItem( m_rcItem->GetAuxItemID() );
  84. if( mainItem )
  85. mainText = mainItem->GetSelectMenuText( aFrame->GetUserUnits() );
  86. if( auxItem )
  87. auxText = auxItem->GetSelectMenuText( aFrame->GetUserUnits() );
  88. aList.emplace_back( mainText, auxText, DARKBROWN );
  89. }
  90. void MARKER_PCB::Rotate(const wxPoint& aRotCentre, double aAngle)
  91. {
  92. RotatePoint( &m_Pos, aRotCentre, aAngle );
  93. }
  94. void MARKER_PCB::Flip(const wxPoint& aCentre, bool aFlipLeftRight )
  95. {
  96. if( aFlipLeftRight )
  97. m_Pos.x = aCentre.x - ( m_Pos.x - aCentre.x );
  98. else
  99. m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
  100. }
  101. wxString MARKER_PCB::GetSelectMenuText( EDA_UNITS aUnits ) const
  102. {
  103. // m_rcItem->GetErrorMessage() could be used instead, but is probably too long
  104. // for menu duty.
  105. return wxString::Format( _( "Marker (%s)" ), m_rcItem->GetErrorText() );
  106. }
  107. BITMAP_DEF MARKER_PCB::GetMenuImage() const
  108. {
  109. return drc_xpm;
  110. }
  111. void MARKER_PCB::ViewGetLayers( int aLayers[], int& aCount ) const
  112. {
  113. aCount = 1;
  114. if( IsExcluded() )
  115. {
  116. aLayers[0] = LAYER_DRC_EXCLUSION;
  117. return;
  118. }
  119. BOARD_ITEM_CONTAINER* ancestor = GetParent();
  120. while( ancestor->GetParent() )
  121. ancestor = ancestor->GetParent();
  122. BOARD* board = static_cast<BOARD*>( ancestor );
  123. switch( board->GetDesignSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
  124. {
  125. default:
  126. case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_DRC_ERROR; break;
  127. case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_DRC_WARNING; break;
  128. }
  129. }
  130. GAL_LAYER_ID MARKER_PCB::GetColorLayer() const
  131. {
  132. if( IsExcluded() )
  133. return LAYER_DRC_EXCLUSION;
  134. BOARD_ITEM_CONTAINER* ancestor = GetParent();
  135. while( ancestor->GetParent() )
  136. ancestor = ancestor->GetParent();
  137. BOARD* board = static_cast<BOARD*>( ancestor );
  138. switch( board->GetDesignSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
  139. {
  140. default:
  141. case SEVERITY::RPT_SEVERITY_ERROR: return LAYER_DRC_ERROR;
  142. case SEVERITY::RPT_SEVERITY_WARNING: return LAYER_DRC_WARNING;
  143. }
  144. }
  145. KIGFX::COLOR4D MARKER_PCB::getColor() const
  146. {
  147. COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
  148. return colors->GetColor( GetColorLayer() );
  149. }
  150. const EDA_RECT MARKER_PCB::GetBoundingBox() const
  151. {
  152. EDA_RECT bbox = m_shapeBoundingBox;
  153. wxPoint pos = m_Pos;
  154. pos.x += int( bbox.GetOrigin().x * MarkerScale() );
  155. pos.y += int( bbox.GetOrigin().y * MarkerScale() );
  156. return EDA_RECT( pos, wxSize( int( bbox.GetWidth() * MarkerScale() ),
  157. int( bbox.GetHeight() * MarkerScale() ) ) );
  158. }
  159. const BOX2I MARKER_PCB::ViewBBox() const
  160. {
  161. EDA_RECT bbox = GetBoundingBox();
  162. return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
  163. }