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 (C) 2014-2024 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 m_typeCombo->Append( DEFAULT_STYLE );
56
57 SetupStandardButtons( { { wxID_APPLY, _( "Default" ) } } );
58
59 // Now all widgets have the size fixed, call FinishDialogSettings
61}
62
63
65{
66 SCH_LINE* first_stroke_item = m_lines.front();
67
68 if( std::all_of( m_lines.begin() + 1, m_lines.end(),
69 [&]( const SCH_LINE* r )
70 {
71 return r->GetPenWidth() == first_stroke_item->GetPenWidth();
72 } ) )
73 {
74 m_width.SetValue( first_stroke_item->GetStroke().GetWidth() );
75 }
76 else
77 {
79 }
80
81 if( std::all_of( m_lines.begin() + 1, m_lines.end(),
82 [&]( const SCH_LINE* r )
83 {
84 return r->GetStroke().GetColor() == first_stroke_item->GetStroke().GetColor();
85 } ) )
86 {
87 m_colorSwatch->SetSwatchColor( first_stroke_item->GetStroke().GetColor(), false );
88 }
89 else
90 {
91 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
92 }
93
94 if( std::all_of( m_lines.begin() + 1, m_lines.end(),
95 [&]( const SCH_LINE* r )
96 {
97 return r->GetStroke().GetLineStyle() == first_stroke_item->GetStroke().GetLineStyle();
98 } ) )
99 {
100 int style = static_cast<int>( first_stroke_item->GetStroke().GetLineStyle() );
101
102 if( style == -1 )
103 m_typeCombo->SetStringSelection( DEFAULT_STYLE );
104 else if( style < (int) lineTypeNames.size() )
105 m_typeCombo->SetSelection( style );
106 else
107 wxFAIL_MSG( wxT( "Line type not found in the type lookup map" ) );
108 }
109 else
110 {
112 m_typeCombo->SetStringSelection( INDETERMINATE_STYLE );
113 }
114
115 return true;
116}
117
118
119void DIALOG_LINE_PROPERTIES::resetDefaults( wxCommandEvent& event )
120{
121 m_width.SetValue( 0 );
122 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
123
124 m_typeCombo->SetStringSelection( DEFAULT_STYLE );
125
126 Refresh();
127}
128
129
131{
132 SCH_COMMIT commit( m_frame );
133
134 for( SCH_LINE* line : m_lines )
135 {
136 commit.Modify( line, m_frame->GetScreen() );
137
138 if( !m_width.IsIndeterminate() )
139 line->SetLineWidth( std::max( 0, m_width.GetIntValue() ) );
140
141 auto it = lineTypeNames.begin();
142 std::advance( it, m_typeCombo->GetSelection() );
143
144 if( it == lineTypeNames.end() )
145 line->SetLineStyle( LINE_STYLE::DEFAULT );
146 else
147 line->SetLineStyle( it->first );
148
149 line->SetLineColor( m_colorSwatch->GetSwatchColor() );
150 }
151
152 commit.Push( m_lines.size() == 1 ? _( "Edit Line" ) : _( "Edit Lines" ) );
153 return true;
154}
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)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
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
Revert the commit by restoring the modified items state.
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:184
int GetWidth() const
Definition: stroke_params.h:89
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:92
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:95
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:391
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:154
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
#define INDETERMINATE_STYLE
Definition: stroke_params.h:72
#define INDETERMINATE_ACTION
Definition: ui_common.h:47