2014-07-09 13:02:56 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-01-21 20:03:36 +00:00
|
|
|
* Copyright (C) 2014-2019 CERN
|
2014-07-09 13:02:56 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
#include "footprint_editor_tools.h"
|
2020-05-03 07:59:05 +00:00
|
|
|
#include <pad_naming.h>
|
2017-05-18 17:21:30 +00:00
|
|
|
#include "kicad_clipboard.h"
|
2014-07-09 13:02:56 +00:00
|
|
|
#include "selection_tool.h"
|
2017-02-21 12:42:08 +00:00
|
|
|
#include "pcb_actions.h"
|
2017-11-01 11:14:16 +00:00
|
|
|
|
|
|
|
#include <core/optional.h>
|
|
|
|
|
2015-05-05 18:39:41 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
#include <class_draw_panel_gal.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <view/view_group.h>
|
2014-07-09 13:10:32 +00:00
|
|
|
#include <pcb_painter.h>
|
2015-09-05 19:47:35 +00:00
|
|
|
#include <origin_viewitem.h>
|
2019-01-17 13:23:03 +00:00
|
|
|
#include <status_popup.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
#include <kicad_plugin.h>
|
|
|
|
#include <pcbnew_id.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
#include <collectors.h>
|
|
|
|
#include <confirm.h>
|
2014-07-09 13:10:32 +00:00
|
|
|
#include <dialogs/dialog_enum_pads.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <hotkeys.h>
|
|
|
|
#include <bitmaps.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_edge_mod.h>
|
2016-06-21 15:06:28 +00:00
|
|
|
#include <board_commit.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-02-04 05:09:50 +00:00
|
|
|
#include <tools/tool_event_utils.h>
|
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
2014-07-09 13:10:32 +00:00
|
|
|
#include <wx/defs.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
// Module editor tools
|
|
|
|
TOOL_ACTION PCB_ACTIONS::placePad( "pcbnew.ModuleEditor.placePad",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
_( "Add Pad" ), _( "Add a pad" ), NULL, AF_ACTIVATE );
|
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
TOOL_ACTION PCB_ACTIONS::createPadFromShapes( "pcbnew.ModuleEditor.createPadFromShapes",
|
|
|
|
AS_CONTEXT, 0,
|
2017-10-20 16:25:44 +00:00
|
|
|
_( "Create Pad from Selected Shapes" ),
|
|
|
|
_( "Creates a custom-shaped pads from a set of selected shapes" ),
|
|
|
|
primitives_to_custom_pad_xpm );
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::explodePadToShapes( "pcbnew.ModuleEditor.explodePadToShapes",
|
|
|
|
AS_CONTEXT, 0,
|
2018-02-09 16:28:33 +00:00
|
|
|
_( "Explode Pad to Graphic Shapes" ),
|
2017-10-20 16:25:44 +00:00
|
|
|
_( "Converts a custom-shaped pads to a set of graphical shapes" ),
|
|
|
|
custom_pad_to_primitives_xpm );
|
2017-10-19 21:16:06 +00:00
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
TOOL_ACTION PCB_ACTIONS::enumeratePads( "pcbnew.ModuleEditor.enumeratePads",
|
|
|
|
AS_GLOBAL, 0,
|
2018-02-09 16:28:33 +00:00
|
|
|
_( "Renumber Pads..." ), _( "Renumber pads by clicking on them in the desired order" ), pad_enumerate_xpm, AF_ACTIVATE );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
MODULE_EDITOR_TOOLS::MODULE_EDITOR_TOOLS() :
|
2017-04-18 15:32:05 +00:00
|
|
|
PCB_TOOL( "pcbnew.ModuleEditor" )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2015-09-05 19:47:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
MODULE_EDITOR_TOOLS::~MODULE_EDITOR_TOOLS()
|
2015-09-05 19:47:35 +00:00
|
|
|
{
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
void MODULE_EDITOR_TOOLS::Reset( RESET_REASON aReason )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2020-05-03 07:59:05 +00:00
|
|
|
if( aReason == MODEL_RELOAD )
|
|
|
|
m_lastPadName = wxT( "1" );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-22 15:46:31 +00:00
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2019-07-19 21:13:52 +00:00
|
|
|
if( !frame()->GetBoard()->m_Modules )
|
|
|
|
return 0;
|
|
|
|
|
2017-04-22 15:46:31 +00:00
|
|
|
struct PAD_PLACER : public INTERACTIVE_PLACER_BASE
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2020-05-03 07:59:05 +00:00
|
|
|
PAD_PLACER( MODULE_EDITOR_TOOLS* aFPEditTools )
|
|
|
|
{
|
|
|
|
m_fpEditTools = aFPEditTools;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~PAD_PLACER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-22 15:46:31 +00:00
|
|
|
std::unique_ptr<BOARD_ITEM> CreateItem() override
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2017-04-22 15:46:31 +00:00
|
|
|
D_PAD* pad = new D_PAD ( m_board->m_Modules );
|
|
|
|
m_frame->Import_Pad_Settings( pad, false ); // use the global settings for pad
|
2020-05-03 07:59:05 +00:00
|
|
|
|
|
|
|
if( PAD_NAMING::PadCanHaveName( *pad ) )
|
|
|
|
{
|
|
|
|
wxString padName = m_fpEditTools->GetLastPadName();
|
|
|
|
padName = m_board->m_Modules->GetNextPadName( padName );
|
|
|
|
pad->SetName( padName );
|
|
|
|
m_fpEditTools->SetLastPadName( padName );
|
|
|
|
}
|
|
|
|
|
2017-04-22 15:46:31 +00:00
|
|
|
return std::unique_ptr<BOARD_ITEM>( pad );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
2018-10-21 12:50:31 +00:00
|
|
|
|
2019-01-23 15:18:44 +00:00
|
|
|
bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit ) override
|
2018-10-21 12:50:31 +00:00
|
|
|
{
|
2019-01-21 20:33:37 +00:00
|
|
|
D_PAD* pad = dynamic_cast<D_PAD*>( aItem );
|
|
|
|
|
|
|
|
if( pad )
|
|
|
|
{
|
|
|
|
m_frame->Export_Pad_Settings( pad );
|
|
|
|
pad->SetLocalCoord();
|
|
|
|
aCommit.Add( aItem );
|
2019-01-23 15:18:44 +00:00
|
|
|
return true;
|
2019-01-21 20:33:37 +00:00
|
|
|
}
|
2019-01-23 15:18:44 +00:00
|
|
|
|
|
|
|
return false;
|
2018-10-21 12:50:31 +00:00
|
|
|
}
|
2020-05-03 07:59:05 +00:00
|
|
|
|
|
|
|
MODULE_EDITOR_TOOLS* m_fpEditTools;
|
2017-04-22 15:46:31 +00:00
|
|
|
};
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2020-05-03 07:59:05 +00:00
|
|
|
PAD_PLACER placer( this );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-04-22 15:46:31 +00:00
|
|
|
frame()->SetToolID( ID_MODEDIT_PAD_TOOL, wxCURSOR_PENCIL, _( "Add pads" ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2018-10-09 22:18:15 +00:00
|
|
|
doInteractiveItemPlacement( &placer, _( "Place pad" ), IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-04-18 15:32:05 +00:00
|
|
|
frame()->SetNoToolSelected();
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2017-04-25 09:06:24 +00:00
|
|
|
if( !board()->m_Modules || !board()->m_Modules->PadsList() )
|
2015-08-25 08:22:52 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-07-19 13:58:53 +00:00
|
|
|
DIALOG_ENUM_PADS settingsDlg( frame() );
|
|
|
|
|
|
|
|
if( settingsDlg.ShowModal() != wxID_OK )
|
|
|
|
return 0;
|
|
|
|
|
2017-03-02 11:34:19 +00:00
|
|
|
Activate();
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
GENERAL_COLLECTOR collector;
|
|
|
|
const KICAD_T types[] = { PCB_PAD_T, EOT };
|
|
|
|
|
2017-04-18 15:32:05 +00:00
|
|
|
GENERAL_COLLECTORS_GUIDE guide = frame()->GetCollectorsGuide();
|
2014-07-09 13:02:56 +00:00
|
|
|
guide.SetIgnoreMTextsMarkedNoShow( true );
|
2014-09-11 16:35:19 +00:00
|
|
|
guide.SetIgnoreMTextsOnBack( true );
|
|
|
|
guide.SetIgnoreMTextsOnFront( true );
|
2014-07-09 13:02:56 +00:00
|
|
|
guide.SetIgnoreModulesVals( true );
|
|
|
|
guide.SetIgnoreModulesRefs( true );
|
|
|
|
|
2019-01-17 13:55:50 +00:00
|
|
|
int seqPadNum = settingsDlg.GetStartNumber();
|
2014-07-09 13:10:32 +00:00
|
|
|
wxString padPrefix = settingsDlg.GetPrefix();
|
2019-01-17 13:55:50 +00:00
|
|
|
std::deque<int> storedPadNumbers;
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2018-02-14 23:46:33 +00:00
|
|
|
frame()->SetToolID( ID_MODEDIT_PAD_TOOL, wxCURSOR_HAND,
|
|
|
|
_( "Click on successive pads to renumber them" ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2017-04-18 15:32:05 +00:00
|
|
|
getViewControls()->ShowCursor( true );
|
2017-03-02 11:34:19 +00:00
|
|
|
|
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
2017-07-19 13:58:53 +00:00
|
|
|
VECTOR2I oldCursorPos; // store the previous mouse cursor position, during mouse drag
|
2015-02-21 20:16:28 +00:00
|
|
|
std::list<D_PAD*> selectedPads;
|
2017-04-18 15:32:05 +00:00
|
|
|
BOARD_COMMIT commit( frame() );
|
2019-01-17 13:55:50 +00:00
|
|
|
std::map<wxString, std::pair<int, wxString>> oldNames;
|
2017-07-19 13:58:53 +00:00
|
|
|
bool isFirstPoint = true; // used to be sure oldCursorPos will be initialized at least once.
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2019-01-17 13:23:03 +00:00
|
|
|
STATUS_TEXT_POPUP statusPopup( frame() );
|
|
|
|
statusPopup.SetText( wxString::Format(
|
|
|
|
_( "Click on pad %s%d\nPress Escape to cancel or double-click to commit" ),
|
2019-01-17 13:55:50 +00:00
|
|
|
padPrefix.c_str(), seqPadNum ) );
|
2019-01-17 13:23:03 +00:00
|
|
|
statusPopup.Popup();
|
|
|
|
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
2017-08-08 14:46:20 +00:00
|
|
|
if( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2015-02-21 20:16:28 +00:00
|
|
|
selectedPads.clear();
|
2017-04-18 15:32:05 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-07-19 13:58:53 +00:00
|
|
|
// Be sure the old cursor mouse position was initialized:
|
|
|
|
if( isFirstPoint )
|
|
|
|
{
|
|
|
|
oldCursorPos = cursorPos;
|
|
|
|
isFirstPoint = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// wxWidgets deliver mouse move events not frequently enough, resulting in skipping
|
|
|
|
// pads if the user moves cursor too fast. To solve it, create a line that approximates
|
|
|
|
// the mouse move and search pads that are on the line.
|
|
|
|
int distance = ( cursorPos - oldCursorPos ).EuclideanNorm();
|
|
|
|
// Search will be made every 0.1 mm:
|
|
|
|
int segments = distance / int( 0.1*IU_PER_MM ) + 1;
|
|
|
|
const wxPoint line_step( ( cursorPos - oldCursorPos ) / segments );
|
|
|
|
|
|
|
|
collector.Empty();
|
|
|
|
|
|
|
|
for( int j = 0; j < segments; ++j )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2017-07-19 13:58:53 +00:00
|
|
|
wxPoint testpoint( cursorPos.x - j * line_step.x,
|
|
|
|
cursorPos.y - j * line_step.y );
|
|
|
|
collector.Collect( board(), types, testpoint, guide );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2015-02-21 20:16:28 +00:00
|
|
|
for( int i = 0; i < collector.GetCount(); ++i )
|
|
|
|
{
|
2017-07-19 13:58:53 +00:00
|
|
|
selectedPads.push_back( static_cast<D_PAD*>( collector[i] ) );
|
2015-02-21 20:16:28 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-07-19 13:58:53 +00:00
|
|
|
selectedPads.unique();
|
2015-02-21 20:16:28 +00:00
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( D_PAD* pad : selectedPads )
|
2015-02-21 20:16:28 +00:00
|
|
|
{
|
2017-03-02 11:34:19 +00:00
|
|
|
// If pad was not selected, then enumerate it
|
|
|
|
if( !pad->IsSelected() )
|
2015-02-21 20:16:28 +00:00
|
|
|
{
|
2017-03-02 11:34:19 +00:00
|
|
|
commit.Modify( pad );
|
|
|
|
|
|
|
|
// Rename pad and store the old name
|
2019-01-17 13:55:50 +00:00
|
|
|
int newval;
|
|
|
|
|
|
|
|
if( storedPadNumbers.size() > 0 )
|
|
|
|
{
|
|
|
|
newval = storedPadNumbers.front();
|
|
|
|
storedPadNumbers.pop_front();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
newval = seqPadNum++;
|
|
|
|
|
|
|
|
wxString newName = wxString::Format( wxT( "%s%d" ), padPrefix.c_str(), newval );
|
|
|
|
oldNames[newName] = { newval, pad->GetName() };
|
2017-08-11 09:22:13 +00:00
|
|
|
pad->SetName( newName );
|
2015-02-21 20:16:28 +00:00
|
|
|
pad->SetSelected();
|
2017-03-02 11:34:19 +00:00
|
|
|
getView()->Update( pad );
|
2019-01-17 13:23:03 +00:00
|
|
|
|
2019-01-17 13:55:50 +00:00
|
|
|
// Ensure the popup text shows the correct next value
|
|
|
|
if( storedPadNumbers.size() > 0 )
|
|
|
|
newval = storedPadNumbers.front();
|
|
|
|
else
|
|
|
|
newval = seqPadNum;
|
|
|
|
|
2019-01-17 13:23:03 +00:00
|
|
|
statusPopup.SetText( wxString::Format(
|
|
|
|
_( "Click on pad %s%d\nPress Escape to cancel or double-click to commit" ),
|
2019-01-17 13:55:50 +00:00
|
|
|
padPrefix.c_str(), newval ) );
|
2015-02-21 20:16:28 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 11:34:19 +00:00
|
|
|
// ..or restore the old name if it was enumerated and clicked again
|
|
|
|
else if( pad->IsSelected() && evt->IsClick( BUT_LEFT ) )
|
2015-02-21 20:16:28 +00:00
|
|
|
{
|
2017-08-11 09:22:13 +00:00
|
|
|
auto it = oldNames.find( pad->GetName() );
|
2017-03-02 11:34:19 +00:00
|
|
|
wxASSERT( it != oldNames.end() );
|
|
|
|
|
|
|
|
if( it != oldNames.end() )
|
|
|
|
{
|
2019-01-17 13:55:50 +00:00
|
|
|
storedPadNumbers.push_back( it->second.first );
|
|
|
|
pad->SetName( it->second.second );
|
2017-03-02 11:34:19 +00:00
|
|
|
oldNames.erase( it );
|
2019-01-17 13:55:50 +00:00
|
|
|
|
|
|
|
statusPopup.SetText( wxString::Format(
|
|
|
|
_( "Click on pad %s%d\nPress Escape to cancel or double-click to commit" ),
|
|
|
|
padPrefix.c_str(), storedPadNumbers.front() ) );
|
2017-03-02 11:34:19 +00:00
|
|
|
}
|
|
|
|
|
2015-02-21 20:16:28 +00:00
|
|
|
pad->ClearSelected();
|
2017-03-02 11:34:19 +00:00
|
|
|
getView()->Update( pad );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( ( evt->IsKeyPressed() && evt->KeyCode() == WXK_RETURN ) ||
|
|
|
|
evt->IsDblClick( BUT_LEFT ) )
|
|
|
|
{
|
2018-02-14 23:46:33 +00:00
|
|
|
commit.Push( _( "Renumber pads" ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-11-19 15:55:08 +00:00
|
|
|
// This is a cancel-current-action (ie: <esc>).
|
|
|
|
// Note that this must go before IsCancelInteractive() as it also checks IsCancel().
|
|
|
|
else if( evt->IsCancel() )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2018-11-19 15:55:08 +00:00
|
|
|
// Clear current selection list to avoid selection of deleted items
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
|
2017-03-02 11:34:19 +00:00
|
|
|
commit.Revert();
|
2014-07-09 13:02:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-07-19 13:58:53 +00:00
|
|
|
|
2018-11-19 15:55:08 +00:00
|
|
|
// Now that cancel-current-action has been handled, check for cancel-tool.
|
|
|
|
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
|
|
|
|
{
|
|
|
|
commit.Push( _( "Renumber pads" ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-11-19 11:25:23 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
2018-02-14 23:46:33 +00:00
|
|
|
{
|
2018-11-19 11:25:23 +00:00
|
|
|
m_menu.ShowContextMenu();
|
2018-02-14 23:46:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-19 13:58:53 +00:00
|
|
|
// Prepare the next loop by updating the old cursor mouse position
|
|
|
|
// to this last mouse cursor position
|
|
|
|
oldCursorPos = getViewControls()->GetCursorPosition();
|
2019-01-17 13:23:03 +00:00
|
|
|
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 09:06:24 +00:00
|
|
|
for( auto p : board()->m_Modules->Pads() )
|
2017-03-02 11:34:19 +00:00
|
|
|
{
|
|
|
|
p->ClearSelected();
|
|
|
|
view->Update( p );
|
|
|
|
}
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2019-01-17 13:23:03 +00:00
|
|
|
statusPopup.Hide();
|
2018-02-14 23:46:33 +00:00
|
|
|
frame()->SetNoToolSelected();
|
2017-07-19 13:58:53 +00:00
|
|
|
frame()->GetGalCanvas()->SetCursor( wxCURSOR_ARROW );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::ExplodePadToShapes( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
SELECTION& selection = m_toolMgr->GetTool<SELECTION_TOOL>()->GetSelection();
|
|
|
|
BOARD_COMMIT commit( frame() );
|
|
|
|
|
|
|
|
if( selection.Size() != 1 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( selection[0]->Type() != PCB_PAD_T )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
auto pad = static_cast<D_PAD*>( selection[0] );
|
|
|
|
|
|
|
|
if( pad->GetShape() != PAD_SHAPE_CUSTOM )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
commit.Modify( pad );
|
|
|
|
|
|
|
|
wxPoint anchor = pad->GetPosition();
|
|
|
|
|
|
|
|
for( auto prim : pad->GetPrimitives() )
|
|
|
|
{
|
|
|
|
auto ds = new EDGE_MODULE( board()->m_Modules );
|
|
|
|
|
2017-10-21 06:48:26 +00:00
|
|
|
prim.ExportTo( ds ); // ExportTo exports to a DRAWSEGMENT
|
|
|
|
// Fix an arbitray draw layer for this EDGE_MODULE
|
|
|
|
ds->SetLayer( Dwgs_User ); //pad->GetLayer() );
|
|
|
|
ds->Move( anchor );
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
commit.Add( ds );
|
|
|
|
}
|
|
|
|
|
|
|
|
pad->SetShape( pad->GetAnchorPadShape() );
|
2018-04-24 15:00:29 +00:00
|
|
|
// Cleanup the pad primitives data, because the initial pad was a custom
|
|
|
|
// shaped pad, and it contains primitives, that does not exist in non custom pads,
|
|
|
|
// and can create issues later:
|
|
|
|
if( pad->GetShape() != PAD_SHAPE_CUSTOM ) // should be always the case
|
|
|
|
{
|
|
|
|
pad->DeletePrimitivesList();
|
|
|
|
}
|
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
commit.Push( _("Explode pad to shapes") );
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MODULE_EDITOR_TOOLS::CreatePadFromShapes( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
SELECTION& selection = m_toolMgr->GetTool<SELECTION_TOOL>()->GetSelection();
|
|
|
|
|
|
|
|
std::unique_ptr<D_PAD> pad ( new D_PAD ( board()->m_Modules ) );
|
|
|
|
D_PAD *refPad = nullptr;
|
|
|
|
bool multipleRefPadsFound = false;
|
|
|
|
bool illegalItemsFound = false;
|
|
|
|
|
|
|
|
std::vector<PAD_CS_PRIMITIVE> shapes;
|
|
|
|
|
|
|
|
BOARD_COMMIT commit( frame() );
|
|
|
|
|
|
|
|
for( auto item : selection )
|
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
|
|
|
if( refPad )
|
|
|
|
multipleRefPadsFound = true;
|
|
|
|
|
|
|
|
refPad = static_cast<D_PAD*>( item );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_MODULE_EDGE_T:
|
|
|
|
{
|
|
|
|
auto em = static_cast<EDGE_MODULE*> ( item );
|
|
|
|
|
2018-07-22 15:11:16 +00:00
|
|
|
// Currently, S_CURVE shape is not supported. so warn the user
|
|
|
|
if( em->GetShape() == S_CURVE )
|
|
|
|
{
|
|
|
|
illegalItemsFound = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
PAD_CS_PRIMITIVE shape( em->GetShape() );
|
|
|
|
shape.m_Start = em->GetStart();
|
|
|
|
shape.m_End = em->GetEnd();
|
|
|
|
shape.m_Radius = em->GetRadius();
|
|
|
|
shape.m_Thickness = em->GetWidth();
|
|
|
|
shape.m_ArcAngle = em->GetAngle();
|
2018-01-24 13:22:43 +00:00
|
|
|
shape.m_Poly = em->BuildPolyPointsList();
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
shapes.push_back(shape);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
illegalItemsFound = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( refPad && selection.Size() == 1 )
|
|
|
|
{
|
|
|
|
// don't convert a pad into itself...
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( multipleRefPadsFound )
|
|
|
|
{
|
2017-10-21 06:48:26 +00:00
|
|
|
DisplayErrorMessage( frame(),
|
|
|
|
_( "Cannot convert items to a custom-shaped pad:\n"
|
|
|
|
"selection contains more than one reference pad." ) );
|
2017-10-19 21:16:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( illegalItemsFound )
|
|
|
|
{
|
2017-10-21 06:48:26 +00:00
|
|
|
DisplayErrorMessage( frame(),
|
|
|
|
_( "Cannot convert items to a custom-shaped pad:\n"
|
|
|
|
"selection contains unsupported items.\n"
|
|
|
|
"Only graphical lines, circles, arcs and polygons are allowed." ) );
|
2017-10-19 21:16:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( refPad )
|
|
|
|
{
|
|
|
|
pad.reset( static_cast<D_PAD*>( refPad->Clone() ) );
|
2018-03-05 16:51:43 +00:00
|
|
|
|
|
|
|
if( refPad->GetShape() == PAD_SHAPE_RECT )
|
|
|
|
pad->SetAnchorPadShape( PAD_SHAPE_RECT );
|
|
|
|
|
|
|
|
// ignore the pad orientation and offset for the moment. Makes more trouble than it's worth.
|
|
|
|
pad->SetOrientation( 0 );
|
|
|
|
pad->SetOffset( wxPoint( 0, 0 ) );
|
2017-10-19 21:16:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-21 06:48:26 +00:00
|
|
|
// Create a default pad anchor:
|
2017-10-19 21:16:06 +00:00
|
|
|
pad->SetAnchorPadShape( PAD_SHAPE_CIRCLE );
|
|
|
|
pad->SetAttribute( PAD_ATTRIB_SMD );
|
|
|
|
pad->SetLayerSet( D_PAD::SMDMask() );
|
2017-10-21 06:48:26 +00:00
|
|
|
int radius = Millimeter2iu( 0.2 );
|
|
|
|
pad->SetSize ( wxSize( radius, radius ) );
|
2018-03-05 16:51:43 +00:00
|
|
|
pad->SetOrientation( 0 );
|
2020-05-03 07:59:05 +00:00
|
|
|
|
|
|
|
if( PAD_NAMING::PadCanHaveName( *pad ) )
|
|
|
|
{
|
|
|
|
wxString padName = GetLastPadName();
|
|
|
|
padName = board()->m_Modules->GetNextPadName( padName );
|
|
|
|
pad->SetName( padName );
|
|
|
|
SetLastPadName( padName );
|
|
|
|
}
|
2017-10-19 21:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pad->SetShape ( PAD_SHAPE_CUSTOM );
|
|
|
|
|
2017-11-01 11:14:16 +00:00
|
|
|
OPT<VECTOR2I> anchor;
|
2017-10-19 21:16:06 +00:00
|
|
|
VECTOR2I tmp;
|
|
|
|
|
|
|
|
if( refPad )
|
|
|
|
{
|
2017-11-01 11:14:16 +00:00
|
|
|
anchor = VECTOR2I( pad->GetPosition() );
|
2017-10-19 21:16:06 +00:00
|
|
|
}
|
|
|
|
else if( pad->GetBestAnchorPosition( tmp ) )
|
|
|
|
{
|
|
|
|
anchor = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !anchor )
|
|
|
|
{
|
2017-10-21 06:48:26 +00:00
|
|
|
DisplayErrorMessage( frame(),
|
|
|
|
_( "Cannot convert items to a custom-shaped pad:\n"
|
|
|
|
"unable to determine the anchor point position.\n"
|
|
|
|
"Consider adding a small anchor pad to the selection and try again.") );
|
2017-10-19 21:16:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// relocate the shapes, they are relative to the anchor pad position
|
|
|
|
for( auto& shape : shapes )
|
|
|
|
{
|
2017-10-21 09:00:59 +00:00
|
|
|
shape.Move( wxPoint( -anchor->x, -anchor->y ) );
|
2017-10-19 21:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pad->SetPosition( wxPoint( anchor->x, anchor->y ) );
|
2018-03-06 13:58:25 +00:00
|
|
|
pad->AddPrimitives( shapes );
|
|
|
|
pad->ClearFlags();
|
2018-04-24 15:00:29 +00:00
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
bool result = pad->MergePrimitivesAsPolygon();
|
|
|
|
|
|
|
|
if( !result )
|
|
|
|
{
|
2017-10-21 09:00:59 +00:00
|
|
|
DisplayErrorMessage( frame(),
|
|
|
|
_( "Cannot convert items to a custom-shaped pad:\n"
|
|
|
|
"selected items do not form a single solid shape.") );
|
2017-10-19 21:16:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto padPtr = pad.release();
|
|
|
|
|
|
|
|
commit.Add( padPtr );
|
|
|
|
for ( auto item : selection )
|
|
|
|
{
|
|
|
|
commit.Remove( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2017-10-21 09:00:59 +00:00
|
|
|
commit.Push(_("Create Pad from Selected Shapes") );
|
2018-03-06 13:58:25 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, padPtr );
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-07-09 13:10:32 +00:00
|
|
|
|
2017-07-31 12:30:51 +00:00
|
|
|
void MODULE_EDITOR_TOOLS::setTransitions()
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2017-02-21 12:42:08 +00:00
|
|
|
Go( &MODULE_EDITOR_TOOLS::PlacePad, PCB_ACTIONS::placePad.MakeEvent() );
|
2017-10-19 21:16:06 +00:00
|
|
|
Go( &MODULE_EDITOR_TOOLS::CreatePadFromShapes, PCB_ACTIONS::createPadFromShapes.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::ExplodePadToShapes, PCB_ACTIONS::explodePadToShapes.MakeEvent() );
|
2017-02-21 12:42:08 +00:00
|
|
|
Go( &MODULE_EDITOR_TOOLS::EnumeratePads, PCB_ACTIONS::enumeratePads.MakeEvent() );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|