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 <core/profile.h>
30
31#include <pgm_base.h>
35#include <layer_ids.h>
36
38#include <dpi_scaling_common.h>
40#include <pcb_draw_panel_gal.h>
42#include <pcb_painter.h>
43#include <pcb_actions.h>
44#include <functional>
45
46#include <pad.h>
47#include <footprint.h>
48#include <board.h>
49#include <pcb_track.h>
50#include <pcb_edit_frame.h>
51
54
55#include <pcb_io/pcb_io_mgr.h>
57
58#include <memory>
59
60#include <trace_helpers.h>
61#include <tool/tool_manager.h>
63
64#include "pcb_test_frame.h"
66
67using namespace KIGFX;
68
69void PCB_TEST_FRAME_BASE::SetBoard( std::shared_ptr<BOARD> b )
70{
71 m_board = b;
72 printf("TestFrameBase::SetBoard %p\n", b.get() );
73
74 PROF_TIMER cntConnectivity( "connectivity-build" );
75 m_board->BuildListOfNets();
76 m_board->BuildConnectivity();
77 cntConnectivity.Show();
78
79 PROF_TIMER cntView("view-build");
80 m_galPanel->DisplayBoard( m_board.get() );
81 cntView.Show();
82
83 PROF_TIMER cntFromTo("fromto-cache-update");
84 m_board->GetConnectivity()->GetFromToCache()->Rebuild( m_board.get() );
85 cntFromTo.Show();
86
87 m_galPanel->UpdateColors();
88
89 KI_TRACE( traceGalProfile, "%s\n", cntConnectivity.to_string() );
90 KI_TRACE( traceGalProfile, "%s\n", cntView.to_string() );
91
92#ifdef USE_TOOL_MANAGER
94
95 mgr.RegisterSettings( new PCBNEW_SETTINGS, false );
96
98
99
101
103 m_galPanel->GetViewControls(), cfg, this );
104
106
108
110
112
113
114 for( TOOL_BASE* tool : m_toolManager->Tools() )
115 {
116 if( PCB_TOOL_BASE* pcbTool = dynamic_cast<PCB_TOOL_BASE*>( tool ) )
117 pcbTool->SetIsBoardEditor( true );
118 }
119
121
122 m_galPanel->SetEventDispatcher( m_toolDispatcher );
123
125 m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
126#endif
127}
128
129
130BOARD* PCB_TEST_FRAME_BASE::LoadAndDisplayBoard( const std::string& filename )
131{
133 BOARD* brd = nullptr;
134
135 try
136 {
137 brd = pi->LoadBoard( wxString( filename.c_str() ), nullptr, nullptr );
138 }
139 catch( const IO_ERROR& ioe )
140 {
141 wxPrintf( "Board Loading Error: '%s'\n", ioe.Problem() );
142 return nullptr;
143 }
144
145 //SetBoard( brd );
146
147 return brd;
148}
149
150void PCB_TEST_FRAME_BASE::SetSelectableItemTypes( const std::vector<KICAD_T> aTypes )
151{
152 m_selectionTool->SetSelectableItemTypes( aTypes );
153}
154
155
156
158{
159 // SUPERSAMPLING_X4;
161
162 DPI_SCALING_COMMON dpi( Pgm().GetCommonSettings(), aParent );
164
165 m_galPanel = std::make_shared<PCB_DRAW_PANEL_GAL>( aParent, -1, wxPoint( 0, 0 ),
166 wxDefaultSize, m_displayOptions, aGalType );
167 m_galPanel->UpdateColors();
168
169 m_galPanel->SetEvtHandlerEnabled( true );
170 m_galPanel->SetFocus();
171 m_galPanel->Show( true );
172 m_galPanel->Raise();
173 m_galPanel->StartDrawing();
174
175 auto gal = m_galPanel->GetGAL();
176
177 gal->SetGridVisibility( true );
178 gal->SetGridSize( VECTOR2D( 100000.0, 100000.0 ) );
179 gal->SetGridOrigin( VECTOR2D( 0.0, 0.0 ) );
180
181 //m_galPanel->Connect( wxEVT_MOTION,
182 //wxMouseEventHandler( PCB_TEST_FRAME::OnMotion ), nullptr, this );
183
184 m_galPanel->GetViewControls()->ShowCursor( true );
185
186
187
188 //SetBoard( std::make_shared<BOARD>( new BOARD ));
189}
190
191
193{
194 m_mruPath = wxGetCwd();
195}
196
197
199{
200
201}
202
203
205{
207
210 mgr.GetColorSettings()->Load();
211}
212
214{
215 auto tool = m_toolManager->FindTool("pcbnew.InteractiveSelection");
216 if (!tool)
217 return;
218
219 auto casted = static_cast<PCB_TEST_SELECTION_TOOL*>( tool );
220
221 casted->SetSelectionHook( aHook );
222}
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
double GetScaleFactor() const override
Get the DPI scale from all known sources in order:
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
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.
std::shared_ptr< BOARD > m_board
std::shared_ptr< PCB_TEST_SELECTION_TOOL > m_selectionTool
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()
void SetSelectionHook(std::function< void(PCB_TEST_FRAME_BASE *, PCB_SELECTION *)> aHook)
void SetSelectableItemTypes(const std::vector< KICAD_T > aTypes)
KIGFX::GAL_DISPLAY_OPTIONS m_displayOptions
virtual BOARD * LoadAndDisplayBoard(const std::string &filename)
void SetSelectionHook(std::function< void(PCB_TEST_FRAME_BASE *, PCB_SELECTION *)> aHook)
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
A small class to help profiling.
Definition: profile.h:49
void Show(std::ostream &aStream=std::cerr)
Print the elapsed time (in a suitable unit) to a stream.
Definition: profile.h:105
std::string to_string()
Definition: profile.h:155
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.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:167
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:169
Base abstract interface for all kinds of tools.
Definition: tool_base.h:66
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition: tool_base.h:80
Master controller class:
Definition: tool_manager.h:62
bool InvokeTool(TOOL_ID aToolId)
Call a tool by sending a tool activation event to tool of given ID.
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
TOOL_BASE * FindTool(int aId) const
Search for a tool with given ID.
std::vector< TOOL_BASE * > Tools()
Definition: tool_manager.h:337
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
void InitTools()
Initializes all registered tools.
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition: io_mgr.h:33
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
wxLogTrace helper definitions.
#define KI_TRACE(aWhat,...)
VECTOR2< double > VECTOR2D
Definition: vector2d.h:690
WX_VIEW_CONTROLS class definition.