Keepout in footprints: fix issues related to netclass management. Keepout do not actually use netclasses, but the netclass info must be valid. Especially when editing a fp in the fp editor, the netclass info is related to the dummy board managed by the fp editor. But when saved to the board editor the netclass info must be related to the main board

This commit is contained in:
jean-pierre charras 2019-10-29 11:09:54 +01:00
parent 1c2891e6d4
commit 04bae776a7
4 changed files with 102 additions and 76 deletions

View File

@ -108,10 +108,18 @@ MODULE::MODULE( const MODULE& aModule ) :
Add( new D_PAD( *pad ) );
}
// Copy auxiliary data: Zones
for( auto item : aModule.Zones() )
// Copy auxiliary data: Zones
for( auto item : aModule.Zones() )
{
Add( static_cast<MODULE_ZONE_CONTAINER*>( item->Clone() ) );
// 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 );
}
// Copy auxiliary data: Drawings
for( auto item : aModule.GraphicalItems() )
{
@ -157,10 +165,10 @@ MODULE::~MODULE()
m_pads.clear();
for( auto p : m_fp_zones )
delete p;
delete p;
m_fp_zones.clear();
for( auto d : m_drawings )
delete d;
@ -206,14 +214,20 @@ MODULE& MODULE::operator=( const MODULE& aOther )
Add( new D_PAD( *pad ) );
}
// Copy auxiliary data: Zones
// Copy auxiliary data: Zones
m_fp_zones.clear();
for( auto item : aOther.Zones() )
{
for( auto item : aOther.Zones() )
{
Add( static_cast<MODULE_ZONE_CONTAINER*>( item->Clone() ) );
}
// 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 );
}
// Copy auxiliary data: Drawings
m_drawings.clear();
@ -279,12 +293,12 @@ void MODULE::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode )
break;
case PCB_MODULE_ZONE_AREA_T:
if( aMode == ADD_APPEND )
if( aMode == ADD_APPEND )
m_fp_zones.push_back( static_cast<MODULE_ZONE_CONTAINER*>( aBoardItem ) );
else
else
m_fp_zones.insert( m_fp_zones.begin(), static_cast<MODULE_ZONE_CONTAINER*>( aBoardItem ) );
break;
break;
default:
{
wxString msg;
@ -339,16 +353,16 @@ void MODULE::Remove( BOARD_ITEM* aBoardItem )
case PCB_MODULE_ZONE_AREA_T:
for( auto it = m_fp_zones.begin(); it != m_fp_zones.end(); ++it )
{
{
if( *it == static_cast<MODULE_ZONE_CONTAINER*>( aBoardItem ) )
{
{
m_fp_zones.erase( it );
break;
}
}
break;
break;
}
}
break;
default:
{
wxString msg;
@ -366,8 +380,8 @@ void MODULE::Print( PCB_BASE_FRAME* aFrame, wxDC* aDC, const wxPoint& aOffset )
pad->Print( aFrame, aDC, aOffset );
for( auto zone : m_fp_zones )
zone->Print( aFrame, aDC, aOffset );
zone->Print( aFrame, aDC, aOffset );
BOARD* brd = GetBoard();
// Draw graphic items
@ -425,8 +439,8 @@ EDA_RECT MODULE::GetFootprintRect() const
area.Merge( pad->GetBoundingBox() );
for( auto zone : m_fp_zones )
area.Merge( zone->GetBoundingBox() );
area.Merge( zone->GetBoundingBox() );
return area;
}
@ -633,11 +647,11 @@ bool MODULE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) co
}
for( auto zone : m_fp_zones )
{
if( zone->HitTest( arect, false, 0 ) )
return true;
}
{
if( zone->HitTest( arect, false, 0 ) )
return true;
}
for( auto item : m_drawings )
{
if( item->HitTest( arect, false, 0 ) )
@ -792,9 +806,9 @@ SEARCH_RESULT MODULE::Visit( INSPECTOR inspector, void* testData, const KICAD_T
case PCB_MODULE_ZONE_AREA_T:
result = IterateForward<MODULE_ZONE_CONTAINER*>( m_fp_zones, inspector, testData, p );
++p;
break;
++p;
break;
case PCB_MODULE_TEXT_T:
result = inspector( m_Reference, testData );
@ -874,7 +888,7 @@ void MODULE::RunOnChildren( const std::function<void (BOARD_ITEM*)>& aFunction )
for( auto zone : m_fp_zones )
aFunction( static_cast<MODULE_ZONE_CONTAINER*>( zone ) );
for( auto drawing : m_drawings )
aFunction( static_cast<BOARD_ITEM*>( drawing ) );
@ -1079,10 +1093,10 @@ void MODULE::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
for( auto pad : m_pads )
pad->Flip( m_Pos, false );
// Mirror zones to other side of board.
// Mirror zones to other side of board.
for( auto zone : m_fp_zones )
zone->Flip( m_Pos, aFlipLeftRight );
zone->Flip( m_Pos, aFlipLeftRight );
// Mirror reference and value.
m_Reference->Flip( m_Pos, false );
m_Value->Flip( m_Pos, false );
@ -1129,8 +1143,8 @@ void MODULE::SetPosition( const wxPoint& newpos )
}
for( auto zone : m_fp_zones )
zone->Move( delta );
zone->Move( delta );
for( auto item : m_drawings )
{
switch( item->Type() )
@ -1231,10 +1245,10 @@ void MODULE::SetOrientation( double newangle )
}
for( auto zone : m_fp_zones )
{
zone->Rotate( GetPosition(), angleChange );
}
{
zone->Rotate( GetPosition(), angleChange );
}
// Update of the reference and value.
m_Reference->SetDrawCoord();
m_Value->SetDrawCoord();
@ -1277,16 +1291,16 @@ BOARD_ITEM* MODULE::Duplicate( const BOARD_ITEM* aItem,
}
case PCB_MODULE_ZONE_AREA_T:
{
{
new_zone = new MODULE_ZONE_CONTAINER( *static_cast<const MODULE_ZONE_CONTAINER*>( aItem ) );
if( aAddToModule )
if( aAddToModule )
m_fp_zones.push_back( new_zone );
new_item = new_zone;
break;
}
new_item = new_zone;
break;
}
case PCB_MODULE_TEXT_T:
{
const TEXTE_MODULE* old_text = static_cast<const TEXTE_MODULE*>( aItem );

View File

@ -59,7 +59,7 @@ ZONE_CONTAINER::ZONE_CONTAINER( BOARD_ITEM_CONTAINER* aParent, bool aInModule )
// used only if m_HatchFillTypeSmoothingLevel > 0
m_priority = 0;
m_cornerSmoothingType = ZONE_SETTINGS::SMOOTHING_NONE;
SetIsKeepout( false );
SetIsKeepout( aInModule ? true : false ); // Zones living in modules have the keepout option.
SetDoNotAllowCopperPour( false ); // has meaning only if m_isKeepout == true
SetDoNotAllowVias( true ); // has meaning only if m_isKeepout == true
SetDoNotAllowTracks( true ); // has meaning only if m_isKeepout == true
@ -76,7 +76,7 @@ ZONE_CONTAINER::ZONE_CONTAINER( BOARD_ITEM_CONTAINER* aParent, bool aInModule )
ZONE_CONTAINER::ZONE_CONTAINER( const ZONE_CONTAINER& aZone )
: BOARD_CONNECTED_ITEM( aZone.GetParent(), PCB_ZONE_AREA_T )
{
copyDataFromSrc( aZone );
initDataFromSrcInCopyCtor( aZone );
}
@ -88,6 +88,7 @@ ZONE_CONTAINER& ZONE_CONTAINER::operator=( const ZONE_CONTAINER& aOther )
delete m_Poly;
m_Poly = new SHAPE_POLY_SET( *aOther.m_Poly );
m_isKeepout = aOther.m_isKeepout;
m_CornerSelection = nullptr; // for corner moving, corner index to (null if no selection)
m_ZoneClearance = aOther.m_ZoneClearance; // clearance value
m_ZoneMinThickness = aOther.m_ZoneMinThickness;
@ -123,8 +124,14 @@ ZONE_CONTAINER::~ZONE_CONTAINER()
}
void ZONE_CONTAINER::copyDataFromSrc( const ZONE_CONTAINER& aZone )
void ZONE_CONTAINER::initDataFromSrcInCopyCtor( const ZONE_CONTAINER& aZone )
{
// members are expected non initialize in this.
// initDataFromSrcInCopyCtor() is expected to be called
// only from a copy constructor.
m_isKeepout = aZone.m_isKeepout;
SetLayerSet( aZone.GetLayerSet() );
m_Poly = new SHAPE_POLY_SET( *aZone.m_Poly );
// For corner moving, corner index to drag, or nullptr if no selection
@ -142,7 +149,6 @@ void ZONE_CONTAINER::copyDataFromSrc( const ZONE_CONTAINER& aZone )
m_FilledPolysList.Append( aZone.m_FilledPolysList );
m_FillSegmList = aZone.m_FillSegmList; // vector <> copy
m_isKeepout = aZone.m_isKeepout;
m_doNotAllowCopperPour = aZone.m_doNotAllowCopperPour;
m_doNotAllowVias = aZone.m_doNotAllowVias;
m_doNotAllowTracks = aZone.m_doNotAllowTracks;
@ -160,13 +166,8 @@ void ZONE_CONTAINER::copyDataFromSrc( const ZONE_CONTAINER& aZone )
m_HatchFillTypeSmoothingLevel = aZone.m_HatchFillTypeSmoothingLevel;
m_HatchFillTypeSmoothingValue = aZone.m_HatchFillTypeSmoothingValue;
SetLayerSet( aZone.GetLayerSet() );
SetLocalFlags( aZone.GetLocalFlags() );
// Now zone type and layer are set, transfer net info
// (has meaning only for copper zones)
m_netinfo = aZone.m_netinfo;
SetNeedRefill( aZone.NeedRefill() );
}
@ -647,10 +648,13 @@ int ZONE_CONTAINER::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const
// The actual zone clearance is the biggest of the zone netclass clearance
// and the zone clearance setting in the zone properties dialog.
NETCLASSPTR myClass = GetNetClass();
if( !m_isKeepout ) // Net class has no meaning for a keepout area.
{
NETCLASSPTR myClass = GetNetClass();
if( myClass )
myClearance = std::max( myClearance, myClass->GetClearance() );
if( myClass )
myClearance = std::max( myClearance, myClass->GetClearance() );
}
// Get the final clearance between me and aItem
if( aItem )
@ -1314,11 +1318,22 @@ void ZONE_CONTAINER::TransformOutlinesShapeWithClearanceToPolygon( SHAPE_POLY_SE
aCornerBuffer.Append( polybuffer );
}
//
/********* MODULE_ZONE_CONTAINER **************/
//
MODULE_ZONE_CONTAINER::MODULE_ZONE_CONTAINER( BOARD_ITEM_CONTAINER* aParent ) :
ZONE_CONTAINER( aParent, true )
{
// in a footprint, net classes are not managed.
// so set the net to NETINFO_LIST::ORPHANED_ITEM
SetNetCode( -1, true );
}
MODULE_ZONE_CONTAINER::MODULE_ZONE_CONTAINER( const MODULE_ZONE_CONTAINER& aZone )
: ZONE_CONTAINER( aZone.GetParent(), true )
{
copyDataFromSrc( aZone );
initDataFromSrcInCopyCtor( aZone );
}
@ -1337,7 +1352,6 @@ EDA_ITEM* MODULE_ZONE_CONTAINER::Clone() const
unsigned int MODULE_ZONE_CONTAINER::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
{
//
const int HIDE = std::numeric_limits<unsigned int>::max();
if( !aView )

View File

@ -710,9 +710,10 @@ public:
protected:
/** Copy aZone data to me
* members are expected non initialize in this.
* copyDataFromSrc() is expected to be called *only* from a copy constructor.
*/
void copyDataFromSrc( const ZONE_CONTAINER& aZone );
void initDataFromSrcInCopyCtor( const ZONE_CONTAINER& aZone );
SHAPE_POLY_SET* m_Poly; ///< Outline of the zone.
int m_cornerSmoothingType;
@ -826,10 +827,7 @@ protected:
class MODULE_ZONE_CONTAINER : public ZONE_CONTAINER
{
public:
MODULE_ZONE_CONTAINER( BOARD_ITEM_CONTAINER* aParent ) :
ZONE_CONTAINER( aParent, true )
{
}
MODULE_ZONE_CONTAINER( BOARD_ITEM_CONTAINER* aParent );
MODULE_ZONE_CONTAINER( const MODULE_ZONE_CONTAINER& aZone );
MODULE_ZONE_CONTAINER& operator=( const MODULE_ZONE_CONTAINER &aOther );

View File

@ -133,15 +133,15 @@ void ZONE_SETTINGS::ExportSetting( ZONE_CONTAINER& aTarget, bool aFullExport ) c
if( aFullExport )
{
aTarget.SetPriority( m_ZonePriority );
aTarget.SetNetCode( m_NetcodeSelection );
// Keepout zones can have multiple layers
// Keepout zones can have multiple layers and have no net
if( m_isKeepout )
{
aTarget.SetLayerSet( m_Layers );
}
else
{
aTarget.SetNetCode( m_NetcodeSelection );
aTarget.SetLayer( m_CurrentZone_Layer );
}
}