KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_wire_bus_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-2021 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>
26#include <sch_bus_entry.h>
27#include <sch_junction.h>
31#include <sch_edit_frame.h>
32#include <stroke_params.h>
34#include <sch_commit.h>
35
36
38 std::deque<SCH_ITEM*>& aItems ) :
40 m_frame( aParent ),
41 m_items( aItems ),
42 m_wireWidth( aParent, m_staticTextWidth, m_lineWidth, m_staticWidthUnits ),
43 m_junctionSize( aParent, m_dotSizeLabel, m_dotSizeCtrl, m_dotSizeUnits )
44{
45 m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
46
49
50 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
51 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
52
54
55 for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
56 m_typeCombo->Append( lineStyleDesc.name, KiBitmapBundle( lineStyleDesc.bitmap ) );
57
58 m_typeCombo->Append( DEFAULT_STYLE );
59
60 SetupStandardButtons( { { wxID_APPLY, _( "Default" ) } } );
61
62 // Now all widgets have the size fixed, call FinishDialogSettings
64}
65
66
68{
69 STROKE_PARAMS stroke;
71 int dotSize = -1; // set value to "not found"
72
73 for( SCH_ITEM* item : m_items )
74 {
75 if( item->HasLineStroke() )
76 {
77 stroke = item->GetStroke();
78 color = stroke.GetColor();
79 }
80 else
81 {
82 wxASSERT( item->Type() == SCH_JUNCTION_T );
83 SCH_JUNCTION* junction = static_cast<SCH_JUNCTION*>( item );
84 color = junction->GetColor();
85 dotSize = junction->GetDiameter();
86 }
87 }
88
89 if( std::all_of( m_items.begin(), m_items.end(),
90 [&]( const SCH_ITEM* item )
91 {
92 return !item->HasLineStroke() || item->GetStroke().GetWidth() == stroke.GetWidth();
93 } ) )
94 {
95 m_wireWidth.SetValue( stroke.GetWidth() );
96 }
97 else
98 {
100 }
101
102 if( std::all_of( m_items.begin(), m_items.end(),
103 [&]( const SCH_ITEM* item )
104 {
105 if( item->HasLineStroke() )
106 return item->GetStroke().GetColor() == color;
107 else
108 return static_cast<const SCH_JUNCTION*>( item )->GetColor() == color;
109 } ) )
110 {
112 }
113 else
114 {
115 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
116 }
117
118 if( std::all_of( m_items.begin(), m_items.end(),
119 [&]( const SCH_ITEM* item )
120 {
121 return !item->HasLineStroke()
122 || item->GetStroke().GetLineStyle() == stroke.GetLineStyle();
123 } ) )
124 {
125 int style = static_cast<int>( stroke.GetLineStyle() );
126
127 if( style == -1 )
128 m_typeCombo->SetStringSelection( DEFAULT_STYLE );
129 else if( style < (int) lineTypeNames.size() )
130 m_typeCombo->SetSelection( style );
131 else
132 wxFAIL_MSG( "Line type not found in the type lookup map" );
133 }
134 else
135 {
137 m_typeCombo->SetStringSelection( INDETERMINATE_STYLE );
138 }
139
140 if( std::all_of( m_items.begin(), m_items.end(),
141 [&]( const SCH_ITEM* item )
142 {
143 return item->Type() != SCH_JUNCTION_T
144 || static_cast<const SCH_JUNCTION*>( item )->GetDiameter() == dotSize;
145 } ) )
146 {
147 if( dotSize >=0 )
148 m_junctionSize.SetValue( dotSize );
149 else
150 {
151 // No junction found in selected items: disable m_junctionSize
152 m_junctionSize.Enable( false );
154 }
155 }
156 else
157 {
159 }
160
161 return true;
162}
163
164
165void DIALOG_WIRE_BUS_PROPERTIES::resetDefaults( wxCommandEvent& event )
166{
168 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
169 m_typeCombo->SetStringSelection( DEFAULT_STYLE );
171
172 Refresh();
173}
174
175
177{
178 SCH_COMMIT commit( m_frame );
179
180 for( SCH_ITEM* item : m_items )
181 {
182 commit.Modify( item, m_frame->GetScreen() );
183
184 if( item->HasLineStroke() )
185 {
187 {
188 int width = std::max( 0, m_wireWidth.GetIntValue() );
189
190 if( item->Type() == SCH_LINE_T )
191 static_cast<SCH_LINE*>( item )->SetLineWidth( width );
192 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
193 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetPenWidth( width );
194 }
195
196 if( m_typeCombo->GetStringSelection() != INDETERMINATE_STYLE )
197 {
198 LINE_STYLE lineStyle = LINE_STYLE::DEFAULT;
199
200 size_t lineTypeSelection = m_typeCombo->GetSelection();
201 auto it = lineTypeNames.begin();
202 std::advance( it, lineTypeSelection );
203
204 if( it != lineTypeNames.end() )
205 lineStyle = it->first;
206
207 if( item->Type() == SCH_LINE_T )
208 static_cast<SCH_LINE*>( item )->SetLineStyle( lineStyle );
209 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
210 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetLineStyle( lineStyle );
211 }
212
214
215 if( item->Type() == SCH_LINE_T )
216 static_cast<SCH_LINE*>( item )->SetLineColor( color );
217 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
218 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetBusEntryColor( color );
219 }
220 else
221 {
222 SCH_JUNCTION* junction = static_cast<SCH_JUNCTION*>( item );
223
224 junction->SetColor( m_colorSwatch->GetSwatchColor() );
225
227 junction->SetDiameter( m_junctionSize.GetValue() );
228 }
229 }
230
231 commit.Push( wxString::Format( _( "Edit %s" ), m_items.size() == 1 ? _( "Wire/Bus" )
232 : _( "Wires/Buses" ) ) );
233 return true;
234}
int color
Definition: DXF_plotter.cpp:58
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
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:98
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...
Class DIALOG_WIRE_BUS_PROPERTIES_BASE.
std::deque< SCH_ITEM * > m_items
DIALOG_WIRE_BUS_PROPERTIES(SCH_EDIT_FRAME *aParent, std::deque< SCH_ITEM * > &aItems)
void resetDefaults(wxCommandEvent &event) override
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.
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:38
void SetBusEntryColor(const COLOR4D &aColor)
void SetPenWidth(int aWidth)
void SetLineStyle(LINE_STYLE aStyle)
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:403
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:172
void SetDiameter(int aDiameter)
COLOR4D GetColor() const
Definition: sch_junction.h:119
int GetDiameter() const
Definition: sch_junction.h:114
void SetColor(const COLOR4D &aColor)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:249
Simple container to manage line stroke parameters.
Definition: stroke_params.h:81
int GetWidth() const
Definition: stroke_params.h:91
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:94
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:97
int GetIntValue()
Definition: unit_binder.h:127
virtual long long int GetValue()
Return the current value in Internal Units.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
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:389
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:151
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
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:48
#define INDETERMINATE_STYLE
Definition: stroke_params.h:74
@ SCH_LINE_T
Definition: typeinfo.h:163
@ SCH_JUNCTION_T
Definition: typeinfo.h:159
#define INDETERMINATE_ACTION
Definition: ui_common.h:46