altium: initial parsing of designator and some parameters
This commit is contained in:
parent
52b5e4d0b3
commit
52d8501563
|
@ -567,6 +567,7 @@ ASCH_SHEET::ASCH_SHEET( const std::map<wxString, wxString>& aProperties )
|
|||
aProperties, "WORKSPACEORIENTATION", 0, 1, ASCH_SHEET_WORKSPACEORIENTATION::LANDSCAPE );
|
||||
}
|
||||
|
||||
|
||||
ASCH_DESIGNATOR::ASCH_DESIGNATOR( const std::map<wxString, wxString>& aProperties )
|
||||
{
|
||||
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::DESIGNATOR );
|
||||
|
@ -578,12 +579,14 @@ ASCH_DESIGNATOR::ASCH_DESIGNATOR( const std::map<wxString, wxString>& aPropertie
|
|||
name = ALTIUM_PARSER::PropertiesReadString( aProperties, "NAME", "" );
|
||||
text = ALTIUM_PARSER::PropertiesReadString( aProperties, "TEXT", "" );
|
||||
|
||||
orientation = ALTIUM_PARSER::PropertiesReadInt( aProperties, "ORIENTATION", 0 );
|
||||
orientation = PropertiesReadEnum<ASCH_RECORD_ORIENTATION>(
|
||||
aProperties, "ORIENTATION", 0, 3, ASCH_RECORD_ORIENTATION::RIGHTWARDS );
|
||||
|
||||
location = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.X" ),
|
||||
-PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) );
|
||||
}
|
||||
|
||||
|
||||
ASCH_BUS_ENTRY::ASCH_BUS_ENTRY( const std::map<wxString, wxString>& aProperties )
|
||||
{
|
||||
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::BUS_ENTRY );
|
||||
|
@ -592,4 +595,27 @@ ASCH_BUS_ENTRY::ASCH_BUS_ENTRY( const std::map<wxString, wxString>& aProperties
|
|||
-PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) );
|
||||
corner = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "CORNER.X" ),
|
||||
-PropertiesReadKiCadUnitFrac( aProperties, "CORNER.Y" ) );
|
||||
}
|
||||
|
||||
|
||||
ASCH_PARAMETER::ASCH_PARAMETER( const std::map<wxString, wxString>& aProperties )
|
||||
{
|
||||
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::PARAMETER );
|
||||
|
||||
ownerindex =
|
||||
ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE );
|
||||
ownerpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", 0 );
|
||||
|
||||
location = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.X" ),
|
||||
-PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) );
|
||||
|
||||
orientation = PropertiesReadEnum<ASCH_RECORD_ORIENTATION>(
|
||||
aProperties, "ORIENTATION", 0, 3, ASCH_RECORD_ORIENTATION::RIGHTWARDS );
|
||||
|
||||
name = ALTIUM_PARSER::PropertiesReadString( aProperties, "NAME", "" );
|
||||
text = ALTIUM_PARSER::PropertiesReadString( aProperties, "TEXT", "" );
|
||||
|
||||
isHidden = ALTIUM_PARSER::PropertiesReadBool( aProperties, "ISHIDDEN", false );
|
||||
isMirrored = ALTIUM_PARSER::PropertiesReadBool( aProperties, "ISMIRRORED", false );
|
||||
isShowName = ALTIUM_PARSER::PropertiesReadBool( aProperties, "SHOWNAME", false );
|
||||
}
|
|
@ -568,7 +568,7 @@ struct ASCH_DESIGNATOR
|
|||
wxString name;
|
||||
wxString text;
|
||||
|
||||
int orientation;
|
||||
ASCH_RECORD_ORIENTATION orientation;
|
||||
wxPoint location;
|
||||
|
||||
explicit ASCH_DESIGNATOR( const std::map<wxString, wxString>& aProperties );
|
||||
|
@ -583,4 +583,23 @@ struct ASCH_BUS_ENTRY
|
|||
explicit ASCH_BUS_ENTRY( const std::map<wxString, wxString>& aProperties );
|
||||
};
|
||||
|
||||
|
||||
struct ASCH_PARAMETER
|
||||
{
|
||||
int ownerindex;
|
||||
int ownerpartid;
|
||||
|
||||
wxPoint location;
|
||||
ASCH_RECORD_ORIENTATION orientation;
|
||||
|
||||
wxString name;
|
||||
wxString text;
|
||||
|
||||
bool isHidden;
|
||||
bool isMirrored;
|
||||
bool isShowName;
|
||||
|
||||
explicit ASCH_PARAMETER( const std::map<wxString, wxString>& aProperties );
|
||||
};
|
||||
|
||||
#endif //ALTIUM_PARSER_SCH_H
|
|
@ -204,7 +204,9 @@ SCH_SHEET* SCH_ALTIUM_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchem
|
|||
}
|
||||
|
||||
m_currentSheet = m_rootSheet;
|
||||
m_currentTitleBlock = std::make_unique<TITLE_BLOCK>();
|
||||
ParseAltiumSch( aFileName );
|
||||
m_currentSheet->GetScreen()->SetTitleBlock( *m_currentTitleBlock );
|
||||
|
||||
m_pi->SaveLibrary( getLibFileName().GetFullPath() );
|
||||
|
||||
|
@ -382,6 +384,7 @@ void SCH_ALTIUM_PLUGIN::Parse( const CFB::CompoundFileReader& aReader )
|
|||
case ALTIUM_SCH_RECORD::TEMPLATE:
|
||||
break;
|
||||
case ALTIUM_SCH_RECORD::PARAMETER:
|
||||
ParseParameter( properties );
|
||||
break;
|
||||
case ALTIUM_SCH_RECORD::WARNING_SIGN:
|
||||
break;
|
||||
|
@ -1771,29 +1774,48 @@ void SCH_ALTIUM_PLUGIN::ParseDesignator( const std::map<wxString, wxString>& aPr
|
|||
{
|
||||
ASCH_DESIGNATOR elem( aProperties );
|
||||
|
||||
if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
|
||||
{
|
||||
return; // TODO: what to do?
|
||||
}
|
||||
|
||||
const auto& component = m_components.find( elem.ownerpartid );
|
||||
if( component == m_components.end() )
|
||||
const auto& symbol = m_symbols.find( elem.ownerindex );
|
||||
if( symbol == m_symbols.end() )
|
||||
{
|
||||
// TODO: e.g. can depend on Template (RECORD=39
|
||||
THROW_IO_ERROR( wxString::Format(
|
||||
"Designator tries to access component with ownerpartid %d which does not exist",
|
||||
elem.ownerpartid ) );
|
||||
wxLogWarning( wxString::Format(
|
||||
"Designator tries to access symbol with ownerindex %d which does not exist",
|
||||
elem.ownerindex ) );
|
||||
return;
|
||||
}
|
||||
|
||||
LIB_PART* symbol = m_symbols.at( elem.ownerpartid );
|
||||
// TODO: component->second->SetRef(m_sheet, elem.name);
|
||||
const auto& component = m_components.at( symbol->first );
|
||||
|
||||
LIB_TEXT* text = new LIB_TEXT( symbol );
|
||||
symbol->AddDrawItem( text );
|
||||
SCH_SHEET_PATH sheetpath;
|
||||
m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath );
|
||||
|
||||
text->SetPosition( elem.location + m_sheetOffset );
|
||||
text->SetTextAngle( elem.orientation * 90. );
|
||||
text->SetText( elem.name ); // TODO: use variable
|
||||
component->SetRef( &sheetpath, elem.text );
|
||||
|
||||
SCH_FIELD* refField = component->GetField( REFERENCE );
|
||||
|
||||
refField->SetPosition( elem.location + m_sheetOffset );
|
||||
refField->SetVisible( true );
|
||||
|
||||
refField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT );
|
||||
refField->SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_BOTTOM );
|
||||
|
||||
switch( elem.orientation )
|
||||
{
|
||||
case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
|
||||
refField->SetTextAngle( 0 );
|
||||
break;
|
||||
case ASCH_RECORD_ORIENTATION::UPWARDS:
|
||||
refField->SetTextAngle( 90 );
|
||||
break;
|
||||
case ASCH_RECORD_ORIENTATION::LEFTWARDS:
|
||||
refField->SetTextAngle( 180 );
|
||||
break;
|
||||
case ASCH_RECORD_ORIENTATION::DOWNWARDS:
|
||||
refField->SetTextAngle( 270 );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1809,3 +1831,72 @@ void SCH_ALTIUM_PLUGIN::ParseBusEntry( const std::map<wxString, wxString>& aProp
|
|||
busWireEntry->SetFlags( IS_NEW );
|
||||
m_currentSheet->GetScreen()->Append( busWireEntry );
|
||||
}
|
||||
|
||||
|
||||
void SCH_ALTIUM_PLUGIN::ParseParameter( const std::map<wxString, wxString>& aProperties )
|
||||
{
|
||||
ASCH_PARAMETER elem( aProperties );
|
||||
|
||||
if( elem.ownerindex <= 0 && elem.ownerpartid == ALTIUM_COMPONENT_NONE )
|
||||
{
|
||||
// This is some sheet parameter
|
||||
if( elem.text == "*" )
|
||||
return; // indicates parameter not set?
|
||||
|
||||
SCH_SHEET_PATH sheetpath;
|
||||
m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath );
|
||||
|
||||
if( elem.name == "SheetNumber" )
|
||||
m_rootSheet->SetPageNumber( sheetpath, elem.text );
|
||||
else if( elem.name == "Title" )
|
||||
m_currentTitleBlock->SetTitle( elem.text );
|
||||
else if( elem.name == "Revision" )
|
||||
m_currentTitleBlock->SetRevision( elem.text );
|
||||
else if( elem.name == "Date" )
|
||||
m_currentTitleBlock->SetDate( elem.text );
|
||||
else if( elem.name == "CompanyName" )
|
||||
m_currentTitleBlock->SetCompany( elem.text );
|
||||
// TODO: parse other parameters
|
||||
// TODO: handle parameters in labels
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto& symbol = m_symbols.find( elem.ownerindex );
|
||||
if( symbol == m_symbols.end() )
|
||||
{
|
||||
// TODO: e.g. can depend on Template (RECORD=39
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& component = m_components.at( symbol->first );
|
||||
|
||||
int fieldIdx = component->GetFieldCount() + 1;
|
||||
|
||||
// TODO: location not correct?
|
||||
SCH_FIELD field( elem.location + m_sheetOffset, fieldIdx, component, elem.name );
|
||||
field.SetText( elem.text );
|
||||
field.SetVisible( !elem.isHidden );
|
||||
field.SetMirrored( elem.isMirrored );
|
||||
field.SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT );
|
||||
|
||||
switch( elem.orientation )
|
||||
{
|
||||
case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
|
||||
field.SetTextAngle( 0 );
|
||||
break;
|
||||
case ASCH_RECORD_ORIENTATION::UPWARDS:
|
||||
field.SetTextAngle( 90 );
|
||||
break;
|
||||
case ASCH_RECORD_ORIENTATION::LEFTWARDS:
|
||||
field.SetTextAngle( 180 );
|
||||
break;
|
||||
case ASCH_RECORD_ORIENTATION::DOWNWARDS:
|
||||
field.SetTextAngle( 270 );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
component->AddField( field );
|
||||
}
|
||||
}
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
|
||||
class SCH_COMPONENT;
|
||||
class TITLE_BLOCK;
|
||||
|
||||
namespace CFB
|
||||
{
|
||||
|
@ -124,6 +125,7 @@ private:
|
|||
void ParseSheet( 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 );
|
||||
|
||||
private:
|
||||
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded..
|
||||
|
@ -135,6 +137,9 @@ private:
|
|||
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi; ///< Plugin to create the KiCad symbol library.
|
||||
std::unique_ptr<PROPERTIES> m_properties; ///< Library plugin properties.
|
||||
|
||||
std::unique_ptr<TITLE_BLOCK>
|
||||
m_currentTitleBlock; /// Will be assigned at the end of parsing a sheet
|
||||
|
||||
wxPoint m_sheetOffset;
|
||||
std::unique_ptr<ASCH_SHEET> m_altiumSheet;
|
||||
std::map<int, SCH_COMPONENT*> m_components;
|
||||
|
|
Loading…
Reference in New Issue