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 The 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, see <https://www.gnu.org/licenses/>.
20 */
21
22
23#include <wx/popupwin.h>
24#include <wx/cmdline.h>
25#include <core/profile.h>
26
27#include <pgm_base.h>
31#include <layer_ids.h>
32
34#include <dpi_scaling_common.h>
36#include <pcb_draw_panel_gal.h>
38#include <pcb_painter.h>
39#include <pcb_actions.h>
40#include <functional>
41
42#include <pad.h>
43#include <footprint.h>
44#include <board.h>
45#include <pcb_track.h>
46#include <pcb_edit_frame.h>
47
50
51#include <pcb_io/pcb_io_mgr.h>
53
54#include <memory>
55
56#include <trace_helpers.h>
57#include <tool/tool_manager.h>
59
60#include "pcb_test_frame.h"
62
63using namespace KIGFX;
64
65void PCB_TEST_FRAME_BASE::SetBoard( std::shared_ptr<BOARD> b )
66{
67 m_board = b;
68 printf("TestFrameBase::SetBoard %p\n", b.get() );
69
70 PROF_TIMER cntConnectivity( "connectivity-build" );
71 m_board->BuildListOfNets();
72 m_board->BuildConnectivity();
73 cntConnectivity.Show();
74
75 PROF_TIMER cntView("view-build");
76 m_galPanel->DisplayBoard( m_board.get() );
77 cntView.Show();
78
79 PROF_TIMER cntFromTo("fromto-cache-update");
80 m_board->GetConnectivity()->GetFromToCache()->Rebuild( m_board.get() );
81 cntFromTo.Show();
82
83 m_galPanel->UpdateColors();
84
85 wxLogTrace( traceGalProfile, "%s", cntConnectivity.to_string() );
86 wxLogTrace( traceGalProfile, "%s", cntView.to_string() );
87
88#ifdef USE_TOOL_MANAGER
90 PCBNEW_SETTINGS* cfg = mgr.RegisterSettings( new PCBNEW_SETTINGS, false );
91
93
94 m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(),
95 m_galPanel->GetViewControls(), cfg, this );
96
98
100
101 m_toolManager->RegisterTool( m_selectionTool.get() );
102
104
105
106 for( TOOL_BASE* tool : m_toolManager->Tools() )
107 {
108 if( PCB_TOOL_BASE* pcbTool = dynamic_cast<PCB_TOOL_BASE*>( tool ) )
109 pcbTool->SetIsBoardEditor( true );
110 }
111
112 m_toolManager->InitTools();
113
114 m_galPanel->SetEventDispatcher( m_toolDispatcher );
115
117 m_toolManager->InvokeTool( "common.InteractiveSelection" );
118#endif
119}
120
121
122BOARD* PCB_TEST_FRAME_BASE::LoadAndDisplayBoard( const std::string& filename )
123{
125 BOARD* brd = nullptr;
126
127 try
128 {
129 brd = pi->LoadBoard( wxString( filename.c_str() ), nullptr, nullptr );
130 }
131 catch( const IO_ERROR& ioe )
132 {
133 wxPrintf( "Board Loading Error: '%s'\n", ioe.Problem() );
134 return nullptr;
135 }
136
137 //SetBoard( brd );
138
139 return brd;
140}
141
142void PCB_TEST_FRAME_BASE::SetSelectableItemTypes( const std::vector<KICAD_T> aTypes )
143{
144 m_selectionTool->SetSelectableItemTypes( aTypes );
145}
146
147
148
150{
151 // SUPERSAMPLING_X4;
153
154 DPI_SCALING_COMMON dpi( Pgm().GetCommonSettings(), aParent );
155 m_displayOptions.m_scaleFactor = dpi.GetScaleFactor();
156
157 m_galPanel = std::make_shared<PCB_DRAW_PANEL_GAL>( aParent, -1, wxPoint( 0, 0 ),
158 wxDefaultSize, m_displayOptions, aGalType );
159 m_galPanel->UpdateColors();
160
161 m_galPanel->SetEvtHandlerEnabled( true );
162 m_galPanel->SetFocus();
163 m_galPanel->Show( true );
164 m_galPanel->Raise();
165 m_galPanel->StartDrawing();
166
167 auto gal = m_galPanel->GetGAL();
168
169 gal->SetGridVisibility( true );
170 gal->SetGridSize( VECTOR2D( 100000.0, 100000.0 ) );
171 gal->SetGridOrigin( VECTOR2D( 0.0, 0.0 ) );
172
173 //m_galPanel->Connect( wxEVT_MOTION,
174 //wxMouseEventHandler( PCB_TEST_FRAME::OnMotion ), nullptr, this );
175
176 m_galPanel->GetViewControls()->ShowCursor( true );
177
178
179
180 //SetBoard( std::make_shared<BOARD>( new BOARD ));
181}
182
183
188
189
194
195
204
206{
207 auto tool = m_toolManager->FindTool( "common.InteractiveSelection" );
208 if (!tool)
209 return;
210
211 auto casted = static_cast<PCB_TEST_SELECTION_TOOL*>( tool );
212
213 casted->SetSelectionHook( aHook );
214}
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:320
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.
virtual const wxString Problem() const
what was the problem?
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
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()
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:126
A small class to help profiling.
Definition profile.h:46
void Show(std::ostream &aStream=std::cerr)
Print the elapsed time (in a suitable unit) to a stream.
Definition profile.h:103
std::string to_string()
Definition profile.h:153
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
Retrieve a color settings object that applications can read colors from.
TOOL_MANAGER * m_toolManager
TOOL_DISPATCHER * m_toolDispatcher
Base abstract interface for all kinds of tools.
Definition tool_base.h:62
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition tool_base.h:76
Master controller class:
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 eda_group.h:29
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
#define DEFAULT_THEME
wxLogTrace helper definitions.
VECTOR2< double > VECTOR2D
Definition vector2d.h:682
WX_VIEW_CONTROLS class definition.