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  msg << wxT( "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions error: id = " )
72  << event.GetId();
73  wxMessageBox( msg );
74  break;
75  }
76 }
77 
78 
79 /* Function OnLeftClick
80  * Captures a left click event in the dialog
81  *
82  */
83 void FOOTPRINT_WIZARD_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
84 {
85 }
86 
87 
88 /* Function OnRightClick
89  * Captures a right click event in the dialog
90  *
91  */
92 bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
93 {
94  return true;
95 }
96 
97 
98 /* Displays the name of the current opened library in the caption */
100 {
101  wxString msg;
102 
103  msg = _( "Footprint Wizard" );
104  msg << wxT( " [" );
105 
106  if( !m_wizardName.IsEmpty() )
107  msg << m_wizardName;
108  else
109  msg += _( "no wizard selected" );
110 
111  msg << wxT( "]" );
112 
113  SetTitle( msg );
114 }
115 
116 
118 {
119  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
120 
121  if( !footprintWizard )
122  return;
123 
124  SetCurItem( NULL );
125 
126  if( IsGalCanvasActive() )
128 
129  // Delete the current footprint
131 
132  // Creates the module
133  wxString msg;
134  MODULE* module = footprintWizard->GetFootprint( &msg );
135  DisplayBuildMessage( msg );
136 
137  if( module )
138  {
139  // Add the object to board
140  GetBoard()->Add( module, ADD_APPEND );
141  module->SetPosition( wxPoint( 0, 0 ) );
142  }
143  else
144  {
145  DBG(printf( "footprintWizard->GetFootprint() returns NULL\n" );)
146  }
147 
148  updateView();
149  m_canvas->Refresh();
150 }
151 
152 
154 {
155  m_buildMessageBox->SetValue( aMessage );
156 }
157 
158 
160 {
161  if( m_wizardName.Length() == 0 )
162  return NULL;
163 
165 
166  if( !footprintWizard )
167  {
168  wxMessageBox( _( "Couldn't reload footprint wizard" ) );
169  return NULL;
170  }
171 
172  return footprintWizard;
173 }
174 
175 
177 {
179 
180  if( footprintWizard && m_modal_ret_val )
181  {
182  wxString msg;
183  MODULE * footprint = footprintWizard->GetFootprint( &msg );
184  DisplayBuildMessage( msg );
185 
186  return footprint;
187  }
188 
189  return NULL;
190 }
191 
192 
194 {
195  DIALOG_FOOTPRINT_WIZARD_LIST wizardSelector( this );
196 
197  if( wizardSelector.ShowModal() != wxID_OK )
198  return;
199 
200  FOOTPRINT_WIZARD* footprintWizard = wizardSelector.GetWizard();
201 
202  if( footprintWizard )
203  {
204  m_wizardName = footprintWizard->GetName();
205  m_wizardDescription = footprintWizard->GetDescription();
206 
207  footprintWizard->ResetParameters();
208  }
209  else
210  {
211  m_wizardName.Empty();
212  m_wizardDescription.Empty();
213  }
214 
215  ReloadFootprint();
216  Zoom_Automatique( false );
220 }
221 
222 
223 void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
224 {
226  updateView();
227 }
228 
229 void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event )
230 {
231  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
232 
233  if ( footprintWizard == NULL )
234  return;
235 
236  footprintWizard->ResetParameters();
237 
238  // Reload
240  ReloadFootprint();
242 }
243 
244 
246 {
247  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
248 
249  if( !footprintWizard )
250  return;
251 
252  if( m_parameterGridPage < 0 )
253  return;
254 
255  wxArrayString prmValues = footprintWizard->GetParameterValues( m_parameterGridPage );
256  wxArrayString ptList = footprintWizard->GetParameterTypes( m_parameterGridPage );
257 
258  bool has_changed = false;
259  int count = m_parameterGrid->GetNumberRows();
260 
261  for( int prm_id = 0; prm_id < count; ++prm_id )
262  {
263  wxString value = m_parameterGrid->GetCellValue( prm_id, WIZ_COL_VALUE );
264 
265  if( prmValues[prm_id] != value )
266  {
267  has_changed = true;
268  prmValues[prm_id] = value;
269  }
270  }
271 
272  if( has_changed )
273  {
274  wxString res = footprintWizard->SetParameterValues( m_parameterGridPage, prmValues );
275 
276  if( !res.IsEmpty() )
277  wxMessageBox( res );
278 
279  ReloadFootprint();
281  }
282 }
283 
284 
291 void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
292 {
293  if( !GetBoard() )
294  return;
295 
296  m_canvas->DrawBackGround( DC );
297  GetBoard()->Draw( m_canvas, DC, GR_COPY );
298 
299  MODULE* module = GetBoard()->m_Modules;
300 
301  if( module )
302  SetMsgPanel( module );
303 
304  m_canvas->DrawCrossHair( DC );
305 
306  ClearMsgPanel();
307 
308  if( module )
309  SetMsgPanel( module );
310 }
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.
The common library.
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:901
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:248
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