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 <sch_line.h>
22#include <sch_bus_entry.h>
23#include <sch_junction.h>
28#include <sch_edit_frame.h>
29#include <stroke_params.h>
31#include <sch_commit.h>
32
33
35 std::deque<SCH_ITEM*>& aItems ) :
37 m_frame( aParent ),
38 m_items( aItems ),
41{
42 m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
43
44 KIGFX::COLOR4D canvas = m_frame->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND );
45 m_colorSwatch->SetSwatchBackground( canvas.ToColour() );
46
47 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
48 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
49
51
52 for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
53 m_typeCombo->Append( lineStyleDesc.name, KiBitmapBundle( lineStyleDesc.bitmap ) );
54
56
57 SetupStandardButtons( { { wxID_APPLY, _( "Default" ) } } );
58
59 // Now all widgets have the size fixed, call FinishDialogSettings
61}
62
63
65{
66 STROKE_PARAMS stroke;
67 COLOR4D color;
68 int dotSize = -1; // set value to "not found"
69
70 for( SCH_ITEM* item : m_items )
71 {
72 if( item->HasLineStroke() )
73 {
74 stroke = item->GetStroke();
75 color = stroke.GetColor();
76 }
77 else
78 {
79 wxASSERT( item->Type() == SCH_JUNCTION_T );
80 SCH_JUNCTION* junction = static_cast<SCH_JUNCTION*>( item );
81 color = junction->GetColor();
82 dotSize = junction->GetDiameter();
83 }
84 }
85
86 if( std::all_of( m_items.begin(), m_items.end(),
87 [&]( const SCH_ITEM* item )
88 {
89 return !item->HasLineStroke() || item->GetStroke().GetWidth() == stroke.GetWidth();
90 } ) )
91 {
92 m_wireWidth.SetValue( stroke.GetWidth() );
93 }
94 else
95 {
97 }
98
99 if( std::all_of( m_items.begin(), m_items.end(),
100 [&]( const SCH_ITEM* item )
101 {
102 if( item->HasLineStroke() )
103 return item->GetStroke().GetColor() == color;
104 else
105 return static_cast<const SCH_JUNCTION*>( item )->GetColor() == color;
106 } ) )
107 {
108 m_colorSwatch->SetSwatchColor( color, false );
109 }
110 else
111 {
112 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
113 }
114
115 if( std::all_of( m_items.begin(), m_items.end(),
116 [&]( const SCH_ITEM* item )
117 {
118 return !item->HasLineStroke()
119 || item->GetStroke().GetLineStyle() == stroke.GetLineStyle();
120 } ) )
121 {
122 int style = static_cast<int>( stroke.GetLineStyle() );
123
124 if( style == -1 )
125 m_typeCombo->SetStringSelection( DEFAULT_WIRE_STYLE_LABEL );
126 else if( style < (int) lineTypeNames.size() )
127 m_typeCombo->SetSelection( style );
128 else
129 wxFAIL_MSG( "Line type not found in the type lookup map" );
130 }
131 else
132 {
134 m_typeCombo->SetStringSelection( INDETERMINATE_STYLE );
135 }
136
137 if( std::all_of( m_items.begin(), m_items.end(),
138 [&]( const SCH_ITEM* item )
139 {
140 return item->Type() != SCH_JUNCTION_T
141 || static_cast<const SCH_JUNCTION*>( item )->GetDiameter() == dotSize;
142 } ) )
143 {
144 if( dotSize >=0 )
145 {
146 m_junctionSize.SetValue( dotSize );
147 }
148 else
149 {
150 // No junction found in selected items: disable m_junctionSize
151 m_junctionSize.Enable( false );
153 }
154 }
155 else
156 {
158 }
159
160 return true;
161}
162
163
164void DIALOG_WIRE_BUS_PROPERTIES::resetDefaults( wxCommandEvent& event )
165{
166 m_wireWidth.SetValue( 0 );
167 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
168 m_typeCombo->SetStringSelection( DEFAULT_WIRE_STYLE_LABEL );
169 m_junctionSize.SetValue( 0 );
170
171 Refresh();
172}
173
174
176{
177 SCH_COMMIT commit( m_frame );
178
179 for( SCH_ITEM* item : m_items )
180 {
181 commit.Modify( item, m_frame->GetScreen() );
182
183 if( item->HasLineStroke() )
184 {
185 if( !m_wireWidth.IsIndeterminate() )
186 {
187 int width = std::max( 0, m_wireWidth.GetIntValue() );
188
189 if( item->Type() == SCH_LINE_T )
190 static_cast<SCH_LINE*>( item )->SetLineWidth( width );
191 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
192 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetPenWidth( width );
193 }
194
195 if( m_typeCombo->GetStringSelection() != INDETERMINATE_STYLE )
196 {
198
199 size_t lineTypeSelection = m_typeCombo->GetSelection();
200 auto it = lineTypeNames.begin();
201 std::advance( it, lineTypeSelection );
202
203 if( it != lineTypeNames.end() )
204 lineStyle = it->first;
205
206 if( item->Type() == SCH_LINE_T )
207 static_cast<SCH_LINE*>( item )->SetLineStyle( lineStyle );
208 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
209 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetLineStyle( lineStyle );
210 }
211
212 COLOR4D color = m_colorSwatch->GetSwatchColor();
213
214 if( item->Type() == SCH_LINE_T )
215 static_cast<SCH_LINE*>( item )->SetLineColor( color );
216 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
217 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetBusEntryColor( color );
218 }
219 else
220 {
221 SCH_JUNCTION* junction = static_cast<SCH_JUNCTION*>( item );
222
223 junction->SetColor( m_colorSwatch->GetSwatchColor() );
224
225 if( !m_junctionSize.IsIndeterminate() )
226 junction->SetDiameter( m_junctionSize.GetValue() );
227 }
228 }
229
230 commit.Push( wxString::Format( _( "Edit %s" ), m_items.size() == 1 ? _( "Wire/Bus" )
231 : _( "Wires/Buses" ) ) );
232 return true;
233}
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:398
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:79
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.
virtual void Push(const wxString &aMessage=wxT("A commit"), 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:162
void SetDiameter(int aDiameter)
COLOR4D GetColor() const
int GetDiameter() const
void SetColor(const COLOR4D &aColor)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:38
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:486
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:160
@ SCH_JUNCTION_T
Definition typeinfo.h:156
#define INDETERMINATE_ACTION
Definition ui_common.h:47