2011-10-13 19:56:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-03-20 12:05:38 +00:00
|
|
|
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2015-02-18 09:13:17 +00:00
|
|
|
* Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2018-03-07 19:18:45 +00:00
|
|
|
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
|
2020-02-20 12:11:04 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-13 19:56:32 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/mirror.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2019-01-29 10:50:50 +00:00
|
|
|
#include <refdes_utils.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2020-06-27 21:27:49 +00:00
|
|
|
#include <unordered_set>
|
2020-10-15 22:39:33 +00:00
|
|
|
#include <kicad_string.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <fp_shape.h>
|
2020-11-27 18:04:30 +00:00
|
|
|
#include <pcb_text.h>
|
2020-11-29 14:00:39 +00:00
|
|
|
#include <pcb_marker.h>
|
2020-12-01 14:03:34 +00:00
|
|
|
#include <pcb_group.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2016-12-02 17:58:12 +00:00
|
|
|
#include <view/view.h>
|
2020-08-26 22:04:16 +00:00
|
|
|
#include <geometry/shape_null.h>
|
2020-10-16 15:51:24 +00:00
|
|
|
#include <i18n_utility.h>
|
2020-10-23 06:48:52 +00:00
|
|
|
#include <convert_drawsegment_list_to_polygon.h>
|
2020-11-29 14:00:39 +00:00
|
|
|
#include <geometry/convex_hull.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT::FOOTPRINT( BOARD* parent ) :
|
2020-11-13 12:21:02 +00:00
|
|
|
BOARD_ITEM_CONTAINER((BOARD_ITEM*) parent, PCB_FOOTPRINT_T ),
|
|
|
|
m_initial_comments( 0 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
m_attributes = 0;
|
2020-11-14 14:29:11 +00:00
|
|
|
m_layer = F_Cu;
|
2020-11-13 02:57:11 +00:00
|
|
|
m_orient = 0;
|
2020-11-13 11:17:15 +00:00
|
|
|
m_fpStatus = FP_PADS_are_LOCKED;
|
2020-11-13 02:57:11 +00:00
|
|
|
m_arflag = 0;
|
|
|
|
m_rot90Cost = m_rot180Cost = 0;
|
|
|
|
m_link = 0;
|
|
|
|
m_lastEditTime = 0;
|
|
|
|
m_localClearance = 0;
|
|
|
|
m_localSolderMaskMargin = 0;
|
|
|
|
m_localSolderPasteMargin = 0;
|
|
|
|
m_localSolderPasteMarginRatio = 0.0;
|
|
|
|
m_zoneConnection = ZONE_CONNECTION::INHERITED; // Use zone setting by default
|
|
|
|
m_thermalWidth = 0; // Use zone setting by default
|
|
|
|
m_thermalGap = 0; // Use zone setting by default
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2014-09-10 15:18:42 +00:00
|
|
|
// These are special and mandatory text fields
|
2020-11-13 02:57:11 +00:00
|
|
|
m_reference = new FP_TEXT( this, FP_TEXT::TEXT_is_REFERENCE );
|
|
|
|
m_value = new FP_TEXT( this, FP_TEXT::TEXT_is_VALUE );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
m_3D_Drawings.clear();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT::FOOTPRINT( const FOOTPRINT& aFootprint ) :
|
2020-10-14 23:37:26 +00:00
|
|
|
BOARD_ITEM_CONTAINER( aFootprint )
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
m_pos = aFootprint.m_pos;
|
|
|
|
m_fpid = aFootprint.m_fpid;
|
|
|
|
m_attributes = aFootprint.m_attributes;
|
2020-11-13 11:17:15 +00:00
|
|
|
m_fpStatus = aFootprint.m_fpStatus;
|
2020-11-13 02:57:11 +00:00
|
|
|
m_orient = aFootprint.m_orient;
|
|
|
|
m_boundingBox = aFootprint.m_boundingBox;
|
|
|
|
m_rot90Cost = aFootprint.m_rot90Cost;
|
|
|
|
m_rot180Cost = aFootprint.m_rot180Cost;
|
|
|
|
m_lastEditTime = aFootprint.m_lastEditTime;
|
|
|
|
m_link = aFootprint.m_link;
|
|
|
|
m_path = aFootprint.m_path;
|
|
|
|
|
|
|
|
m_localClearance = aFootprint.m_localClearance;
|
|
|
|
m_localSolderMaskMargin = aFootprint.m_localSolderMaskMargin;
|
|
|
|
m_localSolderPasteMargin = aFootprint.m_localSolderPasteMargin;
|
|
|
|
m_localSolderPasteMarginRatio = aFootprint.m_localSolderPasteMarginRatio;
|
|
|
|
m_zoneConnection = aFootprint.m_zoneConnection;
|
|
|
|
m_thermalWidth = aFootprint.m_thermalWidth;
|
|
|
|
m_thermalGap = aFootprint.m_thermalGap;
|
2012-01-14 19:50:32 +00:00
|
|
|
|
2020-12-08 23:43:39 +00:00
|
|
|
std::map<BOARD_ITEM*, BOARD_ITEM*> ptrMap;
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Copy reference and value.
|
2020-11-13 02:57:11 +00:00
|
|
|
m_reference = new FP_TEXT( *aFootprint.m_reference );
|
|
|
|
m_reference->SetParent( this );
|
2020-12-08 23:43:39 +00:00
|
|
|
ptrMap[ aFootprint.m_reference ] = m_reference;
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
m_value = new FP_TEXT( *aFootprint.m_value );
|
|
|
|
m_value->SetParent( this );
|
2020-12-08 23:43:39 +00:00
|
|
|
ptrMap[ aFootprint.m_value ] = m_value;
|
2020-10-03 11:16:29 +00:00
|
|
|
|
|
|
|
// Copy pads
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : aFootprint.Pads() )
|
2020-10-03 11:16:29 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* newPad = static_cast<PAD*>( pad->Clone() );
|
2020-10-03 11:16:29 +00:00
|
|
|
ptrMap[ pad ] = newPad;
|
|
|
|
Add( newPad );
|
|
|
|
}
|
2012-01-14 19:50:32 +00:00
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
// Copy zones
|
2020-11-11 23:05:59 +00:00
|
|
|
for( FP_ZONE* zone : aFootprint.Zones() )
|
2019-10-29 10:09:54 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
FP_ZONE* newZone = static_cast<FP_ZONE*>( zone->Clone() );
|
2020-10-03 11:16:29 +00:00
|
|
|
ptrMap[ zone ] = newZone;
|
|
|
|
Add( newZone );
|
2019-10-29 10:09:54 +00:00
|
|
|
|
|
|
|
// Ensure the net info is OK and especially uses the net info list
|
|
|
|
// living in the current board
|
|
|
|
// Needed when copying a fp from fp editor that has its own board
|
|
|
|
// Must be NETINFO_LIST::ORPHANED_ITEM for a keepout that has no net.
|
2020-10-03 11:16:29 +00:00
|
|
|
newZone->SetNetCode( -1 );
|
2019-10-29 10:09:54 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
// Copy drawings
|
2020-10-14 23:37:26 +00:00
|
|
|
for( BOARD_ITEM* item : aFootprint.GraphicalItems() )
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
2020-10-03 11:16:29 +00:00
|
|
|
BOARD_ITEM* newItem = static_cast<BOARD_ITEM*>( item->Clone() );
|
|
|
|
ptrMap[ item ] = newItem;
|
|
|
|
Add( newItem );
|
|
|
|
}
|
2012-01-14 19:50:32 +00:00
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
// Copy groups
|
2020-10-14 23:37:26 +00:00
|
|
|
for( PCB_GROUP* group : aFootprint.Groups() )
|
2020-10-03 11:16:29 +00:00
|
|
|
{
|
|
|
|
PCB_GROUP* newGroup = static_cast<PCB_GROUP*>( group->Clone() );
|
2020-10-13 16:54:01 +00:00
|
|
|
ptrMap[ group ] = newGroup;
|
|
|
|
Add( newGroup );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rebuild groups
|
2020-10-14 23:37:26 +00:00
|
|
|
for( PCB_GROUP* group : aFootprint.Groups() )
|
2020-10-13 16:54:01 +00:00
|
|
|
{
|
|
|
|
PCB_GROUP* newGroup = static_cast<PCB_GROUP*>( ptrMap[ group ] );
|
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
const_cast<std::unordered_set<BOARD_ITEM*>*>( &newGroup->GetItems() )->clear();
|
|
|
|
|
|
|
|
for( BOARD_ITEM* member : group->GetItems() )
|
|
|
|
newGroup->AddItem( ptrMap[ member ] );
|
2012-01-14 19:50:32 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Copy auxiliary data: 3D_Drawings info
|
2020-10-14 23:37:26 +00:00
|
|
|
m_3D_Drawings = aFootprint.m_3D_Drawings;
|
2012-01-14 19:50:32 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
m_doc = aFootprint.m_doc;
|
2020-12-04 12:14:07 +00:00
|
|
|
m_keywords = aFootprint.m_keywords;
|
2020-10-14 23:37:26 +00:00
|
|
|
m_properties = aFootprint.m_properties;
|
2013-01-02 21:49:56 +00:00
|
|
|
|
2015-03-23 08:28:12 +00:00
|
|
|
m_arflag = 0;
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
m_initial_comments = aFootprint.m_initial_comments ?
|
|
|
|
new wxArrayString( *aFootprint.m_initial_comments ) : nullptr;
|
2012-01-14 19:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT::FOOTPRINT( FOOTPRINT&& aFootprint ) :
|
2020-10-14 23:37:26 +00:00
|
|
|
BOARD_ITEM_CONTAINER( aFootprint )
|
2020-07-16 01:11:51 +00:00
|
|
|
{
|
2020-10-14 23:37:26 +00:00
|
|
|
*this = std::move( aFootprint );
|
2020-07-16 01:11:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT::~FOOTPRINT()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2019-08-11 20:30:33 +00:00
|
|
|
// Clean up the owned elements
|
2020-11-13 02:57:11 +00:00
|
|
|
delete m_reference;
|
|
|
|
delete m_value;
|
2013-06-23 19:18:33 +00:00
|
|
|
delete m_initial_comments;
|
2019-08-11 20:30:33 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* p : m_pads )
|
2019-08-11 20:30:33 +00:00
|
|
|
delete p;
|
|
|
|
|
|
|
|
m_pads.clear();
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( FP_ZONE* zone : m_fp_zones )
|
2020-10-03 11:16:29 +00:00
|
|
|
delete zone;
|
2019-10-29 10:09:54 +00:00
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
m_fp_zones.clear();
|
2019-10-29 10:09:54 +00:00
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
for( PCB_GROUP* group : m_fp_groups )
|
|
|
|
delete group;
|
|
|
|
|
|
|
|
m_fp_groups.clear();
|
|
|
|
|
2020-06-27 18:01:00 +00:00
|
|
|
for( BOARD_ITEM* d : m_drawings )
|
2019-08-11 20:30:33 +00:00
|
|
|
delete d;
|
|
|
|
|
|
|
|
m_drawings.clear();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 08:27:52 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT& FOOTPRINT::operator=( FOOTPRINT&& aOther )
|
2020-07-16 01:11:51 +00:00
|
|
|
{
|
|
|
|
BOARD_ITEM::operator=( aOther );
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
m_pos = aOther.m_pos;
|
2020-07-16 01:11:51 +00:00
|
|
|
m_fpid = aOther.m_fpid;
|
2020-11-13 02:57:11 +00:00
|
|
|
m_attributes = aOther.m_attributes;
|
2020-11-13 11:17:15 +00:00
|
|
|
m_fpStatus = aOther.m_fpStatus;
|
2020-11-13 02:57:11 +00:00
|
|
|
m_orient = aOther.m_orient;
|
|
|
|
m_boundingBox = aOther.m_boundingBox;
|
|
|
|
m_rot90Cost = aOther.m_rot90Cost;
|
|
|
|
m_rot180Cost = aOther.m_rot180Cost;
|
|
|
|
m_lastEditTime = aOther.m_lastEditTime;
|
|
|
|
m_link = aOther.m_link;
|
|
|
|
m_path = aOther.m_path;
|
|
|
|
|
|
|
|
m_localClearance = aOther.m_localClearance;
|
|
|
|
m_localSolderMaskMargin = aOther.m_localSolderMaskMargin;
|
|
|
|
m_localSolderPasteMargin = aOther.m_localSolderPasteMargin;
|
|
|
|
m_localSolderPasteMarginRatio = aOther.m_localSolderPasteMarginRatio;
|
|
|
|
m_zoneConnection = aOther.m_zoneConnection;
|
|
|
|
m_thermalWidth = aOther.m_thermalWidth;
|
|
|
|
m_thermalGap = aOther.m_thermalGap;
|
2020-07-16 01:11:51 +00:00
|
|
|
|
|
|
|
// Move reference and value
|
2020-11-13 02:57:11 +00:00
|
|
|
m_reference = aOther.m_reference;
|
|
|
|
m_reference->SetParent( this );
|
|
|
|
m_value = aOther.m_value;
|
|
|
|
m_value->SetParent( this );
|
2020-07-16 01:11:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Move the pads
|
|
|
|
m_pads.clear();
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : aOther.Pads() )
|
2020-07-16 01:11:51 +00:00
|
|
|
Add( pad );
|
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
aOther.Pads().clear();
|
|
|
|
|
2020-07-16 01:11:51 +00:00
|
|
|
// Move the zones
|
|
|
|
m_fp_zones.clear();
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( FP_ZONE* item : aOther.Zones() )
|
2020-07-16 01:11:51 +00:00
|
|
|
{
|
2020-10-03 11:16:29 +00:00
|
|
|
Add( item );
|
2020-07-16 01:11:51 +00:00
|
|
|
|
|
|
|
// Ensure the net info is OK and especially uses the net info list
|
|
|
|
// living in the current board
|
|
|
|
// Needed when copying a fp from fp editor that has its own board
|
|
|
|
// Must be NETINFO_LIST::ORPHANED_ITEM for a keepout that has no net.
|
|
|
|
item->SetNetCode( -1 );
|
|
|
|
}
|
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
aOther.Zones().clear();
|
|
|
|
|
2020-07-16 01:11:51 +00:00
|
|
|
// Move the drawings
|
|
|
|
m_drawings.clear();
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item : aOther.GraphicalItems() )
|
2020-10-03 11:16:29 +00:00
|
|
|
Add( item );
|
2020-07-16 01:11:51 +00:00
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
aOther.GraphicalItems().clear();
|
|
|
|
|
|
|
|
// Move the groups
|
|
|
|
m_fp_groups.clear();
|
|
|
|
|
|
|
|
for( PCB_GROUP* group : aOther.Groups() )
|
|
|
|
Add( group );
|
|
|
|
|
|
|
|
aOther.Groups().clear();
|
2020-07-16 01:11:51 +00:00
|
|
|
|
|
|
|
// Copy auxiliary data: 3D_Drawings info
|
|
|
|
m_3D_Drawings.clear();
|
|
|
|
m_3D_Drawings = aOther.m_3D_Drawings;
|
2020-11-13 02:57:11 +00:00
|
|
|
m_doc = aOther.m_doc;
|
|
|
|
m_keywords = aOther.m_keywords;
|
2020-08-19 19:21:22 +00:00
|
|
|
m_properties = aOther.m_properties;
|
2020-07-16 01:11:51 +00:00
|
|
|
|
|
|
|
// Ensure auxiliary data is up to date
|
|
|
|
CalculateBoundingBox();
|
|
|
|
|
|
|
|
m_initial_comments = aOther.m_initial_comments;
|
|
|
|
|
|
|
|
// Clear the other item's containers since this is a move
|
|
|
|
aOther.Pads().clear();
|
|
|
|
aOther.Zones().clear();
|
|
|
|
aOther.GraphicalItems().clear();
|
2020-11-13 02:57:11 +00:00
|
|
|
aOther.m_value = nullptr;
|
|
|
|
aOther.m_reference = nullptr;
|
2020-07-16 01:11:51 +00:00
|
|
|
aOther.m_initial_comments = nullptr;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT& FOOTPRINT::operator=( const FOOTPRINT& aOther )
|
2016-05-31 08:27:52 +00:00
|
|
|
{
|
|
|
|
BOARD_ITEM::operator=( aOther );
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
m_pos = aOther.m_pos;
|
2016-05-31 08:27:52 +00:00
|
|
|
m_fpid = aOther.m_fpid;
|
2020-11-13 02:57:11 +00:00
|
|
|
m_attributes = aOther.m_attributes;
|
2020-11-13 11:17:15 +00:00
|
|
|
m_fpStatus = aOther.m_fpStatus;
|
2020-11-13 02:57:11 +00:00
|
|
|
m_orient = aOther.m_orient;
|
|
|
|
m_boundingBox = aOther.m_boundingBox;
|
|
|
|
m_rot90Cost = aOther.m_rot90Cost;
|
|
|
|
m_rot180Cost = aOther.m_rot180Cost;
|
|
|
|
m_lastEditTime = aOther.m_lastEditTime;
|
|
|
|
m_link = aOther.m_link;
|
|
|
|
m_path = aOther.m_path;
|
|
|
|
|
|
|
|
m_localClearance = aOther.m_localClearance;
|
|
|
|
m_localSolderMaskMargin = aOther.m_localSolderMaskMargin;
|
|
|
|
m_localSolderPasteMargin = aOther.m_localSolderPasteMargin;
|
|
|
|
m_localSolderPasteMarginRatio = aOther.m_localSolderPasteMarginRatio;
|
|
|
|
m_zoneConnection = aOther.m_zoneConnection;
|
|
|
|
m_thermalWidth = aOther.m_thermalWidth;
|
|
|
|
m_thermalGap = aOther.m_thermalGap;
|
2016-05-31 08:27:52 +00:00
|
|
|
|
|
|
|
// Copy reference and value
|
2020-11-13 02:57:11 +00:00
|
|
|
*m_reference = *aOther.m_reference;
|
|
|
|
m_reference->SetParent( this );
|
|
|
|
*m_value = *aOther.m_value;
|
|
|
|
m_value->SetParent( this );
|
2016-05-31 08:27:52 +00:00
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
std::map<BOARD_ITEM*, BOARD_ITEM*> ptrMap;
|
|
|
|
|
|
|
|
// Copy pads
|
2019-06-01 23:23:36 +00:00
|
|
|
m_pads.clear();
|
2016-05-31 08:27:52 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : aOther.Pads() )
|
2020-10-03 11:16:29 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* newPad = new PAD( *pad );
|
2020-10-03 11:16:29 +00:00
|
|
|
ptrMap[ pad ] = newPad;
|
|
|
|
Add( newPad );
|
|
|
|
}
|
2016-05-31 08:27:52 +00:00
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
// Copy zones
|
2019-10-26 15:49:29 +00:00
|
|
|
m_fp_zones.clear();
|
2019-10-29 10:09:54 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( FP_ZONE* zone : aOther.Zones() )
|
2019-10-29 10:09:54 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
FP_ZONE* newZone = static_cast<FP_ZONE*>( zone->Clone() );
|
2020-10-03 11:16:29 +00:00
|
|
|
ptrMap[ zone ] = newZone;
|
|
|
|
Add( newZone );
|
2019-10-29 10:09:54 +00:00
|
|
|
|
|
|
|
// Ensure the net info is OK and especially uses the net info list
|
|
|
|
// living in the current board
|
|
|
|
// Needed when copying a fp from fp editor that has its own board
|
|
|
|
// Must be NETINFO_LIST::ORPHANED_ITEM for a keepout that has no net.
|
2020-10-03 11:16:29 +00:00
|
|
|
newZone->SetNetCode( -1 );
|
2019-10-29 10:09:54 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
// Copy drawings
|
2019-06-02 03:55:32 +00:00
|
|
|
m_drawings.clear();
|
2016-05-31 08:27:52 +00:00
|
|
|
|
2020-06-27 18:01:00 +00:00
|
|
|
for( BOARD_ITEM* item : aOther.GraphicalItems() )
|
2016-05-31 08:27:52 +00:00
|
|
|
{
|
2020-10-03 11:16:29 +00:00
|
|
|
BOARD_ITEM* newItem = static_cast<BOARD_ITEM*>( item->Clone() );
|
|
|
|
ptrMap[ item ] = newItem;
|
|
|
|
Add( newItem );
|
|
|
|
}
|
2016-05-31 08:27:52 +00:00
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
// Copy groups
|
|
|
|
m_fp_groups.clear();
|
|
|
|
|
|
|
|
for( PCB_GROUP* group : aOther.Groups() )
|
|
|
|
{
|
|
|
|
PCB_GROUP* newGroup = static_cast<PCB_GROUP*>( group->Clone() );
|
|
|
|
const_cast<std::unordered_set<BOARD_ITEM*>*>( &newGroup->GetItems() )->clear();
|
|
|
|
|
|
|
|
for( BOARD_ITEM* member : group->GetItems() )
|
|
|
|
newGroup->AddItem( ptrMap[ member ] );
|
|
|
|
|
|
|
|
Add( newGroup );
|
2016-05-31 08:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy auxiliary data: 3D_Drawings info
|
|
|
|
m_3D_Drawings.clear();
|
|
|
|
m_3D_Drawings = aOther.m_3D_Drawings;
|
2020-11-13 02:57:11 +00:00
|
|
|
m_doc = aOther.m_doc;
|
|
|
|
m_keywords = aOther.m_keywords;
|
2020-08-19 19:21:22 +00:00
|
|
|
m_properties = aOther.m_properties;
|
2016-05-31 08:27:52 +00:00
|
|
|
|
|
|
|
// Ensure auxiliary data is up to date
|
|
|
|
CalculateBoundingBox();
|
|
|
|
|
2020-07-16 01:11:51 +00:00
|
|
|
m_initial_comments = aOther.m_initial_comments ?
|
|
|
|
new wxArrayString( *aOther.m_initial_comments ) : nullptr;
|
|
|
|
|
2016-05-31 08:27:52 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::GetContextualTextVars( wxArrayString* aVars ) const
|
2020-05-27 22:28:36 +00:00
|
|
|
{
|
|
|
|
aVars->push_back( wxT( "REFERENCE" ) );
|
|
|
|
aVars->push_back( wxT( "VALUE" ) );
|
|
|
|
aVars->push_back( wxT( "LAYER" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
bool FOOTPRINT::ResolveTextVar( wxString* token, int aDepth ) const
|
2020-04-06 13:06:57 +00:00
|
|
|
{
|
|
|
|
if( token->IsSameAs( wxT( "REFERENCE" ) ) )
|
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
*token = m_reference->GetShownText( aDepth + 1 );
|
2020-04-06 13:06:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( token->IsSameAs( wxT( "VALUE" ) ) )
|
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
*token = m_value->GetShownText( aDepth + 1 );
|
2020-04-06 13:06:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( token->IsSameAs( wxT( "LAYER" ) ) )
|
|
|
|
{
|
|
|
|
*token = GetLayerName();
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-08 21:47:57 +00:00
|
|
|
else if( m_properties.count( *token ) )
|
|
|
|
{
|
|
|
|
*token = m_properties.at( *token );
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-06 13:06:57 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::ClearAllNets()
|
2015-02-18 09:13:17 +00:00
|
|
|
{
|
|
|
|
// Force the ORPHANED dummy net info for all pads.
|
|
|
|
// ORPHANED dummy net does not depend on a board
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2016-01-29 10:29:56 +00:00
|
|
|
pad->SetNetCode( NETINFO_LIST::ORPHANED );
|
2015-02-18 09:13:17 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 10:30:40 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode )
|
2014-07-09 12:22:29 +00:00
|
|
|
{
|
|
|
|
switch( aBoardItem->Type() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2019-12-10 13:49:28 +00:00
|
|
|
// Only user text can be added this way.
|
2020-10-04 23:34:59 +00:00
|
|
|
assert( static_cast<FP_TEXT*>( aBoardItem )->GetType() == FP_TEXT::TEXT_is_DIVERS );
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
2014-07-09 12:22:29 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
2019-12-28 00:55:11 +00:00
|
|
|
if( aMode == ADD_MODE::APPEND )
|
2019-06-02 03:55:32 +00:00
|
|
|
m_drawings.push_back( aBoardItem );
|
2014-07-09 12:22:29 +00:00
|
|
|
else
|
2019-06-02 03:55:32 +00:00
|
|
|
m_drawings.push_front( aBoardItem );
|
2014-07-09 12:22:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_PAD_T:
|
2019-12-28 00:55:11 +00:00
|
|
|
if( aMode == ADD_MODE::APPEND )
|
2020-11-12 22:30:02 +00:00
|
|
|
m_pads.push_back( static_cast<PAD*>( aBoardItem ) );
|
2014-07-09 12:22:29 +00:00
|
|
|
else
|
2020-11-12 22:30:02 +00:00
|
|
|
m_pads.push_front( static_cast<PAD*>( aBoardItem ) );
|
2014-07-09 12:22:29 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_FP_ZONE_T:
|
2019-12-28 00:55:11 +00:00
|
|
|
if( aMode == ADD_MODE::APPEND )
|
2020-11-11 23:05:59 +00:00
|
|
|
m_fp_zones.push_back( static_cast<FP_ZONE*>( aBoardItem ) );
|
2019-10-29 10:09:54 +00:00
|
|
|
else
|
2020-11-11 23:05:59 +00:00
|
|
|
m_fp_zones.insert( m_fp_zones.begin(), static_cast<FP_ZONE*>( aBoardItem ) );
|
2019-10-29 10:09:54 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
case PCB_GROUP_T:
|
|
|
|
if( aMode == ADD_MODE::APPEND )
|
|
|
|
m_fp_groups.push_back( static_cast<PCB_GROUP*>( aBoardItem ) );
|
|
|
|
else
|
|
|
|
m_fp_groups.insert( m_fp_groups.begin(), static_cast<PCB_GROUP*>( aBoardItem ) );
|
|
|
|
break;
|
|
|
|
|
2014-07-09 12:22:29 +00:00
|
|
|
default:
|
2014-11-15 19:06:05 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2020-11-13 21:07:01 +00:00
|
|
|
msg.Printf( wxT( "FOOTPRINT::Add() needs work: BOARD_ITEM type (%d) not handled" ),
|
2014-11-15 19:06:05 +00:00
|
|
|
aBoardItem->Type() );
|
|
|
|
wxFAIL_MSG( msg );
|
2014-07-09 12:22:29 +00:00
|
|
|
|
2014-11-15 19:06:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-07-09 12:22:29 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 19:50:42 +00:00
|
|
|
aBoardItem->ClearEditFlags();
|
2014-07-09 12:22:29 +00:00
|
|
|
aBoardItem->SetParent( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-07 23:29:30 +00:00
|
|
|
void FOOTPRINT::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aMode )
|
2014-07-09 12:22:29 +00:00
|
|
|
{
|
|
|
|
switch( aBoardItem->Type() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2019-12-10 13:49:28 +00:00
|
|
|
// Only user text can be removed this way.
|
2019-06-11 14:47:54 +00:00
|
|
|
wxCHECK_RET(
|
2020-10-04 23:34:59 +00:00
|
|
|
static_cast<FP_TEXT*>( aBoardItem )->GetType() == FP_TEXT::TEXT_is_DIVERS,
|
2019-06-11 14:47:54 +00:00
|
|
|
"Please report this bug: Invalid remove operation on required text" );
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
2014-07-09 12:22:29 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
2019-06-11 14:47:54 +00:00
|
|
|
for( auto it = m_drawings.begin(); it != m_drawings.end(); ++it )
|
|
|
|
{
|
|
|
|
if( *it == aBoardItem )
|
|
|
|
{
|
|
|
|
m_drawings.erase( it );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 15:31:54 +00:00
|
|
|
break;
|
2014-07-09 12:22:29 +00:00
|
|
|
|
|
|
|
case PCB_PAD_T:
|
2019-06-11 14:47:54 +00:00
|
|
|
for( auto it = m_pads.begin(); it != m_pads.end(); ++it )
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
if( *it == static_cast<PAD*>( aBoardItem ) )
|
2019-06-11 14:47:54 +00:00
|
|
|
{
|
|
|
|
m_pads.erase( it );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 15:31:54 +00:00
|
|
|
break;
|
2014-07-09 12:22:29 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_FP_ZONE_T:
|
2019-10-26 15:49:29 +00:00
|
|
|
for( auto it = m_fp_zones.begin(); it != m_fp_zones.end(); ++it )
|
2019-10-29 10:09:54 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
if( *it == static_cast<FP_ZONE*>( aBoardItem ) )
|
2019-10-29 10:09:54 +00:00
|
|
|
{
|
2019-10-26 15:49:29 +00:00
|
|
|
m_fp_zones.erase( it );
|
2019-10-29 10:09:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
case PCB_GROUP_T:
|
|
|
|
for( auto it = m_fp_groups.begin(); it != m_fp_groups.end(); ++it )
|
|
|
|
{
|
|
|
|
if( *it == static_cast<PCB_GROUP*>( aBoardItem ) )
|
|
|
|
{
|
|
|
|
m_fp_groups.erase( it );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2014-07-09 12:22:29 +00:00
|
|
|
default:
|
2014-11-15 19:06:05 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2020-11-13 21:07:01 +00:00
|
|
|
msg.Printf( wxT( "FOOTPRINT::Remove() needs work: BOARD_ITEM type (%d) not handled" ),
|
2014-11-15 19:06:05 +00:00
|
|
|
aBoardItem->Type() );
|
|
|
|
wxFAIL_MSG( msg );
|
|
|
|
}
|
2014-07-09 12:22:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::CalculateBoundingBox()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
m_boundingBox = GetFootprintRect();
|
2018-09-13 21:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
double FOOTPRINT::GetArea( int aPadding ) const
|
2018-09-13 21:29:52 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
double w = std::abs( static_cast<double>( m_boundingBox.GetWidth() ) ) + aPadding;
|
|
|
|
double h = std::abs( static_cast<double>( m_boundingBox.GetHeight() ) ) + aPadding;
|
2018-09-13 21:29:52 +00:00
|
|
|
return w * h;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
EDA_RECT FOOTPRINT::GetFootprintRect() const
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT area;
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
area.SetOrigin( m_pos );
|
|
|
|
area.SetEnd( m_pos );
|
2013-01-02 21:49:56 +00:00
|
|
|
area.Inflate( Millimeter2iu( 0.25 ) ); // Give a min size to the area
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2020-06-27 18:01:00 +00:00
|
|
|
for( BOARD_ITEM* item : m_drawings )
|
2014-04-30 19:16:22 +00:00
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
if( item->Type() == PCB_FP_SHAPE_T )
|
2018-08-09 00:11:47 +00:00
|
|
|
area.Merge( item->GetBoundingBox() );
|
2014-04-30 19:16:22 +00:00
|
|
|
}
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2010-12-10 19:47:44 +00:00
|
|
|
area.Merge( pad->GetBoundingBox() );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( FP_ZONE* zone : m_fp_zones )
|
2019-10-29 10:09:54 +00:00
|
|
|
area.Merge( zone->GetBoundingBox() );
|
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
// Groups do not contribute to the rect, only their members
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
EDA_RECT FOOTPRINT::GetFpPadsLocalBbox() const
|
2019-11-01 12:35:42 +00:00
|
|
|
{
|
|
|
|
EDA_RECT area;
|
|
|
|
|
|
|
|
// We want the bounding box of the footprint pads at rot 0, not flipped
|
|
|
|
// Create such a image:
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT dummy( *this );
|
2019-11-01 12:35:42 +00:00
|
|
|
|
|
|
|
dummy.SetPosition( wxPoint( 0, 0 ) );
|
2020-10-14 23:37:26 +00:00
|
|
|
|
2019-11-01 12:35:42 +00:00
|
|
|
if( dummy.IsFlipped() )
|
|
|
|
dummy.Flip( wxPoint( 0, 0 ) , false );
|
|
|
|
|
|
|
|
if( dummy.GetOrientation() )
|
|
|
|
dummy.SetOrientation( 0 );
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : dummy.Pads() )
|
2019-11-01 12:35:42 +00:00
|
|
|
area.Merge( pad->GetBoundingBox() );
|
|
|
|
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
const EDA_RECT FOOTPRINT::GetBoundingBox() const
|
2008-03-13 10:08:42 +00:00
|
|
|
{
|
2020-09-16 05:04:48 +00:00
|
|
|
return GetBoundingBox( true );
|
2008-03-13 10:08:42 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
const EDA_RECT FOOTPRINT::GetBoundingBox( bool aIncludeInvisibleText ) const
|
2019-08-20 11:58:14 +00:00
|
|
|
{
|
|
|
|
EDA_RECT area = GetFootprintRect();
|
|
|
|
|
|
|
|
// Add in items not collected by GetFootprintRect():
|
2020-06-27 18:01:00 +00:00
|
|
|
for( BOARD_ITEM* item : m_drawings )
|
2019-08-20 11:58:14 +00:00
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
if( item->Type() != PCB_FP_SHAPE_T )
|
2019-08-20 11:58:14 +00:00
|
|
|
area.Merge( item->GetBoundingBox() );
|
|
|
|
}
|
|
|
|
|
2020-09-16 05:04:48 +00:00
|
|
|
// This can be further optimized when aIncludeInvisibleText is true, but currently
|
|
|
|
// leaving this as is until it's determined there is a noticeable speed hit.
|
|
|
|
bool valueLayerIsVisible = true;
|
|
|
|
bool refLayerIsVisible = true;
|
|
|
|
BOARD* board = GetBoard();
|
|
|
|
|
|
|
|
if( board )
|
|
|
|
{
|
|
|
|
// The first "&&" conditional handles the user turning layers off as well as layers
|
|
|
|
// not being present in the current PCB stackup. Values, references, and all
|
|
|
|
// footprint text can also be turned off via the GAL meta-layers, so the 2nd and
|
|
|
|
// 3rd "&&" conditionals handle that.
|
2020-11-13 02:57:11 +00:00
|
|
|
valueLayerIsVisible = board->IsLayerVisible( m_value->GetLayer() )
|
2020-09-16 05:04:48 +00:00
|
|
|
&& board->IsElementVisible( LAYER_MOD_VALUES )
|
|
|
|
&& board->IsElementVisible( LAYER_MOD_TEXT_FR );
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
refLayerIsVisible = board->IsLayerVisible( m_reference->GetLayer() )
|
2020-09-16 05:04:48 +00:00
|
|
|
&& board->IsElementVisible( LAYER_MOD_REFERENCES )
|
|
|
|
&& board->IsElementVisible( LAYER_MOD_TEXT_FR );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if(( m_value->IsVisible() && valueLayerIsVisible ) || aIncludeInvisibleText )
|
|
|
|
area.Merge( m_value->GetBoundingBox() );
|
2019-08-20 11:58:14 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if(( m_reference->IsVisible() && refLayerIsVisible ) || aIncludeInvisibleText )
|
|
|
|
area.Merge( m_reference->GetBoundingBox() );
|
2019-08-20 11:58:14 +00:00
|
|
|
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-29 14:00:39 +00:00
|
|
|
SHAPE_POLY_SET FOOTPRINT::GetBoundingHull() const
|
2018-02-19 00:00:29 +00:00
|
|
|
{
|
2020-11-29 14:00:39 +00:00
|
|
|
SHAPE_POLY_SET rawPolys;
|
2018-02-19 00:00:29 +00:00
|
|
|
|
2020-11-29 14:00:39 +00:00
|
|
|
for( BOARD_ITEM* item : m_drawings )
|
|
|
|
{
|
|
|
|
if( item->Type() == PCB_FP_SHAPE_T )
|
|
|
|
{
|
|
|
|
item->TransformShapeWithClearanceToPolygon( rawPolys, UNDEFINED_LAYER, 0, ARC_LOW_DEF,
|
|
|
|
ERROR_OUTSIDE );
|
|
|
|
}
|
2018-02-22 01:39:46 +00:00
|
|
|
|
2020-11-29 14:00:39 +00:00
|
|
|
// We intentionally exclude footprint text from the bounding hull.
|
|
|
|
}
|
2018-02-19 00:00:29 +00:00
|
|
|
|
2020-11-29 14:00:39 +00:00
|
|
|
for( PAD* pad : m_pads )
|
|
|
|
{
|
|
|
|
pad->TransformShapeWithClearanceToPolygon( rawPolys, UNDEFINED_LAYER, 0, ARC_LOW_DEF,
|
|
|
|
ERROR_OUTSIDE );
|
|
|
|
}
|
2018-02-22 01:39:46 +00:00
|
|
|
|
2020-11-29 14:00:39 +00:00
|
|
|
for( FP_ZONE* zone : m_fp_zones )
|
2018-02-22 01:39:46 +00:00
|
|
|
{
|
2020-11-29 14:00:39 +00:00
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET layerPoly = zone->GetFilledPolysList( layer );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < layerPoly.OutlineCount(); ii++ )
|
|
|
|
{
|
|
|
|
const SHAPE_LINE_CHAIN& poly = layerPoly.COutline( ii );
|
|
|
|
rawPolys.AddOutline( poly );
|
|
|
|
}
|
|
|
|
}
|
2018-02-22 01:39:46 +00:00
|
|
|
}
|
2018-02-19 00:00:29 +00:00
|
|
|
|
2020-11-29 14:00:39 +00:00
|
|
|
std::vector<wxPoint> convex_hull;
|
|
|
|
BuildConvexHull( convex_hull, rawPolys );
|
|
|
|
|
|
|
|
SHAPE_POLY_SET hullPoly;
|
|
|
|
hullPoly.NewOutline();
|
|
|
|
|
|
|
|
for( const wxPoint& pt : convex_hull )
|
|
|
|
hullPoly.Append( pt );
|
2018-02-19 00:00:29 +00:00
|
|
|
|
2020-11-29 14:00:39 +00:00
|
|
|
return hullPoly;
|
2018-02-19 00:00:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-05-22 10:31:14 +00:00
|
|
|
wxString msg, msg2;
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( m_reference->GetShownText(), m_value->GetShownText() );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2020-05-22 10:31:14 +00:00
|
|
|
if( aFrame->IsType( FRAME_FOOTPRINT_VIEWER )
|
|
|
|
|| aFrame->IsType( FRAME_FOOTPRINT_VIEWER_MODAL )
|
|
|
|
|| aFrame->IsType( FRAME_FOOTPRINT_EDITOR ) )
|
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
wxDateTime date( static_cast<time_t>( m_lastEditTime ) );
|
2009-10-11 13:04:47 +00:00
|
|
|
|
2020-05-22 10:31:14 +00:00
|
|
|
// Date format: see http://www.cplusplus.com/reference/ctime/strftime
|
2020-11-13 02:57:11 +00:00
|
|
|
if( m_lastEditTime && date.IsValid() )
|
2020-05-22 10:31:14 +00:00
|
|
|
msg = date.Format( wxT( "%b %d, %Y" ) ); // Abbreviated_month_name Day, Year
|
|
|
|
else
|
|
|
|
msg = _( "Unknown" );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Last Change" ), msg );
|
2020-05-22 10:31:14 +00:00
|
|
|
}
|
|
|
|
else if( aFrame->IsType( FRAME_PCB_EDITOR ) )
|
|
|
|
{
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Board Side" ), IsFlipped() ? _( "Back (Flipped)" ) : _( "Front" ) );
|
2020-05-22 10:31:14 +00:00
|
|
|
}
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
auto addToken = []( wxString* aStr, const wxString& aAttr )
|
2020-10-14 23:37:26 +00:00
|
|
|
{
|
|
|
|
if( !aStr->IsEmpty() )
|
|
|
|
*aStr += wxT( ", " );
|
2020-08-26 21:43:38 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
*aStr += aAttr;
|
|
|
|
};
|
2020-08-26 21:43:38 +00:00
|
|
|
|
|
|
|
wxString status;
|
|
|
|
wxString attrs;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-09-09 02:27:56 +00:00
|
|
|
if( IsLocked() )
|
2020-08-26 21:43:38 +00:00
|
|
|
addToken( &status, _( "locked" ) );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
if( m_fpStatus & FP_is_PLACED )
|
2020-08-26 21:43:38 +00:00
|
|
|
addToken( &status, _( "autoplaced" ) );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( m_attributes & FP_BOARD_ONLY )
|
2020-08-26 21:43:38 +00:00
|
|
|
addToken( &attrs, _( "not in schematic" ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( m_attributes & FP_EXCLUDE_FROM_POS_FILES )
|
2020-08-26 21:43:38 +00:00
|
|
|
addToken( &attrs, _( "exclude from pos files" ) );
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( m_attributes & FP_EXCLUDE_FROM_BOM )
|
2020-08-26 21:43:38 +00:00
|
|
|
addToken( &attrs, _( "exclude from BOM" ) );
|
2012-12-06 21:53:00 +00:00
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Status: " ) + status, _( "Attributes:" ) + wxS( " " ) + attrs );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Rotation" ), wxString::Format( "%.4g", GetOrientationDegrees() ) );
|
2020-07-06 13:00:36 +00:00
|
|
|
|
2020-10-16 00:39:55 +00:00
|
|
|
msg.Printf( _( "Footprint: %s" ), m_fpid.Format().c_str() );
|
2020-11-30 14:35:48 +00:00
|
|
|
msg2.Printf( _( "3D-Shape: %s" ), m_3D_Drawings.empty() ? _( "<none>" )
|
|
|
|
: m_3D_Drawings.front().m_Filename );
|
|
|
|
aList.emplace_back( msg, msg2 );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
msg.Printf( _( "Doc: %s" ), m_doc );
|
|
|
|
msg2.Printf( _( "Keywords: %s" ), m_keywords );
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( msg, msg2 );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2020-11-26 19:45:22 +00:00
|
|
|
bool FOOTPRINT::IsOnLayer( PCB_LAYER_ID aLayer ) const
|
|
|
|
{
|
|
|
|
// If we have any pads, fall back on normal checking
|
|
|
|
if( !m_pads.empty() )
|
|
|
|
return m_layer == aLayer;
|
|
|
|
|
|
|
|
// No pads? Check if this entire footprint exists on the given layer
|
|
|
|
for( FP_ZONE* zone : m_fp_zones )
|
|
|
|
{
|
|
|
|
if( !zone->IsOnLayer( aLayer ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item : m_drawings )
|
|
|
|
{
|
|
|
|
if( !item->IsOnLayer( aLayer ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
bool FOOTPRINT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
EDA_RECT rect = m_boundingBox;//.GetBoundingBoxRotated( GetPosition(), m_Orient );
|
2019-05-05 10:33:34 +00:00
|
|
|
return rect.Inflate( aAccuracy ).Contains( aPosition );
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
bool FOOTPRINT::HitTestAccurate( const wxPoint& aPosition, int aAccuracy ) const
|
2018-02-19 00:00:29 +00:00
|
|
|
{
|
2020-11-29 14:00:39 +00:00
|
|
|
return GetBoundingHull().Collide( aPosition, aAccuracy );
|
2018-02-19 00:00:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
bool FOOTPRINT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2013-09-21 18:09:41 +00:00
|
|
|
EDA_RECT arect = aRect;
|
|
|
|
arect.Inflate( aAccuracy );
|
2011-09-01 21:39:38 +00:00
|
|
|
|
2013-09-21 18:09:41 +00:00
|
|
|
if( aContained )
|
2020-11-13 02:57:11 +00:00
|
|
|
return arect.Contains( m_boundingBox );
|
2013-09-21 18:09:41 +00:00
|
|
|
else
|
2017-05-02 06:44:41 +00:00
|
|
|
{
|
|
|
|
// If the rect does not intersect the bounding box, skip any tests
|
|
|
|
if( !aRect.Intersects( GetBoundingBox() ) )
|
|
|
|
return false;
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
// Determine if any elements in the FOOTPRINT intersect the rect
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2017-05-02 06:44:41 +00:00
|
|
|
{
|
|
|
|
if( pad->HitTest( arect, false, 0 ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( FP_ZONE* zone : m_fp_zones )
|
2019-10-29 10:09:54 +00:00
|
|
|
{
|
|
|
|
if( zone->HitTest( arect, false, 0 ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-27 18:01:00 +00:00
|
|
|
for( BOARD_ITEM* item : m_drawings )
|
2017-05-02 06:44:41 +00:00
|
|
|
{
|
|
|
|
if( item->HitTest( arect, false, 0 ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
// Groups are not hit-tested; only their members
|
|
|
|
|
2017-05-02 06:44:41 +00:00
|
|
|
// No items were hit
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
PAD* FOOTPRINT::FindPadByName( const wxString& aPadName ) const
|
2008-03-04 04:22:27 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2008-03-04 04:22:27 +00:00
|
|
|
{
|
2019-07-25 15:37:25 +00:00
|
|
|
if( pad->GetName() == aPadName )
|
2008-03-04 04:22:27 +00:00
|
|
|
return pad;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
PAD* FOOTPRINT::GetPad( const wxPoint& aPosition, LSET aLayerMask )
|
2011-09-15 17:58:35 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2011-09-15 17:58:35 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// ... and on the correct layer.
|
2014-06-24 18:30:39 +00:00
|
|
|
if( !( pad->GetLayerSet() & aLayerMask ).any() )
|
2011-09-15 17:58:35 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( pad->HitTest( aPosition ) )
|
|
|
|
return pad;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
PAD* FOOTPRINT::GetTopLeftPad()
|
2017-04-22 20:07:29 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* topLeftPad = GetFirstPad();
|
2017-04-22 20:07:29 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* p : m_pads )
|
2017-04-22 20:07:29 +00:00
|
|
|
{
|
|
|
|
wxPoint pnt = p->GetPosition(); // GetPosition() returns the center of the pad
|
|
|
|
|
|
|
|
if( ( pnt.x < topLeftPad->GetPosition().x ) ||
|
2020-05-22 10:31:14 +00:00
|
|
|
( topLeftPad->GetPosition().x == pnt.x && pnt.y < topLeftPad->GetPosition().y ) )
|
2017-04-22 20:07:29 +00:00
|
|
|
{
|
|
|
|
topLeftPad = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return topLeftPad;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
unsigned FOOTPRINT::GetPadCount( INCLUDE_NPTH_T aIncludeNPTH ) const
|
2013-06-07 13:17:52 +00:00
|
|
|
{
|
|
|
|
if( aIncludeNPTH )
|
2019-06-01 23:23:36 +00:00
|
|
|
return m_pads.size();
|
2013-06-07 13:17:52 +00:00
|
|
|
|
|
|
|
unsigned cnt = 0;
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2013-06-07 13:17:52 +00:00
|
|
|
{
|
2020-09-30 15:38:35 +00:00
|
|
|
if( pad->GetAttribute() == PAD_ATTRIB_NPTH )
|
2013-06-07 13:17:52 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
unsigned FOOTPRINT::GetUniquePadCount( INCLUDE_NPTH_T aIncludeNPTH ) const
|
2015-11-11 18:35:26 +00:00
|
|
|
{
|
2017-08-10 15:00:28 +00:00
|
|
|
std::set<wxString> usedNames;
|
2015-11-11 18:35:26 +00:00
|
|
|
|
|
|
|
// Create a set of used pad numbers
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2015-11-11 18:35:26 +00:00
|
|
|
{
|
2015-11-13 11:32:42 +00:00
|
|
|
// Skip pads not on copper layers (used to build complex
|
|
|
|
// solder paste shapes for instance)
|
|
|
|
if( ( pad->GetLayerSet() & LSET::AllCuMask() ).none() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Skip pads with no name, because they are usually "mechanical"
|
|
|
|
// pads, not "electrical" pads
|
2017-08-11 09:22:13 +00:00
|
|
|
if( pad->GetName().IsEmpty() )
|
2015-11-13 11:32:42 +00:00
|
|
|
continue;
|
|
|
|
|
2015-11-11 18:35:26 +00:00
|
|
|
if( !aIncludeNPTH )
|
|
|
|
{
|
2015-11-13 11:32:42 +00:00
|
|
|
// skip NPTH
|
2020-09-30 15:38:35 +00:00
|
|
|
if( pad->GetAttribute() == PAD_ATTRIB_NPTH )
|
2015-11-11 18:35:26 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 09:22:13 +00:00
|
|
|
usedNames.insert( pad->GetName() );
|
2015-11-11 18:35:26 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 11:32:42 +00:00
|
|
|
return usedNames.size();
|
2015-11-11 18:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::Add3DModel( FP_3DMODEL* a3DModel )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
if( NULL == a3DModel )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( !a3DModel->m_Filename.empty() )
|
|
|
|
m_3D_Drawings.push_back( *a3DModel );
|
|
|
|
|
|
|
|
delete a3DModel;
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
// see footprint.h
|
2020-11-13 15:15:52 +00:00
|
|
|
SEARCH_RESULT FOOTPRINT::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
|
2007-08-09 21:15:08 +00:00
|
|
|
{
|
2008-03-15 10:24:32 +00:00
|
|
|
KICAD_T stype;
|
2019-12-28 00:55:11 +00:00
|
|
|
SEARCH_RESULT result = SEARCH_RESULT::CONTINUE;
|
2008-03-15 10:24:32 +00:00
|
|
|
const KICAD_T* p = scanTypes;
|
|
|
|
bool done = false;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
#if 0 && defined(DEBUG)
|
2008-03-15 10:24:32 +00:00
|
|
|
std::cout << GetClass().mb_str() << ' ';
|
2008-02-19 00:30:10 +00:00
|
|
|
#endif
|
2007-08-09 21:15:08 +00:00
|
|
|
|
2007-08-24 03:40:04 +00:00
|
|
|
while( !done )
|
2007-08-09 21:15:08 +00:00
|
|
|
{
|
2007-08-24 03:40:04 +00:00
|
|
|
stype = *p;
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
switch( stype )
|
|
|
|
{
|
2020-11-13 12:21:02 +00:00
|
|
|
case PCB_FOOTPRINT_T:
|
2016-07-12 19:05:54 +00:00
|
|
|
result = inspector( this, testData ); // inspect me
|
2007-08-24 03:40:04 +00:00
|
|
|
++p;
|
2007-08-09 21:15:08 +00:00
|
|
|
break;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_PAD_T:
|
2020-11-12 22:30:02 +00:00
|
|
|
result = IterateForward<PAD*>( m_pads, inspector, testData, p );
|
2007-08-24 03:40:04 +00:00
|
|
|
++p;
|
2007-08-09 21:15:08 +00:00
|
|
|
break;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_FP_ZONE_T:
|
|
|
|
result = IterateForward<FP_ZONE*>( m_fp_zones, inspector, testData, p );
|
2019-10-29 10:09:54 +00:00
|
|
|
++p;
|
|
|
|
break;
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2020-11-13 02:57:11 +00:00
|
|
|
result = inspector( m_reference, testData );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
if( result == SEARCH_RESULT::QUIT )
|
2007-08-09 21:15:08 +00:00
|
|
|
break;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
result = inspector( m_value, testData );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
if( result == SEARCH_RESULT::QUIT )
|
2007-08-09 21:15:08 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
// Intentionally fall through since m_Drawings can hold PCB_FP_SHAPE_T also
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
2019-06-02 03:55:32 +00:00
|
|
|
result = IterateForward<BOARD_ITEM*>( m_drawings, inspector, testData, p );
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-24 03:40:04 +00:00
|
|
|
// skip over any types handled in the above call.
|
2008-03-15 10:24:32 +00:00
|
|
|
for( ; ; )
|
2007-08-24 03:40:04 +00:00
|
|
|
{
|
|
|
|
switch( stype = *++p )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
|
|
|
case PCB_FP_SHAPE_T:
|
2007-08-24 03:40:04 +00:00
|
|
|
continue;
|
2008-03-15 10:24:32 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
;
|
2007-08-24 03:40:04 +00:00
|
|
|
}
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-24 03:40:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
break;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
case PCB_GROUP_T:
|
|
|
|
result = IterateForward<PCB_GROUP*>( m_fp_groups, inspector, testData, p );
|
|
|
|
++p;
|
|
|
|
break;
|
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
default:
|
2007-08-24 03:40:04 +00:00
|
|
|
done = true;
|
2007-08-09 21:15:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
if( result == SEARCH_RESULT::QUIT )
|
2007-08-09 21:15:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-19 00:30:10 +00:00
|
|
|
return result;
|
2007-08-09 21:15:08 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
wxString FOOTPRINT::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2011-07-14 15:42:44 +00:00
|
|
|
{
|
2018-01-31 09:08:57 +00:00
|
|
|
wxString reference = GetReference();
|
|
|
|
|
|
|
|
if( reference.IsEmpty() )
|
2020-03-17 16:08:29 +00:00
|
|
|
reference = _( "<no reference designator>" );
|
2018-01-31 09:08:57 +00:00
|
|
|
|
2020-09-19 16:12:00 +00:00
|
|
|
return wxString::Format( _( "Footprint %s" ), reference );
|
2011-07-14 15:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
BITMAP_DEF FOOTPRINT::GetMenuImage() const
|
2017-02-20 12:20:39 +00:00
|
|
|
{
|
|
|
|
return module_xpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
EDA_ITEM* FOOTPRINT::Clone() const
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
return new FOOTPRINT( *this );
|
2012-01-14 19:50:32 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::RunOnChildren( const std::function<void ( BOARD_ITEM*)>& aFunction ) const
|
2013-12-18 12:39:11 +00:00
|
|
|
{
|
2015-02-15 22:21:52 +00:00
|
|
|
try
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2015-02-15 22:21:52 +00:00
|
|
|
aFunction( static_cast<BOARD_ITEM*>( pad ) );
|
2013-12-18 12:39:11 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( FP_ZONE* zone : m_fp_zones )
|
|
|
|
aFunction( static_cast<FP_ZONE*>( zone ) );
|
2019-10-29 10:09:54 +00:00
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
for( PCB_GROUP* group : m_fp_groups )
|
|
|
|
aFunction( static_cast<PCB_GROUP*>( group ) );
|
|
|
|
|
2020-06-27 18:01:00 +00:00
|
|
|
for( BOARD_ITEM* drawing : m_drawings )
|
2019-06-02 03:55:32 +00:00
|
|
|
aFunction( static_cast<BOARD_ITEM*>( drawing ) );
|
2013-12-18 12:39:11 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
aFunction( static_cast<BOARD_ITEM*>( m_reference ) );
|
|
|
|
aFunction( static_cast<BOARD_ITEM*>( m_value ) );
|
2015-02-15 22:21:52 +00:00
|
|
|
}
|
2016-10-10 15:04:48 +00:00
|
|
|
catch( std::bad_function_call& )
|
2015-02-15 22:21:52 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
wxFAIL_MSG( "Error running FOOTPRINT::RunOnChildren" );
|
2015-02-15 22:21:52 +00:00
|
|
|
}
|
2013-12-18 12:39:11 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 01:40:50 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::GetAllDrawingLayers( int aLayers[], int& aCount, bool aIncludePads ) const
|
2018-03-08 01:40:50 +00:00
|
|
|
{
|
|
|
|
std::unordered_set<int> layers;
|
|
|
|
|
2020-06-27 18:01:00 +00:00
|
|
|
for( BOARD_ITEM* item : m_drawings )
|
2018-03-08 01:40:50 +00:00
|
|
|
layers.insert( static_cast<int>( item->GetLayer() ) );
|
|
|
|
|
|
|
|
if( aIncludePads )
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2018-03-08 01:40:50 +00:00
|
|
|
{
|
|
|
|
int pad_layers[KIGFX::VIEW::VIEW_MAX_LAYERS], pad_layers_count;
|
|
|
|
pad->ViewGetLayers( pad_layers, pad_layers_count );
|
|
|
|
|
|
|
|
for( int i = 0; i < pad_layers_count; i++ )
|
|
|
|
layers.insert( pad_layers[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aCount = layers.size();
|
|
|
|
int i = 0;
|
|
|
|
|
2020-06-27 18:01:00 +00:00
|
|
|
for( int layer : layers )
|
2018-03-08 01:40:50 +00:00
|
|
|
aLayers[i++] = layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::ViewGetLayers( int aLayers[], int& aCount ) const
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2014-08-04 08:06:24 +00:00
|
|
|
aCount = 2;
|
2017-03-13 03:19:33 +00:00
|
|
|
aLayers[0] = LAYER_ANCHOR;
|
2014-08-04 08:06:24 +00:00
|
|
|
|
2020-11-14 14:29:11 +00:00
|
|
|
switch( m_layer )
|
2014-08-04 08:06:24 +00:00
|
|
|
{
|
2016-03-13 15:39:18 +00:00
|
|
|
default:
|
2020-10-14 23:37:26 +00:00
|
|
|
wxASSERT_MSG( false, "Illegal layer" ); // do you really have footprints placed on
|
|
|
|
// other layers?
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
|
|
|
|
2014-08-04 08:06:24 +00:00
|
|
|
case F_Cu:
|
2017-03-13 03:19:33 +00:00
|
|
|
aLayers[1] = LAYER_MOD_FR;
|
2014-08-04 08:06:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case B_Cu:
|
2017-03-13 03:19:33 +00:00
|
|
|
aLayers[1] = LAYER_MOD_BK;
|
2014-08-04 08:06:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-01-04 22:39:36 +00:00
|
|
|
|
2020-08-30 21:20:37 +00:00
|
|
|
// If there are no pads, and only drawings on a silkscreen layer, then report the silkscreen
|
|
|
|
// layer as well so that the component can be edited with the silkscreen layer
|
2018-01-04 22:39:36 +00:00
|
|
|
bool f_silk = false, b_silk = false, non_silk = false;
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
for( BOARD_ITEM* item : m_drawings )
|
2018-01-04 22:39:36 +00:00
|
|
|
{
|
|
|
|
if( item->GetLayer() == F_SilkS )
|
|
|
|
f_silk = true;
|
|
|
|
else if( item->GetLayer() == B_SilkS )
|
|
|
|
b_silk = true;
|
|
|
|
else
|
|
|
|
non_silk = true;
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
if( ( f_silk || b_silk ) && !non_silk && m_pads.empty() )
|
2018-01-04 22:39:36 +00:00
|
|
|
{
|
|
|
|
if( f_silk )
|
|
|
|
aLayers[ aCount++ ] = F_SilkS;
|
|
|
|
|
|
|
|
if( b_silk )
|
|
|
|
aLayers[ aCount++ ] = B_SilkS;
|
|
|
|
}
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
double FOOTPRINT::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
int layer = ( m_layer == F_Cu ) ? LAYER_MOD_FR :
|
|
|
|
( m_layer == B_Cu ) ? LAYER_MOD_BK : LAYER_ANCHOR;
|
2016-06-07 13:07:47 +00:00
|
|
|
|
2020-08-30 21:20:37 +00:00
|
|
|
// Currently this is only pertinent for the anchor layer; everything else is drawn from the
|
|
|
|
// children.
|
2020-09-21 15:03:08 +00:00
|
|
|
// The "good" value is experimentally chosen.
|
|
|
|
#define MINIMAL_ZOOM_LEVEL_FOR_VISIBILITY 1.5
|
2020-09-21 06:56:53 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
if( aView->IsLayerVisible( layer ) )
|
2020-09-21 06:56:53 +00:00
|
|
|
return MINIMAL_ZOOM_LEVEL_FOR_VISIBILITY;
|
2016-06-07 13:07:47 +00:00
|
|
|
|
2020-09-21 15:03:08 +00:00
|
|
|
return std::numeric_limits<double>::max();
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
2015-06-16 15:03:36 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
const BOX2I FOOTPRINT::ViewBBox() const
|
2014-11-13 16:32:59 +00:00
|
|
|
{
|
2018-06-12 15:37:02 +00:00
|
|
|
EDA_RECT area = GetFootprintRect();
|
|
|
|
|
|
|
|
// Calculate extended area including text fields
|
2020-11-13 02:57:11 +00:00
|
|
|
area.Merge( m_reference->GetBoundingBox() );
|
|
|
|
area.Merge( m_value->GetBoundingBox() );
|
2018-06-12 15:37:02 +00:00
|
|
|
|
2020-08-30 21:20:37 +00:00
|
|
|
// Add the Clearance shape size: (shape around the pads when the clearance is shown. Not
|
|
|
|
// optimized, but the draw cost is small (perhaps smaller than optimization).
|
2018-06-12 15:37:02 +00:00
|
|
|
BOARD* board = GetBoard();
|
2020-12-05 18:03:03 +00:00
|
|
|
|
2018-06-12 15:37:02 +00:00
|
|
|
if( board )
|
|
|
|
{
|
|
|
|
int biggest_clearance = board->GetDesignSettings().GetBiggestClearanceValue();
|
|
|
|
area.Inflate( biggest_clearance );
|
|
|
|
}
|
|
|
|
|
2018-01-30 06:45:53 +00:00
|
|
|
return area;
|
2014-11-13 16:32:59 +00:00
|
|
|
}
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2015-06-16 15:03:36 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
bool FOOTPRINT::IsLibNameValid( const wxString & aName )
|
2012-12-10 11:18:42 +00:00
|
|
|
{
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
const wxChar * invalids = StringLibNameInvalidChars( false );
|
2012-12-10 11:18:42 +00:00
|
|
|
|
|
|
|
if( aName.find_first_of( invalids ) != std::string::npos )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
const wxChar* FOOTPRINT::StringLibNameInvalidChars( bool aUserReadable )
|
2012-12-10 11:18:42 +00:00
|
|
|
{
|
2019-06-29 20:31:11 +00:00
|
|
|
// This list of characters is also duplicated in validators.cpp and
|
|
|
|
// lib_id.cpp
|
|
|
|
// TODO: Unify forbidden character lists
|
|
|
|
static const wxChar invalidChars[] = wxT("%$<>\t\n\r\"\\/:");
|
|
|
|
static const wxChar invalidCharsReadable[] = wxT("% $ < > 'tab' 'return' 'line feed' \\ \" / :");
|
2012-12-10 11:18:42 +00:00
|
|
|
|
|
|
|
if( aUserReadable )
|
|
|
|
return invalidCharsReadable;
|
|
|
|
else
|
|
|
|
return invalidChars;
|
|
|
|
}
|
|
|
|
|
2012-01-14 19:50:32 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::Move( const wxPoint& aMoveVector )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
wxPoint newpos = m_pos + aMoveVector;
|
2013-03-13 18:53:58 +00:00
|
|
|
SetPosition( newpos );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::Rotate( const wxPoint& aRotCentre, double aAngle )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
2019-04-07 21:09:50 +00:00
|
|
|
double orientation = GetOrientation();
|
|
|
|
double newOrientation = orientation + aAngle;
|
2020-11-13 02:57:11 +00:00
|
|
|
wxPoint newpos = m_pos;
|
2013-03-13 18:53:58 +00:00
|
|
|
RotatePoint( &newpos, aRotCentre, aAngle );
|
|
|
|
SetPosition( newpos );
|
2019-04-07 21:09:50 +00:00
|
|
|
SetOrientation( newOrientation );
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
m_reference->KeepUpright( orientation, newOrientation );
|
|
|
|
m_value->KeepUpright( orientation, newOrientation );
|
2019-04-07 21:09:50 +00:00
|
|
|
|
2020-06-27 18:01:00 +00:00
|
|
|
for( BOARD_ITEM* item : m_drawings )
|
2019-04-07 21:09:50 +00:00
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
if( item->Type() == PCB_FP_TEXT_T )
|
2020-10-04 23:34:59 +00:00
|
|
|
static_cast<FP_TEXT*>( item )->KeepUpright( orientation, newOrientation );
|
2019-04-07 21:09:50 +00:00
|
|
|
}
|
2020-10-27 13:18:29 +00:00
|
|
|
|
|
|
|
CalculateBoundingBox();
|
2013-03-13 18:53:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
2020-10-14 23:37:26 +00:00
|
|
|
// Move footprint to its final position:
|
2020-11-13 02:57:11 +00:00
|
|
|
wxPoint finalPos = m_pos;
|
2019-07-12 21:02:10 +00:00
|
|
|
|
2019-09-17 16:51:27 +00:00
|
|
|
// Now Flip the footprint.
|
2020-11-13 02:57:11 +00:00
|
|
|
// Flipping a footprint is a specific transform: it is not mirrored like a text.
|
|
|
|
// We have to change the side, and ensure the footprint rotation is modified according to the
|
|
|
|
// transform, because this parameter is used in pick and place files, and when updating the
|
|
|
|
// footprint from library.
|
2019-09-17 16:51:27 +00:00
|
|
|
// When flipped around the X axis (Y coordinates changed) orientation is negated
|
|
|
|
// When flipped around the Y axis (X coordinates changed) orientation is 180 - old orient.
|
|
|
|
// Because it is specfic to a footprint, we flip around the X axis, and after rotate 180 deg
|
|
|
|
|
|
|
|
MIRROR( finalPos.y, aCentre.y ); /// Mirror the Y position (around the X axis)
|
2019-07-12 21:02:10 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
SetPosition( finalPos );
|
|
|
|
|
|
|
|
// Flip layer
|
2013-04-05 19:04:58 +00:00
|
|
|
SetLayer( FlipLayer( GetLayer() ) );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
|
|
|
// Reverse mirror orientation.
|
2020-11-13 02:57:11 +00:00
|
|
|
m_orient = -m_orient;
|
2019-09-17 16:51:27 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
NORMALIZE_ANGLE_180( m_orient );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2019-07-12 21:02:10 +00:00
|
|
|
// Mirror pads to other side of board.
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2020-11-13 02:57:11 +00:00
|
|
|
pad->Flip( m_pos, false );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2019-10-29 10:09:54 +00:00
|
|
|
// Mirror zones to other side of board.
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : m_fp_zones )
|
2020-11-13 02:57:11 +00:00
|
|
|
zone->Flip( m_pos, aFlipLeftRight );
|
2019-10-29 10:09:54 +00:00
|
|
|
|
2015-07-31 19:04:30 +00:00
|
|
|
// Mirror reference and value.
|
2020-11-13 02:57:11 +00:00
|
|
|
m_reference->Flip( m_pos, false );
|
|
|
|
m_value->Flip( m_pos, false );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
// Reverse mirror footprint graphics and texts.
|
2020-10-14 23:37:26 +00:00
|
|
|
for( BOARD_ITEM* item : m_drawings )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
2020-11-13 02:57:11 +00:00
|
|
|
static_cast<FP_SHAPE*>( item )->Flip( m_pos, false );
|
2013-03-13 18:53:58 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2020-11-13 02:57:11 +00:00
|
|
|
static_cast<FP_TEXT*>( item )->Flip( m_pos, false );
|
2013-03-13 18:53:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-11-13 21:07:01 +00:00
|
|
|
wxMessageBox( wxT( "FOOTPRINT::Flip() error: Unknown Draw Type" ) );
|
2013-03-13 18:53:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-17 16:51:27 +00:00
|
|
|
// Now rotate 180 deg if required
|
|
|
|
if( aFlipLeftRight )
|
|
|
|
Rotate( aCentre, 1800.0 );
|
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
CalculateBoundingBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::SetPosition( const wxPoint& aPos )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
wxPoint delta = aPos - m_pos;
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
m_pos += delta;
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
m_reference->EDA_TEXT::Offset( delta );
|
|
|
|
m_value->EDA_TEXT::Offset( delta );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2013-03-13 18:53:58 +00:00
|
|
|
pad->SetPosition( pad->GetPosition() + delta );
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : m_fp_zones )
|
2019-10-29 10:09:54 +00:00
|
|
|
zone->Move( delta );
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
for( BOARD_ITEM* item : m_drawings )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_SHAPE* shape = static_cast<FP_SHAPE*>( item );
|
|
|
|
shape->SetDrawCoord();
|
2013-03-13 18:53:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT* text = static_cast<FP_TEXT*>( item );
|
2017-01-23 20:30:11 +00:00
|
|
|
text->EDA_TEXT::Offset( delta );
|
2013-03-13 18:53:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxMessageBox( wxT( "Draw type undefined." ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
m_boundingBox.Move( delta );
|
2013-03-13 18:53:58 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::MoveAnchorPosition( const wxPoint& aMoveVector )
|
2013-03-23 13:30:00 +00:00
|
|
|
{
|
|
|
|
/* Move the reference point of the footprint
|
|
|
|
* the footprints elements (pads, outlines, edges .. ) are moved
|
|
|
|
* but:
|
|
|
|
* - the footprint position is not modified.
|
|
|
|
* - the relative (local) coordinates of these items are modified
|
2015-03-02 08:28:49 +00:00
|
|
|
* - Draw coordinates are updated
|
2013-03-23 13:30:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2015-03-02 08:28:49 +00:00
|
|
|
// Update (move) the relative coordinates relative to the new anchor point.
|
2013-03-23 13:30:00 +00:00
|
|
|
wxPoint moveVector = aMoveVector;
|
|
|
|
RotatePoint( &moveVector, -GetOrientation() );
|
|
|
|
|
|
|
|
// Update of the reference and value.
|
2020-11-13 02:57:11 +00:00
|
|
|
m_reference->SetPos0( m_reference->GetPos0() + moveVector );
|
|
|
|
m_reference->SetDrawCoord();
|
|
|
|
m_value->SetPos0( m_value->GetPos0() + moveVector );
|
|
|
|
m_value->SetDrawCoord();
|
2013-03-23 13:30:00 +00:00
|
|
|
|
|
|
|
// Update the pad local coordinates.
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2013-03-23 13:30:00 +00:00
|
|
|
{
|
|
|
|
pad->SetPos0( pad->GetPos0() + moveVector );
|
2015-02-27 14:33:13 +00:00
|
|
|
pad->SetDrawCoord();
|
2013-03-23 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the draw element coordinates.
|
2020-10-03 11:16:29 +00:00
|
|
|
for( BOARD_ITEM* item : GraphicalItems() )
|
2013-03-23 13:30:00 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
2018-03-12 12:17:22 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_SHAPE* shape = static_cast<FP_SHAPE*>( item );
|
|
|
|
shape->Move( moveVector );
|
2018-03-12 12:17:22 +00:00
|
|
|
}
|
2014-11-15 19:06:05 +00:00
|
|
|
break;
|
2013-03-23 13:30:00 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2018-07-22 12:50:35 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT* text = static_cast<FP_TEXT*>( item );
|
2014-11-15 19:06:05 +00:00
|
|
|
text->SetPos0( text->GetPos0() + moveVector );
|
|
|
|
text->SetDrawCoord();
|
2018-07-22 12:50:35 +00:00
|
|
|
}
|
2014-11-15 19:06:05 +00:00
|
|
|
break;
|
2013-03-23 13:30:00 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CalculateBoundingBox();
|
|
|
|
}
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::SetOrientation( double aNewAngle )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
double angleChange = aNewAngle - m_orient; // change in rotation
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2020-09-14 00:15:46 +00:00
|
|
|
NORMALIZE_ANGLE_180( aNewAngle );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
m_orient = aNewAngle;
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
|
|
|
pad->SetOrientation( pad->GetOrientation() + angleChange );
|
2015-02-27 14:33:13 +00:00
|
|
|
pad->SetDrawCoord();
|
2013-03-13 18:53:58 +00:00
|
|
|
}
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : m_fp_zones )
|
2019-10-29 10:09:54 +00:00
|
|
|
{
|
|
|
|
zone->Rotate( GetPosition(), angleChange );
|
|
|
|
}
|
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
// Update of the reference and value.
|
2020-11-13 02:57:11 +00:00
|
|
|
m_reference->SetDrawCoord();
|
|
|
|
m_value->SetDrawCoord();
|
2013-03-13 18:53:58 +00:00
|
|
|
|
|
|
|
// Displace contours and text of the footprint.
|
2020-10-03 11:16:29 +00:00
|
|
|
for( BOARD_ITEM* item : m_drawings )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
if( item->Type() == PCB_FP_SHAPE_T )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
static_cast<FP_SHAPE*>( item )->SetDrawCoord();
|
2013-03-13 18:53:58 +00:00
|
|
|
}
|
2020-10-04 14:19:33 +00:00
|
|
|
else if( item->Type() == PCB_FP_TEXT_T )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
static_cast<FP_TEXT*>( item )->SetDrawCoord();
|
2013-03-13 18:53:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 07:59:05 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
BOARD_ITEM* FOOTPRINT::Duplicate() const
|
2020-08-10 13:22:02 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* dupe = (FOOTPRINT*) Clone();
|
2020-08-10 13:22:02 +00:00
|
|
|
const_cast<KIID&>( dupe->m_Uuid ) = KIID();
|
|
|
|
|
|
|
|
dupe->RunOnChildren( [&]( BOARD_ITEM* child )
|
|
|
|
{
|
|
|
|
const_cast<KIID&>( child->m_Uuid ) = KIID();
|
|
|
|
});
|
|
|
|
|
|
|
|
return static_cast<BOARD_ITEM*>( dupe );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
BOARD_ITEM* FOOTPRINT::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToFootprint )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
|
|
|
BOARD_ITEM* new_item = NULL;
|
2020-11-11 23:05:59 +00:00
|
|
|
FP_ZONE* new_zone = NULL;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* new_pad = new PAD( *static_cast<const PAD*>( aItem ) );
|
2020-08-10 13:22:02 +00:00
|
|
|
const_cast<KIID&>( new_pad->m_Uuid ) = KIID();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( aAddToFootprint )
|
2019-06-01 23:23:36 +00:00
|
|
|
m_pads.push_back( new_pad );
|
2016-05-11 08:17:34 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
new_item = new_pad;
|
|
|
|
break;
|
|
|
|
}
|
2016-03-07 07:13:06 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_FP_ZONE_T:
|
2019-10-29 10:09:54 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
new_zone = new FP_ZONE( *static_cast<const FP_ZONE*>( aItem ) );
|
2020-08-10 13:22:02 +00:00
|
|
|
const_cast<KIID&>( new_zone->m_Uuid ) = KIID();
|
2019-10-29 10:09:54 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( aAddToFootprint )
|
2019-10-26 15:49:29 +00:00
|
|
|
m_fp_zones.push_back( new_zone );
|
2019-10-29 10:09:54 +00:00
|
|
|
|
|
|
|
new_item = new_zone;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT* new_text = new FP_TEXT( *static_cast<const FP_TEXT*>( aItem ) );
|
2020-08-10 13:22:02 +00:00
|
|
|
const_cast<KIID&>( new_text->m_Uuid ) = KIID();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
if( new_text->GetType() == FP_TEXT::TEXT_is_REFERENCE )
|
2020-02-02 23:46:26 +00:00
|
|
|
{
|
2020-03-26 11:02:59 +00:00
|
|
|
new_text->SetText( wxT( "${REFERENCE}" ) );
|
2020-10-04 23:34:59 +00:00
|
|
|
new_text->SetType( FP_TEXT::TEXT_is_DIVERS );
|
2020-02-02 23:46:26 +00:00
|
|
|
}
|
2020-10-04 23:34:59 +00:00
|
|
|
else if( new_text->GetType() == FP_TEXT::TEXT_is_VALUE )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2020-03-26 11:02:59 +00:00
|
|
|
new_text->SetText( wxT( "${VALUE}" ) );
|
2020-10-04 23:34:59 +00:00
|
|
|
new_text->SetType( FP_TEXT::TEXT_is_DIVERS );
|
2020-02-02 23:46:26 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( aAddToFootprint )
|
2020-02-02 23:46:26 +00:00
|
|
|
Add( new_text );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2020-02-02 23:46:26 +00:00
|
|
|
new_item = new_text;
|
2016-05-11 08:17:34 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-03-07 07:13:06 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_SHAPE* new_shape = new FP_SHAPE( *static_cast<const FP_SHAPE*>( aItem ) );
|
|
|
|
const_cast<KIID&>( new_shape->m_Uuid ) = KIID();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( aAddToFootprint )
|
2020-10-04 23:34:59 +00:00
|
|
|
Add( new_shape );
|
2016-05-11 08:17:34 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
new_item = new_shape;
|
2015-02-12 03:22:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-03-07 07:13:06 +00:00
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
case PCB_GROUP_T:
|
|
|
|
new_item = static_cast<const PCB_GROUP*>( aItem )->DeepDuplicate();
|
|
|
|
break;
|
|
|
|
|
2020-11-13 12:21:02 +00:00
|
|
|
case PCB_FOOTPRINT_T:
|
2020-10-14 23:37:26 +00:00
|
|
|
// Ignore the footprint itself
|
2015-02-12 03:22:24 +00:00
|
|
|
break;
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
default:
|
|
|
|
// Un-handled item for duplication
|
2020-02-02 23:46:26 +00:00
|
|
|
wxFAIL_MSG( "Duplication not supported for items of class " + aItem->GetClass() );
|
2015-02-12 03:22:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_item;
|
|
|
|
}
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
wxString FOOTPRINT::GetNextPadName( const wxString& aLastPadName ) const
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2020-05-03 07:59:05 +00:00
|
|
|
std::set<wxString> usedNames;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
// Create a set of used pad numbers
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_pads )
|
2020-05-03 07:59:05 +00:00
|
|
|
usedNames.insert( pad->GetName() );
|
|
|
|
|
|
|
|
wxString prefix = UTIL::GetReferencePrefix( aLastPadName );
|
|
|
|
int num = GetTrailingInt( aLastPadName );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2020-05-03 07:59:05 +00:00
|
|
|
while( usedNames.count( wxString::Format( "%s%d", prefix, num ) ) )
|
|
|
|
num++;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2020-05-03 07:59:05 +00:00
|
|
|
return wxString::Format( "%s%d", prefix, num );
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::IncrementReference( int aDelta )
|
2018-07-24 18:41:08 +00:00
|
|
|
{
|
2020-10-14 23:37:26 +00:00
|
|
|
const wxString& refdes = GetReference();
|
|
|
|
|
|
|
|
SetReference( wxString::Format( wxT( "%s%i" ),
|
|
|
|
UTIL::GetReferencePrefix( refdes ),
|
|
|
|
GetTrailingInt( refdes ) + aDelta ) );
|
2018-07-24 18:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-31 16:46:38 +00:00
|
|
|
// Calculate the area of aPolySet, after fracturation, because
|
|
|
|
// polygons with no hole are expected.
|
|
|
|
static double polygonArea( SHAPE_POLY_SET& aPolySet )
|
2017-12-22 00:49:35 +00:00
|
|
|
{
|
|
|
|
double area = 0.0;
|
2020-10-14 23:37:26 +00:00
|
|
|
|
2017-12-31 16:46:38 +00:00
|
|
|
for( int ii = 0; ii < aPolySet.OutlineCount(); ii++ )
|
2017-12-22 00:49:35 +00:00
|
|
|
{
|
2017-12-31 16:46:38 +00:00
|
|
|
SHAPE_LINE_CHAIN& outline = aPolySet.Outline( ii );
|
|
|
|
// Ensure the curr outline is closed, to calculate area
|
|
|
|
outline.SetClosed( true );
|
|
|
|
|
|
|
|
area += outline.Area();
|
|
|
|
}
|
|
|
|
|
2017-12-22 00:49:35 +00:00
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:04:30 +00:00
|
|
|
|
|
|
|
double FOOTPRINT::GetCoverageArea( const BOARD_ITEM* aItem, const GENERAL_COLLECTOR& aCollector )
|
2017-12-31 16:46:38 +00:00
|
|
|
{
|
2020-11-27 18:04:30 +00:00
|
|
|
int textMargin = KiROUND( 5 * aCollector.GetGuide()->OnePixelInIU() );
|
|
|
|
SHAPE_POLY_SET poly;
|
|
|
|
|
2020-11-29 14:00:39 +00:00
|
|
|
if( aItem->Type() == PCB_MARKER_T )
|
|
|
|
{
|
|
|
|
const PCB_MARKER* marker = static_cast<const PCB_MARKER*>( aItem );
|
|
|
|
SHAPE_LINE_CHAIN markerShape;
|
|
|
|
|
|
|
|
marker->ShapeToPolygon( markerShape );
|
|
|
|
return markerShape.Area();
|
|
|
|
}
|
2020-12-01 14:03:34 +00:00
|
|
|
else if( aItem->Type() == PCB_GROUP_T )
|
|
|
|
{
|
|
|
|
double combinedArea = 0.0;
|
|
|
|
|
|
|
|
for( BOARD_ITEM* member : static_cast<const PCB_GROUP*>( aItem )->GetItems() )
|
|
|
|
combinedArea += GetCoverageArea( member, aCollector );
|
|
|
|
|
|
|
|
return combinedArea;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aItem->Type() == PCB_FOOTPRINT_T )
|
2020-11-27 18:04:30 +00:00
|
|
|
{
|
|
|
|
const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( aItem );
|
|
|
|
|
2020-11-29 14:00:39 +00:00
|
|
|
poly = footprint->GetBoundingHull();
|
2020-11-27 18:04:30 +00:00
|
|
|
}
|
|
|
|
else if( aItem->Type() == PCB_FP_TEXT_T )
|
|
|
|
{
|
|
|
|
const FP_TEXT* text = static_cast<const FP_TEXT*>( aItem );
|
|
|
|
|
|
|
|
text->TransformTextShapeWithClearanceToPolygon( poly, UNDEFINED_LAYER, textMargin,
|
|
|
|
ARC_LOW_DEF, ERROR_OUTSIDE );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aItem->TransformShapeWithClearanceToPolygon( poly, UNDEFINED_LAYER, 0,
|
|
|
|
ARC_LOW_DEF, ERROR_OUTSIDE );
|
|
|
|
}
|
2017-12-22 00:49:35 +00:00
|
|
|
|
2020-11-27 18:04:30 +00:00
|
|
|
poly.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
poly.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
return polygonArea( poly );
|
2017-12-31 16:46:38 +00:00
|
|
|
}
|
2017-12-22 00:49:35 +00:00
|
|
|
|
2020-11-27 18:04:30 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
double FOOTPRINT::CoverageRatio( const GENERAL_COLLECTOR& aCollector ) const
|
2015-02-17 23:58:14 +00:00
|
|
|
{
|
2020-11-27 18:04:30 +00:00
|
|
|
int textMargin = KiROUND( 5 * aCollector.GetGuide()->OnePixelInIU() );
|
2015-02-17 23:58:14 +00:00
|
|
|
|
2020-11-29 14:00:39 +00:00
|
|
|
SHAPE_POLY_SET footprintRegion( GetBoundingHull() );
|
2020-11-27 18:04:30 +00:00
|
|
|
SHAPE_POLY_SET coveredRegion;
|
2018-02-22 10:10:48 +00:00
|
|
|
|
2020-11-27 18:04:30 +00:00
|
|
|
TransformPadsWithClearanceToPolygon( coveredRegion, UNDEFINED_LAYER, 0, ARC_LOW_DEF,
|
|
|
|
ERROR_OUTSIDE );
|
2015-02-17 23:58:14 +00:00
|
|
|
|
2020-11-27 18:04:30 +00:00
|
|
|
TransformFPShapesWithClearanceToPolygon( coveredRegion, UNDEFINED_LAYER, textMargin,
|
|
|
|
ARC_LOW_DEF, ERROR_OUTSIDE,
|
|
|
|
true, /* include text */
|
|
|
|
false /* include shapes */ );
|
2015-02-17 23:58:14 +00:00
|
|
|
|
2018-02-22 10:10:48 +00:00
|
|
|
for( int i = 0; i < aCollector.GetCount(); ++i )
|
|
|
|
{
|
2020-11-27 18:04:30 +00:00
|
|
|
const BOARD_ITEM* item = aCollector[i];
|
2018-02-22 10:10:48 +00:00
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2020-11-27 18:04:30 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
|
|
|
if( item->GetParent() != this )
|
|
|
|
{
|
2020-11-29 14:00:39 +00:00
|
|
|
item->TransformShapeWithClearanceToPolygon( coveredRegion, UNDEFINED_LAYER, 0,
|
2020-11-27 18:04:30 +00:00
|
|
|
ARC_LOW_DEF, ERROR_OUTSIDE );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TEXT_T:
|
|
|
|
case PCB_SHAPE_T:
|
2018-02-22 10:10:48 +00:00
|
|
|
case PCB_TRACE_T:
|
2019-05-17 00:13:21 +00:00
|
|
|
case PCB_ARC_T:
|
2018-02-22 10:10:48 +00:00
|
|
|
case PCB_VIA_T:
|
2020-11-29 14:00:39 +00:00
|
|
|
item->TransformShapeWithClearanceToPolygon( coveredRegion, UNDEFINED_LAYER, 0,
|
2020-11-27 18:04:30 +00:00
|
|
|
ARC_LOW_DEF, ERROR_OUTSIDE );
|
2018-02-22 10:10:48 +00:00
|
|
|
break;
|
2020-11-27 18:04:30 +00:00
|
|
|
|
2020-11-29 14:00:39 +00:00
|
|
|
case PCB_FOOTPRINT_T:
|
|
|
|
if( item != this )
|
|
|
|
{
|
|
|
|
const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( item );
|
|
|
|
coveredRegion.AddOutline( footprint->GetBoundingHull().Outline( 0 ) );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-02-22 10:10:48 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-31 16:46:38 +00:00
|
|
|
SHAPE_POLY_SET uncoveredRegion;
|
2020-01-12 21:07:41 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-11-27 18:04:30 +00:00
|
|
|
uncoveredRegion.BooleanSubtract( footprintRegion, coveredRegion,
|
|
|
|
SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2020-01-12 21:07:41 +00:00
|
|
|
uncoveredRegion.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
uncoveredRegion.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
}
|
|
|
|
catch( ClipperLib::clipperException& )
|
|
|
|
{
|
|
|
|
// better to be conservative (this will result in the disambiguate dialog)
|
|
|
|
return 1.0;
|
|
|
|
}
|
2015-02-17 23:58:14 +00:00
|
|
|
|
2020-11-27 18:04:30 +00:00
|
|
|
double footprintRegionArea = polygonArea( footprintRegion );
|
2017-12-31 16:46:38 +00:00
|
|
|
double uncoveredRegionArea = polygonArea( uncoveredRegion );
|
2020-11-27 18:04:30 +00:00
|
|
|
double coveredArea = footprintRegionArea - uncoveredRegionArea;
|
|
|
|
double ratio = ( coveredArea / footprintRegionArea );
|
2017-12-31 16:46:38 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
return std::min( ratio, 1.0 );
|
2015-02-17 23:58:14 +00:00
|
|
|
}
|
2017-03-16 17:09:33 +00:00
|
|
|
|
2017-12-22 00:49:35 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
std::shared_ptr<SHAPE> FOOTPRINT::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
|
2020-08-26 22:04:16 +00:00
|
|
|
{
|
2020-10-25 19:15:32 +00:00
|
|
|
std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
|
|
|
|
|
|
|
|
// There are several possible interpretations here:
|
|
|
|
// 1) the bounding box (without or without invisible items)
|
2020-10-25 20:18:33 +00:00
|
|
|
// 2) just the pads and "edges" (ie: non-text graphic items)
|
2020-10-25 19:15:32 +00:00
|
|
|
// 3) the courtyard
|
|
|
|
|
|
|
|
// We'll go with (2) for now....
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : Pads() )
|
2020-10-25 23:38:21 +00:00
|
|
|
shape->AddShape( pad->GetEffectiveShape( aLayer )->Clone() );
|
2020-10-25 19:15:32 +00:00
|
|
|
|
|
|
|
for( BOARD_ITEM* item : GraphicalItems() )
|
2020-10-25 20:18:33 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == PCB_FP_SHAPE_T )
|
2020-10-25 23:38:21 +00:00
|
|
|
shape->AddShape( item->GetEffectiveShape( aLayer )->Clone() );
|
2020-10-25 20:18:33 +00:00
|
|
|
}
|
2020-08-26 22:04:16 +00:00
|
|
|
|
|
|
|
return shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-21 20:42:27 +00:00
|
|
|
void FOOTPRINT::BuildPolyCourtyards( OUTLINE_ERROR_HANDLER* aErrorHandler )
|
2017-03-16 17:09:33 +00:00
|
|
|
{
|
2017-03-19 15:38:30 +00:00
|
|
|
m_poly_courtyard_front.RemoveAllContours();
|
|
|
|
m_poly_courtyard_back.RemoveAllContours();
|
2020-11-20 13:55:10 +00:00
|
|
|
ClearFlags( MALFORMED_COURTYARDS );
|
2020-10-25 15:02:49 +00:00
|
|
|
|
2017-03-16 17:09:33 +00:00
|
|
|
// Build the courtyard area from graphic items on the courtyard.
|
2020-10-04 14:19:33 +00:00
|
|
|
// Only PCB_FP_SHAPE_T have meaning, graphic texts are ignored.
|
2017-03-16 17:09:33 +00:00
|
|
|
// Collect items:
|
2020-10-04 23:34:59 +00:00
|
|
|
std::vector<PCB_SHAPE*> list_front;
|
|
|
|
std::vector<PCB_SHAPE*> list_back;
|
2017-03-16 17:09:33 +00:00
|
|
|
|
2020-08-15 12:10:23 +00:00
|
|
|
for( BOARD_ITEM* item : GraphicalItems() )
|
2017-03-16 17:09:33 +00:00
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
if( item->GetLayer() == B_CrtYd && item->Type() == PCB_FP_SHAPE_T )
|
2020-10-04 23:34:59 +00:00
|
|
|
list_back.push_back( static_cast<PCB_SHAPE*>( item ) );
|
2017-03-16 17:09:33 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( item->GetLayer() == F_CrtYd && item->Type() == PCB_FP_SHAPE_T )
|
2020-10-04 23:34:59 +00:00
|
|
|
list_front.push_back( static_cast<PCB_SHAPE*>( item ) );
|
2017-03-16 17:09:33 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 15:38:30 +00:00
|
|
|
if( !list_front.size() && !list_back.size() )
|
2020-10-25 15:02:49 +00:00
|
|
|
return;
|
2017-03-16 17:09:33 +00:00
|
|
|
|
2020-11-21 20:42:27 +00:00
|
|
|
constexpr int errorMax = Millimeter2iu( 0.02 ); /* error max for polygonization */
|
2017-03-16 17:09:33 +00:00
|
|
|
|
2020-11-21 20:42:27 +00:00
|
|
|
if( !ConvertOutlineToPolygon( list_front, m_poly_courtyard_front, errorMax, aErrorHandler ) )
|
2020-11-20 13:55:10 +00:00
|
|
|
SetFlags( MALFORMED_F_COURTYARD );
|
2017-03-20 12:05:38 +00:00
|
|
|
|
2020-11-21 20:42:27 +00:00
|
|
|
if( !ConvertOutlineToPolygon( list_back, m_poly_courtyard_back, errorMax, aErrorHandler ) )
|
2020-11-20 13:55:10 +00:00
|
|
|
SetFlags( MALFORMED_B_COURTYARD );
|
2017-03-16 17:09:33 +00:00
|
|
|
}
|
2017-10-31 13:59:03 +00:00
|
|
|
|
2019-09-15 09:10:53 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT::SwapData( BOARD_ITEM* aImage )
|
2017-10-31 13:59:03 +00:00
|
|
|
{
|
2020-11-13 12:21:02 +00:00
|
|
|
assert( aImage->Type() == PCB_FOOTPRINT_T );
|
2017-10-31 13:59:03 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
std::swap( *((FOOTPRINT*) this), *((FOOTPRINT*) aImage) );
|
2017-10-31 13:59:03 +00:00
|
|
|
}
|
2019-09-15 09:10:53 +00:00
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
bool FOOTPRINT::HasThroughHolePads() const
|
2019-09-15 09:10:53 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : Pads() )
|
2019-09-15 09:10:53 +00:00
|
|
|
{
|
|
|
|
if( pad->GetAttribute() != PAD_ATTRIB_SMD )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-02 18:40:14 +00:00
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
bool FOOTPRINT::cmp_drawings::operator()( const BOARD_ITEM* aFirst,
|
|
|
|
const BOARD_ITEM* aSecond ) const
|
2020-07-24 22:08:36 +00:00
|
|
|
{
|
|
|
|
if( aFirst->Type() != aSecond->Type() )
|
|
|
|
return aFirst->Type() < aSecond->Type();
|
|
|
|
|
|
|
|
if( aFirst->GetLayer() != aSecond->GetLayer() )
|
|
|
|
return aFirst->GetLayer() < aSecond->GetLayer();
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( aFirst->Type() == PCB_FP_SHAPE_T )
|
2020-07-24 22:08:36 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
const FP_SHAPE* dwgA = static_cast<const FP_SHAPE*>( aFirst );
|
|
|
|
const FP_SHAPE* dwgB = static_cast<const FP_SHAPE*>( aSecond );
|
2020-07-24 22:08:36 +00:00
|
|
|
|
|
|
|
if( dwgA->GetShape() != dwgB->GetShape() )
|
|
|
|
return dwgA->GetShape() < dwgB->GetShape();
|
|
|
|
}
|
|
|
|
|
2020-10-11 17:02:38 +00:00
|
|
|
if( aFirst->m_Uuid != aSecond->m_Uuid ) // shopuld be always the case foer valid boards
|
|
|
|
return aFirst->m_Uuid < aSecond->m_Uuid;
|
|
|
|
|
|
|
|
return aFirst < aSecond;
|
2020-07-24 22:08:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
bool FOOTPRINT::cmp_pads::operator()( const PAD* aFirst, const PAD* aSecond ) const
|
2020-07-24 22:08:36 +00:00
|
|
|
{
|
|
|
|
if( aFirst->GetName() != aSecond->GetName() )
|
|
|
|
return StrNumCmp( aFirst->GetName(), aSecond->GetName() ) < 0;
|
|
|
|
|
2020-10-11 17:02:38 +00:00
|
|
|
if( aFirst->m_Uuid != aSecond->m_Uuid ) // shopuld be always the case foer valid boards
|
|
|
|
return aFirst->m_Uuid < aSecond->m_Uuid;
|
|
|
|
|
|
|
|
return aFirst < aSecond;
|
2020-07-24 22:08:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-14 19:16:42 +00:00
|
|
|
static struct FOOTPRINT_DESC
|
2020-02-02 18:40:14 +00:00
|
|
|
{
|
2020-11-14 19:16:42 +00:00
|
|
|
FOOTPRINT_DESC()
|
2020-02-02 18:40:14 +00:00
|
|
|
{
|
2020-08-18 21:42:56 +00:00
|
|
|
ENUM_MAP<PCB_LAYER_ID>& layerEnum = ENUM_MAP<PCB_LAYER_ID>::Instance();
|
|
|
|
|
|
|
|
if( layerEnum.Choices().GetCount() == 0 )
|
|
|
|
{
|
|
|
|
layerEnum.Undefined( UNDEFINED_LAYER );
|
|
|
|
|
|
|
|
for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
|
|
|
|
layerEnum.Map( *seq, LSET::Name( *seq ) );
|
|
|
|
}
|
|
|
|
|
2020-02-05 15:04:12 +00:00
|
|
|
wxPGChoices fpLayers; // footprints might be placed only on F.Cu & B.Cu
|
|
|
|
fpLayers.Add( LSET::Name( F_Cu ), F_Cu );
|
|
|
|
fpLayers.Add( LSET::Name( B_Cu ), B_Cu );
|
|
|
|
|
2020-02-02 18:40:14 +00:00
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
2020-11-13 15:15:52 +00:00
|
|
|
REGISTER_TYPE( FOOTPRINT );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<FOOTPRINT, BOARD_ITEM> );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<FOOTPRINT, BOARD_ITEM_CONTAINER> );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( FOOTPRINT ), TYPE_HASH( BOARD_ITEM ) );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( FOOTPRINT ), TYPE_HASH( BOARD_ITEM_CONTAINER ) );
|
|
|
|
|
|
|
|
auto layer = new PROPERTY_ENUM<FOOTPRINT, PCB_LAYER_ID, BOARD_ITEM>( _HKI( "Layer" ),
|
|
|
|
&FOOTPRINT::SetLayer, &FOOTPRINT::GetLayer );
|
2020-02-05 15:04:12 +00:00
|
|
|
layer->SetChoices( fpLayers );
|
2020-10-16 15:51:24 +00:00
|
|
|
propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ), layer );
|
2020-02-05 15:04:12 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<FOOTPRINT, wxString>( _HKI( "Reference" ),
|
|
|
|
&FOOTPRINT::SetReference, &FOOTPRINT::GetReference ) );
|
|
|
|
propMgr.AddProperty( new PROPERTY<FOOTPRINT, wxString>( _HKI( "Value" ),
|
|
|
|
&FOOTPRINT::SetValue, &FOOTPRINT::GetValue ) );
|
|
|
|
propMgr.AddProperty( new PROPERTY<FOOTPRINT, double>( _HKI( "Orientation" ),
|
|
|
|
&FOOTPRINT::SetOrientationDegrees, &FOOTPRINT::GetOrientationDegrees,
|
2020-09-05 16:00:29 +00:00
|
|
|
PROPERTY_DISPLAY::DEGREE ) );
|
2020-11-13 15:15:52 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<FOOTPRINT, int>( _HKI( "Local Clearance" ),
|
|
|
|
&FOOTPRINT::SetLocalClearance, &FOOTPRINT::GetLocalClearance,
|
2020-09-05 16:00:29 +00:00
|
|
|
PROPERTY_DISPLAY::DISTANCE ) );
|
2020-11-13 15:15:52 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<FOOTPRINT, int>( _HKI( "Local Solderpaste Margin" ),
|
|
|
|
&FOOTPRINT::SetLocalSolderPasteMargin, &FOOTPRINT::GetLocalSolderPasteMargin,
|
2020-09-05 16:00:29 +00:00
|
|
|
PROPERTY_DISPLAY::DISTANCE ) );
|
2020-11-13 15:15:52 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<FOOTPRINT, double>( _HKI( "Local Solderpaste Margin Ratio" ),
|
|
|
|
&FOOTPRINT::SetLocalSolderPasteMarginRatio, &FOOTPRINT::GetLocalSolderPasteMarginRatio ) );
|
|
|
|
propMgr.AddProperty( new PROPERTY<FOOTPRINT, int>( _HKI( "Thermal Width" ),
|
|
|
|
&FOOTPRINT::SetThermalWidth, &FOOTPRINT::GetThermalWidth,
|
2020-09-05 16:00:29 +00:00
|
|
|
PROPERTY_DISPLAY::DISTANCE ) );
|
2020-11-13 15:15:52 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<FOOTPRINT, int>( _HKI( "Thermal Gap" ),
|
|
|
|
&FOOTPRINT::SetThermalGap, &FOOTPRINT::GetThermalGap,
|
2020-09-05 16:00:29 +00:00
|
|
|
PROPERTY_DISPLAY::DISTANCE ) );
|
2020-02-02 18:40:14 +00:00
|
|
|
// TODO zone connection, FPID?
|
|
|
|
}
|
2020-11-14 19:16:42 +00:00
|
|
|
} _FOOTPRINT_DESC;
|