26#include <wx/filename.h>
28#include <wx/mstream.h>
64constexpr int PLACEMENT_GRID = 12700;
67constexpr int BUS_SIGNAL = 65502;
70constexpr int SIGNAL_GAP = 254;
73constexpr int MAX_DIAGONAL_STEPS = 8;
76constexpr int NEAR_MISS = 1000;
79constexpr int LABEL_REACH = 50800;
81const wxString LIB_NAME = wxS(
"target3001" );
86 int quadrant = ( (int) std::lround( aDirection / 90.0f ) % 4 + 4 ) % 4;
148int textQuadrant(
float aDirection )
150 return ( (
int) std::lround( aDirection / 90.0f ) % 4 + 4 ) % 4;
155bool isHiddenText(
const ELEMENT& aElem )
165 if( child.
type == ELEMENT_TYPE::TEXT && child.
text.
function == uint8_t( TEXT_FUNCTION::PIN_NAME ) )
174bool isUnplacedGate(
const ELEMENT& aGate )
233 if( dir.
Cross( c - a ) || dir.
Cross( d - a ) )
236 auto along = [&](
const VECTOR2I& aPos )
238 return dir.
Dot( aPos - a );
241 return std::min( std::max( along( a ), along( b ) ), std::max( along( c ), along( d ) ) )
242 > std::max( std::min( along( a ), along( b ) ), std::min( along( c ), along( d ) ) );
253 bool aUseRightEnd =
true )
257 aFonts.
Apply( aText, aElem, 100 );
259 int quadrant = textQuadrant( src.
direction );
260 bool upsideDown = quadrant >= 2;
261 bool fromEnd = upsideDown != ( src.
mirrored != 0 );
269 if(
end && aUseRightEnd )
302 return KiROUND( aLength / 100.0 );
328 if( !isUnplacedGate( s ) )
336 if( e.
type == ELEMENT_TYPE::SIGNAL && e.
signal )
348 for(
int sheet : used )
359 if( e.
type == ELEMENT_TYPE::SIGNAL && e.
signal )
366 for(
const auto& [sheet, items] :
m_netItems )
387 it->second.
Merge( bbox );
401 case ELEMENT_TYPE::LINE:
421 case ELEMENT_TYPE::RECTANGLE:
432 VECTOR2D corners[4] = { { 0.0, 0.0 }, { double( r.
width ), 0.0 },
445 case ELEMENT_TYPE::TRIANGLE:
456 case ELEMENT_TYPE::DISC:
464 case ELEMENT_TYPE::ARC:
471 if(
sweep >= 360.0 - 1e-6 )
479 auto at = [&](
double aDeg )
491 case ELEMENT_TYPE::TEXT:
493 if( isHiddenText( aElem ) )
499 std::pair<int32_t, int32_t> pos = configureText(
text, aElem,
m_fonts );
512 if( aElem.
type != ELEMENT_TYPE::RECTANGLE )
520 if( data.empty() || size.
x == 0 || size.
y == 0 )
523 wxMemoryInputStream stream( data.data(), data.size() );
525 if( !
image.LoadFile( stream, wxBITMAP_TYPE_ANY ) )
529 int w =
image.GetWidth();
530 int h =
image.GetHeight();
531 int stretchedW = std::max( w,
KiROUND(
double( h ) * size.
x / size.
y ) );
532 int stretchedH = std::max( h,
KiROUND(
double( w ) * size.
y / size.
x ) );
534 if( stretchedW > w + 1 || stretchedH > h + 1 )
535 image.Rescale( stretchedW, stretchedH, wxIMAGE_QUALITY_HIGH );
566 std::vector<const ELEMENT*> gates;
571 gates.push_back( &s );
577 std::stable_sort( gates.begin(), gates.end(),
580 return a->symbol->gateOrdinal < b->symbol->gateOrdinal;
583 bool hasPackage = std::any_of(
comp.packageItems.begin(),
comp.packageItems.end(),
584 [](
const ELEMENT& e ) { return e.type == ELEMENT_TYPE::PACKAGE; } );
585 bool allSupply =
true;
586 int supplySignal = 0;
588 for(
const ELEMENT* gate : gates )
592 if( child.
type != ELEMENT_TYPE::PIN )
597 else if( !supplySignal )
602 bool isPower = !hasPackage && allSupply && supplySignal;
604 wxString reference =
ToWx(
comp.prefix ).Trim().Trim(
false );
605 uint16_t number =
comp.referenceExtension.value_or(
comp.referenceNumber );
608 reference = wxString::Format( wxS(
"#PWR%03d" ), ++
m_powerCount );
612 wxString value =
ToWx(
comp.value );
614 const ELEMENT* sig = isPower ?
m_project.FindSignal( supplySignal ) :
nullptr;
616 if( sig && !sig->
signal->name.empty() )
620 wxString symName =
ToWx(
comp.name );
622 if( symName.IsEmpty() )
625 symName = wxString::Format( wxS(
"%s_%d" ), symName,
int( aComponent.
base.
component ) );
627 symName.Replace( wxS(
"/" ), wxS(
"_" ) );
638 std::map<uint16_t, wxString> padNumbers;
642 if( item.
type == ELEMENT_TYPE::PAD )
643 padNumbers.emplace( item.
pad.
number, PadNumber( item ) );
648 for(
size_t g = 0; g < gates.size(); g++ )
650 const ELEMENT& gate = *gates[g];
652 if( isUnplacedGate( gate ) )
665 if( !
comp.package.empty() )
668 bool refShown =
false;
669 bool valueShown =
false;
674 std::pair<int32_t, int32_t> pos = configureText( field, aText,
m_fonts );
682 if( child.
type != ELEMENT_TYPE::TEXT )
685 if( child.
text.
function == uint8_t( TEXT_FUNCTION::REFERENCE ) )
687 else if( child.
text.
function == uint8_t( TEXT_FUNCTION::VALUE ) )
692 if( isPower && !valueShown )
696 if( child.
type != ELEMENT_TYPE::PIN )
724 if( child.
type == ELEMENT_TYPE::PIN )
747 bool aFieldTexts,
const std::map<uint16_t, wxString>& aPadNumbers )
const
749 bool showNumbers =
false;
750 bool showNames =
false;
753 std::vector<SCH_PIN*> hiddenNames;
755 for(
size_t g = 0; g < aGates.size(); g++ )
757 const ELEMENT& gate = *aGates[g];
759 int unit = int( g ) + 1;
763 if( child.
type == ELEMENT_TYPE::PIN )
767 const ELEMENT* nameText = pinNameText( child );
771 bool nameShown = nameText && !isHiddenText( *nameText ) && !
name.IsEmpty() && !aLib->
IsPower();
780 std::pair<int32_t, int32_t> pos = configureText( &probe, *nameText,
m_fonts );
794 pin->SetType( pinType( child ) );
795 pin->SetShape( pinShape( src ) );
796 pin->SetName(
name.IsEmpty() ? wxString( wxS(
"~" ) ) :
name );
797 pin->SetUnit( unit );
801 const std::string* padName = child.
base.
FindProp(
"PADNAME" );
803 if(
pad != aPadNumbers.end() )
804 pin->SetNumber(
pad->second );
805 else if( padName && !padName->empty() )
806 pin->SetNumber(
ToWx( *padName ) );
808 pin->SetNumber( wxString::Format( wxS(
"%u" ), src.
pinNumber ) );
810 if( !nameShown && !
name.IsEmpty() )
811 hiddenNames.push_back(
pin );
815 showNames |= nameShown;
820 if( aFieldTexts && child.
type == ELEMENT_TYPE::TEXT
821 && ( child.
text.
function == uint8_t( TEXT_FUNCTION::REFERENCE )
822 || child.
text.
function == uint8_t( TEXT_FUNCTION::VALUE ) ) )
828 if( child.
type == ELEMENT_TYPE::RECTANGLE && child.
base.
FindProp(
"JPEG_PICTURE" ) )
833 item->SetUnit( unit );
843 pin->SetNameTextSize( 0 );
851 if( ( alongVotes ? alongVotes : acrossVotes ) > 0 )
859 bool isBus = aSignal.
base.
signal == BUS_SIGNAL;
876 case ELEMENT_TYPE::LINE:
884 case ELEMENT_TYPE::DISC:
889 case ELEMENT_TYPE::TEXT:
891 bool signalName = e.
text.
function == uint8_t( TEXT_FUNCTION::SIGNAL_NAME );
894 if( isHiddenText( e ) && !signalName )
898 std::optional<VECTOR2I>
anchor;
912 configureText( label, e,
m_fonts,
false );
933 if( aSignal.
signal->name.empty() )
940 std::set<int> sheets;
951 sheets.insert(
pin.sheet );
954 return sheets.size() > 1;
961 std::optional<VECTOR2I> best;
963 auto consider = [&](
const VECTOR2I& aCandidate )
965 SEG::ecoord dist = ( aCandidate - aPos ).SquaredEuclideanNorm();
967 if( dist <=
SEG::Square( LABEL_REACH ) && ( !best || dist < ( *best - aPos ).SquaredEuclideanNorm() ) )
973 if( e.
type != ELEMENT_TYPE::LINE ||
sheetOf( e ) != aSheet )
980 if( ( nearest - wire.
A ).Cross( wire.
B - wire.
A ) != 0 )
995 if(
pin.sheet == aSheet )
1006 std::map<int, std::map<int, std::vector<SCH_ITEM*>>> bySignal;
1008 for(
const auto& [sheet, items] :
m_netItems )
1010 for(
const auto& [item, signal] : items )
1011 bySignal[signal][sheet].push_back( item );
1014 for(
const auto& [signal, pins] :
m_pinEnds )
1016 if( signal != BUS_SIGNAL )
1024 const std::vector<PIN_END>& pins =
m_pinEnds.at( aSignal );
1026 bool anyNamed =
false;
1027 std::set<int> sheets;
1033 std::vector<std::pair<VECTOR2I, VECTOR2I>> ends;
1036 std::vector<PIECE> unnamed;
1040 sheets.insert(
pin.sheet );
1042 auto isFree = [&](
int aSheet,
const VECTOR2I& aPos )
1044 for(
const auto& [pos, pinSignal] :
m_pinSignals[aSheet] )
1046 if( pos == aPos && pinSignal != aSignal )
1050 for(
const auto& [item, itemSignal] :
m_netItems[aSheet] )
1052 if( itemSignal == aSignal )
1057 if( item->GetPosition() == aPos )
1072 for(
int sheet : sheets )
1074 std::vector<SEG> wires;
1075 std::vector<VECTOR2I> points;
1076 std::set<VECTOR2I> names;
1077 std::set<VECTOR2I> pinPoints;
1079 if(
auto it = aItems.find( sheet ); it != aItems.end() )
1101 if(
pin.sheet == sheet )
1102 pinPoints.insert(
pin.pos );
1105 std::map<VECTOR2I, int>
index;
1106 std::vector<int> parent;
1108 auto node = [&](
const VECTOR2I& aPos )
1110 auto [it, inserted] =
index.emplace( aPos,
int( parent.size() ) );
1113 parent.push_back( it->second );
1118 auto find = [&](
int aNode )
1120 while( parent[aNode] != aNode )
1121 aNode = parent[aNode] = parent[parent[aNode]];
1126 auto unite = [&](
int aFirst,
int aSecond )
1128 parent[
find( aFirst )] =
find( aSecond );
1131 std::vector<VECTOR2I> ends( pinPoints.begin(), pinPoints.end() );
1133 for(
const SEG& wire : wires )
1135 int start = node( wire.A );
1136 unite( start, node( wire.B ) );
1137 ends.push_back( wire.A );
1138 ends.push_back( wire.B );
1141 for(
const VECTOR2I& pos : points )
1147 for(
const VECTOR2I& pos : pinPoints )
1151 for(
const auto& [pos,
id] :
index )
1153 for(
const SEG& wire : wires )
1156 unite(
id,
index.at( wire.A ) );
1160 std::sort( ends.begin(), ends.end(),
1163 return a.x < b.x || ( a.x == b.x && a.y < b.y );
1166 ends.erase( std::unique( ends.begin(), ends.end() ), ends.end() );
1168 for(
size_t i = 0; i < ends.size(); i++ )
1170 for(
size_t j = i + 1; j < ends.size() && ends[j].x - ends[i].x < NEAR_MISS; j++ )
1172 int first =
index.at( ends[i] );
1173 int second =
index.at( ends[j] );
1175 if( ( ends[j] - ends[i] ).EuclideanNorm() >= NEAR_MISS ||
find( first ) ==
find( second ) )
1181 unite( first, second );
1185 std::set<int> named;
1188 named.insert(
find(
index.at( pos ) ) );
1192 if( global &&
pin.power &&
pin.sheet == sheet )
1196 std::map<VECTOR2I, int> endCount;
1197 std::map<VECTOR2I, VECTOR2I> outward;
1199 for(
const SEG& wire : wires )
1203 outward[wire.A] = wire.A - wire.B;
1204 outward[wire.B] = wire.B - wire.A;
1211 if(
pin.sheet != sheet )
1216 if( named.count( root ) )
1222 if( !seen.insert( root ).second )
1227 for(
const auto& [pos, count] : endCount )
1229 if( count == 1 && !pinPoints.count( pos ) &&
find(
index.at( pos ) ) == root )
1230 piece.ends.emplace_back( pos, outward.at( pos ) );
1233 unnamed.push_back( std::move( piece ) );
1239 if( unnamed.size() + ( anyNamed ? 1 : 0 ) < 2 || !sig || sig->
signal->name.empty() )
1251 for(
const PIECE& piece : unnamed )
1253 int sheet = piece.pin->sheet;
1258 switch( pinOrientation( piece.pin->direction ) )
1266 for(
const auto& [
end, dir] : piece.ends )
1268 if( isFree( sheet,
end ) )
1271 spin = spinAlong( dir );
1292 m_netItems[aSheet].emplace_back( aItem, aSignal );
1298 std::vector<std::pair<SCH_LINE*, int>> wires;
1299 std::vector<SCH_LINE*> buses;
1300 std::vector<std::pair<SCH_ITEM*, int>> points;
1302 for(
const auto& [item, signal] :
m_netItems[aSheet] )
1305 points.emplace_back( item, signal );
1306 else if( signal == BUS_SIGNAL )
1307 buses.push_back(
static_cast<SCH_LINE*
>( item ) );
1309 wires.emplace_back(
static_cast<SCH_LINE*
>( item ), signal );
1313 for(
const auto& [wire, signal] : wires )
1315 for(
int end : { 0, 1 } )
1320 bool onBus = std::any_of( buses.begin(), buses.end(),
1323 return IsPointOnSegment( bus->GetStartPoint(), bus->GetEndPoint(), pos );
1326 if( !onBus ||
moved == pos )
1330 bool labeled =
false;
1332 for(
const auto& [item, itemSignal] : points )
1334 if( itemSignal != signal )
1337 if( item->GetPosition() == pos )
1338 item->SetPosition(
moved );
1341 &&
IsPointOnSegment( wire->GetStartPoint(), wire->GetEndPoint(), item->GetPosition() );
1346 if( labeled || !sig || sig->
signal->name.empty() )
1361 points.emplace_back( label, signal );
1366 auto hasBranch = [&](
const std::pair<SCH_LINE*, int>& aWire )
1368 return std::any_of( points.begin(), points.end(),
1369 [&](
const std::pair<SCH_ITEM*, int>& aPoint )
1371 return aPoint.second == aWire.second
1372 && passesThrough( aWire.first, aPoint.first->GetPosition() );
1378 size_t drawn = wires.size();
1380 for(
size_t i = 0; i < drawn; i++ )
1382 for(
size_t j = i + 1; j < drawn; j++ )
1384 if( wires[i].second == wires[j].second || !overlaps( wires[i].first, wires[j].first ) )
1387 bool firstShorter = wires[i].first->GetLength() <= wires[j].first->GetLength();
1388 std::pair<SCH_LINE*, int> pick = firstShorter ? wires[i] : wires[j];
1390 if( hasBranch( pick ) )
1391 pick = firstShorter ? wires[j] : wires[i];
1395 if( hasBranch( pick ) || wire->
GetLength() <= 2 * SIGNAL_GAP )
1403 for(
const auto& [from, to] : { std::pair( start, start + side ), std::pair(
end + side,
end ) } )
1409 wires.emplace_back( stub, pick.second );
1427 std::map<VECTOR2I, std::vector<MEMBER>> at;
1428 std::set<VECTOR2I> busEnds;
1430 for(
const auto& [wire, signal] : wires )
1432 for(
int end : { 0, 1 } )
1433 at[wireEnd( wire,
end )].push_back( { signal, wire,
end,
false } );
1436 for(
const auto& [pos, signal] :
m_pinSignals[aSheet] )
1437 at[pos].push_back( { signal,
nullptr, -1,
true } );
1439 for(
const auto& [item, signal] : points )
1440 at[item->GetPosition()].push_back( { signal, item, -1,
false } );
1444 busEnds.insert( bus->GetStartPoint() );
1445 busEnds.insert( bus->GetEndPoint() );
1448 for(
auto& [pos, members] : at )
1451 bool joinsBus = std::any_of( members.begin(), members.end(),
1452 [](
const MEMBER& m )
1457 if( joinsBus && busEnds.count( pos ) )
1458 members.push_back( { BUS_SIGNAL,
nullptr, -1,
true } );
1460 for(
const auto& [wire, signal] : wires )
1462 if( passesThrough( wire, pos ) )
1463 members.push_back( { signal, wire, -1,
true } );
1468 if( joinsBus && passesThrough( bus, pos ) )
1469 members.push_back( { BUS_SIGNAL, bus, -1,
true } );
1474 auto isFree = [&](
const VECTOR2I& aPos )
1476 auto onLine = [&](
SCH_LINE* aLine )
1481 return !at.count( aPos ) && std::none_of( buses.begin(), buses.end(), onLine )
1482 && std::none_of( wires.begin(), wires.end(),
1483 [&](
const std::pair<SCH_LINE*, int>& aWire )
1485 return onLine( aWire.first );
1490 auto endAt = [&](
const MEMBER* aMember,
const VECTOR2I& aPos ) -> std::pair<SCH_LINE*, int>
1494 if( wireEnd( line, aMember->end ) == aPos )
1495 return { line, aMember->end };
1497 for(
const auto& [wire, signal] : wires )
1499 for(
int end : { 0, 1 } )
1501 if( signal == aMember->signal && wireEnd( wire,
end ) == aPos )
1502 return { wire,
end };
1506 return { line, aMember->end };
1509 for(
const auto& [pos, members] : at )
1511 std::map<int, std::vector<const MEMBER*>> groups;
1512 std::set<int> fixed;
1513 std::set<int> pinned;
1515 for(
const MEMBER& m : members )
1517 groups[m.signal].push_back( &m );
1520 fixed.insert( m.signal );
1522 if( m.fixed && !m.item )
1523 pinned.insert( m.signal );
1527 if( groups.size() < 2 || pinned.size() > 1 )
1530 int keeper = groups.begin()->first;
1532 for(
const auto& [signal,
group] : groups )
1534 if( fixed.count( signal ) > fixed.count( keeper )
1535 || ( fixed.count( signal ) == fixed.count( keeper ) &&
group.size() > groups.at( keeper ).size() ) )
1541 if( !pinned.empty() )
1542 keeper = *pinned.begin();
1546 for(
const auto& [signal,
group] : groups )
1548 if( signal == keeper )
1553 if( fixed.count( signal ) )
1556 std::optional<VECTOR2I> side =
bendAround( aSheet, signal, pos, wires, isFree );
1561 moved = pos + *side;
1567 [](
const MEMBER* m )
1572 bool oneEnd = std::count_if(
group.begin(),
group.end(),
1573 [](
const MEMBER* m )
1581 auto [line, lineEnd] = endAt( *
end, pos );
1582 moved = stepIn( line, lineEnd );
1591 moved = pos +
VECTOR2I( step * SIGNAL_GAP, step * SIGNAL_GAP );
1592 }
while( !isFree(
moved ) && step < MAX_DIAGONAL_STEPS );
1596 for(
const MEMBER* m :
group )
1600 auto [line, lineEnd] = endAt( m, pos );
1601 setWireEnd( line, lineEnd,
moved );
1603 else if( !m->fixed )
1605 m->item->SetPosition(
moved );
1614 std::vector<std::pair<SCH_LINE*, int>>& aWires,
1615 const std::function<
bool(
const VECTOR2I& )>& aIsFree )
1617 std::vector<SCH_LINE*> lines;
1619 for(
const auto& [wire, signal] : aWires )
1621 if( signal == aSignal && passesThrough( wire, aPos ) )
1622 lines.push_back( wire );
1626 return std::nullopt;
1628 VECTOR2I dir = lines[0]->GetEndPoint() - lines[0]->GetStartPoint();
1632 VECTOR2I span = line->GetEndPoint() - line->GetStartPoint();
1635 if( span.
Cross( dir ) || ( aPos - line->GetStartPoint() ).EuclideanNorm() <= 2 * SIGNAL_GAP
1636 || ( line->GetEndPoint() - aPos ).EuclideanNorm() <= 2 * SIGNAL_GAP )
1638 return std::nullopt;
1645 for(
int k : { 1, -1, 2, -2, 3, -3 } )
1647 if( aIsFree( aPos +
normal * k ) )
1656 VECTOR2I along = ( line->GetEndPoint() - line->GetStartPoint() ).Resize( SIGNAL_GAP );
1661 line->SetEndPoint( before );
1663 for(
const auto& [from, to] : { std::pair( before, before + side ), std::pair( before + side, after + side ),
1664 std::pair( after + side, after ), std::pair( after,
end ) } )
1670 aWires.emplace_back( piece, aSignal );
1685 if( aElem.
type == ELEMENT_TYPE::SYMBOL && aElem.
symbol )
1732 return it->second->GetScreen();
1747 fn.SetName( fn.GetName() + wxString::Format( wxS(
"_%d" ), aSheet ) );
1757 if( aSheet - 1 <
int(
m_project.settings.sheetNames.size() ) )
1760 if(
name.IsEmpty() )
1761 name = wxString::Format( wxS(
"Sheet %d" ), aSheet );
1773 const int margin =
schIUScale.mmToIU( PAGE_MARGIN_MM );
1781 auto snap = [](
int v )
1783 return KiROUND(
double( v ) / PLACEMENT_GRID ) * PLACEMENT_GRID;
1795 item->Move( offset );
1802 std::vector<SCH_SHEET*> sheets;
1804 for(
const auto& [number, sheet] :
m_sheets )
1805 sheets.push_back( sheet );
1812 for(
const auto& [number, sheet] :
m_sheets )
1813 sheet->GetScreen()->SetPageNumber( wxString::Format( wxS(
"%d" ), page++ ) );
constexpr EDA_IU_SCALE schIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
void SetImageType(wxBitmapType aType)
Set the bitmap type (png, jpeg, etc.)
constexpr size_type GetWidth() const
constexpr Vec Centre() const
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr size_type GetHeight() const
constexpr coord_type GetLeft() const
constexpr coord_type GetTop() const
virtual VECTOR2I GetPosition() const
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
KICAD_T Type() const
Returns the type of object.
virtual void SetEnd(const VECTOR2I &aEnd)
virtual void SetCenter(const VECTOR2I &aCenter)
virtual void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual int GetTextHeight() const
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
virtual void SetVisible(bool aVisible)
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
A logical library item identifier and consists of various portions much like a URI.
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Define a library symbol object.
const LIB_ID & GetLibId() const override
bool IsPower() const override
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
void SetUnitCount(int aCount, bool aDuplicateDrawItems)
Set the units per symbol count.
SCH_FIELD & GetValueField()
void SetLibId(const LIB_ID &aLibId)
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
SCH_FIELD & GetReferenceField()
Describe the page size and margins of a paper page on which to eventually print or plot.
void SetWidthMM(double aWidthInMM)
void SetHeightMM(double aHeightInMM)
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
BITMAP_BASE & MutableImage() const
Only use this if you really need to modify the underlying image.
void Rotate(const VECTOR2I &aCenter, const EDA_ANGLE &aAngle)
Rotate the image about aCenter.
bool SetImage(const wxImage &aImage)
Set the image from an existing wxImage.
void SetPosition(const VECTOR2I &aPos)
void SetWidth(int aWidth)
A pure virtual class used to derive REPORTER objects from.
Holds all the data relating to one schematic.
Object to handle a bitmap image that can be inserted in a schematic.
REFERENCE_IMAGE & GetReferenceImage()
void SetPosition(const VECTOR2I &aPosition) override
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
SCH_ITEM * Duplicate(bool addToParentGroup, SCH_COMMIT *aCommit=nullptr, bool aDoClone=false) const
Routine to create a new copy of given item.
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
Segment description base class to describe items which have 2 end points (track, wire,...
void SetStartPoint(const VECTOR2I &aPosition)
VECTOR2I GetEndPoint() const
VECTOR2I GetStartPoint() const
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
bool IsEndPoint(const VECTOR2I &aPoint) const override
Test if aPt is an end point of this schematic object.
void SetEndPoint(const VECTOR2I &aPosition)
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void SetPageSettings(const PAGE_INFO &aPageSettings)
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
void SetStroke(const STROKE_PARAMS &aStroke) override
void AddPoint(const VECTOR2I &aPosition)
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
void SetFileName(const wxString &aFilename)
void SetName(const wxString &aName)
SCH_SCREEN * GetScreen() const
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
void SetExcludedFromSim(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from simulation flag.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the base reference for the given sheet path for this symbol.
void SetFootprintFieldText(const wxString &aFootprint)
void SetExcludedFromBOM(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from schematic bill of materials flag.
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
void SetExcludedFromBoard(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
void SetPosition(const VECTOR2I &aPosition) override
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
VECTOR2I::extended_type ecoord
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
static SEG::ecoord Square(int a)
Spin style for labels of all kinds on schematics.
Simple container to manage line stroke parameters.
virtual void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
virtual void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
static VECTOR2I BaselineShift(const EDA_TEXT &aText)
Offset in text units that moves aText so the baseline-left point of its first glyph lies on its posit...
void Apply(EDA_TEXT *aText, const ELEMENT &aElem, int aUnit)
Give aText the font, style, size and stroke width of text aElem.
void addNetItem(int aSheet, SCH_ITEM *aItem, int aSignal)
Add a wire, junction or label of signal aSignal; separateSignals() keeps it apart from other signals.
const TARGET3001::PROJECT & m_project
TARGET3001_SCH_BUILDER(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const TARGET3001::PROJECT &aProject, const wxString &aFileName, REPORTER *aReporter)
void addToSheet(int aSheet, SCH_ITEM *aItem)
void addFreeItem(const TARGET3001::ELEMENT &aElem)
bool joinsGlobally(const TARGET3001::ELEMENT &aSignal) const
True when the signal's labels must be global: it reaches several sheets or meets supply symbols.
static VECTOR2I toSch(int32_t aX, int32_t aY)
Sheet position in KiCad units, before the per-sheet page offset is applied.
std::map< int, std::vector< PIN_END > > m_pinEnds
placed pins of each signal, by signal ID
SCH_BITMAP * makePicture(const TARGET3001::ELEMENT &aElem) const
Image a rectangle shows instead of its fill, or nullptr when it has none.
std::map< int, std::set< int > > m_powerSheets
sheets holding a power symbol, by signal ID
void joinSignalPieces()
Join the pieces of every signal as separateSignals() left them; see joinPieces()
SCH_ITEM * makeGraphic(const TARGET3001::ELEMENT &aElem, const VECTOR2I &aOrigin, bool aInSymbol) const
Add graphics shared by free items and symbol bodies; returns nullptr for unsupported items.
std::map< int, BOX2I > m_extents
drawn extent of each sheet
void addFreeSymbol(const TARGET3001::ELEMENT &aSymbol)
void joinPieces(int aSignal, const std::map< int, std::vector< SCH_ITEM * > > &aItems)
Join the pieces of signal aSignal that KiCad would see apart, since the file joins a signal's items b...
std::map< int, std::vector< std::pair< SCH_ITEM *, int > > > m_netItems
items and their signal, by sheet
std::map< int, std::vector< std::pair< VECTOR2I, int > > > m_pinSignals
pin points and signal, by sheet
TARGET3001::FONTS m_fonts
lookup cache, filled while drawing
std::optional< VECTOR2I > labelAnchor(const TARGET3001::ELEMENT &aSignal, int aSheet, const VECTOR2I &aPos) const
Point on the signal's own wires or pins nearest a name drawn at aPos, if it is close enough to name t...
std::optional< VECTOR2I > bendAround(int aSheet, int aSignal, const VECTOR2I &aPos, std::vector< std::pair< SCH_LINE *, int > > &aWires, const std::function< bool(const VECTOR2I &)> &aIsFree)
Bend the wires of aSignal that pass through aPos around it, one gap aside on a side aIsFree accepts,...
void addGateBodies(LIB_SYMBOL *aLib, const std::vector< const TARGET3001::ELEMENT * > &aGates, bool aFieldTexts, const std::map< uint16_t, wxString > &aPadNumbers={}) const
Draw each gate's body as one unit of aLib; aFieldTexts leaves reference and value texts to fields.
void addComponent(const TARGET3001::ELEMENT &aComponent)
void addConnections(const TARGET3001::ELEMENT &aSignal)
std::map< int, std::vector< SCH_ITEM * > > m_pending
std::set< int > m_globalSignals
signals joined by global labels
void separateSignals(int aSheet)
Move apart items of different signals that touch where KiCad would join them, since the file connects...
SCH_SCREEN * screen(int aSheet)
Screen for a 1-based sheet number, created on first use.
std::map< int, SCH_SHEET * > m_sheets
by 1-based sheet number
static int sheetOf(const TARGET3001::ELEMENT &aElem)
Sheet number of a schematic element, or 0 for board elements.
constexpr extended_type Cross(const VECTOR2< T > &aVector) const
Compute cross product of self with aVector.
constexpr extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
constexpr extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
static constexpr EDA_ANGLE ANGLE_VERTICAL
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
@ FILLED_SHAPE
Fill with object color.
static const std::string KiCadSchematicFileExtension
SCH_LAYER_ID
Eeschema drawing layers.
constexpr double PAGE_MARGIN_MM
Margin added on every side of the drawn extents before choosing a page, in millimetres.
constexpr int SCHEMATIC_SHEET_COUNT
Sheets occupy layers 101 to 200.
wxString ToWx(const std::string &aRaw)
Convert a stored ANSI string to a wxString.
ELEMENT_TYPE
Element class tags as stored in the file.
constexpr int SCHEMATIC_LAYER_BASE
First layer number used for schematic sheets; sheet N (1-based) is layer 100 + N.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
@ PT_INPUT
usual pin input: must be connected
@ PT_NC
not connected (must be left open)
@ PT_TRISTATE
tri state bus pin
@ PT_NIC
not internally connected (may be connected to anything)
@ PT_BIDI
input or output (like port for a microprocessor)
@ PT_OPENCOLLECTOR
pin type open collector
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
PIN_ORIENTATION
The symbol library pin object orientations.
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
@ PIN_RIGHT
The pin extends rightwards from the connection point.
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
LINE_STYLE
Dashed line types.
Stroked arc or circle. The base position is the start point.
double Sweep() const
Counter-clockwise sweep in (0, 360]; equal angles give a full circle.
float startAngle
degrees, counter-clockwise from +X
Fields shared by every drawable element.
std::vector< uint8_t > Picture() const
Encoded image a rectangle shows stretched over its area instead of its fill, empty for none.
uint16_t component
ID of the owning component (a component stores its own), 0 for none.
uint16_t signal
ID of the owning signal (a signal stores its own), 0 for none.
std::optional< std::pair< int32_t, int32_t > > TextRightEnd() const
Right end of right-aligned text from its ARXY property, in file coordinates.
const std::string * FindProp(const std::string &aKey) const
Return the value of the first property named aKey, if any.
One element of any class.
std::shared_ptr< COMPONENT > component
std::shared_ptr< SYMBOL > symbol
std::shared_ptr< SIGNAL > signal
std::vector< ELEMENT > children
Children of a pin (its number text).
uint8_t dashStyle
0 solid, 1 long dash, 2 dash-dot, 3 other, 4 short dash
Schematic pin. The base position is the connection point; the pin extends along direction.
Filled rectangle anchored at a corner (the base position); sizes are signed.
Filled triangle given by three absolute corners (the first is the base position).
wxString ToWx(const std::string &aRaw)
Convert a stored ANSI string to a wxString.
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
static double sweep(float aStart, float aEnd)
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
bool IsPointOnSegment(const VECTOR2I &aSegStart, const VECTOR2I &aSegEnd, const VECTOR2I &aTestPoint)
Test if aTestPoint is on line defined by aSegStart and aSegEnd.
double DEG2RAD(double deg)
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
VIA_CROSS_SECTION_GEOMETRY::PIECE PIECE
Definition of file extensions used in Kicad.