Run AutoAutoplaceFields() in SCH_SHEET constructor

A constructor should create a fully initialized object.
This commit is contained in:
Mikolaj Wielgus 2021-11-28 18:32:53 +01:00
parent 75d750a3cb
commit 2e1862de1c
3 changed files with 26 additions and 32 deletions

View File

@ -84,17 +84,18 @@ const wxString SCH_SHEET::GetDefaultFieldName( int aFieldNdx, bool aTranslated )
} }
SCH_SHEET::SCH_SHEET( EDA_ITEM* aParent, const wxPoint& pos ) : SCH_SHEET::SCH_SHEET( EDA_ITEM* aParent, const wxPoint& aPos, wxSize aSize,
FIELDS_AUTOPLACED aAutoplaceFields ) :
SCH_ITEM( aParent, SCH_SHEET_T ) SCH_ITEM( aParent, SCH_SHEET_T )
{ {
m_layer = LAYER_SHEET; m_layer = LAYER_SHEET;
m_pos = pos; m_pos = aPos;
m_size = wxSize( Mils2iu( MIN_SHEET_WIDTH ), Mils2iu( MIN_SHEET_HEIGHT ) ); m_size = aSize;
m_screen = nullptr; m_screen = nullptr;
for( int i = 0; i < SHEET_MANDATORY_FIELDS; ++i ) for( int i = 0; i < SHEET_MANDATORY_FIELDS; ++i )
{ {
m_fields.emplace_back( pos, i, this, GetDefaultFieldName( i ) ); m_fields.emplace_back( aPos, i, this, GetDefaultFieldName( i ) );
m_fields.back().SetVisible( true ); m_fields.back().SetVisible( true );
if( i == SHEETNAME ) if( i == SHEETNAME )
@ -105,7 +106,8 @@ SCH_SHEET::SCH_SHEET( EDA_ITEM* aParent, const wxPoint& pos ) :
m_fields.back().SetLayer( LAYER_SHEETFIELDS ); m_fields.back().SetLayer( LAYER_SHEETFIELDS );
} }
m_fieldsAutoplaced = FIELDS_AUTOPLACED_AUTO; m_fieldsAutoplaced = aAutoplaceFields;
AutoAutoplaceFields( nullptr );
m_borderWidth = 0; m_borderWidth = 0;
m_borderColor = COLOR4D::UNSPECIFIED; m_borderColor = COLOR4D::UNSPECIFIED;

View File

@ -54,7 +54,9 @@ enum SHEET_FIELD_TYPE
class SCH_SHEET : public SCH_ITEM class SCH_SHEET : public SCH_ITEM
{ {
public: public:
SCH_SHEET( EDA_ITEM* aParent = nullptr, const wxPoint& pos = wxPoint( 0, 0 ) ); SCH_SHEET( EDA_ITEM* aParent = nullptr, const wxPoint& aPos = wxPoint( 0, 0 ),
wxSize aSize = wxSize( Mils2iu( MIN_SHEET_WIDTH ), Mils2iu( MIN_SHEET_HEIGHT ) ),
FIELDS_AUTOPLACED aAutoplaceFields = FIELDS_AUTOPLACED_AUTO );
/** /**
* Copy \a aSheet into a new object. All sheet pins are copied as is except and * Copy \a aSheet into a new object. All sheet pins are copied as is except and

View File

@ -84,20 +84,10 @@ static SCH_ITEM* Instatiate( KICAD_T aType, SCH_SHEET* sheet )
wxPoint( sheet->GetPosition().x, sheet->GetPosition().y + Millimeter2iu( 40 ) ), wxPoint( sheet->GetPosition().x, sheet->GetPosition().y + Millimeter2iu( 40 ) ),
"test pin" ); "test pin" );
case SCH_SHEET_T: case SCH_SHEET_T: return new SCH_SHEET();
{
SCH_SHEET* sheet = new SCH_SHEET();
sheet->SetSize( wxSize( Millimeter2iu( 100 ), Millimeter2iu( 50 ) ) );
// XXX (?): Sheet fields currently have to be positioned with an additional method call.
sheet->AutoplaceFields( nullptr, false );
return sheet;
}
case SCH_PIN_T: case SCH_PIN_T:
case SCHEMATIC_T:
// TODO case SCHEMATIC_T: // You can't rotate or mirror a schematic object.
return nullptr;
// `LIB_ITEM`s aren't handled in this module. // `LIB_ITEM`s aren't handled in this module.
case LIB_SYMBOL_T: case LIB_SYMBOL_T: