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 (C) 2009-2024 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>
38#include <string_utils.h>
39#include <view/view.h>
43#include <widgets/wx_panel.h>
46#include <confirm.h>
47
48
49// columns of netclasses grid
50enum
51{
53
64
70
72};
73
74std::vector<BITMAPS> g_lineStyleIcons;
75wxArrayString g_lineStyleNames;
76
77
79 std::shared_ptr<NET_SETTINGS> aNetSettings,
80 const std::set<wxString>& aNetNames,
81 bool aIsEEschema ) :
82 PANEL_SETUP_NETCLASSES_BASE( aParentWindow ),
83 m_frame( aFrame ),
84 m_isEEschema( aIsEEschema ),
85 m_netSettings( std::move( aNetSettings ) ),
86 m_netNames( aNetNames ),
87 m_lastCheckedTicker( 0 ),
88 m_hoveredCol( -1 ),
89 m_lastNetclassGridWidth( -1 )
90{
91 // Clear and re-load each time. Language (or darkmode) might have changed.
92 g_lineStyleIcons.clear();
93 g_lineStyleNames.clear();
94
95 g_lineStyleIcons.push_back( BITMAPS::stroke_none );
96 g_lineStyleNames.push_back( _( "<Not defined>" ) );
97 g_lineStyleIcons.push_back( BITMAPS::stroke_solid );
98 g_lineStyleNames.push_back( _( "Solid" ) );
99 g_lineStyleIcons.push_back( BITMAPS::stroke_dash );
100 g_lineStyleNames.push_back( _( "Dashed" ) );
101 g_lineStyleIcons.push_back( BITMAPS::stroke_dot );
102 g_lineStyleNames.push_back( _( "Dotted" ) );
103 g_lineStyleIcons.push_back( BITMAPS::stroke_dashdot );
104 g_lineStyleNames.push_back( _( "Dash-Dot" ) );
105 g_lineStyleIcons.push_back( BITMAPS::stroke_dashdotdot );
106 g_lineStyleNames.push_back( _( "Dash-Dot-Dot" ) );
107
108 m_netclassesDirty = true;
109
110 m_schUnitsProvider = std::make_unique<UNITS_PROVIDER>( schIUScale, m_frame->GetUserUnits() );
111 m_pcbUnitsProvider = std::make_unique<UNITS_PROVIDER>( pcbIUScale, m_frame->GetUserUnits() );
112
113 m_netclassesPane->SetBorders( true, false, false, false );
114 m_membershipPane->SetBorders( true, false, false, false );
115
116 // Prevent Size events from firing before we are ready
117 Freeze();
118 m_netclassGrid->BeginBatch();
119 m_netclassGrid->SetUseNativeColLabels();
120 m_assignmentGrid->BeginBatch();
121 m_assignmentGrid->SetUseNativeColLabels();
122
123 m_splitter->SetMinimumPaneSize( FromDIP( m_splitter->GetMinimumPaneSize() ) );
124
125 wxASSERT( m_netclassGrid->GetNumberCols() == GRID_END );
126
127 // Calculate a min best size to handle longest usual numeric values:
128 int const min_best_width = m_netclassGrid->GetTextExtent( "555,555555 mils" ).x;
129
130 for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
131 {
132 // We calculate the column min size only from texts sizes, not using the initial col width
133 // as this initial width is sometimes strange depending on the language (wxGrid bug?)
134 int const min_width = m_netclassGrid->GetVisibleWidth( i, true, true );
135
136 int const weighted_min_best_width = ( i == GRID_LINESTYLE ) ? min_best_width * 3 / 2
137 : min_best_width;
138
139 // We use a "best size" >= min_best_width
140 m_originalColWidths[ i ] = std::max( min_width, weighted_min_best_width );
141 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
142
143 if( i >= GRID_FIRST_EESCHEMA )
145 else
147 }
148
150
151 if( m_isEEschema )
153 else
155
157
158 wxGridCellAttr* attr = new wxGridCellAttr;
159 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
160 attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ),
161 m_netclassGrid ) );
162 m_netclassGrid->SetColAttr( GRID_SCHEMATIC_COLOR, attr );
163
164 attr = new wxGridCellAttr;
165 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
166 attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ),
167 m_netclassGrid ) );
168 m_netclassGrid->SetColAttr( GRID_PCB_COLOR, attr );
169
170 attr = new wxGridCellAttr;
173 m_netclassGrid->SetColAttr( GRID_LINESTYLE, attr );
174
175 if( m_isEEschema )
176 {
177 m_importColorsButton->Hide();
178 }
179 else
180 {
181 m_colorDefaultHelpText->SetLabel(
182 _( "Set color to transparent to use layer default color." ) );
183 m_colorDefaultHelpText->GetParent()->Layout();
184 }
185
186 m_colorDefaultHelpText->SetFont( KIUI::GetInfoFont( this ).Italic() );
187
198
199
200 // Be sure the column labels are readable
202
203 // Membership combobox editors require a bit more room, so increase the row size of
204 // all our grids for consistency
205 m_netclassGrid->SetDefaultRowSize( m_netclassGrid->GetDefaultRowSize() + 4 );
206 m_assignmentGrid->SetDefaultRowSize( m_assignmentGrid->GetDefaultRowSize() + 4 );
207
208 m_netclassGrid->PushEventHandler( new GRID_TRICKS( m_netclassGrid ) );
209 m_assignmentGrid->PushEventHandler( new GRID_TRICKS( m_assignmentGrid ) );
210
211 m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
212 m_assignmentGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
213
214 m_splitter->SetSashPosition( cfg->m_NetclassPanel.sash_pos );
215
216 m_addButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
217 m_removeButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
218
219 m_addAssignmentButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
220 m_removeAssignmentButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
221
222 m_moveUpButton->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
223 m_moveDownButton->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
224
225 // wxFormBuilder doesn't include this event...
226 m_netclassGrid->Connect( wxEVT_GRID_CELL_CHANGING,
228 nullptr, this );
229
230 // Handle tooltips for grid
231 m_netclassGrid->GetGridColLabelWindow()->Bind( wxEVT_MOTION,
233 this );
234
235 m_frame->Bind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
236
237 m_netclassGrid->EndBatch();
238 m_assignmentGrid->EndBatch();
239 Thaw();
240
241 Bind( wxEVT_IDLE,
242 [this]( wxIdleEvent& aEvent )
243 {
244 // Careful of consuming CPU in an idle event handler. Check the ticker first to
245 // see if there's even a possibility of the netclasses having changed.
247 {
248 wxWindow* dialog = wxGetTopLevelParent( this );
249 wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
250
251 if( topLevelFocus == dialog && m_lastLoaded != m_netSettings->GetNetclasses() )
252 checkReload();
253 }
254 } );
255
256 m_matchingNets->SetFont( KIUI::GetInfoFont( this ) );
257}
258
259
261{
263 cfg->m_NetclassPanel.sash_pos = m_splitter->GetSashPosition();
264
265 if( m_isEEschema )
267 else
269
270 // Delete the GRID_TRICKS.
271 m_netclassGrid->PopEventHandler( true );
272 m_assignmentGrid->PopEventHandler( true );
273
274 m_netclassGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
276 nullptr, this );
277
278 m_frame->Unbind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
279}
280
281
283{
284 auto netclassToGridRow =
285 [&]( int aRow, const NETCLASS* nc )
286 {
287 m_netclassGrid->SetCellValue( aRow, GRID_NAME, nc->GetName() );
288
290 nc->GetWireWidthOpt() );
292 nc->GetBusWidthOpt() );
293
294 wxString colorAsString = nc->GetSchematicColor().ToCSSString();
295 m_netclassGrid->SetCellValue( aRow, GRID_SCHEMATIC_COLOR, colorAsString );
296
297 if( nc->HasLineStyle() )
298 {
299 int lineStyleIdx = std::max( 0, nc->GetLineStyle() );
300
301 if( lineStyleIdx >= (int) g_lineStyleNames.size() + 1 )
302 lineStyleIdx = 0;
303
304 m_netclassGrid->SetCellValue( aRow, GRID_LINESTYLE,
305 g_lineStyleNames[lineStyleIdx + 1] );
306 }
307 else
308 {
309 m_netclassGrid->SetCellValue(
310 aRow, GRID_LINESTYLE,
311 g_lineStyleNames[0] ); // <Not defined> line style in list
312 }
313
314 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_CLEARANCE, nc->GetClearanceOpt() );
315 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_TRACKSIZE, nc->GetTrackWidthOpt() );
316 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_VIASIZE, nc->GetViaDiameterOpt() );
317 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_VIADRILL, nc->GetViaDrillOpt() );
318 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_uVIASIZE, nc->GetuViaDiameterOpt() );
319 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_uVIADRILL, nc->GetuViaDrillOpt() );
320 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_DIFF_PAIR_WIDTH, nc->GetDiffPairWidthOpt() );
321 m_netclassGrid->SetOptionalUnitValue( aRow, GRID_DIFF_PAIR_GAP, nc->GetDiffPairGapOpt() );
322
323 colorAsString = nc->GetPcbColor().ToCSSString();
324 m_netclassGrid->SetCellValue( aRow, GRID_PCB_COLOR, colorAsString );
325
326 if( nc->IsDefault() )
327 {
328 m_netclassGrid->SetReadOnly( aRow, GRID_NAME );
329 m_netclassGrid->SetReadOnly( aRow, GRID_PCB_COLOR );
330 m_netclassGrid->SetReadOnly( aRow, GRID_SCHEMATIC_COLOR );
331 m_netclassGrid->SetReadOnly( aRow, GRID_LINESTYLE );
332 }
333
334 setNetclassRowNullableEditors( aRow, nc->IsDefault() );
335 };
336
337 // Get the netclasses sorted by priority
338 std::vector<const NETCLASS*> netclasses;
339 netclasses.reserve( m_netSettings->GetNetclasses().size() );
340
341 for( const auto& [name, netclass] : m_netSettings->GetNetclasses() )
342 netclasses.push_back( netclass.get() );
343
344 std::sort( netclasses.begin(), netclasses.end(),
345 []( const NETCLASS* nc1, const NETCLASS* nc2 )
346 {
347 return nc1->GetPriority() < nc2->GetPriority();
348 } );
349
350 // Enter user-defined netclasses
352 m_netclassGrid->AppendRows( static_cast<int>( netclasses.size() ) );
353
354 int row = 0;
355
356 for( const NETCLASS* nc : netclasses )
357 netclassToGridRow( row++, nc );
358
359 // Enter the Default netclass.
360 m_netclassGrid->AppendRows( 1 );
361 netclassToGridRow( row, m_netSettings->GetDefaultNetclass().get() );
362
364 m_assignmentGrid->AppendRows( m_netSettings->GetNetclassPatternAssignments().size() );
365
366 row = 0;
367
368 for( const auto& [matcher, netclassName] : m_netSettings->GetNetclassPatternAssignments() )
369 {
370 m_assignmentGrid->SetCellValue( row, 0, matcher->GetPattern() );
371 m_assignmentGrid->SetCellValue( row, 1, netclassName );
372 row++;
373 }
374}
375
376
378{
379 // Set nullable editors
380 auto setCellEditor = [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
490 nc->SetWireWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_WIREWIDTH ) );
491 nc->SetBusWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_BUSWIDTH ) );
492
493 wxString lineStyle = m_netclassGrid->GetCellValue( aRow, GRID_LINESTYLE );
494 int lineIdx = g_lineStyleNames.Index( lineStyle );
495
496 if( lineIdx == 0 )
497 nc->SetLineStyle( std::optional<int>() );
498 else
499 nc->SetLineStyle( lineIdx - 1 );
500
501 wxASSERT_MSG( lineIdx >= 0, "Line style name not found." );
502
503 nc->SetClearance( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_CLEARANCE ) );
504 nc->SetTrackWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_TRACKSIZE ) );
505 nc->SetViaDiameter( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_VIASIZE ) );
506 nc->SetViaDrill( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_VIADRILL ) );
507 nc->SetuViaDiameter( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_uVIASIZE ) );
508 nc->SetuViaDrill( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_uVIADRILL ) );
509 nc->SetDiffPairWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_DIFF_PAIR_WIDTH ) );
510 nc->SetDiffPairGap( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_DIFF_PAIR_GAP ) );
511
512 if( !nc->IsDefault() )
513 {
514 wxString color = m_netclassGrid->GetCellValue( aRow, GRID_PCB_COLOR );
515 KIGFX::COLOR4D newPcbColor( color );
516
517 if( newPcbColor != KIGFX::COLOR4D::UNSPECIFIED )
518 nc->SetPcbColor( newPcbColor );
519
520 color = m_netclassGrid->GetCellValue( aRow, GRID_SCHEMATIC_COLOR );
521 KIGFX::COLOR4D newSchematicColor( color );
522
523 if( newSchematicColor != KIGFX::COLOR4D::UNSPECIFIED )
524 nc->SetSchematicColor( newSchematicColor );
525 }
526 };
527
528 m_netSettings->ClearNetclasses();
529
530 // Copy the default NetClass:
531 gridRowToNetclass( m_netclassGrid->GetNumberRows() - 1, m_netSettings->GetDefaultNetclass() );
532
533 // Copy other NetClasses:
534 for( int row = 0; row < m_netclassGrid->GetNumberRows() - 1; ++row )
535 {
536 auto nc =
537 std::make_shared<NETCLASS>( m_netclassGrid->GetCellValue( row, GRID_NAME ), false );
538 gridRowToNetclass( row, nc );
539 m_netSettings->SetNetclass( nc->GetName(), nc );
540 }
541
542 m_netSettings->ClearNetclassPatternAssignments();
543 m_netSettings->ClearAllCaches();
544
545 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
546 {
547 wxString pattern = m_assignmentGrid->GetCellValue( row, 0 );
548 wxString netclass = m_assignmentGrid->GetCellValue( row, 1 );
549
550 m_netSettings->SetNetclassPatternAssignment( pattern, netclass );
551 }
552
553 return true;
554}
555
556
557bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aName,
558 bool focusFirst )
559{
560 wxString tmp = aName;
561
562 tmp.Trim( true );
563 tmp.Trim( false );
564
565 if( tmp.IsEmpty() )
566 {
567 wxString msg = _( "Netclass must have a name." );
568 PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME );
569 return false;
570 }
571
572 for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
573 {
574 if( ii != aRow && m_netclassGrid->GetCellValue( ii, GRID_NAME ).CmpNoCase( tmp ) == 0 )
575 {
576 wxString msg = _( "Netclass name already in use." );
578 focusFirst ? aRow : ii, GRID_NAME );
579 return false;
580 }
581 }
582
583 return true;
584}
585
586
588{
589 if( event.GetCol() == GRID_NAME )
590 {
591 if( validateNetclassName( event.GetRow(), event.GetString() ) )
592 {
593 wxString oldName = m_netclassGrid->GetCellValue( event.GetRow(), GRID_NAME );
594 wxString newName = event.GetString();
595
596 if( !oldName.IsEmpty() )
597 {
598 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
599 {
600 if( m_assignmentGrid->GetCellValue( row, 1 ) == oldName )
601 m_assignmentGrid->SetCellValue( row, 1, newName );
602 }
603 }
604
605 m_netclassesDirty = true;
606 }
607 else
608 {
609 event.Veto();
610 }
611 }
612}
613
614
616{
617 int col = m_netclassGrid->XToCol( aEvent.GetPosition().x );
618
619 if( aEvent.Moving() || aEvent.Entering() )
620 {
621 aEvent.Skip();
622
623 if( col == wxNOT_FOUND )
624 {
625 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
626 return;
627 }
628
629 if( col == m_hoveredCol )
630 return;
631
632 m_hoveredCol = col;
633
634 wxString tip;
635
636 switch( col )
637 {
638 case GRID_CLEARANCE: tip = _( "Minimum copper clearance" ); break;
639 case GRID_TRACKSIZE: tip = _( "Minimum track width" ); break;
640 case GRID_VIASIZE: tip = _( "Via pad diameter" ); break;
641 case GRID_VIADRILL: tip = _( "Via plated hole diameter" ); break;
642 case GRID_uVIASIZE: tip = _( "Microvia pad diameter" ); break;
643 case GRID_uVIADRILL: tip = _( "Microvia plated hole diameter" ); break;
644 case GRID_DIFF_PAIR_WIDTH: tip = _( "Differential pair track width" ); break;
645 case GRID_DIFF_PAIR_GAP: tip = _( "Differential pair gap" ); break;
646 case GRID_WIREWIDTH: tip = _( "Schematic wire thickness" ); break;
647 case GRID_BUSWIDTH: tip = _( "Bus wire thickness" ); break;
648 case GRID_SCHEMATIC_COLOR: tip = _( "Schematic wire color" ); break;
649 case GRID_LINESTYLE: tip = _( "Schematic wire line style" ); break;
650 case GRID_PCB_COLOR: tip = _( "PCB netclass color" ); break;
651 }
652
653 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
654 m_netclassGrid->GetGridColLabelWindow()->SetToolTip( tip );
655 }
656 else if( aEvent.Leaving() )
657 {
658 m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
659 aEvent.Skip();
660 }
661
662 aEvent.Skip();
663}
664
665
667{
669 return;
670
671 m_netclassGrid->InsertRows();
672
673 // Set defaults where required
674 wxString colorAsString = KIGFX::COLOR4D::UNSPECIFIED.ToCSSString();
675 m_netclassGrid->SetCellValue( 0, GRID_PCB_COLOR, colorAsString );
676 m_netclassGrid->SetCellValue( 0, GRID_SCHEMATIC_COLOR, colorAsString );
677 m_netclassGrid->SetCellValue( 0, GRID_LINESTYLE, g_lineStyleNames[0] );
678
679 // Set the row nullable editors
681
682 m_netclassGrid->MakeCellVisible( 0, 0 );
683 m_netclassGrid->SetGridCursor( 0, 0 );
684
685 m_netclassGrid->EnableCellEditControl( true );
686 m_netclassGrid->ShowCellEditControl();
687
688 m_netclassesDirty = true;
689}
690
691
693{
695 return;
696
697 int curRow = m_netclassGrid->GetGridCursorRow();
698
699 if( curRow < 0 )
700 {
701 return;
702 }
703 else if( curRow == m_netclassGrid->GetNumberRows() - 1 )
704 {
705 wxWindow* topLevelParent = wxGetTopLevelParent( this );
706
707 DisplayErrorMessage( topLevelParent, _( "The default net class is required." ) );
708 return;
709 }
710
711 // reset the net class to default for members of the removed class
712 wxString classname = m_netclassGrid->GetCellValue( curRow, GRID_NAME );
713
714 for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
715 {
716 if( m_assignmentGrid->GetCellValue( row, 1 ) == classname )
717 m_assignmentGrid->SetCellValue( row, 1, NETCLASS::Default );
718 }
719
720 m_netclassGrid->DeleteRows( curRow, 1 );
721
722 m_netclassGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
723 m_netclassGrid->SetGridCursor( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
724
725 m_netclassesDirty = true;
726}
727
728
730{
731 if( aWidth != m_lastNetclassGridWidth )
732 {
734
735 // Account for scroll bars
736 aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x );
737
738 for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
739 {
740 if( m_netclassGrid->GetColSize( i ) > 0 )
741 {
742 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
743 aWidth -= m_originalColWidths[ i ];
744 }
745 }
746
747 m_netclassGrid->SetColSize( 0, std::max( aWidth - 2, m_originalColWidths[ 0 ] ) );
748 }
749}
750
751
753{
754 AdjustNetclassGridColumns( event.GetSize().GetX() );
755
756 event.Skip();
757}
758
759
761{
763 return;
764
765 int row = m_assignmentGrid->GetNumberRows();
766 m_assignmentGrid->AppendRows();
767
768 m_assignmentGrid->SetCellValue( row, 1, m_netSettings->GetDefaultNetclass()->GetName() );
769
770 m_assignmentGrid->MakeCellVisible( row, 0 );
771 m_assignmentGrid->SetGridCursor( row, 0 );
772
773 m_assignmentGrid->EnableCellEditControl( true );
774 m_assignmentGrid->ShowCellEditControl();
775}
776
777
779{
781 return;
782
783 int curRow = m_assignmentGrid->GetGridCursorRow();
784
785 if( curRow < 0 )
786 return;
787
788 m_assignmentGrid->DeleteRows( curRow, 1 );
789
790 if( m_assignmentGrid->GetNumberRows() > 0 )
791 {
792 m_assignmentGrid->MakeCellVisible( std::max( 0, curRow-1 ), 0 );
793 m_assignmentGrid->SetGridCursor( std::max( 0, curRow-1 ), 0 );
794 }
795}
796
797
799{
800 const std::map<wxString, std::shared_ptr<NETCLASS>>& netclasses =
801 m_netSettings->GetNetclasses();
802
803 for( int row = 0; row < m_netclassGrid->GetNumberRows() - 1; ++row )
804 {
805 wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
806
807 if( netclasses.find( netclassName ) != netclasses.end() )
808 {
809 const KIGFX::COLOR4D ncColor = netclasses.at( netclassName )->GetSchematicColor();
810 m_netclassGrid->SetCellValue( row, GRID_PCB_COLOR, ncColor.ToCSSString() );
811 }
812 }
813}
814
815
817{
818 // Account for scroll bars
819 aWidth -= ( m_assignmentGrid->GetSize().x - m_assignmentGrid->GetClientSize().x );
820
821 int classNameWidth = 160;
822 m_assignmentGrid->SetColSize( 1, classNameWidth );
823 m_assignmentGrid->SetColSize( 0, std::max( aWidth - classNameWidth, classNameWidth ) );
824}
825
826
828{
829 AdjustAssignmentGridColumns( event.GetSize().GetX() );
830
831 event.Skip();
832}
833
834
835void PANEL_SETUP_NETCLASSES::OnUpdateUI( wxUpdateUIEvent& event )
836{
838 {
840 m_netclassesDirty = false;
841 }
842
844 {
845 AdjustNetclassGridColumns( GetSize().x - 1 );
847 }
848
849 if( m_assignmentGrid->GetNumberRows() == 0 )
850 return;
851
852 wxString pattern;
853 int row = m_assignmentGrid->GetGridCursorRow();
854 int col = m_assignmentGrid->GetGridCursorCol();
855
856 if( row >= 0 )
857 pattern = m_assignmentGrid->GetCellValue( row, 0 );
858
859 if( col == 0 && m_assignmentGrid->IsCellEditControlShown() )
860 {
861 wxGridCellEditor* cellEditor = m_assignmentGrid->GetCellEditor( row, 0 );
862
863 if( wxTextEntry* txt = dynamic_cast<wxTextEntry*>( cellEditor->GetControl() ) )
864 pattern = txt->GetValue();
865
866 cellEditor->DecRef();
867 }
868
869 if( pattern != m_lastPattern )
870 {
872
873 if( !pattern.IsEmpty() )
874 {
875 EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS );
876
877 m_matchingNets->Report( wxString::Format( _( "<b>Nets matching '%s':</b>" ),
878 pattern ) );
879
880 for( const wxString& net : m_netNames )
881 {
882 if( matcher.StartsWith( net ) )
883 m_matchingNets->Report( net );
884 }
885 }
886
888 m_lastPattern = pattern;
889 }
890}
891
892
894{
896 return false;
897
898 wxString msg;
899
900 // Test net class parameters.
901 for( int row = 0; row < m_netclassGrid->GetNumberRows(); row++ )
902 {
903 wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
904 netclassName.Trim( true );
905 netclassName.Trim( false );
906
907 if( !validateNetclassName( row, netclassName, false ) )
908 return false;
909 }
910
911 return true;
912}
913
914
915void PANEL_SETUP_NETCLASSES::ImportSettingsFrom( const std::shared_ptr<NET_SETTINGS>& aNetSettings )
916{
917 std::shared_ptr<NET_SETTINGS> savedSettings = m_netSettings;
918
919 m_netSettings = aNetSettings;
921
923
924 m_netclassGrid->ForceRefresh();
925 m_assignmentGrid->ForceRefresh();
926
927 m_netSettings = std::move( savedSettings );
928}
929
930
932{
934 return;
935
936 // Work out which rows are selected
937 std::vector<int> selectedRows;
938
939 for( int i = 0; i < m_netclassGrid->GetNumberRows(); ++i )
940 {
941 if( m_netclassGrid->IsInSelection( i, 0 ) )
942 selectedRows.push_back( i );
943 }
944
945 // Only move one row at a time
946 if( selectedRows.size() != 1 )
947 return;
948
949 // Can't move the first netclass, nor move the Default netclass
950 if( selectedRows[0] == 0 || selectedRows[0] == ( m_netclassGrid->GetNumberRows() - 1 ) )
951 return;
952
953 int newRowId = selectedRows[0] - 1;
954 m_netclassGrid->InsertRows( newRowId );
955
956 for( int col = 0; col < m_netclassGrid->GetNumberCols(); col++ )
957 m_netclassGrid->SetCellValue( newRowId, col,
958 m_netclassGrid->GetCellValue( newRowId + 2, col ) );
959
960 // Set the row nullable editors
961 setNetclassRowNullableEditors( newRowId, false );
962
963 m_netclassGrid->DeleteRows( newRowId + 2, 1 );
964 m_netclassGrid->MakeCellVisible( newRowId, 0 );
965 m_netclassGrid->SetGridCursor( newRowId, 0 );
966
967 m_netclassesDirty = true;
968}
969
970
972{
974 return;
975
976 // Work out which rows are selected
977 std::vector<int> selectedRows;
978
979 for( int i = 0; i < m_netclassGrid->GetNumberRows(); ++i )
980 {
981 if( m_netclassGrid->IsInSelection( i, 0 ) )
982 selectedRows.push_back( i );
983 }
984
985 // Only move one row at a time
986 if( selectedRows.size() != 1 )
987 return;
988
989 // Can't move the last row down, nor move the Default netclass
990 if( selectedRows[0] == ( m_netclassGrid->GetNumberRows() - 2 )
991 || selectedRows[0] == ( m_netclassGrid->GetNumberRows() - 1 ) )
992 return;
993
994 int newRowId = selectedRows[0] + 2;
995 m_netclassGrid->InsertRows( newRowId );
996
997 for( int col = 0; col < m_netclassGrid->GetNumberCols(); col++ )
998 {
999 m_netclassGrid->SetCellValue( newRowId, col,
1000 m_netclassGrid->GetCellValue( newRowId - 2, col ) );
1001 }
1002
1003 m_netclassGrid->DeleteRows( newRowId - 2, 1 );
1004 m_netclassGrid->MakeCellVisible( newRowId - 1, 0 );
1005 m_netclassGrid->SetGridCursor( newRowId - 1, 0 );
1006
1007 m_netclassesDirty = true;
1008}
int color
Definition: DXF_plotter.cpp:58
const char * name
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
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:44
static const char Default[]
the name of the default NETCLASS
Definition: netclass.h:46
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:679
int GetNetclassesTicker() const
Definition: project.h:117
int GetTextVarsTicker() const
Definition: project.h:114
void SetBitmap(const wxBitmapBundle &aBmp)
EDA_UNITS GetUserUnits() const
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=true, bool aKeep=false)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:769
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:487
void SetOptionalUnitValue(int aRow, int aCol, std::optional< int > aValue)
Set a unitized cell's optional value.
Definition: wx_grid.cpp:751
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition: wx_grid.cpp:809
wxString GetShownColumnsAsString()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:457
std::bitset< 64 > GetShownColumns()
Definition: wx_grid.cpp:476
std::optional< int > GetOptionalUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:719
void SetAutoEvalCols(const std::vector< int > &aCols)
Definition: wx_grid.h:124
void SetUnitsProvider(UNITS_PROVIDER *aProvider, int aCol=0)
Set a UNITS_PROVIDER to enable use of unit- and eval-based Getters.
Definition: wx_grid.cpp:689
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:184
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:637
void Clear()
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:250
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
This file is part of the common library.
#define _(s)
@ CTX_NETCLASS
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:154
STL namespace.
@ GRID_FIRST_PCBNEW
@ GRID_DIFF_PAIR_GAP
@ GRID_SCHEMATIC_COLOR
@ GRID_DIFF_PAIR_WIDTH
@ GRID_FIRST_EESCHEMA
std::vector< BITMAPS > g_lineStyleIcons
wxArrayString g_lineStyleNames
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE