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  {
49  };
50 
52  {
53  void* control;
55  void* dest;
56  };
57 
58  std::vector<CONFIG_CTRL_T> ctrls;
59  bool& valid;
60 
61 protected:
62  CONFIG_SAVE_RESTORE_WINDOW( bool& validFlag ) :
63  valid( validFlag )
64  {}
65 
66  void Add( wxRadioBox* ctrl, int& dest )
67  {
68  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_RADIOBOX, (void*) &dest };
69 
70  ctrls.push_back( ctrlInfo );
71  }
72 
73  void Add( wxCheckBox* ctrl, bool& dest )
74  {
75  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_CHECKBOX, (void*) &dest };
76 
77  ctrls.push_back( ctrlInfo );
78  }
79 
80  void Add( wxTextCtrl* ctrl, wxString& dest )
81  {
82  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_TEXT, (void*) &dest };
83 
84  ctrls.push_back( ctrlInfo );
85  }
86 
87  void Add( UNIT_BINDER& ctrl, int& dest )
88  {
89  CONFIG_CTRL_T ctrlInfo = { &ctrl, CFG_CTRL_UNIT_BINDER, (void*) &dest };
90 
91  ctrls.push_back( ctrlInfo );
92  }
93 
94 
95  void Add( wxChoice* ctrl, int& dest )
96  {
97  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_CHOICE, (void*) &dest };
98 
99  ctrls.push_back( ctrlInfo );
100  }
101 
102  void Add( wxNotebook* ctrl, int& dest )
103  {
104  CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_TAB, (void*) &dest };
105 
106  ctrls.push_back( ctrlInfo );
107  }
108 
110  {
111  for( std::vector<CONFIG_CTRL_T>::const_iterator iter = ctrls.begin(), iend = ctrls.end();
112  iter != iend; ++iter )
113  {
114  switch( iter->type )
115  {
116  case CFG_CTRL_CHECKBOX:
117  *(bool*) iter->dest = static_cast<wxCheckBox*>( iter->control )->GetValue();
118  break;
119 
120  case CFG_CTRL_TEXT:
121  *(wxString*) iter->dest = static_cast<wxTextCtrl*>( iter->control )->GetValue();
122  break;
123 
125  *(int*) iter->dest = static_cast<UNIT_BINDER*>( iter->control )->GetValue();
126  break;
127 
128  case CFG_CTRL_CHOICE:
129  *(int*) iter->dest = static_cast<wxChoice*>( iter->control )->GetSelection();
130  break;
131 
132  case CFG_CTRL_RADIOBOX:
133  *(int*) iter->dest = static_cast<wxRadioBox*>( iter->control )->GetSelection();
134  break;
135 
136  case CFG_CTRL_TAB:
137  *(int*) iter->dest = static_cast<wxNotebook*>( iter->control )->GetSelection();
138  break;
139 
140  default:
141  wxASSERT_MSG( false, wxString(
142  "Unhandled control type for config store: " ) << iter->type );
143  }
144  }
145 
146  valid = true;
147  }
148 
150  {
151  if( !valid )
152  return;
153 
154  for( std::vector<CONFIG_CTRL_T>::const_iterator iter = ctrls.begin(), iend = ctrls.end();
155  iter != iend; ++iter )
156  {
157  switch( iter->type )
158  {
159  case CFG_CTRL_CHECKBOX:
160  static_cast<wxCheckBox*>( iter->control )->SetValue( *(bool*) iter->dest );
161  break;
162 
163  case CFG_CTRL_TEXT:
164  static_cast<wxTextCtrl*>( iter->control )->SetValue( *(wxString*) iter->dest );
165  break;
166 
168  static_cast<UNIT_BINDER*>( iter->control )->SetValue( *(int*) iter->dest );
169  break;
170 
171  case CFG_CTRL_CHOICE:
172  static_cast<wxChoice*>( iter->control )->SetSelection( *(int*) iter->dest );
173  break;
174 
175  case CFG_CTRL_RADIOBOX:
176  static_cast<wxRadioBox*>( iter->control )->SetSelection( *(int*) iter->dest );
177  break;
178 
179  case CFG_CTRL_TAB:
180  static_cast<wxNotebook*>( iter->control )->SetSelection( *(int*) iter->dest );
181  break;
182 
183  default:
184  wxASSERT_MSG( false, wxString(
185  "Unhandled control type for config restore: " ) << iter->type );
186  }
187  }
188  }
189 };
190 
193 {
194 public:
195 
197  {
200  };
201 
202  // NOTE: do not change order relative to charSetDescriptions
204  {
205  NUMBERING_NUMERIC = 0,
207  NUMBERING_ALPHA_NO_IOSQXZ,
214  };
215 
216  #define NUMBERING_TYPE_MAX NUMBERING_ALPHA_FULL
217 
222  {
224  m_type( aType ),
225  m_shouldNumber( false ),
226  m_numberingStartIsSpecified( false )
227  {}
228 
229  virtual ~ARRAY_OPTIONS() {};
230 
231  ARRAY_TYPE_T m_type;
232 
240  virtual void TransformItem( int n, BOARD_ITEM* item,
241  const wxPoint& rotPoint ) const = 0;
242  virtual int GetArraySize() const = 0;
243  virtual wxString GetItemNumber( int n ) const = 0;
244  virtual wxString InterpolateNumberIntoString( int n, const wxString& pattern ) const;
245 
250  bool ShouldNumberItems() const
251  {
252  return m_shouldNumber;
253  }
254 
261  {
262  return m_shouldNumber && m_numberingStartIsSpecified;
263  }
264 
265  protected:
266  static wxString getCoordinateNumber( int n, NUMBERING_TYPE_T type );
267 
268  // allow the dialog to set directly
269  friend class DIALOG_CREATE_ARRAY;
270 
273 
277  };
278 
280  {
282  ARRAY_OPTIONS( ARRAY_GRID ),
283  m_nx( 0 ), m_ny( 0 ),
284  m_horizontalThenVertical( true ),
285  m_reverseNumberingAlternate( false ),
286  m_stagger( 0 ),
287  m_stagger_rows( true ),
288  m_2dArrayNumbering( false ),
289  m_numberingOffsetX( 0 ),
290  m_numberingOffsetY( 0 ),
291  m_priAxisNumType( NUMBERING_NUMERIC ),
292  m_secAxisNumType( NUMBERING_NUMERIC )
293  {}
294 
295  long m_nx, m_ny;
296  bool m_horizontalThenVertical, m_reverseNumberingAlternate;
297  wxPoint m_delta;
298  wxPoint m_offset;
299  long m_stagger;
302  int m_numberingOffsetX, m_numberingOffsetY;
304 
305  void TransformItem( int n, BOARD_ITEM* item, const wxPoint& rotPoint ) const override;
306  int GetArraySize() const override;
307  wxString GetItemNumber( int n ) const override;
308 
309 private:
310  wxPoint getGridCoords( int n ) const;
311  };
312 
314  {
316  ARRAY_OPTIONS( ARRAY_CIRCULAR ),
317  m_nPts( 0 ),
318  m_angle( 0.0f ),
319  m_rotateItems( false ),
320  m_numberingType( NUMBERING_NUMERIC ),
321  m_numberingOffset( 0 )
322  {}
323 
324  long m_nPts;
325  double m_angle;
326  wxPoint m_centre;
330 
331  void TransformItem( int n, BOARD_ITEM* item, const wxPoint& rotPoint ) const override;
332  int GetArraySize() const override;
333  wxString GetItemNumber( int n ) const override;
334  };
335 
336  // Constructor and destructor
337  DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, bool enableNumbering,
338  wxPoint aOrigPos );
339 
341 
347  {
348  return m_settings;
349  }
350 
351 private:
352 
358 
359  UNIT_BINDER m_hSpacing, m_vSpacing;
360  UNIT_BINDER m_hOffset, m_vOffset;
361  UNIT_BINDER m_hCentre, m_vCentre;
363 
364  /*
365  * The position of the original item(s), used for finding radius, etc
366  */
367  const wxPoint m_originalItemPosition;
368 
369  // Event callbacks
370  void OnParameterChanged( wxCommandEvent& event ) override;
371 
372  // Internal callback handlers
373  void setControlEnablement();
374  void calculateCircularArrayProperties();
375 
376  bool TransferDataFromWindow() override;
377 
379  {
381  m_optionsSet( false ),
382  m_gridStaggerType( 0 ),
383  m_gridNumberingAxis( 0 ),
384  m_gridNumberingReverseAlternate( false ),
385  m_grid2dArrayNumbering( 0 ),
386  m_gridPriAxisNumScheme( 0 ),
387  m_gridSecAxisNumScheme( 0 ),
388  m_circRotate( false ),
389  m_arrayTypeTab( 0 )
390  {}
391 
393 
394  wxString m_gridNx, m_gridNy;
395  int m_gridDx, m_gridDy;
396  int m_gridOffsetX, m_gridOffsetY;
397  wxString m_gridStagger;
398 
399  int m_gridStaggerType, m_gridNumberingAxis;
402  int m_gridPriAxisNumScheme, m_gridSecAxisNumScheme;
403  wxString m_gridPriNumberingOffset, m_gridSecNumberingOffset;
404 
405  int m_circCentreX, m_circCentreY;
406  wxString m_circAngle, m_circCount, m_circNumberingOffset;
409  };
410 
411  // some uses of arrays might not allow component renumbering
413 
414  // saved array options
416 };
417 
418 #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(UNIT_BINDER &ctrl, int &dest)
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