18 changed files with 2331 additions and 1322 deletions
-
3pcbnew/CMakeLists.txt
-
1516pcbnew/autorouter/ar_autoplacer.cpp
-
118pcbnew/autorouter/ar_autoplacer.h
-
125pcbnew/autorouter/ar_cell.h
-
1367pcbnew/autorouter/ar_matrix.cpp
-
171pcbnew/autorouter/ar_matrix.h
-
124pcbnew/autorouter/autoplacer_tool.cpp
-
52pcbnew/autorouter/autoplacer_tool.h
-
49pcbnew/connectivity_data.cpp
-
5pcbnew/connectivity_data.h
-
43pcbnew/edit.cpp
-
16pcbnew/menubar_pcb_editor.cpp
-
20pcbnew/onrightclick.cpp
-
6pcbnew/pcb_edit_frame.cpp
-
27pcbnew/pcbnew_id.h
-
7pcbnew/tools/pcb_actions.cpp
-
2pcbnew/tools/pcb_actions.h
-
2pcbnew/tools/tools_common.cpp
1516
pcbnew/autorouter/ar_autoplacer.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,118 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr |
|||
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> |
|||
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net> |
|||
* |
|||
* Copyright (C) 1992-2012 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 |
|||
*/ |
|||
|
|||
|
|||
#ifndef __AR_AUTOPLACER_H |
|||
#define __AR_AUTOPLACER_H |
|||
|
|||
#include "ar_cell.h" |
|||
#include "ar_matrix.h" |
|||
|
|||
#include <class_board.h> |
|||
#include <class_module.h> |
|||
|
|||
#include <connectivity_data.h> |
|||
|
|||
#include <view/view_overlay.h> |
|||
|
|||
enum AR_CELL_STATE |
|||
{ |
|||
AR_OUT_OF_BOARD = -2, |
|||
AR_OCCUIPED_BY_MODULE = -1, |
|||
AR_FREE_CELL = 0 |
|||
}; |
|||
|
|||
enum AR_RESULT |
|||
{ |
|||
AR_COMPLETED = 1, |
|||
AR_CANCELLED, |
|||
AR_FAILURE |
|||
}; |
|||
|
|||
class PROGRESS_REPORTER; |
|||
|
|||
class AR_AUTOPLACER |
|||
{ |
|||
public: |
|||
AR_AUTOPLACER( BOARD* aBoard ); |
|||
|
|||
AR_RESULT AutoplaceModules( std::vector<MODULE*> aModules, BOARD_COMMIT* aCommit, |
|||
bool aPlaceOffboardModules = false ); |
|||
|
|||
const std::vector<MODULE*> QueryOffboardModules(); |
|||
|
|||
void SetPlacementGrid( int aGrid ) |
|||
{ |
|||
m_gridSize = aGrid; |
|||
} |
|||
|
|||
void SetOverlay( std::shared_ptr<KIGFX::VIEW_OVERLAY> aOverlay ) |
|||
{ |
|||
m_overlay = aOverlay; |
|||
} |
|||
|
|||
void SetRefreshCallback( std::function<int()> aCallback ) |
|||
{ |
|||
m_refreshCallback = aCallback; |
|||
} |
|||
|
|||
void SetProgressReporter( PROGRESS_REPORTER* aReporter ) |
|||
{ |
|||
m_progressReporter = aReporter; |
|||
} |
|||
|
|||
private: |
|||
void drawPlacementRoutingMatrix(); |
|||
void rotateModule( MODULE* module, double angle, bool incremental ); |
|||
int genPlacementRoutingMatrix(); |
|||
void genModuleOnRoutingMatrix( MODULE* Module ); |
|||
int propagate(); |
|||
int testRectangle( const EDA_RECT& aRect, int side ); |
|||
unsigned int calculateKeepOutArea( const EDA_RECT& aRect, int side ); |
|||
int testModuleOnBoard( MODULE* aModule, bool TstOtherSide, const wxPoint& aOffset ); |
|||
int getOptimalModulePlacement( MODULE* aModule ); |
|||
double computePlacementRatsnestCost( MODULE* aModule, const wxPoint& aOffset ); |
|||
MODULE* pickModule(); |
|||
void placeModule( MODULE* aModule, bool aDoNotRecreateRatsnest, const wxPoint& aPos ); |
|||
const D_PAD* nearestPad( MODULE* aRefModule, D_PAD* aRefPad, const wxPoint& aOffset ); |
|||
|
|||
AR_MATRIX m_matrix; |
|||
|
|||
BOARD* m_board; |
|||
|
|||
wxPoint m_curPosition; |
|||
wxPoint m_moduleOffset; |
|||
double m_minCost; |
|||
int m_gridSize; |
|||
|
|||
std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay; |
|||
std::unique_ptr<CONNECTIVITY_DATA> m_connectivity; |
|||
std::function<int()> m_refreshCallback; |
|||
PROGRESS_REPORTER* m_progressReporter; |
|||
}; |
|||
|
|||
#endif |
|||
1367
pcbnew/autorouter/ar_matrix.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,171 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr |
|||
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> |
|||
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net> |
|||
* |
|||
* Copyright (C) 1992-2015 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 |
|||
*/ |
|||
|
|||
|
|||
#ifndef __AR_MATRIX_H |
|||
#define __AR_MATRIX_H |
|||
|
|||
#include <eda_rect.h> |
|||
#include <layers_id_colors_and_visibility.h> |
|||
|
|||
class DRAWSEGMENT; |
|||
class TRACK; |
|||
class D_PAD; |
|||
class MODULE; |
|||
|
|||
#define AR_MAX_ROUTING_LAYERS_COUNT 2 |
|||
|
|||
#define AR_SIDE_TOP 0 |
|||
#define AR_SIDE_BOTTOM 1 |
|||
|
|||
/** |
|||
* class AR_MATRIX |
|||
* handle the matrix routing that describes the actual board |
|||
*/ |
|||
class AR_MATRIX |
|||
{ |
|||
public: |
|||
typedef unsigned char MATRIX_CELL; |
|||
typedef int DIST_CELL; |
|||
typedef char DIR_CELL; |
|||
|
|||
MATRIX_CELL* m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]; // the image map of 2 board sides |
|||
DIST_CELL* m_DistSide[AR_MAX_ROUTING_LAYERS_COUNT]; // the image map of 2 board sides: |
|||
// distance to cells |
|||
DIR_CELL* m_DirSide[AR_MAX_ROUTING_LAYERS_COUNT]; // the image map of 2 board sides: |
|||
// pointers back to source |
|||
bool m_InitMatrixDone; |
|||
int m_RoutingLayersCount; // Number of layers for autorouting (0 or 1) |
|||
int m_GridRouting; // Size of grid for autoplace/autoroute |
|||
EDA_RECT m_BrdBox; // Actual board bounding box |
|||
int m_Nrows, m_Ncols; // Matrix size |
|||
int m_MemSize; // Memory requirement, just for statistics |
|||
int m_RouteCount; // Number of routes |
|||
|
|||
PCB_LAYER_ID m_routeLayerTop; |
|||
PCB_LAYER_ID m_routeLayerBottom; |
|||
|
|||
private: |
|||
// a pointer to the current selected cell operation |
|||
void ( AR_MATRIX::*m_opWriteCell )( int aRow, int aCol, int aSide, MATRIX_CELL aCell ); |
|||
|
|||
public: |
|||
enum CELL_OP |
|||
{ |
|||
WRITE_CELL = 0, |
|||
WRITE_OR_CELL = 1, |
|||
WRITE_XOR_CELL = 2, |
|||
WRITE_AND_CELL = 3, |
|||
WRITE_ADD_CELL = 4 |
|||
}; |
|||
|
|||
AR_MATRIX(); |
|||
~AR_MATRIX(); |
|||
|
|||
void WriteCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell ) |
|||
{ |
|||
( *this.*m_opWriteCell )( aRow, aCol, aSide, aCell ); |
|||
} |
|||
|
|||
/** |
|||
* function GetBrdCoordOrigin |
|||
* @return the board coordinate corresponding to the |
|||
* routing matrix origin ( board coordinate offset ) |
|||
*/ |
|||
wxPoint GetBrdCoordOrigin() |
|||
{ |
|||
return m_BrdBox.GetOrigin(); |
|||
} |
|||
|
|||
/** |
|||
* Function ComputeMatrixSize |
|||
* calculates the number of rows and columns of dimensions of \a aPcb for routing and |
|||
* automatic calculation of area. |
|||
* @param aPcb = the physical board |
|||
* @param aUseBoardEdgesOnly = true to use board edges only, |
|||
* = false to use the full board bounding box (default) |
|||
*/ |
|||
bool ComputeMatrixSize( const EDA_RECT& aBoundingBox ); |
|||
|
|||
/** |
|||
* Function InitBoard |
|||
* initializes the data structures. |
|||
* |
|||
* @return the amount of memory used or -1 if default. |
|||
*/ |
|||
int InitRoutingMatrix(); |
|||
|
|||
void UnInitRoutingMatrix(); |
|||
|
|||
// Initialize WriteCell to make the aLogicOp |
|||
void SetCellOperation( CELL_OP aLogicOp ); |
|||
|
|||
// functions to read/write one cell ( point on grid routing matrix: |
|||
MATRIX_CELL GetCell( int aRow, int aCol, int aSide ); |
|||
void SetCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell ); |
|||
void OrCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell ); |
|||
void XorCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell ); |
|||
void AndCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell ); |
|||
void AddCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell ); |
|||
DIST_CELL GetDist( int aRow, int aCol, int aSide ); |
|||
void SetDist( int aRow, int aCol, int aSide, DIST_CELL ); |
|||
int GetDir( int aRow, int aCol, int aSide ); |
|||
void SetDir( int aRow, int aCol, int aSide, int aDir ); |
|||
|
|||
// calculate distance (with penalty) of a trace through a cell |
|||
int CalcDist( int x, int y, int z, int side ); |
|||
|
|||
// calculate approximate distance (manhattan distance) |
|||
int GetApxDist( int r1, int c1, int r2, int c2 ); |
|||
|
|||
|
|||
void TraceSegmentPcb( DRAWSEGMENT* pt_segm, int color, int marge, AR_MATRIX::CELL_OP op_logic ); |
|||
void TraceSegmentPcb( TRACK* aTrack, int color, int marge, AR_MATRIX::CELL_OP op_logic ); |
|||
void CreateKeepOutRectangle( |
|||
int ux0, int uy0, int ux1, int uy1, int marge, int aKeepOut, LSET aLayerMask ); |
|||
void PlacePad( D_PAD* aPad, int color, int marge, AR_MATRIX::CELL_OP op_logic ); |
|||
void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, double angle, LSET aLayerMask, |
|||
int color, AR_MATRIX::CELL_OP op_logic ); |
|||
void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, LSET aLayerMask, int color, |
|||
AR_MATRIX::CELL_OP op_logic ); |
|||
|
|||
private: |
|||
|
|||
void drawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer, int color, |
|||
CELL_OP op_logic ); |
|||
|
|||
void traceCircle( int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer, int color, |
|||
AR_MATRIX::CELL_OP op_logic ); |
|||
void traceFilledCircle( |
|||
int cx, int cy, int radius, LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic ); |
|||
void traceArc( int ux0, int uy0, int ux1, int uy1, double ArcAngle, int lg, LAYER_NUM layer, |
|||
int color, AR_MATRIX::CELL_OP op_logic ); |
|||
void tracePcbLine( int x0, int y0, int x1, int y1, LAYER_NUM layer, int color, |
|||
AR_MATRIX::CELL_OP op_logic ); |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,124 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2017 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 <board_commit.h>
|
|||
#include <class_draw_panel_gal.h>
|
|||
#include <confirm.h>
|
|||
#include <gal/graphics_abstraction_layer.h>
|
|||
#include <preview_items/centreline_rect_item.h>
|
|||
#include <preview_items/two_point_geom_manager.h>
|
|||
#include <tool/tool_manager.h>
|
|||
#include <view/view.h>
|
|||
#include <view/view_controls.h>
|
|||
|
|||
// For frame ToolID values
|
|||
#include <pcbnew_id.h>
|
|||
|
|||
// For action icons
|
|||
#include <bitmaps.h>
|
|||
|
|||
#include <class_board_item.h>
|
|||
#include <class_module.h>
|
|||
#include <tools/pcb_actions.h>
|
|||
#include <tools/selection_tool.h>
|
|||
#include <tools/tool_event_utils.h>
|
|||
|
|||
#include <widgets/progress_reporter.h>
|
|||
|
|||
#include "ar_autoplacer.h"
|
|||
#include "autoplacer_tool.h"
|
|||
|
|||
|
|||
TOOL_ACTION PCB_ACTIONS::autoplaceSelectedComponents( "pcbnew.Autoplacer.autoplaceSelected", |
|||
AS_GLOBAL, 0, _( "Auto-place selected components" ), |
|||
_( "Performs automatic placement of selected components" ) ); |
|||
|
|||
TOOL_ACTION PCB_ACTIONS::autoplaceOffboardComponents( "pcbnew.Autoplacer.autoplaceOffboard", |
|||
AS_GLOBAL, 0, _( "Auto-place off-board components" ), |
|||
_( "Performs automatic placement of components outside board area" ) ); |
|||
|
|||
AUTOPLACE_TOOL::AUTOPLACE_TOOL() : PCB_TOOL( "pcbnew.Autoplacer" ) |
|||
{ |
|||
} |
|||
|
|||
|
|||
AUTOPLACE_TOOL::~AUTOPLACE_TOOL() |
|||
{ |
|||
} |
|||
|
|||
|
|||
int AUTOPLACE_TOOL::autoplace( std::vector<MODULE*>& aModules, bool aPlaceOffboard ) |
|||
{ |
|||
auto overlay = view()->MakeOverlay(); |
|||
|
|||
Activate(); |
|||
|
|||
AR_AUTOPLACER autoplacer( board() ); |
|||
|
|||
BOARD_COMMIT commit( frame() ); |
|||
|
|||
autoplacer.SetOverlay( overlay ); |
|||
|
|||
std::unique_ptr<WX_PROGRESS_REPORTER> progressReporter( |
|||
new WX_PROGRESS_REPORTER( frame(), _( "Autoplace Components" ), 1 ) ); |
|||
|
|||
autoplacer.SetProgressReporter( progressReporter.get() ); |
|||
auto result = autoplacer.AutoplaceModules( aModules, &commit, aPlaceOffboard ); |
|||
|
|||
if( result == AR_COMPLETED ) |
|||
commit.Push( _( "Autoplace components" ) ); |
|||
else |
|||
commit.Revert(); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int AUTOPLACE_TOOL::autoplaceSelected( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
std::vector<MODULE*> mods; |
|||
|
|||
for( auto item : selection() ) |
|||
{ |
|||
if( item->Type() == PCB_MODULE_T ) |
|||
mods.push_back( static_cast<MODULE*>( item ) ); |
|||
} |
|||
|
|||
return autoplace( mods, false ); |
|||
} |
|||
|
|||
|
|||
int AUTOPLACE_TOOL::autoplaceOffboard( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
std::vector<MODULE*> mods; |
|||
|
|||
return autoplace( mods, true ); |
|||
} |
|||
|
|||
|
|||
void AUTOPLACE_TOOL::setTransitions() |
|||
{ |
|||
Go( &AUTOPLACE_TOOL::autoplaceSelected, PCB_ACTIONS::autoplaceSelectedComponents.MakeEvent() ); |
|||
Go( &AUTOPLACE_TOOL::autoplaceOffboard, PCB_ACTIONS::autoplaceOffboardComponents.MakeEvent() ); |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2017 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 |
|||
*/ |
|||
|
|||
#ifndef TOOLS_AUTOPLACE_TOOL_H |
|||
#define TOOLS_AUTOPLACE_TOOL_H |
|||
|
|||
#include <tools/pcb_tool.h> |
|||
|
|||
|
|||
/** |
|||
* Class AUTOPLACE_TOOL |
|||
* |
|||
* Tool responsible for automagic placement of components. |
|||
*/ |
|||
class AUTOPLACE_TOOL : public PCB_TOOL |
|||
{ |
|||
public: |
|||
AUTOPLACE_TOOL(); |
|||
~AUTOPLACE_TOOL(); |
|||
|
|||
///> Bind handlers to corresponding TOOL_ACTIONs |
|||
void setTransitions() override; |
|||
|
|||
private: |
|||
int autoplace( std::vector<MODULE*>& aModules, bool aPlaceOffboard ); |
|||
|
|||
int autoplaceSelected( const TOOL_EVENT& aEvent ); |
|||
int autoplaceOffboard( const TOOL_EVENT& aEvent ); |
|||
}; |
|||
|
|||
|
|||
#endif // TOOLS_AUTOPLACE_TOOL_H |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue