KiCad PCB EDA Suite
dialog_edit_line_style.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) 2017 Seth Hillbrand <hillbrand@ucdavis.edu>
5  * Copyright (C) 2014-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 #include <cassert>
26 #include <sch_edit_frame.h>
27 #include <sch_line.h>
29 #include <dialog_edit_line_style.h>
30 
31 const int BUTT_COLOR_MINSIZE_X = 32;
32 const int BUTT_COLOR_MINSIZE_Y = 20;
33 
35  DIALOG_EDIT_LINE_STYLE_BASE( aParent ),
36  m_frame( aParent ),
37  m_line( aLine ),
38  m_width( aParent, m_staticTextWidth, m_lineWidth, m_staticWidthUnits, true, 0 )
39 {
40  m_sdbSizerApply->SetLabel( _( "Default" ) );
41 
42  wxBitmap bitmap( std::max( m_colorButton->GetSize().x, BUTT_COLOR_MINSIZE_X ),
43  std::max( m_colorButton->GetSize().y, BUTT_COLOR_MINSIZE_Y ) );
44  m_colorButton->SetBitmap( bitmap );
45 
47 
48  m_sdbSizerOK->SetDefault();
49 
50  // Now all widgets have the size fixed, call FinishDialogSettings
52 }
53 
54 
56 {
59  m_lineStyle->SetSelection( m_line->GetLineStyle() );
60 
61  return true;
62 }
63 
64 
65 void DIALOG_EDIT_LINE_STYLE::onColorButtonClicked( wxCommandEvent& event )
66 {
67  COLOR4D newColor = COLOR4D::UNSPECIFIED;
68  DIALOG_COLOR_PICKER dialog( this, m_selectedColor, false );
69 
70  if( dialog.ShowModal() == wxID_OK )
71  newColor = dialog.GetColor();
72 
73  if( newColor == COLOR4D::UNSPECIFIED || m_selectedColor == newColor )
74  return;
75 
76  setColor( newColor );
77 
78 }
79 
81 {
82  wxMemoryDC iconDC;
83 
84  wxBitmap bitmap = m_colorButton->GetBitmapLabel();
85  iconDC.SelectObject( bitmap );
86  iconDC.SetPen( *wxBLACK_PEN );
87 
88  wxBrush brush( aColor.ToColour() );
89  iconDC.SetBrush( brush );
90 
91  // Paint the full bitmap in aColor:
92  iconDC.SetBackground( brush );
93  iconDC.Clear();
94 
95  m_colorButton->SetBitmapLabel( bitmap );
96  m_colorButton->Refresh();
97 
98  Refresh( false );
99 }
100 
101 
102 void DIALOG_EDIT_LINE_STYLE::resetDefaults( wxCommandEvent& event )
103 {
106  m_lineStyle->SetSelection( m_line->GetDefaultStyle() );
107  Refresh();
108 }
109 
110 
112 {
113  m_selectedColor = aColor;
115 }
116 
117 
119 {
121 
123  m_line->SetLineStyle( m_lineStyle->GetSelection() );
125 
127  m_frame->GetCanvas()->Refresh();
128  m_frame->OnModify();
129 
130  return true;
131 }
void OnModify()
Must be called after a schematic change in order to set the "modify" flag of the current screen* and ...
COLOR4D GetLineColor() const
Definition: sch_line.cpp:243
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:287
void updateColorButton(COLOR4D &aColor)
const int BUTT_COLOR_MINSIZE_X
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Schematic editor (Eeschema) main window.
void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:115
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
void SetLineColor(const COLOR4D aColor)
Definition: sch_line.cpp:219
COLOR4D GetDefaultColor() const
Definition: sch_line.cpp:213
const int BUTT_COLOR_MINSIZE_Y
void SetLineStyle(const int aStyle)
Definition: sch_line.cpp:260
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void resetDefaults(wxCommandEvent &event) override
void setColor(const COLOR4D &aColor)
SCH_DRAW_PANEL * GetCanvas() const override
void SaveCopyInUndoList(SCH_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, bool aAppend=false, const wxPoint &aTransformPoint=wxPoint(0, 0))
Create a copy of the current schematic item, and put it in the undo list.
int GetLineStyle() const
Definition: sch_line.cpp:269
void onColorButtonClicked(wxCommandEvent &aEvent) override
int GetDefaultWidth() const
Definition: sch_line.cpp:278
Segment description base class to describe items which have 2 end points (track, wire, draw line ...)
Definition: sch_line.h:41
#define max(a, b)
Definition: auxiliary.h:86
void RefreshItem(SCH_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
KIGFX::COLOR4D GetColor()
int GetDefaultStyle() const
Definition: sch_line.cpp:251
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_line.cpp:296
Class DIALOG_EDIT_LINE_STYLE_BASE.
DIALOG_EDIT_LINE_STYLE(SCH_EDIT_FRAME *aParent, SCH_LINE *aLine)
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39