KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_base_frame.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) 2018 Jean-Pierre Charras, [email protected]
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 * Copyright (C) 2022 CERN
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
26#include <boost/version.hpp>
27
28#if BOOST_VERSION >= 106700
29#include <boost/uuid/entropy_error.hpp>
30#endif
31
33#include <advanced_config.h>
34#include <base_units.h>
35#include <board.h>
36#include <cleanup_item.h>
37#include <collectors.h>
38#include <confirm.h>
39#include <footprint.h>
42#include <lset.h>
43#include <kiface_base.h>
44#include <pad.h>
45#include <pcb_painter.h>
46#include <pcbnew_id.h>
47#include <pcbnew_settings.h>
48#include <pcb_base_frame.h>
49#include <pcb_draw_panel_gal.h>
50#include <pcb_track.h>
51#include <pgm_base.h>
52#include <project_pcb.h>
53#include <scoped_set_reset.h>
54#include <trace_helpers.h>
56#include <zone.h>
57
58#include <math/vector2d.h>
59#include <math/vector2wx.h>
60#include <widgets/msgpanel.h>
61#include <wx/fswatcher.h>
62
65#include <tool/tool_manager.h>
67#include <tools/pcb_actions.h>
68#include <tool/grid_menu.h>
70
71#if defined(__linux__) || defined(__FreeBSD__)
73#else
75#endif
76
79
80wxDEFINE_EVENT( EDA_EVT_BOARD_CHANGING, wxCommandEvent );
81wxDEFINE_EVENT( EDA_EVT_BOARD_CHANGED, wxCommandEvent );
82
83PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
84 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
85 long aStyle, const wxString& aFrameName ) :
86 EDA_DRAW_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName, pcbIUScale ),
87 m_pcb( nullptr ),
88 m_originTransforms( *this ),
90{
92}
93
94
96{
97 // Ensure m_canvasType is up to date, to save it in config
98 if( GetCanvas() )
100
101 if( m_toolManager )
102 m_toolManager->ClearModel();
103
104 delete m_pcb;
105 m_pcb = nullptr;
106}
107
108
109bool PCB_BASE_FRAME::canCloseWindow( wxCloseEvent& aEvent )
110{
111 // Close modeless dialogs. They're trouble when they get destroyed after the frame and/or
112 // board.
113 wxWindow* viewer3D = Get3DViewerFrame();
114
115 if( viewer3D )
116 viewer3D->Close( true );
117
118 // Similarly, wxConvBrokenFileNames uses some statically allocated variables that make it
119 // crash when run later from a d'tor.
121
122 return true;
123}
124
125
126void PCB_BASE_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
127{
129
130 if( m_spaceMouse )
131 m_spaceMouse->SetFocus( aEvent.GetActive() );
132}
133
134
135void PCB_BASE_FRAME::handleIconizeEvent( wxIconizeEvent& aEvent )
136{
138
139 if( m_spaceMouse && aEvent.IsIconized() )
140 m_spaceMouse->SetFocus( false );
141}
142
143
145{
146 wxWindow* frame = FindWindowByName( QUALIFIED_VIEWER3D_FRAMENAME( this ) );
147 return dynamic_cast<EDA_3D_VIEWER_FRAME*>( frame );
148}
149
150
151void PCB_BASE_FRAME::Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle )
152{
153 EDA_3D_VIEWER_FRAME* draw3DFrame = Get3DViewerFrame();
154
155 if( draw3DFrame )
156 {
157 if( aTitle )
158 draw3DFrame->SetTitle( *aTitle );
159
160 if( aMarkDirty )
161 draw3DFrame->ReloadRequest();
162
163 if( aRefresh )
164 draw3DFrame->Redraw();
165 }
166}
167
168
170{
171 if( m_pcb != aBoard )
172 {
173 delete m_pcb;
174 m_pcb = aBoard;
175
176 if( GetBoard() )
178
179 if( GetBoard() && GetCanvas() )
180 {
182
183 if( rs )
184 {
185 rs->SetDashLengthRatio( GetBoard()->GetPlotOptions().GetDashedLineDashRatio() );
186 rs->SetGapLengthRatio( GetBoard()->GetPlotOptions().GetDashedLineGapRatio() );
187 }
188 }
189
190 wxCommandEvent e( EDA_EVT_BOARD_CHANGED );
191 ProcessEventLocally( e );
192 }
193}
194
195
197{
198 if( aFootprint )
199 {
200 GetBoard()->Add( aFootprint, ADD_MODE::APPEND );
201
202 aFootprint->SetFlags( IS_NEW );
203 aFootprint->SetPosition( VECTOR2I( 0, 0 ) ); // cursor in GAL may not be initialized yet
204
205 // Put it on FRONT layer (note that it might be stored flipped if the lib is an archive
206 // built from a board)
207 if( aFootprint->IsFlipped() )
208 aFootprint->Flip( aFootprint->GetPosition(), GetPcbNewSettings()->m_FlipDirection );
209
210 // Place it in orientation 0 even if it is not saved with orientation 0 in lib (note that
211 // it might be stored in another orientation if the lib is an archive built from a board)
212 aFootprint->SetOrientation( ANGLE_0 );
213
214 GetBoard()->UpdateUserUnits( aFootprint, GetCanvas()->GetView() );
215
217 }
218}
219
220
221EDA_ITEM* PCB_BASE_FRAME::ResolveItem( const KIID& aId, bool aAllowNullptrReturn ) const
222{
223 return GetBoard()->ResolveItem( aId, aAllowNullptrReturn );
224}
225
226void PCB_BASE_FRAME::FocusOnItem( EDA_ITEM* aItem, bool aAllowScroll )
227{
228 // nullptr will clear the current focus
229 if( aItem != nullptr && !aItem->IsBOARD_ITEM() )
230 return;
231
232 FocusOnItem( static_cast<BOARD_ITEM*>( aItem ), UNDEFINED_LAYER, aAllowScroll );
233}
234
235void PCB_BASE_FRAME::FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer, bool aAllowScroll )
236{
237 std::vector<BOARD_ITEM*> items;
238
239 if( aItem )
240 items.push_back( aItem );
241
242 FocusOnItems( items, aLayer, aAllowScroll );
243}
244
245
246void PCB_BASE_FRAME::FocusOnItems( std::vector<BOARD_ITEM*> aItems, PCB_LAYER_ID aLayer, bool aAllowScroll )
247{
248 static std::vector<KIID> lastBrightenedItemIDs;
249
250 bool itemsUnbrightened = false;
251
252 for( KIID lastBrightenedItemID : lastBrightenedItemIDs )
253 {
254 if( BOARD_ITEM* lastItem = GetBoard()->ResolveItem( lastBrightenedItemID, true ) )
255 {
256 lastItem->ClearBrightened();
257 GetCanvas()->GetView()->Update( lastItem );
258 itemsUnbrightened = true;
259 }
260 }
261
262 if( itemsUnbrightened )
263 GetCanvas()->Refresh();
264
265 lastBrightenedItemIDs.clear();
266
267 if( aItems.empty() )
268 return;
269
270 for( BOARD_ITEM* item : aItems )
271 {
272 if( item && item != DELETED_BOARD_ITEM::GetInstance() )
273 {
274 item->SetBrightened();
275 lastBrightenedItemIDs.push_back( item->m_Uuid );
276
277 item->RunOnChildren(
278 [&]( BOARD_ITEM* child )
279 {
280 child->SetBrightened();
281 lastBrightenedItemIDs.push_back( child->m_Uuid );
282 },
284
285 GetCanvas()->GetView()->Update( item );
286 }
287 }
288
289 VECTOR2I focusPt;
290 KIGFX::VIEW* view = GetCanvas()->GetView();
291 SHAPE_POLY_SET viewportPoly( view->GetViewport() );
292
293 for( wxWindow* dialog : findDialogs() )
294 {
295 wxPoint dialogPos = GetCanvas()->ScreenToClient( dialog->GetScreenPosition() );
296 SHAPE_POLY_SET dialogPoly( BOX2D( view->ToWorld( ToVECTOR2D( dialogPos ), true ),
297 view->ToWorld( ToVECTOR2D( dialog->GetSize() ), false ) ) );
298
299 try
300 {
301 viewportPoly.BooleanSubtract( dialogPoly );
302 }
303 catch( const std::exception& e )
304 {
305 wxFAIL_MSG( wxString::Format( wxT( "Clipper exception occurred: %s" ), e.what() ) );
306 }
307 }
308
309 SHAPE_POLY_SET itemPoly, clippedPoly;
310
311 for( BOARD_ITEM* item : aItems )
312 {
313 if( item && item != DELETED_BOARD_ITEM::GetInstance() )
314 {
315 // Focus on the object's location. Prefer a visible part of the object to its anchor
316 // in order to keep from scrolling around.
317
318 focusPt = item->GetPosition();
319
320 if( aLayer == UNDEFINED_LAYER && item->GetLayerSet().any() )
321 aLayer = item->GetLayerSet().Seq()[0];
322
323 switch( item->Type() )
324 {
325 case PCB_FOOTPRINT_T:
326 try
327 {
328 itemPoly = static_cast<FOOTPRINT*>( item )->GetBoundingHull();
329 }
330 catch( const std::exception& e )
331 {
332 wxFAIL_MSG( wxString::Format( wxT( "Clipper exception occurred: %s" ), e.what() ) );
333 }
334
335 break;
336
337 case PCB_PAD_T:
338 case PCB_MARKER_T:
339 case PCB_VIA_T:
340 FocusOnLocation( item->GetFocusPosition(), aAllowScroll );
341 GetCanvas()->Refresh();
342 return;
343
344 case PCB_SHAPE_T:
345 case PCB_FIELD_T:
346 case PCB_TEXT_T:
347 case PCB_TEXTBOX_T:
348 case PCB_BARCODE_T:
349 case PCB_TRACE_T:
350 case PCB_ARC_T:
352 case PCB_DIM_LEADER_T:
353 case PCB_DIM_CENTER_T:
354 case PCB_DIM_RADIAL_T:
356 item->TransformShapeToPolygon( itemPoly, aLayer, 0, pcbIUScale.mmToIU( 0.1 ), ERROR_INSIDE );
357 break;
358
359 case PCB_ZONE_T:
360 {
361 ZONE* zone = static_cast<ZONE*>( item );
362#if 0
363 // Using the filled area shapes to find a Focus point can give good results, but
364 // unfortunately the calculations are highly time consuming, even for not very
365 // large areas (can be easily a few minutes for large areas).
366 // so we used only the zone outline that usually do not have too many vertices.
367 zone->TransformShapeToPolygon( itemPoly, aLayer, 0, pcbIUScale.mmToIU( 0.1 ), ERROR_INSIDE );
368
369 if( itemPoly.IsEmpty() )
370 itemPoly = zone->GetBoardOutline();
371#else
372 // much faster calculation time when using only the zone outlines
373 itemPoly = zone->GetBoardOutline();
374#endif
375
376 break;
377 }
378
379 default:
380 {
381 BOX2I item_bbox = item->GetBoundingBox();
382 itemPoly.NewOutline();
383 itemPoly.Append( item_bbox.GetOrigin() );
384 itemPoly.Append( item_bbox.GetOrigin() + VECTOR2I( item_bbox.GetWidth(), 0 ) );
385 itemPoly.Append( item_bbox.GetOrigin() + VECTOR2I( 0, item_bbox.GetHeight() ) );
386 itemPoly.Append( item_bbox.GetOrigin() + VECTOR2I( item_bbox.GetWidth(),
387 item_bbox.GetHeight() ) );
388 break;
389 }
390 }
391
392 try
393 {
394 itemPoly.ClearArcs();
395 viewportPoly.ClearArcs();
396 clippedPoly.BooleanIntersection( itemPoly, viewportPoly );
397 }
398 catch( const std::exception& e )
399 {
400 wxFAIL_MSG( wxString::Format( wxT( "Clipper exception occurred: %s" ), e.what() ) );
401 }
402
403 if( !clippedPoly.IsEmpty() )
404 itemPoly = clippedPoly;
405 }
406 }
407
408 /*
409 * Perform a step-wise deflate to find the visual-center-of-mass
410 */
411
412 if( itemPoly.IsEmpty() )
413 {
414 FocusOnLocation( focusPt, aAllowScroll );
415 GetCanvas()->Refresh();
416 return;
417 }
418
419 BOX2I bbox = itemPoly.BBox();
420 int step = std::min( bbox.GetWidth(), bbox.GetHeight() ) / 10;
421
422 // Tiny shapes can quantize to a zero deflate step
423 if( step <= 0 )
424 {
425 FocusOnLocation( bbox.Centre(), aAllowScroll );
426 GetCanvas()->Refresh();
427 return;
428 }
429
430 while( !itemPoly.IsEmpty() )
431 {
432 focusPt = itemPoly.BBox().Centre();
433
434 try
435 {
437 }
438 catch( const std::exception& e )
439 {
440 wxFAIL_MSG( wxString::Format( wxT( "Clipper exception occurred: %s" ), e.what() ) );
441 }
442 }
443
444 FocusOnLocation( focusPt, aAllowScroll );
445
446 GetCanvas()->Refresh();
447}
448
449
451{
452 KIGFX::PCB_VIEW* view = GetCanvas()->GetView();
453
454 if( view && GetBoard()->m_SolderMaskBridges && view->HasItem( GetBoard()->m_SolderMaskBridges ) )
455 view->Remove( GetBoard()->m_SolderMaskBridges );
456}
457
458
460{
461 KIGFX::PCB_VIEW* view = GetCanvas()->GetView();
462
463 if( view && GetBoard()->m_SolderMaskBridges )
464 {
465 if( view->HasItem( GetBoard()->m_SolderMaskBridges ) )
466 view->Remove( GetBoard()->m_SolderMaskBridges );
467
468 view->Add( GetBoard()->m_SolderMaskBridges );
469 }
470}
471
472
473void PCB_BASE_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
474{
475 m_pcb->SetPageSettings( aPageSettings );
476
477 if( GetScreen() )
478 GetScreen()->InitDataPoints( aPageSettings.GetSizeIU( pcbIUScale.IU_PER_MILS ) );
479}
480
481
483{
484 return m_pcb->GetPageSettings();
485}
486
487
489{
490 // this function is only needed because EDA_DRAW_FRAME is not compiled
491 // with either -DPCBNEW or -DEESCHEMA, so the virtual is used to route
492 // into an application specific source file.
493 return m_pcb->GetPageSettings().GetSizeIU( pcbIUScale.IU_PER_MILS );
494}
495
496
498{
499 return m_pcb->GetDesignSettings().GetGridOrigin();
500}
501
502
504{
505 m_pcb->GetDesignSettings().SetGridOrigin( aPoint );
506}
507
508
510{
511 return m_pcb->GetDesignSettings().GetAuxOrigin();
512}
513
514
516{
517 VECTOR2I origin( 0, 0 );
518
519 switch( GetPcbNewSettings()->m_Display.m_DisplayOrigin )
520 {
522 case PCB_DISPLAY_ORIGIN::PCB_ORIGIN_AUX: origin = GetAuxOrigin(); break;
524 default: wxASSERT( false ); break;
525 }
526
527 return origin;
528}
529
534
535
537{
538 return m_pcb->GetTitleBlock();
539}
540
541
543{
544 m_pcb->SetTitleBlock( aTitleBlock );
545}
546
547
549{
550 return m_pcb->GetDesignSettings();
551}
552
553
555{
556 m_drawBgColor= aColor;
557 m_auimgr.Update();
558}
559
560
562{
563 return m_pcb->GetPlotOptions();
564}
565
566
568{
569 m_pcb->SetPlotOptions( aSettings );
570
571 // Plot Settings can also change the "tent vias" setting, which can affect the solder mask.
572 LSET visibleLayers = GetBoard()->GetVisibleLayers();
573
574 if( visibleLayers.test( F_Mask ) || visibleLayers.test( B_Mask ) )
575 {
577 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
578 {
579 BOARD_ITEM* item = nullptr;
580
581 if( aItem->IsBOARD_ITEM() )
582 item = static_cast<BOARD_ITEM*>( aItem );
583
584 // Note: KIGFX::REPAINT isn't enough for things that go from invisible to
585 // visible as they won't be found in the view layer's itemset for re-painting.
586 if( item && item->Type() == PCB_VIA_T )
587 return KIGFX::ALL;
588
589 return 0;
590 } );
591
592 GetCanvas()->Refresh();
593 }
594}
595
596
597BOX2I PCB_BASE_FRAME::GetBoardBoundingBox( bool aBoardEdgesOnly ) const
598{
599 BOX2I area = aBoardEdgesOnly ? m_pcb->GetBoardEdgesBoundingBox() : m_pcb->GetBoundingBox();
600
601 if( area.GetWidth() == 0 && area.GetHeight() == 0 )
602 {
603 VECTOR2I pageSize = GetPageSizeIU();
604
606 {
607 area.SetOrigin( 0, 0 );
608 area.SetEnd( pageSize.x, pageSize.y );
609 }
610 else
611 {
612 area.SetOrigin( -pageSize.x / 2, -pageSize.y / 2 );
613 area.SetEnd( pageSize.x / 2, pageSize.y / 2 );
614 }
615 }
616
617 return area;
618}
619
620
621const BOX2I PCB_BASE_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
622{
623 /* "Zoom to Fit" calls this with "aIncludeAllVisible" as true. Since that feature
624 * always ignored the page and border, this function returns a bbox without them
625 * as well when passed true. This technically is not all things visible, but it
626 * keeps behavior consistent.
627 *
628 * When passed false, this function returns a bbox of just the board edge. This
629 * allows things like fabrication text or anything else outside the board edge to
630 * be ignored, and just zooms up to the board itself.
631 *
632 * Calling "GetBoardBoundingBox(true)" when edge cuts are turned off will return
633 * the entire page and border, so we call "GetBoardBoundingBox(false)" instead.
634 */
635 if( aIncludeAllVisible || !m_pcb->IsLayerVisible( Edge_Cuts ) )
636 return GetBoardBoundingBox( false );
637 else
638 return GetBoardBoundingBox( true );
639}
640
641
642// Virtual function
646
647
649{
650 return static_cast<PCB_SCREEN*>( EDA_DRAW_FRAME::GetScreen() );
651}
652
653
655{
656 GetScreen()->m_Active_Layer = aLayer;
657}
658
659
664
665
667{
668 // call my base class
670
671 // tooltips in toolbars
673
675
676 if( viewer3D )
677 viewer3D->ShowChangedLanguage();
678}
679
680
682{
683 EDA_3D_VIEWER_FRAME* draw3DFrame = Get3DViewerFrame();
684
685 if( !draw3DFrame )
686 draw3DFrame = new EDA_3D_VIEWER_FRAME( &Kiway(), this, _( "3D Viewer" ) );
687
688 // Raising the window does not show the window on Windows if iconized. This should work
689 // on any platform.
690 if( draw3DFrame->IsIconized() )
691 draw3DFrame->Iconize( false );
692
693 draw3DFrame->Raise();
694 draw3DFrame->Show( true );
695
696 // Raising the window does not set the focus on Linux. This should work on any platform.
697 if( wxWindow::FindFocus() != draw3DFrame )
698 draw3DFrame->SetFocus();
699
700 // Allocate a slice of time to display the 3D frame
701 // a call to wxSafeYield() should be enough (and better), but on Linux we need
702 // to call wxYield()
703 // otherwise the activity messages are not displayed during the first board loading
704 wxYield();
705
706 // Note, the caller is responsible to load/update the board 3D view.
707 // after frame creation the board is not automatically created.
708
709 return draw3DFrame;
710}
711
712
714{
715 PCB_LAYER_ID preslayer = GetActiveLayer();
716 auto& displ_opts = GetDisplayOptions();
717
718 // Check if the specified layer matches the present layer
719 if( layer == preslayer )
720 return;
721
722 // Copper layers cannot be selected unconditionally; how many of those layers are
723 // currently enabled needs to be checked.
724 if( IsCopperLayer( layer ) )
725 {
726 if( layer > m_pcb->GetCopperLayerStackMaxId() )
727 return;
728 }
729
730 // Is yet more checking required? E.g. when the layer to be selected is a non-copper
731 // layer, or when switching between a copper layer and a non-copper layer, or vice-versa?
732 // ...
733
734 SetActiveLayer( layer );
735
736 if( displ_opts.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL )
737 GetCanvas()->Refresh();
738}
739
740
742{
743 GENERAL_COLLECTORS_GUIDE guide( m_pcb->GetVisibleLayers(), GetActiveLayer(),
744 GetCanvas()->GetView() );
745
746 // account for the globals
747 guide.SetIgnoreFPTextOnBack( !m_pcb->IsElementVisible( LAYER_FP_TEXT ) );
748 guide.SetIgnoreFPTextOnFront( !m_pcb->IsElementVisible( LAYER_FP_TEXT ) );
749 guide.SetIgnoreFootprintsOnBack( !m_pcb->IsElementVisible( LAYER_FOOTPRINTS_BK ) );
750 guide.SetIgnoreFootprintsOnFront( !m_pcb->IsElementVisible( LAYER_FOOTPRINTS_FR ) );
751 guide.SetIgnoreThroughHolePads( ! m_pcb->IsElementVisible( LAYER_PADS ) );
752 guide.SetIgnoreFPValues( !m_pcb->IsElementVisible( LAYER_FP_VALUES ) );
753 guide.SetIgnoreFPReferences( !m_pcb->IsElementVisible( LAYER_FP_REFERENCES ) );
754 guide.SetIgnoreThroughVias( ! m_pcb->IsElementVisible( LAYER_VIAS ) );
755 guide.SetIgnoreBlindBuriedVias( ! m_pcb->IsElementVisible( LAYER_VIAS ) );
756 guide.SetIgnoreMicroVias( ! m_pcb->IsElementVisible( LAYER_VIAS ) );
757 guide.SetIgnoreTracks( ! m_pcb->IsElementVisible( LAYER_TRACKS ) );
758
759 return guide;
760}
761
762
764{
766
767 BASE_SCREEN* screen = GetScreen();
768
769 if( !screen )
770 return;
771
772 wxString line;
774
775 if( GetShowPolarCoords() ) // display polar coordinates
776 {
777 double dx = cursorPos.x - screen->m_LocalOrigin.x;
778 double dy = cursorPos.y - screen->m_LocalOrigin.y;
779 double theta = RAD2DEG( atan2( -dy, dx ) );
780 double ro = hypot( dx, dy );
781
782 line.Printf( wxT( "r %s theta %.3f" ),
783 MessageTextFromValue( ro, false ),
784 theta );
785
786 SetStatusText( line, 3 );
787 }
788
789 // Transform absolute coordinates for user origin preferences
790 double userXpos = m_originTransforms.ToDisplayAbsX( static_cast<double>( cursorPos.x ) );
791 double userYpos = m_originTransforms.ToDisplayAbsY( static_cast<double>( cursorPos.y ) );
792
793 // Display absolute coordinates:
794 line.Printf( wxT( "X %s Y %s" ),
795 MessageTextFromValue( userXpos, false ),
796 MessageTextFromValue( userYpos, false ) );
797 SetStatusText( line, 2 );
798
799 if( !GetShowPolarCoords() ) // display relative cartesian coordinates
800 {
801 // Calculate relative coordinates
802 double relXpos = cursorPos.x - screen->m_LocalOrigin.x;
803 double relYpos = cursorPos.y - screen->m_LocalOrigin.y;
804
805 // Transform relative coordinates for user origin preferences
806 userXpos = m_originTransforms.ToDisplayRelX( relXpos );
807 userYpos = m_originTransforms.ToDisplayRelY( relYpos );
808
809 line.Printf( wxT( "dx %s dy %s dist %s" ),
810 MessageTextFromValue( userXpos, false ),
811 MessageTextFromValue( userYpos, false ),
812 MessageTextFromValue( hypot( userXpos, userYpos ), false ) );
813 SetStatusText( line, 3 );
814 }
815
817}
818
819
821{
822 EDA_DRAW_FRAME::unitsChangeRefresh(); // Update the status bar.
823
824 if( GetBoard() )
826
828}
829
830
832{
834
835 // Move legacy user grids to grid list
836 if( !aCfg->m_Window.grid.user_grid_x.empty() )
837 {
838 aCfg->m_Window.grid.grids.emplace_back( GRID{ "User Grid", aCfg->m_Window.grid.user_grid_x,
839 aCfg->m_Window.grid.user_grid_y } );
840 aCfg->m_Window.grid.user_grid_x = wxEmptyString;
841 aCfg->m_Window.grid.user_grid_y = wxEmptyString;
842 }
843
844 // Some, but not all, derived classes have a PCBNEW_SETTINGS.
845 if( PCBNEW_SETTINGS* pcbnew_cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg ) )
846 m_polarCoords = pcbnew_cfg->m_PolarCoords;
847
848 wxASSERT( GetCanvas() );
849
850 if( GetCanvas() )
851 {
853
854 if( rs )
855 {
858 rs->SetDefaultFont( wxEmptyString ); // Always the KiCad font for PCBs
859 }
860 }
861}
862
863
865{
866 if( aErrorCode >= CLEANUP_FIRST )
867 return RPT_SEVERITY_ACTION;
868
870
871 return bds.m_DRCSeverities[ aErrorCode ];
872}
873
874
876{
878
879 // Some, but not all derived classes have a PCBNEW_SETTINGS.
880 PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
881
882 if( cfg )
884}
885
886
891
892
897
898
920
921
923{
924 static MAGNETIC_SETTINGS fallback;
925
927 return &cfg->m_MagneticItems;
928
929 return &fallback;
930}
931
932
934{
936
937 KIGFX::VIEW* view = GetCanvas()->GetView();
938 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view->GetPainter() );
939 PCB_RENDER_SETTINGS* settings = painter->GetSettings();
940
941 settings->LoadColors( GetColorSettings( true ) );
944
945 if( aFlags & TEXTVARS_CHANGED )
947
948 // Note: KIGFX::REPAINT isn't enough for things that go from invisible to visible as
949 // they won't be found in the view layer's itemset for re-painting.
951 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
952 {
953 if( dynamic_cast<RATSNEST_VIEW_ITEM*>( aItem ) )
954 {
955 return KIGFX::ALL; // ratsnest display
956 }
957 else if( dynamic_cast<PCB_TRACK*>( aItem ) )
958 {
959 return KIGFX::REPAINT; // track, arc & via clearance display
960 }
961 else if( dynamic_cast<PAD*>( aItem ) )
962 {
963 return KIGFX::REPAINT; // pad clearance display
964 }
965 else if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ) )
966 {
967 if( text->HasTextVars() )
968 {
969 text->ClearRenderCache();
970 text->ClearBoundingBoxCache();
972 }
973 }
974
975 return 0;
976 } );
977
979
981
982 // The 3D viewer isn't in the Kiway, so send its update manually
984
985 if( viewer )
986 viewer->CommonSettingsChanged( aFlags );
987}
988
989
991{
993
996
997 if( m_isClosing )
998 return;
999
1002}
1003
1004
1011
1012
1017
1018
1020{
1022
1023 EDA_DRAW_PANEL_GAL* canvas = GetCanvas();
1024 KIGFX::VIEW* view = canvas->GetView();
1025
1026 if( m_toolManager )
1027 {
1028 m_toolManager->SetEnvironment( m_pcb, view, canvas->GetViewControls(), config(), this );
1029
1030 m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH );
1031 }
1032
1033 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view->GetPainter() );
1034 KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
1035 const PCB_DISPLAY_OPTIONS& displ_opts = GetDisplayOptions();
1036
1037 settings->LoadDisplayOptions( displ_opts );
1038 settings->LoadColors( GetColorSettings() );
1040
1041 view->RecacheAllItems();
1043 canvas->StartDrawing();
1044
1045 try
1046 {
1047 if( !m_spaceMouse )
1048 {
1049#if defined(__linux__) || defined(__FreeBSD__)
1050 m_spaceMouse = std::make_unique<SPNAV_2D_PLUGIN>( GetCanvas() );
1051 m_spaceMouse->SetScale( 0.01 );
1052#else
1053 m_spaceMouse = std::make_unique<NL_PCBNEW_PLUGIN>( GetCanvas() );
1054#endif
1055 }
1056 }
1057 catch( const std::exception& e )
1058 {
1059 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), wxS( "%s" ), e.what() );
1060 }
1061 catch( ... )
1062 {
1063 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ),
1064 wxT( "Unknown exception during SpaceMouse initialization" ) );
1065 }
1066}
1067
1068
1069void PCB_BASE_FRAME::SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions, bool aRefresh )
1070{
1071 bool hcChanged = m_displayOptions.m_ContrastModeDisplay != aOptions.m_ContrastModeDisplay;
1072 bool hcVisChanged = m_displayOptions.m_ContrastModeDisplay == HIGH_CONTRAST_MODE::HIDDEN
1074 m_displayOptions = aOptions;
1075
1076 EDA_DRAW_PANEL_GAL* canvas = GetCanvas();
1077 KIGFX::PCB_VIEW* view = static_cast<KIGFX::PCB_VIEW*>( canvas->GetView() );
1078
1079 view->UpdateDisplayOptions( aOptions );
1080 view->SetMirror( aOptions.m_FlipBoardView, view->IsMirroredY() );
1081 view->RecacheAllItems();
1082
1085
1086 // Vias on a restricted layer set must be redrawn when high contrast mode is changed
1087 if( hcChanged )
1088 {
1089 bool showNetNames = false;
1090
1091 if( PCBNEW_SETTINGS* config = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
1092 showNetNames = config->m_Display.m_NetNames > 0;
1093
1094 // Note: KIGFX::REPAINT isn't enough for things that go from invisible to visible as
1095 // they won't be found in the view layer's itemset for re-painting.
1097 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
1098 {
1099 if( PCB_VIA* via = dynamic_cast<PCB_VIA*>( aItem ) )
1100 {
1101 if( via->GetViaType() != VIATYPE::THROUGH
1102 || via->GetRemoveUnconnected()
1103 || showNetNames )
1104 {
1105 return hcVisChanged ? KIGFX::ALL : KIGFX::REPAINT;
1106 }
1107 }
1108 else if( PAD* pad = dynamic_cast<PAD*>( aItem ) )
1109 {
1110 if( pad->GetRemoveUnconnected()
1111 || showNetNames )
1112 {
1113 return hcVisChanged ? KIGFX::ALL : KIGFX::REPAINT;
1114 }
1115 }
1116
1117 return 0;
1118 } );
1119 }
1120
1121 if( aRefresh )
1122 canvas->Refresh();
1123}
1124
1125
1127{
1128 wxLogTrace( traceLibWatch, "setFPWatcher" );
1129
1130 Unbind( wxEVT_FSWATCHER, &PCB_BASE_FRAME::OnFPChange, this );
1131
1132 if( m_watcher )
1133 {
1134 wxLogTrace( traceLibWatch, "Remove watch" );
1135 m_watcher->RemoveAll();
1136 m_watcher->SetOwner( nullptr );
1137 m_watcher.reset();
1138 }
1139
1140 wxString libfullname;
1142
1143 if( !aFootprint || !adapter )
1144 return;
1145
1146 try
1147 {
1148 std::optional<LIBRARY_TABLE_ROW*> row = adapter->GetRow( aFootprint->GetFPID().GetLibNickname() );
1149
1150 if( !row )
1151 return;
1152
1153 libfullname = LIBRARY_MANAGER::GetFullURI( *row, true );
1154 }
1155 catch( const IO_ERROR& error )
1156 {
1157 wxLogTrace( traceLibWatch, "Error: %s", error.What() );
1158 return;
1159 }
1160 catch( const std::exception& e )
1161 {
1162 DisplayInfoMessage( this, e.what() );
1163 return;
1164 }
1165
1166 m_watcherFileName.Assign( libfullname, aFootprint->GetFPID().GetLibItemName(),
1168
1169 if( !m_watcherFileName.FileExists() )
1170 return;
1171
1172 m_watcherLastModified = m_watcherFileName.GetModificationTime();
1173
1174 Bind( wxEVT_FSWATCHER, &PCB_BASE_FRAME::OnFPChange, this );
1175 m_watcher = std::make_unique<wxFileSystemWatcher>();
1176 m_watcher->SetOwner( this );
1177
1178 wxFileName fn;
1179 fn.AssignDir( m_watcherFileName.GetPath() );
1180 fn.DontFollowLink();
1181
1182 wxLogTrace( traceLibWatch, "Add watch: %s", fn.GetPath() );
1183
1184 {
1185 // Silence OS errors that come from the watcher
1186 wxLogNull silence;
1187 m_watcher->Add( fn );
1188 }
1189}
1190
1191
1192void PCB_BASE_FRAME::OnFPChange( wxFileSystemWatcherEvent& aEvent )
1193{
1194 if( aEvent.GetPath() != m_watcherFileName.GetFullPath() )
1195 return;
1196
1197 // Start the debounce timer (set to 1 second)
1198 if( !m_watcherDebounceTimer.StartOnce( 1000 ) )
1199 {
1200 wxLogTrace( traceLibWatch, "Failed to start the debounce timer" );
1201 return;
1202 }
1203}
1204
1205
1207{
1208 if( aEvent.GetId() != m_watcherDebounceTimer.GetId() )
1209 {
1210 aEvent.Skip();
1211 return;
1212 }
1213
1215 {
1216 wxLogTrace( traceLibWatch, "Restarting debounce timer" );
1217 m_watcherDebounceTimer.StartOnce( 3000 );
1218 return;
1219 }
1220
1221 // If the frame is currently disabled then a quasi-modal/modal dialog is open on top of it (for
1222 // example the footprint properties dialog). Reloading the footprint now would delete the items
1223 // the dialog is editing and crash on dialog close. Defer the reload until the dialog is gone.
1224 if( !IsEnabled() )
1225 {
1226 wxLogTrace( traceLibWatch, "Frame disabled (dialog open); restarting debounce timer" );
1227 m_watcherDebounceTimer.StartOnce( 1000 );
1228 return;
1229 }
1230
1231 // An interactive tool (move, draw, place) holds references into the current footprint while its
1232 // event loop runs. Reloading now would free those out from under the running tool and crash.
1233 // Restart the timer before touching the watcher timestamp so the reload is retried once the tool
1234 // finishes rather than silently dropped.
1235 if( !ToolStackIsEmpty() )
1236 {
1237 wxLogTrace( traceLibWatch, "Interactive tool active; restarting debounce timer" );
1238 m_watcherDebounceTimer.StartOnce( 1000 );
1239 return;
1240 }
1241
1242 wxLogTrace( traceLibWatch, "OnFpChangeDebounceTimer" );
1243
1244 wxDateTime lastModified;
1245
1246 {
1247 // Silence spurious OS messages while checking if the file has changed
1248 wxLogNull silence;
1249 lastModified = m_watcherFileName.GetModificationTime();
1250 }
1251
1252 if( lastModified == m_watcherLastModified || !lastModified.IsValid() )
1253 return;
1254
1255 m_watcherLastModified = lastModified;
1256
1259
1260 // When loading a footprint from a library in the footprint editor
1261 // the items UUIDs must be keep and not reinitialized
1262 bool keepUUID = IsType( FRAME_FOOTPRINT_EDITOR );
1263
1264 if( !fp || !adapter )
1265 return;
1266
1267 SCOPED_SET_RESET<bool> inTimerEvent( m_inFpChangeTimerEvent, true );
1268
1270 || IsOK( this, _( "The library containing the current footprint has changed.\n"
1271 "Do you want to reload the footprint?" ) ) )
1272 {
1273 wxString fpname = fp->GetFPID().GetLibItemName();
1274 wxString nickname = fp->GetFPID().GetLibNickname();
1275
1276 try
1277 {
1278 FOOTPRINT* newfp = adapter->LoadFootprint( nickname, fpname, keepUUID );
1279
1280 if( newfp )
1281 {
1282 std::vector<KIID> selectedItems;
1283
1284 for( const EDA_ITEM* item : GetCurrentSelection() )
1285 selectedItems.emplace_back( item->m_Uuid );
1286
1288
1289 ReloadFootprint( newfp );
1290
1291 newfp->ClearAllNets();
1295
1296 std::vector<EDA_ITEM*> sel;
1297
1298 for( const KIID& uuid : selectedItems )
1299 {
1300 if( BOARD_ITEM* item = GetBoard()->ResolveItem( uuid, true ) )
1301 sel.push_back( item );
1302 }
1303
1304 if( !sel.empty() )
1305 m_toolManager->RunAction( ACTIONS::selectItems, &sel );
1306 }
1307 }
1308 catch( const IO_ERROR& ioe )
1309 {
1310 DisplayError( this, ioe.What() );
1311 }
1312 }
1313}
@ ERROR_INSIDE
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
constexpr int ARC_LOW_DEF
Definition base_units.h:136
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
@ NORMAL
Inactive layers are shown normally (no high-contrast mode)
@ HIDDEN
Inactive layers are hidden.
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
BOX2< VECTOR2D > BOX2D
Definition box2.h:919
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition actions.h:228
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
WINDOW_SETTINGS m_Window
Handles how to draw a screen (a board, a schematic ...)
Definition base_screen.h:37
VECTOR2D m_LocalOrigin
Relative Screen cursor coordinate (on grid) in user units.
Definition base_screen.h:86
void SetContentModified(bool aModified=true)
Definition base_screen.h:55
void InitDataPoints(const VECTOR2I &aPageSizeInternalUnits)
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1295
void UpdateUserUnits(BOARD_ITEM *aItem, KIGFX::VIEW *aView)
Update any references within aItem (or its descendants) to the user units.
Definition board.cpp:1763
const LSET & GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1048
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition board.cpp:201
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:587
void IncrementTimeStamp()
Definition board.cpp:283
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1149
void SynchronizeProperties()
Copy the current project's text variables into the boards property cache.
Definition board.cpp:2809
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition board.cpp:1846
void SetUserUnits(EDA_UNITS aUnits)
Definition board.h:902
constexpr void SetOrigin(const Vec &pos)
Definition box2.h:233
constexpr size_type GetWidth() const
Definition box2.h:210
constexpr Vec Centre() const
Definition box2.h:93
constexpr size_type GetHeight() const
Definition box2.h:211
constexpr const Vec & GetOrigin() const
Definition box2.h:206
constexpr void SetEnd(coord_type x, coord_type y)
Definition box2.h:293
static DELETED_BOARD_ITEM * GetInstance()
Definition board_item.h:543
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
void CommonSettingsChanged(int aFlags) override
Notification that common settings are updated.
void ShowChangedLanguage() override
void ReloadRequest()
Request reloading the 3D view.
FRAME_T GetFrameType() const
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void handleIconizeEvent(wxIconizeEvent &aEvent)
Handle a window iconize event.
virtual void OnModify()
Must be called after a model change in order to set the "modify" flag and do other frame-specific pro...
wxAuiManager m_auimgr
virtual bool IsContentModified() const
Get if the contents of the frame have been modified since the last save.
virtual void RecreateToolbars()
bool m_isClosing
Set by the close window event handler after frames are asked if they can close.
bool IsType(FRAME_T aType) const
virtual void ActivateGalCanvas()
Use to start up the GAL drawing canvas.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
The current canvas type.
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
void UpdateGridSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
EDA_DRAW_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
virtual void handleActivateEvent(wxActivateEvent &aEvent)
Handle a window activation event.
virtual void UpdateMsgPanel()
Redraw the message panel.
void FocusOnLocation(const VECTOR2I &aPos, bool aAllowScroll=true)
Useful to focus on a particular location, in find functions.
void UpdateStatusBar() override
Update the status bar information.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
std::vector< wxWindow * > findDialogs()
virtual void DisplayGridMsg()
Display current grid size in the status bar.
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
bool m_showBorderAndTitleBlock
bool GetShowPolarCoords() const
For those frames that support polar coordinates.
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
virtual void SetHighContrastLayer(int aLayer)
Take care of display settings for the given layer to be displayed in high contrast mode.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the #VIEW_CONTROLS instance used in the panel.
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
void StartDrawing()
Begin drawing if it was stopped previously.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:152
const KIID m_Uuid
Definition eda_item.h:531
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
void SetBrightened()
Definition eda_item.h:145
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:89
static const TOOL_EVENT ConnectivityChangedEvent
Selected item had a property changed (except movement)
Definition actions.h:345
An interface to the global shared library manager that is schematic-specific and linked to one projec...
FOOTPRINT * LoadFootprint(const wxString &aNickname, const wxString &aName, bool aKeepUUID)
Load a FOOTPRINT having aName from the library given by aNickname.
void SetPosition(const VECTOR2I &aPos) override
void SetOrientation(const EDA_ANGLE &aNewAngle)
bool IsFlipped() const
Definition footprint.h:614
const LIB_ID & GetFPID() const
Definition footprint.h:441
void ClearAllNets()
Clear (i.e.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
VECTOR2I GetPosition() const override
Definition footprint.h:403
A general implementation of a COLLECTORS_GUIDE.
Definition collectors.h:320
void SetIgnoreBlindBuriedVias(bool ignore)
Definition collectors.h:460
void SetIgnoreTracks(bool ignore)
Definition collectors.h:466
void SetIgnoreFootprintsOnFront(bool ignore)
Definition collectors.h:424
void SetIgnoreFPTextOnFront(bool ignore)
Definition collectors.h:412
void SetIgnoreMicroVias(bool ignore)
Definition collectors.h:463
void SetIgnoreFPTextOnBack(bool ignore)
Definition collectors.h:406
void SetIgnoreThroughVias(bool ignore)
Definition collectors.h:457
void SetIgnoreThroughHolePads(bool ignore)
Definition collectors.h:442
void SetIgnoreFPReferences(bool ignore)
Definition collectors.h:454
void SetIgnoreFPValues(bool ignore)
Definition collectors.h:448
void SetIgnoreFootprintsOnBack(bool ignore)
Definition collectors.h:418
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
Contains methods for drawing PCB-specific items.
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
PCB specific render settings.
Definition pcb_painter.h:78
void LoadColors(const COLOR_SETTINGS *aSettings) override
void LoadDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
Load settings related to display options (high-contrast mode, full or outline modes for vias/pads/tra...
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition pcb_view.cpp:87
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition pcb_view.cpp:53
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition pcb_view.cpp:70
void UpdateDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
Definition pcb_view.cpp:145
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void SetDefaultFont(const wxString &aFont)
void SetGapLengthRatio(double aRatio)
void SetDashLengthRatio(double aRatio)
void SetHighlightFactor(float aFactor)
void SetSelectFactor(float aFactor)
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
bool IsBOARD_ITEM() const
Definition view_item.h:98
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
void SetMirror(bool aMirrorX, bool aMirrorY)
Control the mirroring of the VIEW.
Definition view.cpp:624
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
Definition view.cpp:597
bool HasItem(const VIEW_ITEM *aItem) const
Indicates whether or not the given item has been added to the view.
Definition view.cpp:1821
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
Definition view.cpp:534
void RecacheAllItems()
Rebuild GAL display lists.
Definition view.cpp:1552
bool IsMirroredY() const
Return true if view is flipped across the Y axis.
Definition view.h:263
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition view.cpp:1686
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:225
void UpdateAllItemsConditionally(int aUpdateFlags, std::function< bool(VIEW_ITEM *)> aCondition)
Update items in the view according to the given flags and condition.
Definition view.cpp:1702
Definition kiid.h:44
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:311
std::optional< LIBRARY_TABLE_ROW * > GetRow(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::GetRow but filtered to the LIBRARY_TABLE_TYPE of this adapter.
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false)
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:83
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
A class to perform either relative or absolute display origin transforms for a single axis of a point...
Definition pad.h:61
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition page_info.h:173
DISPLAY_OPTIONS m_Display
static TOOL_ACTION rehatchShapes
SEVERITY GetSeverity(int aErrorCode) const override
std::unique_ptr< wxFileSystemWatcher > m_watcher
virtual void ReloadFootprint(FOOTPRINT *aFootprint)
Reload the footprint from the library.
virtual void OnDisplayOptionsChanged()
void handleIconizeEvent(wxIconizeEvent &aEvent) override
Handle a window iconize event.
ORIGIN_TRANSFORMS & GetOriginTransforms() override
Return a reference to the default ORIGIN_TRANSFORMS object.
virtual const PCB_PLOT_PARAMS & GetPlotSettings() const
Return the PCB_PLOT_PARAMS for the BOARD owned by this frame.
std::unique_ptr< NL_PCBNEW_PLUGIN > m_spaceMouse
wxDateTime m_watcherLastModified
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void handleActivateEvent(wxActivateEvent &aEvent) override
Handle a window activation event.
void setFPWatcher(FOOTPRINT *aFootprint)
Create or removes a watcher on the specified footprint.
virtual void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Return bounding box of document with option to not include some items.
const VECTOR2I GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
PCBNEW_SETTINGS * GetPcbNewSettings() const
virtual void SwitchLayer(PCB_LAYER_ID aLayer)
Change the active layer in the frame.
PCB_BASE_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
void OnModify() override
Must be called after a change in order to set the "modify" flag and update other data structures and ...
const VECTOR2I & GetAuxOrigin() const
virtual PCB_VIEWERS_SETTINGS_BASE * GetViewerSettingsBase() const
const VECTOR2I GetUserOrigin() const
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
void FocusOnItems(std::vector< BOARD_ITEM * > aItems, PCB_LAYER_ID aLayer=UNDEFINED_LAYER, bool aAllowScroll=true)
void OnFPChange(wxFileSystemWatcherEvent &aEvent)
Handler for FP change events.
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
const VECTOR2I & GetGridOrigin() const override
Return the absolute coordinates of the origin of the snap grid.
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
const TITLE_BLOCK & GetTitleBlock() const override
const PAGE_INFO & GetPageSettings() const override
BOX2I GetBoardBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
EDA_ITEM * ResolveItem(const KIID &aId, bool aAllowNullptrReturn=false) const override
Fetch an item by KIID.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual void ActivateGalCanvas() override
Use to start up the GAL drawing canvas.
void SetDrawBgColor(const COLOR4D &aColor) override
void OnFpChangeDebounceTimer(wxTimerEvent &aEvent)
Handler for the filesystem watcher debounce timer.
virtual void SetBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
virtual PCB_LAYER_ID GetActiveLayer() const
virtual void SetPageSettings(const PAGE_INFO &aPageSettings) override
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock) override
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
BOARD * GetBoard() const
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Return the BOARD_DESIGN_SETTINGS for the open project.
virtual void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual void AddFootprintToBoard(FOOTPRINT *aFootprint)
Add the given footprint to the board.
virtual void doReCreateMenuBar() override
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aRefresh=true)
Update the current display options.
GENERAL_COLLECTORS_GUIDE GetCollectorsGuide()
virtual void SetPlotSettings(const PCB_PLOT_PARAMS &aSettings)
void FocusOnItem(EDA_ITEM *aItem, bool aAllowScroll=true) override
Focus on a particular canvas item.
PCB_DISPLAY_OPTIONS m_displayOptions
FOOTPRINT_EDITOR_SETTINGS * GetFootprintEditorSettings() const
void SetGridOrigin(const VECTOR2I &aPoint) override
PCB_ORIGIN_TRANSFORMS m_originTransforms
EDA_3D_VIEWER_FRAME * CreateAndShow3D_Frame()
Show the 3D view frame.
wxTimer m_watcherDebounceTimer
EDA_3D_VIEWER_FRAME * Get3DViewerFrame()
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Helper to retrieve the current color settings.
wxFileName m_watcherFileName
virtual void Update3DView(bool aMarkDirty, bool aRefresh, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
virtual void UpdateStatusBar() override
Update the status bar information.
bool m_FlipBoardView
true if the board is flipped to show the mirrored view
HIGH_CONTRAST_MODE m_ContrastModeDisplay
How inactive layers are displayed.
void UpdateColors()
Update the color settings in the painter and GAL.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void DisplayBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Add all items from the current board to the VIEW, so they can be displayed by GAL.
void RedrawRatsnest()
Return the bounding box of the view that should be used if model is not valid.
Parameters and options when plotting/printing a board.
PCB_LAYER_ID m_Active_Layer
Definition pcb_screen.h:38
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
A progress reporter interface for use in multi-threaded environments.
static void Cleanup3DCache(PROJECT *aProject)
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
RAII class that sets an value at construction and resets it to the original value at destruction.
T * GetAppSettings(const char *aFilename)
Return a handle to the a given settings by type.
Represent a set of closed polygons.
void ClearArcs()
Removes all arc references from all the outlines and holes in the polyset.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void Deflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError)
void BooleanIntersection(const SHAPE_POLY_SET &b)
Perform boolean polyset intersection.
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition title_block.h:37
TOOL_MANAGER * m_toolManager
TOOL_DISPATCHER * m_toolDispatcher
bool ToolStackIsEmpty()
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
virtual SELECTION & GetCurrentSelection()
Get the current selection from the canvas area.
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition tool_base.h:76
@ GAL_SWITCH
Rendering engine changes.
Definition tool_base.h:78
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
EDA_UNITS GetUserUnits() const
Handle a list of polygons defining a copper zone.
Definition zone.h:70
SHAPE_POLY_SET GetBoardOutline() const
Definition zone.cpp:835
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the zone shape to a closed polygon Used in filling zones calculations Circles and arcs are ap...
Definition zone.cpp:1857
@ CLEANUP_FIRST
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:274
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition confirm.cpp:245
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
@ ALLOW_ACUTE_CORNERS
just inflate the polygon. Acute angles create spikes
#define _(s)
Declaration of the eda_3d_viewer class.
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
#define QUALIFIED_VIEWER3D_FRAMENAME(parent)
@ RECURSE
Definition eda_item.h:49
#define IS_NEW
New item, just created.
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:29
@ FRAME_PCB_EDITOR
Definition frame_type.h:38
@ FRAME_CVPCB_DISPLAY
Definition frame_type.h:49
@ FRAME_FOOTPRINT_VIEWER
Definition frame_type.h:41
@ FRAME_FOOTPRINT_WIZARD
Definition frame_type.h:42
@ FRAME_FOOTPRINT_PREVIEW
Definition frame_type.h:44
@ FRAME_FOOTPRINT_CHOOSER
Definition frame_type.h:40
@ FRAME_FOOTPRINT_EDITOR
Definition frame_type.h:39
@ FRAME_PCB_DISPLAY3D
Definition frame_type.h:43
@ FRAME_CVPCB
Definition frame_type.h:48
static const std::string KiCadFootprintFileExtension
const wxChar *const traceLibWatch
Flag to enable debug output for library file watch refreshes.
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:675
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
Definition layer_ids.h:255
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition layer_ids.h:262
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored).
Definition layer_ids.h:288
@ LAYER_TRACKS
Definition layer_ids.h:263
@ LAYER_FP_TEXT
Definition layer_ids.h:236
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
Definition layer_ids.h:256
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition layer_ids.h:259
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition layer_ids.h:228
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ Edge_Cuts
Definition layer_ids.h:108
@ B_Mask
Definition layer_ids.h:94
@ F_Mask
Definition layer_ids.h:93
@ UNDEFINED_LAYER
Definition layer_ids.h:57
Message panel definition file.
@ COLOR
Color has changed.
Definition view_item.h:50
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
@ GEOMETRY
Position or shape has changed.
Definition view_item.h:51
@ ALL
All except INITIAL_ADD.
Definition view_item.h:55
Declaration of the NL_PCBNEW_PLUGIN class.
wxDEFINE_EVENT(EDA_EVT_BOARD_CHANGING, wxCommandEvent)
@ PCB_ORIGIN_AUX
@ PCB_ORIGIN_GRID
@ PCB_ORIGIN_PAGE
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
SEVERITY
@ RPT_SEVERITY_ACTION
KIWAY Kiway(KFCTL_STANDALONE)
float highlight_factor
How much to brighten highlighted objects by.
float select_factor
How much to brighten selected objects by.
wxString user_grid_x
std::vector< GRID > grids
wxString user_grid_y
Common grid settings, available to every frame.
GRID_SETTINGS grid
#define TEXTVARS_CHANGED
wxLogTrace helper definitions.
double RAD2DEG(double rad)
Definition trigo.h:163
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:81
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:99
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:96
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:90
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:97
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:86
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:101
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:85
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:83
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition typeinfo.h:92
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:94
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:79
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:95
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:80
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:91
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:89
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:98
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682
VECTOR2D ToVECTOR2D(const wxPoint &aPoint)
Definition vector2wx.h:36
Definition of file extensions used in Kicad.