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 <tomasz.wlostowski@cern.ch>
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 
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 
72 using namespace KIGFX;
73 
74 
75 void PCB_TEST_FRAME_BASE::SetBoard( std::shared_ptr<BOARD> b )
76 {
77  m_board = b;
78 
79  m_board->GetConnectivity()->Build( m_board.get() );
80  m_galPanel->DisplayBoard( m_board.get() );
81  m_galPanel->UpdateColors();
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 
92 BOARD* PCB_TEST_FRAME_BASE::LoadAndDisplayBoard( const std::string& filename )
93 {
94  PLUGIN::RELEASER pi( new PCB_IO );
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 
113 class TEST_ACTIONS : public ACTIONS
114 {
115 };
116 
117 
119 {
120  // SUPERSAMPLING_X4;
121  m_displayOptions.gl_antialiasing_mode = KIGFX::OPENGL_ANTIALIASING_MODE::NONE;
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 );
153  createUserTools();
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 }
A PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:236
Model changes (required full reload)
Definition: tool_base.h:80
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:622
see class PGM_BASE
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
virtual void SetBoard(std::shared_ptr< BOARD > b)
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