kicad/pcbnew/class_mire.cpp

231 lines
5.2 KiB
C++
Raw Normal View History

/****************************************************/
/* MIRE class definition (targets for photos) */
/****************************************************/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "class_drawpanel.h"
#include "kicad_string.h"
#include "pcbnew.h"
2009-10-28 11:48:47 +00:00
#include "class_board_design_settings.h"
#include "colors_selection.h"
2009-08-01 19:26:05 +00:00
#include "trigo.h"
#include "protos.h"
MIREPCB::MIREPCB( BOARD_ITEM* aParent ) :
BOARD_ITEM( aParent, TYPE_MIRE )
{
2007-08-08 20:51:08 +00:00
m_Shape = 0;
m_Size = 5000;
}
2007-08-08 20:51:08 +00:00
2007-08-23 04:28:46 +00:00
MIREPCB::~MIREPCB()
{
}
2007-08-08 20:51:08 +00:00
void MIREPCB::Copy( MIREPCB* source )
{
2007-08-08 20:51:08 +00:00
m_Layer = source->m_Layer;
m_Width = source->m_Width;
m_Pos = source->m_Pos;
m_Shape = source->m_Shape;
m_Size = source->m_Size;
m_TimeStamp = GetTimeStamp();
}
/* Read the description from the PCB file.
2007-08-08 20:51:08 +00:00
*/
bool MIREPCB::ReadMirePcbDescr( FILE* File, int* LineNum )
{
2007-08-08 20:51:08 +00:00
char Line[256];
while( GetLine( File, Line, LineNum ) != NULL )
{
if( strnicmp( Line, "$End", 4 ) == 0 )
return TRUE;
2007-08-08 20:51:08 +00:00
if( Line[0] == 'P' )
{
sscanf( Line + 2, " %X %d %d %d %d %d %lX",
&m_Shape, &m_Layer,
&m_Pos.x, &m_Pos.y,
&m_Size, &m_Width, &m_TimeStamp );
if( m_Layer < FIRST_NO_COPPER_LAYER )
m_Layer = FIRST_NO_COPPER_LAYER;
if( m_Layer > LAST_NO_COPPER_LAYER )
m_Layer = LAST_NO_COPPER_LAYER;
}
}
return FALSE;
}
2007-10-30 21:30:58 +00:00
bool MIREPCB::Save( FILE* aFile ) const
{
if( GetState( DELETED ) )
return true;
bool rc = false;
2008-04-01 05:21:50 +00:00
2007-10-30 21:30:58 +00:00
if( fprintf( aFile, "$MIREPCB\n" ) != sizeof("$MIREPCB\n")-1 )
goto out;
2008-04-01 05:21:50 +00:00
2007-10-30 21:30:58 +00:00
fprintf( aFile, "Po %X %d %d %d %d %d %8.8lX\n",
m_Shape, m_Layer,
m_Pos.x, m_Pos.y,
m_Size, m_Width, m_TimeStamp );
2008-04-01 05:21:50 +00:00
2007-10-30 21:30:58 +00:00
if( fprintf( aFile, "$EndMIREPCB\n" ) != sizeof("$EndMIREPCB\n")-1 )
goto out;
2008-04-01 05:21:50 +00:00
2007-10-30 21:30:58 +00:00
rc = true;
2008-04-01 05:21:50 +00:00
out:
2007-10-30 21:30:58 +00:00
return rc;
}
2008-04-01 05:21:50 +00:00
/* Draw MIREPCB object: 2 segments + 1 circle
* The circle radius is half the radius of the target
* 2 lines have length the diameter of the target
*/
2007-08-08 20:51:08 +00:00
void MIREPCB::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
2008-04-01 05:21:50 +00:00
int mode_color, const wxPoint& offset )
{
2007-08-08 20:51:08 +00:00
int rayon, ox, oy, gcolor, width;
int dx1, dx2, dy1, dy2;
int typeaff;
ox = m_Pos.x + offset.x;
oy = m_Pos.y + offset.y;
BOARD * brd = GetBoard( );
if( brd->IsLayerVisible( m_Layer ) == false )
2007-08-08 20:51:08 +00:00
return;
gcolor = brd->GetLayerColor(m_Layer);
2009-10-10 01:25:53 +00:00
2007-08-08 20:51:08 +00:00
GRSetDrawMode( DC, mode_color );
typeaff = DisplayOpt.DisplayDrawItems;
width = m_Width;
#ifdef USE_WX_ZOOM
if( DC->LogicalToDeviceXRel( width ) < 2 )
#else
if( panel->GetScreen()->Scale( width ) < 2 )
#endif
2007-08-08 20:51:08 +00:00
typeaff = FILAIRE;
rayon = m_Size / 4;
switch( typeaff )
{
case FILAIRE:
width = 0;
case FILLED:
GRCircle( &panel->m_ClipBox, DC, ox, oy, rayon, width, gcolor );
break;
case SKETCH:
GRCircle( &panel->m_ClipBox, DC, ox, oy, rayon + (width / 2), gcolor );
GRCircle( &panel->m_ClipBox, DC, ox, oy, rayon - (width / 2), gcolor );
break;
}
rayon = m_Size / 2;
dx1 = rayon;
dy1 = 0;
dx2 = 0;
dy2 = rayon;
2007-08-08 20:51:08 +00:00
if( m_Shape ) /* Form X */
2007-08-08 20:51:08 +00:00
{
dx1 = dy1 = ( rayon * 7 ) / 5;
dx2 = dx1;
dy2 = -dy1;
2007-08-08 20:51:08 +00:00
}
switch( typeaff )
{
case FILAIRE:
case FILLED:
GRLine( &panel->m_ClipBox, DC, ox - dx1, oy - dy1,
ox + dx1, oy + dy1, width, gcolor );
GRLine( &panel->m_ClipBox, DC, ox - dx2, oy - dy2,
ox + dx2, oy + dy2, width, gcolor );
break;
case SKETCH:
GRCSegm( &panel->m_ClipBox, DC, ox - dx1, oy - dy1,
ox + dx1, oy + dy1,
width, gcolor );
GRCSegm( &panel->m_ClipBox, DC, ox - dx2, oy - dy2,
ox + dx2, oy + dy2,
width, gcolor );
break;
}
}
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param refPos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool MIREPCB::HitTest( const wxPoint& refPos )
{
int dX = refPos.x - m_Pos.x;
int dY = refPos.y - m_Pos.y;
int rayon = m_Size / 2;
return abs( dX ) <= rayon && abs( dY ) <= rayon;
}
2008-01-06 12:43:57 +00:00
/**
* Function HitTest (overlayed)
* tests if the given EDA_Rect intersect this object.
* @param EDA_Rect : the given EDA_Rect
* @return bool - true if a hit, else false
*/
bool MIREPCB::HitTest( EDA_Rect& refArea )
{
2008-04-01 05:21:50 +00:00
if( refArea.Inside( m_Pos ) )
return true;
return false;
2008-01-06 12:43:57 +00:00
}
2009-08-01 19:26:05 +00:00
/**
* Function Rotate
* Rotate this object.
* @param const wxPoint& aRotCentre - the rotation point.
* @param aAngle - the rotation angle in 0.1 degree.
*/
void MIREPCB::Rotate(const wxPoint& aRotCentre, int aAngle)
{
RotatePoint( &m_Pos, aRotCentre, aAngle );
}
2009-08-01 19:26:05 +00:00
/**
* Function Flip
* Flip this object, i.e. change the board side for this object
* @param const wxPoint& aCentre - the rotation point.
*/
void MIREPCB::Flip(const wxPoint& aCentre )
{
m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
2009-08-01 19:26:05 +00:00
SetLayer( ChangeSideNumLayer( GetLayer() ) );
}