From 35978adef955bd5c075a4507be495e639c1b05ec Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 19 Jan 2021 16:08:37 +0000 Subject: [PATCH] Don't run dimension updates while parsing files. They mess up the geometry when only partial values are provided. Fixes https://gitlab.com/kicad/code/kicad/issues/7177 --- pcbnew/dimension.cpp | 30 +++++++++--------------------- pcbnew/dimension.h | 8 +++++--- pcbnew/tools/drawing_tool.cpp | 6 ++++++ pcbnew/tools/pcb_point_editor.cpp | 17 +++++++++++------ 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/pcbnew/dimension.cpp b/pcbnew/dimension.cpp index 50d62d6548..7b0bbbb5cf 100644 --- a/pcbnew/dimension.cpp +++ b/pcbnew/dimension.cpp @@ -293,20 +293,6 @@ void DIMENSION_BASE::Mirror( const wxPoint& axis_pos, bool aMirrorLeftRight ) } -void DIMENSION_BASE::SetStart( const wxPoint& aOrigin ) -{ - m_start = aOrigin; - Update(); -} - - -void DIMENSION_BASE::SetEnd( const wxPoint& aEnd ) -{ - m_end = aEnd; - Update(); -} - - void DIMENSION_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) { // for now, display only the text within the DIMENSION using class PCB_TEXT. @@ -526,13 +512,6 @@ BITMAP_DEF ALIGNED_DIMENSION::GetMenuImage() const } -void ALIGNED_DIMENSION::SetHeight( int aHeight ) -{ - m_height = aHeight; - Update(); -} - - void ALIGNED_DIMENSION::UpdateHeight( const wxPoint& aCrossbarStart, const wxPoint& aCrossbarEnd ) { VECTOR2D height( aCrossbarStart - GetStart() ); @@ -670,6 +649,15 @@ void ALIGNED_DIMENSION::updateText() } +void ALIGNED_DIMENSION::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, + std::vector& aList ) +{ + DIMENSION_BASE::GetMsgPanelInfo( aFrame, aList ); + + aList.emplace_back( _( "Height" ), MessageTextFromValue( aFrame->GetUserUnits(), m_height ) ); +} + + ORTHOGONAL_DIMENSION::ORTHOGONAL_DIMENSION( BOARD_ITEM* aParent ) : ALIGNED_DIMENSION( aParent, PCB_DIM_ORTHOGONAL_T ) { diff --git a/pcbnew/dimension.h b/pcbnew/dimension.h index e103e8c84e..1eca8edde2 100644 --- a/pcbnew/dimension.h +++ b/pcbnew/dimension.h @@ -119,10 +119,10 @@ public: * @return the origin point of this dimension */ virtual const wxPoint& GetStart() const { return m_start; } - virtual void SetStart( const wxPoint& aPoint ); + virtual void SetStart( const wxPoint& aPoint ) { m_start = aPoint; } virtual const wxPoint& GetEnd() const { return m_end; } - virtual void SetEnd( const wxPoint& aPoint ); + virtual void SetEnd( const wxPoint& aPoint ) { m_end = aPoint; } wxPoint GetPosition() const override { return m_start; } void SetPosition( const wxPoint& aPos ) override { m_start = aPos; } @@ -363,7 +363,7 @@ public: * Sets the distance from the feature points to the crossbar line * @param aHeight is the new height. */ - void SetHeight( int aHeight ); + void SetHeight( int aHeight ) { m_height = aHeight; } int GetHeight() const { return m_height; } /** @@ -392,6 +392,8 @@ public: return wxT( "ALIGNED_DIMENSION" ); } + void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) override; + protected: void updateGeometry() override; diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 61c5658fa3..3cfd058987 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -632,6 +632,7 @@ void DRAWING_TOOL::constrainDimension( DIMENSION_BASE* aDim ) const VECTOR2I lineVector{ aDim->GetEnd() - aDim->GetStart() }; aDim->SetEnd( wxPoint( VECTOR2I( aDim->GetStart() ) + GetVectorSnapped45( lineVector ) ) ); + aDim->Update(); } @@ -826,6 +827,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) dimension->SetExtensionOffset( boardSettings.m_DimensionExtensionOffset ); dimension->SetStart( (wxPoint) cursorPos ); dimension->SetEnd( (wxPoint) cursorPos ); + dimension->Update(); preview.Add( dimension ); frame()->SetMsgPanel( dimension ); @@ -838,6 +840,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) case SET_END: { dimension->SetEnd( (wxPoint) cursorPos ); + dimension->Update(); if( !!evt->Modifier( MD_CTRL ) || dimension->Type() == PCB_DIM_CENTER_T ) constrainDimension( dimension ); @@ -903,6 +906,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) { case SET_END: dimension->SetEnd( (wxPoint) cursorPos ); + dimension->Update(); if( !!evt->Modifier( MD_CTRL ) || dimension->Type() == PCB_DIM_CENTER_T ) constrainDimension( dimension ); @@ -921,6 +925,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) wxPoint delta( (wxPoint) cursorPos - dimension->GetEnd() ); double height = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) ); aligned->SetHeight( height ); + aligned->Update(); } else if( dimension->Type() == PCB_DIM_ORTHOGONAL_T ) { @@ -944,6 +949,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) VECTOR2I heightVector( cursorPos - dimension->GetStart() ); ortho->SetHeight( vert ? heightVector.x : heightVector.y ); + ortho->Update(); } else if( dimension->Type() == PCB_DIM_LEADER_T ) { diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp index 54b9743644..3ed655890a 100644 --- a/pcbnew/tools/pcb_point_editor.cpp +++ b/pcbnew/tools/pcb_point_editor.cpp @@ -1388,8 +1388,9 @@ void PCB_POINT_EDITOR::updateItem() const dimension->SetHeight( -featureLine.EuclideanNorm() ); else dimension->SetHeight( featureLine.EuclideanNorm() ); - } + dimension->Update(); + } else if( isModified( m_editPoints->Point( DIM_CROSSBAREND ) ) ) { VECTOR2D featureLine( m_editedPoint->GetPosition() - dimension->GetEnd() ); @@ -1399,28 +1400,31 @@ void PCB_POINT_EDITOR::updateItem() const dimension->SetHeight( -featureLine.EuclideanNorm() ); else dimension->SetHeight( featureLine.EuclideanNorm() ); - } + dimension->Update(); + } else if( isModified( m_editPoints->Point( DIM_START ) ) ) { dimension->SetStart( wxPoint( m_editedPoint->GetPosition().x, m_editedPoint->GetPosition().y ) ); + dimension->Update(); + m_editPoints->Point( DIM_CROSSBARSTART ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARSTART ), - m_editPoints->Point( DIM_START ) ) ); + m_editPoints->Point( DIM_START ) ) ); m_editPoints->Point( DIM_CROSSBAREND ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBAREND ), m_editPoints->Point( DIM_END ) ) ); } - else if( isModified( m_editPoints->Point( DIM_END ) ) ) { dimension->SetEnd( wxPoint( m_editedPoint->GetPosition().x, m_editedPoint->GetPosition().y ) ); + dimension->Update(); + m_editPoints->Point( DIM_CROSSBARSTART ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARSTART ), m_editPoints->Point( DIM_START ) ) ); m_editPoints->Point( DIM_CROSSBAREND ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBAREND ), m_editPoints->Point( DIM_END ) ) ); } - else if( isModified( m_editPoints->Point(DIM_TEXT ) ) ) { // Force manual mode if we weren't already in it @@ -1472,9 +1476,10 @@ void PCB_POINT_EDITOR::updateItem() const // Force manual mode if we weren't already in it dimension->SetTextPositionMode( DIM_TEXT_POSITION::MANUAL ); dimension->Text().SetPosition( wxPoint( m_editedPoint->GetPosition() ) ); - dimension->Update(); } + dimension->Update(); + break; }