Added PCB_TARGET placing tool.
This commit is contained in:
parent
e43b5f7c0f
commit
87d3458ea9
|
@ -127,6 +127,7 @@ void TARGET_PROPERTIES_DIALOG_EDITOR::OnCancelClick( wxCommandEvent& event )
|
||||||
*/
|
*/
|
||||||
void TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick( wxCommandEvent& event )
|
void TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
|
if( m_DC )
|
||||||
m_Target->Draw( m_Parent->GetCanvas(), m_DC, GR_XOR );
|
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)
|
// Save old item in undo list, if is is not currently edited (will be later if so)
|
||||||
|
@ -145,6 +146,7 @@ void TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick( wxCommandEvent& event )
|
||||||
|
|
||||||
m_Target->SetShape( m_TargetShape->GetSelection() ? 1 : 0 );
|
m_Target->SetShape( m_TargetShape->GetSelection() ? 1 : 0 );
|
||||||
|
|
||||||
|
if( m_DC )
|
||||||
m_Target->Draw( m_Parent->GetCanvas(), m_DC, ( m_Target->IsMoving() ) ? GR_XOR : GR_OR );
|
m_Target->Draw( m_Parent->GetCanvas(), m_DC, ( m_Target->IsMoving() ) ? GR_XOR : GR_OR );
|
||||||
|
|
||||||
m_Parent->OnModify();
|
m_Parent->OnModify();
|
||||||
|
|
|
@ -76,3 +76,7 @@ TOOL_ACTION COMMON_ACTIONS::drawText( "pcbnew.InteractiveDrawing.text",
|
||||||
TOOL_ACTION COMMON_ACTIONS::drawDimension( "pcbnew.InteractiveDrawing.dimension",
|
TOOL_ACTION COMMON_ACTIONS::drawDimension( "pcbnew.InteractiveDrawing.dimension",
|
||||||
AS_GLOBAL, 'X',
|
AS_GLOBAL, 'X',
|
||||||
"Add a dimension", "Add a dimension" );
|
"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)
|
/// Activation of the drawing tool (dimension)
|
||||||
static TOOL_ACTION drawDimension;
|
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_drawsegment.h>
|
||||||
#include <class_pcb_text.h>
|
#include <class_pcb_text.h>
|
||||||
#include <class_dimension.h>
|
#include <class_dimension.h>
|
||||||
|
#include <class_mire.h>
|
||||||
#include <gal/graphics_abstraction_layer.h>
|
#include <gal/graphics_abstraction_layer.h>
|
||||||
#include <tool/tool_manager.h>
|
#include <tool/tool_manager.h>
|
||||||
#include <confirm.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()
|
void DRAWING_TOOL::setTransitions()
|
||||||
{
|
{
|
||||||
Go( &DRAWING_TOOL::DrawLine, COMMON_ACTIONS::drawLine.MakeEvent() );
|
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::DrawArc, COMMON_ACTIONS::drawArc.MakeEvent() );
|
||||||
Go( &DRAWING_TOOL::DrawText, COMMON_ACTIONS::drawText.MakeEvent() );
|
Go( &DRAWING_TOOL::DrawText, COMMON_ACTIONS::drawText.MakeEvent() );
|
||||||
Go( &DRAWING_TOOL::DrawDimension, COMMON_ACTIONS::drawDimension.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 DrawDimension( TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
int PlaceTarget( TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///> Starts drawing a selected shape.
|
///> Starts drawing a selected shape.
|
||||||
int draw( STROKE_T aShape );
|
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::drawArc );
|
||||||
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawText );
|
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawText );
|
||||||
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawDimension );
|
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawDimension );
|
||||||
|
m_toolManager->RegisterAction( &COMMON_ACTIONS::placeTarget );
|
||||||
|
|
||||||
// Register tools
|
// Register tools
|
||||||
m_toolManager->RegisterTool( new SELECTION_TOOL );
|
m_toolManager->RegisterTool( new SELECTION_TOOL );
|
||||||
|
|
Loading…
Reference in New Issue