Commit a7cb90de authored by Maciej Suminski's avatar Maciej Suminski

Some more minor refactorization.

parent b7d43776
...@@ -67,35 +67,30 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason ) ...@@ -67,35 +67,30 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason )
int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent ) int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent )
{ {
m_continous = true; return drawSegment( S_SEGMENT, true );
return draw( S_SEGMENT );
} }
int DRAWING_TOOL::DrawCircle( TOOL_EVENT& aEvent ) int DRAWING_TOOL::DrawCircle( TOOL_EVENT& aEvent )
{ {
m_continous = false; return drawSegment( S_CIRCLE, false );
return draw( S_CIRCLE );
} }
int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
{ {
m_continous = false; bool clockwise = true;
double startAngle; // angle of the first arc line
int step = 0; VECTOR2I cursorPos = m_controls->GetCursorPosition();
DRAWSEGMENT graphic;
DRAWSEGMENT helperLine;
bool positive = true;
// Init the new item attributes // Init the new item attributes
DRAWSEGMENT graphic;
graphic.SetShape( S_ARC ); graphic.SetShape( S_ARC );
graphic.SetAngle( 0.0 ); graphic.SetAngle( 0.0 );
graphic.SetWidth( m_board->GetDesignSettings().m_DrawSegmentWidth ); graphic.SetWidth( m_board->GetDesignSettings().m_DrawSegmentWidth );
graphic.SetCenter( wxPoint( cursorPos.x, cursorPos.y ) );
DRAWSEGMENT helperLine;
helperLine.SetShape( S_SEGMENT ); helperLine.SetShape( S_SEGMENT );
helperLine.SetLayer( DRAW_N ); helperLine.SetLayer( DRAW_N );
helperLine.SetWidth( 1 ); helperLine.SetWidth( 1 );
...@@ -106,13 +101,23 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) ...@@ -106,13 +101,23 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
m_controls->ShowCursor( true ); m_controls->ShowCursor( true );
m_controls->SetSnapping( true ); m_controls->SetSnapping( true );
m_controls->SetAutoPan( true );
Activate(); Activate();
enum ARC_STEPS
{
SET_ORIGIN = 0,
SET_END,
SET_ANGLE,
FINISHED
};
int step = SET_ORIGIN;
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
{ {
VECTOR2I cursorPos = m_controls->GetCursorPosition(); cursorPos = m_controls->GetCursorPosition();
if( evt->IsCancel() ) if( evt->IsCancel() )
break; break;
...@@ -126,14 +131,14 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) ...@@ -126,14 +131,14 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
graphic.SetWidth( width - WIDTH_STEP ); graphic.SetWidth( width - WIDTH_STEP );
else if( evt->KeyCode() == '=' ) else if( evt->KeyCode() == '=' )
graphic.SetWidth( width + WIDTH_STEP ); graphic.SetWidth( width + WIDTH_STEP );
else if( evt->KeyCode() == ' ' ) else if( evt->KeyCode() == '/' )
{ {
if( positive ) if( clockwise )
graphic.SetAngle( graphic.GetAngle() - 3600.0 ); graphic.SetAngle( graphic.GetAngle() - 3600.0 );
else else
graphic.SetAngle( graphic.GetAngle() + 3600.0 ); graphic.SetAngle( graphic.GetAngle() + 3600.0 );
positive = !positive; clockwise = !clockwise;
} }
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
...@@ -143,9 +148,9 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) ...@@ -143,9 +148,9 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
{ {
switch( step ) switch( step )
{ {
case 0: case SET_ORIGIN:
{ {
LAYER_NUM layer = getEditFrame<PCB_EDIT_FRAME>()->GetScreen()->m_Active_Layer; LAYER_NUM layer = m_frame->GetScreen()->m_Active_Layer;
if( IsCopperLayer( layer ) ) if( IsCopperLayer( layer ) )
{ {
...@@ -154,8 +159,6 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) ...@@ -154,8 +159,6 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
} }
else else
{ {
m_controls->SetAutoPan( true );
helperLine.SetStart( graphic.GetCenter() ); helperLine.SetStart( graphic.GetCenter() );
graphic.SetLayer( layer ); graphic.SetLayer( layer );
preview.Add( &graphic ); preview.Add( &graphic );
...@@ -164,7 +167,14 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) ...@@ -164,7 +167,14 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
} }
break; break;
case 2: case SET_END:
{
VECTOR2D startLine( graphic.GetArcStart() - graphic.GetCenter() );
startAngle = startLine.Angle();
}
break;
case SET_ANGLE:
{ {
if( wxPoint( cursorPos.x, cursorPos.y ) != graphic.GetCenter() ) if( wxPoint( cursorPos.x, cursorPos.y ) != graphic.GetCenter() )
{ {
...@@ -175,10 +185,9 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) ...@@ -175,10 +185,9 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
} }
} }
break; break;
} }
if( ++step == 3 ) if( ++step == FINISHED )
break; break;
} }
...@@ -186,31 +195,27 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) ...@@ -186,31 +195,27 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
{ {
switch( step ) switch( step )
{ {
case 0: case SET_ORIGIN:
graphic.SetCenter( wxPoint( cursorPos.x, cursorPos.y ) ); graphic.SetCenter( wxPoint( cursorPos.x, cursorPos.y ) );
break; break;
case 1: case SET_END:
helperLine.SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); helperLine.SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
graphic.SetArcStart( wxPoint( cursorPos.x, cursorPos.y ) ); graphic.SetArcStart( wxPoint( cursorPos.x, cursorPos.y ) );
break; break;
case 2: case SET_ANGLE:
{ {
VECTOR2D firstLine( graphic.GetArcStart() - graphic.GetCenter() ); // Compute the current angle
double firstAngle = firstLine.Angle(); VECTOR2D endLine( wxPoint( cursorPos.x, cursorPos.y ) - graphic.GetCenter() );
double newAngle = RAD2DECIDEG( endLine.Angle() - startAngle );
VECTOR2D secondLine( wxPoint( cursorPos.x, cursorPos.y ) - graphic.GetCenter() );
double secondAngle = secondLine.Angle();
double angle = RAD2DECIDEG( secondAngle - firstAngle ); if( clockwise && newAngle < 0.0 )
newAngle += 3600.0;
else if( !clockwise && newAngle > 0.0 )
newAngle -= 3600.0;
if( positive && angle < 0.0 ) graphic.SetAngle( newAngle );
angle += 3600.0;
else if( !positive && angle > 0.0 )
angle -= 3600.0;
graphic.SetAngle( angle );
} }
break; break;
} }
...@@ -309,23 +314,18 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent ) ...@@ -309,23 +314,18 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent ) int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
{ {
m_continous = false;
int step = 0;
DIMENSION* dimension = new DIMENSION( m_board ); DIMENSION* dimension = new DIMENSION( m_board );
// Init the new item attributes // Init the new item attributes
dimension->Text().SetSize( m_board->GetDesignSettings().m_PcbTextSize ); dimension->Text().SetSize( m_board->GetDesignSettings().m_PcbTextSize );
int width = m_board->GetDesignSettings().m_PcbTextWidth; int width = m_board->GetDesignSettings().m_PcbTextWidth;
int maxthickness = Clamp_Text_PenSize( width, dimension->Text().GetSize() ); int maxThickness = Clamp_Text_PenSize( width, dimension->Text().GetSize() );
if( width > maxthickness ) if( width > maxThickness )
width = maxthickness; width = maxThickness;
dimension->Text().SetThickness( width ); dimension->Text().SetThickness( width );
dimension->SetWidth( width ); dimension->SetWidth( width );
dimension->SetFlags( IS_NEW );
dimension->AdjustDimensionDetails(); dimension->AdjustDimensionDetails();
// Add a VIEW_GROUP that serves as a preview for the new item // Add a VIEW_GROUP that serves as a preview for the new item
...@@ -337,6 +337,15 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent ) ...@@ -337,6 +337,15 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
Activate(); Activate();
enum DIMENSION_STEPS
{
SET_ORIGIN = 0,
SET_END,
SET_HEIGHT,
FINISHED
};
int step = SET_ORIGIN;
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
{ {
...@@ -350,7 +359,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent ) ...@@ -350,7 +359,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
else if( evt->IsKeyUp() ) else if( evt->IsKeyUp() )
{ {
int width = dimension->GetWidth(); width = dimension->GetWidth();
// Modify the new item width // Modify the new item width
if( evt->KeyCode() == '-' && width > WIDTH_STEP ) if( evt->KeyCode() == '-' && width > WIDTH_STEP )
...@@ -365,7 +374,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent ) ...@@ -365,7 +374,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
{ {
switch( step ) switch( step )
{ {
case 0: case SET_ORIGIN:
{ {
LAYER_NUM layer = m_frame->GetScreen()->m_Active_Layer; LAYER_NUM layer = m_frame->GetScreen()->m_Active_Layer;
...@@ -386,7 +395,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent ) ...@@ -386,7 +395,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
} }
break; break;
case 2: case SET_HEIGHT:
{ {
if( wxPoint( cursorPos.x, cursorPos.y ) != dimension->GetPosition() ) if( wxPoint( cursorPos.x, cursorPos.y ) != dimension->GetPosition() )
{ {
...@@ -398,7 +407,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent ) ...@@ -398,7 +407,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
break; break;
} }
if( ++step == 3 ) if( ++step == FINISHED )
break; break;
} }
...@@ -406,13 +415,13 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent ) ...@@ -406,13 +415,13 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
{ {
switch( step ) switch( step )
{ {
case 1: case SET_END:
dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
break; break;
case 2: case SET_HEIGHT:
{ {
/* Calculating the direction of travel perpendicular to the selected axis. */ // Calculating the direction of travel perpendicular to the selected axis
double angle = dimension->GetAngle() + ( M_PI / 2 ); double angle = dimension->GetAngle() + ( M_PI / 2 );
wxPoint pos( cursorPos.x, cursorPos.y ); wxPoint pos( cursorPos.x, cursorPos.y );
...@@ -475,7 +484,7 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent ) ...@@ -475,7 +484,7 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
{ {
VECTOR2I cursorPos = m_controls->GetCursorPosition(); cursorPos = m_controls->GetCursorPosition();
if( evt->IsCancel() ) if( evt->IsCancel() )
{ {
...@@ -596,7 +605,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent ) ...@@ -596,7 +605,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
} }
int DRAWING_TOOL::draw( int aShape ) int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
{ {
// Only two shapes are currently supported // Only two shapes are currently supported
assert( aShape == S_SEGMENT || aShape == S_CIRCLE ); assert( aShape == S_SEGMENT || aShape == S_CIRCLE );
...@@ -670,7 +679,7 @@ int DRAWING_TOOL::draw( int aShape ) ...@@ -670,7 +679,7 @@ int DRAWING_TOOL::draw( int aShape )
m_board->Add( newItem ); m_board->Add( newItem );
newItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); newItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
if( m_continous ) if( aContinous )
graphic.SetStart( graphic.GetEnd() ); // This is the origin point for a new item graphic.SetStart( graphic.GetEnd() ); // This is the origin point for a new item
else else
break; break;
......
...@@ -77,7 +77,8 @@ public: ...@@ -77,7 +77,8 @@ public:
private: private:
///> Starts drawing a selected shape (i.e. DRAWSEGMENT). ///> Starts drawing a selected shape (i.e. DRAWSEGMENT).
///> @param aShape is the type of created shape (@see STROKE_T). ///> @param aShape is the type of created shape (@see STROKE_T).
int draw( int aShape ); ///> @param aContinous decides if there is only one or multiple shapes to draw.
int drawSegment( int aShape, bool aContinous );
///> Draws a polygon, that is added as a zone or a keepout area. ///> Draws a polygon, that is added as a zone or a keepout area.
///> @param aKeepout decides if the drawn polygon is a zone or a keepout area. ///> @param aKeepout decides if the drawn polygon is a zone or a keepout area.
...@@ -86,9 +87,6 @@ private: ...@@ -86,9 +87,6 @@ private:
///> Sets up handlers for various events. ///> Sets up handlers for various events.
void setTransitions(); void setTransitions();
///> Should drawing be stopped after drawing one object or should it continue with another one.
bool m_continous;
KIGFX::VIEW* m_view; KIGFX::VIEW* m_view;
KIGFX::VIEW_CONTROLS* m_controls; KIGFX::VIEW_CONTROLS* m_controls;
BOARD* m_board; BOARD* m_board;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment