21#include <magic_enum.hpp>
34#include <api/common/commands/library_commands.pb.h>
98#include <api/common/types/base_types.pb.h>
102#include <api/board/board_rules.pb.h>
104#include <google/protobuf/util/json_util.h>
113using namespace kiapi::common::commands;
114using namespace kiapi::board::commands;
115using types::CommandStatus;
116using types::DocumentType;
117using types::ItemRequestStatus;
164 kiapi::common::tasks::StartTaskResponse>(
244 if( aCtx.
Request.type() != DocumentType::DOCTYPE_PCB )
248 e.set_status( ApiStatusCode::AS_UNHANDLED );
249 return tl::unexpected( e );
252 GetOpenDocumentsResponse response;
253 common::types::DocumentSpecifier doc;
255 wxFileName fn(
pcbContext()->GetCurrentFileName() );
257 doc.set_type( DocumentType::DOCTYPE_PCB );
258 doc.set_board_filename( fn.GetFullName() );
263 response.mutable_documents()->Add( std::move( doc ) );
272 return tl::unexpected( documentValidation.error() );
274 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
275 return tl::unexpected( *busy );
277 if(
board()->GetFileName().IsEmpty() )
280 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
281 e.set_error_message(
"the board is untitled; use SaveDocumentAs to save it to a new file" );
282 return tl::unexpected( e );
288 e.set_status( ApiStatusCode::AS_INTERNAL_ERROR );
289 e.set_error_message(
"board could not be saved" );
290 return tl::unexpected( e );
302 e.set_status( ApiStatusCode::AS_UNIMPLEMENTED );
303 e.set_error_message(
"SaveDocumentAs is not available in GUI mode" );
304 return tl::unexpected( e );
308 return tl::unexpected( documentValidation.error() );
310 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
311 return tl::unexpected( *busy );
313 wxString pathStr = wxString::FromUTF8( aCtx.
Request.path() );
315 if( pathStr.IsEmpty() )
318 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
319 e.set_error_message(
"path is required" );
320 return tl::unexpected( e );
323 wxFileName oldBoardFile(
pcbContext()->GetCurrentFileName() );
328 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
329 e.set_error_message( fmt::format(
"failed to save board to '{}'", pathStr.ToStdString() ) );
330 return tl::unexpected( e );
335 wxFileName newBoardFile( pathStr );
338 server->NotifyDocumentRenamed(
thisDocumentType(), oldBoardFile.GetFullPath(), newBoardFile.GetFullPath() );
349 return tl::unexpected( documentValidation.error() );
351 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
352 return tl::unexpected( *busy );
354 wxFileName boardPath(
project().AbsolutePath( wxString::FromUTF8( aCtx.
Request.path() ) ) );
356 if( !boardPath.IsOk() || !boardPath.IsDirWritable() )
359 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
360 e.set_error_message( fmt::format(
"save path '{}' could not be opened",
361 boardPath.GetFullPath().ToStdString() ) );
362 return tl::unexpected( e );
365 if( boardPath.FileExists()
366 && ( !boardPath.IsFileWritable() || !aCtx.
Request.options().overwrite() ) )
369 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
370 e.set_error_message( fmt::format(
"save path '{}' exists and cannot be overwritten",
371 boardPath.GetFullPath().ToStdString() ) );
372 return tl::unexpected( e );
378 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
379 e.set_error_message( fmt::format(
"save path '{}' must have a kicad_pcb extension",
380 boardPath.GetFullPath().ToStdString() ) );
381 return tl::unexpected( e );
386 if( board->
GetFileName().Matches( boardPath.GetFullPath() ) )
391 e.set_status( ApiStatusCode::AS_INTERNAL_ERROR );
392 e.set_error_message(
"board could not be saved" );
393 return tl::unexpected( e );
399 bool includeProject =
true;
401 if( aCtx.
Request.has_options() )
402 includeProject = aCtx.
Request.options().include_project();
404 if( !
pcbContext()->SavePcbCopy( boardPath.GetFullPath(), includeProject,
true ) )
407 e.set_status( ApiStatusCode::AS_INTERNAL_ERROR );
408 e.set_error_message( fmt::format(
"board could not be saved to '{}'",
409 boardPath.GetFullPath().ToStdString() ) );
410 return tl::unexpected( e );
422 return tl::unexpected( documentValidation.error() );
429 e.set_status( ApiStatusCode::AS_BUSY );
430 e.set_error_message(
"cannot revert while a commit is open" );
431 return tl::unexpected( e );
434 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
435 return tl::unexpected( *busy );
440 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
441 e.set_error_message(
"could not revert: there is no saved file on disk to revert to" );
442 return tl::unexpected( e );
451 if( aDocument.type() != DocumentType::DOCTYPE_PCB )
454 e.set_status( ApiStatusCode::AS_UNHANDLED );
455 return tl::unexpected( e );
458 wxFileName fn(
pcbContext()->GetCurrentFileName() );
460 if( aDocument.board_filename().compare( fn.GetFullName() ) != 0 )
463 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
464 e.set_error_message( fmt::format(
"the requested document {} is not open",
465 aDocument.board_filename() ) );
466 return tl::unexpected( e );
506 e.set_status( ApiStatusCode::AS_UNHANDLED );
507 return tl::unexpected( e );
510 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
511 return tl::unexpected( *busy );
513 GetItemsResponse response;
516 std::vector<BOARD_ITEM*> items;
517 std::set<KICAD_T> typesRequested, typesHandled;
521 if( aCtx.
Request.types().empty() )
524 for(
KICAD_T type : requestedTypes )
526 typesRequested.emplace( type );
528 if( typesHandled.count( type ) )
536 std::ranges::copy(
board->Tracks(), std::back_inserter( items ) );
542 std::ranges::copy( fp->Pads(), std::back_inserter( items ) );
548 std::ranges::copy(
board->Footprints(), std::back_inserter( items ) );
565 if( item->Type() == type ||
BaseType( item->Type() ) == type )
566 items.emplace_back( item );
569 typesHandled.insert( type );
573 std::ranges::copy(
board->Zones(), std::back_inserter( items ) );
578 std::ranges::copy(
board->Groups(), std::back_inserter( items ) );
583 std::ranges::copy(
board->Points(), std::back_inserter( items ) );
592 std::ranges::copy(
board->Generators(), std::back_inserter( items ) );
597 std::ranges::copy(
board->Constraints(), std::back_inserter( items ) );
606 if( typesHandled.empty() )
609 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
610 e.set_error_message(
"none of the requested types are valid for a Board object" );
611 return tl::unexpected( e );
616 if( !typesRequested.count( item->Type() ) && !typesRequested.count(
BaseType( item->Type() ) ) )
619 google::protobuf::Any itemBuf;
620 item->Serialize( itemBuf );
621 response.mutable_items()->Add( std::move( itemBuf ) );
624 response.set_status( ItemRequestStatus::IRS_OK );
633 return tl::unexpected( documentValidation.error() );
635 if( aCtx.
Request.copper_layer_count() < 2 || aCtx.
Request.copper_layer_count() % 2 != 0 )
638 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
639 e.set_error_message(
"copper_layer_count must be an even number of at least 2" );
640 return tl::unexpected( e );
646 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
647 e.set_error_message( fmt::format(
"copper_layer_count must be below %d",
MAX_CU_LAYERS ) );
648 return tl::unexpected( e );
651 int copperLayerCount =
static_cast<int>( aCtx.
Request.copper_layer_count() );
656 enabled &=
~LSET::AllCuMask();
661 LSET previousEnabled =
board->GetEnabledLayers();
662 LSET changedLayers = enabled ^ previousEnabled;
664 board->SetEnabledLayers( enabled );
665 board->SetVisibleLayers(
board->GetVisibleLayers() | changedLayers );
671 if( !enabled[layer_id] &&
board->HasItemsOnLayer( layer_id ) )
672 removedLayers.push_back( layer_id );
675 bool modified =
false;
677 if( !removedLayers.empty() )
682 modified |=
board->RemoveAllItemsOnLayer( layer_id );
685 if( enabled != previousEnabled || modified )
688 BoardEnabledLayersResponse response;
690 response.set_copper_layer_count( copperLayerCount );
701 return tl::unexpected( documentValidation.error() );
703 common::types::EmbeddedFiles response;
714 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
715 e.set_error_message(
"embedded file validation failed" );
716 return tl::unexpected( e );
726 return tl::unexpected( documentValidation.error() );
728 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
729 return tl::unexpected( *busy );
739 for(
const std::shared_ptr<EMBEDDED_FILES::EMBEDDED_FILE>& file : files.
EmbeddedFileMap() | std::views::values )
741 auto copy = std::make_shared<EMBEDDED_FILES::EMBEDDED_FILE>( *file );
753 return tl::unexpected( documentValidation.error() );
755 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
756 return tl::unexpected( *busy );
774 if( !documentValidation )
775 return tl::unexpected( documentValidation.error() );
778 BoardDesignRulesResponse response;
779 kiapi::board::BoardDesignRules* rules = response.mutable_rules();
781 kiapi::board::MinimumConstraints* constraints = rules->mutable_constraints();
783 constraints->mutable_min_clearance()->set_value_nm( bds.
m_MinClearance );
784 constraints->mutable_min_groove_width()->set_value_nm( bds.
m_MinGrooveWidth );
785 constraints->mutable_min_connection_width()->set_value_nm( bds.
m_MinConn );
786 constraints->mutable_min_track_width()->set_value_nm( bds.
m_TrackMinWidth );
788 constraints->mutable_min_via_size()->set_value_nm( bds.
m_ViasMinSize );
793 constraints->mutable_hole_clearance()->set_value_nm( bds.
m_HoleClearance );
794 constraints->mutable_hole_to_hole_min()->set_value_nm( bds.
m_HoleToHoleMin );
795 constraints->mutable_silk_clearance()->set_value_nm( bds.
m_SilkClearance );
798 constraints->mutable_min_silk_text_thickness()->set_value_nm( bds.
m_MinSilkLineWidth );
800 kiapi::board::PredefinedSizes* sizes = rules->mutable_predefined_sizes();
803 sizes->add_tracks()->mutable_width()->set_value_nm( bds.
m_TrackWidthList[ii] );
807 kiapi::board::PresetViaDimension*
via = sizes->add_vias();
814 kiapi::board::PresetDiffPairDimension* pair = sizes->add_diff_pairs();
820 kiapi::board::SolderMaskPasteDefaults* maskPaste = rules->mutable_solder_mask_paste();
829 kiapi::board::TeardropDefaults* teardrops = rules->mutable_teardrops();
842 kiapi::board::TeardropTargetEntry* entry = teardrops->add_target_params();
846 entry->mutable_params()->set_enabled( params->
m_Enabled );
847 entry->mutable_params()->mutable_max_length()->set_value_nm( params->
m_TdMaxLen );
848 entry->mutable_params()->mutable_max_width()->set_value_nm( params->
m_TdMaxWidth );
852 entry->mutable_params()->set_curved_edges( params->
m_CurvedEdges );
857 kiapi::board::ViaProtectionDefaults* viaProtection = rules->mutable_via_protection();
870 board::DrcSeveritySetting* setting = rules->add_severities();
871 setting->set_rule_type(
877 rules->add_exclusions()->CopyFrom( exclusion.
ToProto() );
879 response.set_custom_rules_status( CRS_NONE );
883 if( !rulesPath.IsEmpty() && wxFileName::IsFileReadable( rulesPath ) )
885 wxFFile file( rulesPath,
"r" );
887 std::vector<std::shared_ptr<DRC_RULE>> parsedRules;
889 if( !file.IsOpened() )
891 response.set_custom_rules_status( CRS_INVALID );
895 file.ReadAll( &content );
901 parser.
Parse( parsedRules,
nullptr );
902 response.set_custom_rules_status( CRS_VALID );
906 response.set_custom_rules_status( CRS_INVALID );
919 if( !documentValidation )
920 return tl::unexpected( documentValidation.error() );
923 const kiapi::board::BoardDesignRules& rules = aCtx.
Request.rules();
925 if( rules.has_constraints() )
927 const kiapi::board::MinimumConstraints& constraints = rules.constraints();
929 newSettings.
m_MinClearance = constraints.min_clearance().value_nm();
931 newSettings.
m_MinConn = constraints.min_connection_width().value_nm();
932 newSettings.
m_TrackMinWidth = constraints.min_track_width().value_nm();
934 newSettings.
m_ViasMinSize = constraints.min_via_size().value_nm();
940 newSettings.
m_HoleToHoleMin = constraints.hole_to_hole_min().value_nm();
947 if( rules.has_predefined_sizes() )
952 for(
const kiapi::board::PresetTrackWidth& track : rules.predefined_sizes().tracks() )
958 for(
const kiapi::board::PresetViaDimension&
via : rules.predefined_sizes().vias() )
961 static_cast<int>(
via.drill().value_nm() ) );
967 for(
const kiapi::board::PresetDiffPairDimension& pair : rules.predefined_sizes().diff_pairs() )
970 static_cast<int>( pair.width().value_nm() ),
971 static_cast<int>( pair.gap().value_nm() ),
972 static_cast<int>( pair.via_gap().value_nm() ) );
976 if( rules.has_solder_mask_paste() )
978 const kiapi::board::SolderMaskPasteDefaults& maskPaste = rules.solder_mask_paste();
986 maskPaste.allow_soldermask_bridges_in_footprints();
989 if( rules.has_teardrops() )
991 const kiapi::board::TeardropDefaults& teardrops = rules.teardrops();
999 for(
const kiapi::board::TeardropTargetEntry& entry : teardrops.target_params() )
1001 if( entry.target() == kiapi::board::TeardropTarget::TDT_UNKNOWN )
1009 ApiResponseStatus e;
1010 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1011 e.set_error_message(
"unknown teardrop target" );
1012 return tl::unexpected( e );
1017 params->
m_Enabled = entry.params().enabled();
1018 params->
m_TdMaxLen = entry.params().max_length().value_nm();
1019 params->
m_TdMaxWidth = entry.params().max_width().value_nm();
1029 if( rules.has_via_protection() )
1031 const kiapi::board::ViaProtectionDefaults& viaProtection = rules.via_protection();
1039 newSettings.
m_CapVias = viaProtection.cap();
1040 newSettings.
m_FillVias = viaProtection.fill();
1045 for(
const kiapi::board::DrcSeveritySetting& severitySetting : rules.severities() )
1053 if( !permitted.contains( setting ) )
1055 ApiResponseStatus e;
1056 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1057 e.set_error_message( fmt::format(
"DRC severity must be error, warning, or ignore" ) );
1058 return tl::unexpected( e );
1066 for(
const kiapi::board::DrcExclusion& exclusion : rules.exclusions() )
1069 std::vector<BOARD_DESIGN_SETTINGS::VALIDATION_ERROR> errors = newSettings.
ValidateDesignRules();
1071 if( !errors.empty() )
1075 ApiResponseStatus e;
1076 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1077 e.set_error_message( fmt::format(
"Invalid board design rules: {}: {}",
1080 return tl::unexpected( e );
1099 if( !documentValidation )
1100 return tl::unexpected( documentValidation.error() );
1102 CustomRulesResponse response;
1103 response.set_status( CRS_NONE );
1107 if( rulesPath.IsEmpty() || !wxFileName::IsFileReadable( rulesPath ) )
1110 wxFFile file( rulesPath,
"r" );
1112 if( !file.IsOpened() )
1114 response.set_status( CRS_INVALID );
1115 response.set_error_text(
"Failed to open custom rules file" );
1120 file.ReadAll( &content );
1123 std::vector<std::shared_ptr<DRC_RULE>> parsedRules;
1128 parser.
Parse( parsedRules,
nullptr );
1132 response.set_status( CRS_INVALID );
1133 response.set_error_text( ioe.
What().ToStdString() );
1137 for(
const std::shared_ptr<DRC_RULE>& rule : parsedRules )
1144 kiapi::board::CustomRule* customRule = response.add_rules();
1146 if( rule->m_Condition )
1147 customRule->set_condition( rule->m_Condition->GetExpression().ToUTF8() );
1151 board::CustomRuleConstraint* constraintProto = customRule->add_constraints();
1152 constraint.
ToProto( *constraintProto );
1156 customRule->set_name( rule->m_Name.ToUTF8() );
1158 if( rule->m_LayerSource.CmpNoCase( wxS(
"outer" ) ) == 0 )
1160 customRule->set_layer_mode( kiapi::board::CRLM_OUTER );
1162 else if( rule->m_LayerSource.CmpNoCase( wxS(
"inner" ) ) == 0 )
1164 customRule->set_layer_mode( kiapi::board::CRLM_INNER );
1166 else if( !rule->m_LayerSource.IsEmpty() )
1172 customRule->set_single_layer(
1177 if( !comment.IsEmpty() )
1178 customRule->set_comments( comment );
1181 response.set_status( CRS_VALID );
1191 if( !documentValidation )
1192 return tl::unexpected( documentValidation.error() );
1196 if( aCtx.
Request.rules_size() == 0 )
1198 if( wxFileName::FileExists( rulesPath ) )
1200 if( !wxRemoveFile( rulesPath ) )
1202 CustomRulesResponse response;
1203 response.set_status( CRS_INVALID );
1204 response.set_error_text(
"Failed to remove custom rules file" );
1209 CustomRulesResponse response;
1210 response.set_status( CRS_NONE );
1215 rulesText <<
"(version 2)\n";
1217 for(
const board::CustomRule& rule : aCtx.
Request.rules() )
1219 wxString serializationError;
1222 if( serializedRule.IsEmpty() )
1224 CustomRulesResponse response;
1225 response.set_status( CRS_INVALID );
1227 if( serializationError.IsEmpty() )
1228 response.set_error_text(
"Failed to serialize custom rule" );
1230 response.set_error_text( serializationError.ToUTF8() );
1235 rulesText <<
"\n" << serializedRule;
1241 std::vector<std::shared_ptr<DRC_RULE>> parsedRules;
1243 parser.
Parse( parsedRules,
nullptr );
1247 CustomRulesResponse response;
1248 response.set_status( CRS_INVALID );
1249 response.set_error_text( ioe.
What().ToStdString() );
1253 wxFFile file( rulesPath,
"w" );
1255 if( !file.IsOpened() )
1257 CustomRulesResponse response;
1258 response.set_status( CRS_INVALID );
1259 response.set_error_text(
"Failed to open custom rules file for writing" );
1263 if( !file.Write( rulesText ) )
1267 CustomRulesResponse response;
1268 response.set_status( CRS_INVALID );
1269 response.set_error_text(
"Failed to write custom rules file" );
1285 !documentValidation )
1287 return tl::unexpected( documentValidation.error() );
1306 ApiResponseStatus e;
1307 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1308 e.set_error_message(
"Unexpected origin type" );
1309 return tl::unexpected( e );
1313 types::Vector2 reply;
1322 return tl::unexpected( documentValidation.error() );
1324 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1325 return tl::unexpected( *busy );
1382 ApiResponseStatus e;
1383 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1384 e.set_error_message(
"Unexpected origin type" );
1385 return tl::unexpected( e );
1397 !documentValidation )
1399 return tl::unexpected( documentValidation.error() );
1402 BoardLayerNameResponse response;
1406 response.set_name(
board()->GetLayerName(
id ) );
1416 !documentValidation )
1418 return tl::unexpected( documentValidation.error() );
1421 BoardLayerResponse response;
1483 brd->SynchronizeNetsAndNetClasses(
false );
1501 return tl::unexpected( documentValidation.error() );
1503 GetDocumentModifiedStateResponse response;
1504 response.set_state(
pcbContext()->IsContentModified() ? DocumentModifiedState::DMS_MODIFIED
1505 : DocumentModifiedState::DMS_UNMODIFIED );
1513 return tl::unexpected( documentValidation.error() );
1515 NetsResponse response;
1518 std::set<wxString> netclassFilter;
1520 for(
const std::string& nc : aCtx.
Request.netclass_filter() )
1521 netclassFilter.insert( wxString( nc.c_str(), wxConvUTF8 ) );
1527 if( !netclassFilter.empty() && nc )
1529 bool inClass =
false;
1531 for(
const wxString&
filter : netclassFilter )
1544 board::types::Net* netProto = response.add_nets();
1545 netProto->set_name( net->GetNetname() );
1546 netProto->mutable_code()->set_value( net->GetNetCode() );
1558 ApiResponseStatus e;
1559 e.set_status( ApiStatusCode::AS_UNHANDLED );
1560 return tl::unexpected( e );
1563 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1564 return tl::unexpected( *busy );
1567 const bool filterByType = aCtx.
Request.types_size() > 0;
1569 if( filterByType &&
types.empty() )
1571 ApiResponseStatus e;
1572 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1573 e.set_error_message(
"none of the requested types are valid for a Board object" );
1574 return tl::unexpected( e );
1577 std::set<KICAD_T> typeFilter(
types.begin(),
types.end() );
1578 std::vector<BOARD_CONNECTED_ITEM*> sourceItems;
1580 for(
const types::KIID&
id : aCtx.
Request.items() )
1582 if( std::optional<BOARD_ITEM*> item =
getItemById(
KIID(
id.value() ) ) )
1585 sourceItems.emplace_back( connected );
1589 if( sourceItems.empty() )
1591 ApiResponseStatus e;
1592 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1593 e.set_error_message(
"none of the requested IDs were found or valid connected items" );
1594 return tl::unexpected( e );
1597 GetItemsResponse response;
1599 std::set<KIID> insertedItems;
1605 if( filterByType && !typeFilter.contains( connected->Type() ) )
1608 if( !insertedItems.insert( connected->m_Uuid ).second )
1611 connected->Serialize( *response.add_items() );
1615 response.set_status( ItemRequestStatus::IRS_OK );
1625 ApiResponseStatus e;
1626 e.set_status( ApiStatusCode::AS_UNHANDLED );
1627 return tl::unexpected( e );
1630 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1631 return tl::unexpected( *busy );
1634 const bool filterByType = aCtx.
Request.types_size() > 0;
1636 if( filterByType &&
types.empty() )
1638 ApiResponseStatus e;
1639 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1640 e.set_error_message(
"none of the requested types are valid for a Board object" );
1641 return tl::unexpected( e );
1647 GetItemsResponse response;
1649 std::shared_ptr<CONNECTIVITY_DATA> conn =
board->GetConnectivity();
1650 std::set<KIID> insertedItems;
1654 for(
const board::types::Net& net : aCtx.
Request.nets() )
1663 if( !insertedItems.insert( item->m_Uuid ).second )
1666 item->Serialize( *response.add_items() );
1670 response.set_status( ItemRequestStatus::IRS_OK );
1680 ApiResponseStatus e;
1681 e.set_status( ApiStatusCode::AS_UNHANDLED );
1682 return tl::unexpected( e );
1685 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1686 return tl::unexpected( *busy );
1689 const bool filterByType = aCtx.
Request.types_size() > 0;
1691 if( filterByType &&
types.empty() )
1693 ApiResponseStatus e;
1694 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1695 e.set_error_message(
"none of the requested types are valid for a Board object" );
1696 return tl::unexpected( e );
1702 std::set<wxString> requestedClasses;
1704 for(
const std::string& netClass : aCtx.
Request.net_classes() )
1705 requestedClasses.insert( wxString( netClass.c_str(), wxConvUTF8 ) );
1707 GetItemsResponse response;
1709 std::shared_ptr<CONNECTIVITY_DATA> conn =
board->GetConnectivity();
1710 std::set<KIID> insertedItems;
1719 if( !requestedClasses.empty() )
1724 bool inClass =
false;
1726 for(
const wxString&
filter : requestedClasses )
1741 if( !insertedItems.insert( item->m_Uuid ).second )
1744 item->Serialize( *response.add_items() );
1748 response.set_status( ItemRequestStatus::IRS_OK );
1756 NetClassForNetsResponse response;
1761 for(
const board::types::Net& net : aCtx.
Request.net() )
1768 auto [pair, rc] = response.mutable_classes()->insert( { net.name(), {} } );
1777 const google::protobuf::RepeatedPtrField<kiapi::common::types::KIID>& aZoneIds )
const
1779 std::vector<ZONE*> toFill;
1781 for(
const types::KIID&
id : aZoneIds )
1785 if( !item || ( *item )->Type() !=
PCB_ZONE_T )
1787 ApiResponseStatus e;
1788 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1789 e.set_error_message( fmt::format(
"zone with ID {} not found on the board",
id.value() ) );
1790 return tl::unexpected( e );
1793 ZONE* zone =
static_cast<ZONE*
>( *item );
1798 ApiResponseStatus e;
1799 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1800 e.set_error_message( fmt::format(
"zone with ID {} is a rule area and cannot be filled",
1802 return tl::unexpected( e );
1807 toFill.push_back( zone );
1817 return tl::unexpected( documentValidation.error() );
1819 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1820 return tl::unexpected( *busy );
1829 if( aCtx.
Request.zones().empty() )
1833 frame()->CallAfter( [mgr]()
1850 return tl::unexpected( toFill.error() );
1855 if( !filler.
Fill( *toFill ) )
1859 ApiResponseStatus e;
1860 e.set_status( ApiStatusCode::AS_UNKNOWN );
1861 e.set_error_message(
"zone fill failed" );
1862 return tl::unexpected( e );
1880 if( !documentValidation )
1881 return tl::unexpected( documentValidation.error() );
1883 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1884 return tl::unexpected( *busy );
1886 wxFileName netlistPath(
project().AbsolutePath( wxString::FromUTF8( aCtx.
Request.netlist_path() ) ) );
1888 if( !netlistPath.IsOk() || !netlistPath.FileExists() )
1890 ApiResponseStatus e;
1891 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1892 e.set_error_message(
1893 fmt::format(
"netlist file '{}' could not be opened", netlistPath.GetFullPath().ToStdString() ) );
1894 return tl::unexpected( e );
1900 const bool lookupByTimestamp = aCtx.
Request.match_mode() != NetlistMatchMode::NMM_REFERENCE;
1903 netlist.SetFindByTimeStamp( lookupByTimestamp );
1904 netlist.SetReplaceFootprints( aCtx.
Request.update_footprints() );
1908 ApiResponseStatus e;
1909 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1910 e.set_error_message( fmt::format(
"unable to handle netlist file '{}': {}",
1911 netlistPath.GetFullPath().ToStdString(),
1912 reporter.GetMessages().ToStdString() ) );
1913 return tl::unexpected( e );
1919 updater->SetIsDryRun( aCtx.
Request.dry_run() );
1920 updater->SetWillDrag(
false );
1921 updater->SetLookupByTimestamp( lookupByTimestamp );
1922 updater->SetDeleteUnusedFootprints( aCtx.
Request.delete_extra_footprints() );
1923 updater->SetReplaceFootprints( aCtx.
Request.update_footprints() );
1924 updater->SetTransferGroups( aCtx.
Request.transfer_groups() );
1925 updater->SetOverrideLocks( aCtx.
Request.override_locks() );
1926 updater->SetUpdateFields(
true );
1928 const bool success = updater->UpdateNetlist(
netlist );
1930 if( !aCtx.
Request.dry_run() && success )
1933 ImportNetlistResponse response;
1934 response.set_report(
reporter.GetMessages().ToUTF8() );
1935 response.set_error_count( updater->GetErrorCount() );
1936 response.set_warning_count( updater->GetWarningCount() );
1937 response.set_new_footprint_count( updater->GetNewFootprintCount() );
1946 return tl::unexpected( documentValidation.error() );
1948 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1949 return tl::unexpected( *busy );
1951 wxFileName sesPath(
project().AbsolutePath( wxString::FromUTF8( aCtx.
Request.session_path() ) ) );
1953 if( !sesPath.IsOk() || !sesPath.FileExists() )
1955 ApiResponseStatus e;
1956 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1957 e.set_error_message(
1958 fmt::format(
"session file '{}' could not be opened", sesPath.GetFullPath().ToStdString() ) );
1959 return tl::unexpected( e );
1962 int skippedCount = 0;
1974 ApiResponseStatus e;
1975 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1976 e.set_error_message( fmt::format(
"failed to import session '{}': {}", sesPath.GetFullPath().ToStdString(),
1977 ioe.
What().ToStdString() ) );
1978 return tl::unexpected( e );
1984 ImportSpecctraSessionResponse response;
1985 response.set_report(
reporter.GetMessages().ToUTF8() );
1986 response.set_skipped_count( skippedCount );
1994 if( std::optional<ApiResponseStatus> headless =
checkForHeadless(
"GetBoardEditorAppearanceSettings" ) )
1995 return tl::unexpected( *headless );
1997 BoardEditorAppearanceSettings reply;
2005 reply.set_net_color_display(
2008 reply.set_board_flip(
frame()->GetCanvas()->GetView()->IsMirroredX()
2009 ? BoardFlipMode::BFM_FLIPPED_X
2010 : BoardFlipMode::BFM_NORMAL );
2024 if( std::optional<ApiResponseStatus> headless =
checkForHeadless(
"SetBoardEditorAppearanceSettings" ) )
2025 return tl::unexpected( *headless );
2027 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2028 return tl::unexpected( *busy );
2032 const BoardEditorAppearanceSettings& newSettings = aCtx.
Request.settings();
2038 options.
m_FlipBoardView = newSettings.board_flip() == BoardFlipMode::BFM_FLIPPED_X;
2055 return tl::unexpected( documentValidation.error() );
2059 BoardPlotSettingsResponse response;
2060 BoardPlotSettings* settings = response.mutable_plot_settings();
2067 settings->set_mirror( plotOpts.
GetMirror() );
2070 settings->set_scale( plotOpts.
GetScale() );
2077 settings->set_plot_footprint_values( plotOpts.
GetPlotValue() );
2093 return tl::unexpected( documentValidation.error() );
2095 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2096 return tl::unexpected( *busy );
2098 const BoardPlotSettings& settings = aCtx.
Request.plot_settings();
2105 for(
int layer : settings.common_layers() )
2112 ApiResponseStatus e;
2113 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2114 e.set_error_message( fmt::format(
"SetBoardPlotSettings contains an invalid layer {}",
2115 magic_enum::enum_name( layerId ) ) );
2116 return tl::unexpected( e );
2119 commonLayers.push_back( layerId );
2124 plotOpts.
SetMirror( settings.mirror() );
2127 plotOpts.
SetScale( settings.scale() );
2134 plotOpts.
SetPlotValue( settings.plot_footprint_values() );
2155 return tl::unexpected( documentValidation.error() );
2157 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2158 return tl::unexpected( *busy );
2166 drcItem->SetErrorMessage( wxString::FromUTF8( aCtx.
Request.message() ) );
2168 std::vector<KIID> ids;
2170 for(
const auto&
id : aCtx.
Request.items() )
2171 ids.emplace_back(
KIID(
id.value() ) );
2174 drcItem->SetItems( ids );
2176 const auto& pos = aCtx.
Request.position();
2177 VECTOR2I position(
static_cast<int>( pos.x_nm() ),
static_cast<int>( pos.y_nm() ) );
2182 commit->
Add( marker );
2187 InjectDrcErrorResponse response;
2195 const std::string& aCommandName )
2197 if( aUnits == types::Units::U_INCH || aUnits == types::Units::U_MM
2198 || aUnits == types::Units::U_UNKNOWN )
2200 return std::nullopt;
2203 ApiResponseStatus e;
2204 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2205 e.set_error_message( fmt::format(
"{} supports only inch and mm units", aCommandName ) );
2210std::optional<ApiResponseStatus>
2212 const std::string& aCommandName )
2214 if( aMode == kiapi::board::jobs::BoardJobPaginationMode::BJPM_UNKNOWN
2215 || aMode == kiapi::board::jobs::BoardJobPaginationMode::BJPM_ALL_LAYERS_ONE_PAGE
2216 || aMode == kiapi::board::jobs::BoardJobPaginationMode::BJPM_EACH_LAYER_OWN_FILE )
2218 return std::nullopt;
2221 ApiResponseStatus e;
2222 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2223 e.set_error_message( fmt::format(
"{} does not support EACH_LAYER_OWN_PAGE pagination mode",
2232 for(
int layer : aSettings.layers() )
2235 static_cast<board::types::BoardLayer
>( layer ) );
2237 if( !
IsPcbLayer(
static_cast<int>( layerId ) ) )
2239 ApiResponseStatus e;
2240 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2241 e.set_error_message(
"Board plot settings contain an invalid layer" );
2248 for(
int layer : aSettings.common_layers() )
2251 static_cast<board::types::BoardLayer
>( layer ) );
2253 if( !
IsPcbLayer(
static_cast<int>( layerId ) ) )
2255 ApiResponseStatus e;
2256 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2257 e.set_error_message(
"Board plot settings contain an invalid common layer" );
2264 aJob.
m_colorTheme = wxString::FromUTF8( aSettings.color_theme() );
2265 aJob.
m_drawingSheet = wxString::FromUTF8( aSettings.drawing_sheet() );
2266 aJob.
m_variant = wxString::FromUTF8( aSettings.variant() );
2268 aJob.
m_mirror = aSettings.mirror();
2271 aJob.
m_scale = aSettings.scale();
2279 aJob.
m_plotRefDes = aSettings.plot_reference_designators();
2289 return std::nullopt;
2295 types::RunJobResponse response;
2298 if( !aContext || !aContext->
GetKiway() )
2300 response.set_status( types::JobStatus::JS_ERROR );
2301 response.set_message(
"Internal error" );
2302 wxCHECK_MSG(
false, response,
"context missing valid kiway in ExecuteBoardJob?" );
2309 response.add_output_path( output.m_outputPath.ToUTF8() );
2313 response.set_status( types::JobStatus::JS_SUCCESS );
2317 response.set_status( types::JobStatus::JS_ERROR );
2318 response.set_message( fmt::format(
"Board export job '{}' failed with exit code {}: {}",
2320 reporter.GetMessages().ToStdString() ) );
2329 return tl::unexpected( validation.error() );
2331 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2332 return tl::unexpected( *busy );
2386 return tl::unexpected( validation.error() );
2388 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2389 return tl::unexpected( *busy );
2432 return tl::unexpected( validation.error() );
2434 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2435 return tl::unexpected( *busy );
2442 return tl::unexpected( *err );
2447 if( std::optional<ApiResponseStatus> paginationError =
2449 "RunBoardJobExportSvg" ) )
2451 return tl::unexpected( *paginationError );
2464 return tl::unexpected( validation.error() );
2466 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2467 return tl::unexpected( *busy );
2474 return tl::unexpected( *err );
2479 if( std::optional<ApiResponseStatus> unitError =
2482 return tl::unexpected( *unitError );
2487 if( std::optional<ApiResponseStatus> paginationError =
2489 "RunBoardJobExportDxf" ) )
2491 return tl::unexpected( *paginationError );
2504 return tl::unexpected( validation.error() );
2506 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2507 return tl::unexpected( *busy );
2514 return tl::unexpected( *err );
2532 return tl::unexpected( validation.error() );
2534 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2535 return tl::unexpected( *busy );
2542 return tl::unexpected( *err );
2544 if( std::optional<ApiResponseStatus> paginationError =
2546 "RunBoardJobExportPs" ) )
2548 return tl::unexpected( *paginationError );
2567 return tl::unexpected( validation.error() );
2569 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2570 return tl::unexpected( *busy );
2577 return tl::unexpected( *err );
2579 if( std::optional<ApiResponseStatus> paginationError =
2582 return tl::unexpected( *paginationError );
2593 ApiResponseStatus status;
2594 status.set_status( ApiStatusCode::AS_BAD_REQUEST );
2596 return tl::unexpected( status );
2614 return tl::unexpected( validation.error() );
2616 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2617 return tl::unexpected( *busy );
2628 return tl::unexpected( *err );
2637 switch( aCtx.
Request.precision() )
2640 case GerberPrecision::GP_5: job.
m_precision = 5;
break;
2641 case GerberPrecision::GP_6: job.
m_precision = 6;
break;
2652 return tl::unexpected( validation.error() );
2654 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2655 return tl::unexpected( *busy );
2663 if( std::optional<ApiResponseStatus> unitError =
2666 return tl::unexpected( *unitError );
2673 if( aCtx.
Request.has_excellon() )
2675 const ExcellonFormatOptions& excellonOptions = aCtx.
Request.excellon();
2677 if( excellonOptions.has_mirror_y() )
2680 if( excellonOptions.has_minimal_header() )
2683 if( excellonOptions.has_combine_pth_npth() )
2686 if( excellonOptions.has_route_oval_holes() )
2690 if( aCtx.
Request.map_format() != DrillMapFormat::DMF_UNKNOWN )
2698 if( aCtx.
Request.has_gerber_generate_tenting() )
2701 if( aCtx.
Request.report_format() != DrillReportFormat::DRF_UNKNOWN )
2705 if( aCtx.
Request.has_report_filename() )
2717 return tl::unexpected( validation.error() );
2719 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2720 return tl::unexpected( *busy );
2726 if( aCtx.
Request.has_use_drill_place_file_origin() )
2736 if( aCtx.
Request.has_include_board_edge_for_gerber() )
2743 if( std::optional<ApiResponseStatus> unitError =
2746 return tl::unexpected( *unitError );
2760 return tl::unexpected( validation.error() );
2762 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2763 return tl::unexpected( *busy );
2783 return tl::unexpected( validation.error() );
2785 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2786 return tl::unexpected( *busy );
2800 return tl::unexpected( validation.error() );
2802 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2803 return tl::unexpected( *busy );
2810 if( !aCtx.
Request.variant().empty() )
2815 if( aCtx.
Request.has_precision() )
2820 job.
m_colMfgPn = wxString::FromUTF8( aCtx.
Request.manufacturer_part_number_column() );
2821 job.
m_colMfg = wxString::FromUTF8( aCtx.
Request.manufacturer_column() );
2822 job.
m_colDistPn = wxString::FromUTF8( aCtx.
Request.distributor_part_number_column() );
2826 if( std::optional<ApiResponseStatus> unitError =
2829 return tl::unexpected( *unitError );
2846 return tl::unexpected( validation.error() );
2848 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2849 return tl::unexpected( *busy );
2862 aJob.
m_sections = aContent.sections().empty()
2864 : std::optional<wxString>( wxString::FromUTF8( aContent.sections() ) );
2871 aJob.
m_drawingSheet = wxString::FromUTF8( aRequest.drawing_sheet() );
2873 if( aRequest.variant_names_size() > 0 )
2875 for(
const std::string&
name : aRequest.variant_names() )
2878 else if( !aRequest.variant().empty() )
2880 aJob.
m_variantNames.push_back( wxString::FromUTF8( aRequest.variant() ) );
2884 aRequest.variant_packaging() );
2886 if( aRequest.has_precision() )
2892 aJob.
m_colMfgPn = wxString::FromUTF8( aRequest.manufacturer_part_number_column() );
2894 aJob.
m_productName = wxString::FromUTF8( aRequest.product_name() );
2903 return tl::unexpected( validation.error() );
2905 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2906 return tl::unexpected( *busy );
2912 if( std::optional<ApiResponseStatus> unitError =
2915 return tl::unexpected( *unitError );
2928 return tl::unexpected( validation.error() );
2930 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2931 return tl::unexpected( *busy );
2939 if( std::optional<ApiResponseStatus> unitError =
2942 return tl::unexpected( *unitError );
2959 return tl::unexpected( valid.error() );
2961 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
2962 return tl::unexpected( *busy );
2964 switch( aCtx.
Request.units() )
2966 case types::Units::U_UNKNOWN:
2967 case types::Units::U_MM:
2968 case types::Units::U_MILS:
2973 ApiResponseStatus e;
2974 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
2975 e.set_error_message(
"RunBoardJobExportIdf supports only mm and mils units" );
2976 return tl::unexpected( e );
2987 if( aCtx.
Request.origin_mode() == IdfOriginMode::IOM_USER )
2998 if( aCtx.
Request.has_part_number_field() )
3010 wxLogTrace(
traceApi,
"Received announce from frame %d at %s",
3016 CrossProbeAnnounceResponse response;
3017 response.set_status( CPS_OK );
3024 if( std::optional<ApiResponseStatus> headless =
checkForHeadless(
"SyncSelection" ) )
3025 return tl::unexpected( *headless );
3027 SyncSelectionResponse response;
3031 if( !settings.
on_selection && aCtx.
Request.context() != SyncSelectionContext::SSC_EXPLICIT )
3033 response.set_status( CPS_DISABLED );
3034 response.set_message(
"implicit selection sync disabled by user" );
3038 std::vector<BOARD_ITEM*> items =
3043 if( aCtx.
Request.mode() == SyncSelectionMode::SSM_ITEMS_AND_NETS )
3055 wxLogTrace(
traceCrossProbeFlash,
"MAIL_SELECTION(_FORCE) PCB: flash enabled, items=%zu", items.size() );
3062 std::vector<BOARD_ITEM*> boardItems;
3063 std::copy( items.begin(), items.end(), std::back_inserter( boardItems ) );
3072 response.set_status( CPS_OK );
3080 if( std::optional<ApiResponseStatus> headless =
checkForHeadless(
"HighlightNets" ) )
3081 return tl::unexpected( *headless );
3083 HighlightNetsResponse response;
3091 response.set_status( CPS_DISABLED );
3092 response.set_message(
"net highlight cross-probing disabled by user" );
3097 std::vector<wxString> nets;
3099 for(
const std::string&
name : aCtx.
Request.net_name() )
3100 nets.emplace_back( wxString::FromUTF8(
name ) );
3104 response.set_status( CPS_OK );
3112 return tl::unexpected( documentValidation.error() );
3114 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
3115 return tl::unexpected( *busy );
3118 VariantsResponse response;
3122 for(
const wxString&
name :
board->GetVariantNames() )
3124 types::DesignVariant* var = response.add_variants();
3125 var->set_name(
name.ToUTF8() );
3126 var->set_description(
board->GetVariantDescription(
name ).ToUTF8() );
3136 return tl::unexpected( documentValidation.error() );
3138 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
3139 return tl::unexpected( *busy );
3143 wxString
name = wxString::FromUTF8( aCtx.
Request.name() );
3147 ApiResponseStatus e;
3148 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3149 e.set_error_message( fmt::format(
"'{}' is not a valid variant name", aCtx.
Request.name() ) );
3150 return tl::unexpected( e );
3155 ApiResponseStatus e;
3156 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3157 e.set_error_message( fmt::format(
"a variant named '{}' already exists", aCtx.
Request.name() ) );
3158 return tl::unexpected( e );
3163 if( aCtx.
Request.has_description() )
3164 board->SetVariantDescription(
name, wxString::FromUTF8( aCtx.
Request.description() ) );
3178 return tl::unexpected( documentValidation.error() );
3180 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
3181 return tl::unexpected( *busy );
3185 wxString
name = wxString::FromUTF8( aCtx.
Request.name() );
3189 ApiResponseStatus e;
3190 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3191 e.set_error_message( fmt::format(
"'{}' is not a valid variant name", aCtx.
Request.name() ) );
3192 return tl::unexpected( e );
3197 ApiResponseStatus e;
3198 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3199 e.set_error_message( fmt::format(
"no variant named '{}' exists", aCtx.
Request.name() ) );
3200 return tl::unexpected( e );
3217 return tl::unexpected( documentValidation.error() );
3219 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
3220 return tl::unexpected( *busy );
3224 wxString oldName = wxString::FromUTF8( aCtx.
Request.old_name() );
3225 wxString newName = wxString::FromUTF8( aCtx.
Request.new_name() );
3229 ApiResponseStatus e;
3230 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3231 e.set_error_message( fmt::format(
"'{}' is not a valid variant name", aCtx.
Request.old_name() ) );
3232 return tl::unexpected( e );
3237 ApiResponseStatus e;
3238 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3239 e.set_error_message( fmt::format(
"'{}' is not a valid variant name", aCtx.
Request.new_name() ) );
3240 return tl::unexpected( e );
3243 if( !
board->HasVariant( oldName ) )
3245 ApiResponseStatus e;
3246 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3247 e.set_error_message( fmt::format(
"no variant named '{}' exists", aCtx.
Request.old_name() ) );
3248 return tl::unexpected( e );
3251 if(
board->HasVariant( newName ) )
3253 ApiResponseStatus e;
3254 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3255 e.set_error_message( fmt::format(
"a variant named '{}' already exists", aCtx.
Request.new_name() ) );
3256 return tl::unexpected( e );
3259 board->RenameVariant( oldName, newName );
3273 return tl::unexpected( documentValidation.error() );
3275 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
3276 return tl::unexpected( *busy );
3280 wxString oldName = wxString::FromUTF8( aCtx.
Request.old_name() );
3281 wxString newName = wxString::FromUTF8( aCtx.
Request.new_name() );
3285 ApiResponseStatus e;
3286 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3287 e.set_error_message( fmt::format(
"'{}' is not a valid variant name", aCtx.
Request.old_name() ) );
3288 return tl::unexpected( e );
3293 ApiResponseStatus e;
3294 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3295 e.set_error_message( fmt::format(
"'{}' is not a valid variant name", aCtx.
Request.new_name() ) );
3296 return tl::unexpected( e );
3299 if( !
board->HasVariant( oldName ) )
3301 ApiResponseStatus e;
3302 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3303 e.set_error_message( fmt::format(
"no variant named '{}' exists", aCtx.
Request.old_name() ) );
3304 return tl::unexpected( e );
3307 if(
board->HasVariant( newName ) )
3309 ApiResponseStatus e;
3310 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3311 e.set_error_message( fmt::format(
"a variant named '{}' already exists", aCtx.
Request.new_name() ) );
3312 return tl::unexpected( e );
3315 board->CopyVariant( oldName, newName,
3316 aCtx.
Request.has_new_description() ? wxString::FromUTF8( aCtx.
Request.new_description() )
3331 return tl::unexpected( documentValidation.error() );
3333 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
3334 return tl::unexpected( *busy );
3338 wxString
name = wxString::FromUTF8( aCtx.
Request.name() );
3342 ApiResponseStatus e;
3343 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3344 e.set_error_message( fmt::format(
"no variant named '{}' exists", aCtx.
Request.name() ) );
3345 return tl::unexpected( e );
3348 board->SetVariantDescription(
name, wxString::FromUTF8( aCtx.
Request.description() ) );
3359 return tl::unexpected( documentValidation.error() );
3361 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
3362 return tl::unexpected( *busy );
3370 ApiResponseStatus e;
3371 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3372 e.set_error_message( fmt::format(
"no variant named '{}' exists", aCtx.
Request.name() ) );
3373 return tl::unexpected( e );
3377 wxString varName = aCtx.
Request.has_name() ? wxString::FromUTF8( aCtx.
Request.name() ) : wxString();
3382 board->SetCurrentVariant( varName );
3392 return tl::unexpected( documentValidation.error() );
3394 CurrentVariantResponse response;
3396 if( wxString current =
pcbContext()->GetBoard()->GetCurrentVariant(); !current.IsEmpty() )
3397 response.set_name( current.ToUTF8() );
3408 ApiResponseStatus e;
3409 e.set_status( ApiStatusCode::AS_UNHANDLED );
3410 return tl::unexpected( e );
3413 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
3414 return tl::unexpected( *busy );
3420 ApiResponseStatus e;
3421 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3422 e.set_error_message(
"lib_id must specify both a library nickname and an entry name" );
3423 return tl::unexpected( e );
3434 ApiResponseStatus e;
3435 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3436 e.set_error_message(
"layer must be F_Cu or B_Cu" );
3437 return tl::unexpected( e );
3444 ApiResponseStatus e;
3445 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
3446 e.set_error_message( fmt::format(
"footprint '{}' not found", libId.
Format().
wx_str() ) );
3447 return tl::unexpected( e );
3450 footprint->SetUuid(
KIID() );
3451 footprint->RunOnChildren(
3458 footprint->SetParent(
board() );
3462 if( aCtx.
Request.has_orientation() )
3463 footprint->SetOrientationDegrees( aCtx.
Request.orientation().value_degrees() );
3465 footprint->SetLayerAndFlip( layer );
3468 FOOTPRINT* placed = footprint.release();
3469 commit->
Add( placed );
3474 PlaceFromLibraryResponse response;
3475 response.mutable_header()->CopyFrom( aCtx.
Request.header() );
3476 placed->
Serialize( *response.mutable_item() );
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
tl::expected< T, ApiResponseStatus > HANDLER_RESULT
std::optional< ApiResponseStatus > ValidatePaginationModeForSingleOrPerFile(kiapi::board::jobs::BoardJobPaginationMode aMode, const std::string &aCommandName)
HANDLER_RESULT< Empty > unpackEmbeddedFiles(EMBEDDED_FILES &aOutput, const common::types::EmbeddedFiles &aProto)
void ApplyOdbJobRequest(const RunBoardJobExportODB &aRequest, JOB_EXPORT_PCB_ODB &aJob)
std::optional< ApiResponseStatus > ApplyBoardPlotSettings(const BoardPlotSettings &aSettings, JOB_EXPORT_PCB_PLOT &aJob)
std::optional< ApiResponseStatus > ValidateUnitsInchMm(types::Units aUnits, const std::string &aCommandName)
HANDLER_RESULT< types::RunJobResponse > ExecuteBoardJob(PCB_CONTEXT *aContext, JOB &aJob)
void ApplyFabExportContent(const FabExportContent &aContent, JOB_EXPORT_PCB_FAB &aJob)
static const std::vector< KICAD_T > s_allowedBoardTypes
void ApplyOdbJobRequest(const kiapi::board::jobs::RunBoardJobExportODB &aRequest, JOB_EXPORT_PCB_ODB &aJob)
void ApplyFabExportContent(const kiapi::board::jobs::FabExportContent &aContent, JOB_EXPORT_PCB_FAB &aJob)
BASE_SCREEN class implementation.
constexpr EDA_IU_SCALE pcbIUScale
static TOOL_ACTION selectionClear
Clear the current selection.
static TOOL_ACTION gridSetOrigin
API_HANDLER_BOARD(std::shared_ptr< BOARD_CONTEXT > aContext, EDA_BASE_FRAME *aFrame=nullptr)
std::unique_ptr< COMMIT > createCommit() override
Override this to create an appropriate COMMIT subclass for the frame in question.
TOOL_MANAGER * toolManager() const
std::vector< KICAD_T > parseRequestedItemTypes(const google::protobuf::RepeatedField< int > &aTypes)
PROJECT & project() const
void pushCurrentCommit(const std::string &aClientName, const wxString &aMessage) override
BOARD_CONTEXT * context() const
std::optional< ApiResponseStatus > checkForHeadless(const std::string &aCommandName) const
std::optional< BOARD_ITEM * > getItemById(const KIID &aId) const
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)
COMMIT * getCurrentCommit(const std::string &aClientName)
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< ImportNetlistResponse > handleImportNetlist(const HANDLER_CONTEXT< ImportNetlist > &aCtx)
HANDLER_RESULT< BoardPlotSettingsResponse > handleGetBoardPlotSettings(const HANDLER_CONTEXT< GetBoardPlotSettings > &aCtx)
HANDLER_RESULT< Empty > handleDeleteVariant(const HANDLER_CONTEXT< commands::DeleteVariant > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportPdf(const HANDLER_CONTEXT< RunBoardJobExportPdf > &aCtx)
HANDLER_RESULT< google::protobuf::Empty > handleSetEmbeddedFiles(const HANDLER_CONTEXT< SetEmbeddedFiles > &aCtx)
HANDLER_RESULT< commands::CurrentVariantResponse > handleGetCurrentVariant(const HANDLER_CONTEXT< commands::GetCurrentVariant > &aCtx)
HANDLER_RESULT< BoardDesignRulesResponse > handleSetBoardDesignRules(const HANDLER_CONTEXT< SetBoardDesignRules > &aCtx)
HANDLER_RESULT< kiapi::common::tasks::StartTaskResponse > handleStartDrcTask(const HANDLER_CONTEXT< kiapi::board::tasks::StartDrcTask > &aCtx)
API_HANDLER_PCB(PCB_EDIT_FRAME *aFrame)
HANDLER_RESULT< Empty > handleAddVariant(const HANDLER_CONTEXT< commands::AddVariant > &aCtx)
HANDLER_RESULT< commands::GetItemsResponse > handleGetConnectedItems(const HANDLER_CONTEXT< GetConnectedItems > &aCtx)
HANDLER_RESULT< commands::VariantsResponse > handleGetVariants(const HANDLER_CONTEXT< commands::GetVariants > &aCtx)
HANDLER_RESULT< types::Vector2 > handleGetBoardOrigin(const HANDLER_CONTEXT< GetBoardOrigin > &aCtx)
HANDLER_RESULT< commands::GetItemsResponse > handleGetItemsByNetClass(const HANDLER_CONTEXT< GetItemsByNetClass > &aCtx)
HANDLER_RESULT< Empty > handleSaveDocumentAs(const HANDLER_CONTEXT< commands::SaveDocumentAs > &aCtx)
HANDLER_RESULT< NetClassForNetsResponse > handleGetNetClassForNets(const HANDLER_CONTEXT< GetNetClassForNets > &aCtx)
HANDLER_RESULT< commands::CrossProbeAnnounceResponse > handleCrossProbeAnnounce(const HANDLER_CONTEXT< commands::CrossProbeAnnounce > &aCtx)
HANDLER_RESULT< Empty > handleCopyVariant(const HANDLER_CONTEXT< commands::CopyVariant > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportIpcD356(const HANDLER_CONTEXT< RunBoardJobExportIpcD356 > &aCtx)
PCB_CONTEXT * pcbContext() const
HANDLER_RESULT< BoardDesignRulesResponse > handleGetBoardDesignRules(const HANDLER_CONTEXT< GetBoardDesignRules > &aCtx)
HANDLER_RESULT< commands::GetDocumentModifiedStateResponse > handleGetDocumentModifiedState(const HANDLER_CONTEXT< commands::GetDocumentModifiedState > &aCtx) override
HANDLER_RESULT< kiapi::common::tasks::StartTaskResponse > handleStartRefillZonesTask(const HANDLER_CONTEXT< kiapi::board::tasks::StartRefillZonesTask > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportGerbers(const HANDLER_CONTEXT< RunBoardJobExportGerbers > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportODB(const HANDLER_CONTEXT< RunBoardJobExportODB > &aCtx)
HANDLER_RESULT< Empty > handleSaveCopyOfDocument(const HANDLER_CONTEXT< commands::SaveCopyOfDocument > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExport3D(const HANDLER_CONTEXT< RunBoardJobExport3D > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportSpecctraDsn(const HANDLER_CONTEXT< RunBoardJobExportSpecctraDsn > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportPng(const HANDLER_CONTEXT< RunBoardJobExportPng > &aCtx)
HANDLER_RESULT< Empty > handleSetCurrentVariant(const HANDLER_CONTEXT< commands::SetCurrentVariant > &aCtx)
void setDrawingSheetFileName(const wxString &aFileName) override
HANDLER_RESULT< commands::GetItemsResponse > handleGetItemsByNet(const HANDLER_CONTEXT< GetItemsByNet > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportIpc2581(const HANDLER_CONTEXT< RunBoardJobExportIpc2581 > &aCtx)
std::optional< TITLE_BLOCK * > getTitleBlock(const DocumentSpecifier &aDocument) override
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportPosition(const HANDLER_CONTEXT< RunBoardJobExportPosition > &aCtx)
HANDLER_RESULT< Empty > handleSetBoardOrigin(const HANDLER_CONTEXT< SetBoardOrigin > &aCtx)
HANDLER_RESULT< Empty > handleSetBoardPlotSettings(const HANDLER_CONTEXT< SetBoardPlotSettings > &aCtx)
HANDLER_RESULT< BoardLayerNameResponse > handleGetBoardLayerName(const HANDLER_CONTEXT< GetBoardLayerName > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportStats(const HANDLER_CONTEXT< RunBoardJobExportStats > &aCtx)
void onModified() override
HANDLER_RESULT< ImportSpecctraSessionResponse > handleImportSpecctraSession(const HANDLER_CONTEXT< ImportSpecctraSession > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportPs(const HANDLER_CONTEXT< RunBoardJobExportPs > &aCtx)
HANDLER_RESULT< CustomRulesResponse > handleGetCustomDesignRules(const HANDLER_CONTEXT< GetCustomDesignRules > &aCtx)
bool setPageSettings(const DocumentSpecifier &aDocument, const PAGE_INFO &aPageInfo) override
HANDLER_RESULT< std::vector< ZONE * > > resolveZonesToFill(const google::protobuf::RepeatedPtrField< kiapi::common::types::KIID > &aZoneIds) const
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportSvg(const HANDLER_CONTEXT< RunBoardJobExportSvg > &aCtx)
kiapi::common::types::DocumentType thisDocumentType() const override
Override this to specify which document type this editor handles.
HANDLER_RESULT< commands::GetOpenDocumentsResponse > handleGetOpenDocuments(const HANDLER_CONTEXT< commands::GetOpenDocuments > &aCtx)
HANDLER_RESULT< commands::SyncSelectionResponse > handleSyncSelection(const HANDLER_CONTEXT< commands::SyncSelection > &aCtx)
HANDLER_RESULT< BoardEditorAppearanceSettings > handleGetBoardEditorAppearanceSettings(const HANDLER_CONTEXT< GetBoardEditorAppearanceSettings > &aCtx)
HANDLER_RESULT< NetsResponse > handleGetNets(const HANDLER_CONTEXT< GetNets > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportDxf(const HANDLER_CONTEXT< RunBoardJobExportDxf > &aCtx)
HANDLER_RESULT< Empty > handleSetVariantDescription(const HANDLER_CONTEXT< commands::SetVariantDescription > &aCtx)
HANDLER_RESULT< Empty > handleSaveDocument(const HANDLER_CONTEXT< commands::SaveDocument > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportDrill(const HANDLER_CONTEXT< RunBoardJobExportDrill > &aCtx)
HANDLER_RESULT< commands::GetItemsResponse > handleGetItems(const HANDLER_CONTEXT< commands::GetItems > &aCtx)
HANDLER_RESULT< kiapi::common::commands::PlaceFromLibraryResponse > handlePlaceFootprintFromLibrary(const HANDLER_CONTEXT< kiapi::board::commands::PlaceFootprintFromLibrary > &aCtx)
HANDLER_RESULT< kiapi::board::tasks::DrcTaskResult > handleGetDrcTaskResult(const HANDLER_CONTEXT< kiapi::board::tasks::GetDrcTaskResult > &aCtx)
HANDLER_RESULT< InjectDrcErrorResponse > handleInjectDrcError(const HANDLER_CONTEXT< InjectDrcError > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportRender(const HANDLER_CONTEXT< RunBoardJobExportRender > &aCtx)
PCB_EDIT_FRAME * frame() const
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportGencad(const HANDLER_CONTEXT< RunBoardJobExportGencad > &aCtx)
HANDLER_RESULT< BoardEnabledLayersResponse > handleSetBoardEnabledLayers(const HANDLER_CONTEXT< SetBoardEnabledLayers > &aCtx)
HANDLER_RESULT< Empty > handleRenameVariant(const HANDLER_CONTEXT< commands::RenameVariant > &aCtx)
std::optional< PAGE_INFO > getPageSettings(const DocumentSpecifier &aDocument) override
HANDLER_RESULT< Empty > handleSetBoardEditorAppearanceSettings(const HANDLER_CONTEXT< SetBoardEditorAppearanceSettings > &aCtx)
tl::expected< bool, ApiResponseStatus > validateDocumentInternal(const DocumentSpecifier &aDocument) const override
HANDLER_RESULT< Empty > handleRefillZones(const HANDLER_CONTEXT< RefillZones > &aCtx)
HANDLER_RESULT< commands::HighlightNetsResponse > handleHighlightNets(const HANDLER_CONTEXT< commands::HighlightNets > &aCtx)
HANDLER_RESULT< types::RunJobResponse > handleRunBoardJobExportIdf(const HANDLER_CONTEXT< RunBoardJobExportIdf > &aCtx)
HANDLER_RESULT< google::protobuf::Empty > handleAddEmbeddedFiles(const HANDLER_CONTEXT< AddEmbeddedFiles > &aCtx)
HANDLER_RESULT< common::types::EmbeddedFiles > handleGetEmbeddedFiles(const HANDLER_CONTEXT< GetEmbeddedFiles > &aCtx)
HANDLER_RESULT< BoardLayerResponse > handleGetBoardLayerByName(const HANDLER_CONTEXT< GetBoardLayerByName > &aCtx)
HANDLER_RESULT< Empty > handleRevertDocument(const HANDLER_CONTEXT< commands::RevertDocument > &aCtx)
HANDLER_RESULT< CustomRulesResponse > handleSetCustomDesignRules(const HANDLER_CONTEXT< SetCustomDesignRules > &aCtx)
void onNetSettingsChanged() override
Called on all registered handlers after project net settings (netclasses or netclass assignments) hav...
wxString getDrawingSheetFileName() override
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 Revert() override
Revert the commit by restoring the modified items state.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual KIWAY * GetKiway() const =0
virtual BOARD * GetBoard() const =0
Container for design settings for a BOARD object.
int m_CopperEdgeClearance
std::map< int, SEVERITY > m_DRCSeverities
void SetGridOrigin(const VECTOR2I &aOrigin)
std::vector< DIFF_PAIR_DIMENSION > m_DiffPairDimensionsList
int m_SolderMaskToCopperClearance
const VECTOR2I & GetGridOrigin() const
bool m_AllowSoldermaskBridgesInFPs
TEARDROP_PARAMETERS_LIST m_TeardropParamsList
The parameters of teardrops for the different teardrop targets (via/pad, track end).
void SetAuxOrigin(const VECTOR2I &aOrigin)
const VECTOR2I & GetAuxOrigin() const
int m_SolderMaskExpansion
std::vector< int > m_TrackWidthList
std::vector< VALIDATION_ERROR > ValidateDesignRules(std::optional< EDA_UNITS > aUnits=std::nullopt) const
Validate design settings values and return per-field errors.
double m_SolderPasteMarginRatio
std::vector< VIA_DIMENSION > m_ViasDimensionsList
int m_ViasMinAnnularWidth
std::set< DRC_EXCLUSION, DRC_EXCLUSION_COMPARE > m_DrcExclusions
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual void CopyFrom(const BOARD_ITEM *aOther)
Information pertinent to a Pcbnew printed circuit board.
void SetPlotOptions(const PCB_PLOT_PARAMS &aOptions)
EMBEDDED_FILES * GetEmbeddedFiles() override
const PAGE_INFO & GetPageSettings() const
void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aSettings)
TITLE_BLOCK & GetTitleBlock()
PCB_LAYER_ID GetLayerID(const wxString &aLayerName) const
Return the ID of a layer.
void SetPageSettings(const PAGE_INFO &aPageSettings)
const wxString & GetFileName() const
const PCB_PLOT_PARAMS & GetPlotOptions() const
wxString GetDesignRulesPath() const
Return the absolute path to the design rules file for this board.
BOARD_DESIGN_SETTINGS & GetDesignSettings()
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Represent a set of changes (additions, deletions or modifications) of a data model (e....
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
static void RegisterPeer(FRAME_T aFrameType, const std::string &aSocketPath)
void ToProto(kiapi::board::CustomRuleConstraint &aProto) const
Container for an DRC exclusion, which is a PCB_MARKER plus an optional comment.
static DRC_EXCLUSION FromProto(const kiapi::board::DrcExclusion &aMessage)
const kiapi::board::DrcExclusion & ToProto() const
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
void Parse(std::vector< std::shared_ptr< DRC_RULE > > &aRules, REPORTER *aReporter)
static wxString ExtractRuleComment(const wxString &aOriginalText)
Extract comment lines from a rule.
static wxString ExtractRuleText(const wxString &aContent, const wxString &aRuleName)
Extract the complete original text of a rule from file content.
static wxString FormatRuleFromProto(const kiapi::board::CustomRule &aRule, wxString *aErrorText=nullptr)
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
const std::map< wxString, std::shared_ptr< EMBEDDED_FILE > > & EmbeddedFileMap() const
Provide an iterable view of the file collection.
static const TOOL_EVENT SelectedItemsModified
Selected item had a property changed (except movement)
double m_BoardOutlinesChainingEpsilon
bool m_IncludeUnspecified
wxString m_ComponentFilter
bool m_UsePcbCenterOrigin
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
JOB_EXPORT_PCB_3D::FORMAT m_format
EXPORTER_STEP_PARAMS m_3dparams
Despite the name; also used for other formats.
ZEROS_FORMAT m_zeroFormat
bool m_excellonOvalDrillRoute
DRILL_ORIGIN m_drillOrigin
bool m_excellonCombinePTHNPTH
bool m_excellonMinimalHeader
bool m_plotGraphicItemsUsingContours
std::optional< wxString > m_sections
Section key that replaces the optional sections of the data set Unset lets the data set select them a...
std::vector< wxString > m_variantNames
bool m_checkZonesBeforeExport
bool m_useIndividualShapes
bool m_useBoardPlotParams
bool m_useProtelFileExtension
bool m_includeNetlistAttributes
bool m_disableApertureMacros
IDF_SETTINGS::COORD_ORIGIN m_originMode
bool m_calculateHeightFromModels
VECTOR2D m_userOrigin
In whatever units the user specified in m_units.
wxString m_partNumberField
IDF_SETTINGS::UNITS m_units
bool m_includeUnspecified
IPC2581_VERSION m_version
VARIANT_PACKAGING m_variantPackaging
ODB_COMPRESSION m_compressionMode
bool m_pdfFrontFPPropertyPopups
wxString m_pdfBackgroundColor
The background color specified in a hex string.
bool m_pdfBackFPPropertyPopups
GEN_MODE m_pdfGenMode
uused by the cli, will be removed when the other behavior is deprecated
bool m_sketchDNPFPsOnFabLayers
bool m_useDrillOrigin
Used by SVG/DXF/PDF/Gerbers.
bool m_plotFootprintValues
LSEQ m_plotOnAllLayersSequence
Layers to include on all individual layer prints.
bool m_checkZonesBeforePlot
bool m_sketchPadsOnFabLayers
DRILL_MARKS m_drillShapeOption
Used by SVG & PDF.
bool m_crossoutDNPFPsOnFabLayers
bool m_hideDNPFPsOnFabLayers
bool m_mirror
Common Options.
bool m_subtractSolderMaskFromSilk
bool m_useBackgroundColor
wxString m_variant
Variant name for variant-aware filtering.
bool m_useDrillPlaceFileOrigin
bool m_excludeFootprintsWithTh
double m_trackWidthCorrection
bool m_subtractHolesFromBoardArea
bool m_excludeFootprintsWithoutPads
bool m_subtractHolesFromCopperAreas
VECTOR3D m_lightBottomIntensity
VECTOR3D m_lightTopIntensity
VECTOR3D m_lightCameraIntensity
bool m_proceduralTextures
bool m_useBoardStackupColors
VECTOR3D m_lightSideIntensity
std::string m_appearancePreset
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
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
std::string AsStdString() const
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
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.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
LSET is a set of PCB_LAYER_IDs.
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
static int NameToLayer(wxString &aName)
Return the layer number from a layer name.
A collection of nets and the parameters used to route or test these nets.
bool ContainsNetclassWithName(const wxString &netclass) const
Determines if the given netclass name is a constituent of this (maybe aggregate) netclass.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Handle the data for a net.
Container for NETINFO_ITEM elements, which are the nets.
NETINFO_ITEM * GetNetItem(int aNetCode) const
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Describe the page size and margins of a paper page on which to eventually print or plot.
DISPLAY_OPTIONS m_Display
static TOOL_ACTION zoneFillAll
static TOOL_ACTION syncSelection
Sets selection to specified items, zooms to fit, if enabled.
static TOOL_ACTION drillSetOrigin
static TOOL_ACTION syncSelectionWithNets
Sets selection to specified items with connected nets, zooms to fit, if enabled.
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
PCBNEW_SETTINGS * GetPcbNewSettings() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aRefresh=true)
Update the current display options.
virtual void Update3DView(bool aMarkDirty, bool aRefresh, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
PCB-editor-specific context; extends BOARD_CONTEXT with save/filename operations.
virtual wxString GetCurrentFileName() const =0
virtual void OnNetlistChanged(BOARD_NETLIST_UPDATER &aUpdater)=0
Post-import board sync (nets, classes, DRC, ratsnest, new footprint placement).
virtual bool ReadNetlistFromFile(const wxString &aFilename, NETLIST &aNetlist, REPORTER &aReporter)=0
Read a netlist file and preload component footprints.
virtual void SetContentModified(bool aModified=true)=0
virtual std::unique_ptr< BOARD_NETLIST_UPDATER > MakeNetlistUpdater()=0
Create a netlist updater bound to this context's board.
bool m_FlipBoardView
true if the board is flipped to show the mirrored view
HIGH_CONTRAST_MODE m_ContrastModeDisplay
How inactive layers are displayed.
NET_COLOR_MODE m_NetColorMode
How to use color overrides on specific nets and netclasses.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the KIGFX::VIEW instance used in the panel.
The main frame for Pcbnew.
void LoadDrawingSheet()
Load the drawing sheet file.
void OnModify() override
Must be called after a board change to set the modified flag.
void StartCrossProbeFlash(const std::vector< BOARD_ITEM * > &aItems)
void UpdateVariantSelectionCtrl()
Update the variant selection dropdown with the current board's variant names.
void SetCurrentVariant(const wxString &aVariantName)
Set the current variant on the board and update the drawing sheet's cached variant name and descripti...
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility,...
void HandleRemoteNetHighlight(const std::vector< wxString > &aNetNames)
const KIID GetUUID() const override
Parameters and options when plotting/printing a board.
void SetDrillMarksType(DRILL_MARKS aVal)
bool GetUseAuxOrigin() const
LSEQ GetPlotOnAllLayersSequence() const
bool GetHideDNPFPsOnFabLayers() const
void SetLayerSelection(const LSET &aSelection)
void SetPlotReference(bool aFlag)
void SetSketchPadsOnFabLayers(bool aFlag)
bool GetCrossoutDNPFPsOnFabLayers() const
bool GetSketchDNPFPsOnFabLayers() const
void SetPlotOnAllLayersSequence(LSEQ aSeq)
void SetPlotFrameRef(bool aFlag)
void SetSketchDNPFPsOnFabLayers(bool aFlag)
void SetPlotPadNumbers(bool aFlag)
LSET GetLayerSelection() const
bool GetPlotReference() const
void SetScale(double aVal)
void SetMirror(bool aFlag)
void SetBlackAndWhite(bool blackAndWhite)
void SetSubtractMaskFromSilk(bool aSubtract)
bool GetSketchPadsOnFabLayers() const
void SetHideDNPFPsOnFabLayers(bool aFlag)
bool GetSubtractMaskFromSilk() const
void SetPlotValue(bool aFlag)
bool GetPlotPadNumbers() const
DRILL_MARKS GetDrillMarksType() const
bool GetPlotValue() const
void SetNegative(bool aFlag)
bool GetBlackAndWhite() const
void SetUseAuxOrigin(bool aAux)
bool GetPlotFrameRef() const
void SetCrossoutDNPFPsOnFabLayers(bool aFlag)
wxString m_BoardDrawingSheetFile
PcbNew params.
virtual PROJECT_FILE & GetProjectFile() const
TEARDROP_PARAMETERS_LIST is a helper class to handle the list of TEARDROP_PARAMETERS needed to build ...
bool m_UseRoundShapesOnly
True to create teardrops for round shapes only.
bool m_TargetVias
True to create teardrops for vias.
bool m_TargetPTHPads
True to create teardrops for pads with holes.
bool m_TargetTrack2Track
True to create teardrops at the end of a track connected to the end of another track having a differe...
TEARDROP_PARAMETERS * GetParameters(TARGET_TD aTdType)
bool m_TargetSMDPads
True to create teardrops for pads SMD, edge connectors,.
TEARDROP_PARAMETARS is a helper class to handle parameters needed to build teardrops for a board thes...
double m_BestWidthRatio
The height of a teardrop as ratio between height and size of pad/via.
int m_TdMaxLen
max allowed length for teardrops in IU. <= 0 to disable
bool m_AllowUseTwoTracks
True to create teardrops using 2 track segments if the first in too small.
int m_TdMaxWidth
max allowed height for teardrops in IU. <= 0 to disable
double m_BestLengthRatio
The length of a teardrop as ratio between length and size of pad/via.
double m_WidthtoSizeFilterRatio
The ratio (H/D) between the via/pad size and the track width max value to create a teardrop 1....
bool m_TdOnPadsInZones
A filter to exclude pads inside zone fills.
bool m_Enabled
Flag to enable teardrops.
bool m_CurvedEdges
True if the teardrop should be curved.
A wrapper for reporting to a wxString object.
bool Fill(const std::vector< ZONE * > &aZones, bool aCheck=false, wxWindow *aParent=nullptr)
Fills the given list of zones.
Handle a list of polygons defining a copper zone.
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
static std::string ToStdString(const wxString &aStr)
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
static const std::string KiCadPcbFileExtension
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.
bool IsPcbLayer(int aLayer)
Test whether a layer is a valid layer for Pcbnew.
@ LAYER_DRC_WARNING
Layer for DRC markers with RPT_SEVERITY_WARNING.
@ LAYER_DRC_ERROR
Layer for DRC markers with RPT_SEVERITY_ERROR.
bool IsExternalCopperLayer(int aLayerId)
Test whether a layer is an external (F_Cu or B_Cu) copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
bool ImportSpecctraSession(BOARD *aBoard, const wxString &fullFileName, COMMIT &aCommit, REPORTER *aReporter=nullptr, int *aSkippedCount=nullptr)
Helper method to import SES file to a board.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
void PackLayerSet(google::protobuf::RepeatedField< int > &aOutput, const LSET &aLayerSet)
void PackEmbeddedFiles(common::types::EmbeddedFiles &aOutput, const EMBEDDED_FILES &aFiles)
bool UnpackEmbeddedFiles(EMBEDDED_FILES &aOutput, const common::types::EmbeddedFiles &aProto)
LSET UnpackLayerSet(const google::protobuf::RepeatedField< int > &aProtoLayerSet)
std::vector< BOARD_ITEM * > FindItemsFromSyncSelection(const BOARD *aBoard, const google::protobuf::RepeatedPtrField< kiapi::common::commands::SelectionSpec > &aItems)
Resolve a cross-probe selection request against a board.
KICOMMON_API VECTOR3D UnpackVector3D(const types::Vector3D &aInput)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API LIB_ID UnpackLibId(const types::LibraryIdentifier &aId)
const KICOMMON_API std::string KiwayClientName
const KICOMMON_API std::string StandaloneCrossProbeClientName
std::shared_ptr< PCB_CONTEXT > CreatePcbFrameContext(PCB_EDIT_FRAME *aFrame)
Class to handle a set of BOARD_ITEMs.
FOOTPRINT * LoadFootprintFromProject(BOARD *aBoard, const LIB_ID &aFootprintId, bool aKeepUuid)
Load a footprint from the project library table and apply board default settings.
PGM_BASE & Pgm()
The global program "get" accessor.
constexpr int MIN_PNG_DPI
constexpr int MAX_PNG_DPI
#define SKIP_CONNECTIVITY
wxString GetDefaultVariantName()
bool flash_selection
Flash newly cross-probed selection (visual attention aid).
bool on_selection
Synchronize the selection for multiple items too.
bool auto_highlight
Automatically turn on highlight mode in the target frame.
RequestMessageType Request
RATSNEST_MODE m_RatsnestMode
IbisParser parser & reporter
wxString result
Test unit parsing edge cases and error handling.
wxLogTrace helper definitions.
constexpr KICAD_T BaseType(const KICAD_T aType)
Return the underlying type of the given type.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
@ PCB_CONSTRAINT_T
a geometric constraint between board items
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_DRILL_MAP_T
class PCB_DRILL_MAP, drill symbols drawn at the holes
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_3D_BODY_T
class PCB_3D_BODY, a 3D body (extruded or model) on a footprint
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_GRID_ITEM_T
a subgrid placed on a board
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
@ PCB_STACKUP_TABLE_T
class PCB_STACKUP_TABLE, a live stackup table derived from PCB_TABLE
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
@ PCB_DRILL_CHART_T
class PCB_DRILL_CHART, a live drill chart derived from PCB_TABLE
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D