New items are created using pointers (instead of copying automatic variables when drawing is finished).
This commit is contained in:
parent
8aef3b30fa
commit
834dce571e
|
@ -40,7 +40,6 @@
|
||||||
#include <class_mire.h>
|
#include <class_mire.h>
|
||||||
#include <class_zone.h>
|
#include <class_zone.h>
|
||||||
#include <class_module.h>
|
#include <class_module.h>
|
||||||
#include <class_netinfo.h> // TODO to be removed if we do not need the flags
|
|
||||||
|
|
||||||
DRAWING_TOOL::DRAWING_TOOL() :
|
DRAWING_TOOL::DRAWING_TOOL() :
|
||||||
TOOL_INTERACTIVE( "pcbnew.InteractiveDrawing" )
|
TOOL_INTERACTIVE( "pcbnew.InteractiveDrawing" )
|
||||||
|
@ -79,16 +78,16 @@ int DRAWING_TOOL::DrawCircle( TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
|
int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
bool clockwise = true;
|
bool clockwise = true; // drawing direction of the arc
|
||||||
double startAngle; // angle of the first arc line
|
double startAngle; // angle of the first arc line
|
||||||
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
||||||
|
|
||||||
// Init the new item attributes
|
// Init the new item attributes
|
||||||
DRAWSEGMENT graphic;
|
DRAWSEGMENT* graphic = new DRAWSEGMENT( m_board );
|
||||||
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 ) );
|
graphic->SetCenter( wxPoint( cursorPos.x, cursorPos.y ) );
|
||||||
|
|
||||||
DRAWSEGMENT helperLine;
|
DRAWSEGMENT helperLine;
|
||||||
helperLine.SetShape( S_SEGMENT );
|
helperLine.SetShape( S_SEGMENT );
|
||||||
|
@ -120,23 +119,26 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
|
||||||
cursorPos = m_controls->GetCursorPosition();
|
cursorPos = m_controls->GetCursorPosition();
|
||||||
|
|
||||||
if( evt->IsCancel() )
|
if( evt->IsCancel() )
|
||||||
|
{
|
||||||
|
delete graphic;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
else if( evt->IsKeyUp() )
|
else if( evt->IsKeyUp() )
|
||||||
{
|
{
|
||||||
int width = graphic.GetWidth();
|
int width = graphic->GetWidth();
|
||||||
|
|
||||||
// Modify the new item width
|
// Modify the new item width
|
||||||
if( evt->KeyCode() == '-' && width > WIDTH_STEP )
|
if( evt->KeyCode() == '-' && width > WIDTH_STEP )
|
||||||
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( clockwise )
|
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 );
|
||||||
|
|
||||||
clockwise = !clockwise;
|
clockwise = !clockwise;
|
||||||
}
|
}
|
||||||
|
@ -159,9 +161,9 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
helperLine.SetStart( graphic.GetCenter() );
|
helperLine.SetStart( graphic->GetCenter() );
|
||||||
graphic.SetLayer( layer );
|
graphic->SetLayer( layer );
|
||||||
preview.Add( &graphic );
|
preview.Add( graphic );
|
||||||
preview.Add( &helperLine );
|
preview.Add( &helperLine );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,19 +171,23 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
case SET_END:
|
case SET_END:
|
||||||
{
|
{
|
||||||
VECTOR2D startLine( graphic.GetArcStart() - graphic.GetCenter() );
|
VECTOR2D startLine( graphic->GetArcStart() - graphic->GetCenter() );
|
||||||
startAngle = startLine.Angle();
|
startAngle = startLine.Angle();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SET_ANGLE:
|
case SET_ANGLE:
|
||||||
{
|
{
|
||||||
if( wxPoint( cursorPos.x, cursorPos.y ) != graphic.GetCenter() )
|
if( wxPoint( cursorPos.x, cursorPos.y ) != graphic->GetCenter() )
|
||||||
{
|
{
|
||||||
DRAWSEGMENT* newItem = new DRAWSEGMENT( graphic );
|
m_view->Add( graphic );
|
||||||
m_view->Add( newItem );
|
m_board->Add( graphic );
|
||||||
m_board->Add( newItem );
|
graphic->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||||
newItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Let's give the user another chance of drawing a proper arc (i.e. angle > 0)
|
||||||
|
--step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -196,18 +202,18 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
|
||||||
switch( step )
|
switch( step )
|
||||||
{
|
{
|
||||||
case SET_ORIGIN:
|
case SET_ORIGIN:
|
||||||
graphic.SetCenter( wxPoint( cursorPos.x, cursorPos.y ) );
|
graphic->SetCenter( wxPoint( cursorPos.x, cursorPos.y ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SET_END:
|
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 SET_ANGLE:
|
case SET_ANGLE:
|
||||||
{
|
{
|
||||||
// Compute the current angle
|
// Compute the current angle
|
||||||
VECTOR2D endLine( wxPoint( cursorPos.x, cursorPos.y ) - graphic.GetCenter() );
|
VECTOR2D endLine( wxPoint( cursorPos.x, cursorPos.y ) - graphic->GetCenter() );
|
||||||
double newAngle = RAD2DECIDEG( endLine.Angle() - startAngle );
|
double newAngle = RAD2DECIDEG( endLine.Angle() - startAngle );
|
||||||
|
|
||||||
if( clockwise && newAngle < 0.0 )
|
if( clockwise && newAngle < 0.0 )
|
||||||
|
@ -215,7 +221,7 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
|
||||||
else if( !clockwise && newAngle > 0.0 )
|
else if( !clockwise && newAngle > 0.0 )
|
||||||
newAngle -= 3600.0;
|
newAngle -= 3600.0;
|
||||||
|
|
||||||
graphic.SetAngle( newAngle );
|
graphic->SetAngle( newAngle );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -395,6 +401,12 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SET_END:
|
||||||
|
// Dimensions that have origin and end in the same spot are not valid
|
||||||
|
if( dimension->GetOrigin() == wxPoint( cursorPos.x, cursorPos.y ) )
|
||||||
|
--step;
|
||||||
|
break;
|
||||||
|
|
||||||
case SET_HEIGHT:
|
case SET_HEIGHT:
|
||||||
{
|
{
|
||||||
if( wxPoint( cursorPos.x, cursorPos.y ) != dimension->GetPosition() )
|
if( wxPoint( cursorPos.x, cursorPos.y ) != dimension->GetPosition() )
|
||||||
|
@ -610,12 +622,11 @@ 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 );
|
||||||
|
|
||||||
bool started = false;
|
DRAWSEGMENT* graphic = new DRAWSEGMENT( m_board );
|
||||||
DRAWSEGMENT graphic;
|
|
||||||
|
|
||||||
// Init the new item attributes
|
// Init the new item attributes
|
||||||
graphic.SetShape( (STROKE_T) aShape );
|
graphic->SetShape( (STROKE_T) aShape );
|
||||||
graphic.SetWidth( m_board->GetDesignSettings().m_DrawSegmentWidth );
|
graphic->SetWidth( m_board->GetDesignSettings().m_DrawSegmentWidth );
|
||||||
|
|
||||||
// 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
|
||||||
KIGFX::VIEW_GROUP preview( m_view );
|
KIGFX::VIEW_GROUP preview( m_view );
|
||||||
|
@ -626,6 +637,7 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
|
||||||
|
|
||||||
Activate();
|
Activate();
|
||||||
|
|
||||||
|
bool started = false;
|
||||||
// Main loop: keep receiving events
|
// Main loop: keep receiving events
|
||||||
while( OPT_TOOL_EVENT evt = Wait() )
|
while( OPT_TOOL_EVENT evt = Wait() )
|
||||||
{
|
{
|
||||||
|
@ -634,17 +646,22 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
|
||||||
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
||||||
|
|
||||||
if( evt->IsCancel() )
|
if( evt->IsCancel() )
|
||||||
|
{
|
||||||
|
preview.FreeItems();
|
||||||
|
if( !started )
|
||||||
|
delete graphic;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
else if( evt->IsKeyUp() )
|
else if( evt->IsKeyUp() )
|
||||||
{
|
{
|
||||||
int width = graphic.GetWidth();
|
int width = graphic->GetWidth();
|
||||||
|
|
||||||
// Modify the new item width
|
// Modify the new item width
|
||||||
if( evt->KeyCode() == '-' && width > WIDTH_STEP )
|
if( evt->KeyCode() == '-' && width > WIDTH_STEP )
|
||||||
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 );
|
||||||
|
|
||||||
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||||
}
|
}
|
||||||
|
@ -663,29 +680,37 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
|
||||||
{
|
{
|
||||||
m_controls->SetAutoPan( true );
|
m_controls->SetAutoPan( true );
|
||||||
|
|
||||||
graphic.SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
|
graphic->SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
|
||||||
graphic.SetLayer( layer );
|
graphic->SetLayer( layer );
|
||||||
preview.Add( &graphic );
|
preview.Add( graphic );
|
||||||
|
|
||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( wxPoint( cursorPos.x, cursorPos.y ) != graphic.GetStart() )
|
if( wxPoint( cursorPos.x, cursorPos.y ) != graphic->GetStart() )
|
||||||
{
|
{
|
||||||
DRAWSEGMENT* newItem = new DRAWSEGMENT( graphic );
|
m_view->Add( graphic );
|
||||||
m_view->Add( newItem );
|
m_board->Add( graphic );
|
||||||
m_board->Add( newItem );
|
graphic->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||||
newItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
preview.Remove( graphic );
|
||||||
|
|
||||||
if( aContinous )
|
if( aContinous )
|
||||||
graphic.SetStart( graphic.GetEnd() ); // This is the origin point for a new item
|
{
|
||||||
|
graphic = new DRAWSEGMENT( *graphic );
|
||||||
|
// Start the new line in the same spot where the previous one has ended
|
||||||
|
graphic->SetStart( graphic->GetEnd() );
|
||||||
|
preview.Add( graphic );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else // User has clicked twice in the same spot
|
else
|
||||||
break; // seems like a clear sign that the drawing is finished
|
{ // User has clicked twice in the same spot
|
||||||
|
delete graphic; // seems like a clear sign that the drawing is finished
|
||||||
|
break; // and we should remove the latest DRAWSEGMENT we have created
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,9 +718,9 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
|
||||||
{
|
{
|
||||||
// 45 degree lines
|
// 45 degree lines
|
||||||
if( linesAngle45 && aShape == S_SEGMENT )
|
if( linesAngle45 && aShape == S_SEGMENT )
|
||||||
make45DegLine( &graphic );
|
make45DegLine( graphic );
|
||||||
else
|
else
|
||||||
graphic.SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
graphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
||||||
|
|
||||||
// Show a preview of the item
|
// Show a preview of the item
|
||||||
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||||
|
@ -809,8 +834,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
|
||||||
{
|
{
|
||||||
// Add the first point
|
// Add the first point
|
||||||
zone->Outline()->Start( zoneInfo.m_CurrentZone_Layer,
|
zone->Outline()->Start( zoneInfo.m_CurrentZone_Layer,
|
||||||
cursorPos.x,
|
cursorPos.x, cursorPos.y,
|
||||||
cursorPos.y,
|
|
||||||
zone->GetHatchStyle() );
|
zone->GetHatchStyle() );
|
||||||
helperLine->SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
|
helperLine->SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
|
||||||
origin = cursorPos;
|
origin = cursorPos;
|
||||||
|
|
|
@ -54,25 +54,70 @@ public:
|
||||||
/**
|
/**
|
||||||
* Function DrawLine()
|
* Function DrawLine()
|
||||||
* Starts interactively drawing a line. After invoking the function it expects the user
|
* Starts interactively drawing a line. After invoking the function it expects the user
|
||||||
* to click at least twice to determine the origin and the end for a line. If there are
|
* to click at least two times to determine the origin and the end for a line. If there are
|
||||||
* more clicks, the line is drawn as a continous polyline.
|
* more clicks, the line is drawn as a continous polyline.
|
||||||
*/
|
*/
|
||||||
int DrawLine( TOOL_EVENT& aEvent );
|
int DrawLine( TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function DrawCircle()
|
||||||
|
* Starts interactively drawing a circle. After invoking the function it expects the user
|
||||||
|
* to first click on a point that is going to be used as the center of the circle. The second
|
||||||
|
* click determines the circle radius.
|
||||||
|
*/
|
||||||
int DrawCircle( TOOL_EVENT& aEvent );
|
int DrawCircle( TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function DrawArc()
|
||||||
|
* Starts interactively drawing an arc. After invoking the function it expects the user
|
||||||
|
* to first click on a point that is going to be used as the center of the arc. The second
|
||||||
|
* click determines the origin and radius, the third one - the angle.
|
||||||
|
*/
|
||||||
int DrawArc( TOOL_EVENT& aEvent );
|
int DrawArc( TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function DrawText()
|
||||||
|
* Displays a dialog that allows to input text and its settings and then lets the user decide
|
||||||
|
* where to place the text.
|
||||||
|
*/
|
||||||
int DrawText( TOOL_EVENT& aEvent );
|
int DrawText( TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function DrawDimension()
|
||||||
|
* Starts interactively drawing a dimension. After invoking the function it expects the user
|
||||||
|
* to first click on a point that is going to be used as the origin of the dimension.
|
||||||
|
* The second click determines the end and the third click modifies its height.
|
||||||
|
*/
|
||||||
int DrawDimension( TOOL_EVENT& aEvent );
|
int DrawDimension( TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function DrawZone()
|
||||||
|
* Starts interactively drawing a zone. After invoking the function a zone settings dialog
|
||||||
|
* is displayed. After confirmation it allows the user to set points that are going to be used
|
||||||
|
* as a boundary polygon of the zone. Double click or clicking on the origin of the boundary
|
||||||
|
* polyline finishes the drawing.
|
||||||
|
*/
|
||||||
int DrawZone( TOOL_EVENT& aEvent );
|
int DrawZone( TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function DrawKeepout()
|
||||||
|
* Starts interactively drawing a keepout area. After invoking the function an area settings
|
||||||
|
* dialog is displayed. After confirmation it allows the user to set points that are going to
|
||||||
|
* be used as a boundary polygon of the area. Double click or clicking on the origin of the
|
||||||
|
* boundary polyline finishes the drawing.
|
||||||
|
*/
|
||||||
int DrawKeepout( TOOL_EVENT& aEvent );
|
int DrawKeepout( TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function PlaceTarget()
|
||||||
|
* Allows user to place a layer alignment target.
|
||||||
|
*/
|
||||||
int PlaceTarget( TOOL_EVENT& aEvent );
|
int PlaceTarget( TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function PlaceModule()
|
||||||
|
* Displays a dialog to selected a module to be added and then allows user to set its position..
|
||||||
|
*/
|
||||||
int PlaceModule( TOOL_EVENT& aEvent );
|
int PlaceModule( TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue