KiCad PCB EDA Suite
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>
34#include <layer_ids.h>
35
38#include <pcb_draw_panel_gal.h>
40#include <pcb_painter.h>
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
49
50#include <io_mgr.h>
51#include <memory>
52
53#include <tool/actions.h>
54#include <tool/tool_manager.h>
56#include <tools/pcb_tool_base.h>
58
59#include "pcb_test_frame.h"
60
61#include <trace_helpers.h>
62
63using namespace KIGFX;
64
65
66void PCB_TEST_FRAME_BASE::SetBoard( std::shared_ptr<BOARD> b )
67{
68 m_board = b;
69
70 PROF_TIMER cntConnectivity( "connectivity-build" );
71 m_board->BuildConnectivity();
72 cntConnectivity.Stop();
73
74 PROF_TIMER cntView("view-build");
75 m_galPanel->DisplayBoard( m_board.get() );
76 cntView.Stop();
77
78 m_galPanel->UpdateColors();
79
80 KI_TRACE( traceGalProfile, "%s\n", cntConnectivity.to_string() );
81 KI_TRACE( traceGalProfile, "%s\n", cntView.to_string() );
82
83#ifdef USE_TOOL_MANAGER
84 m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(),
85 m_galPanel->GetViewControls(), nullptr );
86
87 m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
88#endif
89}
90
91
92BOARD* PCB_TEST_FRAME_BASE::LoadAndDisplayBoard( const std::string& filename )
93{
95 BOARD* brd = nullptr;
96
97 try
98 {
99 brd = pi->Load( wxString( filename.c_str() ), nullptr, nullptr );
100 }
101 catch( const IO_ERROR& ioe )
102 {
103 wxPrintf( "Board Loading Error: '%s'\n", ioe.Problem() );
104 return nullptr;
105 }
106
107 //SetBoard( brd );
108
109 return brd;
110}
111
112
113class TEST_ACTIONS : public ACTIONS
114{
115};
116
117
119{
120 // SUPERSAMPLING_X4;
122
123 m_galPanel = std::make_shared<PCB_DRAW_PANEL_GAL>( aParent, -1, wxPoint( 0, 0 ),
124 wxDefaultSize, m_displayOptions, aGalType );
125 m_galPanel->UpdateColors();
126
127 m_galPanel->SetEvtHandlerEnabled( true );
128 m_galPanel->SetFocus();
129 m_galPanel->Show( true );
130 m_galPanel->Raise();
131 m_galPanel->StartDrawing();
132
133 auto gal = m_galPanel->GetGAL();
134
135 gal->SetGridVisibility( true );
136 gal->SetGridSize( VECTOR2D( 100000.0, 100000.0 ) );
137 gal->SetGridOrigin( VECTOR2D( 0.0, 0.0 ) );
138
139 //m_galPanel->Connect( wxEVT_MOTION,
140 //wxMouseEventHandler( PCB_TEST_FRAME::OnMotion ), nullptr, this );
141
142 m_galPanel->GetViewControls()->ShowCursor( true );
143
144#ifdef USE_TOOL_MANAGER
145 m_toolManager = std::make_unique<TOOL_MANAGER>( );
146 m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(),
147 m_galPanel->GetViewControls(), nullptr );
148
149 m_pcbActions = std::make_unique<TEST_ACTIONS>( );
150 m_toolDispatcher = std::make_unique<TOOL_DISPATCHER>( m_toolManager.get() );
151
152 //m_toolManager->RegisterTool( new PCB_SELECTION_TOOL );
154
155 m_toolManager->InitTools();
156 m_toolManager->InvokeTool( "test.DefaultTool" );
157#endif
158
159 //SetBoard( std::make_shared<BOARD>( new BOARD ));
160}
161
162
164{
165}
166
167
169{
170
171}
172
173
175{
176 auto cs = Pgm().GetSettingsManager().GetColorSettings();
177 //cs->SetColorContext( COLOR_CONTEXT::PCB );
178 cs->Load();
179}
Gather all the actions that are shared by tools.
Definition: actions.h:41
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
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
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
A PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
Definition: pcb_plugin.h:258
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:564
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:46
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
@ MODEL_RELOAD
Model changes (required full reload)
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:266
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
wxLogTrace helper definitions.
#define KI_TRACE(aWhat,...)
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617
WX_VIEW_CONTROLS class definition.