Commit bd52f006 authored by Henner Zeller's avatar Henner Zeller Committed by Wayne Stambaugh

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.
parent 34ad6389
......@@ -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
}
......
......@@ -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.
......
......@@ -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 );
}
......
......@@ -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 */
......@@ -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 );
}
......@@ -392,7 +392,7 @@
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND | wxALL</property>
<property name="proportion">1</property>
<property name="proportion">2</property>
<object class="wxPanel" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
......@@ -426,7 +426,7 @@
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">100,100</property>
<property name="minimum_size">150,150</property>
<property name="moveable">1</property>
<property name="name">m_componentView</property>
<property name="pane_border">1</property>
......@@ -443,7 +443,7 @@
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxTAB_TRAVERSAL</property>
<property name="window_style">wxFULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER</property>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
......@@ -453,14 +453,14 @@
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnLeftUp">OnStartComponentBrowser</event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnPaint">OnHandlePreviewRepaint</event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
......@@ -472,7 +472,7 @@
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">2</property>
<property name="proportion">3</property>
<object class="wxTextCtrl" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
......
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment