Code cleaning: add comments, better names for a function, simplify code. No actual code change.

This commit is contained in:
jean-pierre charras 2017-05-04 08:54:30 +02:00
parent c70adcdf31
commit d1dfa5aba3
8 changed files with 39 additions and 44 deletions

View File

@ -493,7 +493,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
switch( GetDrillShape() )
{
case PAD_DRILL_SHAPE_CIRCLE:
if( aDC->LogicalToDeviceXRel( hole ) > MIN_DRAW_WIDTH )
if( aDC->LogicalToDeviceXRel( hole ) > 1 ) // hole is drawn if hole > 1pixel
GRFilledCircle( aClipBox, aDC, holepos.x, holepos.y, hole, 0,
hole_color, hole_color );
break;

View File

@ -665,11 +665,10 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode,
GRSetDrawMode( aDC, aDrawMode );
int l_trace = m_Width / 2;
if( aDC->LogicalToDeviceXRel( l_trace ) <= MIN_DRAW_WIDTH )
// Draw track as line if width <= 1pixel:
if( aDC->LogicalToDeviceXRel( m_Width ) <= 1 )
{
GRLine( panel->GetClipBox(), aDC, m_Start + aOffset, m_End + aOffset, 0, color );
GRLine( panel->GetClipBox(), aDC, m_Start + aOffset, m_End + aOffset, m_Width, color );
return;
}
@ -733,11 +732,10 @@ void SEGZONE::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode,
GRSetDrawMode( aDC, aDrawMode );
int l_trace = m_Width / 2;
if( aDC->LogicalToDeviceXRel( l_trace ) <= MIN_DRAW_WIDTH )
// Draw track as line if width <= 1pixel:
if( aDC->LogicalToDeviceXRel( m_Width ) <= 1 )
{
GRLine( panel->GetClipBox(), aDC, m_Start + aOffset, m_End + aOffset, 0, color );
GRLine( panel->GetClipBox(), aDC, m_Start + aOffset, m_End + aOffset, m_Width, color );
return;
}
@ -868,7 +866,8 @@ void VIA::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, const w
if( (aDrawMode & GR_XOR) == 0)
GRSetDrawMode( aDC, GR_COPY );
if( aDC->LogicalToDeviceXRel( drill_radius ) > MIN_DRAW_WIDTH ) // Draw hole if large enough.
// Draw hole if the radius is > 1pixel.
if( aDC->LogicalToDeviceXRel( drill_radius ) > 1 )
GRFilledCircle( panel->GetClipBox(), aDC, m_Start.x + aOffset.x,
m_Start.y + aOffset.y, drill_radius, 0, color, color );

View File

@ -351,9 +351,8 @@ static void DrawSegment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosi
{
wxPoint pt;
CalculateSegmentEndPoint( aPanel->GetParent()->GetCrossHairPosition(),
Segment->GetStart().x, Segment->GetStart().y,
&pt.x, &pt.y );
pt = CalculateSegmentEndPoint( aPanel->GetParent()->GetCrossHairPosition(),
Segment->GetStart() );
Segment->SetEnd( pt );
}
else // here the angle is arbitrary

View File

@ -650,7 +650,7 @@ static void PushTrack( EDA_DRAW_PANEL* panel )
n.y = KiROUND( f * n.y );
wxPoint hp = track->GetEnd();
Project( &hp, cursor, other );
FindBestGridPointOnTrack( &hp, cursor, other );
track->SetEnd( hp + n );
}
@ -662,7 +662,7 @@ inline void DrawViaCirclesWhenEditingNewTrack( EDA_RECT* aPanelClipBox,
int aViaRadiusWithClearence,
COLOR4D aColor)
{
//Current viasize clearence circle
//Current viasize clearance circle
GRCircle( aPanelClipBox, aDC, aPos.x, aPos.y, aViaRadiusWithClearence, aColor );
//Current viasize circle
GRCircle( aPanelClipBox, aDC, aPos.x, aPos.y, aViaRadius, aColor );
@ -754,11 +754,8 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo
* horizontal, vertical or 45 degrees.
*/
wxPoint hp = g_CurrentTrackSegment->GetEnd();
CalculateSegmentEndPoint( frame->GetCrossHairPosition(),
g_CurrentTrackSegment->GetStart().x,
g_CurrentTrackSegment->GetStart().y,
&hp.x,
&hp.y );
hp = CalculateSegmentEndPoint( frame->GetCrossHairPosition(),
g_CurrentTrackSegment->GetStart() );
g_CurrentTrackSegment->SetEnd(hp);
}
}
@ -833,19 +830,18 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo
}
/* Determine the coordinate to advanced the the current segment
* in 0, 90, or 45 degrees, depending on position of origin and \a aPosition.
*/
void CalculateSegmentEndPoint( const wxPoint& aPosition, int ox, int oy, int* fx, int* fy )
wxPoint CalculateSegmentEndPoint( const wxPoint& aPosition, const wxPoint& aOrigin )
{
int deltax, deltay, angle;
// Determine end point for a segment direction 0, 90, or 45 degrees
// depending on it's position from the origin \a aOrigin and \a aPosition.
wxPoint endPoint;
deltax = aPosition.x - ox;
deltay = aPosition.y - oy;
int deltax = aPosition.x - aOrigin.x;
int deltay = aPosition.y - aOrigin.y;
deltax = abs( deltax );
deltay = abs( deltay );
angle = 45;
int angle = 45;
if( deltax >= deltay )
{
@ -867,8 +863,8 @@ void CalculateSegmentEndPoint( const wxPoint& aPosition, int ox, int oy, int* fx
switch( angle )
{
case 0:
*fx = aPosition.x;
*fy = oy;
endPoint.x = aPosition.x;
endPoint.y = aOrigin.y;
break;
case 45:
@ -876,21 +872,23 @@ void CalculateSegmentEndPoint( const wxPoint& aPosition, int ox, int oy, int* fx
deltay = deltax;
// Recalculate the signs for deltax and deltaY.
if( ( aPosition.x - ox ) < 0 )
if( ( aPosition.x - aOrigin.x ) < 0 )
deltax = -deltax;
if( ( aPosition.y - oy ) < 0 )
if( ( aPosition.y - aOrigin.y ) < 0 )
deltay = -deltay;
*fx = ox + deltax;
*fy = oy + deltay;
endPoint.x = aOrigin.x + deltax;
endPoint.y = aOrigin.y + deltay;
break;
case 90:
*fx = ox;
*fy = aPosition.y;
endPoint.x = aOrigin.x;
endPoint.y = aPosition.y;
break;
}
return endPoint;
}

View File

@ -94,7 +94,7 @@ static bool Join( wxPoint* aIntersectPoint, wxPoint a0, wxPoint a1, wxPoint b0,
* "Project" finds the projection of a grid point on a track. This is the point
* from where we want to draw new orthogonal tracks when starting on a track.
*/
bool Project( wxPoint* aNearPos, wxPoint on_grid, const TRACK* track )
bool FindBestGridPointOnTrack( wxPoint* aNearPos, wxPoint on_grid, const TRACK* track )
{
if( track->GetStart ()== track->GetEnd() )
return false;
@ -219,7 +219,7 @@ bool Magnetize( PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize aGridSize,
return false;
}
return Project( curpos, on_grid, track );
return FindBestGridPointOnTrack( curpos, on_grid, track );
}
/*

View File

@ -62,7 +62,6 @@ enum ENDPOINT_T {
#define TEXTS_MIN_SIZE Mils2iu( 5 ) ///< Minimum text size in Pcbnew units value (5 mils)
#define TEXTS_MAX_SIZE Mils2iu( 1000 ) ///< Maximum text size in Pcbnew units value (1 inch) )
#define TEXTS_MAX_WIDTH Mils2iu( 500 ) ///< Maximum text width in Pcbnew units value (0.5 inches)
#define MIN_DRAW_WIDTH 1 ///< Minimum trace drawing width in pixels.
// Flag to force the SKETCH mode to display items (.m_Flags member)

View File

@ -65,16 +65,16 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo
bool aErase );
/**
* Determine coordinate for a segment direction of 0, 90, or 45 degrees
* depending on it's position from the origin (ox, oy) and \a aPosiition.
* Determine end point for a segment direction 0, 90, or 45 degrees
* depending on it's position from the origin \a aOrigin and \a aPosition.
*/
void CalculateSegmentEndPoint( const wxPoint& aPosition, int ox, int oy, int* fx, int* fy );
wxPoint CalculateSegmentEndPoint( const wxPoint& aPosition, const wxPoint& aOrigin );
/**
* Finds the projection of a grid point on a track. This is the point
* from where we want to draw new orthogonal tracks when starting on a track.
*/
bool Project( wxPoint* res, wxPoint on_grid, const TRACK* track );
bool FindBestGridPointOnTrack( wxPoint* res, wxPoint on_grid, const TRACK* track );
TRACK* LocateIntrusion( TRACK* listStart, TRACK* aTrack, LAYER_NUM aLayer, const wxPoint& aRef );

View File

@ -847,7 +847,7 @@ static void Show_New_Edge_While_Move_Mouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
{
// calculate the new position as allowed
wxPoint StartPoint = static_cast<wxPoint>( zone->GetCornerPosition( icorner - 1 ) );
CalculateSegmentEndPoint( c_pos, StartPoint.x, StartPoint.y, &c_pos.x, &c_pos.y );
c_pos = CalculateSegmentEndPoint( c_pos, StartPoint );
}
zone->SetCornerPosition( icorner, c_pos );