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 PCBNEW_SETTINGS* cfg = mgr.RegisterSettings( new PCBNEW_SETTINGS, false );
95
97
99 m_galPanel->GetViewControls(), cfg, this );
100
102
104
106
108
109
110 for( TOOL_BASE* tool : m_toolManager->Tools() )
111 {
112 if( PCB_TOOL_BASE* pcbTool = dynamic_cast<PCB_TOOL_BASE*>( tool ) )
113 pcbTool->SetIsBoardEditor( true );
114 }
115
117
118 m_galPanel->SetEventDispatcher( m_toolDispatcher );
119
121 m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
122#endif
123}
124
125
126BOARD* PCB_TEST_FRAME_BASE::LoadAndDisplayBoard( const std::string& filename )
127{
129 BOARD* brd = nullptr;
130
131 try
132 {
133 brd = pi->LoadBoard( wxString( filename.c_str() ), nullptr, nullptr );
134 }
135 catch( const IO_ERROR& ioe )
136 {
137 wxPrintf( "Board Loading Error: '%s'\n", ioe.Problem() );
138 return nullptr;
139 }
140
141 //SetBoard( brd );
142
143 return brd;
144}
145
146void PCB_TEST_FRAME_BASE::SetSelectableItemTypes( const std::vector<KICAD_T> aTypes )
147{
148 m_selectionTool->SetSelectableItemTypes( aTypes );
149}
150
151
152
154{
155 // SUPERSAMPLING_X4;
157
158 DPI_SCALING_COMMON dpi( Pgm().GetCommonSettings(), aParent );
160
161 m_galPanel = std::make_shared<PCB_DRAW_PANEL_GAL>( aParent, -1, wxPoint( 0, 0 ),
162 wxDefaultSize, m_displayOptions, aGalType );
163 m_galPanel->UpdateColors();
164
165 m_galPanel->SetEvtHandlerEnabled( true );
166 m_galPanel->SetFocus();
167 m_galPanel->Show( true );
168 m_galPanel->Raise();
169 m_galPanel->StartDrawing();
170
171 auto gal = m_galPanel->GetGAL();
172
173 gal->SetGridVisibility( true );
174 gal->SetGridSize( VECTOR2D( 100000.0, 100000.0 ) );
175 gal->SetGridOrigin( VECTOR2D( 0.0, 0.0 ) );
176
177 //m_galPanel->Connect( wxEVT_MOTION,
178 //wxMouseEventHandler( PCB_TEST_FRAME::OnMotion ), nullptr, this );
179
180 m_galPanel->GetViewControls()->ShowCursor( true );
181
182
183
184 //SetBoard( std::make_shared<BOARD>( new BOARD ));
185}
186
187
189{
190 m_mruPath = wxGetCwd();
191}
192
193
195{
196
197}
198
199
201{
203
206 mgr.GetColorSettings()->Load();
207}
208
210{
211 auto tool = m_toolManager->FindTool("pcbnew.InteractiveSelection");
212 if (!tool)
213 return;
214
215 auto casted = static_cast<PCB_TEST_SELECTION_TOOL*>( tool );
216
217 casted->SetSelectionHook( aHook );
218}
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
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.