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 <pcb_base_frame.h>
33 
34 #include <boost/bimap.hpp>
35 #include <widgets/unit_binder.h>
36 
38 {
39 private:
40 
42  {
48  };
49 
51  {
52  wxControl* control;
54  void* dest;
55  };
56 
57  std::vector<CONFIG_CTRL_T> ctrls;
58  bool& valid;
59 
60 protected:
61  CONFIG_SAVE_RESTORE_WINDOW( bool& validFlag ) :
62  valid( validFlag )
63  {}
64 
65  void Add( wxRadioBox* ctrl, int& dest )
66  {
67  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_RADIOBOX, (void*) &dest };
68 
69  ctrls.push_back( ctrlInfo );
70  }
71 
72  void Add( wxCheckBox* ctrl, bool& dest )
73  {
74  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_CHECKBOX, (void*) &dest };
75 
76  ctrls.push_back( ctrlInfo );
77  }
78 
79  void Add( wxTextCtrl* ctrl, wxString& dest )
80  {
81  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_TEXT, (void*) &dest };
82 
83  ctrls.push_back( ctrlInfo );
84  }
85 
86  void Add( wxChoice* ctrl, int& dest )
87  {
88  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_CHOICE, (void*) &dest };
89 
90  ctrls.push_back( ctrlInfo );
91  }
92 
93  void Add( wxNotebook* ctrl, int& dest )
94  {
95  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_TAB, (void*) &dest };
96 
97  ctrls.push_back( ctrlInfo );
98  }
99 
101  {
102  for( std::vector<CONFIG_CTRL_T>::const_iterator iter = ctrls.begin(), iend = ctrls.end();
103  iter != iend; ++iter )
104  {
105  switch( iter->type )
106  {
107  case CFG_CTRL_CHECKBOX:
108  *(bool*) iter->dest = static_cast<wxCheckBox*>( iter->control )->GetValue();
109  break;
110 
111  case CFG_CTRL_TEXT:
112  *(wxString*) iter->dest = static_cast<wxTextCtrl*>( iter->control )->GetValue();
113  break;
114 
115  case CFG_CTRL_CHOICE:
116  *(int*) iter->dest = static_cast<wxChoice*>( iter->control )->GetSelection();
117  break;
118 
119  case CFG_CTRL_RADIOBOX:
120  *(int*) iter->dest = static_cast<wxRadioBox*>( iter->control )->GetSelection();
121  break;
122 
123  case CFG_CTRL_TAB:
124  *(int*) iter->dest = static_cast<wxNotebook*>( iter->control )->GetSelection();
125  break;
126 
127  default:
128  wxASSERT_MSG( false, wxString(
129  "Unhandled control type for config store: " ) << iter->type );
130  }
131  }
132 
133  valid = true;
134  }
135 
137  {
138  if( !valid )
139  return;
140 
141  for( std::vector<CONFIG_CTRL_T>::const_iterator iter = ctrls.begin(), iend = ctrls.end();
142  iter != iend; ++iter )
143  {
144  switch( iter->type )
145  {
146  case CFG_CTRL_CHECKBOX:
147  static_cast<wxCheckBox*>( iter->control )->SetValue( *(bool*) iter->dest );
148  break;
149 
150  case CFG_CTRL_TEXT:
151  static_cast<wxTextCtrl*>( iter->control )->SetValue( *(wxString*) iter->dest );
152  break;
153 
154  case CFG_CTRL_CHOICE:
155  static_cast<wxChoice*>( iter->control )->SetSelection( *(int*) iter->dest );
156  break;
157 
158  case CFG_CTRL_RADIOBOX:
159  static_cast<wxRadioBox*>( iter->control )->SetSelection( *(int*) iter->dest );
160  break;
161 
162  case CFG_CTRL_TAB:
163  static_cast<wxNotebook*>( iter->control )->SetSelection( *(int*) iter->dest );
164  break;
165 
166  default:
167  wxASSERT_MSG( false, wxString(
168  "Unhandled control type for config restore: " ) << iter->type );
169  }
170  }
171  }
172 };
173 
176 {
177 public:
178 
180  {
183  };
184 
185  // NOTE: do not change order relative to charSetDescriptions
187  {
188  NUMBERING_NUMERIC = 0,
190  NUMBERING_ALPHA_NO_IOSQXZ,
197  };
198 
199  #define NUMBERING_TYPE_MAX NUMBERING_ALPHA_FULL
200 
205  {
207  m_type( aType ),
208  m_shouldNumber( false ),
209  m_numberingStartIsSpecified( false )
210  {}
211 
212  virtual ~ARRAY_OPTIONS() {};
213 
214  ARRAY_TYPE_T m_type;
215 
223  virtual void TransformItem( int n, BOARD_ITEM* item,
224  const wxPoint& rotPoint ) const = 0;
225  virtual int GetArraySize() const = 0;
226  virtual wxString GetItemNumber( int n ) const = 0;
227  virtual wxString InterpolateNumberIntoString( int n, const wxString& pattern ) const;
228 
233  bool ShouldNumberItems() const
234  {
235  return m_shouldNumber;
236  }
237 
244  {
245  return m_shouldNumber && m_numberingStartIsSpecified;
246  }
247 
248  protected:
249  static wxString getCoordinateNumber( int n, NUMBERING_TYPE_T type );
250 
251  // allow the dialog to set directly
252  friend class DIALOG_CREATE_ARRAY;
253 
256 
260  };
261 
263  {
265  ARRAY_OPTIONS( ARRAY_GRID ),
266  m_nx( 0 ), m_ny( 0 ),
267  m_horizontalThenVertical( true ),
268  m_reverseNumberingAlternate( false ),
269  m_stagger( 0 ),
270  m_stagger_rows( true ),
271  m_2dArrayNumbering( false ),
272  m_numberingOffsetX( 0 ),
273  m_numberingOffsetY( 0 ),
274  m_priAxisNumType( NUMBERING_NUMERIC ),
275  m_secAxisNumType( NUMBERING_NUMERIC )
276  {}
277 
278  long m_nx, m_ny;
279  bool m_horizontalThenVertical, m_reverseNumberingAlternate;
282  long m_stagger;
285  int m_numberingOffsetX, m_numberingOffsetY;
287 
288  void TransformItem( int n, BOARD_ITEM* item, const wxPoint& rotPoint ) const override;
289  int GetArraySize() const override;
290  wxString GetItemNumber( int n ) const override;
291 
292 private:
293  wxPoint getGridCoords( int n ) const;
294  };
295 
297  {
299  ARRAY_OPTIONS( ARRAY_CIRCULAR ),
300  m_nPts( 0 ),
301  m_angle( 0.0f ),
302  m_rotateItems( false ),
303  m_numberingType( NUMBERING_NUMERIC ),
304  m_numberingOffset( 0 )
305  {}
306 
307  long m_nPts;
308  double m_angle;
313 
314  void TransformItem( int n, BOARD_ITEM* item, const wxPoint& rotPoint ) const override;
315  int GetArraySize() const override;
316  wxString GetItemNumber( int n ) const override;
317  };
318 
319  // Constructor and destructor
320  DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, bool enableNumbering,
321  wxPoint aOrigPos );
322 
324 
330  {
331  return m_settings;
332  }
333 
334 private:
335 
341 
342  UNIT_BINDER m_hSpacing, m_vSpacing;
343  UNIT_BINDER m_hOffset, m_vOffset;
344  UNIT_BINDER m_hCentre, m_vCentre;
346 
347  /*
348  * The position of the original item(s), used for finding radius, etc
349  */
351 
352  // Event callbacks
353  void OnParameterChanged( wxCommandEvent& event ) override;
354 
355  // Internal callback handlers
356  void setControlEnablement();
357  void calculateCircularArrayProperties();
358 
359  bool TransferDataFromWindow() override;
360 
362  {
364  m_optionsSet( false ),
365  m_gridStaggerType( 0 ),
366  m_gridNumberingAxis( 0 ),
367  m_gridNumberingReverseAlternate( false ),
368  m_grid2dArrayNumbering( 0 ),
369  m_gridPriAxisNumScheme( 0 ),
370  m_gridSecAxisNumScheme( 0 ),
371  m_circRotate( false ),
372  m_arrayTypeTab( 0 )
373  {}
374 
376 
377  wxString m_gridNx, m_gridNy,
378  m_gridDx, m_gridDy,
379  m_gridOffsetX, m_gridOffsetY,
381 
382  int m_gridStaggerType, m_gridNumberingAxis;
385  int m_gridPriAxisNumScheme, m_gridSecAxisNumScheme;
386  wxString m_gridPriNumberingOffset, m_gridSecNumberingOffset;
387 
388  wxString m_circCentreX, m_circCentreY,
389  m_circAngle, m_circCount, m_circNumberingOffset;
392  };
393 
394  // some uses of arrays might not allow component renumbering
396 
397  // saved array options
399 };
400 
401 #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&#39;s number starts from the preset point False if the array numbering starts from som...
Classes used in Pcbnew, CvPcb and GerbView.
void Add(wxNotebook *ctrl, int &dest)
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