mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
design blocks: commonize a lot of the code in prep for PCB blocks
This commit is contained in:
parent
55e5596cda
commit
b894e7fe91
@ -348,6 +348,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
|
||||
@ -421,6 +423,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
|
||||
@ -445,6 +448,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
|
||||
@ -607,6 +611,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
|
||||
|
@ -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>
|
||||
@ -61,3 +65,5 @@ private:
|
||||
|
||||
nlohmann::ordered_map<wxString, wxString> m_fields;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -25,30 +25,34 @@
|
||||
#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 ),
|
||||
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 )
|
||||
{
|
||||
}
|
||||
|
||||
@ -206,5 +210,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;
|
||||
}
|
@ -35,7 +35,8 @@ public:
|
||||
*/
|
||||
static wxObjectDataPtr<LIB_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 );
|
||||
|
||||
void AddLibraries( EDA_BASE_FRAME* aParent );
|
||||
void ClearLibraries();
|
||||
@ -51,7 +52,8 @@ 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 );
|
||||
@ -61,6 +63,7 @@ protected:
|
||||
protected:
|
||||
DESIGN_BLOCK_LIB_TABLE* m_libs;
|
||||
EDA_BASE_FRAME* m_frame;
|
||||
TOOL_INTERACTIVE* m_contextMenuTool;
|
||||
};
|
||||
|
||||
#endif // DESIGN_BLOCK_TREE_MODEL_ADAPTER_H
|
@ -24,16 +24,16 @@
|
||||
|
||||
|
||||
#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 ) :
|
||||
DIALOG_DESIGN_BLOCK_PROPERTIES_BASE( aParent ), m_designBlock( aDesignBlock )
|
||||
{
|
||||
if( !m_textName->IsEmpty() )
|
@ -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 );
|
||||
~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
|
@ -70,6 +70,60 @@ 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 ) );
|
||||
|
||||
|
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( EDA_LANG_CHANGED, &DESIGN_BLOCK_PANE::OnLanguageChanged, this );
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK_PANE::~DESIGN_BLOCK_PANE()
|
||||
{
|
||||
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::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;
|
||||
}
|
||||
}
|
108
common/widgets/design_block_pane.h
Normal file
108
common/widgets/design_block_pane.h
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
virtual void OnLanguageChanged( wxCommandEvent& aEvent );
|
||||
|
||||
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;
|
||||
|
||||
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,25 @@
|
||||
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 +83,7 @@ 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,19 +102,16 @@ 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 );
|
||||
|
||||
m_preview = new DESIGN_BLOCK_PREVIEW_WIDGET( detailsPanel, false,
|
||||
EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
|
||||
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 );
|
||||
|
||||
@ -168,17 +168,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();
|
||||
}
|
||||
}
|
||||
@ -191,6 +188,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 )
|
||||
@ -217,7 +222,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
|
||||
@ -226,7 +231,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 );
|
||||
@ -334,7 +339,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
|
||||
@ -346,7 +351,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 ) );
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
ee_collectors.cpp
|
||||
eeschema_config.cpp
|
||||
eeschema_helpers.cpp
|
||||
|
@ -38,7 +38,7 @@
|
||||
#include <tools/ee_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,
|
||||
|
@ -1,636 +0,0 @@
|
||||
/*
|
||||
* 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 <pgm_base.h>
|
||||
#include <kiway.h>
|
||||
#include <design_block.h>
|
||||
#include <design_block_lib_table.h>
|
||||
#include <design_block_pane.h>
|
||||
#include <sch_edit_frame.h>
|
||||
#include <wx/choicdlg.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/textdlg.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <paths.h>
|
||||
#include <env_paths.h>
|
||||
#include <common.h>
|
||||
#include <kidialog.h>
|
||||
#include <confirm.h>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <ee_selection_tool.h>
|
||||
#include <dialogs/dialog_design_block_properties.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
|
||||
bool checkOverwrite( SCH_EDIT_FRAME* 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* SCH_EDIT_FRAME::selectDesignBlockLibTable( bool aOptional )
|
||||
{
|
||||
// If no project is loaded, always work with the global table
|
||||
if( Prj().IsNullProject() )
|
||||
{
|
||||
DESIGN_BLOCK_LIB_TABLE* ret = &DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable();
|
||||
|
||||
if( aOptional )
|
||||
{
|
||||
wxMessageDialog dlg( this, _( "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( this, _( "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 Prj().DesignBlockLibs();
|
||||
default: return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
wxString SCH_EDIT_FRAME::CreateNewDesignBlockLibrary( const wxString& aLibName,
|
||||
const wxString& aProposedName )
|
||||
{
|
||||
return createNewDesignBlockLibrary( aLibName, aProposedName, selectDesignBlockLibTable() );
|
||||
}
|
||||
|
||||
|
||||
wxString SCH_EDIT_FRAME::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() : Prj().GetProjectPath();
|
||||
|
||||
if( aLibName.IsEmpty() )
|
||||
{
|
||||
fn = initialPath;
|
||||
|
||||
if( !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 );
|
||||
ShowInfoBarError( msg );
|
||||
return wxEmptyString;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Library %s already exists." ), libPath );
|
||||
KIDIALOG dlg( this, 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( this, ioe.What() );
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
if( doAdd )
|
||||
AddDesignBlockLibrary( libPath, aTable );
|
||||
|
||||
return libPath;
|
||||
}
|
||||
|
||||
|
||||
bool SCH_EDIT_FRAME::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( !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, this );
|
||||
|
||||
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(), &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
|
||||
Prj().DesignBlockLibs()->Save( Prj().DesignBlockLibTblName() );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( this, ioe.What() );
|
||||
return false;
|
||||
}
|
||||
|
||||
LIB_ID libID( libName, wxEmptyString );
|
||||
m_designBlocksPane->RefreshLibs();
|
||||
m_designBlocksPane->SelectLibId( libID );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void SCH_EDIT_FRAME::SaveSheetAsDesignBlock( const wxString& aLibraryName,
|
||||
SCH_SHEET_PATH& aSheetPath )
|
||||
{
|
||||
// Make sure the user has selected a library to save into
|
||||
if( m_designBlocksPane->GetSelectedLibId().GetLibNickname().empty() )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Please select a library to save the design block to." ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// Just block all attempts to create design blocks with nested sheets at this point
|
||||
std::vector<SCH_ITEM*> sheets;
|
||||
aSheetPath.LastScreen()->GetSheets( &sheets );
|
||||
|
||||
if( !sheets.empty() )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Design blocks with nested sheets are not supported." ) );
|
||||
return;
|
||||
}
|
||||
|
||||
DESIGN_BLOCK blk;
|
||||
wxFileName fn = wxFileNameFromPath( aSheetPath.Last()->GetName() );
|
||||
|
||||
blk.SetLibId( LIB_ID( aLibraryName, fn.GetName() ) );
|
||||
|
||||
// Copy all fields from the sheet to the design block
|
||||
std::vector<SCH_FIELD>& shFields = aSheetPath.Last()->GetFields();
|
||||
nlohmann::ordered_map<wxString, wxString> dbFields;
|
||||
|
||||
for( int i = 0; i < (int) shFields.size(); i++ )
|
||||
{
|
||||
if( i == SHEETNAME || i == SHEETFILENAME )
|
||||
continue;
|
||||
|
||||
dbFields[shFields[i].GetCanonicalName()] = shFields[i].GetText();
|
||||
}
|
||||
|
||||
blk.SetFields( dbFields );
|
||||
|
||||
DIALOG_DESIGN_BLOCK_PROPERTIES dlg( this, &blk );
|
||||
|
||||
if( dlg.ShowModal() != wxID_OK )
|
||||
return;
|
||||
|
||||
// Save a temporary copy of the schematic file, as the plugin is just going to move it
|
||||
wxString tempFile = wxFileName::CreateTempFileName( "design_block" );
|
||||
if( !saveSchematicFile( aSheetPath.Last(), tempFile ) )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Error saving temporary schematic file to create design block." ) );
|
||||
wxRemoveFile( tempFile );
|
||||
return;
|
||||
}
|
||||
|
||||
blk.SetSchematicFile( tempFile );
|
||||
|
||||
try
|
||||
{
|
||||
wxString libName = blk.GetLibId().GetLibNickname();
|
||||
wxString newName = blk.GetLibId().GetLibItemName();
|
||||
|
||||
if( Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) )
|
||||
if( !checkOverwrite( this, libName, newName ) )
|
||||
return;
|
||||
|
||||
Prj().DesignBlockLibs()->DesignBlockSave( aLibraryName, &blk );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( this, ioe.What() );
|
||||
}
|
||||
|
||||
// Clean up the temporary file
|
||||
wxRemoveFile( tempFile );
|
||||
|
||||
m_designBlocksPane->RefreshLibs();
|
||||
m_designBlocksPane->SelectLibId( blk.GetLibId() );
|
||||
}
|
||||
|
||||
|
||||
void SCH_EDIT_FRAME::SaveSelectionAsDesignBlock( const wxString& aLibraryName )
|
||||
{
|
||||
// Make sure the user has selected a library to save into
|
||||
if( m_designBlocksPane->GetSelectedLibId().GetLibNickname().empty() )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Please select a library to save the design block to." ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all selected items
|
||||
EE_SELECTION selection = m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
|
||||
|
||||
if( selection.Empty() )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Please select some items to save as a design block." ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// Just block all attempts to create design blocks with nested sheets at this point
|
||||
if( selection.HasType( SCH_SHEET_T ) )
|
||||
{
|
||||
if( selection.Size() == 1 )
|
||||
{
|
||||
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( selection.Front() );
|
||||
SCH_SHEET_PATH curPath = GetCurrentSheet();
|
||||
|
||||
curPath.push_back( sheet );
|
||||
SaveSheetAsDesignBlock( aLibraryName, curPath );
|
||||
}
|
||||
else
|
||||
DisplayErrorMessage( this, _( "Design blocks with nested sheets are not supported." ) );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
DESIGN_BLOCK blk;
|
||||
wxFileName fn = wxFileNameFromPath( GetScreen()->GetFileName() );
|
||||
|
||||
blk.SetLibId( LIB_ID( aLibraryName, fn.GetName() ) );
|
||||
|
||||
DIALOG_DESIGN_BLOCK_PROPERTIES dlg( this, &blk );
|
||||
|
||||
if( dlg.ShowModal() != wxID_OK )
|
||||
return;
|
||||
|
||||
// Create a temporary screen
|
||||
SCH_SCREEN* tempScreen = new SCH_SCREEN( m_schematic );
|
||||
|
||||
// Copy the selected items to the temporary screen
|
||||
for( EDA_ITEM* item : selection )
|
||||
{
|
||||
EDA_ITEM* copy = item->Clone();
|
||||
tempScreen->Append( static_cast<SCH_ITEM*>( copy ) );
|
||||
}
|
||||
|
||||
// Create a sheet for the temporary screen
|
||||
SCH_SHEET* tempSheet = new SCH_SHEET( m_schematic );
|
||||
tempSheet->SetScreen( tempScreen );
|
||||
|
||||
// Save a temporary copy of the schematic file, as the plugin is just going to move it
|
||||
wxString tempFile = wxFileName::CreateTempFileName( "design_block" );
|
||||
if( !saveSchematicFile( tempSheet, tempFile ) )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Error saving temporary schematic file to create design block." ) );
|
||||
wxRemoveFile( tempFile );
|
||||
return;
|
||||
}
|
||||
|
||||
blk.SetSchematicFile( tempFile );
|
||||
|
||||
try
|
||||
{
|
||||
wxString libName = blk.GetLibId().GetLibNickname();
|
||||
wxString newName = blk.GetLibId().GetLibItemName();
|
||||
|
||||
if( Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) )
|
||||
if( !checkOverwrite( this, libName, newName ) )
|
||||
return;
|
||||
|
||||
Prj().DesignBlockLibs()->DesignBlockSave( aLibraryName, &blk );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( this, ioe.What() );
|
||||
}
|
||||
|
||||
// Clean up the temporaries
|
||||
wxRemoveFile( tempFile );
|
||||
// This will also delete the screen
|
||||
delete tempSheet;
|
||||
|
||||
m_designBlocksPane->RefreshLibs();
|
||||
m_designBlocksPane->SelectLibId( blk.GetLibId() );
|
||||
}
|
||||
|
||||
|
||||
bool SCH_EDIT_FRAME::DeleteDesignBlockLibrary( const wxString& aLibName, bool aConfirm )
|
||||
{
|
||||
if( aLibName.IsEmpty() )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Please select a library to delete." ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !Prj().DesignBlockLibs()->IsDesignBlockLibWritable( aLibName ) )
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Library '%s' is read only." ), aLibName );
|
||||
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( this, msg ) )
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
Prj().DesignBlockLibs()->DesignBlockLibDelete( aLibName );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( this, ioe.What() );
|
||||
return false;
|
||||
}
|
||||
|
||||
msg.Printf( _( "Design block library '%s' deleted" ), aLibName.GetData() );
|
||||
SetStatusText( msg );
|
||||
|
||||
m_designBlocksPane->RefreshLibs();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SCH_EDIT_FRAME::DeleteDesignBlockFromLibrary( const LIB_ID& aLibId, bool aConfirm )
|
||||
{
|
||||
if( !aLibId.IsValid() )
|
||||
return false;
|
||||
|
||||
wxString libname = aLibId.GetLibNickname();
|
||||
wxString dbname = aLibId.GetLibItemName();
|
||||
|
||||
if( !Prj().DesignBlockLibs()->IsDesignBlockLibWritable( libname ) )
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Library '%s' is read only." ), libname );
|
||||
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( this, msg ) )
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
Prj().DesignBlockLibs()->DesignBlockDelete( libname, dbname );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( this, ioe.What() );
|
||||
return false;
|
||||
}
|
||||
|
||||
msg.Printf( _( "Design block '%s' deleted from library '%s'" ), dbname.GetData(),
|
||||
libname.GetData() );
|
||||
|
||||
SetStatusText( msg );
|
||||
|
||||
m_designBlocksPane->RefreshLibs();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SCH_EDIT_FRAME::EditDesignBlockProperties( const LIB_ID& aLibId )
|
||||
{
|
||||
if( !aLibId.IsValid() )
|
||||
return false;
|
||||
|
||||
wxString libname = aLibId.GetLibNickname();
|
||||
wxString dbname = aLibId.GetLibItemName();
|
||||
|
||||
if( !Prj().DesignBlockLibs()->IsDesignBlockLibWritable( libname ) )
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Library '%s' is read only." ), libname );
|
||||
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( this, designBlock );
|
||||
|
||||
if( dlg.ShowModal() != wxID_OK )
|
||||
return false;
|
||||
|
||||
wxString newName = designBlock->GetLibId().GetLibItemName();
|
||||
|
||||
try
|
||||
{
|
||||
if( originalName != newName )
|
||||
{
|
||||
if( Prj().DesignBlockLibs()->DesignBlockExists( libname, newName ) )
|
||||
if( !checkOverwrite( this, libname, newName ) )
|
||||
return false;
|
||||
|
||||
Prj().DesignBlockLibs()->DesignBlockSave( libname, designBlock );
|
||||
Prj().DesignBlockLibs()->DesignBlockDelete( libname, originalName );
|
||||
}
|
||||
else
|
||||
Prj().DesignBlockLibs()->DesignBlockSave( libname, designBlock );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( this, ioe.What() );
|
||||
return false;
|
||||
}
|
||||
|
||||
m_designBlocksPane->RefreshLibs();
|
||||
m_designBlocksPane->SelectLibId( designBlock->GetLibId() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK* SchGetDesignBlock( const LIB_ID& aLibId, DESIGN_BLOCK_LIB_TABLE* aLibTable,
|
||||
wxWindow* aParent, bool aShowErrorMsg )
|
||||
{
|
||||
wxCHECK_MSG( aLibTable, nullptr, wxS( "Invalid design block library table." ) );
|
||||
|
||||
DESIGN_BLOCK* designBlock = nullptr;
|
||||
|
||||
try
|
||||
{
|
||||
designBlock = aLibTable->DesignBlockLoadWithOptionalNickname( aLibId, true );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
if( aShowErrorMsg )
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Error loading designblock %s from library '%s'." ),
|
||||
aLibId.GetLibItemName().wx_str(),
|
||||
aLibId.GetLibNickname().wx_str() );
|
||||
DisplayErrorMessage( aParent, msg, ioe.What() );
|
||||
}
|
||||
}
|
||||
|
||||
return designBlock;
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK* SCH_EDIT_FRAME::GetDesignBlock( const LIB_ID& aLibId, bool aUseCacheLib,
|
||||
bool aShowErrorMsg )
|
||||
{
|
||||
return SchGetDesignBlock( aLibId, Prj().DesignBlockLibs(), this, aShowErrorMsg );
|
||||
}
|
||||
|
||||
|
||||
void SCH_EDIT_FRAME::UpdateDesignBlockOptions()
|
||||
{
|
||||
m_designBlocksPane->UpdateCheckboxes();
|
||||
}
|
@ -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>
|
||||
|
@ -653,59 +653,6 @@ EESCHEMA_SETTINGS::EESCHEMA_SETTINGS() :
|
||||
m_params.emplace_back( new PARAM<bool>( "symbol_chooser.place_all_units",
|
||||
&m_SymChooserPanel.place_all_units, true ) );
|
||||
|
||||
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<bool>( "import_graphics.interactive_placement",
|
||||
&m_ImportGraphics.interactive_placement, true ) );
|
||||
|
||||
|
@ -276,21 +276,6 @@ public:
|
||||
bool place_all_units;
|
||||
};
|
||||
|
||||
struct PANEL_DESIGN_BLOCK_CHOOSER
|
||||
{
|
||||
int sash_pos_h;
|
||||
int sash_pos_v;
|
||||
int width;
|
||||
int height;
|
||||
int sort_mode;
|
||||
bool repeated_placement;
|
||||
bool place_as_sheet;
|
||||
bool keep_annotations;
|
||||
|
||||
// For saving tree columns and widths
|
||||
LIB_TREE tree;
|
||||
};
|
||||
|
||||
struct DIALOG_IMPORT_GRAPHICS
|
||||
{
|
||||
bool interactive_placement;
|
||||
@ -381,8 +366,6 @@ public:
|
||||
|
||||
PANEL_SYM_CHOOSER m_SymChooserPanel;
|
||||
|
||||
PANEL_DESIGN_BLOCK_CHOOSER m_DesignBlockChooserPanel;
|
||||
|
||||
DIALOG_IMPORT_GRAPHICS m_ImportGraphics;
|
||||
|
||||
SELECTION m_Selection;
|
||||
|
232
eeschema/sch_design_block_utils.cpp
Normal file
232
eeschema/sch_design_block_utils.cpp
Normal file
@ -0,0 +1,232 @@
|
||||
/*
|
||||
* 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 <pgm_base.h>
|
||||
#include <kiway.h>
|
||||
#include <design_block.h>
|
||||
#include <design_block_lib_table.h>
|
||||
#include <sch_design_block_pane.h>
|
||||
#include <sch_edit_frame.h>
|
||||
#include <wx/choicdlg.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/textdlg.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <paths.h>
|
||||
#include <env_paths.h>
|
||||
#include <common.h>
|
||||
#include <kidialog.h>
|
||||
#include <confirm.h>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <ee_selection_tool.h>
|
||||
#include <dialogs/dialog_design_block_properties.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
bool 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;
|
||||
}
|
||||
|
||||
|
||||
void SCH_EDIT_FRAME::SaveSheetAsDesignBlock( const wxString& aLibraryName,
|
||||
SCH_SHEET_PATH& aSheetPath )
|
||||
{
|
||||
// Make sure the user has selected a library to save into
|
||||
if( m_designBlocksPane->GetSelectedLibId().GetLibNickname().empty() )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Please select a library to save the design block to." ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// Just block all attempts to create design blocks with nested sheets at this point
|
||||
std::vector<SCH_ITEM*> sheets;
|
||||
aSheetPath.LastScreen()->GetSheets( &sheets );
|
||||
|
||||
if( !sheets.empty() )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Design blocks with nested sheets are not supported." ) );
|
||||
return;
|
||||
}
|
||||
|
||||
DESIGN_BLOCK blk;
|
||||
wxFileName fn = wxFileNameFromPath( aSheetPath.Last()->GetName() );
|
||||
|
||||
blk.SetLibId( LIB_ID( aLibraryName, fn.GetName() ) );
|
||||
|
||||
// Copy all fields from the sheet to the design block
|
||||
std::vector<SCH_FIELD>& shFields = aSheetPath.Last()->GetFields();
|
||||
nlohmann::ordered_map<wxString, wxString> dbFields;
|
||||
|
||||
for( int i = 0; i < (int) shFields.size(); i++ )
|
||||
{
|
||||
if( i == SHEETNAME || i == SHEETFILENAME )
|
||||
continue;
|
||||
|
||||
dbFields[shFields[i].GetCanonicalName()] = shFields[i].GetText();
|
||||
}
|
||||
|
||||
blk.SetFields( dbFields );
|
||||
|
||||
DIALOG_DESIGN_BLOCK_PROPERTIES dlg( this, &blk );
|
||||
|
||||
if( dlg.ShowModal() != wxID_OK )
|
||||
return;
|
||||
|
||||
// Save a temporary copy of the schematic file, as the plugin is just going to move it
|
||||
wxString tempFile = wxFileName::CreateTempFileName( "design_block" );
|
||||
if( !saveSchematicFile( aSheetPath.Last(), tempFile ) )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Error saving temporary schematic file to create design block." ) );
|
||||
wxRemoveFile( tempFile );
|
||||
return;
|
||||
}
|
||||
|
||||
blk.SetSchematicFile( tempFile );
|
||||
|
||||
try
|
||||
{
|
||||
wxString libName = blk.GetLibId().GetLibNickname();
|
||||
wxString newName = blk.GetLibId().GetLibItemName();
|
||||
|
||||
if( Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) )
|
||||
if( !checkOverwrite( this, libName, newName ) )
|
||||
return;
|
||||
|
||||
Prj().DesignBlockLibs()->DesignBlockSave( aLibraryName, &blk );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( this, ioe.What() );
|
||||
}
|
||||
|
||||
// Clean up the temporary file
|
||||
wxRemoveFile( tempFile );
|
||||
|
||||
m_designBlocksPane->RefreshLibs();
|
||||
m_designBlocksPane->SelectLibId( blk.GetLibId() );
|
||||
}
|
||||
|
||||
|
||||
void SCH_EDIT_FRAME::SaveSelectionAsDesignBlock( const wxString& aLibraryName )
|
||||
{
|
||||
// Make sure the user has selected a library to save into
|
||||
if( m_designBlocksPane->GetSelectedLibId().GetLibNickname().empty() )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Please select a library to save the design block to." ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all selected items
|
||||
EE_SELECTION selection = m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
|
||||
|
||||
if( selection.Empty() )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Please select some items to save as a design block." ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// Just block all attempts to create design blocks with nested sheets at this point
|
||||
if( selection.HasType( SCH_SHEET_T ) )
|
||||
{
|
||||
if( selection.Size() == 1 )
|
||||
{
|
||||
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( selection.Front() );
|
||||
SCH_SHEET_PATH curPath = GetCurrentSheet();
|
||||
|
||||
curPath.push_back( sheet );
|
||||
SaveSheetAsDesignBlock( aLibraryName, curPath );
|
||||
}
|
||||
else
|
||||
DisplayErrorMessage( this, _( "Design blocks with nested sheets are not supported." ) );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
DESIGN_BLOCK blk;
|
||||
wxFileName fn = wxFileNameFromPath( GetScreen()->GetFileName() );
|
||||
|
||||
blk.SetLibId( LIB_ID( aLibraryName, fn.GetName() ) );
|
||||
|
||||
DIALOG_DESIGN_BLOCK_PROPERTIES dlg( this, &blk );
|
||||
|
||||
if( dlg.ShowModal() != wxID_OK )
|
||||
return;
|
||||
|
||||
// Create a temporary screen
|
||||
SCH_SCREEN* tempScreen = new SCH_SCREEN( m_schematic );
|
||||
|
||||
// Copy the selected items to the temporary screen
|
||||
for( EDA_ITEM* item : selection )
|
||||
{
|
||||
EDA_ITEM* copy = item->Clone();
|
||||
tempScreen->Append( static_cast<SCH_ITEM*>( copy ) );
|
||||
}
|
||||
|
||||
// Create a sheet for the temporary screen
|
||||
SCH_SHEET* tempSheet = new SCH_SHEET( m_schematic );
|
||||
tempSheet->SetScreen( tempScreen );
|
||||
|
||||
// Save a temporary copy of the schematic file, as the plugin is just going to move it
|
||||
wxString tempFile = wxFileName::CreateTempFileName( "design_block" );
|
||||
if( !saveSchematicFile( tempSheet, tempFile ) )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Error saving temporary schematic file to create design block." ) );
|
||||
wxRemoveFile( tempFile );
|
||||
return;
|
||||
}
|
||||
|
||||
blk.SetSchematicFile( tempFile );
|
||||
|
||||
try
|
||||
{
|
||||
wxString libName = blk.GetLibId().GetLibNickname();
|
||||
wxString newName = blk.GetLibId().GetLibItemName();
|
||||
|
||||
if( Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) )
|
||||
if( !checkOverwrite( this, libName, newName ) )
|
||||
return;
|
||||
|
||||
Prj().DesignBlockLibs()->DesignBlockSave( aLibraryName, &blk );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( this, ioe.What() );
|
||||
}
|
||||
|
||||
// Clean up the temporaries
|
||||
wxRemoveFile( tempFile );
|
||||
// This will also delete the screen
|
||||
delete tempSheet;
|
||||
|
||||
m_designBlocksPane->RefreshLibs();
|
||||
m_designBlocksPane->SelectLibId( blk.GetLibId() );
|
||||
}
|
@ -34,7 +34,7 @@
|
||||
#include <dialogs/dialog_schematic_find.h>
|
||||
#include <dialogs/dialog_book_reporter.h>
|
||||
#include <dialogs/dialog_symbol_fields_table.h>
|
||||
#include <widgets/design_block_pane.h>
|
||||
#include <widgets/sch_design_block_pane.h>
|
||||
#include <eeschema_id.h>
|
||||
#include <executable_names.h>
|
||||
#include <gal/graphics_abstraction_layer.h>
|
||||
@ -212,7 +212,7 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
||||
m_propertiesPanel->SetSplitterProportion( eeconfig()->m_AuiPanels.properties_splitter );
|
||||
|
||||
m_selectionFilterPanel = new PANEL_SCH_SELECTION_FILTER( this );
|
||||
m_designBlocksPane = new DESIGN_BLOCK_PANE( this, nullptr, m_designBlockHistoryList );
|
||||
m_designBlocksPane = new SCH_DESIGN_BLOCK_PANE( this, nullptr, m_designBlockHistoryList );
|
||||
|
||||
m_auimgr.SetManagedWindow( this );
|
||||
|
||||
|
@ -56,8 +56,7 @@ class SCH_FIELD;
|
||||
class SCH_JUNCTION;
|
||||
class SCHEMATIC;
|
||||
class SCH_COMMIT;
|
||||
class DESIGN_BLOCK;
|
||||
class DESIGN_BLOCK_PANE;
|
||||
class SCH_DESIGN_BLOCK_PANE;
|
||||
class DIALOG_BOOK_REPORTER;
|
||||
class DIALOG_ERC;
|
||||
class DIALOG_SYMBOL_FIELDS_TABLE;
|
||||
@ -745,52 +744,11 @@ public:
|
||||
*/
|
||||
bool CreateArchiveLibrary( const wxString& aFileName );
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
void SaveSheetAsDesignBlock( const wxString& aLibraryName, SCH_SHEET_PATH& aSheetPath );
|
||||
|
||||
void SaveSelectionAsDesignBlock( const wxString& aLibraryName );
|
||||
|
||||
bool DeleteDesignBlockLibrary( const wxString& aLibName, bool aConfirm );
|
||||
|
||||
bool DeleteDesignBlockFromLibrary( const LIB_ID& aLibId, bool aConfirm );
|
||||
|
||||
bool EditDesignBlockProperties( 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 = false,
|
||||
bool aShowErrorMsg = false );
|
||||
|
||||
DESIGN_BLOCK_PANE* GetDesignBlockPane() const { return m_designBlocksPane; }
|
||||
SCH_DESIGN_BLOCK_PANE* GetDesignBlockPane() const { return m_designBlocksPane; }
|
||||
|
||||
/**
|
||||
* Plot or print the current sheet to the clipboard.
|
||||
@ -981,20 +939,6 @@ protected:
|
||||
void onPluginAvailabilityChanged( wxCommandEvent& aEvt );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Prompts a user to select global or project library tables
|
||||
*
|
||||
* @return Pointer to library table selected or nullptr if none selected/canceled
|
||||
*/
|
||||
DESIGN_BLOCK_LIB_TABLE* selectDesignBlockLibTable( bool aOptional = false );
|
||||
|
||||
/**
|
||||
* Create a new library in the given table (presumed to be either the global or project
|
||||
* library table).
|
||||
*/
|
||||
wxString createNewDesignBlockLibrary( const wxString& aLibName, const wxString& aProposedName,
|
||||
DESIGN_BLOCK_LIB_TABLE* aTable );
|
||||
|
||||
private:
|
||||
// Called when resizing the Hierarchy Navigator panel
|
||||
void OnResizeHierarchyNavigator( wxSizeEvent& aEvent );
|
||||
@ -1113,7 +1057,7 @@ private:
|
||||
|
||||
std::vector<LIB_ID> m_designBlockHistoryList;
|
||||
|
||||
DESIGN_BLOCK_PANE* m_designBlocksPane;
|
||||
SCH_DESIGN_BLOCK_PANE* m_designBlocksPane;
|
||||
|
||||
#ifdef KICAD_IPC_API
|
||||
std::unique_ptr<API_HANDLER_SCH> m_apiHandler;
|
||||
|
@ -37,9 +37,9 @@
|
||||
#include <tool/action_toolbar.h>
|
||||
#include <tools/ee_actions.h>
|
||||
#include <tools/ee_selection_tool.h>
|
||||
#include <widgets/design_block_pane.h>
|
||||
#include <widgets/hierarchy_pane.h>
|
||||
#include <widgets/wx_aui_utils.h>
|
||||
#include <widgets/sch_design_block_pane.h>
|
||||
#include <widgets/sch_properties_panel.h>
|
||||
#include <widgets/sch_search_pane.h>
|
||||
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include <sch_line_wire_bus_tool.h>
|
||||
#include <tool/tool_action.h>
|
||||
|
||||
class DESIGN_BLOCK;
|
||||
|
||||
// Actions, being statically-defined, require specialized I18N handling. We continue to
|
||||
// use the _() macro so that string harvesting by the I18N framework doesn't have to be
|
||||
// specialized, but we don't translate on initialization and instead do it in the getters.
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <tool/tool_action.h>
|
||||
#include <tool/actions.h>
|
||||
|
||||
class DESIGN_BLOCK;
|
||||
class SCH_SYMBOL;
|
||||
class TOOL_EVENT;
|
||||
class TOOL_MANAGER;
|
||||
|
@ -22,8 +22,8 @@
|
||||
*/
|
||||
#include <tool/library_editor_control.h>
|
||||
#include <sch_design_block_control.h>
|
||||
#include <design_block_pane.h>
|
||||
#include <panel_design_block_chooser.h>
|
||||
#include <widgets/sch_design_block_pane.h>
|
||||
#include <widgets/panel_design_block_chooser.h>
|
||||
#include <dialog_design_block_properties.h>
|
||||
#include <ee_actions.h>
|
||||
|
||||
@ -121,7 +121,8 @@ int SCH_DESIGN_BLOCK_CONTROL::UnpinLibrary( const TOOL_EVENT& aEvent )
|
||||
|
||||
int SCH_DESIGN_BLOCK_CONTROL::NewLibrary( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
m_editFrame->CreateNewDesignBlockLibrary();
|
||||
getDesignBlockPane()->CreateNewDesignBlockLibrary();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -160,7 +161,7 @@ int SCH_DESIGN_BLOCK_CONTROL::DeleteDesignBlock( const TOOL_EVENT& aEvent )
|
||||
if( !current )
|
||||
return -1;
|
||||
|
||||
m_editFrame->DeleteDesignBlockFromLibrary( current->m_LibId, true );
|
||||
getDesignBlockPane()->DeleteDesignBlockFromLibrary( current->m_LibId, true );
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -173,7 +174,7 @@ int SCH_DESIGN_BLOCK_CONTROL::EditDesignBlockProperties( const TOOL_EVENT& aEven
|
||||
if( !current )
|
||||
return -1;
|
||||
|
||||
if( m_editFrame->EditDesignBlockProperties( current->m_LibId ) )
|
||||
if( getDesignBlockPane()->EditDesignBlockProperties( current->m_LibId ) )
|
||||
return 0;
|
||||
|
||||
return -1;
|
||||
@ -205,13 +206,13 @@ void SCH_DESIGN_BLOCK_CONTROL::setTransitions()
|
||||
|
||||
LIB_ID SCH_DESIGN_BLOCK_CONTROL::getSelectedLibId()
|
||||
{
|
||||
m_editFrame->GetDesignBlockPane()->GetSelectedLibId();
|
||||
getDesignBlockPane()->GetSelectedLibId();
|
||||
|
||||
return LIB_ID();
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK_PANE* SCH_DESIGN_BLOCK_CONTROL::getDesignBlockPane()
|
||||
SCH_DESIGN_BLOCK_PANE* SCH_DESIGN_BLOCK_CONTROL::getDesignBlockPane()
|
||||
{
|
||||
return m_editFrame->GetDesignBlockPane();
|
||||
}
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include <sch_base_frame.h>
|
||||
#include <tools/ee_tool_base.h>
|
||||
|
||||
class DESIGN_BLOCK_PANE;
|
||||
|
||||
/**
|
||||
* Handle schematic design block actions in the schematic editor.
|
||||
*/
|
||||
@ -57,7 +59,7 @@ private:
|
||||
///< Set up handlers for various events.
|
||||
void setTransitions() override;
|
||||
|
||||
DESIGN_BLOCK_PANE* getDesignBlockPane();
|
||||
SCH_DESIGN_BLOCK_PANE* getDesignBlockPane();
|
||||
LIB_TREE_NODE* getCurrentTreeNode();
|
||||
|
||||
SCH_EDIT_FRAME* m_editFrame = nullptr;
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include <sch_edit_frame.h>
|
||||
#include <pgm_base.h>
|
||||
#include <design_block.h>
|
||||
#include <design_block_pane.h>
|
||||
#include <widgets/sch_design_block_pane.h>
|
||||
#include <eeschema_id.h>
|
||||
#include <confirm.h>
|
||||
#include <view/view_controls.h>
|
||||
@ -623,8 +623,8 @@ int SCH_DRAWING_TOOLS::ImportSheet( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
if( m_frame->GetDesignBlockPane()->GetSelectedLibId().IsValid() )
|
||||
{
|
||||
designBlock =
|
||||
m_frame->GetDesignBlock( m_frame->GetDesignBlockPane()->GetSelectedLibId() );
|
||||
designBlock = m_frame->GetDesignBlockPane()->GetDesignBlock(
|
||||
m_frame->GetDesignBlockPane()->GetSelectedLibId(), true, true );
|
||||
|
||||
if( !designBlock )
|
||||
return 0;
|
||||
@ -794,7 +794,7 @@ int SCH_DRAWING_TOOLS::ImportSheet( const TOOL_EVENT& aEvent )
|
||||
|
||||
sheetFileName = dlg.GetPath();
|
||||
|
||||
m_frame->UpdateDesignBlockOptions();
|
||||
m_frame->GetDesignBlockPane()->UpdateCheckboxes();
|
||||
}
|
||||
|
||||
if( sheetFileName.IsEmpty() )
|
||||
|
@ -22,7 +22,8 @@
|
||||
*/
|
||||
|
||||
#include <design_block.h>
|
||||
#include <widgets/design_block_pane.h>
|
||||
#include <widgets/sch_design_block_pane.h>
|
||||
#include <widgets/sch_design_block_preview_widget.h>
|
||||
#include <widgets/panel_design_block_chooser.h>
|
||||
#include <eeschema_settings.h>
|
||||
#include <kiface_base.h>
|
||||
@ -36,6 +37,7 @@
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <ee_actions.h>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <tools/sch_design_block_control.h>
|
||||
|
||||
|
||||
// Do not make these static wxStrings; they need to respond to language changes
|
||||
@ -43,10 +45,9 @@
|
||||
#define PLACE_AS_SHEET _( "Place as sheet" )
|
||||
#define KEEP_ANNOTATIONS _( "Keep annotations" )
|
||||
|
||||
DESIGN_BLOCK_PANE::DESIGN_BLOCK_PANE( SCH_EDIT_FRAME* aParent, const LIB_ID* aPreselect,
|
||||
SCH_DESIGN_BLOCK_PANE::SCH_DESIGN_BLOCK_PANE( SCH_EDIT_FRAME* aParent, const LIB_ID* aPreselect,
|
||||
std::vector<LIB_ID>& aHistoryList ) :
|
||||
WX_PANEL( aParent ),
|
||||
m_frame( aParent )
|
||||
DESIGN_BLOCK_PANE( aParent, aPreselect, aHistoryList )
|
||||
{
|
||||
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
|
||||
m_chooserPanel = new PANEL_DESIGN_BLOCK_CHOOSER( aParent, this, aHistoryList,
|
||||
@ -54,7 +55,10 @@ DESIGN_BLOCK_PANE::DESIGN_BLOCK_PANE( SCH_EDIT_FRAME* aParent, const LIB_ID* aPr
|
||||
{
|
||||
aParent->GetToolManager()->RunAction(
|
||||
EE_ACTIONS::placeDesignBlock );
|
||||
} );
|
||||
},
|
||||
aParent->GetToolManager()->GetTool<SCH_DESIGN_BLOCK_CONTROL>()
|
||||
);
|
||||
m_chooserPanel->SetPreviewWidget(new SCH_DESIGN_BLOCK_PREVIEW_WIDGET( m_chooserPanel->GetDetailsPanel(), EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL, true ) );
|
||||
sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
|
||||
|
||||
if( aPreselect && aPreselect->IsValid() )
|
||||
@ -71,13 +75,13 @@ DESIGN_BLOCK_PANE::DESIGN_BLOCK_PANE( SCH_EDIT_FRAME* aParent, const LIB_ID* aPr
|
||||
UpdateCheckboxes();
|
||||
|
||||
// Set all checkbox handlers to the same function
|
||||
m_repeatedPlacement->Bind( wxEVT_CHECKBOX, &DESIGN_BLOCK_PANE::OnCheckBox, this );
|
||||
m_placeAsSheet->Bind( wxEVT_CHECKBOX, &DESIGN_BLOCK_PANE::OnCheckBox, this );
|
||||
m_keepAnnotations->Bind( wxEVT_CHECKBOX, &DESIGN_BLOCK_PANE::OnCheckBox, this );
|
||||
m_repeatedPlacement->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
|
||||
m_placeAsSheet->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
|
||||
m_keepAnnotations->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
|
||||
|
||||
cbSizer->Add( m_repeatedPlacement, 0, wxTOP|wxLEFT, 2 );
|
||||
cbSizer->Add( m_placeAsSheet, 0, wxTOP|wxLEFT, 2 );
|
||||
cbSizer->Add( m_keepAnnotations, 0, wxTOP|wxLEFT|wxBOTTOM, 2 );
|
||||
cbSizer->Add( m_repeatedPlacement, 0, wxTOP | wxLEFT, 2 );
|
||||
cbSizer->Add( m_placeAsSheet, 0, wxTOP | wxLEFT, 2 );
|
||||
cbSizer->Add( m_keepAnnotations, 0, wxTOP | wxLEFT | wxBOTTOM, 2 );
|
||||
|
||||
sizer->Add( cbSizer, 0, wxEXPAND, 5 );
|
||||
SetSizer( sizer );
|
||||
@ -90,13 +94,7 @@ DESIGN_BLOCK_PANE::DESIGN_BLOCK_PANE( SCH_EDIT_FRAME* aParent, const LIB_ID* aPr
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK_PANE::~DESIGN_BLOCK_PANE()
|
||||
{
|
||||
m_frame->Unbind( EDA_LANG_CHANGED, &DESIGN_BLOCK_PANE::OnLanguageChanged, this );
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_PANE::setLabelsAndTooltips()
|
||||
void SCH_DESIGN_BLOCK_PANE::setLabelsAndTooltips()
|
||||
{
|
||||
if( m_repeatedPlacement )
|
||||
{
|
||||
@ -121,18 +119,7 @@ void DESIGN_BLOCK_PANE::setLabelsAndTooltips()
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_PANE::OnLanguageChanged( wxCommandEvent& aEvent )
|
||||
{
|
||||
if( m_chooserPanel )
|
||||
m_chooserPanel->ShowChangedLanguage();
|
||||
|
||||
setLabelsAndTooltips();
|
||||
|
||||
aEvent.Skip();
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_PANE::OnCheckBox( wxCommandEvent& aEvent )
|
||||
void SCH_DESIGN_BLOCK_PANE::OnCheckBox( wxCommandEvent& aEvent )
|
||||
{
|
||||
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
||||
{
|
||||
@ -143,7 +130,7 @@ void DESIGN_BLOCK_PANE::OnCheckBox( wxCommandEvent& aEvent )
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_PANE::UpdateCheckboxes()
|
||||
void SCH_DESIGN_BLOCK_PANE::UpdateCheckboxes()
|
||||
{
|
||||
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
||||
{
|
||||
@ -154,30 +141,6 @@ void DESIGN_BLOCK_PANE::UpdateCheckboxes()
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
FILEDLG_IMPORT_SHEET_CONTENTS::FILEDLG_IMPORT_SHEET_CONTENTS( EESCHEMA_SETTINGS* aSettings ) :
|
||||
m_cbRepeatedPlacement( nullptr ),
|
||||
m_cbPlaceAsSheet( nullptr ),
|
@ -20,9 +20,10 @@
|
||||
* 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
|
||||
#ifndef SCH_DESIGN_BLOCK_PANE_H
|
||||
#define SCH_DESIGN_BLOCK_PANE_H
|
||||
|
||||
#include <widgets/design_block_pane.h>
|
||||
#include <design_block_tree_model_adapter.h>
|
||||
#include <widgets/html_window.h>
|
||||
#include <widgets/wx_panel.h>
|
||||
@ -35,40 +36,11 @@ class SCH_EDIT_FRAME;
|
||||
class PANEL_DESIGN_BLOCK_CHOOSER;
|
||||
|
||||
|
||||
class DESIGN_BLOCK_PANE : public WX_PANEL
|
||||
class SCH_DESIGN_BLOCK_PANE : public DESIGN_BLOCK_PANE
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create dialog to choose design_block.
|
||||
*
|
||||
* @param aParent a SCH_BASE_FRAME parent window.
|
||||
* @param aAllowFieldEdits if false, all functions that allow the user to edit fields
|
||||
* (currently just footprint selection) will not be available.
|
||||
* @param aShowFootprints if false, all footprint preview and selection features are
|
||||
* disabled. This forces aAllowFieldEdits false too.
|
||||
*/
|
||||
DESIGN_BLOCK_PANE( SCH_EDIT_FRAME* aParent, const LIB_ID* aPreselect,
|
||||
std::vector<LIB_ID>& aHistoryList );
|
||||
|
||||
~DESIGN_BLOCK_PANE() override;
|
||||
|
||||
void SaveSettings();
|
||||
|
||||
/**
|
||||
* To be called after this dialog returns from ShowModal().
|
||||
*
|
||||
* For multi-unit design_blocks, if the user selects the design_block itself rather than picking
|
||||
* an individual unit, 0 will be returned in aUnit.
|
||||
* Beware that this is an invalid unit number - this should be replaced with whatever
|
||||
* default is desired (usually 1).
|
||||
*
|
||||
* @param aUnit if not NULL, the selected unit is filled in here.
|
||||
* @return the #LIB_ID of the design_block that has been selected.
|
||||
*/
|
||||
LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
|
||||
void SelectLibId( const LIB_ID& aLibId );
|
||||
|
||||
void RefreshLibs();
|
||||
SCH_DESIGN_BLOCK_PANE( SCH_EDIT_FRAME* aParent, const LIB_ID* aPreselect,
|
||||
std::vector<LIB_ID>& aHistoryList );
|
||||
|
||||
/* Handler for checkbox events */
|
||||
void OnCheckBox( wxCommandEvent& aEvent );
|
||||
@ -77,24 +49,13 @@ public:
|
||||
void OnSaveSheetAsDesignBlock( wxCommandEvent& aEvent );
|
||||
void OnSaveSelectionAsDesignBlock( wxCommandEvent& aEvent );
|
||||
|
||||
void OnDeleteLibrary( wxCommandEvent& aEvent );
|
||||
void OnDeleteDesignBlock( wxCommandEvent& aEvent );
|
||||
|
||||
PANEL_DESIGN_BLOCK_CHOOSER* GetDesignBlockPanel() const { return m_chooserPanel; }
|
||||
protected:
|
||||
void setLabelsAndTooltips() override;
|
||||
|
||||
protected:
|
||||
void setLabelsAndTooltips();
|
||||
|
||||
virtual void OnLanguageChanged( wxCommandEvent& aEvent );
|
||||
|
||||
protected:
|
||||
PANEL_DESIGN_BLOCK_CHOOSER* m_chooserPanel;
|
||||
|
||||
wxCheckBox* m_repeatedPlacement;
|
||||
wxCheckBox* m_placeAsSheet;
|
||||
wxCheckBox* m_keepAnnotations;
|
||||
|
||||
SCH_EDIT_FRAME* m_frame;
|
||||
wxCheckBox* m_repeatedPlacement;
|
||||
wxCheckBox* m_placeAsSheet;
|
||||
wxCheckBox* m_keepAnnotations;
|
||||
};
|
||||
|
||||
|
||||
@ -105,9 +66,9 @@ class FILEDLG_IMPORT_SHEET_CONTENTS : public wxFileDialogCustomizeHook
|
||||
public:
|
||||
FILEDLG_IMPORT_SHEET_CONTENTS( EESCHEMA_SETTINGS* aSettings );
|
||||
|
||||
virtual void AddCustomControls( wxFileDialogCustomize& customizer ) override;
|
||||
void AddCustomControls( wxFileDialogCustomize& customizer ) override;
|
||||
|
||||
virtual void TransferDataFromCustomControls() override;
|
||||
void TransferDataFromCustomControls() override;
|
||||
|
||||
private:
|
||||
EESCHEMA_SETTINGS* m_settings;
|
@ -17,7 +17,6 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "design_block_preview_widget.h"
|
||||
#include <schematic.h>
|
||||
#include <sch_sheet.h>
|
||||
#include <sch_view.h>
|
||||
@ -35,13 +34,16 @@
|
||||
#include <eeschema_settings.h>
|
||||
#include <eeschema_helpers.h>
|
||||
#include <settings/settings_manager.h>
|
||||
#include <widgets/sch_design_block_preview_widget.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/stattext.h>
|
||||
#include <wx/panel.h>
|
||||
|
||||
|
||||
DESIGN_BLOCK_PREVIEW_WIDGET::DESIGN_BLOCK_PREVIEW_WIDGET( wxWindow* aParent, bool aIncludeStatus,
|
||||
EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) :
|
||||
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ),
|
||||
SCH_DESIGN_BLOCK_PREVIEW_WIDGET::SCH_DESIGN_BLOCK_PREVIEW_WIDGET( wxWindow* aParent,
|
||||
EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType,
|
||||
bool aIncludeStatus ) :
|
||||
DESIGN_BLOCK_PREVIEW_WIDGET( aParent ),
|
||||
m_preview( nullptr ),
|
||||
m_status( nullptr ),
|
||||
m_statusPanel( nullptr ),
|
||||
@ -131,11 +133,11 @@ DESIGN_BLOCK_PREVIEW_WIDGET::DESIGN_BLOCK_PREVIEW_WIDGET( wxWindow* aParent, boo
|
||||
SetSizer( m_outerSizer );
|
||||
Layout();
|
||||
|
||||
Connect( wxEVT_SIZE, wxSizeEventHandler( DESIGN_BLOCK_PREVIEW_WIDGET::onSize ), nullptr, this );
|
||||
Connect( wxEVT_SIZE, wxSizeEventHandler( SCH_DESIGN_BLOCK_PREVIEW_WIDGET::onSize ), nullptr, this );
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK_PREVIEW_WIDGET::~DESIGN_BLOCK_PREVIEW_WIDGET()
|
||||
SCH_DESIGN_BLOCK_PREVIEW_WIDGET::~SCH_DESIGN_BLOCK_PREVIEW_WIDGET()
|
||||
{
|
||||
if( m_previewItem )
|
||||
m_preview->GetView()->Remove( m_previewItem );
|
||||
@ -144,7 +146,7 @@ DESIGN_BLOCK_PREVIEW_WIDGET::~DESIGN_BLOCK_PREVIEW_WIDGET()
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_PREVIEW_WIDGET::SetStatusText( wxString const& aText )
|
||||
void SCH_DESIGN_BLOCK_PREVIEW_WIDGET::SetStatusText( wxString const& aText )
|
||||
{
|
||||
wxCHECK( m_statusPanel, /* void */ );
|
||||
|
||||
@ -155,7 +157,7 @@ void DESIGN_BLOCK_PREVIEW_WIDGET::SetStatusText( wxString const& aText )
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_PREVIEW_WIDGET::onSize( wxSizeEvent& aEvent )
|
||||
void SCH_DESIGN_BLOCK_PREVIEW_WIDGET::onSize( wxSizeEvent& aEvent )
|
||||
{
|
||||
if( m_previewItem )
|
||||
{
|
||||
@ -167,7 +169,7 @@ void DESIGN_BLOCK_PREVIEW_WIDGET::onSize( wxSizeEvent& aEvent )
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_PREVIEW_WIDGET::fitOnDrawArea()
|
||||
void SCH_DESIGN_BLOCK_PREVIEW_WIDGET::fitOnDrawArea()
|
||||
{
|
||||
if( !m_previewItem )
|
||||
return;
|
||||
@ -191,7 +193,7 @@ void DESIGN_BLOCK_PREVIEW_WIDGET::fitOnDrawArea()
|
||||
}
|
||||
|
||||
|
||||
void DESIGN_BLOCK_PREVIEW_WIDGET::DisplayDesignBlock( DESIGN_BLOCK* aDesignBlock )
|
||||
void SCH_DESIGN_BLOCK_PREVIEW_WIDGET::DisplayDesignBlock( DESIGN_BLOCK* aDesignBlock )
|
||||
{
|
||||
KIGFX::VIEW* view = m_preview->GetView();
|
||||
|
@ -17,10 +17,11 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DESIGN_BLOCK_PREVIEW_WIDGET_H
|
||||
#define DESIGN_BLOCK_PREVIEW_WIDGET_H
|
||||
#ifndef SCH_DESIGN_BLOCK_PREVIEW_WIDGET_H
|
||||
#define SCH_DESIGN_BLOCK_PREVIEW_WIDGET_H
|
||||
|
||||
#include <wx/panel.h>
|
||||
#include <widgets/design_block_preview_widget.h>
|
||||
#include <kiway.h>
|
||||
#include <gal_display_options_common.h>
|
||||
#include <class_draw_panel_gal.h>
|
||||
@ -34,29 +35,27 @@ class wxStaticText;
|
||||
class wxSizer;
|
||||
|
||||
|
||||
class DESIGN_BLOCK_PREVIEW_WIDGET : public wxPanel
|
||||
class SCH_DESIGN_BLOCK_PREVIEW_WIDGET : public DESIGN_BLOCK_PREVIEW_WIDGET
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Construct a symbol preview widget.
|
||||
* Construct a schematic design block preview widget.
|
||||
*
|
||||
* @param aParent - parent window
|
||||
* @param aCanvasType = the type of canvas (GAL_TYPE_OPENGL or GAL_TYPE_CAIRO only)
|
||||
*/
|
||||
DESIGN_BLOCK_PREVIEW_WIDGET( wxWindow* aParent, bool aIncludeStatus,
|
||||
EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType );
|
||||
SCH_DESIGN_BLOCK_PREVIEW_WIDGET( wxWindow* aParent, EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType, bool aIncludeStatus );
|
||||
|
||||
~DESIGN_BLOCK_PREVIEW_WIDGET() override;
|
||||
~SCH_DESIGN_BLOCK_PREVIEW_WIDGET() override;
|
||||
|
||||
/**
|
||||
* Set the contents of the status label and display it.
|
||||
*/
|
||||
void SetStatusText( const wxString& aText );
|
||||
void SetStatusText( const wxString& aText ) override;
|
||||
|
||||
/**
|
||||
* Set the currently displayed symbol.
|
||||
*/
|
||||
void DisplayDesignBlock( DESIGN_BLOCK* aDesignBlock );
|
||||
void DisplayDesignBlock( DESIGN_BLOCK* aDesignBlock ) override;
|
||||
|
||||
protected:
|
||||
void onSize( wxSizeEvent& aEvent );
|
||||
@ -78,4 +77,4 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
#endif // DESIGN_BLOCK_PREVIEW_WIDGET_H
|
||||
#endif
|
@ -135,6 +135,21 @@ public:
|
||||
std::vector<wxString> open_libs; ///< list of libraries the user has open in the tree.
|
||||
};
|
||||
|
||||
struct PANEL_DESIGN_BLOCK_CHOOSER
|
||||
{
|
||||
int sash_pos_h;
|
||||
int sash_pos_v;
|
||||
int width;
|
||||
int height;
|
||||
int sort_mode;
|
||||
bool repeated_placement;
|
||||
bool place_as_sheet;
|
||||
bool keep_annotations;
|
||||
|
||||
// For saving tree columns and widths
|
||||
LIB_TREE tree;
|
||||
};
|
||||
|
||||
struct PRINTING
|
||||
{
|
||||
bool background; ///< Whether or not to print background color.
|
||||
@ -179,6 +194,8 @@ public:
|
||||
|
||||
FIND_REPLACE m_FindReplace;
|
||||
|
||||
PANEL_DESIGN_BLOCK_CHOOSER m_DesignBlockChooserPanel;
|
||||
|
||||
GRAPHICS m_Graphics;
|
||||
|
||||
COLOR_PICKER m_ColorPicker;
|
||||
|
Loading…
x
Reference in New Issue
Block a user