KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_handler_common.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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <optional>
22#include <ranges>
23#include <set>
24#include <tuple>
25
28#include <build_version.h>
29#include <eda_shape.h>
30#include <eda_text.h>
31#include <gestfich.h>
33#include <google/protobuf/empty.pb.h>
34#include <paths.h>
35#include <pgm_base.h>
36#include <api/api_plugin.h>
37#include <api/api_utils.h>
41#include <wx/string.h>
42
43using namespace kiapi::common::commands;
44using namespace kiapi::common::types;
45using google::protobuf::Empty;
46
47
50{
82}
83
84
87{
88 GetVersionResponse reply;
89
90 reply.mutable_version()->set_full_version( GetBuildVersion().ToStdString() );
91
92 std::tuple<int, int, int> version = GetMajorMinorPatchTuple();
93 reply.mutable_version()->set_major( std::get<0>( version ) );
94 reply.mutable_version()->set_minor( std::get<1>( version ) );
95 reply.mutable_version()->set_patch( std::get<2>( version ) );
96
97 return reply;
98}
99
100
103{
104 wxFileName fn( wxEmptyString, wxString::FromUTF8( aCtx.Request.binary_name() ) );
105#ifdef _WIN32
106 fn.SetExt( wxT( "exe" ) );
107#endif
108
109 wxString path = FindKicadFile( fn.GetFullName() );
110 PathResponse reply;
111 reply.set_path( path.ToUTF8() );
112 return reply;
113}
114
115
116tl::expected<bool, ApiResponseStatus> API_HANDLER_COMMON::validateProject( const ProjectSpecifier& aProject,
117 bool aAllowEmpty )
118{
119 if( !aAllowEmpty && ( aProject.name().empty() || aProject.path().empty() ) )
120 {
121 ApiResponseStatus e;
122 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
123 e.set_error_message( "a project name and path must be specified" );
124 return tl::unexpected( e );
125 }
126
127 const PROJECT& prj = Pgm().GetSettingsManager().Prj();
128
129 if( !aProject.name().empty() && aProject.name() != prj.GetProjectName().utf8_string() )
130 {
131 ApiResponseStatus e;
132 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
133 e.set_error_message( fmt::format( "the requested project {} is not open", aProject.name() ) );
134 return tl::unexpected( e );
135 }
136
137 if( !aProject.path().empty() && aProject.path() != prj.GetProjectPath().utf8_string() )
138 {
139 ApiResponseStatus e;
140 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
141 e.set_error_message( fmt::format( "the requested project {} is not open at path {}",
142 aProject.name(),
143 aProject.path() ) );
144 return tl::unexpected( e );
145 }
146
147 return true;
148}
149
150
152{
153 if( tl::expected<bool, ApiResponseStatus> result = validateProject( aCtx.Request.project(), true ); !result )
154 return tl::unexpected( result.error() );
155
156 NetClassesResponse reply;
157
158 std::shared_ptr<NET_SETTINGS>& netSettings = Pgm().GetSettingsManager().Prj().GetProjectFile().m_NetSettings;
159
160 google::protobuf::Any any;
161
162 netSettings->GetDefaultNetclass()->Serialize( any );
163
164 if( !any.UnpackTo( reply.add_net_classes() ) )
165 wxFAIL_MSG( wxT( "Failed to unpack Default netclasss from internal serialization" ) );
166
167 for( const std::shared_ptr<NETCLASS>& netClass : netSettings->GetNetclasses() | std::views::values )
168 {
169 netClass->Serialize( any );
170
171 if( !any.UnpackTo( reply.add_net_classes() ) )
172 {
173 wxFAIL_MSG( wxString::Format( wxT( "Failed to unpack netclass %s from internal serialization" ),
174 netClass->GetName() ) );
175 }
176 }
177
178 return reply;
179}
180
181
183{
184 if( tl::expected<bool, ApiResponseStatus> result = validateProject( aCtx.Request.project(), true ); !result )
185 return tl::unexpected( result.error() );
186
187 std::shared_ptr<NET_SETTINGS>& netSettings = Pgm().GetSettingsManager().Prj().GetProjectFile().m_NetSettings;
188
189 std::map<wxString, std::shared_ptr<NETCLASS>> netClasses;
190 google::protobuf::Any any;
191
192 if( aCtx.Request.merge_mode() != MapMergeMode::MMM_REPLACE )
193 netClasses = netSettings->GetNetclasses();
194
195 for( const kiapi::common::project::NetClass& ncProto : aCtx.Request.net_classes() )
196 {
197 wxString name = wxString::FromUTF8( ncProto.name() );
198 bool deserialized = false;
199
200 if( any.PackFrom( ncProto ) )
201 {
202 if( name == wxT( "Default" ) )
203 {
204 deserialized = netSettings->GetDefaultNetclass()->Deserialize( any );
205 }
206 else
207 {
208 if( !netClasses.contains( name ) )
209 netClasses.insert( { name, std::make_shared<NETCLASS>( name, false ) } );
210
211 deserialized = netClasses[name]->Deserialize( any );
212 }
213 }
214
215 if( !deserialized )
216 {
217 ApiResponseStatus e;
218 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
219 e.set_error_message( fmt::format( "could not unpack netclass '{}'", name.ToUTF8().data() ) );
220 return tl::unexpected( e );
221 }
222 }
223
224 netSettings->ClearNetclasses();
225 netSettings->SetNetclasses( netClasses );
227
228 return Empty();
229}
230
231
234{
235 if( tl::expected<bool, ApiResponseStatus> result = validateProject( aCtx.Request.project() ); !result )
236 return tl::unexpected( result.error() );
237
238 std::shared_ptr<NET_SETTINGS>& netSettings = Pgm().GetSettingsManager().Prj().GetProjectFile().m_NetSettings;
239
240 NetClassAssignmentsResponse reply;
241
242 for( const auto& [netName, netclassNames] : netSettings->GetNetclassLabelAssignments() )
243 {
244 project::NetClassAssignment* assignment = reply.add_assignments();
245 assignment->set_net( netName.ToUTF8() );
246
247 for( const wxString& netclassName : netclassNames )
248 assignment->add_netclasses( netclassName.ToUTF8() );
249 }
250
251 for( const auto& [matcher, netclassName] : netSettings->GetNetclassPatternAssignments() )
252 {
253 project::NetClassPatternAssignment* pattern = reply.add_pattern_assignments();
254 pattern->set_pattern( matcher->GetPattern().ToUTF8() );
255 pattern->set_netclass( netclassName.ToUTF8() );
256 }
257
258 return reply;
259}
260
261
264{
265 if( tl::expected<bool, ApiResponseStatus> result = validateProject( aCtx.Request.project() ); !result )
266 return tl::unexpected( result.error() );
267
268 std::shared_ptr<NET_SETTINGS>& netSettings = Pgm().GetSettingsManager().Prj().GetProjectFile().m_NetSettings;
269
270 std::set<wxString, std::less<>> knownNetclasses;
271 knownNetclasses.insert( NETCLASS::Default );
272
273 for( const wxString& name : netSettings->GetNetclasses() | std::views::keys )
274 knownNetclasses.insert( name );
275
276 auto checkNetclassName =
277 [&]( const std::string& aName, const char* aKind ) -> std::optional<ApiResponseStatus>
278 {
279 if( knownNetclasses.contains( wxString::FromUTF8( aName ) ) )
280 return std::nullopt;
281
282 ApiResponseStatus e;
283 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
284 e.set_error_message( fmt::format( "unknown netclass '{}' in {} assignment", aName, aKind ) );
285 return e;
286 };
287
288 for( const project::NetClassAssignment& assignment : aCtx.Request.assignments() )
289 {
290 if( assignment.net().empty() )
291 {
292 ApiResponseStatus e;
293 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
294 e.set_error_message( "net name cannot be empty in a netclass assignment" );
295 return tl::unexpected( e );
296 }
297
298 for( const std::string& netclassName : assignment.netclasses() )
299 {
300 if( std::optional<ApiResponseStatus> err = checkNetclassName( netclassName, "net" ) )
301 return tl::unexpected( *err );
302 }
303 }
304
305 for( const project::NetClassPatternAssignment& pattern : aCtx.Request.pattern_assignments() )
306 {
307 if( pattern.pattern().empty() )
308 {
309 ApiResponseStatus e;
310 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
311 e.set_error_message( "pattern cannot be empty in a netclass pattern assignment" );
312 return tl::unexpected( e );
313 }
314
315 if( !pattern.netclass().empty() )
316 {
317 if( std::optional<ApiResponseStatus> err = checkNetclassName( pattern.netclass(), "pattern" ) )
318 return tl::unexpected( *err );
319 }
320 }
321
322 if( aCtx.Request.merge_mode() == MapMergeMode::MMM_REPLACE )
323 {
324 netSettings->ClearNetclassLabelAssignments();
325 netSettings->ClearNetclassPatternAssignments();
326 }
327
328 for( const project::NetClassAssignment& assignment : aCtx.Request.assignments() )
329 {
330 std::set<wxString> netclasses;
331
332 for( const std::string& netclassName : assignment.netclasses() )
333 netclasses.insert( wxString::FromUTF8( netclassName ) );
334
335 if( netclasses.empty() )
336 netSettings->ClearNetclassLabelAssignment( wxString::FromUTF8( assignment.net() ) );
337 else
338 netSettings->SetNetclassLabelAssignment( wxString::FromUTF8( assignment.net() ), netclasses );
339 }
340
341 for( const project::NetClassPatternAssignment& pattern : aCtx.Request.pattern_assignments() )
342 {
343 std::vector<std::pair<std::unique_ptr<EDA_COMBINED_MATCHER>, wxString>> kept;
344
345 for( auto& existing : netSettings->GetNetclassPatternAssignments() )
346 {
347 if( existing.first->GetPattern() != wxString::FromUTF8( pattern.pattern() ) )
348 kept.emplace_back( std::move( existing ) );
349 }
350
351 netSettings->SetNetclassPatternAssignments( std::move( kept ) );
352
353 if( !pattern.netclass().empty() )
354 {
355 netSettings->SetNetclassPatternAssignment( wxString::FromUTF8( pattern.pattern() ),
356 wxString::FromUTF8( pattern.netclass() ) );
357 }
358 }
359
360 netSettings->ClearAllCaches();
362
363 return Empty();
364}
365
366
371
372
374{
376 google::protobuf::Any any;
377
378 if( !any.PackFrom( aCtx.Request.text() ) || !text.Deserialize( any ) )
379 {
380 ApiResponseStatus e;
381 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
382 e.set_error_message( "Could not decode text in GetTextExtents message" );
383 return tl::unexpected( e );
384 }
385
386 types::Box2 response;
387
388 BOX2I bbox = text.GetTextBox( nullptr );
389 EDA_ANGLE angle = text.GetTextAngle();
390
391 if( !angle.IsZero() )
392 bbox = bbox.GetBoundingBoxRotated( text.GetTextPos(), text.GetTextAngle() );
393
394 response.mutable_position()->set_x_nm( bbox.GetPosition().x );
395 response.mutable_position()->set_y_nm( bbox.GetPosition().y );
396 response.mutable_size()->set_x_nm( bbox.GetSize().x );
397 response.mutable_size()->set_y_nm( bbox.GetSize().y );
398
399 return response;
400}
401
402
405{
406 GetTextAsShapesResponse reply;
407
408 for( const TextOrTextBox& textMsg : aCtx.Request.text() )
409 {
410 Text dummyText;
411 const Text* textPtr = &textMsg.text();
412
413 if( textMsg.has_textbox() )
414 {
415 dummyText.set_text( textMsg.textbox().text() );
416 dummyText.mutable_attributes()->CopyFrom( textMsg.textbox().attributes() );
417 textPtr = &dummyText;
418 }
419
421 google::protobuf::Any any;
422
423 if( !any.PackFrom( *textPtr ) || !text.Deserialize( any ) )
424 {
425 ApiResponseStatus e;
426 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
427 e.set_error_message( "Could not decode text in GetTextAsShapes message" );
428 return tl::unexpected( e );
429 }
430
431 std::shared_ptr<SHAPE_COMPOUND> shapes = text.GetEffectiveTextShape( false );
432
433 TextWithShapes* entry = reply.add_text_with_shapes();
434 entry->mutable_text()->CopyFrom( textMsg );
435
436 for( SHAPE* subshape : shapes->Shapes() )
437 {
438 EDA_SHAPE proxy( *subshape );
439 proxy.Serialize( any );
440 GraphicShape* shapeMsg = entry->mutable_shapes()->add_shapes();
441
442 if( !any.UnpackTo( shapeMsg ) )
443 wxFAIL_MSG( wxT( "Failed to unpack text-as-shapes component from internal serialization" ) );
444 }
445
446 if( textMsg.has_textbox() && textMsg.textbox().border_enabled() )
447 {
448 GraphicShape* border = entry->mutable_shapes()->add_shapes();
449 int width = (int) textMsg.textbox().attributes().stroke_width().value_nm();
450 border->mutable_attributes()->mutable_stroke()->mutable_width()->set_value_nm( width );
451 VECTOR2I tl = UnpackVector2( textMsg.textbox().top_left() );
452 VECTOR2I br = UnpackVector2( textMsg.textbox().bottom_right() );
453
454 // top
455 PackVector2( *border->mutable_segment()->mutable_start(), tl );
456 PackVector2( *border->mutable_segment()->mutable_end(), VECTOR2I( br.x, tl.y ) );
457
458 // right
459 border = entry->mutable_shapes()->add_shapes();
460 border->mutable_attributes()->mutable_stroke()->mutable_width()->set_value_nm( width );
461 PackVector2( *border->mutable_segment()->mutable_start(), VECTOR2I( br.x, tl.y ) );
462 PackVector2( *border->mutable_segment()->mutable_end(), br );
463
464 // bottom
465 border = entry->mutable_shapes()->add_shapes();
466 border->mutable_attributes()->mutable_stroke()->mutable_width()->set_value_nm( width );
467 PackVector2( *border->mutable_segment()->mutable_start(), br );
468 PackVector2( *border->mutable_segment()->mutable_end(), VECTOR2I( tl.x, br.y ) );
469
470 // left
471 border = entry->mutable_shapes()->add_shapes();
472 border->mutable_attributes()->mutable_stroke()->mutable_width()->set_value_nm( width );
473 PackVector2( *border->mutable_segment()->mutable_start(), VECTOR2I( tl.x, br.y ) );
474 PackVector2( *border->mutable_segment()->mutable_end(), tl );
475 }
476 }
477
478 return reply;
479}
480
481
484{
485 if( !aCtx.Request.has_document() || aCtx.Request.document().type() != DOCTYPE_PROJECT )
486 {
487 ApiResponseStatus e;
488 e.set_status( ApiStatusCode::AS_UNHANDLED );
489 // No error message, this is a flag that the server should try a different handler
490 return tl::unexpected( e );
491 }
492
493 ExpandTextVariablesResponse reply;
495
496 for( const std::string& textMsg : aCtx.Request.text() )
497 {
498 wxString result = ExpandTextVars( wxString::FromUTF8( textMsg ), &project, INTERNAL );
499
500 if( aCtx.Request.expand_env_vars() )
502
503 reply.add_text( result.ToUTF8() );
504 }
505
506 return reply;
507}
508
509
512{
513 wxString identifier = wxString::FromUTF8( aCtx.Request.identifier() );
514
515 if( identifier.IsEmpty() )
516 {
517 ApiResponseStatus e;
518 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
519 e.set_error_message( "plugin identifier is missing" );
520 return tl::unexpected( e );
521 }
522
523 if( !API_PLUGIN::IsValidIdentifier( identifier ) )
524 {
525 ApiResponseStatus e;
526 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
527 e.set_error_message( "plugin identifier is invalid" );
528 return tl::unexpected( e );
529 }
530
531 wxFileName path( PATHS::GetUserSettingsPath(), wxEmptyString );
532 path.AppendDir( "plugins" );
533
534 // Create the base plugins path if needed, but leave the specific plugin to create its own path
535 PATHS::EnsurePathExists( path.GetPath() );
536
537 path.AppendDir( identifier );
538
539 StringResponse reply;
540 reply.set_response( path.GetPath() );
541 return reply;
542}
543
544
547{
548 if( !aCtx.Request.has_document() || aCtx.Request.document().type() != DOCTYPE_PROJECT )
549 {
550 ApiResponseStatus e;
551 e.set_status( ApiStatusCode::AS_UNHANDLED );
552 // No error message, this is a flag that the server should try a different handler
553 return tl::unexpected( e );
554 }
555
556 if( tl::expected<bool, ApiResponseStatus> result = validateProject( aCtx.Request.document().project() );
557 !result )
558 {
559 return tl::unexpected( result.error() );
560 }
561
563
564 if( project.IsNullProject() )
565 {
566 ApiResponseStatus e;
567 e.set_status( ApiStatusCode::AS_NOT_READY );
568 e.set_error_message( "no valid project is loaded, cannot get text variables" );
569 return tl::unexpected( e );
570 }
571
572 const std::map<wxString, wxString>& vars = project.GetTextVars();
573
574 project::TextVariables reply;
575 auto map = reply.mutable_variables();
576
577 for( const auto& [key, value] : vars )
578 ( *map )[ std::string( key.ToUTF8() ) ] = value.ToUTF8();
579
580 return reply;
581}
582
583
586{
587 if( !aCtx.Request.has_document() || aCtx.Request.document().type() != DOCTYPE_PROJECT )
588 {
589 ApiResponseStatus e;
590 e.set_status( ApiStatusCode::AS_UNHANDLED );
591 // No error message, this is a flag that the server should try a different handler
592 return tl::unexpected( e );
593 }
594
595 if( tl::expected<bool, ApiResponseStatus> result = validateProject( aCtx.Request.document().project() );
596 !result )
597 {
598 return tl::unexpected( result.error() );
599 }
600
602
603 if( project.IsNullProject() )
604 {
605 ApiResponseStatus e;
606 e.set_status( ApiStatusCode::AS_NOT_READY );
607 e.set_error_message( "no valid project is loaded, cannot set text variables" );
608 return tl::unexpected( e );
609 }
610
611 const project::TextVariables& newVars = aCtx.Request.variables();
612 std::map<wxString, wxString>& vars = project.GetTextVars();
613
614 if( aCtx.Request.merge_mode() == MapMergeMode::MMM_REPLACE )
615 vars.clear();
616
617 for( const auto& [key, value] : newVars.variables() )
618 vars[wxString::FromUTF8( key )] = wxString::FromUTF8( value );
619
620 if( !Pgm().GetSettingsManager().SaveProject() )
621 {
622 ApiResponseStatus e;
623 e.set_status( ApiStatusCode::AS_INTERNAL_ERROR );
624 e.set_error_message( "failed to save project text variables" );
625 return tl::unexpected( e );
626 }
627
628 return Empty();
629}
630
631
634{
636 {
637 ApiResponseStatus e;
638 e.set_status( ApiStatusCode::AS_UNIMPLEMENTED );
639 e.set_error_message( "OpenDocument is not available in this KiCad mode" );
640 return tl::unexpected( e );
641 }
642
643 return m_openDocumentHandler( aCtx.Request );
644}
645
646
649{
651 {
652 ApiResponseStatus e;
653 e.set_status( ApiStatusCode::AS_UNIMPLEMENTED );
654 e.set_error_message( "CloseDocument is not available in this KiCad mode" );
655 return tl::unexpected( e );
656 }
657
658 return m_closeDocumentHandler( aCtx.Request );
659}
660
661
664{
666 {
667 ApiResponseStatus e;
668 e.set_status( ApiStatusCode::AS_UNIMPLEMENTED );
669 e.set_error_message( "CreateDocument is not available in this KiCad mode" );
670 return tl::unexpected( e );
671 }
672
673 return m_createDocumentHandler( aCtx.Request );
674}
675
676
678{
680 {
681 ApiResponseStatus e;
682 e.set_status( ApiStatusCode::AS_UNIMPLEMENTED );
683 e.set_error_message( "CloseAllDocuments is not available in this KiCad mode" );
684 return tl::unexpected( e );
685 }
686
687 return m_closeAllDocumentsHandler( aCtx.Request );
688}
689
690
692{
693 GetPathsResponse reply;
694
695 auto addPath = [&]( types::PathType aType, const wxString& aPath )
696 {
697 PathEntry* entry = reply.add_paths();
698 entry->set_type( aType );
699 entry->set_path( aPath.ToUTF8() );
700 };
701
702 addPath( types::PATH_USER_PLUGINS, PATHS::GetUserPluginsPath() );
703 addPath( types::PATH_USER_TEMPLATES, PATHS::GetUserTemplatesPath() );
704 addPath( types::PATH_USER_SETTINGS, PATHS::GetUserSettingsPath() );
705 addPath( types::PATH_STOCK_SYMBOLS, PATHS::GetStockSymbolsPath() );
706 addPath( types::PATH_STOCK_FOOTPRINTS, PATHS::GetStockFootprintsPath() );
707 addPath( types::PATH_STOCK_DESIGN_BLOCKS, PATHS::GetStockDesignBlocksPath() );
708 addPath( types::PATH_STOCK_3DMODELS, PATHS::GetStock3dmodelsPath() );
709 addPath( types::PATH_STOCK_TEMPLATES, PATHS::GetStockTemplatesPath() );
710
711 return reply;
712}
713
714
717{
718 if( !aCtx.Request.has_token() || aCtx.Request.token().value().empty() )
719 {
720 ApiResponseStatus e;
721 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
722 e.set_error_message( "no task token provided" );
723 return tl::unexpected( e );
724 }
725
726 std::optional<tasks::TaskStatusResponse> status =
727 API_TASK_SCHEDULER::Instance().GetStatus( aCtx.Request.token().value() );
728
729 if( !status )
730 {
731 ApiResponseStatus e;
732 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
733 e.set_error_message( fmt::format( "unknown task token {}", aCtx.Request.token().value() ) );
734 return tl::unexpected( e );
735 }
736
737 return *status;
738}
const char * name
tl::expected< T, ApiResponseStatus > HANDLER_RESULT
Definition api_handler.h:47
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
const std::tuple< int, int, int > & GetMajorMinorPatchTuple()
Get the build version numbers as a tuple.
wxString GetBuildVersion()
Get the full KiCad version string.
HANDLER_RESULT< Empty > handlePing(const HANDLER_CONTEXT< commands::Ping > &aCtx)
HANDLER_RESULT< types::Box2 > handleGetTextExtents(const HANDLER_CONTEXT< commands::GetTextExtents > &aCtx)
CLOSE_ALL_DOCUMENTS_HANDLER m_closeAllDocumentsHandler
HANDLER_RESULT< tasks::TaskStatusResponse > handleGetTaskStatus(const HANDLER_CONTEXT< tasks::GetTaskStatus > &aCtx)
HANDLER_RESULT< commands::GetTextAsShapesResponse > handleGetTextAsShapes(const HANDLER_CONTEXT< commands::GetTextAsShapes > &aCtx)
HANDLER_RESULT< commands::GetVersionResponse > handleGetVersion(const HANDLER_CONTEXT< commands::GetVersion > &aCtx)
CREATE_DOCUMENT_HANDLER m_createDocumentHandler
HANDLER_RESULT< Empty > handleCloseAllDocuments(const HANDLER_CONTEXT< commands::CloseAllDocuments > &aCtx)
HANDLER_RESULT< Empty > handleSetNetClassAssignments(const HANDLER_CONTEXT< commands::SetNetClassAssignments > &aCtx)
HANDLER_RESULT< commands::OpenDocumentResponse > handleCreateDocument(const HANDLER_CONTEXT< commands::CreateDocument > &aCtx)
HANDLER_RESULT< commands::NetClassAssignmentsResponse > handleGetNetClassAssignments(const HANDLER_CONTEXT< commands::GetNetClassAssignments > &aCtx)
HANDLER_RESULT< commands::PathResponse > handleGetKiCadBinaryPath(const HANDLER_CONTEXT< commands::GetKiCadBinaryPath > &aCtx)
HANDLER_RESULT< commands::NetClassesResponse > handleGetNetClasses(const HANDLER_CONTEXT< commands::GetNetClasses > &aCtx)
CLOSE_DOCUMENT_HANDLER m_closeDocumentHandler
OPEN_DOCUMENT_HANDLER m_openDocumentHandler
HANDLER_RESULT< Empty > handleCloseDocument(const HANDLER_CONTEXT< commands::CloseDocument > &aCtx)
HANDLER_RESULT< Empty > handleSetNetClasses(const HANDLER_CONTEXT< commands::SetNetClasses > &aCtx)
static tl::expected< bool, ApiResponseStatus > validateProject(const ProjectSpecifier &aProject, bool aAllowEmpty=false)
HANDLER_RESULT< commands::StringResponse > handleGetPluginSettingsPath(const HANDLER_CONTEXT< commands::GetPluginSettingsPath > &aCtx)
HANDLER_RESULT< commands::OpenDocumentResponse > handleOpenDocument(const HANDLER_CONTEXT< commands::OpenDocument > &aCtx)
HANDLER_RESULT< commands::ExpandTextVariablesResponse > handleExpandTextVariables(const HANDLER_CONTEXT< commands::ExpandTextVariables > &aCtx)
HANDLER_RESULT< Empty > handleSetTextVariables(const HANDLER_CONTEXT< commands::SetTextVariables > &aCtx)
HANDLER_RESULT< commands::GetPathsResponse > handleGetPaths(const HANDLER_CONTEXT< commands::GetPaths > &aCtx)
HANDLER_RESULT< project::TextVariables > handleGetTextVariables(const HANDLER_CONTEXT< commands::GetTextVariables > &aCtx)
void registerHandler(HANDLER_RESULT< ResponseType >(HandlerType::*aHandler)(const HANDLER_CONTEXT< RequestType > &), bool aAllowedDuringTask=false)
Registers an API command handler for the given message types.
void requestNetSettingsNotification()
Definition api_handler.h:93
static bool IsValidIdentifier(const wxString &aIdentifier)
std::optional< kiapi::common::tasks::TaskStatusResponse > GetStatus(const std::string &aToken) const
Get a snapshot of the task's current status.
static API_TASK_SCHEDULER & Instance()
constexpr const Vec & GetPosition() const
Definition box2.h:214
const BOX2< Vec > GetBoundingBoxRotated(const VECTOR2I &aRotCenter, const EDA_ANGLE &aAngle) const
Useful to calculate bounding box of rotated items, when rotation is not cardinal.
Definition box2.h:659
constexpr const SizeVec & GetSize() const
Definition box2.h:209
bool IsZero() const
Definition eda_angle.h:135
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
static const char Default[]
the name of the default NETCLASS
Definition netclass.h:46
static wxString GetUserPluginsPath()
Gets the user path for plugins.
Definition paths.cpp:49
static wxString GetStockSymbolsPath()
Gets the stock (install) symbols path.
Definition paths.cpp:262
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
Definition paths.cpp:71
static bool EnsurePathExists(const wxString &aPath, bool aPathToFile=false)
Attempts to create a given path if it does not exist.
Definition paths.cpp:470
static wxString GetStock3dmodelsPath()
Gets the stock (install) 3dmodels path.
Definition paths.cpp:295
static wxString GetStockTemplatesPath()
Gets the stock (install) templates path.
Definition paths.cpp:317
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
Definition paths.cpp:586
static wxString GetStockDesignBlocksPath()
Gets the stock (install) footprints path.
Definition paths.cpp:284
static wxString GetStockFootprintsPath()
Gets the stock (install) footprints path.
Definition paths.cpp:273
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here)
Container for project specific data.
Definition project.h:63
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:277
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition project.cpp:289
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:201
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
An abstract shape on 2D plane.
Definition shape.h:124
A type-safe container of any type.
Definition ki_any.h:92
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject, bool aAllowEscapes)
Replace any environment variable & text variable references with their values.
Definition common.cpp:777
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, RESOLUTION_CONTEXT aContext)
Definition common.cpp:60
@ INTERNAL
Definition common.h:96
static std::string ToStdString(const wxString &aStr)
wxString FindKicadFile(const wxString &shortname)
Search the executable file shortname in KiCad binary path and return full file name if found or short...
Definition gestfich.cpp:72
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
RequestMessageType Request
Definition api_handler.h:54
std::string path
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708