KiCad PCB EDA Suite
footprint_wizard_frame_functions.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) 2012 Miguel Angel Ajo Pelayo, miguelangel@nbee.es
5  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
6  * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors.
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 
30 #include <fctsys.h>
31 #include <gr_basic.h>
32 #include <class_drawpanel.h>
33 #include <pcb_edit_frame.h>
34 #include <dialog_helpers.h>
35 
36 #include <class_board.h>
37 #include <class_module.h>
38 
39 #include <pcbnew.h>
40 #include <pcbnew_id.h>
41 #include "footprint_wizard_frame.h"
44 #include <base_units.h>
45 
46 #include <tool/tool_manager.h>
47 
49 {
50  wxString msg;
51  int page;
52 
53  switch( event.GetId() )
54  {
56  m_pageList->SetSelection( m_pageList->GetSelection() + 1, true );
57  ClickOnPageList( event );
58  break;
59 
61  page = m_pageList->GetSelection() - 1;
62 
63  if( page < 0 )
64  page = 0;
65 
66  m_pageList->SetSelection( page, true );
67  ClickOnPageList( event );
68  break;
69 
70  default:
71  wxLogDebug( wxT( "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions error: id = %d" ),
72  event.GetId() );
73  break;
74  }
75 }
76 
77 
78 /* Function OnLeftClick
79  * Captures a left click event in the dialog
80  *
81  */
82 void FOOTPRINT_WIZARD_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
83 {
84 }
85 
86 
87 /* Function OnRightClick
88  * Captures a right click event in the dialog
89  *
90  */
91 bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
92 {
93  return true;
94 }
95 
96 
97 /* Displays the name of the current opened library in the caption */
99 {
100  wxString msg;
101 
102  msg = _( "Footprint Wizard" );
103  msg << wxT( " [" );
104 
105  if( !m_wizardName.IsEmpty() )
106  msg << m_wizardName;
107  else
108  msg += _( "no wizard selected" );
109 
110  msg << wxT( "]" );
111 
112  SetTitle( msg );
113 }
114 
115 
117 {
118  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
119 
120  if( !footprintWizard )
121  return;
122 
123  SetCurItem( NULL );
124 
125  if( IsGalCanvasActive() )
127 
128  // Delete the current footprint
130 
131  // Creates the module
132  wxString msg;
133  MODULE* module = footprintWizard->GetFootprint( &msg );
134  DisplayBuildMessage( msg );
135 
136  if( module )
137  {
138  // Add the object to board
139  GetBoard()->Add( module, ADD_APPEND );
140  module->SetPosition( wxPoint( 0, 0 ) );
141  }
142  else
143  {
144  DBG(printf( "footprintWizard->GetFootprint() returns NULL\n" );)
145  }
146 
147  updateView();
148  m_canvas->Refresh();
149 }
150 
151 
153 {
154  m_buildMessageBox->SetValue( aMessage );
155 }
156 
157 
159 {
160  if( m_wizardName.Length() == 0 )
161  return NULL;
162 
164 
165  if( !footprintWizard )
166  {
167  wxMessageBox( _( "Couldn't reload footprint wizard" ) );
168  return NULL;
169  }
170 
171  return footprintWizard;
172 }
173 
174 
176 {
178 
179  if( footprintWizard && m_modal_ret_val )
180  {
181  wxString msg;
182  MODULE * footprint = footprintWizard->GetFootprint( &msg );
183  DisplayBuildMessage( msg );
184 
185  return footprint;
186  }
187 
188  return NULL;
189 }
190 
191 
193 {
194  DIALOG_FOOTPRINT_WIZARD_LIST wizardSelector( this );
195 
196  if( wizardSelector.ShowModal() != wxID_OK )
197  return;
198 
199  FOOTPRINT_WIZARD* footprintWizard = wizardSelector.GetWizard();
200 
201  if( footprintWizard )
202  {
203  m_wizardName = footprintWizard->GetName();
204  m_wizardDescription = footprintWizard->GetDescription();
205 
206  footprintWizard->ResetParameters();
207  }
208  else
209  {
210  m_wizardName.Empty();
211  m_wizardDescription.Empty();
212  }
213 
214  ReloadFootprint();
215  Zoom_Automatique( false );
219 }
220 
221 
222 void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
223 {
225  updateView();
226 }
227 
228 void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event )
229 {
230  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
231 
232  if ( footprintWizard == NULL )
233  return;
234 
235  footprintWizard->ResetParameters();
236 
237  // Reload
239  ReloadFootprint();
241 }
242 
243 
245 {
246  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
247 
248  if( !footprintWizard )
249  return;
250 
251  if( m_parameterGridPage < 0 )
252  return;
253 
254  wxArrayString prmValues = footprintWizard->GetParameterValues( m_parameterGridPage );
255  wxArrayString ptList = footprintWizard->GetParameterTypes( m_parameterGridPage );
256 
257  bool has_changed = false;
258  int count = m_parameterGrid->GetNumberRows();
259 
260  for( int prm_id = 0; prm_id < count; ++prm_id )
261  {
262  wxString value = m_parameterGrid->GetCellValue( prm_id, WIZ_COL_VALUE );
263 
264  if( prmValues[prm_id] != value )
265  {
266  has_changed = true;
267  prmValues[prm_id] = value;
268  }
269  }
270 
271  if( has_changed )
272  {
273  wxString res = footprintWizard->SetParameterValues( m_parameterGridPage, prmValues );
274 
275  if( !res.IsEmpty() )
276  wxMessageBox( res );
277 
278  ReloadFootprint();
280  }
281 }
282 
283 
290 void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
291 {
292  if( !GetBoard() )
293  return;
294 
295  m_canvas->DrawBackGround( DC );
296  GetBoard()->Draw( m_canvas, DC, GR_COPY );
297 
298  MODULE* module = GetBoard()->m_Modules;
299 
300  if( module )
301  SetMsgPanel( module );
302 
303  m_canvas->DrawCrossHair( DC );
304 
305  ClearMsgPanel();
306 
307  if( module )
308  SetMsgPanel( module );
309 }
TOOL_MANAGER * m_toolManager
Definition: draw_frame.h:125
bool m_modal_ret_val
Definition: kiway_player.h:253
wxString m_wizardName
name of the current wizard
void DisplayWizardInfos()
Function DisplayWizardInfos Shows all the details about the current wizard.
Model changes (required full reload)
Definition: tool_base.h:83
Implementation of conversion functions that require both schematic and board internal units...
static FOOTPRINT_WIZARD * GetWizard(const wxString &aName)
Function GetWizard.
wxListBox * m_pageList
The list of pages.
virtual wxString SetParameterValues(int aPage, wxArrayString &aValues)=0
Function SetParameterValues.
void RedrawActiveWindow(wxDC *DC, bool EraseBg) override
Function RedrawActiveWindow Display the current selected component.
Class BOARD to handle a board.
int m_parameterGridPage
the page currently displayed by m_parameterGrid it is most of time the m_pageList selection...
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
virtual wxArrayString GetParameterTypes(int aPage)=0
Function GetParameterTypes.
BOARD * GetBoard() const
void ReloadFootprint()
Function ReloadFootprint Reloads the current footprint.
void DeleteAll()
Function DeleteAll deletes all items on the list and leaves the list empty.
Definition: dlist.cpp:44
void ClickOnPageList(wxCommandEvent &event)
void ReCreateParameterList()
Function ReCreateParameterList Creates the list of parameters for the current page.
virtual void Zoom_Automatique(bool aWarpPointer)
Redraw the screen with best zoom level and the best centering that shows all the page or the board...
wxGrid * m_parameterGrid
The list of parameters.
void ReCreatePageList()
Function ReCreatePageList Creates or recreates the list of parameter pages for the current wizard...
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual wxString GetDescription()=0
Function GetDescription.
void ParametersUpdated(wxGridEvent &event)
Function ParametersUpdated Update the footprint python parameters values from the values in grid...
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
Definition of file extensions used in Kicad.
void DisplayBuildMessage(wxString &aMessage)
Function DisplayBuildMessages Display the message generated by the python build footprint script...
Helper dialog and control classes.
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Function ResetTools() Resets all tools (i.e.
virtual void DrawCrossHair(wxDC *aDC=nullptr, COLOR4D aColor=COLOR4D::WHITE)
Function DrawCrossHair draws the user cross hair.
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:918
void SetPosition(const wxPoint &aPos) override
FOOTPRINT_WIZARD * GetMyWizard()
Function GetMyWizard Reloads the wizard by name.
bool OnRightClick(const wxPoint &MousePos, wxMenu *PopMenu) override
void DefaultParameters(wxCommandEvent &event)
virtual MODULE * GetFootprint(wxString *aMessage)=0
Function GetModule This method builds the module itself and returns it to the caller function...
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:123
DLIST< MODULE > m_Modules
Definition: class_board.h:249
virtual wxString GetName()=0
Function GetName.
void SelectFootprintWizard()
Function SelectFootprintWizard Shows the list of footprint wizards available into the system...
virtual void DrawBackGround(wxDC *DC)
Function DrawBackGround.
void SelectCurrentWizard(wxCommandEvent &event)
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw.
virtual wxArrayString GetParameterValues(int aPage)=0
Function GetParameterValues.
#define DBG(x)
Definition: fctsys.h:33
void Process_Special_Functions(wxCommandEvent &event)
Module description (excepted pads)
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
virtual void ResetParameters()=0
Function ResetParameters Reset all wizard parameters to default values.
void updateView()
rebuild the GAL view (reint tool manager, colors and drawings) must be run after any footprint change...
void ClearMsgPanel(void)
Clear all messages from the message panel.
void OnLeftClick(wxDC *DC, const wxPoint &MousePos) override
Class FOOTPRINT_WIZARD This is the parent class from where any footprint wizard class must derive...
wxString m_wizardDescription
description of the wizard