KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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, [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
26#include <algorithm>
27#include <limits>
28#include <wx/wupdlock.h>
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
66
72
74};
75
76std::vector<BITMAPS> g_lineStyleIcons;
77wxArrayString g_lineStyleNames;
78
79
81 std::shared_ptr<NET_SETTINGS> aNetSettings,
82 const std::set<wxString>& aNetNames, 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 m_sortAsc( false ),
92 m_sortCol( 0 )
93{
94 // Clear and re-load each time. Language (or darkmode) might have changed.
95 g_lineStyleIcons.clear();
96 g_lineStyleNames.clear();
97
98 g_lineStyleIcons.push_back( BITMAPS::stroke_none );
99 g_lineStyleNames.push_back( _( "<Not defined>" ) );
100 g_lineStyleIcons.push_back( BITMAPS::stroke_solid );
101 g_lineStyleNames.push_back( _( "Solid" ) );
102 g_lineStyleIcons.push_back( BITMAPS::stroke_dash );
103 g_lineStyleNames.push_back( _( "Dashed" ) );
104 g_lineStyleIcons.push_back( BITMAPS::stroke_dot );
105 g_lineStyleNames.push_back( _( "Dotted" ) );
106 g_lineStyleIcons.push_back( BITMAPS::stroke_dashdot );
107 g_lineStyleNames.push_back( _( "Dash-Dot" ) );
108 g_lineStyleIcons.push_back( BITMAPS::stroke_dashdotdot );
109 g_lineStyleNames.push_back( _( "Dash-Dot-Dot" ) );
110
111 m_netclassesDirty = true;
112
113 m_schUnitsProvider = std::make_unique<UNITS_PROVIDER>( schIUScale, m_frame->GetUserUnits() );
114 m_pcbUnitsProvider = std::make_unique<UNITS_PROVIDER>( pcbIUScale, m_frame->GetUserUnits() );
115
116 m_netclassesPane->SetBorders( true, false, false, false );
117 m_membershipPane->SetBorders( true, false, false, false );
118
119 // Prevent Size events from firing before we are ready
120 wxWindowUpdateLocker updateLock( this );
121
122 m_netclassGrid->BeginBatch();
123 m_netclassGrid->SetUseNativeColLabels();
124 m_assignmentGrid->BeginBatch();
125 m_assignmentGrid->SetUseNativeColLabels();
126
127 m_splitter->SetMinimumPaneSize( FromDIP( m_splitter->GetMinimumPaneSize() ) );
128
129 wxASSERT( m_netclassGrid->GetNumberCols() == GRID_END );
130
131 // Calculate a min best size to handle longest usual numeric values:
132 int const min_best_width = m_netclassGrid->GetTextExtent( "555,555555 mils" ).x;
133
134 for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
135 {
136 // We calculate the column min size only from texts sizes, not using the initial col width
137 // as this initial width is sometimes strange depending on the language (wxGrid bug?)
138 int const min_width = m_netclassGrid->GetVisibleWidth( i, true, true );
139
140 int const weighted_min_best_width = ( i == GRID_LINESTYLE ) ? min_best_width * 3 / 2
141 : min_best_width;
142
143 // We use a "best size" >= min_best_width
144 m_originalColWidths[ i ] = std::max( min_width, weighted_min_best_width );
145 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
146
147 if( i >= GRID_FIRST_EESCHEMA )
149 else
151 }
152
154
155 if( m_isEEschema )
157 else
159
161
162 wxGridCellAttr* attr = new wxGridCellAttr;
163 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
164 attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ), m_netclassGrid ) );
165 m_netclassGrid->SetColAttr( GRID_SCHEMATIC_COLOR, attr );
166
167 attr = new wxGridCellAttr;
168 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
169 attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ), m_netclassGrid ) );
170 m_netclassGrid->SetColAttr( GRID_PCB_COLOR, attr );
171
172 attr = new wxGridCellAttr;
175 m_netclassGrid->SetColAttr( GRID_LINESTYLE, attr );
176
177 if( m_isEEschema )
178 {
179 m_importColorsButton->Hide();
180 }
181 else
182 {
183 m_colorDefaultHelpText->SetLabel( _( "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 // Be sure the column labels are readable
202
203 m_netclassGrid->PushEventHandler( new GRID_TRICKS( m_netclassGrid ) );
204 m_assignmentGrid->PushEventHandler( new GRID_TRICKS( m_assignmentGrid ) );
205
206 m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
207 m_assignmentGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
208
209 m_splitter->SetSashPosition( cfg->m_NetclassPanel.sash_pos );
210
211 m_addButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
212 m_removeButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
213
214 m_addAssignmentButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
215 m_removeAssignmentButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
216
217 m_moveUpButton->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
218 m_moveDownButton->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
219
220 // wxFormBuilder doesn't include this event...
221 m_netclassGrid->Connect( wxEVT_GRID_CELL_CHANGING,
223 nullptr, this );
224
225 // Handle tooltips for grid
226 m_netclassGrid->GetGridColLabelWindow()->Bind( wxEVT_MOTION, &PANEL_SETUP_NETCLASSES::OnNetclassGridMouseEvent,
227 this );
228
229 // Allow sorting assignments by column
230 m_assignmentGrid->Connect( wxEVT_GRID_LABEL_LEFT_CLICK,
232 nullptr, this );
233
234 m_frame->Bind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
235
236 m_netclassGrid->EndBatch();
237 m_assignmentGrid->EndBatch();
238
239 Bind( wxEVT_IDLE,
240 [this]( wxIdleEvent& aEvent )
241 {
242 // Careful of consuming CPU in an idle event handler. Check the ticker first to
243 // see if there's even a possibility of the netclasses having changed.
245 {
246 wxWindow* dialog = wxGetTopLevelParent( this );
247 wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
248
249 if( topLevelFocus == dialog && m_lastLoaded != m_netSettings->GetNetclasses() )
250 checkReload();
251 }
252 } );
253
254 m_matchingNets->SetFont( KIUI::GetInfoFont( this ) );
255}
256
257
259{
261 cfg->m_NetclassPanel.sash_pos = m_splitter->GetSashPosition();
262
263 if( m_isEEschema )
265 else
267
268 // Delete the GRID_TRICKS.
269 m_netclassGrid->PopEventHandler( true );
270 m_assignmentGrid->PopEventHandler( true );
271
272 m_netclassGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
274 nullptr, this );
275
276 m_assignmentGrid->Disconnect( wxEVT_GRID_LABEL_LEFT_CLICK,
278 nullptr, this );
279
280 m_frame->Unbind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
281}
282
283
285{
286 auto netclassToGridRow =
287 [&]( int aRow, const NETCLASS* nc )
288 {
289 m_netclassGrid->SetCellValue( aRow, GRID_NAME, nc->GetName() );
290 m_netclassGrid->SetCellValue( aRow, GRID_DELAY_PROFILE, nc->GetDelayProfile() );
291
292 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_WIREWIDTH, nc->GetWireWidthOpt() );
293 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_BUSWIDTH, 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, g_lineStyleNames[lineStyleIdx + 1] );
306 }
307 else
308 {
309 // <Not defined> line style in list.
310 m_netclassGrid->SetCellValue( aRow, GRID_LINESTYLE, g_lineStyleNames[0] );
311 }
312
313 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_CLEARANCE, nc->GetClearanceOpt() );
314 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_TRACKSIZE, nc->GetTrackWidthOpt() );
315 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_VIASIZE, nc->GetViaDiameterOpt() );
316 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_VIADRILL, nc->GetViaDrillOpt() );
317 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_uVIASIZE, nc->GetuViaDiameterOpt() );
318 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_uVIADRILL, nc->GetuViaDrillOpt() );
319 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_DIFF_PAIR_WIDTH, nc->GetDiffPairWidthOpt() );
320 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_DIFF_PAIR_GAP, nc->GetDiffPairGapOpt() );
321
322 colorAsString = nc->GetPcbColor().ToCSSString();
323 m_netclassGrid->SetCellValue( aRow, GRID_PCB_COLOR, colorAsString );
324
325 if( nc->IsDefault() )
326 {
327 m_netclassGrid->SetReadOnly( aRow, GRID_NAME );
328 m_netclassGrid->SetReadOnly( aRow, GRID_PCB_COLOR );
329 m_netclassGrid->SetReadOnly( aRow, GRID_SCHEMATIC_COLOR );
330 m_netclassGrid->SetReadOnly( aRow, GRID_LINESTYLE );
331 }
332
333 setNetclassRowNullableEditors( aRow, nc->IsDefault() );
334 };
335
336 // Get the netclasses sorted by priority
337 std::vector<const NETCLASS*> netclasses;
338 netclasses.reserve( m_netSettings->GetNetclasses().size() );
339
340 for( const auto& [name, netclass] : m_netSettings->GetNetclasses() )
341 netclasses.push_back( netclass.get() );
342
343 std::sort( netclasses.begin(), netclasses.end(),
344 []( const NETCLASS* nc1, const NETCLASS* nc2 )
345 {
346 return nc1->GetPriority() < nc2->GetPriority();
347 } );
348
349 // Enter user-defined netclasses
351 m_netclassGrid->AppendRows( static_cast<int>( netclasses.size() ) );
352
353 int row = 0;
354
355 for( const NETCLASS* nc : netclasses )
356 netclassToGridRow( row++, nc );
357
358 // Enter the Default netclass.
359 m_netclassGrid->AppendRows( 1 );
360 netclassToGridRow( row, m_netSettings->GetDefaultNetclass().get() );
361
363 m_assignmentGrid->AppendRows( m_netSettings->GetNetclassPatternAssignments().size() );
364
365 row = 0;
366
367 for( const auto& [matcher, netclassName] : m_netSettings->GetNetclassPatternAssignments() )
368 {
369 m_assignmentGrid->SetCellValue( row, 0, matcher->GetPattern() );
370 m_assignmentGrid->SetCellValue( row, 1, netclassName );
371 row++;
372 }
373}
374
375
377{
378 // Set nullable editors
379 auto setCellEditor =
380 [this, aRowId, aIsDefault]( int aCol )
381 {
382 GRID_CELL_MARK_AS_NULLABLE* cellEditor;
383
384 if( aIsDefault )
385 cellEditor = new GRID_CELL_MARK_AS_NULLABLE( false );
386 else
387 cellEditor = new GRID_CELL_MARK_AS_NULLABLE( true );
388
389 wxGridCellAttr* attr = m_netclassGrid->GetOrCreateCellAttr( aRowId, aCol );
390 attr->SetEditor( cellEditor );
391 attr->DecRef();
392 };
393
394 setCellEditor( GRID_WIREWIDTH );
395 setCellEditor( GRID_BUSWIDTH );
396 setCellEditor( GRID_CLEARANCE );
397 setCellEditor( GRID_TRACKSIZE );
398 setCellEditor( GRID_VIASIZE );
399 setCellEditor( GRID_VIADRILL );
400 setCellEditor( GRID_VIADRILL );
401 setCellEditor( GRID_uVIASIZE );
402 setCellEditor( GRID_uVIADRILL );
403 setCellEditor( GRID_DIFF_PAIR_WIDTH );
404 setCellEditor( GRID_DIFF_PAIR_GAP );
405}
406
407
409{
410 // MUST update the ticker before calling IsOK (or we'll end up re-entering through the idle
411 // event until we crash the stack).
413
414 if( IsOK( m_parent, _( "The netclasses have been changed outside the Setup dialog.\n"
415 "Do you wish to reload them?" ) ) )
416 {
417 m_lastLoaded = m_netSettings->GetNetclasses();
419 }
420}
421
422
423void PANEL_SETUP_NETCLASSES::onUnitsChanged( wxCommandEvent& aEvent )
424{
425 std::shared_ptr<NET_SETTINGS> tempNetSettings = std::make_shared<NET_SETTINGS>( nullptr, "" );
426 std::shared_ptr<NET_SETTINGS> saveNetSettings = m_netSettings;
427
428 m_netSettings = tempNetSettings;
429
431
432 m_schUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
433 m_pcbUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
434
436
437 m_netSettings = saveNetSettings;
438
439 aEvent.Skip();
440}
441
442
444{
445 m_lastLoaded = m_netSettings->GetNetclasses();
447
449 AdjustAssignmentGridColumns( GetSize().x * 3 / 5 );
450
451 return true;
452}
453
454
456{
458
459 wxArrayString netclassNames;
460
461 for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
462 {
463 wxString netclassName = m_netclassGrid->GetCellValue( ii, GRID_NAME );
464
465 if( !netclassName.IsEmpty() )
466 netclassNames.push_back( netclassName );
467 }
468
469 wxGridCellAttr* attr = new wxGridCellAttr;
470 attr->SetEditor( new wxGridCellChoiceEditor( netclassNames ) );
471 m_assignmentGrid->SetColAttr( 1, attr );
472}
473
474
476{
477 if( !Validate() )
478 return false;
479
480 auto gridRowToNetclass =
481 [&]( int aRow, const std::shared_ptr<NETCLASS>& nc )
482 {
483 if( nc->IsDefault() )
484 nc->SetPriority( std::numeric_limits<int>::max() );
485 else
486 nc->SetPriority( aRow );
487
488 nc->SetName( m_netclassGrid->GetCellValue( aRow, GRID_NAME ) );
489 nc->SetDelayProfile( m_netclassGrid->GetCellValue( aRow, GRID_DELAY_PROFILE ) );
490
491 nc->SetWireWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_WIREWIDTH ) );
492 nc->SetBusWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_BUSWIDTH ) );
493
494 wxString lineStyle = m_netclassGrid->GetCellValue( aRow, GRID_LINESTYLE );
495 int lineIdx = g_lineStyleNames.Index( lineStyle );
496
497 if( lineIdx == 0 )
498 nc->SetLineStyle( std::optional<int>() );
499 else
500 nc->SetLineStyle( lineIdx - 1 );
501
502 wxASSERT_MSG( lineIdx >= 0, "Line style name not found." );
503
504 // clang-format off
505 nc->SetClearance( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_CLEARANCE ) );
506 nc->SetTrackWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_TRACKSIZE ) );
507 nc->SetViaDiameter( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_VIASIZE ) );
508 nc->SetViaDrill( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_VIADRILL ) );
509 nc->SetuViaDiameter( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_uVIASIZE ) );
510 nc->SetuViaDrill( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_uVIADRILL ) );
511 nc->SetDiffPairWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_DIFF_PAIR_WIDTH ) );
512 nc->SetDiffPairGap( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_DIFF_PAIR_GAP ) );
513 // clang-format on
514
515 if( !nc->IsDefault() )
516 {
517 wxString color = m_netclassGrid->GetCellValue( aRow, GRID_PCB_COLOR );
518 KIGFX::COLOR4D newPcbColor( color );
519
520 if( newPcbColor != KIGFX::COLOR4D::UNSPECIFIED )
521 nc->SetPcbColor( newPcbColor );
522
523 color = m_netclassGrid->GetCellValue( aRow, GRID_SCHEMATIC_COLOR );
524 KIGFX::COLOR4D newSchematicColor( color );
525
526 if( newSchematicColor != KIGFX::COLOR4D::UNSPECIFIED )
527 nc->SetSchematicColor( newSchematicColor );
528 }
529 };
530
531 m_netSettings->ClearNetclasses();
532
533 // Copy the default NetClass:
534 gridRowToNetclass( m_netclassGrid->GetNumberRows() - 1, m_netSettings->GetDefaultNetclass() );
535
536 // Copy other NetClasses:
537 for( int row = 0; row < m_netclassGrid->GetNumberRows() - 1; ++row )
538 {
539 auto nc = std::make_shared<NETCLASS>( m_netclassGrid->GetCellValue( row, GRID_NAME ), false );
540 gridRowToNetclass( row, nc );
541 m_netSettings->SetNetclass( nc->GetName(), nc );
542 }
543
544 m_netSettings->ClearNetclassPatternAssignments();
545 m_netSettings->ClearAllCaches();
546
547 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
548 {
549 wxString pattern = m_assignmentGrid->GetCellValue( row, 0 );
550 wxString netclass = m_assignmentGrid->GetCellValue( row, 1 );
551
552 m_netSettings->SetNetclassPatternAssignment( pattern, netclass );
553 }
554
555 return true;
556}
557
558
559bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aName, bool focusFirst )
560{
561 wxString tmp = aName;
562
563 tmp.Trim( true );
564 tmp.Trim( false );
565
566 if( tmp.IsEmpty() )
567 {
568 wxString msg = _( "Netclass must have a name." );
569 PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME );
570 return false;
571 }
572
573 for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
574 {
575 if( ii != aRow && m_netclassGrid->GetCellValue( ii, GRID_NAME ).CmpNoCase( tmp ) == 0 )
576 {
577 wxString msg = _( "Netclass name already in use." );
578 PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, focusFirst ? aRow : ii,
579 GRID_NAME );
580 return false;
581 }
582 }
583
584 return true;
585}
586
587
589{
590 // Clip clearance. This is not a nag; we can end up with overflow errors and very poor
591 // performance if the clearance is too large.
592
593 std::optional<int> clearance = m_netclassGrid->GetOptionalUnitValue( aRow, GRID_CLEARANCE );
594
595 if( clearance.has_value() && clearance.value() > MAXIMUM_CLEARANCE )
596 {
597 wxString msg = wxString::Format( _( "Clearance was too large. It has been clipped to %s." ),
601 return false;
602 }
603
604 return true;
605}
606
607
609{
610 if( event.GetCol() == GRID_NAME )
611 {
612 if( validateNetclassName( event.GetRow(), event.GetString() ) )
613 {
614 wxString oldName = m_netclassGrid->GetCellValue( event.GetRow(), GRID_NAME );
615 wxString newName = event.GetString();
616
617 if( !oldName.IsEmpty() )
618 {
619 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
620 {
621 if( m_assignmentGrid->GetCellValue( row, 1 ) == oldName )
622 m_assignmentGrid->SetCellValue( row, 1, newName );
623 }
624 }
625
626 m_netclassesDirty = true;
627 }
628 else
629 {
630 event.Veto();
631 }
632 }
633 else if( event.GetCol() == GRID_CLEARANCE )
634 {
635 validateNetclassClearance( event.GetRow() );
636 }
637}
638
640{
641 event.Skip();
642
644 return;
645
646 if( ( event.GetCol() < 0 ) || ( event.GetCol() >= m_assignmentGrid->GetNumberCols() ) )
647 return;
648
649 // Toggle sort order if the same column is clicked
650 if( event.GetCol() != m_sortCol )
651 {
652 m_sortCol = event.GetCol();
653 m_sortAsc = true;
654 }
655 else
656 {
658 }
659
660 std::vector<std::pair<wxString, wxString>> netclassesassignments;
661 netclassesassignments.reserve( m_assignmentGrid->GetNumberRows() );
662
663 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
664 {
665 netclassesassignments.emplace_back( m_assignmentGrid->GetCellValue( row, 0 ),
666 m_assignmentGrid->GetCellValue( row, 1 ) );
667 }
668
669 std::sort( netclassesassignments.begin(), netclassesassignments.end(),
670 [this]( const std::pair<wxString, wxString>& assign1,
671 const std::pair<wxString, wxString>& assign2 )
672 {
673 const wxString& str1 = ( m_sortCol == 0 ) ? assign1.first : assign1.second;
674 const wxString& str2 = ( m_sortCol == 0 ) ? assign2.first : assign2.second;
675 return m_sortAsc ? ( str1 < str2 ) : ( str1 > str2 );
676 } );
677
679 m_assignmentGrid->AppendRows( netclassesassignments.size() );
680
681 int row = 0;
682
683 for( const auto& [pattern, netclassName] : netclassesassignments )
684 {
685 m_assignmentGrid->SetCellValue( row, 0, pattern );
686 m_assignmentGrid->SetCellValue( row, 1, netclassName );
687 row++;
688 }
689}
690
692{
693 int col = m_netclassGrid->XToCol( aEvent.GetPosition().x );
694
695 if( aEvent.Moving() || aEvent.Entering() )
696 {
697 aEvent.Skip();
698
699 if( col == wxNOT_FOUND )
700 {
701 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
702 return;
703 }
704
705 if( col == m_hoveredCol )
706 return;
707
708 m_hoveredCol = col;
709
710 wxString tip;
711
712 switch( col )
713 {
714 case GRID_CLEARANCE: tip = _( "Minimum copper clearance" ); break;
715 case GRID_TRACKSIZE: tip = _( "Minimum track width" ); break;
716 case GRID_VIASIZE: tip = _( "Via pad diameter" ); break;
717 case GRID_VIADRILL: tip = _( "Via plated hole diameter" ); break;
718 case GRID_uVIASIZE: tip = _( "Microvia pad diameter" ); break;
719 case GRID_uVIADRILL: tip = _( "Microvia plated hole diameter" ); break;
720 case GRID_DIFF_PAIR_WIDTH: tip = _( "Differential pair track width" ); break;
721 case GRID_DIFF_PAIR_GAP: tip = _( "Differential pair gap" ); break;
722 case GRID_WIREWIDTH: tip = _( "Schematic wire thickness" ); break;
723 case GRID_BUSWIDTH: tip = _( "Bus wire thickness" ); break;
724 case GRID_SCHEMATIC_COLOR: tip = _( "Schematic wire color" ); break;
725 case GRID_LINESTYLE: tip = _( "Schematic wire line style" ); break;
726 case GRID_PCB_COLOR: tip = _( "PCB netclass color" ); break;
727 }
728
729 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
730 m_netclassGrid->GetGridColLabelWindow()->SetToolTip( tip );
731 }
732 else if( aEvent.Leaving() )
733 {
734 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
735 aEvent.Skip();
736 }
737
738 aEvent.Skip();
739}
740
741
743{
745 [&]() -> std::pair<int, int>
746 {
747 m_netclassGrid->InsertRows();
748
749 // Set defaults where required
750 wxString colorAsString = KIGFX::COLOR4D::UNSPECIFIED.ToCSSString();
751 m_netclassGrid->SetCellValue( 0, GRID_PCB_COLOR, colorAsString );
752 m_netclassGrid->SetCellValue( 0, GRID_SCHEMATIC_COLOR, colorAsString );
753 m_netclassGrid->SetCellValue( 0, GRID_LINESTYLE, g_lineStyleNames[0] );
754
755 // Set the row nullable editors
757
758 m_netclassesDirty = true;
759 return { 0, GRID_NAME };
760 } );
761}
762
763
765{
767 [&]( int row )
768 {
769 if( row == m_netclassGrid->GetNumberRows() - 1 )
770 {
771 DisplayErrorMessage( wxGetTopLevelParent( this ), _( "The default net class is required." ) );
772 return false;
773 }
774
775 return true;
776 },
777 [&]( int row )
778 {
779 // reset the net class to default for members of the removed class
780 wxString classname = m_netclassGrid->GetCellValue( row, GRID_NAME );
781
782 for( int assignment = 0; assignment < m_assignmentGrid->GetNumberRows(); ++assignment )
783 {
784 if( m_assignmentGrid->GetCellValue( assignment, 1 ) == classname )
785 m_assignmentGrid->SetCellValue( assignment, 1, NETCLASS::Default );
786 }
787
788 m_netclassGrid->DeleteRows( row, 1 );
789 m_netclassesDirty = true;
790 } );
791}
792
793
795{
796 if( aWidth != m_lastNetclassGridWidth )
797 {
799
800 // Account for scroll bars
801 aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x );
802
803 for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
804 {
805 if( m_netclassGrid->GetColSize( i ) > 0 )
806 {
807 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
808 aWidth -= m_originalColWidths[ i ];
809 }
810 }
811
812 m_netclassGrid->SetColSize( 0, std::max( aWidth - 2, m_originalColWidths[ 0 ] ) );
813 }
814}
815
816
818{
819 AdjustNetclassGridColumns( event.GetSize().GetX() );
820
821 event.Skip();
822}
823
824
826{
828 [&]() -> std::pair<int, int>
829 {
830 int row = m_assignmentGrid->GetNumberRows();
831 m_assignmentGrid->AppendRows();
832 m_assignmentGrid->SetCellValue( row, 1, m_netSettings->GetDefaultNetclass()->GetName() );
833 return { row, 0 };
834 } );
835}
836
837
839{
841 [&]( int row )
842 {
843 m_assignmentGrid->DeleteRows( row, 1 );
844 } );
845}
846
847
849{
850 const std::map<wxString, std::shared_ptr<NETCLASS>>& netclasses =
851 m_netSettings->GetNetclasses();
852
853 for( int row = 0; row < m_netclassGrid->GetNumberRows() - 1; ++row )
854 {
855 wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
856
857 if( netclasses.find( netclassName ) != netclasses.end() )
858 {
859 const KIGFX::COLOR4D ncColor = netclasses.at( netclassName )->GetSchematicColor();
860 m_netclassGrid->SetCellValue( row, GRID_PCB_COLOR, ncColor.ToCSSString() );
861 }
862 }
863}
864
865
867{
868 // Account for scroll bars
869 aWidth -= ( m_assignmentGrid->GetSize().x - m_assignmentGrid->GetClientSize().x );
870
871 int classNameWidth = 160;
872 m_assignmentGrid->SetColSize( 1, classNameWidth );
873 m_assignmentGrid->SetColSize( 0, std::max( aWidth - classNameWidth, classNameWidth ) );
874}
875
876
878{
879 AdjustAssignmentGridColumns( event.GetSize().GetX() );
880
881 event.Skip();
882}
883
884
885void PANEL_SETUP_NETCLASSES::OnUpdateUI( wxUpdateUIEvent& event )
886{
888 {
890 m_netclassesDirty = false;
891 }
892
894 {
895 AdjustNetclassGridColumns( GetSize().x - 1 );
897 }
898
899 if( m_assignmentGrid->GetNumberRows() == 0 )
900 return;
901
902 wxString pattern;
903 int row = m_assignmentGrid->GetGridCursorRow();
904 int col = m_assignmentGrid->GetGridCursorCol();
905
906 if( row >= 0 )
907 pattern = m_assignmentGrid->GetCellValue( row, 0 );
908
909 if( col == 0 && m_assignmentGrid->IsCellEditControlShown() )
910 {
911 wxGridCellEditor* cellEditor = m_assignmentGrid->GetCellEditor( row, 0 );
912
913 if( wxTextEntry* txt = dynamic_cast<wxTextEntry*>( cellEditor->GetControl() ) )
914 pattern = txt->GetValue();
915
916 cellEditor->DecRef();
917 }
918
919 if( pattern != m_lastPattern )
920 {
922
923 if( !pattern.IsEmpty() )
924 {
925 EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS );
926
927 m_matchingNets->Report( wxString::Format( _( "<b>Nets matching '%s':</b>" ), pattern ) );
928
929 for( const wxString& net : m_netNames )
930 {
931 if( matcher.StartsWith( net ) )
932 m_matchingNets->Report( net );
933 }
934 }
935
937 m_lastPattern = pattern;
938 }
939}
940
941
943{
945 return false;
946
947 // Test net class parameters.
948 for( int row = 0; row < m_netclassGrid->GetNumberRows(); row++ )
949 {
950 wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
951 netclassName.Trim( true );
952 netclassName.Trim( false );
953
954 if( !validateNetclassName( row, netclassName, false ) )
955 return false;
956
957 if( !validateNetclassClearance( row ) )
958 return false;
959 }
960
961 return true;
962}
963
964
965void PANEL_SETUP_NETCLASSES::ImportSettingsFrom( const std::shared_ptr<NET_SETTINGS>& aNetSettings )
966{
967 std::shared_ptr<NET_SETTINGS> savedSettings = m_netSettings;
968
969 m_netSettings = aNetSettings;
971
973
974 m_netclassGrid->ForceRefresh();
975 m_assignmentGrid->ForceRefresh();
976
977 m_netSettings = std::move( savedSettings );
978}
979
980
982{
984 [&]( int row )
985 {
986 // Can't move the Default netclass
987 return row != m_netclassGrid->GetNumberRows() - 1;
988 },
989 [&]( int row )
990 {
991 m_netclassGrid->SwapRows( row, row - 1 );
992 m_netclassesDirty = true;
993 } );
994}
995
996
998{
1000 [&]( int row )
1001 {
1002 // Can't move the Default netclass
1003 return row + 1 != m_netclassGrid->GetNumberRows() - 1;
1004 },
1005 [&]( int row )
1006 {
1007 m_netclassGrid->SwapRows( row, row + 1 );
1008 m_netclassesDirty = true;
1009 } );
1010}
1011
1012
1013void PANEL_SETUP_NETCLASSES::UpdateDelayProfileNames( const std::vector<wxString>& aNames ) const
1014{
1015 wxArrayString profileNames;
1016 profileNames.push_back( wxEmptyString );
1017 std::ranges::for_each( aNames,
1018 [&]( const wxString& aName )
1019 {
1020 profileNames.push_back( aName );
1021 } );
1022
1023 wxGridCellAttr* attr = new wxGridCellAttr;
1024 attr->SetEditor( new wxGridCellChoiceEditor( profileNames, false ) );
1025 m_netclassGrid->SetColAttr( GRID_DELAY_PROFILE, attr );
1026}
int color
Definition: DXF_plotter.cpp:63
const char * name
Definition: DXF_plotter.cpp:62
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:114
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:112
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 UpdateDelayProfileNames(const std::vector< wxString > &aNames) const
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 OnNetclassAssignmentSort(wxGridEvent &event)
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:565
int GetNetclassesTicker() const
Definition: project.h:121
int GetTextVarsTicker() const
Definition: project.h:118
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:916
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 OnMoveRowUp(const std::function< void(int row)> &aMover)
Definition: wx_grid.cpp:766
void SwapRows(int aRowA, int aRowB)
These aren't that tricky, but might as well share code.
Definition: wx_grid.cpp:755
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition: wx_grid.cpp:890
void OnMoveRowDown(const std::function< void(int row)> &aMover)
Definition: wx_grid.cpp:799
void SetOptionalUnitValue(int aRow, int aCol, std::optional< int > aValue)
Set a unitized cell's optional value.
Definition: wx_grid.cpp:903
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition: wx_grid.cpp:956
void OnDeleteRows(const std::function< void(int row)> &aDeleter)
Handles a row deletion event.
Definition: wx_grid.cpp:704
wxString GetShownColumnsAsString()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:464
void OnAddRow(const std::function< std::pair< int, int >()> &aAdder)
Definition: wx_grid.cpp:684
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:872
void SetAutoEvalCols(const std::vector< int > &aCols)
Definition: wx_grid.h:145
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:832
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:220
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:632
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:251
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
@ GRID_DELAY_PROFILE
wxArrayString g_lineStyleNames
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:902
see class PGM_BASE
int clearance