From 2bcbb67528fd511fd5743aa97b061c4570793974 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 9 Jul 2014 15:02:56 +0200 Subject: [PATCH] Initial version of the Pad Enumeration tool. --- pcbnew/tools/common_actions.cpp | 4 ++ pcbnew/tools/common_actions.h | 3 + pcbnew/tools/module_tools.cpp | 116 ++++++++++++++++++++++++++++++++ pcbnew/tools/module_tools.h | 6 ++ 4 files changed, 129 insertions(+) diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 96c819e890..c1b538ba04 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -269,6 +269,10 @@ TOOL_ACTION COMMON_ACTIONS::placePad( "pcbnew.ModuleEditor.placePad", AS_GLOBAL, 0, "Add pads", "Add pads", AF_ACTIVATE ); +TOOL_ACTION COMMON_ACTIONS::enumeratePads( "pcbnew.ModuleEditor.enumeratePads", + AS_GLOBAL, 0, + "Enumerate pads", "Enumerate pads", AF_ACTIVATE ); + TOOL_ACTION COMMON_ACTIONS::copyItems( "pcbnew.ModuleEditor.copyItems", AS_GLOBAL, MD_CTRL + int( 'C' ), "Copy items", "Copy items", AF_ACTIVATE ); diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index e25e4a431f..78bc6f50d1 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -177,6 +177,9 @@ public: /// Activation of the drawing tool (placing a PAD) static TOOL_ACTION placePad; + /// Tool for quick pad enumeration + static TOOL_ACTION enumeratePads; + /// Copying module items to clipboard static TOOL_ACTION copyItems; diff --git a/pcbnew/tools/module_tools.cpp b/pcbnew/tools/module_tools.cpp index dffc355133..2a297052e0 100644 --- a/pcbnew/tools/module_tools.cpp +++ b/pcbnew/tools/module_tools.cpp @@ -32,6 +32,8 @@ #include #include +#include +#include #include #include @@ -39,6 +41,7 @@ #include #include +#include MODULE_TOOLS::MODULE_TOOLS() : TOOL_INTERACTIVE( "pcbnew.ModuleEditor" ) @@ -58,6 +61,17 @@ void MODULE_TOOLS::Reset( RESET_REASON aReason ) bool MODULE_TOOLS::Init() { + // Find the selection tool, so they can cooperate + SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); + + if( !selectionTool ) + { + DisplayError( NULL, wxT( "pcbnew.InteractiveSelection tool is not available" ) ); + return false; + } + + selectionTool->AddMenuItem( COMMON_ACTIONS::enumeratePads ); + setTransitions(); return true; @@ -204,6 +218,107 @@ int MODULE_TOOLS::PlacePad( TOOL_EVENT& aEvent ) } +int MODULE_TOOLS::EnumeratePads( TOOL_EVENT& aEvent ) +{ + std::list pads; + std::set allPads; + MODULE* module = m_board->m_Modules; + + GENERAL_COLLECTOR collector; + const KICAD_T types[] = { PCB_PAD_T, EOT }; + + GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide(); + guide.SetIgnoreMTextsMarkedNoShow( true ); + guide.SetIgnoreMTextsOnCopper( true ); + guide.SetIgnoreMTextsOnCmp( true ); + guide.SetIgnoreModulesOnCu( true ); + guide.SetIgnoreModulesOnCmp( true ); + guide.SetIgnoreModulesVals( true ); + guide.SetIgnoreModulesRefs( true ); + + // Create a set containing all pads (to avoid double adding to a list); + for( D_PAD* p = module->Pads(); p; p = p->Next() ) + allPads.insert( p ); + + // TODO display settings window + int padNumber = 1; + wxString padPrefix = ""; + + m_frame->DisplayToolMsg( _( "Hold left mouse button and move cursor over pads to enumerate them" ) ); + + Activate(); + + m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); + m_controls->ShowCursor( true ); + + while( OPT_TOOL_EVENT evt = Wait() ) + { + if( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) + { + // Add pads to the list according to the selection order + VECTOR2I cursorPos = m_controls->GetCursorPosition(); + + collector.Empty(); + collector.Collect( m_board, types, wxPoint( cursorPos.x, cursorPos.y ), guide ); + + for( int i = 0; i < collector.GetCount(); ++i ) + { + if( collector[i]->Type() == PCB_PAD_T ) + { + D_PAD* pad = static_cast( collector[i] ); + + std::set::iterator it = allPads.find( pad ); + + // Add the pad to the list, if it was not selected previously.. + if( it != allPads.end() ) + { + allPads.erase( it ); + pads.push_back( pad ); + pad->SetSelected(); + } + + // ..or remove it from the list if it was clicked + else if( evt->IsClick( BUT_LEFT ) ) + { + allPads.insert( pad ); + pads.remove( pad ); + pad->ClearSelected(); + } + } + } + } + + else if( ( evt->IsKeyPressed() && evt->KeyCode() == WXK_RETURN ) || + evt->IsDblClick( BUT_LEFT ) ) + { + // Accept changes + m_frame->OnModify(); + m_frame->SaveCopyInUndoList( module, UR_MODEDIT ); + + BOOST_FOREACH( D_PAD* pad, pads ) + pad->SetPadName( wxString::Format( "%s%d", padPrefix, padNumber++ ) ); + + break; + } + + else if( evt->IsCancel() || evt->IsActivate() ) + { + break; + } + } + + BOOST_FOREACH( D_PAD* pad, pads ) + pad->ClearSelected(); + + m_frame->DisplayToolMsg( wxEmptyString ); + m_controls->ShowCursor( false ); + + setTransitions(); + + return 0; +} + + int MODULE_TOOLS::CopyItems( TOOL_EVENT& aEvent ) { const SELECTION_TOOL::SELECTION& selection = m_toolMgr->GetTool()->GetSelection(); @@ -411,6 +526,7 @@ int MODULE_TOOLS::PasteItems( TOOL_EVENT& aEvent ) void MODULE_TOOLS::setTransitions() { Go( &MODULE_TOOLS::PlacePad, COMMON_ACTIONS::placePad.MakeEvent() ); + Go( &MODULE_TOOLS::EnumeratePads, COMMON_ACTIONS::enumeratePads.MakeEvent() ); Go( &MODULE_TOOLS::CopyItems, COMMON_ACTIONS::copyItems.MakeEvent() ); Go( &MODULE_TOOLS::PasteItems, COMMON_ACTIONS::pasteItems.MakeEvent() ); } diff --git a/pcbnew/tools/module_tools.h b/pcbnew/tools/module_tools.h index b23898c02c..64899e4182 100644 --- a/pcbnew/tools/module_tools.h +++ b/pcbnew/tools/module_tools.h @@ -57,6 +57,12 @@ public: */ int PlacePad( TOOL_EVENT& aEvent ); + /** + * Function EnumeratePads() + * Tool for quick pad enumeration. + */ + int EnumeratePads( TOOL_EVENT& aEvent ); + /** * Function CopyItems() *