Eeschema: fix sheet bug in schematic editor drawing tool.
SCH_SHEET objects can only have another SCH_SHEET object as a parent
or nullptr for the root sheet so overload EDA_ITEM::SetParent() to
prevent the parent from being set to another type of object and add
some checks to the root sheet code just in case someone gets clever
and attempts to bypass the overloaded SetParent() call.
(cherry picked from commit fa57c8a570
)
This commit is contained in:
parent
ffc95090aa
commit
3f717f3baf
|
@ -577,7 +577,7 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
|
|||
SCH_SCREEN* screen = new SCH_SCREEN( m_kiway );
|
||||
|
||||
sheet->SetTimeStamp( GetNewTimeStamp() - i ); // minus the sheet index to make it unique.
|
||||
sheet->SetParent( m_rootSheet->GetScreen() );
|
||||
sheet->SetParent( m_rootSheet );
|
||||
sheet->SetScreen( screen );
|
||||
sheet->GetScreen()->SetFileName( sheet->GetFileName() );
|
||||
|
||||
|
|
|
@ -101,6 +101,19 @@ EDA_ITEM* SCH_SHEET::Clone() const
|
|||
}
|
||||
|
||||
|
||||
void SCH_SHEET::SetParent( EDA_ITEM* aSheet )
|
||||
{
|
||||
m_Parent = nullptr;
|
||||
|
||||
if( aSheet )
|
||||
{
|
||||
// Parent must be another SCH_SHEET object or nullptr
|
||||
wxCHECK( aSheet->Type() == SCH_SHEET_T, /* void */ );
|
||||
m_Parent = aSheet;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SCH_SHEET::SetScreen( SCH_SCREEN* aScreen )
|
||||
{
|
||||
if( aScreen == m_screen )
|
||||
|
@ -135,11 +148,16 @@ int SCH_SHEET::GetScreenCount() const
|
|||
|
||||
SCH_SHEET* SCH_SHEET::GetRootSheet()
|
||||
{
|
||||
SCH_SHEET* sheet = dynamic_cast< SCH_SHEET* >( GetParent() );
|
||||
EDA_ITEM* item = GetParent();
|
||||
|
||||
if( sheet == NULL )
|
||||
if( item == nullptr )
|
||||
return this;
|
||||
|
||||
SCH_SHEET* sheet = dynamic_cast< SCH_SHEET* >( item );
|
||||
|
||||
// The parent must be a SCH_SHEET object.
|
||||
wxCHECK( sheet, nullptr );
|
||||
|
||||
// Recurse until a sheet is found with no parent which is the root sheet.
|
||||
return sheet->GetRootSheet();
|
||||
}
|
||||
|
|
|
@ -253,6 +253,8 @@ public:
|
|||
return wxT( "SCH_SHEET" );
|
||||
}
|
||||
|
||||
virtual void SetParent( EDA_ITEM* aSheet ) override;
|
||||
|
||||
/**
|
||||
* Return true for items which are moved with the anchor point at mouse cursor
|
||||
* and false for items moved with no reference to anchor.
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* Copyright (C) 2013-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2008-2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
||||
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
||||
* Copyright (C) 2004-2018 KiCad Developers, see change_log.txt for contributors.
|
||||
* Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -213,8 +213,8 @@ public:
|
|||
|
||||
void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
|
||||
void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
|
||||
void SetParent( EDA_ITEM* aParent ) { m_Parent = aParent; }
|
||||
void SetList( DHEAD* aList ) { m_List = aList; }
|
||||
virtual void SetParent( EDA_ITEM* aParent ) { m_Parent = aParent; }
|
||||
|
||||
inline bool IsNew() const { return m_Flags & IS_NEW; }
|
||||
inline bool IsModified() const { return m_Flags & IS_CHANGED; }
|
||||
|
|
Loading…
Reference in New Issue