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
|
|
|
|
* @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
|
|
|
|
|
|
|
#include <properties.h>
|
2017-07-03 14:02:55 +00:00
|
|
|
#include <kiway.h>
|
2017-02-27 10:07:52 +00:00
|
|
|
|
|
|
|
#include <wx/filename.h>
|
2017-03-09 12:49:24 +00:00
|
|
|
#include <memory>
|
2018-03-28 14:03:27 +00:00
|
|
|
#include <algorithm>
|
2017-02-27 10:07:52 +00:00
|
|
|
|
2017-06-18 11:31:11 +00:00
|
|
|
#include <sch_junction.h>
|
2017-03-09 12:49:24 +00:00
|
|
|
#include <sch_sheet.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2018-02-13 00:54:33 +00:00
|
|
|
#include <worksheet_shape_builder.h>
|
2017-07-06 11:54:38 +00:00
|
|
|
#include <template_fieldnames.h>
|
2017-06-18 12:02:04 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <sch_screen.h>
|
2017-06-18 12:02:04 +00:00
|
|
|
#include <class_library.h>
|
2017-05-08 15:11:14 +00:00
|
|
|
#include <class_libentry.h>
|
2017-06-30 01:52:05 +00:00
|
|
|
#include <lib_draw_item.h>
|
2018-06-21 04:12:11 +00:00
|
|
|
#include <lib_id.h>
|
2017-06-26 07:56:11 +00:00
|
|
|
#include <sch_component.h>
|
2017-08-24 15:56:15 +00:00
|
|
|
#include <sch_sheet_path.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>
|
|
|
|
#include <lib_rectangle.h>
|
|
|
|
#include <lib_polyline.h>
|
2017-06-18 11:31:11 +00:00
|
|
|
#include <lib_pin.h>
|
2017-06-18 12:36:35 +00:00
|
|
|
#include <lib_text.h>
|
2017-07-05 15:05:03 +00:00
|
|
|
#include <sch_text.h>
|
2018-01-28 21:02:31 +00:00
|
|
|
#include <draw_graphic_text.h>
|
2017-07-13 12:35:26 +00:00
|
|
|
#include <sch_marker.h>
|
|
|
|
#include <sch_bus_entry.h>
|
2017-05-08 14:10:23 +00:00
|
|
|
#include <eagle_parser.h>
|
2017-10-24 23:08:28 +00:00
|
|
|
#include <symbol_lib_table.h>
|
|
|
|
#include <sch_legacy_plugin.h>
|
2017-07-05 15:05:03 +00:00
|
|
|
#include <sch_eagle_plugin.h>
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
EDA_RECT bbox;
|
|
|
|
SCH_ITEM* item = aSheet->GetScreen()->GetDrawItems();
|
2018-05-29 07:27:11 +00:00
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return bbox;
|
|
|
|
|
2018-04-06 11:23:24 +00:00
|
|
|
bbox = item->GetBoundingBox();
|
|
|
|
item = item->Next();
|
|
|
|
|
|
|
|
while( item )
|
|
|
|
{
|
|
|
|
bbox.Merge( item->GetBoundingBox() );
|
|
|
|
item = item->Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
m_libName = m_kiway->Prj().GetProjectName();
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
wxFileName fn( m_kiway->Prj().GetProjectPath(), getLibName(), SchematicLibraryFileExtension );
|
|
|
|
|
|
|
|
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 ) );
|
|
|
|
|
|
|
|
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.
|
2017-10-03 10:30:23 +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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-27 10:07:52 +00:00
|
|
|
SCH_EAGLE_PLUGIN::SCH_EAGLE_PLUGIN()
|
|
|
|
{
|
2017-11-01 09:20:13 +00:00
|
|
|
m_kiway = nullptr;
|
2017-03-09 12:49:24 +00:00
|
|
|
m_rootSheet = nullptr;
|
2017-11-01 09:20:13 +00:00
|
|
|
m_currentSheet = 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EAGLE_PLUGIN::GetModifyHash() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
|
2017-07-06 12:31:11 +00:00
|
|
|
SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties )
|
2017-02-27 10:07:52 +00:00
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
wxASSERT( !aFileName || aKiway != NULL );
|
2017-09-20 13:25:00 +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
|
|
|
|
2017-06-30 01:52:05 +00:00
|
|
|
m_filename = aFileName;
|
2017-06-18 11:25:09 +00:00
|
|
|
m_kiway = aKiway;
|
2017-02-27 10:07:52 +00:00
|
|
|
|
2017-07-02 12:26:23 +00:00
|
|
|
if( !xmlDocument.Load( m_filename.GetFullPath() ) )
|
2017-12-15 11:37:46 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
|
2017-07-06 12:31:11 +00:00
|
|
|
m_filename.GetFullPath() ) );
|
2017-02-27 10:07:52 +00:00
|
|
|
|
2017-03-09 12:49:24 +00:00
|
|
|
// Delete on exception, if I own m_rootSheet, according to aAppendToMe
|
2017-05-08 15:11:14 +00:00
|
|
|
unique_ptr<SCH_SHEET> deleter( aAppendToMe ? nullptr : m_rootSheet );
|
2017-03-09 12:49:24 +00:00
|
|
|
|
|
|
|
if( aAppendToMe )
|
|
|
|
{
|
|
|
|
m_rootSheet = aAppendToMe->GetRootSheet();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_rootSheet = new SCH_SHEET();
|
|
|
|
m_rootSheet->SetFileName( aFileName );
|
|
|
|
}
|
|
|
|
|
2017-05-08 15:11:14 +00:00
|
|
|
if( !m_rootSheet->GetScreen() )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = new SCH_SCREEN( aKiway );
|
|
|
|
screen->SetFileName( aFileName );
|
|
|
|
m_rootSheet->SetScreen( screen );
|
|
|
|
}
|
|
|
|
|
2017-10-24 23:08:28 +00:00
|
|
|
SYMBOL_LIB_TABLE* libTable = m_kiway->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
|
|
|
|
2017-10-24 23:08:28 +00:00
|
|
|
m_pi.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
|
|
|
|
m_properties = std::make_unique<PROPERTIES>();
|
|
|
|
(*m_properties)[ SCH_LEGACY_PLUGIN::PropBuffering ] = "";
|
|
|
|
|
|
|
|
/// @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.
|
|
|
|
libTable->InsertRow( new SYMBOL_LIB_TABLE_ROW( getLibName(), libTableUri,
|
|
|
|
wxString( "Legacy" ) ) );
|
2017-07-03 14:02:55 +00:00
|
|
|
|
2017-10-24 23:08:28 +00:00
|
|
|
// Save project symbol library table.
|
|
|
|
wxFileName fn( m_kiway->Prj().GetProjectPath(),
|
|
|
|
SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
|
|
|
|
|
|
|
|
// So output formatter goes out of scope and closes the file before reloading.
|
|
|
|
{
|
|
|
|
FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
|
|
|
|
libTable->Format( &formatter, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Relaod the symbol library table.
|
|
|
|
m_kiway->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL );
|
|
|
|
m_kiway->Prj().SchSymbolLibTable();
|
|
|
|
}
|
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"]
|
|
|
|
|
2017-07-13 12:42:06 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
// Load schematic
|
2018-08-09 17:53:48 +00:00
|
|
|
auto schematic = drawingChildren["schematic"];
|
|
|
|
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 );
|
2018-08-09 17:53:48 +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 );
|
2017-06-30 01:52:05 +00:00
|
|
|
partNode = partNode->GetNext();
|
|
|
|
}
|
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];
|
|
|
|
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;
|
2017-10-03 10:23:52 +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 )
|
|
|
|
{
|
2017-07-06 12:31:11 +00:00
|
|
|
wxPoint pos = wxPoint( x * 1000, y * 1000 );
|
2017-06-19 13:43:55 +00:00
|
|
|
std::unique_ptr<SCH_SHEET> sheet( new SCH_SHEET( pos ) );
|
|
|
|
SCH_SCREEN* screen = new SCH_SCREEN( m_kiway );
|
2017-06-18 11:25:09 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
sheet->SetTimeStamp( GetNewTimeStamp() - i ); // minus the sheet index to make it unique.
|
2020-04-26 18:27:51 +00:00
|
|
|
sheet->SetParent( m_rootSheet );
|
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;
|
|
|
|
|
2017-11-01 09:20:13 +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
|
|
|
|
wxSize pageSizeIU = m_rootSheet->GetScreen()->GetPageSettings().GetSizeIU();
|
|
|
|
EDA_RECT sheetBbox = getSheetBbox( m_rootSheet );
|
|
|
|
wxPoint newCmpPosition( sheetBbox.GetLeft(), sheetBbox.GetBottom() );
|
|
|
|
int maxY = sheetBbox.GetY();
|
|
|
|
|
|
|
|
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 )
|
|
|
|
continue; // unit has been already processed
|
|
|
|
|
|
|
|
// Instantiate the missing component unit
|
|
|
|
int unit = unitEntry.first;
|
|
|
|
const wxString& reference = origCmp->GetField( REFERENCE )->GetText();
|
|
|
|
std::unique_ptr<SCH_COMPONENT> component( new SCH_COMPONENT( *origCmp ) );
|
|
|
|
component->SetUnitSelection( &sheetpath, unit );
|
|
|
|
component->SetUnit( unit );
|
|
|
|
component->SetTimeStamp( EagleModuleTstamp( reference, origCmp->GetField( VALUE )->GetText(), unit ) );
|
|
|
|
component->SetOrientation( 0 );
|
|
|
|
component->AddHierarchicalReference( sheetpath.Path(), reference, unit );
|
|
|
|
|
|
|
|
// Calculate the placement position
|
|
|
|
EDA_RECT cmpBbox = component->GetBoundingBox();
|
|
|
|
int posY = newCmpPosition.y + cmpBbox.GetHeight();
|
|
|
|
component->SetPosition( wxPoint( newCmpPosition.x, posY ) );
|
|
|
|
newCmpPosition.x += cmpBbox.GetWidth();
|
|
|
|
maxY = std::max( maxY, posY );
|
|
|
|
|
|
|
|
if( newCmpPosition.x >= pageSizeIU.GetWidth() ) // reached the page boundary?
|
|
|
|
newCmpPosition = wxPoint( sheetBbox.GetLeft(), maxY ); // then start a new row
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2017-08-12 09:18:18 +00:00
|
|
|
wxString des;
|
|
|
|
std::string filename;
|
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 );
|
2017-06-19 13:43:55 +00:00
|
|
|
m_currentSheet->SetName( 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 );
|
2017-08-12 09:18:18 +00:00
|
|
|
m_currentSheet->SetName( filename );
|
|
|
|
}
|
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" );
|
|
|
|
m_currentSheet->SetFileName( fn );
|
|
|
|
wxFileName fileName = m_currentSheet->GetFileName();
|
|
|
|
m_currentSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
|
2017-06-18 11:25:09 +00:00
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
// Loop through all busses
|
|
|
|
// 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
|
|
|
|
wxString busName = busNode->GetAttribute( "name" );
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2018-03-28 14:03:27 +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 );
|
2017-10-03 10:23:52 +00:00
|
|
|
wxSize targetSheetSize = sheetBoundingBox.GetSize();
|
|
|
|
targetSheetSize.IncBy( 1500, 1500 );
|
2017-07-09 02:37:02 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// Get current Eeschema sheet size.
|
|
|
|
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 )
|
2017-07-09 02:37:02 +00:00
|
|
|
pageInfo.SetWidthMils( targetSheetSize.x );
|
|
|
|
|
2017-10-17 08:19:43 +00:00
|
|
|
if( pageSizeIU.y < targetSheetSize.y )
|
2017-07-09 02:37:02 +00:00
|
|
|
pageInfo.SetHeightMils( targetSheetSize.y );
|
|
|
|
|
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;
|
|
|
|
translation.x = translation.x - translation.x % 100;
|
|
|
|
translation.y = translation.y - translation.y % 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
|
|
|
|
for( SCH_ITEM* item = m_currentSheet->GetScreen()->GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
addImplicitConnections( static_cast<SCH_COMPONENT*>( item ), m_currentSheet->GetScreen(), true );
|
|
|
|
}
|
2018-04-12 16:10:22 +00:00
|
|
|
|
|
|
|
m_connPoints.clear();
|
|
|
|
|
|
|
|
// Translate the items.
|
|
|
|
for( SCH_ITEM* item = m_currentSheet->GetScreen()->GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
item->SetPosition( item->GetPosition() + translation );
|
|
|
|
item->ClearFlags();
|
|
|
|
}
|
2017-03-09 12:49:24 +00:00
|
|
|
}
|
|
|
|
|
2017-05-08 14:10:23 +00:00
|
|
|
|
2017-06-19 13:43:55 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, const wxString& netName,
|
2017-10-03 10:23:52 +00:00
|
|
|
const wxString& aNetClass )
|
2017-03-09 12:49:24 +00:00
|
|
|
{
|
2017-05-08 14:10:23 +00:00
|
|
|
// Loop through all segments
|
|
|
|
wxXmlNode* currentSegment = aSegmentsNode->GetChildren();
|
2017-06-18 11:31:11 +00:00
|
|
|
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
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
bool labelled = false; // has a label been added to this continously connected segment
|
|
|
|
NODE_MAP segmentChildren = MapChildren( currentSegment );
|
2018-03-28 14:03:27 +00:00
|
|
|
SCH_LINE* firstWire = nullptr;
|
|
|
|
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 )
|
|
|
|
continue; // no point in saving intersections of the same net
|
|
|
|
|
|
|
|
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 );
|
|
|
|
wxASSERT( segDesc.labels.empty() || segDesc.labels.front()->GetText() == label->GetText() );
|
|
|
|
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" )
|
|
|
|
{
|
|
|
|
segmentAttribute->GetAttribute( "gate" ); // REQUIRED
|
|
|
|
segmentAttribute->GetAttribute( "part" ); // REQUIRED
|
|
|
|
segmentAttribute->GetAttribute( "pin" ); // REQUIRED
|
|
|
|
}
|
|
|
|
else if( nodeName == "wire" )
|
|
|
|
{
|
2017-07-13 12:42:06 +00:00
|
|
|
// already handled;
|
2017-05-08 14:10:23 +00:00
|
|
|
}
|
2017-07-06 12:31:11 +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 ) );
|
2018-02-18 10:54:37 +00:00
|
|
|
label->SetTextSize( wxSize( 10, 10 ) );
|
|
|
|
label->SetLabelSpinStyle( 0 );
|
|
|
|
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
|
|
|
|
2017-06-19 13:43:55 +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
|
|
|
{
|
2017-06-19 13:43:55 +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
|
|
|
|
bool global = m_netCounts[aNetName] > 1;
|
|
|
|
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() ) );
|
|
|
|
label->SetLabelSpinStyle( global ? 2 : 0 );
|
2017-06-18 11:31:11 +00:00
|
|
|
|
2018-03-22 15:19:38 +00:00
|
|
|
if( elabel.rot )
|
|
|
|
{
|
|
|
|
int offset = global ? 2 : 0;
|
|
|
|
label->SetLabelSpinStyle( int( elabel.rot->degrees / 90 + offset ) % 4 );
|
2018-02-18 10:54:37 +00:00
|
|
|
|
2018-03-22 15:19:38 +00:00
|
|
|
if( elabel.rot->mirror
|
|
|
|
&& ( label->GetLabelSpinStyle() == 0 || label->GetLabelSpinStyle() == 2 ) )
|
|
|
|
label->SetLabelSpinStyle( (label->GetLabelSpinStyle() + 2 ) % 4 );
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-28 14:03:27 +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
|
|
|
{
|
2018-03-28 14:03:27 +00:00
|
|
|
VECTOR2I nearestPoint;
|
|
|
|
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;
|
2017-10-03 10:23:52 +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 )
|
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
mindistance = d;
|
|
|
|
nearestPoint = testpoint;
|
2018-03-28 14:03:27 +00:00
|
|
|
nearestLine = &line;
|
2017-07-13 12:42:06 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 14:03:27 +00:00
|
|
|
testpoint = line.Center();
|
2017-10-03 10:23:52 +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 )
|
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
mindistance = d;
|
|
|
|
nearestPoint = testpoint;
|
2018-03-28 14:03:27 +00:00
|
|
|
nearestLine = &line;
|
2017-07-13 12:42:06 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 14:03:27 +00:00
|
|
|
testpoint = line.B;
|
2017-10-03 10:23:52 +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 )
|
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
mindistance = d;
|
|
|
|
nearestPoint = testpoint;
|
2018-03-28 14:03:27 +00:00
|
|
|
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;
|
|
|
|
wxString gatename = epart->deviceset + epart->device + einstance.gate;
|
|
|
|
wxString symbolname = wxString( epart->deviceset + epart->device );
|
|
|
|
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
|
|
|
|
2017-12-14 09:37:32 +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
|
|
|
|
2017-10-24 23:08:28 +00:00
|
|
|
LIB_ALIAS* alias = m_pi->LoadSymbol( getLibFileName().GetFullPath(), kisymbolname,
|
|
|
|
m_properties.get() );
|
2017-07-09 09:35:13 +00:00
|
|
|
|
2017-10-24 23:08:28 +00:00
|
|
|
if( !alias || !alias->GetPart() )
|
2018-05-29 07:28:28 +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
|
|
|
|
2017-10-24 23:08:28 +00:00
|
|
|
LIB_PART* part = alias->GetPart();
|
|
|
|
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-10-03 10:30:23 +00:00
|
|
|
component->SetTimeStamp( EagleModuleTstamp( einstance.part, epart->value ? *epart->value : "",
|
2017-10-03 10:23:52 +00:00
|
|
|
unit ) );
|
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-08-19 07:35:21 +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 );
|
|
|
|
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 );
|
2017-08-24 15:56:15 +00:00
|
|
|
wxString current_sheetpath = sheetpath.Path();
|
|
|
|
|
|
|
|
wxString tstamp;
|
2017-10-03 10:23:52 +00:00
|
|
|
tstamp.Printf( "%8.8lX", (unsigned long) component->GetTimeStamp() );
|
2017-08-24 15:56:15 +00:00
|
|
|
current_sheetpath += tstamp;
|
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
|
|
|
|
2018-07-10 14:32:10 +00:00
|
|
|
for( auto a:epart->attribute )
|
|
|
|
{
|
|
|
|
auto field = component->AddField( *component->GetField( VALUE ) );
|
|
|
|
field->SetName( a.first );
|
|
|
|
field->SetText( a.second );
|
|
|
|
field->SetVisible( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto a:epart->variant )
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
auto attr = EATTR( attributeNode );
|
2018-07-10 14:32:10 +00:00
|
|
|
SCH_FIELD* field = NULL;
|
|
|
|
|
|
|
|
if( attr.name.Lower() == "name" )
|
|
|
|
{
|
|
|
|
field = component->GetField( REFERENCE );
|
|
|
|
nameAttributeFound = true;
|
|
|
|
}
|
|
|
|
else if( attr.name.Lower() == "value" )
|
|
|
|
{
|
|
|
|
field = component->GetField( VALUE );
|
|
|
|
valueAttributeFound = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
field = component->FindField( attr.name );
|
2017-07-16 16:12:05 +00:00
|
|
|
|
2018-07-10 14:32:10 +00:00
|
|
|
if(field)
|
|
|
|
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() ) );
|
2017-07-16 16:12:05 +00:00
|
|
|
int align = attr.align ? *attr.align : ETEXT::BOTTOM_LEFT;
|
2017-07-23 14:28:23 +00:00
|
|
|
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
|
|
|
|
2017-07-25 09:58:54 +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;
|
|
|
|
|
2017-10-03 10:23:52 +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 )
|
|
|
|
&& attributeNode->GetAttribute( "value", &value ) )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
auto& schLibTable = *m_kiway->Prj().SchSymbolLibTable();
|
|
|
|
wxCHECK( component->Resolve( schLibTable ), /*void*/ );
|
|
|
|
component->UpdatePinCache();
|
|
|
|
std::vector<LIB_PIN*> pins;
|
|
|
|
component->GetPins( pins );
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-03 10:23:52 +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 )
|
|
|
|
{
|
2017-12-14 09:37:32 +00:00
|
|
|
wxString symbolName = symbolNode->GetAttribute( "name" );
|
2017-10-03 10:23:52 +00:00
|
|
|
aEagleLibrary->SymbolNodes[symbolName] = symbolNode;
|
2017-05-08 14:10:23 +00:00
|
|
|
symbolNode = symbolNode->GetNext();
|
|
|
|
}
|
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
|
|
|
|
2017-07-06 12:31:11 +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.
|
2017-07-06 12:31:11 +00:00
|
|
|
wxXmlNode* gateNode = getChildrenNodes( aDeviceSetChildren, "gates" );
|
2017-10-03 10:30:23 +00:00
|
|
|
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
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
int gateindex = 1;
|
2017-07-30 09:50:38 +00:00
|
|
|
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
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
ispower = loadSymbol( aEagleLibrary->SymbolNodes[egate.symbol],
|
2017-08-06 14:20:29 +00:00
|
|
|
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();
|
2017-07-06 12:31:11 +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() ),
|
|
|
|
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();
|
2017-07-06 12:31:11 +00:00
|
|
|
} // devicenode
|
2017-06-26 07:56:11 +00:00
|
|
|
|
2017-06-30 01:52:05 +00:00
|
|
|
devicesetNode = devicesetNode->GetNext();
|
2017-07-06 12:31:11 +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
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
2017-10-03 10:23:52 +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
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
EPIN ePin = EPIN( currentNode );
|
|
|
|
std::unique_ptr<LIB_PIN> pin( loadPin( aPart, currentNode, &ePin, aGateNumber ) );
|
2017-07-30 09:50:38 +00:00
|
|
|
pincount++;
|
|
|
|
|
2019-01-06 16:53:16 +00:00
|
|
|
pin->SetType( PIN_BIDI );
|
|
|
|
|
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
|
|
|
const std::map<wxString, ELECTRICAL_PINTYPE> pinDirectionsMap =
|
2017-07-30 09:50:38 +00:00
|
|
|
{
|
2018-04-03 11:16:29 +00:00
|
|
|
{ "sup", PIN_POWER_IN }, { "pas", PIN_PASSIVE },
|
|
|
|
{ "out", PIN_OUTPUT }, { "in", PIN_INPUT },
|
|
|
|
{ "nc", PIN_NC }, { "io", PIN_BIDI },
|
|
|
|
{ "oc", PIN_OPENCOLLECTOR }, { "hiz", PIN_TRISTATE },
|
|
|
|
{ "pwr", PIN_POWER_IN },
|
|
|
|
};
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
if( pinDir.first == "sup" ) // power supply symbol
|
|
|
|
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
|
|
|
{
|
2017-07-09 02:40:23 +00:00
|
|
|
for( 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
|
|
|
{
|
2017-10-17 08:19:43 +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->SetPartNumber( aGateNumber );
|
|
|
|
pin->SetUnit( aGateNumber );
|
2017-10-11 12:28:07 +00:00
|
|
|
pin->SetName( escapeName( pin->GetName() ) );
|
2017-07-14 14:36:46 +00:00
|
|
|
|
2017-09-23 07:34:20 +00:00
|
|
|
if( pads.GetCount() > 1)
|
|
|
|
{
|
|
|
|
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.
|
2017-10-20 11:48:36 +00:00
|
|
|
for( unsigned i = 0; i < pads.GetCount(); i++)
|
2017-09-23 07:34:20 +00:00
|
|
|
{
|
2019-06-10 00:00:09 +00:00
|
|
|
if( pin->GetType() == PIN_NC && i > 0)
|
|
|
|
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->SetPartNumber( aGateNumber );
|
|
|
|
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
|
|
|
|
2017-10-18 08:33:51 +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;
|
|
|
|
}
|
|
|
|
else if( libtext->GetText().Upper() ==">VALUE" )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2017-10-03 10:23:52 +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
|
|
|
|
2017-10-03 10:23:52 +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
|
|
|
|
2017-10-03 10:23:52 +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() ) );
|
2017-10-17 08:18:54 +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 ) )
|
2017-10-03 10:23:52 +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;
|
|
|
|
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;
|
|
|
|
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 ) )
|
2017-10-03 10:23:52 +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 );
|
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
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
LIB_POLYLINE* SCH_EAGLE_PLUGIN::loadSymbolPolyLine( std::unique_ptr<LIB_PART>& aPart,
|
2017-10-17 08:18:54 +00:00
|
|
|
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
|
|
|
|
2017-07-17 12:47:49 +00:00
|
|
|
EPOLYGON epoly( aPolygonNode );
|
|
|
|
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 )
|
|
|
|
{
|
2017-07-17 12:47:49 +00:00
|
|
|
if( vertex->GetName() == "vertex" ) // skip <xmlattr> node
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
LIB_PIN* SCH_EAGLE_PLUGIN::loadPin( std::unique_ptr<LIB_PART>& aPart,
|
|
|
|
wxXmlNode* aPin,
|
2017-10-03 10:30:23 +00:00
|
|
|
EPIN* aEPin,
|
2017-10-03 10:23:52 +00:00
|
|
|
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 ) );
|
2017-07-06 12:31:11 +00:00
|
|
|
|
|
|
|
// fall through
|
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
|
|
|
|
|
|
|
if( length =="short" )
|
|
|
|
{
|
|
|
|
pin->SetLength( 100 );
|
|
|
|
}
|
|
|
|
else if( length =="middle" )
|
|
|
|
{
|
|
|
|
pin->SetLength( 200 );
|
|
|
|
}
|
|
|
|
else if( length == "long" )
|
|
|
|
{
|
|
|
|
pin->SetLength( 300 );
|
|
|
|
}
|
|
|
|
else if( length == "point" )
|
|
|
|
{
|
|
|
|
pin->SetLength( 0 );
|
|
|
|
}
|
2017-06-18 12:25:36 +00:00
|
|
|
}
|
2017-06-18 11:31:11 +00:00
|
|
|
|
2017-10-18 08:33:51 +00:00
|
|
|
// emulate the visibility of pin elements
|
2017-10-03 10:30:23 +00:00
|
|
|
if( aEPin->visible )
|
2017-07-16 16:13:10 +00:00
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
wxString visible = aEPin->visible.Get();
|
2017-07-16 16:13:10 +00:00
|
|
|
|
|
|
|
if( visible == "off" )
|
|
|
|
{
|
|
|
|
pin->SetNameTextSize( 0 );
|
|
|
|
pin->SetNumberTextSize( 0 );
|
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
else if( visible == "pad" )
|
2017-07-16 16:13:10 +00:00
|
|
|
{
|
|
|
|
pin->SetNameTextSize( 0 );
|
|
|
|
}
|
|
|
|
else if( visible == "pin" )
|
|
|
|
{
|
|
|
|
pin->SetNumberTextSize( 0 );
|
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
|
2017-07-16 16:13:10 +00:00
|
|
|
/*
|
2017-10-03 10:23:52 +00:00
|
|
|
* else if( visible == "both" )
|
|
|
|
* {
|
|
|
|
* }
|
|
|
|
*/
|
2017-07-16 16:13:10 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
if( aEPin->function )
|
2017-08-19 05:41:48 +00:00
|
|
|
{
|
2017-10-03 10:30:23 +00:00
|
|
|
wxString function = aEPin->function.Get();
|
2017-08-19 05:41:48 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
if( function == "dot" )
|
2017-08-19 05:41:48 +00:00
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
pin->SetShape( 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
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
pin->SetShape( 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
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
pin->SetShape( 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
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymbolText( std::unique_ptr<LIB_PART>& aPart,
|
2017-10-18 08:12:22 +00:00
|
|
|
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() ) );
|
|
|
|
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() );
|
2017-10-18 08:12:22 +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 );
|
|
|
|
aText->SetThickness( GetPenSizeForBold( aText->GetTextWidth() ) );
|
2017-07-05 15:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-18 08:12:22 +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() );
|
|
|
|
|
|
|
|
auto onIntersection = [&]( const VECTOR2I& aPos )
|
|
|
|
{
|
|
|
|
return std::binary_search( m_wireIntersections.begin(), m_wireIntersections.end(), aPos );
|
|
|
|
};
|
|
|
|
|
|
|
|
for( auto& segDesc : m_segments )
|
|
|
|
{
|
|
|
|
for( SCH_TEXT* label : segDesc.labels )
|
|
|
|
{
|
|
|
|
VECTOR2I labelPos( label->GetPosition() );
|
|
|
|
const SEG* segAttached = segDesc.LabelAttached( label );
|
|
|
|
|
|
|
|
if( segAttached && !onIntersection( labelPos ) )
|
|
|
|
continue; // label is placed correctly
|
|
|
|
|
|
|
|
|
|
|
|
// Move the label to the nearest wire
|
|
|
|
if( !segAttached )
|
|
|
|
{
|
|
|
|
std::tie( labelPos, segAttached ) = findNearestLinePoint( label->GetPosition(), segDesc.segs );
|
|
|
|
|
|
|
|
if( !segAttached ) // we cannot do anything
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create a vector pointing in the direction of the wire, 50 mils long
|
|
|
|
VECTOR2I wireDirection( segAttached->B - segAttached->A );
|
|
|
|
wireDirection = wireDirection.Resize( 50 );
|
|
|
|
const VECTOR2I origPos( labelPos );
|
|
|
|
|
|
|
|
// Flags determining the search direction
|
|
|
|
bool checkPositive = true, checkNegative = true, move = false;
|
|
|
|
int trial = 0;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
firstline = tempFile.GetFirstLine();
|
2017-10-03 10:23:52 +00:00
|
|
|
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
|
|
|
{
|
2017-08-14 14:45:57 +00:00
|
|
|
for( SCH_ITEM* item = m_currentSheet->GetScreen()->GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2017-08-13 16:48:52 +00:00
|
|
|
for( SCH_ITEM* bus = m_currentSheet->GetScreen()->GetDrawItems(); bus; bus = bus->Next() )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
// Check line type for line
|
|
|
|
if( bus->Type() != SCH_LINE_T )
|
2017-07-13 12:35:26 +00:00
|
|
|
continue;
|
|
|
|
|
2017-08-13 16:48:52 +00:00
|
|
|
// Check line type for wire
|
|
|
|
if( ( (SCH_LINE*) bus )->GetLayer() != LAYER_BUS )
|
2017-07-13 12:35:26 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
2017-08-13 16:48:52 +00:00
|
|
|
wxPoint busstart = ( (SCH_LINE*) bus )->GetStartPoint();
|
|
|
|
wxPoint busend = ( (SCH_LINE*) bus )->GetEndPoint();
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
SCH_ITEM* nextline;
|
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
for( SCH_ITEM* line = m_currentSheet->GetScreen()->GetDrawItems(); line; line = nextline )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
nextline = line->Next();
|
|
|
|
|
|
|
|
// Check line type for line
|
|
|
|
if( line->Type() == SCH_LINE_T )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
// Check line type for bus
|
|
|
|
if( ( (SCH_LINE*) line )->GetLayer() == LAYER_WIRE )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
// Get points of both segments.
|
|
|
|
|
|
|
|
wxPoint linestart = ( (SCH_LINE*) line )->GetStartPoint();
|
|
|
|
wxPoint lineend = ( (SCH_LINE*) line )->GetEndPoint();
|
2017-07-13 12:35:26 +00:00
|
|
|
|
|
|
|
|
2017-08-13 16:48:52 +00:00
|
|
|
// Test for horizontal wire and vertical bus
|
|
|
|
if( linestart.y == lineend.y && busstart.x == busend.x )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
if( TestSegmentHit( linestart, busstart, busend, 0 ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
// Wire start is on a bus.
|
|
|
|
// Wire start is on the vertical bus
|
|
|
|
|
|
|
|
// 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( linestart + wxPoint(
|
|
|
|
-100,
|
|
|
|
0 ),
|
|
|
|
'/' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, linestart + wxPoint( -100, 0 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) 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( linestart + wxPoint(
|
|
|
|
-100,
|
|
|
|
0 ),
|
|
|
|
'\\' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, linestart + wxPoint( -100, 0 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) line )->SetStartPoint( linestart +
|
|
|
|
wxPoint( -100, 0 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( linestart,
|
2018-02-25 12:17:23 +00:00
|
|
|
"Bus Entry needed" );
|
2017-08-13 16:48:52 +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
|
|
|
|
// |
|
|
|
|
// |----
|
2017-07-13 12:35:26 +00:00
|
|
|
// |
|
2017-08-13 16:48:52 +00:00
|
|
|
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( linestart + wxPoint(
|
|
|
|
0,
|
|
|
|
-100 ),
|
|
|
|
'\\' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, linestart + wxPoint( 100, 0 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) 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( linestart + wxPoint(
|
|
|
|
0,
|
|
|
|
100 ),
|
|
|
|
'/' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, linestart + wxPoint( 100, 0 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) line )->SetStartPoint( linestart + wxPoint( 100,
|
|
|
|
0 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( linestart,
|
2018-02-25 12:17:23 +00:00
|
|
|
"Bus Entry needed" );
|
2017-08-13 16:48:52 +00:00
|
|
|
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
2017-08-13 16:48:52 +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
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
// Wire end is on the vertical bus
|
|
|
|
|
|
|
|
// 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 ) )
|
|
|
|
{
|
|
|
|
// |
|
|
|
|
// ___/|
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
|
|
|
|
-100,
|
|
|
|
0 ),
|
|
|
|
'\\' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, lineend + wxPoint( -100, 0 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) 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 = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
|
|
|
|
-100,
|
|
|
|
0 ),
|
|
|
|
'/' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, lineend + wxPoint( -100, 0 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) line )->SetEndPoint( lineend +
|
|
|
|
wxPoint( -100, 0 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( lineend,
|
2018-02-25 12:17:23 +00:00
|
|
|
"Bus Entry needed" );
|
2017-08-13 16:48:52 +00:00
|
|
|
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// else the start of the wire is to the right of the bus
|
|
|
|
// |
|
|
|
|
// |----
|
|
|
|
// |
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// test if bus existed above the wire
|
|
|
|
if( TestSegmentHit( lineend + wxPoint( 0, -100 ), busstart,
|
|
|
|
busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
|
|
|
|
0,
|
|
|
|
-100 ),
|
|
|
|
'\\' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, lineend + wxPoint( 100, 0 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) 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 = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
|
|
|
|
0,
|
|
|
|
100 ),
|
|
|
|
'/' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, lineend + wxPoint( 100, 0 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) line )->SetEndPoint( lineend +
|
|
|
|
wxPoint( 100, 0 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( lineend,
|
2018-02-25 12:17:23 +00:00
|
|
|
"Bus Entry needed" );
|
2017-08-13 16:48:52 +00:00
|
|
|
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
} // if( linestart.y == lineend.y && busstart.x == busend.x)
|
2017-08-13 16:48:52 +00:00
|
|
|
|
|
|
|
// Test for horizontal wire and vertical bus
|
|
|
|
if( linestart.x == lineend.x && busstart.y == busend.y )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
if( TestSegmentHit( linestart, busstart, busend, 0 ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
// Wire start is on the bus
|
|
|
|
// If wire end is above the bus,
|
|
|
|
if( lineend.y < busstart.y )
|
|
|
|
{
|
|
|
|
// Test for bus existance to the left of the wire
|
|
|
|
if( TestSegmentHit( linestart + wxPoint( -100, 0 ), busstart,
|
|
|
|
busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart + wxPoint(
|
|
|
|
-100,
|
|
|
|
0 ),
|
|
|
|
'/' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, linestart + wxPoint( 0, -100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) line )->SetStartPoint( linestart +
|
|
|
|
wxPoint( 0, -100 ) );
|
|
|
|
}
|
|
|
|
else if( TestSegmentHit( linestart + wxPoint( 100, 0 ), busstart,
|
|
|
|
busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart + wxPoint(
|
|
|
|
0,
|
|
|
|
100 ),
|
|
|
|
'\\' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, linestart + wxPoint( 0, -100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) line )->SetStartPoint( linestart +
|
|
|
|
wxPoint( 0, -100 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( linestart,
|
2018-02-25 12:17:23 +00:00
|
|
|
"Bus Entry needed" );
|
2017-08-13 16:48:52 +00:00
|
|
|
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
else // wire end is below the bus.
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
|
|
|
// Test for bus existance to the left of the wire
|
|
|
|
if( TestSegmentHit( linestart + wxPoint( -100, 0 ), busstart,
|
|
|
|
busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart + wxPoint(
|
|
|
|
-100,
|
|
|
|
0 ),
|
|
|
|
'\\' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, linestart + wxPoint( 0, 100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) line )->SetStartPoint( linestart + wxPoint( 0,
|
|
|
|
100 ) );
|
|
|
|
}
|
|
|
|
else if( TestSegmentHit( linestart + wxPoint( 100, 0 ), busstart,
|
|
|
|
busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart + wxPoint(
|
|
|
|
100,
|
|
|
|
0 ),
|
|
|
|
'/' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, linestart + wxPoint( 0, 100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) line )->SetStartPoint( linestart + wxPoint( 0,
|
|
|
|
100 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( linestart,
|
2018-02-25 12:17:23 +00:00
|
|
|
"Bus Entry needed" );
|
2017-08-13 16:48:52 +00:00
|
|
|
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
2017-08-13 16:48:52 +00:00
|
|
|
|
|
|
|
if( TestSegmentHit( lineend, busstart, busend, 0 ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
// Wire end is on the bus
|
|
|
|
// If wire start is above the bus,
|
|
|
|
|
|
|
|
if( linestart.y < busstart.y )
|
|
|
|
{
|
|
|
|
// Test for bus existance to the left of the wire
|
|
|
|
if( TestSegmentHit( lineend + wxPoint( -100, 0 ), busstart,
|
|
|
|
busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
|
|
|
|
-100,
|
|
|
|
0 ),
|
|
|
|
'/' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, lineend + wxPoint( 0, -100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) line )->SetEndPoint( lineend +
|
|
|
|
wxPoint( 0, -100 ) );
|
|
|
|
}
|
|
|
|
else if( TestSegmentHit( lineend + wxPoint( 100, 0 ), busstart,
|
|
|
|
busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
|
|
|
|
0,
|
|
|
|
-100 ),
|
|
|
|
'\\' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, lineend + wxPoint( 0, -100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) line )->SetEndPoint( lineend +
|
|
|
|
wxPoint( 0, -100 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( lineend,
|
2018-02-25 12:17:23 +00:00
|
|
|
"Bus Entry needed" );
|
2017-08-13 16:48:52 +00:00
|
|
|
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
else // wire end is below the bus.
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
|
|
|
// Test for bus existance to the left of the wire
|
|
|
|
if( TestSegmentHit( lineend + wxPoint( -100, 0 ), busstart,
|
|
|
|
busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
|
|
|
|
-100,
|
|
|
|
0 ),
|
|
|
|
'\\' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, lineend + wxPoint( 0, 100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) line )->SetEndPoint( lineend +
|
|
|
|
wxPoint( 0, 100 ) );
|
|
|
|
}
|
|
|
|
else if( TestSegmentHit( lineend + wxPoint( 100, 0 ), busstart,
|
|
|
|
busend, 0 ) )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
|
|
|
|
0,
|
|
|
|
100 ),
|
|
|
|
'/' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, lineend + wxPoint( 0, 100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
( (SCH_LINE*) line )->SetEndPoint( lineend +
|
|
|
|
wxPoint( 0, 100 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( lineend,
|
2018-02-25 12:17:23 +00:00
|
|
|
"Bus Entry needed" );
|
2017-08-13 16:48:52 +00:00
|
|
|
|
|
|
|
m_currentSheet->GetScreen()->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-13 16:48:52 +00:00
|
|
|
linestart = ( (SCH_LINE*) line )->GetStartPoint();
|
2017-10-03 10:23:52 +00:00
|
|
|
lineend = ( (SCH_LINE*) line )->GetEndPoint();
|
|
|
|
busstart = ( (SCH_LINE*) bus )->GetStartPoint();
|
2017-08-13 16:48:52 +00:00
|
|
|
busend = ( (SCH_LINE*) bus )->GetEndPoint();
|
2017-07-13 12:35:26 +00:00
|
|
|
|
|
|
|
|
2017-08-13 16:48:52 +00:00
|
|
|
// bus entry wire isn't horizontal or vertical
|
|
|
|
if( TestSegmentHit( linestart, busstart, busend, 0 ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
wxPoint wirevector = linestart - lineend;
|
2017-07-13 12:35:26 +00:00
|
|
|
|
2017-08-13 16:48:52 +00:00
|
|
|
if( wirevector.x > 0 )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
if( wirevector.y > 0 )
|
|
|
|
{
|
|
|
|
wxPoint p = linestart + wxPoint( -100, -100 );
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, '\\' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, p );
|
|
|
|
|
|
|
|
if( p == lineend ) // wire is overlapped by bus entry symbol
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
2018-03-28 13:51:10 +00:00
|
|
|
line = nullptr;
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
( (SCH_LINE*) line )->SetStartPoint( p );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxPoint p = linestart + wxPoint( -100, 100 );
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, '/' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, p );
|
|
|
|
|
2018-03-28 10:59:56 +00:00
|
|
|
if( p == lineend ) // wire is overlapped by bus entry symbol
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
2018-03-28 13:51:10 +00:00
|
|
|
line = nullptr;
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
( (SCH_LINE*) line )->SetStartPoint( p );
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
if( wirevector.y > 0 )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart,
|
|
|
|
'/' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, linestart + wxPoint( 100, -100 ) );
|
|
|
|
|
|
|
|
if( linestart + wxPoint( 100, -100 )== lineend ) // wire is overlapped by bus entry symbol
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
2018-03-28 13:51:10 +00:00
|
|
|
line = nullptr;
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
( (SCH_LINE*) line )->SetStartPoint( linestart +
|
|
|
|
wxPoint( 100, -100 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart,
|
|
|
|
'\\' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, linestart + wxPoint( 100, 100 ) );
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
if( linestart + wxPoint( 100, 100 )== lineend ) // wire is overlapped by bus entry symbol
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
2018-03-28 13:51:10 +00:00
|
|
|
line = nullptr;
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
( (SCH_LINE*) line )->SetStartPoint( linestart +
|
|
|
|
wxPoint( 100, 100 ) );
|
|
|
|
}
|
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-13 16:48:52 +00:00
|
|
|
|
2018-03-28 13:51:10 +00:00
|
|
|
if( line && TestSegmentHit( lineend, busstart, busend, 0 ) )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
wxPoint wirevector = linestart - lineend;
|
|
|
|
|
|
|
|
if( wirevector.x > 0 )
|
2017-07-13 12:35:26 +00:00
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
if( wirevector.y > 0 )
|
|
|
|
{
|
|
|
|
wxPoint p = lineend + wxPoint( 100, 100 );
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry =
|
|
|
|
new SCH_BUS_WIRE_ENTRY( lineend, '\\' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, p );
|
|
|
|
|
|
|
|
if( p == linestart ) // wire is overlapped by bus entry symbol
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
( (SCH_LINE*) line )->SetEndPoint( p );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxPoint p = lineend + wxPoint( 100, -100 );
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry =
|
|
|
|
new SCH_BUS_WIRE_ENTRY( lineend, '/' );
|
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, p );
|
|
|
|
|
|
|
|
if( p== linestart ) // wire is overlapped by bus entry symbol
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
( (SCH_LINE*) line )->SetEndPoint( p );
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2017-08-13 16:48:52 +00:00
|
|
|
if( wirevector.y > 0 )
|
|
|
|
{
|
2017-08-14 14:45:57 +00:00
|
|
|
wxPoint p = lineend + wxPoint( -100, 100 );
|
2017-08-13 16:48:52 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry =
|
2017-08-14 14:45:57 +00:00
|
|
|
new SCH_BUS_WIRE_ENTRY( p, '/' );
|
2017-08-13 16:48:52 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, p );
|
|
|
|
|
|
|
|
if( p == linestart ) // wire is overlapped by bus entry symbol
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-14 14:45:57 +00:00
|
|
|
( (SCH_LINE*) line )->SetEndPoint( p );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
wxPoint p = lineend + wxPoint( -100, -100 );
|
2017-08-13 16:48:52 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry =
|
2017-10-03 10:23:52 +00:00
|
|
|
new SCH_BUS_WIRE_ENTRY( p, '\\' );
|
2017-08-13 16:48:52 +00:00
|
|
|
busEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busEntry );
|
2017-10-03 10:23:52 +00:00
|
|
|
moveLabels( line, p );
|
|
|
|
|
|
|
|
if( p == linestart ) // wire is overlapped by bus entry symbol
|
2017-08-13 16:48:52 +00:00
|
|
|
{
|
|
|
|
m_currentSheet->GetScreen()->DeleteItem( line );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-14 14:45:57 +00:00
|
|
|
( (SCH_LINE*) line )->SetEndPoint( p );
|
2017-08-13 16:48:52 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-13 12:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 10:23:52 +00:00
|
|
|
} // for ( line ..
|
|
|
|
} // 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())
|
|
|
|
bool SCH_EAGLE_PLUGIN::checkConnections( const SCH_COMPONENT* aComponent, const LIB_PIN* aPin ) const
|
|
|
|
{
|
|
|
|
wxPoint pinPosition = aComponent->GetPinPhysicalPosition( aPin );
|
|
|
|
auto pointIt = m_connPoints.find( pinPosition );
|
|
|
|
|
|
|
|
if( pointIt == m_connPoints.end() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const auto& items = pointIt->second;
|
|
|
|
wxASSERT( items.find( aPin ) != items.end() );
|
|
|
|
return items.size() > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-06 13:56:32 +00:00
|
|
|
void SCH_EAGLE_PLUGIN::addImplicitConnections( SCH_COMPONENT* aComponent,
|
|
|
|
SCH_SCREEN* aScreen, bool aUpdateSet )
|
|
|
|
{
|
|
|
|
aComponent->UpdatePinCache();
|
|
|
|
auto partRef = aComponent->GetPartRef().lock();
|
|
|
|
wxCHECK( partRef, /*void*/ );
|
|
|
|
|
|
|
|
// Normally power parts also have power input pins,
|
|
|
|
// but they already force net names on the attached wires
|
|
|
|
if( partRef->IsPower() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int unit = aComponent->GetUnit();
|
|
|
|
const wxString& reference = aComponent->GetField( REFERENCE )->GetText();
|
|
|
|
std::vector<LIB_PIN*> pins;
|
|
|
|
partRef->GetPins( pins );
|
|
|
|
std::set<int> missingUnits;
|
|
|
|
|
|
|
|
// Search all units for pins creating implicit connections
|
|
|
|
for( const auto& pin : pins )
|
|
|
|
{
|
|
|
|
if( pin->GetType() == PIN_POWER_IN )
|
|
|
|
{
|
2018-04-12 16:10:22 +00:00
|
|
|
bool pinInUnit = !unit || pin->GetUnit() == unit; // pin belongs to the tested unit
|
|
|
|
|
|
|
|
// 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() ) );
|
|
|
|
netLabel->SetTextSize( wxSize( 10, 10 ) );
|
|
|
|
netLabel->SetLabelSpinStyle( 0 );
|
|
|
|
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];
|
|
|
|
entry.cmp = aComponent;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|