KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_handler_pcb.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2023 Jon Evans <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <magic_enum.hpp>
22#include <properties/property.h>
23
24#include <common.h>
25#include <api/api_handler_pcb.h>
26#include <api/api_pcb_utils.h>
27#include <api/api_enums.h>
28#include <api/api_utils.h>
29#include <board_commit.h>
31#include <footprint.h>
32#include <kicad_clipboard.h>
33#include <netinfo.h>
34#include <pad.h>
35#include <pcb_edit_frame.h>
36#include <pcb_group.h>
37#include <pcb_reference_image.h>
38#include <pcb_shape.h>
39#include <pcb_text.h>
40#include <pcb_textbox.h>
41#include <pcb_track.h>
42#include <pcbnew_id.h>
43#include <pcb_marker.h>
44#include <drc/drc_item.h>
45#include <layer_ids.h>
46#include <project.h>
47#include <tool/tool_manager.h>
48#include <tools/pcb_actions.h>
50#include <zone.h>
51
52#include <api/common/types/base_types.pb.h>
55
56using namespace kiapi::common::commands;
57using types::CommandStatus;
58using types::DocumentType;
59using types::ItemRequestStatus;
60
61
63 API_HANDLER_EDITOR( aFrame )
64{
71
74
80
100
106
123}
124
125
127{
128 return static_cast<PCB_EDIT_FRAME*>( m_frame );
129}
130
131
133 const HANDLER_CONTEXT<RunAction>& aCtx )
134{
135 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
136 return tl::unexpected( *busy );
137
138 RunActionResponse response;
139
140 if( frame()->GetToolManager()->RunAction( aCtx.Request.action(), true ) )
141 response.set_status( RunActionStatus::RAS_OK );
142 else
143 response.set_status( RunActionStatus::RAS_INVALID );
144
145 return response;
146}
147
148
151{
152 if( aCtx.Request.type() != DocumentType::DOCTYPE_PCB )
153 {
154 ApiResponseStatus e;
155 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
156 e.set_status( ApiStatusCode::AS_UNHANDLED );
157 return tl::unexpected( e );
158 }
159
160 GetOpenDocumentsResponse response;
161 common::types::DocumentSpecifier doc;
162
163 wxFileName fn( frame()->GetCurrentFileName() );
164
165 doc.set_type( DocumentType::DOCTYPE_PCB );
166 doc.set_board_filename( fn.GetFullName() );
167
168 doc.mutable_project()->set_name( frame()->Prj().GetProjectName().ToStdString() );
169 doc.mutable_project()->set_path( frame()->Prj().GetProjectDirectory().ToStdString() );
170
171 response.mutable_documents()->Add( std::move( doc ) );
172 return response;
173}
174
175
178{
179 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
180 return tl::unexpected( *busy );
181
182 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
183
184 if( !documentValidation )
185 return tl::unexpected( documentValidation.error() );
186
187 frame()->SaveBoard();
188 return Empty();
189}
190
191
194{
195 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
196 return tl::unexpected( *busy );
197
198 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
199
200 if( !documentValidation )
201 return tl::unexpected( documentValidation.error() );
202
203 wxFileName boardPath( frame()->Prj().AbsolutePath( wxString::FromUTF8( aCtx.Request.path() ) ) );
204
205 if( !boardPath.IsOk() || !boardPath.IsDirWritable() )
206 {
207 ApiResponseStatus e;
208 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
209 e.set_error_message( fmt::format( "save path '{}' could not be opened",
210 boardPath.GetFullPath().ToStdString() ) );
211 return tl::unexpected( e );
212 }
213
214 if( boardPath.FileExists()
215 && ( !boardPath.IsFileWritable() || !aCtx.Request.options().overwrite() ) )
216 {
217 ApiResponseStatus e;
218 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
219 e.set_error_message( fmt::format( "save path '{}' exists and cannot be overwritten",
220 boardPath.GetFullPath().ToStdString() ) );
221 return tl::unexpected( e );
222 }
223
224 if( boardPath.GetExt() != FILEEXT::KiCadPcbFileExtension )
225 {
226 ApiResponseStatus e;
227 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
228 e.set_error_message( fmt::format( "save path '{}' must have a kicad_pcb extension",
229 boardPath.GetFullPath().ToStdString() ) );
230 return tl::unexpected( e );
231 }
232
233 BOARD* board = frame()->GetBoard();
234
235 if( board->GetFileName().Matches( boardPath.GetFullPath() ) )
236 {
237 frame()->SaveBoard();
238 return Empty();
239 }
240
241 bool includeProject = true;
242
243 if( aCtx.Request.has_options() )
244 includeProject = aCtx.Request.options().include_project();
245
246 frame()->SavePcbCopy( boardPath.GetFullPath(), includeProject, /* aHeadless = */ true );
247
248 return Empty();
249}
250
251
254{
255 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
256 return tl::unexpected( *busy );
257
258 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
259
260 if( !documentValidation )
261 return tl::unexpected( documentValidation.error() );
262
263 wxFileName fn = frame()->Prj().AbsolutePath( frame()->GetBoard()->GetFileName() );
264
265 frame()->GetScreen()->SetContentModified( false );
266 frame()->ReleaseFile();
267 frame()->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ), KICTL_REVERT );
268
269 return Empty();
270}
271
272
273void API_HANDLER_PCB::pushCurrentCommit( const std::string& aClientName, const wxString& aMessage )
274{
275 API_HANDLER_EDITOR::pushCurrentCommit( aClientName, aMessage );
276 frame()->Refresh();
277}
278
279
280std::unique_ptr<COMMIT> API_HANDLER_PCB::createCommit()
281{
282 return std::make_unique<BOARD_COMMIT>( frame() );
283}
284
285
286std::optional<BOARD_ITEM*> API_HANDLER_PCB::getItemById( const KIID& aId ) const
287{
288 BOARD_ITEM* item = frame()->GetBoard()->ResolveItem( aId, true );
289
290 if( !item )
291 return std::nullopt;
292
293 return item;
294}
295
296
297bool API_HANDLER_PCB::validateDocumentInternal( const DocumentSpecifier& aDocument ) const
298{
299 if( aDocument.type() != DocumentType::DOCTYPE_PCB )
300 return false;
301
302 wxFileName fn( frame()->GetCurrentFileName() );
303 return 0 == aDocument.board_filename().compare( fn.GetFullName() );
304}
305
306
308 BOARD_ITEM_CONTAINER* aContainer )
309{
310 if( !aContainer )
311 {
312 ApiResponseStatus e;
313 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
314 e.set_error_message( "Tried to create an item in a null container" );
315 return tl::unexpected( e );
316 }
317
318 if( aType == PCB_PAD_T && !dynamic_cast<FOOTPRINT*>( aContainer ) )
319 {
320 ApiResponseStatus e;
321 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
322 e.set_error_message( fmt::format( "Tried to create a pad in {}, which is not a footprint",
323 aContainer->GetFriendlyName().ToStdString() ) );
324 return tl::unexpected( e );
325 }
326 else if( aType == PCB_FOOTPRINT_T && !dynamic_cast<BOARD*>( aContainer ) )
327 {
328 ApiResponseStatus e;
329 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
330 e.set_error_message( fmt::format( "Tried to create a footprint in {}, which is not a board",
331 aContainer->GetFriendlyName().ToStdString() ) );
332 return tl::unexpected( e );
333 }
334
335 std::unique_ptr<BOARD_ITEM> created = CreateItemForType( aType, aContainer );
336
337 if( !created )
338 {
339 ApiResponseStatus e;
340 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
341 e.set_error_message( fmt::format( "Tried to create an item of type {}, which is unhandled",
342 magic_enum::enum_name( aType ) ) );
343 return tl::unexpected( e );
344 }
345
346 return created;
347}
348
349
351 const std::string& aClientName,
352 const types::ItemHeader &aHeader,
353 const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems,
354 std::function<void( ItemStatus, google::protobuf::Any )> aItemHandler )
355{
356 ApiResponseStatus e;
357
358 auto containerResult = validateItemHeaderDocument( aHeader );
359
360 if( !containerResult && containerResult.error().status() == ApiStatusCode::AS_UNHANDLED )
361 {
362 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
363 e.set_status( ApiStatusCode::AS_UNHANDLED );
364 return tl::unexpected( e );
365 }
366 else if( !containerResult )
367 {
368 e.CopyFrom( containerResult.error() );
369 return tl::unexpected( e );
370 }
371
372 BOARD* board = frame()->GetBoard();
373 BOARD_ITEM_CONTAINER* container = board;
374
375 if( containerResult->has_value() )
376 {
377 const KIID& containerId = **containerResult;
378 std::optional<BOARD_ITEM*> optItem = getItemById( containerId );
379
380 if( optItem )
381 {
382 container = dynamic_cast<BOARD_ITEM_CONTAINER*>( *optItem );
383
384 if( !container )
385 {
386 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
387 e.set_error_message( fmt::format(
388 "The requested container {} is not a valid board item container",
389 containerId.AsStdString() ) );
390 return tl::unexpected( e );
391 }
392 }
393 else
394 {
395 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
396 e.set_error_message( fmt::format(
397 "The requested container {} does not exist in this document",
398 containerId.AsStdString() ) );
399 return tl::unexpected( e );
400 }
401 }
402
403 BOARD_COMMIT* commit = static_cast<BOARD_COMMIT*>( getCurrentCommit( aClientName ) );
404
405 for( const google::protobuf::Any& anyItem : aItems )
406 {
407 ItemStatus status;
408 std::optional<KICAD_T> type = TypeNameFromAny( anyItem );
409
410 if( !type )
411 {
412 status.set_code( ItemStatusCode::ISC_INVALID_TYPE );
413 status.set_error_message( fmt::format( "Could not decode a valid type from {}",
414 anyItem.type_url() ) );
415 aItemHandler( status, anyItem );
416 continue;
417 }
418
419 if( type == PCB_DIMENSION_T )
420 {
421 board::types::Dimension dimension;
422 anyItem.UnpackTo( &dimension );
423
424 switch( dimension.dimension_style_case() )
425 {
426 case board::types::Dimension::kAligned: type = PCB_DIM_ALIGNED_T; break;
427 case board::types::Dimension::kOrthogonal: type = PCB_DIM_ORTHOGONAL_T; break;
428 case board::types::Dimension::kRadial: type = PCB_DIM_RADIAL_T; break;
429 case board::types::Dimension::kLeader: type = PCB_DIM_LEADER_T; break;
430 case board::types::Dimension::kCenter: type = PCB_DIM_CENTER_T; break;
431 case board::types::Dimension::DIMENSION_STYLE_NOT_SET: break;
432 }
433 }
434
436 createItemForType( *type, container );
437
438 if( !creationResult )
439 {
440 status.set_code( ItemStatusCode::ISC_INVALID_TYPE );
441 status.set_error_message( creationResult.error().error_message() );
442 aItemHandler( status, anyItem );
443 continue;
444 }
445
446 std::unique_ptr<BOARD_ITEM> item( std::move( *creationResult ) );
447
448 if( !item->Deserialize( anyItem ) )
449 {
450 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
451 e.set_error_message( fmt::format( "could not unpack {} from request",
452 item->GetClass().ToStdString() ) );
453 return tl::unexpected( e );
454 }
455
456 std::optional<BOARD_ITEM*> optItem = getItemById( item->m_Uuid );
457
458 if( aCreate && optItem )
459 {
460 status.set_code( ItemStatusCode::ISC_EXISTING );
461 status.set_error_message( fmt::format( "an item with UUID {} already exists",
462 item->m_Uuid.AsStdString() ) );
463 aItemHandler( status, anyItem );
464 continue;
465 }
466 else if( !aCreate && !optItem )
467 {
468 status.set_code( ItemStatusCode::ISC_NONEXISTENT );
469 status.set_error_message( fmt::format( "an item with UUID {} does not exist",
470 item->m_Uuid.AsStdString() ) );
471 aItemHandler( status, anyItem );
472 continue;
473 }
474
475 if( aCreate && !( board->GetEnabledLayers() & item->GetLayerSet() ).any() )
476 {
477 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
478 status.set_error_message(
479 "attempted to add item with no overlapping layers with the board" );
480 aItemHandler( status, anyItem );
481 continue;
482 }
483
484 status.set_code( ItemStatusCode::ISC_OK );
485 google::protobuf::Any newItem;
486
487 if( aCreate )
488 {
489 if( item->Type() == PCB_FOOTPRINT_T )
490 {
491 // Ensure children have unique identifiers; in case the API client created this new
492 // footprint by cloning an existing one and only changing the parent UUID.
493 item->RunOnChildren(
494 []( BOARD_ITEM* aChild )
495 {
496 const_cast<KIID&>( aChild->m_Uuid ) = KIID();
497 },
498 RECURSE );
499 }
500
501 item->Serialize( newItem );
502 commit->Add( item.release() );
503 }
504 else
505 {
506 BOARD_ITEM* boardItem = *optItem;
507
508 // Footprints can't be modified by CopyFrom at the moment because the commit system
509 // doesn't currently know what to do with a footprint that has had its children
510 // replaced with other children; which results in things like the view not having its
511 // cached geometry for footprint children updated when you move a footprint around.
512 // And also, groups are special because they can contain any item type, so we
513 // can't use CopyFrom on them either.
514 if( boardItem->Type() == PCB_FOOTPRINT_T || boardItem->Type() == PCB_GROUP_T )
515 {
516 // Save group membership before removal, since Remove() severs the relationship
517 PCB_GROUP* parentGroup = dynamic_cast<PCB_GROUP*>( boardItem->GetParentGroup() );
518
519 commit->Remove( boardItem );
520 item->Serialize( newItem );
521
522 BOARD_ITEM* newBoardItem = item.release();
523 commit->Add( newBoardItem );
524
525 // Restore group membership for the newly added item
526 if( parentGroup )
527 parentGroup->AddItem( newBoardItem );
528 }
529 else
530 {
531 commit->Modify( boardItem );
532 boardItem->CopyFrom( item.get() );
533 boardItem->Serialize( newItem );
534 }
535 }
536
537 aItemHandler( status, newItem );
538 }
539
540 if( !m_activeClients.count( aClientName ) )
541 {
542 pushCurrentCommit( aClientName, aCreate ? _( "Created items via API" )
543 : _( "Modified items via API" ) );
544 }
545
546
547 return ItemRequestStatus::IRS_OK;
548}
549
550
552{
553 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
554 return tl::unexpected( *busy );
555
556 if( !validateItemHeaderDocument( aCtx.Request.header() ) )
557 {
558 ApiResponseStatus e;
559 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
560 e.set_status( ApiStatusCode::AS_UNHANDLED );
561 return tl::unexpected( e );
562 }
563
564 GetItemsResponse response;
565
566 BOARD* board = frame()->GetBoard();
567 std::vector<BOARD_ITEM*> items;
568 std::set<KICAD_T> typesRequested, typesInserted;
569 bool handledAnything = false;
570
571 for( int typeRaw : aCtx.Request.types() )
572 {
573 auto typeMessage = static_cast<common::types::KiCadObjectType>( typeRaw );
574 KICAD_T type = FromProtoEnum<KICAD_T>( typeMessage );
575
576 if( type == TYPE_NOT_INIT )
577 continue;
578
579 typesRequested.emplace( type );
580
581 if( typesInserted.count( type ) )
582 continue;
583
584 switch( type )
585 {
586 case PCB_TRACE_T:
587 case PCB_ARC_T:
588 case PCB_VIA_T:
589 handledAnything = true;
590 std::copy( board->Tracks().begin(), board->Tracks().end(),
591 std::back_inserter( items ) );
592 typesInserted.insert( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } );
593 break;
594
595 case PCB_PAD_T:
596 {
597 handledAnything = true;
598
599 for( FOOTPRINT* fp : board->Footprints() )
600 {
601 std::copy( fp->Pads().begin(), fp->Pads().end(),
602 std::back_inserter( items ) );
603 }
604
605 typesInserted.insert( PCB_PAD_T );
606 break;
607 }
608
609 case PCB_FOOTPRINT_T:
610 {
611 handledAnything = true;
612
613 std::copy( board->Footprints().begin(), board->Footprints().end(),
614 std::back_inserter( items ) );
615
616 typesInserted.insert( PCB_FOOTPRINT_T );
617 break;
618 }
619
620 case PCB_SHAPE_T:
621 case PCB_TEXT_T:
622 case PCB_TEXTBOX_T:
623 case PCB_BARCODE_T:
624 {
625 handledAnything = true;
626 bool inserted = false;
627
628 for( BOARD_ITEM* item : board->Drawings() )
629 {
630 if( item->Type() == type )
631 {
632 items.emplace_back( item );
633 inserted = true;
634 }
635 }
636
637 if( inserted )
638 typesInserted.insert( type );
639
640 break;
641 }
642
643 case PCB_ZONE_T:
644 {
645 handledAnything = true;
646
647 std::copy( board->Zones().begin(), board->Zones().end(),
648 std::back_inserter( items ) );
649
650 typesInserted.insert( PCB_ZONE_T );
651 break;
652 }
653
654 case PCB_GROUP_T:
655 {
656 handledAnything = true;
657
658 std::copy( board->Groups().begin(), board->Groups().end(),
659 std::back_inserter( items ) );
660
661 typesInserted.insert( PCB_GROUP_T );
662 break;
663 }
664 default:
665 break;
666 }
667 }
668
669 if( !handledAnything )
670 {
671 ApiResponseStatus e;
672 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
673 e.set_error_message( "none of the requested types are valid for a Board object" );
674 return tl::unexpected( e );
675 }
676
677 for( const BOARD_ITEM* item : items )
678 {
679 if( !typesRequested.count( item->Type() ) )
680 continue;
681
682 google::protobuf::Any itemBuf;
683 item->Serialize( itemBuf );
684 response.mutable_items()->Add( std::move( itemBuf ) );
685 }
686
687 response.set_status( ItemRequestStatus::IRS_OK );
688 return response;
689}
690
691
694{
695 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
696 return tl::unexpected( *busy );
697
698 if( !validateItemHeaderDocument( aCtx.Request.header() ) )
699 {
700 ApiResponseStatus e;
701 e.set_status( ApiStatusCode::AS_UNHANDLED );
702 return tl::unexpected( e );
703 }
704
705 GetItemsResponse response;
706
707 std::vector<BOARD_ITEM*> items;
708
709 for( const kiapi::common::types::KIID& id : aCtx.Request.items() )
710 {
711 if( std::optional<BOARD_ITEM*> item = getItemById( KIID( id.value() ) ) )
712 items.emplace_back( *item );
713 }
714
715 if( items.empty() )
716 {
717 ApiResponseStatus e;
718 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
719 e.set_error_message( "none of the requested IDs were found or valid" );
720 return tl::unexpected( e );
721 }
722
723 for( const BOARD_ITEM* item : items )
724 {
725 google::protobuf::Any itemBuf;
726 item->Serialize( itemBuf );
727 response.mutable_items()->Add( std::move( itemBuf ) );
728 }
729
730 response.set_status( ItemRequestStatus::IRS_OK );
731 return response;
732}
733
734void API_HANDLER_PCB::deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& aItemsToDelete,
735 const std::string& aClientName )
736{
737 BOARD* board = frame()->GetBoard();
738 std::vector<BOARD_ITEM*> validatedItems;
739
740 for( std::pair<const KIID, ItemDeletionStatus> pair : aItemsToDelete )
741 {
742 if( BOARD_ITEM* item = board->ResolveItem( pair.first, true ) )
743 {
744 validatedItems.push_back( item );
745 aItemsToDelete[pair.first] = ItemDeletionStatus::IDS_OK;
746 }
747
748 // Note: we don't currently support locking items from API modification, but here is where
749 // to add it in the future (and return IDS_IMMUTABLE)
750 }
751
752 COMMIT* commit = getCurrentCommit( aClientName );
753
754 for( BOARD_ITEM* item : validatedItems )
755 commit->Remove( item );
756
757 if( !m_activeClients.count( aClientName ) )
758 pushCurrentCommit( aClientName, _( "Deleted items via API" ) );
759}
760
761
762std::optional<EDA_ITEM*> API_HANDLER_PCB::getItemFromDocument( const DocumentSpecifier& aDocument,
763 const KIID& aId )
764{
765 if( !validateDocument( aDocument ) )
766 return std::nullopt;
767
768 return getItemById( aId );
769}
770
771
774{
775 if( !validateItemHeaderDocument( aCtx.Request.header() ) )
776 {
777 ApiResponseStatus e;
778 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
779 e.set_status( ApiStatusCode::AS_UNHANDLED );
780 return tl::unexpected( e );
781 }
782
783 std::set<KICAD_T> filter;
784
785 for( int typeRaw : aCtx.Request.types() )
786 {
787 auto typeMessage = static_cast<types::KiCadObjectType>( typeRaw );
788 KICAD_T type = FromProtoEnum<KICAD_T>( typeMessage );
789
790 if( type == TYPE_NOT_INIT )
791 continue;
792
793 filter.insert( type );
794 }
795
797 PCB_SELECTION_TOOL* selectionTool = mgr->GetTool<PCB_SELECTION_TOOL>();
798
799 SelectionResponse response;
800
801 for( EDA_ITEM* item : selectionTool->GetSelection() )
802 {
803 if( filter.empty() || filter.contains( item->Type() ) )
804 item->Serialize( *response.add_items() );
805 }
806
807 return response;
808}
809
810
813{
814 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
815 return tl::unexpected( *busy );
816
817 if( !validateItemHeaderDocument( aCtx.Request.header() ) )
818 {
819 ApiResponseStatus e;
820 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
821 e.set_status( ApiStatusCode::AS_UNHANDLED );
822 return tl::unexpected( e );
823 }
824
827 frame()->Refresh();
828
829 return Empty();
830}
831
832
835{
836 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
837 return tl::unexpected( *busy );
838
839 if( !validateItemHeaderDocument( aCtx.Request.header() ) )
840 {
841 ApiResponseStatus e;
842 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
843 e.set_status( ApiStatusCode::AS_UNHANDLED );
844 return tl::unexpected( e );
845 }
846
848 PCB_SELECTION_TOOL* selectionTool = mgr->GetTool<PCB_SELECTION_TOOL>();
849
850 std::vector<EDA_ITEM*> toAdd;
851
852 for( const types::KIID& id : aCtx.Request.items() )
853 {
854 if( std::optional<BOARD_ITEM*> item = getItemById( KIID( id.value() ) ) )
855 toAdd.emplace_back( *item );
856 }
857
858 selectionTool->AddItemsToSel( &toAdd );
859 frame()->Refresh();
860
861 SelectionResponse response;
862
863 for( EDA_ITEM* item : selectionTool->GetSelection() )
864 item->Serialize( *response.add_items() );
865
866 return response;
867}
868
869
872{
873 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
874 return tl::unexpected( *busy );
875
876 if( !validateItemHeaderDocument( aCtx.Request.header() ) )
877 {
878 ApiResponseStatus e;
879 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
880 e.set_status( ApiStatusCode::AS_UNHANDLED );
881 return tl::unexpected( e );
882 }
883
885 PCB_SELECTION_TOOL* selectionTool = mgr->GetTool<PCB_SELECTION_TOOL>();
886
887 std::vector<EDA_ITEM*> toRemove;
888
889 for( const types::KIID& id : aCtx.Request.items() )
890 {
891 if( std::optional<BOARD_ITEM*> item = getItemById( KIID( id.value() ) ) )
892 toRemove.emplace_back( *item );
893 }
894
895 selectionTool->RemoveItemsFromSel( &toRemove );
896 frame()->Refresh();
897
898 SelectionResponse response;
899
900 for( EDA_ITEM* item : selectionTool->GetSelection() )
901 item->Serialize( *response.add_items() );
902
903 return response;
904}
905
906
909{
910 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
911
912 if( !documentValidation )
913 return tl::unexpected( documentValidation.error() );
914
915 BoardStackupResponse response;
916 google::protobuf::Any any;
917
919
920 any.UnpackTo( response.mutable_stackup() );
921
922 // User-settable layer names are not stored in BOARD_STACKUP at the moment
923 for( board::BoardStackupLayer& layer : *response.mutable_stackup()->mutable_layers() )
924 {
925 if( layer.type() == board::BoardStackupLayerType::BSLT_DIELECTRIC )
926 continue;
927
928 PCB_LAYER_ID id = FromProtoEnum<PCB_LAYER_ID>( layer.layer() );
929 wxCHECK2( id != UNDEFINED_LAYER, continue );
930
931 layer.set_user_name( frame()->GetBoard()->GetLayerName( id ) );
932 }
933
934 return response;
935}
936
937
940{
941 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
942
943 if( !documentValidation )
944 return tl::unexpected( documentValidation.error() );
945
946 BoardEnabledLayersResponse response;
947
948 BOARD* board = frame()->GetBoard();
949 int copperLayerCount = board->GetCopperLayerCount();
950
951 response.set_copper_layer_count( copperLayerCount );
952
953 LSET enabled = board->GetEnabledLayers();
954
955 // The Rescue layer is an internal detail and should be hidden from the API
956 enabled.reset( Rescue );
957
958 // Just in case this is out of sync; the API should always return the expected copper layers
959 enabled |= LSET::AllCuMask( copperLayerCount );
960
961 board::PackLayerSet( *response.mutable_layers(), enabled );
962
963 return response;
964}
965
966
969{
970 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
971
972 if( !documentValidation )
973 return tl::unexpected( documentValidation.error() );
974
975 if( aCtx.Request.copper_layer_count() % 2 != 0 )
976 {
977 ApiResponseStatus e;
978 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
979 e.set_error_message( "copper_layer_count must be an even number" );
980 return tl::unexpected( e );
981 }
982
983 if( aCtx.Request.copper_layer_count() > MAX_CU_LAYERS )
984 {
985 ApiResponseStatus e;
986 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
987 e.set_error_message( fmt::format( "copper_layer_count must be below %d", MAX_CU_LAYERS ) );
988 return tl::unexpected( e );
989 }
990
991 int copperLayerCount = static_cast<int>( aCtx.Request.copper_layer_count() );
992 LSET enabled = board::UnpackLayerSet( aCtx.Request.layers() );
993
994 // Sanitize the input
995 enabled |= LSET( { Edge_Cuts, Margin, F_CrtYd, B_CrtYd } );
996 enabled &= ~LSET::AllCuMask();
997 enabled |= LSET::AllCuMask( copperLayerCount );
998
999 BOARD* board = frame()->GetBoard();
1000
1001 LSET previousEnabled = board->GetEnabledLayers();
1002 LSET changedLayers = enabled ^ previousEnabled;
1003
1004 board->SetEnabledLayers( enabled );
1005 board->SetVisibleLayers( board->GetVisibleLayers() | changedLayers );
1006
1007 LSEQ removedLayers;
1008
1009 for( PCB_LAYER_ID layer_id : previousEnabled )
1010 {
1011 if( !enabled[layer_id] && board->HasItemsOnLayer( layer_id ) )
1012 removedLayers.push_back( layer_id );
1013 }
1014
1015 bool modified = false;
1016
1017 if( !removedLayers.empty() )
1018 {
1019 m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear );
1020
1021 for( PCB_LAYER_ID layer_id : removedLayers )
1022 modified |= board->RemoveAllItemsOnLayer( layer_id );
1023 }
1024
1025 if( enabled != previousEnabled )
1027
1028 if( modified )
1029 frame()->OnModify();
1030
1031 BoardEnabledLayersResponse response;
1032
1033 response.set_copper_layer_count( copperLayerCount );
1034 board::PackLayerSet( *response.mutable_layers(), enabled );
1035
1036 return response;
1037}
1038
1039
1042{
1043 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1044
1045 if( !documentValidation )
1046 return tl::unexpected( documentValidation.error() );
1047
1049 GraphicsDefaultsResponse response;
1050
1051 // TODO: This should change to be an enum class
1052 constexpr std::array<kiapi::board::BoardLayerClass, LAYER_CLASS_COUNT> classOrder = {
1053 kiapi::board::BLC_SILKSCREEN,
1054 kiapi::board::BLC_COPPER,
1055 kiapi::board::BLC_EDGES,
1056 kiapi::board::BLC_COURTYARD,
1057 kiapi::board::BLC_FABRICATION,
1058 kiapi::board::BLC_OTHER
1059 };
1060
1061 for( int i = 0; i < LAYER_CLASS_COUNT; ++i )
1062 {
1063 kiapi::board::BoardLayerGraphicsDefaults* l = response.mutable_defaults()->add_layers();
1064
1065 l->set_layer( classOrder[i] );
1066 l->mutable_line_thickness()->set_value_nm( bds.m_LineThickness[i] );
1067
1068 kiapi::common::types::TextAttributes* text = l->mutable_text();
1069 text->mutable_size()->set_x_nm( bds.m_TextSize[i].x );
1070 text->mutable_size()->set_y_nm( bds.m_TextSize[i].y );
1071 text->mutable_stroke_width()->set_value_nm( bds.m_TextThickness[i] );
1072 text->set_italic( bds.m_TextItalic[i] );
1073 text->set_keep_upright( bds.m_TextUpright[i] );
1074 }
1075
1076 return response;
1077}
1078
1079
1082{
1083 if( HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1084 !documentValidation )
1085 {
1086 return tl::unexpected( documentValidation.error() );
1087 }
1088
1089 VECTOR2I origin;
1090 const BOARD_DESIGN_SETTINGS& settings = frame()->GetBoard()->GetDesignSettings();
1091
1092 switch( aCtx.Request.type() )
1093 {
1094 case BOT_GRID:
1095 origin = settings.GetGridOrigin();
1096 break;
1097
1098 case BOT_DRILL:
1099 origin = settings.GetAuxOrigin();
1100 break;
1101
1102 default:
1103 case BOT_UNKNOWN:
1104 {
1105 ApiResponseStatus e;
1106 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1107 e.set_error_message( "Unexpected origin type" );
1108 return tl::unexpected( e );
1109 }
1110 }
1111
1112 types::Vector2 reply;
1113 PackVector2( reply, origin );
1114 return reply;
1115}
1116
1119{
1120 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1121 return tl::unexpected( *busy );
1122
1123 if( HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1124 !documentValidation )
1125 {
1126 return tl::unexpected( documentValidation.error() );
1127 }
1128
1129 VECTOR2I origin = UnpackVector2( aCtx.Request.origin() );
1130
1131 switch( aCtx.Request.type() )
1132 {
1133 case BOT_GRID:
1134 {
1135 PCB_EDIT_FRAME* f = frame();
1136
1137 frame()->CallAfter( [f, origin]()
1138 {
1139 // gridSetOrigin takes ownership and frees this
1140 VECTOR2D* dorigin = new VECTOR2D( origin );
1141 TOOL_MANAGER* mgr = f->GetToolManager();
1142 mgr->RunAction( PCB_ACTIONS::gridSetOrigin, dorigin );
1143 f->Refresh();
1144 } );
1145 break;
1146 }
1147
1148 case BOT_DRILL:
1149 {
1150 PCB_EDIT_FRAME* f = frame();
1151
1152 frame()->CallAfter( [f, origin]()
1153 {
1154 TOOL_MANAGER* mgr = f->GetToolManager();
1155 mgr->RunAction( PCB_ACTIONS::drillSetOrigin, origin );
1156 f->Refresh();
1157 } );
1158 break;
1159 }
1160
1161 default:
1162 case BOT_UNKNOWN:
1163 {
1164 ApiResponseStatus e;
1165 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1166 e.set_error_message( "Unexpected origin type" );
1167 return tl::unexpected( e );
1168 }
1169 }
1170
1171 return Empty();
1172}
1173
1174
1177{
1178 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1179 return tl::unexpected( *busy );
1180
1181 if( !validateItemHeaderDocument( aCtx.Request.header() ) )
1182 {
1183 ApiResponseStatus e;
1184 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
1185 e.set_status( ApiStatusCode::AS_UNHANDLED );
1186 return tl::unexpected( e );
1187 }
1188
1189 GetBoundingBoxResponse response;
1190 bool includeText = aCtx.Request.mode() == BoundingBoxMode::BBM_ITEM_AND_CHILD_TEXT;
1191
1192 for( const types::KIID& idMsg : aCtx.Request.items() )
1193 {
1194 KIID id( idMsg.value() );
1195 std::optional<BOARD_ITEM*> optItem = getItemById( id );
1196
1197 if( !optItem )
1198 continue;
1199
1200 BOARD_ITEM* item = *optItem;
1201 BOX2I bbox;
1202
1203 if( item->Type() == PCB_FOOTPRINT_T )
1204 bbox = static_cast<FOOTPRINT*>( item )->GetBoundingBox( includeText );
1205 else
1206 bbox = item->GetBoundingBox();
1207
1208 response.add_items()->set_value( idMsg.value() );
1209 PackBox2( *response.add_boxes(), bbox );
1210 }
1211
1212 return response;
1213}
1214
1215
1218{
1219 if( HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1220 !documentValidation )
1221 {
1222 return tl::unexpected( documentValidation.error() );
1223 }
1224
1225 PadShapeAsPolygonResponse response;
1227
1228 for( const types::KIID& padRequest : aCtx.Request.pads() )
1229 {
1230 KIID id( padRequest.value() );
1231 std::optional<BOARD_ITEM*> optPad = getItemById( id );
1232
1233 if( !optPad || ( *optPad )->Type() != PCB_PAD_T )
1234 continue;
1235
1236 response.add_pads()->set_value( padRequest.value() );
1237
1238 PAD* pad = static_cast<PAD*>( *optPad );
1239 SHAPE_POLY_SET poly;
1240 pad->TransformShapeToPolygon( poly, pad->Padstack().EffectiveLayerFor( layer ), 0,
1241 pad->GetMaxError(), ERROR_INSIDE );
1242
1243 types::PolygonWithHoles* polyMsg = response.mutable_polygons()->Add();
1244 PackPolyLine( *polyMsg->mutable_outline(), poly.COutline( 0 ) );
1245 }
1246
1247 return response;
1248}
1249
1250
1253{
1254 using board::types::BoardLayer;
1255
1256 if( HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1257 !documentValidation )
1258 {
1259 return tl::unexpected( documentValidation.error() );
1260 }
1261
1262 PadstackPresenceResponse response;
1263
1264 LSET layers;
1265
1266 for( const int layer : aCtx.Request.layers() )
1267 layers.set( FromProtoEnum<PCB_LAYER_ID, BoardLayer>( static_cast<BoardLayer>( layer ) ) );
1268
1269 for( const types::KIID& padRequest : aCtx.Request.items() )
1270 {
1271 KIID id( padRequest.value() );
1272 std::optional<BOARD_ITEM*> optItem = getItemById( id );
1273
1274 if( !optItem )
1275 continue;
1276
1277 switch( ( *optItem )->Type() )
1278 {
1279 case PCB_PAD_T:
1280 {
1281 PAD* pad = static_cast<PAD*>( *optItem );
1282
1283 for( PCB_LAYER_ID layer : layers )
1284 {
1285 PadstackPresenceEntry* entry = response.add_entries();
1286 entry->mutable_item()->set_value( pad->m_Uuid.AsStdString() );
1287 entry->set_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( layer ) );
1288 entry->set_presence( pad->FlashLayer( layer ) ? PSP_PRESENT : PSP_NOT_PRESENT );
1289 }
1290
1291 break;
1292 }
1293
1294 case PCB_VIA_T:
1295 {
1296 PCB_VIA* via = static_cast<PCB_VIA*>( *optItem );
1297
1298 for( PCB_LAYER_ID layer : layers )
1299 {
1300 PadstackPresenceEntry* entry = response.add_entries();
1301 entry->mutable_item()->set_value( via->m_Uuid.AsStdString() );
1302 entry->set_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( layer ) );
1303 entry->set_presence( via->FlashLayer( layer ) ? PSP_PRESENT : PSP_NOT_PRESENT );
1304 }
1305
1306 break;
1307 }
1308
1309 default:
1310 break;
1311 }
1312 }
1313
1314 return response;
1315}
1316
1317
1320{
1321 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
1322
1323 if( !documentValidation )
1324 return tl::unexpected( documentValidation.error() );
1325
1326 BOARD* board = frame()->GetBoard();
1327 const TITLE_BLOCK& block = board->GetTitleBlock();
1328
1329 types::TitleBlockInfo response;
1330
1331 response.set_title( block.GetTitle().ToUTF8() );
1332 response.set_date( block.GetDate().ToUTF8() );
1333 response.set_revision( block.GetRevision().ToUTF8() );
1334 response.set_company( block.GetCompany().ToUTF8() );
1335 response.set_comment1( block.GetComment( 0 ).ToUTF8() );
1336 response.set_comment2( block.GetComment( 1 ).ToUTF8() );
1337 response.set_comment3( block.GetComment( 2 ).ToUTF8() );
1338 response.set_comment4( block.GetComment( 3 ).ToUTF8() );
1339 response.set_comment5( block.GetComment( 4 ).ToUTF8() );
1340 response.set_comment6( block.GetComment( 5 ).ToUTF8() );
1341 response.set_comment7( block.GetComment( 6 ).ToUTF8() );
1342 response.set_comment8( block.GetComment( 7 ).ToUTF8() );
1343 response.set_comment9( block.GetComment( 8 ).ToUTF8() );
1344
1345 return response;
1346}
1347
1348
1351{
1352 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
1353
1354 if( !documentValidation )
1355 return tl::unexpected( documentValidation.error() );
1356
1357 ExpandTextVariablesResponse reply;
1358 BOARD* board = frame()->GetBoard();
1359
1360 std::function<bool( wxString* )> textResolver =
1361 [&]( wxString* token ) -> bool
1362 {
1363 // Handles m_board->GetTitleBlock() *and* m_board->GetProject()
1364 return board->ResolveTextVar( token, 0 );
1365 };
1366
1367 for( const std::string& textMsg : aCtx.Request.text() )
1368 {
1369 wxString text = ExpandTextVars( wxString::FromUTF8( textMsg ), &textResolver );
1370 reply.add_text( text.ToUTF8() );
1371 }
1372
1373 return reply;
1374}
1375
1376
1379{
1380 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1381 return tl::unexpected( *busy );
1382
1383 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1384
1385 if( !documentValidation )
1386 return tl::unexpected( documentValidation.error() );
1387
1388 TOOL_MANAGER* mgr = frame()->GetToolManager();
1389 std::vector<EDA_ITEM*> toSelect;
1390
1391 for( const kiapi::common::types::KIID& id : aCtx.Request.items() )
1392 {
1393 if( std::optional<BOARD_ITEM*> item = getItemById( KIID( id.value() ) ) )
1394 toSelect.emplace_back( static_cast<EDA_ITEM*>( *item ) );
1395 }
1396
1397 if( toSelect.empty() )
1398 {
1399 ApiResponseStatus e;
1400 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1401 e.set_error_message( fmt::format( "None of the given items exist on the board",
1402 aCtx.Request.board().board_filename() ) );
1403 return tl::unexpected( e );
1404 }
1405
1406 PCB_SELECTION_TOOL* selectionTool = mgr->GetTool<PCB_SELECTION_TOOL>();
1407 selectionTool->GetSelection().SetReferencePoint( toSelect[0]->GetPosition() );
1408
1410 mgr->RunAction<EDA_ITEMS*>( ACTIONS::selectItems, &toSelect );
1411
1412 COMMIT* commit = getCurrentCommit( aCtx.ClientName );
1413 mgr->PostAPIAction( PCB_ACTIONS::move, commit );
1414
1415 return Empty();
1416}
1417
1418
1420{
1421 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1422
1423 if( !documentValidation )
1424 return tl::unexpected( documentValidation.error() );
1425
1426 NetsResponse response;
1427 BOARD* board = frame()->GetBoard();
1428
1429 std::set<wxString> netclassFilter;
1430
1431 for( const std::string& nc : aCtx.Request.netclass_filter() )
1432 netclassFilter.insert( wxString( nc.c_str(), wxConvUTF8 ) );
1433
1434 for( NETINFO_ITEM* net : board->GetNetInfo() )
1435 {
1436 NETCLASS* nc = net->GetNetClass();
1437
1438 if( !netclassFilter.empty() && nc && !netclassFilter.count( nc->GetName() ) )
1439 continue;
1440
1441 board::types::Net* netProto = response.add_nets();
1442 netProto->set_name( net->GetNetname() );
1443 netProto->mutable_code()->set_value( net->GetNetCode() );
1444 }
1445
1446 return response;
1447}
1448
1449
1452{
1453 NetClassForNetsResponse response;
1454
1455 BOARD* board = frame()->GetBoard();
1456 const NETINFO_LIST& nets = board->GetNetInfo();
1457 google::protobuf::Any any;
1458
1459 for( const board::types::Net& net : aCtx.Request.net() )
1460 {
1461 NETINFO_ITEM* netInfo = nets.GetNetItem( wxString::FromUTF8( net.name() ) );
1462
1463 if( !netInfo )
1464 continue;
1465
1466 netInfo->GetNetClass()->Serialize( any );
1467 auto [pair, rc] = response.mutable_classes()->insert( { net.name(), {} } );
1468 any.UnpackTo( &pair->second );
1469 }
1470
1471 return response;
1472}
1473
1474
1476{
1477 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1478 return tl::unexpected( *busy );
1479
1480 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1481
1482 if( !documentValidation )
1483 return tl::unexpected( documentValidation.error() );
1484
1485 if( aCtx.Request.zones().empty() )
1486 {
1487 TOOL_MANAGER* mgr = frame()->GetToolManager();
1488 frame()->CallAfter( [mgr]()
1489 {
1491 } );
1492 }
1493 else
1494 {
1495 // TODO
1496 ApiResponseStatus e;
1497 e.set_status( ApiStatusCode::AS_UNIMPLEMENTED );
1498 return tl::unexpected( e );
1499 }
1500
1501 return Empty();
1502}
1503
1504
1507{
1508 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
1509
1510 if( !documentValidation )
1511 return tl::unexpected( documentValidation.error() );
1512
1513 SavedDocumentResponse response;
1514 response.mutable_document()->CopyFrom( aCtx.Request.document() );
1515
1516 CLIPBOARD_IO io;
1517 io.SetWriter(
1518 [&]( const wxString& aData )
1519 {
1520 response.set_contents( aData.ToUTF8() );
1521 } );
1522
1523 io.SaveBoard( wxEmptyString, frame()->GetBoard(), nullptr );
1524
1525 return response;
1526}
1527
1528
1531{
1532 SavedSelectionResponse response;
1533
1534 TOOL_MANAGER* mgr = frame()->GetToolManager();
1535 PCB_SELECTION_TOOL* selectionTool = mgr->GetTool<PCB_SELECTION_TOOL>();
1536 PCB_SELECTION& selection = selectionTool->GetSelection();
1537
1538 CLIPBOARD_IO io;
1539 io.SetWriter(
1540 [&]( const wxString& aData )
1541 {
1542 response.set_contents( aData.ToUTF8() );
1543 } );
1544
1545 io.SetBoard( frame()->GetBoard() );
1546 io.SaveSelection( selection, false );
1547
1548 return response;
1549}
1550
1551
1554{
1555 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1556 return tl::unexpected( *busy );
1557
1558 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
1559
1560 if( !documentValidation )
1561 return tl::unexpected( documentValidation.error() );
1562
1563 CreateItemsResponse response;
1564 return response;
1565}
1566
1567
1570{
1571 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1572
1573 if( !documentValidation )
1574 return tl::unexpected( documentValidation.error() );
1575
1576 BoardLayers response;
1577
1578 for( PCB_LAYER_ID layer : frame()->GetBoard()->GetVisibleLayers() )
1579 response.add_layers( ToProtoEnum<PCB_LAYER_ID, board::types::BoardLayer>( layer ) );
1580
1581 return response;
1582}
1583
1584
1587{
1588 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1589 return tl::unexpected( *busy );
1590
1591 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1592
1593 if( !documentValidation )
1594 return tl::unexpected( documentValidation.error() );
1595
1596 LSET visible;
1597 LSET enabled = frame()->GetBoard()->GetEnabledLayers();
1598
1599 for( int layerIdx : aCtx.Request.layers() )
1600 {
1601 PCB_LAYER_ID layer =
1602 FromProtoEnum<PCB_LAYER_ID>( static_cast<board::types::BoardLayer>( layerIdx ) );
1603
1604 if( enabled.Contains( layer ) )
1605 visible.set( layer );
1606 }
1607
1608 frame()->GetBoard()->SetVisibleLayers( visible );
1611 frame()->Refresh();
1612 return Empty();
1613}
1614
1615
1618{
1619 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1620
1621 if( !documentValidation )
1622 return tl::unexpected( documentValidation.error() );
1623
1624 BoardLayerResponse response;
1625 response.set_layer(
1627
1628 return response;
1629}
1630
1631
1634{
1635 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1636 return tl::unexpected( *busy );
1637
1638 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1639
1640 if( !documentValidation )
1641 return tl::unexpected( documentValidation.error() );
1642
1643 PCB_LAYER_ID layer = FromProtoEnum<PCB_LAYER_ID>( aCtx.Request.layer() );
1644
1645 if( !frame()->GetBoard()->GetEnabledLayers().Contains( layer ) )
1646 {
1647 ApiResponseStatus err;
1648 err.set_status( ApiStatusCode::AS_BAD_REQUEST );
1649 err.set_error_message( fmt::format( "Layer {} is not a valid layer for the given board",
1650 magic_enum::enum_name( layer ) ) );
1651 return tl::unexpected( err );
1652 }
1653
1654 frame()->SetActiveLayer( layer );
1655 return Empty();
1656}
1657
1658
1661{
1662 BoardEditorAppearanceSettings reply;
1663
1664 // TODO: might be nice to put all these things in one place and have it derive SERIALIZABLE
1665
1666 const PCB_DISPLAY_OPTIONS& displayOptions = frame()->GetDisplayOptions();
1667
1668 reply.set_inactive_layer_display( ToProtoEnum<HIGH_CONTRAST_MODE, InactiveLayerDisplayMode>(
1669 displayOptions.m_ContrastModeDisplay ) );
1670 reply.set_net_color_display(
1672
1673 reply.set_board_flip( frame()->GetCanvas()->GetView()->IsMirroredX()
1674 ? BoardFlipMode::BFM_FLIPPED_X
1675 : BoardFlipMode::BFM_NORMAL );
1676
1677 PCBNEW_SETTINGS* editorSettings = frame()->GetPcbNewSettings();
1678
1679 reply.set_ratsnest_display( ToProtoEnum<RATSNEST_MODE, RatsnestDisplayMode>(
1680 editorSettings->m_Display.m_RatsnestMode ) );
1681
1682 return reply;
1683}
1684
1685
1688{
1689 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1690 return tl::unexpected( *busy );
1691
1693 KIGFX::PCB_VIEW* view = frame()->GetCanvas()->GetView();
1694 PCBNEW_SETTINGS* editorSettings = frame()->GetPcbNewSettings();
1695 const BoardEditorAppearanceSettings& newSettings = aCtx.Request.settings();
1696
1697 options.m_ContrastModeDisplay =
1698 FromProtoEnum<HIGH_CONTRAST_MODE>( newSettings.inactive_layer_display() );
1699 options.m_NetColorMode =
1700 FromProtoEnum<NET_COLOR_MODE>( newSettings.net_color_display() );
1701
1702 bool flip = newSettings.board_flip() == BoardFlipMode::BFM_FLIPPED_X;
1703
1704 if( flip != view->IsMirroredX() )
1705 {
1706 view->SetMirror( !view->IsMirroredX(), view->IsMirroredY() );
1707 view->RecacheAllItems();
1708 }
1709
1710 editorSettings->m_Display.m_RatsnestMode =
1711 FromProtoEnum<RATSNEST_MODE>( newSettings.ratsnest_display() );
1712
1713 frame()->SetDisplayOptions( options );
1715 frame()->GetCanvas()->Refresh();
1716
1717 return Empty();
1718}
1719
1720
1723{
1724 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1725 return tl::unexpected( *busy );
1726
1727 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1728
1729 if( !documentValidation )
1730 return tl::unexpected( documentValidation.error() );
1731
1732 SEVERITY severity = FromProtoEnum<SEVERITY>( aCtx.Request.severity() );
1733 int layer = severity == RPT_SEVERITY_WARNING ? LAYER_DRC_WARNING : LAYER_DRC_ERROR;
1735
1736 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( code );
1737
1738 drcItem->SetErrorMessage( wxString::FromUTF8( aCtx.Request.message() ) );
1739
1740 RC_ITEM::KIIDS ids;
1741
1742 for( const auto& id : aCtx.Request.items() )
1743 ids.emplace_back( KIID( id.value() ) );
1744
1745 if( !ids.empty() )
1746 drcItem->SetItems( ids );
1747
1748 const auto& pos = aCtx.Request.position();
1749 VECTOR2I position( static_cast<int>( pos.x_nm() ), static_cast<int>( pos.y_nm() ) );
1750
1751 PCB_MARKER* marker = new PCB_MARKER( drcItem, position, layer );
1752
1753 COMMIT* commit = getCurrentCommit( aCtx.ClientName );
1754 commit->Add( marker );
1755 commit->Push( wxS( "API injected DRC marker" ) );
1756
1757 InjectDrcErrorResponse response;
1758 response.mutable_marker()->set_value( marker->GetUUID().AsStdString() );
1759
1760 return response;
1761}
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
Definition api_enums.cpp:97
KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:36
tl::expected< T, ApiResponseStatus > HANDLER_RESULT
Definition api_handler.h:45
std::unique_ptr< EDA_ITEM > CreateItemForType(KICAD_T aType, EDA_ITEM *aContainer)
@ ERROR_INSIDE
@ LAYER_CLASS_COUNT
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:224
static TOOL_ACTION gridSetOrigin
Definition actions.h:195
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition actions.h:232
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.
API_HANDLER_EDITOR(EDA_BASE_FRAME *aFrame=nullptr)
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.
EDA_BASE_FRAME * m_frame
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< commands::GetItemsResponse > handleGetItemsById(const HANDLER_CONTEXT< commands::GetItemsById > &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< PadstackPresenceResponse > handleCheckPadstackPresenceOnLayers(const HANDLER_CONTEXT< CheckPadstackPresenceOnLayers > &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< BoardEnabledLayersResponse > handleGetBoardEnabledLayers(const HANDLER_CONTEXT< GetBoardEnabledLayers > &aCtx)
HANDLER_RESULT< commands::GetItemsResponse > handleGetItems(const HANDLER_CONTEXT< commands::GetItems > &aCtx)
HANDLER_RESULT< PadShapeAsPolygonResponse > handleGetPadShapeAsPolygon(const HANDLER_CONTEXT< GetPadShapeAsPolygon > &aCtx)
HANDLER_RESULT< InjectDrcErrorResponse > handleInjectDrcError(const HANDLER_CONTEXT< InjectDrcError > &aCtx)
PCB_EDIT_FRAME * frame() const
HANDLER_RESULT< BoardEnabledLayersResponse > handleSetBoardEnabledLayers(const HANDLER_CONTEXT< SetBoardEnabledLayers > &aCtx)
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 registerHandler(HANDLER_RESULT< ResponseType >(HandlerType::*aHandler)(const HANDLER_CONTEXT< RequestType > &))
Registers an API command handler for the given message types.
Definition api_handler.h:93
void SetContentModified(bool aModified=true)
Definition base_screen.h:59
BASE_SET & reset(size_t pos)
Definition base_set.h:143
BASE_SET & set(size_t pos)
Definition base_set.h:116
Container for design settings for a BOARD object.
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...
Definition board_item.h:84
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.
Definition board.h:322
BOARD_STACKUP GetStackupOrDefault() const
Definition board.cpp:2900
void SetVisibleLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
Definition board.cpp:999
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1082
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition board.cpp:967
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition board.cpp:1779
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....
Definition commit.h:72
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition commit.h:90
virtual void Push(const wxString &aMessage=wxT("A commit"), int aFlags=0)=0
Execute the changes.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:106
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Definition commit.h:78
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition drc_item.cpp:400
void ReleaseFile()
Release the current file marked in use.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
void AddItem(EDA_ITEM *aItem)
Add item to group.
Definition eda_group.cpp:27
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:99
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:120
const KIID m_Uuid
Definition eda_item.h:522
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:117
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:111
virtual wxString GetFriendlyName() const
Definition eda_item.cpp:411
void SetMirror(bool aMirrorX, bool aMirrorY)
Control the mirroring of the VIEW.
Definition view.cpp:562
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
Definition view.cpp:780
bool IsMirroredX() const
Return true if view is flipped across the X axis.
Definition view.h:251
void RecacheAllItems()
Rebuild GAL display lists.
Definition view.cpp:1466
bool IsMirroredY() const
Return true if view is flipped across the Y axis.
Definition view.h:259
Definition kiid.h:49
std::string AsStdString() const
Definition kiid.cpp:250
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition lseq.h:47
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static LSET AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition lset.cpp:608
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:45
const wxString GetName() const
Gets the name of this (maybe aggregate) netclass in a format for internal usage or for export to exte...
Definition netclass.cpp:328
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition netclass.cpp:136
Handle the data for a net.
Definition netinfo.h:54
NETCLASS * GetNetClass()
Definition netinfo.h:99
Container for NETINFO_ITEM elements, which are the nets.
Definition netinfo.h:212
NETINFO_ITEM * GetNetItem(int aNetCode) const
Definition pad.h:55
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.
BOARD * GetBoard() const
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.
void OnModify() override
Must be called after a board change to set the modified flag.
bool SaveBoard(bool aSaveAs=false, bool aSaveCopy=false)
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Load a KiCad board (.kicad_pcb) from aFileName.
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility,...
bool SavePcbCopy(const wxString &aFileName, bool aCreateProject=false, bool aHeadless=false)
Write the board data structures to aFileName.
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:53
const KIID GetUUID() const override
Definition pcb_marker.h:49
The selection tool: currently supports:
PCB_SELECTION & GetSelection()
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.
Definition project.cpp:401
std::vector< KIID > KIIDS
Definition rc_item.h:83
int AddItemsToSel(const TOOL_EVENT &aEvent)
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
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.
Definition title_block.h:41
const wxString & GetCompany() const
Definition title_block.h:96
const wxString & GetRevision() const
Definition title_block.h:86
const wxString & GetDate() const
Definition title_block.h:76
const wxString & GetComment(int aIdx) const
const wxString & GetTitle() const
Definition title_block.h:63
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Master controller class:
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
bool PostAPIAction(const TOOL_ACTION &aAction, COMMIT *aCommit)
A type-safe container of any type.
Definition ki_any.h:93
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
Definition common.cpp:62
The common library.
@ DRCE_GENERIC_ERROR
Definition drc_item.h:91
@ DRCE_GENERIC_WARNING
Definition drc_item.h:90
#define _(s)
@ RECURSE
Definition eda_item.h:52
static const std::string KiCadPcbFileExtension
PROJECT & Prj()
Definition kicad.cpp:642
#define KICTL_REVERT
reverting to a previously-saved (KiCad) file.
#define MAX_CU_LAYERS
Definition layer_ids.h:176
@ LAYER_DRC_WARNING
Layer for DRC markers with #SEVERITY_WARNING.
Definition layer_ids.h:301
@ LAYER_DRC_ERROR
Layer for DRC markers with #SEVERITY_ERROR.
Definition layer_ids.h:277
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ F_CrtYd
Definition layer_ids.h:116
@ Edge_Cuts
Definition layer_ids.h:112
@ Margin
Definition layer_ids.h:113
@ B_CrtYd
Definition layer_ids.h:115
@ UNDEFINED_LAYER
Definition layer_ids.h:61
@ Rescue
Definition layer_ids.h:121
void PackLayerSet(google::protobuf::RepeatedField< int > &aOutput, const LSET &aLayerSet)
LSET UnpackLayerSet(const google::protobuf::RepeatedField< int > &aProtoLayerSet)
KICOMMON_API void PackBox2(types::Box2 &aOutput, const BOX2I &aInput)
KICOMMON_API std::optional< KICAD_T > TypeNameFromAny(const google::protobuf::Any &aMessage)
Definition api_utils.cpp:33
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput)
Definition api_utils.cpp:86
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput)
Definition api_utils.cpp:79
KICOMMON_API void PackPolyLine(types::PolyLine &aOutput, const SHAPE_LINE_CHAIN &aSlc)
Class to handle a set of BOARD_ITEMs.
BOARD * GetBoard()
SEVERITY
@ RPT_SEVERITY_WARNING
std::vector< EDA_ITEM * > EDA_ITEMS
std::string ClientName
Definition api_handler.h:51
RequestMessageType Request
Definition api_handler.h:52
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:78
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:88
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:106
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:103
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:97
@ TYPE_NOT_INIT
Definition typeinfo.h:81
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:104
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:111
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:93
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:108
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:92
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:101
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:86
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:102
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:87
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:98
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition typeinfo.h:100
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:96
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:105
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694