2019-04-21 23:45:34 +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
|
2024-01-06 12:56:16 +00:00
|
|
|
* Copyright (C) 2019-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-04-21 23:45:34 +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
|
|
|
|
*/
|
|
|
|
|
2020-09-02 00:37:28 +00:00
|
|
|
#include <kiway.h>
|
2019-07-15 23:44:01 +00:00
|
|
|
#include <tool/picker_tool.h>
|
2019-04-23 13:06:37 +00:00
|
|
|
#include <tools/sch_edit_tool.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <tools/ee_selection_tool.h>
|
2024-03-12 00:48:58 +00:00
|
|
|
#include <tools/ee_inspection_tool.h>
|
2019-06-16 13:42:40 +00:00
|
|
|
#include <tools/sch_line_wire_bus_tool.h>
|
2019-05-04 13:02:05 +00:00
|
|
|
#include <tools/sch_move_tool.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <tools/sch_drawing_tools.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <ee_actions.h>
|
2019-04-23 17:40:29 +00:00
|
|
|
#include <confirm.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2024-03-12 00:48:58 +00:00
|
|
|
#include <sch_bitmap.h>
|
|
|
|
#include <sch_bus_entry.h>
|
|
|
|
#include <sch_commit.h>
|
|
|
|
#include <sch_edit_frame.h>
|
2019-05-10 19:57:24 +00:00
|
|
|
#include <sch_item.h>
|
2024-03-12 00:48:58 +00:00
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_marker.h>
|
2024-04-25 14:24:46 +00:00
|
|
|
#include <sch_rule_area.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <sch_shape.h>
|
2019-04-23 17:40:29 +00:00
|
|
|
#include <sch_sheet.h>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2019-04-23 17:40:29 +00:00
|
|
|
#include <sch_text.h>
|
2022-01-25 22:33:37 +00:00
|
|
|
#include <sch_textbox.h>
|
2023-11-25 12:38:24 +00:00
|
|
|
#include <sch_table.h>
|
|
|
|
#include <sch_tablecell.h>
|
2019-04-23 13:06:37 +00:00
|
|
|
#include <sch_view.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_proxy_view_item.h>
|
2019-04-27 23:50:35 +00:00
|
|
|
#include <eeschema_id.h>
|
2020-08-13 17:51:26 +00:00
|
|
|
#include <dialogs/dialog_change_symbols.h>
|
2022-07-07 14:17:21 +00:00
|
|
|
#include <dialogs/dialog_image_properties.h>
|
2022-03-16 13:43:19 +00:00
|
|
|
#include <dialogs/dialog_line_properties.h>
|
|
|
|
#include <dialogs/dialog_wire_bus_properties.h>
|
2020-10-17 23:25:39 +00:00
|
|
|
#include <dialogs/dialog_symbol_properties.h>
|
2020-10-29 22:46:33 +00:00
|
|
|
#include <dialogs/dialog_sheet_pin_properties.h>
|
2021-08-06 19:54:26 +00:00
|
|
|
#include <dialogs/dialog_field_properties.h>
|
2020-06-24 17:35:33 +00:00
|
|
|
#include <dialogs/dialog_junction_props.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <dialogs/dialog_shape_properties.h>
|
2021-10-12 20:05:37 +00:00
|
|
|
#include <dialogs/dialog_label_properties.h>
|
|
|
|
#include <dialogs/dialog_text_properties.h>
|
2023-11-25 12:38:24 +00:00
|
|
|
#include <dialogs/dialog_tablecell_properties.h>
|
2024-02-03 13:43:41 +00:00
|
|
|
#include <dialogs/dialog_table_properties.h>
|
2020-04-12 23:09:17 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_editor_settings.h>
|
2021-01-12 23:55:46 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2024-04-27 19:57:24 +00:00
|
|
|
#include <view/view_controls.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/textdlg.h>
|
2023-06-07 22:45:06 +00:00
|
|
|
#include <project/net_settings.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
|
2019-05-14 11:14:00 +00:00
|
|
|
class SYMBOL_UNIT_MENU : public ACTION_MENU
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-06-15 00:29:42 +00:00
|
|
|
SYMBOL_UNIT_MENU() :
|
|
|
|
ACTION_MENU( true )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
SetIcon( BITMAPS::component_select_unit );
|
2019-05-02 20:03:03 +00:00
|
|
|
SetTitle( _( "Symbol Unit" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2019-05-14 11:14:00 +00:00
|
|
|
ACTION_MENU* create() const override
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
|
|
|
return new SYMBOL_UNIT_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void update() override
|
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = getToolManager()->GetTool<EE_SELECTION_TOOL>();
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = selTool->GetSelection();
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( selection.Front() );
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2019-06-19 20:04:34 +00:00
|
|
|
Clear();
|
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
wxCHECK( symbol, /* void */ );
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2021-03-19 20:27:30 +00:00
|
|
|
int unit = symbol->GetUnit();
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
for( int ii = 0; ii < symbol->GetLibSymbolRef()->GetUnitCount(); ii++ )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
|
|
|
wxString num_unit;
|
2023-11-12 23:42:36 +00:00
|
|
|
num_unit.Printf( _( "Unit %s" ), symbol->SubReference( ii + 1, false ) );
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2023-08-28 11:29:47 +00:00
|
|
|
wxMenuItem* item = Append( ID_POPUP_SCH_SELECT_UNIT1 + ii, num_unit, wxEmptyString,
|
|
|
|
wxITEM_CHECK );
|
|
|
|
|
2019-05-02 20:03:03 +00:00
|
|
|
if( unit == ii + 1 )
|
2023-08-28 11:29:47 +00:00
|
|
|
item->Check( true );
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2023-08-28 11:29:47 +00:00
|
|
|
// The ID max for these submenus is ID_POPUP_SCH_SELECT_UNIT_END
|
2019-05-02 20:03:03 +00:00
|
|
|
// See eeschema_id to modify this value.
|
2023-08-28 11:29:47 +00:00
|
|
|
if( ii >= ( ID_POPUP_SCH_SELECT_UNIT_END - ID_POPUP_SCH_SELECT_UNIT1) )
|
|
|
|
break; // We have used all IDs for these submenus
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ALT_PIN_FUNCTION_MENU : public ACTION_MENU
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ALT_PIN_FUNCTION_MENU() :
|
|
|
|
ACTION_MENU( true )
|
|
|
|
{
|
|
|
|
SetIcon( BITMAPS::component_select_unit );
|
2023-08-29 17:04:33 +00:00
|
|
|
SetTitle( _( "Pin Function" ) );
|
2023-08-28 11:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ACTION_MENU* create() const override
|
|
|
|
{
|
|
|
|
return new ALT_PIN_FUNCTION_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void update() override
|
|
|
|
{
|
|
|
|
EE_SELECTION_TOOL* selTool = getToolManager()->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
EE_SELECTION& selection = selTool->GetSelection();
|
|
|
|
SCH_PIN* pin = dynamic_cast<SCH_PIN*>( selection.Front() );
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN* libPin = pin ? pin->GetLibPin() : nullptr;
|
2023-08-28 11:29:47 +00:00
|
|
|
|
|
|
|
Clear();
|
|
|
|
|
2024-03-02 12:15:50 +00:00
|
|
|
wxCHECK( libPin, /* void */ );
|
2023-08-28 11:29:47 +00:00
|
|
|
|
2024-03-02 12:15:50 +00:00
|
|
|
wxMenuItem* item = Append( ID_POPUP_SCH_ALT_PIN_FUNCTION, libPin->GetName(), wxEmptyString,
|
2023-08-28 11:29:47 +00:00
|
|
|
wxITEM_CHECK );
|
|
|
|
|
|
|
|
if( pin->GetAlt().IsEmpty() )
|
|
|
|
item->Check( true );
|
|
|
|
|
|
|
|
int ii = 1;
|
|
|
|
|
2024-03-02 12:15:50 +00:00
|
|
|
for( const auto& [ name, definition ] : libPin->GetAlternates() )
|
2023-08-28 11:29:47 +00:00
|
|
|
{
|
|
|
|
item = Append( ID_POPUP_SCH_ALT_PIN_FUNCTION + ii, name, wxEmptyString, wxITEM_CHECK );
|
|
|
|
|
|
|
|
if( name == pin->GetAlt() )
|
|
|
|
item->Check( true );
|
|
|
|
|
|
|
|
// The ID max for these submenus is ID_POPUP_SCH_ALT_PIN_FUNCTION_END
|
|
|
|
// See eeschema_id to modify this value.
|
|
|
|
if( ++ii >= ( ID_POPUP_SCH_ALT_PIN_FUNCTION_END - ID_POPUP_SCH_SELECT_UNIT ) )
|
2019-05-02 20:03:03 +00:00
|
|
|
break; // We have used all IDs for these submenus
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-09-28 14:27:27 +00:00
|
|
|
class PIN_TRICKS_MENU : public ACTION_MENU
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PIN_TRICKS_MENU() : ACTION_MENU( true )
|
|
|
|
{
|
|
|
|
SetIcon( BITMAPS::pin );
|
|
|
|
SetTitle( _( "Pin Helpers" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ACTION_MENU* create() const override { return new PIN_TRICKS_MENU(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void update() override
|
|
|
|
{
|
|
|
|
EE_SELECTION_TOOL* selTool = getToolManager()->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
EE_SELECTION& selection = selTool->GetSelection();
|
|
|
|
SCH_PIN* pin = dynamic_cast<SCH_PIN*>( selection.Front() );
|
2024-05-01 22:49:35 +00:00
|
|
|
SCH_SHEET_PIN* sheetPin = dynamic_cast<SCH_SHEET_PIN*>( selection.Front() );
|
2023-09-28 14:27:27 +00:00
|
|
|
|
|
|
|
Clear();
|
|
|
|
|
2024-05-01 22:49:35 +00:00
|
|
|
if( !pin && !sheetPin )
|
2023-09-28 14:27:27 +00:00
|
|
|
return;
|
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
Add( _( "Wire" ), ID_POPUP_SCH_PIN_TRICKS_WIRE, BITMAPS::add_line );
|
|
|
|
Add( _( "No Connect" ), ID_POPUP_SCH_PIN_TRICKS_NO_CONNECT, BITMAPS::noconn );
|
|
|
|
Add( _( "Net Label" ), ID_POPUP_SCH_PIN_TRICKS_NET_LABEL, BITMAPS::add_label );
|
|
|
|
Add( _( "Hierarchical Label" ), ID_POPUP_SCH_PIN_TRICKS_HIER_LABEL, BITMAPS::add_hierarchical_label );
|
|
|
|
Add( _( "Global Label" ), ID_POPUP_SCH_PIN_TRICKS_GLOBAL_LABEL, BITMAPS::add_glabel );
|
2023-09-28 14:27:27 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-04-23 13:06:37 +00:00
|
|
|
SCH_EDIT_TOOL::SCH_EDIT_TOOL() :
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveEdit" )
|
2019-04-23 13:06:37 +00:00
|
|
|
{
|
2020-01-11 00:11:31 +00:00
|
|
|
m_pickerItem = nullptr;
|
2019-04-26 18:37:47 +00:00
|
|
|
}
|
2019-04-23 13:06:37 +00:00
|
|
|
|
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
using E_C = EE_CONDITIONS;
|
|
|
|
|
2019-04-23 13:06:37 +00:00
|
|
|
bool SCH_EDIT_TOOL::Init()
|
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE::Init();
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
SCH_DRAWING_TOOLS* drawingTools = m_toolMgr->GetTool<SCH_DRAWING_TOOLS>();
|
2019-05-12 11:49:58 +00:00
|
|
|
SCH_MOVE_TOOL* moveTool = m_toolMgr->GetTool<SCH_MOVE_TOOL>();
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
wxASSERT_MSG( drawingTools, "eeshema.InteractiveDrawing tool is not available" );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-08-20 23:05:21 +00:00
|
|
|
auto hasElements =
|
2021-07-18 23:08:54 +00:00
|
|
|
[this]( const SELECTION& aSel )
|
2020-08-20 23:05:21 +00:00
|
|
|
{
|
|
|
|
return !m_frame->GetScreen()->Items().empty();
|
|
|
|
};
|
|
|
|
|
2021-08-30 15:45:25 +00:00
|
|
|
auto sheetHasUndefinedPins =
|
2021-07-18 23:08:54 +00:00
|
|
|
[]( const SELECTION& aSel )
|
2021-08-30 15:45:25 +00:00
|
|
|
{
|
2022-09-22 00:05:51 +00:00
|
|
|
if( aSel.Size() == 1 && aSel.Front()->Type() == SCH_SHEET_T )
|
|
|
|
return static_cast<SCH_SHEET*>( aSel.Front() )->HasUndefinedPins();
|
2021-08-30 15:45:25 +00:00
|
|
|
|
2022-09-22 00:05:51 +00:00
|
|
|
return false;
|
2021-08-30 15:45:25 +00:00
|
|
|
};
|
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_SHEET_T } );
|
2022-05-30 13:07:28 +00:00
|
|
|
|
2022-07-10 23:14:29 +00:00
|
|
|
auto haveHighlight =
|
|
|
|
[&]( const SELECTION& sel )
|
|
|
|
{
|
|
|
|
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
|
|
|
|
|
2023-05-17 00:06:21 +00:00
|
|
|
return editFrame && !editFrame->GetHighlightedConnection().IsEmpty();
|
2022-07-10 23:14:29 +00:00
|
|
|
};
|
|
|
|
|
2020-04-20 23:24:29 +00:00
|
|
|
auto anyTextTool =
|
2021-07-18 23:08:54 +00:00
|
|
|
[this]( const SELECTION& aSel )
|
2020-04-20 23:24:29 +00:00
|
|
|
{
|
|
|
|
return ( m_frame->IsCurrentTool( EE_ACTIONS::placeLabel )
|
2021-10-12 20:05:37 +00:00
|
|
|
|| m_frame->IsCurrentTool( EE_ACTIONS::placeClassLabel )
|
2020-04-20 23:24:29 +00:00
|
|
|
|| m_frame->IsCurrentTool( EE_ACTIONS::placeGlobalLabel )
|
|
|
|
|| m_frame->IsCurrentTool( EE_ACTIONS::placeHierLabel )
|
|
|
|
|| m_frame->IsCurrentTool( EE_ACTIONS::placeSchematicText ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
auto duplicateCondition =
|
2021-07-18 23:08:54 +00:00
|
|
|
[]( const SELECTION& aSel )
|
2020-04-20 23:24:29 +00:00
|
|
|
{
|
|
|
|
if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
|
|
|
|
return false;
|
2019-05-03 22:48:24 +00:00
|
|
|
|
2020-04-20 23:24:29 +00:00
|
|
|
return true;
|
|
|
|
};
|
2019-05-02 10:59:36 +00:00
|
|
|
|
2020-04-20 23:24:29 +00:00
|
|
|
auto orientCondition =
|
2021-07-18 23:08:54 +00:00
|
|
|
[]( const SELECTION& aSel )
|
2020-04-20 23:24:29 +00:00
|
|
|
{
|
|
|
|
if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
|
|
|
|
return false;
|
2019-04-29 17:50:46 +00:00
|
|
|
|
2022-12-27 18:22:58 +00:00
|
|
|
return SELECTION_CONDITIONS::HasTypes( SCH_EDIT_TOOL::RotatableItems )( aSel );
|
2020-04-20 23:24:29 +00:00
|
|
|
};
|
2019-04-29 17:50:46 +00:00
|
|
|
|
2020-04-20 23:24:29 +00:00
|
|
|
auto propertiesCondition =
|
2021-04-11 13:18:08 +00:00
|
|
|
[&]( const SELECTION& aSel )
|
2020-04-20 23:24:29 +00:00
|
|
|
{
|
|
|
|
if( aSel.GetSize() == 0 )
|
2021-04-11 13:18:08 +00:00
|
|
|
{
|
|
|
|
if( getView()->IsLayerVisible( LAYER_SCHEMATIC_DRAWINGSHEET ) )
|
|
|
|
{
|
|
|
|
DS_PROXY_VIEW_ITEM* ds = m_frame->GetCanvas()->GetView()->GetDrawingSheet();
|
|
|
|
VECTOR2D cursor = getViewControls()->GetCursorPosition( false );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
if( ds && ds->HitTestDrawingSheetItems( getView(), cursor ) )
|
2021-04-11 13:18:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-29 17:50:46 +00:00
|
|
|
|
2020-11-25 00:08:09 +00:00
|
|
|
SCH_ITEM* firstItem = dynamic_cast<SCH_ITEM*>( aSel.Front() );
|
2020-06-19 11:48:00 +00:00
|
|
|
const EE_SELECTION* eeSelection = dynamic_cast<const EE_SELECTION*>( &aSel );
|
|
|
|
|
2020-11-25 00:08:09 +00:00
|
|
|
if( !firstItem || !eeSelection )
|
|
|
|
return false;
|
2020-06-24 17:35:33 +00:00
|
|
|
|
2020-05-12 18:48:36 +00:00
|
|
|
switch( firstItem->Type() )
|
2020-04-20 23:24:29 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
case SCH_SYMBOL_T:
|
2020-04-20 23:24:29 +00:00
|
|
|
case SCH_SHEET_T:
|
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
case SCH_TEXT_T:
|
2022-01-25 22:33:37 +00:00
|
|
|
case SCH_TEXTBOX_T:
|
2023-11-25 12:38:24 +00:00
|
|
|
case SCH_TABLE_T:
|
|
|
|
case SCH_TABLECELL_T:
|
2020-04-20 23:24:29 +00:00
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
2022-01-24 13:40:39 +00:00
|
|
|
case SCH_DIRECTIVE_LABEL_T:
|
2024-04-25 14:24:46 +00:00
|
|
|
case SCH_RULE_AREA_T:
|
2020-04-20 23:24:29 +00:00
|
|
|
case SCH_FIELD_T:
|
2021-12-31 23:43:13 +00:00
|
|
|
case SCH_SHAPE_T:
|
2020-04-20 23:24:29 +00:00
|
|
|
case SCH_BITMAP_T:
|
|
|
|
return aSel.GetSize() == 1;
|
|
|
|
|
|
|
|
case SCH_LINE_T:
|
2020-06-19 11:48:00 +00:00
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
2020-06-24 17:35:33 +00:00
|
|
|
case SCH_JUNCTION_T:
|
2022-03-16 13:43:19 +00:00
|
|
|
if( std::all_of( aSel.Items().begin(), aSel.Items().end(),
|
|
|
|
[&]( const EDA_ITEM* item )
|
|
|
|
{
|
|
|
|
return item->Type() == SCH_LINE_T
|
|
|
|
&& static_cast<const SCH_LINE*>( item )->IsGraphicLine();
|
|
|
|
} ) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( std::all_of( aSel.Items().begin(), aSel.Items().end(),
|
|
|
|
[&]( const EDA_ITEM* item )
|
|
|
|
{
|
|
|
|
return item->Type() == SCH_JUNCTION_T;
|
|
|
|
} ) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( std::all_of( aSel.Items().begin(), aSel.Items().end(),
|
|
|
|
[&]( const EDA_ITEM* item )
|
|
|
|
{
|
|
|
|
const SCH_ITEM* schItem = dynamic_cast<const SCH_ITEM*>( item );
|
|
|
|
|
2022-03-25 19:51:05 +00:00
|
|
|
wxCHECK( schItem, false );
|
|
|
|
|
2022-03-16 13:43:19 +00:00
|
|
|
return ( schItem->HasLineStroke() && schItem->IsConnectable() )
|
|
|
|
|| item->Type() == SCH_JUNCTION_T;
|
|
|
|
} ) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-06-24 17:35:33 +00:00
|
|
|
|
2020-04-20 23:24:29 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2019-04-29 20:38:05 +00:00
|
|
|
|
2021-07-29 19:23:11 +00:00
|
|
|
auto autoplaceCondition =
|
2021-07-18 23:08:54 +00:00
|
|
|
[]( const SELECTION& aSel )
|
2021-07-29 19:23:11 +00:00
|
|
|
{
|
|
|
|
for( const EDA_ITEM* item : aSel )
|
|
|
|
{
|
|
|
|
if( item->IsType( EE_COLLECTOR::FieldOwners ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2023-01-09 14:30:36 +00:00
|
|
|
// allTextTypes does not include SCH_SHEET_PIN_T because one cannot convert other
|
|
|
|
// types to/from this type, living only in a SHEET
|
|
|
|
static std::vector<KICAD_T> allTextTypes = { SCH_LABEL_T,
|
|
|
|
SCH_DIRECTIVE_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_TEXTBOX_T };
|
2021-11-20 22:36:11 +00:00
|
|
|
|
2022-07-21 11:40:58 +00:00
|
|
|
auto toChangeCondition = ( E_C::OnlyTypes( allTextTypes ) );
|
2022-06-09 14:46:21 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
auto toLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_DIRECTIVE_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_TEXTBOX_T } ) )
|
2022-07-21 11:40:58 +00:00
|
|
|
|| ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) );
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
auto toCLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_TEXTBOX_T } ) )
|
2022-07-21 11:40:58 +00:00
|
|
|
|| ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) );
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
auto toHLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_LABEL_T,
|
|
|
|
SCH_DIRECTIVE_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_TEXTBOX_T } ) )
|
2022-07-21 11:40:58 +00:00
|
|
|
|| ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) );
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
auto toGLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_LABEL_T,
|
|
|
|
SCH_DIRECTIVE_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_TEXTBOX_T } ) )
|
2022-07-21 11:40:58 +00:00
|
|
|
|| ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
auto toTextCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_LABEL_T,
|
|
|
|
SCH_DIRECTIVE_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_TEXTBOX_T } ) )
|
2022-07-21 11:40:58 +00:00
|
|
|
|| ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) );
|
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
auto toTextBoxCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_LABEL_T,
|
|
|
|
SCH_DIRECTIVE_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_TEXT_T } ) )
|
2022-07-21 11:40:58 +00:00
|
|
|
|| ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) );
|
2019-05-01 21:50:11 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
auto entryCondition = E_C::MoreThan( 0 ) && E_C::OnlyTypes( { SCH_BUS_WIRE_ENTRY_T,
|
|
|
|
SCH_BUS_BUS_ENTRY_T} );
|
2019-05-01 21:50:11 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
auto singleSheetCondition = E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_SHEET_T } );
|
2021-02-19 14:51:18 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
auto makeSymbolUnitMenu =
|
|
|
|
[&]( TOOL_INTERACTIVE* tool )
|
|
|
|
{
|
|
|
|
std::shared_ptr<SYMBOL_UNIT_MENU> menu = std::make_shared<SYMBOL_UNIT_MENU>();
|
|
|
|
menu->SetTool( tool );
|
|
|
|
tool->GetToolMenu().RegisterSubMenu( menu );
|
|
|
|
return menu.get();
|
|
|
|
};
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
auto makePinFunctionMenu =
|
|
|
|
[&]( TOOL_INTERACTIVE* tool )
|
|
|
|
{
|
|
|
|
std::shared_ptr<ALT_PIN_FUNCTION_MENU> menu = std::make_shared<ALT_PIN_FUNCTION_MENU>();
|
|
|
|
menu->SetTool( tool );
|
|
|
|
tool->GetToolMenu().RegisterSubMenu( menu );
|
|
|
|
return menu.get();
|
|
|
|
};
|
|
|
|
|
|
|
|
auto makePinTricksMenu =
|
|
|
|
[&]( TOOL_INTERACTIVE* tool )
|
|
|
|
{
|
|
|
|
std::shared_ptr<PIN_TRICKS_MENU> menu = std::make_shared<PIN_TRICKS_MENU>();
|
|
|
|
menu->SetTool( tool );
|
|
|
|
tool->GetToolMenu().RegisterSubMenu( menu );
|
|
|
|
return menu.get();
|
|
|
|
};
|
2023-05-04 18:50:39 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
auto makeTransformMenu =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
CONDITIONAL_MENU* menu = new CONDITIONAL_MENU( moveTool );
|
|
|
|
menu->SetTitle( _( "Transform Selection" ) );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
menu->AddItem( EE_ACTIONS::rotateCCW, orientCondition );
|
|
|
|
menu->AddItem( EE_ACTIONS::rotateCW, orientCondition );
|
|
|
|
menu->AddItem( EE_ACTIONS::mirrorV, orientCondition );
|
|
|
|
menu->AddItem( EE_ACTIONS::mirrorH, orientCondition );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
return menu;
|
|
|
|
};
|
2023-05-04 18:50:39 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
auto makeAttributesMenu =
|
|
|
|
[&]()
|
2023-05-04 18:50:39 +00:00
|
|
|
{
|
2023-12-28 13:54:49 +00:00
|
|
|
CONDITIONAL_MENU* menu = new CONDITIONAL_MENU( moveTool );
|
|
|
|
menu->SetTitle( _( "Attributes" ) );
|
2019-05-10 17:19:48 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
menu->AddItem( EE_ACTIONS::setExcludeFromSimulation, E_C::ShowAlways );
|
|
|
|
menu->AddItem( EE_ACTIONS::unsetExcludeFromSimulation, E_C::ShowAlways );
|
|
|
|
menu->AddItem( EE_ACTIONS::toggleExcludeFromSimulation, E_C::ShowAlways );
|
2022-06-13 09:35:17 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
menu->AddSeparator();
|
|
|
|
menu->AddItem( EE_ACTIONS::setExcludeFromBOM, E_C::ShowAlways );
|
|
|
|
menu->AddItem( EE_ACTIONS::unsetExcludeFromBOM, E_C::ShowAlways );
|
|
|
|
menu->AddItem( EE_ACTIONS::toggleExcludeFromBOM, E_C::ShowAlways );
|
2022-06-13 09:35:17 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
menu->AddSeparator();
|
|
|
|
menu->AddItem( EE_ACTIONS::setExcludeFromBoard, E_C::ShowAlways );
|
|
|
|
menu->AddItem( EE_ACTIONS::unsetExcludeFromBoard, E_C::ShowAlways );
|
|
|
|
menu->AddItem( EE_ACTIONS::toggleExcludeFromBoard, E_C::ShowAlways );
|
2022-06-13 09:35:17 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
menu->AddSeparator();
|
|
|
|
menu->AddItem( EE_ACTIONS::setDNP, E_C::ShowAlways );
|
|
|
|
menu->AddItem( EE_ACTIONS::unsetDNP, E_C::ShowAlways );
|
|
|
|
menu->AddItem( EE_ACTIONS::toggleDNP, E_C::ShowAlways );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
return menu;
|
|
|
|
};
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
auto makeEditFieldsMenu =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
CONDITIONAL_MENU* menu = new CONDITIONAL_MENU( m_selectionTool );
|
|
|
|
menu->SetTitle( _( "Edit Main Fields" ) );
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
menu->AddItem( EE_ACTIONS::editReference, E_C::SingleSymbol, 200 );
|
|
|
|
menu->AddItem( EE_ACTIONS::editValue, E_C::SingleSymbol, 200 );
|
|
|
|
menu->AddItem( EE_ACTIONS::editFootprint, E_C::SingleSymbol, 200 );
|
2022-07-10 23:14:29 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
return menu;
|
|
|
|
};
|
2022-05-30 13:07:28 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
auto makeConvertToMenu =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
CONDITIONAL_MENU* menu = new CONDITIONAL_MENU( m_selectionTool );
|
|
|
|
menu->SetTitle( _( "Change To" ) );
|
|
|
|
menu->SetIcon( BITMAPS::right );
|
|
|
|
|
|
|
|
menu->AddItem( EE_ACTIONS::toLabel, toLabelCondition );
|
|
|
|
menu->AddItem( EE_ACTIONS::toCLabel, toCLabelCondition );
|
|
|
|
menu->AddItem( EE_ACTIONS::toHLabel, toHLabelCondition );
|
|
|
|
menu->AddItem( EE_ACTIONS::toGLabel, toGLabelCondition );
|
|
|
|
menu->AddItem( EE_ACTIONS::toText, toTextCondition );
|
|
|
|
menu->AddItem( EE_ACTIONS::toTextBox, toTextBoxCondition );
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
};
|
2023-05-04 18:50:39 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
//
|
|
|
|
// Add edit actions to the move tool menu
|
|
|
|
//
|
|
|
|
CONDITIONAL_MENU& moveMenu = moveTool->GetToolMenu().GetMenu();
|
2023-05-04 18:50:39 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
moveMenu.AddSeparator();
|
|
|
|
moveMenu.AddMenu( makeSymbolUnitMenu( moveTool ), E_C::SingleMultiUnitSymbol, 1 );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
moveMenu.AddMenu( makeTransformMenu(), orientCondition, 200 );
|
|
|
|
moveMenu.AddMenu( makeAttributesMenu(), E_C::HasType( SCH_SYMBOL_T ), 200 );
|
|
|
|
moveMenu.AddItem( EE_ACTIONS::swap, SELECTION_CONDITIONS::MoreThan( 1 ), 200);
|
|
|
|
moveMenu.AddItem( EE_ACTIONS::properties, propertiesCondition, 200 );
|
|
|
|
moveMenu.AddMenu( makeEditFieldsMenu(), E_C::SingleSymbol, 200 );
|
2019-05-17 15:44:58 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
moveMenu.AddSeparator();
|
|
|
|
moveMenu.AddItem( ACTIONS::cut, E_C::IdleSelection );
|
|
|
|
moveMenu.AddItem( ACTIONS::copy, E_C::IdleSelection );
|
|
|
|
moveMenu.AddItem( ACTIONS::doDelete, E_C::NotEmpty );
|
|
|
|
moveMenu.AddItem( ACTIONS::duplicate, duplicateCondition );
|
2022-06-13 09:35:17 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
//
|
|
|
|
// Add editing actions to the drawing tool menu
|
|
|
|
//
|
|
|
|
CONDITIONAL_MENU& drawMenu = drawingTools->GetToolMenu().GetMenu();
|
2022-06-13 09:35:17 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
drawMenu.AddItem( EE_ACTIONS::clearHighlight, haveHighlight && EE_CONDITIONS::Idle, 1 );
|
|
|
|
drawMenu.AddSeparator( haveHighlight && EE_CONDITIONS::Idle, 1 );
|
2022-06-13 09:35:17 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
drawMenu.AddItem( EE_ACTIONS::enterSheet, sheetSelection && EE_CONDITIONS::Idle, 1 );
|
|
|
|
drawMenu.AddSeparator( sheetSelection && EE_CONDITIONS::Idle, 1 );
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
drawMenu.AddMenu( makeSymbolUnitMenu( drawingTools ), E_C::SingleMultiUnitSymbol, 1 );
|
2022-06-13 09:35:17 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
drawMenu.AddMenu( makeTransformMenu(), orientCondition, 200 );
|
|
|
|
drawMenu.AddMenu( makeAttributesMenu(), E_C::HasType( SCH_SYMBOL_T ), 200 );
|
|
|
|
drawMenu.AddItem( EE_ACTIONS::properties, propertiesCondition, 200 );
|
|
|
|
drawMenu.AddMenu( makeEditFieldsMenu(), E_C::SingleSymbol, 200 );
|
|
|
|
drawMenu.AddItem( EE_ACTIONS::autoplaceFields, autoplaceCondition, 200 );
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
drawMenu.AddItem( EE_ACTIONS::editWithLibEdit, E_C::SingleSymbolOrPower && E_C::Idle, 200 );
|
2019-05-06 20:37:54 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
drawMenu.AddItem( EE_ACTIONS::toLabel, anyTextTool && E_C::Idle, 200 );
|
|
|
|
drawMenu.AddItem( EE_ACTIONS::toHLabel, anyTextTool && E_C::Idle, 200 );
|
|
|
|
drawMenu.AddItem( EE_ACTIONS::toGLabel, anyTextTool && E_C::Idle, 200 );
|
|
|
|
drawMenu.AddItem( EE_ACTIONS::toText, anyTextTool && E_C::Idle, 200 );
|
|
|
|
drawMenu.AddItem( EE_ACTIONS::toTextBox, anyTextTool && E_C::Idle, 200 );
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2019-05-02 10:59:36 +00:00
|
|
|
//
|
2019-04-28 23:34:43 +00:00
|
|
|
// Add editing actions to the selection tool menu
|
|
|
|
//
|
|
|
|
CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
|
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
selToolMenu.AddMenu( makeSymbolUnitMenu( m_selectionTool ), E_C::SingleMultiUnitSymbol, 1 );
|
|
|
|
selToolMenu.AddMenu( makePinFunctionMenu( m_selectionTool ), E_C::SingleMultiFunctionPin, 1 );
|
2024-05-01 22:49:35 +00:00
|
|
|
selToolMenu.AddMenu( makePinTricksMenu( m_selectionTool ), E_C::AllPinsOrSheetPins, 1 );
|
2019-05-02 10:59:36 +00:00
|
|
|
|
2023-12-28 13:54:49 +00:00
|
|
|
selToolMenu.AddMenu( makeTransformMenu(), orientCondition, 200 );
|
|
|
|
selToolMenu.AddMenu( makeAttributesMenu(), E_C::HasType( SCH_SYMBOL_T ), 200 );
|
|
|
|
selToolMenu.AddItem( EE_ACTIONS::swap, SELECTION_CONDITIONS::MoreThan( 1 ), 200 );
|
2019-05-10 17:19:48 +00:00
|
|
|
selToolMenu.AddItem( EE_ACTIONS::properties, propertiesCondition, 200 );
|
2023-12-28 13:54:49 +00:00
|
|
|
selToolMenu.AddMenu( makeEditFieldsMenu(), E_C::SingleSymbol, 200 );
|
|
|
|
selToolMenu.AddItem( EE_ACTIONS::autoplaceFields, autoplaceCondition, 200 );
|
2023-09-28 14:27:27 +00:00
|
|
|
|
2021-02-21 23:45:32 +00:00
|
|
|
selToolMenu.AddItem( EE_ACTIONS::editWithLibEdit, E_C::SingleSymbolOrPower && E_C::Idle, 200 );
|
2021-02-17 00:14:23 +00:00
|
|
|
selToolMenu.AddItem( EE_ACTIONS::changeSymbol, E_C::SingleSymbolOrPower, 200 );
|
|
|
|
selToolMenu.AddItem( EE_ACTIONS::updateSymbol, E_C::SingleSymbolOrPower, 200 );
|
2022-12-22 19:00:10 +00:00
|
|
|
selToolMenu.AddItem( EE_ACTIONS::changeSymbols, E_C::MultipleSymbolsOrPower, 200 );
|
|
|
|
selToolMenu.AddItem( EE_ACTIONS::updateSymbols, E_C::MultipleSymbolsOrPower, 200 );
|
2023-12-28 13:54:49 +00:00
|
|
|
selToolMenu.AddMenu( makeConvertToMenu(), toChangeCondition, 200 );
|
2022-06-09 14:46:21 +00:00
|
|
|
|
2021-08-30 15:45:25 +00:00
|
|
|
selToolMenu.AddItem( EE_ACTIONS::cleanupSheetPins, sheetHasUndefinedPins, 250 );
|
2019-04-29 10:41:27 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
selToolMenu.AddSeparator( 300 );
|
2019-05-17 16:45:27 +00:00
|
|
|
selToolMenu.AddItem( ACTIONS::cut, E_C::IdleSelection, 300 );
|
|
|
|
selToolMenu.AddItem( ACTIONS::copy, E_C::IdleSelection, 300 );
|
|
|
|
selToolMenu.AddItem( ACTIONS::paste, E_C::Idle, 300 );
|
2019-09-02 18:23:46 +00:00
|
|
|
selToolMenu.AddItem( ACTIONS::pasteSpecial, E_C::Idle, 300 );
|
2021-01-17 18:19:02 +00:00
|
|
|
selToolMenu.AddItem( ACTIONS::doDelete, E_C::NotEmpty, 300 );
|
2019-05-27 10:40:52 +00:00
|
|
|
selToolMenu.AddItem( ACTIONS::duplicate, duplicateCondition, 300 );
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2020-08-20 23:05:21 +00:00
|
|
|
selToolMenu.AddSeparator( 400 );
|
|
|
|
selToolMenu.AddItem( ACTIONS::selectAll, hasElements, 400 );
|
2023-09-06 23:44:39 +00:00
|
|
|
selToolMenu.AddItem( ACTIONS::unselectAll, hasElements, 400 );
|
2020-08-20 23:05:21 +00:00
|
|
|
|
2019-04-23 13:06:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-27 18:22:58 +00:00
|
|
|
const std::vector<KICAD_T> SCH_EDIT_TOOL::RotatableItems = {
|
2021-07-17 19:56:18 +00:00
|
|
|
SCH_SHAPE_T,
|
2024-04-25 14:24:46 +00:00
|
|
|
SCH_RULE_AREA_T,
|
2019-06-17 21:11:41 +00:00
|
|
|
SCH_TEXT_T,
|
2022-01-25 22:33:37 +00:00
|
|
|
SCH_TEXTBOX_T,
|
2023-11-25 12:38:24 +00:00
|
|
|
SCH_TABLE_T,
|
|
|
|
SCH_TABLECELL_T, // will be promoted to parent table(s)
|
2019-06-17 21:11:41 +00:00
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
2022-01-24 13:40:39 +00:00
|
|
|
SCH_DIRECTIVE_LABEL_T,
|
2019-06-17 21:11:41 +00:00
|
|
|
SCH_FIELD_T,
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL_T,
|
2019-06-17 21:11:41 +00:00
|
|
|
SCH_SHEET_PIN_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
SCH_BITMAP_T,
|
|
|
|
SCH_BUS_BUS_ENTRY_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
|
|
|
SCH_LINE_T,
|
2023-01-09 16:04:42 +00:00
|
|
|
SCH_JUNCTION_T,
|
2023-01-11 12:15:38 +00:00
|
|
|
SCH_NO_CONNECT_T
|
2019-06-17 21:11:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-12-23 01:17:18 +00:00
|
|
|
bool clockwise = ( aEvent.Matches( EE_ACTIONS::rotateCW.MakeEvent() ) );
|
2023-11-25 12:38:24 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( RotatableItems, true );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
|
|
|
if( selection.GetSize() == 0 )
|
|
|
|
return 0;
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_ITEM* head = nullptr;
|
|
|
|
int principalItemCount = 0; // User-selected items (as opposed to connected wires)
|
|
|
|
VECTOR2I rotPoint;
|
|
|
|
bool moving = false;
|
|
|
|
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 16:24:49 +00:00
|
|
|
|
|
|
|
if( !commit )
|
2023-06-09 21:41:33 +00:00
|
|
|
commit = &localCommit;
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-12-23 01:17:18 +00:00
|
|
|
for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.GetItem( ii ) );
|
|
|
|
|
2022-03-03 14:35:57 +00:00
|
|
|
if( item->HasFlag( SELECTED_BY_DRAG ) )
|
2020-12-23 01:17:18 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
principalItemCount++;
|
|
|
|
|
|
|
|
if( !head )
|
|
|
|
head = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( head && head->IsMoving() )
|
|
|
|
moving = true;
|
|
|
|
|
|
|
|
if( principalItemCount == 1 )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2021-10-18 12:24:06 +00:00
|
|
|
if( moving && selection.HasReferencePoint() )
|
2022-01-01 06:04:08 +00:00
|
|
|
rotPoint = selection.GetReferencePoint();
|
2022-01-25 22:33:37 +00:00
|
|
|
else if( head->IsConnectable() )
|
2021-10-18 12:24:06 +00:00
|
|
|
rotPoint = head->GetPosition();
|
2022-01-25 22:33:37 +00:00
|
|
|
else
|
|
|
|
rotPoint = m_frame->GetNearestHalfGridPosition( head->GetBoundingBox().GetCenter() );
|
2020-12-23 01:17:18 +00:00
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
if( !moving )
|
2023-06-09 16:24:49 +00:00
|
|
|
commit->Modify( head, m_frame->GetScreen() );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-12-23 01:17:18 +00:00
|
|
|
switch( head->Type() )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
case SCH_SYMBOL_T:
|
2020-01-08 19:07:55 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( head );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2024-04-04 22:51:22 +00:00
|
|
|
symbol->Rotate( rotPoint, !clockwise );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-04-12 23:09:17 +00:00
|
|
|
if( m_frame->eeconfig()->m_AutoplaceFields.enable )
|
2021-03-19 20:27:30 +00:00
|
|
|
symbol->AutoAutoplaceFields( m_frame->GetScreen() );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case SCH_TEXT_T:
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
2022-01-24 13:40:39 +00:00
|
|
|
case SCH_DIRECTIVE_LABEL_T:
|
2020-01-08 19:07:55 +00:00
|
|
|
{
|
2020-12-23 01:17:18 +00:00
|
|
|
SCH_TEXT* textItem = static_cast<SCH_TEXT*>( head );
|
2020-11-18 21:40:04 +00:00
|
|
|
textItem->Rotate90( clockwise );
|
2020-01-08 19:07:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
{
|
|
|
|
// Rotate pin within parent sheet
|
2020-12-23 01:17:18 +00:00
|
|
|
SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( head );
|
2020-01-08 19:07:55 +00:00
|
|
|
SCH_SHEET* sheet = pin->GetParent();
|
2020-11-18 21:40:04 +00:00
|
|
|
|
2024-04-04 22:51:22 +00:00
|
|
|
pin->Rotate( sheet->GetBoundingBox().GetCenter(), !clockwise );
|
2020-11-18 23:34:03 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-11-24 23:40:17 +00:00
|
|
|
case SCH_LINE_T:
|
2022-02-25 16:27:55 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( head );
|
|
|
|
|
|
|
|
// Equal checks for both and neither. We need this because on undo
|
|
|
|
// the item will have both flags cleared, but will be selected, so it is possible
|
|
|
|
// for the user to get a selected line with neither endpoint selected. We
|
|
|
|
// set flags to make sure Rotate() works when we call it.
|
|
|
|
if( line->HasFlag( STARTPOINT ) == line->HasFlag( ENDPOINT ) )
|
|
|
|
{
|
|
|
|
line->SetFlags( STARTPOINT | ENDPOINT );
|
2022-10-17 13:19:39 +00:00
|
|
|
|
2022-02-25 16:27:55 +00:00
|
|
|
// When we allow off grid items, the rotPoint should be set to the midpoint
|
|
|
|
// of the line to allow rotation around the center, and the next if
|
|
|
|
// should become an else-if
|
|
|
|
}
|
|
|
|
|
|
|
|
if( line->HasFlag( STARTPOINT ) )
|
|
|
|
rotPoint = line->GetEndPoint();
|
|
|
|
else if( line->HasFlag( ENDPOINT ) )
|
|
|
|
rotPoint = line->GetStartPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
KI_FALLTHROUGH;
|
2023-01-09 16:04:42 +00:00
|
|
|
case SCH_JUNCTION_T:
|
2024-01-02 22:03:10 +00:00
|
|
|
case SCH_NO_CONNECT_T:
|
2020-01-08 19:07:55 +00:00
|
|
|
case SCH_BUS_BUS_ENTRY_T:
|
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
2024-04-04 22:51:22 +00:00
|
|
|
head->Rotate( rotPoint, !clockwise );
|
2020-11-18 21:40:04 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
break;
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case SCH_FIELD_T:
|
|
|
|
{
|
2020-12-23 01:17:18 +00:00
|
|
|
SCH_FIELD* field = static_cast<SCH_FIELD*>( head );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
if( field->GetTextAngle().IsHorizontal() )
|
2022-01-13 12:29:46 +00:00
|
|
|
field->SetTextAngle( ANGLE_VERTICAL );
|
2020-01-08 19:07:55 +00:00
|
|
|
else
|
2022-01-13 12:29:46 +00:00
|
|
|
field->SetTextAngle( ANGLE_HORIZONTAL );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
// Now that we're moving a field, they're no longer autoplaced.
|
2020-12-23 01:17:18 +00:00
|
|
|
static_cast<SCH_ITEM*>( head->GetParent() )->ClearFieldsAutoplaced();
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2024-04-25 14:24:46 +00:00
|
|
|
case SCH_RULE_AREA_T:
|
2021-07-17 19:56:18 +00:00
|
|
|
case SCH_SHAPE_T:
|
2022-01-25 22:33:37 +00:00
|
|
|
case SCH_TEXTBOX_T:
|
2024-04-04 22:51:22 +00:00
|
|
|
head->Rotate( rotPoint, !clockwise );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2023-11-25 12:38:24 +00:00
|
|
|
case SCH_TABLE_T:
|
|
|
|
{
|
|
|
|
// Rotate the table on itself. Tables do not have an anchor point.
|
|
|
|
SCH_TABLE* table = static_cast<SCH_TABLE*>( head );
|
|
|
|
BOX2I box( table->GetPosition(), table->GetEnd() - table->GetPosition() );
|
|
|
|
rotPoint = m_frame->GetNearestHalfGridPosition( box.GetCenter() );
|
|
|
|
|
2024-04-04 22:51:22 +00:00
|
|
|
head->Rotate( rotPoint, !clockwise );
|
2023-11-25 12:38:24 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
case SCH_BITMAP_T:
|
2024-04-04 22:51:22 +00:00
|
|
|
head->Rotate( rotPoint, !clockwise );
|
2020-11-18 21:40:04 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
// The bitmap is cached in Opengl: clear the cache to redraw
|
|
|
|
getView()->RecacheAllItems();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_SHEET_T:
|
|
|
|
{
|
2023-11-25 12:38:24 +00:00
|
|
|
// Rotate the sheet on itself. Sheets do not have an anchor point.
|
2020-12-23 01:17:18 +00:00
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( head );
|
2019-09-02 21:34:50 +00:00
|
|
|
|
2024-04-04 22:51:22 +00:00
|
|
|
rotPoint = m_frame->GetNearestHalfGridPosition( sheet->GetRotationCenter() );
|
|
|
|
sheet->Rotate( rotPoint, !clockwise );
|
2020-12-23 01:17:18 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
default:
|
2021-07-17 19:56:18 +00:00
|
|
|
UNIMPLEMENTED_FOR( head->GetClass() );
|
2019-04-23 17:40:29 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 03:10:20 +00:00
|
|
|
m_frame->UpdateItem( head, false, true );
|
2019-04-23 17:40:29 +00:00
|
|
|
}
|
2020-12-23 01:17:18 +00:00
|
|
|
else
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2021-10-18 12:24:06 +00:00
|
|
|
if( moving && selection.HasReferencePoint() )
|
2022-01-01 06:04:08 +00:00
|
|
|
rotPoint = selection.GetReferencePoint();
|
2021-10-18 12:24:06 +00:00
|
|
|
else
|
2022-01-01 06:04:08 +00:00
|
|
|
rotPoint = m_frame->GetNearestHalfGridPosition( selection.GetCenter() );
|
2020-12-23 01:17:18 +00:00
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
for( EDA_ITEM* edaItem : selection )
|
2020-12-23 01:17:18 +00:00
|
|
|
{
|
2023-06-09 16:24:49 +00:00
|
|
|
SCH_ITEM* item = static_cast<SCH_ITEM*>( edaItem );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-12-23 01:17:18 +00:00
|
|
|
// We've already rotated the user selected item if there was only one. We're just
|
|
|
|
// here to rotate the ends of wires that were attached to it.
|
2022-03-03 14:35:57 +00:00
|
|
|
if( principalItemCount == 1 && !item->HasFlag( SELECTED_BY_DRAG ) )
|
2020-12-23 01:17:18 +00:00
|
|
|
continue;
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-12-23 01:17:18 +00:00
|
|
|
if( !moving )
|
2023-06-09 16:24:49 +00:00
|
|
|
commit->Modify( item, m_frame->GetScreen() );
|
2020-12-23 01:17:18 +00:00
|
|
|
|
2021-09-17 16:06:21 +00:00
|
|
|
for( int i = 0; clockwise ? i < 3 : i < 1; ++i )
|
2020-12-23 01:17:18 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == SCH_LINE_T )
|
2019-05-03 22:46:44 +00:00
|
|
|
{
|
2020-12-23 01:17:18 +00:00
|
|
|
SCH_LINE* line = (SCH_LINE*) item;
|
2019-05-17 16:45:27 +00:00
|
|
|
|
2021-08-31 21:31:56 +00:00
|
|
|
// If we are rotating more than one item, we do not have start/end
|
|
|
|
// points separately selected
|
2021-09-23 21:39:29 +00:00
|
|
|
if( item->HasFlag( STARTPOINT ) )
|
2020-12-23 01:17:18 +00:00
|
|
|
line->RotateStart( rotPoint );
|
2019-05-17 16:45:27 +00:00
|
|
|
|
2021-09-23 21:39:29 +00:00
|
|
|
if( item->HasFlag( ENDPOINT ) )
|
2020-12-23 01:17:18 +00:00
|
|
|
line->RotateEnd( rotPoint );
|
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_SHEET_PIN_T )
|
|
|
|
{
|
|
|
|
if( item->GetParent()->IsSelected() )
|
2019-05-17 16:45:27 +00:00
|
|
|
{
|
2020-12-23 01:17:18 +00:00
|
|
|
// parent will rotate us
|
2019-05-17 16:45:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-23 01:17:18 +00:00
|
|
|
// rotate within parent
|
|
|
|
SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( item );
|
|
|
|
SCH_SHEET* sheet = pin->GetParent();
|
|
|
|
|
2024-04-04 22:51:22 +00:00
|
|
|
pin->Rotate( sheet->GetBodyBoundingBox().GetCenter(), false );
|
2019-05-17 16:45:27 +00:00
|
|
|
}
|
2019-05-03 22:46:44 +00:00
|
|
|
}
|
2021-02-04 00:04:54 +00:00
|
|
|
else if( item->Type() == SCH_FIELD_T )
|
|
|
|
{
|
|
|
|
if( item->GetParent()->IsSelected() )
|
|
|
|
{
|
|
|
|
// parent will rotate us
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-13 19:02:32 +00:00
|
|
|
SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
|
|
|
|
|
2024-05-03 20:13:51 +00:00
|
|
|
field->Rotate( rotPoint, true );
|
2021-06-13 19:02:32 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
if( field->GetTextAngle().IsHorizontal() )
|
2022-01-13 12:29:46 +00:00
|
|
|
field->SetTextAngle( ANGLE_VERTICAL );
|
2021-06-13 19:02:32 +00:00
|
|
|
else
|
2022-01-13 12:29:46 +00:00
|
|
|
field->SetTextAngle( ANGLE_HORIZONTAL );
|
2021-06-13 19:02:32 +00:00
|
|
|
|
|
|
|
// Now that we're moving a field, they're no longer autoplaced.
|
|
|
|
static_cast<SCH_ITEM*>( field->GetParent() )->ClearFieldsAutoplaced();
|
2021-02-04 00:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-23 01:17:18 +00:00
|
|
|
else
|
|
|
|
{
|
2024-05-03 20:13:51 +00:00
|
|
|
item->Rotate( rotPoint, true );
|
2020-12-23 01:17:18 +00:00
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
}
|
2020-12-23 01:17:18 +00:00
|
|
|
|
2021-10-06 03:10:20 +00:00
|
|
|
m_frame->UpdateItem( item, false, true );
|
2021-08-31 23:36:10 +00:00
|
|
|
updateItem( item, true );
|
2019-04-23 17:40:29 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 01:17:18 +00:00
|
|
|
if( moving )
|
2019-05-20 10:22:36 +00:00
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2019-05-20 10:22:36 +00:00
|
|
|
}
|
|
|
|
else
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2022-05-05 16:18:29 +00:00
|
|
|
EE_SELECTION selectionCopy = selection;
|
|
|
|
|
2019-04-26 16:34:04 +00:00
|
|
|
if( selection.IsHover() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
2023-01-06 22:14:06 +00:00
|
|
|
SCH_LINE_WIRE_BUS_TOOL* lwbTool = m_toolMgr->GetTool<SCH_LINE_WIRE_BUS_TOOL>();
|
2023-06-09 16:24:49 +00:00
|
|
|
lwbTool->TrimOverLappingWires( commit, &selectionCopy );
|
|
|
|
lwbTool->AddJunctionsIfNeeded( commit, &selectionCopy );
|
2022-04-11 11:01:38 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
m_frame->SchematicCleanUp( commit );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
if( !localCommit.Empty() )
|
|
|
|
localCommit.Push( _( "Rotate" ) );
|
2019-04-26 16:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2022-12-27 18:22:58 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( RotatableItems );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
|
|
|
if( selection.GetSize() == 0 )
|
|
|
|
return 0;
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
bool vertical = ( aEvent.Matches( EE_ACTIONS::mirrorV.MakeEvent() ) );
|
|
|
|
SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
|
|
|
|
bool connections = false;
|
|
|
|
bool moving = item->IsMoving();
|
|
|
|
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 16:24:49 +00:00
|
|
|
|
|
|
|
if( !commit )
|
2023-06-09 21:41:33 +00:00
|
|
|
commit = &localCommit;
|
2019-04-26 16:34:04 +00:00
|
|
|
|
|
|
|
if( selection.GetSize() == 1 )
|
|
|
|
{
|
|
|
|
if( !moving )
|
2023-06-09 16:24:49 +00:00
|
|
|
commit->Modify( item, m_frame->GetScreen() );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
case SCH_SYMBOL_T:
|
2019-04-26 16:34:04 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
if( vertical )
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->SetOrientation( SYM_MIRROR_X );
|
2019-04-26 16:34:04 +00:00
|
|
|
else
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->SetOrientation( SYM_MIRROR_Y );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
2022-04-25 19:50:45 +00:00
|
|
|
symbol->ClearFieldsAutoplaced();
|
2019-04-26 16:34:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_TEXT_T:
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
2022-01-24 13:40:39 +00:00
|
|
|
case SCH_DIRECTIVE_LABEL_T:
|
2019-04-26 16:34:04 +00:00
|
|
|
{
|
|
|
|
SCH_TEXT* textItem = static_cast<SCH_TEXT*>( item );
|
2021-02-16 20:45:25 +00:00
|
|
|
textItem->MirrorSpinStyle( !vertical );
|
2019-04-26 16:34:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
{
|
|
|
|
// mirror within parent sheet
|
|
|
|
SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( item );
|
|
|
|
SCH_SHEET* sheet = pin->GetParent();
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
if( vertical )
|
|
|
|
pin->MirrorVertically( sheet->GetBoundingBox().GetCenter().y );
|
2019-05-17 16:45:27 +00:00
|
|
|
else
|
2021-02-16 20:45:25 +00:00
|
|
|
pin->MirrorHorizontally( sheet->GetBoundingBox().GetCenter().x );
|
2019-05-17 16:45:27 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-04-26 16:34:04 +00:00
|
|
|
case SCH_FIELD_T:
|
|
|
|
{
|
|
|
|
SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
if( vertical )
|
2021-12-28 22:13:54 +00:00
|
|
|
field->SetVertJustify( TO_VJUSTIFY( -field->GetVertJustify() ) );
|
2019-04-26 16:34:04 +00:00
|
|
|
else
|
2021-12-28 22:13:54 +00:00
|
|
|
field->SetHorizJustify( TO_HJUSTIFY( -field->GetHorizJustify() ) );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
|
|
|
// Now that we're re-justifying a field, they're no longer autoplaced.
|
2021-12-28 22:13:54 +00:00
|
|
|
static_cast<SCH_ITEM*>( field->GetParent() )->ClearFieldsAutoplaced();
|
2019-04-26 16:34:04 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_BITMAP_T:
|
2021-02-16 20:45:25 +00:00
|
|
|
if( vertical )
|
|
|
|
item->MirrorVertically( item->GetPosition().y );
|
2019-04-26 16:34:04 +00:00
|
|
|
else
|
2021-02-16 20:45:25 +00:00
|
|
|
item->MirrorHorizontally( item->GetPosition().x );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
|
|
|
// The bitmap is cached in Opengl: clear the cache to redraw
|
|
|
|
getView()->RecacheAllItems();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_SHEET_T:
|
2022-05-21 21:15:22 +00:00
|
|
|
{
|
2019-04-26 16:34:04 +00:00
|
|
|
// Mirror the sheet on itself. Sheets do not have a anchor point.
|
2022-05-21 21:15:22 +00:00
|
|
|
VECTOR2I mirrorPoint = m_frame->GetNearestHalfGridPosition( item->GetBoundingBox().Centre() );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
if( vertical )
|
|
|
|
item->MirrorVertically( mirrorPoint.y );
|
2019-04-26 16:34:04 +00:00
|
|
|
else
|
2021-02-16 20:45:25 +00:00
|
|
|
item->MirrorHorizontally( mirrorPoint.x );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
|
|
|
break;
|
2022-05-21 21:15:22 +00:00
|
|
|
}
|
2019-04-26 16:34:04 +00:00
|
|
|
|
|
|
|
default:
|
2022-05-21 21:15:22 +00:00
|
|
|
if( vertical )
|
|
|
|
item->MirrorVertically( item->GetPosition().y );
|
|
|
|
else
|
|
|
|
item->MirrorHorizontally( item->GetPosition().x );
|
|
|
|
|
|
|
|
break;
|
2019-04-26 16:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
connections = item->IsConnectable();
|
2021-10-06 03:10:20 +00:00
|
|
|
m_frame->UpdateItem( item, false, true );
|
2019-04-26 16:34:04 +00:00
|
|
|
}
|
|
|
|
else if( selection.GetSize() > 1 )
|
|
|
|
{
|
2022-05-21 21:15:22 +00:00
|
|
|
VECTOR2I mirrorPoint = m_frame->GetNearestHalfGridPosition( selection.GetCenter() );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
for( EDA_ITEM* edaItem : selection )
|
2019-04-26 16:34:04 +00:00
|
|
|
{
|
2023-06-09 16:24:49 +00:00
|
|
|
item = static_cast<SCH_ITEM*>( edaItem );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
|
|
|
if( !moving )
|
2023-06-09 16:24:49 +00:00
|
|
|
commit->Modify( item, m_frame->GetScreen() );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
if( item->Type() == SCH_SHEET_PIN_T )
|
|
|
|
{
|
|
|
|
if( item->GetParent()->IsSelected() )
|
|
|
|
{
|
|
|
|
// parent will mirror us
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// mirror within parent sheet
|
|
|
|
SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( item );
|
|
|
|
SCH_SHEET* sheet = pin->GetParent();
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
if( vertical )
|
|
|
|
pin->MirrorVertically( sheet->GetBoundingBox().GetCenter().y );
|
2019-05-17 16:45:27 +00:00
|
|
|
else
|
2021-02-16 20:45:25 +00:00
|
|
|
pin->MirrorHorizontally( sheet->GetBoundingBox().GetCenter().x );
|
2019-05-17 16:45:27 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-26 16:34:27 +00:00
|
|
|
else if( item->Type() == SCH_FIELD_T )
|
|
|
|
{
|
|
|
|
SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
|
|
|
|
|
|
|
|
if( vertical )
|
|
|
|
field->SetVertJustify( TO_VJUSTIFY( -field->GetVertJustify() ) );
|
|
|
|
else
|
|
|
|
field->SetHorizJustify( TO_HJUSTIFY( -field->GetHorizJustify() ) );
|
|
|
|
|
|
|
|
// Now that we're re-justifying a field, they're no longer autoplaced.
|
|
|
|
static_cast<SCH_ITEM*>( field->GetParent() )->ClearFieldsAutoplaced();
|
|
|
|
}
|
2019-04-26 16:34:04 +00:00
|
|
|
else
|
2019-05-17 16:45:27 +00:00
|
|
|
{
|
2021-02-16 20:45:25 +00:00
|
|
|
if( vertical )
|
|
|
|
item->MirrorVertically( mirrorPoint.y );
|
2019-05-17 16:45:27 +00:00
|
|
|
else
|
2021-02-16 20:45:25 +00:00
|
|
|
item->MirrorHorizontally( mirrorPoint.x );
|
2019-05-17 16:45:27 +00:00
|
|
|
}
|
2019-04-26 16:34:04 +00:00
|
|
|
|
|
|
|
connections |= item->IsConnectable();
|
2021-10-06 03:10:20 +00:00
|
|
|
m_frame->UpdateItem( item, false, true );
|
2019-04-26 16:34:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 00:18:44 +00:00
|
|
|
// Update R-Tree for modified items
|
|
|
|
for( EDA_ITEM* selected : selection )
|
|
|
|
updateItem( selected, true );
|
|
|
|
|
2019-05-20 10:22:36 +00:00
|
|
|
if( item->IsMoving() )
|
|
|
|
{
|
2019-07-04 20:56:21 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
2019-05-20 10:22:36 +00:00
|
|
|
}
|
|
|
|
else
|
2019-04-26 16:34:04 +00:00
|
|
|
{
|
2023-01-09 16:04:42 +00:00
|
|
|
EE_SELECTION selectionCopy = selection;
|
|
|
|
|
2019-04-26 16:34:04 +00:00
|
|
|
if( selection.IsHover() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-04-26 16:34:04 +00:00
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
if( connections )
|
2023-01-09 16:04:42 +00:00
|
|
|
{
|
|
|
|
SCH_LINE_WIRE_BUS_TOOL* lwbTool = m_toolMgr->GetTool<SCH_LINE_WIRE_BUS_TOOL>();
|
2023-06-09 16:24:49 +00:00
|
|
|
lwbTool->TrimOverLappingWires( commit, &selectionCopy );
|
|
|
|
lwbTool->AddJunctionsIfNeeded( commit, &selectionCopy );
|
2023-01-09 16:04:42 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
m_frame->SchematicCleanUp( commit );
|
2023-01-09 16:04:42 +00:00
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
if( !localCommit.Empty() )
|
|
|
|
localCommit.Push( _( "Mirror" ) );
|
2019-04-23 17:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-30 13:01:48 +00:00
|
|
|
const std::vector<KICAD_T> swappableItems = {
|
|
|
|
SCH_SHAPE_T,
|
2024-04-25 14:24:46 +00:00
|
|
|
SCH_RULE_AREA_T,
|
2022-08-30 13:01:48 +00:00
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_TEXTBOX_T,
|
|
|
|
SCH_LABEL_T,
|
2023-07-09 00:26:26 +00:00
|
|
|
SCH_SHEET_PIN_T,
|
2022-08-30 13:01:48 +00:00
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_DIRECTIVE_LABEL_T,
|
|
|
|
SCH_FIELD_T,
|
|
|
|
SCH_SYMBOL_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
SCH_BITMAP_T,
|
|
|
|
SCH_JUNCTION_T,
|
|
|
|
SCH_NO_CONNECT_T
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDIT_TOOL::Swap( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( swappableItems );
|
|
|
|
std::vector<EDA_ITEM*> sorted = selection.GetItemsSortedBySelectionOrder();
|
|
|
|
|
2023-07-09 00:26:26 +00:00
|
|
|
// Sheet pins are special, we need to make sure if we have any sheet pins,
|
|
|
|
// that we only have sheet pins, and that they have the same parent
|
|
|
|
if( selection.CountType( SCH_SHEET_PIN_T ) > 0 )
|
|
|
|
{
|
|
|
|
if( !selection.OnlyContains( { SCH_SHEET_PIN_T } ) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
SCH_SHEET_PIN* firstPin = static_cast<SCH_SHEET_PIN*>( selection.Front() );
|
|
|
|
SCH_SHEET* parent = firstPin->GetParent();
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( item );
|
|
|
|
|
|
|
|
if( pin->GetParent() != parent )
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:01:48 +00:00
|
|
|
if( selection.Size() < 2 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bool isMoving = selection.Front()->IsMoving();
|
|
|
|
bool appendUndo = isMoving;
|
|
|
|
bool connections = false;
|
|
|
|
|
|
|
|
SCH_SCREEN* screen = this->m_frame->GetScreen();
|
|
|
|
|
|
|
|
for( size_t i = 0; i < sorted.size() - 1; i++ )
|
|
|
|
{
|
|
|
|
SCH_ITEM* a = static_cast<SCH_ITEM*>( sorted[i] );
|
|
|
|
SCH_ITEM* b = static_cast<SCH_ITEM*>( sorted[( i + 1 ) % sorted.size()] );
|
|
|
|
|
|
|
|
VECTOR2I aPos = a->GetPosition(), bPos = b->GetPosition();
|
|
|
|
std::swap( aPos, bPos );
|
|
|
|
|
|
|
|
saveCopyInUndoList( a, UNDO_REDO::CHANGED, appendUndo );
|
|
|
|
appendUndo = true;
|
|
|
|
saveCopyInUndoList( b, UNDO_REDO::CHANGED, appendUndo );
|
|
|
|
|
2023-07-09 00:26:26 +00:00
|
|
|
// Sheet pins need to have their sides swapped before we change their
|
|
|
|
// positions
|
|
|
|
if( a->Type() == SCH_SHEET_PIN_T )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PIN* aPin = static_cast<SCH_SHEET_PIN*>( a );
|
|
|
|
SCH_SHEET_PIN* bPin = static_cast<SCH_SHEET_PIN*>( b );
|
|
|
|
SHEET_SIDE aSide = aPin->GetSide(), bSide = bPin->GetSide();
|
|
|
|
std::swap( aSide, bSide );
|
|
|
|
aPin->SetSide( aSide );
|
|
|
|
bPin->SetSide( bSide );
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:01:48 +00:00
|
|
|
a->SetPosition( aPos );
|
|
|
|
b->SetPosition( bPos );
|
|
|
|
|
|
|
|
if( a->Type() == b->Type() )
|
|
|
|
{
|
|
|
|
switch( a->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
|
|
|
case SCH_DIRECTIVE_LABEL_T:
|
|
|
|
m_frame->AutoRotateItem( screen, a );
|
|
|
|
m_frame->AutoRotateItem( screen, b );
|
|
|
|
break;
|
|
|
|
case SCH_SYMBOL_T:
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* aSymbol = static_cast<SCH_SYMBOL*>( a );
|
|
|
|
SCH_SYMBOL* bSymbol = static_cast<SCH_SYMBOL*>( b );
|
|
|
|
int aOrient = aSymbol->GetOrientation(), bOrient = bSymbol->GetOrientation();
|
|
|
|
std::swap( aOrient, bOrient );
|
|
|
|
aSymbol->SetOrientation( aOrient );
|
|
|
|
bSymbol->SetOrientation( bOrient );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
connections |= a->IsConnectable();
|
|
|
|
connections |= b->IsConnectable();
|
|
|
|
m_frame->UpdateItem( a, false, true );
|
|
|
|
m_frame->UpdateItem( b, false, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update R-Tree for modified items
|
|
|
|
for( EDA_ITEM* selected : selection )
|
|
|
|
updateItem( selected, true );
|
|
|
|
|
|
|
|
if( isMoving )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2022-08-30 13:01:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( selection.IsHover() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2022-08-30 13:01:48 +00:00
|
|
|
|
|
|
|
if( connections )
|
|
|
|
m_frame->TestDanglingEnds();
|
|
|
|
|
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-26 22:23:12 +00:00
|
|
|
int SCH_EDIT_TOOL::RepeatDrawItem( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2022-09-09 17:08:18 +00:00
|
|
|
const std::vector<std::unique_ptr<SCH_ITEM>>& sourceItems = m_frame->GetRepeatItems();
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2022-09-09 17:08:18 +00:00
|
|
|
if( sourceItems.empty() )
|
2019-04-26 22:23:12 +00:00
|
|
|
return 0;
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
EE_SELECTION newItems;
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2022-09-09 17:08:18 +00:00
|
|
|
for( const std::unique_ptr<SCH_ITEM>& item : sourceItems )
|
2019-04-26 22:23:12 +00:00
|
|
|
{
|
2022-09-09 17:08:18 +00:00
|
|
|
SCH_ITEM* newItem = item->Duplicate();
|
2021-11-27 11:52:36 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
|
2023-06-30 17:57:01 +00:00
|
|
|
bool restore_state = false;
|
2020-04-12 23:09:17 +00:00
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( newItem ) )
|
2020-04-12 23:09:17 +00:00
|
|
|
{
|
2021-11-27 11:52:36 +00:00
|
|
|
// If incrementing tries to go below zero, tell user why the value is repeated
|
2020-12-04 12:48:32 +00:00
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
if( !label->IncrementLabel( cfg->m_Drawing.repeat_label_increment ) )
|
2021-11-27 11:52:36 +00:00
|
|
|
m_frame->ShowInfoBarWarning( _( "Label value cannot go below zero" ), true );
|
2020-04-12 23:09:17 +00:00
|
|
|
}
|
2021-11-27 11:52:36 +00:00
|
|
|
|
2022-09-09 17:08:18 +00:00
|
|
|
// If cloning a symbol then put into 'move' mode.
|
|
|
|
if( newItem->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( true );
|
|
|
|
newItem->Move( cursorPos - newItem->GetPosition() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-16 23:42:20 +00:00
|
|
|
newItem->Move( VECTOR2I( schIUScale.MilsToIU( cfg->m_Drawing.default_repeat_offset_x ),
|
|
|
|
schIUScale.MilsToIU( cfg->m_Drawing.default_repeat_offset_y ) ) );
|
2022-09-09 17:08:18 +00:00
|
|
|
}
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2023-11-26 21:43:06 +00:00
|
|
|
// If cloning a sheet, check that we aren't going to create recursion
|
|
|
|
if( newItem->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH* currentSheet = &m_frame->GetCurrentSheet();
|
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( newItem );
|
|
|
|
|
|
|
|
if( m_frame->CheckSheetForRecursion( sheet, currentSheet ) )
|
|
|
|
{
|
|
|
|
// Clear out the filename so that the user can pick a new one
|
|
|
|
sheet->SetFileName( wxEmptyString );
|
|
|
|
sheet->GetScreen()->SetFileName( wxEmptyString );
|
|
|
|
restore_state = !m_frame->EditSheetProperties( sheet, currentSheet, nullptr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEM*>( EE_ACTIONS::addItemToSel, newItem );
|
2022-09-09 17:08:18 +00:00
|
|
|
newItem->SetFlags( IS_NEW );
|
|
|
|
m_frame->AddToScreen( newItem, m_frame->GetScreen() );
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Added( newItem, m_frame->GetScreen() );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2022-09-09 17:08:18 +00:00
|
|
|
if( newItem->Type() == SCH_SYMBOL_T )
|
2022-03-30 17:41:40 +00:00
|
|
|
{
|
2022-09-09 17:08:18 +00:00
|
|
|
EESCHEMA_SETTINGS::PANEL_ANNOTATE& annotate = m_frame->eeconfig()->m_AnnotatePanel;
|
|
|
|
SCHEMATIC_SETTINGS& projSettings = m_frame->Schematic().Settings();
|
|
|
|
int annotateStartNum = projSettings.m_AnnotateStartNum;
|
|
|
|
|
|
|
|
if( annotate.automatic )
|
|
|
|
{
|
|
|
|
static_cast<SCH_SYMBOL*>( newItem )->ClearAnnotation( nullptr, false );
|
|
|
|
NULL_REPORTER reporter;
|
2023-06-09 16:24:49 +00:00
|
|
|
m_frame->AnnotateSymbols( &commit, ANNOTATE_SELECTION,
|
2022-10-17 13:19:39 +00:00
|
|
|
(ANNOTATE_ORDER_T) annotate.sort_order,
|
2023-01-05 21:33:19 +00:00
|
|
|
(ANNOTATE_ALGO_T) annotate.method, true /* recursive */,
|
2023-06-09 16:24:49 +00:00
|
|
|
annotateStartNum, false, false, reporter );
|
2022-09-09 17:08:18 +00:00
|
|
|
}
|
|
|
|
|
2023-06-30 17:57:01 +00:00
|
|
|
restore_state = !m_toolMgr->RunSynchronousAction( EE_ACTIONS::move, &commit );
|
2022-03-30 17:41:40 +00:00
|
|
|
}
|
|
|
|
|
2023-06-30 17:57:01 +00:00
|
|
|
if( restore_state )
|
|
|
|
{
|
|
|
|
commit.Revert();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newItems.Add( newItem );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2023-06-30 17:57:01 +00:00
|
|
|
SCH_LINE_WIRE_BUS_TOOL* lwbTool = m_toolMgr->GetTool<SCH_LINE_WIRE_BUS_TOOL>();
|
|
|
|
lwbTool->TrimOverLappingWires( &commit, &newItems );
|
|
|
|
lwbTool->AddJunctionsIfNeeded( &commit, &newItems );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2023-06-30 17:57:01 +00:00
|
|
|
m_frame->SchematicCleanUp( &commit );
|
|
|
|
commit.Push( _( "Repeat Item" ) );
|
|
|
|
}
|
2021-03-09 21:24:03 +00:00
|
|
|
|
2019-06-19 03:10:21 +00:00
|
|
|
}
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2022-09-09 17:08:18 +00:00
|
|
|
if( !newItems.Empty() )
|
|
|
|
m_frame->SaveCopyForRepeatItem( static_cast<SCH_ITEM*>( newItems[0] ) );
|
|
|
|
|
|
|
|
for( size_t ii = 1; ii < newItems.GetSize(); ++ii )
|
|
|
|
m_frame->AddCopyForRepeatItem( static_cast<SCH_ITEM*>( newItems[ii] ) );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-21 19:54:07 +00:00
|
|
|
static std::vector<KICAD_T> deletableItems =
|
2019-06-17 21:11:41 +00:00
|
|
|
{
|
|
|
|
SCH_MARKER_T,
|
|
|
|
SCH_JUNCTION_T,
|
|
|
|
SCH_LINE_T,
|
|
|
|
SCH_BUS_BUS_ENTRY_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
2021-07-17 19:56:18 +00:00
|
|
|
SCH_SHAPE_T,
|
2024-04-25 14:24:46 +00:00
|
|
|
SCH_RULE_AREA_T,
|
2019-06-17 21:11:41 +00:00
|
|
|
SCH_TEXT_T,
|
2022-01-25 22:33:37 +00:00
|
|
|
SCH_TEXTBOX_T,
|
2023-11-25 12:38:24 +00:00
|
|
|
SCH_TABLECELL_T, // Clear contents
|
|
|
|
SCH_TABLE_T,
|
2019-06-17 21:11:41 +00:00
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
2022-01-24 13:40:39 +00:00
|
|
|
SCH_DIRECTIVE_LABEL_T,
|
2019-06-17 21:11:41 +00:00
|
|
|
SCH_NO_CONNECT_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
SCH_SHEET_PIN_T,
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL_T,
|
2023-11-25 12:38:24 +00:00
|
|
|
SCH_FIELD_T, // Will be hidden
|
2022-08-20 09:27:35 +00:00
|
|
|
SCH_BITMAP_T
|
2019-06-17 21:11:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
|
2019-04-23 13:06:37 +00:00
|
|
|
{
|
2023-06-07 14:30:56 +00:00
|
|
|
SCH_SCREEN* screen = m_frame->GetScreen();
|
|
|
|
std::deque<EDA_ITEM*> items = m_selectionTool->RequestSelection( deletableItems ).GetItems();
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> pts;
|
2023-07-09 12:40:06 +00:00
|
|
|
bool updateHierarchy = false;
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
if( items.empty() )
|
2019-04-23 13:06:37 +00:00
|
|
|
return 0;
|
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
// Don't leave a freed pointer in the selection
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2019-05-04 13:02:05 +00:00
|
|
|
for( EDA_ITEM* item : items )
|
2019-06-19 18:30:11 +00:00
|
|
|
item->ClearFlags( STRUCT_DELETED );
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2019-06-19 18:30:11 +00:00
|
|
|
for( EDA_ITEM* item : items )
|
|
|
|
{
|
2019-08-27 10:03:49 +00:00
|
|
|
SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item );
|
|
|
|
|
2019-10-18 04:29:26 +00:00
|
|
|
if( !sch_item )
|
|
|
|
continue;
|
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
if( sch_item->IsConnectable() )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> tmp_pts = sch_item->GetConnectionPoints();
|
2020-09-08 13:27:13 +00:00
|
|
|
pts.insert( pts.end(), tmp_pts.begin(), tmp_pts.end() );
|
|
|
|
}
|
|
|
|
|
2019-08-27 10:03:49 +00:00
|
|
|
if( sch_item->Type() == SCH_JUNCTION_T )
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
2019-08-27 10:03:49 +00:00
|
|
|
sch_item->SetFlags( STRUCT_DELETED );
|
2019-06-19 18:30:11 +00:00
|
|
|
// clean up junctions at the end
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
2021-01-12 23:55:46 +00:00
|
|
|
else if( sch_item->Type() == SCH_SHEET_PIN_T )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PIN* pin = (SCH_SHEET_PIN*) sch_item;
|
|
|
|
SCH_SHEET* sheet = pin->GetParent();
|
|
|
|
|
|
|
|
if( !alg::contains( items, sheet ) )
|
|
|
|
{
|
2023-07-09 12:40:06 +00:00
|
|
|
commit.Modify( sheet, m_frame->GetScreen() );
|
2021-01-12 23:55:46 +00:00
|
|
|
sheet->RemovePin( pin );
|
|
|
|
}
|
|
|
|
}
|
2022-04-11 18:03:17 +00:00
|
|
|
else if( sch_item->Type() == SCH_FIELD_T )
|
|
|
|
{
|
2024-01-15 17:29:55 +00:00
|
|
|
// Hide field
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Modify( item, m_frame->GetScreen() );
|
2022-04-11 18:03:17 +00:00
|
|
|
static_cast<SCH_FIELD*>( sch_item )->SetVisible( false );
|
|
|
|
}
|
2023-11-25 12:38:24 +00:00
|
|
|
else if( sch_item->Type() == SCH_TABLECELL_T )
|
|
|
|
{
|
2024-01-15 17:29:55 +00:00
|
|
|
// Clear contents of table cell
|
2023-11-25 12:38:24 +00:00
|
|
|
commit.Modify( item, m_frame->GetScreen() );
|
|
|
|
static_cast<SCH_TABLECELL*>( sch_item )->SetText( wxEmptyString );
|
|
|
|
}
|
2024-04-25 14:24:46 +00:00
|
|
|
else if( sch_item->Type() == SCH_RULE_AREA_T )
|
|
|
|
{
|
|
|
|
sch_item->SetFlags( STRUCT_DELETED );
|
|
|
|
commit.Remove( item, m_frame->GetScreen() );
|
|
|
|
}
|
2019-05-04 13:02:05 +00:00
|
|
|
else
|
|
|
|
{
|
2019-08-27 10:03:49 +00:00
|
|
|
sch_item->SetFlags( STRUCT_DELETED );
|
2023-07-09 12:40:06 +00:00
|
|
|
commit.Remove( item, m_frame->GetScreen() );
|
|
|
|
updateHierarchy |= ( sch_item->Type() == SCH_SHEET_T );
|
2019-05-04 13:02:05 +00:00
|
|
|
}
|
2019-04-23 13:06:37 +00:00
|
|
|
}
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
for( const VECTOR2I& point : pts )
|
2019-06-19 18:30:11 +00:00
|
|
|
{
|
|
|
|
SCH_ITEM* junction = screen->GetItem( point, 0, SCH_JUNCTION_T );
|
2019-08-27 10:03:49 +00:00
|
|
|
|
|
|
|
if( !junction )
|
|
|
|
continue;
|
|
|
|
|
2021-11-04 12:38:15 +00:00
|
|
|
if( junction->HasFlag( STRUCT_DELETED ) || !screen->IsExplicitJunction( point ) )
|
2023-06-09 16:24:49 +00:00
|
|
|
m_frame->DeleteJunction( &commit, junction );
|
2019-06-19 18:30:11 +00:00
|
|
|
}
|
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Push( _( "Delete" ) );
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2023-07-09 12:40:06 +00:00
|
|
|
if( updateHierarchy )
|
|
|
|
m_frame->UpdateHierarchyNavigator();
|
|
|
|
|
2019-04-23 13:06:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-17 21:11:41 +00:00
|
|
|
#define HITTEST_THRESHOLD_PIXELS 5
|
|
|
|
|
|
|
|
|
2023-10-10 14:43:45 +00:00
|
|
|
int SCH_EDIT_TOOL::InteractiveDelete( const TOOL_EVENT& aEvent )
|
2019-04-28 16:36:31 +00:00
|
|
|
{
|
2019-07-15 23:44:01 +00:00
|
|
|
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
|
2019-04-28 16:36:31 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-06-17 21:11:41 +00:00
|
|
|
m_pickerItem = nullptr;
|
|
|
|
|
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 );
|
2021-01-31 14:50:19 +00:00
|
|
|
picker->SetSnapping( false );
|
2019-04-28 16:36:31 +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-06-25 13:01:22 +00:00
|
|
|
{
|
2020-11-22 22:21:41 +00:00
|
|
|
if( m_pickerItem )
|
2019-07-15 23:44:01 +00:00
|
|
|
{
|
2020-11-22 22:21:41 +00:00
|
|
|
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-04-28 16:36:31 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
return true;
|
|
|
|
} );
|
2019-06-25 13:01:22 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
picker->SetMotionHandler(
|
2020-11-22 22:21:41 +00:00
|
|
|
[this]( const VECTOR2D& aPos )
|
|
|
|
{
|
|
|
|
EE_COLLECTOR collector;
|
|
|
|
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
2022-01-01 06:04:08 +00:00
|
|
|
collector.Collect( m_frame->GetScreen(), deletableItems, aPos );
|
2019-05-05 10:33:34 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
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 );
|
2019-06-25 13:01:22 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
m_pickerItem = item;
|
2019-04-28 16:36:31 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( m_pickerItem )
|
|
|
|
selectionTool->BrightenItem( m_pickerItem );
|
|
|
|
}
|
|
|
|
} );
|
2019-04-28 16:36:31 +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-06-17 21:11:41 +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-04-28 16:36:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
void SCH_EDIT_TOOL::editFieldText( SCH_FIELD* aField )
|
2019-06-19 10:31:21 +00:00
|
|
|
{
|
2023-06-09 21:41:33 +00:00
|
|
|
KICAD_T parentType = aField->GetParent() ? aField->GetParent()->Type() : SCHEMATIC_T;
|
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2023-02-07 12:05:41 +00:00
|
|
|
|
2021-03-19 20:27:30 +00:00
|
|
|
// Save old symbol in undo list if not already in edit, or moving.
|
2019-06-19 10:31:21 +00:00
|
|
|
if( aField->GetEditFlags() == 0 ) // i.e. not edited, or moved
|
2023-06-07 14:30:56 +00:00
|
|
|
commit.Modify( aField, m_frame->GetScreen() );
|
2019-06-19 10:31:21 +00:00
|
|
|
|
2023-02-07 12:05:41 +00:00
|
|
|
if( parentType == SCH_SYMBOL_T && aField->GetId() == REFERENCE_FIELD )
|
|
|
|
static_cast<SCH_ITEM*>( aField->GetParent() )->SetConnectivityDirty();
|
|
|
|
|
2021-07-19 13:43:34 +00:00
|
|
|
wxString caption;
|
|
|
|
|
|
|
|
// Use title caps for mandatory fields. "Edit Sheet name Field" looks dorky.
|
2024-04-12 21:00:41 +00:00
|
|
|
if( parentType == SCH_SYMBOL_T && aField->IsMandatory() )
|
2022-05-13 09:39:16 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
wxString translated_fieldname = TEMPLATE_FIELDNAME::GetDefaultFieldName( aField->GetId(),
|
|
|
|
DO_TRANSLATE );
|
2022-05-13 09:39:16 +00:00
|
|
|
caption.Printf( _( "Edit %s Field" ), TitleCaps( translated_fieldname ) );
|
|
|
|
}
|
2024-04-12 21:00:41 +00:00
|
|
|
else if( parentType == SCH_SHEET_T && aField->IsMandatory() )
|
2021-07-19 13:43:34 +00:00
|
|
|
caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) );
|
|
|
|
else
|
|
|
|
caption.Printf( _( "Edit '%s' Field" ), aField->GetName() );
|
2019-06-19 10:31:21 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
DIALOG_FIELD_PROPERTIES dlg( m_frame, caption, aField );
|
2019-06-19 10:31:21 +00:00
|
|
|
|
2019-07-20 23:31:16 +00:00
|
|
|
// The footprint field dialog can invoke a KIWAY_PLAYER so we must use a quasi-modal
|
2019-07-28 05:33:34 +00:00
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
2019-06-19 10:31:21 +00:00
|
|
|
return;
|
|
|
|
|
2023-06-07 22:45:06 +00:00
|
|
|
dlg.UpdateField( &commit, aField, &m_frame->GetCurrentSheet() );
|
2019-06-19 10:31:21 +00:00
|
|
|
|
2021-07-19 13:43:34 +00:00
|
|
|
if( m_frame->eeconfig()->m_AutoplaceFields.enable || parentType == SCH_SHEET_T )
|
2020-03-06 20:02:58 +00:00
|
|
|
static_cast<SCH_ITEM*>( aField->GetParent() )->AutoAutoplaceFields( m_frame->GetScreen() );
|
2019-06-19 10:31:21 +00:00
|
|
|
|
2023-06-07 14:30:56 +00:00
|
|
|
if( !commit.Empty() )
|
2024-03-09 13:50:26 +00:00
|
|
|
commit.Push( caption );
|
2019-06-19 10:31:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-27 23:50:35 +00:00
|
|
|
int SCH_EDIT_TOOL::EditField( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2024-04-09 12:39:59 +00:00
|
|
|
EE_SELECTION sel = m_selectionTool->RequestSelection( { SCH_FIELD_T, SCH_SYMBOL_T } );
|
2019-04-27 23:50:35 +00:00
|
|
|
|
2022-08-21 11:26:47 +00:00
|
|
|
if( sel.Size() != 1 )
|
2019-04-27 23:50:35 +00:00
|
|
|
return 0;
|
|
|
|
|
2022-08-21 11:26:47 +00:00
|
|
|
bool clearSelection = sel.IsHover();
|
|
|
|
EDA_ITEM* item = sel.Front();
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2024-04-09 12:39:59 +00:00
|
|
|
if( item->Type() == SCH_FIELD_T )
|
|
|
|
{
|
|
|
|
SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
|
|
|
|
|
|
|
|
if( ( aEvent.IsAction( &EE_ACTIONS::editReference ) && field->GetId() != REFERENCE_FIELD )
|
|
|
|
|| ( aEvent.IsAction( &EE_ACTIONS::editValue ) && field->GetId() != VALUE_FIELD )
|
|
|
|
|| ( aEvent.IsAction( &EE_ACTIONS::editFootprint ) && field->GetId() != FOOTPRINT_FIELD ) )
|
|
|
|
{
|
|
|
|
item = field->GetParentSymbol();
|
|
|
|
m_selectionTool->ClearSelection( true );
|
|
|
|
m_selectionTool->AddItemToSel( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
2019-04-27 23:50:35 +00:00
|
|
|
{
|
2021-09-21 15:43:53 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2019-04-27 23:50:35 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::editReference ) )
|
2024-01-19 20:51:44 +00:00
|
|
|
{
|
2021-03-19 20:27:30 +00:00
|
|
|
editFieldText( symbol->GetField( REFERENCE_FIELD ) );
|
2024-01-19 20:51:44 +00:00
|
|
|
}
|
2019-05-10 17:19:48 +00:00
|
|
|
else if( aEvent.IsAction( &EE_ACTIONS::editValue ) )
|
2024-01-19 20:51:44 +00:00
|
|
|
{
|
2021-03-19 20:27:30 +00:00
|
|
|
editFieldText( symbol->GetField( VALUE_FIELD ) );
|
2024-01-19 20:51:44 +00:00
|
|
|
}
|
2019-05-10 17:19:48 +00:00
|
|
|
else if( aEvent.IsAction( &EE_ACTIONS::editFootprint ) )
|
2024-01-19 20:51:44 +00:00
|
|
|
{
|
|
|
|
if( !symbol->IsPower() )
|
|
|
|
editFieldText( symbol->GetField( FOOTPRINT_FIELD ) );
|
|
|
|
}
|
2019-04-27 23:50:35 +00:00
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_FIELD_T )
|
|
|
|
{
|
2021-09-21 15:43:53 +00:00
|
|
|
SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
|
|
|
|
|
|
|
|
editFieldText( field );
|
|
|
|
|
|
|
|
if( !field->IsVisible() )
|
|
|
|
clearSelection = true;
|
2019-04-27 23:50:35 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 15:43:53 +00:00
|
|
|
if( clearSelection )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2020-05-06 18:00:55 +00:00
|
|
|
|
2019-04-27 23:50:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 23:34:43 +00:00
|
|
|
int SCH_EDIT_TOOL::AutoplaceFields( const TOOL_EVENT& aEvent )
|
2019-04-27 23:50:35 +00:00
|
|
|
{
|
2023-06-09 21:41:33 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( RotatableItems );
|
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
SCH_ITEM* head = static_cast<SCH_ITEM*>( selection.Front() );
|
|
|
|
bool moving = head && head->IsMoving();
|
2019-04-27 23:50:35 +00:00
|
|
|
|
2019-04-28 23:34:43 +00:00
|
|
|
if( selection.Empty() )
|
|
|
|
return 0;
|
|
|
|
|
2022-05-02 19:10:40 +00:00
|
|
|
std::vector<SCH_ITEM*> autoplaceItems;
|
2021-11-29 20:48:16 +00:00
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
|
2021-07-29 15:51:12 +00:00
|
|
|
{
|
2022-05-02 19:10:40 +00:00
|
|
|
SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.GetItem( ii ) );
|
|
|
|
|
|
|
|
if( item->IsType( EE_COLLECTOR::FieldOwners ) )
|
|
|
|
autoplaceItems.push_back( item );
|
|
|
|
else if( item->GetParent() && item->GetParent()->IsType( EE_COLLECTOR::FieldOwners ) )
|
|
|
|
autoplaceItems.push_back( static_cast<SCH_ITEM*>( item->GetParent() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( SCH_ITEM* sch_item : autoplaceItems )
|
|
|
|
{
|
2021-11-29 20:48:16 +00:00
|
|
|
if( !moving && !sch_item->IsNew() )
|
2023-06-07 14:30:56 +00:00
|
|
|
commit.Modify( sch_item, m_frame->GetScreen() );
|
2021-11-29 20:48:16 +00:00
|
|
|
|
2022-05-02 19:10:40 +00:00
|
|
|
sch_item->AutoplaceFields( m_frame->GetScreen(), /* aManual */ true );
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2021-07-29 15:51:12 +00:00
|
|
|
updateItem( sch_item, true );
|
|
|
|
}
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2021-11-29 20:48:16 +00:00
|
|
|
if( moving )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2021-11-29 20:48:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-07 14:30:56 +00:00
|
|
|
if( !commit.Empty() )
|
|
|
|
commit.Push( _( "Autoplace Fields" ) );
|
|
|
|
|
2021-11-29 20:48:16 +00:00
|
|
|
if( selection.IsHover() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2021-11-29 20:48:16 +00:00
|
|
|
}
|
2020-05-06 18:00:55 +00:00
|
|
|
|
2019-04-28 23:34:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-13 17:51:26 +00:00
|
|
|
int SCH_EDIT_TOOL::ChangeSymbols( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* selectedSymbol = nullptr;
|
2022-08-20 09:27:35 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_SYMBOL_T } );
|
2020-08-13 17:51:26 +00:00
|
|
|
|
|
|
|
if( !selection.Empty() )
|
2021-06-10 14:10:55 +00:00
|
|
|
selectedSymbol = dynamic_cast<SCH_SYMBOL*>( selection.Front() );
|
2020-08-13 17:51:26 +00:00
|
|
|
|
|
|
|
DIALOG_CHANGE_SYMBOLS::MODE mode = DIALOG_CHANGE_SYMBOLS::MODE::UPDATE;
|
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::changeSymbol )
|
|
|
|
|| aEvent.IsAction( &EE_ACTIONS::changeSymbols ) )
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
2020-08-13 17:51:26 +00:00
|
|
|
mode = DIALOG_CHANGE_SYMBOLS::MODE::CHANGE;
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
2020-08-13 17:51:26 +00:00
|
|
|
|
|
|
|
DIALOG_CHANGE_SYMBOLS dlg( m_frame, selectedSymbol, mode );
|
|
|
|
|
2024-03-10 12:18:27 +00:00
|
|
|
// QuasiModal required to invoke symbol browser
|
2020-12-17 23:51:24 +00:00
|
|
|
dlg.ShowQuasiModal();
|
2020-08-13 17:51:26 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
int SCH_EDIT_TOOL::ChangeBodyStyle( const TOOL_EVENT& aEvent )
|
2019-05-01 21:50:11 +00:00
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_SYMBOL_T } );
|
2019-05-01 21:50:11 +00:00
|
|
|
|
|
|
|
if( selection.Empty() )
|
|
|
|
return 0;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = (SCH_SYMBOL*) selection.Front();
|
2019-05-01 21:50:11 +00:00
|
|
|
|
2019-06-01 19:48:01 +00:00
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::showDeMorganStandard )
|
2024-04-06 13:14:44 +00:00
|
|
|
&& symbol->GetBodyStyle() == BODY_STYLE::BASE )
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
2019-06-01 19:48:01 +00:00
|
|
|
return 0;
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
2019-06-01 19:48:01 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::showDeMorganAlternate )
|
2024-04-06 13:14:44 +00:00
|
|
|
&& symbol->GetBodyStyle() == BODY_STYLE::DEMORGAN )
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
2019-06-01 19:48:01 +00:00
|
|
|
return 0;
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
2019-06-01 19:48:01 +00:00
|
|
|
|
2024-01-26 22:29:32 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
|
2021-03-19 20:27:30 +00:00
|
|
|
if( !symbol->IsNew() )
|
2024-01-26 22:29:32 +00:00
|
|
|
commit.Modify( symbol, m_frame->GetScreen() );
|
2019-05-01 21:50:11 +00:00
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
m_frame->FlipBodyStyle( symbol );
|
2019-05-01 21:50:11 +00:00
|
|
|
|
2021-03-19 20:27:30 +00:00
|
|
|
if( symbol->IsNew() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2019-06-01 19:48:01 +00:00
|
|
|
|
2024-01-26 22:29:32 +00:00
|
|
|
if( !commit.Empty() )
|
2024-02-05 11:05:31 +00:00
|
|
|
commit.Push( _( "Change Body Style" ) );
|
2024-01-26 22:29:32 +00:00
|
|
|
|
2020-05-06 18:00:55 +00:00
|
|
|
if( selection.IsHover() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2020-05-06 18:00:55 +00:00
|
|
|
|
2019-05-01 21:50:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 23:34:43 +00:00
|
|
|
int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2024-03-12 00:48:58 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection();
|
2021-09-21 15:43:53 +00:00
|
|
|
bool clearSelection = selection.IsHover();
|
2019-04-28 23:34:43 +00:00
|
|
|
|
|
|
|
if( selection.Empty() )
|
2020-04-20 23:24:29 +00:00
|
|
|
{
|
2021-02-22 16:37:43 +00:00
|
|
|
if( getView()->IsLayerVisible( LAYER_SCHEMATIC_DRAWINGSHEET ) )
|
2020-05-02 23:06:43 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_PROXY_VIEW_ITEM* ds = m_frame->GetCanvas()->GetView()->GetDrawingSheet();
|
|
|
|
VECTOR2D cursorPos = getViewControls()->GetCursorPosition( false );
|
2020-05-02 23:06:43 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
if( ds && ds->HitTestDrawingSheetItems( getView(), cursorPos ) )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::pageSettings );
|
2020-05-02 23:06:43 +00:00
|
|
|
}
|
|
|
|
|
2019-04-28 23:34:43 +00:00
|
|
|
return 0;
|
2020-04-20 23:24:29 +00:00
|
|
|
}
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2022-03-17 19:13:17 +00:00
|
|
|
EDA_ITEM* curr_item = selection.Front();
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2022-03-17 19:13:17 +00:00
|
|
|
switch( curr_item->Type() )
|
2020-05-13 10:52:44 +00:00
|
|
|
{
|
|
|
|
case SCH_LINE_T:
|
2020-06-19 11:48:00 +00:00
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
2020-06-24 17:35:33 +00:00
|
|
|
case SCH_JUNCTION_T:
|
2024-02-03 13:43:41 +00:00
|
|
|
case SCH_TABLECELL_T:
|
2020-06-24 17:35:33 +00:00
|
|
|
break;
|
|
|
|
|
2020-05-13 10:52:44 +00:00
|
|
|
default:
|
|
|
|
if( selection.Size() > 1 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-03-17 19:13:17 +00:00
|
|
|
switch( curr_item->Type() )
|
2019-04-27 23:50:35 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
case SCH_SYMBOL_T:
|
2019-06-19 10:31:21 +00:00
|
|
|
{
|
2022-12-20 13:23:02 +00:00
|
|
|
int retval;
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( curr_item );
|
|
|
|
|
|
|
|
// This needs to be scoped so the dialog destructor removes blocking status
|
|
|
|
// before we launch the next dialog.
|
|
|
|
{
|
|
|
|
DIALOG_SYMBOL_PROPERTIES symbolPropsDialog( m_frame, symbol );
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
retval = symbolPropsDialog.ShowQuasiModal();
|
|
|
|
}
|
2020-09-02 00:37:28 +00:00
|
|
|
|
|
|
|
if( retval == SYMBOL_PROPS_EDIT_OK )
|
2019-06-19 10:31:21 +00:00
|
|
|
{
|
2020-04-12 23:09:17 +00:00
|
|
|
if( m_frame->eeconfig()->m_AutoplaceFields.enable )
|
2021-03-19 20:27:30 +00:00
|
|
|
symbol->AutoAutoplaceFields( m_frame->GetScreen() );
|
2019-06-19 10:31:21 +00:00
|
|
|
|
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
2020-09-02 00:37:28 +00:00
|
|
|
else if( retval == SYMBOL_PROPS_EDIT_SCHEMATIC_SYMBOL )
|
|
|
|
{
|
2024-05-08 17:19:24 +00:00
|
|
|
if( KIWAY_PLAYER* frame = m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, true ) )
|
|
|
|
{
|
|
|
|
SYMBOL_EDIT_FRAME* editor = static_cast<SYMBOL_EDIT_FRAME*>( frame );
|
2023-08-07 14:19:37 +00:00
|
|
|
|
2024-05-08 17:19:24 +00:00
|
|
|
if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() )
|
|
|
|
blocking_win->Close( true );
|
2022-07-12 21:44:53 +00:00
|
|
|
|
2024-05-08 17:19:24 +00:00
|
|
|
// The broken library symbol link indicator cannot be edited.
|
|
|
|
if( symbol->IsMissingLibSymbol() )
|
|
|
|
return 0;
|
2022-09-02 19:48:10 +00:00
|
|
|
|
2024-05-08 17:19:24 +00:00
|
|
|
editor->LoadSymbolFromSchematic( symbol );
|
|
|
|
editor->Show( true );
|
|
|
|
editor->Raise();
|
|
|
|
}
|
2020-09-02 00:37:28 +00:00
|
|
|
}
|
|
|
|
else if( retval == SYMBOL_PROPS_EDIT_LIBRARY_SYMBOL )
|
|
|
|
{
|
2024-05-08 17:19:24 +00:00
|
|
|
if( KIWAY_PLAYER* frame = m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, true ) )
|
|
|
|
{
|
|
|
|
SYMBOL_EDIT_FRAME* editor = static_cast<SYMBOL_EDIT_FRAME*>( frame );
|
2022-07-12 21:44:53 +00:00
|
|
|
|
2024-05-08 17:19:24 +00:00
|
|
|
if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() )
|
|
|
|
blocking_win->Close( true );
|
2020-09-02 00:37:28 +00:00
|
|
|
|
2024-05-08 17:19:24 +00:00
|
|
|
editor->LoadSymbol( symbol->GetLibId(), symbol->GetUnit(), symbol->GetBodyStyle() );
|
|
|
|
editor->Show( true );
|
|
|
|
editor->Raise();
|
|
|
|
}
|
2020-09-02 00:37:28 +00:00
|
|
|
}
|
|
|
|
else if( retval == SYMBOL_PROPS_WANT_UPDATE_SYMBOL )
|
|
|
|
{
|
2021-03-19 20:27:30 +00:00
|
|
|
DIALOG_CHANGE_SYMBOLS dlg( m_frame, symbol, DIALOG_CHANGE_SYMBOLS::MODE::UPDATE );
|
2020-12-17 23:51:24 +00:00
|
|
|
dlg.ShowQuasiModal();
|
2020-09-02 00:37:28 +00:00
|
|
|
}
|
|
|
|
else if( retval == SYMBOL_PROPS_WANT_EXCHANGE_SYMBOL )
|
|
|
|
{
|
2021-03-19 20:27:30 +00:00
|
|
|
DIALOG_CHANGE_SYMBOLS dlg( m_frame, symbol, DIALOG_CHANGE_SYMBOLS::MODE::CHANGE );
|
2020-12-17 23:51:24 +00:00
|
|
|
dlg.ShowQuasiModal();
|
2020-09-02 00:37:28 +00:00
|
|
|
}
|
2023-08-07 17:35:51 +00:00
|
|
|
|
2019-04-27 23:50:35 +00:00
|
|
|
break;
|
2023-08-07 17:35:51 +00:00
|
|
|
}
|
2019-04-27 23:50:35 +00:00
|
|
|
|
|
|
|
case SCH_SHEET_T:
|
|
|
|
{
|
2022-03-17 19:13:17 +00:00
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( curr_item );
|
2020-03-12 13:56:44 +00:00
|
|
|
bool doClearAnnotation;
|
|
|
|
bool doRefresh = false;
|
2024-03-17 13:02:07 +00:00
|
|
|
bool updateHierarchyNavigator = false;
|
2019-04-27 23:50:35 +00:00
|
|
|
|
2020-10-05 12:24:21 +00:00
|
|
|
// Keep track of existing sheet paths. EditSheet() can modify this list.
|
|
|
|
// Note that we use the validity checking/repairing version here just to make sure
|
|
|
|
// we've got a valid hierarchy to begin with.
|
2022-12-25 16:04:45 +00:00
|
|
|
SCH_SHEET_LIST originalHierarchy( &m_frame->Schematic().Root(), true );
|
2020-10-05 12:24:21 +00:00
|
|
|
|
|
|
|
doRefresh = m_frame->EditSheetProperties( sheet, &m_frame->GetCurrentSheet(),
|
2024-03-17 13:02:07 +00:00
|
|
|
&doClearAnnotation, &updateHierarchyNavigator );
|
2019-04-27 23:50:35 +00:00
|
|
|
|
2020-05-13 10:52:44 +00:00
|
|
|
// If the sheet file is changed and new sheet contents are loaded then we have to
|
|
|
|
// clear the annotations on the new content (as it may have been set from some other
|
|
|
|
// sheet path reference)
|
|
|
|
if( doClearAnnotation )
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SCREENS screensList( &m_frame->Schematic().Root() );
|
2022-12-25 16:04:45 +00:00
|
|
|
|
2019-04-27 23:50:35 +00:00
|
|
|
// We clear annotation of new sheet paths here:
|
2022-12-25 16:04:45 +00:00
|
|
|
screensList.ClearAnnotationOfNewSheetPaths( originalHierarchy );
|
|
|
|
|
2020-05-13 10:52:44 +00:00
|
|
|
// Clear annotation of g_CurrentSheet itself, because its sheetpath is not a new
|
2021-03-19 20:27:30 +00:00
|
|
|
// path, but symbols managed by its sheet path must have their annotation cleared
|
|
|
|
// because they are new:
|
2022-04-13 22:37:42 +00:00
|
|
|
sheet->GetScreen()->ClearAnnotation( &m_frame->GetCurrentSheet(), false );
|
2019-04-27 23:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( doRefresh )
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
2024-03-17 13:02:07 +00:00
|
|
|
|
|
|
|
if( updateHierarchyNavigator )
|
2019-10-24 17:07:01 +00:00
|
|
|
m_frame->UpdateHierarchyNavigator();
|
2019-04-27 23:50:35 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_SHEET_PIN_T:
|
2019-06-19 10:31:21 +00:00
|
|
|
{
|
2022-03-17 19:13:17 +00:00
|
|
|
SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( curr_item );
|
2020-10-29 22:46:33 +00:00
|
|
|
DIALOG_SHEET_PIN_PROPERTIES dlg( m_frame, pin );
|
2019-06-19 10:31:21 +00:00
|
|
|
|
2020-10-29 22:46:33 +00:00
|
|
|
// QuasiModal required for help dialog
|
2024-02-03 13:43:41 +00:00
|
|
|
dlg.ShowQuasiModal();
|
2019-04-27 23:50:35 +00:00
|
|
|
break;
|
2023-08-07 17:35:51 +00:00
|
|
|
}
|
2019-04-27 23:50:35 +00:00
|
|
|
|
|
|
|
case SCH_TEXT_T:
|
2022-01-25 22:33:37 +00:00
|
|
|
case SCH_TEXTBOX_T:
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
2022-03-17 19:13:17 +00:00
|
|
|
DIALOG_TEXT_PROPERTIES dlg( m_frame, static_cast<SCH_ITEM*>( curr_item ) );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2023-05-24 11:08:52 +00:00
|
|
|
// QuasiModal required for syntax help and Scintilla auto-complete
|
2024-02-03 13:43:41 +00:00
|
|
|
dlg.ShowQuasiModal();
|
2023-11-25 12:38:24 +00:00
|
|
|
break;
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
2023-11-25 12:38:24 +00:00
|
|
|
|
|
|
|
case SCH_TABLECELL_T:
|
2024-02-03 13:43:41 +00:00
|
|
|
if( SELECTION_CONDITIONS::OnlyTypes( { SCH_TABLECELL_T } )( selection ) )
|
|
|
|
{
|
|
|
|
std::vector<SCH_TABLECELL*> cells;
|
2023-11-25 12:38:24 +00:00
|
|
|
|
2024-02-03 13:43:41 +00:00
|
|
|
for( EDA_ITEM* item : selection.Items() )
|
|
|
|
cells.push_back( static_cast<SCH_TABLECELL*>( item ) );
|
|
|
|
|
|
|
|
DIALOG_TABLECELL_PROPERTIES dlg( m_frame, cells );
|
|
|
|
|
|
|
|
dlg.ShowModal();
|
|
|
|
|
|
|
|
if( dlg.GetReturnValue() == DIALOG_TABLECELL_PROPERTIES::TABLECELL_PROPS_EDIT_TABLE )
|
|
|
|
{
|
|
|
|
SCH_TABLE* table = static_cast<SCH_TABLE*>( cells[0]->GetParent() );
|
|
|
|
DIALOG_TABLE_PROPERTIES tableDlg( m_frame, table );
|
|
|
|
|
2024-03-10 12:18:27 +00:00
|
|
|
tableDlg.ShowModal();
|
2024-02-03 13:43:41 +00:00
|
|
|
}
|
|
|
|
}
|
2023-11-25 12:38:24 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
break;
|
|
|
|
|
2024-03-10 12:18:27 +00:00
|
|
|
case SCH_TABLE_T:
|
|
|
|
{
|
|
|
|
DIALOG_TABLE_PROPERTIES dlg( m_frame, static_cast<SCH_TABLE*>( curr_item ) );
|
|
|
|
|
|
|
|
// QuasiModal required for Scintilla auto-complete
|
|
|
|
dlg.ShowQuasiModal();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-04-27 23:50:35 +00:00
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
2022-01-24 13:40:39 +00:00
|
|
|
case SCH_DIRECTIVE_LABEL_T:
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
2022-03-17 19:13:17 +00:00
|
|
|
DIALOG_LABEL_PROPERTIES dlg( m_frame, static_cast<SCH_LABEL_BASE*>( curr_item ) );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2024-03-10 12:18:27 +00:00
|
|
|
// QuasiModal for syntax help and Scintilla auto-complete
|
2024-02-03 13:43:41 +00:00
|
|
|
dlg.ShowQuasiModal();
|
2019-04-27 23:50:35 +00:00
|
|
|
break;
|
2023-08-07 17:35:51 +00:00
|
|
|
}
|
2019-04-27 23:50:35 +00:00
|
|
|
|
|
|
|
case SCH_FIELD_T:
|
2021-09-21 15:43:53 +00:00
|
|
|
{
|
2022-03-17 19:13:17 +00:00
|
|
|
SCH_FIELD* field = static_cast<SCH_FIELD*>( curr_item );
|
2021-09-21 15:43:53 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
editFieldText( field );
|
2021-09-21 15:43:53 +00:00
|
|
|
|
|
|
|
if( !field->IsVisible() )
|
|
|
|
clearSelection = true;
|
2023-08-07 17:35:51 +00:00
|
|
|
|
2019-04-27 23:50:35 +00:00
|
|
|
break;
|
2023-08-07 17:35:51 +00:00
|
|
|
}
|
2019-04-27 23:50:35 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
case SCH_SHAPE_T:
|
|
|
|
{
|
2022-03-17 19:13:17 +00:00
|
|
|
DIALOG_SHAPE_PROPERTIES dlg( m_frame, static_cast<SCH_SHAPE*>( curr_item ) );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-02-03 13:43:41 +00:00
|
|
|
dlg.ShowModal();
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
2023-08-07 17:35:51 +00:00
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2019-04-27 23:50:35 +00:00
|
|
|
case SCH_BITMAP_T:
|
2019-06-19 10:31:21 +00:00
|
|
|
{
|
2022-07-07 14:17:21 +00:00
|
|
|
SCH_BITMAP* bitmap = static_cast<SCH_BITMAP*>( curr_item );
|
|
|
|
DIALOG_IMAGE_PROPERTIES dlg( m_frame, bitmap );
|
2019-06-19 10:31:21 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
2019-04-27 23:50:35 +00:00
|
|
|
{
|
|
|
|
// The bitmap is cached in Opengl: clear the cache in case it has become invalid
|
|
|
|
getView()->RecacheAllItems();
|
|
|
|
}
|
2023-08-07 17:35:51 +00:00
|
|
|
|
2019-04-27 23:50:35 +00:00
|
|
|
break;
|
2023-08-07 17:35:51 +00:00
|
|
|
}
|
2019-04-27 23:50:35 +00:00
|
|
|
|
2024-04-25 14:24:46 +00:00
|
|
|
case SCH_RULE_AREA_T:
|
|
|
|
{
|
|
|
|
DIALOG_SHAPE_PROPERTIES dlg( m_frame, static_cast<SCH_SHAPE*>( curr_item ) );
|
|
|
|
dlg.SetTitle( _( "Rule Area Properties" ) );
|
|
|
|
|
|
|
|
dlg.ShowModal();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-04-27 23:50:35 +00:00
|
|
|
case SCH_LINE_T:
|
2020-06-19 11:48:00 +00:00
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
2022-03-16 13:43:19 +00:00
|
|
|
case SCH_JUNCTION_T:
|
2024-02-03 13:43:41 +00:00
|
|
|
if( SELECTION_CONDITIONS::OnlyTypes( { SCH_ITEM_LOCATE_GRAPHIC_LINE_T } )( selection ) )
|
2019-12-31 04:05:51 +00:00
|
|
|
{
|
2022-03-16 13:43:19 +00:00
|
|
|
std::deque<SCH_LINE*> lines;
|
2020-01-03 19:30:29 +00:00
|
|
|
|
2022-03-16 13:43:19 +00:00
|
|
|
for( EDA_ITEM* selItem : selection.Items() )
|
|
|
|
lines.push_back( static_cast<SCH_LINE*>( selItem ) );
|
2019-12-31 04:05:51 +00:00
|
|
|
|
2022-03-16 13:43:19 +00:00
|
|
|
DIALOG_LINE_PROPERTIES dlg( m_frame, lines );
|
2019-06-19 10:31:21 +00:00
|
|
|
|
2024-02-03 13:43:41 +00:00
|
|
|
dlg.ShowModal();
|
2019-06-19 10:31:21 +00:00
|
|
|
}
|
2024-02-03 13:43:41 +00:00
|
|
|
else if( SELECTION_CONDITIONS::OnlyTypes( { SCH_JUNCTION_T } )( selection ) )
|
2020-06-24 17:35:33 +00:00
|
|
|
{
|
2022-03-16 13:43:19 +00:00
|
|
|
std::deque<SCH_JUNCTION*> junctions;
|
|
|
|
|
|
|
|
for( EDA_ITEM* selItem : selection.Items() )
|
|
|
|
junctions.push_back( static_cast<SCH_JUNCTION*>( selItem ) );
|
2020-06-24 17:35:33 +00:00
|
|
|
|
2022-03-16 13:43:19 +00:00
|
|
|
DIALOG_JUNCTION_PROPS dlg( m_frame, junctions );
|
2020-06-24 17:35:33 +00:00
|
|
|
|
2024-02-03 13:43:41 +00:00
|
|
|
dlg.ShowModal();
|
2020-06-24 17:35:33 +00:00
|
|
|
}
|
2024-02-03 13:43:41 +00:00
|
|
|
else if( SELECTION_CONDITIONS::OnlyTypes( { SCH_ITEM_LOCATE_WIRE_T,
|
|
|
|
SCH_ITEM_LOCATE_BUS_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
|
|
|
SCH_JUNCTION_T } )( selection ) )
|
2022-03-16 13:43:19 +00:00
|
|
|
{
|
|
|
|
std::deque<SCH_ITEM*> items;
|
2020-06-24 17:35:33 +00:00
|
|
|
|
2022-03-16 13:43:19 +00:00
|
|
|
for( EDA_ITEM* selItem : selection.Items() )
|
|
|
|
items.push_back( static_cast<SCH_ITEM*>( selItem ) );
|
|
|
|
|
|
|
|
DIALOG_WIRE_BUS_PROPERTIES dlg( m_frame, items );
|
|
|
|
|
2024-02-03 13:43:41 +00:00
|
|
|
dlg.ShowModal();
|
2022-03-16 13:43:19 +00:00
|
|
|
}
|
|
|
|
else
|
2020-06-24 17:35:33 +00:00
|
|
|
{
|
2022-03-16 13:43:19 +00:00
|
|
|
return 0;
|
2020-06-24 17:35:33 +00:00
|
|
|
}
|
2022-03-16 13:43:19 +00:00
|
|
|
|
2020-06-27 18:01:00 +00:00
|
|
|
break;
|
2020-06-24 17:35:33 +00:00
|
|
|
|
2024-03-12 00:48:58 +00:00
|
|
|
case SCH_MARKER_T:
|
|
|
|
if( SELECTION_CONDITIONS::OnlyTypes( { SCH_MARKER_T } )( selection ) )
|
|
|
|
{
|
|
|
|
EE_INSPECTION_TOOL* inspectionTool = m_toolMgr->GetTool<EE_INSPECTION_TOOL>();
|
|
|
|
|
|
|
|
if( inspectionTool )
|
|
|
|
inspectionTool->CrossProbe( static_cast<SCH_MARKER*> ( selection.Front() ) );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-04-27 23:50:35 +00:00
|
|
|
case SCH_NO_CONNECT_T:
|
2024-04-20 09:44:34 +00:00
|
|
|
case SCH_PIN_T:
|
2019-04-27 23:50:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: // Unexpected item
|
2022-03-17 19:13:17 +00:00
|
|
|
wxFAIL_MSG( wxString( "Cannot edit schematic item type " ) + curr_item->GetClass() );
|
2019-04-27 23:50:35 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 19:13:17 +00:00
|
|
|
updateItem( curr_item, true );
|
2019-04-27 23:50:35 +00:00
|
|
|
|
2021-09-21 15:43:53 +00:00
|
|
|
if( clearSelection )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-20 07:38:00 +00:00
|
|
|
|
2019-04-27 23:50:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-29 17:50:46 +00:00
|
|
|
int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-17 22:02:30 +00:00
|
|
|
KICAD_T convertTo = aEvent.Parameter<KICAD_T>();
|
2022-08-20 09:27:35 +00:00
|
|
|
EE_SELECTION selection = m_selectionTool->RequestSelection( { SCH_LABEL_LOCATE_ANY_T,
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_TEXTBOX_T } );
|
2023-08-07 17:35:51 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2019-04-29 17:50:46 +00:00
|
|
|
|
2019-05-09 15:10:53 +00:00
|
|
|
for( unsigned int i = 0; i < selection.GetSize(); ++i )
|
2019-04-29 17:50:46 +00:00
|
|
|
{
|
2023-08-07 17:35:51 +00:00
|
|
|
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( selection.GetItem( i ) );
|
2019-04-29 17:50:46 +00:00
|
|
|
|
2022-07-21 11:40:58 +00:00
|
|
|
if( item && item->Type() != convertTo )
|
2020-05-27 11:13:57 +00:00
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
EDA_TEXT* sourceText = dynamic_cast<EDA_TEXT*>( item );
|
2022-07-21 11:40:58 +00:00
|
|
|
bool selected = item->IsSelected();
|
|
|
|
SCH_ITEM* newtext = nullptr;
|
|
|
|
VECTOR2I position = item->GetPosition();
|
|
|
|
wxString txt;
|
2022-09-17 19:56:01 +00:00
|
|
|
wxString href;
|
2023-09-07 16:09:53 +00:00
|
|
|
SPIN_STYLE spinStyle = SPIN_STYLE::SPIN::RIGHT;
|
2022-07-21 11:40:58 +00:00
|
|
|
LABEL_FLAG_SHAPE shape = LABEL_FLAG_SHAPE::L_UNSPECIFIED;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
|
2020-05-27 11:13:57 +00:00
|
|
|
|
2022-07-21 11:40:58 +00:00
|
|
|
txt = UnescapeString( label->GetText() );
|
2023-09-07 16:09:53 +00:00
|
|
|
spinStyle = label->GetSpinStyle();
|
2022-07-21 11:40:58 +00:00
|
|
|
shape = label->GetShape();
|
2022-09-17 19:56:01 +00:00
|
|
|
href = label->GetHyperlink();
|
2022-07-21 11:40:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_DIRECTIVE_LABEL_T:
|
2022-06-10 12:11:42 +00:00
|
|
|
{
|
2022-07-21 11:40:58 +00:00
|
|
|
SCH_DIRECTIVE_LABEL* dirlabel = static_cast<SCH_DIRECTIVE_LABEL*>( item );
|
|
|
|
|
2022-09-22 00:05:51 +00:00
|
|
|
// a SCH_DIRECTIVE_LABEL has no text
|
|
|
|
txt = _( "<empty>" );
|
2022-07-21 11:40:58 +00:00
|
|
|
|
2023-09-07 16:09:53 +00:00
|
|
|
spinStyle = dirlabel->GetSpinStyle();
|
2022-09-17 19:56:01 +00:00
|
|
|
href = dirlabel->GetHyperlink();
|
2022-07-21 11:40:58 +00:00
|
|
|
break;
|
2022-06-10 12:11:42 +00:00
|
|
|
}
|
|
|
|
|
2022-07-21 11:40:58 +00:00
|
|
|
case SCH_TEXT_T:
|
2020-05-27 11:13:57 +00:00
|
|
|
{
|
2022-07-21 11:40:58 +00:00
|
|
|
SCH_TEXT* text = static_cast<SCH_TEXT*>( item );
|
|
|
|
|
|
|
|
txt = text->GetText();
|
2022-09-17 19:56:01 +00:00
|
|
|
href = text->GetHyperlink();
|
2022-07-21 11:40:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_TEXTBOX_T:
|
|
|
|
{
|
|
|
|
SCH_TEXTBOX* textbox = static_cast<SCH_TEXTBOX*>( item );
|
|
|
|
BOX2I bbox = textbox->GetBoundingBox();
|
|
|
|
|
2024-01-20 17:05:21 +00:00
|
|
|
bbox.SetOrigin( bbox.GetLeft() + textbox->GetMarginLeft(),
|
|
|
|
bbox.GetTop() + textbox->GetMarginTop() );
|
|
|
|
bbox.SetEnd( bbox.GetRight() - textbox->GetMarginRight(),
|
|
|
|
bbox.GetBottom() - textbox->GetMarginBottom() );
|
2022-07-21 11:40:58 +00:00
|
|
|
|
|
|
|
if( convertTo == SCH_LABEL_T
|
2022-10-17 13:19:39 +00:00
|
|
|
|| convertTo == SCH_HIER_LABEL_T
|
|
|
|
|| convertTo == SCH_GLOBAL_LABEL_T )
|
2022-07-21 11:40:58 +00:00
|
|
|
{
|
2022-10-17 13:19:39 +00:00
|
|
|
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item );
|
|
|
|
wxCHECK( text, 0 );
|
|
|
|
int textSize = text->GetTextSize().y;
|
2023-09-07 16:09:53 +00:00
|
|
|
bbox.Inflate( KiROUND( item->Schematic()->Settings().m_LabelSizeRatio * textSize ) );
|
2022-07-21 11:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
txt = textbox->GetText();
|
|
|
|
|
|
|
|
if( textbox->GetTextAngle().IsVertical() )
|
|
|
|
{
|
|
|
|
if( textbox->GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
|
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
spinStyle = SPIN_STYLE::SPIN::BOTTOM;
|
2022-07-21 11:40:58 +00:00
|
|
|
position = VECTOR2I( bbox.Centre().x, bbox.GetOrigin().y );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
spinStyle = SPIN_STYLE::SPIN::UP;
|
2022-07-21 11:40:58 +00:00
|
|
|
position = VECTOR2I( bbox.Centre().x, bbox.GetEnd().y );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( textbox->GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
|
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
spinStyle = SPIN_STYLE::SPIN::LEFT;
|
2022-07-21 11:40:58 +00:00
|
|
|
position = VECTOR2I( bbox.GetEnd().x, bbox.Centre().y );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
spinStyle = SPIN_STYLE::SPIN::RIGHT;
|
2022-07-21 11:40:58 +00:00
|
|
|
position = VECTOR2I( bbox.GetOrigin().x, bbox.Centre().y );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
position = m_frame->GetNearestGridPosition( position );
|
2022-09-17 19:56:01 +00:00
|
|
|
href = textbox->GetHyperlink();
|
2022-07-21 11:40:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( item->GetClass() );
|
|
|
|
break;
|
2020-05-27 11:13:57 +00:00
|
|
|
}
|
|
|
|
|
2022-09-17 19:56:01 +00:00
|
|
|
auto getValidNetname =
|
|
|
|
[]( const wxString& aText )
|
2022-07-21 11:40:58 +00:00
|
|
|
{
|
2022-07-24 07:33:43 +00:00
|
|
|
wxString local_txt = aText;
|
|
|
|
local_txt.Replace( "\n", "_" );
|
|
|
|
local_txt.Replace( "\r", "_" );
|
|
|
|
local_txt.Replace( "\t", "_" );
|
2022-09-17 19:56:01 +00:00
|
|
|
|
|
|
|
// Bus groups can have spaces; bus vectors and signal names cannot
|
|
|
|
if( !NET_SETTINGS::ParseBusGroup( aText, nullptr, nullptr ) )
|
|
|
|
local_txt.Replace( " ", "_" );
|
2022-07-21 11:40:58 +00:00
|
|
|
|
|
|
|
// label strings are "escaped" i.e. a '/' is replaced by "{slash}"
|
2022-09-22 00:05:51 +00:00
|
|
|
local_txt = EscapeString( local_txt, CTX_NETNAME );
|
|
|
|
|
|
|
|
if( local_txt.IsEmpty() )
|
|
|
|
return _( "<empty>" );
|
|
|
|
else
|
|
|
|
return local_txt;
|
2022-07-21 11:40:58 +00:00
|
|
|
};
|
2020-05-27 11:13:57 +00:00
|
|
|
|
|
|
|
switch( convertTo )
|
|
|
|
{
|
2022-07-21 11:40:58 +00:00
|
|
|
case SCH_LABEL_T:
|
|
|
|
{
|
2022-09-17 19:56:01 +00:00
|
|
|
SCH_LABEL_BASE* new_label = new SCH_LABEL( position, getValidNetname( txt ) );
|
2022-07-21 11:40:58 +00:00
|
|
|
|
|
|
|
new_label->SetShape( shape );
|
2023-09-07 16:09:53 +00:00
|
|
|
new_label->SetAttributes( *sourceText, false );
|
|
|
|
new_label->SetSpinStyle( spinStyle );
|
2022-09-17 19:56:01 +00:00
|
|
|
new_label->SetHyperlink( href );
|
2024-04-19 23:07:44 +00:00
|
|
|
|
|
|
|
if( item->Type() == SCH_GLOBAL_LABEL_T || item->Type() == SCH_HIER_LABEL_T )
|
|
|
|
{
|
|
|
|
if( static_cast<SCH_LABEL_BASE*>( item )->GetSpinStyle() == SPIN_STYLE::SPIN::UP )
|
|
|
|
new_label->MirrorVertically( position.y );
|
|
|
|
else if( static_cast<SCH_LABEL_BASE*>( item )->GetSpinStyle() == SPIN_STYLE::SPIN::BOTTOM )
|
|
|
|
new_label->MirrorVertically( position.y );
|
|
|
|
else if( static_cast<SCH_LABEL_BASE*>( item )->GetSpinStyle() == SPIN_STYLE::SPIN::LEFT )
|
|
|
|
new_label->MirrorHorizontally( position.x );
|
|
|
|
else if( static_cast<SCH_LABEL_BASE*>( item )->GetSpinStyle() == SPIN_STYLE::SPIN::RIGHT )
|
|
|
|
new_label->MirrorHorizontally( position.x );
|
|
|
|
}
|
|
|
|
|
2022-07-21 11:40:58 +00:00
|
|
|
newtext = new_label;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
{
|
2022-09-17 19:56:01 +00:00
|
|
|
SCH_LABEL_BASE* new_label = new SCH_GLOBALLABEL( position, getValidNetname( txt ) );
|
2022-07-21 11:40:58 +00:00
|
|
|
|
|
|
|
new_label->SetShape( shape );
|
2023-09-07 16:09:53 +00:00
|
|
|
new_label->SetAttributes( *sourceText, false );
|
|
|
|
new_label->SetSpinStyle( spinStyle );
|
2022-09-17 19:56:01 +00:00
|
|
|
new_label->SetHyperlink( href );
|
2024-04-19 23:07:44 +00:00
|
|
|
|
|
|
|
if( item->Type() == SCH_LABEL_T )
|
|
|
|
{
|
|
|
|
if( static_cast<SCH_LABEL_BASE*>( item )->GetSpinStyle() == SPIN_STYLE::SPIN::UP )
|
|
|
|
new_label->MirrorVertically( position.y );
|
|
|
|
else if( static_cast<SCH_LABEL_BASE*>( item )->GetSpinStyle() == SPIN_STYLE::SPIN::BOTTOM )
|
|
|
|
new_label->MirrorVertically( position.y );
|
|
|
|
else if( static_cast<SCH_LABEL_BASE*>( item )->GetSpinStyle() == SPIN_STYLE::SPIN::LEFT )
|
|
|
|
new_label->MirrorHorizontally( position.x );
|
|
|
|
else if( static_cast<SCH_LABEL_BASE*>( item )->GetSpinStyle() == SPIN_STYLE::SPIN::RIGHT )
|
|
|
|
new_label->MirrorHorizontally( position.x );
|
|
|
|
}
|
|
|
|
|
2022-07-21 11:40:58 +00:00
|
|
|
newtext = new_label;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_HIER_LABEL_T:
|
|
|
|
{
|
2022-09-17 19:56:01 +00:00
|
|
|
SCH_LABEL_BASE* new_label = new SCH_HIERLABEL( position, getValidNetname( txt ) );
|
2022-07-21 11:40:58 +00:00
|
|
|
|
|
|
|
new_label->SetShape( shape );
|
2023-09-07 16:09:53 +00:00
|
|
|
new_label->SetAttributes( *sourceText, false );
|
|
|
|
new_label->SetSpinStyle( spinStyle );
|
2022-09-17 19:56:01 +00:00
|
|
|
new_label->SetHyperlink( href );
|
2024-04-19 23:07:44 +00:00
|
|
|
|
|
|
|
if( item->Type() == SCH_LABEL_T )
|
|
|
|
{
|
|
|
|
if( static_cast<SCH_LABEL_BASE*>( item )->GetSpinStyle() == SPIN_STYLE::SPIN::UP )
|
|
|
|
new_label->MirrorVertically( position.y );
|
|
|
|
else if( static_cast<SCH_LABEL_BASE*>( item )->GetSpinStyle() == SPIN_STYLE::SPIN::BOTTOM )
|
|
|
|
new_label->MirrorVertically( position.y );
|
|
|
|
else if( static_cast<SCH_LABEL_BASE*>( item )->GetSpinStyle() == SPIN_STYLE::SPIN::LEFT )
|
|
|
|
new_label->MirrorHorizontally( position.x );
|
|
|
|
else if( static_cast<SCH_LABEL_BASE*>( item )->GetSpinStyle() == SPIN_STYLE::SPIN::RIGHT )
|
|
|
|
new_label->MirrorHorizontally( position.x );
|
|
|
|
}
|
|
|
|
|
2022-07-21 11:40:58 +00:00
|
|
|
newtext = new_label;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_DIRECTIVE_LABEL_T:
|
|
|
|
{
|
|
|
|
SCH_LABEL_BASE* new_label = new SCH_DIRECTIVE_LABEL( position );
|
|
|
|
|
2022-09-22 00:05:51 +00:00
|
|
|
// A SCH_DIRECTIVE_LABEL usually has at least one field containing the net class
|
|
|
|
// name. If we're copying from a text object assume the text is the netclass
|
|
|
|
// name. Otherwise, we'll just copy the fields which will either have a netclass
|
|
|
|
// or not.
|
|
|
|
if( !dynamic_cast<SCH_LABEL_BASE*>( item ) )
|
|
|
|
{
|
|
|
|
SCH_FIELD netclass( position, 0, new_label, wxT( "Netclass" ) );
|
|
|
|
netclass.SetText( txt );
|
|
|
|
netclass.SetVisible( true );
|
|
|
|
new_label->GetFields().push_back( netclass );
|
|
|
|
}
|
2022-07-21 11:40:58 +00:00
|
|
|
|
|
|
|
new_label->SetShape( LABEL_FLAG_SHAPE::F_ROUND );
|
2023-09-07 16:09:53 +00:00
|
|
|
new_label->SetAttributes( *sourceText, false );
|
|
|
|
new_label->SetSpinStyle( spinStyle );
|
2022-09-17 19:56:01 +00:00
|
|
|
new_label->SetHyperlink( href );
|
2022-07-21 11:40:58 +00:00
|
|
|
newtext = new_label;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_TEXT_T:
|
|
|
|
{
|
|
|
|
SCH_TEXT* new_text = new SCH_TEXT( position, txt );
|
|
|
|
|
2023-09-07 16:09:53 +00:00
|
|
|
new_text->SetAttributes( *sourceText, false );
|
2022-09-17 19:56:01 +00:00
|
|
|
new_text->SetHyperlink( href );
|
2022-07-21 11:40:58 +00:00
|
|
|
newtext = new_text;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_TEXTBOX_T:
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_TEXTBOX* new_textbox = new SCH_TEXTBOX( LAYER_NOTES, 0, FILL_T::NO_FILL, txt );
|
2022-07-21 11:40:58 +00:00
|
|
|
BOX2I bbox = item->GetBoundingBox();
|
|
|
|
|
|
|
|
if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( item ) )
|
|
|
|
bbox.Inflate( -label->GetLabelBoxExpansion() );
|
|
|
|
|
2023-09-07 16:09:53 +00:00
|
|
|
new_textbox->SetAttributes( *sourceText, false );
|
2022-07-21 11:40:58 +00:00
|
|
|
|
2024-01-20 17:05:21 +00:00
|
|
|
bbox.SetOrigin( bbox.GetLeft() - new_textbox->GetMarginLeft(),
|
|
|
|
bbox.GetTop() - new_textbox->GetMarginTop() );
|
|
|
|
bbox.SetEnd( bbox.GetRight() + new_textbox->GetMarginRight(),
|
|
|
|
bbox.GetBottom() + new_textbox->GetMarginBottom() );
|
2022-09-16 17:32:31 +00:00
|
|
|
|
2023-09-07 16:09:53 +00:00
|
|
|
VECTOR2I topLeft = bbox.GetPosition();
|
|
|
|
VECTOR2I botRight = bbox.GetEnd();
|
|
|
|
|
2022-09-16 17:32:31 +00:00
|
|
|
// Add 1/20 of the margin at the end to reduce line-breaking changes.
|
2024-01-20 17:05:21 +00:00
|
|
|
int slop = new_textbox->GetLegacyTextMargin() / 20;
|
2022-07-21 11:40:58 +00:00
|
|
|
|
2023-09-07 16:09:53 +00:00
|
|
|
if( sourceText->GetTextAngle() == ANGLE_VERTICAL )
|
|
|
|
{
|
|
|
|
if( sourceText->GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
|
|
|
|
botRight.y += slop;
|
|
|
|
else
|
|
|
|
topLeft.y -= slop;
|
|
|
|
}
|
|
|
|
else
|
2022-07-21 11:40:58 +00:00
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
if( sourceText->GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
|
|
|
|
topLeft.x -= slop;
|
|
|
|
else
|
|
|
|
botRight.x += slop;
|
2022-07-21 11:40:58 +00:00
|
|
|
}
|
|
|
|
|
2023-09-07 16:09:53 +00:00
|
|
|
new_textbox->SetPosition( topLeft );
|
|
|
|
new_textbox->SetEnd( botRight );
|
|
|
|
|
2022-09-17 19:56:01 +00:00
|
|
|
new_textbox->SetHyperlink( href );
|
2022-07-21 11:40:58 +00:00
|
|
|
newtext = new_textbox;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( wxString::Format( "%d.", convertTo ) );
|
|
|
|
break;
|
2020-05-27 11:13:57 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 19:51:05 +00:00
|
|
|
wxCHECK2( newtext, continue );
|
|
|
|
|
2020-05-27 11:13:57 +00:00
|
|
|
// Copy the old text item settings to the new one. Justifications are not copied
|
|
|
|
// because they are not used in labels. Justifications will be set to default value
|
|
|
|
// in the new text item type.
|
|
|
|
//
|
2022-07-21 11:40:58 +00:00
|
|
|
newtext->SetFlags( item->GetEditFlags() );
|
2022-06-10 12:11:42 +00:00
|
|
|
|
2022-07-21 11:40:58 +00:00
|
|
|
EDA_TEXT* eda_text = dynamic_cast<EDA_TEXT*>( item );
|
|
|
|
EDA_TEXT* new_eda_text = dynamic_cast<EDA_TEXT*>( newtext );
|
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
wxCHECK2( eda_text && new_eda_text, continue );
|
|
|
|
|
2022-10-12 22:49:22 +00:00
|
|
|
new_eda_text->SetFont( eda_text->GetFont() );
|
2022-07-21 11:40:58 +00:00
|
|
|
new_eda_text->SetTextSize( eda_text->GetTextSize() );
|
|
|
|
new_eda_text->SetTextThickness( eda_text->GetTextThickness() );
|
2024-02-25 17:28:05 +00:00
|
|
|
|
|
|
|
// Must be after SetTextSize()
|
2022-07-21 11:40:58 +00:00
|
|
|
new_eda_text->SetBold( eda_text->IsBold() );
|
2024-02-25 17:28:05 +00:00
|
|
|
new_eda_text->SetItalic( eda_text->IsItalic() );
|
2022-06-10 12:11:42 +00:00
|
|
|
|
|
|
|
newtext->AutoplaceFields( m_frame->GetScreen(), false );
|
2020-05-27 11:13:57 +00:00
|
|
|
|
2022-09-22 00:05:51 +00:00
|
|
|
SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( item );
|
|
|
|
SCH_LABEL_BASE* new_label = dynamic_cast<SCH_LABEL_BASE*>( newtext );
|
|
|
|
|
|
|
|
if( label && new_label )
|
2023-04-10 07:57:25 +00:00
|
|
|
{
|
2023-04-09 10:06:01 +00:00
|
|
|
new_label->AddFields( label->GetFields() );
|
2022-09-22 00:05:51 +00:00
|
|
|
|
2023-04-10 07:57:25 +00:00
|
|
|
// A SCH_GLOBALLABEL has a specific field, that has no meaning for
|
|
|
|
// other labels, and expected to be the first field in list.
|
|
|
|
// It is the first field in list for this kind of label
|
|
|
|
// So remove field named "Intersheetrefs" if exists for other labels
|
|
|
|
int min_idx = new_label->Type() == SCH_GLOBAL_LABEL_T ? 1 : 0;
|
|
|
|
std::vector<SCH_FIELD>& fields = new_label->GetFields();
|
|
|
|
|
|
|
|
for( int ii = fields.size()-1; ii >= min_idx; ii-- )
|
|
|
|
{
|
|
|
|
if( fields[ii].GetCanonicalName() == wxT( "Intersheetrefs" ) )
|
|
|
|
fields.erase( fields.begin() + ii );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 11:13:57 +00:00
|
|
|
if( selected )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEM*>( EE_ACTIONS::removeItemFromSel, item );
|
2020-05-27 11:13:57 +00:00
|
|
|
|
2022-07-21 11:40:58 +00:00
|
|
|
if( !item->IsNew() )
|
2020-05-27 11:13:57 +00:00
|
|
|
{
|
2022-07-21 11:40:58 +00:00
|
|
|
m_frame->RemoveFromScreen( item, m_frame->GetScreen() );
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Removed( item, m_frame->GetScreen() );
|
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->AddToScreen( newtext, m_frame->GetScreen() );
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Added( newtext, m_frame->GetScreen() );
|
2020-05-27 11:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( selected )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEM*>( EE_ACTIONS::addItemToSel, newtext );
|
2020-05-27 11:13:57 +00:00
|
|
|
|
|
|
|
// Otherwise, pointer is owned by the undo stack
|
2022-07-21 11:40:58 +00:00
|
|
|
if( item->IsNew() )
|
|
|
|
delete item;
|
2020-05-27 11:13:57 +00:00
|
|
|
}
|
2019-04-29 17:50:46 +00:00
|
|
|
}
|
|
|
|
|
2023-08-07 17:35:51 +00:00
|
|
|
if( !commit.Empty() )
|
|
|
|
commit.Push( _( "Change To" ) );
|
|
|
|
|
2020-05-06 18:00:55 +00:00
|
|
|
if( selection.IsHover() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2020-05-06 18:00:55 +00:00
|
|
|
|
2019-04-29 17:50:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-21 23:43:48 +00:00
|
|
|
int SCH_EDIT_TOOL::JustifyText( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
static std::vector<KICAD_T> justifiableItems = {
|
|
|
|
SCH_FIELD_T,
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_TEXTBOX_T,
|
|
|
|
SCH_LABEL_T
|
|
|
|
};
|
|
|
|
|
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( justifiableItems );
|
|
|
|
|
|
|
|
if( selection.GetSize() == 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
|
|
|
|
bool moving = item->IsMoving();
|
|
|
|
SCH_COMMIT localCommit( m_toolMgr );
|
|
|
|
SCH_COMMIT* commit = dynamic_cast<SCH_COMMIT*>( aEvent.Commit() );
|
|
|
|
|
|
|
|
if( !commit )
|
|
|
|
commit = &localCommit;
|
|
|
|
|
|
|
|
auto setJustify =
|
|
|
|
[&]( EDA_TEXT* aTextItem )
|
|
|
|
{
|
|
|
|
if( aEvent.Matches( ACTIONS::leftJustify.MakeEvent() ) )
|
|
|
|
aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
else if( aEvent.Matches( ACTIONS::centerJustify.MakeEvent() ) )
|
|
|
|
aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
else
|
|
|
|
aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
};
|
|
|
|
|
|
|
|
for( EDA_ITEM* edaItem : selection )
|
|
|
|
{
|
|
|
|
item = static_cast<SCH_ITEM*>( edaItem );
|
|
|
|
|
|
|
|
if( !moving )
|
|
|
|
commit->Modify( item, m_frame->GetScreen() );
|
|
|
|
|
|
|
|
if( item->Type() == SCH_FIELD_T )
|
|
|
|
{
|
|
|
|
setJustify( static_cast<SCH_FIELD*>( item ) );
|
|
|
|
|
|
|
|
// Now that we're re-justifying a field, they're no longer autoplaced.
|
|
|
|
static_cast<SCH_ITEM*>( item->GetParent() )->ClearFieldsAutoplaced();
|
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_TEXT_T )
|
|
|
|
{
|
|
|
|
setJustify( static_cast<SCH_TEXT*>( item ) );
|
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_TEXTBOX_T )
|
|
|
|
{
|
|
|
|
setJustify( static_cast<SCH_TEXTBOX*>( item ) );
|
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_LABEL_T )
|
|
|
|
{
|
|
|
|
SCH_LABEL* label = static_cast<SCH_LABEL*>( item );
|
|
|
|
|
|
|
|
if( label->GetTextAngle() == ANGLE_HORIZONTAL )
|
|
|
|
setJustify( label );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->UpdateItem( item, false, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update R-Tree for modified items
|
|
|
|
for( EDA_ITEM* selected : selection )
|
|
|
|
updateItem( selected, true );
|
|
|
|
|
|
|
|
if( item->IsMoving() )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EE_SELECTION selectionCopy = selection;
|
|
|
|
|
|
|
|
if( selection.IsHover() )
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
|
|
|
|
|
|
|
if( !localCommit.Empty() )
|
|
|
|
{
|
|
|
|
if( aEvent.Matches( ACTIONS::leftJustify.MakeEvent() ) )
|
|
|
|
localCommit.Push( _( "Left Justify" ) );
|
|
|
|
else if( aEvent.Matches( ACTIONS::centerJustify.MakeEvent() ) )
|
|
|
|
localCommit.Push( _( "Center Justify" ) );
|
|
|
|
else
|
|
|
|
localCommit.Push( _( "Right Justify" ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-30 13:54:32 +00:00
|
|
|
int SCH_EDIT_TOOL::BreakWire( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2022-12-15 15:26:48 +00:00
|
|
|
bool isSlice = aEvent.Matches( EE_ACTIONS::slice.MakeEvent() );
|
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
|
2022-08-20 09:27:35 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_LINE_T } );
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_SCREEN* screen = m_frame->GetScreen();
|
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2021-02-13 01:15:45 +00:00
|
|
|
std::vector<SCH_LINE*> lines;
|
2019-04-30 13:54:32 +00:00
|
|
|
|
2021-07-29 15:51:12 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2019-04-30 13:54:32 +00:00
|
|
|
{
|
2023-06-24 17:19:44 +00:00
|
|
|
if( item->Type() == SCH_LINE_T )
|
2021-02-16 18:09:56 +00:00
|
|
|
{
|
2023-06-24 17:19:44 +00:00
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( item );
|
|
|
|
|
2021-02-16 18:09:56 +00:00
|
|
|
if( !line->IsEndPoint( cursorPos ) )
|
2021-07-29 15:51:12 +00:00
|
|
|
lines.push_back( line );
|
2021-02-16 18:09:56 +00:00
|
|
|
}
|
2021-02-13 01:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_selectionTool->ClearSelection();
|
|
|
|
|
2021-02-16 18:09:56 +00:00
|
|
|
for( SCH_LINE* line : lines )
|
2022-07-09 05:03:23 +00:00
|
|
|
{
|
2022-12-15 15:26:48 +00:00
|
|
|
SCH_LINE* newLine;
|
2022-07-09 05:03:23 +00:00
|
|
|
|
2022-12-15 15:26:48 +00:00
|
|
|
// We let the user select the break point if they're on a single line
|
|
|
|
if( lines.size() == 1 && line->HitTest( cursorPos ) )
|
2023-06-09 16:24:49 +00:00
|
|
|
m_frame->BreakSegment( &commit, line, cursorPos, &newLine, screen );
|
2022-12-15 15:26:48 +00:00
|
|
|
else
|
2023-06-09 16:24:49 +00:00
|
|
|
m_frame->BreakSegment( &commit, line, line->GetMidPoint(), &newLine, screen );
|
2022-12-15 15:26:48 +00:00
|
|
|
|
|
|
|
// Make sure both endpoints are deselected
|
|
|
|
newLine->ClearFlags();
|
|
|
|
|
|
|
|
m_selectionTool->AddItemToSel( line );
|
|
|
|
line->SetFlags( ENDPOINT );
|
|
|
|
|
|
|
|
// If we're a break, we want to drag both wires.
|
|
|
|
// Side note: the drag/move tool only checks whether the first item is
|
|
|
|
// new to determine if it should append undo or not, someday this should
|
|
|
|
// be cleaned up and explictly controlled but for now the newLine
|
|
|
|
// selection addition must be after the existing line.
|
|
|
|
if( !isSlice )
|
|
|
|
{
|
|
|
|
m_selectionTool->AddItemToSel( newLine );
|
|
|
|
newLine->SetFlags( STARTPOINT );
|
|
|
|
}
|
2022-07-09 05:03:23 +00:00
|
|
|
}
|
2021-02-13 01:15:45 +00:00
|
|
|
|
2021-02-16 18:09:56 +00:00
|
|
|
if( !lines.empty() )
|
|
|
|
{
|
2019-04-30 13:54:32 +00:00
|
|
|
m_frame->TestDanglingEnds();
|
2021-02-13 01:15:45 +00:00
|
|
|
|
2023-06-30 17:57:01 +00:00
|
|
|
if( m_toolMgr->RunSynchronousAction( EE_ACTIONS::drag, &commit, isSlice ) )
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Push( isSlice ? _( "Slice Wire" ) : _( "Break Wire" ) );
|
2023-06-30 17:57:01 +00:00
|
|
|
else
|
|
|
|
commit.Revert();
|
2019-04-30 13:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-01 22:14:21 +00:00
|
|
|
int SCH_EDIT_TOOL::CleanupSheetPins( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_SHEET_T } );
|
2019-06-08 21:48:22 +00:00
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) selection.Front();
|
2024-01-26 22:29:32 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2019-05-01 22:14:21 +00:00
|
|
|
|
2021-08-30 15:45:25 +00:00
|
|
|
if( !sheet || !sheet->HasUndefinedPins() )
|
2019-05-01 22:14:21 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( !IsOK( m_frame, _( "Do you wish to delete the unreferenced pins from this sheet?" ) ) )
|
|
|
|
return 0;
|
|
|
|
|
2024-01-26 22:29:32 +00:00
|
|
|
commit.Modify( sheet, m_frame->GetScreen() );
|
2019-05-01 22:14:21 +00:00
|
|
|
|
|
|
|
sheet->CleanupSheet();
|
|
|
|
|
2020-10-30 15:15:20 +00:00
|
|
|
updateItem( sheet, true );
|
2024-01-26 22:29:32 +00:00
|
|
|
|
2024-01-27 15:55:05 +00:00
|
|
|
commit.Push( _( "Cleanup Sheet Pins" ) );
|
2019-05-01 22:14:21 +00:00
|
|
|
|
2020-05-06 18:00:55 +00:00
|
|
|
if( selection.IsHover() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2020-05-06 18:00:55 +00:00
|
|
|
|
2019-05-01 22:14:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
int SCH_EDIT_TOOL::EditPageNumber( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_SHEET_T } );
|
2020-10-18 20:30:37 +00:00
|
|
|
|
|
|
|
if( selection.GetSize() > 1 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) selection.Front();
|
|
|
|
|
|
|
|
SCH_SHEET_PATH instance = m_frame->GetCurrentSheet();
|
|
|
|
|
|
|
|
SCH_SCREEN* screen;
|
|
|
|
|
|
|
|
if( sheet )
|
|
|
|
{
|
|
|
|
// When changing the page number of a selected sheet, the current screen owns the sheet.
|
|
|
|
screen = m_frame->GetScreen();
|
|
|
|
|
|
|
|
instance.push_back( sheet );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH prevInstance = instance;
|
|
|
|
|
|
|
|
// When change the page number in the screen, the previous screen owns the sheet.
|
|
|
|
if( prevInstance.size() )
|
|
|
|
{
|
|
|
|
prevInstance.pop_back();
|
|
|
|
screen = prevInstance.LastScreen();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The root sheet and root screen are effectively the same thing.
|
|
|
|
screen = m_frame->GetScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
sheet = m_frame->GetCurrentSheet().Last();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString msg;
|
2020-11-29 00:10:17 +00:00
|
|
|
wxString sheetPath = instance.PathHumanReadable( false );
|
2021-12-06 12:47:18 +00:00
|
|
|
wxString pageNumber = instance.GetPageNumber();
|
2020-10-18 20:30:37 +00:00
|
|
|
|
|
|
|
msg.Printf( _( "Enter page number for sheet path%s" ),
|
|
|
|
( sheetPath.Length() > 20 ) ? "\n" + sheetPath : " " + sheetPath );
|
|
|
|
|
2021-02-19 14:51:18 +00:00
|
|
|
wxTextEntryDialog dlg( m_frame, msg, _( "Edit Sheet Page Number" ), pageNumber );
|
2020-10-18 20:30:37 +00:00
|
|
|
|
|
|
|
dlg.SetTextValidator( wxFILTER_ALPHANUMERIC ); // No white space.
|
|
|
|
|
2021-12-06 12:47:18 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue() == instance.GetPageNumber() )
|
2020-10-18 20:30:37 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
m_frame->SaveCopyInUndoList( screen, sheet, UNDO_REDO::CHANGED, false );
|
|
|
|
|
2021-12-06 12:47:18 +00:00
|
|
|
instance.SetPageNumber( dlg.GetValue() );
|
2020-10-18 20:30:37 +00:00
|
|
|
|
|
|
|
if( instance == m_frame->GetCurrentSheet() )
|
|
|
|
{
|
|
|
|
m_frame->GetScreen()->SetPageNumber( dlg.GetValue() );
|
|
|
|
m_frame->OnPageSettingsChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->OnModify();
|
|
|
|
|
2024-01-25 17:20:43 +00:00
|
|
|
// Update the hierarchy navigator labels if needed
|
|
|
|
if( pageNumber != dlg.GetValue() )
|
|
|
|
m_frame->UpdateLabelsHierarchyNavigator();
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-14 22:28:09 +00:00
|
|
|
int SCH_EDIT_TOOL::DdAppendFile( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxString aFileName = *aEvent.Parameter<wxString*>();
|
|
|
|
return ( m_frame->AddSheetAndUpdateDisplay( aFileName ) ? 0 : 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-04 18:50:39 +00:00
|
|
|
int SCH_EDIT_TOOL::SetAttribute( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_SYMBOL_T } );
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( selection.Empty() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
2023-06-24 17:19:44 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
2023-05-04 18:50:39 +00:00
|
|
|
{
|
2023-06-24 17:19:44 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
commit.Modify( symbol, m_frame->GetScreen() );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::setDNP ) )
|
2023-06-24 17:19:44 +00:00
|
|
|
symbol->SetDNP( true );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::setExcludeFromSimulation ) )
|
2023-08-08 16:32:08 +00:00
|
|
|
symbol->SetExcludedFromSim( true );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::setExcludeFromBOM ) )
|
2023-06-24 17:19:44 +00:00
|
|
|
symbol->SetExcludedFromBOM( true );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::setExcludeFromBoard ) )
|
2023-06-24 17:19:44 +00:00
|
|
|
symbol->SetExcludedFromBoard( true );
|
2023-05-04 18:50:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-07 17:35:51 +00:00
|
|
|
if( !commit.Empty() )
|
|
|
|
commit.Push( _( "Set Attribute" ) );
|
|
|
|
|
2023-05-04 18:50:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDIT_TOOL::UnsetAttribute( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_SYMBOL_T } );
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( selection.Empty() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
2023-06-24 17:19:44 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
2023-05-04 18:50:39 +00:00
|
|
|
{
|
2023-06-24 17:19:44 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
commit.Modify( symbol, m_frame->GetScreen() );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::unsetDNP ) )
|
2023-06-24 17:19:44 +00:00
|
|
|
symbol->SetDNP( false );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::unsetExcludeFromSimulation ) )
|
2023-08-08 16:32:08 +00:00
|
|
|
symbol->SetExcludedFromSim( false );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::unsetExcludeFromBOM ) )
|
2023-06-24 17:19:44 +00:00
|
|
|
symbol->SetExcludedFromBOM( false );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::unsetExcludeFromBoard ) )
|
2023-06-24 17:19:44 +00:00
|
|
|
symbol->SetExcludedFromBoard( false );
|
2023-05-04 18:50:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-07 17:35:51 +00:00
|
|
|
if( !commit.Empty() )
|
|
|
|
commit.Push( _( "Clear Attribute" ) );
|
|
|
|
|
2023-05-04 18:50:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDIT_TOOL::ToggleAttribute( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_SYMBOL_T } );
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( selection.Empty() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
2023-06-24 17:19:44 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
2023-05-04 18:50:39 +00:00
|
|
|
{
|
2023-06-24 17:19:44 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
commit.Modify( symbol, m_frame->GetScreen() );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::toggleDNP ) )
|
2023-06-24 17:19:44 +00:00
|
|
|
symbol->SetDNP( !symbol->GetDNP() );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::toggleExcludeFromSimulation ) )
|
2023-08-08 16:32:08 +00:00
|
|
|
symbol->SetExcludedFromSim( !symbol->GetExcludedFromSim() );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::toggleExcludeFromBOM ) )
|
2023-06-24 17:19:44 +00:00
|
|
|
symbol->SetExcludedFromBOM( !symbol->GetExcludedFromBOM() );
|
2023-05-04 18:50:39 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::toggleExcludeFromBoard ) )
|
2023-06-24 17:19:44 +00:00
|
|
|
symbol->SetExcludedFromBoard( !symbol->GetExcludedFromBoard() );
|
2023-05-04 18:50:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-07 17:35:51 +00:00
|
|
|
if( !commit.Empty() )
|
|
|
|
commit.Push( _( "Toggle Attribute" ) );
|
|
|
|
|
2023-05-04 18:50:39 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-23 13:06:37 +00:00
|
|
|
void SCH_EDIT_TOOL::setTransitions()
|
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::RepeatDrawItem, EE_ACTIONS::repeatDrawItem.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::Rotate, EE_ACTIONS::rotateCW.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::Rotate, EE_ACTIONS::rotateCCW.MakeEvent() );
|
2021-02-16 20:45:25 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::Mirror, EE_ACTIONS::mirrorV.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::Mirror, EE_ACTIONS::mirrorH.MakeEvent() );
|
2022-08-30 13:01:48 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::Swap, EE_ACTIONS::swap.MakeEvent() );
|
2019-07-31 12:48:00 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::DoDelete, ACTIONS::doDelete.MakeEvent() );
|
2023-10-10 14:43:45 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::InteractiveDelete, ACTIONS::deleteTool.MakeEvent() );
|
2019-05-10 17:19:48 +00:00
|
|
|
|
|
|
|
Go( &SCH_EDIT_TOOL::Properties, EE_ACTIONS::properties.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::EditField, EE_ACTIONS::editReference.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::EditField, EE_ACTIONS::editValue.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::EditField, EE_ACTIONS::editFootprint.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::AutoplaceFields, EE_ACTIONS::autoplaceFields.MakeEvent() );
|
2020-08-13 17:51:26 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::ChangeSymbols, EE_ACTIONS::changeSymbols.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::ChangeSymbols, EE_ACTIONS::updateSymbols.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::ChangeSymbols, EE_ACTIONS::changeSymbol.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::ChangeSymbols, EE_ACTIONS::updateSymbol.MakeEvent() );
|
2024-01-26 16:16:13 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::ChangeBodyStyle, EE_ACTIONS::toggleDeMorgan.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::ChangeBodyStyle, EE_ACTIONS::showDeMorganStandard.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::ChangeBodyStyle, EE_ACTIONS::showDeMorganAlternate.MakeEvent() );
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toLabel.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toHLabel.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toGLabel.MakeEvent() );
|
2022-06-10 12:11:42 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toCLabel.MakeEvent() );
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toText.MakeEvent() );
|
2022-07-21 11:40:58 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toTextBox.MakeEvent() );
|
2023-11-21 23:43:48 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::JustifyText, ACTIONS::leftJustify.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::JustifyText, ACTIONS::centerJustify.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::JustifyText, ACTIONS::rightJustify.MakeEvent() );
|
2019-05-10 17:19:48 +00:00
|
|
|
|
|
|
|
Go( &SCH_EDIT_TOOL::BreakWire, EE_ACTIONS::breakWire.MakeEvent() );
|
2022-12-15 15:26:48 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::BreakWire, EE_ACTIONS::slice.MakeEvent() );
|
2019-05-10 17:19:48 +00:00
|
|
|
|
2023-05-04 18:50:39 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::SetAttribute, EE_ACTIONS::setDNP.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::SetAttribute, EE_ACTIONS::setExcludeFromBOM.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::SetAttribute, EE_ACTIONS::setExcludeFromBoard.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::SetAttribute, EE_ACTIONS::setExcludeFromSimulation.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::UnsetAttribute, EE_ACTIONS::unsetDNP.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::UnsetAttribute, EE_ACTIONS::unsetExcludeFromBOM.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::UnsetAttribute, EE_ACTIONS::unsetExcludeFromBoard.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::UnsetAttribute, EE_ACTIONS::unsetExcludeFromSimulation.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::ToggleAttribute, EE_ACTIONS::toggleDNP.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::ToggleAttribute, EE_ACTIONS::toggleExcludeFromBOM.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::ToggleAttribute, EE_ACTIONS::toggleExcludeFromBoard.MakeEvent() );
|
|
|
|
Go( &SCH_EDIT_TOOL::ToggleAttribute, EE_ACTIONS::toggleExcludeFromSimulation.MakeEvent() );
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::CleanupSheetPins, EE_ACTIONS::cleanupSheetPins.MakeEvent() );
|
2019-06-30 22:06:34 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::GlobalEdit, EE_ACTIONS::editTextAndGraphics.MakeEvent() );
|
2020-10-18 20:30:37 +00:00
|
|
|
Go( &SCH_EDIT_TOOL::EditPageNumber, EE_ACTIONS::editPageNumber.MakeEvent() );
|
2022-09-14 22:28:09 +00:00
|
|
|
|
|
|
|
Go( &SCH_EDIT_TOOL::DdAppendFile, EE_ACTIONS::ddAppendFile.MakeEvent() );
|
2019-04-23 13:06:37 +00:00
|
|
|
}
|