KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_line_properties.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 <[email protected]>
5 * Copyright The 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 <sch_line.h>
29#include <sch_edit_frame.h>
30#include <stroke_params.h>
32#include <sch_commit.h>
33
34
36 std::deque<SCH_LINE*>& aLines ) :
38 m_frame( aParent ),
39 m_lines( aLines ),
40 m_width( aParent, m_staticTextWidth, m_lineWidth, m_staticWidthUnits, true )
41{
42 m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
43
46
47 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
48 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
49
51
52 for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
53 m_typeCombo->Append( lineStyleDesc.name, KiBitmapBundle( lineStyleDesc.bitmap ) );
54
55 SetupStandardButtons( { { wxID_APPLY, _( "Default" ) } } );
56
57 // Now all widgets have the size fixed, call FinishDialogSettings
59}
60
61
63{
64 SCH_LINE* first_stroke_item = m_lines.front();
65
66 if( std::all_of( m_lines.begin() + 1, m_lines.end(),
67 [&]( const SCH_LINE* r )
68 {
69 return r->GetPenWidth() == first_stroke_item->GetPenWidth();
70 } ) )
71 {
72 m_width.SetValue( first_stroke_item->GetStroke().GetWidth() );
73 }
74 else
75 {
77 }
78
79 if( std::all_of( m_lines.begin() + 1, m_lines.end(),
80 [&]( const SCH_LINE* r )
81 {
82 return r->GetStroke().GetColor() == first_stroke_item->GetStroke().GetColor();
83 } ) )
84 {
85 m_colorSwatch->SetSwatchColor( first_stroke_item->GetStroke().GetColor(), false );
86 }
87 else
88 {
89 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
90 }
91
92 if( std::all_of( m_lines.begin() + 1, m_lines.end(),
93 [&]( const SCH_LINE* r )
94 {
95 return r->GetStroke().GetLineStyle() == first_stroke_item->GetStroke().GetLineStyle();
96 } ) )
97 {
98 int style = static_cast<int>( first_stroke_item->GetStroke().GetLineStyle() );
99
100 if( style >= 0 && style < (int) lineTypeNames.size() )
101 m_typeCombo->SetSelection( style );
102 else
103 m_typeCombo->SetSelection( 0 );
104 }
105 else
106 {
108 m_typeCombo->SetStringSelection( INDETERMINATE_STYLE );
109 }
110
111 return true;
112}
113
114
115void DIALOG_LINE_PROPERTIES::resetDefaults( wxCommandEvent& event )
116{
117 m_width.SetValue( 0 );
118 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
119
120 m_typeCombo->SetStringSelection( DEFAULT_LINE_STYLE_LABEL );
121
122 Refresh();
123}
124
125
127{
128 SCH_COMMIT commit( m_frame );
129
130 for( SCH_LINE* line : m_lines )
131 {
132 commit.Modify( line, m_frame->GetScreen() );
133
134 if( !m_width.IsIndeterminate() )
135 line->SetLineWidth( std::max( 0, m_width.GetIntValue() ) );
136
137 auto it = lineTypeNames.begin();
138 std::advance( it, m_typeCombo->GetSelection() );
139
140 if( it == lineTypeNames.end() )
141 line->SetLineStyle( LINE_STYLE::DEFAULT );
142 else
143 line->SetLineStyle( it->first );
144
145 line->SetLineColor( m_colorSwatch->GetSwatchColor() );
146 }
147
148 commit.Push( m_lines.size() == 1 ? _( "Edit Line" ) : _( "Edit Lines" ) );
149 return true;
150}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
COLOR4D GetColor(int aLayer) const
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
KIGFX::COLOR4D GetSwatchColor() const
void SetDefaultColor(const KIGFX::COLOR4D &aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
void SetSwatchBackground(const KIGFX::COLOR4D &aBackground)
Set the swatch background color.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Modify a given item in the model.
Definition: commit.h:108
Class DIALOG_LINE_PROPERTIES_BASE.
std::deque< SCH_LINE * > m_lines
DIALOG_LINE_PROPERTIES(SCH_EDIT_FRAME *aParent, std::deque< SCH_LINE * > &aLines)
void resetDefaults(wxCommandEvent &event) override
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:102
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
wxColour ToColour() const
Definition: color4d.cpp:220
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Definition: sch_commit.cpp:432
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:189
int GetWidth() const
LINE_STYLE GetLineStyle() const
KIGFX::COLOR4D GetColor() const
int GetIntValue()
Definition: unit_binder.h:129
bool IsIndeterminate() const
Return true if the control holds the indeterminate value (for instance, if it represents a multiple s...
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
#define _(s)
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:476
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:155
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
const std::map< LINE_STYLE, struct LINE_STYLE_DESC > lineTypeNames
Conversion map between LINE_STYLE values and style names displayed.
#define INDETERMINATE_STYLE
Definition: stroke_params.h:87
#define DEFAULT_LINE_STYLE_LABEL
Definition: stroke_params.h:85
#define INDETERMINATE_ACTION
Definition: ui_common.h:47