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
23#include <api/api_handler_pcb.h>
24#include <api/api_pcb_utils.h>
25#include <api/api_enums.h>
26#include <api/api_utils.h>
27#include <board_commit.h>
29#include <footprint.h>
30#include <kicad_clipboard.h>
31#include <netinfo.h>
32#include <pad.h>
33#include <pcb_edit_frame.h>
34#include <pcb_group.h>
35#include <pcb_reference_image.h>
36#include <pcb_shape.h>
37#include <pcb_text.h>
38#include <pcb_textbox.h>
39#include <pcb_track.h>
40#include <pcbnew_id.h>
41#include <project.h>
42#include <tool/tool_manager.h>
43#include <tools/pcb_actions.h>
45#include <zone.h>
46
47#include <api/common/types/base_types.pb.h>
49
50using namespace kiapi::common::commands;
51using types::CommandStatus;
52using types::DocumentType;
53using types::ItemRequestStatus;
54
55
57 API_HANDLER_EDITOR( aFrame )
58{
59 registerHandler<RunAction, RunActionResponse>( &API_HANDLER_PCB::handleRunAction );
60 registerHandler<GetOpenDocuments, GetOpenDocumentsResponse>(
62 registerHandler<SaveDocument, Empty>( &API_HANDLER_PCB::handleSaveDocument );
63 registerHandler<SaveCopyOfDocument, Empty>( &API_HANDLER_PCB::handleSaveCopyOfDocument );
64 registerHandler<RevertDocument, Empty>( &API_HANDLER_PCB::handleRevertDocument );
65
66 registerHandler<GetItems, GetItemsResponse>( &API_HANDLER_PCB::handleGetItems );
67
68 registerHandler<GetSelection, SelectionResponse>( &API_HANDLER_PCB::handleGetSelection );
69 registerHandler<ClearSelection, Empty>( &API_HANDLER_PCB::handleClearSelection );
70 registerHandler<AddToSelection, SelectionResponse>( &API_HANDLER_PCB::handleAddToSelection );
71 registerHandler<RemoveFromSelection, SelectionResponse>(
73
74 registerHandler<GetBoardStackup, BoardStackupResponse>( &API_HANDLER_PCB::handleGetStackup );
75 registerHandler<GetGraphicsDefaults, GraphicsDefaultsResponse>(
77 registerHandler<GetBoundingBox, GetBoundingBoxResponse>(
79 registerHandler<GetPadShapeAsPolygon, PadShapeAsPolygonResponse>(
81 registerHandler<GetTitleBlockInfo, types::TitleBlockInfo>(
83 registerHandler<ExpandTextVariables, ExpandTextVariablesResponse>(
85
86 registerHandler<InteractiveMoveItems, Empty>( &API_HANDLER_PCB::handleInteractiveMoveItems );
87 registerHandler<GetNets, NetsResponse>( &API_HANDLER_PCB::handleGetNets );
88 registerHandler<GetNetClassForNets, NetClassForNetsResponse>(
90 registerHandler<RefillZones, Empty>( &API_HANDLER_PCB::handleRefillZones );
91
92 registerHandler<SaveDocumentToString, SavedDocumentResponse>(
94 registerHandler<SaveSelectionToString, SavedSelectionResponse>(
96 registerHandler<ParseAndCreateItemsFromString, CreateItemsResponse>(
98 registerHandler<GetVisibleLayers, BoardLayers>( &API_HANDLER_PCB::handleGetVisibleLayers );
99 registerHandler<SetVisibleLayers, Empty>( &API_HANDLER_PCB::handleSetVisibleLayers );
100 registerHandler<GetActiveLayer, BoardLayerResponse>( &API_HANDLER_PCB::handleGetActiveLayer );
101 registerHandler<SetActiveLayer, Empty>( &API_HANDLER_PCB::handleSetActiveLayer );
102 registerHandler<GetBoardEditorAppearanceSettings, BoardEditorAppearanceSettings>(
104 registerHandler<SetBoardEditorAppearanceSettings, Empty>(
106}
107
108
110{
111 return static_cast<PCB_EDIT_FRAME*>( m_frame );
112}
113
114
116 const HANDLER_CONTEXT<RunAction>& aCtx )
117{
118 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
119 return tl::unexpected( *busy );
120
121 RunActionResponse response;
122
123 if( frame()->GetToolManager()->RunAction( aCtx.Request.action(), true ) )
124 response.set_status( RunActionStatus::RAS_OK );
125 else
126 response.set_status( RunActionStatus::RAS_INVALID );
127
128 return response;
129}
130
131
134{
135 if( aCtx.Request.type() != DocumentType::DOCTYPE_PCB )
136 {
137 ApiResponseStatus e;
138 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
139 e.set_status( ApiStatusCode::AS_UNHANDLED );
140 return tl::unexpected( e );
141 }
142
143 GetOpenDocumentsResponse response;
144 common::types::DocumentSpecifier doc;
145
146 wxFileName fn( frame()->GetCurrentFileName() );
147
148 doc.set_type( DocumentType::DOCTYPE_PCB );
149 doc.set_board_filename( fn.GetFullName() );
150
151 doc.mutable_project()->set_name( frame()->Prj().GetProjectName().ToStdString() );
152 doc.mutable_project()->set_path( frame()->Prj().GetProjectDirectory().ToStdString() );
153
154 response.mutable_documents()->Add( std::move( doc ) );
155 return response;
156}
157
158
161{
162 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
163 return tl::unexpected( *busy );
164
165 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
166
167 if( !documentValidation )
168 return tl::unexpected( documentValidation.error() );
169
171 return Empty();
172}
173
174
177{
178 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
179 return tl::unexpected( *busy );
180
181 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
182
183 if( !documentValidation )
184 return tl::unexpected( documentValidation.error() );
185
186 wxFileName boardPath( frame()->Prj().AbsolutePath( wxString::FromUTF8( aCtx.Request.path() ) ) );
187
188 if( !boardPath.IsOk() || !boardPath.IsDirWritable() )
189 {
190 ApiResponseStatus e;
191 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
192 e.set_error_message( fmt::format( "save path '{}' could not be opened",
193 boardPath.GetFullPath().ToStdString() ) );
194 return tl::unexpected( e );
195 }
196
197 if( boardPath.FileExists()
198 && ( !boardPath.IsFileWritable() || !aCtx.Request.options().overwrite() ) )
199 {
200 ApiResponseStatus e;
201 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
202 e.set_error_message( fmt::format( "save path '{}' exists and cannot be overwritten",
203 boardPath.GetFullPath().ToStdString() ) );
204 return tl::unexpected( e );
205 }
206
207 if( boardPath.GetExt() != FILEEXT::KiCadPcbFileExtension )
208 {
209 ApiResponseStatus e;
210 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
211 e.set_error_message( fmt::format( "save path '{}' must have a kicad_pcb extension",
212 boardPath.GetFullPath().ToStdString() ) );
213 return tl::unexpected( e );
214 }
215
216 BOARD* board = frame()->GetBoard();
217
218 if( board->GetFileName().Matches( boardPath.GetFullPath() ) )
219 {
221 return Empty();
222 }
223
224 bool includeProject = true;
225
226 if( aCtx.Request.has_options() )
227 includeProject = aCtx.Request.options().include_project();
228
229 frame()->SavePcbCopy( boardPath.GetFullPath(), includeProject, /* aHeadless = */ true );
230
231 return Empty();
232}
233
234
237{
238 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
239 return tl::unexpected( *busy );
240
241 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
242
243 if( !documentValidation )
244 return tl::unexpected( documentValidation.error() );
245
246 wxFileName fn = frame()->Prj().AbsolutePath( frame()->GetBoard()->GetFileName() );
247
248 frame()->GetScreen()->SetContentModified( false );
249 frame()->ReleaseFile();
250 frame()->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ), KICTL_REVERT );
251
252 return Empty();
253}
254
255
256void API_HANDLER_PCB::pushCurrentCommit( const std::string& aClientName, const wxString& aMessage )
257{
258 API_HANDLER_EDITOR::pushCurrentCommit( aClientName, aMessage );
259 frame()->Refresh();
260}
261
262
263std::unique_ptr<COMMIT> API_HANDLER_PCB::createCommit()
264{
265 return std::make_unique<BOARD_COMMIT>( frame() );
266}
267
268
269std::optional<BOARD_ITEM*> API_HANDLER_PCB::getItemById( const KIID& aId ) const
270{
271 BOARD_ITEM* item = frame()->GetBoard()->GetItem( aId );
272
273 if( item == DELETED_BOARD_ITEM::GetInstance() )
274 return std::nullopt;
275
276 return item;
277}
278
279
280bool API_HANDLER_PCB::validateDocumentInternal( const DocumentSpecifier& aDocument ) const
281{
282 if( aDocument.type() != DocumentType::DOCTYPE_PCB )
283 return false;
284
285 wxFileName fn( frame()->GetCurrentFileName() );
286 return 0 == aDocument.board_filename().compare( fn.GetFullName() );
287}
288
289
291 BOARD_ITEM_CONTAINER* aContainer )
292{
293 if( !aContainer )
294 {
295 ApiResponseStatus e;
296 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
297 e.set_error_message( "Tried to create an item in a null container" );
298 return tl::unexpected( e );
299 }
300
301 if( aType == PCB_PAD_T && !dynamic_cast<FOOTPRINT*>( aContainer ) )
302 {
303 ApiResponseStatus e;
304 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
305 e.set_error_message( fmt::format( "Tried to create a pad in {}, which is not a footprint",
306 aContainer->GetFriendlyName().ToStdString() ) );
307 return tl::unexpected( e );
308 }
309 else if( aType == PCB_FOOTPRINT_T && !dynamic_cast<BOARD*>( aContainer ) )
310 {
311 ApiResponseStatus e;
312 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
313 e.set_error_message( fmt::format( "Tried to create a footprint in {}, which is not a board",
314 aContainer->GetFriendlyName().ToStdString() ) );
315 return tl::unexpected( e );
316 }
317
318 std::unique_ptr<BOARD_ITEM> created = CreateItemForType( aType, aContainer );
319
320 if( !created )
321 {
322 ApiResponseStatus e;
323 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
324 e.set_error_message( fmt::format( "Tried to create an item of type {}, which is unhandled",
325 magic_enum::enum_name( aType ) ) );
326 return tl::unexpected( e );
327 }
328
329 return created;
330}
331
332
334 const std::string& aClientName,
335 const types::ItemHeader &aHeader,
336 const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems,
337 std::function<void( ItemStatus, google::protobuf::Any )> aItemHandler )
338{
339 ApiResponseStatus e;
340
341 auto containerResult = validateItemHeaderDocument( aHeader );
342
343 if( !containerResult && containerResult.error().status() == ApiStatusCode::AS_UNHANDLED )
344 {
345 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
346 e.set_status( ApiStatusCode::AS_UNHANDLED );
347 return tl::unexpected( e );
348 }
349 else if( !containerResult )
350 {
351 e.CopyFrom( containerResult.error() );
352 return tl::unexpected( e );
353 }
354
355 BOARD* board = frame()->GetBoard();
356 BOARD_ITEM_CONTAINER* container = board;
357
358 if( containerResult->has_value() )
359 {
360 const KIID& containerId = **containerResult;
361 std::optional<BOARD_ITEM*> optItem = getItemById( containerId );
362
363 if( optItem )
364 {
365 container = dynamic_cast<BOARD_ITEM_CONTAINER*>( *optItem );
366
367 if( !container )
368 {
369 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
370 e.set_error_message( fmt::format(
371 "The requested container {} is not a valid board item container",
372 containerId.AsStdString() ) );
373 return tl::unexpected( e );
374 }
375 }
376 else
377 {
378 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
379 e.set_error_message( fmt::format(
380 "The requested container {} does not exist in this document",
381 containerId.AsStdString() ) );
382 return tl::unexpected( e );
383 }
384 }
385
386 BOARD_COMMIT* commit = static_cast<BOARD_COMMIT*>( getCurrentCommit( aClientName ) );
387
388 for( const google::protobuf::Any& anyItem : aItems )
389 {
390 ItemStatus status;
391 std::optional<KICAD_T> type = TypeNameFromAny( anyItem );
392
393 if( !type )
394 {
395 status.set_code( ItemStatusCode::ISC_INVALID_TYPE );
396 status.set_error_message( fmt::format( "Could not decode a valid type from {}",
397 anyItem.type_url() ) );
398 aItemHandler( status, anyItem );
399 continue;
400 }
401
402 if( type == PCB_DIMENSION_T )
403 {
404 board::types::Dimension dimension;
405 anyItem.UnpackTo( &dimension );
406
407 switch( dimension.dimension_style_case() )
408 {
409 case board::types::Dimension::kAligned: type = PCB_DIM_ALIGNED_T; break;
410 case board::types::Dimension::kOrthogonal: type = PCB_DIM_ORTHOGONAL_T; break;
411 case board::types::Dimension::kRadial: type = PCB_DIM_RADIAL_T; break;
412 case board::types::Dimension::kLeader: type = PCB_DIM_LEADER_T; break;
413 case board::types::Dimension::kCenter: type = PCB_DIM_CENTER_T; break;
414 case board::types::Dimension::DIMENSION_STYLE_NOT_SET: break;
415 }
416 }
417
419 createItemForType( *type, container );
420
421 if( !creationResult )
422 {
423 status.set_code( ItemStatusCode::ISC_INVALID_TYPE );
424 status.set_error_message( creationResult.error().error_message() );
425 aItemHandler( status, anyItem );
426 continue;
427 }
428
429 std::unique_ptr<BOARD_ITEM> item( std::move( *creationResult ) );
430
431 if( !item->Deserialize( anyItem ) )
432 {
433 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
434 e.set_error_message( fmt::format( "could not unpack {} from request",
435 item->GetClass().ToStdString() ) );
436 return tl::unexpected( e );
437 }
438
439 std::optional<BOARD_ITEM*> optItem = getItemById( item->m_Uuid );
440
441 if( aCreate && optItem )
442 {
443 status.set_code( ItemStatusCode::ISC_EXISTING );
444 status.set_error_message( fmt::format( "an item with UUID {} already exists",
445 item->m_Uuid.AsStdString() ) );
446 aItemHandler( status, anyItem );
447 continue;
448 }
449 else if( !aCreate && !optItem )
450 {
451 status.set_code( ItemStatusCode::ISC_NONEXISTENT );
452 status.set_error_message( fmt::format( "an item with UUID {} does not exist",
453 item->m_Uuid.AsStdString() ) );
454 aItemHandler( status, anyItem );
455 continue;
456 }
457
458 if( aCreate && !( board->GetEnabledLayers() & item->GetLayerSet() ).any() )
459 {
460 status.set_code( ItemStatusCode::ISC_INVALID_DATA );
461 status.set_error_message(
462 "attempted to add item with no overlapping layers with the board" );
463 aItemHandler( status, anyItem );
464 continue;
465 }
466
467 status.set_code( ItemStatusCode::ISC_OK );
468 google::protobuf::Any newItem;
469
470 if( aCreate )
471 {
472 item->Serialize( newItem );
473 commit->Add( item.release() );
474 }
475 else
476 {
477 BOARD_ITEM* boardItem = *optItem;
478 commit->Modify( boardItem );
479 boardItem->SwapItemData( item.get() );
480 boardItem->Serialize( newItem );
481 }
482
483 aItemHandler( status, newItem );
484 }
485
486 if( !m_activeClients.count( aClientName ) )
487 {
488 pushCurrentCommit( aClientName, aCreate ? _( "Created items via API" )
489 : _( "Added items via API" ) );
490 }
491
492
493 return ItemRequestStatus::IRS_OK;
494}
495
496
498 const HANDLER_CONTEXT<GetItems>& aCtx )
499{
500 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
501 return tl::unexpected( *busy );
502
503 if( !validateItemHeaderDocument( aCtx.Request.header() ) )
504 {
505 ApiResponseStatus e;
506 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
507 e.set_status( ApiStatusCode::AS_UNHANDLED );
508 return tl::unexpected( e );
509 }
510
511 GetItemsResponse response;
512
513 BOARD* board = frame()->GetBoard();
514 std::vector<BOARD_ITEM*> items;
515 std::set<KICAD_T> typesRequested, typesInserted;
516 bool handledAnything = false;
517
518 for( int typeRaw : aCtx.Request.types() )
519 {
520 auto typeMessage = static_cast<common::types::KiCadObjectType>( typeRaw );
521 KICAD_T type = FromProtoEnum<KICAD_T>( typeMessage );
522
523 if( type == TYPE_NOT_INIT )
524 continue;
525
526 typesRequested.emplace( type );
527
528 if( typesInserted.count( type ) )
529 continue;
530
531 switch( type )
532 {
533 case PCB_TRACE_T:
534 case PCB_ARC_T:
535 case PCB_VIA_T:
536 handledAnything = true;
537 std::copy( board->Tracks().begin(), board->Tracks().end(),
538 std::back_inserter( items ) );
539 typesInserted.insert( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } );
540 break;
541
542 case PCB_PAD_T:
543 {
544 handledAnything = true;
545
546 for( FOOTPRINT* fp : board->Footprints() )
547 {
548 std::copy( fp->Pads().begin(), fp->Pads().end(),
549 std::back_inserter( items ) );
550 }
551
552 typesInserted.insert( PCB_PAD_T );
553 break;
554 }
555
556 case PCB_FOOTPRINT_T:
557 {
558 handledAnything = true;
559
560 std::copy( board->Footprints().begin(), board->Footprints().end(),
561 std::back_inserter( items ) );
562
563 typesInserted.insert( PCB_FOOTPRINT_T );
564 break;
565 }
566
567 case PCB_SHAPE_T:
568 case PCB_TEXT_T:
569 case PCB_TEXTBOX_T:
570 {
571 handledAnything = true;
572 bool inserted = false;
573
574 for( BOARD_ITEM* item : board->Drawings() )
575 {
576 if( item->Type() == type )
577 {
578 items.emplace_back( item );
579 inserted = true;
580 }
581 }
582
583 if( inserted )
584 typesInserted.insert( PCB_SHAPE_T );
585
586 break;
587 }
588
589 case PCB_ZONE_T:
590 {
591 handledAnything = true;
592
593 std::copy( board->Zones().begin(), board->Zones().end(),
594 std::back_inserter( items ) );
595
596 typesInserted.insert( PCB_ZONE_T );
597 break;
598 }
599
600 default:
601 break;
602 }
603 }
604
605 if( !handledAnything )
606 {
607 ApiResponseStatus e;
608 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
609 e.set_error_message( "none of the requested types are valid for a Board object" );
610 return tl::unexpected( e );
611 }
612
613 for( const BOARD_ITEM* item : items )
614 {
615 if( !typesRequested.count( item->Type() ) )
616 continue;
617
618 google::protobuf::Any itemBuf;
619 item->Serialize( itemBuf );
620 response.mutable_items()->Add( std::move( itemBuf ) );
621 }
622
623 response.set_status( ItemRequestStatus::IRS_OK );
624 return response;
625}
626
627
628void API_HANDLER_PCB::deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& aItemsToDelete,
629 const std::string& aClientName )
630{
631 BOARD* board = frame()->GetBoard();
632 std::vector<BOARD_ITEM*> validatedItems;
633
634 for( std::pair<const KIID, ItemDeletionStatus> pair : aItemsToDelete )
635 {
636 if( BOARD_ITEM* item = board->GetItem( pair.first ) )
637 {
638 validatedItems.push_back( item );
639 aItemsToDelete[pair.first] = ItemDeletionStatus::IDS_OK;
640 }
641
642 // Note: we don't currently support locking items from API modification, but here is where
643 // to add it in the future (and return IDS_IMMUTABLE)
644 }
645
646 COMMIT* commit = getCurrentCommit( aClientName );
647
648 for( BOARD_ITEM* item : validatedItems )
649 commit->Remove( item );
650
651 if( !m_activeClients.count( aClientName ) )
652 pushCurrentCommit( aClientName, _( "Deleted items via API" ) );
653}
654
655
656std::optional<EDA_ITEM*> API_HANDLER_PCB::getItemFromDocument( const DocumentSpecifier& aDocument,
657 const KIID& aId )
658{
659 if( !validateDocument( aDocument ) )
660 return std::nullopt;
661
662 return getItemById( aId );
663}
664
665
668{
669 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
670 return tl::unexpected( *busy );
671
672 if( !validateItemHeaderDocument( aCtx.Request.header() ) )
673 {
674 ApiResponseStatus e;
675 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
676 e.set_status( ApiStatusCode::AS_UNHANDLED );
677 return tl::unexpected( e );
678 }
679
680 std::set<KICAD_T> filter;
681
682 for( int typeRaw : aCtx.Request.types() )
683 {
684 auto typeMessage = static_cast<types::KiCadObjectType>( typeRaw );
685 KICAD_T type = FromProtoEnum<KICAD_T>( typeMessage );
686
687 if( type == TYPE_NOT_INIT )
688 continue;
689
690 filter.insert( type );
691 }
692
694 PCB_SELECTION_TOOL* selectionTool = mgr->GetTool<PCB_SELECTION_TOOL>();
695
696 SelectionResponse response;
697
698 for( EDA_ITEM* item : selectionTool->GetSelection() )
699 {
700 if( filter.empty() || filter.contains( item->Type() ) )
701 item->Serialize( *response.add_items() );
702 }
703
704 return response;
705}
706
707
710{
711 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
712 return tl::unexpected( *busy );
713
714 if( !validateItemHeaderDocument( aCtx.Request.header() ) )
715 {
716 ApiResponseStatus e;
717 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
718 e.set_status( ApiStatusCode::AS_UNHANDLED );
719 return tl::unexpected( e );
720 }
721
724
725 return Empty();
726}
727
728
731{
732 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
733 return tl::unexpected( *busy );
734
735 if( !validateItemHeaderDocument( aCtx.Request.header() ) )
736 {
737 ApiResponseStatus e;
738 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
739 e.set_status( ApiStatusCode::AS_UNHANDLED );
740 return tl::unexpected( e );
741 }
742
744 PCB_SELECTION_TOOL* selectionTool = mgr->GetTool<PCB_SELECTION_TOOL>();
745
746 std::vector<EDA_ITEM*> toAdd;
747
748 for( const types::KIID& id : aCtx.Request.items() )
749 {
750 if( std::optional<BOARD_ITEM*> item = getItemById( KIID( id.value() ) ) )
751 toAdd.emplace_back( *item );
752 }
753
754 selectionTool->AddItemsToSel( &toAdd );
755
756 SelectionResponse response;
757
758 for( EDA_ITEM* item : selectionTool->GetSelection() )
759 item->Serialize( *response.add_items() );
760
761 return response;
762}
763
764
767{
768 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
769 return tl::unexpected( *busy );
770
771 if( !validateItemHeaderDocument( aCtx.Request.header() ) )
772 {
773 ApiResponseStatus e;
774 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
775 e.set_status( ApiStatusCode::AS_UNHANDLED );
776 return tl::unexpected( e );
777 }
778
780 PCB_SELECTION_TOOL* selectionTool = mgr->GetTool<PCB_SELECTION_TOOL>();
781
782 std::vector<EDA_ITEM*> toRemove;
783
784 for( const types::KIID& id : aCtx.Request.items() )
785 {
786 if( std::optional<BOARD_ITEM*> item = getItemById( KIID( id.value() ) ) )
787 toRemove.emplace_back( *item );
788 }
789
790 selectionTool->RemoveItemsFromSel( &toRemove );
791
792 SelectionResponse response;
793
794 for( EDA_ITEM* item : selectionTool->GetSelection() )
795 item->Serialize( *response.add_items() );
796
797 return response;
798}
799
800
803{
804 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
805 return tl::unexpected( *busy );
806
807 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
808
809 if( !documentValidation )
810 return tl::unexpected( documentValidation.error() );
811
812 BoardStackupResponse response;
813 google::protobuf::Any any;
814
816
817 any.UnpackTo( response.mutable_stackup() );
818
819 // User-settable layer names are not stored in BOARD_STACKUP at the moment
820 for( board::BoardStackupLayer& layer : *response.mutable_stackup()->mutable_layers() )
821 {
822 if( layer.type() == board::BoardStackupLayerType::BSLT_DIELECTRIC )
823 continue;
824
825 PCB_LAYER_ID id = FromProtoEnum<PCB_LAYER_ID>( layer.layer() );
826 wxCHECK2( id != UNDEFINED_LAYER, continue );
827
828 layer.set_user_name( frame()->GetBoard()->GetLayerName( id ) );
829 }
830
831 return response;
832}
833
834
837{
838 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
839 return tl::unexpected( *busy );
840
841 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
842
843 if( !documentValidation )
844 return tl::unexpected( documentValidation.error() );
845
847 GraphicsDefaultsResponse response;
848
849 // TODO: This should change to be an enum class
850 constexpr std::array<kiapi::board::BoardLayerClass, LAYER_CLASS_COUNT> classOrder = {
851 kiapi::board::BLC_SILKSCREEN,
852 kiapi::board::BLC_COPPER,
853 kiapi::board::BLC_EDGES,
854 kiapi::board::BLC_COURTYARD,
855 kiapi::board::BLC_FABRICATION,
856 kiapi::board::BLC_OTHER
857 };
858
859 for( int i = 0; i < LAYER_CLASS_COUNT; ++i )
860 {
861 kiapi::board::BoardLayerGraphicsDefaults* l = response.mutable_defaults()->add_layers();
862
863 l->set_layer( classOrder[i] );
864 l->mutable_line_thickness()->set_value_nm( bds.m_LineThickness[i] );
865
866 kiapi::common::types::TextAttributes* text = l->mutable_text();
867 text->mutable_size()->set_x_nm( bds.m_TextSize[i].x );
868 text->mutable_size()->set_y_nm( bds.m_TextSize[i].y );
869 text->mutable_stroke_width()->set_value_nm( bds.m_TextThickness[i] );
870 text->set_italic( bds.m_TextItalic[i] );
871 text->set_keep_upright( bds.m_TextUpright[i] );
872 }
873
874 return response;
875}
876
877
880{
881 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
882 return tl::unexpected( *busy );
883
884 if( !validateItemHeaderDocument( aCtx.Request.header() ) )
885 {
886 ApiResponseStatus e;
887 // No message needed for AS_UNHANDLED; this is an internal flag for the API server
888 e.set_status( ApiStatusCode::AS_UNHANDLED );
889 return tl::unexpected( e );
890 }
891
892 GetBoundingBoxResponse response;
893 bool includeText = aCtx.Request.mode() == BoundingBoxMode::BBM_ITEM_AND_CHILD_TEXT;
894
895 for( const types::KIID& idMsg : aCtx.Request.items() )
896 {
897 KIID id( idMsg.value() );
898 std::optional<BOARD_ITEM*> optItem = getItemById( id );
899
900 if( !optItem )
901 continue;
902
903 BOARD_ITEM* item = *optItem;
904 BOX2I bbox;
905
906 if( item->Type() == PCB_FOOTPRINT_T )
907 bbox = static_cast<FOOTPRINT*>( item )->GetBoundingBox( includeText );
908 else
909 bbox = item->GetBoundingBox();
910
911 response.add_items()->set_value( idMsg.value() );
912 PackBox2( *response.add_boxes(), bbox );
913 }
914
915 return response;
916}
917
918
921{
922 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
923
924 if( !documentValidation )
925 return tl::unexpected( documentValidation.error() );
926
927 PadShapeAsPolygonResponse response;
928 PCB_LAYER_ID layer = FromProtoEnum<PCB_LAYER_ID, board::types::BoardLayer>( aCtx.Request.layer() );
929
930 for( const types::KIID& padRequest : aCtx.Request.pads() )
931 {
932 KIID id( padRequest.value() );
933 std::optional<BOARD_ITEM*> optPad = getItemById( id );
934
935 if( !optPad || ( *optPad )->Type() != PCB_PAD_T )
936 continue;
937
938 response.add_pads()->set_value( padRequest.value() );
939
940 PAD* pad = static_cast<PAD*>( *optPad );
941 SHAPE_POLY_SET poly;
942 pad->TransformShapeToPolygon( poly, pad->Padstack().EffectiveLayerFor( layer ), 0,
944
945 types::PolygonWithHoles* polyMsg = response.mutable_polygons()->Add();
946 PackPolyLine( *polyMsg->mutable_outline(), poly.COutline( 0 ) );
947 }
948
949 return response;
950}
951
952
955{
956 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
957
958 if( !documentValidation )
959 return tl::unexpected( documentValidation.error() );
960
961 BOARD* board = frame()->GetBoard();
962 const TITLE_BLOCK& block = board->GetTitleBlock();
963
964 types::TitleBlockInfo response;
965
966 response.set_title( block.GetTitle().ToUTF8() );
967 response.set_date( block.GetDate().ToUTF8() );
968 response.set_revision( block.GetRevision().ToUTF8() );
969 response.set_company( block.GetCompany().ToUTF8() );
970 response.set_comment1( block.GetComment( 0 ).ToUTF8() );
971 response.set_comment2( block.GetComment( 1 ).ToUTF8() );
972 response.set_comment3( block.GetComment( 2 ).ToUTF8() );
973 response.set_comment4( block.GetComment( 3 ).ToUTF8() );
974 response.set_comment5( block.GetComment( 4 ).ToUTF8() );
975 response.set_comment6( block.GetComment( 5 ).ToUTF8() );
976 response.set_comment7( block.GetComment( 6 ).ToUTF8() );
977 response.set_comment8( block.GetComment( 7 ).ToUTF8() );
978 response.set_comment9( block.GetComment( 8 ).ToUTF8() );
979
980 return response;
981}
982
983
986{
987 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
988
989 if( !documentValidation )
990 return tl::unexpected( documentValidation.error() );
991
992 ExpandTextVariablesResponse reply;
993 BOARD* board = frame()->GetBoard();
994
995 std::function<bool( wxString* )> textResolver =
996 [&]( wxString* token ) -> bool
997 {
998 // Handles m_board->GetTitleBlock() *and* m_board->GetProject()
999 return board->ResolveTextVar( token, 0 );
1000 };
1001
1002 for( const std::string& textMsg : aCtx.Request.text() )
1003 {
1004 wxString text = ExpandTextVars( wxString::FromUTF8( textMsg ), &textResolver );
1005 reply.add_text( text.ToUTF8() );
1006 }
1007
1008 return reply;
1009}
1010
1011
1014{
1015 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1016 return tl::unexpected( *busy );
1017
1018 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1019
1020 if( !documentValidation )
1021 return tl::unexpected( documentValidation.error() );
1022
1023 TOOL_MANAGER* mgr = frame()->GetToolManager();
1024 std::vector<EDA_ITEM*> toSelect;
1025
1026 for( const kiapi::common::types::KIID& id : aCtx.Request.items() )
1027 {
1028 if( std::optional<BOARD_ITEM*> item = getItemById( KIID( id.value() ) ) )
1029 toSelect.emplace_back( static_cast<EDA_ITEM*>( *item ) );
1030 }
1031
1032 if( toSelect.empty() )
1033 {
1034 ApiResponseStatus e;
1035 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
1036 e.set_error_message( fmt::format( "None of the given items exist on the board",
1037 aCtx.Request.board().board_filename() ) );
1038 return tl::unexpected( e );
1039 }
1040
1041 PCB_SELECTION_TOOL* selectionTool = mgr->GetTool<PCB_SELECTION_TOOL>();
1042 selectionTool->GetSelection().SetReferencePoint( toSelect[0]->GetPosition() );
1043
1045 mgr->RunAction<EDA_ITEMS*>( PCB_ACTIONS::selectItems, &toSelect );
1046
1047 COMMIT* commit = getCurrentCommit( aCtx.ClientName );
1048 mgr->PostAction( PCB_ACTIONS::move, commit );
1049
1050 return Empty();
1051}
1052
1053
1055{
1056 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1057 return tl::unexpected( *busy );
1058
1059 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1060
1061 if( !documentValidation )
1062 return tl::unexpected( documentValidation.error() );
1063
1064 NetsResponse response;
1065 BOARD* board = frame()->GetBoard();
1066
1067 std::set<wxString> netclassFilter;
1068
1069 for( const std::string& nc : aCtx.Request.netclass_filter() )
1070 netclassFilter.insert( wxString( nc.c_str(), wxConvUTF8 ) );
1071
1072 for( NETINFO_ITEM* net : board->GetNetInfo() )
1073 {
1074 NETCLASS* nc = net->GetNetClass();
1075
1076 if( !netclassFilter.empty() && nc && !netclassFilter.count( nc->GetName() ) )
1077 continue;
1078
1079 board::types::Net* netProto = response.add_nets();
1080 netProto->set_name( net->GetNetname() );
1081 netProto->mutable_code()->set_value( net->GetNetCode() );
1082 }
1083
1084 return response;
1085}
1086
1087
1090{
1091 NetClassForNetsResponse response;
1092
1093 BOARD* board = frame()->GetBoard();
1094 NETINFO_LIST nets = board->GetNetInfo();
1095 google::protobuf::Any any;
1096
1097 for( const board::types::Net& net : aCtx.Request.net() )
1098 {
1099 NETINFO_ITEM* netInfo = nets.GetNetItem( wxString::FromUTF8( net.name() ) );
1100
1101 if( !netInfo )
1102 continue;
1103
1104 netInfo->GetNetClass()->Serialize( any );
1105 auto [pair, rc] = response.mutable_classes()->insert( { net.name(), {} } );
1106 any.UnpackTo( &pair->second );
1107 }
1108
1109 return response;
1110}
1111
1112
1114{
1115 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1116 return tl::unexpected( *busy );
1117
1118 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1119
1120 if( !documentValidation )
1121 return tl::unexpected( documentValidation.error() );
1122
1123 if( aCtx.Request.zones().empty() )
1124 {
1125 TOOL_MANAGER* mgr = frame()->GetToolManager();
1126 frame()->CallAfter( [mgr]()
1127 {
1129 } );
1130 }
1131 else
1132 {
1133 // TODO
1134 ApiResponseStatus e;
1135 e.set_status( ApiStatusCode::AS_UNIMPLEMENTED );
1136 return tl::unexpected( e );
1137 }
1138
1139 return Empty();
1140}
1141
1142
1145{
1146 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
1147
1148 if( !documentValidation )
1149 return tl::unexpected( documentValidation.error() );
1150
1151 SavedDocumentResponse response;
1152 response.mutable_document()->CopyFrom( aCtx.Request.document() );
1153
1154 CLIPBOARD_IO io;
1155 io.SetWriter(
1156 [&]( const wxString& aData )
1157 {
1158 response.set_contents( aData.ToUTF8() );
1159 } );
1160
1161 io.SaveBoard( wxEmptyString, frame()->GetBoard(), nullptr );
1162
1163 return response;
1164}
1165
1166
1169{
1170 SavedSelectionResponse response;
1171
1172 TOOL_MANAGER* mgr = frame()->GetToolManager();
1173 PCB_SELECTION_TOOL* selectionTool = mgr->GetTool<PCB_SELECTION_TOOL>();
1174 PCB_SELECTION& selection = selectionTool->GetSelection();
1175
1176 CLIPBOARD_IO io;
1177 io.SetWriter(
1178 [&]( const wxString& aData )
1179 {
1180 response.set_contents( aData.ToUTF8() );
1181 } );
1182
1183 io.SetBoard( frame()->GetBoard() );
1184 io.SaveSelection( selection, false );
1185
1186 return response;
1187}
1188
1189
1192{
1193 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1194 return tl::unexpected( *busy );
1195
1196 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
1197
1198 if( !documentValidation )
1199 return tl::unexpected( documentValidation.error() );
1200
1201 CreateItemsResponse response;
1202 return response;
1203}
1204
1205
1208{
1209 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1210
1211 if( !documentValidation )
1212 return tl::unexpected( documentValidation.error() );
1213
1214 BoardLayers response;
1215
1216 for( PCB_LAYER_ID layer : frame()->GetBoard()->GetVisibleLayers() )
1217 response.add_layers( ToProtoEnum<PCB_LAYER_ID, board::types::BoardLayer>( layer ) );
1218
1219 return response;
1220}
1221
1222
1225{
1226 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1227 return tl::unexpected( *busy );
1228
1229 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1230
1231 if( !documentValidation )
1232 return tl::unexpected( documentValidation.error() );
1233
1234 LSET visible;
1235 LSET enabled = frame()->GetBoard()->GetEnabledLayers();
1236
1237 for( int layerIdx : aCtx.Request.layers() )
1238 {
1239 PCB_LAYER_ID layer =
1240 FromProtoEnum<PCB_LAYER_ID>( static_cast<board::types::BoardLayer>( layerIdx ) );
1241
1242 if( enabled.Contains( layer ) )
1243 visible.set( layer );
1244 }
1245
1246 frame()->GetBoard()->SetVisibleLayers( visible );
1249 frame()->Refresh();
1250 return Empty();
1251}
1252
1253
1256{
1257 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1258
1259 if( !documentValidation )
1260 return tl::unexpected( documentValidation.error() );
1261
1262 BoardLayerResponse response;
1263 response.set_layer(
1264 ToProtoEnum<PCB_LAYER_ID, board::types::BoardLayer>( frame()->GetActiveLayer() ) );
1265
1266 return response;
1267}
1268
1269
1272{
1273 if( std::optional<ApiResponseStatus> busy = checkForBusy() )
1274 return tl::unexpected( *busy );
1275
1276 HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
1277
1278 if( !documentValidation )
1279 return tl::unexpected( documentValidation.error() );
1280
1281 PCB_LAYER_ID layer = FromProtoEnum<PCB_LAYER_ID>( aCtx.Request.layer() );
1282
1283 if( !frame()->GetBoard()->GetEnabledLayers().Contains( layer ) )
1284 {
1285 ApiResponseStatus err;
1286 err.set_status( ApiStatusCode::AS_BAD_REQUEST );
1287 err.set_error_message( fmt::format( "Layer {} is not a valid layer for the given board",
1288 magic_enum::enum_name( layer ) ) );
1289 return tl::unexpected( err );
1290 }
1291
1292 frame()->SetActiveLayer( layer );
1293 return Empty();
1294}
1295
1296
1299{
1300 BoardEditorAppearanceSettings reply;
1301
1302 // TODO: might be nice to put all these things in one place and have it derive SERIALIZABLE
1303
1304 const PCB_DISPLAY_OPTIONS& displayOptions = frame()->GetDisplayOptions();
1305
1306 reply.set_inactive_layer_display( ToProtoEnum<HIGH_CONTRAST_MODE, InactiveLayerDisplayMode>(
1307 displayOptions.m_ContrastModeDisplay ) );
1308 reply.set_net_color_display(
1309 ToProtoEnum<NET_COLOR_MODE, NetColorDisplayMode>( displayOptions.m_NetColorMode ) );
1310
1311 reply.set_board_flip( frame()->GetCanvas()->GetView()->IsMirroredX()
1312 ? BoardFlipMode::BFM_FLIPPED_X
1313 : BoardFlipMode::BFM_NORMAL );
1314
1315 PCBNEW_SETTINGS* editorSettings = frame()->GetPcbNewSettings();
1316
1317 reply.set_ratsnest_display( ToProtoEnum<RATSNEST_MODE, RatsnestDisplayMode>(
1318 editorSettings->m_Display.m_RatsnestMode ) );
1319
1320 return reply;
1321}
1322
1323
1326{
1328 KIGFX::PCB_VIEW* view = frame()->GetCanvas()->GetView();
1329 PCBNEW_SETTINGS* editorSettings = frame()->GetPcbNewSettings();
1330 const BoardEditorAppearanceSettings& newSettings = aCtx.Request.settings();
1331
1332 options.m_ContrastModeDisplay =
1333 FromProtoEnum<HIGH_CONTRAST_MODE>( newSettings.inactive_layer_display() );
1334 options.m_NetColorMode =
1335 FromProtoEnum<NET_COLOR_MODE>( newSettings.net_color_display() );
1336
1337 bool flip = newSettings.board_flip() == BoardFlipMode::BFM_FLIPPED_X;
1338
1339 if( flip != view->IsMirroredX() )
1340 {
1341 view->SetMirror( !view->IsMirroredX(), view->IsMirroredY() );
1342 view->RecacheAllItems();
1343 }
1344
1345 editorSettings->m_Display.m_RatsnestMode =
1346 FromProtoEnum<RATSNEST_MODE>( newSettings.ratsnest_display() );
1347
1348 frame()->SetDisplayOptions( options );
1350 frame()->GetCanvas()->Refresh();
1351
1352 return Empty();
1353}
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
Definition: approximation.h:34
constexpr int ARC_HIGH_DEF
Definition: base_units.h:120
@ LAYER_CLASS_COUNT
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.
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
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 > 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)
Definition: base_screen.h:59
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]
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:79
void SwapItemData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: board_item.cpp:225
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:295
BOARD_STACKUP GetStackupOrDefault() const
Definition: board.cpp:2333
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:879
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:820
BOARD_ITEM * GetItem(const KIID &aID) const
Definition: board.cpp:1454
const ZONES & Zones() const
Definition: board.h:340
bool ResolveTextVar(wxString *token, int aDepth) const
Definition: board.cpp:436
TITLE_BLOCK & GetTitleBlock()
Definition: board.h:703
const FOOTPRINTS & Footprints() const
Definition: board.h:336
const TRACKS & Tracks() const
Definition: board.h:334
void SetVisibleLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
Definition: board.cpp:852
const wxString & GetFileName() const
Definition: board.h:332
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:937
const DRAWINGS & Drawings() const
Definition: board.h:338
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:74
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition: commit.h:92
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Modify a given item in the model.
Definition: commit.h:108
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Definition: commit.h:80
static DELETED_BOARD_ITEM * GetInstance()
Definition: board_item.h:477
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.
Definition: eda_item.h:89
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:77
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
virtual wxString GetFriendlyName() const
Definition: eda_item.cpp:332
void SetMirror(bool aMirrorX, bool aMirrorY)
Control the mirroring of the VIEW.
Definition: view.cpp:547
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
Definition: view.cpp:765
bool IsMirroredX() const
Return true if view is flipped across the X axis.
Definition: view.h:246
void RecacheAllItems()
Rebuild GAL display lists.
Definition: view.cpp:1439
bool IsMirroredY() const
Return true if view is flipped across the Y axis.
Definition: view.h:254
Definition: kiid.h:49
std::string AsStdString() const
Definition: kiid.cpp:252
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
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:314
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: netclass.cpp:134
Handle the data for a net.
Definition: netinfo.h:56
NETCLASS * GetNetClass()
Definition: netinfo.h:101
Container for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:346
NETINFO_ITEM * GetNetItem(int aNetCode) const
Definition: pad.h:54
DISPLAY_OPTIONS m_Display
static TOOL_ACTION zoneFillAll
Definition: pcb_actions.h:408
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:68
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:120
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition: pcb_actions.h:76
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.
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.
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:370
int AddItemsToSel(const TOOL_EVENT &aEvent)
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.cpp:178
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
Definition: title_block.h:107
const wxString & GetTitle() const
Definition: title_block.h:63
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
Master controller class:
Definition: tool_manager.h:62
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
Definition: tool_manager.h:235
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
Definition: common.cpp:59
#define _(s)
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:538
static const std::string KiCadPcbFileExtension
@ ID_SAVE_BOARD
Definition: id.h:74
PROJECT & Prj()
Definition: kicad.cpp:597
#define KICTL_REVERT
reverting to a previously-saved (KiCad) file.
Definition: kiway_player.h:78
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
KICOMMON_API void PackBox2(types::Box2 &aOutput, const BOX2I &aInput)
Definition: api_utils.cpp:104
KICOMMON_API std::optional< KICAD_T > TypeNameFromAny(const google::protobuf::Any &aMessage)
Definition: api_utils.cpp:32
KICOMMON_API void PackPolyLine(types::PolyLine &aOutput, const SHAPE_LINE_CHAIN &aSlc)
Definition: api_utils.cpp:117
Class to handle a set of BOARD_ITEMs.
BOARD * GetBoard()
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:105
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
@ 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:103
@ 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:107
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
@ 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:101
@ 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:104