29#include <fmt/ranges.h>
31#include <magic_enum.hpp>
69#include <wx/filename.h>
71#include <api/common/commands/library_commands.pb.h>
72#include <api/common/types/base_types.pb.h>
77using namespace kiapi::common::commands;
78using kiapi::common::types::CommandStatus;
79using kiapi::common::types::DocumentType;
80using kiapi::common::types::ItemRequestStatus;
107 types::RunJobResponse response;
112 response.add_output_path( output.m_outputPath.ToUTF8() );
116 response.set_status( types::JobStatus::JS_SUCCESS );
120 response.set_status( types::JobStatus::JS_ERROR );
121 response.set_message( fmt::format(
"Schematic export job '{}' failed with exit code {}: {}",
123 reporter.GetMessages().ToStdString() ) );
139 using namespace kiapi::schematic::jobs;
141 using namespace kiapi::schematic::commands;
212 return std::make_unique<SCH_COMMIT>(
toolManager() );
235 e.set_status( ApiStatusCode::AS_UNIMPLEMENTED );
236 e.set_error_message( fmt::format(
"{} is not available in headless mode", aCommandName ) );
246 kiapi::schematic::types::SchematicSymbolInstance symbol;
251 if( !aOut.PackFrom( symbol ) )
253 wxFAIL_MSG( wxT(
"Failed to pack SCH_SYMBOL" ) );
259 kiapi::schematic::types::SheetSymbol sheet;
264 if( !aOut.PackFrom( sheet ) )
266 wxFAIL_MSG( wxT(
"Failed to pack SCH_SHEET" ) );
293tl::expected<bool, ApiResponseStatus>
296 if( aDocument.type() != DocumentType::DOCTYPE_SCHEMATIC )
299 e.set_status( ApiStatusCode::AS_UNHANDLED );
300 return tl::unexpected( e );
305 if( aDocument.project().name().compare( prj.
GetProjectName().ToUTF8() ) != 0 )
308 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
309 e.set_error_message( fmt::format(
"the requested project {} is not open",
310 aDocument.project().name() ) );
311 return tl::unexpected( e );
314 if( aDocument.project().path().compare( prj.
GetProjectPath().ToUTF8() ) != 0 )
317 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
318 e.set_error_message( fmt::format(
"the requested project {} is not open at path {}",
319 aDocument.project().name(),
320 aDocument.project().path() ) );
321 return tl::unexpected( e );
324 if( aDocument.has_sheet_path() )
331 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
332 e.set_error_message( fmt::format(
"the requested sheet path {} is not valid for this schematic",
333 path.AsString().ToStdString() ) );
334 return tl::unexpected( e );
345 return tl::unexpected( documentValidation.error() );
347 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
348 return tl::unexpected( *busy );
353 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
354 e.set_error_message(
"the schematic is untitled; use SaveDocumentAs to save it to a new file" );
355 return tl::unexpected( e );
358 if( !
context()->SaveSchematic() )
361 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
362 e.set_error_message(
"failed to save schematic" );
363 return tl::unexpected( e );
366 return google::protobuf::Empty();
378 e.set_status( ApiStatusCode::AS_UNIMPLEMENTED );
379 e.set_error_message(
"SaveDocumentAs is not available in GUI mode" );
380 return tl::unexpected( e );
383 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
384 return tl::unexpected( *busy );
388 if( !documentValidation )
389 return tl::unexpected( documentValidation.error() );
391 wxString pathStr = wxString::FromUTF8( aCtx.
Request.path() );
393 if( pathStr.IsEmpty() )
396 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
397 e.set_error_message(
"path is required" );
398 return tl::unexpected( e );
401 wxFileName oldSchematicFile(
m_context->GetCurrentFileName() );
403 if( !
context()->SaveSchematicAs( pathStr ) )
406 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
407 e.set_error_message( fmt::format(
"failed to save schematic to '{}'", pathStr.ToStdString() ) );
408 return tl::unexpected( e );
413 wxFileName newSchematicFile( pathStr );
416 server->NotifyDocumentRenamed(
thisDocumentType(), oldSchematicFile.GetFullPath(),
417 newSchematicFile.GetFullPath() );
420 return google::protobuf::Empty();
429 if( !documentValidation )
430 return tl::unexpected( documentValidation.error() );
432 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
433 return tl::unexpected( *busy );
435 wxFileName schematicPath(
project().AbsolutePath( wxString::FromUTF8( aCtx.
Request.path() ) ) );
437 if( !schematicPath.IsOk() || !schematicPath.IsDirWritable() )
440 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
442 fmt::format(
"save path '{}' could not be opened", schematicPath.GetFullPath().ToStdString() ) );
443 return tl::unexpected( e );
446 if( schematicPath.FileExists() && ( !schematicPath.IsFileWritable() || !aCtx.
Request.options().overwrite() ) )
449 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
450 e.set_error_message( fmt::format(
"save path '{}' exists and cannot be overwritten",
451 schematicPath.GetFullPath().ToStdString() ) );
452 return tl::unexpected( e );
458 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
459 e.set_error_message( fmt::format(
"save path '{}' must have a kicad_sch extension",
460 schematicPath.GetFullPath().ToStdString() ) );
461 return tl::unexpected( e );
464 bool includeProject =
true;
466 if( aCtx.
Request.has_options() )
467 includeProject = aCtx.
Request.options().include_project();
469 if( !
context()->SaveSchematicCopy( schematicPath.GetFullPath(), includeProject ) )
472 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
473 e.set_error_message(
"failed to save schematic copy" );
474 return tl::unexpected( e );
477 return google::protobuf::Empty();
484 if( aCtx.
Request.document().type() != DocumentType::DOCTYPE_SCHEMATIC )
487 e.set_status( ApiStatusCode::AS_UNHANDLED );
488 return tl::unexpected( e );
493 if( !documentValidation )
494 return tl::unexpected( documentValidation.error() );
499 e.set_status( ApiStatusCode::AS_BUSY );
500 e.set_error_message(
"cannot revert while a commit is open" );
501 return tl::unexpected( e );
504 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
505 return tl::unexpected( *busy );
507 if( !
context()->RevertToSaved() )
510 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
511 e.set_error_message(
"could not revert: there is no saved file on disk to revert to" );
512 return tl::unexpected( e );
515 return google::protobuf::Empty();
524 if( !documentValidation )
525 return tl::unexpected( documentValidation.error() );
527 commands::SavedDocumentResponse response;
531 if( aCtx.
Request.document().has_sheet_path() )
535 if( std::optional<SCH_SHEET_PATH> resolvedPath =
schematic()->Hierarchy().GetSheetPathByKIIDPath( kiidPath ) )
536 topLevelSheet = resolvedPath->Last();
539 if( !topLevelSheet || !topLevelSheet->
GetScreen() )
542 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
543 e.set_error_message(
"schematic has no top-level sheet to save" );
544 return tl::unexpected( e );
552 std::string contents = formatter.
GetString();
554 response.set_contents( contents );
563 if( std::optional<ApiResponseStatus> headless =
checkForHeadless(
"SaveSelectionToString" ) )
564 return tl::unexpected( *headless );
569 if( selection.Empty() )
572 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
573 e.set_error_message(
"the selection is empty" );
574 return tl::unexpected( e );
577 commands::SavedSelectionResponse response;
582 response.add_ids()->set_value( item->m_Uuid.AsStdString() );
589 std::string contents = formatter.
GetString();
591 response.set_contents( contents );
600 if( aCtx.
Request.type() != DocumentType::DOCTYPE_SCHEMATIC )
605 e.set_status( ApiStatusCode::AS_UNHANDLED );
606 return tl::unexpected( e );
609 GetOpenDocumentsResponse response;
610 common::types::DocumentSpecifier doc;
612 wxFileName fn(
m_context->GetCurrentFileName() );
614 doc.set_type( DocumentType::DOCTYPE_SCHEMATIC );
616 if( std::optional<SCH_SHEET_PATH>
path =
m_context->GetCurrentSheet() )
621 response.mutable_documents()->Add( std::move( doc ) );
630 return tl::unexpected( documentValidation.error() );
632 GetDocumentModifiedStateResponse response;
634 if( aCtx.
Request.document().has_sheet_path() )
643 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
644 e.set_error_message(
"the requested sheet path is not valid for this schematic" );
645 return tl::unexpected( e );
648 if(
const SCH_SCREEN* screen = sheetPath->LastScreen() )
650 response.set_state( screen->IsContentModified() ? DocumentModifiedState::DMS_MODIFIED
651 : DocumentModifiedState::DMS_UNMODIFIED );
660 response.set_state(
schematic()->Hierarchy().IsModified() ? DocumentModifiedState::DMS_MODIFIED
661 : DocumentModifiedState::DMS_UNMODIFIED );
668 std::erase_if( aTypeList,
681 return tl::unexpected( valid.error() );
684 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
685 return tl::unexpected( *busy );
689 if( aCtx.
Request.types().empty() )
692 std::set<KICAD_T> typesRequested;
694 for(
KICAD_T type : requestedTypes )
695 typesRequested.insert( type );
699 if( typesRequested.empty() )
702 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
703 e.set_error_message(
"none of the requested types are valid for a Schematic object" );
704 return tl::unexpected( e );
708 std::optional<SCH_SHEET_PATH> pathFilter;
710 if( aCtx.
Request.header().document().has_sheet_path() )
716 std::map<KICAD_T, std::vector<std::pair<EDA_ITEM*, SCH_SHEET_PATH>>> itemMap;
721 const SCH_SCREEN* aScreen = aPath.LastScreen();
728 itemMap[ aItem->Type() ].emplace_back( aItem, aPath );
734 aItem->RunOnChildren(
737 itemMap[ aChild->
Type() ].emplace_back( aChild, aPath );
745 processScreen( *pathFilter );
750 processScreen(
path );
753 GetItemsResponse response;
754 google::protobuf::Any
any;
756 for(
KICAD_T type : typesRequested )
758 for(
const auto& [item, itemPath] : itemMap[type] )
761 response.mutable_items()->Add( std::move(
any ) );
765 response.set_status( ItemRequestStatus::IRS_OK );
775 e.set_status( ApiStatusCode::AS_UNHANDLED );
776 return tl::unexpected( e );
779 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
780 return tl::unexpected( *busy );
783 std::optional<SCH_SHEET_PATH> pathFilter;
785 if( aCtx.
Request.header().document().has_sheet_path() )
791 GetItemsResponse response;
794 for(
const types::KIID& idProto : aCtx.
Request.items() )
796 google::protobuf::Any
any;
797 KIID id( idProto.value() );
803 item = pathFilter->ResolveItem(
id );
804 itemPath = *pathFilter;
808 item = hierarchy.
ResolveItem(
id, &itemPath,
true );
816 kiapi::schematic::types::SchematicSymbolInstance symbol;
821 if( !
any.PackFrom( symbol ) )
826 kiapi::schematic::types::SheetSymbol sheet;
831 if( !
any.PackFrom( sheet ) )
839 response.mutable_items()->Add( std::move(
any ) );
842 if( response.items().empty() )
845 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
846 e.set_error_message(
"none of the requested IDs were found or valid" );
847 return tl::unexpected( e );
850 response.set_status( ItemRequestStatus::IRS_OK );
858 if( std::optional<ApiResponseStatus> headless =
checkForHeadless(
"GetSelection" ) )
859 return tl::unexpected( *headless );
865 e.set_status( ApiStatusCode::AS_UNHANDLED );
866 return tl::unexpected( e );
877 SelectionResponse response;
878 google::protobuf::Any
any;
885 response.mutable_items()->Add( std::move(
any ) );
896 if( std::optional<ApiResponseStatus> headless =
checkForHeadless(
"ClearSelection" ) )
897 return tl::unexpected( *headless );
903 e.set_status( ApiStatusCode::AS_UNHANDLED );
904 return tl::unexpected( e );
907 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
908 return tl::unexpected( *busy );
920 if( std::optional<ApiResponseStatus> headless =
checkForHeadless(
"AddToSelection" ) )
921 return tl::unexpected( *headless );
927 e.set_status( ApiStatusCode::AS_UNHANDLED );
928 return tl::unexpected( e );
931 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
932 return tl::unexpected( *busy );
939 for(
const types::KIID&
id : aCtx.
Request.items() )
944 if( std::optional<SCH_ITEM*> item =
getItemById(
KIID(
id.value() ), &itemPath );
945 item && itemPath == current )
947 toAdd.push_back( *item );
954 SelectionResponse response;
955 google::protobuf::Any
any;
960 response.mutable_items()->Add( std::move(
any ) );
970 if( std::optional<ApiResponseStatus> headless =
checkForHeadless(
"RemoveFromSelection" ) )
971 return tl::unexpected( *headless );
977 e.set_status( ApiStatusCode::AS_UNHANDLED );
978 return tl::unexpected( e );
981 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
982 return tl::unexpected( *busy );
989 for(
const types::KIID&
id : aCtx.
Request.items() )
993 if( std::optional<SCH_ITEM*> item =
getItemById(
KIID(
id.value() ), &itemPath );
994 item && itemPath == current )
996 toRemove.push_back( *item );
1003 SelectionResponse response;
1004 google::protobuf::Any
any;
1009 response.mutable_items()->Add( std::move(
any ) );
1018 if( std::optional<ApiResponseStatus> headless =
checkForHeadless(
"FocusOnItems" ) )
1019 return tl::unexpected( *headless );
1022 return tl::unexpected( documentValidation.error() );
1024 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1025 return tl::unexpected( *busy );
1027 std::vector<KIID> ids;
1029 for(
const types::KIID&
id : aCtx.
Request.items() )
1030 ids.emplace_back(
id.value() );
1032 std::optional<KIID_PATH> sheetPath;
1034 if( aCtx.
Request.document().has_sheet_path() )
1040 return tl::unexpected( target.error() );
1045 BOX2I bbox = target->BBox;
1047 if( aCtx.
Request.has_margin() )
1060 ApiResponseStatus e;
1061 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1062 e.set_error_message(
"Tried to create an item in a null container" );
1063 return tl::unexpected( e );
1068 ApiResponseStatus e;
1069 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1070 e.set_error_message( fmt::format(
"type {} is not supported by the schematic API handler",
1071 magic_enum::enum_name( aType ) ) );
1072 return tl::unexpected( e );
1077 ApiResponseStatus e;
1078 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1079 e.set_error_message( fmt::format(
"Tried to create a pin in {}, which is not a symbol",
1081 return tl::unexpected( e );
1085 ApiResponseStatus e;
1086 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1087 e.set_error_message( fmt::format(
"Tried to create a sheet symbol in {}, which is not a "
1090 return tl::unexpected( e );
1094 ApiResponseStatus e;
1095 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1096 e.set_error_message( fmt::format(
"Tried to create a symbol in {}, which is not a "
1099 return tl::unexpected( e );
1104 if( created && !created->GetParent() )
1105 created->SetParent( aContainer );
1109 ApiResponseStatus e;
1110 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1111 e.set_error_message( fmt::format(
"Tried to create an item of type {}, which is unhandled",
1112 magic_enum::enum_name( aType ) ) );
1113 return tl::unexpected( e );
1121 const std::string& aClientName,
1122 const types::ItemHeader &aHeader,
1123 const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems,
1124 std::function<
void( ItemStatus, google::protobuf::Any )> aItemHandler )
1126 ApiResponseStatus e;
1130 if( !containerResult && containerResult.error().status() == ApiStatusCode::AS_UNHANDLED )
1133 e.set_status( ApiStatusCode::AS_UNHANDLED );
1134 return tl::unexpected( e );
1136 else if( !containerResult )
1138 e.CopyFrom( containerResult.error() );
1139 return tl::unexpected( e );
1146 if( aHeader.document().has_sheet_path() )
1159 bool connectivityChanged =
false;
1160 EDA_ITEM* container = targetScreen;
1162 if( containerResult->has_value() )
1166 if( !containerItem )
1168 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1169 e.set_error_message(
"the requested container does not exist in this document" );
1170 return tl::unexpected( e );
1173 container = containerItem;
1176 for(
const google::protobuf::Any& anyItem : aItems )
1183 status.set_code( ItemStatusCode::ISC_INVALID_TYPE );
1184 status.set_error_message( fmt::format(
"Could not decode a valid type from {}", anyItem.type_url() ) );
1185 aItemHandler( status, anyItem );
1191 if( !creationResult )
1193 status.set_code( ItemStatusCode::ISC_INVALID_TYPE );
1194 status.set_error_message( creationResult.error().error_message() );
1195 aItemHandler( status, anyItem );
1199 std::unique_ptr<EDA_ITEM> item( std::move( *creationResult ) );
1201 bool unpacked =
false;
1205 kiapi::schematic::types::SchematicSymbolInstance symbolProto;
1206 kiapi::schematic::types::SheetSymbol sheetProto;
1210 unpacked = anyItem.UnpackTo( &symbolProto )
1215 unpacked = anyItem.UnpackTo( &sheetProto );
1221 if( tl::expected<bool, ApiResponseStatus>
result =
UnpackSheet( sheet, sheetProto );
1228 return tl::unexpected(
result.error() );
1234 unpacked =
group->DeserializeGroup( anyItem, commit );
1238 unpacked = item->Deserialize( anyItem );
1245 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1246 e.set_error_message( fmt::format(
"could not unpack {} from request", item->GetClass().ToStdString() ) );
1247 return tl::unexpected( e );
1250 if( std::vector<wxString> removed = item->RemoveConflictingCustomProperties(); !removed.empty() )
1253 [](
const wxString& aIn )
1255 return std::string( aIn.ToUTF8() );
1258 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
1259 status.set_error_message( fmt::format(
"Invalid custom properties for item {}: property name(s) '{}' "
1261 item->m_Uuid.AsStdString(),
1262 fmt::join( std::views::transform( removed, as_str ),
", " ) ) );
1264 aItemHandler( status, anyItem );
1271 existingItem = targetPath.
ResolveItem( item->m_Uuid );
1274 existingPath = targetPath;
1276 if( aCreate && existingItem )
1278 status.set_code( ItemStatusCode::ISC_EXISTING );
1279 status.set_error_message( fmt::format(
"an item with UUID {} already exists",
1280 item->m_Uuid.AsStdString() ) );
1281 aItemHandler( status, anyItem );
1284 else if( !aCreate && !existingItem )
1286 status.set_code( ItemStatusCode::ISC_NONEXISTENT );
1287 status.set_error_message( fmt::format(
"an item with UUID {} does not exist",
1288 item->m_Uuid.AsStdString() ) );
1289 aItemHandler( status, anyItem );
1293 if( !aCreate && existingItem->
Type() != *type )
1295 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
1296 status.set_error_message( fmt::format(
"item {} is not of the requested type",
1297 item->m_Uuid.AsStdString() ) );
1298 aItemHandler( status, anyItem );
1306 if( itemScreen != targetScreen )
1308 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
1309 status.set_error_message( fmt::format(
"item {} exists on a different sheet than targeted",
1310 item->m_Uuid.AsStdString() ) );
1311 aItemHandler( status, anyItem );
1318 if( symbolProto.has_definition() )
1320 if( symbolProto.definition().id().entry_name().empty() )
1322 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
1323 status.set_error_message(
"symbol definition is missing an entry name" );
1324 aItemHandler( status, anyItem );
1330 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
1331 status.set_error_message(
"a symbol definition is required" );
1332 aItemHandler( status, anyItem );
1344 ? wxString( wxEmptyString )
1347 for(
const std::unique_ptr<SCH_PIN>&
pin : existingSymbol->
GetRawPins() )
1349 tempSymbol->
GetRawPins().emplace_back( std::make_unique<SCH_PIN>( *
pin ) );
1350 tempSymbol->
GetRawPins().back()->SetParent( tempSymbol );
1364 aItemHandler( status, anyItem );
1372 if( wxString rawFilename = sheet->
GetFileName(); !rawFilename.IsEmpty() )
1378 parentFileName.GetPath() ) )
1380 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
1381 status.set_error_message( fmt::format(
"could not resolve sheet filename '{}' for new sheet",
1382 rawFilename.ToStdString() ) );
1383 aItemHandler( status, anyItem );
1395 parentPath = targetPath;
1397 parentPath = existingPath;
1401 if( !destFilePath.IsEmpty() )
1408 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
1409 status.set_error_message(
"sheet update would create recursive hierarchy" );
1410 aItemHandler( status, anyItem );
1416 status.set_code( ItemStatusCode::ISC_OK );
1417 google::protobuf::Any newItem;
1419 if( aCreate && !item )
1423 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1424 e.set_error_message(
"could not add the requested item to its parent container" );
1425 return tl::unexpected( e );
1450 aItemHandler( status, anyItem );
1457 commit->
Add( createdItem, targetScreen );
1462 kiapi::schematic::types::SchematicSymbolInstance packed;
1466 aItemHandler( status, anyItem );
1471 (void) newItem.PackFrom( packed );
1476 kiapi::schematic::types::SheetSymbol packed;
1478 if( sheetProto.page_number().empty() )
1483 aItemHandler( status, anyItem );
1487 if(
PackSheet( &packed, sheet, targetPath ) )
1488 (void) newItem.PackFrom( packed );
1499 std::vector<SCH_SYMBOL_INSTANCE> symbolPlacements;
1500 std::vector<SCH_SHEET_INSTANCE> sheetPlacements;
1503 symbolPlacements =
static_cast<SCH_SYMBOL*
>( existingItem )->GetInstances();
1505 sheetPlacements =
static_cast<SCH_SHEET*
>( existingItem )->GetInstances();
1512 aItemHandler( status, anyItem );
1516 commit->
Modify( existingItem, targetScreen );
1522 connectivityChanged =
true;
1528 kiapi::schematic::types::SchematicSymbolInstance packed;
1535 aItemHandler( status, anyItem );
1539 if(
PackSymbol( &packed, symbol, existingPath ) )
1540 (void) newItem.PackFrom( packed );
1545 kiapi::schematic::types::SheetSymbol packed;
1552 aItemHandler( status, anyItem );
1556 if(
PackSheet( &packed, sheet, existingPath ) )
1557 (void) newItem.PackFrom( packed );
1565 aItemHandler( status, newItem );
1571 :
_(
"Modified items via API" ) );
1574 if(
m_frame && connectivityChanged )
1577 return ItemRequestStatus::IRS_OK;
1582 const std::string& aClientName )
1587 for(
auto& [
id, status] : aItemsToDelete )
1597 status = ItemDeletionStatus::IDS_IMMUTABLE;
1602 status = ItemDeletionStatus::IDS_OK;
1613 return std::nullopt;
1618 return std::nullopt;
1626 if( aDocument.has_sheet_path() )
1630 if( std::optional<SCH_SHEET_PATH> sheetPath =
schematic()->Hierarchy().GetSheetPathByKIIDPath(
path ) )
1631 return sheetPath->LastScreen();
1636 if( std::optional<SCH_SHEET_PATH> current =
m_context->GetCurrentSheet() )
1637 return current->LastScreen();
1649 return std::nullopt;
1656 return screen->GetPageSettings();
1658 return std::nullopt;
1666 screen->SetPageSettings( aPageInfo );
1667 screen->SetContentModified();
1698 else if(
schematic()->GetCurrentScreen() )
1712static std::optional<ApiResponseStatus>
1716 aJob.
m_drawingSheet = wxString::FromUTF8( aSettings.drawing_sheet() );
1717 aJob.
m_defaultFont = wxString::FromUTF8( aSettings.default_font() );
1718 aJob.
m_variant = wxString::FromUTF8( aSettings.variant() );
1725 aJob.
m_theme = wxString::FromUTF8( aSettings.theme() );
1729 for(
const std::string& page : aSettings.plot_pages() )
1730 aJob.
m_plotPages.push_back( wxString::FromUTF8( page ) );
1732 if( aSettings.page_size() != schematic::jobs::SchematicJobPageSize::SJPS_UNKNOWN )
1736 if( aSettings.sheet_mode() == schematic::jobs::SJSM_ALL_SHEETS )
1738 else if( aSettings.sheet_mode() == schematic::jobs::SJSM_SINGLE_SHEET )
1741 if( aDocument.has_sheet_path() )
1744 return std::nullopt;
1753 if( !documentValidation )
1754 return tl::unexpected( documentValidation.error() );
1756 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1757 return tl::unexpected( *busy );
1759 auto plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_SVG>( aCtx.
Request.plot_settings().sheet_mode()
1760 != schematic::jobs::SJSM_SINGLE_SHEET );
1763 if( !aCtx.
Request.job_settings().output_path().empty() )
1764 plotJob->SetConfiguredOutputPath( wxString::FromUTF8( aCtx.
Request.job_settings().output_path() ) );
1769 return tl::unexpected( *err );
1781 if( !documentValidation )
1782 return tl::unexpected( documentValidation.error() );
1784 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1785 return tl::unexpected( *busy );
1787 auto plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_DXF>( aCtx.
Request.plot_settings().sheet_mode()
1788 != schematic::jobs::SJSM_SINGLE_SHEET );
1792 if( !aCtx.
Request.job_settings().output_path().empty() )
1793 plotJob->SetConfiguredOutputPath( wxString::FromUTF8( aCtx.
Request.job_settings().output_path() ) );
1798 return tl::unexpected( *err );
1810 if( !documentValidation )
1811 return tl::unexpected( documentValidation.error() );
1813 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1814 return tl::unexpected( *busy );
1816 auto plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_PDF>(
false );
1819 if( !aCtx.
Request.job_settings().output_path().empty() )
1820 plotJob->SetConfiguredOutputPath( wxString::FromUTF8( aCtx.
Request.job_settings().output_path() ) );
1825 return tl::unexpected( *err );
1829 plotJob->m_PDFHierarchicalLinks = aCtx.
Request.hierarchical_links();
1841 if( !documentValidation )
1842 return tl::unexpected( documentValidation.error() );
1844 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1845 return tl::unexpected( *busy );
1847 auto plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_PS>( aCtx.
Request.plot_settings().sheet_mode()
1848 != schematic::jobs::SJSM_SINGLE_SHEET );
1851 if( !aCtx.
Request.job_settings().output_path().empty() )
1852 plotJob->SetConfiguredOutputPath( wxString::FromUTF8( aCtx.
Request.job_settings().output_path() ) );
1857 return tl::unexpected( *err );
1868 return tl::unexpected( validation.error() );
1870 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1871 return tl::unexpected( *busy );
1873 const schematic::jobs::SchematicJobSheetMode sheetMode = aCtx.
Request.plot_settings().sheet_mode();
1875 auto plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_PNG>( sheetMode != schematic::jobs::SJSM_SINGLE_SHEET );
1878 if( !aCtx.
Request.job_settings().output_path().empty() )
1879 plotJob->SetConfiguredOutputPath( wxString::FromUTF8( aCtx.
Request.job_settings().output_path() ) );
1884 return tl::unexpected( *err );
1893 ApiResponseStatus status;
1894 status.set_status( ApiStatusCode::AS_BAD_REQUEST );
1896 return tl::unexpected( status );
1903 plotJob->m_antialias = aCtx.
Request.antialiasing() != types::AntialiasingMode::AAM_NONE;
1904 plotJob->m_useBackgroundColor = aCtx.
Request.plot_background_color();
1915 if( !documentValidation )
1916 return tl::unexpected( documentValidation.error() );
1918 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1919 return tl::unexpected( *busy );
1921 if( aCtx.
Request.format() == kiapi::schematic::jobs::SchematicNetlistFormat::SNF_UNKNOWN )
1923 ApiResponseStatus e;
1924 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1925 e.set_error_message(
"RunSchematicJobExportNetlist requires a valid format" );
1926 return tl::unexpected( e );
1932 if( !aCtx.
Request.job_settings().output_path().empty() )
1937 if( !aCtx.
Request.variant_name().empty() )
1949 if( !documentValidation )
1950 return tl::unexpected( documentValidation.error() );
1952 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1953 return tl::unexpected( *busy );
1958 if( !aCtx.
Request.job_settings().output_path().empty() )
1976 ApiResponseStatus e;
1977 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1978 e.set_error_message(
"A list of fields fields or a fields preset are required" );
1979 return tl::unexpected( e );
1982 switch( aCtx.
Request.fields().filter_scope() )
1984 case kiapi::schematic::jobs::BOMFilterScope::BFS_VISIBLE:
1988 case kiapi::schematic::jobs::BOMFilterScope::BFS_ALL:
1992 case kiapi::schematic::jobs::BOMFilterScope::BFS_REFERENCE:
1998 if( aCtx.
Request.fields().sort_direction() == kiapi::schematic::jobs::BOMSortDirection::BSD_ASCENDING )
2002 else if( aCtx.
Request.fields().sort_direction() == kiapi::schematic::jobs::BOMSortDirection::BSD_DESCENDING )
2007 for(
const kiapi::schematic::jobs::BOMField& field : aCtx.
Request.fields().fields() )
2009 bomJob.
m_fieldsOrdered.emplace_back( wxString::FromUTF8( field.name() ) );
2010 bomJob.
m_fieldsLabels.emplace_back( wxString::FromUTF8( field.label() ) );
2012 if( field.group_by() )
2013 bomJob.
m_fieldsGroupBy.emplace_back( wxString::FromUTF8( field.name() ) );
2019 if( !aCtx.
Request.variant_name().empty() )
2035 if( sheetName.IsEmpty() && aSheet->
GetScreen() )
2038 sheetName = fn.GetName();
2041 aInstance->set_name( sheetName.ToUTF8() );
2042 aInstance->set_filename( aSheet->
GetFileName().ToUTF8() );
2043 aInstance->set_page_number( aPath.
GetPageNumber().ToUTF8() );
2047 std::vector<SCH_ITEM*> childSheets;
2050 std::ranges::sort( childSheets,
2062 for(
SCH_ITEM* childItem : childSheets )
2065 kiapi::schematic::types::SheetInstance* childInstance = aInstance->add_children();
2079 if( !documentValidation )
2080 return tl::unexpected( documentValidation.error() );
2082 kiapi::schematic::commands::SchematicHierarchyResponse response;
2083 response.mutable_document()->CopyFrom( aCtx.
Request.document() );
2091 std::ranges::sort( topLevelSheets,
2103 for(
SCH_SHEET* topSheet : topLevelSheets )
2105 kiapi::schematic::types::SheetInstance* instance = response.add_top_level_sheets();
2121 ApiResponseStatus status;
2122 status.set_status( ApiStatusCode::AS_BUSY );
2123 status.set_error_message(
"Cannot rebuild connectivity during an interactive operation" );
2124 return tl::unexpected( status );
2129 if( !documentValidation )
2130 return tl::unexpected( documentValidation.error() );
2132 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2133 return tl::unexpected( *busy );
2136 const bool filterByType = aCtx.
Request.types_size() > 0;
2138 static const std::set<KICAD_T> s_netlistTypes = {
2153 std::set<KICAD_T> typeFilter(
types.begin(),
types.end() );
2154 std::erase_if( typeFilter, [](
KICAD_T aType ) {
return !s_netlistTypes.contains( aType ); } );
2156 if( filterByType && typeFilter.empty() )
2158 ApiResponseStatus e;
2159 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2160 e.set_error_message(
"none of the requested types are valid for a netlist object" );
2161 return tl::unexpected( e );
2166 if( !connectionGraph )
2168 ApiResponseStatus e;
2169 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2170 e.set_error_message(
"schematic has no connection graph" );
2171 return tl::unexpected( e );
2180 catch(
const std::exception& error )
2184 m_frame->ShowInfoBarError(
_(
"Unable to rebuild schematic connectivity." ),
true );
2188 wxLogTrace(
traceApi, wxS(
"GetSchematicNetlist rebuild failed: %s" ),
2189 wxString::FromUTF8( error.what() ) );
2191 ApiResponseStatus status;
2192 status.set_status( ApiStatusCode::AS_UNKNOWN );
2193 status.set_error_message( error.what() );
2194 return tl::unexpected( status );
2198 kiapi::schematic::commands::SchematicNetlistResponse response;
2199 response.mutable_document()->CopyFrom( aCtx.
Request.document() );
2203 for(
const auto&
group :
schematic()->Connectivity().GetNetMap() )
2205 if(
group.instances.empty() || !
group.instances.front().IsNet()
2206 || !
group.instances.front().Driver() )
2211 kiapi::schematic::types::SchematicNet* net =
nullptr;
2213 for(
const auto& view :
group.instances )
2215 const auto physicalItems = view.Items();
2217 if( physicalItems.empty() )
2222 net = response.add_nets();
2223 net->set_name(
group.name.ToUTF8() );
2226 auto* sheet = net->add_sheets();
2229 for(
SCH_ITEM* item : physicalItems )
2231 if( !filterByType || typeFilter.contains( item->Type() ) )
2232 sheet->add_items()->set_value( item->m_Uuid.AsStdString() );
2240 for(
const auto& [key, subgraphList] : connectionGraph->
GetNetMap() )
2242 if( subgraphList.empty() )
2253 kiapi::schematic::types::SchematicNet* net = response.add_nets();
2254 net->set_name( key.Name.ToUTF8() );
2258 kiapi::schematic::types::SchematicNetSheetContents* sheetContents = net->add_sheets();
2259 PackSheetPath( *sheetContents->mutable_path(), subGraph->GetSheet() );
2261 for(
SCH_ITEM* item : subGraph->GetItems() )
2263 if( filterByType && !typeFilter.contains( item->Type() ) )
2266 sheetContents->add_items()->set_value( item->m_Uuid.AsStdString() );
2279 wxLogTrace(
traceApi,
"Received announce from frame %d at %s",
2285 CrossProbeAnnounceResponse response;
2286 response.set_status( CPS_OK );
2292 std::unordered_map<wxString, std::vector<SCH_REFERENCE>>& aSyncSymMap,
2293 std::unordered_map<wxString, std::unordered_map<wxString, SCH_PIN*>>& aSyncPinMap,
2294 const wxString& aVariantName = wxEmptyString,
bool aRecursive =
false )
2304 findSymbolsAndPins( aSchematicSheetList, candidate, aSyncSymMap, aSyncPinMap, aVariantName, aRecursive );
2312 for(
unsigned ii = 0; ii < references.
GetCount(); ii++ )
2324 if( fullRef.StartsWith( wxS(
"#" ) ) )
2328 if( refNum.compare( wxS(
"?" ) ) == 0 )
2332 auto symMatchIt = aSyncSymMap.find( fullRef );
2334 if( symMatchIt != aSyncSymMap.end() )
2336 symMatchIt->second.emplace_back( schRef );
2343 auto symPinMatchIt = aSyncPinMap.find( fullRef );
2345 if( symPinMatchIt != aSyncPinMap.end() )
2347 std::unordered_map<wxString, SCH_PIN*>& pinMap = symPinMatchIt->second;
2348 std::vector<SCH_PIN*> pinsOnSheet = symbol->
GetPins( &aSheetPath );
2352 int pinUnit =
pin->GetLibPin() ?
pin->GetLibPin()->GetUnit() :
ALL_UNITS;
2354 if( pinUnit > 0 && pinUnit != schRef.
GetUnit() )
2359 for(
const wxString&
pad :
2362 auto pinIt = pinMap.find(
pad );
2364 if( pinIt != pinMap.end() )
2366 pinIt->second =
pin;
2380 std::unordered_map<wxString, std::vector<SCH_REFERENCE>>& aSyncSymMap,
2381 std::unordered_map<wxString, std::unordered_map<wxString, SCH_PIN*>>& aSyncPinMap,
2382 std::unordered_map<SCH_SHEET_PATH, bool>& aCache )
2384 auto cacheIt = aCache.find( aSheetPath );
2386 if( cacheIt != aCache.end() )
2387 return cacheIt->second;
2396 aSyncPinMap, aCache );
2400 aCache.emplace( aSheetPath,
false );
2410 aCache.emplace( aSheetPath,
false );
2414 for(
unsigned ii = 0; ii < references.
GetCount(); ii++ )
2425 if( fullRef.StartsWith( wxS(
"#" ) ) )
2429 if( refNum.compare( wxS(
"?" ) ) == 0 )
2432 if( aSyncSymMap.find( fullRef ) == aSyncSymMap.end() )
2434 aCache.emplace( aSheetPath,
false );
2438 if( aSyncPinMap.find( fullRef ) != aSyncPinMap.end() )
2440 aCache.emplace( aSheetPath,
false );
2445 aCache.emplace( aSheetPath,
true );
2450std::optional<std::tuple<SCH_SHEET_PATH, SCH_ITEM*, std::vector<SCH_ITEM*>>>
2452 const kiapi::common::commands::SyncSelection& aSync )
2454 std::unordered_map<wxString, std::vector<SCH_REFERENCE>> syncSymMap;
2455 std::unordered_map<wxString, std::unordered_map<wxString, SCH_PIN*>> syncPinMap;
2456 std::unordered_map<SCH_SHEET_PATH, bool> fullyWantedCache;
2458 std::optional<wxString> focusSymbol;
2459 std::optional<std::pair<wxString, wxString>> focusPin;
2460 std::unordered_map<SCH_SHEET_PATH, std::vector<SCH_ITEM*>> focusItemResults;
2465 std::vector<SCH_SHEET_PATH> orderedSheets;
2466 orderedSheets.reserve( allSheetsList.size() );
2472 orderedSheets.push_back( sheetPath );
2475 const bool focusOnFirst = ( aSync.mode() == kiapi::common::commands::SSM_ITEMS_AND_NETS ) && aSync.has_focus_item();
2477 for(
const kiapi::common::commands::SelectionSpec& spec : aSync.items() )
2479 switch( spec.spec_case() )
2481 case kiapi::common::commands::SelectionSpec::kFootprint:
2483 wxString symRef = wxString::FromUTF8( spec.footprint().reference() );
2484 syncSymMap[symRef] = std::vector<SCH_REFERENCE>();
2488 case kiapi::common::commands::SelectionSpec::kPad:
2490 wxString symRef = wxString::FromUTF8( spec.pad().reference() );
2491 wxString padNum = wxString::FromUTF8( spec.pad().number() );
2492 syncPinMap[symRef][padNum] =
nullptr;
2503 const kiapi::common::commands::SelectionSpec& focusSpec = aSync.focus_item();
2505 if( focusSpec.has_footprint() )
2506 focusSymbol = wxString::FromUTF8( focusSpec.footprint().reference() );
2507 else if( focusSpec.has_pad() )
2508 focusPin = std::make_pair( wxString::FromUTF8( focusSpec.pad().reference() ),
2509 wxString::FromUTF8( focusSpec.pad().number() ) );
2513 auto flattenSyncMaps =
2514 [&syncSymMap, &syncPinMap]() -> std::vector<SCH_ITEM*>
2516 std::vector<SCH_ITEM*> allVec;
2518 for(
const auto& [symRef, symbols] : syncSymMap )
2521 allVec.push_back( ref.GetSymbol() );
2524 for(
const auto& [symRef, pinMap] : syncPinMap )
2526 for(
const auto& [padNum,
pin] : pinMap )
2529 allVec.push_back(
pin );
2536 auto clearSyncMaps =
2537 [&syncSymMap, &syncPinMap]()
2539 for(
auto& [symRef, symbols] : syncSymMap )
2542 for(
auto& [reference, pins] : syncPinMap )
2544 for(
auto& [number,
pin] : pins )
2549 auto syncMapsValuesEmpty =
2550 [&syncSymMap, &syncPinMap]() ->
bool
2552 for(
const auto& [symRef, symbols] : syncSymMap )
2554 if( symbols.size() > 0 )
2558 for(
const auto& [symRef, pins] : syncPinMap )
2560 for(
const auto& [padNum,
pin] : pins )
2570 auto checkFocusItems =
2575 auto findIt = syncSymMap.find( *focusSymbol );
2577 if( findIt != syncSymMap.end() )
2579 if( findIt->second.size() > 0 )
2580 focusItemResults[aSheet].push_back( findIt->second.front().GetSymbol() );
2585 auto findIt = syncPinMap.find( focusPin->first );
2587 if( findIt != syncPinMap.end() )
2589 if( findIt->second[focusPin->second] )
2590 focusItemResults[aSheet].push_back( findIt->second[focusPin->second] );
2595 auto makeRetForSheet =
2602 std::vector<SCH_ITEM*> itemsVector = flattenSyncMaps();
2608 kiidPath.push_back( item->m_Uuid );
2610 std::optional<SCH_SHEET_PATH> subsheetPath =
2617 syncPinMap, fullyWantedCache ) )
2619 itemsVector.push_back( item );
2623 return std::make_tuple( aSheet, aFocusItem, itemsVector );
2634 checkFocusItems( sheetPath );
2637 if( focusItemResults.size() > 0 )
2641 const std::vector<SCH_ITEM*>& items = focusItemResults[sheetPath];
2643 if( !items.empty() )
2644 return makeRetForSheet( sheetPath, items.front() );
2656 if( !syncMapsValuesEmpty() )
2659 return makeRetForSheet( sheetPath,
nullptr );
2664 return std::nullopt;
2671 if( std::optional<ApiResponseStatus> headless =
checkForHeadless(
"SyncSelection" ) )
2672 return tl::unexpected( *headless );
2674 SyncSelectionResponse response;
2678 if( !settings.
on_selection && aCtx.
Request.context() != SyncSelectionContext::SSC_EXPLICIT )
2680 response.set_status( CPS_DISABLED );
2681 response.set_message(
"implicit selection sync disabled by user" );
2686 if( aCtx.
Request.items_size() == 0 )
2694 response.set_status( CPS_OK );
2698 std::optional<std::tuple<SCH_SHEET_PATH, SCH_ITEM*, std::vector<SCH_ITEM*>>> findRet =
2703 auto& [sheetPath, focusItem, items] = *findRet;
2711 if(
frame()->eeconfig()->m_CrossProbing.flash_selection )
2722 std::vector<SCH_ITEM*> itemPtrs;
2723 std::copy( items.begin(), items.end(), std::back_inserter( itemPtrs ) );
2734 response.set_status( CPS_OK );
2742 if( std::optional<ApiResponseStatus> headless =
checkForHeadless(
"HighlightNets" ) )
2743 return tl::unexpected( *headless );
2745 HighlightNetsResponse response;
2753 response.set_status( CPS_DISABLED );
2760 if( aCtx.
Request.net_name_size() > 0 )
2761 net = wxString::FromUTF8( aCtx.
Request.net_name( 0 ) );
2765 response.set_status( CPS_OK );
2776 if( !documentValidation )
2777 return tl::unexpected( documentValidation.error() );
2781 if( aCtx.
Request.document().has_sheet_path() )
2785 if( std::optional<SCH_SHEET_PATH> resolvedPath =
schematic()->Hierarchy().GetSheetPathByKIIDPath( kiidPath ) )
2787 path = *resolvedPath;
2791 ExpandTextVariablesResponse reply;
2793 std::function<bool( wxString* )> textResolver =
2794 [&]( wxString* token ) ->
bool
2801 for(
const std::string& textMsg : aCtx.
Request.text() )
2805 if( aCtx.
Request.expand_env_vars() )
2808 reply.add_text(
text.ToUTF8() );
2818 return tl::unexpected( documentValidation.error() );
2820 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2821 return tl::unexpected( *busy );
2823 VariantsResponse response;
2825 response.mutable_document()->CopyFrom( aCtx.
Request.document() );
2827 for(
const wxString&
name :
schematic()->GetVariantNames() )
2829 types::DesignVariant* var = response.add_variants();
2830 var->set_name(
name.ToUTF8() );
2831 var->set_description(
schematic()->GetVariantDescription(
name ).ToUTF8() );
2841 return tl::unexpected( documentValidation.error() );
2843 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2844 return tl::unexpected( *busy );
2847 wxString
name = wxString::FromUTF8( aCtx.
Request.name() );
2851 ApiResponseStatus e;
2852 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2853 e.set_error_message( fmt::format(
"'{}' is not a usable new variant name", aCtx.
Request.name() ) );
2854 return tl::unexpected( e );
2864 if( aCtx.
Request.has_description() )
2887 return tl::unexpected( documentValidation.error() );
2889 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2890 return tl::unexpected( *busy );
2893 wxString
name = wxString::FromUTF8( aCtx.
Request.name() );
2897 ApiResponseStatus e;
2898 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2899 e.set_error_message( fmt::format(
"'{}' is not a valid variant name", aCtx.
Request.name() ) );
2900 return tl::unexpected( e );
2905 ApiResponseStatus e;
2906 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2907 e.set_error_message( fmt::format(
"no variant named '{}' exists", aCtx.
Request.name() ) );
2908 return tl::unexpected( e );
2913 bool pushedCommit =
false;
2920 if( !commit.
Empty() )
2923 pushedCommit =
true;
2937 if(
frame()->Schematic().GetCurrentVariant().CmpNoCase(
name ) == 0 )
2951 return tl::unexpected( documentValidation.error() );
2953 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2954 return tl::unexpected( *busy );
2957 wxString oldName = wxString::FromUTF8( aCtx.
Request.old_name() );
2958 wxString newName = wxString::FromUTF8( aCtx.
Request.new_name() );
2962 ApiResponseStatus e;
2963 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2964 e.set_error_message( fmt::format(
"'{}' is not a valid variant name", aCtx.
Request.old_name() ) );
2965 return tl::unexpected( e );
2970 ApiResponseStatus e;
2971 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2972 e.set_error_message( fmt::format(
"'{}' is not a valid variant name", aCtx.
Request.new_name() ) );
2973 return tl::unexpected( e );
2978 ApiResponseStatus e;
2979 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2980 e.set_error_message( fmt::format(
"no variant named '{}' exists", aCtx.
Request.old_name() ) );
2981 return tl::unexpected( e );
2986 ApiResponseStatus e;
2987 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2988 e.set_error_message( fmt::format(
"a variant named '{}' already exists", aCtx.
Request.new_name() ) );
2989 return tl::unexpected( e );
2996 bool pushedCommit =
false;
2999 oldName = *canonicalOld;
3001 schematic->RenameVariant( oldName, newName, &commit );
3003 if( !commit.
Empty() )
3006 pushedCommit =
true;
3034 return tl::unexpected( documentValidation.error() );
3036 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
3037 return tl::unexpected( *busy );
3040 wxString oldName = wxString::FromUTF8( aCtx.
Request.old_name() );
3041 wxString newName = wxString::FromUTF8( aCtx.
Request.new_name() );
3045 ApiResponseStatus e;
3046 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3047 e.set_error_message( fmt::format(
"'{}' is not a valid variant name", aCtx.
Request.old_name() ) );
3048 return tl::unexpected( e );
3053 ApiResponseStatus e;
3054 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3055 e.set_error_message( fmt::format(
"'{}' is not a valid variant name", aCtx.
Request.new_name() ) );
3056 return tl::unexpected( e );
3061 ApiResponseStatus e;
3062 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3063 e.set_error_message( fmt::format(
"no variant named '{}' exists", aCtx.
Request.old_name() ) );
3064 return tl::unexpected( e );
3069 ApiResponseStatus e;
3070 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3071 e.set_error_message( fmt::format(
"a variant named '{}' already exists", aCtx.
Request.new_name() ) );
3072 return tl::unexpected( e );
3077 bool pushedCommit =
false;
3080 oldName = *canonicalOld;
3082 schematic->CopyVariant( oldName, newName, &commit );
3084 if( aCtx.
Request.has_new_description() )
3085 schematic->SetVariantDescription( newName, wxString::FromUTF8( aCtx.
Request.new_description() ) );
3087 if( !commit.
Empty() )
3090 pushedCommit =
true;
3114 return tl::unexpected( documentValidation.error() );
3116 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
3117 return tl::unexpected( *busy );
3120 wxString
name = wxString::FromUTF8( aCtx.
Request.name() );
3124 ApiResponseStatus e;
3125 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3126 e.set_error_message( fmt::format(
"no variant named '{}' exists", aCtx.
Request.name() ) );
3127 return tl::unexpected( e );
3153 return tl::unexpected( documentValidation.error() );
3155 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
3156 return tl::unexpected( *busy );
3164 ApiResponseStatus e;
3165 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3166 e.set_error_message( fmt::format(
"no variant named '{}' exists", aCtx.
Request.name() ) );
3167 return tl::unexpected( e );
3171 wxString
name = aCtx.
Request.has_name() ? wxString::FromUTF8( aCtx.
Request.name() ) : wxString();
3189 return tl::unexpected( documentValidation.error() );
3191 CurrentVariantResponse response;
3193 if( wxString current =
schematic()->GetCurrentVariant(); !current.
IsEmpty() )
3194 response.set_name( current.ToUTF8() );
3205 ApiResponseStatus e;
3206 e.set_status( ApiStatusCode::AS_UNHANDLED );
3207 return tl::unexpected( e );
3210 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
3211 return tl::unexpected( *busy );
3217 ApiResponseStatus e;
3218 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3219 e.set_error_message(
"lib_id must specify both a library nickname and an entry name" );
3220 return tl::unexpected( e );
3232 ApiResponseStatus e;
3233 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3234 e.set_error_message( fmt::format(
"error loading symbol '{}' from library", libId.
Format().
wx_str() ) );
3235 return tl::unexpected( e );
3240 ApiResponseStatus e;
3241 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3242 e.set_error_message( fmt::format(
"symbol '{}' not found", libId.
Format().
wx_str() ) );
3243 return tl::unexpected( e );
3249 if( aCtx.
Request.header().document().has_sheet_path() )
3259 ApiResponseStatus e;
3260 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3261 e.set_error_message( fmt::format(
"the requested sheet path {} is not valid for this schematic",
3263 return tl::unexpected( e );
3269 int unit = aCtx.
Request.has_unit() ? aCtx.
Request.unit().unit() : 1;
3273 ApiResponseStatus e;
3274 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3275 e.set_error_message( fmt::format(
"unit {} is out of range for symbol '{}' ({} units)", unit,
3277 return tl::unexpected( e );
3282 std::unique_ptr<SCH_SYMBOL> symbol(
3283 std::make_unique<SCH_SYMBOL>( *libSymbol, libId, &targetPath, unit, 0, position ) );
3285 if( aCtx.
Request.has_orientation() )
3288 if( !aCtx.
Request.reference().empty() )
3291 wxString error = symbol->BaseRefFromUser( targetPath, wxString::FromUTF8( aCtx.
Request.reference() ), base,
3294 if( !error.IsEmpty() )
3296 ApiResponseStatus e;
3297 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3298 e.set_error_message( error.ToStdString() );
3299 return tl::unexpected( e );
3302 symbol->SetRef( &targetPath, base );
3313 annotate |=
frame->eeconfig()->m_AnnotatePanel.automatic;
3320 std::vector<SCH_SHEET_PATH> paths = { targetPath };
3322 if(
schematic()->Settings().m_AnnotateReusedSheetSuffixes )
3326 paths.assign( screenPaths.begin(), screenPaths.end() );
3335 if(
frame->eeconfig()->m_AutoplaceFields.enable )
3341 commit->
Add( placed, targetScreen );
3346 PlaceFromLibraryResponse response;
3347 response.mutable_header()->CopyFrom( aCtx.
Request.header() );
3349 kiapi::schematic::types::SchematicSymbolInstance packed;
3352 (void) response.mutable_item()->PackFrom( packed );
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
tl::expected< T, ApiResponseStatus > HANDLER_RESULT
static std::optional< ApiResponseStatus > applySchematicPlotSettings(const schematic::jobs::SchematicPlotSettings &aSettings, const types::DocumentSpecifier &aDocument, JOB_EXPORT_SCH_PLOT &aJob)
HANDLER_RESULT< types::RunJobResponse > ExecuteSchematicJob(KIWAY *aKiway, JOB &aJob)
bool findSymbolsAndPins(const SCH_SHEET_LIST &aSchematicSheetList, const SCH_SHEET_PATH &aSheetPath, std::unordered_map< wxString, std::vector< SCH_REFERENCE > > &aSyncSymMap, std::unordered_map< wxString, std::unordered_map< wxString, SCH_PIN * > > &aSyncPinMap, const wxString &aVariantName=wxEmptyString, bool aRecursive=false)
std::optional< std::tuple< SCH_SHEET_PATH, SCH_ITEM *, std::vector< SCH_ITEM * > > > findItemsFromSyncSelection(const SCHEMATIC &aSchematic, const kiapi::common::commands::SyncSelection &aSync)
bool sheetContainsOnlyWantedItems(const SCH_SHEET_LIST &aSchematicSheetList, const SCH_SHEET_PATH &aSheetPath, std::unordered_map< wxString, std::vector< SCH_REFERENCE > > &aSyncSymMap, std::unordered_map< wxString, std::unordered_map< wxString, SCH_PIN * > > &aSyncPinMap, std::unordered_map< SCH_SHEET_PATH, bool > &aCache)
bool ValidateSymbolInstance(kiapi::common::commands::ItemStatus *aStatus, const SCH_SYMBOL *aSymbol, const kiapi::schematic::types::SchematicSymbolInstance &aInput, const SCH_SHEET_PATH &aPath, const SCHEMATIC *aSchematic)
Check what ApplySymbolInstance would refuse, so a caller can reject a request before it changes anyth...
bool ValidateSheetInstance(commands::ItemStatus *aStatus, const SCH_SHEET *aSheet, const kiapi::schematic::types::SheetSymbol &aInput)
std::unique_ptr< EDA_ITEM > CreateItemForType(KICAD_T aType, EDA_ITEM *aContainer)
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...
std::optional< wxString > FindVariantNoCase(const SCHEMATIC *aSchematic, const wxString &aName)
Variant names are stored and compared exactly, but SCHEMATIC::HasVariant matches case-insensitively.
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...
BASE_SCREEN class implementation.
constexpr EDA_IU_SCALE schIUScale
static TOOL_ACTION selectionClear
Clear the current selection.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
HANDLER_RESULT< bool > validateDocument(const DocumentSpecifier &aDocument)
HANDLER_RESULT< types::PageSettings > handleSetPageSettings(const HANDLER_CONTEXT< commands::SetPageSettings > &aCtx)
HANDLER_RESULT< std::optional< KIID > > validateItemHeaderDocument(const kiapi::common::types::ItemHeader &aHeader)
If the header is valid, returns the item container.
HANDLER_RESULT< types::PageSettings > handleGetPageSettings(const HANDLER_CONTEXT< commands::GetPageSettings > &aCtx)
API_HANDLER_EDITOR(EDA_BASE_FRAME *aFrame=nullptr)
static std::vector< KICAD_T > parseRequestedItemTypes(const google::protobuf::RepeatedField< int > &aTypes)
COMMIT * getCurrentCommit(const std::string &aClientName)
virtual void pushCurrentCommit(const std::string &aClientName, const wxString &aMessage)
std::set< std::string > m_activeClients
std::map< std::string, std::pair< KIID, std::unique_ptr< COMMIT > > > m_commits
virtual std::optional< ApiResponseStatus > checkForBusy()
Checks if the editor can accept commands.
HANDLER_RESULT< types::RunJobResponse > handleRunSchematicJobExportDxf(const HANDLER_CONTEXT< kiapi::schematic::jobs::RunSchematicJobExportDxf > &aCtx)
HANDLER_RESULT< Empty > handleFocusOnItems(const HANDLER_CONTEXT< commands::FocusOnItems > &aCtx)
wxString getDrawingSheetFileName() override
HANDLER_RESULT< types::RunJobResponse > handleRunSchematicJobExportPng(const HANDLER_CONTEXT< kiapi::schematic::jobs::RunSchematicJobExportPng > &aCtx)
HANDLER_RESULT< kiapi::schematic::tasks::ErcTaskResult > handleGetErcTaskResult(const HANDLER_CONTEXT< kiapi::schematic::tasks::GetErcTaskResult > &aCtx)
HANDLER_RESULT< Empty > handleSetCurrentVariant(const HANDLER_CONTEXT< commands::SetCurrentVariant > &aCtx)
HANDLER_RESULT< kiapi::schematic::commands::SchematicHierarchyResponse > handleGetSchematicHierarchy(const HANDLER_CONTEXT< kiapi::schematic::commands::GetSchematicHierarchy > &aCtx)
HANDLER_RESULT< commands::VariantsResponse > handleGetVariants(const HANDLER_CONTEXT< commands::GetVariants > &aCtx)
std::unique_ptr< COMMIT > createCommit() override
Override this to create an appropriate COMMIT subclass for the frame in question.
SCHEMATIC * schematic() const
HANDLER_RESULT< commands::SelectionResponse > handleGetSelection(const HANDLER_CONTEXT< commands::GetSelection > &aCtx)
HANDLER_RESULT< Empty > handleCopyVariant(const HANDLER_CONTEXT< commands::CopyVariant > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunSchematicJobExportPdf(const HANDLER_CONTEXT< kiapi::schematic::jobs::RunSchematicJobExportPdf > &aCtx)
SCH_SCREEN * resolveScreenFromDocument(const DocumentSpecifier &aDocument) const
Returns the sheet path's screen when one is given and it is found, or null.
HANDLER_RESULT< commands::CurrentVariantResponse > handleGetCurrentVariant(const HANDLER_CONTEXT< commands::GetCurrentVariant > &aCtx)
static std::set< KICAD_T > s_allowedTypes
HANDLER_RESULT< commands::GetItemsResponse > handleGetItemsById(const HANDLER_CONTEXT< commands::GetItemsById > &aCtx)
HANDLER_RESULT< google::protobuf::Empty > handleSaveDocument(const HANDLER_CONTEXT< commands::SaveDocument > &aCtx)
std::optional< PAGE_INFO > getPageSettings(const DocumentSpecifier &aDocument) override
HANDLER_RESULT< kiapi::schematic::commands::SchematicNetlistResponse > handleGetSchematicNetlist(const HANDLER_CONTEXT< kiapi::schematic::commands::GetSchematicNetlist > &aCtx)
std::optional< SCH_ITEM * > getItemById(const KIID &aId, SCH_SHEET_PATH *aPathOut=nullptr) const
std::shared_ptr< SCH_CONTEXT > m_context
std::optional< EDA_ITEM * > getItemFromDocument(const DocumentSpecifier &aDocument, const KIID &aId) override
TOOL_MANAGER * toolManager() const
HANDLER_RESULT< types::RunJobResponse > handleRunSchematicJobExportSvg(const HANDLER_CONTEXT< kiapi::schematic::jobs::RunSchematicJobExportSvg > &aCtx)
HANDLER_RESULT< Empty > handleDeleteVariant(const HANDLER_CONTEXT< commands::DeleteVariant > &aCtx)
HANDLER_RESULT< Empty > handleClearSelection(const HANDLER_CONTEXT< commands::ClearSelection > &aCtx)
HANDLER_RESULT< commands::HighlightNetsResponse > handleHighlightNets(const HANDLER_CONTEXT< commands::HighlightNets > &aCtx)
std::optional< ApiResponseStatus > checkForHeadless(const std::string &aCommandName) const
bool setPageSettings(const DocumentSpecifier &aDocument, const PAGE_INFO &aPageInfo) override
HANDLER_RESULT< commands::SavedSelectionResponse > handleSaveSelectionToString(const HANDLER_CONTEXT< commands::SaveSelectionToString > &aCtx)
HANDLER_RESULT< commands::CrossProbeAnnounceResponse > handleCrossProbeAnnounce(const HANDLER_CONTEXT< commands::CrossProbeAnnounce > &aCtx)
HANDLER_RESULT< std::unique_ptr< EDA_ITEM > > createItemForType(KICAD_T aType, EDA_ITEM *aContainer)
HANDLER_RESULT< kiapi::common::commands::PlaceFromLibraryResponse > handlePlaceSymbolFromLibrary(const HANDLER_CONTEXT< kiapi::schematic::commands::PlaceSymbolFromLibrary > &aCtx)
HANDLER_RESULT< commands::GetDocumentModifiedStateResponse > handleGetDocumentModifiedState(const HANDLER_CONTEXT< commands::GetDocumentModifiedState > &aCtx) override
HANDLER_RESULT< Empty > handleRenameVariant(const HANDLER_CONTEXT< commands::RenameVariant > &aCtx)
void filterValidSchTypes(std::set< KICAD_T > &aTypeList)
std::optional< TITLE_BLOCK * > getTitleBlock(const DocumentSpecifier &aDocument) override
HANDLER_RESULT< types::RunJobResponse > handleRunSchematicJobExportBOM(const HANDLER_CONTEXT< kiapi::schematic::jobs::RunSchematicJobExportBOM > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunSchematicJobExportPs(const HANDLER_CONTEXT< kiapi::schematic::jobs::RunSchematicJobExportPs > &aCtx)
HANDLER_RESULT< commands::SavedDocumentResponse > handleSaveDocumentToString(const HANDLER_CONTEXT< commands::SaveDocumentToString > &aCtx)
PROJECT & project() const
void onModified() override
API_HANDLER_SCH(SCH_EDIT_FRAME *aFrame)
bool packSchItem(google::protobuf::Any &aOut, SCH_ITEM *aItem, const SCH_SHEET_PATH &aPath)
Serializes a schematic item into aOut, using path-aware packing for symbols and sheets.
HANDLER_RESULT< Empty > handleAddVariant(const HANDLER_CONTEXT< commands::AddVariant > &aCtx)
kiapi::common::types::DocumentType thisDocumentType() const override
Override this to specify which document type this editor handles.
HANDLER_RESULT< types::ItemRequestStatus > handleCreateUpdateItemsInternal(bool aCreate, const std::string &aClientName, const types::ItemHeader &aHeader, const google::protobuf::RepeatedPtrField< google::protobuf::Any > &aItems, std::function< void(commands::ItemStatus, google::protobuf::Any)> aItemHandler) override
HANDLER_RESULT< commands::GetOpenDocumentsResponse > handleGetOpenDocuments(const HANDLER_CONTEXT< commands::GetOpenDocuments > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunSchematicJobExportNetlist(const HANDLER_CONTEXT< kiapi::schematic::jobs::RunSchematicJobExportNetlist > &aCtx)
HANDLER_RESULT< google::protobuf::Empty > handleRevertDocument(const HANDLER_CONTEXT< commands::RevertDocument > &aCtx)
HANDLER_RESULT< commands::SelectionResponse > handleAddToSelection(const HANDLER_CONTEXT< commands::AddToSelection > &aCtx)
HANDLER_RESULT< commands::SelectionResponse > handleRemoveFromSelection(const HANDLER_CONTEXT< commands::RemoveFromSelection > &aCtx)
void onNetSettingsChanged() override
Called on all registered handlers after project net settings (netclasses or netclass assignments) hav...
HANDLER_RESULT< kiapi::common::tasks::StartTaskResponse > handleStartErcTask(const HANDLER_CONTEXT< kiapi::schematic::tasks::StartErcTask > &aCtx)
HANDLER_RESULT< commands::ExpandTextVariablesResponse > handleExpandTextVariables(const HANDLER_CONTEXT< commands::ExpandTextVariables > &aCtx)
void deleteItemsInternal(std::map< KIID, ItemDeletionStatus > &aItemsToDelete, const std::string &aClientName) override
void packSheetInstance(kiapi::schematic::types::SheetInstance *aInstance, SCH_SHEET_PATH &aPath, SCH_SHEET *aSheet)
tl::expected< bool, ApiResponseStatus > validateDocumentInternal(const DocumentSpecifier &aDocument) const override
HANDLER_RESULT< commands::SyncSelectionResponse > handleSyncSelection(const HANDLER_CONTEXT< commands::SyncSelection > &aCtx)
SCH_EDIT_FRAME * frame() const
HANDLER_RESULT< google::protobuf::Empty > handleSaveCopyOfDocument(const HANDLER_CONTEXT< commands::SaveCopyOfDocument > &aCtx)
SCH_CONTEXT * context() const
void setDrawingSheetFileName(const wxString &aFileName) override
HANDLER_RESULT< Empty > handleSetVariantDescription(const HANDLER_CONTEXT< commands::SetVariantDescription > &aCtx)
HANDLER_RESULT< commands::GetItemsResponse > handleGetItems(const HANDLER_CONTEXT< commands::GetItems > &aCtx)
HANDLER_RESULT< google::protobuf::Empty > handleSaveDocumentAs(const HANDLER_CONTEXT< commands::SaveDocumentAs > &aCtx)
KICAD_API_SERVER * apiServer() const
void registerHandler(HANDLER_RESULT< ResponseType >(HandlerType::*aHandler)(const HANDLER_CONTEXT< RequestType > &), bool aAllowedDuringTask=false)
Registers an API command handler for the given message types.
CROSS_PROBING_SETTINGS m_CrossProbing
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
void SetContentModified(bool aModified=true)
Represent a set of changes (additions, deletions or modifications) of a data model (e....
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Calculate the connectivity of a schematic and generate netlists.
const NET_MAP & GetNetMap() const
A subgraph is a set of items that are electrically connected on a single sheet.
static PRIORITY GetDriverPriority(SCH_ITEM *aDriver)
Return the priority (higher is more important) of a candidate driver.
const SCH_CONNECTION * GetDriverConnection() const
static void RegisterPeer(FRAME_T aFrameType, const std::string &aSocketPath)
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Add a command to undo in the undo list.
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
Return the last command to undo and remove it from list, nothing is deleted.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
virtual void FinalizeGroupDeserialization()
A base class for most all the KiCad significant classes used in schematics and boards.
KICAD_T Type() const
Returns the type of object.
virtual wxString GetFriendlyName() const
EE_TYPE OfType(KICAD_T aType) const
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
std::vector< wxString > m_variantNames
wxString m_stringDelimiter
wxString m_fieldDelimiter
bool m_includeByteOrderMark
std::vector< wxString > m_fieldsOrdered
wxString m_refRangeDelimiter
std::vector< wxString > m_fieldsLabels
std::vector< wxString > m_fieldsGroupBy
wxString m_bomFmtPresetName
BOM_FILTER_SCOPE m_filterScope
std::vector< wxString > m_variantNames
JOB_PAGE_SIZE m_pageSizeSelect
bool m_useBackgroundColor
std::vector< wxString > m_plotPages
An simple container class that lets us dispatch output jobs to kifaces.
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
const std::vector< JOB_OUTPUT > & GetOutputs()
const std::string & GetType() const
wxString AsString() const
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
Define a library symbol object.
int GetUnitCount() const override
Describe the page size and margins of a paper page on which to eventually print or plot.
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
void SetDescription(const wxString &aDescription)
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
Container for project specific data.
virtual const wxString GetProjectPath() const
Return the full path of the project.
virtual const wxString GetProjectName() const
Return the short name of the project.
wxString m_SchDrawingSheetFileName
Holds all the data relating to one schematic.
SCHEMATIC_SETTINGS & Settings() const
SCH_SCREEN * GetCurrentScreen() const
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) const
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
SCH_SHEET * GetTopLevelSheet(int aIndex=0) const
wxString GetCurrentVariant() const
Return the current variant being edited.
CONNECTION_GRAPH * ConnectionGraph() const
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
void RebuildConnectivity(std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr, KIGFX::SCH_VIEW *aSchView=nullptr)
std::vector< SCH_SHEET * > GetTopLevelSheets() const
Get the list of top-level sheets.
SCH_SHEET_PATH & CurrentSheet() const
static TOOL_ACTION changeSheet
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
EESCHEMA_SETTINGS * eeconfig() const
Commit for the schematic and symbol editors.
void RevertToCheckpoint(int aCheckpoint) override
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
Schematic editor (Eeschema) main window.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
void SyncVariantUI()
Refill the toolbar variant control and any open symbol fields table from the schematic.
void RefreshConnectivity(bool aForce=false, const SCH_CONNECTIVITY::CHANGE_SET *aChanges=nullptr)
void SetCurrentVariant(const wxString &aVariantName)
bool RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, PROGRESS_REPORTER *aProgressReporter=nullptr, bool aCleanupDone=false)
Generate the connection data for the entire schematic hierarchy.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
void LoadDrawingSheet()
Load the drawing sheet file.
void SetSyncingSelection(bool aSet)
void StartCrossProbeFlash(const std::vector< SCH_ITEM * > &aItems)
void HandleRemoteNetHighlight(const wxString &aNetName)
A set of SCH_ITEMs (i.e., without duplicates).
A SCH_IO derivation for loading schematic files using the new s-expression file format.
void FormatSchematicToFormatter(OUTPUTFORMATTER *aOut, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const std::map< std::string, UTF8 > *aProperties=nullptr)
Serialize a schematic sheet to an OUTPUTFORMATTER without file I/O or Prettify.
void Format(SCH_SHEET *aSheet)
Base class for any item which can be embedded within the SCHEMATIC container class,...
virtual bool IsConnectable() const
void SetConnectivityDirty(bool aDirty=true)
Set the dirty flag.
void SwapItemData(SCH_ITEM *aImage)
Swap data between aItem and aImage.
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
void SortByReferenceOnly()
Sort the list of references by reference.
A helper to define a symbol's reference designator in a schematic.
wxString GetComposedRef() const
Return the reference as shown on this sheet path, with its sheet suffix.
bool AlwaysAnnotate() const
Verify the reference should always be automatically annotated.
void Split()
Attempt to split the reference designator into a name (U) and number (1).
SCH_SYMBOL * GetSymbol() const
bool IsSplitNeeded() const
Determine if this reference needs to be split or if it likely already has been.
wxString GetRefNumber() const
EE_RTREE & Items()
Get the full RTree, usually for iterating.
const wxString & GetFileName() const
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
TITLE_BLOCK & GetTitleBlock()
void GetSheets(std::vector< SCH_ITEM * > *aItems) const
Similar to Items().OfType( SCH_SHEET_T ), but return the sheets in a deterministic order (L-R,...
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
std::optional< SCH_SHEET_PATH > GetSheetPathByKIIDPath(const KIID_PATH &aPath, bool aIncludeLastSheet=true) const
Finds a SCH_SHEET_PATH that matches the provided KIID_PATH.
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) const
Fetch a SCH_ITEM by ID.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
SCH_SHEET_LIST FindAllSheetsForScreen(const SCH_SCREEN *aScreen) const
Return a SCH_SHEET_LIST with a copy of all the SCH_SHEET_PATH using a particular screen.
wxString GetNextPageNumber() const
void GetSymbols(SCH_REFERENCE_LIST &aReferences, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
bool TestForRecursion(const SCH_SHEET_LIST &aSrcSheetHierarchy, const wxString &aDestFileName)
Test every SCH_SHEET_PATH in this SCH_SHEET_LIST to verify if adding the sheets stored in aSrcSheetHi...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
int ComparePageNum(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare sheets by their page number.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Adds SCH_REFERENCE object to aReferences for each symbol in the sheet.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_ITEM * ResolveItem(const KIID &aID) const
Fetch a SCH_ITEM by ID.
SCH_SCREEN * LastScreen()
wxString GetPageNumber() const
bool IsContainedWithin(const SCH_SHEET_PATH &aSheetPathToTest) const
Check if this path is contained inside aSheetPathToTest.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
void pop_back()
Forwarded method from std::vector.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
wxString GetFileName() const
Return the filename corresponding to this sheet.
void AddInstance(const SCH_SHEET_INSTANCE &aInstance)
SCH_SCREEN * GetScreen() const
wxString GetShownName(RESOLUTION_CONTEXT aContext) const
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
std::vector< SCH_SHEET_PIN * > & GetPins()
void SetLibId(const LIB_ID &aName)
std::vector< std::unique_ptr< SCH_PIN > > & GetRawPins()
bool UseLibIdLookup() const
wxString GetSchSymbolLibraryName() const
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
Add a full hierarchical reference to this symbol.
const LIB_ID & GetLibId() const override
void SetSchSymbolLibraryName(const wxString &aName)
The name of the symbol in the schematic library symbol list.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
virtual void Serialize(google::protobuf::Any &aContainer) const
Serializes this object to the given Any message.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
A wrapper for reporting to a wxString object.
A type-safe container of any type.
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject, bool aAllowEscapes)
Replace any environment variable & text variable references with their values.
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, RESOLUTION_CONTEXT aContext)
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
bool m_ConnectivityEngine
Use the schematic connectivity engine instead of CONNECTION_GRAPH.
static const std::string KiCadSchematicFileExtension
const wxChar *const traceCrossProbeFlash
Flag to enable debug output for cross-probe flash operations.
const wxChar *const traceApi
Flag to enable debug output related to the IPC API and its plugin system.
KICOMMON_API void PackProject(types::ProjectSpecifier &aOutput, const PROJECT &aInput)
KICOMMON_API int UnpackDistance(const types::Distance &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API KIID_PATH UnpackSheetPath(const types::SheetPath &aInput)
KICOMMON_API std::optional< KICAD_T > TypeNameFromAny(const google::protobuf::Any &aMessage)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackSheetPath(types::SheetPath &aOutput, const KIID_PATH &aInput)
KICOMMON_API LIB_ID UnpackLibId(const types::LibraryIdentifier &aId)
const KICOMMON_API std::string KiwayClientName
const KICOMMON_API std::string StandaloneCrossProbeClientName
static int plotJob(JOB_EXPORT_PCB_PLOT *aJob, PCB_PLOTTER &aPlotter, const LSEQ &aLayersToPlot, const wxString &aOutPath, bool aSingleOutput, bool aUseVarOverrides, bool aForceAllLayersToOnePage=false)
PGM_BASE & Pgm()
The global program "get" accessor.
constexpr int MIN_PNG_DPI
constexpr int MAX_PNG_DPI
std::shared_ptr< SCH_CONTEXT > CreateSchFrameContext(SCH_EDIT_FRAME *aFrame)
Class to handle a set of SCH_ITEMs.
std::vector< EDA_ITEM * > EDA_ITEMS
void AnnotateNewSymbol(SCH_SYMBOL *aSymbol, const std::vector< SCH_SHEET_PATH > &aPaths, SCH_REFERENCE_LIST &aExistingRefs, const SCHEMATIC_SETTINGS &aSettings, SCH_SHEET_LIST *aHierarchy)
Annotate a newly placed symbol on each of aPaths in turn, avoiding aExistingRefs and adding the resul...
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
@ SYMBOL_FILTER_NON_POWER
wxString GetDefaultVariantName()
std::vector< wxString > ExpandStackedPinNotation(const wxString &aPinName, bool *aValid)
Expand stacked pin notation like [1,2,3], [1-4], [A1-A4], or [AA1-AA3,AB4,CD12-CD14] into individual ...
bool on_selection
Synchronize the selection for multiple items too.
bool auto_highlight
Automatically turn on highlight mode in the target frame.
RequestMessageType Request
A simple container for sheet instance information.
A simple container for schematic symbol instance information.
IbisParser parser & reporter
wxString result
Test unit parsing edge cases and error handling.
wxLogTrace helper definitions.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().