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
 
wxColourPickerCtrl * m_SelBgColor
 
wxBoxSizer * m_mainBoxSizer
 

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 113 of file widget_eeschema_color_config.cpp.

References CreateControls().

113  :
114  wxPanel( aParent ), m_drawFrame( aDrawFrame )
115 {
116  CreateControls();
117 }

Member Function Documentation

void WIDGET_EESCHEMA_COLOR_CONFIG::CreateControls ( )
private

Definition at line 120 of file widget_eeschema_color_config.cpp.

References BUTT_SIZE_X, BUTT_SIZE_Y, buttonGroups, color, EDA_DRAW_FRAME::GetDrawBgColor(), GetDrawFrame(), GetLayerColor(), LAYER_SCHEMATIC_BACKGROUND, 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().

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

Definition at line 54 of file widget_eeschema_color_config.h.

References m_drawFrame.

Referenced by CreateControls(), and TransferDataFromControl().

54 { return m_drawFrame; }
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 316 of file widget_eeschema_color_config.cpp.

Referenced by DIALOG_EESCHEMA_OPTIONS::DIALOG_EESCHEMA_OPTIONS().

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

Definition at line 227 of file widget_eeschema_color_config.cpp.

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

Referenced by CreateControls().

228 {
229  wxBitmapButton* button = (wxBitmapButton*) event.GetEventObject();
230 
231  wxCHECK_RET( button != NULL, wxT( "Color button event object is NULL." ) );
232 
233  COLORBUTTON* colorButton = (COLORBUTTON*) button->GetClientData();
234 
235  wxCHECK_RET( colorButton != NULL, wxT( "Client data not set for color button." ) );
236  COLOR4D oldColor = currentColors[ SCH_LAYER_INDEX( colorButton->m_Layer ) ];
237  COLOR4D newColor = COLOR4D::UNSPECIFIED;
238  COLOR4D_PICKER_DLG dialog( this, oldColor, false );
239 
240  if( dialog.ShowModal() == wxID_OK )
241  {
242  newColor = dialog.GetColor();
243  }
244 
245  if( newColor == COLOR4D::UNSPECIFIED || oldColor == newColor )
246  return;
247 
248  currentColors[ SCH_LAYER_INDEX( colorButton->m_Layer ) ] = newColor;
249 
250  wxMemoryDC iconDC;
251 
252  wxBitmap bitmap = button->GetBitmapLabel();
253  iconDC.SelectObject( bitmap );
254  iconDC.SetPen( *wxBLACK_PEN );
255 
256  wxBrush brush;
257  brush.SetColour( newColor.ToColour() );
258  brush.SetStyle( wxBRUSHSTYLE_SOLID );
259 
260  iconDC.SetBrush( brush );
261  iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
262  button->SetBitmapLabel( bitmap );
263  button->Refresh();
264 
265  Refresh( false );
266 }
static COLOR4D currentColors[SCH_LAYER_ID_COUNT]
#define SCH_LAYER_INDEX(x)
void Refresh()
const int BUTT_SIZE_Y
const int BUTT_SIZE_X
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 269 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 DIALOG_EESCHEMA_OPTIONS::TransferDataFromWindow().

270 {
271  bool warning = false;
272 
273  // Check for color conflicts with background color to give user a chance to bail
274  // out before making changes.
275 
277 
278  for( SCH_LAYER_ID clyr = LAYER_WIRE; clyr < SCH_LAYER_ID_END; ++clyr )
279  {
280  if( bgcolor == currentColors[ SCH_LAYER_INDEX( clyr ) ] && clyr != LAYER_SCHEMATIC_BACKGROUND )
281  {
282  warning = true;
283  break;
284  }
285  }
286 
287  // Prompt the user if an item has the same color as the background
288  // because this item cannot be seen:
289  if( warning )
290  {
291  if( wxMessageBox( _( "Some items have the same color as the background\n"
292  "and they will not be seen on the screen. Are you\n"
293  "sure you want to use these colors?" ),
294  _( "Warning" ),
295  wxYES_NO | wxICON_QUESTION, this ) == wxNO )
296  return false;
297  }
298 
299  // Update color of background
300  GetDrawFrame()->SetDrawBgColor( bgcolor );
302 
303 
304  for( SCH_LAYER_ID clyr = LAYER_WIRE; clyr < SCH_LAYER_ID_END; ++clyr )
305  {
306  SetLayerColor( currentColors[ SCH_LAYER_INDEX( clyr ) ], clyr );
307  }
308 
311 
312  return true;
313 }
void SetLayerColor(COLOR4D aColor, SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:174
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:299
static COLOR4D currentColors[SCH_LAYER_ID_COUNT]
virtual void SetDrawBgColor(COLOR4D aColor)
Definition: draw_frame.h:291
#define SCH_LAYER_INDEX(x)
virtual void SetGridColor(COLOR4D aColor)
Function SetGridColor() , virtual.
Definition: draw_frame.h:457
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

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 47 of file widget_eeschema_color_config.h.

Referenced by CreateControls().

wxColourPickerCtrl* WIDGET_EESCHEMA_COLOR_CONFIG::m_SelBgColor
private

Definition at line 46 of file widget_eeschema_color_config.h.


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