From d9d2822fe041bb420dac895b42cf097ed87a9bb0 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 8 Sep 2018 21:57:56 +0100 Subject: [PATCH] Fix cross-probing. --- eeschema/find.cpp | 30 +++------------- eeschema/sch_base_frame.cpp | 24 ++++++++++--- eeschema/sch_base_frame.h | 4 ++- eeschema/sch_draw_panel.cpp | 51 +++++++++++++--------------- eeschema/sch_draw_panel.h | 3 ++ include/legacy_gal/class_drawpanel.h | 3 -- 6 files changed, 53 insertions(+), 62 deletions(-) diff --git a/eeschema/find.cpp b/eeschema/find.cpp index 5310292dd1..e8d4404744 100644 --- a/eeschema/find.cpp +++ b/eeschema/find.cpp @@ -90,7 +90,8 @@ void SCH_EDIT_FRAME::OnFindDrcMarker( wxFindDialogEvent& event ) SetCrossHairPosition( lastMarker->GetPosition() ); - RedrawScreen( lastMarker->GetPosition(), warpCursor ); + + CenterScreen( lastMarker->GetPosition(), warpCursor ); msg.Printf( _( "Design rule check marker found in sheet %s at %s, %s" ), sheetFoundIn->Path(), @@ -115,7 +116,6 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference, SCH_ITEM* item = NULL; SCH_COMPONENT* Component = NULL; wxPoint pos; - bool centerAndRedraw = false; bool notFound = true; LIB_PIN* pin; SCH_SHEET_LIST sheetList( g_RootSheet ); @@ -193,7 +193,6 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference, *m_CurrentSheet = *sheet; m_CurrentSheet->UpdateAllScreenReferences(); sheet->LastScreen()->TestDanglingEnds(); - centerAndRedraw = true; } wxPoint delta; @@ -201,25 +200,8 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference, delta = Component->GetTransform().TransformCoordinate( pos ); pos = delta + Component->GetPosition(); - - /* There may be need to reframe the drawing */ - if( ! m_canvas->IsPointOnDisplay( pos ) ) - centerAndRedraw = true; - - if( centerAndRedraw ) - { - SetCrossHairPosition( pos ); - RedrawScreen( pos, false ); - } - else - { - /*INSTALL_UNBUFFERED_DC( dc, m_canvas ); - - m_canvas->CrossHairOff( &dc ); - SetCrossHairPosition( pos ); - m_canvas->CrossHairOn( &dc );*/ - // fixme-gal - } + SetCrossHairPosition( pos ); + CenterScreen( pos, false ); } /* Print diag */ @@ -439,10 +421,8 @@ void SCH_EDIT_FRAME::updateFindReplaceView( wxFindDialogEvent& aEvent ) sheet->LastScreen()->TestDanglingEnds(); } - // careful here SetCrossHairPosition( data.GetPosition() ); - - RedrawScreen( data.GetPosition(), warpCursor ); + CenterScreen( data.GetPosition(), warpCursor ); msg = m_foundItems.GetText( m_UserUnits ); diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 832cff6ca8..99a1122440 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -82,7 +82,7 @@ LIB_PART* SchGetLibPart( const LIB_ID& aLibId, SYMBOL_LIB_TABLE* aLibTable, PART } -// Sttaic members: +// Static members: SCH_BASE_FRAME::SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aWindowType, const wxString& aTitle, @@ -335,6 +335,8 @@ bool SCH_BASE_FRAME::saveSymbolLibTables( bool aGlobal, bool aProject ) return success; } + +// Set the zoom level to show the contents of the view. void SCH_BASE_FRAME::Zoom_Automatique( bool aWarpPointer ) { EDA_DRAW_PANEL_GAL* galCanvas = GetGalCanvas(); @@ -378,11 +380,12 @@ void SCH_BASE_FRAME::Zoom_Automatique( bool aWarpPointer ) galCanvas->Refresh(); } - /* Set the zoom level to show the area Rect */ -void SCH_BASE_FRAME::Window_Zoom( EDA_RECT& Rect ) + +// Set the zoom level to show the area of aRect +void SCH_BASE_FRAME::Window_Zoom( EDA_RECT& aRect ) { KIGFX::VIEW* view = GetGalCanvas()->GetView(); - BOX2I selectionBox ( Rect.GetPosition(), Rect.GetSize() ); + BOX2I selectionBox ( aRect.GetPosition(), aRect.GetSize() ); VECTOR2D screenSize = view->ToWorld( GetGalCanvas()->GetClientSize(), false ); @@ -418,7 +421,7 @@ void SCH_BASE_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointe GetCanvas()->GetView()->SetScale( scale ); if( aWarpPointer ) - GetCanvas()->GetViewControls()->CenterOnCursor(); + GetCanvas()->GetViewControls()->WarpCursor( aCenterPoint ); GetCanvas()->Refresh(); } @@ -438,6 +441,17 @@ void SCH_BASE_FRAME::RedrawScreen2( const wxPoint& posBefore ) } +void SCH_BASE_FRAME::CenterScreen( const wxPoint& aCenterPoint, bool aWarpPointer ) +{ + GetCanvas()->GetView()->SetCenter( aCenterPoint ); + + if( aWarpPointer ) + GetCanvas()->GetViewControls()->WarpCursor( aCenterPoint ); + + GetGalCanvas()->Refresh(); +} + + void SCH_BASE_FRAME::HardRedraw() { GetCanvas()->DisplaySheet( GetScreen() ); diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index 75513c6619..24b2ada6a7 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -280,12 +280,14 @@ public: virtual void Zoom_Automatique( bool aWarpPointer ) override; /* Set the zoom level to show the area Rect */ - virtual void Window_Zoom( EDA_RECT& Rect ) override; + virtual void Window_Zoom( EDA_RECT& aRect ) override; virtual void RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer ) override; virtual void RedrawScreen2( const wxPoint& posBefore ) override; + virtual void CenterScreen( const wxPoint& aCenterPoint, bool aWarpPointer ); + virtual void HardRedraw() override; void AddToScreen( SCH_ITEM* aItem ); diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index a71a538187..a11edb8f90 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -27,7 +27,6 @@ #include #include - #include #include #include @@ -42,6 +41,26 @@ using namespace std::placeholders; +// Events used by EDA_DRAW_PANEL +// GAL TODO: some (most?) of these need to be implemented... +BEGIN_EVENT_TABLE( SCH_DRAW_PANEL, wxScrolledWindow ) +// EVT_LEAVE_WINDOW( EDA_DRAW_PANEL::OnMouseLeaving ) +// EVT_ENTER_WINDOW( EDA_DRAW_PANEL::OnMouseEntering ) +// EVT_MOUSEWHEEL( EDA_DRAW_PANEL::OnMouseWheel ) +#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT ) +// EVT_MAGNIFY( EDA_DRAW_PANEL::OnMagnify ) +#endif +// EVT_MOUSE_EVENTS( EDA_DRAW_PANEL::OnMouseEvent ) + EVT_CHAR( SCH_DRAW_PANEL::OnKeyEvent ) + EVT_CHAR_HOOK( SCH_DRAW_PANEL::OnCharHook ) + EVT_PAINT( SCH_DRAW_PANEL::onPaint ) +// EVT_ERASE_BACKGROUND( EDA_DRAW_PANEL::OnEraseBackground ) +// EVT_SCROLLWIN( EDA_DRAW_PANEL::OnScroll ) +// EVT_ACTIVATE( EDA_DRAW_PANEL::OnActivate ) +// EVT_MENU_RANGE( ID_PAN_UP, ID_PAN_RIGHT, EDA_DRAW_PANEL::OnPan ) +END_EVENT_TABLE() + + SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, const wxPoint& aPosition, const wxSize& aSize, KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) : @@ -85,8 +104,7 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, for( auto e : events ) { - Connect( e, wxMouseEventHandler( SCH_DRAW_PANEL::OnMouseEvent ), - NULL, this ); + Connect( e, wxMouseEventHandler( SCH_DRAW_PANEL::OnMouseEvent ), NULL, this ); } Connect( wxEVT_CHAR, wxKeyEventHandler( SCH_DRAW_PANEL::OnKeyEvent ), NULL, this ); @@ -111,11 +129,9 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, m_enableBlockCommands = false; m_minDragEventCount = 0; - m_cursorLevel = 0; m_PrintIsMirrored = false; - m_ClickTimer = (wxTimer*) NULL; m_doubleClickInterval = 250; m_gal->SetGridColor( COLOR4D(0.0, 0.0, 0.0, 1.0) ); @@ -251,7 +267,6 @@ void SCH_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) auto controls = GetViewControls(); auto vcp = VECTOR2I( controls->GetCursorPosition() ); auto vmp = VECTOR2I( controls->GetMousePosition() ); - wxPoint cursorPos ( vcp.x, vcp.y ); wxPoint mousePos ( vmp.x, vmp.y ); event.Skip(); @@ -313,11 +328,6 @@ void SCH_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) // Calling Double Click and Click functions : if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) ) { - if( m_ClickTimer ) - { - m_ClickTimer->Stop(); - wxDELETE( m_ClickTimer ); - } GetParent()->OnLeftDClick( nullptr, mousePos ); // inhibit a response to the mouse left button release, @@ -335,20 +345,7 @@ void SCH_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) m_ignoreNextLeftButtonRelease = false; if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK && !ignoreEvt ) - { - EDA_ITEM* item = screen->GetCurItem(); - - // If we have an item already selected, or we are using a tool, - // we won't use the disambiguation menu so process the click immediately - if( ( item && item->GetFlags() ) || GetParent()->GetToolId() != ID_NO_TOOL_SELECTED ) - GetParent()->OnLeftClick( nullptr, mousePos ); - else - { - wxDELETE( m_ClickTimer ); - m_ClickTimer = new wxTimer(this, ID_MOUSE_DOUBLECLICK); - m_ClickTimer->StartOnce( m_doubleClickInterval ); - } - } + GetParent()->OnLeftClick( nullptr, mousePos ); } else if( !event.LeftIsDown() ) @@ -527,13 +524,12 @@ void SCH_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) } + bool SCH_DRAW_PANEL::OnRightClick( wxMouseEvent& event ) { auto controls = GetViewControls(); auto vmp = controls->GetMousePosition(); - auto vsp = GetView()->ToScreen( vmp ); wxPoint mouseWorldPos ( (int) vmp.x, (int) vmp.y ); - wxPoint mouseScreenPos ( (int) vsp.x, (int) vsp.y ); wxMenu MasterMenu; @@ -559,7 +555,6 @@ void SCH_DRAW_PANEL::CallMouseCapture( wxDC* aDC, const wxPoint& aPosition, bool void SCH_DRAW_PANEL::CallEndMouseCapture( wxDC* aDC ) { - // CallEndMouseCapture is sometimes called with m_endMouseCaptureCallback == NULL // for instance after an ABORT in block paste. if( m_endMouseCaptureCallback ) diff --git a/eeschema/sch_draw_panel.h b/eeschema/sch_draw_panel.h index 2aa0f1d6e1..5f26cfe41d 100644 --- a/eeschema/sch_draw_panel.h +++ b/eeschema/sch_draw_panel.h @@ -61,6 +61,7 @@ public: bool OnRightClick( wxMouseEvent& event ); void OnKeyEvent( wxKeyEvent& event ); void OnCharHook( wxKeyEvent& event ); + void OnTimer( wxTimerEvent& event ); void SetEnableMousewheelPan( bool aEnable ) override; void SetEnableZoomNoCenter( bool aEnable ) override; @@ -101,6 +102,8 @@ protected: void setDefaultLayerDeps(); wxWindow* m_parent; + + DECLARE_EVENT_TABLE() }; #endif diff --git a/include/legacy_gal/class_drawpanel.h b/include/legacy_gal/class_drawpanel.h index a4c6f1a7e6..0f2ef13d59 100644 --- a/include/legacy_gal/class_drawpanel.h +++ b/include/legacy_gal/class_drawpanel.h @@ -35,9 +35,6 @@ protected: wxPoint m_PanStartCenter; ///< Initial scroll center position when pan started wxPoint m_PanStartEventPosition; ///< Initial position of mouse event when pan started - wxPoint m_CursorClickPos; ///< Used for maintaining click position - wxTimer *m_ClickTimer; - /// The drawing area used to redraw the screen which is usually the visible area /// of the drawing in internal units. EDA_RECT m_ClipBox;