mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-13 17:53:11 +02:00
Merge branch 'drc_inject' into 'master'
ADDED: API for injecting arbitrary DRC errors/warn Closes #21727 See merge request kicad/code/kicad!2309
This commit is contained in:
commit
c04e2e8177
@ -225,6 +225,34 @@ message PadstackPresenceResponse
|
||||
repeated PadstackPresenceEntry entries = 1;
|
||||
}
|
||||
|
||||
// DRC markers
|
||||
|
||||
enum DrcSeverity
|
||||
{
|
||||
DRS_UNKNOWN = 0;
|
||||
DRS_WARNING = 1;
|
||||
DRS_ERROR = 2;
|
||||
}
|
||||
|
||||
// Returns InjectDrcErrorResponse
|
||||
message InjectDrcError
|
||||
{
|
||||
kiapi.common.types.DocumentSpecifier board = 1;
|
||||
|
||||
DrcSeverity severity = 2;
|
||||
|
||||
string message = 3;
|
||||
|
||||
kiapi.common.types.Vector2 position = 4;
|
||||
|
||||
repeated kiapi.common.types.KIID items = 5;
|
||||
}
|
||||
|
||||
message InjectDrcErrorResponse
|
||||
{
|
||||
kiapi.common.types.KIID marker = 1;
|
||||
}
|
||||
|
||||
// PCB editor commands
|
||||
|
||||
// returns BoardLayers
|
||||
|
@ -38,6 +38,9 @@
|
||||
#include <pcb_textbox.h>
|
||||
#include <pcb_track.h>
|
||||
#include <pcbnew_id.h>
|
||||
#include <pcb_marker.h>
|
||||
#include <drc/drc_item.h>
|
||||
#include <layer_ids.h>
|
||||
#include <project.h>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <tools/pcb_actions.h>
|
||||
@ -46,6 +49,7 @@
|
||||
|
||||
#include <api/common/types/base_types.pb.h>
|
||||
#include <widgets/appearance_controls.h>
|
||||
#include <widgets/report_severity.h>
|
||||
|
||||
using namespace kiapi::common::commands;
|
||||
using types::CommandStatus;
|
||||
@ -108,6 +112,8 @@ API_HANDLER_PCB::API_HANDLER_PCB( PCB_EDIT_FRAME* aFrame ) :
|
||||
&API_HANDLER_PCB::handleGetBoardEditorAppearanceSettings );
|
||||
registerHandler<SetBoardEditorAppearanceSettings, Empty>(
|
||||
&API_HANDLER_PCB::handleSetBoardEditorAppearanceSettings );
|
||||
registerHandler<InjectDrcError, InjectDrcErrorResponse>(
|
||||
&API_HANDLER_PCB::handleInjectDrcError );
|
||||
}
|
||||
|
||||
|
||||
@ -1581,3 +1587,46 @@ HANDLER_RESULT<Empty> API_HANDLER_PCB::handleSetBoardEditorAppearanceSettings(
|
||||
|
||||
return Empty();
|
||||
}
|
||||
|
||||
|
||||
HANDLER_RESULT<InjectDrcErrorResponse> API_HANDLER_PCB::handleInjectDrcError(
|
||||
const HANDLER_CONTEXT<InjectDrcError>& aCtx )
|
||||
{
|
||||
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
|
||||
return tl::unexpected( *busy );
|
||||
|
||||
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
|
||||
|
||||
if( !documentValidation )
|
||||
return tl::unexpected( documentValidation.error() );
|
||||
|
||||
SEVERITY severity = FromProtoEnum<SEVERITY>( aCtx.Request.severity() );
|
||||
int layer = severity == RPT_SEVERITY_WARNING ? LAYER_DRC_WARNING : LAYER_DRC_ERROR;
|
||||
int code = severity == RPT_SEVERITY_WARNING ? DRCE_GENERIC_WARNING : DRCE_GENERIC_ERROR;
|
||||
|
||||
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( code );
|
||||
|
||||
drcItem->SetErrorMessage( wxString::FromUTF8( aCtx.Request.message() ) );
|
||||
|
||||
RC_ITEM::KIIDS ids;
|
||||
|
||||
for( const auto& id : aCtx.Request.items() )
|
||||
ids.emplace_back( KIID( id.value() ) );
|
||||
|
||||
if( !ids.empty() )
|
||||
drcItem->SetItems( ids );
|
||||
|
||||
const auto& pos = aCtx.Request.position();
|
||||
VECTOR2I position( static_cast<int>( pos.x_nm() ), static_cast<int>( pos.y_nm() ) );
|
||||
|
||||
PCB_MARKER* marker = new PCB_MARKER( drcItem, position, layer );
|
||||
|
||||
COMMIT* commit = getCurrentCommit( aCtx.ClientName );
|
||||
commit->Add( marker );
|
||||
commit->Push( wxS( "API injected DRC marker" ) );
|
||||
|
||||
InjectDrcErrorResponse response;
|
||||
response.mutable_marker()->set_value( marker->GetUUID().AsStdString() );
|
||||
|
||||
return response;
|
||||
}
|
||||
|
@ -145,6 +145,9 @@ private:
|
||||
HANDLER_RESULT<Empty> handleSetBoardEditorAppearanceSettings(
|
||||
const HANDLER_CONTEXT<SetBoardEditorAppearanceSettings>& aCtx );
|
||||
|
||||
HANDLER_RESULT<InjectDrcErrorResponse> handleInjectDrcError(
|
||||
const HANDLER_CONTEXT<InjectDrcError>& aCtx );
|
||||
|
||||
protected:
|
||||
std::unique_ptr<COMMIT> createCommit() override;
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <api/board/board_types.pb.h>
|
||||
#include <api/board/board_commands.pb.h>
|
||||
#include <wx/wx.h>
|
||||
#include <widgets/report_severity.h>
|
||||
|
||||
#include <board_stackup_manager/board_stackup.h>
|
||||
#include <padstack.h>
|
||||
@ -35,6 +36,7 @@
|
||||
// Adding something new here? Add it to test_api_enums.cpp!
|
||||
|
||||
using namespace kiapi::board;
|
||||
using namespace kiapi::board::commands;
|
||||
|
||||
template<>
|
||||
types::PadType ToProtoEnum( PAD_ATTRIB aValue )
|
||||
@ -823,4 +825,31 @@ BOARD_STACKUP_ITEM_TYPE FromProtoEnum( BoardStackupLayerType aValue )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
DrcSeverity ToProtoEnum( SEVERITY aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case RPT_SEVERITY_WARNING: return DrcSeverity::DRS_WARNING;
|
||||
case RPT_SEVERITY_ERROR: return DrcSeverity::DRS_ERROR;
|
||||
|
||||
default:
|
||||
return DrcSeverity::DRS_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
SEVERITY FromProtoEnum( DrcSeverity aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case DrcSeverity::DRS_WARNING: return RPT_SEVERITY_WARNING;
|
||||
case DrcSeverity::DRS_ERROR: return RPT_SEVERITY_ERROR;
|
||||
case DrcSeverity::DRS_UNKNOWN:
|
||||
default: return RPT_SEVERITY_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// Adding something new here? Add it to test_api_enums.cpp!
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <font/text_attributes.h>
|
||||
#include <layer_ids.h>
|
||||
#include <stroke_params.h>
|
||||
#include <widgets/report_severity.h>
|
||||
|
||||
// Board-specific
|
||||
#include <api/board/board_types.pb.h>
|
||||
@ -267,4 +268,9 @@ BOOST_AUTO_TEST_CASE( BoardStackupLayerType )
|
||||
testEnums<BOARD_STACKUP_ITEM_TYPE, kiapi::board::BoardStackupLayerType>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( DrcSeverity )
|
||||
{
|
||||
testEnums<SEVERITY, kiapi::board::commands::DrcSeverity>( true );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
x
Reference in New Issue
Block a user