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() ) switch( GetDrillShape() )
{ {
case PAD_DRILL_SHAPE_CIRCLE: 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, GRFilledCircle( aClipBox, aDC, holepos.x, holepos.y, hole, 0,
hole_color, hole_color ); hole_color, hole_color );
break; break;

View File

@ -665,11 +665,10 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode,
GRSetDrawMode( aDC, aDrawMode ); GRSetDrawMode( aDC, aDrawMode );
int l_trace = m_Width / 2; // Draw track as line if width <= 1pixel:
if( aDC->LogicalToDeviceXRel( m_Width ) <= 1 )
if( aDC->LogicalToDeviceXRel( l_trace ) <= MIN_DRAW_WIDTH )
{ {
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; return;
} }
@ -733,11 +732,10 @@ void SEGZONE::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode,
GRSetDrawMode( aDC, aDrawMode ); GRSetDrawMode( aDC, aDrawMode );
int l_trace = m_Width / 2; // Draw track as line if width <= 1pixel:
if( aDC->LogicalToDeviceXRel( m_Width ) <= 1 )
if( aDC->LogicalToDeviceXRel( l_trace ) <= MIN_DRAW_WIDTH )
{ {
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; return;
} }
@ -868,7 +866,8 @@ void VIA::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, const w
if( (aDrawMode & GR_XOR) == 0) if( (aDrawMode & GR_XOR) == 0)
GRSetDrawMode( aDC, GR_COPY ); 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, GRFilledCircle( panel->GetClipBox(), aDC, m_Start.x + aOffset.x,
m_Start.y + aOffset.y, drill_radius, 0, color, color ); 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; wxPoint pt;
CalculateSegmentEndPoint( aPanel->GetParent()->GetCrossHairPosition(), pt = CalculateSegmentEndPoint( aPanel->GetParent()->GetCrossHairPosition(),
Segment->GetStart().x, Segment->GetStart().y, Segment->GetStart() );
&pt.x, &pt.y );
Segment->SetEnd( pt ); Segment->SetEnd( pt );
} }
else // here the angle is arbitrary 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 ); n.y = KiROUND( f * n.y );
wxPoint hp = track->GetEnd(); wxPoint hp = track->GetEnd();
Project( &hp, cursor, other ); FindBestGridPointOnTrack( &hp, cursor, other );
track->SetEnd( hp + n ); track->SetEnd( hp + n );
} }
@ -662,7 +662,7 @@ inline void DrawViaCirclesWhenEditingNewTrack( EDA_RECT* aPanelClipBox,
int aViaRadiusWithClearence, int aViaRadiusWithClearence,
COLOR4D aColor) COLOR4D aColor)
{ {
//Current viasize clearence circle //Current viasize clearance circle
GRCircle( aPanelClipBox, aDC, aPos.x, aPos.y, aViaRadiusWithClearence, aColor ); GRCircle( aPanelClipBox, aDC, aPos.x, aPos.y, aViaRadiusWithClearence, aColor );
//Current viasize circle //Current viasize circle
GRCircle( aPanelClipBox, aDC, aPos.x, aPos.y, aViaRadius, aColor ); 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. * horizontal, vertical or 45 degrees.
*/ */
wxPoint hp = g_CurrentTrackSegment->GetEnd(); wxPoint hp = g_CurrentTrackSegment->GetEnd();
CalculateSegmentEndPoint( frame->GetCrossHairPosition(), hp = CalculateSegmentEndPoint( frame->GetCrossHairPosition(),
g_CurrentTrackSegment->GetStart().x, g_CurrentTrackSegment->GetStart() );
g_CurrentTrackSegment->GetStart().y,
&hp.x,
&hp.y );
g_CurrentTrackSegment->SetEnd(hp); 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 wxPoint CalculateSegmentEndPoint( const wxPoint& aPosition, const wxPoint& aOrigin )
* 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 )
{ {
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; int deltax = aPosition.x - aOrigin.x;
deltay = aPosition.y - oy; int deltay = aPosition.y - aOrigin.y;
deltax = abs( deltax ); deltax = abs( deltax );
deltay = abs( deltay ); deltay = abs( deltay );
angle = 45; int angle = 45;
if( deltax >= deltay ) if( deltax >= deltay )
{ {
@ -867,8 +863,8 @@ void CalculateSegmentEndPoint( const wxPoint& aPosition, int ox, int oy, int* fx
switch( angle ) switch( angle )
{ {
case 0: case 0:
*fx = aPosition.x; endPoint.x = aPosition.x;
*fy = oy; endPoint.y = aOrigin.y;
break; break;
case 45: case 45:
@ -876,21 +872,23 @@ void CalculateSegmentEndPoint( const wxPoint& aPosition, int ox, int oy, int* fx
deltay = deltax; deltay = deltax;
// Recalculate the signs for deltax and deltaY. // Recalculate the signs for deltax and deltaY.
if( ( aPosition.x - ox ) < 0 ) if( ( aPosition.x - aOrigin.x ) < 0 )
deltax = -deltax; deltax = -deltax;
if( ( aPosition.y - oy ) < 0 ) if( ( aPosition.y - aOrigin.y ) < 0 )
deltay = -deltay; deltay = -deltay;
*fx = ox + deltax; endPoint.x = aOrigin.x + deltax;
*fy = oy + deltay; endPoint.y = aOrigin.y + deltay;
break; break;
case 90: case 90:
*fx = ox; endPoint.x = aOrigin.x;
*fy = aPosition.y; endPoint.y = aPosition.y;
break; 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 * "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. * 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() ) if( track->GetStart ()== track->GetEnd() )
return false; return false;
@ -219,7 +219,7 @@ bool Magnetize( PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize aGridSize,
return false; 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_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_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 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) // 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 ); bool aErase );
/** /**
* Determine coordinate for a segment direction of 0, 90, or 45 degrees * Determine end point for a segment direction 0, 90, or 45 degrees
* depending on it's position from the origin (ox, oy) and \a aPosiition. * 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 * 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. * 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 ); 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 // calculate the new position as allowed
wxPoint StartPoint = static_cast<wxPoint>( zone->GetCornerPosition( icorner - 1 ) ); 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 ); zone->SetCornerPosition( icorner, c_pos );