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 
26 #include <fctsys.h>
27 #include <gr_basic.h>
28 #include <pcb_edit_frame.h>
29 #include <dialog_helpers.h>
30 
31 #include <class_board.h>
32 #include <class_module.h>
33 
34 #include <pcbnew.h>
35 #include <pcbnew_id.h>
36 #include "footprint_wizard_frame.h"
39 #include <base_units.h>
40 #include <widgets/wx_grid.h>
41 
42 #include <tool/tool_manager.h>
43 
45 {
46  wxString msg;
47  int page;
48 
49  switch( event.GetId() )
50  {
52  m_pageList->SetSelection( m_pageList->GetSelection() + 1, true );
53  ClickOnPageList( event );
54  break;
55 
57  page = m_pageList->GetSelection() - 1;
58 
59  if( page < 0 )
60  page = 0;
61 
62  m_pageList->SetSelection( page, true );
63  ClickOnPageList( event );
64  break;
65 
66  default:
67  wxLogDebug( wxT( "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions error: id = %d" ),
68  event.GetId() );
69  break;
70  }
71 }
72 
73 
74 /* Displays the name of the current opened library in the caption */
76 {
77  wxString msg;
78 
79  msg = _( "Footprint Wizard" );
80  msg << wxT( " [" );
81 
82  if( !m_wizardName.IsEmpty() )
83  msg << m_wizardName;
84  else
85  msg += _( "no wizard selected" );
86 
87  msg << wxT( "]" );
88 
89  SetTitle( msg );
90 }
91 
92 
94 {
95  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
96 
97  if( !footprintWizard )
98  return;
99 
101 
102  // Delete the current footprint
104 
105  // Creates the module
106  wxString msg;
107  MODULE* module = footprintWizard->GetFootprint( &msg );
108  DisplayBuildMessage( msg );
109 
110  if( module )
111  {
112  // Add the object to board
113  GetBoard()->Add( module, ADD_APPEND );
114  module->SetPosition( wxPoint( 0, 0 ) );
115  }
116  else
117  {
118  DBG(printf( "footprintWizard->GetFootprint() returns NULL\n" );)
119  }
120 
121  updateView();
122  GetCanvas()->Refresh();
123 }
124 
125 
127 {
128  m_buildMessageBox->SetValue( aMessage );
129 }
130 
131 
133 {
134  if( m_wizardName.Length() == 0 )
135  return NULL;
136 
138 
139  if( !footprintWizard )
140  {
141  wxMessageBox( _( "Couldn't reload footprint wizard" ) );
142  return NULL;
143  }
144 
145  return footprintWizard;
146 }
147 
148 
150 {
152 
153  if( footprintWizard && m_modal_ret_val )
154  {
155  wxString msg;
156  MODULE * footprint = footprintWizard->GetFootprint( &msg );
157  DisplayBuildMessage( msg );
158 
159  return footprint;
160  }
161 
162  return NULL;
163 }
164 
165 
167 {
168  DIALOG_FOOTPRINT_WIZARD_LIST wizardSelector( this );
169 
170  if( wizardSelector.ShowModal() != wxID_OK )
171  return;
172 
173  FOOTPRINT_WIZARD* footprintWizard = wizardSelector.GetWizard();
174 
175  if( footprintWizard )
176  {
177  m_wizardName = footprintWizard->GetName();
178  m_wizardDescription = footprintWizard->GetDescription();
179 
180  footprintWizard->ResetParameters();
181  }
182  else
183  {
184  m_wizardName.Empty();
185  m_wizardDescription.Empty();
186  }
187 
188  ReloadFootprint();
189  Zoom_Automatique( false );
193 }
194 
195 
196 void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
197 {
199  updateView();
200 }
201 
202 void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event )
203 {
204  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
205 
206  if ( footprintWizard == NULL )
207  return;
208 
209  footprintWizard->ResetParameters();
210 
211  // Reload
213  ReloadFootprint();
215 }
216 
217 
219 {
220  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
221 
222  if( !footprintWizard )
223  return;
224 
225  if( m_parameterGridPage < 0 )
226  return;
227 
228  wxArrayString prmValues = footprintWizard->GetParameterValues( m_parameterGridPage );
229  wxArrayString ptList = footprintWizard->GetParameterTypes( m_parameterGridPage );
230 
231  bool has_changed = false;
232  int count = m_parameterGrid->GetNumberRows();
233 
234  for( int prm_id = 0; prm_id < count; ++prm_id )
235  {
236  wxString value = m_parameterGrid->GetCellValue( prm_id, WIZ_COL_VALUE );
237 
238  if( prmValues[prm_id] != value )
239  {
240  has_changed = true;
241  prmValues[prm_id] = value;
242  }
243  }
244 
245  if( has_changed )
246  {
247  wxString res = footprintWizard->SetParameterValues( m_parameterGridPage, prmValues );
248 
249  if( !res.IsEmpty() )
250  wxMessageBox( res );
251 
252  ReloadFootprint();
254  }
255 }
256 
bool m_modal_ret_val
Definition: kiway_player.h:192
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:82
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.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
int m_parameterGridPage
the page currently displayed by m_parameterGrid it is most of time the m_pageList selection,...
virtual wxArrayString GetParameterTypes(int aPage)=0
Function GetParameterTypes.
WX_GRID * m_parameterGrid
The list of parameters.
void ReloadFootprint()
Function ReloadFootprint Reloads the current footprint.
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.
void ReCreatePageList()
Function ReCreatePageList Creates or recreates the list of parameter pages for the current wizard.
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.
void SetPosition(const wxPoint &aPos) override
FOOTPRINT_WIZARD * GetMyWizard()
Function GetMyWizard Reloads the wizard by name.
#define _(s)
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
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.
virtual wxString GetName()=0
Function GetName.
void SelectFootprintWizard()
Function SelectFootprintWizard Shows the list of footprint wizards available into the system.
void DeleteAllModules()
Removes all modules from the deque and frees the memory associated with them.
Definition: class_board.h:293
void SelectCurrentWizard(wxCommandEvent &event)
virtual wxArrayString GetParameterValues(int aPage)=0
Function GetParameterValues.
#define DBG(x)
Definition: fctsys.h:33
void Process_Special_Functions(wxCommandEvent &event)
TOOL_MANAGER * m_toolManager
Module description (excepted pads)
BOARD * GetBoard() const
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...
Class FOOTPRINT_WIZARD This is the parent class from where any footprint wizard class must derive.
wxString m_wizardDescription
description of the wizard