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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <sch_line.h>
26#include <sch_edit_frame.h>
27#include <stroke_params.h>
29#include <sch_commit.h>
30
31
33 std::deque<SCH_LINE*>& aLines ) :
35 m_frame( aParent ),
36 m_lines( aLines ),
38{
39 m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
40
41 KIGFX::COLOR4D canvas = m_frame->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND );
42 m_colorSwatch->SetSwatchBackground( canvas.ToColour() );
43
44 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
45 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
46
48
49 for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
50 m_typeCombo->Append( lineStyleDesc.name, KiBitmapBundle( lineStyleDesc.bitmap ) );
51
52 SetupStandardButtons( { { wxID_APPLY, _( "Default" ) } } );
53
54 // Now all widgets have the size fixed, call FinishDialogSettings
56}
57
58
60{
61 SCH_LINE* first_stroke_item = m_lines.front();
62
63 if( std::all_of( m_lines.begin() + 1, m_lines.end(),
64 [&]( const SCH_LINE* r )
65 {
66 return r->GetPenWidth() == first_stroke_item->GetPenWidth();
67 } ) )
68 {
69 m_width.SetValue( first_stroke_item->GetStroke().GetWidth() );
70 }
71 else
72 {
73 m_width.SetValue( INDETERMINATE_ACTION );
74 }
75
76 if( std::all_of( m_lines.begin() + 1, m_lines.end(),
77 [&]( const SCH_LINE* r )
78 {
79 return r->GetStroke().GetColor() == first_stroke_item->GetStroke().GetColor();
80 } ) )
81 {
82 m_colorSwatch->SetSwatchColor( first_stroke_item->GetStroke().GetColor(), false );
83 }
84 else
85 {
86 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
87 }
88
89 if( std::all_of( m_lines.begin() + 1, m_lines.end(),
90 [&]( const SCH_LINE* r )
91 {
92 return r->GetStroke().GetLineStyle() == first_stroke_item->GetStroke().GetLineStyle();
93 } ) )
94 {
95 int style = static_cast<int>( first_stroke_item->GetStroke().GetLineStyle() );
96
97 if( style >= 0 && style < (int) lineTypeNames.size() )
98 m_typeCombo->SetSelection( style );
99 else
100 m_typeCombo->SetSelection( 0 );
101 }
102 else
103 {
105 m_typeCombo->SetStringSelection( INDETERMINATE_STYLE );
106 }
107
108 return true;
109}
110
111
112void DIALOG_LINE_PROPERTIES::resetDefaults( wxCommandEvent& event )
113{
114 m_width.SetValue( 0 );
115 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
116
117 m_typeCombo->SetStringSelection( DEFAULT_LINE_STYLE_LABEL );
118
119 Refresh();
120}
121
122
124{
125 SCH_COMMIT commit( m_frame );
126
127 for( SCH_LINE* line : m_lines )
128 {
129 // Commit the change only if the line is not new. If new this is useless
130 // and can create dangling pointers if the line creation is aborted
131 if( !line->HasFlag( IS_NEW ) )
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, int aMinHeight)
Definition bitmap.cpp:106
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:398
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:102
DIALOG_LINE_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Line Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
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:79
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:101
wxColour ToColour() const
Definition color4d.cpp:221
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Schematic editor (Eeschema) main window.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:38
virtual STROKE_PARAMS GetStroke() const override
Definition sch_line.h:197
int GetWidth() const
KIGFX::COLOR4D GetColor() const
#define _(s)
#define IS_NEW
New item, just created.
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:486
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
const std::map< LINE_STYLE, struct LINE_STYLE_DESC > lineTypeNames
Conversion map between LINE_STYLE values and style names displayed.
#define INDETERMINATE_STYLE
#define DEFAULT_LINE_STYLE_LABEL
#define INDETERMINATE_ACTION
Definition ui_common.h:47