From bd22ab3df5f2d869b500262d4655a64757630f06 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 9 Jul 2014 14:01:06 +0200 Subject: [PATCH] Adapted graphics tools to cooperate with module editor. --- pcbnew/moduleframe.cpp | 3 +- pcbnew/tools/common_actions.cpp | 7 ++ pcbnew/tools/drawing_tool.cpp | 121 +++++++++++++++++++++++++------- 3 files changed, 103 insertions(+), 28 deletions(-) diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 451f5a9130..ed9ff6165e 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -271,11 +271,12 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : drawPanel->SetEventDispatcher( m_toolDispatcher ); m_toolManager->RegisterTool( new SELECTION_TOOL ); - m_toolManager->GetTool()->EditModules( true ); m_toolManager->RegisterTool( new EDIT_TOOL ); m_toolManager->RegisterTool( new DRAWING_TOOL ); m_toolManager->RegisterTool( new POINT_EDITOR ); m_toolManager->RegisterTool( new PCBNEW_CONTROL ); + m_toolManager->GetTool()->EditModules( true ); + m_toolManager->GetTool()->EditModules( true ); m_toolManager->ResetTools( TOOL_BASE::RUN ); // Run the selection tool, it is supposed to be always active diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 71c5b928f3..57edb54dc6 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -286,12 +286,15 @@ boost::optional COMMON_ACTIONS::TranslateLegacyId( int aId ) return COMMON_ACTIONS::drawKeepout.MakeEvent(); case ID_PCB_ADD_LINE_BUTT: + case ID_MODEDIT_LINE_TOOL: return COMMON_ACTIONS::drawLine.MakeEvent(); case ID_PCB_CIRCLE_BUTT: + case ID_MODEDIT_CIRCLE_TOOL: return COMMON_ACTIONS::drawCircle.MakeEvent(); case ID_PCB_ARC_BUTT: + case ID_MODEDIT_ARC_TOOL: return COMMON_ACTIONS::drawArc.MakeEvent(); case ID_PCB_ADD_TEXT_BUTT: @@ -305,6 +308,7 @@ boost::optional COMMON_ACTIONS::TranslateLegacyId( int aId ) return COMMON_ACTIONS::placeTarget.MakeEvent(); case ID_PCB_PLACE_GRID_COORD_BUTT: + case ID_MODEDIT_PLACE_GRID_COORD: return COMMON_ACTIONS::gridSetOrigin.MakeEvent(); case ID_ZOOM_IN: // toolbar button "Zoom In" @@ -325,6 +329,9 @@ boost::optional COMMON_ACTIONS::TranslateLegacyId( int aId ) case ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR_MICROWAVE: case ID_MENU_PCB_SHOW_HIDE_MUWAVE_TOOLBAR: case ID_MICROWAVE_V_TOOLBAR: + case ID_MODEDIT_PAD_TOOL: + case ID_MODEDIT_DELETE_TOOL: + case ID_MODEDIT_ANCHOR_TOOL: return COMMON_ACTIONS::toBeDone.MakeEvent(); } diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index e2fde67446..37264569a5 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include #include @@ -73,13 +73,38 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason ) int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent ) { - m_frame->SetToolID( ID_PCB_ADD_LINE_BUTT, wxCURSOR_PENCIL, _( "Add graphic line" ) ); - - DRAWSEGMENT* line = new DRAWSEGMENT; - - while( drawSegment( S_SEGMENT, line ) ) + if( m_editModules ) { - line = new DRAWSEGMENT; + m_frame->SetToolID( ID_MODEDIT_LINE_TOOL, wxCURSOR_PENCIL, _( "Add graphic line" ) ); + + MODULE* module = m_frame->GetBoard()->m_Modules; + EDGE_MODULE* line = new EDGE_MODULE( module ); + + while( drawSegment( S_SEGMENT, line ) ) + { + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( module, UR_MODEDIT ); + line->SetLocalCoord(); + line->SetParent( module ); + module->GraphicalItems().PushFront( line ); + + line = new EDGE_MODULE( module ); + } + } + else + { + m_frame->SetToolID( ID_PCB_ADD_LINE_BUTT, wxCURSOR_PENCIL, _( "Add graphic line" ) ); + + DRAWSEGMENT* line = new DRAWSEGMENT; + + while( drawSegment( S_SEGMENT, line ) ) + { + m_board->Add( line ); + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( line, UR_NEW ); + + line = new DRAWSEGMENT; + } } setTransitions(); @@ -91,13 +116,38 @@ int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent ) int DRAWING_TOOL::DrawCircle( TOOL_EVENT& aEvent ) { - m_frame->SetToolID( ID_PCB_CIRCLE_BUTT, wxCURSOR_PENCIL, _( "Add graphic circle" ) ); - - DRAWSEGMENT* circle = new DRAWSEGMENT; - - while( drawSegment( S_CIRCLE, circle ) ) + if( m_editModules ) { - circle = new DRAWSEGMENT; + m_frame->SetToolID( ID_MODEDIT_CIRCLE_TOOL, wxCURSOR_PENCIL, _( "Add graphic circle" ) ); + + MODULE* module = m_frame->GetBoard()->m_Modules; + EDGE_MODULE* circle = new EDGE_MODULE( module ); + + while( drawSegment( S_CIRCLE, circle ) ) + { + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( module, UR_MODEDIT ); + circle->SetLocalCoord(); + circle->SetParent( module ); + module->GraphicalItems().PushFront( circle ); + + circle = new EDGE_MODULE( module ); + } + } + else + { + m_frame->SetToolID( ID_PCB_CIRCLE_BUTT, wxCURSOR_PENCIL, _( "Add graphic circle" ) ); + + DRAWSEGMENT* circle = new DRAWSEGMENT; + + while( drawSegment( S_CIRCLE, circle ) ) + { + m_board->Add( circle ); + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( circle, UR_NEW ); + + circle = new DRAWSEGMENT; + } } setTransitions(); @@ -109,13 +159,38 @@ int DRAWING_TOOL::DrawCircle( TOOL_EVENT& aEvent ) int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) { - m_frame->SetToolID( ID_PCB_ARC_BUTT, wxCURSOR_PENCIL, _( "Add graphic arc" ) ); - - DRAWSEGMENT* arc = new DRAWSEGMENT; - - while( drawArc( arc ) ) + if( m_editModules ) { - arc = new DRAWSEGMENT; + m_frame->SetToolID( ID_MODEDIT_ARC_TOOL, wxCURSOR_PENCIL, _( "Add graphic arc" ) ); + + MODULE* module = m_frame->GetBoard()->m_Modules; + EDGE_MODULE* arc = new EDGE_MODULE( module ); + + while( drawArc( arc ) ) + { + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( module, UR_MODEDIT ); + arc->SetLocalCoord(); + arc->SetParent( module ); + module->GraphicalItems().PushFront( arc ); + + arc = new EDGE_MODULE( module ); + } + } + else + { + m_frame->SetToolID( ID_PCB_ARC_BUTT, wxCURSOR_PENCIL, _( "Add graphic arc" ) ); + + DRAWSEGMENT* arc = new DRAWSEGMENT; + + while( drawArc( arc ) ) + { + m_board->Add( arc ); + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( arc, UR_NEW ); + + arc = new DRAWSEGMENT; + } } setTransitions(); @@ -624,11 +699,7 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT* aGraphic ) assert( aGraphic->GetWidth() > 0 ); m_view->Add( aGraphic ); - m_board->Add( aGraphic ); aGraphic->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( aGraphic, UR_NEW ); } else // User has clicked twice in the same spot { // a clear sign that the current drawing is finished @@ -785,12 +856,8 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT* aGraphic ) assert( aGraphic->GetWidth() > 0 ); m_view->Add( aGraphic ); - m_board->Add( aGraphic ); aGraphic->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - m_frame->OnModify(); - m_frame->SaveCopyInUndoList( aGraphic, UR_NEW ); - preview.Remove( aGraphic ); preview.Remove( &helperLine ); }