Pcbnew: fix issues with 360 deg angle arcs.

Fixes: lp:1725943
https://bugs.launchpad.net/kicad/+bug/1725943
This commit is contained in:
jean-pierre charras 2017-10-23 15:35:03 +02:00
parent cdb577bbbc
commit 7418deb454
11 changed files with 45 additions and 22 deletions

View File

@ -601,6 +601,8 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius, d
SWAP( aStartAngle, >, aEndAngle );
const double alphaIncrement = calcAngleStep( aRadius );
printf( "st %f end %f alphaIncrement = %f\n",
aStartAngle * 180/M_PI, aEndAngle * 180/M_PI, alphaIncrement * 180/M_PI);
Save();
currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );

View File

@ -263,14 +263,17 @@ bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy )
/* Move selected sheet with the cursor.
* Callback function used by m_mouseCaptureCallback.
* Note also now this function is aclled only when resizing the sheet
* Note also now this function is called only when resizing the sheet
* But the (very small code) relative to sheet move is still present here
*/
static void resizeSheetWithMouseCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase )
{
BASE_SCREEN* screen = aPanel->GetScreen();
SCH_SHEET* sheet = (SCH_SHEET*) screen->GetCurItem();
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( screen->GetCurItem() );
if( sheet == nullptr ) // Be sure we are using the right object
return;
if( aErase )
sheet->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );

View File

@ -206,8 +206,20 @@ inline double RAD2DECIDEG( double rad ) { return rad * 1800.0 / M_PI; }
/* These are templated over T (and not simply double) because eeschema
is still using int for angles in some place */
/// Normalize angle to be in the -360.0 .. 360.0:
template <class T> inline T NormalizeAngle360( T Angle )
/// Normalize angle to be >=-360.0 and <= 360.0
/// Angle can be equal to -360 or +360
template <class T> inline T NormalizeAngle360Max( T Angle )
{
while( Angle < -3600 )
Angle += 3600;
while( Angle > 3600 )
Angle -= 3600;
return Angle;
}
/// Normalize angle to be > -360.0 and < 360.0
/// Angle equal to -360 or +360 are set to 0
template <class T> inline T NormalizeAngle360Min( T Angle )
{
while( Angle <= -3600 )
Angle += 3600;
@ -216,7 +228,6 @@ template <class T> inline T NormalizeAngle360( T Angle )
return Angle;
}
/// Normalize angle to be in the 0.0 .. 360.0 range:
/// angle is in 1/10 degees
template <class T> inline T NormalizeAnglePos( T Angle )
@ -243,6 +254,8 @@ inline double NormalizeAngleDegreesPos( double Angle )
Angle -= 360.0;
return Angle;
}
inline void NORMALIZE_ANGLE_DEGREES_POS( double& Angle )
{
Angle = NormalizeAngleDegreesPos( Angle );
@ -258,6 +271,7 @@ template <class T, class T2> inline T AddAngles( T a1, T2 a2 )
return a1;
}
template <class T> inline T NegateAndNormalizeAnglePos( T Angle )
{
Angle = -Angle;

View File

@ -299,7 +299,7 @@ public:
void SetTextAngle( double aAngle )
{
EDA_TEXT::SetTextAngle( NormalizeAngle360( aAngle ) );
EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) );
}
/**

View File

@ -186,7 +186,8 @@ double DRAWSEGMENT::GetArcAngleStart() const
void DRAWSEGMENT::SetAngle( double aAngle )
{
m_Angle = NormalizeAngle360( aAngle );
// m_Angle must be >= -360 and <= +360 degrees
m_Angle = NormalizeAngle360Max( aAngle );
}

View File

@ -1120,7 +1120,7 @@ void D_PAD::Rotate( const wxPoint& aRotCentre, double aAngle )
{
RotatePoint( &m_Pos, aRotCentre, aAngle );
m_Orient = NormalizeAngle360( m_Orient + aAngle );
m_Orient = NormalizeAngle360Min( m_Orient + aAngle );
SetLocalCoord();
}

View File

@ -62,7 +62,7 @@ TEXTE_PCB::~TEXTE_PCB()
void TEXTE_PCB::SetTextAngle( double aAngle )
{
EDA_TEXT::SetTextAngle( NormalizeAngle360( aAngle ) );
EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) );
}

View File

@ -85,7 +85,7 @@ TEXTE_MODULE::~TEXTE_MODULE()
void TEXTE_MODULE::SetTextAngle( double aAngle )
{
EDA_TEXT::SetTextAngle( NormalizeAngle360( aAngle ) );
EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) );
}

View File

@ -290,11 +290,11 @@ bool DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::Validate()
// Check angle of arc.
double angle;
m_AngleCtrl->GetValue().ToDouble( &angle );
angle = NormalizeAngle360( angle );
angle = NormalizeAngle360Max( angle );
if( angle == 0 )
{
error_msgs.Add( _( "The arc angle must be greater than zero." ) );
error_msgs.Add( _( "The arc angle cannot be zero." ) );
}
// Fall through.

View File

@ -1545,7 +1545,7 @@ void PCB_IO::format( TEXTE_MODULE* aText, int aNestLevel ) const
#else
// Choose compatibility for now, even though this is only a 720 degree clamp
// with two possible values for every angle.
orient = NormalizeAngle360( orient + parent->GetOrientation() );
orient = NormalizeAngle360Min( orient + parent->GetOrientation() );
#endif
}

View File

@ -931,6 +931,9 @@ void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment, int aLayer )
break;
case S_ARC:
printf( "S_ARC st %f end %f angle %f\n",
aSegment->GetArcAngleStart()/10.0, (aSegment->GetArcAngleStart() + aSegment->GetAngle())/10.0,
aSegment->GetAngle()/10.0 );
m_gal->DrawArcSegment( start, aSegment->GetRadius(),
DECIDEG2RAD( aSegment->GetArcAngleStart() ),
DECIDEG2RAD( aSegment->GetArcAngleStart() + aSegment->GetAngle() ),