Undo commit -r 6535.

This commit is contained in:
Wayne Stambaugh 2016-02-15 15:12:42 -05:00
parent 9eda45a97e
commit 7b5823185a
9 changed files with 134 additions and 152 deletions

View File

@ -475,11 +475,10 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
if( srcFn.IsRelative() ) if( srcFn.IsRelative() )
srcFn.MakeAbsolute( Prj().GetProjectPath() ); srcFn.MakeAbsolute( Prj().GetProjectPath() );
std::vector< std::vector< const SCH_SHEET* > > sheetHierarchy; SCH_SHEET_LIST sheetHierarchy( sheet );
sheet->GetSheetPaths( sheetHierarchy );
if( g_RootSheet->TestForRecursion( sheetHierarchy, if( hierarchy.TestForRecursion( sheetHierarchy,
destFn.GetFullPath( wxPATH_UNIX ) ) ) destFn.GetFullPath( wxPATH_UNIX ) ) )
{ {
wxString msg; wxString msg;

View File

@ -1187,31 +1187,10 @@ unsigned SCH_SHEET::GetSheets( std::vector<const SCH_SHEET*>& aSheetList ) const
} }
void SCH_SHEET::GetSheetPaths( std::vector< std::vector< const SCH_SHEET* > >& aSheetPaths ) const SCH_SHEET* SCH_SHEET::GetRootSheet()
{
static std::vector< const SCH_SHEET* > path;
path.push_back( const_cast< SCH_SHEET* >( this ) );
aSheetPaths.push_back( path );
SCH_ITEM* item = m_screen->GetDrawItems();
while( item )
{
if( item->Type() == SCH_SHEET_T )
( (SCH_SHEET*) item )->GetSheetPaths( aSheetPaths );
item = item->Next();
}
path.pop_back();
}
const SCH_SHEET* SCH_SHEET::GetRootSheet() const
{ {
EDA_ITEM* parent = GetParent(); EDA_ITEM* parent = GetParent();
const SCH_SHEET* rootSheet = const_cast< SCH_SHEET* >( this ); SCH_SHEET* rootSheet = this;
while( parent ) while( parent )
{ {
@ -1221,7 +1200,7 @@ const SCH_SHEET* SCH_SHEET::GetRootSheet() const
parent = parent->GetParent(); parent = parent->GetParent();
} }
return const_cast< SCH_SHEET* >( rootSheet ); return rootSheet;
} }
@ -1603,88 +1582,6 @@ int SCH_SHEET::operator-( const SCH_SHEET& aRhs ) const
} }
bool SCH_SHEET::TestForRecursion( std::vector< std::vector< const SCH_SHEET* > >& aSrcSheetHierarchy,
const wxString& aDestFileName ) const
{
std::vector< std::vector< const SCH_SHEET* > > hierarchy;
wxFileName rootFn = GetRootSheet()->GetFileName();
wxFileName destFn = aDestFileName;
if( destFn.IsRelative() )
destFn.MakeAbsolute( rootFn.GetPath() );
GetRootSheet()->GetSheetPaths( hierarchy );
// Test each SCH_SHEET_PATH in this SCH_SHEET_LIST for potential recursion.
for( unsigned i = 0; i < hierarchy.size(); i++ )
{
// Test each SCH_SHEET_PATH in the source sheet.
for( unsigned j = 0; j < aSrcSheetHierarchy.size(); j++ )
{
std::vector< const SCH_SHEET* > sheetPath = aSrcSheetHierarchy[ j ];
for( unsigned k = 0; k < sheetPath.size(); k++ )
{
wxFileName srcFn = sheetPath[k]->GetFileName();
if( srcFn.IsRelative() )
srcFn.MakeAbsolute( rootFn.GetPath() );
// The source and destination sheet file names cannot be the same.
if( srcFn == destFn )
return true;
/// @todo Store sheet file names with full path, either relative to project path
/// or absolute path. The current design always assumes subsheet files are
/// located in the project folder which may or may not be desirable.
std::vector< const SCH_SHEET* > destPath = hierarchy[i];
unsigned l = 0;
while( l < destPath.size() )
{
wxFileName cmpFn = destPath[i]->GetFileName();
if( cmpFn.IsRelative() )
cmpFn.MakeAbsolute( rootFn.GetPath() );
// Test if the file name of the destination sheet is in anywhere in the
// source sheet path.
if( cmpFn == destFn )
break;
l++;
}
// The destination sheet file name was not found in the any of the source sheet
// path or the destination sheet file name is the root sheet so no recursion is
// possible.
if( l >= destPath.size() || l == 0 )
return false;
// Walk back up to the root sheet to see if the source file name is already a
// parent in destination the sheet path. If so, recursion will occur.
do
{
l -= 1;
wxFileName cmpFn = destPath[i]->GetFileName();
if( cmpFn.IsRelative() )
cmpFn.MakeAbsolute( rootFn.GetPath() );
if( cmpFn == srcFn )
return true;
} while( l != 0 );
}
}
}
// The source sheet file can safely be added to the destination sheet file.
return false;
}
#if defined(DEBUG) #if defined(DEBUG)
void SCH_SHEET::Show( int nestLevel, std::ostream& os ) const void SCH_SHEET::Show( int nestLevel, std::ostream& os ) const

View File

@ -250,8 +250,6 @@ class SCH_SHEET : public SCH_ITEM
// than assigned in the order the sheets were parsed and loaded. // than assigned in the order the sheets were parsed and loaded.
int m_number; int m_number;
SCH_SHEET* getRootSheet();
public: public:
SCH_SHEET( const wxPoint& pos = wxPoint( 0, 0 ) ); SCH_SHEET( const wxPoint& pos = wxPoint( 0, 0 ) );
@ -601,18 +599,6 @@ public:
*/ */
unsigned GetSheets( std::vector<const SCH_SHEET*>& aSheetList ) const; unsigned GetSheets( std::vector<const SCH_SHEET*>& aSheetList ) const;
/**
* Function GetSheetPaths
*
* Returns a list of lists of #SCH_SHEET pointers to \a sSheetPaths.
*
* This is analagous to the old SCH_SHEET_LIST::BuildSheetList(). It creates a list of
* stacks to the sheet pointer hierarchy.
*
* @param aSheetPaths is a vector of vector of #SCH_SHEET pointers.
*/
void GetSheetPaths( std::vector< std::vector< const SCH_SHEET* > >& aSheetPaths ) const;
/** /**
* Function GetRootSheet * Function GetRootSheet
* *
@ -624,12 +610,7 @@ public:
* *
* @return a SCH_SHEET pointer to the root sheet. * @return a SCH_SHEET pointer to the root sheet.
*/ */
const SCH_SHEET* GetRootSheet() const; SCH_SHEET* GetRootSheet();
SCH_SHEET* GetRootSheet()
{
return const_cast< SCH_SHEET* >( static_cast< const SCH_SHEET&>( *this ).GetRootSheet() );
}
/** /**
* Function IsRootSheet * Function IsRootSheet
@ -766,20 +747,6 @@ public:
*/ */
SCH_ITEM* FindNextItem( KICAD_T aType, SCH_ITEM* aLastItem = NULL, bool aWrap = false ) const; SCH_ITEM* FindNextItem( KICAD_T aType, SCH_ITEM* aLastItem = NULL, bool aWrap = false ) const;
/**
* Function TestForRecursion
*
* test every SCH_SHEET in the SCH_SHEET hierarchy to verify if adding the sheets stored
* in \a aSrcSheetHierarchy to the sheet stored in \a aDestFileName will cause recursion.
*
* @param aSrcSheetHierarchy is a list #SCH_SHEET pointer lists of the source sheet add
* to \a aDestFileName.
* @param aDestFileName is the file name of the destination sheet for \a aSrcFileName.
* @return true if \a aFileName will cause recursion in the sheet path. Otherwise false.
*/
bool TestForRecursion( std::vector< std::vector< const SCH_SHEET* > >& aSrcSheetHierarchy,
const wxString& aDestFileName ) const;
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const; // override void Show( int nestLevel, std::ostream& os ) const; // override
#endif #endif

View File

@ -294,6 +294,69 @@ bool SCH_SHEET_PATH::operator==( const SCH_SHEET_PATH& d1 ) const
} }
bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName,
const wxString& aDestFileName ) const
{
wxFileName rootFn = g_RootSheet->GetFileName();
wxFileName srcFn = aSrcFileName;
wxFileName destFn = aDestFileName;
if( srcFn.IsRelative() )
srcFn.MakeAbsolute( rootFn.GetPath() );
if( destFn.IsRelative() )
destFn.MakeAbsolute( rootFn.GetPath() );
// The source and destination sheet file names cannot be the same.
if( srcFn == destFn )
return true;
/// @todo Store sheet file names with full path, either relative to project path
/// or absolute path. The current design always assumes subsheet files are
/// located in the project folder which may or may not be desirable.
unsigned i = 0;
while( i < m_numSheets )
{
wxFileName cmpFn = m_sheets[i]->GetFileName();
if( cmpFn.IsRelative() )
cmpFn.MakeAbsolute( rootFn.GetPath() );
// Test if the file name of the destination sheet is in anywhere in this sheet path.
if( cmpFn == destFn )
break;
i++;
}
// The destination sheet file name was not found in the sheet path or the destination
// sheet file name is the root sheet so no recursion is possible.
if( i >= m_numSheets || i == 0 )
return false;
// Walk back up to the root sheet to see if the source file name is already a parent in
// the sheet path. If so, recursion will occur.
do
{
i -= 1;
wxFileName cmpFn = m_sheets[i]->GetFileName();
if( cmpFn.IsRelative() )
cmpFn.MakeAbsolute( rootFn.GetPath() );
if( cmpFn == srcFn )
return true;
} while( i != 0 );
// The source sheet file name is not a parent of the destination sheet file name.
return false;
}
int SCH_SHEET_PATH::FindSheet( const wxString& aFileName ) const int SCH_SHEET_PATH::FindSheet( const wxString& aFileName ) const
{ {
for( unsigned i = 0; i < m_numSheets; i++ ) for( unsigned i = 0; i < m_numSheets; i++ )
@ -537,6 +600,37 @@ SCH_ITEM* SCH_SHEET_LIST::FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aShe
} }
bool SCH_SHEET_LIST::TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
const wxString& aDestFileName ) const
{
wxFileName rootFn = g_RootSheet->GetFileName();
wxFileName destFn = aDestFileName;
if( destFn.IsRelative() )
destFn.MakeAbsolute( rootFn.GetPath() );
// Test each SCH_SHEET_PATH in this SCH_SHEET_LIST for potential recursion.
for( int i = 0; i < m_count; i++ )
{
// Test each SCH_SHEET_PATH in the source sheet.
for( int j = 0; j < aSrcSheetHierarchy.GetCount(); j++ )
{
SCH_SHEET_PATH* sheetPath = aSrcSheetHierarchy.GetSheet( j );
for( unsigned k = 0; k < sheetPath->GetCount(); k++ )
{
if( m_list[i].TestForRecursion( sheetPath->GetSheet( k )->GetFileName(),
aDestFileName ) )
return true;
}
}
}
// The source sheet file can safely be added to the destination sheet file.
return false;
}
SCH_SHEET* SCH_SHEET_LIST::FindSheetByName( const wxString& aSheetName ) SCH_SHEET* SCH_SHEET_LIST::FindSheetByName( const wxString& aSheetName )
{ {
for( int i = 0; i < m_count; i++ ) for( int i = 0; i < m_count; i++ )

View File

@ -220,6 +220,19 @@ public:
*/ */
SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_ITEM* aLastItem = NULL, bool aWrap = false ) const; SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_ITEM* aLastItem = NULL, bool aWrap = false ) const;
/**
* Function TestForRecursion
*
* test the SCH_SHEET_PATH file names to check adding the sheet stored in the file
* \a aSrcFileName to the sheet stored in file \a aDestFileName will cause a sheet
* path recursion.
*
* @param aSrcFileName is the source file name of the sheet add to \a aDestFileName.
* @param aDestFileName is the file name of the destination sheet for \a aSrcFileName.
* @return true if \a aFileName will cause recursion in the sheet path. Otherwise false.
*/
bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName ) const;
int FindSheet( const wxString& aFileName ) const; int FindSheet( const wxString& aFileName ) const;
/** /**
@ -375,6 +388,19 @@ public:
SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFound = NULL, SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFound = NULL,
SCH_ITEM* aLastItem = NULL, bool aWrap = true ); SCH_ITEM* aLastItem = NULL, bool aWrap = true );
/**
* Function TestForRecursion
*
* test every SCH_SHEET_PATH in the SCH_SHEET_LIST to verify if adding the sheets stored
* in \a aSrcSheetHierarchy to the sheet stored in \a aDestFileName will cause recursion.
*
* @param aSrcSheetHierarchy is the SCH_SHEET_LIST of the source sheet add to \a aDestFileName.
* @param aDestFileName is the file name of the destination sheet for \a aSrcFileName.
* @return true if \a aFileName will cause recursion in the sheet path. Otherwise false.
*/
bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
const wxString& aDestFileName ) const;
/** /**
* Function FindSheetByName * Function FindSheetByName
* *

View File

@ -983,7 +983,7 @@ void SCH_EDIT_FRAME::OnEditItem( wxCommandEvent& aEvent )
} }
case SCH_SHEET_T: case SCH_SHEET_T:
if( EditSheet( (SCH_SHEET*) item, m_CurrentSheet->Last() ) ) if( EditSheet( (SCH_SHEET*) item, m_CurrentSheet ) )
m_canvas->Refresh(); m_canvas->Refresh();
break; break;

View File

@ -1274,7 +1274,7 @@ void SCH_EDIT_FRAME::addCurrentItemToList( bool aRedraw )
// the m_mouseCaptureCallback function. // the m_mouseCaptureCallback function.
m_canvas->SetMouseCapture( NULL, NULL ); m_canvas->SetMouseCapture( NULL, NULL );
if( !EditSheet( (SCH_SHEET*)item, m_CurrentSheet->Last() ) ) if( !EditSheet( (SCH_SHEET*)item, m_CurrentSheet ) )
{ {
screen->SetCurItem( NULL ); screen->SetCurItem( NULL );
delete item; delete item;

View File

@ -1015,7 +1015,7 @@ public:
* *
* Note: the screen is not refresh. The caller is responsible to do that * Note: the screen is not refresh. The caller is responsible to do that
*/ */
bool EditSheet( SCH_SHEET* aSheet, SCH_SHEET* aHierarchy ); bool EditSheet( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy );
wxPoint GetLastSheetPinPosition() const { return m_lastSheetPinPosition; } wxPoint GetLastSheetPinPosition() const { return m_lastSheetPinPosition; }

View File

@ -41,7 +41,7 @@
#include <project.h> #include <project.h>
bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, SCH_SHEET* aHierarchy ) bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy )
{ {
if( aSheet == NULL || aHierarchy == NULL ) if( aSheet == NULL || aHierarchy == NULL )
return false; return false;
@ -235,16 +235,15 @@ bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, SCH_SHEET* aHierarchy )
(long unsigned) aSheet->GetTimeStamp() ) ); (long unsigned) aSheet->GetTimeStamp() ) );
// Make sure the sheet changes do not cause any recursion. // Make sure the sheet changes do not cause any recursion.
std::vector< std::vector< const SCH_SHEET* > > sheetHierarchy; SCH_SHEET_LIST sheetHierarchy( aSheet );
aSheet->GetSheetPaths( sheetHierarchy );
// Make sure files have fully qualified path and file name. // Make sure files have fully qualified path and file name.
wxFileName destFn = aHierarchy->GetFileName(); wxFileName destFn = aHierarchy->Last()->GetFileName();
if( destFn.IsRelative() ) if( destFn.IsRelative() )
destFn.MakeAbsolute( Prj().GetProjectPath() ); destFn.MakeAbsolute( Prj().GetProjectPath() );
if( g_RootSheet->TestForRecursion( sheetHierarchy, destFn.GetFullPath( wxPATH_UNIX ) ) ) if( hierarchy.TestForRecursion( sheetHierarchy, destFn.GetFullPath( wxPATH_UNIX ) ) )
{ {
msg.Printf( _( "The sheet changes cannot be made because the destination sheet already " msg.Printf( _( "The sheet changes cannot be made because the destination sheet already "
"has the sheet <%s> or one of it's subsheets as a parent somewhere in " "has the sheet <%s> or one of it's subsheets as a parent somewhere in "