Commit 87d3458e authored by Maciej Suminski's avatar Maciej Suminski

Added PCB_TARGET placing tool.

parent e43b5f7c
......@@ -127,7 +127,8 @@ void TARGET_PROPERTIES_DIALOG_EDITOR::OnCancelClick( wxCommandEvent& event )
*/
void TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick( wxCommandEvent& event )
{
m_Target->Draw( m_Parent->GetCanvas(), m_DC, GR_XOR );
if( m_DC )
m_Target->Draw( m_Parent->GetCanvas(), m_DC, GR_XOR );
// Save old item in undo list, if is is not currently edited (will be later if so)
if( m_Target->GetFlags() == 0 )
......@@ -145,7 +146,8 @@ void TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick( wxCommandEvent& event )
m_Target->SetShape( m_TargetShape->GetSelection() ? 1 : 0 );
m_Target->Draw( m_Parent->GetCanvas(), m_DC, ( m_Target->IsMoving() ) ? GR_XOR : GR_OR );
if( m_DC )
m_Target->Draw( m_Parent->GetCanvas(), m_DC, ( m_Target->IsMoving() ) ? GR_XOR : GR_OR );
m_Parent->OnModify();
EndModal( 1 );
......
......@@ -76,3 +76,7 @@ TOOL_ACTION COMMON_ACTIONS::drawText( "pcbnew.InteractiveDrawing.text",
TOOL_ACTION COMMON_ACTIONS::drawDimension( "pcbnew.InteractiveDrawing.dimension",
AS_GLOBAL, 'X',
"Add a dimension", "Add a dimension" );
TOOL_ACTION COMMON_ACTIONS::placeTarget( "pcbnew.InteractiveDrawing.placeTarget",
AS_GLOBAL, 'C',
"Add layer alignment target", "Add layer alignment target" );
......@@ -71,4 +71,7 @@ public:
/// Activation of the drawing tool (dimension)
static TOOL_ACTION drawDimension;
/// Activation of the drawing tool (placing a TARGET)
static TOOL_ACTION placeTarget;
};
......@@ -32,6 +32,7 @@
#include <class_drawsegment.h>
#include <class_pcb_text.h>
#include <class_dimension.h>
#include <class_mire.h>
#include <gal/graphics_abstraction_layer.h>
#include <tool/tool_manager.h>
#include <confirm.h>
......@@ -558,6 +559,77 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
}
int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
{
KIGFX::VIEW* view = getView();
KIGFX::VIEW_CONTROLS* controls = getViewControls();
BOARD* board = getModel<BOARD>( PCB_T );
PCB_TARGET* target = new PCB_TARGET( board );
// Init the new item attributes
target->SetLayer( EDGE_N );
target->SetWidth( board->GetDesignSettings().m_EdgeSegmentWidth );
target->SetSize( Millimeter2iu( 5 ) );
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX::VIEW_GROUP preview( view );
preview.Add( target );
view->Add( &preview );
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
controls->SetSnapping( true );
Activate();
// Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() )
{
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() );
if( evt->IsCancel() )
{
delete target;
break;
}
else if( evt->IsKeyUp() )
{
int width = target->GetWidth();
// Modify the new item width
if( evt->KeyCode() == '-' && width > WIDTH_STEP )
target->SetWidth( width - WIDTH_STEP );
else if( evt->KeyCode() == '=' )
target->SetWidth( width + WIDTH_STEP );
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
else if( evt->IsClick( BUT_LEFT ) )
{
view->Add( target );
board->Add( target );
target->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
break;
}
else if( evt->IsMotion() )
{
target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
}
controls->SetSnapping( false );
controls->SetAutoPan( false );
view->Remove( &preview );
setTransitions();
return 0;
}
void DRAWING_TOOL::setTransitions()
{
Go( &DRAWING_TOOL::DrawLine, COMMON_ACTIONS::drawLine.MakeEvent() );
......@@ -565,4 +637,5 @@ void DRAWING_TOOL::setTransitions()
Go( &DRAWING_TOOL::DrawArc, COMMON_ACTIONS::drawArc.MakeEvent() );
Go( &DRAWING_TOOL::DrawText, COMMON_ACTIONS::drawText.MakeEvent() );
Go( &DRAWING_TOOL::DrawDimension, COMMON_ACTIONS::drawDimension.MakeEvent() );
Go( &DRAWING_TOOL::PlaceTarget, COMMON_ACTIONS::placeTarget.MakeEvent() );
}
......@@ -59,6 +59,8 @@ public:
int DrawDimension( TOOL_EVENT& aEvent );
int PlaceTarget( TOOL_EVENT& aEvent );
private:
///> Starts drawing a selected shape.
int draw( STROKE_T aShape );
......
......@@ -60,6 +60,7 @@ void PCB_EDIT_FRAME::setupTools()
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawArc );
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawText );
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawDimension );
m_toolManager->RegisterAction( &COMMON_ACTIONS::placeTarget );
// Register tools
m_toolManager->RegisterTool( new SELECTION_TOOL );
......
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