2018-08-03 14:18:26 +02:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-01-25 20:18:22 +01:00
|
|
|
* Copyright (C) 2014-2019 CERN
|
2018-08-03 14:18:26 +02:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2018-08-03 14:18:26 +02: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 <sch_draw_panel.h>
|
2019-12-10 07:47:13 -08:00
|
|
|
|
|
|
|
#include <wx/debug.h>
|
|
|
|
#include <wx/event.h>
|
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/window.h>
|
|
|
|
#include <wx/windowid.h>
|
|
|
|
#include <memory>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <eda_draw_frame.h>
|
|
|
|
#include <gal/definitions.h>
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2021-07-29 10:47:43 +01:00
|
|
|
#include <layer_ids.h>
|
2019-12-10 07:47:13 -08:00
|
|
|
#include <math/vector2d.h>
|
2020-01-12 20:44:19 -05:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2019-12-10 07:47:13 -08:00
|
|
|
#include <view/view.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <view/wx_view_controls.h>
|
|
|
|
|
|
|
|
#include <sch_base_frame.h>
|
2018-08-03 14:18:26 +02:00
|
|
|
#include <sch_painter.h>
|
2020-12-02 18:33:59 +01:00
|
|
|
#include <zoom_defines.h>
|
2018-08-03 14:18:26 +02:00
|
|
|
|
2018-10-21 13:50:31 +01:00
|
|
|
|
2018-08-03 14:18:26 +02:00
|
|
|
SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
|
2018-08-28 14:27:13 +01:00
|
|
|
const wxPoint& aPosition, const wxSize& aSize,
|
2020-05-19 23:54:05 +01:00
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType )
|
|
|
|
: EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
|
2018-08-03 14:18:26 +02:00
|
|
|
{
|
2024-11-21 18:59:26 -08:00
|
|
|
m_view = new KIGFX::SCH_VIEW( dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() ) );
|
2018-08-03 14:18:26 +02:00
|
|
|
m_view->SetGAL( m_gal );
|
|
|
|
|
2018-10-23 09:53:05 +02:00
|
|
|
m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
|
2018-08-03 14:18:26 +02:00
|
|
|
|
|
|
|
m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
|
2020-02-03 17:46:58 +01:00
|
|
|
|
|
|
|
COLOR_SETTINGS* cs = nullptr;
|
|
|
|
|
2020-05-19 23:54:05 +01:00
|
|
|
if( auto frame = dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() ) )
|
2020-02-03 17:46:58 +01:00
|
|
|
cs = frame->GetColorSettings();
|
|
|
|
else
|
|
|
|
cs = Pgm().GetSettingsManager().GetColorSettings();
|
|
|
|
|
|
|
|
wxASSERT( cs );
|
|
|
|
m_painter->GetSettings()->LoadColors( cs );
|
2018-08-03 14:18:26 +02:00
|
|
|
|
|
|
|
m_view->SetPainter( m_painter.get() );
|
2025-02-06 09:47:00 -05:00
|
|
|
|
2020-12-02 18:33:59 +01:00
|
|
|
// This fixes the zoom in and zoom out limits:
|
|
|
|
m_view->SetScaleLimits( ZOOM_MAX_LIMIT_EESCHEMA, ZOOM_MIN_LIMIT_EESCHEMA );
|
2018-08-03 14:18:26 +02:00
|
|
|
m_view->SetMirror( false, false );
|
|
|
|
|
2019-01-25 20:18:22 +01:00
|
|
|
// Early initialization of the canvas background color,
|
|
|
|
// before any OnPaint event is fired for the canvas using a wrong bg color
|
|
|
|
auto settings = m_painter->GetSettings();
|
|
|
|
m_gal->SetClearColor( settings->GetBackgroundColor() );
|
|
|
|
|
2018-08-03 14:18:26 +02:00
|
|
|
setDefaultLayerOrder();
|
|
|
|
setDefaultLayerDeps();
|
|
|
|
|
2019-06-13 18:28:55 +01:00
|
|
|
GetView()->UpdateAllLayersOrder();
|
2018-10-13 15:53:28 +01:00
|
|
|
|
2018-08-03 14:18:26 +02:00
|
|
|
// 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 );
|
|
|
|
|
|
|
|
SetEvtHandlerEnabled( true );
|
|
|
|
SetFocus();
|
|
|
|
Show( true );
|
|
|
|
Raise();
|
|
|
|
StartDrawing();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_DRAW_PANEL::~SCH_DRAW_PANEL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 14:00:08 -04:00
|
|
|
void SCH_DRAW_PANEL::DisplaySymbol( LIB_SYMBOL* aSymbol )
|
2018-08-03 14:18:26 +02:00
|
|
|
{
|
2021-06-14 14:00:08 -04:00
|
|
|
GetView()->DisplaySymbol( aSymbol );
|
2018-08-03 14:18:26 +02:00
|
|
|
}
|
|
|
|
|
2018-11-20 15:11:22 +01:00
|
|
|
|
2020-12-20 19:44:13 +01:00
|
|
|
void SCH_DRAW_PANEL::DisplaySheet( SCH_SCREEN *aScreen )
|
2018-08-03 14:18:26 +02:00
|
|
|
{
|
2019-06-13 18:28:55 +01:00
|
|
|
GetView()->Clear();
|
2018-09-04 21:53:04 +01:00
|
|
|
|
2018-08-03 14:18:26 +02:00
|
|
|
if( aScreen )
|
2020-12-20 19:59:07 +01:00
|
|
|
GetView()->DisplaySheet( aScreen );
|
2020-08-08 16:52:57 -04:00
|
|
|
else
|
|
|
|
GetView()->Cleanup();
|
2018-08-03 14:18:26 +02:00
|
|
|
}
|
|
|
|
|
2018-11-20 15:11:22 +01:00
|
|
|
|
2018-08-03 14:18:26 +02:00
|
|
|
void SCH_DRAW_PANEL::setDefaultLayerOrder()
|
|
|
|
{
|
2021-07-22 00:14:56 +01:00
|
|
|
for( int i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( int ); ++i )
|
2018-08-03 14:18:26 +02:00
|
|
|
{
|
2021-07-22 00:14:56 +01:00
|
|
|
int layer = SCH_LAYER_ORDER[i];
|
2018-08-03 14:18:26 +02:00
|
|
|
wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
|
|
|
|
|
|
|
|
m_view->SetLayerOrder( layer, i );
|
2018-10-21 13:50:31 +01:00
|
|
|
}
|
2018-08-03 14:18:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_DRAW_PANEL::SwitchBackend( GAL_TYPE aGalType )
|
|
|
|
{
|
|
|
|
bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
|
|
|
|
setDefaultLayerDeps();
|
2018-10-23 09:53:05 +02:00
|
|
|
m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
|
2018-10-11 18:44:59 +02:00
|
|
|
|
|
|
|
Refresh();
|
|
|
|
|
2018-08-03 14:18:26 +02:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_DRAW_PANEL::setDefaultLayerDeps()
|
|
|
|
{
|
|
|
|
// caching makes no sense for Cairo and other software renderers
|
2018-10-13 15:53:28 +01:00
|
|
|
auto target = m_backend == GAL_TYPE_OPENGL ? KIGFX::TARGET_CACHED : KIGFX::TARGET_NONCACHED;
|
2018-08-03 14:18:26 +02:00
|
|
|
|
|
|
|
for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
|
|
|
|
m_view->SetLayerTarget( i, target );
|
|
|
|
|
2025-04-08 09:54:02 -04:00
|
|
|
m_view->SetLayerTarget( LAYER_SCHEMATIC_ANCHOR, KIGFX::TARGET_NONCACHED );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_SCHEMATIC_ANCHOR );
|
|
|
|
|
2018-10-16 14:20:09 +02:00
|
|
|
// Bitmaps are draw on a non cached GAL layer:
|
2019-07-29 19:57:41 -06:00
|
|
|
m_view->SetLayerTarget( LAYER_DRAW_BITMAPS, KIGFX::TARGET_NONCACHED );
|
2018-08-03 14:18:26 +02:00
|
|
|
|
2018-10-16 14:20:09 +02:00
|
|
|
// Some draw layers need specific settings
|
2019-07-29 19:57:41 -06:00
|
|
|
m_view->SetLayerTarget( LAYER_GP_OVERLAY, KIGFX::TARGET_OVERLAY );
|
2018-08-03 14:18:26 +02:00
|
|
|
m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ;
|
2018-10-16 14:20:09 +02:00
|
|
|
|
2019-07-29 19:57:41 -06:00
|
|
|
m_view->SetLayerTarget( LAYER_SELECT_OVERLAY, KIGFX::TARGET_OVERLAY );
|
2018-10-16 14:20:09 +02:00
|
|
|
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 ) ;
|
2019-07-29 19:57:41 -06:00
|
|
|
|
2023-02-09 17:18:56 +00:00
|
|
|
m_view->SetLayerTarget( LAYER_OP_VOLTAGES, KIGFX::TARGET_OVERLAY );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_OP_VOLTAGES );
|
|
|
|
m_view->SetLayerTarget( LAYER_OP_CURRENTS, KIGFX::TARGET_OVERLAY );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_OP_CURRENTS );
|
|
|
|
|
2023-02-23 16:41:20 +00:00
|
|
|
m_view->SetLayerTarget( LAYER_SELECTION_SHADOWS, KIGFX::TARGET_OVERLAY );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_SELECTION_SHADOWS ) ;
|
2025-04-08 09:54:02 -04:00
|
|
|
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_NET_COLOR_HIGHLIGHT );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_DANGLING );
|
2018-08-03 14:18:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-13 18:28:55 +01:00
|
|
|
KIGFX::SCH_VIEW* SCH_DRAW_PANEL::GetView() const
|
2018-08-03 14:18:26 +02:00
|
|
|
{
|
|
|
|
return static_cast<KIGFX::SCH_VIEW*>( m_view );
|
|
|
|
}
|
|
|
|
|
2018-09-09 10:57:36 +01:00
|
|
|
|
2019-12-10 07:47:13 -08:00
|
|
|
void SCH_DRAW_PANEL::OnShow()
|
|
|
|
{
|
2020-05-19 23:54:05 +01:00
|
|
|
SCH_BASE_FRAME* frame = dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() );
|
2019-12-10 07:47:13 -08:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Check if the current rendering backend can be properly initialized
|
|
|
|
m_view->UpdateItems();
|
|
|
|
}
|
|
|
|
catch( const std::runtime_error& e )
|
|
|
|
{
|
|
|
|
DisplayInfoMessage( frame, e.what() );
|
|
|
|
|
2020-08-31 18:47:44 +01:00
|
|
|
// Use fallback if one is available
|
|
|
|
if( GAL_FALLBACK != m_backend )
|
|
|
|
{
|
|
|
|
SwitchBackend( GAL_FALLBACK );
|
|
|
|
|
|
|
|
if( frame )
|
|
|
|
frame->ActivateGalCanvas();
|
|
|
|
}
|
2019-12-10 07:47:13 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-03 14:18:26 +02:00
|
|
|
void SCH_DRAW_PANEL::onPaint( wxPaintEvent& aEvent )
|
|
|
|
{
|
2019-05-31 18:37:07 +01:00
|
|
|
// The first wxPaintEvent can be fired at startup before the GAL engine is fully initialized
|
|
|
|
// (depending on platforms). Do nothing in this case
|
2019-03-18 05:22:33 -07:00
|
|
|
if( !m_gal->IsInitialized() || !m_gal->IsVisible() )
|
2018-09-15 16:01:35 +02:00
|
|
|
return;
|
|
|
|
|
2018-08-03 14:18:26 +02:00
|
|
|
EDA_DRAW_PANEL_GAL::onPaint( aEvent );
|
|
|
|
}
|