mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-03-30 05:46:55 +00:00
design blocks: add PCB design blocks behind advanced config
Fixes: https://gitlab.com/kicad/code/kicad/-/issues/2508
This commit is contained in:
parent
e64239969a
commit
e11cf94a3e
common
CMakeLists.txtadvanced_config.cppdesign_block.hdesign_block_io.cppdesign_block_io.hdesign_block_lib_table.cppdesign_block_tree_model_adapter.cppdesign_block_tree_model_adapter.h
dialogs
dialog_design_block_properties.cppdialog_design_block_properties.hdialog_design_block_properties_base.cppdialog_design_block_properties_base.fbpdialog_design_block_properties_base.hpanel_design_block_lib_table.cpp
settings
tool
widgets
eeschema
CMakeLists.txtcross-probing.cppeeschema_config.cppeeschema_settings.cppeeschema_settings.hmenubar.cppsch_design_block_utils.cppsch_edit_frame.cppsch_edit_frame.htoolbars_sch_editor.cpp
tools
sch_actions.cppsch_actions.hsch_design_block_control.cppsch_design_block_control.hsch_drawing_tools.cpp
widgets
include
kicad
pcbnew
CMakeLists.txtboard.cppboard.hcross-probing.cppfiles.cppmenubar_pcb_editor.cpppcb_design_block_utils.cpppcb_edit_frame.cpppcb_edit_frame.hpcbnew_settings.cpppcbnew_settings.htoolbars_pcb_editor.cpp
tools
board_editor_control.cppboard_editor_control.hpcb_actions.cpppcb_actions.hpcb_control.cpppcb_control.hpcb_design_block_control.cpppcb_design_block_control.h
widgets
@ -353,6 +353,8 @@ set( COMMON_DLG_SRCS
|
||||
dialogs/dialog_color_picker_base.cpp
|
||||
dialogs/dialog_configure_paths.cpp
|
||||
dialogs/dialog_configure_paths_base.cpp
|
||||
dialogs/dialog_design_block_properties.cpp
|
||||
dialogs/dialog_design_block_properties_base.cpp
|
||||
dialogs/dialog_display_html_text_base.cpp
|
||||
dialogs/dialog_edit_library_tables.cpp
|
||||
dialogs/dialog_embed_files.cpp
|
||||
@ -431,6 +433,7 @@ set( COMMON_WIDGET_SRCS
|
||||
widgets/bitmap_toggle.cpp
|
||||
widgets/button_row_panel.cpp
|
||||
widgets/color_swatch.cpp
|
||||
widgets/design_block_pane.cpp
|
||||
widgets/filter_combobox.cpp
|
||||
widgets/font_choice.cpp
|
||||
widgets/footprint_choice.cpp
|
||||
@ -455,6 +458,7 @@ set( COMMON_WIDGET_SRCS
|
||||
widgets/mathplot.cpp
|
||||
widgets/msgpanel.cpp
|
||||
widgets/paged_dialog.cpp
|
||||
widgets/panel_design_block_chooser.cpp
|
||||
widgets/properties_panel.cpp
|
||||
widgets/search_pane.cpp
|
||||
widgets/search_pane_base.cpp
|
||||
@ -616,6 +620,7 @@ set( COMMON_SRCS
|
||||
lib_table_grid_tricks.cpp
|
||||
lib_tree_model.cpp
|
||||
lib_tree_model_adapter.cpp
|
||||
design_block_tree_model_adapter.cpp
|
||||
marker_base.cpp
|
||||
origin_transforms.cpp
|
||||
printout.cpp
|
||||
@ -649,6 +654,7 @@ set( COMMON_SRCS
|
||||
tool/construction_manager.cpp
|
||||
tool/common_tools.cpp
|
||||
tool/conditional_menu.cpp
|
||||
tool/design_block_control.cpp
|
||||
tool/edit_constraints.cpp
|
||||
tool/edit_points.cpp
|
||||
tool/editor_conditions.cpp
|
||||
|
@ -98,7 +98,7 @@ static const wxChar AllowManualCanvasScale[] = wxT( "AllowManualCanvasScale" );
|
||||
static const wxChar UpdateUIEventInterval[] = wxT( "UpdateUIEventInterval" );
|
||||
static const wxChar V3DRT_BevelHeight_um[] = wxT( "V3DRT_BevelHeight_um" );
|
||||
static const wxChar V3DRT_BevelExtentFactor[] = wxT( "V3DRT_BevelExtentFactor" );
|
||||
static const wxChar EnableDesignBlocks[] = wxT( "EnableDesignBlocks" );
|
||||
static const wxChar EnablePcbDesignBlocks[] = wxT( "EnablePcbDesignBlocks" );
|
||||
static const wxChar EnableGenerators[] = wxT( "EnableGenerators" );
|
||||
static const wxChar EnableGit[] = wxT( "EnableGit" );
|
||||
static const wxChar EnableLibWithText[] = wxT( "EnableLibWithText" );
|
||||
@ -257,7 +257,7 @@ ADVANCED_CFG::ADVANCED_CFG()
|
||||
m_CompactSave = false;
|
||||
m_UpdateUIEventInterval = 0;
|
||||
m_ShowRepairSchematic = false;
|
||||
m_EnableDesignBlocks = true;
|
||||
m_EnablePcbDesignBlocks = false;
|
||||
m_EnableGenerators = false;
|
||||
m_EnableGit = true;
|
||||
m_EnableLibWithText = false;
|
||||
@ -493,8 +493,8 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
|
||||
m_DisambiguationMenuDelay,
|
||||
50, 10000 ) );
|
||||
|
||||
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::EnableDesignBlocks,
|
||||
&m_EnableDesignBlocks, m_EnableDesignBlocks ) );
|
||||
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::EnablePcbDesignBlocks, &m_EnablePcbDesignBlocks,
|
||||
m_EnablePcbDesignBlocks ) );
|
||||
|
||||
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::EnableGenerators,
|
||||
&m_EnableGenerators, m_EnableGenerators ) );
|
||||
|
@ -21,6 +21,10 @@
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifndef DESIGN_BLOCK_H
|
||||
#define DESIGN_BLOCK_H
|
||||
|
||||
#include <kicommon.h>
|
||||
#include <lib_id.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
@ -41,6 +45,9 @@ public:
|
||||
const wxString& GetSchematicFile() const { return m_schematicFile; }
|
||||
void SetSchematicFile( const wxString& aFile ) { m_schematicFile = aFile; }
|
||||
|
||||
const wxString& GetBoardFile() const { return m_boardFile; }
|
||||
void SetBoardFile( const wxString& aFile ) { m_boardFile = aFile; }
|
||||
|
||||
void SetFields( nlohmann::ordered_map<wxString, wxString>& aFields )
|
||||
{
|
||||
m_fields = std::move( aFields );
|
||||
@ -55,9 +62,12 @@ public:
|
||||
|
||||
private:
|
||||
LIB_ID m_lib_id;
|
||||
wxString m_schematicFile; ///< File name and path for schematic symbol.
|
||||
wxString m_schematicFile; ///< File name and path for schematic file.
|
||||
wxString m_boardFile; ///< File name and path for board file
|
||||
wxString m_libDescription; ///< File name and path for documentation file.
|
||||
wxString m_keywords; ///< Search keywords to find footprint in library.
|
||||
wxString m_keywords; ///< Search keywords to find design block in library.
|
||||
|
||||
nlohmann::ordered_map<wxString, wxString> m_fields;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -267,7 +267,9 @@ void DESIGN_BLOCK_IO::DesignBlockEnumerate( wxArrayString& aDesignBlockNames,
|
||||
wxDir dir( aLibraryPath );
|
||||
|
||||
if( !dir.IsOpened() )
|
||||
return;
|
||||
{
|
||||
THROW_IO_ERROR( wxString::Format( _( "Design block '%s' does not exist." ), aLibraryPath ) );
|
||||
}
|
||||
|
||||
wxString dirname;
|
||||
wxString fileSpec = wxT( "*." ) + wxString( FILEEXT::KiCadDesignBlockPathExtension );
|
||||
@ -289,17 +291,23 @@ DESIGN_BLOCK* DESIGN_BLOCK_IO::DesignBlockLoad( const wxString& aLibraryPath,
|
||||
+ FILEEXT::KiCadDesignBlockPathExtension + wxFileName::GetPathSeparator();
|
||||
wxString dbSchPath = dbPath + aDesignBlockName + wxT( "." )
|
||||
+ FILEEXT::KiCadSchematicFileExtension;
|
||||
wxString dbPcbPath = dbPath + aDesignBlockName + wxT( "." ) + FILEEXT::KiCadPcbFileExtension;
|
||||
wxString dbMetadataPath = dbPath + aDesignBlockName + wxT( "." ) + FILEEXT::JsonFileExtension;
|
||||
|
||||
if( !wxFileExists( dbSchPath ) )
|
||||
return nullptr;
|
||||
if( !wxDir::Exists( dbPath ) )
|
||||
THROW_IO_ERROR( wxString::Format( _( "Design block '%s' does not exist." ), dbPath ) );
|
||||
|
||||
DESIGN_BLOCK* newDB = new DESIGN_BLOCK();
|
||||
|
||||
// Library name needs to be empty for when we fill it in with the correct library nickname
|
||||
// one layer above
|
||||
newDB->SetLibId( LIB_ID( wxEmptyString, aDesignBlockName ) );
|
||||
newDB->SetSchematicFile( dbSchPath );
|
||||
|
||||
if( wxFileExists( dbSchPath ) )
|
||||
newDB->SetSchematicFile( dbSchPath );
|
||||
|
||||
if( wxFileExists( dbPcbPath ) )
|
||||
newDB->SetBoardFile( dbPcbPath );
|
||||
|
||||
// Parse the JSON file if it exists
|
||||
if( wxFileExists( dbMetadataPath ) )
|
||||
@ -335,16 +343,27 @@ DESIGN_BLOCK* DESIGN_BLOCK_IO::DesignBlockLoad( const wxString& aLibraryPath,
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
delete newDB;
|
||||
THROW_IO_ERROR( wxString::Format(
|
||||
_( "Design block metadata file '%s' could not be read." ), dbMetadataPath ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return newDB;
|
||||
}
|
||||
|
||||
|
||||
bool DESIGN_BLOCK_IO::DesignBlockExists( const wxString& aLibraryPath,
|
||||
const wxString& aDesignBlockName,
|
||||
const std::map<std::string, UTF8>* aProperties )
|
||||
{
|
||||
wxString dbPath = aLibraryPath + wxFileName::GetPathSeparator() + aDesignBlockName + wxT( "." )
|
||||
+ FILEEXT::KiCadDesignBlockPathExtension + wxFileName::GetPathSeparator();
|
||||
|
||||
return wxDir::Exists( dbPath );
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_IO::DesignBlockSave( const wxString& aLibraryPath,
|
||||
const DESIGN_BLOCK* aDesignBlock,
|
||||
const std::map<std::string, UTF8>* aProperties )
|
||||
@ -355,12 +374,23 @@ void DESIGN_BLOCK_IO::DesignBlockSave( const wxString& aLibra
|
||||
THROW_IO_ERROR( _( "Design block does not have a valid library ID." ) );
|
||||
}
|
||||
|
||||
wxFileName schematicFile( aDesignBlock->GetSchematicFile() );
|
||||
|
||||
if( !schematicFile.FileExists() )
|
||||
if( aDesignBlock->GetSchematicFile().IsEmpty() && aDesignBlock->GetBoardFile().IsEmpty() )
|
||||
{
|
||||
THROW_IO_ERROR( wxString::Format( _( "Schematic source file '%s' does not exist." ),
|
||||
schematicFile.GetFullPath() ) );
|
||||
THROW_IO_ERROR( _( "Design block does not have a schematic or board file." ) );
|
||||
}
|
||||
|
||||
wxFileName schematicFile( aDesignBlock->GetSchematicFile() );
|
||||
wxFileName boardFile( aDesignBlock->GetBoardFile() );
|
||||
|
||||
if( !aDesignBlock->GetSchematicFile().IsEmpty() && !schematicFile.FileExists() )
|
||||
{
|
||||
THROW_IO_ERROR(
|
||||
wxString::Format( _( "Schematic source file '%s' does not exist." ), schematicFile.GetFullPath() ) );
|
||||
}
|
||||
|
||||
if( !aDesignBlock->GetBoardFile().IsEmpty() && !boardFile.FileExists() )
|
||||
{
|
||||
THROW_IO_ERROR( wxString::Format( _( "Board source file '%s' does not exist." ), boardFile.GetFullPath() ) );
|
||||
}
|
||||
|
||||
// Create the design block folder
|
||||
@ -378,23 +408,44 @@ void DESIGN_BLOCK_IO::DesignBlockSave( const wxString& aLibra
|
||||
}
|
||||
}
|
||||
|
||||
// The new schematic file name is based on the design block name, not the source sheet name
|
||||
wxString dbSchematicFile = dbFolder.GetFullPath() + aDesignBlock->GetLibId().GetLibItemName()
|
||||
+ wxT( "." ) + FILEEXT::KiCadSchematicFileExtension;
|
||||
|
||||
// If the source and destination files are the same, then we don't need to copy the file
|
||||
// as we are just updating the metadata
|
||||
if( schematicFile.GetFullPath() != dbSchematicFile )
|
||||
if( !aDesignBlock->GetSchematicFile().IsEmpty() )
|
||||
{
|
||||
// Copy the source sheet file to the design block folder, under the design block name
|
||||
if( !wxCopyFile( schematicFile.GetFullPath(), dbSchematicFile ) )
|
||||
// The new schematic file name is based on the design block name, not the source sheet name
|
||||
wxString dbSchematicFile = dbFolder.GetFullPath() + aDesignBlock->GetLibId().GetLibItemName() + wxT( "." )
|
||||
+ FILEEXT::KiCadSchematicFileExtension;
|
||||
|
||||
// If the source and destination files are the same, then we don't need to copy the file
|
||||
// as we are just updating the metadata
|
||||
if( schematicFile.GetFullPath() != dbSchematicFile )
|
||||
{
|
||||
THROW_IO_ERROR( wxString::Format(
|
||||
_( "Schematic file '%s' could not be saved as design block at '%s'." ),
|
||||
schematicFile.GetFullPath(), dbSchematicFile ) );
|
||||
// Copy the source sheet file to the design block folder, under the design block name
|
||||
if( !wxCopyFile( schematicFile.GetFullPath(), dbSchematicFile ) )
|
||||
{
|
||||
THROW_IO_ERROR(
|
||||
wxString::Format( _( "Schematic file '%s' could not be saved as design block at '%s'." ),
|
||||
schematicFile.GetFullPath(), dbSchematicFile ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !aDesignBlock->GetBoardFile().IsEmpty() )
|
||||
{
|
||||
// The new Board file name is based on the design block name, not the source sheet name
|
||||
wxString dbBoardFile = dbFolder.GetFullPath() + aDesignBlock->GetLibId().GetLibItemName() + wxT( "." )
|
||||
+ FILEEXT::KiCadPcbFileExtension;
|
||||
|
||||
// If the source and destination files are the same, then we don't need to copy the file
|
||||
// as we are just updating the metadata
|
||||
if( boardFile.GetFullPath() != dbBoardFile )
|
||||
{
|
||||
// Copy the source sheet file to the design block folder, under the design block name
|
||||
if( !wxCopyFile( boardFile.GetFullPath(), dbBoardFile ) )
|
||||
{
|
||||
THROW_IO_ERROR( wxString::Format( _( "Board file '%s' could not be saved as design block at '%s'." ),
|
||||
boardFile.GetFullPath(), dbBoardFile ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wxString dbMetadataFile = dbFolder.GetFullPath() + aDesignBlock->GetLibId().GetLibItemName()
|
||||
+ wxT( "." ) + FILEEXT::JsonFileExtension;
|
||||
|
@ -76,10 +76,7 @@ public:
|
||||
}
|
||||
|
||||
bool DesignBlockExists( const wxString& aLibraryPath, const wxString& aDesignBlockName,
|
||||
const std::map<std::string, UTF8>* aProperties = nullptr )
|
||||
{
|
||||
return DesignBlockLoad( aLibraryPath, aDesignBlockName, true, aProperties ) != nullptr;
|
||||
}
|
||||
const std::map<std::string, UTF8>* aProperties = nullptr );
|
||||
|
||||
DESIGN_BLOCK* ImportDesignBlock( const wxString& aDesignBlockPath,
|
||||
wxString& aDesignBlockNameOut,
|
||||
|
@ -73,6 +73,23 @@ void DESIGN_BLOCK_LIB_TABLE_ROW::SetType( const wxString& aType )
|
||||
}
|
||||
|
||||
|
||||
bool DESIGN_BLOCK_LIB_TABLE_ROW::Refresh()
|
||||
{
|
||||
if( !plugin )
|
||||
{
|
||||
wxArrayString dummyList;
|
||||
|
||||
plugin.reset( DESIGN_BLOCK_IO_MGR::FindPlugin( type ) );
|
||||
SetLoaded( false );
|
||||
plugin->DesignBlockEnumerate( dummyList, GetFullURI( true ), true, GetProperties() );
|
||||
SetLoaded( true );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK_LIB_TABLE::DESIGN_BLOCK_LIB_TABLE( DESIGN_BLOCK_LIB_TABLE* aFallBackTable ) :
|
||||
LIB_TABLE( aFallBackTable )
|
||||
{
|
||||
|
@ -25,30 +25,32 @@
|
||||
#include <project/project_file.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/tokenzr.h>
|
||||
#include <settings/app_settings.h>
|
||||
#include <string_utils.h>
|
||||
#include <eda_pattern_match.h>
|
||||
#include <design_block.h>
|
||||
#include <design_block_lib_table.h>
|
||||
#include <design_block_info.h>
|
||||
#include <design_block_tree_model_adapter.h>
|
||||
#include <tools/sch_design_block_control.h>
|
||||
|
||||
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
|
||||
DESIGN_BLOCK_TREE_MODEL_ADAPTER::Create( EDA_BASE_FRAME* aParent, LIB_TABLE* aLibs,
|
||||
APP_SETTINGS_BASE::LIB_TREE& aSettings )
|
||||
APP_SETTINGS_BASE::LIB_TREE& aSettings,
|
||||
TOOL_INTERACTIVE* aContextMenuTool )
|
||||
{
|
||||
auto* adapter = new DESIGN_BLOCK_TREE_MODEL_ADAPTER( aParent, aLibs, aSettings );
|
||||
adapter->m_frame = aParent;
|
||||
auto* adapter = new DESIGN_BLOCK_TREE_MODEL_ADAPTER( aParent, aLibs, aSettings, aContextMenuTool );
|
||||
return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK_TREE_MODEL_ADAPTER::DESIGN_BLOCK_TREE_MODEL_ADAPTER( EDA_BASE_FRAME* aParent,
|
||||
LIB_TABLE* aLibs,
|
||||
APP_SETTINGS_BASE::LIB_TREE& aSettings ) :
|
||||
LIB_TREE_MODEL_ADAPTER( aParent, wxT( "pinned_design_block_libs" ), aSettings ),
|
||||
DESIGN_BLOCK_TREE_MODEL_ADAPTER::DESIGN_BLOCK_TREE_MODEL_ADAPTER( EDA_BASE_FRAME* aParent, LIB_TABLE* aLibs,
|
||||
APP_SETTINGS_BASE::LIB_TREE& aSettings,
|
||||
TOOL_INTERACTIVE* aContextMenuTool ) :
|
||||
LIB_TREE_MODEL_ADAPTER( aParent, wxT( "pinned_design_block_libs" ),
|
||||
Kiface().KifaceSettings()->m_DesignBlockChooserPanel.tree ),
|
||||
m_libs( (DESIGN_BLOCK_LIB_TABLE*) aLibs ),
|
||||
m_frame( aParent )
|
||||
m_frame( aParent ),
|
||||
m_contextMenuTool( aContextMenuTool )
|
||||
{
|
||||
}
|
||||
|
||||
@ -74,8 +76,7 @@ void DESIGN_BLOCK_TREE_MODEL_ADAPTER::AddLibraries( EDA_BASE_FRAME* aParent )
|
||||
bool pinned = alg::contains( cfg->m_Session.pinned_design_block_libs, libName )
|
||||
|| alg::contains( project.m_PinnedDesignBlockLibs, libName );
|
||||
|
||||
DoAddLibrary( libName, library->GetDescr(), getDesignBlocks( aParent, libName ), pinned,
|
||||
true );
|
||||
DoAddLibrary( libName, library->GetDescr(), getDesignBlocks( aParent, libName ), pinned, true );
|
||||
}
|
||||
|
||||
m_tree.AssignIntrinsicRanks();
|
||||
@ -88,23 +89,20 @@ void DESIGN_BLOCK_TREE_MODEL_ADAPTER::ClearLibraries()
|
||||
}
|
||||
|
||||
|
||||
std::vector<LIB_TREE_ITEM*>
|
||||
DESIGN_BLOCK_TREE_MODEL_ADAPTER::getDesignBlocks( EDA_BASE_FRAME* aParent,
|
||||
const wxString& aLibName )
|
||||
std::vector<LIB_TREE_ITEM*> DESIGN_BLOCK_TREE_MODEL_ADAPTER::getDesignBlocks( EDA_BASE_FRAME* aParent,
|
||||
const wxString& aLibName )
|
||||
{
|
||||
std::vector<LIB_TREE_ITEM*> libList;
|
||||
|
||||
auto fullListStart = DESIGN_BLOCK_LIB_TABLE::GetGlobalList().GetList().begin();
|
||||
auto fullListEnd = DESIGN_BLOCK_LIB_TABLE::GetGlobalList().GetList().end();
|
||||
|
||||
std::unique_ptr<DESIGN_BLOCK_INFO> dummy =
|
||||
std::make_unique<DESIGN_BLOCK_INFO_IMPL>( aLibName, wxEmptyString );
|
||||
std::unique_ptr<DESIGN_BLOCK_INFO> dummy = std::make_unique<DESIGN_BLOCK_INFO_IMPL>( aLibName, wxEmptyString );
|
||||
|
||||
// List is sorted, so use a binary search to find the range of footnotes for our library
|
||||
auto libBounds = std::equal_range(
|
||||
fullListStart, fullListEnd, dummy,
|
||||
[]( const std::unique_ptr<DESIGN_BLOCK_INFO>& a,
|
||||
const std::unique_ptr<DESIGN_BLOCK_INFO>& b )
|
||||
[]( const std::unique_ptr<DESIGN_BLOCK_INFO>& a, const std::unique_ptr<DESIGN_BLOCK_INFO>& b )
|
||||
{
|
||||
return StrNumCmp( a->GetLibNickname(), b->GetLibNickname(), false ) < 0;
|
||||
} );
|
||||
@ -148,8 +146,7 @@ wxString DESIGN_BLOCK_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, in
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
wxLogError( _( "Error loading design block %s from library '%s'." ) + wxS( "\n%s" ),
|
||||
aLibId.GetLibItemName().wx_str(), aLibId.GetLibNickname().wx_str(),
|
||||
ioe.What() );
|
||||
aLibId.GetLibItemName().wx_str(), aLibId.GetLibNickname().wx_str(), ioe.What() );
|
||||
|
||||
return wxEmptyString;
|
||||
}
|
||||
@ -206,5 +203,5 @@ wxString DESIGN_BLOCK_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, in
|
||||
|
||||
TOOL_INTERACTIVE* DESIGN_BLOCK_TREE_MODEL_ADAPTER::GetContextMenuTool()
|
||||
{
|
||||
return m_frame->GetToolManager()->GetTool<SCH_DESIGN_BLOCK_CONTROL>();
|
||||
return m_contextMenuTool;
|
||||
}
|
@ -33,9 +33,9 @@ public:
|
||||
*
|
||||
* @param aLibs library set from which parts will be loaded
|
||||
*/
|
||||
static wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> Create( EDA_BASE_FRAME* aParent,
|
||||
LIB_TABLE* aLibs,
|
||||
APP_SETTINGS_BASE::LIB_TREE& aSettings );
|
||||
static wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> Create( EDA_BASE_FRAME* aParent, LIB_TABLE* aLibs,
|
||||
APP_SETTINGS_BASE::LIB_TREE& aSettings,
|
||||
TOOL_INTERACTIVE* aContextMenuTool );
|
||||
|
||||
void AddLibraries( EDA_BASE_FRAME* aParent );
|
||||
void ClearLibraries();
|
||||
@ -51,16 +51,17 @@ protected:
|
||||
* Constructor; takes a set of libraries to be included in the search.
|
||||
*/
|
||||
DESIGN_BLOCK_TREE_MODEL_ADAPTER( EDA_BASE_FRAME* aParent, LIB_TABLE* aLibs,
|
||||
APP_SETTINGS_BASE::LIB_TREE& aSettings );
|
||||
APP_SETTINGS_BASE::LIB_TREE& aSettings,
|
||||
TOOL_INTERACTIVE* aContextMenuTool );
|
||||
|
||||
std::vector<LIB_TREE_ITEM*> getDesignBlocks( EDA_BASE_FRAME* aParent,
|
||||
const wxString& aLibName );
|
||||
std::vector<LIB_TREE_ITEM*> getDesignBlocks( EDA_BASE_FRAME* aParent, const wxString& aLibName );
|
||||
|
||||
PROJECT::LIB_TYPE_T getLibType() override { return PROJECT::LIB_TYPE_T::DESIGN_BLOCK_LIB; }
|
||||
|
||||
protected:
|
||||
DESIGN_BLOCK_LIB_TABLE* m_libs;
|
||||
EDA_BASE_FRAME* m_frame;
|
||||
TOOL_INTERACTIVE* m_contextMenuTool;
|
||||
};
|
||||
|
||||
#endif // DESIGN_BLOCK_TREE_MODEL_ADAPTER_H
|
@ -24,20 +24,20 @@
|
||||
|
||||
|
||||
#include <dialogs/dialog_design_block_properties.h>
|
||||
#include <sch_edit_frame.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/tooltip.h>
|
||||
#include <grid_tricks.h>
|
||||
#include <widgets/std_bitmap_button.h>
|
||||
#include <bitmaps.h>
|
||||
|
||||
#include <design_block.h>
|
||||
|
||||
DIALOG_DESIGN_BLOCK_PROPERTIES::DIALOG_DESIGN_BLOCK_PROPERTIES( SCH_EDIT_FRAME* aParent,
|
||||
DESIGN_BLOCK* aDesignBlock ) :
|
||||
DIALOG_DESIGN_BLOCK_PROPERTIES::DIALOG_DESIGN_BLOCK_PROPERTIES( wxWindow* aParent,
|
||||
DESIGN_BLOCK* aDesignBlock,
|
||||
bool aDisableName ) :
|
||||
DIALOG_DESIGN_BLOCK_PROPERTIES_BASE( aParent ), m_designBlock( aDesignBlock )
|
||||
{
|
||||
if( !m_textName->IsEmpty() )
|
||||
m_textName->SetEditable( false );
|
||||
m_textName->SetEditable( !aDisableName );
|
||||
|
||||
wxToolTip::Enable( true );
|
||||
SetupStandardButtons();
|
||||
@ -50,10 +50,11 @@ DIALOG_DESIGN_BLOCK_PROPERTIES::DIALOG_DESIGN_BLOCK_PROPERTIES( SCH_EDIT_FRAME*
|
||||
|
||||
m_fieldsGrid->SetUseNativeColLabels();
|
||||
|
||||
m_fieldsGrid->PushEventHandler( new GRID_TRICKS( m_fieldsGrid, [this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddField( aEvent );
|
||||
} ) );
|
||||
m_fieldsGrid->PushEventHandler( new GRID_TRICKS( m_fieldsGrid,
|
||||
[this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddField( aEvent );
|
||||
} ) );
|
||||
m_fieldsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
||||
}
|
||||
|
||||
@ -86,8 +87,7 @@ bool DIALOG_DESIGN_BLOCK_PROPERTIES::TransferDataToWindow()
|
||||
|
||||
bool DIALOG_DESIGN_BLOCK_PROPERTIES::TransferDataFromWindow()
|
||||
{
|
||||
m_designBlock->SetLibId(
|
||||
LIB_ID( m_designBlock->GetLibId().GetLibNickname(), m_textName->GetValue() ) );
|
||||
m_designBlock->SetLibId( LIB_ID( m_designBlock->GetLibId().GetLibNickname(), m_textName->GetValue() ) );
|
||||
m_designBlock->SetLibDescription( m_textDescription->GetValue() );
|
||||
m_designBlock->SetKeywords( m_textKeywords->GetValue() );
|
||||
|
@ -22,6 +22,9 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifndef DIALOG_DESIGN_BLOCK_PROPERTIES_H
|
||||
#define DIALOG_DESIGN_BLOCK_PROPERTIES_H
|
||||
|
||||
#include <dialogs/dialog_design_block_properties_base.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@ -31,7 +34,7 @@ class DESIGN_BLOCK;
|
||||
class DIALOG_DESIGN_BLOCK_PROPERTIES : public DIALOG_DESIGN_BLOCK_PROPERTIES_BASE
|
||||
{
|
||||
public:
|
||||
DIALOG_DESIGN_BLOCK_PROPERTIES( SCH_EDIT_FRAME* aParent, DESIGN_BLOCK* aDesignBlock );
|
||||
DIALOG_DESIGN_BLOCK_PROPERTIES( wxWindow* aParent, DESIGN_BLOCK* aDesignBlock, bool aDisableName = false );
|
||||
~DIALOG_DESIGN_BLOCK_PROPERTIES() override;
|
||||
|
||||
bool TransferDataToWindow() override;
|
||||
@ -50,6 +53,8 @@ public:
|
||||
private:
|
||||
void AdjustGridColumns( int aWidth );
|
||||
|
||||
DESIGN_BLOCK* m_designBlock;
|
||||
DESIGN_BLOCK* m_designBlock;
|
||||
nlohmann::ordered_map<wxString, wxString> m_fields;
|
||||
};
|
||||
|
||||
#endif
|
@ -633,6 +633,44 @@ bool PANEL_DESIGN_BLOCK_LIB_TABLE::verifyTables()
|
||||
}
|
||||
}
|
||||
|
||||
for( DESIGN_BLOCK_LIB_TABLE* table : { global_model(), project_model() } )
|
||||
{
|
||||
if( !table )
|
||||
continue;
|
||||
|
||||
for( unsigned int r = 0; r < table->GetCount(); ++r )
|
||||
{
|
||||
DESIGN_BLOCK_LIB_TABLE_ROW& row = dynamic_cast<DESIGN_BLOCK_LIB_TABLE_ROW&>( table->At( r ) );
|
||||
|
||||
// Newly-added rows won't have set this yet
|
||||
row.SetParent( table );
|
||||
|
||||
if( !row.GetIsEnabled() )
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
if( row.Refresh() )
|
||||
{
|
||||
if( table == global_model() )
|
||||
m_parent->m_GlobalTableChanged = true;
|
||||
else
|
||||
m_parent->m_ProjectTableChanged = true;
|
||||
}
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
msg.Printf( _( "Design block library '%s' failed to load." ), row.GetNickName() );
|
||||
|
||||
wxWindow* topLevelParent = wxGetTopLevelParent( this );
|
||||
wxMessageDialog errdlg( topLevelParent, msg + wxS( "\n" ) + ioe.What(), _( "Error Loading Library" ) );
|
||||
errdlg.ShowModal();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1214,7 +1252,7 @@ void InvokeEditDesignBlockLibTable( KIWAY* aKiway, wxWindow *aParent )
|
||||
|
||||
std::string payload = "";
|
||||
aKiway->ExpressMail( FRAME_SCH, MAIL_RELOAD_LIB, payload );
|
||||
aKiway->ExpressMail( FRAME_SCH_VIEWER, MAIL_RELOAD_LIB, payload );
|
||||
aKiway->ExpressMail( FRAME_PCB_EDITOR, MAIL_RELOAD_LIB, payload );
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -71,6 +71,59 @@ APP_SETTINGS_BASE::APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaV
|
||||
m_params.emplace_back( new PARAM_LIST<wxString>( "find_replace.replace_history",
|
||||
&m_FindReplace.replace_history, {} ) );
|
||||
|
||||
m_params.emplace_back( new PARAM<int>( "design_block_chooser.sash_pos_h",
|
||||
&m_DesignBlockChooserPanel.sash_pos_h, -1 ) );
|
||||
|
||||
m_params.emplace_back( new PARAM<int>( "design_block_chooser.sash_pos_v",
|
||||
&m_DesignBlockChooserPanel.sash_pos_v, -1 ) );
|
||||
|
||||
m_params.emplace_back( new PARAM<int>( "design_block_chooser.width",
|
||||
&m_DesignBlockChooserPanel.width, -1 ) );
|
||||
|
||||
m_params.emplace_back( new PARAM<int>( "design_block_chooser.height",
|
||||
&m_DesignBlockChooserPanel.height, -1 ) );
|
||||
|
||||
m_params.emplace_back( new PARAM<int>( "design_block_chooser.sort_mode",
|
||||
&m_DesignBlockChooserPanel.sort_mode, 0 ) );
|
||||
|
||||
m_params.emplace_back( new PARAM<bool>( "design_block_chooser.repeated_placement",
|
||||
&m_DesignBlockChooserPanel.repeated_placement, false ) );
|
||||
|
||||
m_params.emplace_back( new PARAM<bool>( "design_block_chooser.place_as_sheet",
|
||||
&m_DesignBlockChooserPanel.place_as_sheet, false ) );
|
||||
|
||||
m_params.emplace_back( new PARAM<bool>( "design_block_chooser.keep_annotations",
|
||||
&m_DesignBlockChooserPanel.keep_annotations, false ) );
|
||||
|
||||
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
|
||||
"design_block_chooser.lib_tree.column_widths",
|
||||
[&]() -> nlohmann::json
|
||||
{
|
||||
nlohmann::json ret = {};
|
||||
|
||||
for( const auto& [name, width] : m_DesignBlockChooserPanel.tree.column_widths )
|
||||
ret[std::string( name.ToUTF8() )] = width;
|
||||
|
||||
return ret;
|
||||
},
|
||||
[&]( const nlohmann::json& aJson )
|
||||
{
|
||||
if( !aJson.is_object() )
|
||||
return;
|
||||
|
||||
m_DesignBlockChooserPanel.tree.column_widths.clear();
|
||||
|
||||
for( const auto& entry : aJson.items() )
|
||||
{
|
||||
if( !entry.value().is_number_integer() )
|
||||
continue;
|
||||
|
||||
m_DesignBlockChooserPanel.tree.column_widths[entry.key()] = entry.value().get<int>();
|
||||
}
|
||||
},
|
||||
{} ) );
|
||||
|
||||
|
||||
m_params.emplace_back( new PARAM<int>( "graphics.canvas_type",
|
||||
&m_Graphics.canvas_type, EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL ) );
|
||||
|
||||
|
218
common/tool/design_block_control.cpp
Normal file
218
common/tool/design_block_control.cpp
Normal file
@ -0,0 +1,218 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The KiCad Developers, see AUTHORS.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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
#include <tool/actions.h>
|
||||
#include <tool/library_editor_control.h>
|
||||
#include <tool/design_block_control.h>
|
||||
#include <widgets/design_block_pane.h>
|
||||
#include <widgets/panel_design_block_chooser.h>
|
||||
#include <dialog_design_block_properties.h>
|
||||
#include <mail_type.h>
|
||||
#include <kiway.h>
|
||||
|
||||
|
||||
DESIGN_BLOCK_CONTROL::~DESIGN_BLOCK_CONTROL()
|
||||
{
|
||||
}
|
||||
|
||||
DESIGN_BLOCK_CONTROL::DESIGN_BLOCK_CONTROL( const std::string& aName ) : TOOL_INTERACTIVE( aName )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_CONTROL::Reset( RESET_REASON aReason )
|
||||
{
|
||||
m_frame = getEditFrame<EDA_DRAW_FRAME>();
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_CONTROL::AddContextMenuItems( CONDITIONAL_MENU* aMenu )
|
||||
{
|
||||
auto pinnedLib =
|
||||
[this]( const SELECTION& aSel )
|
||||
{
|
||||
//
|
||||
LIB_TREE_NODE* current = getCurrentTreeNode();
|
||||
return current && current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
|
||||
&& current->m_Pinned;
|
||||
};
|
||||
|
||||
auto unpinnedLib =
|
||||
[this](const SELECTION& aSel )
|
||||
{
|
||||
LIB_TREE_NODE* current = getCurrentTreeNode();
|
||||
return current && current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
|
||||
&& !current->m_Pinned;
|
||||
};
|
||||
|
||||
auto isDesignBlock =
|
||||
[this](const SELECTION& aSel )
|
||||
{
|
||||
return this->selIsDesignBlock(aSel);
|
||||
};
|
||||
|
||||
aMenu->AddItem( ACTIONS::pinLibrary, unpinnedLib, 1 );
|
||||
aMenu->AddItem( ACTIONS::unpinLibrary, pinnedLib, 1 );
|
||||
aMenu->AddItem( ACTIONS::newLibrary, !isDesignBlock, 1 );
|
||||
aMenu->AddSeparator( 2 );
|
||||
|
||||
aMenu->AddSeparator( 400 );
|
||||
aMenu->AddItem( ACTIONS::hideLibraryTree, SELECTION_CONDITIONS::ShowAlways, 400 );
|
||||
}
|
||||
|
||||
|
||||
int DESIGN_BLOCK_CONTROL::PinLibrary( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
LIB_TREE_NODE* current = getCurrentTreeNode();
|
||||
|
||||
if( current && !current->m_Pinned )
|
||||
{
|
||||
m_frame->Prj().PinLibrary( current->m_LibId.GetLibNickname(), PROJECT::LIB_TYPE_T::DESIGN_BLOCK_LIB );
|
||||
current->m_Pinned = true;
|
||||
getDesignBlockPane()->RefreshLibs();
|
||||
notifyOtherFrames();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int DESIGN_BLOCK_CONTROL::UnpinLibrary( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
LIB_TREE_NODE* current = getCurrentTreeNode();
|
||||
|
||||
if( current && current->m_Pinned )
|
||||
{
|
||||
m_frame->Prj().UnpinLibrary( current->m_LibId.GetLibNickname(), PROJECT::LIB_TYPE_T::DESIGN_BLOCK_LIB );
|
||||
current->m_Pinned = false;
|
||||
getDesignBlockPane()->RefreshLibs();
|
||||
notifyOtherFrames();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int DESIGN_BLOCK_CONTROL::NewLibrary( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
if( getDesignBlockPane()->CreateNewDesignBlockLibrary() != wxEmptyString )
|
||||
{
|
||||
notifyOtherFrames();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int DESIGN_BLOCK_CONTROL::DeleteDesignBlock( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
LIB_TREE_NODE* current = getCurrentTreeNode();
|
||||
|
||||
if( !current )
|
||||
return -1;
|
||||
|
||||
if( getDesignBlockPane()->DeleteDesignBlockFromLibrary( current->m_LibId, true ) )
|
||||
{
|
||||
notifyOtherFrames();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int DESIGN_BLOCK_CONTROL::EditDesignBlockProperties( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
LIB_TREE_NODE* current = getCurrentTreeNode();
|
||||
|
||||
if( !current )
|
||||
return -1;
|
||||
|
||||
if( getDesignBlockPane()->EditDesignBlockProperties( current->m_LibId ) )
|
||||
{
|
||||
notifyOtherFrames();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int DESIGN_BLOCK_CONTROL::HideLibraryTree( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
m_frame->ToggleLibraryTree();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool DESIGN_BLOCK_CONTROL::selIsInLibrary( const SELECTION& aSel )
|
||||
{
|
||||
LIB_TREE_NODE* current = getCurrentTreeNode();
|
||||
return current
|
||||
&& ( current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
|
||||
|| current->m_Type == LIB_TREE_NODE::TYPE::ITEM );
|
||||
}
|
||||
|
||||
|
||||
bool DESIGN_BLOCK_CONTROL::selIsDesignBlock( const SELECTION& aSel )
|
||||
{
|
||||
LIB_TREE_NODE* current = getCurrentTreeNode();
|
||||
return current && current->m_Type == LIB_TREE_NODE::TYPE::ITEM;
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_CONTROL::setTransitions()
|
||||
{
|
||||
Go( &DESIGN_BLOCK_CONTROL::PinLibrary, ACTIONS::pinLibrary.MakeEvent() );
|
||||
Go( &DESIGN_BLOCK_CONTROL::UnpinLibrary, ACTIONS::unpinLibrary.MakeEvent() );
|
||||
Go( &DESIGN_BLOCK_CONTROL::NewLibrary, ACTIONS::newLibrary.MakeEvent() );
|
||||
Go( &DESIGN_BLOCK_CONTROL::HideLibraryTree, ACTIONS::hideLibraryTree.MakeEvent() );
|
||||
}
|
||||
|
||||
|
||||
LIB_ID DESIGN_BLOCK_CONTROL::getSelectedLibId()
|
||||
{
|
||||
getDesignBlockPane()->GetSelectedLibId();
|
||||
|
||||
return LIB_ID();
|
||||
}
|
||||
|
||||
|
||||
LIB_TREE_NODE* DESIGN_BLOCK_CONTROL::getCurrentTreeNode()
|
||||
{
|
||||
LIB_TREE* libTree = getDesignBlockPane()->GetDesignBlockPanel()->GetLibTree();
|
||||
return libTree ? libTree->GetCurrentTreeNode() : nullptr;
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_CONTROL::notifyOtherFrames()
|
||||
{
|
||||
std::string payload = "";
|
||||
|
||||
for( FRAME_T frame : m_framesToNotify )
|
||||
m_frame->Kiway().ExpressMail( frame, MAIL_RELOAD_LIB, payload );
|
||||
}
|
77
common/tool/design_block_control.h
Normal file
77
common/tool/design_block_control.h
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The KiCad Developers, see AUTHORS.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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DESIGN_BLOCK_CONTROL_H
|
||||
#define DESIGN_BLOCK_CONTROL_H
|
||||
|
||||
#include <eda_draw_frame.h>
|
||||
#include <tool/tool_interactive.h>
|
||||
|
||||
class DESIGN_BLOCK_PANE;
|
||||
|
||||
/**
|
||||
* Handle schematic design block actions in the schematic editor.
|
||||
*/
|
||||
class DESIGN_BLOCK_CONTROL : public TOOL_INTERACTIVE, public wxEvtHandler
|
||||
{
|
||||
public:
|
||||
DESIGN_BLOCK_CONTROL( const std::string& aName );
|
||||
virtual ~DESIGN_BLOCK_CONTROL();
|
||||
|
||||
/// @copydoc TOOL_INTERACTIVE::Reset()
|
||||
void Reset( RESET_REASON aReason ) override;
|
||||
|
||||
void AddContextMenuItems( CONDITIONAL_MENU* aMenu );
|
||||
|
||||
int PinLibrary( const TOOL_EVENT& aEvent );
|
||||
int UnpinLibrary( const TOOL_EVENT& aEvent );
|
||||
|
||||
int NewLibrary( const TOOL_EVENT& aEvent );
|
||||
int DeleteLibrary( const TOOL_EVENT& aEvent );
|
||||
|
||||
int DeleteDesignBlock( const TOOL_EVENT& aEvent );
|
||||
int EditDesignBlockProperties( const TOOL_EVENT& aEvent );
|
||||
|
||||
int HideLibraryTree( const TOOL_EVENT& aEvent );
|
||||
|
||||
protected:
|
||||
bool selIsInLibrary( const SELECTION& aSel );
|
||||
bool selIsDesignBlock( const SELECTION& aSel );
|
||||
|
||||
LIB_ID getSelectedLibId();
|
||||
///< Set up handlers for various events.
|
||||
void setTransitions() override;
|
||||
|
||||
virtual DESIGN_BLOCK_PANE* getDesignBlockPane() = 0;
|
||||
LIB_TREE_NODE* getCurrentTreeNode();
|
||||
|
||||
/// Notify other frames that the design block lib table has changed
|
||||
std::vector<FRAME_T> m_framesToNotify;
|
||||
void notifyOtherFrames();
|
||||
|
||||
EDA_DRAW_FRAME* m_frame = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
512
common/widgets/design_block_pane.cpp
Normal file
512
common/widgets/design_block_pane.cpp
Normal file
@ -0,0 +1,512 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The KiCad Developers, see AUTHORS.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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <design_block.h>
|
||||
#include <design_block_lib_table.h>
|
||||
#include <paths.h>
|
||||
#include <env_paths.h>
|
||||
#include <pgm_base.h>
|
||||
#include <common.h>
|
||||
#include <kidialog.h>
|
||||
#include <widgets/design_block_pane.h>
|
||||
#include <dialog_design_block_properties.h>
|
||||
#include <widgets/panel_design_block_chooser.h>
|
||||
#include <kiface_base.h>
|
||||
#include <core/kicad_algo.h>
|
||||
#include <template_fieldnames.h>
|
||||
#include <wx/button.h>
|
||||
#include <wx/checkbox.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/choicdlg.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/textdlg.h>
|
||||
#include <confirm.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <tool/tool_manager.h>
|
||||
|
||||
DESIGN_BLOCK_PANE::DESIGN_BLOCK_PANE( EDA_DRAW_FRAME* aParent, const LIB_ID* aPreselect,
|
||||
std::vector<LIB_ID>& aHistoryList ) : WX_PANEL( aParent ), m_frame( aParent )
|
||||
{
|
||||
m_frame->Bind( wxEVT_AUI_PANE_CLOSE, &DESIGN_BLOCK_PANE::OnClosed, this );
|
||||
m_frame->Bind( EDA_LANG_CHANGED, &DESIGN_BLOCK_PANE::OnLanguageChanged, this );
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK_PANE::~DESIGN_BLOCK_PANE()
|
||||
{
|
||||
m_frame->Unbind( wxEVT_AUI_PANE_CLOSE, &DESIGN_BLOCK_PANE::OnClosed, this );
|
||||
m_frame->Unbind( EDA_LANG_CHANGED, &DESIGN_BLOCK_PANE::OnLanguageChanged, this );
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_PANE::OnLanguageChanged( wxCommandEvent& aEvent )
|
||||
{
|
||||
if( m_chooserPanel )
|
||||
m_chooserPanel->ShowChangedLanguage();
|
||||
|
||||
setLabelsAndTooltips();
|
||||
|
||||
aEvent.Skip();
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_PANE::OnClosed( wxAuiManagerEvent& aEvent )
|
||||
{
|
||||
if( APP_SETTINGS_BASE* cfg = m_frame->config() )
|
||||
{
|
||||
if( IsShownOnScreen() ) // Ensure the panel is shown when trying to save its size
|
||||
m_frame->SaveSettings( cfg );
|
||||
}
|
||||
|
||||
aEvent.Skip();
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_PANE::SaveSettings()
|
||||
{
|
||||
m_chooserPanel->SaveSettings();
|
||||
}
|
||||
|
||||
|
||||
LIB_ID DESIGN_BLOCK_PANE::GetSelectedLibId( int* aUnit ) const
|
||||
{
|
||||
return m_chooserPanel->GetSelectedLibId( aUnit );
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_PANE::SelectLibId( const LIB_ID& aLibId )
|
||||
{
|
||||
m_chooserPanel->SelectLibId( aLibId );
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_PANE::RefreshLibs()
|
||||
{
|
||||
m_chooserPanel->RefreshLibs();
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK* DESIGN_BLOCK_PANE::GetDesignBlock( const LIB_ID& aLibId, bool aUseCacheLib, bool aShowErrorMsg )
|
||||
{
|
||||
DESIGN_BLOCK_LIB_TABLE* prjLibs = m_frame->Prj().DesignBlockLibs();
|
||||
|
||||
wxCHECK_MSG( prjLibs, nullptr, wxS( "Invalid design block library table." ) );
|
||||
|
||||
DESIGN_BLOCK* designBlock = nullptr;
|
||||
|
||||
try
|
||||
{
|
||||
designBlock = prjLibs->DesignBlockLoadWithOptionalNickname( aLibId, true );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
if( aShowErrorMsg )
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Error loading design block %s from library '%s'." ),
|
||||
aLibId.GetLibItemName().wx_str(), aLibId.GetLibNickname().wx_str() );
|
||||
DisplayErrorMessage( m_frame, msg, ioe.What() );
|
||||
}
|
||||
}
|
||||
|
||||
return designBlock;
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK* DESIGN_BLOCK_PANE::GetSelectedDesignBlock( bool aUseCacheLib, bool aShowErrorMsg )
|
||||
{
|
||||
if( !GetSelectedLibId().IsValid() )
|
||||
return nullptr;
|
||||
|
||||
return GetDesignBlock( GetSelectedLibId(), aUseCacheLib, aShowErrorMsg );
|
||||
}
|
||||
|
||||
|
||||
wxString DESIGN_BLOCK_PANE::CreateNewDesignBlockLibrary( const wxString& aLibName, const wxString& aProposedName )
|
||||
{
|
||||
return createNewDesignBlockLibrary( aLibName, aProposedName, selectDesignBlockLibTable() );
|
||||
}
|
||||
|
||||
|
||||
wxString DESIGN_BLOCK_PANE::createNewDesignBlockLibrary( const wxString& aLibName, const wxString& aProposedName,
|
||||
DESIGN_BLOCK_LIB_TABLE* aTable )
|
||||
{
|
||||
if( aTable == nullptr )
|
||||
return wxEmptyString;
|
||||
|
||||
wxFileName fn;
|
||||
bool doAdd = false;
|
||||
bool isGlobal = ( aTable == &DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable() );
|
||||
wxString initialPath = aProposedName;
|
||||
|
||||
if( initialPath.IsEmpty() )
|
||||
initialPath = isGlobal ? PATHS::GetDefaultUserDesignBlocksPath() : m_frame->Prj().GetProjectPath();
|
||||
|
||||
if( aLibName.IsEmpty() )
|
||||
{
|
||||
fn = initialPath;
|
||||
|
||||
if( !m_frame->LibraryFileBrowser( false, fn, FILEEXT::KiCadDesignBlockLibPathWildcard(),
|
||||
FILEEXT::KiCadDesignBlockLibPathExtension, false, isGlobal, initialPath ) )
|
||||
{
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
doAdd = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fn = EnsureFileExtension( aLibName, FILEEXT::KiCadDesignBlockLibPathExtension );
|
||||
|
||||
if( !fn.IsAbsolute() )
|
||||
{
|
||||
fn.SetName( aLibName );
|
||||
fn.MakeAbsolute( initialPath );
|
||||
}
|
||||
}
|
||||
|
||||
// We can save libs only using DESIGN_BLOCK_IO_MGR::KICAD_SEXP format (.pretty libraries)
|
||||
DESIGN_BLOCK_IO_MGR::DESIGN_BLOCK_FILE_T piType = DESIGN_BLOCK_IO_MGR::KICAD_SEXP;
|
||||
wxString libPath = fn.GetFullPath();
|
||||
|
||||
try
|
||||
{
|
||||
IO_RELEASER<DESIGN_BLOCK_IO> pi( DESIGN_BLOCK_IO_MGR::FindPlugin( piType ) );
|
||||
|
||||
bool writable = false;
|
||||
bool exists = false;
|
||||
|
||||
try
|
||||
{
|
||||
writable = pi->IsLibraryWritable( libPath );
|
||||
exists = fn.Exists();
|
||||
}
|
||||
catch( const IO_ERROR& )
|
||||
{
|
||||
// best efforts....
|
||||
}
|
||||
|
||||
if( exists )
|
||||
{
|
||||
if( !writable )
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Library %s is read only." ), libPath );
|
||||
m_frame->ShowInfoBarError( msg );
|
||||
return wxEmptyString;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Library %s already exists." ), libPath );
|
||||
KIDIALOG dlg( m_frame, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
|
||||
dlg.SetOKLabel( _( "Overwrite" ) );
|
||||
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
||||
|
||||
if( dlg.ShowModal() == wxID_CANCEL )
|
||||
return wxEmptyString;
|
||||
|
||||
pi->DeleteLibrary( libPath );
|
||||
}
|
||||
}
|
||||
|
||||
pi->CreateLibrary( libPath );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( m_frame, ioe.What() );
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
if( doAdd )
|
||||
AddDesignBlockLibrary( libPath, aTable );
|
||||
|
||||
return libPath;
|
||||
}
|
||||
|
||||
|
||||
bool DESIGN_BLOCK_PANE::AddDesignBlockLibrary( const wxString& aFilename, DESIGN_BLOCK_LIB_TABLE* aTable )
|
||||
{
|
||||
if( aTable == nullptr )
|
||||
aTable = selectDesignBlockLibTable();
|
||||
|
||||
if( aTable == nullptr )
|
||||
return wxEmptyString;
|
||||
|
||||
bool isGlobal = ( aTable == &DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable() );
|
||||
|
||||
wxFileName fn( aFilename );
|
||||
|
||||
if( aFilename.IsEmpty() )
|
||||
{
|
||||
if( !m_frame->LibraryFileBrowser( true, fn, FILEEXT::KiCadDesignBlockLibPathWildcard(),
|
||||
FILEEXT::KiCadDesignBlockLibPathExtension, true, isGlobal,
|
||||
PATHS::GetDefaultUserDesignBlocksPath() ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
wxString libPath = fn.GetFullPath();
|
||||
wxString libName = fn.GetName();
|
||||
|
||||
if( libName.IsEmpty() )
|
||||
return false;
|
||||
|
||||
// Open a dialog to ask for a description
|
||||
wxString description = wxGetTextFromUser( _( "Enter a description for the library:" ), _( "Library Description" ),
|
||||
wxEmptyString, m_frame );
|
||||
|
||||
DESIGN_BLOCK_IO_MGR::DESIGN_BLOCK_FILE_T lib_type = DESIGN_BLOCK_IO_MGR::GuessPluginTypeFromLibPath( libPath );
|
||||
|
||||
if( lib_type == DESIGN_BLOCK_IO_MGR::FILE_TYPE_NONE )
|
||||
lib_type = DESIGN_BLOCK_IO_MGR::KICAD_SEXP;
|
||||
|
||||
wxString type = DESIGN_BLOCK_IO_MGR::ShowType( lib_type );
|
||||
|
||||
// KiCad lib is our default guess. So it might not have the .kicad_blocks extension
|
||||
// In this case, the extension is part of the library name
|
||||
if( lib_type == DESIGN_BLOCK_IO_MGR::KICAD_SEXP && fn.GetExt() != FILEEXT::KiCadDesignBlockLibPathExtension )
|
||||
libName = fn.GetFullName();
|
||||
|
||||
// try to use path normalized to an environmental variable or project path
|
||||
wxString normalizedPath = NormalizePath( libPath, &Pgm().GetLocalEnvVariables(), &m_frame->Prj() );
|
||||
|
||||
try
|
||||
{
|
||||
DESIGN_BLOCK_LIB_TABLE_ROW* row =
|
||||
new DESIGN_BLOCK_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString, description );
|
||||
aTable->InsertRow( row );
|
||||
|
||||
if( isGlobal )
|
||||
DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable().Save( DESIGN_BLOCK_LIB_TABLE::GetGlobalTableFileName() );
|
||||
else
|
||||
m_frame->Prj().DesignBlockLibs()->Save( m_frame->Prj().DesignBlockLibTblName() );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( m_frame, ioe.What() );
|
||||
return false;
|
||||
}
|
||||
|
||||
LIB_ID libID( libName, wxEmptyString );
|
||||
RefreshLibs();
|
||||
SelectLibId( libID );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DESIGN_BLOCK_PANE::DeleteDesignBlockLibrary( const wxString& aLibName, bool aConfirm )
|
||||
{
|
||||
if( aLibName.IsEmpty() )
|
||||
{
|
||||
DisplayErrorMessage( m_frame, _( "Please select a library to delete." ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !m_frame->Prj().DesignBlockLibs()->IsDesignBlockLibWritable( aLibName ) )
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Library '%s' is read only." ), aLibName );
|
||||
m_frame->ShowInfoBarError( msg );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Confirmation
|
||||
wxString msg = wxString::Format( _( "Delete design block library '%s' from disk? This will "
|
||||
"delete all design blocks within the library." ),
|
||||
aLibName.GetData() );
|
||||
|
||||
if( aConfirm && !IsOK( m_frame, msg ) )
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
m_frame->Prj().DesignBlockLibs()->DesignBlockLibDelete( aLibName );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( m_frame, ioe.What() );
|
||||
return false;
|
||||
}
|
||||
|
||||
msg.Printf( _( "Design block library '%s' deleted" ), aLibName.GetData() );
|
||||
m_frame->SetStatusText( msg );
|
||||
|
||||
RefreshLibs();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DESIGN_BLOCK_PANE::DeleteDesignBlockFromLibrary( const LIB_ID& aLibId, bool aConfirm )
|
||||
{
|
||||
if( !aLibId.IsValid() )
|
||||
return false;
|
||||
|
||||
wxString libname = aLibId.GetLibNickname();
|
||||
wxString dbname = aLibId.GetLibItemName();
|
||||
|
||||
if( !m_frame->Prj().DesignBlockLibs()->IsDesignBlockLibWritable( libname ) )
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Library '%s' is read only." ), libname );
|
||||
m_frame->ShowInfoBarError( msg );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Confirmation
|
||||
wxString msg = wxString::Format( _( "Delete design block '%s' in library '%s' from disk?" ),
|
||||
dbname.GetData(), libname.GetData() );
|
||||
|
||||
if( aConfirm && !IsOK( m_frame, msg ) )
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
m_frame->Prj().DesignBlockLibs()->DesignBlockDelete( libname, dbname );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( m_frame, ioe.What() );
|
||||
return false;
|
||||
}
|
||||
|
||||
msg.Printf( _( "Design block '%s' deleted from library '%s'" ), dbname.GetData(), libname.GetData() );
|
||||
|
||||
m_frame->SetStatusText( msg );
|
||||
|
||||
RefreshLibs();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DESIGN_BLOCK_PANE::EditDesignBlockProperties( const LIB_ID& aLibId )
|
||||
{
|
||||
if( !aLibId.IsValid() )
|
||||
return false;
|
||||
|
||||
wxString libname = aLibId.GetLibNickname();
|
||||
wxString dbname = aLibId.GetLibItemName();
|
||||
|
||||
if( !m_frame->Prj().DesignBlockLibs()->IsDesignBlockLibWritable( libname ) )
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Library '%s' is read only." ), libname );
|
||||
m_frame->ShowInfoBarError( msg );
|
||||
return false;
|
||||
}
|
||||
|
||||
DESIGN_BLOCK* designBlock = GetDesignBlock( aLibId, true, true );
|
||||
|
||||
if( !designBlock )
|
||||
return false;
|
||||
|
||||
wxString originalName = designBlock->GetLibId().GetLibItemName();
|
||||
DIALOG_DESIGN_BLOCK_PROPERTIES dlg( m_frame, designBlock );
|
||||
|
||||
if( dlg.ShowModal() != wxID_OK )
|
||||
return false;
|
||||
|
||||
wxString newName = designBlock->GetLibId().GetLibItemName();
|
||||
|
||||
try
|
||||
{
|
||||
if( originalName != newName )
|
||||
{
|
||||
if( m_frame->Prj().DesignBlockLibs()->DesignBlockExists( libname, newName ) )
|
||||
if( !checkOverwrite( m_frame, libname, newName ) )
|
||||
return false;
|
||||
|
||||
m_frame->Prj().DesignBlockLibs()->DesignBlockSave( libname, designBlock );
|
||||
m_frame->Prj().DesignBlockLibs()->DesignBlockDelete( libname, originalName );
|
||||
}
|
||||
else
|
||||
m_frame->Prj().DesignBlockLibs()->DesignBlockSave( libname, designBlock );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( m_frame, ioe.What() );
|
||||
return false;
|
||||
}
|
||||
|
||||
RefreshLibs();
|
||||
SelectLibId( designBlock->GetLibId() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DESIGN_BLOCK_PANE::checkOverwrite( wxWindow* aFrame, wxString& libname, wxString& newName )
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Design block '%s' already exists in library '%s'." ),
|
||||
newName.GetData(), libname.GetData() );
|
||||
|
||||
if( OKOrCancelDialog( aFrame, _( "Confirmation" ), msg, _( "Overwrite existing design block?" ), _( "Overwrite" ) )
|
||||
!= wxID_OK )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK_LIB_TABLE* DESIGN_BLOCK_PANE::selectDesignBlockLibTable( bool aOptional )
|
||||
{
|
||||
// If no project is loaded, always work with the global table
|
||||
if( m_frame->Prj().IsNullProject() )
|
||||
{
|
||||
DESIGN_BLOCK_LIB_TABLE* ret = &DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable();
|
||||
|
||||
if( aOptional )
|
||||
{
|
||||
wxMessageDialog dlg( m_frame, _( "Add the library to the global library table?" ),
|
||||
_( "Add To Global Library Table" ), wxYES_NO );
|
||||
|
||||
if( dlg.ShowModal() != wxID_OK )
|
||||
ret = nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
wxArrayString libTableNames;
|
||||
libTableNames.Add( _( "Global" ) );
|
||||
libTableNames.Add( _( "Project" ) );
|
||||
|
||||
wxSingleChoiceDialog dlg( m_frame, _( "Choose the Library Table to add the library to:" ),
|
||||
_( "Add To Library Table" ), libTableNames );
|
||||
|
||||
if( aOptional )
|
||||
{
|
||||
dlg.FindWindow( wxID_CANCEL )->SetLabel( _( "Skip" ) );
|
||||
dlg.FindWindow( wxID_OK )->SetLabel( _( "Add" ) );
|
||||
}
|
||||
|
||||
if( dlg.ShowModal() != wxID_OK )
|
||||
return nullptr;
|
||||
|
||||
switch( dlg.GetSelection() )
|
||||
{
|
||||
case 0: return &DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable();
|
||||
case 1: return m_frame->Prj().DesignBlockLibs();
|
||||
default: return nullptr;
|
||||
}
|
||||
}
|
109
common/widgets/design_block_pane.h
Normal file
109
common/widgets/design_block_pane.h
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The KiCad Developers, see AUTHORS.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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
#ifndef DESIGN_BLOCK_PANE_H
|
||||
#define DESIGN_BLOCK_PANE_H
|
||||
|
||||
#include <design_block_tree_model_adapter.h>
|
||||
#include <widgets/html_window.h>
|
||||
#include <widgets/wx_panel.h>
|
||||
#include <wx/checkbox.h>
|
||||
#include <wx/filedlgcustomize.h>
|
||||
#include <eda_draw_frame.h>
|
||||
|
||||
|
||||
class DESIGN_BLOCK;
|
||||
class PANEL_DESIGN_BLOCK_CHOOSER;
|
||||
|
||||
|
||||
class DESIGN_BLOCK_PANE : public WX_PANEL
|
||||
{
|
||||
public:
|
||||
DESIGN_BLOCK_PANE( EDA_DRAW_FRAME* aParent, const LIB_ID* aPreselect, std::vector<LIB_ID>& aHistoryList );
|
||||
|
||||
~DESIGN_BLOCK_PANE() override;
|
||||
|
||||
void SaveSettings();
|
||||
|
||||
LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
|
||||
void SelectLibId( const LIB_ID& aLibId );
|
||||
|
||||
/**
|
||||
* Load design block from design block library table.
|
||||
*
|
||||
* @param aLibId is the design block library identifier to load.
|
||||
* @param aUseCacheLib set to true to fall back to cache library if design block is not found in
|
||||
* design block library table.
|
||||
* @param aShowErrorMessage set to true to show any error messages.
|
||||
* @return The design block found in the library or NULL if the design block was not found.
|
||||
*/
|
||||
DESIGN_BLOCK* GetDesignBlock( const LIB_ID& aLibId, bool aUseCacheLib, bool aShowErrorMsg );
|
||||
DESIGN_BLOCK* GetSelectedDesignBlock( bool aUseCacheLib, bool aShowErrorMsg );
|
||||
|
||||
void RefreshLibs();
|
||||
|
||||
/**
|
||||
* If a library name is given, creates a new design block library in the project folder
|
||||
* with the given name. If no library name is given it prompts user for a library path,
|
||||
* then creates a new design block library at that location.
|
||||
* If library exists, user is warned about that, and is given a chance
|
||||
* to abort the new creation, and in that case existing library is first deleted.
|
||||
*
|
||||
* @param aProposedName is the initial path and filename shown in the file chooser dialog.
|
||||
* @return The newly created library path if library was successfully created, else
|
||||
* wxEmptyString because user aborted or error.
|
||||
*/
|
||||
wxString CreateNewDesignBlockLibrary( const wxString& aLibName = wxEmptyString,
|
||||
const wxString& aProposedName = wxEmptyString );
|
||||
|
||||
/**
|
||||
* Add an existing library to either the global or project library table.
|
||||
*
|
||||
* @param aFileName the library to add; a file open dialog will be displayed if empty.
|
||||
* @return true if successfully added.
|
||||
*/
|
||||
bool AddDesignBlockLibrary( const wxString& aFilename, DESIGN_BLOCK_LIB_TABLE* aTable );
|
||||
|
||||
bool DeleteDesignBlockLibrary( const wxString& aLibName, bool aConfirm );
|
||||
|
||||
bool DeleteDesignBlockFromLibrary( const LIB_ID& aLibId, bool aConfirm );
|
||||
|
||||
bool EditDesignBlockProperties( const LIB_ID& aLibId );
|
||||
|
||||
PANEL_DESIGN_BLOCK_CHOOSER* GetDesignBlockPanel() const { return m_chooserPanel; }
|
||||
|
||||
protected:
|
||||
virtual void setLabelsAndTooltips() = 0;
|
||||
|
||||
virtual void OnLanguageChanged( wxCommandEvent& aEvent );
|
||||
void OnClosed( wxAuiManagerEvent& aEvent );
|
||||
|
||||
EDA_DRAW_FRAME* m_frame = nullptr;
|
||||
PANEL_DESIGN_BLOCK_CHOOSER* m_chooserPanel = nullptr;
|
||||
|
||||
private:
|
||||
bool checkOverwrite( wxWindow* aFrame, wxString& libname, wxString& newName );
|
||||
DESIGN_BLOCK_LIB_TABLE* selectDesignBlockLibTable( bool aOptional = false );
|
||||
wxString createNewDesignBlockLibrary( const wxString& aLibName, const wxString& aProposedName,
|
||||
DESIGN_BLOCK_LIB_TABLE* aTable );
|
||||
};
|
||||
#endif
|
66
common/widgets/design_block_preview_widget.h
Normal file
66
common/widgets/design_block_preview_widget.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The KiCad Developers, see AUTHORS.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 as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DESIGN_BLOCK_PREVIEW_WIDGET_H
|
||||
#define DESIGN_BLOCK_PREVIEW_WIDGET_H
|
||||
|
||||
#include <wx/panel.h>
|
||||
#include <kiway.h>
|
||||
#include <gal_display_options_common.h>
|
||||
#include <class_draw_panel_gal.h>
|
||||
|
||||
|
||||
class LIB_ID;
|
||||
class DESIGN_BLOCK;
|
||||
class SCHEMATIC;
|
||||
class SCH_SHEET;
|
||||
class wxStaticText;
|
||||
class wxSizer;
|
||||
|
||||
|
||||
class DESIGN_BLOCK_PREVIEW_WIDGET : public wxPanel
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Construct a design block preview widget.
|
||||
*
|
||||
* @param aParent - parent window
|
||||
*/
|
||||
DESIGN_BLOCK_PREVIEW_WIDGET( wxWindow* aParent ) : wxPanel( aParent ) {}
|
||||
~DESIGN_BLOCK_PREVIEW_WIDGET() = default;
|
||||
|
||||
|
||||
/**
|
||||
* Set the contents of the status label and display it.
|
||||
*/
|
||||
virtual void SetStatusText( const wxString& aText ) = 0;
|
||||
|
||||
/**
|
||||
* Set the currently displayed design block.
|
||||
*/
|
||||
virtual void DisplayDesignBlock( DESIGN_BLOCK* aDesignBlock ) = 0;
|
||||
|
||||
protected:
|
||||
void onSize( wxSizeEvent& aEvent );
|
||||
|
||||
void fitOnDrawArea(); // set the view scale to fit the item on screen and center
|
||||
};
|
||||
|
||||
|
||||
#endif // DESIGN_BLOCK_PREVIEW_WIDGET_H
|
@ -23,15 +23,18 @@
|
||||
|
||||
#include <pgm_base.h>
|
||||
#include <design_block.h>
|
||||
#include <design_block_pane.h>
|
||||
#include <design_block_lib_table.h>
|
||||
#include <panel_design_block_chooser.h>
|
||||
#include <design_block_preview_widget.h>
|
||||
#include <kiface_base.h>
|
||||
#include <sch_edit_frame.h>
|
||||
#include <kiway_holder.h>
|
||||
#include <eda_draw_frame.h>
|
||||
#include <widgets/lib_tree.h>
|
||||
#include <settings/settings_manager.h>
|
||||
#include <project/project_file.h>
|
||||
#include <dialogs/html_message_box.h>
|
||||
#include <settings/app_settings.h>
|
||||
#include <string_utils.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/panel.h>
|
||||
@ -46,24 +49,24 @@
|
||||
wxString PANEL_DESIGN_BLOCK_CHOOSER::g_designBlockSearchString;
|
||||
|
||||
|
||||
PANEL_DESIGN_BLOCK_CHOOSER::PANEL_DESIGN_BLOCK_CHOOSER( SCH_EDIT_FRAME* aFrame, wxWindow* aParent,
|
||||
PANEL_DESIGN_BLOCK_CHOOSER::PANEL_DESIGN_BLOCK_CHOOSER( EDA_DRAW_FRAME* aFrame, DESIGN_BLOCK_PANE* aParent,
|
||||
std::vector<LIB_ID>& aHistoryList,
|
||||
std::function<void()> aSelectHandler ) :
|
||||
std::function<void()> aSelectHandler,
|
||||
TOOL_INTERACTIVE* aContextMenuTool ) :
|
||||
|
||||
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
|
||||
m_dbl_click_timer( nullptr ),
|
||||
m_open_libs_timer( nullptr ),
|
||||
m_vsplitter( nullptr ),
|
||||
m_tree( nullptr ),
|
||||
m_preview( nullptr ),
|
||||
m_parent( aParent ),
|
||||
m_frame( aFrame ),
|
||||
m_selectHandler( std::move( aSelectHandler ) ),
|
||||
m_historyList( aHistoryList )
|
||||
{
|
||||
DESIGN_BLOCK_LIB_TABLE* libs = m_frame->Prj().DesignBlockLibs();
|
||||
|
||||
// Make sure settings are loaded before we start running multi-threaded design block loaders
|
||||
Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
|
||||
|
||||
// Load design block files:
|
||||
WX_PROGRESS_REPORTER* progressReporter =
|
||||
new WX_PROGRESS_REPORTER( aParent, _( "Loading Design Block Libraries" ), 1 );
|
||||
@ -79,8 +82,8 @@ PANEL_DESIGN_BLOCK_CHOOSER::PANEL_DESIGN_BLOCK_CHOOSER( SCH_EDIT_FRAME* aFrame,
|
||||
if( DESIGN_BLOCK_LIB_TABLE::GetGlobalList().GetErrorCount() )
|
||||
displayErrors( aFrame );
|
||||
|
||||
m_adapter = DESIGN_BLOCK_TREE_MODEL_ADAPTER::Create( m_frame, libs,
|
||||
m_frame->eeconfig()->m_DesignBlockChooserPanel.tree );
|
||||
m_adapter = DESIGN_BLOCK_TREE_MODEL_ADAPTER::Create(
|
||||
m_frame, libs, m_frame->config()->m_DesignBlockChooserPanel.tree, aContextMenuTool );
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
// Construct the actual panel
|
||||
@ -99,27 +102,21 @@ PANEL_DESIGN_BLOCK_CHOOSER::PANEL_DESIGN_BLOCK_CHOOSER( SCH_EDIT_FRAME* aFrame,
|
||||
wxBoxSizer* treeSizer = new wxBoxSizer( wxVERTICAL );
|
||||
treePanel->SetSizer( treeSizer );
|
||||
|
||||
wxPanel* detailsPanel = new wxPanel( m_vsplitter );
|
||||
wxBoxSizer* detailsSizer = new wxBoxSizer( wxVERTICAL );
|
||||
detailsPanel->SetSizer( detailsSizer );
|
||||
m_detailsPanel = new wxPanel( m_vsplitter );
|
||||
m_detailsSizer = new wxBoxSizer( wxVERTICAL );
|
||||
m_detailsPanel->SetSizer( m_detailsSizer );
|
||||
|
||||
// Use the same draw engine type as the one used in parent frame m_frame
|
||||
EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = m_frame->GetCanvas()->GetBackend();
|
||||
m_preview = new DESIGN_BLOCK_PREVIEW_WIDGET( detailsPanel, false, canvasType );
|
||||
|
||||
detailsSizer->Add( m_preview, 1, wxEXPAND, 5 );
|
||||
detailsPanel->Layout();
|
||||
detailsSizer->Fit( detailsPanel );
|
||||
m_detailsPanel->Layout();
|
||||
m_detailsSizer->Fit( m_detailsPanel );
|
||||
|
||||
m_vsplitter->SetSashGravity( 0.5 );
|
||||
m_vsplitter->SetMinimumPaneSize( 20 );
|
||||
m_vsplitter->SplitHorizontally( treePanel, detailsPanel );
|
||||
m_vsplitter->SplitHorizontally( treePanel, m_detailsPanel );
|
||||
|
||||
sizer->Add( m_vsplitter, 1, wxEXPAND, 5 );
|
||||
|
||||
|
||||
m_tree = new LIB_TREE( treePanel, wxT( "design_blocks" ), libs, m_adapter,
|
||||
LIB_TREE::FLAGS::ALL_WIDGETS, nullptr );
|
||||
m_tree = new LIB_TREE( treePanel, wxT( "design_blocks" ), libs, m_adapter, LIB_TREE::FLAGS::ALL_WIDGETS, nullptr );
|
||||
|
||||
treeSizer->Add( m_tree, 1, wxEXPAND, 5 );
|
||||
treePanel->Layout();
|
||||
@ -137,10 +134,8 @@ PANEL_DESIGN_BLOCK_CHOOSER::PANEL_DESIGN_BLOCK_CHOOSER( SCH_EDIT_FRAME* aFrame,
|
||||
|
||||
Layout();
|
||||
|
||||
Bind( wxEVT_TIMER, &PANEL_DESIGN_BLOCK_CHOOSER::onCloseTimer, this,
|
||||
m_dbl_click_timer->GetId() );
|
||||
Bind( wxEVT_TIMER, &PANEL_DESIGN_BLOCK_CHOOSER::onOpenLibsTimer, this,
|
||||
m_open_libs_timer->GetId() );
|
||||
Bind( wxEVT_TIMER, &PANEL_DESIGN_BLOCK_CHOOSER::onCloseTimer, this, m_dbl_click_timer->GetId() );
|
||||
Bind( wxEVT_TIMER, &PANEL_DESIGN_BLOCK_CHOOSER::onOpenLibsTimer, this, m_open_libs_timer->GetId() );
|
||||
Bind( EVT_LIBITEM_CHOSEN, &PANEL_DESIGN_BLOCK_CHOOSER::onDesignBlockChosen, this );
|
||||
Bind( wxEVT_CHAR_HOOK, &PANEL_DESIGN_BLOCK_CHOOSER::OnChar, this );
|
||||
|
||||
@ -170,17 +165,14 @@ void PANEL_DESIGN_BLOCK_CHOOSER::SaveSettings()
|
||||
{
|
||||
g_designBlockSearchString = m_tree->GetSearchString();
|
||||
|
||||
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
||||
if( APP_SETTINGS_BASE* cfg = m_frame->config() )
|
||||
{
|
||||
// Save any changes to column widths, etc.
|
||||
m_adapter->SaveSettings();
|
||||
|
||||
cfg->m_DesignBlockChooserPanel.width = GetParent()->GetSize().x;
|
||||
cfg->m_DesignBlockChooserPanel.height = GetParent()->GetSize().y;
|
||||
|
||||
if( m_vsplitter )
|
||||
cfg->m_DesignBlockChooserPanel.sash_pos_v = m_vsplitter->GetSashPosition();
|
||||
|
||||
cfg->m_DesignBlockChooserPanel.sash_pos_v = m_vsplitter->GetSashPosition();
|
||||
cfg->m_DesignBlockChooserPanel.sort_mode = m_tree->GetSortMode();
|
||||
}
|
||||
}
|
||||
@ -193,6 +185,14 @@ void PANEL_DESIGN_BLOCK_CHOOSER::ShowChangedLanguage()
|
||||
}
|
||||
|
||||
|
||||
void PANEL_DESIGN_BLOCK_CHOOSER::SetPreviewWidget( DESIGN_BLOCK_PREVIEW_WIDGET* aPreview )
|
||||
{
|
||||
m_preview = aPreview;
|
||||
m_detailsSizer->Add( m_preview, 1, wxEXPAND, 5 );
|
||||
Layout();
|
||||
}
|
||||
|
||||
|
||||
void PANEL_DESIGN_BLOCK_CHOOSER::OnChar( wxKeyEvent& aEvent )
|
||||
{
|
||||
if( aEvent.GetKeyCode() == WXK_ESCAPE )
|
||||
@ -202,8 +202,7 @@ void PANEL_DESIGN_BLOCK_CHOOSER::OnChar( wxKeyEvent& aEvent )
|
||||
if( wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( eventSource ) )
|
||||
{
|
||||
// First escape cancels search string value
|
||||
if( textCtrl->GetValue() == m_tree->GetSearchString()
|
||||
&& !m_tree->GetSearchString().IsEmpty() )
|
||||
if( textCtrl->GetValue() == m_tree->GetSearchString() && !m_tree->GetSearchString().IsEmpty() )
|
||||
{
|
||||
m_tree->SetSearchString( wxEmptyString );
|
||||
return;
|
||||
@ -219,7 +218,7 @@ void PANEL_DESIGN_BLOCK_CHOOSER::OnChar( wxKeyEvent& aEvent )
|
||||
|
||||
void PANEL_DESIGN_BLOCK_CHOOSER::FinishSetup()
|
||||
{
|
||||
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
||||
if( APP_SETTINGS_BASE* cfg = m_frame->config() )
|
||||
{
|
||||
auto horizPixelsFromDU =
|
||||
[&]( int x ) -> int
|
||||
@ -228,7 +227,7 @@ void PANEL_DESIGN_BLOCK_CHOOSER::FinishSetup()
|
||||
return GetParent()->ConvertDialogToPixels( sz ).x;
|
||||
};
|
||||
|
||||
EESCHEMA_SETTINGS::PANEL_DESIGN_BLOCK_CHOOSER& panelCfg = cfg->m_DesignBlockChooserPanel;
|
||||
APP_SETTINGS_BASE::PANEL_DESIGN_BLOCK_CHOOSER& panelCfg = cfg->m_DesignBlockChooserPanel;
|
||||
|
||||
int w = panelCfg.width > 40 ? panelCfg.width : horizPixelsFromDU( 440 );
|
||||
int h = panelCfg.height > 40 ? panelCfg.height : horizPixelsFromDU( 340 );
|
||||
@ -259,8 +258,7 @@ void PANEL_DESIGN_BLOCK_CHOOSER::RefreshLibs( bool aProgress )
|
||||
// if a selected item is removed during the sync
|
||||
m_tree->Unselect();
|
||||
|
||||
DESIGN_BLOCK_TREE_MODEL_ADAPTER* adapter =
|
||||
static_cast<DESIGN_BLOCK_TREE_MODEL_ADAPTER*>( m_adapter.get() );
|
||||
DESIGN_BLOCK_TREE_MODEL_ADAPTER* adapter = static_cast<DESIGN_BLOCK_TREE_MODEL_ADAPTER*>( m_adapter.get() );
|
||||
|
||||
// Clear all existing libraries then re-add
|
||||
adapter->ClearLibraries();
|
||||
@ -273,8 +271,7 @@ void PANEL_DESIGN_BLOCK_CHOOSER::RefreshLibs( bool aProgress )
|
||||
if( aProgress )
|
||||
{
|
||||
WX_PROGRESS_REPORTER progressReporter( this, _( "Updating Design Block Libraries" ), 2 );
|
||||
DESIGN_BLOCK_LIB_TABLE::GetGlobalList().ReadDesignBlockFiles( fpTable, nullptr,
|
||||
&progressReporter );
|
||||
DESIGN_BLOCK_LIB_TABLE::GetGlobalList().ReadDesignBlockFiles( fpTable, nullptr, &progressReporter );
|
||||
progressReporter.Show( false );
|
||||
}
|
||||
else
|
||||
@ -336,7 +333,7 @@ void PANEL_DESIGN_BLOCK_CHOOSER::onCloseTimer( wxTimerEvent& aEvent )
|
||||
|
||||
void PANEL_DESIGN_BLOCK_CHOOSER::onOpenLibsTimer( wxTimerEvent& aEvent )
|
||||
{
|
||||
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
||||
if( APP_SETTINGS_BASE* cfg = m_frame->config() )
|
||||
m_adapter->OpenLibs( cfg->m_LibTree.open_libs );
|
||||
|
||||
// Bind this now se we don't spam the event queue with EVT_LIBITEM_SELECTED events during
|
||||
@ -348,7 +345,7 @@ void PANEL_DESIGN_BLOCK_CHOOSER::onOpenLibsTimer( wxTimerEvent& aEvent )
|
||||
void PANEL_DESIGN_BLOCK_CHOOSER::onDesignBlockSelected( wxCommandEvent& aEvent )
|
||||
{
|
||||
if( GetSelectedLibId().IsValid() )
|
||||
m_preview->DisplayDesignBlock( m_frame->GetDesignBlock( GetSelectedLibId() ) );
|
||||
m_preview->DisplayDesignBlock( m_parent->GetDesignBlock( GetSelectedLibId(), true, true ) );
|
||||
}
|
||||
|
||||
|
||||
@ -405,8 +402,8 @@ void PANEL_DESIGN_BLOCK_CHOOSER::rebuildHistoryNode()
|
||||
|
||||
for( const LIB_ID& lib : m_historyList )
|
||||
{
|
||||
LIB_TREE_ITEM* fp_info = DESIGN_BLOCK_LIB_TABLE::GetGlobalList().GetDesignBlockInfo(
|
||||
lib.GetLibNickname(), lib.GetLibItemName() );
|
||||
LIB_TREE_ITEM* fp_info = DESIGN_BLOCK_LIB_TABLE::GetGlobalList().GetDesignBlockInfo( lib.GetLibNickname(),
|
||||
lib.GetLibItemName() );
|
||||
|
||||
// this can be null, for example, if the design block has been deleted from a library.
|
||||
if( fp_info != nullptr )
|
||||
@ -427,7 +424,7 @@ void PANEL_DESIGN_BLOCK_CHOOSER::displayErrors( wxTopLevelWindow* aWindow )
|
||||
|
||||
HTML_MESSAGE_BOX dlg( aWindow, _( "Load Error" ) );
|
||||
|
||||
dlg.MessageSet( _( "Errors were encountered loading footprints:" ) );
|
||||
dlg.MessageSet( _( "Errors were encountered loading design blocks:" ) );
|
||||
|
||||
wxString msg;
|
||||
|
@ -31,24 +31,27 @@ class wxPanel;
|
||||
class wxTimer;
|
||||
class wxSplitterWindow;
|
||||
|
||||
class SCH_EDIT_FRAME;
|
||||
class EDA_DRAW_FRAME;
|
||||
class DESIGN_BLOCK_PANE;
|
||||
class DESIGN_BLOCK_PREVIEW_WIDGET;
|
||||
|
||||
|
||||
class PANEL_DESIGN_BLOCK_CHOOSER : public wxPanel
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create dialog to choose design_block.
|
||||
*
|
||||
* @param aFrame the parent frame (usually a SCH_EDIT_FRAME or DESIGN_BLOCK_CHOOSER_FRAME)
|
||||
* @param aParent the parent window (usually a DIALOG_SHIM or DESIGN_BLOCK_CHOOSER_FRAME)
|
||||
* @param aAcceptHandler a handler to be called on double-click of a footprint
|
||||
* @param aEscapeHandler a handler to be called on <ESC>
|
||||
*/
|
||||
PANEL_DESIGN_BLOCK_CHOOSER( SCH_EDIT_FRAME* aFrame, wxWindow* aParent,
|
||||
/**
|
||||
* Panel for using design blocks.
|
||||
*
|
||||
* @param aFrame the parent frame (usually a SCH_EDIT_FRAME or PCB_EDIT_FRAME)
|
||||
* @param aParent the parent design block pane
|
||||
* @param aAcceptHandler a handler to be called on double-click of a footprint
|
||||
* @param aContextMenuTool the tool that will be used to provide an appropriate context menu
|
||||
* for the design block actions available in that frame
|
||||
*/
|
||||
PANEL_DESIGN_BLOCK_CHOOSER( EDA_DRAW_FRAME* aFrame, DESIGN_BLOCK_PANE* aParent,
|
||||
std::vector<LIB_ID>& aHistoryList,
|
||||
std::function<void()> aSelectHandler );
|
||||
std::function<void()> aSelectHandler,
|
||||
TOOL_INTERACTIVE* aContextMenuTool );
|
||||
|
||||
~PANEL_DESIGN_BLOCK_CHOOSER();
|
||||
|
||||
@ -56,7 +59,9 @@ public:
|
||||
|
||||
void OnChar( wxKeyEvent& aEvent );
|
||||
|
||||
void FinishSetup();
|
||||
wxPanel* GetDetailsPanel() { return m_detailsPanel; }
|
||||
void SetPreviewWidget( DESIGN_BLOCK_PREVIEW_WIDGET* aPreview );
|
||||
void FinishSetup();
|
||||
|
||||
void SetPreselect( const LIB_ID& aPreselect );
|
||||
|
||||
@ -105,16 +110,19 @@ protected:
|
||||
protected:
|
||||
static wxString g_designBlockSearchString;
|
||||
|
||||
wxTimer* m_dbl_click_timer;
|
||||
wxTimer* m_open_libs_timer;
|
||||
wxSplitterWindow* m_vsplitter;
|
||||
wxTimer* m_dbl_click_timer;
|
||||
wxTimer* m_open_libs_timer;
|
||||
wxSplitterWindow* m_vsplitter;
|
||||
wxPanel* m_detailsPanel;
|
||||
wxBoxSizer* m_detailsSizer;
|
||||
|
||||
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
|
||||
|
||||
LIB_TREE* m_tree;
|
||||
DESIGN_BLOCK_PREVIEW_WIDGET* m_preview;
|
||||
LIB_TREE* m_tree;
|
||||
DESIGN_BLOCK_PREVIEW_WIDGET* m_preview;
|
||||
|
||||
SCH_EDIT_FRAME* m_frame;
|
||||
DESIGN_BLOCK_PANE* m_parent;
|
||||
EDA_DRAW_FRAME* m_frame;
|
||||
std::function<void()> m_selectHandler;
|
||||
|
||||
std::vector<LIB_ID> m_historyList;
|
@ -99,8 +99,6 @@ set( EESCHEMA_DLGS
|
||||
dialogs/dialog_change_symbols_base.cpp
|
||||
dialogs/dialog_database_lib_settings_base.cpp
|
||||
dialogs/dialog_database_lib_settings.cpp
|
||||
dialogs/dialog_design_block_properties_base.cpp
|
||||
dialogs/dialog_design_block_properties.cpp
|
||||
dialogs/dialog_edit_symbols_libid.cpp
|
||||
dialogs/dialog_edit_symbols_libid_base.cpp
|
||||
dialogs/dialog_eeschema_page_settings.cpp
|
||||
@ -278,16 +276,15 @@ set( EESCHEMA_SIM_SRCS
|
||||
)
|
||||
|
||||
set( EESCHEMA_WIDGETS
|
||||
widgets/design_block_pane.cpp
|
||||
widgets/design_block_preview_widget.cpp
|
||||
widgets/hierarchy_pane.cpp
|
||||
widgets/panel_design_block_chooser.cpp
|
||||
widgets/panel_sch_selection_filter_base.cpp
|
||||
widgets/panel_sch_selection_filter.cpp
|
||||
widgets/panel_symbol_chooser.cpp
|
||||
widgets/pin_shape_combobox.cpp
|
||||
widgets/pin_type_combobox.cpp
|
||||
widgets/symbol_diff_widget.cpp
|
||||
widgets/sch_design_block_pane.cpp
|
||||
widgets/sch_design_block_preview_widget.cpp
|
||||
widgets/sch_properties_panel.cpp
|
||||
widgets/sch_search_pane.cpp
|
||||
widgets/search_handlers.cpp
|
||||
@ -357,8 +354,7 @@ set( EESCHEMA_SRCS
|
||||
bus-wire-junction.cpp
|
||||
connection_graph.cpp
|
||||
cross-probing.cpp
|
||||
design_block_tree_model_adapter.cpp
|
||||
design_block_utils.cpp
|
||||
sch_design_block_utils.cpp
|
||||
eeschema_config.cpp
|
||||
eeschema_helpers.cpp
|
||||
eeschema_jobs_handler.cpp
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include <tools/sch_actions.h>
|
||||
#include <tools/sch_editor_control.h>
|
||||
#include <advanced_config.h>
|
||||
#include <widgets/design_block_pane.h>
|
||||
#include <widgets/sch_design_block_pane.h>
|
||||
#include <wx/log.h>
|
||||
|
||||
SCH_ITEM* SCH_EDITOR_CONTROL::FindSymbolAndItem( const wxString* aPath, const wxString* aReference,
|
||||
|
@ -34,8 +34,8 @@
|
||||
#include <sch_edit_frame.h>
|
||||
#include <sch_painter.h>
|
||||
#include <schematic.h>
|
||||
#include <widgets/design_block_pane.h>
|
||||
#include <widgets/hierarchy_pane.h>
|
||||
#include <widgets/sch_design_block_pane.h>
|
||||
#include <widgets/sch_search_pane.h>
|
||||
#include <widgets/panel_sch_selection_filter.h>
|
||||
#include <widgets/properties_panel.h>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user