diff --git a/pcbnew/target_edit.cpp b/pcbnew/target_edit.cpp index dba25a86d2..75989719c9 100644 --- a/pcbnew/target_edit.cpp +++ b/pcbnew/target_edit.cpp @@ -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 ); diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 4649123d24..de860ccc06 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -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" ); diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index c2e350a67d..732aa22e7d 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -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; }; diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index bfe59af214..28c287ea7a 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -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( 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() ); } diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index 3af4c4fee7..c34109a2cf 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -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 ); diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index e05d294a11..9202ddb4b5 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -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 );