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>
30#include <sch_edit_frame.h>
31#include <stroke_params.h>
33#include <sch_commit.h>
34
35
37 std::deque<SCH_LINE*>& aLines ) :
39 m_frame( aParent ),
40 m_lines( aLines ),
42{
43 m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
44
45 KIGFX::COLOR4D canvas = m_frame->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND );
46 m_colorSwatch->SetSwatchBackground( canvas.ToColour() );
47
48 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
49 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
50
52
53 for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
54 m_typeCombo->Append( lineStyleDesc.name, KiBitmapBundle( lineStyleDesc.bitmap ) );
55
56 SetupStandardButtons( { { wxID_APPLY, _( "Default" ) } } );
57
58 // Now all widgets have the size fixed, call FinishDialogSettings
60}
61
62
64{
65 SCH_LINE* first_stroke_item = m_lines.front();
66
67 if( std::all_of( m_lines.begin() + 1, m_lines.end(),
68 [&]( const SCH_LINE* r )
69 {
70 return r->GetPenWidth() == first_stroke_item->GetPenWidth();
71 } ) )
72 {
73 m_width.SetValue( first_stroke_item->GetStroke().GetWidth() );
74 }
75 else
76 {
77 m_width.SetValue( INDETERMINATE_ACTION );
78 }
79
80 if( std::all_of( m_lines.begin() + 1, m_lines.end(),
81 [&]( const SCH_LINE* r )
82 {
83 return r->GetStroke().GetColor() == first_stroke_item->GetStroke().GetColor();
84 } ) )
85 {
86 m_colorSwatch->SetSwatchColor( first_stroke_item->GetStroke().GetColor(), false );
87 }
88 else
89 {
90 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
91 }
92
93 if( std::all_of( m_lines.begin() + 1, m_lines.end(),
94 [&]( const SCH_LINE* r )
95 {
96 return r->GetStroke().GetLineStyle() == first_stroke_item->GetStroke().GetLineStyle();
97 } ) )
98 {
99 int style = static_cast<int>( first_stroke_item->GetStroke().GetLineStyle() );
100
101 if( style >= 0 && style < (int) lineTypeNames.size() )
102 m_typeCombo->SetSelection( style );
103 else
104 m_typeCombo->SetSelection( 0 );
105 }
106 else
107 {
109 m_typeCombo->SetStringSelection( INDETERMINATE_STYLE );
110 }
111
112 return true;
113}
114
115
116void DIALOG_LINE_PROPERTIES::resetDefaults( wxCommandEvent& event )
117{
118 m_width.SetValue( 0 );
119 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
120
121 m_typeCombo->SetStringSelection( DEFAULT_LINE_STYLE_LABEL );
122
123 Refresh();
124}
125
126
128{
129 SCH_COMMIT commit( m_frame );
130
131 for( SCH_LINE* line : m_lines )
132 {
133 // Commit the change only if the line is not new. If new this is useless
134 // and can create dangling pointers if the line creation is aborted
135 if( !line->HasFlag( IS_NEW ) )
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, int aMinHeight)
Definition bitmap.cpp:110
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:402
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:106
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:82
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:105
wxColour ToColour() const
Definition color4d.cpp:225
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:42
virtual STROKE_PARAMS GetStroke() const override
Definition sch_line.h:201
int GetWidth() const
KIGFX::COLOR4D GetColor() const
#define _(s)
#define IS_NEW
New item, just created.
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:488
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
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
#define DEFAULT_LINE_STYLE_LABEL
#define INDETERMINATE_ACTION
Definition ui_common.h:47