← Back to team overview

kicad-developers team mailing list archive

[PATCH] Rework GERBVIEW_FRAME::ReCreateAuxiliaryToolbar to fix layout issues

 

Fix for the minor part of https://bugs.launchpad.net/kicad/+bug/1745203

The X2 attribute highlight dropdowns weren't getting re-created properly
and so there were layout glitches when loading files that have them.
wxAuiToolBar is kind of annoying...

Note that I'm going to keep this launchpad bug set to confirmed even with
this patch, because the bigger part of the bug is tracking slow GerbView
performance when loading very complicated files.

-Jon
From d00cebddc51b4deb9d41943d4df048aa8301e2d5 Mon Sep 17 00:00:00 2001
From: Jon Evans <jon@xxxxxxxxxxxxx>
Date: Sun, 28 Jan 2018 20:30:43 -0500
Subject: [PATCH] Rework GERBVIEW_FRAME::ReCreateAuxiliaryToolbar to fix layout
 issues

Fixes: lp:1745203
* https://bugs.launchpad.net/kicad/+bug/1745203
---
 gerbview/gerbview_frame.cpp  |   7 ++-
 gerbview/toolbars_gerber.cpp | 111 ++++++++++++++++++++++---------------------
 2 files changed, 61 insertions(+), 57 deletions(-)

diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp
index 4de5d109d..395721db0 100644
--- a/gerbview/gerbview_frame.cpp
+++ b/gerbview/gerbview_frame.cpp
@@ -86,6 +86,9 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ):
     m_hotkeysDescrList = GerbviewHokeysDescr;
     m_SelLayerBox   = NULL;
     m_DCodeSelector = NULL;
+    m_SelComponentBox = nullptr;
+    m_SelNetnameBox = nullptr;
+    m_SelAperAttributesBox = nullptr;
     m_displayMode   = 0;
     m_drillFileHistory.SetBaseId( ID_GERBVIEW_DRILL_FILE1 );
     m_zipFileHistory.SetBaseId( ID_GERBVIEW_ZIP_FILE1 );
@@ -137,13 +140,13 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ):
         m_LastGridSizeId = ID_POPUP_GRID_LEVEL_0_0_1MM-ID_POPUP_GRID_LEVEL_1000;
     GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId  );
 
+    m_auimgr.SetManagedWindow( this );
+
     ReCreateMenuBar();
     ReCreateHToolbar();
     ReCreateOptToolbar();
     ReCreateAuxiliaryToolbar();
 
-    m_auimgr.SetManagedWindow( this );
-
     EDA_PANEINFO    horiz;
     horiz.HorizontalToolbarPane();
 
diff --git a/gerbview/toolbars_gerber.cpp b/gerbview/toolbars_gerber.cpp
index ee40aa857..2c0d48b20 100644
--- a/gerbview/toolbars_gerber.cpp
+++ b/gerbview/toolbars_gerber.cpp
@@ -108,80 +108,81 @@ void GERBVIEW_FRAME::ReCreateHToolbar( void )
 void GERBVIEW_FRAME::ReCreateAuxiliaryToolbar()
 {
     wxWindowUpdateLocker dummy( this );
+    wxStaticText* text;
 
-#if 0
-    if( m_auxiliaryToolBar )
+    if( !m_auxiliaryToolBar )
+        m_auxiliaryToolBar = new wxAuiToolBar( this, ID_AUX_TOOLBAR, wxDefaultPosition, wxDefaultSize,
+                                               KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
+
+    // Creates box to display and choose components:
+    if( !m_SelComponentBox )
     {
-        updateComponentListSelectBox();
-        updateNetnameListSelectBox();
-        updateAperAttributesSelectBox();
-        updateDCodeSelectBox();
-
-        // combobox sizes can have changed: apply new best sizes
-        wxSize size;
-        size = m_SelComponentBox->GetBestSize();
-        size.x = std::max( size.x, 100 );
-        m_SelComponentBox->SetMinSize( size );
+        m_SelComponentBox = new wxChoice( m_auxiliaryToolBar,
+                                          ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE );
+        m_SelComponentBox->SetToolTip( _("Select a component and highlight items belonging to this component") );
+    }
 
-        size = m_SelNetnameBox->GetBestSize();
-        size.x = std::max( size.x, 100 );
-        m_SelNetnameBox->SetMinSize( size );
+    // Creates choice box to display net names and highlight selected:
+    if( !m_SelNetnameBox )
+    {
+        m_SelNetnameBox = new wxChoice( m_auxiliaryToolBar,
+                                        ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE );
+        m_SelNetnameBox->SetToolTip( _("Select a net name and highlight graphic items belonging to this net") );
+    }
 
-        size = m_SelAperAttributesBox->GetBestSize();
-        size.x = std::max( size.x, 100 );
-        m_SelAperAttributesBox->SetMinSize( size );
+    // Creates choice box to display aperture attributes and highlight selected:
+    if( !m_SelAperAttributesBox )
+    {
+        m_SelAperAttributesBox = new wxChoice( m_auxiliaryToolBar,
+                                          ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE );
+        m_SelAperAttributesBox->SetToolTip( _("Select an aperture attribute and highlight graphic items having this attribute") );
+    }
 
-        size = m_DCodeSelector->GetBestSize();
-        size.x = std::max( size.x, 100 );
-        m_DCodeSelector->SetMinSize( size );
+    if( !m_DCodeSelector )
+    {
+        m_DCodeSelector = new DCODE_SELECTION_BOX( m_auxiliaryToolBar,
+                                                   ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE,
+                                                   wxDefaultPosition, wxSize( 150, -1 ) );
+    }
 
-        m_auimgr.Update();
-        return;
+    updateComponentListSelectBox();
+    updateNetnameListSelectBox();
+    updateAperAttributesSelectBox();
+    updateDCodeSelectBox();
+
+    // combobox sizes can have changed: apply new best sizes
+    m_SelComponentBox->SetMinSize( m_SelComponentBox->GetBestSize() );
+    m_SelNetnameBox->SetMinSize( m_SelNetnameBox->GetBestSize() );
+    m_SelAperAttributesBox->SetMinSize( m_SelAperAttributesBox->GetBestSize() );
+
+    // Because wxAuiToolBar doesn't actually clear things properly...
+    for( unsigned i = 0; i < m_auxiliaryToolBar->GetToolCount(); ++i )
+    {
+        auto item = m_auxiliaryToolBar->FindToolByIndex( i );
+        auto control = dynamic_cast<wxStaticText*>( item->GetWindow() );
+
+        if( control )
+        {
+            delete control;
+        }
     }
-#endif
 
-    if( m_auxiliaryToolBar )
-        m_auxiliaryToolBar->Clear();
-    else
-        m_auxiliaryToolBar = new wxAuiToolBar( this, ID_AUX_TOOLBAR, wxDefaultPosition, wxDefaultSize,
-                                               KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
+    m_auxiliaryToolBar->Clear();
 
-    // Creates box to display and choose components:
-    wxStaticText* text = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _("Cmp:") );
+    text = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _("Cmp:") );
     m_auxiliaryToolBar->AddControl( text );
-    m_SelComponentBox = new wxChoice( m_auxiliaryToolBar,
-                                      ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE );
-    m_SelComponentBox->SetToolTip( _("Select a component and highlight items belonging to this component") );
-    updateComponentListSelectBox();
     m_auxiliaryToolBar->AddControl( m_SelComponentBox );
-    KiScaledSeparator( m_mainToolBar, this );
-
-    // Creates choice box to display net names and highlight selected:
+    KiScaledSeparator( m_auxiliaryToolBar, this );
     text = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _("Net:") );
     m_auxiliaryToolBar->AddControl( text );
-    m_SelNetnameBox = new wxChoice( m_auxiliaryToolBar,
-                                    ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE );
-    m_SelNetnameBox->SetToolTip( _("Select a net name and highlight graphic items belonging to this net") );
     m_auxiliaryToolBar->AddControl( m_SelNetnameBox );
-    updateNetnameListSelectBox();
-    KiScaledSeparator( m_mainToolBar, this );
-
-    // Creates choice box to display aperture attributes and highlight selected:
+    KiScaledSeparator( m_auxiliaryToolBar, this );
     text = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _("Attr:") );
     m_auxiliaryToolBar->AddControl( text );
-    m_SelAperAttributesBox = new wxChoice( m_auxiliaryToolBar,
-                                      ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE );
-    m_SelAperAttributesBox->SetToolTip( _("Select an aperture attribute and highlight graphic items having this attribute") );
     m_auxiliaryToolBar->AddControl( m_SelAperAttributesBox );
-    updateAperAttributesSelectBox();
-
-    KiScaledSeparator( m_mainToolBar, this );
+    KiScaledSeparator( m_auxiliaryToolBar, this );
     text = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _("DCode:") );
     m_auxiliaryToolBar->AddControl( text );
-    m_DCodeSelector = new DCODE_SELECTION_BOX( m_auxiliaryToolBar,
-                                               ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE,
-                                               wxDefaultPosition, wxSize( 150, -1 ) );
-    updateDCodeSelectBox();
     m_auxiliaryToolBar->AddControl( m_DCodeSelector );
 
     // after adding the buttons to the toolbar, must call Realize()
-- 
2.14.1


Follow ups