Browse Source

design blocks: convenience: copy fields from sheet to new design block

pcb_db
Mike Williams 1 year ago
parent
commit
0b9984d547
  1. 17
      eeschema/design_block_utils.cpp
  2. 2
      eeschema/tools/ee_actions.cpp

17
eeschema/design_block_utils.cpp

@ -39,6 +39,7 @@
#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 )
@ -302,10 +303,24 @@ void SCH_EDIT_FRAME::SaveSheetAsDesignBlock( const wxString& aLibraryName,
}
DESIGN_BLOCK blk;
wxFileName fn = wxFileNameFromPath( aSheetPath.LastScreen()->GetFileName() );
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 )

2
eeschema/tools/ee_actions.cpp

@ -156,7 +156,7 @@ TOOL_ACTION EE_ACTIONS::syncSelection( TOOL_ACTION_ARGS()
TOOL_ACTION EE_ACTIONS::saveSheetAsDesignBlock( TOOL_ACTION_ARGS()
.Name( "eeschema.SchDesignBlockControl.saveSheetAsDesignBlock" )
.Scope( AS_GLOBAL )
.FriendlyName( _( "Save Sheet as Design Block..." ) )
.FriendlyName( _( "Save Current Sheet as Design Block..." ) )
.Tooltip( _( "Create a new design block from the current sheet" ) )
.Icon( BITMAPS::new_component ) );

Loading…
Cancel
Save