Fixed menu items, moved the copy and cut to the EDIT_TOOL, Fixed rendering when copying a module

This commit is contained in:
Kristoffer Ödmark 2017-09-17 19:49:06 +02:00 committed by Tomasz Włostowski
parent 7ff096fbac
commit b4879d061c
7 changed files with 82 additions and 43 deletions

View File

@ -55,6 +55,8 @@ using namespace std::placeholders;
#include "selection_tool.h"
#include "edit_tool.h"
#include "grid_helper.h"
#include "kicad_clipboard.h"
#include "pcbnew_control.h"
#include <router/router_tool.h>
@ -161,6 +163,17 @@ TOOL_ACTION PCB_ACTIONS::measureTool( "pcbnew.InteractiveEdit.measureTool",
_( "Measuring tool" ), _( "Interactively measure distance between points" ),
nullptr, AF_ACTIVATE );
TOOL_ACTION PCB_ACTIONS::copyToClipboard( "pcbnew.InteractiveEdit.CopyToClipboard",
AS_GLOBAL, MD_CTRL + int( 'C' ),
_( "Copy to Clipboard" ), _( "Copy selected content to clipboard" ),
copy_xpm );
TOOL_ACTION PCB_ACTIONS::cutToClipboard( "pcbnew.InteractiveEdit.CutToClipboard",
AS_GLOBAL, MD_CTRL + int( 'X' ),
_( "Cut to Clipboard" ), _( "Cut selected content to clipboard" ),
cut_xpm );
static wxPoint getAnchorPoint( const SELECTION &selection, const MOVE_PARAMETERS &params )
{
wxPoint anchorPoint;
@ -235,8 +248,6 @@ static wxPoint getAnchorPoint( const SELECTION &selection, const MOVE_PARAMETERS
}
EDIT_TOOL::EDIT_TOOL() :
PCB_TOOL( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ),
m_dragging( false )
@ -289,6 +300,12 @@ bool EDIT_TOOL::Init()
menu.AddItem( PCB_ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( PCB_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty );
menu.AddSeparator();
menu.AddItem( PCB_ACTIONS::copyToClipboard, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( PCB_ACTIONS::cutToClipboard, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( PCB_ACTIONS::pasteFromClipboard );
menu.AddSeparator();
// Mirror only available in modedit
menu.AddItem( PCB_ACTIONS::mirror, editingModuleCondition && SELECTION_CONDITIONS::NotEmpty );
@ -1211,6 +1228,10 @@ void EDIT_TOOL::setTransitions()
Go( &EDIT_TOOL::editFootprintInFpEditor, PCB_ACTIONS::editFootprintInFpEditor.MakeEvent() );
Go( &EDIT_TOOL::ExchangeFootprints, PCB_ACTIONS::exchangeFootprints.MakeEvent() );
Go( &EDIT_TOOL::MeasureTool, PCB_ACTIONS::measureTool.MakeEvent() );
Go( &EDIT_TOOL::copyToClipboard, PCB_ACTIONS::copyToClipboard.MakeEvent() );
Go( &EDIT_TOOL::cutToClipboard, PCB_ACTIONS::cutToClipboard.MakeEvent() );
}
@ -1268,6 +1289,25 @@ int EDIT_TOOL::editFootprintInFpEditor( const TOOL_EVENT& aEvent )
return 0;
}
int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent )
{
CLIPBOARD_IO io;
BOARD* board = getModel<BOARD>();
io.setBoard( board );
auto& selection = m_selectionTool->RequestSelection();
io.SaveSelection( selection );
return 0;
}
int EDIT_TOOL::cutToClipboard( const TOOL_EVENT& aEvent )
{
copyToClipboard( aEvent );
Remove( aEvent );
return 0;
}
template<class T>
T* EDIT_TOOL::uniqueSelected()

View File

@ -139,6 +139,22 @@ public:
///> Sets up handlers for various events.
void setTransitions() override;
/**
* Function copyToClipboard()
* Sends the current selection to the clipboard by formatting it as a fake pcb
* see AppendBoardFromClipboard for importing
* @return True if it was sent succesfully
*/
int copyToClipboard( const TOOL_EVENT& aEvent );
/**
* Function cutToClipboard()
* Sends the current selection to the clipboard by formatting it as a fake pcb
* see AppendBoardFromClipboard for importing
* @return True if it was sent succesfully
*/
int cutToClipboard( const TOOL_EVENT& aEvent );
private:
///> Selection tool used for obtaining selected items
SELECTION_TOOL* m_selectionTool;

View File

@ -82,8 +82,6 @@ public:
/// Filters the items in the current selection (invokes dialog)
static TOOL_ACTION filterSelection;
/// Copy selected items to clipboard
static TOOL_ACTION selectionToClipboard;
// Edit Tool
/// Activation of the edit tool
@ -303,6 +301,15 @@ public:
/// Pasting module items from clipboard
static TOOL_ACTION pasteItems;
/// Copy selected items to clipboard
static TOOL_ACTION copyToClipboard;
/// Paste from clipboard
static TOOL_ACTION pasteFromClipboard;
/// Paste from clipboard
static TOOL_ACTION cutToClipboard;
/// Display module edges as outlines
static TOOL_ACTION moduleEdgeOutlines;
@ -368,7 +375,6 @@ public:
static TOOL_ACTION drillOrigin;
static TOOL_ACTION crossProbeSchToPcb;
static TOOL_ACTION appendBoard;
static TOOL_ACTION appendClipboard;
static TOOL_ACTION showHelp;
static TOOL_ACTION showLocalRatsnest;
static TOOL_ACTION toBeDone;

View File

@ -142,10 +142,6 @@ TOOL_ACTION PCB_ACTIONS::appendBoard( "pcbnew.EditorControl.appendBoard",
AS_GLOBAL, 0,
"", "" );
TOOL_ACTION PCB_ACTIONS::appendClipboard( "pcbnew.EditorControl.appendClipboard",
AS_GLOBAL, MD_CTRL + int( 'V' ),
"", "" );
TOOL_ACTION PCB_ACTIONS::highlightNet( "pcbnew.EditorControl.highlightNet",
AS_GLOBAL, 0,
"", "" );
@ -411,17 +407,21 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
m_frame->SetToolID( ID_PCB_MODULE_BUTT, wxCURSOR_PENCIL, _( "Add footprint" ) );
// Add all the drawable parts to preview
VECTOR2I cursorPos = controls->GetCursorPosition();
if( module )
{
module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
preview.Add( module );
module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
view->Update( &preview );
}
// Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() )
{
VECTOR2I cursorPos = controls->GetCursorPosition();
cursorPos = controls->GetCursorPosition();
if( evt->IsCancel() || evt->IsActivate() )
if( evt->IsCancel() )
{
if( module )
{

View File

@ -54,6 +54,7 @@
#include <pcb_painter.h>
#include <origin_viewitem.h>
#include <board_commit.h>
#include <bitmaps.h>
#include <functional>
using namespace std::placeholders;
@ -224,6 +225,11 @@ TOOL_ACTION PCB_ACTIONS::toBeDone( "pcbnew.Control.toBeDone",
AS_GLOBAL, 0, // dialog saying it is not implemented yet
"", "" ); // so users are aware of that
TOOL_ACTION PCB_ACTIONS::pasteFromClipboard( "pcbnew.InteractiveEdit.pasteFromClipboard",
AS_GLOBAL, MD_CTRL + int( 'V' ),
_( "Paste from Clipboard" ), _( "Paste content from clipboard" ),
paste_xpm );
PCBNEW_CONTROL::PCBNEW_CONTROL() :
TOOL_INTERACTIVE( "pcbnew.Control" ), m_frame( NULL )
@ -763,7 +769,7 @@ int PCBNEW_CONTROL::AppendBoardFromClipboard( const TOOL_EVENT& aEvent )
}
break;
case PCB_MODULE_T:
clipItem->SetParent( board );
if(frame->IsType( FRAME_PCB) )
{
m_toolMgr->RunAction( "pcbnew.EditorControl.placeModule", true,
@ -1019,8 +1025,9 @@ void PCBNEW_CONTROL::setTransitions()
// Append control
Go( &PCBNEW_CONTROL::AppendBoardFromFile,
PCB_ACTIONS::appendBoard.MakeEvent() );
Go( &PCBNEW_CONTROL::AppendBoardFromClipboard,
PCB_ACTIONS::appendClipboard.MakeEvent() );
PCB_ACTIONS::pasteFromClipboard.MakeEvent() );
}

View File

@ -59,7 +59,6 @@ using namespace std::placeholders;
#include "pcb_actions.h"
#include "kicad_plugin.h"
#include "kicad_clipboard.h"
// Selection tool actions
TOOL_ACTION PCB_ACTIONS::selectionActivate( "pcbnew.InteractiveSelection",
@ -123,13 +122,6 @@ TOOL_ACTION PCB_ACTIONS::filterSelection( "pcbnew.InteractiveSelection.FilterSel
_( "Filter Selection" ), _( "Filter the types of items in the selection" ),
nullptr );
TOOL_ACTION PCB_ACTIONS::selectionToClipboard( "pcbnew.InteractiveSelection.CopyToClipboard",
AS_GLOBAL, MD_CTRL + int( 'C' ),
_( "Copy to Clipboard" ), _( "Copy selected content to clipboard" ),
nullptr );
class SELECT_MENU: public CONTEXT_MENU
{
public:
@ -618,25 +610,11 @@ void SELECTION_TOOL::setTransitions()
Go( &SELECTION_TOOL::selectNet, PCB_ACTIONS::selectNet.MakeEvent() );
Go( &SELECTION_TOOL::selectSameSheet, PCB_ACTIONS::selectSameSheet.MakeEvent() );
Go( &SELECTION_TOOL::selectionToClipboard, PCB_ACTIONS::selectionToClipboard.MakeEvent() );
Go( &SELECTION_TOOL::selectOnSheetFromEeschema, PCB_ACTIONS::selectOnSheetFromEeschema.MakeEvent() );
Go( &SELECTION_TOOL::updateSelection, PCB_ACTIONS::selectionModified.MakeEvent() );
}
int SELECTION_TOOL::selectionToClipboard( const TOOL_EVENT& aEvent )
{
CLIPBOARD_IO io;
BOARD* board = getModel<BOARD>();
io.setBoard( board );
//auto& selection = RequestSelection( SELECTION_DELETABLE | SELECTION_SANITIZE_PADS );
auto& selection = GetSelection();
io.SaveSelection( selection );
return 0;
}
SELECTION_LOCK_FLAGS SELECTION_TOOL::CheckLock()
{

View File

@ -299,14 +299,6 @@ private:
*/
void unselectVisually( BOARD_ITEM* aItem );
/**
* Function selectionToClipboard()
* Sends the current selection to the clipboard by formatting it as a fake pcb
* see AppendBoardFromClipboard for importing
* @return True if it was sent succesfully
*/
int selectionToClipboard( const TOOL_EVENT& aEvent );
/**
* Function selectionContains()
* Checks if the given point is placed within any of selected items' bounding box.