CADSTAR Schematic Archive Importer: Load Documentation Symbols
This commit is contained in:
parent
c6bc72d579
commit
5e2e692ad8
|
@ -86,6 +86,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( ::SCHEMATIC* aSchematic, ::SCH_SHEET* aRo
|
|||
loadNets();
|
||||
loadFigures();
|
||||
loadTexts();
|
||||
loadDocumentationSymbols();
|
||||
// TODO Load other elements!
|
||||
|
||||
// For all sheets, centre all elements and re calculate the page size:
|
||||
|
@ -657,6 +658,66 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadTexts()
|
|||
}
|
||||
|
||||
|
||||
void CADSTAR_SCH_ARCHIVE_LOADER::loadDocumentationSymbols()
|
||||
{
|
||||
for( std::pair<DOCUMENTATION_SYMBOL_ID, DOCUMENTATION_SYMBOL> docSymPair :
|
||||
Schematic.DocumentationSymbols )
|
||||
{
|
||||
DOCUMENTATION_SYMBOL docSym = docSymPair.second;
|
||||
|
||||
if( Library.SymbolDefinitions.find( docSym.SymdefID ) == Library.SymbolDefinitions.end() )
|
||||
{
|
||||
wxLogError(
|
||||
wxString::Format( _( "Documentation Symbol '%s' refers to symbol definition "
|
||||
"ID '%s' which does not exist in the library. The symbol "
|
||||
"was not loaded." ),
|
||||
docSym.ID, docSym.SymdefID ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
SYMDEF_SCM docSymDef = Library.SymbolDefinitions.at( docSym.SymdefID );
|
||||
wxPoint moveVector = getKiCadPoint( docSym.Origin ) - getKiCadPoint( docSymDef.Origin );
|
||||
double rotationAngle = getAngleTenthDegree( docSym.OrientAngle );
|
||||
double scalingFactor =
|
||||
(double) docSym.ScaleRatioNumerator / (double) docSym.ScaleRatioDenominator;
|
||||
wxPoint centreOfTransform = getKiCadPoint( docSymDef.Origin );
|
||||
bool mirrorInvert = docSym.Mirror;
|
||||
|
||||
for( std::pair<FIGURE_ID, FIGURE> figPair : docSymDef.Figures )
|
||||
{
|
||||
FIGURE fig = figPair.second;
|
||||
|
||||
loadFigure( fig, docSym.LayerID, LAYER_NOTES, moveVector, rotationAngle, scalingFactor,
|
||||
centreOfTransform, mirrorInvert );
|
||||
}
|
||||
|
||||
for( std::pair<TEXT_ID, TEXT> textPair : docSymDef.Texts )
|
||||
{
|
||||
TEXT txt = textPair.second;
|
||||
|
||||
SCH_TEXT* kiTxt = getKiCadSchText( txt );
|
||||
|
||||
wxPoint newPosition = applyTransform( kiTxt->GetPosition(), moveVector, rotationAngle,
|
||||
scalingFactor, centreOfTransform, mirrorInvert );
|
||||
double newTxtAngle = NormalizeAnglePos( kiTxt->GetTextAngle() + rotationAngle );
|
||||
bool newMirrorStatus = kiTxt->IsMirrored() ? !mirrorInvert : mirrorInvert;
|
||||
int newTxtWidth = KiROUND( kiTxt->GetTextWidth() * scalingFactor );
|
||||
int newTxtHeight = KiROUND( kiTxt->GetTextHeight() * scalingFactor );
|
||||
int newTxtThickness = KiROUND( kiTxt->GetTextThickness() * scalingFactor );
|
||||
|
||||
kiTxt->SetPosition( newPosition );
|
||||
kiTxt->SetTextAngle( newTxtAngle );
|
||||
kiTxt->SetMirrored( newMirrorStatus );
|
||||
kiTxt->SetTextWidth( newTxtWidth );
|
||||
kiTxt->SetTextHeight( newTxtHeight );
|
||||
kiTxt->SetTextThickness( newTxtThickness );
|
||||
|
||||
loadItemOntoKiCadSheet( docSym.LayerID, kiTxt );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdefID,
|
||||
const PART* aCadstarPart, const GATE_ID& aGateID, LIB_PART* aPart )
|
||||
{
|
||||
|
@ -1073,7 +1134,9 @@ wxString CADSTAR_SCH_ARCHIVE_LOADER::getNetName( const NET_SCH& aNet )
|
|||
|
||||
|
||||
void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector<VERTEX>& aCadstarVertices,
|
||||
LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID )
|
||||
LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID,
|
||||
const wxPoint& aMoveVector, const double& aRotationAngleDeciDeg,
|
||||
const double& aScalingFactor, const wxPoint& aTransformCentre, const bool& aMirrorInvert )
|
||||
{
|
||||
const VERTEX* prev = &aCadstarVertices.at( 0 );
|
||||
const VERTEX* cur;
|
||||
|
@ -1089,11 +1152,18 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector<VERTEX>& a
|
|||
wxPoint startPoint = getKiCadPoint( prev->End );
|
||||
wxPoint endPoint = getKiCadPoint( cur->End );
|
||||
|
||||
segment->SetLayer( aKiCadSchLayerID );
|
||||
segment->SetLineWidth( KiROUND( getLineThickness( aCadstarLineCodeID ) * aScalingFactor ) );
|
||||
segment->SetLineStyle( getLineStyle( aCadstarLineCodeID ) );
|
||||
|
||||
//Apply transforms
|
||||
startPoint = applyTransform( startPoint, aMoveVector, aRotationAngleDeciDeg, aScalingFactor,
|
||||
aTransformCentre, aMirrorInvert );
|
||||
endPoint = applyTransform( endPoint, aMoveVector, aRotationAngleDeciDeg, aScalingFactor,
|
||||
aTransformCentre, aMirrorInvert );
|
||||
|
||||
segment->SetStartPoint( startPoint );
|
||||
segment->SetEndPoint( endPoint );
|
||||
segment->SetLayer( aKiCadSchLayerID );
|
||||
segment->SetLineWidth( getLineThickness( aCadstarLineCodeID ) );
|
||||
segment->SetLineStyle( getLineStyle( aCadstarLineCodeID ) );
|
||||
|
||||
prev = cur;
|
||||
|
||||
|
@ -1103,15 +1173,19 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector<VERTEX>& a
|
|||
|
||||
|
||||
void CADSTAR_SCH_ARCHIVE_LOADER::loadFigure( const FIGURE& aCadstarFigure,
|
||||
const LAYER_ID& aCadstarSheetIDOverride, SCH_LAYER_ID aKiCadSchLayerID )
|
||||
const LAYER_ID& aCadstarSheetIDOverride, SCH_LAYER_ID aKiCadSchLayerID,
|
||||
const wxPoint& aMoveVector, const double& aRotationAngleDeciDeg,
|
||||
const double& aScalingFactor, const wxPoint& aTransformCentre, const bool& aMirrorInvert )
|
||||
{
|
||||
loadShapeVertices( aCadstarFigure.Shape.Vertices, aCadstarFigure.LineCodeID,
|
||||
aCadstarFigure.LayerID, aKiCadSchLayerID );
|
||||
aCadstarSheetIDOverride, aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg,
|
||||
aScalingFactor, aTransformCentre, aMirrorInvert );
|
||||
|
||||
for( CUTOUT cutout : aCadstarFigure.Shape.Cutouts )
|
||||
{
|
||||
loadShapeVertices( cutout.Vertices, aCadstarFigure.LineCodeID, aCadstarFigure.LayerID,
|
||||
aKiCadSchLayerID );
|
||||
loadShapeVertices( cutout.Vertices, aCadstarFigure.LineCodeID, aCadstarSheetIDOverride,
|
||||
aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg, aScalingFactor,
|
||||
aTransformCentre, aMirrorInvert );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1612,6 +1686,41 @@ wxPoint CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLibraryPoint(
|
|||
}
|
||||
|
||||
|
||||
wxPoint CADSTAR_SCH_ARCHIVE_LOADER::applyTransform( const wxPoint& aPoint,
|
||||
const wxPoint& aMoveVector, const double& aRotationAngleDeciDeg,
|
||||
const double& aScalingFactor, const wxPoint& aTransformCentre, const bool& aMirrorInvert )
|
||||
{
|
||||
wxPoint retVal = aPoint;
|
||||
|
||||
if( aScalingFactor != 1.0 )
|
||||
{
|
||||
//scale point
|
||||
retVal -= aTransformCentre;
|
||||
retVal.x = KiROUND( retVal.x * aScalingFactor );
|
||||
retVal.y = KiROUND( retVal.y * aScalingFactor );
|
||||
retVal += aTransformCentre;
|
||||
}
|
||||
|
||||
if( aMirrorInvert )
|
||||
{
|
||||
MIRROR( retVal.x, aTransformCentre.x );
|
||||
MIRROR( retVal.x, aTransformCentre.x );
|
||||
}
|
||||
|
||||
if( aRotationAngleDeciDeg != 0.0 )
|
||||
{
|
||||
RotatePoint( &retVal, aTransformCentre, aRotationAngleDeciDeg );
|
||||
}
|
||||
|
||||
if( aMoveVector != wxPoint{ 0, 0 } )
|
||||
{
|
||||
retVal += aMoveVector;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
double CADSTAR_SCH_ARCHIVE_LOADER::getPolarAngle( wxPoint aPoint )
|
||||
{
|
||||
return NormalizeAnglePos( ArcTangente( aPoint.y, aPoint.x ) );
|
||||
|
|
|
@ -103,53 +103,77 @@ private:
|
|||
void loadNets();
|
||||
void loadFigures();
|
||||
void loadTexts();
|
||||
void loadDocumentationSymbols();
|
||||
|
||||
//Helper Functions for loading sheets
|
||||
void loadSheetAndChildSheets( LAYER_ID aCadstarSheetID, wxPoint aPosition, wxSize aSheetSize,
|
||||
SCH_SHEET* aParentSheet );
|
||||
|
||||
void loadChildSheets( LAYER_ID aCadstarSheetID );
|
||||
|
||||
std::vector<LAYER_ID> findOrphanSheets();
|
||||
int getSheetNumber( LAYER_ID aCadstarSheetID );
|
||||
void loadItemOntoKiCadSheet( LAYER_ID aCadstarSheetID, SCH_ITEM* aItem );
|
||||
|
||||
int getSheetNumber( LAYER_ID aCadstarSheetID );
|
||||
|
||||
void loadItemOntoKiCadSheet( LAYER_ID aCadstarSheetID, SCH_ITEM* aItem );
|
||||
|
||||
//Helper Functions for loading library items
|
||||
void loadSymDefIntoLibrary( const SYMDEF_ID& aSymdefID, const PART* aCadstarPart,
|
||||
const GATE_ID& aGateID, LIB_PART* aPart );
|
||||
|
||||
void loadLibrarySymbolShapeVertices( const std::vector<VERTEX>& aCadstarVertices,
|
||||
wxPoint aSymbolOrigin, LIB_PART* aPart, int aGateNumber );
|
||||
|
||||
void loadLibraryFieldAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
|
||||
wxPoint aSymbolOrigin, LIB_FIELD* aKiCadField );
|
||||
|
||||
//Helper Functions for loading symbols in schematic
|
||||
SCH_COMPONENT* loadSchematicSymbol( const SYMBOL& aCadstarSymbol, LIB_PART* aKiCadPart,
|
||||
double& aComponentOrientationDeciDeg );
|
||||
void loadSymbolFieldAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
|
||||
const double& aComponentOrientationDeciDeg, SCH_FIELD* aKiCadField );
|
||||
int getComponentOrientation(
|
||||
long long aCadstarOrientAngle, double& aReturnedOrientationDeciDeg );
|
||||
|
||||
void loadSymbolFieldAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
|
||||
const double& aComponentOrientationDeciDeg, SCH_FIELD* aKiCadField );
|
||||
|
||||
int getComponentOrientation(
|
||||
long long aCadstarOrientAngle, double& aReturnedOrientationDeciDeg );
|
||||
|
||||
//Helper functions for loading nets
|
||||
POINT getLocationOfNetElement( const NET_SCH& aNet, const NETELEMENT_ID& aNetElementID );
|
||||
POINT getLocationOfNetElement( const NET_SCH& aNet, const NETELEMENT_ID& aNetElementID );
|
||||
|
||||
wxString getNetName( const NET_SCH& aNet );
|
||||
|
||||
//Helper functions for loading figures / graphical items
|
||||
void loadShapeVertices( const std::vector<VERTEX>& aCadstarVertices,
|
||||
LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID,
|
||||
SCH_LAYER_ID aKiCadSchLayerID );
|
||||
LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID,
|
||||
const wxPoint& aMoveVector = { 0, 0 }, const double& aRotationAngleDeciDeg = 0.0,
|
||||
const double& aScalingFactor = 1.0, const wxPoint& aTransformCentre = { 0, 0 },
|
||||
const bool& aMirrorInvert = false );
|
||||
|
||||
void loadFigure( const FIGURE& aCadstarFigure, const LAYER_ID& aCadstarSheetIDOverride,
|
||||
SCH_LAYER_ID aKiCadSchLayerID );
|
||||
SCH_LAYER_ID aKiCadSchLayerID, const wxPoint& aMoveVector = { 0, 0 },
|
||||
const double& aRotationAngleDeciDeg = 0.0, const double& aScalingFactor = 1.0,
|
||||
const wxPoint& aTransformCentre = { 0, 0 }, const bool& aMirrorInvert = false );
|
||||
|
||||
//Helper functions for loading text elements
|
||||
void applyTextSettings( const TEXTCODE_ID& aCadstarTextCodeID,
|
||||
const ALIGNMENT& aCadstarAlignment, const JUSTIFICATION& aCadstarJustification,
|
||||
EDA_TEXT* aKiCadTextItem );
|
||||
SCH_TEXT* getKiCadSchText( const TEXT& aCadstarTextElement );
|
||||
|
||||
|
||||
//Helper Functions for obtaining CADSTAR elements from the parsed structures
|
||||
SYMDEF_ID getSymDefFromName( const wxString& aSymdefName, const wxString& aSymDefAlternate );
|
||||
wxString generateSymDefName( const SYMDEF_ID& aSymdefID );
|
||||
int getLineThickness( const LINECODE_ID& aCadstarLineCodeID );
|
||||
PLOT_DASH_TYPE getLineStyle( const LINECODE_ID& aCadstarLineCodeID );
|
||||
PART getPart( const PART_ID& aCadstarPartID );
|
||||
ROUTECODE getRouteCode( const ROUTECODE_ID& aCadstarRouteCodeID );
|
||||
TEXTCODE getTextCode( const TEXTCODE_ID& aCadstarTextCodeID );
|
||||
wxString getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID );
|
||||
wxString getAttributeValue( const ATTRIBUTE_ID& aCadstarAttributeID,
|
||||
const std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE>& aCadstarAttributeMap );
|
||||
|
||||
wxString generateSymDefName( const SYMDEF_ID& aSymdefID );
|
||||
int getLineThickness( const LINECODE_ID& aCadstarLineCodeID );
|
||||
PLOT_DASH_TYPE getLineStyle( const LINECODE_ID& aCadstarLineCodeID );
|
||||
PART getPart( const PART_ID& aCadstarPartID );
|
||||
ROUTECODE getRouteCode( const ROUTECODE_ID& aCadstarRouteCodeID );
|
||||
TEXTCODE getTextCode( const TEXTCODE_ID& aCadstarTextCodeID );
|
||||
wxString getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID );
|
||||
wxString getAttributeValue( const ATTRIBUTE_ID& aCadstarAttributeID,
|
||||
const std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE>& aCadstarAttributeMap );
|
||||
|
||||
PART::DEFINITION::PIN getPartDefinitionPin(
|
||||
const PART& aCadstarPart, const GATE_ID& aGateID, const TERMINAL_ID& aTerminalID );
|
||||
|
||||
|
@ -158,11 +182,8 @@ private:
|
|||
LABEL_SPIN_STYLE getSpinStyle( const long long& aCadstarOrientation, bool aMirror );
|
||||
LABEL_SPIN_STYLE getSpinStyleDeciDeg( const double& aOrientationDeciDeg );
|
||||
|
||||
void applyTextSettings( const TEXTCODE_ID& aCadstarTextCodeID,
|
||||
const ALIGNMENT& aCadstarAlignment, const JUSTIFICATION& aCadstarJustification,
|
||||
EDA_TEXT* aKiCadTextItem );
|
||||
SCH_TEXT* getKiCadSchText( const TEXT& aCadstarTextElement );
|
||||
|
||||
// General Graphical manipulation functions
|
||||
|
||||
std::pair<wxPoint, wxSize> getFigureExtentsKiCad( const FIGURE& aCadstarFigure );
|
||||
|
||||
|
@ -170,6 +191,9 @@ private:
|
|||
|
||||
wxPoint getKiCadLibraryPoint( wxPoint aCadstarPoint, wxPoint aCadstarCentre );
|
||||
|
||||
wxPoint applyTransform( const wxPoint& aPoint, const wxPoint& aMoveVector = { 0, 0 },
|
||||
const double& aRotationAngleDeciDeg = 0.0, const double& aScalingFactor = 1.0,
|
||||
const wxPoint& aTransformCentre = { 0, 0 }, const bool& aMirrorInvert = false );
|
||||
|
||||
int getKiCadLength( long long aCadstarLength )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue