ADDED: Option to disable autoplacement for particular fields

Fixes https://gitlab.com/kicad/code/kicad/-/issues/5767
This commit is contained in:
Jon Evans 2022-09-04 12:34:16 -04:00
parent 1079a4144a
commit 04f65c6c5c
14 changed files with 143 additions and 28 deletions

View File

@ -151,7 +151,7 @@ public:
{ {
SCH_FIELD* field = m_fields[field_idx]; SCH_FIELD* field = m_fields[field_idx];
if( !field->IsVisible() ) if( !field->IsVisible() || !field->CanAutoplace() )
continue; continue;
if( m_allow_rejustify ) if( m_allow_rejustify )
@ -204,11 +204,14 @@ protected:
} }
for( SCH_FIELD* field : visibleFields ) for( SCH_FIELD* field : visibleFields )
{
if( field->CanAutoplace() )
{ {
if( m_symbol->GetTransform().y1 ) if( m_symbol->GetTransform().y1 )
field->SetTextAngle( ANGLE_VERTICAL ); field->SetTextAngle( ANGLE_VERTICAL );
else else
field->SetTextAngle( ANGLE_HORIZONTAL ); field->SetTextAngle( ANGLE_HORIZONTAL );
}
BOX2I bbox = field->GetBoundingBox(); BOX2I bbox = field->GetBoundingBox();
int field_width = bbox.GetWidth(); int field_width = bbox.GetWidth();

View File

@ -332,6 +332,7 @@ bool DIALOG_FIELD_PROPERTIES::TransferDataToWindow()
m_visible->SetValue( m_isVisible ); m_visible->SetValue( m_isVisible );
m_nameVisible->SetValue( m_isNameVisible ); m_nameVisible->SetValue( m_isNameVisible );
m_cbAllowAutoPlace->SetValue( m_allowAutoplace );
return true; return true;
} }
@ -402,6 +403,7 @@ bool DIALOG_FIELD_PROPERTIES::TransferDataFromWindow()
m_isVisible = m_visible->GetValue(); m_isVisible = m_visible->GetValue();
m_isNameVisible = m_nameVisible->GetValue(); m_isNameVisible = m_nameVisible->GetValue();
m_allowAutoplace = m_cbAllowAutoPlace->GetValue();
return true; return true;
} }
@ -427,10 +429,14 @@ DIALOG_LIB_FIELD_PROPERTIES::DIALOG_LIB_FIELD_PROPERTIES( SCH_BASE_FRAME* aParen
{ {
m_fieldId = aField->GetId(); m_fieldId = aField->GetId();
m_isNameVisible = aField->IsNameShown(); m_isNameVisible = aField->IsNameShown();
m_allowAutoplace = aField->CanAutoplace();
if( m_fieldId == VALUE_FIELD ) if( m_fieldId == VALUE_FIELD )
m_text = UnescapeString( aField->GetText() ); m_text = UnescapeString( aField->GetText() );
m_nameVisible->Show();
m_cbAllowAutoPlace->Show();
// When in the library editor, power symbols can be renamed. // When in the library editor, power symbols can be renamed.
m_isPower = false; m_isPower = false;
init(); init();
@ -453,6 +459,7 @@ void DIALOG_LIB_FIELD_PROPERTIES::UpdateField( LIB_FIELD* aField )
updateText( aField ); updateText( aField );
aField->SetNameShown( m_isNameVisible ); aField->SetNameShown( m_isNameVisible );
aField->SetCanAutoplace( m_allowAutoplace );
aField->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_horizontalJustification ) ); aField->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_horizontalJustification ) );
aField->SetVertJustify( EDA_TEXT::MapVertJustify( m_verticalJustification ) ); aField->SetVertJustify( EDA_TEXT::MapVertJustify( m_verticalJustification ) );
@ -510,6 +517,7 @@ DIALOG_SCH_FIELD_PROPERTIES::DIALOG_SCH_FIELD_PROPERTIES( SCH_BASE_FRAME* aParen
m_position = m_field->GetPosition(); m_position = m_field->GetPosition();
m_isNameVisible = m_field->IsNameShown(); m_isNameVisible = m_field->IsNameShown();
m_allowAutoplace = m_field->CanAutoplace();
m_horizontalJustification = m_field->GetEffectiveHorizJustify(); m_horizontalJustification = m_field->GetEffectiveHorizJustify();
m_verticalJustification = m_field->GetEffectiveVertJustify(); m_verticalJustification = m_field->GetEffectiveVertJustify();
@ -530,6 +538,9 @@ DIALOG_SCH_FIELD_PROPERTIES::DIALOG_SCH_FIELD_PROPERTIES( SCH_BASE_FRAME* aParen
m_StyledTextCtrl->Bind( wxEVT_STC_CHARADDED, &DIALOG_SCH_FIELD_PROPERTIES::onScintillaCharAdded, m_StyledTextCtrl->Bind( wxEVT_STC_CHARADDED, &DIALOG_SCH_FIELD_PROPERTIES::onScintillaCharAdded,
this ); this );
m_nameVisible->Show();
m_cbAllowAutoPlace->Show();
init(); init();
if( m_isSheetFilename ) if( m_isSheetFilename )
@ -672,6 +683,7 @@ void DIALOG_SCH_FIELD_PROPERTIES::UpdateField( SCH_FIELD* aField, SCH_SHEET_PATH
aField->SetFont( m_font ); aField->SetFont( m_font );
aField->SetNameShown( m_isNameVisible ); aField->SetNameShown( m_isNameVisible );
aField->SetCanAutoplace( m_allowAutoplace );
// Note that we must set justifications before we can ask if they're flipped. If the old // Note that we must set justifications before we can ask if they're flipped. If the old
// justification is center then it won't know (whereas if the new justification is center // justification is center then it won't know (whereas if the new justification is center

View File

@ -102,6 +102,7 @@ protected:
GR_TEXT_H_ALIGN_T m_horizontalJustification; GR_TEXT_H_ALIGN_T m_horizontalJustification;
bool m_isVisible; bool m_isVisible;
bool m_isNameVisible; bool m_isNameVisible;
bool m_allowAutoplace;
bool m_firstFocus; bool m_firstFocus;

View File

@ -88,10 +88,18 @@ DIALOG_FIELD_PROPERTIES_BASE::DIALOG_FIELD_PROPERTIES_BASE( wxWindow* parent, wx
bSizer9->Add( m_visible, 0, wxALIGN_LEFT|wxBOTTOM, 2 ); bSizer9->Add( m_visible, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
m_nameVisible = new wxCheckBox( this, wxID_ANY, _("Show field name"), wxDefaultPosition, wxDefaultSize, 0 ); m_nameVisible = new wxCheckBox( this, wxID_ANY, _("Show field name"), wxDefaultPosition, wxDefaultSize, 0 );
m_nameVisible->Hide();
m_nameVisible->SetToolTip( _("Show the field name in addtion to its value") ); m_nameVisible->SetToolTip( _("Show the field name in addtion to its value") );
bSizer9->Add( m_nameVisible, 0, wxLEFT, 5 ); bSizer9->Add( m_nameVisible, 0, wxLEFT, 5 );
m_cbAllowAutoPlace = new wxCheckBox( this, wxID_ANY, _("Allow autoplacement"), wxDefaultPosition, wxDefaultSize, 0 );
m_cbAllowAutoPlace->SetValue(true);
m_cbAllowAutoPlace->Hide();
m_cbAllowAutoPlace->SetToolTip( _("Allow automatic placement of this field in the schematic") );
bSizer9->Add( m_cbAllowAutoPlace, 0, wxFIXED_MINSIZE, 5 );
bPropertiesSizer->Add( bSizer9, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 10 ); bPropertiesSizer->Add( bSizer9, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 10 );

View File

@ -527,7 +527,7 @@
<property name="floatable">1</property> <property name="floatable">1</property>
<property name="font"></property> <property name="font"></property>
<property name="gripper">0</property> <property name="gripper">0</property>
<property name="hidden">0</property> <property name="hidden">1</property>
<property name="id">wxID_ANY</property> <property name="id">wxID_ANY</property>
<property name="label">Show field name</property> <property name="label">Show field name</property>
<property name="max_size"></property> <property name="max_size"></property>
@ -560,6 +560,70 @@
<property name="window_style"></property> <property name="window_style"></property>
</object> </object>
</object> </object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxFIXED_MINSIZE</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="checked">1</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">1</property>
<property name="id">wxID_ANY</property>
<property name="label">Allow autoplacement</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_cbAllowAutoPlace</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">0</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip">Allow automatic placement of this field in the schematic</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
</object> </object>
</object> </object>
<object class="sizeritem" expanded="1"> <object class="sizeritem" expanded="1">

View File

@ -53,6 +53,7 @@ class DIALOG_FIELD_PROPERTIES_BASE : public DIALOG_SHIM
wxStaticText* m_note; wxStaticText* m_note;
wxCheckBox* m_visible; wxCheckBox* m_visible;
wxCheckBox* m_nameVisible; wxCheckBox* m_nameVisible;
wxCheckBox* m_cbAllowAutoPlace;
wxStaticText* m_fontLabel; wxStaticText* m_fontLabel;
FONT_CHOICE* m_fontCtrl; FONT_CHOICE* m_fontCtrl;
BITMAP_BUTTON* m_separator1; BITMAP_BUTTON* m_separator1;

View File

@ -76,6 +76,7 @@ LIB_FIELD& LIB_FIELD::operator=( const LIB_FIELD& field )
m_parent = field.m_parent; m_parent = field.m_parent;
m_autoAdded = field.m_autoAdded; m_autoAdded = field.m_autoAdded;
m_showName = field.m_showName; m_showName = field.m_showName;
m_allowAutoPlace = field.m_allowAutoPlace;
SetText( field.GetText() ); SetText( field.GetText() );
SetAttributes( field ); SetAttributes( field );
@ -103,6 +104,7 @@ void LIB_FIELD::Init( int aId )
m_autoAdded = false; m_autoAdded = false;
m_showName = false; m_showName = false;
m_allowAutoPlace = true;
} }
@ -196,6 +198,7 @@ void LIB_FIELD::Copy( LIB_FIELD* aTarget ) const
{ {
aTarget->m_name = m_name; aTarget->m_name = m_name;
aTarget->m_showName = m_showName; aTarget->m_showName = m_showName;
aTarget->m_allowAutoPlace = m_allowAutoPlace;
aTarget->CopyText( *this ); aTarget->CopyText( *this );
aTarget->SetAttributes( *this ); aTarget->SetAttributes( *this );

View File

@ -181,6 +181,9 @@ public:
bool IsNameShown() const { return m_showName; } bool IsNameShown() const { return m_showName; }
void SetNameShown( bool aShown = true ) { m_showName = aShown; } void SetNameShown( bool aShown = true ) { m_showName = aShown; }
bool CanAutoplace() const { return m_allowAutoPlace; }
void SetCanAutoplace( bool aCanPlace ) { m_allowAutoPlace = aCanPlace; }
private: private:
/** /**
@ -219,6 +222,7 @@ private:
wxString m_name; ///< Name (not the field text value itself, that is #EDA_TEXT::m_Text) wxString m_name; ///< Name (not the field text value itself, that is #EDA_TEXT::m_Text)
bool m_autoAdded; ///< Was this field automatically added to a LIB_SYMBOL? bool m_autoAdded; ///< Was this field automatically added to a LIB_SYMBOL?
bool m_showName; ///< Render the field's name in addition to its value bool m_showName; ///< Render the field's name in addition to its value
bool m_allowAutoPlace; ///< This field can be autoplaced when converted to a SCH_FIELD
}; };
#endif // CLASS_LIBENTRY_FIELDS_H #endif // CLASS_LIBENTRY_FIELDS_H

View File

@ -63,6 +63,7 @@ SCH_FIELD::SCH_FIELD( const VECTOR2I& aPos, int aFieldId, SCH_ITEM* aParent,
m_id( 0 ), m_id( 0 ),
m_name( aName ), m_name( aName ),
m_showName( false ), m_showName( false ),
m_allowAutoPlace( true ),
m_renderCacheValid( false ) m_renderCacheValid( false )
{ {
SetTextPos( aPos ); SetTextPos( aPos );
@ -78,6 +79,7 @@ SCH_FIELD::SCH_FIELD( const SCH_FIELD& aField ) :
m_id = aField.m_id; m_id = aField.m_id;
m_name = aField.m_name; m_name = aField.m_name;
m_showName = aField.m_showName; m_showName = aField.m_showName;
m_allowAutoPlace = aField.m_allowAutoPlace;
m_renderCache.clear(); m_renderCache.clear();
@ -99,6 +101,7 @@ SCH_FIELD& SCH_FIELD::operator=( const SCH_FIELD& aField )
m_id = aField.m_id; m_id = aField.m_id;
m_name = aField.m_name; m_name = aField.m_name;
m_showName = aField.m_showName; m_showName = aField.m_showName;
m_allowAutoPlace = aField.m_allowAutoPlace;
m_renderCache.clear(); m_renderCache.clear();
@ -368,6 +371,7 @@ void SCH_FIELD::ImportValues( const LIB_FIELD& aSource )
{ {
SetAttributes( aSource ); SetAttributes( aSource );
SetNameShown( aSource.IsNameShown() ); SetNameShown( aSource.IsNameShown() );
SetCanAutoplace( aSource.CanAutoplace() );
} }
@ -380,6 +384,7 @@ void SCH_FIELD::SwapData( SCH_ITEM* aItem )
std::swap( m_layer, item->m_layer ); std::swap( m_layer, item->m_layer );
std::swap( m_showName, item->m_showName ); std::swap( m_showName, item->m_showName );
std::swap( m_allowAutoPlace, item->m_allowAutoPlace );
SwapText( *item ); SwapText( *item );
SwapAttributes( *item ); SwapAttributes( *item );
} }

View File

@ -139,6 +139,9 @@ public:
bool IsNameShown() const { return m_showName; } bool IsNameShown() const { return m_showName; }
void SetNameShown( bool aShown = true ) { m_showName = aShown; } void SetNameShown( bool aShown = true ) { m_showName = aShown; }
bool CanAutoplace() const { return m_allowAutoPlace; }
void SetCanAutoplace( bool aCanPlace ) { m_allowAutoPlace = aCanPlace; }
/** /**
* @return true if the field is either empty or holds "~". * @return true if the field is either empty or holds "~".
*/ */
@ -234,6 +237,7 @@ private:
wxString m_name; wxString m_name;
bool m_showName; ///< Render the field name in addition to its value bool m_showName; ///< Render the field name in addition to its value
bool m_allowAutoPlace; ///< This field can be autoplaced
mutable bool m_renderCacheValid; mutable bool m_renderCacheValid;
mutable VECTOR2I m_renderCachePos; mutable VECTOR2I m_renderCachePos;

View File

@ -84,4 +84,5 @@
//#define SEXPR_SCHEMATIC_FILE_VERSION 20220622 // New simulation model format. //#define SEXPR_SCHEMATIC_FILE_VERSION 20220622 // New simulation model format.
//#define SEXPR_SCHEMATIC_FILE_VERSION 20220820 // Fix broken default symbol instance data. //#define SEXPR_SCHEMATIC_FILE_VERSION 20220820 // Fix broken default symbol instance data.
//#define SEXPR_SCHEMATIC_FILE_VERSION 20220822 // Hyperlinks in text objects //#define SEXPR_SCHEMATIC_FILE_VERSION 20220822 // Hyperlinks in text objects
#define SEXPR_SCHEMATIC_FILE_VERSION 20220903 // Field name visibility //#define SEXPR_SCHEMATIC_FILE_VERSION 20220903 // Field name visibility
#define SEXPR_SCHEMATIC_FILE_VERSION 20220904 // Do not autoplace field option

View File

@ -402,6 +402,9 @@ void SCH_SEXPR_PLUGIN_CACHE::saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFor
if( aField->IsNameShown() ) if( aField->IsNameShown() )
aFormatter.Print( aNestLevel, " (show_name)" ); aFormatter.Print( aNestLevel, " (show_name)" );
if( !aField->CanAutoplace() )
aFormatter.Print( aNestLevel, " (do_not_autoplace)" );
aField->Format( &aFormatter, aNestLevel, 0 ); aField->Format( &aFormatter, aNestLevel, 0 );
aFormatter.Print( aNestLevel, "\n)\n" ); aFormatter.Print( aNestLevel, "\n)\n" );
} }

View File

@ -800,8 +800,13 @@ LIB_FIELD* SCH_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_SYMBOL>& aSymbol
NeedRIGHT(); NeedRIGHT();
break; break;
case T_do_not_autoplace:
field->SetCanAutoplace( false );
NeedRIGHT();
break;
default: default:
Expecting( "id, at, show_name, or effects" ); Expecting( "id, at, show_name, do_not_autoplace, or effects" );
} }
} }

View File

@ -28,6 +28,7 @@ default_instance
diameter diameter
diamond diamond
directive_label directive_label
do_not_autoplace
dot dot
edge_clock_high edge_clock_high
effects effects