diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 0c771879a9..d2a89feec9 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -461,6 +461,17 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) } +void DRAWING_TOOL::constrainDimension( DIMENSION* dimension ) +{ + VECTOR2I lineVector( dimension->GetEnd() - dimension->GetOrigin() ); + double angle = lineVector.Angle(); + double newAngle = KiROUND( angle / M_PI_4 ) * M_PI_4; + VECTOR2I newLineVector = lineVector.Rotate( newAngle - angle ); + + dimension->SetEnd( dimension->GetOrigin() + static_cast( newLineVector ) ); +} + + int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) { DIMENSION* dimension = NULL; @@ -571,6 +582,9 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) case SET_END: dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); + if( !!evt->Modifier( MD_CTRL ) ) + constrainDimension( dimension ); + // Dimensions that have origin and end in the same spot are not valid if( dimension->GetOrigin() == dimension->GetEnd() ) --step; @@ -606,6 +620,10 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) { case SET_END: dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); + + if( !!evt->Modifier( MD_CTRL ) ) + constrainDimension( dimension ); + break; case SET_HEIGHT: diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index d851c24cb6..3160d07f52 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -258,6 +258,13 @@ private: */ void make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) const; + /** + * Function constrainDimension() + * Forces the dimension lime to be drawn on multiple of 45 degrees + * @param aDimension is the dimension element currently being drawn + */ + void constrainDimension( DIMENSION* dimension ); + ///> Returns the appropriate width for a segment depending on the settings. int getSegmentWidth( unsigned int aLayer ) const;