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.

149 lines
3.9 KiB

  1. /*********************/
  2. /* lib_draw_item.cpp */
  3. /*********************/
  4. #include "fctsys.h"
  5. #include "gr_basic.h"
  6. #include "class_drawpanel.h"
  7. #include "wxstruct.h"
  8. #include "protos.h"
  9. #include "general.h"
  10. #include "lib_draw_item.h"
  11. const int fill_tab[3] = { 'N', 'F', 'f' };
  12. //#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
  13. /* Base class (abstract) for components bodies items */
  14. LIB_DRAW_ITEM::LIB_DRAW_ITEM( KICAD_T aType,
  15. LIB_COMPONENT* aComponent,
  16. int aUnit,
  17. int aConvert,
  18. FILL_T aFillType ) :
  19. EDA_ITEM( aType )
  20. {
  21. m_Unit = aUnit;
  22. m_Convert = aConvert;
  23. m_Fill = aFillType;
  24. m_Parent = (EDA_ITEM*) aComponent;
  25. m_typeName = _( "Undefined" );
  26. m_isFillable = false;
  27. m_eraseLastDrawItem = false;
  28. }
  29. LIB_DRAW_ITEM::LIB_DRAW_ITEM( const LIB_DRAW_ITEM& aItem ) :
  30. EDA_ITEM( aItem )
  31. {
  32. m_Unit = aItem.m_Unit;
  33. m_Convert = aItem.m_Convert;
  34. m_Fill = aItem.m_Fill;
  35. m_Parent = aItem.m_Parent;
  36. m_typeName = aItem.m_typeName;
  37. m_isFillable = aItem.m_isFillable;
  38. }
  39. /**
  40. * Update the message panel information with the drawing information.
  41. *
  42. * This base function is used to display the information common to the
  43. * all library items. Call the base class from the derived class or the
  44. * common information will not be updated in the message panel.
  45. */
  46. void LIB_DRAW_ITEM::DisplayInfo( EDA_DRAW_FRAME* aFrame )
  47. {
  48. wxString msg;
  49. aFrame->ClearMsgPanel();
  50. aFrame->AppendMsgPanel( _( "Type" ), m_typeName, CYAN );
  51. if( m_Unit == 0 )
  52. msg = _( "All" );
  53. else
  54. msg.Printf( wxT( "%d" ), m_Unit );
  55. aFrame->AppendMsgPanel( _( "Unit" ), msg, BROWN );
  56. if( m_Convert == 0 )
  57. msg = _( "All" );
  58. else if( m_Convert == 1 )
  59. msg = _( "no" );
  60. else if( m_Convert == 2 )
  61. msg = _( "yes" );
  62. else
  63. msg = wxT( "?" );
  64. aFrame->AppendMsgPanel( _( "Convert" ), msg, BROWN );
  65. }
  66. bool LIB_DRAW_ITEM::operator==( const LIB_DRAW_ITEM& aOther ) const
  67. {
  68. return ( ( Type() == aOther.Type() )
  69. && ( m_Unit == aOther.m_Unit )
  70. && ( m_Convert == aOther.m_Convert )
  71. && DoCompare( aOther ) == 0 );
  72. }
  73. bool LIB_DRAW_ITEM::operator<( const LIB_DRAW_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 ( DoCompare( aOther ) < 0 );
  85. }
  86. void LIB_DRAW_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, int aColor,
  87. int aDrawMode, void* aData, const TRANSFORM& aTransform )
  88. {
  89. if( InEditMode() )
  90. {
  91. // Temporarily disable filling while the item is being edited.
  92. FILL_T fillMode = m_Fill;
  93. int color = GetDefaultColor();
  94. m_Fill = NO_FILL;
  95. // Erase the old items using the previous attributes.
  96. if( m_eraseLastDrawItem )
  97. {
  98. GRSetDrawMode( aDC, g_XorMode );
  99. drawEditGraphics( &aPanel->m_ClipBox, aDC, color );
  100. drawGraphic( aPanel, aDC, wxPoint( 0, 0 ), color, g_XorMode, aData, aTransform );
  101. }
  102. // Calculate the new attributes at the current cursor position.
  103. calcEdit( aOffset );
  104. // Draw the items using the new attributes.
  105. drawEditGraphics( &aPanel->m_ClipBox, aDC, color );
  106. drawGraphic( aPanel, aDC, wxPoint( 0, 0 ), color, g_XorMode, aData, aTransform );
  107. m_Fill = fillMode;
  108. }
  109. else
  110. {
  111. drawGraphic( aPanel, aDC, aOffset, aColor, aDrawMode, aData, aTransform );
  112. }
  113. }
  114. int LIB_DRAW_ITEM::GetDefaultColor()
  115. {
  116. return ReturnLayerColor( LAYER_DEVICE );
  117. }