2012-01-14 19:50:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-01-14 19:50:32 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2012-02-28 20:14:17 +00:00
|
|
|
#include <class_pcb_screen.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <colors_selection.h>
|
|
|
|
#include <richio.h>
|
|
|
|
#include <macros.h>
|
2013-05-01 17:32:36 +00:00
|
|
|
#include <math_for_graphics.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wxBasePcbFrame.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <msgpanel.h>
|
|
|
|
#include <base_units.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_edge_mod.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-02-28 20:14:17 +00:00
|
|
|
#include <stdio.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;
|
2014-06-24 16:17:18 +00:00
|
|
|
m_Layer = F_SilkS;
|
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
|
|
|
|
2013-11-19 18:58:12 +00:00
|
|
|
const EDGE_MODULE& EDGE_MODULE::operator = ( const EDGE_MODULE& rhs )
|
|
|
|
{
|
|
|
|
if( &rhs == this )
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
DRAWSEGMENT::operator=( rhs );
|
|
|
|
|
|
|
|
m_Start0 = rhs.m_Start0;
|
|
|
|
m_End0 = rhs.m_End0;
|
|
|
|
|
|
|
|
m_PolyPoints = rhs.m_PolyPoints; // std::vector copy
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-11-19 18:58:12 +00:00
|
|
|
*this = *source;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2014-07-09 09:59:24 +00:00
|
|
|
void EDGE_MODULE::SetLocalCoord()
|
|
|
|
{
|
|
|
|
MODULE* module = (MODULE*) m_Parent;
|
|
|
|
|
|
|
|
if( module == NULL )
|
|
|
|
{
|
|
|
|
m_Start0 = m_Start;
|
|
|
|
m_End0 = m_End;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Start0 = m_Start - module->GetPosition();
|
|
|
|
m_End0 = m_End - module->GetPosition();
|
|
|
|
double angle = module->GetOrientation();
|
|
|
|
RotatePoint( &m_Start0.x, &m_Start0.y, -angle );
|
|
|
|
RotatePoint( &m_End0.x, &m_End0.y, -angle );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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() );
|
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
m_Start += module->GetPosition();
|
|
|
|
m_End += module->GetPosition();
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-01 13:38:27 +00:00
|
|
|
void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
|
|
|
|
const wxPoint& offset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2014-06-29 13:05:51 +00:00
|
|
|
int ux0, uy0, dx, dy, radius, StAngle, EndAngle;
|
|
|
|
int typeaff;
|
|
|
|
LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
|
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
MODULE* module = (MODULE*) m_Parent;
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2014-06-29 13:05:51 +00:00
|
|
|
if( !module )
|
2010-01-31 20:01:46 +00:00
|
|
|
return;
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2014-06-29 13:05:51 +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;
|
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T color = brd->GetLayerColor( m_Layer );
|
2015-01-10 10:27:49 +00:00
|
|
|
DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)panel->GetDisplayOptions();
|
2009-10-10 01:25:53 +00:00
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
if(( draw_mode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && displ_opts->m_ContrastModeDisplay )
|
2012-02-28 20:14:17 +00:00
|
|
|
{
|
|
|
|
if( !IsOnLayer( curr_layer ) )
|
2012-09-02 12:06:47 +00:00
|
|
|
ColorTurnToDarkDarkGray( &color );
|
2012-02-28 20:14:17 +00:00
|
|
|
}
|
|
|
|
|
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 );
|
2015-01-10 10:27:49 +00:00
|
|
|
typeaff = displ_opts ? displ_opts->m_DisplayModEdge : FILLED;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( IsCopperLayer( m_Layer ) )
|
2007-08-06 20:26:59 +00:00
|
|
|
{
|
2015-01-10 10:27:49 +00:00
|
|
|
typeaff = displ_opts ? displ_opts->m_DisplayPcbTrackFill : FILLED;
|
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
|
|
|
|
2013-04-09 17:16:53 +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
|
|
|
|
2014-09-24 16:42:56 +00:00
|
|
|
switch( m_Shape )
|
2007-08-06 20:26:59 +00:00
|
|
|
{
|
|
|
|
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:
|
2013-05-01 17:32:36 +00:00
|
|
|
radius = KiROUND( Distance( ux0, uy0, dx, dy ) );
|
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
|
|
|
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:
|
2013-05-01 17:32:36 +00:00
|
|
|
radius = KiROUND( Distance( ux0, uy0, dx, dy ) );
|
|
|
|
StAngle = ArcTangente( dy - uy0, dx - ux0 );
|
2007-08-06 20:26:59 +00:00
|
|
|
EndAngle = StAngle + m_Angle;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-02-12 10:03:34 +00:00
|
|
|
if( !panel->GetPrintMirrored() )
|
|
|
|
{
|
|
|
|
if( StAngle > EndAngle )
|
|
|
|
EXCHG( StAngle, EndAngle );
|
|
|
|
}
|
|
|
|
else // Mirrored mode: arc orientation is reversed
|
|
|
|
{
|
|
|
|
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:
|
2014-09-24 16:42:56 +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
|
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() );
|
2013-03-13 18:53:58 +00:00
|
|
|
pt += module->GetPosition() - 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 );
|
2014-09-24 16:42:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
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
|
2013-01-12 17:32:24 +00:00
|
|
|
void EDGE_MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
|
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;
|
|
|
|
|
2014-11-15 19:06:05 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Footprint" ), module->GetReference(), DARKCYAN ) );
|
2013-03-13 18:53:58 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Value" ), module->GetValue(), BLUE ) );
|
2011-12-12 08:37:05 +00:00
|
|
|
msg.Printf( wxT( "%8.8lX" ), module->GetTimeStamp() );
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "TimeStamp" ), msg, BROWN ) );
|
2014-11-15 19:06:05 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Footprint Layer" ),
|
2013-04-07 11:55:18 +00:00
|
|
|
module->GetLayerName(), RED ) );
|
2014-11-15 13:09:59 +00:00
|
|
|
|
|
|
|
// append the features shared with the base class
|
|
|
|
DRAWSEGMENT::GetMsgPanelInfo( aList );
|
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;
|
2013-04-09 17:49:01 +00:00
|
|
|
text.Printf( _( "Graphic (%s) on %s of %s" ),
|
|
|
|
GetChars( ShowShape( (STROKE_T) m_Shape ) ),
|
|
|
|
GetChars( GetLayerName() ),
|
|
|
|
GetChars( ((MODULE*) GetParent())->GetReference() ) );
|
2011-07-14 15:42:44 +00:00
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* EDGE_MODULE::Clone() const
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
|
|
|
return new EDGE_MODULE( *this );
|
|
|
|
}
|
|
|
|
|
2014-09-24 16:42:56 +00:00
|
|
|
|
2014-11-15 19:06:05 +00:00
|
|
|
void EDGE_MODULE::Flip( const wxPoint& aCentre )
|
2014-09-24 16:42:56 +00:00
|
|
|
{
|
|
|
|
wxPoint pt;
|
|
|
|
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case S_ARC:
|
|
|
|
SetAngle( -GetAngle() );
|
|
|
|
//Fall through
|
|
|
|
default:
|
|
|
|
case S_SEGMENT:
|
|
|
|
pt = GetStart();
|
|
|
|
pt.y -= aCentre.y;
|
|
|
|
pt.y = -pt.y;
|
|
|
|
pt.y += aCentre.y;
|
|
|
|
SetStart( pt );
|
|
|
|
|
|
|
|
pt = GetEnd();
|
|
|
|
pt.y -= aCentre.y;
|
|
|
|
pt.y = -pt.y;
|
|
|
|
pt.y += aCentre.y;
|
|
|
|
SetEnd( pt );
|
|
|
|
|
|
|
|
NEGATE( m_Start0.y );
|
|
|
|
NEGATE( m_End0.y );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON:
|
|
|
|
// polygon corners coordinates are always relative to the
|
|
|
|
// footprint position, orientation 0
|
|
|
|
for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ )
|
|
|
|
NEGATE( m_PolyPoints[ii].y );
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLayer( FlipLayer( GetLayer() ) );
|
|
|
|
}
|