2014-07-09 13:02:56 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-02-21 20:16:28 +00:00
|
|
|
* Copyright (C) 2014-2015 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
|
|
|
|
*/
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
#include "module_editor_tools.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"
|
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>
|
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
|
|
|
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#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 );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::enumeratePads( "pcbnew.ModuleEditor.enumeratePads",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
_( "Enumerate Pads" ), _( "Enumerate pads" ), pad_enumerate_xpm, AF_ACTIVATE );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::copyItems( "pcbnew.ModuleEditor.copyItems",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_COPY_ITEM ),
|
|
|
|
_( "Copy" ), _( "Copy items" ), NULL, AF_ACTIVATE );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::pasteItems( "pcbnew.ModuleEditor.pasteItems",
|
|
|
|
AS_GLOBAL, MD_CTRL + int( 'V' ),
|
|
|
|
_( "Paste" ), _( "Paste items" ), NULL, AF_ACTIVATE );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::moduleEdgeOutlines( "pcbnew.ModuleEditor.graphicOutlines",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
"", "" );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::moduleTextOutlines( "pcbnew.ModuleEditor.textOutlines",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
"", "" );
|
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
MODULE_EDITOR_TOOLS::MODULE_EDITOR_TOOLS() :
|
2015-02-15 22:21:52 +00:00
|
|
|
TOOL_INTERACTIVE( "pcbnew.ModuleEditor" ), m_view( NULL ), m_controls( NULL ),
|
|
|
|
m_board( NULL ), m_frame( NULL )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2015-09-05 19:47:35 +00:00
|
|
|
// Generate an origin marker at 0,0 which is used as an axis origin marker (0,0)
|
|
|
|
m_axisOrigin = new KIGFX::ORIGIN_VIEWITEM( KIGFX::COLOR4D(0.0, 0.0, 0.8, 1.0),
|
|
|
|
KIGFX::ORIGIN_VIEWITEM::CROSS,
|
|
|
|
20000,
|
|
|
|
VECTOR2D(0,0) );
|
|
|
|
m_axisOrigin->SetDrawAtZero( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
MODULE_EDITOR_TOOLS::~MODULE_EDITOR_TOOLS()
|
2015-09-05 19:47:35 +00:00
|
|
|
{
|
|
|
|
delete m_axisOrigin;
|
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
|
|
|
{
|
|
|
|
// Init variables used by every drawing tool
|
|
|
|
m_view = getView();
|
|
|
|
m_controls = getViewControls();
|
|
|
|
m_board = getModel<BOARD>();
|
|
|
|
m_frame = getEditFrame<PCB_EDIT_FRAME>();
|
2015-09-05 19:47:35 +00:00
|
|
|
|
|
|
|
if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH )
|
|
|
|
{
|
|
|
|
// Draw the axis origin if we're editing modules (essentially in the footprint editor)
|
|
|
|
m_view->Remove( m_axisOrigin );
|
|
|
|
m_view->Add( m_axisOrigin );
|
|
|
|
}
|
2014-07-09 13:02:56 +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
|
|
|
{
|
|
|
|
m_frame->SetToolID( ID_MODEDIT_PAD_TOOL, wxCURSOR_PENCIL, _( "Add pads" ) );
|
|
|
|
|
2015-12-15 12:39:53 +00:00
|
|
|
assert( m_board->m_Modules );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2015-12-15 12:39:53 +00:00
|
|
|
D_PAD* pad = new D_PAD( m_board->m_Modules );
|
2014-07-09 13:02:56 +00:00
|
|
|
m_frame->Import_Pad_Settings( pad, false ); // use the global settings for pad
|
|
|
|
|
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
|
|
|
pad->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
|
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
|
|
|
KIGFX::VIEW_GROUP preview( m_view );
|
|
|
|
preview.Add( pad );
|
|
|
|
m_view->Add( &preview );
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2014-07-09 13:02:56 +00:00
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->SetSnapping( true );
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
|
|
|
cursorPos = m_controls->GetCursorPosition();
|
|
|
|
|
|
|
|
if( evt->IsMotion() )
|
|
|
|
{
|
|
|
|
pad->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
2016-12-02 17:58:12 +00:00
|
|
|
m_view->Update( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->Category() == TC_COMMAND )
|
|
|
|
{
|
2017-02-04 05:09:50 +00:00
|
|
|
if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2017-02-04 05:09:50 +00:00
|
|
|
const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle(
|
|
|
|
*m_frame, *evt );
|
|
|
|
pad->Rotate( pad->GetPosition(), rotationAngle );
|
2016-12-02 17:58:12 +00:00
|
|
|
m_view->Update( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::flip ) )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
|
|
|
pad->Flip( pad->GetPosition() );
|
2016-12-02 17:58:12 +00:00
|
|
|
m_view->Update( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsCancel() || evt->IsActivate() )
|
|
|
|
{
|
|
|
|
preview.Clear();
|
|
|
|
delete pad;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
commit.Add( pad );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
m_board->m_Status_Pcb = 0; // I have no clue why, but it is done in the legacy view
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
// Take the next available pad number
|
|
|
|
pad->IncrementPadName( true, true );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
// Handle the view aspect
|
|
|
|
preview.Remove( pad );
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Push( _( "Add a pad" ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
// Start placing next pad
|
2015-12-15 12:39:53 +00:00
|
|
|
pad = new D_PAD( m_board->m_Modules );
|
2014-07-09 13:02:56 +00:00
|
|
|
m_frame->Import_Pad_Settings( pad, false );
|
2014-07-09 14:50:31 +00:00
|
|
|
pad->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
preview.Add( pad );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_controls->ShowCursor( false );
|
|
|
|
m_controls->SetSnapping( false );
|
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_view->Remove( &preview );
|
|
|
|
|
|
|
|
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2015-12-15 12:39:53 +00:00
|
|
|
if( !m_board->m_Modules || !m_board->m_Modules->Pads() )
|
2015-08-25 08:22:52 +00:00
|
|
|
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 };
|
|
|
|
|
|
|
|
GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide();
|
|
|
|
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 );
|
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
DIALOG_ENUM_PADS settingsDlg( m_frame );
|
|
|
|
|
|
|
|
if( settingsDlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int padNumber = settingsDlg.GetStartNumber();
|
|
|
|
wxString padPrefix = settingsDlg.GetPrefix();
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
m_frame->DisplayToolMsg( _( "Hold left mouse button and move cursor over pads to enumerate them" ) );
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2014-07-09 13:02:56 +00:00
|
|
|
m_controls->ShowCursor( true );
|
2017-03-02 11:34:19 +00:00
|
|
|
|
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
2015-02-21 20:16:28 +00:00
|
|
|
VECTOR2I oldCursorPos = m_controls->GetCursorPosition();
|
|
|
|
std::list<D_PAD*> selectedPads;
|
2017-03-02 11:34:19 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
std::map<wxString, wxString> oldNames;
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
|
|
|
if( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
2015-02-21 20:16:28 +00:00
|
|
|
selectedPads.clear();
|
2014-07-09 13:02:56 +00:00
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
|
|
|
|
2015-02-21 20:16:28 +00:00
|
|
|
if( evt->IsClick( BUT_LEFT ) )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2015-02-21 20:16:28 +00:00
|
|
|
oldCursorPos = m_controls->GetCursorPosition();
|
|
|
|
collector.Empty();
|
|
|
|
collector.Collect( m_board, types, wxPoint( cursorPos.x, cursorPos.y ), 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 )
|
|
|
|
{
|
|
|
|
if( collector[i]->Type() == PCB_PAD_T )
|
|
|
|
selectedPads.push_back( static_cast<D_PAD*>( collector[i] ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //evt->IsDrag( BUT_LEFT )
|
|
|
|
{
|
|
|
|
// 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 select items intersecting with the line.
|
|
|
|
int distance = ( cursorPos - oldCursorPos ).EuclideanNorm();
|
|
|
|
int segments = distance / 100000 + 1;
|
|
|
|
const wxPoint LINE_STEP( ( cursorPos - oldCursorPos ).x / segments,
|
|
|
|
( cursorPos - oldCursorPos ).y / segments );
|
|
|
|
|
|
|
|
collector.Empty();
|
|
|
|
for( int j = 0; j < segments; ++j ) {
|
|
|
|
collector.Collect( m_board, types,
|
|
|
|
wxPoint( oldCursorPos.x, oldCursorPos.y ) + j * LINE_STEP,
|
|
|
|
guide );
|
|
|
|
|
|
|
|
for( int i = 0; i < collector.GetCount(); ++i )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2015-02-21 20:16:28 +00:00
|
|
|
if( collector[i]->Type() == PCB_PAD_T )
|
|
|
|
selectedPads.push_back( static_cast<D_PAD*>( collector[i] ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
2015-02-21 20:16:28 +00:00
|
|
|
}
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2015-02-21 20:16:28 +00:00
|
|
|
selectedPads.unique();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
wxString newName = wxString::Format( wxT( "%s%d" ), padPrefix.c_str(), padNumber++ );
|
|
|
|
oldNames[newName] = pad->GetPadName();
|
|
|
|
pad->SetPadName( newName );
|
2015-02-21 20:16:28 +00:00
|
|
|
pad->SetSelected();
|
2017-03-02 11:34:19 +00:00
|
|
|
getView()->Update( pad );
|
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-03-02 11:34:19 +00:00
|
|
|
auto it = oldNames.find( pad->GetPadName() );
|
|
|
|
wxASSERT( it != oldNames.end() );
|
|
|
|
|
|
|
|
if( it != oldNames.end() )
|
|
|
|
{
|
|
|
|
pad->SetPadName( it->second );
|
|
|
|
oldNames.erase( it );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2015-02-21 20:16:28 +00:00
|
|
|
|
|
|
|
oldCursorPos = cursorPos;
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( ( evt->IsKeyPressed() && evt->KeyCode() == WXK_RETURN ) ||
|
|
|
|
evt->IsDblClick( BUT_LEFT ) )
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Push( _( "Enumerate pads" ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsCancel() || evt->IsActivate() )
|
|
|
|
{
|
2017-03-02 11:34:19 +00:00
|
|
|
commit.Revert();
|
2014-07-09 13:02:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-02 11:34:19 +00:00
|
|
|
for( D_PAD* p = m_board->m_Modules->Pads(); p; p = p->Next() )
|
|
|
|
{
|
|
|
|
p->ClearSelected();
|
|
|
|
view->Update( p );
|
|
|
|
}
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
m_frame->DisplayToolMsg( wxEmptyString );
|
|
|
|
m_controls->ShowCursor( false );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::CopyItems( const TOOL_EVENT& aEvent )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2014-07-09 13:10:32 +00:00
|
|
|
const SELECTION& selection = m_toolMgr->GetTool<SELECTION_TOOL>()->GetSelection();
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
m_controls->SetSnapping( true );
|
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->SetAutoPan( true );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
m_frame->DisplayToolMsg( _( "Select reference point" ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
bool cancelled = false;
|
2014-07-09 13:02:56 +00:00
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
|
|
|
if( evt->IsMotion() )
|
|
|
|
{
|
2014-07-09 13:02:56 +00:00
|
|
|
cursorPos = m_controls->GetCursorPosition();
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsCancel() || evt->IsActivate() )
|
|
|
|
{
|
|
|
|
cancelled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !cancelled )
|
|
|
|
{
|
|
|
|
PCB_IO io( CTL_FOR_CLIPBOARD );
|
|
|
|
|
|
|
|
// Create a temporary module that contains selected items to ease serialization
|
2014-07-09 13:02:56 +00:00
|
|
|
MODULE module( m_board );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : selection )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2016-12-09 11:04:32 +00:00
|
|
|
auto clone = static_cast<BOARD_ITEM*>( item->Clone() );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
// Do not add reference/value - convert them to the common type
|
|
|
|
if( TEXTE_MODULE* text = dyn_cast<TEXTE_MODULE*>( clone ) )
|
|
|
|
text->SetType( TEXTE_MODULE::TEXT_is_DIVERS );
|
|
|
|
|
|
|
|
module.Add( clone );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the new relative internal local coordinates of copied items
|
2014-07-09 13:02:56 +00:00
|
|
|
MODULE* editedModule = m_board->m_Modules;
|
2014-07-09 13:02:56 +00:00
|
|
|
wxPoint moveVector = module.GetPosition() + editedModule->GetPosition() -
|
|
|
|
wxPoint( cursorPos.x, cursorPos.y );
|
|
|
|
module.MoveAnchorPosition( moveVector );
|
|
|
|
|
|
|
|
io.Format( &module, 0 );
|
|
|
|
std::string data = io.GetStringOutput( true );
|
|
|
|
m_toolMgr->SaveClipboard( data );
|
|
|
|
}
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
m_frame->DisplayToolMsg( wxString::Format( _( "Copied %d item(s)" ), selection.Size() ) );
|
|
|
|
m_controls->SetSnapping( false );
|
|
|
|
m_controls->ShowCursor( false );
|
|
|
|
m_controls->SetAutoPan( false );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::PasteItems( const TOOL_EVENT& aEvent )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
|
|
|
// Parse clipboard
|
|
|
|
PCB_IO io( CTL_FOR_CLIPBOARD );
|
|
|
|
MODULE* pastedModule = NULL;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = io.Parse( wxString( m_toolMgr->GetClipboard().c_str(), wxConvUTF8 ) );
|
|
|
|
assert( item->Type() == PCB_MODULE_T );
|
|
|
|
pastedModule = dyn_cast<MODULE*>( item );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
m_frame->DisplayToolMsg( _( "Invalid clipboard contents" ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Placement tool part
|
2014-07-09 13:02:56 +00:00
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
2014-07-09 13:02:56 +00:00
|
|
|
KIGFX::VIEW_GROUP preview( m_view );
|
|
|
|
pastedModule->SetParent( m_board );
|
2014-07-09 13:02:56 +00:00
|
|
|
pastedModule->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
2016-11-04 21:29:47 +00:00
|
|
|
pastedModule->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add,
|
2016-06-29 10:23:11 +00:00
|
|
|
std::ref( preview ), _1 ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
preview.Add( pastedModule );
|
2014-07-09 13:02:56 +00:00
|
|
|
m_view->Add( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2014-07-09 13:02:56 +00:00
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->SetSnapping( true );
|
|
|
|
m_controls->SetAutoPan( true );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
2014-07-09 13:02:56 +00:00
|
|
|
cursorPos = m_controls->GetCursorPosition();
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
if( evt->IsMotion() )
|
|
|
|
{
|
|
|
|
pastedModule->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
2016-12-02 17:58:12 +00:00
|
|
|
m_view->Update( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->Category() == TC_COMMAND )
|
|
|
|
{
|
2017-02-04 05:09:50 +00:00
|
|
|
if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2017-02-04 05:09:50 +00:00
|
|
|
const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle(
|
|
|
|
*m_frame, *evt );
|
|
|
|
pastedModule->Rotate( pastedModule->GetPosition(), rotationAngle );
|
2016-12-02 17:58:12 +00:00
|
|
|
m_view->Update( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::flip ) )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
|
|
|
pastedModule->Flip( pastedModule->GetPosition() );
|
2016-12-02 17:58:12 +00:00
|
|
|
m_view->Update( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsCancel() || evt->IsActivate() )
|
|
|
|
{
|
|
|
|
preview.Clear();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
m_board->m_Status_Pcb = 0; // I have no clue why, but it is done in the legacy view
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
// MODULE::RunOnChildren is infeasible here: we need to create copies of items, do not
|
|
|
|
// directly modify them
|
|
|
|
|
|
|
|
for( D_PAD* pad = pastedModule->Pads(); pad; pad = pad->Next() )
|
|
|
|
{
|
|
|
|
D_PAD* clone = static_cast<D_PAD*>( pad->Clone() );
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( clone );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( BOARD_ITEM* drawing = pastedModule->GraphicalItems();
|
|
|
|
drawing; drawing = drawing->Next() )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* clone = static_cast<BOARD_ITEM*>( drawing->Clone() );
|
|
|
|
|
|
|
|
if( TEXTE_MODULE* text = dyn_cast<TEXTE_MODULE*>( clone ) )
|
|
|
|
{
|
|
|
|
// Do not add reference/value - convert them to the common type
|
|
|
|
text->SetType( TEXTE_MODULE::TEXT_is_DIVERS );
|
|
|
|
|
|
|
|
// Whyyyyyyyyyyyyyyyyyyyyyy?! All other items conform to rotation performed
|
|
|
|
// on its parent module, but texts are so independent..
|
|
|
|
text->Rotate( text->GetPosition(), pastedModule->GetOrientation() );
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( text );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( clone );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Push( _( "Paste clipboard contents" ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
preview.Clear();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pastedModule;
|
2014-07-09 13:02:56 +00:00
|
|
|
m_controls->ShowCursor( false );
|
|
|
|
m_controls->SetSnapping( false );
|
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_view->Remove( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::ModuleTextOutlines( const TOOL_EVENT& aEvent )
|
2014-07-09 13:10:32 +00:00
|
|
|
{
|
2017-01-17 12:34:56 +00:00
|
|
|
KIGFX::VIEW* view = getView();
|
2014-07-09 13:10:32 +00:00
|
|
|
KIGFX::PCB_RENDER_SETTINGS* settings =
|
2017-01-17 12:34:56 +00:00
|
|
|
static_cast<KIGFX::PCB_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() );
|
2014-07-09 13:10:32 +00:00
|
|
|
|
|
|
|
const LAYER_NUM layers[] = { ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE ),
|
|
|
|
ITEM_GAL_LAYER( MOD_TEXT_FR_VISIBLE ),
|
|
|
|
ITEM_GAL_LAYER( MOD_TEXT_INVISIBLE ),
|
|
|
|
ITEM_GAL_LAYER( MOD_REFERENCES_VISIBLE ),
|
|
|
|
ITEM_GAL_LAYER( MOD_VALUES_VISIBLE ) };
|
|
|
|
|
|
|
|
bool enable = !settings->GetSketchMode( layers[0] );
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( LAYER_NUM layer : layers )
|
2014-07-09 13:10:32 +00:00
|
|
|
settings->SetSketchMode( layer, enable );
|
|
|
|
|
|
|
|
for( MODULE* module = getModel<BOARD>()->m_Modules; module; module = module->Next() )
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item = module->GraphicalItems(); item; item = item ->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() == PCB_MODULE_TEXT_T )
|
2017-01-17 12:34:56 +00:00
|
|
|
view->Update( item, KIGFX::GEOMETRY );
|
2014-07-09 13:10:32 +00:00
|
|
|
}
|
|
|
|
|
2017-01-17 12:34:56 +00:00
|
|
|
view->Update( &module->Reference(), KIGFX::GEOMETRY );
|
|
|
|
view->Update( &module->Value(), KIGFX::GEOMETRY );
|
2014-07-09 13:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->GetGalCanvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::ModuleEdgeOutlines( const TOOL_EVENT& aEvent )
|
2014-07-09 13:10:32 +00:00
|
|
|
{
|
2017-01-17 12:34:56 +00:00
|
|
|
KIGFX::VIEW* view = getView();
|
2014-07-09 13:10:32 +00:00
|
|
|
KIGFX::PCB_RENDER_SETTINGS* settings =
|
2017-01-17 12:34:56 +00:00
|
|
|
static_cast<KIGFX::PCB_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() );
|
2014-07-09 13:10:32 +00:00
|
|
|
|
2014-07-09 14:25:50 +00:00
|
|
|
const LAYER_ID layers[] = { F_Adhes, B_Adhes, F_Paste, B_Paste,
|
|
|
|
F_SilkS, B_SilkS, F_Mask, B_Mask,
|
|
|
|
Dwgs_User, Cmts_User, Eco1_User, Eco2_User, Edge_Cuts };
|
2014-07-09 13:10:32 +00:00
|
|
|
|
|
|
|
bool enable = !settings->GetSketchMode( layers[0] );
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( LAYER_NUM layer : layers )
|
2014-07-09 13:10:32 +00:00
|
|
|
settings->SetSketchMode( layer, enable );
|
|
|
|
|
|
|
|
for( MODULE* module = getModel<BOARD>()->m_Modules; module; module = module->Next() )
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item = module->GraphicalItems(); item; item = item ->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() == PCB_MODULE_EDGE_T )
|
2017-01-17 12:34:56 +00:00
|
|
|
view->Update( item, KIGFX::GEOMETRY );
|
2014-07-09 13:10:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->GetGalCanvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +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() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::EnumeratePads, PCB_ACTIONS::enumeratePads.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::CopyItems, PCB_ACTIONS::copyItems.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::PasteItems, PCB_ACTIONS::pasteItems.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::ModuleTextOutlines, PCB_ACTIONS::moduleTextOutlines.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::ModuleEdgeOutlines, PCB_ACTIONS::moduleEdgeOutlines.MakeEvent() );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|