55static const std::map<wxString, FAMILY>&
families()
58 static const std::map<wxString, FAMILY>
families = {
100 static const std::map<wxString, COMMON_PROPERTY> common = {
101 { wxS(
"Layer" ), {
_HKI(
"Layer" ), {
102 { wxS(
"barcode" ), wxS(
"Layer" ) },
103 { wxS(
"dimension" ), wxS(
"Layer" ) },
104 { wxS(
"shape" ), wxS(
"Layer" ) },
105 { wxS(
"table" ), wxS(
"Layer" ) },
106 { wxS(
"generated_table" ), wxS(
"Layer" ) },
107 { wxS(
"target" ), wxS(
"Layer" ) },
108 { wxS(
"text" ), wxS(
"Layer" ) },
109 { wxS(
"textbox" ), wxS(
"Layer" ) },
110 { wxS(
"reference_image" ), wxS(
"Associated Layer" ) } } } },
112 { wxS(
"Line Width" ), {
_HKI(
"Line Width" ), {
113 { wxS(
"route" ), wxS(
"Width" ) },
114 { wxS(
"shape" ), wxS(
"Line Width" ) },
115 { wxS(
"table" ), wxS(
"Border Width" ) },
116 { wxS(
"generated_table" ), wxS(
"Border Width" ) },
117 { wxS(
"target" ), wxS(
"Width" ) } } } },
119 { wxS(
"Soldermask" ), {
_HKI(
"Soldermask" ), {
120 { wxS(
"route" ), wxS(
"Soldermask" ) },
121 { wxS(
"shape" ), wxS(
"Soldermask" ) } } } },
123 { wxS(
"Soldermask Margin Override" ), {
_HKI(
"Soldermask Margin Override" ), {
124 { wxS(
"pad" ), wxS(
"Soldermask Margin Override" ) },
125 { wxS(
"route" ), wxS(
"Soldermask Margin Override" ) },
126 { wxS(
"shape" ), wxS(
"Soldermask Margin Override" ) } } } },
131 { wxS(
"Font" ), {
_HKI(
"Font" ), {
132 { wxS(
"dimension" ), wxS(
"Font" ) },
133 { wxS(
"table_cell" ), wxS(
"Font" ) },
134 { wxS(
"text" ), wxS(
"Font" ) },
135 { wxS(
"textbox" ), wxS(
"Font" ) } } } },
137 { wxS(
"Text Width" ), {
_HKI(
"Text Width" ), {
138 { wxS(
"dimension" ), wxS(
"Width" ) },
139 { wxS(
"table_cell" ), wxS(
"Width" ) },
140 { wxS(
"text" ), wxS(
"Width" ) },
141 { wxS(
"textbox" ), wxS(
"Width" ) } } } },
143 { wxS(
"Text Height" ), {
_HKI(
"Text Height" ), {
144 { wxS(
"dimension" ), wxS(
"Height" ) },
145 { wxS(
"table_cell" ), wxS(
"Height" ) },
146 { wxS(
"text" ), wxS(
"Height" ) },
147 { wxS(
"textbox" ), wxS(
"Height" ) } } } },
149 { wxS(
"Text Thickness" ), {
_HKI(
"Text Thickness" ), {
150 { wxS(
"dimension" ), wxS(
"Thickness" ) },
151 { wxS(
"table_cell" ), wxS(
"Thickness" ) },
152 { wxS(
"text" ), wxS(
"Thickness" ) },
153 { wxS(
"textbox" ), wxS(
"Thickness" ) } } } },
155 { wxS(
"Bold" ), {
_HKI(
"Bold" ), {
156 { wxS(
"dimension" ), wxS(
"Bold" ) },
157 { wxS(
"table_cell" ), wxS(
"Bold" ) },
158 { wxS(
"text" ), wxS(
"Bold" ) },
159 { wxS(
"textbox" ), wxS(
"Bold" ) } } } },
161 { wxS(
"Italic" ), {
_HKI(
"Italic" ), {
162 { wxS(
"dimension" ), wxS(
"Italic" ) },
163 { wxS(
"table_cell" ), wxS(
"Italic" ) },
164 { wxS(
"text" ), wxS(
"Italic" ) },
165 { wxS(
"textbox" ), wxS(
"Italic" ) } } } },
167 { wxS(
"Horizontal Justification" ), {
_HKI(
"Horizontal Justification" ), {
168 { wxS(
"dimension" ), wxS(
"Horizontal Justification" ) },
169 { wxS(
"table_cell" ), wxS(
"Horizontal Justification" ) },
170 { wxS(
"text" ), wxS(
"Horizontal Justification" ) },
171 { wxS(
"textbox" ), wxS(
"Horizontal Justification" ) } } } },
173 { wxS(
"Vertical Justification" ), {
_HKI(
"Vertical Justification" ), {
174 { wxS(
"dimension" ), wxS(
"Vertical Justification" ) },
175 { wxS(
"table_cell" ), wxS(
"Vertical Justification" ) },
176 { wxS(
"text" ), wxS(
"Vertical Justification" ) },
177 { wxS(
"textbox" ), wxS(
"Vertical Justification" ) } } } },
179 { wxS(
"Knockout" ), {
_HKI(
"Knockout" ), {
180 { wxS(
"barcode" ), wxS(
"Knockout" ) },
181 { wxS(
"dimension" ), wxS(
"Knockout" ) },
182 { wxS(
"table_cell" ), wxS(
"Knockout" ) },
183 { wxS(
"text" ), wxS(
"Knockout" ) },
184 { wxS(
"textbox" ), wxS(
"Knockout" ) } } } }
193static const std::map<wxString, std::map<wxString, wxString>>&
commonReach();
210 return family.IsEmpty() ? wxString() : family + wxS(
"/" );
216 switch( aItem.
Type() )
241 case PCB_ZONE_T:
return static_cast<const ZONE&
>( aItem ).GetIsRuleArea() ? wxS(
"rule_area" ) : wxS(
"zone" );
242 default:
return wxEmptyString;
250 return _(
"Common to Several Kinds" );
252 auto entry =
families().find( aFamily );
254 return entry ==
families().end() ? aFamily : wxGetTranslation( entry->second.m_Label );
260 const wxString family = aKey.BeforeFirst(
'/' );
265 auto entry =
commonReach().find( aKey.AfterFirst(
'/' ) );
272 for(
const auto& [
name, property] : entry->second )
281 auto entry =
families().find( aFamily );
297 return wxGetTranslation( entry->second.m_Label );
302 const wxString
name = aKey.AfterFirst(
'/' );
304 return wxGetTranslation(
name );
317 const wxString target =
Family( aTarget );
319 if(
source.IsEmpty() || target.IsEmpty() )
337 const std::vector<EDA_ITEM*>& aCandidates )
339 std::vector<EDA_ITEM*> targets;
341 for(
EDA_ITEM* candidate : aCandidates )
343 if( candidate && candidate != &aSource &&
Compatible( aSource, *candidate ) )
344 targets.push_back( candidate );
355 if( prefix.IsEmpty() )
358 auto it = aEnabledKeys.lower_bound( prefix );
360 if( it != aEnabledKeys.end() && it->StartsWith( prefix ) )
363 const wxString family =
Family( aItem );
377 const std::set<wxString>& aEnabledKeys )
379 std::vector<PENDING_PROPERTY> pending;
383 const bool acrossKinds = sourceFamily != targetFamily;
390 [&](
const wxString& aSourceName,
const wxString& aTargetName,
bool aOptional )
395 if( !sourceProperty || !targetProperty )
410 pending.push_back( { targetProperty, aSource.
Get( sourceProperty ), aOptional } );
417 for(
auto it = aEnabledKeys.lower_bound( prefix ); it != aEnabledKeys.end() && it->StartsWith( prefix );
420 const wxString
name = it->Mid( prefix.length() );
430 auto sourceName =
families.find( sourceFamily );
431 auto targetName =
families.find( targetFamily );
436 if( !aEnabledKeys.contains(
COMMON_FAMILY + wxS(
"/" ) + key ) )
439 stage( sourceName->second, targetName->second, acrossKinds );
447 const std::set<wxString>& aEnabledKeys )
453 result.m_Error =
_(
"The source and target have no properties in common." );
459 std::unique_ptr<EDA_ITEM> staged( aTarget.
Clone() );
460 std::vector<PENDING_PROPERTY> pending =
plan( aSource, aTarget, aEnabledKeys );
461 std::vector<std::pair<PROPERTY_BASE*, bool>> stagedProperties;
465 for(
bool madeProgress =
true; madeProgress; )
467 madeProgress =
false;
469 for(
auto it = pending.begin(); it != pending.end(); )
473 if( !mgr.
IsAvailableFor( targetType, targetProperty, staged.get() )
474 || !mgr.
IsWriteableFor( targetType, targetProperty, staged.get() ) )
480 if( !staged->Set( targetProperty, it->m_Value,
false ) )
486 it = pending.erase( it );
491 result.m_Error = wxString::Format(
_(
"Could not apply property '%s' to the target item." ),
492 wxGetTranslation( targetProperty->
Name() ) );
496 stagedProperties.push_back( { targetProperty, it->m_Optional } );
497 it = pending.erase( it );
504 std::vector<std::pair<PROPERTY_BASE*, wxAny>> apply;
506 for(
const auto& [targetProperty, optional] : stagedProperties )
508 if( !mgr.
IsAvailableFor( targetType, targetProperty, staged.get() )
509 || !mgr.
IsWriteableFor( targetType, targetProperty, staged.get() ) )
514 wxAny stagedValue = staged->Get( targetProperty );
516 if( targetProperty->Validate( wxAny( stagedValue ), staged.get() ) )
523 result.m_Error = wxString::Format(
_(
"The value for property '%s' is not valid for the target item." ),
524 wxGetTranslation( targetProperty->Name() ) );
528 apply.emplace_back( targetProperty, std::move( stagedValue ) );
531 for(
auto& [targetProperty, value] : apply )
534 && aTarget.
Set( targetProperty, value ) )
547 static const std::set<wxString> keys = []
549 std::set<wxString>
result;
555 ZONE ruleArea( &board );
558 for(
const auto& [family, entry] :
families() )
560 const TYPE_ID type = entry.m_Type;
561 const bool ruleAreaFamily = family == wxS(
"rule_area" );
565 if( !property->IsCopyable() || property->IsHiddenFromPropertiesManager() )
569 && mgr.
IsAvailableFor( type, property, &ruleArea ) != ruleAreaFamily )
574 result.insert( family + wxS(
"/" ) + property->Name() );
582 std::vector<wxString> covered;
584 for(
const auto& [family,
name] : common.m_Names )
586 const wxString familyKey = family + wxS(
"/" ) +
name;
588 if(
result.contains( familyKey ) )
589 covered.push_back( familyKey );
593 if( covered.size() < 2 )
596 for(
const wxString& familyKey : covered )
597 result.erase( familyKey );
609const std::map<wxString, std::map<wxString, wxString>>&
commonReach()
611 static const std::map<wxString, std::map<wxString, wxString>> reach = []
613 std::map<wxString, std::map<wxString, wxString>>
result;
622 for(
const auto& [family,
name] : common.m_Names )
638 static const std::set<wxString> keys = {
639 wxS(
"common/Layer" ), wxS(
"common/Line Width" ), wxS(
"shape/Fill" ),
640 wxS(
"common/Soldermask" ), wxS(
"common/Soldermask Margin Override" ),
641 wxS(
"common/Font" ), wxS(
"common/Text Width" ), wxS(
"common/Text Height" ),
642 wxS(
"common/Text Thickness" ), wxS(
"common/Bold" ), wxS(
"common/Italic" ),
643 wxS(
"shape/Line Style" ), wxS(
"via/Diameter" ), wxS(
"via/Hole" ),
644 wxS(
"zone/Fill Mode" ), wxS(
"table/Border Style" )
Information pertinent to a Pcbnew printed circuit board.
A base class for most all the KiCad significant classes used in schematics and boards.
KICAD_T Type() const
Returns the type of object.
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
wxAny Get(PROPERTY_BASE *aProperty) const
bool Set(PROPERTY_BASE *aProperty, wxAny &aValue, bool aNotify=true)
For better understanding of the points that make a dimension:
A table whose cell text is derived from the board and rebuilt whenever it goes stale.
Object to handle a bitmap image that can be inserted in a PCB.
bool IsHiddenFromPropertiesManager() const
bool IsCopyable() const
True for a property that says how an item looks, not what or where it is.
bool IsIndeterminate(INSPECTABLE *aObject) const
Return true if aObject holds several values for this property, so it has no single value to show.
const wxString & Name() const
const std::vector< PROPERTY_BASE * > & GetProperties(TYPE_ID aType) const
Return all properties for a specific type.
bool IsWriteableFor(TYPE_ID aItemClass, PROPERTY_BASE *aProp, INSPECTABLE *aItem)
Checks overriden availability and original availability of a property, returns false if the property ...
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Return a property for a specific type.
bool IsAvailableFor(TYPE_ID aItemClass, PROPERTY_BASE *aProp, INSPECTABLE *aItem)
Checks overriden availability and original availability of a property, returns false if the property ...
Handle a list of polygons defining a copper zone.
void SetIsRuleArea(bool aEnable)
Some functions to handle hotkeys in KiCad.
static std::vector< PENDING_PROPERTY > plan(const EDA_ITEM &aSource, const EDA_ITEM &aTarget, const std::set< wxString > &aEnabledKeys)
Target properties to write, paired with values read off the source.
static wxString familyPrefix(const EDA_ITEM &aItem)
Empty if the item has no family. Never matches a key.
static const std::map< wxString, COMMON_PROPERTY > & commonProperties()
Keyed by the name the settings use after the prefix.
static const wxString COMMON_FAMILY
The prefix common keys carry in the enabled set, in place of a family.
static const std::map< wxString, std::map< wxString, wxString > > & commonReach()
The families a common property actually reaches, once the unregistered ones are dropped.
static const std::map< wxString, FAMILY > & families()
Keyed by the names Family() returns. Every family there must appear here.
MATCH_PROPERTIES_RESULT Copy(const EDA_ITEM &aSource, EDA_ITEM &aTarget, const std::set< wxString > &aEnabledKeys)
bool Compatible(const EDA_ITEM &aSource, const EDA_ITEM &aTarget)
const std::set< wxString > & AllSafeKeys()
Every property Match Properties may copy, keyed as "family/Property Name".
bool PropertyIsRegistered(const wxString &aFamily, const wxString &aName)
Whether aFamily registers a property of that name. Used to prune the common table.
wxString PropertyLabel(const wxString &aKey)
The translated property name alone, without the family it belongs to.
const std::set< wxString > & DefaultKeys()
The subset enabled until the user says otherwise.
bool AnyEnabledFor(const EDA_ITEM &aItem, const std::set< wxString > &aEnabledKeys)
True if any enabled key names a property of this item's family.
std::vector< EDA_ITEM * > CompatibleTargets(const EDA_ITEM &aSource, const std::vector< EDA_ITEM * > &aCandidates)
wxString FamilyLabel(const wxString &aFamily)
The translated name of a family, for the heading of its group.
std::set< wxString > FamiliesFor(const wxString &aKey)
The families a key reaches. One for a family key, several for a common one.
wxString Family(const EDA_ITEM &aItem)
wxString DisplayLabel(const wxString &aKey)
BARCODE class definition.
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
size_t TYPE_ID
Unique type identifier.
A property that means the same thing in more than one family.
std::map< wxString, wxString > m_Names
family -> the name it is registered under there
TYPE_ID m_Type
One item type carrying every property the family advertises.
One value staged for the target. Optional entries are dropped if they will not go.
PROPERTY_BASE * m_Property
wxString result
Test unit parsing edge cases and error handling.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
@ PCB_STACKUP_TABLE_T
class PCB_STACKUP_TABLE, a live stackup table derived from PCB_TABLE
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
@ PCB_DRILL_CHART_T
class PCB_DRILL_CHART, a live drill chart derived from PCB_TABLE
bool KiWxAnyEquals(const wxAny &aA, const wxAny &aB, const PROPERTY_BASE *aProperty)
Compare two wxAny values for equality across the KiCad property type set.