KiCad PCB EDA Suite
dialog_keepout_area_properties.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
9  * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
10  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, you may find one here:
24  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25  * or you may search the http://www.gnu.org website for the version 2 license,
26  * or you may write to the Free Software Foundation, Inc.,
27  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  */
29 
30 #include <wx/wx.h>
31 #include <fctsys.h>
32 #include <kiface_i.h>
33 #include <confirm.h>
34 #include <pcbnew.h>
35 #include <wxPcbStruct.h>
36 #include <class_zone.h>
37 #include <zones.h>
38 #include <base_units.h>
39 
40 #include <class_zone_settings.h>
41 #include <class_board.h>
43 
44 #include <wx/imaglist.h> // needed for wx/listctrl.h, in wxGTK 2.8.12
45 #include <wx/listctrl.h>
46 
47 
48 
54 {
55 public:
57 
58 private:
60  wxConfigBase* m_config;
63 
69  void initDialog();
70 
74  virtual bool TransferDataFromWindow() override;
75 
76  virtual void OnLayerSelection( wxDataViewEvent& event ) override;
77 
84 
90  wxIcon makeLayerIcon( COLOR4D aColor );
91 };
92 
93 
94 #define LAYER_BITMAP_SIZE_X 25
95 #define LAYER_BITMAP_SIZE_Y 15
96 
98 {
99  DIALOG_KEEPOUT_AREA_PROPERTIES dlg( aCaller, aSettings );
100 
101  ZONE_EDIT_T result = ZONE_ABORT;
102 
103  if( dlg.ShowModal() == wxID_OK )
104  result = ZONE_OK;
105 
106  return result;
107 }
108 
109 
111  ZONE_SETTINGS* aSettings ) :
113 {
114  m_parent = aParent;
116 
117  m_ptr = aSettings;
118  m_zonesettings = *aSettings;
119 
120  initDialog();
121  m_sdbSizerButtonsOK->SetDefault();
122 
124 }
125 
126 
128 {
129  BOARD* board = m_parent->GetBoard();
130 
131  wxString msg;
132 
134  m_OrientEdgesOpt->SetSelection( 1 );
135 
137  {
139  m_OutlineAppearanceCtrl->SetSelection( 0 );
140  break;
141 
143  m_OutlineAppearanceCtrl->SetSelection( 1 );
144  break;
145 
147  m_OutlineAppearanceCtrl->SetSelection( 2 );
148  break;
149  }
150 
151  // Build copper layer list and append to layer widget
152  LSET show = LSET::AllCuMask( board->GetCopperLayerCount() );
153 
154  auto* checkColumn = m_layers->AppendToggleColumn( wxEmptyString );
155  auto* layerColumn = m_layers->AppendIconTextColumn( wxEmptyString );
156 
157  wxVector<wxVariant> row;
158 
159  int imgIdx = 0;
160 
161  for( LSEQ cu_stack = show.UIOrder(); cu_stack; ++cu_stack, imgIdx++ )
162  {
163  PCB_LAYER_ID layer = *cu_stack;
164 
165  msg = board->GetLayerName( layer );
166 
167  COLOR4D layerColor = m_parent->Settings().Colors().GetLayerColor( layer );
168 
169  row.clear();
170  row.push_back( m_zonesettings.m_Layers.test( layer ) );
171  auto iconItem = wxDataViewIconText( msg, makeLayerIcon( layerColor ) );
172  row.push_back( wxVariant( iconItem ) );
173 
174  m_layers->AppendItem( row );
175 
176  }
177 
178  // Init keepout parameters:
182 
183  checkColumn->SetWidth( wxCOL_WIDTH_AUTOSIZE );
184  layerColumn->SetWidth( wxCOL_WIDTH_AUTOSIZE );
185 
186  m_layers->SetExpanderColumn( layerColumn );
187  m_layers->SetMinSize( wxSize( 300, -1 ) );
188 
189  m_layers->Update();
190 
191  Update();
192 
193  m_sdbSizerButtonsOK->Enable( m_zonesettings.m_Layers.count() > 0 );
194 }
195 
196 
198 {
200  {
202  return true;
203  }
204 
205  return false;
206 }
207 
208 
210 {
211  if( event.GetColumn() != 0 )
212  {
213  return;
214  }
215 
216  wxDataViewItem item = event.GetItem();
217 
218  int row = m_layers->ItemToRow( item );
219  bool selected = m_layers->GetToggleValue( row, 0 );
220 
221  BOARD* board = m_parent->GetBoard();
222  LSEQ cu_stack = LSET::AllCuMask( board->GetCopperLayerCount() ).UIOrder();
223 
224  if( row >= 0 && row < (int)cu_stack.size() )
225  {
226  m_zonesettings.m_Layers.set( cu_stack[ row ], selected );
227  }
228 
229  m_sdbSizerButtonsOK->Enable( m_zonesettings.m_Layers.count() > 0 );
230 }
231 
232 
234 {
235  // Init keepout parameters:
240 
241  // Test for not allowed items: should have at least one item not allowed:
245  {
246  DisplayError( NULL,
247  _("Tracks, vias, and pads are allowed. The keepout is useless" ) );
248  return false;
249  }
250 
251  if( m_zonesettings.m_Layers.count() == 0 )
252  {
253  DisplayError( NULL, _( "No layers selected." ) );
254  return false;
255  }
256 
257  switch( m_OutlineAppearanceCtrl->GetSelection() )
258  {
259  case 0:
261  break;
262 
263  case 1:
265  break;
266 
267  case 2:
269  break;
270  }
271 
272  if( m_config )
273  {
276  }
277 
278  if( m_OrientEdgesOpt->GetSelection() == 0 )
280  else
282 
283  m_zonesettings.m_ZonePriority = 0; // for a keepout, this param is not used.
284  // set it to 0
285  return true;
286 }
287 
288 
290 {
291  wxBitmap bitmap( LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y );
292  wxBrush brush;
293  wxMemoryDC iconDC;
294 
295  iconDC.SelectObject( bitmap );
296  brush.SetColour( aColor.ToColour() );
297  brush.SetStyle( wxBRUSHSTYLE_SOLID );
298 
299  iconDC.SetBrush( brush );
300  iconDC.DrawRectangle( 0, 0, LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y );
301 
302  iconDC.SelectObject( wxNullBitmap ); // mandatory before using bitmap data
303  wxIcon icon;
304  icon.CopyFromBitmap( bitmap );
305  return icon;
306 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:646
int m_Zone_HatchingStyle
Option to show the zone area (outlines only, short hatches or full hatches.
#define LAYER_BITMAP_SIZE_Y
const bool GetDoNotAllowTracks() const
Implementation of conversion functions that require both schematic and board internal units...
This file is part of the common library.
Class BOARD to handle a board.
ZONE_EDIT_T
Exit codes for zone editing dialogs.
Definition: zones.h:47
void initDialog()
Function initDialog fills in the dialog controls using the current settings.
const bool GetDoNotAllowCopperPour() const
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int GetCopperLayerCount() const
Function GetCopperLayerCount.
BOARD * GetBoard() const
Classes to handle copper zones.
bool AcceptOptionsForKeepOut()
Function AcceptOptionsForKeepOut Test validity of options, and copy options in m_zonesettings, for keepout zones.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
void SetDoNotAllowVias(bool aEnable)
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
if new values were accepted
Definition: zones.h:49
#define ZONE_NET_OUTLINES_HATCH_OPTION_KEY
Definition: zones.h:29
PCB_GENERAL_SETTINGS & Settings()
DIALOG_KEEPOUT_AREA_PROPERTIES(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
int m_ZonePriority
Priority (0 ... N) of the zone.
if no change
Definition: zones.h:48
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
virtual void OnLayerSelection(wxDataViewEvent &event) override
void SetIsKeepout(bool aEnable)
void SetDoNotAllowTracks(bool aEnable)
ZONE_SETTINGS * m_ptr
the pointer to the zone settings of the zone to edit
Class DIALOG_KEEPOUT_AREA_PROPERTIES_BASE.
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
COLORS_DESIGN_SETTINGS & Colors()
Class ZONE_SETTINGS handles zones parameters.
Class DIALOG_KEEPOUT_AREA_PROPERTIES is the derived class from dialog_copper_zone_frame created by wx...
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
Class ZONE_SETTINGS used to handle zones parameters in dialogs.
virtual bool TransferDataFromWindow() override
automatically called by wxWidgets before closing the dialog
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
wxIcon makeLayerIcon(COLOR4D aColor)
Function makeLayerIcon creates the colored rectangle icons used in the layer selection widget...
const bool GetDoNotAllowVias() const
void SetDoNotAllowCopperPour(bool aEnable)
ZONE_EDIT_T InvokeKeepoutAreaEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeKeepoutAreaEditor invokes up a modal dialog window for copper zone editing...
#define LAYER_BITMAP_SIZE_X
ZONE_SETTINGS m_zonesettings
the working copy of zone settings
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:73
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
LSEQ UIOrder() const
Definition: lset.cpp:759
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39