diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index ad485bb57e..0cf507b256 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -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 ); diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index 6538cb4781..f38e01d666 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -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( 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 ); diff --git a/include/trigo.h b/include/trigo.h index 516636f29e..5cb93f93b2 100644 --- a/include/trigo.h +++ b/include/trigo.h @@ -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 inline T NormalizeAngle360( T Angle ) +/// Normalize angle to be >=-360.0 and <= 360.0 +/// Angle can be equal to -360 or +360 +template 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 inline T NormalizeAngle360Min( T Angle ) { while( Angle <= -3600 ) Angle += 3600; @@ -216,7 +228,6 @@ template 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 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 inline T AddAngles( T a1, T2 a2 ) return a1; } + template inline T NegateAndNormalizeAnglePos( T Angle ) { Angle = -Angle; diff --git a/include/worksheet_shape_builder.h b/include/worksheet_shape_builder.h index c9bcd904b4..32bc63db80 100644 --- a/include/worksheet_shape_builder.h +++ b/include/worksheet_shape_builder.h @@ -299,7 +299,7 @@ public: void SetTextAngle( double aAngle ) { - EDA_TEXT::SetTextAngle( NormalizeAngle360( aAngle ) ); + EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) ); } /** diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp index 82c133a187..b516dfb4af 100644 --- a/pcbnew/class_drawsegment.cpp +++ b/pcbnew/class_drawsegment.cpp @@ -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 ); } diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index bd1f5f58a0..9847fafefc 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -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(); } diff --git a/pcbnew/class_pcb_text.cpp b/pcbnew/class_pcb_text.cpp index 4edae5ad16..899a69ac7b 100644 --- a/pcbnew/class_pcb_text.cpp +++ b/pcbnew/class_pcb_text.cpp @@ -62,7 +62,7 @@ TEXTE_PCB::~TEXTE_PCB() void TEXTE_PCB::SetTextAngle( double aAngle ) { - EDA_TEXT::SetTextAngle( NormalizeAngle360( aAngle ) ); + EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) ); } diff --git a/pcbnew/class_text_mod.cpp b/pcbnew/class_text_mod.cpp index c9c451df38..933e65228e 100644 --- a/pcbnew/class_text_mod.cpp +++ b/pcbnew/class_text_mod.cpp @@ -85,7 +85,7 @@ TEXTE_MODULE::~TEXTE_MODULE() void TEXTE_MODULE::SetTextAngle( double aAngle ) { - EDA_TEXT::SetTextAngle( NormalizeAngle360( aAngle ) ); + EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) ); } diff --git a/pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp b/pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp index 9de5632d90..2325527ae0 100644 --- a/pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp +++ b/pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp @@ -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. diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index 21d4b7ce3a..ad1a5a0211 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -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 } diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index dd5ceb6abc..7ab373d3f3 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -301,7 +301,7 @@ bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer ) break; case PCB_ZONE_AREA_T: - draw( static_cast( item ), aLayer ); + draw( static_cast( item ), aLayer ); break; case PCB_DIMENSION_T: @@ -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() ), @@ -1082,15 +1085,15 @@ void PCB_PAINTER::draw( const MODULE* aModule, int aLayer ) } -void PCB_PAINTER::draw( const ZONE_CONTAINER* aZone, int aLayer ) +void PCB_PAINTER::draw( const ZONE_CONTAINER* aZone, int aLayer ) { - - if( !aZone->IsOnLayer( (PCB_LAYER_ID) aLayer ) ) - { - return; - } - - const COLOR4D& color = m_pcbSettings.GetColor( aZone, aLayer ); + + if( !aZone->IsOnLayer( (PCB_LAYER_ID) aLayer ) ) + { + return; + } + + const COLOR4D& color = m_pcbSettings.GetColor( aZone, aLayer ); std::deque corners; PCB_RENDER_SETTINGS::DISPLAY_ZONE_MODE displayMode = m_pcbSettings.m_displayZone;