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-2015 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 
64  std::vector<LAYER_NUM> m_layerId;
65 
71  void initDialog();
72 
73  virtual void OnOkClick( wxCommandEvent& event ) override;
74 
81 
87  wxBitmap makeLayerBitmap( COLOR4D aColor );
88 };
89 
90 
91 #define LAYER_BITMAP_SIZE_X 20
92 #define LAYER_BITMAP_SIZE_Y 10
93 
95 {
96  DIALOG_KEEPOUT_AREA_PROPERTIES dlg( aCaller, aSettings );
97 
98  ZONE_EDIT_T result = ZONE_ABORT;
99 
100  if( dlg.ShowModal() == wxID_OK )
101  result = ZONE_OK;
102 
103  return result;
104 }
105 
106 
108  ZONE_SETTINGS* aSettings ) :
110 {
111  m_parent = aParent;
113 
114  m_ptr = aSettings;
115  m_zonesettings = *aSettings;
116 
117  initDialog();
118  m_sdbSizerButtonsOK->SetDefault();
119 
121 }
122 
123 
125 {
126  BOARD* board = m_parent->GetBoard();
127 
128  wxString msg;
129 
131  m_OrientEdgesOpt->SetSelection( 1 );
132 
134  {
136  m_OutlineAppearanceCtrl->SetSelection( 0 );
137  break;
138 
140  m_OutlineAppearanceCtrl->SetSelection( 1 );
141  break;
142 
144  m_OutlineAppearanceCtrl->SetSelection( 2 );
145  break;
146  }
147 
148  // Create one column in m_LayerSelectionCtrl
149  wxListItem column0;
150  column0.SetId( 0 );
151  m_LayerSelectionCtrl->InsertColumn( 0, column0 );
152 
153  wxImageList* imageList = new wxImageList( LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y );
154  m_LayerSelectionCtrl->AssignImageList( imageList, wxIMAGE_LIST_SMALL );
155 
156  // Build copper layer list and append to layer widget
157  LSET show = LSET::AllCuMask( board->GetCopperLayerCount() );
158  int imgIdx = 0;
159 
160  for( LSEQ cu_stack = show.UIOrder(); cu_stack; ++cu_stack, imgIdx++ )
161  {
162  PCB_LAYER_ID layer = *cu_stack;
163 
164  m_layerId.push_back( layer );
165 
166  msg = board->GetLayerName( layer );
167 
168  COLOR4D layerColor = m_parent->Settings().Colors().GetLayerColor( layer );
169 
170  imageList->Add( makeLayerBitmap( layerColor ) );
171 
172  int itemIndex = m_LayerSelectionCtrl->InsertItem(
173  m_LayerSelectionCtrl->GetItemCount(), msg, imgIdx );
174 
175  if( m_zonesettings.m_CurrentZone_Layer == layer )
176  m_LayerSelectionCtrl->Select( itemIndex );
177  }
178 
179  m_LayerSelectionCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE);
180 
181  // Init keepout parameters:
185 }
186 
187 
188 void DIALOG_KEEPOUT_AREA_PROPERTIES::OnOkClick( wxCommandEvent& event )
189 {
191  {
193  event.Skip(); // ends returning wxID_OK (default behavior)
194  }
195 }
196 
197 
199 {
200  // Init keepout parameters:
205 
206  // Test for not allowed items: should have at least one item not allowed:
210  {
211  DisplayError( NULL,
212  _("Tracks, vias, and pads are allowed. The keepout is useless" ) );
213  return false;
214  }
215 
216  // Get the layer selection for this zone
217  int ii = m_LayerSelectionCtrl->GetFirstSelected();
218 
219  if( ii < 0 )
220  {
221  DisplayError( NULL, _( "No layer selected." ) );
222  return false;
223  }
224 
226 
227  switch( m_OutlineAppearanceCtrl->GetSelection() )
228  {
229  case 0:
231  break;
232 
233  case 1:
235  break;
236 
237  case 2:
239  break;
240  }
241 
242  if( m_config )
243  {
246  }
247 
248  if( m_OrientEdgesOpt->GetSelection() == 0 )
250  else
252 
253  m_zonesettings.m_ZonePriority = 0; //m_PriorityLevelCtrl->GetValue();
254 
255  return true;
256 }
257 
258 
260 {
261  wxBitmap bitmap( LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y );
262  wxBrush brush;
263  wxMemoryDC iconDC;
264 
265  iconDC.SelectObject( bitmap );
266  brush.SetColour( aColor.ToColour() );
267  brush.SetStyle( wxBRUSHSTYLE_SOLID );
268 
269  iconDC.SetBrush( brush );
270  iconDC.DrawRectangle( 0, 0, LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y );
271 
272  return bitmap;
273 }
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:639
std::vector< LAYER_NUM > m_layerId
Handle the real layer number from layer name position in m_LayerSelectionCtrl.
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.
virtual void OnOkClick(wxCommandEvent &event) override
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
void SetIsKeepout(bool aEnable)
void SetDoNotAllowTracks(bool aEnable)
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.
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
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
wxBitmap makeLayerBitmap(COLOR4D aColor)
Function makeLayerBitmap creates the colored rectangle bitmaps used in the layer selection widget...
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:767
PCB_LAYER_ID m_CurrentZone_Layer
Layer used to create the current zone.
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
LSEQ UIOrder() const
Definition: lset.cpp:752
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39