44#include <api/common/tasks.pb.h>
45#include <api/schematic/schematic_tasks.pb.h>
50using kiapi::common::tasks::StartTaskResponse;
51using kiapi::common::tasks::TaskState;
52using kiapi::common::tasks::TaskStatusResponse;
53using kiapi::common::tasks::TS_CANCELLED;
54using kiapi::common::tasks::TS_FAILED;
55using kiapi::common::tasks::TS_RUNNING;
56using kiapi::common::tasks::TS_UNKNOWN;
57using kiapi::schematic::tasks::ErcTaskResult;
58using kiapi::schematic::tasks::GetErcTaskResult;
59using kiapi::schematic::tasks::StartErcTask;
76 frame->ClearErcMarkers();
95 wxString variant =
m_schematic->GetCurrentVariant();
101 std::unique_ptr<DS_PROXY_VIEW_ITEM> drawingSheet( drawingSheetRaw );
105 std::unique_ptr<API_TASK_GUI_PROGRESS_REPORTER>
reporter;
108 reporter = std::make_unique<API_TASK_GUI_PROGRESS_REPORTER>(
frame,
_(
"Running ERC" ), 1, 0 );
117 frame->RefreshErcMarkers();
122 void FillStatus( TaskStatusResponse& aStatus )
const override
141 std::vector<SCH_MARKER*> markers;
147 for(
SCH_ITEM* item : screen->Items() )
150 markers.push_back(
static_cast<SCH_MARKER*
>( item ) );
154 std::stable_sort( markers.begin(), markers.end(),
157 auto rank = []( SEVERITY aSeverity )
159 return aSeverity == RPT_SEVERITY_IGNORE
160 || aSeverity == RPT_SEVERITY_DEBUG
162 : static_cast<int>( aSeverity );
173 kiapi::schematic::ErcMarker markerMsg;
175 *
m_result.add_violations() = std::move( markerMsg );
180 int code = item.get().GetErrorCode();
201 if( !documentValidation )
202 return tl::unexpected( documentValidation.error() );
204 if( std::optional<ApiResponseStatus> busy =
checkForBusy() )
205 return tl::unexpected( *busy );
212 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
213 e.set_error_message(
"no schematic is open" );
214 return tl::unexpected( e );
217 auto task = std::make_shared<API_HANDLER_SCH::ERC_TASK>(
this,
schematic );
221 if( !token.has_value() )
224 e.set_status( ApiStatusCode::AS_BUSY );
225 e.set_error_message(
"another task is already running" );
226 return tl::unexpected( e );
229 StartTaskResponse response;
230 response.mutable_token()->set_value( *token );
237 if( !aCtx.
Request.has_token() || aCtx.
Request.token().value().empty() )
240 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
241 e.set_error_message(
"no task token provided" );
242 return tl::unexpected( e );
250 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
251 e.set_error_message( fmt::format(
"unknown task token {}", aCtx.
Request.token().value() ) );
252 return tl::unexpected( e );
255 if( status->state() == TS_RUNNING )
258 e.set_status( ApiStatusCode::AS_BUSY );
259 e.set_error_message(
"the ERC task is still running" );
260 return tl::unexpected( e );
263 if( status->state() == TS_FAILED || status->state() == TS_CANCELLED )
266 e.set_status( ApiStatusCode::AS_INTERNAL_ERROR );
267 e.set_error_message( status->error_message().empty() ? std::string(
"ERC task failed" )
268 : status->error_message() );
269 return tl::unexpected( e );
277 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
278 e.set_error_message( fmt::format(
"no completed task with token {}", aCtx.
Request.token().value() ) );
279 return tl::unexpected( e );
287 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
288 e.set_error_message(
"task is not an ERC task" );
289 return tl::unexpected( e );
tl::expected< T, ApiResponseStatus > HANDLER_RESULT
constexpr EDA_IU_SCALE schIUScale
HANDLER_RESULT< bool > validateDocument(const DocumentSpecifier &aDocument)
virtual std::optional< ApiResponseStatus > checkForBusy()
Checks if the editor can accept commands.
API_HANDLER_SCH * m_handler
std::string m_errorMessage
ErcTaskResult Result() const
ERC_TASK(API_HANDLER_SCH *aHandler, SCHEMATIC *aSchematic)
void FillStatus(TaskStatusResponse &aStatus) const override
void Run() override
The task runner; called on the main thread.
HANDLER_RESULT< kiapi::schematic::tasks::ErcTaskResult > handleGetErcTaskResult(const HANDLER_CONTEXT< kiapi::schematic::tasks::GetErcTaskResult > &aCtx)
SCHEMATIC * schematic() const
API_HANDLER_SCH(SCH_EDIT_FRAME *aFrame)
HANDLER_RESULT< kiapi::common::tasks::StartTaskResponse > handleStartErcTask(const HANDLER_CONTEXT< kiapi::schematic::tasks::StartErcTask > &aCtx)
SCH_EDIT_FRAME * frame() const
SCH_CONTEXT * context() const
std::shared_ptr< API_TASK > GetFinishedTask(const std::string &aToken) const
Look up a task that has finished, for result retrieval.
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()
std::optional< std::string > StartTask(const std::shared_ptr< API_TASK > &aTask, const wxString &aDescription)
Register a new task and begin running it.
void SetSheetPath(const std::string &aSheetPath)
Set the sheet path displayed in the title block.
void SetSheetCount(int aSheetCount)
Change the sheet-count number displayed in the title block.
void SetVariantName(const std::string &aVariant)
Set the current variant name and description to be shown on the drawing sheet.
void SetVariantDesc(const std::string &aVariantDesc)
void SetPageNumber(const std::string &aPageNumber)
Change the page number displayed in the title block.
void SetSheetName(const std::string &aSheetName)
Set the sheet name displayed in the title block.
void SetPageBorderColorLayer(int aLayerId)
Override the layer used to pick the color of the page border (normally LAYER_GRID)
void SetIsFirstPage(bool aIsFirstPage)
Change if this is first page.
void SetFileName(const std::string &aFileName)
Set the file name displayed in the title block.
void SetColorLayer(int aLayerId)
Can be used to override which layer ID is used for drawing sheet item colors.
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
SEVERITY GetSeverity(int aErrorCode) const
Runs the electrical rules checks and adds a SCH_MARKER for each violation.
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
void AsyncLoad()
Loads all available libraries for this adapter type in the background.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
Holds all the data relating to one schematic.
ERC_SETTINGS & ErcSettings() const
virtual SCHEMATIC * GetSchematic() const =0
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
SEVERITY GetSeverity() const override
static void ToProto(kiapi::schematic::ErcMarker &aMsg, const SCH_MARKER &aMarker)
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
@ LAYER_SCHEMATIC_DRAWINGSHEET
@ LAYER_SCHEMATIC_PAGE_LIMITS
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
RequestMessageType Request
IbisParser parser & reporter