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>
|
2019-01-13 21:20:29 +00:00
|
|
|
* Copyright (C) 1992-2019 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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
2018-01-28 18:12:26 +00:00
|
|
|
#include <plotter.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <trigo.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <pcbnew.h>
|
2019-01-29 10:50:50 +00:00
|
|
|
#include <refdes_utils.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <richio.h>
|
|
|
|
#include <filter_reader.h>
|
|
|
|
#include <macros.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <msgpanel.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2018-03-08 01:40:50 +00:00
|
|
|
#include <unordered_set>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_edge_mod.h>
|
|
|
|
#include <class_module.h>
|
2017-03-16 17:09:33 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2019-06-29 20:31:11 +00:00
|
|
|
#include <validators.h>
|
2016-12-02 17:58:12 +00:00
|
|
|
#include <view/view.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-02-19 00:30:10 +00:00
|
|
|
MODULE::MODULE( BOARD* parent ) :
|
2016-05-13 15:31:54 +00:00
|
|
|
BOARD_ITEM_CONTAINER( (BOARD_ITEM*) parent, PCB_MODULE_T ),
|
2013-06-23 19:18:33 +00:00
|
|
|
m_initial_comments( 0 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-06 02:02:39 +00:00
|
|
|
m_Attributs = MOD_DEFAULT;
|
2014-06-24 16:17:18 +00:00
|
|
|
m_Layer = F_Cu;
|
2007-08-06 02:02:39 +00:00
|
|
|
m_Orient = 0;
|
2015-02-17 23:58:14 +00:00
|
|
|
m_ModuleStatus = MODULE_PADS_LOCKED;
|
2015-03-23 08:28:12 +00:00
|
|
|
m_arflag = 0;
|
2007-08-06 02:02:39 +00:00
|
|
|
m_CntRot90 = m_CntRot180 = 0;
|
2009-11-04 19:08:08 +00:00
|
|
|
m_Link = 0;
|
2015-03-12 17:43:39 +00:00
|
|
|
m_LastEditTime = 0;
|
2009-11-04 19:08:08 +00:00
|
|
|
m_LocalClearance = 0;
|
|
|
|
m_LocalSolderMaskMargin = 0;
|
|
|
|
m_LocalSolderPasteMargin = 0;
|
|
|
|
m_LocalSolderPasteMarginRatio = 0.0;
|
2015-08-18 14:19:17 +00:00
|
|
|
m_ZoneConnection = PAD_ZONE_CONN_INHERITED; // Use zone setting by default
|
2015-02-18 09:13:17 +00:00
|
|
|
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
|
2013-04-07 11:55:18 +00:00
|
|
|
m_Reference = new TEXTE_MODULE( this, TEXTE_MODULE::TEXT_is_REFERENCE );
|
|
|
|
m_Value = new TEXTE_MODULE( this, TEXTE_MODULE::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
|
|
|
|
2012-01-14 19:50:32 +00:00
|
|
|
MODULE::MODULE( const MODULE& aModule ) :
|
2016-05-13 15:31:54 +00:00
|
|
|
BOARD_ITEM_CONTAINER( aModule )
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
|
|
|
m_Pos = aModule.m_Pos;
|
2013-09-08 18:31:21 +00:00
|
|
|
m_fpid = aModule.m_fpid;
|
2012-01-14 19:50:32 +00:00
|
|
|
m_Attributs = aModule.m_Attributs;
|
2012-01-30 13:25:46 +00:00
|
|
|
m_ModuleStatus = aModule.m_ModuleStatus;
|
2012-01-14 19:50:32 +00:00
|
|
|
m_Orient = aModule.m_Orient;
|
|
|
|
m_BoundaryBox = aModule.m_BoundaryBox;
|
|
|
|
m_CntRot90 = aModule.m_CntRot90;
|
|
|
|
m_CntRot180 = aModule.m_CntRot180;
|
2013-03-13 18:53:58 +00:00
|
|
|
m_LastEditTime = aModule.m_LastEditTime;
|
2012-01-14 19:50:32 +00:00
|
|
|
m_Link = aModule.m_Link;
|
2018-07-22 12:50:35 +00:00
|
|
|
m_Path = aModule.m_Path; // is this correct behavior?
|
2012-01-14 19:50:32 +00:00
|
|
|
|
|
|
|
m_LocalClearance = aModule.m_LocalClearance;
|
|
|
|
m_LocalSolderMaskMargin = aModule.m_LocalSolderMaskMargin;
|
|
|
|
m_LocalSolderPasteMargin = aModule.m_LocalSolderPasteMargin;
|
|
|
|
m_LocalSolderPasteMarginRatio = aModule.m_LocalSolderPasteMarginRatio;
|
2012-02-24 23:23:46 +00:00
|
|
|
m_ZoneConnection = aModule.m_ZoneConnection;
|
2012-03-08 20:44:03 +00:00
|
|
|
m_ThermalWidth = aModule.m_ThermalWidth;
|
|
|
|
m_ThermalGap = aModule.m_ThermalGap;
|
2012-01-14 19:50:32 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Copy reference and value.
|
2012-01-14 19:50:32 +00:00
|
|
|
m_Reference = new TEXTE_MODULE( *aModule.m_Reference );
|
|
|
|
m_Reference->SetParent( this );
|
|
|
|
m_Value = new TEXTE_MODULE( *aModule.m_Value );
|
|
|
|
m_Value->SetParent( this );
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Copy auxiliary data: Pads
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : aModule.Pads() )
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
2016-05-31 08:27:52 +00:00
|
|
|
Add( new D_PAD( *pad ) );
|
2012-01-14 19:50:32 +00:00
|
|
|
}
|
|
|
|
|
2019-10-29 10:09:54 +00:00
|
|
|
// Copy auxiliary data: Zones
|
|
|
|
for( auto item : aModule.Zones() )
|
|
|
|
{
|
2019-10-26 15:49:29 +00:00
|
|
|
Add( static_cast<MODULE_ZONE_CONTAINER*>( item->Clone() ) );
|
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.
|
|
|
|
item->SetNetCode( -1 );
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Copy auxiliary data: Drawings
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : aModule.GraphicalItems() )
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
case PCB_MODULE_EDGE_T:
|
2016-05-31 08:27:52 +00:00
|
|
|
Add( static_cast<BOARD_ITEM*>( item->Clone() ) );
|
2012-01-14 19:50:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-05-31 08:27:52 +00:00
|
|
|
wxLogMessage( wxT( "Class MODULE copy constructor internal error: unknown type" ) );
|
2012-01-14 19:50:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Copy auxiliary data: 3D_Drawings info
|
2016-07-19 17:35:25 +00:00
|
|
|
m_3D_Drawings = aModule.m_3D_Drawings;
|
2012-01-14 19:50:32 +00:00
|
|
|
|
|
|
|
m_Doc = aModule.m_Doc;
|
|
|
|
m_KeyWord = aModule.m_KeyWord;
|
2013-01-02 21:49:56 +00:00
|
|
|
|
2015-03-23 08:28:12 +00:00
|
|
|
m_arflag = 0;
|
|
|
|
|
2013-01-02 21:49:56 +00:00
|
|
|
// Ensure auxiliary data is up to date
|
|
|
|
CalculateBoundingBox();
|
2013-06-23 22:41:35 +00:00
|
|
|
|
|
|
|
m_initial_comments = aModule.m_initial_comments ?
|
|
|
|
new wxArrayString( *aModule.m_initial_comments ) : 0;
|
2012-01-14 19:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
MODULE::~MODULE()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2019-08-11 20:30:33 +00:00
|
|
|
// Clean up the owned elements
|
2007-08-06 02:02:39 +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
|
|
|
|
|
|
|
for( auto p : m_pads )
|
|
|
|
delete p;
|
|
|
|
|
|
|
|
m_pads.clear();
|
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
for( auto p : m_fp_zones )
|
2019-10-29 10:09:54 +00:00
|
|
|
delete p;
|
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
m_fp_zones.clear();
|
2019-10-29 10:09:54 +00:00
|
|
|
|
2019-08-11 20:30:33 +00:00
|
|
|
for( auto d : m_drawings )
|
|
|
|
delete d;
|
|
|
|
|
|
|
|
m_drawings.clear();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 08:27:52 +00:00
|
|
|
|
|
|
|
MODULE& MODULE::operator=( const MODULE& aOther )
|
|
|
|
{
|
|
|
|
BOARD_ITEM::operator=( aOther );
|
|
|
|
|
|
|
|
m_Pos = aOther.m_Pos;
|
|
|
|
m_fpid = aOther.m_fpid;
|
|
|
|
m_Attributs = aOther.m_Attributs;
|
|
|
|
m_ModuleStatus = aOther.m_ModuleStatus;
|
|
|
|
m_Orient = aOther.m_Orient;
|
|
|
|
m_BoundaryBox = aOther.m_BoundaryBox;
|
|
|
|
m_CntRot90 = aOther.m_CntRot90;
|
|
|
|
m_CntRot180 = aOther.m_CntRot180;
|
|
|
|
m_LastEditTime = aOther.m_LastEditTime;
|
|
|
|
m_Link = aOther.m_Link;
|
|
|
|
m_Path = aOther.m_Path; //is this correct behavior?
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Copy reference and value
|
|
|
|
*m_Reference = *aOther.m_Reference;
|
|
|
|
m_Reference->SetParent( this );
|
|
|
|
*m_Value = *aOther.m_Value;
|
|
|
|
m_Value->SetParent( this );
|
|
|
|
|
|
|
|
// Copy auxiliary data: Pads
|
2019-06-01 23:23:36 +00:00
|
|
|
m_pads.clear();
|
2016-05-31 08:27:52 +00:00
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : aOther.Pads() )
|
2016-05-31 08:27:52 +00:00
|
|
|
{
|
|
|
|
Add( new D_PAD( *pad ) );
|
|
|
|
}
|
|
|
|
|
2019-10-29 10:09:54 +00:00
|
|
|
// Copy auxiliary data: Zones
|
2019-10-26 15:49:29 +00:00
|
|
|
m_fp_zones.clear();
|
2019-10-29 10:09:54 +00:00
|
|
|
|
|
|
|
for( auto item : aOther.Zones() )
|
|
|
|
{
|
2019-10-26 15:49:29 +00:00
|
|
|
Add( static_cast<MODULE_ZONE_CONTAINER*>( item->Clone() ) );
|
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.
|
|
|
|
item->SetNetCode( -1 );
|
|
|
|
}
|
|
|
|
|
2016-05-31 08:27:52 +00:00
|
|
|
// Copy auxiliary data: Drawings
|
2019-06-02 03:55:32 +00:00
|
|
|
m_drawings.clear();
|
2016-05-31 08:27:52 +00:00
|
|
|
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : aOther.GraphicalItems() )
|
2016-05-31 08:27:52 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
case PCB_MODULE_EDGE_T:
|
|
|
|
Add( static_cast<BOARD_ITEM*>( item->Clone() ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxLogMessage( wxT( "MODULE::operator=() internal error: unknown type" ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy auxiliary data: 3D_Drawings info
|
|
|
|
m_3D_Drawings.clear();
|
|
|
|
m_3D_Drawings = aOther.m_3D_Drawings;
|
|
|
|
m_Doc = aOther.m_Doc;
|
|
|
|
m_KeyWord = aOther.m_KeyWord;
|
|
|
|
|
|
|
|
// Ensure auxiliary data is up to date
|
|
|
|
CalculateBoundingBox();
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 09:13:17 +00:00
|
|
|
void MODULE::ClearAllNets()
|
|
|
|
{
|
|
|
|
// Force the ORPHANED dummy net info for all pads.
|
|
|
|
// ORPHANED dummy net does not depend on a board
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto 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
|
|
|
|
2016-05-13 15:31:54 +00:00
|
|
|
void MODULE::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode )
|
2014-07-09 12:22:29 +00:00
|
|
|
{
|
|
|
|
switch( aBoardItem->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_TEXT_T:
|
2019-12-10 13:49:28 +00:00
|
|
|
// Only user text can be added this way.
|
2014-07-09 12:22:29 +00:00
|
|
|
assert( static_cast<TEXTE_MODULE*>( aBoardItem )->GetType() == TEXTE_MODULE::TEXT_is_DIVERS );
|
2014-09-10 15:18:42 +00:00
|
|
|
|
|
|
|
// no break
|
2014-07-09 12:22:29 +00:00
|
|
|
|
|
|
|
case PCB_MODULE_EDGE_T:
|
2016-05-13 15:31:54 +00:00
|
|
|
if( aMode == ADD_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:
|
2016-05-13 15:31:54 +00:00
|
|
|
if( aMode == ADD_APPEND )
|
2019-06-01 23:23:36 +00:00
|
|
|
m_pads.push_back( static_cast<D_PAD*>( aBoardItem ) );
|
2014-07-09 12:22:29 +00:00
|
|
|
else
|
2019-06-01 23:23:36 +00:00
|
|
|
m_pads.push_front( static_cast<D_PAD*>( aBoardItem ) );
|
2014-07-09 12:22:29 +00:00
|
|
|
break;
|
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
case PCB_MODULE_ZONE_AREA_T:
|
2019-10-29 10:09:54 +00:00
|
|
|
if( aMode == ADD_APPEND )
|
2019-10-26 15:49:29 +00:00
|
|
|
m_fp_zones.push_back( static_cast<MODULE_ZONE_CONTAINER*>( aBoardItem ) );
|
2019-10-29 10:09:54 +00:00
|
|
|
else
|
2019-10-26 15:49:29 +00:00
|
|
|
m_fp_zones.insert( m_fp_zones.begin(), static_cast<MODULE_ZONE_CONTAINER*>( aBoardItem ) );
|
2019-10-29 10:09:54 +00:00
|
|
|
break;
|
|
|
|
|
2014-07-09 12:22:29 +00:00
|
|
|
default:
|
2014-11-15 19:06:05 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( wxT( "MODULE::Add() needs work: BOARD_ITEM type (%d) not handled" ),
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-13 15:31:54 +00:00
|
|
|
void MODULE::Remove( BOARD_ITEM* aBoardItem )
|
2014-07-09 12:22:29 +00:00
|
|
|
{
|
|
|
|
switch( aBoardItem->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_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(
|
|
|
|
static_cast<TEXTE_MODULE*>( aBoardItem )->GetType() == TEXTE_MODULE::TEXT_is_DIVERS,
|
|
|
|
"Please report this bug: Invalid remove operation on required text" );
|
2014-09-10 15:18:42 +00:00
|
|
|
|
|
|
|
// no break
|
2014-07-09 12:22:29 +00:00
|
|
|
|
|
|
|
case PCB_MODULE_EDGE_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 )
|
|
|
|
{
|
|
|
|
if( *it == static_cast<D_PAD*>( aBoardItem ) )
|
|
|
|
{
|
|
|
|
m_pads.erase( it );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 15:31:54 +00:00
|
|
|
break;
|
2014-07-09 12:22:29 +00:00
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
case PCB_MODULE_ZONE_AREA_T:
|
|
|
|
for( auto it = m_fp_zones.begin(); it != m_fp_zones.end(); ++it )
|
2019-10-29 10:09:54 +00:00
|
|
|
{
|
2019-10-26 15:49:29 +00:00
|
|
|
if( *it == static_cast<MODULE_ZONE_CONTAINER*>( 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;
|
|
|
|
|
2014-07-09 12:22:29 +00:00
|
|
|
default:
|
2014-11-15 19:06:05 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( wxT( "MODULE::Remove() needs work: BOARD_ITEM type (%d) not handled" ),
|
|
|
|
aBoardItem->Type() );
|
|
|
|
wxFAIL_MSG( msg );
|
|
|
|
}
|
2014-07-09 12:22:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
void MODULE::Print( PCB_BASE_FRAME* aFrame, wxDC* aDC, const wxPoint& aOffset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : m_pads )
|
2019-05-31 12:15:25 +00:00
|
|
|
pad->Print( aFrame, aDC, aOffset );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
for( auto zone : m_fp_zones )
|
2019-10-29 10:09:54 +00:00
|
|
|
zone->Print( aFrame, aDC, aOffset );
|
|
|
|
|
2010-07-20 10:30:40 +00:00
|
|
|
BOARD* brd = GetBoard();
|
2010-01-31 20:01:46 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Draw graphic items
|
2017-03-13 03:19:33 +00:00
|
|
|
if( brd->IsElementVisible( LAYER_MOD_REFERENCES ) )
|
2019-05-31 12:15:25 +00:00
|
|
|
m_Reference->Print( aFrame, aDC, aOffset );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
if( brd->IsElementVisible( LAYER_MOD_VALUES ) )
|
2019-05-31 12:15:25 +00:00
|
|
|
m_Value->Print( aFrame, aDC, aOffset );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : m_drawings )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-04-01 05:21:50 +00:00
|
|
|
switch( item->Type() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
case PCB_MODULE_EDGE_T:
|
2019-05-31 12:15:25 +00:00
|
|
|
item->Print( aFrame, aDC, aOffset );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
void MODULE::CalculateBoundingBox()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
m_BoundaryBox = GetFootprintRect();
|
2018-09-13 21:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double MODULE::GetArea( int aPadding ) const
|
|
|
|
{
|
|
|
|
double w = std::abs( m_BoundaryBox.GetWidth() ) + aPadding;
|
|
|
|
double h = std::abs( m_BoundaryBox.GetHeight() ) + aPadding;
|
|
|
|
return w * h;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
EDA_RECT MODULE::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
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
area.SetOrigin( m_Pos );
|
2010-12-10 19:47:44 +00:00
|
|
|
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
|
|
|
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : m_drawings )
|
2014-04-30 19:16:22 +00:00
|
|
|
{
|
2018-08-09 00:11:47 +00:00
|
|
|
if( item->Type() == PCB_MODULE_EDGE_T )
|
|
|
|
area.Merge( item->GetBoundingBox() );
|
2014-04-30 19:16:22 +00:00
|
|
|
}
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : m_pads )
|
2010-12-10 19:47:44 +00:00
|
|
|
area.Merge( pad->GetBoundingBox() );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
for( auto zone : m_fp_zones )
|
2019-10-29 10:09:54 +00:00
|
|
|
area.Merge( zone->GetBoundingBox() );
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-01 12:35:42 +00:00
|
|
|
EDA_RECT MODULE::GetFpPadsLocalBbox() const
|
|
|
|
{
|
|
|
|
EDA_RECT area;
|
|
|
|
|
|
|
|
// We want the bounding box of the footprint pads at rot 0, not flipped
|
|
|
|
// Create such a image:
|
|
|
|
MODULE dummy( *this );
|
|
|
|
|
|
|
|
dummy.SetPosition( wxPoint( 0, 0 ) );
|
|
|
|
if( dummy.IsFlipped() )
|
|
|
|
dummy.Flip( wxPoint( 0, 0 ) , false );
|
|
|
|
|
|
|
|
if( dummy.GetOrientation() )
|
|
|
|
dummy.SetOrientation( 0 );
|
|
|
|
|
|
|
|
for( auto pad : dummy.Pads() )
|
|
|
|
area.Merge( pad->GetBoundingBox() );
|
|
|
|
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT MODULE::GetBoundingBox() const
|
2008-03-13 10:08:42 +00:00
|
|
|
{
|
2018-08-09 00:11:47 +00:00
|
|
|
EDA_RECT area = GetFootprintRect();
|
|
|
|
|
|
|
|
// Add in items not collected by GetFootprintRect():
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : m_drawings )
|
2018-08-09 00:11:47 +00:00
|
|
|
{
|
|
|
|
if( item->Type() != PCB_MODULE_EDGE_T )
|
|
|
|
area.Merge( item->GetBoundingBox() );
|
|
|
|
}
|
|
|
|
|
|
|
|
area.Merge( m_Value->GetBoundingBox() );
|
|
|
|
area.Merge( m_Reference->GetBoundingBox() );
|
|
|
|
|
|
|
|
return area;
|
2008-03-13 10:08:42 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2019-08-20 11:58:14 +00:00
|
|
|
const EDA_RECT MODULE::GetBoundingBox( bool aIncludeInvisibleText ) const
|
|
|
|
{
|
|
|
|
EDA_RECT area = GetFootprintRect();
|
|
|
|
|
|
|
|
// Add in items not collected by GetFootprintRect():
|
|
|
|
for( auto item : m_drawings )
|
|
|
|
{
|
|
|
|
if( item->Type() != PCB_MODULE_EDGE_T )
|
|
|
|
area.Merge( item->GetBoundingBox() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Value->IsVisible() || aIncludeInvisibleText )
|
|
|
|
area.Merge( m_Value->GetBoundingBox() );
|
|
|
|
|
|
|
|
if( m_Reference->IsVisible() || aIncludeInvisibleText )
|
|
|
|
area.Merge( m_Reference->GetBoundingBox() );
|
|
|
|
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-22 01:39:46 +00:00
|
|
|
/**
|
|
|
|
* This is a bit hacky right now for performance reasons.
|
|
|
|
*
|
|
|
|
* We assume that most footprints will have features aligned to the axes in
|
|
|
|
* the zero-rotation state. Therefore, if the footprint is rotated, we
|
|
|
|
* temporarily rotate back to zero, get the bounding box (excluding reference
|
|
|
|
* and value text) and then rotate the resulting poly back to the correct
|
|
|
|
* orientation.
|
|
|
|
*
|
|
|
|
* This is more accurate than using the AABB when most footprints are rotated
|
|
|
|
* off of the axes, but less accurate than computing some kind of bounding hull.
|
|
|
|
* We should consider doing that instead at some point in the future if we can
|
|
|
|
* use a performant algorithm and cache the result to avoid extra computing.
|
|
|
|
*/
|
2018-02-19 00:00:29 +00:00
|
|
|
SHAPE_POLY_SET MODULE::GetBoundingPoly() const
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET poly;
|
|
|
|
|
2018-02-22 01:39:46 +00:00
|
|
|
double orientation = GetOrientationRadians();
|
|
|
|
|
|
|
|
MODULE temp = *this;
|
|
|
|
temp.SetOrientation( 0.0 );
|
|
|
|
BOX2I area = temp.GetFootprintRect();
|
|
|
|
|
|
|
|
poly.NewOutline();
|
2018-02-19 00:00:29 +00:00
|
|
|
|
2018-02-22 01:39:46 +00:00
|
|
|
VECTOR2I p = area.GetPosition();
|
|
|
|
poly.Append( p );
|
|
|
|
p.x = area.GetRight();
|
|
|
|
poly.Append( p );
|
|
|
|
p.y = area.GetBottom();
|
|
|
|
poly.Append( p );
|
|
|
|
p.x = area.GetX();
|
|
|
|
poly.Append( p );
|
|
|
|
|
|
|
|
BOARD* board = GetBoard();
|
|
|
|
if( board )
|
|
|
|
{
|
|
|
|
int biggest_clearance = board->GetDesignSettings().GetBiggestClearanceValue();
|
|
|
|
poly.Inflate( biggest_clearance, 4 );
|
|
|
|
}
|
2018-02-19 00:00:29 +00:00
|
|
|
|
2018-02-22 01:39:46 +00:00
|
|
|
poly.Inflate( Millimeter2iu( 0.01 ), 4 );
|
|
|
|
poly.Rotate( -orientation, m_Pos );
|
2018-02-19 00:00:29 +00:00
|
|
|
|
|
|
|
return poly;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
void MODULE::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-06 02:02:39 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2019-07-13 16:35:57 +00:00
|
|
|
aList.emplace_back( MSG_PANEL_ITEM( m_Reference->GetShownText(), m_Value->GetShownText(), DARKCYAN ) );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
// Display last date the component was edited (useful in Module Editor).
|
2018-03-29 16:28:42 +00:00
|
|
|
wxDateTime date( static_cast<time_t>( m_LastEditTime ) );
|
2015-03-12 17:43:39 +00:00
|
|
|
|
|
|
|
if( m_LastEditTime && date.IsValid() )
|
2015-03-11 13:59:43 +00:00
|
|
|
// Date format: see http://www.cplusplus.com/reference/ctime/strftime
|
2015-03-12 17:43:39 +00:00
|
|
|
msg = date.Format( wxT( "%b %d, %Y" ) ); // Abbreviated_month_name Day, Year
|
|
|
|
else
|
|
|
|
msg = _( "Unknown" );
|
|
|
|
|
2019-07-13 16:35:57 +00:00
|
|
|
aList.emplace_back( MSG_PANEL_ITEM( _( "Last Change" ), msg, BROWN ) );
|
2009-10-11 13:04:47 +00:00
|
|
|
|
2013-12-14 19:03:38 +00:00
|
|
|
// display schematic path
|
2019-07-13 16:35:57 +00:00
|
|
|
aList.emplace_back( MSG_PANEL_ITEM( _( "Netlist Path" ), m_Path, BROWN ) );
|
2013-12-14 19:03:38 +00:00
|
|
|
|
2016-05-02 10:49:14 +00:00
|
|
|
// display the board side placement
|
2019-07-13 16:35:57 +00:00
|
|
|
aList.emplace_back( MSG_PANEL_ITEM( _( "Board Side" ),
|
|
|
|
IsFlipped()? _( "Back (Flipped)" ) : _( "Front" ), RED ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
msg.Printf( wxT( "%zu" ), m_pads.size() );
|
2019-07-13 16:35:57 +00:00
|
|
|
aList.emplace_back( MSG_PANEL_ITEM( _( "Pads" ), msg, BLUE ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
msg = wxT( ".." );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-09-09 02:27:56 +00:00
|
|
|
if( IsLocked() )
|
2007-09-21 10:38:50 +00:00
|
|
|
msg[0] = 'L';
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
if( m_ModuleStatus & MODULE_is_PLACED )
|
|
|
|
msg[1] = 'P';
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2019-07-13 16:35:57 +00:00
|
|
|
aList.emplace_back( MSG_PANEL_ITEM( _( "Status" ), msg, MAGENTA ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2016-05-02 10:49:14 +00:00
|
|
|
msg.Printf( wxT( "%.1f" ), GetOrientationDegrees() );
|
2019-07-13 16:35:57 +00:00
|
|
|
aList.emplace_back( MSG_PANEL_ITEM( _( "Rotation" ), msg, BROWN ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2013-04-07 11:55:18 +00:00
|
|
|
// Controls on right side of the dialog
|
2012-12-06 21:53:00 +00:00
|
|
|
switch( m_Attributs & 255 )
|
|
|
|
{
|
|
|
|
case 0:
|
2014-11-15 19:06:05 +00:00
|
|
|
msg = _( "Normal" );
|
2012-12-06 21:53:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MOD_CMS:
|
2014-11-15 19:06:05 +00:00
|
|
|
msg = _( "Insert" );
|
2012-12-06 21:53:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MOD_VIRTUAL:
|
2014-11-15 19:06:05 +00:00
|
|
|
msg = _( "Virtual" );
|
2012-12-06 21:53:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-11-15 19:06:05 +00:00
|
|
|
msg = wxT( "???" );
|
2012-12-06 21:53:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-07-13 16:35:57 +00:00
|
|
|
aList.emplace_back( MSG_PANEL_ITEM( _( "Attributes" ), msg, BROWN ) );
|
|
|
|
aList.emplace_back( MSG_PANEL_ITEM( _( "Footprint" ), FROM_UTF8( m_fpid.Format().c_str() ), BLUE ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( m_3D_Drawings.empty() )
|
|
|
|
msg = _( "No 3D shape" );
|
|
|
|
else
|
|
|
|
msg = m_3D_Drawings.front().m_Filename;
|
|
|
|
|
2013-01-17 17:34:03 +00:00
|
|
|
// Search the first active 3D shape in list
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2019-07-13 16:35:57 +00:00
|
|
|
aList.emplace_back( MSG_PANEL_ITEM( _( "3D-Shape" ), msg, RED ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2013-04-09 17:49:01 +00:00
|
|
|
wxString doc, keyword;
|
2019-07-13 16:35:57 +00:00
|
|
|
doc.Printf( _( "Doc: %s" ), m_Doc );
|
|
|
|
keyword.Printf( _( "Key Words: %s" ), m_KeyWord );
|
|
|
|
aList.emplace_back( MSG_PANEL_ITEM( doc, keyword, BLACK ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
bool MODULE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
EDA_RECT rect = m_BoundaryBox;
|
|
|
|
return rect.Inflate( aAccuracy ).Contains( aPosition );
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
bool MODULE::HitTestAccurate( const wxPoint& aPosition, int aAccuracy ) const
|
2018-02-19 00:00:29 +00:00
|
|
|
{
|
2019-07-13 16:35:57 +00:00
|
|
|
return GetBoundingPoly().Collide( aPosition, aAccuracy );
|
2018-02-19 00:00:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 18:09:41 +00:00
|
|
|
bool MODULE::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 )
|
|
|
|
return arect.Contains( m_BoundaryBox );
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Determine if any elements in the MODULE intersect the rect
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : m_pads )
|
2017-05-02 06:44:41 +00:00
|
|
|
{
|
|
|
|
if( pad->HitTest( arect, false, 0 ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
for( auto zone : m_fp_zones )
|
2019-10-29 10:09:54 +00:00
|
|
|
{
|
|
|
|
if( zone->HitTest( arect, false, 0 ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : m_drawings )
|
2017-05-02 06:44:41 +00:00
|
|
|
{
|
|
|
|
if( item->HitTest( arect, false, 0 ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No items were hit
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-04 04:22:27 +00:00
|
|
|
D_PAD* MODULE::FindPadByName( const wxString& aPadName ) const
|
|
|
|
{
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
D_PAD* MODULE::GetPad( const wxPoint& aPosition, LSET aLayerMask )
|
2011-09-15 17:58:35 +00:00
|
|
|
{
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-22 20:07:29 +00:00
|
|
|
D_PAD* MODULE::GetTopLeftPad()
|
|
|
|
{
|
2019-06-01 23:23:36 +00:00
|
|
|
D_PAD* topLeftPad = GetFirstPad();
|
2017-04-22 20:07:29 +00:00
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto 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 ) ||
|
|
|
|
( ( topLeftPad->GetPosition().x == pnt.x ) &&
|
|
|
|
( pnt.y < topLeftPad->GetPosition().y ) ) )
|
|
|
|
{
|
|
|
|
topLeftPad = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return topLeftPad;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-07 13:17:52 +00:00
|
|
|
unsigned MODULE::GetPadCount( INCLUDE_NPTH_T aIncludeNPTH ) const
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : m_pads )
|
2013-06-07 13:17:52 +00:00
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
if( pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED )
|
2013-06-07 13:17:52 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-11 18:35:26 +00:00
|
|
|
unsigned MODULE::GetUniquePadCount( INCLUDE_NPTH_T aIncludeNPTH ) const
|
|
|
|
{
|
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
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto 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
|
2015-11-11 18:35:26 +00:00
|
|
|
if( pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED )
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-27 14:25:20 +00:00
|
|
|
void MODULE::Add3DModel( MODULE_3D_SETTINGS* 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-19 00:30:10 +00:00
|
|
|
// see class_module.h
|
2016-07-12 19:05:54 +00:00
|
|
|
SEARCH_RESULT MODULE::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;
|
|
|
|
SEARCH_RESULT result = SEARCH_CONTINUE;
|
|
|
|
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 )
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_MODULE_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:
|
2019-06-01 23:23:36 +00:00
|
|
|
result = IterateForward<D_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
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
case PCB_MODULE_ZONE_AREA_T:
|
|
|
|
result = IterateForward<MODULE_ZONE_CONTAINER*>( m_fp_zones, inspector, testData, p );
|
2019-10-29 10:09:54 +00:00
|
|
|
++p;
|
|
|
|
break;
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_MODULE_TEXT_T:
|
2016-07-12 19:05:54 +00:00
|
|
|
result = inspector( m_Reference, testData );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
if( result == SEARCH_QUIT )
|
|
|
|
break;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2016-07-12 19:05:54 +00:00
|
|
|
result = inspector( m_Value, testData );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
if( result == SEARCH_QUIT )
|
|
|
|
break;
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
// m_Drawings can hold TYPETEXTMODULE also, so fall thru
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_MODULE_EDGE_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 )
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
case PCB_MODULE_EDGE_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
|
|
|
|
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
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
if( result == SEARCH_QUIT )
|
|
|
|
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
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString MODULE::GetSelectMenuText( EDA_UNITS_T aUnits ) const
|
2011-07-14 15:42:44 +00:00
|
|
|
{
|
2018-01-31 09:08:57 +00:00
|
|
|
wxString reference = GetReference();
|
|
|
|
|
|
|
|
if( reference.IsEmpty() )
|
|
|
|
reference = _( "<no reference>" );
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( _( "Footprint %s on %s" ), reference, GetLayerName() );
|
2011-07-14 15:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
BITMAP_DEF MODULE::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return module_xpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* MODULE::Clone() const
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
|
|
|
return new MODULE( *this );
|
|
|
|
}
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
void MODULE::RunOnChildren( const std::function<void (BOARD_ITEM*)>& aFunction )
|
2013-12-18 12:39:11 +00:00
|
|
|
{
|
2015-02-15 22:21:52 +00:00
|
|
|
try
|
|
|
|
{
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto 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
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
for( auto zone : m_fp_zones )
|
|
|
|
aFunction( static_cast<MODULE_ZONE_CONTAINER*>( zone ) );
|
2019-10-29 10:09:54 +00:00
|
|
|
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto drawing : m_drawings )
|
|
|
|
aFunction( static_cast<BOARD_ITEM*>( drawing ) );
|
2013-12-18 12:39:11 +00:00
|
|
|
|
2015-02-15 22:21:52 +00:00
|
|
|
aFunction( static_cast<BOARD_ITEM*>( m_Reference ) );
|
|
|
|
aFunction( static_cast<BOARD_ITEM*>( m_Value ) );
|
|
|
|
}
|
2016-10-10 15:04:48 +00:00
|
|
|
catch( std::bad_function_call& )
|
2015-02-15 22:21:52 +00:00
|
|
|
{
|
|
|
|
DisplayError( NULL, wxT( "Error running MODULE::RunOnChildren" ) );
|
|
|
|
}
|
2013-12-18 12:39:11 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 01:40:50 +00:00
|
|
|
|
|
|
|
void MODULE::GetAllDrawingLayers( int aLayers[], int& aCount, bool aIncludePads ) const
|
|
|
|
{
|
|
|
|
std::unordered_set<int> layers;
|
|
|
|
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : m_drawings )
|
2018-03-08 01:40:50 +00:00
|
|
|
{
|
|
|
|
layers.insert( static_cast<int>( item->GetLayer() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aIncludePads )
|
|
|
|
{
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto 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;
|
|
|
|
|
|
|
|
for( auto layer : layers )
|
|
|
|
aLayers[i++] = layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
void MODULE::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
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
|
|
|
|
|
|
|
switch( m_Layer )
|
|
|
|
{
|
2016-03-13 15:39:18 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
wxASSERT_MSG( false, "Illegal layer" ); // do you really have modules placed on other layers?
|
|
|
|
// pass through
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
bool f_silk = false, b_silk = false, non_silk = false;
|
|
|
|
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
unsigned int MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2017-03-13 03:19:33 +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
|
|
|
|
|
|
|
// Currently it is only for anchor layer
|
2017-03-13 03:19:33 +00:00
|
|
|
if( aView->IsLayerVisible( layer ) )
|
2018-11-02 23:33:34 +00:00
|
|
|
return 3;
|
2016-06-07 13:07:47 +00:00
|
|
|
|
|
|
|
return std::numeric_limits<unsigned int>::max();
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
2015-06-16 15:03:36 +00:00
|
|
|
|
2014-11-13 16:32:59 +00:00
|
|
|
const BOX2I MODULE::ViewBBox() const
|
|
|
|
{
|
2018-06-12 15:37:02 +00:00
|
|
|
EDA_RECT area = GetFootprintRect();
|
|
|
|
|
|
|
|
// Calculate extended area including text fields
|
|
|
|
area.Merge( m_Reference->GetBoundingBox() );
|
|
|
|
area.Merge( m_Value->GetBoundingBox() );
|
|
|
|
|
|
|
|
// 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).
|
|
|
|
BOARD* board = GetBoard();
|
|
|
|
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
|
|
|
|
2012-12-10 11:18:42 +00:00
|
|
|
bool MODULE::IsLibNameValid( const wxString & aName )
|
|
|
|
{
|
* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
* 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* MODULE::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
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
void MODULE::Move( const wxPoint& aMoveVector )
|
|
|
|
{
|
|
|
|
wxPoint newpos = m_Pos + aMoveVector;
|
|
|
|
SetPosition( newpos );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MODULE::Rotate( const wxPoint& aRotCentre, double aAngle )
|
|
|
|
{
|
2019-04-07 21:09:50 +00:00
|
|
|
double orientation = GetOrientation();
|
|
|
|
double newOrientation = orientation + aAngle;
|
2013-03-13 18:53:58 +00:00
|
|
|
wxPoint newpos = m_Pos;
|
|
|
|
RotatePoint( &newpos, aRotCentre, aAngle );
|
|
|
|
SetPosition( newpos );
|
2019-04-07 21:09:50 +00:00
|
|
|
SetOrientation( newOrientation );
|
|
|
|
|
|
|
|
m_Reference->KeepUpright( orientation, newOrientation );
|
|
|
|
m_Value->KeepUpright( orientation, newOrientation );
|
|
|
|
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : m_drawings )
|
2019-04-07 21:09:50 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == PCB_MODULE_TEXT_T )
|
|
|
|
static_cast<TEXTE_MODULE*>( item )->KeepUpright( orientation, newOrientation );
|
|
|
|
}
|
2013-03-13 18:53:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-12 21:02:10 +00:00
|
|
|
void MODULE::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
|
|
|
// Move module to its final position:
|
|
|
|
wxPoint finalPos = m_Pos;
|
2019-07-12 21:02:10 +00:00
|
|
|
|
2019-09-17 16:51:27 +00:00
|
|
|
// Now Flip the footprint.
|
|
|
|
// 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 accordint to the transform, because this parameter is used
|
|
|
|
// in pick and place files, and when updating the footprint from library.
|
|
|
|
// 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.
|
2015-06-26 13:41:56 +00:00
|
|
|
m_Orient = -m_Orient;
|
2019-09-17 16:51:27 +00:00
|
|
|
|
2019-09-19 18:24:14 +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.
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : m_pads )
|
2019-09-17 16:51:27 +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.
|
2019-10-26 15:49:29 +00:00
|
|
|
for( auto zone : m_fp_zones )
|
2019-10-29 10:09:54 +00:00
|
|
|
zone->Flip( m_Pos, aFlipLeftRight );
|
|
|
|
|
2015-07-31 19:04:30 +00:00
|
|
|
// Mirror reference and value.
|
2019-09-17 16:51:27 +00:00
|
|
|
m_Reference->Flip( m_Pos, false );
|
|
|
|
m_Value->Flip( m_Pos, false );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
|
|
|
// Reverse mirror module graphics and texts.
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : m_drawings )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_EDGE_T:
|
2019-09-17 16:51:27 +00:00
|
|
|
static_cast<EDGE_MODULE*>( item )->Flip( m_Pos, false );
|
2013-03-13 18:53:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_MODULE_TEXT_T:
|
2019-09-17 16:51:27 +00:00
|
|
|
static_cast<TEXTE_MODULE*>( item )->Flip( m_Pos, false );
|
2013-03-13 18:53:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxMessageBox( wxT( "MODULE::Flip() error: Unknown Draw Type" ) );
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MODULE::SetPosition( const wxPoint& newpos )
|
|
|
|
{
|
|
|
|
wxPoint delta = newpos - m_Pos;
|
|
|
|
|
|
|
|
m_Pos += delta;
|
2017-01-23 20:30:11 +00:00
|
|
|
|
|
|
|
m_Reference->EDA_TEXT::Offset( delta );
|
|
|
|
m_Value->EDA_TEXT::Offset( delta );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : m_pads )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
|
|
|
pad->SetPosition( pad->GetPosition() + delta );
|
|
|
|
}
|
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
for( auto zone : m_fp_zones )
|
2019-10-29 10:09:54 +00:00
|
|
|
zone->Move( delta );
|
|
|
|
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : m_drawings )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_EDGE_T:
|
|
|
|
{
|
|
|
|
EDGE_MODULE* pt_edgmod = (EDGE_MODULE*) item;
|
|
|
|
pt_edgmod->SetDrawCoord();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
{
|
2014-09-10 15:18:42 +00:00
|
|
|
TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CalculateBoundingBox();
|
|
|
|
}
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-03-23 13:30:00 +00:00
|
|
|
void MODULE::MoveAnchorPosition( const wxPoint& aMoveVector )
|
|
|
|
{
|
|
|
|
/* 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.
|
|
|
|
m_Reference->SetPos0( m_Reference->GetPos0() + moveVector );
|
|
|
|
m_Reference->SetDrawCoord();
|
|
|
|
m_Value->SetPos0( m_Value->GetPos0() + moveVector );
|
|
|
|
m_Value->SetDrawCoord();
|
|
|
|
|
|
|
|
// Update the pad local coordinates.
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto 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.
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : GraphicalItems() )
|
2013-03-23 13:30:00 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_EDGE_T:
|
2018-03-12 12:17:22 +00:00
|
|
|
{
|
2018-07-22 12:50:35 +00:00
|
|
|
EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( item );
|
|
|
|
edge->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
|
|
|
|
|
|
|
case PCB_MODULE_TEXT_T:
|
2018-07-22 12:50:35 +00:00
|
|
|
{
|
2014-11-15 19:06:05 +00:00
|
|
|
TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
|
|
|
|
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
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
void MODULE::SetOrientation( double newangle )
|
|
|
|
{
|
|
|
|
double angleChange = newangle - m_Orient; // change in rotation
|
|
|
|
|
2019-09-19 18:24:14 +00:00
|
|
|
NORMALIZE_ANGLE_180( newangle );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
|
|
|
m_Orient = newangle;
|
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto 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
|
|
|
}
|
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
for( auto 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.
|
|
|
|
m_Reference->SetDrawCoord();
|
|
|
|
m_Value->SetDrawCoord();
|
|
|
|
|
|
|
|
// Displace contours and text of the footprint.
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : m_drawings )
|
2013-03-13 18:53:58 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == PCB_MODULE_EDGE_T )
|
|
|
|
{
|
2014-09-10 15:18:42 +00:00
|
|
|
static_cast<EDGE_MODULE*>( item )->SetDrawCoord();
|
2013-03-13 18:53:58 +00:00
|
|
|
}
|
|
|
|
else if( item->Type() == PCB_MODULE_TEXT_T )
|
|
|
|
{
|
2014-09-10 15:18:42 +00:00
|
|
|
static_cast<TEXTE_MODULE*>( item )->SetDrawCoord();
|
2013-03-13 18:53:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CalculateBoundingBox();
|
|
|
|
}
|
|
|
|
|
2016-05-11 08:17:34 +00:00
|
|
|
BOARD_ITEM* MODULE::Duplicate( const BOARD_ITEM* aItem,
|
|
|
|
bool aIncrementPadNumbers,
|
|
|
|
bool aAddToModule )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
|
|
|
BOARD_ITEM* new_item = NULL;
|
2016-06-01 09:28:07 +00:00
|
|
|
D_PAD* new_pad = NULL;
|
2019-10-26 15:49:29 +00:00
|
|
|
MODULE_ZONE_CONTAINER* new_zone = NULL;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
2016-06-01 09:28:07 +00:00
|
|
|
new_pad = new D_PAD( *static_cast<const D_PAD*>( aItem ) );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2016-05-11 08:17:34 +00:00
|
|
|
if( aAddToModule )
|
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
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
case PCB_MODULE_ZONE_AREA_T:
|
2019-10-29 10:09:54 +00:00
|
|
|
{
|
2019-10-26 15:49:29 +00:00
|
|
|
new_zone = new MODULE_ZONE_CONTAINER( *static_cast<const MODULE_ZONE_CONTAINER*>( aItem ) );
|
2019-10-29 10:09:54 +00:00
|
|
|
|
|
|
|
if( aAddToModule )
|
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;
|
|
|
|
}
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
{
|
|
|
|
const TEXTE_MODULE* old_text = static_cast<const TEXTE_MODULE*>( aItem );
|
|
|
|
|
|
|
|
// do not duplicate value or reference fields
|
|
|
|
// (there can only be one of each)
|
|
|
|
if( old_text->GetType() == TEXTE_MODULE::TEXT_is_DIVERS )
|
|
|
|
{
|
|
|
|
TEXTE_MODULE* new_text = new TEXTE_MODULE( *old_text );
|
|
|
|
|
2016-05-11 08:17:34 +00:00
|
|
|
if( aAddToModule )
|
2019-06-02 03:55:32 +00:00
|
|
|
Add( new_text );
|
2016-05-11 08:17:34 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
new_item = new_text;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-03-07 07:13:06 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
case PCB_MODULE_EDGE_T:
|
|
|
|
{
|
|
|
|
EDGE_MODULE* new_edge = new EDGE_MODULE(
|
|
|
|
*static_cast<const EDGE_MODULE*>(aItem) );
|
|
|
|
|
2016-05-11 08:17:34 +00:00
|
|
|
if( aAddToModule )
|
2019-06-02 03:55:32 +00:00
|
|
|
Add( new_edge );
|
2016-05-11 08:17:34 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
new_item = new_edge;
|
|
|
|
break;
|
|
|
|
}
|
2016-03-07 07:13:06 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
case PCB_MODULE_T:
|
|
|
|
// Ignore the module itself
|
|
|
|
break;
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
default:
|
|
|
|
// Un-handled item for duplication
|
|
|
|
wxASSERT_MSG( false, "Duplication not supported for items of class "
|
|
|
|
+ aItem->GetClass() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-07-24 13:56:20 +00:00
|
|
|
if( aIncrementPadNumbers && new_pad && !new_pad->IsAperturePad() )
|
2015-03-22 09:42:41 +00:00
|
|
|
{
|
2016-06-01 09:28:07 +00:00
|
|
|
new_pad->IncrementPadName( true, true );
|
2015-03-22 09:42:41 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
return new_item;
|
|
|
|
}
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
wxString MODULE::GetNextPadName( bool aFillSequenceGaps ) const
|
|
|
|
{
|
|
|
|
std::set<int> usedNumbers;
|
|
|
|
|
|
|
|
// Create a set of used pad numbers
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : m_pads )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2019-01-29 10:15:44 +00:00
|
|
|
int padNumber = GetTrailingInt( pad->GetName() );
|
2015-02-12 03:22:24 +00:00
|
|
|
usedNumbers.insert( padNumber );
|
|
|
|
}
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
const int nextNum = getNextNumberInSequence( usedNumbers, aFillSequenceGaps );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
return wxString::Format( wxT( "%i" ), nextNum );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-24 18:41:08 +00:00
|
|
|
void MODULE::IncrementReference( int aDelta )
|
|
|
|
{
|
2019-01-29 10:50:50 +00:00
|
|
|
const auto& 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;
|
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;
|
|
|
|
}
|
|
|
|
|
2017-12-31 16:46:38 +00:00
|
|
|
// a helper function to add a rectangular polygon aRect to aPolySet
|
|
|
|
static void addRect( SHAPE_POLY_SET& aPolySet, wxRect aRect )
|
|
|
|
{
|
|
|
|
aPolySet.NewOutline();
|
2017-12-22 00:49:35 +00:00
|
|
|
|
2017-12-31 16:46:38 +00:00
|
|
|
aPolySet.Append( aRect.GetX(), aRect.GetY() );
|
|
|
|
aPolySet.Append( aRect.GetX()+aRect.width, aRect.GetY() );
|
|
|
|
aPolySet.Append( aRect.GetX()+aRect.width, aRect.GetY()+aRect.height );
|
|
|
|
aPolySet.Append( aRect.GetX(), aRect.GetY()+aRect.height );
|
|
|
|
}
|
2017-12-22 00:49:35 +00:00
|
|
|
|
2018-02-22 10:10:48 +00:00
|
|
|
double MODULE::CoverageRatio( const GENERAL_COLLECTOR& aCollector ) const
|
2015-02-17 23:58:14 +00:00
|
|
|
{
|
|
|
|
double moduleArea = GetFootprintRect().GetArea();
|
2017-12-31 16:46:38 +00:00
|
|
|
SHAPE_POLY_SET coveredRegion;
|
2018-02-22 10:10:48 +00:00
|
|
|
addRect( coveredRegion, GetFootprintRect() );
|
2015-02-17 23:58:14 +00:00
|
|
|
|
2018-02-22 10:10:48 +00:00
|
|
|
// build list of holes (covered areas not available for selection)
|
2017-12-31 16:46:38 +00:00
|
|
|
SHAPE_POLY_SET holes;
|
2018-02-22 10:10:48 +00:00
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : m_pads )
|
2017-12-31 16:46:38 +00:00
|
|
|
addRect( holes, pad->GetBoundingBox() );
|
2015-02-17 23:58:14 +00:00
|
|
|
|
2017-12-31 16:46:38 +00:00
|
|
|
addRect( holes, m_Reference->GetBoundingBox() );
|
|
|
|
addRect( holes, m_Value->GetBoundingBox() );
|
2015-02-17 23:58:14 +00:00
|
|
|
|
2018-02-22 10:10:48 +00:00
|
|
|
for( int i = 0; i < aCollector.GetCount(); ++i )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = aCollector[i];
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_TEXT_T:
|
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
case PCB_TRACE_T:
|
|
|
|
case PCB_VIA_T:
|
|
|
|
addRect( holes, item->GetBoundingBox() );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-31 16:46:38 +00:00
|
|
|
SHAPE_POLY_SET uncoveredRegion;
|
|
|
|
uncoveredRegion.BooleanSubtract( coveredRegion, holes, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
uncoveredRegion.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
uncoveredRegion.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2015-02-17 23:58:14 +00:00
|
|
|
|
2017-12-31 16:46:38 +00:00
|
|
|
double uncoveredRegionArea = polygonArea( uncoveredRegion );
|
|
|
|
double coveredArea = moduleArea - uncoveredRegionArea;
|
2017-12-22 00:49:35 +00:00
|
|
|
double ratio = ( coveredArea / moduleArea );
|
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
|
|
|
|
2017-03-19 15:38:30 +00:00
|
|
|
// see convert_drawsegment_list_to_polygon.cpp:
|
2018-06-18 15:34:43 +00:00
|
|
|
extern bool ConvertOutlineToPolygon( std::vector<DRAWSEGMENT*>& aSegList, SHAPE_POLY_SET& aPolygons,
|
2018-11-28 12:11:43 +00:00
|
|
|
wxString* aErrorText, unsigned int aTolerance, wxPoint* aErrorLocation = nullptr );
|
2017-03-16 17:09:33 +00:00
|
|
|
|
|
|
|
bool MODULE::BuildPolyCourtyard()
|
|
|
|
{
|
2017-03-19 15:38:30 +00:00
|
|
|
m_poly_courtyard_front.RemoveAllContours();
|
|
|
|
m_poly_courtyard_back.RemoveAllContours();
|
2017-03-16 17:09:33 +00:00
|
|
|
// Build the courtyard area from graphic items on the courtyard.
|
|
|
|
// Only PCB_MODULE_EDGE_T have meaning, graphic texts are ignored.
|
|
|
|
// Collect items:
|
2017-03-19 15:38:30 +00:00
|
|
|
std::vector< DRAWSEGMENT* > list_front;
|
|
|
|
std::vector< DRAWSEGMENT* > list_back;
|
2017-03-16 17:09:33 +00:00
|
|
|
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : GraphicalItems() )
|
2017-03-16 17:09:33 +00:00
|
|
|
{
|
|
|
|
if( item->GetLayer() == B_CrtYd && item->Type() == PCB_MODULE_EDGE_T )
|
2017-03-19 15:38:30 +00:00
|
|
|
list_back.push_back( static_cast< DRAWSEGMENT* > ( item ) );
|
2017-03-16 17:09:33 +00:00
|
|
|
|
|
|
|
if( item->GetLayer() == F_CrtYd && item->Type() == PCB_MODULE_EDGE_T )
|
2017-03-19 15:38:30 +00:00
|
|
|
list_front.push_back( static_cast< DRAWSEGMENT* > ( item ) );
|
2017-03-16 17:09:33 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 15:38:30 +00:00
|
|
|
// Note: if no item found on courtyard layers, return true.
|
|
|
|
// false is returned only when the shape defined on courtyard layers
|
|
|
|
// is not convertible to a polygon
|
|
|
|
if( !list_front.size() && !list_back.size() )
|
|
|
|
return true;
|
2017-03-16 17:09:33 +00:00
|
|
|
|
2017-03-20 12:05:38 +00:00
|
|
|
wxString error_msg;
|
|
|
|
|
2019-10-03 16:32:09 +00:00
|
|
|
#define ARC_ERROR_MAX 0.02 /* error max in mm to approximate a arc by segments */
|
2018-06-18 15:34:43 +00:00
|
|
|
bool success = ConvertOutlineToPolygon( list_front, m_poly_courtyard_front,
|
2019-10-03 16:32:09 +00:00
|
|
|
&error_msg,
|
|
|
|
(unsigned) Millimeter2iu( ARC_ERROR_MAX ) );
|
2017-03-16 17:09:33 +00:00
|
|
|
|
2017-03-19 15:38:30 +00:00
|
|
|
if( success )
|
2018-06-18 15:34:43 +00:00
|
|
|
{
|
|
|
|
success = ConvertOutlineToPolygon( list_back, m_poly_courtyard_back,
|
2019-10-03 16:32:09 +00:00
|
|
|
&error_msg,
|
|
|
|
(unsigned) Millimeter2iu( ARC_ERROR_MAX ) );
|
2018-06-18 15:34:43 +00:00
|
|
|
}
|
2017-03-20 12:05:38 +00:00
|
|
|
|
|
|
|
if( !error_msg.IsEmpty() )
|
|
|
|
{
|
2018-10-11 14:31:35 +00:00
|
|
|
wxLogMessage( wxString::Format( _( "Processing courtyard of \"%s\": %s" ),
|
|
|
|
GetChars( GetFPID().Format() ),
|
|
|
|
error_msg) );
|
2017-03-20 12:05:38 +00:00
|
|
|
}
|
2017-03-16 17:09:33 +00:00
|
|
|
|
2017-03-19 15:38:30 +00:00
|
|
|
return success;
|
2017-03-16 17:09:33 +00:00
|
|
|
}
|
2017-10-31 13:59:03 +00:00
|
|
|
|
2019-09-15 09:10:53 +00:00
|
|
|
|
2017-10-31 13:59:03 +00:00
|
|
|
void MODULE::SwapData( BOARD_ITEM* aImage )
|
|
|
|
{
|
|
|
|
assert( aImage->Type() == PCB_MODULE_T );
|
|
|
|
|
|
|
|
std::swap( *((MODULE*) this), *((MODULE*) aImage) );
|
|
|
|
}
|
2019-09-15 09:10:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool MODULE::HasNonSMDPins() const
|
|
|
|
{
|
|
|
|
// returns true if the given module has at lesat one non smd pin, such as through hole
|
|
|
|
|
|
|
|
for( auto pad : Pads() )
|
|
|
|
{
|
|
|
|
if( pad->GetAttribute() != PAD_ATTRIB_SMD )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|