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
{
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 )
{
return r->Type() == m_items.front()->Type();
} ) );
} );
}
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 )
{
return r->IsType( aList );
} ) );
} );
}
const std::vector<EDA_ITEM*> SELECTION::GetItemsSortedBySelectionOrder() const
{
using pairedIterators =
std::pair<decltype( m_items.begin() ), decltype( m_itemsOrders.begin() )>;
using pairedIterators = std::pair<decltype( m_items.begin() ),
decltype( m_itemsOrders.begin() )>;
// Create a vector of all {selection item, selection order} iterator 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" );
if( aSymbol->GetPinNameOffset() != schIUScale.MilsToIU( DEFAULT_PIN_NAME_OFFSET ) )
{
aFormatter.Print( 0, " (offset %s)",
EDA_UNIT_UTILS::FormatInternalUnits( schIUScale,
aSymbol->GetPinNameOffset() ).c_str() );
}
if( !aSymbol->GetShowPinNames() )
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_text:
case T_text_box:
item = ParseDrawItem();
item = ParseSymbolDrawItem();
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_text:
case T_text_box:
item = ParseDrawItem();
item = ParseSymbolDrawItem();
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() )
{
@ -562,7 +562,7 @@ SCH_ITEM* SCH_IO_KICAD_SEXPR_PARSER::ParseDrawItem()
break;
case T_pin:
return parsePin();
return parseSymbolPin();
break;
case T_polyline:
@ -796,7 +796,7 @@ void SCH_IO_KICAD_SEXPR_PARSER::parseEDA_TEXT( EDA_TEXT* aText, bool aConvertOve
NeedSYMBOL();
wxString hyperlink = FromUTF8();
if( !aText->ValidateHyperlink( hyperlink ) )
if( !EDA_TEXT::ValidateHyperlink( hyperlink ) )
{
THROW_PARSE_ERROR( wxString::Format( _( "Invalid hyperlink url '%s'" ), hyperlink ),
CurSource(), CurLine(), CurLineNumber(), CurOffset() );
@ -1415,9 +1415,10 @@ 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 )
{
@ -1436,14 +1437,15 @@ SCH_PIN* SCH_IO_KICAD_SEXPR_PARSER::parsePin()
case T_free: return ELECTRICAL_PINTYPE::PT_NIC;
default:
Expecting( "input, output, bidirectional, tri_state, passive, "
"unspecified, power_in, power_out, open_collector, "
"open_emitter, free or no_connect" );
Expecting( "input, output, bidirectional, tri_state, passive, unspecified, "
"power_in, power_out, open_collector, open_emitter, free or "
"no_connect" );
return ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
}
};
auto parseShape = [&]( T token ) -> GRAPHIC_PINSHAPE
auto parseShape =
[&]( T token ) -> GRAPHIC_PINSHAPE
{
switch( token )
{
@ -1458,8 +1460,8 @@ SCH_PIN* SCH_IO_KICAD_SEXPR_PARSER::parsePin()
case T_non_logic: return GRAPHIC_PINSHAPE::NONLOGIC;
default:
Expecting( "line, inverted, clock, inverted_clock, input_low, "
"clock_low, output_low, edge_clock_high, non_logic" );
Expecting( "line, inverted, clock, inverted_clock, input_low, clock_low, "
"output_low, edge_clock_high, non_logic" );
return GRAPHIC_PINSHAPE::LINE;
}
};
@ -2364,7 +2366,7 @@ void SCH_IO_KICAD_SEXPR_PARSER::parseSchSheetInstances( SCH_SHEET* aRootSheet, S
else
{
// Whitespaces are not permitted
for( wxString ch : whitespaces )
for( const wxString& ch : whitespaces )
numReplacements += instance.m_PageNumber.Replace( ch, wxEmptyString );
}

View File

@ -87,7 +87,7 @@ public:
LIB_SYMBOL* ParseSymbol( LIB_SYMBOL_MAP& aSymbolLibMap,
int aFileVersion = SEXPR_SYMBOL_LIB_FILE_VERSION );
SCH_ITEM* ParseDrawItem();
SCH_ITEM* ParseSymbolDrawItem();
/**
* Parse the internal #LINE_READER object into \a aSheet.
@ -139,12 +139,12 @@ private:
int parseInternalUnits( const char* aExpected );
inline int parseInternalUnits( TSCHEMATIC_T::T aToken )
int parseInternalUnits( TSCHEMATIC_T::T aToken )
{
return parseInternalUnits( GetTokenText( aToken ) );
}
inline VECTOR2I parseXY()
VECTOR2I parseXY()
{
VECTOR2I xy;
@ -196,7 +196,7 @@ private:
SCH_SHAPE* parseSymbolArc();
SCH_SHAPE* parseSymbolBezier();
SCH_SHAPE* parseSymbolCircle();
SCH_PIN* parsePin();
SCH_PIN* parseSymbolPin();
SCH_SHAPE* parseSymbolPolyLine();
SCH_SHAPE* parseSymbolRectangle();
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 )
{
if( const SCH_ITEM* item = dynamic_cast<const SCH_ITEM*>( aItem ) )
{
if( item->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
return;
}
BOX2I box = aItem->GetBoundingBox();
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( int i = 0; i < o.n_rots; i++ )
item.Rotate( VECTOR2I(0, 0 ), true );
item.Rotate( VECTOR2I( 0, 0 ), true );
if( o.mirror_x )
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
{
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. */
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.
*/
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;

View File

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