Constrain dimension tool while creating

The dimension tool is optionally constrained (MD_CTRL) while editing the
dimension.  This ensures same behavior for the creation step.
This commit is contained in:
Seth Hillbrand 2018-06-02 21:01:01 -07:00
parent 40d2535625
commit a5b92a1fe4
2 changed files with 25 additions and 0 deletions

View File

@ -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<wxPoint>( 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:

View File

@ -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;