2012-01-14 19:50:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file class_edge_mod.cpp
|
|
|
|
* @brief EDGE_MODULE class definition.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <colors_selection.h>
|
|
|
|
#include <richio.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <wxBasePcbFrame.h>
|
|
|
|
#include <pcbcommon.h>
|
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_edge_mod.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
|
|
|
|
2011-12-01 22:50:41 +00:00
|
|
|
EDGE_MODULE::EDGE_MODULE( MODULE* parent, STROKE_T aShape ) :
|
2011-10-01 19:24:27 +00:00
|
|
|
DRAWSEGMENT( parent, PCB_MODULE_EDGE_T )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-01 22:50:41 +00:00
|
|
|
m_Shape = aShape;
|
2009-11-20 19:51:39 +00:00
|
|
|
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;
|
|
|
|
|
2011-08-08 23:50:55 +00:00
|
|
|
DRAWSEGMENT::Copy( source );
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
m_Start0 = source->m_Start0;
|
|
|
|
m_End0 = source->m_End0;
|
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
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
void EDGE_MODULE::SetDrawCoord()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-11-29 17:25:30 +00:00
|
|
|
MODULE* module = (MODULE*) m_Parent;
|
2007-08-06 20:26:59 +00:00
|
|
|
|
|
|
|
m_Start = m_Start0;
|
|
|
|
m_End = m_End0;
|
|
|
|
|
2011-11-29 17:25:30 +00:00
|
|
|
if( module )
|
2007-08-06 20:26:59 +00:00
|
|
|
{
|
2011-11-29 17:25:30 +00:00
|
|
|
RotatePoint( &m_Start.x, &m_Start.y, module->GetOrientation() );
|
|
|
|
RotatePoint( &m_End.x, &m_End.y, module->GetOrientation() );
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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-09-07 19:41:04 +00:00
|
|
|
int ux0, uy0, dx, dy, radius, StAngle, EndAngle;
|
2011-03-01 19:26:17 +00:00
|
|
|
int color, type_trace;
|
|
|
|
int typeaff;
|
|
|
|
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( );
|
2011-08-08 23:50:55 +00:00
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
if( brd->IsLayerVisible( m_Layer ) == false )
|
2007-08-06 20:26:59 +00:00
|
|
|
return;
|
|
|
|
|
2011-08-08 23:50:55 +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
|
|
|
|
|
|
|
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;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
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;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
if( !typeaff )
|
|
|
|
typeaff = SKETCH;
|
|
|
|
}
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2011-09-24 18:33:28 +00:00
|
|
|
if( DC->LogicalToDeviceXRel( m_Width ) < MIN_DRAW_WIDTH )
|
2012-01-03 17:14:17 +00:00
|
|
|
typeaff = LINE;
|
2007-08-06 20:26:59 +00:00
|
|
|
|
|
|
|
switch( type_trace )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
2012-01-03 17:14:17 +00:00
|
|
|
if( typeaff == LINE )
|
2011-12-29 20:11:42 +00:00
|
|
|
GRLine( panel->GetClipBox(), DC, ux0, uy0, dx, dy, 0, color );
|
2007-08-06 20:26:59 +00:00
|
|
|
else if( typeaff == FILLED )
|
2011-12-29 20:11:42 +00:00
|
|
|
GRLine( panel->GetClipBox(), DC, ux0, uy0, dx, dy, m_Width, color );
|
2007-08-06 20:26:59 +00:00
|
|
|
else
|
|
|
|
// SKETCH Mode
|
2011-12-29 20:11:42 +00:00
|
|
|
GRCSegm( panel->GetClipBox(), DC, ux0, uy0, dx, dy, m_Width, color );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
2011-09-07 19:41:04 +00:00
|
|
|
radius = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) );
|
|
|
|
|
2012-01-03 17:14:17 +00:00
|
|
|
if( typeaff == LINE )
|
2007-08-06 20:26:59 +00:00
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
GRCircle( panel->GetClipBox(), DC, ux0, uy0, radius, color );
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( typeaff == FILLED )
|
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
GRCircle( panel->GetClipBox(), DC, ux0, uy0, radius, m_Width, color );
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
else // SKETCH Mode
|
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
GRCircle( panel->GetClipBox(), DC, ux0, uy0, radius + (m_Width / 2), color );
|
|
|
|
GRCircle( panel->GetClipBox(), DC, ux0, uy0, radius - (m_Width / 2), color );
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ARC:
|
2011-09-07 19:41:04 +00:00
|
|
|
radius = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) );
|
2007-08-06 20:26:59 +00:00
|
|
|
StAngle = (int) ArcTangente( dy - uy0, dx - ux0 );
|
|
|
|
EndAngle = StAngle + m_Angle;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
if( StAngle > EndAngle )
|
|
|
|
EXCHG( StAngle, EndAngle );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-01-03 17:14:17 +00:00
|
|
|
if( typeaff == LINE )
|
2007-08-06 20:26:59 +00:00
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
GRArc( panel->GetClipBox(), DC, ux0, uy0, StAngle, EndAngle, radius, color );
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
else if( typeaff == FILLED )
|
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
GRArc( panel->GetClipBox(), DC, ux0, uy0, StAngle, EndAngle, radius, m_Width, color );
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
else // SKETCH Mode
|
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
GRArc( panel->GetClipBox(), DC, ux0, uy0, StAngle, EndAngle,
|
2011-09-07 19:41:04 +00:00
|
|
|
radius + (m_Width / 2), color );
|
2011-12-29 20:11:42 +00:00
|
|
|
GRArc( panel->GetClipBox(), DC, ux0, uy0, StAngle, EndAngle,
|
2011-09-07 19:41:04 +00:00
|
|
|
radius - (m_Width / 2), color );
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2011-06-06 06:51:42 +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
|
|
|
|
2011-11-29 17:25:30 +00:00
|
|
|
RotatePoint( &pt.x, &pt.y, module->GetOrientation() );
|
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
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
GRPoly( panel->GetClipBox(), 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();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
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 );
|
2011-09-07 19:41:04 +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
|
|
|
|
2011-12-12 08:37:05 +00:00
|
|
|
msg.Printf( wxT( "%8.8lX" ), module->GetTimeStamp() );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "TimeStamp" ), msg, BROWN );
|
2011-09-07 19:41:04 +00:00
|
|
|
frame->AppendMsgPanel( _( "Mod Layer" ), board->GetLayerName( module->GetLayer() ), RED );
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
2011-07-14 15:42:44 +00:00
|
|
|
wxString EDGE_MODULE::GetSelectMenuText() const
|
|
|
|
{
|
|
|
|
wxString text;
|
|
|
|
|
2011-12-01 22:50:41 +00:00
|
|
|
text << _( "Graphic" ) << wxT( " " ) << ShowShape( (STROKE_T) m_Shape );
|
2011-07-14 15:42:44 +00:00
|
|
|
text << wxT( " (" ) << GetLayerName() << wxT( ")" );
|
|
|
|
text << _( " of " ) << ( (MODULE*) GetParent() )->GetReference();
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-14 19:50:32 +00:00
|
|
|
EDA_ITEM* EDGE_MODULE::doClone() const
|
|
|
|
{
|
|
|
|
return new EDGE_MODULE( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-14 15:42:44 +00:00
|
|
|
#if defined(DEBUG)
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
void EDGE_MODULE::Show( int nestLevel, std::ostream& os ) const
|
2008-02-22 17:34:11 +00:00
|
|
|
{
|
2011-12-01 22:50:41 +00:00
|
|
|
wxString shape = ShowShape( (STROKE_T) 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
|