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  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 //#define USE_TOOL_MANAGER
26 
27 #include <wx/timer.h>
28 #include <wx/math.h>
29 #include <wx/log.h>
30 #include <wx/popupwin.h>
31 #include <wx/cmdline.h>
32 
33 
34 #include <pgm_base.h>
38 
40 #include <view/view.h>
41 #include <class_draw_panel_gal.h>
42 #include <pcb_draw_panel_gal.h>
43 #include <view/wx_view_controls.h>
44 #include <pcb_painter.h>
45 
46 #include <pad.h>
47 #include <footprint.h>
48 #include <board.h>
49 #include <track.h>
50 
51 #include <pcb_painter.h>
52 #include <pcb_edit_frame.h>
53 
55 
56 #include <io_mgr.h>
57 #include <memory>
58 #include <set>
59 
60 #include <tool/actions.h>
61 #include <tool/tool_manager.h>
62 #include <tool/tool_dispatcher.h>
63 #include <tools/pcb_tool_base.h>
64 #include <tools/pcb_actions.h>
67 
68 #include "pcb_test_frame.h"
69 
70 
71 
72 using namespace KIGFX;
73 
74 void PCB_TEST_FRAME_BASE::SetBoard( std::shared_ptr<BOARD> b )
75 {
76  m_board = b;
77 
78  m_board->GetConnectivity()->Build( m_board.get() );
79  m_galPanel->DisplayBoard( m_board.get() );
80  m_galPanel->UpdateColors();
81 
82 #ifdef USE_TOOL_MANAGER
83 
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() ), NULL, NULL );
100  }
101  catch( const IO_ERROR& ioe )
102  {
103  wxString msg = wxString::Format( _( "Error loading board.\n%s" ),
104  ioe.Problem() );
105 
106  printf( "%s\n", (const char*) msg.mb_str() );
107  return nullptr;
108  }
109 
110  //SetBoard( brd );
111 
112  return brd;
113 }
114 
115 class TEST_ACTIONS : public ACTIONS
116 {
117  virtual OPT<TOOL_EVENT> TranslateLegacyId( int aId ) override
118  {
119  return OPT<TOOL_EVENT> ();
120  }
121 };
122 
124 {
125  m_displayOptions.gl_antialiasing_mode = KIGFX::OPENGL_ANTIALIASING_MODE::NONE; //SUPERSAMPLING_X4;
126 
127  m_galPanel = std::make_shared<PCB_DRAW_PANEL_GAL>( aParent, -1, wxPoint( 0,
128  0 ), wxDefaultSize, m_displayOptions, aGalType );
129  m_galPanel->UpdateColors();
130 
131  m_galPanel->SetEvtHandlerEnabled( true );
132  m_galPanel->SetFocus();
133  m_galPanel->Show( true );
134  m_galPanel->Raise();
135  m_galPanel->StartDrawing();
136 
137  auto gal = m_galPanel->GetGAL();
138 
139  gal->SetGridVisibility( true );
140  gal->SetGridSize( VECTOR2D( 100000.0, 100000.0 ) );
141  gal->SetGridOrigin( VECTOR2D( 0.0, 0.0 ) );
142 
143  //m_galPanel->Connect( wxEVT_MOTION,
144  //wxMouseEventHandler( PCB_TEST_FRAME::OnMotion ), NULL, this );
145 
146  m_galPanel->GetViewControls()->ShowCursor( true );
147 
148 #ifdef USE_TOOL_MANAGER
149  m_toolManager = std::make_unique<TOOL_MANAGER>( );
150  m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(),
151  m_galPanel->GetViewControls(), nullptr );
152 
153  m_pcbActions = std::make_unique<TEST_ACTIONS>( );
154  m_toolDispatcher = std::make_unique<TOOL_DISPATCHER>( m_toolManager.get(), m_pcbActions.get() );
155 
156  //m_toolManager->RegisterTool( new PCB_SELECTION_TOOL );
157  createUserTools();
158 
159  m_toolManager->InitTools();
160  m_galPanel->SetEventDispatcher( m_toolDispatcher.get() );
161  m_toolManager->InvokeTool( "test.DefaultTool" );
162 #endif
163 
164  //SetBoard( std::make_shared<BOARD>( new BOARD ));
165 }
166 
168 {
169 }
170 
171 
173 {
174 
175 }
176 
178 {
179  auto cs = Pgm().GetSettingsManager().GetColorSettings();
180  //cs->SetColorContext( COLOR_CONTEXT::PCB );
181  cs->Load();
182 }
A PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
virtual OPT< TOOL_EVENT > TranslateLegacyId(int aId) override
Translate legacy tool ids to the corresponding TOOL_ACTION name.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
Model changes (required full reload)
Definition: tool_base.h:81
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:45
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:545
virtual ~PCB_TEST_FRAME_BASE()
#define NULL
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
see class PGM_BASE
Board layer functions and definitions.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:189
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetBoard(std::shared_ptr< BOARD > b)
boost::optional< T > OPT
Definition: optional.h:7
Gather all the actions that are shared by tools.
Definition: actions.h:43
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75