kicad/eeschema/picksymbol.cpp

180 lines
5.7 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2004-2023 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 <symbol_library.h>
#include <settings/settings_manager.h>
#include <project/project_file.h>
#include <core/kicad_algo.h>
#include <symbol_library_common.h>
#include <confirm.h>
#include <eeschema_id.h>
#include <general.h>
#include <kiway.h>
2020-12-25 23:37:01 +00:00
#include <symbol_viewer_frame.h>
#include <symbol_tree_model_adapter.h>
#include <symbol_editor/symbol_editor_settings.h>
#include <sch_symbol.h>
#include <sch_commit.h>
2018-01-30 10:49:51 +00:00
#include <sch_edit_frame.h>
#include <symbol_lib_table.h>
#include <tool/tool_manager.h>
#include <tools/ee_actions.h>
#include <project_sch.h>
#include <dialog_symbol_chooser.h>
PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibrary( const SYMBOL_LIBRARY_FILTER* aFilter,
std::vector<PICKED_SYMBOL>& aHistoryList,
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
2020-12-25 23:37:01 +00:00
bool aShowFootprints, const LIB_ID* aHighlight,
2020-11-07 14:31:50 +00:00
bool aAllowFields )
{
std::unique_lock<std::mutex> dialogLock( DIALOG_SYMBOL_CHOOSER::g_Mutex, std::defer_lock );
// One DIALOG_SYMBOL_CHOOSER dialog at a time. User probably can't handle more anyway.
if( !dialogLock.try_lock() )
2020-11-07 14:31:50 +00:00
return PICKED_SYMBOL();
DIALOG_SYMBOL_CHOOSER dlg( this, aHighlight, aFilter, aHistoryList, aAlreadyPlaced,
aAllowFields, aShowFootprints );
if( dlg.ShowModal() == wxID_CANCEL )
return PICKED_SYMBOL();
2020-11-07 14:31:50 +00:00
PICKED_SYMBOL sel;
LIB_ID id = dlg.GetSelectedLibId( &sel.Unit );
if( !id.IsValid() )
2020-11-07 14:31:50 +00:00
return PICKED_SYMBOL();
if( sel.Unit == 0 )
sel.Unit = 1;
sel.Fields = dlg.GetFields();
sel.LibId = id;
if( sel.LibId.IsValid() )
{
alg::delete_if( aHistoryList, [&sel]( PICKED_SYMBOL const& i )
{
return i.LibId == sel.LibId;
} );
aHistoryList.insert( aHistoryList.begin(), sel );
}
return sel;
}
2021-06-10 14:10:55 +00:00
void SCH_EDIT_FRAME::SelectUnit( SCH_SYMBOL* aSymbol, int aUnit )
{
SCH_COMMIT commit( m_toolManager );
2021-06-17 21:22:10 +00:00
LIB_SYMBOL* symbol = GetLibSymbol( aSymbol->GetLibId() );
2021-06-10 18:51:46 +00:00
if( !symbol )
return;
2021-06-10 18:51:46 +00:00
int unitCount = symbol->GetUnitCount();
2021-03-19 20:27:30 +00:00
if( unitCount <= 1 || aSymbol->GetUnit() == aUnit )
return;
if( aUnit > unitCount )
aUnit = unitCount;
2021-03-19 20:27:30 +00:00
if( !aSymbol->GetEditFlags() ) // No command in progress: save in undo list
commit.Modify( aSymbol, GetScreen() );
/* Update the unit number. */
2021-03-19 20:27:30 +00:00
aSymbol->SetUnitSelection( &GetCurrentSheet(), aUnit );
aSymbol->SetUnit( aUnit );
if( !commit.Empty() )
{
if( eeconfig()->m_AutoplaceFields.enable )
2021-03-19 20:27:30 +00:00
aSymbol->AutoAutoplaceFields( GetScreen() );
commit.Push( _( "Change Unit" ) );
}
}
void SCH_EDIT_FRAME::FlipBodyStyle( SCH_SYMBOL* aSymbol )
{
if( !aSymbol || !aSymbol->GetLibSymbolRef() )
return;
SCH_COMMIT commit( m_toolManager );
wxString msg;
if( !aSymbol->GetLibSymbolRef()->HasAlternateBodyStyle() )
{
LIB_ID id = aSymbol->GetLibSymbolRef()->GetLibId();
msg.Printf( _( "No alternate body style found for symbol '%s' in library '%s'." ),
id.GetLibItemName().wx_str(),
id.GetLibNickname().wx_str() );
DisplayError( this, msg );
return;
}
commit.Modify( aSymbol, GetScreen() );
aSymbol->SetBodyStyle( aSymbol->GetBodyStyle() + 1 );
// ensure m_bodyStyle = 1 or 2
// 1 = shape 1 = first (base DeMorgan) alternate body style
// 2 = shape 2 = second (DeMorgan conversion) alternate body style
2021-03-19 20:27:30 +00:00
// > 2 is not currently supported
// When m_bodyStyle = val max, return to the first shape
if( aSymbol->GetBodyStyle() > LIB_ITEM::BODY_STYLE::DEMORGAN )
aSymbol->SetBodyStyle( LIB_ITEM::BODY_STYLE::BASE );
// If selected make sure all the now-included pins are selected
2021-03-19 20:27:30 +00:00
if( aSymbol->IsSelected() )
m_toolManager->RunAction<EDA_ITEM*>( EE_ACTIONS::addItemToSel, aSymbol );
commit.Push( _( "Change Body Style" ) );
}
void SCH_EDIT_FRAME::SetAltPinFunction( SCH_PIN* aPin, const wxString& aFunction )
{
if( !aPin )
return;
SCH_COMMIT commit( m_toolManager );
commit.Modify( aPin, GetScreen() );
if( aFunction == aPin->GetName() )
aPin->SetAlt( wxEmptyString );
else
aPin->SetAlt( aFunction );
commit.Push( _( "Set Pin Function" ) );
}