Commit 14e3507e authored by jean-pierre charras's avatar jean-pierre charras

gr_basic: fix incorrect clipping of thick lines (due to changes in code, the...

gr_basic: fix incorrect clipping of thick lines (due to changes in code, the thickness was not taken in account to calculate the clip box size)
Pcbnew: fix a very minor bug.
parents 0cedcb87 e9c618b6
......@@ -43,7 +43,7 @@ after calling this conversion function, the comma is changed in point.
(Happens after reading a parameter stored in a wxConfig structure, if this
parameter is a double)
Workaround:
Use a version > 2.9.2
Use a version > 2.9.1
Currently ( 2011, april 12 ) the 2.9.2 is not yet finalized
(and can be found only on the wxWidgets snv server)
......
......@@ -63,7 +63,6 @@ static void ClipAndDrawFilledPoly( EDA_RECT * ClipBox, wxDC * DC, wxPoint Points
* ( GRSCircle is called by GRCircle for instance) after mapping coordinates
* from user units to screen units(pixels coordinates)
*/
static void GRSMoveTo( int x, int y );
static void GRSRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1,
int x2, int y2, int aWidth, int aColor,
wxPenStyle aStyle = wxPENSTYLE_SOLID );
......@@ -326,18 +325,9 @@ static void WinClipAndDrawLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int
if( ClipBox )
{
xcliplo = ClipBox->GetX();
ycliplo = ClipBox->GetY();
xcliphi = ClipBox->GetRight();
ycliphi = ClipBox->GetBottom();
xcliplo -= width;
ycliplo -= width;
xcliphi += width;
ycliphi += width;
if( clipLine( ClipBox, x1, y1, x2, y2 ) )
EDA_RECT clipbox(*ClipBox);
clipbox.Inflate(width/2);
if( clipLine( &clipbox, x1, y1, x2, y2 ) )
return;
}
......@@ -591,15 +581,6 @@ void GRMixedLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
}
/*
* Move to a new position, in screen (pixels) space.
*/
void GRSMoveTo( int x, int y )
{
GRLastMoveToX = x;
GRLastMoveToY = y;
}
/**
* Function GRLineArray
......@@ -634,15 +615,22 @@ void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC, std::vector<wxPoint>& aLines,
gc->ResetClip();
delete gc;
#else
for( unsigned i = 0; i < aLines.size(); )
if( aClipBox )
aClipBox->Inflate(aWidth/2);
for( unsigned i = 0; i < aLines.size(); i += 2)
{
WinClipAndDrawLine( aClipBox, aDC, aLines[i].x, aLines[i].y,
aLines[i + 1].x, aLines[i + 1].y, aColor, aWidth );
i++;
GRLastMoveToX = aLines[i].x;
GRLastMoveToY = aLines[i].y;
i++;
int x1 = aLines[i].x;
int y1 = aLines[i].y;
int x2 = aLines[i+1].x;
int y2 = aLines[i+1].y;
GRLastMoveToX = x2;
GRLastMoveToY = y2;
if( ( aClipBox == NULL ) || clipLine( aClipBox, x1, y1, x2, y2 ) )
aDC->DrawLine( x1, y1, x2, y2 );
}
if( aClipBox )
aClipBox->Inflate(-aWidth/2);
#endif
}
......@@ -663,18 +651,10 @@ void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
if( ClipBox )
{
xcliplo = ClipBox->GetX();
ycliplo = ClipBox->GetY();
xcliphi = ClipBox->GetRight();
ycliphi = ClipBox->GetHeight();
xcliplo -= width;
ycliplo -= width;
xcliphi += width;
ycliphi += width;
EDA_RECT clipbox(*ClipBox);
clipbox.Inflate(width/2);
if( clipLine( ClipBox, x1, y1, x2, y2 ) )
if( clipLine( &clipbox, x1, y1, x2, y2 ) )
return;
}
......@@ -935,7 +915,8 @@ static void GRSClosedPoly( EDA_RECT* ClipBox,
if( Fill && ( aPointCount > 2 ) )
{
GRSMoveTo( aPoints[aPointCount - 1].x, aPoints[aPointCount - 1].y );
GRLastMoveToX = aPoints[aPointCount - 1].x;
GRLastMoveToY = aPoints[aPointCount - 1].y;
GRSetBrush( DC, BgColor, FILLED );
#ifdef USE_CLIP_FILLED_POLYGONS
ClipAndDrawFilledPoly( ClipBox, DC, aPoints, aPointCount );
......@@ -1345,12 +1326,19 @@ void GRSRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2,
points[4] = points[0];
GRSetColorPen( aDC, aColor, aWidth, aStyle );
GRSetBrush( aDC, BLACK );
ClipAndDrawFilledPoly(aClipBox, aDC, points, 5); // polygon approach is more accurate
if( aClipBox )
{
EDA_RECT clipbox(*aClipBox);
clipbox.Inflate(aWidth);
ClipAndDrawFilledPoly(&clipbox, aDC, points, 5); // polygon approach is more accurate
}
else
ClipAndDrawFilledPoly(aClipBox, aDC, points, 5);
}
void GRSFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
int width, int Color, int BgColor )
void GRSFilledRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2,
int aWidth, int aColor, int aBgColor )
{
wxPoint points[5];
......@@ -1359,9 +1347,16 @@ void GRSFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
points[2] = wxPoint(x2, y2);
points[3] = wxPoint(x2, y1);
points[4] = points[0];
GRSetBrush( DC, BgColor, FILLED );
GRSetColorPen( DC, BgColor, width );
ClipAndDrawFilledPoly(ClipBox, DC, points, 5); // polygon approach is more accurate
GRSetBrush( aDC, aBgColor, FILLED );
GRSetColorPen( aDC, aBgColor, aWidth );
if( aClipBox && (aWidth > 0) )
{
EDA_RECT clipbox(*aClipBox);
clipbox.Inflate(aWidth);
ClipAndDrawFilledPoly(&clipbox, aDC, points, 5); // polygon approach is more accurate
}
else
ClipAndDrawFilledPoly(aClipBox, aDC, points, 5);
}
......
......@@ -818,8 +818,32 @@ public:
*/
void Edit_TrackSegm_Width( wxDC* aDC, TRACK* aTrackItem );
TRACK* Begin_Route( TRACK* track, wxDC* DC );
void End_Route( TRACK* track, wxDC* DC );
/**
* Function Begin_Route
* Starts a new track and/or establish of a new track point.
*
* For a new track:
* - Search the netname of the new track from the starting point
* if it is on a pad or an existing track
* - Highlight all this net
* If a track is in progress:
* - Call DRC
* - If DRC is OK: finish the track segment and starts a new one.
* @param aTrack = the current track segment, or NULL to start a new track
* @param aDC = the current device context
* @return a pointer to the new track segment or null if not created (DRC error)
*/
TRACK* Begin_Route( TRACK* aTrack, wxDC* aDC );
/**
* Function End_Route
* Terminates a track currently being created
* @param aTrack = the current track segment in progress
* @param aDC = the current device context
* @return true if the track was created, false if not (due to a DRC error)
*/
bool End_Route( TRACK* aTrack, wxDC* aDC );
void ExChange_Track_Layer( TRACK* pt_segm, wxDC* DC );
void Attribut_Segment( TRACK* track, wxDC* DC, bool Flag_On );
void Attribut_Track( TRACK* track, wxDC* DC, bool Flag_On );
......
......@@ -88,6 +88,24 @@ BOARD::~BOARD()
delete m_NetInfo;
}
/*
* Function PushHightLight
* save current hight light info for later use
*/
void BOARD::PushHightLight()
{
m_hightLightPrevious = m_hightLight;
}
/*
* Function PopHightLight
* retrieve a previously saved hight light info
*/
void BOARD::PopHightLight()
{
m_hightLight = m_hightLightPrevious;
m_hightLightPrevious.Clear();
}
/**
* Function SetCurrentNetClass
......
......@@ -321,17 +321,13 @@ public:
* Function PushHightLight
* save current hight light info for later use
*/
void PushHightLight() { m_hightLightPrevious = m_hightLight; }
void PushHightLight();
/**
* Function PopHightLight
* retrieve a previously saved hight light info
*/
void PopHightLight()
{
m_hightLight = m_hightLightPrevious;
m_hightLightPrevious.Clear();
}
void PopHightLight();
/**
* Function GetCopperLayerCount
......
......@@ -187,8 +187,7 @@ int TRACK::IsPointOnEnds( const wxPoint& point, int min_dist )
}
else
{
double dist = ( (double) dx * dx ) + ( (double) dy * dy );
dist = sqrt( dist );
double dist = hypot( (double)dx, (double) dy );
if( min_dist >= (int) dist )
result |= STARTPOINT;
}
......@@ -202,8 +201,7 @@ int TRACK::IsPointOnEnds( const wxPoint& point, int min_dist )
}
else
{
double dist = ( (double) dx * dx ) + ( (double) dy * dy );
dist = sqrt( dist );
double dist = hypot( (double) dx, (double) dy );
if( min_dist >= (int) dist )
result |= ENDPOINT;
}
......@@ -626,17 +624,13 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint&
if( DC->LogicalToDeviceXRel( l_piste ) < L_MIN_DESSIN )
{
GRLine( &panel->m_ClipBox, DC, m_Start.x + aOffset.x,
m_Start.y + aOffset.y,
m_End.x + aOffset.x, m_End.y + aOffset.y, 0, color );
GRLine( &panel->m_ClipBox, DC, m_Start + aOffset, m_End + aOffset, 0, color );
return;
}
if( !DisplayOpt.DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
{
GRCSegm( &panel->m_ClipBox, DC, m_Start.x + aOffset.x,
m_Start.y + aOffset.y,
m_End.x + aOffset.x, m_End.y + aOffset.y, m_Width, color );
GRCSegm( &panel->m_ClipBox, DC, m_Start + aOffset, m_End + aOffset, m_Width, color );
}
else
{
......@@ -651,9 +645,7 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint&
// Show clearance for tracks, not for zone segments
if( ShowClearance( this ) )
{
GRCSegm( &panel->m_ClipBox, DC, m_Start.x + aOffset.x,
m_Start.y + aOffset.y,
m_End.x + aOffset.x, m_End.y + aOffset.y,
GRCSegm( &panel->m_ClipBox, DC, m_Start + aOffset, m_End + aOffset,
m_Width + (GetClearance() * 2), color );
}
......@@ -784,18 +776,14 @@ void SEGVIA::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint
}
if( fillvia )
GRFilledCircle( &panel->m_ClipBox, DC, m_Start.x + aOffset.x,
m_Start.y + aOffset.y, rayon, 0, color, color );
GRFilledCircle( &panel->m_ClipBox, DC, m_Start + aOffset, rayon, color );
else
{
GRCircle( &panel->m_ClipBox, DC, m_Start.x + aOffset.x,
m_Start.y + aOffset.y, rayon, color );
GRCircle( &panel->m_ClipBox, DC, m_Start + aOffset,rayon, 0, color );
if ( fast_draw )
return;
GRCircle( &panel->m_ClipBox, DC, m_Start.x + aOffset.x,
m_Start.y + aOffset.y,
inner_rayon, color );
GRCircle( &panel->m_ClipBox, DC, m_Start + aOffset, inner_rayon, 0, color );
}
// Draw the via hole if the display option allows it
......@@ -831,17 +819,14 @@ void SEGVIA::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint
else
{
if( drill_rayon < inner_rayon ) // We can show the via hole
GRCircle( &panel->m_ClipBox, DC, m_Start.x + aOffset.x,
m_Start.y + aOffset.y,
drill_rayon, color );
GRCircle( &panel->m_ClipBox, DC, m_Start + aOffset, drill_rayon, 0, color );
}
}
}
if( DisplayOpt.ShowTrackClearanceMode == SHOW_CLEARANCE_ALWAYS )
GRCircle( &panel->m_ClipBox, DC, m_Start.x + aOffset.x,
m_Start.y + aOffset.y,
rayon + GetClearance(), color );
GRCircle( &panel->m_ClipBox, DC, m_Start + aOffset,
rayon + GetClearance(), 0, color );
// for Micro Vias, draw a partial cross :
// X on component layer, or + on copper layer
......
......@@ -17,7 +17,7 @@
#include "protos.h"
static void Exit_Editrack( EDA_DRAW_PANEL* panel, wxDC* DC );
static void Abort_Create_Track( EDA_DRAW_PANEL* panel, wxDC* DC );
void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
const wxPoint& aPosition, bool aErase );
static void ComputeBreakPoint( TRACK* track, int n, wxPoint end );
......@@ -30,7 +30,7 @@ static PICKED_ITEMS_LIST s_ItemsListPicker;
/* Routine to cancel the route if a track is being drawn, or exit the
* application EDITRACK.
*/
static void Exit_Editrack( EDA_DRAW_PANEL* Panel, wxDC* DC )
static void Abort_Create_Track( EDA_DRAW_PANEL* Panel, wxDC* DC )
{
PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Panel->GetParent();
BOARD * pcb = frame->GetBoard();
......@@ -45,11 +45,11 @@ static void Exit_Editrack( EDA_DRAW_PANEL* Panel, wxDC* DC )
pcb->PopHightLight();
if( pcb->IsHightLightNetON() )
frame->High_Light( DC );
pcb->DrawHighLight( Panel, DC, pcb->GetHightLightNetCode() );
frame->MsgPanel->EraseMsgBox();
// Undo pending changes (mainly a lock point cretion) and clear the
// Undo pending changes (mainly a lock point creation) and clear the
// undo picker list:
frame->PutDataInPreviousState( &s_ItemsListPicker, false, false );
s_ItemsListPicker.ClearListAndDeleteItems();
......@@ -63,16 +63,19 @@ static void Exit_Editrack( EDA_DRAW_PANEL* Panel, wxDC* DC )
/*
* Begin drawing a new track and/or establish of a new track point.
* Function Begin_Route
* Starts a new track and/or establish of a new track point.
*
* If no current track record of:
* - Search netname of the new track (pad out departure netname
* if the departure runway on an old track
* - Highlight all the net
* - Initialize the various trace pointers.
* If current track:
* - Control DRC
* - OK if DRC: adding a new track.
* For a new track:
* - Search the netname of the new track from the starting point
* if it is on a pad or an existing track
* - Highlight all this net
* If a track is in progress:
* - Call DRC
* - If DRC is OK: finish the track segment and starts a new one.
* param aTrack = the current track segment, or NULL to start a new track
* param aDC = the current device context
* return a pointer to the new track segment or null if not created (DRC error)
*/
TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC )
{
......@@ -83,10 +86,10 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC )
BOARD_ITEM* LockPoint;
wxPoint pos = GetScreen()->GetCrossHairPosition();
DrawPanel->SetMouseCapture( ShowNewTrackWhenMovingCursor, Exit_Editrack );
if( aTrack == NULL ) /* Starting a new track */
{
DrawPanel->SetMouseCapture( ShowNewTrackWhenMovingCursor, Abort_Create_Track );
// Prepare the undo command info
s_ItemsListPicker.ClearListAndDeleteItems(); // Should not be
// necessary,
......@@ -141,7 +144,8 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC )
D( g_CurrentTrackList.VerifyListIntegrity(); );
High_Light( DC );
GetBoard()->HightLightON();
GetBoard()->DrawHighLight( DrawPanel, DC, GetBoard()->GetHightLightNetCode() );
// Display info about track Net class, and init track and vias sizes:
g_CurrentTrackSegment->SetNet( GetBoard()->GetHightLightNetCode() );
......@@ -408,19 +412,22 @@ bool PCB_EDIT_FRAME::Add_45_degrees_Segment( wxDC* DC )
/*
* End trace route in progress.
* Function End_Route
* Terminates a track currently being created
* param aTrack = the current track segment in progress
* @return true if the track was created, false if not (due to a DRC error)
*/
void PCB_EDIT_FRAME::End_Route( TRACK* aTrack, wxDC* DC )
bool PCB_EDIT_FRAME::End_Route( TRACK* aTrack, wxDC* DC )
{
int masquelayer =
g_TabOneLayerMask[( (PCB_SCREEN*) GetScreen() )->m_Active_Layer];
if( aTrack == NULL )
return;
return false;
if( Drc_On && BAD_DRC==
m_drc->Drc( g_CurrentTrackSegment, GetBoard()->m_Track ) )
return;
return false;
/* Sauvegarde des coord du point terminal de la piste */
wxPoint pos = g_CurrentTrackSegment->m_End;
......@@ -428,7 +435,7 @@ void PCB_EDIT_FRAME::End_Route( TRACK* aTrack, wxDC* DC )
D( g_CurrentTrackList.VerifyListIntegrity(); );
if( Begin_Route( aTrack, DC ) == NULL )
return;
return false;
ShowNewTrackWhenMovingCursor( DrawPanel, DC, wxDefaultPosition, true );
ShowNewTrackWhenMovingCursor( DrawPanel, DC, wxDefaultPosition, false );
......@@ -531,10 +538,12 @@ void PCB_EDIT_FRAME::End_Route( TRACK* aTrack, wxDC* DC )
GetBoard()->PopHightLight();
if( GetBoard()->IsHightLightNetON() )
High_Light( DC );
GetBoard()->DrawHighLight( DrawPanel, DC, GetBoard()->GetHightLightNetCode() );
DrawPanel->SetMouseCapture( NULL, NULL );
SetCurItem( NULL );
return true;
}
......
......@@ -410,7 +410,7 @@ void PCB_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
case TYPE_VIA:
if( DrawStruct->IsNew() )
{
End_Route( (TRACK*) DrawStruct, aDC );
if( End_Route( (TRACK*) DrawStruct, aDC ) )
DrawPanel->m_AutoPAN_Request = false;
}
else if( DrawStruct->m_Flags == 0 )
......@@ -448,7 +448,7 @@ void PCB_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
case ID_TRACK_BUTT:
if( DrawStruct && DrawStruct->IsNew() )
{
End_Route( (TRACK*) DrawStruct, aDC );
if( End_Route( (TRACK*) DrawStruct, aDC ) )
DrawPanel->m_AutoPAN_Request = false;
}
break;
......
......@@ -197,7 +197,6 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* DC,
Trace_Pads_Only( aPanel, DC, module, 0, 0, layerMask, aDrawMode );
}
// @todo: this high-light functionality could be built into me.
if( IsHightLightNetON() )
DrawHighLight( aPanel, DC, GetHightLightNetCode() );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment