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 <eda_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  { _( "Selection Highlight" ), LAYER_SELECTION_SHADOWS },
100  { wxT( "" ), -1 } // Sentinel marking end of list.
101 };
102 
103 
105  { _( "General" ), generalColorButtons },
106  { _( "Component" ), componentColorButtons },
107  { _( "Sheet" ), sheetColorButtons },
108  { _( "Miscellaneous" ), miscColorButtons },
109  { wxT( "" ), NULL }
110 };
111 
113 
115 
116 
118  wxPanel( aParent ), m_drawFrame( aDrawFrame )
119 {
120  m_butt_size_pix = ConvertDialogToPixels( BUTT_SIZE );
121  m_butt_border_pix = ConvertDialogToPixels( BUTT_BORDER );
122 
123  CreateControls();
124 }
125 
126 
128 {
129  wxStaticText* label;
130  int buttonId = 1800;
131 
132  m_mainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
133  SetSizer( m_mainBoxSizer );
134 
135  BUTTONINDEX* groups = buttonGroups;
136  wxBoxSizer* columnBoxSizer = NULL;
137 
138  while( groups->m_Buttons != NULL )
139  {
140  COLORBUTTON* buttons = groups->m_Buttons;
141 
142  columnBoxSizer = new wxBoxSizer( wxVERTICAL );
143  m_mainBoxSizer->Add( columnBoxSizer, 1, wxALIGN_TOP | wxLEFT, 5 );
144  wxBoxSizer* rowBoxSizer = new wxBoxSizer( wxHORIZONTAL );
145  columnBoxSizer->Add( rowBoxSizer, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
146 
147  // Add a text string to identify the column of color select buttons.
148  label = new wxStaticText( this, wxID_ANY, groups->m_Name );
149 
150  // Make the column label font bold.
151  wxFont font( label->GetFont() );
152  font.SetWeight( wxFONTWEIGHT_BOLD );
153  label->SetFont( font );
154 
155  rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
156 
157  while( buttons->m_Layer >= 0 )
158  {
159  rowBoxSizer = new wxBoxSizer( wxHORIZONTAL );
160  columnBoxSizer->Add( rowBoxSizer, 0, wxGROW | wxALL, 0 );
161 
163  currentColors[ buttons->m_Layer ] = color;
164 
165  wxMemoryDC iconDC;
166  wxBitmap bitmap( m_butt_size_pix );
167 
168  iconDC.SelectObject( bitmap );
169  iconDC.SetPen( *wxBLACK_PEN );
170 
171  wxBrush brush;
172  brush.SetColour( color.ToColour() );
173  brush.SetStyle( wxBRUSHSTYLE_SOLID );
174  iconDC.SetBrush( brush );
175  iconDC.DrawRectangle( 0, 0, m_butt_size_pix.x, m_butt_size_pix.y );
176 
177  wxBitmapButton* bitmapButton = new wxBitmapButton(
178  this, buttonId, bitmap, wxDefaultPosition,
179  m_butt_size_pix + m_butt_border_pix + wxSize( 1, 1 ) );
180  bitmapButton->SetClientData( (void*) buttons );
181 
182  rowBoxSizer->Add( bitmapButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
183 
184  label = new wxStaticText( this, wxID_ANY, wxGetTranslation( buttons->m_Name ) );
185  rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
186  buttonId += 1;
187  buttons++;
188  }
189 
190  groups++;
191  }
192 
193  Connect( 1800, buttonId, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WIDGET_EESCHEMA_COLOR_CONFIG::SetColor ) );
194 
195  // Dialog now needs to be resized, but the associated command is found elsewhere.
196 }
197 
198 
199 void WIDGET_EESCHEMA_COLOR_CONFIG::SetColor( wxCommandEvent& event )
200 {
201  wxBitmapButton* button = (wxBitmapButton*) event.GetEventObject();
202 
203  wxCHECK_RET( button != NULL, wxT( "Color button event object is NULL." ) );
204 
205  COLORBUTTON* colorButton = (COLORBUTTON*) button->GetClientData();
206 
207  wxCHECK_RET( colorButton != NULL, wxT( "Client data not set for color button." ) );
208  COLOR4D oldColor = currentColors[ colorButton->m_Layer ];
209  COLOR4D newColor = COLOR4D::UNSPECIFIED;
210  DIALOG_COLOR_PICKER dialog( this, oldColor, false );
211 
212  if( dialog.ShowModal() == wxID_OK )
213  {
214  newColor = dialog.GetColor();
215  }
216 
217  if( newColor == COLOR4D::UNSPECIFIED || oldColor == newColor )
218  return;
219 
220  currentColors[ colorButton->m_Layer ] = newColor;
221 
222  wxMemoryDC iconDC;
223 
224  wxBitmap bitmap = button->GetBitmapLabel();
225  iconDC.SelectObject( bitmap );
226  iconDC.SetPen( *wxBLACK_PEN );
227 
228  wxBrush brush;
229  brush.SetColour( newColor.ToColour() );
230  brush.SetStyle( wxBRUSHSTYLE_SOLID );
231 
232  iconDC.SetBrush( brush );
233  iconDC.DrawRectangle( 0, 0, m_butt_size_pix.x, m_butt_size_pix.y );
234  button->SetBitmapLabel( bitmap );
235  button->Refresh();
236 
237  Refresh( false );
238 }
239 
240 
242 {
243  // Check for color conflicts with background color to give user a chance to bail
244  // out before making changes.
245 
247 
248  for( SCH_LAYER_ID clyr = SCH_LAYER_ID_START; clyr < SCH_LAYER_ID_END; ++clyr )
249  {
250  if( bgcolor == currentColors[ clyr ] && clyr != LAYER_SCHEMATIC_BACKGROUND )
251  {
252  wxString msg = _( "Some items have the same color as the background\n"
253  "and they will not be seen on the screen. Are you\n"
254  "sure you want to use these colors?" );
255 
256  if( wxMessageBox( msg, _( "Warning" ), wxYES_NO | wxICON_QUESTION, this ) == wxNO )
257  return false;
258 
259  break;
260  }
261  }
262 
263  for( SCH_LAYER_ID clyr = SCH_LAYER_ID_START; clyr < SCH_LAYER_ID_END; ++clyr )
264  SetLayerColor( currentColors[ clyr ], clyr );
265 
267 
268  return true;
269 }
270 
271 
273  wxWindow* aParent ) :
274  wxPanel( aParent )
275 {
276  auto sizer = new wxBoxSizer( wxVERTICAL );
277  SetSizer( sizer );
278 
279  m_colorConfig = new WIDGET_EESCHEMA_COLOR_CONFIG( this, aFrame );
280  sizer->Add( m_colorConfig, 1, wxEXPAND | wxLEFT | wxRIGHT, 5 );
281 }
282 
283 
285 {
286  return true;
287 }
288 
289 
291 {
293 }
void SetLayerColor(COLOR4D aColor, SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:167
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.
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:160
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 _(s)
#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