KiCad PCB EDA Suite
dialog_create_array.h
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) 2015 John Beard, john.j.beard@gmail.com
5  * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
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 #ifndef __DIALOG_CREATE_ARRAY__
26 #define __DIALOG_CREATE_ARRAY__
27 
28 // Include the wxFormBuider header base:
30 
31 #include <class_board_item.h>
32 #include <wxBasePcbFrame.h>
33 
34 #include <boost/bimap.hpp>
35 
37 {
38 private:
39 
41  {
47  };
48 
50  {
51  wxControl* control;
53  void* dest;
54  };
55 
56  std::vector<CONFIG_CTRL_T> ctrls;
57  bool& valid;
58 
59 protected:
60  CONFIG_SAVE_RESTORE_WINDOW( bool& validFlag ) :
61  valid( validFlag )
62  {}
63 
64  void Add( wxRadioBox* ctrl, int& dest )
65  {
66  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_RADIOBOX, (void*) &dest };
67 
68  ctrls.push_back( ctrlInfo );
69  }
70 
71  void Add( wxCheckBox* ctrl, bool& dest )
72  {
73  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_CHECKBOX, (void*) &dest };
74 
75  ctrls.push_back( ctrlInfo );
76  }
77 
78  void Add( wxTextCtrl* ctrl, wxString& dest )
79  {
80  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_TEXT, (void*) &dest };
81 
82  ctrls.push_back( ctrlInfo );
83  }
84 
85  void Add( wxChoice* ctrl, int& dest )
86  {
87  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_CHOICE, (void*) &dest };
88 
89  ctrls.push_back( ctrlInfo );
90  }
91 
92  void Add( wxNotebook* ctrl, int& dest )
93  {
94  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_TAB, (void*) &dest };
95 
96  ctrls.push_back( ctrlInfo );
97  }
98 
100  {
101  for( std::vector<CONFIG_CTRL_T>::const_iterator iter = ctrls.begin(), iend = ctrls.end();
102  iter != iend; ++iter )
103  {
104  switch( iter->type )
105  {
106  case CFG_CTRL_CHECKBOX:
107  *(bool*) iter->dest = static_cast<wxCheckBox*>( iter->control )->GetValue();
108  break;
109 
110  case CFG_CTRL_TEXT:
111  *(wxString*) iter->dest = static_cast<wxTextCtrl*>( iter->control )->GetValue();
112  break;
113 
114  case CFG_CTRL_CHOICE:
115  *(int*) iter->dest = static_cast<wxChoice*>( iter->control )->GetSelection();
116  break;
117 
118  case CFG_CTRL_RADIOBOX:
119  *(int*) iter->dest = static_cast<wxRadioBox*>( iter->control )->GetSelection();
120  break;
121 
122  case CFG_CTRL_TAB:
123  *(int*) iter->dest = static_cast<wxNotebook*>( iter->control )->GetSelection();
124  break;
125 
126  default:
127  wxASSERT_MSG( false, wxString(
128  "Unhandled control type for config store: " ) << iter->type );
129  }
130  }
131 
132  valid = true;
133  }
134 
136  {
137  if( !valid )
138  return;
139 
140  for( std::vector<CONFIG_CTRL_T>::const_iterator iter = ctrls.begin(), iend = ctrls.end();
141  iter != iend; ++iter )
142  {
143  switch( iter->type )
144  {
145  case CFG_CTRL_CHECKBOX:
146  static_cast<wxCheckBox*>( iter->control )->SetValue( *(bool*) iter->dest );
147  break;
148 
149  case CFG_CTRL_TEXT:
150  static_cast<wxTextCtrl*>( iter->control )->SetValue( *(wxString*) iter->dest );
151  break;
152 
153  case CFG_CTRL_CHOICE:
154  static_cast<wxChoice*>( iter->control )->SetSelection( *(int*) iter->dest );
155  break;
156 
157  case CFG_CTRL_RADIOBOX:
158  static_cast<wxRadioBox*>( iter->control )->SetSelection( *(int*) iter->dest );
159  break;
160 
161  case CFG_CTRL_TAB:
162  static_cast<wxNotebook*>( iter->control )->SetSelection( *(int*) iter->dest );
163  break;
164 
165  default:
166  wxASSERT_MSG( false, wxString(
167  "Unhandled control type for config restore: " ) << iter->type );
168  }
169  }
170  }
171 };
172 
175 {
176 public:
177 
179  {
182  };
183 
184  // NOTE: do not change order relative to charSetDescriptions
186  {
187  NUMBERING_NUMERIC = 0,
189  NUMBERING_ALPHA_NO_IOSQXZ,
196  };
197 
198  #define NUMBERING_TYPE_MAX NUMBERING_ALPHA_FULL
199 
204  {
206  m_type( aType ),
207  m_shouldNumber( false ),
208  m_numberingStartIsSpecified( false )
209  {}
210 
211  virtual ~ARRAY_OPTIONS() {};
212 
213  ARRAY_TYPE_T m_type;
214 
222  virtual void TransformItem( int n, BOARD_ITEM* item,
223  const wxPoint& rotPoint ) const = 0;
224  virtual int GetArraySize() const = 0;
225  virtual wxString GetItemNumber( int n ) const = 0;
226  virtual wxString InterpolateNumberIntoString( int n, const wxString& pattern ) const;
227 
232  bool ShouldNumberItems() const
233  {
234  return m_shouldNumber;
235  }
236 
243  {
244  return m_shouldNumber && m_numberingStartIsSpecified;
245  }
246 
247  protected:
248  static wxString getCoordinateNumber( int n, ARRAY_NUMBERING_TYPE_T type );
249 
250  // allow the dialog to set directly
251  friend class DIALOG_CREATE_ARRAY;
252 
255 
259  };
260 
262  {
264  ARRAY_OPTIONS( ARRAY_GRID ),
265  m_nx( 0 ), m_ny( 0 ),
266  m_horizontalThenVertical( true ),
267  m_reverseNumberingAlternate( false ),
268  m_stagger( 0 ),
269  m_stagger_rows( true ),
270  m_2dArrayNumbering( false ),
271  m_numberingOffsetX( 0 ),
272  m_numberingOffsetY( 0 ),
273  m_priAxisNumType( NUMBERING_NUMERIC ),
274  m_secAxisNumType( NUMBERING_NUMERIC )
275  {}
276 
277  long m_nx, m_ny;
278  bool m_horizontalThenVertical, m_reverseNumberingAlternate;
281  long m_stagger;
284  int m_numberingOffsetX, m_numberingOffsetY;
286 
287  void TransformItem( int n, BOARD_ITEM* item, const wxPoint& rotPoint ) const override;
288  int GetArraySize() const override;
289  wxString GetItemNumber( int n ) const override;
290 
291 private:
292  wxPoint getGridCoords( int n ) const;
293  };
294 
296  {
298  ARRAY_OPTIONS( ARRAY_CIRCULAR ),
299  m_nPts( 0 ),
300  m_angle( 0.0f ),
301  m_rotateItems( false ),
302  m_numberingType( NUMBERING_NUMERIC ),
303  m_numberingOffset( 0 )
304  {}
305 
306  long m_nPts;
307  double m_angle;
312 
313  void TransformItem( int n, BOARD_ITEM* item, const wxPoint& rotPoint ) const override;
314  int GetArraySize() const override;
315  wxString GetItemNumber( int n ) const override;
316  };
317 
318  // Constructor and destructor
319  DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, bool enableNumbering,
320  wxPoint aOrigPos );
321 
323 
329  {
330  return m_settings;
331  }
332 
333 private:
334 
340 
341  /*
342  * The position of the original item(s), used for finding radius, etc
343  */
345 
346  // Event callbacks
347  void OnParameterChanged( wxCommandEvent& event ) override;
348  void OnOkClick( wxCommandEvent& event ) override;
349 
350  // Internal callback handlers
351  void setControlEnablement();
352  void calculateCircularArrayProperties();
353 
355  {
357  m_optionsSet( false ),
358  m_gridStaggerType( 0 ),
359  m_gridNumberingAxis( 0 ),
360  m_gridNumberingReverseAlternate( false ),
361  m_grid2dArrayNumbering( 0 ),
362  m_gridPriAxisNumScheme( 0 ),
363  m_gridSecAxisNumScheme( 0 ),
364  m_circRotate( false ),
365  m_arrayTypeTab( 0 )
366  {}
367 
369 
370  wxString m_gridNx, m_gridNy,
371  m_gridDx, m_gridDy,
372  m_gridOffsetX, m_gridOffsetY,
374 
375  int m_gridStaggerType, m_gridNumberingAxis;
378  int m_gridPriAxisNumScheme, m_gridSecAxisNumScheme;
379  wxString m_gridPriNumberingOffset, m_gridSecNumberingOffset;
380 
381  wxString m_circCentreX, m_circCentreY,
382  m_circAngle, m_circCount, m_circNumberingOffset;
385  };
386 
387  // some uses of arrays might not allow component renumbering
389 
390  // saved array options
392 };
393 
394 #endif // __DIALOG_CREATE_ARRAY__
CONFIG_SAVE_RESTORE_WINDOW(bool &validFlag)
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
ARRAY_OPTIONS * GetArrayOptions() const
ARRAY_OPTIONS * m_settings
The settings object returned to the caller.
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
void Add(wxRadioBox *ctrl, int &dest)
std::vector< CONFIG_CTRL_T > ctrls
void Add(wxCheckBox *ctrl, bool &dest)
bool m_numberingStartIsSpecified
True if this array's number starts from the preset point False if the array numbering starts from som...
void Add(wxNotebook *ctrl, int &dest)
Classes used in Pcbnew, CvPcb and GerbView.
bool m_shouldNumber
True if this array numbers the new items.
void Add(wxTextCtrl *ctrl, wxString &dest)
static CREATE_ARRAY_DIALOG_ENTRIES m_options
void Add(wxChoice *ctrl, int &dest)
Class DIALOG_CREATE_ARRAY_BASE.
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
const wxPoint m_originalItemPosition