From 3d9c25494c0cb2bbecd6619b557f263a81fcc0b4 Mon Sep 17 00:00:00 2001 From: Russell Oliver Date: Sun, 18 Feb 2018 21:54:37 +1100 Subject: [PATCH] Revert "Eagle importer: use only global net labels" This reverts commit b1f456fade43284408f6ca88f9c6c5d6e2527fef. --- eeschema/sch_eagle_plugin.cpp | 193 ++++++++++++++++++++++++++-------- eeschema/sch_eagle_plugin.h | 2 + 2 files changed, 152 insertions(+), 43 deletions(-) diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index 57e2d0f3f1..c6dc2166a8 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -471,6 +471,38 @@ void SCH_EAGLE_PLUGIN::loadDrawing( wxXmlNode* aDrawingNode ) } +void SCH_EAGLE_PLUGIN::countNets( wxXmlNode* aSchematicNode ) +{ + // Map all children into a readable dictionary + NODE_MAP schematicChildren = MapChildren( aSchematicNode ); + // Loop through all the sheets + wxXmlNode* sheetNode = schematicChildren["sheets"]->GetChildren(); + + while( sheetNode ) + { + NODE_MAP sheetChildren = MapChildren( sheetNode ); + // Loop through all nets + // From the DTD: "Net is an electrical connection in a schematic." + wxXmlNode* netNode = getChildrenNodes( sheetChildren, "nets" ); + + while( netNode ) + { + wxString netName = netNode->GetAttribute( "name" ); + + if( m_netCounts.count( netName ) ) + m_netCounts[netName] = m_netCounts[netName] + 1; + else + m_netCounts[netName] = 1; + + // Get next net + netNode = netNode->GetNext(); + } + + sheetNode = sheetNode->GetNext(); + } +} + + void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode ) { // Map all children into a readable dictionary @@ -502,6 +534,10 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode ) libraryNode = libraryNode->GetNext(); } + // find all nets and count how many sheets they appear on. + // local labels will be used for nets found only on that sheet. + countNets( aSchematicNode ); + // Loop through all the sheets wxXmlNode* sheetNode = schematicChildren["sheets"]->GetChildren(); @@ -721,6 +757,8 @@ void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, const wxString& n wxXmlNode* currentSegment = aSegmentsNode->GetChildren(); SCH_SCREEN* screen = m_currentSheet->GetScreen(); + int segmentCount = countChildren( aSegmentsNode, "segment" ); + // wxCHECK( screen, [>void<] ); while( currentSegment ) { @@ -788,12 +826,25 @@ void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, const wxString& n { wxString netname = escapeName( netName ); - std::unique_ptr glabel( new SCH_GLOBALLABEL ); - glabel->SetPosition( wire->GetStartPoint() ); - glabel->SetText( netname ); - glabel->SetTextSize( wxSize( 20, 20 ) ); - glabel->SetLabelSpinStyle( 0 ); - screen->Append( glabel.release() ); + // Add a global label if the net appears on more than one Eagle sheet + if( m_netCounts[netName.ToStdString()] > 1 ) + { + std::unique_ptr glabel( new SCH_GLOBALLABEL ); + glabel->SetPosition( wire->GetStartPoint() ); + glabel->SetText( netname ); + glabel->SetTextSize( wxSize( 10, 10 ) ); + glabel->SetLabelSpinStyle( 0 ); + screen->Append( glabel.release() ); + } + else if( segmentCount > 1 ) + { + std::unique_ptr label( new SCH_LABEL ); + label->SetPosition( wire->GetStartPoint() ); + label->SetText( netname ); + label->SetTextSize( wxSize( 10, 10 ) ); + label->SetLabelSpinStyle( 0 ); + screen->Append( label.release() ); + } } @@ -851,56 +902,112 @@ SCH_TEXT* SCH_EAGLE_PLUGIN::loadLabel( wxXmlNode* aLabelNode, const DLIST& segmentWires ) { auto elabel = ELABEL( aLabelNode, aNetName ); + wxPoint elabelpos( elabel.x.ToSchUnits(), -elabel.y.ToSchUnits() ); + wxString netname = escapeName( elabel.netname ); - std::unique_ptr glabel( new SCH_GLOBALLABEL ); - glabel->SetPosition( elabelpos ); - glabel->SetText( netname ); - glabel->SetTextSize( wxSize( elabel.size.ToSchUnits(), elabel.size.ToSchUnits() ) ); - glabel->SetLabelSpinStyle( 2 ); - if( elabel.rot ) + // Determine if the Label is a local and global label based on the number of sheets the net appears on. + if( m_netCounts[aNetName] > 1 ) { - glabel->SetLabelSpinStyle( ( int( elabel.rot->degrees ) / 90 + 2 ) % 4 ); + std::unique_ptr glabel( new SCH_GLOBALLABEL ); + glabel->SetPosition( elabelpos ); + glabel->SetText( netname ); + glabel->SetTextSize( wxSize( elabel.size.ToSchUnits(), elabel.size.ToSchUnits() ) ); + glabel->SetLabelSpinStyle( 2 ); - if( elabel.rot->mirror - && ( glabel->GetLabelSpinStyle() == 0 || glabel->GetLabelSpinStyle() == 2 ) ) - glabel->SetLabelSpinStyle( glabel->GetLabelSpinStyle() % 4 ); - } - - SCH_LINE* wire; - SCH_LINE* next_wire; - - bool labelOnWire = false; - auto glabelPosition = glabel->GetPosition(); - - // determine if the segment has been labelled. - for( wire = segmentWires.begin(); wire; wire = next_wire ) - { - next_wire = wire->Next(); - - if( wire->HitTest( glabelPosition, 0 ) ) + if( elabel.rot ) { - labelOnWire = true; - break; + glabel->SetLabelSpinStyle( ( int( elabel.rot->degrees ) / 90 + 2 ) % 4 ); + + if( elabel.rot->mirror + && ( glabel->GetLabelSpinStyle() == 0 || glabel->GetLabelSpinStyle() == 2 ) ) + glabel->SetLabelSpinStyle( glabel->GetLabelSpinStyle() % 4 ); } - } - wire = segmentWires.begin(); + SCH_LINE* wire; + SCH_LINE* next_wire; - // Reposition label if necessary - if( labelOnWire == false ) - { - wxPoint newLabelPos = findNearestLinePoint( elabelpos, segmentWires ); + bool labelOnWire = false; + auto glabelPosition = glabel->GetPosition(); - if( wire ) + // determine if the segment has been labelled. + for( wire = segmentWires.begin(); wire; wire = next_wire ) { - glabel->SetPosition( newLabelPos ); - } - } + next_wire = wire->Next(); - return glabel.release(); + if( wire->HitTest( glabelPosition, 0 ) ) + { + labelOnWire = true; + break; + } + } + + wire = segmentWires.begin(); + + // Reposition label if necessary + if( labelOnWire == false ) + { + wxPoint newLabelPos = findNearestLinePoint( elabelpos, segmentWires ); + + if( wire ) + { + glabel->SetPosition( newLabelPos ); + } + } + + return glabel.release(); + } + else + { + std::unique_ptr label( new SCH_LABEL ); + label->SetPosition( elabelpos ); + label->SetText( netname ); + label->SetTextSize( wxSize( elabel.size.ToSchUnits(), elabel.size.ToSchUnits() ) ); + + label->SetLabelSpinStyle( 0 ); + + if( elabel.rot ) + { + label->SetLabelSpinStyle( int(elabel.rot->degrees / 90) % 4 ); + + if( elabel.rot->mirror + && ( label->GetLabelSpinStyle() == 0 || label->GetLabelSpinStyle() == 2 ) ) + label->SetLabelSpinStyle( (label->GetLabelSpinStyle() + 2) % 4 ); + } + + SCH_LINE* wire; + SCH_LINE* next_wire; + + bool labelOnWire = false; + auto labelPosition = label->GetPosition(); + + for( wire = segmentWires.begin(); wire; wire = next_wire ) + { + next_wire = wire->Next(); + + if( wire->HitTest( labelPosition, 0 ) ) + { + labelOnWire = true; + break; + } + } + + wire = segmentWires.begin(); + + // Reposition label if necessary + if( labelOnWire == false ) + { + if( wire ) + { + wxPoint newLabelPos = findNearestLinePoint( elabelpos, segmentWires ); + label->SetPosition( newLabelPos ); + } + } + + return label.release(); + } } diff --git a/eeschema/sch_eagle_plugin.h b/eeschema/sch_eagle_plugin.h index df4c0acb36..16a3f1c6ea 100644 --- a/eeschema/sch_eagle_plugin.h +++ b/eeschema/sch_eagle_plugin.h @@ -137,6 +137,7 @@ private: void loadSheet( wxXmlNode* aSheetNode, int sheetcount ); void loadInstance( wxXmlNode* aInstanceNode ); EAGLE_LIBRARY* loadLibrary( wxXmlNode* aLibraryNode, EAGLE_LIBRARY* aEagleLib ); + void countNets( wxXmlNode* aSchematicNode ); /// Moves any labels on the wire to the new end point of the wire. void moveLabels( SCH_ITEM* aWire, const wxPoint& aNewEndPoint ); @@ -184,6 +185,7 @@ private: SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi; ///< Plugin to create the KiCad symbol library. std::unique_ptr< PROPERTIES > m_properties; ///< Library plugin properties. + std::map m_netCounts; std::map m_layerMap; };