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, 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
61 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
62 m_fillColorSwatch->SetSwatchBackground( schematicBackground );
63
67
69 m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
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
96 this );
98 this );
99
100 // Now all widgets have the size fixed, call FinishDialogSettings
102}
103
104
106{
107 m_borderColorSwatch->Unbind( COLOR_SWATCH_CHANGED, &DIALOG_SHAPE_PROPERTIES::onBorderSwatch,
108 this );
109 m_customColorSwatch->Unbind( COLOR_SWATCH_CHANGED,
111 this );
112}
113
114
116{
117 if( !wxDialog::TransferDataToWindow() )
118 return false;
119
120 if( m_shape->GetWidth() >= 0 )
121 {
122 m_borderCheckbox->SetValue( true );
124 }
125 else
126 {
127 m_borderCheckbox->SetValue( false );
128
129 m_borderWidth.Enable( false );
130 m_borderColorLabel->Enable( false );
131 m_borderColorSwatch->Enable( false );
132 m_borderStyleLabel->Enable( false );
133 m_borderStyleCombo->Enable( false );
134 }
135
137
138 int style = static_cast<int>( m_shape->GetStroke().GetLineStyle() );
139
140 if( style == -1 )
141 m_borderStyleCombo->SetStringSelection( DEFAULT_STYLE );
142 else if( style < (int) lineTypeNames.size() )
143 m_borderStyleCombo->SetSelection( style );
144 else
145 wxFAIL_MSG( wxT( "Line type not found in the type lookup map" ) );
146
147 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
148 {
149 m_rbFillNone->Enable( true );
150 m_rbFillOutline->Enable( true );
151 m_rbFillBackground->Enable( true );
152 m_rbFillCustom->Enable( true );
153 m_customColorSwatch->Enable( true );
154
155 if( m_shape->GetFillMode() == FILL_T::FILLED_SHAPE )
156 {
157 m_rbFillOutline->SetValue( true );
158
160
161 if( color == COLOR4D::UNSPECIFIED )
163
165 }
166 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
167 {
168 m_rbFillBackground->SetValue( true );
169
172 }
173 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR )
174 {
175 m_rbFillCustom->SetValue( true );
177 }
178 else
179 {
180 m_rbFillNone->SetValue( true );
181 m_customColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
182 }
183
184 const SYMBOL* symbol = m_shape->GetParentSymbol();
185
186 m_privateCheckbox->SetValue( m_shape->IsPrivate() );
187 m_checkApplyToAllUnits->SetValue( symbol->GetUnitCount() > 1 && m_shape->GetUnit() == 0 );
188 m_checkApplyToAllUnits->Enable( symbol->GetUnitCount() > 1 );
190
191 bool enableAlternateBodyStyle = symbol->HasAlternateBodyStyle();
192
193 // If a symbol contains no body-style-specific pins or graphic items,
194 // symbol->HasAlternateBodyStyle() will return false.
195 // But when creating a new symbol, with DeMorgan option set, the m_checkApplyToAllBodyStyles
196 // must be enabled in order to be able to create graphic items shared by all body styles.
197 if( symbolEditor->GetShowDeMorgan() )
198 enableAlternateBodyStyle = true;
199
200 m_checkApplyToAllBodyStyles->Enable( enableAlternateBodyStyle );
201 }
202 else
203 {
204 m_filledCtrl->SetValue( m_shape->IsFilled() );
206 }
207
208 return true;
209}
210
211
212void DIALOG_SHAPE_PROPERTIES::onBorderChecked( wxCommandEvent& event )
213{
214 bool border = m_borderCheckbox->GetValue();
215
216 if( border && m_borderWidth.GetValue() < 0 )
217 {
218 int defaultInMils;
219
220 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
221 defaultInMils = symbolEditor->libeditconfig()->m_Defaults.line_width;
222 else
224
225 m_borderWidth.SetValue( schIUScale.MilsToIU( defaultInMils ) );
226 }
227
228 m_borderWidth.Enable( border );
229 m_borderColorLabel->Enable( border );
230 m_borderColorSwatch->Enable( border );
231 m_borderStyleLabel->Enable( border );
232 m_borderStyleCombo->Enable( border );
233}
234
235
236void DIALOG_SHAPE_PROPERTIES::onFillChecked( wxCommandEvent& aEvent )
237{
238 bool fill = m_filledCtrl->GetValue();
239
240 m_fillColorLabel->Enable( fill );
241 m_fillColorSwatch->Enable( fill );
242}
243
244
246{
247 if( event.GetId() == NO_FILL )
248 {
249 m_rbFillNone->SetValue( true );
250 m_customColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
251 }
252 else if( event.GetId() == FILLED_SHAPE )
253 {
254 m_rbFillOutline->SetValue( true );
255
257
258 if( color == COLOR4D::UNSPECIFIED || !m_rbFillOutline->GetValue() )
260
262 }
263 else if( event.GetId() == FILLED_WITH_BG_BODYCOLOR )
264 {
265 m_rbFillBackground->SetValue( true );
266
269 }
270 else if( event.GetId() == FILLED_WITH_COLOR )
271 {
272 m_rbFillCustom->SetValue( true );
274 }
275}
276
277
278void DIALOG_SHAPE_PROPERTIES::onBorderSwatch( wxCommandEvent& aEvent )
279{
280 if( m_rbFillOutline->GetValue() )
282
283 if( m_rbFillOutline->IsEnabled() && m_rbFillOutline->GetValue() )
284 {
285 COLOR4D color = COLOR4D::UNSPECIFIED;
286
287 if( m_rbFillOutline->GetValue() )
289
290 if( color == COLOR4D::UNSPECIFIED )
292
294 }
295}
296
297
299{
300 m_rbFillCustom->SetValue( true );
301}
302
303
305{
306 if( !wxDialog::TransferDataFromWindow() )
307 return false;
308
309 SCH_COMMIT commit( m_frame );
310
311 if( !m_shape->IsNew() )
312 commit.Modify( m_shape, m_frame->GetScreen() );
313
314 STROKE_PARAMS stroke = m_shape->GetStroke();
315
316 if( m_borderCheckbox->GetValue() )
317 {
319 stroke.SetWidth( std::max( 0, m_borderWidth.GetIntValue() ) );
320 }
321 else
322 {
323 stroke.SetWidth( -1 );
324 }
325
326 auto it = lineTypeNames.begin();
327 std::advance( it, m_borderStyleCombo->GetSelection() );
328
329 if( it == lineTypeNames.end() )
330 stroke.SetLineStyle( LINE_STYLE::SOLID );
331 else
332 stroke.SetLineStyle( it->first );
333
335
336 m_shape->SetStroke( stroke );
337
338 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
339 {
340 if( m_rbFillOutline->GetValue() )
341 m_shape->SetFillMode( FILL_T::FILLED_SHAPE );
342 else if( m_rbFillBackground->GetValue() )
343 m_shape->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
344 else if( m_rbFillCustom->GetValue() )
345 m_shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
346 else
347 m_shape->SetFillMode( FILL_T::NO_FILL );
348
350
351 m_shape->SetPrivate( m_privateCheckbox->GetValue() );
352
353 if( m_checkApplyToAllBodyStyles->IsChecked() )
354 m_shape->SetBodyStyle( 0 );
355 else
356 m_shape->SetBodyStyle( symbolEditor->GetBodyStyle() );
357
358 if( m_checkApplyToAllUnits->IsChecked() )
359 m_shape->SetUnit( 0 );
360 else
361 m_shape->SetUnit( symbolEditor->GetUnit() );
362 }
363 else
364 {
365 if( m_filledCtrl->GetValue() )
366 m_shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
367 else
368 m_shape->SetFillMode( FILL_T::NO_FILL );
369
371 }
372
373 if( !commit.Empty() )
374 commit.Push( wxString::Format( _( "Edit %s" ), m_shape->GetFriendlyName() ) );
375
376 return true;
377}
378
379
int color
Definition: DXF_plotter.cpp:60
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)
Modify a given item in the model.
Definition: commit.h:108
bool Empty() const
Definition: commit.h:150
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:230
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
Execute the changes.
Definition: sch_commit.cpp:432
virtual void SetBodyStyle(int aBodyStyle)
Definition: sch_item.h:232
const SYMBOL * GetParentSymbol() const
Definition: sch_item.cpp:166
void SetPrivate(bool aPrivate)
Definition: sch_item.h:235
int GetBodyStyle() const
Definition: sch_item.h:233
int GetUnit() const
Definition: sch_item.h:230
bool IsPrivate() const
Definition: sch_item.h:236
virtual void SetUnit(int aUnit)
Definition: sch_item.h:229
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:93
void SetLineStyle(LINE_STYLE aLineStyle)
void SetWidth(int aWidth)
void SetColor(const KIGFX::COLOR4D &aColor)
LINE_STYLE GetLineStyle() const
KIGFX::COLOR4D GetColor() const
The symbol library editor main window.
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition: symbol.h:63
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:153
#define _(s)
@ LAYER_DEVICE
Definition: layer_ids.h:418
@ LAYER_DEVICE_BACKGROUND
Definition: layer_ids.h:436
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:440
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:155
#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
Conversion map between LINE_STYLE values and style names displayed.
#define DEFAULT_STYLE
Definition: stroke_params.h:85
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93