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 )
 
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, wxPoint aSymbolOrigin, LIB_SYMBOL *aSymbol, int aGateNumber, int aLineThickness)
 
void applyToLibraryFieldAttribute (const ATTRIBUTE_LOCATION &aCadstarAttrLoc, wxPoint 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 loadGraphicStaightSegment (const VECTOR2I &aStartPoint, const VECTOR2I &aEndPoint, const LINECODE_ID &aCadstarLineCodeID, const LAYER_ID &aCadstarSheetID, const 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 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, wxSize > getFigureExtentsKiCad (const FIGURE &aCadstarFigure)
 
VECTOR2I getKiCadPoint (const VECTOR2I &aCadstarPoint)
 
wxPoint getKiCadLibraryPoint (const wxPoint &aCadstarPoint, const wxPoint &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...
 

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 100 of file cadstar_archive_parser.h.

◆ BLOCK_ID

typedef wxString CADSTAR_SCH_ARCHIVE_PARSER::BLOCK_ID
inherited

Definition at line 54 of file cadstar_sch_archive_parser.h.

◆ BLOCK_PIN_ID

Definition at line 86 of file cadstar_sch_archive_loader.h.

◆ BUS_ID

typedef wxString CADSTAR_SCH_ARCHIVE_PARSER::BUS_ID
inherited

Definition at line 53 of file cadstar_sch_archive_parser.h.

◆ COLOR_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::COLOR_ID
inherited

Definition at line 114 of file cadstar_archive_parser.h.

◆ DOCUMENTATION_SYMBOL_ID

Definition at line 113 of file cadstar_archive_parser.h.

◆ FIGURE_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::FIGURE_ID
inherited

Definition at line 108 of file cadstar_archive_parser.h.

◆ GATE_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::GATE_ID
inherited

Definition at line 103 of file cadstar_archive_parser.h.

◆ GROUP_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::GROUP_ID
inherited

Definition at line 109 of file cadstar_archive_parser.h.

◆ HATCHCODE_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::HATCHCODE_ID
inherited

Definition at line 93 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 98 of file cadstar_archive_parser.h.

◆ LINECODE_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::LINECODE_ID
inherited

Definition at line 92 of file cadstar_archive_parser.h.

◆ NET_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::NET_ID
inherited

Definition at line 111 of file cadstar_archive_parser.h.

◆ NETCLASS_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::NETCLASS_ID
inherited

Definition at line 95 of file cadstar_archive_parser.h.

◆ NETELEMENT_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::NETELEMENT_ID
inherited

Definition at line 112 of file cadstar_archive_parser.h.

◆ PART_DEFINITION_PIN_ID

Pin identifier in the part definition.

Definition at line 105 of file cadstar_archive_parser.h.

◆ PART_GATE_ID

Definition at line 87 of file cadstar_sch_archive_loader.h.

◆ PART_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::PART_ID
inherited

Definition at line 102 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 106 of file cadstar_archive_parser.h.

◆ REUSEBLOCK_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::REUSEBLOCK_ID
inherited

Definition at line 110 of file cadstar_archive_parser.h.

◆ ROUTECODE_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::ROUTECODE_ID
inherited

Definition at line 94 of file cadstar_archive_parser.h.

◆ SHEET_NAME

typedef wxString CADSTAR_SCH_ARCHIVE_PARSER::SHEET_NAME
inherited

Definition at line 55 of file cadstar_sch_archive_parser.h.

◆ SPACING_CLASS_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::SPACING_CLASS_ID
inherited

Definition at line 96 of file cadstar_archive_parser.h.

◆ SYMBOL_ID

typedef wxString CADSTAR_SCH_ARCHIVE_PARSER::SYMBOL_ID
inherited

Definition at line 52 of file cadstar_sch_archive_parser.h.

◆ SYMDEF_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::SYMDEF_ID
inherited

Definition at line 101 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 104 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 93 of file cadstar_sch_archive_loader.h.

◆ TERMINALCODE_ID

typedef wxString CADSTAR_SCH_ARCHIVE_PARSER::TERMINALCODE_ID
inherited

Definition at line 51 of file cadstar_sch_archive_parser.h.

◆ TEXT_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::TEXT_ID
inherited

Definition at line 107 of file cadstar_archive_parser.h.

◆ TEXTCODE_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::TEXTCODE_ID
inherited

Definition at line 97 of file cadstar_archive_parser.h.

◆ VARIANT_ID

typedef wxString CADSTAR_ARCHIVE_PARSER::VARIANT_ID
inherited

Definition at line 99 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 576 of file cadstar_archive_parser.h.

577 {
578 NO_ALIGNMENT,
579 TOPLEFT,
580 TOPCENTER,
581 TOPRIGHT,
582 CENTERLEFT,
583 CENTERCENTER,
584 CENTERRIGHT,
585 BOTTOMLEFT,
586 BOTTOMCENTER,
587 BOTTOMRIGHT
588 };

◆ ANGUNITS

enum class CADSTAR_ARCHIVE_PARSER::ANGUNITS
stronginherited
Enumerator
DEGREES 
RADIANS 

Definition at line 486 of file cadstar_archive_parser.h.

487 {
488 DEGREES,
489 RADIANS
490 };

◆ 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 630 of file cadstar_archive_parser.h.

631 {
632 ALL_ITEMS,
633 AREA,
634 BOARD,
635 COMPONENT,
636 CONNECTION,
637 COPPER,
638 DOCSYMBOL,
639 FIGURE,
640 NET,
641 NETCLASS,
642 PART,
643 PART_DEFINITION,
644 PIN,
645 SIGNALREF,
646 SYMBOL,
647 SYMDEF,
648 TEMPLATE,
650 };
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:240
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 653 of file cadstar_archive_parser.h.

654 {
655 BOTH,
657 COMPONENT,
658 PART_DEFINITION,
660 PART_LIBRARY,
661 SYMBOL,
663 UNDEFINED
666 };

◆ 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 496 of file cadstar_archive_parser.h.

497 {
498 FRACTIONALGRID,
500 STEPGRID
501 };

◆ 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 602 of file cadstar_archive_parser.h.

◆ LINESTYLE

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

Definition at line 280 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 620 of file cadstar_archive_parser.h.

621 {
622 BOTTOM_TO_TOP,
623 TOP_TO_BOTTOM
624 };

◆ RESOLUTION

enum class CADSTAR_ARCHIVE_PARSER::RESOLUTION
stronginherited
Enumerator
HUNDREDTH_MICRON 

Definition at line 242 of file cadstar_archive_parser.h.

243 {
244 HUNDREDTH_MICRON
245 };

◆ 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 450 of file cadstar_archive_parser.h.

451 {
452 OPENSHAPE,
453 OUTLINE,
454 SOLID,
455 HATCHED
456 };

◆ 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 810 of file cadstar_archive_parser.h.

811 {
812 NO_SWAP,
813 USE_SWAP_LAYER,
814 BOTH
815 };

◆ 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 58 of file cadstar_sch_archive_parser.h.

59 {
60 ANNULUS,
61 BOX,
62 BULLET,
63 CIRCLE,
64 CROSS,
65 DIAMOND,
66 FINGER,
67 OCTAGON,
68 PLUS,
69 POINTER,
71 ROUNDED_RECT,
72 SQUARE,
73 STAR,
76 };
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 135 of file cadstar_archive_parser.h.

136 {
137 DESIGN_TITLE,
138 SHORT_JOBNAME,
139 LONG_JOBNAME,
140 NUM_OF_SHEETS,
141 SHEET_NUMBER,
143 VARIANT_NAME,
144 VARIANT_DESCRIPTION,
145 REG_USER,
146 COMPANY_NAME,
147 CURRENT_USER,
148 DATE,
149 TIME,
150 MACHINE_NAME,
151 FROM_FILE,
152 DISTANCE,
153 UNITS_SHORT,
154 UNITS_ABBREV,
155 UNITS_FULL,
156 HYPERLINK,
157 NONE
158 };
@ NONE
No updates are required.
Definition: view_item.h:46
@ DISTANCE
Display value expressed in distance units (mm/inch)
Definition: property.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 471 of file cadstar_archive_parser.h.

472 {
473 DESIGN,
474 THOU,
475 INCH,
476 MICROMETRE,
477 MM,
479 METER
480 };
@ INCH
Definition: rs274x.cpp:63

◆ VERTEX_TYPE

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

Definition at line 416 of file cadstar_archive_parser.h.

417 {
418 POINT,
419 CLOCKWISE_ARC,
420 CLOCKWISE_SEMICIRCLE,
421 ANTICLOCKWISE_ARC,
422 ANTICLOCKWISE_SEMICIRCLE
423 };

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 58 of file cadstar_sch_archive_loader.h.

59 :
61 {
62 m_schematic = nullptr;
63 m_rootSheet = nullptr;
64 m_plugin = nullptr;
65 m_designCenter.x = 0;
66 m_designCenter.y = 0;
67 m_reporter = aReporter;
68 m_progressReporter = aProgressReporter;
69 }
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 72 of file cadstar_sch_archive_loader.h.

73 {
74 }

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 2621 of file cadstar_sch_archive_loader.cpp.

2627{
2628 // Justification ignored for now as not supported in Eeschema, but leaving this code in
2629 // place for future upgrades.
2630 // TODO update this when Eeschema supports justification independent of anchor position.
2631
2632 TEXTCODE textCode = getTextCode( aCadstarTextCodeID );
2633 int textHeight = KiROUND( (double) getKiCadLength( textCode.Height ) * TXT_HEIGHT_RATIO );
2634 int textWidth = getKiCadLength( textCode.Width );
2635
2636 // Ensure we have no Cadstar overbar characters
2637 wxString escapedText = HandleTextOverbar( aKiCadTextItem->GetText() );
2638 aKiCadTextItem->SetText( escapedText );
2639
2640 // The width is zero for all non-cadstar fonts. Using a width equal to 2/3 the height seems
2641 // to work well for most fonts.
2642 if( textWidth == 0 )
2643 textWidth = getKiCadLength( 2 * textCode.Height / 3 );
2644
2645 aKiCadTextItem->SetTextWidth( textWidth );
2646 aKiCadTextItem->SetTextHeight( textHeight );
2647 aKiCadTextItem->SetTextThickness( getKiCadLength( textCode.LineWidth ) );
2648 aKiCadTextItem->SetTextAngle( getAngle( aCadstarOrientAngle ) );
2649 aKiCadTextItem->SetBold( textCode.Font.Modifier1 == FONT_BOLD );
2650 aKiCadTextItem->SetItalic( textCode.Font.Italic );
2651
2652 ALIGNMENT textAlignment = aCadstarAlignment;
2653
2654 // KiCad mirrors the justification and alignment when the symbol is mirrored but CADSTAR
2655 // specifies it post-mirroring. In contrast, if the text item itself is mirrored (not
2656 // supported in KiCad), CADSTAR specifies the alignment and justification pre-mirroring
2657 if( aMirrored )
2658 textAlignment = mirrorX( aCadstarAlignment );
2659
2660 auto setAlignment =
2661 [&]( EDA_TEXT* aText, ALIGNMENT aAlignment )
2662 {
2663 switch( aAlignment )
2664 {
2665 case ALIGNMENT::NO_ALIGNMENT: // Bottom left of the first line
2666 //No exact KiCad equivalent, so lets move the position of the text
2672 break;
2673
2677 break;
2678
2682 break;
2683
2687 break;
2688
2692 break;
2693
2697 break;
2698
2699 case ALIGNMENT::TOPLEFT:
2702 break;
2703
2707 break;
2708
2712 break;
2713 }
2714 };
2715
2716 TEXT_SPIN_STYLE spin = getSpinStyle( aCadstarOrientAngle, aMirrored );
2717 EDA_ITEM* textEdaItem = dynamic_cast<EDA_ITEM*>( aKiCadTextItem );
2718 wxCHECK( textEdaItem, /* void */ ); // ensure this is a EDA_ITEM
2719
2720 switch( textEdaItem->Type() )
2721 {
2722 // Some KiCad schematic text items only permit a limited amount of angles
2723 // and text justifications
2724 case LIB_TEXT_T:
2725 case SCH_FIELD_T:
2726 case LIB_FIELD_T:
2727 {
2728 // Spin style not used. All text justifications are permitted. However, only orientations
2729 // of 0 deg or 90 deg are supported
2730 EDA_ANGLE angle = aKiCadTextItem->GetTextAngle();
2731 angle.Normalize();
2732
2733 int quadrant = KiROUND( angle.AsDegrees() / 90.0 );
2734 quadrant %= 4;
2735
2736 switch( quadrant )
2737 {
2738 case 0:
2740 break;
2741 case 1:
2743 break;
2744 case 2:
2746 textAlignment = rotate180( textAlignment );
2747 break;
2748 case 3:
2750 textAlignment = rotate180( textAlignment );
2751 break;
2752 default: wxFAIL_MSG( "Unknown Quadrant" );
2753 }
2754
2755 aKiCadTextItem->SetTextAngle( angle );
2756 setAlignment( aKiCadTextItem, textAlignment );
2757 return;
2758 }
2759
2760 case SCH_TEXT_T:
2761 {
2762 // Note spin style in a SCH_TEXT results in a vertical alignment GR_TEXT_V_ALIGN_BOTTOM
2763 // so need to adjust the location of the text element based on Cadstar's original text
2764 // alignment (anchor position).
2765 setAlignment( aKiCadTextItem, textAlignment );
2766 EDA_RECT bb = textEdaItem->GetBoundingBox();
2767 int off = static_cast<SCH_TEXT*>( aKiCadTextItem )->GetTextOffset();
2768 wxPoint pos;
2769
2770 // Change the anchor point of the text item to make it match the same bounding box
2771 // And correct the error introduced by the text offsetting in KiCad
2772 switch( spin )
2773 {
2774 case TEXT_SPIN_STYLE::BOTTOM: pos = { bb.GetRight() - off, bb.GetTop() }; break;
2775 case TEXT_SPIN_STYLE::UP: pos = { bb.GetRight() - off, bb.GetBottom() }; break;
2776 case TEXT_SPIN_STYLE::LEFT: pos = { bb.GetRight() , bb.GetBottom() + off }; break;
2777 case TEXT_SPIN_STYLE::RIGHT: pos = { bb.GetLeft() , bb.GetBottom() + off }; break;
2778 }
2779
2780 aKiCadTextItem->SetTextPos( pos );
2781 }
2783
2784 // We don't want to change position of net labels as that would break connectivity
2785 case SCH_LABEL_T:
2786 case SCH_GLOBAL_LABEL_T:
2787 case SCH_HIER_LABEL_T:
2788 case SCH_SHEET_PIN_T:
2789 static_cast<SCH_TEXT*>( aKiCadTextItem )->SetTextSpinStyle( spin );
2790 return;
2791
2792 default:
2793 wxFAIL_MSG( "Unexpected item type" );
2794 return;
2795 }
2796}
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:100
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:75
Handle the component boundary box.
Definition: eda_rect.h:44
int GetLeft() const
Definition: eda_rect.h:126
int GetTop() const
Definition: eda_rect.h:127
int GetRight() const
Definition: eda_rect.h:125
int GetBottom() const
Definition: eda_rect.h:128
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:73
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:128
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:88
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:371
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:248
void SetTextWidth(int aWidth)
Definition: eda_text.cpp:355
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:185
void SetTextHeight(int aHeight)
Definition: eda_text.cpp:363
void SetBold(bool aBold)
Definition: eda_text.cpp:209
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:163
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:193
void SetItalic(bool aItalic)
Definition: eda_text.cpp:201
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:240
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
Definition: eda_angle.h:419
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:420
#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:192
@ SCH_FIELD_T
Definition: typeinfo.h:146
@ SCH_LABEL_T
Definition: typeinfo.h:142
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:144
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:148
@ SCH_TEXT_T
Definition: typeinfo.h:141
@ LIB_FIELD_T
Definition: typeinfo.h:200
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:143
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:80

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(), EDA_RECT::GetBottom(), EDA_ITEM::GetBoundingBox(), getKiCadLength(), EDA_RECT::GetLeft(), EDA_RECT::GetRight(), getSpinStyle(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), getTextCode(), EDA_RECT::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,
wxPoint  aSymbolOrigin,
LIB_FIELD aKiCadField 
)
private

Definition at line 1702 of file cadstar_sch_archive_loader.cpp.

1704{
1705 aKiCadField->SetTextPos( getKiCadLibraryPoint( aCadstarAttrLoc.Position, aSymbolOrigin ) );
1706
1707 applyTextSettings( aKiCadField,
1708 aCadstarAttrLoc.TextCodeID,
1709 aCadstarAttrLoc.Alignment,
1710 aCadstarAttrLoc.Justification,
1711 aCadstarAttrLoc.OrientAngle,
1712 aCadstarAttrLoc.Mirror );
1713}
void applyTextSettings(EDA_TEXT *aKiCadTextItem, const TEXTCODE_ID &aCadstarTextCodeID, const ALIGNMENT &aCadstarAlignment, const JUSTIFICATION &aCadstarJustification, const long long aCadstarOrientAngle=0, bool aMirrored=false)
wxPoint getKiCadLibraryPoint(const wxPoint &aCadstarPoint, const wxPoint &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 3051 of file cadstar_sch_archive_loader.cpp.

3057{
3058 VECTOR2I retVal = aPoint;
3059
3060 if( aScalingFactor != 1.0 )
3061 {
3062 //scale point
3063 retVal -= aTransformCentre;
3064 retVal.x = KiROUND( retVal.x * aScalingFactor );
3065 retVal.y = KiROUND( retVal.y * aScalingFactor );
3066 retVal += aTransformCentre;
3067 }
3068
3069 if( aMirrorInvert )
3070 MIRROR( retVal.x, aTransformCentre.x );
3071
3072 if( !aRotation.IsZero() )
3073 RotatePoint( retVal, aTransformCentre, aRotation );
3074
3075 if( aMoveVector != wxPoint{ 0, 0 } )
3076 retVal += aMoveVector;
3077
3078 return retVal;
3079}
bool IsZero() const
Definition: eda_angle.h:180
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 loadGraphicStaightSegment().

◆ 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 2648 of file cadstar_archive_parser.cpp.

2649{
2650 if( m_progressReporter )
2651 {
2653
2655 THROW_IO_ERROR( _( "File import cancelled by user." ) );
2656 }
2657}
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 2297 of file cadstar_sch_archive_loader.cpp.

2298{
2299 std::vector<LAYER_ID> childSheets, orphanSheets;
2300
2301 //Find all sheets that are child of another
2302 for( std::pair<BLOCK_ID, BLOCK> blockPair : Schematic.Blocks )
2303 {
2304 BLOCK& block = blockPair.second;
2305 LAYER_ID& assocSheetID = block.AssocLayerID;
2306
2307 if( block.Type == BLOCK::TYPE::CHILD )
2308 childSheets.push_back( assocSheetID );
2309 }
2310
2311 //Add sheets that do not have a parent
2312 for( LAYER_ID sheetID : Sheets.SheetOrder )
2313 {
2314 if( std::find( childSheets.begin(), childSheets.end(), sheetID ) == childSheets.end() )
2315 orphanSheets.push_back( sheetID );
2316 }
2317
2318 return orphanSheets;
2319}
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 2621 of file cadstar_archive_parser.cpp.

2622{
2623 if( !aKiCadTextItem->GetText().IsEmpty() )
2624 {
2625 VECTOR2I positionOffset( 0, aKiCadTextItem->GetInterline() );
2626 RotatePoint( positionOffset, aKiCadTextItem->GetTextAngle() );
2627
2628 EDA_ITEM* textEdaItem = dynamic_cast<EDA_ITEM*>( aKiCadTextItem );
2629
2630 if( textEdaItem &&
2631 ( textEdaItem->Type() == LIB_TEXT_T || textEdaItem->Type() == LIB_FIELD_T ) )
2632 {
2633 // Y coordinate increases upwards in the symbol editor
2634 positionOffset.y = -positionOffset.y;
2635 }
2636
2637 //Count num of additional lines
2638 wxString text = aKiCadTextItem->GetText();
2639 int numExtraLines = text.Replace( "\n", "\n" );
2640 numExtraLines -= text.at( text.size() - 1 ) == '\n'; // Ignore new line character at end
2641 positionOffset.x *= numExtraLines;
2642 positionOffset.y *= numExtraLines;
2643
2644 aKiCadTextItem->Offset( positionOffset );
2645 }
2646}
int GetInterline() const
Return the distance between two lines of text.
Definition: eda_text.cpp:526
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:389

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 2899 of file cadstar_sch_archive_loader.cpp.

2900{
2901 auto compLambda = []( const VECTOR2I& aA, const VECTOR2I& aB )
2902 {
2903 return LexicographicalCompare( aA, aB ) < 0;
2904 };
2905
2906 // Store a list of vertical or horizontal segments in the symbol
2907 // Note: Need the custom comparison function to ensure the map is sorted correctly
2908 std::map<VECTOR2I, SHAPE_LINE_CHAIN, decltype( compLambda )> uniqueSegments( compLambda );
2909
2910 LIB_ITEMS_CONTAINER::ITERATOR shapeIt = aSymbolToFix->GetDrawItems().begin( LIB_SHAPE_T );
2911
2912 for( ; shapeIt != aSymbolToFix->GetDrawItems().end( LIB_SHAPE_T ); ++shapeIt )
2913 {
2914 LIB_SHAPE& shape = static_cast<LIB_SHAPE&>( *shapeIt );
2915
2916 if( aGateNumber > 0 && shape.GetUnit() != aGateNumber )
2917 continue;
2918
2919 if( shape.GetShape() != SHAPE_T::POLY )
2920 continue;
2921
2922 SHAPE_LINE_CHAIN poly = shape.GetPolyShape().Outline( 0 );
2923
2924 if( poly.GetPointCount() == 2 )
2925 {
2926 VECTOR2I pt0 = poly.CPoint( 0 );
2927 VECTOR2I pt1 = poly.CPoint( 1 );
2928
2929 if( pt0 != pt1 && uniqueSegments.count( pt0 ) == 0 && uniqueSegments.count( pt1 ) == 0 )
2930 {
2931 // we are only interested in vertical or horizontal segments
2932 if( pt0.x == pt1.x || pt0.y == pt1.y )
2933 {
2934 uniqueSegments.insert( { pt0, poly } );
2935 uniqueSegments.insert( { pt1, poly } );
2936 }
2937 }
2938 }
2939 }
2940
2941 LIB_PINS pins;
2942 aSymbolToFix->GetPins( pins, aGateNumber );
2943
2944 for( auto& pin : pins )
2945 {
2946 auto setPinOrientation =
2947 [&]( const EDA_ANGLE& aAngle )
2948 {
2949 EDA_ANGLE angle( aAngle );
2950 angle.Normalize180();
2951
2952 if( angle >= -ANGLE_45 && angle <= ANGLE_45 )
2953 pin->SetOrientation( 'R' ); // 0 degrees
2954 else if( angle >= ANGLE_45 && angle <= ANGLE_135 )
2955 pin->SetOrientation( 'U' ); // 90 degrees
2956 else if( angle >= ANGLE_135 || angle <= -ANGLE_135 )
2957 pin->SetOrientation( 'L' ); // 180 degrees
2958 else
2959 pin->SetOrientation( 'D' ); // -90 degrees
2960 };
2961
2962 if( uniqueSegments.count( pin->GetPosition() ) )
2963 {
2964 SHAPE_LINE_CHAIN& poly = uniqueSegments.at( pin->GetPosition() );
2965
2966 VECTOR2I otherPt = poly.CPoint( 0 );
2967
2968 if( otherPt == pin->GetPosition() )
2969 otherPt = poly.CPoint( 1 );
2970
2971 VECTOR2I vec( otherPt - pin->GetPosition() );
2972
2973 pin->SetLength( vec.EuclideanNorm() );
2974 setPinOrientation( EDA_ANGLE( vec ) );
2975 }
2976 }
2977}
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:242
SHAPE_T GetShape() const
Definition: eda_shape.h:110
int GetUnit() const
Definition: lib_item.h:272
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:502
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:753
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:424
static constexpr EDA_ANGLE & ANGLE_135
Definition: eda_angle.h:426
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:55
@ LIB_SHAPE_T
Definition: typeinfo.h:191
const int LexicographicalCompare(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
Definition: vector2d.h:558
VECTOR2< int > VECTOR2I
Definition: vector2d.h:607

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 1404 of file cadstar_archive_parser.h.

1405 {
1406 return aRefName
1407 + ( ( aAlternateName.size() > 0 ) ? ( wxT( " (" ) + aAlternateName + wxT( ")" ) )
1408 : wxT( "" ) );
1409 }

Referenced by loadSymDefIntoLibrary().

◆ getAngle()

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

Definition at line 258 of file cadstar_sch_archive_loader.h.

259 {
260 // CADSTAR v6 (which outputted Schematic Format Version 8) and earlier used 1/10 degree
261 // as the unit for angles/orientations. It is assumed that CADSTAR version 7 (i.e. Schematic
262 // Format Version 9 and later) is the version that introduced 1/1000 degree for angles.
263 if( Header.Format.Version > 8 )
264 {
265 return EDA_ANGLE( (double) aCadstarAngle / 1000.0, DEGREES_T );
266 }
267 else
268 {
269 return EDA_ANGLE( (double) aCadstarAngle, TENTHS_OF_A_DEGREE_T );
270 }
271 }
@ 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 273 of file cadstar_sch_archive_loader.h.

274 {
275 // CADSTAR v6 (which outputted Schematic Format Version 8) and earlier used 1/10 degree
276 // as the unit for angles/orientations. It is assumed that CADSTAR version 7 (i.e. Schematic
277 // Format Version 9 and later) is the version that introduced 1/1000 degree for angles.
278 if( Header.Format.Version > 8 )
279 {
280 return KiROUND( aAngle.AsDegrees() * 1000.0 );
281 }
282 else
283 {
284 return aAngle.AsTenthsOfADegree();
285 }
286 }
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 1861 of file cadstar_sch_archive_loader.cpp.

1863{
1864 int compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_0;
1865
1866 EDA_ANGLE oDeg = aOrientAngle;
1867 oDeg.Normalize180();
1868
1869 if( oDeg >= -ANGLE_45 && oDeg <= ANGLE_45 )
1870 {
1871 compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_0;
1872 aReturnedOrientation = ANGLE_0;
1873 }
1874 else if( oDeg >= ANGLE_45 && oDeg <= ANGLE_135 )
1875 {
1876 compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_90;
1877 aReturnedOrientation = ANGLE_90;
1878 }
1879 else if( oDeg >= ANGLE_135 || oDeg <= -ANGLE_135 )
1880 {
1881 compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_180;
1882 aReturnedOrientation = ANGLE_180;
1883 }
1884 else
1885 {
1886 compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_270;
1887 aReturnedOrientation = ANGLE_270;
1888 }
1889
1890 return compOrientation;
1891}
EDA_ANGLE Normalize180()
Definition: eda_angle.h:282
static constexpr EDA_ANGLE & ANGLE_180
Definition: eda_angle.h:427
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:425
static constexpr EDA_ANGLE & ANGLE_0
Definition: eda_angle.h:423
static constexpr EDA_ANGLE & ANGLE_270
Definition: eda_angle.h:428
@ 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, wxSize > CADSTAR_SCH_ARCHIVE_LOADER::getFigureExtentsKiCad ( const FIGURE aCadstarFigure)
private

Definition at line 2981 of file cadstar_sch_archive_loader.cpp.

2982{
2983 VECTOR2I upperLeft( Assignments.Settings.DesignLimit.x, 0 );
2984 VECTOR2I lowerRight( 0, Assignments.Settings.DesignLimit.y );
2985
2986 for( const VERTEX& v : aCadstarFigure.Shape.Vertices )
2987 {
2988 if( upperLeft.x > v.End.x )
2989 upperLeft.x = v.End.x;
2990
2991 if( upperLeft.y < v.End.y )
2992 upperLeft.y = v.End.y;
2993
2994 if( lowerRight.x < v.End.x )
2995 lowerRight.x = v.End.x;
2996
2997 if( lowerRight.y > v.End.y )
2998 lowerRight.y = v.End.y;
2999 }
3000
3001 for( CUTOUT cutout : aCadstarFigure.Shape.Cutouts )
3002 {
3003 for( const VERTEX& v : aCadstarFigure.Shape.Vertices )
3004 {
3005 if( upperLeft.x > v.End.x )
3006 upperLeft.x = v.End.x;
3007
3008 if( upperLeft.y < v.End.y )
3009 upperLeft.y = v.End.y;
3010
3011 if( lowerRight.x < v.End.x )
3012 lowerRight.x = v.End.x;
3013
3014 if( lowerRight.y > v.End.y )
3015 lowerRight.y = v.End.y;
3016 }
3017 }
3018
3019 VECTOR2I upperLeftKiCad = getKiCadPoint( upperLeft );
3020 VECTOR2I lowerRightKiCad = getKiCadPoint( lowerRight );
3021
3022 VECTOR2I size = lowerRightKiCad - upperLeftKiCad;
3023
3024 return { upperLeftKiCad, wxSize( abs( size.x ), abs( size.y ) ) };
3025}
VECTOR2I getKiCadPoint(const VECTOR2I &aCadstarPoint)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:412
@ 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 245 of file cadstar_sch_archive_loader.h.

246 {
247 int mod = aCadstarLength % KiCadUnitDivider;
248 int absmod = sign( mod ) * mod;
249 int offset = 0;
250
251 // Round half-way cases away from zero
252 if( absmod >= KiCadUnitDivider / 2 )
253 offset = sign( aCadstarLength );
254
255 return ( aCadstarLength / KiCadUnitDivider ) + offset;
256 }
int KiCadUnitDivider
Use this value to convert units in this CSA file to KiCad units.
int sign(T val)
Definition: util.h:111

References CADSTAR_SCH_ARCHIVE_PARSER::KiCadUnitDivider, and sign().

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

◆ getKiCadLibraryPoint()

wxPoint CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLibraryPoint ( const wxPoint &  aCadstarPoint,
const wxPoint &  aCadstarCentre 
)
private

Definition at line 3039 of file cadstar_sch_archive_loader.cpp.

3041{
3042 wxPoint retval;
3043
3044 retval.x = getKiCadLength( aCadstarPoint.x - aCadstarCentre.x );
3045 retval.y = getKiCadLength( aCadstarPoint.y - aCadstarCentre.y );
3046
3047 return retval;
3048}

References getKiCadLength().

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

◆ getKiCadPinType()

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

Definition at line 2508 of file cadstar_sch_archive_loader.cpp.

2509{
2510 switch( aPinType )
2511 {
2512 case PART::PIN_TYPE::UNCOMMITTED: return ELECTRICAL_PINTYPE::PT_PASSIVE;
2513 case PART::PIN_TYPE::INPUT: return ELECTRICAL_PINTYPE::PT_INPUT;
2514 case PART::PIN_TYPE::OUTPUT_OR: return ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR;
2515 case PART::PIN_TYPE::OUTPUT_NOT_OR: return ELECTRICAL_PINTYPE::PT_OUTPUT;
2516 case PART::PIN_TYPE::OUTPUT_NOT_NORM_OR: return ELECTRICAL_PINTYPE::PT_OUTPUT;
2517 case PART::PIN_TYPE::POWER: return ELECTRICAL_PINTYPE::PT_POWER_IN;
2518 case PART::PIN_TYPE::GROUND: return ELECTRICAL_PINTYPE::PT_POWER_IN;
2519 case PART::PIN_TYPE::TRISTATE_BIDIR: return ELECTRICAL_PINTYPE::PT_BIDI;
2520 case PART::PIN_TYPE::TRISTATE_INPUT: return ELECTRICAL_PINTYPE::PT_INPUT;
2521 case PART::PIN_TYPE::TRISTATE_DRIVER: return ELECTRICAL_PINTYPE::PT_OUTPUT;
2522 }
2523
2525}
@ 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 2799 of file cadstar_sch_archive_loader.cpp.

2800{
2801 SCH_TEXT* kiTxt = new SCH_TEXT();
2802
2803 kiTxt->SetParent( m_schematic ); // set to the schematic for now to avoid asserts
2804 kiTxt->SetPosition( getKiCadPoint( aCadstarTextElement.Position ) );
2805 kiTxt->SetText( aCadstarTextElement.Text );
2806
2807 applyTextSettings( kiTxt,
2808 aCadstarTextElement.TextCodeID,
2809 aCadstarTextElement.Alignment,
2810 aCadstarTextElement.Justification,
2811 aCadstarTextElement.OrientAngle,
2812 aCadstarTextElement.Mirror );
2813
2814 return kiTxt;
2815}
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:115
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_text.h:202

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 2527 of file cadstar_sch_archive_loader.cpp.

2528{
2529 if( aCadstarGateID.IsEmpty() )
2530 return 1;
2531
2532 return (int) aCadstarGateID.Upper().GetChar( 0 ) - (int) wxUniChar( 'A' ) + 1;
2533}

Referenced by loadSchematicSymbol(), and loadSymDefIntoLibrary().

◆ getLineStyle()

PLOT_DASH_TYPE CADSTAR_SCH_ARCHIVE_LOADER::getLineStyle ( const LINECODE_ID aCadstarLineCodeID)
private

Definition at line 2420 of file cadstar_sch_archive_loader.cpp.

2421{
2422 wxCHECK( Assignments.Codedefs.LineCodes.find( aCadstarLineCodeID )
2425
2426 // clang-format off
2427 switch( Assignments.Codedefs.LineCodes.at( aCadstarLineCodeID ).Style )
2428 {
2431 case LINESTYLE::DASHDOTDOT: return PLOT_DASH_TYPE::DASHDOT; //TODO: update in future
2434 default: return PLOT_DASH_TYPE::DEFAULT;
2435 }
2436 // clang-format on
2437
2438 return PLOT_DASH_TYPE();
2439}
PLOT_DASH_TYPE
Dashed line types.
Definition: stroke_params.h:47
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 loadGraphicStaightSegment().

◆ getLineThickness()

int CADSTAR_SCH_ARCHIVE_LOADER::getLineThickness ( const LINECODE_ID aCadstarLineCodeID)
private

Definition at line 2410 of file cadstar_sch_archive_loader.cpp.

2411{
2412 wxCHECK( Assignments.Codedefs.LineCodes.find( aCadstarLineCodeID )
2414 Mils2iu( DEFAULT_WIRE_WIDTH_MILS ) );
2415
2416 return getKiCadLength( Assignments.Codedefs.LineCodes.at( aCadstarLineCodeID ).Width );
2417}
#define DEFAULT_WIRE_WIDTH_MILS
The default bus width in mils. (can be changed in preference menu)

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

Referenced by loadBusses(), loadGraphicStaightSegment(), loadNets(), 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 1895 of file cadstar_sch_archive_loader.cpp.

1897{
1898 // clang-format off
1899 auto logUnknownNetElementError =
1900 [&]()
1901 {
1902 m_reporter->Report( wxString::Format( _( "Net %s references unknown net element %s. "
1903 "The net was not properly loaded and may "
1904 "require manual fixing." ),
1905 getNetName( aNet ),
1906 aNetElementID ),
1908
1909 return POINT();
1910 };
1911 // clang-format on
1912
1913 if( aNetElementID.Contains( "J" ) ) // Junction
1914 {
1915 if( aNet.Junctions.find( aNetElementID ) == aNet.Junctions.end() )
1916 return logUnknownNetElementError();
1917
1918 return aNet.Junctions.at( aNetElementID ).Location;
1919 }
1920 else if( aNetElementID.Contains( "P" ) ) // Terminal/Pin of a symbol
1921 {
1922 if( aNet.Terminals.find( aNetElementID ) == aNet.Terminals.end() )
1923 return logUnknownNetElementError();
1924
1925 SYMBOL_ID symid = aNet.Terminals.at( aNetElementID ).SymbolID;
1926 TERMINAL_ID termid = aNet.Terminals.at( aNetElementID ).TerminalID;
1927
1928 if( Schematic.Symbols.find( symid ) == Schematic.Symbols.end() )
1929 return logUnknownNetElementError();
1930
1931 SYMBOL sym = Schematic.Symbols.at( symid );
1932 SYMDEF_ID symdefid = sym.SymdefID;
1933 VECTOR2I symbolOrigin = sym.Origin;
1934
1935 if( Library.SymbolDefinitions.find( symdefid ) == Library.SymbolDefinitions.end() )
1936 return logUnknownNetElementError();
1937
1938 VECTOR2I libpinPosition =
1939 Library.SymbolDefinitions.at( symdefid ).Terminals.at( termid ).Position;
1940 VECTOR2I libOrigin = Library.SymbolDefinitions.at( symdefid ).Origin;
1941
1942 VECTOR2I pinOffset = libpinPosition - libOrigin;
1943 pinOffset.x = ( pinOffset.x * sym.ScaleRatioNumerator ) / sym.ScaleRatioDenominator;
1944 pinOffset.y = ( pinOffset.y * sym.ScaleRatioNumerator ) / sym.ScaleRatioDenominator;
1945
1946 VECTOR2I pinPosition = symbolOrigin + pinOffset;
1947 EDA_ANGLE compAngle = getAngle( sym.OrientAngle );
1948
1949 if( sym.Mirror )
1950 pinPosition.x = ( 2 * symbolOrigin.x ) - pinPosition.x;
1951
1952 EDA_ANGLE adjustedOrientation;
1953 getComponentOrientation( compAngle, adjustedOrientation );
1954
1955 RotatePoint( pinPosition, symbolOrigin, -adjustedOrientation );
1956
1957 POINT retval;
1958 retval.x = pinPosition.x;
1959 retval.y = pinPosition.y;
1960
1961 return retval;
1962 }
1963 else if( aNetElementID.Contains( "BT" ) ) // Bus Terminal
1964 {
1965 if( aNet.BusTerminals.find( aNetElementID ) == aNet.BusTerminals.end() )
1966 return logUnknownNetElementError();
1967
1968 return aNet.BusTerminals.at( aNetElementID ).SecondPoint;
1969 }
1970 else if( aNetElementID.Contains( "BLKT" ) ) // Block Terminal (sheet hierarchy connection)
1971 {
1972 if( aNet.BlockTerminals.find( aNetElementID ) == aNet.BlockTerminals.end() )
1973 return logUnknownNetElementError();
1974
1975 BLOCK_ID blockid = aNet.BlockTerminals.at( aNetElementID ).BlockID;
1976 TERMINAL_ID termid = aNet.BlockTerminals.at( aNetElementID ).TerminalID;
1977
1978 if( Schematic.Blocks.find( blockid ) == Schematic.Blocks.end() )
1979 return logUnknownNetElementError();
1980
1981 return Schematic.Blocks.at( blockid ).Terminals.at( termid ).Position;
1982 }
1983 else if( aNetElementID.Contains( "D" ) ) // Dangler
1984 {
1985 if( aNet.Danglers.find( aNetElementID ) == aNet.Danglers.end() )
1986 return logUnknownNetElementError();
1987
1988 return aNet.Danglers.at( aNetElementID ).Position;
1989 }
1990 else
1991 {
1992 return logUnknownNetElementError();
1993 }
1994
1995 return POINT();
1996}
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 1999 of file cadstar_sch_archive_loader.cpp.

2000{
2001 wxString netname = aNet.Name;
2002
2003 if( netname.IsEmpty() )
2004 netname = wxString::Format( "$%ld", aNet.SignalNum );
2005
2006 return netname;
2007}

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 2579 of file cadstar_archive_parser.cpp.

2580{
2581 XNODE* childNodes = aNode->GetChildren();
2582 long retval = 0;
2583
2584 for( ; childNodes; childNodes = childNodes->GetNext() )
2585 retval++;
2586
2587 return retval;
2588}
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 2591 of file cadstar_archive_parser.cpp.

2592{
2593 XNODE* level1Node = aRootNode->GetChildren();
2594 long retval = 0;
2595
2596 for( ; level1Node; level1Node = level1Node->GetNext() )
2597 {
2598 for( wxString childNodeName : aSubNodeChildrenToCount )
2599 {
2600 if( level1Node->GetName() == childNodeName )
2601 retval += GetNumberOfChildNodes( level1Node );
2602 }
2603
2604 retval++;
2605 }
2606
2607 return retval;
2608}
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 2472 of file cadstar_sch_archive_loader.cpp.

2473{
2474 wxCHECK( Parts.PartDefinitions.find( aCadstarPartID ) != Parts.PartDefinitions.end(), PART() );
2475
2476 return Parts.PartDefinitions.at( aCadstarPartID );
2477}
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 2492 of file cadstar_sch_archive_loader.cpp.

2494{
2495 for( std::pair<PART_DEFINITION_PIN_ID, PART::DEFINITION::PIN> pinPair :
2496 aCadstarPart.Definition.Pins )
2497 {
2498 PART::DEFINITION::PIN partPin = pinPair.second;
2499
2500 if( partPin.TerminalGate == aGateID && partPin.TerminalPin == aTerminalID )
2501 return partPin;
2502 }
2503
2504 return PART::DEFINITION::PIN();
2505}

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 3082 of file cadstar_sch_archive_loader.cpp.

3083{
3084 return sqrt( ( (double) aPoint.x * (double) aPoint.x )
3085 + ( (double) aPoint.y * (double) aPoint.y ) );
3086}

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 2481 of file cadstar_sch_archive_loader.cpp.

2482{
2483 wxCHECK( Assignments.Codedefs.RouteCodes.find( aCadstarRouteCodeID )
2485 ROUTECODE() );
2486
2487 return Assignments.Codedefs.RouteCodes.at( aCadstarRouteCodeID );
2488}
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 2818 of file cadstar_sch_archive_loader.cpp.

2821{
2822 LIB_SYMBOL* retval = new LIB_SYMBOL( *aSymbol );
2823
2824 if( aScalingFactorNumerator == aScalingFactorDenominator )
2825 return retval; // 1:1 scale, nothing to do
2826
2827 auto scaleLen =
2828 [&]( int aLength ) -> int
2829 {
2830 return( aLength * aScalingFactorNumerator ) / aScalingFactorDenominator;
2831 };
2832
2833 auto scalePt =
2834 [&]( VECTOR2I aCoord ) -> VECTOR2I
2835 {
2836 return VECTOR2I( scaleLen( aCoord.x ), scaleLen( aCoord.y ) );
2837 };
2838
2839 auto scaleSize =
2840 [&]( VECTOR2I aSize ) -> VECTOR2I
2841 {
2842 return VECTOR2I( scaleLen( aSize.x ), scaleLen( aSize.y ) );
2843 };
2844
2845 LIB_ITEMS_CONTAINER& items = retval->GetDrawItems();
2846
2847 for( LIB_ITEM& item : items )
2848 {
2849 switch( item.Type() )
2850 {
2852 {
2853 LIB_SHAPE& shape = static_cast<LIB_SHAPE&>( item );
2854
2855 if( shape.GetShape() == SHAPE_T::ARC )
2856 {
2857 shape.SetPosition( scalePt( shape.GetPosition() ) );
2858 shape.SetStart( scalePt( shape.GetStart() ) );
2859 shape.SetEnd( scalePt( shape.GetEnd() ) );
2860 }
2861 else if( shape.GetShape() == SHAPE_T::POLY )
2862 {
2863 SHAPE_LINE_CHAIN& poly = shape.GetPolyShape().Outline( 0 );
2864
2865 for( size_t ii = 0; ii < poly.GetPointCount(); ++ii )
2866 poly.SetPoint( ii, scalePt( (wxPoint) poly.CPoint( ii ) ) );
2867 }
2868 break;
2869 }
2870
2871 case KICAD_T::LIB_PIN_T:
2872 {
2873 LIB_PIN& pin = static_cast<LIB_PIN&>( item );
2874
2875 pin.SetPosition( scalePt( pin.GetPosition() ) );
2876 pin.SetLength( scaleLen( pin.GetLength() ) );
2877 break;
2878 }
2879
2881 {
2882 LIB_TEXT& txt = static_cast<LIB_TEXT&>( item );
2883
2884 txt.SetPosition( scalePt( txt.GetPosition() ) );
2885 txt.SetTextSize( scaleSize( txt.GetTextSize() ) );
2886 break;
2887 }
2888
2889 default:
2890 break;
2891 }
2892
2893 }
2894
2895 return retval;
2896}
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:140
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:119
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:115
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:144
void SetTextSize(const VECTOR2I &aNewSize)
Definition: eda_text.cpp:347
VECTOR2I GetTextSize() const
Definition: eda_text.h:197
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:62
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:194

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 2322 of file cadstar_sch_archive_loader.cpp.

2323{
2324 int i = 1;
2325
2326 for( LAYER_ID sheetID : Sheets.SheetOrder )
2327 {
2328 if( sheetID == aCadstarSheetID )
2329 return i;
2330
2331 ++i;
2332 }
2333
2334 return -1;
2335}

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 2552 of file cadstar_sch_archive_loader.cpp.

2553{
2555
2556 EDA_ANGLE oDeg = aOrientation;
2557 oDeg.Normalize180();
2558
2559 if( oDeg >= -ANGLE_45 && oDeg <= ANGLE_45 )
2560 spinStyle = TEXT_SPIN_STYLE::RIGHT; // 0deg
2561 else if( oDeg >= ANGLE_45 && oDeg <= ANGLE_135 )
2562 spinStyle = TEXT_SPIN_STYLE::UP; // 90deg
2563 else if( oDeg >= ANGLE_135 || oDeg <= -ANGLE_135 )
2564 spinStyle = TEXT_SPIN_STYLE::LEFT; // 180deg
2565 else
2566 spinStyle = TEXT_SPIN_STYLE::BOTTOM; // 270deg
2567
2568 return spinStyle;
2569}

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 2536 of file cadstar_sch_archive_loader.cpp.

2538{
2539 EDA_ANGLE orientation = getAngle( aCadstarOrientation );
2540 TEXT_SPIN_STYLE spinStyle = getSpinStyle( orientation );
2541
2542 if( aMirror )
2543 {
2544 spinStyle = spinStyle.RotateCCW();
2545 spinStyle = spinStyle.RotateCCW();
2546 }
2547
2548 return spinStyle;
2549}
TEXT_SPIN_STYLE RotateCCW()
Definition: sch_text.cpp:65

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 2378 of file cadstar_sch_archive_loader.cpp.

2380{
2381 // Do a case-insensitive comparison
2382 for( std::pair<SYMDEF_ID, SYMDEF_SCM> symPair : Library.SymbolDefinitions )
2383 {
2384 SYMDEF_ID id = symPair.first;
2385 SYMDEF_SCM symdef = symPair.second;
2386
2387 if( symdef.ReferenceName.Lower() == aSymdefName.Lower()
2388 && symdef.Alternate.Lower() == aSymDefAlternate.Lower() )
2389 {
2390 return id;
2391 }
2392 }
2393
2394 return SYMDEF_ID();
2395}

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 2443 of file cadstar_sch_archive_loader.cpp.

2444{
2445 wxCHECK( Assignments.Codedefs.TextCodes.find( aCadstarTextCodeID )
2447 TEXTCODE() );
2448
2449 return Assignments.Codedefs.TextCodes.at( aCadstarTextCodeID );
2450}
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 2453 of file cadstar_sch_archive_loader.cpp.

2454{
2455 TEXTCODE txtCode = getTextCode( aCadstarTextCodeID );
2456
2457 return KiROUND( (double) getKiCadLength( txtCode.Height ) * TXT_HEIGHT_RATIO );
2458}

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 2451 of file cadstar_archive_parser.cpp.

2453{
2454 long retVal;
2455 bool success = GetXmlAttributeIDString( aNode, aID, aIsRequired ).ToLong( &retVal );
2456
2457 if( !success )
2458 {
2459 if( aIsRequired )
2460 THROW_PARSING_IO_ERROR( std::to_string( aID ), aNode->GetName() );
2461 else
2462 return UNDEFINED_VALUE;
2463 }
2464
2465 return retVal;
2466}
#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 2432 of file cadstar_archive_parser.cpp.

2434{
2435 wxString attrName, retVal;
2436 attrName = "attr";
2437 attrName << aID;
2438
2439 if( !aNode->GetAttribute( attrName, &retVal ) )
2440 {
2441 if( aIsRequired )
2442 THROW_MISSING_PARAMETER_IO_ERROR( std::to_string( aID ), aNode->GetName() );
2443 else
2444 return wxEmptyString;
2445 }
2446
2447 return retVal;
2448}
#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 2611 of file cadstar_archive_parser.cpp.

2612{
2613 wxString escapedText = aCadstarString;
2614
2615 escapedText.Replace( wxT( "'" ), wxT( "~" ) );
2616
2617 return ConvertToNewOverbarNotation( escapedText );
2618}
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 2301 of file cadstar_archive_parser.cpp.

2302{
2303 wxString result;
2304 int numAttributes = 0;
2305
2306 if( aNode->GetAttribute( wxT( "numAttributes" ), &result ) )
2307 {
2308 numAttributes = wxAtoi( result );
2309 aNode->DeleteAttribute( wxT( "numAttributes" ) );
2310 ++numAttributes;
2311 }
2312
2313 aNode->AddAttribute( wxT( "numAttributes" ), wxString::Format( wxT( "%i" ), numAttributes ) );
2314
2315 wxString paramName = wxT( "attr" );
2316 paramName << numAttributes;
2317
2318 aNode->AddAttribute( paramName, aValue );
2319}

References Format().

Referenced by CADSTAR_ARCHIVE_PARSER::LoadArchiveFile().

◆ isAttributeVisible()

bool CADSTAR_SCH_ARCHIVE_LOADER::isAttributeVisible ( const ATTRIBUTE_ID aCadstarAttributeID)
private

Definition at line 2398 of file cadstar_sch_archive_loader.cpp.

2399{
2400 // Use CADSTAR visibility settings to determine if an attribute is visible
2401 if( AttrColors.AttributeColors.find( aCadstarAttributeID ) != AttrColors.AttributeColors.end() )
2402 {
2403 return AttrColors.AttributeColors.at( aCadstarAttributeID ).IsVisible;
2404 }
2405
2406 return false; // If there is no visibility setting, assume not displayed
2407}
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 54 of file cadstar_sch_archive_loader.cpp.

57{
59 m_progressReporter->SetNumPhases( 3 ); // (0) Read file, (1) Parse file, (2) Load file
60
61 Parse();
62
63 LONGPOINT designLimit = Assignments.Settings.DesignLimit;
64
65 //Note: can't use getKiCadPoint() due VECTOR2I being int - need long long to make the check
66 long long designSizeXkicad = (long long) designLimit.x / KiCadUnitDivider;
67 long long designSizeYkicad = (long long) designLimit.y / KiCadUnitDivider;
68
69 // Max size limited by the positive dimension of VECTOR2I (which is an int)
70 constexpr long long maxDesignSizekicad = std::numeric_limits<int>::max();
71
72 if( designSizeXkicad > maxDesignSizekicad || designSizeYkicad > maxDesignSizekicad )
73 {
75 _( "The design is too large and cannot be imported into KiCad. \n"
76 "Please reduce the maximum design size in CADSTAR by navigating to: \n"
77 "Design Tab -> Properties -> Design Options -> Maximum Design Size. \n"
78 "Current Design size: %.2f, %.2f millimeters. \n"
79 "Maximum permitted design size: %.2f, %.2f millimeters.\n" ),
80 (double) designSizeXkicad / SCH_IU_PER_MM,
81 (double) designSizeYkicad / SCH_IU_PER_MM,
82 (double) maxDesignSizekicad / SCH_IU_PER_MM,
83 (double) maxDesignSizekicad / SCH_IU_PER_MM ) );
84 }
85
86 // Assume the center at 0,0 since we are going to be translating the design afterwards anyway
87 m_designCenter = { 0, 0 };
88
89 m_schematic = aSchematic;
90 m_rootSheet = aRootSheet;
91 m_plugin = aSchPlugin;
92 m_libraryFileName = aLibraryFileName;
93
95 {
97 long numSteps = 11; // one step for each of below functions + one at the end of import
98
99 // Step 4 is by far the longest - add granularity in reporting
100 numSteps += Parts.PartDefinitions.size();
101
103 }
104
105 loadTextVariables(); // Load text variables right at the start to ensure bounding box
106 // calculations work correctly for text items
107 checkPoint(); // Step 1
108 loadSheets();
109 checkPoint(); // Step 2
111 checkPoint(); // Step 3
113 checkPoint(); // Step 4, Subdivided into extra steps
115 checkPoint(); // Step 5
116 loadBusses();
117 checkPoint(); // Step 6
118 loadNets();
119 checkPoint(); // Step 7
120 loadFigures();
121 checkPoint(); // Step 8
122 loadTexts();
123 checkPoint(); // Step 9
125 checkPoint(); // Step 10
126
127 if( Schematic.VariantHierarchy.Variants.size() > 0 )
128 {
129 m_reporter->Report( wxString::Format( _( "The CADSTAR design contains variants which has "
130 "no KiCad equivalent. Only the master variant "
131 "('%s') was loaded." ),
132 Schematic.VariantHierarchy.Variants.at( "V0" ).Name ),
134 }
135
136 if( Schematic.Groups.size() > 0 )
137 {
138 m_reporter->Report( _( "The CADSTAR design contains grouped items which has no KiCad "
139 "equivalent. Any grouped items have been ungrouped." ),
141 }
142
143 if( Schematic.ReuseBlocks.size() > 0 )
144 {
145 m_reporter->Report( _( "The CADSTAR design contains re-use blocks which has no KiCad "
146 "equivalent. The re-use block information has been discarded during "
147 "the import." ),
149 }
150
151
152 // For all sheets, center all elements and re calculate the page size:
153 for( std::pair<LAYER_ID, SCH_SHEET*> sheetPair : m_sheetMap )
154 {
155 SCH_SHEET* sheet = sheetPair.second;
156
157 // Calculate the new sheet size.
158 EDA_RECT sheetBoundingBox;
159
160 for( auto item : sheet->GetScreen()->Items() )
161 {
162 EDA_RECT bbox;
163
164 // Only use the visible fields of the symbols to calculate their bounding box
165 // (hidden fields could be very long and artificially enlarge the sheet bounding box)
166 if( item->Type() == SCH_SYMBOL_T )
167 {
168 SCH_SYMBOL* comp = static_cast<SCH_SYMBOL*>( item );
169 bbox = comp->GetBodyAndPinsBoundingBox();
170
171 for( const SCH_FIELD& field : comp->GetFields() )
172 {
173 if( field.IsVisible() )
174 bbox.Merge( field.GetBoundingBox() );
175 }
176 }
177 else if( item->Type() == SCH_TEXT_T )
178 {
179 SCH_TEXT* txtItem = static_cast<SCH_TEXT*>( item );
180 wxString txt = txtItem->GetText();
181
182 if( txt.Contains( "${" ) )
183 continue; // We can't calculate bounding box of text items with variables
184 else
185 bbox = txtItem->GetBoundingBox();
186 }
187 else
188 {
189 bbox = item->GetBoundingBox();
190 }
191
192 sheetBoundingBox.Merge( bbox );
193 }
194
195 // Find the working grid of the original CADSTAR design
197
202
204
205 auto roundToNearestGrid =
206 [&]( int aNumber ) -> int
207 {
208 int error = aNumber % grid;
209 int absError = sign( error ) * error;
210
211 if( absError > ( grid / 2 ) )
212 return aNumber + ( sign( error ) * grid ) - error;
213 else
214 return aNumber - error;
215 };
216
217 // When exporting to pdf, CADSTAR applies a margin of 3% of the longest dimension (height
218 // or width) to all 4 sides (top, bottom, left right). For the import, we are also rounding
219 // the margin to the nearest grid, ensuring all items remain on the grid.
220 wxSize targetSheetSize = (wxSize)sheetBoundingBox.GetSize();
221 int longestSide = std::max( targetSheetSize.x, targetSheetSize.y );
222 int margin = ( (double) longestSide * 0.03 );
223 margin = roundToNearestGrid( margin );
224 targetSheetSize.IncBy( margin * 2, margin * 2 );
225
226 // Update page size always
227 PAGE_INFO pageInfo = sheet->GetScreen()->GetPageSettings();
228 pageInfo.SetWidthMils( Iu2Mils( targetSheetSize.x ) );
229 pageInfo.SetHeightMils( Iu2Mils( targetSheetSize.y ) );
230
231 // Set the new sheet size.
232 sheet->GetScreen()->SetPageSettings( pageInfo );
233
234 wxSize pageSizeIU = sheet->GetScreen()->GetPageSettings().GetSizeIU();
235 VECTOR2I sheetcentre( pageSizeIU.x / 2, pageSizeIU.y / 2 );
236 VECTOR2I itemsCentre = sheetBoundingBox.Centre();
237
238 // round the translation to nearest point on the grid
239 VECTOR2I translation = sheetcentre - itemsCentre;
240 translation.x = roundToNearestGrid( translation.x );
241 translation.y = roundToNearestGrid( translation.y );
242
243 // Translate the items.
244 std::vector<SCH_ITEM*> allItems;
245
246 std::copy( sheet->GetScreen()->Items().begin(), sheet->GetScreen()->Items().end(),
247 std::back_inserter( allItems ) );
248
249 for( SCH_ITEM* item : allItems )
250 {
251 item->Move( translation );
252 item->ClearFlags();
253 sheet->GetScreen()->Update( item );
254 }
255 }
256
257 checkPoint();
258
259 m_reporter->Report( _( "The CADSTAR design has been imported successfully.\n"
260 "Please review the import errors and warnings (if any)." ) );
261}
@ 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.
void Merge(const EDA_RECT &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: eda_rect.cpp:426
const VECTOR2I GetSize() const
Definition: eda_rect.h:105
VECTOR2I Centre() const
Definition: eda_rect.h:69
iterator end()
Returns a read/write iterator that points to one past the last element in the EE_RTREE.
Definition: sch_rtree.h:282
iterator begin()
Returns a read/write iterator that points to the first element in the EE_RTREE N.B.
Definition: sch_rtree.h:273
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:243
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:257
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:50
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:145
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:129
void Update(SCH_ITEM *aItem)
Update aItem's bounding box in the tree.
Definition: sch_screen.cpp:266
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:130
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:107
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:55
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:102
Schematic symbol object.
Definition: sch_symbol.h:79
EDA_RECT 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:782
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_text.cpp:314
constexpr double SCH_IU_PER_MM
@ RPT_SEVERITY_WARNING
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
@ SCH_SYMBOL_T
Definition: typeinfo.h:147

References _, CADSTAR_SCH_ARCHIVE_PARSER::Assignments, EE_RTREE::begin(), PROGRESS_REPORTER::BeginPhase(), EDA_RECT::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(), EDA_RECT::GetSize(), EDA_TEXT::GetText(), grid, CADSTAR_SCH_ARCHIVE_PARSER::ASSIGNMENTS_SCM::Grids, CADSTAR_SCH_ARCHIVE_PARSER::CADSTAR_SCHEMATIC::Groups, SCH_SCREEN::Items(), 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, EDA_RECT::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, 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::GRIDS::WorkingGrid, 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 2322 of file cadstar_archive_parser.cpp.

2324{
2325 KEYWORD emptyKeywords[1] = {};
2326 XNODE * iNode = nullptr, *cNode = nullptr;
2327 int tok;
2328 bool cadstarFileCheckDone = false;
2329 wxString str;
2330 wxCSConv win1252( wxT( "windows-1252" ) );
2331 wxMBConv* conv = &win1252; // Initial testing suggests file encoding to be Windows-1252
2332 // More samples required.
2333
2334 // Open the file and get the file size
2335 FILE* fp = wxFopen( aFileName, wxT( "rt" ) );
2336
2337 if( !fp )
2338 THROW_IO_ERROR( wxString::Format( _( "Cannot open file '%s'" ), aFileName ) );
2339
2340 fseek( fp, 0L, SEEK_END );
2341 long fileSize = ftell( fp );
2342 rewind( fp );
2343
2344 DSNLEXER lexer( emptyKeywords, 0, nullptr, fp, aFileName );
2345
2346 auto currentProgress = [&]() -> double
2347 {
2348 return static_cast<double>( ftell( fp ) ) / fileSize;
2349 };
2350
2351 double previousReportedProgress = -1.0;
2352
2353 while( ( tok = lexer.NextTok() ) != DSN_EOF )
2354 {
2355 if( aProgressReporter && ( currentProgress() - previousReportedProgress ) > 0.01 )
2356 {
2357 if( !aProgressReporter->KeepRefreshing() )
2358 THROW_IO_ERROR( _( "File import cancelled by user." ) );
2359
2360 aProgressReporter->SetCurrentProgress( currentProgress() );
2361 previousReportedProgress = currentProgress();
2362 }
2363
2364 if( tok == DSN_RIGHT )
2365 {
2366 cNode = iNode;
2367 if( cNode )
2368 {
2369 iNode = cNode->GetParent();
2370 }
2371 else
2372 {
2373 //too many closing brackets
2374 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2375 }
2376 }
2377 else if( tok == DSN_LEFT )
2378 {
2379 tok = lexer.NextTok();
2380 str = wxString( lexer.CurText(), *conv );
2381 cNode = new XNODE( wxXML_ELEMENT_NODE, str );
2382
2383 if( iNode )
2384 {
2385 //we will add it as attribute as well as child node
2386 InsertAttributeAtEnd( iNode, str );
2387 iNode->AddChild( cNode );
2388 }
2389 else if( !cadstarFileCheckDone )
2390 {
2391 if( cNode->GetName() != aFileTypeIdentifier )
2392 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2393
2394 cadstarFileCheckDone = true;
2395 }
2396
2397 iNode = cNode;
2398 }
2399 else if( iNode )
2400 {
2401 str = wxString( lexer.CurText(), *conv );
2402 //Insert even if string is empty
2403 InsertAttributeAtEnd( iNode, str );
2404 }
2405 else
2406 {
2407 //not enough closing brackets
2408 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2409 }
2410 }
2411
2412 // Not enough closing brackets
2413 if( iNode != nullptr )
2414 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2415
2416 // Throw if no data was parsed
2417 if( cNode )
2418 return cNode;
2419 else
2420 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2421
2422 return nullptr;
2423}
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 727 of file cadstar_sch_archive_loader.cpp.

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

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

1180{
1181 for( std::pair<DOCUMENTATION_SYMBOL_ID, DOCUMENTATION_SYMBOL> docSymPair :
1183 {
1184 DOCUMENTATION_SYMBOL docSym = docSymPair.second;
1185
1186 if( Library.SymbolDefinitions.find( docSym.SymdefID ) == Library.SymbolDefinitions.end() )
1187 {
1188 m_reporter->Report( wxString::Format( _( "Documentation Symbol '%s' refers to symbol "
1189 "definition ID '%s' which does not exist in "
1190 "the library. The symbol was not loaded." ),
1191 docSym.ID,
1192 docSym.SymdefID ),
1194 continue;
1195 }
1196
1197 SYMDEF_SCM docSymDef = Library.SymbolDefinitions.at( docSym.SymdefID );
1198 VECTOR2I moveVector = getKiCadPoint( docSym.Origin ) - getKiCadPoint( docSymDef.Origin );
1199 EDA_ANGLE rotationAngle = getAngle( docSym.OrientAngle );
1200 double scalingFactor = (double) docSym.ScaleRatioNumerator
1201 / (double) docSym.ScaleRatioDenominator;
1202 VECTOR2I centreOfTransform = getKiCadPoint( docSymDef.Origin );
1203 bool mirrorInvert = docSym.Mirror;
1204
1205 for( std::pair<FIGURE_ID, FIGURE> figPair : docSymDef.Figures )
1206 {
1207 FIGURE fig = figPair.second;
1208
1209 loadFigure( fig, docSym.LayerID, LAYER_NOTES, moveVector, rotationAngle, scalingFactor,
1210 centreOfTransform, mirrorInvert );
1211 }
1212
1213 for( std::pair<TEXT_ID, TEXT> textPair : docSymDef.Texts )
1214 {
1215 TEXT txt = textPair.second;
1216
1217 txt.Mirror = ( txt.Mirror ) ? !mirrorInvert : mirrorInvert;
1218 txt.OrientAngle = docSym.OrientAngle - txt.OrientAngle;
1219
1220 SCH_TEXT* kiTxt = getKiCadSchText( txt );
1221
1222 VECTOR2I newPosition = applyTransform( kiTxt->GetPosition(), moveVector, rotationAngle,
1223 scalingFactor, centreOfTransform, mirrorInvert );
1224
1225 int newTxtWidth = KiROUND( kiTxt->GetTextWidth() * scalingFactor );
1226 int newTxtHeight = KiROUND( kiTxt->GetTextHeight() * scalingFactor );
1227 int newTxtThickness = KiROUND( kiTxt->GetTextThickness() * scalingFactor );
1228
1229 kiTxt->SetPosition( newPosition );
1230 kiTxt->SetTextWidth( newTxtWidth );
1231 kiTxt->SetTextHeight( newTxtHeight );
1232 kiTxt->SetTextThickness( newTxtThickness );
1233
1234 loadItemOntoKiCadSheet( docSym.LayerID, kiTxt );
1235 }
1236 }
1237}
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:203
int GetTextWidth() const
Definition: eda_text.h:200
int GetTextThickness() const
Definition: eda_text.h:120
VECTOR2I GetPosition() const override
Definition: sch_text.h:201
@ 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 2124 of file cadstar_sch_archive_loader.cpp.

2132{
2133 loadShapeVertices( aCadstarFigure.Shape.Vertices, aCadstarFigure.LineCodeID,
2134 aCadstarSheetIDOverride, aKiCadSchLayerID, aMoveVector, aRotation,
2135 aScalingFactor, aTransformCentre, aMirrorInvert );
2136
2137 for( CUTOUT cutout : aCadstarFigure.Shape.Cutouts )
2138 {
2139 loadShapeVertices( cutout.Vertices, aCadstarFigure.LineCodeID, aCadstarSheetIDOverride,
2140 aKiCadSchLayerID, aMoveVector, aRotation, aScalingFactor,
2141 aTransformCentre, aMirrorInvert );
2142 }
2143}
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 1156 of file cadstar_sch_archive_loader.cpp.

1157{
1158 for( std::pair<FIGURE_ID, FIGURE> figPair : Schematic.Figures )
1159 {
1160 FIGURE fig = figPair.second;
1161
1162 loadFigure( fig, fig.LayerID, LAYER_NOTES );
1163 }
1164}

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().

◆ loadGraphicStaightSegment()

void CADSTAR_SCH_ARCHIVE_LOADER::loadGraphicStaightSegment ( const VECTOR2I aStartPoint,
const VECTOR2I aEndPoint,
const LINECODE_ID aCadstarLineCodeID,
const LAYER_ID aCadstarSheetID,
const 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 2010 of file cadstar_sch_archive_loader.cpp.

2020{
2021 SCH_LINE* segment = new SCH_LINE();
2022
2023 segment->SetLayer( aKiCadSchLayerID );
2024 segment->SetLineWidth( KiROUND( getLineThickness( aCadstarLineCodeID ) * aScalingFactor ) );
2025 segment->SetLineStyle( getLineStyle( aCadstarLineCodeID ) );
2026
2027 //Apply transforms
2028 VECTOR2I startPoint = applyTransform( aStartPoint, aMoveVector, aRotation, aScalingFactor,
2029 aTransformCentre, aMirrorInvert );
2030 VECTOR2I endPoint = applyTransform( aEndPoint, aMoveVector, aRotation, aScalingFactor,
2031 aTransformCentre, aMirrorInvert );
2032
2033 segment->SetStartPoint( startPoint );
2034 segment->SetEndPoint( endPoint );
2035
2036 loadItemOntoKiCadSheet( aCadstarSheetID, segment );
2037}
PLOT_DASH_TYPE getLineStyle(const LINECODE_ID &aCadstarLineCodeID)
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:267

References applyTransform(), getLineStyle(), getLineThickness(), KiROUND(), loadItemOntoKiCadSheet(), SCH_LINE::SetEndPoint(), SCH_ITEM::SetLayer(), SCH_LINE::SetLineStyle(), SCH_LINE::SetLineWidth(), and SCH_LINE::SetStartPoint().

Referenced by loadShapeVertices().

◆ loadHierarchicalSheetPins()

void CADSTAR_SCH_ARCHIVE_LOADER::loadHierarchicalSheetPins ( )
private

Definition at line 318 of file cadstar_sch_archive_loader.cpp.

319{
320 for( std::pair<BLOCK_ID, BLOCK> blockPair : Schematic.Blocks )
321 {
322 BLOCK& block = blockPair.second;
323 LAYER_ID sheetID = "";
324
325 if( block.Type == BLOCK::TYPE::PARENT )
326 sheetID = block.LayerID;
327 else if( block.Type == BLOCK::TYPE::CHILD )
328 sheetID = block.AssocLayerID;
329 else
330 continue;
331
332 if( m_sheetMap.find( sheetID ) != m_sheetMap.end() )
333 {
334 SCH_SHEET* sheet = m_sheetMap.at( sheetID );
335
336 for( std::pair<TERMINAL_ID, TERMINAL> termPair : block.Terminals )
337 {
338 TERMINAL term = termPair.second;
339 wxString name = "YOU SHOULDN'T SEE THIS TEXT. THIS IS A BUG.";
340
341 SCH_HIERLABEL* sheetPin = nullptr;
342
343 if( block.Type == BLOCK::TYPE::PARENT )
344 sheetPin = new SCH_HIERLABEL();
345 else if( block.Type == BLOCK::TYPE::CHILD )
346 sheetPin = new SCH_SHEET_PIN( sheet );
347
348 sheetPin->SetText( name );
350 sheetPin->SetTextSpinStyle( getSpinStyle( term.OrientAngle, false ) );
351 sheetPin->SetPosition( getKiCadPoint( term.Position ) );
352
353 if( sheetPin->Type() == SCH_SHEET_PIN_T )
354 sheet->AddPin( (SCH_SHEET_PIN*) sheetPin );
355 else
356 sheet->GetScreen()->Append( sheetPin );
357
358 BLOCK_PIN_ID blockPinID = std::make_pair( block.ID, term.ID );
359 m_sheetPinMap.insert( { blockPinID, sheetPin } );
360 }
361 }
362 }
363}
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:1436
void SetShape(LABEL_FLAG_SHAPE aShape) override
Definition: sch_label.h:77
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:327
@ 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 2338 of file cadstar_sch_archive_loader.cpp.

2339{
2340 wxCHECK_MSG( aItem, /*void*/, "aItem is null" );
2341
2342 if( aCadstarSheetID == "ALL_SHEETS" )
2343 {
2344 SCH_ITEM* duplicateItem;
2345
2346 for( std::pair<LAYER_ID, SHEET_NAME> sheetPair : Sheets.SheetNames )
2347 {
2348 LAYER_ID sheetID = sheetPair.first;
2349 duplicateItem = aItem->Duplicate();
2350 m_sheetMap.at( sheetID )->GetScreen()->Append( aItem->Duplicate() );
2351 }
2352
2353 //Get rid of the extra copy:
2354 delete aItem;
2355 aItem = duplicateItem;
2356 }
2357 else if( aCadstarSheetID == "NO_SHEET" )
2358 {
2359 wxASSERT_MSG( false,
2360 "Trying to add an item to NO_SHEET? This might be a documentation symbol." );
2361 }
2362 else
2363 {
2364 if( m_sheetMap.find( aCadstarSheetID ) != m_sheetMap.end() )
2365 {
2366 m_sheetMap.at( aCadstarSheetID )->GetScreen()->Append( aItem );
2367 }
2368 else
2369 {
2370 delete aItem;
2371 wxASSERT_MSG( false, "Unknown Sheet ID." );
2372 }
2373 }
2374}
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(), loadGraphicStaightSegment(), and loadTexts().

◆ loadLibrarySymbolShapeVertices()

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

Definition at line 1628 of file cadstar_sch_archive_loader.cpp.

1633{
1634 const VERTEX* prev = &aCadstarVertices.at( 0 );
1635 const VERTEX* cur;
1636
1637 wxASSERT_MSG( prev->Type == VERTEX_TYPE::POINT, "First vertex should always be a point." );
1638
1639 for( size_t i = 1; i < aCadstarVertices.size(); i++ )
1640 {
1641 cur = &aCadstarVertices.at( i );
1642
1643 LIB_SHAPE* shape = nullptr;
1644 bool cw = false;
1645 wxPoint startPoint = getKiCadLibraryPoint( prev->End, aSymbolOrigin );
1646 wxPoint endPoint = getKiCadLibraryPoint( cur->End, aSymbolOrigin );
1647 wxPoint centerPoint;
1648
1650 || cur->Type == VERTEX_TYPE::CLOCKWISE_SEMICIRCLE )
1651 {
1652 centerPoint = ( startPoint + endPoint ) / 2;
1653 }
1654 else
1655 {
1656 centerPoint = getKiCadLibraryPoint( cur->Center, aSymbolOrigin );
1657 }
1658
1659
1660 switch( cur->Type )
1661 {
1662 case VERTEX_TYPE::POINT:
1663 shape = new LIB_SHAPE( aSymbol, SHAPE_T::POLY );
1664 shape->AddPoint( startPoint );
1665 shape->AddPoint( endPoint );
1666 break;
1667
1670 cw = true;
1672
1675 shape = new LIB_SHAPE( aSymbol, SHAPE_T::ARC );
1676
1677 shape->SetPosition( centerPoint );
1678
1679 if( cw )
1680 {
1681 shape->SetStart( endPoint );
1682 shape->SetEnd( startPoint );
1683 }
1684 else
1685 {
1686 shape->SetStart( startPoint );
1687 shape->SetEnd( endPoint );
1688 }
1689
1690 break;
1691 }
1692
1693 shape->SetUnit( aGateNumber );
1694 shape->SetStroke( STROKE_PARAMS( aLineThickness, PLOT_DASH_TYPE::SOLID ) );
1695 aSymbol->AddDrawItem( shape );
1696
1697 prev = cur;
1698 }
1699}
void SetUnit(int aUnit)
Definition: lib_item.h:271
void SetStroke(const STROKE_PARAMS &aStroke)
Definition: lib_shape.h:53
void AddPoint(const VECTOR2I &aPosition)
Definition: lib_shape.cpp:483
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:713
Simple container to manage line stroke parameters.
Definition: stroke_params.h:87

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 810 of file cadstar_sch_archive_loader.cpp.

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

367{
368 for( std::pair<PART_ID, PART> partPair : Parts.PartDefinitions )
369 {
370 PART_ID partID = partPair.first;
371 PART part = partPair.second;
372
373 wxString escapedPartName = EscapeString( part.Name, CTX_LIBID );
374 LIB_SYMBOL* kiPart = new LIB_SYMBOL( escapedPartName );
375
376 kiPart->SetUnitCount( part.Definition.GateSymbols.size() );
377 bool ok = true;
378
379 for( std::pair<GATE_ID, PART::DEFINITION::GATE> gatePair : part.Definition.GateSymbols )
380 {
381 GATE_ID gateID = gatePair.first;
382 PART::DEFINITION::GATE gate = gatePair.second;
383 SYMDEF_ID symbolID = getSymDefFromName( gate.Name, gate.Alternate );
384
385 if( symbolID.IsEmpty() )
386 {
387 m_reporter->Report( wxString::Format( _( "Part definition '%s' references symbol "
388 "'%s' (alternate '%s') which could not be "
389 "found in the symbol library. The part has "
390 "not been loaded into the KiCad library." ),
391 part.Name,
392 gate.Name,
393 gate.Alternate ),
395
396 ok = false;
397 break;
398 }
399
400 m_partSymbolsMap.insert( { { partID, gateID }, symbolID } );
401 loadSymDefIntoLibrary( symbolID, &part, gateID, kiPart );
402 }
403
404 if( ok && part.Definition.GateSymbols.size() != 0 )
405 {
406 ( *m_plugin )->SaveSymbol( m_libraryFileName.GetFullPath(), kiPart );
407
408 LIB_SYMBOL* loadedPart =
409 ( *m_plugin )->LoadSymbol( m_libraryFileName.GetFullPath(), kiPart->GetName() );
410
411 m_partMap.insert( { partID, loadedPart } );
412 }
413 else
414 {
415 if( part.Definition.GateSymbols.size() == 0 )
416 {
418 wxString::Format( _( "Part definition '%s' has an incomplete definition (no"
419 " symbol definitions are associated with it). The part"
420 " has not been loaded into the KiCad library." ),
421 part.Name ),
423 }
424
425 // Don't save in the library, but still keep it cached as some of the units might have
426 // been loaded correctly (saving us time later on), plus the part definition contains
427 // the part name, which is important to load
428 m_partMap.insert( { partID, kiPart } );
429 }
430
431 checkPoint();
432 }
433}
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:137
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 1716 of file cadstar_sch_archive_loader.cpp.

1719{
1720 LIB_ID libId( m_libraryFileName.GetName(), aKiCadPart.GetName() );
1721 int unit = getKiCadUnitNumberFromGate( aCadstarSymbol.GateID );
1722
1723 SCH_SHEET_PATH sheetpath;
1724 SCH_SHEET* kiSheet = m_sheetMap.at( aCadstarSymbol.LayerID );
1725 m_rootSheet->LocatePathOfScreen( kiSheet->GetScreen(), &sheetpath );
1726
1727 SCH_SYMBOL* symbol = new SCH_SYMBOL( aKiCadPart, libId, &sheetpath, unit );
1728
1729 if( aCadstarSymbol.IsComponent )
1730 {
1731 symbol->SetRef( &sheetpath, aCadstarSymbol.ComponentRef.Designator );
1732 }
1733
1734 symbol->SetPosition( getKiCadPoint( aCadstarSymbol.Origin ) );
1735
1736 EDA_ANGLE compAngle = getAngle( aCadstarSymbol.OrientAngle );
1737 int compOrientation = 0;
1738
1739 if( aCadstarSymbol.Mirror )
1740 {
1741 compAngle = -compAngle;
1742 compOrientation += SYMBOL_ORIENTATION_T::SYM_MIRROR_Y;
1743 }
1744
1745 compOrientation += getComponentOrientation( compAngle, aComponentOrientation );
1746 EDA_ANGLE test1( compAngle );
1747 EDA_ANGLE test2( aComponentOrientation );
1748
1749 if( test1.Normalize180() != test2.Normalize180() )
1750 {
1751 m_reporter->Report( wxString::Format( _( "Symbol '%s' is rotated by an angle of %.1f "
1752 "degrees in the original CADSTAR design but "
1753 "KiCad only supports rotation angles multiples "
1754 "of 90 degrees. The connecting wires will need "
1755 "manual fixing." ),
1756 aCadstarSymbol.ComponentRef.Designator,
1757 compAngle.AsDegrees() ),
1759 }
1760
1761 symbol->SetOrientation( compOrientation );
1762
1763 if( m_sheetMap.find( aCadstarSymbol.LayerID ) == m_sheetMap.end() )
1764 {
1765 m_reporter->Report( wxString::Format( _( "Symbol '%s' references sheet ID '%s' which does "
1766 "not exist in the design. The symbol was not "
1767 "loaded." ),
1768 aCadstarSymbol.ComponentRef.Designator,
1769 aCadstarSymbol.LayerID ),
1771
1772 delete symbol;
1773 return nullptr;
1774 }
1775
1776 wxString gate = ( aCadstarSymbol.GateID.IsEmpty() ) ? wxT( "A" ) : aCadstarSymbol.GateID;
1777 wxString partGateIndex = aCadstarSymbol.PartRef.RefID + gate;
1778
1779 //Handle pin swaps
1780 if( m_pinNumsMap.find( partGateIndex ) != m_pinNumsMap.end() )
1781 {
1782 TERMINAL_TO_PINNUM_MAP termNumMap = m_pinNumsMap.at( partGateIndex );
1783
1784 std::map<wxString, LIB_PIN*> pinNumToLibPinMap;
1785
1786 for( auto& term : termNumMap )
1787 {
1788 wxString pinNum = term.second;
1789 pinNumToLibPinMap.insert( { pinNum,
1790 symbol->GetLibSymbolRef()->GetPin( term.second ) } );
1791 }
1792
1793 auto replacePinNumber =
1794 [&]( wxString aOldPinNum, wxString aNewPinNum )
1795 {
1796 if( aOldPinNum == aNewPinNum )
1797 return;
1798
1799 LIB_PIN* libpin = pinNumToLibPinMap.at( aOldPinNum );
1800 libpin->SetNumber( HandleTextOverbar( aNewPinNum ) );
1801 };
1802
1803 //Older versions of Cadstar used pin numbers
1804 for( auto& pinPair : aCadstarSymbol.PinNumbers )
1805 {
1806 SYMBOL::PIN_NUM pin = pinPair.second;
1807
1808 replacePinNumber( termNumMap.at( pin.TerminalID ),
1809 wxString::Format( "%ld", pin.PinNum ) );
1810 }
1811
1812 //Newer versions of Cadstar use pin names
1813 for( auto& pinPair : aCadstarSymbol.PinNames )
1814 {
1815 SYMPINNAME_LABEL pin = pinPair.second;
1816 replacePinNumber( termNumMap.at( pin.TerminalID ), pin.NameOrLabel );
1817 }
1818
1819 symbol->UpdatePins();
1820 }
1821
1822 kiSheet->GetScreen()->Append( symbol );
1823
1824 return symbol;
1825}
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:52
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:125
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:717
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_symbol.h:666
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
Definition: sch_symbol.cpp:321
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:529
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:174
@ 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 436 of file cadstar_sch_archive_loader.cpp.

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

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 for( size_t ii = 1; ii < aCadstarVertices.size(); ii++ )
2057 {
2058 cur = &aCadstarVertices.at( ii );
2059
2060 VECTOR2I startPoint = getKiCadPoint( prev->End );
2061 VECTOR2I endPoint = getKiCadPoint( cur->End );
2062 VECTOR2I centerPoint = getKiCadPoint( cur->Center );
2063 bool cw = false;
2064
2066 || cur->Type == VERTEX_TYPE::CLOCKWISE_SEMICIRCLE )
2067 {
2068 centerPoint = ( startPoint + endPoint ) / 2;
2069 }
2070
2071 switch( cur->Type )
2072 {
2075 cw = true;
2079 {
2080 EDA_ANGLE arcStartAngle( startPoint - centerPoint );
2081 EDA_ANGLE arcEndAngle( endPoint - centerPoint );
2082 EDA_ANGLE arcAngle = arcEndAngle - arcStartAngle;
2083
2084 if( cw )
2085 arcAngle = arcAngle.Normalize();
2086 else
2087 arcAngle = -arcAngle.Normalize();
2088
2089 // TODO: Load as arc...
2090
2091 SHAPE_ARC tempArc( centerPoint, startPoint, arcAngle );
2092 SHAPE_LINE_CHAIN arcSegments = tempArc.ConvertToPolyline( Millimeter2iu( 0.1 ) );
2093
2094 // Load the arc as a series of piece-wise segments
2095
2096 for( int jj = 0; jj < arcSegments.SegmentCount(); jj++ )
2097 {
2098 VECTOR2I segStart = (wxPoint) arcSegments.Segment( jj ).A;
2099 VECTOR2I segEnd = (wxPoint) arcSegments.Segment( jj ).B;
2100
2101 loadGraphicStaightSegment( segStart, segEnd, aCadstarLineCodeID, aCadstarSheetID,
2102 aKiCadSchLayerID, aMoveVector, aRotation, aScalingFactor,
2103 aTransformCentre, aMirrorInvert );
2104 }
2105 }
2106 break;
2107
2108 case VERTEX_TYPE::POINT:
2109 loadGraphicStaightSegment( startPoint, endPoint, aCadstarLineCodeID, aCadstarSheetID,
2110 aKiCadSchLayerID, aMoveVector, aRotation, aScalingFactor,
2111 aTransformCentre, aMirrorInvert );
2112 break;
2113
2114 default:
2115 wxFAIL_MSG( "Unknown CADSTAR Vertex type" );
2116 }
2117
2118
2119 prev = cur;
2120 }
2121}
void loadGraphicStaightSegment(const VECTOR2I &aStartPoint, const VECTOR2I &aEndPoint, const LINECODE_ID &aCadstarLineCodeID, const LAYER_ID &aCadstarSheetID, const 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)
EDA_ANGLE Normalize()
Definition: eda_angle.h:260
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
int SegmentCount() const
Return the number of segments in this line chain.
SEG Segment(int aIndex)
Return a copy of the aIndex-th segment in the line chain.
static constexpr int Millimeter2iu(double mm)

References SEG::A, CADSTAR_ARCHIVE_PARSER::ANTICLOCKWISE_ARC, CADSTAR_ARCHIVE_PARSER::ANTICLOCKWISE_SEMICIRCLE, SEG::B, CADSTAR_ARCHIVE_PARSER::VERTEX::Center, CADSTAR_ARCHIVE_PARSER::CLOCKWISE_ARC, CADSTAR_ARCHIVE_PARSER::CLOCKWISE_SEMICIRCLE, SHAPE_ARC::ConvertToPolyline(), CADSTAR_ARCHIVE_PARSER::VERTEX::End, getKiCadPoint(), KI_FALLTHROUGH, loadGraphicStaightSegment(), Millimeter2iu(), EDA_ANGLE::Normalize(), CADSTAR_ARCHIVE_PARSER::POINT, SHAPE_LINE_CHAIN::Segment(), SHAPE_LINE_CHAIN::SegmentCount(), 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 2146 of file cadstar_sch_archive_loader.cpp.

2150{
2151 wxCHECK_MSG( m_sheetMap.find( aCadstarSheetID ) == m_sheetMap.end(), ,
2152 "Sheet already loaded!" );
2153
2154 SCH_SHEET* sheet = new SCH_SHEET(
2155 /* aParent */ aParentSheet.Last(),
2156 /* aPosition */ aPosition,
2157 /* aSize */ wxSize( aSheetSize ) );
2158 SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
2159 SCH_SHEET_PATH instance( aParentSheet );
2160
2161 sheet->SetScreen( screen );
2162
2163 wxString name = Sheets.SheetNames.at( aCadstarSheetID );
2164
2165 SCH_FIELD& sheetNameField = sheet->GetFields()[SHEETNAME];
2166 SCH_FIELD& filenameField = sheet->GetFields()[SHEETFILENAME];
2167
2168 sheetNameField.SetText( name );
2169
2170 int sheetNum = getSheetNumber( aCadstarSheetID );
2171 wxString loadedFilename = wxFileName( Filename ).GetName();
2172 std::string filename = wxString::Format( "%s_%02d", loadedFilename, sheetNum ).ToStdString();
2173
2174 ReplaceIllegalFileNameChars( &filename );
2175 filename += wxT( "." ) + KiCadSchematicFileExtension;
2176
2177 filenameField.SetText( filename );
2178
2179 wxFileName fn( m_schematic->Prj().GetProjectPath() + filename );
2180 sheet->GetScreen()->SetFileName( fn.GetFullPath() );
2181 aParentSheet.Last()->GetScreen()->Append( sheet );
2182 instance.push_back( sheet );
2183 sheet->AddInstance( instance );
2184
2185 wxString pageNumStr = wxString::Format( "%d", getSheetNumber( aCadstarSheetID ) );
2186 sheet->SetPageNumber( instance, pageNumStr );
2187
2188 sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
2189
2190 m_sheetMap.insert( { aCadstarSheetID, sheet } );
2191
2192 loadChildSheets( aCadstarSheetID, instance );
2193}
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:122
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
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 SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1194
bool AddInstance(const SCH_SHEET_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1149
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:160
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_sheet.cpp:564
const std::string KiCadSchematicFileExtension
@ SHEETNAME
Definition: sch_sheet.h:43
@ SHEETFILENAME
Definition: sch_sheet.h:44
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Checks aName for illegal file name characters.

References SCH_SHEET::AddInstance(), 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::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 264 of file cadstar_sch_archive_loader.cpp.

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

References _, SCH_SHEET::AddInstance(), CADSTAR_SCH_ARCHIVE_PARSER::Filename, findOrphanSheets(), Format(), PROJECT::GetProjectPath(), SCH_SHEET::GetScreen(), getSheetNumber(), KiCadSchematicFileExtension, loadChildSheets(), loadSheetAndChildSheets(), m_rootSheet, m_schematic, m_sheetMap, SCHEMATIC::Prj(), SCH_SHEET_PATH::push_back(), ReplaceIllegalFileNameChars(), SCH_SCREEN::SetFileName(), SCH_SHEET::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 1828 of file cadstar_sch_archive_loader.cpp.

1832{
1833 aKiCadField->SetPosition( getKiCadPoint( aCadstarAttrLoc.Position ) );
1834 aKiCadField->SetVisible( true );
1835
1836 ALIGNMENT alignment = aCadstarAttrLoc.Alignment;
1837 EDA_ANGLE textAngle = getAngle( aCadstarAttrLoc.OrientAngle );
1838
1839 if( aIsMirrored )
1840 {
1841 // We need to change the aligment when the symbol is mirrored based on the text orientation
1842 // To ensure the anchor point is the same in KiCad.
1843
1844 int textIsVertical = KiROUND( textAngle.AsDegrees() / 90.0 ) % 2;
1845
1846 if( textIsVertical )
1847 alignment = rotate180( alignment );
1848
1849 alignment = mirrorX( alignment );
1850 }
1851
1852 applyTextSettings( aKiCadField,
1853 aCadstarAttrLoc.TextCodeID,
1854 alignment,
1855 aCadstarAttrLoc.Justification,
1856 getCadstarAngle( textAngle - aComponentOrientation ),
1857 aCadstarAttrLoc.Mirror );
1858}
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 1303 of file cadstar_sch_archive_loader.cpp.

1305{
1306 wxCHECK( Library.SymbolDefinitions.find( aSymdefID ) != Library.SymbolDefinitions.end(), );
1307
1308 SYMDEF_SCM symbol = Library.SymbolDefinitions.at( aSymdefID );
1309 int gateNumber = getKiCadUnitNumberFromGate( aGateID );
1310
1311 // Ensure there are no items on this unit (e.g. if we already previously loaded the symbol from
1312 // the part definition)
1313 std::vector<LIB_ITEM*> drawItems = aSymbol->GetUnitDrawItems( gateNumber, 0 );
1314
1315 for( LIB_ITEM* item : drawItems )
1316 aSymbol->RemoveDrawItem( item );
1317
1318 for( std::pair<FIGURE_ID, FIGURE> figPair : symbol.Figures )
1319 {
1320 FIGURE fig = figPair.second;
1321 int lineThickness = getLineThickness( fig.LineCodeID );
1322
1323 loadLibrarySymbolShapeVertices( fig.Shape.Vertices, symbol.Origin, aSymbol, gateNumber,
1324 lineThickness );
1325
1326 for( CUTOUT c : fig.Shape.Cutouts )
1327 {
1328 loadLibrarySymbolShapeVertices( c.Vertices, symbol.Origin, aSymbol, gateNumber,
1329 lineThickness );
1330 }
1331 }
1332
1333 TERMINAL_TO_PINNUM_MAP pinNumMap;
1334
1335 for( std::pair<TERMINAL_ID, TERMINAL> termPair : symbol.Terminals )
1336 {
1337 TERMINAL term = termPair.second;
1338 wxString pinNum = wxString::Format( "%ld", term.ID );
1339 wxString pinName = wxEmptyString;
1340 LIB_PIN* pin = new LIB_PIN( aSymbol );
1341
1342 if( aCadstarPart )
1343 {
1344 PART::DEFINITION::PIN csPin = getPartDefinitionPin( *aCadstarPart, aGateID, term.ID );
1345
1346 pinName = HandleTextOverbar( csPin.Label );
1347 pinNum = HandleTextOverbar( csPin.Name );
1348
1349 if( pinNum.IsEmpty() )
1350 {
1351 if( !csPin.Identifier.IsEmpty() )
1352 pinNum = csPin.Identifier;
1353 else if( csPin.ID == UNDEFINED_VALUE )
1354 pinNum = wxString::Format( "%ld", term.ID );
1355 else
1356 pinNum = wxString::Format( "%ld", csPin.ID );
1357 }
1358
1359 pin->SetType( getKiCadPinType( csPin.Type ) );
1360
1361 pinNumMap.insert( { term.ID, pinNum } );
1362 }
1363 else
1364 {
1365 // If no part is defined, we don't know the pin type. Assume passive pin
1367 }
1368
1369 pin->SetPosition( getKiCadLibraryPoint( term.Position, symbol.Origin ) );
1370 pin->SetLength( 0 ); //CADSTAR Pins are just a point (have no length)
1371 pin->SetShape( GRAPHIC_PINSHAPE::LINE );
1372 pin->SetUnit( gateNumber );
1373 pin->SetNumber( pinNum );
1374 pin->SetName( pinName );
1375
1376 int pinNumberHeight = getTextHeightFromTextCode( wxT( "TC0" ) ); // TC0 is the default CADSTAR text size for name/number
1377 int pinNameHeight = getTextHeightFromTextCode( wxT( "TC0" ) );
1378
1379 if( symbol.PinNumberLocations.count( term.ID ) )
1380 {
1381 PIN_NUM_LABEL_LOC pinNumLocation = symbol.PinNumberLocations.at( term.ID );
1382 pinNumberHeight = getTextHeightFromTextCode( pinNumLocation.TextCodeID );
1383 }
1384
1385 if( symbol.PinLabelLocations.count( term.ID ) )
1386 {
1387 PIN_NUM_LABEL_LOC pinNameLocation = symbol.PinLabelLocations.at( term.ID );
1388 pinNameHeight = getTextHeightFromTextCode( pinNameLocation.TextCodeID );
1389 }
1390
1391 pin->SetNumberTextSize( pinNumberHeight );
1392 pin->SetNameTextSize( pinNameHeight );
1393
1394 if( aSymbol->IsPower() )
1395 {
1396 pin->SetVisible( false );
1398 pin->SetName( aSymbol->GetName() );
1399 }
1400
1401 aSymbol->AddDrawItem( pin );
1402 }
1403
1404 fixUpLibraryPins( aSymbol, gateNumber );
1405
1406 if(aCadstarPart)
1407 m_pinNumsMap.insert( { aCadstarPart->ID + aGateID, pinNumMap } );
1408
1409 for( std::pair<TEXT_ID, TEXT> textPair : symbol.Texts )
1410 {
1411 TEXT csText = textPair.second;
1412
1413 LIB_TEXT* libtext = new LIB_TEXT( aSymbol );
1414 libtext->SetText( csText.Text );
1415 libtext->SetUnit( gateNumber );
1416 libtext->SetPosition( getKiCadLibraryPoint( csText.Position, symbol.Origin ) );
1417 libtext->SetMultilineAllowed( true ); // temporarily so that we calculate bbox correctly
1418
1419 applyTextSettings( libtext,
1420 csText.TextCodeID,
1421 csText.Alignment,
1422 csText.Justification,
1423 csText.OrientAngle,
1424 csText.Mirror );
1425
1426 // Split out multi line text items into individual text elements
1427 if( csText.Text.Contains( "\n" ) )
1428 {
1429 wxArrayStri