2018-08-28 13:26:39 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-12-30 18:28:00 +00:00
|
|
|
* Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-08-28 13:26:39 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_proxy_view_item.h>
|
2018-08-28 13:26:39 +00:00
|
|
|
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
|
|
|
|
#include <sch_preview_panel.h>
|
|
|
|
#include <sch_view.h>
|
|
|
|
#include <sch_painter.h>
|
|
|
|
#include <sch_edit_frame.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2018-08-28 13:26:39 +00:00
|
|
|
#include <preview_items/selection_area.h>
|
2020-12-02 17:33:59 +00:00
|
|
|
#include <zoom_defines.h>
|
2018-08-28 13:26:39 +00:00
|
|
|
|
|
|
|
#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 ) :
|
2020-05-19 22:54:05 +00:00
|
|
|
EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
|
2018-08-28 13:26:39 +00:00
|
|
|
{
|
2018-11-19 09:21:28 +00:00
|
|
|
m_view = new KIGFX::SCH_VIEW( true, nullptr );
|
2018-08-28 13:26:39 +00:00
|
|
|
m_view->SetGAL( m_gal );
|
|
|
|
|
2018-10-23 07:53:05 +00:00
|
|
|
m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
|
2018-08-28 13:26:39 +00:00
|
|
|
|
|
|
|
m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
|
2020-01-13 01:44:19 +00:00
|
|
|
m_painter->GetSettings()->LoadColors( Pgm().GetSettingsManager().GetColorSettings() );
|
2018-08-28 13:26:39 +00:00
|
|
|
|
|
|
|
m_view->SetPainter( m_painter.get() );
|
2020-12-02 17:33:59 +00:00
|
|
|
// This fixes the zoom in and zoom out limits:
|
|
|
|
m_view->SetScaleLimits( ZOOM_MAX_LIMIT_EESCHEMA_PREVIEW, ZOOM_MIN_LIMIT_EESCHEMA_PREVIEW );
|
2018-08-28 13:26:39 +00:00
|
|
|
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 );
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
m_gal->SetGridColor( m_painter->GetSettings()->GetLayerColor( LAYER_SCHEMATIC_GRID ) );
|
2020-03-09 01:40:48 +00:00
|
|
|
m_gal->SetCursorEnabled( false );
|
2020-08-01 19:48:39 +00:00
|
|
|
m_gal->SetGridSize( VECTOR2D( Mils2iu( 100.0 ), Mils2iu( 100.0 ) ) );
|
2018-08-28 13:26:39 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2018-10-21 12:50:31 +00:00
|
|
|
for( LAYER_NUM i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
|
2018-08-28 13:26:39 +00:00
|
|
|
{
|
2018-10-21 12:50:31 +00:00
|
|
|
LAYER_NUM layer = SCH_LAYER_ORDER[i];
|
2018-08-28 13:26:39 +00:00
|
|
|
wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
|
|
|
|
|
|
|
|
m_view->SetLayerOrder( layer, i );
|
2018-10-21 12:50:31 +00:00
|
|
|
}
|
2018-08-28 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_PREVIEW_PANEL::setDefaultLayerDeps()
|
|
|
|
{
|
2018-10-23 15:02:55 +00:00
|
|
|
// An alias's fields don't know how to substitute in their parent's values, so we
|
|
|
|
// don't let them draw themselves. This means no caching.
|
|
|
|
auto target = KIGFX::TARGET_NONCACHED;
|
2018-08-28 13:26:39 +00:00
|
|
|
|
|
|
|
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 ) ;
|
2018-10-21 12:50:31 +00:00
|
|
|
|
|
|
|
m_view->SetLayerTarget( LAYER_SELECT_OVERLAY , KIGFX::TARGET_OVERLAY );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY ) ;
|
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
m_view->SetLayerTarget( LAYER_DRAWINGSHEET , KIGFX::TARGET_NONCACHED );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET ) ;
|
2018-08-28 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2018-09-03 17:16:17 +00:00
|
|
|
if( IsShown() )
|
|
|
|
EDA_DRAW_PANEL_GAL::onPaint( aEvent );
|
2018-08-28 13:26:39 +00:00
|
|
|
}
|