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 (C) 2021-2024 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25#include <stroke_params.h>
26#include <sch_edit_frame.h>
27#include <symbol_edit_frame.h>
28#include <sch_shape.h>
32#include <sch_commit.h>
33#include <string_utils.h>
34
35
38 m_frame( aParent ),
39 m_shape( aShape ),
40 m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits, true )
41{
42 SetTitle( wxString::Format( GetTitle(), aShape->GetFriendlyName() ) );
43
44 // DIALOG_SHIM needs a unique hash_key because classname is not sufficient because the
45 // different shapes (and even whether or not we're within the symbol editor) cause different
46 // dialog layouts).
47 m_hash_key = TO_UTF8( GetTitle() + aParent->GetName() );
48
49 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
50 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
51
52 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
53 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
54
55 m_borderColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
56 m_borderColorSwatch->SetSwatchBackground( schematicBackground );
57
58 for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
59 m_borderStyleCombo->Append( lineStyleDesc.name, KiBitmapBundle( lineStyleDesc.bitmap ) );
60
62
63 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
64 m_fillColorSwatch->SetSwatchBackground( schematicBackground );
65
69
71 m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
72
74
75 // Required under wxGTK if we want to dismiss the dialog with the ESC key
76 SetFocus();
77
79
80 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
81 {
82 m_fillBook->SetSelection( 1 );
83
84 if( !symbolEditor->IsSymbolEditable() || symbolEditor->IsSymbolAlias() )
85 {
86 m_sdbSizerCancel->SetDefault();
87 m_sdbSizerOK->SetLabel( _( "Read Only" ) );
88 m_sdbSizerOK->Enable( false );
89 }
90 }
91 else
92 {
93 m_fillBook->SetSelection( 0 );
94 m_symbolEditorSizer->Show( false );
95 }
96
98 this );
100 this );
101
102 // Now all widgets have the size fixed, call FinishDialogSettings
104}
105
106
108{
109 m_borderColorSwatch->Unbind( COLOR_SWATCH_CHANGED, &DIALOG_SHAPE_PROPERTIES::onBorderSwatch,
110 this );
112 this );
113}
114
115
117{
118 if( !wxDialog::TransferDataToWindow() )
119 return false;
120
121 if( m_shape->GetWidth() >= 0 )
122 {
123 m_borderCheckbox->SetValue( true );
125 }
126 else
127 {
128 m_borderCheckbox->SetValue( false );
129
130 m_borderWidth.Enable( false );
131 m_borderColorLabel->Enable( false );
132 m_borderColorSwatch->Enable( false );
133 m_borderStyleLabel->Enable( false );
134 m_borderStyleCombo->Enable( false );
135 }
136
138
139 int style = static_cast<int>( m_shape->GetStroke().GetLineStyle() );
140
141 if( style == -1 )
142 m_borderStyleCombo->SetStringSelection( DEFAULT_STYLE );
143 else if( style < (int) lineTypeNames.size() )
144 m_borderStyleCombo->SetSelection( style );
145 else
146 wxFAIL_MSG( wxT( "Line type not found in the type lookup map" ) );
147
148 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
149 {
150 m_rbFillNone->Enable( true );
151 m_rbFillOutline->Enable( true );
152 m_rbFillBackground->Enable( true );
153 m_rbFillCustom->Enable( true );
154 m_customColorSwatch->Enable( true );
155
156 if( m_shape->GetFillMode() == FILL_T::FILLED_SHAPE )
157 {
158 m_rbFillOutline->SetValue( true );
159
161
162 if( color == COLOR4D::UNSPECIFIED )
164
166 }
167 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
168 {
169 m_rbFillBackground->SetValue( true );
170
173 }
174 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR )
175 {
176 m_rbFillCustom->SetValue( true );
178 }
179 else
180 {
181 m_rbFillNone->SetValue( true );
182 m_customColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
183 }
184
185 const SYMBOL* symbol = m_shape->GetParentSymbol();
186
187 m_privateCheckbox->SetValue( m_shape->IsPrivate() );
188 m_checkApplyToAllUnits->SetValue( symbol->GetUnitCount() > 1 && m_shape->GetUnit() == 0 );
189 m_checkApplyToAllUnits->Enable( symbol->GetUnitCount() > 1 );
191
192 bool enableAlternateBodyStyle = symbol->HasAlternateBodyStyle();
193
194 // If a symbol contains no body-style-specific pins or graphic items,
195 // symbol->HasAlternateBodyStyle() will return false.
196 // But when creating a new symbol, with DeMorgan option set, the m_checkApplyToAllBodyStyles
197 // must be enabled in order to be able to create graphic items shared by all body styles.
198 if( symbolEditor->GetShowDeMorgan() )
199 enableAlternateBodyStyle = true;
200
201 m_checkApplyToAllBodyStyles->Enable( enableAlternateBodyStyle );
202 }
203 else
204 {
205 m_filledCtrl->SetValue( m_shape->IsFilled() );
207 }
208
209 return true;
210}
211
212
213void DIALOG_SHAPE_PROPERTIES::onBorderChecked( wxCommandEvent& event )
214{
215 bool border = m_borderCheckbox->GetValue();
216
217 if( border && m_borderWidth.GetValue() < 0 )
218 {
219 int defaultInMils;
220
221 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
222 defaultInMils = symbolEditor->libeditconfig()->m_Defaults.line_width;
223 else
225
226 m_borderWidth.SetValue( schIUScale.MilsToIU( defaultInMils ) );
227 }
228
229 m_borderWidth.Enable( border );
230 m_borderColorLabel->Enable( border );
231 m_borderColorSwatch->Enable( border );
232 m_borderStyleLabel->Enable( border );
233 m_borderStyleCombo->Enable( border );
234}
235
236
237void DIALOG_SHAPE_PROPERTIES::onFillChecked( wxCommandEvent& aEvent )
238{
239 bool fill = m_filledCtrl->GetValue();
240
241 m_fillColorLabel->Enable( fill );
242 m_fillColorSwatch->Enable( fill );
243}
244
245
247{
248 if( event.GetId() == NO_FILL )
249 {
250 m_rbFillNone->SetValue( true );
251 m_customColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
252 }
253 else if( event.GetId() == FILLED_SHAPE )
254 {
255 m_rbFillOutline->SetValue( true );
256
258
259 if( color == COLOR4D::UNSPECIFIED || !m_rbFillOutline->GetValue() )
261
263 }
264 else if( event.GetId() == FILLED_WITH_BG_BODYCOLOR )
265 {
266 m_rbFillBackground->SetValue( true );
267
270 }
271 else if( event.GetId() == FILLED_WITH_COLOR )
272 {
273 m_rbFillCustom->SetValue( true );
275 }
276}
277
278
279void DIALOG_SHAPE_PROPERTIES::onBorderSwatch( wxCommandEvent& aEvent )
280{
281 if( m_rbFillOutline->GetValue() )
283
284 if( m_rbFillOutline->IsEnabled() && m_rbFillOutline->GetValue() )
285 {
286 COLOR4D color = COLOR4D::UNSPECIFIED;
287
288 if( m_rbFillOutline->GetValue() )
290
291 if( color == COLOR4D::UNSPECIFIED )
293
295 }
296}
297
298
300{
301 m_rbFillCustom->SetValue( true );
302}
303
304
306{
307 if( !wxDialog::TransferDataFromWindow() )
308 return false;
309
310 SCH_COMMIT commit( m_frame );
311
312 if( !m_shape->IsNew() )
313 commit.Modify( m_shape, m_frame->GetScreen() );
314
315 STROKE_PARAMS stroke = m_shape->GetStroke();
316
317 if( m_borderCheckbox->GetValue() )
318 {
320 stroke.SetWidth( std::max( 0, m_borderWidth.GetIntValue() ) );
321 }
322 else
323 {
324 stroke.SetWidth( -1 );
325 }
326
327 auto it = lineTypeNames.begin();
328 std::advance( it, m_borderStyleCombo->GetSelection() );
329
330 if( it == lineTypeNames.end() )
331 stroke.SetLineStyle( LINE_STYLE::DEFAULT );
332 else
333 stroke.SetLineStyle( it->first );
334
336
337 m_shape->SetStroke( stroke );
338
339 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
340 {
341 if( m_rbFillOutline->GetValue() )
342 m_shape->SetFillMode( FILL_T::FILLED_SHAPE );
343 else if( m_rbFillBackground->GetValue() )
344 m_shape->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
345 else if( m_rbFillCustom->GetValue() )
346 m_shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
347 else
348 m_shape->SetFillMode( FILL_T::NO_FILL );
349
351
352 m_shape->SetPrivate( m_privateCheckbox->GetValue() );
353
354 if( m_checkApplyToAllBodyStyles->IsChecked() )
355 m_shape->SetBodyStyle( 0 );
356 else
357 m_shape->SetBodyStyle( symbolEditor->GetBodyStyle() );
358
359 if( m_checkApplyToAllUnits->IsChecked() )
360 m_shape->SetUnit( 0 );
361 else
362 m_shape->SetUnit( symbolEditor->GetUnit() );
363 }
364 else
365 {
366 if( m_filledCtrl->GetValue() )
367 m_shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
368 else
369 m_shape->SetFillMode( FILL_T::NO_FILL );
370
372 }
373
374 if( !commit.Empty() )
375 commit.Push( wxString::Format( _( "Edit %s" ), m_shape->GetFriendlyName() ) );
376
377 return true;
378}
379
380
int color
Definition: DXF_plotter.cpp:58
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
Color settings are a bit different than most of the settings objects in that there can be more than o...
bool GetOverrideSchItemColors() const
COLOR4D GetColor(int aLayer) const
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
void GetNewSwatchColor()
Prompt for a new colour, using the colour picker dialog.
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)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
bool Empty() const
Returns status of an item.
Definition: commit.h:144
DIALOG_SHAPE_PROPERTIES(SCH_BASE_FRAME *aParent, SCH_SHAPE *aShape)
void onFillChecked(wxCommandEvent &aEvent) override
void onBorderChecked(wxCommandEvent &aEvent) 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:102
void SetupStandardButtons(std::map< int, wxString > aLabels={})
std::string m_hash_key
Definition: dialog_shim.h:222
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:332
bool IsNew() const
Definition: eda_item.h:107
FILL_T GetFillMode() const
Definition: eda_shape.h:114
bool IsFilled() const
Definition: eda_shape.h:98
void SetFillColor(const COLOR4D &aColor)
Definition: eda_shape.h:119
COLOR4D GetFillColor() const
Definition: eda_shape.h:118
virtual int GetWidth() const
Definition: eda_shape.h:122
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:113
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
wxColour ToColour() const
Definition: color4d.cpp:220
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
SCH_RENDER_SETTINGS * GetRenderSettings()
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
EESCHEMA_SETTINGS * eeconfig() const
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:432
virtual void SetBodyStyle(int aBodyStyle)
Definition: sch_item.h:231
const SYMBOL * GetParentSymbol() const
Definition: sch_item.cpp:166
void SetPrivate(bool aPrivate)
Definition: sch_item.h:234
int GetBodyStyle() const
Definition: sch_item.h:232
int GetUnit() const
Definition: sch_item.h:229
bool IsPrivate() const
Definition: sch_item.h:235
virtual void SetUnit(int aUnit)
Definition: sch_item.h:228
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_shape.cpp:63
STROKE_PARAMS GetStroke() const override
Definition: sch_shape.h:55
Simple container to manage line stroke parameters.
Definition: stroke_params.h:79
void SetLineStyle(LINE_STYLE aLineStyle)
Definition: stroke_params.h:93
void SetWidth(int aWidth)
Definition: stroke_params.h:90
void SetColor(const KIGFX::COLOR4D &aColor)
Definition: stroke_params.h:96
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:92
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:95
The symbol library editor main window.
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition: symbol.h:34
virtual int GetUnitCount() const =0
virtual bool HasAlternateBodyStyle() const =0
Test if symbol has more than one body conversion type (DeMorgan).
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.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:154
#define _(s)
@ LAYER_DEVICE
Definition: layer_ids.h:370
@ LAYER_DEVICE_BACKGROUND
Definition: layer_ids.h:387
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:391
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:154
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:398
const std::map< LINE_STYLE, struct LINE_STYLE_DESC > lineTypeNames
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93