From 9618c3a5f592d08718b3048d596f867a1f1adf73 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 5 Jan 2011 18:28:55 +0100 Subject: [PATCH] Pcbnew: Bug fix: arcs in modules outlines (when flipped) were incorrectly saved and read in .brd files. this was due to incorrect macro NORMALIZE_ANGLE (was the same as NORMALIZE_ANGLE_POS), now modified and renamed NORMALIZE_ANGLE_360 --- eeschema/lib_arc.cpp | 12 ++++++------ eeschema/transform.cpp | 8 ++++---- include/macros.h | 7 ++++--- pcbnew/block.cpp | 8 +++++--- pcbnew/block_module_editor.cpp | 4 ++-- pcbnew/class_edge_mod.cpp | 2 +- pcbnew/dialogs/dialog_graphic_item_properties.cpp | 2 +- pcbnew/edit_pcb_text.cpp | 2 +- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/eeschema/lib_arc.cpp b/eeschema/lib_arc.cpp index 4d4063c32c..2089de75e9 100644 --- a/eeschema/lib_arc.cpp +++ b/eeschema/lib_arc.cpp @@ -126,8 +126,8 @@ bool LIB_ARC::Load( char* aLine, wxString& aErrorMsg ) if( tmp[0] == 'f' ) m_Fill = FILLED_WITH_BG_BODYCOLOR; - NORMALIZE_ANGLE( m_t1 ); - NORMALIZE_ANGLE( m_t2 ); + NORMALIZE_ANGLE_POS( m_t1 ); + NORMALIZE_ANGLE_POS( m_t2 ); // Actual Coordinates of arc ends are read from file if( cnt >= 13 ) @@ -712,8 +712,8 @@ void LIB_ARC::calcRadiusAngles() m_t2 = (int) ( atan2( (double) centerEndVector.y, (double) centerEndVector.x ) * 1800 / M_PI ); - NORMALIZE_ANGLE( m_t1 ); - NORMALIZE_ANGLE( m_t2 ); // angles = 0 .. 3600 + NORMALIZE_ANGLE_POS( m_t1 ); + NORMALIZE_ANGLE_POS( m_t2 ); // angles = 0 .. 3600 // Restrict angle to less than 180 to avoid PBS display mirror Trace because it is // assumed that the arc is less than 180 deg to find orientation after rotate or mirror. @@ -734,8 +734,8 @@ void LIB_ARC::calcRadiusAngles() m_t1--; } - NORMALIZE_ANGLE( m_t1 ); + NORMALIZE_ANGLE_POS( m_t1 ); if( !IsMoving() ) - NORMALIZE_ANGLE( m_t2 ); + NORMALIZE_ANGLE_POS( m_t2 ); } diff --git a/eeschema/transform.cpp b/eeschema/transform.cpp index 3eba67c633..86763a77ba 100644 --- a/eeschema/transform.cpp +++ b/eeschema/transform.cpp @@ -62,8 +62,8 @@ bool TRANSFORM::MapAngles( int* aAngle1, int* aAngle2 ) const x = t; *aAngle2 = (int) ( atan2( y, x ) * 1800.0 / M_PI + 0.5 ); - NORMALIZE_ANGLE( *aAngle1 ); - NORMALIZE_ANGLE( *aAngle2 ); + NORMALIZE_ANGLE_POS( *aAngle1 ); + NORMALIZE_ANGLE_POS( *aAngle2 ); if( *aAngle2 < *aAngle1 ) *aAngle2 += 3600; @@ -73,8 +73,8 @@ bool TRANSFORM::MapAngles( int* aAngle1, int* aAngle2 ) const *aAngle1 = (*aAngle2); *aAngle2 = Angle; - NORMALIZE_ANGLE( *aAngle1 ); - NORMALIZE_ANGLE( *aAngle2 ); + NORMALIZE_ANGLE_POS( *aAngle1 ); + NORMALIZE_ANGLE_POS( *aAngle2 ); if( *aAngle2 < *aAngle1 ) *aAngle2 += 3600; swap = true; diff --git a/include/macros.h b/include/macros.h index f2be2b1730..97dc86f984 100644 --- a/include/macros.h +++ b/include/macros.h @@ -63,15 +63,16 @@ static inline const wxChar* GetChars( const wxString& s ) #define DEG2RAD( Deg ) ( (Deg) * M_PI / 180.0 ) #define RAD2DEG( Rad ) ( (Rad) * 180.0 / M_PI ) -/* Normalize angle to be in the -360.0 .. 360.0 range or 0 .. 360.0: */ -#define NORMALIZE_ANGLE( Angle ) { while( Angle < 0 ) \ +// Normalize angle to be in the -360.0 .. 360.0: +#define NORMALIZE_ANGLE_360( Angle ) { while( Angle < -3600 ) \ Angle += 3600;\ while( Angle > 3600 ) \ Angle -= 3600;} /* Normalize angle to be in the 0.0 .. 360.0 range: */ #define NORMALIZE_ANGLE_POS( Angle ) { while( Angle < 0 ) \ - Angle += 3600;while( Angle >= 3600 ) \ + Angle += 3600;\ + while( Angle >= 3600 ) \ Angle -= 3600;} #define NEGATE_AND_NORMALIZE_ANGLE_POS( Angle ) \ { Angle = -Angle; while( Angle < 0 ) \ diff --git a/pcbnew/block.cpp b/pcbnew/block.cpp index 4b26f87bd4..cb4f947af4 100644 --- a/pcbnew/block.cpp +++ b/pcbnew/block.cpp @@ -248,6 +248,8 @@ void WinEDA_PcbFrame::HandleBlockPlace( wxDC* DC ) } DisplayToolMsg( wxEmptyString ); + DrawPanel->SetCursor( DrawPanel->m_PanelCursor = + DrawPanel->m_PanelDefaultCursor ); } @@ -263,7 +265,7 @@ void WinEDA_PcbFrame::HandleBlockPlace( wxDC* DC ) */ bool WinEDA_PcbFrame::HandleBlockEnd( wxDC* DC ) { - bool nextcmd = false; + bool nextcmd = false; // Will be set to true if a block place is needed bool cancelCmd = false; // If coming here after cancel block, clean up and exit @@ -296,8 +298,8 @@ bool WinEDA_PcbFrame::HandleBlockEnd( wxDC* DC ) // Exit if no items found if( !GetScreen()->m_BlockLocate.GetCount() ) cancelCmd = true; - else - nextcmd = true; +// else +// nextcmd = true; } } diff --git a/pcbnew/block_module_editor.cpp b/pcbnew/block_module_editor.cpp index f34f3b59d2..cf0c9b0d02 100644 --- a/pcbnew/block_module_editor.cpp +++ b/pcbnew/block_module_editor.cpp @@ -532,7 +532,7 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset ) NEGATE( pad->m_Offset.x ); NEGATE( pad->m_DeltaSize.x ); pad->m_Orient = 1800 - pad->m_Orient; - NORMALIZE_ANGLE( pad->m_Orient ); + NORMALIZE_ANGLE_POS( pad->m_Orient ); } item = module->m_Drawings; @@ -587,7 +587,7 @@ void RotateMarkedItems( MODULE* module, wxPoint offset ) ROTATE( pad->GetPosition() ); pad->m_Pos0 = pad->GetPosition(); pad->m_Orient += 900; - NORMALIZE_ANGLE( pad->m_Orient ); + NORMALIZE_ANGLE_POS( pad->m_Orient ); } item = module->m_Drawings; diff --git a/pcbnew/class_edge_mod.cpp b/pcbnew/class_edge_mod.cpp index ed0d81f615..1262f9c6d3 100644 --- a/pcbnew/class_edge_mod.cpp +++ b/pcbnew/class_edge_mod.cpp @@ -421,7 +421,7 @@ int EDGE_MODULE::ReadDescr( char* Line, FILE* File, &m_Start0.x, &m_Start0.y, &m_End0.x, &m_End0.y, &m_Angle, &m_Width, &m_Layer ); - NORMALIZE_ANGLE( m_Angle ); + NORMALIZE_ANGLE_360( m_Angle ); break; case S_SEGMENT: diff --git a/pcbnew/dialogs/dialog_graphic_item_properties.cpp b/pcbnew/dialogs/dialog_graphic_item_properties.cpp index 02056e2749..a80e128ed3 100644 --- a/pcbnew/dialogs/dialog_graphic_item_properties.cpp +++ b/pcbnew/dialogs/dialog_graphic_item_properties.cpp @@ -215,7 +215,7 @@ void DialogGraphicItemProperties::OnOkClick( wxCommandEvent& event ) { long angle; m_Angle_Ctrl->GetValue().ToLong(&angle); - NORMALIZE_ANGLE(angle); + NORMALIZE_ANGLE_360(angle); m_Item->m_Angle = angle; } diff --git a/pcbnew/edit_pcb_text.cpp b/pcbnew/edit_pcb_text.cpp index ef1549b743..f7ae815c9b 100644 --- a/pcbnew/edit_pcb_text.cpp +++ b/pcbnew/edit_pcb_text.cpp @@ -192,7 +192,7 @@ void WinEDA_PcbFrame::Rotate_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ) TextePcb->Draw( DrawPanel, DC, GR_XOR ); TextePcb->m_Orient += angle; - NORMALIZE_ANGLE( TextePcb->m_Orient ); + NORMALIZE_ANGLE_POS( TextePcb->m_Orient ); /* Redraw text in new position. */ TextePcb->Draw( DrawPanel, DC, drawmode );