33#include <google/protobuf/any.pb.h>
34#include <api/board/board.pb.h>
155 || aDielectricPrmsIdx < 0
183 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
190 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
198 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
206 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
214 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
222 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
230 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
238 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
247 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
256 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
265 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
274 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
283 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
292 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
301 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
310 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer <
GetSublayersCount() );
458 if( !std::equal( std::begin(
m_list ), std::end(
m_list ), std::begin( aOther.
m_list ),
477 BoardStackupLayer* layer = stackup.mutable_layers()->Add();
479 layer->mutable_thickness()->set_value_nm( item->GetThickness() );
481 layer->set_enabled( item->IsEnabled() );
484 if( item->IsColorEditable() )
486 wxString colorStr = item->GetColor( 0 );
495 switch( item->GetType() )
499 layer->set_material_name(
"copper" );
506 BoardStackupDielectricLayer* dielectric = layer->mutable_dielectric();
508 const wxString& typeName = item->GetTypeName();
511 dielectric->set_type( BoardStackupDielectricType::BSDT_CORE );
513 dielectric->set_type( BoardStackupDielectricType::BSDT_PREPREG );
515 dielectric->set_type( BoardStackupDielectricType::BSDT_NONE );
517 for(
int i = 0; i < item->GetSublayersCount(); ++i )
519 BoardStackupDielectricProperties* props = dielectric->mutable_layer()->Add();
520 props->set_epsilon_r( item->GetEpsilonR( i ) );
521 props->set_loss_tangent( item->GetLossTangent( i ) );
522 props->set_material_name( item->GetMaterial( i ).ToUTF8() );
523 props->mutable_thickness()->set_value_nm( item->GetThickness( i ) );
525 props->set_thickness_locked( item->IsThicknessLocked( i ) );
527 if( item->GetSpecFreq( i ) != 0.0 )
528 props->set_spec_frequency( item->GetSpecFreq( i ) );
530 props->set_dielectric_model(
539 BoardStackupSoldermaskLayer* soldermask = layer->mutable_soldermask();
540 soldermask->set_epsilon_r( item->GetEpsilonR( 0 ) );
541 soldermask->set_loss_tangent( item->GetLossTangent( 0 ) );
542 soldermask->set_material_name( item->GetMaterial( 0 ).ToUTF8() );
543 soldermask->mutable_thickness()->set_value_nm( item->GetThickness( 0 ) );
549 BoardStackupSilkscreenLayer* silkscreen = layer->mutable_silkscreen();
550 silkscreen->set_material_name( item->GetMaterial( 0 ).ToUTF8() );
559 stackup.mutable_finish()->set_type_name(
m_FinishType.ToUTF8() );
562 BoardEdgeSettings* edge = stackup.mutable_edge();
563 edge->mutable_connector()->set_type(
565 edge->mutable_plating()->set_has_edge_plating(
m_EdgePlating );
572 kiapi::board::BoardStackup stackup;
574 aContainer.PackFrom( stackup );
581 kiapi::board::BoardStackup stackup;
583 if( !aContainer.UnpackTo( &stackup ) )
608 if( aIndex < 0 || aIndex >=
GetCount() )
622 if( item->IsThicknessEditable() && item->IsEnabled() )
624 thickness += item->GetThickness();
628 for(
int idx = 1; idx < item->GetSublayersCount(); idx++ )
630 thickness += item->GetThickness( idx );
656 if( std::ranges::none_of( stackup.
GetList(),
667 auto initial = std::ranges::find_if(
m_list,
670 return sameLayer( item, aItem );
673 if( initial !=
m_list.end() )
694 int aActiveCopperLayersCount )
707 int activeCuLayerCount = copperLayerCount;
709 if( aSettings ==
nullptr && aActiveCopperLayersCount > 0 )
710 activeCuLayerCount = aActiveCopperLayersCount;
713 int diel_thickness = brd__thickness -
719 diel_thickness /= std::max( 1, activeCuLayerCount - 1 );
721 int dielectric_idx = 0;
740 if( enabledLayer[
F_Mask] )
765 if( (dielectric_idx & 1) == 0 )
781 if( enabledLayer[
B_Mask] )
824 aFormatter->
Print(
"(stackup" );
833 layer_name.Printf( wxT(
"dielectric %d" ), item->GetDielectricLayerId() );
835 layer_name =
LSET::Name( item->GetBrdLayerId() );
837 aFormatter->
Print(
"(layer %s (type %s)",
838 aFormatter->
Quotew( layer_name ).c_str(),
839 aFormatter->
Quotew( item->GetTypeName() ).c_str() );
842 for(
int idx = 0; idx < item->GetSublayersCount(); idx++ )
845 aFormatter->
Print(
" addsublayer" );
847 if( item->IsColorEditable() &&
IsPrmSpecified( item->GetColor( idx ) ) )
849 aFormatter->
Print(
"(color %s)",
850 aFormatter->
Quotew( item->GetColor( idx ) ).c_str() );
853 if( item->IsThicknessEditable() )
855 aFormatter->
Print(
"(thickness %s",
859 aFormatter->
Print(
" locked" );
861 aFormatter->
Print(
")" );
864 if( item->HasMaterialValue( idx ) )
866 aFormatter->
Print(
"(material %s)",
867 aFormatter->
Quotew( item->GetMaterial( idx ) ).c_str() );
870 if( item->HasEpsilonRValue() && item->HasMaterialValue( idx ) )
873 if( item->HasLossTangentValue() && item->HasMaterialValue( idx ) )
875 aFormatter->
Print(
"(loss_tangent %s)",
879 if( item->HasSpecFreqValue() && item->HasMaterialValue( idx ) )
883 wxString modelToken = wxT(
"constant" );
886 modelToken = wxT(
"djordjevic_sarkar" );
888 aFormatter->
Print(
"(dielectric_model %s)", modelToken.ToStdString().c_str() );
892 aFormatter->
Print(
")" );
903 aFormatter->
Print(
"(edge_connector %s)",
910 aFormatter->
Print(
")" );
918 if( aFirstLayer == aSecondLayer )
922 if( aSecondLayer !=
B_Cu && ( aSecondLayer < aFirstLayer || aFirstLayer ==
B_Cu ) )
923 std::swap( aFirstLayer, aSecondLayer );
943 if( aFirstLayer !=
F_Cu && aFirstLayer !=
B_Cu )
953 if( aSecondLayer !=
F_Cu && aSecondLayer !=
B_Cu )
957 for(
int sublayer = 0; sublayer < item->GetSublayersCount(); sublayer++ )
959 const int subThickness = item->GetThickness( sublayer );
960 total += half ? ( subThickness / 2 ) : subThickness;
977 if( !aPrmValue.IsEmpty()
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
constexpr EDA_IU_SCALE pcbIUScale
bool IsPrmSpecified(const wxString &aPrmValue)
@ BS_ITEM_TYPE_SILKSCREEN
@ BS_ITEM_TYPE_DIELECTRIC
@ BS_ITEM_TYPE_SOLDERPASTE
@ BS_ITEM_TYPE_SOLDERMASK
Container for design settings for a BOARD object.
const LSET & GetEnabledLayers() const
Return a bit-mask of all the layers that are enabled.
int GetBoardThickness() const
The full thickness of the board including copper and masks.
BOARD_STACKUP & GetStackupDescriptor()
int GetCopperLayerCount() const
Manage one layer needed to make a physical board.
void AddDielectricPrms(int aDielectricPrmsIdx)
Add (insert) a DIELECTRIC_PRMS item to m_DielectricPrmsList all values are set to default.
DIELECTRIC_MODEL GetDielectricModel(int aDielectricSubLayer=0) const
PCB_LAYER_ID m_LayerId
the layer id (F.Cu to B.Cu, F.Silk, B.silk, F.Mask, B.Mask) and UNDEFINED_LAYER (-1) for dielectric l...
int GetSublayersCount() const
bool m_enabled
true if this stackup item must be taken in account, false to ignore it.
void SetDielectricLayerId(int aLayerId)
bool HasSpecFreqValue() const
double GetEpsilonR(int aDielectricSubLayer=0) const
wxString GetColor(int aDielectricSubLayer=0) const
bool HasEpsilonRValue() const
void SetThickness(int aThickness, int aDielectricSubLayer=0)
bool IsMaterialEditable() const
BOARD_STACKUP_ITEM_TYPE m_Type
void SetDielectricModel(DIELECTRIC_MODEL aModel, int aDielectricSubLayer=0)
bool HasMaterialValue(int aDielectricSubLayer=0) const
void SetThicknessLocked(bool aLocked, int aDielectricSubLayer=0)
wxString FormatDielectricLayerName() const
void SetSpecFreq(double aSpecFreq, int aDielectricSubLayer=0)
void SetMaterial(const wxString &aName, int aDielectricSubLayer=0)
BOARD_STACKUP_ITEM(BOARD_STACKUP_ITEM_TYPE aType)
bool HasLossTangentValue() const
PCB_LAYER_ID GetBrdLayerId() const
bool IsThicknessEditable() const
void SetLossTangent(double aTg, int aDielectricSubLayer=0)
wxString m_LayerName
name of layer as shown in layer manager. Useful to create reports
int GetThickness(int aDielectricSubLayer=0) const
void SetEnabled(bool aEnable)
std::vector< DIELECTRIC_PRMS > m_DielectricPrmsList
List of dielectric parameters usually only one item, but in complex (microwave) boards,...
static int GetMaskDefaultThickness()
wxString GetMaterial(int aDielectricSubLayer=0) const
wxString m_TypeName
type name of layer (copper, silk screen, core, prepreg ...)
void SetBrdLayerId(PCB_LAYER_ID aBrdLayerId)
void SetTypeName(const wxString &aName)
bool IsThicknessLocked(int aDielectricSubLayer=0) const
wxString FormatEpsilonR(int aDielectricSubLayer=0) const
int m_DielectricLayerId
the "layer" id for dielectric layers, from 1 (top) to 31 (bottom) (only 31 dielectric layers for 32 c...
void SetColor(const wxString &aColorName, int aDielectricSubLayer=0)
void SetEpsilonR(double aEpsilon, int aDielectricSubLayer=0)
double GetSpecFreq(int aDielectricSubLayer=0) const
void RemoveDielectricPrms(int aDielectricPrmsIdx)
Remove a DIELECTRIC_PRMS item from m_DielectricPrmsList.
int GetDielectricLayerId() const
bool operator==(const BOARD_STACKUP_ITEM &aOther) const
bool IsColorEditable() const
wxString FormatLossTangent(int aDielectricSubLayer=0) const
double GetLossTangent(int aDielectricSubLayer=0) const
static int GetCopperDefaultThickness()
void RemoveAll()
Delete all items in list and clear the list.
const std::vector< BOARD_STACKUP_ITEM * > & GetList() const
static LSET StackupAllowedBrdLayers()
bool SynchronizeWithBoard(const BOARD_DESIGN_SETTINGS *aSettings)
Synchronize the BOARD_STACKUP_ITEM* list with the board.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
bool operator==(const BOARD_STACKUP &aOther) const
int BuildBoardThicknessFromStackup() const
bool m_HasDielectricConstrains
True if some layers have impedance controlled tracks or have specific constrains for micro-wave appli...
void Add(BOARD_STACKUP_ITEM *aItem)
Add a new item in stackup layer.
void BuildDefaultStackupList(const BOARD_DESIGN_SETTINGS *aSettings, int aActiveCopperLayersCount=0)
Create a default stackup, according to the current BOARD_DESIGN_SETTINGS settings.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
BOARD_STACKUP & operator=(const BOARD_STACKUP &aOther)
BOARD_STACKUP_ITEM * GetStackupLayer(int aIndex)
int GetLayerDistance(PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer) const
Calculate the distance (height) between the two given copper layers.
std::vector< BOARD_STACKUP_ITEM * > m_list
bool m_EdgePlating
True if the edge board is plated.
BS_EDGE_CONNECTOR_CONSTRAINTS m_EdgeConnectorConstraints
If the board has edge connector cards, some constrains can be specified in job file: BS_EDGE_CONNECTO...
void FormatBoardStackup(OUTPUTFORMATTER *aFormatter, const BOARD *aBoard) const
Write the stackup info on board file.
bool m_HasThicknessConstrains
True if some layers (copper and/or dielectric) have specific thickness.
wxString m_FinishType
The name of external copper finish.
Information pertinent to a Pcbnew printed circuit board.
A helper class to manage a dielectric layer set of parameters.
double m_EpsilonR
For dielectric (and solder mask) the dielectric constant.
double m_SpecFreq
For dielectric the frequency (Hz) at which E_R is specified.
int m_Thickness
the physical layer thickness in internal units
wxString m_Material
type of material (for dielectric and solder mask)
bool operator==(const DIELECTRIC_PRMS &aOther) const
wxString m_Color
mainly for silkscreen and solder mask
DIELECTRIC_MODEL m_DielectricModel
For dielectric the dielectric frequency correction model.
bool m_ThicknessLocked
true for dielectric layers with a fixed thickness (for impedance controlled purposes),...
double m_LossTangent
For dielectric (and solder mask) the dielectric loss.
A color representation with 4 components: red, green, blue, alpha.
LSET is a set of PCB_LAYER_IDs.
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Some functions to handle hotkeys in KiCad.
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
Converts aValue from internal units to a string appropriate for writing to file.
KICOMMON_API void PackColor(types::Color &aOutput, const KIGFX::COLOR4D &aInput)
wxString NotSpecifiedPrm()
#define DEFAULT_EPSILON_R_SILKSCREEN
#define DEFAULT_EPSILON_R_SOLDERMASK
std::string UIDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 We want to avoid scientific ...
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
DIELECTRIC_MODEL
Frequency-domain model used for the substrate dielectric properties.