2017-09-17 22:44:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-07-16 20:13:26 +00:00
|
|
|
* Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-09-17 22:44:30 +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 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 "gerbview_draw_panel_gal.h"
|
|
|
|
#include <view/view.h>
|
|
|
|
#include <view/wx_view_controls.h>
|
|
|
|
#include <gerbview_painter.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_proxy_view_item.h>
|
2020-12-02 17:33:59 +00:00
|
|
|
#include <zoom_defines.h>
|
2017-09-17 22:44:30 +00:00
|
|
|
|
|
|
|
#include <gerbview_frame.h>
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2021-06-06 22:56:20 +00:00
|
|
|
#include <pgm_base.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2017-09-17 22:44:30 +00:00
|
|
|
|
2018-12-03 12:10:55 +00:00
|
|
|
#include <gerber_file_image.h>
|
|
|
|
#include <gerber_file_image_list.h>
|
|
|
|
|
2017-09-17 22:44:30 +00:00
|
|
|
#include <functional>
|
2019-12-05 13:43:55 +00:00
|
|
|
#include <memory>
|
2020-12-02 17:33:59 +00:00
|
|
|
|
2017-09-17 22:44:30 +00:00
|
|
|
using namespace std::placeholders;
|
|
|
|
|
|
|
|
|
|
|
|
GERBVIEW_DRAW_PANEL_GAL::GERBVIEW_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
|
2021-07-16 20:13:26 +00:00
|
|
|
const wxPoint& aPosition, const wxSize& aSize,
|
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS& aOptions,
|
|
|
|
GAL_TYPE aGalType ) :
|
2017-09-17 22:44:30 +00:00
|
|
|
EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
|
|
|
|
{
|
2017-11-05 21:09:56 +00:00
|
|
|
m_view = new KIGFX::VIEW( true );
|
|
|
|
m_view->SetGAL( m_gal );
|
2018-11-20 09:22:45 +00:00
|
|
|
GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
|
2017-09-17 22:44:30 +00:00
|
|
|
|
2019-12-05 13:43:55 +00:00
|
|
|
m_painter = std::make_unique<KIGFX::GERBVIEW_PAINTER>( m_gal );
|
2017-10-30 08:36:31 +00:00
|
|
|
m_view->SetPainter( m_painter.get() );
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2020-12-02 17:33:59 +00:00
|
|
|
// This fixes the zoom in and zoom out limits:
|
|
|
|
m_view->SetScaleLimits( ZOOM_MAX_LIMIT_GERBVIEW, ZOOM_MIN_LIMIT_GERBVIEW );
|
2017-09-17 22:44:30 +00:00
|
|
|
|
2017-11-05 21:09:56 +00:00
|
|
|
m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
|
|
|
|
|
|
|
|
setDefaultLayerDeps();
|
|
|
|
|
2017-09-17 22:44:30 +00:00
|
|
|
// Load display options (such as filled/outline display of items).
|
|
|
|
auto frame = static_cast< GERBVIEW_FRAME* >( GetParentEDAFrame() );
|
|
|
|
|
|
|
|
if( frame )
|
|
|
|
{
|
2019-11-07 14:23:09 +00:00
|
|
|
auto& displ_opts = frame->GetDisplayOptions();
|
2020-01-13 01:44:19 +00:00
|
|
|
auto rs = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>(
|
|
|
|
m_view->GetPainter()->GetSettings() );
|
|
|
|
|
|
|
|
rs->LoadDisplayOptions( displ_opts );
|
|
|
|
rs->LoadColors( Pgm().GetSettingsManager().GetColorSettings() );
|
2017-09-17 22:44:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GERBVIEW_DRAW_PANEL_GAL::~GERBVIEW_DRAW_PANEL_GAL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBVIEW_DRAW_PANEL_GAL::SetHighContrastLayer( int aLayer )
|
|
|
|
{
|
|
|
|
// Set display settings for high contrast mode
|
|
|
|
KIGFX::RENDER_SETTINGS* rSettings = m_view->GetPainter()->GetSettings();
|
|
|
|
|
|
|
|
SetTopLayer( aLayer );
|
|
|
|
|
2020-10-03 21:26:44 +00:00
|
|
|
rSettings->ClearHighContrastLayers();
|
|
|
|
rSettings->SetLayerIsHighContrast( aLayer );
|
|
|
|
rSettings->SetLayerIsHighContrast( GERBER_DCODE_LAYER( aLayer ) );
|
2017-09-17 22:44:30 +00:00
|
|
|
|
|
|
|
m_view->UpdateAllLayersColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
void GERBVIEW_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
|
|
|
|
std::vector<MSG_PANEL_ITEM>& aList )
|
2017-09-17 22:44:30 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBVIEW_DRAW_PANEL_GAL::OnShow()
|
|
|
|
{
|
2020-05-19 22:54:05 +00:00
|
|
|
GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
|
2017-09-17 22:44:30 +00:00
|
|
|
|
|
|
|
if( frame )
|
|
|
|
{
|
|
|
|
SetTopLayer( frame->GetActiveLayer() );
|
2019-11-07 14:23:09 +00:00
|
|
|
auto& displ_opts = frame->GetDisplayOptions();
|
2017-09-17 22:44:30 +00:00
|
|
|
static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>(
|
|
|
|
m_view->GetPainter()->GetSettings() )->LoadDisplayOptions( displ_opts );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_view->RecacheAllItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GERBVIEW_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
|
|
|
|
{
|
|
|
|
bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
|
2018-12-03 12:10:55 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
// The next onPaint event will call m_view->UpdateItems() that is very time consuming
|
2018-12-03 12:10:55 +00:00
|
|
|
// after switching to opengl. Clearing m_view and rebuild it is much faster
|
|
|
|
if( aGalType == GAL_TYPE_OPENGL )
|
|
|
|
{
|
2020-05-19 22:54:05 +00:00
|
|
|
GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
|
2018-12-03 12:10:55 +00:00
|
|
|
|
|
|
|
if( frame )
|
|
|
|
{
|
|
|
|
m_view->Clear();
|
|
|
|
|
|
|
|
for( int layer = GERBER_DRAWLAYERS_COUNT-1; layer>= 0; --layer )
|
|
|
|
{
|
|
|
|
GERBER_FILE_IMAGE* gerber = frame->GetImagesList()->GetGbrImage( layer );
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( gerber == nullptr ) // Graphic layer not yet used
|
2018-12-03 12:10:55 +00:00
|
|
|
continue;
|
|
|
|
|
2019-12-30 13:23:33 +00:00
|
|
|
for( GERBER_DRAW_ITEM* item : gerber->GetItems() )
|
2018-12-03 12:10:55 +00:00
|
|
|
{
|
|
|
|
m_view->Add (item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-17 22:44:30 +00:00
|
|
|
setDefaultLayerDeps();
|
2018-11-20 09:22:45 +00:00
|
|
|
|
|
|
|
GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
|
|
|
|
|
2017-09-17 22:44:30 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBVIEW_DRAW_PANEL_GAL::setDefaultLayerDeps()
|
|
|
|
{
|
|
|
|
// caching makes no sense for Cairo and other software renderers
|
|
|
|
auto target = m_backend == GAL_TYPE_OPENGL ? KIGFX::TARGET_CACHED : KIGFX::TARGET_NONCACHED;
|
|
|
|
|
|
|
|
for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
|
|
|
|
m_view->SetLayerTarget( i, target );
|
|
|
|
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_DCODES );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_NEGATIVE_OBJECTS );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_GERBVIEW_GRID );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_GERBVIEW_AXES );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_GERBVIEW_BACKGROUND );
|
2021-02-22 16:37:43 +00:00
|
|
|
m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET );
|
2017-09-17 22:44:30 +00:00
|
|
|
|
2018-08-28 22:12:02 +00:00
|
|
|
m_view->SetLayerTarget( LAYER_SELECT_OVERLAY, KIGFX::TARGET_OVERLAY );
|
|
|
|
m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY );
|
|
|
|
|
2017-09-20 08:30:48 +00:00
|
|
|
m_view->SetLayerTarget( LAYER_GP_OVERLAY, KIGFX::TARGET_OVERLAY );
|
2017-09-17 22:44:30 +00:00
|
|
|
m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void GERBVIEW_DRAW_PANEL_GAL::SetDrawingSheet( DS_PROXY_VIEW_ITEM* aDrawingSheet )
|
2018-06-01 07:11:43 +00:00
|
|
|
{
|
2021-02-22 16:37:43 +00:00
|
|
|
m_drawingSheet.reset( aDrawingSheet );
|
|
|
|
m_view->Add( m_drawingSheet.get() );
|
2018-06-01 07:11:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-17 22:44:30 +00:00
|
|
|
void GERBVIEW_DRAW_PANEL_GAL::SetTopLayer( int aLayer )
|
|
|
|
{
|
|
|
|
m_view->ClearTopLayers();
|
|
|
|
|
|
|
|
for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; ++i )
|
|
|
|
{
|
|
|
|
m_view->SetLayerOrder( GERBER_DCODE_LAYER( GERBER_DRAW_LAYER( i ) ), 2 * i );
|
2018-03-04 04:43:16 +00:00
|
|
|
m_view->SetLayerOrder( GERBER_DRAW_LAYER( i ), ( 2 * i ) + 1 );
|
2017-09-17 22:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_view->SetTopLayer( aLayer );
|
|
|
|
|
|
|
|
// Move DCODE layer to the top
|
|
|
|
m_view->SetTopLayer( GERBER_DCODE_LAYER( aLayer ) );
|
|
|
|
|
2018-08-30 23:54:08 +00:00
|
|
|
m_view->SetTopLayer( LAYER_SELECT_OVERLAY );
|
|
|
|
|
2017-09-17 22:44:30 +00:00
|
|
|
m_view->SetTopLayer( LAYER_GP_OVERLAY );
|
|
|
|
|
|
|
|
m_view->UpdateAllLayersOrder();
|
|
|
|
}
|
2018-06-01 07:27:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
BOX2I GERBVIEW_DRAW_PANEL_GAL::GetDefaultViewBBox() const
|
|
|
|
{
|
2021-02-22 16:37:43 +00:00
|
|
|
// Even in Gervbview, LAYER_DRAWINGSHEET controls the visibility of the drawingsheet
|
|
|
|
if( m_drawingSheet && m_view->IsLayerVisible( LAYER_DRAWINGSHEET ) )
|
|
|
|
return m_drawingSheet->ViewBBox();
|
2018-06-01 07:27:23 +00:00
|
|
|
|
|
|
|
return BOX2I();
|
|
|
|
}
|