26#include <magic_enum.hpp>
44#include <wx/filename.h>
46#include <api/common/types/base_types.pb.h>
48using namespace kiapi::common::commands;
49using kiapi::common::types::CommandStatus;
50using kiapi::common::types::DocumentType;
51using kiapi::common::types::ItemRequestStatus;
78 types::RunJobResponse response;
83 response.add_output_path(
output.m_outputPath.ToUTF8() );
87 response.set_status( types::JobStatus::JS_SUCCESS );
91 response.set_status( types::JobStatus::JS_ERROR );
92 response.set_message( fmt::format(
"Schematic export job '{}' failed with exit code {}: {}",
111 using namespace kiapi::schematic::jobs;
112 using namespace kiapi::schematic::types;
140 return std::make_unique<SCH_COMMIT>(
m_frame );
165tl::expected<bool, ApiResponseStatus>
168 if( aDocument.type() != DocumentType::DOCTYPE_SCHEMATIC )
171 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
172 e.set_error_message(
"the requested document is not a schematic" );
173 return tl::unexpected( e );
178 if( aDocument.project().name().compare( prj.
GetProjectName().ToUTF8() ) != 0 )
181 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
182 e.set_error_message( fmt::format(
"the requested project {} is not open",
183 aDocument.project().name() ) );
184 return tl::unexpected( e );
187 if( aDocument.project().path().compare( prj.
GetProjectPath().ToUTF8() ) != 0 )
190 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
191 e.set_error_message( fmt::format(
"the requested project {} is not open at path {}",
192 aDocument.project().name(),
193 aDocument.project().path() ) );
194 return tl::unexpected( e );
197 if( aDocument.has_sheet_path() )
204 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
205 e.set_error_message( fmt::format(
"the requested sheet path {} is not valid for this schematic",
206 path.AsString().ToStdString() ) );
207 return tl::unexpected( e );
218 if( aCtx.
Request.type() != DocumentType::DOCTYPE_SCHEMATIC )
223 e.set_status( ApiStatusCode::AS_UNHANDLED );
224 return tl::unexpected( e );
227 GetOpenDocumentsResponse response;
228 common::types::DocumentSpecifier doc;
230 wxFileName fn(
m_context->GetCurrentFileName() );
232 doc.set_type( DocumentType::DOCTYPE_SCHEMATIC );
234 if( std::optional<SCH_SHEET_PATH>
path =
m_context->GetCurrentSheet() )
239 response.mutable_documents()->Add( std::move( doc ) );
246 std::erase_if( aTypeList,
256 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
257 return tl::unexpected( *busy );
262 return tl::unexpected( valid.error() );
265 std::set<KICAD_T> typesRequested, typesInserted;
268 typesRequested.insert( type );
272 if( typesRequested.empty() )
275 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
276 e.set_error_message(
"none of the requested types are valid for a Schematic object" );
277 return tl::unexpected( e );
281 std::optional<SCH_SHEET_PATH> pathFilter;
283 if( aCtx.
Request.header().document().has_sheet_path() )
289 std::map<KICAD_T, std::vector<std::pair<EDA_ITEM*, SCH_SHEET_PATH>>> itemMap;
294 const SCH_SCREEN* aScreen = aPath.LastScreen();
298 itemMap[ aItem->Type() ].emplace_back( aItem, aPath );
300 aItem->RunOnChildren(
303 itemMap[ aChild->
Type() ].emplace_back( aChild, aPath );
311 processScreen( *pathFilter );
316 processScreen(
path );
319 GetItemsResponse response;
320 google::protobuf::Any
any;
327 if( typesInserted.contains( type ) )
330 for(
const auto& [item, itemPath] : itemMap[type] )
334 kiapi::schematic::types::SchematicSymbolInstance symbol;
339 any.PackFrom( symbol );
343 kiapi::schematic::types::SheetSymbol sheet;
348 any.PackFrom( sheet );
352 item->Serialize(
any );
355 response.mutable_items()->Add( std::move(
any ) );
359 response.set_status( ItemRequestStatus::IRS_OK );
366 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
367 return tl::unexpected( *busy );
372 e.set_status( ApiStatusCode::AS_UNHANDLED );
373 return tl::unexpected( e );
377 std::optional<SCH_SHEET_PATH> pathFilter;
379 if( aCtx.
Request.header().document().has_sheet_path() )
385 GetItemsResponse response;
387 google::protobuf::Any
any;
389 for(
const types::KIID& idProto : aCtx.
Request.items() )
391 KIID id( idProto.value() );
397 item = pathFilter->ResolveItem(
id );
398 itemPath = *pathFilter;
402 item = hierarchy.
ResolveItem(
id, &itemPath,
true );
410 kiapi::schematic::types::SchematicSymbolInstance symbol;
415 any.PackFrom( symbol );
419 kiapi::schematic::types::SheetSymbol sheet;
424 any.PackFrom( sheet );
431 response.mutable_items()->Add( std::move(
any ) );
434 if( response.items().empty() )
437 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
438 e.set_error_message(
"none of the requested IDs were found or valid" );
439 return tl::unexpected( e );
442 response.set_status( ItemRequestStatus::IRS_OK );
452 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
453 e.set_error_message(
"Tried to create an item in a null container" );
454 return tl::unexpected( e );
460 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
461 e.set_error_message( fmt::format(
"type {} is not supported by the schematic API handler",
462 magic_enum::enum_name( aType ) ) );
463 return tl::unexpected( e );
469 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
470 e.set_error_message( fmt::format(
"Tried to create a pin in {}, which is not a symbol",
472 return tl::unexpected( e );
477 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
478 e.set_error_message( fmt::format(
"Tried to create a sheet symbol in {}, which is not a "
481 return tl::unexpected( e );
486 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
487 e.set_error_message( fmt::format(
"Tried to create a symbol in {}, which is not a "
490 return tl::unexpected( e );
495 if( created && !created->GetParent() )
496 created->SetParent( aContainer );
501 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
502 e.set_error_message( fmt::format(
"Tried to create an item of type {}, which is unhandled",
503 magic_enum::enum_name( aType ) ) );
504 return tl::unexpected( e );
512 const std::string& aClientName,
513 const types::ItemHeader &aHeader,
514 const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems,
515 std::function<
void( ItemStatus, google::protobuf::Any )> aItemHandler )
521 if( !containerResult && containerResult.error().status() == ApiStatusCode::AS_UNHANDLED )
524 e.set_status( ApiStatusCode::AS_UNHANDLED );
525 return tl::unexpected( e );
527 else if( !containerResult )
529 e.CopyFrom( containerResult.error() );
530 return tl::unexpected( e );
537 if( aHeader.document().has_sheet_path() )
549 for(
const google::protobuf::Any& anyItem : aItems )
556 status.set_code( ItemStatusCode::ISC_INVALID_TYPE );
557 status.set_error_message( fmt::format(
"Could not decode a valid type from {}",
558 anyItem.type_url() ) );
559 aItemHandler( status, anyItem );
567 if( !creationResult )
569 status.set_code( ItemStatusCode::ISC_INVALID_TYPE );
570 status.set_error_message( creationResult.error().error_message() );
571 aItemHandler( status, anyItem );
575 std::unique_ptr<EDA_ITEM> item( std::move( *creationResult ) );
577 bool unpacked =
false;
581 kiapi::schematic::types::SchematicSymbolInstance symbol;
582 unpacked = anyItem.UnpackTo( &symbol )
587 kiapi::schematic::types::SheetSymbol sheetProto;
588 unpacked = anyItem.UnpackTo( &sheetProto );
594 if( tl::expected<bool, ApiResponseStatus>
result =
UnpackSheet( sheet, sheetProto );
606 if( instance.
m_Path.empty() )
617 return tl::unexpected(
result.error() );
623 unpacked = item->Deserialize( anyItem );
628 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
629 e.set_error_message( fmt::format(
"could not unpack {} from request",
630 item->GetClass().ToStdString() ) );
631 return tl::unexpected( e );
637 existingItem = targetPath.
ResolveItem( item->m_Uuid );
640 existingPath = targetPath;
642 if( aCreate && existingItem )
644 status.set_code( ItemStatusCode::ISC_EXISTING );
645 status.set_error_message( fmt::format(
"an item with UUID {} already exists",
646 item->m_Uuid.AsStdString() ) );
647 aItemHandler( status, anyItem );
650 else if( !aCreate && !existingItem )
652 status.set_code( ItemStatusCode::ISC_NONEXISTENT );
653 status.set_error_message( fmt::format(
"an item with UUID {} does not exist",
654 item->m_Uuid.AsStdString() ) );
655 aItemHandler( status, anyItem );
663 if( itemScreen != targetScreen )
665 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
666 status.set_error_message( fmt::format(
"item {} exists on a different sheet than targeted",
667 item->m_Uuid.AsStdString() ) );
668 aItemHandler( status, anyItem );
683 parentPath = targetPath;
685 parentPath = existingPath;
689 if( !destFilePath.IsEmpty() )
696 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
697 status.set_error_message(
"sheet update would create recursive hierarchy" );
698 aItemHandler( status, anyItem );
704 status.set_code( ItemStatusCode::ISC_OK );
705 google::protobuf::Any newItem;
710 commit->
Add( createdItem, targetScreen );
714 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
715 e.set_error_message(
"could not add the requested item to its parent container" );
716 return tl::unexpected( e );
721 kiapi::schematic::types::SchematicSymbolInstance symbol;
724 newItem.PackFrom( symbol );
728 kiapi::schematic::types::SheetSymbol sheet;
731 newItem.PackFrom( sheet );
740 commit->
Modify( existingItem, targetScreen );
746 kiapi::schematic::types::SchematicSymbolInstance symbol;
749 newItem.PackFrom( symbol );
754 kiapi::schematic::types::SheetSymbol sheet;
757 newItem.PackFrom( sheet );
765 aItemHandler( status, newItem );
771 :
_(
"Modified items via API" ) );
775 return ItemRequestStatus::IRS_OK;
780 const std::string& aClientName )
785 for(
auto& [
id, status] : aItemsToDelete )
795 status = ItemDeletionStatus::IDS_IMMUTABLE;
800 status = ItemDeletionStatus::IDS_OK;
824 wxCHECK(
m_context->GetCurrentSheet(), std::nullopt );
825 return &
m_context->GetCurrentSheet()->LastScreen()->GetTitleBlock();
831 wxCHECK(
m_context->GetCurrentSheet(), std::nullopt );
832 return m_context->GetCurrentSheet()->LastScreen()->GetPageSettings();
838 wxCHECK(
m_context->GetCurrentSheet(),
false );
839 m_context->GetCurrentSheet()->LastScreen()->SetPageSettings( aPageInfo );
873 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
874 return tl::unexpected( *busy );
878 if( !documentValidation )
879 return tl::unexpected( documentValidation.error() );
881 auto plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_SVG>();
882 plotJob->m_filename =
m_context->GetCurrentFileName();
884 if( !aCtx.
Request.job_settings().output_path().empty() )
885 plotJob->SetConfiguredOutputPath( wxString::FromUTF8( aCtx.
Request.job_settings().output_path() ) );
887 const kiapi::schematic::jobs::SchematicPlotSettings& settings = aCtx.
Request.plot_settings();
889 plotJob->m_drawingSheet = wxString::FromUTF8( settings.drawing_sheet() );
890 plotJob->m_defaultFont = wxString::FromUTF8( settings.default_font() );
891 plotJob->m_variant = wxString::FromUTF8( settings.variant() );
892 plotJob->m_plotAll = settings.plot_all();
893 plotJob->m_plotDrawingSheet = settings.plot_drawing_sheet();
894 plotJob->m_show_hop_over = settings.show_hop_over();
895 plotJob->m_blackAndWhite = settings.black_and_white();
896 plotJob->m_useBackgroundColor = settings.use_background_color();
897 plotJob->m_minPenWidth = settings.min_pen_width();
898 plotJob->m_theme = wxString::FromUTF8( settings.theme() );
900 plotJob->m_plotPages.clear();
902 for(
const std::string& page : settings.plot_pages() )
903 plotJob->m_plotPages.push_back( wxString::FromUTF8( page ) );
905 if( aCtx.
Request.plot_settings().page_size() != kiapi::schematic::jobs::SchematicJobPageSize::SJPS_UNKNOWN )
917 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
918 return tl::unexpected( *busy );
922 if( !documentValidation )
923 return tl::unexpected( documentValidation.error() );
925 auto plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_DXF>();
926 plotJob->m_filename =
m_context->GetCurrentFileName();
928 if( !aCtx.
Request.job_settings().output_path().empty() )
929 plotJob->SetConfiguredOutputPath( wxString::FromUTF8( aCtx.
Request.job_settings().output_path() ) );
931 const kiapi::schematic::jobs::SchematicPlotSettings& settings = aCtx.
Request.plot_settings();
933 plotJob->m_drawingSheet = wxString::FromUTF8( settings.drawing_sheet() );
934 plotJob->m_defaultFont = wxString::FromUTF8( settings.default_font() );
935 plotJob->m_variant = wxString::FromUTF8( settings.variant() );
936 plotJob->m_plotAll = settings.plot_all();
937 plotJob->m_plotDrawingSheet = settings.plot_drawing_sheet();
938 plotJob->m_show_hop_over = settings.show_hop_over();
939 plotJob->m_blackAndWhite = settings.black_and_white();
940 plotJob->m_useBackgroundColor = settings.use_background_color();
941 plotJob->m_minPenWidth = settings.min_pen_width();
942 plotJob->m_theme = wxString::FromUTF8( settings.theme() );
944 plotJob->m_plotPages.clear();
946 for(
const std::string& page : settings.plot_pages() )
947 plotJob->m_plotPages.push_back( wxString::FromUTF8( page ) );
949 if( aCtx.
Request.plot_settings().page_size() != kiapi::schematic::jobs::SchematicJobPageSize::SJPS_UNKNOWN )
961 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
962 return tl::unexpected( *busy );
966 if( !documentValidation )
967 return tl::unexpected( documentValidation.error() );
969 auto plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_PDF>(
false );
970 plotJob->m_filename =
m_context->GetCurrentFileName();
972 if( !aCtx.
Request.job_settings().output_path().empty() )
973 plotJob->SetConfiguredOutputPath( wxString::FromUTF8( aCtx.
Request.job_settings().output_path() ) );
975 const kiapi::schematic::jobs::SchematicPlotSettings& settings = aCtx.
Request.plot_settings();
977 plotJob->m_drawingSheet = wxString::FromUTF8( settings.drawing_sheet() );
978 plotJob->m_defaultFont = wxString::FromUTF8( settings.default_font() );
979 plotJob->m_variant = wxString::FromUTF8( settings.variant() );
980 plotJob->m_plotAll = settings.plot_all();
981 plotJob->m_plotDrawingSheet = settings.plot_drawing_sheet();
982 plotJob->m_show_hop_over = settings.show_hop_over();
983 plotJob->m_blackAndWhite = settings.black_and_white();
984 plotJob->m_useBackgroundColor = settings.use_background_color();
985 plotJob->m_minPenWidth = settings.min_pen_width();
986 plotJob->m_theme = wxString::FromUTF8( settings.theme() );
988 plotJob->m_plotPages.clear();
990 for(
const std::string& page : settings.plot_pages() )
991 plotJob->m_plotPages.push_back( wxString::FromUTF8( page ) );
993 if( aCtx.
Request.plot_settings().page_size() != kiapi::schematic::jobs::SchematicJobPageSize::SJPS_UNKNOWN )
998 plotJob->m_PDFPropertyPopups = aCtx.
Request.property_popups();
999 plotJob->m_PDFHierarchicalLinks = aCtx.
Request.hierarchical_links();
1000 plotJob->m_PDFMetadata = aCtx.
Request.include_metadata();
1009 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1010 return tl::unexpected( *busy );
1014 if( !documentValidation )
1015 return tl::unexpected( documentValidation.error() );
1017 auto plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_PS>();
1018 plotJob->m_filename =
m_context->GetCurrentFileName();
1020 if( !aCtx.
Request.job_settings().output_path().empty() )
1021 plotJob->SetConfiguredOutputPath( wxString::FromUTF8( aCtx.
Request.job_settings().output_path() ) );
1023 const kiapi::schematic::jobs::SchematicPlotSettings& settings = aCtx.
Request.plot_settings();
1025 plotJob->m_drawingSheet = wxString::FromUTF8( settings.drawing_sheet() );
1026 plotJob->m_defaultFont = wxString::FromUTF8( settings.default_font() );
1027 plotJob->m_variant = wxString::FromUTF8( settings.variant() );
1028 plotJob->m_plotAll = settings.plot_all();
1029 plotJob->m_plotDrawingSheet = settings.plot_drawing_sheet();
1030 plotJob->m_show_hop_over = settings.show_hop_over();
1031 plotJob->m_blackAndWhite = settings.black_and_white();
1032 plotJob->m_useBackgroundColor = settings.use_background_color();
1033 plotJob->m_minPenWidth = settings.min_pen_width();
1034 plotJob->m_theme = wxString::FromUTF8( settings.theme() );
1036 plotJob->m_plotPages.clear();
1038 for(
const std::string& page : settings.plot_pages() )
1039 plotJob->m_plotPages.push_back( wxString::FromUTF8( page ) );
1041 if( aCtx.
Request.plot_settings().page_size() != kiapi::schematic::jobs::SchematicJobPageSize::SJPS_UNKNOWN )
1053 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1054 return tl::unexpected( *busy );
1058 if( !documentValidation )
1059 return tl::unexpected( documentValidation.error() );
1061 if( aCtx.
Request.format() == kiapi::schematic::jobs::SchematicNetlistFormat::SNF_UNKNOWN )
1063 ApiResponseStatus e;
1064 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1065 e.set_error_message(
"RunSchematicJobExportNetlist requires a valid format" );
1066 return tl::unexpected( e );
1072 if( !aCtx.
Request.job_settings().output_path().empty() )
1077 if( !aCtx.
Request.variant_name().empty() )
1087 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1088 return tl::unexpected( *busy );
1092 if( !documentValidation )
1093 return tl::unexpected( documentValidation.error() );
1098 if( !aCtx.
Request.job_settings().output_path().empty() )
1113 if( aCtx.
Request.fields().sort_direction() == kiapi::schematic::jobs::BOMSortDirection::BSD_ASCENDING )
1117 else if( aCtx.
Request.fields().sort_direction() == kiapi::schematic::jobs::BOMSortDirection::BSD_DESCENDING )
1122 for(
const kiapi::schematic::jobs::BOMField& field : aCtx.
Request.fields().fields() )
1124 bomJob.
m_fieldsOrdered.emplace_back( wxString::FromUTF8( field.name() ) );
1125 bomJob.
m_fieldsLabels.emplace_back( wxString::FromUTF8( field.label() ) );
1127 if( field.group_by() )
1128 bomJob.
m_fieldsGroupBy.emplace_back( wxString::FromUTF8( field.name() ) );
1134 if( !aCtx.
Request.variant_name().empty() )
1150 if( sheetName.IsEmpty() && aSheet->
GetScreen() )
1153 sheetName = fn.GetName();
1156 aInstance->set_name( sheetName.ToUTF8() );
1157 aInstance->set_filename( aSheet->
GetFileName().ToUTF8() );
1158 aInstance->set_page_number( aPath.
GetPageNumber().ToUTF8() );
1162 std::vector<SCH_ITEM*> childSheets;
1165 std::ranges::sort( childSheets,
1177 for(
SCH_ITEM* childItem : childSheets )
1180 kiapi::schematic::types::SheetInstance* childInstance = aInstance->add_children();
1194 if( !documentValidation )
1195 return tl::unexpected( documentValidation.error() );
1197 kiapi::schematic::types::SchematicHierarchyResponse response;
1198 response.mutable_document()->CopyFrom( aCtx.
Request.document() );
1206 std::ranges::sort( topLevelSheets,
1218 for(
SCH_SHEET* topSheet : topLevelSheets )
1220 kiapi::schematic::types::SheetInstance* instance = response.add_top_level_sheets();
1231 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1232 return tl::unexpected( *busy );
1236 if( !documentValidation )
1237 return tl::unexpected( documentValidation.error() );
1240 const bool filterByType = aCtx.
Request.types_size() > 0;
1242 if( filterByType && types.empty() )
1244 ApiResponseStatus e;
1245 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1246 e.set_error_message(
"none of the requested types are valid for a Schematic object" );
1247 return tl::unexpected( e );
1250 std::set<KICAD_T> typeFilter( types.begin(), types.end() );
1254 if( !connectionGraph )
1256 ApiResponseStatus e;
1257 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1258 e.set_error_message(
"schematic has no connection graph" );
1259 return tl::unexpected( e );
1262 kiapi::schematic::types::SchematicNetlistResponse response;
1263 response.mutable_document()->CopyFrom( aCtx.
Request.document() );
1265 for(
const auto& [key, subgraphList] : connectionGraph->
GetNetMap() )
1267 if( subgraphList.empty() )
1278 kiapi::schematic::types::SchematicNet* net = response.add_nets();
1279 net->set_name( key.Name.ToUTF8() );
1283 kiapi::schematic::types::SchematicNetSheetContents* sheetContents = net->add_sheets();
1284 PackSheetPath( *sheetContents->mutable_path(), subGraph->GetSheet().Path() );
1286 for(
SCH_ITEM* item : subGraph->GetItems() )
1288 if( filterByType && !typeFilter.contains( item->Type() ) )
1291 sheetContents->add_items()->set_value( item->m_Uuid.AsStdString() );
KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
tl::expected< T, ApiResponseStatus > HANDLER_RESULT
HANDLER_RESULT< types::RunJobResponse > ExecuteSchematicJob(KIWAY *aKiway, JOB &aJob)
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)
bool PackSheet(kiapi::schematic::types::SheetSymbol *aOutput, const SCH_SHEET *aInput, const SCH_SHEET_PATH &aPath)
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)
BASE_SCREEN class implementation.
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
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)
std::optional< TITLE_BLOCK * > getTitleBlock() override
wxString getDrawingSheetFileName() override
HANDLER_RESULT< kiapi::schematic::types::SchematicHierarchyResponse > handleGetSchematicHierarchy(const HANDLER_CONTEXT< kiapi::schematic::types::GetSchematicHierarchy > &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< kiapi::schematic::types::SchematicNetlistResponse > handleGetSchematicNetlist(const HANDLER_CONTEXT< kiapi::schematic::types::GetSchematicNetlist > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunSchematicJobExportPdf(const HANDLER_CONTEXT< kiapi::schematic::jobs::RunSchematicJobExportPdf > &aCtx)
static std::set< KICAD_T > s_allowedTypes
HANDLER_RESULT< commands::GetItemsResponse > handleGetItemsById(const HANDLER_CONTEXT< commands::GetItemsById > &aCtx)
std::optional< SCH_ITEM * > getItemById(const KIID &aId, SCH_SHEET_PATH *aPathOut=nullptr) const
bool setPageSettings(const PAGE_INFO &aPageInfo) override
std::shared_ptr< SCH_CONTEXT > m_context
std::optional< EDA_ITEM * > getItemFromDocument(const DocumentSpecifier &aDocument, const KIID &aId) override
HANDLER_RESULT< types::RunJobResponse > handleRunSchematicJobExportSvg(const HANDLER_CONTEXT< kiapi::schematic::jobs::RunSchematicJobExportSvg > &aCtx)
HANDLER_RESULT< std::unique_ptr< EDA_ITEM > > createItemForType(KICAD_T aType, EDA_ITEM *aContainer)
void filterValidSchTypes(std::set< KICAD_T > &aTypeList)
HANDLER_RESULT< types::RunJobResponse > handleRunSchematicJobExportBOM(const HANDLER_CONTEXT< kiapi::schematic::jobs::RunSchematicJobExportBOM > &aCtx)
std::optional< PAGE_INFO > getPageSettings() override
HANDLER_RESULT< types::RunJobResponse > handleRunSchematicJobExportPs(const HANDLER_CONTEXT< kiapi::schematic::jobs::RunSchematicJobExportPs > &aCtx)
void onModified() override
API_HANDLER_SCH(SCH_EDIT_FRAME *aFrame)
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)
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
void setDrawingSheetFileName(const wxString &aFileName) override
HANDLER_RESULT< commands::GetItemsResponse > handleGetItems(const HANDLER_CONTEXT< commands::GetItems > &aCtx)
void registerHandler(HANDLER_RESULT< ResponseType >(HandlerType::*aHandler)(const HANDLER_CONTEXT< RequestType > &))
Registers an API command handler for the given message types.
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
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 generates 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
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
std::vector< wxString > m_fieldsLabels
std::vector< wxString > m_fieldsOrdered
wxString m_refRangeDelimiter
std::vector< wxString > m_fieldsGroupBy
std::vector< wxString > m_variantNames
wxString m_stringDelimiter
wxString m_fieldDelimiter
wxString m_bomFmtPresetName
std::vector< wxString > m_variantNames
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
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)
Describe the page size and margins of a paper page on which to eventually print or plot.
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.
CONNECTION_GRAPH * ConnectionGraph() const
std::vector< SCH_SHEET * > GetTopLevelSheets() const
Get the list of top-level sheets.
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
void SwapItemData(SCH_ITEM *aImage)
Swap data between aItem and aImage.
EE_RTREE & Items()
Get the full RTree, usually for iterating.
const wxString & GetFileName() const
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.
wxString GetNextPageNumber() const
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.
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
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
void pop_back()
Forwarded method from std::vector.
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
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
wxString GetShownName(bool aAllowExtraText) const
const std::vector< SCH_SHEET_INSTANCE > & GetInstances() const
virtual void Serialize(google::protobuf::Any &aContainer) const
Serializes this object to the given Any message.
A wrapper for reporting to a wxString object.
const wxString & GetMessages() const
A type-safe container of any type.
KICOMMON_API void PackProject(types::ProjectSpecifier &aOutput, const PROJECT &aInput)
KICOMMON_API KIID_PATH UnpackSheetPath(const types::SheetPath &aInput)
KICOMMON_API std::optional< KICAD_T > TypeNameFromAny(const google::protobuf::Any &aMessage)
KICOMMON_API void PackSheetPath(types::SheetPath &aOutput, const KIID_PATH &aInput)
std::shared_ptr< SCH_CONTEXT > CreateSchFrameContext(SCH_EDIT_FRAME *aFrame)
Class to handle a set of SCH_ITEMs.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
RequestMessageType Request
A simple container for sheet instance information.
wxString result
Test unit parsing edge cases and error handling.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.