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"
|
|
|
|
#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-02-04 15:25:03 +00:00
|
|
|
|
2008-09-13 18:59:57 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
static int fill_tab[3] = { 'N', 'F', 'f' };
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2008-09-13 18:59:57 +00:00
|
|
|
//#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* Base class (abstract) for components bodies items */
|
2009-06-18 13:30:52 +00:00
|
|
|
LibEDA_BaseStruct::LibEDA_BaseStruct( KICAD_T struct_type, EDA_LibComponentStruct* aParent ) :
|
2008-09-14 04:27:22 +00:00
|
|
|
EDA_BaseStruct( struct_type )
|
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
m_Unit = 0; /* Unit identification (for multi part per package)
|
2009-04-05 20:49:15 +00:00
|
|
|
* 0 if the item is common to all units */
|
2009-06-11 14:26:17 +00:00
|
|
|
m_Convert = 0; /* Shape identification (for parts which have a convert
|
2009-04-05 20:49:15 +00:00
|
|
|
* shape) 0 if the item is common to all shapes */
|
2009-06-11 14:26:17 +00:00
|
|
|
m_Fill = NO_FILL;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
m_Parent = aParent;
|
2009-04-05 20:49:15 +00:00
|
|
|
m_typeName = _( "Undefined" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void LibEDA_BaseStruct::DisplayInfo( WinEDA_DrawFrame* frame )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
frame->MsgPanel->EraseMsgBox();
|
|
|
|
|
|
|
|
frame->MsgPanel->Affiche_1_Parametre( 1, _( "Type" ), m_typeName, CYAN );
|
|
|
|
|
|
|
|
/* Affichage de l'appartenance */
|
|
|
|
if( m_Unit == 0 )
|
|
|
|
msg = _( "All" );
|
|
|
|
else
|
|
|
|
msg.Printf( wxT( "%d" ), m_Unit );
|
|
|
|
Affiche_1_Parametre( frame, 8, _( "Unit" ), msg, BROWN );
|
|
|
|
|
|
|
|
if( m_Convert == 0 )
|
|
|
|
msg = _( "All" );
|
|
|
|
else if( m_Convert == 1 )
|
|
|
|
msg = _( "no" );
|
|
|
|
else if( m_Convert == 2 )
|
|
|
|
msg = _( "yes" );
|
|
|
|
else
|
|
|
|
msg = wxT( "?" );
|
|
|
|
Affiche_1_Parametre( frame, 14, _( "Convert" ), msg, BROWN );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
/**********************/
|
|
|
|
/** class LibDrawArc **/
|
|
|
|
/**********************/
|
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
LibDrawArc::LibDrawArc( EDA_LibComponentStruct* aParent ) :
|
|
|
|
LibEDA_BaseStruct( COMPONENT_ARC_DRAW_TYPE, aParent )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
m_Rayon = 0;
|
|
|
|
t1 = t2 = 0;
|
2009-06-11 14:26:17 +00:00
|
|
|
m_Width = 0;
|
|
|
|
m_Fill = NO_FILL;
|
2009-04-05 20:49:15 +00:00
|
|
|
m_typeName = _( "Arc" );
|
2008-09-14 04:27:22 +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-04-05 20:49:15 +00:00
|
|
|
bool LibDrawArc::Save( FILE* ExportFile ) const
|
|
|
|
{
|
|
|
|
int x1 = t1;
|
|
|
|
|
|
|
|
if( x1 > 1800 )
|
|
|
|
x1 -= 3600;
|
|
|
|
|
|
|
|
int x2 = t2;
|
|
|
|
|
|
|
|
if( x2 > 1800 )
|
|
|
|
x2 -= 3600;
|
|
|
|
|
|
|
|
fprintf( ExportFile, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
|
|
|
|
m_Pos.x, m_Pos.y, m_Rayon, x1, x2, m_Unit, m_Convert, m_Width,
|
|
|
|
fill_tab[m_Fill], m_ArcStart.x, m_ArcStart.y, m_ArcEnd.x,
|
|
|
|
m_ArcEnd.y );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LibDrawArc::Load( char* line, wxString& errorMsg )
|
|
|
|
{
|
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];
|
|
|
|
|
|
|
|
cnt = sscanf( &line[2], "%d %d %d %d %d %d %d %d %s %d %d %d %d",
|
|
|
|
&m_Pos.x, &m_Pos.y, &m_Rayon, &t1, &t2, &m_Unit, &m_Convert,
|
|
|
|
&m_Width, tmp, &startx, &starty, &endx, &endy );
|
|
|
|
if( cnt < 8 )
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
errorMsg.Printf( _( "arc only had %d parameters of the required 8" ),
|
|
|
|
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;
|
|
|
|
|
|
|
|
NORMALIZE_ANGLE( t1 );
|
|
|
|
NORMALIZE_ANGLE( t2 );
|
|
|
|
|
|
|
|
// 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
|
|
|
|
m_ArcStart.x = m_Rayon;
|
|
|
|
m_ArcStart.y = 0;
|
|
|
|
m_ArcEnd.x = m_Rayon;
|
2009-06-11 14:26:17 +00:00
|
|
|
m_ArcEnd.y = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
RotatePoint( &m_ArcStart.x, &m_ArcStart.y, -t1 );
|
|
|
|
m_ArcStart.x += m_Pos.x;
|
|
|
|
m_ArcStart.y += m_Pos.y;
|
|
|
|
RotatePoint( &m_ArcEnd.x, &m_ArcEnd.y, -t2 );
|
|
|
|
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-06-13 17:06:07 +00:00
|
|
|
bool LibDrawArc::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
|
2009-06-18 13:30:52 +00:00
|
|
|
if( mindist < 3 )
|
2009-06-11 14:26:17 +00:00
|
|
|
mindist = 3; // = 3 mils
|
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
|
|
|
|
* @param aThreshold = max distance to this object (usually the half thickness of a line)
|
|
|
|
* @param aTransMat = the transform matrix
|
|
|
|
*/
|
|
|
|
bool LibDrawArc::HitTest( wxPoint aRefPoint, int aThreshold, const int aTransMat[2][2] )
|
|
|
|
{
|
|
|
|
// TODO: use aTransMat to calculmates parameters
|
|
|
|
wxPoint relpos = aRefPoint;
|
2009-06-18 13:30:52 +00:00
|
|
|
|
|
|
|
NEGATE( relpos.y ); // reverse Y axis
|
2009-06-13 17:06:07 +00:00
|
|
|
|
|
|
|
relpos -= m_Pos;
|
2009-06-26 17:24:32 +00:00
|
|
|
int dist = wxRound( sqrt( ( (double) relpos.x * (double) relpos.x ) +
|
|
|
|
( (double) relpos.y * (double) relpos.y ) ) );
|
2009-06-13 17:06:07 +00:00
|
|
|
|
|
|
|
if( abs( dist - m_Rayon ) > aThreshold )
|
2009-06-11 14:26:17 +00:00
|
|
|
return false;
|
2009-06-12 04:07:09 +00:00
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
// We are on the circle, ensure we are only on the arc, i.e. between m_ArcStart and m_ArcEnd
|
2009-06-11 14:26:17 +00:00
|
|
|
int astart = t1; // arc starting point ( in 0.1 degree)
|
2009-06-18 13:30:52 +00:00
|
|
|
int aend = t2; // arc ending point ( in 0.1 degree)
|
2009-06-26 17:24:32 +00:00
|
|
|
int atest = wxRound( atan2( (double) relpos.y, (double) relpos.x ) * 1800.0 / M_PI );
|
2009-06-18 13:30:52 +00:00
|
|
|
NORMALIZE_ANGLE_180( atest );
|
|
|
|
NORMALIZE_ANGLE_180( astart );
|
|
|
|
NORMALIZE_ANGLE_180( aend );
|
2009-06-11 14:26:17 +00:00
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
if( astart > aend )
|
|
|
|
EXCHG( astart, aend );
|
2009-06-11 14:26:17 +00:00
|
|
|
|
|
|
|
if( atest >= astart && atest <= aend )
|
|
|
|
return true;
|
2009-06-12 04:07:09 +00:00
|
|
|
|
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-04-05 20:49:15 +00:00
|
|
|
LibDrawArc* LibDrawArc::GenCopy()
|
|
|
|
{
|
2009-06-18 13:30:52 +00:00
|
|
|
LibDrawArc* newitem = new LibDrawArc( GetParent() );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
newitem->m_Pos = m_Pos;
|
|
|
|
newitem->m_ArcStart = m_ArcStart;
|
|
|
|
newitem->m_ArcEnd = m_ArcEnd;
|
|
|
|
newitem->m_Rayon = m_Rayon;
|
|
|
|
newitem->t1 = t1;
|
|
|
|
newitem->t2 = t2;
|
|
|
|
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;
|
|
|
|
return newitem;
|
|
|
|
}
|
2008-09-13 18:59:57 +00:00
|
|
|
|
2009-04-05 20:49:15 +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
|
|
|
|
*/
|
|
|
|
int LibDrawArc::GetPenSize( )
|
|
|
|
{
|
|
|
|
int pensize = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width;
|
|
|
|
return pensize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
void LibDrawArc::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;
|
|
|
|
|
|
|
|
int color = ReturnLayerColor( LAYER_DEVICE );
|
|
|
|
|
|
|
|
if( aColor < 0 ) // Used normal color or selected color
|
|
|
|
{
|
|
|
|
if( (m_Selected & IS_SELECTED) )
|
|
|
|
color = g_ItemSelectetColor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
color = aColor;
|
|
|
|
|
|
|
|
pos1 = TransformCoordinate( aTransformMatrix, m_ArcEnd ) + aOffset;
|
|
|
|
pos2 = TransformCoordinate( aTransformMatrix, m_ArcStart ) + aOffset;
|
|
|
|
posc = TransformCoordinate( aTransformMatrix, m_Pos ) + aOffset;
|
|
|
|
int pt1 = t1;
|
|
|
|
int pt2 = t2;
|
|
|
|
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,
|
2009-06-30 17:57:27 +00:00
|
|
|
m_Rayon, GetPenSize( ), color,
|
2009-01-02 17:07:50 +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-01-02 17:07:50 +00:00
|
|
|
m_Rayon, 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-06-30 17:57:27 +00:00
|
|
|
m_Rayon, GetPenSize( ), color );
|
2008-09-14 04:27:22 +00:00
|
|
|
|
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-04-05 20:49:15 +00:00
|
|
|
EDA_Rect LibDrawArc::GetBoundingBox()
|
|
|
|
{
|
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-06-11 14:26:17 +00:00
|
|
|
|| ( m_Rayon == 0 ) )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-06-11 14:26:17 +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,
|
|
|
|
m_ArcEnd.y, m_Rayon );
|
|
|
|
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-04-05 20:49:15 +00:00
|
|
|
angleStart = t1;
|
2009-06-11 14:26:17 +00:00
|
|
|
angleEnd = 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 )
|
|
|
|
maxX = centerPos.x + m_Rayon;
|
|
|
|
|
|
|
|
/* 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-04-05 20:49:15 +00:00
|
|
|
maxY = centerPos.y + m_Rayon;
|
2009-06-11 14:26:17 +00:00
|
|
|
if( angleStart <= 1800 && angleEnd >= 1800 ) /* 180 deg */
|
2009-04-05 20:49:15 +00:00
|
|
|
minX = centerPos.x - m_Rayon;
|
2009-06-11 14:26:17 +00:00
|
|
|
if( angleStart <= 2700 && angleEnd >= 2700 ) /* 270 deg */
|
2009-04-05 20:49:15 +00:00
|
|
|
minY = centerPos.y - m_Rayon;
|
2009-06-11 14:26:17 +00:00
|
|
|
if( angleStart <= 3600 && angleEnd >= 3600 ) /* 0 deg */
|
2009-04-05 20:49:15 +00:00
|
|
|
maxX = centerPos.x + m_Rayon;
|
|
|
|
|
|
|
|
rect.SetOrigin( minX, minY );
|
|
|
|
rect.SetEnd( maxX, maxY );
|
|
|
|
rect.Inflate( m_Width / 2, m_Width / 2 );
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LibDrawArc::DisplayInfo( WinEDA_DrawFrame* frame )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
|
|
|
|
|
|
|
LibEDA_BaseStruct::DisplayInfo( frame );
|
|
|
|
|
|
|
|
msg = ReturnStringFromValue( g_UnitMetric, m_Width,
|
|
|
|
EESCHEMA_INTERNAL_UNIT, true );
|
|
|
|
|
|
|
|
frame->MsgPanel->Affiche_1_Parametre( 20, _( "Line width" ), msg, BLUE );
|
|
|
|
|
|
|
|
msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x,
|
|
|
|
bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y );
|
|
|
|
|
|
|
|
frame->MsgPanel->Affiche_1_Parametre( 40, _( "Bounding box" ), msg, BROWN );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-12 04:07:09 +00:00
|
|
|
/*************************/
|
|
|
|
/** class LibDrawCircle **/
|
|
|
|
/*************************/
|
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
LibDrawCircle::LibDrawCircle( EDA_LibComponentStruct* aParent ) :
|
|
|
|
LibEDA_BaseStruct( COMPONENT_CIRCLE_DRAW_TYPE, aParent )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
m_Rayon = 0;
|
|
|
|
m_Fill = NO_FILL;
|
2009-04-05 20:49:15 +00:00
|
|
|
m_typeName = _( "Circle" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LibDrawCircle::Save( FILE* ExportFile ) const
|
|
|
|
{
|
|
|
|
fprintf( ExportFile, "C %d %d %d %d %d %d %c\n", m_Pos.x, m_Pos.y,
|
|
|
|
m_Rayon, m_Unit, m_Convert, m_Width, fill_tab[m_Fill] );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LibDrawCircle::Load( char* line, wxString& errorMsg )
|
|
|
|
{
|
|
|
|
char tmp[256];
|
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
int cnt = sscanf( &line[2], "%d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y,
|
2009-04-05 20:49:15 +00:00
|
|
|
&m_Rayon, &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-05-21 17:42:42 +00:00
|
|
|
errorMsg.Printf( _( "circle only had %d parameters of the required 6" ),
|
|
|
|
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-06-11 14:26:17 +00:00
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
2009-06-13 17:06:07 +00:00
|
|
|
bool LibDrawCircle::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
|
2009-06-18 13:30:52 +00:00
|
|
|
if( mindist < 3 )
|
2009-06-11 14:26:17 +00:00
|
|
|
mindist = 3; // = 3 mils
|
|
|
|
|
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
|
|
|
|
* @param aThreshold = max distance to this object (usually the half thickness of a line)
|
|
|
|
* @param aTransMat = the transform matrix
|
|
|
|
*/
|
|
|
|
bool LibDrawCircle::HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] )
|
|
|
|
{
|
|
|
|
wxPoint relpos = aPosRef - TransformCoordinate( aTransMat, m_Pos );
|
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
int dist =
|
|
|
|
wxRound( sqrt( ( (double) relpos.x * relpos.x ) + ( (double) relpos.y * relpos.y ) ) );
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
if( abs( dist - m_Rayon ) <= aThreshold )
|
|
|
|
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-04-05 20:49:15 +00:00
|
|
|
LibDrawCircle* LibDrawCircle::GenCopy()
|
|
|
|
{
|
2009-06-18 13:30:52 +00:00
|
|
|
LibDrawCircle* newitem = new LibDrawCircle( GetParent() );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
newitem->m_Pos = m_Pos;
|
|
|
|
newitem->m_Rayon = m_Rayon;
|
|
|
|
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;
|
|
|
|
return newitem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
int LibDrawCircle::GetPenSize( )
|
|
|
|
{
|
|
|
|
int pensize = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width;
|
|
|
|
return pensize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
void LibDrawCircle::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;
|
|
|
|
|
|
|
|
int color = ReturnLayerColor( LAYER_DEVICE );
|
|
|
|
|
|
|
|
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,
|
2009-06-30 17:57:27 +00:00
|
|
|
m_Rayon, GetPenSize( ), color,
|
2009-06-11 14:26:17 +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-01-02 17:07:50 +00:00
|
|
|
m_Rayon, 0, color, color );
|
2008-09-13 18:59:57 +00:00
|
|
|
else
|
|
|
|
GRCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y,
|
2009-06-30 17:57:27 +00:00
|
|
|
m_Rayon, GetPenSize( ), color );
|
2008-09-13 18:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
EDA_Rect LibDrawCircle::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-04-05 20:49:15 +00:00
|
|
|
rect.SetOrigin( m_Pos.x - m_Rayon, ( m_Pos.y - m_Rayon ) * -1 );
|
|
|
|
rect.SetEnd( m_Pos.x + m_Rayon, ( m_Pos.y + m_Rayon ) * -1 );
|
|
|
|
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-04-05 20:49:15 +00:00
|
|
|
void LibDrawCircle::DisplayInfo( WinEDA_DrawFrame* frame )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
2008-09-13 18:59:57 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
LibEDA_BaseStruct::DisplayInfo( frame );
|
2008-09-13 18:59:57 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = ReturnStringFromValue( g_UnitMetric, m_Width,
|
|
|
|
EESCHEMA_INTERNAL_UNIT, true );
|
2008-09-13 18:59:57 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
frame->MsgPanel->Affiche_1_Parametre( 20, _( "Line width" ), msg, BLUE );
|
|
|
|
|
|
|
|
msg = ReturnStringFromValue( g_UnitMetric, m_Rayon,
|
|
|
|
EESCHEMA_INTERNAL_UNIT, true );
|
|
|
|
frame->MsgPanel->Affiche_1_Parametre( 40, _( "Radius" ), msg, RED );
|
|
|
|
|
|
|
|
msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x,
|
|
|
|
bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y );
|
|
|
|
|
|
|
|
frame->MsgPanel->Affiche_1_Parametre( 60, _( "Bounding box" ), msg, BROWN );
|
2008-09-13 18:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
/*************************/
|
|
|
|
/** class LibDrawSquare **/
|
|
|
|
/*************************/
|
|
|
|
|
2009-06-18 13:30:52 +00:00
|
|
|
LibDrawSquare::LibDrawSquare( EDA_LibComponentStruct* aParent ) :
|
|
|
|
LibEDA_BaseStruct( COMPONENT_RECT_DRAW_TYPE, aParent )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
m_Width = 0;
|
|
|
|
m_Fill = NO_FILL;
|
2009-04-05 20:49:15 +00:00
|
|
|
m_typeName = _( "Rectangle" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LibDrawSquare::Save( FILE* ExportFile ) const
|
|
|
|
{
|
|
|
|
fprintf( ExportFile, "S %d %d %d %d %d %d %d %c\n", m_Pos.x, m_Pos.y,
|
|
|
|
m_End.x, m_End.y, m_Unit, m_Convert, m_Width, fill_tab[m_Fill] );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LibDrawSquare::Load( char* line, wxString& errorMsg )
|
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
int cnt;
|
2009-04-05 20:49:15 +00:00
|
|
|
char tmp[256];
|
|
|
|
|
|
|
|
cnt = sscanf( &line[2], "%d %d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y,
|
|
|
|
&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-05-21 17:42:42 +00:00
|
|
|
errorMsg.Printf( _( "rectangle only had %d parameters of the required 7" ),
|
|
|
|
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-04-05 20:49:15 +00:00
|
|
|
LibDrawSquare* LibDrawSquare::GenCopy()
|
|
|
|
{
|
2009-06-18 13:30:52 +00:00
|
|
|
LibDrawSquare* newitem = new LibDrawSquare( 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;
|
|
|
|
return newitem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
int LibDrawSquare::GetPenSize( )
|
|
|
|
{
|
|
|
|
int pensize = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width;
|
|
|
|
return pensize;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
void LibDrawSquare::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
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxPoint pos1, pos2;
|
2008-09-17 17:26:25 +00:00
|
|
|
|
2009-04-05 20:49:15 +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-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,
|
2009-06-30 17:57:27 +00:00
|
|
|
GetPenSize( ), color,
|
2009-06-11 14:26:17 +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 );
|
2008-11-12 17:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
void LibDrawSquare::DisplayInfo( WinEDA_DrawFrame* frame )
|
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-04-05 20:49:15 +00:00
|
|
|
LibEDA_BaseStruct::DisplayInfo( frame );
|
2008-11-12 17:27:32 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = ReturnStringFromValue( g_UnitMetric, m_Width,
|
|
|
|
EESCHEMA_INTERNAL_UNIT, true );
|
2008-11-12 17:27:32 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
frame->MsgPanel->Affiche_1_Parametre( 20, _( "Line width" ), msg, BLUE );
|
|
|
|
}
|
2008-11-12 17:27:32 +00:00
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
EDA_Rect LibDrawSquare::GetBoundingBox()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
|
|
|
bool LibDrawSquare::HitTest( const wxPoint& aRefPoint )
|
|
|
|
{
|
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
|
2009-06-18 13:30:52 +00:00
|
|
|
if( mindist < 3 )
|
2009-06-13 17:06:07 +00:00
|
|
|
mindist = 3; // = 3 mils
|
|
|
|
|
|
|
|
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
|
|
|
|
* @param aThreshold = max distance to this object (usually the half thickness of a line)
|
|
|
|
* @param aTransMat = the transform matrix
|
|
|
|
*/
|
|
|
|
bool LibDrawSquare::HitTest( wxPoint aRefPoint, int aThreshold, const int aTransMat[2][2] )
|
|
|
|
{
|
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
|
|
|
|
start.x = actualStart.x;
|
|
|
|
end.x = actualStart.y;
|
|
|
|
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
|
|
|
/**************************/
|
|
|
|
/** class LibDrawSegment **/
|
|
|
|
/**************************/
|
2009-06-18 13:30:52 +00:00
|
|
|
LibDrawSegment::LibDrawSegment( EDA_LibComponentStruct* aParent ) :
|
|
|
|
LibEDA_BaseStruct( 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-04-05 20:49:15 +00:00
|
|
|
bool LibDrawSegment::Save( FILE* ExportFile ) const
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( ExportFile, "L %d %d %d", m_Unit, m_Convert, m_Width );
|
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-04-05 20:49:15 +00:00
|
|
|
bool LibDrawSegment::Load( char* line, wxString& errorMsg )
|
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-04-05 20:49:15 +00:00
|
|
|
LibDrawSegment* LibDrawSegment::GenCopy()
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-06-18 13:30:52 +00:00
|
|
|
LibDrawSegment* newitem = new LibDrawSegment( 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;
|
|
|
|
return newitem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
int LibDrawSegment::GetPenSize( )
|
|
|
|
{
|
|
|
|
int pensize = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width;
|
|
|
|
return pensize;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
void LibDrawSegment::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-04-05 20:49:15 +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;
|
|
|
|
|
|
|
|
GRLine( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y,
|
2009-06-30 17:57:27 +00:00
|
|
|
GetPenSize( ), color );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
void LibDrawSegment::DisplayInfo( WinEDA_DrawFrame* frame )
|
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-04-05 20:49:15 +00:00
|
|
|
LibEDA_BaseStruct::DisplayInfo( frame );
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = ReturnStringFromValue( g_UnitMetric, m_Width,
|
|
|
|
EESCHEMA_INTERNAL_UNIT, true );
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
frame->MsgPanel->Affiche_1_Parametre( 20, _( "Line width" ), msg, BLUE );
|
|
|
|
|
|
|
|
msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x,
|
|
|
|
bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y );
|
|
|
|
|
|
|
|
frame->MsgPanel->Affiche_1_Parametre( 60, _( "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
|
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
|
|
|
bool LibDrawSegment::HitTest( const wxPoint& aPosRef )
|
|
|
|
{
|
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
|
2009-06-18 13:30:52 +00:00
|
|
|
if( mindist < 3 )
|
2009-06-13 17:06:07 +00:00
|
|
|
mindist = 3; // = 3 mils
|
|
|
|
|
|
|
|
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
|
|
|
|
* @param aThreshold = max distance to this object (usually the half thickness of a line)
|
|
|
|
* @param aTransMat = the transform matrix
|
|
|
|
*/
|
|
|
|
bool LibDrawSegment::HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] )
|
|
|
|
{
|
|
|
|
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
|
|
|
/***************************/
|
|
|
|
/** class LibDrawPolyline **/
|
|
|
|
/***************************/
|
2009-06-18 13:30:52 +00:00
|
|
|
LibDrawPolyline::LibDrawPolyline( EDA_LibComponentStruct* aParent ) :
|
|
|
|
LibEDA_BaseStruct( COMPONENT_POLYLINE_DRAW_TYPE, aParent )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
m_Fill = NO_FILL;
|
|
|
|
m_Width = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
m_typeName = _( "PolyLine" );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
bool LibDrawPolyline::Save( FILE* ExportFile ) const
|
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-04-05 20:49:15 +00:00
|
|
|
fprintf( ExportFile, "P %d %d %d %d", ccount, m_Unit, m_Convert, m_Width );
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < GetCornerCount(); i++ )
|
|
|
|
{
|
|
|
|
fprintf( ExportFile, " %d %d", m_PolyPoints[i].x, m_PolyPoints[i].y );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( ExportFile, " %c\n", fill_tab[m_Fill] );
|
|
|
|
|
|
|
|
return true;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
bool LibDrawPolyline::Load( char* line, wxString& errorMsg )
|
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;
|
|
|
|
|
|
|
|
i = sscanf( &line[2], "%d %d %d %d", &ccount, &m_Unit, &m_Convert,
|
|
|
|
&m_Width );
|
|
|
|
|
|
|
|
if( i < 4 )
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
errorMsg.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-05-21 17:42:42 +00:00
|
|
|
errorMsg.Printf( _( "polyline count parameter %d is invalid" ),
|
2009-04-05 20:49:15 +00:00
|
|
|
ccount );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = strtok( &line[2], " \t\n" );
|
|
|
|
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-05-21 17:42:42 +00:00
|
|
|
errorMsg.Printf( _( "polyline point %d X position not defined" ),
|
2009-04-05 20:49:15 +00:00
|
|
|
i );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
p = strtok( NULL, " \t\n" );
|
|
|
|
if( sscanf( p, "%d", &pt.y ) != 1 )
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
errorMsg.Printf( _( "polyline point %d Y position not defined" ),
|
2009-04-05 20:49:15 +00:00
|
|
|
i );
|
|
|
|
return false;
|
|
|
|
}
|
2009-06-11 14:26:17 +00:00
|
|
|
AddPoint( pt );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LibDrawPolyline* LibDrawPolyline::GenCopy()
|
|
|
|
{
|
2009-06-18 13:30:52 +00:00
|
|
|
LibDrawPolyline* newitem = new LibDrawPolyline( GetParent() );
|
2009-01-02 17:07:50 +00:00
|
|
|
|
2009-01-02 13:19:34 +00:00
|
|
|
newitem->m_PolyPoints = m_PolyPoints; // Vector copy
|
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;
|
|
|
|
newitem->m_Fill = m_Fill;
|
|
|
|
return newitem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LibDrawPolyline::AddPoint( const wxPoint& point )
|
|
|
|
{
|
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
|
|
|
|
*/
|
|
|
|
int LibDrawPolyline::GetPenSize( )
|
|
|
|
{
|
|
|
|
int pensize = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width;
|
|
|
|
return pensize;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aOffset, int aColor, int aDrawMode,
|
|
|
|
void* aData, const int aTransformMatrix[2][2] )
|
|
|
|
{
|
|
|
|
wxPoint pos1;
|
|
|
|
|
|
|
|
int color = ReturnLayerColor( LAYER_DEVICE );
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if( fill == FILLED_WITH_BG_BODYCOLOR )
|
|
|
|
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
|
2009-06-30 17:57:27 +00:00
|
|
|
Buf_Poly_Drawings, 1, GetPenSize( ), color,
|
2009-06-11 14:26:17 +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-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
|
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
|
|
|
bool LibDrawPolyline::HitTest( const wxPoint& aRefPos )
|
|
|
|
{
|
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
|
2009-06-18 13:30:52 +00:00
|
|
|
if( mindist < 3 )
|
2009-06-13 17:06:07 +00:00
|
|
|
mindist = 3; // = 3 mils
|
|
|
|
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-04-05 20:49:15 +00:00
|
|
|
bool LibDrawPolyline::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-04-05 20:49:15 +00:00
|
|
|
EDA_Rect LibDrawPolyline::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LibDrawPolyline::DisplayInfo( WinEDA_DrawFrame* frame )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
|
|
|
|
|
|
|
LibEDA_BaseStruct::DisplayInfo( frame );
|
|
|
|
|
|
|
|
msg = ReturnStringFromValue( g_UnitMetric, m_Width,
|
|
|
|
EESCHEMA_INTERNAL_UNIT, true );
|
|
|
|
|
|
|
|
frame->MsgPanel->Affiche_1_Parametre( 20, _( "Line width" ), msg, BLUE );
|
|
|
|
|
|
|
|
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-04-05 20:49:15 +00:00
|
|
|
frame->MsgPanel->Affiche_1_Parametre( 40, _( "Bounding box" ), msg, BROWN );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
2009-06-25 20:45:27 +00:00
|
|
|
|
|
|
|
/***************************/
|
|
|
|
/** class LibDrawBezier **/
|
|
|
|
/***************************/
|
|
|
|
LibDrawBezier::LibDrawBezier( EDA_LibComponentStruct* aParent ) :
|
|
|
|
LibEDA_BaseStruct( COMPONENT_BEZIER_DRAW_TYPE, aParent )
|
|
|
|
{
|
|
|
|
m_Fill = NO_FILL;
|
|
|
|
m_Width = 0;
|
|
|
|
m_typeName = _( "Bezier" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LibDrawBezier::Save( FILE* ExportFile ) const
|
|
|
|
{
|
|
|
|
int ccount = GetCornerCount();
|
|
|
|
|
|
|
|
fprintf( ExportFile, "B %d %d %d %d", ccount, m_Unit, m_Convert, m_Width );
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < GetCornerCount(); i++ )
|
|
|
|
{
|
|
|
|
fprintf( ExportFile, " %d %d", m_BezierPoints[i].x, m_BezierPoints[i].y );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( ExportFile, " %c\n", fill_tab[m_Fill] );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LibDrawBezier::Load( char* line, wxString& errorMsg )
|
|
|
|
{
|
|
|
|
char* p;
|
|
|
|
int i, ccount = 0;
|
|
|
|
wxPoint pt;
|
|
|
|
|
|
|
|
i = sscanf( &line[2], "%d %d %d %d", &ccount, &m_Unit, &m_Convert,
|
|
|
|
&m_Width );
|
|
|
|
|
|
|
|
if( i !=4 )
|
|
|
|
{
|
|
|
|
errorMsg.Printf( _( "Bezier only had %d parameters of the required 4" ), i );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if( ccount <= 0 )
|
|
|
|
{
|
|
|
|
errorMsg.Printf( _( "Bezier count parameter %d is invalid" ),
|
|
|
|
ccount );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = strtok( &line[2], " \t\n" );
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
errorMsg.Printf( _( "Bezier point %d X position not defined" ),
|
|
|
|
i );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
p = strtok( NULL, " \t\n" );
|
|
|
|
if( sscanf( p, "%d", &pt.y ) != 1 )
|
|
|
|
{
|
|
|
|
errorMsg.Printf( _( "Bezier point %d Y position not defined" ),
|
|
|
|
i );
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LibDrawBezier* LibDrawBezier::GenCopy()
|
|
|
|
{
|
|
|
|
LibDrawBezier* newitem = new LibDrawBezier(GetParent());
|
|
|
|
|
|
|
|
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;
|
|
|
|
return newitem;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
int LibDrawBezier::GetPenSize( )
|
|
|
|
{
|
|
|
|
int pensize = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width;
|
|
|
|
return pensize;
|
|
|
|
}
|
|
|
|
|
2009-06-25 20:45:27 +00:00
|
|
|
void LibDrawBezier::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aOffset, int aColor, int aDrawMode,
|
|
|
|
void* aData, const int aTransformMatrix[2][2] )
|
|
|
|
{
|
|
|
|
wxPoint pos1;
|
|
|
|
std::vector<wxPoint> PolyPointsTraslated;
|
|
|
|
|
|
|
|
int color = ReturnLayerColor( LAYER_DEVICE );
|
|
|
|
|
|
|
|
m_PolyPoints = Bezier2Poly( m_BezierPoints[0] ,
|
|
|
|
m_BezierPoints[1] ,
|
|
|
|
m_BezierPoints[2] ,
|
|
|
|
m_BezierPoints[3]);
|
|
|
|
|
|
|
|
PolyPointsTraslated.clear();
|
|
|
|
for( unsigned int i = 0; i < m_PolyPoints.size() ; i++)
|
|
|
|
PolyPointsTraslated.push_back( TransformCoordinate( aTransformMatrix, m_PolyPoints[i] ) + aOffset);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if( fill == FILLED_WITH_BG_BODYCOLOR )
|
|
|
|
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
|
2009-06-30 17:57:27 +00:00
|
|
|
&PolyPointsTraslated[0], 1, GetPenSize( ), color,
|
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-06-30 17:57:27 +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-06-30 17:57:27 +00:00
|
|
|
&PolyPointsTraslated[0], 0, GetPenSize( ), color, color );
|
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
|
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
|
|
|
bool LibDrawBezier::HitTest( const wxPoint& aRefPos )
|
|
|
|
{
|
|
|
|
int mindist = m_Width ? m_Width /2 : g_DrawDefaultLineThickness / 2;
|
|
|
|
// Have a minimal tolerance for hit test
|
|
|
|
if ( mindist < 3 )
|
|
|
|
mindist = 3; // = 3 mils
|
|
|
|
return HitTest( aRefPos, mindist, DefaultTransformMatrix );
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
*/
|
|
|
|
bool LibDrawBezier::HitTest( wxPoint aPosRef, int aThreshold,
|
|
|
|
const int aTransMat[2][2] )
|
|
|
|
{
|
|
|
|
wxPoint ref, start, end;
|
|
|
|
|
|
|
|
for( unsigned ii = 1; ii < GetCornerCount(); ii++ )
|
|
|
|
{
|
|
|
|
start = TransformCoordinate( aTransMat, m_PolyPoints[ii - 1] );
|
|
|
|
end = TransformCoordinate( aTransMat, m_PolyPoints[ii] );
|
|
|
|
if ( TestSegmentHit( aPosRef, start, end, aThreshold ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Function GetBoundingBox
|
|
|
|
* @return the boundary box for this, in library coordinates
|
|
|
|
*/
|
|
|
|
EDA_Rect LibDrawBezier::GetBoundingBox()
|
|
|
|
{
|
|
|
|
EDA_Rect rect;
|
|
|
|
int xmin, xmax, ymin, ymax;
|
|
|
|
if(!GetCornerCount())
|
|
|
|
return rect;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LibDrawBezier::DisplayInfo( WinEDA_DrawFrame* frame )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
EDA_Rect bBox = GetBoundingBox();
|
|
|
|
|
|
|
|
LibEDA_BaseStruct::DisplayInfo( frame );
|
|
|
|
|
|
|
|
msg = ReturnStringFromValue( g_UnitMetric, m_Width,
|
|
|
|
EESCHEMA_INTERNAL_UNIT, true );
|
|
|
|
|
|
|
|
frame->MsgPanel->Affiche_1_Parametre( 20, _( "Line width" ), msg, BLUE );
|
|
|
|
|
|
|
|
msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x,
|
|
|
|
bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y );
|
|
|
|
|
|
|
|
frame->MsgPanel->Affiche_1_Parametre( 40, _( "Bounding box" ), msg, BROWN );
|
|
|
|
}
|