KiCad PCB EDA Suite
CADSTAR_SCH_ARCHIVE_LOADER Class Reference

#include <cadstar_sch_archive_loader.h>

Inheritance diagram for CADSTAR_SCH_ARCHIVE_LOADER:
CADSTAR_SCH_ARCHIVE_PARSER CADSTAR_ARCHIVE_PARSER

Public Types

enum class  TERMINAL_SHAPE_TYPE {
  ANNULUS , BOX , BULLET , CIRCLE ,
  CROSS , DIAMOND , FINGER , OCTAGON ,
  PLUS , POINTER , RECTANGLE , ROUNDED_RECT ,
  SQUARE , STAR , TRIANGLE , UNDEFINED
}
 
typedef wxString TERMINALCODE_ID
 
typedef wxString SYMBOL_ID
 
typedef wxString BUS_ID
 
typedef wxString BLOCK_ID
 
typedef wxString SHEET_NAME
 
enum class  TEXT_FIELD_NAME {
  DESIGN_TITLE , SHORT_JOBNAME , LONG_JOBNAME , NUM_OF_SHEETS ,
  SHEET_NUMBER , SHEET_NAME , VARIANT_NAME , VARIANT_DESCRIPTION ,
  REG_USER , COMPANY_NAME , CURRENT_USER , DATE ,
  TIME , MACHINE_NAME , FROM_FILE , DISTANCE ,
  UNITS_SHORT , UNITS_ABBREV , UNITS_FULL , HYPERLINK ,
  NONE
}
 These are special fields in text objects enclosed between the tokens '<@' and '>' such as <@[FIELD_NAME][FIELD_VALUE]>. More...
 
enum class  RESOLUTION { HUNDREDTH_MICRON }
 
enum class  LINESTYLE {
  SOLID , DASH , DASHDOT , DASHDOTDOT ,
  DOT
}
 
enum class  VERTEX_TYPE {
  POINT , CLOCKWISE_ARC , CLOCKWISE_SEMICIRCLE , ANTICLOCKWISE_ARC ,
  ANTICLOCKWISE_SEMICIRCLE
}
 
enum class  SHAPE_TYPE { OPENSHAPE , OUTLINE , SOLID , HATCHED }
 
enum class  UNITS {
  DESIGN , THOU , INCH , MICROMETRE ,
  MM , CENTIMETER , METER
}
 
enum class  ANGUNITS { DEGREES , RADIANS }
 
enum class  GRID_TYPE { FRACTIONALGRID , STEPGRID }
 
enum class  ALIGNMENT {
  NO_ALIGNMENT , TOPLEFT , TOPCENTER , TOPRIGHT ,
  CENTERLEFT , CENTERCENTER , CENTERRIGHT , BOTTOMLEFT ,
  BOTTOMCENTER , BOTTOMRIGHT
}
 From CADSTAR Help: "Text Alignment enables you to define the position of an alignment origin for all text items in CADSTAR. More...
 
enum class  JUSTIFICATION { LEFT , CENTER , RIGHT }
 From CADSTAR Help: "Multi Line Text can also be justified as Left, Centre or Right. More...
 
enum class  READABILITY { BOTTOM_TO_TOP , TOP_TO_BOTTOM }
 Sets the readability direction of text. More...
 
enum class  ATTROWNER {
  ALL_ITEMS , AREA , BOARD , COMPONENT ,
  CONNECTION , COPPER , DOCSYMBOL , FIGURE ,
  NET , NETCLASS , PART , PART_DEFINITION ,
  PIN , SIGNALREF , SYMBOL , SYMDEF ,
  TEMPLATE , TESTPOINT
}
 
enum class  ATTRUSAGE {
  BOTH , COMPONENT , PART_DEFINITION , PART_LIBRARY ,
  SYMBOL , UNDEFINED
}
 
enum class  SWAP_RULE { NO_SWAP , USE_SWAP_LAYER , BOTH }
 Corresponds to "Display when" Item property. More...
 
typedef wxString LINECODE_ID
 
typedef wxString HATCHCODE_ID
 
typedef wxString ROUTECODE_ID
 
typedef wxString NETCLASS_ID
 
typedef wxString SPACING_CLASS_ID
 
typedef wxString TEXTCODE_ID
 
typedef wxString LAYER_ID
 ID of a Sheet (if schematic) or board Layer (if PCB) More...
 
typedef wxString VARIANT_ID
 
typedef wxString ATTRIBUTE_ID
 
typedef wxString SYMDEF_ID
 
typedef wxString PART_ID
 
typedef wxString GATE_ID
 
typedef long TERMINAL_ID
 Terminal is the pin identifier in the schematic. More...
 
typedef long PART_DEFINITION_PIN_ID
 Pin identifier in the part definition. More...
 
typedef long PART_PIN_ID
 Pin identifier in the part. More...
 
typedef wxString TEXT_ID
 
typedef wxString FIGURE_ID
 
typedef wxString GROUP_ID
 
typedef wxString REUSEBLOCK_ID
 
typedef wxString NET_ID
 
typedef wxString NETELEMENT_ID
 
typedef wxString DOCUMENTATION_SYMBOL_ID
 
typedef wxString COLOR_ID
 

Public Member Functions

 CADSTAR_SCH_ARCHIVE_LOADER (wxString aFilename, REPORTER *aReporter, PROGRESS_REPORTER *aProgressReporter)
 
 ~CADSTAR_SCH_ARCHIVE_LOADER ()
 
void Load (SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, SCH_PLUGIN::SCH_PLUGIN_RELEASER *aSchPlugin, const wxFileName &aLibraryFileName)
 Loads a CADSTAR PCB Archive file into the KiCad BOARD object given. More...
 
void Parse ()
 Parses the file. More...
 

Static Public Member Functions

static TERMINAL_SHAPE_TYPE ParseTermShapeType (const wxString &aShapeStr)
 
static wxString ParseTextFields (const wxString &aTextString, PARSER_CONTEXT *aParserContext)
 Replaces CADSTAR fields for the equivalent in KiCad and stores the field values in aParserContext. More...
 
static UNITS ParseUnits (XNODE *aNode)
 
static ANGUNITS ParseAngunits (XNODE *aNode)
 
static ALIGNMENT ParseAlignment (XNODE *aNode)
 
static JUSTIFICATION ParseJustification (XNODE *aNode)
 
static READABILITY ParseReadability (XNODE *aNode)
 
static SWAP_RULE ParseSwapRule (XNODE *aNode)
 
static void InsertAttributeAtEnd (XNODE *aNode, wxString aValue)
 
static XNODELoadArchiveFile (const wxString &aFileName, const wxString &aFileTypeIdentifier, PROGRESS_REPORTER *aProgressReporter=nullptr)
 Reads a CADSTAR Archive file (S-parameter format) More...
 
static bool IsValidAttribute (wxXmlAttribute *aAttribute)
 
static wxString GetXmlAttributeIDString (XNODE *aNode, unsigned int aID, bool aIsRequired=true)
 
static long GetXmlAttributeIDLong (XNODE *aNode, unsigned int aID, bool aIsRequired=true)
 
static void CheckNoChildNodes (XNODE *aNode)
 
static void CheckNoNextNodes (XNODE *aNode)
 
static void ParseChildEValue (XNODE *aNode, PARSER_CONTEXT *aContext, EVALUE &aValueToParse)
 
static std::vector< POINTParseAllChildPoints (XNODE *aNode, PARSER_CONTEXT *aContext, bool aTestAllChildNodes=false, int aExpectedNumPoints=UNDEFINED_VALUE)
 if no children are present, it just returns an empty vector (without throwing an exception) More...
 
static std::vector< VERTEXParseAllChildVertices (XNODE *aNode, PARSER_CONTEXT *aContext, bool aTestAllChildNodes=false)
 if no children are present, it just returns an empty vector (without throwing an exception) More...
 
static std::vector< CUTOUTParseAllChildCutouts (XNODE *aNode, PARSER_CONTEXT *aContext, bool aTestAllChildNodes=false)
 if no children are present, it just returns an empty vector (without throwing an exception) More...
 
static long GetNumberOfChildNodes (XNODE *aNode)
 
static long GetNumberOfStepsForReporting (XNODE *aRootNode, std::vector< wxString > aSubNodeChildrenToCount)
 
static wxString HandleTextOverbar (wxString aCadstarString)
 Convert a string with CADSTAR overbar characters to equivalent in KiCad. More...
 
static void FixTextPositionNoAlignment (EDA_TEXT *aKiCadTextItem)
 Corrects the position of a text element that had NO_ALIGNMENT in CADSTAR. More...
 
static wxString generateLibName (const wxString &aRefName, const wxString &aAlternateName)
 

Public Attributes

const int SMALL_LABEL_SIZE = KiROUND( (double) SCH_IU_PER_MM * 0.4 )
 
const double ARC_ACCURACY = SCH_IU_PER_MM * 0.01
 
wxString Filename
 
HEADER Header
 
ASSIGNMENTS_SCM Assignments
 
LIBRARY_SCM Library
 
PARTS Parts
 
SHEETS Sheets
 
CADSTAR_SCHEMATIC Schematic
 
ATTRCOLORS AttrColors
 
PARTNAMECOL SymbolPartNameColor
 
int KiCadUnitDivider
 Use this value to convert units in this CSA file to KiCad units. More...
 

Static Public Attributes

static const long UNDEFINED_VALUE = -1
 
static const double TXT_HEIGHT_RATIO = ( 24.0 - 5.0 ) / 24.0
 CADSTAR fonts are drawn on a 24x24 integer matrix, where the each axis goes from 0 to 24. More...
 
static const std::map< TEXT_FIELD_NAME, wxString > CADSTAR_TO_KICAD_FIELDS
 Map between CADSTAR fields and KiCad text variables. More...
 
static const long FONT_NORMAL = 400
 
static const long FONT_BOLD = 700
 

Protected Member Functions

void checkPoint ()
 Updates m_progressReporter or throws if user cancelled. More...
 

Protected Attributes

PARSER_CONTEXT m_context
 
PROGRESS_REPORTERm_progressReporter
 

Private Types

typedef std::pair< BLOCK_ID, TERMINAL_IDBLOCK_PIN_ID
 
typedef std::pair< PART_ID, GATE_IDPART_GATE_ID
 
typedef std::map< TERMINAL_ID, wxString > TERMINAL_TO_PINNUM_MAP
 Map between a terminal ID in a symbol definition to the pin number that should be imported into KiCad. More...
 

Private Member Functions

void loadSheets ()
 
void loadHierarchicalSheetPins ()
 
void loadPartsLibrary ()
 
void loadSchematicSymbolInstances ()
 
void loadBusses ()
 
void loadNets ()
 
void loadFigures ()
 
void loadTexts ()
 
void loadDocumentationSymbols ()
 
void loadTextVariables ()
 
void loadSheetAndChildSheets (LAYER_ID aCadstarSheetID, const VECTOR2I &aPosition, VECTOR2I aSheetSize, const SCH_SHEET_PATH &aParentSheet)
 
void loadChildSheets (LAYER_ID aCadstarSheetID, const SCH_SHEET_PATH &aSheet)
 
std::vector< LAYER_IDfindOrphanSheets ()
 
int getSheetNumber (LAYER_ID aCadstarSheetID)
 
void loadItemOntoKiCadSheet (LAYER_ID aCadstarSheetID, SCH_ITEM *aItem)
 
void loadSymDefIntoLibrary (const SYMDEF_ID &aSymdefID, const PART *aCadstarPart, const GATE_ID &aGateID, LIB_SYMBOL *aSymbol)
 
void loadLibrarySymbolShapeVertices (const std::vector< VERTEX > &aCadstarVertices, VECTOR2I aSymbolOrigin, LIB_SYMBOL *aSymbol, int aGateNumber, int aLineThickness)
 
void applyToLibraryFieldAttribute (const ATTRIBUTE_LOCATION &aCadstarAttrLoc, VECTOR2I aSymbolOrigin, LIB_FIELD *aKiCadField)
 
SCH_SYMBOLloadSchematicSymbol (const SYMBOL &aCadstarSymbol, const LIB_SYMBOL &aKiCadPart, EDA_ANGLE &aComponentOrientation)
 
void loadSymbolFieldAttribute (const ATTRIBUTE_LOCATION &aCadstarAttrLoc, const EDA_ANGLE &aComponentOrientation, bool aIsMirrored, SCH_FIELD *aKiCadField)
 
int getComponentOrientation (const EDA_ANGLE &aOrientAngle, EDA_ANGLE &aReturnedOrientation)
 
POINT getLocationOfNetElement (const NET_SCH &aNet, const NETELEMENT_ID &aNetElementID)
 
wxString getNetName (const NET_SCH &aNet)
 
void loadShapeVertices (const std::vector< VERTEX > &aCadstarVertices, LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID, const VECTOR2I &aMoveVector={ 0, 0 }, const EDA_ANGLE &aRotation=ANGLE_0, const double &aScalingFactor=1.0, const VECTOR2I &aTransformCentre={ 0, 0 }, const bool &aMirrorInvert=false)
 
void loadFigure (const FIGURE &aCadstarFigure, const LAYER_ID &aCadstarSheetIDOverride, SCH_LAYER_ID aKiCadSchLayerID, const VECTOR2I &aMoveVector={ 0, 0 }, const EDA_ANGLE &aRotation=ANGLE_0, const double &aScalingFactor=1.0, const VECTOR2I &aTransformCentre={ 0, 0 }, const bool &aMirrorInvert=false)
 
void applyTextSettings (EDA_TEXT *aKiCadTextItem, const TEXTCODE_ID &aCadstarTextCodeID, const ALIGNMENT &aCadstarAlignment, const JUSTIFICATION &aCadstarJustification, const long long aCadstarOrientAngle=0, bool aMirrored=false)
 
SCH_TEXTgetKiCadSchText (const TEXT &aCadstarTextElement)
 
SYMDEF_ID getSymDefFromName (const wxString &aSymdefName, const wxString &aSymDefAlternate)
 
bool isAttributeVisible (const ATTRIBUTE_ID &aCadstarAttributeID)
 
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)
 
int getTextHeightFromTextCode (const TEXTCODE_ID &aCadstarTextCodeID)
 
wxString getAttributeName (const ATTRIBUTE_ID &aCadstarAttributeID)
 
PART::DEFINITION::PIN getPartDefinitionPin (const PART &aCadstarPart, const GATE_ID &aGateID, const TERMINAL_ID &aTerminalID)
 
ELECTRICAL_PINTYPE getKiCadPinType (const PART::PIN_TYPE &aPinType)
 
int getKiCadUnitNumberFromGate (const GATE_ID &aCadstarGateID)
 
TEXT_SPIN_STYLE getSpinStyle (const long long &aCadstarOrientation, bool aMirror)
 
TEXT_SPIN_STYLE getSpinStyle (const EDA_ANGLE &aOrientation)
 
ALIGNMENT mirrorX (const ALIGNMENT &aCadstarAlignment)
 
ALIGNMENT rotate180 (const ALIGNMENT &aCadstarAlignment)
 
LIB_SYMBOLgetScaledLibPart (const LIB_SYMBOL *aSymbol, long long aScalingFactorNumerator, long long aScalingFactorDenominator)
 
void fixUpLibraryPins (LIB_SYMBOL *aSymbolToFix, int aGateNumber)
 
std::pair< VECTOR2I, VECTOR2IgetFigureExtentsKiCad (const FIGURE &aCadstarFigure)
 
VECTOR2I getKiCadPoint (const VECTOR2I &aCadstarPoint)
 
VECTOR2I getKiCadLibraryPoint (const VECTOR2I &aCadstarPoint, const VECTOR2I &aCadstarCentre)
 
VECTOR2I applyTransform (const VECTOR2I &aPoint, const VECTOR2I &aMoveVector={ 0, 0 }, const EDA_ANGLE &aRotation=ANGLE_0, const double &aScalingFactor=1.0, const VECTOR2I &aTransformCentre={ 0, 0 }, const bool &aMirrorInvert=false)
 
int getKiCadLength (long long aCadstarLength)
 
EDA_ANGLE getAngle (const long long &aCadstarAngle)
 
long long getCadstarAngle (const EDA_ANGLE &aAngle)
 
double getPolarRadius (const VECTOR2I &aPoint)
 

Private Attributes

REPORTERm_reporter
 
SCHEMATICm_schematic
 
SCH_SHEETm_rootSheet
 
SCH_PLUGIN::SCH_PLUGIN_RELEASERm_plugin
 
wxFileName m_libraryFileName
 
wxPoint m_designCenter
 Used for calculating the required offset to apply to the Cadstar design so that it fits in KiCad canvas. More...
 
std::map< LAYER_ID, SCH_SHEET * > m_sheetMap
 Map between Cadstar and KiCad Sheets. More...
 
std::map< BLOCK_PIN_ID, SCH_HIERLABEL * > m_sheetPinMap
 Map between Cadstar and KiCad Sheets Pins. More...
 
std::map< PART_ID, LIB_SYMBOL * > m_partMap
 Map between Cadstar and KiCad Parts. More...
 
std::map< PART_GATE_ID, SYMDEF_IDm_partSymbolsMap
 Map holding the symbols loaded so far for a particular PART_ID and GATE_ID. More...
 
std::map< PART_ID, TERMINAL_TO_PINNUM_MAPm_pinNumsMap
 Map of pin numbers in CADSTAR parts. More...
 
std::map< wxString, LIB_SYMBOL * > m_powerSymLibMap
 Map of KiCad Power Symbol Library items. More...
 
std::map< SYMBOL_ID, SCH_SYMBOL * > m_powerSymMap
 Map between Cadstar and KiCad Power Symbols. More...
 
std::map< SYMBOL_ID, SCH_GLOBALLABEL * > m_globalLabelsMap
 Map between Cadstar and KiCad Global Labels. More...
 
std::map< BUS_ID, std::shared_ptr< BUS_ALIAS > > m_busesMap
 Map of Cadstar and KiCad Buses. More...
 
XNODEm_rootNode
 

Detailed Description

Definition at line 52 of file cadstar_sch_archive_loader.h.

Member Typedef Documentation

◆ ATTRIBUTE_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_ID
inherited

Definition at line 107 of file cadstar_archive_parser.h.

◆ BLOCK_ID

typedef wxString CADSTAR_SCH_ARCHIVE_PARSER::BLOCK_ID
inherited

Definition at line 61 of file cadstar_sch_archive_parser.h.

◆ BLOCK_PIN_ID

Definition at line 87 of file cadstar_sch_archive_loader.h.

◆ BUS_ID

typedef wxString CADSTAR_SCH_ARCHIVE_PARSER::BUS_ID
inherited

Definition at line 60 of file cadstar_sch_archive_parser.h.

◆ COLOR_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::COLOR_ID
inherited

Definition at line 121 of file cadstar_archive_parser.h.

◆ DOCUMENTATION_SYMBOL_ID

Definition at line 120 of file cadstar_archive_parser.h.

◆ FIGURE_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::FIGURE_ID
inherited

Definition at line 115 of file cadstar_archive_parser.h.

◆ GATE_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::GATE_ID
inherited

Definition at line 110 of file cadstar_archive_parser.h.

◆ GROUP_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::GROUP_ID
inherited

Definition at line 116 of file cadstar_archive_parser.h.

◆ HATCHCODE_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::HATCHCODE_ID
inherited

Definition at line 100 of file cadstar_archive_parser.h.

◆ LAYER_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::LAYER_ID
inherited

ID of a Sheet (if schematic) or board Layer (if PCB)

Definition at line 105 of file cadstar_archive_parser.h.

◆ LINECODE_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::LINECODE_ID
inherited

Definition at line 99 of file cadstar_archive_parser.h.

◆ NET_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::NET_ID
inherited

Definition at line 118 of file cadstar_archive_parser.h.

◆ NETCLASS_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::NETCLASS_ID
inherited

Definition at line 102 of file cadstar_archive_parser.h.

◆ NETELEMENT_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::NETELEMENT_ID
inherited

Definition at line 119 of file cadstar_archive_parser.h.

◆ PART_DEFINITION_PIN_ID

Pin identifier in the part definition.

Definition at line 112 of file cadstar_archive_parser.h.

◆ PART_GATE_ID

Definition at line 88 of file cadstar_sch_archive_loader.h.

◆ PART_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::PART_ID
inherited

Definition at line 109 of file cadstar_archive_parser.h.

◆ PART_PIN_ID

typedef long CADSTAR_ARCHIVE_PARSER::PART_PIN_ID
inherited

Pin identifier in the part.

Definition at line 113 of file cadstar_archive_parser.h.

◆ REUSEBLOCK_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::REUSEBLOCK_ID
inherited

Definition at line 117 of file cadstar_archive_parser.h.

◆ ROUTECODE_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::ROUTECODE_ID
inherited

Definition at line 101 of file cadstar_archive_parser.h.

◆ SHEET_NAME

typedef wxString CADSTAR_SCH_ARCHIVE_PARSER::SHEET_NAME
inherited

Definition at line 62 of file cadstar_sch_archive_parser.h.

◆ SPACING_CLASS_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::SPACING_CLASS_ID
inherited

Definition at line 103 of file cadstar_archive_parser.h.

◆ SYMBOL_ID

typedef wxString CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL_ID
inherited

Definition at line 59 of file cadstar_sch_archive_parser.h.

◆ SYMDEF_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::SYMDEF_ID
inherited

Definition at line 108 of file cadstar_archive_parser.h.

◆ TERMINAL_ID

typedef long CADSTAR_ARCHIVE_PARSER::TERMINAL_ID
inherited

Terminal is the pin identifier in the schematic.

Definition at line 111 of file cadstar_archive_parser.h.

◆ TERMINAL_TO_PINNUM_MAP

Map between a terminal ID in a symbol definition to the pin number that should be imported into KiCad.

Definition at line 94 of file cadstar_sch_archive_loader.h.

◆ TERMINALCODE_ID

typedef wxString CADSTAR_SCH_ARCHIVE_PARSER::TERMINALCODE_ID
inherited

Definition at line 58 of file cadstar_sch_archive_parser.h.

◆ TEXT_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::TEXT_ID
inherited

Definition at line 114 of file cadstar_archive_parser.h.

◆ TEXTCODE_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::TEXTCODE_ID
inherited

Definition at line 104 of file cadstar_archive_parser.h.

◆ VARIANT_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::VARIANT_ID
inherited

Definition at line 106 of file cadstar_archive_parser.h.

Member Enumeration Documentation

◆ ALIGNMENT

enum class CADSTAR_ARCHIVE_PARSER::ALIGNMENT
stronginherited

From CADSTAR Help: "Text Alignment enables you to define the position of an alignment origin for all text items in CADSTAR.

The alignment origin is a point on or within the text boundary and defines how the text is displayed.

For example, with an alignment of bottom-right the origin will be positioned at the bottom right of the text boundary. This makes it easier to right-align several text items regardless of the length of text displayed.

Text Alignment applies to all CADSTAR text. [...]

Note: Unaligned text operates in the way CADSTAR text always has. In most cases this behaves as Bottom Left alignment, but there are a few exceptions, e.g. pin names. Also unaligned multiline text has an origin Bottom Left of the first line."

See also JUSTIFICATION

Enumerator
NO_ALIGNMENT 

NO_ALIGNMENT has different meaning depending on the object type.

TOPLEFT 
TOPCENTER 
TOPRIGHT 
CENTERLEFT 
CENTERCENTER 
CENTERRIGHT 
BOTTOMLEFT 
BOTTOMCENTER 
BOTTOMRIGHT 

Definition at line 608 of file cadstar_archive_parser.h.

609 {
610 NO_ALIGNMENT,
611 TOPLEFT,
612 TOPCENTER,
613 TOPRIGHT,
614 CENTERLEFT,
615 CENTERCENTER,
616 CENTERRIGHT,
617 BOTTOMLEFT,
618 BOTTOMCENTER,
619 BOTTOMRIGHT
620 };

◆ ANGUNITS

enum class CADSTAR_ARCHIVE_PARSER::ANGUNITS
stronginherited
Enumerator
DEGREES 
RADIANS 

Definition at line 518 of file cadstar_archive_parser.h.

519 {
520 DEGREES,
521 RADIANS
522 };

◆ ATTROWNER

enum class CADSTAR_ARCHIVE_PARSER::ATTROWNER
stronginherited
Enumerator
ALL_ITEMS 
AREA 
BOARD 
COMPONENT 
CONNECTION 
COPPER 
DOCSYMBOL 
FIGURE 
NET 
NETCLASS 
PART 

Only library Attributes.

PART_DEFINITION 

Only library Attributes.

PIN 
SIGNALREF 
SYMBOL 
SYMDEF 
TEMPLATE 
TESTPOINT 

Definition at line 662 of file cadstar_archive_parser.h.

663 {
664 ALL_ITEMS,
665 AREA,
666 BOARD,
667 COMPONENT,
668 CONNECTION,
669 COPPER,
670 DOCSYMBOL,
671 FIGURE,
672 NET,
673 NETCLASS,
674 PART,
675 PART_DEFINITION,
676 PIN,
677 SIGNALREF,
678 SYMBOL,
679 SYMDEF,
680 TEMPLATE,
682 };
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:269
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:85
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:47
@ TESTPOINT
a test point pad
@ NET
This item represents a net.

◆ ATTRUSAGE

enum class CADSTAR_ARCHIVE_PARSER::ATTRUSAGE
stronginherited
Enumerator
BOTH 

From CADSTAR Help: Assigned to both Schematic symbols and PCB components, and displayed on Schematic and PCB designs.

COMPONENT 

From CADSTAR Help: Assigned to PCB components and displayed on PCB designs.

PART_DEFINITION 

From CADSTAR Help: Assigned to Parts library Definitions and displayed by the Library searcher.

PART_LIBRARY 

From CADSTAR Help: Only used by non-Cadstar applications.

SYMBOL 

From CADSTAR Help: Assigned to Schematic Symbols and displayed on Schematic Designs.

UNDEFINED 

Note: It seems that some attribute have no "ATTRUSAGE" defined.

It appears that the attributes that fall under this category are the ones associated with the design itself (i.e. not inherited from the library)

Definition at line 685 of file cadstar_archive_parser.h.

686 {
687 BOTH,
689 COMPONENT,
690 PART_DEFINITION,
692 PART_LIBRARY,
693 SYMBOL,
695 UNDEFINED
698 };

◆ GRID_TYPE

enum class CADSTAR_ARCHIVE_PARSER::GRID_TYPE
stronginherited
Enumerator
FRACTIONALGRID 

Param1 = Units, Param2 = Divisor.

The grid is equal in X and Y dimensions with a step size equal to Param1/Param2

STEPGRID 

Param1 = X Step, Param2 = Y Step. A standard x,y grid.

Definition at line 528 of file cadstar_archive_parser.h.

529 {
530 FRACTIONALGRID,
532 STEPGRID
533 };

◆ JUSTIFICATION

enum class CADSTAR_ARCHIVE_PARSER::JUSTIFICATION
stronginherited

From CADSTAR Help: "Multi Line Text can also be justified as Left, Centre or Right.

This does not affect the text alignment. Note: Justification of single line text has no effect."

This only affects multiline text

See also ALIGNMENT

Enumerator
LEFT 
CENTER 
RIGHT 

Definition at line 634 of file cadstar_archive_parser.h.

◆ LINESTYLE

enum class CADSTAR_ARCHIVE_PARSER::LINESTYLE
stronginherited
Enumerator
SOLID 
DASH 
DASHDOT 
DASHDOTDOT 
DOT 

Definition at line 287 of file cadstar_archive_parser.h.

◆ READABILITY

enum class CADSTAR_ARCHIVE_PARSER::READABILITY
stronginherited

Sets the readability direction of text.

From CADSTAR Help: "Horizontal text will always be displayed from left to right (i.e. never upside down). Vertical text can be set as readable from either the left or right edge of the design."

I.e. Vertical text can either be rotated 90 degrees clockwise or 90 degrees anticlockwise from horizontal. This does not impact vertical text

Enumerator
BOTTOM_TO_TOP 

When text is vertical, show it rotated 90 degrees anticlockwise.

TOP_TO_BOTTOM 

When text is vertical, show it rotated 90 degrees clockwise.

Definition at line 652 of file cadstar_archive_parser.h.

653 {
654 BOTTOM_TO_TOP,
655 TOP_TO_BOTTOM
656 };

◆ RESOLUTION

enum class CADSTAR_ARCHIVE_PARSER::RESOLUTION
stronginherited
Enumerator
HUNDREDTH_MICRON 

Definition at line 249 of file cadstar_archive_parser.h.

250 {
251 HUNDREDTH_MICRON
252 };

◆ SHAPE_TYPE

enum class CADSTAR_ARCHIVE_PARSER::SHAPE_TYPE
stronginherited
Enumerator
OPENSHAPE 

Unfilled open shape. Cannot have cutouts.

OUTLINE 

Unfilled closed shape.

SOLID 

Filled closed shape (solid fill).

HATCHED 

Filled closed shape (hatch fill).

Definition at line 474 of file cadstar_archive_parser.h.

475 {
476 OPENSHAPE,
477 OUTLINE,
478 SOLID,
479 HATCHED
480 };

◆ SWAP_RULE

enum class CADSTAR_ARCHIVE_PARSER::SWAP_RULE
stronginherited

Corresponds to "Display when" Item property.

From CADSTAR Help: "This parameter enables you to make the visibility of a component outline/area (or an area of component copper, or a string of component text) dependent on the current mirror status of the component. For example, you may require a string of component text to be displayed only when the component is mirrored."

Enumerator
NO_SWAP 

Display when Unmirrored.

USE_SWAP_LAYER 

Display when Mirrored.

BOTH 

Always display (Mirrored and Unmirrored)

Definition at line 842 of file cadstar_archive_parser.h.

843 {
844 NO_SWAP,
845 USE_SWAP_LAYER,
846 BOTH
847 };

◆ TERMINAL_SHAPE_TYPE

Enumerator
ANNULUS 
BOX 
BULLET 
CIRCLE 

Keyword "ROUND".

CROSS 
DIAMOND 
FINGER 
OCTAGON 
PLUS 
POINTER 
RECTANGLE 
ROUNDED_RECT 

Keyword "ROUNDED".

SQUARE 
STAR 
TRIANGLE 
UNDEFINED 

Only used for error checking (not a real shape)

Definition at line 65 of file cadstar_sch_archive_parser.h.

66 {
67 ANNULUS,
68 BOX,
69 BULLET,
70 CIRCLE,
71 CROSS,
72 DIAMOND,
73 FINGER,
74 OCTAGON,
75 PLUS,
76 POINTER,
78 ROUNDED_RECT,
79 SQUARE,
80 STAR,
83 };
Represent basic circle geometry with utility geometry functions.
Definition: circle.h:33
A triangle object.
Definition: triangle_3d.h:43

◆ TEXT_FIELD_NAME

enum class CADSTAR_ARCHIVE_PARSER::TEXT_FIELD_NAME
stronginherited

These are special fields in text objects enclosed between the tokens '<@' and '>' such as <@[FIELD_NAME][FIELD_VALUE]>.

For example: "<@DESIGN TITLEProject [email protected]>"

Enumerator
DESIGN_TITLE 
SHORT_JOBNAME 
LONG_JOBNAME 
NUM_OF_SHEETS 
SHEET_NUMBER 
SHEET_NAME 
VARIANT_NAME 
VARIANT_DESCRIPTION 
REG_USER 
COMPANY_NAME 
CURRENT_USER 
DATE 
TIME 
MACHINE_NAME 
FROM_FILE 
DISTANCE 
UNITS_SHORT 
UNITS_ABBREV 
UNITS_FULL 
HYPERLINK 
NONE 

Synthetic for flagging.

Definition at line 142 of file cadstar_archive_parser.h.

143 {
144 DESIGN_TITLE,
145 SHORT_JOBNAME,
146 LONG_JOBNAME,
147 NUM_OF_SHEETS,
148 SHEET_NUMBER,
150 VARIANT_NAME,
151 VARIANT_DESCRIPTION,
152 REG_USER,
153 COMPANY_NAME,
154 CURRENT_USER,
155 DATE,
156 TIME,
157 MACHINE_NAME,
158 FROM_FILE,
159 DISTANCE,
160 UNITS_SHORT,
161 UNITS_ABBREV,
162 UNITS_FULL,
163 HYPERLINK,
164 NONE
165 };
@ NONE
Definition: kibis.h:53

◆ UNITS

enum class CADSTAR_ARCHIVE_PARSER::UNITS
stronginherited
Enumerator
DESIGN 

Inherits from design units (assumed Assignments->Technology->Units)

THOU 
INCH 
MICROMETRE 
MM 
CENTIMETER 
METER 

Definition at line 503 of file cadstar_archive_parser.h.

504 {
505 DESIGN,
506 THOU,
507 INCH,
508 MICROMETRE,
509 MM,
511 METER
512 };
@ INCH
Definition: rs274x.cpp:64

◆ VERTEX_TYPE

enum class CADSTAR_ARCHIVE_PARSER::VERTEX_TYPE
stronginherited
Enumerator
POINT 
CLOCKWISE_ARC 
CLOCKWISE_SEMICIRCLE 
ANTICLOCKWISE_ARC 
ANTICLOCKWISE_SEMICIRCLE 

Definition at line 428 of file cadstar_archive_parser.h.

429 {
430 POINT,
431 CLOCKWISE_ARC,
432 CLOCKWISE_SEMICIRCLE,
433 ANTICLOCKWISE_ARC,
434 ANTICLOCKWISE_SEMICIRCLE
435 };

Constructor & Destructor Documentation

◆ CADSTAR_SCH_ARCHIVE_LOADER()

CADSTAR_SCH_ARCHIVE_LOADER::CADSTAR_SCH_ARCHIVE_LOADER ( wxString  aFilename,
REPORTER aReporter,
PROGRESS_REPORTER aProgressReporter 
)
inlineexplicit

Definition at line 59 of file cadstar_sch_archive_loader.h.

60 :
62 {
63 m_schematic = nullptr;
64 m_rootSheet = nullptr;
65 m_plugin = nullptr;
66 m_designCenter.x = 0;
67 m_designCenter.y = 0;
68 m_reporter = aReporter;
69 m_progressReporter = aProgressReporter;
70 }
PROGRESS_REPORTER * m_progressReporter
SCH_PLUGIN::SCH_PLUGIN_RELEASER * m_plugin
wxPoint m_designCenter
Used for calculating the required offset to apply to the Cadstar design so that it fits in KiCad canv...
CADSTAR_SCH_ARCHIVE_PARSER(wxString aFilename)

References m_designCenter, m_plugin, CADSTAR_ARCHIVE_PARSER::m_progressReporter, m_reporter, m_rootSheet, and m_schematic.

◆ ~CADSTAR_SCH_ARCHIVE_LOADER()

CADSTAR_SCH_ARCHIVE_LOADER::~CADSTAR_SCH_ARCHIVE_LOADER ( )
inline

Definition at line 73 of file cadstar_sch_archive_loader.h.

74 {
75 }

Member Function Documentation

◆ applyTextSettings()

void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings ( EDA_TEXT aKiCadTextItem,
const TEXTCODE_ID aCadstarTextCodeID,
const ALIGNMENT aCadstarAlignment,
const JUSTIFICATION aCadstarJustification,
const long long  aCadstarOrientAngle = 0,
bool  aMirrored = false 
)
private

Definition at line 2607 of file cadstar_sch_archive_loader.cpp.

2613{
2614 // Justification ignored for now as not supported in Eeschema, but leaving this code in
2615 // place for future upgrades.
2616 // TODO update this when Eeschema supports justification independent of anchor position.
2617
2618 TEXTCODE textCode = getTextCode( aCadstarTextCodeID );
2619 int textHeight = KiROUND( (double) getKiCadLength( textCode.Height ) * TXT_HEIGHT_RATIO );
2620 int textWidth = getKiCadLength( textCode.Width );
2621
2622 // Ensure we have no Cadstar overbar characters
2623 wxString escapedText = HandleTextOverbar( aKiCadTextItem->GetText() );
2624 aKiCadTextItem->SetText( escapedText );
2625
2626 // The width is zero for all non-cadstar fonts. Using a width equal to 2/3 the height seems
2627 // to work well for most fonts.
2628 if( textWidth == 0 )
2629 textWidth = getKiCadLength( 2 * textCode.Height / 3 );
2630
2631 aKiCadTextItem->SetTextWidth( textWidth );
2632 aKiCadTextItem->SetTextHeight( textHeight );
2633 aKiCadTextItem->SetTextThickness( getKiCadLength( textCode.LineWidth ) );
2634 aKiCadTextItem->SetTextAngle( getAngle( aCadstarOrientAngle ) );
2635 aKiCadTextItem->SetBold( textCode.Font.Modifier1 == FONT_BOLD );
2636 aKiCadTextItem->SetItalic( textCode.Font.Italic );
2637
2638 ALIGNMENT textAlignment = aCadstarAlignment;
2639
2640 // KiCad mirrors the justification and alignment when the symbol is mirrored but CADSTAR
2641 // specifies it post-mirroring. In contrast, if the text item itself is mirrored (not
2642 // supported in KiCad), CADSTAR specifies the alignment and justification pre-mirroring
2643 if( aMirrored )
2644 textAlignment = mirrorX( aCadstarAlignment );
2645
2646 auto setAlignment =
2647 [&]( EDA_TEXT* aText, ALIGNMENT aAlignment )
2648 {
2649 switch( aAlignment )
2650 {
2651 case ALIGNMENT::NO_ALIGNMENT: // Bottom left of the first line
2652 //No exact KiCad equivalent, so lets move the position of the text
2658 break;
2659
2663 break;
2664
2668 break;
2669
2673 break;
2674
2678 break;
2679
2683 break;
2684
2685 case ALIGNMENT::TOPLEFT:
2688 break;
2689
2693 break;
2694
2698 break;
2699 }
2700 };
2701
2702 TEXT_SPIN_STYLE spin = getSpinStyle( aCadstarOrientAngle, aMirrored );
2703 EDA_ITEM* textEdaItem = dynamic_cast<EDA_ITEM*>( aKiCadTextItem );
2704 wxCHECK( textEdaItem, /* void */ ); // ensure this is a EDA_ITEM
2705
2706 switch( textEdaItem->Type() )
2707 {
2708 // Some KiCad schematic text items only permit a limited amount of angles
2709 // and text justifications
2710 case LIB_TEXT_T:
2711 case SCH_FIELD_T:
2712 case LIB_FIELD_T:
2713 {
2714 // Spin style not used. All text justifications are permitted. However, only orientations
2715 // of 0 deg or 90 deg are supported
2716 EDA_ANGLE angle = aKiCadTextItem->GetTextAngle();
2717 angle.Normalize();
2718
2719 int quadrant = KiROUND( angle.AsDegrees() / 90.0 );
2720 quadrant %= 4;
2721
2722 switch( quadrant )
2723 {
2724 case 0:
2726 break;
2727 case 1:
2729 break;
2730 case 2:
2732 textAlignment = rotate180( textAlignment );
2733 break;
2734 case 3:
2736 textAlignment = rotate180( textAlignment );
2737 break;
2738 default: wxFAIL_MSG( "Unknown Quadrant" );
2739 }
2740
2741 aKiCadTextItem->SetTextAngle( angle );
2742 setAlignment( aKiCadTextItem, textAlignment );
2743 return;
2744 }
2745
2746 case SCH_TEXT_T:
2747 {
2748 // Note spin style in a SCH_TEXT results in a vertical alignment GR_TEXT_V_ALIGN_BOTTOM
2749 // so need to adjust the location of the text element based on Cadstar's original text
2750 // alignment (anchor position).
2751 setAlignment( aKiCadTextItem, textAlignment );
2752 BOX2I bb = textEdaItem->GetBoundingBox();
2753 int off = static_cast<SCH_TEXT*>( aKiCadTextItem )->GetTextOffset();
2754 VECTOR2I pos;
2755
2756 // Change the anchor point of the text item to make it match the same bounding box
2757 // And correct the error introduced by the text offsetting in KiCad
2758 switch( spin )
2759 {
2760 case TEXT_SPIN_STYLE::BOTTOM: pos = { bb.GetRight() - off, bb.GetTop() }; break;
2761 case TEXT_SPIN_STYLE::UP: pos = { bb.GetRight() - off, bb.GetBottom() }; break;
2762 case TEXT_SPIN_STYLE::LEFT: pos = { bb.GetRight() , bb.GetBottom() + off }; break;
2763 case TEXT_SPIN_STYLE::RIGHT: pos = { bb.GetLeft() , bb.GetBottom() + off }; break;
2764 }
2765
2766 aKiCadTextItem->SetTextPos( pos );
2767 }
2769
2770 // We don't want to change position of net labels as that would break connectivity
2771 case SCH_LABEL_T:
2772 case SCH_GLOBAL_LABEL_T:
2773 case SCH_HIER_LABEL_T:
2774 case SCH_SHEET_PIN_T:
2775 static_cast<SCH_TEXT*>( aKiCadTextItem )->SetTextSpinStyle( spin );
2776 return;
2777
2778 default:
2779 wxFAIL_MSG( "Unexpected item type" );
2780 return;
2781 }
2782}
coord_type GetTop() const
Definition: box2.h:194
coord_type GetRight() const
Definition: box2.h:189
coord_type GetLeft() const
Definition: box2.h:193
coord_type GetBottom() const
Definition: box2.h:190
ALIGNMENT
From CADSTAR Help: "Text Alignment enables you to define the position of an alignment origin for all ...
@ NO_ALIGNMENT
NO_ALIGNMENT has different meaning depending on the object type.
static void FixTextPositionNoAlignment(EDA_TEXT *aKiCadTextItem)
Corrects the position of a text element that had NO_ALIGNMENT in CADSTAR.
static const double TXT_HEIGHT_RATIO
CADSTAR fonts are drawn on a 24x24 integer matrix, where the each axis goes from 0 to 24.
static wxString HandleTextOverbar(wxString aCadstarString)
Convert a string with CADSTAR overbar characters to equivalent in KiCad.
TEXT_SPIN_STYLE getSpinStyle(const long long &aCadstarOrientation, bool aMirror)
TEXTCODE getTextCode(const TEXTCODE_ID &aCadstarTextCodeID)
int getKiCadLength(long long aCadstarLength)
EDA_ANGLE getAngle(const long long &aCadstarAngle)
ALIGNMENT rotate180(const ALIGNMENT &aCadstarAlignment)
ALIGNMENT mirrorX(const ALIGNMENT &aCadstarAlignment)
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:74
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:72
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:120
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:373
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:250
void SetTextWidth(int aWidth)
Definition: eda_text.cpp:357
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:187
void SetTextHeight(int aHeight)
Definition: eda_text.cpp:365
void SetBold(bool aBold)
Definition: eda_text.cpp:211
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:165
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:195
void SetItalic(bool aItalic)
Definition: eda_text.cpp:203
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:242
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
Definition: eda_angle.h:425
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:426
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
@ LIB_TEXT_T
Definition: typeinfo.h:200
@ SCH_FIELD_T
Definition: typeinfo.h:155
@ SCH_LABEL_T
Definition: typeinfo.h:151
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:153
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:157
@ SCH_TEXT_T
Definition: typeinfo.h:150
@ LIB_FIELD_T
Definition: typeinfo.h:208
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:152
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85

References PNS::angle(), ANGLE_HORIZONTAL, ANGLE_VERTICAL, TEXT_SPIN_STYLE::BOTTOM, CADSTAR_ARCHIVE_PARSER::BOTTOMCENTER, CADSTAR_ARCHIVE_PARSER::BOTTOMLEFT, CADSTAR_ARCHIVE_PARSER::BOTTOMRIGHT, CADSTAR_ARCHIVE_PARSER::CENTERCENTER, CADSTAR_ARCHIVE_PARSER::CENTERLEFT, CADSTAR_ARCHIVE_PARSER::CENTERRIGHT, CADSTAR_ARCHIVE_PARSER::FixTextPositionNoAlignment(), CADSTAR_ARCHIVE_PARSER::TEXTCODE::Font, CADSTAR_ARCHIVE_PARSER::FONT_BOLD, getAngle(), BOX2< Vec >::GetBottom(), EDA_ITEM::GetBoundingBox(), getKiCadLength(), BOX2< Vec >::GetLeft(), BOX2< Vec >::GetRight(), getSpinStyle(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), getTextCode(), BOX2< Vec >::GetTop(), GR_TEXT_H_ALIGN_CENTER, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_BOTTOM, GR_TEXT_V_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP, CADSTAR_ARCHIVE_PARSER::HandleTextOverbar(), CADSTAR_ARCHIVE_PARSER::TEXTCODE::Height, CADSTAR_ARCHIVE_PARSER::FONT::Italic, KI_FALLTHROUGH, KiROUND(), TEXT_SPIN_STYLE::LEFT, LIB_FIELD_T, LIB_TEXT_T, CADSTAR_ARCHIVE_PARSER::TEXTCODE::LineWidth, mirrorX(), CADSTAR_ARCHIVE_PARSER::FONT::Modifier1, CADSTAR_ARCHIVE_PARSER::NO_ALIGNMENT, TEXT_SPIN_STYLE::RIGHT, rotate180(), SCH_FIELD_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_LABEL_T, SCH_SHEET_PIN_T, SCH_TEXT_T, EDA_TEXT::SetBold(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), EDA_TEXT::SetText(), EDA_TEXT::SetTextAngle(), EDA_TEXT::SetTextHeight(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextThickness(), EDA_TEXT::SetTextWidth(), EDA_TEXT::SetVertJustify(), CADSTAR_ARCHIVE_PARSER::TOPCENTER, CADSTAR_ARCHIVE_PARSER::TOPLEFT, CADSTAR_ARCHIVE_PARSER::TOPRIGHT, CADSTAR_ARCHIVE_PARSER::TXT_HEIGHT_RATIO, EDA_ITEM::Type(), TEXT_SPIN_STYLE::UP, and CADSTAR_ARCHIVE_PARSER::TEXTCODE::Width.

Referenced by applyToLibraryFieldAttribute(), getKiCadSchText(), loadBusses(), loadChildSheets(), loadNets(), loadSchematicSymbolInstances(), loadSymbolFieldAttribute(), and loadSymDefIntoLibrary().

◆ applyToLibraryFieldAttribute()

void CADSTAR_SCH_ARCHIVE_LOADER::applyToLibraryFieldAttribute ( const ATTRIBUTE_LOCATION aCadstarAttrLoc,
VECTOR2I  aSymbolOrigin,
LIB_FIELD aKiCadField 
)
private

Definition at line 1729 of file cadstar_sch_archive_loader.cpp.

1731{
1732 aKiCadField->SetTextPos( getKiCadLibraryPoint( aCadstarAttrLoc.Position, aSymbolOrigin ) );
1733
1734 applyTextSettings( aKiCadField,
1735 aCadstarAttrLoc.TextCodeID,
1736 aCadstarAttrLoc.Alignment,
1737 aCadstarAttrLoc.Justification,
1738 aCadstarAttrLoc.OrientAngle,
1739 aCadstarAttrLoc.Mirror );
1740}
void applyTextSettings(EDA_TEXT *aKiCadTextItem, const TEXTCODE_ID &aCadstarTextCodeID, const ALIGNMENT &aCadstarAlignment, const JUSTIFICATION &aCadstarJustification, const long long aCadstarOrientAngle=0, bool aMirrored=false)
VECTOR2I getKiCadLibraryPoint(const VECTOR2I &aCadstarPoint, const VECTOR2I &aCadstarCentre)

References CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Alignment, applyTextSettings(), getKiCadLibraryPoint(), CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Justification, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Mirror, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::OrientAngle, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Position, EDA_TEXT::SetTextPos(), and CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::TextCodeID.

Referenced by loadSymDefIntoLibrary().

◆ applyTransform()

VECTOR2I CADSTAR_SCH_ARCHIVE_LOADER::applyTransform ( const VECTOR2I aPoint,
const VECTOR2I aMoveVector = { 0, 0 },
const EDA_ANGLE aRotation = ANGLE_0,
const double &  aScalingFactor = 1.0,
const VECTOR2I aTransformCentre = { 0, 0 },
const bool &  aMirrorInvert = false 
)
private

Definition at line 3037 of file cadstar_sch_archive_loader.cpp.

3043{
3044 VECTOR2I retVal = aPoint;
3045
3046 if( aScalingFactor != 1.0 )
3047 {
3048 //scale point
3049 retVal -= aTransformCentre;
3050 retVal.x = KiROUND( retVal.x * aScalingFactor );
3051 retVal.y = KiROUND( retVal.y * aScalingFactor );
3052 retVal += aTransformCentre;
3053 }
3054
3055 if( aMirrorInvert )
3056 MIRROR( retVal.x, aTransformCentre.x );
3057
3058 if( !aRotation.IsZero() )
3059 RotatePoint( retVal, aTransformCentre, aRotation );
3060
3061 if( aMoveVector != VECTOR2I{ 0, 0 } )
3062 retVal += aMoveVector;
3063
3064 return retVal;
3065}
bool IsZero() const
Definition: eda_angle.h:169
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:40
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Definition: trigo.cpp:183

References EDA_ANGLE::IsZero(), KiROUND(), MIRROR(), RotatePoint(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by loadDocumentationSymbols(), and loadShapeVertices().

◆ CheckNoChildNodes()

◆ CheckNoNextNodes()

void CADSTAR_ARCHIVE_PARSER::CheckNoNextNodes ( XNODE aNode)
staticinherited

◆ checkPoint()

void CADSTAR_ARCHIVE_PARSER::checkPoint ( )
protectedinherited

Updates m_progressReporter or throws if user cancelled.

Definition at line 2774 of file cadstar_archive_parser.cpp.

2775{
2776 if( m_progressReporter )
2777 {
2779
2781 THROW_IO_ERROR( _( "File import cancelled by user." ) );
2782 }
2783}
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void AdvanceProgress()=0
Increment the progress bar length (inside the current virtual zone).
#define _(s)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, PROGRESS_REPORTER::AdvanceProgress(), PROGRESS_REPORTER::KeepRefreshing(), CADSTAR_ARCHIVE_PARSER::m_progressReporter, and THROW_IO_ERROR.

Referenced by CADSTAR_PCB_ARCHIVE_LOADER::calculateZonePriorities(), Load(), CADSTAR_PCB_ARCHIVE_LOADER::loadCoppers(), loadPartsLibrary(), CADSTAR_SCH_ARCHIVE_PARSER::Parse(), and CADSTAR_PCB_ARCHIVE_PARSER::Parse().

◆ findOrphanSheets()

std::vector< CADSTAR_SCH_ARCHIVE_LOADER::LAYER_ID > CADSTAR_SCH_ARCHIVE_LOADER::findOrphanSheets ( )
private

Definition at line 2283 of file cadstar_sch_archive_loader.cpp.

2284{
2285 std::vector<LAYER_ID> childSheets, orphanSheets;
2286
2287 //Find all sheets that are child of another
2288 for( std::pair<BLOCK_ID, BLOCK> blockPair : Schematic.Blocks )
2289 {
2290 BLOCK& block = blockPair.second;
2291 LAYER_ID& assocSheetID = block.AssocLayerID;
2292
2293 if( block.Type == BLOCK::TYPE::CHILD )
2294 childSheets.push_back( assocSheetID );
2295 }
2296
2297 //Add sheets that do not have a parent
2298 for( LAYER_ID sheetID : Sheets.SheetOrder )
2299 {
2300 if( std::find( childSheets.begin(), childSheets.end(), sheetID ) == childSheets.end() )
2301 orphanSheets.push_back( sheetID );
2302 }
2303
2304 return orphanSheets;
2305}
wxString LAYER_ID
ID of a Sheet (if schematic) or board Layer (if PCB)
std::vector< LAYER_ID > SheetOrder
A vector to also store the order in which sheets are to be displayed.

References CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::AssocLayerID, CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::Blocks, CADSTAR_SCH_ARCHIVE_PARSER::Schematic, CADSTAR_SCH_ARCHIVE_PARSER::SHEETS::SheetOrder, CADSTAR_SCH_ARCHIVE_PARSER::Sheets, and CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::Type.

Referenced by loadSheets().

◆ FixTextPositionNoAlignment()

void CADSTAR_ARCHIVE_PARSER::FixTextPositionNoAlignment ( EDA_TEXT aKiCadTextItem)
staticinherited

Corrects the position of a text element that had NO_ALIGNMENT in CADSTAR.

Assumes that the provided text element has been initialised with a position and orientation.

Parameters
aKiCadTextItema Kicad item to correct

Definition at line 2747 of file cadstar_archive_parser.cpp.

2748{
2749 if( !aKiCadTextItem->GetText().IsEmpty() )
2750 {
2751 VECTOR2I positionOffset( 0, aKiCadTextItem->GetInterline() );
2752 RotatePoint( positionOffset, aKiCadTextItem->GetTextAngle() );
2753
2754 EDA_ITEM* textEdaItem = dynamic_cast<EDA_ITEM*>( aKiCadTextItem );
2755
2756 if( textEdaItem &&
2757 ( textEdaItem->Type() == LIB_TEXT_T || textEdaItem->Type() == LIB_FIELD_T ) )
2758 {
2759 // Y coordinate increases upwards in the symbol editor
2760 positionOffset.y = -positionOffset.y;
2761 }
2762
2763 //Count num of additional lines
2764 wxString text = aKiCadTextItem->GetText();
2765 int numExtraLines = text.Replace( "\n", "\n" );
2766 numExtraLines -= text.at( text.size() - 1 ) == '\n'; // Ignore new line character at end
2767 positionOffset.x *= numExtraLines;
2768 positionOffset.y *= numExtraLines;
2769
2770 aKiCadTextItem->Offset( positionOffset );
2771 }
2772}
int GetInterline() const
Return the distance between two lines of text.
Definition: eda_text.cpp:499
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:391

References EDA_TEXT::GetInterline(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), LIB_FIELD_T, LIB_TEXT_T, EDA_TEXT::Offset(), RotatePoint(), text, EDA_ITEM::Type(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by CADSTAR_PCB_ARCHIVE_LOADER::addAttribute(), applyTextSettings(), and CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText().

◆ fixUpLibraryPins()

void CADSTAR_SCH_ARCHIVE_LOADER::fixUpLibraryPins ( LIB_SYMBOL aSymbolToFix,
int  aGateNumber 
)
private

Definition at line 2885 of file cadstar_sch_archive_loader.cpp.

2886{
2887 auto compLambda = []( const VECTOR2I& aA, const VECTOR2I& aB )
2888 {
2889 return LexicographicalCompare( aA, aB ) < 0;
2890 };
2891
2892 // Store a list of vertical or horizontal segments in the symbol
2893 // Note: Need the custom comparison function to ensure the map is sorted correctly
2894 std::map<VECTOR2I, SHAPE_LINE_CHAIN, decltype( compLambda )> uniqueSegments( compLambda );
2895
2896 LIB_ITEMS_CONTAINER::ITERATOR shapeIt = aSymbolToFix->GetDrawItems().begin( LIB_SHAPE_T );
2897
2898 for( ; shapeIt != aSymbolToFix->GetDrawItems().end( LIB_SHAPE_T ); ++shapeIt )
2899 {
2900 LIB_SHAPE& shape = static_cast<LIB_SHAPE&>( *shapeIt );
2901
2902 if( aGateNumber > 0 && shape.GetUnit() != aGateNumber )
2903 continue;
2904
2905 if( shape.GetShape() != SHAPE_T::POLY )
2906 continue;
2907
2908 SHAPE_LINE_CHAIN poly = shape.GetPolyShape().Outline( 0 );
2909
2910 if( poly.GetPointCount() == 2 )
2911 {
2912 VECTOR2I pt0 = poly.CPoint( 0 );
2913 VECTOR2I pt1 = poly.CPoint( 1 );
2914
2915 if( pt0 != pt1 && uniqueSegments.count( pt0 ) == 0 && uniqueSegments.count( pt1 ) == 0 )
2916 {
2917 // we are only interested in vertical or horizontal segments
2918 if( pt0.x == pt1.x || pt0.y == pt1.y )
2919 {
2920 uniqueSegments.insert( { pt0, poly } );
2921 uniqueSegments.insert( { pt1, poly } );
2922 }
2923 }
2924 }
2925 }
2926
2927 LIB_PINS pins;
2928 aSymbolToFix->GetPins( pins, aGateNumber );
2929
2930 for( auto& pin : pins )
2931 {
2932 auto setPinOrientation =
2933 [&]( const EDA_ANGLE& aAngle )
2934 {
2935 EDA_ANGLE angle( aAngle );
2936 angle.Normalize180();
2937
2938 if( angle >= -ANGLE_45 && angle <= ANGLE_45 )
2939 pin->SetOrientation( 'R' ); // 0 degrees
2940 else if( angle >= ANGLE_45 && angle <= ANGLE_135 )
2941 pin->SetOrientation( 'U' ); // 90 degrees
2942 else if( angle >= ANGLE_135 || angle <= -ANGLE_135 )
2943 pin->SetOrientation( 'L' ); // 180 degrees
2944 else
2945 pin->SetOrientation( 'D' ); // -90 degrees
2946 };
2947
2948 if( uniqueSegments.count( pin->GetPosition() ) )
2949 {
2950 SHAPE_LINE_CHAIN& poly = uniqueSegments.at( pin->GetPosition() );
2951
2952 VECTOR2I otherPt = poly.CPoint( 0 );
2953
2954 if( otherPt == pin->GetPosition() )
2955 otherPt = poly.CPoint( 1 );
2956
2957 VECTOR2I vec( otherPt - pin->GetPosition() );
2958
2959 pin->SetLength( vec.EuclideanNorm() );
2960 setPinOrientation( EDA_ANGLE( vec ) );
2961 }
2962 }
2963}
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:247
SHAPE_T GetShape() const
Definition: eda_shape.h:113
int GetUnit() const
Definition: lib_item.h:273
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:508
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0) const
Return a list of pin object pointers from the draw item list.
Definition: lib_symbol.cpp:831
ITERATOR_BASE< LIB_ITEM, MULTIVECTOR< LIB_ITEM, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::iterator > ITERATOR
The const iterator.
Definition: multivector.h:164
ITERATOR end(int aType=UNDEFINED_TYPE)
Definition: multivector.h:194
ITERATOR begin(int aType=UNDEFINED_TYPE)
Definition: multivector.h:188
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
virtual size_t GetPointCount() const override
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
SHAPE_LINE_CHAIN & Outline(int aIndex)
static constexpr EDA_ANGLE & ANGLE_45
Definition: eda_angle.h:430
static constexpr EDA_ANGLE & ANGLE_135
Definition: eda_angle.h:432
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:54
@ LIB_SHAPE_T
Definition: typeinfo.h:199
const int LexicographicalCompare(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
Definition: vector2d.h:541
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590

References PNS::angle(), ANGLE_135, ANGLE_45, MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::begin(), SHAPE_LINE_CHAIN::CPoint(), MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::end(), VECTOR2< T >::EuclideanNorm(), LIB_SYMBOL::GetDrawItems(), LIB_SYMBOL::GetPins(), SHAPE_LINE_CHAIN::GetPointCount(), EDA_SHAPE::GetPolyShape(), EDA_SHAPE::GetShape(), LIB_ITEM::GetUnit(), LexicographicalCompare(), LIB_SHAPE_T, SHAPE_POLY_SET::Outline(), pin, POLY, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by loadSymDefIntoLibrary().

◆ generateLibName()

static wxString CADSTAR_ARCHIVE_PARSER::generateLibName ( const wxString &  aRefName,
const wxString &  aAlternateName 
)
inlinestaticinherited

Definition at line 1436 of file cadstar_archive_parser.h.

1437 {
1438 return aRefName
1439 + ( ( aAlternateName.size() > 0 ) ? ( wxT( " (" ) + aAlternateName + wxT( ")" ) )
1440 : wxString( wxT( "" ) ) );
1441 }

Referenced by loadSymDefIntoLibrary().

◆ getAngle()

EDA_ANGLE CADSTAR_SCH_ARCHIVE_LOADER::getAngle ( const long long &  aCadstarAngle)
inlineprivate

Definition at line 249 of file cadstar_sch_archive_loader.h.

250 {
251 // CADSTAR v6 (which outputted Schematic Format Version 8) and earlier used 1/10 degree
252 // as the unit for angles/orientations. It is assumed that CADSTAR version 7 (i.e. Schematic
253 // Format Version 9 and later) is the version that introduced 1/1000 degree for angles.
254 if( Header.Format.Version > 8 )
255 {
256 return EDA_ANGLE( (double) aCadstarAngle / 1000.0, DEGREES_T );
257 }
258 else
259 {
260 return EDA_ANGLE( (double) aCadstarAngle, TENTHS_OF_A_DEGREE_T );
261 }
262 }
@ TENTHS_OF_A_DEGREE_T
Definition: eda_angle.h:30
@ DEGREES_T
Definition: eda_angle.h:31
long Version
Archive version number (e.g.

References DEGREES_T, CADSTAR_ARCHIVE_PARSER::HEADER::Format, CADSTAR_SCH_ARCHIVE_PARSER::Header, TENTHS_OF_A_DEGREE_T, and CADSTAR_ARCHIVE_PARSER::FORMAT::Version.

Referenced by applyTextSettings(), getLocationOfNetElement(), getSpinStyle(), loadDocumentationSymbols(), loadNets(), loadSchematicSymbol(), loadSchematicSymbolInstances(), and loadSymbolFieldAttribute().

◆ getAttributeName()

wxString CADSTAR_SCH_ARCHIVE_LOADER::getAttributeName ( const ATTRIBUTE_ID aCadstarAttributeID)
private

◆ getCadstarAngle()

long long CADSTAR_SCH_ARCHIVE_LOADER::getCadstarAngle ( const EDA_ANGLE aAngle)
inlineprivate

Definition at line 264 of file cadstar_sch_archive_loader.h.

265 {
266 // CADSTAR v6 (which outputted Schematic Format Version 8) and earlier used 1/10 degree
267 // as the unit for angles/orientations. It is assumed that CADSTAR version 7 (i.e. Schematic
268 // Format Version 9 and later) is the version that introduced 1/1000 degree for angles.
269 if( Header.Format.Version > 8 )
270 {
271 return KiROUND( aAngle.AsDegrees() * 1000.0 );
272 }
273 else
274 {
275 return aAngle.AsTenthsOfADegree();
276 }
277 }
int AsTenthsOfADegree() const
Definition: eda_angle.h:151
double AsDegrees() const
Definition: eda_angle.h:149

References EDA_ANGLE::AsDegrees(), EDA_ANGLE::AsTenthsOfADegree(), CADSTAR_ARCHIVE_PARSER::HEADER::Format, CADSTAR_SCH_ARCHIVE_PARSER::Header, KiROUND(), and CADSTAR_ARCHIVE_PARSER::FORMAT::Version.

Referenced by loadSymbolFieldAttribute().

◆ getComponentOrientation()

int CADSTAR_SCH_ARCHIVE_LOADER::getComponentOrientation ( const EDA_ANGLE aOrientAngle,
EDA_ANGLE aReturnedOrientation 
)
private

Definition at line 1888 of file cadstar_sch_archive_loader.cpp.

1890{
1891 int compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_0;
1892
1893 EDA_ANGLE oDeg = aOrientAngle;
1894 oDeg.Normalize180();
1895
1896 if( oDeg >= -ANGLE_45 && oDeg <= ANGLE_45 )
1897 {
1898 compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_0;
1899 aReturnedOrientation = ANGLE_0;
1900 }
1901 else if( oDeg >= ANGLE_45 && oDeg <= ANGLE_135 )
1902 {
1903 compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_90;
1904 aReturnedOrientation = ANGLE_90;
1905 }
1906 else if( oDeg >= ANGLE_135 || oDeg <= -ANGLE_135 )
1907 {
1908 compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_180;
1909 aReturnedOrientation = ANGLE_180;
1910 }
1911 else
1912 {
1913 compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_270;
1914 aReturnedOrientation = ANGLE_270;
1915 }
1916
1917 return compOrientation;
1918}
EDA_ANGLE Normalize180()
Definition: eda_angle.h:288
static constexpr EDA_ANGLE & ANGLE_180
Definition: eda_angle.h:433
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:431
static constexpr EDA_ANGLE & ANGLE_0
Definition: eda_angle.h:429
static constexpr EDA_ANGLE & ANGLE_270
Definition: eda_angle.h:434
@ SYM_ORIENT_270
@ SYM_ORIENT_180
@ SYM_ORIENT_90
@ SYM_ORIENT_0

References ANGLE_0, ANGLE_135, ANGLE_180, ANGLE_270, ANGLE_45, ANGLE_90, EDA_ANGLE::Normalize180(), SYM_ORIENT_0, SYM_ORIENT_180, SYM_ORIENT_270, and SYM_ORIENT_90.

Referenced by getLocationOfNetElement(), and loadSchematicSymbol().

◆ getFigureExtentsKiCad()

std::pair< VECTOR2I, VECTOR2I > CADSTAR_SCH_ARCHIVE_LOADER::getFigureExtentsKiCad ( const FIGURE aCadstarFigure)
private

Definition at line 2967 of file cadstar_sch_archive_loader.cpp.

2968{
2969 VECTOR2I upperLeft( Assignments.Settings.DesignLimit.x, 0 );
2970 VECTOR2I lowerRight( 0, Assignments.Settings.DesignLimit.y );
2971
2972 for( const VERTEX& v : aCadstarFigure.Shape.Vertices )
2973 {
2974 if( upperLeft.x > v.End.x )
2975 upperLeft.x = v.End.x;
2976
2977 if( upperLeft.y < v.End.y )
2978 upperLeft.y = v.End.y;
2979
2980 if( lowerRight.x < v.End.x )
2981 lowerRight.x = v.End.x;
2982
2983 if( lowerRight.y > v.End.y )
2984 lowerRight.y = v.End.y;
2985 }
2986
2987 for( CUTOUT cutout : aCadstarFigure.Shape.Cutouts )
2988 {
2989 for( const VERTEX& v : aCadstarFigure.Shape.Vertices )
2990 {
2991 if( upperLeft.x > v.End.x )
2992 upperLeft.x = v.End.x;
2993
2994 if( upperLeft.y < v.End.y )
2995 upperLeft.y = v.End.y;
2996
2997 if( lowerRight.x < v.End.x )
2998 lowerRight.x = v.End.x;
2999
3000 if( lowerRight.y > v.End.y )
3001 lowerRight.y = v.End.y;
3002 }
3003 }
3004
3005 VECTOR2I upperLeftKiCad = getKiCadPoint( upperLeft );
3006 VECTOR2I lowerRightKiCad = getKiCadPoint( lowerRight );
3007
3008 VECTOR2I size = lowerRightKiCad - upperLeftKiCad;
3009
3010 return { upperLeftKiCad, VECTOR2I( abs( size.x ), abs( size.y ) ) };
3011}
VECTOR2I getKiCadPoint(const VECTOR2I &aCadstarPoint)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:418
@ CUTOUT
Make a cutout to an existing zone.

References std::abs(), CADSTAR_SCH_ARCHIVE_PARSER::Assignments, CADSTAR_ARCHIVE_PARSER::SHAPE::Cutouts, CADSTAR_ARCHIVE_PARSER::SETTINGS::DesignLimit, CADSTAR_ARCHIVE_PARSER::VERTEX::End, getKiCadPoint(), CADSTAR_SCH_ARCHIVE_PARSER::ASSIGNMENTS_SCM::Settings, CADSTAR_ARCHIVE_PARSER::FIGURE::Shape, CADSTAR_ARCHIVE_PARSER::SHAPE::Vertices, CADSTAR_ARCHIVE_PARSER::LONGPOINT::x, VECTOR2< T >::x, CADSTAR_ARCHIVE_PARSER::LONGPOINT::y, and VECTOR2< T >::y.

Referenced by loadChildSheets().

◆ getKiCadLength()

int CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLength ( long long  aCadstarLength)
inlineprivate

Definition at line 236 of file cadstar_sch_archive_loader.h.

237 {
238 int mod = aCadstarLength % KiCadUnitDivider;
239 int absmod = sign( mod ) * mod;
240 int offset = 0;
241
242 // Round half-way cases away from zero
243 if( absmod >= KiCadUnitDivider / 2 )
244 offset = sign( aCadstarLength );
245
246 return ( aCadstarLength / KiCadUnitDivider ) + offset;
247 }
int KiCadUnitDivider
Use this value to convert units in this CSA file to KiCad units.
int sign(T val)
Definition: util.h:124

References CADSTAR_SCH_ARCHIVE_PARSER::KiCadUnitDivider, and sign().

Referenced by applyTextSettings(), getKiCadLibraryPoint(), getKiCadPoint(), getLineThickness(), getTextHeightFromTextCode(), and Load().

◆ getKiCadLibraryPoint()

VECTOR2I CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLibraryPoint ( const VECTOR2I aCadstarPoint,
const VECTOR2I aCadstarCentre 
)
private

Definition at line 3025 of file cadstar_sch_archive_loader.cpp.

3027{
3028 VECTOR2I retval;
3029
3030 retval.x = getKiCadLength( aCadstarPoint.x - aCadstarCentre.x );
3031 retval.y = getKiCadLength( aCadstarPoint.y - aCadstarCentre.y );
3032
3033 return retval;
3034}

References getKiCadLength(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by applyToLibraryFieldAttribute(), loadLibrarySymbolShapeVertices(), loadSchematicSymbolInstances(), and loadSymDefIntoLibrary().

◆ getKiCadPinType()

ELECTRICAL_PINTYPE CADSTAR_SCH_ARCHIVE_LOADER::getKiCadPinType ( const PART::PIN_TYPE aPinType)
private

Definition at line 2494 of file cadstar_sch_archive_loader.cpp.

2495{
2496 switch( aPinType )
2497 {
2498 case PART::PIN_TYPE::UNCOMMITTED: return ELECTRICAL_PINTYPE::PT_PASSIVE;
2499 case PART::PIN_TYPE::INPUT: return ELECTRICAL_PINTYPE::PT_INPUT;
2500 case PART::PIN_TYPE::OUTPUT_OR: return ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR;
2501 case PART::PIN_TYPE::OUTPUT_NOT_OR: return ELECTRICAL_PINTYPE::PT_OUTPUT;
2502 case PART::PIN_TYPE::OUTPUT_NOT_NORM_OR: return ELECTRICAL_PINTYPE::PT_OUTPUT;
2503 case PART::PIN_TYPE::POWER: return ELECTRICAL_PINTYPE::PT_POWER_IN;
2504 case PART::PIN_TYPE::GROUND: return ELECTRICAL_PINTYPE::PT_POWER_IN;
2505 case PART::PIN_TYPE::TRISTATE_BIDIR: return ELECTRICAL_PINTYPE::PT_BIDI;
2506 case PART::PIN_TYPE::TRISTATE_INPUT: return ELECTRICAL_PINTYPE::PT_INPUT;
2507 case PART::PIN_TYPE::TRISTATE_DRIVER: return ELECTRICAL_PINTYPE::PT_OUTPUT;
2508 }
2509
2511}
@ PT_INPUT
usual pin input: must be connected
@ PT_OUTPUT
usual output
@ PT_BIDI
input or output (like port for a microprocessor)
@ PT_OPENCOLLECTOR
pin type open collector
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin

References PT_BIDI, PT_INPUT, PT_OPENCOLLECTOR, PT_OUTPUT, PT_PASSIVE, PT_POWER_IN, and PT_UNSPECIFIED.

Referenced by loadSymDefIntoLibrary().

◆ getKiCadPoint()

VECTOR2I CADSTAR_SCH_ARCHIVE_LOADER::getKiCadPoint ( const VECTOR2I aCadstarPoint)
private

◆ getKiCadSchText()

SCH_TEXT * CADSTAR_SCH_ARCHIVE_LOADER::getKiCadSchText ( const TEXT aCadstarTextElement)
private

Definition at line 2785 of file cadstar_sch_archive_loader.cpp.

2786{
2787 SCH_TEXT* kiTxt = new SCH_TEXT();
2788
2789 kiTxt->SetParent( m_schematic ); // set to the schematic for now to avoid asserts
2790 kiTxt->SetPosition( getKiCadPoint( aCadstarTextElement.Position ) );
2791 kiTxt->SetText( aCadstarTextElement.Text );
2792
2793 applyTextSettings( kiTxt,
2794 aCadstarTextElement.TextCodeID,
2795 aCadstarTextElement.Alignment,
2796 aCadstarTextElement.Justification,
2797 aCadstarTextElement.OrientAngle,
2798 aCadstarTextElement.Mirror );
2799
2800 return kiTxt;
2801}
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:100
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_text.h:204

References CADSTAR_ARCHIVE_PARSER::TEXT::Alignment, applyTextSettings(), getKiCadPoint(), CADSTAR_ARCHIVE_PARSER::TEXT::Justification, m_schematic, CADSTAR_ARCHIVE_PARSER::TEXT::Mirror, CADSTAR_ARCHIVE_PARSER::TEXT::OrientAngle, CADSTAR_ARCHIVE_PARSER::TEXT::Position, EDA_ITEM::SetParent(), SCH_TEXT::SetPosition(), EDA_TEXT::SetText(), CADSTAR_ARCHIVE_PARSER::TEXT::Text, and CADSTAR_ARCHIVE_PARSER::TEXT::TextCodeID.

Referenced by loadDocumentationSymbols(), and loadTexts().

◆ getKiCadUnitNumberFromGate()

int CADSTAR_SCH_ARCHIVE_LOADER::getKiCadUnitNumberFromGate ( const GATE_ID aCadstarGateID)
private

Definition at line 2513 of file cadstar_sch_archive_loader.cpp.

2514{
2515 if( aCadstarGateID.IsEmpty() )
2516 return 1;
2517
2518 return (int) aCadstarGateID.Upper().GetChar( 0 ) - (int) wxUniChar( 'A' ) + 1;
2519}

Referenced by loadSchematicSymbol(), and loadSymDefIntoLibrary().

◆ getLineStyle()

PLOT_DASH_TYPE CADSTAR_SCH_ARCHIVE_LOADER::getLineStyle ( const LINECODE_ID aCadstarLineCodeID)
private

Definition at line 2406 of file cadstar_sch_archive_loader.cpp.

2407{
2408 wxCHECK( Assignments.Codedefs.LineCodes.find( aCadstarLineCodeID )
2411
2412 // clang-format off
2413 switch( Assignments.Codedefs.LineCodes.at( aCadstarLineCodeID ).Style )
2414 {
2417 case LINESTYLE::DASHDOTDOT: return PLOT_DASH_TYPE::DASHDOT; //TODO: update in future
2420 default: return PLOT_DASH_TYPE::DEFAULT;
2421 }
2422 // clang-format on
2423
2424 return PLOT_DASH_TYPE();
2425}
PLOT_DASH_TYPE
Dashed line types.
Definition: stroke_params.h:48
std::map< LINECODE_ID, LINECODE > LineCodes

References CADSTAR_SCH_ARCHIVE_PARSER::Assignments, CADSTAR_SCH_ARCHIVE_PARSER::ASSIGNMENTS_SCM::Codedefs, CADSTAR_ARCHIVE_PARSER::DASH, DASH, CADSTAR_ARCHIVE_PARSER::DASHDOT, DASHDOT, CADSTAR_ARCHIVE_PARSER::DASHDOTDOT, DEFAULT, CADSTAR_ARCHIVE_PARSER::DOT, DOT, CADSTAR_ARCHIVE_PARSER::CODEDEFS::LineCodes, CADSTAR_ARCHIVE_PARSER::SOLID, and SOLID.

Referenced by loadShapeVertices(), and loadSymDefIntoLibrary().

◆ getLineThickness()

int CADSTAR_SCH_ARCHIVE_LOADER::getLineThickness ( const LINECODE_ID aCadstarLineCodeID)
private

Definition at line 2396 of file cadstar_sch_archive_loader.cpp.

2397{
2398 wxCHECK( Assignments.Codedefs.LineCodes.find( aCadstarLineCodeID )
2401
2402 return getKiCadLength( Assignments.Codedefs.LineCodes.at( aCadstarLineCodeID ).Width );
2403}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
#define DEFAULT_WIRE_WIDTH_MILS
The default bus width in mils. (can be changed in preference menu)
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94

References CADSTAR_SCH_ARCHIVE_PARSER::Assignments, CADSTAR_SCH_ARCHIVE_PARSER::ASSIGNMENTS_SCM::Codedefs, DEFAULT_WIRE_WIDTH_MILS, getKiCadLength(), CADSTAR_ARCHIVE_PARSER::CODEDEFS::LineCodes, EDA_IU_SCALE::MilsToIU(), and schIUScale.

Referenced by loadBusses(), loadNets(), loadShapeVertices(), and loadSymDefIntoLibrary().

◆ getLocationOfNetElement()

CADSTAR_SCH_ARCHIVE_LOADER::POINT CADSTAR_SCH_ARCHIVE_LOADER::getLocationOfNetElement ( const NET_SCH aNet,
const NETELEMENT_ID aNetElementID 
)
private

Definition at line 1922 of file cadstar_sch_archive_loader.cpp.

1924{
1925 // clang-format off
1926 auto logUnknownNetElementError =
1927 [&]()
1928 {
1929 m_reporter->Report( wxString::Format( _( "Net %s references unknown net element %s. "
1930 "The net was not properly loaded and may "
1931 "require manual fixing." ),
1932 getNetName( aNet ),
1933 aNetElementID ),
1935
1936 return POINT();
1937 };
1938 // clang-format on
1939
1940 if( aNetElementID.Contains( "J" ) ) // Junction
1941 {
1942 if( aNet.Junctions.find( aNetElementID ) == aNet.Junctions.end() )
1943 return logUnknownNetElementError();
1944
1945 return aNet.Junctions.at( aNetElementID ).Location;
1946 }
1947 else if( aNetElementID.Contains( "P" ) ) // Terminal/Pin of a symbol
1948 {
1949 if( aNet.Terminals.find( aNetElementID ) == aNet.Terminals.end() )
1950 return logUnknownNetElementError();
1951
1952 SYMBOL_ID symid = aNet.Terminals.at( aNetElementID ).SymbolID;
1953 TERMINAL_ID termid = aNet.Terminals.at( aNetElementID ).TerminalID;
1954
1955 if( Schematic.Symbols.find( symid ) == Schematic.Symbols.end() )
1956 return logUnknownNetElementError();
1957
1958 SYMBOL sym = Schematic.Symbols.at( symid );
1959 SYMDEF_ID symdefid = sym.SymdefID;
1960 VECTOR2I symbolOrigin = sym.Origin;
1961
1962 if( Library.SymbolDefinitions.find( symdefid ) == Library.SymbolDefinitions.end() )
1963 return logUnknownNetElementError();
1964
1965 VECTOR2I libpinPosition =
1966 Library.SymbolDefinitions.at( symdefid ).Terminals.at( termid ).Position;
1967 VECTOR2I libOrigin = Library.SymbolDefinitions.at( symdefid ).Origin;
1968
1969 VECTOR2I pinOffset = libpinPosition - libOrigin;
1970 pinOffset.x = ( pinOffset.x * sym.ScaleRatioNumerator ) / sym.ScaleRatioDenominator;
1971 pinOffset.y = ( pinOffset.y * sym.ScaleRatioNumerator ) / sym.ScaleRatioDenominator;
1972
1973 VECTOR2I pinPosition = symbolOrigin + pinOffset;
1974 EDA_ANGLE compAngle = getAngle( sym.OrientAngle );
1975
1976 if( sym.Mirror )
1977 pinPosition.x = ( 2 * symbolOrigin.x ) - pinPosition.x;
1978
1979 EDA_ANGLE adjustedOrientation;
1980 getComponentOrientation( compAngle, adjustedOrientation );
1981
1982 RotatePoint( pinPosition, symbolOrigin, -adjustedOrientation );
1983
1984 POINT retval;
1985 retval.x = pinPosition.x;
1986 retval.y = pinPosition.y;
1987
1988 return retval;
1989 }
1990 else if( aNetElementID.Contains( "BT" ) ) // Bus Terminal
1991 {
1992 if( aNet.BusTerminals.find( aNetElementID ) == aNet.BusTerminals.end() )
1993 return logUnknownNetElementError();
1994
1995 return aNet.BusTerminals.at( aNetElementID ).SecondPoint;
1996 }
1997 else if( aNetElementID.Contains( "BLKT" ) ) // Block Terminal (sheet hierarchy connection)
1998 {
1999 if( aNet.BlockTerminals.find( aNetElementID ) == aNet.BlockTerminals.end() )
2000 return logUnknownNetElementError();
2001
2002 BLOCK_ID blockid = aNet.BlockTerminals.at( aNetElementID ).BlockID;
2003 TERMINAL_ID termid = aNet.BlockTerminals.at( aNetElementID ).TerminalID;
2004
2005 if( Schematic.Blocks.find( blockid ) == Schematic.Blocks.end() )
2006 return logUnknownNetElementError();
2007
2008 return Schematic.Blocks.at( blockid ).Terminals.at( termid ).Position;
2009 }
2010 else if( aNetElementID.Contains( "D" ) ) // Dangler
2011 {
2012 if( aNet.Danglers.find( aNetElementID ) == aNet.Danglers.end() )
2013 return logUnknownNetElementError();
2014
2015 return aNet.Danglers.at( aNetElementID ).Position;
2016 }
2017 else
2018 {
2019 return logUnknownNetElementError();
2020 }
2021
2022 return POINT();
2023}
long TERMINAL_ID
Terminal is the pin identifier in the schematic.
wxString getNetName(const NET_SCH &aNet)
int getComponentOrientation(const EDA_ANGLE &aOrientAngle, EDA_ANGLE &aReturnedOrientation)
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
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
@ RPT_SEVERITY_ERROR
std::map< SYMDEF_ID, SYMDEF_SCM > SymbolDefinitions

References _, CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::Blocks, CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::BlockTerminals, CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::BusTerminals, CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::Danglers, Format(), getAngle(), getComponentOrientation(), getNetName(), CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::Junctions, CADSTAR_SCH_ARCHIVE_PARSER::Library, m_reporter, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::Mirror, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::OrientAngle, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::Origin, REPORTER::Report(), RotatePoint(), RPT_SEVERITY_ERROR, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::ScaleRatioDenominator, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::ScaleRatioNumerator, CADSTAR_SCH_ARCHIVE_PARSER::Schematic, CADSTAR_SCH_ARCHIVE_PARSER::LIBRARY_SCM::SymbolDefinitions, CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::Symbols, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::SymdefID, CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::Terminals, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by loadNets().

◆ getNetName()

wxString CADSTAR_SCH_ARCHIVE_LOADER::getNetName ( const NET_SCH aNet)
private

Definition at line 2026 of file cadstar_sch_archive_loader.cpp.

2027{
2028 wxString netname = aNet.Name;
2029
2030 if( netname.IsEmpty() )
2031 netname = wxString::Format( "$%ld", aNet.SignalNum );
2032
2033 return netname;
2034}

References Format(), CADSTAR_ARCHIVE_PARSER::NET::Name, and CADSTAR_ARCHIVE_PARSER::NET::SignalNum.

Referenced by getLocationOfNetElement().

◆ GetNumberOfChildNodes()

long CADSTAR_ARCHIVE_PARSER::GetNumberOfChildNodes ( XNODE aNode)
staticinherited

Definition at line 2705 of file cadstar_archive_parser.cpp.

2706{
2707 XNODE* childNodes = aNode->GetChildren();
2708 long retval = 0;
2709
2710 for( ; childNodes; childNodes = childNodes->GetNext() )
2711 retval++;
2712
2713 return retval;
2714}
Hold an XML or S-expression element.
Definition: xnode.h:44

References XNODE::GetChildren(), and XNODE::GetNext().

Referenced by CADSTAR_ARCHIVE_PARSER::GetNumberOfStepsForReporting().

◆ GetNumberOfStepsForReporting()

long CADSTAR_ARCHIVE_PARSER::GetNumberOfStepsForReporting ( XNODE aRootNode,
std::vector< wxString >  aSubNodeChildrenToCount 
)
staticinherited

Definition at line 2717 of file cadstar_archive_parser.cpp.

2718{
2719 XNODE* level1Node = aRootNode->GetChildren();
2720 long retval = 0;
2721
2722 for( ; level1Node; level1Node = level1Node->GetNext() )
2723 {
2724 for( wxString childNodeName : aSubNodeChildrenToCount )
2725 {
2726 if( level1Node->GetName() == childNodeName )
2727 retval += GetNumberOfChildNodes( level1Node );
2728 }
2729
2730 retval++;
2731 }
2732
2733 return retval;
2734}
static long GetNumberOfChildNodes(XNODE *aNode)

References XNODE::GetChildren(), XNODE::GetNext(), and CADSTAR_ARCHIVE_PARSER::GetNumberOfChildNodes().

Referenced by CADSTAR_SCH_ARCHIVE_PARSER::Parse(), and CADSTAR_PCB_ARCHIVE_PARSER::Parse().

◆ getPart()

CADSTAR_SCH_ARCHIVE_LOADER::PART CADSTAR_SCH_ARCHIVE_LOADER::getPart ( const PART_ID aCadstarPartID)
private

Definition at line 2458 of file cadstar_sch_archive_loader.cpp.

2459{
2460 wxCHECK( Parts.PartDefinitions.find( aCadstarPartID ) != Parts.PartDefinitions.end(), PART() );
2461
2462 return Parts.PartDefinitions.at( aCadstarPartID );
2463}
std::map< PART_ID, PART > PartDefinitions

References CADSTAR_ARCHIVE_PARSER::PARTS::PartDefinitions, and CADSTAR_SCH_ARCHIVE_PARSER::Parts.

Referenced by loadSchematicSymbolInstances().

◆ getPartDefinitionPin()

CADSTAR_SCH_ARCHIVE_LOADER::PART::DEFINITION::PIN CADSTAR_SCH_ARCHIVE_LOADER::getPartDefinitionPin ( const PART aCadstarPart,
const GATE_ID aGateID,
const TERMINAL_ID aTerminalID 
)
private

Definition at line 2478 of file cadstar_sch_archive_loader.cpp.

2480{
2481 for( std::pair<PART_DEFINITION_PIN_ID, PART::DEFINITION::PIN> pinPair :
2482 aCadstarPart.Definition.Pins )
2483 {
2484 PART::DEFINITION::PIN partPin = pinPair.second;
2485
2486 if( partPin.TerminalGate == aGateID && partPin.TerminalPin == aTerminalID )
2487 return partPin;
2488 }
2489
2490 return PART::DEFINITION::PIN();
2491}

References CADSTAR_ARCHIVE_PARSER::PART::Definition, and CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::Pins.

Referenced by loadSymDefIntoLibrary().

◆ getPolarRadius()

double CADSTAR_SCH_ARCHIVE_LOADER::getPolarRadius ( const VECTOR2I aPoint)
private
Parameters
aPoint
Returns
Radius of polar representation of the point

Definition at line 3068 of file cadstar_sch_archive_loader.cpp.

3069{
3070 return sqrt( ( (double) aPoint.x * (double) aPoint.x )
3071 + ( (double) aPoint.y * (double) aPoint.y ) );
3072}

References VECTOR2< T >::x, and VECTOR2< T >::y.

◆ getRouteCode()

CADSTAR_SCH_ARCHIVE_LOADER::ROUTECODE CADSTAR_SCH_ARCHIVE_LOADER::getRouteCode ( const ROUTECODE_ID aCadstarRouteCodeID)
private

Definition at line 2467 of file cadstar_sch_archive_loader.cpp.

2468{
2469 wxCHECK( Assignments.Codedefs.RouteCodes.find( aCadstarRouteCodeID )
2471 ROUTECODE() );
2472
2473 return Assignments.Codedefs.RouteCodes.at( aCadstarRouteCodeID );
2474}
std::map< ROUTECODE_ID, ROUTECODE > RouteCodes

References CADSTAR_SCH_ARCHIVE_PARSER::Assignments, CADSTAR_SCH_ARCHIVE_PARSER::ASSIGNMENTS_SCM::Codedefs, and CADSTAR_ARCHIVE_PARSER::CODEDEFS::RouteCodes.

◆ getScaledLibPart()

LIB_SYMBOL * CADSTAR_SCH_ARCHIVE_LOADER::getScaledLibPart ( const LIB_SYMBOL aSymbol,
long long  aScalingFactorNumerator,
long long  aScalingFactorDenominator 
)
private

Definition at line 2804 of file cadstar_sch_archive_loader.cpp.

2807{
2808 LIB_SYMBOL* retval = new LIB_SYMBOL( *aSymbol );
2809
2810 if( aScalingFactorNumerator == aScalingFactorDenominator )
2811 return retval; // 1:1 scale, nothing to do
2812
2813 auto scaleLen =
2814 [&]( int aLength ) -> int
2815 {
2816 return( aLength * aScalingFactorNumerator ) / aScalingFactorDenominator;
2817 };
2818
2819 auto scalePt =
2820 [&]( VECTOR2I aCoord ) -> VECTOR2I
2821 {
2822 return VECTOR2I( scaleLen( aCoord.x ), scaleLen( aCoord.y ) );
2823 };
2824
2825 auto scaleSize =
2826 [&]( VECTOR2I aSize ) -> VECTOR2I
2827 {
2828 return VECTOR2I( scaleLen( aSize.x ), scaleLen( aSize.y ) );
2829 };
2830
2831 LIB_ITEMS_CONTAINER& items = retval->GetDrawItems();
2832
2833 for( LIB_ITEM& item : items )
2834 {
2835 switch( item.Type() )
2836 {
2838 {
2839 LIB_SHAPE& shape = static_cast<LIB_SHAPE&>( item );
2840
2841 if( shape.GetShape() == SHAPE_T::ARC )
2842 {
2843 shape.SetPosition( scalePt( shape.GetPosition() ) );
2844 shape.SetStart( scalePt( shape.GetStart() ) );
2845 shape.SetEnd( scalePt( shape.GetEnd() ) );
2846 }
2847 else if( shape.GetShape() == SHAPE_T::POLY )
2848 {
2849 SHAPE_LINE_CHAIN& poly = shape.GetPolyShape().Outline( 0 );
2850
2851 for( size_t ii = 0; ii < poly.GetPointCount(); ++ii )
2852 poly.SetPoint( ii, scalePt( poly.CPoint( ii ) ) );
2853 }
2854 break;
2855 }
2856
2857 case KICAD_T::LIB_PIN_T:
2858 {
2859 LIB_PIN& pin = static_cast<LIB_PIN&>( item );
2860
2861 pin.SetPosition( scalePt( pin.GetPosition() ) );
2862 pin.SetLength( scaleLen( pin.GetLength() ) );
2863 break;
2864 }
2865
2867 {
2868 LIB_TEXT& txt = static_cast<LIB_TEXT&>( item );
2869
2870 txt.SetPosition( scalePt( txt.GetPosition() ) );
2871 txt.SetTextSize( scaleSize( txt.GetTextSize() ) );
2872 break;
2873 }
2874
2875 default:
2876 break;
2877 }
2878
2879 }
2880
2881 return retval;
2882}
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:145
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:124
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:120
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:149
void SetTextSize(const VECTOR2I &aNewSize)
Definition: eda_text.cpp:349
VECTOR2I GetTextSize() const
Definition: eda_text.h:196
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
void SetPosition(const VECTOR2I &aPosition) override
Definition: lib_item.h:234
void SetPosition(const VECTOR2I &aPosition) override
Definition: lib_shape.h:86
VECTOR2I GetPosition() const override
Definition: lib_shape.h:85
Define a library symbol object.
Definition: lib_symbol.h:99
Define a symbol library graphical text item.
Definition: lib_text.h:40
VECTOR2I GetPosition() const override
Definition: lib_text.h:93
void SetPoint(int aIndex, const VECTOR2I &aPos)
Move a point to a specific location.
@ LIB_PIN_T
Definition: typeinfo.h:202

References ARC, SHAPE_LINE_CHAIN::CPoint(), LIB_SYMBOL::GetDrawItems(), EDA_SHAPE::GetEnd(), SHAPE_LINE_CHAIN::GetPointCount(), EDA_SHAPE::GetPolyShape(), LIB_SHAPE::GetPosition(), LIB_TEXT::GetPosition(), EDA_SHAPE::GetShape(), EDA_SHAPE::GetStart(), EDA_TEXT::GetTextSize(), LIB_PIN_T, LIB_SHAPE_T, LIB_TEXT_T, SHAPE_POLY_SET::Outline(), pin, POLY, EDA_SHAPE::SetEnd(), SHAPE_LINE_CHAIN::SetPoint(), LIB_ITEM::SetPosition(), LIB_SHAPE::SetPosition(), EDA_SHAPE::SetStart(), and EDA_TEXT::SetTextSize().

Referenced by loadSchematicSymbolInstances().

◆ getSheetNumber()

int CADSTAR_SCH_ARCHIVE_LOADER::getSheetNumber ( LAYER_ID  aCadstarSheetID)
private

Definition at line 2308 of file cadstar_sch_archive_loader.cpp.

2309{
2310 int i = 1;
2311
2312 for( LAYER_ID sheetID : Sheets.SheetOrder )
2313 {
2314 if( sheetID == aCadstarSheetID )
2315 return i;
2316
2317 ++i;
2318 }
2319
2320 return -1;
2321}

References CADSTAR_SCH_ARCHIVE_PARSER::SHEETS::SheetOrder, and CADSTAR_SCH_ARCHIVE_PARSER::Sheets.

Referenced by loadSheetAndChildSheets(), and loadSheets().

◆ getSpinStyle() [1/2]

TEXT_SPIN_STYLE CADSTAR_SCH_ARCHIVE_LOADER::getSpinStyle ( const EDA_ANGLE aOrientation)
private

Definition at line 2538 of file cadstar_sch_archive_loader.cpp.

2539{
2541
2542 EDA_ANGLE oDeg = aOrientation;
2543 oDeg.Normalize180();
2544
2545 if( oDeg >= -ANGLE_45 && oDeg <= ANGLE_45 )
2546 spinStyle = TEXT_SPIN_STYLE::RIGHT; // 0deg
2547 else if( oDeg >= ANGLE_45 && oDeg <= ANGLE_135 )
2548 spinStyle = TEXT_SPIN_STYLE::UP; // 90deg
2549 else if( oDeg >= ANGLE_135 || oDeg <= -ANGLE_135 )
2550 spinStyle = TEXT_SPIN_STYLE::LEFT; // 180deg
2551 else
2552 spinStyle = TEXT_SPIN_STYLE::BOTTOM; // 270deg
2553
2554 return spinStyle;
2555}

References ANGLE_135, ANGLE_45, TEXT_SPIN_STYLE::BOTTOM, TEXT_SPIN_STYLE::LEFT, EDA_ANGLE::Normalize180(), TEXT_SPIN_STYLE::RIGHT, and TEXT_SPIN_STYLE::UP.

◆ getSpinStyle() [2/2]

TEXT_SPIN_STYLE CADSTAR_SCH_ARCHIVE_LOADER::getSpinStyle ( const long long &  aCadstarOrientation,
bool  aMirror 
)
private

Definition at line 2522 of file cadstar_sch_archive_loader.cpp.

2524{
2525 EDA_ANGLE orientation = getAngle( aCadstarOrientation );
2526 TEXT_SPIN_STYLE spinStyle = getSpinStyle( orientation );
2527
2528 if( aMirror )
2529 {
2530 spinStyle = spinStyle.RotateCCW();
2531 spinStyle = spinStyle.RotateCCW();
2532 }
2533
2534 return spinStyle;
2535}
TEXT_SPIN_STYLE RotateCCW()
Definition: sch_text.cpp:67

References getAngle(), getSpinStyle(), and TEXT_SPIN_STYLE::RotateCCW().

Referenced by applyTextSettings(), getSpinStyle(), loadHierarchicalSheetPins(), loadNets(), and loadSchematicSymbolInstances().

◆ getSymDefFromName()

CADSTAR_SCH_ARCHIVE_LOADER::SYMDEF_ID CADSTAR_SCH_ARCHIVE_LOADER::getSymDefFromName ( const wxString &  aSymdefName,
const wxString &  aSymDefAlternate 
)
private

Definition at line 2364 of file cadstar_sch_archive_loader.cpp.

2366{
2367 // Do a case-insensitive comparison
2368 for( std::pair<SYMDEF_ID, SYMDEF_SCM> symPair : Library.SymbolDefinitions )
2369 {
2370 SYMDEF_ID id = symPair.first;
2371 SYMDEF_SCM symdef = symPair.second;
2372
2373 if( symdef.ReferenceName.Lower() == aSymdefName.Lower()
2374 && symdef.Alternate.Lower() == aSymDefAlternate.Lower() )
2375 {
2376 return id;
2377 }
2378 }
2379
2380 return SYMDEF_ID();
2381}

References CADSTAR_ARCHIVE_PARSER::SYMDEF::Alternate, CADSTAR_SCH_ARCHIVE_PARSER::Library, CADSTAR_ARCHIVE_PARSER::SYMDEF::ReferenceName, and CADSTAR_SCH_ARCHIVE_PARSER::LIBRARY_SCM::SymbolDefinitions.

Referenced by loadPartsLibrary().

◆ getTextCode()

CADSTAR_SCH_ARCHIVE_LOADER::TEXTCODE CADSTAR_SCH_ARCHIVE_LOADER::getTextCode ( const TEXTCODE_ID aCadstarTextCodeID)
private

Definition at line 2429 of file cadstar_sch_archive_loader.cpp.

2430{
2431 wxCHECK( Assignments.Codedefs.TextCodes.find( aCadstarTextCodeID )
2433 TEXTCODE() );
2434
2435 return Assignments.Codedefs.TextCodes.at( aCadstarTextCodeID );
2436}
std::map< TEXTCODE_ID, TEXTCODE > TextCodes

References CADSTAR_SCH_ARCHIVE_PARSER::Assignments, CADSTAR_SCH_ARCHIVE_PARSER::ASSIGNMENTS_SCM::Codedefs, and CADSTAR_ARCHIVE_PARSER::CODEDEFS::TextCodes.

Referenced by applyTextSettings(), and getTextHeightFromTextCode().

◆ getTextHeightFromTextCode()

int CADSTAR_SCH_ARCHIVE_LOADER::getTextHeightFromTextCode ( const TEXTCODE_ID aCadstarTextCodeID)
private

Definition at line 2439 of file cadstar_sch_archive_loader.cpp.

2440{
2441 TEXTCODE txtCode = getTextCode( aCadstarTextCodeID );
2442
2443 return KiROUND( (double) getKiCadLength( txtCode.Height ) * TXT_HEIGHT_RATIO );
2444}

References getKiCadLength(), getTextCode(), CADSTAR_ARCHIVE_PARSER::TEXTCODE::Height, KiROUND(), and CADSTAR_ARCHIVE_PARSER::TXT_HEIGHT_RATIO.

Referenced by loadSymDefIntoLibrary().

◆ GetXmlAttributeIDLong()

long CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDLong ( XNODE aNode,
unsigned int  aID,
bool  aIsRequired = true 
)
staticinherited
Parameters
aNode
aID
aIsRequiredPrevents exception throwing if false.
Returns
returns the value (long) of attribute "attrX" in aNode where 'X' is aID
Exceptions
IO_ERRORif attribute does not exist

Definition at line 2577 of file cadstar_archive_parser.cpp.

2579{
2580 long retVal;
2581 bool success = GetXmlAttributeIDString( aNode, aID, aIsRequired ).ToLong( &retVal );
2582
2583 if( !success )
2584 {
2585 if( aIsRequired )
2586 THROW_PARSING_IO_ERROR( std::to_string( aID ), aNode->GetName() );
2587 else
2588 return UNDEFINED_VALUE;
2589 }
2590
2591 return retVal;
2592}
#define THROW_PARSING_IO_ERROR(param, location)
static const long UNDEFINED_VALUE
static wxString GetXmlAttributeIDString(XNODE *aNode, unsigned int aID, bool aIsRequired=true)

References CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDString(), THROW_PARSING_IO_ERROR, and CADSTAR_ARCHIVE_PARSER::UNDEFINED_VALUE.

Referenced by CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::ROUTE_VERTEX::Parse(), CADSTAR_ARCHIVE_PARSER::FORMAT::Parse(), CADSTAR_ARCHIVE_PARSER::HATCH::Parse(), CADSTAR_ARCHIVE_PARSER::FONT::Parse(), CADSTAR_ARCHIVE_PARSER::TEXTCODE::Parse(), CADSTAR_ARCHIVE_PARSER::ROUTEREASSIGN::Parse(), CADSTAR_ARCHIVE_PARSER::ROUTECODE::Parse(), CADSTAR_ARCHIVE_PARSER::POINT::Parse(), CADSTAR_ARCHIVE_PARSER::LONGPOINT::Parse(), CADSTAR_ARCHIVE_PARSER::GRID::Parse(), CADSTAR_ARCHIVE_PARSER::ATTRNAME::COLUMNORDER::Parse(), CADSTAR_ARCHIVE_PARSER::ATTRNAME::COLUMNWIDTH::Parse(), CADSTAR_ARCHIVE_PARSER::TEXT_LOCATION::Parse(), CADSTAR_ARCHIVE_PARSER::REUSEBLOCK::Parse(), CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::GATE::Parse(), CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::PIN::Parse(), CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::Parse(), CADSTAR_ARCHIVE_PARSER::PART::PART_PIN::Parse(), CADSTAR_ARCHIVE_PARSER::PART::Parse(), CADSTAR_ARCHIVE_PARSER::DOCUMENTATION_SYMBOL::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::TERMINAL_SHAPE::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::TERMINAL::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::PIN_NUM_LABEL_LOC::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::TERMATTR::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::SYMPINNAME_LABEL::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::PIN_NUM::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::SYM_TERM::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::BLOCK_TERM::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::LAYER::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::COPREASSIGN::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::COPPERCODE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::SPACINGCODE::REASSIGN::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::SPACINGCODE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::CADSTAR_PAD_SHAPE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::PADCODE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::VIACODE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::LAYERPAIR::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::SPCCLASSSPACE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::TECHNOLOGY_SECTION::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::COMPONENT_PAD::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::ARROW::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::TEXTFORMAT::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::EXTENSION_LINE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::LINE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::SYMDEF_PCB::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::AREA::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::PIN_ATTRIBUTE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::PADEXCEPTION::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::COMPONENT::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::PIN::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::COPPER_TERMINAL::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::TEMPLATE::POURING::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::COPPER::NETREF::COPPER_TERM::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::DRILL_TABLE::Parse(), CADSTAR_ARCHIVE_PARSER::TEXT::Parse(), CADSTAR_ARCHIVE_PARSER::SETTINGS::ParseSubNode(), CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::ParseSubNode(), CADSTAR_ARCHIVE_PARSER::SYMDEF::ParseSubNode(), and CADSTAR_ARCHIVE_PARSER::NET::ParseSubNode().

◆ GetXmlAttributeIDString()

wxString CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDString ( XNODE aNode,
unsigned int  aID,
bool  aIsRequired = true 
)
staticinherited
Parameters
aNode
aID
aIsRequiredPrevents exception throwing if false.
Returns
returns the value (wxString) of attribute "attrX" in aNode where 'X' is aID
Exceptions
IO_ERRORif attribute does not exist

Definition at line 2558 of file cadstar_archive_parser.cpp.

2560{
2561 wxString attrName, retVal;
2562 attrName = "attr";
2563 attrName << aID;
2564
2565 if( !aNode->GetAttribute( attrName, &retVal ) )
2566 {
2567 if( aIsRequired )
2568 THROW_MISSING_PARAMETER_IO_ERROR( std::to_string( aID ), aNode->GetName() );
2569 else
2570 return wxEmptyString;
2571 }
2572
2573 return retVal;
2574}
#define THROW_MISSING_PARAMETER_IO_ERROR(param, location)

References THROW_MISSING_PARAMETER_IO_ERROR.

Referenced by CADSTAR_ARCHIVE_PARSER::PART::GetPinType(), CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDLong(), CADSTAR_ARCHIVE_PARSER::FORMAT::Parse(), CADSTAR_ARCHIVE_PARSER::TIMESTAMP::Parse(), CADSTAR_ARCHIVE_PARSER::HEADER::Parse(), CADSTAR_ARCHIVE_PARSER::VARIANT::Parse(), CADSTAR_ARCHIVE_PARSER::LINECODE::Parse(), CADSTAR_ARCHIVE_PARSER::HATCHCODE::Parse(), CADSTAR_ARCHIVE_PARSER::FONT::Parse(), CADSTAR_ARCHIVE_PARSER::TEXTCODE::Parse(), CADSTAR_ARCHIVE_PARSER::ROUTEREASSIGN::Parse(), CADSTAR_ARCHIVE_PARSER::ROUTECODE::Parse(), CADSTAR_ARCHIVE_PARSER::EVALUE::Parse(), CADSTAR_ARCHIVE_PARSER::SHAPE::Parse(), CADSTAR_ARCHIVE_PARSER::GRID::Parse(), CADSTAR_ARCHIVE_PARSER::ATTRNAME::Parse(), CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_VALUE::Parse(), CADSTAR_ARCHIVE_PARSER::TEXT_LOCATION::Parse(), CADSTAR_ARCHIVE_PARSER::CADSTAR_NETCLASS::Parse(), CADSTAR_ARCHIVE_PARSER::SPCCLASSNAME::Parse(), CADSTAR_ARCHIVE_PARSER::REUSEBLOCK::Parse(), CADSTAR_ARCHIVE_PARSER::REUSEBLOCKREF::Parse(), CADSTAR_ARCHIVE_PARSER::GROUP::Parse(), CADSTAR_ARCHIVE_PARSER::FIGURE::Parse(), CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::GATE::Parse(), CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::PIN::Parse(), CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::SWAP_GROUP::Parse(), CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::Parse(), CADSTAR_ARCHIVE_PARSER::PART::PART_PIN::Parse(), CADSTAR_ARCHIVE_PARSER::PART::Parse(), CADSTAR_ARCHIVE_PARSER::DOCUMENTATION_SYMBOL::Parse(), CADSTAR_ARCHIVE_PARSER::DFLTSETTINGS::Parse(), CADSTAR_ARCHIVE_PARSER::ATTRCOL::Parse(), CADSTAR_ARCHIVE_PARSER::PARTNAMECOL::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::TERMINALCODE::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::TERMINAL::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::PIN_NUM_LABEL_LOC::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::SHEETS::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::COMP::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::PARTREF::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::SYMPINNAME_LABEL::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::SYMBOLVARIANT::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::SIGNALREFERENCELINK::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::SIGLOC::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::BUS::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::JUNCTION_SCH::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::SYM_TERM::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::BUS_TERM::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::BLOCK_TERM::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::DANGLER::Parse(), CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::CONNECTION_SCH::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::MATERIAL::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::LAYER::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::LAYERDEFS::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::COPREASSIGN::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::COPPERCODE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::SPACINGCODE::REASSIGN::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::SPACINGCODE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::PADREASSIGN::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::PADCODE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::VIAREASSIGN::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::VIACODE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::LAYERPAIR::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::SPCCLASSSPACE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::RULESET::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::COMPONENT_COPPER::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::COMPONENT_AREA::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::COMPONENT_PAD::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::ARROW::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::TEXTFORMAT::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::EXTENSION_LINE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::LINE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::CADSTAR_BOARD::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::AREA::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::PADEXCEPTION::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::COMPONENT::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::TRUNK::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::PIN::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::JUNCTION_PCB::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::VIA::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::COPPER_TERMINAL::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::ROUTE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::CONNECTION_PCB::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::TEMPLATE::POURING::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::TEMPLATE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::COPPER::NETREF::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::COPPER::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::DRILL_TABLE::Parse(), CADSTAR_PCB_ARCHIVE_PARSER::LAYOUT::Parse(), CADSTAR_ARCHIVE_PARSER::TEXT::Parse(), CADSTAR_ARCHIVE_PARSER::ParseAlignment(), CADSTAR_ARCHIVE_PARSER::ParseAngunits(), CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::ParseIdentifiers(), CADSTAR_ARCHIVE_PARSER::SYMDEF::ParseIdentifiers(), CADSTAR_ARCHIVE_PARSER::NET::JUNCTION::ParseIdentifiers(), CADSTAR_ARCHIVE_PARSER::NET::CONNECTION::ParseIdentifiers(), CADSTAR_ARCHIVE_PARSER::NET::ParseIdentifiers(), CADSTAR_ARCHIVE_PARSER::ParseJustification(), CADSTAR_ARCHIVE_PARSER::ParseReadability(), CADSTAR_ARCHIVE_PARSER::NET::JUNCTION::ParseSubNode(), CADSTAR_ARCHIVE_PARSER::NET::CONNECTION::ParseSubNode(), CADSTAR_ARCHIVE_PARSER::NET::ParseSubNode(), CADSTAR_ARCHIVE_PARSER::ParseSwapRule(), CADSTAR_PCB_ARCHIVE_PARSER::ParseTestlandSide(), and CADSTAR_ARCHIVE_PARSER::ParseUnits().

◆ HandleTextOverbar()

wxString CADSTAR_ARCHIVE_PARSER::HandleTextOverbar ( wxString  aCadstarString)
staticinherited

Convert a string with CADSTAR overbar characters to equivalent in KiCad.

Parameters
aCadstarStringInput string
Returns
KiCad string with overbar characters

Definition at line 2737 of file cadstar_archive_parser.cpp.

2738{
2739 wxString escapedText = aCadstarString;
2740
2741 escapedText.Replace( wxT( "'" ), wxT( "~" ) );
2742
2743 return ConvertToNewOverbarNotation( escapedText );
2744}
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.

References ConvertToNewOverbarNotation().

Referenced by applyTextSettings(), loadBusses(), loadNets(), loadSchematicSymbol(), and loadSymDefIntoLibrary().

◆ InsertAttributeAtEnd()

void CADSTAR_ARCHIVE_PARSER::InsertAttributeAtEnd ( XNODE aNode,
wxString  aValue 
)
staticinherited

Definition at line 2406 of file cadstar_archive_parser.cpp.

2407{
2408 wxString result;
2409 int numAttributes = 0;
2410
2411 if( aNode->GetAttribute( wxT( "numAttributes" ), &result ) )
2412 {
2413 numAttributes = wxAtoi( result );
2414 aNode->DeleteAttribute( wxT( "numAttributes" ) );
2415 ++numAttributes;
2416 }
2417
2418 aNode->AddAttribute( wxT( "numAttributes" ), wxString::Format( wxT( "%i" ), numAttributes ) );
2419
2420 wxString paramName = wxT( "attr" );
2421 paramName << numAttributes;
2422
2423 aNode->AddAttribute( paramName, aValue );
2424}

References Format().

Referenced by CADSTAR_ARCHIVE_PARSER::LoadArchiveFile().

◆ isAttributeVisible()

bool CADSTAR_SCH_ARCHIVE_LOADER::isAttributeVisible ( const ATTRIBUTE_ID aCadstarAttributeID)
private

Definition at line 2384 of file cadstar_sch_archive_loader.cpp.

2385{
2386 // Use CADSTAR visibility settings to determine if an attribute is visible
2387 if( AttrColors.AttributeColors.find( aCadstarAttributeID ) != AttrColors.AttributeColors.end() )
2388 {
2389 return AttrColors.AttributeColors.at( aCadstarAttributeID ).IsVisible;
2390 }
2391
2392 return false; // If there is no visibility setting, assume not displayed
2393}
std::map< ATTRIBUTE_ID, ATTRCOL > AttributeColors

References CADSTAR_SCH_ARCHIVE_PARSER::AttrColors, and CADSTAR_ARCHIVE_PARSER::ATTRCOLORS::AttributeColors.

Referenced by loadSchematicSymbolInstances(), and loadSymDefIntoLibrary().

◆ IsValidAttribute()

◆ Load()

void CADSTAR_SCH_ARCHIVE_LOADER::Load ( SCHEMATIC aSchematic,
SCH_SHEET aRootSheet,
SCH_PLUGIN::SCH_PLUGIN_RELEASER aSchPlugin,
const wxFileName &  aLibraryFileName 
)

Loads a CADSTAR PCB Archive file into the KiCad BOARD object given.

Parameters
aSchematicSchematic to add the design onto
aRootSheetRoot sheet to add the design onto

Definition at line 56 of file cadstar_sch_archive_loader.cpp.

59{
61 m_progressReporter->SetNumPhases( 3 ); // (0) Read file, (1) Parse file, (2) Load file
62
63 Parse();
64
65 LONGPOINT designLimit = Assignments.Settings.DesignLimit;
66
67 //Note: can't use getKiCadPoint() due VECTOR2I being int - need long long to make the check
68 long long designSizeXkicad = (long long) designLimit.x / KiCadUnitDivider;
69 long long designSizeYkicad = (long long) designLimit.y / KiCadUnitDivider;
70
71 // Max size limited by the positive dimension of VECTOR2I (which is an int)
72 constexpr long long maxDesignSizekicad = std::numeric_limits<int>::max();
73
74 if( designSizeXkicad > maxDesignSizekicad || designSizeYkicad > maxDesignSizekicad )
75 {
77 _( "The design is too large and cannot be imported into KiCad. \n"
78 "Please reduce the maximum design size in CADSTAR by navigating to: \n"
79 "Design Tab -> Properties -> Design Options -> Maximum Design Size. \n"
80 "Current Design size: %.2f, %.2f millimeters. \n"
81 "Maximum permitted design size: %.2f, %.2f millimeters.\n" ),
82 (double) designSizeXkicad / SCH_IU_PER_MM,
83 (double) designSizeYkicad / SCH_IU_PER_MM,
84 (double) maxDesignSizekicad / SCH_IU_PER_MM,
85 (double) maxDesignSizekicad / SCH_IU_PER_MM ) );
86 }
87
88 // Assume the center at 0,0 since we are going to be translating the design afterwards anyway
89 m_designCenter = { 0, 0 };
90
91 m_schematic = aSchematic;
92 m_rootSheet = aRootSheet;
93 m_plugin = aSchPlugin;
94 m_libraryFileName = aLibraryFileName;
95
97 {
99 long numSteps = 11; // one step for each of below functions + one at the end of import
100
101 // Step 4 is by far the longest - add granularity in reporting
102 numSteps += Parts.PartDefinitions.size();
103
105 }
106
107 loadTextVariables(); // Load text variables right at the start to ensure bounding box
108 // calculations work correctly for text items
109 checkPoint(); // Step 1
110 loadSheets();
111 checkPoint(); // Step 2
113 checkPoint(); // Step 3
115 checkPoint(); // Step 4, Subdivided into extra steps
117 checkPoint(); // Step 5
118 loadBusses();
119 checkPoint(); // Step 6
120 loadNets();
121 checkPoint(); // Step 7
122 loadFigures();
123 checkPoint(); // Step 8
124 loadTexts();
125 checkPoint(); // Step 9
127 checkPoint(); // Step 10
128
129 if( Schematic.VariantHierarchy.Variants.size() > 0 )
130 {
131 m_reporter->Report( wxString::Format( _( "The CADSTAR design contains variants which has "
132 "no KiCad equivalent. Only the master variant "
133 "('%s') was loaded." ),
134 Schematic.VariantHierarchy.Variants.at( "V0" ).Name ),
136 }
137
138 if( Schematic.Groups.size() > 0 )
139 {
140 m_reporter->Report( _( "The CADSTAR design contains grouped items which has no KiCad "
141 "equivalent. Any grouped items have been ungrouped." ),
143 }
144
145 if( Schematic.ReuseBlocks.size() > 0 )
146 {
147 m_reporter->Report( _( "The CADSTAR design contains re-use blocks which has no KiCad "
148 "equivalent. The re-use block information has been discarded during "
149 "the import." ),
151 }
152
153
154 // For all sheets, center all elements and re calculate the page size:
155 for( std::pair<LAYER_ID, SCH_SHEET*> sheetPair : m_sheetMap )
156 {
157 SCH_SHEET* sheet = sheetPair.second;
158
159 // Calculate the new sheet size.
160 BOX2I sheetBoundingBox;
161
162 for( SCH_ITEM* item : sheet->GetScreen()->Items() )
163 {
164 BOX2I bbox;
165
166 // Only use the visible fields of the symbols to calculate their bounding box
167 // (hidden fields could be very long and artificially enlarge the sheet bounding box)
168 if( item->Type() == SCH_SYMBOL_T )
169 {
170 SCH_SYMBOL* comp = static_cast<SCH_SYMBOL*>( item );
171 bbox = comp->GetBodyAndPinsBoundingBox();
172
173 for( const SCH_FIELD& field : comp->GetFields() )
174 {
175 if( field.IsVisible() )
176 bbox.Merge( field.GetBoundingBox() );
177 }
178 }
179 else if( item->Type() == SCH_TEXT_T )
180 {
181 SCH_TEXT* txtItem = static_cast<SCH_TEXT*>( item );
182 wxString txt = txtItem->GetText();
183
184 if( txt.Contains( "${" ) )
185 continue; // We can't calculate bounding box of text items with variables
186 else
187 bbox = txtItem->GetBoundingBox();
188 }
189 else
190 {
191 bbox = item->GetBoundingBox();
192 }
193
194 sheetBoundingBox.Merge( bbox );
195 }
196
197 // Find the screen grid of the original CADSTAR design
199
204
206
207 auto roundToNearestGrid =
208 [&]( int aNumber ) -> int
209 {
210 int error = aNumber % grid;
211 int absError = sign( error ) * error;
212
213 if( absError > ( grid / 2 ) )
214 return aNumber + ( sign( error ) * grid ) - error;
215 else
216 return aNumber - error;
217 };
218
219 // When exporting to pdf, CADSTAR applies a margin of 3% of the longest dimension (height
220 // or width) to all 4 sides (top, bottom, left right). For the import, we are also rounding
221 // the margin to the nearest grid, ensuring all items remain on the grid.
222 VECTOR2I targetSheetSize = sheetBoundingBox.GetSize();
223 int longestSide = std::max( targetSheetSize.x, targetSheetSize.y );
224 int margin = ( (double) longestSide * 0.03 );
225 margin = roundToNearestGrid( margin );
226 targetSheetSize += margin * 2;
227
228 // Update page size always
229 PAGE_INFO pageInfo = sheet->GetScreen()->GetPageSettings();
230 pageInfo.SetWidthMils( schIUScale.IUToMils( targetSheetSize.x ) );
231 pageInfo.SetHeightMils( schIUScale.IUToMils( targetSheetSize.y ) );
232
233 // Set the new sheet size.
234 sheet->GetScreen()->SetPageSettings( pageInfo );
235
237 VECTOR2I sheetcentre( pageSizeIU.x / 2, pageSizeIU.y / 2 );
238 VECTOR2I itemsCentre = sheetBoundingBox.Centre();
239
240 // round the translation to nearest point on the grid
241 VECTOR2I translation = sheetcentre - itemsCentre;
242 translation.x = roundToNearestGrid( translation.x );
243 translation.y = roundToNearestGrid( translation.y );
244
245 // Translate the items.
246 std::vector<SCH_ITEM*> allItems;
247
248 std::copy( sheet->GetScreen()->Items().begin(), sheet->GetScreen()->Items().end(),
249 std::back_inserter( allItems ) );
250
251 for( SCH_ITEM* item : allItems )
252 {
253 item->Move( translation );
254 item->ClearFlags();
255 sheet->GetScreen()->Update( item );
256 }
257 }
258
259 checkPoint();
260
261 m_reporter->Report( _( "CADSTAR fonts are different to the ones in KiCad. This will likely "
262 "result in alignment issues. Please review the imported text elements "
263 "carefully and correct manually if required." ),
265
266 m_reporter->Report( _( "The CADSTAR design has been imported successfully.\n"
267 "Please review the import errors and warnings (if any)." ) );
268}
constexpr double SCH_IU_PER_MM
Definition: base_units.h:73
Vec Centre() const
Definition: box2.h:70
const Vec & GetSize() const
Definition: box2.h:179
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:588
@ FRACTIONALGRID
Param1 = Units, Param2 = Divisor.
void checkPoint()
Updates m_progressReporter or throws if user cancelled.
std::map< LAYER_ID, SCH_SHEET * > m_sheetMap
Map between Cadstar and KiCad Sheets.
iterator end()
Returns a read/write iterator that points to one past the last element in the EE_RTREE.
Definition: sch_rtree.h:285
iterator begin()
Returns a read/write iterator that points to the first element in the EE_RTREE N.B.
Definition: sch_rtree.h:276
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:245
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:259
const VECTOR2I GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition: page_info.h:162
virtual void SetNumPhases(int aNumPhases)=0
Set the number of phases.
virtual void BeginPhase(int aPhase)=0
Initialize the aPhase virtual zone of the dialog progress bar.
virtual void SetMaxProgress(int aMaxProgress)=0
Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:131
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:132
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:109
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
Definition: sch_screen.cpp:300
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:106
Schematic symbol object.
Definition: sch_symbol.h:81
BOX2I GetBodyAndPinsBoundingBox() const
Return a bounding box for the symbol body and pins but not the fields.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:901
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_text.cpp:321
@ RPT_SEVERITY_WARNING
GRID ScreenGrid
From CADSTAR Help: "There is one Screen Grid, which is visible as dots on the screen.
long Param1
Either Units or X step, depending on Type (see GRID_TYPE for more details)
long Param2
Either Divisor or Y step, depending on Type (see GRID_TYPE for more details)
std::map< REUSEBLOCK_ID, REUSEBLOCK > ReuseBlocks
constexpr int IUToMils(int iu) const
Definition: base_units.h:100
const double IU_PER_MILS
Definition: base_units.h:78
@ SCH_SYMBOL_T
Definition: typeinfo.h:156

References _, CADSTAR_SCH_ARCHIVE_PARSER::Assignments, EE_RTREE::begin(), PROGRESS_REPORTER::BeginPhase(), BOX2< Vec >::Centre(), CADSTAR_ARCHIVE_PARSER::checkPoint(), CADSTAR_ARCHIVE_PARSER::SETTINGS::DesignLimit, EE_RTREE::end(), Format(), CADSTAR_ARCHIVE_PARSER::FRACTIONALGRID, SCH_SYMBOL::GetBodyAndPinsBoundingBox(), SCH_TEXT::GetBoundingBox(), SCH_SYMBOL::GetFields(), getKiCadLength(), SCH_SCREEN::GetPageSettings(), SCH_SHEET::GetScreen(), BOX2< Vec >::GetSize(), PAGE_INFO::GetSizeIU(), EDA_TEXT::GetText(), grid, CADSTAR_SCH_ARCHIVE_PARSER::ASSIGNMENTS_SCM::Grids, CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::Groups, SCH_SCREEN::Items(), EDA_IU_SCALE::IU_PER_MILS, EDA_IU_SCALE::IUToMils(), CADSTAR_SCH_ARCHIVE_PARSER::KiCadUnitDivider, loadBusses(), loadDocumentationSymbols(), loadFigures(), loadHierarchicalSheetPins(), loadNets(), loadPartsLibrary(), loadSchematicSymbolInstances(), loadSheets(), loadTexts(), loadTextVariables(), m_designCenter, m_libraryFileName, m_plugin, CADSTAR_ARCHIVE_PARSER::m_progressReporter, m_reporter, m_rootSheet, m_schematic, m_sheetMap, BOX2< Vec >::Merge(), CADSTAR_ARCHIVE_PARSER::GRID::Param1, CADSTAR_ARCHIVE_PARSER::GRID::Param2, CADSTAR_SCH_ARCHIVE_PARSER::Parse(), CADSTAR_ARCHIVE_PARSER::PARTS::PartDefinitions, CADSTAR_SCH_ARCHIVE_PARSER::Parts, REPORTER::Report(), CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::ReuseBlocks, RPT_SEVERITY_WARNING, SCH_IU_PER_MM, SCH_SYMBOL_T, SCH_TEXT_T, CADSTAR_SCH_ARCHIVE_PARSER::Schematic, schIUScale, CADSTAR_ARCHIVE_PARSER::GRIDS::ScreenGrid, PAGE_INFO::SetHeightMils(), PROGRESS_REPORTER::SetMaxProgress(), PROGRESS_REPORTER::SetNumPhases(), SCH_SCREEN::SetPageSettings(), CADSTAR_SCH_ARCHIVE_PARSER::ASSIGNMENTS_SCM::Settings, PAGE_INFO::SetWidthMils(), sign(), THROW_IO_ERROR, CADSTAR_ARCHIVE_PARSER::GRID::Type, SCH_SCREEN::Update(), CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::VariantHierarchy, CADSTAR_ARCHIVE_PARSER::VARIANT_HIERARCHY::Variants, CADSTAR_ARCHIVE_PARSER::LONGPOINT::x, VECTOR2< T >::x, CADSTAR_ARCHIVE_PARSER::LONGPOINT::y, and VECTOR2< T >::y.

Referenced by CADSTAR_SCH_ARCHIVE_PLUGIN::Load().

◆ LoadArchiveFile()

XNODE * CADSTAR_ARCHIVE_PARSER::LoadArchiveFile ( const wxString &  aFileName,
const wxString &  aFileTypeIdentifier,
PROGRESS_REPORTER aProgressReporter = nullptr 
)
staticinherited

Reads a CADSTAR Archive file (S-parameter format)

Parameters
aFileName
aFileTypeIdentifierIdentifier of the first node in the file to check against. E.g. "CADSTARPCB"
aProgressReporterPointer to a Progress Reporter to report progress to.
Returns
XNODE pointing to the top of the tree for further parsing. Each node has the first element as the node's name and subsequent elements as node attributes ("attr0", "attr1", "attr2", etc.). Caller is responsible for deleting to avoid memory leaks.
Exceptions
IO_ERROR

Definition at line 2427 of file cadstar_archive_parser.cpp.

2429{
2430 KEYWORD emptyKeywords[1] = {};
2431 XNODE* rootNode = nullptr;
2432 XNODE* cNode = nullptr;
2433 XNODE* iNode = nullptr;
2434 int tok;
2435 bool cadstarFileCheckDone = false;
2436 wxString str;
2437 wxCSConv win1252( wxT( "windows-1252" ) );
2438 wxMBConv* conv = &win1252; // Initial testing suggests file encoding to be Windows-1252
2439 // More samples required.
2440
2441 // Open the file and get the file size
2442 FILE* fp = wxFopen( aFileName, wxT( "rt" ) );
2443
2444 if( !fp )
2445 THROW_IO_ERROR( wxString::Format( _( "Cannot open file '%s'" ), aFileName ) );
2446
2447 fseek( fp, 0L, SEEK_END );
2448 long fileSize = ftell( fp );
2449 rewind( fp );
2450
2451 DSNLEXER lexer( emptyKeywords, 0, nullptr, fp, aFileName );
2452
2453 auto currentProgress = [&]() -> double
2454 {
2455 return static_cast<double>( ftell( fp ) ) / fileSize;
2456 };
2457
2458 double previousReportedProgress = -1.0;
2459
2460 while( ( tok = lexer.NextTok() ) != DSN_EOF )
2461 {
2462 if( aProgressReporter && ( currentProgress() - previousReportedProgress ) > 0.01 )
2463 {
2464 if( !aProgressReporter->KeepRefreshing() )
2465 {
2466 delete rootNode;
2467 THROW_IO_ERROR( _( "File import cancelled by user." ) );
2468 }
2469
2470 aProgressReporter->SetCurrentProgress( currentProgress() );
2471 previousReportedProgress = currentProgress();
2472 }
2473
2474 if( tok == DSN_RIGHT )
2475 {
2476 cNode = iNode;
2477 if( cNode )
2478 {
2479 iNode = cNode->GetParent();
2480 }
2481 else
2482 {
2483 //too many closing brackets
2484 delete rootNode;
2485 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2486 }
2487 }
2488 else if( tok == DSN_LEFT )
2489 {
2490 tok = lexer.NextTok();
2491 str = wxString( lexer.CurText(), *conv );
2492 cNode = new XNODE( wxXML_ELEMENT_NODE, str );
2493
2494 if( !rootNode )
2495 rootNode = cNode;
2496
2497 if( iNode )
2498 {
2499 //we will add it as attribute as well as child node
2500 InsertAttributeAtEnd( iNode, str );
2501 iNode->AddChild( cNode );
2502 }
2503 else if( !cadstarFileCheckDone )
2504 {
2505 if( cNode->GetName() != aFileTypeIdentifier )
2506 {
2507 delete rootNode;
2508 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2509 }
2510
2511 cadstarFileCheckDone = true;
2512 }
2513
2514 iNode = cNode;
2515 }
2516 else if( iNode )
2517 {
2518 str = wxString( lexer.CurText(), *conv );
2519 //Insert even if string is empty
2520 InsertAttributeAtEnd( iNode, str );
2521 }
2522 else
2523 {
2524 //not enough closing brackets
2525 delete rootNode;
2526 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2527 }
2528 }
2529
2530 // Not enough closing brackets
2531 if( iNode != nullptr )
2532 {
2533 delete rootNode;
2534 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2535 }
2536
2537 // Throw if no data was parsed
2538 if( rootNode )
2539 {
2540 return rootNode;
2541 }
2542 else
2543 {
2544 delete rootNode;
2545 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2546 }
2547
2548 return nullptr;
2549}
static void InsertAttributeAtEnd(XNODE *aNode, wxString aValue)
Implement a lexical analyzer for the SPECCTRA DSN file format.
Definition: dsnlexer.h:79
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
@ DSN_LEFT
Definition: dsnlexer.h:67
@ DSN_RIGHT
Definition: dsnlexer.h:66
@ DSN_EOF
Definition: dsnlexer.h:69
Hold a keyword string and its unique integer token.
Definition: dsnlexer.h:40

References _, DSNLEXER::CurText(), DSN_EOF, DSN_LEFT, DSN_RIGHT, Format(), XNODE::GetParent(), CADSTAR_ARCHIVE_PARSER::InsertAttributeAtEnd(), PROGRESS_REPORTER::KeepRefreshing(), DSNLEXER::NextTok(), PROGRESS_REPORTER::SetCurrentProgress(), and THROW_IO_ERROR.

Referenced by CADSTAR_SCH_ARCHIVE_PARSER::Parse(), and CADSTAR_PCB_ARCHIVE_PARSER::Parse().

◆ loadBusses()

void CADSTAR_SCH_ARCHIVE_LOADER::loadBusses ( )
private

Definition at line 733 of file cadstar_sch_archive_loader.cpp.

734{
735 for( std::pair<BUS_ID, BUS> busPair : Schematic.Buses )
736 {
737 BUS bus = busPair.second;
738 bool firstPt = true;
739 VERTEX last;
740
741 if( bus.LayerID != wxT( "NO_SHEET" ) )
742 {
743 SCH_SCREEN* screen = m_sheetMap.at( bus.LayerID )->GetScreen();
744 std::shared_ptr<BUS_ALIAS> kiBusAlias = std::make_shared<BUS_ALIAS>();
745
746 kiBusAlias->SetName( bus.Name );
747 kiBusAlias->SetParent( screen );
748 screen->AddBusAlias( kiBusAlias );
749 m_busesMap.insert( { bus.ID, kiBusAlias } );
750
751 SCH_LABEL* label = new SCH_LABEL();
752
753 wxString busname = HandleTextOverbar( bus.Name );
754
755 label->SetText( wxT( "{" ) + busname + wxT( "}" ) );
756 label->SetVisible( true );
757 screen->Append( label );
758
759 SHAPE_LINE_CHAIN busLineChain; // to compute nearest segment to bus label
760
761 for( const VERTEX& cur : bus.Shape.Vertices )
762 {
763 busLineChain.Append( getKiCadPoint( cur.End ) );
764
765 if( firstPt )
766 {
767 last = cur;
768 firstPt = false;
769
770 if( !bus.HasBusLabel )
771 {
772 // Add a bus label on the starting point if the original CADSTAR design
773 // does not have an explicit label
774 label->SetPosition( getKiCadPoint( last.End ) );
775 }
776
777 continue;
778 }
779
780
781 SCH_LINE* kiBus = new SCH_LINE();
782
783 kiBus->SetStartPoint( getKiCadPoint( last.End ) );
784 kiBus->SetEndPoint( getKiCadPoint( cur.End ) );
785 kiBus->SetLayer( LAYER_BUS );
786 kiBus->SetLineWidth( getLineThickness( bus.LineCodeID ) );
787 screen->Append( kiBus );
788
789 last = cur;
790 }
791
792 if( bus.HasBusLabel )
793 {
794 //lets find the closest point in the busline to the label
795 VECTOR2I busLabelLoc = getKiCadPoint( bus.BusLabel.Position );
796 VECTOR2I nearestPt = busLineChain.NearestPoint( busLabelLoc );
797
798 label->SetPosition( nearestPt );
799
800 applyTextSettings( label,
801 bus.BusLabel.TextCodeID,
802 bus.BusLabel.Alignment,
803 bus.BusLabel.Justification );
804
805 // Re-set bus name as it might have been "double-escaped" after applyTextSettings
806 label->SetText( wxT( "{" ) + busname + wxT( "}" ) );
807
808 // Note orientation of the bus label will be determined in loadNets
809 // (the position of the wire will determine how best to place the bus label)
810 }
811 }
812 }
813}
std::map< BUS_ID, std::shared_ptr< BUS_ALIAS > > m_busesMap
Map of Cadstar and KiCad Buses.
int getLineThickness(const LINECODE_ID &aCadstarLineCodeID)
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:219
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:253
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
void SetStartPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:139
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:316
void SetEndPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:144
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:145
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Add a bus alias definition (and transfers ownership of the pointer).
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const VECTOR2I NearestPoint(const VECTOR2I &aP, bool aAllowInternalShapePoints=true) const
Find a point on the line chain that is closest to point aP.
@ LAYER_BUS
Definition: layer_ids.h:345
@ BUS
This item represents a bus vector.

References SCH_SCREEN::AddBusAlias(), CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Alignment, SHAPE_LINE_CHAIN::Append(), SCH_SCREEN::Append(), applyTextSettings(), CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::Buses, CADSTAR_SCH_ARCHIVE_PARSER::BUS::BusLabel, CADSTAR_ARCHIVE_PARSER::VERTEX::End, getKiCadPoint(), getLineThickness(), CADSTAR_ARCHIVE_PARSER::HandleTextOverbar(), CADSTAR_SCH_ARCHIVE_PARSER::BUS::HasBusLabel, CADSTAR_SCH_ARCHIVE_PARSER::BUS::ID, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Justification, LAYER_BUS, CADSTAR_SCH_ARCHIVE_PARSER::BUS::LayerID, CADSTAR_SCH_ARCHIVE_PARSER::BUS::LineCodeID, m_busesMap, m_sheetMap, CADSTAR_SCH_ARCHIVE_PARSER::BUS::Name, SHAPE_LINE_CHAIN::NearestPoint(), CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Position, CADSTAR_SCH_ARCHIVE_PARSER::Schematic, SCH_LINE::SetEndPoint(), SCH_ITEM::SetLayer(), SCH_LINE::SetLineWidth(), SCH_TEXT::SetPosition(), SCH_LINE::SetStartPoint(), EDA_TEXT::SetText(), EDA_TEXT::SetVisible(), CADSTAR_SCH_ARCHIVE_PARSER::BUS::Shape, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::TextCodeID, and CADSTAR_ARCHIVE_PARSER::SHAPE::Vertices.

Referenced by Load().

◆ loadChildSheets()

void CADSTAR_SCH_ARCHIVE_LOADER::loadChildSheets ( LAYER_ID  aCadstarSheetID,
const SCH_SHEET_PATH aSheet 
)
private

Definition at line 2182 of file cadstar_sch_archive_loader.cpp.

2184{
2185 wxCHECK_MSG( m_sheetMap.find( aCadstarSheetID ) != m_sheetMap.end(), ,
2186 "FIXME! Parent sheet should be loaded before attempting to load subsheets" );
2187
2188 for( std::pair<BLOCK_ID, BLOCK> blockPair : Schematic.Blocks )
2189 {
2190 BLOCK& block = blockPair.second;
2191
2192 if( block.LayerID == aCadstarSheetID && block.Type == BLOCK::TYPE::CHILD )
2193 {
2194 if( block.AssocLayerID == wxT( "NO_LINK" ) )
2195 {
2196 if( block.Figures.size() > 0 )
2197 {
2198 m_reporter->Report( wxString::Format( _( "The block ID %s (Block name: '%s') "
2199 "is drawn on sheet '%s' but is not "
2200 "linked to another sheet in the "
2201 "design. KiCad requires all sheet "
2202 "symbols to be associated to a sheet, "
2203 "so the block was not loaded." ),
2204 block.ID, block.Name,
2205 Sheets.SheetNames.at( aCadstarSheetID ) ),
2207 }
2208
2209 continue;
2210 }
2211
2212 // In KiCad you can only draw rectangular shapes whereas in Cadstar arbitrary shapes
2213 // are allowed. We will calculate the extents of the Cadstar shape and draw a rectangle
2214
2215 std::pair<VECTOR2I, VECTOR2I> blockExtents;
2216
2217 if( block.Figures.size() > 0 )
2218 {
2219 blockExtents = getFigureExtentsKiCad( block.Figures.begin()->second );
2220 }
2221 else
2222 {
2223 THROW_IO_ERROR( wxString::Format( _( "The CADSTAR schematic might be corrupt: "
2224 "Block %s references a child sheet but has no "
2225 "Figure defined." ),
2226 block.ID ) );
2227 }
2228
2229 loadSheetAndChildSheets( block.AssocLayerID, blockExtents.first, blockExtents.second,
2230 aSheet );
2231
2232 // Hide all KiCad sheet properties (sheet name/filename is not applicable in CADSTAR)
2233 SCH_SHEET* loadedSheet = m_sheetMap.at( block.AssocLayerID );
2234 SCH_FIELDS fields = loadedSheet->GetFields();
2235
2236 for( SCH_FIELD& field : fields )
2237 {
2238 field.SetVisible( false );
2239 }
2240
2241 if( block.HasBlockLabel )
2242 {
2243 //@todo use below code when KiCad supports multi-line fields
2244 /*
2245 // Add the block label as a separate field
2246 SCH_FIELD blockNameField( getKiCadPoint( block.BlockLabel.Position ), 2,
2247 loadedSheet, wxString( "Block name" ) );
2248 blockNameField.SetText( block.Name );
2249 blockNameField.SetVisible( true );
2250
2251 applyTextSettings( &blockNameField,
2252 block.BlockLabel.TextCodeID,
2253 block.BlockLabel.Alignment,
2254 block.BlockLabel.Justification,
2255 block.BlockLabel.OrientAngle,
2256 block.BlockLabel.Mirror );
2257
2258 fields.push_back( blockNameField );*/
2259
2260 // For now as as a text item (supports multi-line properly)
2261 SCH_TEXT* kiTxt = new SCH_TEXT();
2262
2263 kiTxt->SetParent( m_schematic );
2264 kiTxt->SetPosition( getKiCadPoint( block.BlockLabel.Position ) );
2265 kiTxt->SetText( block.Name );
2266
2267 applyTextSettings( kiTxt,
2268 block.BlockLabel.TextCodeID,
2269 block.BlockLabel.Alignment,
2270 block.BlockLabel.Justification,
2271 block.BlockLabel.OrientAngle,
2272 block.BlockLabel.Mirror );
2273
2274 loadItemOntoKiCadSheet( aCadstarSheetID, kiTxt );
2275 }
2276
2277 loadedSheet->SetFields( fields );
2278 }
2279 }
2280}
void loadSheetAndChildSheets(LAYER_ID aCadstarSheetID, const VECTOR2I &aPosition, VECTOR2I aSheetSize, const SCH_SHEET_PATH &aParentSheet)
void loadItemOntoKiCadSheet(LAYER_ID aCadstarSheetID, SCH_ITEM *aItem)
std::pair< VECTOR2I, VECTOR2I > getFigureExtentsKiCad(const FIGURE &aCadstarFigure)
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:93
void SetFields(const std::vector< SCH_FIELD > &aFields)
Set multiple schematic fields.
Definition: sch_sheet.cpp:347
std::vector< SCH_FIELD > SCH_FIELDS
A container for several SCH_FIELD items.
Definition: sch_symbol.h:69
std::map< LAYER_ID, SHEET_NAME > SheetNames

References _, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Alignment, applyTextSettings(), CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::AssocLayerID, CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::BlockLabel, CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::Blocks, CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::Figures, Format(), SCH_SHEET::GetFields(), getFigureExtentsKiCad(), getKiCadPoint(), CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::HasBlockLabel, CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::ID, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Justification, CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::LayerID, loadItemOntoKiCadSheet(), loadSheetAndChildSheets(), m_reporter, m_schematic, m_sheetMap, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Mirror, CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::Name, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::OrientAngle, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Position, REPORTER::Report(), RPT_SEVERITY_ERROR, CADSTAR_SCH_ARCHIVE_PARSER::Schematic, SCH_SHEET::SetFields(), EDA_ITEM::SetParent(), SCH_TEXT::SetPosition(), EDA_TEXT::SetText(), CADSTAR_SCH_ARCHIVE_PARSER::SHEETS::SheetNames, CADSTAR_SCH_ARCHIVE_PARSER::Sheets, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::TextCodeID, THROW_IO_ERROR, and CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::Type.

Referenced by loadSheetAndChildSheets(), and loadSheets().

◆ loadDocumentationSymbols()

void CADSTAR_SCH_ARCHIVE_LOADER::loadDocumentationSymbols ( )
private

Definition at line 1185 of file cadstar_sch_archive_loader.cpp.

1186{
1187 for( std::pair<DOCUMENTATION_SYMBOL_ID, DOCUMENTATION_SYMBOL> docSymPair :
1189 {
1190 DOCUMENTATION_SYMBOL docSym = docSymPair.second;
1191
1192 if( Library.SymbolDefinitions.find( docSym.SymdefID ) == Library.SymbolDefinitions.end() )
1193 {
1194 m_reporter->Report( wxString::Format( _( "Documentation Symbol '%s' refers to symbol "
1195 "definition ID '%s' which does not exist in "
1196 "the library. The symbol was not loaded." ),
1197 docSym.ID,
1198 docSym.SymdefID ),
1200 continue;
1201 }
1202
1203 SYMDEF_SCM docSymDef = Library.SymbolDefinitions.at( docSym.SymdefID );
1204 VECTOR2I moveVector = getKiCadPoint( docSym.Origin ) - getKiCadPoint( docSymDef.Origin );
1205 EDA_ANGLE rotationAngle = getAngle( docSym.OrientAngle );
1206 double scalingFactor = (double) docSym.ScaleRatioNumerator
1207 / (double) docSym.ScaleRatioDenominator;
1208 VECTOR2I centreOfTransform = getKiCadPoint( docSymDef.Origin );
1209 bool mirrorInvert = docSym.Mirror;
1210
1211 for( std::pair<FIGURE_ID, FIGURE> figPair : docSymDef.Figures )
1212 {
1213 FIGURE fig = figPair.second;
1214
1215 loadFigure( fig, docSym.LayerID, LAYER_NOTES, moveVector, rotationAngle, scalingFactor,
1216 centreOfTransform, mirrorInvert );
1217 }
1218
1219 for( std::pair<TEXT_ID, TEXT> textPair : docSymDef.Texts )
1220 {
1221 TEXT txt = textPair.second;
1222
1223 txt.Mirror = ( txt.Mirror ) ? !mirrorInvert : mirrorInvert;
1224 txt.OrientAngle = docSym.OrientAngle - txt.OrientAngle;
1225
1226 SCH_TEXT* kiTxt = getKiCadSchText( txt );
1227
1228 VECTOR2I newPosition = applyTransform( kiTxt->GetPosition(), moveVector, rotationAngle,
1229 scalingFactor, centreOfTransform, mirrorInvert );
1230
1231 int newTxtWidth = KiROUND( kiTxt->GetTextWidth() * scalingFactor );
1232 int newTxtHeight = KiROUND( kiTxt->GetTextHeight() * scalingFactor );
1233 int newTxtThickness = KiROUND( kiTxt->GetTextThickness() * scalingFactor );
1234
1235 kiTxt->SetPosition( newPosition );
1236 kiTxt->SetTextWidth( newTxtWidth );
1237 kiTxt->SetTextHeight( newTxtHeight );
1238 kiTxt->SetTextThickness( newTxtThickness );
1239
1240 loadItemOntoKiCadSheet( docSym.LayerID, kiTxt );
1241 }
1242 }
1243}
VECTOR2I applyTransform(const VECTOR2I &aPoint, const VECTOR2I &aMoveVector={ 0, 0 }, const EDA_ANGLE &aRotation=ANGLE_0, const double &aScalingFactor=1.0, const VECTOR2I &aTransformCentre={ 0, 0 }, const bool &aMirrorInvert=false)
SCH_TEXT * getKiCadSchText(const TEXT &aCadstarTextElement)
void loadFigure(const FIGURE &aCadstarFigure, const LAYER_ID &aCadstarSheetIDOverride, SCH_LAYER_ID aKiCadSchLayerID, const VECTOR2I &aMoveVector={ 0, 0 }, const EDA_ANGLE &aRotation=ANGLE_0, const double &aScalingFactor=1.0, const VECTOR2I &aTransformCentre={ 0, 0 }, const bool &aMirrorInvert=false)
int GetTextHeight() const
Definition: eda_text.h:202
int GetTextWidth() const
Definition: eda_text.h:199
int GetTextThickness() const
Definition: eda_text.h:112
VECTOR2I GetPosition() const override
Definition: sch_text.h:203
@ LAYER_NOTES
Definition: layer_ids.h:358
std::map< DOCUMENTATION_SYMBOL_ID, DOCUMENTATION_SYMBOL > DocumentationSymbols

References _, applyTransform(), CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::DocumentationSymbols, CADSTAR_ARCHIVE_PARSER::SYMDEF::Figures, Format(), getAngle(), getKiCadPoint(), getKiCadSchText(), SCH_TEXT::GetPosition(), EDA_TEXT::GetTextHeight(), EDA_TEXT::GetTextThickness(), EDA_TEXT::GetTextWidth(), CADSTAR_ARCHIVE_PARSER::DOCUMENTATION_SYMBOL::ID, KiROUND(), LAYER_NOTES, CADSTAR_ARCHIVE_PARSER::DOCUMENTATION_SYMBOL::LayerID, CADSTAR_SCH_ARCHIVE_PARSER::Library, loadFigure(), loadItemOntoKiCadSheet(), m_reporter, CADSTAR_ARCHIVE_PARSER::TEXT::Mirror, CADSTAR_ARCHIVE_PARSER::DOCUMENTATION_SYMBOL::Mirror, CADSTAR_ARCHIVE_PARSER::TEXT::OrientAngle, CADSTAR_ARCHIVE_PARSER::DOCUMENTATION_SYMBOL::OrientAngle, CADSTAR_ARCHIVE_PARSER::SYMDEF::Origin, CADSTAR_ARCHIVE_PARSER::DOCUMENTATION_SYMBOL::Origin, REPORTER::Report(), RPT_SEVERITY_ERROR, CADSTAR_ARCHIVE_PARSER::DOCUMENTATION_SYMBOL::ScaleRatioDenominator, CADSTAR_ARCHIVE_PARSER::DOCUMENTATION_SYMBOL::ScaleRatioNumerator, CADSTAR_SCH_ARCHIVE_PARSER::Schematic, SCH_TEXT::SetPosition(), EDA_TEXT::SetTextHeight(), EDA_TEXT::SetTextThickness(), EDA_TEXT::SetTextWidth(), CADSTAR_SCH_ARCHIVE_PARSER::LIBRARY_SCM::SymbolDefinitions, CADSTAR_ARCHIVE_PARSER::DOCUMENTATION_SYMBOL::SymdefID, and CADSTAR_ARCHIVE_PARSER::SYMDEF::Texts.

Referenced by Load().

◆ loadFigure()

void CADSTAR_SCH_ARCHIVE_LOADER::loadFigure ( const FIGURE aCadstarFigure,
const LAYER_ID aCadstarSheetIDOverride,
SCH_LAYER_ID  aKiCadSchLayerID,
const VECTOR2I aMoveVector = { 0, 0 },
const EDA_ANGLE aRotation = ANGLE_0,
const double &  aScalingFactor = 1.0,
const VECTOR2I aTransformCentre = { 0, 0 },
const bool &  aMirrorInvert = false 
)
private

Definition at line 2111 of file cadstar_sch_archive_loader.cpp.

2119{
2120 loadShapeVertices( aCadstarFigure.Shape.Vertices, aCadstarFigure.LineCodeID,
2121 aCadstarSheetIDOverride, aKiCadSchLayerID, aMoveVector, aRotation,
2122 aScalingFactor, aTransformCentre, aMirrorInvert );
2123
2124 for( CUTOUT cutout : aCadstarFigure.Shape.Cutouts )
2125 {
2126 loadShapeVertices( cutout.Vertices, aCadstarFigure.LineCodeID, aCadstarSheetIDOverride,
2127 aKiCadSchLayerID, aMoveVector, aRotation, aScalingFactor,
2128 aTransformCentre, aMirrorInvert );
2129 }
2130}
void loadShapeVertices(const std::vector< VERTEX > &aCadstarVertices, LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID, const VECTOR2I &aMoveVector={ 0, 0 }, const EDA_ANGLE &aRotation=ANGLE_0, const double &aScalingFactor=1.0, const VECTOR2I &aTransformCentre={ 0, 0 }, const bool &aMirrorInvert=false)

References CADSTAR_ARCHIVE_PARSER::SHAPE::Cutouts, CADSTAR_ARCHIVE_PARSER::FIGURE::LineCodeID, loadShapeVertices(), CADSTAR_ARCHIVE_PARSER::FIGURE::Shape, CADSTAR_ARCHIVE_PARSER::CUTOUT::Vertices, and CADSTAR_ARCHIVE_PARSER::SHAPE::Vertices.

Referenced by loadDocumentationSymbols(), and loadFigures().

◆ loadFigures()

void CADSTAR_SCH_ARCHIVE_LOADER::loadFigures ( )
private

Definition at line 1162 of file cadstar_sch_archive_loader.cpp.

1163{
1164 for( std::pair<FIGURE_ID, FIGURE> figPair : Schematic.Figures )
1165 {
1166 FIGURE fig = figPair.second;
1167
1168 loadFigure( fig, fig.LayerID, LAYER_NOTES );
1169 }
1170}

References CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::Figures, LAYER_NOTES, CADSTAR_ARCHIVE_PARSER::FIGURE::LayerID, loadFigure(), and CADSTAR_SCH_ARCHIVE_PARSER::Schematic.

Referenced by Load().

◆ loadHierarchicalSheetPins()

void CADSTAR_SCH_ARCHIVE_LOADER::loadHierarchicalSheetPins ( )
private

Definition at line 324 of file cadstar_sch_archive_loader.cpp.

325{
326 for( std::pair<BLOCK_ID, BLOCK> blockPair : Schematic.Blocks )
327 {
328 BLOCK& block = blockPair.second;
329 LAYER_ID sheetID = "";
330
331 if( block.Type == BLOCK::TYPE::PARENT )
332 sheetID = block.LayerID;
333 else if( block.Type == BLOCK::TYPE::CHILD )
334 sheetID = block.AssocLayerID;
335 else
336 continue;
337
338 if( m_sheetMap.find( sheetID ) != m_sheetMap.end() )
339 {
340 SCH_SHEET* sheet = m_sheetMap.at( sheetID );
341
342 for( std::pair<TERMINAL_ID, TERMINAL> termPair : block.Terminals )
343 {
344 TERMINAL term = termPair.second;
345 wxString name = "YOU SHOULDN'T SEE THIS TEXT. THIS IS A BUG.";
346
347 SCH_HIERLABEL* sheetPin = nullptr;
348
349 if( block.Type == BLOCK::TYPE::PARENT )
350 sheetPin = new SCH_HIERLABEL();
351 else if( block.Type == BLOCK::TYPE::CHILD )
352 sheetPin = new SCH_SHEET_PIN( sheet );
353
354 sheetPin->SetText( name );
356 sheetPin->SetTextSpinStyle( getSpinStyle( term.OrientAngle, false ) );
357 sheetPin->SetPosition( getKiCadPoint( term.Position ) );
358
359 if( sheetPin->Type() == SCH_SHEET_PIN_T )
360 sheet->AddPin( (SCH_SHEET_PIN*) sheetPin );
361 else
362 sheet->GetScreen()->Append( sheetPin );
363
364 BLOCK_PIN_ID blockPinID = std::make_pair( block.ID, term.ID );
365 m_sheetPinMap.insert( { blockPinID, sheetPin } );
366 }
367 }
368 }
369}
const char * name
Definition: DXF_plotter.cpp:56
std::map< BLOCK_PIN_ID, SCH_HIERLABEL * > m_sheetPinMap
Map between Cadstar and KiCad Sheets Pins.
std::pair< BLOCK_ID, TERMINAL_ID > BLOCK_PIN_ID
void SetTextSpinStyle(TEXT_SPIN_STYLE aSpinStyle) override
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_label.cpp:1565
void SetShape(LABEL_FLAG_SHAPE aShape) override
Definition: sch_label.h:74
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
Definition: sch_sheet.cpp:369
@ L_UNSPECIFIED
Definition: sch_text.h:101

References SCH_SHEET::AddPin(), SCH_SCREEN::Append(), CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::AssocLayerID, CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::Blocks, getKiCadPoint(), SCH_SHEET::GetScreen(), getSpinStyle(), CADSTAR_SCH_ARCHIVE_PARSER::TERMINAL::ID, CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::ID, L_UNSPECIFIED, CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::LayerID, m_sheetMap, m_sheetPinMap, name, CADSTAR_SCH_ARCHIVE_PARSER::TERMINAL::OrientAngle, CADSTAR_SCH_ARCHIVE_PARSER::TERMINAL::Position, SCH_SHEET_PIN_T, CADSTAR_SCH_ARCHIVE_PARSER::Schematic, SCH_TEXT::SetPosition(), SCH_LABEL_BASE::SetShape(), EDA_TEXT::SetText(), SCH_HIERLABEL::SetTextSpinStyle(), CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::Terminals, CADSTAR_SCH_ARCHIVE_PARSER::BLOCK::Type, and EDA_ITEM::Type().

Referenced by Load().

◆ loadItemOntoKiCadSheet()

void CADSTAR_SCH_ARCHIVE_LOADER::loadItemOntoKiCadSheet ( LAYER_ID  aCadstarSheetID,
SCH_ITEM aItem 
)
private

Definition at line 2324 of file cadstar_sch_archive_loader.cpp.

2325{
2326 wxCHECK_MSG( aItem, /*void*/, "aItem is null" );
2327
2328 if( aCadstarSheetID == "ALL_SHEETS" )
2329 {
2330 SCH_ITEM* duplicateItem;
2331
2332 for( std::pair<LAYER_ID, SHEET_NAME> sheetPair : Sheets.SheetNames )
2333 {
2334 LAYER_ID sheetID = sheetPair.first;
2335 duplicateItem = aItem->Duplicate();
2336 m_sheetMap.at( sheetID )->GetScreen()->Append( aItem->Duplicate() );
2337 }
2338
2339 //Get rid of the extra copy:
2340 delete aItem;
2341 aItem = duplicateItem;
2342 }
2343 else if( aCadstarSheetID == "NO_SHEET" )
2344 {
2345 wxASSERT_MSG( false,
2346 "Trying to add an item to NO_SHEET? This might be a documentation symbol." );
2347 }
2348 else
2349 {
2350 if( m_sheetMap.find( aCadstarSheetID ) != m_sheetMap.end() )
2351 {
2352 m_sheetMap.at( aCadstarSheetID )->GetScreen()->Append( aItem );
2353 }
2354 else
2355 {
2356 delete aItem;
2357 wxASSERT_MSG( false, "Unknown Sheet ID." );
2358 }
2359 }
2360}
SCH_ITEM * Duplicate(bool doClone=false) const
Routine to create a new copy of given item.
Definition: sch_item.cpp:93

References SCH_ITEM::Duplicate(), m_sheetMap, CADSTAR_SCH_ARCHIVE_PARSER::SHEETS::SheetNames, and CADSTAR_SCH_ARCHIVE_PARSER::Sheets.

Referenced by loadChildSheets(), loadDocumentationSymbols(), loadShapeVertices(), and loadTexts().

◆ loadLibrarySymbolShapeVertices()

void CADSTAR_SCH_ARCHIVE_LOADER::loadLibrarySymbolShapeVertices ( const std::vector< VERTEX > &  aCadstarVertices,
VECTOR2I  aSymbolOrigin,
LIB_SYMBOL aSymbol,
int  aGateNumber,
int  aLineThickness 
)
private

Definition at line 1655 of file cadstar_sch_archive_loader.cpp.

1660{
1661 const VERTEX* prev = &aCadstarVertices.at( 0 );
1662 const VERTEX* cur;
1663
1664 wxASSERT_MSG( prev->Type == VERTEX_TYPE::POINT, "First vertex should always be a point." );
1665
1666 for( size_t i = 1; i < aCadstarVertices.size(); i++ )
1667 {
1668 cur = &aCadstarVertices.at( i );
1669
1670 LIB_SHAPE* shape = nullptr;
1671 bool cw = false;
1672 VECTOR2I startPoint = getKiCadLibraryPoint( prev->End, aSymbolOrigin );
1673 VECTOR2I endPoint = getKiCadLibraryPoint( cur->End, aSymbolOrigin );
1674 VECTOR2I centerPoint;
1675
1677 || cur->Type == VERTEX_TYPE::CLOCKWISE_SEMICIRCLE )
1678 {
1679 centerPoint = ( startPoint + endPoint ) / 2;
1680 }
1681 else
1682 {
1683 centerPoint = getKiCadLibraryPoint( cur->Center, aSymbolOrigin );
1684 }
1685
1686
1687 switch( cur->Type )
1688 {
1689 case VERTEX_TYPE::POINT:
1690 shape = new LIB_SHAPE( aSymbol, SHAPE_T::POLY );
1691 shape->AddPoint( startPoint );
1692 shape->AddPoint( endPoint );
1693 break;
1694
1697 cw = true;
1699
1702 shape = new LIB_SHAPE( aSymbol, SHAPE_T::ARC );
1703
1704 shape->SetPosition( centerPoint );
1705
1706 if( cw )
1707 {
1708 shape->SetStart( endPoint );
1709 shape->SetEnd( startPoint );
1710 }
1711 else
1712 {
1713 shape->SetStart( startPoint );
1714 shape->SetEnd( endPoint );
1715 }
1716
1717 break;
1718 }
1719
1720 shape->SetUnit( aGateNumber );
1721 shape->SetStroke( STROKE_PARAMS( aLineThickness, PLOT_DASH_TYPE::SOLID ) );
1722 aSymbol->AddDrawItem( shape );
1723
1724 prev = cur;
1725 }
1726}
void SetUnit(int aUnit)
Definition: lib_item.h:272
void SetStroke(const STROKE_PARAMS &aStroke)
Definition: lib_shape.h:53
void AddPoint(const VECTOR2I &aPosition)
Definition: lib_shape.cpp:518
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:820
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88

References LIB_SYMBOL::AddDrawItem(), LIB_SHAPE::AddPoint(), CADSTAR_ARCHIVE_PARSER::ANTICLOCKWISE_ARC, CADSTAR_ARCHIVE_PARSER::ANTICLOCKWISE_SEMICIRCLE, ARC, CADSTAR_ARCHIVE_PARSER::VERTEX::Center, CADSTAR_ARCHIVE_PARSER::CLOCKWISE_ARC, CADSTAR_ARCHIVE_PARSER::CLOCKWISE_SEMICIRCLE, CADSTAR_ARCHIVE_PARSER::VERTEX::End, getKiCadLibraryPoint(), KI_FALLTHROUGH, CADSTAR_ARCHIVE_PARSER::POINT, POLY, EDA_SHAPE::SetEnd(), LIB_SHAPE::SetPosition(), EDA_SHAPE::SetStart(), LIB_SHAPE::SetStroke(), LIB_ITEM::SetUnit(), SOLID, and CADSTAR_ARCHIVE_PARSER::VERTEX::Type.

Referenced by loadSymDefIntoLibrary().

◆ loadNets()

void CADSTAR_SCH_ARCHIVE_LOADER::loadNets ( )
private

Definition at line 816 of file cadstar_sch_archive_loader.cpp.

817{
818 for( std::pair<NET_ID, NET_SCH> netPair : Schematic.Nets )
819 {
820 NET_SCH net = netPair.second;
821 wxString netName = net.Name;
822 std::map<NETELEMENT_ID, SCH_LABEL*> netlabels;
823
824 if( netName.IsEmpty() )
825 netName = wxString::Format( "$%ld", net.SignalNum );
826
827 netName = HandleTextOverbar( netName );
828
829 for( std::pair<NETELEMENT_ID, NET_SCH::SYM_TERM> terminalPair : net.Terminals )
830 {
831 NET_SCH::SYM_TERM netTerm = terminalPair.second;
832
833 if( m_powerSymMap.find( netTerm.SymbolID ) != m_powerSymMap.end() )
834 {
835 SCH_FIELD* val = m_powerSymMap.at( netTerm.SymbolID )->GetField( VALUE_FIELD );
836 val->SetText( netName );
837 val->SetBold( false );
838 val->SetVisible( false );
839
840 if( netTerm.HasNetLabel )
841 {
842 val->SetVisible( true );
843 val->SetPosition( getKiCadPoint( netTerm.NetLabel.Position ) );
844
846 netTerm.NetLabel.TextCodeID,
847 netTerm.NetLabel.Alignment,
848 netTerm.NetLabel.Justification,
849 netTerm.NetLabel.OrientAngle,
850 netTerm.NetLabel.Mirror );
851 }
852 }
853 else if( m_globalLabelsMap.find( netTerm.SymbolID ) != m_globalLabelsMap.end() )
854 {
855 m_globalLabelsMap.at( netTerm.SymbolID )->SetText( netName );
856
857 LAYER_ID sheet = Schematic.Symbols.at( netTerm.SymbolID ).LayerID;
858
859 if( m_sheetMap.count( sheet ) )
860 {
861 SCH_SCREEN* screen = m_sheetMap.at( sheet )->GetScreen();
862
863 // autoplace intersheet refs again since we've changed the name
864 m_globalLabelsMap.at( netTerm.SymbolID )->AutoplaceFields( screen, false );
865 }
866 }
867 else if( !net.Name.IsEmpty() && Schematic.Symbols.count( netTerm.SymbolID )
868 && netTerm.HasNetLabel )
869 {
870 // This is a named net that connects to a schematic symbol pin - we need to put a label
871 SCH_LABEL* label = new SCH_LABEL();
872 label->SetText( netName );
873
874 POINT pinLocation = getLocationOfNetElement( net, netTerm.ID );
875 label->SetPosition( getKiCadPoint( pinLocation ) );
876 label->SetVisible( true );
877
878 applyTextSettings( label, netTerm.NetLabel.TextCodeID, netTerm.NetLabel.Alignment,
879 netTerm.NetLabel.Justification );
880
881 netlabels.insert( { netTerm.ID, label } );
882
883 LAYER_ID sheet = Schematic.Symbols.at( netTerm.SymbolID ).LayerID;
884 m_sheetMap.at( sheet )->GetScreen()->Append( label );
885 }
886 }
887
888 auto getHierarchicalLabel =
889 [&]( NETELEMENT_ID aNode ) -> SCH_HIERLABEL*
890 {
891 if( aNode.Contains( "BLKT" ) )
892 {
893 NET_SCH::BLOCK_TERM blockTerm = net.BlockTerminals.at( aNode );
894 BLOCK_PIN_ID blockPinID = std::make_pair( blockTerm.BlockID,
895 blockTerm.TerminalID );
896
897 if( m_sheetPinMap.find( blockPinID ) != m_sheetPinMap.end() )
898 return m_sheetPinMap.at( blockPinID );
899 }
900
901 return nullptr;
902 };
903
904 //Add net name to all hierarchical pins (block terminals in CADSTAR)
905 for( std::pair<NETELEMENT_ID, NET_SCH::BLOCK_TERM> blockPair : net.BlockTerminals )
906 {
907 SCH_HIERLABEL* label = getHierarchicalLabel( blockPair.first );
908
909 if( label )
910 label->SetText( netName );
911 }
912
913 // Load all bus entries and add net label if required
914 for( std::pair<NETELEMENT_ID, NET_SCH::BUS_TERM> busPair : net.BusTerminals )
915 {
916 NET_SCH::BUS_TERM busTerm = busPair.second;
917 BUS bus = Schematic.Buses.at( busTerm.BusID );
918
919 if( !alg::contains( m_busesMap.at( bus.ID )->Members(), netName ) )
920 m_busesMap.at( bus.ID )->Members().emplace_back( netName );
921
922 SCH_BUS_WIRE_ENTRY* busEntry =
923 new SCH_BUS_WIRE_ENTRY( getKiCadPoint( busTerm.FirstPoint ), false );
924
925 VECTOR2I size =
926 getKiCadPoint( busTerm.SecondPoint ) - getKiCadPoint( busTerm.FirstPoint );
927 busEntry->SetSize( VECTOR2I( size.x, size.y ) );
928
929 m_sheetMap.at( bus.LayerID )->GetScreen()->Append( busEntry );
930
931 // Always add a label at bus terminals to ensure connectivity.
932 // If the original design does not have a label, just make it very small
933 // to keep connectivity but make the design look visually similar to
934 // the original.
935 SCH_LABEL* label = new SCH_LABEL();
936 label->SetText( netName );
937 label->SetPosition( getKiCadPoint( busTerm.SecondPoint ) );
938 label->SetVisible( true );
939
940 if( busTerm.HasNetLabel )
941 {
942 applyTextSettings( label,
943 busTerm.NetLabel.TextCodeID,
944 busTerm.NetLabel.Alignment,
945 busTerm.NetLabel.Justification );
946 }
947 else
948 {
950 }
951
952 netlabels.insert( { busTerm.ID, label } );
953 m_sheetMap.at( bus.LayerID )->GetScreen()->Append( label );
954 }
955
956 for( std::pair<NETELEMENT_ID, NET_SCH::DANGLER> danglerPair : net.Danglers )
957 {
958 NET_SCH::DANGLER dangler = danglerPair.second;
959
960 SCH_LABEL* label = new SCH_LABEL();
961 label->SetPosition( getKiCadPoint( dangler.Position ) );
962 label->SetVisible( true );
963
964 if( dangler.HasNetLabel )
965 {
966 applyTextSettings( label,
967 dangler.NetLabel.TextCodeID,
968 dangler.NetLabel.Alignment,
969 dangler.NetLabel.Justification );
970 }
971
972 label->SetText( netName ); // set text after applying settings to avoid double-escaping
973 netlabels.insert( { dangler.ID, label } );
974
975 m_sheetMap.at( dangler.LayerID )->GetScreen()->Append( label );
976 }
977
978 for( NET_SCH::CONNECTION_SCH conn : net.Connections )
979 {
980 if( conn.LayerID == wxT( "NO_SHEET" ) )
981 continue; // No point loading virtual connections. KiCad handles that internally
982
983 POINT start = getLocationOfNetElement( net, conn.StartNode );
984 POINT end = getLocationOfNetElement( net, conn.EndNode );
985
986 if( start.x == UNDEFINED_VALUE || end.x == UNDEFINED_VALUE )
987 continue;
988
989 // Connections in CADSTAR are always implied between symbols even if the route
990 // doesn't start and end exactly at the connection points
991 if( conn.Path.size() < 1 || conn.Path.front() != start )
992 conn.Path.insert( conn.Path.begin(), start );
993
994 if( conn.Path.size() < 2 || conn.Path.back() != end )
995 conn.Path.push_back( end );
996
997 bool firstPt = true;
998 bool secondPt = false;
999 VECTOR2I last;
1000 SCH_LINE* wire = nullptr;
1001
1002 SHAPE_LINE_CHAIN wireChain; // Create a temp. line chain representing the connection
1003
1004 for( POINT pt : conn.Path )
1005 {
1006 wireChain.Append( getKiCadPoint( pt ) );
1007 }
1008
1009 // AUTO-FIX SHEET PINS
1010 //--------------------
1011 // KiCad constrains the sheet pin on the edge of the sheet object whereas in
1012 // CADSTAR it can be anywhere. Let's find the intersection of the wires with the sheet
1013 // and place the hierarchical
1014 std::vector<NETELEMENT_ID> nodes;
1015 nodes.push_back( conn.StartNode );
1016 nodes.push_back( conn.EndNode );
1017
1018 for( NETELEMENT_ID node : nodes )
1019 {
1020 SCH_HIERLABEL* sheetPin = getHierarchicalLabel( node );
1021
1022 if( sheetPin )
1023 {
1024 if( sheetPin->Type() == SCH_SHEET_PIN_T
1025 && SCH_SHEET::ClassOf( sheetPin->GetParent() ) )
1026 {
1027 SCH_SHEET* parentSheet = static_cast<SCH_SHEET*>( sheetPin->GetParent() );
1028 VECTOR2I sheetSize = parentSheet->GetSize();
1029 VECTOR2I sheetPosition = parentSheet->GetPosition();
1030
1031 int leftSide = sheetPosition.x;
1032 int rightSide = sheetPosition.x + sheetSize.x;
1033 int topSide = sheetPosition.y;
1034 int botSide = sheetPosition.y + sheetSize.y;
1035
1036 SHAPE_LINE_CHAIN sheetEdge;
1037
1038 sheetEdge.Append( leftSide, topSide );
1039 sheetEdge.Append( rightSide, topSide );
1040 sheetEdge.Append( rightSide, botSide );
1041 sheetEdge.Append( leftSide, botSide );
1042 sheetEdge.Append( leftSide, topSide );
1043
1044 SHAPE_LINE_CHAIN::INTERSECTIONS wireToSheetIntersects;
1045
1046 if( !wireChain.Intersect( sheetEdge, wireToSheetIntersects ) )
1047 {
1048 // The block terminal is outside the block shape in the original
1049 // CADSTAR design. Since KiCad's Sheet Pin will already be constrained
1050 // on the edge, we will simply join to it with a straight line.
1051 if( node == conn.StartNode )
1052 wireChain = wireChain.Reverse();
1053
1054 wireChain.Append( sheetPin->GetPosition() );
1055
1056 if( node == conn.StartNode )
1057 wireChain = wireChain.Reverse();
1058 }
1059 else
1060 {
1061 // The block terminal is either inside or on the shape edge. Lets use
1062 // the first intersection point.
1063 VECTOR2I intsctPt = wireToSheetIntersects.at( 0 ).p;
1064 int intsctIndx = wireChain.FindSegment( intsctPt );
1065 wxASSERT_MSG( intsctIndx != -1, "Can't find intersecting segment" );
1066
1067 if( node == conn.StartNode )
1068 wireChain.Replace( 0, intsctIndx, intsctPt );
1069 else
1070 wireChain.Replace( intsctIndx + 1, /*end index*/ -1, intsctPt );
1071
1072 sheetPin->SetPosition( intsctPt );
1073 }
1074 }
1075 }
1076 }
1077
1078 auto fixNetLabelsAndSheetPins =
1079 [&]( const EDA_ANGLE& aWireAngle, NETELEMENT_ID& aNetEleID )
1080 {
1081 TEXT_SPIN_STYLE spin = getSpinStyle( aWireAngle );
1082
1083 if( netlabels.find( aNetEleID ) != netlabels.end() )
1084 netlabels.at( aNetEleID )->SetTextSpinStyle( spin.MirrorY() );
1085
1086 SCH_HIERLABEL* sheetPin = getHierarchicalLabel( aNetEleID );
1087
1088 if( sheetPin )
1089 sheetPin->SetTextSpinStyle( spin.MirrorX() );
1090 };
1091
1092 // Now we can load the wires and fix the label orientations
1093 for( const VECTOR2I& pt : wireChain.CPoints() )
1094 {
1095 if( firstPt )
1096 {
1097 last = pt;
1098 firstPt = false;
1099 secondPt = true;
1100 continue;
1101 }
1102
1103 if( secondPt )
1104 {
1105 secondPt = false;
1106
1107 EDA_ANGLE wireAngle( last - pt );
1108 fixNetLabelsAndSheetPins( wireAngle, conn.StartNode );
1109 }
1110
1111 wire = new SCH_LINE();
1112
1113 wire->SetStartPoint( last );
1114 wire->SetEndPoint( pt );
1115 wire->SetLayer( LAYER_WIRE );
1116
1117 if( !conn.ConnectionLineCode.IsEmpty() )
1118 wire->SetLineWidth( getLineThickness( conn.ConnectionLineCode ) );
1119
1120 last = pt;
1121
1122 m_sheetMap.at( conn.LayerID )->GetScreen()->Append( wire );
1123 }
1124
1125 //Fix labels on the end wire
1126 if( wire )
1127 {
1128 EDA_ANGLE wireAngle( wire->GetEndPoint() - wire->GetStartPoint() );
1129 fixNetLabelsAndSheetPins( wireAngle, conn.EndNode );
1130 }
1131 }
1132
1133 for( std::pair<NETELEMENT_ID, NET_SCH::JUNCTION_SCH> juncPair : net.Junctions )
1134 {
1135 NET_SCH::JUNCTION_SCH junc = juncPair.second;
1136
1137 SCH_JUNCTION* kiJunc = new SCH_JUNCTION();
1138
1139 kiJunc->SetPosition( getKiCadPoint( junc.Location ) );
1140 m_sheetMap.at( junc.LayerID )->GetScreen()->Append( kiJunc );
1141
1142 if( junc.HasNetLabel )
1143 {
1144 // In CADSTAR the label can be placed anywhere, but in KiCad it has to be placed
1145 // in the same location as the junction for it to be connected to it.
1146 SCH_LABEL* label = new SCH_LABEL();
1147 label->SetText( netName );
1148 label->SetPosition( getKiCadPoint( junc.Location ) );
1149 label->SetVisible( true );
1150
1151 EDA_ANGLE labelAngle = getAngle( junc.NetLabel.OrientAngle );
1152 TEXT_SPIN_STYLE spin = getSpinStyle( labelAngle );
1153 label->SetTextSpinStyle( spin );
1154
1155 m_sheetMap.at( junc.LayerID )->GetScreen()->Append( label );
1156 }
1157 }
1158 }
1159}
std::map< SYMBOL_ID, SCH_GLOBALLABEL * > m_globalLabelsMap
Map between Cadstar and KiCad Global Labels.
std::map< SYMBOL_ID, SCH_SYMBOL * > m_powerSymMap
Map between Cadstar and KiCad Power Symbols.
POINT getLocationOfNetElement(const NET_SCH &aNet, const NETELEMENT_ID &aNetElementID)
EDA_ITEM * GetParent() const
Definition: eda_item.h:99
void SetSize(const VECTOR2I &aSize)
Definition: sch_bus_entry.h:72
Class for a wire to bus entry.
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_field.cpp:1048
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_junction.h:103
VECTOR2I GetEndPoint() const
Definition: sch_line.h:143
VECTOR2I GetStartPoint() const
Definition: sch_line.h:138
VECTOR2I GetSize() const
Definition: sch_sheet.h:108
VECTOR2I GetPosition() const override
Definition: sch_sheet.h:368
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_sheet.h:72
virtual void SetTextSpinStyle(TEXT_SPIN_STYLE aSpinStyle)
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:188
const SHAPE_LINE_CHAIN Reverse() const
Reverse point order in the line chain.
int FindSegment(const VECTOR2I &aP, int aThreshold=1) const
Search for segment containing point aP.
int Intersect(const SEG &aSeg, INTERSECTIONS &aIp) const
Find all intersection points between our line chain and the segment aSeg.
void Replace(int aStartIndex, int aEndIndex, const VECTOR2I &aP)
Replace points with indices in range [start_index, end_index] with a single point aP.
std::vector< INTERSECTION > INTERSECTIONS
const std::vector< VECTOR2I > & CPoints() const
TEXT_SPIN_STYLE MirrorY()
Mirror the label spin style across the Y axis or simply swaps left and right.
Definition: sch_text.cpp:99
TEXT_SPIN_STYLE MirrorX()
Mirror the label spin style across the X axis or simply swaps up and bottom.
Definition: sch_text.cpp:83
@ LAYER_WIRE
Definition: layer_ids.h:344
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:99
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".

References SHAPE_LINE_CHAIN::Append(), applyTextSettings(), CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::BlockTerminals, CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::Buses, CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::BusTerminals, SCH_SHEET::ClassOf(), CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::Connections, alg::contains(), SHAPE_LINE_CHAIN::CPoints(), CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::Danglers, SHAPE_LINE_CHAIN::FindSegment(), Format(), getAngle(), SCH_LINE::GetEndPoint(), getKiCadPoint(), getLineThickness(), getLocationOfNetElement(), EDA_ITEM::GetParent(), SCH_SHEET::GetPosition(), SCH_TEXT::GetPosition(), SCH_SHEET::GetSize(), getSpinStyle(), SCH_LINE::GetStartPoint(), CADSTAR_ARCHIVE_PARSER::HandleTextOverbar(), CADSTAR_ARCHIVE_PARSER::NET::ID, CADSTAR_SCH_ARCHIVE_PARSER::BUS::ID, SHAPE_LINE_CHAIN::Intersect(), CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::Junctions, LAYER_WIRE, CADSTAR_SCH_ARCHIVE_PARSER::BUS::LayerID, m_busesMap, m_globalLabelsMap, m_powerSymMap, m_sheetMap, m_sheetPinMap, TEXT_SPIN_STYLE::MirrorX(), TEXT_SPIN_STYLE::MirrorY(), CADSTAR_ARCHIVE_PARSER::NET::Name, CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::Nets, SHAPE_LINE_CHAIN::Replace(), SHAPE_LINE_CHAIN::Reverse(), SCH_SHEET_PIN_T, CADSTAR_SCH_ARCHIVE_PARSER::Schematic, EDA_TEXT::SetBold(), SCH_LINE::SetEndPoint(), SCH_ITEM::SetLayer(), SCH_LINE::SetLineWidth(), SCH_FIELD::SetPosition(), SCH_JUNCTION::SetPosition(), SCH_TEXT::SetPosition(), SCH_BUS_ENTRY_BASE::SetSize(), SCH_LINE::SetStartPoint(), EDA_TEXT::SetText(), EDA_TEXT::SetTextSize(), SCH_TEXT::SetTextSpinStyle(), SCH_HIERLABEL::SetTextSpinStyle(), EDA_TEXT::SetVisible(), CADSTAR_ARCHIVE_PARSER::NET::SignalNum, SMALL_LABEL_SIZE, CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::Symbols, CADSTAR_SCH_ARCHIVE_PARSER::NET_SCH::Terminals, EDA_ITEM::Type(), CADSTAR_ARCHIVE_PARSER::UNDEFINED_VALUE, VALUE_FIELD, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Load().

◆ loadPartsLibrary()

void CADSTAR_SCH_ARCHIVE_LOADER::loadPartsLibrary ( )
private

Definition at line 372 of file cadstar_sch_archive_loader.cpp.

373{
374 for( std::pair<PART_ID, PART> partPair : Parts.PartDefinitions )
375 {
376 PART_ID partID = partPair.first;
377 PART part = partPair.second;
378
379 wxString escapedPartName = EscapeString( part.Name, CTX_LIBID );
380 LIB_SYMBOL* kiPart = new LIB_SYMBOL( escapedPartName );
381
382 kiPart->SetUnitCount( part.Definition.GateSymbols.size() );
383 bool ok = true;
384
385 for( std::pair<GATE_ID, PART::DEFINITION::GATE> gatePair : part.Definition.GateSymbols )
386 {
387 GATE_ID gateID = gatePair.first;
388 PART::DEFINITION::GATE gate = gatePair.second;
389 SYMDEF_ID symbolID = getSymDefFromName( gate.Name, gate.Alternate );
390
391 if( symbolID.IsEmpty() )
392 {
393 m_reporter->Report( wxString::Format( _( "Part definition '%s' references symbol "
394 "'%s' (alternate '%s') which could not be "
395 "found in the symbol library. The part has "
396 "not been loaded into the KiCad library." ),
397 part.Name,
398 gate.Name,
399 gate.Alternate ),
401
402 ok = false;
403 break;
404 }
405
406 m_partSymbolsMap.insert( { { partID, gateID }, symbolID } );
407 loadSymDefIntoLibrary( symbolID, &part, gateID, kiPart );
408 }
409
410 if( ok && part.Definition.GateSymbols.size() != 0 )
411 {
412 ( *m_plugin )->SaveSymbol( m_libraryFileName.GetFullPath(), kiPart );
413
414 LIB_SYMBOL* loadedPart =
415 ( *m_plugin )->LoadSymbol( m_libraryFileName.GetFullPath(), kiPart->GetName() );
416
417 m_partMap.insert( { partID, loadedPart } );
418 }
419 else
420 {
421 if( part.Definition.GateSymbols.size() == 0 )
422 {
424 wxString::Format( _( "Part definition '%s' has an incomplete definition (no"
425 " symbol definitions are associated with it). The part"
426 " has not been loaded into the KiCad library." ),
427 part.Name ),
429 }
430
431 // Don't save in the library, but still keep it cached as some of the units might have
432 // been loaded correctly (saving us time later on), plus the part definition contains
433 // the part name, which is important to load
434 m_partMap.insert( { partID, kiPart } );
435 }
436
437 checkPoint();
438 }
439}
void loadSymDefIntoLibrary(const SYMDEF_ID &aSymdefID, const PART *aCadstarPart, const GATE_ID &aGateID, LIB_SYMBOL *aSymbol)
std::map< PART_ID, LIB_SYMBOL * > m_partMap
Map between Cadstar and KiCad Parts.
std::map< PART_GATE_ID, SYMDEF_ID > m_partSymbolsMap
Map holding the symbols loaded so far for a particular PART_ID and GATE_ID.
SYMDEF_ID getSymDefFromName(const wxString &aSymdefName, const wxString &aSymDefAlternate)
void SetUnitCount(int aCount, bool aDuplicateDrawItems=true)
Set the units per symbol count.
wxString GetName() const override
Definition: lib_symbol.h:138
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_LIBID
Definition: string_utils.h:55

References _, CADSTAR_ARCHIVE_PARSER::checkPoint(), CTX_LIBID, CADSTAR_ARCHIVE_PARSER::PART::Definition, EscapeString(), Format(), CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::GateSymbols, LIB_SYMBOL::GetName(), getSymDefFromName(), loadSymDefIntoLibrary(), m_libraryFileName, m_partMap, m_partSymbolsMap, m_reporter, CADSTAR_ARCHIVE_PARSER::PART::Name, CADSTAR_ARCHIVE_PARSER::PARTS::PartDefinitions, CADSTAR_SCH_ARCHIVE_PARSER::Parts, REPORTER::Report(), RPT_SEVERITY_WARNING, and LIB_SYMBOL::SetUnitCount().

Referenced by Load().

◆ loadSchematicSymbol()

SCH_SYMBOL * CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbol ( const SYMBOL aCadstarSymbol,
const LIB_SYMBOL aKiCadPart,
EDA_ANGLE aComponentOrientation 
)
private

Definition at line 1743 of file cadstar_sch_archive_loader.cpp.

1746{
1747 LIB_ID libId( m_libraryFileName.GetName(), aKiCadPart.GetName() );
1748 int unit = getKiCadUnitNumberFromGate( aCadstarSymbol.GateID );
1749
1750 SCH_SHEET_PATH sheetpath;
1751 SCH_SHEET* kiSheet = m_sheetMap.at( aCadstarSymbol.LayerID );
1752 m_rootSheet->LocatePathOfScreen( kiSheet->GetScreen(), &sheetpath );
1753
1754 SCH_SYMBOL* symbol = new SCH_SYMBOL( aKiCadPart, libId, &sheetpath, unit );
1755
1756 if( aCadstarSymbol.IsComponent )
1757 {
1758 symbol->SetRef( &sheetpath, aCadstarSymbol.ComponentRef.Designator );
1759 }
1760
1761 symbol->SetPosition( getKiCadPoint( aCadstarSymbol.Origin ) );
1762
1763 EDA_ANGLE compAngle = getAngle( aCadstarSymbol.OrientAngle );
1764 int compOrientation = 0;
1765
1766 if( aCadstarSymbol.Mirror )
1767 {
1768 compAngle = -compAngle;
1769 compOrientation += SYMBOL_ORIENTATION_T::SYM_MIRROR_Y;
1770 }
1771
1772 compOrientation += getComponentOrientation( compAngle, aComponentOrientation );
1773 EDA_ANGLE test1( compAngle );
1774 EDA_ANGLE test2( aComponentOrientation );
1775
1776 if( test1.Normalize180() != test2.Normalize180() )
1777 {
1778 m_reporter->Report( wxString::Format( _( "Symbol '%s' is rotated by an angle of %.1f "
1779 "degrees in the original CADSTAR design but "
1780 "KiCad only supports rotation angles multiples "
1781 "of 90 degrees. The connecting wires will need "
1782 "manual fixing." ),
1783 aCadstarSymbol.ComponentRef.Designator,
1784 compAngle.AsDegrees() ),
1786 }
1787
1788 symbol->SetOrientation( compOrientation );
1789
1790 if( m_sheetMap.find( aCadstarSymbol.LayerID ) == m_sheetMap.end() )
1791 {
1792 m_reporter->Report( wxString::Format( _( "Symbol '%s' references sheet ID '%s' which does "
1793 "not exist in the design. The symbol was not "
1794 "loaded." ),
1795 aCadstarSymbol.ComponentRef.Designator,
1796 aCadstarSymbol.LayerID ),
1798
1799 delete symbol;
1800 return nullptr;
1801 }
1802
1803 wxString gate = ( aCadstarSymbol.GateID.IsEmpty() ) ? wxString( wxT( "A" ) ) : aCadstarSymbol.GateID;
1804 wxString partGateIndex = aCadstarSymbol.PartRef.RefID + gate;
1805
1806 //Handle pin swaps
1807 if( m_pinNumsMap.find( partGateIndex ) != m_pinNumsMap.end() )
1808 {
1809 TERMINAL_TO_PINNUM_MAP termNumMap = m_pinNumsMap.at( partGateIndex );
1810
1811 std::map<wxString, LIB_PIN*> pinNumToLibPinMap;
1812
1813 for( auto& term : termNumMap )
1814 {
1815 wxString pinNum = term.second;
1816 pinNumToLibPinMap.insert( { pinNum,
1817 symbol->GetLibSymbolRef()->GetPin( term.second ) } );
1818 }
1819
1820 auto replacePinNumber =
1821 [&]( wxString aOldPinNum, wxString aNewPinNum )
1822 {
1823 if( aOldPinNum == aNewPinNum )
1824 return;
1825
1826 LIB_PIN* libpin = pinNumToLibPinMap.at( aOldPinNum );
1827 libpin->SetNumber( HandleTextOverbar( aNewPinNum ) );
1828 };
1829
1830 //Older versions of Cadstar used pin numbers
1831 for( auto& pinPair : aCadstarSymbol.PinNumbers )
1832 {
1833 SYMBOL::PIN_NUM pin = pinPair.second;
1834
1835 replacePinNumber( termNumMap.at( pin.TerminalID ),
1836 wxString::Format( "%ld", pin.PinNum ) );
1837 }
1838
1839 //Newer versions of Cadstar use pin names
1840 for( auto& pinPair : aCadstarSymbol.PinNames )
1841 {
1842 SYMPINNAME_LABEL pin = pinPair.second;
1843 replacePinNumber( termNumMap.at( pin.TerminalID ), pin.NameOrLabel );
1844 }
1845
1846 symbol->UpdatePins();
1847 }
1848
1849 kiSheet->GetScreen()->Append( symbol );
1850
1851 return symbol;
1852}
std::map< TERMINAL_ID, wxString > TERMINAL_TO_PINNUM_MAP
Map between a terminal ID in a symbol definition to the pin number that should be imported into KiCad...
std::map< PART_ID, TERMINAL_TO_PINNUM_MAP > m_pinNumsMap
Map of pin numbers in CADSTAR parts.
int getKiCadUnitNumberFromGate(const GATE_ID &aCadstarGateID)
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:124
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
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:759
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_symbol.h:713
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
Definition: sch_symbol.cpp:339
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:716
void SetOrientation(int aOrientation)
Compute the new transform matrix based on aOrientation for the symbol which is applied to the current...
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:192
@ SYM_MIRROR_Y

References _, SCH_SCREEN::Append(), EDA_ANGLE::AsDegrees(), CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::ComponentRef, CADSTAR_SCH_ARCHIVE_PARSER::COMP::Designator, Format(), CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::GateID, getAngle(), getComponentOrientation(), getKiCadPoint(), getKiCadUnitNumberFromGate(), SCH_SYMBOL::GetLibSymbolRef(), LIB_SYMBOL::GetName(), SCH_SHEET::GetScreen(), CADSTAR_ARCHIVE_PARSER::HandleTextOverbar(), CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::IsComponent, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::LayerID, SCH_SHEET::LocatePathOfScreen(), m_libraryFileName, m_pinNumsMap, m_reporter, m_rootSheet, m_sheetMap, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::Mirror, EDA_ANGLE::Normalize180(), CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::OrientAngle, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::Origin, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::PartRef, pin, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::PinNames, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::PinNumbers, CADSTAR_SCH_ARCHIVE_PARSER::PARTREF::RefID, REPORTER::Report(), RPT_SEVERITY_ERROR, LIB_PIN::SetNumber(), SCH_SYMBOL::SetOrientation(), SCH_SYMBOL::SetPosition(), SCH_SYMBOL::SetRef(), SYM_MIRROR_Y, and SCH_SYMBOL::UpdatePins().

Referenced by loadSchematicSymbolInstances().

◆ loadSchematicSymbolInstances()

void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances ( )
private

Definition at line 442 of file cadstar_sch_archive_loader.cpp.

443{
444 for( std::pair<SYMBOL_ID, SYMBOL> symPair : Schematic.Symbols )
445 {
446 SYMBOL sym = symPair.second;
447
448 if( !sym.VariantID.empty() && sym.VariantParentSymbolID != sym.ID )
449 continue; // Only load master Variant
450
451 if( sym.IsComponent )
452 {
453 if( m_partMap.find( sym.PartRef.RefID ) == m_partMap.end() )
454 {
455 m_reporter->Report( wxString::Format( _( "Symbol '%s' references part '%s' which "
456 "could not be found in the library. The "
457 "symbol was not loaded" ),
458 sym.ComponentRef.Designator,
459 sym.PartRef.RefID ),
461
462 continue;
463 }
464
465 if( sym.GateID.IsEmpty() )
466 sym.GateID = wxT( "A" ); // Assume Gate "A" if unspecified
467
468 PART_GATE_ID partSymbolID = { sym.PartRef.RefID, sym.GateID };
469 LIB_SYMBOL* kiPart = m_partMap.at( sym.PartRef.RefID );
470 bool copy = false;
471
472 // The symbol definition in the part either does not exist for this gate number
473 // or is different to the symbol instance. We need to load a new symbol
474 if( m_partSymbolsMap.find( partSymbolID ) == m_partSymbolsMap.end()
475 || m_partSymbolsMap.at( partSymbolID ) != sym.SymdefID )
476 {
477 kiPart = new LIB_SYMBOL( *kiPart ); // Make a copy
478 copy = true;
479 const PART& part = Parts.PartDefinitions.at( sym.PartRef.RefID );
480 loadSymDefIntoLibrary( sym.SymdefID, &part, sym.GateID, kiPart );
481 }
482
483 LIB_SYMBOL* scaledPart = getScaledLibPart( kiPart, sym.ScaleRatioNumerator,
484 sym.ScaleRatioDenominator );
485
486 EDA_ANGLE symOrient = ANGLE_0;
487 SCH_SYMBOL* symbol = loadSchematicSymbol( sym, *scaledPart, symOrient );
488
489 delete scaledPart;
490
491 if( copy )
492 delete kiPart;
493
494 SCH_FIELD* refField = symbol->GetField( REFERENCE_FIELD );
495
496 sym.ComponentRef.Designator.Replace( wxT( "\n" ), wxT( "\\n" ) );
497 sym.ComponentRef.Designator.Replace( wxT( "\r" ), wxT( "\\r" ) );
498 sym.ComponentRef.Designator.Replace( wxT( "\t" ), wxT( "\\t" ) );
499 sym.ComponentRef.Designator.Replace( wxT( " " ), wxT( "_" ) );
500
501 refField->SetText( sym.ComponentRef.Designator );
502 loadSymbolFieldAttribute( sym.ComponentRef.AttrLoc, symOrient, sym.Mirror, refField );
503
504 if( sym.HasPartRef )
505 {
506 SCH_FIELD* partField = symbol->FindField( PartNameFieldName );
507
508 if( !partField )
509 {
510 int fieldID = symbol->GetFieldCount();
511 partField = symbol->AddField( SCH_FIELD( VECTOR2I(), fieldID, symbol,
513 }
514
515 wxASSERT( partField->GetName() == PartNameFieldName );
516
517 wxString partname = getPart( sym.PartRef.RefID ).Name;
518 partname.Replace( wxT( "\n" ), wxT( "\\n" ) );
519 partname.Replace( wxT( "\r" ), wxT( "\\r" ) );
520 partname.Replace( wxT( "\t" ), wxT( "\\t" ) );
521 partField->SetText( partname );
522
523 loadSymbolFieldAttribute( sym.PartRef.AttrLoc, symOrient, sym.Mirror, partField );
524
526 }
527
528 for( auto attr : sym.AttributeValues )
529 {
530 ATTRIBUTE_VALUE attrVal = attr.second;
531
532 if( attrVal.HasLocation )
533 {
534 wxString attrName = getAttributeName( attrVal.AttributeID );
535 SCH_FIELD* attrField = symbol->FindField( attrName );
536
537 if( !attrField )
538 {
539 int fieldID = symbol->GetFieldCount();
540 attrField = symbol->AddField(
541 SCH_FIELD( VECTOR2I(), fieldID, symbol, attrName ) );
542 }
543
544 wxASSERT( attrField->GetName() == attrName );
545
546 attrVal.Value.Replace( wxT( "\n" ), wxT( "\\n" ) );
547 attrVal.Value.Replace( wxT( "\r" ), wxT( "\\r" ) );
548 attrVal.Value.Replace( wxT( "\t" ), wxT( "\\t" ) );
549 attrField->SetText( attrVal.Value );
550
551 loadSymbolFieldAttribute( attrVal.AttributeLocation, symOrient, sym.Mirror,
552 attrField );
553 attrField->SetVisible( isAttributeVisible( attrVal.AttributeID ) );
554 }
555 }
556 }
557 else if( sym.IsSymbolVariant )
558 {
559 if( Library.SymbolDefinitions.find( sym.SymdefID ) == Library.SymbolDefinitions.end() )
560 {
562 _( "Symbol ID '%s' references library symbol '%s' which could not be "
563 "found in the library. Did you export all items of the design?" ),
564 sym.ID, sym.PartRef.RefID ) );
565 }
566
567 SYMDEF_SCM libSymDef = Library.SymbolDefinitions.at( sym.SymdefID );
568
569 if( libSymDef.Terminals.size() != 1 )
570 {
572 _( "Symbol ID '%s' is a signal reference or global signal but it has too "
573 "many pins. The expected number of pins is 1 but %d were found." ),
574 sym.ID, libSymDef.Terminals.size() ) );
575 }
576
577 if( sym.SymbolVariant.Type == SYMBOLVARIANT::TYPE::GLOBALSIGNAL )
578 {
579 SYMDEF_ID symID = sym.SymdefID;
580 LIB_SYMBOL* kiPart = nullptr;
581
582 // In CADSTAR "GlobalSignal" is a special type of symbol which defines
583 // a Power Symbol. The "Alternate" name defines the default net name of
584 // the power symbol but this can be overridden in the design itself.
585 wxString libraryNetName = Library.SymbolDefinitions.at( symID ).Alternate;
586
587 // Name of the net that the symbol instance in CADSTAR refers to:
588 wxString symbolInstanceNetName = sym.SymbolVariant.Reference;
589 symbolInstanceNetName = EscapeString( symbolInstanceNetName, CTX_LIBID );
590
591 // Name of the symbol we will use for saving the part in KiCad
592 // Note: In CADSTAR all power symbols will start have the reference name be
593 // "GLOBALSIGNAL" followed by the default net name, so it makes sense to save
594 // the symbol in KiCad as the default net name as well.
595 wxString libPartName = libraryNetName;
596
597 // In CADSTAR power symbol instances can refer to a different net to that defined
598 // in the library. This causes problems in KiCad v6 as it breaks connectivity when
599 // the user decides to update all symbols from library. We handle this by creating
600 // individual versions of the power symbol for each net name.
601 if( libPartName != symbolInstanceNetName )
602 {
603 libPartName += wxT( " (" ) + symbolInstanceNetName + wxT( ")" );
604 }
605
606 if( m_powerSymLibMap.find( libPartName ) == m_powerSymLibMap.end() )
607 {
608 SYMDEF_SCM symbolDef = Library.SymbolDefinitions.at( symID );
609
610 kiPart = new LIB_SYMBOL( libPartName );
611 kiPart->SetPower();
612 loadSymDefIntoLibrary( symID, nullptr, "A", kiPart );
613
614 kiPart->GetValueField().SetText( symbolInstanceNetName );
615
616 if( symbolDef.TextLocations.find( SIGNALNAME_ORIGIN_ATTRID )
617 != symbolDef.TextLocations.end() )
618 {
619 TEXT_LOCATION txtLoc =
620 symbolDef.TextLocations.at( SIGNALNAME_ORIGIN_ATTRID );
621
622 VECTOR2I valPos = getKiCadLibraryPoint( txtLoc.Position, symbolDef.Origin );
623
624 kiPart->GetValueField().SetPosition( valPos );
625 kiPart->GetValueField().SetVisible( true );
626 }
627 else
628 {
629 kiPart->GetValueField().SetVisible( false );
630 }
631
632 kiPart->GetReferenceField().SetText( "#PWR" );
633 kiPart->GetReferenceField().SetVisible( false );
634 ( *m_plugin )->SaveSymbol( m_libraryFileName.GetFullPath(), kiPart );
635 m_powerSymLibMap.insert( { libPartName, kiPart } );
636 }
637 else
638 {
639 kiPart = m_powerSymLibMap.at( libPartName );
640 wxASSERT( kiPart->GetValueField().GetText() == symbolInstanceNetName );
641 }
642
643 LIB_SYMBOL* scaledPart = getScaledLibPart( kiPart, sym.ScaleRatioNumerator,
644 sym.ScaleRatioDenominator );
645
646 EDA_ANGLE returnedOrient = ANGLE_0;
647 SCH_SYMBOL* symbol = loadSchematicSymbol( sym, *scaledPart, returnedOrient );
648 m_powerSymMap.insert( { sym.ID, symbol } );
649
650 delete scaledPart;
651 }
652 else if( sym.SymbolVariant.Type == SYMBOLVARIANT::TYPE::SIGNALREF )
653 {
654 // There should only be one pin and we'll use that to set the position
655 TERMINAL& symbolTerminal = libSymDef.Terminals.begin()->second;
656 VECTOR2I terminalPosOffset = symbolTerminal.Position - libSymDef.Origin;
657 EDA_ANGLE rotate = getAngle( sym.OrientAngle );
658
659 if( sym.Mirror )
660 rotate += ANGLE_180;
661
662 RotatePoint( terminalPosOffset, -rotate );
663
664 SCH_GLOBALLABEL* netLabel = new SCH_GLOBALLABEL;
665 netLabel->SetPosition( getKiCadPoint( (VECTOR2I)sym.Origin + terminalPosOffset ) );
666 netLabel->SetText( "***UNKNOWN NET****" ); // This should be later updated when we load the netlist
667 netLabel->SetTextSize( VECTOR2I( schIUScale.MilsToIU( 50 ), schIUScale.MilsToIU( 50 ) ) );
668
669 SYMDEF_SCM symbolDef = Library.SymbolDefinitions.at( sym.SymdefID );
670
671 if( symbolDef.TextLocations.count( LINK_ORIGIN_ATTRID ) )
672 {
673 TEXT_LOCATION linkOrigin = symbolDef.TextLocations.at( LINK_ORIGIN_ATTRID );
674 applyTextSettings( netLabel, linkOrigin.TextCodeID, linkOrigin.Alignment,
675 linkOrigin.Justification );
676 }
677
678 netLabel->SetTextSpinStyle( getSpinStyle( sym.OrientAngle, sym.Mirror ) );
679
680 if( libSymDef.Alternate.Lower().Contains( "in" ) )
682 else if( libSymDef.Alternate.Lower().Contains( "bi" ) )
684 else if( libSymDef.Alternate.Lower().Contains( "out" ) )
686 else
688
689 SCH_SCREEN* screen = m_sheetMap.at( sym.LayerID )->GetScreen();
690
691 // autoplace intersheet refs
692 netLabel->AutoplaceFields( screen, false );
693
694 screen->Append( netLabel );
695 m_globalLabelsMap.insert( { sym.ID, netLabel } );
696 }
697 else
698 {
699 wxASSERT_MSG( false, "Unknown Symbol Variant." );
700 }
701 }
702 else
703 {
704 m_reporter->Report( wxString::Format( _( "Symbol ID '%s' is of an unknown type. It is "
705 "neither a symbol or a net power / symbol. "
706 "The symbol was not loaded." ),
707 sym.ID ),
709 }
710
711 if( sym.ScaleRatioDenominator != 1 || sym.ScaleRatioNumerator != 1 )
712 {
713 wxString symbolName = sym.ComponentRef.Designator;
714
715 if( symbolName.empty() )
716 symbolName = wxString::Format( "ID: %s", sym.ID );
717 else
718 symbolName += sym.GateID;
719
720 m_reporter->Report( wxString::Format( _( "Symbol '%s' is scaled in the original "
721 "CADSTAR schematic but this is not supported "
722 "in KiCad. When the symbol is reloaded from "
723 "the library, it will revert to the original "
724 "1:1 scale." ),
725 symbolName,
726 sym.PartRef.RefID ),
728 }
729 }
730}
#define SIGNALNAME_ORIGIN_ATTRID
#define LINK_ORIGIN_ATTRID
const wxString PartNameFieldName
SCH_SYMBOL * loadSchematicSymbol(const SYMBOL &aCadstarSymbol, const LIB_SYMBOL &aKiCadPart, EDA_ANGLE &aComponentOrientation)
wxString getAttributeName(const ATTRIBUTE_ID &aCadstarAttributeID)
PART getPart(const PART_ID &aCadstarPartID)
std::pair< PART_ID, GATE_ID > PART_GATE_ID
std::map< wxString, LIB_SYMBOL * > m_powerSymLibMap
Map of KiCad Power Symbol Library items.
bool isAttributeVisible(const ATTRIBUTE_ID &aCadstarAttributeID)
LIB_SYMBOL * getScaledLibPart(const LIB_SYMBOL *aSymbol, long long aScalingFactorNumerator, long long aScalingFactorDenominator)
void loadSymbolFieldAttribute(const ATTRIBUTE_LOCATION &aCadstarAttrLoc, const EDA_ANGLE &aComponentOrientation, bool aIsMirrored, SCH_FIELD *aKiCadField)
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
void SetPower()
Definition: lib_symbol.cpp:554
LIB_FIELD & GetValueField()
Return reference to the value field.
bool Replace(const EDA_SEARCH_DATA &aSearchData, void *aAuxData=nullptr) override
Perform a text replace using the find and replace criteria in aSearchData on items that support text ...
Definition: sch_field.cpp:631
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:804
void SetTextSpinStyle(TEXT_SPIN_STYLE aSpinStyle) override
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_label.cpp:1332
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_label.cpp:376
int GetFieldCount() const
Return the number of fields in this symbol.
Definition: sch_symbol.h:486
SCH_FIELD * FindField(const wxString &aFieldName, bool aIncludeDefaultFields=true)
Search for a SCH_FIELD with aFieldName.
Definition: sch_symbol.cpp:938
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:865
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
Definition: sch_symbol.cpp:916
@ L_BIDI
Definition: sch_text.h:99
@ L_OUTPUT
Definition: sch_text.h:98
@ L_INPUT
Definition: sch_text.h:97
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".

References _, SCH_SYMBOL::AddField(), CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Alignment, CADSTAR_ARCHIVE_PARSER::SYMDEF::Alternate, ANGLE_0, ANGLE_180, SCH_SCREEN::Append(), applyTextSettings(), CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_VALUE::AttributeID, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_VALUE::AttributeLocation, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::AttributeValues, CADSTAR_SCH_ARCHIVE_PARSER::COMP::AttrLoc, CADSTAR_SCH_ARCHIVE_PARSER::PARTREF::AttrLoc, SCH_LABEL_BASE::AutoplaceFields(), CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::ComponentRef, copy, CTX_LIBID, CADSTAR_SCH_ARCHIVE_PARSER::COMP::Designator, EscapeString(), SCH_SYMBOL::FindField(), Format(), CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::GateID, getAngle(), getAttributeName(), SCH_SYMBOL::GetField(), SCH_SYMBOL::GetFieldCount(), getKiCadLibraryPoint(), getKiCadPoint(), SCH_FIELD::GetName(), getPart(), LIB_SYMBOL::GetReferenceField(), getScaledLibPart(), getSpinStyle(), EDA_TEXT::GetText(), LIB_SYMBOL::GetValueField(), CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_VALUE::HasLocation, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::HasPartRef, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::ID, isAttributeVisible(), CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::IsComponent, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::IsSymbolVariant, CADSTAR_ARCHIVE_PARSER::PARTNAMECOL::IsVisible, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Justification, L_BIDI, L_INPUT, L_OUTPUT, L_UNSPECIFIED, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::LayerID, CADSTAR_SCH_ARCHIVE_PARSER::Library, LINK_ORIGIN_ATTRID, loadSchematicSymbol(), loadSymbolFieldAttribute(), loadSymDefIntoLibrary(), m_globalLabelsMap, m_libraryFileName, m_partMap, m_partSymbolsMap, m_powerSymLibMap, m_powerSymMap, m_reporter, m_sheetMap, EDA_IU_SCALE::MilsToIU(), CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::Mirror, CADSTAR_ARCHIVE_PARSER::PART::Name, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::OrientAngle, CADSTAR_ARCHIVE_PARSER::SYMDEF::Origin, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::Origin, CADSTAR_ARCHIVE_PARSER::PARTS::PartDefinitions, PartNameFieldName, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::PartRef, CADSTAR_SCH_ARCHIVE_PARSER::Parts, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Position, CADSTAR_SCH_ARCHIVE_PARSER::TERMINAL::Position, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOLVARIANT::Reference, REFERENCE_FIELD, CADSTAR_SCH_ARCHIVE_PARSER::PARTREF::RefID, REPORTER::Report(), RotatePoint(), RPT_SEVERITY_ERROR, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::ScaleRatioDenominator, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::ScaleRatioNumerator, CADSTAR_SCH_ARCHIVE_PARSER::Schematic, schIUScale, LIB_ITEM::SetPosition(), SCH_TEXT::SetPosition(), LIB_SYMBOL::SetPower(), SCH_LABEL_BASE::SetShape(), EDA_TEXT::SetText(), EDA_TEXT::SetTextSize(), SCH_GLOBALLABEL::SetTextSpinStyle(), EDA_TEXT::SetVisible(), SIGNALNAME_ORIGIN_ATTRID, CADSTAR_SCH_ARCHIVE_PARSER::LIBRARY_SCM::SymbolDefinitions, CADSTAR_SCH_ARCHIVE_PARSER::SymbolPartNameColor, CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::Symbols, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::SymbolVariant, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::SymdefID, CADSTAR_SCH_ARCHIVE_PARSER::SYMDEF_SCM::Terminals, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::TextCodeID, CADSTAR_ARCHIVE_PARSER::SYMDEF::TextLocations, THROW_IO_ERROR, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOLVARIANT::Type, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_VALUE::Value, CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::VariantID, and CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL::VariantParentSymbolID.

Referenced by Load().

◆ loadShapeVertices()

void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices ( const std::vector< VERTEX > &  aCadstarVertices,
LINECODE_ID  aCadstarLineCodeID,
LAYER_ID  aCadstarSheetID,
SCH_LAYER_ID  aKiCadSchLayerID,
const VECTOR2I aMoveVector = { 0, 0 },
const EDA_ANGLE aRotation = ANGLE_0,
const double &  aScalingFactor = 1.0,
const VECTOR2I aTransformCentre = { 0, 0 },
const bool &  aMirrorInvert = false 
)
private

Definition at line 2037 of file cadstar_sch_archive_loader.cpp.

2046{
2047 int lineWidth = KiROUND( getLineThickness( aCadstarLineCodeID ) * aScalingFactor );
2048 PLOT_DASH_TYPE lineStyle = getLineStyle( aCadstarLineCodeID );
2049
2050 const VERTEX* prev = &aCadstarVertices.at( 0 );
2051 const VERTEX* cur;
2052
2053 wxASSERT_MSG( prev->Type == VERTEX_TYPE::POINT,
2054 "First vertex should always be a point vertex" );
2055
2056 auto pointTransform =
2057 [&]( const VECTOR2I& aV )
2058 {
2059 return applyTransform( getKiCadPoint( aV ), aMoveVector, aRotation,
2060 aScalingFactor, aTransformCentre, aMirrorInvert );
2061 };
2062
2063 for( size_t ii = 1; ii < aCadstarVertices.size(); ii++ )
2064 {
2065 cur = &aCadstarVertices.at( ii );
2066
2067 VECTOR2I transformedStartPoint = pointTransform( prev->End );
2068 VECTOR2I transformedEndPoint = pointTransform( cur->End );
2069
2070 switch( cur->Type )
2071 {
2076 {
2077 SHAPE_ARC tempArc = cur->BuildArc( transformedStartPoint, pointTransform );
2078
2079 SCH_SHAPE* arcShape = new SCH_SHAPE( SHAPE_T::ARC, lineWidth );
2080 arcShape->SetArcGeometry( tempArc.GetP0(), tempArc.GetArcMid(), tempArc.GetP1() );
2081
2082 loadItemOntoKiCadSheet( aCadstarSheetID, arcShape );
2083 }
2084 break;
2085
2086 case VERTEX_TYPE::POINT:
2087 {
2088 SCH_LINE* segment = new SCH_LINE();
2089
2090 segment->SetLayer( aKiCadSchLayerID );
2091 segment->SetLineWidth( lineWidth );
2092 segment->SetLineStyle( lineStyle );
2093
2094 segment->SetStartPoint( transformedStartPoint );
2095 segment->SetEndPoint( transformedEndPoint );
2096
2097 loadItemOntoKiCadSheet( aCadstarSheetID, segment );
2098 }
2099 break;
2100
2101 default:
2102 wxFAIL_MSG( "Unknown CADSTAR Vertex type" );
2103 }
2104
2105
2106 prev = cur;
2107 }
2108}
PLOT_DASH_TYPE getLineStyle(const LINECODE_ID &aCadstarLineCodeID)
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
Definition: eda_shape.cpp:555
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:287
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:114
const VECTOR2I & GetP1() const
Definition: shape_arc.h:113
const VECTOR2I & GetP0() const
Definition: shape_arc.h:112

References CADSTAR_ARCHIVE_PARSER::ANTICLOCKWISE_ARC, CADSTAR_ARCHIVE_PARSER::ANTICLOCKWISE_SEMICIRCLE, applyTransform(), ARC, CADSTAR_ARCHIVE_PARSER::VERTEX::BuildArc(), CADSTAR_ARCHIVE_PARSER::CLOCKWISE_ARC, CADSTAR_ARCHIVE_PARSER::CLOCKWISE_SEMICIRCLE, CADSTAR_ARCHIVE_PARSER::VERTEX::End, SHAPE_ARC::GetArcMid(), getKiCadPoint(), getLineStyle(), getLineThickness(), SHAPE_ARC::GetP0(), SHAPE_ARC::GetP1(), KiROUND(), loadItemOntoKiCadSheet(), CADSTAR_ARCHIVE_PARSER::POINT, EDA_SHAPE::SetArcGeometry(), SCH_LINE::SetEndPoint(), SCH_ITEM::SetLayer(), SCH_LINE::SetLineStyle(), SCH_LINE::SetLineWidth(), SCH_LINE::SetStartPoint(), and CADSTAR_ARCHIVE_PARSER::VERTEX::Type.

Referenced by loadFigure().

◆ loadSheetAndChildSheets()

void CADSTAR_SCH_ARCHIVE_LOADER::loadSheetAndChildSheets ( LAYER_ID  aCadstarSheetID,
const VECTOR2I aPosition,
VECTOR2I  aSheetSize,
const SCH_SHEET_PATH aParentSheet 
)
private

Definition at line 2133 of file cadstar_sch_archive_loader.cpp.

2137{
2138 wxCHECK_MSG( m_sheetMap.find( aCadstarSheetID ) == m_sheetMap.end(), ,
2139 "Sheet already loaded!" );
2140
2141 SCH_SHEET* sheet = new SCH_SHEET(
2142 /* aParent */ aParentSheet.Last(),
2143 /* aPosition */ aPosition,
2144 /* aSize */ VECTOR2I( aSheetSize ) );
2145 SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
2146 SCH_SHEET_PATH instance( aParentSheet );
2147
2148 sheet->SetScreen( screen );
2149
2150 wxString name = Sheets.SheetNames.at( aCadstarSheetID );
2151
2152 SCH_FIELD& sheetNameField = sheet->GetFields()[SHEETNAME];
2153 SCH_FIELD& filenameField = sheet->GetFields()[SHEETFILENAME];
2154
2155 sheetNameField.SetText( name );
2156
2157 int sheetNum = getSheetNumber( aCadstarSheetID );
2158 wxString loadedFilename = wxFileName( Filename ).GetName();
2159 std::string filename = wxString::Format( "%s_%02d", loadedFilename, sheetNum ).ToStdString();
2160
2161 ReplaceIllegalFileNameChars( &filename );
2162 filename += wxT( "." ) + KiCadSchematicFileExtension;
2163
2164 filenameField.SetText( filename );
2165
2166 wxFileName fn( m_schematic->Prj().GetProjectPath() + filename );
2167 sheet->GetScreen()->SetFileName( fn.GetFullPath() );
2168 aParentSheet.Last()->GetScreen()->Append( sheet );
2169 instance.push_back( sheet );
2170
2171 wxString pageNumStr = wxString::Format( "%d", getSheetNumber( aCadstarSheetID ) );
2172 instance.SetPageNumber( pageNumStr );
2173
2174 sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
2175
2176 m_sheetMap.insert( { aCadstarSheetID, sheet } );
2177
2178 loadChildSheets( aCadstarSheetID, instance );
2179}
int getSheetNumber(LAYER_ID aCadstarSheetID)
void loadChildSheets(LAYER_ID aCadstarSheetID, const SCH_SHEET_PATH &aSheet)
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:126
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:76
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:110
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:162
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_sheet.cpp:606
const std::string KiCadSchematicFileExtension
@ SHEETNAME
Definition: sch_sheet.h:45
@ SHEETFILENAME
Definition: sch_sheet.h:46
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Checks aName for illegal file name characters.

References SCH_SCREEN::Append(), SCH_SHEET::AutoplaceFields(), CADSTAR_SCH_ARCHIVE_PARSER::Filename, Format(), SCH_SHEET::GetFields(), PROJECT::GetProjectPath(), SCH_SHEET::GetScreen(), getSheetNumber(), KiCadSchematicFileExtension, SCH_SHEET_PATH::Last(), loadChildSheets(), m_schematic, m_sheetMap, name, SCHEMATIC::Prj(), SCH_SHEET_PATH::push_back(), ReplaceIllegalFileNameChars(), SCH_SCREEN::SetFileName(), SCH_SHEET_PATH::SetPageNumber(), SCH_SHEET::SetScreen(), EDA_TEXT::SetText(), SHEETFILENAME, SHEETNAME, CADSTAR_SCH_ARCHIVE_PARSER::SHEETS::SheetNames, and CADSTAR_SCH_ARCHIVE_PARSER::Sheets.

Referenced by loadChildSheets(), and loadSheets().

◆ loadSheets()

void CADSTAR_SCH_ARCHIVE_LOADER::loadSheets ( )
private

Definition at line 271 of file cadstar_sch_archive_loader.cpp.

272{
273 const std::vector<LAYER_ID>& orphanSheets = findOrphanSheets();
274 SCH_SHEET_PATH rootPath;
275 rootPath.push_back( m_rootSheet );
276 rootPath.SetPageNumber( wxT( "1" ) );
277
278 if( orphanSheets.size() > 1 )
279 {
280 int x = 1;
281 int y = 1;
282
283 for( LAYER_ID sheetID : orphanSheets )
284 {
285 VECTOR2I pos( x * schIUScale.MilsToIU( 1000 ), y * schIUScale.MilsToIU( 1000 ) );
286 VECTOR2I siz( schIUScale.MilsToIU( 1000 ), schIUScale.MilsToIU( 1000 ) );
287
288 loadSheetAndChildSheets( sheetID, pos, siz, rootPath );
289
290 x += 2;
291
292 if( x > 10 ) // start next row
293 {
294 x = 1;
295 y += 2;
296 }
297 }
298 }
299 else if( orphanSheets.size() > 0 )
300 {
301 LAYER_ID rootSheetID = orphanSheets.at( 0 );
302
303 wxFileName loadedFilePath = wxFileName( Filename );
304
305 std::string filename = wxString::Format( "%s_%02d",
306 loadedFilePath.GetName(),
307 getSheetNumber( rootSheetID ) ).ToStdString();
308 ReplaceIllegalFileNameChars( &filename );
309 filename += wxT( "." ) + KiCadSchematicFileExtension;
310
311 wxFileName fn( m_schematic->Prj().GetProjectPath() + filename );
312 m_rootSheet->GetScreen()->SetFileName( fn.GetFullPath() );
313
314 m_sheetMap.insert( { rootSheetID, m_rootSheet } );
315 loadChildSheets( rootSheetID, rootPath );
316 }
317 else
318 {
319 THROW_IO_ERROR( _( "The CADSTAR schematic might be corrupt: there is no root sheet." ) );
320 }
321}
std::vector< LAYER_ID > findOrphanSheets()
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.

References _, CADSTAR_SCH_ARCHIVE_PARSER::Filename, findOrphanSheets(), Format(), PROJECT::GetProjectPath(), SCH_SHEET::GetScreen(), getSheetNumber(), KiCadSchematicFileExtension, loadChildSheets(), loadSheetAndChildSheets(), m_rootSheet, m_schematic, m_sheetMap, EDA_IU_SCALE::MilsToIU(), SCHEMATIC::Prj(), SCH_SHEET_PATH::push_back(), ReplaceIllegalFileNameChars(), schIUScale, SCH_SCREEN::SetFileName(), SCH_SHEET_PATH::SetPageNumber(), and THROW_IO_ERROR.

Referenced by Load().

◆ loadSymbolFieldAttribute()

void CADSTAR_SCH_ARCHIVE_LOADER::loadSymbolFieldAttribute ( const ATTRIBUTE_LOCATION aCadstarAttrLoc,
const EDA_ANGLE aComponentOrientation,
bool  aIsMirrored,
SCH_FIELD aKiCadField 
)
private

Definition at line 1855 of file cadstar_sch_archive_loader.cpp.

1859{
1860 aKiCadField->SetPosition( getKiCadPoint( aCadstarAttrLoc.Position ) );
1861 aKiCadField->SetVisible( true );
1862
1863 ALIGNMENT alignment = aCadstarAttrLoc.Alignment;
1864 EDA_ANGLE textAngle = getAngle( aCadstarAttrLoc.OrientAngle );
1865
1866 if( aIsMirrored )
1867 {
1868 // We need to change the aligment when the symbol is mirrored based on the text orientation
1869 // To ensure the anchor point is the same in KiCad.
1870
1871 int textIsVertical = KiROUND( textAngle.AsDegrees() / 90.0 ) % 2;
1872
1873 if( textIsVertical )
1874 alignment = rotate180( alignment );
1875
1876 alignment = mirrorX( alignment );
1877 }
1878
1879 applyTextSettings( aKiCadField,
1880 aCadstarAttrLoc.TextCodeID,
1881 alignment,
1882 aCadstarAttrLoc.Justification,
1883 getCadstarAngle( textAngle - aComponentOrientation ),
1884 aCadstarAttrLoc.Mirror );
1885}
long long getCadstarAngle(const EDA_ANGLE &aAngle)

References CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Alignment, applyTextSettings(), EDA_ANGLE::AsDegrees(), getAngle(), getCadstarAngle(), getKiCadPoint(), CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Justification, KiROUND(), CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Mirror, mirrorX(), CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::OrientAngle, CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::Position, rotate180(), SCH_FIELD::SetPosition(), EDA_TEXT::SetVisible(), and CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::TextCodeID.

Referenced by loadSchematicSymbolInstances().

◆ loadSymDefIntoLibrary()

void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary ( const SYMDEF_ID aSymdefID,
const PART aCadstarPart,
const GATE_ID aGateID,
LIB_SYMBOL aSymbol 
)
private

Definition at line 1309 of file cadstar_sch_archive_loader.cpp.

1311{
1312 wxCHECK( Library.SymbolDefinitions.find( aSymdefID ) != Library.SymbolDefinitions.end(), );
1313
1314 SYMDEF_SCM symbol = Library.SymbolDefinitions.at( aSymdefID );
1315 int gateNumber = getKiCadUnitNumberFromGate( aGateID );
1316
1317 // Ensure there are no items on this unit (e.g. if we already previously loaded the symbol from
1318 // the part definition)
1319 std::vector<LIB_ITEM*> drawItems = aSymbol->GetUnitDrawItems( gateNumber, 0 );
1320
1321 for( LIB_ITEM* item : drawItems )
1322 aSymbol->RemoveDrawItem( item );
1323
1324 for( std::pair<FIGURE_ID, FIGURE> figPair : symbol.Figures )
1325 {
1326 FIGURE fig = figPair.second;
1327 int lineThickness = getLineThickness( fig.LineCodeID );
1328 PLOT_DASH_TYPE linestyle = getLineStyle( fig.LineCodeID );
1329
1330 if( fig.Shape.Type == SHAPE_TYPE::OPENSHAPE )
1331 {
1332 loadLibrarySymbolShapeVertices( fig.Shape.Vertices, symbol.Origin, aSymbol, gateNumber,
1333 lineThickness );
1334 }
1335 else
1336 {
1337 LIB_SHAPE* shape = new LIB_SHAPE( aSymbol, SHAPE_T::POLY );
1338 shape->SetPolyShape( fig.Shape.ConvertToPolySet(
1339 [&]( const VECTOR2I& aPt )
1340 {
1341 return getKiCadLibraryPoint( aPt, symbol.Origin );
1342 },
1343 ARC_ACCURACY ) );
1344
1345 shape->SetUnit( gateNumber );
1346
1347 shape->SetStroke( STROKE_PARAMS( lineThickness, linestyle ) );
1348
1349 if( fig.Shape.Type == SHAPE_TYPE::SOLID )
1351 else if( fig.Shape.Type == SHAPE_TYPE::OUTLINE )
1352 shape->SetFillMode( FILL_T::NO_FILL );
1353 else if( fig.Shape.Type == SHAPE_TYPE::HATCHED ) // We don't have an equivalent
1355
1356 aSymbol->AddDrawItem( shape );
1357 }
1358 }
1359
1360 TERMINAL_TO_PINNUM_MAP pinNumMap;
1361
1362 for( std::pair<TERMINAL_ID, TERMINAL> termPair : symbol.Terminals )
1363 {
1364 TERMINAL term = termPair.second;
1365 wxString pinNum = wxString::Format( "%ld", term.ID );
1366 wxString pinName = wxEmptyString;
1367 LIB_PIN* pin = new LIB_PIN( aSymbol );
1368
1369 if( aCadstarPart )
1370 {
1371 PART::DEFINITION::PIN csPin = getPartDefinitionPin( *aCadstarPart, aGateID, term.ID );
1372
1373 pinName = HandleTextOverbar( csPin.Label );
1374 pinNum = HandleTextOverbar( csPin.Name );
1375
1376 if( pinNum.IsEmpty() )
1377 {
1378 if( !csPin.Identifier.IsEmpty() )
1379 pinNum = csPin.Identifier;
1380 else if( csPin.ID == UNDEFINED_VALUE )
1381 pinNum = wxString::Format( "%ld", term.ID );
1382 else
1383 pinNum = wxString::Format( "%ld", csPin.ID );
1384 }
1385
1386 pin->SetType( getKiCadPinType( csPin.Type ) );
1387
1388 pinNumMap.insert( { term.ID, pinNum } );
1389 }
1390 else
1391 {
1392 // If no part is defined, we don't know the pin type. Assume passive pin
1394 }
1395
1396 pin->SetPosition( getKiCadLibraryPoint( term.Position, symbol.Origin ) );
1397 pin->SetLength( 0 ); //CADSTAR Pins are just a point (have no length)
1398 pin->SetShape( GRAPHIC_PINSHAPE::LINE );
1399 pin->SetUnit( gateNumber );
1400 pin->SetNumber( pinNum );
1401 pin->SetName( pinName );
1402
1403 int pinNumberHeight = getTextHeightFromTextCode( wxT( "TC0" ) ); // TC0 is the default CADSTAR text size for name/number
1404 int pinNameHeight = getTextHeightFromTextCode( wxT( "TC0" ) );
1405
1406 if( symbol.PinNumberLocations.count( term.ID ) )
1407 {
1408 PIN_NUM_LABEL_LOC pinNumLocation = symbol.PinNumberLocations.at( term.ID );
1409 pinNumberHeight = getTextHeightFromTextCode( pinNumLocation.TextCodeID );
1410 }
1411
1412 if( symbol.PinLabelLocations.count( term.ID ) )
1413 {
1414 PIN_NUM_LABEL_LOC pinNameLocation = symbol.PinLabelLocations.at( term.ID );
1415 pinNameHeight = getTextHeightFromTextCode( pinNameLocation.TextCodeID );
1416 }
1417
1418 pin->SetNumberTextSize( pinNumberHeight );
1419 pin->SetNameTextSize( pinNameHeight );
1420
1421 if( aSymbol->IsPower() )
1422 {
1424