Move symbol chooser dialog preview to GAL.
This commit is contained in:
parent
8e915ae8d8
commit
7cbfa08ddd
|
@ -90,6 +90,7 @@ set( EESCHEMA_DLGS
|
||||||
set( EESCHEMA_WIDGETS
|
set( EESCHEMA_WIDGETS
|
||||||
widgets/pin_shape_combobox.cpp
|
widgets/pin_shape_combobox.cpp
|
||||||
widgets/pin_type_combobox.cpp
|
widgets/pin_type_combobox.cpp
|
||||||
|
widgets/symbol_preview_widget.cpp
|
||||||
widgets/symbol_tree_pane.cpp
|
widgets/symbol_tree_pane.cpp
|
||||||
widgets/widget_eeschema_color_config.cpp
|
widgets/widget_eeschema_color_config.cpp
|
||||||
)
|
)
|
||||||
|
@ -193,6 +194,7 @@ set( EESCHEMA_SRCS
|
||||||
sch_marker.cpp
|
sch_marker.cpp
|
||||||
sch_no_connect.cpp
|
sch_no_connect.cpp
|
||||||
sch_plugin.cpp
|
sch_plugin.cpp
|
||||||
|
sch_preview_panel.cpp
|
||||||
sch_screen.cpp
|
sch_screen.cpp
|
||||||
sch_sheet.cpp
|
sch_sheet.cpp
|
||||||
sch_sheet_path.cpp
|
sch_sheet_path.cpp
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include <widgets/lib_tree.h>
|
#include <widgets/lib_tree.h>
|
||||||
#include <widgets/footprint_preview_widget.h>
|
#include <widgets/footprint_preview_widget.h>
|
||||||
#include <widgets/footprint_select_widget.h>
|
#include <widgets/footprint_select_widget.h>
|
||||||
|
#include <widgets/symbol_preview_widget.h>
|
||||||
|
|
||||||
|
|
||||||
wxSize DIALOG_CHOOSE_COMPONENT::m_last_dlg_size( -1, -1 );
|
wxSize DIALOG_CHOOSE_COMPONENT::m_last_dlg_size( -1, -1 );
|
||||||
|
@ -145,7 +146,6 @@ DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const
|
||||||
Bind( wxEVT_TIMER, &DIALOG_CHOOSE_COMPONENT::OnCloseTimer, this, m_dbl_click_timer->GetId() );
|
Bind( wxEVT_TIMER, &DIALOG_CHOOSE_COMPONENT::OnCloseTimer, this, m_dbl_click_timer->GetId() );
|
||||||
Bind( COMPONENT_PRESELECTED, &DIALOG_CHOOSE_COMPONENT::OnComponentPreselected, this );
|
Bind( COMPONENT_PRESELECTED, &DIALOG_CHOOSE_COMPONENT::OnComponentPreselected, this );
|
||||||
Bind( COMPONENT_SELECTED, &DIALOG_CHOOSE_COMPONENT::OnComponentSelected, this );
|
Bind( COMPONENT_SELECTED, &DIALOG_CHOOSE_COMPONENT::OnComponentSelected, this );
|
||||||
m_symbol_preview->Bind( wxEVT_PAINT, &DIALOG_CHOOSE_COMPONENT::OnSymbolPreviewPaint, this );
|
|
||||||
|
|
||||||
if( m_browser_button )
|
if( m_browser_button )
|
||||||
m_browser_button->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
|
m_browser_button->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
|
||||||
|
@ -180,7 +180,6 @@ DIALOG_CHOOSE_COMPONENT::~DIALOG_CHOOSE_COMPONENT()
|
||||||
Unbind( wxEVT_TIMER, &DIALOG_CHOOSE_COMPONENT::OnCloseTimer, this );
|
Unbind( wxEVT_TIMER, &DIALOG_CHOOSE_COMPONENT::OnCloseTimer, this );
|
||||||
Unbind( COMPONENT_PRESELECTED, &DIALOG_CHOOSE_COMPONENT::OnComponentPreselected, this );
|
Unbind( COMPONENT_PRESELECTED, &DIALOG_CHOOSE_COMPONENT::OnComponentPreselected, this );
|
||||||
Unbind( COMPONENT_SELECTED, &DIALOG_CHOOSE_COMPONENT::OnComponentSelected, this );
|
Unbind( COMPONENT_SELECTED, &DIALOG_CHOOSE_COMPONENT::OnComponentSelected, this );
|
||||||
m_symbol_preview->Unbind( wxEVT_PAINT, &DIALOG_CHOOSE_COMPONENT::OnSymbolPreviewPaint, this );
|
|
||||||
|
|
||||||
if( m_browser_button )
|
if( m_browser_button )
|
||||||
m_browser_button->Unbind( wxEVT_COMMAND_BUTTON_CLICKED,
|
m_browser_button->Unbind( wxEVT_COMMAND_BUTTON_CLICKED,
|
||||||
|
@ -208,8 +207,7 @@ wxPanel* DIALOG_CHOOSE_COMPONENT::ConstructRightPanel( wxWindow* aParent )
|
||||||
auto panel = new wxPanel( aParent );
|
auto panel = new wxPanel( aParent );
|
||||||
auto sizer = new wxBoxSizer( wxVERTICAL );
|
auto sizer = new wxBoxSizer( wxVERTICAL );
|
||||||
|
|
||||||
m_symbol_preview = new wxPanel( panel, wxID_ANY, wxDefaultPosition, wxSize( -1, -1 ),
|
m_symbol_preview = new SYMBOL_PREVIEW_WIDGET( panel, Kiway() );
|
||||||
wxFULL_REPAINT_ON_RESIZE | wxTAB_TRAVERSAL );
|
|
||||||
m_symbol_preview->SetLayoutDirection( wxLayout_LeftToRight );
|
m_symbol_preview->SetLayoutDirection( wxLayout_LeftToRight );
|
||||||
|
|
||||||
if( m_show_footprints )
|
if( m_show_footprints )
|
||||||
|
@ -302,8 +300,7 @@ void DIALOG_CHOOSE_COMPONENT::ShowFootprintFor( LIB_ID const& aLibId )
|
||||||
}
|
}
|
||||||
catch( const IO_ERROR& ioe )
|
catch( const IO_ERROR& ioe )
|
||||||
{
|
{
|
||||||
wxLogError( wxString::Format( _( "Error occurred loading symbol %s from library %s."
|
wxLogError( wxString::Format( _( "Error loading symbol %s from library %s.\n\n%s" ),
|
||||||
"\n\n%s" ),
|
|
||||||
aLibId.GetLibItemName().wx_str(),
|
aLibId.GetLibItemName().wx_str(),
|
||||||
aLibId.GetLibNickname().wx_str(),
|
aLibId.GetLibNickname().wx_str(),
|
||||||
ioe.What() ) );
|
ioe.What() ) );
|
||||||
|
@ -393,63 +390,6 @@ void DIALOG_CHOOSE_COMPONENT::PopulateFootprintSelector( LIB_ID const& aLibId )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DIALOG_CHOOSE_COMPONENT::OnSymbolPreviewPaint( wxPaintEvent& aEvent )
|
|
||||||
{
|
|
||||||
int unit = 0;
|
|
||||||
LIB_ID id = m_tree->GetSelectedLibId( &unit );
|
|
||||||
|
|
||||||
if( !id.IsValid() )
|
|
||||||
{
|
|
||||||
// No symbol to show, display a tooltip
|
|
||||||
RenderPreview( nullptr, unit );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LIB_ALIAS* alias = nullptr;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
alias = Prj().SchSymbolLibTable()->LoadSymbol( id );
|
|
||||||
}
|
|
||||||
catch( const IO_ERROR& ioe )
|
|
||||||
{
|
|
||||||
wxLogError( wxString::Format( _( "Error occurred loading symbol %s from library %s."
|
|
||||||
"\n\n%s" ),
|
|
||||||
id.GetLibItemName().wx_str(),
|
|
||||||
id.GetLibNickname().wx_str(),
|
|
||||||
ioe.What() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !alias )
|
|
||||||
return;
|
|
||||||
|
|
||||||
LIB_PART* part = alias->GetPart();
|
|
||||||
|
|
||||||
// Don't draw if we don't have a part to show, just display a tooltip
|
|
||||||
if( !part )
|
|
||||||
{
|
|
||||||
RenderPreview( nullptr, unit );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( alias->IsRoot() )
|
|
||||||
{
|
|
||||||
// just show the part directly
|
|
||||||
RenderPreview( part, unit );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// switch out the name temporarily for the alias name
|
|
||||||
wxString tmp( part->GetName() );
|
|
||||||
part->SetName( alias->GetName() );
|
|
||||||
|
|
||||||
RenderPreview( part, unit );
|
|
||||||
|
|
||||||
part->SetName( tmp );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DIALOG_CHOOSE_COMPONENT::OnFootprintSelected( wxCommandEvent& aEvent )
|
void DIALOG_CHOOSE_COMPONENT::OnFootprintSelected( wxCommandEvent& aEvent )
|
||||||
{
|
{
|
||||||
m_fp_override = aEvent.GetString();
|
m_fp_override = aEvent.GetString();
|
||||||
|
@ -471,15 +411,18 @@ void DIALOG_CHOOSE_COMPONENT::OnComponentPreselected( wxCommandEvent& aEvent )
|
||||||
|
|
||||||
LIB_ID id = m_tree->GetSelectedLibId( &unit );
|
LIB_ID id = m_tree->GetSelectedLibId( &unit );
|
||||||
|
|
||||||
m_symbol_preview->Refresh();
|
|
||||||
|
|
||||||
if( id.IsValid() )
|
if( id.IsValid() )
|
||||||
{
|
{
|
||||||
|
m_symbol_preview->DisplaySymbol( id, unit );
|
||||||
|
|
||||||
ShowFootprintFor( id );
|
ShowFootprintFor( id );
|
||||||
PopulateFootprintSelector( id );
|
PopulateFootprintSelector( id );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
m_symbol_preview->SetStatusText( _( "No symbol selected" ) );
|
||||||
|
|
||||||
if( m_fp_preview && m_fp_preview->IsInitialized() )
|
if( m_fp_preview && m_fp_preview->IsInitialized() )
|
||||||
m_fp_preview->SetStatusText( wxEmptyString );
|
m_fp_preview->SetStatusText( wxEmptyString );
|
||||||
|
|
||||||
|
@ -509,46 +452,3 @@ void DIALOG_CHOOSE_COMPONENT::OnComponentSelected( wxCommandEvent& aEvent )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DIALOG_CHOOSE_COMPONENT::RenderPreview( LIB_PART* aComponent, int aUnit )
|
|
||||||
{
|
|
||||||
wxPaintDC dc( m_symbol_preview );
|
|
||||||
|
|
||||||
const wxSize dc_size = dc.GetSize();
|
|
||||||
|
|
||||||
// Avoid rendering when either dimension is zero
|
|
||||||
if( dc_size.x == 0 || dc_size.y == 0 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
GRResetPenAndBrush( &dc );
|
|
||||||
|
|
||||||
COLOR4D bgColor = m_parent->GetDrawBgColor();
|
|
||||||
|
|
||||||
dc.SetBackground( wxBrush( bgColor.ToColour() ) );
|
|
||||||
dc.Clear();
|
|
||||||
|
|
||||||
if( !aComponent ) // display a tooltip
|
|
||||||
{
|
|
||||||
wxString tooltip = _( "No symbol selected" );
|
|
||||||
GRDrawWrappedText( dc, tooltip );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int unit = aUnit > 0 ? aUnit : 1;
|
|
||||||
int convert = m_deMorganConvert > 0 ? m_deMorganConvert : 1;
|
|
||||||
|
|
||||||
dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 );
|
|
||||||
|
|
||||||
// Find joint bounding box for everything we are about to draw.
|
|
||||||
EDA_RECT bBox = aComponent->GetUnitBoundingBox( unit, convert );
|
|
||||||
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;
|
|
||||||
|
|
||||||
dc.SetUserScale( scale, scale );
|
|
||||||
|
|
||||||
wxPoint offset = -bBox.Centre();
|
|
||||||
|
|
||||||
auto opts = PART_DRAW_OPTIONS::Default();
|
|
||||||
opts.draw_hidden_fields = false;
|
|
||||||
aComponent->Draw( nullptr, &dc, offset, unit, convert, opts );
|
|
||||||
}
|
|
||||||
|
|
|
@ -40,11 +40,13 @@ class wxButton;
|
||||||
class wxTimer;
|
class wxTimer;
|
||||||
|
|
||||||
class LIB_TREE;
|
class LIB_TREE;
|
||||||
|
class SYMBOL_PREVIEW_WIDGET;
|
||||||
class FOOTPRINT_PREVIEW_WIDGET;
|
class FOOTPRINT_PREVIEW_WIDGET;
|
||||||
class FOOTPRINT_SELECT_WIDGET;
|
class FOOTPRINT_SELECT_WIDGET;
|
||||||
class LIB_ALIAS;
|
class LIB_ALIAS;
|
||||||
class LIB_PART;
|
class LIB_PART;
|
||||||
class SCH_BASE_FRAME;
|
class SCH_BASE_FRAME;
|
||||||
|
class SCH_DRAW_PANEL;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -152,8 +154,6 @@ protected:
|
||||||
void OnCloseTimer( wxTimerEvent& aEvent );
|
void OnCloseTimer( wxTimerEvent& aEvent );
|
||||||
void OnUseBrowser( wxCommandEvent& aEvent );
|
void OnUseBrowser( wxCommandEvent& aEvent );
|
||||||
|
|
||||||
void OnSymbolPreviewPaint( wxPaintEvent& aEvent );
|
|
||||||
|
|
||||||
void OnFootprintSelected( wxCommandEvent& aEvent );
|
void OnFootprintSelected( wxCommandEvent& aEvent );
|
||||||
void OnComponentPreselected( wxCommandEvent& aEvent );
|
void OnComponentPreselected( wxCommandEvent& aEvent );
|
||||||
|
|
||||||
|
@ -189,14 +189,14 @@ protected:
|
||||||
void RenderPreview( LIB_PART* aComponent, int aUnit );
|
void RenderPreview( LIB_PART* aComponent, int aUnit );
|
||||||
|
|
||||||
wxTimer* m_dbl_click_timer;
|
wxTimer* m_dbl_click_timer;
|
||||||
wxPanel* m_symbol_preview;
|
SYMBOL_PREVIEW_WIDGET* m_symbol_preview;
|
||||||
wxButton* m_browser_button;
|
wxButton* m_browser_button;
|
||||||
wxSplitterWindow* m_hsplitter;
|
wxSplitterWindow* m_hsplitter;
|
||||||
wxSplitterWindow* m_vsplitter;
|
wxSplitterWindow* m_vsplitter;
|
||||||
|
|
||||||
FOOTPRINT_SELECT_WIDGET* m_fp_sel_ctrl;
|
FOOTPRINT_SELECT_WIDGET* m_fp_sel_ctrl;
|
||||||
FOOTPRINT_PREVIEW_WIDGET* m_fp_preview;
|
FOOTPRINT_PREVIEW_WIDGET* m_fp_preview;
|
||||||
LIB_TREE* m_tree;
|
LIB_TREE* m_tree;
|
||||||
|
|
||||||
static int m_h_sash_pos; // remember sash positions during a session
|
static int m_h_sash_pos; // remember sash positions during a session
|
||||||
static int m_v_sash_pos;
|
static int m_v_sash_pos;
|
||||||
|
|
|
@ -0,0 +1,140 @@
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, you may find one here:
|
||||||
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||||
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||||
|
* or you may write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <view/wx_view_controls.h>
|
||||||
|
#include <worksheet_viewitem.h>
|
||||||
|
|
||||||
|
#include <gal/graphics_abstraction_layer.h>
|
||||||
|
|
||||||
|
#include <sch_preview_panel.h>
|
||||||
|
#include <sch_view.h>
|
||||||
|
#include <sch_painter.h>
|
||||||
|
#include <sch_edit_frame.h>
|
||||||
|
#include <preview_items/selection_area.h>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#include <sch_sheet.h>
|
||||||
|
#include <pgm_base.h>
|
||||||
|
|
||||||
|
using namespace std::placeholders;
|
||||||
|
|
||||||
|
|
||||||
|
SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
|
||||||
|
const wxPoint& aPosition, const wxSize& aSize,
|
||||||
|
KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
|
||||||
|
EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, GAL_TYPE_OPENGL ),
|
||||||
|
m_parent( aParentWindow )
|
||||||
|
{
|
||||||
|
m_view = new KIGFX::SCH_VIEW( true );
|
||||||
|
m_view->SetGAL( m_gal );
|
||||||
|
|
||||||
|
m_gal->SetWorldUnitLength( 0.01 ); // 1 unit = 0.01 inch
|
||||||
|
|
||||||
|
m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
|
||||||
|
|
||||||
|
m_view->SetPainter( m_painter.get() );
|
||||||
|
m_view->SetScaleLimits( 2000000.0, 0.002 );
|
||||||
|
m_view->SetMirror( false, false );
|
||||||
|
|
||||||
|
setDefaultLayerOrder();
|
||||||
|
setDefaultLayerDeps();
|
||||||
|
|
||||||
|
view()->UpdateAllLayersOrder();
|
||||||
|
// 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 );
|
||||||
|
|
||||||
|
m_gal->SetGridColor( COLOR4D(0.0, 0.0, 0.0, 1.0) );
|
||||||
|
m_gal->SetCursorColor( COLOR4D(0.0, 0.0, 0.0, 1.0) );
|
||||||
|
|
||||||
|
m_viewControls->SetSnapping( true );
|
||||||
|
|
||||||
|
SetEvtHandlerEnabled( true );
|
||||||
|
SetFocus();
|
||||||
|
Show( true );
|
||||||
|
Raise();
|
||||||
|
StartDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SCH_PREVIEW_PANEL::~SCH_PREVIEW_PANEL()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SCH_PREVIEW_PANEL::OnShow()
|
||||||
|
{
|
||||||
|
//m_view->RecacheAllItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SCH_PREVIEW_PANEL::setDefaultLayerOrder()
|
||||||
|
{
|
||||||
|
/* for( LAYER_NUM i = 0; (unsigned) i < sizeof( GAL_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
|
||||||
|
{
|
||||||
|
LAYER_NUM layer = GAL_LAYER_ORDER[i];
|
||||||
|
wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
|
||||||
|
|
||||||
|
m_view->SetLayerOrder( layer, i );
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SCH_PREVIEW_PANEL::setDefaultLayerDeps()
|
||||||
|
{
|
||||||
|
// caching makes no sense for Cairo and other software renderers
|
||||||
|
auto target = KIGFX::TARGET_NONCACHED;
|
||||||
|
|
||||||
|
for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
|
||||||
|
m_view->SetLayerTarget( i, target );
|
||||||
|
|
||||||
|
m_view->SetLayerTarget( LAYER_GP_OVERLAY , KIGFX::TARGET_OVERLAY );
|
||||||
|
|
||||||
|
m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ;
|
||||||
|
m_view->SetLayerDisplayOnly( LAYER_WORKSHEET ) ;
|
||||||
|
m_view->SetLayerDisplayOnly( LAYER_DRC );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
KIGFX::SCH_VIEW* SCH_PREVIEW_PANEL::view() const
|
||||||
|
{
|
||||||
|
return static_cast<KIGFX::SCH_VIEW*>( m_view );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SCH_PREVIEW_PANEL::Refresh( bool aEraseBackground, const wxRect* aRect )
|
||||||
|
{
|
||||||
|
EDA_DRAW_PANEL_GAL::Refresh( aEraseBackground, aRect );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SCH_PREVIEW_PANEL::onPaint( wxPaintEvent& aEvent )
|
||||||
|
{
|
||||||
|
if( m_painter )
|
||||||
|
static_cast<KIGFX::SCH_PAINTER*>(m_painter.get())->GetSettings()->ImportLegacyColors( nullptr );
|
||||||
|
|
||||||
|
EDA_DRAW_PANEL_GAL::onPaint( aEvent );
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, you may find one here:
|
||||||
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||||
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||||
|
* or you may write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SCH_PREVIEW_PANEL_H
|
||||||
|
#define SCH_PREVIEW_PANEL_H
|
||||||
|
|
||||||
|
#include <class_draw_panel_gal.h>
|
||||||
|
#include <base_struct.h>
|
||||||
|
#include <gr_basic.h>
|
||||||
|
#include <eda_rect.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace KIGFX {
|
||||||
|
class SCH_VIEW;
|
||||||
|
namespace PREVIEW {
|
||||||
|
class SELECTION_AREA;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
class COLORS_DESIGN_SETTINGS;
|
||||||
|
|
||||||
|
|
||||||
|
class SCH_PREVIEW_PANEL : public EDA_DRAW_PANEL_GAL
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, const wxPoint& aPosition,
|
||||||
|
const wxSize& aSize, KIGFX::GAL_DISPLAY_OPTIONS& aOptions,
|
||||||
|
GAL_TYPE aGalType = GAL_TYPE_OPENGL );
|
||||||
|
|
||||||
|
~SCH_PREVIEW_PANEL() override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function UseColorScheme
|
||||||
|
* Applies layer color settings.
|
||||||
|
* @param aSettings are the new settings.
|
||||||
|
*/
|
||||||
|
void UseColorScheme( const COLORS_DESIGN_SETTINGS* aSettings );
|
||||||
|
|
||||||
|
///> @copydoc EDA_DRAW_PANEL_GAL::OnShow()
|
||||||
|
void OnShow() override;
|
||||||
|
|
||||||
|
/// @copydoc wxWindow::Refresh()
|
||||||
|
void Refresh( bool aEraseBackground, const wxRect* aRect ) override;
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) override;
|
||||||
|
|
||||||
|
KIGFX::SCH_VIEW* view() const;
|
||||||
|
|
||||||
|
///> Reassigns layer order to the initial settings.
|
||||||
|
void setDefaultLayerOrder();
|
||||||
|
|
||||||
|
///> Sets rendering targets & dependencies for layers.
|
||||||
|
void setDefaultLayerDeps();
|
||||||
|
|
||||||
|
wxWindow* m_parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,115 @@
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "symbol_preview_widget.h"
|
||||||
|
#include <wx/stattext.h>
|
||||||
|
#include <wx/sizer.h>
|
||||||
|
#include <kiway.h>
|
||||||
|
#include <sch_view.h>
|
||||||
|
#include <gal/gal_display_options.h>
|
||||||
|
#include <class_libentry.h>
|
||||||
|
#include <symbol_lib_table.h>
|
||||||
|
#include <sch_preview_panel.h>
|
||||||
|
#include <pgm_base.h>
|
||||||
|
|
||||||
|
SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway ) :
|
||||||
|
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
||||||
|
wxFULL_REPAINT_ON_RESIZE | wxTAB_TRAVERSAL ),
|
||||||
|
m_kiway( aKiway ),
|
||||||
|
m_preview( nullptr ),
|
||||||
|
m_status( nullptr ),
|
||||||
|
m_sizer( nullptr )
|
||||||
|
{
|
||||||
|
m_preview = new SCH_PREVIEW_PANEL( aParent, wxID_ANY, wxDefaultPosition, wxSize( -1, -1 ),
|
||||||
|
m_galDisplayOptions, EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
|
||||||
|
m_preview->SetStealsFocus( false );
|
||||||
|
|
||||||
|
SetBackgroundColour( *wxWHITE );
|
||||||
|
SetForegroundColour( *wxBLACK );
|
||||||
|
|
||||||
|
m_status = new wxStaticText( this, -1, wxEmptyString );
|
||||||
|
m_sizer = new wxBoxSizer( wxVERTICAL );
|
||||||
|
m_sizer->Add( 0, 0, 1 );
|
||||||
|
m_sizer->Add( m_status, 0, wxALL | wxALIGN_CENTER, 0 );
|
||||||
|
m_sizer->Add( 0, 0, 1 );
|
||||||
|
|
||||||
|
auto outer_sizer = new wxBoxSizer( wxVERTICAL );
|
||||||
|
outer_sizer->Add( m_preview, 1, wxALL | wxEXPAND, 0 );
|
||||||
|
outer_sizer->Add( m_sizer, 1, wxALL | wxALIGN_CENTER, 0 );
|
||||||
|
|
||||||
|
m_sizer->ShowItems( false );
|
||||||
|
|
||||||
|
SetSizer( outer_sizer );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SYMBOL_PREVIEW_WIDGET::SetStatusText( wxString const& aText )
|
||||||
|
{
|
||||||
|
m_status->SetLabel( aText );
|
||||||
|
m_sizer->ShowItems( true );
|
||||||
|
m_preview->Hide();
|
||||||
|
Layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SYMBOL_PREVIEW_WIDGET::DisplaySymbol( const LIB_ID& aSymbolID, int aUnit )
|
||||||
|
{
|
||||||
|
KIGFX::VIEW* view = m_preview->GetView();
|
||||||
|
LIB_ALIAS* alias = nullptr;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
alias = m_kiway.Prj().SchSymbolLibTable()->LoadSymbol( aSymbolID );
|
||||||
|
}
|
||||||
|
catch( const IO_ERROR& ioe )
|
||||||
|
{
|
||||||
|
wxLogError( wxString::Format( _( "Error loading symbol %s from library %s.\n\n%s" ),
|
||||||
|
aSymbolID.GetLibItemName().wx_str(),
|
||||||
|
aSymbolID.GetLibNickname().wx_str(),
|
||||||
|
ioe.What() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
view->Clear();
|
||||||
|
|
||||||
|
if( alias )
|
||||||
|
{
|
||||||
|
// JEY TODO: how to communicate unit to drawing code?
|
||||||
|
view->Add( alias );
|
||||||
|
|
||||||
|
// Zoom to fit
|
||||||
|
BOX2I bBox = alias->GetPart()->GetUnitBoundingBox( aUnit, 0 );
|
||||||
|
VECTOR2D clientSize = m_preview->GetClientSize();
|
||||||
|
double scale = std::min( fabs( clientSize.x / bBox.GetWidth() ),
|
||||||
|
fabs( clientSize.y / bBox.GetHeight() ) );
|
||||||
|
|
||||||
|
// Above calculation will yield an exact fit; add a bit of whitespace around symbol
|
||||||
|
scale /= 1.2;
|
||||||
|
|
||||||
|
view->SetScale( scale );
|
||||||
|
view->SetCenter( bBox.Centre() );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_preview->ForceRefresh();
|
||||||
|
|
||||||
|
m_preview->Show();
|
||||||
|
m_sizer->ShowItems( false );
|
||||||
|
Layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SYMBOL_PREVIEW_WIDGET_H
|
||||||
|
#define SYMBOL_PREVIEW_WIDGET_H
|
||||||
|
|
||||||
|
#include <wx/panel.h>
|
||||||
|
#include <kiway.h>
|
||||||
|
#include <gal/gal_display_options.h>
|
||||||
|
|
||||||
|
|
||||||
|
class LIB_ID;
|
||||||
|
class EDA_DRAW_PANEL_GAL;
|
||||||
|
class wxStaticText;
|
||||||
|
class wxSizer;
|
||||||
|
|
||||||
|
|
||||||
|
class SYMBOL_PREVIEW_WIDGET: public wxPanel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a symbol preview widget.
|
||||||
|
*
|
||||||
|
* @param aParent - parent window
|
||||||
|
* @param aKiway - an active Kiway instance
|
||||||
|
*/
|
||||||
|
SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the contents of the status label and display it.
|
||||||
|
*/
|
||||||
|
void SetStatusText( wxString const& aText );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the currently displayed symbol.
|
||||||
|
*/
|
||||||
|
void DisplaySymbol( const LIB_ID& aSymbolID, int aUnit );
|
||||||
|
|
||||||
|
private:
|
||||||
|
KIWAY& m_kiway;
|
||||||
|
|
||||||
|
KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions;
|
||||||
|
EDA_DRAW_PANEL_GAL* m_preview;
|
||||||
|
|
||||||
|
wxStaticText* m_status;
|
||||||
|
wxSizer* m_sizer;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SYMBOL_PREVIEW_WIDGET_H
|
Loading…
Reference in New Issue