KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eeschema/dialogs/dialog_shape_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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <stroke_params.h>
22#include <sch_edit_frame.h>
23#include <symbol_edit_frame.h>
24#include <sch_shape.h>
25#include <sch_rule_area.h>
28#include <widgets/wx_infobar.h>
30#include <sch_commit.h>
31#include <string_utils.h>
32
33
36 m_frame( aParent ),
37 m_shape( aShape ),
39{
40 SetTitle( wxString::Format( GetTitle(), aShape->GetFriendlyName() ) );
41
42 // DIALOG_SHIM needs a unique hash_key because classname is not sufficient because the
43 // different shapes (and even whether or not we're within the symbol editor) cause different
44 // dialog layouts.
45 m_hash_key = TO_UTF8( GetTitle() + aParent->GetName() );
46
47 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
48 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
49
50 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
51 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
52
53 m_borderColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
54 m_borderColorSwatch->SetSwatchBackground( schematicBackground );
55
56 for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
57 m_borderStyleCombo->Append( lineStyleDesc.name, KiBitmapBundle( lineStyleDesc.bitmap ) );
58
59 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
60 m_fillColorSwatch->SetSwatchBackground( schematicBackground );
61
62 KIGFX::COLOR4D canvas = m_frame->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND );
63 m_borderColorSwatch->SetSwatchBackground( canvas.ToColour() );
64 m_fillColorSwatch->SetSwatchBackground( canvas.ToColour() );
65
66 if( m_frame->GetColorSettings()->GetOverrideSchItemColors() )
67 m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
68
69 m_ruleAreaSizer->Show( dynamic_cast<SCH_RULE_AREA*>( aShape ) != nullptr );
70
72
73 // Required under wxGTK if we want to dismiss the dialog with the ESC key
74 SetFocus();
75
77
78 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
79 {
80 m_fillBook->SetSelection( 1 );
81
82 if( !symbolEditor->IsSymbolEditable() || symbolEditor->IsSymbolAlias() )
83 {
84 m_sdbSizerCancel->SetDefault();
85 m_sdbSizerOK->SetLabel( _( "Read Only" ) );
86 m_sdbSizerOK->Enable( false );
87 }
88 }
89 else
90 {
91 m_fillBook->SetSelection( 0 );
92 m_symbolEditorSizer->Show( false );
93 }
94
95 m_borderColorSwatch->Bind( COLOR_SWATCH_CHANGED, &DIALOG_SHAPE_PROPERTIES::onBorderSwatch, this );
96 m_customColorSwatch->Bind( COLOR_SWATCH_CHANGED, &DIALOG_SHAPE_PROPERTIES::onCustomColorSwatch, this );
97
98 // Now all widgets have the size fixed, call FinishDialogSettings
100}
101
102
108
109
111{
112 if( !wxDialog::TransferDataToWindow() )
113 return false;
114
115 if( SCH_RULE_AREA* ruleArea = dynamic_cast<SCH_RULE_AREA*>( m_shape ) )
116 {
117 m_cbExcludeFromSim->SetValue( ruleArea->GetExcludedFromSim() );
118 m_cbExcludeFromBom->SetValue( ruleArea->GetExcludedFromBOM() );
119 m_cbExcludeFromBoard->SetValue( ruleArea->GetExcludedFromBoard() );
120 m_cbDNP->SetValue( ruleArea->GetDNP() );
121 }
122
123 if( m_shape->GetWidth() >= 0 )
124 {
125 m_borderCheckbox->SetValue( true );
126 m_borderWidth.SetValue( m_shape->GetWidth() );
127 }
128 else
129 {
130 m_borderCheckbox->SetValue( false );
131
132 m_borderWidth.Enable( false );
133 m_borderColorLabel->Enable( false );
134 m_borderColorSwatch->Enable( false );
135 m_borderStyleLabel->Enable( false );
136 m_borderStyleCombo->Enable( false );
137 }
138
139 m_borderColorSwatch->SetSwatchColor( m_shape->GetStroke().GetColor(), false );
140
141 int style = static_cast<int>( m_shape->GetStroke().GetLineStyle() );
142
143 if( style == -1 )
144 m_borderStyleCombo->SetStringSelection( DEFAULT_LINE_STYLE_LABEL );
145 else if( style < (int) lineTypeNames.size() )
146 m_borderStyleCombo->SetSelection( style );
147 else
148 wxFAIL_MSG( wxT( "Line type not found in the type lookup map" ) );
149
150 if( dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
151 {
152 m_rbFillNone->Enable( true );
153 m_rbFillOutline->Enable( true );
154 m_rbFillBackground->Enable( true );
155 m_rbFillCustom->Enable( true );
156 m_customColorSwatch->Enable( true );
157
158 if( m_shape->GetFillMode() == FILL_T::FILLED_SHAPE )
159 {
160 m_rbFillOutline->SetValue( true );
161
162 COLOR4D color = m_shape->GetStroke().GetColor();
163
164 if( color == COLOR4D::UNSPECIFIED )
165 color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE );
166
167 m_customColorSwatch->SetSwatchColor( color, false );
168 }
169 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
170 {
171 m_rbFillBackground->SetValue( true );
172
173 COLOR4D color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE_BACKGROUND );
174 m_customColorSwatch->SetSwatchColor( color, false );
175 }
176 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR )
177 {
178 m_rbFillCustom->SetValue( true );
179 m_customColorSwatch->SetSwatchColor( m_shape->GetFillColor(), false );
180 }
181 else
182 {
183 m_rbFillNone->SetValue( true );
184 m_customColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
185 }
186
187 const SYMBOL* symbol = m_shape->GetParentSymbol();
188
189 m_privateCheckbox->SetValue( m_shape->IsPrivate() );
190 m_checkApplyToAllUnits->SetValue( symbol->IsMultiUnit() && m_shape->GetUnit() == 0 );
191 m_checkApplyToAllUnits->Enable( symbol->IsMultiUnit() );
192 m_checkApplyToAllBodyStyles->SetValue( symbol->IsMultiBodyStyle() && m_shape->GetBodyStyle() == 0 );
194 }
195 else
196 {
197 m_fillCtrl->SetSelection( m_shape->GetFillModeProp() );
198 m_fillColorSwatch->SetSwatchColor( m_shape->GetFillColor(), false );
199 }
200
201 m_fillColorLabel->Enable( m_fillCtrl->GetSelection() != UI_FILL_MODE::NONE );
202 m_fillColorSwatch->Enable( m_fillCtrl->GetSelection() != UI_FILL_MODE::NONE );
203
204 return true;
205}
206
207
208void DIALOG_SHAPE_PROPERTIES::onBorderChecked( wxCommandEvent& event )
209{
210 bool border = m_borderCheckbox->GetValue();
211
212 if( border && m_borderWidth.GetValue() < 0 )
213 {
214 int defaultInMils;
215
216 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
217 defaultInMils = symbolEditor->libeditconfig()->m_Defaults.line_width;
218 else
219 defaultInMils = m_frame->eeconfig()->m_Drawing.default_line_thickness;
220
221 m_borderWidth.SetValue( schIUScale.MilsToIU( defaultInMils ) );
222 }
223
224 m_borderWidth.Enable( border );
225 m_borderColorLabel->Enable( border );
226 m_borderColorSwatch->Enable( border );
227 m_borderStyleLabel->Enable( border );
228 m_borderStyleCombo->Enable( border );
229}
230
231
232void DIALOG_SHAPE_PROPERTIES::onFillChoice( wxCommandEvent& event )
233{
234 m_fillColorLabel->Enable( m_fillCtrl->GetSelection() != UI_FILL_MODE::NONE );
235 m_fillColorSwatch->Enable( m_fillCtrl->GetSelection() != UI_FILL_MODE::NONE );
236}
237
238
240{
241 if( event.GetId() == NO_FILL )
242 {
243 m_rbFillNone->SetValue( true );
244 m_customColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
245 }
246 else if( event.GetId() == FILLED_SHAPE )
247 {
248 m_rbFillOutline->SetValue( true );
249
250 COLOR4D color = m_borderColorSwatch->GetSwatchColor();
251
252 if( color == COLOR4D::UNSPECIFIED || !m_rbFillOutline->GetValue() )
253 color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE );
254
255 m_customColorSwatch->SetSwatchColor( color, false );
256 }
257 else if( event.GetId() == FILLED_WITH_BG_BODYCOLOR )
258 {
259 m_rbFillBackground->SetValue( true );
260
261 COLOR4D color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE_BACKGROUND );
262 m_customColorSwatch->SetSwatchColor( color, false );
263 }
264 else if( event.GetId() == FILLED_WITH_COLOR )
265 {
266 m_rbFillCustom->SetValue( true );
267 m_customColorSwatch->GetNewSwatchColor();
268 }
269}
270
271
272void DIALOG_SHAPE_PROPERTIES::onBorderSwatch( wxCommandEvent& aEvent )
273{
274 if( m_rbFillOutline->GetValue() )
275 m_fillColorSwatch->SetSwatchColor( m_borderColorSwatch->GetSwatchColor(), false );
276
277 if( m_rbFillOutline->IsEnabled() && m_rbFillOutline->GetValue() )
278 {
280
281 if( m_rbFillOutline->GetValue() )
282 color = m_fillColorSwatch->GetSwatchColor();
283
284 if( color == COLOR4D::UNSPECIFIED )
285 color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE );
286
287 m_customColorSwatch->SetSwatchColor( color, false );
288 }
289}
290
291
293{
294 m_rbFillCustom->SetValue( true );
295}
296
297
299{
300 if( !wxDialog::TransferDataFromWindow() )
301 return false;
302
303 SCH_COMMIT commit( m_frame );
304
305 if( !m_shape->IsNew() )
306 commit.Modify( m_shape, m_frame->GetScreen() );
307
308 if( SCH_RULE_AREA* ruleArea = dynamic_cast<SCH_RULE_AREA*>( m_shape ) )
309 {
310 ruleArea->SetExcludedFromSim( m_cbExcludeFromSim->GetValue() );
311 ruleArea->SetExcludedFromBOM( m_cbExcludeFromBom->GetValue() );
312 ruleArea->SetExcludedFromBoard( m_cbExcludeFromBoard->GetValue() );
313 ruleArea->SetDNP( m_cbDNP->GetValue() );
314 }
315
316 STROKE_PARAMS stroke = m_shape->GetStroke();
317
318 if( m_borderCheckbox->GetValue() )
319 {
320 if( !m_borderWidth.IsIndeterminate() )
321 stroke.SetWidth( std::max( 0, m_borderWidth.GetIntValue() ) );
322 }
323 else
324 {
325 stroke.SetWidth( -1 );
326 }
327
328 auto it = lineTypeNames.begin();
329 std::advance( it, m_borderStyleCombo->GetSelection() );
330
331 if( it == lineTypeNames.end() )
333 else
334 stroke.SetLineStyle( it->first );
335
336 stroke.SetColor( m_borderColorSwatch->GetSwatchColor() );
337
338 m_shape->SetStroke( stroke );
339
340 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
341 {
342 if( m_rbFillOutline->GetValue() )
343 m_shape->SetFillMode( FILL_T::FILLED_SHAPE );
344 else if( m_rbFillBackground->GetValue() )
346 else if( m_rbFillCustom->GetValue() )
347 m_shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
348 else
349 m_shape->SetFillMode( FILL_T::NO_FILL );
350
351 m_shape->SetFillColor( m_customColorSwatch->GetSwatchColor() );
352
353 m_shape->SetPrivate( m_privateCheckbox->GetValue() );
354
355 if( m_checkApplyToAllBodyStyles->IsChecked() )
356 m_shape->SetBodyStyle( 0 );
357 else
358 m_shape->SetBodyStyle( symbolEditor->GetBodyStyle() );
359
360 if( m_checkApplyToAllUnits->IsChecked() )
361 m_shape->SetUnit( 0 );
362 else
363 m_shape->SetUnit( symbolEditor->GetUnit() );
364 }
365 else
366 {
367 m_shape->SetFillModeProp( (UI_FILL_MODE) m_fillCtrl->GetSelection() );
368 m_shape->SetFillColor( m_fillColorSwatch->GetSwatchColor() );
369 }
370
371 if( !commit.Empty() )
372 commit.Push( wxString::Format( _( "Edit %s" ), m_shape->GetFriendlyName() ) );
373
374 return true;
375}
376
377
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
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
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
bool Empty() const
Definition commit.h:134
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
DIALOG_SHAPE_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("%s Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
DIALOG_SHAPE_PROPERTIES(SCH_BASE_FRAME *aParent, SCH_SHAPE *aShape)
void onBorderChecked(wxCommandEvent &aEvent) override
void onFillChoice(wxCommandEvent &event) override
void onFillRadioButton(wxCommandEvent &aEvent) override
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={})
std::string m_hash_key
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual wxString GetFriendlyName() const
Definition eda_item.cpp:426
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
wxColour ToColour() const
Definition color4d.cpp:221
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Simple container to manage line stroke parameters.
void SetLineStyle(LINE_STYLE aLineStyle)
void SetWidth(int aWidth)
void SetColor(const KIGFX::COLOR4D &aColor)
The symbol library editor main window.
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition symbol.h:59
virtual bool IsMultiUnit() const =0
virtual bool IsMultiBodyStyle() const =0
#define _(s)
UI_FILL_MODE
Definition eda_shape.h:71
@ NONE
Definition eda_shape.h:72
@ FILLED_WITH_COLOR
Definition eda_shape.h:63
@ NO_FILL
Definition eda_shape.h:60
@ FILLED_WITH_BG_BODYCOLOR
Definition eda_shape.h:62
@ FILLED_SHAPE
Fill with object color.
Definition eda_shape.h:61
@ LAYER_DEVICE
Definition layer_ids.h:464
@ LAYER_DEVICE_BACKGROUND
Definition layer_ids.h:482
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:486
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
const std::map< LINE_STYLE, struct LINE_STYLE_DESC > lineTypeNames
Conversion map between LINE_STYLE values and style names displayed.
#define DEFAULT_LINE_STYLE_LABEL