GAL canvases update status bar, message panel & zoom widget.

This commit is contained in:
Maciej Suminski 2015-07-03 20:58:12 +02:00
parent 891bd3d629
commit 3cb095b7c2
15 changed files with 181 additions and 59 deletions

View File

@ -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 ) );
}

View File

@ -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

View File

@ -145,7 +145,7 @@ void TOOL_DISPATCHER::ResetState()
KIGFX::VIEW* TOOL_DISPATCHER::getView()
{
return static_cast<PCB_BASE_FRAME*>( m_toolMgr->GetEditFrame() )->GetGalCanvas()->GetView();
return static_cast<EDA_DRAW_FRAME*>( m_toolMgr->GetEditFrame() )->GetGalCanvas()->GetView();
}
@ -271,7 +271,6 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
{
motion = true;
m_lastMousePos = pos;
static_cast<PCB_BASE_FRAME*>( 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<EDA_DRAW_FRAME*>( m_toolMgr->GetEditFrame() );
frame->UpdateStatusBar();
frame->UpdateMsgPanel();
}

View File

@ -86,11 +86,9 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent )
m_view->SetCenter( m_lookStartPoint + delta );
aEvent.StopPropagation();
}
else
{
aEvent.Skip();
}
}
aEvent.Skip();
}

View File

@ -34,6 +34,7 @@
#include <wx/timer.h>
#include <layers_id_colors_and_visibility.h>
#include <math/vector2d.h>
#include <msgpanel.h>
class BOARD;
class TOOL_DISPATCHER;
@ -150,6 +151,17 @@ public:
*/
virtual void SetTopLayer( LAYER_ID aLayer );
virtual void GetMsgPanelInfo( std::vector<MSG_PANEL_ITEM>& 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;

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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();
}
}

View File

@ -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;

View File

@ -28,6 +28,7 @@
#include <pcb_painter.h>
#include <worksheet_viewitem.h>
#include <ratsnest_viewitem.h>
#include <ratsnest_data.h>
#include <class_colors_design_settings.h>
#include <class_board.h>
@ -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<MSG_PANEL_ITEM>& aList )
{
BOARD* board = static_cast<PCB_BASE_FRAME*>( 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 ) );
}

View File

@ -77,6 +77,9 @@ public:
*/
void SyncLayersVisibility( const BOARD* aBoard );
///> @copydoc EDA_DRAW_PANEL_GAL::GetMsgPanelInfo()
void GetMsgPanelInfo( std::vector<MSG_PANEL_ITEM>& aList );
protected:
///> Currently used worksheet
KIGFX::WORKSHEET_VIEWITEM* m_worksheet;

View File

@ -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<RN_EDGE_MST_PTR>* 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 )

View File

@ -445,7 +445,7 @@ public:
std::list<RN_NODE_PTR> 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()

View File

@ -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 );
}