KiCad PCB EDA Suite
widget_eeschema_color_config.cpp
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 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2016-2018 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 /* Set up colors to draw items in Eeschema
26  */
27 
28 #include <fctsys.h>
29 #include <draw_frame.h>
30 #include <sch_draw_panel.h>
31 #include <sch_view.h>
32 #include <general.h>
33 
36 
37 // Width and height of every (color-displaying / bitmap) button in dialog units
38 const wxSize BUTT_SIZE( 10, 6 );
39 const wxSize BUTT_BORDER( 4, 4 );
40 
41 /********************/
42 /* Layer menu list. */
43 /********************/
44 
46 {
47  wxString m_Name;
48  int m_Layer;
49 };
50 
52 {
53  wxString m_Name;
55 };
56 
58  { _( "Wire" ), LAYER_WIRE },
59  { _( "Bus" ), LAYER_BUS },
60  { _( "Junction" ), LAYER_JUNCTION },
61  { _( "Label" ), LAYER_LOCLABEL },
62  { _( "Global label" ), LAYER_GLOBLABEL },
63  { _( "Net name" ), LAYER_NETNAM },
64  { _( "Notes" ), LAYER_NOTES },
65  { _( "No connect symbol" ), LAYER_NOCONNECT },
66  { wxT( "" ), -1 } // Sentinel marking end of list.
67 };
68 
70  { _( "Body outline" ), LAYER_DEVICE },
71  { _( "Body background" ), LAYER_DEVICE_BACKGROUND },
72  { _( "Pin" ), LAYER_PIN },
73  { _( "Pin number" ), LAYER_PINNUM },
74  { _( "Pin name" ), LAYER_PINNAM },
75  { _( "Reference" ), LAYER_REFERENCEPART },
76  { _( "Value" ), LAYER_VALUEPART },
77  { _( "Fields" ), LAYER_FIELDS },
78  { wxT( "" ), -1 } // Sentinel marking end of list.
79 };
80 
82  { _( "Sheet" ), LAYER_SHEET },
83  { _( "Sheet file name" ), LAYER_SHEETFILENAME },
84  { _( "Sheet name" ), LAYER_SHEETNAME },
85  { _( "Sheet label" ), LAYER_SHEETLABEL },
86  { _( "Hierarchical label" ),LAYER_HIERLABEL },
87  { wxT( "" ), -1 } // Sentinel marking end of list.
88 };
89 
91  { _( "ERC warning" ), LAYER_ERC_WARN },
92  { _( "ERC error" ), LAYER_ERC_ERR },
93  { _( "Brightened" ), LAYER_BRIGHTENED },
94  { _( "Hidden items" ), LAYER_HIDDEN },
95  { _( "Worksheet" ), LAYER_WORKSHEET },
96  { _( "Cursor" ), LAYER_SCHEMATIC_CURSOR },
97  { _( "Grid" ), LAYER_SCHEMATIC_GRID },
98  { _( "Background" ), LAYER_SCHEMATIC_BACKGROUND },
99  { wxT( "" ), -1 } // Sentinel marking end of list.
100 };
101 
102 
104  { _( "General" ), generalColorButtons },
105  { _( "Component" ), componentColorButtons },
106  { _( "Sheet" ), sheetColorButtons },
107  { _( "Miscellaneous" ), miscColorButtons },
108  { wxT( "" ), NULL }
109 };
110 
112 
114 
115 
117  wxPanel( aParent ), m_drawFrame( aDrawFrame )
118 {
119  m_butt_size_pix = ConvertDialogToPixels( BUTT_SIZE );
120  m_butt_border_pix = ConvertDialogToPixels( BUTT_BORDER );
121 
122  CreateControls();
123 }
124 
125 
127 {
128  wxStaticText* label;
129  int buttonId = 1800;
130 
131  m_mainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
132  SetSizer( m_mainBoxSizer );
133 
134  BUTTONINDEX* groups = buttonGroups;
135  wxBoxSizer* columnBoxSizer = NULL;
136 
137  while( groups->m_Buttons != NULL )
138  {
139  COLORBUTTON* buttons = groups->m_Buttons;
140 
141  columnBoxSizer = new wxBoxSizer( wxVERTICAL );
142  m_mainBoxSizer->Add( columnBoxSizer, 1, wxALIGN_TOP | wxLEFT, 5 );
143  wxBoxSizer* rowBoxSizer = new wxBoxSizer( wxHORIZONTAL );
144  columnBoxSizer->Add( rowBoxSizer, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
145 
146  // Add a text string to identify the column of color select buttons.
147  label = new wxStaticText( this, wxID_ANY, groups->m_Name );
148 
149  // Make the column label font bold.
150  wxFont font( label->GetFont() );
151  font.SetWeight( wxFONTWEIGHT_BOLD );
152  label->SetFont( font );
153 
154  rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
155 
156  while( buttons->m_Layer >= 0 )
157  {
158  rowBoxSizer = new wxBoxSizer( wxHORIZONTAL );
159  columnBoxSizer->Add( rowBoxSizer, 0, wxGROW | wxALL, 0 );
160 
162  currentColors[ buttons->m_Layer ] = color;
163 
164  wxMemoryDC iconDC;
165  wxBitmap bitmap( m_butt_size_pix );
166 
167  iconDC.SelectObject( bitmap );
168  iconDC.SetPen( *wxBLACK_PEN );
169 
170  wxBrush brush;
171  brush.SetColour( color.ToColour() );
172  brush.SetStyle( wxBRUSHSTYLE_SOLID );
173  iconDC.SetBrush( brush );
174  iconDC.DrawRectangle( 0, 0, m_butt_size_pix.x, m_butt_size_pix.y );
175 
176  wxBitmapButton* bitmapButton = new wxBitmapButton(
177  this, buttonId, bitmap, wxDefaultPosition,
178  m_butt_size_pix + m_butt_border_pix + wxSize( 1, 1 ) );
179  bitmapButton->SetClientData( (void*) buttons );
180 
181  rowBoxSizer->Add( bitmapButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
182 
183  label = new wxStaticText( this, wxID_ANY, wxGetTranslation( buttons->m_Name ) );
184  rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
185  buttonId += 1;
186  buttons++;
187  }
188 
189  groups++;
190  }
191 
192  Connect( 1800, buttonId, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WIDGET_EESCHEMA_COLOR_CONFIG::SetColor ) );
193 
194  // Dialog now needs to be resized, but the associated command is found elsewhere.
195 }
196 
197 
198 void WIDGET_EESCHEMA_COLOR_CONFIG::SetColor( wxCommandEvent& event )
199 {
200  wxBitmapButton* button = (wxBitmapButton*) event.GetEventObject();
201 
202  wxCHECK_RET( button != NULL, wxT( "Color button event object is NULL." ) );
203 
204  COLORBUTTON* colorButton = (COLORBUTTON*) button->GetClientData();
205 
206  wxCHECK_RET( colorButton != NULL, wxT( "Client data not set for color button." ) );
207  COLOR4D oldColor = currentColors[ colorButton->m_Layer ];
208  COLOR4D newColor = COLOR4D::UNSPECIFIED;
209  DIALOG_COLOR_PICKER dialog( this, oldColor, false );
210 
211  if( dialog.ShowModal() == wxID_OK )
212  {
213  newColor = dialog.GetColor();
214  }
215 
216  if( newColor == COLOR4D::UNSPECIFIED || oldColor == newColor )
217  return;
218 
219  currentColors[ colorButton->m_Layer ] = newColor;
220 
221  wxMemoryDC iconDC;
222 
223  wxBitmap bitmap = button->GetBitmapLabel();
224  iconDC.SelectObject( bitmap );
225  iconDC.SetPen( *wxBLACK_PEN );
226 
227  wxBrush brush;
228  brush.SetColour( newColor.ToColour() );
229  brush.SetStyle( wxBRUSHSTYLE_SOLID );
230 
231  iconDC.SetBrush( brush );
232  iconDC.DrawRectangle( 0, 0, m_butt_size_pix.x, m_butt_size_pix.y );
233  button->SetBitmapLabel( bitmap );
234  button->Refresh();
235 
236  Refresh( false );
237 }
238 
239 
241 {
242  // Check for color conflicts with background color to give user a chance to bail
243  // out before making changes.
244 
245  COLOR4D bgcolor = currentColors[ LAYER_SCHEMATIC_BACKGROUND ];
246 
247  for( SCH_LAYER_ID clyr = SCH_LAYER_ID_START; clyr < SCH_LAYER_ID_END; ++clyr )
248  {
249  if( bgcolor == currentColors[ clyr ] && clyr != LAYER_SCHEMATIC_BACKGROUND )
250  {
251  wxString msg = _( "Some items have the same color as the background\n"
252  "and they will not be seen on the screen. Are you\n"
253  "sure you want to use these colors?" );
254 
255  if( wxMessageBox( msg, _( "Warning" ), wxYES_NO | wxICON_QUESTION, this ) == wxNO )
256  return false;
257 
258  break;
259  }
260  }
261 
262  for( SCH_LAYER_ID clyr = SCH_LAYER_ID_START; clyr < SCH_LAYER_ID_END; ++clyr )
263  SetLayerColor( currentColors[ clyr ], clyr );
264 
265  SetLayerColor( currentColors[ LAYER_WORKSHEET ], (SCH_LAYER_ID) LAYER_WORKSHEET );
266 
267  return true;
268 }
269 
270 
272  wxWindow* aParent ) :
273  wxPanel( aParent )
274 {
275  auto sizer = new wxBoxSizer( wxVERTICAL );
276  SetSizer( sizer );
277 
278  m_colorConfig = new WIDGET_EESCHEMA_COLOR_CONFIG( this, aFrame );
279  sizer->Add( m_colorConfig, 1, wxEXPAND | wxLEFT | wxRIGHT, 5 );
280 }
281 
282 
284 {
285  return true;
286 }
287 
288 
290 {
292 }
void SetLayerColor(COLOR4D aColor, SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:181
static COLORBUTTON generalColorButtons[]
int color
Definition: DXF_plotter.cpp:62
const wxSize BUTT_BORDER(4, 4)
WIDGET_EESCHEMA_COLOR_CONFIG(wxWindow *aParent, EDA_DRAW_FRAME *aDrawFrame)
static BUTTONINDEX buttonGroups[]
static COLORBUTTON bgColorButton
WIDGET_EESCHEMA_COLOR_CONFIG * m_colorConfig
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:174
static COLORBUTTON sheetColorButtons[]
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
PANEL_EESCHEMA_COLOR_CONFIG(EDA_DRAW_FRAME *aFrame, wxWindow *aParent)
SCH_LAYER_ID
Eeschema drawing layers.
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
static COLOR4D currentColors[LAYER_ID_COUNT]
static COLORBUTTON miscColorButtons[]
static COLORBUTTON componentColorButtons[]
KIGFX::COLOR4D GetColor()
const wxSize BUTT_SIZE(10, 6)
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39