KiCad PCB EDA Suite
sch_altium_plugin.cpp File Reference
#include <memory>
#include "altium_parser_sch.h"
#include <plugins/altium/altium_parser.h>
#include <plugins/altium/altium_parser_utils.h>
#include <sch_plugins/altium/sch_altium_plugin.h>
#include <schematic.h>
#include <lib_arc.h>
#include <lib_bezier.h>
#include <lib_circle.h>
#include <lib_id.h>
#include <lib_item.h>
#include <lib_pin.h>
#include <lib_polyline.h>
#include <lib_rectangle.h>
#include <lib_text.h>
#include <bus_alias.h>
#include <sch_bitmap.h>
#include <sch_bus_entry.h>
#include <sch_symbol.h>
#include <sch_junction.h>
#include <sch_line.h>
#include <sch_no_connect.h>
#include <sch_screen.h>
#include <sch_sheet.h>
#include <sch_sheet_pin.h>
#include <sch_text.h>
#include <bezier_curves.h>
#include <compoundfilereader.h>
#include <kicad_string.h>
#include <sch_edit_frame.h>
#include <wildcards_and_files_ext.h>
#include <wx/mstream.h>
#include <wx/zstream.h>
#include <wx/wfstream.h>

Go to the source code of this file.

Functions

const wxPoint GetRelativePosition (const wxPoint &aPosition, const SCH_COMPONENT *aComponent)
 
COLOR4D GetColorFromInt (int color)
 
void SetEdaTextJustification (EDA_TEXT *text, ASCH_LABEL_JUSTIFICATION justification)
 
wxPoint HelperGeneratePowerPortGraphics (LIB_PART *aKPart, ASCH_POWER_PORT_STYLE aStyle, REPORTER *aReporter)
 
void SetFieldOrientation (SCH_FIELD &aField, ASCH_RECORD_ORIENTATION aOrientation)
 

Function Documentation

◆ GetColorFromInt()

COLOR4D GetColorFromInt ( int  color)

Definition at line 73 of file sch_altium_plugin.cpp.

74 {
75  int red = color & 0x0000FF;
76  int green = ( color & 0x00FF00 ) >> 8;
77  int blue = ( color & 0xFF0000 ) >> 16;
78 
79  return COLOR4D().FromCSSRGBA( red, green, blue, 1.0 );
80 }
COLOR4D & FromCSSRGBA(int aRed, int aGreen, int aBlue, double aAlpha=1.0)
Initialize the color from a RGBA value with 0-255 red/green/blue and 0-1 alpha.
Definition: color4d.cpp:476
int color
Definition: DXF_plotter.cpp:60
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References color, KIGFX::COLOR4D::FromCSSRGBA(), and red.

Referenced by SCH_ALTIUM_PLUGIN::ParseSheetSymbol().

◆ GetRelativePosition()

const wxPoint GetRelativePosition ( const wxPoint &  aPosition,
const SCH_COMPONENT aComponent 
)

Definition at line 66 of file sch_altium_plugin.cpp.

67 {
68  TRANSFORM t = aComponent->GetTransform().InverseTransform();
69  return t.TransformCoordinate( aPosition - aComponent->GetPosition() );
70 }
TRANSFORM InverseTransform() const
Calculate the Inverse mirror/rotation transform.
Definition: transform.cpp:59
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:42
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
TRANSFORM & GetTransform()
Definition: sch_symbol.h:231
wxPoint GetPosition() const override
Definition: sch_symbol.h:641

References SCH_COMPONENT::GetPosition(), SCH_COMPONENT::GetTransform(), TRANSFORM::InverseTransform(), and TRANSFORM::TransformCoordinate().

Referenced by SCH_ALTIUM_PLUGIN::ParseArc(), SCH_ALTIUM_PLUGIN::ParseBezier(), SCH_ALTIUM_PLUGIN::ParseLabel(), SCH_ALTIUM_PLUGIN::ParseLine(), SCH_ALTIUM_PLUGIN::ParsePin(), SCH_ALTIUM_PLUGIN::ParsePolygon(), SCH_ALTIUM_PLUGIN::ParsePolyline(), SCH_ALTIUM_PLUGIN::ParseRectangle(), and SCH_ALTIUM_PLUGIN::ParseRoundRectangle().

◆ HelperGeneratePowerPortGraphics()

wxPoint HelperGeneratePowerPortGraphics ( LIB_PART aKPart,
ASCH_POWER_PORT_STYLE  aStyle,
REPORTER aReporter 
)

Definition at line 1428 of file sch_altium_plugin.cpp.

1430 {
1431  if( aStyle == ASCH_POWER_PORT_STYLE::CIRCLE || aStyle == ASCH_POWER_PORT_STYLE::ARROW )
1432  {
1433  LIB_POLYLINE* line1 = new LIB_POLYLINE( aKPart );
1434  aKPart->AddDrawItem( line1 );
1435  line1->SetWidth( Mils2iu( 10 ) );
1436  line1->AddPoint( { 0, 0 } );
1437  line1->AddPoint( { 0, Mils2iu( -50 ) } );
1438 
1439  if( aStyle == ASCH_POWER_PORT_STYLE::CIRCLE )
1440  {
1441  LIB_CIRCLE* circle = new LIB_CIRCLE( aKPart );
1442  aKPart->AddDrawItem( circle );
1443  circle->SetWidth( Mils2iu( 5 ) );
1444  circle->SetRadius( Mils2iu( 25 ) );
1445  circle->SetPosition( { Mils2iu( 0 ), Mils2iu( -75 ) } );
1446  }
1447  else
1448  {
1449  LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
1450  aKPart->AddDrawItem( line2 );
1451  line2->SetWidth( Mils2iu( 10 ) );
1452  line2->AddPoint( { Mils2iu( -25 ), Mils2iu( -50 ) } );
1453  line2->AddPoint( { Mils2iu( 25 ), Mils2iu( -50 ) } );
1454  line2->AddPoint( { Mils2iu( 0 ), Mils2iu( -100 ) } );
1455  line2->AddPoint( { Mils2iu( -25 ), Mils2iu( -50 ) } );
1456  }
1457 
1458  return { 0, Mils2iu( 150 ) };
1459  }
1460  else if( aStyle == ASCH_POWER_PORT_STYLE::WAVE )
1461  {
1462  LIB_POLYLINE* line = new LIB_POLYLINE( aKPart );
1463  aKPart->AddDrawItem( line );
1464  line->SetWidth( Mils2iu( 10 ) );
1465  line->AddPoint( { 0, 0 } );
1466  line->AddPoint( { 0, Mils2iu( -72 ) } );
1467 
1468  LIB_BEZIER* bezier = new LIB_BEZIER( aKPart );
1469  aKPart->AddDrawItem( bezier );
1470  bezier->SetWidth( Mils2iu( 5 ) );
1471  bezier->AddPoint( { Mils2iu( 30 ), Mils2iu( -50 ) } );
1472  bezier->AddPoint( { Mils2iu( 30 ), Mils2iu( -87 ) } );
1473  bezier->AddPoint( { Mils2iu( -30 ), Mils2iu( -63 ) } );
1474  bezier->AddPoint( { Mils2iu( -30 ), Mils2iu( -100 ) } );
1475 
1476  return { 0, Mils2iu( 150 ) };
1477  }
1478  else if( aStyle == ASCH_POWER_PORT_STYLE::POWER_GROUND
1480  || aStyle == ASCH_POWER_PORT_STYLE::EARTH
1481  || aStyle == ASCH_POWER_PORT_STYLE::GOST_ARROW )
1482  {
1483  LIB_POLYLINE* line1 = new LIB_POLYLINE( aKPart );
1484  aKPart->AddDrawItem( line1 );
1485  line1->SetWidth( Mils2iu( 10 ) );
1486  line1->AddPoint( { 0, 0 } );
1487  line1->AddPoint( { 0, Mils2iu( -100 ) } );
1488 
1489  if( aStyle == ASCH_POWER_PORT_STYLE::POWER_GROUND )
1490  {
1491  LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
1492  aKPart->AddDrawItem( line2 );
1493  line2->SetWidth( Mils2iu( 10 ) );
1494  line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -100 ) } );
1495  line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -100 ) } );
1496 
1497  LIB_POLYLINE* line3 = new LIB_POLYLINE( aKPart );
1498  aKPart->AddDrawItem( line3 );
1499  line3->SetWidth( Mils2iu( 10 ) );
1500  line3->AddPoint( { Mils2iu( -70 ), Mils2iu( -130 ) } );
1501  line3->AddPoint( { Mils2iu( 70 ), Mils2iu( -130 ) } );
1502 
1503  LIB_POLYLINE* line4 = new LIB_POLYLINE( aKPart );
1504  aKPart->AddDrawItem( line4 );
1505  line4->SetWidth( Mils2iu( 10 ) );
1506  line4->AddPoint( { Mils2iu( -40 ), Mils2iu( -160 ) } );
1507  line4->AddPoint( { Mils2iu( 40 ), Mils2iu( -160 ) } );
1508 
1509  LIB_POLYLINE* line5 = new LIB_POLYLINE( aKPart );
1510  aKPart->AddDrawItem( line5 );
1511  line5->SetWidth( Mils2iu( 10 ) );
1512  line5->AddPoint( { Mils2iu( -10 ), Mils2iu( -190 ) } );
1513  line5->AddPoint( { Mils2iu( 10 ), Mils2iu( -190 ) } );
1514  }
1515  else if( aStyle == ASCH_POWER_PORT_STYLE::SIGNAL_GROUND )
1516  {
1517  LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
1518  aKPart->AddDrawItem( line2 );
1519  line2->SetWidth( Mils2iu( 10 ) );
1520  line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -100 ) } );
1521  line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -100 ) } );
1522  line2->AddPoint( { Mils2iu( 0 ), Mils2iu( -200 ) } );
1523  line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -100 ) } );
1524  }
1525  else if( aStyle == ASCH_POWER_PORT_STYLE::EARTH )
1526  {
1527  LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
1528  aKPart->AddDrawItem( line2 );
1529  line2->SetWidth( Mils2iu( 10 ) );
1530  line2->AddPoint( { Mils2iu( -150 ), Mils2iu( -200 ) } );
1531  line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -100 ) } );
1532  line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -100 ) } );
1533  line2->AddPoint( { Mils2iu( 50 ), Mils2iu( -200 ) } );
1534 
1535  LIB_POLYLINE* line3 = new LIB_POLYLINE( aKPart );
1536  aKPart->AddDrawItem( line3 );
1537  line3->SetWidth( Mils2iu( 10 ) );
1538  line3->AddPoint( { Mils2iu( 0 ), Mils2iu( -100 ) } );
1539  line3->AddPoint( { Mils2iu( -50 ), Mils2iu( -200 ) } );
1540  }
1541  else // ASCH_POWER_PORT_STYLE::GOST_ARROW
1542  {
1543  LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
1544  aKPart->AddDrawItem( line2 );
1545  line2->SetWidth( Mils2iu( 10 ) );
1546  line2->AddPoint( { Mils2iu( -25 ), Mils2iu( -50 ) } );
1547  line2->AddPoint( { Mils2iu( 0 ), Mils2iu( -100 ) } );
1548  line2->AddPoint( { Mils2iu( 25 ), Mils2iu( -50 ) } );
1549 
1550  return { 0, Mils2iu( 150 ) }; // special case
1551  }
1552 
1553  return { 0, Mils2iu( 250 ) };
1554  }
1555  else if( aStyle == ASCH_POWER_PORT_STYLE::GOST_POWER_GROUND
1556  || aStyle == ASCH_POWER_PORT_STYLE::GOST_EARTH )
1557  {
1558  LIB_POLYLINE* line1 = new LIB_POLYLINE( aKPart );
1559  aKPart->AddDrawItem( line1 );
1560  line1->SetWidth( Mils2iu( 10 ) );
1561  line1->AddPoint( { 0, 0 } );
1562  line1->AddPoint( { 0, Mils2iu( -160 ) } );
1563 
1564  LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
1565  aKPart->AddDrawItem( line2 );
1566  line2->SetWidth( Mils2iu( 10 ) );
1567  line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -160 ) } );
1568  line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -160 ) } );
1569 
1570  LIB_POLYLINE* line3 = new LIB_POLYLINE( aKPart );
1571  aKPart->AddDrawItem( line3 );
1572  line3->SetWidth( Mils2iu( 10 ) );
1573  line3->AddPoint( { Mils2iu( -60 ), Mils2iu( -200 ) } );
1574  line3->AddPoint( { Mils2iu( 60 ), Mils2iu( -200 ) } );
1575 
1576  LIB_POLYLINE* line4 = new LIB_POLYLINE( aKPart );
1577  aKPart->AddDrawItem( line4 );
1578  line4->SetWidth( Mils2iu( 10 ) );
1579  line4->AddPoint( { Mils2iu( -20 ), Mils2iu( -240 ) } );
1580  line4->AddPoint( { Mils2iu( 20 ), Mils2iu( -240 ) } );
1581 
1583  return { 0, Mils2iu( 300 ) };
1584 
1585  LIB_CIRCLE* circle = new LIB_CIRCLE( aKPart );
1586  aKPart->AddDrawItem( circle );
1587  circle->SetWidth( Mils2iu( 10 ) );
1588  circle->SetRadius( Mils2iu( 120 ) );
1589  circle->SetPosition( { Mils2iu( 0 ), Mils2iu( -160 ) } );
1590 
1591  return { 0, Mils2iu( 350 ) };
1592  }
1593  else if( aStyle == ASCH_POWER_PORT_STYLE::GOST_BAR )
1594  {
1595  LIB_POLYLINE* line1 = new LIB_POLYLINE( aKPart );
1596  aKPart->AddDrawItem( line1 );
1597  line1->SetWidth( Mils2iu( 10 ) );
1598  line1->AddPoint( { 0, 0 } );
1599  line1->AddPoint( { 0, Mils2iu( -200 ) } );
1600 
1601  LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
1602  aKPart->AddDrawItem( line2 );
1603  line2->SetWidth( Mils2iu( 10 ) );
1604  line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -200 ) } );
1605  line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -200 ) } );
1606 
1607  return { 0, Mils2iu( 250 ) };
1608  }
1609  else
1610  {
1611  if( aStyle != ASCH_POWER_PORT_STYLE::BAR )
1612  {
1613  aReporter->Report( _( "Power Port has unknown style, use bar instead." ),
1615  }
1616 
1617  LIB_POLYLINE* line1 = new LIB_POLYLINE( aKPart );
1618  aKPart->AddDrawItem( line1 );
1619  line1->SetWidth( Mils2iu( 10 ) );
1620  line1->AddPoint( { 0, 0 } );
1621  line1->AddPoint( { 0, Mils2iu( -100 ) } );
1622 
1623  LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
1624  aKPart->AddDrawItem( line2 );
1625  line2->SetWidth( Mils2iu( 10 ) );
1626  line2->AddPoint( { Mils2iu( -50 ), Mils2iu( -100 ) } );
1627  line2->AddPoint( { Mils2iu( 50 ), Mils2iu( -100 ) } );
1628 
1629  return { 0, Mils2iu( 150 ) };
1630  }
1631 }
void SetWidth(int aWidth) override
Definition: lib_polyline.h:97
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void AddDrawItem(LIB_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
Definition: lib_symbol.cpp:655
void SetRadius(int aRadius)
Definition: lib_circle.h:83
void AddPoint(const wxPoint &aPoint)
#define _(s)
Definition: 3d_actions.cpp:33
void SetWidth(int aWidth) override
Definition: lib_circle.h:81
void SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:213
void SetWidth(int aWidth) override
Definition: lib_bezier.h:83
void AddPoint(const wxPoint &aPoint)
Definition: lib_bezier.h:54
Define a bezier curve graphic body item.
Definition: lib_bezier.h:34

References _, LIB_PART::AddDrawItem(), LIB_POLYLINE::AddPoint(), LIB_BEZIER::AddPoint(), ARROW, BAR, CIRCLE, EARTH, GOST_ARROW, GOST_BAR, GOST_EARTH, GOST_POWER_GROUND, POWER_GROUND, REPORTER::Report(), RPT_SEVERITY_WARNING, LIB_ITEM::SetPosition(), LIB_CIRCLE::SetRadius(), LIB_CIRCLE::SetWidth(), LIB_BEZIER::SetWidth(), LIB_POLYLINE::SetWidth(), SIGNAL_GROUND, and WAVE.

Referenced by SCH_ALTIUM_PLUGIN::ParsePowerPort().

◆ SetEdaTextJustification()

void SetEdaTextJustification ( EDA_TEXT text,
ASCH_LABEL_JUSTIFICATION  justification 
)

Definition at line 728 of file sch_altium_plugin.cpp.

729 {
730  switch( justification )
731  {
732  default:
738  break;
743  break;
748  break;
749  }
750 
751  switch( justification )
752  {
753  default:
759  break;
764  break;
769  break;
770  }
771 }

References BOTTOM_CENTER, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER_CENTER, CENTER_LEFT, CENTER_RIGHT, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, text, TOP_CENTER, TOP_LEFT, TOP_RIGHT, and UNKNOWN.

Referenced by SCH_ALTIUM_PLUGIN::ParseLabel().

◆ SetFieldOrientation()

void SetFieldOrientation ( SCH_FIELD aField,
ASCH_RECORD_ORIENTATION  aOrientation 
)

Definition at line 2068 of file sch_altium_plugin.cpp.

2069 {
2070  switch( aOrientation )
2071  {
2072  default:
2074  aField.SetTextAngle( 0 );
2075  break;
2077  aField.SetTextAngle( 900 );
2078  break;
2080  aField.SetTextAngle( 1800 );
2081  break;
2083  aField.SetTextAngle( 2700 );
2084  break;
2085  }
2086 }
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:174

References DOWNWARDS, LEFTWARDS, RIGHTWARDS, EDA_TEXT::SetTextAngle(), and UPWARDS.

Referenced by SCH_ALTIUM_PLUGIN::ParseDesignator(), SCH_ALTIUM_PLUGIN::ParseFileName(), and SCH_ALTIUM_PLUGIN::ParseSheetName().