From 70a61b802846a07b31cc123c0e32046bbfea8f04 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 24 Sep 2014 18:42:56 +0200 Subject: [PATCH] Pcbnew: fix Bug #1373267 (polygons in footprint outlines do not flip correctly) Minor other fixes. --- eeschema/block_libedit.cpp | 2 +- pcbnew/block.cpp | 13 +++++++-- pcbnew/block_module_editor.cpp | 2 +- pcbnew/class_edge_mod.cpp | 50 ++++++++++++++++++++++++++++++---- pcbnew/class_edge_mod.h | 3 ++ pcbnew/class_module.cpp | 26 +----------------- 6 files changed, 61 insertions(+), 35 deletions(-) diff --git a/eeschema/block_libedit.cpp b/eeschema/block_libedit.cpp index 64dc21c5f2..794ce6a52e 100644 --- a/eeschema/block_libedit.cpp +++ b/eeschema/block_libedit.cpp @@ -48,7 +48,7 @@ int LIB_EDIT_FRAME::BlockCommand( int key ) switch( key ) { default: - cmd = key & 0x255; + cmd = key & 0xFF; break; case -1: diff --git a/pcbnew/block.cpp b/pcbnew/block.cpp index 7523968c8d..fb6c7d62c2 100644 --- a/pcbnew/block.cpp +++ b/pcbnew/block.cpp @@ -185,7 +185,7 @@ int PCB_EDIT_FRAME::BlockCommand( int aKey ) switch( aKey ) { default: - cmd = aKey & 0x255; + cmd = aKey & 0xFF; break; case 0: @@ -219,6 +219,8 @@ int PCB_EDIT_FRAME::BlockCommand( int aKey ) void PCB_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) { + GetBoard()->m_Status_Pcb &= ~DO_NOT_SHOW_GENERAL_RASTNEST; + if( !m_canvas->IsMouseCaptured() ) { DisplayError( this, wxT( "Error in HandleBlockPLace : m_mouseCaptureCallback = NULL" ) ); @@ -274,7 +276,6 @@ bool PCB_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) { 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 if( GetScreen()->m_BlockLocate.GetState() == STATE_NO_BLOCK ) { @@ -369,6 +370,7 @@ bool PCB_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) if( ! nextcmd ) { + GetBoard()->m_Status_Pcb |= DO_NOT_SHOW_GENERAL_RASTNEST; GetScreen()->ClearBlockCommand(); m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, false ); @@ -562,6 +564,10 @@ static void drawMovingBlock( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& a { BASE_SCREEN* screen = aPanel->GetScreen(); + // do not show local module rastnest in block move, it is not usable. + bool tmp = g_Show_Module_Ratsnest; + g_Show_Module_Ratsnest = false; + if( aErase ) { if( screen->m_BlockLocate.GetMoveVector().x || screen->m_BlockLocate.GetMoveVector().y ) @@ -589,6 +595,8 @@ static void drawMovingBlock( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& a if( blockDrawItems ) drawPickedItems( aPanel, aDC, screen->m_BlockLocate.GetMoveVector() ); } + + g_Show_Module_Ratsnest = tmp; } @@ -795,6 +803,7 @@ void PCB_EDIT_FRAME::Block_Move() BOARD_ITEM* item = (BOARD_ITEM*) itemsList->GetPickedItem( ii ); itemsList->SetPickedItemStatus( UR_MOVED, ii ); item->Move( MoveVector ); + item->ClearFlags( IS_MOVED ); switch( item->Type() ) { diff --git a/pcbnew/block_module_editor.cpp b/pcbnew/block_module_editor.cpp index 419effc776..68cf46eb77 100644 --- a/pcbnew/block_module_editor.cpp +++ b/pcbnew/block_module_editor.cpp @@ -80,7 +80,7 @@ int FOOTPRINT_EDIT_FRAME::BlockCommand( int key ) switch( key ) { default: - cmd = key & 0x255; + cmd = key & 0xFF; break; case - 1: diff --git a/pcbnew/class_edge_mod.cpp b/pcbnew/class_edge_mod.cpp index 25359962cf..6ade01c509 100644 --- a/pcbnew/class_edge_mod.cpp +++ b/pcbnew/class_edge_mod.cpp @@ -130,7 +130,6 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode, const wxPoint& offset ) { int ux0, uy0, dx, dy, radius, StAngle, EndAngle; - int type_trace; int typeaff; LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer; @@ -154,8 +153,6 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode, PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) panel->GetParent(); - type_trace = m_Shape; - ux0 = m_Start.x - offset.x; uy0 = m_Start.y - offset.y; @@ -176,7 +173,7 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode, if( DC->LogicalToDeviceXRel( m_Width ) <= MIN_DRAW_WIDTH ) typeaff = LINE; - switch( type_trace ) + switch( m_Shape ) { case S_SEGMENT: if( typeaff == LINE ) @@ -245,10 +242,9 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode, break; case S_POLYGON: - + { // We must compute true coordinates from m_PolyPoints // which are relative to module position, orientation 0 - std::vector points = m_PolyPoints; for( unsigned ii = 0; ii < points.size(); ii++ ) @@ -260,6 +256,10 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode, } GRPoly( panel->GetClipBox(), DC, points.size(), &points[0], true, m_Width, color, color ); + } + break; + + default: break; } } @@ -312,3 +312,41 @@ EDA_ITEM* EDGE_MODULE::Clone() const return new EDGE_MODULE( *this ); } + + +void EDGE_MODULE::Flip(const wxPoint& aCentre ) +{ + wxPoint pt; + + switch( GetShape() ) + { + case S_ARC: + SetAngle( -GetAngle() ); + //Fall through + default: + case S_SEGMENT: + pt = GetStart(); + pt.y -= aCentre.y; + pt.y = -pt.y; + pt.y += aCentre.y; + SetStart( pt ); + + pt = GetEnd(); + pt.y -= aCentre.y; + pt.y = -pt.y; + pt.y += aCentre.y; + SetEnd( pt ); + + NEGATE( m_Start0.y ); + NEGATE( m_End0.y ); + break; + + case S_POLYGON: + // polygon corners coordinates are always relative to the + // footprint position, orientation 0 + for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ ) + NEGATE( m_PolyPoints[ii].y ); + } + + SetLayer( FlipLayer( GetLayer() ) ); +} diff --git a/pcbnew/class_edge_mod.h b/pcbnew/class_edge_mod.h index e7b945a9af..65f83ee994 100644 --- a/pcbnew/class_edge_mod.h +++ b/pcbnew/class_edge_mod.h @@ -68,6 +68,9 @@ public: SetLocalCoord(); } + /// Flip entity relative to aCentre + void Flip( const wxPoint& aCentre ); + void SetStart0( const wxPoint& aPoint ) { m_Start0 = aPoint; } const wxPoint& GetStart0() const { return m_Start0; } diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 2f864ce40b..6c9d860b9a 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -947,31 +947,7 @@ void MODULE::Flip( const wxPoint& aCentre ) switch( item->Type() ) { case PCB_MODULE_EDGE_T: - { - EDGE_MODULE* em = (EDGE_MODULE*) item; - - wxPoint s = em->GetStart(); - s.y -= m_Pos.y; - s.y = -s.y; - s.y += m_Pos.y; - em->SetStart( s ); - - wxPoint e = em->GetEnd(); - e.y -= m_Pos.y; - e.y = -e.y; - e.y += m_Pos.y; - em->SetEnd( e ); - - NEGATE( em->m_Start0.y ); - NEGATE( em->m_End0.y ); - - if( em->GetShape() == S_ARC ) - { - em->SetAngle( -em->GetAngle() ); - } - - em->SetLayer( FlipLayer( em->GetLayer() ) ); - } + ( (EDGE_MODULE*) item )->Flip( m_Pos ); break; case PCB_MODULE_TEXT_T: