kicad/pcbnew/class_marker.cpp

222 lines
5.7 KiB
C++
Raw Normal View History

/*****************************************************************************/
/* Functions to handle markers used to show somthing (usually a drc problem) */
/*****************************************************************************/
/* file class_marker.cpp */
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "pcbnew.h"
#include "class_marker.h"
/* Routines Locales : */
/* Default bitmap shape for markers */
static char Default_MarkerBitmap[] =
{
2007-12-01 05:37:44 +00:00
12, 12, /* x and y size of the bitmap */
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, /* bitmap: 1 = color, 0 = notrace */
1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0,
1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0,
1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0,
1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0
};
/*******************/
2007-11-27 22:49:35 +00:00
/* Classe MARKER */
/*******************/
2007-12-01 03:42:52 +00:00
void MARKER::init()
{
m_Bitmap = NULL;
m_Type = 0;
m_Color = RED;
m_Bitmap = Default_MarkerBitmap;
2008-02-23 04:53:44 +00:00
m_Size.x = Default_MarkerBitmap[0];
m_Size.y = Default_MarkerBitmap[1];
}
MARKER::MARKER( BOARD_ITEM* aParent ) :
BOARD_ITEM( aParent, TYPE_MARKER ),
2007-12-01 03:42:52 +00:00
m_drc()
{
init();
}
2008-02-23 04:53:44 +00:00
MARKER::MARKER( int aErrorCode, const wxPoint& aMarkerPos,
const wxString& aText, const wxPoint& aPos,
2007-12-01 03:42:52 +00:00
const wxString& bText, const wxPoint& bPos ) :
BOARD_ITEM( NULL, TYPE_MARKER ) // parent set during BOARD::Add()
2007-12-01 03:42:52 +00:00
{
init();
2008-02-23 04:53:44 +00:00
SetData( aErrorCode, aMarkerPos,
2007-12-01 03:42:52 +00:00
aText, aPos,
bText, bPos );
}
2008-02-23 04:53:44 +00:00
MARKER::MARKER( int aErrorCode, const wxPoint& aMarkerPos,
const wxString& aText, const wxPoint& aPos ) :
BOARD_ITEM( NULL, TYPE_MARKER ) // parent set during BOARD::Add()
{
init();
2008-02-23 04:53:44 +00:00
SetData( aErrorCode, aMarkerPos,
aText, aPos );
}
/* Effacement memoire de la structure */
2007-11-27 22:49:35 +00:00
MARKER::~MARKER()
{
2007-11-27 22:49:35 +00:00
#if defined(DEBUG)
printf("MARKER %p deleted\n", this );
#endif
}
2008-02-23 04:53:44 +00:00
void MARKER::SetData( int aErrorCode, const wxPoint& aMarkerPos,
const wxString& aText, const wxPoint& aPos,
2007-12-01 03:42:52 +00:00
const wxString& bText, const wxPoint& bPos )
{
2008-02-23 04:53:44 +00:00
m_drc.SetData( aErrorCode, aMarkerPos,
2007-12-01 03:42:52 +00:00
aText, bText,
aPos, bPos );
2008-02-23 04:53:44 +00:00
2007-12-01 03:42:52 +00:00
// @todo: switch on error code to set error code specific color, and possibly bitmap.
m_Color = WHITE;
}
2008-02-23 04:53:44 +00:00
void MARKER::SetData( int aErrorCode, const wxPoint& aMarkerPos,
const wxString& aText, const wxPoint& aPos )
{
2008-02-23 04:53:44 +00:00
m_drc.SetData( aErrorCode, aMarkerPos,
aText, aPos );
2008-02-23 04:53:44 +00:00
// @todo: switch on error code to set error code specific color, and possibly bitmap.
m_Color = WHITE;
}
/* supprime du chainage la structure Struct
* les structures arrieres et avant sont chainees directement
*/
2007-11-27 22:49:35 +00:00
void MARKER::UnLink()
{
2007-11-27 22:49:35 +00:00
wxFAIL_MSG( wxT("MARKER::UnLink is deprecated") );
}
2007-11-27 22:49:35 +00:00
void MARKER::Display_Infos( WinEDA_DrawFrame* frame )
{
int text_pos;
frame->MsgPanel->EraseMsgBox();
2007-12-01 05:37:44 +00:00
const DRC_ITEM& rpt = m_drc;
2008-02-23 04:53:44 +00:00
text_pos = 1;
Affiche_1_Parametre( frame, text_pos, _( "Type" ), _("Marker"), DARKCYAN );
2007-12-01 05:37:44 +00:00
wxString errorTxt;
2008-02-23 04:53:44 +00:00
errorTxt << _("ErrType") << wxT("(") << rpt.GetErrorCode() << wxT(")- ") << rpt.GetErrorText() << wxT(":");
2008-02-23 04:53:44 +00:00
2007-12-01 05:37:44 +00:00
text_pos = 5;
Affiche_1_Parametre( frame, text_pos, errorTxt, wxEmptyString, RED );
wxString txtA;
txtA << DRC_ITEM::ShowCoord( rpt.GetPointA() ) << wxT(": ") << rpt.GetTextA();
2008-02-23 04:53:44 +00:00
2007-12-01 05:37:44 +00:00
wxString txtB;
2008-02-23 04:53:44 +00:00
if ( rpt.HasSecondItem() )
txtB << DRC_ITEM::ShowCoord( rpt.GetPointB() ) << wxT(": ") << rpt.GetTextB();
text_pos = 25;
Affiche_1_Parametre( frame, text_pos, txtA, txtB, DARKBROWN );
}
/**********************************************/
2007-11-27 22:49:35 +00:00
bool MARKER::HitTest( const wxPoint& refPos )
/**********************************************/
{
// the MARKER is 12 pixels by 12 pixels, but is not resized with zoom, so
// as zoom changes, the effective real size (in user units) of the MARKER changes.
2008-02-23 04:53:44 +00:00
wxSize TrueSize = m_Size;
2008-02-23 04:53:44 +00:00
if ( ActiveScreen )
{
TrueSize.x *= ActiveScreen->GetZoom();
TrueSize.y *= ActiveScreen->GetZoom();
}
2007-12-01 03:42:52 +00:00
wxPoint pos = GetPosition();
2008-02-23 04:53:44 +00:00
2007-12-01 03:42:52 +00:00
int dx = refPos.x - pos.x;
int dy = refPos.y - pos.y;
2008-02-23 04:53:44 +00:00
/* is refPos in the box: Marker size to right an bottom,
or size/2 to left or top */
if( dx <= TrueSize.x && dy <= TrueSize.y &&
2008-02-23 04:53:44 +00:00
dx >= -TrueSize.x/2 && dy >= -TrueSize.y/2 )
return true;
else
return false;
}
/**********************************************************************/
2008-04-01 05:21:50 +00:00
void MARKER::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int DrawMode, const wxPoint& offset )
/**********************************************************************/
/*
* Trace un repere sur l'ecran au point de coordonnees PCB pos
* Le marqueur est defini par un tableau de 2 + (lig*col) elements:
* 1er element: dim nbre ligne
* 2er element: dim nbre col
* suite: lig * col elements a 0 ou 1 : si 1 mise a color du pixel
*/
{
int px, py;
int ii, jj;
char* pt_bitmap = m_Bitmap;
if( pt_bitmap == NULL ) return;
GRSetDrawMode( DC, DrawMode );
2008-02-23 04:53:44 +00:00
px = GRMapX( GetPosition().x );
2007-12-01 03:42:52 +00:00
py = GRMapY( GetPosition().y );
/* Get the bitmap size */
2008-02-23 04:53:44 +00:00
m_Size.x = *(pt_bitmap++);
m_Size.y = *(pt_bitmap++);
/* Draw the bitmap */
for( ii = 0; ii < m_Size.x; ii++ )
{
for( jj = 0; jj < m_Size.y; jj++, pt_bitmap++ )
{
if( *pt_bitmap )
GRSPutPixel( &panel->m_ClipBox, DC,
px + ii, py + jj, m_Color );
}
}
}