mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 19:03:45 +00:00
API: Add board origin setter/getter
See https://gitlab.com/kicad/code/kicad-python/-/issues/20
This commit is contained in:
parent
72411af9de
commit
5cec2fac9d
api/proto/board
include
pcbnew
@ -58,6 +58,30 @@ message GraphicsDefaultsResponse
|
||||
kiapi.board.GraphicsDefaults defaults = 1;
|
||||
}
|
||||
|
||||
enum BoardOriginType
|
||||
{
|
||||
BOT_UNKNOWN = 0;
|
||||
BOT_GRID = 1;
|
||||
BOT_DRILL = 2;
|
||||
}
|
||||
|
||||
// Returns a Vector2 with the specified origin point
|
||||
message GetBoardOrigin
|
||||
{
|
||||
kiapi.common.types.DocumentSpecifier board = 1;
|
||||
|
||||
BoardOriginType type = 2;
|
||||
}
|
||||
|
||||
message SetBoardOrigin
|
||||
{
|
||||
kiapi.common.types.DocumentSpecifier board = 1;
|
||||
|
||||
BoardOriginType type = 2;
|
||||
|
||||
kiapi.common.types.Vector2 origin = 3;
|
||||
}
|
||||
|
||||
/*
|
||||
* Net management
|
||||
*/
|
||||
|
@ -670,10 +670,10 @@ public:
|
||||
int GetLayerClass( PCB_LAYER_ID aLayer ) const;
|
||||
|
||||
void SetAuxOrigin( const VECTOR2I& aOrigin ) { m_auxOrigin = aOrigin; }
|
||||
const VECTOR2I& GetAuxOrigin() { return m_auxOrigin; }
|
||||
const VECTOR2I& GetAuxOrigin() const { return m_auxOrigin; }
|
||||
|
||||
void SetGridOrigin( const VECTOR2I& aOrigin ) { m_gridOrigin = aOrigin; }
|
||||
const VECTOR2I& GetGridOrigin() { return m_gridOrigin; }
|
||||
const VECTOR2I& GetGridOrigin() const { return m_gridOrigin; }
|
||||
|
||||
void SetDefaultMasterPad();
|
||||
|
||||
|
@ -82,6 +82,8 @@ API_HANDLER_PCB::API_HANDLER_PCB( PCB_EDIT_FRAME* aFrame ) :
|
||||
&API_HANDLER_PCB::handleGetTitleBlockInfo );
|
||||
registerHandler<ExpandTextVariables, ExpandTextVariablesResponse>(
|
||||
&API_HANDLER_PCB::handleExpandTextVariables );
|
||||
registerHandler<GetBoardOrigin, types::Vector2>( &API_HANDLER_PCB::handleGetBoardOrigin );
|
||||
registerHandler<SetBoardOrigin, Empty>( &API_HANDLER_PCB::handleSetBoardOrigin );
|
||||
|
||||
registerHandler<InteractiveMoveItems, Empty>( &API_HANDLER_PCB::handleInteractiveMoveItems );
|
||||
registerHandler<GetNets, NetsResponse>( &API_HANDLER_PCB::handleGetNets );
|
||||
@ -869,6 +871,92 @@ HANDLER_RESULT<GraphicsDefaultsResponse> API_HANDLER_PCB::handleGetGraphicsDefau
|
||||
}
|
||||
|
||||
|
||||
HANDLER_RESULT<types::Vector2> API_HANDLER_PCB::handleGetBoardOrigin(
|
||||
const HANDLER_CONTEXT<GetBoardOrigin>& aCtx )
|
||||
{
|
||||
if( HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
|
||||
!documentValidation )
|
||||
{
|
||||
return tl::unexpected( documentValidation.error() );
|
||||
}
|
||||
|
||||
VECTOR2I origin;
|
||||
const BOARD_DESIGN_SETTINGS& settings = frame()->GetBoard()->GetDesignSettings();
|
||||
|
||||
switch( aCtx.Request.type() )
|
||||
{
|
||||
case BOT_GRID:
|
||||
origin = settings.GetGridOrigin();
|
||||
break;
|
||||
|
||||
case BOT_DRILL:
|
||||
origin = settings.GetAuxOrigin();
|
||||
break;
|
||||
|
||||
default:
|
||||
case BOT_UNKNOWN:
|
||||
{
|
||||
ApiResponseStatus e;
|
||||
e.set_status( ApiStatusCode::AS_BAD_REQUEST );
|
||||
e.set_error_message( "Unexpected origin type" );
|
||||
return tl::unexpected( e );
|
||||
}
|
||||
}
|
||||
|
||||
types::Vector2 reply;
|
||||
PackVector2( reply, origin );
|
||||
return reply;
|
||||
}
|
||||
|
||||
HANDLER_RESULT<Empty> API_HANDLER_PCB::handleSetBoardOrigin(
|
||||
const HANDLER_CONTEXT<SetBoardOrigin>& aCtx )
|
||||
{
|
||||
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
|
||||
return tl::unexpected( *busy );
|
||||
|
||||
if( HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
|
||||
!documentValidation )
|
||||
{
|
||||
return tl::unexpected( documentValidation.error() );
|
||||
}
|
||||
|
||||
BOARD_DESIGN_SETTINGS& settings = frame()->GetBoard()->GetDesignSettings();
|
||||
VECTOR2I origin = UnpackVector2( aCtx.Request.origin() );
|
||||
|
||||
switch( aCtx.Request.type() )
|
||||
{
|
||||
case BOT_GRID:
|
||||
settings.SetGridOrigin( origin );
|
||||
frame()->Refresh();
|
||||
break;
|
||||
|
||||
case BOT_DRILL:
|
||||
{
|
||||
PCB_EDIT_FRAME* f = frame();
|
||||
|
||||
frame()->CallAfter( [f, origin]()
|
||||
{
|
||||
TOOL_MANAGER* mgr = f->GetToolManager();
|
||||
mgr->RunAction( PCB_ACTIONS::drillSetOrigin, origin );
|
||||
f->Refresh();
|
||||
} );
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
case BOT_UNKNOWN:
|
||||
{
|
||||
ApiResponseStatus e;
|
||||
e.set_status( ApiStatusCode::AS_BAD_REQUEST );
|
||||
e.set_error_message( "Unexpected origin type" );
|
||||
return tl::unexpected( e );
|
||||
}
|
||||
}
|
||||
|
||||
return Empty();
|
||||
}
|
||||
|
||||
|
||||
HANDLER_RESULT<GetBoundingBoxResponse> API_HANDLER_PCB::handleGetBoundingBox(
|
||||
const HANDLER_CONTEXT<GetBoundingBox>& aCtx )
|
||||
{
|
||||
@ -913,10 +1001,11 @@ HANDLER_RESULT<GetBoundingBoxResponse> API_HANDLER_PCB::handleGetBoundingBox(
|
||||
HANDLER_RESULT<PadShapeAsPolygonResponse> API_HANDLER_PCB::handleGetPadShapeAsPolygon(
|
||||
const HANDLER_CONTEXT<GetPadShapeAsPolygon>& aCtx )
|
||||
{
|
||||
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
|
||||
|
||||
if( !documentValidation )
|
||||
if( HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
|
||||
!documentValidation )
|
||||
{
|
||||
return tl::unexpected( documentValidation.error() );
|
||||
}
|
||||
|
||||
PadShapeAsPolygonResponse response;
|
||||
PCB_LAYER_ID layer = FromProtoEnum<PCB_LAYER_ID, board::types::BoardLayer>( aCtx.Request.layer() );
|
||||
|
@ -92,6 +92,11 @@ private:
|
||||
HANDLER_RESULT<GraphicsDefaultsResponse> handleGetGraphicsDefaults(
|
||||
const HANDLER_CONTEXT<GetGraphicsDefaults>& aCtx );
|
||||
|
||||
HANDLER_RESULT<types::Vector2> handleGetBoardOrigin(
|
||||
const HANDLER_CONTEXT<GetBoardOrigin>& aCtx );
|
||||
|
||||
HANDLER_RESULT<Empty> handleSetBoardOrigin( const HANDLER_CONTEXT<SetBoardOrigin>& aCtx );
|
||||
|
||||
HANDLER_RESULT<commands::GetBoundingBoxResponse> handleGetBoundingBox(
|
||||
const HANDLER_CONTEXT<commands::GetBoundingBox>& aCtx );
|
||||
|
||||
|
@ -1650,6 +1650,14 @@ int BOARD_EDITOR_CONTROL::DrillOrigin( const TOOL_EVENT& aEvent )
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( aEvent.IsAction( &PCB_ACTIONS::drillSetOrigin ) )
|
||||
{
|
||||
VECTOR2I origin = aEvent.Parameter<VECTOR2I>();
|
||||
m_frame->SaveCopyInUndoList( m_placeOrigin.get(), UNDO_REDO::GRIDORIGIN );
|
||||
DoSetDrillOrigin( getView(), m_frame, m_placeOrigin.get(), origin );
|
||||
return 0;
|
||||
}
|
||||
|
||||
PCB_PICKER_TOOL* picker = m_toolMgr->GetTool<PCB_PICKER_TOOL>();
|
||||
|
||||
// Deactivate other tools; particularly important if another PICKER is currently running
|
||||
@ -1719,6 +1727,7 @@ void BOARD_EDITOR_CONTROL::setTransitions()
|
||||
Go( &BOARD_EDITOR_CONTROL::PlaceFootprint, PCB_ACTIONS::placeFootprint.MakeEvent() );
|
||||
Go( &BOARD_EDITOR_CONTROL::DrillOrigin, PCB_ACTIONS::drillOrigin.MakeEvent() );
|
||||
Go( &BOARD_EDITOR_CONTROL::DrillOrigin, PCB_ACTIONS::drillResetOrigin.MakeEvent() );
|
||||
Go( &BOARD_EDITOR_CONTROL::DrillOrigin, PCB_ACTIONS::drillSetOrigin.MakeEvent() );
|
||||
|
||||
Go( &BOARD_EDITOR_CONTROL::EditFpInFpEditor, PCB_ACTIONS::editFpInFpEditor.MakeEvent() );
|
||||
Go( &BOARD_EDITOR_CONTROL::EditFpInFpEditor, PCB_ACTIONS::editLibFpInFpEditor.MakeEvent() );
|
||||
|
@ -1153,6 +1153,11 @@ TOOL_ACTION PCB_ACTIONS::drillResetOrigin( TOOL_ACTION_ARGS()
|
||||
.LegacyHotkeyName( "Reset Drill Origin" )
|
||||
.FriendlyName( _( "Reset Drill Origin" ) ) );
|
||||
|
||||
TOOL_ACTION PCB_ACTIONS::drillSetOrigin( TOOL_ACTION_ARGS()
|
||||
.Name( "pcbnew.EditorControl.drillSetOrigin" )
|
||||
.Scope( AS_CONTEXT )
|
||||
.Parameter( VECTOR2I() ) );
|
||||
|
||||
TOOL_ACTION PCB_ACTIONS::toggleLock( TOOL_ACTION_ARGS()
|
||||
.Name( "pcbnew.EditorControl.toggleLock" )
|
||||
.Scope( AS_GLOBAL )
|
||||
|
@ -541,7 +541,7 @@ public:
|
||||
static TOOL_ACTION measureTool;
|
||||
static TOOL_ACTION drillOrigin;
|
||||
static TOOL_ACTION drillResetOrigin;
|
||||
static TOOL_ACTION placeFileOrigin;
|
||||
static TOOL_ACTION drillSetOrigin;
|
||||
static TOOL_ACTION appendBoard;
|
||||
static TOOL_ACTION showEeschema;
|
||||
static TOOL_ACTION boardStatistics;
|
||||
|
Loading…
Reference in New Issue
Block a user