21#include <magic_enum.hpp>
47#include <api/common/types/base_types.pb.h>
50using namespace kiapi::common::commands;
51using types::CommandStatus;
52using types::DocumentType;
53using types::ItemRequestStatus;
60 registerHandler<GetOpenDocuments, GetOpenDocumentsResponse>(
71 registerHandler<RemoveFromSelection, SelectionResponse>(
75 registerHandler<GetGraphicsDefaults, GraphicsDefaultsResponse>(
77 registerHandler<GetBoundingBox, GetBoundingBoxResponse>(
79 registerHandler<GetPadShapeAsPolygon, PadShapeAsPolygonResponse>(
81 registerHandler<GetTitleBlockInfo, types::TitleBlockInfo>(
83 registerHandler<ExpandTextVariables, ExpandTextVariablesResponse>(
90 registerHandler<GetNetClassForNets, NetClassForNetsResponse>(
94 registerHandler<SaveDocumentToString, SavedDocumentResponse>(
96 registerHandler<SaveSelectionToString, SavedSelectionResponse>(
98 registerHandler<ParseAndCreateItemsFromString, CreateItemsResponse>(
104 registerHandler<GetBoardEditorAppearanceSettings, BoardEditorAppearanceSettings>(
106 registerHandler<SetBoardEditorAppearanceSettings, Empty>(
120 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
121 return tl::unexpected( *busy );
123 RunActionResponse response;
125 if(
frame()->GetToolManager()->RunAction( aCtx.
Request.action(),
true ) )
126 response.set_status( RunActionStatus::RAS_OK );
128 response.set_status( RunActionStatus::RAS_INVALID );
137 if( aCtx.
Request.type() != DocumentType::DOCTYPE_PCB )
141 e.set_status( ApiStatusCode::AS_UNHANDLED );
142 return tl::unexpected( e );
145 GetOpenDocumentsResponse response;
146 common::types::DocumentSpecifier doc;
148 wxFileName fn(
frame()->GetCurrentFileName() );
150 doc.set_type( DocumentType::DOCTYPE_PCB );
151 doc.set_board_filename( fn.GetFullName() );
153 doc.mutable_project()->set_name(
frame()->
Prj().GetProjectName().ToStdString() );
154 doc.mutable_project()->set_path(
frame()->
Prj().GetProjectDirectory().ToStdString() );
156 response.mutable_documents()->Add( std::move( doc ) );
164 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
165 return tl::unexpected( *busy );
169 if( !documentValidation )
170 return tl::unexpected( documentValidation.error() );
180 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
181 return tl::unexpected( *busy );
185 if( !documentValidation )
186 return tl::unexpected( documentValidation.error() );
188 wxFileName boardPath(
frame()->
Prj().AbsolutePath( wxString::FromUTF8( aCtx.
Request.path() ) ) );
190 if( !boardPath.IsOk() || !boardPath.IsDirWritable() )
193 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
194 e.set_error_message( fmt::format(
"save path '{}' could not be opened",
195 boardPath.GetFullPath().ToStdString() ) );
196 return tl::unexpected( e );
199 if( boardPath.FileExists()
200 && ( !boardPath.IsFileWritable() || !aCtx.
Request.options().overwrite() ) )
203 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
204 e.set_error_message( fmt::format(
"save path '{}' exists and cannot be overwritten",
205 boardPath.GetFullPath().ToStdString() ) );
206 return tl::unexpected( e );
212 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
213 e.set_error_message( fmt::format(
"save path '{}' must have a kicad_pcb extension",
214 boardPath.GetFullPath().ToStdString() ) );
215 return tl::unexpected( e );
220 if( board->
GetFileName().Matches( boardPath.GetFullPath() ) )
226 bool includeProject =
true;
228 if( aCtx.
Request.has_options() )
229 includeProject = aCtx.
Request.options().include_project();
240 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
241 return tl::unexpected( *busy );
245 if( !documentValidation )
246 return tl::unexpected( documentValidation.error() );
267 return std::make_unique<BOARD_COMMIT>(
frame() );
284 if( aDocument.type() != DocumentType::DOCTYPE_PCB )
287 wxFileName fn(
frame()->GetCurrentFileName() );
288 return 0 == aDocument.board_filename().compare( fn.GetFullName() );
298 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
299 e.set_error_message(
"Tried to create an item in a null container" );
300 return tl::unexpected( e );
306 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
307 e.set_error_message( fmt::format(
"Tried to create a pad in {}, which is not a footprint",
309 return tl::unexpected( e );
314 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
315 e.set_error_message( fmt::format(
"Tried to create a footprint in {}, which is not a board",
317 return tl::unexpected( e );
325 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
326 e.set_error_message( fmt::format(
"Tried to create an item of type {}, which is unhandled",
327 magic_enum::enum_name( aType ) ) );
328 return tl::unexpected( e );
336 const std::string& aClientName,
337 const types::ItemHeader &aHeader,
338 const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems,
339 std::function<
void( ItemStatus, google::protobuf::Any )> aItemHandler )
345 if( !containerResult && containerResult.error().status() == ApiStatusCode::AS_UNHANDLED )
348 e.set_status( ApiStatusCode::AS_UNHANDLED );
349 return tl::unexpected( e );
351 else if( !containerResult )
353 e.CopyFrom( containerResult.error() );
354 return tl::unexpected( e );
360 if( containerResult->has_value() )
362 const KIID& containerId = **containerResult;
363 std::optional<BOARD_ITEM*> optItem =
getItemById( containerId );
371 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
372 e.set_error_message( fmt::format(
373 "The requested container {} is not a valid board item container",
375 return tl::unexpected( e );
380 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
381 e.set_error_message( fmt::format(
382 "The requested container {} does not exist in this document",
384 return tl::unexpected( e );
390 for(
const google::protobuf::Any& anyItem : aItems )
397 status.set_code( ItemStatusCode::ISC_INVALID_TYPE );
398 status.set_error_message( fmt::format(
"Could not decode a valid type from {}",
399 anyItem.type_url() ) );
400 aItemHandler( status, anyItem );
406 board::types::Dimension dimension;
407 anyItem.UnpackTo( &dimension );
409 switch( dimension.dimension_style_case() )
416 case board::types::Dimension::DIMENSION_STYLE_NOT_SET:
break;
423 if( !creationResult )
425 status.set_code( ItemStatusCode::ISC_INVALID_TYPE );
426 status.set_error_message( creationResult.error().error_message() );
427 aItemHandler( status, anyItem );
431 std::unique_ptr<BOARD_ITEM> item( std::move( *creationResult ) );
433 if( !item->Deserialize( anyItem ) )
435 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
436 e.set_error_message( fmt::format(
"could not unpack {} from request",
437 item->GetClass().ToStdString() ) );
438 return tl::unexpected( e );
441 std::optional<BOARD_ITEM*> optItem =
getItemById( item->m_Uuid );
443 if( aCreate && optItem )
445 status.set_code( ItemStatusCode::ISC_EXISTING );
446 status.set_error_message( fmt::format(
"an item with UUID {} already exists",
447 item->m_Uuid.AsStdString() ) );
448 aItemHandler( status, anyItem );
451 else if( !aCreate && !optItem )
453 status.set_code( ItemStatusCode::ISC_NONEXISTENT );
454 status.set_error_message( fmt::format(
"an item with UUID {} does not exist",
455 item->m_Uuid.AsStdString() ) );
456 aItemHandler( status, anyItem );
462 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
463 status.set_error_message(
464 "attempted to add item with no overlapping layers with the board" );
465 aItemHandler( status, anyItem );
469 status.set_code( ItemStatusCode::ISC_OK );
470 google::protobuf::Any newItem;
474 item->Serialize( newItem );
475 commit->
Add( item.release() );
487 commit->
Remove( boardItem );
488 item->Serialize( newItem );
489 commit->
Add( item.release() );
493 commit->
Modify( boardItem );
499 aItemHandler( status, newItem );
505 :
_(
"Modified items via API" ) );
509 return ItemRequestStatus::IRS_OK;
516 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
517 return tl::unexpected( *busy );
523 e.set_status( ApiStatusCode::AS_UNHANDLED );
524 return tl::unexpected( e );
527 GetItemsResponse response;
530 std::vector<BOARD_ITEM*> items;
531 std::set<KICAD_T> typesRequested, typesInserted;
532 bool handledAnything =
false;
534 for(
int typeRaw : aCtx.
Request.types() )
536 auto typeMessage =
static_cast<common::types::KiCadObjectType
>( typeRaw );
537 KICAD_T type = FromProtoEnum<KICAD_T>( typeMessage );
542 typesRequested.emplace( type );
544 if( typesInserted.count( type ) )
552 handledAnything =
true;
553 std::copy( board->
Tracks().begin(), board->
Tracks().end(),
554 std::back_inserter( items ) );
560 handledAnything =
true;
564 std::copy( fp->Pads().begin(), fp->Pads().end(),
565 std::back_inserter( items ) );
574 handledAnything =
true;
577 std::back_inserter( items ) );
587 handledAnything =
true;
588 bool inserted =
false;
592 if( item->Type() == type )
594 items.emplace_back( item );
607 handledAnything =
true;
609 std::copy( board->
Zones().begin(), board->
Zones().end(),
610 std::back_inserter( items ) );
621 if( !handledAnything )
624 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
625 e.set_error_message(
"none of the requested types are valid for a Board object" );
626 return tl::unexpected( e );
631 if( !typesRequested.count( item->Type() ) )
634 google::protobuf::Any itemBuf;
635 item->Serialize( itemBuf );
636 response.mutable_items()->Add( std::move( itemBuf ) );
639 response.set_status( ItemRequestStatus::IRS_OK );
645 const std::string& aClientName )
648 std::vector<BOARD_ITEM*> validatedItems;
650 for( std::pair<const KIID, ItemDeletionStatus> pair : aItemsToDelete )
654 validatedItems.push_back( item );
655 aItemsToDelete[pair.first] = ItemDeletionStatus::IDS_OK;
689 e.set_status( ApiStatusCode::AS_UNHANDLED );
690 return tl::unexpected( e );
695 for(
int typeRaw : aCtx.
Request.types() )
697 auto typeMessage =
static_cast<types::KiCadObjectType
>( typeRaw );
698 KICAD_T type = FromProtoEnum<KICAD_T>( typeMessage );
709 SelectionResponse response;
714 item->Serialize( *response.add_items() );
724 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
725 return tl::unexpected( *busy );
731 e.set_status( ApiStatusCode::AS_UNHANDLED );
732 return tl::unexpected( e );
746 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
747 return tl::unexpected( *busy );
753 e.set_status( ApiStatusCode::AS_UNHANDLED );
754 return tl::unexpected( e );
760 std::vector<EDA_ITEM*> toAdd;
762 for(
const types::KIID&
id : aCtx.
Request.items() )
764 if( std::optional<BOARD_ITEM*> item =
getItemById(
KIID(
id.value() ) ) )
765 toAdd.emplace_back( *item );
771 SelectionResponse response;
774 item->Serialize( *response.add_items() );
783 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
784 return tl::unexpected( *busy );
790 e.set_status( ApiStatusCode::AS_UNHANDLED );
791 return tl::unexpected( e );
797 std::vector<EDA_ITEM*> toRemove;
799 for(
const types::KIID&
id : aCtx.
Request.items() )
801 if( std::optional<BOARD_ITEM*> item =
getItemById(
KIID(
id.value() ) ) )
802 toRemove.emplace_back( *item );
808 SelectionResponse response;
811 item->Serialize( *response.add_items() );
822 if( !documentValidation )
823 return tl::unexpected( documentValidation.error() );
825 BoardStackupResponse response;
826 google::protobuf::Any any;
830 any.UnpackTo( response.mutable_stackup() );
833 for( board::BoardStackupLayer& layer : *response.mutable_stackup()->mutable_layers() )
835 if( layer.type() == board::BoardStackupLayerType::BSLT_DIELECTRIC )
838 PCB_LAYER_ID id = FromProtoEnum<PCB_LAYER_ID>( layer.layer() );
841 layer.set_user_name(
frame()->
GetBoard()->GetLayerName(
id ) );
853 if( !documentValidation )
854 return tl::unexpected( documentValidation.error() );
857 GraphicsDefaultsResponse response;
860 constexpr std::array<kiapi::board::BoardLayerClass, LAYER_CLASS_COUNT> classOrder = {
861 kiapi::board::BLC_SILKSCREEN,
862 kiapi::board::BLC_COPPER,
863 kiapi::board::BLC_EDGES,
864 kiapi::board::BLC_COURTYARD,
865 kiapi::board::BLC_FABRICATION,
866 kiapi::board::BLC_OTHER
871 kiapi::board::BoardLayerGraphicsDefaults* l = response.mutable_defaults()->add_layers();
873 l->set_layer( classOrder[i] );
876 kiapi::common::types::TextAttributes*
text = l->mutable_text();
892 !documentValidation )
894 return tl::unexpected( documentValidation.error() );
914 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
915 e.set_error_message(
"Unexpected origin type" );
916 return tl::unexpected( e );
920 types::Vector2 reply;
928 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
929 return tl::unexpected( *busy );
932 !documentValidation )
934 return tl::unexpected( documentValidation.error() );
951 frame()->CallAfter( [f, origin]()
964 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
965 e.set_error_message(
"Unexpected origin type" );
966 return tl::unexpected( e );
977 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
978 return tl::unexpected( *busy );
984 e.set_status( ApiStatusCode::AS_UNHANDLED );
985 return tl::unexpected( e );
988 GetBoundingBoxResponse response;
989 bool includeText = aCtx.
Request.mode() == BoundingBoxMode::BBM_ITEM_AND_CHILD_TEXT;
991 for(
const types::KIID& idMsg : aCtx.
Request.items() )
993 KIID id( idMsg.value() );
994 std::optional<BOARD_ITEM*> optItem =
getItemById(
id );
1003 bbox =
static_cast<FOOTPRINT*
>( item )->GetBoundingBox( includeText );
1007 response.add_items()->set_value( idMsg.value() );
1008 PackBox2( *response.add_boxes(), bbox );
1019 !documentValidation )
1021 return tl::unexpected( documentValidation.error() );
1024 PadShapeAsPolygonResponse response;
1025 PCB_LAYER_ID layer = FromProtoEnum<PCB_LAYER_ID, board::types::BoardLayer>( aCtx.
Request.layer() );
1027 for(
const types::KIID& padRequest : aCtx.
Request.pads() )
1029 KIID id( padRequest.value() );
1030 std::optional<BOARD_ITEM*> optPad =
getItemById(
id );
1032 if( !optPad || ( *optPad )->Type() !=
PCB_PAD_T )
1035 response.add_pads()->set_value( padRequest.value() );
1037 PAD*
pad =
static_cast<PAD*
>( *optPad );
1039 pad->TransformShapeToPolygon( poly,
pad->Padstack().EffectiveLayerFor( layer ), 0,
1042 types::PolygonWithHoles* polyMsg = response.mutable_polygons()->Add();
1055 if( !documentValidation )
1056 return tl::unexpected( documentValidation.error() );
1061 types::TitleBlockInfo response;
1063 response.set_title( block.
GetTitle().ToUTF8() );
1064 response.set_date( block.
GetDate().ToUTF8() );
1065 response.set_revision( block.
GetRevision().ToUTF8() );
1066 response.set_company( block.
GetCompany().ToUTF8() );
1067 response.set_comment1( block.
GetComment( 0 ).ToUTF8() );
1068 response.set_comment2( block.
GetComment( 1 ).ToUTF8() );
1069 response.set_comment3( block.
GetComment( 2 ).ToUTF8() );
1070 response.set_comment4( block.
GetComment( 3 ).ToUTF8() );
1071 response.set_comment5( block.
GetComment( 4 ).ToUTF8() );
1072 response.set_comment6( block.
GetComment( 5 ).ToUTF8() );
1073 response.set_comment7( block.
GetComment( 6 ).ToUTF8() );
1074 response.set_comment8( block.
GetComment( 7 ).ToUTF8() );
1075 response.set_comment9( block.
GetComment( 8 ).ToUTF8() );
1086 if( !documentValidation )
1087 return tl::unexpected( documentValidation.error() );
1089 ExpandTextVariablesResponse reply;
1092 std::function<bool( wxString* )> textResolver =
1093 [&]( wxString* token ) ->
bool
1099 for(
const std::string& textMsg : aCtx.
Request.text() )
1102 reply.add_text(
text.ToUTF8() );
1112 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1113 return tl::unexpected( *busy );
1117 if( !documentValidation )
1118 return tl::unexpected( documentValidation.error() );
1121 std::vector<EDA_ITEM*> toSelect;
1123 for(
const kiapi::common::types::KIID&
id : aCtx.
Request.items() )
1125 if( std::optional<BOARD_ITEM*> item =
getItemById(
KIID(
id.value() ) ) )
1126 toSelect.emplace_back(
static_cast<EDA_ITEM*
>( *item ) );
1129 if( toSelect.empty() )
1131 ApiResponseStatus e;
1132 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1133 e.set_error_message( fmt::format(
"None of the given items exist on the board",
1134 aCtx.
Request.board().board_filename() ) );
1135 return tl::unexpected( e );
1155 if( !documentValidation )
1156 return tl::unexpected( documentValidation.error() );
1158 NetsResponse response;
1161 std::set<wxString> netclassFilter;
1163 for(
const std::string& nc : aCtx.
Request.netclass_filter() )
1164 netclassFilter.insert( wxString( nc.c_str(), wxConvUTF8 ) );
1170 if( !netclassFilter.empty() && nc && !netclassFilter.count( nc->
GetName() ) )
1173 board::types::Net* netProto = response.add_nets();
1174 netProto->set_name( net->GetNetname() );
1175 netProto->mutable_code()->set_value( net->GetNetCode() );
1185 NetClassForNetsResponse response;
1189 google::protobuf::Any any;
1191 for(
const board::types::Net& net : aCtx.
Request.net() )
1199 auto [pair, rc] = response.mutable_classes()->insert( { net.name(), {} } );
1200 any.UnpackTo( &pair->second );
1209 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1210 return tl::unexpected( *busy );
1214 if( !documentValidation )
1215 return tl::unexpected( documentValidation.error() );
1217 if( aCtx.
Request.zones().empty() )
1220 frame()->CallAfter( [mgr]()
1228 ApiResponseStatus e;
1229 e.set_status( ApiStatusCode::AS_UNIMPLEMENTED );
1230 return tl::unexpected( e );
1242 if( !documentValidation )
1243 return tl::unexpected( documentValidation.error() );
1245 SavedDocumentResponse response;
1246 response.mutable_document()->CopyFrom( aCtx.
Request.document() );
1250 [&](
const wxString& aData )
1252 response.set_contents( aData.ToUTF8() );
1264 SavedSelectionResponse response;
1272 [&](
const wxString& aData )
1274 response.set_contents( aData.ToUTF8() );
1287 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1288 return tl::unexpected( *busy );
1292 if( !documentValidation )
1293 return tl::unexpected( documentValidation.error() );
1295 CreateItemsResponse response;
1305 if( !documentValidation )
1306 return tl::unexpected( documentValidation.error() );
1308 BoardLayers response;
1311 response.add_layers( ToProtoEnum<PCB_LAYER_ID, board::types::BoardLayer>( layer ) );
1320 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1321 return tl::unexpected( *busy );
1325 if( !documentValidation )
1326 return tl::unexpected( documentValidation.error() );
1331 for(
int layerIdx : aCtx.
Request.layers() )
1334 FromProtoEnum<PCB_LAYER_ID>(
static_cast<board::types::BoardLayer
>( layerIdx ) );
1337 visible.
set( layer );
1353 if( !documentValidation )
1354 return tl::unexpected( documentValidation.error() );
1356 BoardLayerResponse response;
1358 ToProtoEnum<PCB_LAYER_ID, board::types::BoardLayer>(
frame()->GetActiveLayer() ) );
1367 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1368 return tl::unexpected( *busy );
1372 if( !documentValidation )
1373 return tl::unexpected( documentValidation.error() );
1377 if( !
frame()->
GetBoard()->GetEnabledLayers().Contains( layer ) )
1379 ApiResponseStatus err;
1380 err.set_status( ApiStatusCode::AS_BAD_REQUEST );
1381 err.set_error_message( fmt::format(
"Layer {} is not a valid layer for the given board",
1382 magic_enum::enum_name( layer ) ) );
1383 return tl::unexpected( err );
1394 BoardEditorAppearanceSettings reply;
1400 reply.set_inactive_layer_display( ToProtoEnum<HIGH_CONTRAST_MODE, InactiveLayerDisplayMode>(
1402 reply.set_net_color_display(
1403 ToProtoEnum<NET_COLOR_MODE, NetColorDisplayMode>( displayOptions.
m_NetColorMode ) );
1405 reply.set_board_flip(
frame()->GetCanvas()->GetView()->IsMirroredX()
1406 ? BoardFlipMode::BFM_FLIPPED_X
1407 : BoardFlipMode::BFM_NORMAL );
1411 reply.set_ratsnest_display( ToProtoEnum<RATSNEST_MODE, RatsnestDisplayMode>(
1421 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
1422 return tl::unexpected( *busy );
1427 const BoardEditorAppearanceSettings& newSettings = aCtx.
Request.settings();
1430 FromProtoEnum<HIGH_CONTRAST_MODE>( newSettings.inactive_layer_display() );
1432 FromProtoEnum<NET_COLOR_MODE>( newSettings.net_color_display() );
1434 bool flip = newSettings.board_flip() == BoardFlipMode::BFM_FLIPPED_X;
1443 FromProtoEnum<RATSNEST_MODE>( newSettings.ratsnest_display() );
tl::expected< T, ApiResponseStatus > HANDLER_RESULT
std::unique_ptr< EDA_ITEM > CreateItemForType(KICAD_T aType, EDA_ITEM *aContainer)
constexpr int ARC_HIGH_DEF
static TOOL_ACTION selectionClear
Clear the current selection.
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Base class for API handlers related to editor frames.
HANDLER_RESULT< bool > validateDocument(const DocumentSpecifier &aDocument)
HANDLER_RESULT< std::optional< KIID > > validateItemHeaderDocument(const kiapi::common::types::ItemHeader &aHeader)
If the header is valid, returns the item container.
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< commands::SelectionResponse > handleAddToSelection(const HANDLER_CONTEXT< commands::AddToSelection > &aCtx)
HANDLER_RESULT< commands::CreateItemsResponse > handleParseAndCreateItemsFromString(const HANDLER_CONTEXT< commands::ParseAndCreateItemsFromString > &aCtx)
HANDLER_RESULT< Empty > handleInteractiveMoveItems(const HANDLER_CONTEXT< InteractiveMoveItems > &aCtx)
bool validateDocumentInternal(const DocumentSpecifier &aDocument) const override
HANDLER_RESULT< Empty > handleSetActiveLayer(const HANDLER_CONTEXT< SetActiveLayer > &aCtx)
API_HANDLER_PCB(PCB_EDIT_FRAME *aFrame)
static HANDLER_RESULT< std::unique_ptr< BOARD_ITEM > > createItemForType(KICAD_T aType, BOARD_ITEM_CONTAINER *aContainer)
std::optional< BOARD_ITEM * > getItemById(const KIID &aId) const
HANDLER_RESULT< types::Vector2 > handleGetBoardOrigin(const HANDLER_CONTEXT< GetBoardOrigin > &aCtx)
std::unique_ptr< COMMIT > createCommit() override
Override this to create an appropriate COMMIT subclass for the frame in question.
HANDLER_RESULT< BoardStackupResponse > handleGetStackup(const HANDLER_CONTEXT< GetBoardStackup > &aCtx)
HANDLER_RESULT< types::TitleBlockInfo > handleGetTitleBlockInfo(const HANDLER_CONTEXT< commands::GetTitleBlockInfo > &aCtx)
HANDLER_RESULT< commands::SelectionResponse > handleGetSelection(const HANDLER_CONTEXT< commands::GetSelection > &aCtx)
HANDLER_RESULT< NetClassForNetsResponse > handleGetNetClassForNets(const HANDLER_CONTEXT< GetNetClassForNets > &aCtx)
std::optional< EDA_ITEM * > getItemFromDocument(const DocumentSpecifier &aDocument, const KIID &aId) override
HANDLER_RESULT< commands::ExpandTextVariablesResponse > handleExpandTextVariables(const HANDLER_CONTEXT< commands::ExpandTextVariables > &aCtx)
HANDLER_RESULT< Empty > handleSetVisibleLayers(const HANDLER_CONTEXT< SetVisibleLayers > &aCtx)
HANDLER_RESULT< Empty > handleSaveCopyOfDocument(const HANDLER_CONTEXT< commands::SaveCopyOfDocument > &aCtx)
HANDLER_RESULT< GraphicsDefaultsResponse > handleGetGraphicsDefaults(const HANDLER_CONTEXT< GetGraphicsDefaults > &aCtx)
HANDLER_RESULT< Empty > handleSetBoardOrigin(const HANDLER_CONTEXT< SetBoardOrigin > &aCtx)
HANDLER_RESULT< Empty > handleClearSelection(const HANDLER_CONTEXT< commands::ClearSelection > &aCtx)
HANDLER_RESULT< commands::RunActionResponse > handleRunAction(const HANDLER_CONTEXT< commands::RunAction > &aCtx)
HANDLER_RESULT< BoardLayers > handleGetVisibleLayers(const HANDLER_CONTEXT< GetVisibleLayers > &aCtx)
HANDLER_RESULT< commands::SelectionResponse > handleRemoveFromSelection(const HANDLER_CONTEXT< commands::RemoveFromSelection > &aCtx)
HANDLER_RESULT< commands::GetOpenDocumentsResponse > handleGetOpenDocuments(const HANDLER_CONTEXT< commands::GetOpenDocuments > &aCtx)
HANDLER_RESULT< BoardEditorAppearanceSettings > handleGetBoardEditorAppearanceSettings(const HANDLER_CONTEXT< GetBoardEditorAppearanceSettings > &aCtx)
HANDLER_RESULT< NetsResponse > handleGetNets(const HANDLER_CONTEXT< GetNets > &aCtx)
HANDLER_RESULT< commands::SavedDocumentResponse > handleSaveDocumentToString(const HANDLER_CONTEXT< commands::SaveDocumentToString > &aCtx)
HANDLER_RESULT< commands::GetBoundingBoxResponse > handleGetBoundingBox(const HANDLER_CONTEXT< commands::GetBoundingBox > &aCtx)
HANDLER_RESULT< Empty > handleSaveDocument(const HANDLER_CONTEXT< commands::SaveDocument > &aCtx)
void deleteItemsInternal(std::map< KIID, ItemDeletionStatus > &aItemsToDelete, const std::string &aClientName) override
HANDLER_RESULT< commands::GetItemsResponse > handleGetItems(const HANDLER_CONTEXT< commands::GetItems > &aCtx)
HANDLER_RESULT< PadShapeAsPolygonResponse > handleGetPadShapeAsPolygon(const HANDLER_CONTEXT< GetPadShapeAsPolygon > &aCtx)
PCB_EDIT_FRAME * frame() const
HANDLER_RESULT< Empty > handleSetBoardEditorAppearanceSettings(const HANDLER_CONTEXT< SetBoardEditorAppearanceSettings > &aCtx)
HANDLER_RESULT< Empty > handleRefillZones(const HANDLER_CONTEXT< RefillZones > &aCtx)
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< BoardLayerResponse > handleGetActiveLayer(const HANDLER_CONTEXT< GetActiveLayer > &aCtx)
HANDLER_RESULT< Empty > handleRevertDocument(const HANDLER_CONTEXT< commands::RevertDocument > &aCtx)
HANDLER_RESULT< commands::SavedSelectionResponse > handleSaveSelectionToString(const HANDLER_CONTEXT< commands::SaveSelectionToString > &aCtx)
void pushCurrentCommit(const std::string &aClientName, const wxString &aMessage) override
void SetContentModified(bool aModified=true)
BASE_SET & set(size_t pos)
Container for design settings for a BOARD object.
void SetGridOrigin(const VECTOR2I &aOrigin)
bool m_TextUpright[LAYER_CLASS_COUNT]
const VECTOR2I & GetGridOrigin() const
const VECTOR2I & GetAuxOrigin() const
int m_TextThickness[LAYER_CLASS_COUNT]
int m_LineThickness[LAYER_CLASS_COUNT]
VECTOR2I m_TextSize[LAYER_CLASS_COUNT]
bool m_TextItalic[LAYER_CLASS_COUNT]
Abstract interface for BOARD_ITEMs capable of storing other items inside.
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)
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Information pertinent to a Pcbnew printed circuit board.
BOARD_STACKUP GetStackupOrDefault() const
const NETINFO_LIST & GetNetInfo() const
void SetVisibleLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
BOARD_ITEM * GetItem(const KIID &aID) const
const ZONES & Zones() const
bool ResolveTextVar(wxString *token, int aDepth) const
TITLE_BLOCK & GetTitleBlock()
const FOOTPRINTS & Footprints() const
const TRACKS & Tracks() const
const wxString & GetFileName() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
const DRAWINGS & Drawings() const
void SaveSelection(const PCB_SELECTION &selected, bool isFootprintEditor)
void SetWriter(std::function< void(const wxString &)> aWriter)
void SaveBoard(const wxString &aFileName, BOARD *aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aBoard to a storage file in a format that this PCB_IO implementation knows about or it can be u...
void SetBoard(BOARD *aBoard)
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)
Modify a given item in the model.
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
static DELETED_BOARD_ITEM * GetInstance()
void ReleaseFile()
Release the current file marked in use.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A base class for most all the KiCad significant classes used in schematics and boards.
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
KICAD_T Type() const
Returns the type of object.
virtual wxString GetFriendlyName() const
void SetMirror(bool aMirrorX, bool aMirrorY)
Control the mirroring of the VIEW.
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
bool IsMirroredX() const
Return true if view is flipped across the X axis.
void RecacheAllItems()
Rebuild GAL display lists.
bool IsMirroredY() const
Return true if view is flipped across the Y axis.
std::string AsStdString() const
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
LSET is a set of PCB_LAYER_IDs.
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
A collection of nets and the parameters used to route or test these nets.
const wxString GetName() const
Gets the name of this (maybe aggregate) netclass in a format for internal usage or for export to exte...
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
DISPLAY_OPTIONS m_Display
static TOOL_ACTION zoneFillAll
static TOOL_ACTION move
move or drag an item
static TOOL_ACTION drillSetOrigin
APPEARANCE_CONTROLS * GetAppearancePanel()
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.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aRefresh=true)
Update the current display options.
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 #VIEW instance used in the panel.
void SyncLayersVisibility(const BOARD *aBoard)
Update "visibility" property of each layer of a given BOARD.
The main frame for Pcbnew.
void SetActiveLayer(PCB_LAYER_ID aLayer) override
Change the currently active layer to aLayer and also update the APPEARANCE_CONTROLS.
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Load a KiCad board (.kicad_pcb) from aFileName.
bool SavePcbCopy(const wxString &aFileName, bool aCreateProject=false, bool aHeadless=false)
Write the board data structures to aFileName.
bool Files_io_from_id(int aId)
Read and write board files according to aId.
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
void SetReferencePoint(const VECTOR2I &aP)
virtual void Serialize(google::protobuf::Any &aContainer) const
Serializes this object to the given Any message.
Represent a set of closed polygons.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
Hold the information shown in the lower right corner of a plot, printout, or editing view.
const wxString & GetCompany() const
const wxString & GetRevision() const
const wxString & GetDate() const
const wxString & GetComment(int aIdx) const
const wxString & GetTitle() const
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
static const std::string KiCadPcbFileExtension
#define KICTL_REVERT
reverting to a previously-saved (KiCad) file.
PCB_LAYER_ID
A quick note on layer IDs:
KICOMMON_API void PackBox2(types::Box2 &aOutput, const BOX2I &aInput)
KICOMMON_API std::optional< KICAD_T > TypeNameFromAny(const google::protobuf::Any &aMessage)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput)
KICOMMON_API void PackPolyLine(types::PolyLine &aOutput, const SHAPE_LINE_CHAIN &aSlc)
Class to handle a set of BOARD_ITEMs.
RequestMessageType Request
RATSNEST_MODE m_RatsnestMode
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
@ 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_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
@ 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_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension