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
|
2020-04-16 16:43:50 +00:00
|
|
|
* Copyright (C) 2017-2020 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
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <sch_eagle_plugin.h>
|
|
|
|
|
2017-07-03 14:02:55 +00:00
|
|
|
#include <kiway.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>
|
2017-02-27 10:07:52 +00:00
|
|
|
|
2017-05-08 15:11:14 +00:00
|
|
|
#include <class_libentry.h>
|
2020-01-06 14:39:20 +00:00
|
|
|
#include <class_library.h>
|
|
|
|
#include <eagle_parser.h>
|
|
|
|
#include <gr_text.h>
|
2017-07-25 13:51:07 +00:00
|
|
|
#include <lib_arc.h>
|
2017-05-08 15:11:14 +00:00
|
|
|
#include <lib_circle.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>
|
2020-01-06 14:39:20 +00:00
|
|
|
#include <lib_polyline.h>
|
|
|
|
#include <lib_rectangle.h>
|
2017-06-18 12:36:35 +00:00
|
|
|
#include <lib_text.h>
|
2020-04-24 23:44:09 +00:00
|
|
|
#include <macros.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>
|
2020-01-06 14:39:20 +00:00
|
|
|
#include <sch_component.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>
|
|
|
|
#include <sch_legacy_plugin.h>
|
|
|
|
#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 <template_fieldnames.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
#include <ws_draw_item.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
|
2017-10-03 10:23:52 +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
|
|
|
/**
|
|
|
|
* Provides an easy access to the children of an XML node via their names.
|
|
|
|
* @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
|
|
|
|
2018-04-06 11:23:24 +00:00
|
|
|
///> Computes a bounding box for all items in a schematic sheet
|
|
|
|
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
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto item : aSheet->GetScreen()->Items() )
|
2018-04-06 11:23:24 +00:00
|
|
|
bbox.Merge( item->GetBoundingBox() );
|
|
|
|
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-06 13:56:32 +00:00
|
|
|
///> Extracts the net name part from a pin name (e.g. return 'GND' for pin named 'GND@2')
|
|
|
|
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";
|
2018-06-21 04:12:11 +00:00
|
|
|
m_libName = LIB_ID::FixIllegalChars( m_libName, LIB_ID::ID_SCH, 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
|
|
|
|
for( const auto& elayer : eagleLayers )
|
2017-07-23 14:26:13 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Layers in Kicad schematics are not actually layers, but abstract groups mainly used to
|
|
|
|
* decide item colours.
|
|
|
|
*
|
|
|
|
* <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
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// Return the kicad component orientation based on eagle rotation degrees.
|
|
|
|
static COMPONENT_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:
|
|
|
|
return CMP_ORIENT_0;
|
|
|
|
|
|
|
|
case 90:
|
|
|
|
return CMP_ORIENT_90;
|
|
|
|
|
|
|
|
case 180:
|
|
|
|
return CMP_ORIENT_180;
|
|
|
|
|
|
|
|
case 270:
|
|
|
|
return CMP_ORIENT_270;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CMP_ORIENT_0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
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:
|
2017-07-23 14:28:23 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2017-07-16 16:12:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_LEFT:
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
2017-07-23 14:28:23 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2017-07-16 16:12:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_RIGHT:
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
2017-07-23 14:28:23 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
2017-07-16 16:12:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_CENTER:
|
2017-07-23 14:28:23 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
2017-07-16 16:12:05 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_LEFT:
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_RIGHT:
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_CENTER:
|
2017-07-23 14:28:23 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
2017-07-16 16:12:05 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_LEFT:
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_RIGHT:
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-07-23 14:28:23 +00:00
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
2017-07-16 16:12:05 +00:00
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
2020-01-10 23:14:37 +00:00
|
|
|
break;
|
2017-07-16 16:12:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-27 10:07:52 +00:00
|
|
|
SCH_EAGLE_PLUGIN::SCH_EAGLE_PLUGIN()
|
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
m_kiway = nullptr;
|
|
|
|
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;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-03-09 12:49:24 +00:00
|
|
|
// Load the document
|
|
|
|
wxXmlDocument xmlDocument;
|
2017-07-06 12:31:11 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
m_filename = aFileName;
|
|
|
|
m_schematic = aSchematic;
|
2017-02-27 10:07:52 +00:00
|
|
|
|
2017-07-02 12:26:23 +00:00
|
|
|
if( !xmlDocument.Load( m_filename.GetFullPath() ) )
|
2020-01-06 14:39:20 +00:00
|
|
|
THROW_IO_ERROR(
|
|
|
|
wxString::Format( _( "Unable to read file \"%s\"" ), 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
|
|
|
|
|
|
|
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 );
|
2017-03-09 12:49:24 +00:00
|
|
|
m_rootSheet->SetFileName( aFileName );
|
|
|
|
}
|
|
|
|
|
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 );
|
2017-05-08 15:11:14 +00:00
|
|
|
screen->SetFileName( aFileName );
|
|
|
|
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
|
|
|
|
2017-10-24 23:08:28 +00:00
|
|
|
wxCHECK_MSG( libTable, NULL, "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-01-06 14:39:20 +00:00
|
|
|
m_properties = std::make_unique<PROPERTIES>();
|
|
|
|
( *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
|
|
|
}
|
|
|
|
|
|
|
|
// Relaod the symbol library table.
|
2020-06-17 21:30:24 +00:00
|
|
|
m_schematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL );
|
|
|
|
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
|
|
|
|
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 );
|
|
|
|
// 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 );
|
|
|
|
// 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
|
2017-10-03 10:23:52 +00:00
|
|
|
NODE_MAP schematicChildren = MapChildren( aSchematicNode );
|
2020-01-06 14:39:20 +00:00
|
|
|
auto partNode = getChildrenNodes( schematicChildren, "parts" );
|
|
|
|
auto libraryNode = getChildrenNodes( schematicChildren, "libraries" );
|
|
|
|
auto sheetNode = getChildrenNodes( schematicChildren, "sheets" );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2018-08-09 17:53:48 +00:00
|
|
|
if( !partNode || !libraryNode || !sheetNode )
|
|
|
|
return;
|
2017-07-06 12:31:11 +00:00
|
|
|
|
2017-06-30 01:52:05 +00:00
|
|
|
while( partNode )
|
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
std::unique_ptr<EPART> epart( new 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
|
|
|
|
|
|
|
// Loop through all the libraries
|
|
|
|
while( libraryNode )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2017-08-23 04:13:37 +00:00
|
|
|
// Read the library name
|
|
|
|
wxString libName = libraryNode->GetAttribute( "name" );
|
|
|
|
|
2017-12-14 09:37:32 +00:00
|
|
|
EAGLE_LIBRARY* elib = &m_eagleLibs[libName];
|
2020-01-06 14:39:20 +00:00
|
|
|
elib->name = libName;
|
2017-08-23 04:13:37 +00:00
|
|
|
|
2017-12-14 09:37:32 +00:00
|
|
|
loadLibrary( libraryNode, &m_eagleLibs[libName] );
|
2017-08-23 04:13:37 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
libraryNode = libraryNode->GetNext();
|
|
|
|
}
|
2017-03-09 12:49:24 +00:00
|
|
|
|
2018-04-06 10:42:10 +00:00
|
|
|
m_pi->SaveLibrary( getLibFileName().GetFullPath() );
|
|
|
|
|
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 )
|
|
|
|
{
|
2020-01-22 17:26:27 +00:00
|
|
|
wxPoint pos = wxPoint( x * Mils2iu( 1000 ), y * Mils2iu( 1000 ) );
|
2020-05-13 02:00:37 +00:00
|
|
|
std::unique_ptr<SCH_SHEET> sheet( new 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
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
2018-04-06 13:56:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Handle the missing component units that need to be instantiated
|
|
|
|
// to create the missing implicit connections
|
|
|
|
|
|
|
|
// Calculate the already placed items bounding box and the page size to determine
|
|
|
|
// placement for the new components
|
2020-01-06 14:39:20 +00:00
|
|
|
wxSize pageSizeIU = m_rootSheet->GetScreen()->GetPageSettings().GetSizeIU();
|
|
|
|
EDA_RECT sheetBbox = getSheetBbox( m_rootSheet );
|
|
|
|
wxPoint newCmpPosition( sheetBbox.GetLeft(), sheetBbox.GetBottom() );
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
const SCH_COMPONENT* origCmp = cmp.second.cmp;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// Instantiate the missing component unit
|
2020-01-06 14:39:20 +00:00
|
|
|
int unit = unitEntry.first;
|
|
|
|
const wxString reference = origCmp->GetField( REFERENCE )->GetText();
|
2020-02-20 12:11:04 +00:00
|
|
|
std::unique_ptr<SCH_COMPONENT> component( (SCH_COMPONENT*) origCmp->Duplicate() );
|
2018-04-06 13:56:32 +00:00
|
|
|
component->SetUnitSelection( &sheetpath, unit );
|
|
|
|
component->SetUnit( unit );
|
|
|
|
component->SetOrientation( 0 );
|
|
|
|
component->AddHierarchicalReference( sheetpath.Path(), reference, unit );
|
|
|
|
|
|
|
|
// Calculate the placement position
|
|
|
|
EDA_RECT cmpBbox = component->GetBoundingBox();
|
2020-01-06 14:39:20 +00:00
|
|
|
int posY = newCmpPosition.y + cmpBbox.GetHeight();
|
2018-04-06 13:56:32 +00:00
|
|
|
component->SetPosition( wxPoint( newCmpPosition.x, posY ) );
|
|
|
|
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?
|
|
|
|
newCmpPosition = wxPoint( 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
|
|
|
|
addImplicitConnections( component.get(), m_rootSheet->GetScreen(), false );
|
|
|
|
m_rootSheet->GetScreen()->Append( component.release() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-08-12 09:18:18 +00:00
|
|
|
wxString fn = wxString( filename + ".sch" );
|
2020-03-13 09:53:44 +00:00
|
|
|
filenameField.SetText( fn );
|
|
|
|
wxFileName fileName( fn );
|
2017-08-12 09:18:18 +00:00
|
|
|
m_currentSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
|
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 )
|
|
|
|
{
|
|
|
|
// 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 )
|
|
|
|
{
|
|
|
|
// 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-05-08 14:10:23 +00:00
|
|
|
// Loop through all instances
|
2017-05-08 15:11:14 +00:00
|
|
|
wxXmlNode* instanceNode = getChildrenNodes( sheetChildren, "instances" );
|
2017-05-08 14:27:11 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
while( instanceNode )
|
|
|
|
{
|
|
|
|
loadInstance( instanceNode );
|
|
|
|
instanceNode = instanceNode->GetNext();
|
|
|
|
}
|
|
|
|
|
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 )
|
|
|
|
{
|
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 ) );
|
|
|
|
}
|
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 );
|
2020-01-06 14:39:20 +00:00
|
|
|
wxSize targetSheetSize = sheetBoundingBox.GetSize();
|
2020-01-05 19:11:15 +00:00
|
|
|
targetSheetSize.IncBy( 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();
|
|
|
|
wxPoint sheetcentre( pageSizeIU.x / 2, pageSizeIU.y / 2 );
|
2017-10-03 10:23:52 +00:00
|
|
|
wxPoint 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.
|
|
|
|
wxPoint 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
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto item : m_currentSheet->GetScreen()->Items().OfType( SCH_COMPONENT_T ) )
|
2020-01-06 14:39:20 +00:00
|
|
|
addImplicitConnections(
|
|
|
|
static_cast<SCH_COMPONENT*>( item ), 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 ) );
|
|
|
|
|
|
|
|
for( auto item : allItems )
|
2018-04-12 16:10:22 +00:00
|
|
|
{
|
|
|
|
item->SetPosition( item->GetPosition() + translation );
|
|
|
|
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
|
|
|
|
2020-01-06 14:39:20 +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
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
bool labelled = false; // has a label been added to this continously connected segment
|
|
|
|
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() );
|
|
|
|
|
|
|
|
for( auto& desc : m_segments )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
for( const auto& seg : desc.segs )
|
|
|
|
{
|
|
|
|
auto intersection = thisWire.Intersect( seg, true );
|
|
|
|
|
|
|
|
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
|
|
|
|
segmentAttribute->GetAttribute( "part" ); // REQUIRED
|
|
|
|
segmentAttribute->GetAttribute( "pin" ); // REQUIRED
|
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
|
|
|
{
|
2017-12-15 11:37:46 +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
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// Add a small label to the net segment if it hasn't been labelled already
|
|
|
|
// 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 ) );
|
2020-01-05 19:11:15 +00:00
|
|
|
label->SetTextSize( wxSize( Mils2iu( 10 ), Mils2iu( 10 ) ) );
|
2020-01-08 19:07:55 +00:00
|
|
|
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT );
|
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
|
|
|
{
|
2017-05-08 15:11:14 +00:00
|
|
|
std::unique_ptr<SCH_LINE> wire( new SCH_LINE );
|
|
|
|
|
|
|
|
auto 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
|
|
|
|
|
|
|
wxPoint begin, end;
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
std::unique_ptr<SCH_JUNCTION> junction( new SCH_JUNCTION );
|
2017-06-18 11:31:11 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
auto ejunction = EJUNCTION( aJunction );
|
2017-10-17 08:18:54 +00:00
|
|
|
wxPoint 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
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
auto elabel = ELABEL( aLabelNode, aNetName );
|
2017-10-17 08:18:54 +00:00
|
|
|
wxPoint 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
|
|
|
|
2018-03-22 15:19:38 +00:00
|
|
|
if( global )
|
|
|
|
label.reset( new SCH_GLOBALLABEL );
|
2018-02-18 10:54:37 +00:00
|
|
|
else
|
2018-03-22 15:19:38 +00:00
|
|
|
label.reset( new 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 ) );
|
|
|
|
label->SetTextSize( wxSize( elabel.size.ToSchUnits(), elabel.size.ToSchUnits() ) );
|
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 )
|
|
|
|
{
|
2020-03-29 01:12:29 +00:00
|
|
|
label->SetLabelSpinStyle( (LABEL_SPIN_STYLE::SPIN) ( KiROUND( elabel.rot->degrees / 90 ) % 4 ) );
|
2018-02-18 10:54:37 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
if( elabel.rot->mirror )
|
|
|
|
{
|
|
|
|
label->SetLabelSpinStyle( label->GetLabelSpinStyle().MirrorY() );
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
std::pair<VECTOR2I, const SEG*> SCH_EAGLE_PLUGIN::findNearestLinePoint(
|
|
|
|
const wxPoint& aPoint, 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
|
|
|
{
|
2018-03-28 14:03:27 +00:00
|
|
|
auto 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 )
|
|
|
|
{
|
2017-06-26 07:56:11 +00:00
|
|
|
auto einstance = EINSTANCE( aInstanceNode );
|
|
|
|
|
|
|
|
SCH_SCREEN* screen = m_currentSheet->GetScreen();
|
|
|
|
|
|
|
|
// Find the part in the list for the sheet.
|
|
|
|
// Assign the component its value from the part entry
|
|
|
|
// Calculate the unit number from the gate entry of the instance
|
2017-07-06 12:31:11 +00:00
|
|
|
// Assign the the LIB_ID from deviceset 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() )
|
|
|
|
{
|
|
|
|
wxLogError( _( "Error parsing Eagle file. "
|
|
|
|
"Could not find \"%s\" instance but it is referenced in the schematic." ),
|
|
|
|
einstance.part );
|
|
|
|
|
|
|
|
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( "*", "" );
|
2018-09-12 08:10:33 +00:00
|
|
|
wxString kisymbolname = fixSymbolName( symbolname );
|
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
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
LIB_PART* 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
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
wxLogMessage( wxString::Format( _( "Could not find %s in the imported library" ),
|
|
|
|
kisymbolname ) );
|
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
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
LIB_ID libId( getLibName(), kisymbolname );
|
2017-07-09 09:35:13 +00:00
|
|
|
std::unique_ptr<SCH_COMPONENT> component( new SCH_COMPONENT() );
|
2017-07-03 14:02:55 +00:00
|
|
|
component->SetLibId( libId );
|
|
|
|
component->SetUnit( unit );
|
2017-10-17 08:18:54 +00:00
|
|
|
component->SetPosition( wxPoint( einstance.x.ToSchUnits(), -einstance.y.ToSchUnits() ) );
|
2017-12-14 09:37:32 +00:00
|
|
|
component->GetField( FOOTPRINT )->SetText( package );
|
2017-07-03 14:02:55 +00:00
|
|
|
|
|
|
|
if( einstance.rot )
|
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
component->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 )
|
2017-10-17 08:18:54 +00:00
|
|
|
component->MirrorY( einstance.x.ToSchUnits() );
|
2017-06-30 01:52:05 +00:00
|
|
|
}
|
2017-07-03 14:02:55 +00:00
|
|
|
|
2017-07-09 09:35:13 +00:00
|
|
|
LIB_FIELDS partFields;
|
2017-10-03 10:23:52 +00:00
|
|
|
part->GetFields( partFields );
|
|
|
|
|
2017-07-09 09:35:13 +00:00
|
|
|
for( auto const& field : partFields )
|
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
component->GetField( field.GetId() )->ImportValues( field );
|
2020-01-06 14:39:20 +00:00
|
|
|
component->GetField( field.GetId() )
|
|
|
|
->SetTextPos( component->GetPosition() + 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 );
|
2020-02-22 21:39:59 +00:00
|
|
|
wxString current_sheetpath = sheetpath.PathAsString() + component->m_Uuid.AsString();
|
2017-07-23 14:28:23 +00:00
|
|
|
|
2018-04-03 07:57:56 +00:00
|
|
|
component->GetField( REFERENCE )->SetText( reference );
|
2018-03-22 17:17:23 +00:00
|
|
|
component->AddHierarchicalReference( current_sheetpath, reference, unit );
|
2017-07-23 14:28:23 +00:00
|
|
|
|
2017-07-14 15:20:59 +00:00
|
|
|
if( epart->value )
|
2017-12-14 09:37:32 +00:00
|
|
|
component->GetField( VALUE )->SetText( *epart->value );
|
2017-07-14 15:20:59 +00:00
|
|
|
else
|
2018-06-21 04:12:11 +00:00
|
|
|
component->GetField( VALUE )->SetText( kisymbolname );
|
2017-07-14 15:20:59 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// Set the visibility of fields.
|
2017-10-17 08:19:43 +00:00
|
|
|
component->GetField( REFERENCE )->SetVisible( part->GetField( REFERENCE )->IsVisible() );
|
|
|
|
component->GetField( VALUE )->SetVisible( part->GetField( VALUE )->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
|
|
|
{
|
|
|
|
auto field = component->AddField( *component->GetField( VALUE ) );
|
|
|
|
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
|
|
|
{
|
|
|
|
auto field = component->AddField( *component->GetField( VALUE ) );
|
|
|
|
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
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
auto attr = EATTR( attributeNode );
|
2018-07-10 14:32:10 +00:00
|
|
|
SCH_FIELD* field = NULL;
|
|
|
|
|
|
|
|
if( attr.name.Lower() == "name" )
|
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
field = component->GetField( REFERENCE );
|
2018-07-10 14:32:10 +00:00
|
|
|
nameAttributeFound = true;
|
|
|
|
}
|
|
|
|
else if( attr.name.Lower() == "value" )
|
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
field = component->GetField( VALUE );
|
2018-07-10 14:32:10 +00:00
|
|
|
valueAttributeFound = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
field = component->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
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
field->SetPosition( wxPoint( 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;
|
|
|
|
|
2020-01-06 14:39:20 +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
|
|
|
{
|
|
|
|
auto field = component->AddField( *component->GetField( VALUE ) );
|
|
|
|
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 )
|
|
|
|
component->GetField( VALUE )->SetVisible( false );
|
2017-08-19 07:35:21 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
if( !nameAttributeFound )
|
|
|
|
component->GetField( REFERENCE )->SetVisible( false );
|
|
|
|
}
|
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();
|
2020-04-16 16:43:50 +00:00
|
|
|
LIB_PART* libSymbol = schLibTable.LoadSymbol( component->GetLibId() );
|
|
|
|
|
|
|
|
wxCHECK( libSymbol, /*void*/ );
|
|
|
|
|
2020-05-05 22:06:43 +00:00
|
|
|
component->SetLibSymbol( new LIB_PART( *libSymbol ) );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
2018-04-12 16:10:22 +00:00
|
|
|
std::vector<LIB_PIN*> pins;
|
2020-08-21 15:54:24 +00:00
|
|
|
component->GetLibPins( pins );
|
2018-04-12 16:10:22 +00:00
|
|
|
|
|
|
|
for( const auto& pin : pins )
|
|
|
|
m_connPoints[component->GetPinPhysicalPosition( pin )].emplace( pin );
|
|
|
|
|
2017-07-02 12:26:23 +00:00
|
|
|
component->ClearFlags();
|
2017-06-26 07:56:11 +00:00
|
|
|
|
|
|
|
screen->Append( component.release() );
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-06 14:39:20 +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
|
|
|
|
2017-06-30 01:52:05 +00:00
|
|
|
// Loop through the devicesets 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
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
NODE_MAP aDeviceSetChildren = MapChildren( devicesetNode );
|
|
|
|
wxXmlNode* deviceNode = getChildrenNodes( aDeviceSetChildren, "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() );
|
2018-09-12 08:10:33 +00:00
|
|
|
symbolName = fixSymbolName( symbolName );
|
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.
|
2017-07-06 12:31:11 +00:00
|
|
|
unique_ptr<LIB_PART> kpart( new LIB_PART( 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.
|
2020-01-06 14:39:20 +00:00
|
|
|
wxXmlNode* gateNode = getChildrenNodes( aDeviceSetChildren, "gates" );
|
|
|
|
int gates_count = countChildren( aDeviceSetChildren["gates"], "gate" );
|
2017-07-06 12:31:11 +00:00
|
|
|
kpart->SetUnitCount( gates_count );
|
2018-05-08 10:17:46 +00:00
|
|
|
kpart->LockUnits( true );
|
2017-08-20 05:56:14 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
LIB_FIELD* reference = kpart->GetField( REFERENCE );
|
|
|
|
|
2017-10-17 08:19:43 +00:00
|
|
|
if( prefix.length() == 0 )
|
2017-08-20 05:56:14 +00:00
|
|
|
reference->SetVisible( false );
|
|
|
|
else
|
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 );
|
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 )
|
|
|
|
{
|
|
|
|
EGATE egate = EGATE( gateNode );
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
aEagleLibrary->GateUnit[edeviceset.name + edevice.name + egate.name] = gateindex;
|
2017-07-09 09:35:13 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
ispower = loadSymbol( aEagleLibrary->SymbolNodes[egate.symbol], kpart, &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
|
|
|
|
2017-07-06 12:31:11 +00:00
|
|
|
kpart->SetUnitCount( gates_count );
|
2017-10-03 10:23:52 +00:00
|
|
|
|
|
|
|
if( gates_count == 1 && ispower )
|
|
|
|
kpart->SetPower();
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2018-09-12 08:10:33 +00:00
|
|
|
wxString name = fixSymbolName( kpart->GetName() );
|
2017-10-24 23:08:28 +00:00
|
|
|
kpart->SetName( name );
|
|
|
|
m_pi->SaveSymbol( getLibFileName().GetFullPath(), new LIB_PART( *kpart.get() ),
|
2020-01-06 14:39:20 +00:00
|
|
|
m_properties.get() );
|
2017-10-03 10:23:52 +00:00
|
|
|
aEagleLibrary->KiCadSymbols.insert( name, kpart.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
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-14 09:37:32 +00:00
|
|
|
bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr<LIB_PART>& aPart,
|
|
|
|
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
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
aPart->AddDrawItem( loadSymbolCircle( aPart, 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 );
|
2017-10-03 10:23:52 +00:00
|
|
|
std::unique_ptr<LIB_PIN> pin( loadPin( aPart, 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
|
|
|
{
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& 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 );
|
|
|
|
}
|
|
|
|
|
2019-06-10 00:00:09 +00:00
|
|
|
// Eagle does not connect multiple NC pins together when they are stacked.
|
|
|
|
// KiCad will do this for pins that are coincident. We opt here for correct
|
|
|
|
// schematic netlist and leave out the multiple NC pins when stacked.
|
2020-01-06 14:39:20 +00:00
|
|
|
for( unsigned i = 0; i < pads.GetCount(); i++ )
|
2017-09-23 07:34:20 +00:00
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
if( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC && i > 0 )
|
2019-06-10 00:00:09 +00:00
|
|
|
break;
|
|
|
|
|
2017-09-23 07:34:20 +00:00
|
|
|
LIB_PIN* apin = new LIB_PIN( *pin );
|
|
|
|
|
|
|
|
wxString padname( pads[i] );
|
|
|
|
apin->SetNumber( padname );
|
2017-10-17 08:19:43 +00:00
|
|
|
aPart->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 ) );
|
2017-08-06 14:20:29 +00:00
|
|
|
aPart->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
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
aPart->AddDrawItem( loadSymbolPolyLine( aPart, 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
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
aPart->AddDrawItem( loadSymbolRectangle( aPart, 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
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
std::unique_ptr<LIB_TEXT> libtext( loadSymbolText( aPart, 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
|
|
|
{
|
2017-10-18 08:33:51 +00:00
|
|
|
LIB_FIELD* field = aPart->GetField( REFERENCE );
|
|
|
|
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
|
|
|
{
|
|
|
|
LIB_FIELD* field = aPart->GetField( VALUE );
|
|
|
|
loadFieldAttributes( field, libtext.get() );
|
|
|
|
foundValue = true;
|
2017-07-02 12:26:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-06 14:20:29 +00:00
|
|
|
aPart->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
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
aPart->AddDrawItem( loadSymbolWire( aPart, currentNode, aGateNumber ) );
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
/*
|
|
|
|
* else if( nodeName == "description" )
|
|
|
|
* {
|
|
|
|
* }
|
|
|
|
* else if( nodeName == "dimension" )
|
|
|
|
* {
|
|
|
|
* }
|
|
|
|
* else if( nodeName == "frame" )
|
|
|
|
* {
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
|
2017-03-09 12:49:24 +00:00
|
|
|
currentNode = currentNode->GetNext();
|
|
|
|
}
|
2017-07-16 16:15:04 +00:00
|
|
|
|
|
|
|
if( foundName == false )
|
2017-10-03 10:23:52 +00:00
|
|
|
aPart->GetField( REFERENCE )->SetVisible( false );
|
|
|
|
|
2017-07-16 16:15:04 +00:00
|
|
|
if( foundValue == false )
|
2017-10-03 10:23:52 +00:00
|
|
|
aPart->GetField( VALUE )->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
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
LIB_CIRCLE* SCH_EAGLE_PLUGIN::loadSymbolCircle(
|
|
|
|
std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aCircleNode, int aGateNumber )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2017-05-08 15:11:14 +00:00
|
|
|
// Parse the circle properties
|
|
|
|
ECIRCLE c( aCircleNode );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2017-08-06 14:20:29 +00:00
|
|
|
unique_ptr<LIB_CIRCLE> circle( new LIB_CIRCLE( aPart.get() ) );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
circle->SetPosition( wxPoint( c.x.ToSchUnits(), c.y.ToSchUnits() ) );
|
|
|
|
circle->SetRadius( c.radius.ToSchUnits() );
|
|
|
|
circle->SetWidth( c.width.ToSchUnits() );
|
2017-10-03 10:23:52 +00:00
|
|
|
circle->SetUnit( aGateNumber );
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2017-05-08 15:11:14 +00:00
|
|
|
return circle.release();
|
|
|
|
}
|
2017-03-09 12:49:24 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
LIB_RECTANGLE* SCH_EAGLE_PLUGIN::loadSymbolRectangle(
|
|
|
|
std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aRectNode, int aGateNumber )
|
2017-05-08 15:11:14 +00:00
|
|
|
{
|
|
|
|
ERECT rect( aRectNode );
|
|
|
|
|
2017-08-06 14:20:29 +00:00
|
|
|
unique_ptr<LIB_RECTANGLE> rectangle( new LIB_RECTANGLE( aPart.get() ) );
|
2017-05-08 15:11:14 +00:00
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
rectangle->SetPosition( wxPoint( rect.x1.ToSchUnits(), rect.y1.ToSchUnits() ) );
|
|
|
|
rectangle->SetEnd( wxPoint( rect.x2.ToSchUnits(), rect.y2.ToSchUnits() ) );
|
2017-05-08 15:11:14 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
rectangle->SetUnit( aGateNumber );
|
2017-07-23 14:27:42 +00:00
|
|
|
// Eagle rectangles are filled by definition.
|
2017-10-03 10:23:52 +00:00
|
|
|
rectangle->SetFillMode( FILLED_SHAPE );
|
2017-05-08 15:11:14 +00:00
|
|
|
|
|
|
|
return rectangle.release();
|
|
|
|
}
|
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
LIB_ITEM* SCH_EAGLE_PLUGIN::loadSymbolWire(
|
|
|
|
std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aWireNode, int aGateNumber )
|
2017-06-18 11:31:11 +00:00
|
|
|
{
|
2017-07-06 12:31:11 +00:00
|
|
|
auto ewire = EWIRE( aWireNode );
|
2017-07-25 13:51:07 +00:00
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
wxPoint 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 )
|
|
|
|
{
|
2017-08-06 14:20:29 +00:00
|
|
|
std::unique_ptr<LIB_ARC> arc( new LIB_ARC( aPart.get() ) );
|
2020-01-06 14:39:20 +00:00
|
|
|
wxPoint center = ConvertArcCenter( begin, end, *ewire.curve * -1 );
|
2017-07-25 13:51:07 +00:00
|
|
|
|
2017-08-07 09:25:15 +00:00
|
|
|
double 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
|
|
|
|
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
|
|
|
{
|
2017-10-17 08:18:54 +00:00
|
|
|
wxPoint centerStartVector = begin - center;
|
2020-01-06 14:39:20 +00:00
|
|
|
wxPoint 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
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
arc->SetWidth( 1 );
|
|
|
|
arc->SetFillMode( FILLED_SHAPE );
|
2017-07-25 13:51:07 +00:00
|
|
|
}
|
2017-10-17 08:18:54 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
arc->SetWidth( ewire.width.ToSchUnits() );
|
|
|
|
}
|
2017-07-25 13:51:07 +00:00
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
arc->SetPosition( center );
|
|
|
|
|
|
|
|
if( *ewire.curve > 0 )
|
|
|
|
{
|
|
|
|
arc->SetStart( begin );
|
|
|
|
arc->SetEnd( end );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
arc->SetStart( end );
|
|
|
|
arc->SetEnd( begin );
|
|
|
|
}
|
2017-07-25 13:51:07 +00:00
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
arc->SetRadius( radius );
|
|
|
|
arc->CalcRadiusAngles();
|
2017-10-03 10:23:52 +00:00
|
|
|
arc->SetUnit( aGateNumber );
|
|
|
|
|
|
|
|
return (LIB_ITEM*) arc.release();
|
2017-07-25 13:51:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-06 14:20:29 +00:00
|
|
|
std::unique_ptr<LIB_POLYLINE> polyLine( new LIB_POLYLINE( aPart.get() ) );
|
2017-07-25 13:51:07 +00:00
|
|
|
|
|
|
|
polyLine->AddPoint( begin );
|
|
|
|
polyLine->AddPoint( end );
|
2017-10-03 10:23:52 +00:00
|
|
|
polyLine->SetUnit( aGateNumber );
|
2020-02-22 18:44:30 +00:00
|
|
|
polyLine->SetWidth( ewire.width.ToSchUnits() );
|
2017-10-17 08:18:54 +00:00
|
|
|
|
2017-07-25 13:51:07 +00:00
|
|
|
return (LIB_ITEM*) polyLine.release();
|
|
|
|
}
|
2017-06-18 11:31:11 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
LIB_POLYLINE* SCH_EAGLE_PLUGIN::loadSymbolPolyLine(
|
|
|
|
std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aPolygonNode, int aGateNumber )
|
2017-05-08 15:11:14 +00:00
|
|
|
{
|
2017-08-06 14:20:29 +00:00
|
|
|
std::unique_ptr<LIB_POLYLINE> polyLine( new LIB_POLYLINE( aPart.get() ) );
|
2017-05-08 15:11:14 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
EPOLYGON epoly( aPolygonNode );
|
2017-07-17 12:47:49 +00:00
|
|
|
wxXmlNode* vertex = aPolygonNode->GetChildren();
|
2017-05-08 15:11:14 +00:00
|
|
|
|
2017-07-17 12:47:49 +00:00
|
|
|
|
|
|
|
wxPoint 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 );
|
2017-10-17 08:18:54 +00:00
|
|
|
pt = wxPoint( evertex.x.ToSchUnits(), evertex.y.ToSchUnits() );
|
2017-07-17 12:47:49 +00:00
|
|
|
polyLine->AddPoint( pt );
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2017-07-17 12:47:49 +00:00
|
|
|
polyLine->SetFillMode( FILLED_SHAPE );
|
2017-10-03 10:23:52 +00:00
|
|
|
polyLine->SetUnit( aGateNumber );
|
2017-07-17 12:47:49 +00:00
|
|
|
|
2017-05-08 15:11:14 +00:00
|
|
|
return polyLine.release();
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
2017-02-27 10:07:52 +00:00
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
LIB_PIN* SCH_EAGLE_PLUGIN::loadPin(
|
|
|
|
std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aPin, EPIN* aEPin, int aGateNumber )
|
2017-06-18 11:31:11 +00:00
|
|
|
{
|
2017-08-06 14:20:29 +00:00
|
|
|
std::unique_ptr<LIB_PIN> pin( new LIB_PIN( aPart.get() ) );
|
2017-10-17 08:18:54 +00:00
|
|
|
pin->SetPosition( wxPoint( 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 )
|
|
|
|
{
|
2017-07-03 14:01:39 +00:00
|
|
|
default:
|
|
|
|
wxASSERT_MSG( false, wxString::Format( "Unhandled orientation (%d degrees)", roti ) );
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
2017-07-06 12:31:11 +00:00
|
|
|
|
2017-06-18 12:25:36 +00:00
|
|
|
case 0:
|
|
|
|
pin->SetOrientation( 'R' );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 90:
|
2017-06-30 01:52:05 +00:00
|
|
|
pin->SetOrientation( 'U' );
|
2017-06-18 12:25:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 180:
|
|
|
|
pin->SetOrientation( 'L' );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 270:
|
2017-06-30 01:52:05 +00:00
|
|
|
pin->SetOrientation( 'D' );
|
2017-06-18 12:25:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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" )
|
2017-06-19 12:44:31 +00:00
|
|
|
{
|
2020-01-05 19:11:15 +00:00
|
|
|
pin->SetLength( Mils2iu( 100 ) );
|
2017-06-19 12:44:31 +00:00
|
|
|
}
|
2020-01-06 14:39:20 +00:00
|
|
|
else if( length == "middle" )
|
2017-06-19 12:44:31 +00:00
|
|
|
{
|
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-19 12:44:31 +00:00
|
|
|
}
|
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" )
|
2017-08-19 05:41:48 +00:00
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::INVERTED );
|
2017-08-19 05:41:48 +00:00
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
else if( function == "clk" )
|
2017-08-19 05:41:48 +00:00
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::CLOCK );
|
2017-08-19 05:41:48 +00:00
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
else if( function == "dotclk" )
|
2017-08-19 05:41:48 +00:00
|
|
|
{
|
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
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymbolText(
|
|
|
|
std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aLibText, int aGateNumber )
|
2017-06-18 12:36:35 +00:00
|
|
|
{
|
2017-08-06 14:20:29 +00:00
|
|
|
std::unique_ptr<LIB_TEXT> libtext( new LIB_TEXT( aPart.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 );
|
2017-10-17 08:18:54 +00:00
|
|
|
libtext->SetPosition( wxPoint( 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', '_' );
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
SCH_TEXT* SCH_EAGLE_PLUGIN::loadPlainText( wxXmlNode* aSchText )
|
2017-07-05 15:05:03 +00:00
|
|
|
{
|
|
|
|
std::unique_ptr<SCH_TEXT> schtext( new SCH_TEXT() );
|
2020-01-06 14:39:20 +00:00
|
|
|
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();
|
|
|
|
schtext->SetText( thetext.IsEmpty() ? "\" \"" : escapeName( thetext ) );
|
2017-10-17 08:18:54 +00:00
|
|
|
schtext->SetPosition( wxPoint( 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() );
|
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
auto onIntersection = [&]( const VECTOR2I& aPos ) {
|
2018-03-28 14:03:27 +00:00
|
|
|
return std::binary_search( m_wireIntersections.begin(), m_wireIntersections.end(), aPos );
|
|
|
|
};
|
|
|
|
|
|
|
|
for( auto& segDesc : m_segments )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
2020-01-06 14:39:20 +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 )
|
|
|
|
{
|
|
|
|
labelPos = wxPoint( origPos + wireDirection * trial / 2 );
|
|
|
|
move = checkPositive = segAttached->Contains( labelPos );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
labelPos = wxPoint( origPos - wireDirection * trial / 2 );
|
|
|
|
move = checkNegative = segAttached->Contains( labelPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
++trial;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( move )
|
|
|
|
label->SetPosition( wxPoint( labelPos ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
// 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
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::moveLabels( SCH_ITEM* aWire, const wxPoint& aNewEndPoint )
|
2017-10-03 10:23:52 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto item : m_currentSheet->GetScreen()->Items().Overlapping( aWire->GetBoundingBox() ) )
|
2017-08-14 14:45:57 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == SCH_LABEL_T || item->Type() == SCH_GLOBAL_LABEL_T )
|
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
if( TestSegmentHit( item->GetPosition(), ( (SCH_LINE*) aWire )->GetStartPoint(),
|
|
|
|
( (SCH_LINE*) aWire )->GetEndPoint(), 0 ) )
|
2017-08-14 14:45:57 +00:00
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
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
|
|
|
|
|
|
|
// for each wire segment, compare each end with all busess.
|
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
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto it1 = m_currentSheet->GetScreen()->Items().OfType( SCH_LINE_T ).begin();
|
|
|
|
it1 != m_currentSheet->GetScreen()->Items().end(); ++it1 )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_LINE* bus = static_cast<SCH_LINE*>( *it1 );
|
2017-07-13 12:35:26 +00:00
|
|
|
|
2017-08-13 16:48:52 +00:00
|
|
|
// Check line type for wire
|
2019-06-25 23:39:58 +00:00
|
|
|
if( bus->GetLayer() != LAYER_BUS )
|
2017-07-13 12:35:26 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
wxPoint busstart = bus->GetStartPoint();
|
|
|
|
wxPoint busend = bus->GetEndPoint();
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
auto it2 = it1;
|
|
|
|
++it2;
|
|
|
|
for( ; it2 != m_currentSheet->GetScreen()->Items().end(); ++it2 )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( *it2 );
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
// Check line type for bus
|
|
|
|
if( ( (SCH_LINE*) *it2 )->GetLayer() == LAYER_WIRE )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
// Get points of both segments.
|
|
|
|
wxPoint linestart = line->GetStartPoint();
|
|
|
|
wxPoint lineend = line->GetEndPoint();
|
|
|
|
|
|
|
|
// Test for horizontal wire and vertical bus
|
|
|
|
if( linestart.y == lineend.y && busstart.x == busend.x )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
if( TestSegmentHit( linestart, busstart, busend, 0 ) )
|
|
|
|
{
|
|
|
|
// Wire start is on a bus.
|
|
|
|
// Wire start is on the vertical bus
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
// if the end of the wire is to the left of the bus
|
|
|
|
if( lineend.x < busstart.x )
|
|
|
|
{
|
|
|
|
// |
|
|
|
|
// ---|
|
|
|
|
// |
|
|
|
|
if( TestSegmentHit(
|
|
|
|
linestart + wxPoint( 0, -100 ), busstart, busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
|
2020-06-30 01:08:33 +00:00
|
|
|
linestart + wxPoint( -100, 0 ), true );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, linestart + wxPoint( -100, 0 ) );
|
|
|
|
line->SetStartPoint( linestart + wxPoint( -100, 0 ) );
|
|
|
|
}
|
|
|
|
else if( TestSegmentHit(
|
|
|
|
linestart + wxPoint( 0, 100 ), busstart, busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
|
2020-06-30 01:08:33 +00:00
|
|
|
linestart + wxPoint( -100, 0 ), false );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, linestart + wxPoint( -100, 0 ) );
|
|
|
|
line->SetStartPoint( linestart + wxPoint( -100, 0 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// else the wire end is to the right of the bus
|
|
|
|
// Wire is to the right of the bus
|
|
|
|
// |
|
|
|
|
// |----
|
|
|
|
// |
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// test is bus exists above the wire
|
|
|
|
if( TestSegmentHit(
|
|
|
|
linestart + wxPoint( 0, -100 ), busstart, busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
|
2020-06-30 01:08:33 +00:00
|
|
|
linestart + wxPoint( 0, -100 ), false );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, linestart + wxPoint( 100, 0 ) );
|
|
|
|
line->SetStartPoint( linestart + wxPoint( 100, 0 ) );
|
|
|
|
}
|
|
|
|
// test is bus exists below the wire
|
|
|
|
else if( TestSegmentHit(
|
|
|
|
linestart + wxPoint( 0, 100 ), busstart, busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
|
2020-06-30 01:08:33 +00:00
|
|
|
linestart + wxPoint( 0, 100 ), true );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, linestart + wxPoint( 100, 0 ) );
|
|
|
|
line->SetStartPoint( linestart + wxPoint( 100, 0 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
// Same thing but test end of the wire instead.
|
|
|
|
if( TestSegmentHit( lineend, busstart, busend, 0 ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
// Wire end is on the vertical bus
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
// if the start of the wire is to the left of the bus
|
|
|
|
if( linestart.x < busstart.x )
|
|
|
|
{
|
|
|
|
// Test if bus exists above the wire
|
|
|
|
if( TestSegmentHit( lineend + wxPoint( 0, 100 ), busstart, busend, 0 ) )
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
|
|
|
// |
|
2019-06-25 23:39:58 +00:00
|
|
|
// ___/|
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
|
2020-06-30 01:08:33 +00:00
|
|
|
lineend + wxPoint( -100, 0 ), false );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, lineend + wxPoint( -100, 0 ) );
|
|
|
|
line->SetEndPoint( lineend + wxPoint( -100, 0 ) );
|
|
|
|
}
|
|
|
|
// Test if bus exists below the wire
|
|
|
|
else if( TestSegmentHit(
|
|
|
|
lineend + wxPoint( 0, -100 ), busstart, busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry =
|
2020-06-30 01:08:33 +00:00
|
|
|
new SCH_BUS_WIRE_ENTRY( lineend + wxPoint( -100, 0 ), true );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, lineend + wxPoint( -100, 0 ) );
|
|
|
|
line->SetEndPoint( lineend + wxPoint( -100, 0 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
// else the start of the wire is to the right of the bus
|
|
|
|
// |
|
|
|
|
// |----
|
|
|
|
// |
|
|
|
|
else
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
// test if bus existed above the wire
|
|
|
|
if( TestSegmentHit(
|
|
|
|
lineend + wxPoint( 0, -100 ), busstart, busend, 0 ) )
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
|
2020-06-30 01:08:33 +00:00
|
|
|
lineend + wxPoint( 0, -100 ), false );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, lineend + wxPoint( 100, 0 ) );
|
|
|
|
line->SetEndPoint( lineend + wxPoint( 100, 0 ) );
|
|
|
|
}
|
|
|
|
// test if bus existed below the wire
|
|
|
|
else if( TestSegmentHit(
|
|
|
|
lineend + wxPoint( 0, 100 ), busstart, busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry =
|
2020-06-30 01:08:33 +00:00
|
|
|
new SCH_BUS_WIRE_ENTRY( lineend + wxPoint( 0, 100 ), true );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, lineend + wxPoint( 100, 0 ) );
|
|
|
|
line->SetEndPoint( lineend + wxPoint( 100, 0 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
} // if( linestart.y == lineend.y && busstart.x == busend.x)
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
// Test for horizontal wire and vertical bus
|
|
|
|
if( linestart.x == lineend.x && busstart.y == busend.y )
|
|
|
|
{
|
|
|
|
if( TestSegmentHit( linestart, busstart, busend, 0 ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
// Wire start is on the bus
|
|
|
|
// If wire end is above the bus,
|
|
|
|
if( lineend.y < busstart.y )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
// Test for bus existance to the left of the wire
|
|
|
|
if( TestSegmentHit(
|
|
|
|
linestart + wxPoint( -100, 0 ), busstart, busend, 0 ) )
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
|
2020-06-30 01:08:33 +00:00
|
|
|
linestart + wxPoint( -100, 0 ), true );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, linestart + wxPoint( 0, -100 ) );
|
|
|
|
line->SetStartPoint( linestart + wxPoint( 0, -100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
else if( TestSegmentHit(
|
|
|
|
linestart + wxPoint( 100, 0 ), busstart, busend, 0 ) )
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
|
2020-06-30 01:08:33 +00:00
|
|
|
linestart + wxPoint( 0, 100 ), false );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, linestart + wxPoint( 0, -100 ) );
|
|
|
|
line->SetStartPoint( linestart + wxPoint( 0, -100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
else
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // wire end is below the bus.
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
// Test for bus existance to the left of the wire
|
|
|
|
if( TestSegmentHit(
|
|
|
|
linestart + wxPoint( -100, 0 ), busstart, busend, 0 ) )
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
|
2020-06-30 01:08:33 +00:00
|
|
|
linestart + wxPoint( -100, 0 ), false );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, linestart + wxPoint( 0, 100 ) );
|
|
|
|
line->SetStartPoint( linestart + wxPoint( 0, 100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
else if( TestSegmentHit(
|
|
|
|
linestart + wxPoint( 100, 0 ), busstart, busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
|
2020-06-30 01:08:33 +00:00
|
|
|
linestart + wxPoint( 100, 0 ), true );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, linestart + wxPoint( 0, 100 ) );
|
|
|
|
line->SetStartPoint( linestart + wxPoint( 0, 100 ) );
|
|
|
|
}
|
|
|
|
else
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
if( TestSegmentHit( lineend, busstart, busend, 0 ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
// Wire end is on the bus
|
|
|
|
// If wire start is above the bus,
|
2017-07-13 12:35:26 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
if( linestart.y < busstart.y )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
// Test for bus existance to the left of the wire
|
|
|
|
if( TestSegmentHit(
|
|
|
|
lineend + wxPoint( -100, 0 ), busstart, busend, 0 ) )
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry =
|
2020-06-30 01:08:33 +00:00
|
|
|
new SCH_BUS_WIRE_ENTRY( lineend + wxPoint( -100, 0 ), true );
|
2017-08-13 16:48:52 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2019-06-25 23:39:58 +00:00
|
|
|
moveLabels( line, lineend + wxPoint( 0, -100 ) );
|
|
|
|
line->SetEndPoint( lineend + wxPoint( 0, -100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
else if( TestSegmentHit(
|
|
|
|
lineend + wxPoint( 100, 0 ), busstart, busend, 0 ) )
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
|
2020-06-30 01:08:33 +00:00
|
|
|
lineend + wxPoint( 0, -100 ), false );
|
2017-08-13 16:48:52 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2019-06-25 23:39:58 +00:00
|
|
|
moveLabels( line, lineend + wxPoint( 0, -100 ) );
|
|
|
|
line->SetEndPoint( lineend + wxPoint( 0, -100 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
else // wire end is below the bus.
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
// Test for bus existance to the left of the wire
|
|
|
|
if( TestSegmentHit(
|
|
|
|
lineend + wxPoint( -100, 0 ), busstart, busend, 0 ) )
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
|
2020-06-30 01:08:33 +00:00
|
|
|
lineend + wxPoint( -100, 0 ), false );
|
2017-08-13 16:48:52 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2019-06-25 23:39:58 +00:00
|
|
|
moveLabels( line, lineend + wxPoint( 0, 100 ) );
|
|
|
|
line->SetEndPoint( lineend + wxPoint( 0, 100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
else if( TestSegmentHit(
|
|
|
|
lineend + wxPoint( 100, 0 ), busstart, busend, 0 ) )
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
2020-01-06 14:39:20 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry =
|
2020-06-30 01:08:33 +00:00
|
|
|
new SCH_BUS_WIRE_ENTRY( lineend + wxPoint( 0, 100 ), true );
|
2017-08-13 16:48:52 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2019-06-25 23:39:58 +00:00
|
|
|
moveLabels( line, lineend + wxPoint( 0, 100 ) );
|
|
|
|
line->SetEndPoint( lineend + wxPoint( 0, 100 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
linestart = line->GetStartPoint();
|
|
|
|
lineend = line->GetEndPoint();
|
|
|
|
busstart = bus->GetStartPoint();
|
|
|
|
busend = bus->GetEndPoint();
|
|
|
|
|
|
|
|
// bus entry wire isn't horizontal or vertical
|
|
|
|
if( TestSegmentHit( linestart, busstart, busend, 0 ) )
|
|
|
|
{
|
|
|
|
wxPoint wirevector = linestart - lineend;
|
|
|
|
|
|
|
|
if( wirevector.x > 0 )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
if( wirevector.y > 0 )
|
|
|
|
{
|
|
|
|
wxPoint p = linestart + wxPoint( -100, -100 );
|
2020-06-30 01:08:33 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, false );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, p );
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
if( p == lineend ) // wire is overlapped by bus entry symbol
|
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
|
|
|
line = nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line->SetStartPoint( p );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
wxPoint p = linestart + wxPoint( -100, 100 );
|
2020-06-30 01:08:33 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, true );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
|
|
|
|
moveLabels( line, p );
|
|
|
|
|
|
|
|
if( p == lineend ) // wire is overlapped by bus entry symbol
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
|
|
|
line = nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line->SetStartPoint( p );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( wirevector.y > 0 )
|
|
|
|
{
|
2020-06-30 01:08:33 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart, true );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
moveLabels( line, linestart + wxPoint( 100, -100 ) );
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
if( linestart + wxPoint( 100, -100 )
|
|
|
|
== lineend ) // wire is overlapped by bus entry symbol
|
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
|
|
|
line = nullptr;
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
line->SetStartPoint( linestart + wxPoint( 100, -100 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry =
|
2020-06-30 01:08:33 +00:00
|
|
|
new SCH_BUS_WIRE_ENTRY( linestart, false );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, linestart + wxPoint( 100, 100 ) );
|
|
|
|
|
|
|
|
if( linestart + wxPoint( 100, 100 )
|
|
|
|
== lineend ) // wire is overlapped by bus entry symbol
|
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
|
|
|
line = nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line->SetStartPoint( linestart + wxPoint( 100, 100 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
if( line && TestSegmentHit( lineend, busstart, busend, 0 ) )
|
|
|
|
{
|
|
|
|
wxPoint wirevector = linestart - lineend;
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
if( wirevector.x > 0 )
|
|
|
|
{
|
|
|
|
if( wirevector.y > 0 )
|
|
|
|
{
|
|
|
|
wxPoint p = lineend + wxPoint( 100, 100 );
|
2020-06-30 01:08:33 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend, false );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
|
|
|
|
moveLabels( line, p );
|
|
|
|
|
|
|
|
if( p == linestart ) // wire is overlapped by bus entry symbol
|
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line->SetEndPoint( p );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
2017-08-13 16:48:52 +00:00
|
|
|
else
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
wxPoint p = lineend + wxPoint( 100, -100 );
|
2020-06-30 01:08:33 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend, true );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
|
|
|
|
moveLabels( line, p );
|
|
|
|
|
|
|
|
if( p == linestart ) // wire is overlapped by bus entry symbol
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
line->SetEndPoint( p );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( wirevector.y > 0 )
|
|
|
|
{
|
|
|
|
wxPoint p = lineend + wxPoint( -100, 100 );
|
2020-06-30 01:08:33 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, true );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, p );
|
|
|
|
|
|
|
|
if( p == linestart ) // wire is overlapped by bus entry symbol
|
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line->SetEndPoint( p );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxPoint p = lineend + wxPoint( -100, -100 );
|
2020-06-30 01:08:33 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, false );
|
2019-06-25 23:39:58 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
moveLabels( line, p );
|
|
|
|
|
|
|
|
if( p == linestart ) // wire is overlapped by bus entry symbol
|
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line->SetEndPoint( p );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
} // for ( bus ..
|
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() );
|
|
|
|
|
|
|
|
for( const auto& seg : segs )
|
|
|
|
{
|
|
|
|
if( seg.Contains( labelPos ) )
|
|
|
|
return &seg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-04-06 13:56:32 +00:00
|
|
|
|
|
|
|
|
2018-04-12 16:10:22 +00:00
|
|
|
// TODO could be used to place junctions, instead of IsJunctionNeeded() (see SCH_EDIT_FRAME::importFile())
|
2020-01-06 14:39:20 +00:00
|
|
|
bool SCH_EAGLE_PLUGIN::checkConnections(
|
|
|
|
const SCH_COMPONENT* aComponent, const LIB_PIN* aPin ) const
|
2018-04-12 16:10:22 +00:00
|
|
|
{
|
|
|
|
wxPoint pinPosition = aComponent->GetPinPhysicalPosition( aPin );
|
2020-01-06 14:39:20 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::addImplicitConnections(
|
|
|
|
SCH_COMPONENT* aComponent, SCH_SCREEN* aScreen, bool aUpdateSet )
|
2018-04-06 13:56:32 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
wxCHECK( aComponent->GetPartRef(), /*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
|
2019-11-06 19:15:42 +00:00
|
|
|
if( aComponent->GetPartRef()->IsPower() )
|
2018-04-06 13:56:32 +00:00
|
|
|
return;
|
|
|
|
|
2020-01-06 14:39:20 +00:00
|
|
|
int unit = aComponent->GetUnit();
|
|
|
|
const wxString reference = aComponent->GetField( REFERENCE )->GetText();
|
2018-04-06 13:56:32 +00:00
|
|
|
std::vector<LIB_PIN*> pins;
|
2019-11-06 19:15:42 +00:00
|
|
|
aComponent->GetPartRef()->GetPins( pins );
|
2018-04-06 13:56:32 +00:00
|
|
|
std::set<int> missingUnits;
|
|
|
|
|
|
|
|
// Search all units for pins creating implicit connections
|
|
|
|
for( const auto& pin : pins )
|
|
|
|
{
|
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
|
|
|
|
if( pinInUnit && !checkConnections( aComponent, pin ) )
|
2018-04-06 13:56:32 +00:00
|
|
|
{
|
|
|
|
// Create a net label to force the net name on the pin
|
|
|
|
SCH_GLOBALLABEL* netLabel = new SCH_GLOBALLABEL;
|
|
|
|
netLabel->SetPosition( aComponent->GetPinPhysicalPosition( pin ) );
|
|
|
|
netLabel->SetText( extractNetName( pin->GetName() ) );
|
2020-01-05 19:11:15 +00:00
|
|
|
netLabel->SetTextSize( wxSize( Mils2iu( 10 ), Mils2iu( 10 ) ) );
|
2020-01-08 19:07:55 +00:00
|
|
|
netLabel->SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT );
|
2018-04-06 13:56:32 +00:00
|
|
|
aScreen->Append( netLabel );
|
|
|
|
}
|
|
|
|
|
2018-04-12 16:10:22 +00:00
|
|
|
else if( !pinInUnit && 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() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aUpdateSet )
|
|
|
|
{
|
|
|
|
auto cmpIt = m_missingCmps.find( reference );
|
|
|
|
|
|
|
|
// Set the flag indicating this unit has been processed
|
|
|
|
if( cmpIt != m_missingCmps.end() )
|
|
|
|
cmpIt->second.units[unit] = false;
|
|
|
|
|
|
|
|
// Save the units that need later processing
|
|
|
|
else if( !missingUnits.empty() )
|
|
|
|
{
|
|
|
|
EAGLE_MISSING_CMP& entry = m_missingCmps[reference];
|
2020-01-06 14:39:20 +00:00
|
|
|
entry.cmp = aComponent;
|
2018-04-06 13:56:32 +00:00
|
|
|
|
|
|
|
for( int i : missingUnits )
|
|
|
|
entry.units.emplace( i, true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-12 08:10:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
wxString SCH_EAGLE_PLUGIN::fixSymbolName( const wxString& aName )
|
|
|
|
{
|
2018-10-07 13:08:30 +00:00
|
|
|
wxString ret = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_SCH );
|
2018-09-12 08:10:33 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
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;
|
|
|
|
}
|