2017-10-31 16:38:01 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-09-04 23:13:20 +00:00
|
|
|
* Copyright (C) 2013-2017 CERN
|
2022-09-29 16:07:42 +00:00
|
|
|
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-10-31 16:38:01 +00:00
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2020-09-04 23:13:20 +00:00
|
|
|
|
2017-10-31 16:38:01 +00:00
|
|
|
#include <wx/popupwin.h>
|
|
|
|
#include <wx/cmdline.h>
|
2023-09-07 11:22:10 +00:00
|
|
|
#include <core/profile.h>
|
2020-09-04 23:13:20 +00:00
|
|
|
|
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
#include <settings/color_settings.h>
|
2023-05-26 01:53:38 +00:00
|
|
|
#include <settings/cvpcb_settings.h>
|
2021-07-29 09:47:43 +00:00
|
|
|
#include <layer_ids.h>
|
2017-10-31 16:38:01 +00:00
|
|
|
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2023-09-23 03:17:53 +00:00
|
|
|
#include <dpi_scaling_common.h>
|
2017-10-31 16:38:01 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
|
|
|
#include <pcb_draw_panel_gal.h>
|
|
|
|
#include <view/wx_view_controls.h>
|
|
|
|
#include <pcb_painter.h>
|
2024-03-02 22:35:18 +00:00
|
|
|
#include <pcb_actions.h>
|
|
|
|
#include <functional>
|
2017-10-31 16:38:01 +00:00
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <pad.h>
|
|
|
|
#include <footprint.h>
|
|
|
|
#include <board.h>
|
2021-06-19 21:21:23 +00:00
|
|
|
#include <pcb_track.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2017-10-31 16:38:01 +00:00
|
|
|
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2024-03-02 22:35:18 +00:00
|
|
|
#include <connectivity/from_to_cache.h>
|
2017-10-31 16:38:01 +00:00
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <pcb_io/pcb_io_mgr.h>
|
2023-12-24 01:21:58 +00:00
|
|
|
#include <pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h>
|
2023-12-19 17:39:26 +00:00
|
|
|
|
2019-12-05 13:43:55 +00:00
|
|
|
#include <memory>
|
2017-10-31 16:38:01 +00:00
|
|
|
|
2024-03-02 22:35:18 +00:00
|
|
|
#include <trace_helpers.h>
|
2017-10-31 16:38:01 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tool/tool_dispatcher.h>
|
|
|
|
|
|
|
|
#include "pcb_test_frame.h"
|
2024-03-02 22:35:18 +00:00
|
|
|
#include "pcb_test_selection_tool.h"
|
2017-10-31 16:38:01 +00:00
|
|
|
|
2020-09-04 23:13:20 +00:00
|
|
|
using namespace KIGFX;
|
2017-10-31 16:38:01 +00:00
|
|
|
|
2020-09-04 23:13:20 +00:00
|
|
|
void PCB_TEST_FRAME_BASE::SetBoard( std::shared_ptr<BOARD> b )
|
2017-10-31 16:38:01 +00:00
|
|
|
{
|
2020-09-04 23:13:20 +00:00
|
|
|
m_board = b;
|
2024-03-02 22:35:18 +00:00
|
|
|
printf("TestFrameBase::SetBoard %p\n", b.get() );
|
2017-10-31 16:38:01 +00:00
|
|
|
|
2021-12-05 19:16:18 +00:00
|
|
|
PROF_TIMER cntConnectivity( "connectivity-build" );
|
2024-03-02 22:35:18 +00:00
|
|
|
m_board->BuildListOfNets();
|
2022-09-29 16:07:42 +00:00
|
|
|
m_board->BuildConnectivity();
|
2024-03-02 22:35:18 +00:00
|
|
|
cntConnectivity.Show();
|
2021-11-28 20:52:42 +00:00
|
|
|
|
2021-12-05 19:16:18 +00:00
|
|
|
PROF_TIMER cntView("view-build");
|
2017-10-31 16:38:01 +00:00
|
|
|
m_galPanel->DisplayBoard( m_board.get() );
|
2024-03-02 22:35:18 +00:00
|
|
|
cntView.Show();
|
|
|
|
|
|
|
|
PROF_TIMER cntFromTo("fromto-cache-update");
|
|
|
|
m_board->GetConnectivity()->GetFromToCache()->Rebuild( m_board.get() );
|
|
|
|
cntFromTo.Show();
|
2021-11-28 20:52:42 +00:00
|
|
|
|
2020-09-04 23:13:20 +00:00
|
|
|
m_galPanel->UpdateColors();
|
|
|
|
|
2021-11-28 20:52:42 +00:00
|
|
|
KI_TRACE( traceGalProfile, "%s\n", cntConnectivity.to_string() );
|
|
|
|
KI_TRACE( traceGalProfile, "%s\n", cntView.to_string() );
|
|
|
|
|
2019-01-21 18:42:06 +00:00
|
|
|
#ifdef USE_TOOL_MANAGER
|
2023-01-12 22:36:51 +00:00
|
|
|
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
|
2023-04-18 22:59:30 +00:00
|
|
|
|
|
|
|
mgr.RegisterSettings( new PCBNEW_SETTINGS, false );
|
|
|
|
|
2023-01-12 22:36:51 +00:00
|
|
|
PCBNEW_SETTINGS* cfg = mgr.GetAppSettings<PCBNEW_SETTINGS>();
|
|
|
|
|
2024-03-02 22:35:18 +00:00
|
|
|
|
|
|
|
m_toolManager = new TOOL_MANAGER;
|
|
|
|
|
2017-10-31 16:38:01 +00:00
|
|
|
m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(),
|
2024-03-02 22:35:18 +00:00
|
|
|
m_galPanel->GetViewControls(), cfg, this );
|
|
|
|
|
|
|
|
m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
|
|
|
|
|
|
|
|
m_selectionTool.reset( new PCB_TEST_SELECTION_TOOL );
|
|
|
|
|
|
|
|
m_toolManager->RegisterTool( m_selectionTool.get() );
|
|
|
|
|
|
|
|
createUserTools();
|
|
|
|
|
|
|
|
|
|
|
|
for( TOOL_BASE* tool : m_toolManager->Tools() )
|
|
|
|
{
|
|
|
|
if( PCB_TOOL_BASE* pcbTool = dynamic_cast<PCB_TOOL_BASE*>( tool ) )
|
|
|
|
pcbTool->SetIsBoardEditor( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_toolManager->InitTools();
|
|
|
|
|
|
|
|
m_galPanel->SetEventDispatcher( m_toolDispatcher );
|
2017-10-31 16:38:01 +00:00
|
|
|
|
|
|
|
m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
|
2024-03-02 22:35:18 +00:00
|
|
|
m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
|
2019-01-21 18:42:06 +00:00
|
|
|
#endif
|
2017-10-31 16:38:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-04 23:13:20 +00:00
|
|
|
BOARD* PCB_TEST_FRAME_BASE::LoadAndDisplayBoard( const std::string& filename )
|
2017-10-31 16:38:01 +00:00
|
|
|
{
|
2023-12-27 20:39:29 +00:00
|
|
|
IO_RELEASER<PCB_IO> pi( new PCB_IO_KICAD_SEXPR );
|
2017-10-31 16:38:01 +00:00
|
|
|
BOARD* brd = nullptr;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2023-08-15 03:55:32 +00:00
|
|
|
brd = pi->LoadBoard( wxString( filename.c_str() ), nullptr, nullptr );
|
2017-10-31 16:38:01 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2021-07-22 18:45:22 +00:00
|
|
|
wxPrintf( "Board Loading Error: '%s'\n", ioe.Problem() );
|
2017-10-31 16:38:01 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-09-04 23:13:20 +00:00
|
|
|
//SetBoard( brd );
|
2017-10-31 16:38:01 +00:00
|
|
|
|
|
|
|
return brd;
|
|
|
|
}
|
|
|
|
|
2024-03-02 22:35:18 +00:00
|
|
|
void PCB_TEST_FRAME_BASE::SetSelectableItemTypes( const std::vector<KICAD_T> aTypes )
|
2017-10-31 16:38:01 +00:00
|
|
|
{
|
2024-03-02 22:35:18 +00:00
|
|
|
m_selectionTool->SetSelectableItemTypes( aTypes );
|
|
|
|
}
|
|
|
|
|
2017-10-31 16:38:01 +00:00
|
|
|
|
2021-07-20 14:32:22 +00:00
|
|
|
|
2020-09-04 23:13:20 +00:00
|
|
|
void PCB_TEST_FRAME_BASE::createView( wxWindow *aParent, PCB_DRAW_PANEL_GAL::GAL_TYPE aGalType )
|
|
|
|
{
|
2021-07-20 14:32:22 +00:00
|
|
|
// SUPERSAMPLING_X4;
|
|
|
|
m_displayOptions.gl_antialiasing_mode = KIGFX::OPENGL_ANTIALIASING_MODE::NONE;
|
2019-01-21 18:42:06 +00:00
|
|
|
|
2023-09-23 03:17:53 +00:00
|
|
|
DPI_SCALING_COMMON dpi( Pgm().GetCommonSettings(), aParent );
|
2023-05-26 01:53:38 +00:00
|
|
|
m_displayOptions.m_scaleFactor = dpi.GetScaleFactor();
|
|
|
|
|
2021-07-20 14:32:22 +00:00
|
|
|
m_galPanel = std::make_shared<PCB_DRAW_PANEL_GAL>( aParent, -1, wxPoint( 0, 0 ),
|
|
|
|
wxDefaultSize, m_displayOptions, aGalType );
|
2020-09-04 23:13:20 +00:00
|
|
|
m_galPanel->UpdateColors();
|
2021-03-27 20:02:34 +00:00
|
|
|
|
2017-10-31 16:38:01 +00:00
|
|
|
m_galPanel->SetEvtHandlerEnabled( true );
|
|
|
|
m_galPanel->SetFocus();
|
|
|
|
m_galPanel->Show( true );
|
|
|
|
m_galPanel->Raise();
|
|
|
|
m_galPanel->StartDrawing();
|
|
|
|
|
|
|
|
auto gal = m_galPanel->GetGAL();
|
|
|
|
|
|
|
|
gal->SetGridVisibility( true );
|
|
|
|
gal->SetGridSize( VECTOR2D( 100000.0, 100000.0 ) );
|
|
|
|
gal->SetGridOrigin( VECTOR2D( 0.0, 0.0 ) );
|
|
|
|
|
2020-09-04 23:13:20 +00:00
|
|
|
//m_galPanel->Connect( wxEVT_MOTION,
|
2021-07-20 14:32:22 +00:00
|
|
|
//wxMouseEventHandler( PCB_TEST_FRAME::OnMotion ), nullptr, this );
|
2017-10-31 16:38:01 +00:00
|
|
|
|
|
|
|
m_galPanel->GetViewControls()->ShowCursor( true );
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-04 23:13:20 +00:00
|
|
|
//SetBoard( std::make_shared<BOARD>( new BOARD ));
|
2017-10-31 16:38:01 +00:00
|
|
|
}
|
|
|
|
|
2021-07-20 14:32:22 +00:00
|
|
|
|
2020-09-04 23:13:20 +00:00
|
|
|
PCB_TEST_FRAME_BASE::PCB_TEST_FRAME_BASE()
|
2017-10-31 16:38:01 +00:00
|
|
|
{
|
2023-08-08 18:43:42 +00:00
|
|
|
m_mruPath = wxGetCwd();
|
2017-10-31 16:38:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-04 23:13:20 +00:00
|
|
|
PCB_TEST_FRAME_BASE::~PCB_TEST_FRAME_BASE()
|
2017-10-31 16:38:01 +00:00
|
|
|
{
|
2020-09-04 23:13:20 +00:00
|
|
|
|
2017-10-31 16:38:01 +00:00
|
|
|
}
|
2020-09-04 23:13:20 +00:00
|
|
|
|
2021-07-20 14:32:22 +00:00
|
|
|
|
2020-09-04 23:13:20 +00:00
|
|
|
void PCB_TEST_FRAME_BASE::LoadSettings()
|
|
|
|
{
|
2023-05-26 01:53:38 +00:00
|
|
|
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
|
|
|
|
|
|
|
|
mgr.RegisterSettings( new PCBNEW_SETTINGS );
|
|
|
|
mgr.RegisterSettings( new CVPCB_SETTINGS );
|
|
|
|
mgr.GetColorSettings()->Load();
|
2021-03-27 20:02:34 +00:00
|
|
|
}
|
2024-03-02 22:35:18 +00:00
|
|
|
|
|
|
|
void PCB_TEST_FRAME_BASE::SetSelectionHook( std::function<void(PCB_TEST_FRAME_BASE*, PCB_SELECTION*)> aHook )
|
|
|
|
{
|
|
|
|
auto tool = m_toolManager->FindTool("pcbnew.InteractiveSelection");
|
|
|
|
if (!tool)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto casted = static_cast<PCB_TEST_SELECTION_TOOL*>( tool );
|
|
|
|
|
|
|
|
casted->SetSelectionHook( aHook );
|
|
|
|
}
|