20#include <boost/test/unit_test.hpp>
25#include <api/schematic/schematic_types.pb.h>
46#include <wx/filename.h>
57 for(
SCH_ITEM* item : m_schematic->RootScreen()->Items() )
59 switch( item->Type() )
66 return std::make_unique<SCH_JUNCTION>();
75 return std::make_unique<SCH_NO_CONNECT>();
84 return std::make_unique<SCH_BUS_WIRE_ENTRY>();
93 return std::make_unique<SCH_BUS_BUS_ENTRY>();
102 return std::make_unique<SCH_LINE>();
111 return std::make_unique<SCH_SHAPE>();
120 return std::make_unique<SCH_RULE_AREA>();
129 return std::make_unique<SCH_BITMAP>();
138 return std::make_unique<SCH_TEXT>();
147 return std::make_unique<SCH_TEXTBOX>();
156 return std::make_unique<SCH_LABEL>();
165 return std::make_unique<SCH_GLOBALLABEL>();
174 return std::make_unique<SCH_HIERLABEL>();
183 return std::make_unique<SCH_DIRECTIVE_LABEL>();
192 return std::make_unique<SCH_GROUP>( m_schematic->RootScreen() );
201 return std::make_unique<SCH_SHEET>( m_schematic->RootScreen() );
210 return std::make_unique<SCH_TABLE>();
221 kiapi::common::commands::ItemStatus status;
222 kiapi::schematic::types::SchematicSymbolInstance symbolProto;
226 std::unique_ptr<SCH_SYMBOL> output = std::make_unique<SCH_SYMBOL>();
230 output->SetParent( m_schematic->RootScreen() );
236 m_schematic.get() ) );
238 kiapi::schematic::types::SchematicSymbolInstance outputProto;
242 if( !google::protobuf::util::MessageDifferencer::Equals( symbolProto, outputProto ) )
246 BOOST_TEST_FAIL(
"Round-tripped protobuf does not match" );
249 if( !output->operator==( *symbol ) )
250 BOOST_TEST_FAIL(
"Round-tripped object does not match" );
279 const wxString variantName( wxS(
"api-variant" ) );
280 const bool baseDNP = symbol->
GetDNP();
282 kiapi::schematic::types::SchematicSymbolInstance proto;
285 kiapi::common::commands::ItemStatus status;
286 kiapi::schematic::types::SchematicSymbolVariant* variant = proto.mutable_variants()->add_variants();
287 variant->set_name( variantName.ToUTF8() );
288 variant->mutable_attributes()->set_do_not_populate( !baseDNP );
294 BOOST_CHECK( m_schematic->GetVariantNames().count( variantName ) );
297 kiapi::schematic::types::SchematicSymbolInstance untouched;
298 untouched.mutable_reference_field()->mutable_text()->set_text( symbol->
GetRef( &
path ).ToUTF8() );
306 kiapi::schematic::types::SchematicSymbolInstance cleared;
309 cleared.mutable_variants()->clear_variants();
314 BOOST_CHECK( m_schematic->GetVariantNames().count( variantName ) );
334 const wxString variantName( wxS(
"api-variant" ) );
337 const wxString overrideValue( wxS(
"Override" ) );
339 kiapi::common::commands::ItemStatus status;
340 kiapi::schematic::types::SchematicSymbolInstance proto;
343 kiapi::schematic::types::SchematicSymbolVariant* variant = proto.mutable_variants()->add_variants();
344 variant->set_name( variantName.ToUTF8() );
345 variant->mutable_attributes()->set_do_not_populate(
true );
346 ( *variant->mutable_fields() )[std::string( fieldName.ToUTF8() )] = overrideValue.ToUTF8();
353 kiapi::schematic::types::SchematicSymbolInstance withoutField;
357 withoutField.mutable_variants()->mutable_variants( 0 )->clear_fields();
364 kiapi::schematic::types::SchematicSymbolInstance cleared;
366 cleared.mutable_variants()->clear_variants();
371 BOOST_CHECK( m_schematic->GetVariantNames().count( variantName ) );
378 fn.AppendDir( wxS(
"variants" ) );
379 fn.SetName( wxS(
"variants" ) );
380 fn.SetExt( wxS(
"kicad_sch" ) );
395 kiapi::schematic::types::SheetSymbol proto;
401 kiapi::common::commands::ItemStatus status;
402 const kiapi::schematic::types::SheetVariant& variant = proto.variants().variants( 0 );
406 std::unique_ptr<SCH_SHEET> output = std::make_unique<SCH_SHEET>( m_schematic->RootScreen() );
407 output->SetParent( m_schematic->RootScreen() );
408 output->SetScreen(
new SCH_SCREEN( m_schematic.get() ) );
417 BOOST_CHECK( output->GetExcludedFromSim( &parentPath, wxS(
"Variant 1" ) ) );
419 kiapi::schematic::types::SheetSymbol outputProto;
426 proto.variants().variants( 0 ).exclude_from_sim() );
446 const wxString variantName( wxS(
"api-sheet-variant" ) );
447 const bool baseDNP = sheet->
GetDNP( &parentPath );
449 kiapi::common::commands::ItemStatus status;
450 kiapi::schematic::types::SheetSymbol proto;
453 kiapi::schematic::types::SheetVariant* variant = proto.mutable_variants()->add_variants();
454 variant->set_name( variantName.ToUTF8() );
455 variant->set_dnp( !baseDNP );
461 BOOST_CHECK( m_schematic->GetVariantNames().count( variantName ) );
464 kiapi::schematic::types::SheetSymbol before;
466 const wxString originalDescription = m_schematic->GetVariantDescription( variantName );
467 proto.set_page_number(
"999" );
468 variant->set_dnp( baseDNP );
469 variant->set_description(
"Rejected description" );
471 for(
const std::string& field : {
"Sheetname",
"Sheetfile",
"Reference Suffix" } )
475 variant->clear_fields();
476 ( *variant->mutable_fields() )[field] =
"should_not_be_allowed";
479 kiapi::schematic::types::SheetSymbol after;
481 BOOST_CHECK( google::protobuf::util::MessageDifferencer::Equals( before, after ) );
482 BOOST_CHECK_EQUAL( m_schematic->GetVariantDescription( variantName ), originalDescription );
486 kiapi::schematic::types::SheetSymbol untouched;
488 untouched.clear_variants();
490 if( untouched.page_number().empty() )
491 untouched.set_page_number(
"1" );
497 kiapi::schematic::types::SheetSymbol cleared;
500 cleared.mutable_variants()->clear_variants();
505 BOOST_CHECK( m_schematic->GetVariantNames().count( variantName ) );
511 fn.AppendDir( wxS(
"variants" ) );
512 fn.SetName( wxS(
"variants" ) );
513 fn.SetExt( wxS(
"kicad_sch" ) );
517 BOOST_REQUIRE_GE( hierarchy.size(), 2u );
524 if(
path.size() > 1 )
531 BOOST_REQUIRE_GT( subPath.
size(), 1u );
533 std::vector<SCH_ITEM*> subSymbols;
536 subSymbols.push_back( item );
538 BOOST_REQUIRE_GE( subSymbols.size(), 2u );
552 auto target =
ResolveFocusItems( *m_schematic, { subSymbols[0]->m_Uuid, subSymbols[1]->m_Uuid }, std::nullopt );
553 BOOST_REQUIRE_MESSAGE( target.has_value(), ( target ? std::string() : target.error().error_message() ) );
557 expected.Merge( subSymbols[1]->GetBoundingBox() );
570 BOOST_REQUIRE_MESSAGE( target.has_value(), ( target ? std::string() : target.error().error_message() ) );
tl::expected< bool, ApiResponseStatus > UnpackSheet(SCH_SHEET *aOutput, const kiapi::schematic::types::SheetSymbol &aInput)
Unpack the every placement data from the input.
bool ApplySymbolInstance(kiapi::common::commands::ItemStatus *aStatus, 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 attribut...
bool PackSheet(kiapi::schematic::types::SheetSymbol *aOutput, const SCH_SHEET *aInput, const SCH_SHEET_PATH &aPath)
bool ApplySheetInstance(commands::ItemStatus *aStatus, SCH_SHEET *aSheet, const kiapi::schematic::types::SheetSymbol &aInput, const SCH_SHEET_PATH &aParentPath, SCHEMATIC *aSchematic)
bool PackSymbol(kiapi::schematic::types::SchematicSymbolInstance *aOutput, const SCH_SYMBOL *aInput, const SCH_SHEET_PATH &aPath, const SCHEMATIC *aSchematic)
tl::expected< SCH_FOCUS_TARGET, ApiResponseStatus > ResolveFocusItems(SCHEMATIC &aSchematic, const std::vector< KIID > &aIds, const std::optional< KIID_PATH > &aSheetPath)
Resolve the items of a FocusOnItems request to the sheet that shows them and their combined bounding ...
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 shar...
void testProtoFromKiCadObject(KiCadClass *aInput, Factory &&aCreateOutput)
EE_TYPE OfType(KICAD_T aType) const
std::string AsStdString() const
A generic fixture for loading schematics and associated settings for qa tests.
Object to handle a bitmap image that can be inserted in a schematic.
Class for a bus to bus entry.
Class for a wire to bus entry.
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
A set of SCH_ITEMs (i.e., without duplicates).
Base class for any item which can be embedded within the SCHEMATIC container class,...
Segment description base class to describe items which have 2 end points (track, wire,...
EE_RTREE & Items()
Get the full RTree, usually for iterating.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SCREEN * LastScreen()
wxString GetPageNumber() const
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
size_t size() const
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add aFieldName to the list of fields.
bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flags.
virtual bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flag.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
wxString GetFieldText(const SCH_FIELD *aField, const wxString &aFieldName, const SCH_SHEET_PATH *aPath, const wxString &aVariantName) const
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Class to handle a set of SCH_ITEMs.
static void LoadSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxString &aFileName, REPORTER *aReporter)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE_MESSAGE(dc.CacheTableInfo(table, { "part_id", "val" }), dc.GetLastError())
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
BOOST_AUTO_TEST_CASE(KitchenSink)
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
wxString result
Test unit parsing edge cases and error handling.