diff --git a/api/proto/board/board_commands.proto b/api/proto/board/board_commands.proto index 04ad03b2aa..bb5df9f425 100644 --- a/api/proto/board/board_commands.proto +++ b/api/proto/board/board_commands.proto @@ -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 classes = 1; +} + /* * Blocking operations */ diff --git a/api/proto/common/types/project_settings.proto b/api/proto/common/types/project_settings.proto index ba2796a6b2..5af1320464 100644 --- a/api/proto/common/types/project_settings.proto +++ b/api/proto/common/types/project_settings.proto @@ -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 diff --git a/common/netclass.cpp b/common/netclass.cpp index e9583f5900..335bbf2328 100644 --- a/common/netclass.cpp +++ b/common/netclass.cpp @@ -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(); diff --git a/pcbnew/api/api_handler_pcb.cpp b/pcbnew/api/api_handler_pcb.cpp index e8142bfe3a..f8179fb076 100644 --- a/pcbnew/api/api_handler_pcb.cpp +++ b/pcbnew/api/api_handler_pcb.cpp @@ -76,6 +76,8 @@ API_HANDLER_PCB::API_HANDLER_PCB( PCB_EDIT_FRAME* aFrame ) : registerHandler( &API_HANDLER_PCB::handleInteractiveMoveItems ); registerHandler( &API_HANDLER_PCB::handleGetNets ); + registerHandler( + &API_HANDLER_PCB::handleGetNetClassForNets ); registerHandler( &API_HANDLER_PCB::handleRefillZones ); registerHandler( @@ -830,6 +832,31 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetNets( const HANDLER_CONTE } +HANDLER_RESULT API_HANDLER_PCB::handleGetNetClassForNets( + const HANDLER_CONTEXT& 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 API_HANDLER_PCB::handleRefillZones( const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) diff --git a/pcbnew/api/api_handler_pcb.h b/pcbnew/api/api_handler_pcb.h index 80c9ed6458..618154fec7 100644 --- a/pcbnew/api/api_handler_pcb.h +++ b/pcbnew/api/api_handler_pcb.h @@ -87,6 +87,9 @@ private: HANDLER_RESULT handleGetNets( const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetNetClassForNets( + const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleRefillZones( const HANDLER_CONTEXT& aCtx ); HANDLER_RESULT handleSaveDocumentToString(