From 517ca83fbcec9915c57bb7d60dfbea0c35ff0bb1 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Thu, 26 Dec 2013 16:36:43 -0600 Subject: [PATCH] Hide m_galCanvas and m_galCanvasActive behind accessors. Fix DLIST concatonation API corner case. --- TODO.txt | 1 - common/dlist.cpp | 45 ++++++++++++----------- common/drawframe.cpp | 34 ++++++++--------- common/zoom.cpp | 10 ++--- include/wxstruct.h | 24 ++++++------ pcbnew/basepcbframe.cpp | 16 ++++---- pcbnew/class_pcb_layer_widget.cpp | 6 ++- pcbnew/dialogs/dialog_general_options.cpp | 6 +-- pcbnew/pcbframe.cpp | 44 +++++++++++----------- pcbnew/tools/pcb_tools.cpp | 2 +- 10 files changed, 97 insertions(+), 91 deletions(-) diff --git a/TODO.txt b/TODO.txt index 7a534122bb..f7c42ce854 100644 --- a/TODO.txt +++ b/TODO.txt @@ -62,7 +62,6 @@ PCBNew Dick's Final TODO List: ====================== -*) Apply Fabrizio and Alexander's linux desktop patches after unifying them. *) Get licensing cleaned up. *) Re-arrange the repo architecture. *) DLL-ization of pcbnew & eeschema diff --git a/common/dlist.cpp b/common/dlist.cpp index 55ed137fd3..512fd1ce7a 100644 --- a/common/dlist.cpp +++ b/common/dlist.cpp @@ -87,31 +87,32 @@ void DHEAD::append( EDA_ITEM* aNewElement ) void DHEAD::append( DHEAD& aList ) { - wxCHECK_RET( aList.GetCount() != 0, wxT( "Attempt to append empty list." ) ); - - // Change the item's list to me. - for( EDA_ITEM* item = aList.first; item != NULL; item = item->Next() ) - item->SetList( this ); - - if( first ) // list is not empty, set last item's next to the first item in aList + if( aList.first ) { - wxCHECK_RET( last != NULL, wxT( "Last list element not set." ) ); + // Change the item's list to me. + for( EDA_ITEM* item = aList.first; item; item = item->Next() ) + item->SetList( this ); - last->SetNext( aList.first ); - aList.first->SetBack( last ); - last = aList.last; + if( first ) // this list is not empty, set last item's next to the first item in aList + { + wxCHECK_RET( last != NULL, wxT( "Last list element not set." ) ); + + last->SetNext( aList.first ); + aList.first->SetBack( last ); + last = aList.last; + } + else // this list is empty, first and last are same as aList + { + first = aList.first; + last = aList.last; + } + + count += aList.count; + + aList.count = 0; + aList.first = NULL; + aList.last = NULL; } - else // list is empty, first and last are same as aList - { - first = aList.first; - last = aList.last; - } - - count += aList.count; - - aList.count = 0; - aList.first = NULL; - aList.last = NULL; } diff --git a/common/drawframe.cpp b/common/drawframe.cpp index 3aabc8bd48..3937a02286 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -228,10 +228,10 @@ void EDA_DRAW_FRAME::SkipNextLeftButtonReleaseEvent() void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent ) { SetGridVisibility( !IsGridVisible() ); - if( m_galCanvasActive ) + if( IsGalCanvasActive() ) { - m_galCanvas->GetGAL()->SetGridVisibility( IsGridVisible() ); - m_galCanvas->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); + GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); + GetGalCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); } m_canvas->Refresh(); @@ -387,11 +387,11 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) screen->SetGrid( id ); SetCrossHairPosition( RefPos( true ) ); - if( m_galCanvasActive ) + if( IsGalCanvasActive() ) { - m_galCanvas->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size.x, + GetGalCanvas()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size.x, screen->GetGrid().m_Size.y ) ); - m_galCanvas->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); + GetGalCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); } m_canvas->Refresh(); @@ -422,17 +422,17 @@ void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event ) GetScreen()->SetZoom( selectedZoom ); - if( m_galCanvasActive ) + if( IsGalCanvasActive() ) { // Apply computed view settings to GAL - KIGFX::VIEW* view = m_galCanvas->GetView(); - KIGFX::GAL* gal = m_galCanvas->GetGAL(); + KIGFX::VIEW* view = GetGalCanvas()->GetView(); + KIGFX::GAL* gal = GetGalCanvas()->GetGAL(); double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); double zoom = 1.0 / ( zoomFactor * GetZoom() ); view->SetScale( zoom ); - m_galCanvas->Refresh(); + GetGalCanvas()->Refresh(); } else RedrawScreen( GetScrollCenterPosition(), false ); @@ -954,8 +954,8 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU ) void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) { - KIGFX::VIEW* view = m_galCanvas->GetView(); - KIGFX::GAL* gal = m_galCanvas->GetGAL(); + KIGFX::VIEW* view = GetGalCanvas()->GetView(); + KIGFX::GAL* gal = GetGalCanvas()->GetGAL(); double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); @@ -965,7 +965,7 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) BASE_SCREEN* screen = GetScreen(); // Switch to GAL rendering - if( !m_galCanvasActive ) + if( !IsGalCanvasActive() ) { // Set up viewport double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() ); @@ -981,7 +981,7 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) else { // Switch to standard rendering - if( m_galCanvasActive ) + if( IsGalCanvasActive() ) { // Change view settings only if GAL was active previously double zoom = 1.0 / ( zoomFactor * view->GetScale() ); @@ -993,17 +993,17 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) } m_canvas->SetEvtHandlerEnabled( !aEnable ); - m_galCanvas->SetEvtHandlerEnabled( aEnable ); + GetGalCanvas()->SetEvtHandlerEnabled( aEnable ); // Switch panes m_auimgr.GetPane( wxT( "DrawFrame" ) ).Show( !aEnable ); m_auimgr.GetPane( wxT( "DrawFrameGal" ) ).Show( aEnable ); m_auimgr.Update(); - m_galCanvasActive = aEnable; + SetGalCanvasActive( aEnable ); if( aEnable ) - m_galCanvas->SetFocus(); + GetGalCanvas()->SetFocus(); } //-----< BASE_SCREEN API moved here >-------------------------------------------- diff --git a/common/zoom.cpp b/common/zoom.cpp index f839684ae2..6add6bc2f6 100644 --- a/common/zoom.cpp +++ b/common/zoom.cpp @@ -84,7 +84,7 @@ void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer ) if( screen->m_FirstRedraw ) SetCrossHairPosition( GetScrollCenterPosition() ); - if( !m_galCanvasActive ) + if( !IsGalCanvasActive() ) RedrawScreen( GetScrollCenterPosition(), aWarpPointer ); } @@ -194,18 +194,18 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event ) RedrawScreen( center, true ); } - if( m_galCanvasActive ) + if( IsGalCanvasActive() ) { // Apply computed view settings to GAL - KIGFX::VIEW* view = m_galCanvas->GetView(); - KIGFX::GAL* gal = m_galCanvas->GetGAL(); + KIGFX::VIEW* view = GetGalCanvas()->GetView(); + KIGFX::GAL* gal = GetGalCanvas()->GetGAL(); double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); double zoom = 1.0 / ( zoomFactor * GetZoom() ); view->SetScale( zoom ); view->SetCenter( VECTOR2D( center ) ); - m_galCanvas->Refresh(); + GetGalCanvas()->Refresh(); } UpdateStatusBar(); diff --git a/include/wxstruct.h b/include/wxstruct.h index b26dfeeca2..002b396938 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -390,24 +390,24 @@ class EDA_DRAW_FRAME : public EDA_BASE_FRAME friend class EDA_DRAW_PANEL; ///< Id of active button on the vertical toolbar. - int m_toolId; + int m_toolId; - BASE_SCREEN* m_currentScreen; ///< current used SCREEN - bool m_snapToGrid; ///< Indicates if cursor should be snapped to grid. + BASE_SCREEN* m_currentScreen; ///< current used SCREEN + + bool m_snapToGrid; ///< Indicates if cursor should be snapped to grid. + bool m_galCanvasActive; ///< whether to use new GAL engine + + EDA_DRAW_PANEL_GAL* m_galCanvas; protected: EDA_HOTKEY_CONFIG* m_HotkeysZoomAndGridList; int m_LastGridSizeId; bool m_DrawGrid; // hide/Show grid - bool m_galCanvasActive; // whether to use new GAL engine EDA_COLOR_T m_GridColor; // Grid color /// The area to draw on. EDA_DRAW_PANEL* m_canvas; - /// New type of area (GAL-based) to draw on. - EDA_DRAW_PANEL_GAL* m_galCanvas; - /// Tool ID of previously active draw tool bar button. int m_lastDrawToolId; @@ -979,20 +979,22 @@ public: virtual void UseGalCanvas( bool aEnable ); /** - * Function IsNewCanvasActive + * Function IsGalCanvasActive * is used to check which canvas (GAL-based or standard) is currently in use. * * @return True for GAL-based canvas, false for standard canvas. */ - bool IsGalCanvasActive() { return m_galCanvasActive; } + bool IsGalCanvasActive() const { return m_galCanvasActive; } + void SetGalCanvasActive( bool aState ) { m_galCanvasActive = aState; } /** - * Function GetCalCanvas + * Function GetGalCanvas * returns a pointer to GAL-based canvas of given EDA draw frame. * * @return Pointer to GAL-based canvas. */ - EDA_DRAW_PANEL_GAL* GetGalCanvas() { return m_galCanvas; } + EDA_DRAW_PANEL_GAL* GetGalCanvas() const { return m_galCanvas; } + void SetGalCanvas( EDA_DRAW_PANEL_GAL* aPanel ) { m_galCanvas = aPanel; } DECLARE_EVENT_TABLE() }; diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 7b3f66df58..858aa40c0e 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -152,10 +152,12 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( wxWindow* aParent, ID_DRAWFRAME_TYPE aFrameType, m_FastGrid1 = 0; m_FastGrid2 = 0; - m_galCanvas = new EDA_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize, - EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL ); + SetGalCanvas( new EDA_DRAW_PANEL_GAL( + this, -1, wxPoint( 0, 0 ), m_FrameSize, + EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL ) ); + // Hide by default, it has to be explicitly shown - m_galCanvas->Hide(); + GetGalCanvas()->Hide(); m_auxiliaryToolBar = NULL; } @@ -166,7 +168,7 @@ PCB_BASE_FRAME::~PCB_BASE_FRAME() delete m_Collector; delete m_Pcb; // is already NULL for FOOTPRINT_EDIT_FRAME - delete m_galCanvas; + delete GetGalCanvas(); } @@ -437,11 +439,11 @@ void PCB_BASE_FRAME::OnTogglePadDrawMode( wxCommandEvent& aEvent ) // Apply new display options to the GAL canvas KIGFX::PCB_PAINTER* painter = - static_cast ( m_galCanvas->GetView()->GetPainter() ); + static_cast ( GetGalCanvas()->GetView()->GetPainter() ); KIGFX::PCB_RENDER_SETTINGS* settings = static_cast ( painter->GetSettings() ); settings->LoadDisplayOptions( DisplayOpt ); - m_galCanvas->GetView()->RecacheAllItems( true ); + GetGalCanvas()->GetView()->RecacheAllItems( true ); m_canvas->Refresh(); } @@ -764,7 +766,7 @@ void PCB_BASE_FRAME::LoadSettings() m_DisplayModText = FILLED; // Apply display settings for GAL - KIGFX::VIEW* view = m_galCanvas->GetView(); + KIGFX::VIEW* view = GetGalCanvas()->GetView(); // Set rendering order and properties of layers for( LAYER_NUM i = 0; (unsigned) i < sizeof(GAL_LAYER_ORDER) / sizeof(LAYER_NUM); ++i ) diff --git a/pcbnew/class_pcb_layer_widget.cpp b/pcbnew/class_pcb_layer_widget.cpp index 68811af01d..00dcd3fad4 100644 --- a/pcbnew/class_pcb_layer_widget.cpp +++ b/pcbnew/class_pcb_layer_widget.cpp @@ -404,25 +404,27 @@ void PCB_LAYER_WIDGET::OnLayerVisible( LAYER_NUM aLayer, bool isVisible, bool is myframe->GetCanvas()->Refresh(); } + void PCB_LAYER_WIDGET::OnRenderColorChange( int aId, EDA_COLOR_T aColor ) { myframe->GetBoard()->SetVisibleElementColor( aId, aColor ); myframe->GetCanvas()->Refresh(); } + void PCB_LAYER_WIDGET::OnRenderEnable( int aId, bool isEnabled ) { BOARD* brd = myframe->GetBoard(); brd->SetElementVisibility( aId, isEnabled ); - EDA_DRAW_PANEL_GAL *galCanvas = myframe->GetGalCanvas(); + EDA_DRAW_PANEL_GAL* galCanvas = myframe->GetGalCanvas(); if( galCanvas ) { KIGFX::VIEW* view = galCanvas->GetView(); view->SetLayerVisible( ITEM_GAL_LAYER( aId ), isEnabled ); } - if( myframe->IsGalCanvasActive() ) + if( galCanvas && myframe->IsGalCanvasActive() ) galCanvas->Refresh(); else myframe->GetCanvas()->Refresh(); diff --git a/pcbnew/dialogs/dialog_general_options.cpp b/pcbnew/dialogs/dialog_general_options.cpp index 3470426f2c..237b7b18a1 100644 --- a/pcbnew/dialogs/dialog_general_options.cpp +++ b/pcbnew/dialogs/dialog_general_options.cpp @@ -153,7 +153,7 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) int id = event.GetId(); bool state = event.IsChecked(); KIGFX::PCB_PAINTER* painter = - static_cast ( m_galCanvas->GetView()->GetPainter() ); + static_cast ( GetGalCanvas()->GetView()->GetPainter() ); KIGFX::PCB_RENDER_SETTINGS* settings = static_cast ( painter->GetSettings() ); bool recache = false; @@ -259,9 +259,9 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) { // Apply new display options to the GAL canvas settings->LoadDisplayOptions( DisplayOpt ); - m_galCanvas->GetView()->RecacheAllItems( true ); + GetGalCanvas()->GetView()->RecacheAllItems( true ); } if( IsGalCanvasActive() ) - m_galCanvas->Refresh(); + GetGalCanvas()->Refresh(); } diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 3145afec51..58c1692d31 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -335,14 +335,14 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, SetBoard( new BOARD() ); - if( m_galCanvas ) + if( GetGalCanvas() ) { ViewReloadBoard( m_Pcb ); // update the tool manager with the new board and its view. if( m_toolManager ) - m_toolManager->SetEnvironment( m_Pcb, m_galCanvas->GetView(), - m_galCanvas->GetViewControls(), this ); + m_toolManager->SetEnvironment( m_Pcb, GetGalCanvas()->GetView(), + GetGalCanvas()->GetViewControls(), this ); } // Create the PCB_LAYER_WIDGET *after* SetBoard(): @@ -356,7 +356,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, if( screenHeight <= 900 ) pointSize = (pointSize * 8) / 10; - m_Layers = new PCB_LAYER_WIDGET( this, m_galCanvas, pointSize ); + m_Layers = new PCB_LAYER_WIDGET( this, GetGalCanvas(), pointSize ); m_drc = new DRC( this ); // these 2 objects point to each other @@ -454,8 +454,8 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, m_auimgr.AddPane( m_canvas, wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() ); - if( m_galCanvas ) - m_auimgr.AddPane( (wxWindow*) m_galCanvas, + if( GetGalCanvas() ) + m_auimgr.AddPane( (wxWindow*) GetGalCanvas(), wxAuiPaneInfo().Name( wxT( "DrawFrameGal" ) ).CentrePane().Hide() ); if( m_messagePanel ) @@ -538,21 +538,21 @@ void PCB_EDIT_FRAME::SetBoard( BOARD* aBoard ) { PCB_BASE_FRAME::SetBoard( aBoard ); - if( m_galCanvas ) + if( GetGalCanvas() ) { ViewReloadBoard( aBoard ); // update the tool manager with the new board and its view. if( m_toolManager ) - m_toolManager->SetEnvironment( aBoard, m_galCanvas->GetView(), - m_galCanvas->GetViewControls(), this ); + m_toolManager->SetEnvironment( aBoard, GetGalCanvas()->GetView(), + GetGalCanvas()->GetViewControls(), this ); } } void PCB_EDIT_FRAME::ViewReloadBoard( const BOARD* aBoard ) const { - KIGFX::VIEW* view = m_galCanvas->GetView(); + KIGFX::VIEW* view = GetGalCanvas()->GetView(); view->Clear(); // All of PCB drawing elements should be added to the VIEW @@ -629,8 +629,8 @@ void PCB_EDIT_FRAME::ViewReloadBoard( const BOARD* aBoard ) const view->SetPanBoundary( worksheet->ViewBBox() ); view->RecacheAllItems( true ); - if( m_galCanvasActive ) - m_galCanvas->Refresh(); + if( IsGalCanvasActive() ) + GetGalCanvas()->Refresh(); } @@ -668,7 +668,7 @@ void PCB_EDIT_FRAME::OnQuit( wxCommandEvent& event ) void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) { m_canvas->SetAbortRequest( true ); - m_galCanvas->StopDrawing(); + GetGalCanvas()->StopDrawing(); if( GetScreen()->IsModify() ) { @@ -750,8 +750,8 @@ void PCB_EDIT_FRAME::UseGalCanvas( bool aEnable ) { EDA_DRAW_FRAME::UseGalCanvas( aEnable ); - m_toolManager->SetEnvironment( m_Pcb, m_galCanvas->GetView(), - m_galCanvas->GetViewControls(), this ); + m_toolManager->SetEnvironment( m_Pcb, GetGalCanvas()->GetView(), + GetGalCanvas()->GetViewControls(), this ); ViewReloadBoard( m_Pcb ); } @@ -768,12 +768,12 @@ void PCB_EDIT_FRAME::SwitchCanvas( wxCommandEvent& aEvent ) break; case ID_MENU_CANVAS_CAIRO: - m_galCanvas->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ); + GetGalCanvas()->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ); UseGalCanvas( true ); break; case ID_MENU_CANVAS_OPENGL: - m_galCanvas->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL ); + GetGalCanvas()->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL ); UseGalCanvas( true ); break; } @@ -902,7 +902,7 @@ bool PCB_EDIT_FRAME::IsMicroViaAcceptable( void ) void PCB_EDIT_FRAME::setHighContrastLayer( LAYER_NUM aLayer ) { // Set display settings for high contrast mode - KIGFX::VIEW* view = m_galCanvas->GetView(); + KIGFX::VIEW* view = GetGalCanvas()->GetView(); KIGFX::RENDER_SETTINGS* rSettings = view->GetPainter()->GetSettings(); setTopLayer( aLayer ); @@ -945,7 +945,7 @@ void PCB_EDIT_FRAME::setHighContrastLayer( LAYER_NUM aLayer ) void PCB_EDIT_FRAME::setTopLayer( LAYER_NUM aLayer ) { // Set display settings for high contrast mode - KIGFX::VIEW* view = m_galCanvas->GetView(); + KIGFX::VIEW* view = GetGalCanvas()->GetView(); view->ClearTopLayers(); view->SetTopLayer( aLayer ); @@ -993,8 +993,8 @@ void PCB_EDIT_FRAME::setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate if( doLayerWidgetUpdate ) syncLayerWidgetLayer(); - if( m_galCanvasActive ) - m_galCanvas->Refresh(); + if( IsGalCanvasActive() ) + GetGalCanvas()->Refresh(); } @@ -1015,7 +1015,7 @@ void PCB_EDIT_FRAME::syncLayerVisibilities() { m_Layers->SyncLayerVisibilities(); - KIGFX::VIEW* view = m_galCanvas->GetView(); + KIGFX::VIEW* view = GetGalCanvas()->GetView(); // Load layer & elements visibility settings for( LAYER_NUM i = 0; i < NB_LAYERS; ++i ) { diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index f3749a0c94..e8e0568587 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -44,7 +44,7 @@ void PCB_EDIT_FRAME::setupTools() // Create the manager and dispatcher & route draw panel events to the dispatcher m_toolManager = new TOOL_MANAGER; m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, this ); - m_galCanvas->SetEventDispatcher( m_toolDispatcher ); + GetGalCanvas()->SetEventDispatcher( m_toolDispatcher ); // Register tool actions m_toolManager->RegisterAction( &COMMON_ACTIONS::moveActivate );