Pcbnew: when update PCB from schematic, spread footprints also in legacy mode. Remove also one useless undo command level after update.

This commit is contained in:
jean-pierre charras 2016-10-25 15:34:59 +02:00
parent 4ee344e150
commit 89f9b7df5c
9 changed files with 84 additions and 34 deletions

View File

@ -1562,11 +1562,15 @@ public:
* board edges, if aSpreadAreaPosition is incorrectly chosen.
* @param aSpreadAreaPosition the position of the upper left corner of the
* area used to spread footprints
* @param aPrepareUndoCommand = true (defualt) to commit a undo command for the
* spread footprints, false to do just the spread command
* (no undo specific to this move command)
*/
void SpreadFootprints( std::vector<MODULE*>* aFootprints,
bool aMoveFootprintsOutsideBoardOnly,
bool aCheckForBoardEdges,
wxPoint aSpreadAreaPosition );
wxPoint aSpreadAreaPosition,
bool aPrepareUndoCommand = true );
/**
* Function AutoPlaceModule

View File

@ -167,13 +167,15 @@ void moveFootprintsInArea( CRectPlacement& aPlacementArea,
static bool sortFootprintsbySheetPath( MODULE* ref, MODULE* compare );
/* Function to move components in a rectangular area format 4 / 3,
* starting from the mouse cursor
* The components with the FIXED status set are not moved
* starting from the mouse cursor.
* Footprints are grouped by sheet.
* Components with the LOCKED status set are not moved
*/
void PCB_EDIT_FRAME::SpreadFootprints( std::vector<MODULE*>* aFootprints,
bool aMoveFootprintsOutsideBoardOnly,
bool aCheckForBoardEdges,
wxPoint aSpreadAreaPosition )
wxPoint aSpreadAreaPosition,
bool aPrepareUndoCommand )
{
EDA_RECT bbox = GetBoard()->ComputeBoundingBox( true );
bool edgesExist = bbox.GetWidth() || bbox.GetHeight();
@ -216,17 +218,23 @@ void PCB_EDIT_FRAME::SpreadFootprints( std::vector<MODULE*>* aFootprints,
// sort footprints by sheet path. we group them later by sheet
sort( footprintList.begin(), footprintList.end(), sortFootprintsbySheetPath );
// Undo command: init undo list
// Undo command: init undo list. If aPrepareUndoCommand == false
// no undo command will be initialized.
// Useful when a undo command is already initialized by the caller
PICKED_ITEMS_LIST undoList;
undoList.m_Status = UR_CHANGED;
ITEM_PICKER picker( NULL, UR_CHANGED );
for( MODULE* footprint : footprintList )
if( aPrepareUndoCommand )
{
// Undo: add copy of the footprint to undo list
picker.SetItem( footprint );
picker.SetLink( footprint->Clone() );
undoList.PushItem( picker );
undoList.m_Status = UR_CHANGED;
ITEM_PICKER picker( NULL, UR_CHANGED );
for( MODULE* footprint : footprintList )
{
// Undo: add copy of the footprint to undo list
picker.SetItem( footprint );
picker.SetLink( footprint->Clone() );
undoList.PushItem( picker );
}
}
// Extract and place footprints by sheet
@ -348,7 +356,9 @@ void PCB_EDIT_FRAME::SpreadFootprints( std::vector<MODULE*>* aFootprints,
} // End pass
// Undo: commit list
SaveCopyInUndoList( undoList, UR_CHANGED );
if( aPrepareUndoCommand )
SaveCopyInUndoList( undoList, UR_CHANGED );
OnModify();
m_canvas->Refresh();

View File

@ -250,7 +250,8 @@ void PCB_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
{
NETLIST netlist;
try {
try
{
STRING_LINE_READER* lineReader = new STRING_LINE_READER( payload, _( "EEschema netlist" ) );
KICAD_NETLIST_READER netlistReader( lineReader, &netlist );
netlistReader.LoadNetlist();

View File

@ -1,3 +1,30 @@
/**
* @file pcbnew/dialogs/dialog_update_pcb.cpp
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
*
* 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
*/
#include <common.h>
#include <wxPcbStruct.h>
#include <pcb_netlist.h>
@ -7,6 +34,7 @@
#include <tool/tool_manager.h>
#include <tools/common_actions.h>
#include <class_draw_panel_gal.h>
#include <class_drawpanel.h>
#include <class_board.h>
#include <ratsnest_data.h>
@ -40,6 +68,10 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
TOOL_MANAGER* toolManager = m_frame->GetToolManager();
BOARD* board = m_frame->GetBoard();
// keep trace of the initial baord area, if we want to place new footprints
// outside the existinag board
EDA_RECT bbox = board->ComputeBoundingBox( false );
if( !aDryRun )
{
@ -81,13 +113,24 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
m_frame->SetCurItem( NULL );
m_frame->SetMsgPanel( board );
std::vector<MODULE*> newFootprints = updater.GetAddedComponents();
// Spread new footprints.
wxPoint areaPosition = m_frame->GetCrossHairPosition();
if( !m_frame->IsGalCanvasActive() )
{
// In legacy mode place area to the left side of the board.
// if the board is empty, the bbox position is (0,0)
areaPosition.x = bbox.GetEnd().x + Millimeter2iu( 10 );
areaPosition.y = bbox.GetOrigin().y;
}
m_frame->SpreadFootprints( &newFootprints, false, false, areaPosition, false );
if( m_frame->IsGalCanvasActive() )
{
std::vector<MODULE*> newFootprints = updater.GetAddedComponents();
// Place the new modules
m_frame->SpreadFootprints( &newFootprints, false, false, m_frame->GetCrossHairPosition() );
// Start move and place the new modules command
if( !newFootprints.empty() )
{
for( MODULE* footprint : newFootprints )
@ -98,6 +141,8 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
toolManager->InvokeTool( "pcbnew.InteractiveEdit" );
}
}
else // Legacy canvas
m_frame->GetCanvas()->Refresh();
m_btnPerformUpdate->Enable( false );
m_btnPerformUpdate->SetLabel( _( "Update complete" ) );
@ -112,12 +157,6 @@ void DIALOG_UPDATE_PCB::OnMatchChange( wxCommandEvent& event )
}
void DIALOG_UPDATE_PCB::OnCancelClick( wxCommandEvent& event )
{
EndModal( wxID_CANCEL );
}
void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event )
{
m_messagePanel->SetLabel( _( "Changes applied to the PCB:" ) );

View File

@ -539,7 +539,7 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">OnCancelClick</event>
<event name="OnButtonClick"></event>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>

View File

@ -5,7 +5,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -48,7 +48,6 @@ public:
private:
virtual void OnMatchChange( wxCommandEvent& event ) override;
virtual void OnCancelClick( wxCommandEvent& event ) override;
virtual void OnUpdateClick( wxCommandEvent& event ) override;
};

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 6 2014)
// C++ code generated with wxFormBuilder (version Sep 8 2016)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@ -70,7 +70,6 @@ DIALOG_UPDATE_PCB_BASE::DIALOG_UPDATE_PCB_BASE( wxWindow* parent, wxWindowID id,
// Connect Events
m_matchByReference->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_UPDATE_PCB_BASE::OnMatchChange ), NULL, this );
m_matchByTimestamp->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_UPDATE_PCB_BASE::OnMatchChange ), NULL, this );
m_btnCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_PCB_BASE::OnCancelClick ), NULL, this );
m_btnPerformUpdate->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_PCB_BASE::OnUpdateClick ), NULL, this );
}
@ -79,7 +78,6 @@ DIALOG_UPDATE_PCB_BASE::~DIALOG_UPDATE_PCB_BASE()
// Disconnect Events
m_matchByReference->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_UPDATE_PCB_BASE::OnMatchChange ), NULL, this );
m_matchByTimestamp->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_UPDATE_PCB_BASE::OnMatchChange ), NULL, this );
m_btnCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_PCB_BASE::OnCancelClick ), NULL, this );
m_btnPerformUpdate->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_PCB_BASE::OnUpdateClick ), NULL, this );
}

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 6 2014)
// C++ code generated with wxFormBuilder (version Sep 8 2016)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@ -46,7 +46,6 @@ class DIALOG_UPDATE_PCB_BASE : public DIALOG_SHIM
// Virtual event handlers, overide them in your derived class
virtual void OnMatchChange( wxCommandEvent& event ) { event.Skip(); }
virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnUpdateClick( wxCommandEvent& event ) { event.Skip(); }

View File

@ -71,7 +71,7 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName,
std::vector<MODULE*> newFootprints;
// keep trace of the initial baord area, if we want to place new footprints
// outside the existinag board
EDA_RECT bbox = GetBoard()->ComputeBoundingBox( false );
EDA_RECT bbox = board->ComputeBoundingBox( false );
netlist.SetIsDryRun( aIsDryRun );
netlist.SetFindByTimeStamp( aSelectByTimeStamp );