KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
panel_setup_netclasses.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) 2004-2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2009 Dick Hollenbeck, dick@softplc.com
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
26#include <algorithm>
27#include <limits>
28
29#include <pgm_base.h>
30#include <eda_draw_frame.h>
31#include <bitmaps.h>
32#include <netclass.h>
33#include <gal/painter.h>
34#include <grid_tricks.h>
36#include <tool/tool_manager.h>
37#include <pcb_painter.h>
39#include <string_utils.h>
40#include <view/view.h>
44#include <widgets/wx_panel.h>
47#include <confirm.h>
48
49
50// columns of netclasses grid
51enum
52{
54
65
71
73};
74
75std::vector<BITMAPS> g_lineStyleIcons;
76wxArrayString g_lineStyleNames;
77
78
80 std::shared_ptr<NET_SETTINGS> aNetSettings,
81 const std::set<wxString>& aNetNames,
82 bool aIsEEschema ) :
83 PANEL_SETUP_NETCLASSES_BASE( aParentWindow ),
84 m_frame( aFrame ),
85 m_isEEschema( aIsEEschema ),
86 m_netSettings( std::move( aNetSettings ) ),
87 m_netNames( aNetNames ),
88 m_lastCheckedTicker( 0 ),
89 m_hoveredCol( -1 ),
90 m_lastNetclassGridWidth( -1 )
91{
92 // Clear and re-load each time. Language (or darkmode) might have changed.
93 g_lineStyleIcons.clear();
94 g_lineStyleNames.clear();
95
96 g_lineStyleIcons.push_back( BITMAPS::stroke_none );
97 g_lineStyleNames.push_back( _( "<Not defined>" ) );
98 g_lineStyleIcons.push_back( BITMAPS::stroke_solid );
99 g_lineStyleNames.push_back( _( "Solid" ) );
100 g_lineStyleIcons.push_back( BITMAPS::stroke_dash );
101 g_lineStyleNames.push_back( _( "Dashed" ) );
102 g_lineStyleIcons.push_back( BITMAPS::stroke_dot );
103 g_lineStyleNames.push_back( _( "Dotted" ) );
104 g_lineStyleIcons.push_back( BITMAPS::stroke_dashdot );
105 g_lineStyleNames.push_back( _( "Dash-Dot" ) );
106 g_lineStyleIcons.push_back( BITMAPS::stroke_dashdotdot );
107 g_lineStyleNames.push_back( _( "Dash-Dot-Dot" ) );
108
109 m_netclassesDirty = true;
110
111 m_schUnitsProvider = std::make_unique<UNITS_PROVIDER>( schIUScale, m_frame->GetUserUnits() );
112 m_pcbUnitsProvider = std::make_unique<UNITS_PROVIDER>( pcbIUScale, m_frame->GetUserUnits() );
113
114 m_netclassesPane->SetBorders( true, false, false, false );
115 m_membershipPane->SetBorders( true, false, false, false );
116
117 // Prevent Size events from firing before we are ready
118 Freeze();
119 m_netclassGrid->BeginBatch();
120 m_netclassGrid->SetUseNativeColLabels();
121 m_assignmentGrid->BeginBatch();
122 m_assignmentGrid->SetUseNativeColLabels();
123
124 m_splitter->SetMinimumPaneSize( FromDIP( m_splitter->GetMinimumPaneSize() ) );
125
126 wxASSERT( m_netclassGrid->GetNumberCols() == GRID_END );
127
128 // Calculate a min best size to handle longest usual numeric values:
129 int const min_best_width = m_netclassGrid->GetTextExtent( "555,555555 mils" ).x;
130
131 for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
132 {
133 // We calculate the column min size only from texts sizes, not using the initial col width
134 // as this initial width is sometimes strange depending on the language (wxGrid bug?)
135 int const min_width = m_netclassGrid->GetVisibleWidth( i, true, true );
136
137 int const weighted_min_best_width = ( i == GRID_LINESTYLE ) ? min_best_width * 3 / 2
138 : min_best_width;
139
140 // We use a "best size" >= min_best_width
141 m_originalColWidths[ i ] = std::max( min_width, weighted_min_best_width );
142 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
143
144 if( i >= GRID_FIRST_EESCHEMA )
146 else
148 }
149
151
152 if( m_isEEschema )
154 else
156
158
159 wxGridCellAttr* attr = new wxGridCellAttr;
160 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
161 attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ),
162 m_netclassGrid ) );
163 m_netclassGrid->SetColAttr( GRID_SCHEMATIC_COLOR, attr );
164
165 attr = new wxGridCellAttr;
166 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
167 attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ),
168 m_netclassGrid ) );
169 m_netclassGrid->SetColAttr( GRID_PCB_COLOR, attr );
170
171 attr = new wxGridCellAttr;
174 m_netclassGrid->SetColAttr( GRID_LINESTYLE, attr );
175
176 if( m_isEEschema )
177 {
178 m_importColorsButton->Hide();
179 }
180 else
181 {
182 m_colorDefaultHelpText->SetLabel(
183 _( "Set color to transparent to use layer default color." ) );
184 m_colorDefaultHelpText->GetParent()->Layout();
185 }
186
187 m_colorDefaultHelpText->SetFont( KIUI::GetInfoFont( this ).Italic() );
188
199
200
201 // Be sure the column labels are readable
203
204 // Membership combobox editors require a bit more room, so increase the row size of
205 // all our grids for consistency
206 m_netclassGrid->SetDefaultRowSize( m_netclassGrid->GetDefaultRowSize() + 4 );
207 m_assignmentGrid->SetDefaultRowSize( m_assignmentGrid->GetDefaultRowSize() + 4 );
208
209 m_netclassGrid->PushEventHandler( new GRID_TRICKS( m_netclassGrid ) );
210 m_assignmentGrid->PushEventHandler( new GRID_TRICKS( m_assignmentGrid ) );
211
212 m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
213 m_assignmentGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
214
215 m_splitter->SetSashPosition( cfg->m_NetclassPanel.sash_pos );
216
217 m_addButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
218 m_removeButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
219
220 m_addAssignmentButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
221 m_removeAssignmentButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
222
223 m_moveUpButton->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
224 m_moveDownButton->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
225
226 // wxFormBuilder doesn't include this event...
227 m_netclassGrid->Connect( wxEVT_GRID_CELL_CHANGING,
229 nullptr, this );
230
231 // Handle tooltips for grid
232 m_netclassGrid->GetGridColLabelWindow()->Bind( wxEVT_MOTION,
234 this );
235
236 m_frame->Bind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
237
238 m_netclassGrid->EndBatch();
239 m_assignmentGrid->EndBatch();
240 Thaw();
241
242 Bind( wxEVT_IDLE,
243 [this]( wxIdleEvent& aEvent )
244 {
245 // Careful of consuming CPU in an idle event handler. Check the ticker first to
246 // see if there's even a possibility of the netclasses having changed.
248 {
249 wxWindow* dialog = wxGetTopLevelParent( this );
250 wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
251
252 if( topLevelFocus == dialog && m_lastLoaded != m_netSettings->GetNetclasses() )
253 checkReload();
254 }
255 } );
256
257 m_matchingNets->SetFont( KIUI::GetInfoFont( this ) );
258}
259
260
262{
264 cfg->m_NetclassPanel.sash_pos = m_splitter->GetSashPosition();
265
266 if( m_isEEschema )
268 else
270
271 // Delete the GRID_TRICKS.
272 m_netclassGrid->PopEventHandler( true );
273 m_assignmentGrid->PopEventHandler( true );
274
275 m_netclassGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
277 nullptr, this );
278
279 m_frame->Unbind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
280}
281
282
284{
285 auto netclassToGridRow =
286 [&]( int aRow, const NETCLASS* nc )
287 {
288 m_netclassGrid->SetCellValue( aRow, GRID_NAME, nc->GetName() );
289
291 nc->GetWireWidthOpt() );
293 nc->GetBusWidthOpt() );
294
295 wxString colorAsString = nc->GetSchematicColor().ToCSSString();
296 m_netclassGrid->SetCellValue( aRow, GRID_SCHEMATIC_COLOR, colorAsString );
297
298 if( nc->HasLineStyle() )
299 {
300 int lineStyleIdx = std::max( 0, nc->GetLineStyle() );
301
302 if( lineStyleIdx >= (int) g_lineStyleNames.size() + 1 )
303 lineStyleIdx = 0;
304
305 m_netclassGrid->SetCellValue( aRow, GRID_LINESTYLE,
306 g_lineStyleNames[lineStyleIdx + 1] );
307 }
308 else
309 {
310 // <Not defined> line style in list.
311 m_netclassGrid->SetCellValue( aRow, GRID_LINESTYLE,
312 g_lineStyleNames[0] );
313 }
314
315 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_CLEARANCE, nc->GetClearanceOpt() );
317 nc->GetTrackWidthOpt() );
318 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_VIASIZE, nc->GetViaDiameterOpt() );
319 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_VIADRILL, nc->GetViaDrillOpt() );
321 nc->GetuViaDiameterOpt() );
322 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_uVIADRILL, nc->GetuViaDrillOpt() );
324 nc->GetDiffPairWidthOpt() );
326 nc->GetDiffPairGapOpt() );
327
328 colorAsString = nc->GetPcbColor().ToCSSString();
329 m_netclassGrid->SetCellValue( aRow, GRID_PCB_COLOR, colorAsString );
330
331 if( nc->IsDefault() )
332 {
333 m_netclassGrid->SetReadOnly( aRow, GRID_NAME );
334 m_netclassGrid->SetReadOnly( aRow, GRID_PCB_COLOR );
335 m_netclassGrid->SetReadOnly( aRow, GRID_SCHEMATIC_COLOR );
336 m_netclassGrid->SetReadOnly( aRow, GRID_LINESTYLE );
337 }
338
339 setNetclassRowNullableEditors( aRow, nc->IsDefault() );
340 };
341
342 // Get the netclasses sorted by priority
343 std::vector<const NETCLASS*> netclasses;
344 netclasses.reserve( m_netSettings->GetNetclasses().size() );
345
346 for( const auto& [name, netclass] : m_netSettings->GetNetclasses() )
347 netclasses.push_back( netclass.get() );
348
349 std::sort( netclasses.begin(), netclasses.end(),
350 []( const NETCLASS* nc1, const NETCLASS* nc2 )
351 {
352 return nc1->GetPriority() < nc2->GetPriority();
353 } );
354
355 // Enter user-defined netclasses
357 m_netclassGrid->AppendRows( static_cast<int>( netclasses.size() ) );
358
359 int row = 0;
360
361 for( const NETCLASS* nc : netclasses )
362 netclassToGridRow( row++, nc );
363
364 // Enter the Default netclass.
365 m_netclassGrid->AppendRows( 1 );
366 netclassToGridRow( row, m_netSettings->GetDefaultNetclass().get() );
367
369 m_assignmentGrid->AppendRows( m_netSettings->GetNetclassPatternAssignments().size() );
370
371 row = 0;
372
373 for( const auto& [matcher, netclassName] : m_netSettings->GetNetclassPatternAssignments() )
374 {
375 m_assignmentGrid->SetCellValue( row, 0, matcher->GetPattern() );
376 m_assignmentGrid->SetCellValue( row, 1, netclassName );
377 row++;
378 }
379}
380
381
383{
384 // Set nullable editors
385 auto setCellEditor = [this, aRowId, aIsDefault]( int aCol )
386 {
387 GRID_CELL_MARK_AS_NULLABLE* cellEditor;
388
389 if( aIsDefault )
390 cellEditor = new GRID_CELL_MARK_AS_NULLABLE( false );
391 else
392 cellEditor = new GRID_CELL_MARK_AS_NULLABLE( true );
393
394 wxGridCellAttr* attr = m_netclassGrid->GetOrCreateCellAttr( aRowId, aCol );
395 attr->SetEditor( cellEditor );
396 attr->DecRef();
397 };
398
399 setCellEditor( GRID_WIREWIDTH );
400 setCellEditor( GRID_BUSWIDTH );
401 setCellEditor( GRID_CLEARANCE );
402 setCellEditor( GRID_TRACKSIZE );
403 setCellEditor( GRID_VIASIZE );
404 setCellEditor( GRID_VIADRILL );
405 setCellEditor( GRID_VIADRILL );
406 setCellEditor( GRID_uVIASIZE );
407 setCellEditor( GRID_uVIADRILL );
408 setCellEditor( GRID_DIFF_PAIR_WIDTH );
409 setCellEditor( GRID_DIFF_PAIR_GAP );
410}
411
412
414{
415 // MUST update the ticker before calling IsOK (or we'll end up re-entering through the idle
416 // event until we crash the stack).
418
419 if( IsOK( m_parent, _( "The netclasses have been changed outside the Setup dialog.\n"
420 "Do you wish to reload them?" ) ) )
421 {
422 m_lastLoaded = m_netSettings->GetNetclasses();
424 }
425}
426
427
428void PANEL_SETUP_NETCLASSES::onUnitsChanged( wxCommandEvent& aEvent )
429{
430 std::shared_ptr<NET_SETTINGS> tempNetSettings = std::make_shared<NET_SETTINGS>( nullptr, "" );
431 std::shared_ptr<NET_SETTINGS> saveNetSettings = m_netSettings;
432
433 m_netSettings = tempNetSettings;
434
436
437 m_schUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
438 m_pcbUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
439
441
442 m_netSettings = saveNetSettings;
443
444 aEvent.Skip();
445}
446
447
449{
450 m_lastLoaded = m_netSettings->GetNetclasses();
452
454 AdjustAssignmentGridColumns( GetSize().x * 3 / 5 );
455
456 return true;
457}
458
459
461{
463
464 wxArrayString netclassNames;
465
466 for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
467 {
468 wxString netclassName = m_netclassGrid->GetCellValue( ii, GRID_NAME );
469
470 if( !netclassName.IsEmpty() )
471 netclassNames.push_back( netclassName );
472 }
473
474 wxGridCellAttr* attr = new wxGridCellAttr;
475 attr->SetEditor( new wxGridCellChoiceEditor( netclassNames ) );
476 m_assignmentGrid->SetColAttr( 1, attr );
477}
478
479
481{
482 if( !Validate() )
483 return false;
484
485 auto gridRowToNetclass =
486 [&]( int aRow, const std::shared_ptr<NETCLASS>& nc )
487 {
488 if( nc->IsDefault() )
489 nc->SetPriority( std::numeric_limits<int>::max() );
490 else
491 nc->SetPriority( aRow );
492
493 nc->SetName( m_netclassGrid->GetCellValue( aRow, GRID_NAME ) );
494
495 nc->SetWireWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_WIREWIDTH ) );
496 nc->SetBusWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_BUSWIDTH ) );
497
498 wxString lineStyle = m_netclassGrid->GetCellValue( aRow, GRID_LINESTYLE );
499 int lineIdx = g_lineStyleNames.Index( lineStyle );
500
501 if( lineIdx == 0 )
502 nc->SetLineStyle( std::optional<int>() );
503 else
504 nc->SetLineStyle( lineIdx - 1 );
505
506 wxASSERT_MSG( lineIdx >= 0, "Line style name not found." );
507
508 // clang-format off
509 nc->SetClearance( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_CLEARANCE ) );
510 nc->SetTrackWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_TRACKSIZE ) );
511 nc->SetViaDiameter( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_VIASIZE ) );
512 nc->SetViaDrill( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_VIADRILL ) );
513 nc->SetuViaDiameter( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_uVIASIZE ) );
514 nc->SetuViaDrill( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_uVIADRILL ) );
515 nc->SetDiffPairWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_DIFF_PAIR_WIDTH ) );
516 nc->SetDiffPairGap( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_DIFF_PAIR_GAP ) );
517 // clang-format on
518
519 if( !nc->IsDefault() )
520 {
521 wxString color = m_netclassGrid->GetCellValue( aRow, GRID_PCB_COLOR );
522 KIGFX::COLOR4D newPcbColor( color );
523
524 if( newPcbColor != KIGFX::COLOR4D::UNSPECIFIED )
525 nc->SetPcbColor( newPcbColor );
526
527 color = m_netclassGrid->GetCellValue( aRow, GRID_SCHEMATIC_COLOR );
528 KIGFX::COLOR4D newSchematicColor( color );
529
530 if( newSchematicColor != KIGFX::COLOR4D::UNSPECIFIED )
531 nc->SetSchematicColor( newSchematicColor );
532 }
533 };
534
535 m_netSettings->ClearNetclasses();
536
537 // Copy the default NetClass:
538 gridRowToNetclass( m_netclassGrid->GetNumberRows() - 1, m_netSettings->GetDefaultNetclass() );
539
540 // Copy other NetClasses:
541 for( int row = 0; row < m_netclassGrid->GetNumberRows() - 1; ++row )
542 {
543 auto nc =
544 std::make_shared<NETCLASS>( m_netclassGrid->GetCellValue( row, GRID_NAME ), false );
545 gridRowToNetclass( row, nc );
546 m_netSettings->SetNetclass( nc->GetName(), nc );
547 }
548
549 m_netSettings->ClearNetclassPatternAssignments();
550 m_netSettings->ClearAllCaches();
551
552 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
553 {
554 wxString pattern = m_assignmentGrid->GetCellValue( row, 0 );
555 wxString netclass = m_assignmentGrid->GetCellValue( row, 1 );
556
557 m_netSettings->SetNetclassPatternAssignment( pattern, netclass );
558 }
559
560 return true;
561}
562
563
564bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aName,
565 bool focusFirst )
566{
567 wxString tmp = aName;
568
569 tmp.Trim( true );
570 tmp.Trim( false );
571
572 if( tmp.IsEmpty() )
573 {
574 wxString msg = _( "Netclass must have a name." );
575 PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME );
576 return false;
577 }
578
579 for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
580 {
581 if( ii != aRow && m_netclassGrid->GetCellValue( ii, GRID_NAME ).CmpNoCase( tmp ) == 0 )
582 {
583 wxString msg = _( "Netclass name already in use." );
585 focusFirst ? aRow : ii, GRID_NAME );
586 return false;
587 }
588 }
589
590 return true;
591}
592
593
595{
596 // Clip clearance. This is not a nag; we can end up with overflow errors and very poor
597 // performance if the clearance is too large.
598
599 std::optional<int> clearance = m_netclassGrid->GetOptionalUnitValue( aRow, GRID_CLEARANCE );
600
601 if( clearance.has_value() && clearance.value() > MAXIMUM_CLEARANCE )
602 {
603 wxString msg = wxString::Format( _( "Clearance was too large. It has been clipped to %s." ),
607 return false;
608 }
609
610 return true;
611}
612
613
615{
616 if( event.GetCol() == GRID_NAME )
617 {
618 if( validateNetclassName( event.GetRow(), event.GetString() ) )
619 {
620 wxString oldName = m_netclassGrid->GetCellValue( event.GetRow(), GRID_NAME );
621 wxString newName = event.GetString();
622
623 if( !oldName.IsEmpty() )
624 {
625 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
626 {
627 if( m_assignmentGrid->GetCellValue( row, 1 ) == oldName )
628 m_assignmentGrid->SetCellValue( row, 1, newName );
629 }
630 }
631
632 m_netclassesDirty = true;
633 }
634 else
635 {
636 event.Veto();
637 }
638 }
639 else if( event.GetCol() == GRID_CLEARANCE )
640 {
641 validateNetclassClearance( event.GetRow() );
642 }
643}
644
645
647{
648 int col = m_netclassGrid->XToCol( aEvent.GetPosition().x );
649
650 if( aEvent.Moving() || aEvent.Entering() )
651 {
652 aEvent.Skip();
653
654 if( col == wxNOT_FOUND )
655 {
656 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
657 return;
658 }
659
660 if( col == m_hoveredCol )
661 return;
662
663 m_hoveredCol = col;
664
665 wxString tip;
666
667 switch( col )
668 {
669 case GRID_CLEARANCE: tip = _( "Minimum copper clearance" ); break;
670 case GRID_TRACKSIZE: tip = _( "Minimum track width" ); break;
671 case GRID_VIASIZE: tip = _( "Via pad diameter" ); break;
672 case GRID_VIADRILL: tip = _( "Via plated hole diameter" ); break;
673 case GRID_uVIASIZE: tip = _( "Microvia pad diameter" ); break;
674 case GRID_uVIADRILL: tip = _( "Microvia plated hole diameter" ); break;
675 case GRID_DIFF_PAIR_WIDTH: tip = _( "Differential pair track width" ); break;
676 case GRID_DIFF_PAIR_GAP: tip = _( "Differential pair gap" ); break;
677 case GRID_WIREWIDTH: tip = _( "Schematic wire thickness" ); break;
678 case GRID_BUSWIDTH: tip = _( "Bus wire thickness" ); break;
679 case GRID_SCHEMATIC_COLOR: tip = _( "Schematic wire color" ); break;
680 case GRID_LINESTYLE: tip = _( "Schematic wire line style" ); break;
681 case GRID_PCB_COLOR: tip = _( "PCB netclass color" ); break;
682 }
683
684 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
685 m_netclassGrid->GetGridColLabelWindow()->SetToolTip( tip );
686 }
687 else if( aEvent.Leaving() )
688 {
689 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
690 aEvent.Skip();
691 }
692
693 aEvent.Skip();
694}
695
696
698{
700 return;
701
702 m_netclassGrid->InsertRows();
703
704 // Set defaults where required
705 wxString colorAsString = KIGFX::COLOR4D::UNSPECIFIED.ToCSSString();
706 m_netclassGrid->SetCellValue( 0, GRID_PCB_COLOR, colorAsString );
707 m_netclassGrid->SetCellValue( 0, GRID_SCHEMATIC_COLOR, colorAsString );
708 m_netclassGrid->SetCellValue( 0, GRID_LINESTYLE, g_lineStyleNames[0] );
709
710 // Set the row nullable editors
712
713 m_netclassGrid->MakeCellVisible( 0, 0 );
714 m_netclassGrid->SetGridCursor( 0, 0 );
715
716 m_netclassGrid->EnableCellEditControl( true );
717 m_netclassGrid->ShowCellEditControl();
718
719 m_netclassesDirty = true;
720}
721
722
724{
726 return;
727
728 int curRow = m_netclassGrid->GetGridCursorRow();
729
730 if( curRow < 0 )
731 {
732 return;
733 }
734 else if( curRow == m_netclassGrid->GetNumberRows() - 1 )
735 {
736 wxWindow* topLevelParent = wxGetTopLevelParent( this );
737
738 DisplayErrorMessage( topLevelParent, _( "The default net class is required." ) );
739 return;
740 }
741
742 // reset the net class to default for members of the removed class
743 wxString classname = m_netclassGrid->GetCellValue( curRow, GRID_NAME );
744
745 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
746 {
747 if( m_assignmentGrid->GetCellValue( row, 1 ) == classname )
748 m_assignmentGrid->SetCellValue( row, 1, NETCLASS::Default );
749 }
750
751 m_netclassGrid->DeleteRows( curRow, 1 );
752
753 m_netclassGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
754 m_netclassGrid->SetGridCursor( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
755
756 m_netclassesDirty = true;
757}
758
759
761{
762 if( aWidth != m_lastNetclassGridWidth )
763 {
765
766 // Account for scroll bars
767 aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x );
768
769 for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
770 {
771 if( m_netclassGrid->GetColSize( i ) > 0 )
772 {
773 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
774 aWidth -= m_originalColWidths[ i ];
775 }
776 }
777
778 m_netclassGrid->SetColSize( 0, std::max( aWidth - 2, m_originalColWidths[ 0 ] ) );
779 }
780}
781
782
784{
785 AdjustNetclassGridColumns( event.GetSize().GetX() );
786
787 event.Skip();
788}
789
790
792{
794 return;
795
796 int row = m_assignmentGrid->GetNumberRows();
797 m_assignmentGrid->AppendRows();
798
799 m_assignmentGrid->SetCellValue( row, 1, m_netSettings->GetDefaultNetclass()->GetName() );
800
801 m_assignmentGrid->MakeCellVisible( row, 0 );
802 m_assignmentGrid->SetGridCursor( row, 0 );
803
804 m_assignmentGrid->EnableCellEditControl( true );
805 m_assignmentGrid->ShowCellEditControl();
806}
807
808
810{
812 return;
813
814 int curRow = m_assignmentGrid->GetGridCursorRow();
815
816 if( curRow < 0 )
817 return;
818
819 m_assignmentGrid->DeleteRows( curRow, 1 );
820
821 if( m_assignmentGrid->GetNumberRows() > 0 )
822 {
823 m_assignmentGrid->MakeCellVisible( std::max( 0, curRow-1 ), 0 );
824 m_assignmentGrid->SetGridCursor( std::max( 0, curRow-1 ), 0 );
825 }
826}
827
828
830{
831 const std::map<wxString, std::shared_ptr<NETCLASS>>& netclasses =
832 m_netSettings->GetNetclasses();
833
834 for( int row = 0; row < m_netclassGrid->GetNumberRows() - 1; ++row )
835 {
836 wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
837
838 if( netclasses.find( netclassName ) != netclasses.end() )
839 {
840 const KIGFX::COLOR4D ncColor = netclasses.at( netclassName )->GetSchematicColor();
841 m_netclassGrid->SetCellValue( row, GRID_PCB_COLOR, ncColor.ToCSSString() );
842 }
843 }
844}
845
846
848{
849 // Account for scroll bars
850 aWidth -= ( m_assignmentGrid->GetSize().x - m_assignmentGrid->GetClientSize().x );
851
852 int classNameWidth = 160;
853 m_assignmentGrid->SetColSize( 1, classNameWidth );
854 m_assignmentGrid->SetColSize( 0, std::max( aWidth - classNameWidth, classNameWidth ) );
855}
856
857
859{
860 AdjustAssignmentGridColumns( event.GetSize().GetX() );
861
862 event.Skip();
863}
864
865
866void PANEL_SETUP_NETCLASSES::OnUpdateUI( wxUpdateUIEvent& event )
867{
869 {
871 m_netclassesDirty = false;
872 }
873
875 {
876 AdjustNetclassGridColumns( GetSize().x - 1 );
878 }
879
880 if( m_assignmentGrid->GetNumberRows() == 0 )
881 return;
882
883 wxString pattern;
884 int row = m_assignmentGrid->GetGridCursorRow();
885 int col = m_assignmentGrid->GetGridCursorCol();
886
887 if( row >= 0 )
888 pattern = m_assignmentGrid->GetCellValue( row, 0 );
889
890 if( col == 0 && m_assignmentGrid->IsCellEditControlShown() )
891 {
892 wxGridCellEditor* cellEditor = m_assignmentGrid->GetCellEditor( row, 0 );
893
894 if( wxTextEntry* txt = dynamic_cast<wxTextEntry*>( cellEditor->GetControl() ) )
895 pattern = txt->GetValue();
896
897 cellEditor->DecRef();
898 }
899
900 if( pattern != m_lastPattern )
901 {
903
904 if( !pattern.IsEmpty() )
905 {
906 EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS );
907
908 m_matchingNets->Report( wxString::Format( _( "<b>Nets matching '%s':</b>" ),
909 pattern ) );
910
911 for( const wxString& net : m_netNames )
912 {
913 if( matcher.StartsWith( net ) )
914 m_matchingNets->Report( net );
915 }
916 }
917
919 m_lastPattern = pattern;
920 }
921}
922
923
925{
927 return false;
928
929 // Test net class parameters.
930 for( int row = 0; row < m_netclassGrid->GetNumberRows(); row++ )
931 {
932 wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
933 netclassName.Trim( true );
934 netclassName.Trim( false );
935
936 if( !validateNetclassName( row, netclassName, false ) )
937 return false;
938
939 if( !validateNetclassClearance( row ) )
940 return false;
941 }
942
943 return true;
944}
945
946
947void PANEL_SETUP_NETCLASSES::ImportSettingsFrom( const std::shared_ptr<NET_SETTINGS>& aNetSettings )
948{
949 std::shared_ptr<NET_SETTINGS> savedSettings = m_netSettings;
950
951 m_netSettings = aNetSettings;
953
955
956 m_netclassGrid->ForceRefresh();
957 m_assignmentGrid->ForceRefresh();
958
959 m_netSettings = std::move( savedSettings );
960}
961
962
964{
966 return;
967
968 // Work out which rows are selected
969 std::vector<int> selectedRows;
970
971 for( int i = 0; i < m_netclassGrid->GetNumberRows(); ++i )
972 {
973 if( m_netclassGrid->IsInSelection( i, 0 ) )
974 selectedRows.push_back( i );
975 }
976
977 // Only move one row at a time
978 if( selectedRows.size() != 1 )
979 return;
980
981 // Can't move the first netclass, nor move the Default netclass
982 if( selectedRows[0] == 0 || selectedRows[0] == ( m_netclassGrid->GetNumberRows() - 1 ) )
983 return;
984
985 int newRowId = selectedRows[0] - 1;
986 m_netclassGrid->InsertRows( newRowId );
987
988 for( int col = 0; col < m_netclassGrid->GetNumberCols(); col++ )
989 m_netclassGrid->SetCellValue( newRowId, col,
990 m_netclassGrid->GetCellValue( newRowId + 2, col ) );
991
992 // Set the row nullable editors
993 setNetclassRowNullableEditors( newRowId, false );
994
995 m_netclassGrid->DeleteRows( newRowId + 2, 1 );
996 m_netclassGrid->MakeCellVisible( newRowId, 0 );
997 m_netclassGrid->SetGridCursor( newRowId, 0 );
998
999 m_netclassesDirty = true;
1000}
1001
1002
1004{
1006 return;
1007
1008 // Work out which rows are selected
1009 std::vector<int> selectedRows;
1010
1011 for( int i = 0; i < m_netclassGrid->GetNumberRows(); ++i )
1012 {
1013 if( m_netclassGrid->IsInSelection( i, 0 ) )
1014 selectedRows.push_back( i );
1015 }
1016
1017 // Only move one row at a time
1018 if( selectedRows.size() != 1 )
1019 return;
1020
1021 // Can't move the last row down, nor move the Default netclass
1022 if( selectedRows[0] == ( m_netclassGrid->GetNumberRows() - 2 )
1023 || selectedRows[0] == ( m_netclassGrid->GetNumberRows() - 1 ) )
1024 return;
1025
1026 int newRowId = selectedRows[0] + 2;
1027 m_netclassGrid->InsertRows( newRowId );
1028
1029 for( int col = 0; col < m_netclassGrid->GetNumberCols(); col++ )
1030 {
1031 m_netclassGrid->SetCellValue( newRowId, col,
1032 m_netclassGrid->GetCellValue( newRowId - 2, col ) );
1033 }
1034
1035 m_netclassGrid->DeleteRows( newRowId - 2, 1 );
1036 m_netclassGrid->MakeCellVisible( newRowId - 1, 0 );
1037 m_netclassGrid->SetGridCursor( newRowId - 1, 0 );
1038
1039 m_netclassesDirty = true;
1040}
int color
Definition: DXF_plotter.cpp:60
const char * name
Definition: DXF_plotter.cpp:59
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition: bitmap.cpp:110
#define MAXIMUM_CLEARANCE
NETCLASS_PANEL m_NetclassPanel
bool StartsWith(const wxString &aTerm)
The base class for create windows for drawing purpose.
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
wxString ToCSSString() const
Definition: color4d.cpp:147
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:398
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:45
static const char Default[]
the name of the default NETCLASS
Definition: netclass.h:47
static PAGED_DIALOG * GetDialog(wxWindow *aWindow)
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
Class PANEL_SETUP_NETCLASSES_BASE.
void OnImportColorsClick(wxCommandEvent &event) override
std::map< int, int > m_originalColWidths
void OnUpdateUI(wxUpdateUIEvent &event) override
void OnSizeAssignmentGrid(wxSizeEvent &event) override
PANEL_SETUP_NETCLASSES(wxWindow *aParentWindow, EDA_DRAW_FRAME *aFrame, std::shared_ptr< NET_SETTINGS > aSettings, const std::set< wxString > &aNetNames, bool isEEschema)
void OnRemoveNetclassClick(wxCommandEvent &event) override
void OnRemoveAssignmentClick(wxCommandEvent &event) override
std::map< wxString, std::shared_ptr< NETCLASS > > m_lastLoaded
void ImportSettingsFrom(const std::shared_ptr< NET_SETTINGS > &aNetSettings)
void onUnitsChanged(wxCommandEvent &aEvent)
void OnNetclassGridCellChanging(wxGridEvent &event)
void setNetclassRowNullableEditors(int aRowId, bool aIsDefault)
bool validateNetclassName(int aRow, const wxString &aName, bool focusFirst=true)
std::unique_ptr< UNITS_PROVIDER > m_pcbUnitsProvider
void OnNetclassGridMouseEvent(wxMouseEvent &event)
void OnAddAssignmentClick(wxCommandEvent &event) override
void AdjustAssignmentGridColumns(int aWidth)
void OnMoveNetclassUpClick(wxCommandEvent &event) override
std::set< wxString > m_netNames
void OnAddNetclassClick(wxCommandEvent &event) override
std::unique_ptr< UNITS_PROVIDER > m_schUnitsProvider
std::bitset< 64 > m_shownColumns
void OnSizeNetclassGrid(wxSizeEvent &event) override
void AdjustNetclassGridColumns(int aWidth)
std::shared_ptr< NET_SETTINGS > m_netSettings
void OnMoveNetclassDownClick(wxCommandEvent &event) override
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:687
int GetNetclassesTicker() const
Definition: project.h:120
int GetTextVarsTicker() const
Definition: project.h:117
void SetBitmap(const wxBitmapBundle &aBmp)
EDA_UNITS GetUserUnits() const
wxString StringFromValue(double aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
Converts aValue in internal units into a united string.
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=true, bool aKeep=false)
Calculate the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:776
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:494
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition: wx_grid.cpp:747
void SetOptionalUnitValue(int aRow, int aCol, std::optional< int > aValue)
Set a unitized cell's optional value.
Definition: wx_grid.cpp:758
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition: wx_grid.cpp:817
wxString GetShownColumnsAsString()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:464
std::bitset< 64 > GetShownColumns()
Definition: wx_grid.cpp:483
std::optional< int > GetOptionalUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:726
void SetAutoEvalCols(const std::vector< int > &aCols)
Definition: wx_grid.h:128
void SetUnitsProvider(UNITS_PROVIDER *aProvider, int aCol=0)
Set a EUNITS_PROVIDER to enable use of unit- and eval-based Getters.
Definition: wx_grid.cpp:696
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:193
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:644
void Clear() override
Delete the stored messages.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
void Flush()
Build the HTML messages page.
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
Definition: wx_panel.h:39
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:249
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:194
This file is part of the common library.
#define _(s)
@ CTX_NETCLASS
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:156
STL namespace.
std::vector< BITMAPS > g_lineStyleIcons
@ GRID_FIRST_PCBNEW
@ GRID_DIFF_PAIR_GAP
@ GRID_SCHEMATIC_COLOR
@ GRID_DIFF_PAIR_WIDTH
@ GRID_FIRST_EESCHEMA
wxArrayString g_lineStyleNames
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1071
see class PGM_BASE
int clearance