2008-09-13 18:59:57 +00:00
|
|
|
/************************/
|
|
|
|
/* class_body_items.cpp */
|
|
|
|
/************************/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2009-10-05 17:52:41 +00:00
|
|
|
#include "plot_common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "drawtxt.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "trigo.h"
|
2009-06-25 20:45:27 +00:00
|
|
|
#include "bezier_curves.h"
|
2009-12-15 21:11:05 +00:00
|
|
|
#include "confirm.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2008-09-13 18:59:57 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "classes_body_items.h"
|
2008-09-13 18:59:57 +00:00
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
static int fill_tab[3] = { 'N', 'F', 'f' };
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
//#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
|
2008-09-13 18:59:57 +00:00
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* Base class (abstract) for components bodies items */
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_DRAW_ITEM::LIB_DRAW_ITEM( KICAD_T aType, LIB_COMPONENT* aParent ) :
|
|
|
|
EDA_BaseStruct( aType )
|
2008-09-14 04:27:22 +00:00
|
|
|
{
|
2009-10-20 19:36:58 +00:00
|
|
|
m_Unit = 0; /* Unit identification (for multi part per package)
|
|
|
|
* 0 if the item is common to all units */
|
|
|
|
m_Convert = 0; /* Shape identification (for parts which have a convert
|
|
|
|
* shape) 0 if the item is common to all shapes */
|
|
|
|
m_Fill = NO_FILL;
|
|
|
|
m_Parent = (EDA_BaseStruct*) aParent;
|
|
|
|
m_typeName = _( "Undefined" );
|
|
|
|
m_isFillable = false;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_DRAW_ITEM::LIB_DRAW_ITEM( const LIB_DRAW_ITEM& aItem ) :
|
|
|
|
EDA_BaseStruct( aItem )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Unit = aItem.m_Unit;
|
|
|
|
m_Convert = aItem.m_Convert;
|
|
|
|
m_Fill = aItem.m_Fill;
|
|
|
|
m_Parent = aItem.m_Parent;
|
|
|
|
m_typeName = aItem.m_typeName;
|
|
|
|
m_isFillable = aItem.m_isFillable;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/**
|
|
|
|
* Update the message panel information with the drawing information.
|
|
|
|
*
|
|
|
|
* This base function is used to display the information common to the
|
|
|
|
* all library items. Call the base class from the derived class or the
|
|
|
|
* common information will not be updated in the message panel.
|
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_DRAW_ITEM::DisplayInfo( WinEDA_DrawFrame* aFrame )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->ClearMsgPanel();
|
|
|
|
aFrame->AppendMsgPanel( _( "Type" ), m_typeName, CYAN );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( m_Unit == 0 )
|
|
|
|
msg = _( "All" );
|
|
|
|
else
|
|
|
|
msg.Printf( wxT( "%d" ), m_Unit );
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel( _( "Unit" ), msg, BROWN );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( m_Convert == 0 )
|
|
|
|
msg = _( "All" );
|
|
|
|
else if( m_Convert == 1 )
|
|
|
|
msg = _( "no" );
|
|
|
|
else if( m_Convert == 2 )
|
|
|
|
msg = _( "yes" );
|
|
|
|
else
|
|
|
|
msg = wxT( "?" );
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel( _( "Convert" ), msg, BROWN );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_DRAW_ITEM::operator==( const LIB_DRAW_ITEM& aOther ) const
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
return ( ( Type() == aOther.Type() )
|
|
|
|
&& ( m_Unit == aOther.m_Unit )
|
|
|
|
&& ( m_Convert == aOther.m_Convert )
|
|
|
|
&& DoCompare( aOther ) == 0 );
|
2009-10-01 14:17:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_DRAW_ITEM::operator<( const LIB_DRAW_ITEM& aOther ) const
|
2009-10-01 14:17:47 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
int result = m_Convert - aOther.m_Convert;
|
2009-10-01 14:17:47 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
if( result != 0 )
|
|
|
|
return result < 0;
|
2009-10-01 14:17:47 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
result = m_Unit - aOther.m_Unit;
|
2009-10-01 14:17:47 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
if( result != 0 )
|
|
|
|
return result < 0;
|
2009-10-01 14:17:47 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
result = Type() - aOther.Type();
|
2009-10-01 14:17:47 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
if( result != 0 )
|
|
|
|
return result < 0;
|
2009-10-01 14:17:47 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
return ( DoCompare( aOther ) < 0 );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
/**********************/
|
2009-10-08 13:19:28 +00:00
|
|
|
/** class LIB_ARC **/
|
2009-06-11 14:26:17 +00:00
|
|
|
/**********************/
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_ARC::LIB_ARC( LIB_COMPONENT* aParent ) :
|
2009-09-25 18:49:04 +00:00
|
|
|
LIB_DRAW_ITEM( COMPONENT_ARC_DRAW_TYPE, aParent )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-20 19:36:58 +00:00
|
|
|
m_Radius = 0;
|
|
|
|
m_t1 = 0;
|
|
|
|
m_t2 = 0;
|
|
|
|
m_Width = 0;
|
|
|
|
m_Fill = NO_FILL;
|
|
|
|
m_isFillable = true;
|
|
|
|
m_typeName = _( "Arc" );
|
2008-09-14 04:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_ARC::LIB_ARC( const LIB_ARC& aArc ) : LIB_DRAW_ITEM( aArc )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Radius = aArc.m_Radius;
|
|
|
|
m_t1 = aArc.m_t1;
|
|
|
|
m_t2 = aArc.m_t2;
|
|
|
|
m_Width = aArc.m_Width;
|
|
|
|
m_Fill = aArc.m_Fill;
|
|
|
|
m_Pos = aArc.m_Pos;
|
|
|
|
m_ArcStart = aArc.m_ArcStart;
|
|
|
|
m_ArcEnd = aArc.m_ArcEnd;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/**
|
|
|
|
* format:
|
|
|
|
* A centre_posx centre_posy rayon start_angle end_angle unit convert
|
|
|
|
* fill('N', 'F' ou 'f') startx starty endx endy
|
2008-09-13 18:59:57 +00:00
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_ARC::Save( FILE* aFile )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
int x1 = m_t1;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( x1 > 1800 )
|
|
|
|
x1 -= 3600;
|
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
int x2 = m_t2;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( x2 > 1800 )
|
|
|
|
x2 -= 3600;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( fprintf( aFile, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
|
2009-09-14 13:24:17 +00:00
|
|
|
m_Pos.x, m_Pos.y, m_Radius, x1, x2, m_Unit, m_Convert, m_Width,
|
|
|
|
fill_tab[m_Fill], m_ArcStart.x, m_ArcStart.y, m_ArcEnd.x,
|
|
|
|
m_ArcEnd.y ) < 0 )
|
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_ARC::Load( char* aLine, wxString& aErrorMsg )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
int startx, starty, endx, endy, cnt;
|
2009-04-05 20:49:15 +00:00
|
|
|
char tmp[256];
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
cnt = sscanf( &aLine[2], "%d %d %d %d %d %d %d %d %s %d %d %d %d",
|
2009-09-14 13:24:17 +00:00
|
|
|
&m_Pos.x, &m_Pos.y, &m_Radius, &m_t1, &m_t2, &m_Unit,
|
|
|
|
&m_Convert, &m_Width, tmp, &startx, &starty, &endx, &endy );
|
2009-04-05 20:49:15 +00:00
|
|
|
if( cnt < 8 )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( _( "arc only had %d parameters of the required 8" ),
|
2009-05-21 17:42:42 +00:00
|
|
|
cnt );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( tmp[0] == 'F' )
|
|
|
|
m_Fill = FILLED_SHAPE;
|
|
|
|
if( tmp[0] == 'f' )
|
|
|
|
m_Fill = FILLED_WITH_BG_BODYCOLOR;
|
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
NORMALIZE_ANGLE( m_t1 );
|
|
|
|
NORMALIZE_ANGLE( m_t2 );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
// Actual Coordinates of arc ends are read from file
|
|
|
|
if( cnt >= 13 )
|
|
|
|
{
|
|
|
|
m_ArcStart.x = startx;
|
|
|
|
m_ArcStart.y = starty;
|
|
|
|
m_ArcEnd.x = endx;
|
2009-06-11 14:26:17 +00:00
|
|
|
m_ArcEnd.y = endy;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Actual Coordinates of arc ends are not read from file
|
|
|
|
// (old library), calculate them
|
2009-09-14 13:24:17 +00:00
|
|
|
m_ArcStart.x = m_Radius;
|
2009-04-05 20:49:15 +00:00
|
|
|
m_ArcStart.y = 0;
|
2009-09-14 13:24:17 +00:00
|
|
|
m_ArcEnd.x = m_Radius;
|
2009-06-11 14:26:17 +00:00
|
|
|
m_ArcEnd.y = 0;
|
2009-09-14 13:24:17 +00:00
|
|
|
RotatePoint( &m_ArcStart.x, &m_ArcStart.y, -m_t1 );
|
2009-04-05 20:49:15 +00:00
|
|
|
m_ArcStart.x += m_Pos.x;
|
|
|
|
m_ArcStart.y += m_Pos.y;
|
2009-09-14 13:24:17 +00:00
|
|
|
RotatePoint( &m_ArcEnd.x, &m_ArcEnd.y, -m_t2 );
|
2009-04-05 20:49:15 +00:00
|
|
|
m_ArcEnd.x += m_Pos.x;
|
|
|
|
m_ArcEnd.y += m_Pos.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
/**
|
|
|
|
* Function HitTest
|
|
|
|
* tests if the given wxPoint is within the bounds of this object.
|
2009-06-13 17:06:07 +00:00
|
|
|
* @param aRefPoint A wxPoint to test in eeschema space
|
2009-06-11 14:26:17 +00:00
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
bool LIB_ARC::HitTest( const wxPoint& aRefPoint )
|
2009-06-11 14:26:17 +00:00
|
|
|
{
|
2009-06-18 13:30:52 +00:00
|
|
|
int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;
|
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
// Have a minimal tolerance for hit test
|
2010-02-04 17:46:12 +00:00
|
|
|
if( mindist < MINIMUM_SELECTION_DISTANCE )
|
|
|
|
mindist = MINIMUM_SELECTION_DISTANCE;
|
2009-06-13 17:06:07 +00:00
|
|
|
|
|
|
|
return HitTest( aRefPoint, mindist, DefaultTransformMatrix );
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Function HitTest
|
|
|
|
* @return true if the point aPosRef is near this object
|
|
|
|
* @param aRefPoint = a wxPoint to test
|
2009-09-04 18:57:37 +00:00
|
|
|
* @param aThreshold = max distance to this object (usually the half thickness
|
|
|
|
* of a line)
|
2009-06-13 17:06:07 +00:00
|
|
|
* @param aTransMat = the transform matrix
|
|
|
|
*/
|
2010-02-04 17:46:12 +00:00
|
|
|
bool LIB_ARC::HitTest( wxPoint aReferencePoint, int aThreshold,
|
|
|
|
const int aTransformationMatrix[2][2] )
|
2009-06-13 17:06:07 +00:00
|
|
|
{
|
2010-02-04 17:46:12 +00:00
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
// TODO: use aTransMat to calculmates parameters
|
2010-02-04 17:46:12 +00:00
|
|
|
wxPoint relativePosition = aReferencePoint;
|
2009-06-18 13:30:52 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
NEGATE( relativePosition.y ); // reverse Y axis
|
2009-06-13 17:06:07 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
int distance = wxRound( EuclideanNorm(TwoPointVector(m_Pos, relativePosition) ) );
|
2009-06-13 17:06:07 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
if( abs( distance - m_Radius ) > aThreshold )
|
2009-06-11 14:26:17 +00:00
|
|
|
return false;
|
2009-06-12 04:07:09 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
// We are on the circle, ensure we are only on the arc, i.e. between
|
|
|
|
// m_ArcStart and m_ArcEnd
|
2009-06-12 04:07:09 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
wxPoint startEndVector = TwoPointVector( m_ArcStart, m_ArcEnd);
|
|
|
|
wxPoint startRelativePositionVector = TwoPointVector( m_ArcStart, relativePosition);
|
|
|
|
|
|
|
|
wxPoint centerStartVector = TwoPointVector( m_Pos, m_ArcStart);
|
|
|
|
wxPoint centerEndVector = TwoPointVector( m_Pos, m_ArcEnd);
|
|
|
|
wxPoint centerRelativePositionVector = TwoPointVector( m_Pos, relativePosition);
|
|
|
|
|
|
|
|
// Compute the cross product to check if the point is in the sector
|
|
|
|
int crossProductStart = CrossProduct(centerStartVector, centerRelativePositionVector);
|
|
|
|
int crossProductEnd = CrossProduct(centerEndVector, centerRelativePositionVector);
|
|
|
|
|
|
|
|
// The cross products need to be exchanged, depending on which side the center point
|
|
|
|
// relative to the start point to end point vector lies
|
|
|
|
if (CrossProduct(startEndVector, startRelativePositionVector) < 0 ){
|
|
|
|
EXCHG(crossProductStart, crossProductEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the cross products have a different sign, the point lies in sector
|
|
|
|
// also check, if the reference is near start or end point
|
|
|
|
return HitTestPoints(m_ArcStart, relativePosition, MINIMUM_SELECTION_DISTANCE) ||
|
|
|
|
HitTestPoints(m_ArcEnd, relativePosition, MINIMUM_SELECTION_DISTANCE) ||
|
|
|
|
(crossProductStart <= 0 && crossProductEnd >= 0);
|
2009-06-11 14:26:17 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_DRAW_ITEM* LIB_ARC::DoGenCopy()
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_ARC* newitem = new LIB_ARC( GetParent() );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
newitem->m_Pos = m_Pos;
|
2009-04-05 20:49:15 +00:00
|
|
|
newitem->m_ArcStart = m_ArcStart;
|
|
|
|
newitem->m_ArcEnd = m_ArcEnd;
|
2009-09-14 13:24:17 +00:00
|
|
|
newitem->m_Radius = m_Radius;
|
|
|
|
newitem->m_t1 = m_t1;
|
|
|
|
newitem->m_t2 = m_t2;
|
2009-09-04 18:57:37 +00:00
|
|
|
newitem->m_Width = m_Width;
|
|
|
|
newitem->m_Unit = m_Unit;
|
|
|
|
newitem->m_Convert = m_Convert;
|
|
|
|
newitem->m_Flags = m_Flags;
|
|
|
|
newitem->m_Fill = m_Fill;
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
return (LIB_DRAW_ITEM*) newitem;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2008-09-13 18:59:57 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
int LIB_ARC::DoCompare( const LIB_DRAW_ITEM& aOther ) const
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aOther.Type() == COMPONENT_ARC_DRAW_TYPE );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
const LIB_ARC* tmp = ( LIB_ARC* ) &aOther;
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
if( m_Pos.x != tmp->m_Pos.x )
|
|
|
|
return m_Pos.x - tmp->m_Pos.x;
|
|
|
|
|
|
|
|
if( m_Pos.y != tmp->m_Pos.y )
|
|
|
|
return m_Pos.y - tmp->m_Pos.y;
|
|
|
|
|
|
|
|
if( m_t1 != tmp->m_t1 )
|
|
|
|
return m_t1 - tmp->m_t1;
|
|
|
|
|
|
|
|
if( m_t2 != tmp->m_t2 )
|
|
|
|
return m_t2 - tmp->m_t2;
|
|
|
|
|
|
|
|
return 0;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_ARC::DoOffset( const wxPoint& aOffset )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos += aOffset;
|
|
|
|
m_ArcStart += aOffset;
|
|
|
|
m_ArcEnd += aOffset;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_ARC::DoTestInside( EDA_Rect& aRect )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
return aRect.Inside( m_ArcStart.x, -m_ArcStart.y )
|
|
|
|
|| aRect.Inside( m_ArcEnd.x, -m_ArcEnd.y );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_ARC::DoMove( const wxPoint& aPosition )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxPoint offset = aPosition - m_Pos;
|
|
|
|
m_Pos = aPosition;
|
2009-09-25 18:49:04 +00:00
|
|
|
m_ArcStart += offset;
|
|
|
|
m_ArcEnd += offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_ARC::DoMirrorHorizontal( const wxPoint& aCenter )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos.x -= aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
m_Pos.x *= -1;
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos.x += aCenter.x;
|
|
|
|
m_ArcStart.x -= aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
m_ArcStart.x *= -1;
|
2009-12-15 21:11:05 +00:00
|
|
|
m_ArcStart.x += aCenter.x;
|
|
|
|
m_ArcEnd.x -= aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
m_ArcEnd.x *= -1;
|
2009-12-15 21:11:05 +00:00
|
|
|
m_ArcEnd.x += aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
EXCHG( m_ArcStart, m_ArcEnd );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_ARC::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
|
|
|
|
const int aTransform[2][2] )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aPlotter != NULL );
|
2009-10-05 17:52:41 +00:00
|
|
|
|
|
|
|
int t1 = m_t1;
|
|
|
|
int t2 = m_t2;
|
2009-12-15 21:11:05 +00:00
|
|
|
wxPoint pos = TransformCoordinate( aTransform, m_Pos ) + aOffset;
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
MapAngles( &t1, &t2, aTransform );
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
|
|
|
|
aPlotter->arc( pos, -t2, -t1, m_Radius, FILLED_SHAPE, 0 );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
|
|
|
|
aPlotter->arc( pos, -t2, -t1, m_Radius, m_Fill, GetPenSize() );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-30 17:57:27 +00:00
|
|
|
/** Function GetPenSize
|
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
int LIB_ARC::GetPenSize()
|
2009-06-30 17:57:27 +00:00
|
|
|
{
|
2009-09-04 18:57:37 +00:00
|
|
|
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
|
2009-06-30 17:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
void LIB_ARC::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aOffset, int aColor, int aDrawMode,
|
|
|
|
void* aData, const int aTransformMatrix[2][2] )
|
2008-09-13 18:59:57 +00:00
|
|
|
{
|
|
|
|
wxPoint pos1, pos2, posc;
|
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
int color = ReturnLayerColor( LAYER_DEVICE );
|
2008-09-13 18:59:57 +00:00
|
|
|
|
|
|
|
if( aColor < 0 ) // Used normal color or selected color
|
|
|
|
{
|
2009-09-04 18:57:37 +00:00
|
|
|
if( ( m_Selected & IS_SELECTED ) )
|
2008-09-13 18:59:57 +00:00
|
|
|
color = g_ItemSelectetColor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
color = aColor;
|
|
|
|
|
|
|
|
pos1 = TransformCoordinate( aTransformMatrix, m_ArcEnd ) + aOffset;
|
|
|
|
pos2 = TransformCoordinate( aTransformMatrix, m_ArcStart ) + aOffset;
|
|
|
|
posc = TransformCoordinate( aTransformMatrix, m_Pos ) + aOffset;
|
2009-09-14 13:24:17 +00:00
|
|
|
int pt1 = m_t1;
|
|
|
|
int pt2 = m_t2;
|
2008-09-13 18:59:57 +00:00
|
|
|
bool swap = MapAngles( &pt1, &pt2, aTransformMatrix );
|
|
|
|
if( swap )
|
|
|
|
{
|
2008-10-30 10:55:46 +00:00
|
|
|
EXCHG( pos1.x, pos2.x );
|
|
|
|
EXCHG( pos1.y, pos2.y );
|
2008-09-13 18:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
|
|
|
|
|
|
|
FILL_T fill = aData ? NO_FILL : m_Fill;
|
|
|
|
if( aColor >= 0 )
|
|
|
|
fill = NO_FILL;
|
|
|
|
|
|
|
|
if( fill == FILLED_WITH_BG_BODYCOLOR )
|
|
|
|
GRFilledArc( &aPanel->m_ClipBox, aDC, posc.x, posc.y, pt1, pt2,
|
2010-03-28 14:46:49 +00:00
|
|
|
m_Radius, GetPenSize( ),
|
|
|
|
(m_Flags & IS_MOVED) ? color : ReturnLayerColor( LAYER_DEVICE_BACKGROUND ),
|
2009-09-04 18:57:37 +00:00
|
|
|
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
|
2008-09-13 18:59:57 +00:00
|
|
|
else if( fill == FILLED_SHAPE && !aData )
|
|
|
|
GRFilledArc( &aPanel->m_ClipBox, aDC, posc.x, posc.y, pt1, pt2,
|
2009-09-14 13:24:17 +00:00
|
|
|
m_Radius, color, color );
|
2008-09-13 18:59:57 +00:00
|
|
|
else
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2008-09-13 18:59:57 +00:00
|
|
|
#ifdef DRAW_ARC_WITH_ANGLE
|
|
|
|
|
|
|
|
GRArc( &aPanel->m_ClipBox, aDC, posc.x, posc.y, pt1, pt2,
|
2009-09-14 13:24:17 +00:00
|
|
|
m_Radius, GetPenSize( ), color );
|
2009-04-05 20:49:15 +00:00
|
|
|
#else
|
2008-09-14 04:27:22 +00:00
|
|
|
|
2008-09-13 18:59:57 +00:00
|
|
|
GRArc1( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y,
|
2009-06-30 17:57:27 +00:00
|
|
|
posc.x, posc.y, GetPenSize( ), color );
|
2009-04-05 20:49:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set to one (1) to draw bounding box around arc to validate bounding box
|
|
|
|
* calculation. */
|
|
|
|
#if 0
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
|
|
|
GRRect( &aPanel->m_ClipBox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y,
|
|
|
|
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
|
2008-09-13 18:59:57 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
EDA_Rect LIB_ARC::GetBoundingBox()
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
int minX, minY, maxX, maxY, angleStart, angleEnd;
|
2009-04-05 20:49:15 +00:00
|
|
|
EDA_Rect rect;
|
2009-06-11 14:26:17 +00:00
|
|
|
wxPoint nullPoint, startPos, endPos, centerPos;
|
|
|
|
wxPoint normStart = m_ArcStart - m_Pos;
|
|
|
|
wxPoint normEnd = m_ArcEnd - m_Pos;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( ( normStart == nullPoint ) || ( normEnd == nullPoint )
|
2009-09-14 13:24:17 +00:00
|
|
|
|| ( m_Radius == 0 ) )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-09-04 18:57:37 +00:00
|
|
|
wxLogDebug( wxT("Invalid arc drawing definition, center(%d, %d) \
|
|
|
|
start(%d, %d), end(%d, %d), radius %d" ),
|
2009-04-05 20:49:15 +00:00
|
|
|
m_Pos.x, m_Pos.y, m_ArcStart.x, m_ArcStart.y, m_ArcEnd.x,
|
2009-09-14 13:24:17 +00:00
|
|
|
m_ArcEnd.y, m_Radius );
|
2009-04-05 20:49:15 +00:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
endPos = TransformCoordinate( DefaultTransformMatrix, m_ArcEnd );
|
|
|
|
startPos = TransformCoordinate( DefaultTransformMatrix, m_ArcStart );
|
|
|
|
centerPos = TransformCoordinate( DefaultTransformMatrix, m_Pos );
|
2009-09-14 13:24:17 +00:00
|
|
|
angleStart = m_t1;
|
|
|
|
angleEnd = m_t2;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( MapAngles( &angleStart, &angleEnd, DefaultTransformMatrix ) )
|
|
|
|
{
|
|
|
|
EXCHG( endPos.x, startPos.x );
|
|
|
|
EXCHG( endPos.y, startPos.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start with the start and end point of the arc. */
|
|
|
|
minX = MIN( startPos.x, endPos.x );
|
|
|
|
minY = MIN( startPos.y, endPos.y );
|
|
|
|
maxX = MAX( startPos.x, endPos.x );
|
|
|
|
maxY = MAX( startPos.y, endPos.y );
|
|
|
|
|
|
|
|
/* Zero degrees is a special case. */
|
|
|
|
if( angleStart == 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
maxX = centerPos.x + m_Radius;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
/* Arc end angle wrapped passed 360. */
|
|
|
|
if( angleStart > angleEnd )
|
|
|
|
angleEnd += 3600;
|
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
if( angleStart <= 900 && angleEnd >= 900 ) /* 90 deg */
|
2009-09-14 13:24:17 +00:00
|
|
|
maxY = centerPos.y + m_Radius;
|
2009-06-11 14:26:17 +00:00
|
|
|
if( angleStart <= 1800 && angleEnd >= 1800 ) /* 180 deg */
|
2009-09-14 13:24:17 +00:00
|
|
|
minX = centerPos.x - m_Radius;
|
2009-06-11 14:26:17 +00:00
|
|
|
if( angleStart <= 2700 && angleEnd >= 2700 ) /* 270 deg */
|
2009-09-14 13:24:17 +00:00
|
|
|
minY = centerPos.y - m_Radius;
|
2009-06-11 14:26:17 +00:00
|
|
|
if( angleStart <= 3600 && angleEnd >= 3600 ) /* 0 deg */
|
2009-09-14 13:24:17 +00:00
|
|
|
maxX = centerPos.x + m_Radius;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
rect.SetOrigin( minX, minY );
|
|
|
|
rect.SetEnd( maxX, maxY );
|
|
|
|
rect.Inflate( m_Width / 2, m_Width / 2 );
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_ARC::DisplayInfo( WinEDA_DrawFrame* aFrame )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_DRAW_ITEM::DisplayInfo( aFrame );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
msg = ReturnStringFromValue( g_UserUnit, m_Width,
|
2009-04-05 20:49:15 +00:00
|
|
|
EESCHEMA_INTERNAL_UNIT, true );
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel( _( "Line width" ), msg, BLUE );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x,
|
|
|
|
bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y );
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel( _( "Bounding box" ), msg, BROWN );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-12 04:07:09 +00:00
|
|
|
/*************************/
|
2009-10-08 13:19:28 +00:00
|
|
|
/** class LIB_CIRCLE **/
|
2009-06-12 04:07:09 +00:00
|
|
|
/*************************/
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_CIRCLE::LIB_CIRCLE( LIB_COMPONENT* aParent ) :
|
2009-09-25 18:49:04 +00:00
|
|
|
LIB_DRAW_ITEM( COMPONENT_CIRCLE_DRAW_TYPE, aParent )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-20 19:36:58 +00:00
|
|
|
m_Radius = 0;
|
|
|
|
m_Fill = NO_FILL;
|
|
|
|
m_isFillable = true;
|
|
|
|
m_typeName = _( "Circle" );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_CIRCLE::LIB_CIRCLE( const LIB_CIRCLE& aCircle ) :
|
|
|
|
LIB_DRAW_ITEM( aCircle )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos = aCircle.m_Pos;
|
|
|
|
m_Radius = aCircle.m_Radius;
|
|
|
|
m_Fill = aCircle.m_Fill;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_CIRCLE::Save( FILE* aFile )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( fprintf( aFile, "C %d %d %d %d %d %d %c\n", m_Pos.x, m_Pos.y,
|
2009-09-14 13:24:17 +00:00
|
|
|
m_Radius, m_Unit, m_Convert, m_Width, fill_tab[m_Fill] ) < 0 )
|
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_CIRCLE::Load( char* aLine, wxString& aErrorMsg )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
char tmp[256];
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
int cnt = sscanf( &aLine[2], "%d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y,
|
2009-09-14 13:24:17 +00:00
|
|
|
&m_Radius, &m_Unit, &m_Convert, &m_Width, tmp );
|
2009-06-11 14:26:17 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( cnt < 6 )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( _( "circle only had %d parameters of the required 6" ),
|
2009-05-21 17:42:42 +00:00
|
|
|
cnt );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( tmp[0] == 'F' )
|
|
|
|
m_Fill = FILLED_SHAPE;
|
|
|
|
if( tmp[0] == 'f' )
|
|
|
|
m_Fill = FILLED_WITH_BG_BODYCOLOR;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
/**
|
|
|
|
* Function HitTest
|
|
|
|
* tests if the given wxPoint is within the bounds of this object.
|
2009-06-13 17:06:07 +00:00
|
|
|
* @param aRefPos A wxPoint to test in eeschema space
|
2009-12-15 21:11:05 +00:00
|
|
|
* @return - true if a hit, else false
|
2009-06-11 14:26:17 +00:00
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef )
|
2009-06-11 14:26:17 +00:00
|
|
|
{
|
2009-06-18 13:30:52 +00:00
|
|
|
int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;
|
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
// Have a minimal tolerance for hit test
|
2010-02-04 17:46:12 +00:00
|
|
|
if( mindist < MINIMUM_SELECTION_DISTANCE )
|
|
|
|
mindist = MINIMUM_SELECTION_DISTANCE;
|
2009-06-11 14:26:17 +00:00
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
return HitTest( aPosRef, mindist, DefaultTransformMatrix );
|
|
|
|
}
|
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
/** Function HitTest
|
|
|
|
* @return true if the point aPosRef is near this object
|
|
|
|
* @param aPosRef = a wxPoint to test
|
2009-09-14 13:24:17 +00:00
|
|
|
* @param aThreshold = max distance to this object (usually the half
|
|
|
|
* thickness of a line)
|
2009-06-13 17:06:07 +00:00
|
|
|
* @param aTransMat = the transform matrix
|
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_CIRCLE::HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] )
|
2009-06-13 17:06:07 +00:00
|
|
|
{
|
|
|
|
wxPoint relpos = aPosRef - TransformCoordinate( aTransMat, m_Pos );
|
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
int dist =
|
2009-09-04 18:57:37 +00:00
|
|
|
wxRound( sqrt( ( (double) relpos.x * relpos.x ) +
|
|
|
|
( (double) relpos.y * relpos.y ) ) );
|
2009-06-18 13:30:52 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
if( abs( dist - m_Radius ) <= aThreshold )
|
2009-06-13 17:06:07 +00:00
|
|
|
return true;
|
2009-06-11 14:26:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_DRAW_ITEM* LIB_CIRCLE::DoGenCopy()
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_CIRCLE* newitem = new LIB_CIRCLE( GetParent() );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
newitem->m_Pos = m_Pos;
|
2009-09-14 13:24:17 +00:00
|
|
|
newitem->m_Radius = m_Radius;
|
2009-04-05 20:49:15 +00:00
|
|
|
newitem->m_Width = m_Width;
|
|
|
|
newitem->m_Unit = m_Unit;
|
|
|
|
newitem->m_Convert = m_Convert;
|
|
|
|
newitem->m_Flags = m_Flags;
|
|
|
|
newitem->m_Fill = m_Fill;
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
return (LIB_DRAW_ITEM*) newitem;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
int LIB_CIRCLE::DoCompare( const LIB_DRAW_ITEM& aOther ) const
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aOther.Type() == COMPONENT_CIRCLE_DRAW_TYPE );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
const LIB_CIRCLE* tmp = ( LIB_CIRCLE* ) &aOther;
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
if( m_Pos.x != tmp->m_Pos.x )
|
|
|
|
return m_Pos.x - tmp->m_Pos.x;
|
|
|
|
|
|
|
|
if( m_Pos.y != tmp->m_Pos.y )
|
|
|
|
return m_Pos.y - tmp->m_Pos.y;
|
|
|
|
|
|
|
|
if( m_Radius != tmp->m_Radius )
|
|
|
|
return m_Radius - tmp->m_Radius;
|
|
|
|
|
|
|
|
return 0;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_CIRCLE::DoOffset( const wxPoint& aOffset )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos += aOffset;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_CIRCLE::DoTestInside( EDA_Rect& aRect )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* FIXME: This fails to take into acount the radius around the center
|
|
|
|
* point.
|
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
return aRect.Inside( m_Pos.x, -m_Pos.y );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_CIRCLE::DoMove( const wxPoint& aPosition )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos = aPosition;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_CIRCLE::DoMirrorHorizontal( const wxPoint& aCenter )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos.x -= aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
m_Pos.x *= -1;
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos.x += aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_CIRCLE::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
|
|
|
|
const int aTransform[2][2] )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxPoint pos = TransformCoordinate( aTransform, m_Pos ) + aOffset;
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
|
|
|
|
aPlotter->circle( pos, m_Radius * 2, FILLED_SHAPE, 0 );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
|
|
|
|
aPlotter->circle( pos, m_Radius * 2, m_Fill, GetPenSize() );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-30 17:57:27 +00:00
|
|
|
/** Function GetPenSize
|
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
int LIB_CIRCLE::GetPenSize()
|
2009-06-30 17:57:27 +00:00
|
|
|
{
|
2009-09-04 18:57:37 +00:00
|
|
|
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
|
2009-06-30 17:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
void LIB_CIRCLE::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aOffset, int aColor, int aDrawMode,
|
|
|
|
void* aData, const int aTransformMatrix[2][2] )
|
2008-09-13 18:59:57 +00:00
|
|
|
{
|
|
|
|
wxPoint pos1;
|
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
int color = ReturnLayerColor( LAYER_DEVICE );
|
2008-09-13 18:59:57 +00:00
|
|
|
|
|
|
|
if( aColor < 0 ) // Used normal color or selected color
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
if( ( m_Selected & IS_SELECTED ) )
|
2008-09-13 18:59:57 +00:00
|
|
|
color = g_ItemSelectetColor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
color = aColor;
|
|
|
|
|
|
|
|
pos1 = TransformCoordinate( aTransformMatrix, m_Pos ) + aOffset;
|
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
|
|
|
|
|
|
|
FILL_T fill = aData ? NO_FILL : m_Fill;
|
|
|
|
if( aColor >= 0 )
|
|
|
|
fill = NO_FILL;
|
|
|
|
|
|
|
|
if( fill == FILLED_WITH_BG_BODYCOLOR )
|
|
|
|
GRFilledCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y,
|
2010-03-28 14:46:49 +00:00
|
|
|
m_Radius, GetPenSize( ),
|
|
|
|
(m_Flags & IS_MOVED) ? color : ReturnLayerColor( LAYER_DEVICE_BACKGROUND ),
|
2009-09-04 18:57:37 +00:00
|
|
|
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
|
2008-09-13 18:59:57 +00:00
|
|
|
else if( fill == FILLED_SHAPE )
|
|
|
|
GRFilledCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y,
|
2009-09-14 13:24:17 +00:00
|
|
|
m_Radius, 0, color, color );
|
2008-09-13 18:59:57 +00:00
|
|
|
else
|
|
|
|
GRCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y,
|
2009-09-14 13:24:17 +00:00
|
|
|
m_Radius, GetPenSize( ), color );
|
2009-10-01 14:17:47 +00:00
|
|
|
|
|
|
|
/* Set to one (1) to draw bounding box around circle to validate bounding
|
|
|
|
* box calculation. */
|
|
|
|
#if 0
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
|
|
|
GRRect( &aPanel->m_ClipBox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y,
|
|
|
|
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
|
|
|
|
#endif
|
2008-09-13 18:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
EDA_Rect LIB_CIRCLE::GetBoundingBox()
|
2008-09-13 18:59:57 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
EDA_Rect rect;
|
2009-06-11 14:26:17 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
rect.SetOrigin( m_Pos.x - m_Radius, ( m_Pos.y - m_Radius ) * -1 );
|
|
|
|
rect.SetEnd( m_Pos.x + m_Radius, ( m_Pos.y + m_Radius ) * -1 );
|
2009-04-05 20:49:15 +00:00
|
|
|
rect.Inflate( m_Width / 2, m_Width / 2 );
|
2009-06-11 14:26:17 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
return rect;
|
|
|
|
}
|
2008-09-13 18:59:57 +00:00
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_CIRCLE::DisplayInfo( WinEDA_DrawFrame* aFrame )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
2008-09-13 18:59:57 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_DRAW_ITEM::DisplayInfo( aFrame );
|
2008-09-13 18:59:57 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
msg = ReturnStringFromValue( g_UserUnit, m_Width,
|
2009-04-05 20:49:15 +00:00
|
|
|
EESCHEMA_INTERNAL_UNIT, true );
|
2008-09-13 18:59:57 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel( _( "Line width" ), msg, BLUE );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
msg = ReturnStringFromValue( g_UserUnit, m_Radius,
|
2009-04-05 20:49:15 +00:00
|
|
|
EESCHEMA_INTERNAL_UNIT, true );
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel( _( "Radius" ), msg, RED );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x,
|
|
|
|
bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y );
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel( _( "Bounding box" ), msg, BROWN );
|
2008-09-13 18:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
/*************************/
|
2009-10-08 13:19:28 +00:00
|
|
|
/** class LIB_RECTANGLE **/
|
2009-06-11 14:26:17 +00:00
|
|
|
/*************************/
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_RECTANGLE::LIB_RECTANGLE( LIB_COMPONENT* aParent ) :
|
2009-09-25 18:49:04 +00:00
|
|
|
LIB_DRAW_ITEM( COMPONENT_RECT_DRAW_TYPE, aParent )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-20 19:36:58 +00:00
|
|
|
m_Width = 0;
|
|
|
|
m_Fill = NO_FILL;
|
|
|
|
m_isFillable = true;
|
|
|
|
m_typeName = _( "Rectangle" );
|
2010-02-04 17:46:12 +00:00
|
|
|
m_isHeightLocked = false;
|
|
|
|
m_isWidthLocked = false;
|
|
|
|
m_isStartPointSelected = false;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_RECTANGLE::LIB_RECTANGLE( const LIB_RECTANGLE& aRect ) :
|
|
|
|
LIB_DRAW_ITEM( aRect )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos = aRect.m_Pos;
|
|
|
|
m_End = aRect.m_End;
|
|
|
|
m_Width = aRect.m_Width;
|
|
|
|
m_Fill = aRect.m_Fill;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_RECTANGLE::Save( FILE* aFile )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( fprintf( aFile, "S %d %d %d %d %d %d %d %c\n", m_Pos.x, m_Pos.y,
|
2009-09-14 13:24:17 +00:00
|
|
|
m_End.x, m_End.y, m_Unit, m_Convert, m_Width,
|
|
|
|
fill_tab[m_Fill] ) < 0 )
|
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_RECTANGLE::Load( char* aLine, wxString& aErrorMsg )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
int cnt;
|
2009-04-05 20:49:15 +00:00
|
|
|
char tmp[256];
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
cnt = sscanf( &aLine[2], "%d %d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y,
|
2009-04-05 20:49:15 +00:00
|
|
|
&m_End.x, &m_End.y, &m_Unit, &m_Convert, &m_Width, tmp );
|
|
|
|
|
|
|
|
if( cnt < 7 )
|
2008-09-13 18:59:57 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( _( "rectangle only had %d parameters of the required 7" ),
|
2009-05-21 17:42:42 +00:00
|
|
|
cnt );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2008-09-13 18:59:57 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( tmp[0] == 'F' )
|
|
|
|
m_Fill = FILLED_SHAPE;
|
|
|
|
if( tmp[0] == 'f' )
|
|
|
|
m_Fill = FILLED_WITH_BG_BODYCOLOR;
|
2008-09-13 18:59:57 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
return true;
|
2008-09-13 18:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_DRAW_ITEM* LIB_RECTANGLE::DoGenCopy()
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_RECTANGLE* newitem = new LIB_RECTANGLE( GetParent() );
|
2008-10-30 10:55:46 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
newitem->m_Pos = m_Pos;
|
|
|
|
newitem->m_End = m_End;
|
|
|
|
newitem->m_Width = m_Width;
|
|
|
|
newitem->m_Unit = m_Unit;
|
|
|
|
newitem->m_Convert = m_Convert;
|
|
|
|
newitem->m_Flags = m_Flags;
|
|
|
|
newitem->m_Fill = m_Fill;
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
return (LIB_DRAW_ITEM*) newitem;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
int LIB_RECTANGLE::DoCompare( const LIB_DRAW_ITEM& aOther ) const
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aOther.Type() == COMPONENT_RECT_DRAW_TYPE );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
const LIB_RECTANGLE* tmp = ( LIB_RECTANGLE* ) &aOther;
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
if( m_Pos.x != tmp->m_Pos.x )
|
|
|
|
return m_Pos.x - tmp->m_Pos.x;
|
|
|
|
|
|
|
|
if( m_Pos.y != tmp->m_Pos.y )
|
|
|
|
return m_Pos.y - tmp->m_Pos.y;
|
|
|
|
|
|
|
|
if( m_End.x != tmp->m_End.x )
|
|
|
|
return m_End.x - tmp->m_End.x;
|
|
|
|
|
|
|
|
if( m_End.y != tmp->m_End.y )
|
|
|
|
return m_End.y - tmp->m_End.y;
|
|
|
|
|
|
|
|
return 0;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_RECTANGLE::DoOffset( const wxPoint& aOffset )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos += aOffset;
|
|
|
|
m_End += aOffset;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_RECTANGLE::DoTestInside( EDA_Rect& aRect )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
return aRect.Inside( m_Pos.x, -m_Pos.y ) || aRect.Inside( m_End.x, -m_End.y );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_RECTANGLE::DoMove( const wxPoint& aPosition )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
|
|
|
wxPoint size = m_End - m_Pos;
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos = aPosition;
|
|
|
|
m_End = aPosition + size;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_RECTANGLE::DoMirrorHorizontal( const wxPoint& aCenter )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos.x -= aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
m_Pos.x *= -1;
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos.x += aCenter.x;
|
|
|
|
m_End.x -= aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
m_End.x *= -1;
|
2009-12-15 21:11:05 +00:00
|
|
|
m_End.x += aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_RECTANGLE::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
|
|
|
|
const int aTransform[2][2] )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aPlotter != NULL );
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
wxPoint pos = TransformCoordinate( aTransform, m_Pos ) + aOffset;
|
|
|
|
wxPoint end = TransformCoordinate( aTransform, m_End ) + aOffset;
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
|
|
|
|
aPlotter->rect( pos, end, FILLED_WITH_BG_BODYCOLOR, 0 );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
|
|
|
|
aPlotter->rect( pos, end, m_Fill, GetPenSize() );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-30 17:57:27 +00:00
|
|
|
/** Function GetPenSize
|
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
int LIB_RECTANGLE::GetPenSize()
|
2009-06-30 17:57:27 +00:00
|
|
|
{
|
2009-09-04 18:57:37 +00:00
|
|
|
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
|
2009-06-30 17:57:27 +00:00
|
|
|
}
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
void LIB_RECTANGLE::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
2009-04-05 20:49:15 +00:00
|
|
|
const wxPoint& aOffset, int aColor, int aDrawMode,
|
|
|
|
void* aData, const int aTransformMatrix[2][2] )
|
2008-09-13 18:59:57 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxPoint pos1, pos2;
|
2008-09-17 17:26:25 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
int color = ReturnLayerColor( LAYER_DEVICE );
|
2008-09-17 17:26:25 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( aColor < 0 ) // Used normal color or selected color
|
2008-09-17 17:26:25 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
if( m_Selected & IS_SELECTED )
|
2008-09-17 17:26:25 +00:00
|
|
|
color = g_ItemSelectetColor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
color = aColor;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
pos1 = TransformCoordinate( aTransformMatrix, m_Pos ) + aOffset;
|
|
|
|
pos2 = TransformCoordinate( aTransformMatrix, m_End ) + aOffset;
|
2008-09-17 17:26:25 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
FILL_T fill = aData ? NO_FILL : m_Fill;
|
|
|
|
if( aColor >= 0 )
|
|
|
|
fill = NO_FILL;
|
2008-09-17 17:26:25 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( fill == FILLED_WITH_BG_BODYCOLOR && !aData )
|
|
|
|
GRFilledRect( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y,
|
2010-03-28 14:46:49 +00:00
|
|
|
GetPenSize( ),
|
|
|
|
(m_Flags & IS_MOVED) ? color : ReturnLayerColor( LAYER_DEVICE_BACKGROUND ),
|
2009-09-04 18:57:37 +00:00
|
|
|
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
else if( m_Fill == FILLED_SHAPE && !aData )
|
|
|
|
GRFilledRect( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y,
|
2009-06-30 17:57:27 +00:00
|
|
|
GetPenSize( ), color, color );
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
|
|
|
GRRect( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y,
|
2009-06-30 17:57:27 +00:00
|
|
|
GetPenSize( ), color );
|
2009-10-01 14:17:47 +00:00
|
|
|
|
|
|
|
/* Set to one (1) to draw bounding box around rectangle to validate
|
|
|
|
* bounding box calculation. */
|
|
|
|
#if 0
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
|
|
|
bBox.Inflate( m_Width + 1, m_Width + 1 );
|
|
|
|
GRRect( &aPanel->m_ClipBox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y,
|
|
|
|
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
|
|
|
|
#endif
|
2008-11-12 17:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_RECTANGLE::DisplayInfo( WinEDA_DrawFrame* aFrame )
|
2008-11-12 17:27:32 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString msg;
|
2008-11-12 17:27:32 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_DRAW_ITEM::DisplayInfo( aFrame );
|
2008-11-12 17:27:32 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
msg = ReturnStringFromValue( g_UserUnit, m_Width, EESCHEMA_INTERNAL_UNIT, true );
|
2008-11-12 17:27:32 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel( _( "Line width" ), msg, BLUE );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2008-11-12 17:27:32 +00:00
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
EDA_Rect LIB_RECTANGLE::GetBoundingBox()
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
EDA_Rect rect;
|
2009-06-11 14:26:17 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
rect.SetOrigin( m_Pos.x, m_Pos.y * -1 );
|
|
|
|
rect.SetEnd( m_End.x, m_End.y * -1 );
|
|
|
|
rect.Inflate( m_Width / 2, m_Width / 2 );
|
|
|
|
return rect;
|
2008-09-13 18:59:57 +00:00
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
/**
|
|
|
|
* Function HitTest
|
|
|
|
* tests if the given wxPoint is within the bounds of this object.
|
|
|
|
* @param aRefPoint A wxPoint to test in eeschema space
|
2009-12-15 21:11:05 +00:00
|
|
|
* @return true if a hit, else false
|
2009-06-13 17:06:07 +00:00
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
bool LIB_RECTANGLE::HitTest( const wxPoint& aRefPoint )
|
2009-06-13 17:06:07 +00:00
|
|
|
{
|
2009-06-18 13:30:52 +00:00
|
|
|
int mindist = (m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2) + 1;
|
2009-06-13 17:06:07 +00:00
|
|
|
|
|
|
|
// Have a minimal tolerance for hit test
|
2010-02-04 17:46:12 +00:00
|
|
|
if( mindist < MINIMUM_SELECTION_DISTANCE )
|
|
|
|
mindist = MINIMUM_SELECTION_DISTANCE;
|
2009-06-13 17:06:07 +00:00
|
|
|
|
|
|
|
return HitTest( aRefPoint, mindist, DefaultTransformMatrix );
|
|
|
|
}
|
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
/** Function HitTest
|
|
|
|
* @return true if the point aPosRef is near this object
|
|
|
|
* @param aRefPoint = a wxPoint to test
|
2009-09-04 18:57:37 +00:00
|
|
|
* @param aThreshold = max distance to this object (usually the half thickness
|
|
|
|
* of a line)
|
2009-06-13 17:06:07 +00:00
|
|
|
* @param aTransMat = the transform matrix
|
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
bool LIB_RECTANGLE::HitTest( wxPoint aRefPoint, int aThreshold,
|
2009-09-04 18:57:37 +00:00
|
|
|
const int aTransMat[2][2] )
|
2009-06-13 17:06:07 +00:00
|
|
|
{
|
2009-06-18 13:30:52 +00:00
|
|
|
wxPoint actualStart = TransformCoordinate( aTransMat, m_Pos );
|
|
|
|
wxPoint actualEnd = TransformCoordinate( aTransMat, m_End );
|
2009-06-13 17:06:07 +00:00
|
|
|
|
|
|
|
// locate lower segment
|
|
|
|
wxPoint start, end;
|
2009-06-18 13:30:52 +00:00
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
start = actualStart;
|
2009-06-18 13:30:52 +00:00
|
|
|
end.x = actualEnd.x;
|
|
|
|
end.y = actualStart.y;
|
2009-06-13 17:06:07 +00:00
|
|
|
if( TestSegmentHit( aRefPoint, start, end, aThreshold ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// locate right segment
|
|
|
|
start.x = actualEnd.x;
|
|
|
|
end.y = actualEnd.y;
|
|
|
|
if( TestSegmentHit( aRefPoint, start, end, aThreshold ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// locate upper segment
|
|
|
|
start.y = actualEnd.y;
|
|
|
|
end.x = actualStart.x;
|
|
|
|
if( TestSegmentHit( aRefPoint, start, end, aThreshold ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// locate left segment
|
2010-02-04 17:46:12 +00:00
|
|
|
start = actualStart;
|
|
|
|
end.x = actualStart.x;
|
|
|
|
end.y = actualEnd.y;
|
2009-06-13 17:06:07 +00:00
|
|
|
if( TestSegmentHit( aRefPoint, start, end, aThreshold ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
|
2009-06-12 04:07:09 +00:00
|
|
|
/**************************/
|
2009-10-08 13:19:28 +00:00
|
|
|
/** class LIB_SEGMENT **/
|
2009-06-12 04:07:09 +00:00
|
|
|
/**************************/
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_SEGMENT::LIB_SEGMENT( LIB_COMPONENT* aParent ) :
|
2009-09-25 18:49:04 +00:00
|
|
|
LIB_DRAW_ITEM( COMPONENT_LINE_DRAW_TYPE, aParent )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
m_Width = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
m_typeName = _( "Segment" );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_SEGMENT::LIB_SEGMENT( const LIB_SEGMENT& aSegment ) :
|
|
|
|
LIB_DRAW_ITEM( aSegment )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos = aSegment.m_Pos;
|
|
|
|
m_End = aSegment.m_End;
|
|
|
|
m_Width = aSegment.m_Width;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_SEGMENT::Save( FILE* aFile )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( fprintf( aFile, "L %d %d %d", m_Unit, m_Convert, m_Width ) )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
return true;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_SEGMENT::Load( char* aLine, wxString& aErrorMsg )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
return true;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_DRAW_ITEM* LIB_SEGMENT::DoGenCopy()
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_SEGMENT* newitem = new LIB_SEGMENT( GetParent() );
|
2008-12-31 09:27:19 +00:00
|
|
|
|
|
|
|
newitem->m_Pos = m_Pos;
|
2009-04-05 20:49:15 +00:00
|
|
|
newitem->m_End = m_End;
|
2008-12-31 09:27:19 +00:00
|
|
|
newitem->m_Width = m_Width;
|
|
|
|
newitem->m_Unit = m_Unit;
|
|
|
|
newitem->m_Convert = m_Convert;
|
|
|
|
newitem->m_Flags = m_Flags;
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
return (LIB_DRAW_ITEM*) newitem;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
int LIB_SEGMENT::DoCompare( const LIB_DRAW_ITEM& aOther ) const
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aOther.Type() == COMPONENT_LINE_DRAW_TYPE );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
const LIB_SEGMENT* tmp = ( LIB_SEGMENT* ) &aOther;
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
if( m_Pos.x != tmp->m_Pos.x )
|
|
|
|
return m_Pos.x - tmp->m_Pos.x;
|
|
|
|
|
|
|
|
if( m_Pos.y != tmp->m_Pos.y )
|
|
|
|
return m_Pos.y - tmp->m_Pos.y;
|
|
|
|
|
|
|
|
if( m_End.x != tmp->m_End.x )
|
|
|
|
return m_End.x - tmp->m_End.x;
|
|
|
|
|
|
|
|
if( m_End.y != tmp->m_End.y )
|
|
|
|
return m_End.y - tmp->m_End.y;
|
|
|
|
|
|
|
|
return 0;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_SEGMENT::DoOffset( const wxPoint& aOffset )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos += aOffset;
|
|
|
|
m_End += aOffset;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_SEGMENT::DoTestInside( EDA_Rect& aRect )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
return aRect.Inside( m_Pos.x, -m_Pos.y ) || aRect.Inside( m_End.x, -m_End.y );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_SEGMENT::DoMove( const wxPoint& aPosition )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxPoint offset = aPosition - m_Pos;
|
2009-09-25 18:49:04 +00:00
|
|
|
m_Pos += offset;
|
|
|
|
m_End += offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_SEGMENT::DoMirrorHorizontal( const wxPoint& aCenter )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos.x -= aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
m_Pos.x *= -1;
|
2009-12-15 21:11:05 +00:00
|
|
|
m_Pos.x += aCenter.x;
|
|
|
|
m_End.x -= aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
m_End.x *= -1;
|
2009-12-15 21:11:05 +00:00
|
|
|
m_End.x += aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_SEGMENT::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
|
|
|
|
const int aTransform[2][2] )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aPlotter != NULL );
|
2009-10-05 17:52:41 +00:00
|
|
|
|
|
|
|
int points[4];
|
2009-12-15 21:11:05 +00:00
|
|
|
wxPoint pos = TransformCoordinate( aTransform, m_Pos ) + aOffset;
|
|
|
|
wxPoint end = TransformCoordinate( aTransform, m_End ) + aOffset;
|
2009-10-05 17:52:41 +00:00
|
|
|
points[0] = pos.x;
|
|
|
|
points[1] = pos.y;
|
|
|
|
points[2] = end.x;
|
|
|
|
points[3] = end.y;
|
2009-12-15 21:11:05 +00:00
|
|
|
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
|
|
|
|
aPlotter->poly( 2, points, m_Fill, GetPenSize() );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-30 17:57:27 +00:00
|
|
|
/** Function GetPenSize
|
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
int LIB_SEGMENT::GetPenSize()
|
2009-06-30 17:57:27 +00:00
|
|
|
{
|
2009-09-04 18:57:37 +00:00
|
|
|
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
|
2009-06-30 17:57:27 +00:00
|
|
|
}
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
void LIB_SEGMENT::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aOffset, int aColor, int aDrawMode,
|
|
|
|
void* aData, const int aTransformMatrix[2][2] )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxPoint pos1, pos2;
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
int color = ReturnLayerColor( LAYER_DEVICE );
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( aColor < 0 ) // Used normal color or selected color
|
|
|
|
{
|
|
|
|
if( m_Selected & IS_SELECTED )
|
|
|
|
color = g_ItemSelectetColor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
color = aColor;
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
pos1 = TransformCoordinate( aTransformMatrix, m_Pos ) + aOffset;
|
|
|
|
pos2 = TransformCoordinate( aTransformMatrix, m_End ) + aOffset;
|
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
GRLine( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y,
|
2009-06-30 17:57:27 +00:00
|
|
|
GetPenSize( ), color );
|
2009-10-01 14:17:47 +00:00
|
|
|
|
|
|
|
/* Set to one (1) to draw bounding box around line segment to validate
|
|
|
|
* bounding box calculation. */
|
|
|
|
#if 0
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
2009-10-23 14:35:24 +00:00
|
|
|
bBox.Inflate( m_Width + 2 );
|
2009-10-01 14:17:47 +00:00
|
|
|
GRRect( &aPanel->m_ClipBox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y,
|
|
|
|
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
|
|
|
|
#endif
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_SEGMENT::DisplayInfo( WinEDA_DrawFrame* aFrame )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString msg;
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_DRAW_ITEM::DisplayInfo( aFrame );
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
msg = ReturnStringFromValue( g_UserUnit, m_Width,
|
2009-04-05 20:49:15 +00:00
|
|
|
EESCHEMA_INTERNAL_UNIT, true );
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel( _( "Line width" ), msg, BLUE );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x,
|
|
|
|
bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y );
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel( _( "Bounding box" ), msg, BROWN );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
|
|
|
|
/**
|
2009-06-13 17:06:07 +00:00
|
|
|
* Function HitTest
|
|
|
|
* tests if the given wxPoint is within the bounds of this object.
|
|
|
|
* @param aRefPos A wxPoint to test
|
2009-12-15 21:11:05 +00:00
|
|
|
* @return - true if a hit, else false
|
2009-06-13 17:06:07 +00:00
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
bool LIB_SEGMENT::HitTest( const wxPoint& aPosRef )
|
2009-06-13 17:06:07 +00:00
|
|
|
{
|
2009-06-18 13:30:52 +00:00
|
|
|
int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
// Have a minimal tolerance for hit test
|
2010-02-04 17:46:12 +00:00
|
|
|
if( mindist < MINIMUM_SELECTION_DISTANCE )
|
|
|
|
mindist = MINIMUM_SELECTION_DISTANCE;
|
2009-06-13 17:06:07 +00:00
|
|
|
|
|
|
|
return HitTest( aPosRef, mindist, DefaultTransformMatrix );
|
|
|
|
}
|
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
/** Function HitTest
|
|
|
|
* @return true if the point aPosRef is near this object
|
|
|
|
* @param aPosRef = a wxPoint to test
|
2009-09-04 18:57:37 +00:00
|
|
|
* @param aThreshold = max distance to this object (usually the half
|
|
|
|
* thickness of a line)
|
2009-06-13 17:06:07 +00:00
|
|
|
* @param aTransMat = the transform matrix
|
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
bool LIB_SEGMENT::HitTest( wxPoint aPosRef, int aThreshold,
|
|
|
|
const int aTransMat[2][2] )
|
2009-06-13 17:06:07 +00:00
|
|
|
{
|
|
|
|
wxPoint start = TransformCoordinate( aTransMat, m_Pos );
|
2009-06-18 13:30:52 +00:00
|
|
|
wxPoint end = TransformCoordinate( aTransMat, m_End );
|
2009-06-13 17:06:07 +00:00
|
|
|
|
|
|
|
return TestSegmentHit( aPosRef, start, end, aThreshold );
|
|
|
|
}
|
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-06-12 04:07:09 +00:00
|
|
|
/***************************/
|
2009-10-08 13:19:28 +00:00
|
|
|
/** class LIB_POLYLINE **/
|
2009-06-12 04:07:09 +00:00
|
|
|
/***************************/
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_POLYLINE::LIB_POLYLINE( LIB_COMPONENT* aParent ) :
|
2009-09-25 18:49:04 +00:00
|
|
|
LIB_DRAW_ITEM( COMPONENT_POLYLINE_DRAW_TYPE, aParent )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-10-20 19:36:58 +00:00
|
|
|
m_Fill = NO_FILL;
|
|
|
|
m_Width = 0;
|
|
|
|
m_isFillable = true;
|
|
|
|
m_typeName = _( "PolyLine" );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_POLYLINE::LIB_POLYLINE( const LIB_POLYLINE& polyline ) :
|
2009-09-25 18:49:04 +00:00
|
|
|
LIB_DRAW_ITEM( polyline )
|
|
|
|
{
|
|
|
|
m_PolyPoints = polyline.m_PolyPoints; // Vector copy
|
|
|
|
m_Width = polyline.m_Width;
|
|
|
|
m_Fill = polyline.m_Fill;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_POLYLINE::Save( FILE* aFile )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
int ccount = GetCornerCount();
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( fprintf( aFile, "P %d %d %d %d", ccount, m_Unit, m_Convert, m_Width ) < 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
for( unsigned i = 0; i < GetCornerCount(); i++ )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( fprintf( aFile, " %d %d", m_PolyPoints[i].x, m_PolyPoints[i].y ) < 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( fprintf( aFile, " %c\n", fill_tab[m_Fill] ) < 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
return true;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
char* p;
|
|
|
|
int i, ccount = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxPoint pt;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
i = sscanf( &aLine[2], "%d %d %d %d", &ccount, &m_Unit, &m_Convert,
|
2009-04-05 20:49:15 +00:00
|
|
|
&m_Width );
|
|
|
|
|
2010-06-10 18:43:12 +00:00
|
|
|
m_Fill = NO_FILL;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( i < 4 )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( _( "polyline only had %d parameters of the required 4" ), i );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-06-11 14:26:17 +00:00
|
|
|
if( ccount <= 0 )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( _( "polyline count parameter %d is invalid" ), ccount );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
p = strtok( &aLine[2], " \t\n" );
|
2009-04-05 20:49:15 +00:00
|
|
|
p = strtok( NULL, " \t\n" );
|
|
|
|
p = strtok( NULL, " \t\n" );
|
|
|
|
p = strtok( NULL, " \t\n" );
|
|
|
|
|
|
|
|
for( i = 0; i < ccount; i++ )
|
|
|
|
{
|
|
|
|
wxPoint point;
|
|
|
|
p = strtok( NULL, " \t\n" );
|
2010-06-10 18:43:12 +00:00
|
|
|
if( p == NULL || sscanf( p, "%d", &pt.x ) != 1 )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( _( "polyline point %d X position not defined" ), i );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
p = strtok( NULL, " \t\n" );
|
2010-06-10 18:43:12 +00:00
|
|
|
if( p == NULL || sscanf( p, "%d", &pt.y ) != 1 )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( _( "polyline point %d Y position not defined" ), i );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-06-11 14:26:17 +00:00
|
|
|
AddPoint( pt );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( ( p = strtok( NULL, " \t\n" ) ) != NULL )
|
|
|
|
{
|
|
|
|
if( p[0] == 'F' )
|
|
|
|
m_Fill = FILLED_SHAPE;
|
|
|
|
if( p[0] == 'f' )
|
|
|
|
m_Fill = FILLED_WITH_BG_BODYCOLOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_DRAW_ITEM* LIB_POLYLINE::DoGenCopy()
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_POLYLINE* newitem = new LIB_POLYLINE( GetParent() );
|
2009-01-02 17:07:50 +00:00
|
|
|
|
2009-01-02 13:19:34 +00:00
|
|
|
newitem->m_PolyPoints = m_PolyPoints; // Vector copy
|
2009-09-04 18:57:37 +00:00
|
|
|
newitem->m_Width = m_Width;
|
|
|
|
newitem->m_Unit = m_Unit;
|
|
|
|
newitem->m_Convert = m_Convert;
|
|
|
|
newitem->m_Flags = m_Flags;
|
|
|
|
newitem->m_Fill = m_Fill;
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
return (LIB_DRAW_ITEM*) newitem;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
int LIB_POLYLINE::DoCompare( const LIB_DRAW_ITEM& aOther ) const
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aOther.Type() == COMPONENT_POLYLINE_DRAW_TYPE );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
const LIB_POLYLINE* tmp = ( LIB_POLYLINE* ) &aOther;
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
if( m_PolyPoints.size() != tmp->m_PolyPoints.size() )
|
2009-10-01 14:17:47 +00:00
|
|
|
return m_PolyPoints.size() - tmp->m_PolyPoints.size();
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
for( size_t i = 0; i < m_PolyPoints.size(); i++ )
|
|
|
|
{
|
2009-10-01 14:17:47 +00:00
|
|
|
if( m_PolyPoints[i].x != tmp->m_PolyPoints[i].x )
|
|
|
|
return m_PolyPoints[i].x - tmp->m_PolyPoints[i].x;
|
|
|
|
if( m_PolyPoints[i].y != tmp->m_PolyPoints[i].y )
|
|
|
|
return m_PolyPoints[i].y - tmp->m_PolyPoints[i].y;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
2009-10-01 14:17:47 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_POLYLINE::DoOffset( const wxPoint& aOffset )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
|
|
|
for( size_t i = 0; i < m_PolyPoints.size(); i++ )
|
2009-12-15 21:11:05 +00:00
|
|
|
m_PolyPoints[i] += aOffset;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_POLYLINE::DoTestInside( EDA_Rect& aRect )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
|
|
|
for( size_t i = 0; i < m_PolyPoints.size(); i++ )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aRect.Inside( m_PolyPoints[i].x, -m_PolyPoints[i].y ) )
|
2009-09-14 13:24:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_POLYLINE::DoMove( const wxPoint& aPosition )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
DoOffset( aPosition - m_PolyPoints[0] );
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_POLYLINE::DoMirrorHorizontal( const wxPoint& aCenter )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
|
|
|
size_t i, imax = m_PolyPoints.size();
|
|
|
|
|
|
|
|
for( i = 0; i < imax; i++ )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_PolyPoints[i].x -= aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
m_PolyPoints[i].x *= -1;
|
2009-12-15 21:11:05 +00:00
|
|
|
m_PolyPoints[i].x += aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_POLYLINE::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
|
|
|
|
const int aTransform[2][2] )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aPlotter != NULL );
|
2009-10-05 17:52:41 +00:00
|
|
|
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
int* Poly = (int*) MyMalloc( sizeof(int) * 2 * GetCornerCount() );
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( Poly == NULL )
|
|
|
|
return;
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
for( i = 0; i < m_PolyPoints.size(); i++ )
|
|
|
|
{
|
|
|
|
wxPoint pos = m_PolyPoints[i];
|
2009-12-15 21:11:05 +00:00
|
|
|
pos = TransformCoordinate( aTransform, pos ) + aOffset;
|
2009-10-05 17:52:41 +00:00
|
|
|
Poly[i * 2] = pos.x;
|
|
|
|
Poly[i * 2 + 1] = pos.y;
|
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
|
|
|
|
aPlotter->poly( i, Poly, FILLED_WITH_BG_BODYCOLOR, 0 );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
|
|
|
|
aPlotter->poly( i, Poly, m_Fill, GetPenSize() );
|
2009-10-05 17:52:41 +00:00
|
|
|
MyFree( Poly );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
void LIB_POLYLINE::AddPoint( const wxPoint& point )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-01-02 13:19:34 +00:00
|
|
|
m_PolyPoints.push_back( point );
|
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
|
|
|
|
|
2009-06-30 17:57:27 +00:00
|
|
|
/** Function GetPenSize
|
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
int LIB_POLYLINE::GetPenSize()
|
2009-06-30 17:57:27 +00:00
|
|
|
{
|
2009-09-04 18:57:37 +00:00
|
|
|
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
|
2009-06-30 17:57:27 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
void LIB_POLYLINE::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aOffset, int aColor, int aDrawMode,
|
|
|
|
void* aData, const int aTransformMatrix[2][2] )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
wxPoint pos1;
|
2009-09-04 18:57:37 +00:00
|
|
|
int color = ReturnLayerColor( LAYER_DEVICE );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
// Buffer used to store current corners coordinates for drawings
|
|
|
|
static wxPoint* Buf_Poly_Drawings = NULL;
|
|
|
|
static unsigned Buf_Poly_Size = 0;
|
|
|
|
|
|
|
|
if( aColor < 0 ) // Used normal color or selected color
|
|
|
|
{
|
|
|
|
if( m_Selected & IS_SELECTED )
|
|
|
|
color = g_ItemSelectetColor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
color = aColor;
|
|
|
|
|
|
|
|
// Set the size of the buffer od coordinates
|
|
|
|
if( Buf_Poly_Drawings == NULL )
|
|
|
|
{
|
|
|
|
Buf_Poly_Size = m_PolyPoints.size();
|
|
|
|
Buf_Poly_Drawings =
|
|
|
|
(wxPoint*) MyMalloc( sizeof(wxPoint) * Buf_Poly_Size );
|
|
|
|
}
|
|
|
|
else if( Buf_Poly_Size < m_PolyPoints.size() )
|
|
|
|
{
|
|
|
|
Buf_Poly_Size = m_PolyPoints.size();
|
|
|
|
Buf_Poly_Drawings =
|
|
|
|
(wxPoint*) realloc( Buf_Poly_Drawings,
|
|
|
|
sizeof(wxPoint) * Buf_Poly_Size );
|
2009-12-15 21:11:05 +00:00
|
|
|
|
|
|
|
if( Buf_Poly_Drawings == NULL )
|
|
|
|
{
|
2009-12-29 10:35:11 +00:00
|
|
|
DisplayError( NULL, wxT( "Cannot allocate memory to draw polylines." ) );
|
2009-12-15 21:11:05 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( Buf_Poly_Drawings == NULL )
|
|
|
|
return;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ )
|
|
|
|
{
|
|
|
|
Buf_Poly_Drawings[ii] =
|
|
|
|
TransformCoordinate( aTransformMatrix, m_PolyPoints[ii] ) + aOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILL_T fill = aData ? NO_FILL : m_Fill;
|
|
|
|
if( aColor >= 0 )
|
|
|
|
fill = NO_FILL;
|
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( fill == FILLED_WITH_BG_BODYCOLOR )
|
|
|
|
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
|
2010-03-28 14:46:49 +00:00
|
|
|
Buf_Poly_Drawings, 1, GetPenSize( ),
|
|
|
|
(m_Flags & IS_MOVED) ? color : ReturnLayerColor( LAYER_DEVICE_BACKGROUND ),
|
2009-09-04 18:57:37 +00:00
|
|
|
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
else if( fill == FILLED_SHAPE )
|
|
|
|
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
|
2009-06-30 17:57:27 +00:00
|
|
|
Buf_Poly_Drawings, 1, GetPenSize( ), color, color );
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
|
|
|
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
|
2009-06-30 17:57:27 +00:00
|
|
|
Buf_Poly_Drawings, 0, GetPenSize( ), color, color );
|
2009-10-01 14:17:47 +00:00
|
|
|
|
|
|
|
/* Set to one (1) to draw bounding box around polyline to validate
|
|
|
|
* bounding box calculation. */
|
|
|
|
#if 0
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
|
|
|
bBox.Inflate( m_Width + 1, m_Width + 1 );
|
|
|
|
GRRect( &aPanel->m_ClipBox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y,
|
|
|
|
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
|
|
|
|
#endif
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
/**
|
|
|
|
* Function HitTest
|
|
|
|
* tests if the given wxPoint is within the bounds of this object.
|
|
|
|
* @param aRefPos A wxPoint to test
|
2009-12-15 21:11:05 +00:00
|
|
|
* @return true if a hit, else false
|
2009-06-13 17:06:07 +00:00
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
bool LIB_POLYLINE::HitTest( const wxPoint& aRefPos )
|
2009-06-13 17:06:07 +00:00
|
|
|
{
|
2009-06-18 13:30:52 +00:00
|
|
|
int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
// Have a minimal tolerance for hit test
|
2010-02-04 17:46:12 +00:00
|
|
|
if( mindist < MINIMUM_SELECTION_DISTANCE )
|
|
|
|
mindist = MINIMUM_SELECTION_DISTANCE;
|
2009-06-13 17:06:07 +00:00
|
|
|
return HitTest( aRefPos, mindist, DefaultTransformMatrix );
|
|
|
|
}
|
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
|
2009-01-02 13:19:34 +00:00
|
|
|
/** Function HitTest
|
|
|
|
* @return true if the point aPosRef is near a segment
|
|
|
|
* @param aPosRef = a wxPoint to test
|
|
|
|
* @param aThreshold = max distance to a segment
|
|
|
|
* @param aTransMat = the transform matrix
|
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_POLYLINE::HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] )
|
2009-01-02 13:19:34 +00:00
|
|
|
{
|
2009-01-02 17:07:50 +00:00
|
|
|
wxPoint ref, start, end;
|
2009-01-02 13:19:34 +00:00
|
|
|
|
2009-01-31 18:08:47 +00:00
|
|
|
for( unsigned ii = 1; ii < GetCornerCount(); ii++ )
|
2009-01-02 13:19:34 +00:00
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
start = TransformCoordinate( aTransMat, m_PolyPoints[ii - 1] );
|
2009-01-31 18:08:47 +00:00
|
|
|
end = TransformCoordinate( aTransMat, m_PolyPoints[ii] );
|
2009-01-02 13:19:34 +00:00
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
if( TestSegmentHit( aPosRef, start, end, aThreshold ) )
|
2009-01-02 17:07:50 +00:00
|
|
|
return true;
|
2009-01-02 13:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-01-02 17:07:50 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/** Function GetBoundingBox
|
2009-01-02 13:19:34 +00:00
|
|
|
* @return the boundary box for this, in library coordinates
|
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
EDA_Rect LIB_POLYLINE::GetBoundingBox()
|
2009-01-02 13:19:34 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
EDA_Rect rect;
|
2009-01-02 17:07:50 +00:00
|
|
|
int xmin, xmax, ymin, ymax;
|
|
|
|
|
2009-01-02 13:19:34 +00:00
|
|
|
xmin = xmax = m_PolyPoints[0].x;
|
|
|
|
ymin = ymax = m_PolyPoints[0].y;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-01-02 13:19:34 +00:00
|
|
|
for( unsigned ii = 1; ii < GetCornerCount(); ii++ )
|
|
|
|
{
|
2009-02-13 09:11:12 +00:00
|
|
|
xmin = MIN( xmin, m_PolyPoints[ii].x );
|
|
|
|
xmax = MAX( xmax, m_PolyPoints[ii].x );
|
2009-01-31 18:08:47 +00:00
|
|
|
ymin = MIN( ymin, m_PolyPoints[ii].y );
|
|
|
|
ymax = MAX( ymax, m_PolyPoints[ii].y );
|
2009-01-02 13:19:34 +00:00
|
|
|
}
|
2009-01-02 17:07:50 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
rect.SetOrigin( xmin, ymin * -1 );
|
|
|
|
rect.SetEnd( xmax, ymax * -1 );
|
|
|
|
rect.Inflate( m_Width / 2, m_Width / 2 );
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_POLYLINE::DisplayInfo( WinEDA_DrawFrame* aFrame )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_DRAW_ITEM::DisplayInfo( aFrame );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
msg = ReturnStringFromValue( g_UserUnit, m_Width,
|
2009-04-05 20:49:15 +00:00
|
|
|
EESCHEMA_INTERNAL_UNIT, true );
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel(_( "Line width" ), msg, BLUE );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x,
|
|
|
|
bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y );
|
2009-01-02 13:19:34 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel( _( "Bounding box" ), msg, BROWN );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
2009-06-25 20:45:27 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2009-06-25 20:45:27 +00:00
|
|
|
/***************************/
|
2009-10-08 13:19:28 +00:00
|
|
|
/** class LIB_BEZIER **/
|
2009-06-25 20:45:27 +00:00
|
|
|
/***************************/
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_BEZIER::LIB_BEZIER( LIB_COMPONENT* aParent ) :
|
2009-09-25 18:49:04 +00:00
|
|
|
LIB_DRAW_ITEM( COMPONENT_BEZIER_DRAW_TYPE, aParent )
|
2009-06-25 20:45:27 +00:00
|
|
|
{
|
2009-10-20 19:36:58 +00:00
|
|
|
m_Fill = NO_FILL;
|
|
|
|
m_Width = 0;
|
|
|
|
m_isFillable = true;
|
|
|
|
m_typeName = _( "Bezier" );
|
2009-06-25 20:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_BEZIER::LIB_BEZIER( const LIB_BEZIER& aBezier ) : LIB_DRAW_ITEM( aBezier )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_PolyPoints = aBezier.m_PolyPoints;
|
|
|
|
m_BezierPoints = aBezier.m_BezierPoints; // Vector copy
|
|
|
|
m_Width = aBezier.m_Width;
|
|
|
|
m_Fill = aBezier.m_Fill;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_BEZIER::Save( FILE* aFile )
|
2009-06-25 20:45:27 +00:00
|
|
|
{
|
|
|
|
int ccount = GetCornerCount();
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( fprintf( aFile, "B %d %d %d %d",
|
2009-09-14 13:24:17 +00:00
|
|
|
ccount, m_Unit, m_Convert, m_Width ) < 0 )
|
|
|
|
return false;
|
2009-06-25 20:45:27 +00:00
|
|
|
|
|
|
|
for( unsigned i = 0; i < GetCornerCount(); i++ )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( fprintf( aFile, " %d %d", m_BezierPoints[i].x,
|
2009-09-14 13:24:17 +00:00
|
|
|
m_BezierPoints[i].y ) < 0 )
|
|
|
|
return false;
|
2009-06-25 20:45:27 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( fprintf( aFile, " %c\n", fill_tab[m_Fill] ) < 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
2009-06-25 20:45:27 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_BEZIER::Load( char* aLine, wxString& aErrorMsg )
|
2009-06-25 20:45:27 +00:00
|
|
|
{
|
|
|
|
char* p;
|
|
|
|
int i, ccount = 0;
|
|
|
|
wxPoint pt;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
i = sscanf( &aLine[2], "%d %d %d %d", &ccount, &m_Unit, &m_Convert, &m_Width );
|
2009-06-25 20:45:27 +00:00
|
|
|
|
|
|
|
if( i !=4 )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( _( "Bezier only had %d parameters of the required 4" ), i );
|
2009-06-25 20:45:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if( ccount <= 0 )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( _( "Bezier count parameter %d is invalid" ), ccount );
|
2009-06-25 20:45:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
p = strtok( &aLine[2], " \t\n" );
|
2009-06-25 20:45:27 +00:00
|
|
|
p = strtok( NULL, " \t\n" );
|
|
|
|
p = strtok( NULL, " \t\n" );
|
|
|
|
p = strtok( NULL, " \t\n" );
|
|
|
|
|
|
|
|
for( i = 0; i < ccount; i++ )
|
|
|
|
{
|
|
|
|
wxPoint point;
|
|
|
|
p = strtok( NULL, " \t\n" );
|
|
|
|
if( sscanf( p, "%d", &pt.x ) != 1 )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( _( "Bezier point %d X position not defined" ), i );
|
2009-06-25 20:45:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
p = strtok( NULL, " \t\n" );
|
|
|
|
if( sscanf( p, "%d", &pt.y ) != 1 )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( _( "Bezier point %d Y position not defined" ), i );
|
2009-06-25 20:45:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_BezierPoints.push_back( pt );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Fill = NO_FILL;
|
|
|
|
|
|
|
|
if( ( p = strtok( NULL, " \t\n" ) ) != NULL )
|
|
|
|
{
|
|
|
|
if( p[0] == 'F' )
|
|
|
|
m_Fill = FILLED_SHAPE;
|
|
|
|
if( p[0] == 'f' )
|
|
|
|
m_Fill = FILLED_WITH_BG_BODYCOLOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_DRAW_ITEM* LIB_BEZIER::DoGenCopy()
|
2009-06-25 20:45:27 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_BEZIER* newitem = new LIB_BEZIER(GetParent());
|
2009-06-25 20:45:27 +00:00
|
|
|
|
|
|
|
newitem->m_BezierPoints = m_BezierPoints; // Vector copy
|
|
|
|
newitem->m_Width = m_Width;
|
|
|
|
newitem->m_Unit = m_Unit;
|
|
|
|
newitem->m_Convert = m_Convert;
|
|
|
|
newitem->m_Flags = m_Flags;
|
|
|
|
newitem->m_Fill = m_Fill;
|
2009-09-25 18:49:04 +00:00
|
|
|
return (LIB_DRAW_ITEM*) newitem;
|
2009-06-25 20:45:27 +00:00
|
|
|
}
|
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
int LIB_BEZIER::DoCompare( const LIB_DRAW_ITEM& aOther ) const
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aOther.Type() == COMPONENT_BEZIER_DRAW_TYPE );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
const LIB_BEZIER* tmp = ( LIB_BEZIER* ) &aOther;
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
if( m_BezierPoints.size() != tmp->m_BezierPoints.size() )
|
2009-10-01 14:17:47 +00:00
|
|
|
return m_BezierPoints.size() - tmp->m_BezierPoints.size();
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
for( size_t i = 0; i < m_BezierPoints.size(); i++ )
|
|
|
|
{
|
2009-10-01 14:17:47 +00:00
|
|
|
if( m_BezierPoints[i].x != tmp->m_BezierPoints[i].x )
|
|
|
|
return m_BezierPoints[i].x - tmp->m_BezierPoints[i].x;
|
|
|
|
if( m_BezierPoints[i].y != tmp->m_BezierPoints[i].y )
|
|
|
|
return m_BezierPoints[i].y - tmp->m_BezierPoints[i].y;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
return 0;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_BEZIER::DoOffset( const wxPoint& aOffset )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for( i = 0; i < m_BezierPoints.size(); i++ )
|
2009-12-15 21:11:05 +00:00
|
|
|
m_BezierPoints[i] += aOffset;
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
for( i = 0; i < m_PolyPoints.size(); i++ )
|
2009-12-15 21:11:05 +00:00
|
|
|
m_PolyPoints[i] += aOffset;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_BEZIER::DoTestInside( EDA_Rect& aRect )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
|
|
|
for( size_t i = 0; i < m_PolyPoints.size(); i++ )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aRect.Inside( m_PolyPoints[i].x, -m_PolyPoints[i].y ) )
|
2009-09-14 13:24:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_BEZIER::DoMove( const wxPoint& aPosition )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
DoOffset( aPosition - m_PolyPoints[0] );
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_BEZIER::DoMirrorHorizontal( const wxPoint& aCenter )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
|
|
|
size_t i, imax = m_PolyPoints.size();
|
|
|
|
|
|
|
|
for( i = 0; i < imax; i++ )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_PolyPoints[i].x -= aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
m_PolyPoints[i].x *= -1;
|
2009-12-15 21:11:05 +00:00
|
|
|
m_PolyPoints[i].x += aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
imax = m_BezierPoints.size();
|
|
|
|
for( i = 0; i < imax; i++ )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
m_BezierPoints[i].x -= aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
m_BezierPoints[i].x *= -1;
|
2009-12-15 21:11:05 +00:00
|
|
|
m_BezierPoints[i].x += aCenter.x;
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_BEZIER::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
|
|
|
|
const int aTransform[2][2] )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aPlotter != NULL );
|
2009-10-05 17:52:41 +00:00
|
|
|
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
int* Poly = (int*) MyMalloc( sizeof(int) * 2 * GetCornerCount() );
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( Poly == NULL )
|
|
|
|
return;
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
for( i = 0; i < m_PolyPoints.size(); i++ )
|
|
|
|
{
|
|
|
|
wxPoint pos = m_PolyPoints[i];
|
2009-12-15 21:11:05 +00:00
|
|
|
pos = TransformCoordinate( aTransform, pos ) + aOffset;
|
2009-10-05 17:52:41 +00:00
|
|
|
Poly[i * 2] = pos.x;
|
|
|
|
Poly[i * 2 + 1] = pos.y;
|
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
|
|
|
|
aPlotter->poly( i, Poly, FILLED_WITH_BG_BODYCOLOR, 0 );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
|
|
|
|
aPlotter->poly( i, Poly, m_Fill, GetPenSize() );
|
2009-10-05 17:52:41 +00:00
|
|
|
MyFree( Poly );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-30 17:57:27 +00:00
|
|
|
/** Function GetPenSize
|
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
int LIB_BEZIER::GetPenSize()
|
2009-06-30 17:57:27 +00:00
|
|
|
{
|
2009-09-04 18:57:37 +00:00
|
|
|
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
|
2009-06-30 17:57:27 +00:00
|
|
|
}
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
void LIB_BEZIER::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aOffset, int aColor, int aDrawMode,
|
|
|
|
void* aData, const int aTransformMatrix[2][2] )
|
2009-06-25 20:45:27 +00:00
|
|
|
{
|
2009-09-04 18:57:37 +00:00
|
|
|
wxPoint pos1;
|
|
|
|
std::vector<wxPoint> PolyPointsTraslated;
|
|
|
|
|
|
|
|
int color = ReturnLayerColor( LAYER_DEVICE );
|
2009-06-25 20:45:27 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
m_PolyPoints = Bezier2Poly( m_BezierPoints[0],
|
|
|
|
m_BezierPoints[1],
|
|
|
|
m_BezierPoints[2],
|
|
|
|
m_BezierPoints[3] );
|
2009-06-25 20:45:27 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
PolyPointsTraslated.clear();
|
2009-06-25 20:45:27 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
for( unsigned int i = 0; i < m_PolyPoints.size() ; i++ )
|
|
|
|
PolyPointsTraslated.push_back(
|
|
|
|
TransformCoordinate( aTransformMatrix, m_PolyPoints[i] ) + aOffset );
|
2009-06-25 20:45:27 +00:00
|
|
|
|
|
|
|
if( aColor < 0 ) // Used normal color or selected color
|
|
|
|
{
|
|
|
|
if( m_Selected & IS_SELECTED )
|
|
|
|
color = g_ItemSelectetColor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
color = aColor;
|
|
|
|
|
|
|
|
FILL_T fill = aData ? NO_FILL : m_Fill;
|
|
|
|
if( aColor >= 0 )
|
|
|
|
fill = NO_FILL;
|
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
|
|
|
|
2009-06-25 20:45:27 +00:00
|
|
|
if( fill == FILLED_WITH_BG_BODYCOLOR )
|
|
|
|
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
|
2010-03-28 14:46:49 +00:00
|
|
|
&PolyPointsTraslated[0], 1, GetPenSize(),
|
|
|
|
(m_Flags & IS_MOVED) ? color : ReturnLayerColor( LAYER_DEVICE_BACKGROUND ),
|
2009-06-25 20:45:27 +00:00
|
|
|
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
|
|
|
|
else if( fill == FILLED_SHAPE )
|
|
|
|
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
|
2009-09-04 18:57:37 +00:00
|
|
|
&PolyPointsTraslated[0], 1, GetPenSize(), color, color );
|
2009-06-25 20:45:27 +00:00
|
|
|
else
|
|
|
|
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
|
2009-09-04 18:57:37 +00:00
|
|
|
&PolyPointsTraslated[0], 0, GetPenSize(), color, color );
|
2009-06-25 20:45:27 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
/* Set to one (1) to draw bounding box around bezier curve to validate
|
|
|
|
* bounding box calculation. */
|
|
|
|
#if 0
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
|
|
|
bBox.Inflate( m_Width + 1, m_Width + 1 );
|
|
|
|
GRRect( &aPanel->m_ClipBox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y,
|
|
|
|
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
|
|
|
|
#endif
|
2009-06-25 20:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function HitTest
|
|
|
|
* tests if the given wxPoint is within the bounds of this object.
|
|
|
|
* @param aRefPos A wxPoint to test
|
2009-12-15 21:11:05 +00:00
|
|
|
* @return true if a hit, else false
|
2009-06-25 20:45:27 +00:00
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
bool LIB_BEZIER::HitTest( const wxPoint& aRefPos )
|
2009-06-25 20:45:27 +00:00
|
|
|
{
|
|
|
|
int mindist = m_Width ? m_Width /2 : g_DrawDefaultLineThickness / 2;
|
|
|
|
// Have a minimal tolerance for hit test
|
2010-02-04 17:46:12 +00:00
|
|
|
if ( mindist < MINIMUM_SELECTION_DISTANCE )
|
|
|
|
mindist = MINIMUM_SELECTION_DISTANCE;
|
2009-06-25 20:45:27 +00:00
|
|
|
return HitTest( aRefPos, mindist, DefaultTransformMatrix );
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Function HitTest
|
2009-12-15 21:11:05 +00:00
|
|
|
* @return if the point aPosRef is near a segment
|
2009-06-25 20:45:27 +00:00
|
|
|
* @param aPosRef = a wxPoint to test
|
|
|
|
* @param aThreshold = max distance to a segment
|
|
|
|
* @param aTransMat = the transform matrix
|
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
bool LIB_BEZIER::HitTest( wxPoint aPosRef, int aThreshold,
|
|
|
|
const int aTransMat[2][2] )
|
2009-06-25 20:45:27 +00:00
|
|
|
{
|
|
|
|
wxPoint ref, start, end;
|
|
|
|
|
|
|
|
for( unsigned ii = 1; ii < GetCornerCount(); ii++ )
|
|
|
|
{
|
|
|
|
start = TransformCoordinate( aTransMat, m_PolyPoints[ii - 1] );
|
|
|
|
end = TransformCoordinate( aTransMat, m_PolyPoints[ii] );
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2009-06-25 20:45:27 +00:00
|
|
|
if ( TestSegmentHit( aPosRef, start, end, aThreshold ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Function GetBoundingBox
|
|
|
|
* @return the boundary box for this, in library coordinates
|
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
EDA_Rect LIB_BEZIER::GetBoundingBox()
|
2009-06-25 20:45:27 +00:00
|
|
|
{
|
|
|
|
EDA_Rect rect;
|
|
|
|
int xmin, xmax, ymin, ymax;
|
2009-09-04 18:57:37 +00:00
|
|
|
|
|
|
|
if( !GetCornerCount() )
|
|
|
|
return rect;
|
|
|
|
|
2009-06-25 20:45:27 +00:00
|
|
|
xmin = xmax = m_PolyPoints[0].x;
|
|
|
|
ymin = ymax = m_PolyPoints[0].y;
|
|
|
|
|
|
|
|
for( unsigned ii = 1; ii < GetCornerCount(); ii++ )
|
|
|
|
{
|
|
|
|
xmin = MIN( xmin, m_PolyPoints[ii].x );
|
|
|
|
xmax = MAX( xmax, m_PolyPoints[ii].x );
|
|
|
|
ymin = MIN( ymin, m_PolyPoints[ii].y );
|
|
|
|
ymax = MAX( ymax, m_PolyPoints[ii].y );
|
|
|
|
}
|
|
|
|
|
|
|
|
rect.SetOrigin( xmin, ymin * -1 );
|
|
|
|
rect.SetEnd( xmax, ymax * -1 );
|
|
|
|
rect.Inflate( m_Width / 2, m_Width / 2 );
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_BEZIER::DisplayInfo( WinEDA_DrawFrame* aFrame )
|
2009-06-25 20:45:27 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_DRAW_ITEM::DisplayInfo( aFrame );
|
2009-06-25 20:45:27 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
msg = ReturnStringFromValue( g_UserUnit, m_Width,
|
2009-09-04 18:57:37 +00:00
|
|
|
EESCHEMA_INTERNAL_UNIT, true );
|
2009-06-25 20:45:27 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel( _( "Line width" ), msg, BLUE );
|
2009-06-25 20:45:27 +00:00
|
|
|
|
|
|
|
msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x,
|
2009-09-04 18:57:37 +00:00
|
|
|
bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y );
|
2009-06-25 20:45:27 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aFrame->AppendMsgPanel( _( "Bounding box" ), msg, BROWN );
|
2009-06-25 20:45:27 +00:00
|
|
|
}
|