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>
29#include <sch_rule_area.h>
32#include <widgets/wx_infobar.h>
34#include <sch_commit.h>
35#include <string_utils.h>
36
37
40 m_frame( aParent ),
41 m_shape( aShape ),
43{
44 SetTitle( wxString::Format( GetTitle(), aShape->GetFriendlyName() ) );
45
46 // DIALOG_SHIM needs a unique hash_key because classname is not sufficient because the
47 // different shapes (and even whether or not we're within the symbol editor) cause different
48 // dialog layouts.
49 m_hash_key = TO_UTF8( GetTitle() + aParent->GetName() );
50
51 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
52 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
53
54 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
55 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
56
57 m_borderColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
58 m_borderColorSwatch->SetSwatchBackground( schematicBackground );
59
60 for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
61 m_borderStyleCombo->Append( lineStyleDesc.name, KiBitmapBundle( lineStyleDesc.bitmap ) );
62
63 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
64 m_fillColorSwatch->SetSwatchBackground( schematicBackground );
65
66 KIGFX::COLOR4D canvas = m_frame->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND );
67 m_borderColorSwatch->SetSwatchBackground( canvas.ToColour() );
68 m_fillColorSwatch->SetSwatchBackground( canvas.ToColour() );
69
70 if( m_frame->GetColorSettings()->GetOverrideSchItemColors() )
71 m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
72
73 m_ruleAreaSizer->Show( dynamic_cast<SCH_RULE_AREA*>( aShape ) != nullptr );
74
76
77 // Required under wxGTK if we want to dismiss the dialog with the ESC key
78 SetFocus();
79
81
82 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
83 {
84 m_fillBook->SetSelection( 1 );
85
86 if( !symbolEditor->IsSymbolEditable() || symbolEditor->IsSymbolAlias() )
87 {
88 m_sdbSizerCancel->SetDefault();
89 m_sdbSizerOK->SetLabel( _( "Read Only" ) );
90 m_sdbSizerOK->Enable( false );
91 }
92 }
93 else
94 {
95 m_fillBook->SetSelection( 0 );
96 m_symbolEditorSizer->Show( false );
97 }
98
99 m_borderColorSwatch->Bind( COLOR_SWATCH_CHANGED, &DIALOG_SHAPE_PROPERTIES::onBorderSwatch, this );
100 m_customColorSwatch->Bind( COLOR_SWATCH_CHANGED, &DIALOG_SHAPE_PROPERTIES::onCustomColorSwatch, this );
101
102 // Now all widgets have the size fixed, call FinishDialogSettings
104}
105
106
112
113
115{
116 if( !wxDialog::TransferDataToWindow() )
117 return false;
118
119 if( SCH_RULE_AREA* ruleArea = dynamic_cast<SCH_RULE_AREA*>( m_shape ) )
120 {
121 m_cbExcludeFromSim->SetValue( ruleArea->GetExcludedFromSim() );
122 m_cbExcludeFromBom->SetValue( ruleArea->GetExcludedFromBOM() );
123 m_cbExcludeFromBoard->SetValue( ruleArea->GetExcludedFromBoard() );
124 m_cbDNP->SetValue( ruleArea->GetDNP() );
125 }
126
127 if( m_shape->GetWidth() >= 0 )
128 {
129 m_borderCheckbox->SetValue( true );
130 m_borderWidth.SetValue( m_shape->GetWidth() );
131 }
132 else
133 {
134 m_borderCheckbox->SetValue( false );
135
136 m_borderWidth.Enable( false );
137 m_borderColorLabel->Enable( false );
138 m_borderColorSwatch->Enable( false );
139 m_borderStyleLabel->Enable( false );
140 m_borderStyleCombo->Enable( false );
141 }
142
143 m_borderColorSwatch->SetSwatchColor( m_shape->GetStroke().GetColor(), false );
144
145 int style = static_cast<int>( m_shape->GetStroke().GetLineStyle() );
146
147 if( style == -1 )
148 m_borderStyleCombo->SetStringSelection( DEFAULT_LINE_STYLE_LABEL );
149 else if( style < (int) lineTypeNames.size() )
150 m_borderStyleCombo->SetSelection( style );
151 else
152 wxFAIL_MSG( wxT( "Line type not found in the type lookup map" ) );
153
154 if( dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
155 {
156 m_rbFillNone->Enable( true );
157 m_rbFillOutline->Enable( true );
158 m_rbFillBackground->Enable( true );
159 m_rbFillCustom->Enable( true );
160 m_customColorSwatch->Enable( true );
161
162 if( m_shape->GetFillMode() == FILL_T::FILLED_SHAPE )
163 {
164 m_rbFillOutline->SetValue( true );
165
166 COLOR4D color = m_shape->GetStroke().GetColor();
167
168 if( color == COLOR4D::UNSPECIFIED )
169 color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE );
170
171 m_customColorSwatch->SetSwatchColor( color, false );
172 }
173 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
174 {
175 m_rbFillBackground->SetValue( true );
176
177 COLOR4D color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE_BACKGROUND );
178 m_customColorSwatch->SetSwatchColor( color, false );
179 }
180 else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR )
181 {
182 m_rbFillCustom->SetValue( true );
183 m_customColorSwatch->SetSwatchColor( m_shape->GetFillColor(), false );
184 }
185 else
186 {
187 m_rbFillNone->SetValue( true );
188 m_customColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
189 }
190
191 const SYMBOL* symbol = m_shape->GetParentSymbol();
192
193 m_privateCheckbox->SetValue( m_shape->IsPrivate() );
194 m_checkApplyToAllUnits->SetValue( symbol->IsMultiUnit() && m_shape->GetUnit() == 0 );
195 m_checkApplyToAllUnits->Enable( symbol->IsMultiUnit() );
196 m_checkApplyToAllBodyStyles->SetValue( symbol->IsMultiBodyStyle() && m_shape->GetBodyStyle() == 0 );
198 }
199 else
200 {
201 m_fillCtrl->SetSelection( m_shape->GetFillModeProp() );
202 m_fillColorSwatch->SetSwatchColor( m_shape->GetFillColor(), false );
203 }
204
205 m_fillColorLabel->Enable( m_fillCtrl->GetSelection() != UI_FILL_MODE::NONE );
206 m_fillColorSwatch->Enable( m_fillCtrl->GetSelection() != UI_FILL_MODE::NONE );
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
223 defaultInMils = m_frame->eeconfig()->m_Drawing.default_line_thickness;
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::onFillChoice( wxCommandEvent& event )
237{
238 m_fillColorLabel->Enable( m_fillCtrl->GetSelection() != UI_FILL_MODE::NONE );
239 m_fillColorSwatch->Enable( m_fillCtrl->GetSelection() != UI_FILL_MODE::NONE );
240}
241
242
244{
245 if( event.GetId() == NO_FILL )
246 {
247 m_rbFillNone->SetValue( true );
248 m_customColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
249 }
250 else if( event.GetId() == FILLED_SHAPE )
251 {
252 m_rbFillOutline->SetValue( true );
253
254 COLOR4D color = m_borderColorSwatch->GetSwatchColor();
255
256 if( color == COLOR4D::UNSPECIFIED || !m_rbFillOutline->GetValue() )
257 color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE );
258
259 m_customColorSwatch->SetSwatchColor( color, false );
260 }
261 else if( event.GetId() == FILLED_WITH_BG_BODYCOLOR )
262 {
263 m_rbFillBackground->SetValue( true );
264
265 COLOR4D color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE_BACKGROUND );
266 m_customColorSwatch->SetSwatchColor( color, false );
267 }
268 else if( event.GetId() == FILLED_WITH_COLOR )
269 {
270 m_rbFillCustom->SetValue( true );
271 m_customColorSwatch->GetNewSwatchColor();
272 }
273}
274
275
276void DIALOG_SHAPE_PROPERTIES::onBorderSwatch( wxCommandEvent& aEvent )
277{
278 if( m_rbFillOutline->GetValue() )
279 m_fillColorSwatch->SetSwatchColor( m_borderColorSwatch->GetSwatchColor(), false );
280
281 if( m_rbFillOutline->IsEnabled() && m_rbFillOutline->GetValue() )
282 {
284
285 if( m_rbFillOutline->GetValue() )
286 color = m_fillColorSwatch->GetSwatchColor();
287
288 if( color == COLOR4D::UNSPECIFIED )
289 color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE );
290
291 m_customColorSwatch->SetSwatchColor( color, false );
292 }
293}
294
295
297{
298 m_rbFillCustom->SetValue( true );
299}
300
301
303{
304 if( !wxDialog::TransferDataFromWindow() )
305 return false;
306
307 SCH_COMMIT commit( m_frame );
308
309 if( !m_shape->IsNew() )
310 commit.Modify( m_shape, m_frame->GetScreen() );
311
312 if( SCH_RULE_AREA* ruleArea = dynamic_cast<SCH_RULE_AREA*>( m_shape ) )
313 {
314 ruleArea->SetExcludedFromSim( m_cbExcludeFromSim->GetValue() );
315 ruleArea->SetExcludedFromBOM( m_cbExcludeFromBom->GetValue() );
316 ruleArea->SetExcludedFromBoard( m_cbExcludeFromBoard->GetValue() );
317 ruleArea->SetDNP( m_cbDNP->GetValue() );
318 }
319
320 STROKE_PARAMS stroke = m_shape->GetStroke();
321
322 if( m_borderCheckbox->GetValue() )
323 {
324 if( !m_borderWidth.IsIndeterminate() )
325 stroke.SetWidth( std::max( 0, m_borderWidth.GetIntValue() ) );
326 }
327 else
328 {
329 stroke.SetWidth( -1 );
330 }
331
332 auto it = lineTypeNames.begin();
333 std::advance( it, m_borderStyleCombo->GetSelection() );
334
335 if( it == lineTypeNames.end() )
337 else
338 stroke.SetLineStyle( it->first );
339
340 stroke.SetColor( m_borderColorSwatch->GetSwatchColor() );
341
342 m_shape->SetStroke( stroke );
343
344 if( SYMBOL_EDIT_FRAME* symbolEditor = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame ) )
345 {
346 if( m_rbFillOutline->GetValue() )
347 m_shape->SetFillMode( FILL_T::FILLED_SHAPE );
348 else if( m_rbFillBackground->GetValue() )
350 else if( m_rbFillCustom->GetValue() )
351 m_shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
352 else
353 m_shape->SetFillMode( FILL_T::NO_FILL );
354
355 m_shape->SetFillColor( m_customColorSwatch->GetSwatchColor() );
356
357 m_shape->SetPrivate( m_privateCheckbox->GetValue() );
358
359 if( m_checkApplyToAllBodyStyles->IsChecked() )
360 m_shape->SetBodyStyle( 0 );
361 else
362 m_shape->SetBodyStyle( symbolEditor->GetBodyStyle() );
363
364 if( m_checkApplyToAllUnits->IsChecked() )
365 m_shape->SetUnit( 0 );
366 else
367 m_shape->SetUnit( symbolEditor->GetUnit() );
368 }
369 else
370 {
371 m_shape->SetFillModeProp( (UI_FILL_MODE) m_fillCtrl->GetSelection() );
372 m_shape->SetFillColor( m_fillColorSwatch->GetSwatchColor() );
373 }
374
375 if( !commit.Empty() )
376 commit.Push( wxString::Format( _( "Edit %s" ), m_shape->GetFriendlyName() ) );
377
378 return true;
379}
380
381
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
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
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:137
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
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:82
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:411
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
wxColour ToColour() const
Definition color4d.cpp:225
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:63
virtual bool IsMultiUnit() const =0
virtual bool IsMultiBodyStyle() const =0
#define _(s)
UI_FILL_MODE
Definition eda_shape.h:68
@ NONE
Definition eda_shape.h:69
@ FILLED_WITH_COLOR
Definition eda_shape.h:60
@ NO_FILL
Definition eda_shape.h:57
@ FILLED_WITH_BG_BODYCOLOR
Definition eda_shape.h:59
@ FILLED_SHAPE
Fill with object color.
Definition eda_shape.h:58
@ LAYER_DEVICE
Definition layer_ids.h:466
@ LAYER_DEVICE_BACKGROUND
Definition layer_ids.h:484
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:488
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