KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_label_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) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2013 Wayne Stambaugh <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
27#include <widgets/font_choice.h>
32#include <sch_edit_frame.h>
33#include <tool/tool_manager.h>
34#include <gr_text.h>
35#include <confirm.h>
36#include <schematic.h>
39#include <string_utils.h>
40#include <kiface_base.h>
41#include <sch_label.h>
42#include <sch_commit.h>
43
44
47 m_Parent( aParent ),
48 m_currentLabel( aLabel ),
49 m_activeTextEntry( nullptr ),
50 m_netNameValidator( true ),
51 m_fields( nullptr ),
53 m_helpWindow( nullptr ),
54 m_labelList( nullptr )
55{
56 COLOR_SETTINGS* colorSettings = m_Parent->GetColorSettings();
57 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
58 bool multiLine = false;
59
60 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
61 multiLine = cfg->m_Appearance.edit_label_multiple;
62
63 m_cbMultiLine->SetValue( multiLine );
64
65 m_fields = new FIELDS_GRID_TABLE( this, aParent, m_grid, m_currentLabel );
68
69 if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T || m_currentLabel->Type() == SCH_LABEL_T )
70 {
71 m_activeTextEntry = m_valueCombo;
72 SetInitialFocus( m_valueCombo->GetTextCtrl() );
73
74 m_labelSingleLine->Show( false );
75 m_valueSingleLine->Show( false );
76
77 if( multiLine && aNew )
78 {
79 m_activeTextEntry = m_valueMultiLine;
80 SetInitialFocus( m_valueMultiLine );
81 m_labelCombo->Show( false );
82 m_valueCombo->Show( false );
83 }
84 else
85 {
86 m_labelMultiLine->Show( false );
87 m_valueMultiLine->Show( false );
88 m_valueCombo->SetValidator( m_netNameValidator );
89 }
90 }
91 else if( m_currentLabel->Type() == SCH_HIER_LABEL_T )
92 {
93 m_activeTextEntry = m_valueSingleLine;
94 SetInitialFocus( m_valueSingleLine );
95
96 m_labelCombo->Show( false );
97 m_valueCombo->Show( false );
98
99 if( multiLine && aNew )
100 {
101 m_activeTextEntry = m_valueMultiLine;
102 SetInitialFocus( m_valueMultiLine );
103 m_labelSingleLine->Show( false );
104 m_valueSingleLine->Show( false );
105 }
106 else
107 {
108 m_labelMultiLine->Show( false );
109 m_valueMultiLine->Show( false );
110 m_valueSingleLine->SetValidator( m_netNameValidator );
111 }
112 }
113 else if( m_currentLabel->Type() == SCH_DIRECTIVE_LABEL_T )
114 {
115 SetInitialFocus( m_grid );
116 m_delayedFocusRow = 0;
117
118 m_labelSingleLine->Show( false );
119 m_valueSingleLine->Show( false );
120 m_labelCombo->Show( false );
121 m_valueCombo->Show( false );
122 m_syntaxHelp->Show( false );
123 m_textEntrySizer->Show( false );
124 m_labelCombo->Show( false );
125 m_valueCombo->Show( false );
126 m_cbMultiLine->Show( false );
127
128 m_textSizeLabel->SetLabel( _( "Pin length:" ) );
129 }
130
131 if( !aNew )
132 m_cbMultiLine->Show( false );
133
134 switch( m_currentLabel->Type() )
135 {
136 case SCH_GLOBAL_LABEL_T: SetTitle( _( "Global Label Properties" ) ); break;
137 case SCH_HIER_LABEL_T: SetTitle( _( "Hierarchical Label Properties" ) ); break;
138 case SCH_LABEL_T: SetTitle( _( "Label Properties" ) ); break;
139 case SCH_DIRECTIVE_LABEL_T: SetTitle( _( "Directive Label Properties" ) ); break;
140 case SCH_SHEET_PIN_T: SetTitle( _( "Hierarchical Sheet Pin Properties" ) ); break;
141 default: UNIMPLEMENTED_FOR( m_currentLabel->GetClass() ); break;
142 }
143
144 m_grid->SetTable( m_fields );
145 m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this, {},
146 [&]( wxCommandEvent& aEvent )
147 {
148 OnAddField( aEvent );
149 } ) );
150 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
151
152 // Show/hide columns according to user's preference
153 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
154 {
155 m_grid->ShowHideColumns( cfg->m_Appearance.edit_label_visible_columns );
156 m_shownColumns = m_grid->GetShownColumns();
157 }
158
159 // Configure button logos
160 m_bpAdd->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
161 m_bpDelete->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
162 m_bpMoveUp->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
163 m_bpMoveDown->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
164
165 m_separator1->SetIsSeparator();
166
167 m_bold->SetIsCheckButton();
168 m_bold->SetBitmap( KiBitmapBundle( BITMAPS::text_bold ) );
169 m_italic->SetIsCheckButton();
170 m_italic->SetBitmap( KiBitmapBundle( BITMAPS::text_italic ) );
171
172 m_separator2->SetIsSeparator();
173
174 m_spin0->SetIsRadioButton();
175 m_spin1->SetIsRadioButton();
176 m_spin2->SetIsRadioButton();
177 m_spin3->SetIsRadioButton();
178
179 m_separator3->SetIsSeparator();
180
181 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
182 m_textColorSwatch->SetSwatchBackground( schematicBackground );
183
184 // Show/hide relevant controls
185 if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T || m_currentLabel->Type() == SCH_HIER_LABEL_T )
186 {
187 m_dot->Hide();
188 m_circle->Hide();
189 m_diamond->Hide();
190 m_rectangle->Hide();
191
192 m_spin0->SetBitmap( KiBitmapBundle( BITMAPS::label_align_left ) );
193 m_spin1->SetBitmap( KiBitmapBundle( BITMAPS::label_align_right ) );
194 m_spin2->SetBitmap( KiBitmapBundle( BITMAPS::label_align_bottom ) );
195 m_spin3->SetBitmap( KiBitmapBundle( BITMAPS::label_align_top ) );
196 }
197 else if( m_currentLabel->Type() == SCH_DIRECTIVE_LABEL_T )
198 {
199 m_input->Hide();
200 m_output->Hide();
201 m_bidirectional->Hide();
202 m_triState->Hide();
203 m_passive->Hide();
204
205 m_fontLabel->SetLabel( _( "Orientation:" ) );
206 m_fontCtrl->Hide();
207 m_separator1->Hide();
208 m_bold->Hide();
209 m_italic->Hide();
210 m_separator2->Hide();
211 m_spin0->SetBitmap( KiBitmapBundle( BITMAPS::pinorient_down ) );
212 m_spin1->SetBitmap( KiBitmapBundle( BITMAPS::pinorient_up ) );
213 m_spin2->SetBitmap( KiBitmapBundle( BITMAPS::pinorient_right ) );
214 m_spin3->SetBitmap( KiBitmapBundle( BITMAPS::pinorient_left ) );
215 m_separator3->Hide();
216
217 m_formattingGB->Detach( m_fontCtrl );
218 m_formattingGB->Detach( m_iconBar );
219 m_formattingGB->Add( m_iconBar, wxGBPosition( 0, 1 ), wxGBSpan( 1, 1 ), wxEXPAND | wxRIGHT, 5 );
220 }
221 else
222 {
223 m_shapeSizer->Show( false );
224
225 m_spin0->SetBitmap( KiBitmapBundle( BITMAPS::text_align_left ) );
226 m_spin1->SetBitmap( KiBitmapBundle( BITMAPS::text_align_right ) );
227 m_spin2->SetBitmap( KiBitmapBundle( BITMAPS::text_align_bottom ) );
228 m_spin3->SetBitmap( KiBitmapBundle( BITMAPS::text_align_top ) );
229 }
230
231 if( !m_currentLabel->AutoRotateOnPlacementSupported() )
232 {
233 m_autoRotate->Hide();
234 wxSizer* parentSizer = m_autoRotate->GetContainingSizer();
235 parentSizer->Detach( m_autoRotate );
236 parentSizer->Layout();
237 }
238
239 SetupStandardButtons();
240
241 // DIALOG_SHIM needs a unique hash_key because classname is not sufficient because the
242 // various versions have different controls so we want to store sizes for each version.
243 m_hash_key = TO_UTF8( GetTitle() );
244
245 m_spin0->Bind( wxEVT_BUTTON, &DIALOG_LABEL_PROPERTIES::onSpinButton, this );
246 m_spin1->Bind( wxEVT_BUTTON, &DIALOG_LABEL_PROPERTIES::onSpinButton, this );
247 m_spin2->Bind( wxEVT_BUTTON, &DIALOG_LABEL_PROPERTIES::onSpinButton, this );
248 m_spin3->Bind( wxEVT_BUTTON, &DIALOG_LABEL_PROPERTIES::onSpinButton, this );
249
250 // Now all widgets have the size fixed, call FinishDialogSettings
251 finishDialogSettings();
252
253 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
254 {
255 if( cfg->m_Appearance.edit_label_width > 0 && cfg->m_Appearance.edit_label_height > 0 )
256 SetSize( cfg->m_Appearance.edit_label_width, cfg->m_Appearance.edit_label_height );
257 }
258}
259
260
262{
263 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
264 {
265 cfg->m_Appearance.edit_label_visible_columns = m_grid->GetShownColumnsAsString();
266 cfg->m_Appearance.edit_label_width = GetSize().x;
267 cfg->m_Appearance.edit_label_height = GetSize().y;
268 cfg->m_Appearance.edit_label_multiple = m_cbMultiLine->IsChecked();
269 }
270
271 // Prevents crash bug in wxGrid's d'tor
272 m_grid->DestroyTable( m_fields );
273
274 // Delete the GRID_TRICKS.
275 m_grid->PopEventHandler( true );
276
277 if( m_helpWindow )
278 m_helpWindow->Destroy();
279}
280
281
283{
284 if( !wxDialog::TransferDataToWindow() )
285 return false;
286
287 wxString text;
288
290 {
291 // show control characters in a human-readable format
292 text = UnescapeString( m_currentLabel->GetText() );
293
294 // show text variable cross-references in a human-readable format
295 text = m_currentLabel->Schematic()->ConvertKIIDsToRefs( text );
296 }
297
298 if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T || m_currentLabel->Type() == SCH_LABEL_T )
299 {
300 // Load the combobox with the existing labels of the same type
301 std::set<wxString> existingLabels;
302 SCH_SCREENS allScreens( m_Parent->Schematic().Root() );
303
304 for( SCH_SCREEN* screen = allScreens.GetFirst(); screen; screen = allScreens.GetNext() )
305 {
306 for( SCH_ITEM* item : screen->Items().OfType( m_currentLabel->Type() ) )
307 {
308 const SCH_LABEL_BASE* label = static_cast<const SCH_LABEL_BASE*>( item );
309 existingLabels.insert( UnescapeString( label->GetText() ) );
310 }
311
312 // Add global power labels from power symbols
313 if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T )
314 {
315 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_LOCATE_POWER_T ) )
316 {
317 const SCH_SYMBOL* power = static_cast<const SCH_SYMBOL*>( item );
318
319 // Ensure the symbol has the Power (i.e. equivalent to a global label
320 // before adding its value in list
321 if( power->IsSymbolLikePowerGlobalLabel() )
322 {
323 const SCH_FIELD* valueField = power->GetField( FIELD_T::VALUE );
324 existingLabels.insert( UnescapeString( valueField->GetText() ) );
325 }
326 }
327 }
328
329 // Add local power labels from power symbols
330 if( m_currentLabel->Type() == SCH_LABEL_T )
331 {
332 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_LOCATE_POWER_T ) )
333 {
334 const SCH_SYMBOL* power = static_cast<const SCH_SYMBOL*>( item );
335
336 // Ensure the symbol has the Power (i.e. equivalent to a local label
337 // before adding its value in list
338 if( power->IsSymbolLikePowerLocalLabel() )
339 {
340 const SCH_FIELD* valueField = power->GetField( FIELD_T::VALUE );
341 existingLabels.insert( UnescapeString( valueField->GetText() ) );
342 }
343 }
344 }
345 }
346
347 // Add bus aliases to label list
348 for( const std::shared_ptr<BUS_ALIAS>& busAlias : m_Parent->Schematic().GetAllBusAliases() )
349 existingLabels.insert( wxT( "{" ) + busAlias->GetName() + wxT( "}" ) );
350
351 for( const wxString& label : existingLabels )
352 m_existingLabelArray.push_back( label );
353
354 m_valueCombo->SetStringList( m_existingLabelArray );
355 m_valueCombo->SetSelectedString( text );
356 }
357 else if( m_activeTextEntry )
358 {
359 m_activeTextEntry->SetValue( text );
360 }
361
362 // Push a copy of each field into m_updateFields
363 for( SCH_FIELD& field : m_currentLabel->GetFields() )
364 {
365 SCH_FIELD field_copy( field );
366
367 // change offset to be symbol-relative
368 field_copy.Offset( -m_currentLabel->GetPosition() );
369
370 m_fields->push_back( field_copy );
371 }
372
373 // notify the grid
374 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, (int) m_fields->size() );
375 m_grid->ProcessTableMessage( msg );
376
377 if( m_shapeSizer->AreAnyItemsShown() )
378 {
379 switch( m_currentLabel->GetShape() )
380 {
381 case LABEL_FLAG_SHAPE::L_INPUT: m_input->SetValue( true ); break;
382 case LABEL_FLAG_SHAPE::L_OUTPUT: m_output->SetValue( true ); break;
383 case LABEL_FLAG_SHAPE::L_BIDI: m_bidirectional->SetValue( true ); break;
384 case LABEL_FLAG_SHAPE::L_TRISTATE: m_triState->SetValue( true ); break;
385 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: m_passive->SetValue( true ); break;
386 case LABEL_FLAG_SHAPE::F_DOT: m_dot->SetValue( true ); break;
387 case LABEL_FLAG_SHAPE::F_ROUND: m_circle->SetValue( true ); break;
388 case LABEL_FLAG_SHAPE::F_DIAMOND: m_diamond->SetValue( true ); break;
389 case LABEL_FLAG_SHAPE::F_RECTANGLE: m_rectangle->SetValue( true ); break;
390 }
391 }
392
393 m_fontCtrl->SetFontSelection( m_currentLabel->GetFont() );
394
396 m_textSize.SetValue( static_cast<SCH_DIRECTIVE_LABEL*>( m_currentLabel )->GetPinLength() );
397 else
398 m_textSize.SetValue( m_currentLabel->GetTextWidth() );
399
400 m_bold->Check( m_currentLabel->IsBold() );
401 m_italic->Check( m_currentLabel->IsItalic() );
402 m_textColorSwatch->SetSwatchColor( m_currentLabel->GetTextColor(), false );
403
404 switch( m_currentLabel->GetSpinStyle() )
405 {
406 case SPIN_STYLE::RIGHT: m_spin0->Check( true ); break;
407 case SPIN_STYLE::LEFT: m_spin1->Check( true ); break;
408 case SPIN_STYLE::UP: m_spin2->Check( true ); break;
409 case SPIN_STYLE::BOTTOM: m_spin3->Check( true ); break;
410 }
411
412 if( m_currentLabel->AutoRotateOnPlacementSupported() )
413 m_autoRotate->SetValue( m_currentLabel->AutoRotateOnPlacement() );
414
415 return true;
416}
417
418
419void DIALOG_LABEL_PROPERTIES::OnEnterKey( wxCommandEvent& aEvent )
420{
421 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
422}
423
424
426{
427 // If the key is WXK_RETURN/WXK_NUMPAD_ENTER because m_valueCombo is the source event, we do not skip
428 // the key event because the default action is to show the m_valueCombo dropdown list,
429 // and we only want to accept the entered string.
430 if(( aEvent.GetKeyCode() == WXK_RETURN ) || (aEvent.GetKeyCode() == WXK_NUMPAD_ENTER))
431 {
432 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
433 }
434 else if( aEvent.GetKeyCode() == WXK_SPACE )
435 {
436 // our FILTER_COMBOBOX uses the space as special command, not wanted here,
437 // to open the dropdown list of labels.
438 // So just add the space char to the current text, at current insertion point,
439 // and do not skip this event
440 m_activeTextEntry->WriteText( wxT(" " ) );
441 }
442 else
443 {
444 aEvent.Skip();
445 }
446}
447
448
450{
451 if( aEvent.GetKeyCode() == WXK_TAB )
452 {
453 if( aEvent.ShiftDown() )
454 {
455 m_textSizeCtrl->SetFocusFromKbd();
456 }
457 else if( !m_fields->empty() )
458 {
459 m_grid->SetFocusFromKbd();
460 m_grid->MakeCellVisible( 0, 0 );
461 m_grid->SetGridCursor( 0, 0 );
462 }
463 else
464 {
465 m_textSizeCtrl->SetFocusFromKbd();
466 }
467 }
468 else
469 {
470 aEvent.Skip();
471 }
472}
473
474
475static bool positioningChanged( const SCH_FIELD& a, const SCH_FIELD& b )
476{
477 return a.GetPosition() != b.GetPosition()
478 || a.GetHorizJustify() != b.GetHorizJustify()
479 || a.GetVertJustify() != b.GetVertJustify()
480 || a.GetTextAngle() != b.GetTextAngle();
481}
482
483
484static bool positioningChanged( FIELDS_GRID_TABLE* a, std::vector<SCH_FIELD>& b )
485{
486 for( size_t i = 0; i < a->size() && i < b.size(); ++i )
487 {
488 if( positioningChanged( a->at( i ), b.at( i ) ) )
489 return true;
490 }
491
492 return false;
493}
494
495
497{
498 if( !m_grid->CommitPendingChanges() )
499 return false;
500
501 if( !wxDialog::TransferDataFromWindow() )
502 return false;
503
504 // Don't allow text to disappear; it can be difficult to correct if you can't select it
505 if( !m_textSize.Validate( 0.01, 1000.0, EDA_UNITS::MM ) )
506 return false;
507
508 SCH_COMMIT commit( m_Parent );
509 wxString text;
510
511 /* save old text in undo list if not already in edit */
512 if( m_currentLabel->GetEditFlags() == 0 )
513 commit.Modify( m_currentLabel, m_Parent->GetScreen() );
514
515 m_Parent->GetCanvas()->Refresh();
516
518 {
519 // labels need escaping
521
522 // convert any text variable cross-references to their UUIDs
523 text = m_currentLabel->Schematic()->ConvertRefsToKIIDs( text );
524
525#ifdef __WXMAC__
526 // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
527 text.Replace( wxS( "\r" ), wxS( "\n" ) );
528#endif
529
530 if( text.IsEmpty() && !m_currentLabel->IsNew() )
531 {
532 DisplayError( this, _( "Label can not be empty." ) );
533 return false;
534 }
535
536 m_currentLabel->SetText( text );
537 }
538
539 // change all field positions from relative to absolute
540 for( SCH_FIELD& field : *m_fields )
541 {
542 field.Offset( m_currentLabel->GetPosition() );
543
544 if( field.GetCanonicalName() == wxT( "Netclass" ) )
545 {
546 field.SetLayer( LAYER_NETCLASS_REFS );
547 }
548 else if( field.GetId() == FIELD_T::INTERSHEET_REFS )
549 {
550 if( field.IsVisible() != m_Parent->Schematic().Settings().m_IntersheetRefsShow )
551 {
552 DisplayInfoMessage( this, _( "Intersheet reference visibility is controlled globally from "
553 "Schematic Setup > General > Formatting" ) );
554 }
555
556 field.SetLayer( LAYER_INTERSHEET_REFS );
557 }
558 else
559 {
560 field.SetLayer( LAYER_FIELDS );
561 }
562 }
563
564 if( positioningChanged( m_fields, m_currentLabel->GetFields() ) )
565 m_currentLabel->SetFieldsAutoplaced( AUTOPLACE_NONE );
566
567 for( int ii = m_fields->GetNumberRows() - 1; ii >= 0; ii-- )
568 {
569 SCH_FIELD& field = m_fields->at( ii );
570 const wxString& fieldName = field.GetCanonicalName();
571 const wxString& fieldText = field.GetText();
572
573 if( fieldName.IsEmpty() && fieldText.IsEmpty() )
574 {
575 // delete empty, unnamed fields
576 m_fields->erase( m_fields->begin() + ii );
577 }
578 else if( fieldName == wxT( "Netclass" ) && fieldText.IsEmpty() )
579 {
580 // delete empty Netclass fields if there are other Netclass fields present
581 int netclassFieldCount = 0;
582
583 for( int jj = 0; jj < m_fields->GetNumberRows(); ++jj )
584 {
585 if( m_fields->at( jj ).GetCanonicalName() == wxT( "Netclass" ) )
586 netclassFieldCount++;
587 }
588
589 if( netclassFieldCount > 1 )
590 m_fields->erase( m_fields->begin() + ii );
591 }
592 else if( fieldName.IsEmpty() )
593 {
594 // give non-empty, unnamed fields a name
595 field.SetName( _( "untitled" ) );
596 }
597 }
598
599 int ordinal = 42; // Arbitrarily larger than any mandatory FIELD_T ids.
600
601 for( SCH_FIELD& field : *m_fields )
602 {
603 if( !field.IsMandatory() )
604 field.SetOrdinal( ordinal++ );
605 }
606
607 m_currentLabel->SetFields( *m_fields );
608
609 if( m_shapeSizer->AreAnyItemsShown() )
610 {
611 if( m_bidirectional->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
612 else if( m_input->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
613 else if( m_output->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
614 else if( m_triState->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
615 else if( m_passive->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
616 else if( m_dot->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DOT );
617 else if( m_circle->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_ROUND );
618 else if( m_diamond->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DIAMOND );
619 else if( m_rectangle->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_RECTANGLE );
620 }
621
622 if( m_fontCtrl->HaveFontSelection() )
623 m_currentLabel->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), m_italic->IsChecked() ) );
624
626 static_cast<SCH_DIRECTIVE_LABEL*>( m_currentLabel )->SetPinLength( m_textSize.GetIntValue() );
627 else if( m_currentLabel->GetTextWidth() != m_textSize.GetIntValue() )
628 m_currentLabel->SetTextSize( VECTOR2I( m_textSize.GetIntValue(), m_textSize.GetIntValue() ) );
629
630 // Must come after SetTextSize()
631 m_currentLabel->SetBold( m_bold->IsChecked() );
632 m_currentLabel->SetItalic( m_italic->IsChecked() );
633
634 m_currentLabel->SetTextColor( m_textColorSwatch->GetSwatchColor() );
635
636 SPIN_STYLE selectedSpinStyle= SPIN_STYLE::LEFT;
637
638 if( m_spin0->IsChecked() ) selectedSpinStyle = SPIN_STYLE::RIGHT;
639 else if( m_spin1->IsChecked() ) selectedSpinStyle = SPIN_STYLE::LEFT;
640 else if( m_spin2->IsChecked() ) selectedSpinStyle = SPIN_STYLE::UP;
641 else if( m_spin3->IsChecked() ) selectedSpinStyle = SPIN_STYLE::BOTTOM;
642
643 if( m_currentLabel->AutoRotateOnPlacementSupported() )
644 {
645 SCH_EDIT_FRAME* frame = static_cast<SCH_EDIT_FRAME*>( m_parentFrame );
646 m_currentLabel->SetAutoRotateOnPlacement( m_autoRotate->IsChecked() );
647 frame->AutoRotateItem( frame->GetScreen(), m_currentLabel );
648 }
649 else
650 {
651 m_currentLabel->SetAutoRotateOnPlacement( false );
652 }
653
654 if( !m_currentLabel->AutoRotateOnPlacement() && m_currentLabel->GetSpinStyle() != selectedSpinStyle )
655 m_currentLabel->SetSpinStyle( selectedSpinStyle );
656
657 AUTOPLACE_ALGO fieldsAutoplaced = m_currentLabel->GetFieldsAutoplaced();
658
659 if( fieldsAutoplaced == AUTOPLACE_AUTO || fieldsAutoplaced == AUTOPLACE_MANUAL )
660 m_currentLabel->AutoplaceFields( m_Parent->GetScreen(), fieldsAutoplaced );
661
662 if( !commit.Empty() )
663 {
664 commit.Push( _( "Edit Label Properties" ) );
665 }
666 else if( m_activeTextEntry && m_labelList )
667 {
668 text = m_activeTextEntry->GetValue();
669 // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
670 text.Replace( wxS( "\r" ), wxS( "\n" ) );
671 wxArrayString lines = wxSplit( text, '\n' );
672
673 for( const wxString& line : lines )
674 {
675 text = EscapeString( line, CTX_NETNAME );
676 text.Trim( false ).Trim( true );
677
678 if( text.empty() )
679 continue;
680
681 // convert any text variable cross-references to their UUIDs
682 text = m_currentLabel->Schematic()->ConvertRefsToKIIDs( text );
683
684 switch ( m_currentLabel->Type() )
685 {
687 {
688 SCH_GLOBALLABEL* label = new SCH_GLOBALLABEL( *static_cast<SCH_GLOBALLABEL*>( m_currentLabel ) );
689 label->SetText( text );
690 m_labelList->push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
691 break;
692 }
693 case SCH_HIER_LABEL_T:
694 {
695 SCH_HIERLABEL* label = new SCH_HIERLABEL( *static_cast<SCH_HIERLABEL*>( m_currentLabel ) );
696 label->SetText( text );
697 m_labelList->push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
698 break;
699 }
700 case SCH_LABEL_T:
701 {
702 SCH_LABEL* label = new SCH_LABEL( *static_cast<SCH_LABEL*>( m_currentLabel ) );
703 label->SetText( text );
704 m_labelList->push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
705 break;
706 }
707 default:
708 break;
709 }
710 }
711 }
712 else if( m_labelList && m_currentLabel->Type() == SCH_DIRECTIVE_LABEL_T )
713 {
715 m_labelList->push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
716 }
717
718 return true;
719}
720
721
722void DIALOG_LABEL_PROPERTIES::onSpinButton( wxCommandEvent& aEvent )
723{
724 for( BITMAP_BUTTON* btn : { m_spin0, m_spin1, m_spin2, m_spin3 } )
725 {
726 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
727 btn->Check( false );
728 }
729}
730
731
732void DIALOG_LABEL_PROPERTIES::OnFormattingHelp( wxHyperlinkEvent& aEvent )
733{
735}
736
737
738void DIALOG_LABEL_PROPERTIES::OnAddField( wxCommandEvent& event )
739{
740 m_grid->OnAddRow(
741 [&]() -> std::pair<int, int>
742 {
743 wxString fieldName = wxT( "Netclass" );
744
745 for( SCH_FIELD& field : *m_fields )
746 {
747 if( field.GetId() != FIELD_T::INTERSHEET_REFS && field.GetName() != wxT( "Netclass" ) )
748 {
749 fieldName = wxEmptyString;
750 break;
751 }
752 }
753
754 fieldName = SCH_LABEL_BASE::GetDefaultFieldName( fieldName, true );
755
756 SCH_FIELD newField( m_currentLabel, FIELD_T::USER, fieldName );
757
758 if( m_fields->size() > 0 )
759 {
760 // SetAttributes() also covers text angle, size, italic and bold
761 newField.SetAttributes( m_fields->at( m_fields->size() - 1 ) );
762 newField.SetVisible( m_fields->at( m_fields->size() - 1 ).IsVisible() );
763 }
764 else
765 {
766 newField.SetVisible( true );
767 newField.SetItalic( true );
768 }
769
770 m_fields->push_back( newField );
771
772 // notify the grid
773 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
774 m_grid->ProcessTableMessage( msg );
775 return { m_fields->size() - 1, FDC_NAME };
776 } );
777}
778
779
780void DIALOG_LABEL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
781{
782 m_grid->OnDeleteRows(
783 [&]( int row )
784 {
785 if( row < m_currentLabel->GetMandatoryFieldCount() )
786 {
787 DisplayError( this, _( "The first field is mandatory." ) );
788 return false;
789 }
790
791 return true;
792 },
793 [&]( int row )
794 {
795 m_fields->erase( m_fields->begin() + row );
796
797 // notify the grid
798 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
799 m_grid->ProcessTableMessage( msg );
800 } );
801}
802
803
804void DIALOG_LABEL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
805{
806 m_grid->OnMoveRowUp(
807 [&]( int row )
808 {
809 return row > m_currentLabel->GetMandatoryFieldCount();
810 },
811 [&]( int row )
812 {
813 std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row - 1 ) );
814 m_grid->ForceRefresh();
815 } );
816}
817
818
819void DIALOG_LABEL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
820{
821 m_grid->OnMoveRowUp(
822 [&]( int row )
823 {
824 return row >= m_currentLabel->GetMandatoryFieldCount();
825 },
826 [&]( int row )
827 {
828 std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row + 1 ) );
829 m_grid->ForceRefresh();
830 } );
831}
832
833
834void DIALOG_LABEL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
835{
836 std::bitset<64> shownColumns = m_grid->GetShownColumns();
837
838 if( shownColumns != m_shownColumns )
839 {
840 m_shownColumns = shownColumns;
841
842 if( !m_grid->IsCellEditControlShown() )
843 m_grid->SetGridWidthsDirty();
844 }
845
846 // Handle a delayed focus
847 if( m_delayedFocusRow >= 0 && m_delayedFocusRow < m_grid->GetNumberRows() )
848 {
849 m_grid->SetFocus();
850 m_grid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
852 }
853
856}
857
858
860{
861 if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T || m_currentLabel->Type() == SCH_LABEL_T )
862 {
863 m_labelCombo->Show( !m_cbMultiLine->IsChecked() );
864 m_valueCombo->Show( !m_cbMultiLine->IsChecked() );
865 m_labelMultiLine->Show( m_cbMultiLine->IsChecked() );
866 m_valueMultiLine->Show( m_cbMultiLine->IsChecked() );
867
868 if( m_cbMultiLine->IsChecked() )
869 {
870 m_valueMultiLine->SetValue( m_valueCombo->GetValue() );
873 }
874 else
875 {
876 wxString multiText = m_valueMultiLine->GetValue();
877 m_valueCombo->SetValue( multiText.BeforeFirst( '\n' ) );
880 }
881 }
882 else if( m_currentLabel->Type() == SCH_HIER_LABEL_T )
883 {
884 m_labelSingleLine->Show( !m_cbMultiLine->IsChecked() );
885 m_valueSingleLine->Show( !m_cbMultiLine->IsChecked() );
886 m_labelMultiLine->Show( m_cbMultiLine->IsChecked() );
887 m_valueMultiLine->Show( m_cbMultiLine->IsChecked() );
888
889 if( m_cbMultiLine->IsChecked() )
890 {
891 m_valueMultiLine->SetValue( m_valueSingleLine->GetValue() );
894 }
895 else
896 {
897 wxString multiText = m_valueMultiLine->GetValue();
898 m_valueSingleLine->SetValue( multiText.BeforeFirst( '\n' ) );
901 }
902 }
903
904 Layout();
905}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
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: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_LABEL_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Label Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
std::list< std::unique_ptr< SCH_LABEL_BASE > > * m_labelList
void OnMoveUp(wxCommandEvent &event) override
void OnMoveDown(wxCommandEvent &event) override
DIALOG_LABEL_PROPERTIES(SCH_EDIT_FRAME *parent, SCH_LABEL_BASE *aLabel, bool aNew)
void OnEnterKey(wxCommandEvent &aEvent) override
wxEVT_COMMAND_ENTER event handler for single-line control.
void OnAddField(wxCommandEvent &event) override
SCH_NETNAME_VALIDATOR m_netNameValidator
void OnFormattingHelp(wxHyperlinkEvent &aEvent) override
void OnCBValueCharHook(wxKeyEvent &aEvent) override
void OnUpdateUI(wxUpdateUIEvent &event) override
void onSpinButton(wxCommandEvent &aEvent)
void onMultiLabelCheck(wxCommandEvent &aEvent) override
void OnDeleteField(wxCommandEvent &event) override
void OnValueCharHook(wxKeyEvent &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
EDA_BASE_FRAME * m_parentFrame
const EDA_ANGLE & GetTextAngle() const
Definition eda_text.h:147
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:98
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition eda_text.cpp:444
void Offset(const VECTOR2I &aOffset)
Definition eda_text.cpp:607
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:200
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:397
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:203
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:281
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition eda_text.cpp:318
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:104
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void AutoRotateItem(SCH_SCREEN *aScreen, SCH_ITEM *aItem)
Automatically set the rotation of an item (if the item supports it).
VECTOR2I GetPosition() const override
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
void SetName(const wxString &aName)
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
static const wxString GetDefaultFieldName(const wxString &aName, bool aUseDefaultName)
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition sch_screen.h:731
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
Schematic symbol object.
Definition sch_symbol.h:75
bool IsSymbolLikePowerGlobalLabel() const
bool IsSymbolLikePowerLocalLabel() const
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition confirm.cpp:222
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:169
This file is part of the common library.
static bool positioningChanged(const SCH_FIELD &a, const SCH_FIELD &b)
#define _(s)
@ FDC_NAME
@ FDC_VALUE
@ LAYER_FIELDS
Definition layer_ids.h:462
@ LAYER_NETCLASS_REFS
Definition layer_ids.h:464
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:488
@ LAYER_INTERSHEET_REFS
Definition layer_ids.h:463
AUTOPLACE_ALGO
Definition sch_item.h:68
@ AUTOPLACE_MANUAL
Definition sch_item.h:71
@ AUTOPLACE_NONE
Definition sch_item.h:69
@ AUTOPLACE_AUTO
Definition sch_item.h:70
@ L_BIDI
Definition sch_label.h:102
@ L_TRISTATE
Definition sch_label.h:103
@ L_UNSPECIFIED
Definition sch_label.h:104
@ F_DOT
Definition sch_label.h:107
@ F_ROUND
Definition sch_label.h:108
@ L_OUTPUT
Definition sch_label.h:101
@ F_DIAMOND
Definition sch_label.h:109
@ L_INPUT
Definition sch_label.h:100
@ F_RECTANGLE
Definition sch_label.h:110
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
@ CTX_NETNAME
@ USER
The field ID hasn't been set yet; field is invalid.
@ INTERSHEET_REFS
Global label cross-reference page numbers.
@ VALUE
Field Value of part, i.e. "3.3K".
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:175
@ SCH_LABEL_T
Definition typeinfo.h:171
@ SCH_HIER_LABEL_T
Definition typeinfo.h:173
@ SCH_SYMBOL_LOCATE_POWER_T
Definition typeinfo.h:200
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:172
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695