2017-02-27 10:07:52 +00:00
|
|
|
/*
|
2017-07-06 12:31:11 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 CERN
|
2021-01-26 15:23:37 +00:00
|
|
|
* Copyright (C) 2017-2021 Kicad Developers, see AUTHORS.txt for contributors.
|
2020-01-22 17:26:27 +00:00
|
|
|
*
|
2017-07-06 12:31:11 +00:00
|
|
|
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
|
2017-10-03 10:23:52 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
* @author Russell Oliver <roliver8143@gmail.com>
|
2017-07-06 12:31:11 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2017-09-20 15:06:01 +00:00
|
|
|
* as published by the Free Software Foundation; either version 3
|
2017-07-06 12:31:11 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2017-02-27 10:07:52 +00:00
|
|
|
|
2020-10-03 20:48:58 +00:00
|
|
|
#include <sch_plugins/eagle/sch_eagle_plugin.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2020-01-06 14:39:20 +00:00
|
|
|
#include <properties.h>
|
2017-02-27 10:07:52 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <memory>
|
2017-02-27 10:07:52 +00:00
|
|
|
#include <wx/filename.h>
|
2019-06-06 02:09:09 +00:00
|
|
|
#include <wx/tokenzr.h>
|
2021-05-03 23:39:56 +00:00
|
|
|
#include <wx/wfstream.h>
|
2021-06-06 13:34:57 +00:00
|
|
|
#include <wx/xml/xml.h>
|
2017-02-27 10:07:52 +00:00
|
|
|
|
2021-06-15 13:24:55 +00:00
|
|
|
#include <symbol_library.h>
|
2020-10-03 20:48:58 +00:00
|
|
|
#include <plugins/eagle/eagle_parser.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <gr_text.h>
|
2021-07-18 23:08:54 +00:00
|
|
|
#include <lib_shape.h>
|
2020-01-06 14:39:20 +00:00
|
|
|
#include <lib_id.h>
|
|
|
|
#include <lib_item.h>
|
2017-06-18 11:31:11 +00:00
|
|
|
#include <lib_pin.h>
|
2017-06-18 12:36:35 +00:00
|
|
|
#include <lib_text.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <project.h>
|
2017-07-13 12:35:26 +00:00
|
|
|
#include <sch_bus_entry.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2020-07-06 10:51:04 +00:00
|
|
|
#include <project/net_settings.h>
|
2020-01-06 14:39:20 +00:00
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <sch_junction.h>
|
2020-10-05 18:38:40 +00:00
|
|
|
#include <sch_plugins/legacy/sch_legacy_plugin.h>
|
2020-01-06 14:39:20 +00:00
|
|
|
#include <sch_marker.h>
|
|
|
|
#include <sch_screen.h>
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <sch_sheet_path.h>
|
|
|
|
#include <sch_text.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2020-01-06 14:39:20 +00:00
|
|
|
#include <symbol_lib_table.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <progress_reporter.h>
|
2017-07-05 15:05:03 +00:00
|
|
|
|
2017-06-18 11:31:11 +00:00
|
|
|
|
|
|
|
// Eagle schematic axes are aligned with x increasing left to right and Y increasing bottom to top
|
2021-01-26 15:23:37 +00:00
|
|
|
// KiCad schematic axes are aligned with x increasing left to right and Y increasing top to bottom.
|
2017-06-18 11:31:11 +00:00
|
|
|
|
2017-03-09 12:49:24 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
/**
|
|
|
|
* Map of EAGLE pin type values to KiCad pin type values
|
|
|
|
*/
|
|
|
|
static const std::map<wxString, ELECTRICAL_PINTYPE> pinDirectionsMap = {
|
|
|
|
{ "sup", ELECTRICAL_PINTYPE::PT_POWER_IN },
|
|
|
|
{ "pas", ELECTRICAL_PINTYPE::PT_PASSIVE },
|
|
|
|
{ "out", ELECTRICAL_PINTYPE::PT_OUTPUT },
|
|
|
|
{ "in", ELECTRICAL_PINTYPE::PT_INPUT },
|
|
|
|
{ "nc", ELECTRICAL_PINTYPE::PT_NC },
|
|
|
|
{ "io", ELECTRICAL_PINTYPE::PT_BIDI },
|
|
|
|
{ "oc", ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR },
|
|
|
|
{ "hiz", ELECTRICAL_PINTYPE::PT_TRISTATE },
|
|
|
|
{ "pwr", ELECTRICAL_PINTYPE::PT_POWER_IN },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Provide an easy access to the children of an XML node via their names.
|
|
|
|
*
|
2017-10-03 10:30:23 +00:00
|
|
|
* @param aCurrentNode is a pointer to a wxXmlNode, whose children will be mapped.
|
|
|
|
* @param aName the name of the specific child names to be counted.
|
|
|
|
* @return number of children with the give node name.
|
|
|
|
*/
|
2017-12-14 09:37:32 +00:00
|
|
|
static int countChildren( wxXmlNode* aCurrentNode, const wxString& aName )
|
2017-10-03 10:30:23 +00:00
|
|
|
{
|
|
|
|
// Map node_name -> node_pointer
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
// Loop through all children counting them if they match the given name
|
|
|
|
aCurrentNode = aCurrentNode->GetChildren();
|
|
|
|
|
|
|
|
while( aCurrentNode )
|
|
|
|
{
|
2017-12-14 09:37:32 +00:00
|
|
|
if( aCurrentNode->GetName() == aName )
|
2017-10-03 10:30:23 +00:00
|
|
|
count++;
|
|
|
|
|
|
|
|
// Get next child
|
|
|
|
aCurrentNode = aCurrentNode->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2017-06-18 11:25:09 +00:00
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Compute a bounding box for all items in a schematic sheet
|
2018-04-06 11:23:24 +00:00
|
|
|
static EDA_RECT getSheetBbox( SCH_SHEET* aSheet )
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
EDA_RECT bbox;
|
2018-05-29 07:27:11 +00:00
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
for( SCH_ITEM* item : aSheet->GetScreen()->Items() )
|
2018-04-06 11:23:24 +00:00
|
|
|
bbox.Merge( item->GetBoundingBox() );
|
|
|
|
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Extract the net name part from a pin name (e.g. return 'GND' for pin named 'GND@2')
|
2018-04-06 13:56:32 +00:00
|
|
|
static inline wxString extractNetName( const wxString& aPinName )
|
|
|
|
{
|
|
|
|
return aPinName.BeforeFirst( '@' );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 14:25:49 +00:00
|
|
|
wxString SCH_EAGLE_PLUGIN::getLibName()
|
2017-10-24 23:08:28 +00:00
|
|
|
{
|
2017-12-12 14:25:49 +00:00
|
|
|
if( m_libName.IsEmpty() )
|
|
|
|
{
|
|
|
|
// Try to come up with a meaningful name
|
2020-06-17 21:30:24 +00:00
|
|
|
m_libName = m_schematic->Prj().GetProjectName();
|
2017-12-12 14:25:49 +00:00
|
|
|
|
|
|
|
if( m_libName.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName fn( m_rootSheet->GetFileName() );
|
|
|
|
m_libName = fn.GetName();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_libName.IsEmpty() )
|
|
|
|
m_libName = "noname";
|
|
|
|
|
|
|
|
m_libName += "-eagle-import";
|
2020-12-17 23:32:23 +00:00
|
|
|
m_libName = LIB_ID::FixIllegalChars( m_libName, true );
|
2017-12-12 14:25:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_libName;
|
2017-10-24 23:08:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 14:25:49 +00:00
|
|
|
wxFileName SCH_EAGLE_PLUGIN::getLibFileName()
|
2017-10-24 23:08:28 +00:00
|
|
|
{
|
2020-06-17 21:30:24 +00:00
|
|
|
wxFileName fn( m_schematic->Prj().GetProjectPath(), getLibName(), KiCadSymbolLibFileExtension );
|
2017-10-24 23:08:28 +00:00
|
|
|
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-23 14:26:13 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::loadLayerDefs( wxXmlNode* aLayers )
|
2017-05-08 14:10:23 +00:00
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
std::vector<ELAYER> eagleLayers;
|
2017-07-06 12:31:11 +00:00
|
|
|
|
2017-07-23 14:26:13 +00:00
|
|
|
// Get the first layer and iterate
|
|
|
|
wxXmlNode* layerNode = aLayers->GetChildren();
|
2017-07-06 12:31:11 +00:00
|
|
|
|
2017-07-23 14:26:13 +00:00
|
|
|
while( layerNode )
|
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
ELAYER elayer( layerNode );
|
|
|
|
eagleLayers.push_back( elayer );
|
2017-07-06 12:31:11 +00:00
|
|
|
|
2017-07-23 14:26:13 +00:00
|
|
|
layerNode = layerNode->GetNext();
|
|
|
|
}
|
2017-07-06 12:31:11 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// match layers based on their names
|
2021-09-20 14:35:45 +00:00
|
|
|
for( const ELAYER& elayer : eagleLayers )
|
2017-07-23 14:26:13 +00:00
|
|
|
{
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Layers in KiCad schematics are not actually layers, but abstract groups mainly used to
|
|
|
|
* decide item colors.
|
2017-07-23 14:26:13 +00:00
|
|
|
*
|
|
|
|
* <layers>
|
|
|
|
* <layer number="90" name="Modules" color="5" fill="1" visible="yes" active="yes"/>
|
|
|
|
* <layer number="91" name="Nets" color="2" fill="1" visible="yes" active="yes"/>
|
|
|
|
* <layer number="92" name="Busses" color="1" fill="1" visible="yes" active="yes"/>
|
|
|
|
* <layer number="93" name="Pins" color="2" fill="1" visible="no" active="yes"/>
|
|
|
|
* <layer number="94" name="Symbols" color="4" fill="1" visible="yes" active="yes"/>
|
|
|
|
* <layer number="95" name="Names" color="7" fill="1" visible="yes" active="yes"/>
|
|
|
|
* <layer number="96" name="Values" color="7" fill="1" visible="yes" active="yes"/>
|
|
|
|
* <layer number="97" name="Info" color="7" fill="1" visible="yes" active="yes"/>
|
|
|
|
* <layer number="98" name="Guide" color="6" fill="1" visible="yes" active="yes"/>
|
|
|
|
* </layers>
|
|
|
|
*/
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
if( elayer.name == "Nets" )
|
2017-07-23 14:26:13 +00:00
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
m_layerMap[elayer.number] = LAYER_WIRE;
|
2017-07-23 14:26:13 +00:00
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
else if( elayer.name == "Info" || elayer.name == "Guide" )
|
2017-07-23 14:26:13 +00:00
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
m_layerMap[elayer.number] = LAYER_NOTES;
|
2017-07-23 14:26:13 +00:00
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
else if( elayer.name == "Busses" )
|
2017-07-23 14:26:13 +00:00
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
m_layerMap[elayer.number] = LAYER_BUS;
|
2017-07-23 14:26:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 12:31:11 +00:00
|
|
|
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
SCH_LAYER_ID SCH_EAGLE_PLUGIN::kiCadLayer( int aEagleLayer )
|
2017-07-23 14:26:13 +00:00
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
auto it = m_layerMap.find( aEagleLayer );
|
|
|
|
return it == m_layerMap.end() ? LAYER_NOTES : it->second;
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
|
|
|
|
2017-02-27 10:07:52 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Return the KiCad symbol orientation based on eagle rotation degrees.
|
|
|
|
static SYMBOL_ORIENTATION_T kiCadComponentRotation( float eagleDegrees )
|
2017-07-06 11:55:41 +00:00
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
int roti = int( eagleDegrees );
|
2017-07-06 11:55:41 +00:00
|
|
|
|
|
|
|
switch( roti )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
wxASSERT_MSG( false, wxString::Format( "Unhandled orientation (%d degrees)", roti ) );
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
2017-07-06 11:55:41 +00:00
|
|
|
|
|
|
|
case 0:
|
2021-06-10 14:10:55 +00:00
|
|
|
return SYM_ORIENT_0;
|
2017-07-06 11:55:41 +00:00
|
|
|
|
|
|
|
case 90:
|
2021-06-10 14:10:55 +00:00
|
|
|
return SYM_ORIENT_90;
|
2017-07-06 11:55:41 +00:00
|
|
|
|
|
|
|
case 180:
|
2021-06-10 14:10:55 +00:00
|
|
|
return SYM_ORIENT_180;
|
2017-07-06 11:55:41 +00:00
|
|
|
|
|
|
|
case 270:
|
2021-06-10 14:10:55 +00:00
|
|
|
return SYM_ORIENT_270;
|
2017-07-06 11:55:41 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
return SYM_ORIENT_0;
|
2017-07-06 11:55:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// Calculate text alignment based on the given Eagle text alignment parameters.
|
2020-01-06 14:39:20 +00:00
|
|
|
static void eagleToKicadAlignment( EDA_TEXT* aText, int aEagleAlignment, int aRelDegress,
|
2021-06-10 14:10:55 +00:00
|
|
|
bool aMirror, bool aSpin, int aAbsDegress )
|
2017-07-16 16:12:05 +00:00
|
|
|
{
|
2017-07-23 14:28:23 +00:00
|
|
|
int align = aEagleAlignment;
|
2017-07-16 16:12:05 +00:00
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
if( aRelDegress == 90 )
|
2017-07-23 14:28:23 +00:00
|
|
|
{
|
|
|
|
aText->SetTextAngle( 900 );
|
|
|
|
}
|
2017-10-03 10:30:23 +00:00
|
|
|
else if( aRelDegress == 180 )
|
2017-07-23 14:28:23 +00:00
|
|
|
align = -align;
|
2017-10-03 10:30:23 +00:00
|
|
|
else if( aRelDegress == 270 )
|
2017-07-23 14:28:23 +00:00
|
|
|
{
|
|
|
|
aText->SetTextAngle( 900 );
|
|
|
|
align = -align;
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
if( aMirror == true )
|
2017-10-03 10:23:52 +00:00
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
if( aAbsDegress == 90 || aAbsDegress == 270 )
|
2017-07-23 14:28:23 +00:00
|
|
|
{
|
|
|
|
if( align == ETEXT::BOTTOM_RIGHT )
|
|
|
|
align = ETEXT::TOP_RIGHT;
|
|
|
|
else if( align == ETEXT::BOTTOM_LEFT )
|
|
|
|
align = ETEXT::TOP_LEFT;
|
|
|
|
else if( align == ETEXT::TOP_LEFT )
|
|
|
|
align = ETEXT::BOTTOM_LEFT;
|
|
|
|
else if( align == ETEXT::TOP_RIGHT )
|
|
|
|
align = ETEXT::BOTTOM_RIGHT;
|
|
|
|
}
|
2017-10-03 10:30:23 +00:00
|
|
|
else if( aAbsDegress == 0 || aAbsDegress == 180 )
|
2017-07-23 14:28:23 +00:00
|
|
|
{
|
|
|
|
if( align == ETEXT::BOTTOM_RIGHT )
|
|
|
|
align = ETEXT::BOTTOM_LEFT;
|
|
|
|
else if( align == ETEXT::BOTTOM_LEFT )
|
|
|
|
align = ETEXT::BOTTOM_RIGHT;
|
|
|
|
else if( align == ETEXT::TOP_LEFT )
|
|
|
|
align = ETEXT::TOP_RIGHT;
|
|
|
|
else if( align == ETEXT::TOP_RIGHT )
|
|
|
|
align = ETEXT::TOP_LEFT;
|
|
|
|
else if( align == ETEXT::CENTER_LEFT )
|
|
|
|
align = ETEXT::CENTER_RIGHT;
|
|
|
|
else if( align == ETEXT::CENTER_RIGHT )
|
|
|
|
align = ETEXT::CENTER_LEFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( align )
|
2017-07-16 16:12:05 +00:00
|
|
|
{
|
|
|
|
case ETEXT::CENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2017-07-16 16:12:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_LEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2017-07-16 16:12:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_RIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2017-07-16 16:12:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_CENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2017-07-16 16:12:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_LEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2017-07-16 16:12:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_RIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2017-07-16 16:12:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_CENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2017-07-16 16:12:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_LEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2017-07-16 16:12:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_RIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2017-07-16 16:12:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-12-28 22:13:54 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
aText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2020-01-10 23:14:37 +00:00
|
|
|
break;
|
2017-07-16 16:12:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
SCH_EAGLE_PLUGIN::SCH_EAGLE_PLUGIN() :
|
|
|
|
m_progressReporter( nullptr ),
|
|
|
|
m_doneCount( 0 ),
|
|
|
|
m_lastProgressCount( 0 ),
|
|
|
|
m_totalCount( 0 )
|
2017-02-27 10:07:52 +00:00
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
m_rootSheet = nullptr;
|
2017-11-01 09:20:13 +00:00
|
|
|
m_currentSheet = nullptr;
|
2020-05-19 02:58:28 +00:00
|
|
|
m_schematic = nullptr;
|
2021-03-31 21:33:30 +00:00
|
|
|
|
|
|
|
m_reporter = &WXLOG_REPORTER::GetInstance();
|
2017-02-27 10:07:52 +00:00
|
|
|
}
|
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2017-02-27 10:07:52 +00:00
|
|
|
SCH_EAGLE_PLUGIN::~SCH_EAGLE_PLUGIN()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-03-09 12:49:24 +00:00
|
|
|
|
2017-02-27 10:07:52 +00:00
|
|
|
const wxString SCH_EAGLE_PLUGIN::GetName() const
|
|
|
|
{
|
2017-12-14 09:37:32 +00:00
|
|
|
return "EAGLE";
|
2017-02-27 10:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxString SCH_EAGLE_PLUGIN::GetFileExtension() const
|
|
|
|
{
|
2017-12-14 09:37:32 +00:00
|
|
|
return "sch";
|
2017-02-27 10:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-28 14:03:09 +00:00
|
|
|
const wxString SCH_EAGLE_PLUGIN::GetLibraryFileExtension() const
|
|
|
|
{
|
|
|
|
return "lbr";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-27 10:07:52 +00:00
|
|
|
int SCH_EAGLE_PLUGIN::GetModifyHash() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::checkpoint()
|
|
|
|
{
|
|
|
|
const unsigned PROGRESS_DELTA = 5;
|
|
|
|
|
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
if( ++m_doneCount > m_lastProgressCount + PROGRESS_DELTA )
|
|
|
|
{
|
2021-06-24 10:09:03 +00:00
|
|
|
m_progressReporter->SetCurrentProgress( ( (double) m_doneCount )
|
|
|
|
/ std::max( 1U, m_totalCount ) );
|
2021-06-23 22:53:08 +00:00
|
|
|
|
|
|
|
if( !m_progressReporter->KeepRefreshing() )
|
2021-07-16 20:13:26 +00:00
|
|
|
THROW_IO_ERROR( ( "Open canceled by user." ) );
|
2021-06-23 22:53:08 +00:00
|
|
|
|
|
|
|
m_lastProgressCount = m_doneCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-21 03:00:23 +00:00
|
|
|
SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
|
|
|
SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties )
|
2017-02-27 10:07:52 +00:00
|
|
|
{
|
2020-05-21 03:00:23 +00:00
|
|
|
wxASSERT( !aFileName || aSchematic != nullptr );
|
2020-01-06 14:39:20 +00:00
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
2017-02-27 10:07:52 +00:00
|
|
|
|
2021-05-03 23:39:56 +00:00
|
|
|
m_filename = aFileName;
|
|
|
|
m_schematic = aSchematic;
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
|
|
|
|
|
|
|
|
if( !m_progressReporter->KeepRefreshing() )
|
2021-07-16 20:13:26 +00:00
|
|
|
THROW_IO_ERROR( ( "Open canceled by user." ) );
|
2021-06-23 22:53:08 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 12:49:24 +00:00
|
|
|
// Load the document
|
|
|
|
wxXmlDocument xmlDocument;
|
2021-05-03 23:39:56 +00:00
|
|
|
wxFFileInputStream stream( m_filename.GetFullPath() );
|
2017-07-06 12:31:11 +00:00
|
|
|
|
2021-05-03 23:39:56 +00:00
|
|
|
if( !stream.IsOk() || !xmlDocument.Load( stream ) )
|
2020-11-05 23:19:47 +00:00
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'." ),
|
2020-11-05 23:19:47 +00:00
|
|
|
m_filename.GetFullPath() ) );
|
|
|
|
}
|
2017-02-27 10:07:52 +00:00
|
|
|
|
2017-03-09 12:49:24 +00:00
|
|
|
// Delete on exception, if I own m_rootSheet, according to aAppendToMe
|
2017-05-08 15:11:14 +00:00
|
|
|
unique_ptr<SCH_SHEET> deleter( aAppendToMe ? nullptr : m_rootSheet );
|
2017-03-09 12:49:24 +00:00
|
|
|
|
2020-11-06 01:32:40 +00:00
|
|
|
wxFileName newFilename( m_filename );
|
2021-03-03 01:06:25 +00:00
|
|
|
newFilename.SetExt( KiCadSchematicFileExtension );
|
2020-11-06 01:32:40 +00:00
|
|
|
|
2017-03-09 12:49:24 +00:00
|
|
|
if( aAppendToMe )
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
|
|
|
|
m_rootSheet = &aSchematic->Root();
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
m_rootSheet = new SCH_SHEET( aSchematic );
|
2020-11-06 01:32:40 +00:00
|
|
|
m_rootSheet->SetFileName( newFilename.GetFullPath() );
|
2021-12-10 23:40:31 +00:00
|
|
|
aSchematic->SetRoot( m_rootSheet );
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
|
|
|
|
2017-05-08 15:11:14 +00:00
|
|
|
if( !m_rootSheet->GetScreen() )
|
|
|
|
{
|
2020-05-21 02:27:48 +00:00
|
|
|
SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
|
2020-11-06 01:32:40 +00:00
|
|
|
screen->SetFileName( newFilename.GetFullPath() );
|
2017-05-08 15:11:14 +00:00
|
|
|
m_rootSheet->SetScreen( screen );
|
|
|
|
}
|
|
|
|
|
2020-06-17 21:30:24 +00:00
|
|
|
SYMBOL_LIB_TABLE* libTable = m_schematic->Prj().SchSymbolLibTable();
|
2017-08-25 07:14:26 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." );
|
2017-07-03 14:02:55 +00:00
|
|
|
|
2020-05-15 13:25:11 +00:00
|
|
|
m_pi.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
|
2020-11-05 23:19:47 +00:00
|
|
|
m_properties = std::make_unique<PROPERTIES>();
|
2020-01-06 14:39:20 +00:00
|
|
|
( *m_properties )[SCH_LEGACY_PLUGIN::PropBuffering] = "";
|
2017-10-24 23:08:28 +00:00
|
|
|
|
|
|
|
/// @note No check is being done here to see if the existing symbol library exists so this
|
|
|
|
/// will overwrite the existing one.
|
|
|
|
if( !libTable->HasLibrary( getLibName() ) )
|
2017-07-03 14:02:55 +00:00
|
|
|
{
|
2017-10-24 23:08:28 +00:00
|
|
|
// Create a new empty symbol library.
|
|
|
|
m_pi->CreateSymbolLib( getLibFileName().GetFullPath() );
|
|
|
|
wxString libTableUri = "${KIPRJMOD}/" + getLibFileName().GetFullName();
|
2017-12-14 09:37:32 +00:00
|
|
|
|
2017-10-24 23:08:28 +00:00
|
|
|
// Add the new library to the project symbol library table.
|
2020-01-06 14:39:20 +00:00
|
|
|
libTable->InsertRow(
|
2020-05-15 13:25:11 +00:00
|
|
|
new SYMBOL_LIB_TABLE_ROW( getLibName(), libTableUri, wxString( "KiCad" ) ) );
|
2017-07-03 14:02:55 +00:00
|
|
|
|
2017-10-24 23:08:28 +00:00
|
|
|
// Save project symbol library table.
|
2020-06-17 21:30:24 +00:00
|
|
|
wxFileName fn( m_schematic->Prj().GetProjectPath(),
|
|
|
|
SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
|
2017-10-24 23:08:28 +00:00
|
|
|
|
|
|
|
// So output formatter goes out of scope and closes the file before reloading.
|
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
|
|
|
|
libTable->Format( &formatter, 0 );
|
2017-10-24 23:08:28 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
// Reload the symbol library table.
|
2021-07-16 20:13:26 +00:00
|
|
|
m_schematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr );
|
2020-06-17 21:30:24 +00:00
|
|
|
m_schematic->Prj().SchSymbolLibTable();
|
2017-10-24 23:08:28 +00:00
|
|
|
}
|
2017-06-18 12:02:04 +00:00
|
|
|
|
2017-03-09 12:49:24 +00:00
|
|
|
// Retrieve the root as current node
|
|
|
|
wxXmlNode* currentNode = xmlDocument.GetRoot();
|
|
|
|
|
|
|
|
// If the attribute is found, store the Eagle version;
|
|
|
|
// otherwise, store the dummy "0.0" version.
|
2017-05-08 14:10:23 +00:00
|
|
|
m_version = currentNode->GetAttribute( "version", "0.0" );
|
2017-03-09 12:49:24 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
// Map all children into a readable dictionary
|
2017-10-03 10:23:52 +00:00
|
|
|
NODE_MAP children = MapChildren( currentNode );
|
2017-03-09 12:49:24 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
// Load drawing
|
|
|
|
loadDrawing( children["drawing"] );
|
2017-03-09 12:49:24 +00:00
|
|
|
|
2017-10-24 23:08:28 +00:00
|
|
|
m_pi->SaveLibrary( getLibFileName().GetFullPath() );
|
2017-07-03 14:02:55 +00:00
|
|
|
|
2021-03-16 19:51:31 +00:00
|
|
|
SCH_SCREENS allSheets( m_rootSheet );
|
|
|
|
allSheets.UpdateSymbolLinks(); // Update all symbol library links for all sheets.
|
|
|
|
|
2017-03-09 12:49:24 +00:00
|
|
|
return m_rootSheet;
|
2017-02-27 10:07:52 +00:00
|
|
|
}
|
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
|
|
|
|
void SCH_EAGLE_PLUGIN::loadDrawing( wxXmlNode* aDrawingNode )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2017-05-08 14:10:23 +00:00
|
|
|
// Map all children into a readable dictionary
|
2017-10-03 10:23:52 +00:00
|
|
|
NODE_MAP drawingChildren = MapChildren( aDrawingNode );
|
2017-03-09 12:49:24 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
// Board nodes should not appear in .sch files
|
|
|
|
// wxXmlNode* board = drawingChildren["board"]
|
|
|
|
|
|
|
|
// wxXmlNode* grid = drawingChildren["grid"]
|
|
|
|
|
2018-08-09 17:53:48 +00:00
|
|
|
auto layers = drawingChildren["layers"];
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2018-08-09 17:53:48 +00:00
|
|
|
if( layers )
|
|
|
|
loadLayerDefs( layers );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
|
|
|
// wxXmlNode* library = drawingChildren["library"]
|
|
|
|
|
|
|
|
// wxXmlNode* settings = drawingChildren["settings"]
|
|
|
|
|
|
|
|
// Load schematic
|
2018-08-09 17:53:48 +00:00
|
|
|
auto schematic = drawingChildren["schematic"];
|
2020-05-15 13:25:11 +00:00
|
|
|
|
2018-08-09 17:53:48 +00:00
|
|
|
if( schematic )
|
|
|
|
loadSchematic( schematic );
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2018-02-18 10:54:37 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::countNets( wxXmlNode* aSchematicNode )
|
|
|
|
{
|
|
|
|
// Map all children into a readable dictionary
|
|
|
|
NODE_MAP schematicChildren = MapChildren( aSchematicNode );
|
2018-08-09 17:53:48 +00:00
|
|
|
|
2021-02-15 21:44:58 +00:00
|
|
|
// Loop through all the sheets
|
2018-08-09 17:53:48 +00:00
|
|
|
wxXmlNode* sheetNode = getChildrenNodes( schematicChildren, "sheets" );
|
2018-02-18 10:54:37 +00:00
|
|
|
|
|
|
|
while( sheetNode )
|
|
|
|
{
|
|
|
|
NODE_MAP sheetChildren = MapChildren( sheetNode );
|
2021-02-15 21:44:58 +00:00
|
|
|
|
2018-02-18 10:54:37 +00:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
|
|
|
|
{
|
|
|
|
// Map all children into a readable dictionary
|
2021-02-15 21:44:58 +00:00
|
|
|
NODE_MAP schematicChildren = MapChildren( aSchematicNode );
|
|
|
|
wxXmlNode* partNode = getChildrenNodes( schematicChildren, "parts" );
|
|
|
|
wxXmlNode* libraryNode = getChildrenNodes( schematicChildren, "libraries" );
|
|
|
|
wxXmlNode* sheetNode = getChildrenNodes( schematicChildren, "sheets" );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2021-06-16 21:02:50 +00:00
|
|
|
if( !sheetNode )
|
2018-08-09 17:53:48 +00:00
|
|
|
return;
|
2017-07-06 12:31:11 +00:00
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
auto count_nodes =
|
|
|
|
[]( wxXmlNode* aNode ) -> unsigned
|
2021-06-23 22:53:08 +00:00
|
|
|
{
|
|
|
|
unsigned count = 0;
|
|
|
|
|
|
|
|
while( aNode )
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
aNode = aNode->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
m_totalCount = 0;
|
|
|
|
m_doneCount = 0;
|
|
|
|
|
|
|
|
m_totalCount += count_nodes( partNode );
|
|
|
|
|
|
|
|
while( libraryNode )
|
|
|
|
{
|
|
|
|
NODE_MAP libraryChildren = MapChildren( libraryNode );
|
|
|
|
wxXmlNode* devicesetNode = getChildrenNodes( libraryChildren, "devicesets" );
|
|
|
|
|
|
|
|
while( devicesetNode )
|
|
|
|
{
|
|
|
|
NODE_MAP deviceSetChildren = MapChildren( devicesetNode );
|
|
|
|
wxXmlNode* deviceNode = getChildrenNodes( deviceSetChildren, "devices" );
|
|
|
|
wxXmlNode* gateNode = getChildrenNodes( deviceSetChildren, "gates" );
|
|
|
|
|
|
|
|
m_totalCount += count_nodes( deviceNode ) * count_nodes( gateNode );
|
|
|
|
|
|
|
|
devicesetNode = devicesetNode->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
libraryNode = libraryNode->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rewind
|
|
|
|
libraryNode = getChildrenNodes( schematicChildren, "libraries" );
|
|
|
|
|
|
|
|
while( sheetNode )
|
|
|
|
{
|
|
|
|
NODE_MAP sheetChildren = MapChildren( sheetNode );
|
|
|
|
|
|
|
|
m_totalCount += count_nodes( getChildrenNodes( sheetChildren, "instances" ) );
|
|
|
|
m_totalCount += count_nodes( getChildrenNodes( sheetChildren, "busses" ) );
|
|
|
|
m_totalCount += count_nodes( getChildrenNodes( sheetChildren, "nets" ) );
|
|
|
|
m_totalCount += count_nodes( getChildrenNodes( sheetChildren, "plain" ) );
|
|
|
|
|
|
|
|
sheetNode = sheetNode->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rewind
|
|
|
|
sheetNode = getChildrenNodes( schematicChildren, "sheets" );
|
|
|
|
}
|
|
|
|
|
2017-06-30 01:52:05 +00:00
|
|
|
while( partNode )
|
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<EPART> epart = std::make_unique<EPART>( partNode );
|
2019-05-27 03:12:27 +00:00
|
|
|
|
|
|
|
// N.B. Eagle parts are case-insensitive in matching but we keep the display case
|
|
|
|
m_partlist[epart->name.Upper()] = std::move( epart );
|
2020-01-06 14:39:20 +00:00
|
|
|
partNode = partNode->GetNext();
|
2017-06-30 01:52:05 +00:00
|
|
|
}
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2021-06-16 21:02:50 +00:00
|
|
|
if( libraryNode )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2021-06-16 21:02:50 +00:00
|
|
|
while( libraryNode )
|
|
|
|
{
|
|
|
|
// Read the library name
|
|
|
|
wxString libName = libraryNode->GetAttribute( "name" );
|
2017-08-23 04:13:37 +00:00
|
|
|
|
2021-06-16 21:02:50 +00:00
|
|
|
EAGLE_LIBRARY* elib = &m_eagleLibs[libName];
|
|
|
|
elib->name = libName;
|
2017-08-23 04:13:37 +00:00
|
|
|
|
2021-06-16 21:02:50 +00:00
|
|
|
loadLibrary( libraryNode, &m_eagleLibs[libName] );
|
2017-08-23 04:13:37 +00:00
|
|
|
|
2021-06-16 21:02:50 +00:00
|
|
|
libraryNode = libraryNode->GetNext();
|
|
|
|
}
|
|
|
|
m_pi->SaveLibrary( getLibFileName().GetFullPath() );
|
|
|
|
}
|
2018-04-06 10:42:10 +00:00
|
|
|
|
2018-02-18 10:54:37 +00:00
|
|
|
// 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 );
|
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
// Loop through all the sheets
|
2018-08-09 17:53:48 +00:00
|
|
|
int sheet_count = countChildren( sheetNode->GetParent(), "sheet" );
|
2017-06-18 11:25:09 +00:00
|
|
|
|
2018-03-28 10:59:56 +00:00
|
|
|
// If eagle schematic has multiple sheets then create corresponding subsheets on the root sheet
|
2017-06-19 13:43:55 +00:00
|
|
|
if( sheet_count > 1 )
|
|
|
|
{
|
2017-08-12 09:18:18 +00:00
|
|
|
int x, y, i;
|
2020-01-06 14:39:20 +00:00
|
|
|
i = 1;
|
|
|
|
x = 1;
|
|
|
|
y = 1;
|
2017-06-18 11:25:09 +00:00
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
while( sheetNode )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos = VECTOR2I( x * Mils2iu( 1000 ), y * Mils2iu( 1000 ) );
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>( m_rootSheet, pos );
|
2020-05-21 02:27:48 +00:00
|
|
|
SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
|
2017-06-18 11:25:09 +00:00
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
sheet->SetScreen( screen );
|
2017-11-01 09:20:13 +00:00
|
|
|
sheet->GetScreen()->SetFileName( sheet->GetFileName() );
|
2017-06-19 13:43:55 +00:00
|
|
|
|
|
|
|
m_currentSheet = sheet.get();
|
2017-10-03 10:23:52 +00:00
|
|
|
loadSheet( sheetNode, i );
|
2017-11-01 09:20:13 +00:00
|
|
|
m_rootSheet->GetScreen()->Append( sheet.release() );
|
2017-06-19 13:43:55 +00:00
|
|
|
|
2021-12-10 23:40:31 +00:00
|
|
|
SCH_SHEET_PATH sheetpath;
|
|
|
|
m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath );
|
|
|
|
sheetpath.push_back( m_currentSheet );
|
|
|
|
|
|
|
|
m_rootSheet->AddInstance( sheetpath );
|
|
|
|
m_rootSheet->SetPageNumber( sheetpath, wxString::Format( "%d", i ) );
|
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
sheetNode = sheetNode->GetNext();
|
|
|
|
x += 2;
|
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
if( x > 10 ) // start next row
|
2017-06-19 13:43:55 +00:00
|
|
|
{
|
2017-11-01 09:20:13 +00:00
|
|
|
x = 1;
|
|
|
|
y += 2;
|
2017-06-19 13:43:55 +00:00
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2017-08-12 09:18:18 +00:00
|
|
|
i++;
|
2017-06-19 13:43:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-18 11:25:09 +00:00
|
|
|
while( sheetNode )
|
|
|
|
{
|
|
|
|
m_currentSheet = m_rootSheet;
|
2017-08-12 09:18:18 +00:00
|
|
|
loadSheet( sheetNode, 0 );
|
2017-06-18 11:25:09 +00:00
|
|
|
sheetNode = sheetNode->GetNext();
|
2021-12-10 23:40:31 +00:00
|
|
|
|
|
|
|
SCH_SHEET_PATH rootPath;
|
|
|
|
rootPath.push_back( m_rootSheet );
|
|
|
|
m_rootSheet->AddInstance( rootPath );
|
|
|
|
m_rootSheet->SetPageNumber( rootPath, wxT( "1" ) );
|
2017-06-18 11:25:09 +00:00
|
|
|
}
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
2018-04-06 13:56:32 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Handle the missing symbol units that need to be instantiated
|
2018-04-06 13:56:32 +00:00
|
|
|
// to create the missing implicit connections
|
|
|
|
|
|
|
|
// Calculate the already placed items bounding box and the page size to determine
|
2021-06-10 14:10:55 +00:00
|
|
|
// placement for the new symbols
|
2020-01-06 14:39:20 +00:00
|
|
|
wxSize pageSizeIU = m_rootSheet->GetScreen()->GetPageSettings().GetSizeIU();
|
|
|
|
EDA_RECT sheetBbox = getSheetBbox( m_rootSheet );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I newCmpPosition( sheetBbox.GetLeft(), sheetBbox.GetBottom() );
|
2020-01-06 14:39:20 +00:00
|
|
|
int maxY = sheetBbox.GetY();
|
2018-04-06 13:56:32 +00:00
|
|
|
|
|
|
|
SCH_SHEET_PATH sheetpath;
|
|
|
|
m_rootSheet->LocatePathOfScreen( m_rootSheet->GetScreen(), &sheetpath );
|
|
|
|
|
|
|
|
for( auto& cmp : m_missingCmps )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
const SCH_SYMBOL* origSymbol = cmp.second.cmp;
|
2018-04-06 13:56:32 +00:00
|
|
|
|
|
|
|
for( auto unitEntry : cmp.second.units )
|
|
|
|
{
|
|
|
|
if( unitEntry.second == false )
|
2020-01-06 14:39:20 +00:00
|
|
|
continue; // unit has been already processed
|
2018-04-06 13:56:32 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Instantiate the missing symbol unit
|
2020-11-12 21:31:41 +00:00
|
|
|
int unit = unitEntry.first;
|
2021-06-10 14:10:55 +00:00
|
|
|
const wxString reference = origSymbol->GetField( REFERENCE_FIELD )->GetText();
|
|
|
|
std::unique_ptr<SCH_SYMBOL> symbol( (SCH_SYMBOL*) origSymbol->Duplicate() );
|
2020-11-12 21:31:41 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->SetUnitSelection( &sheetpath, unit );
|
|
|
|
symbol->SetUnit( unit );
|
|
|
|
symbol->SetOrientation( 0 );
|
|
|
|
symbol->AddHierarchicalReference( sheetpath.Path(), reference, unit );
|
2018-04-06 13:56:32 +00:00
|
|
|
|
|
|
|
// Calculate the placement position
|
2021-06-10 14:10:55 +00:00
|
|
|
EDA_RECT cmpBbox = symbol->GetBoundingBox();
|
2020-01-06 14:39:20 +00:00
|
|
|
int posY = newCmpPosition.y + cmpBbox.GetHeight();
|
2022-01-01 06:04:08 +00:00
|
|
|
symbol->SetPosition( VECTOR2I( newCmpPosition.x, posY ) );
|
2018-04-06 13:56:32 +00:00
|
|
|
newCmpPosition.x += cmpBbox.GetWidth();
|
|
|
|
maxY = std::max( maxY, posY );
|
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
if( newCmpPosition.x >= pageSizeIU.GetWidth() ) // reached the page boundary?
|
2022-01-01 06:04:08 +00:00
|
|
|
newCmpPosition = VECTOR2I( sheetBbox.GetLeft(), maxY ); // then start a new row
|
2018-04-06 13:56:32 +00:00
|
|
|
|
|
|
|
// Add the global net labels to recreate the implicit connections
|
2021-06-10 14:10:55 +00:00
|
|
|
addImplicitConnections( symbol.get(), m_rootSheet->GetScreen(), false );
|
|
|
|
m_rootSheet->GetScreen()->Append( symbol.release() );
|
2018-04-06 13:56:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_missingCmps.clear();
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
2017-03-09 12:49:24 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode, int aSheetIndex )
|
2017-05-08 14:10:23 +00:00
|
|
|
{
|
|
|
|
// Map all children into a readable dictionary
|
2017-10-03 10:23:52 +00:00
|
|
|
NODE_MAP sheetChildren = MapChildren( aSheetNode );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2017-06-18 11:25:09 +00:00
|
|
|
// Get description node
|
|
|
|
wxXmlNode* descriptionNode = getChildrenNodes( sheetChildren, "description" );
|
2017-06-19 13:43:55 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
wxString des;
|
2017-08-12 09:18:18 +00:00
|
|
|
std::string filename;
|
2020-03-13 09:53:44 +00:00
|
|
|
SCH_FIELD& sheetNameField = m_currentSheet->GetFields()[SHEETNAME];
|
|
|
|
SCH_FIELD& filenameField = m_currentSheet->GetFields()[SHEETFILENAME];
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2017-06-18 11:25:09 +00:00
|
|
|
if( descriptionNode )
|
|
|
|
{
|
2017-08-12 09:18:18 +00:00
|
|
|
des = descriptionNode->GetContent();
|
2019-06-08 05:06:41 +00:00
|
|
|
des.Replace( "\n", "_", true );
|
2020-03-13 09:53:44 +00:00
|
|
|
sheetNameField.SetText( des );
|
2017-08-12 09:18:18 +00:00
|
|
|
filename = des.ToStdString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-14 09:37:32 +00:00
|
|
|
filename = wxString::Format( "%s_%d", m_filename.GetName(), aSheetIndex );
|
2020-03-13 09:53:44 +00:00
|
|
|
sheetNameField.SetText( filename );
|
2017-08-12 09:18:18 +00:00
|
|
|
}
|
2017-06-18 11:25:09 +00:00
|
|
|
|
2017-08-12 09:18:18 +00:00
|
|
|
ReplaceIllegalFileNameChars( &filename );
|
|
|
|
replace( filename.begin(), filename.end(), ' ', '_' );
|
2017-06-18 11:25:09 +00:00
|
|
|
|
2021-06-16 20:02:39 +00:00
|
|
|
wxFileName fn( m_filename );
|
|
|
|
fn.SetName( filename );
|
|
|
|
fn.SetExt( KiCadSchematicFileExtension );
|
|
|
|
|
|
|
|
filenameField.SetText( fn.GetFullName() );
|
|
|
|
m_currentSheet->GetScreen()->SetFileName( fn.GetFullPath() );
|
2021-02-15 21:44:58 +00:00
|
|
|
m_currentSheet->AutoplaceFields( m_currentSheet->GetScreen(), true );
|
|
|
|
|
|
|
|
|
|
|
|
// Loop through all of the symbol instances.
|
|
|
|
wxXmlNode* instanceNode = getChildrenNodes( sheetChildren, "instances" );
|
|
|
|
|
|
|
|
while( instanceNode )
|
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2021-02-15 21:44:58 +00:00
|
|
|
loadInstance( instanceNode );
|
|
|
|
instanceNode = instanceNode->GetNext();
|
|
|
|
}
|
2017-06-18 11:25:09 +00:00
|
|
|
|
2020-04-02 17:03:53 +00:00
|
|
|
// Loop through all buses
|
2017-05-08 14:10:23 +00:00
|
|
|
// From the DTD: "Buses receive names which determine which signals they include.
|
|
|
|
// A bus is a drawing object. It does not create any electrical connections.
|
|
|
|
// These are always created by means of the nets and their names."
|
2017-05-08 15:11:14 +00:00
|
|
|
wxXmlNode* busNode = getChildrenNodes( sheetChildren, "busses" );
|
2017-05-08 14:27:11 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
while( busNode )
|
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
// Get the bus name
|
2019-06-06 02:09:09 +00:00
|
|
|
wxString busName = translateEagleBusName( busNode->GetAttribute( "name" ) );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
|
|
|
// Load segments of this bus
|
2017-10-03 10:23:52 +00:00
|
|
|
loadSegments( busNode, busName, wxString() );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
|
|
|
// Get next bus
|
|
|
|
busNode = busNode->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop through all nets
|
|
|
|
// From the DTD: "Net is an electrical connection in a schematic."
|
2017-05-08 15:11:14 +00:00
|
|
|
wxXmlNode* netNode = getChildrenNodes( sheetChildren, "nets" );
|
2017-05-08 14:27:11 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
while( netNode )
|
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
// Get the net name and class
|
2017-12-14 09:37:32 +00:00
|
|
|
wxString netName = netNode->GetAttribute( "name" );
|
|
|
|
wxString netClass = netNode->GetAttribute( "class" );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
|
|
|
// Load segments of this net
|
2017-06-19 13:43:55 +00:00
|
|
|
loadSegments( netNode, netName, netClass );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
|
|
|
// Get next net
|
|
|
|
netNode = netNode->GetNext();
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
adjustNetLabels(); // needs to be called before addBusEntries()
|
2017-08-13 16:48:52 +00:00
|
|
|
addBusEntries();
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
/* moduleinst is a design block definition and is an EagleCad 8 feature,
|
|
|
|
*
|
|
|
|
* // Loop through all moduleinsts
|
|
|
|
* wxXmlNode* moduleinstNode = getChildrenNodes( sheetChildren, "moduleinsts" );
|
|
|
|
*
|
|
|
|
* while( moduleinstNode )
|
|
|
|
* {
|
|
|
|
* loadModuleinst( moduleinstNode );
|
|
|
|
* moduleinstNode = moduleinstNode->GetNext();
|
|
|
|
* }
|
|
|
|
*/
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2017-07-06 12:31:11 +00:00
|
|
|
wxXmlNode* plainNode = getChildrenNodes( sheetChildren, "plain" );
|
2017-05-08 15:11:14 +00:00
|
|
|
|
|
|
|
while( plainNode )
|
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2017-07-05 15:05:03 +00:00
|
|
|
wxString nodeName = plainNode->GetName();
|
|
|
|
|
2017-07-16 16:18:58 +00:00
|
|
|
if( nodeName == "text" )
|
2017-07-05 15:05:03 +00:00
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
m_currentSheet->GetScreen()->Append( loadPlainText( plainNode ) );
|
2017-07-05 15:05:03 +00:00
|
|
|
}
|
2017-07-16 16:18:58 +00:00
|
|
|
else if( nodeName == "wire" )
|
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->Append( loadWire( plainNode ) );
|
|
|
|
}
|
2021-02-15 21:44:58 +00:00
|
|
|
else if( nodeName == "frame" )
|
|
|
|
{
|
|
|
|
std::vector<SCH_LINE*> lines;
|
|
|
|
|
|
|
|
loadFrame( plainNode, lines );
|
|
|
|
|
|
|
|
for( SCH_LINE* line : lines )
|
|
|
|
m_currentSheet->GetScreen()->Append( line );
|
|
|
|
}
|
2017-07-05 15:05:03 +00:00
|
|
|
|
2017-05-08 15:11:14 +00:00
|
|
|
plainNode = plainNode->GetNext();
|
|
|
|
}
|
2017-07-09 02:37:02 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// Calculate the new sheet size.
|
2018-04-06 11:23:24 +00:00
|
|
|
EDA_RECT sheetBoundingBox = getSheetBbox( m_currentSheet );
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I targetSheetSize = sheetBoundingBox.GetSize();
|
|
|
|
targetSheetSize += VECTOR2I( Mils2iu( 1500 ), Mils2iu( 1500 ) );
|
2017-07-09 02:37:02 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// Get current Eeschema sheet size.
|
2020-01-06 14:39:20 +00:00
|
|
|
wxSize pageSizeIU = m_currentSheet->GetScreen()->GetPageSettings().GetSizeIU();
|
|
|
|
PAGE_INFO pageInfo = m_currentSheet->GetScreen()->GetPageSettings();
|
2017-07-09 02:37:02 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// Increase if necessary
|
2017-10-17 08:19:43 +00:00
|
|
|
if( pageSizeIU.x < targetSheetSize.x )
|
2020-01-05 19:11:15 +00:00
|
|
|
pageInfo.SetWidthMils( Iu2Mils( targetSheetSize.x ) );
|
2017-07-09 02:37:02 +00:00
|
|
|
|
2017-10-17 08:19:43 +00:00
|
|
|
if( pageSizeIU.y < targetSheetSize.y )
|
2020-01-05 19:11:15 +00:00
|
|
|
pageInfo.SetHeightMils( Iu2Mils( targetSheetSize.y ) );
|
2017-07-09 02:37:02 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// Set the new sheet size.
|
2017-07-09 02:37:02 +00:00
|
|
|
m_currentSheet->GetScreen()->SetPageSettings( pageInfo );
|
|
|
|
|
|
|
|
pageSizeIU = m_currentSheet->GetScreen()->GetPageSettings().GetSizeIU();
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I sheetcentre( pageSizeIU.x / 2, pageSizeIU.y / 2 );
|
|
|
|
VECTOR2I itemsCentre = sheetBoundingBox.Centre();
|
2017-07-09 02:37:02 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// round the translation to nearest 100mil to place it on the grid.
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I translation = sheetcentre - itemsCentre;
|
2020-01-05 19:11:15 +00:00
|
|
|
translation.x = translation.x - translation.x % Mils2iu( 100 );
|
|
|
|
translation.y = translation.y - translation.y % Mils2iu( 100 );
|
2017-07-13 12:28:35 +00:00
|
|
|
|
2018-04-06 13:56:32 +00:00
|
|
|
// Add global net labels for the named power input pins in this sheet
|
2021-09-20 14:35:45 +00:00
|
|
|
for( SCH_ITEM* item : m_currentSheet->GetScreen()->Items().OfType( SCH_SYMBOL_T ) )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
addImplicitConnections( symbol, m_currentSheet->GetScreen(), true );
|
|
|
|
}
|
2018-04-12 16:10:22 +00:00
|
|
|
|
|
|
|
m_connPoints.clear();
|
|
|
|
|
|
|
|
// Translate the items.
|
2020-02-22 18:28:03 +00:00
|
|
|
std::vector<SCH_ITEM*> allItems;
|
|
|
|
|
|
|
|
std::copy( m_currentSheet->GetScreen()->Items().begin(),
|
|
|
|
m_currentSheet->GetScreen()->Items().end(), std::back_inserter( allItems ) );
|
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
for( SCH_ITEM* item : allItems )
|
2018-04-12 16:10:22 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
item->SetPosition( item->GetPosition() + translation );
|
2018-04-12 16:10:22 +00:00
|
|
|
item->ClearFlags();
|
2020-02-22 18:28:03 +00:00
|
|
|
m_currentSheet->GetScreen()->Update( item );
|
|
|
|
|
2018-04-12 16:10:22 +00:00
|
|
|
}
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2021-02-15 21:44:58 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::loadFrame( wxXmlNode* aFrameNode, std::vector<SCH_LINE*>& aLines )
|
|
|
|
{
|
|
|
|
EFRAME eframe( aFrameNode );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I corner1( eframe.x1.ToSchUnits(), -eframe.y1.ToSchUnits() );
|
|
|
|
VECTOR2I corner3( eframe.x2.ToSchUnits(), -eframe.y2.ToSchUnits() );
|
|
|
|
VECTOR2I corner2( corner3.x, corner1.y );
|
|
|
|
VECTOR2I corner4( corner1.x, corner3.y );
|
2021-02-15 21:44:58 +00:00
|
|
|
|
|
|
|
SCH_LINE* line = new SCH_LINE();
|
|
|
|
line->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
|
|
|
line->SetStartPoint( corner1 );
|
|
|
|
line->SetEndPoint( corner2 );
|
|
|
|
aLines.push_back( line );
|
|
|
|
|
|
|
|
line = new SCH_LINE();
|
|
|
|
line->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
|
|
|
line->SetStartPoint( corner2 );
|
|
|
|
line->SetEndPoint( corner3 );
|
|
|
|
aLines.push_back( line );
|
|
|
|
|
|
|
|
line = new SCH_LINE();
|
|
|
|
line->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
|
|
|
line->SetStartPoint( corner3 );
|
|
|
|
line->SetEndPoint( corner4 );
|
|
|
|
aLines.push_back( line );
|
|
|
|
|
|
|
|
line = new SCH_LINE();
|
|
|
|
line->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
|
|
|
line->SetStartPoint( corner4 );
|
|
|
|
line->SetEndPoint( corner1 );
|
|
|
|
aLines.push_back( line );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, const wxString& netName,
|
|
|
|
const wxString& aNetClass )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2017-05-08 14:10:23 +00:00
|
|
|
// Loop through all segments
|
2020-01-06 14:39:20 +00:00
|
|
|
wxXmlNode* currentSegment = aSegmentsNode->GetChildren();
|
|
|
|
SCH_SCREEN* screen = m_currentSheet->GetScreen();
|
2017-07-06 12:31:11 +00:00
|
|
|
|
2018-02-18 10:54:37 +00:00
|
|
|
int segmentCount = countChildren( aSegmentsNode, "segment" );
|
|
|
|
|
2017-07-06 12:31:11 +00:00
|
|
|
// wxCHECK( screen, [>void<] );
|
2017-05-08 14:10:23 +00:00
|
|
|
while( currentSegment )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2021-01-26 15:23:37 +00:00
|
|
|
bool labelled = false; // has a label been added to this continuously connected segment
|
2020-01-06 14:39:20 +00:00
|
|
|
NODE_MAP segmentChildren = MapChildren( currentSegment );
|
|
|
|
SCH_LINE* firstWire = nullptr;
|
2018-03-28 14:03:27 +00:00
|
|
|
m_segments.emplace_back();
|
|
|
|
SEG_DESC& segDesc = m_segments.back();
|
2017-07-13 12:42:06 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
// Loop through all segment children
|
|
|
|
wxXmlNode* segmentAttribute = currentSegment->GetChildren();
|
2017-03-09 12:49:24 +00:00
|
|
|
|
2017-07-13 12:42:06 +00:00
|
|
|
while( segmentAttribute )
|
|
|
|
{
|
|
|
|
if( segmentAttribute->GetName() == "wire" )
|
2018-03-28 14:03:27 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* wire = loadWire( segmentAttribute );
|
|
|
|
|
|
|
|
if( !firstWire )
|
|
|
|
firstWire = wire;
|
|
|
|
|
|
|
|
// Test for intersections with other wires
|
|
|
|
SEG thisWire( wire->GetStartPoint(), wire->GetEndPoint() );
|
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
for( SEG_DESC& desc : m_segments )
|
2018-03-28 14:03:27 +00:00
|
|
|
{
|
|
|
|
if( !desc.labels.empty() && desc.labels.front()->GetText() == netName )
|
2020-01-06 14:39:20 +00:00
|
|
|
continue; // no point in saving intersections of the same net
|
2018-03-28 14:03:27 +00:00
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
for( const SEG& seg : desc.segs )
|
2018-03-28 14:03:27 +00:00
|
|
|
{
|
2021-09-20 14:35:45 +00:00
|
|
|
OPT_VECTOR2I intersection = thisWire.Intersect( seg, true );
|
2018-03-28 14:03:27 +00:00
|
|
|
|
|
|
|
if( intersection )
|
|
|
|
m_wireIntersections.push_back( *intersection );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
segDesc.segs.push_back( thisWire );
|
|
|
|
screen->Append( wire );
|
|
|
|
}
|
2017-07-13 12:42:06 +00:00
|
|
|
|
|
|
|
segmentAttribute = segmentAttribute->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
segmentAttribute = currentSegment->GetChildren();
|
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
while( segmentAttribute )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2017-05-08 14:10:23 +00:00
|
|
|
wxString nodeName = segmentAttribute->GetName();
|
|
|
|
|
|
|
|
if( nodeName == "junction" )
|
|
|
|
{
|
2017-06-19 13:43:55 +00:00
|
|
|
screen->Append( loadJunction( segmentAttribute ) );
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
|
|
|
else if( nodeName == "label" )
|
|
|
|
{
|
2018-03-28 14:03:27 +00:00
|
|
|
SCH_TEXT* label = loadLabel( segmentAttribute, netName );
|
|
|
|
screen->Append( label );
|
2020-01-06 14:39:20 +00:00
|
|
|
wxASSERT( segDesc.labels.empty()
|
|
|
|
|| segDesc.labels.front()->GetText() == label->GetText() );
|
2018-03-28 14:03:27 +00:00
|
|
|
segDesc.labels.push_back( label );
|
2017-07-13 12:42:06 +00:00
|
|
|
labelled = true;
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
|
|
|
else if( nodeName == "pinref" )
|
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
segmentAttribute->GetAttribute( "gate" ); // REQUIRED
|
2021-09-20 18:54:47 +00:00
|
|
|
wxString part = segmentAttribute->GetAttribute( "part" ); // REQUIRED
|
|
|
|
wxString pin = segmentAttribute->GetAttribute( "pin" ); // REQUIRED
|
|
|
|
|
|
|
|
auto powerPort = m_powerPorts.find( "#" + part );
|
|
|
|
|
|
|
|
if( powerPort != m_powerPorts.end()
|
|
|
|
&& powerPort->second == EscapeString( pin, CTX_NETNAME ) )
|
|
|
|
{
|
|
|
|
labelled = true;
|
|
|
|
}
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
|
|
|
else if( nodeName == "wire" )
|
|
|
|
{
|
2017-07-13 12:42:06 +00:00
|
|
|
// already handled;
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
2020-01-06 14:39:20 +00:00
|
|
|
else // DEFAULT
|
2017-05-08 14:10:23 +00:00
|
|
|
{
|
2021-11-04 00:02:14 +00:00
|
|
|
// THROW_IO_ERROR( wxString::Format( _( "XML node '%s' unknown" ), nodeName ) );
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get next segment attribute
|
|
|
|
segmentAttribute = segmentAttribute->GetNext();
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2021-02-15 21:44:58 +00:00
|
|
|
// Add a small label to the net segment if it hasn't been labeled already or is not
|
|
|
|
// connect to a power symbol with a pin on the same net. This preserves the named net
|
|
|
|
// feature of Eagle schematics.
|
2018-03-28 14:03:27 +00:00
|
|
|
if( !labelled && firstWire )
|
2017-07-13 12:42:06 +00:00
|
|
|
{
|
2018-03-22 15:19:38 +00:00
|
|
|
std::unique_ptr<SCH_TEXT> label;
|
2017-08-17 15:32:40 +00:00
|
|
|
|
2018-02-18 10:54:37 +00:00
|
|
|
// Add a global label if the net appears on more than one Eagle sheet
|
|
|
|
if( m_netCounts[netName.ToStdString()] > 1 )
|
2018-03-22 15:19:38 +00:00
|
|
|
label.reset( new SCH_GLOBALLABEL );
|
2018-02-18 10:54:37 +00:00
|
|
|
else if( segmentCount > 1 )
|
2018-03-22 15:19:38 +00:00
|
|
|
label.reset( new SCH_LABEL );
|
|
|
|
|
|
|
|
if( label )
|
2018-02-18 10:54:37 +00:00
|
|
|
{
|
2018-03-28 14:03:27 +00:00
|
|
|
label->SetPosition( firstWire->GetStartPoint() );
|
2018-04-03 07:57:56 +00:00
|
|
|
label->SetText( escapeName( netName ) );
|
2021-02-15 21:44:58 +00:00
|
|
|
label->SetTextSize( wxSize( Mils2iu( 40 ), Mils2iu( 40 ) ) );
|
2021-10-27 12:48:49 +00:00
|
|
|
|
|
|
|
if( firstWire->GetEndPoint().x > firstWire->GetStartPoint().x )
|
|
|
|
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT );
|
|
|
|
else
|
|
|
|
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT );
|
|
|
|
|
2018-02-18 10:54:37 +00:00
|
|
|
screen->Append( label.release() );
|
|
|
|
}
|
2017-07-13 12:42:06 +00:00
|
|
|
}
|
2017-08-12 09:17:40 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
currentSegment = currentSegment->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-16 16:18:58 +00:00
|
|
|
SCH_LINE* SCH_EAGLE_PLUGIN::loadWire( wxXmlNode* aWireNode )
|
2017-05-08 14:10:23 +00:00
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
|
2017-05-08 15:11:14 +00:00
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
EWIRE ewire = EWIRE( aWireNode );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
wire->SetLayer( kiCadLayer( ewire.layer ) );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I begin, end;
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
begin.x = ewire.x1.ToSchUnits();
|
|
|
|
begin.y = -ewire.y1.ToSchUnits();
|
|
|
|
end.x = ewire.x2.ToSchUnits();
|
|
|
|
end.y = -ewire.y2.ToSchUnits();
|
2017-05-08 14:10:23 +00:00
|
|
|
|
|
|
|
wire->SetStartPoint( begin );
|
|
|
|
wire->SetEndPoint( end );
|
|
|
|
|
2018-04-12 16:10:22 +00:00
|
|
|
m_connPoints[begin].emplace( wire.get() );
|
|
|
|
m_connPoints[end].emplace( wire.get() );
|
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
return wire.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
SCH_JUNCTION* SCH_EAGLE_PLUGIN::loadJunction( wxXmlNode* aJunction )
|
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
|
2017-06-18 11:31:11 +00:00
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
EJUNCTION ejunction = EJUNCTION( aJunction );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos( ejunction.x.ToSchUnits(), -ejunction.y.ToSchUnits() );
|
2017-07-09 02:37:02 +00:00
|
|
|
|
2018-03-28 10:59:56 +00:00
|
|
|
junction->SetPosition( pos );
|
2017-07-09 02:37:02 +00:00
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
return junction.release();
|
2017-06-18 11:31:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-28 14:03:27 +00:00
|
|
|
SCH_TEXT* SCH_EAGLE_PLUGIN::loadLabel( wxXmlNode* aLabelNode, const wxString& aNetName )
|
2017-07-13 12:42:06 +00:00
|
|
|
{
|
2021-09-20 14:35:45 +00:00
|
|
|
ELABEL elabel = ELABEL( aLabelNode, aNetName );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I elabelpos( elabel.x.ToSchUnits(), -elabel.y.ToSchUnits() );
|
2018-02-18 10:54:37 +00:00
|
|
|
|
2018-03-22 15:19:38 +00:00
|
|
|
// Determine if the label is local or global depending on
|
|
|
|
// the number of sheets the net appears in
|
2020-01-06 14:39:20 +00:00
|
|
|
bool global = m_netCounts[aNetName] > 1;
|
2018-03-22 15:19:38 +00:00
|
|
|
std::unique_ptr<SCH_TEXT> label;
|
2018-02-18 10:54:37 +00:00
|
|
|
|
2021-09-20 14:39:56 +00:00
|
|
|
wxSize textSize = wxSize( KiROUND( elabel.size.ToSchUnits() * 0.7 ),
|
|
|
|
KiROUND( elabel.size.ToSchUnits() * 0.7 ) );
|
2021-02-15 21:44:58 +00:00
|
|
|
|
2018-03-22 15:19:38 +00:00
|
|
|
if( global )
|
2020-10-26 23:49:11 +00:00
|
|
|
label = std::make_unique<SCH_GLOBALLABEL>();
|
2018-02-18 10:54:37 +00:00
|
|
|
else
|
2020-10-26 23:49:11 +00:00
|
|
|
label = std::make_unique<SCH_LABEL>();
|
2018-02-18 10:54:37 +00:00
|
|
|
|
2018-03-22 15:19:38 +00:00
|
|
|
label->SetPosition( elabelpos );
|
|
|
|
label->SetText( escapeName( elabel.netname ) );
|
2021-02-15 21:44:58 +00:00
|
|
|
label->SetTextSize( textSize );
|
2020-01-08 19:07:55 +00:00
|
|
|
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT );
|
2017-06-18 11:31:11 +00:00
|
|
|
|
2018-03-22 15:19:38 +00:00
|
|
|
if( elabel.rot )
|
|
|
|
{
|
2021-09-20 14:39:56 +00:00
|
|
|
for( int i = 0; i < KiROUND( elabel.rot->degrees / 90 ) %4; ++i )
|
|
|
|
label->Rotate90( false );
|
2018-02-18 10:54:37 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
if( elabel.rot->mirror )
|
2021-09-20 14:39:56 +00:00
|
|
|
label->MirrorSpinStyle( false );
|
2018-03-22 15:19:38 +00:00
|
|
|
}
|
2018-02-16 22:48:58 +00:00
|
|
|
|
2018-03-22 15:19:38 +00:00
|
|
|
return label.release();
|
2017-07-13 12:42:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
std::pair<VECTOR2I, const SEG*>
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_EAGLE_PLUGIN::findNearestLinePoint( const VECTOR2I& aPoint,
|
2021-09-20 14:35:45 +00:00
|
|
|
const std::vector<SEG>& aLines ) const
|
2017-07-13 12:42:06 +00:00
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
VECTOR2I nearestPoint;
|
2018-03-28 14:03:27 +00:00
|
|
|
const SEG* nearestLine = nullptr;
|
2017-07-13 12:42:06 +00:00
|
|
|
|
2018-03-28 14:03:27 +00:00
|
|
|
float d, mindistance = std::numeric_limits<float>::max();
|
2017-10-03 10:23:52 +00:00
|
|
|
|
|
|
|
// Find the nearest start, middle or end of a line from the list of lines.
|
2018-03-28 14:03:27 +00:00
|
|
|
for( const SEG& line : aLines )
|
2017-07-09 05:16:27 +00:00
|
|
|
{
|
2021-09-20 14:35:45 +00:00
|
|
|
VECTOR2I testpoint = line.A;
|
2020-01-06 14:39:20 +00:00
|
|
|
d = sqrt( abs( ( ( aPoint.x - testpoint.x ) ^ 2 ) + ( ( aPoint.y - testpoint.y ) ^ 2 ) ) );
|
2017-07-13 12:42:06 +00:00
|
|
|
|
|
|
|
if( d < mindistance )
|
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
mindistance = d;
|
|
|
|
nearestPoint = testpoint;
|
|
|
|
nearestLine = &line;
|
2017-07-13 12:42:06 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 14:03:27 +00:00
|
|
|
testpoint = line.Center();
|
2020-01-06 14:39:20 +00:00
|
|
|
d = sqrt( abs( ( ( aPoint.x - testpoint.x ) ^ 2 ) + ( ( aPoint.y - testpoint.y ) ^ 2 ) ) );
|
2017-07-13 12:42:06 +00:00
|
|
|
|
|
|
|
if( d < mindistance )
|
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
mindistance = d;
|
|
|
|
nearestPoint = testpoint;
|
|
|
|
nearestLine = &line;
|
2017-07-13 12:42:06 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 14:03:27 +00:00
|
|
|
testpoint = line.B;
|
2020-01-06 14:39:20 +00:00
|
|
|
d = sqrt( abs( ( ( aPoint.x - testpoint.x ) ^ 2 ) + ( ( aPoint.y - testpoint.y ) ^ 2 ) ) );
|
2017-07-13 12:42:06 +00:00
|
|
|
|
|
|
|
if( d < mindistance )
|
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
mindistance = d;
|
|
|
|
nearestPoint = testpoint;
|
|
|
|
nearestLine = &line;
|
2017-07-13 12:42:06 +00:00
|
|
|
}
|
2017-07-09 05:16:27 +00:00
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2018-03-28 14:03:27 +00:00
|
|
|
return std::make_pair( nearestPoint, nearestLine );
|
2017-06-18 11:31:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
|
|
|
|
{
|
2021-09-20 14:35:45 +00:00
|
|
|
EINSTANCE einstance = EINSTANCE( aInstanceNode );
|
2017-06-26 07:56:11 +00:00
|
|
|
SCH_SCREEN* screen = m_currentSheet->GetScreen();
|
|
|
|
|
|
|
|
// Find the part in the list for the sheet.
|
2021-06-10 14:10:55 +00:00
|
|
|
// Assign the symbol its value from the part entry
|
2017-06-26 07:56:11 +00:00
|
|
|
// Calculate the unit number from the gate entry of the instance
|
2021-06-09 19:32:58 +00:00
|
|
|
// Assign the LIB_ID from device set and device names
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2019-05-27 03:12:27 +00:00
|
|
|
auto part_it = m_partlist.find( einstance.part.Upper() );
|
|
|
|
|
|
|
|
if( part_it == m_partlist.end() )
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Error parsing Eagle file. Could not find '%s' "
|
|
|
|
"instance but it is referenced in the schematic." ),
|
|
|
|
einstance.part ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2019-05-27 03:12:27 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EPART* epart = part_it->second.get();
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2017-12-14 09:37:32 +00:00
|
|
|
wxString libraryname = epart->library;
|
2020-01-06 14:39:20 +00:00
|
|
|
wxString gatename = epart->deviceset + epart->device + einstance.gate;
|
|
|
|
wxString symbolname = wxString( epart->deviceset + epart->device );
|
2017-12-14 09:37:32 +00:00
|
|
|
symbolname.Replace( "*", "" );
|
2021-07-31 19:06:31 +00:00
|
|
|
wxString kisymbolname = EscapeString( symbolname, CTX_LIBID );
|
2017-08-20 05:56:14 +00:00
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
int unit = m_eagleLibs[libraryname].GateUnit[gatename];
|
2017-07-03 14:02:55 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
wxString package;
|
2017-10-03 10:30:23 +00:00
|
|
|
EAGLE_LIBRARY* elib = &m_eagleLibs[libraryname];
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2018-06-21 04:12:11 +00:00
|
|
|
auto p = elib->package.find( kisymbolname );
|
2017-10-03 10:23:52 +00:00
|
|
|
|
|
|
|
if( p != elib->package.end() )
|
2017-08-23 04:13:37 +00:00
|
|
|
package = p->second;
|
2017-07-09 09:35:13 +00:00
|
|
|
|
2021-07-31 19:06:31 +00:00
|
|
|
LIB_SYMBOL* part = m_pi->LoadSymbol( getLibFileName().GetFullPath(), kisymbolname,
|
|
|
|
m_properties.get() );
|
2017-07-09 09:35:13 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( !part )
|
2018-05-29 07:28:28 +00:00
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Could not find '%s' in the imported library." ),
|
2021-07-31 19:06:31 +00:00
|
|
|
UnescapeString( kisymbolname ) ),
|
2021-03-31 21:33:30 +00:00
|
|
|
RPT_SEVERITY_ERROR );
|
2017-10-03 10:23:52 +00:00
|
|
|
return;
|
2018-05-29 07:28:28 +00:00
|
|
|
}
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
LIB_ID libId( getLibName(), kisymbolname );
|
|
|
|
std::unique_ptr<SCH_SYMBOL> symbol = std::make_unique<SCH_SYMBOL>();
|
|
|
|
symbol->SetLibId( libId );
|
|
|
|
symbol->SetUnit( unit );
|
2022-01-01 06:04:08 +00:00
|
|
|
symbol->SetPosition( VECTOR2I( einstance.x.ToSchUnits(), -einstance.y.ToSchUnits() ) );
|
2022-01-05 09:58:06 +00:00
|
|
|
// assume that footprint library is identical to project name
|
|
|
|
wxString packageString = m_schematic->Prj().GetProjectName() + wxT( ":" ) + package;
|
|
|
|
symbol->GetField( FOOTPRINT_FIELD )->SetText( packageString );
|
2017-07-03 14:02:55 +00:00
|
|
|
|
|
|
|
if( einstance.rot )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->SetOrientation( kiCadComponentRotation( einstance.rot->degrees ) );
|
2017-07-06 12:31:11 +00:00
|
|
|
|
2017-07-03 14:02:55 +00:00
|
|
|
if( einstance.rot->mirror )
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->MirrorHorizontally( einstance.x.ToSchUnits() );
|
2017-06-30 01:52:05 +00:00
|
|
|
}
|
2017-07-03 14:02:55 +00:00
|
|
|
|
2020-12-15 15:06:19 +00:00
|
|
|
std::vector<LIB_FIELD*> partFields;
|
2017-10-03 10:23:52 +00:00
|
|
|
part->GetFields( partFields );
|
|
|
|
|
2020-12-15 15:06:19 +00:00
|
|
|
for( const LIB_FIELD* field : partFields )
|
2017-07-09 09:35:13 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->GetFieldById( field->GetId() )->ImportValues( *field );
|
2021-12-29 21:30:11 +00:00
|
|
|
symbol->GetFieldById( field->GetId() )->SetTextPos( (VECTOR2I)symbol->GetPosition()
|
2021-06-10 14:10:55 +00:00
|
|
|
+ field->GetTextPos() );
|
2017-07-09 09:35:13 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 17:17:23 +00:00
|
|
|
// If there is no footprint assigned, then prepend the reference value
|
|
|
|
// with a hash character to mute netlist updater complaints
|
|
|
|
wxString reference = package.IsEmpty() ? '#' + einstance.part : einstance.part;
|
2017-07-14 15:20:59 +00:00
|
|
|
|
2019-05-21 02:47:32 +00:00
|
|
|
// EAGLE allows references to be single digits. This breaks KiCad netlisting, which requires
|
|
|
|
// parts to have non-digit + digit annotation. If the reference begins with a number,
|
|
|
|
// we prepend 'UNK' (unknown) for the symbol designator
|
|
|
|
if( reference.find_first_not_of( "0123456789" ) == wxString::npos )
|
|
|
|
reference.Prepend( "UNK" );
|
|
|
|
|
2017-08-24 15:56:15 +00:00
|
|
|
SCH_SHEET_PATH sheetpath;
|
2017-10-03 10:23:52 +00:00
|
|
|
m_rootSheet->LocatePathOfScreen( screen, &sheetpath );
|
2021-06-10 14:10:55 +00:00
|
|
|
wxString current_sheetpath = sheetpath.PathAsString() + symbol->m_Uuid.AsString();
|
2017-07-23 14:28:23 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->GetField( REFERENCE_FIELD )->SetText( reference );
|
|
|
|
symbol->AddHierarchicalReference( current_sheetpath, reference, unit );
|
2017-07-23 14:28:23 +00:00
|
|
|
|
2017-07-14 15:20:59 +00:00
|
|
|
if( epart->value )
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->GetField( VALUE_FIELD )->SetText( *epart->value );
|
2017-07-14 15:20:59 +00:00
|
|
|
else
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->GetField( VALUE_FIELD )->SetText( kisymbolname );
|
2017-07-14 15:20:59 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// Set the visibility of fields.
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->GetField( REFERENCE_FIELD )->SetVisible(
|
|
|
|
part->GetFieldById( REFERENCE_FIELD )->IsVisible() );
|
|
|
|
symbol->GetField( VALUE_FIELD )->SetVisible( part->GetFieldById( VALUE_FIELD )->IsVisible() );
|
2017-08-19 07:35:21 +00:00
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& a : epart->attribute )
|
2018-07-10 14:32:10 +00:00
|
|
|
{
|
2021-09-20 14:35:45 +00:00
|
|
|
SCH_FIELD* field = symbol->AddField( *symbol->GetField( VALUE_FIELD ) );
|
2018-07-10 14:32:10 +00:00
|
|
|
field->SetName( a.first );
|
|
|
|
field->SetText( a.second );
|
|
|
|
field->SetVisible( false );
|
|
|
|
}
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& a : epart->variant )
|
2018-07-10 14:32:10 +00:00
|
|
|
{
|
2021-09-20 14:35:45 +00:00
|
|
|
SCH_FIELD* field = symbol->AddField( *symbol->GetField( VALUE_FIELD ) );
|
2018-07-10 14:32:10 +00:00
|
|
|
field->SetName( "VARIANT_" + a.first );
|
|
|
|
field->SetText( a.second );
|
|
|
|
field->SetVisible( false );
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
bool valueAttributeFound = false;
|
|
|
|
bool nameAttributeFound = false;
|
2017-08-19 07:35:21 +00:00
|
|
|
|
2017-07-16 16:12:05 +00:00
|
|
|
wxXmlNode* attributeNode = aInstanceNode->GetChildren();
|
2017-10-03 10:23:52 +00:00
|
|
|
|
|
|
|
// Parse attributes for the instance
|
|
|
|
while( attributeNode )
|
2017-07-16 16:12:05 +00:00
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
if( attributeNode->GetName() == "attribute" )
|
2017-07-16 16:12:05 +00:00
|
|
|
{
|
2021-09-20 14:35:45 +00:00
|
|
|
EATTR attr = EATTR( attributeNode );
|
2021-07-16 20:13:26 +00:00
|
|
|
SCH_FIELD* field = nullptr;
|
2018-07-10 14:32:10 +00:00
|
|
|
|
|
|
|
if( attr.name.Lower() == "name" )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
field = symbol->GetField( REFERENCE_FIELD );
|
2018-07-10 14:32:10 +00:00
|
|
|
nameAttributeFound = true;
|
|
|
|
}
|
|
|
|
else if( attr.name.Lower() == "value" )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
field = symbol->GetField( VALUE_FIELD );
|
2018-07-10 14:32:10 +00:00
|
|
|
valueAttributeFound = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
field = symbol->FindField( attr.name );
|
2017-07-16 16:12:05 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
if( field )
|
2018-07-10 14:32:10 +00:00
|
|
|
field->SetVisible( false );
|
|
|
|
}
|
2017-07-23 14:28:23 +00:00
|
|
|
|
2018-07-10 14:32:10 +00:00
|
|
|
if( field )
|
2017-10-03 10:23:52 +00:00
|
|
|
{
|
2017-08-20 03:38:47 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
field->SetPosition( VECTOR2I( attr.x->ToSchUnits(), -attr.y->ToSchUnits() ) );
|
2020-01-06 14:39:20 +00:00
|
|
|
int align = attr.align ? *attr.align : ETEXT::BOTTOM_LEFT;
|
|
|
|
int absdegrees = attr.rot ? attr.rot->degrees : 0;
|
|
|
|
bool mirror = attr.rot ? attr.rot->mirror : false;
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
if( einstance.rot && einstance.rot->mirror )
|
|
|
|
mirror = !mirror;
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2017-07-23 14:28:23 +00:00
|
|
|
bool spin = attr.rot ? attr.rot->spin : false;
|
2017-07-25 09:58:54 +00:00
|
|
|
|
2018-05-11 13:44:36 +00:00
|
|
|
if( attr.display == EATTR::Off || attr.display == EATTR::NAME )
|
2017-10-03 10:23:52 +00:00
|
|
|
field->SetVisible( false );
|
2017-08-20 03:38:47 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
int rotation = einstance.rot ? einstance.rot->degrees : 0;
|
2017-10-17 08:19:43 +00:00
|
|
|
int reldegrees = ( absdegrees - rotation + 360.0 );
|
2017-07-23 14:28:23 +00:00
|
|
|
reldegrees %= 360;
|
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
eagleToKicadAlignment( (EDA_TEXT*) field, align, reldegrees, mirror, spin,
|
|
|
|
absdegrees );
|
2017-07-16 16:12:05 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-10 14:32:10 +00:00
|
|
|
else if( attributeNode->GetName() == "variant" )
|
|
|
|
{
|
|
|
|
wxString variant, value;
|
|
|
|
|
|
|
|
if( attributeNode->GetAttribute( "name", &variant )
|
2020-01-06 14:39:20 +00:00
|
|
|
&& attributeNode->GetAttribute( "value", &value ) )
|
2018-07-10 14:32:10 +00:00
|
|
|
{
|
2021-09-20 14:35:45 +00:00
|
|
|
SCH_FIELD* field = symbol->AddField( *symbol->GetField( VALUE_FIELD ) );
|
2018-07-10 14:32:10 +00:00
|
|
|
field->SetName( "VARIANT_" + variant );
|
|
|
|
field->SetText( value );
|
|
|
|
field->SetVisible( false );
|
|
|
|
}
|
|
|
|
}
|
2017-07-16 16:12:05 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
attributeNode = attributeNode->GetNext();
|
2017-07-16 16:12:05 +00:00
|
|
|
}
|
2017-08-19 07:35:21 +00:00
|
|
|
|
2017-10-17 08:19:43 +00:00
|
|
|
if( einstance.smashed && einstance.smashed.Get() )
|
2017-10-03 10:23:52 +00:00
|
|
|
{
|
|
|
|
if( !valueAttributeFound )
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->GetField( VALUE_FIELD )->SetVisible( false );
|
2017-08-19 07:35:21 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
if( !nameAttributeFound )
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->GetField( REFERENCE_FIELD )->SetVisible( false );
|
2017-10-03 10:23:52 +00:00
|
|
|
}
|
2017-07-16 16:12:05 +00:00
|
|
|
|
2018-04-12 16:10:22 +00:00
|
|
|
// Save the pin positions
|
2020-06-17 21:30:24 +00:00
|
|
|
SYMBOL_LIB_TABLE& schLibTable = *m_schematic->Prj().SchSymbolLibTable();
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* libSymbol = schLibTable.LoadSymbol( symbol->GetLibId() );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
wxCHECK( libSymbol, /*void*/ );
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
symbol->SetLibSymbol( new LIB_SYMBOL( *libSymbol ) );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
2018-04-12 16:10:22 +00:00
|
|
|
std::vector<LIB_PIN*> pins;
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->GetLibPins( pins );
|
2018-04-12 16:10:22 +00:00
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
for( const LIB_PIN* pin : pins )
|
2021-06-10 14:10:55 +00:00
|
|
|
m_connPoints[symbol->GetPinPhysicalPosition( pin )].emplace( pin );
|
2018-04-12 16:10:22 +00:00
|
|
|
|
2021-09-20 18:54:47 +00:00
|
|
|
if( part->IsPower() )
|
|
|
|
m_powerPorts[ reference ] = symbol->GetField( VALUE_FIELD )->GetText();
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->ClearFlags();
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
screen->Append( symbol.release() );
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode,
|
|
|
|
EAGLE_LIBRARY* aEagleLibrary )
|
2017-05-08 14:10:23 +00:00
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
NODE_MAP libraryChildren = MapChildren( aLibraryNode );
|
2017-06-30 01:52:05 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
// Loop through the symbols and load each of them
|
2018-08-09 17:53:48 +00:00
|
|
|
wxXmlNode* symbolNode = getChildrenNodes( libraryChildren, "symbols" );
|
2017-05-08 14:27:11 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
while( symbolNode )
|
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
wxString symbolName = symbolNode->GetAttribute( "name" );
|
2017-10-03 10:23:52 +00:00
|
|
|
aEagleLibrary->SymbolNodes[symbolName] = symbolNode;
|
2020-01-06 14:39:20 +00:00
|
|
|
symbolNode = symbolNode->GetNext();
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
// Loop through the device sets and load each of them
|
2018-08-09 17:53:48 +00:00
|
|
|
wxXmlNode* devicesetNode = getChildrenNodes( libraryChildren, "devicesets" );
|
2017-07-06 12:31:11 +00:00
|
|
|
|
2017-06-30 01:52:05 +00:00
|
|
|
while( devicesetNode )
|
2017-06-26 07:56:11 +00:00
|
|
|
{
|
2017-06-30 01:52:05 +00:00
|
|
|
// Get Device set information
|
2017-10-03 10:23:52 +00:00
|
|
|
EDEVICE_SET edeviceset = EDEVICE_SET( devicesetNode );
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
wxString prefix = edeviceset.prefix ? edeviceset.prefix.Get() : "";
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
NODE_MAP deviceSetChildren = MapChildren( devicesetNode );
|
|
|
|
wxXmlNode* deviceNode = getChildrenNodes( deviceSetChildren, "devices" );
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2017-06-30 01:52:05 +00:00
|
|
|
// For each device in the device set:
|
2017-07-06 12:31:11 +00:00
|
|
|
while( deviceNode )
|
|
|
|
{
|
2017-06-30 01:52:05 +00:00
|
|
|
// Get device information
|
2017-07-06 12:31:11 +00:00
|
|
|
EDEVICE edevice = EDEVICE( deviceNode );
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2017-06-30 01:52:05 +00:00
|
|
|
// Create symbol name from deviceset and device names.
|
2017-12-14 09:37:32 +00:00
|
|
|
wxString symbolName = edeviceset.name + edevice.name;
|
2017-10-03 10:23:52 +00:00
|
|
|
symbolName.Replace( "*", "" );
|
2017-12-14 09:37:32 +00:00
|
|
|
wxASSERT( !symbolName.IsEmpty() );
|
2021-07-31 19:06:31 +00:00
|
|
|
symbolName = EscapeString( symbolName, CTX_LIBID );
|
2017-08-23 04:13:37 +00:00
|
|
|
|
2017-07-14 15:20:59 +00:00
|
|
|
if( edevice.package )
|
2017-12-14 09:37:32 +00:00
|
|
|
aEagleLibrary->package[symbolName] = edevice.package.Get();
|
2017-10-03 10:23:52 +00:00
|
|
|
|
|
|
|
// Create KiCad symbol.
|
2021-07-31 19:06:31 +00:00
|
|
|
unique_ptr<LIB_SYMBOL> libSymbol( new LIB_SYMBOL( symbolName ) );
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2017-06-30 01:52:05 +00:00
|
|
|
// Process each gate in the deviceset for this device.
|
2021-06-23 22:53:08 +00:00
|
|
|
wxXmlNode* gateNode = getChildrenNodes( deviceSetChildren, "gates" );
|
|
|
|
int gates_count = countChildren( deviceSetChildren["gates"], "gate" );
|
2021-07-31 19:06:31 +00:00
|
|
|
libSymbol->SetUnitCount( gates_count );
|
|
|
|
libSymbol->LockUnits( true );
|
2017-08-20 05:56:14 +00:00
|
|
|
|
2021-07-31 19:06:31 +00:00
|
|
|
LIB_FIELD* reference = libSymbol->GetFieldById( REFERENCE_FIELD );
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2017-10-17 08:19:43 +00:00
|
|
|
if( prefix.length() == 0 )
|
2021-07-31 19:06:31 +00:00
|
|
|
{
|
2017-08-20 05:56:14 +00:00
|
|
|
reference->SetVisible( false );
|
2021-07-31 19:06:31 +00:00
|
|
|
}
|
2017-08-20 05:56:14 +00:00
|
|
|
else
|
2021-07-31 19:06:31 +00:00
|
|
|
{
|
2018-03-22 17:17:23 +00:00
|
|
|
// If there is no footprint assigned, then prepend the reference value
|
|
|
|
// with a hash character to mute netlist updater complaints
|
|
|
|
reference->SetText( edevice.package ? prefix : '#' + prefix );
|
2021-07-31 19:06:31 +00:00
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
int gateindex = 1;
|
|
|
|
bool ispower = false;
|
2017-07-06 12:31:11 +00:00
|
|
|
|
|
|
|
while( gateNode )
|
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2017-07-06 12:31:11 +00:00
|
|
|
EGATE egate = EGATE( gateNode );
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
aEagleLibrary->GateUnit[edeviceset.name + edevice.name + egate.name] = gateindex;
|
2021-07-31 19:06:31 +00:00
|
|
|
ispower = loadSymbol( aEagleLibrary->SymbolNodes[egate.symbol], libSymbol, &edevice,
|
|
|
|
gateindex, egate.name );
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2017-07-02 12:26:23 +00:00
|
|
|
gateindex++;
|
2017-06-30 01:52:05 +00:00
|
|
|
gateNode = gateNode->GetNext();
|
2020-01-06 14:39:20 +00:00
|
|
|
} // gateNode
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2021-07-31 19:06:31 +00:00
|
|
|
libSymbol->SetUnitCount( gates_count );
|
2017-10-03 10:23:52 +00:00
|
|
|
|
|
|
|
if( gates_count == 1 && ispower )
|
2021-07-31 19:06:31 +00:00
|
|
|
libSymbol->SetPower();
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2022-01-05 10:14:14 +00:00
|
|
|
// assume that footprint library is identical to project name
|
|
|
|
wxString packageString = m_schematic->Prj().GetProjectName() + wxT( ":" ) + aEagleLibrary->package[symbolName];
|
|
|
|
libSymbol->GetFootprintField().SetText( packageString );
|
|
|
|
|
2021-07-31 19:06:31 +00:00
|
|
|
wxString name = libSymbol->GetName();
|
|
|
|
libSymbol->SetName( name );
|
|
|
|
m_pi->SaveSymbol( getLibFileName().GetFullPath(), new LIB_SYMBOL( *libSymbol.get() ),
|
|
|
|
m_properties.get() );
|
|
|
|
aEagleLibrary->KiCadSymbols.insert( name, libSymbol.release() );
|
2017-06-30 01:52:05 +00:00
|
|
|
|
|
|
|
deviceNode = deviceNode->GetNext();
|
2020-01-06 14:39:20 +00:00
|
|
|
} // devicenode
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2017-06-30 01:52:05 +00:00
|
|
|
devicesetNode = devicesetNode->GetNext();
|
2020-01-06 14:39:20 +00:00
|
|
|
} // devicesetNode
|
2017-06-30 01:52:05 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
return aEagleLibrary;
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr<LIB_SYMBOL>& aSymbol,
|
2021-07-17 19:56:18 +00:00
|
|
|
EDEVICE* aDevice, int aGateNumber, const wxString& aGateName )
|
2017-05-08 14:10:23 +00:00
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
wxString symbolName = aSymbolNode->GetAttribute( "name" );
|
2017-07-06 12:31:11 +00:00
|
|
|
std::vector<LIB_ITEM*> items;
|
2017-05-08 14:10:23 +00:00
|
|
|
|
|
|
|
wxXmlNode* currentNode = aSymbolNode->GetChildren();
|
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
bool foundName = false;
|
|
|
|
bool foundValue = false;
|
|
|
|
bool ispower = false;
|
|
|
|
int pincount = 0;
|
2017-07-16 16:15:04 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
while( currentNode )
|
|
|
|
{
|
2017-06-30 01:52:05 +00:00
|
|
|
wxString nodeName = currentNode->GetName();
|
2017-07-06 12:31:11 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
if( nodeName == "circle" )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->AddDrawItem( loadSymbolCircle( aSymbol, currentNode, aGateNumber ) );
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
2017-05-08 14:10:23 +00:00
|
|
|
else if( nodeName == "pin" )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
EPIN ePin = EPIN( currentNode );
|
2021-06-10 18:51:46 +00:00
|
|
|
std::unique_ptr<LIB_PIN> pin( loadPin( aSymbol, currentNode, &ePin, aGateNumber ) );
|
2017-07-30 09:50:38 +00:00
|
|
|
pincount++;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_BIDI );
|
2019-01-06 16:53:16 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
if( ePin.direction )
|
2017-07-30 09:50:38 +00:00
|
|
|
{
|
2018-04-03 11:16:29 +00:00
|
|
|
for( const auto& pinDir : pinDirectionsMap )
|
2017-08-05 05:41:03 +00:00
|
|
|
{
|
2018-04-03 11:16:29 +00:00
|
|
|
if( ePin.direction->Lower() == pinDir.first )
|
|
|
|
{
|
|
|
|
pin->SetType( pinDir.second );
|
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
if( pinDir.first == "sup" ) // power supply symbol
|
2018-04-03 11:16:29 +00:00
|
|
|
ispower = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2017-08-05 05:41:03 +00:00
|
|
|
}
|
2017-07-30 09:50:38 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
if( aDevice->connects.size() != 0 )
|
2017-07-06 12:31:11 +00:00
|
|
|
{
|
2021-09-20 14:35:45 +00:00
|
|
|
for( const ECONNECT& connect : aDevice->connects )
|
2017-07-06 12:31:11 +00:00
|
|
|
{
|
2017-12-14 09:37:32 +00:00
|
|
|
if( connect.gate == aGateName && pin->GetName() == connect.pin )
|
2017-07-09 02:40:23 +00:00
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
wxArrayString pads = wxSplit( wxString( connect.pad ), ' ' );
|
2017-09-23 07:34:20 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
pin->SetUnit( aGateNumber );
|
2017-10-11 12:28:07 +00:00
|
|
|
pin->SetName( escapeName( pin->GetName() ) );
|
2017-07-14 14:36:46 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
if( pads.GetCount() > 1 )
|
2017-09-23 07:34:20 +00:00
|
|
|
{
|
|
|
|
pin->SetNumberTextSize( 0 );
|
|
|
|
}
|
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
for( unsigned i = 0; i < pads.GetCount(); i++ )
|
2017-09-23 07:34:20 +00:00
|
|
|
{
|
|
|
|
LIB_PIN* apin = new LIB_PIN( *pin );
|
|
|
|
|
|
|
|
wxString padname( pads[i] );
|
|
|
|
apin->SetNumber( padname );
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->AddDrawItem( apin );
|
2017-09-23 07:34:20 +00:00
|
|
|
}
|
2019-06-10 00:00:09 +00:00
|
|
|
|
2017-07-09 02:40:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-07-06 12:31:11 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-09 02:40:23 +00:00
|
|
|
else
|
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
pin->SetUnit( aGateNumber );
|
2017-12-14 09:37:32 +00:00
|
|
|
pin->SetNumber( wxString::Format( "%i", pincount ) );
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->AddDrawItem( pin.release() );
|
2017-07-09 02:40:23 +00:00
|
|
|
}
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
2017-05-08 14:10:23 +00:00
|
|
|
else if( nodeName == "polygon" )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->AddDrawItem( loadSymbolPolyLine( aSymbol, currentNode, aGateNumber ) );
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
2017-05-08 14:10:23 +00:00
|
|
|
else if( nodeName == "rectangle" )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->AddDrawItem( loadSymbolRectangle( aSymbol, currentNode, aGateNumber ) );
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
2017-05-08 14:10:23 +00:00
|
|
|
else if( nodeName == "text" )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
std::unique_ptr<LIB_TEXT> libtext( loadSymbolText( aSymbol, currentNode,
|
|
|
|
aGateNumber ) );
|
2017-07-16 16:15:04 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
if( libtext->GetText().Upper() == ">NAME" )
|
2017-06-18 12:36:35 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_FIELD* field = aSymbol->GetFieldById( REFERENCE_FIELD );
|
2017-10-18 08:33:51 +00:00
|
|
|
loadFieldAttributes( field, libtext.get() );
|
|
|
|
foundName = true;
|
|
|
|
}
|
2020-01-06 14:39:20 +00:00
|
|
|
else if( libtext->GetText().Upper() == ">VALUE" )
|
2017-10-18 08:33:51 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_FIELD* field = aSymbol->GetFieldById( VALUE_FIELD );
|
2017-10-18 08:33:51 +00:00
|
|
|
loadFieldAttributes( field, libtext.get() );
|
|
|
|
foundValue = true;
|
2017-07-02 12:26:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->AddDrawItem( libtext.release() );
|
2017-06-18 12:36:35 +00:00
|
|
|
}
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
2017-05-08 14:10:23 +00:00
|
|
|
else if( nodeName == "wire" )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->AddDrawItem( loadSymbolWire( aSymbol, currentNode, aGateNumber ) );
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
2021-02-15 21:44:58 +00:00
|
|
|
else if( nodeName == "frame" )
|
|
|
|
{
|
|
|
|
std::vector<LIB_ITEM*> frameItems;
|
|
|
|
|
|
|
|
loadFrame( currentNode, frameItems );
|
|
|
|
|
|
|
|
for( LIB_ITEM* item : frameItems )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
item->SetParent( aSymbol.get() );
|
|
|
|
aSymbol->AddDrawItem( item );
|
2021-02-15 21:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-09 12:49:24 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
/*
|
|
|
|
* else if( nodeName == "description" )
|
|
|
|
* {
|
|
|
|
* }
|
|
|
|
* else if( nodeName == "dimension" )
|
|
|
|
* {
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
|
2017-03-09 12:49:24 +00:00
|
|
|
currentNode = currentNode->GetNext();
|
|
|
|
}
|
2017-07-16 16:15:04 +00:00
|
|
|
|
|
|
|
if( foundName == false )
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->GetFieldById( REFERENCE_FIELD )->SetVisible( false );
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2017-07-16 16:15:04 +00:00
|
|
|
if( foundValue == false )
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->GetFieldById( VALUE_FIELD )->SetVisible( false );
|
2017-07-16 16:15:04 +00:00
|
|
|
|
2017-07-30 09:50:38 +00:00
|
|
|
return pincount == 1 ? ispower : false;
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
|
|
|
|
2017-05-08 14:27:11 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* SCH_EAGLE_PLUGIN::loadSymbolCircle( std::unique_ptr<LIB_SYMBOL>& aSymbol,
|
|
|
|
wxXmlNode* aCircleNode, int aGateNumber )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2017-05-08 15:11:14 +00:00
|
|
|
// Parse the circle properties
|
2021-07-18 23:08:54 +00:00
|
|
|
ECIRCLE c( aCircleNode );
|
|
|
|
LIB_SHAPE* circle = new LIB_SHAPE( aSymbol.get(), SHAPE_T::CIRCLE );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I center( c.x.ToSchUnits(), c.y.ToSchUnits() );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
circle->SetPosition( center );
|
2022-01-01 06:04:08 +00:00
|
|
|
circle->SetEnd( VECTOR2I( center.x + c.radius.ToSchUnits(), center.y ) );
|
2021-07-17 19:56:18 +00:00
|
|
|
circle->SetStroke( STROKE_PARAMS( c.width.ToSchUnits(), PLOT_DASH_TYPE::SOLID ) );
|
2017-10-03 10:23:52 +00:00
|
|
|
circle->SetUnit( aGateNumber );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
return circle;
|
2017-05-08 15:11:14 +00:00
|
|
|
}
|
2017-03-09 12:49:24 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* SCH_EAGLE_PLUGIN::loadSymbolRectangle( std::unique_ptr<LIB_SYMBOL>& aSymbol,
|
|
|
|
wxXmlNode* aRectNode, int aGateNumber )
|
2017-05-08 15:11:14 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
ERECT rect( aRectNode );
|
|
|
|
LIB_SHAPE* rectangle = new LIB_SHAPE( aSymbol.get(), SHAPE_T::RECT );
|
2017-05-08 15:11:14 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
rectangle->SetPosition( VECTOR2I( rect.x1.ToSchUnits(), rect.y1.ToSchUnits() ) );
|
|
|
|
rectangle->SetEnd( VECTOR2I( rect.x2.ToSchUnits(), rect.y2.ToSchUnits() ) );
|
2017-05-08 15:11:14 +00:00
|
|
|
|
2022-01-12 21:47:37 +00:00
|
|
|
if( rect.rot )
|
|
|
|
{
|
2022-01-12 23:49:03 +00:00
|
|
|
VECTOR2I pos( rectangle->GetPosition() );
|
|
|
|
VECTOR2I end( rectangle->GetEnd() );
|
|
|
|
VECTOR2I center( rectangle->GetCenter() );
|
2022-01-12 21:47:37 +00:00
|
|
|
|
2022-01-12 23:49:03 +00:00
|
|
|
RotatePoint( pos, center, rect.rot->degrees * 10 );
|
|
|
|
RotatePoint( end, center, rect.rot->degrees * 10 );
|
2022-01-12 21:47:37 +00:00
|
|
|
|
|
|
|
rectangle->SetPosition( pos );
|
|
|
|
rectangle->SetEnd( end );
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
rectangle->SetUnit( aGateNumber );
|
2021-02-15 21:44:58 +00:00
|
|
|
|
2017-07-23 14:27:42 +00:00
|
|
|
// Eagle rectangles are filled by definition.
|
2021-07-18 23:08:54 +00:00
|
|
|
rectangle->SetFillMode( FILL_T::FILLED_SHAPE );
|
2017-05-08 15:11:14 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
return rectangle;
|
2017-05-08 15:11:14 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
LIB_ITEM* SCH_EAGLE_PLUGIN::loadSymbolWire( std::unique_ptr<LIB_SYMBOL>& aSymbol,
|
|
|
|
wxXmlNode* aWireNode, int aGateNumber )
|
2017-06-18 11:31:11 +00:00
|
|
|
{
|
2021-09-20 14:35:45 +00:00
|
|
|
EWIRE ewire = EWIRE( aWireNode );
|
2017-07-25 13:51:07 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I begin, end;
|
2017-06-18 11:31:11 +00:00
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
begin.x = ewire.x1.ToSchUnits();
|
|
|
|
begin.y = ewire.y1.ToSchUnits();
|
|
|
|
end.x = ewire.x2.ToSchUnits();
|
|
|
|
end.y = ewire.y2.ToSchUnits();
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2019-05-27 03:12:27 +00:00
|
|
|
if( begin == end )
|
|
|
|
return nullptr;
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// if the wire is an arc
|
2017-07-25 13:51:07 +00:00
|
|
|
if( ewire.curve )
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* arc = new LIB_SHAPE( aSymbol.get(), SHAPE_T::ARC );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I center = ConvertArcCenter( begin, end, *ewire.curve * -1 );
|
2021-07-18 23:08:54 +00:00
|
|
|
double radius = sqrt( abs( ( ( center.x - begin.x ) * ( center.x - begin.x ) )
|
|
|
|
+ ( ( center.y - begin.y ) * ( center.y - begin.y ) ) ) )
|
|
|
|
* 2;
|
2017-07-25 13:51:07 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// this emulates the filled semicircles created by a thick arc with flat ends caps.
|
2017-10-17 08:18:54 +00:00
|
|
|
if( ewire.width.ToSchUnits() * 2 > radius )
|
2017-10-03 10:23:52 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I centerStartVector = begin - center;
|
|
|
|
VECTOR2I centerEndVector = end - center;
|
2017-07-25 13:51:07 +00:00
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
centerStartVector.x = centerStartVector.x * ewire.width.ToSchUnits() * 2 / radius;
|
|
|
|
centerStartVector.y = centerStartVector.y * ewire.width.ToSchUnits() * 2 / radius;
|
2017-05-08 15:11:14 +00:00
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
centerEndVector.x = centerEndVector.x * ewire.width.ToSchUnits() * 2 / radius;
|
|
|
|
centerEndVector.y = centerEndVector.y * ewire.width.ToSchUnits() * 2 / radius;
|
2017-06-18 11:31:11 +00:00
|
|
|
|
2017-07-25 13:51:07 +00:00
|
|
|
begin = center + centerStartVector;
|
2020-01-06 14:39:20 +00:00
|
|
|
end = center + centerEndVector;
|
2017-10-17 08:18:54 +00:00
|
|
|
|
2017-08-07 09:25:15 +00:00
|
|
|
radius = sqrt( abs( ( ( center.x - begin.x ) * ( center.x - begin.x ) )
|
2020-01-06 14:39:20 +00:00
|
|
|
+ ( ( center.y - begin.y ) * ( center.y - begin.y ) ) ) )
|
|
|
|
* 2;
|
2017-07-25 13:51:07 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
arc->SetStroke( STROKE_PARAMS( 1, PLOT_DASH_TYPE::SOLID ) );
|
2021-07-18 23:08:54 +00:00
|
|
|
arc->SetFillMode( FILL_T::FILLED_SHAPE );
|
2017-07-25 13:51:07 +00:00
|
|
|
}
|
2017-10-17 08:18:54 +00:00
|
|
|
else
|
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
arc->SetStroke( STROKE_PARAMS( ewire.width.ToSchUnits(), PLOT_DASH_TYPE::SOLID ) );
|
2017-10-17 08:18:54 +00:00
|
|
|
}
|
2017-07-25 13:51:07 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
arc->SetArcGeometry( begin, CalcArcMid( begin, end, center ), end );
|
2017-10-03 10:23:52 +00:00
|
|
|
arc->SetUnit( aGateNumber );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
return arc;
|
2017-07-25 13:51:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* poly = new LIB_SHAPE( aSymbol.get(), SHAPE_T::POLY );
|
2017-07-25 13:51:07 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
poly->AddPoint( begin );
|
|
|
|
poly->AddPoint( end );
|
|
|
|
poly->SetUnit( aGateNumber );
|
2021-07-17 19:56:18 +00:00
|
|
|
poly->SetStroke( STROKE_PARAMS( ewire.width.ToSchUnits(), PLOT_DASH_TYPE::SOLID ) );
|
2017-10-17 08:18:54 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
return poly;
|
2017-07-25 13:51:07 +00:00
|
|
|
}
|
2017-06-18 11:31:11 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* SCH_EAGLE_PLUGIN::loadSymbolPolyLine( std::unique_ptr<LIB_SYMBOL>& aSymbol,
|
|
|
|
wxXmlNode* aPolygonNode, int aGateNumber )
|
2017-05-08 15:11:14 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* poly = new LIB_SHAPE( aSymbol.get(), SHAPE_T::POLY );
|
2020-01-06 14:39:20 +00:00
|
|
|
EPOLYGON epoly( aPolygonNode );
|
2017-07-17 12:47:49 +00:00
|
|
|
wxXmlNode* vertex = aPolygonNode->GetChildren();
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pt;
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
while( vertex )
|
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
if( vertex->GetName() == "vertex" ) // skip <xmlattr> node
|
2017-07-17 12:47:49 +00:00
|
|
|
{
|
|
|
|
EVERTEX evertex( vertex );
|
2022-01-01 06:04:08 +00:00
|
|
|
pt = VECTOR2I( evertex.x.ToSchUnits(), evertex.y.ToSchUnits() );
|
2021-07-18 23:08:54 +00:00
|
|
|
poly->AddPoint( pt );
|
2017-07-17 12:47:49 +00:00
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2017-07-17 12:47:49 +00:00
|
|
|
vertex = vertex->GetNext();
|
2017-05-08 15:11:14 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
poly->SetFillMode( FILL_T::FILLED_SHAPE );
|
|
|
|
poly->SetUnit( aGateNumber );
|
2017-07-17 12:47:49 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
return poly;
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
2017-02-27 10:07:52 +00:00
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
LIB_PIN* SCH_EAGLE_PLUGIN::loadPin( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode* aPin,
|
|
|
|
EPIN* aEPin, int aGateNumber )
|
2017-06-18 11:31:11 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
std::unique_ptr<LIB_PIN> pin = std::make_unique<LIB_PIN>( aSymbol.get() );
|
2022-01-01 06:04:08 +00:00
|
|
|
pin->SetPosition( VECTOR2I( aEPin->x.ToSchUnits(), aEPin->y.ToSchUnits() ) );
|
2017-10-03 10:30:23 +00:00
|
|
|
pin->SetName( aEPin->name );
|
2017-10-03 10:23:52 +00:00
|
|
|
pin->SetUnit( aGateNumber );
|
2017-06-18 11:31:11 +00:00
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
int roti = aEPin->rot ? aEPin->rot->degrees : 0;
|
2017-06-18 12:25:36 +00:00
|
|
|
|
|
|
|
switch( roti )
|
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
case 0: pin->SetOrientation( 'R' ); break;
|
|
|
|
case 90: pin->SetOrientation( 'U' ); break;
|
|
|
|
case 180: pin->SetOrientation( 'L' ); break;
|
|
|
|
case 270: pin->SetOrientation( 'D' ); break;
|
|
|
|
default: wxFAIL_MSG( wxString::Format( "Unhandled orientation (%d degrees).", roti ) );
|
2017-06-18 12:25:36 +00:00
|
|
|
}
|
|
|
|
|
2021-02-15 21:44:58 +00:00
|
|
|
pin->SetLength( Mils2iu( 300 ) ); // Default pin length when not defined.
|
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
if( aEPin->length )
|
2017-06-18 12:25:36 +00:00
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
wxString length = aEPin->length.Get();
|
2017-06-19 12:44:31 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
if( length == "short" )
|
2020-01-05 19:11:15 +00:00
|
|
|
pin->SetLength( Mils2iu( 100 ) );
|
2020-01-06 14:39:20 +00:00
|
|
|
else if( length == "middle" )
|
2020-01-05 19:11:15 +00:00
|
|
|
pin->SetLength( Mils2iu( 200 ) );
|
2017-06-19 12:44:31 +00:00
|
|
|
else if( length == "long" )
|
2020-01-05 19:11:15 +00:00
|
|
|
pin->SetLength( Mils2iu( 300 ) );
|
2017-06-19 12:44:31 +00:00
|
|
|
else if( length == "point" )
|
2020-01-05 19:11:15 +00:00
|
|
|
pin->SetLength( Mils2iu( 0 ) );
|
2017-06-18 12:25:36 +00:00
|
|
|
}
|
2017-06-18 11:31:11 +00:00
|
|
|
|
2017-10-18 08:33:51 +00:00
|
|
|
// emulate the visibility of pin elements
|
2017-10-03 10:30:23 +00:00
|
|
|
if( aEPin->visible )
|
2017-07-16 16:13:10 +00:00
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
wxString visible = aEPin->visible.Get();
|
2017-07-16 16:13:10 +00:00
|
|
|
|
|
|
|
if( visible == "off" )
|
|
|
|
{
|
|
|
|
pin->SetNameTextSize( 0 );
|
|
|
|
pin->SetNumberTextSize( 0 );
|
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
else if( visible == "pad" )
|
2017-07-16 16:13:10 +00:00
|
|
|
{
|
|
|
|
pin->SetNameTextSize( 0 );
|
|
|
|
}
|
|
|
|
else if( visible == "pin" )
|
|
|
|
{
|
|
|
|
pin->SetNumberTextSize( 0 );
|
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2017-07-16 16:13:10 +00:00
|
|
|
/*
|
2017-10-03 10:23:52 +00:00
|
|
|
* else if( visible == "both" )
|
|
|
|
* {
|
|
|
|
* }
|
|
|
|
*/
|
2017-07-16 16:13:10 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
if( aEPin->function )
|
2017-08-19 05:41:48 +00:00
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
wxString function = aEPin->function.Get();
|
2017-08-19 05:41:48 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
if( function == "dot" )
|
2020-01-18 20:51:28 +00:00
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::INVERTED );
|
2017-10-03 10:23:52 +00:00
|
|
|
else if( function == "clk" )
|
2020-01-18 20:51:28 +00:00
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::CLOCK );
|
2017-10-03 10:23:52 +00:00
|
|
|
else if( function == "dotclk" )
|
2020-01-18 20:51:28 +00:00
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::INVERTED_CLOCK );
|
2017-08-19 05:41:48 +00:00
|
|
|
}
|
|
|
|
|
2017-06-18 12:25:36 +00:00
|
|
|
return pin.release();
|
2017-06-18 11:31:11 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymbolText( std::unique_ptr<LIB_SYMBOL>& aSymbol,
|
|
|
|
wxXmlNode* aLibText, int aGateNumber )
|
2017-06-18 12:36:35 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
std::unique_ptr<LIB_TEXT> libtext = std::make_unique<LIB_TEXT>( aSymbol.get() );
|
2020-01-06 14:39:20 +00:00
|
|
|
ETEXT etext( aLibText );
|
2017-06-18 12:36:35 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
libtext->SetUnit( aGateNumber );
|
2022-01-01 06:04:08 +00:00
|
|
|
libtext->SetPosition( VECTOR2I( etext.x.ToSchUnits(), etext.y.ToSchUnits() ) );
|
2017-11-04 01:37:18 +00:00
|
|
|
|
|
|
|
// Eagle supports multiple line text in library symbols. Legacy library symbol text cannot
|
|
|
|
// contain CRs or LFs.
|
|
|
|
//
|
|
|
|
// @todo Split this into multiple text objects and offset the Y position so that it looks
|
|
|
|
// more like the original Eagle schematic.
|
|
|
|
wxString text = aLibText->GetNodeContent();
|
|
|
|
std::replace( text.begin(), text.end(), '\n', '_' );
|
|
|
|
std::replace( text.begin(), text.end(), '\r', '_' );
|
|
|
|
|
2021-09-01 18:24:42 +00:00
|
|
|
libtext->SetText( text.IsEmpty() ? "~" : text );
|
2017-10-18 08:12:22 +00:00
|
|
|
loadTextAttributes( libtext.get(), etext );
|
2017-06-18 12:36:35 +00:00
|
|
|
|
|
|
|
return libtext.release();
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2021-02-15 21:44:58 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::loadFrame( wxXmlNode* aFrameNode, std::vector<LIB_ITEM*>& aItems )
|
|
|
|
{
|
|
|
|
EFRAME eframe( aFrameNode );
|
|
|
|
|
2021-02-16 14:33:15 +00:00
|
|
|
int xMin = eframe.x1.ToSchUnits();
|
|
|
|
int xMax = eframe.x2.ToSchUnits();
|
|
|
|
int yMin = eframe.y1.ToSchUnits();
|
|
|
|
int yMax = eframe.y2.ToSchUnits();
|
|
|
|
|
|
|
|
if( xMin > xMax )
|
|
|
|
std::swap( xMin, xMax );
|
|
|
|
|
|
|
|
if( yMin > yMax )
|
|
|
|
std::swap( yMin, yMax );
|
2021-02-15 21:44:58 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* lines = new LIB_SHAPE( nullptr, SHAPE_T::POLY );
|
2022-01-01 06:04:08 +00:00
|
|
|
lines->AddPoint( VECTOR2I( xMin, yMin ) );
|
|
|
|
lines->AddPoint( VECTOR2I( xMax, yMin ) );
|
|
|
|
lines->AddPoint( VECTOR2I( xMax, yMax ) );
|
|
|
|
lines->AddPoint( VECTOR2I( xMin, yMax ) );
|
|
|
|
lines->AddPoint( VECTOR2I( xMin, yMin ) );
|
2021-02-15 21:44:58 +00:00
|
|
|
aItems.push_back( lines );
|
2021-02-16 14:33:15 +00:00
|
|
|
|
|
|
|
if( !eframe.border_left )
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
lines = new LIB_SHAPE( nullptr, SHAPE_T::POLY );
|
2022-01-01 06:04:08 +00:00
|
|
|
lines->AddPoint( VECTOR2I( xMin + Mils2iu( 150 ), yMin + Mils2iu( 150 ) ) );
|
|
|
|
lines->AddPoint( VECTOR2I( xMin + Mils2iu( 150 ), yMax - Mils2iu( 150 ) ) );
|
2021-02-16 14:33:15 +00:00
|
|
|
aItems.push_back( lines );
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int height = yMax - yMin;
|
|
|
|
int x1 = xMin;
|
|
|
|
int x2 = x1 + Mils2iu( 150 );
|
|
|
|
int legendPosX = xMin + Mils2iu( 75 );
|
|
|
|
double rowSpacing = height / double( eframe.rows );
|
|
|
|
double legendPosY = yMax - ( rowSpacing / 2 );
|
|
|
|
|
|
|
|
for( i = 1; i < eframe.rows; i++ )
|
|
|
|
{
|
|
|
|
int newY = KiROUND( yMin + ( rowSpacing * (double) i ) );
|
2021-07-18 23:08:54 +00:00
|
|
|
lines = new LIB_SHAPE( nullptr, SHAPE_T::POLY );
|
2022-01-01 06:04:08 +00:00
|
|
|
lines->AddPoint( VECTOR2I( x1, newY ) );
|
|
|
|
lines->AddPoint( VECTOR2I( x2, newY ) );
|
2021-02-16 14:33:15 +00:00
|
|
|
aItems.push_back( lines );
|
|
|
|
}
|
|
|
|
|
|
|
|
char legendChar = 'A';
|
|
|
|
|
|
|
|
for( i = 0; i < eframe.rows; i++ )
|
|
|
|
{
|
|
|
|
LIB_TEXT* legendText = new LIB_TEXT( nullptr );
|
2022-01-01 06:04:08 +00:00
|
|
|
legendText->SetPosition( VECTOR2I( legendPosX, KiROUND( legendPosY ) ) );
|
2021-02-16 14:33:15 +00:00
|
|
|
legendText->SetText( wxString( legendChar ) );
|
|
|
|
legendText->SetTextSize( wxSize( Mils2iu( 90 ), Mils2iu( 100 ) ) );
|
|
|
|
aItems.push_back( legendText );
|
|
|
|
legendChar++;
|
|
|
|
legendPosY -= rowSpacing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !eframe.border_right )
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
lines = new LIB_SHAPE( nullptr, SHAPE_T::POLY );
|
2022-01-01 06:04:08 +00:00
|
|
|
lines->AddPoint( VECTOR2I( xMax - Mils2iu( 150 ), yMin + Mils2iu( 150 ) ) );
|
|
|
|
lines->AddPoint( VECTOR2I( xMax - Mils2iu( 150 ), yMax - Mils2iu( 150 ) ) );
|
2021-02-16 14:33:15 +00:00
|
|
|
aItems.push_back( lines );
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int height = yMax - yMin;
|
|
|
|
int x1 = xMax - Mils2iu( 150 );
|
|
|
|
int x2 = xMax;
|
|
|
|
int legendPosX = xMax - Mils2iu( 75 );
|
|
|
|
double rowSpacing = height / double( eframe.rows );
|
|
|
|
double legendPosY = yMax - ( rowSpacing / 2 );
|
|
|
|
|
|
|
|
for( i = 1; i < eframe.rows; i++ )
|
|
|
|
{
|
|
|
|
int newY = KiROUND( yMin + ( rowSpacing * (double) i ) );
|
2021-07-18 23:08:54 +00:00
|
|
|
lines = new LIB_SHAPE( nullptr, SHAPE_T::POLY );
|
2022-01-01 06:04:08 +00:00
|
|
|
lines->AddPoint( VECTOR2I( x1, newY ) );
|
|
|
|
lines->AddPoint( VECTOR2I( x2, newY ) );
|
2021-02-16 14:33:15 +00:00
|
|
|
aItems.push_back( lines );
|
|
|
|
}
|
|
|
|
|
|
|
|
char legendChar = 'A';
|
|
|
|
|
|
|
|
for( i = 0; i < eframe.rows; i++ )
|
|
|
|
{
|
|
|
|
LIB_TEXT* legendText = new LIB_TEXT( nullptr );
|
2022-01-01 06:04:08 +00:00
|
|
|
legendText->SetPosition( VECTOR2I( legendPosX, KiROUND( legendPosY ) ) );
|
2021-02-16 14:33:15 +00:00
|
|
|
legendText->SetText( wxString( legendChar ) );
|
|
|
|
legendText->SetTextSize( wxSize( Mils2iu( 90 ), Mils2iu( 100 ) ) );
|
|
|
|
aItems.push_back( legendText );
|
|
|
|
legendChar++;
|
|
|
|
legendPosY -= rowSpacing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !eframe.border_top )
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
lines = new LIB_SHAPE( nullptr, SHAPE_T::POLY );
|
2022-01-01 06:04:08 +00:00
|
|
|
lines->AddPoint( VECTOR2I( xMax - Mils2iu( 150 ), yMax - Mils2iu( 150 ) ) );
|
|
|
|
lines->AddPoint( VECTOR2I( xMin + Mils2iu( 150 ), yMax - Mils2iu( 150 ) ) );
|
2021-02-16 14:33:15 +00:00
|
|
|
aItems.push_back( lines );
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int width = xMax - xMin;
|
|
|
|
int y1 = yMin;
|
|
|
|
int y2 = yMin + Mils2iu( 150 );
|
|
|
|
int legendPosY = yMax - Mils2iu( 75 );
|
|
|
|
double columnSpacing = width / double( eframe.columns );
|
|
|
|
double legendPosX = xMin + ( columnSpacing / 2 );
|
|
|
|
|
|
|
|
for( i = 1; i < eframe.columns; i++ )
|
|
|
|
{
|
|
|
|
int newX = KiROUND( xMin + ( columnSpacing * (double) i ) );
|
2021-07-18 23:08:54 +00:00
|
|
|
lines = new LIB_SHAPE( nullptr, SHAPE_T::POLY );
|
2022-01-01 06:04:08 +00:00
|
|
|
lines->AddPoint( VECTOR2I( newX, y1 ) );
|
|
|
|
lines->AddPoint( VECTOR2I( newX, y2 ) );
|
2021-02-16 14:33:15 +00:00
|
|
|
aItems.push_back( lines );
|
|
|
|
}
|
|
|
|
|
|
|
|
char legendChar = '1';
|
|
|
|
|
|
|
|
for( i = 0; i < eframe.columns; i++ )
|
|
|
|
{
|
|
|
|
LIB_TEXT* legendText = new LIB_TEXT( nullptr );
|
2022-01-01 06:04:08 +00:00
|
|
|
legendText->SetPosition( VECTOR2I( KiROUND( legendPosX ), legendPosY ) );
|
2021-02-16 14:33:15 +00:00
|
|
|
legendText->SetText( wxString( legendChar ) );
|
|
|
|
legendText->SetTextSize( wxSize( Mils2iu( 90 ), Mils2iu( 100 ) ) );
|
|
|
|
aItems.push_back( legendText );
|
|
|
|
legendChar++;
|
|
|
|
legendPosX += columnSpacing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !eframe.border_bottom )
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
lines = new LIB_SHAPE( nullptr, SHAPE_T::POLY );
|
2022-01-01 06:04:08 +00:00
|
|
|
lines->AddPoint( VECTOR2I( xMax - Mils2iu( 150 ), yMin + Mils2iu( 150 ) ) );
|
|
|
|
lines->AddPoint( VECTOR2I( xMin + Mils2iu( 150 ), yMin + Mils2iu( 150 ) ) );
|
2021-02-16 14:33:15 +00:00
|
|
|
aItems.push_back( lines );
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int width = xMax - xMin;
|
|
|
|
int y1 = yMax - Mils2iu( 150 );
|
|
|
|
int y2 = yMax;
|
|
|
|
int legendPosY = yMin + Mils2iu( 75 );
|
|
|
|
double columnSpacing = width / double( eframe.columns );
|
|
|
|
double legendPosX = xMin + ( columnSpacing / 2 );
|
|
|
|
|
|
|
|
for( i = 1; i < eframe.columns; i++ )
|
|
|
|
{
|
|
|
|
int newX = KiROUND( xMin + ( columnSpacing * (double) i ) );
|
2021-07-18 23:08:54 +00:00
|
|
|
lines = new LIB_SHAPE( nullptr, SHAPE_T::POLY );
|
2022-01-01 06:04:08 +00:00
|
|
|
lines->AddPoint( VECTOR2I( newX, y1 ) );
|
|
|
|
lines->AddPoint( VECTOR2I( newX, y2 ) );
|
2021-02-16 14:33:15 +00:00
|
|
|
aItems.push_back( lines );
|
|
|
|
}
|
|
|
|
|
|
|
|
char legendChar = '1';
|
|
|
|
|
|
|
|
for( i = 0; i < eframe.columns; i++ )
|
|
|
|
{
|
|
|
|
LIB_TEXT* legendText = new LIB_TEXT( nullptr );
|
2022-01-01 06:04:08 +00:00
|
|
|
legendText->SetPosition( VECTOR2I( KiROUND( legendPosX ), legendPosY ) );
|
2021-02-16 14:33:15 +00:00
|
|
|
legendText->SetText( wxString( legendChar ) );
|
|
|
|
legendText->SetTextSize( wxSize( Mils2iu( 90 ), Mils2iu( 100 ) ) );
|
|
|
|
aItems.push_back( legendText );
|
|
|
|
legendChar++;
|
|
|
|
legendPosX += columnSpacing;
|
|
|
|
}
|
|
|
|
}
|
2021-02-15 21:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
SCH_TEXT* SCH_EAGLE_PLUGIN::loadPlainText( wxXmlNode* aSchText )
|
2017-07-05 15:05:03 +00:00
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<SCH_TEXT> schtext = std::make_unique<SCH_TEXT>();
|
|
|
|
ETEXT etext = ETEXT( aSchText );
|
2017-07-05 15:05:03 +00:00
|
|
|
|
2017-10-18 08:12:22 +00:00
|
|
|
const wxString& thetext = aSchText->GetNodeContent();
|
2021-02-15 21:44:58 +00:00
|
|
|
|
|
|
|
wxString adjustedText;
|
|
|
|
wxStringTokenizer tokenizer( thetext, "\r\n" );
|
|
|
|
|
|
|
|
// Strip the whitespace from both ends of each line.
|
|
|
|
while( tokenizer.HasMoreTokens() )
|
|
|
|
{
|
|
|
|
wxString tmp = tokenizer.GetNextToken().Trim();
|
|
|
|
|
|
|
|
tmp = tmp.Trim( false );
|
|
|
|
|
|
|
|
if( tokenizer.HasMoreTokens() )
|
|
|
|
tmp += wxT( "\n" );
|
|
|
|
|
|
|
|
adjustedText += tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
schtext->SetText( adjustedText.IsEmpty() ? "\" \"" : escapeName( adjustedText ) );
|
2022-01-01 06:04:08 +00:00
|
|
|
schtext->SetPosition( VECTOR2I( etext.x.ToSchUnits(), -etext.y.ToSchUnits() ) );
|
2017-10-18 08:12:22 +00:00
|
|
|
loadTextAttributes( schtext.get(), etext );
|
|
|
|
schtext->SetItalic( false );
|
2017-08-19 07:34:22 +00:00
|
|
|
|
2017-10-18 08:12:22 +00:00
|
|
|
return schtext.release();
|
|
|
|
}
|
2017-07-05 15:05:03 +00:00
|
|
|
|
2017-10-18 08:12:22 +00:00
|
|
|
|
|
|
|
void SCH_EAGLE_PLUGIN::loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs ) const
|
|
|
|
{
|
|
|
|
aText->SetTextSize( aAttribs.ConvertSize() );
|
|
|
|
|
|
|
|
if( aAttribs.ratio )
|
2017-07-05 15:05:03 +00:00
|
|
|
{
|
2017-10-18 08:12:22 +00:00
|
|
|
if( aAttribs.ratio.CGet() > 12 )
|
2017-07-05 15:05:03 +00:00
|
|
|
{
|
2017-10-18 08:12:22 +00:00
|
|
|
aText->SetBold( true );
|
2020-04-14 12:25:00 +00:00
|
|
|
aText->SetTextThickness( GetPenSizeForBold( aText->GetTextWidth() ) );
|
2017-07-05 15:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
int align = aAttribs.align ? *aAttribs.align : ETEXT::BOTTOM_LEFT;
|
|
|
|
int degrees = aAttribs.rot ? aAttribs.rot->degrees : 0;
|
|
|
|
bool mirror = aAttribs.rot ? aAttribs.rot->mirror : false;
|
|
|
|
bool spin = aAttribs.rot ? aAttribs.rot->spin : false;
|
2017-07-23 14:28:23 +00:00
|
|
|
|
2017-10-18 08:12:22 +00:00
|
|
|
eagleToKicadAlignment( aText, align, degrees, mirror, spin, 0 );
|
2017-07-05 15:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-18 08:33:51 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::loadFieldAttributes( LIB_FIELD* aField, const LIB_TEXT* aText ) const
|
|
|
|
{
|
|
|
|
aField->SetTextPos( aText->GetPosition() );
|
|
|
|
aField->SetTextSize( aText->GetTextSize() );
|
|
|
|
aField->SetTextAngle( aText->GetTextAngle() );
|
|
|
|
aField->SetBold( aText->IsBold() );
|
|
|
|
aField->SetVertJustify( aText->GetVertJustify() );
|
|
|
|
aField->SetHorizJustify( aText->GetHorizJustify() );
|
|
|
|
aField->SetVisible( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-28 14:03:27 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::adjustNetLabels()
|
|
|
|
{
|
|
|
|
// Eagle supports detached labels, so a label does not need to be placed on a wire
|
|
|
|
// to be associated with it. KiCad needs to move them, so the labels actually touch the
|
|
|
|
// corresponding wires.
|
|
|
|
|
|
|
|
// Sort the intersection points to speed up the search process
|
|
|
|
std::sort( m_wireIntersections.begin(), m_wireIntersections.end() );
|
|
|
|
|
2021-02-15 21:44:58 +00:00
|
|
|
auto onIntersection =
|
|
|
|
[&]( const VECTOR2I& aPos )
|
|
|
|
{
|
|
|
|
return std::binary_search( m_wireIntersections.begin(),
|
|
|
|
m_wireIntersections.end(), aPos );
|
|
|
|
};
|
2018-03-28 14:03:27 +00:00
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
for( SEG_DESC& segDesc : m_segments )
|
2018-03-28 14:03:27 +00:00
|
|
|
{
|
|
|
|
for( SCH_TEXT* label : segDesc.labels )
|
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
VECTOR2I labelPos( label->GetPosition() );
|
2018-03-28 14:03:27 +00:00
|
|
|
const SEG* segAttached = segDesc.LabelAttached( label );
|
|
|
|
|
|
|
|
if( segAttached && !onIntersection( labelPos ) )
|
2020-01-06 14:39:20 +00:00
|
|
|
continue; // label is placed correctly
|
2018-03-28 14:03:27 +00:00
|
|
|
|
|
|
|
// Move the label to the nearest wire
|
|
|
|
if( !segAttached )
|
|
|
|
{
|
2021-09-20 14:35:45 +00:00
|
|
|
std::tie( labelPos, segAttached ) = findNearestLinePoint( label->GetPosition(),
|
|
|
|
segDesc.segs );
|
2018-03-28 14:03:27 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
if( !segAttached ) // we cannot do anything
|
2018-03-28 14:03:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a vector pointing in the direction of the wire, 50 mils long
|
|
|
|
VECTOR2I wireDirection( segAttached->B - segAttached->A );
|
2020-01-05 19:11:15 +00:00
|
|
|
wireDirection = wireDirection.Resize( Mils2iu( 50 ) );
|
2018-03-28 14:03:27 +00:00
|
|
|
const VECTOR2I origPos( labelPos );
|
|
|
|
|
|
|
|
// Flags determining the search direction
|
|
|
|
bool checkPositive = true, checkNegative = true, move = false;
|
2020-01-06 14:39:20 +00:00
|
|
|
int trial = 0;
|
2018-03-28 14:03:27 +00:00
|
|
|
|
|
|
|
// Be sure the label is not placed on a wire intersection
|
|
|
|
while( ( !move || onIntersection( labelPos ) ) && ( checkPositive || checkNegative ) )
|
|
|
|
{
|
|
|
|
move = false;
|
|
|
|
|
|
|
|
// Move along the attached wire to find the new label position
|
|
|
|
if( trial % 2 == 1 )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
labelPos = VECTOR2I( origPos + wireDirection * trial / 2 );
|
2018-03-28 14:03:27 +00:00
|
|
|
move = checkPositive = segAttached->Contains( labelPos );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
labelPos = VECTOR2I( origPos - wireDirection * trial / 2 );
|
2018-03-28 14:03:27 +00:00
|
|
|
move = checkNegative = segAttached->Contains( labelPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
++trial;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( move )
|
2022-01-01 06:04:08 +00:00
|
|
|
label->SetPosition( VECTOR2I( labelPos ) );
|
2018-03-28 14:03:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_segments.clear();
|
|
|
|
m_wireIntersections.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-21 12:41:00 +00:00
|
|
|
bool SCH_EAGLE_PLUGIN::CheckHeader( const wxString& aFileName )
|
|
|
|
{
|
|
|
|
// Open file and check first line
|
|
|
|
wxTextFile tempFile;
|
|
|
|
|
|
|
|
tempFile.Open( aFileName );
|
|
|
|
wxString firstline;
|
2021-02-15 21:44:58 +00:00
|
|
|
|
2017-06-21 12:41:00 +00:00
|
|
|
// read the first line
|
2020-01-06 14:39:20 +00:00
|
|
|
firstline = tempFile.GetFirstLine();
|
|
|
|
wxString secondline = tempFile.GetNextLine();
|
|
|
|
wxString thirdline = tempFile.GetNextLine();
|
2017-06-21 12:41:00 +00:00
|
|
|
tempFile.Close();
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
return firstline.StartsWith( "<?xml" ) && secondline.StartsWith( "<!DOCTYPE eagle SYSTEM" )
|
|
|
|
&& thirdline.StartsWith( "<eagle version" );
|
2017-06-21 12:41:00 +00:00
|
|
|
}
|
|
|
|
|
2017-07-16 16:12:05 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::moveLabels( SCH_LINE* aWire, const VECTOR2I& aNewEndPoint )
|
2017-10-03 10:23:52 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
static KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT };
|
|
|
|
SCH_SCREEN* screen = m_currentSheet->GetScreen();
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : screen->Items().Overlapping( aWire->GetBoundingBox() ) )
|
2017-08-14 14:45:57 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
if( !item->IsType( labelTypes ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( TestSegmentHit( item->GetPosition(), aWire->GetStartPoint(), aWire->GetEndPoint(), 0 ) )
|
|
|
|
item->SetPosition( aNewEndPoint );
|
2017-08-14 14:45:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2017-07-13 12:35:26 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::addBusEntries()
|
|
|
|
{
|
|
|
|
// Add bus entry symbols
|
2019-06-25 23:39:58 +00:00
|
|
|
// TODO: Cleanup this function and break into pieces
|
2017-07-13 12:35:26 +00:00
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
// for each wire segment, compare each end with all busses.
|
2017-08-13 16:48:52 +00:00
|
|
|
// If the wire end is found to end on a bus segment, place a bus entry symbol.
|
2017-07-13 12:35:26 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
std::vector<SCH_LINE*> buses;
|
|
|
|
std::vector<SCH_LINE*> wires;
|
|
|
|
|
2021-06-16 20:02:39 +00:00
|
|
|
for( SCH_ITEM* ii : m_currentSheet->GetScreen()->Items().OfType( SCH_LINE_T ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2021-06-17 17:16:38 +00:00
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( ii );
|
2017-07-13 12:35:26 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
if( line->IsBus() )
|
|
|
|
buses.push_back( line );
|
|
|
|
else if( line->IsWire() )
|
|
|
|
wires.push_back( line );
|
|
|
|
}
|
2021-06-15 22:21:53 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
for( SCH_LINE* wire : wires )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I wireStart = wire->GetStartPoint();
|
|
|
|
VECTOR2I wireEnd = wire->GetEndPoint();
|
2021-06-15 22:21:53 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
for( SCH_LINE* bus : buses )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I busStart = bus->GetStartPoint();
|
|
|
|
VECTOR2I busEnd = bus->GetEndPoint();
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
auto entrySize =
|
2022-01-01 06:04:08 +00:00
|
|
|
[]( int signX, int signY ) -> VECTOR2I
|
2021-06-17 17:16:38 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
return VECTOR2I( Mils2iu( DEFAULT_SCH_ENTRY_SIZE ) * signX,
|
2021-06-17 17:16:38 +00:00
|
|
|
Mils2iu( DEFAULT_SCH_ENTRY_SIZE ) * signY );
|
|
|
|
};
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
auto testBusHit =
|
2022-01-01 06:04:08 +00:00
|
|
|
[&]( const VECTOR2I& aPt ) -> bool
|
2021-06-17 17:16:38 +00:00
|
|
|
{
|
|
|
|
return TestSegmentHit( aPt, busStart, busEnd, 0 );
|
|
|
|
};
|
2021-06-16 20:02:39 +00:00
|
|
|
|
|
|
|
if( wireStart.y == wireEnd.y && busStart.x == busEnd.x )
|
|
|
|
{
|
2021-06-17 17:16:38 +00:00
|
|
|
// Horizontal wire and vertical bus
|
|
|
|
|
2021-06-16 20:02:39 +00:00
|
|
|
if( testBusHit( wireStart ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2021-06-16 20:02:39 +00:00
|
|
|
// Wire start is on the vertical bus
|
|
|
|
|
|
|
|
if( wireEnd.x < busStart.x )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* the end of the wire is to the left of the bus
|
|
|
|
* ⎥⎢
|
|
|
|
* ——————⎥⎢
|
|
|
|
* ⎥⎢
|
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireStart + entrySize( -1, 0 );
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2021-06-16 20:02:39 +00:00
|
|
|
if( testBusHit( wireStart + entrySize( 0, -1 ) ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* there is room above the wire for the bus entry
|
|
|
|
* ⎥⎢
|
|
|
|
* _____/⎥⎢
|
|
|
|
* ⎥⎢
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetStartPoint( p );
|
|
|
|
}
|
|
|
|
else if( testBusHit( wireStart + entrySize( 0, 1 ) ) )
|
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* there is room below the wire for the bus entry
|
|
|
|
* _____ ⎥⎢
|
|
|
|
* \⎥⎢
|
|
|
|
* ⎥⎢
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetStartPoint( p );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-16 20:02:39 +00:00
|
|
|
auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, wireStart );
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-16 20:02:39 +00:00
|
|
|
else
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* the wire end is to the right of the bus
|
|
|
|
* ⎥⎢
|
|
|
|
* ⎥⎢——————
|
|
|
|
* ⎥⎢
|
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireStart + entrySize( 1, 0 );
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2021-06-16 20:02:39 +00:00
|
|
|
if( testBusHit( wireStart + entrySize( 0, -1 ) ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* There is room above the wire for the bus entry
|
|
|
|
* ⎥⎢
|
|
|
|
* ⎥⎢\_____
|
|
|
|
* ⎥⎢
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p , 4 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetStartPoint( p );
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
2021-06-16 20:02:39 +00:00
|
|
|
else if( testBusHit( wireStart + entrySize( 0, 1 ) ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* There is room below the wire for the bus entry
|
|
|
|
* ⎥⎢ _____
|
|
|
|
* ⎥⎢/
|
|
|
|
* ⎥⎢
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetStartPoint( p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, wireStart );
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( testBusHit( wireEnd ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-16 20:02:39 +00:00
|
|
|
// Wire end is on the vertical bus
|
|
|
|
|
|
|
|
if( wireStart.x < busStart.x )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* start of the wire is to the left of the bus
|
|
|
|
* ⎥⎢
|
|
|
|
* ——————⎥⎢
|
|
|
|
* ⎥⎢
|
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireEnd + entrySize( -1, 0 );
|
2021-06-15 22:21:53 +00:00
|
|
|
|
2021-06-16 20:02:39 +00:00
|
|
|
if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* there is room above the wire for the bus entry
|
|
|
|
* ⎥⎢
|
|
|
|
* _____/⎥⎢
|
|
|
|
* ⎥⎢
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetEndPoint( p );
|
|
|
|
}
|
|
|
|
else if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
|
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* there is room below the wire for the bus entry
|
|
|
|
* _____ ⎥⎢
|
|
|
|
* \⎥⎢
|
|
|
|
* ⎥⎢
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( wire, wireEnd + entrySize( -1, 0 ) );
|
|
|
|
wire->SetEndPoint( wireEnd + entrySize( -1, 0 ) );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2021-06-15 22:21:53 +00:00
|
|
|
else
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2021-06-16 20:02:39 +00:00
|
|
|
auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, wireEnd );
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-16 20:02:39 +00:00
|
|
|
else
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* the start of the wire is to the right of the bus
|
|
|
|
* ⎥⎢
|
|
|
|
* ⎥⎢——————
|
|
|
|
* ⎥⎢
|
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireEnd + entrySize( 1, 0 );
|
2017-07-13 12:35:26 +00:00
|
|
|
|
2021-06-16 20:02:39 +00:00
|
|
|
if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* There is room above the wire for the bus entry
|
|
|
|
* ⎥⎢
|
|
|
|
* ⎥⎢\_____
|
|
|
|
* ⎥⎢
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetEndPoint( p );
|
|
|
|
}
|
|
|
|
else if( testBusHit( wireEnd + entrySize( 0, 1 ) ) )
|
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* There is room below the wire for the bus entry
|
|
|
|
* ⎥⎢ _____
|
|
|
|
* ⎥⎢/
|
|
|
|
* ⎥⎢
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetEndPoint( p );
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
2021-06-15 22:21:53 +00:00
|
|
|
else
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2021-06-16 20:02:39 +00:00
|
|
|
auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, wireEnd );
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( wireStart.x == wireEnd.x && busStart.y == busEnd.y )
|
2021-06-16 20:02:39 +00:00
|
|
|
{
|
2021-06-17 17:16:38 +00:00
|
|
|
// Vertical wire and horizontal bus
|
|
|
|
|
2021-06-16 20:02:39 +00:00
|
|
|
if( testBusHit( wireStart ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-16 20:02:39 +00:00
|
|
|
// Wire start is on the bus
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2021-06-16 20:02:39 +00:00
|
|
|
if( wireEnd.y < busStart.y )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* the end of the wire is above the bus
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* =======
|
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireStart + entrySize( 0, -1 );
|
2021-06-16 20:02:39 +00:00
|
|
|
|
|
|
|
if( testBusHit( wireStart + entrySize( -1, 0 ) ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-17 06:08:27 +00:00
|
|
|
/* there is room to the left of the wire for the bus entry
|
2021-06-18 11:01:16 +00:00
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* /
|
|
|
|
* =======
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetStartPoint( p );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2021-06-16 20:02:39 +00:00
|
|
|
else if( testBusHit( wireStart + entrySize( 1, 0 ) ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2021-06-17 06:08:27 +00:00
|
|
|
/* there is room to the right of the wire for the bus entry
|
2021-06-18 11:01:16 +00:00
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* \
|
|
|
|
* =======
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetStartPoint( p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, wireStart );
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* wire end is below the bus
|
|
|
|
* =======
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireStart + entrySize( 0, 1 );
|
2021-06-16 20:02:39 +00:00
|
|
|
|
|
|
|
if( testBusHit( wireStart + entrySize( -1, 0 ) ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-17 06:08:27 +00:00
|
|
|
/* there is room to the left of the wire for the bus entry
|
2021-06-18 11:01:16 +00:00
|
|
|
* =======
|
|
|
|
* \
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetStartPoint( p );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2021-06-16 20:02:39 +00:00
|
|
|
else if( testBusHit( wireStart + entrySize( 1, 0 ) ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-17 06:08:27 +00:00
|
|
|
/* there is room to the right of the wire for the bus entry
|
2021-06-18 11:01:16 +00:00
|
|
|
* =======
|
|
|
|
* /
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetStartPoint( p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, wireStart );
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-16 20:02:39 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( testBusHit( wireEnd ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-16 20:02:39 +00:00
|
|
|
// Wire end is on the bus
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2021-06-16 20:02:39 +00:00
|
|
|
if( wireStart.y < busStart.y )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* the start of the wire is above the bus
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* =======
|
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireEnd + entrySize( 0, -1 );
|
2021-06-16 20:02:39 +00:00
|
|
|
|
|
|
|
if( testBusHit( wireEnd + entrySize( -1, 0 ) ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-17 06:08:27 +00:00
|
|
|
/* there is room to the left of the wire for the bus entry
|
2021-06-18 11:01:16 +00:00
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* /
|
|
|
|
* =======
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetEndPoint( p );
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
2021-06-16 20:02:39 +00:00
|
|
|
else if( testBusHit( wireEnd + entrySize( 1, 0 ) ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2021-06-17 06:08:27 +00:00
|
|
|
/* there is room to the right of the wire for the bus entry
|
2021-06-18 11:01:16 +00:00
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* \
|
|
|
|
* =======
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetEndPoint( p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, wireEnd );
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* wire start is below the bus
|
|
|
|
* =======
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireEnd + entrySize( 0, 1 );
|
2021-06-16 20:02:39 +00:00
|
|
|
|
|
|
|
if( testBusHit( wireEnd + entrySize( -1, 0 ) ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-17 06:08:27 +00:00
|
|
|
/* there is room to the left of the wire for the bus entry
|
2021-06-18 11:01:16 +00:00
|
|
|
* =======
|
|
|
|
* \
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetEndPoint( p );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2021-06-16 20:02:39 +00:00
|
|
|
else if( testBusHit( wireEnd + entrySize( 1, 0 ) ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-18 11:01:16 +00:00
|
|
|
/* there is room to the right of the wire for the bus entry
|
|
|
|
* =======
|
|
|
|
* /
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
*/
|
2021-06-16 20:02:39 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetEndPoint( p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, wireEnd );
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-17 17:16:38 +00:00
|
|
|
|
|
|
|
break;
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-17 17:16:38 +00:00
|
|
|
else
|
2021-06-16 20:02:39 +00:00
|
|
|
{
|
2021-06-17 17:16:38 +00:00
|
|
|
// Wire isn't horizontal or vertical
|
2021-06-16 20:02:39 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
if( testBusHit( wireStart ) )
|
2021-06-16 20:02:39 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I wirevector = wireStart - wireEnd;
|
2021-06-16 20:02:39 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
if( wirevector.x > 0 )
|
2021-06-16 20:02:39 +00:00
|
|
|
{
|
2021-06-17 17:16:38 +00:00
|
|
|
if( wirevector.y > 0 )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireStart + entrySize( -1, -1 );
|
2021-06-17 17:16:38 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetStartPoint( p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireStart + entrySize( -1, 1 );
|
2021-06-17 17:16:38 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetStartPoint( p );
|
|
|
|
}
|
2021-06-16 20:02:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-17 17:16:38 +00:00
|
|
|
if( wirevector.y > 0 )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireStart + entrySize( 1, -1 );
|
2021-06-17 17:16:38 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetStartPoint( p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireStart + entrySize( 1, 1 );
|
2021-06-17 17:16:38 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetStartPoint( p );
|
|
|
|
}
|
2021-06-16 20:02:39 +00:00
|
|
|
}
|
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
break;
|
2021-06-16 20:02:39 +00:00
|
|
|
}
|
2021-06-17 17:16:38 +00:00
|
|
|
else if( testBusHit( wireEnd ) )
|
2021-06-16 20:02:39 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I wirevector = wireStart - wireEnd;
|
2021-06-17 17:16:38 +00:00
|
|
|
|
|
|
|
if( wirevector.x > 0 )
|
2021-06-16 20:02:39 +00:00
|
|
|
{
|
2021-06-17 17:16:38 +00:00
|
|
|
if( wirevector.y > 0 )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireEnd + entrySize( 1, 1 );
|
2021-06-17 17:16:38 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetEndPoint( p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireEnd + entrySize( 1, -1 );
|
2021-06-17 17:16:38 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
|
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetEndPoint( p );
|
|
|
|
}
|
2021-06-16 20:02:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-17 17:16:38 +00:00
|
|
|
if( wirevector.y > 0 )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireEnd + entrySize( -1, 1 );
|
2021-06-17 17:16:38 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2021-06-16 20:02:39 +00:00
|
|
|
|
2021-06-17 17:16:38 +00:00
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetEndPoint( p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p = wireEnd + entrySize( -1, -1 );
|
2021-06-17 17:16:38 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
|
|
|
|
moveLabels( wire, p );
|
|
|
|
wire->SetEndPoint( p );
|
|
|
|
}
|
2021-06-16 20:02:39 +00:00
|
|
|
}
|
2021-06-17 17:16:38 +00:00
|
|
|
|
|
|
|
break;
|
2021-06-16 20:02:39 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2021-06-16 20:02:39 +00:00
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
2018-03-28 14:03:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
const SEG* SCH_EAGLE_PLUGIN::SEG_DESC::LabelAttached( const SCH_TEXT* aLabel ) const
|
|
|
|
{
|
|
|
|
VECTOR2I labelPos( aLabel->GetPosition() );
|
|
|
|
|
2021-09-20 14:35:45 +00:00
|
|
|
for( const SEG& seg : segs )
|
2018-03-28 14:03:27 +00:00
|
|
|
{
|
|
|
|
if( seg.Contains( labelPos ) )
|
|
|
|
return &seg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-04-06 13:56:32 +00:00
|
|
|
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
// TODO could be used to place junctions, instead of IsJunctionNeeded()
|
|
|
|
// (see SCH_EDIT_FRAME::importFile())
|
2021-06-10 14:10:55 +00:00
|
|
|
bool SCH_EAGLE_PLUGIN::checkConnections( const SCH_SYMBOL* aSymbol, const LIB_PIN* aPin ) const
|
2018-04-12 16:10:22 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pinPosition = aSymbol->GetPinPhysicalPosition( aPin );
|
|
|
|
auto pointIt = m_connPoints.find( pinPosition );
|
2018-04-12 16:10:22 +00:00
|
|
|
|
|
|
|
if( pointIt == m_connPoints.end() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const auto& items = pointIt->second;
|
|
|
|
wxASSERT( items.find( aPin ) != items.end() );
|
|
|
|
return items.size() > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::addImplicitConnections( SCH_SYMBOL* aSymbol, SCH_SCREEN* aScreen,
|
|
|
|
bool aUpdateSet )
|
2018-04-06 13:56:32 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
wxCHECK( aSymbol->GetLibSymbolRef(), /*void*/ );
|
2018-04-06 13:56:32 +00:00
|
|
|
|
|
|
|
// Normally power parts also have power input pins,
|
|
|
|
// but they already force net names on the attached wires
|
2021-06-15 12:31:28 +00:00
|
|
|
if( aSymbol->GetLibSymbolRef()->IsPower() )
|
2018-04-06 13:56:32 +00:00
|
|
|
return;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
int unit = aSymbol->GetUnit();
|
|
|
|
const wxString reference = aSymbol->GetField( REFERENCE_FIELD )->GetText();
|
2018-04-06 13:56:32 +00:00
|
|
|
std::vector<LIB_PIN*> pins;
|
2021-06-15 12:31:28 +00:00
|
|
|
aSymbol->GetLibSymbolRef()->GetPins( pins );
|
2018-04-06 13:56:32 +00:00
|
|
|
std::set<int> missingUnits;
|
|
|
|
|
|
|
|
// Search all units for pins creating implicit connections
|
2021-09-20 14:35:45 +00:00
|
|
|
for( const LIB_PIN* pin : pins )
|
2018-04-06 13:56:32 +00:00
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
if( pin->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
|
2018-04-06 13:56:32 +00:00
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
bool pinInUnit = !unit || pin->GetUnit() == unit; // pin belongs to the tested unit
|
2018-04-12 16:10:22 +00:00
|
|
|
|
|
|
|
// Create a global net label only if there are no other wires/pins attached
|
2021-02-15 21:44:58 +00:00
|
|
|
if( pinInUnit )
|
2018-04-06 13:56:32 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
if( !checkConnections( aSymbol, pin ) )
|
2021-02-15 21:44:58 +00:00
|
|
|
{
|
|
|
|
// Create a net label to force the net name on the pin
|
|
|
|
SCH_GLOBALLABEL* netLabel = new SCH_GLOBALLABEL;
|
2021-06-10 14:10:55 +00:00
|
|
|
netLabel->SetPosition( aSymbol->GetPinPhysicalPosition( pin ) );
|
2021-02-15 21:44:58 +00:00
|
|
|
netLabel->SetText( extractNetName( pin->GetName() ) );
|
|
|
|
netLabel->SetTextSize( wxSize( Mils2iu( 40 ), Mils2iu( 40 ) ) );
|
2021-10-27 12:48:49 +00:00
|
|
|
|
|
|
|
switch( pin->GetOrientation() )
|
|
|
|
{
|
|
|
|
case PIN_LEFT: netLabel->SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT ); break;
|
|
|
|
case PIN_RIGHT: netLabel->SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT ); break;
|
|
|
|
case PIN_UP: netLabel->SetLabelSpinStyle( LABEL_SPIN_STYLE::UP ); break;
|
|
|
|
case PIN_DOWN: netLabel->SetLabelSpinStyle( LABEL_SPIN_STYLE::BOTTOM ); break;
|
|
|
|
}
|
|
|
|
|
2021-02-15 21:44:58 +00:00
|
|
|
aScreen->Append( netLabel );
|
|
|
|
}
|
2018-04-06 13:56:32 +00:00
|
|
|
}
|
2021-02-15 21:44:58 +00:00
|
|
|
else if( aUpdateSet )
|
2018-04-06 13:56:32 +00:00
|
|
|
{
|
|
|
|
// Found a pin creating implicit connection information in another unit.
|
|
|
|
// Such units will be instantiated if they do not appear in another sheet and
|
|
|
|
// processed later.
|
|
|
|
wxASSERT( pin->GetUnit() );
|
|
|
|
missingUnits.insert( pin->GetUnit() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( aUpdateSet && aSymbol->GetLibSymbolRef()->GetUnitCount() > 1 )
|
2018-04-06 13:56:32 +00:00
|
|
|
{
|
|
|
|
auto cmpIt = m_missingCmps.find( reference );
|
|
|
|
|
2021-02-15 21:44:58 +00:00
|
|
|
// The first unit found has always already been processed.
|
|
|
|
if( cmpIt == m_missingCmps.end() )
|
|
|
|
{
|
|
|
|
EAGLE_MISSING_CMP& entry = m_missingCmps[reference];
|
2021-06-10 14:10:55 +00:00
|
|
|
entry.cmp = aSymbol;
|
2021-02-15 21:44:58 +00:00
|
|
|
entry.units.emplace( unit, false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Set the flag indicating this unit has been processed.
|
2018-04-06 13:56:32 +00:00
|
|
|
cmpIt->second.units[unit] = false;
|
2021-02-15 21:44:58 +00:00
|
|
|
}
|
2018-04-06 13:56:32 +00:00
|
|
|
|
2021-02-15 21:44:58 +00:00
|
|
|
if( !missingUnits.empty() ) // Save the units that need later processing
|
2018-04-06 13:56:32 +00:00
|
|
|
{
|
|
|
|
EAGLE_MISSING_CMP& entry = m_missingCmps[reference];
|
2021-06-10 14:10:55 +00:00
|
|
|
entry.cmp = aSymbol;
|
2018-04-06 13:56:32 +00:00
|
|
|
|
2021-02-15 21:44:58 +00:00
|
|
|
// Add units that haven't already been processed.
|
2018-04-06 13:56:32 +00:00
|
|
|
for( int i : missingUnits )
|
2021-02-15 21:44:58 +00:00
|
|
|
{
|
|
|
|
if( entry.units.find( i ) != entry.units.end() )
|
|
|
|
entry.units.emplace( i, true );
|
|
|
|
}
|
2018-04-06 13:56:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-12 08:10:33 +00:00
|
|
|
|
|
|
|
|
2019-06-06 02:09:09 +00:00
|
|
|
wxString SCH_EAGLE_PLUGIN::translateEagleBusName( const wxString& aEagleName ) const
|
|
|
|
{
|
2020-07-06 10:51:04 +00:00
|
|
|
if( NET_SETTINGS::ParseBusVector( aEagleName, nullptr, nullptr ) )
|
2019-06-06 02:09:09 +00:00
|
|
|
return aEagleName;
|
|
|
|
|
|
|
|
wxString ret = "{";
|
|
|
|
|
|
|
|
wxStringTokenizer tokenizer( aEagleName, "," );
|
|
|
|
|
|
|
|
while( tokenizer.HasMoreTokens() )
|
|
|
|
{
|
|
|
|
wxString member = tokenizer.GetNextToken();
|
|
|
|
|
|
|
|
// In Eagle, overbar text is automatically stopped at the end of the net name, even when
|
|
|
|
// that net name is part of a bus definition. In KiCad, we don't (currently) do that, so
|
|
|
|
// if there is an odd number of overbar markers in this net name, we need to append one
|
|
|
|
// to close it out before appending the space.
|
|
|
|
|
|
|
|
if( member.Freq( '!' ) % 2 > 0 )
|
|
|
|
member << "!";
|
|
|
|
|
|
|
|
ret << member << " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.Trim( true );
|
|
|
|
ret << "}";
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|