Mostly clean-up, but also bug fixes with bounding boxes.

This commit is contained in:
Jeff Young 2024-04-22 10:54:58 +01:00
parent bbab5a979a
commit e8be782687
9 changed files with 100 additions and 87 deletions

View File

@ -201,28 +201,28 @@ const std::vector<KIGFX::VIEW_ITEM*> SELECTION::updateDrawList() const
bool SELECTION::AreAllItemsIdentical() const bool SELECTION::AreAllItemsIdentical() const
{ {
return ( std::all_of( m_items.begin() + 1, m_items.end(), return std::all_of( m_items.begin() + 1, m_items.end(),
[&]( const EDA_ITEM* r ) [&]( const EDA_ITEM* r )
{ {
return r->Type() == m_items.front()->Type(); return r->Type() == m_items.front()->Type();
} ) ); } );
} }
bool SELECTION::OnlyContains( std::vector<KICAD_T> aList ) const bool SELECTION::OnlyContains( std::vector<KICAD_T> aList ) const
{ {
return ( std::all_of( m_items.begin(), m_items.end(), return std::all_of( m_items.begin(), m_items.end(),
[&]( const EDA_ITEM* r ) [&]( const EDA_ITEM* r )
{ {
return r->IsType( aList ); return r->IsType( aList );
} ) ); } );
} }
const std::vector<EDA_ITEM*> SELECTION::GetItemsSortedBySelectionOrder() const const std::vector<EDA_ITEM*> SELECTION::GetItemsSortedBySelectionOrder() const
{ {
using pairedIterators = using pairedIterators = std::pair<decltype( m_items.begin() ),
std::pair<decltype( m_items.begin() ), decltype( m_itemsOrders.begin() )>; decltype( m_itemsOrders.begin() )>;
// Create a vector of all {selection item, selection order} iterator pairs // Create a vector of all {selection item, selection order} iterator pairs
std::vector<pairedIterators> pairs; std::vector<pairedIterators> pairs;

View File

@ -174,9 +174,11 @@ void SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMAT
aFormatter.Print( 0, " (pin_names" ); aFormatter.Print( 0, " (pin_names" );
if( aSymbol->GetPinNameOffset() != schIUScale.MilsToIU( DEFAULT_PIN_NAME_OFFSET ) ) if( aSymbol->GetPinNameOffset() != schIUScale.MilsToIU( DEFAULT_PIN_NAME_OFFSET ) )
{
aFormatter.Print( 0, " (offset %s)", aFormatter.Print( 0, " (offset %s)",
EDA_UNIT_UTILS::FormatInternalUnits( schIUScale, EDA_UNIT_UTILS::FormatInternalUnits( schIUScale,
aSymbol->GetPinNameOffset() ).c_str() ); aSymbol->GetPinNameOffset() ).c_str() );
}
if( !aSymbol->GetShowPinNames() ) if( !aSymbol->GetShowPinNames() )
aFormatter.Print( 0, " hide" ); aFormatter.Print( 0, " hide" );

View File

@ -498,7 +498,7 @@ LIB_SYMBOL* SCH_IO_KICAD_SEXPR_PARSER::parseLibSymbol( LIB_SYMBOL_MAP& aSymbolLi
case T_rectangle: case T_rectangle:
case T_text: case T_text:
case T_text_box: case T_text_box:
item = ParseDrawItem(); item = ParseSymbolDrawItem();
wxCHECK_MSG( item, nullptr, "Invalid draw item pointer." ); wxCHECK_MSG( item, nullptr, "Invalid draw item pointer." );
@ -524,7 +524,7 @@ LIB_SYMBOL* SCH_IO_KICAD_SEXPR_PARSER::parseLibSymbol( LIB_SYMBOL_MAP& aSymbolLi
case T_rectangle: case T_rectangle:
case T_text: case T_text:
case T_text_box: case T_text_box:
item = ParseDrawItem(); item = ParseSymbolDrawItem();
wxCHECK_MSG( item, nullptr, "Invalid draw item pointer." ); wxCHECK_MSG( item, nullptr, "Invalid draw item pointer." );
@ -545,7 +545,7 @@ LIB_SYMBOL* SCH_IO_KICAD_SEXPR_PARSER::parseLibSymbol( LIB_SYMBOL_MAP& aSymbolLi
} }
SCH_ITEM* SCH_IO_KICAD_SEXPR_PARSER::ParseDrawItem() SCH_ITEM* SCH_IO_KICAD_SEXPR_PARSER::ParseSymbolDrawItem()
{ {
switch( CurTok() ) switch( CurTok() )
{ {
@ -562,7 +562,7 @@ SCH_ITEM* SCH_IO_KICAD_SEXPR_PARSER::ParseDrawItem()
break; break;
case T_pin: case T_pin:
return parsePin(); return parseSymbolPin();
break; break;
case T_polyline: case T_polyline:
@ -796,7 +796,7 @@ void SCH_IO_KICAD_SEXPR_PARSER::parseEDA_TEXT( EDA_TEXT* aText, bool aConvertOve
NeedSYMBOL(); NeedSYMBOL();
wxString hyperlink = FromUTF8(); wxString hyperlink = FromUTF8();
if( !aText->ValidateHyperlink( hyperlink ) ) if( !EDA_TEXT::ValidateHyperlink( hyperlink ) )
{ {
THROW_PARSE_ERROR( wxString::Format( _( "Invalid hyperlink url '%s'" ), hyperlink ), THROW_PARSE_ERROR( wxString::Format( _( "Invalid hyperlink url '%s'" ), hyperlink ),
CurSource(), CurLine(), CurLineNumber(), CurOffset() ); CurSource(), CurLine(), CurLineNumber(), CurOffset() );
@ -1415,54 +1415,56 @@ SCH_SHAPE* SCH_IO_KICAD_SEXPR_PARSER::parseSymbolCircle()
} }
SCH_PIN* SCH_IO_KICAD_SEXPR_PARSER::parsePin() SCH_PIN* SCH_IO_KICAD_SEXPR_PARSER::parseSymbolPin()
{ {
auto parseType = [&]( T token ) -> ELECTRICAL_PINTYPE auto parseType =
{ [&]( T token ) -> ELECTRICAL_PINTYPE
switch( token ) {
{ switch( token )
case T_input: return ELECTRICAL_PINTYPE::PT_INPUT; {
case T_output: return ELECTRICAL_PINTYPE::PT_OUTPUT; case T_input: return ELECTRICAL_PINTYPE::PT_INPUT;
case T_bidirectional: return ELECTRICAL_PINTYPE::PT_BIDI; case T_output: return ELECTRICAL_PINTYPE::PT_OUTPUT;
case T_tri_state: return ELECTRICAL_PINTYPE::PT_TRISTATE; case T_bidirectional: return ELECTRICAL_PINTYPE::PT_BIDI;
case T_passive: return ELECTRICAL_PINTYPE::PT_PASSIVE; case T_tri_state: return ELECTRICAL_PINTYPE::PT_TRISTATE;
case T_unspecified: return ELECTRICAL_PINTYPE::PT_UNSPECIFIED; case T_passive: return ELECTRICAL_PINTYPE::PT_PASSIVE;
case T_power_in: return ELECTRICAL_PINTYPE::PT_POWER_IN; case T_unspecified: return ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
case T_power_out: return ELECTRICAL_PINTYPE::PT_POWER_OUT; case T_power_in: return ELECTRICAL_PINTYPE::PT_POWER_IN;
case T_open_collector: return ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR; case T_power_out: return ELECTRICAL_PINTYPE::PT_POWER_OUT;
case T_open_emitter: return ELECTRICAL_PINTYPE::PT_OPENEMITTER; case T_open_collector: return ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR;
case T_unconnected: case T_open_emitter: return ELECTRICAL_PINTYPE::PT_OPENEMITTER;
case T_no_connect: return ELECTRICAL_PINTYPE::PT_NC; case T_unconnected:
case T_free: return ELECTRICAL_PINTYPE::PT_NIC; case T_no_connect: return ELECTRICAL_PINTYPE::PT_NC;
case T_free: return ELECTRICAL_PINTYPE::PT_NIC;
default: default:
Expecting( "input, output, bidirectional, tri_state, passive, " Expecting( "input, output, bidirectional, tri_state, passive, unspecified, "
"unspecified, power_in, power_out, open_collector, " "power_in, power_out, open_collector, open_emitter, free or "
"open_emitter, free or no_connect" ); "no_connect" );
return ELECTRICAL_PINTYPE::PT_UNSPECIFIED; return ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
} }
}; };
auto parseShape = [&]( T token ) -> GRAPHIC_PINSHAPE auto parseShape =
{ [&]( T token ) -> GRAPHIC_PINSHAPE
switch( token ) {
{ switch( token )
case T_line: return GRAPHIC_PINSHAPE::LINE; {
case T_inverted: return GRAPHIC_PINSHAPE::INVERTED; case T_line: return GRAPHIC_PINSHAPE::LINE;
case T_clock: return GRAPHIC_PINSHAPE::CLOCK; case T_inverted: return GRAPHIC_PINSHAPE::INVERTED;
case T_inverted_clock: return GRAPHIC_PINSHAPE::INVERTED_CLOCK; case T_clock: return GRAPHIC_PINSHAPE::CLOCK;
case T_input_low: return GRAPHIC_PINSHAPE::INPUT_LOW; case T_inverted_clock: return GRAPHIC_PINSHAPE::INVERTED_CLOCK;
case T_clock_low: return GRAPHIC_PINSHAPE::CLOCK_LOW; case T_input_low: return GRAPHIC_PINSHAPE::INPUT_LOW;
case T_output_low: return GRAPHIC_PINSHAPE::OUTPUT_LOW; case T_clock_low: return GRAPHIC_PINSHAPE::CLOCK_LOW;
case T_edge_clock_high: return GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK; case T_output_low: return GRAPHIC_PINSHAPE::OUTPUT_LOW;
case T_non_logic: return GRAPHIC_PINSHAPE::NONLOGIC; case T_edge_clock_high: return GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK;
case T_non_logic: return GRAPHIC_PINSHAPE::NONLOGIC;
default: default:
Expecting( "line, inverted, clock, inverted_clock, input_low, " Expecting( "line, inverted, clock, inverted_clock, input_low, clock_low, "
"clock_low, output_low, edge_clock_high, non_logic" ); "output_low, edge_clock_high, non_logic" );
return GRAPHIC_PINSHAPE::LINE; return GRAPHIC_PINSHAPE::LINE;
} }
}; };
wxCHECK_MSG( CurTok() == T_pin, nullptr, wxCHECK_MSG( CurTok() == T_pin, nullptr,
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a pin token." ) ); wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a pin token." ) );
@ -2364,7 +2366,7 @@ void SCH_IO_KICAD_SEXPR_PARSER::parseSchSheetInstances( SCH_SHEET* aRootSheet, S
else else
{ {
// Whitespaces are not permitted // Whitespaces are not permitted
for( wxString ch : whitespaces ) for( const wxString& ch : whitespaces )
numReplacements += instance.m_PageNumber.Replace( ch, wxEmptyString ); numReplacements += instance.m_PageNumber.Replace( ch, wxEmptyString );
} }

View File

@ -87,7 +87,7 @@ public:
LIB_SYMBOL* ParseSymbol( LIB_SYMBOL_MAP& aSymbolLibMap, LIB_SYMBOL* ParseSymbol( LIB_SYMBOL_MAP& aSymbolLibMap,
int aFileVersion = SEXPR_SYMBOL_LIB_FILE_VERSION ); int aFileVersion = SEXPR_SYMBOL_LIB_FILE_VERSION );
SCH_ITEM* ParseDrawItem(); SCH_ITEM* ParseSymbolDrawItem();
/** /**
* Parse the internal #LINE_READER object into \a aSheet. * Parse the internal #LINE_READER object into \a aSheet.
@ -139,12 +139,12 @@ private:
int parseInternalUnits( const char* aExpected ); int parseInternalUnits( const char* aExpected );
inline int parseInternalUnits( TSCHEMATIC_T::T aToken ) int parseInternalUnits( TSCHEMATIC_T::T aToken )
{ {
return parseInternalUnits( GetTokenText( aToken ) ); return parseInternalUnits( GetTokenText( aToken ) );
} }
inline VECTOR2I parseXY() VECTOR2I parseXY()
{ {
VECTOR2I xy; VECTOR2I xy;
@ -196,7 +196,7 @@ private:
SCH_SHAPE* parseSymbolArc(); SCH_SHAPE* parseSymbolArc();
SCH_SHAPE* parseSymbolBezier(); SCH_SHAPE* parseSymbolBezier();
SCH_SHAPE* parseSymbolCircle(); SCH_SHAPE* parseSymbolCircle();
SCH_PIN* parsePin(); SCH_PIN* parseSymbolPin();
SCH_SHAPE* parseSymbolPolyLine(); SCH_SHAPE* parseSymbolPolyLine();
SCH_SHAPE* parseSymbolRectangle(); SCH_SHAPE* parseSymbolRectangle();
SCH_TEXT* parseSymbolText(); SCH_TEXT* parseSymbolText();

View File

@ -250,6 +250,12 @@ void SCH_PAINTER::draw( const EDA_ITEM* aItem, int aLayer, bool aDimmed )
void SCH_PAINTER::drawItemBoundingBox( const EDA_ITEM* aItem ) void SCH_PAINTER::drawItemBoundingBox( const EDA_ITEM* aItem )
{ {
if( const SCH_ITEM* item = dynamic_cast<const SCH_ITEM*>( aItem ) )
{
if( item->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
return;
}
BOX2I box = aItem->GetBoundingBox(); BOX2I box = aItem->GetBoundingBox();
if( aItem->Type() == SCH_SYMBOL_T ) if( aItem->Type() == SCH_SYMBOL_T )
@ -2191,7 +2197,7 @@ static void orientSymbol( LIB_SYMBOL* symbol, int orientation )
for( SCH_ITEM& item : symbol->GetDrawItems() ) for( SCH_ITEM& item : symbol->GetDrawItems() )
{ {
for( int i = 0; i < o.n_rots; i++ ) for( int i = 0; i < o.n_rots; i++ )
item.Rotate( VECTOR2I(0, 0 ), true ); item.Rotate( VECTOR2I( 0, 0 ), true );
if( o.mirror_x ) if( o.mirror_x )
item.MirrorVertically( 0 ); item.MirrorVertically( 0 );

View File

@ -1711,7 +1711,7 @@ wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoC
const BOX2I SCH_PIN::ViewBBox() const const BOX2I SCH_PIN::ViewBBox() const
{ {
return GetBoundingBox( false, true, true ); return GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
} }

View File

@ -161,7 +161,7 @@ public:
/* Cannot use a default parameter here as it will not be compatible with the virtual. */ /* Cannot use a default parameter here as it will not be compatible with the virtual. */
const BOX2I GetBoundingBox() const override const BOX2I GetBoundingBox() const override
{ {
return GetBoundingBox( false, true, m_layer == LAYER_DEVICE ); return GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
} }
/** /**

View File

@ -53,9 +53,19 @@ public:
/** /**
* The default construct creates a transform that draws object is the normal orientation. * The default construct creates a transform that draws object is the normal orientation.
*/ */
TRANSFORM() : x1( 1 ), y1( 0 ), x2( 0 ), y2( -1 ) {} TRANSFORM() :
x1( 1 ),
y1( 0 ),
x2( 0 ),
y2( -1 )
{}
TRANSFORM( int ax1, int ay1, int ax2, int ay2 ) : x1( ax1 ), y1( ay1 ), x2( ax2 ), y2( ay2 ) {} TRANSFORM( int ax1, int ay1, int ax2, int ay2 ) :
x1( ax1 ),
y1( ay1 ),
x2( ax2 ),
y2( ay2 )
{}
bool operator==( const TRANSFORM& aTransform ) const; bool operator==( const TRANSFORM& aTransform ) const;

View File

@ -286,9 +286,7 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer(
} }
else if( elType == wxS( "CIRCLE" ) ) else if( elType == wxS( "CIRCLE" ) )
{ {
std::unique_ptr<PCB_SHAPE> shape = auto shape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::CIRCLE );
std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::CIRCLE );
double width = ConvertSize( arr[4] ); double width = ConvertSize( arr[4] );
shape->SetWidth( width ); shape->SetWidth( width );
@ -311,9 +309,7 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer(
} }
else if( elType == wxS( "RECT" ) ) else if( elType == wxS( "RECT" ) )
{ {
std::unique_ptr<PCB_SHAPE> shape = auto shape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::RECTANGLE );
std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::RECTANGLE );
double width = ConvertSize( arr[8] ); double width = ConvertSize( arr[8] );
shape->SetWidth( width ); shape->SetWidth( width );
@ -447,10 +443,8 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer(
{ {
for( int segId = 0; segId < chain.SegmentCount(); segId++ ) for( int segId = 0; segId < chain.SegmentCount(); segId++ )
{ {
SEG seg = chain.CSegment( segId ); SEG seg = chain.CSegment( segId );
auto shape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::SEGMENT );
std::unique_ptr<PCB_SHAPE> shape =
std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::SEGMENT );
shape->SetLayer( layer ); shape->SetLayer( layer );
shape->SetWidth( lineWidth ); shape->SetWidth( lineWidth );
@ -476,8 +470,7 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer(
{ {
for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() ) for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() )
{ {
std::unique_ptr<PCB_SHAPE> shape = auto shape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::POLY );
std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::POLY );
shape->SetLayer( Edge_Cuts ); shape->SetLayer( Edge_Cuts );
shape->SetFilled( false ); shape->SetFilled( false );
@ -600,19 +593,20 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer(
else else
{ {
// arr[1] is "stroke Width" per docs // arr[1] is "stroke Width" per docs
int minThickness = int minThickness = std::max( pcbIUScale.mmToIU( 0.03 ),
std::max( pcbIUScale.mmToIU( 0.03 ), int( ConvertSize( arr[1] ) ) ); int( ConvertSize( arr[1] ) ) );
zone->SetMinThickness( minThickness ); zone->SetMinThickness( minThickness );
} }
if( arr.size() > 18 ) if( arr.size() > 18 )
{ {
zone->SetThermalReliefSpokeWidth( zone->SetThermalReliefSpokeWidth( std::max( int( ConvertSize( arr[18] ) ),
std::max( int( ConvertSize( arr[18] ) ), zone->GetMinThickness() ) ); zone->GetMinThickness() ) );
} }
else else
{ {
wxFAIL_MSG( wxString::Format( "COPPERAREA unexpected size %d: %s ", arr.size(), wxFAIL_MSG( wxString::Format( "COPPERAREA unexpected size %d: %s ",
arr.size(),
shape ) ); shape ) );
zone->SetThermalReliefSpokeWidth( zone->GetMinThickness() ); zone->SetThermalReliefSpokeWidth( zone->GetMinThickness() );
@ -760,8 +754,7 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer(
for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() ) for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() )
{ {
std::unique_ptr<PCB_SHAPE> shape = auto shape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::POLY );
std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::POLY );
shape->SetFilled( true ); shape->SetFilled( true );
shape->SetPolyShape( poly ); shape->SetPolyShape( poly );