KiCad PCB EDA Suite
footprint_wizard.cpp
Go to the documentation of this file.
1 
5 #include <fctsys.h>
6 #include <gr_basic.h>
7 #include <class_drawpanel.h>
8 #include <wxPcbStruct.h>
9 #include <dialog_helpers.h>
10 //#include <3d_viewer/eda_3d_viewer.h>
11 
12 #include <class_board.h>
13 #include <class_module.h>
14 
15 #include <pcbnew.h>
16 #include <pcbnew_id.h>
17 #include "footprint_wizard_frame.h"
20 #include <base_units.h>
21 
22 
24 {
25  wxString msg;
26  int page;
27 
28  switch( event.GetId() )
29  {
31  m_pageList->SetSelection( m_pageList->GetSelection() + 1, true );
32  ClickOnPageList( event );
33  break;
34 
36  page = m_pageList->GetSelection() - 1;
37 
38  if( page < 0 )
39  page = 0;
40 
41  m_pageList->SetSelection( page, true );
42  ClickOnPageList( event );
43  break;
44 
45  default:
46  msg << wxT( "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions error: id = " )
47  << event.GetId();
48  wxMessageBox( msg );
49  break;
50  }
51 }
52 
53 
54 /* Function OnLeftClick
55  * Captures a left click event in the dialog
56  *
57  */
58 void FOOTPRINT_WIZARD_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
59 {
60 }
61 
62 
63 /* Function OnRightClick
64  * Captures a right click event in the dialog
65  *
66  */
67 bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
68 {
69  return true;
70 }
71 
72 
73 /* Displays the name of the current opened library in the caption */
75 {
76  wxString msg;
77 
78  msg = _( "Footprint Wizard" );
79  msg << wxT( " [" );
80 
81  if( !m_wizardName.IsEmpty() )
82  msg << m_wizardName;
83  else
84  msg += _( "no wizard selected" );
85 
86  msg << wxT( "]" );
87 
88  SetTitle( msg );
89 }
90 
91 
93 {
94  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
95 
96  if( !footprintWizard )
97  return;
98 
99  SetCurItem( NULL );
100  // Delete the current footprint
102 
103  // Creates the module
104  wxString msg;
105  MODULE* module = footprintWizard->GetFootprint( &msg );
106  DisplayBuildMessage( msg );
107 
108  if( module )
109  {
110  // Add the object to board
111  GetBoard()->Add( module, ADD_APPEND );
112  module->SetPosition( wxPoint( 0, 0 ) );
113  }
114  else
115  {
116  DBG(printf( "footprintWizard->GetFootprint() returns NULL\n" );)
117  }
118 
119  m_canvas->Refresh();
120 }
121 
122 
124 {
125  if( m_messagesFrame == NULL )
126  {
127  // Prepare the window to display the message generated by the footprint script builder
129  m_messagesFrame->Show( true );
130  }
131 
133 
134  if( !aMessage.IsEmpty() )
135  m_messagesFrame->PrintMessage( aMessage );
136 }
137 
138 
140 {
141  if( m_wizardName.Length() == 0 )
142  return NULL;
143 
145 
146  if( !footprintWizard )
147  {
148  wxMessageBox( _( "Couldn't reload footprint wizard" ) );
149  return NULL;
150  }
151 
152  return footprintWizard;
153 }
154 
155 
157 {
159 
160  if( footprintWizard && m_modal_ret_val )
161  {
162  wxString msg;
163  MODULE * footprint = footprintWizard->GetFootprint( &msg );
164  DisplayBuildMessage( msg );
165 
166  return footprint;
167  }
168 
169  return NULL;
170 }
171 
172 
174 {
175  DIALOG_FOOTPRINT_WIZARD_LIST wizardSelector( this );
176 
177  if( wizardSelector.ShowModal() != wxID_OK )
178  return;
179 
180  FOOTPRINT_WIZARD* footprintWizard = wizardSelector.GetWizard();
181 
182  if( footprintWizard )
183  {
184  m_wizardName = footprintWizard->GetName();
185  m_wizardDescription = footprintWizard->GetDescription();
186  }
187  else
188  {
189  m_wizardName.Empty();
190  m_wizardDescription.Empty();
191  }
192 
193  ReloadFootprint();
194  Zoom_Automatique( false );
198 }
199 
200 
201 void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
202 {
204 }
205 
206 void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event )
207 {
208  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
209 
210  if ( footprintWizard == NULL )
211  return;
212 
213  footprintWizard->ResetParameters();
214 
215  // Reload
217  ReloadFootprint();
219 
220 }
221 
222 
224 {
225  int page = m_pageList->GetSelection();
226 
227  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
228 
229  if( !footprintWizard )
230  return;
231 
232  if( page < 0 )
233  return;
234 
235  wxArrayString prmValues = footprintWizard->GetParameterValues( page );
236  wxArrayString ptList = footprintWizard->GetParameterTypes( page );
237 
238  bool has_changed = false;
239  int count = m_parameterGrid->GetNumberRows();
240 
241  // Skip extra event, useless
242  if( event.GetString() == m_parameterGrid->GetCellValue( event.GetRow(), WIZ_COL_VALUE ) )
243  return;
244 
245  for( int prm_id = 0; prm_id < count; ++prm_id )
246  {
247  wxString value = m_parameterGrid->GetCellValue( prm_id, WIZ_COL_VALUE );
248 
249  if( prmValues[prm_id] != value )
250  {
251  has_changed = true;
252  prmValues[prm_id] = value;
253  }
254  }
255 
256  if( has_changed )
257  {
258  wxString res = footprintWizard->SetParameterValues( page, prmValues );
259 
260  if( !res.IsEmpty() )
261  wxMessageBox( res );
262 
263  ReloadFootprint();
265  }
266 }
267 
268 
275 void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
276 {
277  if( !GetBoard() )
278  return;
279 
280  m_canvas->DrawBackGround( DC );
281  GetBoard()->Draw( m_canvas, DC, GR_COPY );
282 
283  MODULE* module = GetBoard()->m_Modules;
284 
285  if( module )
286  SetMsgPanel( module );
287 
288  m_canvas->DrawCrossHair( DC );
289 
290  ClearMsgPanel();
291 
292  if( module )
293  SetMsgPanel( module );
294 }
bool m_modal_ret_val
Definition: kiway_player.h:250
wxString m_wizardName
name of the current wizard
void DisplayWizardInfos()
Function DisplayWizardInfos Shows all the details about the current wizard.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
Implementation of conversion functions that require both schematic and board internal units...
wxListBox * m_pageList
The list of pages.
virtual wxString SetParameterValues(int aPage, wxArrayString &aValues)=0
Function SetParameterValues.
static FOOTPRINT_WIZARD * GetWizard(wxString aName)
Function GetWizard.
void RedrawActiveWindow(wxDC *DC, bool EraseBg) override
Function RedrawActiveWindow Display the current selected component.
Class BOARD to handle a board.
void DrawCrossHair(wxDC *aDC, COLOR4D aColor=COLOR4D::WHITE)
Function DrawCrossHair draws the user cross hair.
Definition: draw_panel.cpp:216
FOOTPRINT_WIZARD_MESSAGES * m_messagesFrame
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.
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
Definition: basicframe.cpp:361
void DeleteAll()
Function DeleteAll deletes all items on the list and leaves the list empty.
Definition: dlist.cpp:41
void ClickOnPageList(wxCommandEvent &event)
void ReCreateParameterList()
Function ReCreateParameterList Creates the list of parameters for the current page.
void Zoom_Automatique(bool aWarpPointer)
Function Zoom_Automatique redraws the screen with best zoom level and the best centering that shows a...
Definition: zoom.cpp:77
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)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:751
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
>
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 PrintMessage(const wxString &aMessage)
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:92
DLIST< MODULE > m_Modules
Definition: class_board.h:243
virtual wxString GetName()=0
Function GetName.
void SelectFootprintWizard()
Function SelectFootprintWizard Shows the list of footprint wizards available into the system...
void DrawBackGround(wxDC *DC)
Function DrawBackGround.
Definition: draw_panel.cpp:666
void SelectCurrentWizard(wxCommandEvent &event)
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw.
Definition: tracepcb.cpp:135
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 ResetParameters()=0
Function ResetParameters Reset all wizard parameters to default values.
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:742
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