Cleanup.
This commit is contained in:
parent
176b1a0fd5
commit
fcff0dd228
|
@ -126,59 +126,6 @@ SYMBOL_LIB_TABLE_ROW* LIB_MANAGER::GetLibrary( const wxString& aLibrary ) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool LIB_MANAGER::FlushAll()
|
|
||||||
{
|
|
||||||
bool result = true;
|
|
||||||
|
|
||||||
for( auto& libBuf : m_libs )
|
|
||||||
result &= FlushLibrary( libBuf.first );
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool LIB_MANAGER::FlushLibrary( const wxString& aLibrary )
|
|
||||||
{
|
|
||||||
auto it = m_libs.find( aLibrary );
|
|
||||||
|
|
||||||
if( it == m_libs.end() ) // no changes to flush
|
|
||||||
return true;
|
|
||||||
|
|
||||||
LIB_BUFFER& libBuf = it->second;
|
|
||||||
wxArrayString aliases;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
symTable()->EnumerateSymbolLib( aLibrary, aliases );
|
|
||||||
|
|
||||||
// TODO probably this could be implemented more efficiently
|
|
||||||
for( const auto& alias : aliases )
|
|
||||||
symTable()->DeleteAlias( aLibrary, alias );
|
|
||||||
}
|
|
||||||
catch( const IO_ERROR& e )
|
|
||||||
{
|
|
||||||
wxLogMessage( _( "Cannot flush library changes (\"%s\") (%s)" ), aLibrary, e.What() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assume all libraries are successfully saved
|
|
||||||
bool res = true;
|
|
||||||
|
|
||||||
for( const auto& partBuf : libBuf.GetBuffers() )
|
|
||||||
{
|
|
||||||
if( !libBuf.SaveBuffer( partBuf, symTable() ) )
|
|
||||||
{
|
|
||||||
// Something went wrong but try to save other libraries
|
|
||||||
res = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( res )
|
|
||||||
libBuf.ClearDeletedBuffer();
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool LIB_MANAGER::SaveLibrary( const wxString& aLibrary, const wxString& aFileName )
|
bool LIB_MANAGER::SaveLibrary( const wxString& aLibrary, const wxString& aFileName )
|
||||||
{
|
{
|
||||||
wxCHECK( LibraryExists( aLibrary ), false );
|
wxCHECK( LibraryExists( aLibrary ), false );
|
||||||
|
@ -755,17 +702,6 @@ bool LIB_MANAGER::PART_BUFFER::IsModified() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxArrayString LIB_MANAGER::LIB_BUFFER::GetAliasNames() const
|
|
||||||
{
|
|
||||||
wxArrayString ret;
|
|
||||||
|
|
||||||
for( const auto& alias : m_aliases )
|
|
||||||
ret.push_back( alias.first );
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool LIB_MANAGER::LIB_BUFFER::CreateBuffer( LIB_PART* aCopy, SCH_SCREEN* aScreen )
|
bool LIB_MANAGER::LIB_BUFFER::CreateBuffer( LIB_PART* aCopy, SCH_SCREEN* aScreen )
|
||||||
{
|
{
|
||||||
wxASSERT( m_aliases.count( aCopy->GetName() ) == 0 ); // only for new parts
|
wxASSERT( m_aliases.count( aCopy->GetName() ) == 0 ); // only for new parts
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
|
|
||||||
class LIB_ALIAS;
|
class LIB_ALIAS;
|
||||||
class LIB_PART;
|
class LIB_PART;
|
||||||
class LIB_BUFFER;
|
|
||||||
class PART_LIB;
|
class PART_LIB;
|
||||||
class SCH_PLUGIN;
|
class SCH_PLUGIN;
|
||||||
class LIB_EDIT_FRAME;
|
class LIB_EDIT_FRAME;
|
||||||
|
@ -48,11 +47,12 @@ class SYMBOL_LIB_TABLE_ROW;
|
||||||
class LIB_LOGGER : public wxLogGui
|
class LIB_LOGGER : public wxLogGui
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LIB_LOGGER() : m_previousLogger( nullptr ), m_activated( false )
|
LIB_LOGGER() :
|
||||||
{
|
m_previousLogger( nullptr ),
|
||||||
}
|
m_activated( false )
|
||||||
|
{ }
|
||||||
|
|
||||||
~LIB_LOGGER()
|
~LIB_LOGGER() override
|
||||||
{
|
{
|
||||||
if( m_activated )
|
if( m_activated )
|
||||||
wxLog::SetActiveTarget( m_previousLogger );
|
wxLog::SetActiveTarget( m_previousLogger );
|
||||||
|
@ -72,14 +72,13 @@ public:
|
||||||
{
|
{
|
||||||
wxLogMessage( _( "Not all libraries could be loaded. Use the Manage Symbol Libraries dialog \n"
|
wxLogMessage( _( "Not all libraries could be loaded. Use the Manage Symbol Libraries dialog \n"
|
||||||
"to adjust paths and add or remove libraries." ) );
|
"to adjust paths and add or remove libraries." ) );
|
||||||
|
|
||||||
wxLogGui::Flush();
|
wxLogGui::Flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxLog* m_previousLogger;
|
wxLog* m_previousLogger;
|
||||||
bool m_activated;
|
bool m_activated;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,9 +103,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns a library hash value to determine if it has changed.
|
* Returns a library hash value to determine if it has changed.
|
||||||
*
|
*
|
||||||
* For buffered libraries, it returns a number corresponding to the number
|
* For buffered libraries, it returns a number corresponding to the number of modifications.
|
||||||
* of modifications. For original libraries, hash is computed basing on the
|
* For original libraries, hash is computed basing on the library URI. Returns -1 when the
|
||||||
* library URI. Returns -1 when the requested library does not exist.
|
* requested library does not exist.
|
||||||
*/
|
*/
|
||||||
int GetLibraryHash( const wxString& aLibrary ) const;
|
int GetLibraryHash( const wxString& aLibrary ) const;
|
||||||
|
|
||||||
|
@ -219,14 +218,6 @@ public:
|
||||||
*/
|
*/
|
||||||
bool FlushPart( const wxString& aAlias, const wxString& aLibrary );
|
bool FlushPart( const wxString& aAlias, const wxString& aLibrary );
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves changes to the library copy used by the schematic editor. Note it is not
|
|
||||||
* necessarily saved to the file.
|
|
||||||
* @param aLibrary is the library name.
|
|
||||||
* @return True on success, false otherwise.
|
|
||||||
*/
|
|
||||||
bool FlushLibrary( const wxString& aLibrary );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves library to a file, including unsaved changes.
|
* Saves library to a file, including unsaved changes.
|
||||||
* @param aLibrary is the library name.
|
* @param aLibrary is the library name.
|
||||||
|
@ -235,12 +226,6 @@ public:
|
||||||
*/
|
*/
|
||||||
bool SaveLibrary( const wxString& aLibrary, const wxString& aFileName );
|
bool SaveLibrary( const wxString& aLibrary, const wxString& aFileName );
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves all changes to libraries.
|
|
||||||
* @return True if all changes have been flushed successfully, false otherwise.
|
|
||||||
*/
|
|
||||||
bool FlushAll();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverts unsaved changes for a particular part.
|
* Reverts unsaved changes for a particular part.
|
||||||
* @return The LIB_ID of the reverted part (which may be different in the case
|
* @return The LIB_ID of the reverted part (which may be different in the case
|
||||||
|
@ -275,34 +260,14 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns the currently modified library name.
|
* Returns the currently modified library name.
|
||||||
*/
|
*/
|
||||||
const wxString& GetCurrentLib() const
|
const wxString& GetCurrentLib() const { return m_currentLib; }
|
||||||
{
|
void SetCurrentLib( const wxString& aLibrary ) { m_currentLib = aLibrary; }
|
||||||
return m_currentLib;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the currently modified library name.
|
|
||||||
*/
|
|
||||||
void SetCurrentLib( const wxString& aLibrary )
|
|
||||||
{
|
|
||||||
m_currentLib = aLibrary;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the currently modified part name.
|
* Returns the currently modified part name.
|
||||||
*/
|
*/
|
||||||
const wxString& GetCurrentPart() const
|
const wxString& GetCurrentPart() const { return m_currentPart; }
|
||||||
{
|
void SetCurrentPart( const wxString& aPart ) { m_currentPart = aPart; }
|
||||||
return m_currentPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the currently modified part name.
|
|
||||||
*/
|
|
||||||
void SetCurrentPart( const wxString& aPart )
|
|
||||||
{
|
|
||||||
m_currentPart = aPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current library and part name as LIB_ID.
|
* Returns the current library and part name as LIB_ID.
|
||||||
|
@ -313,9 +278,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///> Parent frame
|
|
||||||
LIB_EDIT_FRAME& m_frame;
|
|
||||||
|
|
||||||
///> Extracts library name basing on the file name
|
///> Extracts library name basing on the file name
|
||||||
static wxString getLibraryName( const wxString& aFilePath );
|
static wxString getLibraryName( const wxString& aFilePath );
|
||||||
|
|
||||||
|
@ -360,11 +322,8 @@ private:
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<SCH_SCREEN> m_screen;
|
std::unique_ptr<SCH_SCREEN> m_screen;
|
||||||
|
|
||||||
///> Working copy
|
LIB_PART* m_part; // Working copy
|
||||||
LIB_PART* m_part;
|
LIB_PART* m_original; // Initial state of the part
|
||||||
|
|
||||||
///> Initial state of the part
|
|
||||||
LIB_PART* m_original;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -372,10 +331,10 @@ private:
|
||||||
class LIB_BUFFER
|
class LIB_BUFFER
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LIB_BUFFER( const wxString& aLibrary )
|
LIB_BUFFER( const wxString& aLibrary ) :
|
||||||
: m_libName( aLibrary ), m_hash( 1 )
|
m_libName( aLibrary ),
|
||||||
{
|
m_hash( 1 )
|
||||||
}
|
{ }
|
||||||
|
|
||||||
bool IsModified() const
|
bool IsModified() const
|
||||||
{
|
{
|
||||||
|
@ -391,13 +350,7 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetHash() const
|
int GetHash() const { return m_hash; }
|
||||||
{
|
|
||||||
return m_hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
///> Returns all alias names for stored parts
|
|
||||||
wxArrayString GetAliasNames() const;
|
|
||||||
|
|
||||||
///> Returns the working copy of a LIB_PART object with specified alias
|
///> Returns the working copy of a LIB_PART object with specified alias
|
||||||
LIB_PART* GetPart( const wxString& aAlias ) const
|
LIB_PART* GetPart( const wxString& aAlias ) const
|
||||||
|
@ -435,16 +388,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
///> Returns all buffered parts
|
///> Returns all buffered parts
|
||||||
const std::deque<PART_BUFFER::PTR>& GetBuffers() const
|
const std::deque<PART_BUFFER::PTR>& GetBuffers() const { return m_parts; }
|
||||||
{
|
|
||||||
return m_parts;
|
|
||||||
}
|
|
||||||
|
|
||||||
///> Returns all aliases of buffered parts
|
|
||||||
const std::map<wxString, PART_BUFFER::WEAK_PTR>& GetAliases() const
|
|
||||||
{
|
|
||||||
return m_aliases;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///> Creates alias entries for a particular part buffer
|
///> Creates alias entries for a particular part buffer
|
||||||
|
@ -455,16 +399,9 @@ private:
|
||||||
|
|
||||||
std::map<wxString, PART_BUFFER::WEAK_PTR> m_aliases;
|
std::map<wxString, PART_BUFFER::WEAK_PTR> m_aliases;
|
||||||
std::deque<PART_BUFFER::PTR> m_parts;
|
std::deque<PART_BUFFER::PTR> m_parts;
|
||||||
|
std::deque<PART_BUFFER::PTR> m_deleted; // Buffer for deleted parts until library is saved
|
||||||
///> Buffer to keep deleted parts until the library is saved
|
const wxString m_libName; // Buffered library name
|
||||||
std::deque<PART_BUFFER::PTR> m_deleted;
|
int m_hash;
|
||||||
|
|
||||||
/// Buffered library name
|
|
||||||
const wxString m_libName;
|
|
||||||
|
|
||||||
int m_hash;
|
|
||||||
|
|
||||||
friend class PART_BUFFER;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
///> Returns a set of LIB_PART objects belonging to the original library
|
///> Returns a set of LIB_PART objects belonging to the original library
|
||||||
|
@ -477,11 +414,12 @@ private:
|
||||||
///> The library buffers
|
///> The library buffers
|
||||||
std::map<wxString, LIB_BUFFER> m_libs;
|
std::map<wxString, LIB_BUFFER> m_libs;
|
||||||
|
|
||||||
LIB_LOGGER m_logger;
|
LIB_EDIT_FRAME& m_frame; // Parent frame
|
||||||
int m_syncHash; // Symbol Lib Table hash value from the last synchronization
|
LIB_LOGGER m_logger;
|
||||||
|
int m_syncHash; // Symbol Lib Table hash value from the last synchronization
|
||||||
|
|
||||||
wxString m_currentLib; // Currently modified part
|
wxString m_currentLib; // Currently modified part
|
||||||
wxString m_currentPart; // Currently modified library
|
wxString m_currentPart; // Currently modified library
|
||||||
|
|
||||||
SYMBOL_TREE_SYNCHRONIZING_ADAPTER::PTR m_adapter;
|
SYMBOL_TREE_SYNCHRONIZING_ADAPTER::PTR m_adapter;
|
||||||
SYMBOL_TREE_SYNCHRONIZING_ADAPTER* getAdapter()
|
SYMBOL_TREE_SYNCHRONIZING_ADAPTER* getAdapter()
|
||||||
|
|
Loading…
Reference in New Issue