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-2022 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
33
35 std::deque<SCH_LINE*>& aLines ) :
37 m_frame( aParent ),
38 m_lines( aLines ),
39 m_width( aParent, m_staticTextWidth, m_lineWidth, m_staticWidthUnits, true )
40{
41 m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
42
45
46 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
47 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
48
50
51 for( const std::pair<const PLOT_DASH_TYPE, lineTypeStruct>& typeEntry : lineTypeNames )
52 m_typeCombo->Append( typeEntry.second.name, KiBitmap( typeEntry.second.bitmap ) );
53
54 m_typeCombo->Append( DEFAULT_STYLE );
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 {
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().GetPlotStyle() == first_stroke_item->GetStroke().GetPlotStyle();
97 } ) )
98 {
99 int style = static_cast<int>( first_stroke_item->GetStroke().GetPlotStyle() );
100
101 if( style == -1 )
102 m_typeCombo->SetStringSelection( DEFAULT_STYLE );
103 else if( style < (int) lineTypeNames.size() )
104 m_typeCombo->SetSelection( style );
105 else
106 wxFAIL_MSG( "Line type not found in the type lookup map" );
107 }
108 else
109 {
111 m_typeCombo->SetStringSelection( INDETERMINATE_STYLE );
112 }
113
114 return true;
115}
116
117
118void DIALOG_LINE_PROPERTIES::resetDefaults( wxCommandEvent& event )
119{
120 m_width.SetValue( 0 );
121 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
122
123 m_typeCombo->SetStringSelection( DEFAULT_STYLE );
124
125 Refresh();
126}
127
128
130{
131 PICKED_ITEMS_LIST pickedItems;
132
133 for( SCH_LINE* line : m_lines )
134 pickedItems.PushItem( ITEM_PICKER( m_frame->GetScreen(), line, UNDO_REDO::CHANGED ) );
135
136 m_frame->SaveCopyInUndoList( pickedItems, UNDO_REDO::CHANGED, false, false );
137
138 for( SCH_LINE* line : m_lines )
139 {
140 if( !m_width.IsIndeterminate() )
141 line->SetLineWidth( std::max( (long long int) 0, m_width.GetValue() ) );
142
143 auto it = lineTypeNames.begin();
144 std::advance( it, m_typeCombo->GetSelection() );
145
146 if( it == lineTypeNames.end() )
147 line->SetLineStyle( PLOT_DASH_TYPE::DEFAULT );
148 else
149 line->SetLineStyle( it->first );
150
151 line->SetLineColor( m_colorSwatch->GetSwatchColor() );
152
153 m_frame->UpdateItem( line, false, true );
154 }
155
157 m_frame->OnModify();
158
159 return true;
160}
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:106
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.
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:97
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...
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
wxColour ToColour() const
Definition: color4d.cpp:220
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
Schematic editor (Eeschema) main window.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, bool aDirtyConnectivity=true)
Create a copy of the current schematic item, and put it in the undo list.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:177
int GetWidth() const
Definition: stroke_params.h:98
KIGFX::COLOR4D GetColor() const
PLOT_DASH_TYPE GetPlotStyle() const
virtual long long int GetValue()
Return the current value in Internal Units.
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:380
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:156
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
#define INDETERMINATE_STYLE
Definition: stroke_params.h:81
const std::map< PLOT_DASH_TYPE, struct lineTypeStruct > lineTypeNames
Definition: stroke_params.h:70
#define INDETERMINATE_ACTION
Definition: ui_common.h:43