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:
parent
40d2535625
commit
a5b92a1fe4
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue