2007-06-05 12:10:51 +00:00
|
|
|
/****************************************************/
|
2009-11-12 15:43:38 +00:00
|
|
|
/* MIRE class definition (targets for photos) */
|
2007-06-05 12:10:51 +00:00
|
|
|
/****************************************************/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "pcbnew.h"
|
2009-10-28 11:48:47 +00:00
|
|
|
#include "class_board_design_settings.h"
|
2010-01-29 20:36:12 +00:00
|
|
|
#include "colors_selection.h"
|
2009-08-01 19:26:05 +00:00
|
|
|
#include "trigo.h"
|
|
|
|
#include "protos.h"
|
2011-01-14 17:43:30 +00:00
|
|
|
#include "richio.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent ) :
|
|
|
|
BOARD_ITEM( aParent, PCB_TARGET_T )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-08 20:51:08 +00:00
|
|
|
m_Shape = 0;
|
|
|
|
m_Size = 5000;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 20:51:08 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
PCB_TARGET::~PCB_TARGET()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
void PCB_TARGET::Copy( PCB_TARGET* source )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
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();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Read the description from the PCB file.
|
2007-08-08 20:51:08 +00:00
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
bool PCB_TARGET::ReadMirePcbDescr( LINE_READER* aReader )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
char* Line;
|
2007-08-08 20:51:08 +00:00
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
while( aReader->ReadLine() )
|
2007-08-08 20:51:08 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = aReader->Line();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-08 20:51:08 +00:00
|
|
|
if( strnicmp( Line, "$End", 4 ) == 0 )
|
2011-09-07 19:41:04 +00:00
|
|
|
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 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-08 20:51:08 +00:00
|
|
|
if( m_Layer < FIRST_NO_COPPER_LAYER )
|
|
|
|
m_Layer = FIRST_NO_COPPER_LAYER;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-08 20:51:08 +00:00
|
|
|
if( m_Layer > LAST_NO_COPPER_LAYER )
|
|
|
|
m_Layer = LAST_NO_COPPER_LAYER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
return false;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
bool PCB_TARGET::Save( FILE* aFile ) const
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
bool rc = false;
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( fprintf( aFile, "$PCB_TARGET\n" ) != sizeof("$PCB_TARGET\n")-1 )
|
2007-10-30 21:30:58 +00:00
|
|
|
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
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( fprintf( aFile, "$EndPCB_TARGET\n" ) != sizeof("$EndPCB_TARGET\n")-1 )
|
2007-10-30 21:30:58 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
/* Draw PCB_TARGET object: 2 segments + 1 circle
|
2009-11-12 15:43:38 +00:00
|
|
|
* The circle radius is half the radius of the target
|
|
|
|
* 2 lines have length the diameter of the target
|
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
void PCB_TARGET::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int mode_color, const wxPoint& offset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
int radius, ox, oy, gcolor, width;
|
2007-08-08 20:51:08 +00:00
|
|
|
int dx1, dx2, dy1, dy2;
|
|
|
|
int typeaff;
|
|
|
|
|
|
|
|
ox = m_Pos.x + offset.x;
|
|
|
|
oy = m_Pos.y + offset.y;
|
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
BOARD * brd = GetBoard( );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
if( brd->IsLayerVisible( m_Layer ) == false )
|
2007-08-08 20:51:08 +00:00
|
|
|
return;
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
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;
|
2010-02-08 18:15:42 +00:00
|
|
|
|
|
|
|
if( DC->LogicalToDeviceXRel( width ) < 2 )
|
2007-08-08 20:51:08 +00:00
|
|
|
typeaff = FILAIRE;
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
radius = m_Size / 4;
|
2007-08-08 20:51:08 +00:00
|
|
|
|
|
|
|
switch( typeaff )
|
|
|
|
{
|
|
|
|
case FILAIRE:
|
|
|
|
width = 0;
|
|
|
|
|
|
|
|
case FILLED:
|
2011-09-07 19:41:04 +00:00
|
|
|
GRCircle( &panel->m_ClipBox, DC, ox, oy, radius, width, gcolor );
|
2007-08-08 20:51:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SKETCH:
|
2011-09-07 19:41:04 +00:00
|
|
|
GRCircle( &panel->m_ClipBox, DC, ox, oy, radius + (width / 2), gcolor );
|
|
|
|
GRCircle( &panel->m_ClipBox, DC, ox, oy, radius - (width / 2), gcolor );
|
2007-08-08 20:51:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
radius = m_Size / 2;
|
|
|
|
dx1 = radius;
|
2009-11-12 15:43:38 +00:00
|
|
|
dy1 = 0;
|
|
|
|
dx2 = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
dy2 = radius;
|
2007-08-08 20:51:08 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
if( m_Shape ) /* Form X */
|
2007-08-08 20:51:08 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
dx1 = dy1 = ( radius * 7 ) / 5;
|
2009-11-12 15:43:38 +00:00
|
|
|
dx2 = dx1;
|
|
|
|
dy2 = -dy1;
|
2007-08-08 20:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( typeaff )
|
|
|
|
{
|
|
|
|
case FILAIRE:
|
|
|
|
case FILLED:
|
2011-09-07 19:41:04 +00:00
|
|
|
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 );
|
2007-08-08 20:51:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SKETCH:
|
2011-09-07 19:41:04 +00:00
|
|
|
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 );
|
2007-08-08 20:51:08 +00:00
|
|
|
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
|
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
bool PCB_TARGET::HitTest( const wxPoint& refPos )
|
2007-08-08 20:51:08 +00:00
|
|
|
{
|
|
|
|
int dX = refPos.x - m_Pos.x;
|
|
|
|
int dY = refPos.y - m_Pos.y;
|
2011-09-07 19:41:04 +00:00
|
|
|
int radius = m_Size / 2;
|
|
|
|
return abs( dX ) <= radius && abs( dY ) <= radius;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2008-01-06 12:43:57 +00:00
|
|
|
/**
|
|
|
|
* Function HitTest (overlayed)
|
2011-03-29 19:33:07 +00:00
|
|
|
* tests if the given EDA_RECT intersect this object.
|
|
|
|
* @param refArea : the given EDA_RECT
|
2008-01-06 12:43:57 +00:00
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
bool PCB_TARGET::HitTest( EDA_RECT& refArea )
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2010-12-20 17:44:25 +00:00
|
|
|
if( refArea.Contains( m_Pos ) )
|
2008-04-01 05:21:50 +00:00
|
|
|
return true;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-04-01 05:21:50 +00:00
|
|
|
return false;
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/**
|
|
|
|
* Function Rotate
|
|
|
|
* Rotate this object.
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aRotCentre - the rotation point.
|
2009-08-01 19:26:05 +00:00
|
|
|
* @param aAngle - the rotation angle in 0.1 degree.
|
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
void PCB_TARGET::Rotate(const wxPoint& aRotCentre, int aAngle)
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
|
|
|
RotatePoint( &m_Pos, aRotCentre, aAngle );
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/**
|
|
|
|
* Function Flip
|
|
|
|
* Flip this object, i.e. change the board side for this object
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aCentre - the rotation point.
|
2009-08-01 19:26:05 +00:00
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
void PCB_TARGET::Flip(const wxPoint& aCentre )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
|
2009-08-01 19:26:05 +00:00
|
|
|
SetLayer( ChangeSideNumLayer( GetLayer() ) );
|
|
|
|
}
|
2011-02-25 16:23:24 +00:00
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
EDA_RECT PCB_TARGET::GetBoundingBox() const
|
2011-02-25 16:23:24 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT bBox;
|
2011-02-25 16:23:24 +00:00
|
|
|
bBox.SetX( m_Pos.x - m_Size/2 );
|
|
|
|
bBox.SetY( m_Pos.y - m_Size/2 );
|
|
|
|
bBox.SetWidth( m_Size );
|
|
|
|
bBox.SetHeight( m_Size );
|
|
|
|
|
|
|
|
return bBox;
|
|
|
|
}
|
2011-07-14 15:42:44 +00:00
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
wxString PCB_TARGET::GetSelectMenuText() const
|
2011-07-14 15:42:44 +00:00
|
|
|
{
|
|
|
|
wxString text;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
valeur_param( m_Size, msg );
|
|
|
|
|
|
|
|
text << _( "Target" ) << _( " on " ) << GetLayerName() << wxT( " " ) << _( "size" )
|
|
|
|
<< wxT( " " ) << msg;
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|