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  PCB_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  PCB_LAYER_ID layer = *seq;
157 
158  COLOR4D layerColor = m_parent->Settings().Colors().GetLayerColor( layer );
159 
160  imageList->Add( makeLayerBitmap( layerColor ) );
161 
162  msg = board->GetLayerName( layer );
163  msg.Trim();
164 
165  int itemIndex = m_LayerSelectionCtrl->InsertItem(
166  m_LayerSelectionCtrl->GetItemCount(), msg, imgIdx );
167 
168  if(lyrSelect == layer )
169  m_LayerSelectionCtrl->Select( itemIndex );
170 
171  wxSize tsize( GetTextSize( msg, m_LayerSelectionCtrl ) );
172  ctrlWidth = std::max( ctrlWidth, tsize.x );
173  }
174 
175  // The most easy way to ensure the right size is to use wxLIST_AUTOSIZE
176  // unfortunately this option does not work well both on
177  // wxWidgets 2.8 ( column witdth too small), and
178  // wxWidgets 2.9 ( column witdth too large)
179  ctrlWidth += LAYER_BITMAP_SIZE_X + 25; // Add bitmap width + margin between bitmap and text
180  m_LayerSelectionCtrl->SetColumnWidth( 0, ctrlWidth );
181 
182  ctrlWidth += 25; // add small margin between text and window borders
183  // and room for vertical scroll bar
184  m_LayerSelectionCtrl->SetMinSize( wxSize( ctrlWidth, -1 ) );
185 }
186 
187 
188 void DIALOG_NON_COPPER_ZONES_EDITOR::OnOkClick( wxCommandEvent& event )
189 {
190  wxString txtvalue = m_ZoneMinThicknessCtrl->GetValue();
191 
193 
194  if( m_settings.m_ZoneMinThickness < 10 )
195  {
196  DisplayError( this,
197  _( "Error :\nyou must choose a min thickness value bigger than 0.001 inch (or 0.0254 mm)" ) );
198  return;
199  }
200 
201  m_settings.m_FillMode = 0; // Use always polygon fill mode
202 
203  switch( m_OutlineAppearanceCtrl->GetSelection() )
204  {
205  case 0:
207  break;
208 
209  case 1:
211  break;
212 
213  case 2:
215  break;
216  }
217 
218  wxConfigBase* cfg = Kiface().KifaceSettings();
219  wxASSERT( cfg );
220 
222 
223  if( m_OrientEdgesOpt->GetSelection() == 0 )
224  m_settings.m_Zone_45_Only = false;
225  else
226  m_settings.m_Zone_45_Only = true;
227 
228  // Get the layer selection for this zone
229  int ii = m_LayerSelectionCtrl->GetFirstSelected();
230 
231  if( ii < 0 )
232  {
233  DisplayError( this, _( "Error : you must choose a layer" ) );
234  return;
235  }
236 
237  LSEQ seq = LSET::AllNonCuMask().Seq();
238 
240 
241  *m_ptr = m_settings;
242 
243  EndModal( ZONE_OK );
244 }
245 
246 
248 {
249  // do not save the edits.
250 
251  EndModal( ZONE_ABORT );
252 }
253 
254 
256 {
257  wxBitmap bitmap( LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y );
258  wxBrush brush;
259  wxMemoryDC iconDC;
260 
261  iconDC.SelectObject( bitmap );
262  brush.SetColour( aColor.ToColour() );
263  brush.SetStyle( wxBRUSHSTYLE_SOLID );
264 
265  iconDC.SetBrush( brush );
266  iconDC.DrawRectangle( 0, 0, LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y );
267 
268  return bitmap;
269 }
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
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
static LSET AllNonCuMask()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:662
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.
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
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:337
PCB_LAYER_ID
A quick note on 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()
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
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:103
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 PCB_LAYER_IDs.
COLORS_DESIGN_SETTINGS & Colors()
Class ZONE_SETTINGS handles zones parameters.
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
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:169
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
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:71
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
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...
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