2019-05-08 18:56:03 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2021-01-08 23:24:12 +00:00
|
|
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-08 18:56:03 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
#include <tool/picker_tool.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <tools/ee_selection_tool.h>
|
2020-12-12 03:13:52 +00:00
|
|
|
#include <tools/symbol_editor_pin_tool.h>
|
|
|
|
#include <tools/symbol_editor_drawing_tools.h>
|
|
|
|
#include <tools/symbol_editor_move_tool.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <ee_actions.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2023-06-09 21:41:33 +00:00
|
|
|
#include <sch_commit.h>
|
2021-08-06 19:54:26 +00:00
|
|
|
#include <dialogs/dialog_lib_shape_properties.h>
|
|
|
|
#include <dialogs/dialog_lib_text_properties.h>
|
2023-06-09 16:24:49 +00:00
|
|
|
#include <dialogs/dialog_lib_textbox_properties.h>
|
2021-08-06 19:54:26 +00:00
|
|
|
#include <dialogs/dialog_field_properties.h>
|
2020-10-22 09:40:54 +00:00
|
|
|
#include <dialogs/dialog_lib_symbol_properties.h>
|
2019-05-11 14:38:05 +00:00
|
|
|
#include <dialogs/dialog_lib_edit_pin_table.h>
|
2021-02-13 21:28:06 +00:00
|
|
|
#include <dialogs/dialog_update_symbol_fields.h>
|
2023-12-24 00:31:24 +00:00
|
|
|
#include <sch_io/kicad_sexpr/sch_io_kicad_sexpr.h>
|
2019-08-15 07:19:15 +00:00
|
|
|
#include <lib_text.h>
|
2023-06-09 16:24:49 +00:00
|
|
|
#include <lib_textbox.h>
|
2020-12-12 03:13:52 +00:00
|
|
|
#include "symbol_editor_edit_tool.h"
|
2022-09-14 22:11:37 +00:00
|
|
|
#include <wx/textdlg.h> // for wxTextEntryDialog
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
SYMBOL_EDITOR_EDIT_TOOL::SYMBOL_EDITOR_EDIT_TOOL() :
|
2020-01-11 16:56:25 +00:00
|
|
|
EE_TOOL_BASE( "eeschema.SymbolEditTool" ),
|
|
|
|
m_pickerItem( nullptr )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
bool SYMBOL_EDITOR_EDIT_TOOL::Init()
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE::Init();
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
SYMBOL_EDITOR_DRAWING_TOOLS* drawingTools = m_toolMgr->GetTool<SYMBOL_EDITOR_DRAWING_TOOLS>();
|
|
|
|
SYMBOL_EDITOR_MOVE_TOOL* moveTool = m_toolMgr->GetTool<SYMBOL_EDITOR_MOVE_TOOL>();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-06-09 22:21:53 +00:00
|
|
|
wxASSERT_MSG( drawingTools, "eeschema.SymbolDrawing tool is not available" );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
auto haveSymbolCondition =
|
2020-08-20 23:05:21 +00:00
|
|
|
[&]( const SELECTION& sel )
|
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
return m_isSymbolEditor &&
|
|
|
|
static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
|
2020-08-20 23:05:21 +00:00
|
|
|
};
|
|
|
|
|
2021-01-08 23:24:12 +00:00
|
|
|
auto canEdit =
|
|
|
|
[&]( const SELECTION& sel )
|
|
|
|
{
|
|
|
|
SYMBOL_EDIT_FRAME* editor = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
|
|
|
wxCHECK( editor, false );
|
|
|
|
|
2021-02-10 22:56:26 +00:00
|
|
|
if( !editor->IsSymbolEditable() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( editor->IsSymbolAlias() )
|
|
|
|
{
|
|
|
|
for( EDA_ITEM* item : sel )
|
|
|
|
{
|
|
|
|
if( item->Type() != LIB_FIELD_T )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2021-01-08 23:24:12 +00:00
|
|
|
};
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
// Add edit actions to the move tool menu
|
|
|
|
if( moveTool )
|
|
|
|
{
|
|
|
|
CONDITIONAL_MENU& moveMenu = moveTool->GetToolMenu().GetMenu();
|
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
moveMenu.AddSeparator( 200 );
|
2021-01-08 23:24:12 +00:00
|
|
|
moveMenu.AddItem( EE_ACTIONS::rotateCCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
|
|
|
|
moveMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
|
2021-02-16 20:45:25 +00:00
|
|
|
moveMenu.AddItem( EE_ACTIONS::mirrorV, canEdit && EE_CONDITIONS::NotEmpty, 200 );
|
|
|
|
moveMenu.AddItem( EE_ACTIONS::mirrorH, canEdit && EE_CONDITIONS::NotEmpty, 200 );
|
2019-05-12 11:49:58 +00:00
|
|
|
|
2021-01-08 23:24:12 +00:00
|
|
|
moveMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 );
|
2019-05-12 11:49:58 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
moveMenu.AddSeparator( 300 );
|
2021-01-08 23:24:12 +00:00
|
|
|
moveMenu.AddItem( ACTIONS::cut, EE_CONDITIONS::IdleSelection, 300 );
|
|
|
|
moveMenu.AddItem( ACTIONS::copy, EE_CONDITIONS::IdleSelection, 300 );
|
|
|
|
moveMenu.AddItem( ACTIONS::duplicate, canEdit && EE_CONDITIONS::NotEmpty, 300 );
|
2021-01-17 18:19:02 +00:00
|
|
|
moveMenu.AddItem( ACTIONS::doDelete, canEdit && EE_CONDITIONS::NotEmpty, 200 );
|
2020-08-20 23:05:21 +00:00
|
|
|
|
|
|
|
moveMenu.AddSeparator( 400 );
|
2021-06-15 12:31:28 +00:00
|
|
|
moveMenu.AddItem( ACTIONS::selectAll, haveSymbolCondition, 400 );
|
2023-09-06 23:44:39 +00:00
|
|
|
moveMenu.AddItem( ACTIONS::unselectAll, haveSymbolCondition, 400 );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add editing actions to the drawing tool menu
|
|
|
|
CONDITIONAL_MENU& drawMenu = drawingTools->GetToolMenu().GetMenu();
|
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
drawMenu.AddSeparator( 200 );
|
2021-01-08 23:24:12 +00:00
|
|
|
drawMenu.AddItem( EE_ACTIONS::rotateCCW, canEdit && EE_CONDITIONS::IdleSelection, 200 );
|
|
|
|
drawMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::IdleSelection, 200 );
|
2021-02-16 20:45:25 +00:00
|
|
|
drawMenu.AddItem( EE_ACTIONS::mirrorV, canEdit && EE_CONDITIONS::IdleSelection, 200 );
|
|
|
|
drawMenu.AddItem( EE_ACTIONS::mirrorH, canEdit && EE_CONDITIONS::IdleSelection, 200 );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-01-08 23:24:12 +00:00
|
|
|
drawMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
// Add editing actions to the selection tool menu
|
|
|
|
CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
|
|
|
|
|
2021-01-08 23:24:12 +00:00
|
|
|
selToolMenu.AddItem( EE_ACTIONS::rotateCCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
|
|
|
|
selToolMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
|
2021-02-16 20:45:25 +00:00
|
|
|
selToolMenu.AddItem( EE_ACTIONS::mirrorV, canEdit && EE_CONDITIONS::NotEmpty, 200 );
|
|
|
|
selToolMenu.AddItem( EE_ACTIONS::mirrorH, canEdit && EE_CONDITIONS::NotEmpty, 200 );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-01-08 23:24:12 +00:00
|
|
|
selToolMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
selToolMenu.AddSeparator( 300 );
|
2021-01-08 23:24:12 +00:00
|
|
|
selToolMenu.AddItem( ACTIONS::cut, EE_CONDITIONS::IdleSelection, 300 );
|
|
|
|
selToolMenu.AddItem( ACTIONS::copy, EE_CONDITIONS::IdleSelection, 300 );
|
|
|
|
selToolMenu.AddItem( ACTIONS::paste, canEdit && EE_CONDITIONS::Idle, 300 );
|
|
|
|
selToolMenu.AddItem( ACTIONS::duplicate, canEdit && EE_CONDITIONS::NotEmpty, 300 );
|
2021-01-17 18:19:02 +00:00
|
|
|
selToolMenu.AddItem( ACTIONS::doDelete, canEdit && EE_CONDITIONS::NotEmpty, 300 );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-08-20 23:05:21 +00:00
|
|
|
selToolMenu.AddSeparator( 400 );
|
2021-06-15 12:31:28 +00:00
|
|
|
selToolMenu.AddItem( ACTIONS::selectAll, haveSymbolCondition, 400 );
|
2023-09-06 23:44:39 +00:00
|
|
|
selToolMenu.AddItem( ACTIONS::unselectAll, haveSymbolCondition, 400 );
|
2020-08-20 23:05:21 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( selection.GetSize() == 0 )
|
|
|
|
return 0;
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
VECTOR2I rotPoint;
|
|
|
|
bool ccw = ( aEvent.Matches( EE_ACTIONS::rotateCCW.MakeEvent() ) );
|
|
|
|
LIB_ITEM* item = static_cast<LIB_ITEM*>( selection.Front() );
|
|
|
|
SCH_COMMIT localCommit( m_toolMgr );
|
2023-06-26 23:57:09 +00:00
|
|
|
SCH_COMMIT* commit = dynamic_cast<SCH_COMMIT*>( aEvent.Commit() );
|
2023-06-09 21:41:33 +00:00
|
|
|
|
|
|
|
if( !commit )
|
|
|
|
commit = &localCommit;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( !item->IsMoving() )
|
2023-06-09 21:41:33 +00:00
|
|
|
commit->Modify( m_frame->GetCurSymbol(), m_frame->GetScreen() );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( selection.GetSize() == 1 )
|
|
|
|
rotPoint = item->GetPosition();
|
|
|
|
else
|
2021-12-01 16:53:14 +00:00
|
|
|
rotPoint = m_frame->GetNearestHalfGridPosition( mapCoords( selection.GetCenter() ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
|
|
|
|
{
|
|
|
|
item = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
|
|
|
|
item->Rotate( rotPoint, ccw );
|
2021-10-06 03:10:20 +00:00
|
|
|
m_frame->UpdateItem( item, false, true );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 13:09:19 +00:00
|
|
|
if( item->IsMoving() )
|
2020-11-22 22:21:41 +00:00
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
2020-11-22 22:21:41 +00:00
|
|
|
}
|
2019-08-08 13:09:19 +00:00
|
|
|
else
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-08-08 13:09:19 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
if( selection.IsHover() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
if( !localCommit.Empty() )
|
|
|
|
localCommit.Push( _( "Rotate" ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( selection.GetSize() == 0 )
|
|
|
|
return 0;
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I mirrorPoint;
|
2021-02-16 20:45:25 +00:00
|
|
|
bool xAxis = ( aEvent.Matches( EE_ACTIONS::mirrorV.MakeEvent() ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
LIB_ITEM* item = static_cast<LIB_ITEM*>( selection.Front() );
|
|
|
|
|
|
|
|
if( !item->IsMoving() )
|
2021-06-15 12:31:28 +00:00
|
|
|
saveCopyInUndoList( m_frame->GetCurSymbol(), UNDO_REDO::LIBEDIT );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( selection.GetSize() == 1 )
|
2023-11-20 22:55:51 +00:00
|
|
|
{
|
2019-05-08 18:56:03 +00:00
|
|
|
mirrorPoint = item->GetPosition();
|
2023-11-20 22:55:51 +00:00
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case LIB_FIELD_T:
|
|
|
|
{
|
|
|
|
LIB_FIELD* field = static_cast<LIB_FIELD*>( item );
|
|
|
|
|
|
|
|
if( xAxis )
|
|
|
|
field->SetVertJustify( TO_VJUSTIFY( -field->GetVertJustify() ) );
|
|
|
|
else
|
|
|
|
field->SetHorizJustify( TO_HJUSTIFY( -field->GetHorizJustify() ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
if( xAxis )
|
|
|
|
item->MirrorVertical( mirrorPoint );
|
|
|
|
else
|
|
|
|
item->MirrorHorizontal( mirrorPoint );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_frame->UpdateItem( item, false, true );
|
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
else
|
2023-11-20 22:55:51 +00:00
|
|
|
{
|
2021-02-15 19:58:12 +00:00
|
|
|
mirrorPoint = m_frame->GetNearestHalfGridPosition( mapCoords( selection.GetCenter() ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2023-11-20 22:55:51 +00:00
|
|
|
for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
|
|
|
|
{
|
|
|
|
item = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2023-11-20 22:55:51 +00:00
|
|
|
if( xAxis )
|
|
|
|
item->MirrorVertical( mirrorPoint );
|
|
|
|
else
|
|
|
|
item->MirrorHorizontal( mirrorPoint );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2023-11-20 22:55:51 +00:00
|
|
|
m_frame->UpdateItem( item, false, true );
|
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 13:09:19 +00:00
|
|
|
if( item->IsMoving() )
|
2020-11-22 22:21:41 +00:00
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
2020-11-22 22:21:41 +00:00
|
|
|
}
|
2019-08-08 13:09:19 +00:00
|
|
|
else
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
if( selection.IsHover() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-21 19:54:07 +00:00
|
|
|
static std::vector<KICAD_T> nonFields =
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
LIB_SYMBOL_T,
|
|
|
|
LIB_SHAPE_T,
|
|
|
|
LIB_TEXT_T,
|
|
|
|
LIB_TEXTBOX_T,
|
|
|
|
LIB_PIN_T
|
2019-05-08 18:56:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2023-06-09 21:41:33 +00:00
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
2021-10-06 17:20:07 +00:00
|
|
|
std::deque<EDA_ITEM*> items = m_selectionTool->RequestSelection( nonFields ).GetItems();
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_frame );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( items.empty() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Don't leave a freed pointer in the selection
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
commit.Modify( symbol, m_frame->GetScreen() );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
std::set<LIB_ITEM*> toDelete;
|
2019-05-22 19:35:03 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
for( EDA_ITEM* item : items )
|
|
|
|
{
|
|
|
|
if( item->Type() == LIB_PIN_T )
|
|
|
|
{
|
2023-01-22 08:40:09 +00:00
|
|
|
LIB_PIN* curr_pin = static_cast<LIB_PIN*>( item );
|
|
|
|
VECTOR2I pos = curr_pin->GetPosition();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2023-01-22 08:40:09 +00:00
|
|
|
toDelete.insert( curr_pin );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-12-18 23:16:30 +00:00
|
|
|
// when pin editing is synchronized, pins in the same position, with the same name
|
|
|
|
// in different units are also removed. But only one pin per unit (matching)
|
2019-05-08 18:56:03 +00:00
|
|
|
if( m_frame->SynchronizePins() )
|
|
|
|
{
|
2021-10-30 12:52:13 +00:00
|
|
|
std::vector<bool> got_unit( symbol->GetUnitCount() + 1 );
|
2020-12-18 23:16:30 +00:00
|
|
|
|
2023-01-22 08:40:09 +00:00
|
|
|
got_unit[curr_pin->GetUnit()] = true;
|
2020-12-18 23:16:30 +00:00
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
int curr_bodyStyle = curr_pin->GetBodyStyle();
|
2023-01-22 08:40:09 +00:00
|
|
|
ELECTRICAL_PINTYPE etype = curr_pin->GetType();
|
|
|
|
wxString name = curr_pin->GetName();
|
2023-01-20 22:12:15 +00:00
|
|
|
std::vector<LIB_PIN*> pins = symbol->GetAllLibPins();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2023-01-20 22:12:15 +00:00
|
|
|
for( LIB_PIN* pin : pins )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-12-18 23:16:30 +00:00
|
|
|
if( got_unit[pin->GetUnit()] )
|
|
|
|
continue;
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
if( pin->GetPosition() != pos )
|
|
|
|
continue;
|
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
if( pin->GetBodyStyle() != curr_bodyStyle )
|
2019-05-08 18:56:03 +00:00
|
|
|
continue;
|
|
|
|
|
2020-12-18 23:16:30 +00:00
|
|
|
if( pin->GetType() != etype )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( pin->GetName() != name )
|
|
|
|
continue;
|
|
|
|
|
2019-05-22 19:35:03 +00:00
|
|
|
toDelete.insert( pin );
|
2020-12-18 23:16:30 +00:00
|
|
|
got_unit[pin->GetUnit()] = true;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-22 19:35:03 +00:00
|
|
|
toDelete.insert( (LIB_ITEM*) item );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
for( LIB_ITEM* item : toDelete )
|
2021-06-10 18:51:46 +00:00
|
|
|
symbol->RemoveDrawItem( item );
|
2019-05-22 19:35:03 +00:00
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
commit.Push( _( "Delete" ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
m_frame->RebuildView();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
#define HITTEST_THRESHOLD_PIXELS 5
|
|
|
|
|
|
|
|
|
2023-10-10 14:43:45 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::InteractiveDelete( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-07-15 23:44:01 +00:00
|
|
|
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-07-15 23:44:01 +00:00
|
|
|
m_pickerItem = nullptr;
|
2019-06-24 15:27:05 +00:00
|
|
|
|
2019-07-19 20:47:33 +00:00
|
|
|
// Deactivate other tools; particularly important if another PICKER is currently running
|
|
|
|
Activate();
|
|
|
|
|
2020-10-08 00:50:28 +00:00
|
|
|
picker->SetCursor( KICURSOR::REMOVE );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
picker->SetClickHandler(
|
2020-11-22 22:21:41 +00:00
|
|
|
[this]( const VECTOR2D& aPosition ) -> bool
|
2019-07-15 23:44:01 +00:00
|
|
|
{
|
2020-11-22 22:21:41 +00:00
|
|
|
if( m_pickerItem )
|
|
|
|
{
|
|
|
|
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
selectionTool->UnbrightenItem( m_pickerItem );
|
|
|
|
selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::doDelete );
|
2020-11-22 22:21:41 +00:00
|
|
|
m_pickerItem = nullptr;
|
|
|
|
}
|
2019-06-24 15:27:05 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
return true;
|
|
|
|
} );
|
2019-07-15 23:44:01 +00:00
|
|
|
|
|
|
|
picker->SetMotionHandler(
|
2020-11-22 22:21:41 +00:00
|
|
|
[this]( const VECTOR2D& aPos )
|
2019-08-01 04:31:19 +00:00
|
|
|
{
|
2020-11-22 22:21:41 +00:00
|
|
|
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
EE_COLLECTOR collector;
|
2019-08-01 04:31:19 +00:00
|
|
|
|
2021-01-19 21:10:04 +00:00
|
|
|
selectionTool->CollectHits( collector, aPos, nonFields );
|
2019-06-24 15:27:05 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
// Remove unselectable items
|
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
|
|
|
{
|
|
|
|
if( !selectionTool->Selectable( collector[ i ] ) )
|
|
|
|
collector.Remove( i );
|
|
|
|
}
|
2019-06-24 15:27:05 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( collector.GetCount() > 1 )
|
|
|
|
selectionTool->GuessSelectionCandidates( collector, aPos );
|
2019-06-28 19:11:26 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
|
2019-06-28 19:11:26 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( m_pickerItem != item )
|
|
|
|
{
|
|
|
|
if( m_pickerItem )
|
|
|
|
selectionTool->UnbrightenItem( m_pickerItem );
|
|
|
|
|
|
|
|
m_pickerItem = item;
|
|
|
|
|
|
|
|
if( m_pickerItem )
|
|
|
|
selectionTool->BrightenItem( m_pickerItem );
|
|
|
|
}
|
|
|
|
} );
|
2019-06-24 15:27:05 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
picker->SetFinalizeHandler(
|
2020-11-22 22:21:41 +00:00
|
|
|
[this]( const int& aFinalState )
|
|
|
|
{
|
|
|
|
if( m_pickerItem )
|
|
|
|
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
|
2020-10-11 17:12:13 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
// Wake the selection tool after exiting to ensure the cursor gets updated
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( EE_ACTIONS::selectionActivate );
|
2020-11-22 22:21:41 +00:00
|
|
|
} );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::pickerTool, &aEvent );
|
2019-07-15 12:15:58 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-05-11 14:38:05 +00:00
|
|
|
if( selection.Empty() || aEvent.IsAction( &EE_ACTIONS::symbolProperties ) )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
if( m_frame->GetCurSymbol() )
|
2019-05-11 14:38:05 +00:00
|
|
|
editSymbolProperties();
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
else if( selection.Size() == 1 )
|
|
|
|
{
|
|
|
|
LIB_ITEM* item = (LIB_ITEM*) selection.Front();
|
|
|
|
|
|
|
|
// Save copy for undo if not in edit (edit command already handle the save copy)
|
2019-07-02 20:09:23 +00:00
|
|
|
if( item->GetEditFlags() == 0 )
|
2020-08-26 18:04:32 +00:00
|
|
|
saveCopyInUndoList( item->GetParent(), UNDO_REDO::LIBEDIT );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case LIB_PIN_T:
|
2023-12-22 17:30:14 +00:00
|
|
|
if( SYMBOL_EDITOR_PIN_TOOL* pinTool = m_toolMgr->GetTool<SYMBOL_EDITOR_PIN_TOOL>() )
|
2019-05-08 18:56:03 +00:00
|
|
|
pinTool->EditPinProperties( (LIB_PIN*) item );
|
2023-12-22 17:30:14 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LIB_SHAPE_T:
|
2022-06-16 12:23:35 +00:00
|
|
|
editShapeProperties( static_cast<LIB_SHAPE*>( item ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LIB_TEXT_T:
|
|
|
|
editTextProperties( item );
|
|
|
|
break;
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
case LIB_TEXTBOX_T:
|
|
|
|
editTextBoxProperties( item );
|
|
|
|
break;
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
case LIB_FIELD_T:
|
|
|
|
editFieldProperties( (LIB_FIELD*) item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-23 17:12:09 +00:00
|
|
|
if( selection.IsHover() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
void SYMBOL_EDITOR_EDIT_TOOL::editShapeProperties( LIB_SHAPE* aShape )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2022-06-16 12:23:35 +00:00
|
|
|
DIALOG_LIB_SHAPE_PROPERTIES dlg( m_frame, aShape );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-03-13 00:07:58 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2019-05-08 18:56:03 +00:00
|
|
|
return;
|
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
updateItem( aShape, true );
|
2019-05-08 18:56:03 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
2021-03-13 00:07:58 +00:00
|
|
|
m_frame->OnModify();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
SYMBOL_EDITOR_DRAWING_TOOLS* drawingTools = m_toolMgr->GetTool<SYMBOL_EDITOR_DRAWING_TOOLS>();
|
2024-01-26 16:16:13 +00:00
|
|
|
drawingTools->SetDrawSpecificBodyStyle( !dlg.GetApplyToAllConversions() );
|
2021-03-13 00:07:58 +00:00
|
|
|
drawingTools->SetDrawSpecificUnit( !dlg.GetApplyToAllUnits() );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
std::vector<MSG_PANEL_ITEM> items;
|
2022-06-16 12:23:35 +00:00
|
|
|
aShape->GetMsgPanelInfo( m_frame, items );
|
2019-05-08 18:56:03 +00:00
|
|
|
m_frame->SetMsgPanel( items );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
void SYMBOL_EDITOR_EDIT_TOOL::editTextProperties( LIB_ITEM* aItem )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-08-06 19:54:26 +00:00
|
|
|
if ( aItem->Type() != LIB_TEXT_T )
|
2019-05-08 18:56:03 +00:00
|
|
|
return;
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
DIALOG_LIB_TEXT_PROPERTIES dlg( m_frame, static_cast<LIB_TEXT*>( aItem ) );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
|
|
|
updateItem( aItem, true );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
m_frame->OnModify( );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SYMBOL_EDITOR_EDIT_TOOL::editTextBoxProperties( LIB_ITEM* aItem )
|
|
|
|
{
|
|
|
|
if ( aItem->Type() != LIB_TEXTBOX_T )
|
|
|
|
return;
|
|
|
|
|
|
|
|
DIALOG_LIB_TEXTBOX_PROPERTIES dlg( m_frame, static_cast<LIB_TEXTBOX*>( aItem ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
2020-10-30 15:15:20 +00:00
|
|
|
updateItem( aItem, true );
|
2019-05-08 18:56:03 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
m_frame->OnModify( );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
void SYMBOL_EDITOR_EDIT_TOOL::editFieldProperties( LIB_FIELD* aField )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
if( aField == nullptr )
|
2019-05-08 18:56:03 +00:00
|
|
|
return;
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
wxString caption;
|
|
|
|
LIB_SYMBOL* parent = aField->GetParent();
|
2019-05-08 18:56:03 +00:00
|
|
|
wxCHECK( parent, /* void */ );
|
|
|
|
|
2023-05-29 11:40:00 +00:00
|
|
|
if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
|
2021-03-20 00:01:37 +00:00
|
|
|
caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) );
|
2021-07-19 13:43:34 +00:00
|
|
|
else
|
|
|
|
caption.Printf( _( "Edit '%s' Field" ), aField->GetName() );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
DIALOG_LIB_FIELD_PROPERTIES dlg( m_frame, caption, aField );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
// The dialog may invoke a kiway player for footprint fields
|
|
|
|
// so we must use a quasimodal dialog.
|
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
2021-06-30 10:53:04 +00:00
|
|
|
wxString newFieldValue = EscapeString( dlg.GetText(), CTX_LIBID );
|
2019-05-08 18:56:03 +00:00
|
|
|
wxString oldFieldValue = aField->GetFullText( m_frame->GetUnit() );
|
|
|
|
|
2023-12-22 17:30:14 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
commit.Modify( aField, m_frame->GetScreen() );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
dlg.UpdateField( aField );
|
|
|
|
|
2023-12-22 17:30:14 +00:00
|
|
|
commit.Push( caption );
|
|
|
|
|
2022-08-20 21:43:20 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
m_frame->UpdateSymbolMsgPanelInfo();
|
2019-05-11 14:38:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
void SYMBOL_EDITOR_EDIT_TOOL::editSymbolProperties()
|
2019-05-11 14:38:05 +00:00
|
|
|
{
|
2021-06-30 10:53:04 +00:00
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
|
|
|
bool partLocked = symbol->UnitsLocked();
|
2019-05-11 14:38:05 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cancelInteractive );
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-11 14:38:05 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
DIALOG_LIB_SYMBOL_PROPERTIES dlg( m_frame, symbol );
|
2019-05-11 14:38:05 +00:00
|
|
|
|
|
|
|
// This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
|
|
|
|
// frame. Therefore this dialog as a modal frame parent, MUST be run under
|
|
|
|
// quasimodal mode for the quasimodal frame support to work. So don't use
|
|
|
|
// the QUASIMODAL macros here.
|
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
m_frame->OnModify();
|
|
|
|
|
2019-05-11 14:38:05 +00:00
|
|
|
// if m_UnitSelectionLocked has changed, set some edit options or defaults
|
|
|
|
// to the best value
|
2021-06-10 18:51:46 +00:00
|
|
|
if( partLocked != symbol->UnitsLocked() )
|
2019-05-11 14:38:05 +00:00
|
|
|
{
|
2020-12-12 03:13:52 +00:00
|
|
|
SYMBOL_EDITOR_DRAWING_TOOLS* tools = m_toolMgr->GetTool<SYMBOL_EDITOR_DRAWING_TOOLS>();
|
2020-05-23 15:50:08 +00:00
|
|
|
|
2019-05-11 14:38:05 +00:00
|
|
|
// Enable synchronized pin edit mode for symbols with interchangeable units
|
2021-06-10 18:51:46 +00:00
|
|
|
m_frame->m_SyncPinEdit = !symbol->UnitsLocked();
|
2020-05-23 15:50:08 +00:00
|
|
|
|
2019-05-11 14:38:05 +00:00
|
|
|
// also set default edit options to the better value
|
|
|
|
// Usually if units are locked, graphic items are specific to each unit
|
|
|
|
// and if units are interchangeable, graphic items are common to units
|
2021-06-10 18:51:46 +00:00
|
|
|
tools->SetDrawSpecificUnit( symbol->UnitsLocked() );
|
2019-05-11 14:38:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-14 22:33:43 +00:00
|
|
|
void SYMBOL_EDITOR_EDIT_TOOL::handlePinDuplication( LIB_PIN* aOldPin, LIB_PIN* aNewPin,
|
|
|
|
int& aSymbolLastPinNumber )
|
|
|
|
{
|
|
|
|
if( !aNewPin->GetNumber().IsEmpty() )
|
|
|
|
{
|
|
|
|
// when duplicating a pin in symbol editor, assigning identical pin number
|
|
|
|
// to the old one does not makes any sense, so assign the next unassigned number to it
|
|
|
|
aSymbolLastPinNumber++;
|
|
|
|
aNewPin->SetNumber( wxString::Format( wxT( "%i" ), aSymbolLastPinNumber ) );
|
|
|
|
}
|
|
|
|
}
|
2019-05-11 14:38:05 +00:00
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::PinTable( const TOOL_EVENT& aEvent )
|
2019-05-11 14:38:05 +00:00
|
|
|
{
|
2023-12-22 17:30:14 +00:00
|
|
|
SCH_COMMIT commit( m_frame );
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
2019-05-11 14:38:05 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !symbol )
|
2019-05-16 22:50:29 +00:00
|
|
|
return 0;
|
|
|
|
|
2023-12-22 17:30:14 +00:00
|
|
|
commit.Modify( symbol );
|
2019-05-11 14:38:05 +00:00
|
|
|
|
2023-12-22 17:30:14 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-11 14:38:05 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
DIALOG_LIB_EDIT_PIN_TABLE dlg( m_frame, symbol );
|
2019-05-11 14:38:05 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return -1;
|
|
|
|
|
2023-12-22 17:30:14 +00:00
|
|
|
// TODO: 9.0: this would be better as "Edit Pins", but we're past string freeze, so this
|
|
|
|
// (existing) string will have to do.
|
|
|
|
commit.Push( _( "Edit Pin Properties" ) );
|
2019-05-11 14:38:05 +00:00
|
|
|
m_frame->RebuildView();
|
|
|
|
|
|
|
|
return 0;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-13 21:28:06 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::UpdateSymbolFields( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
2021-02-13 21:28:06 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !symbol )
|
2021-02-13 21:28:06 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !symbol->IsAlias() )
|
2021-02-13 21:28:06 +00:00
|
|
|
{
|
|
|
|
m_frame->ShowInfoBarError( _( "Symbol is not derived from another symbol." ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
DIALOG_UPDATE_SYMBOL_FIELDS dlg( m_frame, symbol );
|
2021-02-13 21:28:06 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-14 22:11:37 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::SetUnitDisplayName( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
|
|
|
|
|
|
|
if( !symbol )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int unitid = m_frame->GetUnit();
|
|
|
|
|
|
|
|
if( unitid == 0 )
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString promptText = wxString::Format( _( "Enter display name for unit %s" ),
|
|
|
|
symbol->GetUnitReference( unitid ) );
|
|
|
|
wxString currentvalue;
|
|
|
|
|
|
|
|
if( symbol->HasUnitDisplayName( unitid ) )
|
|
|
|
{
|
|
|
|
currentvalue = symbol->GetUnitDisplayName( unitid );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxTextEntryDialog dlg( m_frame, promptText, _( "Set Unit Display Name" ), currentvalue );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
saveCopyInUndoList( symbol, UNDO_REDO::LIBEDIT );
|
|
|
|
symbol->SetUnitDisplayName( unitid, dlg.GetValue() );
|
|
|
|
m_frame->RebuildSymbolUnitsList();
|
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::Undo( const TOOL_EVENT& aEvent )
|
2019-05-14 19:21:10 +00:00
|
|
|
{
|
2019-06-29 18:57:23 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
2023-12-22 17:30:14 +00:00
|
|
|
|
|
|
|
// Nuke the selection for later rebuilding. This does *not* clear the flags on any items;
|
|
|
|
// it just clears the SELECTION's reference to them.
|
|
|
|
selTool->GetSelection().Clear();
|
|
|
|
{
|
|
|
|
m_frame->GetSymbolFromUndoList();
|
|
|
|
}
|
2019-06-29 18:57:23 +00:00
|
|
|
selTool->RebuildSelection();
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::Redo( const TOOL_EVENT& aEvent )
|
2019-05-14 19:21:10 +00:00
|
|
|
{
|
2019-06-29 18:57:23 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
2023-12-22 17:30:14 +00:00
|
|
|
|
|
|
|
// Nuke the selection for later rebuilding. This does *not* clear the flags on any items;
|
|
|
|
// it just clears the SELECTION's reference to them.
|
|
|
|
selTool->GetSelection().Clear();
|
|
|
|
{
|
|
|
|
m_frame->GetSymbolFromRedoList();
|
|
|
|
}
|
2019-06-29 18:57:23 +00:00
|
|
|
selTool->RebuildSelection();
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::Cut( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
int retVal = Copy( aEvent );
|
|
|
|
|
|
|
|
if( retVal == 0 )
|
|
|
|
retVal = DoDelete( aEvent );
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::Copy( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( nonFields );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !symbol || !selection.GetSize() )
|
2019-05-08 18:56:03 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
for( LIB_ITEM& item : symbol->GetDrawItems() )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
if( item.Type() == LIB_FIELD_T )
|
|
|
|
continue;
|
|
|
|
|
2019-08-27 12:12:34 +00:00
|
|
|
wxASSERT( !item.HasFlag( STRUCT_DELETED ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( !item.IsSelected() )
|
|
|
|
item.SetFlags( STRUCT_DELETED );
|
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* partCopy = new LIB_SYMBOL( *symbol );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
STRING_FORMATTER formatter;
|
2023-12-24 00:31:24 +00:00
|
|
|
SCH_IO_KICAD_SEXPR::FormatLibSymbol( partCopy, formatter );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
delete partCopy;
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
for( LIB_ITEM& item : symbol->GetDrawItems() )
|
2019-05-08 18:56:03 +00:00
|
|
|
item.ClearFlags( STRUCT_DELETED );
|
|
|
|
|
|
|
|
if( m_toolMgr->SaveClipboard( formatter.GetString() ) )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2023-06-12 22:13:23 +00:00
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
|
|
|
LIB_SYMBOL* newPart = nullptr;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !symbol || symbol->IsAlias() )
|
2019-05-08 18:56:03 +00:00
|
|
|
return 0;
|
|
|
|
|
2023-06-12 22:13:23 +00:00
|
|
|
std::string clipboardData = m_toolMgr->GetClipboardUTF8();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2023-12-24 00:31:24 +00:00
|
|
|
std::vector<LIB_SYMBOL*> newParts = SCH_IO_KICAD_SEXPR::ParseLibSymbols( clipboardData, "Clipboard" );
|
2023-06-12 22:13:23 +00:00
|
|
|
|
|
|
|
if( newParts.empty() || !newParts[0] )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
newPart = newParts[0];
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2020-02-29 21:53:51 +00:00
|
|
|
catch( IO_ERROR& )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
// If it's not a symbol then paste as text
|
|
|
|
newPart = new LIB_SYMBOL( "dummy_part" );
|
2020-04-18 20:04:41 +00:00
|
|
|
LIB_TEXT* newText = new LIB_TEXT( newPart );
|
2023-06-12 22:13:23 +00:00
|
|
|
newText->SetText( clipboardData );
|
2019-08-15 07:19:15 +00:00
|
|
|
newPart->AddDrawItem( newText );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2023-06-09 16:24:49 +00:00
|
|
|
|
|
|
|
commit.Modify( symbol );
|
2019-05-27 09:07:13 +00:00
|
|
|
m_selectionTool->ClearSelection();
|
2019-05-16 22:50:29 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
for( LIB_ITEM& item : symbol->GetDrawItems() )
|
2020-03-21 20:54:35 +00:00
|
|
|
item.ClearFlags( IS_NEW | IS_PASTED | SELECTED );
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
for( LIB_ITEM& item : newPart->GetDrawItems() )
|
|
|
|
{
|
|
|
|
if( item.Type() == LIB_FIELD_T )
|
|
|
|
continue;
|
|
|
|
|
2023-09-03 18:05:33 +00:00
|
|
|
LIB_ITEM* newItem = (LIB_ITEM*) item.Duplicate();
|
2021-06-10 18:51:46 +00:00
|
|
|
newItem->SetParent( symbol );
|
2019-05-27 09:07:13 +00:00
|
|
|
newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-11-12 14:11:08 +00:00
|
|
|
newItem->SetUnit( newItem->GetUnit() ? m_frame->GetUnit() : 0 );
|
2024-01-26 16:16:13 +00:00
|
|
|
newItem->SetBodyStyle( newItem->GetBodyStyle() ? m_frame->GetBodyStyle() : 0 );
|
2019-06-29 21:20:21 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
symbol->AddDrawItem( newItem );
|
2019-05-08 18:56:03 +00:00
|
|
|
getView()->Add( newItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
delete newPart;
|
|
|
|
|
2019-05-27 09:07:13 +00:00
|
|
|
m_selectionTool->RebuildSelection();
|
|
|
|
|
2020-03-21 20:54:35 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->GetSelection();
|
|
|
|
|
2019-05-27 09:07:13 +00:00
|
|
|
if( !selection.Empty() )
|
|
|
|
{
|
2019-05-27 12:18:55 +00:00
|
|
|
selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) );
|
2023-06-30 17:57:01 +00:00
|
|
|
|
|
|
|
if( m_toolMgr->RunSynchronousAction( EE_ACTIONS::move, &commit ) )
|
|
|
|
commit.Push( _( "Paste" ) );
|
|
|
|
else
|
|
|
|
commit.Revert();
|
2019-05-27 10:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
|
2019-05-27 10:40:52 +00:00
|
|
|
{
|
2023-06-09 21:41:33 +00:00
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( nonFields );
|
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2019-05-27 10:40:52 +00:00
|
|
|
|
|
|
|
if( selection.GetSize() == 0 )
|
|
|
|
return 0;
|
|
|
|
|
2023-09-03 18:05:33 +00:00
|
|
|
commit.Modify( symbol, m_frame->GetScreen() );
|
2019-05-27 10:40:52 +00:00
|
|
|
|
2019-09-07 19:51:30 +00:00
|
|
|
EDA_ITEMS newItems;
|
|
|
|
|
2019-05-27 10:40:52 +00:00
|
|
|
for( unsigned ii = 0; ii < selection.GetSize(); ++ii )
|
|
|
|
{
|
|
|
|
LIB_ITEM* oldItem = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
|
2023-09-03 18:05:33 +00:00
|
|
|
LIB_ITEM* newItem = static_cast<LIB_ITEM*>( oldItem->Duplicate() );
|
2022-05-14 22:33:43 +00:00
|
|
|
|
2023-09-03 18:05:33 +00:00
|
|
|
if( newItem->Type() == LIB_PIN_T )
|
2022-05-14 22:33:43 +00:00
|
|
|
{
|
2023-09-03 18:05:33 +00:00
|
|
|
LIB_PIN* newPin = static_cast<LIB_PIN*>( newItem );
|
2022-05-14 22:33:43 +00:00
|
|
|
|
2023-09-03 18:05:33 +00:00
|
|
|
if( !newPin->GetNumber().IsEmpty() )
|
|
|
|
newPin->SetNumber( wxString::Format( wxT( "%i" ), symbol->GetMaxPinNumber() + 1 ) );
|
2022-05-14 22:33:43 +00:00
|
|
|
}
|
|
|
|
|
2020-03-21 20:54:35 +00:00
|
|
|
oldItem->ClearFlags( IS_NEW | IS_PASTED | SELECTED );
|
2019-05-27 10:40:52 +00:00
|
|
|
newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
|
2021-06-10 18:51:46 +00:00
|
|
|
newItem->SetParent( symbol );
|
2019-09-07 19:51:30 +00:00
|
|
|
newItems.push_back( newItem );
|
2019-05-27 10:40:52 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
symbol->AddDrawItem( newItem );
|
2019-05-27 10:40:52 +00:00
|
|
|
getView()->Add( newItem );
|
|
|
|
}
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
|
|
|
m_toolMgr->RunAction<EDA_ITEMS*>( EE_ACTIONS::addItemsToSel, &newItems );
|
2019-05-27 10:40:52 +00:00
|
|
|
|
2019-09-07 19:51:30 +00:00
|
|
|
selection.SetReferencePoint( mapCoords( getViewControls()->GetCursorPosition( true ) ) );
|
2023-06-30 17:57:01 +00:00
|
|
|
|
|
|
|
if( m_toolMgr->RunSynchronousAction( EE_ACTIONS::move, &commit ) )
|
|
|
|
commit.Push( _( "Duplicate" ) );
|
|
|
|
else
|
|
|
|
commit.Revert();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
void SYMBOL_EDITOR_EDIT_TOOL::setTransitions()
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-12-12 03:13:52 +00:00
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::Undo, ACTIONS::undo.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::Redo, ACTIONS::redo.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::Cut, ACTIONS::cut.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::Copy, ACTIONS::copy.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::Paste, ACTIONS::paste.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::Duplicate, ACTIONS::duplicate.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::Rotate, EE_ACTIONS::rotateCW.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::Rotate, EE_ACTIONS::rotateCCW.MakeEvent() );
|
2021-02-16 20:45:25 +00:00
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::Mirror, EE_ACTIONS::mirrorV.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::Mirror, EE_ACTIONS::mirrorH.MakeEvent() );
|
2020-12-12 03:13:52 +00:00
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::DoDelete, ACTIONS::doDelete.MakeEvent() );
|
2023-10-10 14:43:45 +00:00
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::InteractiveDelete, ACTIONS::deleteTool.MakeEvent() );
|
2020-12-12 03:13:52 +00:00
|
|
|
|
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::Properties, EE_ACTIONS::properties.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::Properties, EE_ACTIONS::symbolProperties.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::PinTable, EE_ACTIONS::pinTable.MakeEvent() );
|
2021-02-13 21:28:06 +00:00
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::UpdateSymbolFields, EE_ACTIONS::updateSymbolFields.MakeEvent() );
|
2022-09-14 22:11:37 +00:00
|
|
|
Go( &SYMBOL_EDITOR_EDIT_TOOL::SetUnitDisplayName, EE_ACTIONS::setUnitDisplayName.MakeEvent() );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|