KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_sch_utils.cpp File Reference
#include <algorithm>
#include <set>
#include <trace_helpers.h>
#include <sch_pin.h>
#include <lib_symbol.h>
#include <schematic.h>
#include <sch_symbol.h>
#include <sch_bitmap.h>
#include <sch_bus_entry.h>
#include <sch_field.h>
#include <sch_group.h>
#include <sch_junction.h>
#include <sch_label.h>
#include <sch_line.h>
#include <sch_no_connect.h>
#include <sch_rule_area.h>
#include <sch_shape.h>
#include <sch_sheet.h>
#include <sch_sheet_path.h>
#include <sch_screen.h>
#include <sch_sheet_pin.h>
#include <sch_table.h>
#include <sch_tablecell.h>
#include <sch_text.h>
#include <sch_textbox.h>
#include "api_sch_utils.h"
#include <api/api_utils.h>
#include <api/api_enums.h>

Go to the source code of this file.

Functions

std::unique_ptr< EDA_ITEMCreateItemForType (KICAD_T aType, EDA_ITEM *aContainer)
 
void PackPinMapOverride (kiapi::schematic::types::PinMapInstanceOverride *aOutput, const PIN_MAP_INSTANCE_OVERRIDE &aOverride)
 Pack/unpack a pin-to-pad map instance override to/from its protobuf form (issue #2282).
 
PIN_MAP_INSTANCE_OVERRIDE UnpackPinMapOverride (const kiapi::schematic::types::PinMapInstanceOverride &aInput)
 
bool PackSymbol (kiapi::schematic::types::SchematicSymbolInstance *aOutput, const SCH_SYMBOL *aInput, const SCH_SHEET_PATH &aPath)
 
bool UnpackSymbol (SCH_SYMBOL *aOutput, const kiapi::schematic::types::SchematicSymbolInstance &aInput)
 Unpack the geometry, the library definition, fields, and the default-variant attributes that are shared between every placement.
 
template<typename VariantProto>
static void registerVariant (SCHEMATIC *aSchematic, const wxString &aName, const VariantProto &aInput)
 Make the schematic aware of a variant a request named. Accepts either variant message.
 
static void applySymbolVariants (SCH_SYMBOL *aSymbol, const kiapi::schematic::types::SchematicSymbolVariants &aInput, const SCH_SHEET_PATH &aPath, SCHEMATIC *aSchematic)
 Make the set of variant records on one placement of a symbol match aInput, by name.
 
void ApplySymbolInstance (SCH_SYMBOL *aSymbol, const kiapi::schematic::types::SchematicSymbolInstance &aInput, const SCH_SHEET_PATH &aPath, SCHEMATIC *aSchematic)
 Apply placement-specific data to an aSymbol at aPath: reference, unit, and the per-placement attribute and field differentials.
 
bool PackSheet (kiapi::schematic::types::SheetSymbol *aOutput, const SCH_SHEET *aInput, const SCH_SHEET_PATH &aPath)
 
static void applySheetVariants (SCH_SHEET *aSheet, const kiapi::schematic::types::SheetVariants &aInput, const SCH_SHEET_PATH &aParentPath, SCHEMATIC *aSchematic)
 Make the set of variant records on one placement of a sheet match aInput, by name.
 
void ApplySheetInstance (SCH_SHEET *aSheet, const kiapi::schematic::types::SheetSymbol &aInput, const SCH_SHEET_PATH &aParentPath, SCHEMATIC *aSchematic)
 Apply the placement data in a sheet message to aSheet: page number and the variants the message carries.
 
tl::expected< bool, ApiResponseStatus > UnpackSheet (SCH_SHEET *aOutput, const kiapi::schematic::types::SheetSymbol &aInput)
 Unpack the every placement data from the input.
 
void PackSheetPath (types::SheetPath &aOutput, const SCH_SHEET_PATH &aInput)
 

Function Documentation

◆ ApplySheetInstance()

void ApplySheetInstance ( SCH_SHEET * aSheet,
const kiapi::schematic::types::SheetSymbol & aInput,
const SCH_SHEET_PATH & aParentPath,
SCHEMATIC * aSchematic )

Apply the placement data in a sheet message to aSheet: page number and the variants the message carries.

aParentPath is the path of the sheet that contains aSheet, which is how a sheet's placement records are keyed.

Definition at line 525 of file api_sch_utils.cpp.

References applySheetVariants(), and path.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and API_HANDLER_SCH::handleCreateUpdateItemsInternal().

◆ applySheetVariants()

static void applySheetVariants ( SCH_SHEET * aSheet,
const kiapi::schematic::types::SheetVariants & aInput,
const SCH_SHEET_PATH & aParentPath,
SCHEMATIC * aSchematic )
static

Make the set of variant records on one placement of a sheet match aInput, by name.

Each surviving record keeps the attributes the message leaves unset.

Definition at line 456 of file api_sch_utils.cpp.

References SCH_SHEET::ClearVariantField(), SCH_SHEET::DeleteVariant(), SCH_SHEET::GetInstance(), SCH_SHEET_INSTANCE::m_Variants, name, SCH_SHEET_PATH::Path(), registerVariant(), SCH_SHEET::SetDNP(), SCH_SHEET::SetExcludedFromBOM(), SCH_SHEET::SetExcludedFromSim(), and SCH_SHEET::SetFieldText().

Referenced by ApplySheetInstance().

◆ ApplySymbolInstance()

void ApplySymbolInstance ( SCH_SYMBOL * aSymbol,
const kiapi::schematic::types::SchematicSymbolInstance & aInput,
const SCH_SHEET_PATH & aPath,
SCHEMATIC * aSchematic )

Apply placement-specific data to an aSymbol at aPath: reference, unit, and the per-placement attribute and field differentials.

Variant names are registered with aSchematic so that the UI offers them for selection. aSymbol must already be in the schematic; the other placements of the symbol are untouched.

Definition at line 379 of file api_sch_utils.cpp.

References SCH_SYMBOL::AddHierarchicalReference(), applySymbolVariants(), SCH_SYMBOL::GetInstance(), SCH_SYMBOL_INSTANCE::m_Path, SCH_SYMBOL_INSTANCE::m_Reference, SCH_SYMBOL_INSTANCE::m_Unit, SCH_SHEET_PATH::Path(), SCH_SYMBOL::SetRef(), SCH_ITEM::SetUnit(), and SCH_SYMBOL::SetUnitSelection().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and API_HANDLER_SCH::handleCreateUpdateItemsInternal().

◆ applySymbolVariants()

◆ CreateItemForType()

◆ PackPinMapOverride()

void PackPinMapOverride ( kiapi::schematic::types::PinMapInstanceOverride * aOutput,
const PIN_MAP_INSTANCE_OVERRIDE & aOverride )

Pack/unpack a pin-to-pad map instance override to/from its protobuf form (issue #2282).

Definition at line 110 of file api_sch_utils.cpp.

References edit, PIN_MAP_INSTANCE_OVERRIDE::m_ActiveMapName, PIN_MAP_INSTANCE_OVERRIDE::m_Edits, PIN_MAP_INSTANCE_OVERRIDE::m_Mode, and ToProtoEnum().

Referenced by PackSymbol().

◆ PackSheet()

◆ PackSheetPath()

void PackSheetPath ( types::SheetPath & aOutput,
const SCH_SHEET_PATH & aInput )

◆ PackSymbol()

◆ registerVariant()

template<typename VariantProto>
static void registerVariant ( SCHEMATIC * aSchematic,
const wxString & aName,
const VariantProto & aInput )
static

Make the schematic aware of a variant a request named. Accepts either variant message.

Definition at line 287 of file api_sch_utils.cpp.

References SCHEMATIC::AddVariant(), and SCHEMATIC::SetVariantDescription().

Referenced by applySheetVariants(), and applySymbolVariants().

◆ UnpackPinMapOverride()

PIN_MAP_INSTANCE_OVERRIDE UnpackPinMapOverride ( const kiapi::schematic::types::PinMapInstanceOverride & aInput)

Definition at line 127 of file api_sch_utils.cpp.

References FromProtoEnum(), and PIN_MAP_INSTANCE_OVERRIDE::m_Mode.

Referenced by applySymbolVariants(), and UnpackSymbol().

◆ UnpackSheet()

tl::expected< bool, ApiResponseStatus > UnpackSheet ( SCH_SHEET * aOutput,
const kiapi::schematic::types::SheetSymbol & aInput )

Unpack the every placement data from the input.

Placement data is applied separately by ApplySheetInstance.

Definition at line 543 of file api_sch_utils.cpp.

References SCH_SHEET::Deserialize().

Referenced by BOOST_AUTO_TEST_CASE(), and API_HANDLER_SCH::handleCreateUpdateItemsInternal().

◆ UnpackSymbol()

bool UnpackSymbol ( SCH_SYMBOL * aOutput,
const kiapi::schematic::types::SchematicSymbolInstance & aInput )

Unpack the geometry, the library definition, fields, and the default-variant attributes that are shared between every placement.

Single-placement data is handled by ApplySymbolInstance.

Definition at line 259 of file api_sch_utils.cpp.

References SCH_SYMBOL::Deserialize(), SCH_SYMBOL::SetDNP(), SCH_SYMBOL::SetExcludedFromBoard(), SCH_SYMBOL::SetExcludedFromBOM(), SCH_SYMBOL::SetExcludedFromPosFiles(), SCH_SYMBOL::SetExcludedFromSim(), SCH_SYMBOL::SetPinMapOverride(), and UnpackPinMapOverride().

Referenced by BOOST_AUTO_TEST_CASE(), and API_HANDLER_SCH::handleCreateUpdateItemsInternal().