class_marker.cpp 5.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*****************************************************************************/
/* 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[] =
{
21
    12, 12,                                 /* x and y size of the bitmap */
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
    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
};


/*******************/
38
/* Classe MARKER */
39 40
/*******************/

41
void MARKER::init()
42 43 44 45 46 47 48 49 50
{
    m_Bitmap = NULL;
    m_Type   = 0;
    m_Color  = RED;
    m_Bitmap = Default_MarkerBitmap;
	m_Size.x = Default_MarkerBitmap[0]; 
    m_Size.y = Default_MarkerBitmap[1];
}

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
MARKER::MARKER( BOARD_ITEM* StructFather ) :
    BOARD_ITEM( StructFather, TYPEMARKER ),
    m_drc()
{
    init();
}


MARKER::MARKER( int aErrorCode, const wxPoint& aMarkerPos, 
               const wxString& aText, const wxPoint& aPos, 
               const wxString& bText, const wxPoint& bPos ) :
    BOARD_ITEM( NULL, TYPEMARKER )  // parent set during BOARD::Add()
{
    init();

    SetData( aErrorCode, aMarkerPos, 
         aText, aPos,
         bText, bPos );
}

71 72

/* Effacement memoire de la structure */
73
MARKER::~MARKER()
74
{
75 76 77
#if defined(DEBUG)
    printf("MARKER %p deleted\n", this );
#endif
78 79 80
}


81 82 83 84 85 86 87 88 89 90 91 92 93
void MARKER::SetData( int aErrorCode, const wxPoint& aMarkerPos, 
         const wxString& aText, const wxPoint& aPos, 
         const wxString& bText, const wxPoint& bPos )
{
    m_drc.SetData( aErrorCode, aMarkerPos, 
             aText, bText,
             aPos, bPos );
    
    // @todo: switch on error code to set error code specific color, and possibly bitmap.
    m_Color = WHITE;
}


94 95 96
/* supprime du chainage la structure Struct
 *  les structures arrieres et avant sont chainees directement
 */
97
void MARKER::UnLink()
98
{
99
    wxFAIL_MSG( wxT("MARKER::UnLink is deprecated") );
100 101 102
}


103
void MARKER::Display_Infos( WinEDA_DrawFrame* frame )
104 105 106 107 108
{
    int      text_pos;

    frame->MsgPanel->EraseMsgBox();

109 110
    const DRC_ITEM& rpt = m_drc;
    
111 112 113
    text_pos = 1;
    Affiche_1_Parametre( frame, text_pos, _( "Type" ), _("Marker"), DARKCYAN );

114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    wxString errorTxt;
    
    errorTxt << _("ErrType") << wxT("(") << rpt.GetErrorCode() << wxT(")- ") << rpt.GetErrorText() << wxT(":");
    
    text_pos = 5;
    Affiche_1_Parametre( frame, text_pos, errorTxt, wxEmptyString, RED );

    wxString txtA;
    txtA << DRC_ITEM::ShowCoord( rpt.GetPointA() ) << wxT(": ") << rpt.GetTextA();
    
    wxString txtB;
    txtB << DRC_ITEM::ShowCoord( rpt.GetPointB() ) << wxT(": ") << rpt.GetTextB();     
    
    text_pos = 20;      // @todo pick a better color here
    Affiche_1_Parametre( frame, text_pos, txtA, txtB, BLACK );
129 130 131 132
}


/**********************************************/
133
bool MARKER::HitTest( const wxPoint& refPos )
134 135 136 137 138 139 140 141 142 143 144
/**********************************************/
{
    // 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.
   
    wxSize TrueSize = m_Size;
	if ( ActiveScreen )
	{
		TrueSize.x *= ActiveScreen->GetZoom();
		TrueSize.y *= ActiveScreen->GetZoom();
	}
145 146

    wxPoint pos = GetPosition();
147
    
148 149
    int dx = refPos.x - pos.x;
    int dy = refPos.y - pos.y;
150 151 152 153 154 155 156 157 158 159 160 161 162
	
	/* 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 &&
		dx >= -TrueSize.x/2  && dy >= -TrueSize.y/2 )
        return true;
    else
        return false;
}



/**********************************************************************/
163
void MARKER::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int DrawMode )
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
/**********************************************************************/

/*
 *  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 );

182 183
    px = GRMapX( GetPosition().x ); 
    py = GRMapY( GetPosition().y );
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199

    /* Get the bitmap size */
    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 );
        }
    }
}