From 3cb095b7c2ed8d2c4c25311b05fb1b42cafa23b2 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 3 Jul 2015 20:58:12 +0200 Subject: [PATCH] GAL canvases update status bar, message panel & zoom widget. --- common/draw_frame.cpp | 50 ++++++++++++++++++++----------- common/draw_panel_gal.cpp | 13 ++++++-- common/tool/tool_dispatcher.cpp | 17 +++++++++-- common/view/wx_view_controls.cpp | 6 ++-- include/class_draw_panel_gal.h | 14 ++++++++- include/draw_frame.h | 6 ++++ include/tool/tool_dispatcher.h | 5 +++- include/wxBasePcbFrame.h | 3 ++ pcbnew/basepcbframe.cpp | 51 +++++++++++++++++--------------- pcbnew/class_board.h | 6 ---- pcbnew/pcb_draw_panel_gal.cpp | 36 ++++++++++++++++++++++ pcbnew/pcb_draw_panel_gal.h | 3 ++ pcbnew/ratsnest_data.cpp | 16 ++++++++++ pcbnew/ratsnest_data.h | 9 +++++- pcbnew/tools/pcbnew_control.cpp | 5 ++++ 15 files changed, 181 insertions(+), 59 deletions(-) diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index 7cb84de40e..485a5deff0 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -217,11 +217,7 @@ bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName ) void EDA_DRAW_FRAME::unitsChangeRefresh() { UpdateStatusBar(); - - EDA_ITEM* item = GetScreen()->GetCurItem(); - - if( item ) - SetMsgPanel( item ); + UpdateMsgPanel(); } @@ -447,7 +443,10 @@ void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event ) TOOL_MANAGER* mgr = GetToolManager(); if( mgr && IsGalCanvasActive() ) + { mgr->RunAction( "common.Control.zoomPreset", true, id ); + UpdateStatusBar(); + } } @@ -634,16 +633,24 @@ void EDA_DRAW_FRAME::UpdateStatusBar() const wxString EDA_DRAW_FRAME::GetZoomLevelIndicator() const { - BASE_SCREEN* screen = GetScreen(); wxString Line; + double level = 0.0; - if( screen ) + if( IsGalCanvasActive() ) { - // returns a human readable value which can be displayed as zoom - // level indicator in dialogs. - double level = m_zoomLevelCoeff / (double)screen->GetZoom(); - Line.Printf( wxT( "Z %.2f" ), level ); + KIGFX::GAL* gal = m_galCanvas->GetGAL(); + KIGFX::VIEW* view = m_galCanvas->GetView(); + double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); + level = m_zoomLevelCoeff * zoomFactor * view->GetScale(); } + else if( BASE_SCREEN* screen = GetScreen() ) + { + level = m_zoomLevelCoeff / (double) screen->GetZoom(); + } + + // returns a human readable value which can be displayed as zoom + // level indicator in dialogs. + Line.Printf( wxT( "Z %.2f" ), level ); return Line; } @@ -728,6 +735,15 @@ void EDA_DRAW_FRAME::SetMsgPanel( EDA_ITEM* aItem ) } +void EDA_DRAW_FRAME::UpdateMsgPanel() +{ + EDA_ITEM* item = GetScreen()->GetCurItem(); + + if( item ) + SetMsgPanel( item ); +} + + wxString EDA_DRAW_FRAME::CoordinateToString( int aValue, bool aConvertToMils ) const { return ::CoordinateToString( aValue, aConvertToMils ); @@ -1028,9 +1044,6 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) KIGFX::VIEW* view = GetGalCanvas()->GetView(); KIGFX::GAL* gal = GetGalCanvas()->GetGAL(); - double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); - BASE_SCREEN* screen = GetScreen(); - // Display the same view after canvas switching if( aEnable ) { @@ -1038,6 +1051,7 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) if( !m_galCanvasActive ) { // Set up viewport + double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() ); view->SetScale( zoom ); view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) ); @@ -1045,7 +1059,7 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) // Set up grid settings gal->SetGridVisibility( IsGridVisible() ); - gal->SetGridSize( VECTOR2D( screen->GetGridSize() ) ); + gal->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) ); gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) ); GetToolManager()->RunAction( "pcbnew.Control.switchCursor" ); @@ -1053,9 +1067,9 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) else if( m_galCanvasActive ) { // Switch to standard rendering - double zoom = 1.0 / ( zoomFactor * view->GetScale() ); - m_canvas->SetZoom( zoom ); - + double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); + // TODO replace it with EDA_DRAW_PANEL_GAL::GetLegacyZoom + m_canvas->SetZoom( 1.0 / ( zoomFactor * view->GetScale() ) ); VECTOR2D center = view->GetCenter(); AdjustScrollBars( wxPoint( center.x, center.y ) ); } diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index c968fc5df8..84903cffea 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -73,8 +73,6 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin m_view->SetPainter( m_painter ); m_view->SetGAL( m_gal ); - m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this ); - Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this ); Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this ); Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( EDA_DRAW_PANEL_GAL::onLostFocus ), NULL, this ); @@ -97,6 +95,10 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin NULL, m_eventDispatcher ); } + // View controls is the first in the event handler chain, so the Tool Framework operates + // on updated viewport data. + m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this ); + // Set up timer that prevents too frequent redraw commands m_refreshTimer.SetOwner( this ); m_pendingRefresh = false; @@ -257,6 +259,13 @@ void EDA_DRAW_PANEL_GAL::SetTopLayer( LAYER_ID aLayer ) } +double EDA_DRAW_PANEL_GAL::GetLegacyZoom() const +{ + double zoomFactor = m_gal->GetWorldScale() / m_gal->GetZoomFactor(); + return ( 1.0 / ( zoomFactor * m_view->GetScale() ) ); +} + + bool EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) { // Do not do anything if the currently used GAL is correct diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 7228a13686..8a66147ceb 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -145,7 +145,7 @@ void TOOL_DISPATCHER::ResetState() KIGFX::VIEW* TOOL_DISPATCHER::getView() { - return static_cast( m_toolMgr->GetEditFrame() )->GetGalCanvas()->GetView(); + return static_cast( m_toolMgr->GetEditFrame() )->GetGalCanvas()->GetView(); } @@ -271,7 +271,6 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) { motion = true; m_lastMousePos = pos; - static_cast( m_toolMgr->GetEditFrame() )->UpdateStatusBar(); } for( unsigned int i = 0; i < m_buttons.size(); i++ ) @@ -325,6 +324,8 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) // pass the event to the GUI, it might still be interested in it aEvent.Skip(); + + updateUI(); } @@ -336,4 +337,16 @@ void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent& aEvent ) m_toolMgr->ProcessEvent( *evt ); else aEvent.Skip(); + + updateUI(); +} + + +void TOOL_DISPATCHER::updateUI() +{ + // TODO I don't feel it is the right place for updating UI, + // but at the moment I cannot think of a better one.. + EDA_DRAW_FRAME* frame = static_cast( m_toolMgr->GetEditFrame() ); + frame->UpdateStatusBar(); + frame->UpdateMsgPanel(); } diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index e931830289..061f88246d 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -86,11 +86,9 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent ) m_view->SetCenter( m_lookStartPoint + delta ); aEvent.StopPropagation(); } - else - { - aEvent.Skip(); - } } + + aEvent.Skip(); } diff --git a/include/class_draw_panel_gal.h b/include/class_draw_panel_gal.h index 36e60a7892..84ca213a83 100644 --- a/include/class_draw_panel_gal.h +++ b/include/class_draw_panel_gal.h @@ -34,6 +34,7 @@ #include #include #include +#include class BOARD; class TOOL_DISPATCHER; @@ -150,6 +151,17 @@ public: */ virtual void SetTopLayer( LAYER_ID aLayer ); + virtual void GetMsgPanelInfo( std::vector& aList ) + { + assert( false ); + } + + /** + * Function GetLegacyZoom() + * Returns current view scale converted to zoom value used by the legacy canvas. + */ + double GetLegacyZoom() const; + protected: void onPaint( wxPaintEvent& WXUNUSED( aEvent ) ); void onSize( wxSizeEvent& aEvent ); @@ -161,7 +173,7 @@ protected: static const int MinRefreshPeriod = 17; ///< 60 FPS. /// Pointer to the parent window - wxWindow* m_parent; + wxWindow* m_parent; /// Last timestamp when the panel was refreshed wxLongLong m_lastRefresh; diff --git a/include/draw_frame.h b/include/draw_frame.h index ad35c5a4a5..33560c390b 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -713,6 +713,12 @@ public: void SetMsgPanel( EDA_ITEM* aItem ); + /** + * Function UpdateMsgPanel + * redraws the message panel. + */ + virtual void UpdateMsgPanel(); + /** * Function PrintPage * used to print a page diff --git a/include/tool/tool_dispatcher.h b/include/tool/tool_dispatcher.h index ef673b2792..3cc9bacea4 100644 --- a/include/tool/tool_dispatcher.h +++ b/include/tool/tool_dispatcher.h @@ -93,7 +93,7 @@ private: ///> and a beginning of drag event (expressed in screen pixels). static const int DragDistanceThreshold = 8; - ///> Handles mouse related events (click, motion, dragging) + ///> Handles mouse related events (click, motion, dragging). bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion ); ///> Saves the state of key modifiers (Alt, Ctrl and so on). @@ -114,6 +114,9 @@ private: return mods; } + ///> Redraws the status bar and message panel. + void updateUI(); + ///> Stores all the informations regarding a mouse button state. struct BUTTON_STATE; diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h index d06cc00d95..cc05ce1919 100644 --- a/include/wxBasePcbFrame.h +++ b/include/wxBasePcbFrame.h @@ -258,6 +258,9 @@ public: BOARD_ITEM* GetCurItem(); + ///> @copydoc EDA_DRAW_FRAME::UpdateMsgPanel() + void UpdateMsgPanel(); + /** * Function GetCollectorsGuide * @return GENERAL_COLLECTORS_GUIDE - that considers the global diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 852c9f881c..7a017f864a 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -505,10 +505,11 @@ void PCB_BASE_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent ) return; int current = 0; + double zoom = IsGalCanvasActive() ? GetGalCanvas()->GetLegacyZoom() : GetScreen()->GetZoom(); for( unsigned i = 0; i < GetScreen()->m_ZoomList.size(); i++ ) { - if( GetScreen()->GetZoom() == GetScreen()->m_ZoomList[i] ) + if( zoom == GetScreen()->m_ZoomList[i] ) { current = i + 1; break; @@ -545,33 +546,29 @@ void PCB_BASE_FRAME::SetCurItem( BOARD_ITEM* aItem, bool aDisplayInfo ) { GetScreen()->SetCurItem( aItem ); - if( aItem ) + if( aDisplayInfo ) + UpdateMsgPanel(); +} + + +void PCB_BASE_FRAME::UpdateMsgPanel() +{ + BOARD_ITEM* item = GetScreen()->GetCurItem(); + MSG_PANEL_ITEMS items; + + if( item ) { - if( aDisplayInfo ) - { - MSG_PANEL_ITEMS items; - aItem->GetMsgPanelInfo( items ); - SetMsgPanel( items ); - } - -#if 0 && defined(DEBUG) - aItem->Show( 0, std::cout ); -#endif - + item->GetMsgPanelInfo( items ); } - else + else // show general information about the board { - // we can use either of these two: - - MSG_PANEL_ITEMS items; - m_Pcb->GetMsgPanelInfo( items ); // show the BOARD stuff - SetMsgPanel( items ); - -#if 0 && defined(DEBUG) - std::cout << "SetCurItem(NULL)\n"; -#endif - + if( IsGalCanvasActive() ) + GetGalCanvas()->GetMsgPanelInfo( items ); + else + m_Pcb->GetMsgPanelInfo( items ); } + + SetMsgPanel( items ); } @@ -790,6 +787,12 @@ void PCB_BASE_FRAME::OnModify() { GetScreen()->SetModify(); GetScreen()->SetSave(); + + if( IsGalCanvasActive() ) + { + UpdateStatusBar(); + UpdateMsgPanel(); + } } diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index 9e565bc301..4cc80ac27a 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -58,12 +58,6 @@ class NETLIST; class REPORTER; class RN_DATA; -namespace KIGFX -{ - class RATSNEST_VIEWITEM; - class WORKSHEET_VIEWITEM; -} - // non-owning container of item candidates when searching for items on the same track. typedef std::vector< TRACK* > TRACK_PTRS; diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index bcb661c546..80a1628936 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -360,3 +361,38 @@ void PCB_DRAW_PANEL_GAL::SyncLayersVisibility( const BOARD* aBoard ) m_view->SetLayerVisible( ITEM_GAL_LAYER( WORKSHEET ), true ); m_view->SetLayerVisible( ITEM_GAL_LAYER( GP_OVERLAY ), true ); } + + +void PCB_DRAW_PANEL_GAL::GetMsgPanelInfo( std::vector& aList ) +{ + BOARD* board = static_cast( m_parent )->GetBoard(); + wxString txt; + int viasCount = 0; + int trackSegmentsCount = 0; + + for( const BOARD_ITEM* item = board->m_Track; item; item = item->Next() ) + { + if( item->Type() == PCB_VIA_T ) + viasCount++; + else + trackSegmentsCount++; + } + + txt.Printf( wxT( "%d" ), board->GetPadCount() ); + aList.push_back( MSG_PANEL_ITEM( _( "Pads" ), txt, DARKGREEN ) ); + + txt.Printf( wxT( "%d" ), viasCount ); + aList.push_back( MSG_PANEL_ITEM( _( "Vias" ), txt, DARKGREEN ) ); + + txt.Printf( wxT( "%d" ), trackSegmentsCount ); + aList.push_back( MSG_PANEL_ITEM( _( "Track Segments" ), txt, DARKGREEN ) ); + + txt.Printf( wxT( "%d" ), board->GetNodesCount() ); + aList.push_back( MSG_PANEL_ITEM( _( "Nodes" ), txt, DARKCYAN ) ); + + txt.Printf( wxT( "%d" ), board->GetNetCount() ); + aList.push_back( MSG_PANEL_ITEM( _( "Nets" ), txt, RED ) ); + + txt.Printf( wxT( "%d" ), board->GetRatsnest()->GetUnconnectedCount() ); + aList.push_back( MSG_PANEL_ITEM( _( "Unconnected" ), txt, BLUE ) ); +} diff --git a/pcbnew/pcb_draw_panel_gal.h b/pcbnew/pcb_draw_panel_gal.h index 26ac94f968..2dabaab2bb 100644 --- a/pcbnew/pcb_draw_panel_gal.h +++ b/pcbnew/pcb_draw_panel_gal.h @@ -77,6 +77,9 @@ public: */ void SyncLayersVisibility( const BOARD* aBoard ); + ///> @copydoc EDA_DRAW_PANEL_GAL::GetMsgPanelInfo() + void GetMsgPanelInfo( std::vector& aList ); + protected: ///> Currently used worksheet KIGFX::WORKSHEET_VIEWITEM* m_worksheet; diff --git a/pcbnew/ratsnest_data.cpp b/pcbnew/ratsnest_data.cpp index b0c2af20a8..74c9cc1d52 100644 --- a/pcbnew/ratsnest_data.cpp +++ b/pcbnew/ratsnest_data.cpp @@ -985,6 +985,22 @@ bool RN_DATA::AreConnected( const BOARD_CONNECTED_ITEM* aItem, const BOARD_CONNE } +int RN_DATA::GetUnconnectedCount() const +{ + int count = 0; + + for( unsigned i = 0; i < m_nets.size(); ++i ) + { + const std::vector* unconnected = m_nets[i].GetUnconnected(); + + if( unconnected ) + count += unconnected->size(); + } + + return count; +} + + void RN_NET::processZones() { for( ZONE_DATA_MAP::iterator it = m_zones.begin(); it != m_zones.end(); ++it ) diff --git a/pcbnew/ratsnest_data.h b/pcbnew/ratsnest_data.h index 1e2a56cb3c..4c8793f92b 100644 --- a/pcbnew/ratsnest_data.h +++ b/pcbnew/ratsnest_data.h @@ -445,7 +445,7 @@ public: std::list GetNodes( const BOARD_CONNECTED_ITEM* aItem ) const; /** - * Function GetAllNodes() + * Function GetAllItems() * Adds all stored items to a list. * @param aOutput is the list that will have items added. * @param aType determines the type of added items. @@ -727,6 +727,13 @@ public: */ bool AreConnected( const BOARD_CONNECTED_ITEM* aItem, const BOARD_CONNECTED_ITEM* aOther ); + /** + * Function GetUnconnectedCount() + * Returns the number of missing connections. + * @return Number of missing connections. + */ + int GetUnconnectedCount() const; + protected: /** * Function updateNet() diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index fc789302a1..70f34c1b3f 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -474,6 +474,7 @@ int PCBNEW_CONTROL::CursorControl( const TOOL_EVENT& aEvent ) if( warp ) { KIGFX::VIEW* view = getView(); + VECTOR2D worldCursor = newCursor; newCursor = view->ToScreen( newCursor ); // Pan the screen if required @@ -513,6 +514,10 @@ int PCBNEW_CONTROL::CursorControl( const TOOL_EVENT& aEvent ) view->SetCenter( view->GetCenter() + view->ToWorld( delta, false ) ); } + TOOL_EVENT evt( TC_MOUSE, TA_MOUSE_MOTION ); + evt.SetMousePosition( worldCursor ); + m_toolMgr->ProcessEvent( evt ); + m_frame->GetGalCanvas()->WarpPointer( newCursor.x, newCursor.y ); }