pcbnew: code formatting, removed previous module editor copy/paste functions

This commit is contained in:
Tomasz Włostowski 2017-09-29 11:40:10 +02:00
parent adcda4a3e8
commit c6a0ad895b
17 changed files with 39 additions and 247 deletions

View File

@ -129,7 +129,7 @@ public:
* Function GetLayer
* returns the primary layer this item is on.
*/
virtual PCB_LAYER_ID GetLayer() const { return m_Layer; }
virtual PCB_LAYER_ID GetLayer() const { return m_Layer; }
/**
* Function GetLayerSet
@ -265,7 +265,6 @@ public:
Rotate( wxPoint( aRotCentre.x, aRotCentre.y ), aAngle );
}
/**
* Function Flip
* Flip this object, i.e. change the board side for this object

View File

@ -284,7 +284,7 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry )
if ( !m_editModules )
{
auto panel = static_cast<PCB_DRAW_PANEL_GAL *>( frame->GetGalCanvas() );
auto panel = static_cast<PCB_DRAW_PANEL_GAL*>( frame->GetGalCanvas() );
connectivity->RecalculateRatsnest();
panel->RedrawRatsnest();
}

View File

@ -2908,9 +2908,10 @@ void BOARD::ClearAllNetCodes()
{
for ( auto zone : Zones() )
zone->SetNetCode( 0 );
for ( auto mod : Modules() )
for ( auto pad : mod->Pads() )
pad->SetNetCode( 0 );
pad->SetNetCode( 0 );
for ( auto track : Tracks() )
track->SetNetCode( 0 );

View File

@ -1357,6 +1357,10 @@ public:
*/
TRACK* CreateLockPoint( wxPoint& aPosition, TRACK* aSegment, PICKED_ITEMS_LIST* aList );
/**
* Function ClearAllNetCodes()
* Resets all items' netcodes to 0 (no net).
*/
void ClearAllNetCodes();
};

View File

@ -748,7 +748,11 @@ void CN_CONNECTIVITY_ALGO::propagateConnections()
{
for( auto cluster : m_connClusters )
{
if( cluster->IsOrphaned() )
if( cluster->IsConflicting() )
{
wxLogTrace( "CN", "Conflicting nets in cluster %p\n", cluster.get() );
}
else if( cluster->IsOrphaned() )
{
wxLogTrace( "CN", "Skipping orphaned cluster %p [net: %s]\n", cluster.get(),
(const char*) cluster->OriginNetName().c_str() );

View File

@ -529,7 +529,6 @@ void PCB_IO::formatLayer( const BOARD_ITEM* aItem ) const
void PCB_IO::formatSetup( BOARD* aBoard, int aNestLevel ) const
{
const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
m_out->Print( 0, "\n" );
@ -1709,15 +1708,15 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const
aZone->GetIsKeepout() ? 0 : m_mapping->Translate( aZone->GetNetCode() ),
m_out->Quotew( aZone->GetIsKeepout() ? wxT("") : aZone->GetNetname() ).c_str() );
// If a zone exists on multiple layers, format accordingly
if( aZone->GetLayerSet().count() > 1 )
{
formatLayers( aZone->GetLayerSet() );
}
else
{
formatLayer( aZone );
}
// If a zone exists on multiple layers, format accordingly
if( aZone->GetLayerSet().count() > 1 )
{
formatLayers( aZone->GetLayerSet() );
}
else
{
formatLayer( aZone );
}
m_out->Print( 0, " (tstamp %lX)", (unsigned long) aZone->GetTimeStamp() );
@ -2123,7 +2122,7 @@ void PCB_IO::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootpri
if( !fn.IsOk() )
{
THROW_IO_ERROR( wxString::Format( _( "Footprint file name '%s' is not valid." ),
THROW_IO_ERROR( wxString::Format( _( "Footprint file name '%s' is not valid." ),
GetChars( fn.GetFullPath() ) ) );
}

View File

@ -326,5 +326,4 @@ public:
};
#endif // _PCBNEW_PARSER_H_

View File

@ -777,7 +777,6 @@ void PCB_EDIT_FRAME::enableGALSpecificMenus()
if( GetMenuBar()->FindItem( id_list[ii] ) )
GetMenuBar()->FindItem( id_list[ii] )->Enable( enbl );
}
}
}

View File

@ -423,7 +423,6 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
// Drag items to the current cursor position
for( auto item : selection )
static_cast<BOARD_ITEM*>( item )->Move( movement );
}
else if( !m_dragging ) // Prepare to start dragging
{
@ -1225,19 +1224,19 @@ void EDIT_TOOL::setTransitions()
Go( &EDIT_TOOL::Duplicate, PCB_ACTIONS::duplicateIncrement.MakeEvent() );
Go( &EDIT_TOOL::CreateArray,PCB_ACTIONS::createArray.MakeEvent() );
Go( &EDIT_TOOL::Mirror, PCB_ACTIONS::mirror.MakeEvent() );
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() );
Go( &EDIT_TOOL::copyToClipboard, PCB_ACTIONS::copyToClipboard.MakeEvent() );
Go( &EDIT_TOOL::cutToClipboard, PCB_ACTIONS::cutToClipboard.MakeEvent() );
}
bool EDIT_TOOL::updateModificationPoint( SELECTION& aSelection )
{
if ( aSelection.HasReferencePoint() )
if( aSelection.HasReferencePoint() )
return false;
if( aSelection.Size() == 1 )
@ -1320,7 +1319,10 @@ int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent )
Activate();
auto item1 = MSG_PANEL_ITEM( _(""), _("Select reference point for the block being copied..."), COLOR4D::BLACK );
auto item1 = MSG_PANEL_ITEM( _(""),
_("Select reference point for the block being copied..."),
COLOR4D::BLACK );
std::vector<MSG_PANEL_ITEM> msgItems = { item1 };
SELECTION selection = m_selectionTool->RequestSelection();

View File

@ -149,13 +149,12 @@ public:
/**
* Function cutToClipboard()
* Sends the current selection to the clipboard by formatting it as a fake pcb
* Cuts 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 );
BOARD_COMMIT* GetCurrentCommit() const
{
return m_commit.get();
@ -174,7 +173,6 @@ private:
///> Returns the right modification point (e.g. for rotation), depending on the number of
///> selected items.
wxPoint getModificationPoint( const SELECTION& aSelection );
bool updateModificationPoint( SELECTION& aSelection );
int editFootprintInFpEditor( const TOOL_EVENT& aEvent );

View File

@ -63,14 +63,6 @@ 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_ACTIVE, 0,
_( "Copy" ), _( "Copy items" ), NULL, AF_ACTIVATE );
TOOL_ACTION PCB_ACTIONS::pasteItems( "pcbnew.ModuleEditor.pasteItems",
AS_GLOBAL, 0,
_( "Paste" ), _( "Paste items" ), NULL, AF_ACTIVATE );
TOOL_ACTION PCB_ACTIONS::moduleEdgeOutlines( "pcbnew.ModuleEditor.graphicOutlines",
AS_GLOBAL, 0,
"", "" );
@ -265,183 +257,6 @@ int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
}
int MODULE_EDITOR_TOOLS::CopyItems( const TOOL_EVENT& aEvent )
{
const SELECTION& selection = m_toolMgr->GetTool<SELECTION_TOOL>()->GetSelection();
Activate();
getViewControls()->SetSnapping( true );
getViewControls()->ShowCursor( true );
getViewControls()->SetAutoPan( true );
frame()->DisplayToolMsg( _( "Select reference point" ) );
bool cancelled = false;
VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
while( OPT_TOOL_EVENT evt = Wait() )
{
if( evt->IsMotion() )
{
cursorPos = getViewControls()->GetCursorPosition();
}
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
MODULE module( board() );
for( auto item : selection )
{
auto clone = static_cast<BOARD_ITEM*>( item->Clone() );
// 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
MODULE* editedModule = board()->m_Modules;
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 );
}
frame()->DisplayToolMsg( wxString::Format( _( "Copied %d item(s)" ), selection.Size() ) );
return 0;
}
int MODULE_EDITOR_TOOLS::PasteItems( const TOOL_EVENT& aEvent )
{
MODULE* pastedModule = aEvent.Parameter<MODULE*>();
/* for( BOARD_ITEM* item = pastedModule->GraphicalItems().begin(); item; */
/* item = item->Next() ) */
/* { */
/* if( item->Type() == PCB_MODULE_TEXT_T ) */
/* std::cout << "Crashing on this" << std::endl; */
/* return 0; */
/* } */
// Placement tool part
VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX::VIEW_GROUP preview( view() );
pastedModule->SetParent( board() );
pastedModule->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
pastedModule->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add,
std::ref( preview ), _1 ) );
preview.Add( pastedModule );
view()->Add( &preview );
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
getViewControls()->ShowCursor( true );
getViewControls()->SetSnapping( true );
getViewControls()->SetAutoPan( true );
Activate();
// Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() )
{
cursorPos = getViewControls()->GetCursorPosition();
if( evt->IsMotion() )
{
pastedModule->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
view()->Update( &preview );
}
else if( evt->Category() == TC_COMMAND )
{
if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) )
{
const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle(
*frame(), *evt );
pastedModule->Rotate( pastedModule->GetPosition(), rotationAngle );
view()->Update( &preview );
}
else if( evt->IsAction( &PCB_ACTIONS::flip ) )
{
pastedModule->Flip( pastedModule->GetPosition() );
view()->Update( &preview );
}
else if( evt->IsCancel() || evt->IsActivate() )
{
preview.Clear();
break;
}
}
else if( evt->IsClick( BUT_LEFT ) )
{
BOARD_COMMIT commit( frame() );
board()->m_Status_Pcb = 0; // I have no clue why, but it is done in the legacy view
// MODULE::RunOnChildren is infeasible here: we need to create copies of items, do not
// directly modify them
for( auto pad : pastedModule->Pads() )
{
D_PAD* clone = static_cast<D_PAD*>( pad->Clone() );
commit.Add( clone );
}
for( auto drawing : pastedModule->GraphicalItems() )
{
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() );
}
commit.Add( clone );
}
commit.Push( _( "Paste clipboard contents" ) );
preview.Clear();
break;
}
}
delete pastedModule;
view()->Remove( &preview );
return 0;
}
int MODULE_EDITOR_TOOLS::ModuleTextOutlines( const TOOL_EVENT& aEvent )
{
KIGFX::VIEW* view = getView();
@ -511,8 +326,6 @@ void MODULE_EDITOR_TOOLS::setTransitions()
{
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() );
}

View File

@ -61,20 +61,6 @@ public:
*/
int EnumeratePads( const TOOL_EVENT& aEvent );
/**
* Function CopyItems()
*
* Copies selected items to the clipboard. Works only in "edit modules" mode.
*/
int CopyItems( const TOOL_EVENT& aEvent );
/**
* Function PastePad()
*
* Pastes items from the clipboard. Works only in "edit modules" mode.
*/
int PasteItems( const TOOL_EVENT& aEvent );
/**
* Function CreateArray
*

View File

@ -82,7 +82,6 @@ public:
/// Filters the items in the current selection (invokes dialog)
static TOOL_ACTION filterSelection;
// Edit Tool
/// Activation of the edit tool
static TOOL_ACTION editActivate;
@ -295,12 +294,6 @@ public:
/// Tool for creating an array of objects
static TOOL_ACTION createArray;
/// Copying module items to clipboard
static TOOL_ACTION copyItems;
/// Pasting module items from clipboard
static TOOL_ACTION pasteItems;
/// Copy selected items to clipboard
static TOOL_ACTION copyToClipboard;

View File

@ -126,7 +126,6 @@ protected:
BOARD* board() const { return getModel<BOARD>(); }
MODULE* module() const { return board()->m_Modules; }
bool m_editModules;
};

View File

@ -743,12 +743,12 @@ int PCBNEW_CONTROL::PasteItemsFromClipboard( const TOOL_EVENT& aEvent )
BOARD tmpBoard;
BOARD_ITEM* clipItem = pi.Parse();
if(!clipItem )
if( !clipItem )
{
return 0;
}
if ( clipItem->Type() == PCB_T )
if( clipItem->Type() == PCB_T )
static_cast<BOARD*>(clipItem)->ClearAllNetCodes();
bool editModules = m_editModules || frame()->IsType( FRAME_PCB_MODULE_EDITOR );
@ -756,7 +756,7 @@ int PCBNEW_CONTROL::PasteItemsFromClipboard( const TOOL_EVENT& aEvent )
// The clipboard can contain two different things, an entire kicad_pcb
// or a single module
if ( editModules && ( !board() || !module() ) )
if( editModules && ( !board() || !module() ) )
{
wxLogDebug( wxT( "Attempting to paste to empty module editor window\n") );
return 0;
@ -787,12 +787,12 @@ int PCBNEW_CONTROL::PasteItemsFromClipboard( const TOOL_EVENT& aEvent )
{
auto mod = static_cast<MODULE *>( clipItem );
for ( auto pad : mod->Pads() )
for( auto pad : mod->Pads() )
{
pad->SetParent ( board()->m_Modules.GetFirst() );
items.push_back( pad );
}
for ( auto item : mod->GraphicalItems() )
for( auto item : mod->GraphicalItems() )
{
item->SetParent ( board()->m_Modules.GetFirst() );
items.push_back( item );
@ -871,7 +871,7 @@ int PCBNEW_CONTROL::placeBoardItems( std::vector<BOARD_ITEM*>& aItems )
SELECTION& selection = selectionTool->GetSelection();
for ( auto item : aItems )
for( auto item : aItems )
{
item->SetSelected();
selection.Add( item );
@ -888,7 +888,6 @@ int PCBNEW_CONTROL::placeBoardItems( std::vector<BOARD_ITEM*>& aItems )
int PCBNEW_CONTROL::AppendBoard( PLUGIN& pi, wxString& fileName )
{
PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
if( !editFrame )
return 1;

View File

@ -91,7 +91,6 @@ public:
void setTransitions() override;
private:
int placeBoardItems( BOARD* aBoard );
int placeBoardItems( std::vector<BOARD_ITEM*>& aItems );

View File

@ -592,7 +592,7 @@ bool SELECTION_TOOL::selectMultiple()
m_multiple = false; // Multiple selection mode is inactive
getViewControls()->SetAutoPan( false );
if ( !cancelled )
if( !cancelled )
m_selection.ClearReferencePoint();
return cancelled;
@ -615,13 +615,11 @@ void SELECTION_TOOL::setTransitions()
Go( &SELECTION_TOOL::selectCopper, PCB_ACTIONS::selectCopper.MakeEvent() );
Go( &SELECTION_TOOL::selectNet, PCB_ACTIONS::selectNet.MakeEvent() );
Go( &SELECTION_TOOL::selectSameSheet, PCB_ACTIONS::selectSameSheet.MakeEvent() );
Go( &SELECTION_TOOL::selectOnSheetFromEeschema, PCB_ACTIONS::selectOnSheetFromEeschema.MakeEvent() );
Go( &SELECTION_TOOL::updateSelection, PCB_ACTIONS::selectionModified.MakeEvent() );
}
SELECTION_LOCK_FLAGS SELECTION_TOOL::CheckLock()
{
if( !m_locked || m_editModules )