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
24#include <boost/version.hpp>
25#include <boost/uuid/entropy_error.hpp>
26
28#include <advanced_config.h>
29#include <base_units.h>
30#include <board.h>
31#include <cleanup_item.h>
32#include <collectors.h>
33#include <confirm.h>
34#include <footprint.h>
38#include <lset.h>
39#include <kiface_base.h>
40#include <pad.h>
41#include <pcb_painter.h>
42#include <pcbnew_id.h>
43#include <pcbnew_settings.h>
44#include <pcb_base_frame.h>
45#include <pcb_draw_panel_gal.h>
46#include <pcb_track.h>
47#include <pgm_base.h>
48#include <project_pcb.h>
49#include <scoped_set_reset.h>
50#include <trace_helpers.h>
52#include <zone.h>
53
54#include <math/vector2d.h>
55#include <math/vector2wx.h>
56#include <widgets/msgpanel.h>
57#include <wx/fswatcher.h>
58
61#include <tool/tool_manager.h>
63#include <tools/pcb_actions.h>
64#include <tool/grid_menu.h>
66
67#if defined(__linux__) || defined(__FreeBSD__)
69#else
71#endif
72
75
76wxDEFINE_EVENT( EDA_EVT_BOARD_CHANGING, wxCommandEvent );
77wxDEFINE_EVENT( EDA_EVT_BOARD_CHANGED, wxCommandEvent );
78
79PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
80 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
81 long aStyle, const wxString& aFrameName ) :
82 EDA_DRAW_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName, pcbIUScale ),
83 m_pcb( nullptr ),
84 m_originTransforms( *this ),
86{
88}
89
90
92{
93 // Ensure m_canvasType is up to date, to save it in config
94 if( GetCanvas() )
96
97 if( m_toolManager )
98 m_toolManager->ClearModel();
99
100 delete m_pcb;
101 m_pcb = nullptr;
102}
103
104
105bool PCB_BASE_FRAME::canCloseWindow( wxCloseEvent& aEvent )
106{
107 // Close modeless dialogs. They're trouble when they get destroyed after the frame and/or
108 // board.
109 wxWindow* viewer3D = Get3DViewerFrame();
110
111 if( viewer3D )
112 viewer3D->Close( true );
113
114 // Similarly, wxConvBrokenFileNames uses some statically allocated variables that make it
115 // crash when run later from a d'tor.
117
118 return true;
119}
120
121
122void PCB_BASE_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
123{
125
126 if( m_spaceMouse )
127 m_spaceMouse->SetFocus( aEvent.GetActive() );
128}
129
130
131void PCB_BASE_FRAME::handleIconizeEvent( wxIconizeEvent& aEvent )
132{
134
135 if( m_spaceMouse && aEvent.IsIconized() )
136 m_spaceMouse->SetFocus( false );
137}
138
139
141{
142 wxWindow* frame = FindWindowByName( QUALIFIED_VIEWER3D_FRAMENAME( this ) );
143 return dynamic_cast<EDA_3D_VIEWER_FRAME*>( frame );
144}
145
146
147void PCB_BASE_FRAME::Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle )
148{
149 EDA_3D_VIEWER_FRAME* draw3DFrame = Get3DViewerFrame();
150
151 if( draw3DFrame )
152 {
153 if( aTitle )
154 draw3DFrame->SetTitle( *aTitle );
155
156 if( aMarkDirty )
157 draw3DFrame->ReloadRequest();
158
159 if( aRefresh )
160 draw3DFrame->Redraw();
161 }
162}
163
164
166{
167 if( m_pcb != aBoard )
168 {
169 delete m_pcb;
170 m_pcb = aBoard;
171
172 if( GetBoard() )
174
175 if( GetBoard() && GetCanvas() )
176 {
178
179 if( rs )
180 {
181 rs->SetDashLengthRatio( GetBoard()->GetPlotOptions().GetDashedLineDashRatio() );
182 rs->SetGapLengthRatio( GetBoard()->GetPlotOptions().GetDashedLineGapRatio() );
183 }
184 }
185
186 wxCommandEvent e( EDA_EVT_BOARD_CHANGED );
187 ProcessEventLocally( e );
188 }
189}
190
191
193{
194 if( aFootprint )
195 {
196 GetBoard()->Add( aFootprint, ADD_MODE::APPEND );
197
198 aFootprint->SetFlags( IS_NEW );
199 aFootprint->SetPosition( VECTOR2I( 0, 0 ) ); // cursor in GAL may not be initialized yet
200
201 // Put it on FRONT layer (note that it might be stored flipped if the lib is an archive
202 // built from a board)
203 if( aFootprint->IsFlipped() )
204 aFootprint->Flip( aFootprint->GetPosition(), GetPcbNewSettings()->m_FlipDirection );
205
206 // Place it in orientation 0 even if it is not saved with orientation 0 in lib (note that
207 // it might be stored in another orientation if the lib is an archive built from a board)
208 aFootprint->SetOrientation( ANGLE_0 );
209
210 GetBoard()->UpdateUserUnits( aFootprint, GetCanvas()->GetView() );
211
213 }
214}
215
216
217EDA_ITEM* PCB_BASE_FRAME::ResolveItem( const KIID& aId, bool aAllowNullptrReturn ) const
218{
219 return GetBoard()->ResolveItem( aId, aAllowNullptrReturn );
220}
221
222void PCB_BASE_FRAME::FocusOnItem( EDA_ITEM* aItem, bool aAllowScroll )
223{
224 // nullptr will clear the current focus
225 if( aItem != nullptr && !aItem->IsBOARD_ITEM() )
226 return;
227
228 FocusOnItem( static_cast<BOARD_ITEM*>( aItem ), UNDEFINED_LAYER, aAllowScroll );
229}
230
231void PCB_BASE_FRAME::FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer, bool aAllowScroll )
232{
233 std::vector<BOARD_ITEM*> items;
234
235 if( aItem )
236 items.push_back( aItem );
237
238 FocusOnItems( items, aLayer, aAllowScroll );
239}
240
241
242void PCB_BASE_FRAME::FocusOnItems( std::vector<BOARD_ITEM*> aItems, PCB_LAYER_ID aLayer, bool aAllowScroll )
243{
244 static std::vector<KIID> lastBrightenedItemIDs;
245
246 bool itemsUnbrightened = false;
247
248 for( KIID lastBrightenedItemID : lastBrightenedItemIDs )
249 {
250 if( BOARD_ITEM* lastItem = GetBoard()->ResolveItem( lastBrightenedItemID, true ) )
251 {
252 lastItem->ClearBrightened();
253 GetCanvas()->GetView()->Update( lastItem );
254 itemsUnbrightened = true;
255 }
256 }
257
258 if( itemsUnbrightened )
259 GetCanvas()->Refresh();
260
261 lastBrightenedItemIDs.clear();
262
263 if( aItems.empty() )
264 return;
265
266 for( BOARD_ITEM* item : aItems )
267 {
268 if( item && item != DELETED_BOARD_ITEM::GetInstance() )
269 {
270 item->SetBrightened();
271 lastBrightenedItemIDs.push_back( item->m_Uuid );
272
273 item->RunOnChildren(
274 [&]( BOARD_ITEM* child )
275 {
276 child->SetBrightened();
277 lastBrightenedItemIDs.push_back( child->m_Uuid );
278 },
280
281 GetCanvas()->GetView()->Update( item );
282 }
283 }
284
285 VECTOR2I focusPt;
286 KIGFX::VIEW* view = GetCanvas()->GetView();
287 SHAPE_POLY_SET viewportPoly( view->GetViewport() );
288
289 for( wxWindow* dialog : findDialogs() )
290 {
291 wxPoint dialogPos = GetCanvas()->ScreenToClient( dialog->GetScreenPosition() );
292 SHAPE_POLY_SET dialogPoly( BOX2D( view->ToWorld( ToVECTOR2D( dialogPos ), true ),
293 view->ToWorld( ToVECTOR2D( dialog->GetSize() ), false ) ) );
294
295 try
296 {
297 viewportPoly.BooleanSubtract( dialogPoly );
298 }
299 catch( const std::exception& e )
300 {
301 wxFAIL_MSG( wxString::Format( wxT( "Clipper exception occurred: %s" ), e.what() ) );
302 }
303 }
304
305 SHAPE_POLY_SET itemPoly, clippedPoly;
306
307 for( BOARD_ITEM* item : aItems )
308 {
309 if( item && item != DELETED_BOARD_ITEM::GetInstance() )
310 {
311 // Focus on the object's location. Prefer a visible part of the object to its anchor
312 // in order to keep from scrolling around.
313
314 focusPt = item->GetPosition();
315
316 if( aLayer == UNDEFINED_LAYER && item->GetLayerSet().any() )
317 aLayer = item->GetLayerSet().Seq()[0];
318
319 switch( item->Type() )
320 {
321 case PCB_FOOTPRINT_T:
322 try
323 {
324 itemPoly = static_cast<FOOTPRINT*>( item )->GetBoundingHull();
325 }
326 catch( const std::exception& e )
327 {
328 wxFAIL_MSG( wxString::Format( wxT( "Clipper exception occurred: %s" ), e.what() ) );
329 }
330
331 break;
332
333 case PCB_PAD_T:
334 case PCB_MARKER_T:
335 case PCB_VIA_T:
336 FocusOnLocation( item->GetFocusPosition(), aAllowScroll );
337 GetCanvas()->Refresh();
338 return;
339
340 case PCB_SHAPE_T:
341 case PCB_FIELD_T:
342 case PCB_TEXT_T:
343 case PCB_TEXTBOX_T:
344 case PCB_BARCODE_T:
345 case PCB_TRACE_T:
346 case PCB_ARC_T:
348 case PCB_DIM_LEADER_T:
349 case PCB_DIM_CENTER_T:
350 case PCB_DIM_RADIAL_T:
352 item->TransformShapeToPolygon( itemPoly, aLayer, 0, pcbIUScale.mmToIU( 0.1 ), ERROR_INSIDE );
353 break;
354
355 case PCB_ZONE_T:
356 {
357 ZONE* zone = static_cast<ZONE*>( item );
358#if 0
359 // Using the filled area shapes to find a Focus point can give good results, but
360 // unfortunately the calculations are highly time consuming, even for not very
361 // large areas (can be easily a few minutes for large areas).
362 // so we used only the zone outline that usually do not have too many vertices.
363 zone->TransformShapeToPolygon( itemPoly, aLayer, 0, pcbIUScale.mmToIU( 0.1 ), ERROR_INSIDE );
364
365 if( itemPoly.IsEmpty() )
366 itemPoly = zone->GetBoardOutline();
367#else
368 // much faster calculation time when using only the zone outlines
369 itemPoly = zone->GetBoardOutline();
370#endif
371
372 break;
373 }
374
375 default:
376 {
377 BOX2I item_bbox = item->GetBoundingBox();
378 itemPoly.NewOutline();
379 itemPoly.Append( item_bbox.GetOrigin() );
380 itemPoly.Append( item_bbox.GetOrigin() + VECTOR2I( item_bbox.GetWidth(), 0 ) );
381 itemPoly.Append( item_bbox.GetOrigin() + VECTOR2I( 0, item_bbox.GetHeight() ) );
382 itemPoly.Append( item_bbox.GetOrigin() + VECTOR2I( item_bbox.GetWidth(),
383 item_bbox.GetHeight() ) );
384 break;
385 }
386 }
387
388 try
389 {
390 itemPoly.ClearArcs();
391 viewportPoly.ClearArcs();
392 clippedPoly.BooleanIntersection( itemPoly, viewportPoly );
393 }
394 catch( const std::exception& e )
395 {
396 wxFAIL_MSG( wxString::Format( wxT( "Clipper exception occurred: %s" ), e.what() ) );
397 }
398
399 if( !clippedPoly.IsEmpty() )
400 itemPoly = clippedPoly;
401 }
402 }
403
404 /*
405 * Perform a step-wise deflate to find the visual-center-of-mass
406 */
407
408 if( itemPoly.IsEmpty() )
409 {
410 FocusOnLocation( focusPt, aAllowScroll );
411 GetCanvas()->Refresh();
412 return;
413 }
414
415 BOX2I bbox = itemPoly.BBox();
416 int step = std::min( bbox.GetWidth(), bbox.GetHeight() ) / 10;
417
418 // Tiny shapes can quantize to a zero deflate step
419 if( step <= 0 )
420 {
421 FocusOnLocation( bbox.Centre(), aAllowScroll );
422 GetCanvas()->Refresh();
423 return;
424 }
425
426 while( !itemPoly.IsEmpty() )
427 {
428 focusPt = itemPoly.BBox().Centre();
429
430 try
431 {
433 }
434 catch( const std::exception& e )
435 {
436 wxFAIL_MSG( wxString::Format( wxT( "Clipper exception occurred: %s" ), e.what() ) );
437 }
438 }
439
440 FocusOnLocation( focusPt, aAllowScroll );
441
442 GetCanvas()->Refresh();
443}
444
445
447{
448 KIGFX::PCB_VIEW* view = GetCanvas()->GetView();
449
450 if( view && GetBoard()->m_SolderMaskBridges && view->HasItem( GetBoard()->m_SolderMaskBridges ) )
451 view->Remove( GetBoard()->m_SolderMaskBridges );
452}
453
454
456{
457 KIGFX::PCB_VIEW* view = GetCanvas()->GetView();
458
459 if( view && GetBoard()->m_SolderMaskBridges )
460 {
461 if( view->HasItem( GetBoard()->m_SolderMaskBridges ) )
462 view->Remove( GetBoard()->m_SolderMaskBridges );
463
464 view->Add( GetBoard()->m_SolderMaskBridges );
465 }
466}
467
468
469void PCB_BASE_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
470{
471 m_pcb->SetPageSettings( aPageSettings );
472
473 if( GetScreen() )
474 GetScreen()->InitDataPoints( aPageSettings.GetSizeIU( pcbIUScale.IU_PER_MILS ) );
475}
476
477
479{
480 return m_pcb->GetPageSettings();
481}
482
483
485{
486 // this function is only needed because EDA_DRAW_FRAME is not compiled
487 // with either -DPCBNEW or -DEESCHEMA, so the virtual is used to route
488 // into an application specific source file.
489 return m_pcb->GetPageSettings().GetSizeIU( pcbIUScale.IU_PER_MILS );
490}
491
492
494{
495 return m_pcb->GetDesignSettings().GetGridOrigin();
496}
497
498
500{
501 m_pcb->GetDesignSettings().SetGridOrigin( aPoint );
502}
503
504
506{
507 return m_pcb->GetDesignSettings().GetAuxOrigin();
508}
509
510
512{
513 VECTOR2I origin( 0, 0 );
514
515 switch( GetPcbNewSettings()->m_Display.m_DisplayOrigin )
516 {
518 case PCB_DISPLAY_ORIGIN::PCB_ORIGIN_AUX: origin = GetAuxOrigin(); break;
520 default: wxASSERT( false ); break;
521 }
522
523 return origin;
524}
525
530
531
533{
534 return m_pcb->GetTitleBlock();
535}
536
537
539{
540 m_pcb->SetTitleBlock( aTitleBlock );
541}
542
543
545{
546 return m_pcb->GetDesignSettings();
547}
548
549
551{
552 m_drawBgColor= aColor;
553 m_auimgr.Update();
554}
555
556
558{
559 return m_pcb->GetPlotOptions();
560}
561
562
564{
565 m_pcb->SetPlotOptions( aSettings );
566
567 // Plot Settings can also change the "tent vias" setting, which can affect the solder mask.
568 LSET visibleLayers = GetBoard()->GetVisibleLayers();
569
570 if( visibleLayers.test( F_Mask ) || visibleLayers.test( B_Mask ) )
571 {
573 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
574 {
575 BOARD_ITEM* item = nullptr;
576
577 if( aItem->IsBOARD_ITEM() )
578 item = static_cast<BOARD_ITEM*>( aItem );
579
580 // Note: KIGFX::REPAINT isn't enough for things that go from invisible to
581 // visible as they won't be found in the view layer's itemset for re-painting.
582 if( item && item->Type() == PCB_VIA_T )
583 return KIGFX::ALL;
584
585 return 0;
586 } );
587
588 GetCanvas()->Refresh();
589 }
590}
591
592
593BOX2I PCB_BASE_FRAME::GetBoardBoundingBox( bool aBoardEdgesOnly ) const
594{
595 BOX2I area = aBoardEdgesOnly ? m_pcb->GetBoardEdgesBoundingBox() : m_pcb->GetBoundingBox();
596
597 if( area.GetWidth() == 0 && area.GetHeight() == 0 )
598 {
599 VECTOR2I pageSize = GetPageSizeIU();
600
602 {
603 area.SetOrigin( 0, 0 );
604 area.SetEnd( pageSize.x, pageSize.y );
605 }
606 else
607 {
608 area.SetOrigin( -pageSize.x / 2, -pageSize.y / 2 );
609 area.SetEnd( pageSize.x / 2, pageSize.y / 2 );
610 }
611 }
612
613 return area;
614}
615
616
617const BOX2I PCB_BASE_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
618{
619 /* "Zoom to Fit" calls this with "aIncludeAllVisible" as true. Since that feature
620 * always ignored the page and border, this function returns a bbox without them
621 * as well when passed true. This technically is not all things visible, but it
622 * keeps behavior consistent.
623 *
624 * When passed false, this function returns a bbox of just the board edge. This
625 * allows things like fabrication text or anything else outside the board edge to
626 * be ignored, and just zooms up to the board itself.
627 *
628 * Calling "GetBoardBoundingBox(true)" when edge cuts are turned off will return
629 * the entire page and border, so we call "GetBoardBoundingBox(false)" instead.
630 */
631 if( aIncludeAllVisible || !m_pcb->IsLayerVisible( Edge_Cuts ) )
632 return GetBoardBoundingBox( false );
633 else
634 return GetBoardBoundingBox( true );
635}
636
637
638// Virtual function
642
643
645{
646 return static_cast<PCB_SCREEN*>( EDA_DRAW_FRAME::GetScreen() );
647}
648
649
651{
652 GetScreen()->m_Active_Layer = aLayer;
653}
654
655
660
661
663{
664 // call my base class
666
667 // tooltips in toolbars
669
671
672 if( viewer3D )
673 viewer3D->ShowChangedLanguage();
674}
675
676
678{
679 EDA_3D_VIEWER_FRAME* draw3DFrame = Get3DViewerFrame();
680
681 if( !draw3DFrame )
682 draw3DFrame = new EDA_3D_VIEWER_FRAME( &Kiway(), this, _( "3D Viewer" ) );
683
684 // Raising the window does not show the window on Windows if iconized. This should work
685 // on any platform.
686 if( draw3DFrame->IsIconized() )
687 draw3DFrame->Iconize( false );
688
689 draw3DFrame->Raise();
690 draw3DFrame->Show( true );
691
692 // Raising the window does not set the focus on Linux. This should work on any platform.
693 if( wxWindow::FindFocus() != draw3DFrame )
694 draw3DFrame->SetFocus();
695
696 // Allocate a slice of time to display the 3D frame
697 // a call to wxSafeYield() should be enough (and better), but on Linux we need
698 // to call wxYield()
699 // otherwise the activity messages are not displayed during the first board loading
700 wxYield();
701
702 // Note, the caller is responsible to load/update the board 3D view.
703 // after frame creation the board is not automatically created.
704
705 return draw3DFrame;
706}
707
708
710{
711 PCB_LAYER_ID preslayer = GetActiveLayer();
712 auto& displ_opts = GetDisplayOptions();
713
714 // Check if the specified layer matches the present layer
715 if( layer == preslayer )
716 return;
717
718 // Copper layers cannot be selected unconditionally; how many of those layers are
719 // currently enabled needs to be checked.
720 if( IsCopperLayer( layer ) )
721 {
722 if( layer > m_pcb->GetCopperLayerStackMaxId() )
723 return;
724 }
725
726 // Is yet more checking required? E.g. when the layer to be selected is a non-copper
727 // layer, or when switching between a copper layer and a non-copper layer, or vice-versa?
728 // ...
729
730 SetActiveLayer( layer );
731
732 if( displ_opts.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL )
733 GetCanvas()->Refresh();
734}
735
736
738{
739 GENERAL_COLLECTORS_GUIDE guide( m_pcb->GetVisibleLayers(), GetActiveLayer(),
740 GetCanvas()->GetView() );
741
742 // account for the globals
743 guide.SetIgnoreFPTextOnBack( !m_pcb->IsElementVisible( LAYER_FP_TEXT ) );
744 guide.SetIgnoreFPTextOnFront( !m_pcb->IsElementVisible( LAYER_FP_TEXT ) );
745 guide.SetIgnoreFootprintsOnBack( !m_pcb->IsElementVisible( LAYER_FOOTPRINTS_BK ) );
746 guide.SetIgnoreFootprintsOnFront( !m_pcb->IsElementVisible( LAYER_FOOTPRINTS_FR ) );
747 guide.SetIgnoreThroughHolePads( ! m_pcb->IsElementVisible( LAYER_PADS ) );
748 guide.SetIgnoreFPValues( !m_pcb->IsElementVisible( LAYER_FP_VALUES ) );
749 guide.SetIgnoreFPReferences( !m_pcb->IsElementVisible( LAYER_FP_REFERENCES ) );
750 guide.SetIgnoreThroughVias( ! m_pcb->IsElementVisible( LAYER_VIAS ) );
751 guide.SetIgnoreBlindBuriedVias( ! m_pcb->IsElementVisible( LAYER_VIAS ) );
752 guide.SetIgnoreMicroVias( ! m_pcb->IsElementVisible( LAYER_VIAS ) );
753 guide.SetIgnoreTracks( ! m_pcb->IsElementVisible( LAYER_TRACKS ) );
754
755 return guide;
756}
757
758
760{
762
763 BASE_SCREEN* screen = GetScreen();
764
765 if( !screen )
766 return;
767
768 wxString line;
770
771 if( GetShowPolarCoords() ) // display polar coordinates
772 {
773 double dx = cursorPos.x - screen->m_LocalOrigin.x;
774 double dy = cursorPos.y - screen->m_LocalOrigin.y;
775 double theta = RAD2DEG( atan2( -dy, dx ) );
776 double ro = hypot( dx, dy );
777
778 line.Printf( wxT( "r %s theta %.3f" ),
779 MessageTextFromValue( ro, false ),
780 theta );
781
782 SetStatusText( line, 3 );
783 }
784
785 // Transform absolute coordinates for user origin preferences
786 double userXpos = m_originTransforms.ToDisplayAbsX( static_cast<double>( cursorPos.x ) );
787 double userYpos = m_originTransforms.ToDisplayAbsY( static_cast<double>( cursorPos.y ) );
788
789 // Display absolute coordinates:
790 line.Printf( wxT( "X %s Y %s" ),
791 MessageTextFromValue( userXpos, false ),
792 MessageTextFromValue( userYpos, false ) );
793 SetStatusText( line, 2 );
794
795 if( !GetShowPolarCoords() ) // display relative cartesian coordinates
796 {
797 // Calculate relative coordinates
798 double relXpos = cursorPos.x - screen->m_LocalOrigin.x;
799 double relYpos = cursorPos.y - screen->m_LocalOrigin.y;
800
801 // Transform relative coordinates for user origin preferences
802 userXpos = m_originTransforms.ToDisplayRelX( relXpos );
803 userYpos = m_originTransforms.ToDisplayRelY( relYpos );
804
805 line.Printf( wxT( "dx %s dy %s dist %s" ),
806 MessageTextFromValue( userXpos, false ),
807 MessageTextFromValue( userYpos, false ),
808 MessageTextFromValue( hypot( userXpos, userYpos ), false ) );
809 SetStatusText( line, 3 );
810 }
811
813}
814
815
817{
818 EDA_DRAW_FRAME::unitsChangeRefresh(); // Update the status bar.
819
820 if( GetBoard() )
822
824}
825
826
828{
830
831 // Move legacy user grids to grid list
832 if( !aCfg->m_Window.grid.user_grid_x.empty() )
833 {
834 aCfg->m_Window.grid.grids.emplace_back( GRID{ "User Grid", aCfg->m_Window.grid.user_grid_x,
835 aCfg->m_Window.grid.user_grid_y } );
836 aCfg->m_Window.grid.user_grid_x = wxEmptyString;
837 aCfg->m_Window.grid.user_grid_y = wxEmptyString;
838 }
839
840 // Some, but not all, derived classes have a PCBNEW_SETTINGS.
841 if( PCBNEW_SETTINGS* pcbnew_cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg ) )
842 m_polarCoords = pcbnew_cfg->m_PolarCoords;
843
844 wxASSERT( GetCanvas() );
845
846 if( GetCanvas() )
847 {
849
850 if( rs )
851 {
854 rs->SetDefaultFont( wxEmptyString ); // Always the KiCad font for PCBs
855 }
856 }
857}
858
859
861{
862 if( aErrorCode >= CLEANUP_FIRST )
863 return RPT_SEVERITY_ACTION;
864
866
867 return bds.m_DRCSeverities[ aErrorCode ];
868}
869
870
872{
874
875 // Some, but not all derived classes have a PCBNEW_SETTINGS.
876 PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
877
878 if( cfg )
880}
881
882
887
888
893
894
916
917
919{
920 static MAGNETIC_SETTINGS fallback;
921
923 return &cfg->m_MagneticItems;
924
925 return &fallback;
926}
927
928
930{
932
933 KIGFX::VIEW* view = GetCanvas()->GetView();
934 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view->GetPainter() );
935 PCB_RENDER_SETTINGS* settings = painter->GetSettings();
936
937 settings->LoadColors( GetColorSettings( true ) );
940
941 if( aFlags & TEXTVARS_CHANGED )
943
944 // Note: KIGFX::REPAINT isn't enough for things that go from invisible to visible as
945 // they won't be found in the view layer's itemset for re-painting.
947 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
948 {
949 if( dynamic_cast<RATSNEST_VIEW_ITEM*>( aItem ) )
950 {
951 return KIGFX::ALL; // ratsnest display
952 }
953 else if( dynamic_cast<PCB_TRACK*>( aItem ) )
954 {
955 return KIGFX::REPAINT; // track, arc & via clearance display
956 }
957 else if( dynamic_cast<PAD*>( aItem ) )
958 {
959 return KIGFX::REPAINT; // pad clearance display
960 }
961 else if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ) )
962 {
963 if( text->HasTextVars() )
964 {
965 text->ClearRenderCache();
966 text->ClearBoundingBoxCache();
968 }
969 }
970
971 return 0;
972 } );
973
975
977
978 // The 3D viewer isn't in the Kiway, so send its update manually
980
981 if( viewer )
982 viewer->CommonSettingsChanged( aFlags );
983}
984
985
987{
989
992
993 if( m_isClosing )
994 return;
995
998}
999
1000
1007
1008
1013
1014
1016{
1018
1019 EDA_DRAW_PANEL_GAL* canvas = GetCanvas();
1020 KIGFX::VIEW* view = canvas->GetView();
1021
1022 if( m_toolManager )
1023 {
1024 m_toolManager->SetEnvironment( m_pcb, view, canvas->GetViewControls(), config(), this );
1025
1026 m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH );
1027 }
1028
1029 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view->GetPainter() );
1030 KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
1031 const PCB_DISPLAY_OPTIONS& displ_opts = GetDisplayOptions();
1032
1033 settings->LoadDisplayOptions( displ_opts );
1034 settings->LoadColors( GetColorSettings() );
1036
1037 view->RecacheAllItems();
1039 canvas->StartDrawing();
1040
1041 try
1042 {
1043 if( !m_spaceMouse )
1044 {
1045#if defined(__linux__) || defined(__FreeBSD__)
1046 m_spaceMouse = std::make_unique<SPNAV_2D_PLUGIN>( GetCanvas() );
1047 m_spaceMouse->SetScale( 0.01 );
1048#else
1049 m_spaceMouse = std::make_unique<NL_PCBNEW_PLUGIN>( GetCanvas() );
1050#endif
1051 }
1052 }
1053 catch( const std::exception& e )
1054 {
1055 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), wxS( "%s" ), e.what() );
1056 }
1057 catch( ... )
1058 {
1059 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ),
1060 wxT( "Unknown exception during SpaceMouse initialization" ) );
1061 }
1062}
1063
1064
1066 const PCB_DISPLAY_OPTIONS& aNew )
1067{
1068 // only zone mode and board flip change geometry
1069 // colour opacity contrast are recolour only
1070 return aOld.m_ZoneDisplayMode != aNew.m_ZoneDisplayMode
1071 || aOld.m_FlipBoardView != aNew.m_FlipBoardView;
1072}
1073
1074
1075void PCB_BASE_FRAME::SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions, bool aRefresh )
1076{
1077 bool needsRecache = displayOptionsRequireRecache( m_displayOptions, aOptions );
1078 m_displayOptions = aOptions;
1079
1080 EDA_DRAW_PANEL_GAL* canvas = GetCanvas();
1081 KIGFX::PCB_VIEW* view = static_cast<KIGFX::PCB_VIEW*>( canvas->GetView() );
1082
1083 view->UpdateDisplayOptions( aOptions );
1084 view->SetMirror( aOptions.m_FlipBoardView, view->IsMirroredY() );
1085
1086 // skip recache for colour/alpha-only changes handled by the recolour below
1087 if( needsRecache )
1088 view->RecacheAllItems();
1089
1092
1093 if( aRefresh )
1094 canvas->Refresh();
1095}
1096
1097
1099{
1100 wxLogTrace( traceLibWatch, "setFPWatcher" );
1101
1102 Unbind( wxEVT_FSWATCHER, &PCB_BASE_FRAME::OnFPChange, this );
1103
1104 if( m_watcher )
1105 {
1106 wxLogTrace( traceLibWatch, "Remove watch" );
1107 m_watcher->RemoveAll();
1108 m_watcher->SetOwner( nullptr );
1109 m_watcher.reset();
1110 }
1111
1112 wxString libfullname;
1114
1115 if( !aFootprint || !adapter )
1116 return;
1117
1118 try
1119 {
1120 std::optional<LIBRARY_TABLE_ROW*> row = adapter->GetRow( aFootprint->GetFPID().GetLibNickname() );
1121
1122 if( !row )
1123 return;
1124
1125 libfullname = LIBRARY_MANAGER::GetFullURI( *row, true );
1126 }
1127 catch( const IO_ERROR& error )
1128 {
1129 wxLogTrace( traceLibWatch, "Error: %s", error.What() );
1130 return;
1131 }
1132 catch( const std::exception& e )
1133 {
1134 DisplayInfoMessage( this, e.what() );
1135 return;
1136 }
1137
1138 m_watcherFileName.Assign( libfullname, aFootprint->GetFPID().GetLibItemName(),
1140
1141 if( !m_watcherFileName.FileExists() )
1142 return;
1143
1144 m_watcherLastModified = m_watcherFileName.GetModificationTime();
1145
1146 wxFileName fn;
1147 fn.AssignDir( m_watcherFileName.GetPath() );
1148 fn.DontFollowLink();
1149
1150 // wxMSW frees a watch before SMB completes its pending read, which then corrupts the heap
1151 if( KIPLATFORM::ENV::IsNetworkPath( fn.GetPath() ) )
1152 {
1153 wxLogTrace( traceLibWatch, "Network path, not watching: %s", fn.GetPath() );
1154 return;
1155 }
1156
1157 Bind( wxEVT_FSWATCHER, &PCB_BASE_FRAME::OnFPChange, this );
1158 m_watcher = std::make_unique<wxFileSystemWatcher>();
1159 m_watcher->SetOwner( this );
1160
1161 wxLogTrace( traceLibWatch, "Add watch: %s", fn.GetPath() );
1162
1163 {
1164 // Silence OS errors that come from the watcher
1165 wxLogNull silence;
1166 m_watcher->Add( fn );
1167 }
1168}
1169
1170
1171void PCB_BASE_FRAME::OnFPChange( wxFileSystemWatcherEvent& aEvent )
1172{
1173 if( aEvent.GetPath() != m_watcherFileName.GetFullPath() )
1174 return;
1175
1176 // Start the debounce timer (set to 1 second)
1177 if( !m_watcherDebounceTimer.StartOnce( 1000 ) )
1178 {
1179 wxLogTrace( traceLibWatch, "Failed to start the debounce timer" );
1180 return;
1181 }
1182}
1183
1184
1186{
1187 if( aEvent.GetId() != m_watcherDebounceTimer.GetId() )
1188 {
1189 aEvent.Skip();
1190 return;
1191 }
1192
1194 {
1195 wxLogTrace( traceLibWatch, "Restarting debounce timer" );
1196 m_watcherDebounceTimer.StartOnce( 3000 );
1197 return;
1198 }
1199
1200 // If the frame is currently disabled then a quasi-modal/modal dialog is open on top of it (for
1201 // example the footprint properties dialog). Reloading the footprint now would delete the items
1202 // the dialog is editing and crash on dialog close. Defer the reload until the dialog is gone.
1203 if( !IsEnabled() )
1204 {
1205 wxLogTrace( traceLibWatch, "Frame disabled (dialog open); restarting debounce timer" );
1206 m_watcherDebounceTimer.StartOnce( 1000 );
1207 return;
1208 }
1209
1210 // An interactive tool (move, draw, place) holds references into the current footprint while its
1211 // event loop runs. Reloading now would free those out from under the running tool and crash.
1212 // Restart the timer before touching the watcher timestamp so the reload is retried once the tool
1213 // finishes rather than silently dropped.
1214 if( !ToolStackIsEmpty() )
1215 {
1216 wxLogTrace( traceLibWatch, "Interactive tool active; restarting debounce timer" );
1217 m_watcherDebounceTimer.StartOnce( 1000 );
1218 return;
1219 }
1220
1221 wxLogTrace( traceLibWatch, "OnFpChangeDebounceTimer" );
1222
1223 wxDateTime lastModified;
1224
1225 {
1226 // Silence spurious OS messages while checking if the file has changed
1227 wxLogNull silence;
1228 lastModified = m_watcherFileName.GetModificationTime();
1229 }
1230
1231 if( lastModified == m_watcherLastModified || !lastModified.IsValid() )
1232 return;
1233
1234 m_watcherLastModified = lastModified;
1235
1238
1239 // When loading a footprint from a library in the footprint editor
1240 // the items UUIDs must be keep and not reinitialized
1241 bool keepUUID = IsType( FRAME_FOOTPRINT_EDITOR );
1242
1243 if( !fp || !adapter )
1244 return;
1245
1246 SCOPED_SET_RESET<bool> inTimerEvent( m_inFpChangeTimerEvent, true );
1247
1249 || IsOK( this, _( "The library containing the current footprint has changed.\n"
1250 "Do you want to reload the footprint?" ) ) )
1251 {
1252 wxString fpname = fp->GetFPID().GetLibItemName();
1253 wxString nickname = fp->GetFPID().GetLibNickname();
1254
1255 try
1256 {
1257 FOOTPRINT* newfp = adapter->LoadFootprint( nickname, fpname, keepUUID );
1258
1259 if( newfp )
1260 {
1261 std::vector<KIID> selectedItems;
1262
1263 for( const EDA_ITEM* item : GetCurrentSelection() )
1264 selectedItems.emplace_back( item->m_Uuid );
1265
1267
1268 ReloadFootprint( newfp );
1269
1270 newfp->ClearAllNets();
1274
1275 std::vector<EDA_ITEM*> sel;
1276
1277 for( const KIID& uuid : selectedItems )
1278 {
1279 if( BOARD_ITEM* item = GetBoard()->ResolveItem( uuid, true ) )
1280 sel.push_back( item );
1281 }
1282
1283 if( !sel.empty() )
1284 m_toolManager->RunAction( ACTIONS::selectItems, &sel );
1285 }
1286 }
1287 catch( const IO_ERROR& ioe )
1288 {
1289 DisplayError( this, ioe.What() );
1290 }
1291 }
1292}
@ ERROR_INSIDE
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
constexpr int ARC_LOW_DEF
Definition base_units.h:136
@ NORMAL
Inactive layers are shown normally (no high-contrast mode)
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
BOX2< VECTOR2D > BOX2D
Definition box2.h:928
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:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1497
void UpdateUserUnits(BOARD_ITEM *aItem, KIGFX::VIEW *aView)
Update any references within aItem (or its descendants) to the user units.
Definition board.cpp:2018
const LSET & GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1197
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:364
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:704
void IncrementTimeStamp()
Definition board.cpp:446
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1299
void SynchronizeProperties()
Copy the current project's text variables into the boards property cache.
Definition board.cpp:3132
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition board.cpp:2116
void SetUserUnits(EDA_UNITS aUnits)
Definition board.h:1023
constexpr void SetOrigin(const Vec &pos)
Definition box2.h:234
constexpr size_type GetWidth() const
Definition box2.h:211
constexpr Vec Centre() const
Definition box2.h:94
constexpr size_type GetHeight() const
Definition box2.h:212
constexpr const Vec & GetOrigin() const
Definition box2.h:207
constexpr void SetEnd(coord_type x, coord_type y)
Definition box2.h:294
static DELETED_BOARD_ITEM * GetInstance()
Definition board_item.h:609
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:98
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:158
const KIID m_Uuid
Definition eda_item.h:597
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
void SetBrightened()
Definition eda_item.h:151
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
static const TOOL_EVENT ConnectivityChangedEvent
Selected item had a property changed (except movement)
Definition actions.h:347
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:660
const LIB_ID & GetFPID() const
Definition footprint.h:473
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:435
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:84
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:642
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
Definition view.cpp:615
bool HasItem(const VIEW_ITEM *aItem) const
Indicates whether or not the given item has been added to the view.
Definition view.cpp:1838
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:552
void RecacheAllItems()
Rebuild GAL display lists.
Definition view.cpp:1569
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:1703
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:1719
Definition kiid.h:46
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:340
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
static bool displayOptionsRequireRecache(const PCB_DISPLAY_OPTIONS &aOld, const PCB_DISPLAY_OPTIONS &aNew)
Return true when moving from aOld to aNew changes drawn item geometry and therefore requires the GAL ...
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
ZONE_DISPLAY_MODE m_ZoneDisplayMode
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:123
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:38
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:896
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:1956
@ 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:422
#define QUALIFIED_VIEWER3D_FRAMENAME(parent)
@ RECURSE
Definition eda_item.h:51
#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:703
@ 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
bool IsNetworkPath(const wxString &aPath)
Determines if a given path is a network shared file apth On Windows for example, any form of path is ...
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:173
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:98
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:95
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:96
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:100
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:82
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition typeinfo.h:91
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:93
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:78
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:94
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:90
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:97
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.