From bd52f006015f7381cd7fcf60f1a47a3fdf0c9343 Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Wed, 19 Feb 2014 11:44:48 -0500 Subject: [PATCH] Eeschema: component selection dialog improvements. * Improve component chooser redraw to fit in wxWidgets redraw strategies. * Use LIB_COMPONENT::Draw and LIB_COMPONENT::GetBoundingBox for drawing the component * Make resize redrawing work properly. --- eeschema/class_libentry.cpp | 11 ++--- eeschema/class_libentry.h | 2 +- eeschema/dialogs/dialog_choose_component.cpp | 41 +++---------------- eeschema/dialogs/dialog_choose_component.h | 1 - .../dialogs/dialog_choose_component_base.cpp | 12 ++++-- .../dialogs/dialog_choose_component_base.fbp | 12 +++--- .../dialogs/dialog_choose_component_base.h | 2 + 7 files changed, 28 insertions(+), 53 deletions(-) diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 489114efb8..4b2dcee8a9 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -286,7 +286,7 @@ void LIB_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOff int aConvert, GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor, const TRANSFORM& aTransform, bool aShowPinText, bool aDrawFields, bool aOnlySelected ) { - BASE_SCREEN* screen = aPanel->GetScreen(); + BASE_SCREEN* screen = aPanel ? aPanel->GetScreen() : NULL; GRSetDrawMode( aDc, aDrawMode ); @@ -296,7 +296,7 @@ void LIB_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOff * printing in black and white * If the color is not the default color (aColor != -1 ) */ - if( ! (screen->m_IsPrinting && GetGRForceBlackPenState()) + if( ! (screen && screen->m_IsPrinting && GetGRForceBlackPenState()) && (aColor == UNSPECIFIED_COLOR) ) { BOOST_FOREACH( LIB_ITEM& drawItem, drawings ) @@ -372,10 +372,11 @@ void LIB_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOff // Enable this to draw the anchor of the component. #if 0 int len = aDc->DeviceToLogicalXRel( 3 ); + EDA_RECT* const clipbox = aPanel ? aPanel->GetClipBox() : NULL; - GRLine( aPanel->GetClipBox(), aDc, aOffset.x, aOffset.y - len, aOffset.x, + GRLine( clipbox, aDc, aOffset.x, aOffset.y - len, aOffset.x, aOffset.y + len, 0, aColor ); - GRLine( aPanel->GetClipBox(), aDc, aOffset.x - len, aOffset.y, aOffset.x + len, + GRLine( clipbox, aDc, aOffset.x - len, aOffset.y, aOffset.x + len, aOffset.y, 0, aColor ); #endif @@ -383,7 +384,7 @@ void LIB_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOff * the bounding box calculations. */ #if 0 EDA_RECT bBox = GetBoundingBox( aMulti, aConvert ); - GRRect( aPanel->GetClipBox(), aDc, bBox.GetOrigin().x, bBox.GetOrigin().y, + GRRect( aPanel ? aPanel->GetClipBox() : NULL, aDc, bBox.GetOrigin().x, bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA ); #endif } diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index 695102bc20..43fb8ccc45 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -403,7 +403,7 @@ public: /** * Draw component. * - * @param aPanel - Window to draw on. + * @param aPanel - Window to draw on. Can be NULL if not available. * @param aDc - Device context to draw on. * @param aOffset - Position to component. * @param aMulti - Component unit if multiple parts per component. diff --git a/eeschema/dialogs/dialog_choose_component.cpp b/eeschema/dialogs/dialog_choose_component.cpp index 104e570d7e..1039acf1f6 100644 --- a/eeschema/dialogs/dialog_choose_component.cpp +++ b/eeschema/dialogs/dialog_choose_component.cpp @@ -42,22 +42,11 @@ DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( wxWindow* aParent, const wxStr m_search_container( aContainer ), m_deMorganConvert( aDeMorganConvert >= 0 ? aDeMorganConvert : 0 ), m_external_browser_requested( false ), - m_received_doubleclick_in_tree( false ), - m_ready_to_render( false ) + m_received_doubleclick_in_tree( false ) { m_search_container->SetTree( m_libraryComponentTree ); m_searchBox->SetFocus(); m_componentDetails->SetEditable( false ); - m_componentView - ->Connect( wxEVT_PAINT, - wxPaintEventHandler( DIALOG_CHOOSE_COMPONENT::OnHandlePreviewRepaint ), - NULL, this ); - m_componentView - ->Connect( wxEVT_LEFT_UP, - wxMouseEventHandler( DIALOG_CHOOSE_COMPONENT::OnStartComponentBrowser ), - NULL, this ); - - m_ready_to_render = true; // Only after setup, we accept drawing updates. } @@ -176,7 +165,7 @@ bool DIALOG_CHOOSE_COMPONENT::updateSelection() int unit = 0; LIB_ALIAS* selection = m_search_container->GetSelectedAlias( &unit ); - renderPreview( selection ? selection->GetComponent() : NULL, unit ); + m_componentView->Refresh(); m_componentDetails->Clear(); @@ -234,9 +223,6 @@ void DIALOG_CHOOSE_COMPONENT::OnHandlePreviewRepaint( wxPaintEvent& aRepaintEven // probably have a derived class from wxPanel; but this keeps things local. void DIALOG_CHOOSE_COMPONENT::renderPreview( LIB_COMPONENT* aComponent, int aUnit ) { - if( !m_ready_to_render ) - return; - wxPaintDC dc( m_componentView ); dc.SetBackground( *wxWHITE_BRUSH ); dc.Clear(); @@ -251,16 +237,7 @@ void DIALOG_CHOOSE_COMPONENT::renderPreview( LIB_COMPONENT* aComponent, int aUni dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 ); // Find joint bounding box for everything we are about to draw. - EDA_RECT bBox; - - BOOST_FOREACH( LIB_ITEM& item, aComponent->GetDrawItemList() ) - { - if( ( item.GetUnit() && item.GetUnit() != aUnit ) - || ( item.GetConvert() && item.GetConvert() != m_deMorganConvert ) ) - continue; - bBox.Merge( item.GetBoundingBox() ); - } - + EDA_RECT bBox = aComponent->GetBoundingBox( aUnit, m_deMorganConvert ); const double xscale = (double) dc_size.x / bBox.GetWidth(); const double yscale = (double) dc_size.y / bBox.GetHeight(); const double scale = std::min( xscale, yscale ) * 0.85; @@ -271,16 +248,8 @@ void DIALOG_CHOOSE_COMPONENT::renderPreview( LIB_COMPONENT* aComponent, int aUni NEGATE( offset.x ); NEGATE( offset.y ); - GRResetPenAndBrush( &dc ); - - BOOST_FOREACH( LIB_ITEM& item, aComponent->GetDrawItemList() ) - { - if( ( item.GetUnit() && item.GetUnit() != aUnit ) - || ( item.GetConvert() && item.GetConvert() != m_deMorganConvert ) ) - continue; - item.Draw( NULL, &dc, offset, UNSPECIFIED_COLOR, GR_COPY, - NULL, DefaultTransform ); - } + aComponent->Draw( NULL, &dc, offset, aUnit, m_deMorganConvert, GR_COPY, + UNSPECIFIED_COLOR, DefaultTransform, true, true, false ); } diff --git a/eeschema/dialogs/dialog_choose_component.h b/eeschema/dialogs/dialog_choose_component.h index ec945a2c15..b2e3a0903f 100644 --- a/eeschema/dialogs/dialog_choose_component.h +++ b/eeschema/dialogs/dialog_choose_component.h @@ -72,7 +72,6 @@ private: const int m_deMorganConvert; bool m_external_browser_requested; bool m_received_doubleclick_in_tree; - bool m_ready_to_render; }; #endif /* DIALOG_CHOOSE_COMPONENT_H */ diff --git a/eeschema/dialogs/dialog_choose_component_base.cpp b/eeschema/dialogs/dialog_choose_component_base.cpp index 3ce1599591..d144d06f6b 100644 --- a/eeschema/dialogs/dialog_choose_component_base.cpp +++ b/eeschema/dialogs/dialog_choose_component_base.cpp @@ -37,15 +37,15 @@ DIALOG_CHOOSE_COMPONENT_BASE::DIALOG_CHOOSE_COMPONENT_BASE( wxWindow* parent, wx wxBoxSizer* bSizer3; bSizer3 = new wxBoxSizer( wxHORIZONTAL ); - m_componentView = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - m_componentView->SetMinSize( wxSize( 100,100 ) ); + m_componentView = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER ); + m_componentView->SetMinSize( wxSize( 150,150 ) ); - bSizer3->Add( m_componentView, 1, wxEXPAND | wxALL, 5 ); + bSizer3->Add( m_componentView, 2, wxEXPAND | wxALL, 5 ); m_componentDetails = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( -1,-1 ), wxTE_MULTILINE ); m_componentDetails->SetMinSize( wxSize( -1,100 ) ); - bSizer3->Add( m_componentDetails, 2, wxALL|wxEXPAND, 5 ); + bSizer3->Add( m_componentDetails, 3, wxALL|wxEXPAND, 5 ); bSizer1->Add( bSizer3, 1, wxEXPAND, 5 ); @@ -78,6 +78,8 @@ DIALOG_CHOOSE_COMPONENT_BASE::DIALOG_CHOOSE_COMPONENT_BASE( wxWindow* parent, wx m_libraryComponentTree->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnTreeMouseUp ), NULL, this ); m_libraryComponentTree->Connect( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnDoubleClickTreeSelect ), NULL, this ); m_libraryComponentTree->Connect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnTreeSelect ), NULL, this ); + m_componentView->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnStartComponentBrowser ), NULL, this ); + m_componentView->Connect( wxEVT_PAINT, wxPaintEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnHandlePreviewRepaint ), NULL, this ); } DIALOG_CHOOSE_COMPONENT_BASE::~DIALOG_CHOOSE_COMPONENT_BASE() @@ -89,5 +91,7 @@ DIALOG_CHOOSE_COMPONENT_BASE::~DIALOG_CHOOSE_COMPONENT_BASE() m_libraryComponentTree->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnTreeMouseUp ), NULL, this ); m_libraryComponentTree->Disconnect( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnDoubleClickTreeSelect ), NULL, this ); m_libraryComponentTree->Disconnect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnTreeSelect ), NULL, this ); + m_componentView->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnStartComponentBrowser ), NULL, this ); + m_componentView->Disconnect( wxEVT_PAINT, wxPaintEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnHandlePreviewRepaint ), NULL, this ); } diff --git a/eeschema/dialogs/dialog_choose_component_base.fbp b/eeschema/dialogs/dialog_choose_component_base.fbp index b87834f800..3c6686e101 100644 --- a/eeschema/dialogs/dialog_choose_component_base.fbp +++ b/eeschema/dialogs/dialog_choose_component_base.fbp @@ -392,7 +392,7 @@ 5 wxEXPAND | wxALL - 1 + 2 1 1 @@ -426,7 +426,7 @@ 0 - 100,100 + 150,150 1 m_componentView 1 @@ -443,7 +443,7 @@ - wxTAB_TRAVERSAL + wxFULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER @@ -453,14 +453,14 @@ - + OnStartComponentBrowser - + OnHandlePreviewRepaint @@ -472,7 +472,7 @@ 5 wxALL|wxEXPAND - 2 + 3 1 1 diff --git a/eeschema/dialogs/dialog_choose_component_base.h b/eeschema/dialogs/dialog_choose_component_base.h index 04c73b101f..d135de8a3a 100644 --- a/eeschema/dialogs/dialog_choose_component_base.h +++ b/eeschema/dialogs/dialog_choose_component_base.h @@ -53,6 +53,8 @@ class DIALOG_CHOOSE_COMPONENT_BASE : public DIALOG_SHIM virtual void OnTreeMouseUp( wxMouseEvent& event ) { event.Skip(); } virtual void OnDoubleClickTreeSelect( wxTreeEvent& event ) { event.Skip(); } virtual void OnTreeSelect( wxTreeEvent& event ) { event.Skip(); } + virtual void OnStartComponentBrowser( wxMouseEvent& event ) { event.Skip(); } + virtual void OnHandlePreviewRepaint( wxPaintEvent& event ) { event.Skip(); } public: