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>
32#include <sch_edit_frame.h>
33#include <stroke_params.h>
35#include <sch_commit.h>
36
37
39 std::deque<SCH_ITEM*>& aItems ) :
41 m_frame( aParent ),
42 m_items( aItems ),
45{
46 m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
47
48 KIGFX::COLOR4D canvas = m_frame->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND );
49 m_colorSwatch->SetSwatchBackground( canvas.ToColour() );
50
51 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
52 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
53
55
56 for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
57 m_typeCombo->Append( lineStyleDesc.name, KiBitmapBundle( lineStyleDesc.bitmap ) );
58
60
61 SetupStandardButtons( { { wxID_APPLY, _( "Default" ) } } );
62
63 // Now all widgets have the size fixed, call FinishDialogSettings
65}
66
67
69{
70 STROKE_PARAMS stroke;
71 COLOR4D color;
72 int dotSize = -1; // set value to "not found"
73
74 for( SCH_ITEM* item : m_items )
75 {
76 if( item->HasLineStroke() )
77 {
78 stroke = item->GetStroke();
79 color = stroke.GetColor();
80 }
81 else
82 {
83 wxASSERT( item->Type() == SCH_JUNCTION_T );
84 SCH_JUNCTION* junction = static_cast<SCH_JUNCTION*>( item );
85 color = junction->GetColor();
86 dotSize = junction->GetDiameter();
87 }
88 }
89
90 if( std::all_of( m_items.begin(), m_items.end(),
91 [&]( const SCH_ITEM* item )
92 {
93 return !item->HasLineStroke() || item->GetStroke().GetWidth() == stroke.GetWidth();
94 } ) )
95 {
96 m_wireWidth.SetValue( stroke.GetWidth() );
97 }
98 else
99 {
101 }
102
103 if( std::all_of( m_items.begin(), m_items.end(),
104 [&]( const SCH_ITEM* item )
105 {
106 if( item->HasLineStroke() )
107 return item->GetStroke().GetColor() == color;
108 else
109 return static_cast<const SCH_JUNCTION*>( item )->GetColor() == color;
110 } ) )
111 {
112 m_colorSwatch->SetSwatchColor( color, false );
113 }
114 else
115 {
116 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
117 }
118
119 if( std::all_of( m_items.begin(), m_items.end(),
120 [&]( const SCH_ITEM* item )
121 {
122 return !item->HasLineStroke()
123 || item->GetStroke().GetLineStyle() == stroke.GetLineStyle();
124 } ) )
125 {
126 int style = static_cast<int>( stroke.GetLineStyle() );
127
128 if( style == -1 )
129 m_typeCombo->SetStringSelection( DEFAULT_WIRE_STYLE_LABEL );
130 else if( style < (int) lineTypeNames.size() )
131 m_typeCombo->SetSelection( style );
132 else
133 wxFAIL_MSG( "Line type not found in the type lookup map" );
134 }
135 else
136 {
138 m_typeCombo->SetStringSelection( INDETERMINATE_STYLE );
139 }
140
141 if( std::all_of( m_items.begin(), m_items.end(),
142 [&]( const SCH_ITEM* item )
143 {
144 return item->Type() != SCH_JUNCTION_T
145 || static_cast<const SCH_JUNCTION*>( item )->GetDiameter() == dotSize;
146 } ) )
147 {
148 if( dotSize >=0 )
149 {
150 m_junctionSize.SetValue( dotSize );
151 }
152 else
153 {
154 // No junction found in selected items: disable m_junctionSize
155 m_junctionSize.Enable( false );
157 }
158 }
159 else
160 {
162 }
163
164 return true;
165}
166
167
168void DIALOG_WIRE_BUS_PROPERTIES::resetDefaults( wxCommandEvent& event )
169{
170 m_wireWidth.SetValue( 0 );
171 m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
172 m_typeCombo->SetStringSelection( DEFAULT_WIRE_STYLE_LABEL );
173 m_junctionSize.SetValue( 0 );
174
175 Refresh();
176}
177
178
180{
181 SCH_COMMIT commit( m_frame );
182
183 for( SCH_ITEM* item : m_items )
184 {
185 commit.Modify( item, m_frame->GetScreen() );
186
187 if( item->HasLineStroke() )
188 {
189 if( !m_wireWidth.IsIndeterminate() )
190 {
191 int width = std::max( 0, m_wireWidth.GetIntValue() );
192
193 if( item->Type() == SCH_LINE_T )
194 static_cast<SCH_LINE*>( item )->SetLineWidth( width );
195 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
196 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetPenWidth( width );
197 }
198
199 if( m_typeCombo->GetStringSelection() != INDETERMINATE_STYLE )
200 {
202
203 size_t lineTypeSelection = m_typeCombo->GetSelection();
204 auto it = lineTypeNames.begin();
205 std::advance( it, lineTypeSelection );
206
207 if( it != lineTypeNames.end() )
208 lineStyle = it->first;
209
210 if( item->Type() == SCH_LINE_T )
211 static_cast<SCH_LINE*>( item )->SetLineStyle( lineStyle );
212 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
213 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetLineStyle( lineStyle );
214 }
215
216 COLOR4D color = m_colorSwatch->GetSwatchColor();
217
218 if( item->Type() == SCH_LINE_T )
219 static_cast<SCH_LINE*>( item )->SetLineColor( color );
220 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) )
221 static_cast<SCH_BUS_ENTRY_BASE*>( item )->SetBusEntryColor( color );
222 }
223 else
224 {
225 SCH_JUNCTION* junction = static_cast<SCH_JUNCTION*>( item );
226
227 junction->SetColor( m_colorSwatch->GetSwatchColor() );
228
229 if( !m_junctionSize.IsIndeterminate() )
230 junction->SetDiameter( m_junctionSize.GetValue() );
231 }
232 }
233
234 commit.Push( wxString::Format( _( "Edit %s" ), m_items.size() == 1 ? _( "Wire/Bus" )
235 : _( "Wires/Buses" ) ) );
236 return true;
237}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:402
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:106
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:82
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:105
wxColour ToColour() const
Definition color4d.cpp:225
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:168
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:42
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:488
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
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.
#define INDETERMINATE_STYLE
#define DEFAULT_WIRE_STYLE_LABEL
@ SCH_LINE_T
Definition typeinfo.h:167
@ SCH_JUNCTION_T
Definition typeinfo.h:163
#define INDETERMINATE_ACTION
Definition ui_common.h:47