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.

166 lines
4.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
  5. * Copyright (C) 2015 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 2004-2015 KiCad Developers, see change_log.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 lib_draw_item.cpp
  27. */
  28. #include <fctsys.h>
  29. #include <gr_basic.h>
  30. #include <sch_draw_panel.h>
  31. #include <msgpanel.h>
  32. #include <general.h>
  33. #include <lib_draw_item.h>
  34. const int fill_tab[3] = { 'N', 'F', 'f' };
  35. //#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
  36. LIB_ITEM::LIB_ITEM( KICAD_T aType,
  37. LIB_PART* aComponent,
  38. int aUnit,
  39. int aConvert,
  40. FILL_T aFillType ) :
  41. EDA_ITEM( aType )
  42. {
  43. m_Unit = aUnit;
  44. m_Convert = aConvert;
  45. m_Fill = aFillType;
  46. m_Parent = (EDA_ITEM*) aComponent;
  47. m_isFillable = false;
  48. }
  49. void LIB_ITEM::GetMsgPanelInfo( EDA_UNITS_T aUnits, MSG_PANEL_ITEMS& aList )
  50. {
  51. wxString msg;
  52. aList.push_back( MSG_PANEL_ITEM( _( "Type" ), GetTypeName(), CYAN ) );
  53. if( m_Unit == 0 )
  54. msg = _( "All" );
  55. else
  56. msg.Printf( wxT( "%d" ), m_Unit );
  57. aList.push_back( MSG_PANEL_ITEM( _( "Unit" ), msg, BROWN ) );
  58. if( m_Convert == LIB_ITEM::LIB_CONVERT::BASE )
  59. msg = _( "no" );
  60. else if( m_Convert == LIB_ITEM::LIB_CONVERT::DEMORGAN )
  61. msg = _( "yes" );
  62. else
  63. msg = wxT( "?" );
  64. aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg, BROWN ) );
  65. }
  66. bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
  67. {
  68. return ( ( Type() == aOther.Type() )
  69. && ( m_Unit == aOther.m_Unit )
  70. && ( m_Convert == aOther.m_Convert )
  71. && compare( aOther ) == 0 );
  72. }
  73. bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
  74. {
  75. int result = m_Convert - aOther.m_Convert;
  76. if( result != 0 )
  77. return result < 0;
  78. result = m_Unit - aOther.m_Unit;
  79. if( result != 0 )
  80. return result < 0;
  81. result = Type() - aOther.Type();
  82. if( result != 0 )
  83. return result < 0;
  84. return ( compare( aOther ) < 0 );
  85. }
  86. void LIB_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
  87. const wxPoint& aOffset, COLOR4D aColor,
  88. GR_DRAWMODE aDrawMode, void* aData,
  89. const TRANSFORM& aTransform )
  90. {
  91. #if 0
  92. if( InEditMode() )
  93. {
  94. // Temporarily disable filling while the item is being edited.
  95. FILL_T fillMode = m_Fill;
  96. COLOR4D color = GetDefaultColor();
  97. m_Fill = NO_FILL;
  98. #ifndef USE_WX_OVERLAY
  99. // Erase the old items using the previous attributes.
  100. if( m_eraseLastDrawItem )
  101. {
  102. GRSetDrawMode( aDC, g_XorMode );
  103. drawEditGraphics( aPanel->GetClipBox(), aDC, color );
  104. drawGraphic( aPanel, aDC, wxPoint( 0, 0 ), color, g_XorMode, aData,
  105. aTransform );
  106. }
  107. #endif
  108. // Calculate the new attributes at the current cursor position.
  109. CalcEdit( aOffset );
  110. // Draw the items using the new attributes.
  111. drawEditGraphics( aPanel->GetClipBox(), aDC, color );
  112. drawGraphic( aPanel, aDC, wxPoint( 0, 0 ), color, g_XorMode, aData,
  113. aTransform );
  114. m_Fill = fillMode;
  115. }
  116. else
  117. #endif
  118. {
  119. drawGraphic( aPanel, aDC, aOffset, aColor, aDrawMode, aData, aTransform );
  120. }
  121. }
  122. void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
  123. {
  124. // Basic fallback
  125. aCount = 2;
  126. aLayers[0] = LAYER_DEVICE;
  127. aLayers[1] = LAYER_DEVICE_BACKGROUND;
  128. }
  129. COLOR4D LIB_ITEM::GetDefaultColor()
  130. {
  131. return GetLayerColor( LAYER_DEVICE );
  132. }