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.

221 lines
5.7 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /*****************************************************************************/
  2. /* Functions to handle markers used to show somthing (usually a drc problem) */
  3. /*****************************************************************************/
  4. /* file class_marker.cpp */
  5. #include "fctsys.h"
  6. #include "gr_basic.h"
  7. #include "common.h"
  8. #include "class_drawpanel.h"
  9. #include "pcbnew.h"
  10. #include "class_marker.h"
  11. /* Routines Locales : */
  12. /* Default bitmap shape for markers */
  13. static char Default_MarkerBitmap[] =
  14. {
  15. 12, 12, /* x and y size of the bitmap */
  16. 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, /* bitmap: 1 = color, 0 = notrace */
  17. 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0,
  18. 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0,
  19. 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
  20. 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
  21. 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0,
  22. 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0,
  23. 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0,
  24. 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0,
  25. 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
  26. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
  27. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0
  28. };
  29. /*******************/
  30. /* Classe MARKER */
  31. /*******************/
  32. void MARKER::init()
  33. {
  34. m_Bitmap = NULL;
  35. m_Type = 0;
  36. m_Color = RED;
  37. m_Bitmap = Default_MarkerBitmap;
  38. m_Size.x = Default_MarkerBitmap[0];
  39. m_Size.y = Default_MarkerBitmap[1];
  40. }
  41. MARKER::MARKER( BOARD_ITEM* aParent ) :
  42. BOARD_ITEM( aParent, TYPE_MARKER ),
  43. m_drc()
  44. {
  45. init();
  46. }
  47. MARKER::MARKER( int aErrorCode, const wxPoint& aMarkerPos,
  48. const wxString& aText, const wxPoint& aPos,
  49. const wxString& bText, const wxPoint& bPos ) :
  50. BOARD_ITEM( NULL, TYPE_MARKER ) // parent set during BOARD::Add()
  51. {
  52. init();
  53. SetData( aErrorCode, aMarkerPos,
  54. aText, aPos,
  55. bText, bPos );
  56. }
  57. MARKER::MARKER( int aErrorCode, const wxPoint& aMarkerPos,
  58. const wxString& aText, const wxPoint& aPos ) :
  59. BOARD_ITEM( NULL, TYPE_MARKER ) // parent set during BOARD::Add()
  60. {
  61. init();
  62. SetData( aErrorCode, aMarkerPos,
  63. aText, aPos );
  64. }
  65. /* Effacement memoire de la structure */
  66. MARKER::~MARKER()
  67. {
  68. #if defined(DEBUG)
  69. printf("MARKER %p deleted\n", this );
  70. #endif
  71. }
  72. void MARKER::SetData( int aErrorCode, const wxPoint& aMarkerPos,
  73. const wxString& aText, const wxPoint& aPos,
  74. const wxString& bText, const wxPoint& bPos )
  75. {
  76. m_drc.SetData( aErrorCode, aMarkerPos,
  77. aText, bText,
  78. aPos, bPos );
  79. // @todo: switch on error code to set error code specific color, and possibly bitmap.
  80. m_Color = WHITE;
  81. }
  82. void MARKER::SetData( int aErrorCode, const wxPoint& aMarkerPos,
  83. const wxString& aText, const wxPoint& aPos )
  84. {
  85. m_drc.SetData( aErrorCode, aMarkerPos,
  86. aText, aPos );
  87. // @todo: switch on error code to set error code specific color, and possibly bitmap.
  88. m_Color = WHITE;
  89. }
  90. /* supprime du chainage la structure Struct
  91. * les structures arrieres et avant sont chainees directement
  92. */
  93. void MARKER::UnLink()
  94. {
  95. wxFAIL_MSG( wxT("MARKER::UnLink is deprecated") );
  96. }
  97. void MARKER::DisplayInfo( WinEDA_DrawFrame* frame )
  98. {
  99. int text_pos;
  100. frame->MsgPanel->EraseMsgBox();
  101. const DRC_ITEM& rpt = m_drc;
  102. text_pos = 1;
  103. Affiche_1_Parametre( frame, text_pos, _( "Type" ), _("Marker"), DARKCYAN );
  104. wxString errorTxt;
  105. errorTxt << _("ErrType") << wxT("(") << rpt.GetErrorCode() << wxT(")- ") << rpt.GetErrorText() << wxT(":");
  106. text_pos = 5;
  107. Affiche_1_Parametre( frame, text_pos, errorTxt, wxEmptyString, RED );
  108. wxString txtA;
  109. txtA << DRC_ITEM::ShowCoord( rpt.GetPointA() ) << wxT(": ") << rpt.GetTextA();
  110. wxString txtB;
  111. if ( rpt.HasSecondItem() )
  112. txtB << DRC_ITEM::ShowCoord( rpt.GetPointB() ) << wxT(": ") << rpt.GetTextB();
  113. text_pos = 25;
  114. Affiche_1_Parametre( frame, text_pos, txtA, txtB, DARKBROWN );
  115. }
  116. /**********************************************/
  117. bool MARKER::HitTest( const wxPoint& refPos )
  118. /**********************************************/
  119. {
  120. // the MARKER is 12 pixels by 12 pixels, but is not resized with zoom, so
  121. // as zoom changes, the effective real size (in user units) of the MARKER changes.
  122. wxSize TrueSize = m_Size;
  123. if ( ActiveScreen )
  124. {
  125. ActiveScreen->Unscale( TrueSize );
  126. }
  127. wxPoint pos = GetPosition();
  128. int dx = refPos.x - pos.x;
  129. int dy = refPos.y - pos.y;
  130. /* is refPos in the box: Marker size to right an bottom,
  131. or size/2 to left or top */
  132. if( dx <= TrueSize.x && dy <= TrueSize.y &&
  133. dx >= -TrueSize.x/2 && dy >= -TrueSize.y/2 )
  134. return true;
  135. else
  136. return false;
  137. }
  138. /**********************************************************************/
  139. void MARKER::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int DrawMode, const wxPoint& offset )
  140. /**********************************************************************/
  141. /*
  142. * Trace un repere sur l'ecran au point de coordonnees PCB pos
  143. * Le marqueur est defini par un tableau de 2 + (lig*col) elements:
  144. * 1er element: dim nbre ligne
  145. * 2er element: dim nbre col
  146. * suite: lig * col elements a 0 ou 1 : si 1 mise a color du pixel
  147. */
  148. {
  149. int px, py;
  150. int ii, jj;
  151. char* pt_bitmap = m_Bitmap;
  152. if( pt_bitmap == NULL ) return;
  153. GRSetDrawMode( DC, DrawMode );
  154. px = GRMapX( GetPosition().x );
  155. py = GRMapY( GetPosition().y );
  156. /* Get the bitmap size */
  157. m_Size.x = *(pt_bitmap++);
  158. m_Size.y = *(pt_bitmap++);
  159. /* Draw the bitmap */
  160. for( ii = 0; ii < m_Size.x; ii++ )
  161. {
  162. for( jj = 0; jj < m_Size.y; jj++, pt_bitmap++ )
  163. {
  164. if( *pt_bitmap )
  165. GRSPutPixel( &panel->m_ClipBox, DC,
  166. px + ii, py + jj, m_Color );
  167. }
  168. }
  169. }