KiCad PCB EDA Suite
dialog_non_copper_zones_properties.cpp
Go to the documentation of this file.
1 
4 /*
5  * This program source code file is part of KiCad, a free EDA CAD application.
6  *
7  * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
8  * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
9  * Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, you may find one here:
23  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24  * or you may search the http://www.gnu.org website for the version 2 license,
25  * or you may write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28 
29 #include <fctsys.h>
30 #include <kiface_i.h>
31 #include <confirm.h>
32 #include <wxPcbStruct.h>
33 #include <base_units.h>
34 
35 #include <class_board.h>
36 #include <class_zone.h>
37 
38 #include <pcbnew.h>
39 #include <zones.h>
40 
41 #include <wx/imaglist.h> // needed for wx/listctrl.h, in wxGTK 2.8.12
42 
44 
45 #define LAYER_BITMAP_SIZE_X 20
46 #define LAYER_BITMAP_SIZE_Y 10
47 
55 {
56 private:
60  ZONE_SETTINGS m_settings; // working copy of zone settings
61 
62  void OnOkClick( wxCommandEvent& event ) override;
63  void OnCancelClick( wxCommandEvent& event ) override;
64  void Init();
65 
66 public:
68  ZONE_CONTAINER* aZone, ZONE_SETTINGS* aSettings );
69 
70 private:
76  wxBitmap makeLayerBitmap( COLOR4D aColor );
77 };
78 
79 
81  ZONE_CONTAINER* aZone, ZONE_SETTINGS* aSettings )
82 {
83  DIALOG_NON_COPPER_ZONES_EDITOR dlg( aParent, aZone, aSettings );
84 
85  ZONE_EDIT_T result = ZONE_EDIT_T( dlg.ShowModal() );
86 
87  return result;
88 }
89 
90 
92  ZONE_CONTAINER* aZone,
93  ZONE_SETTINGS* aSettings ) :
95 {
96  m_parent = aParent;
97 
98  m_zone = aZone;
99  m_ptr = aSettings;
100  m_settings = *aSettings;
101 
102  Init();
103 
104  // the size of some items has changed, so we must call SetSizeHints()
105  GetSizer()->SetSizeHints( this );
106 }
107 
108 
110 {
111  BOARD* board = m_parent->GetBoard();
112 
113  SetReturnCode( ZONE_ABORT ); // Will be changed on button click
114 
117  m_ZoneMinThicknessCtrl->SetValue( msg );
118 
120  m_OrientEdgesOpt->SetSelection( 1 );
121 
123  {
125  m_OutlineAppearanceCtrl->SetSelection( 0 );
126  break;
127 
129  m_OutlineAppearanceCtrl->SetSelection( 1 );
130  break;
131 
133  m_OutlineAppearanceCtrl->SetSelection( 2 );
134  break;
135  }
136 
137  // Create one column in m_LayerSelectionCtrl
138  wxListItem column0;
139  column0.SetId( 0 );
140  m_LayerSelectionCtrl->InsertColumn( 0, column0 );
141 
142  // Create an icon list:
143  wxImageList* imageList = new wxImageList( LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y );
144  m_LayerSelectionCtrl->AssignImageList( imageList, wxIMAGE_LIST_SMALL );
145 
146  LAYER_ID lyrSelect = m_parent->GetActiveLayer();
147 
148  if( m_zone )
149  lyrSelect = m_zone->GetLayer();
150 
151  int ctrlWidth = 0; // Min width for m_LayerSelectionCtrl to show the layers names
152  int imgIdx = 0;
153 
154  for( LSEQ seq = LSET::AllNonCuMask().Seq(); seq; ++seq, ++imgIdx )
155  {
156  LAYER_ID layer = *seq;
157 
158  COLOR4D layerColor = board->GetLayerColor( layer );
159  imageList->Add( makeLayerBitmap( layerColor ) );
160 
161  msg = board->GetLayerName( layer );
162  msg.Trim();
163 
164  int itemIndex = m_LayerSelectionCtrl->InsertItem(
165  m_LayerSelectionCtrl->GetItemCount(), msg, imgIdx );
166 
167  if(lyrSelect == layer )
168  m_LayerSelectionCtrl->Select( itemIndex );
169 
170  wxSize tsize( GetTextSize( msg, m_LayerSelectionCtrl ) );
171  ctrlWidth = std::max( ctrlWidth, tsize.x );
172  }
173 
174  // The most easy way to ensure the right size is to use wxLIST_AUTOSIZE
175  // unfortunately this option does not work well both on
176  // wxWidgets 2.8 ( column witdth too small), and
177  // wxWidgets 2.9 ( column witdth too large)
178  ctrlWidth += LAYER_BITMAP_SIZE_X + 25; // Add bitmap width + margin between bitmap and text
179  m_LayerSelectionCtrl->SetColumnWidth( 0, ctrlWidth );
180 
181  ctrlWidth += 25; // add small margin between text and window borders
182  // and room for vertical scroll bar
183  m_LayerSelectionCtrl->SetMinSize( wxSize( ctrlWidth, -1 ) );
184 }
185 
186 
187 void DIALOG_NON_COPPER_ZONES_EDITOR::OnOkClick( wxCommandEvent& event )
188 {
189  wxString txtvalue = m_ZoneMinThicknessCtrl->GetValue();
190 
192 
193  if( m_settings.m_ZoneMinThickness < 10 )
194  {
195  DisplayError( this,
196  _( "Error :\nyou must choose a min thickness value bigger than 0.001 inch (or 0.0254 mm)" ) );
197  return;
198  }
199 
200  m_settings.m_FillMode = 0; // Use always polygon fill mode
201 
202  switch( m_OutlineAppearanceCtrl->GetSelection() )
203  {
204  case 0:
206  break;
207 
208  case 1:
210  break;
211 
212  case 2:
214  break;
215  }
216 
217  wxConfigBase* cfg = Kiface().KifaceSettings();
218  wxASSERT( cfg );
219 
221 
222  if( m_OrientEdgesOpt->GetSelection() == 0 )
223  m_settings.m_Zone_45_Only = false;
224  else
225  m_settings.m_Zone_45_Only = true;
226 
227  // Get the layer selection for this zone
228  int ii = m_LayerSelectionCtrl->GetFirstSelected();
229 
230  if( ii < 0 )
231  {
232  DisplayError( this, _( "Error : you must choose a layer" ) );
233  return;
234  }
235 
236  LSEQ seq = LSET::AllNonCuMask().Seq();
237 
239 
240  *m_ptr = m_settings;
241 
242  EndModal( ZONE_OK );
243 }
244 
245 
247 {
248  // do not save the edits.
249 
250  EndModal( ZONE_ABORT );
251 }
252 
253 
255 {
256  wxBitmap bitmap( LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y );
257  wxBrush brush;
258  wxMemoryDC iconDC;
259 
260  iconDC.SelectObject( bitmap );
261  brush.SetColour( aColor.ToColour() );
262  brush.SetStyle( wxBRUSHSTYLE_SOLID );
263 
264  iconDC.SetBrush( brush );
265  iconDC.DrawRectangle( 0, 0, LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y );
266 
267  return bitmap;
268 }
int m_Zone_HatchingStyle
Option to show the zone area (outlines only, short hatches or full hatches.
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
virtual LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
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
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:203
LSEQ Seq(const LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:336
COLOR4D GetLayerColor(LAYER_ID aLayer) const
Function GetLayerColor gets a layer color for any valid layer, including non-copper ones...
static LSET AllNonCuMask()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:661
BOARD * GetBoard() const
Classes to handle copper zones.
Class DIALOG_NON_COPPER_ZONES_EDITOR is a dialog editor for non copper zones properties, derived from DIALOG_NONCOPPER_ZONES_PROPERTIES_BASE, which is maintained and created by wxFormBuilder.
const wxString GetLayerName(LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
void OnOkClick(wxCommandEvent &event) override
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Function GetTextSize returns the size of aSingleLine of text when it is rendered in aWindow using wha...
Definition: common.cpp:93
if new values were accepted
Definition: zones.h:49
#define ZONE_NET_OUTLINES_HATCH_OPTION_KEY
Definition: zones.h:29
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:368
if no change
Definition: zones.h:48
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:101
void OnCancelClick(wxCommandEvent &event) override
ZONE_EDIT_T InvokeNonCopperZonesEditor(PCB_BASE_FRAME *aParent, ZONE_CONTAINER *aZone, ZONE_SETTINGS *aSettings)
Function InvokeNonCopperZonesEditor invokes up a modal dialog window for non-copper zone editing...
Class DIALOG_NONCOPPER_ZONES_PROPERTIES_BASE.
Class LSEQ is a sequence (and therefore also a set) of LAYER_IDs.
Class ZONE_SETTINGS handles zones parameters.
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
void AddUnitSymbol(wxStaticText &Stext, EDA_UNITS_T aUnit)
Definition: base_units.cpp:509
#define max(a, b)
Definition: auxiliary.h:86
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
LAYER_ID m_CurrentZone_Layer
Layer used to create the current zone.
int m_FillMode
Mode for filling zone : 1 use segments, 0 use polygons.
DIALOG_NON_COPPER_ZONES_EDITOR(PCB_BASE_FRAME *aParent, ZONE_CONTAINER *aZone, ZONE_SETTINGS *aSettings)
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:69
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
int m_ZoneMinThickness
Min thickness value in filled areas.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39