26#include <magic_enum.hpp>
43#include <wx/filename.h>
45#include <api/common/types/base_types.pb.h>
47using namespace kiapi::common::commands;
48using kiapi::common::types::CommandStatus;
49using kiapi::common::types::DocumentType;
50using kiapi::common::types::ItemRequestStatus;
77 types::RunJobResponse response;
82 response.add_output_path(
output.m_outputPath.ToUTF8() );
86 response.set_status( types::JobStatus::JS_SUCCESS );
90 response.set_status( types::JobStatus::JS_ERROR );
91 response.set_message( fmt::format(
"Schematic export job '{}' failed with exit code {}: {}",
110 using namespace kiapi::schematic::jobs;
111 using namespace kiapi::schematic::types;
138 return std::make_unique<SCH_COMMIT>(
m_frame );
163tl::expected<bool, ApiResponseStatus>
166 if( aDocument.type() != DocumentType::DOCTYPE_SCHEMATIC )
169 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
170 e.set_error_message(
"the requested document is not a schematic" );
171 return tl::unexpected( e );
176 if( aDocument.project().name().compare( prj.
GetProjectName().ToUTF8() ) != 0 )
179 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
180 e.set_error_message( fmt::format(
"the requested project {} is not open",
181 aDocument.project().name() ) );
182 return tl::unexpected( e );
185 if( aDocument.project().path().compare( prj.
GetProjectPath().ToUTF8() ) != 0 )
188 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
189 e.set_error_message( fmt::format(
"the requested project {} is not open at path {}",
190 aDocument.project().name(),
191 aDocument.project().path() ) );
192 return tl::unexpected( e );
195 if( aDocument.has_sheet_path() )
202 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
203 e.set_error_message( fmt::format(
"the requested sheet path {} is not valid for this schematic",
204 path.AsString().ToStdString() ) );
205 return tl::unexpected( e );
216 if( aCtx.
Request.type() != DocumentType::DOCTYPE_SCHEMATIC )
221 e.set_status( ApiStatusCode::AS_UNHANDLED );
222 return tl::unexpected( e );
225 GetOpenDocumentsResponse response;
226 common::types::DocumentSpecifier doc;
228 wxFileName fn(
m_context->GetCurrentFileName() );
230 doc.set_type( DocumentType::DOCTYPE_SCHEMATIC );
232 if( std::optional<SCH_SHEET_PATH>
path =
m_context->GetCurrentSheet() )
237 response.mutable_documents()->Add( std::move( doc ) );
244 std::erase_if( aTypeList,
254 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
255 return tl::unexpected( *busy );
260 return tl::unexpected( valid.error() );
263 std::set<KICAD_T> typesRequested, typesInserted;
266 typesRequested.insert( type );
270 if( typesRequested.empty() )
273 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
274 e.set_error_message(
"none of the requested types are valid for a Schematic object" );
275 return tl::unexpected( e );
279 std::optional<SCH_SHEET_PATH> pathFilter;
281 if( aCtx.
Request.header().document().has_sheet_path() )
287 std::map<KICAD_T, std::vector<std::pair<EDA_ITEM*, SCH_SHEET_PATH>>> itemMap;
292 const SCH_SCREEN* aScreen = aPath.LastScreen();
296 itemMap[ aItem->Type() ].emplace_back( aItem, aPath );
298 aItem->RunOnChildren(
301 itemMap[ aChild->
Type() ].emplace_back( aChild, aPath );
309 processScreen( *pathFilter );
314 processScreen(
path );
317 GetItemsResponse response;
318 google::protobuf::Any
any;
325 if( typesInserted.contains( type ) )
328 for(
const auto& [item, itemPath] : itemMap[type] )
332 kiapi::schematic::types::SchematicSymbolInstance symbol;
337 any.PackFrom( symbol );
341 kiapi::schematic::types::SheetSymbol sheet;
346 any.PackFrom( sheet );
350 item->Serialize(
any );
353 response.mutable_items()->Add( std::move(
any ) );
357 response.set_status( ItemRequestStatus::IRS_OK );
364 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
365 return tl::unexpected( *busy );
370 e.set_status( ApiStatusCode::AS_UNHANDLED );
371 return tl::unexpected( e );
375 std::optional<SCH_SHEET_PATH> pathFilter;
377 if( aCtx.
Request.header().document().has_sheet_path() )
383 GetItemsResponse response;
385 google::protobuf::Any
any;
387 for(
const types::KIID& idProto : aCtx.
Request.items() )
389 KIID id( idProto.value() );
395 item = pathFilter->ResolveItem(
id );
396 itemPath = *pathFilter;
400 item = hierarchy.
ResolveItem(
id, &itemPath,
true );
408 kiapi::schematic::types::SchematicSymbolInstance symbol;
413 any.PackFrom( symbol );
417 kiapi::schematic::types::SheetSymbol sheet;
422 any.PackFrom( sheet );
429 response.mutable_items()->Add( std::move(
any ) );
432 if( response.items().empty() )
435 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
436 e.set_error_message(
"none of the requested IDs were found or valid" );
437 return tl::unexpected( e );
440 response.set_status( ItemRequestStatus::IRS_OK );
450 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
451 e.set_error_message(
"Tried to create an item in a null container" );
452 return tl::unexpected( e );
458 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
459 e.set_error_message( fmt::format(
"type {} is not supported by the schematic API handler",
460 magic_enum::enum_name( aType ) ) );
461 return tl::unexpected( e );
467 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
468 e.set_error_message( fmt::format(
"Tried to create a pin in {}, which is not a symbol",
470 return tl::unexpected( e );
475 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
476 e.set_error_message( fmt::format(
"Tried to create a sheet symbol in {}, which is not a "
479 return tl::unexpected( e );
484 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
485 e.set_error_message( fmt::format(
"Tried to create a symbol in {}, which is not a "
488 return tl::unexpected( e );
493 if( created && !created->GetParent() )
494 created->SetParent( aContainer );
499 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
500 e.set_error_message( fmt::format(
"Tried to create an item of type {}, which is unhandled",
501 magic_enum::enum_name( aType ) ) );
502 return tl::unexpected( e );
510 const std::string& aClientName,
511 const types::ItemHeader &aHeader,
512 const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems,
513 std::function<
void( ItemStatus, google::protobuf::Any )> aItemHandler )
519 if( !containerResult && containerResult.error().status() == ApiStatusCode::AS_UNHANDLED )
522 e.set_status( ApiStatusCode::AS_UNHANDLED );
523 return tl::unexpected( e );
525 else if( !containerResult )
527 e.CopyFrom( containerResult.error() );
528 return tl::unexpected( e );
535 if( aHeader.document().has_sheet_path() )
547 for(
const google::protobuf::Any& anyItem : aItems )
554 status.set_code( ItemStatusCode::ISC_INVALID_TYPE );
555 status.set_error_message( fmt::format(
"Could not decode a valid type from {}",
556 anyItem.type_url() ) );
557 aItemHandler( status, anyItem );
565 if( !creationResult )
567 status.set_code( ItemStatusCode::ISC_INVALID_TYPE );
568 status.set_error_message( creationResult.error().error_message() );
569 aItemHandler( status, anyItem );
573 std::unique_ptr<EDA_ITEM> item( std::move( *creationResult ) );
575 bool unpacked =
false;
579 kiapi::schematic::types::SchematicSymbolInstance symbol;
580 unpacked = anyItem.UnpackTo( &symbol )
585 kiapi::schematic::types::SheetSymbol sheetProto;
586 unpacked = anyItem.UnpackTo( &sheetProto );
592 if( tl::expected<bool, ApiResponseStatus>
result =
UnpackSheet( sheet, sheetProto );
604 if( instance.
m_Path.empty() )
615 return tl::unexpected(
result.error() );
621 unpacked = item->Deserialize( anyItem );
626 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
627 e.set_error_message( fmt::format(
"could not unpack {} from request",
628 item->GetClass().ToStdString() ) );
629 return tl::unexpected( e );
635 existingItem = targetPath.
ResolveItem( item->m_Uuid );
638 existingPath = targetPath;
640 if( aCreate && existingItem )
642 status.set_code( ItemStatusCode::ISC_EXISTING );
643 status.set_error_message( fmt::format(
"an item with UUID {} already exists",
644 item->m_Uuid.AsStdString() ) );
645 aItemHandler( status, anyItem );
648 else if( !aCreate && !existingItem )
650 status.set_code( ItemStatusCode::ISC_NONEXISTENT );
651 status.set_error_message( fmt::format(
"an item with UUID {} does not exist",
652 item->m_Uuid.AsStdString() ) );
653 aItemHandler( status, anyItem );
661 if( itemScreen != targetScreen )
663 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
664 status.set_error_message( fmt::format(
"item {} exists on a different sheet than targeted",
665 item->m_Uuid.AsStdString() ) );
666 aItemHandler( status, anyItem );
681 parentPath = targetPath;
683 parentPath = existingPath;
687 if( !destFilePath.IsEmpty() )
694 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
695 status.set_error_message(
"sheet update would create recursive hierarchy" );
696 aItemHandler( status, anyItem );
702 status.set_code( ItemStatusCode::ISC_OK );
703 google::protobuf::Any newItem;
708 commit->
Add( createdItem, targetScreen );
712 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
713 e.set_error_message(
"could not add the requested item to its parent container" );
714 return tl::unexpected( e );
719 kiapi::schematic::types::SchematicSymbolInstance symbol;
722 newItem.PackFrom( symbol );
726 kiapi::schematic::types::SheetSymbol sheet;
729 newItem.PackFrom( sheet );
738 commit->
Modify( existingItem, targetScreen );
744 kiapi::schematic::types::SchematicSymbolInstance symbol;
747 newItem.PackFrom( symbol );
752 kiapi::schematic::types::SheetSymbol sheet;
755 newItem.PackFrom( sheet );
763 aItemHandler( status, newItem );
769 :
_(
"Modified items via API" ) );
773 return ItemRequestStatus::IRS_OK;
778 const std::string& aClientName )
783 for(
auto& [
id, status] : aItemsToDelete )
793 status = ItemDeletionStatus::IDS_IMMUTABLE;
798 status = ItemDeletionStatus::IDS_OK;
822 wxCHECK(
m_context->GetCurrentSheet(), std::nullopt );
823 return &
m_context->GetCurrentSheet()->LastScreen()->GetTitleBlock();
829 wxCHECK(
m_context->GetCurrentSheet(), std::nullopt );
830 return m_context->GetCurrentSheet()->LastScreen()->GetPageSettings();
836 wxCHECK(
m_context->GetCurrentSheet(),
false );
837 m_context->GetCurrentSheet()->LastScreen()->SetPageSettings( aPageInfo );
871 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
872 return tl::unexpected( *busy );
876 if( !documentValidation )
877 return tl::unexpected( documentValidation.error() );
879 auto plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_SVG>();
880 plotJob->m_filename =
m_context->GetCurrentFileName();
882 if( !aCtx.
Request.job_settings().output_path().empty() )
883 plotJob->SetConfiguredOutputPath( wxString::FromUTF8( aCtx.
Request.job_settings().output_path() ) );
885 const kiapi::schematic::jobs::SchematicPlotSettings& settings = aCtx.
Request.plot_settings();
887 plotJob->m_drawingSheet = wxString::FromUTF8( settings.drawing_sheet() );
888 plotJob->m_defaultFont = wxString::FromUTF8( settings.default_font() );
889 plotJob->m_variant = wxString::FromUTF8( settings.variant() );
890 plotJob->m_plotAll = settings.plot_all();
891 plotJob->m_plotDrawingSheet = settings.plot_drawing_sheet();
892 plotJob->m_show_hop_over = settings.show_hop_over();
893 plotJob->m_blackAndWhite = settings.black_and_white();
894 plotJob->m_useBackgroundColor = settings.use_background_color();
895 plotJob->m_minPenWidth = settings.min_pen_width();
896 plotJob->m_theme = wxString::FromUTF8( settings.theme() );
898 plotJob->m_plotPages.clear();
900 for(
const std::string& page : settings.plot_pages() )
901 plotJob->m_plotPages.push_back( wxString::FromUTF8( page ) );
903 if( aCtx.
Request.plot_settings().page_size() != kiapi::schematic::jobs::SchematicJobPageSize::SJPS_UNKNOWN )
915 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
916 return tl::unexpected( *busy );
920 if( !documentValidation )
921 return tl::unexpected( documentValidation.error() );
923 auto plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_DXF>();
924 plotJob->m_filename =
m_context->GetCurrentFileName();
926 if( !aCtx.
Request.job_settings().output_path().empty() )
927 plotJob->SetConfiguredOutputPath( wxString::FromUTF8( aCtx.
Request.job_settings().output_path() ) );
929 const kiapi::schematic::jobs::SchematicPlotSettings& settings = aCtx.
Request.plot_settings();
931 plotJob->m_drawingSheet = wxString::FromUTF8( settings.drawing_sheet() );
932 plotJob->m_defaultFont = wxString::FromUTF8( settings.default_font() );
933 plotJob->m_variant = wxString::FromUTF8( settings.variant() );
934 plotJob->m_plotAll = settings.plot_all();
935 plotJob->m_plotDrawingSheet = settings.plot_drawing_sheet();
936 plotJob->m_show_hop_over = settings.show_hop_over();
937 plotJob->m_blackAndWhite = settings.black_and_white();
938 plotJob->m_useBackgroundColor = settings.use_background_color();
939 plotJob->m_minPenWidth = settings.min_pen_width();
940 plotJob->m_theme = wxString::FromUTF8( settings.theme() );
942 plotJob->m_plotPages.clear();
944 for(
const std::string& page : settings.plot_pages() )
945 plotJob->m_plotPages.push_back( wxString::FromUTF8( page ) );
947 if( aCtx.
Request.plot_settings().page_size() != kiapi::schematic::jobs::SchematicJobPageSize::SJPS_UNKNOWN )
959 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
960 return tl::unexpected( *busy );
964 if( !documentValidation )
965 return tl::unexpected( documentValidation.error() );
967 auto plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_PDF>(
false );
968 plotJob->m_filename =
m_context->GetCurrentFileName();
970 if( !aCtx.
Request.job_settings().output_path().empty() )
971 plotJob->SetConfiguredOutputPath( wxString::FromUTF8( aCtx.
Request.job_settings().output_path() ) );
973 const kiapi::schematic::jobs::SchematicPlotSettings& settings = aCtx.
Request.plot_settings();
975 plotJob->m_drawingSheet = wxString::FromUTF8( settings.drawing_sheet() );
976 plotJob->m_defaultFont = wxString::FromUTF8( settings.default_font() );
977 plotJob->m_variant = wxString::FromUTF8( settings.variant() );
978 plotJob->m_plotAll = settings.plot_all();
979 plotJob->m_plotDrawingSheet = settings.plot_drawing_sheet();
980 plotJob->m_show_hop_over = settings.show_hop_over();
981 plotJob->m_blackAndWhite = settings.black_and_white();
982 plotJob->m_useBackgroundColor = settings.use_background_color();
983 plotJob->m_minPenWidth = settings.min_pen_width();
984 plotJob->m_theme = wxString::FromUTF8( settings.theme() );
986 plotJob->m_plotPages.clear();
988 for(
const std::string& page : settings.plot_pages() )
989 plotJob->m_plotPages.push_back( wxString::FromUTF8( page ) );
991 if( aCtx.
Request.plot_settings().page_size() != kiapi::schematic::jobs::SchematicJobPageSize::SJPS_UNKNOWN )
996 plotJob->m_PDFPropertyPopups = aCtx.
Request.property_popups();
997 plotJob->m_PDFHierarchicalLinks = aCtx.
Request.hierarchical_links();
998 plotJob->m_PDFMetadata = aCtx.
Request.include_metadata();
1007 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1008 return tl::unexpected( *busy );
1012 if( !documentValidation )
1013 return tl::unexpected( documentValidation.error() );
1015 auto plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_PS>();
1016 plotJob->m_filename =
m_context->GetCurrentFileName();
1018 if( !aCtx.
Request.job_settings().output_path().empty() )
1019 plotJob->SetConfiguredOutputPath( wxString::FromUTF8( aCtx.
Request.job_settings().output_path() ) );
1021 const kiapi::schematic::jobs::SchematicPlotSettings& settings = aCtx.
Request.plot_settings();
1023 plotJob->m_drawingSheet = wxString::FromUTF8( settings.drawing_sheet() );
1024 plotJob->m_defaultFont = wxString::FromUTF8( settings.default_font() );
1025 plotJob->m_variant = wxString::FromUTF8( settings.variant() );
1026 plotJob->m_plotAll = settings.plot_all();
1027 plotJob->m_plotDrawingSheet = settings.plot_drawing_sheet();
1028 plotJob->m_show_hop_over = settings.show_hop_over();
1029 plotJob->m_blackAndWhite = settings.black_and_white();
1030 plotJob->m_useBackgroundColor = settings.use_background_color();
1031 plotJob->m_minPenWidth = settings.min_pen_width();
1032 plotJob->m_theme = wxString::FromUTF8( settings.theme() );
1034 plotJob->m_plotPages.clear();
1036 for(
const std::string& page : settings.plot_pages() )
1037 plotJob->m_plotPages.push_back( wxString::FromUTF8( page ) );
1039 if( aCtx.
Request.plot_settings().page_size() != kiapi::schematic::jobs::SchematicJobPageSize::SJPS_UNKNOWN )
1051 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1052 return tl::unexpected( *busy );
1056 if( !documentValidation )
1057 return tl::unexpected( documentValidation.error() );
1059 if( aCtx.
Request.format() == kiapi::schematic::jobs::SchematicNetlistFormat::SNF_UNKNOWN )
1061 ApiResponseStatus e;
1062 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1063 e.set_error_message(
"RunSchematicJobExportNetlist requires a valid format" );
1064 return tl::unexpected( e );
1070 if( !aCtx.
Request.job_settings().output_path().empty() )
1075 if( !aCtx.
Request.variant_name().empty() )
1085 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1086 return tl::unexpected( *busy );
1090 if( !documentValidation )
1091 return tl::unexpected( documentValidation.error() );
1096 if( !aCtx.
Request.job_settings().output_path().empty() )
1111 if( aCtx.
Request.fields().sort_direction() == kiapi::schematic::jobs::BOMSortDirection::BSD_ASCENDING )
1115 else if( aCtx.
Request.fields().sort_direction() == kiapi::schematic::jobs::BOMSortDirection::BSD_DESCENDING )
1120 for(
const kiapi::schematic::jobs::BOMField& field : aCtx.
Request.fields().fields() )
1122 bomJob.
m_fieldsOrdered.emplace_back( wxString::FromUTF8( field.name() ) );
1123 bomJob.
m_fieldsLabels.emplace_back( wxString::FromUTF8( field.label() ) );
1125 if( field.group_by() )
1126 bomJob.
m_fieldsGroupBy.emplace_back( wxString::FromUTF8( field.name() ) );
1132 if( !aCtx.
Request.variant_name().empty() )
1148 if( sheetName.IsEmpty() && aSheet->
GetScreen() )
1151 sheetName = fn.GetName();
1154 aInstance->set_name( sheetName.ToUTF8() );
1155 aInstance->set_filename( aSheet->
GetFileName().ToUTF8() );
1156 aInstance->set_page_number( aPath.
GetPageNumber().ToUTF8() );
1160 std::vector<SCH_ITEM*> childSheets;
1163 std::ranges::sort( childSheets,
1175 for(
SCH_ITEM* childItem : childSheets )
1178 kiapi::schematic::types::SheetInstance* childInstance = aInstance->add_children();
1192 if( !documentValidation )
1193 return tl::unexpected( documentValidation.error() );
1195 kiapi::schematic::types::SchematicHierarchyResponse response;
1196 response.mutable_document()->CopyFrom( aCtx.
Request.document() );
1204 std::ranges::sort( topLevelSheets,
1216 for(
SCH_SHEET* topSheet : topLevelSheets )
1218 kiapi::schematic::types::SheetInstance* instance = response.add_top_level_sheets();
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< 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.
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.
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.