Added keepout areas drawing tool.

This commit is contained in:
Maciej Suminski 2014-02-13 16:24:33 +01:00
parent fce753ba24
commit 3106d25361
5 changed files with 155 additions and 3 deletions

View File

@ -81,6 +81,10 @@ TOOL_ACTION COMMON_ACTIONS::drawZone( "pcbnew.InteractiveDrawing.zone",
AS_GLOBAL, 'B',
"Add a filled zone", "Add a filled zone" );
TOOL_ACTION COMMON_ACTIONS::drawKeepout( "pcbnew.InteractiveDrawing.keepout",
AS_GLOBAL, 'N',
"Add a keepout area", "Add a keepout area" );
TOOL_ACTION COMMON_ACTIONS::placeTarget( "pcbnew.InteractiveDrawing.placeTarget",
AS_GLOBAL, 'C',
"Add layer alignment target", "Add layer alignment target" );

View File

@ -75,6 +75,9 @@ public:
/// Activation of the drawing tool (drawing a ZONE)
static TOOL_ACTION drawZone;
/// Activation of the drawing tool (drawing a keepout area)
static TOOL_ACTION drawKeepout;
/// Activation of the drawing tool (placing a TARGET)
static TOOL_ACTION placeTarget;

View File

@ -598,7 +598,6 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX::VIEW_GROUP preview( view );
// preview.Add( zone );
view->Add( &preview );
controls->ShowCursor( true );
@ -705,8 +704,150 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
controls->SetAutoPan( false );
view->Remove( &preview );
// remove helper lines only
// preview.Remove( zone );
// delete helper lines
preview.FreeItems();
setTransitions();
return 0;
}
int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
{
KIGFX::VIEW* view = getView();
KIGFX::VIEW_CONTROLS* controls = getViewControls();
BOARD* board = getModel<BOARD>( PCB_T );
ZONE_CONTAINER* keepout = new ZONE_CONTAINER( board );
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
// Get the current, default settings for zones
ZONE_SETTINGS zoneInfo = editFrame->GetZoneSettings();
ZONE_EDIT_T dialogResult = InvokeKeepoutAreaEditor( editFrame, &zoneInfo );
if( dialogResult == ZONE_ABORT )
{
delete keepout;
setTransitions();
return 0;
}
zoneInfo.ExportSetting( *keepout );
editFrame->SetTopLayer( zoneInfo.m_CurrentZone_Layer );
DRAWSEGMENT* helperLine = new DRAWSEGMENT;
helperLine->SetShape( S_SEGMENT );
helperLine->SetLayer( zoneInfo.m_CurrentZone_Layer );
helperLine->SetWidth( 1 );
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX::VIEW_GROUP preview( view );
view->Add( &preview );
controls->ShowCursor( true );
controls->SetSnapping( true );
controls->SetAutoPan( true );
Activate();
VECTOR2D lastCursorPos = view->ToWorld( controls->GetCursorPosition() );
// Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() )
{
// Enable 45 degrees lines only mode by holding shift
bool linesAngle45 = evt->Modifier( MD_SHIFT );
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() );
if( evt->IsCancel() )
{
delete keepout;
break;
}
else if( evt->IsClick( BUT_LEFT ) )
{
if( lastCursorPos == cursorPos ||
( keepout->GetNumCorners() > 0 && wxPoint( cursorPos.x, cursorPos.y ) == keepout->Outline()->GetPos( 0 ) ) ) // TODO better conditions
{
if( keepout->GetNumCorners() > 2 )
{
// Finish the zone
keepout->Outline()->CloseLastContour();
keepout->Outline()->RemoveNullSegments();
board->Add( keepout );
view->Add( keepout );
keepout->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
else
{
// That is not a valid zone
delete keepout;
}
break;
}
else
{
if( keepout->GetNumCorners() == 0 )
{
keepout->Outline()->Start( zoneInfo.m_CurrentZone_Layer,
cursorPos.x,
cursorPos.y,
keepout->GetHatchStyle() );
helperLine->SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
preview.Add( helperLine );
}
else
{
keepout->AppendCorner( helperLine->GetEnd() );
helperLine = new DRAWSEGMENT( *helperLine );
preview.Add( helperLine );
helperLine->SetStart( helperLine->GetEnd() );
}
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
lastCursorPos = cursorPos;
}
else if( evt->IsMotion() )
{
helperLine->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
// 45 degree lines
if( linesAngle45 )
{
VECTOR2D lineVector( wxPoint( cursorPos.x, cursorPos.y ) - helperLine->GetStart() );
double angle = lineVector.Angle();
double newAngle = round( angle / ( M_PI / 4.0 ) ) * M_PI / 4.0;
VECTOR2D newLineVector = lineVector.Rotate( newAngle - angle );
// Snap the new line to the grid // TODO fix it, does not work good..
VECTOR2D newLineEnd = VECTOR2D( helperLine->GetStart() ) + newLineVector;
VECTOR2D snapped = view->GetGAL()->GetGridPoint( newLineEnd );
helperLine->SetEnd( wxPoint( snapped.x, snapped.y ) );
}
else
{
helperLine->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
}
// Show a preview of the item
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
}
controls->ShowCursor( false );
controls->SetSnapping( false );
controls->SetAutoPan( false );
view->Remove( &preview );
// delete helper lines
preview.FreeItems();
setTransitions();
@ -875,6 +1016,7 @@ void DRAWING_TOOL::setTransitions()
Go( &DRAWING_TOOL::DrawText, COMMON_ACTIONS::drawText.MakeEvent() );
Go( &DRAWING_TOOL::DrawDimension, COMMON_ACTIONS::drawDimension.MakeEvent() );
Go( &DRAWING_TOOL::DrawZone, COMMON_ACTIONS::drawZone.MakeEvent() );
Go( &DRAWING_TOOL::DrawKeepout, COMMON_ACTIONS::drawKeepout.MakeEvent() );
Go( &DRAWING_TOOL::PlaceTarget, COMMON_ACTIONS::placeTarget.MakeEvent() );
Go( &DRAWING_TOOL::PlaceModule, COMMON_ACTIONS::placeModule.MakeEvent() );
}

View File

@ -61,6 +61,8 @@ public:
int DrawZone( TOOL_EVENT& aEvent );
int DrawKeepout( TOOL_EVENT& aEvent );
int PlaceTarget( TOOL_EVENT& aEvent );
int PlaceModule( TOOL_EVENT& aEvent );

View File

@ -61,6 +61,7 @@ void PCB_EDIT_FRAME::setupTools()
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawText );
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawDimension );
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawZone );
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawKeepout );
m_toolManager->RegisterAction( &COMMON_ACTIONS::placeTarget );
m_toolManager->RegisterAction( &COMMON_ACTIONS::placeModule );