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
59 m_fields = new FIELDS_GRID_TABLE( this, aParent, m_grid, m_currentLabel );
62
63 if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T || m_currentLabel->Type() == SCH_LABEL_T )
64 {
66 SetInitialFocus( m_valueCombo->GetTextCtrl() );
67
68 m_labelSingleLine->Show( false );
69 m_valueSingleLine->Show( false );
70 }
71 else if( m_currentLabel->Type() == SCH_HIER_LABEL_T )
72 {
75
76 m_labelCombo->Show( false );
77 m_valueCombo->Show( false );
78 }
79 else if( m_currentLabel->Type() == SCH_DIRECTIVE_LABEL_T )
80 {
83
84 m_labelSingleLine->Show( false );
85 m_valueSingleLine->Show( false );
86 m_labelCombo->Show( false );
87 m_valueCombo->Show( false );
88 m_syntaxHelp->Show( false );
89 m_textEntrySizer->Show( false );
90 m_labelCombo->Show( false );
91 m_valueCombo->Show( false );
92 m_cbMultiLine->Show( false );
93
94 m_textSizeLabel->SetLabel( _( "Pin length:" ) );
95 }
96
97 if( !aNew )
98 m_cbMultiLine->Show( false );
99
100 // multiline set of labels can be used only to create new labels
101 m_multilineAllowed = aNew && m_cbMultiLine->IsShown();
102
103 switch( m_currentLabel->Type() )
104 {
105 case SCH_GLOBAL_LABEL_T: SetTitle( _( "Global Label Properties" ) ); break;
106 case SCH_HIER_LABEL_T: SetTitle( _( "Hierarchical Label Properties" ) ); break;
107 case SCH_LABEL_T: SetTitle( _( "Label Properties" ) ); break;
108 case SCH_DIRECTIVE_LABEL_T: SetTitle( _( "Directive Label Properties" ) ); break;
109 case SCH_SHEET_PIN_T: SetTitle( _( "Hierarchical Sheet Pin Properties" ) ); break;
110 default: UNIMPLEMENTED_FOR( m_currentLabel->GetClass() ); break;
111 }
112
113 m_grid->SetTable( m_fields );
114 m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this, {},
115 [&]( wxCommandEvent& aEvent )
116 {
117 OnAddField( aEvent );
118 } ) );
119 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
120 m_grid->ShowHideColumns( "0 1 2 3 4 5 6 7" );
121 m_shownColumns = m_grid->GetShownColumns();
122
123 // Configure button logos
128
129 m_separator1->SetIsSeparator();
130
131 m_bold->SetIsCheckButton();
133 m_italic->SetIsCheckButton();
135
136 m_separator2->SetIsSeparator();
137
138 m_spin0->SetIsRadioButton();
139 m_spin1->SetIsRadioButton();
140 m_spin2->SetIsRadioButton();
141 m_spin3->SetIsRadioButton();
142
143 m_separator3->SetIsSeparator();
144
145 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
146 m_textColorSwatch->SetSwatchBackground( schematicBackground );
147
148 // Show/hide relevant controls
150 {
151 m_dot->Hide();
152 m_circle->Hide();
153 m_diamond->Hide();
154 m_rectangle->Hide();
155
160 }
161 else if( m_currentLabel->Type() == SCH_DIRECTIVE_LABEL_T )
162 {
163 m_input->Hide();
164 m_output->Hide();
165 m_bidirectional->Hide();
166 m_triState->Hide();
167 m_passive->Hide();
168
169 m_fontLabel->SetLabel( _( "Orientation:" ) );
170 m_fontCtrl->Hide();
171 m_separator1->Hide();
172 m_bold->Hide();
173 m_italic->Hide();
174 m_separator2->Hide();
179 m_separator3->Hide();
180
181 m_formattingGB->Detach( m_fontCtrl );
182 m_formattingGB->Detach( m_iconBar );
183 m_formattingGB->Add( m_iconBar, wxGBPosition( 0, 1 ), wxGBSpan( 1, 1 ), wxEXPAND | wxRIGHT, 5 );
184 }
185 else
186 {
187 m_shapeSizer->Show( false );
188
193 }
194
195 if( !m_currentLabel->AutoRotateOnPlacementSupported() )
196 {
197 m_autoRotate->Hide();
198 wxSizer* parentSizer = m_autoRotate->GetContainingSizer();
199 parentSizer->Detach( m_autoRotate );
200 parentSizer->Layout();
201 }
202
204
205 // DIALOG_SHIM needs a unique hash_key because classname is not sufficient because the
206 // various versions have different controls so we want to store sizes for each version.
207 m_hash_key = TO_UTF8( GetTitle() );
208
209 m_spin0->Bind( wxEVT_BUTTON, &DIALOG_LABEL_PROPERTIES::onSpinButton, this );
210 m_spin1->Bind( wxEVT_BUTTON, &DIALOG_LABEL_PROPERTIES::onSpinButton, this );
211 m_spin2->Bind( wxEVT_BUTTON, &DIALOG_LABEL_PROPERTIES::onSpinButton, this );
212 m_spin3->Bind( wxEVT_BUTTON, &DIALOG_LABEL_PROPERTIES::onSpinButton, this );
213
214 // Now all widgets have the size fixed, call FinishDialogSettings
216}
217
218
220{
221 // Prevents crash bug in wxGrid's d'tor
222 m_grid->DestroyTable( m_fields );
223
224 // Delete the GRID_TRICKS.
225 m_grid->PopEventHandler( true );
226
227 if( m_helpWindow )
228 m_helpWindow->Destroy();
229}
230
231
233{
234 if( !wxDialog::TransferDataToWindow() )
235 return false;
236
237 // Respond to previously-saved state of multilable checkbox
238 wxCommandEvent dummy;
240
241 wxString text;
242
244 {
245 // show control characters in a human-readable format
246 text = UnescapeString( m_currentLabel->GetText() );
247
248 // show text variable cross-references in a human-readable format
249 text = m_currentLabel->Schematic()->ConvertKIIDsToRefs( text );
250 }
251
252 if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T || m_currentLabel->Type() == SCH_LABEL_T )
253 {
254 // Load the combobox with the existing labels of the same type
255 std::set<wxString> existingLabels;
256 SCH_SCREENS allScreens( m_Parent->Schematic().Root() );
257
258 for( SCH_SCREEN* screen = allScreens.GetFirst(); screen; screen = allScreens.GetNext() )
259 {
260 for( SCH_ITEM* item : screen->Items().OfType( m_currentLabel->Type() ) )
261 {
262 const SCH_LABEL_BASE* label = static_cast<const SCH_LABEL_BASE*>( item );
263 existingLabels.insert( UnescapeString( label->GetText() ) );
264 }
265
266 // Add global power labels from power symbols
267 if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T )
268 {
269 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_LOCATE_POWER_T ) )
270 {
271 const SCH_SYMBOL* power = static_cast<const SCH_SYMBOL*>( item );
272
273 // Ensure the symbol has the Power (i.e. equivalent to a global label
274 // before adding its value in list
275 if( power->IsSymbolLikePowerGlobalLabel() )
276 {
277 const SCH_FIELD* valueField = power->GetField( FIELD_T::VALUE );
278 existingLabels.insert( UnescapeString( valueField->GetText() ) );
279 }
280 }
281 }
282
283 // Add local power labels from power symbols
284 if( m_currentLabel->Type() == SCH_LABEL_T )
285 {
286 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_LOCATE_POWER_T ) )
287 {
288 const SCH_SYMBOL* power = static_cast<const SCH_SYMBOL*>( item );
289
290 // Ensure the symbol has the Power (i.e. equivalent to a local label
291 // before adding its value in list
292 if( power->IsSymbolLikePowerLocalLabel() )
293 {
294 const SCH_FIELD* valueField = power->GetField( FIELD_T::VALUE );
295 existingLabels.insert( UnescapeString( valueField->GetText() ) );
296 }
297 }
298 }
299 }
300
301 // Add bus aliases to label list
302 for( const std::shared_ptr<BUS_ALIAS>& busAlias : m_Parent->Schematic().GetAllBusAliases() )
303 existingLabels.insert( wxT( "{" ) + busAlias->GetName() + wxT( "}" ) );
304
305 for( const wxString& label : existingLabels )
306 m_existingLabelArray.push_back( label );
307
308 m_valueCombo->SetStringList( m_existingLabelArray );
309 m_valueCombo->SetSelectedString( text );
310 }
311 else if( m_activeTextEntry )
312 {
313 m_activeTextEntry->SetValue( text );
314 }
315
316 // Push a copy of each field into m_updateFields
317 for( SCH_FIELD& field : m_currentLabel->GetFields() )
318 {
319 SCH_FIELD field_copy( field );
320
321 // change offset to be symbol-relative
322 field_copy.Offset( -m_currentLabel->GetPosition() );
323
324 m_fields->push_back( field_copy );
325 }
326
327 // notify the grid
328 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, (int) m_fields->size() );
329 m_grid->ProcessTableMessage( msg );
330
331 if( m_shapeSizer->AreAnyItemsShown() )
332 {
333 switch( m_currentLabel->GetShape() )
334 {
335 case LABEL_FLAG_SHAPE::L_INPUT: m_input->SetValue( true ); break;
336 case LABEL_FLAG_SHAPE::L_OUTPUT: m_output->SetValue( true ); break;
337 case LABEL_FLAG_SHAPE::L_BIDI: m_bidirectional->SetValue( true ); break;
338 case LABEL_FLAG_SHAPE::L_TRISTATE: m_triState->SetValue( true ); break;
339 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: m_passive->SetValue( true ); break;
340 case LABEL_FLAG_SHAPE::F_DOT: m_dot->SetValue( true ); break;
341 case LABEL_FLAG_SHAPE::F_ROUND: m_circle->SetValue( true ); break;
342 case LABEL_FLAG_SHAPE::F_DIAMOND: m_diamond->SetValue( true ); break;
343 case LABEL_FLAG_SHAPE::F_RECTANGLE: m_rectangle->SetValue( true ); break;
344 }
345 }
346
347 m_fontCtrl->SetFontSelection( m_currentLabel->GetFont() );
348
350 m_textSize.SetValue( static_cast<SCH_DIRECTIVE_LABEL*>( m_currentLabel )->GetPinLength() );
351 else
352 m_textSize.SetValue( m_currentLabel->GetTextWidth() );
353
354 m_bold->Check( m_currentLabel->IsBold() );
355 m_italic->Check( m_currentLabel->IsItalic() );
356 m_textColorSwatch->SetSwatchColor( m_currentLabel->GetTextColor(), false );
357
358 switch( m_currentLabel->GetSpinStyle() )
359 {
360 case SPIN_STYLE::RIGHT: m_spin0->Check( true ); break;
361 case SPIN_STYLE::LEFT: m_spin1->Check( true ); break;
362 case SPIN_STYLE::UP: m_spin2->Check( true ); break;
363 case SPIN_STYLE::BOTTOM: m_spin3->Check( true ); break;
364 }
365
366 if( m_currentLabel->AutoRotateOnPlacementSupported() )
367 m_autoRotate->SetValue( m_currentLabel->AutoRotateOnPlacement() );
368
369 return true;
370}
371
372
373void DIALOG_LABEL_PROPERTIES::OnEnterKey( wxCommandEvent& aEvent )
374{
375 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
376}
377
378
380{
381 // If the key is WXK_RETURN/WXK_NUMPAD_ENTER because m_valueCombo is the source event, we do not skip
382 // the key event because the default action is to show the m_valueCombo dropdown list,
383 // and we only want to accept the entered string.
384 if(( aEvent.GetKeyCode() == WXK_RETURN ) || (aEvent.GetKeyCode() == WXK_NUMPAD_ENTER))
385 {
386 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
387 }
388 else if( aEvent.GetKeyCode() == WXK_SPACE )
389 {
390 // our FILTER_COMBOBOX uses the space as special command, not wanted here,
391 // to open the dropdown list of labels.
392 // So just add the space char to the current text, at current insertion point,
393 // and do not skip this event
394 m_activeTextEntry->WriteText( wxT(" " ) );
395 }
396 else
397 {
398 aEvent.Skip();
399 }
400}
401
402
404{
405 if( aEvent.GetKeyCode() == WXK_TAB )
406 {
407 if( aEvent.ShiftDown() )
408 {
409 m_textSizeCtrl->SetFocusFromKbd();
410 }
411 else if( !m_fields->empty() )
412 {
413 m_grid->SetFocusFromKbd();
414 m_grid->MakeCellVisible( 0, 0 );
415 m_grid->SetGridCursor( 0, 0 );
416 }
417 else
418 {
419 m_textSizeCtrl->SetFocusFromKbd();
420 }
421 }
422 else
423 {
424 aEvent.Skip();
425 }
426}
427
428
429static bool positioningChanged( const SCH_FIELD& a, const SCH_FIELD& b )
430{
431 return a.GetPosition() != b.GetPosition()
432 || a.GetHorizJustify() != b.GetHorizJustify()
433 || a.GetVertJustify() != b.GetVertJustify()
434 || a.GetTextAngle() != b.GetTextAngle();
435}
436
437
438static bool positioningChanged( FIELDS_GRID_TABLE* a, std::vector<SCH_FIELD>& b )
439{
440 for( size_t i = 0; i < a->size() && i < b.size(); ++i )
441 {
442 if( positioningChanged( a->at( i ), b.at( i ) ) )
443 return true;
444 }
445
446 return false;
447}
448
449
451{
452 if( !m_grid->CommitPendingChanges() )
453 return false;
454
455 if( !wxDialog::TransferDataFromWindow() )
456 return false;
457
458 // Don't allow text to disappear; it can be difficult to correct if you can't select it
459 if( !m_textSize.Validate( 0.01, 1000.0, EDA_UNITS::MM ) )
460 return false;
461
462 SCH_COMMIT commit( m_Parent );
463 wxString text;
464
465 /* save old text in undo list if not already in edit */
466 if( m_currentLabel->GetEditFlags() == 0 )
467 commit.Modify( m_currentLabel, m_Parent->GetScreen() );
468
469 m_Parent->GetCanvas()->Refresh();
470
472 {
473 // labels need escaping
475
476 // convert any text variable cross-references to their UUIDs
477 text = m_currentLabel->Schematic()->ConvertRefsToKIIDs( text );
478
479#ifdef __WXMAC__
480 // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
481 text.Replace( wxS( "\r" ), wxS( "\n" ) );
482#endif
483
484 if( text.IsEmpty() && !m_currentLabel->IsNew() )
485 {
486 DisplayError( this, _( "Label can not be empty." ) );
487 return false;
488 }
489
490 m_currentLabel->SetText( text );
491 }
492
493 // change all field positions from relative to absolute
494 for( SCH_FIELD& field : *m_fields )
495 {
496 field.Offset( m_currentLabel->GetPosition() );
497
498 if( field.GetCanonicalName() == wxT( "Netclass" ) )
499 {
500 field.SetLayer( LAYER_NETCLASS_REFS );
501 }
502 else if( field.GetId() == FIELD_T::INTERSHEET_REFS )
503 {
504 if( field.IsVisible() != m_Parent->Schematic().Settings().m_IntersheetRefsShow )
505 {
506 DisplayInfoMessage( this, _( "Intersheet reference visibility is controlled globally from "
507 "Schematic Setup > General > Formatting" ) );
508 }
509
510 field.SetLayer( LAYER_INTERSHEET_REFS );
511 }
512 else
513 {
514 field.SetLayer( LAYER_FIELDS );
515 }
516 }
517
518 if( positioningChanged( m_fields, m_currentLabel->GetFields() ) )
519 m_currentLabel->SetFieldsAutoplaced( AUTOPLACE_NONE );
520
521 for( int ii = m_fields->GetNumberRows() - 1; ii >= 0; ii-- )
522 {
523 SCH_FIELD& field = m_fields->at( ii );
524 const wxString& fieldName = field.GetCanonicalName();
525 const wxString& fieldText = field.GetText();
526
527 if( fieldName.IsEmpty() && fieldText.IsEmpty() )
528 {
529 // delete empty, unnamed fields
530 m_fields->erase( m_fields->begin() + ii );
531 }
532 else if( fieldName == wxT( "Netclass" ) && fieldText.IsEmpty() )
533 {
534 // delete empty Netclass fields if there are other Netclass fields present
535 int netclassFieldCount = 0;
536
537 for( int jj = 0; jj < m_fields->GetNumberRows(); ++jj )
538 {
539 if( m_fields->at( jj ).GetCanonicalName() == wxT( "Netclass" ) )
540 netclassFieldCount++;
541 }
542
543 if( netclassFieldCount > 1 )
544 m_fields->erase( m_fields->begin() + ii );
545 }
546 else if( fieldName.IsEmpty() )
547 {
548 // give non-empty, unnamed fields a name
549 field.SetName( _( "untitled" ) );
550 }
551 }
552
553 int ordinal = 42; // Arbitrarily larger than any mandatory FIELD_T ids.
554
555 for( SCH_FIELD& field : *m_fields )
556 {
557 if( !field.IsMandatory() )
558 field.SetOrdinal( ordinal++ );
559 }
560
561 m_currentLabel->SetFields( *m_fields );
562
563 if( m_shapeSizer->AreAnyItemsShown() )
564 {
565 if( m_bidirectional->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
566 else if( m_input->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
567 else if( m_output->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
568 else if( m_triState->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
569 else if( m_passive->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
570 else if( m_dot->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DOT );
571 else if( m_circle->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_ROUND );
572 else if( m_diamond->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DIAMOND );
573 else if( m_rectangle->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_RECTANGLE );
574 }
575
576 if( m_fontCtrl->HaveFontSelection() )
577 m_currentLabel->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), m_italic->IsChecked() ) );
578
580 static_cast<SCH_DIRECTIVE_LABEL*>( m_currentLabel )->SetPinLength( m_textSize.GetIntValue() );
581 else if( m_currentLabel->GetTextWidth() != m_textSize.GetIntValue() )
582 m_currentLabel->SetTextSize( VECTOR2I( m_textSize.GetIntValue(), m_textSize.GetIntValue() ) );
583
584 // Must come after SetTextSize()
585 m_currentLabel->SetBold( m_bold->IsChecked() );
586 m_currentLabel->SetItalic( m_italic->IsChecked() );
587
588 m_currentLabel->SetTextColor( m_textColorSwatch->GetSwatchColor() );
589
590 SPIN_STYLE selectedSpinStyle= SPIN_STYLE::LEFT;
591
592 if( m_spin0->IsChecked() ) selectedSpinStyle = SPIN_STYLE::RIGHT;
593 else if( m_spin1->IsChecked() ) selectedSpinStyle = SPIN_STYLE::LEFT;
594 else if( m_spin2->IsChecked() ) selectedSpinStyle = SPIN_STYLE::UP;
595 else if( m_spin3->IsChecked() ) selectedSpinStyle = SPIN_STYLE::BOTTOM;
596
597 if( m_currentLabel->AutoRotateOnPlacementSupported() )
598 {
599 SCH_EDIT_FRAME* frame = static_cast<SCH_EDIT_FRAME*>( m_parentFrame );
600 m_currentLabel->SetAutoRotateOnPlacement( m_autoRotate->IsChecked() );
601 frame->AutoRotateItem( frame->GetScreen(), m_currentLabel );
602 }
603 else
604 {
605 m_currentLabel->SetAutoRotateOnPlacement( false );
606 }
607
608 if( !m_currentLabel->AutoRotateOnPlacement() && m_currentLabel->GetSpinStyle() != selectedSpinStyle )
609 m_currentLabel->SetSpinStyle( selectedSpinStyle );
610
611 AUTOPLACE_ALGO fieldsAutoplaced = m_currentLabel->GetFieldsAutoplaced();
612
613 if( fieldsAutoplaced == AUTOPLACE_AUTO || fieldsAutoplaced == AUTOPLACE_MANUAL )
614 m_currentLabel->AutoplaceFields( m_Parent->GetScreen(), fieldsAutoplaced );
615
616 if( !commit.Empty() )
617 {
618 commit.Push( _( "Edit Label Properties" ) );
619 }
620 else if( m_activeTextEntry && m_labelList )
621 {
622 text = m_activeTextEntry->GetValue();
623 // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
624 text.Replace( wxS( "\r" ), wxS( "\n" ) );
625 wxArrayString lines = wxSplit( text, '\n' );
626
627 for( const wxString& line : lines )
628 {
629 text = EscapeString( line, CTX_NETNAME );
630 text.Trim( false ).Trim( true );
631
632 if( text.empty() )
633 continue;
634
635 // convert any text variable cross-references to their UUIDs
636 text = m_currentLabel->Schematic()->ConvertRefsToKIIDs( text );
637
638 switch ( m_currentLabel->Type() )
639 {
641 {
642 SCH_GLOBALLABEL* label = new SCH_GLOBALLABEL( *static_cast<SCH_GLOBALLABEL*>( m_currentLabel ) );
643 label->SetText( text );
644 m_labelList->push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
645 break;
646 }
647 case SCH_HIER_LABEL_T:
648 {
649 SCH_HIERLABEL* label = new SCH_HIERLABEL( *static_cast<SCH_HIERLABEL*>( m_currentLabel ) );
650 label->SetText( text );
651 m_labelList->push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
652 break;
653 }
654 case SCH_LABEL_T:
655 {
656 SCH_LABEL* label = new SCH_LABEL( *static_cast<SCH_LABEL*>( m_currentLabel ) );
657 label->SetText( text );
658 m_labelList->push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
659 break;
660 }
661 default:
662 break;
663 }
664 }
665 }
666 else if( m_labelList && m_currentLabel->Type() == SCH_DIRECTIVE_LABEL_T )
667 {
669 m_labelList->push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
670 }
671
672 return true;
673}
674
675
676void DIALOG_LABEL_PROPERTIES::onSpinButton( wxCommandEvent& aEvent )
677{
678 for( BITMAP_BUTTON* btn : { m_spin0, m_spin1, m_spin2, m_spin3 } )
679 {
680 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
681 btn->Check( false );
682 }
683}
684
685
686void DIALOG_LABEL_PROPERTIES::OnFormattingHelp( wxHyperlinkEvent& aEvent )
687{
689}
690
691
692void DIALOG_LABEL_PROPERTIES::OnAddField( wxCommandEvent& event )
693{
694 m_grid->OnAddRow(
695 [&]() -> std::pair<int, int>
696 {
697 wxString fieldName = wxT( "Netclass" );
698
699 for( SCH_FIELD& field : *m_fields )
700 {
701 if( field.GetId() != FIELD_T::INTERSHEET_REFS && field.GetName() != wxT( "Netclass" ) )
702 {
703 fieldName = wxEmptyString;
704 break;
705 }
706 }
707
708 fieldName = SCH_LABEL_BASE::GetDefaultFieldName( fieldName, true );
709
710 SCH_FIELD newField( m_currentLabel, FIELD_T::USER, fieldName );
711
712 if( m_fields->size() > 0 )
713 {
714 // SetAttributes() also covers text angle, size, italic and bold
715 newField.SetAttributes( m_fields->at( m_fields->size() - 1 ) );
716 newField.SetVisible( m_fields->at( m_fields->size() - 1 ).IsVisible() );
717 }
718 else
719 {
720 newField.SetVisible( true );
721 newField.SetItalic( true );
722 }
723
724 m_fields->push_back( newField );
725
726 // notify the grid
727 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
728 m_grid->ProcessTableMessage( msg );
729 return { m_fields->size() - 1, FDC_NAME };
730 } );
731}
732
733
734void DIALOG_LABEL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
735{
736 m_grid->OnDeleteRows(
737 [&]( int row )
738 {
739 if( row < m_currentLabel->GetMandatoryFieldCount() )
740 {
741 DisplayError( this, _( "The first field is mandatory." ) );
742 return false;
743 }
744
745 return true;
746 },
747 [&]( int row )
748 {
749 m_fields->erase( m_fields->begin() + row );
750
751 // notify the grid
752 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
753 m_grid->ProcessTableMessage( msg );
754 } );
755}
756
757
758void DIALOG_LABEL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
759{
760 m_grid->OnMoveRowUp(
761 [&]( int row )
762 {
763 return row > m_currentLabel->GetMandatoryFieldCount();
764 },
765 [&]( int row )
766 {
767 std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row - 1 ) );
768 m_grid->ForceRefresh();
769 } );
770}
771
772
773void DIALOG_LABEL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
774{
775 m_grid->OnMoveRowUp(
776 [&]( int row )
777 {
778 return row >= m_currentLabel->GetMandatoryFieldCount();
779 },
780 [&]( int row )
781 {
782 std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row + 1 ) );
783 m_grid->ForceRefresh();
784 } );
785}
786
787
788void DIALOG_LABEL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
789{
790 std::bitset<64> shownColumns = m_grid->GetShownColumns();
791
792 if( shownColumns != m_shownColumns )
793 {
794 m_shownColumns = shownColumns;
795
796 if( !m_grid->IsCellEditControlShown() )
797 m_grid->SetGridWidthsDirty();
798 }
799
800 // Handle a delayed focus
801 if( m_delayedFocusRow >= 0 && m_delayedFocusRow < m_grid->GetNumberRows() )
802 {
803 m_grid->SetFocus();
804 m_grid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
806 }
807
810}
811
812
814{
815 bool multiLine = m_multilineAllowed && m_cbMultiLine->IsChecked();
816
817 if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T || m_currentLabel->Type() == SCH_LABEL_T )
818 {
819 m_labelCombo->Show( !multiLine );
820 m_valueCombo->Show( !multiLine );
821 m_labelMultiLine->Show( multiLine );
822 m_valueMultiLine->Show( multiLine );
823
824 if( multiLine )
825 {
826 m_valueMultiLine->SetValue( m_valueCombo->GetValue() );
829 }
830 else
831 {
832 wxString multiText = m_valueMultiLine->GetValue();
833 m_valueCombo->SetValue( multiText.BeforeFirst( '\n' ) );
835 SetInitialFocus( m_valueCombo->GetTextCtrl() );
836 }
837 }
838 else if( m_currentLabel->Type() == SCH_HIER_LABEL_T )
839 {
840 m_labelSingleLine->Show( !multiLine );
841 m_valueSingleLine->Show( !multiLine );
842 m_labelMultiLine->Show( multiLine );
843 m_valueMultiLine->Show( multiLine );
844
845 if( multiLine )
846 {
847 m_valueMultiLine->SetValue( m_valueSingleLine->GetValue() );
850 }
851 else
852 {
853 wxString multiText = m_valueMultiLine->GetValue();
854 m_valueSingleLine->SetValue( multiText.BeforeFirst( '\n' ) );
857 }
858 }
859
860 Layout();
861}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
@ text_align_right
@ label_align_bottom
@ text_align_left
@ label_align_right
@ label_align_top
@ pinorient_right
@ label_align_left
@ text_align_bottom
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:399
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
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...
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:441
void Offset(const VECTOR2I &aOffset)
Definition eda_text.cpp:602
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:200
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:394
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:203
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:278
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition eda_text.cpp:315
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
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:728
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
Schematic symbol object.
Definition sch_symbol.h:76
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:230
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:177
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
#define UNIMPLEMENTED_FOR(type)
Definition macros.h:96
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
std::vector< FAB_LAYER_COLOR > dummy
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_SHEET_PIN_T
Definition typeinfo.h:178
@ 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