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 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 //#define USE_TOOL_MANAGER
27 
28 #include <wx/timer.h>
29 #include <wx/math.h>
30 #include <wx/log.h>
31 #include <wx/popupwin.h>
32 #include <wx/cmdline.h>
33 #include <profile.h>
34 
35 #include <pgm_base.h>
38 #include <layer_ids.h>
39 
41 #include <view/view.h>
42 #include <class_draw_panel_gal.h>
43 #include <pcb_draw_panel_gal.h>
44 #include <view/wx_view_controls.h>
45 #include <pcb_painter.h>
46 
47 #include <pad.h>
48 #include <footprint.h>
49 #include <board.h>
50 
51 #include <pcb_track.h>
52 #include <pcb_painter.h>
53 #include <pcb_edit_frame.h>
54 
56 
57 #include <io_mgr.h>
58 #include <memory>
59 #include <set>
60 
61 #include <tool/actions.h>
62 #include <tool/tool_manager.h>
63 #include <tool/tool_dispatcher.h>
64 #include <tools/pcb_tool_base.h>
65 #include <tools/pcb_actions.h>
68 
69 #include "pcb_test_frame.h"
70 
71 #include <trace_helpers.h>
72 
73 using namespace KIGFX;
74 
75 
76 void PCB_TEST_FRAME_BASE::SetBoard( std::shared_ptr<BOARD> b )
77 {
78  m_board = b;
79 
80  PROF_TIMER cntConnectivity( "connectivity-build" );
81  m_board->GetConnectivity()->Build( m_board.get() );
82  cntConnectivity.Stop();
83 
84  PROF_TIMER cntView("view-build");
85  m_galPanel->DisplayBoard( m_board.get() );
86  cntView.Stop();
87 
88  m_galPanel->UpdateColors();
89 
90  KI_TRACE( traceGalProfile, "%s\n", cntConnectivity.to_string() );
91  KI_TRACE( traceGalProfile, "%s\n", cntView.to_string() );
92 
93 #ifdef USE_TOOL_MANAGER
94  m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(),
95  m_galPanel->GetViewControls(), nullptr );
96 
97  m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
98 #endif
99 }
100 
101 
102 BOARD* PCB_TEST_FRAME_BASE::LoadAndDisplayBoard( const std::string& filename )
103 {
104  PLUGIN::RELEASER pi( new PCB_PLUGIN );
105  BOARD* brd = nullptr;
106 
107  try
108  {
109  brd = pi->Load( wxString( filename.c_str() ), nullptr, nullptr );
110  }
111  catch( const IO_ERROR& ioe )
112  {
113  wxPrintf( "Board Loading Error: '%s'\n", ioe.Problem() );
114  return nullptr;
115  }
116 
117  //SetBoard( brd );
118 
119  return brd;
120 }
121 
122 
123 class TEST_ACTIONS : public ACTIONS
124 {
125 };
126 
127 
129 {
130  // SUPERSAMPLING_X4;
131  m_displayOptions.gl_antialiasing_mode = KIGFX::OPENGL_ANTIALIASING_MODE::NONE;
132 
133  m_galPanel = std::make_shared<PCB_DRAW_PANEL_GAL>( aParent, -1, wxPoint( 0, 0 ),
134  wxDefaultSize, m_displayOptions, aGalType );
135  m_galPanel->UpdateColors();
136 
137  m_galPanel->SetEvtHandlerEnabled( true );
138  m_galPanel->SetFocus();
139  m_galPanel->Show( true );
140  m_galPanel->Raise();
141  m_galPanel->StartDrawing();
142 
143  auto gal = m_galPanel->GetGAL();
144 
145  gal->SetGridVisibility( true );
146  gal->SetGridSize( VECTOR2D( 100000.0, 100000.0 ) );
147  gal->SetGridOrigin( VECTOR2D( 0.0, 0.0 ) );
148 
149  //m_galPanel->Connect( wxEVT_MOTION,
150  //wxMouseEventHandler( PCB_TEST_FRAME::OnMotion ), nullptr, this );
151 
152  m_galPanel->GetViewControls()->ShowCursor( true );
153 
154 #ifdef USE_TOOL_MANAGER
155  m_toolManager = std::make_unique<TOOL_MANAGER>( );
156  m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(),
157  m_galPanel->GetViewControls(), nullptr );
158 
159  m_pcbActions = std::make_unique<TEST_ACTIONS>( );
160  m_toolDispatcher = std::make_unique<TOOL_DISPATCHER>( m_toolManager.get() );
161 
162  //m_toolManager->RegisterTool( new PCB_SELECTION_TOOL );
163  createUserTools();
164 
165  m_toolManager->InitTools();
166  m_toolManager->InvokeTool( "test.DefaultTool" );
167 #endif
168 
169  //SetBoard( std::make_shared<BOARD>( new BOARD ));
170 }
171 
172 
174 {
175 }
176 
177 
179 {
180 
181 }
182 
183 
185 {
186  auto cs = Pgm().GetSettingsManager().GetColorSettings();
187  //cs->SetColorContext( COLOR_CONTEXT::PCB );
188  cs->Load();
189 }
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:243
Model changes (required full reload)
Definition: tool_base.h:80
A PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
Definition: pcb_plugin.h:141
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
void createView(wxWindow *aParent, PCB_DRAW_PANEL_GAL::GAL_TYPE aGalType=PCB_DRAW_PANEL_GAL::GAL_TYPE_OPENGL)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:46
virtual BOARD * LoadAndDisplayBoard(const std::string &filename)
WX_VIEW_CONTROLS class definition.
Releases a PLUGIN in the context of a potential thrown exception through its destructor.
Definition: io_mgr.h:555
virtual ~PCB_TEST_FRAME_BASE()
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
wxLogTrace helper definitions.
std::string to_string()
Definition: profile.h:153
A small class to help profiling.
Definition: profile.h:46
void Stop()
Save the time when this function was called, and set the counter stane to stop.
Definition: profile.h:86
see class PGM_BASE
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:191
virtual void SetBoard(std::shared_ptr< BOARD > b)
#define KI_TRACE(...)
Gather all the actions that are shared by tools.
Definition: actions.h:40
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75