KiCad PCB EDA Suite
SCH_ALTIUM_PLUGIN Class Reference

SCH_ALTIUM_PLUGIN is a SCH_PLUGIN derivation for loading Altium .SchDoc schematic files. More...

#include <sch_altium_plugin.h>

Inheritance diagram for SCH_ALTIUM_PLUGIN:
SCH_PLUGIN

Public Member Functions

 SCH_ALTIUM_PLUGIN ()
 
 ~SCH_ALTIUM_PLUGIN ()
 
const wxString GetName () const override
 Return a brief hard coded name for this SCH_PLUGIN. More...
 
void SetReporter (REPORTER *aReporter) override
 Set an optional reporter for warnings/errors. More...
 
const wxString GetFileExtension () const override
 Return the file extension for the SCH_PLUGIN. More...
 
const wxString GetLibraryFileExtension () const override
 Return the library file extension for the SCH_PLUGIN object. More...
 
int GetModifyHash () const override
 Return the modification hash from the library cache. More...
 
SCH_SHEETLoad (const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr) override
 Load information from some input file format that this SCH_PLUGIN implementation knows about, into either a new SCH_SHEET or an existing one. More...
 
bool CheckHeader (const wxString &aFileName) override
 Return true if the first line in aFileName begins with the expected header. More...
 
wxString getLibName ()
 
wxFileName getLibFileName ()
 
void ParseAltiumSch (const wxString &aFileName)
 
void ParseStorage (const CFB::CompoundFileReader &aReader)
 
void ParseFileHeader (const CFB::CompoundFileReader &aReader)
 
virtual void SetProgressReporter (PROGRESS_REPORTER *aReporter)
 Set an optional progress reporter. More...
 
virtual void SaveLibrary (const wxString &aFileName, const PROPERTIES *aProperties=nullptr)
 
virtual void Save (const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
 Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about, or it can be used to write a portion of aSchematic to a special kind of export file. More...
 
virtual void EnumerateSymbolLib (wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
 Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath. More...
 
virtual void EnumerateSymbolLib (std::vector< LIB_SYMBOL * > &aSymbolList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
 Populate a list of LIB_SYMBOL aliases contained within the library aLibraryPath. More...
 
virtual LIB_SYMBOLLoadSymbol (const wxString &aLibraryPath, const wxString &aPartName, const PROPERTIES *aProperties=nullptr)
 Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this SCH_PLUGIN knows about. More...
 
virtual void SaveSymbol (const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const PROPERTIES *aProperties=nullptr)
 Write aSymbol to an existing library located at aLibraryPath. More...
 
virtual void DeleteSymbol (const wxString &aLibraryPath, const wxString &aSymbolName, const PROPERTIES *aProperties=nullptr)
 Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath. More...
 
virtual void CreateSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
 Create a new empty symbol library at aLibraryPath. More...
 
virtual bool DeleteSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
 Delete an existing symbol library and returns true if successful, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason. More...
 
virtual bool IsSymbolLibWritable (const wxString &aLibraryPath)
 Return true if the library at aLibraryPath is writable. More...
 
virtual void SymbolLibOptions (PROPERTIES *aListToAppendTo) const
 Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 
virtual const wxString & GetError () const
 Return an error string to the caller. More...
 

Private Member Functions

bool IsComponentPartVisible (int aOwnerindex, int aOwnerpartdisplaymode) const
 
const ASCH_STORAGE_FILEGetFileFromStorage (const wxString &aFilename) const
 
void ParseComponent (int aIndex, const std::map< wxString, wxString > &aProperties)
 
void ParsePin (const std::map< wxString, wxString > &aProperties)
 
void ParseLabel (const std::map< wxString, wxString > &aProperties)
 
void ParseTextFrame (const std::map< wxString, wxString > &aProperties)
 
void ParseNote (const std::map< wxString, wxString > &aProperties)
 
void ParseBezier (const std::map< wxString, wxString > &aProperties)
 
void ParsePolyline (const std::map< wxString, wxString > &aProperties)
 
void ParsePolygon (const std::map< wxString, wxString > &aProperties)
 
void ParseRoundRectangle (const std::map< wxString, wxString > &aProperties)
 
void ParseArc (const std::map< wxString, wxString > &aProperties)
 
void ParseLine (const std::map< wxString, wxString > &aProperties)
 
void ParseRectangle (const std::map< wxString, wxString > &aProperties)
 
void ParseSheetSymbol (int aIndex, const std::map< wxString, wxString > &aProperties)
 
void ParseSheetEntry (const std::map< wxString, wxString > &aProperties)
 
void ParsePowerPort (const std::map< wxString, wxString > &aProperties)
 
void ParsePort (const ASCH_PORT &aElem)
 
void ParseNoERC (const std::map< wxString, wxString > &aProperties)
 
void ParseNetLabel (const std::map< wxString, wxString > &aProperties)
 
void ParseBus (const std::map< wxString, wxString > &aProperties)
 
void ParseWire (const std::map< wxString, wxString > &aProperties)
 
void ParseJunction (const std::map< wxString, wxString > &aProperties)
 
void ParseImage (const std::map< wxString, wxString > &aProperties)
 
void ParseSheet (const std::map< wxString, wxString > &aProperties)
 
void ParseSheetName (const std::map< wxString, wxString > &aProperties)
 
void ParseFileName (const std::map< wxString, wxString > &aProperties)
 
void ParseDesignator (const std::map< wxString, wxString > &aProperties)
 
void ParseBusEntry (const std::map< wxString, wxString > &aProperties)
 
void ParseParameter (const std::map< wxString, wxString > &aProperties)
 
void ParseImplementationList (int aIndex, const std::map< wxString, wxString > &aProperties)
 
void ParseImplementation (const std::map< wxString, wxString > &aProperties)
 

Private Attributes

REPORTERm_reporter
 
SCH_SHEETm_rootSheet
 
SCH_SHEETm_currentSheet
 
SCHEMATICm_schematic
 
wxString m_libName
 
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
 
std::unique_ptr< PROPERTIESm_properties
 
std::unique_ptr< TITLE_BLOCKm_currentTitleBlock
 
wxPoint m_sheetOffset
 
std::unique_ptr< ASCH_SHEETm_altiumSheet
 
std::map< int, SCH_SYMBOL * > m_symbols
 
std::map< int, SCH_SHEET * > m_sheets
 
std::map< int, LIB_SYMBOL * > m_libSymbols
 
std::map< wxString, LIB_SYMBOL * > m_powerSymbols
 
std::vector< ASCH_STORAGE_FILEm_altiumStorage
 
std::map< int, ASCH_SYMBOLm_altiumComponents
 
std::map< int, int > m_altiumImplementationList
 
std::vector< ASCH_PORTm_altiumPortsCurrentSheet
 

Detailed Description

SCH_ALTIUM_PLUGIN is a SCH_PLUGIN derivation for loading Altium .SchDoc schematic files.

As with all SCH_PLUGINs there is no UI dependencies i.e. windowing calls allowed.

Definition at line 51 of file sch_altium_plugin.h.

Constructor & Destructor Documentation

◆ SCH_ALTIUM_PLUGIN()

SCH_ALTIUM_PLUGIN::SCH_ALTIUM_PLUGIN ( )

Definition at line 79 of file sch_altium_plugin.cpp.

80 {
81  m_rootSheet = nullptr;
82  m_currentSheet = nullptr;
83  m_schematic = nullptr;
84 
86 }
static REPORTER & GetInstance()
Definition: reporter.cpp:175
SCH_SHEET * m_currentSheet

References WXLOG_REPORTER::GetInstance(), m_currentSheet, m_reporter, m_rootSheet, and m_schematic.

◆ ~SCH_ALTIUM_PLUGIN()

SCH_ALTIUM_PLUGIN::~SCH_ALTIUM_PLUGIN ( )

Definition at line 89 of file sch_altium_plugin.cpp.

90 {
91 }

Member Function Documentation

◆ CheckHeader()

bool SCH_ALTIUM_PLUGIN::CheckHeader ( const wxString &  aFileName)
overridevirtual

Return true if the first line in aFileName begins with the expected header.

Parameters
aFileNameis the name of the file to use as input

Reimplemented from SCH_PLUGIN.

Definition at line 118 of file sch_altium_plugin.cpp.

119 {
120  // TODO
121 
122  return true;
123 }

◆ CreateSymbolLib()

void SCH_PLUGIN::CreateSymbolLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Create a new empty symbol library at aLibraryPath.

It is an error to attempt to create an existing library or to attempt to create on a "read only" location.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aPropertiesis an associative array that can be used to tell the library create function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem finding the library, or creating it.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 110 of file sch_plugin.cpp.

111 {
112  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
113  not_implemented( this, __FUNCTION__ );
114 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

◆ DeleteSymbol()

void SCH_PLUGIN::DeleteSymbol ( const wxString &  aLibraryPath,
const wxString &  aSymbolName,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
aSymbolNameis the name of a LIB_SYMBOL associated with it's root LIB_SYMBOL object to delete from the specified library.
aPropertiesis an associative array that can be used to tell the library delete function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem finding the alias or the library or deleting it.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 102 of file sch_plugin.cpp.

104 {
105  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
106  not_implemented( this, __FUNCTION__ );
107 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

Referenced by SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer().

◆ DeleteSymbolLib()

bool SCH_PLUGIN::DeleteSymbolLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Delete an existing symbol library and returns true if successful, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason.

Parameters
aLibraryPathis a locator for the "library", usually a directory or file which will contain symbols.
aPropertiesis an associative array that can be used to tell the library delete implementation function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
true if library deleted or false if library did not exist.
Exceptions
IO_ERRORif there is a problem deleting an existing library.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 117 of file sch_plugin.cpp.

118 {
119  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
120  not_implemented( this, __FUNCTION__ );
121  return false;
122 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

◆ EnumerateSymbolLib() [1/2]

void SCH_PLUGIN::EnumerateSymbolLib ( wxArrayString &  aSymbolNameList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.

Parameters
aSymbolNameListis an array to populate with the LIB_SYMBOL names associated with the library.
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing one or more LIB_SYMBOL objects.
aPropertiesis an associative array that can be used to tell the plugin anything needed about how to perform with respect to aLibraryPath. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif the library cannot be found, the part library cannot be loaded.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 67 of file sch_plugin.cpp.

70 {
71  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
72  not_implemented( this, __FUNCTION__ );
73 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

◆ EnumerateSymbolLib() [2/2]

void SCH_PLUGIN::EnumerateSymbolLib ( std::vector< LIB_SYMBOL * > &  aSymbolList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Populate a list of LIB_SYMBOL aliases contained within the library aLibraryPath.

Note
It is the responsibility of the caller to delete the returned object from the heap. Failure to do this will result in memory leaks.
Parameters
aSymbolListis an array to populate with the LIB_SYMBOL pointers associated with the library.
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing one or more LIB_SYMBOL objects.
aPropertiesis an associative array that can be used to tell the plugin anything needed about how to perform with respect to aLibraryPath. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif the library cannot be found, the part library cannot be loaded.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 76 of file sch_plugin.cpp.

79 {
80  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
81  not_implemented( this, __FUNCTION__ );
82 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

◆ GetError()

const wxString & SCH_PLUGIN::GetError ( ) const
virtualinherited

Return an error string to the caller.

This is useful for schematic loaders that can load partial schematics where throwing an exception would be problematic such as the KiCad legacy plugin.

Returns
an unformatted string containing errors if any.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 177 of file sch_plugin.cpp.

178 {
179  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
180  not_implemented( this, __FUNCTION__ );
181  static wxString error;
182  return error;
183 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

Referenced by TEST_SCH_SHEET_LIST_FIXTURE::loadSchematic(), and TEST_NETLISTS_FIXTURE::loadSchematic().

◆ GetFileExtension()

const wxString SCH_ALTIUM_PLUGIN::GetFileExtension ( ) const
overridevirtual

Return the file extension for the SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 100 of file sch_altium_plugin.cpp.

101 {
102  return "SchDoc";
103 }

Referenced by ParseFileName().

◆ GetFileFromStorage()

const ASCH_STORAGE_FILE * SCH_ALTIUM_PLUGIN::GetFileFromStorage ( const wxString &  aFilename) const
private

Definition at line 542 of file sch_altium_plugin.cpp.

543 {
544  const ASCH_STORAGE_FILE* nonExactMatch = nullptr;
545 
546  for( const ASCH_STORAGE_FILE& file : m_altiumStorage )
547  {
548  if( file.filename.IsSameAs( aFilename ) )
549  return &file;
550 
551  if( file.filename.EndsWith( aFilename ) )
552  nonExactMatch = &file;
553  }
554 
555  return nonExactMatch;
556 }
std::vector< ASCH_STORAGE_FILE > m_altiumStorage

References m_altiumStorage.

Referenced by ParseImage().

◆ getLibFileName()

wxFileName SCH_ALTIUM_PLUGIN::getLibFileName ( )

Definition at line 150 of file sch_altium_plugin.cpp.

151 {
153 
154  return fn;
155 }
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:122
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
const std::string KiCadSymbolLibFileExtension

References getLibName(), PROJECT::GetProjectPath(), KiCadSymbolLibFileExtension, m_schematic, and SCHEMATIC::Prj().

Referenced by Load(), ParseFileHeader(), and ParsePowerPort().

◆ getLibName()

wxString SCH_ALTIUM_PLUGIN::getLibName ( )

Definition at line 126 of file sch_altium_plugin.cpp.

127 {
128  if( m_libName.IsEmpty() )
129  {
130  // Try to come up with a meaningful name
132 
133  if( m_libName.IsEmpty() )
134  {
135  wxFileName fn( m_rootSheet->GetFileName() );
136  m_libName = fn.GetName();
137  }
138 
139  if( m_libName.IsEmpty() )
140  m_libName = "noname";
141 
142  m_libName += "-altium-import";
144  }
145 
146  return m_libName;
147 }
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:189
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:317
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:128

References LIB_ID::FixIllegalChars(), SCH_SHEET::GetFileName(), PROJECT::GetProjectName(), m_libName, m_rootSheet, m_schematic, and SCHEMATIC::Prj().

Referenced by getLibFileName(), Load(), ParseComponent(), and ParsePowerPort().

◆ GetLibraryFileExtension()

const wxString SCH_ALTIUM_PLUGIN::GetLibraryFileExtension ( ) const
overridevirtual

Return the library file extension for the SCH_PLUGIN object.

Implements SCH_PLUGIN.

Definition at line 106 of file sch_altium_plugin.cpp.

107 {
108  return "SchLib";
109 }

◆ GetModifyHash()

int SCH_ALTIUM_PLUGIN::GetModifyHash ( ) const
overridevirtual

Return the modification hash from the library cache.

Note
This is temporary until the new s-expr file format is implement. The new file format will embed symbols instead of referencing them from the library. This function can be removed when the new file format is implemented.
Returns
the modification hash of the library cache.

Implements SCH_PLUGIN.

Definition at line 112 of file sch_altium_plugin.cpp.

113 {
114  return 0;
115 }

◆ GetName()

const wxString SCH_ALTIUM_PLUGIN::GetName ( ) const
overridevirtual

Return a brief hard coded name for this SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 94 of file sch_altium_plugin.cpp.

95 {
96  return "Altium";
97 }

◆ IsComponentPartVisible()

bool SCH_ALTIUM_PLUGIN::IsComponentPartVisible ( int  aOwnerindex,
int  aOwnerpartdisplaymode 
) const
private

Definition at line 531 of file sch_altium_plugin.cpp.

532 {
533  const auto& component = m_altiumComponents.find( aOwnerindex );
534 
535  if( component == m_altiumComponents.end() )
536  return false;
537 
538  return component->second.displaymode == aOwnerpartdisplaymode;
539 }
std::map< int, ASCH_SYMBOL > m_altiumComponents

References m_altiumComponents.

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

◆ IsSymbolLibWritable()

bool SCH_PLUGIN::IsSymbolLibWritable ( const wxString &  aLibraryPath)
virtualinherited

Return true if the library at aLibraryPath is writable.

(Often system libraries are read only because of where they are installed.)

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
Exceptions
IO_ERRORif no library at aLibraryPath exists.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 125 of file sch_plugin.cpp.

126 {
127  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
128  not_implemented( this, __FUNCTION__ );
129  return false;
130 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

◆ Load()

SCH_SHEET * SCH_ALTIUM_PLUGIN::Load ( const wxString &  aFileName,
SCHEMATIC aSchematic,
SCH_SHEET aAppendToMe = nullptr,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Load information from some input file format that this SCH_PLUGIN implementation knows about, into either a new SCH_SHEET or an existing one.

This may be used to load an entire new SCH_SHEET, or to augment an existing one if aAppendToMe is not NULL.

Parameters
aFileNameis the name of the file to use as input and may be foreign in nature or native in nature.
aKiwayis the KIWAY object used to access the symbol libraries loaded by the project.
aAppendToMeis an existing SCH_SHEET to append to, but if NULL then this means "do not append, rather load anew".
aPropertiesis an associative array that can be used to tell the loader how to load the file, because it can take any number of additional named arguments that the plugin is known to support. These are tuning parameters for the import or load. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
the successfully loaded schematic, or the same one as aAppendToMe if aAppendToMe was not NULL, and the caller owns it.
Exceptions
IO_ERRORif there is a problem loading, and its contents should say what went wrong, using line number and character offsets of the input file if possible.
Note
No check is being done here to see if the existing symbol library exists so this will overwrite the existing one.

Reimplemented from SCH_PLUGIN.

Definition at line 158 of file sch_altium_plugin.cpp.

160 {
161  wxASSERT( !aFileName || aSchematic != nullptr );
162 
163  wxFileName fileName( aFileName );
164  fileName.SetExt( KiCadSchematicFileExtension );
165  m_schematic = aSchematic;
166 
167  // Delete on exception, if I own m_rootSheet, according to aAppendToMe
168  std::unique_ptr<SCH_SHEET> deleter( aAppendToMe ? nullptr : m_rootSheet );
169 
170  if( aAppendToMe )
171  {
172  wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
173  m_rootSheet = &aSchematic->Root();
174  }
175  else
176  {
177  m_rootSheet = new SCH_SHEET( aSchematic );
178  m_rootSheet->SetFileName( fileName.GetFullPath() );
179 
180  SCH_SHEET_PATH sheetpath;
181  sheetpath.push_back( m_rootSheet );
182 
183  m_rootSheet->AddInstance( sheetpath.Path() );
184  m_rootSheet->SetPageNumber( sheetpath, "#" ); // We'll update later if we find a
185  // pageNumber record for it
186  }
187 
188  if( !m_rootSheet->GetScreen() )
189  {
190  SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
191  screen->SetFileName( aFileName );
192  m_rootSheet->SetScreen( screen );
193  }
194 
195  SYMBOL_LIB_TABLE* libTable = m_schematic->Prj().SchSymbolLibTable();
196 
197  wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." );
198 
199  m_pi.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
200 
203  if( !libTable->HasLibrary( getLibName() ) )
204  {
205  // Create a new empty symbol library.
206  m_pi->CreateSymbolLib( getLibFileName().GetFullPath() );
207  wxString libTableUri = "${KIPRJMOD}/" + getLibFileName().GetFullName();
208 
209  // Add the new library to the project symbol library table.
210  libTable->InsertRow( new SYMBOL_LIB_TABLE_ROW( getLibName(), libTableUri,
211  wxString( "KiCad" ) ) );
212 
213  // Save project symbol library table.
214  wxFileName fn( m_schematic->Prj().GetProjectPath(),
216 
217  // So output formatter goes out of scope and closes the file before reloading.
218  {
219  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
220  libTable->Format( &formatter, 0 );
221  }
222 
223  // Reload the symbol library table.
225  m_schematic->Prj().SchSymbolLibTable();
226  }
227 
229  ParseAltiumSch( aFileName );
230 
231  m_pi->SaveLibrary( getLibFileName().GetFullPath() );
232 
233  SCH_SCREENS allSheets( m_rootSheet );
234  allSheets.UpdateSymbolLinks(); // Update all symbol library links for all sheets.
235  allSheets.ClearEditFlags();
236 
237  return m_rootSheet;
238 }
static const wxString & GetSymbolLibTableFileName()
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
void SetFileName(const wxString &aFilename)
Definition: sch_sheet.h:323
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:172
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:108
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:507
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:122
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1166
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:258
wxFileName getLibFileName()
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
SCH_SHEET * m_currentSheet
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
SCH_SHEET & Root() const
Definition: schematic.h:92
const std::string KiCadSchematicFileExtension
Used for text file output.
Definition: richio.h:456
void ParseAltiumSch(const wxString &aFileName)
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:110
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:593
bool AddInstance(const KIID_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1124

References SCH_SHEET::AddInstance(), SCH_SCREENS::ClearEditFlags(), PROJECT::ELEM_SYMBOL_LIB_TABLE, SYMBOL_LIB_TABLE::Format(), getLibFileName(), getLibName(), PROJECT::GetProjectPath(), SCH_SHEET::GetScreen(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName(), LIB_TABLE::HasLibrary(), LIB_TABLE::InsertRow(), SCHEMATIC::IsValid(), KiCadSchematicFileExtension, m_currentSheet, m_pi, m_rootSheet, m_schematic, ParseAltiumSch(), SCH_SHEET_PATH::Path(), SCHEMATIC::Prj(), SCH_SHEET_PATH::push_back(), SCHEMATIC::Root(), SCH_PLUGIN::SCH_PLUGIN_RELEASER::set(), PROJECT::SetElem(), SCH_SCREEN::SetFileName(), SCH_SHEET::SetFileName(), SCH_SHEET::SetPageNumber(), SCH_SHEET::SetScreen(), and SCH_SCREENS::UpdateSymbolLinks().

◆ LoadSymbol()

LIB_SYMBOL * SCH_PLUGIN::LoadSymbol ( const wxString &  aLibraryPath,
const wxString &  aPartName,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this SCH_PLUGIN knows about.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
aPartNameis the name of the LIB_SYMBOL to load.
aPropertiesis an associative array that can be used to tell the loader implementation to do something special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
the part created on the heap if found caller shares it or NULL if not found.
Exceptions
IO_ERRORif the library cannot be found or read. No exception is thrown in the case where aAliasName cannot be found.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 85 of file sch_plugin.cpp.

87 {
88  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
89  not_implemented( this, __FUNCTION__ );
90  return nullptr;
91 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

Referenced by SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer().

◆ ParseAltiumSch()

void SCH_ALTIUM_PLUGIN::ParseAltiumSch ( const wxString &  aFileName)

Definition at line 241 of file sch_altium_plugin.cpp.

242 {
243  // Open file
244  FILE* fp = wxFopen( aFileName, "rb" );
245 
246  if( fp == nullptr )
247  {
248  m_reporter->Report( wxString::Format( _( "Cannot open file '%s'." ), aFileName ),
250  return;
251  }
252 
253  fseek( fp, 0, SEEK_END );
254  long len = ftell( fp );
255 
256  if( len < 0 )
257  {
258  fclose( fp );
259  THROW_IO_ERROR( "Read error, cannot determine length of file." );
260  }
261 
262  std::unique_ptr<unsigned char[]> buffer( new unsigned char[len] );
263  fseek( fp, 0, SEEK_SET );
264 
265  size_t bytesRead = fread( buffer.get(), sizeof( unsigned char ), len, fp );
266  fclose( fp );
267 
268  if( static_cast<size_t>( len ) != bytesRead )
269  THROW_IO_ERROR( "Read error." );
270 
271  try
272  {
273  CFB::CompoundFileReader reader( buffer.get(), bytesRead );
274  ParseStorage( reader ); // we need this before parsing the FileHeader
275  ParseFileHeader( reader );
276  }
277  catch( CFB::CFBException& exception )
278  {
279  THROW_IO_ERROR( exception.what() );
280  }
281 }
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void ParseFileHeader(const CFB::CompoundFileReader &aReader)
void ParseStorage(const CFB::CompoundFileReader &aReader)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), m_reporter, ParseFileHeader(), ParseStorage(), REPORTER::Report(), RPT_SEVERITY_ERROR, and THROW_IO_ERROR.

Referenced by Load().

◆ ParseArc()

void SCH_ALTIUM_PLUGIN::ParseArc ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 1316 of file sch_altium_plugin.cpp.

1317 {
1318  ASCH_ARC elem( aProperties );
1319 
1320  if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
1321  {
1322  m_reporter->Report( _( "Arcs on schematic not currently supported." ),
1324  }
1325  else
1326  {
1327  const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
1328 
1329  if( libSymbolIt == m_libSymbols.end() )
1330  {
1331  // TODO: e.g. can depend on Template (RECORD=39
1332  m_reporter->Report( wxString::Format( _( "Arc's owner (%d) not found." ),
1333  elem.ownerindex ),
1335  return;
1336  }
1337 
1338  if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
1339  return;
1340 
1341  SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
1342 
1343  if( elem.startAngle == 0 && ( elem.endAngle == 0 || elem.endAngle == 360 ) )
1344  {
1345  LIB_SHAPE* circle = new LIB_SHAPE( libSymbolIt->second, SHAPE_T::CIRCLE );
1346  libSymbolIt->second->AddDrawItem( circle );
1347 
1348  circle->SetUnit( elem.ownerpartid );
1349 
1350  circle->SetPosition( GetRelativePosition( elem.center + m_sheetOffset, symbol ) );
1351  circle->SetEnd( circle->GetPosition() + wxPoint( elem.radius, 0 ) );
1352  circle->SetWidth( elem.lineWidth );
1353  }
1354  else
1355  {
1356  LIB_SHAPE* arc = new LIB_SHAPE( libSymbolIt->second, SHAPE_T::ARC );
1357  libSymbolIt->second->AddDrawItem( arc );
1358  arc->SetUnit( elem.ownerpartid );
1359 
1360  arc->SetCenter( GetRelativePosition( elem.center + m_sheetOffset, symbol ) );
1361 
1362  wxPoint arcStart( elem.radius, 0 );
1363  RotatePoint( &arcStart.x, &arcStart.y, -elem.startAngle * 10.0 );
1364  arcStart += arc->GetCenter();
1365  arc->SetStart( arcStart );
1366 
1367  wxPoint arcEnd( elem.radius, 0 );
1368  RotatePoint( &arcEnd.x, &arcEnd.y, -elem.endAngle * 10.0 );
1369  arcEnd += arc->GetCenter();
1370  arc->SetEnd( arcEnd );
1371 
1372  arc->SetWidth( elem.lineWidth );
1373  }
1374  }
1375 }
const wxPoint GetRelativePosition(const wxPoint &aPosition, const SCH_SYMBOL *aSymbol)
void SetEnd(const wxPoint &aEnd)
Definition: eda_shape.h:126
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void SetStart(const wxPoint &aStart)
Definition: eda_shape.h:101
void SetPosition(const wxPoint &aPosition) override
Definition: lib_shape.h:87
std::map< int, SCH_SYMBOL * > m_symbols
#define _(s)
void SetWidth(int aWidth)
Definition: eda_shape.h:88
std::map< int, LIB_SYMBOL * > m_libSymbols
wxPoint GetCenter() const
Definition: lib_shape.h:89
void SetCenter(const wxPoint &aCenter)
Definition: eda_shape.cpp:419
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void SetUnit(int aUnit)
Definition: lib_item.h:257
Schematic symbol object.
Definition: sch_symbol.h:78
const int ALTIUM_COMPONENT_NONE
wxPoint GetPosition() const override
Definition: lib_shape.h:86
bool IsComponentPartVisible(int aOwnerindex, int aOwnerpartdisplaymode) const

References _, ALTIUM_COMPONENT_NONE, ARC, ASCH_ARC::center, CIRCLE, ASCH_ARC::endAngle, Format(), LIB_SHAPE::GetCenter(), LIB_SHAPE::GetPosition(), GetRelativePosition(), IsComponentPartVisible(), ASCH_ARC::lineWidth, m_libSymbols, m_reporter, m_sheetOffset, m_symbols, ASCH_ARC::ownerindex, ASCH_ARC::ownerpartdisplaymode, ASCH_ARC::ownerpartid, ASCH_ARC::radius, REPORTER::Report(), RotatePoint(), RPT_SEVERITY_ERROR, EDA_SHAPE::SetCenter(), EDA_SHAPE::SetEnd(), LIB_SHAPE::SetPosition(), EDA_SHAPE::SetStart(), LIB_ITEM::SetUnit(), EDA_SHAPE::SetWidth(), and ASCH_ARC::startAngle.

Referenced by ParseFileHeader().

◆ ParseBezier()

void SCH_ALTIUM_PLUGIN::ParseBezier ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 970 of file sch_altium_plugin.cpp.

971 {
972  ASCH_BEZIER elem( aProperties );
973 
974  if( elem.points.size() < 2 )
975  {
976  m_reporter->Report( wxString::Format( _( "Bezier has %d control points. At least 2 are "
977  "expected." ),
978  static_cast<int>( elem.points.size() ) ),
980  return;
981  }
982 
983  if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
984  {
985  for( size_t i = 0; i + 1 < elem.points.size(); i += 3 )
986  {
987  if( i + 2 == elem.points.size() )
988  {
989  // special case: single line
990  SCH_LINE* line = new SCH_LINE( elem.points.at( i ) + m_sheetOffset,
992 
993  line->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
994  line->SetLineWidth( elem.lineWidth );
996 
997  line->SetFlags( IS_NEW );
998  m_currentSheet->GetScreen()->Append( line );
999  }
1000  else
1001  {
1002  // simulate Bezier using line segments
1003  std::vector<wxPoint> bezierPoints;
1004  std::vector<wxPoint> polyPoints;
1005 
1006  for( size_t j = i; j < elem.points.size() && j < i + 4; j++ )
1007  bezierPoints.push_back( elem.points.at( j ) + m_sheetOffset );
1008 
1009  BEZIER_POLY converter( bezierPoints );
1010  converter.GetPoly( polyPoints );
1011 
1012  for( size_t k = 0; k + 1 < polyPoints.size(); k++ )
1013  {
1014  SCH_LINE* line = new SCH_LINE( polyPoints.at( k ) + m_sheetOffset,
1016 
1017  line->SetEndPoint( polyPoints.at( k + 1 ) + m_sheetOffset );
1018  line->SetLineWidth( elem.lineWidth );
1019 
1020  line->SetFlags( IS_NEW );
1021  m_currentSheet->GetScreen()->Append( line );
1022  }
1023  }
1024  }
1025  }
1026  else
1027  {
1028  const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
1029 
1030  if( libSymbolIt == m_libSymbols.end() )
1031  {
1032  // TODO: e.g. can depend on Template (RECORD=39
1033  m_reporter->Report( wxString::Format( _( "Bezier's owner (%d) not found." ),
1034  elem.ownerindex ),
1036  return;
1037  }
1038 
1039  if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
1040  return;
1041 
1042  SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
1043 
1044  for( size_t i = 0; i + 1 < elem.points.size(); i += 3 )
1045  {
1046  if( i + 2 == elem.points.size() )
1047  {
1048  // special case: single line
1049  LIB_SHAPE* line = new LIB_SHAPE( libSymbolIt->second, SHAPE_T::POLY );
1050  libSymbolIt->second->AddDrawItem( line );
1051 
1052  line->SetUnit( elem.ownerpartid );
1053 
1054  for( size_t j = i; j < elem.points.size() && j < i + 2; j++ )
1055  {
1056  line->AddPoint( GetRelativePosition( elem.points.at( j ) + m_sheetOffset,
1057  symbol ) );
1058  }
1059 
1060  line->SetWidth( elem.lineWidth );
1061  }
1062  else if( i + 3 == elem.points.size() )
1063  {
1064  // TODO: special case of a single line with an extra point?
1065  // I haven't a clue what this is all about, but the sample document we have in
1066  // https://gitlab.com/kicad/code/kicad/-/issues/8974 responds best by treating it
1067  // as another single line special case.
1068  LIB_SHAPE* line = new LIB_SHAPE( libSymbolIt->second, SHAPE_T::POLY );
1069  libSymbolIt->second->AddDrawItem( line );
1070 
1071  line->SetUnit( elem.ownerpartid );
1072 
1073  for( size_t j = i; j < elem.points.size() && j < i + 2; j++ )
1074  {
1075  line->AddPoint( GetRelativePosition( elem.points.at( j ) + m_sheetOffset,
1076  symbol ) );
1077  }
1078 
1079  line->SetWidth( elem.lineWidth );
1080  }
1081  else
1082  {
1083  // Bezier always has exactly 4 control points
1084  LIB_SHAPE* bezier = new LIB_SHAPE( libSymbolIt->second, SHAPE_T::BEZIER );
1085  libSymbolIt->second->AddDrawItem( bezier );
1086 
1087  bezier->SetUnit( elem.ownerpartid );
1088 
1089  for( size_t j = i; j < elem.points.size() && j < i + 4; j++ )
1090  {
1091  wxPoint pos = GetRelativePosition( elem.points.at( j ) + m_sheetOffset, symbol );
1092 
1093  switch( j - i )
1094  {
1095  case 0: bezier->SetStart( pos ); break;
1096  case 1: bezier->SetBezierC1( pos ); break;
1097  case 2: bezier->SetBezierC2( pos ); break;
1098  case 3: bezier->SetEnd( pos ); break;
1099  default: break; // Can't get here but silence warnings
1100  }
1101  }
1102 
1103  bezier->SetWidth( elem.lineWidth );
1104  }
1105  }
1106  }
1107 }
void AddPoint(const wxPoint &aPosition)
Definition: lib_shape.cpp:407
const wxPoint GetRelativePosition(const wxPoint &aPosition, const SCH_SYMBOL *aSymbol)
void SetEnd(const wxPoint &aEnd)
Definition: eda_shape.h:126
#define IS_NEW
New item, just created.
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:305
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void SetBezierC1(const wxPoint &aPt)
Definition: eda_shape.h:144
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
void SetStart(const wxPoint &aStart)
Definition: eda_shape.h:101
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:269
std::map< int, SCH_SYMBOL * > m_symbols
#define _(s)
void SetWidth(int aWidth)
Definition: eda_shape.h:88
std::map< int, LIB_SYMBOL * > m_libSymbols
SCH_SHEET * m_currentSheet
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void SetUnit(int aUnit)
Definition: lib_item.h:257
Bezier curves to polygon converter.
Definition: bezier_curves.h:36
Schematic symbol object.
Definition: sch_symbol.h:78
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
void SetBezierC2(const wxPoint &aPt)
Definition: eda_shape.h:147
const int ALTIUM_COMPONENT_NONE
bool IsComponentPartVisible(int aOwnerindex, int aOwnerpartdisplaymode) const

References _, LIB_SHAPE::AddPoint(), ALTIUM_COMPONENT_NONE, SCH_SCREEN::Append(), BEZIER, Format(), BEZIER_POLY::GetPoly(), GetRelativePosition(), SCH_SHEET::GetScreen(), IS_NEW, IsComponentPartVisible(), LAYER_NOTES, ASCH_BEZIER::lineWidth, m_currentSheet, m_libSymbols, m_reporter, m_sheetOffset, m_symbols, ASCH_BEZIER::ownerindex, ASCH_BEZIER::ownerpartdisplaymode, ASCH_BEZIER::ownerpartid, ASCH_BEZIER::points, POLY, REPORTER::Report(), RPT_SEVERITY_ERROR, RPT_SEVERITY_WARNING, EDA_SHAPE::SetBezierC1(), EDA_SHAPE::SetBezierC2(), EDA_SHAPE::SetEnd(), SCH_LINE::SetEndPoint(), EDA_ITEM::SetFlags(), SCH_LINE::SetLineStyle(), SCH_LINE::SetLineWidth(), EDA_SHAPE::SetStart(), LIB_ITEM::SetUnit(), EDA_SHAPE::SetWidth(), and SOLID.

Referenced by ParseFileHeader().

◆ ParseBus()

void SCH_ALTIUM_PLUGIN::ParseBus ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 2075 of file sch_altium_plugin.cpp.

2076 {
2077  ASCH_BUS elem( aProperties );
2078 
2079  for( size_t i = 0; i + 1 < elem.points.size(); i++ )
2080  {
2081  SCH_LINE* bus = new SCH_LINE( elem.points.at( i ) + m_sheetOffset,
2083  bus->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
2084  bus->SetLineWidth( elem.lineWidth );
2085 
2086  bus->SetFlags( IS_NEW );
2087  m_currentSheet->GetScreen()->Append( bus );
2088  }
2089 }
#define IS_NEW
New item, just created.
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:305
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
SCH_SHEET * m_currentSheet
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146

References SCH_SCREEN::Append(), SCH_SHEET::GetScreen(), IS_NEW, LAYER_BUS, ASCH_BUS::lineWidth, m_currentSheet, m_sheetOffset, ASCH_BUS::points, SCH_LINE::SetEndPoint(), EDA_ITEM::SetFlags(), and SCH_LINE::SetLineWidth().

Referenced by ParseFileHeader().

◆ ParseBusEntry()

void SCH_ALTIUM_PLUGIN::ParseBusEntry ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 2309 of file sch_altium_plugin.cpp.

2310 {
2311  ASCH_BUS_ENTRY elem( aProperties );
2312 
2313  SCH_BUS_WIRE_ENTRY* busWireEntry = new SCH_BUS_WIRE_ENTRY( elem.location + m_sheetOffset );
2314 
2315  wxPoint vector = elem.corner - elem.location;
2316  busWireEntry->SetSize( { vector.x, vector.y } );
2317 
2318  busWireEntry->SetFlags( IS_NEW );
2319  m_currentSheet->GetScreen()->Append( busWireEntry );
2320 }
void SetSize(const wxSize &aSize)
Definition: sch_bus_entry.h:76
#define IS_NEW
New item, just created.
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
SCH_SHEET * m_currentSheet
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
Class for a wire to bus entry.

References SCH_SCREEN::Append(), ASCH_BUS_ENTRY::corner, SCH_SHEET::GetScreen(), IS_NEW, ASCH_BUS_ENTRY::location, m_currentSheet, m_sheetOffset, EDA_ITEM::SetFlags(), and SCH_BUS_ENTRY_BASE::SetSize().

Referenced by ParseFileHeader().

◆ ParseComponent()

void SCH_ALTIUM_PLUGIN::ParseComponent ( int  aIndex,
const std::map< wxString, wxString > &  aProperties 
)
private

Definition at line 559 of file sch_altium_plugin.cpp.

561 {
562  auto pair = m_altiumComponents.insert( { aIndex, ASCH_SYMBOL( aProperties ) } );
563  const ASCH_SYMBOL& elem = pair.first->second;
564 
565  // TODO: this is a hack until we correctly apply all transformations to every element
566  wxString name = wxString::Format( "%d%s_%s",
567  elem.orientation,
568  elem.isMirrored ? "_mirrored" : "",
569  elem.libreference );
571 
572  LIB_SYMBOL* ksymbol = new LIB_SYMBOL( wxEmptyString );
573  ksymbol->SetName( name );
574  ksymbol->SetDescription( elem.componentdescription );
575  ksymbol->SetLibId( libId );
576  m_libSymbols.insert( { aIndex, ksymbol } );
577 
578  // each component has its own symbol for now
579  SCH_SYMBOL* symbol = new SCH_SYMBOL();
580 
581  symbol->SetPosition( elem.location + m_sheetOffset );
582 
583  // TODO: keep it simple for now, and only set position.
584  //component->SetOrientation( elem.orientation );
585  symbol->SetLibId( libId );
586 
587  symbol->SetUnit( elem.currentpartid );
588 
589  m_currentSheet->GetScreen()->Append( symbol );
590 
591  m_symbols.insert( { aIndex, symbol } );
592 }
std::map< int, ASCH_SYMBOL > m_altiumComponents
void SetPosition(const wxPoint &aPosition) override
Definition: sch_symbol.h:645
void SetUnit(int aUnit)
Change the unit number to aUnit.
Definition: sch_symbol.cpp:331
void SetLibId(const LIB_ID &aName)
Definition: sch_symbol.cpp:238
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
Define a library symbol object.
Definition: lib_symbol.h:96
wxString libreference
std::map< int, SCH_SYMBOL * > m_symbols
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:313
void SetDescription(const wxString &aDescription)
Definition: lib_symbol.h:140
std::map< int, LIB_SYMBOL * > m_libSymbols
void SetLibId(const LIB_ID &aLibId)
Definition: lib_symbol.h:136
SCH_SHEET * m_currentSheet
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
LIB_ID AltiumToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
Schematic symbol object.
Definition: sch_symbol.h:78
const char * name
Definition: DXF_plotter.cpp:56
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
wxString componentdescription

References AltiumToKiCadLibID(), SCH_SCREEN::Append(), ASCH_SYMBOL::componentdescription, ASCH_SYMBOL::currentpartid, Format(), getLibName(), SCH_SHEET::GetScreen(), ASCH_SYMBOL::isMirrored, ASCH_SYMBOL::libreference, ASCH_SYMBOL::location, m_altiumComponents, m_currentSheet, m_libSymbols, m_sheetOffset, m_symbols, name, ASCH_SYMBOL::orientation, LIB_SYMBOL::SetDescription(), LIB_SYMBOL::SetLibId(), SCH_SYMBOL::SetLibId(), LIB_SYMBOL::SetName(), SCH_SYMBOL::SetPosition(), and SCH_SYMBOL::SetUnit().

Referenced by ParseFileHeader().

◆ ParseDesignator()

void SCH_ALTIUM_PLUGIN::ParseDesignator ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 2280 of file sch_altium_plugin.cpp.

2281 {
2282  ASCH_DESIGNATOR elem( aProperties );
2283 
2284  const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
2285 
2286  if( libSymbolIt == m_libSymbols.end() )
2287  {
2288  // TODO: e.g. can depend on Template (RECORD=39
2289  m_reporter->Report( wxString::Format( _( "Designator's owner (%d) not found." ),
2290  elem.ownerindex ),
2292  return;
2293  }
2294 
2295  SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
2296  SCH_SHEET_PATH sheetpath;
2298 
2299  symbol->SetRef( &sheetpath, elem.text );
2300 
2301  SCH_FIELD* refField = symbol->GetField( REFERENCE_FIELD );
2302 
2303  refField->SetPosition( elem.location + m_sheetOffset );
2304  refField->SetVisible( true );
2305  SetTextPositioning( refField, elem.justification, elem.orientation );
2306 }
Field Reference of part, i.e. "IC21".
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:675
void SetTextPositioning(EDA_TEXT *text, ASCH_LABEL_JUSTIFICATION justification, ASCH_RECORD_ORIENTATION orientation)
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
virtual void SetVisible(bool aVisible)
Definition: eda_text.h:206
std::map< int, SCH_SYMBOL * > m_symbols
#define _(s)
std::map< int, LIB_SYMBOL * > m_libSymbols
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SHEET * m_currentSheet
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
bool LocatePathOfScreen(SCH_SCREEN *aScreen, SCH_SHEET_PATH *aList)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:688
Schematic symbol object.
Definition: sch_symbol.h:78
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:481
void SetPosition(const wxPoint &aPosition) override
Definition: sch_field.cpp:822

References _, Format(), SCH_SYMBOL::GetField(), SCH_SHEET::GetScreen(), ASCH_DESIGNATOR::justification, SCH_SHEET::LocatePathOfScreen(), ASCH_DESIGNATOR::location, m_currentSheet, m_libSymbols, m_reporter, m_rootSheet, m_sheetOffset, m_symbols, ASCH_DESIGNATOR::orientation, ASCH_DESIGNATOR::ownerindex, REFERENCE_FIELD, REPORTER::Report(), RPT_SEVERITY_ERROR, SCH_FIELD::SetPosition(), SCH_SYMBOL::SetRef(), SetTextPositioning(), EDA_TEXT::SetVisible(), and ASCH_DESIGNATOR::text.

Referenced by ParseFileHeader().

◆ ParseFileHeader()

void SCH_ALTIUM_PLUGIN::ParseFileHeader ( const CFB::CompoundFileReader &  aReader)

Definition at line 320 of file sch_altium_plugin.cpp.

321 {
322  const CFB::COMPOUND_FILE_ENTRY* file = FindStream( aReader, "FileHeader" );
323 
324  if( file == nullptr )
325  THROW_IO_ERROR( "FileHeader not found" );
326 
327  ALTIUM_PARSER reader( aReader, file );
328 
329  if( reader.GetRemainingBytes() <= 0 )
330  {
331  THROW_IO_ERROR( "FileHeader does not contain any data" );
332  }
333  else
334  {
335  std::map<wxString, wxString> properties = reader.ReadProperties();
336 
337  int recordId = ALTIUM_PARSER::ReadInt( properties, "RECORD", 0 );
338  ALTIUM_SCH_RECORD record = static_cast<ALTIUM_SCH_RECORD>( recordId );
339 
340  if( record != ALTIUM_SCH_RECORD::HEADER )
341  THROW_IO_ERROR( "Header expected" );
342  }
343 
344  // Prepare some local variables
345  wxASSERT( m_altiumPortsCurrentSheet.empty() );
346  wxASSERT( !m_currentTitleBlock );
347 
348  m_currentTitleBlock = std::make_unique<TITLE_BLOCK>();
349 
350  // index is required to resolve OWNERINDEX
351  for( int index = 0; reader.GetRemainingBytes() > 0; index++ )
352  {
353  std::map<wxString, wxString> properties = reader.ReadProperties();
354 
355  int recordId = ALTIUM_PARSER::ReadInt( properties, "RECORD", 0 );
356  ALTIUM_SCH_RECORD record = static_cast<ALTIUM_SCH_RECORD>( recordId );
357 
358  // see: https://github.com/vadmium/python-altium/blob/master/format.md
359  switch( record )
360  {
362  THROW_IO_ERROR( "Header already parsed" );
364  ParseComponent( index, properties );
365  break;
367  ParsePin( properties );
368  break;
370  break;
372  ParseLabel( properties );
373  break;
375  ParseBezier( properties );
376  break;
378  ParsePolyline( properties );
379  break;
381  ParsePolygon( properties );
382  break;
384  break;
386  break;
388  ParseRoundRectangle( properties );
389  break;
391  break;
393  ParseArc( properties );
394  break;
396  ParseLine( properties );
397  break;
399  ParseRectangle( properties );
400  break;
402  ParseSheetSymbol( index, properties );
403  break;
405  ParseSheetEntry( properties );
406  break;
408  ParsePowerPort( properties );
409  break;
411  // Ports are parsed after the sheet was parsed
412  // This is required because we need all electrical connection points before placing.
413  m_altiumPortsCurrentSheet.emplace_back( properties );
414  break;
416  ParseNoERC( properties );
417  break;
419  ParseNetLabel( properties );
420  break;
422  ParseBus( properties );
423  break;
425  ParseWire( properties );
426  break;
428  ParseTextFrame( properties );
429  break;
431  ParseJunction( properties );
432  break;
434  ParseImage( properties );
435  break;
437  ParseSheet( properties );
438  break;
440  ParseSheetName( properties );
441  break;
443  ParseFileName( properties );
444  break;
446  ParseDesignator( properties );
447  break;
449  ParseBusEntry( properties );
450  break;
452  break;
454  ParseParameter( properties );
455  break;
457  break;
459  ParseImplementationList( index, properties );
460  break;
462  ParseImplementation( properties );
463  break;
465  break;
467  break;
469  break;
471  ParseNote( properties );
472  break;
474  m_reporter->Report( _( "Compile mask not currently supported." ), RPT_SEVERITY_ERROR );
475  break;
477  break;
479  break;
481  break;
483  break;
485  break;
486  default:
487  m_reporter->Report( wxString::Format( _( "Unknown Record id: %d." ), recordId ),
489  break;
490  }
491  }
492 
493  if( reader.HasParsingError() )
494  THROW_IO_ERROR( "stream was not parsed correctly!" );
495 
496  if( reader.GetRemainingBytes() != 0 )
497  THROW_IO_ERROR( "stream is not fully parsed" );
498 
499  // assign LIB_SYMBOL -> COMPONENT
500  for( std::pair<const int, SCH_SYMBOL*>& symbol : m_symbols )
501  {
502  auto libSymbolIt = m_libSymbols.find( symbol.first );
503 
504  if( libSymbolIt == m_libSymbols.end() )
505  THROW_IO_ERROR( "every symbol should have a symbol attached" );
506 
507  m_pi->SaveSymbol( getLibFileName().GetFullPath(),
508  new LIB_SYMBOL( *( libSymbolIt->second ) ), m_properties.get() );
509 
510  symbol.second->SetLibSymbol( libSymbolIt->second );
511  }
512 
513  // Handle title blocks
515  m_currentTitleBlock.reset();
516 
517  // Handle Ports
518  for( const ASCH_PORT& port : m_altiumPortsCurrentSheet )
519  ParsePort( port );
520 
522 
523  m_symbols.clear();
524  m_libSymbols.clear();
525 
526  // Otherwise we cannot save the imported sheet?
528 }
void ParsePort(const ASCH_PORT &aElem)
std::unique_ptr< PROPERTIES > m_properties
void SetModified()
Definition: eda_item.cpp:65
void ParseLabel(const std::map< wxString, wxString > &aProperties)
void ParseBezier(const std::map< wxString, wxString > &aProperties)
void ParsePowerPort(const std::map< wxString, wxString > &aProperties)
void ParseJunction(const std::map< wxString, wxString > &aProperties)
void ParseImplementation(const std::map< wxString, wxString > &aProperties)
void ParseParameter(const std::map< wxString, wxString > &aProperties)
void ParseRoundRectangle(const std::map< wxString, wxString > &aProperties)
void ParseBusEntry(const std::map< wxString, wxString > &aProperties)
void ParseSheet(const std::map< wxString, wxString > &aProperties)
void ParsePolygon(const std::map< wxString, wxString > &aProperties)
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
Define a library symbol object.
Definition: lib_symbol.h:96
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void ParseRectangle(const std::map< wxString, wxString > &aProperties)
void ParsePolyline(const std::map< wxString, wxString > &aProperties)
const CFB::COMPOUND_FILE_ENTRY * FindStream(const CFB::CompoundFileReader &aReader, const char *aStreamName)
void ParseImage(const std::map< wxString, wxString > &aProperties)
std::vector< ASCH_PORT > m_altiumPortsCurrentSheet
static int ReadInt(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aDefault)
void ParseLine(const std::map< wxString, wxString > &aProperties)
std::map< int, SCH_SYMBOL * > m_symbols
wxFileName getLibFileName()
void ParseSheetEntry(const std::map< wxString, wxString > &aProperties)
#define _(s)
std::map< int, LIB_SYMBOL * > m_libSymbols
void ParseFileName(const std::map< wxString, wxString > &aProperties)
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: sch_screen.h:158
void ParseNoERC(const std::map< wxString, wxString > &aProperties)
SCH_SHEET * m_currentSheet
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void ParseComponent(int aIndex, const std::map< wxString, wxString > &aProperties)
void ParseSheetSymbol(int aIndex, const std::map< wxString, wxString > &aProperties)
void ParseNote(const std::map< wxString, wxString > &aProperties)
void ParseWire(const std::map< wxString, wxString > &aProperties)
void ParseSheetName(const std::map< wxString, wxString > &aProperties)
void ParseArc(const std::map< wxString, wxString > &aProperties)
void ParseTextFrame(const std::map< wxString, wxString > &aProperties)
void ParseBus(const std::map< wxString, wxString > &aProperties)
void ParseImplementationList(int aIndex, const std::map< wxString, wxString > &aProperties)
void ParseDesignator(const std::map< wxString, wxString > &aProperties)
void ParsePin(const std::map< wxString, wxString > &aProperties)
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
void ParseNetLabel(const std::map< wxString, wxString > &aProperties)
ALTIUM_SCH_RECORD
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
std::unique_ptr< TITLE_BLOCK > m_currentTitleBlock

References _, ARC, BEZIER, BUS, BUS_ENTRY, COMPILE_MASK, COMPONENT, DESIGNATOR, ELLIPSE, ELLIPTICAL_ARC, FILE_NAME, FindStream(), Format(), getLibFileName(), ALTIUM_PARSER::GetRemainingBytes(), SCH_SHEET::GetScreen(), ALTIUM_PARSER::HasParsingError(), HEADER, IEEE_SYMBOL, IMAGE, IMPLEMENTATION, IMPLEMENTATION_LIST, JUNCTION, LABEL, LINE, m_altiumPortsCurrentSheet, m_currentSheet, m_currentTitleBlock, m_libSymbols, m_pi, m_properties, m_reporter, m_symbols, NET_LABEL, NO_ERC, NOTE, PARAMETER, ParseArc(), ParseBezier(), ParseBus(), ParseBusEntry(), ParseComponent(), ParseDesignator(), ParseFileName(), ParseImage(), ParseImplementation(), ParseImplementationList(), ParseJunction(), ParseLabel(), ParseLine(), ParseNetLabel(), ParseNoERC(), ParseNote(), ParseParameter(), ParsePin(), ParsePolygon(), ParsePolyline(), ParsePort(), ParsePowerPort(), ParseRectangle(), ParseRoundRectangle(), ParseSheet(), ParseSheetEntry(), ParseSheetName(), ParseSheetSymbol(), ParseTextFrame(), ParseWire(), PIECHART, PIN, POLYGON, POLYLINE, PORT, POWER_PORT, ALTIUM_PARSER::ReadInt(), ALTIUM_PARSER::ReadProperties(), RECORD_215, RECORD_216, RECORD_217, RECORD_218, RECORD_226, RECORD_46, RECORD_47, RECORD_48, RECTANGLE, REPORTER::Report(), ROUND_RECTANGLE, RPT_SEVERITY_ERROR, EDA_ITEM::SetModified(), SCH_SCREEN::SetTitleBlock(), SHEET, SHEET_ENTRY, SHEET_NAME, SHEET_SYMBOL, TEMPLATE, TEXT_FRAME, THROW_IO_ERROR, WARNING_SIGN, and WIRE.

Referenced by ParseAltiumSch().

◆ ParseFileName()

void SCH_ALTIUM_PLUGIN::ParseFileName ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 2247 of file sch_altium_plugin.cpp.

2248 {
2249  ASCH_FILE_NAME elem( aProperties );
2250 
2251  const auto& sheetIt = m_sheets.find( elem.ownerindex );
2252 
2253  if( sheetIt == m_sheets.end() )
2254  {
2255  m_reporter->Report( wxString::Format( _( "Filename's owner (%d) not found." ),
2256  elem.ownerindex ),
2258  return;
2259  }
2260 
2261  SCH_FIELD& filenameField = sheetIt->second->GetFields()[SHEETFILENAME];
2262 
2263  filenameField.SetPosition( elem.location + m_sheetOffset );
2264 
2265  // If last symbols are ".sChDoC", change them to ".kicad_sch"
2266  if( ( elem.text.Right( GetFileExtension().length() + 1 ).Lower() )
2267  == ( "." + GetFileExtension().Lower() ) )
2268  {
2269  elem.text.RemoveLast( GetFileExtension().length() );
2270  elem.text += KiCadSchematicFileExtension;
2271  }
2272 
2273  filenameField.SetText( elem.text );
2274 
2275  filenameField.SetVisible( !elem.isHidden );
2276  SetTextPositioning( &filenameField, ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT, elem.orientation );
2277 }
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
void SetTextPositioning(EDA_TEXT *text, ASCH_LABEL_JUSTIFICATION justification, ASCH_RECORD_ORIENTATION orientation)
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
std::map< int, SCH_SHEET * > m_sheets
virtual void SetVisible(bool aVisible)
Definition: eda_text.h:206
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
const wxString GetFileExtension() const override
Return the file extension for the SCH_PLUGIN.
const std::string KiCadSchematicFileExtension
void SetPosition(const wxPoint &aPosition) override
Definition: sch_field.cpp:822

References _, BOTTOM_LEFT, Format(), GetFileExtension(), ASCH_FILE_NAME::isHidden, KiCadSchematicFileExtension, ASCH_FILE_NAME::location, m_reporter, m_sheetOffset, m_sheets, ASCH_FILE_NAME::orientation, ASCH_FILE_NAME::ownerindex, REPORTER::Report(), RPT_SEVERITY_ERROR, SCH_FIELD::SetPosition(), EDA_TEXT::SetText(), SetTextPositioning(), EDA_TEXT::SetVisible(), SHEETFILENAME, and ASCH_FILE_NAME::text.

Referenced by ParseFileHeader().

◆ ParseImage()

void SCH_ALTIUM_PLUGIN::ParseImage ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 2120 of file sch_altium_plugin.cpp.

2121 {
2122  ASCH_IMAGE elem( aProperties );
2123 
2124  wxPoint center = ( elem.location + elem.corner ) / 2 + m_sheetOffset;
2125  std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>( center );
2126 
2127  if( elem.embedimage )
2128  {
2129  const ASCH_STORAGE_FILE* storageFile = GetFileFromStorage( elem.filename );
2130 
2131  if( !storageFile )
2132  {
2133  wxString msg = wxString::Format( _( "Embedded file %s not found in storage." ),
2134  elem.filename );
2136  return;
2137  }
2138 
2139  wxString storagePath = wxFileName::CreateTempFileName( "kicad_import_" );
2140 
2141  // As wxZlibInputStream is not seekable, we need to write a temporary file
2142  wxMemoryInputStream fileStream( storageFile->data.data(), storageFile->data.size() );
2143  wxZlibInputStream zlibInputStream( fileStream );
2144  wxFFileOutputStream outputStream( storagePath );
2145  outputStream.Write( zlibInputStream );
2146  outputStream.Close();
2147 
2148  if( !bitmap->ReadImageFile( storagePath ) )
2149  {
2150  m_reporter->Report( wxString::Format( _( "Error reading image %s." ), storagePath ),
2152  return;
2153  }
2154 
2155  // Remove temporary file
2156  wxRemoveFile( storagePath );
2157  }
2158  else
2159  {
2160  if( !wxFileExists( elem.filename ) )
2161  {
2162  m_reporter->Report( wxString::Format( _( "File not found %s." ), elem.filename ),
2164  return;
2165  }
2166 
2167  if( !bitmap->ReadImageFile( elem.filename ) )
2168  {
2169  m_reporter->Report( wxString::Format( _( "Error reading image %s." ), elem.filename ),
2171  return;
2172  }
2173  }
2174 
2175  // we only support one scale, thus we need to select one in case it does not keep aspect ratio
2176  wxSize currentImageSize = bitmap->GetSize();
2177  wxPoint expectedImageSize = elem.location - elem.corner;
2178  double scaleX = std::abs( static_cast<double>( expectedImageSize.x ) / currentImageSize.x );
2179  double scaleY = std::abs( static_cast<double>( expectedImageSize.y ) / currentImageSize.y );
2180  bitmap->SetImageScale( std::min( scaleX, scaleY ) );
2181 
2182  bitmap->SetFlags( IS_NEW );
2183  m_currentSheet->GetScreen()->Append( bitmap.release() );
2184 }
std::vector< char > data
#define IS_NEW
New item, just created.
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
#define _(s)
const ASCH_STORAGE_FILE * GetFileFromStorage(const wxString &aFilename) const
SCH_SHEET * m_currentSheet
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146

References _, SCH_SCREEN::Append(), ASCH_IMAGE::corner, ASCH_STORAGE_FILE::data, ASCH_IMAGE::embedimage, ASCH_IMAGE::filename, Format(), GetFileFromStorage(), SCH_SHEET::GetScreen(), IS_NEW, ASCH_IMAGE::location, m_currentSheet, m_reporter, m_sheetOffset, REPORTER::Report(), and RPT_SEVERITY_ERROR.

Referenced by ParseFileHeader().

◆ ParseImplementation()

void SCH_ALTIUM_PLUGIN::ParseImplementation ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 2413 of file sch_altium_plugin.cpp.

2414 {
2415  ASCH_IMPLEMENTATION elem( aProperties );
2416 
2417  // Only get footprint, currently assigned only
2418  if( ( elem.type == "PCBLIB" ) && ( elem.isCurrent ) )
2419  {
2420  const auto& implementationOwnerIt = m_altiumImplementationList.find( elem.ownerindex );
2421 
2422  if( implementationOwnerIt == m_altiumImplementationList.end() )
2423  {
2424  m_reporter->Report( wxString::Format( _( "Implementation's owner (%d) not found." ),
2425  elem.ownerindex ),
2427  return;
2428  }
2429 
2430  const auto& libSymbolIt = m_libSymbols.find( implementationOwnerIt->second );
2431 
2432  if( libSymbolIt == m_libSymbols.end() )
2433  {
2434  m_reporter->Report( wxString::Format( _( "Footprint's owner (%d) not found." ),
2435  implementationOwnerIt->second ),
2437  return;
2438  }
2439 
2440  LIB_ID fpLibId = AltiumToKiCadLibID( elem.libname, elem.name );
2441  wxArrayString fpFilters;
2442  fpFilters.Add( fpLibId.Format() );
2443 
2444  libSymbolIt->second->SetFPFilters( fpFilters ); // TODO: not ideal as we overwrite it
2445 
2446  SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
2447 
2448  symbol->SetFootprint( fpLibId.Format() );
2449  }
2450 }
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void SetFootprint(const SCH_SHEET_PATH *sheet, const wxString &aFootprint)
Definition: sch_symbol.cpp:645
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
std::map< int, SCH_SYMBOL * > m_symbols
#define _(s)
std::map< int, LIB_SYMBOL * > m_libSymbols
UTF8 Format() const
Definition: lib_id.cpp:116
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
LIB_ID AltiumToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
Schematic symbol object.
Definition: sch_symbol.h:78
std::map< int, int > m_altiumImplementationList

References _, AltiumToKiCadLibID(), LIB_ID::Format(), Format(), ASCH_IMPLEMENTATION::isCurrent, ASCH_IMPLEMENTATION::libname, m_altiumImplementationList, m_libSymbols, m_reporter, m_symbols, ASCH_IMPLEMENTATION::name, ASCH_IMPLEMENTATION::ownerindex, REPORTER::Report(), RPT_SEVERITY_ERROR, SCH_SYMBOL::SetFootprint(), and ASCH_IMPLEMENTATION::type.

Referenced by ParseFileHeader().

◆ ParseImplementationList()

void SCH_ALTIUM_PLUGIN::ParseImplementationList ( int  aIndex,
const std::map< wxString, wxString > &  aProperties 
)
private

Definition at line 2404 of file sch_altium_plugin.cpp.

2406 {
2407  ASCH_IMPLEMENTATION_LIST elem( aProperties );
2408 
2409  m_altiumImplementationList.emplace( aIndex, elem.ownerindex );
2410 }
std::map< int, int > m_altiumImplementationList

References m_altiumImplementationList, and ASCH_IMPLEMENTATION_LIST::ownerindex.

Referenced by ParseFileHeader().

◆ ParseJunction()

void SCH_ALTIUM_PLUGIN::ParseJunction ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 2109 of file sch_altium_plugin.cpp.

2110 {
2111  ASCH_JUNCTION elem( aProperties );
2112 
2113  SCH_JUNCTION* junction = new SCH_JUNCTION( elem.location + m_sheetOffset );
2114 
2115  junction->SetFlags( IS_NEW );
2116  m_currentSheet->GetScreen()->Append( junction );
2117 }
#define IS_NEW
New item, just created.
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
SCH_SHEET * m_currentSheet
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146

References SCH_SCREEN::Append(), SCH_SHEET::GetScreen(), IS_NEW, ASCH_JUNCTION::location, m_currentSheet, m_sheetOffset, and EDA_ITEM::SetFlags().

Referenced by ParseFileHeader().

◆ ParseLabel()

void SCH_ALTIUM_PLUGIN::ParseLabel ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 815 of file sch_altium_plugin.cpp.

816 {
817  ASCH_LABEL elem( aProperties );
818 
819  if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
820  {
821  std::map<wxString, wxString> variableMap = {
822  { "APPLICATION_BUILDNUMBER", "KICAD_VERSION" },
823  { "SHEETNUMBER", "#" },
824  { "SHEETTOTAL", "##" },
825  { "TITLE", "TITLE" }, // 1:1 maps are sort of useless, but it makes it
826  { "REVISION", "REVISION" }, // easier to see that the list is complete
827  { "DATE", "ISSUE_DATE" },
828  { "CURRENTDATE", "CURRENT_DATE" },
829  { "COMPANYNAME", "COMPANY" },
830  { "DOCUMENTNAME", "FILENAME" },
831  { "PROJECTNAME", "PROJECTNAME" },
832  };
833 
834  wxString kicadText = AltiumSpecialStringsToKiCadVariables( elem.text, variableMap );
835  SCH_TEXT* textItem = new SCH_TEXT( elem.location + m_sheetOffset, kicadText );
836 
837  SetTextPositioning( textItem, elem.justification, elem.orientation );
838 
839  size_t fontId = static_cast<int>( elem.fontId );
840 
841  if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() )
842  {
843  const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 );
844  textItem->SetItalic( font.italic );
845  textItem->SetBold( font.bold );
846  textItem->SetTextSize( { font.size / 2, font.size / 2 } );
847  }
848 
849  textItem->SetFlags(IS_NEW );
850  m_currentSheet->GetScreen()->Append( textItem );
851  }
852  else
853  {
854  const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
855 
856  if( libSymbolIt == m_libSymbols.end() )
857  {
858  // TODO: e.g. can depend on Template (RECORD=39
859  m_reporter->Report( wxString::Format( _( "Label's owner (%d) not found." ),
860  elem.ownerindex ),
862  return;
863  }
864 
865  SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
866  LIB_TEXT* textItem = new LIB_TEXT( libSymbolIt->second );
867  libSymbolIt->second->AddDrawItem( textItem );
868 
869  textItem->SetUnit( elem.ownerpartid );
870 
871  textItem->SetPosition( GetRelativePosition( elem.location + m_sheetOffset, symbol ) );
872  textItem->SetText( elem.text );
873  SetTextPositioning( textItem, elem.justification, elem.orientation );
874 
875  size_t fontId = static_cast<int>( elem.fontId );
876 
877  if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() )
878  {
879  const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 );
880  textItem->SetItalic( font.italic );
881  textItem->SetBold( font.bold );
882  textItem->SetTextSize( { font.size / 2, font.size / 2 } );
883  }
884  }
885 }
const wxPoint GetRelativePosition(const wxPoint &aPosition, const SCH_SYMBOL *aSymbol)
void SetTextPositioning(EDA_TEXT *text, ASCH_LABEL_JUSTIFICATION justification, ASCH_RECORD_ORIENTATION orientation)
#define IS_NEW
New item, just created.
Define a symbol library graphical text item.
Definition: lib_text.h:39
void SetItalic(bool isItalic)
Definition: eda_text.h:200
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:258
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
std::map< int, SCH_SYMBOL * > m_symbols
std::unique_ptr< ASCH_SHEET > m_altiumSheet
#define _(s)
std::map< int, LIB_SYMBOL * > m_libSymbols
SCH_SHEET * m_currentSheet
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void SetUnit(int aUnit)
Definition: lib_item.h:257
Schematic symbol object.
Definition: sch_symbol.h:78
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
wxString AltiumSpecialStringsToKiCadVariables(const wxString &aString, const std::map< wxString, wxString > &aOverrides)
void SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:222
const int ALTIUM_COMPONENT_NONE
void SetBold(bool aBold)
Definition: eda_text.h:203

References _, ALTIUM_COMPONENT_NONE, AltiumSpecialStringsToKiCadVariables(), SCH_SCREEN::Append(), ASCH_SHEET_FONT::bold, ASCH_LABEL::fontId, fonts, Format(), GetRelativePosition(), SCH_SHEET::GetScreen(), IS_NEW, ASCH_SHEET_FONT::italic, ASCH_LABEL::justification, ASCH_LABEL::location, m_altiumSheet, m_currentSheet, m_libSymbols, m_reporter, m_sheetOffset, m_symbols, ASCH_LABEL::orientation, ASCH_LABEL::ownerindex, ASCH_LABEL::ownerpartid, REPORTER::Report(), RPT_SEVERITY_ERROR, EDA_TEXT::SetBold(), EDA_ITEM::SetFlags(), EDA_TEXT::SetItalic(), LIB_ITEM::SetPosition(), EDA_TEXT::SetText(), SetTextPositioning(), EDA_TEXT::SetTextSize(), LIB_ITEM::SetUnit(), ASCH_SHEET_FONT::size, and ASCH_LABEL::text.

Referenced by ParseFileHeader().

◆ ParseLine()

void SCH_ALTIUM_PLUGIN::ParseLine ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 1378 of file sch_altium_plugin.cpp.

1379 {
1380  ASCH_LINE elem( aProperties );
1381 
1382  if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
1383  {
1384  // close polygon
1385  SCH_LINE* line = new SCH_LINE( elem.point1 + m_sheetOffset, SCH_LAYER_ID::LAYER_NOTES );
1386  line->SetEndPoint( elem.point2 + m_sheetOffset );
1387  line->SetLineWidth( elem.lineWidth );
1388  line->SetLineStyle( PLOT_DASH_TYPE::SOLID ); // TODO?
1389 
1390  line->SetFlags( IS_NEW );
1391  m_currentSheet->GetScreen()->Append( line );
1392  }
1393  else
1394  {
1395  const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
1396 
1397  if( libSymbolIt == m_libSymbols.end() )
1398  {
1399  // TODO: e.g. can depend on Template (RECORD=39
1400  m_reporter->Report( wxString::Format( _( "Line's owner (%d) not found." ),
1401  elem.ownerindex ),
1403  return;
1404  }
1405 
1406  if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
1407  return;
1408 
1409  SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
1410  LIB_SHAPE* line = new LIB_SHAPE( libSymbolIt->second, SHAPE_T::POLY );
1411  libSymbolIt->second->AddDrawItem( line );
1412 
1413  line->SetUnit( elem.ownerpartid );
1414 
1415  line->AddPoint( GetRelativePosition( elem.point1 + m_sheetOffset, symbol ) );
1416  line->AddPoint( GetRelativePosition( elem.point2 + m_sheetOffset, symbol ) );
1417 
1418  line->SetWidth( elem.lineWidth );
1419  }
1420 }
void AddPoint(const wxPoint &aPosition)
Definition: lib_shape.cpp:407
const wxPoint GetRelativePosition(const wxPoint &aPosition, const SCH_SYMBOL *aSymbol)
#define IS_NEW
New item, just created.
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:305
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:269
std::map< int, SCH_SYMBOL * > m_symbols
#define _(s)
void SetWidth(int aWidth)
Definition: eda_shape.h:88
std::map< int, LIB_SYMBOL * > m_libSymbols
SCH_SHEET * m_currentSheet
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void SetUnit(int aUnit)
Definition: lib_item.h:257
Schematic symbol object.
Definition: sch_symbol.h:78
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
const int ALTIUM_COMPONENT_NONE
bool IsComponentPartVisible(int aOwnerindex, int aOwnerpartdisplaymode) const

References _, LIB_SHAPE::AddPoint(), ALTIUM_COMPONENT_NONE, SCH_SCREEN::Append(), Format(), GetRelativePosition(), SCH_SHEET::GetScreen(), IS_NEW, IsComponentPartVisible(), LAYER_NOTES, ASCH_LINE::lineWidth, m_currentSheet, m_libSymbols, m_reporter, m_sheetOffset, m_symbols, ASCH_LINE::ownerindex, ASCH_LINE::ownerpartdisplaymode, ASCH_LINE::ownerpartid, ASCH_LINE::point1, ASCH_LINE::point2, POLY, REPORTER::Report(), RPT_SEVERITY_ERROR, SCH_LINE::SetEndPoint(), EDA_ITEM::SetFlags(), SCH_LINE::SetLineStyle(), SCH_LINE::SetLineWidth(), LIB_ITEM::SetUnit(), EDA_SHAPE::SetWidth(), and SOLID.

Referenced by ParseFileHeader().

◆ ParseNetLabel()

void SCH_ALTIUM_PLUGIN::ParseNetLabel ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 2046 of file sch_altium_plugin.cpp.

2047 {
2048  ASCH_NET_LABEL elem( aProperties );
2049 
2050  SCH_LABEL* label = new SCH_LABEL( elem.location + m_sheetOffset, elem.text );
2051 
2052  switch( elem.orientation )
2053  {
2056  break;
2059  break;
2062  break;
2065  break;
2066  default:
2067  break;
2068  }
2069 
2070  label->SetFlags( IS_NEW );
2071  m_currentSheet->GetScreen()->Append( label );
2072 }
#define IS_NEW
New item, just created.
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
SCH_SHEET * m_currentSheet
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
virtual void SetLabelSpinStyle(LABEL_SPIN_STYLE aSpinStyle)
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:330

References SCH_SCREEN::Append(), LABEL_SPIN_STYLE::BOTTOM, DOWNWARDS, SCH_SHEET::GetScreen(), IS_NEW, LABEL_SPIN_STYLE::LEFT, LEFTWARDS, ASCH_NET_LABEL::location, m_currentSheet, m_sheetOffset, ASCH_NET_LABEL::orientation, LABEL_SPIN_STYLE::RIGHT, RIGHTWARDS, EDA_ITEM::SetFlags(), SCH_TEXT::SetLabelSpinStyle(), ASCH_NET_LABEL::text, LABEL_SPIN_STYLE::UP, and UPWARDS.

Referenced by ParseFileHeader().

◆ ParseNoERC()

void SCH_ALTIUM_PLUGIN::ParseNoERC ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 2032 of file sch_altium_plugin.cpp.

2033 {
2034  ASCH_NO_ERC elem( aProperties );
2035 
2036  if( elem.isActive )
2037  {
2038  SCH_NO_CONNECT* noConnect = new SCH_NO_CONNECT( elem.location + m_sheetOffset );
2039 
2040  noConnect->SetFlags( IS_NEW );
2041  m_currentSheet->GetScreen()->Append( noConnect );
2042  }
2043 }
#define IS_NEW
New item, just created.
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
SCH_SHEET * m_currentSheet
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146

References SCH_SCREEN::Append(), SCH_SHEET::GetScreen(), IS_NEW, ASCH_NO_ERC::isActive, ASCH_NO_ERC::location, m_currentSheet, m_sheetOffset, and EDA_ITEM::SetFlags().

Referenced by ParseFileHeader().

◆ ParseNote()

void SCH_ALTIUM_PLUGIN::ParseNote ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 928 of file sch_altium_plugin.cpp.

929 {
930  ASCH_NOTE elem( aProperties );
931 
932  SCH_TEXT* text = new SCH_TEXT( elem.location + m_sheetOffset, elem.text );
933 
934  switch( elem.alignment )
935  {
936  default:
938  text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::RIGHT );
939  break;
941  // No support for centered text in Eeschema yet...
942  text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::RIGHT );
943  break;
945  text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::LEFT );
946  break;
947  }
948 
949  // TODO: set size and word-wrap once KiCad supports wrapped text.
950 
951  // TODO: set border and background color once KiCad supports them.
952 
953  // TODO: need some sort of property system for storing author....
954 
955  size_t fontId = static_cast<int>( elem.fontId );
956 
957  if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() )
958  {
959  const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 );
960  text->SetItalic( font.italic );
961  text->SetBold( font.bold );
962  text->SetTextSize( { font.size / 2, font.size / 2 } );
963  }
964 
965  text->SetFlags( IS_NEW );
967 }
#define IS_NEW
New item, just created.
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
std::unique_ptr< ASCH_SHEET > m_altiumSheet
SCH_SHEET * m_currentSheet
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146

References ASCH_TEXT_FRAME::alignment, SCH_SCREEN::Append(), ASCH_SHEET_FONT::bold, CENTER, ASCH_TEXT_FRAME::fontId, fonts, SCH_SHEET::GetScreen(), IS_NEW, ASCH_SHEET_FONT::italic, LEFT, ASCH_TEXT_FRAME::location, m_altiumSheet, m_currentSheet, m_sheetOffset, RIGHT, ASCH_SHEET_FONT::size, ASCH_TEXT_FRAME::text, and text.

Referenced by ParseFileHeader().

◆ ParseParameter()

void SCH_ALTIUM_PLUGIN::ParseParameter ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 2323 of file sch_altium_plugin.cpp.

2324 {
2325  ASCH_PARAMETER elem( aProperties );
2326 
2327  // TODO: fill in replacements from variant, sheet and project
2328  std::map<wxString, wxString> variableMap = {
2329  { "COMMENT", "VALUE" },
2330  { "VALUE", "ALTIUM_VALUE" },
2331  };
2332 
2333  if( elem.ownerindex <= 0 && elem.ownerpartid == ALTIUM_COMPONENT_NONE )
2334  {
2335  // This is some sheet parameter
2336  if( elem.text == "*" )
2337  return; // indicates parameter not set?
2338 
2339  wxString paramName = elem.name.Upper();
2340 
2341  if( paramName == "SHEETNUMBER" )
2342  {
2343  SCH_SHEET_PATH sheetpath;
2345 
2346  m_rootSheet->SetPageNumber( sheetpath, elem.text );
2347  }
2348  else if( paramName == "TITLE" )
2349  {
2350  m_currentTitleBlock->SetTitle( elem.text );
2351  }
2352  else if( paramName == "REVISION" )
2353  {
2354  m_currentTitleBlock->SetRevision( elem.text );
2355  }
2356  else if( paramName == "DATE" )
2357  {
2358  m_currentTitleBlock->SetDate( elem.text );
2359  }
2360  else if( paramName == "COMPANYNAME" )
2361  {
2362  m_currentTitleBlock->SetCompany( elem.text );
2363  }
2364  else
2365  {
2366  m_schematic->Prj().GetTextVars()[ paramName ] = elem.text;
2367  }
2368  }
2369  else
2370  {
2371  const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
2372 
2373  if( libSymbolIt == m_libSymbols.end() )
2374  {
2375  // TODO: e.g. can depend on Template (RECORD=39
2376  return;
2377  }
2378 
2379  SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
2380  SCH_FIELD* field = nullptr;
2381 
2382  if( elem.name.Upper() == "COMMENT" )
2383  field = symbol->GetField( VALUE_FIELD );
2384  else
2385  {
2386  int fieldIdx = symbol->GetFieldCount();
2387  wxString fieldName = elem.name.Upper();
2388 
2389  if( fieldName == "VALUE" )
2390  fieldName = "ALTIUM_VALUE";
2391 
2392  field = symbol->AddField( SCH_FIELD( wxPoint(), fieldIdx, symbol, fieldName ) );
2393  }
2394 
2395  wxString kicadText = AltiumSpecialStringsToKiCadVariables( elem.text, variableMap );
2396  field->SetText( kicadText );
2397  field->SetPosition( elem.location + m_sheetOffset );
2398  field->SetVisible( !elem.isHidden );
2399  SetTextPositioning( field, elem.justification, elem.orientation );
2400  }
2401 }
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
virtual std::map< wxString, wxString > & GetTextVars() const
Definition: project.cpp:78
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:675
void SetTextPositioning(EDA_TEXT *text, ASCH_LABEL_JUSTIFICATION justification, ASCH_RECORD_ORIENTATION orientation)
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1166
virtual void SetVisible(bool aVisible)
Definition: eda_text.h:206
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
Definition: sch_symbol.cpp:721
Field Value of part, i.e. "3.3K".
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
std::map< int, SCH_SYMBOL * > m_symbols
int GetFieldCount() const
Return the number of fields in this symbol.
Definition: sch_symbol.h:424
std::map< int, LIB_SYMBOL * > m_libSymbols
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SHEET * m_currentSheet
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
bool LocatePathOfScreen(SCH_SCREEN *aScreen, SCH_SHEET_PATH *aList)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:688
Schematic symbol object.
Definition: sch_symbol.h:78
wxString AltiumSpecialStringsToKiCadVariables(const wxString &aString, const std::map< wxString, wxString > &aOverrides)
const int ALTIUM_COMPONENT_NONE
void SetPosition(const wxPoint &aPosition) override
Definition: sch_field.cpp:822
std::unique_ptr< TITLE_BLOCK > m_currentTitleBlock

References SCH_SYMBOL::AddField(), ALTIUM_COMPONENT_NONE, AltiumSpecialStringsToKiCadVariables(), SCH_SYMBOL::GetField(), SCH_SYMBOL::GetFieldCount(), SCH_SHEET::GetScreen(), PROJECT::GetTextVars(), ASCH_PARAMETER::isHidden, ASCH_PARAMETER::justification, SCH_SHEET::LocatePathOfScreen(), ASCH_PARAMETER::location, m_currentSheet, m_currentTitleBlock, m_libSymbols, m_rootSheet, m_schematic, m_sheetOffset, m_symbols, ASCH_PARAMETER::name, ASCH_PARAMETER::orientation, ASCH_PARAMETER::ownerindex, ASCH_PARAMETER::ownerpartid, SCHEMATIC::Prj(), SCH_SHEET::SetPageNumber(), SCH_FIELD::SetPosition(), EDA_TEXT::SetText(), SetTextPositioning(), EDA_TEXT::SetVisible(), ASCH_PARAMETER::text, and VALUE_FIELD.

Referenced by ParseFileHeader().

◆ ParsePin()

void SCH_ALTIUM_PLUGIN::ParsePin ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 595 of file sch_altium_plugin.cpp.

596 {
597  ASCH_PIN elem( aProperties );
598 
599  const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
600 
601  if( libSymbolIt == m_libSymbols.end() )
602  {
603  // TODO: e.g. can depend on Template (RECORD=39
604  m_reporter->Report( wxString::Format( _( "Pin's owner (%d) not found." ), elem.ownerindex ),
606  return;
607  }
608 
609  if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
610  return;
611 
612  SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
613  LIB_PIN* pin = new LIB_PIN( libSymbolIt->second );
614  libSymbolIt->second->AddDrawItem( pin );
615 
616  pin->SetUnit( elem.ownerpartid );
617 
618  pin->SetName( elem.name );
619  pin->SetNumber( elem.designator );
620  pin->SetLength( elem.pinlength );
621 
622  if( !elem.showDesignator )
623  pin->SetNumberTextSize( 0 );
624 
625  if( !elem.showPinName )
626  pin->SetNameTextSize( 0 );
627 
628  wxPoint pinLocation = elem.location; // the location given is not the connection point!
629 
630  switch( elem.orientation )
631  {
633  pin->SetOrientation( DrawPinOrient::PIN_LEFT );
634  pinLocation.x += elem.pinlength;
635  break;
637  pin->SetOrientation( DrawPinOrient::PIN_DOWN );
638  pinLocation.y -= elem.pinlength;
639  break;
641  pin->SetOrientation( DrawPinOrient::PIN_RIGHT );
642  pinLocation.x -= elem.pinlength;
643  break;
645  pin->SetOrientation( DrawPinOrient::PIN_UP );
646  pinLocation.y += elem.pinlength;
647  break;
648  default:
649  m_reporter->Report( _( "Pin has unexpected orientation." ), RPT_SEVERITY_WARNING );
650  break;
651  }
652 
653  // TODO: position can be sometimes off a little bit!
654  pin->SetPosition( GetRelativePosition( pinLocation + m_sheetOffset, symbol ) );
655 
656  // TODO: the following fix is even worse for now?
657  // pin->SetPosition( GetRelativePosition( elem.kicadLocation, symbol ) );
658 
659  switch( elem.electrical )
660  {
662  pin->SetType( ELECTRICAL_PINTYPE::PT_INPUT );
663  break;
665  pin->SetType( ELECTRICAL_PINTYPE::PT_BIDI );
666  break;
669  break;
672  break;
675  break;
678  break;
681  break;
684  break;
686  default:
688  m_reporter->Report( _( "Pin has unexpected electrical type." ), RPT_SEVERITY_WARNING );
689  break;
690  }
691 
692  if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL_OUTEREDGE::UNKNOWN )
693  m_reporter->Report( _( "Pin has unexpected outer edge type." ), RPT_SEVERITY_WARNING );
694 
695  if( elem.symbolInnerEdge == ASCH_PIN_SYMBOL_INNEREDGE::UNKNOWN )
696  m_reporter->Report( _( "Pin has unexpected inner edge type." ), RPT_SEVERITY_WARNING );
697 
698  if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL_OUTEREDGE::NEGATED )
699  {
700  switch( elem.symbolInnerEdge )
701  {
704  break;
705  default:
706  pin->SetShape( GRAPHIC_PINSHAPE::INVERTED );
707  break;
708  }
709  }
710  else if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL_OUTEREDGE::LOW_INPUT )
711  {
712  switch( elem.symbolInnerEdge )
713  {
715  pin->SetShape( GRAPHIC_PINSHAPE::CLOCK_LOW );
716  break;
717  default:
718  pin->SetShape( GRAPHIC_PINSHAPE::INPUT_LOW );
719  break;
720  }
721  }
722  else if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL_OUTEREDGE::LOW_OUTPUT )
723  {
724  pin->SetShape( GRAPHIC_PINSHAPE::OUTPUT_LOW );
725  }
726  else
727  {
728  switch( elem.symbolInnerEdge )
729  {
731  pin->SetShape( GRAPHIC_PINSHAPE::CLOCK );
732  break;
733  default:
734  pin->SetShape( GRAPHIC_PINSHAPE::LINE ); // nothing to do
735  break;
736  }
737  }
738 }
power input (GND, VCC for ICs). Must be connected to a power output.
const wxPoint GetRelativePosition(const wxPoint &aPosition, const SCH_SYMBOL *aSymbol)
pin for passive symbols: must be connected, and can be connected to any pin
unknown electrical properties: creates always a warning when connected
Definition: lib_pin.h:48
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
std::map< int, SCH_SYMBOL * > m_symbols
#define _(s)
std::map< int, LIB_SYMBOL * > m_libSymbols
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Schematic symbol object.
Definition: sch_symbol.h:78
usual pin input: must be connected
input or output (like port for a microprocessor)
bool IsComponentPartVisible(int aOwnerindex, int aOwnerpartdisplaymode) const

References _, BIDI, CLOCK, CLOCK_LOW, ASCH_PIN::designator, DOWNWARDS, ASCH_PIN::electrical, Format(), GetRelativePosition(), INPUT, INPUT_LOW, INVERTED, INVERTED_CLOCK, IsComponentPartVisible(), LEFTWARDS, LINE, ASCH_PIN::location, LOW_INPUT, LOW_OUTPUT, m_libSymbols, m_reporter, m_sheetOffset, m_symbols, ASCH_PIN::name, NEGATED, OPEN_COLLECTOR, OPEN_EMITTER, ASCH_PIN::orientation, OUTPUT, OUTPUT_LOW, ASCH_PIN::ownerindex, ASCH_PIN::ownerpartdisplaymode, ASCH_PIN::ownerpartid, PASSIVE, pin, PIN_DOWN, PIN_LEFT, PIN_RIGHT, PIN_UP, ASCH_PIN::pinlength, POWER, PT_BIDI, PT_INPUT, PT_OPENCOLLECTOR, PT_OPENEMITTER, PT_OUTPUT, PT_PASSIVE, PT_POWER_IN, PT_TRISTATE, PT_UNSPECIFIED, REPORTER::Report(), RIGHTWARDS, RPT_SEVERITY_ERROR, RPT_SEVERITY_WARNING, ASCH_PIN::showDesignator, ASCH_PIN::showPinName, ASCH_PIN::symbolInnerEdge, ASCH_PIN::symbolOuterEdge, TRISTATE, UNKNOWN, and UPWARDS.

Referenced by ParseFileHeader().

◆ ParsePolygon()

void SCH_ALTIUM_PLUGIN::ParsePolygon ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 1169 of file sch_altium_plugin.cpp.

1170 {
1171  ASCH_POLYGON elem( aProperties );
1172 
1173  if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
1174  {
1175  // TODO: we cannot fill this polygon, only draw it for now
1176  for( size_t i = 0; i + 1 < elem.points.size(); i++ )
1177  {
1178  SCH_LINE* line = new SCH_LINE( elem.points.at( i ) + m_sheetOffset,
1180  line->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
1181  line->SetLineWidth( elem.lineWidth );
1183 
1184  line->SetFlags( IS_NEW );
1185  m_currentSheet->GetScreen()->Append( line );
1186  }
1187 
1188  // close polygon
1189  SCH_LINE* line = new SCH_LINE( elem.points.front() + m_sheetOffset,
1191  line->SetEndPoint( elem.points.back() + m_sheetOffset );
1192  line->SetLineWidth( elem.lineWidth );
1194 
1195  line->SetFlags( IS_NEW );
1196  m_currentSheet->GetScreen()->Append( line );
1197  }
1198  else
1199  {
1200  const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
1201 
1202  if( libSymbolIt == m_libSymbols.end() )
1203  {
1204  // TODO: e.g. can depend on Template (RECORD=39
1205  m_reporter->Report( wxString::Format( _( "Polygon's owner (%d) not found." ),
1206  elem.ownerindex ),
1208  return;
1209  }
1210 
1211  if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
1212  return;
1213 
1214  SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
1215  LIB_SHAPE* line = new LIB_SHAPE( libSymbolIt->second, SHAPE_T::POLY );
1216  libSymbolIt->second->AddDrawItem( line );
1217 
1218  line->SetUnit( elem.ownerpartid );
1219 
1220  for( wxPoint& point : elem.points )
1221  line->AddPoint( GetRelativePosition( point + m_sheetOffset, symbol ) );
1222 
1223  line->AddPoint( GetRelativePosition( elem.points.front() + m_sheetOffset, symbol ) );
1224 
1225  line->SetWidth( elem.lineWidth );
1226 
1227  if( !elem.isSolid )
1228  line->SetFillMode( FILL_T::NO_FILL );
1229  else if( elem.color == elem.areacolor )
1231  else
1233  }
1234 }
void AddPoint(const wxPoint &aPosition)
Definition: lib_shape.cpp:407
const wxPoint GetRelativePosition(const wxPoint &aPosition, const SCH_SYMBOL *aSymbol)
#define IS_NEW
New item, just created.
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:305
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:269
std::map< int, SCH_SYMBOL * > m_symbols
#define _(s)
void SetWidth(int aWidth)
Definition: eda_shape.h:88
std::map< int, LIB_SYMBOL * > m_libSymbols
SCH_SHEET * m_currentSheet
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void SetUnit(int aUnit)
Definition: lib_item.h:257
Schematic symbol object.
Definition: sch_symbol.h:78
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:78
const int ALTIUM_COMPONENT_NONE
bool IsComponentPartVisible(int aOwnerindex, int aOwnerpartdisplaymode) const

References _, LIB_SHAPE::AddPoint(), ALTIUM_COMPONENT_NONE, SCH_SCREEN::Append(), ASCH_POLYGON::areacolor, ASCH_POLYGON::color, FILLED_SHAPE, FILLED_WITH_BG_BODYCOLOR, Format(), GetRelativePosition(), SCH_SHEET::GetScreen(), IS_NEW, IsComponentPartVisible(), ASCH_POLYGON::isSolid, LAYER_NOTES, ASCH_POLYGON::lineWidth, m_currentSheet, m_libSymbols, m_reporter, m_sheetOffset, m_symbols, NO_FILL, ASCH_POLYGON::ownerindex, ASCH_POLYGON::ownerpartdisplaymode, ASCH_POLYGON::ownerpartid, ASCH_POLYGON::points, POLY, REPORTER::Report(), RPT_SEVERITY_ERROR, SCH_LINE::SetEndPoint(), EDA_SHAPE::SetFillMode(), EDA_ITEM::SetFlags(), SCH_LINE::SetLineStyle(), SCH_LINE::SetLineWidth(), LIB_ITEM::SetUnit(), EDA_SHAPE::SetWidth(), and SOLID.

Referenced by ParseFileHeader().

◆ ParsePolyline()

void SCH_ALTIUM_PLUGIN::ParsePolyline ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 1110 of file sch_altium_plugin.cpp.

1111 {
1112  ASCH_POLYLINE elem( aProperties );
1113 
1114  if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
1115  {
1117  switch( elem.linestyle )
1118  {
1119  default:
1120  case ASCH_POLYLINE_LINESTYLE::SOLID: dashType = PLOT_DASH_TYPE::SOLID; break;
1121  case ASCH_POLYLINE_LINESTYLE::DASHED: dashType = PLOT_DASH_TYPE::DASH; break;
1122  case ASCH_POLYLINE_LINESTYLE::DOTTED: dashType = PLOT_DASH_TYPE::DOT; break;
1124  }
1125 
1126  for( size_t i = 0; i + 1 < elem.points.size(); i++ )
1127  {
1128  SCH_LINE* line = new SCH_LINE( elem.points.at( i ) + m_sheetOffset,
1130 
1131  line->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
1132  line->SetLineWidth( elem.lineWidth );
1133  line->SetLineStyle( dashType );
1134 
1135  line->SetFlags( IS_NEW );
1136  m_currentSheet->GetScreen()->Append( line );
1137  }
1138  }
1139  else
1140  {
1141  const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
1142 
1143  if( libSymbolIt == m_libSymbols.end() )
1144  {
1145  // TODO: e.g. can depend on Template (RECORD=39
1146  m_reporter->Report( wxString::Format( _( "Polyline's owner (%d) not found." ),
1147  elem.ownerindex ),
1149  return;
1150  }
1151 
1152  if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
1153  return;
1154 
1155  SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
1156  LIB_SHAPE* line = new LIB_SHAPE( libSymbolIt->second, SHAPE_T::POLY );
1157  libSymbolIt->second->AddDrawItem( line );
1158 
1159  line->SetUnit( elem.ownerpartid );
1160 
1161  for( wxPoint& point : elem.points )
1162  line->AddPoint( GetRelativePosition( point + m_sheetOffset, symbol ) );
1163 
1164  line->SetWidth( elem.lineWidth );
1165  }
1166 }
void AddPoint(const wxPoint &aPosition)
Definition: lib_shape.cpp:407
const wxPoint GetRelativePosition(const wxPoint &aPosition, const SCH_SYMBOL *aSymbol)
#define IS_NEW
New item, just created.
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:305
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:269
std::map< int, SCH_SYMBOL * > m_symbols
#define _(s)
void SetWidth(int aWidth)
Definition: eda_shape.h:88
std::map< int, LIB_SYMBOL * > m_libSymbols
SCH_SHEET * m_currentSheet
PLOT_DASH_TYPE
Dashed line types.
Definition: plotter.h:104
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void SetUnit(int aUnit)
Definition: lib_item.h:257
Schematic symbol object.
Definition: sch_symbol.h:78
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
const int ALTIUM_COMPONENT_NONE
bool IsComponentPartVisible(int aOwnerindex, int aOwnerpartdisplaymode) const

References _, LIB_SHAPE::AddPoint(), ALTIUM_COMPONENT_NONE, SCH_SCREEN::Append(), DASH, DASH_DOTTED, DASHDOT, DASHED, DEFAULT, DOT, DOTTED, Format(), GetRelativePosition(), SCH_SHEET::GetScreen(), IS_NEW, IsComponentPartVisible(), LAYER_NOTES, ASCH_POLYLINE::linestyle, ASCH_POLYLINE::lineWidth, m_currentSheet, m_libSymbols, m_reporter, m_sheetOffset, m_symbols, ASCH_POLYLINE::ownerindex, ASCH_POLYLINE::ownerpartdisplaymode, ASCH_POLYLINE::ownerpartid, ASCH_POLYLINE::points, POLY, REPORTER::Report(), RPT_SEVERITY_ERROR, SCH_LINE::SetEndPoint(), EDA_ITEM::SetFlags(), SCH_LINE::SetLineStyle(), SCH_LINE::SetLineWidth(), LIB_ITEM::SetUnit(), EDA_SHAPE::SetWidth(), and SOLID.

Referenced by ParseFileHeader().

◆ ParsePort()

void SCH_ALTIUM_PLUGIN::ParsePort ( const ASCH_PORT aElem)
private

Definition at line 1901 of file sch_altium_plugin.cpp.

1902 {
1903  bool isHarness = !aElem.harnessType.IsEmpty();
1904  wxPoint start = aElem.location + m_sheetOffset;
1905  wxPoint end = start;
1906 
1907  switch( aElem.style )
1908  {
1909  default:
1911  case ASCH_PORT_STYLE::LEFT:
1914  end.x += aElem.width;
1915  break;
1917  case ASCH_PORT_STYLE::TOP:
1920  end.y -= aElem.width;
1921  break;
1922  }
1923 
1924  // Check which connection points exists in the schematic
1925  SCH_SCREEN* screen = m_currentSheet->GetScreen();
1926 
1927  bool startIsWireTerminal = screen->IsTerminalPoint( start, LAYER_WIRE );
1928  bool startIsBusTerminal = screen->IsTerminalPoint( start, LAYER_BUS );
1929 
1930  bool endIsWireTerminal = screen->IsTerminalPoint( end, LAYER_WIRE );
1931  bool endIsBusTerminal = screen->IsTerminalPoint( end, LAYER_BUS );
1932 
1933  // check if any of the points is a terminal point
1934  // TODO: there seems a problem to detect approximated connections towards component pins?
1935  bool connectionFound = startIsWireTerminal
1936  || startIsBusTerminal
1937  || endIsWireTerminal
1938  || endIsBusTerminal;
1939 
1940  if( !isHarness && !connectionFound )
1941  {
1942  m_reporter->Report( wxString::Format( _( "Port %s has no connections." ), aElem.name ),
1944  }
1945 
1946  // Select label position. In case both match, we will add a line later.
1947  wxPoint position = ( startIsWireTerminal || startIsBusTerminal ) ? start : end;
1948  SCH_TEXT* label;
1949 
1950  if( isHarness )
1951  {
1952  wxString name = wxT( "HARNESS: " ) + aElem.name;
1953 
1954  if( aElem.harnessType != aElem.name )
1955  name += wxString::Format( wxT( " (%s)" ), aElem.harnessType );
1956 
1957  label = new SCH_TEXT( position, name );
1958  }
1959  // TODO: detect correct label type depending on sheet settings, etc.
1960  //{
1961  // label = new SCH_HIERLABEL( elem.location + m_sheetOffset, elem.name );
1962  //}
1963  else
1964  {
1965 
1966  label = new SCH_GLOBALLABEL( position, aElem.name );
1967  }
1968 
1969  switch( aElem.iotype )
1970  {
1971  default:
1974  break;
1977  break;
1980  break;
1983  break;
1984  }
1985 
1986  switch( aElem.style )
1987  {
1988  default:
1990  case ASCH_PORT_STYLE::LEFT:
1993  if( ( startIsWireTerminal || startIsBusTerminal ) )
1995  else
1997  break;
1999  case ASCH_PORT_STYLE::TOP:
2002  if( ( startIsWireTerminal || startIsBusTerminal ) )
2004  else
2006  break;
2007  }
2008 
2009  label->SetFlags( IS_NEW );
2010  m_currentSheet->GetScreen()->Append( label );
2011 
2012  // This is a hack, for the case both connection points are valid: add a small wire
2013  if( ( startIsWireTerminal && endIsWireTerminal ) )
2014  {
2015  SCH_LINE* wire = new SCH_LINE( start, SCH_LAYER_ID::LAYER_WIRE );
2016  wire->SetEndPoint( end );
2017  wire->SetLineWidth( Mils2iu( 2 ) );
2018  wire->SetFlags( IS_NEW );
2019  m_currentSheet->GetScreen()->Append( wire );
2020  }
2021  else if( startIsBusTerminal && endIsBusTerminal )
2022  {
2023  SCH_LINE* wire = new SCH_LINE( start, SCH_LAYER_ID::LAYER_BUS );
2024  wire->SetEndPoint( end );
2025  wire->SetLineWidth( Mils2iu( 2 ) );
2026  wire->SetFlags( IS_NEW );
2027  m_currentSheet->GetScreen()->Append( wire );
2028  }
2029 }
wxPoint location
void SetShape(PINSHEETLABEL_SHAPE aShape)
Definition: sch_text.h:163
#define IS_NEW
New item, just created.
bool IsTerminalPoint(const wxPoint &aPosition, int aLayer) const
Test if aPosition is a connection point on aLayer.
Definition: sch_screen.cpp:545
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:305
wxString harnessType
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
ASCH_PORT_STYLE style
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
#define _(s)
SCH_SHEET * m_currentSheet
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
ASCH_PORT_IOTYPE iotype
const char * name
Definition: DXF_plotter.cpp:56
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
virtual void SetLabelSpinStyle(LABEL_SPIN_STYLE aSpinStyle)
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:330

References _, SCH_SCREEN::Append(), BIDI, LABEL_SPIN_STYLE::BOTTOM, BOTTOM, Format(), SCH_SHEET::GetScreen(), ASCH_PORT::harnessType, INPUT, ASCH_PORT::iotype, IS_NEW, SCH_SCREEN::IsTerminalPoint(), LAYER_BUS, LAYER_WIRE, LABEL_SPIN_STYLE::LEFT, LEFT, LEFT_RIGHT, ASCH_PORT::location, m_currentSheet, m_reporter, m_sheetOffset, name, ASCH_PORT::name, NONE_HORIZONTAL, NONE_VERTICAL, OUTPUT, PS_BIDI, PS_INPUT, PS_OUTPUT, PS_UNSPECIFIED, REPORTER::Report(), LABEL_SPIN_STYLE::RIGHT, RIGHT, RPT_SEVERITY_WARNING, SCH_LINE::SetEndPoint(), EDA_ITEM::SetFlags(), SCH_TEXT::SetLabelSpinStyle(), SCH_LINE::SetLineWidth(), SCH_TEXT::SetShape(), ASCH_PORT::style, TOP, TOP_BOTTOM, UNSPECIFIED, LABEL_SPIN_STYLE::UP, and ASCH_PORT::width.

Referenced by ParseFileHeader().

◆ ParsePowerPort()

void SCH_ALTIUM_PLUGIN::ParsePowerPort ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 1806 of file sch_altium_plugin.cpp.

1807 {
1808  ASCH_POWER_PORT elem( aProperties );
1809  LIB_ID libId = AltiumToKiCadLibID( getLibName(), elem.text );
1810  LIB_SYMBOL* libSymbol = nullptr;
1811 
1812  const auto& powerSymbolIt = m_powerSymbols.find( elem.text );
1813 
1814  if( powerSymbolIt != m_powerSymbols.end() )
1815  {
1816  libSymbol = powerSymbolIt->second; // cache hit
1817  }
1818  else
1819  {
1820  libSymbol = new LIB_SYMBOL( wxEmptyString );
1821  libSymbol->SetPower();
1822  libSymbol->SetName( elem.text );
1823  libSymbol->GetReferenceField().SetText( "#PWR" );
1824  libSymbol->GetValueField().SetText( elem.text );
1825  libSymbol->GetValueField().SetVisible( true );
1826  libSymbol->SetDescription( wxString::Format( _( "Power symbol creates a global "
1827  "label with name '%s'" ), elem.text ) );
1828  libSymbol->SetKeyWords( "power-flag" );
1829  libSymbol->SetLibId( libId );
1830 
1831  // generate graphic
1832  LIB_PIN* pin = new LIB_PIN( libSymbol );
1833  libSymbol->AddDrawItem( pin );
1834 
1835  pin->SetName( elem.text );
1836  pin->SetPosition( { 0, 0 } );
1837  pin->SetLength( 0 );
1838 
1839  // marks the pin as a global label
1841  pin->SetVisible( false );
1842 
1843  wxPoint valueFieldPos = HelperGeneratePowerPortGraphics( libSymbol, elem.style, m_reporter );
1844 
1845  libSymbol->GetValueField().SetPosition( valueFieldPos );
1846 
1847  // this has to be done after parsing the LIB_SYMBOL!
1848  m_pi->SaveSymbol( getLibFileName().GetFullPath(), libSymbol, m_properties.get() );
1849  m_powerSymbols.insert( { elem.text, libSymbol } );
1850  }
1851 
1852  SCH_SHEET_PATH sheetpath;
1854 
1855  // each symbol has its own powerSymbolIt for now
1856  SCH_SYMBOL* symbol = new SCH_SYMBOL();
1857  symbol->SetRef( &sheetpath, "#PWR?" );
1858  symbol->SetValue( elem.text );
1859  symbol->SetLibId( libId );
1860  symbol->SetLibSymbol( new LIB_SYMBOL( *libSymbol ) );
1861 
1862  SCH_FIELD* valueField = symbol->GetField( VALUE_FIELD );
1863  valueField->SetVisible( elem.showNetName );
1864 
1865  // TODO: Why do I need to set this a second time?
1866  valueField->SetPosition( libSymbol->GetValueField().GetPosition() );
1867 
1868  symbol->SetPosition( elem.location + m_sheetOffset );
1869 
1870  switch( elem.orientation )
1871  {
1874  valueField->SetTextAngle( TEXT_ANGLE_VERT );
1876  break;
1879  valueField->SetTextAngle( TEXT_ANGLE_HORIZ );
1881  break;
1884  valueField->SetTextAngle( TEXT_ANGLE_VERT );
1886  break;
1889  valueField->SetTextAngle( TEXT_ANGLE_HORIZ );
1891  break;
1892  default:
1893  m_reporter->Report( _( "Pin has unexpected orientation." ), RPT_SEVERITY_WARNING );
1894  break;
1895  }
1896 
1897  m_currentSheet->GetScreen()->Append( symbol );
1898 }
power input (GND, VCC for ICs). Must be connected to a power output.
#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
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
std::unique_ptr< PROPERTIES > m_properties
void SetPosition(const wxPoint &aPosition) override
Definition: sch_symbol.h:645
void SetOrientation(int aOrientation)
Compute the new transform matrix based on aOrientation for the symbol which is applied to the current...
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:675
wxPoint GetPosition() const override
Definition: lib_field.h:157
void SetValue(const SCH_SHEET_PATH *sheet, const wxString &aValue)
Definition: sch_symbol.cpp:594
std::map< wxString, LIB_SYMBOL * > m_powerSymbols
void SetLibId(const LIB_ID &aName)
Definition: sch_symbol.cpp:238
LIB_FIELD & GetValueField()
Return reference to the value field.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
Define a library symbol object.
Definition: lib_symbol.h:96
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
Definition: sch_symbol.cpp:257
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
virtual void SetVisible(bool aVisible)
Definition: eda_text.h:206
Field Value of part, i.e. "3.3K".
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
wxFileName getLibFileName()
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:313
void SetDescription(const wxString &aDescription)
Definition: lib_symbol.h:140
#define _(s)
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:665
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void SetLibId(const LIB_ID &aLibId)
Definition: lib_symbol.h:136
SCH_SHEET * m_currentSheet
wxPoint HelperGeneratePowerPortGraphics(LIB_SYMBOL *aKsymbol, ASCH_POWER_PORT_STYLE aStyle, REPORTER *aReporter)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
bool LocatePathOfScreen(SCH_SCREEN *aScreen, SCH_SHEET_PATH *aList)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:688
LIB_ID AltiumToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
Schematic symbol object.
Definition: sch_symbol.h:78
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:222
void SetPower()
Definition: lib_symbol.cpp:417
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:481
void SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:222
#define TEXT_ANGLE_VERT
Definition: eda_text.h:72
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:188
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
void SetPosition(const wxPoint &aPosition) override
Definition: sch_field.cpp:822
void SetKeyWords(const wxString &aKeyWords)
Definition: lib_symbol.h:153

References _, LIB_SYMBOL::AddDrawItem(), AltiumToKiCadLibID(), SCH_SCREEN::Append(), DOWNWARDS, Format(), SCH_SYMBOL::GetField(), getLibFileName(), getLibName(), LIB_FIELD::GetPosition(), LIB_SYMBOL::GetReferenceField(), SCH_SHEET::GetScreen(), LIB_SYMBOL::GetValueField(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_RIGHT, HelperGeneratePowerPortGraphics(), LEFTWARDS, SCH_SHEET::LocatePathOfScreen(), ASCH_POWER_PORT::location, m_currentSheet, m_pi, m_powerSymbols, m_properties, m_reporter, m_rootSheet, m_sheetOffset, ASCH_POWER_PORT::orientation, pin, PT_POWER_IN, REPORTER::Report(), RIGHTWARDS, RPT_SEVERITY_WARNING, LIB_SYMBOL::SetDescription(), EDA_TEXT::SetHorizJustify(), LIB_SYMBOL::SetKeyWords(), LIB_SYMBOL::SetLibId(), SCH_SYMBOL::SetLibId(), SCH_SYMBOL::SetLibSymbol(), LIB_SYMBOL::SetName(), SCH_SYMBOL::SetOrientation(), SCH_FIELD::SetPosition(), LIB_ITEM::SetPosition(), SCH_SYMBOL::SetPosition(), LIB_SYMBOL::SetPower(), SCH_SYMBOL::SetRef(), EDA_TEXT::SetText(), EDA_TEXT::SetTextAngle(), SCH_SYMBOL::SetValue(), EDA_TEXT::SetVisible(), ASCH_POWER_PORT::showNetName, ASCH_POWER_PORT::style, SYM_ORIENT_0, SYM_ORIENT_180, SYM_ORIENT_270, SYM_ORIENT_90, ASCH_POWER_PORT::text, TEXT_ANGLE_HORIZ, TEXT_ANGLE_VERT, UPWARDS, and VALUE_FIELD.

Referenced by ParseFileHeader().

◆ ParseRectangle()

void SCH_ALTIUM_PLUGIN::ParseRectangle ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 1423 of file sch_altium_plugin.cpp.

1424 {
1425  ASCH_RECTANGLE elem( aProperties );
1426 
1427  wxPoint sheetTopRight = elem.topRight + m_sheetOffset;
1428  wxPoint sheetBottomLeft = elem.bottomLeft + m_sheetOffset;
1429 
1430  if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
1431  {
1432  const wxPoint topLeft = { sheetBottomLeft.x, sheetTopRight.y };
1433  const wxPoint bottomRight = { sheetTopRight.x, sheetBottomLeft.y };
1434 
1435  // TODO: we cannot fill this rectangle, only draw it for now
1436  SCH_LINE* lineTop = new SCH_LINE( sheetTopRight, SCH_LAYER_ID::LAYER_NOTES );
1437  lineTop->SetEndPoint( topLeft );
1438  lineTop->SetLineWidth( elem.lineWidth );
1439  lineTop->SetLineStyle( PLOT_DASH_TYPE::SOLID );
1440  lineTop->SetFlags( IS_NEW );
1441  m_currentSheet->GetScreen()->Append( lineTop );
1442 
1443  SCH_LINE* lineBottom = new SCH_LINE( sheetBottomLeft, SCH_LAYER_ID::LAYER_NOTES );
1444  lineBottom->SetEndPoint( bottomRight );
1445  lineBottom->SetLineWidth( elem.lineWidth );
1446  lineBottom->SetLineStyle( PLOT_DASH_TYPE::SOLID );
1447  lineBottom->SetFlags( IS_NEW );
1448  m_currentSheet->GetScreen()->Append( lineBottom );
1449 
1450  SCH_LINE* lineRight = new SCH_LINE( sheetTopRight, SCH_LAYER_ID::LAYER_NOTES );
1451  lineRight->SetEndPoint( bottomRight );
1452  lineRight->SetLineWidth( elem.lineWidth );
1453  lineRight->SetLineStyle( PLOT_DASH_TYPE::SOLID );
1454  lineRight->SetFlags( IS_NEW );
1455  m_currentSheet->GetScreen()->Append( lineRight );
1456 
1457  SCH_LINE* lineLeft = new SCH_LINE( sheetBottomLeft, SCH_LAYER_ID::LAYER_NOTES );
1458  lineLeft->SetEndPoint( topLeft );
1459  lineLeft->SetLineWidth( elem.lineWidth );
1460  lineLeft->SetLineStyle( PLOT_DASH_TYPE::SOLID );
1461  lineLeft->SetFlags( IS_NEW );
1462  m_currentSheet->GetScreen()->Append( lineLeft );
1463  }
1464  else
1465  {
1466  const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
1467 
1468  if( libSymbolIt == m_libSymbols.end() )
1469  {
1470  // TODO: e.g. can depend on Template (RECORD=39
1471  m_reporter->Report( wxString::Format( _( "Rectangle's owner (%d) not found." ),
1472  elem.ownerindex ),
1474  return;
1475  }
1476 
1477  if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
1478  return;
1479 
1480  SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
1481  LIB_SHAPE* rect = new LIB_SHAPE( libSymbolIt->second, SHAPE_T::RECT );
1482  libSymbolIt->second->AddDrawItem( rect );
1483 
1484  rect->SetUnit( elem.ownerpartid );
1485 
1486  rect->SetPosition( GetRelativePosition( sheetTopRight, symbol ) );
1487  rect->SetEnd( GetRelativePosition( sheetBottomLeft, symbol ) );
1488  rect->SetWidth( elem.lineWidth );
1489 
1490  if( !elem.isSolid )
1491  rect->SetFillMode( FILL_T::NO_FILL );
1492  else if( elem.color == elem.areacolor )
1494  else
1496  }
1497 }
const wxPoint GetRelativePosition(const wxPoint &aPosition, const SCH_SYMBOL *aSymbol)
void SetEnd(const wxPoint &aEnd)
Definition: eda_shape.h:126
#define IS_NEW
New item, just created.
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:305
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
void SetPosition(const wxPoint &aPosition) override
Definition: lib_shape.h:87
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:269
std::map< int, SCH_SYMBOL * > m_symbols
#define _(s)
void SetWidth(int aWidth)
Definition: eda_shape.h:88
std::map< int, LIB_SYMBOL * > m_libSymbols
SCH_SHEET * m_currentSheet
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void SetUnit(int aUnit)
Definition: lib_item.h:257
Schematic symbol object.
Definition: sch_symbol.h:78
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:78
const int ALTIUM_COMPONENT_NONE
bool IsComponentPartVisible(int aOwnerindex, int aOwnerpartdisplaymode) const

References _, ALTIUM_COMPONENT_NONE, SCH_SCREEN::Append(), ASCH_RECTANGLE::areacolor, ASCH_RECTANGLE::bottomLeft, ASCH_RECTANGLE::color, FILLED_SHAPE, FILLED_WITH_BG_BODYCOLOR, Format(), GetRelativePosition(), SCH_SHEET::GetScreen(), IS_NEW, IsComponentPartVisible(), ASCH_RECTANGLE::isSolid, LAYER_NOTES, ASCH_RECTANGLE::lineWidth, m_currentSheet, m_libSymbols, m_reporter, m_sheetOffset, m_symbols, NO_FILL, ASCH_RECTANGLE::ownerindex, ASCH_RECTANGLE::ownerpartdisplaymode, ASCH_RECTANGLE::ownerpartid, RECT, REPORTER::Report(), RPT_SEVERITY_ERROR, EDA_SHAPE::SetEnd(), SCH_LINE::SetEndPoint(), EDA_SHAPE::SetFillMode(), EDA_ITEM::SetFlags(), SCH_LINE::SetLineStyle(), SCH_LINE::SetLineWidth(), LIB_SHAPE::SetPosition(), LIB_ITEM::SetUnit(), EDA_SHAPE::SetWidth(), SOLID, and ASCH_RECTANGLE::topRight.

Referenced by ParseFileHeader().

◆ ParseRoundRectangle()

void SCH_ALTIUM_PLUGIN::ParseRoundRectangle ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 1237 of file sch_altium_plugin.cpp.

1238 {
1239  ASCH_ROUND_RECTANGLE elem( aProperties );
1240 
1241  wxPoint sheetTopRight = elem.topRight + m_sheetOffset;
1242  wxPoint sheetBottomLeft = elem.bottomLeft + m_sheetOffset;
1243 
1244  if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
1245  {
1246  const wxPoint topLeft = { sheetBottomLeft.x, sheetTopRight.y };
1247  const wxPoint bottomRight = { sheetTopRight.x, sheetBottomLeft.y };
1248 
1249  // TODO: we cannot fill this rectangle, only draw it for now
1250  // TODO: misses rounded edges
1251  SCH_LINE* lineTop = new SCH_LINE( sheetTopRight, SCH_LAYER_ID::LAYER_NOTES );
1252  lineTop->SetEndPoint( topLeft );
1253  lineTop->SetLineWidth( elem.lineWidth );
1254  lineTop->SetLineStyle( PLOT_DASH_TYPE::SOLID );
1255  lineTop->SetFlags( IS_NEW );
1256  m_currentSheet->GetScreen()->Append( lineTop );
1257 
1258  SCH_LINE* lineBottom = new SCH_LINE( sheetBottomLeft, SCH_LAYER_ID::LAYER_NOTES );
1259  lineBottom->SetEndPoint( bottomRight );
1260  lineBottom->SetLineWidth( elem.lineWidth );
1261  lineBottom->SetLineStyle( PLOT_DASH_TYPE::SOLID );
1262  lineBottom->SetFlags( IS_NEW );
1263  m_currentSheet->GetScreen()->Append( lineBottom );
1264 
1265  SCH_LINE* lineRight = new SCH_LINE( sheetTopRight, SCH_LAYER_ID::LAYER_NOTES );
1266  lineRight->SetEndPoint( bottomRight );
1267  lineRight->SetLineWidth( elem.lineWidth );
1268  lineRight->SetLineStyle( PLOT_DASH_TYPE::SOLID );
1269  lineRight->SetFlags( IS_NEW );
1270  m_currentSheet->GetScreen()->Append( lineRight );
1271 
1272  SCH_LINE* lineLeft = new SCH_LINE( sheetBottomLeft, SCH_LAYER_ID::LAYER_NOTES );
1273  lineLeft->SetEndPoint( topLeft );
1274  lineLeft->SetLineWidth( elem.lineWidth );
1275  lineLeft->SetLineStyle( PLOT_DASH_TYPE::SOLID );
1276  lineLeft->SetFlags( IS_NEW );
1277  m_currentSheet->GetScreen()->Append( lineLeft );
1278  }
1279  else
1280  {
1281  const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
1282 
1283  if( libSymbolIt == m_libSymbols.end() )
1284  {
1285  // TODO: e.g. can depend on Template (RECORD=39
1286  m_reporter->Report( wxString::Format( _( "Rounded rectangle's owner (%d) not found." ),
1287  elem.ownerindex ),
1289  return;
1290  }
1291 
1292  if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
1293  return;
1294 
1295  SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
1296  // TODO: misses rounded edges
1297  LIB_SHAPE* rect = new LIB_SHAPE( libSymbolIt->second, SHAPE_T::RECT );
1298  libSymbolIt->second->AddDrawItem( rect );
1299 
1300  rect->SetUnit( elem.ownerpartid );
1301 
1302  rect->SetPosition( GetRelativePosition( elem.topRight + m_sheetOffset, symbol ) );
1303  rect->SetEnd( GetRelativePosition( elem.bottomLeft + m_sheetOffset, symbol ) );
1304  rect->SetWidth( elem.lineWidth );
1305 
1306  if( !elem.isSolid )
1307  rect->SetFillMode( FILL_T::NO_FILL );
1308  else if( elem.color == elem.areacolor )
1310  else
1312  }
1313 }
const wxPoint GetRelativePosition(const wxPoint &aPosition, const SCH_SYMBOL *aSymbol)
void SetEnd(const wxPoint &aEnd)
Definition: eda_shape.h:126
#define IS_NEW
New item, just created.
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:305
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
void SetPosition(const wxPoint &aPosition) override
Definition: lib_shape.h:87
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:269
std::map< int, SCH_SYMBOL * > m_symbols
#define _(s)
void SetWidth(int aWidth)
Definition: eda_shape.h:88
std::map< int, LIB_SYMBOL * > m_libSymbols
SCH_SHEET * m_currentSheet
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void SetUnit(int aUnit)
Definition: lib_item.h:257
Schematic symbol object.
Definition: sch_symbol.h:78
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:78
const int ALTIUM_COMPONENT_NONE
bool IsComponentPartVisible(int aOwnerindex, int aOwnerpartdisplaymode) const

References _, ALTIUM_COMPONENT_NONE, SCH_SCREEN::Append(), ASCH_ROUND_RECTANGLE::areacolor, ASCH_ROUND_RECTANGLE::bottomLeft, ASCH_ROUND_RECTANGLE::color, FILLED_SHAPE, FILLED_WITH_BG_BODYCOLOR, Format(), GetRelativePosition(), SCH_SHEET::GetScreen(), IS_NEW, IsComponentPartVisible(), ASCH_ROUND_RECTANGLE::isSolid, LAYER_NOTES, ASCH_ROUND_RECTANGLE::lineWidth, m_currentSheet, m_libSymbols, m_reporter, m_sheetOffset, m_symbols, NO_FILL, ASCH_ROUND_RECTANGLE::ownerindex, ASCH_ROUND_RECTANGLE::ownerpartdisplaymode, ASCH_ROUND_RECTANGLE::ownerpartid, RECT, REPORTER::Report(), RPT_SEVERITY_ERROR, EDA_SHAPE::SetEnd(), SCH_LINE::SetEndPoint(), EDA_SHAPE::SetFillMode(), EDA_ITEM::SetFlags(), SCH_LINE::SetLineStyle(), SCH_LINE::SetLineWidth(), LIB_SHAPE::SetPosition(), LIB_ITEM::SetUnit(), EDA_SHAPE::SetWidth(), SOLID, and ASCH_ROUND_RECTANGLE::topRight.

Referenced by ParseFileHeader().

◆ ParseSheet()

void SCH_ALTIUM_PLUGIN::ParseSheet ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 2187 of file sch_altium_plugin.cpp.

2188 {
2189  m_altiumSheet = std::make_unique<ASCH_SHEET>( aProperties );
2190 
2191  PAGE_INFO pageInfo;
2192 
2193  bool isPortrait = m_altiumSheet->sheetOrientation == ASCH_SHEET_WORKSPACEORIENTATION::PORTRAIT;
2194 
2195  switch( m_altiumSheet->sheetSize )
2196  {
2197  default:
2198  case ASCH_SHEET_SIZE::A4: pageInfo.SetType( "A4", isPortrait ); break;
2199  case ASCH_SHEET_SIZE::A3: pageInfo.SetType( "A3", isPortrait ); break;
2200  case ASCH_SHEET_SIZE::A2: pageInfo.SetType( "A2", isPortrait ); break;
2201  case ASCH_SHEET_SIZE::A1: pageInfo.SetType( "A1", isPortrait ); break;
2202  case ASCH_SHEET_SIZE::A0: pageInfo.SetType( "A0", isPortrait ); break;
2203  case ASCH_SHEET_SIZE::A: pageInfo.SetType( "A", isPortrait ); break;
2204  case ASCH_SHEET_SIZE::B: pageInfo.SetType( "B", isPortrait ); break;
2205  case ASCH_SHEET_SIZE::C: pageInfo.SetType( "C", isPortrait ); break;
2206  case ASCH_SHEET_SIZE::D: pageInfo.SetType( "D", isPortrait ); break;
2207  case ASCH_SHEET_SIZE::E: pageInfo.SetType( "E", isPortrait ); break;
2208  case ASCH_SHEET_SIZE::LETTER: pageInfo.SetType( "USLetter", isPortrait ); break;
2209  case ASCH_SHEET_SIZE::LEGAL: pageInfo.SetType( "USLegal", isPortrait ); break;
2210  case ASCH_SHEET_SIZE::TABLOID: pageInfo.SetType( "A3", isPortrait ); break;
2211  case ASCH_SHEET_SIZE::ORCAD_A: pageInfo.SetType( "A", isPortrait ); break;
2212  case ASCH_SHEET_SIZE::ORCAD_B: pageInfo.SetType( "B", isPortrait ); break;
2213  case ASCH_SHEET_SIZE::ORCAD_C: pageInfo.SetType( "C", isPortrait ); break;
2214  case ASCH_SHEET_SIZE::ORCAD_D: pageInfo.SetType( "D", isPortrait ); break;
2215  case ASCH_SHEET_SIZE::ORCAD_E: pageInfo.SetType( "E", isPortrait ); break;
2216  }
2217 
2218  m_currentSheet->GetScreen()->SetPageSettings( pageInfo );
2219 
2220  m_sheetOffset = { 0, pageInfo.GetHeightIU() };
2221 }
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
Definition: page_info.cpp:119
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:133
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
std::unique_ptr< ASCH_SHEET > m_altiumSheet
SCH_SHEET * m_currentSheet

References A, A0, A1, A2, A3, A4, B, C, D, E, SCH_SHEET::GetScreen(), LEGAL, LETTER, m_altiumSheet, m_currentSheet, m_sheetOffset, ORCAD_A, ORCAD_B, ORCAD_C, ORCAD_D, ORCAD_E, PORTRAIT, SCH_SCREEN::SetPageSettings(), PAGE_INFO::SetType(), and TABLOID.

Referenced by ParseFileHeader().

◆ ParseSheetEntry()

void SCH_ALTIUM_PLUGIN::ParseSheetEntry ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 1531 of file sch_altium_plugin.cpp.

1532 {
1533  ASCH_SHEET_ENTRY elem( aProperties );
1534 
1535  const auto& sheetIt = m_sheets.find( elem.ownerindex );
1536 
1537  if( sheetIt == m_sheets.end() )
1538  {
1539  m_reporter->Report( wxString::Format( _( "Sheet entry's owner (%d) not found." ),
1540  elem.ownerindex ),
1542  return;
1543  }
1544 
1545  SCH_SHEET_PIN* sheetPin = new SCH_SHEET_PIN( sheetIt->second );
1546  sheetIt->second->AddPin( sheetPin );
1547 
1548  sheetPin->SetText( elem.name );
1550  //sheetPin->SetLabelSpinStyle( getSpinStyle( term.OrientAngle, false ) );
1551  //sheetPin->SetPosition( getKiCadPoint( term.Position ) );
1552 
1553  wxPoint pos = sheetIt->second->GetPosition();
1554  wxSize size = sheetIt->second->GetSize();
1555 
1556  switch( elem.side )
1557  {
1558  default:
1560  sheetPin->SetPosition( { pos.x, pos.y + elem.distanceFromTop } );
1562  sheetPin->SetSide( SHEET_SIDE::LEFT );
1563  break;
1565  sheetPin->SetPosition( { pos.x + size.x, pos.y + elem.distanceFromTop } );
1567  sheetPin->SetSide( SHEET_SIDE::RIGHT );
1568  break;
1570  sheetPin->SetPosition( { pos.x + elem.distanceFromTop, pos.y } );
1572  sheetPin->SetSide( SHEET_SIDE::TOP );
1573  break;
1575  sheetPin->SetPosition( { pos.x + elem.distanceFromTop, pos.y + size.y } );
1577  sheetPin->SetSide( SHEET_SIDE::BOTTOM );
1578  break;
1579  }
1580 
1581  switch( elem.iotype )
1582  {
1583  default:
1586  break;
1589  break;
1592  break;
1595  break;
1596  }
1597 }
void SetShape(PINSHEETLABEL_SHAPE aShape)
Definition: sch_text.h:163
void SetSide(SHEET_SIDE aEdge)
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
std::map< int, SCH_SHEET * > m_sheets
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
void SetLabelSpinStyle(LABEL_SPIN_STYLE aSpinStyle) override
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:1563
#define _(s)
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:65
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void SetPosition(const wxPoint &aPosition) override

References _, BIDI, LABEL_SPIN_STYLE::BOTTOM, BOTTOM, ASCH_SHEET_ENTRY::distanceFromTop, Format(), INPUT, ASCH_SHEET_ENTRY::iotype, LABEL_SPIN_STYLE::LEFT, LEFT, m_reporter, m_sheets, ASCH_SHEET_ENTRY::name, OUTPUT, ASCH_SHEET_ENTRY::ownerindex, PS_BIDI, PS_INPUT, PS_OUTPUT, PS_UNSPECIFIED, REPORTER::Report(), LABEL_SPIN_STYLE::RIGHT, RIGHT, RPT_SEVERITY_ERROR, SCH_HIERLABEL::SetLabelSpinStyle(), SCH_SHEET_PIN::SetPosition(), SCH_TEXT::SetShape(), SCH_SHEET_PIN::SetSide(), EDA_TEXT::SetText(), ASCH_SHEET_ENTRY::side, TOP, UNSPECIFIED, and LABEL_SPIN_STYLE::UP.

Referenced by ParseFileHeader().

◆ ParseSheetName()

void SCH_ALTIUM_PLUGIN::ParseSheetName ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 2224 of file sch_altium_plugin.cpp.

2225 {
2226  ASCH_SHEET_NAME elem( aProperties );
2227 
2228  const auto& sheetIt = m_sheets.find( elem.ownerindex );
2229 
2230  if( sheetIt == m_sheets.end() )
2231  {
2232  m_reporter->Report( wxString::Format( _( "Sheetname's owner (%d) not found." ),
2233  elem.ownerindex ),
2235  return;
2236  }
2237 
2238  SCH_FIELD& sheetNameField = sheetIt->second->GetFields()[SHEETNAME];
2239 
2240  sheetNameField.SetPosition( elem.location + m_sheetOffset );
2241  sheetNameField.SetText( elem.text );
2242  sheetNameField.SetVisible( !elem.isHidden );
2243  SetTextPositioning( &sheetNameField, ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT, elem.orientation );
2244 }
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
void SetTextPositioning(EDA_TEXT *text, ASCH_LABEL_JUSTIFICATION justification, ASCH_RECORD_ORIENTATION orientation)
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
std::map< int, SCH_SHEET * > m_sheets
virtual void SetVisible(bool aVisible)
Definition: eda_text.h:206
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void SetPosition(const wxPoint &aPosition) override
Definition: sch_field.cpp:822

References _, BOTTOM_LEFT, Format(), ASCH_SHEET_NAME::isHidden, ASCH_SHEET_NAME::location, m_reporter, m_sheetOffset, m_sheets, ASCH_SHEET_NAME::orientation, ASCH_SHEET_NAME::ownerindex, REPORTER::Report(), RPT_SEVERITY_ERROR, SCH_FIELD::SetPosition(), EDA_TEXT::SetText(), SetTextPositioning(), EDA_TEXT::SetVisible(), SHEETNAME, and ASCH_SHEET_NAME::text.

Referenced by ParseFileHeader().

◆ ParseSheetSymbol()

void SCH_ALTIUM_PLUGIN::ParseSheetSymbol ( int  aIndex,
const std::map< wxString, wxString > &  aProperties 
)
private

Definition at line 1500 of file sch_altium_plugin.cpp.

1502 {
1503  ASCH_SHEET_SYMBOL elem( aProperties );
1504 
1505  SCH_SHEET* sheet = new SCH_SHEET( m_currentSheet, elem.location + m_sheetOffset );
1506  SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
1507 
1508  sheet->SetSize( elem.size );
1509  sheet->SetBorderColor( GetColorFromInt( elem.color ) );
1510 
1511  if( elem.isSolid )
1512  sheet->SetBackgroundColor( GetColorFromInt( elem.areacolor ) );
1513 
1514  sheet->SetScreen( screen );
1515 
1516  sheet->SetFlags( IS_NEW );
1517  m_currentSheet->GetScreen()->Append( sheet );
1518 
1519  SCH_SHEET_PATH sheetpath;
1521  sheetpath.push_back( sheet );
1522 
1523  sheet->AddInstance( sheetpath.Path() );
1524  sheet->SetPageNumber( sheetpath, "#" ); // We'll update later if we find a pageNumber
1525  // record for it
1526 
1527  m_sheets.insert( { aIndex, sheet } );
1528 }
#define IS_NEW
New item, just created.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:172
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1166
std::map< int, SCH_SHEET * > m_sheets
COLOR4D GetColorFromInt(int color)
void SetBackgroundColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:117
void SetBorderColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:114
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SHEET * m_currentSheet
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
void SetSize(const wxSize &aSize)
Definition: sch_sheet.h:108
bool LocatePathOfScreen(SCH_SCREEN *aScreen, SCH_SHEET_PATH *aList)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:688
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
bool AddInstance(const KIID_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1124

References SCH_SHEET::AddInstance(), SCH_SCREEN::Append(), ASCH_SHEET_SYMBOL::areacolor, ASCH_SHEET_SYMBOL::color, GetColorFromInt(), SCH_SHEET::GetScreen(), IS_NEW, ASCH_SHEET_SYMBOL::isSolid, SCH_SHEET::LocatePathOfScreen(), ASCH_SHEET_SYMBOL::location, m_currentSheet, m_rootSheet, m_schematic, m_sheetOffset, m_sheets, SCH_SHEET_PATH::Path(), SCH_SHEET_PATH::push_back(), SCH_SHEET::SetBackgroundColor(), SCH_SHEET::SetBorderColor(), EDA_ITEM::SetFlags(), SCH_SHEET::SetPageNumber(), SCH_SHEET::SetScreen(), SCH_SHEET::SetSize(), and ASCH_SHEET_SYMBOL::size.

Referenced by ParseFileHeader().

◆ ParseStorage()

void SCH_ALTIUM_PLUGIN::ParseStorage ( const CFB::CompoundFileReader &  aReader)

Definition at line 284 of file sch_altium_plugin.cpp.

285 {
286  const CFB::COMPOUND_FILE_ENTRY* file = FindStream( aReader, "Storage" );
287 
288  if( file == nullptr )
289  return;
290 
291  ALTIUM_PARSER reader( aReader, file );
292 
293  std::map<wxString, wxString> properties = reader.ReadProperties();
294  wxString header = ALTIUM_PARSER::ReadString( properties, "HEADER", "" );
295  int weight = ALTIUM_PARSER::ReadInt( properties, "WEIGHT", 0 );
296 
297  if( weight < 0 )
298  THROW_IO_ERROR( "Storage weight is negative!" );
299 
300  for( int i = 0; i < weight; i++ )
301  {
302  m_altiumStorage.emplace_back( reader );
303  }
304 
305  if( reader.HasParsingError() )
306  THROW_IO_ERROR( "stream was not parsed correctly!" );
307 
308  // TODO pointhi: is it possible to have multiple headers in one Storage file? Otherwise
309  // throw IO Error.
310  if( reader.GetRemainingBytes() != 0 )
311  {
312  m_reporter->Report( wxString::Format( _( "Storage file not fully parsed "
313  "(%d bytes remaining)." ),
314  reader.GetRemainingBytes() ),
316  }
317 }
std::vector< ASCH_STORAGE_FILE > m_altiumStorage
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
const CFB::COMPOUND_FILE_ENTRY * FindStream(const CFB::CompoundFileReader &aReader, const char *aStreamName)
static int ReadInt(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aDefault)
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static wxString ReadString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, FindStream(), Format(), ALTIUM_PARSER::GetRemainingBytes(), ALTIUM_PARSER::HasParsingError(), m_altiumStorage, m_reporter, ALTIUM_PARSER::ReadInt(), ALTIUM_PARSER::ReadProperties(), ALTIUM_PARSER::ReadString(), REPORTER::Report(), RPT_SEVERITY_ERROR, and THROW_IO_ERROR.

Referenced by ParseAltiumSch().

◆ ParseTextFrame()

void SCH_ALTIUM_PLUGIN::ParseTextFrame ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 888 of file sch_altium_plugin.cpp.

889 {
890  ASCH_TEXT_FRAME elem( aProperties );
891 
892  SCH_TEXT* text = new SCH_TEXT( elem.location + m_sheetOffset, elem.text );
893 
894  switch( elem.alignment )
895  {
896  default:
898  text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::RIGHT );
899  break;
901  // No support for centered text in Eeschema yet...
902  text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::RIGHT );
903  break;
905  text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::LEFT );
906  break;
907  }
908 
909  // TODO: set size and word-wrap once KiCad supports wrapped text.
910 
911  // TODO: set border and background color once KiCad supports them.
912 
913  size_t fontId = static_cast<int>( elem.fontId );
914 
915  if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() )
916  {
917  const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 );
918  text->SetItalic( font.italic );
919  text->SetBold( font.bold );
920  text->SetTextSize( { font.size / 2, font.size / 2 } );
921  }
922 
923  text->SetFlags( IS_NEW );
925 }
#define IS_NEW
New item, just created.
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
std::unique_ptr< ASCH_SHEET > m_altiumSheet
SCH_SHEET * m_currentSheet
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146

References ASCH_TEXT_FRAME::alignment, SCH_SCREEN::Append(), ASCH_SHEET_FONT::bold, CENTER, ASCH_TEXT_FRAME::fontId, fonts, SCH_SHEET::GetScreen(), IS_NEW, ASCH_SHEET_FONT::italic, LEFT, ASCH_TEXT_FRAME::location, m_altiumSheet, m_currentSheet, m_sheetOffset, RIGHT, ASCH_SHEET_FONT::size, ASCH_TEXT_FRAME::text, and text.

Referenced by ParseFileHeader().

◆ ParseWire()

void SCH_ALTIUM_PLUGIN::ParseWire ( const std::map< wxString, wxString > &  aProperties)
private

Definition at line 2092 of file sch_altium_plugin.cpp.

2093 {
2094  ASCH_WIRE elem( aProperties );
2095 
2096  for( size_t i = 0; i + 1 < elem.points.size(); i++ )
2097  {
2098  SCH_LINE* wire =
2099  new SCH_LINE( elem.points.at( i ) + m_sheetOffset, SCH_LAYER_ID::LAYER_WIRE );
2100  wire->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
2101  wire->SetLineWidth( elem.lineWidth );
2102 
2103  wire->SetFlags( IS_NEW );
2104  m_currentSheet->GetScreen()->Append( wire );
2105  }
2106 }
#define IS_NEW
New item, just created.
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:305
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
SCH_SHEET * m_currentSheet
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146

References SCH_SCREEN::Append(), SCH_SHEET::GetScreen(), IS_NEW, LAYER_WIRE, ASCH_WIRE::lineWidth, m_currentSheet, m_sheetOffset, ASCH_WIRE::points, SCH_LINE::SetEndPoint(), EDA_ITEM::SetFlags(), and SCH_LINE::SetLineWidth().

Referenced by ParseFileHeader().

◆ Save()

void SCH_PLUGIN::Save ( const wxString &  aFileName,
SCH_SHEET aSheet,
SCHEMATIC aSchematic,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about, or it can be used to write a portion of aSchematic to a special kind of export file.

Parameters
aFileNameis the name of a file to save to on disk.
aSheetis the class SCH_SHEET in memory document tree from which to extract information when writing to aFileName. The caller continues to own the SCHEMATIC, and the plugin should refrain from modifying the SCHEMATIC if possible.
aSchematicis the SCHEMATIC object used to access any schematic-wide or project information needed to save the document.
aPropertiesis an associative array that can be used to tell the saver how to save the file, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL. Set the #PropSaveCurrentSheetOnly property to only save the current sheet. Otherwise, all hierarchical sheets are saved.
Exceptions
IO_ERRORif there is a problem saving or exporting.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 59 of file sch_plugin.cpp.

61 {
62  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
63  not_implemented( this, __FUNCTION__ );
64 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

◆ SaveLibrary()

void SCH_PLUGIN::SaveLibrary ( const wxString &  aFileName,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 45 of file sch_plugin.cpp.

46 {
47  not_implemented( this, __FUNCTION__ );
48 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

◆ SaveSymbol()

void SCH_PLUGIN::SaveSymbol ( const wxString &  aLibraryPath,
const LIB_SYMBOL aSymbol,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Write aSymbol to an existing library located at aLibraryPath.

If a LIB_SYMBOL by the same name already exists or there are any conflicting alias names, the new LIB_SYMBOL will silently overwrite any existing aliases and/or part because libraries cannot have duplicate alias names. It is the responsibility of the caller to check the library for conflicts before saving.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
aSymbolis what to store in the library. The library is refreshed and the caller must update any LIB_SYMBOL pointers that may have changed.
aPropertiesis an associative array that can be used to tell the saver how to save the symbol, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem saving.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 94 of file sch_plugin.cpp.

96 {
97  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
98  not_implemented( this, __FUNCTION__ );
99 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

Referenced by SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer().

◆ SetProgressReporter()

virtual void SCH_PLUGIN::SetProgressReporter ( PROGRESS_REPORTER aReporter)
inlinevirtualinherited

Set an optional progress reporter.

Reimplemented in SCH_EAGLE_PLUGIN, SCH_LEGACY_PLUGIN, SCH_SEXPR_PLUGIN, and CADSTAR_SCH_ARCHIVE_PLUGIN.

Definition at line 171 of file sch_io_mgr.h.

171 {}

◆ SetReporter()

void SCH_ALTIUM_PLUGIN::SetReporter ( REPORTER aReporter)
inlineoverridevirtual

Set an optional reporter for warnings/errors.

Reimplemented from SCH_PLUGIN.

Definition at line 59 of file sch_altium_plugin.h.

59 { m_reporter = aReporter; }

References m_reporter.

◆ SymbolLibOptions()

void SCH_PLUGIN::SymbolLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.

Options are typically appended so that a derived SCH_PLUGIN can call its base class function by the same name first, thus inheriting options declared there. (Some base class options could pertain to all Symbol*() functions in all derived SCH_PLUGINs.) Note that since aListToAppendTo is a PROPERTIES object, all options will be unique and last guy wins.

Parameters
aListToAppendToholds a tuple of
option
This eventually is what shows up into the fp-lib-table "options" field, possibly combined with others.
internationalized description
The internationalized description is displayed in DIALOG_FP_SCH_PLUGIN_OPTIONS. It may be multi-line and be quite explanatory of the option.

In the future perhaps aListToAppendTo evolves to something capable of also holding a wxValidator for the cells in said dialog: http://forums.wxwidgets.org/viewtopic.php?t=23277&p=104180. This would require a 3 column list, and introducing wx GUI knowledge to SCH_PLUGIN, which has been avoided to date.

Definition at line 133 of file sch_plugin.cpp.

134 {
135  // disable all these in another couple of months, after everyone has seen them:
136 #if 1
137  (*aListToAppendTo)["debug_level"] = UTF8( _(
138  "Enable <b>debug</b> logging for Symbol*() functions in this SCH_PLUGIN."
139  ) );
140 
141  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
142  "Regular expression <b>symbol name</b> filter."
143  ) );
144 
145  (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
146  "Enable transaction logging. The mere presence of this option turns on the "
147  "logging, no need to set a Value."
148  ) );
149 
150  (*aListToAppendTo)["username"] = UTF8( _(
151  "User name for <b>login</b> to some special library server."
152  ) );
153 
154  (*aListToAppendTo)["password"] = UTF8( _(
155  "Password for <b>login</b> to some special library server."
156  ) );
157 #endif
158 
159 #if 1
160  // Suitable for a C++ to python SCH_PLUGIN::Footprint*() adapter, move it to the adapter
161  // if and when implemented.
162  (*aListToAppendTo)["python_symbol_plugin"] = UTF8( _(
163  "Enter the python symbol which implements the SCH_PLUGIN::Symbol*() functions."
164  ) );
165 #endif
166 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
#define _(s)

References _.

Member Data Documentation

◆ m_altiumComponents

std::map<int, ASCH_SYMBOL> SCH_ALTIUM_PLUGIN::m_altiumComponents
private

Definition at line 169 of file sch_altium_plugin.h.

Referenced by IsComponentPartVisible(), and ParseComponent().

◆ m_altiumImplementationList

std::map<int, int> SCH_ALTIUM_PLUGIN::m_altiumImplementationList
private

Definition at line 170 of file sch_altium_plugin.h.

Referenced by ParseImplementation(), and ParseImplementationList().

◆ m_altiumPortsCurrentSheet

std::vector<ASCH_PORT> SCH_ALTIUM_PLUGIN::m_altiumPortsCurrentSheet
private

Definition at line 171 of file sch_altium_plugin.h.

Referenced by ParseFileHeader().

◆ m_altiumSheet

std::unique_ptr<ASCH_SHEET> SCH_ALTIUM_PLUGIN::m_altiumSheet
private

Definition at line 161 of file sch_altium_plugin.h.

Referenced by ParseLabel(), ParseNote(), ParseSheet(), and ParseTextFrame().

◆ m_altiumStorage

std::vector<ASCH_STORAGE_FILE> SCH_ALTIUM_PLUGIN::m_altiumStorage
private

Definition at line 167 of file sch_altium_plugin.h.

Referenced by GetFileFromStorage(), and ParseStorage().

◆ m_currentSheet

◆ m_currentTitleBlock

std::unique_ptr<TITLE_BLOCK> SCH_ALTIUM_PLUGIN::m_currentTitleBlock
private

Definition at line 157 of file sch_altium_plugin.h.

Referenced by ParseFileHeader(), and ParseParameter().

◆ m_libName

wxString SCH_ALTIUM_PLUGIN::m_libName
private

Definition at line 152 of file sch_altium_plugin.h.

Referenced by getLibName().

◆ m_libSymbols

◆ m_pi

SCH_PLUGIN::SCH_PLUGIN_RELEASER SCH_ALTIUM_PLUGIN::m_pi
private

Definition at line 154 of file sch_altium_plugin.h.

Referenced by Load(), ParseFileHeader(), and ParsePowerPort().

◆ m_powerSymbols

std::map<wxString, LIB_SYMBOL*> SCH_ALTIUM_PLUGIN::m_powerSymbols
private

Definition at line 166 of file sch_altium_plugin.h.

Referenced by ParsePowerPort().

◆ m_properties

std::unique_ptr<PROPERTIES> SCH_ALTIUM_PLUGIN::m_properties
private

Definition at line 155 of file sch_altium_plugin.h.

Referenced by ParseFileHeader(), and ParsePowerPort().

◆ m_reporter

◆ m_rootSheet

SCH_SHEET* SCH_ALTIUM_PLUGIN::m_rootSheet
private

◆ m_schematic

SCHEMATIC* SCH_ALTIUM_PLUGIN::m_schematic
private

◆ m_sheetOffset

◆ m_sheets

std::map<int, SCH_SHEET*> SCH_ALTIUM_PLUGIN::m_sheets
private

◆ m_symbols


The documentation for this class was generated from the following files: