mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-18 19:59:18 +00:00
API: Add GetNetClassForNets; handle implicit netclasses
This commit is contained in:
parent
151b1141f7
commit
d8b8d8aa3c
api/proto
common
pcbnew/api
@ -24,6 +24,7 @@ package kiapi.board.commands;
|
||||
|
||||
import "common/types/base_types.proto";
|
||||
import "common/types/enums.proto";
|
||||
import "common/types/project_settings.proto";
|
||||
import "board/board.proto";
|
||||
import "board/board_types.proto";
|
||||
|
||||
@ -104,6 +105,22 @@ message GetItemsByNetClass
|
||||
repeated string net_classes = 3;
|
||||
}
|
||||
|
||||
// A net may be part of multiple classes that have a priority ordering, which will result in a
|
||||
// composite "effective" netclass containing the merged/overridden properties of all the constituent
|
||||
// netclasses it contains. This message retrieves this effective netclass for a net or list of
|
||||
// nets.
|
||||
// Returns NetClassForNetsResponse
|
||||
message GetNetClassForNets
|
||||
{
|
||||
repeated kiapi.board.types.Net net = 1;
|
||||
}
|
||||
|
||||
message NetClassForNetsResponse
|
||||
{
|
||||
// Map of net name to netclass info
|
||||
map<string, kiapi.common.project.NetClass> classes = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Blocking operations
|
||||
*/
|
||||
|
@ -59,15 +59,30 @@ message NetClassSchematicSettings
|
||||
optional kiapi.common.types.StrokeLineStyle line_style = 4;
|
||||
}
|
||||
|
||||
enum NetClassType
|
||||
{
|
||||
NCT_UNKNOWN = 0;
|
||||
// An explicitly-defined netclass, created by the user and saved in the project file
|
||||
NCT_EXPLICIT = 1;
|
||||
// An implicit (effective) netclass, made up of multiple explicit netclasses
|
||||
NCT_IMPLICIT = 2;
|
||||
}
|
||||
|
||||
message NetClass
|
||||
{
|
||||
// The name of the netclass (the literal string "Default" for the default netclass)
|
||||
// May be empty for composite netclasses
|
||||
string name = 1;
|
||||
|
||||
optional int32 priority = 2;
|
||||
|
||||
optional NetClassBoardSettings board = 3;
|
||||
optional NetClassSchematicSettings schematic = 4;
|
||||
|
||||
NetClassType type = 5;
|
||||
|
||||
// If this is a composite netclass, a list of the names of the "real" netclasses that make it up
|
||||
repeated string constituents = 6;
|
||||
}
|
||||
|
||||
message TextVariables
|
||||
|
@ -137,6 +137,11 @@ void NETCLASS::Serialize( google::protobuf::Any &aContainer ) const
|
||||
nc.set_name( m_Name.ToUTF8() );
|
||||
nc.set_priority( m_Priority );
|
||||
|
||||
nc.set_type( m_constituents.empty() ? project::NCT_EXPLICIT : project::NCT_IMPLICIT );
|
||||
|
||||
for( NETCLASS* member : m_constituents )
|
||||
nc.add_constituents( member->GetName() );
|
||||
|
||||
project::NetClassBoardSettings* board = nc.mutable_board();
|
||||
|
||||
if( m_Clearance )
|
||||
@ -204,6 +209,12 @@ bool NETCLASS::Deserialize( const google::protobuf::Any &aContainer )
|
||||
m_Name = wxString::FromUTF8( nc.name() );
|
||||
m_Priority = nc.priority();
|
||||
|
||||
// We don't allow creating implicit classes directly
|
||||
if( nc.type() == project::NCT_IMPLICIT )
|
||||
return false;
|
||||
|
||||
SetConstituentNetclasses( {} );
|
||||
|
||||
if( nc.board().has_clearance() )
|
||||
m_Clearance = nc.board().clearance().value_nm();
|
||||
|
||||
|
@ -76,6 +76,8 @@ API_HANDLER_PCB::API_HANDLER_PCB( PCB_EDIT_FRAME* aFrame ) :
|
||||
|
||||
registerHandler<InteractiveMoveItems, Empty>( &API_HANDLER_PCB::handleInteractiveMoveItems );
|
||||
registerHandler<GetNets, NetsResponse>( &API_HANDLER_PCB::handleGetNets );
|
||||
registerHandler<GetNetClassForNets, NetClassForNetsResponse>(
|
||||
&API_HANDLER_PCB::handleGetNetClassForNets );
|
||||
registerHandler<RefillZones, Empty>( &API_HANDLER_PCB::handleRefillZones );
|
||||
|
||||
registerHandler<SaveDocumentToString, SavedDocumentResponse>(
|
||||
@ -830,6 +832,31 @@ HANDLER_RESULT<NetsResponse> API_HANDLER_PCB::handleGetNets( const HANDLER_CONTE
|
||||
}
|
||||
|
||||
|
||||
HANDLER_RESULT<NetClassForNetsResponse> API_HANDLER_PCB::handleGetNetClassForNets(
|
||||
const HANDLER_CONTEXT<GetNetClassForNets>& aCtx )
|
||||
{
|
||||
NetClassForNetsResponse response;
|
||||
|
||||
BOARD* board = frame()->GetBoard();
|
||||
NETINFO_LIST nets = board->GetNetInfo();
|
||||
google::protobuf::Any any;
|
||||
|
||||
for( const board::types::Net& net : aCtx.Request.net() )
|
||||
{
|
||||
NETINFO_ITEM* netInfo = nets.GetNetItem( wxString::FromUTF8( net.name() ) );
|
||||
|
||||
if( !netInfo )
|
||||
continue;
|
||||
|
||||
netInfo->GetNetClass()->Serialize( any );
|
||||
auto [pair, rc] = response.mutable_classes()->insert( { net.name(), {} } );
|
||||
any.UnpackTo( &pair->second );
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
HANDLER_RESULT<Empty> API_HANDLER_PCB::handleRefillZones( const HANDLER_CONTEXT<RefillZones>& aCtx )
|
||||
{
|
||||
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
|
||||
|
@ -87,6 +87,9 @@ private:
|
||||
|
||||
HANDLER_RESULT<NetsResponse> handleGetNets( const HANDLER_CONTEXT<GetNets>& aCtx );
|
||||
|
||||
HANDLER_RESULT<NetClassForNetsResponse> handleGetNetClassForNets(
|
||||
const HANDLER_CONTEXT<GetNetClassForNets>& aCtx );
|
||||
|
||||
HANDLER_RESULT<Empty> handleRefillZones( const HANDLER_CONTEXT<RefillZones>& aCtx );
|
||||
|
||||
HANDLER_RESULT<commands::SavedDocumentResponse> handleSaveDocumentToString(
|
||||
|
Loading…
Reference in New Issue
Block a user