diff --git a/pcbnew/autorouter/spread_footprints.cpp b/pcbnew/autorouter/spread_footprints.cpp index afae24c0d7..c2ace653fb 100644 --- a/pcbnew/autorouter/spread_footprints.cpp +++ b/pcbnew/autorouter/spread_footprints.cpp @@ -1,11 +1,11 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr + * Copyright (C) 2019 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2013 Wayne Stambaugh * - * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.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 @@ -166,49 +166,28 @@ 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. - * Footprints are grouped by sheet. - * Components with the LOCKED status set are not moved + +/** + * Footprints (after loaded by reading a netlist for instance) are moved + * to be in a small free area (outside the current board) without overlapping. + * @param aBoard is the board to edit. + * @param aFootprints: a list of footprints to be spread out. + * @param aSpreadAreaPosition the position of the upper left corner of the + * area allowed to spread footprints */ -void PCB_EDIT_FRAME::SpreadFootprints( std::vector* aFootprints, - bool aMoveFootprintsOutsideBoardOnly, - bool aCheckForBoardEdges, - wxPoint aSpreadAreaPosition, - bool aPrepareUndoCommand ) +void SpreadFootprints( std::vector* aFootprints, + wxPoint aSpreadAreaPosition ) { - EDA_RECT bbox = GetBoard()->GetBoardEdgesBoundingBox(); - bool edgesExist = bbox.GetWidth() || bbox.GetHeight(); - // if aFootprintsOutsideBoardOnly is true, and if board outline exists, - // we have to filter footprints to move: - bool outsideBrdFilter = aMoveFootprintsOutsideBoardOnly && edgesExist; - - // no edges exist - if( aMoveFootprintsOutsideBoardOnly && !edgesExist ) - { - DisplayError( this, - _( "Could not automatically place footprints. No board outlines detected." ) ); - return; - } - - // Build candidate list // calculate also the area needed by these footprints std::vector footprintList; for( MODULE* footprint : *aFootprints ) { - footprint->CalculateBoundingBox(); - - if( outsideBrdFilter ) - { - if( bbox.Contains( footprint->GetPosition() ) ) - continue; - } - if( footprint->IsLocked() ) continue; + footprint->CalculateBoundingBox(); footprintList.push_back( footprint ); } @@ -218,55 +197,16 @@ void PCB_EDIT_FRAME::SpreadFootprints( std::vector* aFootprints, // sort footprints by sheet path. we group them later by sheet sort( footprintList.begin(), footprintList.end(), sortFootprintsbySheetPath ); - // 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; - - if( aPrepareUndoCommand ) - { - 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 std::vector footprintListBySheet; std::vector placementSheetAreas; double subsurface; double placementsurface = 0.0; - // put the placement area position on mouse cursor. - // this position will be adjusted later - wxPoint placementAreaPosition = aSpreadAreaPosition; - - // We sometimes do not want to move footprints inside an existing board. - // Therefore, move the placement area position outside the board bounding box - // to the left of the board - if( aCheckForBoardEdges && edgesExist ) - { - if( placementAreaPosition.x < bbox.GetEnd().x && - placementAreaPosition.y < bbox.GetEnd().y ) - { - // the placement area could overlap the board - // move its position to a safe location - placementAreaPosition.x = bbox.GetEnd().x; - placementAreaPosition.y = bbox.GetOrigin().y; - } - } - // The placement uses 2 passes: // the first pass creates the rectangular areas to place footprints // each sheet in schematic creates one rectangular area. // the second pass moves footprints inside these areas - MODULE* footprint; for( int pass = 0; pass < 2; pass++ ) { int subareaIdx = 0; @@ -275,7 +215,7 @@ void PCB_EDIT_FRAME::SpreadFootprints( std::vector* aFootprints, for( unsigned ii = 0; ii < footprintList.size(); ii++ ) { - footprint = footprintList[ii]; + MODULE* footprint = footprintList[ii]; bool islastItem = false; if( ii == footprintList.size() - 1 || @@ -301,7 +241,7 @@ void PCB_EDIT_FRAME::SpreadFootprints( std::vector* aFootprints, if( pass == 1 ) { wxPoint areapos = placementSheetAreas[subareaIdx].GetOrigin() - + placementAreaPosition; + + aSpreadAreaPosition; freeArea.SetOrigin( areapos ); } @@ -354,14 +294,6 @@ void PCB_EDIT_FRAME::SpreadFootprints( std::vector* aFootprints, } } } // End pass - - // Undo: commit list - if( aPrepareUndoCommand ) - SaveCopyInUndoList( undoList, UR_CHANGED ); - - OnModify(); - - GetCanvas()->Refresh(); } diff --git a/pcbnew/netlist.cpp b/pcbnew/netlist.cpp index db9d6e58db..4814f06db4 100644 --- a/pcbnew/netlist.cpp +++ b/pcbnew/netlist.cpp @@ -53,6 +53,9 @@ using namespace std::placeholders; #include #include +extern void SpreadFootprints( std::vector* aFootprints, + wxPoint aSpreadAreaPosition ); + bool PCB_EDIT_FRAME::ReadNetlistFromFile( const wxString &aFilename, NETLIST& aNetlist, @@ -108,7 +111,7 @@ void PCB_EDIT_FRAME::OnNetlistChanged( BOARD_NETLIST_UPDATER& aUpdater, bool* aR GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true ); - SpreadFootprints( &newFootprints, false, false, areaPosition, false ); + SpreadFootprints( &newFootprints, areaPosition ); // Start drag command for new modules if( !newFootprints.empty() ) diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index d00fa50330..e62ec04362 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -944,30 +944,6 @@ public: void LockModule( MODULE* aModule, bool aLocked ); - /** - * Function SpreadFootprints - * Footprints (after loaded by reading a netlist for instance) are moved - * to be in a small free area (outside the current board) without overlapping. - * @param aFootprints: a list of footprints to be spread out. - * @param aMoveFootprintsOutsideBoardOnly: true to move only - * footprints outside the board outlines - * (they are outside if the position of a footprint anchor is outside - * the board outlines bounding box). It imply the board outlines exist - * @param aCheckForBoardEdges: true to try to place footprints outside of - * 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* aFootprints, - bool aMoveFootprintsOutsideBoardOnly, - bool aCheckForBoardEdges, - wxPoint aSpreadAreaPosition, - bool aPrepareUndoCommand = true ); - - /** * Function SendMessageToEESCHEMA * sends a message to the schematic editor so that it may move its cursor