KiCad PCB EDA Suite
WIDGET_EESCHEMA_COLOR_CONFIG Class Reference

#include <widget_eeschema_color_config.h>

Inheritance diagram for WIDGET_EESCHEMA_COLOR_CONFIG:

Public Member Functions

 WIDGET_EESCHEMA_COLOR_CONFIG (wxWindow *aParent, EDA_DRAW_FRAME *aDrawFrame)
 
bool TransferDataFromControl ()
 
void InstallOnPanel (wxPanel *aPanel)
 Method InstallOnPanel Install this WIDGET_EESCHEMA_COLOR_CONFIG onto an empty panel. More...
 

Private Member Functions

void CreateControls ()
 
void SetColor (wxCommandEvent &aEvent)
 
virtual EDA_DRAW_FRAMEGetDrawFrame ()
 

Private Attributes

EDA_DRAW_FRAMEm_drawFrame
 
wxBoxSizer * m_mainBoxSizer
 
wxSize m_butt_size_pix
 
wxSize m_butt_border_pix
 

Detailed Description

Definition at line 42 of file widget_eeschema_color_config.h.

Constructor & Destructor Documentation

WIDGET_EESCHEMA_COLOR_CONFIG::WIDGET_EESCHEMA_COLOR_CONFIG ( wxWindow *  aParent,
EDA_DRAW_FRAME aDrawFrame 
)

Definition at line 112 of file widget_eeschema_color_config.cpp.

References BUTT_BORDER(), BUTT_SIZE(), CreateControls(), m_butt_border_pix, and m_butt_size_pix.

Referenced by GetDrawFrame().

112  :
113  wxPanel( aParent ), m_drawFrame( aDrawFrame )
114 {
115  m_butt_size_pix = ConvertDialogToPixels( BUTT_SIZE );
116  m_butt_border_pix = ConvertDialogToPixels( BUTT_BORDER );
117 
118  CreateControls();
119 }
const wxSize BUTT_BORDER(4, 4)
const wxSize BUTT_SIZE(10, 6)

Member Function Documentation

void WIDGET_EESCHEMA_COLOR_CONFIG::CreateControls ( )
private

Definition at line 122 of file widget_eeschema_color_config.cpp.

References buttonGroups, color, EDA_DRAW_FRAME::GetDrawBgColor(), GetDrawFrame(), GetLayerColor(), LAYER_SCHEMATIC_BACKGROUND, m_butt_border_pix, m_butt_size_pix, BUTTONINDEX::m_Buttons, COLORBUTTON::m_Layer, m_mainBoxSizer, COLORBUTTON::m_Name, BUTTONINDEX::m_Name, SCH_LAYER_INDEX, and SetColor().

Referenced by WIDGET_EESCHEMA_COLOR_CONFIG().

123 {
124  wxStaticText* label;
125  int buttonId = 1800;
126 
127  m_mainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
128  SetSizer( m_mainBoxSizer );
129 
130  BUTTONINDEX* groups = buttonGroups;
131  wxBoxSizer* columnBoxSizer = NULL;
132 
133  while( groups->m_Buttons != NULL )
134  {
135  COLORBUTTON* buttons = groups->m_Buttons;
136 
137  columnBoxSizer = new wxBoxSizer( wxVERTICAL );
138  m_mainBoxSizer->Add( columnBoxSizer, 1, wxALIGN_TOP | wxLEFT | wxTOP, 5 );
139  wxBoxSizer* rowBoxSizer = new wxBoxSizer( wxHORIZONTAL );
140  columnBoxSizer->Add( rowBoxSizer, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
141 
142  // Add a text string to identify the column of color select buttons.
143  label = new wxStaticText( this, wxID_ANY, groups->m_Name );
144 
145  // Make the column label font bold.
146  wxFont font( label->GetFont() );
147  font.SetWeight( wxFONTWEIGHT_BOLD );
148  label->SetFont( font );
149 
150  rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
151 
152  while( buttons->m_Layer >= 0 )
153  {
154  rowBoxSizer = new wxBoxSizer( wxHORIZONTAL );
155  columnBoxSizer->Add( rowBoxSizer, 0, wxGROW | wxALL, 0 );
156 
158  currentColors[ SCH_LAYER_INDEX( buttons->m_Layer ) ] = color;
159 
160  wxMemoryDC iconDC;
161  wxBitmap bitmap( m_butt_size_pix );
162 
163  iconDC.SelectObject( bitmap );
164  iconDC.SetPen( *wxBLACK_PEN );
165 
166  wxBrush brush;
167  brush.SetColour( color.ToColour() );
168  brush.SetStyle( wxBRUSHSTYLE_SOLID );
169  iconDC.SetBrush( brush );
170  iconDC.DrawRectangle( 0, 0, m_butt_size_pix.x, m_butt_size_pix.y );
171 
172  wxBitmapButton* bitmapButton = new wxBitmapButton(
173  this, buttonId, bitmap, wxDefaultPosition,
174  m_butt_size_pix + m_butt_border_pix + wxSize( 1, 1 ) );
175  bitmapButton->SetClientData( (void*) buttons );
176 
177  rowBoxSizer->Add( bitmapButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
178 
179  label = new wxStaticText( this, wxID_ANY, wxGetTranslation( buttons->m_Name ) );
180  rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
181  buttonId += 1;
182  buttons++;
183  }
184 
185  groups++;
186  }
187 
188  COLOR4D bgColor = GetDrawFrame()->GetDrawBgColor();
189  wxMemoryDC iconDC;
190  wxBitmap bitmap( m_butt_size_pix );
191 
192  iconDC.SelectObject( bitmap );
193  iconDC.SetPen( *wxBLACK_PEN );
194 
195  wxBrush brush;
196  brush.SetColour( bgColor.ToColour() );
197  brush.SetStyle( wxBRUSHSTYLE_SOLID );
198  iconDC.SetBrush( brush );
199  iconDC.DrawRectangle( 0, 0, m_butt_size_pix.x, m_butt_size_pix.y );
200 
201  buttonId++;
202  wxBitmapButton* selBgColorBtn = new wxBitmapButton(
203  this, buttonId, bitmap, wxDefaultPosition,
204  m_butt_size_pix + m_butt_border_pix + wxSize( 1, 1 ) );
205  selBgColorBtn->SetClientData( (void*) &bgColorButton );
206 
207  Connect( 1800, buttonId, wxEVT_COMMAND_BUTTON_CLICKED,
208  wxCommandEventHandler( WIDGET_EESCHEMA_COLOR_CONFIG::SetColor ) );
209 
210  wxStaticText* bgColorLabel = new wxStaticText( this, wxID_ANY, _( "Background Color" ) );
211  wxFont font( bgColorLabel->GetFont() );
212  font.SetWeight( wxFONTWEIGHT_BOLD );
213  bgColorLabel->SetFont( font );
214 
215  if( columnBoxSizer )
216  {
217  // Add a spacer to improve appearance.
218  columnBoxSizer->AddSpacer( 5 );
219  columnBoxSizer->Add( bgColorLabel, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
220  columnBoxSizer->Add( selBgColorBtn, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
221  }
222 
224 
225  // Dialog now needs to be resized, but the associated command is found elsewhere.
226 }
static COLOR4D currentColors[SCH_LAYER_ID_COUNT]
int color
Definition: DXF_plotter.cpp:62
static BUTTONINDEX buttonGroups[]
#define SCH_LAYER_INDEX(x)
static COLORBUTTON bgColorButton
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:167
virtual COLOR4D GetDrawBgColor() const
Definition: draw_frame.h:338
SCH_LAYER_ID
Eeschema drawing layers.
virtual EDA_DRAW_FRAME * GetDrawFrame()
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
virtual EDA_DRAW_FRAME* WIDGET_EESCHEMA_COLOR_CONFIG::GetDrawFrame ( )
inlineprivatevirtual
void WIDGET_EESCHEMA_COLOR_CONFIG::InstallOnPanel ( wxPanel *  aPanel)

Method InstallOnPanel Install this WIDGET_EESCHEMA_COLOR_CONFIG onto an empty panel.

This is useful when combining with wxFormBuilder, as an empty panel can be left as a placeholder in the layout.

Definition at line 318 of file widget_eeschema_color_config.cpp.

Referenced by DIALOG_EESCHEMA_OPTIONS::DIALOG_EESCHEMA_OPTIONS(), and GetDrawFrame().

319 {
320  wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
321 
322  sizer->Add( this, 1, wxALL | wxEXPAND, 0 );
323  aPanel->SetSizer( sizer );
324 }
void WIDGET_EESCHEMA_COLOR_CONFIG::SetColor ( wxCommandEvent &  aEvent)
private

Definition at line 229 of file widget_eeschema_color_config.cpp.

References COLOR4D_PICKER_DLG::GetColor(), m_butt_size_pix, COLORBUTTON::m_Layer, Refresh(), and SCH_LAYER_INDEX.

Referenced by CreateControls().

230 {
231  wxBitmapButton* button = (wxBitmapButton*) event.GetEventObject();
232 
233  wxCHECK_RET( button != NULL, wxT( "Color button event object is NULL." ) );
234 
235  COLORBUTTON* colorButton = (COLORBUTTON*) button->GetClientData();
236 
237  wxCHECK_RET( colorButton != NULL, wxT( "Client data not set for color button." ) );
238  COLOR4D oldColor = currentColors[ SCH_LAYER_INDEX( colorButton->m_Layer ) ];
239  COLOR4D newColor = COLOR4D::UNSPECIFIED;
240  COLOR4D_PICKER_DLG dialog( this, oldColor, false );
241 
242  if( dialog.ShowModal() == wxID_OK )
243  {
244  newColor = dialog.GetColor();
245  }
246 
247  if( newColor == COLOR4D::UNSPECIFIED || oldColor == newColor )
248  return;
249 
250  currentColors[ SCH_LAYER_INDEX( colorButton->m_Layer ) ] = newColor;
251 
252  wxMemoryDC iconDC;
253 
254  wxBitmap bitmap = button->GetBitmapLabel();
255  iconDC.SelectObject( bitmap );
256  iconDC.SetPen( *wxBLACK_PEN );
257 
258  wxBrush brush;
259  brush.SetColour( newColor.ToColour() );
260  brush.SetStyle( wxBRUSHSTYLE_SOLID );
261 
262  iconDC.SetBrush( brush );
263  iconDC.DrawRectangle( 0, 0, m_butt_size_pix.x, m_butt_size_pix.y );
264  button->SetBitmapLabel( bitmap );
265  button->Refresh();
266 
267  Refresh( false );
268 }
static COLOR4D currentColors[SCH_LAYER_ID_COUNT]
#define SCH_LAYER_INDEX(x)
void Refresh()
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
bool WIDGET_EESCHEMA_COLOR_CONFIG::TransferDataFromControl ( )

Definition at line 271 of file widget_eeschema_color_config.cpp.

References EDA_DRAW_FRAME::GetCanvas(), GetDrawFrame(), GetLayerColor(), LAYER_SCHEMATIC_BACKGROUND, LAYER_SCHEMATIC_GRID, LAYER_WIRE, EDA_DRAW_PANEL::Refresh(), SCH_LAYER_ID_END, SCH_LAYER_INDEX, EDA_DRAW_FRAME::SetDrawBgColor(), EDA_DRAW_FRAME::SetGridColor(), and SetLayerColor().

Referenced by GetDrawFrame(), and DIALOG_EESCHEMA_OPTIONS::TransferDataFromWindow().

272 {
273  bool warning = false;
274 
275  // Check for color conflicts with background color to give user a chance to bail
276  // out before making changes.
277 
279 
280  for( SCH_LAYER_ID clyr = LAYER_WIRE; clyr < SCH_LAYER_ID_END; ++clyr )
281  {
282  if( bgcolor == currentColors[ SCH_LAYER_INDEX( clyr ) ] && clyr != LAYER_SCHEMATIC_BACKGROUND )
283  {
284  warning = true;
285  break;
286  }
287  }
288 
289  // Prompt the user if an item has the same color as the background
290  // because this item cannot be seen:
291  if( warning )
292  {
293  if( wxMessageBox( _( "Some items have the same color as the background\n"
294  "and they will not be seen on the screen. Are you\n"
295  "sure you want to use these colors?" ),
296  _( "Warning" ),
297  wxYES_NO | wxICON_QUESTION, this ) == wxNO )
298  return false;
299  }
300 
301  // Update color of background
302  GetDrawFrame()->SetDrawBgColor( bgcolor );
304 
305 
306  for( SCH_LAYER_ID clyr = LAYER_WIRE; clyr < SCH_LAYER_ID_END; ++clyr )
307  {
308  SetLayerColor( currentColors[ SCH_LAYER_INDEX( clyr ) ], clyr );
309  }
310 
313 
314  return true;
315 }
void SetLayerColor(COLOR4D aColor, SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:174
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:338
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:351
static COLOR4D currentColors[SCH_LAYER_ID_COUNT]
virtual void SetDrawBgColor(COLOR4D aColor)
Definition: draw_frame.h:343
#define SCH_LAYER_INDEX(x)
virtual void SetGridColor(COLOR4D aColor)
Function SetGridColor() , virtual.
Definition: draw_frame.h:526
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:167
SCH_LAYER_ID
Eeschema drawing layers.
virtual EDA_DRAW_FRAME * GetDrawFrame()
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

Member Data Documentation

wxSize WIDGET_EESCHEMA_COLOR_CONFIG::m_butt_border_pix
private

Definition at line 48 of file widget_eeschema_color_config.h.

Referenced by CreateControls(), and WIDGET_EESCHEMA_COLOR_CONFIG().

wxSize WIDGET_EESCHEMA_COLOR_CONFIG::m_butt_size_pix
private
EDA_DRAW_FRAME* WIDGET_EESCHEMA_COLOR_CONFIG::m_drawFrame
private

Definition at line 45 of file widget_eeschema_color_config.h.

Referenced by GetDrawFrame().

wxBoxSizer* WIDGET_EESCHEMA_COLOR_CONFIG::m_mainBoxSizer
private

Definition at line 46 of file widget_eeschema_color_config.h.

Referenced by CreateControls().


The documentation for this class was generated from the following files: