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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <bitmaps.h>
22#include <sch_line.h>
23#include <sch_bus_entry.h>
24#include <sch_junction.h>
29#include <sch_edit_frame.h>
30#include <stroke_params.h>
32#include <sch_commit.h>
33
34
36 std::deque<SCH_ITEM*>& aItems ) :
38 m_frame( aParent ),
39 m_items( aItems ),
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
57
58 SetupStandardButtons( { { wxID_APPLY, _( "Default" ) } } );
59
60 // Now all widgets have the size fixed, call FinishDialogSettings
62}
63
64
66{
67 STROKE_PARAMS stroke;
68 COLOR4D color;
69 int dotSize = -1; // set value to "not found"
70
71 for( SCH_ITEM* item : m_items )
72 {
73 if( item->HasLineStroke() )
74 {
75 stroke = item->GetStroke();
76 color = stroke.GetColor();
77 }
78 else
79 {
80 wxASSERT( item->Type() == SCH_JUNCTION_T );
81 SCH_JUNCTION* junction = static_cast<SCH_JUNCTION*>( item );
82 color = junction->GetColor();
83 dotSize = junction->GetDiameter();
84 }
85 }
86
87 if( std::all_of( m_items.begin(), m_items.end(),
88 [&]( const SCH_ITEM* item )
89 {
90 return !item->HasLineStroke() || item->GetStroke().GetWidth() == stroke.GetWidth();
91 } ) )
92 {
93 m_wireWidth.SetValue( stroke.GetWidth() );
94 }
95 else
96 {
98 }
99
100 if( std::all_of( m_items.begin(), m_items.end(),
101 [&]( const SCH_ITEM* item )
102 {
103 if( item->HasLineStroke() )
104 return item->GetStroke().GetColor() == color;
105 else
106 return static_cast<const SCH_JUNCTION*>( item )->GetColor() == color;
107 } ) )
108 {
109 m_colorSwatch->SetSwatchColor( color, false );
110 }
111 else
112 {
113 m_colorSwatch->SetIndeterminate();
114 }
115
116 if( std::all_of( m_items.begin(), m_items.end(),
117 [&]( const SCH_ITEM* item )
118 {
119 return !item->HasLineStroke()
120 || item->GetStroke().GetLineStyle() == stroke.GetLineStyle();
121 } ) )
122 {
123 int style = static_cast<int>( stroke.GetLineStyle() );
124
125 if( style == -1 )
126 m_typeCombo->SetStringSelection( DEFAULT_WIRE_STYLE_LABEL );
127 else if( style < (int) lineTypeNames.size() )
128 m_typeCombo->SetSelection( style );
129 else
130 wxFAIL_MSG( "Line type not found in the type lookup map" );
131 }
132 else
133 {
135 m_typeCombo->SetStringSelection( INDETERMINATE_STYLE );
136 }
137
138 if( std::all_of( m_items.begin(), m_items.end(),
139 [&]( const SCH_ITEM* item )
140 {
141 return item->Type() != SCH_JUNCTION_T
142 || static_cast<const SCH_JUNCTION*>( item )->GetDiameter() == dotSize;
143 } ) )
144 {
145 if( dotSize >=0 )
146 {
147 m_junctionSize.SetValue( dotSize );
148 }
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{
167 m_wireWidth.SetValue( 0 );
168 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
169 m_typeCombo->SetStringSelection( DEFAULT_WIRE_STYLE_LABEL );
170 m_junctionSize.SetValue( 0 );
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 {
186 if( !m_wireWidth.IsIndeterminate() )
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 {
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
213 if( !m_colorSwatch->IsIndeterminate() )
214 {
215 COLOR4D color = m_colorSwatch->GetSwatchColor();
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 }
223 else
224 {
225 SCH_JUNCTION* junction = static_cast<SCH_JUNCTION*>( item );
226
227 if( !m_colorSwatch->IsIndeterminate() )
228 junction->SetColor( m_colorSwatch->GetSwatchColor() );
229
230 if( !m_junctionSize.IsIndeterminate() )
231 junction->SetDiameter( m_junctionSize.GetIntValue() );
232 }
233 }
234
235 commit.Push( wxString::Format( _( "Edit %s" ), m_items.size() == 1 ? _( "Wire/Bus" )
236 : _( "Wires/Buses" ) ) );
237 return true;
238}
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:400
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
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:94
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...
DIALOG_WIRE_BUS_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Wire & Bus Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
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:101
wxColour ToColour() const
Definition color4d.cpp:221
Base class for a bus or wire entry.
Commit for the schematic and symbol editors.
Definition sch_commit.h:54
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
void SetColor(const KIGFX::COLOR4D &aColor)
void SetDiameter(int aDiameter)
int GetDiameter() const
KIGFX::COLOR4D GetColor() const
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
Simple container to manage line stroke parameters.
int GetWidth() const
LINE_STYLE GetLineStyle() const
KIGFX::COLOR4D GetColor() const
#define _(s)
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:516
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.
LINE_STYLE
Dashed line types.
#define INDETERMINATE_STYLE
#define DEFAULT_WIRE_STYLE_LABEL
@ SCH_LINE_T
Definition typeinfo.h:159
@ SCH_JUNCTION_T
Definition typeinfo.h:155
#define INDETERMINATE_ACTION
Definition ui_common.h:48