2011-12-08 15:45:01 +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) 2004-2011 KiCad Developers, see change_log.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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file sch_polyline.cpp
|
|
|
|
*/
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <richio.h>
|
|
|
|
|
|
|
|
#include <general.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <sch_polyline.h>
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
SCH_POLYLINE::SCH_POLYLINE( int layer ) :
|
|
|
|
SCH_ITEM( NULL, SCH_POLYLINE_T )
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_width = 0;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
switch( layer )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
m_Layer = LAYER_NOTES;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_WIRE:
|
|
|
|
case LAYER_NOTES:
|
|
|
|
case LAYER_BUS:
|
|
|
|
m_Layer = layer;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_POLYLINE::~SCH_POLYLINE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_POLYLINE::Clone() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
return new SCH_POLYLINE( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_POLYLINE::Save( FILE* aFile ) const
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
const char* layer = "Notes";
|
|
|
|
const char* width = "Line";
|
|
|
|
|
|
|
|
if( GetLayer() == LAYER_WIRE )
|
|
|
|
layer = "Wire";
|
|
|
|
|
|
|
|
if( GetLayer() == LAYER_BUS )
|
|
|
|
layer = "Bus";
|
|
|
|
|
|
|
|
if( fprintf( aFile, "Poly %s %s %d\n", width, layer, GetCornerCount() ) == EOF )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < GetCornerCount(); ii++ )
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
if( fprintf( aFile, "\t%-4d %-4d\n", m_points[ii ].x, m_points[ii].y ) == EOF )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_POLYLINE::Load( LINE_READER& aLine, wxString& aErrorMsg )
|
|
|
|
{
|
|
|
|
char Name1[256];
|
|
|
|
char Name2[256];
|
|
|
|
wxPoint pt;
|
|
|
|
int ii;
|
|
|
|
char* line = (char*) aLine;
|
|
|
|
|
|
|
|
while( (*line != ' ' ) && *line )
|
|
|
|
line++;
|
|
|
|
|
|
|
|
if( sscanf( line, "%s %s %d", Name1, Name2, &ii ) != 3 )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file polyline struct error at line %d, aborted" ),
|
2011-02-28 18:36:19 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
aErrorMsg << wxT( "\n" ) << FROM_UTF8( (char*) aLine );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Layer = LAYER_NOTES;
|
|
|
|
|
|
|
|
if( Name2[0] == 'W' )
|
|
|
|
m_Layer = LAYER_WIRE;
|
|
|
|
|
|
|
|
if( Name2[0] == 'B' )
|
|
|
|
m_Layer = LAYER_BUS;
|
|
|
|
|
|
|
|
for( unsigned jj = 0; jj < (unsigned)ii; jj++ )
|
|
|
|
{
|
|
|
|
wxPoint point;
|
|
|
|
|
|
|
|
if( !aLine.ReadLine() || sscanf( ((char*) aLine), "%d %d", &pt.x, &pt.y ) != 2 )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file polyline struct error at line %d, aborted" ),
|
2011-02-28 18:36:19 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
aErrorMsg << wxT( "\n" ) << FROM_UTF8( (char*) aLine );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddPoint( pt );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_POLYLINE::GetPenSize() const
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
int pensize = ( m_width == 0 ) ? g_DrawDefaultLineThickness : m_width;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
return pensize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_POLYLINE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
|
|
|
|
int aDrawMode, int aColor )
|
|
|
|
{
|
|
|
|
int color;
|
|
|
|
int width = GetPenSize();
|
|
|
|
|
|
|
|
if( aColor >= 0 )
|
|
|
|
color = aColor;
|
|
|
|
else
|
|
|
|
color = ReturnLayerColor( m_Layer );
|
|
|
|
|
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
|
|
|
|
|
|
|
if( m_Layer == LAYER_BUS )
|
|
|
|
{
|
|
|
|
width *= 3;
|
|
|
|
}
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
GRMoveTo( m_points[0].x, m_points[0].y );
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
if( m_Layer == LAYER_NOTES )
|
|
|
|
{
|
|
|
|
for( unsigned i = 1; i < GetCornerCount(); i++ )
|
2011-12-29 20:11:42 +00:00
|
|
|
GRDashedLineTo( aPanel->GetClipBox(), aDC, m_points[i].x + aOffset.x,
|
2011-12-08 15:45:01 +00:00
|
|
|
m_points[i].y + aOffset.y, width, color );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( unsigned i = 1; i < GetCornerCount(); i++ )
|
2011-12-29 20:11:42 +00:00
|
|
|
GRLineTo( aPanel->GetClipBox(), aDC, m_points[i].x + aOffset.x,
|
2011-12-08 15:45:01 +00:00
|
|
|
m_points[i].y + aOffset.y, width, color );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_POLYLINE::MirrorX( int aXaxis_position )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < GetCornerCount(); ii++ )
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_points[ii].y -= aXaxis_position;
|
|
|
|
NEGATE( m_points[ii].y );
|
|
|
|
m_points[ii].y = aXaxis_position;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_POLYLINE::MirrorY( int aYaxis_position )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < GetCornerCount(); ii++ )
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_points[ii].x -= aYaxis_position;
|
|
|
|
NEGATE( m_points[ii].x );
|
|
|
|
m_points[ii].x = aYaxis_position;
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_POLYLINE::Rotate( wxPoint aPosition )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < GetCornerCount(); ii++ )
|
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
RotatePoint( &m_points[ii], aPosition, 900 );
|
2011-02-28 18:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
wxString SCH_POLYLINE::GetSelectMenuText() const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-03-26 10:08:50 +00:00
|
|
|
wxString menuText, fmt;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
switch( m_Layer )
|
|
|
|
{
|
|
|
|
case LAYER_NOTES:
|
2011-03-26 10:08:50 +00:00
|
|
|
fmt = _( "Graphic Polyline with %d Points" );
|
2011-03-25 19:16:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_WIRE:
|
2011-03-26 10:08:50 +00:00
|
|
|
fmt = _( "Polyline Wire with %d Points" );
|
2011-03-25 19:16:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_BUS:
|
2011-03-26 10:08:50 +00:00
|
|
|
fmt = _( "Polyline Bus with %d Points" );
|
2011-03-25 19:16:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-03-26 10:08:50 +00:00
|
|
|
fmt = _( "Polyline on Unkown Layer with %d Points" );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
menuText.Printf( fmt, m_points.size() );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
return menuText;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-29 03:04:59 +00:00
|
|
|
BITMAP_DEF SCH_POLYLINE::GetMenuImage() const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
|
|
|
if( m_Layer == LAYER_NOTES )
|
2011-08-29 03:04:59 +00:00
|
|
|
return add_dashed_line_xpm;
|
2011-03-25 19:16:05 +00:00
|
|
|
else if( m_Layer == LAYER_WIRE )
|
2011-08-29 03:04:59 +00:00
|
|
|
return add_line_xpm;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-08-29 03:04:59 +00:00
|
|
|
return add_bus_xpm;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_POLYLINE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
for( size_t i = 0; i < m_points.size() - 1; i++ )
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
if( TestSegmentHit( aPosition, m_points[i], m_points[i + 1], aAccuracy ) )
|
2011-02-28 18:36:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_POLYLINE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2011-02-28 18:36:19 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = aRect;
|
2011-02-28 18:36:19 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return rect.Contains( GetBoundingBox() );
|
|
|
|
|
|
|
|
return rect.Intersects( GetBoundingBox() );
|
|
|
|
}
|
2011-10-19 20:32:21 +00:00
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_POLYLINE::SetPosition( const wxPoint& aPosition )
|
2011-10-19 20:32:21 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
wxPoint offset = m_points[0] - aPosition;
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
for( size_t i = 0; i < m_points.size(); i++ )
|
|
|
|
m_points[i] = m_points[i] - offset;
|
2011-10-19 20:32:21 +00:00
|
|
|
}
|
|
|
|
|