7 changed files with 417 additions and 111 deletions
-
2eeschema/CMakeLists.txt
-
114eeschema/dialogs/dialog_choose_component.cpp
-
8eeschema/dialogs/dialog_choose_component.h
-
140eeschema/sch_preview_panel.cpp
-
82eeschema/sch_preview_panel.h
-
115eeschema/widgets/symbol_preview_widget.cpp
-
67eeschema/widgets/symbol_preview_widget.h
@ -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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue