KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_test_frame.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2013-2017 CERN
5 * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Tomasz Wlostowski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26
27#include <wx/popupwin.h>
28#include <wx/cmdline.h>
29#include <profile.h>
30
31#include <pgm_base.h>
35#include <layer_ids.h>
36
38#include <gal/dpi_scaling.h>
40#include <pcb_draw_panel_gal.h>
42#include <pcb_painter.h>
43
44#include <pad.h>
45#include <footprint.h>
46#include <board.h>
47#include <pcb_track.h>
48#include <pcb_edit_frame.h>
49
51
52#include <io_mgr.h>
53#include <memory>
54
55#include <tool/actions.h>
56#include <tool/tool_manager.h>
58#include <tools/pcb_tool_base.h>
61
62#include "pcb_test_frame.h"
63
64#include <trace_helpers.h>
65
66using namespace KIGFX;
67
68
69void PCB_TEST_FRAME_BASE::SetBoard( std::shared_ptr<BOARD> b )
70{
71 m_board = b;
72
73 PROF_TIMER cntConnectivity( "connectivity-build" );
74 m_board->BuildConnectivity();
75 cntConnectivity.Stop();
76
77 PROF_TIMER cntView("view-build");
78 m_galPanel->DisplayBoard( m_board.get() );
79 cntView.Stop();
80
81 m_galPanel->UpdateColors();
82
83 KI_TRACE( traceGalProfile, "%s\n", cntConnectivity.to_string() );
84 KI_TRACE( traceGalProfile, "%s\n", cntView.to_string() );
85
86#ifdef USE_TOOL_MANAGER
87 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
88
89 mgr.RegisterSettings( new PCBNEW_SETTINGS, false );
90
92
93 m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(),
94 m_galPanel->GetViewControls(), cfg, nullptr );
95
96 m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
97#endif
98}
99
100
101BOARD* PCB_TEST_FRAME_BASE::LoadAndDisplayBoard( const std::string& filename )
102{
104 BOARD* brd = nullptr;
105
106 try
107 {
108 brd = pi->Load( wxString( filename.c_str() ), nullptr, nullptr );
109 }
110 catch( const IO_ERROR& ioe )
111 {
112 wxPrintf( "Board Loading Error: '%s'\n", ioe.Problem() );
113 return nullptr;
114 }
115
116 //SetBoard( brd );
117
118 return brd;
119}
120
121
122class TEST_ACTIONS : public ACTIONS
123{
124};
125
126
128{
129 // SUPERSAMPLING_X4;
131
132 DPI_SCALING dpi( Pgm().GetCommonSettings(), aParent );
134
135 m_galPanel = std::make_shared<PCB_DRAW_PANEL_GAL>( aParent, -1, wxPoint( 0, 0 ),
136 wxDefaultSize, m_displayOptions, aGalType );
137 m_galPanel->UpdateColors();
138
139 m_galPanel->SetEvtHandlerEnabled( true );
140 m_galPanel->SetFocus();
141 m_galPanel->Show( true );
142 m_galPanel->Raise();
143 m_galPanel->StartDrawing();
144
145 auto gal = m_galPanel->GetGAL();
146
147 gal->SetGridVisibility( true );
148 gal->SetGridSize( VECTOR2D( 100000.0, 100000.0 ) );
149 gal->SetGridOrigin( VECTOR2D( 0.0, 0.0 ) );
150
151 //m_galPanel->Connect( wxEVT_MOTION,
152 //wxMouseEventHandler( PCB_TEST_FRAME::OnMotion ), nullptr, this );
153
154 m_galPanel->GetViewControls()->ShowCursor( true );
155
156#ifdef USE_TOOL_MANAGER
157 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
159
160 m_toolManager = std::make_unique<TOOL_MANAGER>( );
161 m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(),
162 m_galPanel->GetViewControls(), cfg, nullptr );
163
164 m_pcbActions = std::make_unique<TEST_ACTIONS>( );
165 m_toolDispatcher = std::make_unique<TOOL_DISPATCHER>( m_toolManager.get() );
166
167 m_toolManager->RegisterTool( new PCB_SELECTION_TOOL );
169
170 m_toolManager->InitTools();
171 m_toolManager->InvokeTool( "test.DefaultTool" );
172#endif
173
174 //SetBoard( std::make_shared<BOARD>( new BOARD ));
175}
176
177
179{
180}
181
182
184{
185
186}
187
188
190{
191 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
192
195 mgr.GetColorSettings()->Load();
196}
Gather all the actions that are shared by tools.
Definition: actions.h:41
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:270
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
Definition: dpi_scaling.h:37
double GetScaleFactor() const
Get the DPI scale from all known sources in order:
Definition: dpi_scaling.cpp:91
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:46
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
A PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
Definition: pcb_plugin.h:261
The selection tool: currently supports:
std::shared_ptr< BOARD > m_board
std::shared_ptr< PCB_DRAW_PANEL_GAL > m_galPanel
void createView(wxWindow *aParent, PCB_DRAW_PANEL_GAL::GAL_TYPE aGalType=PCB_DRAW_PANEL_GAL::GAL_TYPE_OPENGL)
virtual void SetBoard(std::shared_ptr< BOARD > b)
virtual void createUserTools()
virtual ~PCB_TEST_FRAME_BASE()
KIGFX::GAL_DISPLAY_OPTIONS m_displayOptions
virtual BOARD * LoadAndDisplayBoard(const std::string &filename)
Releases a PLUGIN in the context of a potential thrown exception through its destructor.
Definition: io_mgr.h:562
virtual BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const STRING_UTF8_MAP *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Load information from some input file format that this PLUGIN implementation knows about into either ...
Definition: plugin.cpp:38
A small class to help profiling.
Definition: profile.h:47
void Stop()
Save the time when this function was called, and set the counter stane to stop.
Definition: profile.h:86
std::string to_string()
Definition: profile.h:153
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition: tool_base.h:80
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:115
wxLogTrace helper definitions.
#define KI_TRACE(aWhat,...)
VECTOR2< double > VECTOR2D
Definition: vector2d.h:587
WX_VIEW_CONTROLS class definition.