diff --git a/eeschema/dialogs/dialog_lib_text_properties.cpp b/eeschema/dialogs/dialog_lib_text_properties.cpp index fb90a6d7b2..91793071f8 100644 --- a/eeschema/dialogs/dialog_lib_text_properties.cpp +++ b/eeschema/dialogs/dialog_lib_text_properties.cpp @@ -122,6 +122,8 @@ DIALOG_LIB_TEXT_PROPERTIES::~DIALOG_LIB_TEXT_PROPERTIES() bool DIALOG_LIB_TEXT_PROPERTIES::TransferDataToWindow() { + wxCHECK( m_CommonUnit, false ); + LIB_SYMBOL* symbol = nullptr; if( m_graphicText ) @@ -170,10 +172,11 @@ bool DIALOG_LIB_TEXT_PROPERTIES::TransferDataToWindow() auto* tools = m_parent->GetToolManager()->GetTool(); symbol = m_parent->GetCurSymbol(); + wxCHECK( cfg && symbol && tools, false ); + m_textSize.SetValue( schIUScale.MilsToIU( cfg->m_Defaults.text_size ) ); - m_CommonUnit->SetValue( - symbol && symbol->GetUnitCount() > 1 && !tools->GetDrawSpecificUnit() ); + m_CommonUnit->SetValue( symbol->GetUnitCount() > 1 && !tools->GetDrawSpecificUnit() ); m_CommonConvert->SetValue( !tools->GetDrawSpecificConvert() ); if( tools->GetLastTextAngle().IsHorizontal() ) diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 0dfb9e10c3..37a3096fee 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1831,13 +1831,19 @@ void SCH_EDIT_FRAME::UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete, bool aUpda void SCH_EDIT_FRAME::DisplayCurrentSheet() { + wxCHECK( m_toolManager, /* void */ ); + m_toolManager->RunAction( ACTIONS::cancelInteractive, true ); m_toolManager->RunAction( EE_ACTIONS::clearSelection, true ); SCH_SCREEN* screen = GetCurrentSheet().LastScreen(); - wxASSERT( screen ); + wxCHECK( screen, /* void */ ); - SetScreen( screen ); + m_toolManager->RunAction( EE_ACTIONS::clearSelection, true ); + + SCH_BASE_FRAME::SetScreen( screen ); + + m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); // update the References GetCurrentSheet().UpdateAllScreenReferences(); @@ -1845,6 +1851,8 @@ void SCH_EDIT_FRAME::DisplayCurrentSheet() EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool(); + wxCHECK( selectionTool, /* void */ ); + auto visit = [&]( EDA_ITEM* item ) { @@ -1889,6 +1897,9 @@ void SCH_EDIT_FRAME::DisplayCurrentSheet() HardRedraw(); // Ensure all items are redrawn (especially the drawing-sheet items) SCH_EDITOR_CONTROL* editTool = m_toolManager->GetTool(); + + wxCHECK( editTool, /* void */ ); + TOOL_EVENT dummy; editTool->UpdateNetHighlighting( dummy ); diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index 87154369e2..96d3ba015c 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 CERN - * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -192,6 +192,7 @@ void SCH_MOVE_TOOL::orthoLineDrag( SCH_LINE* line, const VECTOR2I& splitDelta, i // start point to be attached to the unselected end of our drag line). // // Also, new lines are added already so they'll be in the undo list, skip adding them. + if( !foundLine->HasFlag( IS_CHANGED ) && !foundLine->HasFlag( IS_NEW ) ) { saveCopyInUndoList( (SCH_ITEM*) foundLine, UNDO_REDO::CHANGED, true ); @@ -207,7 +208,6 @@ void SCH_MOVE_TOOL::orthoLineDrag( SCH_LINE* line, const VECTOR2I& splitDelta, i updateItem( foundLine, true ); - SCH_LINE* bendLine = nullptr; if( m_lineConnectionCache.count( foundLine ) == 1 @@ -362,16 +362,22 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) m_anchorPos.reset(); if( aEvent.IsAction( &EE_ACTIONS::move ) ) + { m_isDrag = false; + } else if( aEvent.IsAction( &EE_ACTIONS::drag ) ) { m_isDrag = true; isSlice = aEvent.Parameter(); } else if( aEvent.IsAction( &EE_ACTIONS::moveActivate ) ) + { m_isDrag = !cfg->m_Input.drag_is_move; + } else + { return 0; + } if( m_moveInProgress ) { @@ -383,7 +389,17 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) { // Reset the selected items so we can start again with the current m_isDrag // state. - m_frame->RollbackSchematicFromUndo(); + try + { + m_frame->RollbackSchematicFromUndo(); + } + catch( const IO_ERROR& exc ) + { + wxLogWarning( wxS( "Exception \"%s\" rolling back schematic undo ocurred." ), + exc.What() ); + return 1; + } + m_selectionTool->RemoveItemsFromSel( &m_dragAdditions, QUIET_MODE ); m_anchorPos = m_cursor - m_moveOffset; m_moveInProgress = false; @@ -417,6 +433,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) std::vector internalPoints; Activate(); + // Must be done after Activate() so that it gets set into the correct context controls->ShowCursor( true ); @@ -971,7 +988,8 @@ void SCH_MOVE_TOOL::trimDanglingLines() // Delete newly dangling lines: // Find split segments (one segment is new, the other is changed) that // we aren't dragging and don't have selected - if( aChangedItem->HasFlag( IS_BROKEN) && aChangedItem->IsDangling() && !aChangedItem->IsSelected() ) + if( aChangedItem->HasFlag( IS_BROKEN) && aChangedItem->IsDangling() + && !aChangedItem->IsSelected() ) { danglers.insert( aChangedItem ); } diff --git a/pagelayout_editor/tools/pl_edit_tool.cpp b/pagelayout_editor/tools/pl_edit_tool.cpp index 56551364da..101568f4ca 100644 --- a/pagelayout_editor/tools/pl_edit_tool.cpp +++ b/pagelayout_editor/tools/pl_edit_tool.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 CERN - * Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,6 +22,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include + #include #include #include @@ -131,7 +133,18 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) VECTOR2I prevPos; if( !selection.Front()->IsNew() ) - m_frame->SaveCopyInUndoList(); + { + try + { + m_frame->SaveCopyInUndoList(); + } + catch( const fmt::v9::format_error& exc ) + { + wxLogWarning( wxS( "Exception \"%s\" serializing string ocurred." ), + exc.what() ); + return 1; + } + } // Main loop: keep receiving events do diff --git a/pagelayout_editor/tools/pl_point_editor.cpp b/pagelayout_editor/tools/pl_point_editor.cpp index 6b6f570380..11a91db353 100644 --- a/pagelayout_editor/tools/pl_point_editor.cpp +++ b/pagelayout_editor/tools/pl_point_editor.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 CERN - * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -25,6 +25,8 @@ #include using namespace std::placeholders; +#include + #include #include #include @@ -45,11 +47,13 @@ enum RECTANGLE_POINTS RECT_TOPLEFT, RECT_TOPRIGHT, RECT_BOTLEFT, RECT_BOTRIGHT }; + enum LINE_POINTS { LINE_START, LINE_END }; + class EDIT_POINTS_FACTORY { public: @@ -188,7 +192,17 @@ int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent ) { if( !inDrag ) { - m_frame->SaveCopyInUndoList(); + try + { + m_frame->SaveCopyInUndoList(); + } + catch( const fmt::v9::format_error& exc ) + { + wxLogWarning( wxS( "Exception \"%s\" serializing string ocurred." ), + exc.what() ); + return 1; + } + controls->ForceCursorPosition( false ); inDrag = true; modified = true; @@ -215,14 +229,17 @@ int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent ) modified = false; } else if( evt->IsCancelInteractive() ) + { break; + } if( evt->IsActivate() && !evt->IsMoveTool() ) break; } - else + { evt->SetPassEvent(); + } controls->SetAutoPan( inDrag ); controls->CaptureCursor( inDrag ); diff --git a/pcbnew/drc/drc_test_provider_diff_pair_coupling.cpp b/pcbnew/drc/drc_test_provider_diff_pair_coupling.cpp index 4fa64f8110..353d4672ed 100644 --- a/pcbnew/drc/drc_test_provider_diff_pair_coupling.cpp +++ b/pcbnew/drc/drc_test_provider_diff_pair_coupling.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004-2022 KiCad Developers. + * Copyright (C) 2004-2023 KiCad Developers. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -497,7 +497,9 @@ bool test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run() { for( DIFF_PAIR_COUPLED_SEGMENTS& dp : itemSet.coupled ) { - if( ( dp.couplingFailMin || dp.couplingFailMax ) && ( dp.parentP || dp.parentN ) ) + wxCHECK2( dp.parentP && dp.parentN, continue ); + + if( ( dp.couplingFailMin || dp.couplingFailMax ) ) { // We have a candidate violation, now we need to re-query for a constraint // given the actual items, because there may be a location-based rule in play. diff --git a/pcbnew/pcb_track.cpp b/pcbnew/pcb_track.cpp index 155cccfa5d..98b354ff82 100644 --- a/pcbnew/pcb_track.cpp +++ b/pcbnew/pcb_track.cpp @@ -101,6 +101,7 @@ PCB_VIA::PCB_VIA( const PCB_VIA& aOther ) : PCB_VIA::operator=( aOther ); const_cast( m_Uuid ) = aOther.m_Uuid; + m_zoneLayerOverrides = aOther.m_zoneLayerOverrides; } @@ -142,9 +143,7 @@ wxString PCB_VIA::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const default: formatStr = _( "Via %s on %s" ); break; } - return wxString::Format( formatStr, - GetNetnameMsg(), - layerMaskDescribe() ); + return wxString::Format( formatStr, GetNetnameMsg(), layerMaskDescribe() ); } @@ -437,7 +436,6 @@ void PCB_VIA::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) } -// see class_track.h INSPECT_RESULT PCB_TRACK::Visit( INSPECTOR inspector, void* testData, const std::vector& aScanTypes ) { @@ -1137,12 +1135,14 @@ VECTOR2I PCB_ARC::GetPosition() const return center; } + double PCB_ARC::GetRadius() const { auto center = CalcArcCenter( m_Start, m_Mid , m_End ); return GetLineLength( center, m_Start ); } + EDA_ANGLE PCB_ARC::GetAngle() const { VECTOR2I center = GetPosition(); @@ -1152,12 +1152,14 @@ EDA_ANGLE PCB_ARC::GetAngle() const return angle1.Normalize180() + angle2.Normalize180(); } + EDA_ANGLE PCB_ARC::GetArcAngleStart() const { EDA_ANGLE angleStart( m_Start - GetPosition() ); return angleStart.Normalize(); } + EDA_ANGLE PCB_ARC::GetArcAngleEnd() const { EDA_ANGLE angleEnd( m_End - GetPosition() ); diff --git a/pcbnew/pcb_track.h b/pcbnew/pcb_track.h index 6185c7d49c..aa6cb4e263 100644 --- a/pcbnew/pcb_track.h +++ b/pcbnew/pcb_track.h @@ -59,14 +59,13 @@ enum ENDPOINT_T : int ENDPOINT_END = 1 }; -// Via types // Note that this enum must be synchronized to GAL_LAYER_ID enum class VIATYPE : int { THROUGH = 3, /* Always a through hole via */ BLIND_BURIED = 2, /* this via can be on internal layers */ MICROVIA = 1, /* this via which connect from an external layer - * to the near neighbor internal layer */ + * to the near neighbor internal layer */ NOT_DEFINED = 0 /* not yet used */ }; @@ -132,22 +131,22 @@ public: const BOX2I GetBoundingBox() const override; /** - * Function GetLength - * returns the length of the track using the hypotenuse calculation. - * @return double - the length of the track + * Get the length of the track using the hypotenuse calculation. + * + * @return the length of the track. */ virtual double GetLength() const; /** - * Function TransformShapeToPolygon - * Convert the track shape to a closed polygon - * Used in filling zones calculations - * Circles (vias) and arcs (ends of tracks) are approximated by segments - * @param aBuffer = a buffer to store the polygon - * @param aClearance = the clearance around the pad - * @param aError = the maximum deviation from true circle - * @param ignoreLineWidth = used for edge cut items where the line width is only for - * visualization + * Convert the track shape to a closed polygon. + * + * Circles (vias) and arcs (ends of tracks) are approximated by segments. + * + * @param aBuffer is a buffer to store the polygon + * @param aClearance is the clearance around the pad + * @param aError is the maximum deviation from true circle + * @param ignoreLineWidth is used for edge cut items where the line width is only for + * visualization */ void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, @@ -158,17 +157,16 @@ public: FLASHING aFlash = FLASHING::DEFAULT ) const override; /** - * Function IsPointOnEnds - * returns STARTPOINT if point if near (dist = min_dist) start point, ENDPOINT if + * Return STARTPOINT if point if near (dist = min_dist) start point, ENDPOINT if * point if near (dist = min_dist) end point,STARTPOINT|ENDPOINT if point if near * (dist = min_dist) both ends, or 0 if none of the above. - * if min_dist < 0: min_dist = track_width/2 + * + * If min_dist < 0: min_dist = track_width/2 */ EDA_ITEM_FLAGS IsPointOnEnds( const VECTOR2I& point, int min_dist = 0 ) const; /** - * Function IsNull - * returns true if segment length is zero. + * Return true if segment length is zero. */ bool IsNull() const { @@ -192,8 +190,8 @@ public: } /** - * Function GetLocalClearance - * returns any local clearance overrides set in the "classic" (ie: pre-rule) system. + * Return any local clearance overrides set in the "classic" (ie: pre-rule) system. + * * @param aSource [out] optionally reports the source as a user-readable string * @return int - the clearance in internal units. */ @@ -222,7 +220,8 @@ public: } /** - * Get last used LOD for the track net name + * Get last used LOD for the track net name. + * * @return LOD from ViewGetLOD() */ double GetCachedLOD() @@ -231,8 +230,9 @@ public: } /** - * Set the cached LOD - * @param aLOD value from ViewGetLOD() or 0.0 to always display + * Set the cached LOD. + * + * @param aLOD value from ViewGetLOD() or 0.0 to always display. */ void SetCachedLOD( double aLOD ) { @@ -240,7 +240,8 @@ public: } /** - * Get last used zoom scale for the track net name + * Get last used zoom scale for the track net name. + * * @return scale from GetScale() */ double GetCachedScale() @@ -249,7 +250,8 @@ public: } /** - * Set the cached scale + * Set the cached scale. + * * @param aScale value from GetScale() */ void SetCachedScale( double aScale ) @@ -269,7 +271,8 @@ public: protected: virtual void swapData( BOARD_ITEM* aImage ) override; - void GetMsgPanelInfoBase_Common( EDA_DRAW_FRAME* aFrame, std::vector& aList ) const; + void GetMsgPanelInfoBase_Common( EDA_DRAW_FRAME* aFrame, + std::vector& aList ) const; protected: int m_Width; ///< Thickness of track, or via diameter @@ -277,7 +280,8 @@ protected: VECTOR2I m_End; ///< Line end point double m_CachedLOD; ///< Last LOD used to draw this track's net - double m_CachedScale; ///< Last zoom scale used to draw this track's net (we want to redraw when changing zoom) + + double m_CachedScale; ///< Last zoom scale used to draw this track's net. }; @@ -327,7 +331,8 @@ public: EDA_ANGLE GetArcAngleEnd() const; virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override; - virtual bool HitTest( const BOX2I& aRect, bool aContained = true, int aAccuracy = 0 ) const override; + virtual bool HitTest( const BOX2I& aRect, bool aContained = true, + int aAccuracy = 0 ) const override; bool IsCCW() const; @@ -341,8 +346,8 @@ public: FLASHING aFlash = FLASHING::DEFAULT ) const override; /** - * Function GetLength - * returns the length of the arc track + * Return the length of the arc track. + * * @return double - the length of the track */ virtual double GetLength() const override @@ -410,10 +415,10 @@ public: virtual void SetLayerSet( LSET aLayers ) override; /** - * Function SetLayerPair - * For a via m_layer contains the top layer, the other layer is in m_bottomLayer - * @param aTopLayer = first layer connected by the via - * @param aBottomLayer = last layer connected by the via + * For a via m_layer contains the top layer, the other layer is in m_bottomLayer/ + * + * @param aTopLayer is the first layer connected by the via. + * @param aBottomLayer is last layer connected by the via. */ void SetLayerPair( PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer ); @@ -421,11 +426,11 @@ public: void SetTopLayer( PCB_LAYER_ID aLayer ); /** - * Function LayerPair - * Return the 2 layers used by the via (the via actually uses - * all layers between these 2 layers) - * @param top_layer = pointer to the first layer (can be null) - * @param bottom_layer = pointer to the last layer (can be null) + * Return the 2 layers used by the via (the via actually uses all layers between these + * 2 layers) + * + * @param[out] top_layer is storage for the first layer of the via (can be null). + * @param[out] bottom_layer is storage for the last layer of the via(can be null). */ void LayerPair( PCB_LAYER_ID* top_layer, PCB_LAYER_ID* bottom_layer ) const; @@ -433,8 +438,7 @@ public: PCB_LAYER_ID BottomLayer() const; /** - * Function SanitizeLayers - * Check so that the layers are correct dependin on the type of via, and + * Check so that the layers are correct depending on the type of via, and * so that the top actually is on top. */ void SanitizeLayers(); @@ -495,59 +499,61 @@ public: } /** - * Checks to see whether the via should have a pad on the specific layer + * Check to see whether the via should have a pad on the specific layer. + * * @param aLayer Layer to check for connectivity * @return true if connected by pad or track (or optionally zone) */ bool FlashLayer( int aLayer ) const; /** - * Checks to see if the via is present on any of the layers in the set - * @param aLayers set of layers to check the via against - * @return true if connected by pad or track (or optionally zone) on any of the associated layers + * Check to see if the via is present on any of the layers in the set. + * + * @param aLayers is the set of layers to check the via against. + * @return true if connected by pad or track (or optionally zone) on any of the associated + * layers. */ bool FlashLayer( LSET aLayers ) const; /** - * Function SetDrill - * sets the drill value for vias. + * Set the drill value for vias. + * * @param aDrill is the new drill diameter - */ + */ void SetDrill( int aDrill ) { m_drill = aDrill; } /** - * Function GetDrill - * returns the local drill setting for this PCB_VIA. If you want the calculated value, - * use GetDrillValue() instead. + * Return the local drill setting for this PCB_VIA. + * + * @note Use GetDrillValue() to get the calculated value. */ int GetDrill() const { return m_drill; } /** - * Function GetDrillValue - * "calculates" the drill value for vias (m-Drill if > 0, or default - * drill value for the board. - * @return real drill_value - */ + * Calculate the drill value for vias (m-Drill if > 0, or default drill value for the board. + * + * @return the calculated drill value. + */ int GetDrillValue() const; /** - * Function SetDrillDefault - * sets the drill value for vias to the default value #UNDEFINED_DRILL_DIAMETER. - */ + * Set the drill value for vias to the default value #UNDEFINED_DRILL_DIAMETER. + */ void SetDrillDefault() { m_drill = UNDEFINED_DRILL_DIAMETER; } /** - * Checks if the via is a free via (as opposed to one created on a track by the router). + * Check if the via is a free via (as opposed to one created on a track by the router). + * * Free vias don't have their nets automatically updated by the connectivity algorithm. + * * @return true if the via is a free via */ bool GetIsFree() const { return m_isFree; } void SetIsFree( bool aFree = true ) { m_isFree = aFree; } /** - * Function IsDrillDefault * @return true if the drill value is default value (-1) - */ + */ bool IsDrillDefault() const { return m_drill <= 0; } // @copydoc BOARD_ITEM::GetEffectiveShape @@ -555,7 +561,7 @@ public: FLASHING aFlash = FLASHING::DEFAULT ) const override; void ClearZoneLayerOverrides() - { + { m_zoneLayerOverrides.fill( ZLO_NONE ); } diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index fa44861010..d94de597d2 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -248,7 +248,7 @@ bool PNS_PCBNEW_RULE_RESOLVER::IsNetTieExclusion( const PNS::ITEM* aItem, return true; } - if( drcEngine && collidingItem ) + if( drcEngine ) { return drcEngine->IsNetTieExclusion( aItem->Net(), ToLAYER_ID( aItem->Layer() ), aCollisionPos, collidingItem );