2007-08-06 20:26:59 +00:00
|
|
|
/****************************************************/
|
2009-11-12 15:43:38 +00:00
|
|
|
/* class_module.cpp : EDGE_MODULE class definition. */
|
2007-08-06 20:26:59 +00:00
|
|
|
/****************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "wxstruct.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "trigo.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "kicad_string.h"
|
2010-01-29 20:36:12 +00:00
|
|
|
#include "colors_selection.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"
|
2011-01-14 17:43:30 +00:00
|
|
|
#include "richio.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
#define MAX_WIDTH 10000 /* Thickness (in 1 / 10000 ") of maximum reasonable
|
|
|
|
* features, text... */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/*********************/
|
|
|
|
/* class EDGE_MODULE */
|
|
|
|
/*********************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-02-19 00:30:10 +00:00
|
|
|
EDGE_MODULE::EDGE_MODULE( MODULE* parent ) :
|
2008-12-04 04:28:11 +00:00
|
|
|
BOARD_ITEM( parent, TYPE_EDGE_MODULE )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-20 19:51:39 +00:00
|
|
|
m_Shape = S_SEGMENT;
|
|
|
|
m_Angle = 0;
|
|
|
|
m_Width = 120;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
EDGE_MODULE::~EDGE_MODULE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2009-08-04 18:21:32 +00:00
|
|
|
void EDGE_MODULE::Copy( EDGE_MODULE* source )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-06 20:26:59 +00:00
|
|
|
if( source == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_Start = source->m_Start;
|
|
|
|
m_End = source->m_End;
|
|
|
|
m_Shape = source->m_Shape;
|
2009-11-12 15:43:38 +00:00
|
|
|
m_Start0 = source->m_Start0;
|
|
|
|
m_End0 = source->m_End0;
|
|
|
|
m_Angle = source->m_Angle;
|
2007-08-06 20:26:59 +00:00
|
|
|
m_Layer = source->m_Layer;
|
|
|
|
m_Width = source->m_Width;
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2009-01-18 15:51:06 +00:00
|
|
|
m_PolyPoints = source->m_PolyPoints; // std::vector copy
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
/**
|
|
|
|
* Function GetBoundingBox
|
|
|
|
* returns the orthogonal, bounding box of this object for display purposes.
|
|
|
|
* This box should be an enclosing perimeter for visible components of this
|
|
|
|
* object, and the units should be in the pcb or schematic coordinate system.
|
|
|
|
* It is OK to overestimate the size by a few counts.
|
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT EDGE_MODULE::GetBoundingBox() const
|
2009-11-20 19:51:39 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT bbox;
|
2009-11-20 19:51:39 +00:00
|
|
|
|
|
|
|
bbox.SetOrigin( m_Start );
|
|
|
|
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
|
|
|
bbox.SetEnd( m_End );
|
|
|
|
bbox.Inflate( (m_Width / 2) + 1 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
2011-02-27 19:54:01 +00:00
|
|
|
bbox.Inflate( GetRadius() + 1 );
|
|
|
|
break;
|
2009-11-20 19:51:39 +00:00
|
|
|
|
|
|
|
case S_ARC:
|
|
|
|
{
|
2011-02-27 19:54:01 +00:00
|
|
|
bbox.Inflate( GetRadius() + 1 );
|
2009-11-20 19:51:39 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON:
|
|
|
|
{
|
|
|
|
// We must compute true coordinates from m_PolyPoints
|
|
|
|
// which are relative to module position, orientation 0
|
|
|
|
|
2010-07-11 16:24:44 +00:00
|
|
|
wxPoint p_end;
|
2009-11-20 19:51:39 +00:00
|
|
|
MODULE* Module = (MODULE*) m_Parent;
|
2010-07-11 16:24:44 +00:00
|
|
|
for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ )
|
2009-11-20 19:51:39 +00:00
|
|
|
{
|
2010-07-11 16:24:44 +00:00
|
|
|
wxPoint pt = m_PolyPoints[ii];
|
2009-11-20 19:51:39 +00:00
|
|
|
|
|
|
|
if( Module )
|
|
|
|
{
|
2010-07-11 16:24:44 +00:00
|
|
|
RotatePoint( &pt, Module->m_Orient );
|
2010-06-20 14:47:30 +00:00
|
|
|
pt += Module->m_Pos;
|
2009-11-20 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
2010-07-11 16:24:44 +00:00
|
|
|
if( ii == 0 )
|
|
|
|
p_end = pt;
|
2009-11-20 19:51:39 +00:00
|
|
|
bbox.m_Pos.x = MIN( bbox.m_Pos.x, pt.x );
|
|
|
|
bbox.m_Pos.y = MIN( bbox.m_Pos.y, pt.y );
|
|
|
|
p_end.x = MAX( p_end.x, pt.x );
|
|
|
|
p_end.y = MAX( p_end.y, pt.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
bbox.SetEnd(p_end);
|
|
|
|
bbox.Inflate( 1 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-11 16:24:44 +00:00
|
|
|
bbox.Inflate( (m_Width+1) / 2 );
|
2009-11-20 19:51:39 +00:00
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
void EDGE_MODULE::SetDrawCoord()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-06 20:26:59 +00:00
|
|
|
MODULE* Module = (MODULE*) m_Parent;
|
|
|
|
|
|
|
|
m_Start = m_Start0;
|
|
|
|
m_End = m_End0;
|
|
|
|
|
|
|
|
if( Module )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_Start.x, &m_Start.y, Module->m_Orient );
|
|
|
|
RotatePoint( &m_End.x, &m_End.y, Module->m_Orient );
|
2009-01-18 15:51:06 +00:00
|
|
|
m_Start += Module->m_Pos;
|
|
|
|
m_End += Module->m_Pos;
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Draw EDGE_MODULE:
|
|
|
|
* Entry: offset = offset trace
|
|
|
|
* Draw_mode mode = trace (GR_OR, GR_XOR, GR_AND)
|
|
|
|
* The contours are of different types:
|
|
|
|
* - Segment
|
|
|
|
* - Circles
|
|
|
|
* - Arcs
|
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint& offset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-01 19:26:17 +00:00
|
|
|
int ux0, uy0, dx, dy, rayon, StAngle, EndAngle;
|
|
|
|
int color, type_trace;
|
|
|
|
int typeaff;
|
|
|
|
PCB_SCREEN* screen;
|
|
|
|
PCB_BASE_FRAME* frame;
|
2010-01-31 20:01:46 +00:00
|
|
|
MODULE* module = (MODULE*) m_Parent;
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
if( module == NULL )
|
|
|
|
return;
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
BOARD * brd = GetBoard( );
|
|
|
|
if( brd->IsLayerVisible( m_Layer ) == false )
|
2007-08-06 20:26:59 +00:00
|
|
|
return;
|
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
color = brd->GetLayerColor(m_Layer);
|
2009-10-10 01:25:53 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
frame = (PCB_BASE_FRAME*) panel->GetParent();
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
screen = frame->GetScreen();
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
type_trace = m_Shape;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
|
|
|
ux0 = m_Start.x - offset.x;
|
2007-08-08 03:50:44 +00:00
|
|
|
uy0 = m_Start.y - offset.y;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
dx = m_End.x - offset.x;
|
|
|
|
dy = m_End.y - offset.y;
|
2007-08-06 20:26:59 +00:00
|
|
|
|
|
|
|
GRSetDrawMode( DC, draw_mode );
|
|
|
|
typeaff = frame->m_DisplayModEdge;
|
2007-11-01 05:27:31 +00:00
|
|
|
if( m_Layer <= LAST_COPPER_LAYER )
|
2007-08-06 20:26:59 +00:00
|
|
|
{
|
|
|
|
typeaff = frame->m_DisplayPcbTrackFill;
|
|
|
|
if( !typeaff )
|
|
|
|
typeaff = SKETCH;
|
|
|
|
}
|
2010-02-08 18:15:42 +00:00
|
|
|
|
|
|
|
if( DC->LogicalToDeviceXRel( m_Width ) < L_MIN_DESSIN )
|
2007-08-06 20:26:59 +00:00
|
|
|
typeaff = FILAIRE;
|
|
|
|
|
|
|
|
switch( type_trace )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
|
|
|
if( typeaff == FILAIRE )
|
|
|
|
GRLine( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, 0, color );
|
|
|
|
else if( typeaff == FILLED )
|
|
|
|
GRLine( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, m_Width, color );
|
|
|
|
else
|
|
|
|
// SKETCH Mode
|
|
|
|
GRCSegm( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, m_Width, color );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
|
|
|
rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) );
|
|
|
|
if( typeaff == FILAIRE )
|
|
|
|
{
|
|
|
|
GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon, color );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( typeaff == FILLED )
|
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon,
|
|
|
|
m_Width, color );
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
else // SKETCH Mode
|
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
GRCircle( &panel->m_ClipBox, DC, ux0, uy0,
|
|
|
|
rayon + (m_Width / 2), color );
|
|
|
|
GRCircle( &panel->m_ClipBox, DC, ux0, uy0,
|
|
|
|
rayon - (m_Width / 2), color );
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ARC:
|
|
|
|
rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) );
|
|
|
|
StAngle = (int) ArcTangente( dy - uy0, dx - ux0 );
|
|
|
|
EndAngle = StAngle + m_Angle;
|
|
|
|
if( StAngle > EndAngle )
|
|
|
|
EXCHG( StAngle, EndAngle );
|
|
|
|
if( typeaff == FILAIRE )
|
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle,
|
|
|
|
rayon, color );
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
else if( typeaff == FILLED )
|
|
|
|
{
|
|
|
|
GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, rayon,
|
|
|
|
m_Width, color );
|
|
|
|
}
|
|
|
|
else // SKETCH Mode
|
|
|
|
{
|
|
|
|
GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle,
|
|
|
|
rayon + (m_Width / 2), color );
|
|
|
|
GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle,
|
|
|
|
rayon - (m_Width / 2), color );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON:
|
2009-11-20 19:51:39 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
// We must compute true coordinates from m_PolyPoints
|
|
|
|
// which are relative to module position, orientation 0
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
std::vector<wxPoint> points = m_PolyPoints;
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
for( unsigned ii = 0; ii < points.size(); ii++ )
|
|
|
|
{
|
|
|
|
wxPoint& pt = points[ii];
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
RotatePoint( &pt.x, &pt.y, module->m_Orient );
|
2010-07-11 16:24:44 +00:00
|
|
|
pt += module->m_Pos - offset;
|
2008-12-29 18:02:54 +00:00
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
GRPoly( &panel->m_ClipBox, DC, points.size(), &points[0],
|
|
|
|
TRUE, m_Width, color, color );
|
2007-08-06 20:26:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
|
2008-02-19 00:30:10 +00:00
|
|
|
// see class_edge_mod.h
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDGE_MODULE::DisplayInfo( EDA_DRAW_FRAME* frame )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-10-11 15:13:39 +00:00
|
|
|
wxString msg;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
MODULE* module = (MODULE*) m_Parent;
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
if( !module )
|
|
|
|
return;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
BOARD* board = (BOARD*) module->GetParent();
|
2008-02-19 00:30:10 +00:00
|
|
|
if( !board )
|
|
|
|
return;
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->ClearMsgPanel();
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Graphic Item" ), wxEmptyString, DARKCYAN );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
frame->AppendMsgPanel( _( "Module" ), module->m_Reference->m_Text,
|
|
|
|
DARKCYAN );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Value" ), module->m_Value->m_Text, BLUE );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-10-11 15:13:39 +00:00
|
|
|
msg.Printf( wxT( "%8.8lX" ), module->m_TimeStamp );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "TimeStamp" ), msg, BROWN );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
frame->AppendMsgPanel( _( "Mod Layer" ),
|
|
|
|
board->GetLayerName( module->GetLayer() ), RED );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
frame->AppendMsgPanel( _( "Seg Layer" ),
|
|
|
|
board->GetLayerName( GetLayer() ), RED );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-10-11 15:13:39 +00:00
|
|
|
valeur_param( m_Width, msg );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Width" ), msg, BLUE );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2008-01-31 20:53:44 +00:00
|
|
|
/*******************************************/
|
2007-10-30 21:30:58 +00:00
|
|
|
bool EDGE_MODULE::Save( FILE* aFile ) const
|
2008-01-31 20:53:44 +00:00
|
|
|
/*******************************************/
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
|
|
|
ret = fprintf( aFile, "DS %d %d %d %d %d %d\n",
|
2009-11-12 15:43:38 +00:00
|
|
|
m_Start0.x, m_Start0.y,
|
|
|
|
m_End0.x, m_End0.y,
|
|
|
|
m_Width, m_Layer );
|
2007-10-30 21:30:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
|
|
|
ret = fprintf( aFile, "DC %d %d %d %d %d %d\n",
|
2009-11-12 15:43:38 +00:00
|
|
|
m_Start0.x, m_Start0.y,
|
|
|
|
m_End0.x, m_End0.y,
|
|
|
|
m_Width, m_Layer );
|
2007-10-30 21:30:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ARC:
|
|
|
|
ret = fprintf( aFile, "DA %d %d %d %d %d %d %d\n",
|
2009-11-12 15:43:38 +00:00
|
|
|
m_Start0.x, m_Start0.y,
|
|
|
|
m_End0.x, m_End0.y,
|
|
|
|
m_Angle,
|
|
|
|
m_Width, m_Layer );
|
2007-10-30 21:30:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON:
|
|
|
|
ret = fprintf( aFile, "DP %d %d %d %d %d %d %d\n",
|
2009-05-21 17:42:42 +00:00
|
|
|
m_Start0.x, m_Start0.y,
|
|
|
|
m_End0.x, m_End0.y,
|
2009-11-20 19:51:39 +00:00
|
|
|
(int) m_PolyPoints.size(),
|
2009-05-21 17:42:42 +00:00
|
|
|
m_Width, m_Layer );
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
for( unsigned i = 0; i<m_PolyPoints.size(); ++i )
|
2009-11-12 15:43:38 +00:00
|
|
|
fprintf( aFile, "Dl %d %d\n", m_PolyPoints[i].x,
|
|
|
|
m_PolyPoints[i].y );
|
2009-11-20 19:51:39 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-11-20 19:51:39 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
// future: throw an exception here
|
2008-02-19 00:30:10 +00:00
|
|
|
#if defined(DEBUG)
|
2007-10-31 06:40:15 +00:00
|
|
|
printf( "EDGE_MODULE::Save(): unexpected m_Shape: %d\n", m_Shape );
|
2008-02-19 00:30:10 +00:00
|
|
|
#endif
|
2007-10-30 21:30:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
return ret > 5;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
2008-02-19 00:30:10 +00:00
|
|
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Read a description line like:
|
2007-08-06 20:26:59 +00:00
|
|
|
* DS 2600 0 2600 -600 120 21
|
|
|
|
* this description line is in Line
|
|
|
|
* EDGE_MODULE type can be:
|
|
|
|
* - Circle,
|
|
|
|
* - Segment (line)
|
|
|
|
* - Arc
|
|
|
|
* - Polygon
|
2008-02-19 00:30:10 +00:00
|
|
|
*
|
2007-08-06 20:26:59 +00:00
|
|
|
*/
|
2011-01-14 17:43:30 +00:00
|
|
|
int EDGE_MODULE::ReadDescr( LINE_READER* aReader )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-29 18:02:54 +00:00
|
|
|
int ii;
|
2007-08-06 20:26:59 +00:00
|
|
|
int error = 0;
|
2011-01-14 17:43:30 +00:00
|
|
|
char* Buf;
|
|
|
|
char* Line;
|
|
|
|
|
|
|
|
Line = aReader->Line();
|
2007-08-06 20:26:59 +00:00
|
|
|
|
|
|
|
switch( Line[1] )
|
|
|
|
{
|
|
|
|
case 'S':
|
|
|
|
m_Shape = S_SEGMENT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C':
|
|
|
|
m_Shape = S_CIRCLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'A':
|
|
|
|
m_Shape = S_ARC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P':
|
|
|
|
m_Shape = S_POLYGON;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( wxT( "Unknown EDGE_MODULE type <%s>" ), Line );
|
|
|
|
DisplayError( NULL, msg );
|
|
|
|
error = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
2009-11-20 19:51:39 +00:00
|
|
|
case S_ARC:
|
2007-08-06 20:26:59 +00:00
|
|
|
sscanf( Line + 3, "%d %d %d %d %d %d %d",
|
|
|
|
&m_Start0.x, &m_Start0.y,
|
|
|
|
&m_End0.x, &m_End0.y,
|
|
|
|
&m_Angle, &m_Width, &m_Layer );
|
2011-01-05 17:28:55 +00:00
|
|
|
NORMALIZE_ANGLE_360( m_Angle );
|
2007-08-06 20:26:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_SEGMENT:
|
|
|
|
case S_CIRCLE:
|
|
|
|
sscanf( Line + 3, "%d %d %d %d %d %d",
|
|
|
|
&m_Start0.x, &m_Start0.y,
|
|
|
|
&m_End0.x, &m_End0.y,
|
|
|
|
&m_Width, &m_Layer );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON:
|
2008-12-29 18:02:54 +00:00
|
|
|
int pointCount;
|
2007-08-06 20:26:59 +00:00
|
|
|
sscanf( Line + 3, "%d %d %d %d %d %d %d",
|
|
|
|
&m_Start0.x, &m_Start0.y,
|
|
|
|
&m_End0.x, &m_End0.y,
|
2008-12-29 18:02:54 +00:00
|
|
|
&pointCount, &m_Width, &m_Layer );
|
|
|
|
|
|
|
|
m_PolyPoints.clear();
|
|
|
|
m_PolyPoints.reserve( pointCount );
|
|
|
|
for( ii = 0; ii<pointCount; ii++ )
|
2007-08-06 20:26:59 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
if( aReader->ReadLine() )
|
2007-08-06 20:26:59 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Buf = aReader->Line();
|
2007-08-06 20:26:59 +00:00
|
|
|
if( strncmp( Buf, "Dl", 2 ) != 0 )
|
|
|
|
{
|
2008-12-29 18:02:54 +00:00
|
|
|
error = 1;
|
|
|
|
break;
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
2008-12-29 18:02:54 +00:00
|
|
|
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
sscanf( Buf + 3, "%d %d\n", &x, &y );
|
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
m_PolyPoints.push_back( wxPoint( x, y ) );
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-29 18:02:54 +00:00
|
|
|
error = 1;
|
|
|
|
break;
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sscanf( Line + 3, "%d %d %d %d %d %d",
|
|
|
|
&m_Start0.x, &m_Start0.y,
|
|
|
|
&m_End0.x, &m_End0.y,
|
|
|
|
&m_Width, &m_Layer );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// Check for a reasonable width:
|
2007-08-06 20:26:59 +00:00
|
|
|
if( m_Width <= 1 )
|
|
|
|
m_Width = 1;
|
|
|
|
if( m_Width > MAX_WIDTH )
|
|
|
|
m_Width = MAX_WIDTH;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// Check for a reasonable layer:
|
2008-02-19 00:30:10 +00:00
|
|
|
// m_Layer must be >= FIRST_NON_COPPER_LAYER, but because microwave footprints
|
|
|
|
// can use the copper layers m_Layer < FIRST_NON_COPPER_LAYER is allowed.
|
|
|
|
// @todo: changes use of EDGE_MODULE these footprints and allows only m_Layer >= FIRST_NON_COPPER_LAYER
|
2009-11-20 19:51:39 +00:00
|
|
|
if( (m_Layer < 0) || (m_Layer > LAST_NON_COPPER_LAYER) )
|
2009-12-21 17:56:25 +00:00
|
|
|
m_Layer = SILKSCREEN_N_FRONT;
|
2007-08-06 20:26:59 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-27 19:54:01 +00:00
|
|
|
wxPoint EDGE_MODULE::GetStart() const
|
|
|
|
{
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case S_ARC:
|
|
|
|
return m_End; // the start of the arc is held in field m_End, center point is in m_Start.
|
|
|
|
|
|
|
|
case S_SEGMENT:
|
|
|
|
default:
|
|
|
|
return m_Start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxPoint EDGE_MODULE::GetEnd() const
|
|
|
|
{
|
|
|
|
wxPoint endPoint; // start of arc
|
|
|
|
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case S_ARC:
|
|
|
|
// rotate the starting point of the arc, given by m_End, through the
|
|
|
|
// angle m_Angle to get the ending point of the arc.
|
|
|
|
// m_Start is the arc centre
|
|
|
|
endPoint = m_End; // m_End = start point of arc
|
|
|
|
RotatePoint( &endPoint, m_Start, -m_Angle );
|
|
|
|
return endPoint; // after rotation, the end of the arc.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_SEGMENT:
|
|
|
|
default:
|
|
|
|
return m_End;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-08 20:51:08 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2010-12-29 17:47:32 +00:00
|
|
|
bool EDGE_MODULE::HitTest( const wxPoint& refPos )
|
2007-08-08 20:51:08 +00:00
|
|
|
{
|
2009-11-20 19:51:39 +00:00
|
|
|
int rayon, dist;
|
2007-08-08 20:51:08 +00:00
|
|
|
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
2011-02-27 19:54:01 +00:00
|
|
|
if( TestSegmentHit( refPos, m_Start, m_End, m_Width / 2 ) )
|
2007-08-08 20:51:08 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
2011-02-27 19:54:01 +00:00
|
|
|
rayon = GetRadius();
|
|
|
|
dist = (int) hypot( (double) (refPos.x - m_Start.x), (double) (refPos.y - m_Start.y) );
|
|
|
|
if( abs( rayon - dist ) <= (m_Width/2) )
|
2007-08-08 20:51:08 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ARC:
|
2011-02-27 19:54:01 +00:00
|
|
|
rayon = GetRadius();
|
|
|
|
dist = (int) hypot( (double) (refPos.x - m_Start.x), (double) (refPos.y - m_Start.y) );
|
2007-08-08 20:51:08 +00:00
|
|
|
|
2011-02-27 19:54:01 +00:00
|
|
|
if( abs( rayon - dist ) > (m_Width/2) )
|
2007-08-08 20:51:08 +00:00
|
|
|
break;
|
|
|
|
|
2011-02-27 19:54:01 +00:00
|
|
|
int mouseAngle = ArcTangente( refPos.y - m_Start.y, refPos.x - m_Start.x );
|
|
|
|
int stAngle = ArcTangente( m_End.y - m_Start.y, m_End.x - m_Start.x );
|
2007-08-08 20:51:08 +00:00
|
|
|
int endAngle = stAngle + m_Angle;
|
|
|
|
|
|
|
|
if( endAngle > 3600 )
|
|
|
|
{
|
2008-02-19 00:30:10 +00:00
|
|
|
stAngle -= 3600;
|
2007-08-08 20:51:08 +00:00
|
|
|
endAngle -= 3600;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (mouseAngle >= stAngle) && (mouseAngle <= endAngle) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-19 00:30:10 +00:00
|
|
|
return false; // an unknown m_Shape also returns false
|
2007-08-08 20:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-27 19:54:01 +00:00
|
|
|
/**
|
|
|
|
* Function HitTest (overlayed)
|
2011-03-29 19:33:07 +00:00
|
|
|
* tests if the given EDA_RECT intersect this object.
|
2011-02-27 19:54:01 +00:00
|
|
|
* For now, for arcs and segments, an ending point must be inside this rect.
|
2011-03-29 19:33:07 +00:00
|
|
|
* @param refArea : the given EDA_RECT
|
2011-02-27 19:54:01 +00:00
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
bool EDGE_MODULE::HitTest( EDA_RECT& refArea )
|
2011-02-27 19:54:01 +00:00
|
|
|
{
|
|
|
|
switch(m_Shape)
|
|
|
|
{
|
|
|
|
case S_CIRCLE:
|
|
|
|
{
|
|
|
|
int radius = GetRadius();
|
|
|
|
// Test if area intersects the circle:
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT area = refArea;
|
2011-02-27 19:54:01 +00:00
|
|
|
area.Inflate(radius);
|
|
|
|
if( area.Contains(m_Start) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ARC:
|
|
|
|
case S_SEGMENT:
|
|
|
|
if( refArea.Contains( GetStart() ) )
|
|
|
|
return true;
|
|
|
|
if( refArea.Contains( GetEnd() ) )
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
#if defined(DEBUG)
|
2008-02-22 17:34:11 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2008-02-22 17:34:11 +00:00
|
|
|
/**
|
|
|
|
* Function Show
|
|
|
|
* is used to output the object tree, currently for debugging only.
|
|
|
|
* @param nestLevel An aid to prettier tree indenting, and is the level
|
|
|
|
* of nesting of this object within the overall tree.
|
|
|
|
* @param os The ostream& to output to.
|
|
|
|
*/
|
|
|
|
void EDGE_MODULE::Show( int nestLevel, std::ostream& os )
|
|
|
|
{
|
2008-05-05 19:53:18 +00:00
|
|
|
wxString shape = ShowShape( (Track_Shapes) m_Shape );
|
2008-02-22 17:34:11 +00:00
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
// for now, make it look like XML:
|
2008-02-19 00:30:10 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() <<
|
2011-02-28 18:36:19 +00:00
|
|
|
" type=\"" << TO_UTF8( shape ) << "\">";
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2007-08-09 01:41:30 +00:00
|
|
|
os << " <start" << m_Start0 << "/>";
|
|
|
|
os << " <end" << m_End0 << "/>";
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2007-08-09 01:41:30 +00:00
|
|
|
os << " </" << GetClass().Lower().mb_str() << ">\n";
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
#endif
|