mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 17:53:45 +00:00
API: Add some board editor appearance settings
Fixes https://gitlab.com/kicad/code/kicad/-/issues/18269
This commit is contained in:
parent
c430ba63d1
commit
19c748048c
api/proto/board
pcbnew/api
qa/tests/api
@ -186,6 +186,67 @@ message SetActiveLayer
|
||||
kiapi.board.types.BoardLayer layer = 2;
|
||||
}
|
||||
|
||||
enum InactiveLayerDisplayMode
|
||||
{
|
||||
ILDM_UNKNOWN = 0;
|
||||
// Inactive layers are shown
|
||||
ILDM_NORMAL = 1;
|
||||
// Inactive layers are shown with dimmed colors
|
||||
ILDM_DIMMED = 2;
|
||||
// Inactive layers are hidden
|
||||
ILDM_HIDDEN = 3;
|
||||
}
|
||||
|
||||
enum NetColorDisplayMode
|
||||
{
|
||||
NCDM_UNKNOWN = 0;
|
||||
// Net and netclass colors are shown in the ratsnest and on all copper items
|
||||
NCDM_ALL = 1;
|
||||
// Net and netclass colors are shown in the ratsnest only
|
||||
NCDM_RATSNEST = 2;
|
||||
// Net and netclass colors are not shown
|
||||
NCDM_OFF = 3;
|
||||
}
|
||||
|
||||
enum BoardFlipMode
|
||||
{
|
||||
BFM_UNKNOWN = 0;
|
||||
// Normal ("non-flipped") mode
|
||||
BFM_NORMAL = 1;
|
||||
// "Flipped" mode, viewed from the back and mirrored around the X axis
|
||||
BFM_FLIPPED_X = 2;
|
||||
}
|
||||
|
||||
enum RatsnestDisplayMode
|
||||
{
|
||||
RDM_UNKNOWN = 0;
|
||||
// Ratsnest lines are drawn to objects even if they are on hidden layers
|
||||
RDM_ALL_LAYERS = 1;
|
||||
// Ratsnest lines are hidden when at least one endpoint is an item on a hidden layer
|
||||
RDM_VISIBLE_LAYERS = 2;
|
||||
}
|
||||
|
||||
message BoardEditorAppearanceSettings
|
||||
{
|
||||
InactiveLayerDisplayMode inactive_layer_display = 1;
|
||||
|
||||
NetColorDisplayMode net_color_display = 2;
|
||||
|
||||
BoardFlipMode board_flip = 3;
|
||||
|
||||
RatsnestDisplayMode ratsnest_display = 4;
|
||||
}
|
||||
|
||||
// Returns BoardEditorAppearanceSettings
|
||||
message GetBoardEditorAppearanceSettings
|
||||
{
|
||||
}
|
||||
|
||||
message SetBoardEditorAppearanceSettings
|
||||
{
|
||||
BoardEditorAppearanceSettings settings = 1;
|
||||
}
|
||||
|
||||
//// Interactive commands ////
|
||||
// These commands begin an interactive operation in the editor.
|
||||
// They return a response immediately, but the editor will become busy
|
||||
|
@ -88,6 +88,10 @@ API_HANDLER_PCB::API_HANDLER_PCB( PCB_EDIT_FRAME* aFrame ) :
|
||||
registerHandler<SetVisibleLayers, Empty>( &API_HANDLER_PCB::handleSetVisibleLayers );
|
||||
registerHandler<GetActiveLayer, BoardLayerResponse>( &API_HANDLER_PCB::handleGetActiveLayer );
|
||||
registerHandler<SetActiveLayer, Empty>( &API_HANDLER_PCB::handleSetActiveLayer );
|
||||
registerHandler<GetBoardEditorAppearanceSettings, BoardEditorAppearanceSettings>(
|
||||
&API_HANDLER_PCB::handleGetBoardEditorAppearanceSettings );
|
||||
registerHandler<SetBoardEditorAppearanceSettings, Empty>(
|
||||
&API_HANDLER_PCB::handleSetBoardEditorAppearanceSettings );
|
||||
}
|
||||
|
||||
|
||||
@ -1008,3 +1012,62 @@ HANDLER_RESULT<Empty> API_HANDLER_PCB::handleSetActiveLayer(
|
||||
frame()->SetActiveLayer( layer );
|
||||
return Empty();
|
||||
}
|
||||
|
||||
|
||||
HANDLER_RESULT<BoardEditorAppearanceSettings> API_HANDLER_PCB::handleGetBoardEditorAppearanceSettings(
|
||||
const HANDLER_CONTEXT<GetBoardEditorAppearanceSettings>& aCtx )
|
||||
{
|
||||
BoardEditorAppearanceSettings reply;
|
||||
|
||||
// TODO: might be nice to put all these things in one place and have it derive SERIALIZABLE
|
||||
|
||||
const PCB_DISPLAY_OPTIONS& displayOptions = frame()->GetDisplayOptions();
|
||||
|
||||
reply.set_inactive_layer_display( ToProtoEnum<HIGH_CONTRAST_MODE, InactiveLayerDisplayMode>(
|
||||
displayOptions.m_ContrastModeDisplay ) );
|
||||
reply.set_net_color_display(
|
||||
ToProtoEnum<NET_COLOR_MODE, NetColorDisplayMode>( displayOptions.m_NetColorMode ) );
|
||||
|
||||
reply.set_board_flip( frame()->GetCanvas()->GetView()->IsMirroredX()
|
||||
? BoardFlipMode::BFM_FLIPPED_X
|
||||
: BoardFlipMode::BFM_NORMAL );
|
||||
|
||||
PCBNEW_SETTINGS* editorSettings = frame()->GetPcbNewSettings();
|
||||
|
||||
reply.set_ratsnest_display( ToProtoEnum<RATSNEST_MODE, RatsnestDisplayMode>(
|
||||
editorSettings->m_Display.m_RatsnestMode ) );
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
||||
HANDLER_RESULT<Empty> API_HANDLER_PCB::handleSetBoardEditorAppearanceSettings(
|
||||
const HANDLER_CONTEXT<SetBoardEditorAppearanceSettings>& aCtx )
|
||||
{
|
||||
PCB_DISPLAY_OPTIONS options = frame()->GetDisplayOptions();
|
||||
KIGFX::PCB_VIEW* view = frame()->GetCanvas()->GetView();
|
||||
PCBNEW_SETTINGS* editorSettings = frame()->GetPcbNewSettings();
|
||||
const BoardEditorAppearanceSettings& newSettings = aCtx.Request.settings();
|
||||
|
||||
options.m_ContrastModeDisplay =
|
||||
FromProtoEnum<HIGH_CONTRAST_MODE>( newSettings.inactive_layer_display() );
|
||||
options.m_NetColorMode =
|
||||
FromProtoEnum<NET_COLOR_MODE>( newSettings.net_color_display() );
|
||||
|
||||
bool flip = newSettings.board_flip() == BoardFlipMode::BFM_FLIPPED_X;
|
||||
|
||||
if( flip != view->IsMirroredX() )
|
||||
{
|
||||
view->SetMirror( !view->IsMirroredX(), view->IsMirroredY() );
|
||||
view->RecacheAllItems();
|
||||
}
|
||||
|
||||
editorSettings->m_Display.m_RatsnestMode =
|
||||
FromProtoEnum<RATSNEST_MODE>( newSettings.ratsnest_display() );
|
||||
|
||||
frame()->SetDisplayOptions( options );
|
||||
frame()->GetCanvas()->GetView()->UpdateAllLayersColor();
|
||||
frame()->GetCanvas()->Refresh();
|
||||
|
||||
return Empty();
|
||||
}
|
||||
|
@ -104,6 +104,12 @@ private:
|
||||
HANDLER_RESULT<BoardLayerResponse> handleGetActiveLayer( const HANDLER_CONTEXT<GetActiveLayer>& aCtx );
|
||||
HANDLER_RESULT<Empty> handleSetActiveLayer( const HANDLER_CONTEXT<SetActiveLayer>& aCtx );
|
||||
|
||||
HANDLER_RESULT<BoardEditorAppearanceSettings> handleGetBoardEditorAppearanceSettings(
|
||||
const HANDLER_CONTEXT<GetBoardEditorAppearanceSettings>& aCtx );
|
||||
|
||||
HANDLER_RESULT<Empty> handleSetBoardEditorAppearanceSettings(
|
||||
const HANDLER_CONTEXT<SetBoardEditorAppearanceSettings>& aCtx );
|
||||
|
||||
protected:
|
||||
std::unique_ptr<COMMIT> createCommit() override;
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <import_export.h>
|
||||
#include <api/api_enums.h>
|
||||
#include <api/board/board_types.pb.h>
|
||||
#include <api/board/board_commands.pb.h>
|
||||
#include <wx/wx.h>
|
||||
|
||||
#include <padstack.h>
|
||||
@ -28,6 +29,7 @@
|
||||
#include <pcb_track.h>
|
||||
#include <zones.h>
|
||||
#include <zone_settings.h>
|
||||
#include <project/board_project_settings.h>
|
||||
|
||||
// Adding something new here? Add it to test_api_enums.cpp!
|
||||
|
||||
@ -668,4 +670,100 @@ DIM_UNITS_MODE FromProtoEnum( types::DimensionUnit aValue )
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
commands::InactiveLayerDisplayMode ToProtoEnum( HIGH_CONTRAST_MODE aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case HIGH_CONTRAST_MODE::NORMAL: return commands::InactiveLayerDisplayMode::ILDM_NORMAL;
|
||||
case HIGH_CONTRAST_MODE::DIMMED: return commands::InactiveLayerDisplayMode::ILDM_DIMMED;
|
||||
case HIGH_CONTRAST_MODE::HIDDEN: return commands::InactiveLayerDisplayMode::ILDM_HIDDEN;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, commands::InactiveLayerDisplayMode::ILDM_NORMAL,
|
||||
"Unhandled case in ToProtoEnum<HIGH_CONTRAST_MODE>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
HIGH_CONTRAST_MODE FromProtoEnum( commands::InactiveLayerDisplayMode aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case commands::InactiveLayerDisplayMode::ILDM_DIMMED: return HIGH_CONTRAST_MODE::DIMMED;
|
||||
case commands::InactiveLayerDisplayMode::ILDM_HIDDEN: return HIGH_CONTRAST_MODE::HIDDEN;
|
||||
case commands::InactiveLayerDisplayMode::ILDM_UNKNOWN:
|
||||
case commands::InactiveLayerDisplayMode::ILDM_NORMAL: return HIGH_CONTRAST_MODE::NORMAL;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, HIGH_CONTRAST_MODE::NORMAL,
|
||||
"Unhandled case in FromProtoEnum<commands::InactiveLayerDisplayMode>" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
commands::NetColorDisplayMode ToProtoEnum( NET_COLOR_MODE aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case NET_COLOR_MODE::ALL: return commands::NetColorDisplayMode::NCDM_ALL;
|
||||
case NET_COLOR_MODE::RATSNEST: return commands::NetColorDisplayMode::NCDM_RATSNEST;
|
||||
case NET_COLOR_MODE::OFF: return commands::NetColorDisplayMode::NCDM_OFF;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, commands::NetColorDisplayMode::NCDM_UNKNOWN,
|
||||
"Unhandled case in ToProtoEnum<NET_COLOR_MODE>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
NET_COLOR_MODE FromProtoEnum( commands::NetColorDisplayMode aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case commands::NetColorDisplayMode::NCDM_ALL: return NET_COLOR_MODE::ALL;
|
||||
case commands::NetColorDisplayMode::NCDM_OFF: return NET_COLOR_MODE::OFF;
|
||||
case commands::NetColorDisplayMode::NCDM_UNKNOWN:
|
||||
case commands::NetColorDisplayMode::NCDM_RATSNEST: return NET_COLOR_MODE::RATSNEST;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, NET_COLOR_MODE::RATSNEST,
|
||||
"Unhandled case in FromProtoEnum<commands::NetColorDisplayMode>" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
commands::RatsnestDisplayMode ToProtoEnum( RATSNEST_MODE aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case RATSNEST_MODE::ALL: return commands::RatsnestDisplayMode::RDM_ALL_LAYERS;
|
||||
case RATSNEST_MODE::VISIBLE: return commands::RatsnestDisplayMode::RDM_VISIBLE_LAYERS;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, commands::RatsnestDisplayMode::RDM_UNKNOWN,
|
||||
"Unhandled case in ToProtoEnum<RATSNEST_MODE>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
RATSNEST_MODE FromProtoEnum( commands::RatsnestDisplayMode aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case commands::RatsnestDisplayMode::RDM_VISIBLE_LAYERS: return RATSNEST_MODE::VISIBLE;
|
||||
case commands::RatsnestDisplayMode::RDM_UNKNOWN:
|
||||
case commands::RatsnestDisplayMode::RDM_ALL_LAYERS: return RATSNEST_MODE::ALL;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, RATSNEST_MODE::ALL,
|
||||
"Unhandled case in FromProtoEnum<commands::RatsnestDisplayMode>" );
|
||||
}
|
||||
}
|
||||
|
||||
// Adding something new here? Add it to test_api_enums.cpp!
|
||||
|
@ -26,16 +26,18 @@
|
||||
// Common
|
||||
#include <api/api_enums.h>
|
||||
#include <api/common/types/enums.pb.h>
|
||||
#include <api/board/board_types.pb.h>
|
||||
#include <core/typeinfo.h>
|
||||
#include <font/text_attributes.h>
|
||||
#include <layer_ids.h>
|
||||
#include <stroke_params.h>
|
||||
|
||||
// Board-specific
|
||||
#include <api/board/board_types.pb.h>
|
||||
#include <api/board/board_commands.pb.h>
|
||||
#include <padstack.h>
|
||||
#include <pcb_dimension.h>
|
||||
#include <pcb_track.h>
|
||||
#include <project/board_project_settings.h>
|
||||
#include <zones.h>
|
||||
#include <zone_settings.h>
|
||||
|
||||
@ -244,4 +246,19 @@ BOOST_AUTO_TEST_CASE( DimensionUnit )
|
||||
testEnums<DIM_UNITS_MODE, kiapi::board::types::DimensionUnit>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( InactiveLayerDisplayMode )
|
||||
{
|
||||
testEnums<HIGH_CONTRAST_MODE, kiapi::board::commands::InactiveLayerDisplayMode>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( NetColorDisplayMode )
|
||||
{
|
||||
testEnums<NET_COLOR_MODE, kiapi::board::commands::NetColorDisplayMode>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( RatsnestDisplayMode )
|
||||
{
|
||||
testEnums<RATSNEST_MODE, kiapi::board::commands::RatsnestDisplayMode>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
Reference in New Issue
Block a user