diff --git a/common/base_screen.cpp b/common/base_screen.cpp index bfdbf16898..328a6e804b 100644 --- a/common/base_screen.cpp +++ b/common/base_screen.cpp @@ -13,8 +13,6 @@ #include "id.h" -BASE_SCREEN* ActiveScreen = NULL; - #define CURSOR_SIZE 12 /* size of the cross cursor. */ diff --git a/common/drawpanel.cpp b/common/drawpanel.cpp index 88f57d9fb7..f94854e12f 100644 --- a/common/drawpanel.cpp +++ b/common/drawpanel.cpp @@ -285,22 +285,19 @@ wxPoint EDA_DRAW_PANEL::GetScreenCenterLogicalPosition() */ void EDA_DRAW_PANEL::MouseToCursorSchema() { - wxPoint Mouse = CursorScreenPosition(); - - MouseTo( Mouse ); + MoveCursor( GetScreen()->m_Curseur ); } -/** Move the mouse cursor to the position "Mouse" - * @param Mouse = mouse cursor position, in pixels units - */ -void EDA_DRAW_PANEL::MouseTo( const wxPoint& Mouse ) +void EDA_DRAW_PANEL::MoveCursor( const wxPoint& aPosition ) { int x, y, xPpu, yPpu; wxPoint screenPos, drawingPos; wxRect clientRect( wxPoint( 0, 0 ), GetClientSize() ); - CalcScrolledPosition( Mouse.x, Mouse.y, &screenPos.x, &screenPos.y ); + INSTALL_UNBUFFERED_DC( dc, this ); + screenPos.x = dc.LogicalToDeviceX( aPosition.x ); + screenPos.y = dc.LogicalToDeviceY( aPosition.y ); // Scroll if the requested mouse position cursor is outside the drawing area. if( !clientRect.Contains( screenPos ) ) @@ -309,7 +306,7 @@ void EDA_DRAW_PANEL::MouseTo( const wxPoint& Mouse ) GetScrollPixelsPerUnit( &xPpu, &yPpu ); CalcUnscrolledPosition( screenPos.x, screenPos.y, &drawingPos.x, &drawingPos.y ); - wxLogDebug( wxT( "MouseTo() initial screen position(%d, %d) " ) \ + wxLogDebug( wxT( "MoveCursor() initial screen position(%d, %d) " ) \ wxT( "rectangle(%d, %d, %d, %d) view(%d, %d)" ), screenPos.x, screenPos.y, clientRect.x, clientRect.y, clientRect.width, clientRect.height, x, y ); @@ -326,7 +323,7 @@ void EDA_DRAW_PANEL::MouseTo( const wxPoint& Mouse ) Scroll( x, y ); CalcScrolledPosition( drawingPos.x, drawingPos.y, &screenPos.x, &screenPos.y ); - wxLogDebug( wxT( "MouseTo() scrolled screen position(%d, %d) view(%d, %d)" ), + wxLogDebug( wxT( "MoveCursor() scrolled screen position(%d, %d) view(%d, %d)" ), screenPos.x, screenPos.y, x, y ); } @@ -1007,7 +1004,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) } /* Calling the general function on mouse changes (and pseudo key commands) */ - m_Parent->GeneralControle( &DC, pos ); + m_Parent->GeneralControle( &DC, event.GetLogicalPosition( DC ) ); /*******************************/ /* Control of block commands : */ @@ -1221,10 +1218,11 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event ) } /* Some key commands use the current mouse position: refresh it */ - pos = CalcUnscrolledPosition( wxGetMousePosition() - GetScreenPosition() ); + pos = wxGetMousePosition() - GetScreenPosition(); // Compute the cursor position in drawing units. Also known as logical units to wxDC. - Screen->m_MousePosition = CursorRealPosition( pos ); + pos = wxPoint( DC.DeviceToLogicalX( pos.x ), DC.DeviceToLogicalY( pos.y ) ); + Screen->m_MousePosition = pos; m_Parent->GeneralControle( &DC, pos ); diff --git a/common/gr_basic.cpp b/common/gr_basic.cpp index d0eb6e2726..39ab412734 100644 --- a/common/gr_basic.cpp +++ b/common/gr_basic.cpp @@ -70,8 +70,6 @@ static void GRSRect( EDA_Rect* aClipBox, wxDC* aDC, int x1, int y1, /**/ -extern BASE_SCREEN* ActiveScreen; - static int GRLastMoveToX, GRLastMoveToY; static bool s_ForceBlackPen; /* if true: draws in black instead of * color for printing. */ diff --git a/common/zoom.cpp b/common/zoom.cpp index 1a1a307413..ae7f695aa5 100644 --- a/common/zoom.cpp +++ b/common/zoom.cpp @@ -52,17 +52,18 @@ void EDA_DRAW_FRAME::RedrawScreen( bool aWarpPointer ) void EDA_DRAW_FRAME::PutOnGrid( wxPoint* aCoord , wxRealPoint* aGridSize ) { wxRealPoint grid_size; + if( aGridSize ) grid_size = *aGridSize; else - grid_size = GetBaseScreen()->GetGridSize(); + grid_size = GetBaseScreen()->GetGridSize(); const wxPoint& grid_origin = GetBaseScreen()->GetGridOrigin(); - double offset = fmod(grid_origin.x, grid_size.x); + double offset = fmod( grid_origin.x, grid_size.x ); int tmp = wxRound( (aCoord->x - offset) / grid_size.x ); aCoord->x = wxRound( tmp * grid_size.x + offset ); - offset = fmod(grid_origin.y, grid_size.y); + offset = fmod( grid_origin.y, grid_size.y ); tmp = wxRound( (aCoord->y - offset) / grid_size.y ); aCoord->y = wxRound ( tmp * grid_size.y + offset ); } diff --git a/cvpcb/class_DisplayFootprintsFrame.cpp b/cvpcb/class_DisplayFootprintsFrame.cpp index cd53f6cadd..df5445d703 100644 --- a/cvpcb/class_DisplayFootprintsFrame.cpp +++ b/cvpcb/class_DisplayFootprintsFrame.cpp @@ -390,27 +390,19 @@ void DISPLAY_FOOTPRINTS_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) SetToolbars(); } -void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* DC, wxPoint Mouse ) +void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* aDC, wxPoint aPosition ) { - wxRealPoint delta; - int flagcurseur = 0; - wxPoint curpos, oldpos; - double scalar = GetScreen()->GetScalingFactor(); + wxRealPoint gridSize; + int flagcurseur = 0; + wxPoint oldpos; + wxPoint pos = aPosition; + wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetEventObject( this ); - curpos = DrawPanel->CursorRealPosition( Mouse ); + PutOnGrid( &pos ); oldpos = GetScreen()->m_Curseur; - - delta = GetScreen()->GetGridSize(); - - delta.x *= scalar; - delta.y *= scalar; - - if( delta.x <= 0 ) - delta.x = 1; - if( delta.y <= 0 ) - delta.y = 1; + gridSize = GetScreen()->GetGridSize(); switch( g_KeyPressed ) { @@ -418,14 +410,14 @@ void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* DC, wxPoint Mouse ) cmd.SetId( ID_POPUP_ZOOM_IN ); GetEventHandler()->ProcessEvent( cmd ); flagcurseur = 2; - curpos = GetScreen()->m_Curseur; + pos = GetScreen()->m_Curseur; break; case WXK_F2: cmd.SetId( ID_POPUP_ZOOM_OUT ); GetEventHandler()->ProcessEvent( cmd ); flagcurseur = 2; - curpos = GetScreen()->m_Curseur; + pos = GetScreen()->m_Curseur; break; case WXK_F3: @@ -438,14 +430,14 @@ void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* DC, wxPoint Mouse ) cmd.SetId( ID_POPUP_ZOOM_CENTER ); GetEventHandler()->ProcessEvent( cmd ); flagcurseur = 2; - curpos = GetScreen()->m_Curseur; + pos = GetScreen()->m_Curseur; break; case WXK_HOME: cmd.SetId( ID_ZOOM_PAGE ); GetEventHandler()->ProcessEvent( cmd ); flagcurseur = 2; - curpos = GetScreen()->m_Curseur; + pos = GetScreen()->m_Curseur; break; case ' ': @@ -454,32 +446,30 @@ void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* DC, wxPoint Mouse ) case WXK_NUMPAD8: /* cursor moved up */ case WXK_UP: - Mouse.y -= wxRound(delta.y); - DrawPanel->MouseTo( Mouse ); + pos.y -= wxRound( gridSize.y ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD2: /* cursor moved down */ case WXK_DOWN: - Mouse.y += wxRound(delta.y); - DrawPanel->MouseTo( Mouse ); + pos.y += wxRound( gridSize.y ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD4: /* cursor moved left */ case WXK_LEFT: - Mouse.x -= wxRound(delta.x); - DrawPanel->MouseTo( Mouse ); + pos.x -= wxRound( gridSize.x ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD6: /* cursor moved right */ case WXK_RIGHT: - Mouse.x += wxRound(delta.x); - DrawPanel->MouseTo( Mouse ); + pos.x += wxRound( gridSize.x ); + DrawPanel->MoveCursor( pos ); break; } - GetScreen()->m_Curseur = curpos; - /* Put cursor on grid */ - PutOnGrid( &GetScreen()->m_Curseur ); + GetScreen()->m_Curseur = pos; if( GetScreen()->IsRefreshReq() ) { @@ -491,17 +481,16 @@ void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* DC, wxPoint Mouse ) { if( flagcurseur != 2 ) { - curpos = GetScreen()->m_Curseur; + pos = GetScreen()->m_Curseur; GetScreen()->m_Curseur = oldpos; - DrawPanel->CursorOff( DC ); - - GetScreen()->m_Curseur = curpos; - DrawPanel->CursorOn( DC ); + DrawPanel->CursorOff( aDC ); + GetScreen()->m_Curseur = pos; + DrawPanel->CursorOn( aDC ); } if( DrawPanel->ManageCurseur ) { - DrawPanel->ManageCurseur( DrawPanel, DC, 0 ); + DrawPanel->ManageCurseur( DrawPanel, aDC, 0 ); } } diff --git a/cvpcb/setvisu.cpp b/cvpcb/setvisu.cpp index ea50a495ed..f4da07a70d 100644 --- a/cvpcb/setvisu.cpp +++ b/cvpcb/setvisu.cpp @@ -91,12 +91,11 @@ void DISPLAY_FOOTPRINTS_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) if( !GetBoard() ) return; - ActiveScreen = (PCB_SCREEN*) GetScreen(); - DrawPanel->DrawBackGround( DC ); GetBoard()->Draw( DrawPanel, DC, GR_COPY ); MODULE* Module = GetBoard()->m_Modules; + if ( Module ) Module->DisplayInfo( this ); diff --git a/eeschema/controle.cpp b/eeschema/controle.cpp index 4b2d771219..6757c8dc9f 100644 --- a/eeschema/controle.cpp +++ b/eeschema/controle.cpp @@ -48,11 +48,12 @@ SCH_ITEM* SCH_EDIT_FRAME::SchematicGeneralLocateAndDisplay( bool IncludePin ) SCH_COMPONENT* LibItem = NULL; DrawStruct = SchematicGeneralLocateAndDisplay( mouse_position, IncludePin ); + if( !DrawStruct && ( mouse_position != GetScreen()->m_Curseur) ) { - DrawStruct = SchematicGeneralLocateAndDisplay( GetScreen()->m_Curseur, - IncludePin ); + DrawStruct = SchematicGeneralLocateAndDisplay( GetScreen()->m_Curseur, IncludePin ); } + if( !DrawStruct ) return NULL; @@ -235,26 +236,17 @@ SCH_ITEM* SCH_EDIT_FRAME::SchematicGeneralLocateAndDisplay( const wxPoint& refpo } -void SCH_EDIT_FRAME::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) +void SCH_EDIT_FRAME::GeneralControle( wxDC* aDC, wxPoint aPosition ) { - wxRealPoint delta; + wxRealPoint gridSize; SCH_SCREEN* screen = GetScreen(); - wxPoint curpos, oldpos; + wxPoint oldpos; int hotkey = 0; - double scalar = screen->GetScalingFactor(); + wxPoint pos = aPosition; - curpos = screen->m_MousePosition; + PutOnGrid( &pos ); oldpos = screen->m_Curseur; - - delta = screen->GetGridSize(); - - delta.x *= scalar; - delta.y *= scalar; - - if( delta.x <= 0 ) - delta.x = 1; - if( delta.y <= 0 ) - delta.y = 1; + gridSize = screen->GetGridSize(); switch( g_KeyPressed ) { @@ -263,26 +255,26 @@ void SCH_EDIT_FRAME::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) case WXK_NUMPAD8: case WXK_UP: - MousePositionInPixels.y -= wxRound( delta.y ); - DrawPanel->MouseTo( MousePositionInPixels ); + pos.y -= wxRound( gridSize.y ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD2: case WXK_DOWN: - MousePositionInPixels.y += wxRound( delta.y ); - DrawPanel->MouseTo( MousePositionInPixels ); + pos.y += wxRound( gridSize.y ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD4: case WXK_LEFT: - MousePositionInPixels.x -= wxRound( delta.x ); - DrawPanel->MouseTo( MousePositionInPixels ); + pos.x -= wxRound( gridSize.x ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD6: case WXK_RIGHT: - MousePositionInPixels.x += wxRound( delta.x ); - DrawPanel->MouseTo( MousePositionInPixels ); + pos.x += wxRound( gridSize.x ); + DrawPanel->MoveCursor( pos ); break; default: @@ -290,11 +282,8 @@ void SCH_EDIT_FRAME::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) break; } - /* Update cursor position. */ - screen->m_Curseur = curpos; - - /* Snap cursor to grid. */ - PutOnGrid( &(screen->m_Curseur) ); + // Update cursor position. + screen->m_Curseur = pos; if( screen->IsRefreshReq() ) { @@ -304,24 +293,24 @@ void SCH_EDIT_FRAME::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) if( oldpos != screen->m_Curseur ) { - curpos = screen->m_Curseur; + pos = screen->m_Curseur; screen->m_Curseur = oldpos; - DrawPanel->CursorOff( DC ); - screen->m_Curseur = curpos; - DrawPanel->CursorOn( DC ); + DrawPanel->CursorOff( aDC ); + screen->m_Curseur = pos; + DrawPanel->CursorOn( aDC ); if( DrawPanel->ManageCurseur ) { - DrawPanel->ManageCurseur( DrawPanel, DC, TRUE ); + DrawPanel->ManageCurseur( DrawPanel, aDC, TRUE ); } } if( hotkey ) { if( screen->GetCurItem() && screen->GetCurItem()->m_Flags ) - OnHotKey( DC, hotkey, screen->GetCurItem() ); + OnHotKey( aDC, hotkey, screen->GetCurItem() ); else - OnHotKey( DC, hotkey, NULL ); + OnHotKey( aDC, hotkey, NULL ); } UpdateStatusBar(); /* Display cursor coordinates info */ @@ -329,26 +318,17 @@ void SCH_EDIT_FRAME::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) } -void LIB_EDIT_FRAME::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) +void LIB_EDIT_FRAME::GeneralControle( wxDC* aDC, wxPoint aPosition ) { - wxRealPoint delta; + wxRealPoint gridSize; SCH_SCREEN* screen = GetScreen(); - wxPoint curpos, oldpos; + wxPoint oldpos; int hotkey = 0; - double scalar = screen->GetScalingFactor(); + wxPoint pos = aPosition; - curpos = screen->m_MousePosition; + PutOnGrid( &pos ); oldpos = screen->m_Curseur; - - delta = screen->GetGridSize(); - - delta.x *= scalar; - delta.y *= scalar; - - if( delta.x <= 0 ) - delta.x = 1; - if( delta.y <= 0 ) - delta.y = 1; + gridSize = screen->GetGridSize(); switch( g_KeyPressed ) { @@ -357,26 +337,26 @@ void LIB_EDIT_FRAME::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) case WXK_NUMPAD8: case WXK_UP: - MousePositionInPixels.y -= wxRound( delta.y ); - DrawPanel->MouseTo( MousePositionInPixels ); + pos.y -= wxRound( gridSize.y ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD2: case WXK_DOWN: - MousePositionInPixels.y += wxRound( delta.y ); - DrawPanel->MouseTo( MousePositionInPixels ); + pos.y += wxRound( gridSize.y ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD4: case WXK_LEFT: - MousePositionInPixels.x -= wxRound( delta.x ); - DrawPanel->MouseTo( MousePositionInPixels ); + pos.x -= wxRound( gridSize.x ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD6: case WXK_RIGHT: - MousePositionInPixels.x += wxRound( delta.x ); - DrawPanel->MouseTo( MousePositionInPixels ); + pos.x += wxRound( gridSize.x ); + DrawPanel->MoveCursor( pos ); break; default: @@ -384,11 +364,8 @@ void LIB_EDIT_FRAME::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) break; } - /* Update the cursor position. */ - screen->m_Curseur = curpos; - - /* Snap cursor to grid. */ - PutOnGrid( &(screen->m_Curseur) ); + // Update the cursor position. + screen->m_Curseur = pos; if( screen->IsRefreshReq() ) { @@ -398,50 +375,41 @@ void LIB_EDIT_FRAME::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) if( oldpos != screen->m_Curseur ) { - curpos = screen->m_Curseur; + pos = screen->m_Curseur; screen->m_Curseur = oldpos; - DrawPanel->CursorOff( DC ); - screen->m_Curseur = curpos; - DrawPanel->CursorOn( DC ); + DrawPanel->CursorOff( aDC ); + screen->m_Curseur = pos; + DrawPanel->CursorOn( aDC ); if( DrawPanel->ManageCurseur ) { - DrawPanel->ManageCurseur( DrawPanel, DC, TRUE ); + DrawPanel->ManageCurseur( DrawPanel, aDC, TRUE ); } } if( hotkey ) { if( screen->GetCurItem() && screen->GetCurItem()->m_Flags ) - OnHotKey( DC, hotkey, screen->GetCurItem() ); + OnHotKey( aDC, hotkey, screen->GetCurItem() ); else - OnHotKey( DC, hotkey, NULL ); + OnHotKey( aDC, hotkey, NULL ); } UpdateStatusBar(); } -void LIB_VIEW_FRAME::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) +void LIB_VIEW_FRAME::GeneralControle( wxDC* aDC, wxPoint aPosition ) { - wxRealPoint delta; + wxRealPoint gridSize; SCH_SCREEN* screen = GetScreen(); - wxPoint curpos, oldpos; + wxPoint oldpos; int hotkey = 0; - double scalar = screen->GetScalingFactor(); + wxPoint pos = aPosition; - curpos = screen->m_MousePosition; + PutOnGrid( &pos ); oldpos = screen->m_Curseur; - - delta = screen->GetGridSize(); - - delta.x *= scalar; - delta.y *= scalar; - - if( delta.x <= 0 ) - delta.x = 1; - if( delta.y <= 0 ) - delta.y = 1; + gridSize = screen->GetGridSize(); switch( g_KeyPressed ) { @@ -450,26 +418,26 @@ void LIB_VIEW_FRAME::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) case WXK_NUMPAD8: case WXK_UP: - MousePositionInPixels.y -= wxRound( delta.y ); - DrawPanel->MouseTo( MousePositionInPixels ); + pos.y -= wxRound( gridSize.y ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD2: case WXK_DOWN: - MousePositionInPixels.y += wxRound( delta.y ); - DrawPanel->MouseTo( MousePositionInPixels ); + pos.y += wxRound( gridSize.y ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD4: case WXK_LEFT: - MousePositionInPixels.x -= wxRound( delta.x ); - DrawPanel->MouseTo( MousePositionInPixels ); + pos.x -= wxRound( gridSize.x ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD6: case WXK_RIGHT: - MousePositionInPixels.x += wxRound( delta.x ); - DrawPanel->MouseTo( MousePositionInPixels ); + pos.x += wxRound( gridSize.x ); + DrawPanel->MoveCursor( pos ); break; default: @@ -477,11 +445,8 @@ void LIB_VIEW_FRAME::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) break; } - /* Update cursor position. */ - screen->m_Curseur = curpos; - - /* Snap cursor to grid. */ - PutOnGrid( &screen->m_Curseur ); + // Update cursor position. + screen->m_Curseur = pos; if( screen->IsRefreshReq() ) { @@ -491,24 +456,24 @@ void LIB_VIEW_FRAME::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) if( oldpos != screen->m_Curseur ) { - curpos = screen->m_Curseur; + pos = screen->m_Curseur; screen->m_Curseur = oldpos; - DrawPanel->CursorOff( DC ); - screen->m_Curseur = curpos; - DrawPanel->CursorOn( DC ); + DrawPanel->CursorOff( aDC ); + screen->m_Curseur = pos; + DrawPanel->CursorOn( aDC ); if( DrawPanel->ManageCurseur ) { - DrawPanel->ManageCurseur( DrawPanel, DC, TRUE ); + DrawPanel->ManageCurseur( DrawPanel, aDC, TRUE ); } } if( hotkey ) { if( screen->GetCurItem() && screen->GetCurItem()->m_Flags ) - OnHotKey( DC, hotkey, screen->GetCurItem() ); + OnHotKey( aDC, hotkey, screen->GetCurItem() ); else - OnHotKey( DC, hotkey, NULL ); + OnHotKey( aDC, hotkey, NULL ); } UpdateStatusBar(); diff --git a/eeschema/find.cpp b/eeschema/find.cpp index ea23981bcd..04fce2db39 100644 --- a/eeschema/find.cpp +++ b/eeschema/find.cpp @@ -222,7 +222,7 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& component_refere DrawPanel->CursorOff( &dc ); if( mouseWarp ) - DrawPanel->MouseTo( curpos ); + DrawPanel->MoveCursor( curpos ); EXCHG( old_cursor_position, sheet->LastScreen()->m_Curseur ); diff --git a/gerbview/controle.cpp b/gerbview/controle.cpp index 99b4625838..297442253a 100644 --- a/gerbview/controle.cpp +++ b/gerbview/controle.cpp @@ -13,11 +13,14 @@ GERBER_DRAW_ITEM* WinEDA_GerberFrame::GerberGeneralLocateAndDisplay() } -void WinEDA_GerberFrame::GeneralControle( wxDC* DC, wxPoint Mouse ) +void WinEDA_GerberFrame::GeneralControle( wxDC* aDC, wxPoint aPosition ) { - wxRealPoint delta; - wxPoint curpos, oldpos; - int hotkey = 0; + wxRealPoint gridSize; + wxPoint oldpos; + int hotkey = 0; + wxPoint pos = aPosition; + + PutOnGrid( &pos ); if( GetScreen()->IsRefreshReq() ) { @@ -34,45 +37,33 @@ void WinEDA_GerberFrame::GeneralControle( wxDC* DC, wxPoint Mouse ) return; } - double scalar = GetScreen()->GetScalingFactor(); - - curpos = DrawPanel->CursorRealPosition( Mouse ); oldpos = GetScreen()->m_Curseur; - - delta = GetScreen()->GetGridSize(); - - delta.x *= scalar; - delta.y *= scalar; - - if( delta.x == 0 ) - delta.x = 1; - if( delta.y == 0 ) - delta.y = 1; + gridSize = GetScreen()->GetGridSize(); switch( g_KeyPressed ) { case WXK_NUMPAD8: case WXK_UP: - Mouse.y -= wxRound(delta.y); - DrawPanel->MouseTo( Mouse ); + pos.y -= wxRound( gridSize.y ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD2: case WXK_DOWN: - Mouse.y += wxRound(delta.y); - DrawPanel->MouseTo( Mouse ); + pos.y += wxRound( gridSize.y ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD4: case WXK_LEFT: - Mouse.x -= wxRound(delta.x); - DrawPanel->MouseTo( Mouse ); + pos.x -= wxRound( gridSize.x ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD6: case WXK_RIGHT: - Mouse.x += wxRound(delta.x); - DrawPanel->MouseTo( Mouse ); + pos.x += wxRound( gridSize.x ); + DrawPanel->MoveCursor( pos ); break; default: @@ -80,28 +71,25 @@ void WinEDA_GerberFrame::GeneralControle( wxDC* DC, wxPoint Mouse ) break; } - GetScreen()->m_Curseur = curpos; - - PutOnGrid( &GetScreen()->m_Curseur ); + GetScreen()->m_Curseur = pos; if( oldpos != GetScreen()->m_Curseur ) { - curpos = GetScreen()->m_Curseur; + pos = GetScreen()->m_Curseur; GetScreen()->m_Curseur = oldpos; - DrawPanel->CursorOff( DC ); - - GetScreen()->m_Curseur = curpos; - DrawPanel->CursorOn( DC ); + DrawPanel->CursorOff( aDC ); + GetScreen()->m_Curseur = pos; + DrawPanel->CursorOn( aDC ); if( DrawPanel->ManageCurseur ) { - DrawPanel->ManageCurseur( DrawPanel, DC, TRUE ); + DrawPanel->ManageCurseur( DrawPanel, aDC, TRUE ); } } if( hotkey ) { - OnHotKey( DC, hotkey, NULL ); + OnHotKey( aDC, hotkey, NULL ); } if( GetScreen()->IsRefreshReq() ) diff --git a/include/class_drawpanel.h b/include/class_drawpanel.h index 10d54d52b2..85b0b7653a 100644 --- a/include/class_drawpanel.h +++ b/include/class_drawpanel.h @@ -229,7 +229,13 @@ public: wxPoint GetScreenCenterLogicalPosition(); void MouseToCursorSchema(); - void MouseTo( const wxPoint& Mouse ); + + /** + * Function MoveCursor + * moves the mouse pointer to \a aPosition in logical (drawing) units. + * @param aPosition The position in logical units to move the cursor. + */ + void MoveCursor( const wxPoint& aPosition ); /* Cursor functions */ /** diff --git a/include/common.h b/include/common.h index d4cb0fc4d5..43c8835318 100644 --- a/include/common.h +++ b/include/common.h @@ -190,9 +190,6 @@ extern UserUnitType g_UserUnit; ///< display units /* Draw color for moving objects: */ extern int g_GhostColor; -/* Current used screen: (not used in eeshema)*/ -extern BASE_SCREEN* ActiveScreen; - /* COMMON.CPP */ diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index d994b86da2..2e30c548c4 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -160,7 +160,7 @@ public: /** * Function PrintPage , virtual * used to print a page - * Print the page pointed by ActiveScreen, set by the calling print function + * Print the page pointed by the current screen, set by the calling print function * @param aDC = wxDC given by the calling print function * @param aPrintMaskLayer = a 32 bits mask: bit n = 1 -> layer n is printed * @param aPrintMirrorMode = true to plot mirrored diff --git a/include/wxstruct.h b/include/wxstruct.h index 2f810174d3..aa461a1a78 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -365,7 +365,18 @@ public: virtual void OnSelectGrid( wxCommandEvent& event ); virtual void OnSelectZoom( wxCommandEvent& event ); - virtual void GeneralControle( wxDC* DC, wxPoint Mouse ) { /* dummy */ } + /** + * Function GeneralControle + * performs application specific control using \a aDC at \a aPosition in logical units. + *
+ * Override this function for application specific control. This function gets + * called on every mouse and key event. + *
+ * @param aDC A device context. + * @param aPosition The cursor position in logical (drawing) units. + */ + virtual void GeneralControle( wxDC* aDC, wxPoint aPosition ) { /* dummy */ } + virtual void OnSize( wxSizeEvent& event ); void OnEraseBackground( wxEraseEvent& SizeEvent ); @@ -515,7 +526,7 @@ public: /** Virtual function PrintPage * used to print a page - * Print the page pointed by ActiveScreen, set by the calling print function + * Print the page pointed by current screen, set by the calling print function * @param aDC = wxDC given by the calling print function * @param aPrintMask = not used here * @param aPrintMirrorMode = not used here (Set when printing in mirror mode) diff --git a/pcbnew/controle.cpp b/pcbnew/controle.cpp index 78cfca2ee4..da4d4bffb8 100644 --- a/pcbnew/controle.cpp +++ b/pcbnew/controle.cpp @@ -18,15 +18,14 @@ extern bool Magnetize( BOARD* m_Pcb, WinEDA_PcbFrame* frame, int aCurrentTool, wxSize grid, wxPoint on_grid, wxPoint* curpos ); -/*************************************************************************************/ -static BOARD_ITEM* AllAreModulesAndReturnSmallestIfSo( GENERAL_COLLECTOR* aCollector ) -/*************************************************************************************/ + /** * Function AllAreModulesAndReturnSmallestIfSo * tests that all items in the collection are MODULEs and if so, returns the * smallest MODULE. * @return BOARD_ITEM* - The smallest or NULL. */ +static BOARD_ITEM* AllAreModulesAndReturnSmallestIfSo( GENERAL_COLLECTOR* aCollector ) { int count = aCollector->GetCount(); @@ -61,9 +60,7 @@ static BOARD_ITEM* AllAreModulesAndReturnSmallestIfSo( GENERAL_COLLECTOR* aColle } -/****************************************************************************/ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode ) -/****************************************************************************/ { BOARD_ITEM* item; @@ -133,6 +130,7 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode ) for( int ii = 0; ii < m_Collector->GetCount(); ii++ ) { item = (*m_Collector)[ii]; + if( item->Type() != TYPE_ZONE ) continue; @@ -151,7 +149,9 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode ) item = (*m_Collector)[0]; SetCurItem( item ); } - // If the count is 2, and first item is a pad or moduletext, and the 2nd item is its parent module: + + // If the count is 2, and first item is a pad or moduletext, and the 2nd item is its + // parent module: else if( m_Collector->GetCount() == 2 && ( (*m_Collector)[0]->Type() == TYPE_PAD || (*m_Collector)[0]->Type() == TYPE_TEXTE_MODULE ) @@ -173,12 +173,14 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode ) /* Give a title to the selection menu. This is also a cancel menu item */ wxMenuItem * item_title = new wxMenuItem(&itemMenu, -1, _( "Selection Clarification" ) ); + #ifdef __WINDOWS__ wxFont bold_font(*wxNORMAL_FONT); bold_font.SetWeight(wxFONTWEIGHT_BOLD); bold_font.SetStyle( wxFONTSTYLE_ITALIC); item_title->SetFont(bold_font); #endif + itemMenu.Append(item_title); itemMenu.AppendSeparator(); @@ -197,9 +199,11 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode ) ADD_MENUITEM( &itemMenu, ID_POPUP_PCB_ITEM_SELECTION_START + i, text, xpm ); } - /* @todo: rather than assignment to TRUE, these should be increment and decrement operators throughout _everywhere_. + /* @todo: rather than assignment to TRUE, these should be increment and decrement + * operators throughout _everywhere_. * That way we can handle nesting. - * But I tried that and found there cases where the assignment to TRUE (converted to a m_IgnoreMouseEvents++ ) + * But I tried that and found there cases where the assignment to TRUE (converted to + * a m_IgnoreMouseEvents++ ) * was not balanced with the -- (now m_IgnoreMouseEvents=FALSE), so I had to revert. * Somebody should track down these and make them balanced. * DrawPanel->m_IgnoreMouseEvents = TRUE; @@ -222,15 +226,14 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode ) } -/****************************************************************/ -void WinEDA_PcbFrame::GeneralControle( wxDC* DC, wxPoint Mouse ) -/*****************************************************************/ +void WinEDA_PcbFrame::GeneralControle( wxDC* aDC, wxPoint aPosition ) { - wxRealPoint delta; - wxPoint curpos, oldpos; - int hotkey = 0; + wxRealPoint gridSize; + wxPoint oldpos; + int hotkey = 0; + wxPoint pos = aPosition; - ActiveScreen = GetScreen(); + PutOnGrid( &pos ); // Save the board after the time out : int CurrentTime = time( NULL ); @@ -245,7 +248,7 @@ void WinEDA_PcbFrame::GeneralControle( wxDC* DC, wxPoint Mouse ) { wxString tmpFileName = GetScreen()->GetFileName(); wxFileName fn = wxFileName( wxEmptyString, g_SaveFileName, PcbFileExtension ); - bool flgmodify = GetScreen()->IsModify(); + bool flgmodify = GetScreen()->IsModify(); SavePcbFile( fn.GetFullPath() ); @@ -254,50 +257,39 @@ void WinEDA_PcbFrame::GeneralControle( wxDC* DC, wxPoint Mouse ) OnModify(); GetScreen()->SetSave(); // Set the flags m_FlagSave cleared by SetModify() } + GetScreen()->SetFileName( tmpFileName ); SetTitle( GetScreen()->GetFileName() ); } - double scalar = GetScreen()->GetScalingFactor(); - - curpos = DrawPanel->CursorRealPosition( Mouse ); oldpos = GetScreen()->m_Curseur; - delta = GetScreen()->GetGridSize(); - - delta.x *= scalar; - delta.y *= scalar; - - if( delta.x <= 0 ) - delta.x = 1; - - if( delta.y <= 0 ) - delta.y = 1; + gridSize = GetScreen()->GetGridSize(); switch( g_KeyPressed ) { case WXK_NUMPAD8: /* Deplacement curseur vers le haut */ case WXK_UP: - Mouse.y -= wxRound(delta.y); - DrawPanel->MouseTo( Mouse ); + pos.y -= wxRound( gridSize.y ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD2: /* Deplacement curseur vers le bas */ case WXK_DOWN: - Mouse.y += wxRound(delta.y); - DrawPanel->MouseTo( Mouse ); + pos.y += wxRound( gridSize.y ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD4: /* Deplacement curseur vers la gauche */ case WXK_LEFT: - Mouse.x -= wxRound(delta.x); - DrawPanel->MouseTo( Mouse ); + pos.x -= wxRound( gridSize.x ); + DrawPanel->MoveCursor( pos ); break; case WXK_NUMPAD6: /* Deplacement curseur vers la droite */ case WXK_RIGHT: - Mouse.x += wxRound(delta.x); - DrawPanel->MouseTo( Mouse ); + pos.x += wxRound( gridSize.x ); + DrawPanel->MoveCursor( pos ); break; default: @@ -305,14 +297,14 @@ void WinEDA_PcbFrame::GeneralControle( wxDC* DC, wxPoint Mouse ) break; } - /* Put cursor in new position, according to the zoom keys (if any) */ - GetScreen()->m_Curseur = curpos; + // Put cursor in new position, according to the zoom keys (if any). + GetScreen()->m_Curseur = pos; - /* Put cursor on grid or a pad centre if requested - * But if the tool DELETE is active the cursor is left off grid - * this is better to reach items to delete off grid + /* Put cursor on grid or a pad centre if requested. If the tool DELETE is active the + * cursor is left off grid this is better to reach items to delete off grid, */ bool keep_on_grid = TRUE; + if( m_ID_current_state == ID_PCB_DELETE_ITEM_BUTT ) keep_on_grid = FALSE; @@ -327,16 +319,16 @@ void WinEDA_PcbFrame::GeneralControle( wxDC* DC, wxPoint Mouse ) if( keep_on_grid ) { - wxPoint on_grid = curpos; + wxPoint on_grid = pos; PutOnGrid( &on_grid ); wxSize grid; grid.x = (int) GetScreen()->GetGridSize().x; grid.y = (int) GetScreen()->GetGridSize().y; - if( Magnetize(m_Pcb, (WinEDA_PcbFrame *) this, m_ID_current_state, - grid, on_grid, &curpos) ) + + if( Magnetize( m_Pcb, this, m_ID_current_state, grid, on_grid, &pos ) ) { - GetScreen()->m_Curseur = curpos; + GetScreen()->m_Curseur = pos; } else { @@ -354,32 +346,31 @@ void WinEDA_PcbFrame::GeneralControle( wxDC* DC, wxPoint Mouse ) if( oldpos != GetScreen()->m_Curseur ) { - curpos = GetScreen()->m_Curseur; + pos = GetScreen()->m_Curseur; GetScreen()->m_Curseur = oldpos; - DrawPanel->CursorOff( DC ); - - GetScreen()->m_Curseur = curpos; - DrawPanel->CursorOn( DC ); + DrawPanel->CursorOff( aDC ); + GetScreen()->m_Curseur = pos; + DrawPanel->CursorOn( aDC ); if( DrawPanel->ManageCurseur ) { #ifdef USE_WX_OVERLAY - wxDCOverlay oDC( DrawPanel->m_overlay, (wxWindowDC*)DC ); - oDC.Clear(); - DrawPanel->ManageCurseur( DrawPanel, DC, FALSE ); + wxDCOverlay oDC( DrawPanel->m_overlay, (wxWindowDC*)aDC ); + oDC.Clear(); + DrawPanel->ManageCurseur( DrawPanel, aDC, FALSE ); #else - DrawPanel->ManageCurseur( DrawPanel, DC, TRUE ); + DrawPanel->ManageCurseur( DrawPanel, aDC, TRUE ); #endif } #ifdef USE_WX_OVERLAY else - DrawPanel->m_overlay.Reset(); + DrawPanel->m_overlay.Reset(); #endif } if( hotkey ) { - OnHotKey( DC, hotkey, NULL ); + OnHotKey( aDC, hotkey, NULL ); } if( GetScreen()->IsRefreshReq() ) diff --git a/pcbnew/editrack-part2.cpp b/pcbnew/editrack-part2.cpp index 5f05d17d6e..a987294618 100644 --- a/pcbnew/editrack-part2.cpp +++ b/pcbnew/editrack-part2.cpp @@ -271,9 +271,10 @@ void WinEDA_PcbFrame::Affiche_Status_Net( wxDC* DC ) { TRACK* pt_segm; int masquelayer = (1 << getActiveLayer()); + wxPoint pos = GetScreen()->RefPos( true ); + + pt_segm = Locate_Pistes( GetBoard(), GetBoard()->m_Track, pos, masquelayer ); - pt_segm = Locate_Pistes( GetBoard(), GetBoard()->m_Track, masquelayer, - CURSEUR_OFF_GRILLE ); if( pt_segm == NULL ) GetBoard()->DisplayInfo( this ); else diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index a5b2982997..873430438f 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -139,8 +139,6 @@ bool WinEDA_PcbFrame::LoadOnePcbFile( const wxString& aFileName, bool aAppend, FILE* source; wxString msg; - ActiveScreen = GetScreen(); - if( GetScreen()->IsModify() && !aAppend ) { if( !IsOK( this, _( "The current board has been modified. Do you wish to discard \ diff --git a/pcbnew/hotkeys_board_editor.cpp b/pcbnew/hotkeys_board_editor.cpp index 387ea11ad2..5e9076b315 100644 --- a/pcbnew/hotkeys_board_editor.cpp +++ b/pcbnew/hotkeys_board_editor.cpp @@ -32,10 +32,11 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* aDC, int aHotkeyCode, EDA_ITEM* aItem ) if( aHotkeyCode == 0 ) return; + wxPoint pos; bool itemCurrentlyEdited = (GetCurItem() && GetCurItem()->m_Flags); - MODULE* module = NULL; int evt_type = 0; //Used to post a wxCommandEvent on demand + PCB_SCREEN* screen = GetScreen(); /* Convert lower to upper case * (the usual toupper function has problem with non ascii codes like function keys @@ -156,8 +157,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* aDC, int aHotkeyCode, EDA_ITEM* aItem ) case HK_REDO: if( !itemCurrentlyEdited ) { - wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, - HK_Descr->m_IdMenuEvent ); + wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, HK_Descr->m_IdMenuEvent ); wxPostEvent( this, event ); } break; @@ -244,9 +244,9 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* aDC, int aHotkeyCode, EDA_ITEM* aItem ) case HK_ADD_MICROVIA: // Place a micro via if a track is in progress if( m_ID_current_state != ID_TRACK_BUTT ) return; - if( !itemCurrentlyEdited ) // no track in progress: nothing to do + if( !itemCurrentlyEdited ) // no track in progress: nothing to do break; - if( GetCurItem()->Type() != TYPE_TRACK ) // Should not occur + if( GetCurItem()->Type() != TYPE_TRACK ) // Should not occur return; if( (GetCurItem()->m_Flags & IS_NEW) == 0 ) return; @@ -318,10 +318,15 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* aDC, int aHotkeyCode, EDA_ITEM* aItem ) case HK_LOCK_UNLOCK_FOOTPRINT: // toggle module "MODULE_is_LOCKED" status: // get any module, locked or not locked and toggle its locked status if( !itemCurrentlyEdited ) - module = Locate_Prefered_Module( GetBoard(), CURSEUR_OFF_GRILLE - | VISIBLE_ONLY ); + { + pos = screen->RefPos( true ); + module = Locate_Prefered_Module( GetBoard(), pos, screen->m_Active_Layer, true ); + } else if( GetCurItem()->Type() == TYPE_MODULE ) + { module = (MODULE*) GetCurItem(); + } + if( module ) { SetCurItem( module ); @@ -400,11 +405,15 @@ bool WinEDA_PcbFrame::OnHotkeyDeleteItem( wxDC* aDC ) case ID_COMPONENT_BUTT: if( ItemFree ) { - MODULE* module = Locate_Prefered_Module( GetBoard(), CURSEUR_ON_GRILLE ); + wxPoint pos = GetScreen()->RefPos( false ); + MODULE* module = Locate_Prefered_Module( GetBoard(), pos, ALL_LAYERS, false ); + if( module == NULL ) return false; + if( !IsOK( this, _( "Delete module?" ) ) ) return false; + RemoveStruct( module, aDC ); } else diff --git a/pcbnew/locate.cpp b/pcbnew/locate.cpp index c9bfbcdc5d..00ac3484eb 100644 --- a/pcbnew/locate.cpp +++ b/pcbnew/locate.cpp @@ -13,21 +13,6 @@ -/** - * Function RefPos - * returns the reference position, coming from either the mouse position or the - * the cursor position, based on whether the typeloc has the CURSEUR_OFF_GRILLE - * flag ORed in or not. - * @param typeloc int with possible CURSEUR_OFF_GRILLE bit on. - * @return wxPoint - The reference point, either the mouse position or - * the cursor position. - */ -wxPoint inline RefPos( int typeloc ) -{ - return ActiveScreen->RefPos( (typeloc & CURSEUR_OFF_GRILLE) != 0 ); -} - - /* Locates a via point pX, pY * If layer < 0 will be located via whatever layer * If layer = 0 .. 15 Via will be located according to its type: @@ -46,12 +31,16 @@ TRACK* Locate_Via( BOARD* Pcb, const wxPoint& pos, int layer ) { if( track->Type() != TYPE_VIA ) continue; + if( track->m_Start != pos ) continue; + if( track->GetState( BUSY | DELETED ) ) continue; + if( layer < 0 ) break; + if( track->IsOnLayer( layer ) ) break; } @@ -68,12 +57,16 @@ TRACK* Locate_Via_Area( TRACK* aStart, const wxPoint& pos, int layer ) { if( track->Type() != TYPE_VIA ) continue; + if( !track->HitTest(pos) ) continue; + if( track->GetState( BUSY | DELETED ) ) continue; + if( layer < 0 ) break; + if( track->IsOnLayer( layer ) ) break; } @@ -109,6 +102,7 @@ D_PAD* Locate_Pad_Connecte( BOARD* Pcb, TRACK* ptr_piste, int extr ) for( MODULE* module = Pcb->m_Modules; module; module = module->Next() ) { ptr_pad = Locate_Pads( module, ref_pos, masque_layer ); + if( ptr_pad != NULL ) break; } @@ -129,36 +123,19 @@ D_PAD* Locate_Pad_Connecte( BOARD* Pcb, TRACK* ptr_piste, int extr ) * * Priority is the active layer */ -D_PAD* Locate_Any_Pad( BOARD* Pcb, int typeloc, bool OnlyCurrentLayer ) +D_PAD* Locate_Any_Pad( BOARD* Pcb, const wxPoint& ref_pos, int aLayerMask ) { - wxPoint ref_pos = RefPos( typeloc ); - return Locate_Any_Pad( Pcb, ref_pos, OnlyCurrentLayer ); -} + D_PAD* pad = NULL; - -D_PAD* Locate_Any_Pad( BOARD* Pcb, const wxPoint& ref_pos, - bool OnlyCurrentLayer ) -{ - int layer_mask = - g_TabOneLayerMask[ ( (PCB_SCREEN*) ActiveScreen )->m_Active_Layer]; - - for( MODULE* module=Pcb->m_Modules; module; module = module->Next() ) + for( MODULE* module=Pcb->m_Modules; module && ( pad == NULL ); module = module->Next() ) { - D_PAD* pt_pad; - - /* First: Search a pad on the active layer: */ - if( ( pt_pad = Locate_Pads( module, ref_pos, layer_mask ) ) != NULL ) - return pt_pad; - - /* If not found, search on other layers: */ - if( !OnlyCurrentLayer ) - { - if( ( pt_pad = Locate_Pads( module, ref_pos, ALL_LAYERS ) ) != NULL ) - return pt_pad; - } + if( aLayerMask ) + pad = Locate_Pads( module, ref_pos, aLayerMask ); + else + pad = Locate_Pads( module, ref_pos, ALL_LAYERS ); } - return NULL; + return pad; } @@ -171,13 +148,6 @@ D_PAD* Locate_Any_Pad( BOARD* Pcb, const wxPoint& ref_pos, * A pointer to the pad if found * NULL pointer if pad NOT FOUND */ -D_PAD* Locate_Pads( MODULE* module, int masque_layer, int typeloc ) -{ - wxPoint ref_pos = RefPos( typeloc ); - return Locate_Pads( module, ref_pos, masque_layer ); -} - - D_PAD* Locate_Pads( MODULE* module, const wxPoint& ref_pos, int masque_layer ) { for( D_PAD* pt_pad = module->m_Pads; pt_pad; pt_pad = pt_pad->Next() ) @@ -204,11 +174,14 @@ D_PAD* Locate_Pads( MODULE* module, const wxPoint& ref_pos, int masque_layer ) * distance is calculated via manhattan distance from the center of the * bounding rectangle to the cursor position. * - * @param Pcb The BOARD to search within. - * @param typeloc Flag bits, tuning the search, see pcbnew.h - * @return MODULE* - the best module or NULL if none. + * @param aPcb The BOARD to search within. + * @param aPosition Flag bits, tuning the search, see pcbnew.h + * @param aActiveLayer Layer to test. + * @param aVisibleOnly Search only the visible layers if true. + * @return MODULE* The best module or NULL if none. */ -MODULE* Locate_Prefered_Module( BOARD* Pcb, int typeloc ) +MODULE* Locate_Prefered_Module( BOARD* aPcb, const wxPoint& aPosition, int aActiveLayer, + bool aVisibleOnly, bool aIgnoreLocked ) { MODULE* pt_module; int lx, ly; @@ -217,20 +190,17 @@ MODULE* Locate_Prefered_Module( BOARD* Pcb, int typeloc ) int min_dim = 0x7FFFFFFF; int alt_min_dim = 0x7FFFFFFF; int layer; - wxPoint ref_pos; - ref_pos = RefPos( typeloc ); + pt_module = aPcb->m_Modules; - pt_module = Pcb->m_Modules; for( ; pt_module; pt_module = (MODULE*) pt_module->Next() ) { // is the ref point within the module's bounds? - if( !pt_module->HitTest( ref_pos ) ) + if( !pt_module->HitTest( aPosition ) ) continue; - // if caller wants to ignore locked modules, and this one is locked, - // skip it. - if( (typeloc & IGNORE_LOCKED) && pt_module->IsLocked() ) + // if caller wants to ignore locked modules, and this one is locked, skip it. + if( aIgnoreLocked && pt_module->IsLocked() ) continue; /* Calculate priority: the priority is given to the layer of the @@ -242,7 +212,6 @@ MODULE* Locate_Prefered_Module( BOARD* Pcb, int typeloc ) if( layer==ADHESIVE_N_BACK || layer==SILKSCREEN_N_BACK ) layer = LAYER_N_BACK; - else if( layer==ADHESIVE_N_FRONT || layer==SILKSCREEN_N_FRONT ) layer = LAYER_N_FRONT; @@ -251,17 +220,20 @@ MODULE* Locate_Prefered_Module( BOARD* Pcb, int typeloc ) int offx = pt_module->m_BoundaryBox.m_Size.x / 2 + pt_module->m_BoundaryBox.m_Pos.x + pt_module->m_Pos.x; + int offy = pt_module->m_BoundaryBox.m_Size.y / 2 + pt_module->m_BoundaryBox.m_Pos.y + pt_module->m_Pos.y; + //off x & offy point to the middle of the box. - int dist = abs( ref_pos.x - offx ) + abs( ref_pos.y - offy ); + int dist = abs( aPosition.x - offx ) + abs( aPosition.y - offy ); lx = pt_module->m_BoundaryBox.GetWidth(); ly = pt_module->m_BoundaryBox.GetHeight(); + //int dist = MIN(lx, ly); // to pick the smallest module (kinda // screwy with same-sized modules -- this is bad!) - if( ( (PCB_SCREEN*) ActiveScreen )->m_Active_Layer == layer ) + if( aActiveLayer == layer ) { if( dist <= min_dim ) { @@ -270,9 +242,7 @@ MODULE* Locate_Prefered_Module( BOARD* Pcb, int typeloc ) min_dim = dist; } } - else if( !( typeloc & MATCH_LAYER ) - && ( !( typeloc & VISIBLE_ONLY ) - || Pcb->IsModuleLayerVisible( layer ) ) ) + else if( aVisibleOnly && aPcb->IsModuleLayerVisible( layer ) ) { if( dist <= alt_min_dim ) { @@ -338,8 +308,7 @@ int dist; * @param pt_lim = upper limit for search (can be NULL) * @param extr = START or END = end of ref track segment to use in tests */ -TRACK* Locate_Piste_Connectee( TRACK* PtRefSegm, TRACK* pt_base, - TRACK* pt_lim, int extr ) +TRACK* Locate_Piste_Connectee( TRACK* PtRefSegm, TRACK* pt_base, TRACK* pt_lim, int extr ) { const int NEIGHTBOUR_COUNT_MAX = 50; @@ -367,6 +336,7 @@ TRACK* Locate_Piste_Connectee( TRACK* PtRefSegm, TRACK* pt_base, { if( PtSegmN->GetState( BUSY | DELETED ) ) goto suite; + if( PtSegmN == PtRefSegm ) goto suite; @@ -396,6 +366,7 @@ suite: { if( PtSegmB->GetState( BUSY | DELETED ) ) goto suite1; + if( PtSegmB == PtRefSegm ) goto suite1; @@ -429,12 +400,14 @@ suite1: { if( PtSegmN == pt_lim ) break; + continue; } if( PtSegmN == PtRefSegm ) { if( PtSegmN == pt_lim ) break; + continue; } @@ -466,16 +439,7 @@ suite1: * * The search begins to address start_adresse */ -TRACK* Locate_Pistes(BOARD* aPcb, TRACK* start_adresse, int MasqueLayer, int typeloc ) -{ - wxPoint ref_pos = RefPos( typeloc ); - - return Locate_Pistes( aPcb, start_adresse, ref_pos, MasqueLayer ); -} - - -TRACK* Locate_Pistes(BOARD* aPcb, TRACK* start_adresse, const wxPoint& ref_pos, - int MasqueLayer ) +TRACK* Locate_Pistes( BOARD* aPcb, TRACK* start_adresse, const wxPoint& ref_pos, int MasqueLayer ) { for( TRACK* track = start_adresse; track; track = track->Next() ) { @@ -510,6 +474,7 @@ TRACK* Locate_Pistes(BOARD* aPcb, TRACK* start_adresse, const wxPoint& ref_pos, return NULL; } + /* * 1 - Locate zone area by the mouse. * 2 - Locate zone area by point @@ -519,14 +484,6 @@ TRACK* Locate_Pistes(BOARD* aPcb, TRACK* start_adresse, const wxPoint& ref_pos, * * The search begins to address start_adresse */ -TRACK* Locate_Zone( TRACK* start_adresse, int layer, int typeloc ) -{ - wxPoint ref_pos = RefPos( typeloc ); - - return Locate_Zone( start_adresse, ref_pos, layer ); -} - - TRACK* Locate_Zone( TRACK* start_adresse, const wxPoint& ref_pos, int layer ) { for( TRACK* Zone = start_adresse; Zone; Zone = Zone->Next() ) @@ -552,8 +509,7 @@ TRACK* Locate_Zone( TRACK* start_adresse, const wxPoint& ref_pos, int layer ) * Pointer to the structure corresponding descr_pad if pad found * (Good position and good layer). */ -D_PAD* Fast_Locate_Pad_Connecte( BOARD* Pcb, const wxPoint& ref_pos, - int masque_layer ) +D_PAD* Fast_Locate_Pad_Connecte( BOARD* Pcb, const wxPoint& ref_pos, int masque_layer ) { for( unsigned i=0; i