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 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>
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 {
149 m_junctionSize.SetValue( dotSize );
150 }
151 else
152 {
153 // No junction found in selected items: disable m_junctionSize
154 m_junctionSize.Enable( false );
156 }
157 }
158 else
159 {
161 }
162
163 return true;
164}
165
166
167void DIALOG_WIRE_BUS_PROPERTIES::resetDefaults( wxCommandEvent& event )
168{
170 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
171 m_typeCombo->SetStringSelection( DEFAULT_STYLE );
173
174 Refresh();
175}
176
177
179{
180 SCH_COMMIT commit( m_frame );
181
182 for( SCH_ITEM* item : m_items )
183 {
184 commit.Modify( item, m_frame->GetScreen() );
185
186 if( item->HasLineStroke() )
187 {
189 {
190 int width = std::max( 0, m_wireWidth.GetIntValue() );
191
192 if( item->Type() == SCH_LINE_T )
193 static_cast<SCH_LINE*>( item )->SetLineWidth( width );
194 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
195 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetPenWidth( width );
196 }
197
198 if( m_typeCombo->GetStringSelection() != INDETERMINATE_STYLE )
199 {
200 LINE_STYLE lineStyle = LINE_STYLE::DEFAULT;
201
202 size_t lineTypeSelection = m_typeCombo->GetSelection();
203 auto it = lineTypeNames.begin();
204 std::advance( it, lineTypeSelection );
205
206 if( it != lineTypeNames.end() )
207 lineStyle = it->first;
208
209 if( item->Type() == SCH_LINE_T )
210 static_cast<SCH_LINE*>( item )->SetLineStyle( lineStyle );
211 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
212 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetLineStyle( lineStyle );
213 }
214
216
217 if( item->Type() == SCH_LINE_T )
218 static_cast<SCH_LINE*>( item )->SetLineColor( color );
219 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
220 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetBusEntryColor( color );
221 }
222 else
223 {
224 SCH_JUNCTION* junction = static_cast<SCH_JUNCTION*>( item );
225
226 junction->SetColor( m_colorSwatch->GetSwatchColor() );
227
229 junction->SetDiameter( m_junctionSize.GetValue() );
230 }
231 }
232
233 commit.Push( wxString::Format( _( "Edit %s" ), m_items.size() == 1 ? _( "Wire/Bus" )
234 : _( "Wires/Buses" ) ) );
235 return true;
236}
int color
Definition: DXF_plotter.cpp:60
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)
Modify a given item in the model.
Definition: commit.h:108
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...
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
Execute the changes.
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.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:167
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:41
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:243
Simple container to manage line stroke parameters.
Definition: stroke_params.h:93
int GetWidth() const
LINE_STYLE GetLineStyle() const
KIGFX::COLOR4D GetColor() const
int GetIntValue()
Definition: unit_binder.h:129
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:440
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:155
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.
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:46
#define INDETERMINATE_STYLE
Definition: stroke_params.h:86
#define DEFAULT_STYLE
Definition: stroke_params.h:85
@ SCH_LINE_T
Definition: typeinfo.h:163
@ SCH_JUNCTION_T
Definition: typeinfo.h:159
#define INDETERMINATE_ACTION
Definition: ui_common.h:47