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_shape.h>
#include <lib_id.h>
#include <lib_item.h>
#include <lib_pin.h>
#include <lib_text.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 <string_utils.h>
#include <sch_edit_frame.h>
#include <trigo.h>
#include <wildcards_and_files_ext.h>
#include <wx/mstream.h>
#include <wx/log.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_SYMBOL *aSymbol)
 
COLOR4D GetColorFromInt (int color)
 
void SetTextPositioning (EDA_TEXT *text, ASCH_LABEL_JUSTIFICATION justification, ASCH_RECORD_ORIENTATION orientation)
 
wxPoint HelperGeneratePowerPortGraphics (LIB_SYMBOL *aKsymbol, ASCH_POWER_PORT_STYLE aStyle, REPORTER *aReporter)
 

Function Documentation

◆ GetColorFromInt()

COLOR4D GetColorFromInt ( int  color)

Definition at line 70 of file sch_altium_plugin.cpp.

71 {
72  int red = color & 0x0000FF;
73  int green = ( color & 0x00FF00 ) >> 8;
74  int blue = ( color & 0xFF0000 ) >> 16;
75 
76  return COLOR4D().FromCSSRGBA( red, green, blue, 1.0 );
77 }
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:558
int color
Definition: DXF_plotter.cpp:57
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

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

Referenced by SCH_ALTIUM_PLUGIN::ParseSheetSymbol().

◆ GetRelativePosition()

const wxPoint GetRelativePosition ( const wxPoint &  aPosition,
const SCH_SYMBOL aSymbol 
)

Definition at line 63 of file sch_altium_plugin.cpp.

64 {
65  TRANSFORM t = aSymbol->GetTransform().InverseTransform();
66  return t.TransformCoordinate( aPosition - aSymbol->GetPosition() );
67 }
TRANSFORM InverseTransform() const
Calculate the Inverse mirror/rotation transform.
Definition: transform.cpp:57
TRANSFORM & GetTransform()
Definition: sch_symbol.h:232
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
wxPoint GetPosition() const override
Definition: sch_symbol.h:645

References SCH_SYMBOL::GetPosition(), SCH_SYMBOL::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_SYMBOL aKsymbol,
ASCH_POWER_PORT_STYLE  aStyle,
REPORTER aReporter 
)

Definition at line 1602 of file sch_altium_plugin.cpp.

1604 {
1605  if( aStyle == ASCH_POWER_PORT_STYLE::CIRCLE || aStyle == ASCH_POWER_PORT_STYLE::ARROW )
1606  {
1607  LIB_SHAPE* line1 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1608  aKsymbol->AddDrawItem( line1 );
1609  line1->SetWidth( Mils2iu( 10 ) );
1610  line1->AddPoint( { 0, 0 } );
1611  line1->AddPoint( { 0, Mils2iu( -50 ) } );
1612 
1613  if( aStyle == ASCH_POWER_PORT_STYLE::CIRCLE )
1614  {
1615  LIB_SHAPE* circle = new LIB_SHAPE( aKsymbol, SHAPE_T::CIRCLE );
1616  aKsymbol->AddDrawItem( circle );
1617  circle->SetWidth( Mils2iu( 5 ) );
1618  circle->SetPosition( { Mils2iu( 0 ), Mils2iu( -75 ) } );
1619  circle->SetEnd( circle->GetPosition() + wxPoint( Mils2iu( 25 ), 0 ) );
1620  }
1621  else
1622  {
1623  LIB_SHAPE* line2 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1624  aKsymbol->AddDrawItem( line2 );
1625  line2->SetWidth( Mils2iu( 10 ) );
1626  line2->AddPoint( { Mils2iu( -25 ), Mils2iu( -50 ) } );
1627  line2->AddPoint( { Mils2iu( 25 ), Mils2iu( -50 ) } );
1628  line2->AddPoint( { Mils2iu( 0 ), Mils2iu( -100 ) } );
1629  line2->AddPoint( { Mils2iu( -25 ), Mils2iu( -50 ) } );
1630  }
1631 
1632  return { 0, Mils2iu( 150 ) };
1633  }
1634  else if( aStyle == ASCH_POWER_PORT_STYLE::WAVE )
1635  {
1636  LIB_SHAPE* line = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1637  aKsymbol->AddDrawItem( line );
1638  line->SetWidth( Mils2iu( 10 ) );
1639  line->AddPoint( { 0, 0 } );
1640  line->AddPoint( { 0, Mils2iu( -72 ) } );
1641 
1642  LIB_SHAPE* bezier = new LIB_SHAPE( aKsymbol, SHAPE_T::BEZIER );
1643  aKsymbol->AddDrawItem( bezier );
1644  bezier->SetWidth( Mils2iu( 5 ) );
1645  bezier->AddPoint( { Mils2iu( 30 ), Mils2iu( -50 ) } );
1646  bezier->AddPoint( { Mils2iu( 30 ), Mils2iu( -87 ) } );
1647  bezier->AddPoint( { Mils2iu( -30 ), Mils2iu( -63 ) } );
1648  bezier->AddPoint( { Mils2iu( -30 ), Mils2iu( -100 ) } );
1649 
1650  return { 0, Mils2iu( 150 ) };
1651  }
1652  else if( aStyle == ASCH_POWER_PORT_STYLE::POWER_GROUND
1654  || aStyle == ASCH_POWER_PORT_STYLE::EARTH
1655  || aStyle == ASCH_POWER_PORT_STYLE::GOST_ARROW )
1656  {
1657  LIB_SHAPE* line1 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1658  aKsymbol->AddDrawItem( line1 );
1659  line1->SetWidth( Mils2iu( 10 ) );
1660  line1->AddPoint( { 0, 0 } );
1661  line1->AddPoint( { 0, Mils2iu( -100 ) } );
1662 
1663  if( aStyle == ASCH_POWER_PORT_STYLE::POWER_GROUND )
1664  {
1665  LIB_SHAPE* line2 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1666  aKsymbol->AddDrawItem( line2 );
1667  line2->SetWidth( Mils2iu( 10 ) );
1668  line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -100 ) } );
1669  line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -100 ) } );
1670 
1671  LIB_SHAPE* line3 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1672  aKsymbol->AddDrawItem( line3 );
1673  line3->SetWidth( Mils2iu( 10 ) );
1674  line3->AddPoint( { Mils2iu( -70 ), Mils2iu( -130 ) } );
1675  line3->AddPoint( { Mils2iu( 70 ), Mils2iu( -130 ) } );
1676 
1677  LIB_SHAPE* line4 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1678  aKsymbol->AddDrawItem( line4 );
1679  line4->SetWidth( Mils2iu( 10 ) );
1680  line4->AddPoint( { Mils2iu( -40 ), Mils2iu( -160 ) } );
1681  line4->AddPoint( { Mils2iu( 40 ), Mils2iu( -160 ) } );
1682 
1683  LIB_SHAPE* line5 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1684  aKsymbol->AddDrawItem( line5 );
1685  line5->SetWidth( Mils2iu( 10 ) );
1686  line5->AddPoint( { Mils2iu( -10 ), Mils2iu( -190 ) } );
1687  line5->AddPoint( { Mils2iu( 10 ), Mils2iu( -190 ) } );
1688  }
1689  else if( aStyle == ASCH_POWER_PORT_STYLE::SIGNAL_GROUND )
1690  {
1691  LIB_SHAPE* line2 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1692  aKsymbol->AddDrawItem( line2 );
1693  line2->SetWidth( Mils2iu( 10 ) );
1694  line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -100 ) } );
1695  line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -100 ) } );
1696  line2->AddPoint( { Mils2iu( 0 ), Mils2iu( -200 ) } );
1697  line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -100 ) } );
1698  }
1699  else if( aStyle == ASCH_POWER_PORT_STYLE::EARTH )
1700  {
1701  LIB_SHAPE* line2 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1702  aKsymbol->AddDrawItem( line2 );
1703  line2->SetWidth( Mils2iu( 10 ) );
1704  line2->AddPoint( { Mils2iu( -150 ), Mils2iu( -200 ) } );
1705  line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -100 ) } );
1706  line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -100 ) } );
1707  line2->AddPoint( { Mils2iu( 50 ), Mils2iu( -200 ) } );
1708 
1709  LIB_SHAPE* line3 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1710  aKsymbol->AddDrawItem( line3 );
1711  line3->SetWidth( Mils2iu( 10 ) );
1712  line3->AddPoint( { Mils2iu( 0 ), Mils2iu( -100 ) } );
1713  line3->AddPoint( { Mils2iu( -50 ), Mils2iu( -200 ) } );
1714  }
1715  else // ASCH_POWER_PORT_STYLE::GOST_ARROW
1716  {
1717  LIB_SHAPE* line2 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1718  aKsymbol->AddDrawItem( line2 );
1719  line2->SetWidth( Mils2iu( 10 ) );
1720  line2->AddPoint( { Mils2iu( -25 ), Mils2iu( -50 ) } );
1721  line2->AddPoint( { Mils2iu( 0 ), Mils2iu( -100 ) } );
1722  line2->AddPoint( { Mils2iu( 25 ), Mils2iu( -50 ) } );
1723 
1724  return { 0, Mils2iu( 150 ) }; // special case
1725  }
1726 
1727  return { 0, Mils2iu( 250 ) };
1728  }
1729  else if( aStyle == ASCH_POWER_PORT_STYLE::GOST_POWER_GROUND
1730  || aStyle == ASCH_POWER_PORT_STYLE::GOST_EARTH )
1731  {
1732  LIB_SHAPE* line1 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1733  aKsymbol->AddDrawItem( line1 );
1734  line1->SetWidth( Mils2iu( 10 ) );
1735  line1->AddPoint( { 0, 0 } );
1736  line1->AddPoint( { 0, Mils2iu( -160 ) } );
1737 
1738  LIB_SHAPE* line2 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1739  aKsymbol->AddDrawItem( line2 );
1740  line2->SetWidth( Mils2iu( 10 ) );
1741  line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -160 ) } );
1742  line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -160 ) } );
1743 
1744  LIB_SHAPE* line3 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1745  aKsymbol->AddDrawItem( line3 );
1746  line3->SetWidth( Mils2iu( 10 ) );
1747  line3->AddPoint( { Mils2iu( -60 ), Mils2iu( -200 ) } );
1748  line3->AddPoint( { Mils2iu( 60 ), Mils2iu( -200 ) } );
1749 
1750  LIB_SHAPE* line4 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1751  aKsymbol->AddDrawItem( line4 );
1752  line4->SetWidth( Mils2iu( 10 ) );
1753  line4->AddPoint( { Mils2iu( -20 ), Mils2iu( -240 ) } );
1754  line4->AddPoint( { Mils2iu( 20 ), Mils2iu( -240 ) } );
1755 
1757  return { 0, Mils2iu( 300 ) };
1758 
1759  LIB_SHAPE* circle = new LIB_SHAPE( aKsymbol, SHAPE_T::CIRCLE );
1760  aKsymbol->AddDrawItem( circle );
1761  circle->SetWidth( Mils2iu( 10 ) );
1762  circle->SetPosition( { Mils2iu( 0 ), Mils2iu( -160 ) } );
1763  circle->SetEnd( circle->GetPosition() + wxPoint( Mils2iu( 120 ), 0 ) );
1764 
1765  return { 0, Mils2iu( 350 ) };
1766  }
1767  else if( aStyle == ASCH_POWER_PORT_STYLE::GOST_BAR )
1768  {
1769  LIB_SHAPE* line1 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1770  aKsymbol->AddDrawItem( line1 );
1771  line1->SetWidth( Mils2iu( 10 ) );
1772  line1->AddPoint( { 0, 0 } );
1773  line1->AddPoint( { 0, Mils2iu( -200 ) } );
1774 
1775  LIB_SHAPE* line2 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1776  aKsymbol->AddDrawItem( line2 );
1777  line2->SetWidth( Mils2iu( 10 ) );
1778  line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -200 ) } );
1779  line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -200 ) } );
1780 
1781  return { 0, Mils2iu( 250 ) };
1782  }
1783  else
1784  {
1785  if( aStyle != ASCH_POWER_PORT_STYLE::BAR )
1786  {
1787  aReporter->Report( _( "Power Port has unknown style, use bar instead." ),
1789  }
1790 
1791  LIB_SHAPE* line1 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1792  aKsymbol->AddDrawItem( line1 );
1793  line1->SetWidth( Mils2iu( 10 ) );
1794  line1->AddPoint( { 0, 0 } );
1795  line1->AddPoint( { 0, Mils2iu( -100 ) } );
1796 
1797  LIB_SHAPE* line2 = new LIB_SHAPE( aKsymbol, SHAPE_T::POLY );
1798  aKsymbol->AddDrawItem( line2 );
1799  line2->SetWidth( Mils2iu( 10 ) );
1800  line2->AddPoint( { Mils2iu( -50 ), Mils2iu( -100 ) } );
1801  line2->AddPoint( { Mils2iu( 50 ), Mils2iu( -100 ) } );
1802 
1803  return { 0, Mils2iu( 150 ) };
1804  }
1805 }
void AddPoint(const wxPoint &aPosition)
Definition: lib_shape.cpp:414
void SetEnd(const wxPoint &aEnd)
Definition: eda_shape.h:135
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void SetPosition(const wxPoint &aPosition) override
Definition: lib_shape.h:88
#define _(s)
void SetWidth(int aWidth)
Definition: eda_shape.h:97
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:716
wxPoint GetPosition() const override
Definition: lib_shape.h:87

References _, LIB_SYMBOL::AddDrawItem(), LIB_SHAPE::AddPoint(), ARROW, BAR, BEZIER, CIRCLE, EARTH, LIB_SHAPE::GetPosition(), GOST_ARROW, GOST_BAR, GOST_EARTH, GOST_POWER_GROUND, POLY, POWER_GROUND, REPORTER::Report(), RPT_SEVERITY_WARNING, EDA_SHAPE::SetEnd(), LIB_SHAPE::SetPosition(), EDA_SHAPE::SetWidth(), SIGNAL_GROUND, and WAVE.

Referenced by SCH_ALTIUM_PLUGIN::ParsePowerPort().

◆ SetTextPositioning()

void SetTextPositioning ( EDA_TEXT text,
ASCH_LABEL_JUSTIFICATION  justification,
ASCH_RECORD_ORIENTATION  orientation 
)

Definition at line 743 of file sch_altium_plugin.cpp.

745 {
746  int vjustify, hjustify;
747  double angle = TEXT_ANGLE_HORIZ;
748 
749  switch( justification )
750  {
751  default:
757  break;
762  break;
767  break;
768  }
769 
770  switch( justification )
771  {
772  default:
778  break;
783  break;
788  break;
789  }
790 
791  switch( orientation )
792  {
795  break;
797  vjustify *= -1;
798  hjustify *= -1;
800  break;
803  break;
805  vjustify *= -1;
806  hjustify *= -1;
808  break;
809  }
810 
811  text->SetVertJustify( static_cast<EDA_TEXT_VJUSTIFY_T>( vjustify ) );
812  text->SetHorizJustify( static_cast<EDA_TEXT_HJUSTIFY_T>( hjustify ) );
813  text->SetTextAngle( angle );
814 }
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: eda_text.h:71
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
#define TEXT_ANGLE_VERT
Definition: eda_text.h:72

References PNS::angle(), BOTTOM_CENTER, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER_CENTER, CENTER_LEFT, CENTER_RIGHT, DOWNWARDS, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, LEFTWARDS, RIGHTWARDS, text, TEXT_ANGLE_HORIZ, TEXT_ANGLE_VERT, TOP_CENTER, TOP_LEFT, TOP_RIGHT, UNKNOWN, and UPWARDS.

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