2019-04-17 19:09:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-11-07 15:45:48 +00:00
|
|
|
* Copyright (C) 2019-2023 CERN
|
2024-03-09 13:50:26 +00:00
|
|
|
* Copyright (C) 2019-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-04-17 19:09:48 +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
|
|
|
|
*/
|
|
|
|
|
2024-02-25 14:23:59 +00:00
|
|
|
#include "sch_sheet_path.h"
|
2022-12-19 13:19:21 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2023-09-18 03:13:09 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2024-02-25 14:23:59 +00:00
|
|
|
#include <optional>
|
2021-03-13 22:13:47 +00:00
|
|
|
#include <project_sch.h>
|
2022-03-07 12:45:24 +00:00
|
|
|
#include <tools/sch_drawing_tools.h>
|
2023-01-06 22:14:06 +00:00
|
|
|
#include <tools/sch_line_wire_bus_tool.h>
|
2022-03-07 12:45:24 +00:00
|
|
|
#include <tools/ee_selection_tool.h>
|
|
|
|
#include <tools/ee_grid_helper.h>
|
2023-09-18 23:52:27 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <ee_actions.h>
|
2019-04-17 19:09:48 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2022-09-22 00:05:51 +00:00
|
|
|
#include <pgm_base.h>
|
2019-04-17 19:09:48 +00:00
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <view/view.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2019-04-17 19:09:48 +00:00
|
|
|
#include <sch_no_connect.h>
|
2019-05-17 15:16:13 +00:00
|
|
|
#include <sch_line.h>
|
2019-04-17 19:09:48 +00:00
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_bus_entry.h>
|
|
|
|
#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-17 19:09:48 +00:00
|
|
|
#include <sch_sheet.h>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2024-02-25 14:23:59 +00:00
|
|
|
#include <sch_label.h>
|
2019-04-17 19:09:48 +00:00
|
|
|
#include <sch_bitmap.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2023-06-09 21:41:33 +00:00
|
|
|
#include <sch_commit.h>
|
2021-03-13 22:13:47 +00:00
|
|
|
#include <symbol_library.h>
|
2020-04-12 23:09:17 +00:00
|
|
|
#include <eeschema_settings.h>
|
2021-10-12 20:05:37 +00:00
|
|
|
#include <dialogs/dialog_label_properties.h>
|
|
|
|
#include <dialogs/dialog_text_properties.h>
|
2022-03-16 13:43:19 +00:00
|
|
|
#include <dialogs/dialog_wire_bus_properties.h>
|
2020-10-08 17:03:58 +00:00
|
|
|
#include <dialogs/dialog_junction_props.h>
|
2023-10-09 03:56:13 +00:00
|
|
|
#include <import_gfx/dialog_import_gfx_sch.h>
|
2024-02-25 14:23:59 +00:00
|
|
|
#include <sync_sheet_pin/sheet_synchronization_agent.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-03-03 01:06:25 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/filedlg.h>
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
SCH_DRAWING_TOOLS::SCH_DRAWING_TOOLS() :
|
2020-05-23 15:50:08 +00:00
|
|
|
EE_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveDrawing" ),
|
2021-10-12 20:05:37 +00:00
|
|
|
m_lastSheetPinType( LABEL_FLAG_SHAPE::L_INPUT ),
|
|
|
|
m_lastGlobalLabelShape( LABEL_FLAG_SHAPE::L_INPUT ),
|
|
|
|
m_lastNetClassFlagShape( LABEL_FLAG_SHAPE::F_ROUND ),
|
2023-09-07 16:09:53 +00:00
|
|
|
m_lastTextOrientation( SPIN_STYLE::RIGHT ),
|
2020-05-23 15:50:08 +00:00
|
|
|
m_lastTextBold( false ),
|
2021-01-27 19:50:07 +00:00
|
|
|
m_lastTextItalic( false ),
|
2022-06-03 20:47:13 +00:00
|
|
|
m_lastTextAngle( ANGLE_0 ),
|
2023-11-07 15:45:48 +00:00
|
|
|
m_lastTextboxAngle( ANGLE_0 ),
|
|
|
|
m_lastTextHJustify( GR_TEXT_H_ALIGN_CENTER ),
|
|
|
|
m_lastTextVJustify( GR_TEXT_V_ALIGN_CENTER ),
|
|
|
|
m_lastTextboxHJustify( GR_TEXT_H_ALIGN_LEFT ),
|
|
|
|
m_lastTextboxVJustify( GR_TEXT_V_ALIGN_TOP ),
|
2021-07-17 19:56:18 +00:00
|
|
|
m_lastFillStyle( FILL_T::NO_FILL ),
|
2022-06-08 09:32:45 +00:00
|
|
|
m_lastTextboxFillStyle( FILL_T::NO_FILL ),
|
2022-06-03 20:47:13 +00:00
|
|
|
m_lastFillColor( COLOR4D::UNSPECIFIED ),
|
2022-06-08 09:32:45 +00:00
|
|
|
m_lastTextboxFillColor( COLOR4D::UNSPECIFIED ),
|
2023-11-25 13:05:45 +00:00
|
|
|
m_lastStroke( 0, LINE_STYLE::DEFAULT, COLOR4D::UNSPECIFIED ),
|
|
|
|
m_lastTextboxStroke( 0, LINE_STYLE::DEFAULT, COLOR4D::UNSPECIFIED ),
|
2022-02-25 21:18:43 +00:00
|
|
|
m_mruPath( wxEmptyString ),
|
2022-07-06 11:54:17 +00:00
|
|
|
m_lastAutoLabelRotateOnPlacement( false ),
|
2023-11-19 14:17:36 +00:00
|
|
|
m_inDrawingTool( false )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-10 16:48:46 +00:00
|
|
|
}
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
bool SCH_DRAWING_TOOLS::Init()
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE::Init();
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
auto belowRootSheetCondition =
|
|
|
|
[&]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_frame->GetCurrentSheet().Last() != &m_frame->Schematic().Root();
|
|
|
|
};
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
|
2023-12-17 22:06:28 +00:00
|
|
|
ctxMenu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 150 );
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2019-04-17 19:09:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 11:46:07 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = aEvent.Parameter<SCH_SYMBOL*>();
|
2022-01-29 19:07:07 +00:00
|
|
|
SYMBOL_LIBRARY_FILTER filter;
|
2020-11-07 14:31:50 +00:00
|
|
|
std::vector<PICKED_SYMBOL>* historyList = nullptr;
|
2022-05-16 22:41:30 +00:00
|
|
|
bool ignorePrimePosition = false;
|
|
|
|
COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
|
2023-06-12 18:33:52 +00:00
|
|
|
SCH_SCREEN* screen = m_frame->GetScreen();
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2023-11-19 14:17:36 +00:00
|
|
|
if( m_inDrawingTool )
|
2021-01-27 19:50:07 +00:00
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
2023-11-19 14:17:36 +00:00
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-01-27 19:50:07 +00:00
|
|
|
|
2023-08-23 15:13:46 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
VECTOR2I cursorPos;
|
|
|
|
|
2022-07-20 15:40:38 +00:00
|
|
|
// First we need to get all instances of this sheet so we can annotate
|
|
|
|
// whatever symbols we place on all copies
|
|
|
|
SCH_SHEET_LIST hierarchy = m_frame->Schematic().GetSheets();
|
|
|
|
SCH_SHEET_LIST newInstances =
|
|
|
|
hierarchy.FindAllSheetsForScreen( m_frame->GetCurrentSheet().LastScreen() );
|
|
|
|
newInstances.SortByPageNumbers();
|
|
|
|
|
|
|
|
// Get a list of all references in the schematic to avoid duplicates wherever
|
|
|
|
// they're placed
|
|
|
|
SCH_REFERENCE_LIST existingRefs;
|
|
|
|
hierarchy.GetSymbols( existingRefs );
|
|
|
|
existingRefs.SortByReferenceOnly();
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::placeSymbol ) )
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2020-05-23 15:50:08 +00:00
|
|
|
historyList = &m_symbolHistoryList;
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-06-15 00:29:42 +00:00
|
|
|
else if (aEvent.IsAction( &EE_ACTIONS::placePower ) )
|
|
|
|
{
|
2020-05-23 15:50:08 +00:00
|
|
|
historyList = &m_powerHistoryList;
|
2021-06-15 12:31:28 +00:00
|
|
|
filter.FilterPowerSymbols( true );
|
2019-06-15 00:29:42 +00:00
|
|
|
}
|
|
|
|
else
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2021-03-18 11:46:07 +00:00
|
|
|
wxFAIL_MSG( "PlaceSymbol(): unexpected request" );
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2019-05-01 09:24:43 +00:00
|
|
|
|
2021-03-18 11:27:15 +00:00
|
|
|
auto addSymbol =
|
2023-06-12 18:33:52 +00:00
|
|
|
[this]( SCH_SYMBOL* aSymbol )
|
2021-03-18 11:27:15 +00:00
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2021-03-28 19:04:58 +00:00
|
|
|
m_selectionTool->AddItemToSel( aSymbol );
|
2021-03-18 11:27:15 +00:00
|
|
|
|
2021-05-30 21:04:07 +00:00
|
|
|
aSymbol->SetFlags( IS_NEW | IS_MOVING );
|
2023-06-12 18:33:52 +00:00
|
|
|
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( aSymbol, false ); // Add, but not give ownership
|
2021-03-28 19:04:58 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
// Set IS_MOVING again, as AddItemToCommitAndScreen() will have cleared it.
|
2021-05-30 21:04:07 +00:00
|
|
|
aSymbol->SetFlags( IS_MOVING );
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2021-03-18 11:27:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
2021-03-18 11:46:07 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( symbol ? KICURSOR::MOVING
|
|
|
|
: KICURSOR::COMPONENT );
|
2021-03-18 11:27:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto cleanup =
|
2022-07-12 03:45:21 +00:00
|
|
|
[&]()
|
2021-03-18 11:27:15 +00:00
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2023-06-12 18:33:52 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
delete symbol;
|
|
|
|
symbol = nullptr;
|
|
|
|
|
2022-11-29 21:36:02 +00:00
|
|
|
existingRefs.Clear();
|
|
|
|
hierarchy.GetSymbols( existingRefs );
|
|
|
|
existingRefs.SortByReferenceOnly();
|
2021-03-18 11:27:15 +00:00
|
|
|
};
|
|
|
|
|
2022-05-27 00:31:28 +00:00
|
|
|
auto annotate =
|
2022-07-12 03:45:21 +00:00
|
|
|
[&]()
|
2022-05-27 00:31:28 +00:00
|
|
|
{
|
2022-07-12 03:45:21 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
2022-05-27 00:31:28 +00:00
|
|
|
|
2022-07-20 15:40:38 +00:00
|
|
|
// Then we need to annotate all instances by sheet
|
|
|
|
for( SCH_SHEET_PATH& instance : newInstances )
|
2022-05-27 00:31:28 +00:00
|
|
|
{
|
2022-07-20 15:40:38 +00:00
|
|
|
SCH_REFERENCE newReference( symbol, symbol->GetLibSymbolRef().get(), instance );
|
|
|
|
SCH_REFERENCE_LIST refs;
|
|
|
|
refs.AddItem( newReference );
|
|
|
|
|
2023-01-03 21:08:36 +00:00
|
|
|
if( cfg->m_AnnotatePanel.automatic || newReference.AlwaysAnnotate() )
|
2022-07-20 15:40:38 +00:00
|
|
|
{
|
2023-05-06 10:04:16 +00:00
|
|
|
refs.ReannotateByOptions( (ANNOTATE_ORDER_T) cfg->m_AnnotatePanel.sort_order,
|
|
|
|
(ANNOTATE_ALGO_T) cfg->m_AnnotatePanel.method,
|
|
|
|
m_frame->Schematic().Settings().m_AnnotateStartNum,
|
|
|
|
existingRefs, false, &hierarchy );
|
2022-07-20 15:40:38 +00:00
|
|
|
|
|
|
|
refs.UpdateAnnotation();
|
|
|
|
|
|
|
|
// Update existing refs for next iteration
|
|
|
|
for( size_t i = 0; i < refs.GetCount(); i++ )
|
|
|
|
existingRefs.AddItem( refs[i] );
|
|
|
|
}
|
2022-05-27 00:31:28 +00:00
|
|
|
}
|
2022-07-20 15:40:38 +00:00
|
|
|
|
|
|
|
m_frame->GetCurrentSheet().UpdateAllScreenReferences();
|
2022-05-27 00:31:28 +00:00
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
Activate();
|
2022-08-26 17:34:46 +00:00
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
getViewControls()->ShowCursor( true );
|
2022-08-26 17:34:46 +00:00
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
// Prime the pump
|
2021-03-18 11:46:07 +00:00
|
|
|
if( symbol )
|
2019-06-16 18:51:47 +00:00
|
|
|
{
|
2023-06-12 18:33:52 +00:00
|
|
|
addSymbol( symbol );
|
2022-06-22 13:17:44 +00:00
|
|
|
annotate();
|
2022-08-26 17:34:46 +00:00
|
|
|
getViewControls()->WarpMouseCursor( getViewControls()->GetMousePosition( false ) );
|
2019-06-16 18:51:47 +00:00
|
|
|
}
|
2022-05-16 22:41:30 +00:00
|
|
|
else if( aEvent.HasPosition() )
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2022-05-16 09:22:55 +00:00
|
|
|
m_toolMgr->PrimeTool( aEvent.Position() );
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2022-05-16 22:41:30 +00:00
|
|
|
else if( common_settings->m_Input.immediate_actions && !aEvent.IsReactivate() )
|
|
|
|
{
|
|
|
|
m_toolMgr->PrimeTool( { 0, 0 } );
|
|
|
|
ignorePrimePosition = true;
|
|
|
|
}
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2022-05-16 22:41:30 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
|
|
|
|
2023-10-23 13:34:06 +00:00
|
|
|
cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_CONNECTABLE );
|
2023-08-23 15:13:46 +00:00
|
|
|
controls->ForceCursorPosition( true, cursorPos );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2022-06-09 15:53:24 +00:00
|
|
|
// The tool hotkey is interpreted as a click when drawing
|
2022-09-14 17:31:56 +00:00
|
|
|
bool isSyntheticClick = symbol && evt->IsActivate() && evt->HasPosition()
|
|
|
|
&& evt->Matches( aEvent );
|
2022-06-09 15:53:24 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( evt->IsCancelInteractive() || ( symbol && evt->IsAction( &ACTIONS::undo ) ) )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2022-03-17 15:26:49 +00:00
|
|
|
m_frame->GetInfoBar()->Dismiss();
|
|
|
|
|
2021-03-18 11:46:07 +00:00
|
|
|
if( symbol )
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2022-06-09 15:53:24 +00:00
|
|
|
else if( evt->IsActivate() && !isSyntheticClick )
|
2019-07-01 21:01:33 +00:00
|
|
|
{
|
2021-03-18 11:46:07 +00:00
|
|
|
if( symbol && evt->IsMoveTool() )
|
2021-02-23 15:34:27 +00:00
|
|
|
{
|
|
|
|
// we're already moving our own item; ignore the move tool
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-03-18 11:46:07 +00:00
|
|
|
if( symbol )
|
2021-05-08 22:30:38 +00:00
|
|
|
{
|
|
|
|
m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel symbol creation." ) );
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
|
|
|
|
if( evt->IsMoveTool() )
|
2019-06-18 17:56:40 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
// leave ourselves on the stack so we come back after the move
|
2019-06-27 11:47:24 +00:00
|
|
|
break;
|
2019-06-18 21:34:31 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-06-18 17:56:40 +00:00
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
2022-06-09 15:53:24 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) || isSyntheticClick )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2021-03-18 11:46:07 +00:00
|
|
|
if( !symbol )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-01 09:24:43 +00:00
|
|
|
|
2021-03-13 22:13:47 +00:00
|
|
|
SCH_SHEET_LIST sheets = m_frame->Schematic().GetSheets();
|
|
|
|
SYMBOL_LIB_TABLE* libs = PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() );
|
|
|
|
SYMBOL_LIB* cache = PROJECT_SCH::SchLibs( &m_frame->Prj() )->GetCacheLibrary();
|
|
|
|
|
|
|
|
std::vector<LIB_SYMBOL*> part_list;
|
|
|
|
|
|
|
|
for( SCH_SHEET_PATH& sheet : sheets )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : sheet.LastScreen()->Items() )
|
|
|
|
{
|
|
|
|
if( item->Type() != SCH_SYMBOL_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_SYMBOL* s = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
LIB_SYMBOL* libSymbol = SchGetLibSymbol( s->GetLibId(), libs, cache );
|
|
|
|
|
|
|
|
if( libSymbol )
|
|
|
|
part_list.push_back( libSymbol );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove redundant parts
|
|
|
|
sort( part_list.begin(), part_list.end() );
|
|
|
|
part_list.erase( unique( part_list.begin(), part_list.end() ), part_list.end() );
|
|
|
|
|
|
|
|
std::vector<PICKED_SYMBOL> alreadyPlaced;
|
|
|
|
for( LIB_SYMBOL* libSymbol : part_list )
|
|
|
|
{
|
|
|
|
PICKED_SYMBOL pickedSymbol;
|
|
|
|
pickedSymbol.LibId = libSymbol->GetLibId();
|
|
|
|
alreadyPlaced.push_back( pickedSymbol );
|
|
|
|
}
|
|
|
|
|
2022-12-24 19:39:57 +00:00
|
|
|
// Pick the symbol to be placed
|
2020-04-12 23:09:17 +00:00
|
|
|
bool footprintPreviews = m_frame->eeconfig()->m_Appearance.footprint_preview;
|
2023-11-13 15:42:53 +00:00
|
|
|
PICKED_SYMBOL sel = m_frame->PickSymbolFromLibrary( &filter, *historyList,
|
|
|
|
alreadyPlaced,
|
|
|
|
footprintPreviews );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2022-05-16 22:41:30 +00:00
|
|
|
LIB_SYMBOL* libSymbol = sel.LibId.IsValid() ? m_frame->GetLibSymbol( sel.LibId )
|
|
|
|
: nullptr;
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !libSymbol )
|
2019-04-17 19:09:48 +00:00
|
|
|
continue;
|
|
|
|
|
2022-05-16 22:41:30 +00:00
|
|
|
// If we started with a hotkey which has a position then warp back to that.
|
|
|
|
// Otherwise update to the current mouse position pinned inside the autoscroll
|
|
|
|
// boundaries.
|
|
|
|
if( evt->IsPrime() && !ignorePrimePosition )
|
|
|
|
{
|
2023-08-22 14:09:04 +00:00
|
|
|
cursorPos = grid.Align( evt->Position(), GRID_HELPER_GRIDS::GRID_CONNECTABLE );
|
2022-05-16 22:41:30 +00:00
|
|
|
getViewControls()->WarpMouseCursor( cursorPos, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
getViewControls()->PinCursorInsideNonAutoscrollArea( true );
|
2023-08-22 14:09:04 +00:00
|
|
|
cursorPos = grid.Align( getViewControls()->GetMousePosition(),
|
|
|
|
GRID_HELPER_GRIDS::GRID_CONNECTABLE );
|
2022-05-16 22:41:30 +00:00
|
|
|
}
|
|
|
|
|
2022-08-26 17:34:46 +00:00
|
|
|
symbol = new SCH_SYMBOL( *libSymbol, &m_frame->GetCurrentSheet(), sel, cursorPos,
|
|
|
|
&m_frame->Schematic() );
|
2023-06-12 18:33:52 +00:00
|
|
|
addSymbol( symbol );
|
2022-05-27 00:31:28 +00:00
|
|
|
annotate();
|
2020-10-08 02:47:01 +00:00
|
|
|
|
2023-01-03 21:08:36 +00:00
|
|
|
// Update the list of references for the next symbol placement.
|
|
|
|
SCH_REFERENCE placedSymbolReference( symbol, symbol->GetLibSymbolRef().get(),
|
|
|
|
m_frame->GetCurrentSheet() );
|
|
|
|
existingRefs.AddItem( placedSymbolReference );
|
|
|
|
existingRefs.SortByReferenceOnly();
|
|
|
|
|
2022-05-29 19:29:32 +00:00
|
|
|
if( m_frame->eeconfig()->m_AutoplaceFields.enable )
|
|
|
|
symbol->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
|
|
|
|
|
2021-03-18 11:46:07 +00:00
|
|
|
// Update cursor now that we have a symbol
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-12 18:33:52 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_frame->AddToScreen( symbol, screen );
|
|
|
|
|
2021-03-14 22:29:41 +00:00
|
|
|
if( m_frame->eeconfig()->m_AutoplaceFields.enable )
|
2023-06-12 18:33:52 +00:00
|
|
|
symbol->AutoplaceFields( screen, false /* aManual */ );
|
2021-03-14 22:29:41 +00:00
|
|
|
|
2023-09-02 10:56:26 +00:00
|
|
|
m_frame->SaveCopyForRepeatItem( symbol );
|
|
|
|
|
2023-06-12 18:33:52 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
commit.Added( symbol, screen );
|
2021-03-28 19:04:58 +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, &m_selectionTool->GetSelection() );
|
|
|
|
lwbTool->AddJunctionsIfNeeded( &commit, &m_selectionTool->GetSelection() );
|
2019-10-29 05:06:39 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Push( _( "Add Symbol" ) );
|
2019-11-26 21:03:19 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* nextSymbol = nullptr;
|
2021-03-28 19:04:58 +00:00
|
|
|
|
2020-04-12 23:09:17 +00:00
|
|
|
if( m_frame->eeconfig()->m_SymChooserPanel.place_all_units
|
|
|
|
|| m_frame->eeconfig()->m_SymChooserPanel.keep_symbol )
|
2019-10-29 05:06:39 +00:00
|
|
|
{
|
2021-03-18 11:46:07 +00:00
|
|
|
int new_unit = symbol->GetUnit();
|
2019-10-29 05:06:39 +00:00
|
|
|
|
2020-04-12 23:09:17 +00:00
|
|
|
if( m_frame->eeconfig()->m_SymChooserPanel.place_all_units
|
2021-03-18 11:46:07 +00:00
|
|
|
&& symbol->GetUnit() < symbol->GetUnitCount() )
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-10-29 05:06:39 +00:00
|
|
|
new_unit++;
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-10-29 05:06:39 +00:00
|
|
|
else
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-10-29 05:06:39 +00:00
|
|
|
new_unit = 1;
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-10-29 05:06:39 +00:00
|
|
|
|
2021-03-18 11:46:07 +00:00
|
|
|
// We are either stepping to the next unit or next symbol
|
2020-04-12 23:09:17 +00:00
|
|
|
if( m_frame->eeconfig()->m_SymChooserPanel.keep_symbol || new_unit > 1 )
|
2019-10-29 05:06:39 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
nextSymbol = static_cast<SCH_SYMBOL*>( symbol->Duplicate() );
|
2021-03-18 11:46:07 +00:00
|
|
|
nextSymbol->SetUnit( new_unit );
|
|
|
|
nextSymbol->SetUnitSelection( new_unit );
|
2019-10-29 05:06:39 +00:00
|
|
|
|
2022-03-30 17:41:40 +00:00
|
|
|
// Start new annotation sequence at first unit
|
|
|
|
if( new_unit == 1 )
|
|
|
|
nextSymbol->ClearAnnotation( nullptr, false );
|
|
|
|
|
2023-06-12 18:33:52 +00:00
|
|
|
addSymbol( nextSymbol );
|
2023-06-09 16:24:49 +00:00
|
|
|
symbol = nextSymbol;
|
2022-05-27 00:31:28 +00:00
|
|
|
annotate();
|
2023-01-03 21:08:36 +00:00
|
|
|
|
|
|
|
// Update the list of references for the next symbol placement.
|
|
|
|
SCH_REFERENCE placedSymbolReference( symbol,
|
|
|
|
symbol->GetLibSymbolRef().get(),
|
|
|
|
m_frame->GetCurrentSheet() );
|
|
|
|
existingRefs.AddItem( placedSymbolReference );
|
|
|
|
existingRefs.SortByReferenceOnly();
|
2019-10-29 05:06:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-18 11:46:07 +00:00
|
|
|
symbol = nextSymbol;
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2019-04-29 17:50:46 +00:00
|
|
|
// Warp after context menu only if dragging...
|
2021-03-18 11:46:07 +00:00
|
|
|
if( !symbol )
|
2019-04-29 17:50:46 +00:00
|
|
|
m_toolMgr->VetoContextMenuMouseWarp();
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
2019-06-15 00:29:42 +00:00
|
|
|
else if( evt->Category() == TC_COMMAND && evt->Action() == TA_CHOICE_MENU_CHOICE )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2023-08-28 11:29:47 +00:00
|
|
|
if( *evt->GetCommandId() >= ID_POPUP_SCH_SELECT_UNIT
|
|
|
|
&& *evt->GetCommandId() <= ID_POPUP_SCH_SELECT_UNIT_END )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2023-08-28 11:29:47 +00:00
|
|
|
int unit = *evt->GetCommandId() - ID_POPUP_SCH_SELECT_UNIT;
|
2019-05-02 20:44:23 +00:00
|
|
|
|
2021-03-18 11:46:07 +00:00
|
|
|
if( symbol )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2021-03-18 11:46:07 +00:00
|
|
|
m_frame->SelectUnit( symbol, unit );
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-15 12:36:36 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::duplicate )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::repeatDrawItem ) )
|
2022-12-24 19:39:57 +00:00
|
|
|
{
|
|
|
|
if( symbol )
|
|
|
|
{
|
|
|
|
// This doesn't really make sense; we'll just end up dragging a stack of
|
|
|
|
// objects so we ignore the duplicate and just carry on.
|
|
|
|
wxBell();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exit. The duplicate will run in its own loop.
|
|
|
|
m_frame->PopTool( aEvent );
|
|
|
|
break;
|
|
|
|
}
|
2021-03-18 11:46:07 +00:00
|
|
|
else if( symbol && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2022-01-01 17:11:21 +00:00
|
|
|
symbol->SetPosition( cursorPos );
|
2023-06-12 18:33:52 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( symbol, false ); // Add, but not give ownership
|
2022-03-20 15:57:18 +00:00
|
|
|
m_frame->SetMsgPanel( symbol );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
2021-03-29 09:59:21 +00:00
|
|
|
else if( symbol && evt->IsAction( &ACTIONS::doDelete ) )
|
2021-03-15 14:23:17 +00:00
|
|
|
{
|
2021-03-29 09:59:21 +00:00
|
|
|
cleanup();
|
2021-03-15 14:23:17 +00:00
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( symbol && evt->IsAction( &ACTIONS::redo ) )
|
2023-06-16 20:44:16 +00:00
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-11-22 22:21:41 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-11-22 22:21:41 +00:00
|
|
|
}
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
// Enable autopanning and cursor capture only when there is a symbol to be placed
|
2021-03-18 11:46:07 +00:00
|
|
|
getViewControls()->SetAutoPan( symbol != nullptr );
|
|
|
|
getViewControls()->CaptureCursor( symbol != nullptr );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
getViewControls()->CaptureCursor( false );
|
2020-11-19 20:08:58 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2021-07-27 15:36:46 +00:00
|
|
|
|
2019-04-17 19:09:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
|
2019-04-26 22:23:12 +00:00
|
|
|
{
|
2022-05-16 22:41:30 +00:00
|
|
|
SCH_BITMAP* image = aEvent.Parameter<SCH_BITMAP*>();
|
|
|
|
bool immediateMode = image != nullptr;
|
|
|
|
bool ignorePrimePosition = false;
|
|
|
|
COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2023-11-19 14:17:36 +00:00
|
|
|
if( m_inDrawingTool )
|
2021-01-27 19:50:07 +00:00
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
2023-11-19 14:17:36 +00:00
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-01-27 19:50:07 +00:00
|
|
|
|
2023-08-23 15:13:46 +00:00
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
VECTOR2I cursorPos;
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// Add all the drawable symbols to preview
|
2019-04-26 22:23:12 +00:00
|
|
|
if( image )
|
|
|
|
{
|
2022-05-16 22:41:30 +00:00
|
|
|
image->SetPosition( getViewControls()->GetCursorPosition() );
|
2019-04-26 22:23:12 +00:00
|
|
|
m_view->ClearPreview();
|
2022-09-19 14:39:17 +00:00
|
|
|
m_view->AddToPreview( image, false ); // Add, but not give ownership
|
2019-04-26 22:23:12 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2022-03-28 20:16:47 +00:00
|
|
|
|
2020-10-08 16:57:24 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
2020-10-08 02:47:01 +00:00
|
|
|
{
|
|
|
|
if( image )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
|
|
|
|
else
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
|
|
|
};
|
|
|
|
|
2021-03-29 10:04:06 +00:00
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2021-03-29 10:04:06 +00:00
|
|
|
m_view->ClearPreview();
|
2023-02-17 00:29:27 +00:00
|
|
|
m_view->RecacheAllItems();
|
2021-03-29 10:04:06 +00:00
|
|
|
delete image;
|
|
|
|
image = nullptr;
|
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
Activate();
|
2022-08-26 17:34:46 +00:00
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
getViewControls()->ShowCursor( true );
|
2022-08-26 17:34:46 +00:00
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2021-03-29 10:04:06 +00:00
|
|
|
// Prime the pump
|
|
|
|
if( image )
|
2022-05-16 22:41:30 +00:00
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2022-05-16 22:41:30 +00:00
|
|
|
}
|
|
|
|
else if( aEvent.HasPosition() )
|
|
|
|
{
|
2022-05-16 09:22:55 +00:00
|
|
|
m_toolMgr->PrimeTool( aEvent.Position() );
|
2022-05-16 22:41:30 +00:00
|
|
|
}
|
|
|
|
else if( common_settings->m_Input.immediate_actions && !aEvent.IsReactivate() )
|
|
|
|
{
|
|
|
|
m_toolMgr->PrimeTool( { 0, 0 } );
|
|
|
|
ignorePrimePosition = true;
|
|
|
|
}
|
2021-03-29 10:04:06 +00:00
|
|
|
|
2019-04-26 22:23:12 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-26 22:23:12 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2023-08-23 15:13:46 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
|
|
|
|
|
|
|
cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_GRAPHICS );
|
|
|
|
controls->ForceCursorPosition( true, cursorPos );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2022-06-09 15:53:24 +00:00
|
|
|
// The tool hotkey is interpreted as a click when drawing
|
2022-09-14 17:31:56 +00:00
|
|
|
bool isSyntheticClick = image && evt->IsActivate() && evt->HasPosition()
|
|
|
|
&& evt->Matches( aEvent );
|
2022-06-09 15:53:24 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( evt->IsCancelInteractive() || ( image && evt->IsAction( &ACTIONS::undo ) ) )
|
2019-04-26 22:23:12 +00:00
|
|
|
{
|
2022-03-17 15:26:49 +00:00
|
|
|
m_frame->GetInfoBar()->Dismiss();
|
|
|
|
|
2019-04-26 22:23:12 +00:00
|
|
|
if( image )
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
2019-04-26 22:23:12 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
2019-04-26 22:23:12 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
|
|
|
|
if( immediateMode )
|
2019-06-18 17:56:40 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-06-27 11:47:24 +00:00
|
|
|
break;
|
2019-06-18 21:34:31 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2022-06-09 15:53:24 +00:00
|
|
|
else if( evt->IsActivate() && !isSyntheticClick )
|
2019-07-01 21:01:33 +00:00
|
|
|
{
|
2021-02-23 15:34:27 +00:00
|
|
|
if( image && evt->IsMoveTool() )
|
|
|
|
{
|
|
|
|
// we're already moving our own item; ignore the move tool
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( image )
|
2021-05-08 22:30:38 +00:00
|
|
|
{
|
|
|
|
m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel image creation." ) );
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsMoveTool() )
|
|
|
|
{
|
|
|
|
// leave ourselves on the stack so we come back after the move
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-06-18 17:56:40 +00:00
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2019-04-26 22:23:12 +00:00
|
|
|
}
|
2022-06-09 15:53:24 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) || isSyntheticClick )
|
2019-04-26 22:23:12 +00:00
|
|
|
{
|
|
|
|
if( !image )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2021-04-11 16:01:25 +00:00
|
|
|
|
2022-02-25 21:18:43 +00:00
|
|
|
wxFileDialog dlg( m_frame, _( "Choose Image" ), m_mruPath, wxEmptyString,
|
2020-11-22 22:21:41 +00:00
|
|
|
_( "Image Files" ) + wxS( " " ) + wxImage::GetImageExtWildcard(),
|
|
|
|
wxFD_OPEN );
|
2019-05-10 16:48:46 +00:00
|
|
|
|
2019-04-26 22:23:12 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
continue;
|
|
|
|
|
2022-05-16 22:41:30 +00:00
|
|
|
// If we started with a hotkey which has a position then warp back to that.
|
|
|
|
// Otherwise update to the current mouse position pinned inside the autoscroll
|
|
|
|
// boundaries.
|
|
|
|
if( evt->IsPrime() && !ignorePrimePosition )
|
|
|
|
{
|
|
|
|
cursorPos = grid.Align( evt->Position() );
|
|
|
|
getViewControls()->WarpMouseCursor( cursorPos, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
getViewControls()->PinCursorInsideNonAutoscrollArea( true );
|
|
|
|
cursorPos = getViewControls()->GetMousePosition();
|
|
|
|
}
|
2019-04-26 22:23:12 +00:00
|
|
|
|
|
|
|
wxString fullFilename = dlg.GetPath();
|
2022-02-25 21:18:43 +00:00
|
|
|
m_mruPath = wxPathOnly( fullFilename );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2019-05-01 20:15:51 +00:00
|
|
|
if( wxFileExists( fullFilename ) )
|
2022-01-01 17:11:21 +00:00
|
|
|
image = new SCH_BITMAP( cursorPos );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2019-05-01 20:15:51 +00:00
|
|
|
if( !image || !image->ReadImageFile( fullFilename ) )
|
2019-04-26 22:23:12 +00:00
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
|
2019-04-26 22:23:12 +00:00
|
|
|
delete image;
|
2019-05-01 20:15:51 +00:00
|
|
|
image = nullptr;
|
2019-04-26 22:23:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-05-30 21:04:07 +00:00
|
|
|
image->SetFlags( IS_NEW | IS_MOVING );
|
2019-05-03 08:48:53 +00:00
|
|
|
|
2019-05-10 16:48:46 +00:00
|
|
|
m_frame->SaveCopyForRepeatItem( image );
|
2019-05-03 08:48:53 +00:00
|
|
|
|
2019-04-26 22:23:12 +00:00
|
|
|
m_view->ClearPreview();
|
2022-09-19 14:39:17 +00:00
|
|
|
m_view->AddToPreview( image, false ); // Add, but not give ownership
|
2023-06-12 18:33:52 +00:00
|
|
|
m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
|
2019-05-03 10:16:24 +00:00
|
|
|
|
2019-05-01 20:15:51 +00:00
|
|
|
m_selectionTool->AddItemToSel( image );
|
2019-04-29 21:17:26 +00:00
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
getViewControls()->SetCursorPosition( cursorPos, false );
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2019-04-26 22:23:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2023-06-12 18:33:52 +00:00
|
|
|
commit.Add( image, m_frame->GetScreen() );
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Push( _( "Add Image" ) );
|
|
|
|
|
2019-04-26 22:23:12 +00:00
|
|
|
image = nullptr;
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::activatePointEditor );
|
2019-05-01 20:15:51 +00:00
|
|
|
|
|
|
|
m_view->ClearPreview();
|
2019-06-15 00:29:42 +00:00
|
|
|
|
|
|
|
if( immediateMode )
|
2019-07-01 21:01:33 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-06-15 00:29:42 +00:00
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2019-04-26 22:23:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2019-04-29 17:50:46 +00:00
|
|
|
// Warp after context menu only if dragging...
|
|
|
|
if( !image )
|
|
|
|
m_toolMgr->VetoContextMenuMouseWarp();
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
2019-04-26 22:23:12 +00:00
|
|
|
}
|
2024-02-15 12:36:36 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::duplicate )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::repeatDrawItem ) )
|
|
|
|
{
|
|
|
|
if( image )
|
|
|
|
{
|
|
|
|
// This doesn't really make sense; we'll just end up dragging a stack of
|
|
|
|
// objects so we ignore the duplicate and just carry on.
|
|
|
|
wxBell();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exit. The duplicate will run in its own loop.
|
|
|
|
m_frame->PopTool( aEvent );
|
|
|
|
break;
|
|
|
|
}
|
2019-07-04 20:56:21 +00:00
|
|
|
else if( image && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
|
2019-04-26 22:23:12 +00:00
|
|
|
{
|
2022-01-01 17:11:21 +00:00
|
|
|
image->SetPosition( cursorPos );
|
2019-04-26 22:23:12 +00:00
|
|
|
m_view->ClearPreview();
|
2022-09-19 14:39:17 +00:00
|
|
|
m_view->AddToPreview( image, false ); // Add, but not give ownership
|
2023-06-12 18:33:52 +00:00
|
|
|
m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
|
2022-03-20 15:57:18 +00:00
|
|
|
m_frame->SetMsgPanel( image );
|
2019-04-26 22:23:12 +00:00
|
|
|
}
|
2021-03-29 10:04:06 +00:00
|
|
|
else if( image && evt->IsAction( &ACTIONS::doDelete ) )
|
2021-03-15 14:23:17 +00:00
|
|
|
{
|
2021-03-29 09:59:21 +00:00
|
|
|
cleanup();
|
2021-03-15 14:23:17 +00:00
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( image && evt->IsAction( &ACTIONS::redo ) )
|
2023-06-16 20:44:16 +00:00
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-11-22 22:21:41 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-11-22 22:21:41 +00:00
|
|
|
}
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
// Enable autopanning and cursor capture only when there is an image to be placed
|
2019-06-18 17:56:40 +00:00
|
|
|
getViewControls()->SetAutoPan( image != nullptr );
|
|
|
|
getViewControls()->CaptureCursor( image != nullptr );
|
2019-04-26 22:23:12 +00:00
|
|
|
}
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
getViewControls()->CaptureCursor( false );
|
2020-11-19 20:08:58 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2021-07-27 15:36:46 +00:00
|
|
|
|
2019-04-26 22:23:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-29 02:57:21 +00:00
|
|
|
int SCH_DRAWING_TOOLS::ImportGraphics( const TOOL_EVENT& aEvent )
|
2023-10-09 03:56:13 +00:00
|
|
|
{
|
2023-11-19 14:17:36 +00:00
|
|
|
if( m_inDrawingTool )
|
2023-10-09 03:56:13 +00:00
|
|
|
return 0;
|
|
|
|
|
2023-11-19 14:17:36 +00:00
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2023-10-09 03:56:13 +00:00
|
|
|
|
|
|
|
// Note: PlaceImportedGraphics() will convert PCB_SHAPE_T and PCB_TEXT_T to footprint
|
|
|
|
// items if needed
|
|
|
|
DIALOG_IMPORT_GFX_SCH dlg( m_frame );
|
|
|
|
int dlgResult = dlg.ShowModal();
|
|
|
|
|
|
|
|
std::list<std::unique_ptr<EDA_ITEM>>& list = dlg.GetImportedItems();
|
|
|
|
|
|
|
|
if( dlgResult != wxID_OK )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Ensure the list is not empty:
|
|
|
|
if( list.empty() )
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "No graphic items found in file." ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( ACTIONS::cancelInteractive );
|
|
|
|
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
std::vector<SCH_ITEM*> newItems; // all new items, including group
|
|
|
|
std::vector<SCH_ITEM*> selectedItems; // the group, or newItems if no group
|
|
|
|
EE_SELECTION preview;
|
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
|
|
|
|
for( std::unique_ptr<EDA_ITEM>& ptr : list )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( ptr.get() );
|
|
|
|
wxCHECK2( item, continue );
|
|
|
|
|
|
|
|
newItems.push_back( item );
|
|
|
|
selectedItems.push_back( item );
|
|
|
|
preview.Add( item );
|
|
|
|
|
|
|
|
ptr.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !dlg.IsPlacementInteractive() )
|
|
|
|
{
|
|
|
|
// Place the imported drawings
|
|
|
|
for( SCH_ITEM* item : newItems )
|
|
|
|
commit.Add(item, m_frame->GetScreen());
|
|
|
|
|
|
|
|
commit.Push( _( "Import Graphic" ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_view->Add( &preview );
|
|
|
|
|
|
|
|
// Clear the current selection then select the drawings so that edit tools work on them
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
|
|
|
|
|
|
|
EDA_ITEMS selItems( selectedItems.begin(), selectedItems.end() );
|
|
|
|
m_toolMgr->RunAction<EDA_ITEMS*>( EE_ACTIONS::addItemsToSel, &selItems );
|
|
|
|
|
|
|
|
m_frame->PushTool( aEvent );
|
|
|
|
|
|
|
|
auto setCursor = [&]()
|
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
|
|
|
|
};
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
controls->ShowCursor( true );
|
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
|
|
|
//SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
|
|
|
|
// Now move the new items to the current cursor position:
|
|
|
|
VECTOR2I cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
|
|
|
|
VECTOR2I delta = cursorPos;
|
|
|
|
VECTOR2I currentOffset;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : selectedItems )
|
|
|
|
item->Move( delta );
|
|
|
|
|
|
|
|
currentOffset += delta;
|
|
|
|
|
|
|
|
m_view->Update( &preview );
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
|
|
|
{
|
|
|
|
setCursor();
|
|
|
|
|
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
|
|
|
|
|
|
|
cursorPos = grid.Align( controls->GetMousePosition(), GRID_GRAPHICS );
|
|
|
|
controls->ForceCursorPosition( true, cursorPos );
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() || evt->IsActivate() )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : newItems )
|
|
|
|
delete item;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsMotion() )
|
|
|
|
{
|
|
|
|
delta = cursorPos - currentOffset;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : selectedItems )
|
|
|
|
item->Move( delta );
|
|
|
|
|
|
|
|
currentOffset += delta;
|
|
|
|
|
|
|
|
m_view->Update( &preview );
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
// Place the imported drawings
|
|
|
|
for( SCH_ITEM* item : newItems )
|
|
|
|
commit.Add( item, m_frame->GetScreen() );
|
|
|
|
|
|
|
|
commit.Push( _( "Import Graphic" ) );
|
|
|
|
break; // This is a one-shot command, not a tool
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
preview.Clear();
|
|
|
|
m_view->Remove( &preview );
|
|
|
|
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
|
|
|
|
m_frame->PopTool( aEvent );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
VECTOR2I cursorPos;
|
2021-02-21 15:44:38 +00:00
|
|
|
KICAD_T type = aEvent.Parameter<KICAD_T>();
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
2021-01-31 23:16:36 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
2021-02-21 15:44:38 +00:00
|
|
|
SCH_ITEM* previewItem;
|
2021-02-23 12:49:38 +00:00
|
|
|
bool loggedInfoBarError = false;
|
2023-06-09 16:24:49 +00:00
|
|
|
wxString description;
|
2023-06-12 18:33:52 +00:00
|
|
|
SCH_SCREEN* screen = m_frame->GetScreen();
|
2023-09-17 07:37:34 +00:00
|
|
|
bool allowRepeat = false; // Set to true to allow new item repetition
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2023-11-19 14:17:36 +00:00
|
|
|
if( m_inDrawingTool )
|
2021-01-27 19:50:07 +00:00
|
|
|
return 0;
|
|
|
|
|
2023-11-19 14:17:36 +00:00
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-07-27 15:36:46 +00:00
|
|
|
|
2019-06-28 18:32:18 +00:00
|
|
|
if( type == SCH_JUNCTION_T && aEvent.HasPosition() )
|
|
|
|
{
|
|
|
|
EE_SELECTION& selection = m_selectionTool->GetSelection();
|
|
|
|
SCH_LINE* wire = dynamic_cast<SCH_LINE*>( selection.Front() );
|
|
|
|
|
|
|
|
if( wire )
|
|
|
|
{
|
|
|
|
SEG seg( wire->GetStartPoint(), wire->GetEndPoint() );
|
|
|
|
VECTOR2I nearest = seg.NearestPoint( getViewControls()->GetCursorPosition() );
|
|
|
|
getViewControls()->SetCrossHairCursorPosition( nearest, false );
|
2022-05-16 22:41:30 +00:00
|
|
|
getViewControls()->WarpMouseCursor( getViewControls()->GetCursorPosition(), true );
|
2019-06-15 00:29:42 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-28 18:32:18 +00:00
|
|
|
|
2019-11-23 23:34:35 +00:00
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
case SCH_NO_CONNECT_T:
|
|
|
|
previewItem = new SCH_NO_CONNECT( cursorPos );
|
2023-06-12 18:33:52 +00:00
|
|
|
previewItem->SetParent( screen );
|
2023-06-09 16:24:49 +00:00
|
|
|
description = _( "Add No Connect Flag" );
|
2023-09-17 07:37:34 +00:00
|
|
|
allowRepeat = true;
|
2019-11-23 23:34:35 +00:00
|
|
|
break;
|
2021-02-21 15:44:38 +00:00
|
|
|
|
2019-11-23 23:34:35 +00:00
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
previewItem = new SCH_JUNCTION( cursorPos );
|
2023-06-12 18:33:52 +00:00
|
|
|
previewItem->SetParent( screen );
|
2023-06-09 16:24:49 +00:00
|
|
|
description = _( "Add Junction" );
|
2019-11-23 23:34:35 +00:00
|
|
|
break;
|
2021-02-21 15:44:38 +00:00
|
|
|
|
2019-11-23 23:34:35 +00:00
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
2020-06-30 01:08:33 +00:00
|
|
|
previewItem = new SCH_BUS_WIRE_ENTRY( cursorPos );
|
2023-06-12 18:33:52 +00:00
|
|
|
previewItem->SetParent( screen );
|
2023-06-09 16:24:49 +00:00
|
|
|
description = _( "Add Wire to Bus Entry" );
|
2023-09-17 07:37:34 +00:00
|
|
|
allowRepeat = true;
|
2019-11-23 23:34:35 +00:00
|
|
|
break;
|
2021-02-21 15:44:38 +00:00
|
|
|
|
2019-11-23 23:34:35 +00:00
|
|
|
default:
|
|
|
|
wxASSERT_MSG( false, "Unknown item type in SCH_DRAWING_TOOLS::SingleClickPlace" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2021-02-21 15:44:38 +00:00
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
cursorPos = aEvent.HasPosition() ? aEvent.Position() : controls->GetMousePosition();
|
2019-06-28 18:32:18 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2021-09-13 12:23:10 +00:00
|
|
|
|
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PLACE );
|
|
|
|
};
|
|
|
|
|
2019-04-17 19:09:48 +00:00
|
|
|
Activate();
|
2022-08-26 17:34:46 +00:00
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
getViewControls()->ShowCursor( true );
|
2022-08-26 17:34:46 +00:00
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2021-02-21 15:44:38 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( previewItem->Clone() );
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
// Prime the pump
|
2021-02-21 15:44:38 +00:00
|
|
|
if( aEvent.HasPosition() && type != SCH_SHEET_PIN_T )
|
2022-05-16 09:22:55 +00:00
|
|
|
m_toolMgr->PrimeTool( aEvent.Position() );
|
2020-10-08 18:55:44 +00:00
|
|
|
else
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2019-06-15 00:29:42 +00:00
|
|
|
|
2019-04-17 19:09:48 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2021-01-31 23:16:36 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2021-05-09 19:17:01 +00:00
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2021-01-31 23:16:36 +00:00
|
|
|
|
2022-08-30 14:13:51 +00:00
|
|
|
cursorPos = evt->IsPrime() ? evt->Position() : controls->GetMousePosition();
|
2023-07-23 17:51:42 +00:00
|
|
|
cursorPos = grid.BestSnapAnchor( cursorPos, grid.GetItemGrid( previewItem ), nullptr );
|
2021-01-31 23:16:36 +00:00
|
|
|
controls->ForceCursorPosition( true, cursorPos );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-04-17 19:09:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
if( evt->IsMoveTool() )
|
|
|
|
{
|
|
|
|
// leave ourselves on the stack so we come back after the move
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-10-07 17:05:09 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2023-06-12 18:33:52 +00:00
|
|
|
if( !screen->GetItem( cursorPos, 0, type ) )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2021-02-23 12:49:38 +00:00
|
|
|
if( type == SCH_JUNCTION_T )
|
|
|
|
{
|
2023-06-12 18:33:52 +00:00
|
|
|
if( !screen->IsExplicitJunctionAllowed( cursorPos ) )
|
2021-02-23 12:49:38 +00:00
|
|
|
{
|
|
|
|
m_frame->ShowInfoBarError( _( "Junction location contains no joinable "
|
|
|
|
"wires and/or pins." ) );
|
|
|
|
loggedInfoBarError = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if( loggedInfoBarError )
|
|
|
|
{
|
|
|
|
m_frame->GetInfoBar()->Dismiss();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-08 17:03:58 +00:00
|
|
|
SCH_ITEM* newItem = static_cast<SCH_ITEM*>( previewItem->Clone() );
|
2022-10-07 23:32:20 +00:00
|
|
|
const_cast<KIID&>( newItem->m_Uuid ) = KIID();
|
2020-10-08 17:03:58 +00:00
|
|
|
newItem->SetPosition( cursorPos );
|
|
|
|
newItem->SetFlags( IS_NEW );
|
2023-08-03 14:04:36 +00:00
|
|
|
m_frame->AddToScreen( newItem, screen );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2023-09-17 07:37:34 +00:00
|
|
|
if( allowRepeat )
|
|
|
|
m_frame->SaveCopyForRepeatItem( newItem );
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2023-08-03 14:04:36 +00:00
|
|
|
commit.Added( newItem, screen );
|
2021-02-21 15:44:38 +00:00
|
|
|
|
2023-06-23 18:59:18 +00:00
|
|
|
m_frame->SchematicCleanUp( &commit );
|
2020-10-08 17:03:58 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Push( description );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
2020-10-07 17:05:09 +00:00
|
|
|
|
2021-02-21 15:44:38 +00:00
|
|
|
if( evt->IsDblClick( BUT_LEFT ) || type == SCH_SHEET_PIN_T ) // Finish tool.
|
2020-10-07 17:05:09 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2020-10-07 17:05:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
2019-07-04 20:56:21 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() )
|
2019-06-28 18:32:18 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
previewItem->SetPosition( cursorPos );
|
2019-06-28 18:32:18 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( previewItem->Clone() );
|
2022-03-20 15:57:18 +00:00
|
|
|
m_frame->SetMsgPanel( previewItem );
|
2019-06-28 18:32:18 +00:00
|
|
|
}
|
2019-10-30 23:20:11 +00:00
|
|
|
else if( evt->Category() == TC_COMMAND )
|
|
|
|
{
|
2022-05-02 21:31:17 +00:00
|
|
|
if( ( type == SCH_BUS_WIRE_ENTRY_T ) && ( evt->IsAction( &EE_ACTIONS::rotateCW )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::rotateCCW )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::mirrorV )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::mirrorH ) ) )
|
2019-10-30 23:20:11 +00:00
|
|
|
{
|
2019-11-23 23:34:35 +00:00
|
|
|
SCH_BUS_ENTRY_BASE* busItem = static_cast<SCH_BUS_ENTRY_BASE*>( previewItem );
|
|
|
|
|
|
|
|
// The bus entries only rotate in one direction
|
|
|
|
if( evt->IsAction( &EE_ACTIONS::rotateCW )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::rotateCCW ) )
|
2020-10-08 16:57:24 +00:00
|
|
|
{
|
2019-11-23 23:34:35 +00:00
|
|
|
busItem->Rotate( busItem->GetPosition() );
|
2020-10-08 16:57:24 +00:00
|
|
|
}
|
2021-02-16 20:45:25 +00:00
|
|
|
else if( evt->IsAction( &EE_ACTIONS::mirrorV ) )
|
2020-10-08 16:57:24 +00:00
|
|
|
{
|
2023-05-25 00:02:45 +00:00
|
|
|
busItem->MirrorVertically( busItem->GetPosition().y );
|
2020-10-08 16:57:24 +00:00
|
|
|
}
|
2021-02-16 20:45:25 +00:00
|
|
|
else if( evt->IsAction( &EE_ACTIONS::mirrorH ) )
|
2020-10-08 16:57:24 +00:00
|
|
|
{
|
2023-05-25 00:02:45 +00:00
|
|
|
busItem->MirrorHorizontally( busItem->GetPosition().x );
|
2020-10-08 16:57:24 +00:00
|
|
|
}
|
2019-10-30 23:20:11 +00:00
|
|
|
|
2019-11-23 23:34:35 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( previewItem->Clone() );
|
2019-10-30 23:20:11 +00:00
|
|
|
}
|
2020-10-08 17:03:58 +00:00
|
|
|
else if( evt->IsAction( &EE_ACTIONS::properties ) )
|
|
|
|
{
|
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
|
|
|
{
|
|
|
|
std::deque<SCH_ITEM*> strokeItems;
|
|
|
|
strokeItems.push_back( previewItem );
|
|
|
|
|
2022-03-16 13:43:19 +00:00
|
|
|
DIALOG_WIRE_BUS_PROPERTIES dlg( m_frame, strokeItems );
|
2020-10-08 17:03:58 +00:00
|
|
|
}
|
2020-10-09 01:15:03 +00:00
|
|
|
break;
|
2020-10-08 17:03:58 +00:00
|
|
|
|
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
{
|
|
|
|
std::deque<SCH_JUNCTION*> junctions;
|
|
|
|
junctions.push_back( static_cast<SCH_JUNCTION*>( previewItem ) );
|
|
|
|
|
|
|
|
DIALOG_JUNCTION_PROPS dlg( m_frame, junctions );
|
|
|
|
}
|
|
|
|
break;
|
2020-10-09 01:15:03 +00:00
|
|
|
default:
|
|
|
|
// Do nothing
|
|
|
|
break;
|
2020-10-08 17:03:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( previewItem->Clone() );
|
|
|
|
}
|
2020-10-08 16:57:24 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
}
|
2019-10-30 23:20:11 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-10-08 16:57:24 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-10-08 16:57:24 +00:00
|
|
|
}
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
2019-06-28 18:32:18 +00:00
|
|
|
delete previewItem;
|
|
|
|
m_view->ClearPreview();
|
|
|
|
|
2020-11-19 20:08:58 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2021-02-23 21:27:15 +00:00
|
|
|
controls->ForceCursorPosition( false );
|
2021-07-27 15:36:46 +00:00
|
|
|
|
2019-04-17 19:09:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-24 11:35:14 +00:00
|
|
|
SCH_LINE* SCH_DRAWING_TOOLS::findWire( const VECTOR2I& aPosition )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : m_frame->GetScreen()->Items().Overlapping( SCH_LINE_T, aPosition ) )
|
|
|
|
{
|
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( item );
|
|
|
|
|
|
|
|
if( line->GetEditFlags() & STRUCT_DELETED )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( line->IsWire() )
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-23 15:50:08 +00:00
|
|
|
SCH_TEXT* SCH_DRAWING_TOOLS::createNewText( const VECTOR2I& aPosition, int aType )
|
|
|
|
{
|
|
|
|
SCHEMATIC* schematic = getModel<SCHEMATIC>();
|
|
|
|
SCHEMATIC_SETTINGS& settings = schematic->Settings();
|
|
|
|
SCH_TEXT* textItem = nullptr;
|
2022-01-24 13:40:39 +00:00
|
|
|
SCH_LABEL_BASE* labelItem = nullptr;
|
2023-06-24 11:35:14 +00:00
|
|
|
wxString netName;
|
2020-05-23 15:50:08 +00:00
|
|
|
|
|
|
|
switch( aType )
|
|
|
|
{
|
|
|
|
case LAYER_NOTES:
|
2022-01-01 17:11:21 +00:00
|
|
|
textItem = new SCH_TEXT( aPosition );
|
2020-05-23 15:50:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_LOCLABEL:
|
2022-01-24 13:40:39 +00:00
|
|
|
labelItem = new SCH_LABEL( aPosition );
|
|
|
|
textItem = labelItem;
|
2023-06-24 11:35:14 +00:00
|
|
|
|
|
|
|
if( SCH_LINE* wire = findWire( aPosition ) )
|
|
|
|
netName = wire->GetNetname( m_frame->GetCurrentSheet() );
|
|
|
|
|
2020-05-23 15:50:08 +00:00
|
|
|
break;
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
case LAYER_NETCLASS_REFS:
|
2022-01-24 13:40:39 +00:00
|
|
|
labelItem = new SCH_DIRECTIVE_LABEL( aPosition );
|
|
|
|
labelItem->SetShape( m_lastNetClassFlagShape );
|
|
|
|
labelItem->GetFields().emplace_back( SCH_FIELD( {0,0}, 0, labelItem, wxT( "Netclass" ) ) );
|
|
|
|
labelItem->GetFields().back().SetItalic( true );
|
|
|
|
labelItem->GetFields().back().SetVisible( true );
|
|
|
|
textItem = labelItem;
|
2021-10-12 20:05:37 +00:00
|
|
|
break;
|
|
|
|
|
2020-05-23 15:50:08 +00:00
|
|
|
case LAYER_HIERLABEL:
|
2022-01-24 13:40:39 +00:00
|
|
|
labelItem = new SCH_HIERLABEL( aPosition );
|
|
|
|
labelItem->SetShape( m_lastGlobalLabelShape );
|
2022-03-26 16:27:45 +00:00
|
|
|
labelItem->SetAutoRotateOnPlacement( m_lastAutoLabelRotateOnPlacement );
|
2022-01-24 13:40:39 +00:00
|
|
|
textItem = labelItem;
|
2020-05-23 15:50:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_GLOBLABEL:
|
2022-01-24 13:40:39 +00:00
|
|
|
labelItem = new SCH_GLOBALLABEL( aPosition );
|
|
|
|
labelItem->SetShape( m_lastGlobalLabelShape );
|
2022-05-01 17:38:39 +00:00
|
|
|
labelItem->GetFields()[0].SetVisible( settings.m_IntersheetRefsShow );
|
2022-03-26 16:27:45 +00:00
|
|
|
labelItem->SetAutoRotateOnPlacement( m_lastAutoLabelRotateOnPlacement );
|
2022-01-24 13:40:39 +00:00
|
|
|
textItem = labelItem;
|
2023-06-24 11:35:14 +00:00
|
|
|
|
|
|
|
if( SCH_LINE* wire = findWire( aPosition ) )
|
|
|
|
netName = wire->GetNetname( m_frame->GetCurrentSheet() );
|
|
|
|
|
2020-05-23 15:50:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-08-31 13:19:57 +00:00
|
|
|
wxFAIL_MSG( "SCH_EDIT_FRAME::CreateNewText() unknown layer type" );
|
2020-05-23 15:50:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
textItem->SetParent( schematic );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2024-02-25 17:28:05 +00:00
|
|
|
textItem->SetTextSize( VECTOR2I( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
|
|
|
|
|
2022-09-22 00:05:51 +00:00
|
|
|
if( aType != LAYER_NETCLASS_REFS )
|
|
|
|
{
|
2024-02-25 17:28:05 +00:00
|
|
|
// Must be after SetTextSize()
|
2022-09-22 00:05:51 +00:00
|
|
|
textItem->SetBold( m_lastTextBold );
|
2021-10-12 20:05:37 +00:00
|
|
|
textItem->SetItalic( m_lastTextItalic );
|
2022-09-22 00:05:51 +00:00
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2023-09-07 16:09:53 +00:00
|
|
|
if( labelItem )
|
2023-11-07 15:45:48 +00:00
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
labelItem->SetSpinStyle( m_lastTextOrientation );
|
2023-11-07 15:45:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textItem->SetHorizJustify( m_lastTextHJustify );
|
|
|
|
textItem->SetVertJustify( m_lastTextVJustify );
|
|
|
|
textItem->SetTextAngle( m_lastTextAngle );
|
|
|
|
}
|
2023-09-07 16:09:53 +00:00
|
|
|
|
2021-05-30 21:04:07 +00:00
|
|
|
textItem->SetFlags( IS_NEW | IS_MOVING );
|
2020-05-23 15:50:08 +00:00
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
if( !labelItem )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
DIALOG_TEXT_PROPERTIES dlg( m_frame, textItem );
|
|
|
|
|
2023-05-24 11:08:52 +00:00
|
|
|
// QuasiModal required for syntax help and Scintilla auto-complete
|
2021-10-12 20:05:37 +00:00
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
|
|
|
{
|
|
|
|
delete textItem;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2023-06-24 11:35:14 +00:00
|
|
|
else if( !netName.IsEmpty() )
|
|
|
|
{
|
|
|
|
// Auto-create from attached wire
|
|
|
|
textItem->SetText( netName );
|
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DIALOG_LABEL_PROPERTIES dlg( m_frame, static_cast<SCH_LABEL_BASE*>( textItem ) );
|
|
|
|
|
|
|
|
// Must be quasi modal for syntax help
|
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
|
|
|
{
|
2022-01-24 13:40:39 +00:00
|
|
|
delete labelItem;
|
2021-10-12 20:05:37 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2020-05-23 15:50:08 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
wxString text = textItem->GetText();
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
if( textItem->Type() != SCH_DIRECTIVE_LABEL_T && NoPrintableChars( text ) )
|
2020-05-23 15:50:08 +00:00
|
|
|
{
|
|
|
|
delete textItem;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-09-22 00:05:51 +00:00
|
|
|
if( aType != LAYER_NETCLASS_REFS )
|
|
|
|
{
|
|
|
|
m_lastTextBold = textItem->IsBold();
|
2021-10-12 20:05:37 +00:00
|
|
|
m_lastTextItalic = textItem->IsItalic();
|
2022-09-22 00:05:51 +00:00
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2023-09-07 16:09:53 +00:00
|
|
|
if( labelItem )
|
2023-11-07 15:45:48 +00:00
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
m_lastTextOrientation = labelItem->GetSpinStyle();
|
2023-11-07 15:45:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_lastTextHJustify = textItem->GetHorizJustify();
|
|
|
|
m_lastTextVJustify = textItem->GetVertJustify();
|
|
|
|
m_lastTextAngle = textItem->GetTextAngle();
|
|
|
|
}
|
2020-05-23 15:50:08 +00:00
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
if( aType == LAYER_GLOBLABEL || aType == LAYER_HIERLABEL )
|
2022-03-26 16:27:45 +00:00
|
|
|
{
|
2022-01-24 13:40:39 +00:00
|
|
|
m_lastGlobalLabelShape = labelItem->GetShape();
|
2022-03-26 16:27:45 +00:00
|
|
|
m_lastAutoLabelRotateOnPlacement = labelItem->AutoRotateOnPlacement();
|
|
|
|
}
|
2022-01-24 13:40:39 +00:00
|
|
|
else if( aType == LAYER_NETCLASS_REFS )
|
2022-03-26 16:27:45 +00:00
|
|
|
{
|
2022-01-24 13:40:39 +00:00
|
|
|
m_lastNetClassFlagShape = labelItem->GetShape();
|
2022-03-26 16:27:45 +00:00
|
|
|
}
|
2020-05-23 15:50:08 +00:00
|
|
|
|
|
|
|
return textItem;
|
|
|
|
}
|
|
|
|
|
2024-02-25 14:23:59 +00:00
|
|
|
SCH_SHEET_PIN* SCH_DRAWING_TOOLS::createNewSheetPin( SCH_SHEET* aSheet, const VECTOR2I& aPosition )
|
2020-10-31 00:25:46 +00:00
|
|
|
{
|
|
|
|
SCHEMATIC_SETTINGS& settings = aSheet->Schematic()->Settings();
|
2023-06-24 11:35:14 +00:00
|
|
|
SCH_SHEET_PIN* pin = new SCH_SHEET_PIN( aSheet );
|
2020-10-31 00:25:46 +00:00
|
|
|
|
2023-06-24 11:35:14 +00:00
|
|
|
pin->SetFlags( IS_NEW | IS_MOVING );
|
2024-02-25 14:23:59 +00:00
|
|
|
pin->SetText( std::to_string( aSheet->GetPins().size() + 1 ) );
|
2023-06-24 11:35:14 +00:00
|
|
|
pin->SetTextSize( VECTOR2I( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
|
|
|
|
pin->SetPosition( aPosition );
|
|
|
|
pin->ClearSelected();
|
2020-10-31 00:25:46 +00:00
|
|
|
|
2023-06-24 11:35:14 +00:00
|
|
|
m_lastSheetPinType = pin->GetShape();
|
2020-10-31 00:25:46 +00:00
|
|
|
|
2023-06-24 11:35:14 +00:00
|
|
|
return pin;
|
2020-10-31 00:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2020-12-03 15:10:23 +00:00
|
|
|
SCH_ITEM* item = nullptr;
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
2022-03-07 12:45:24 +00:00
|
|
|
bool ignorePrimePosition = false;
|
2022-05-02 13:25:55 +00:00
|
|
|
COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
|
2022-12-29 14:32:10 +00:00
|
|
|
SCH_SHEET* sheet = nullptr;
|
2023-06-09 16:24:49 +00:00
|
|
|
wxString description;
|
2021-03-05 00:01:17 +00:00
|
|
|
|
2023-11-19 14:17:36 +00:00
|
|
|
if( m_inDrawingTool )
|
2021-01-27 19:50:07 +00:00
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
2023-11-19 14:17:36 +00:00
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-01-27 19:50:07 +00:00
|
|
|
|
2021-02-22 11:52:33 +00:00
|
|
|
bool isText = aEvent.IsAction( &EE_ACTIONS::placeSchematicText );
|
|
|
|
bool isGlobalLabel = aEvent.IsAction( &EE_ACTIONS::placeGlobalLabel );
|
|
|
|
bool isHierLabel = aEvent.IsAction( &EE_ACTIONS::placeHierLabel );
|
2021-10-12 20:05:37 +00:00
|
|
|
bool isClassLabel = aEvent.IsAction( &EE_ACTIONS::placeClassLabel );
|
2021-02-22 11:52:33 +00:00
|
|
|
bool isNetLabel = aEvent.IsAction( &EE_ACTIONS::placeLabel );
|
2024-02-25 14:23:59 +00:00
|
|
|
bool isSheetPin = aEvent.IsAction( &EE_ACTIONS::placeSheetPin );
|
2023-07-23 17:51:42 +00:00
|
|
|
|
|
|
|
GRID_HELPER_GRIDS snapGrid = isText ? GRID_TEXT : GRID_CONNECTABLE;
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2022-12-29 14:32:10 +00:00
|
|
|
// If we have a selected sheet use it, otherwise try to get one under the cursor
|
|
|
|
if( isSheetPin )
|
|
|
|
sheet = dynamic_cast<SCH_SHEET*>( m_selectionTool->GetSelection().Front() );
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2022-12-29 14:32:10 +00:00
|
|
|
|
2020-10-08 16:57:24 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
2020-10-08 02:47:01 +00:00
|
|
|
{
|
|
|
|
if( item )
|
2020-10-11 03:45:21 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PLACE );
|
2020-10-09 00:40:03 +00:00
|
|
|
else if( isText )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::TEXT );
|
|
|
|
else if( isGlobalLabel )
|
2020-10-10 22:25:28 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::LABEL_GLOBAL );
|
2020-10-09 00:40:03 +00:00
|
|
|
else if( isNetLabel )
|
2020-10-10 22:25:28 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::LABEL_NET );
|
2021-10-12 20:05:37 +00:00
|
|
|
else if( isClassLabel )
|
2022-01-25 22:33:37 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::LABEL_NET ); // JEY TODO: netclass directive cursor
|
2020-10-10 22:25:28 +00:00
|
|
|
else if( isHierLabel )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::LABEL_HIER );
|
2020-10-08 02:47:01 +00:00
|
|
|
else
|
2020-10-09 00:40:03 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
2020-10-08 02:47:01 +00:00
|
|
|
};
|
|
|
|
|
2021-04-02 10:18:25 +00:00
|
|
|
auto updatePreview =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( item->Clone() );
|
|
|
|
item->RunOnChildren( [&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
m_view->AddToPreview( aChild->Clone() );
|
|
|
|
} );
|
2022-03-20 15:57:18 +00:00
|
|
|
m_frame->SetMsgPanel( item );
|
2021-04-02 10:18:25 +00:00
|
|
|
};
|
|
|
|
|
2021-03-29 10:04:06 +00:00
|
|
|
auto cleanup =
|
2021-04-02 10:18:25 +00:00
|
|
|
[&]()
|
2021-03-29 10:04:06 +00:00
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2021-03-29 10:04:06 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
delete item;
|
|
|
|
item = nullptr;
|
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
Activate();
|
2022-08-26 17:34:46 +00:00
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
controls->ShowCursor( true );
|
2022-08-26 17:34:46 +00:00
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2022-03-07 12:45:24 +00:00
|
|
|
if( aEvent.HasPosition() )
|
2021-03-29 10:04:06 +00:00
|
|
|
{
|
2022-03-07 12:45:24 +00:00
|
|
|
m_toolMgr->PrimeTool( aEvent.Position() );
|
|
|
|
}
|
2022-05-16 09:22:55 +00:00
|
|
|
else if( common_settings->m_Input.immediate_actions && !aEvent.IsReactivate()
|
|
|
|
&& ( isText || isGlobalLabel || isHierLabel || isClassLabel || isNetLabel ) )
|
2022-03-07 12:45:24 +00:00
|
|
|
{
|
|
|
|
m_toolMgr->PrimeTool( { 0, 0 } );
|
|
|
|
ignorePrimePosition = true;
|
2021-03-29 10:04:06 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 19:09:48 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2020-12-03 15:10:23 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2021-05-09 19:17:01 +00:00
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2020-10-08 02:47:01 +00:00
|
|
|
|
2022-05-16 22:41:30 +00:00
|
|
|
VECTOR2I cursorPos = controls->GetMousePosition();
|
2023-07-23 17:51:42 +00:00
|
|
|
cursorPos = grid.BestSnapAnchor( cursorPos, snapGrid, item );
|
2021-02-23 15:28:45 +00:00
|
|
|
controls->ForceCursorPosition( true, cursorPos );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2022-06-09 15:53:24 +00:00
|
|
|
// The tool hotkey is interpreted as a click when drawing
|
2022-09-14 17:31:56 +00:00
|
|
|
bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition()
|
|
|
|
&& evt->Matches( aEvent );
|
2022-06-09 15:53:24 +00:00
|
|
|
|
2023-06-16 20:44:16 +00:00
|
|
|
if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2022-03-17 15:26:49 +00:00
|
|
|
m_frame->GetInfoBar()->Dismiss();
|
|
|
|
|
2019-04-17 19:09:48 +00:00
|
|
|
if( item )
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-06-09 15:53:24 +00:00
|
|
|
else if( evt->IsActivate() && !isSyntheticClick )
|
2019-07-01 21:01:33 +00:00
|
|
|
{
|
2021-02-23 15:34:27 +00:00
|
|
|
if( item && evt->IsMoveTool() )
|
|
|
|
{
|
|
|
|
// we're already moving our own item; ignore the move tool
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( item )
|
2021-05-08 22:30:38 +00:00
|
|
|
{
|
|
|
|
m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel item creation." ) );
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
|
|
|
|
if( evt->IsPointEditor() )
|
|
|
|
{
|
|
|
|
// don't exit (the point editor runs in the background)
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsMoveTool() )
|
2019-06-18 17:56:40 +00:00
|
|
|
{
|
2023-01-06 22:14:06 +00:00
|
|
|
// leave ourselves on the stack so we come back after the move
|
2019-06-27 11:47:24 +00:00
|
|
|
break;
|
2019-06-18 21:34:31 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-06-18 17:56:40 +00:00
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
2022-06-09 15:53:24 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) || isSyntheticClick )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-04-29 17:50:46 +00:00
|
|
|
// First click creates...
|
2019-04-17 19:09:48 +00:00
|
|
|
if( !item )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2021-02-22 11:52:33 +00:00
|
|
|
if( isText )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2021-02-23 17:49:52 +00:00
|
|
|
item = createNewText( cursorPos, LAYER_NOTES );
|
2023-06-09 16:24:49 +00:00
|
|
|
description = _( "Add Text" );
|
2021-02-22 11:52:33 +00:00
|
|
|
}
|
|
|
|
else if( isHierLabel )
|
|
|
|
{
|
2024-02-25 14:23:59 +00:00
|
|
|
if( m_dialogSyncSheetPin && m_dialogSyncSheetPin->GetPlacementTemplate() )
|
|
|
|
{
|
|
|
|
auto pin = static_cast<SCH_HIERLABEL*>(
|
|
|
|
m_dialogSyncSheetPin->GetPlacementTemplate() );
|
|
|
|
SCH_HIERLABEL* label = new SCH_HIERLABEL( cursorPos );
|
|
|
|
SCHEMATIC* schematic = getModel<SCHEMATIC>();
|
|
|
|
label->SetText( pin->GetText() );
|
|
|
|
label->SetShape( pin->GetShape() );
|
|
|
|
label->SetAutoRotateOnPlacement( m_lastAutoLabelRotateOnPlacement );
|
|
|
|
label->SetParent( schematic );
|
|
|
|
label->SetBold( m_lastTextBold );
|
|
|
|
label->SetItalic( m_lastTextItalic );
|
|
|
|
label->SetSpinStyle( m_lastTextOrientation );
|
|
|
|
label->SetTextSize( VECTOR2I( schematic->Settings().m_DefaultTextSize,
|
|
|
|
schematic->Settings().m_DefaultTextSize ) );
|
|
|
|
label->SetFlags( IS_NEW | IS_MOVING );
|
|
|
|
item = label;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item = createNewText( cursorPos, LAYER_HIERLABEL );
|
|
|
|
}
|
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
description = _( "Add Hierarchical Label" );
|
2021-02-22 11:52:33 +00:00
|
|
|
}
|
2023-06-24 11:35:14 +00:00
|
|
|
else if( isNetLabel )
|
2021-02-22 11:52:33 +00:00
|
|
|
{
|
2023-06-24 11:35:14 +00:00
|
|
|
item = createNewText( cursorPos, LAYER_LOCLABEL );
|
|
|
|
description = _( "Add Label" );
|
|
|
|
}
|
|
|
|
else if( isGlobalLabel )
|
|
|
|
{
|
|
|
|
item = createNewText( cursorPos, LAYER_GLOBLABEL );
|
2023-06-09 16:24:49 +00:00
|
|
|
description = _( "Add Label" );
|
2021-02-22 11:52:33 +00:00
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
else if( isClassLabel )
|
|
|
|
{
|
|
|
|
item = createNewText( cursorPos, LAYER_NETCLASS_REFS );
|
2023-06-09 16:24:49 +00:00
|
|
|
description = _( "Add Label" );
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
2021-02-22 11:52:33 +00:00
|
|
|
else if( isSheetPin )
|
2019-05-16 21:58:47 +00:00
|
|
|
{
|
2023-04-11 08:53:35 +00:00
|
|
|
EDA_ITEM* i = nullptr;
|
2020-05-27 15:18:12 +00:00
|
|
|
|
2022-12-29 14:32:10 +00:00
|
|
|
// If we didn't have a sheet selected, try to find one under the cursor
|
|
|
|
if( !sheet && m_selectionTool->SelectPoint( cursorPos, { SCH_SHEET_T }, &i ) )
|
2020-11-17 16:02:47 +00:00
|
|
|
sheet = dynamic_cast<SCH_SHEET*>( i );
|
2020-05-27 15:18:12 +00:00
|
|
|
|
2019-05-16 21:58:47 +00:00
|
|
|
if( !sheet )
|
2019-05-16 21:27:03 +00:00
|
|
|
{
|
2022-12-19 13:19:21 +00:00
|
|
|
m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( m_frame );
|
2019-05-16 21:58:47 +00:00
|
|
|
m_statusPopup->SetText( _( "Click over a sheet." ) );
|
2023-09-18 03:13:09 +00:00
|
|
|
m_statusPopup->Move( KIPLATFORM::UI::GetMousePosition()
|
|
|
|
+ wxPoint( 20, 20 ) );
|
2019-05-19 21:04:04 +00:00
|
|
|
m_statusPopup->PopupFor( 2000 );
|
2021-02-22 11:52:33 +00:00
|
|
|
item = nullptr;
|
2019-05-16 21:27:03 +00:00
|
|
|
}
|
2021-02-22 11:52:33 +00:00
|
|
|
else
|
2019-05-16 21:58:47 +00:00
|
|
|
{
|
2024-02-25 14:23:59 +00:00
|
|
|
item = createNewSheetPin( sheet, cursorPos );
|
2024-02-26 12:43:56 +00:00
|
|
|
|
2024-02-25 14:23:59 +00:00
|
|
|
if( m_dialogSyncSheetPin && m_dialogSyncSheetPin->GetPlacementTemplate() )
|
2019-05-16 21:58:47 +00:00
|
|
|
{
|
2024-02-25 14:23:59 +00:00
|
|
|
auto label = static_cast<SCH_HIERLABEL*>(
|
|
|
|
m_dialogSyncSheetPin->GetPlacementTemplate() );
|
|
|
|
auto pin = static_cast<SCH_HIERLABEL*>( item );
|
|
|
|
pin->SetText( label->GetText() );
|
|
|
|
pin->SetShape( label->GetShape() );
|
2019-05-16 21:58:47 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-09 16:24:49 +00:00
|
|
|
|
|
|
|
description = _( "Add Sheet Pin" );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-16 22:41:30 +00:00
|
|
|
// If we started with a hotkey which has a position then warp back to that.
|
|
|
|
// Otherwise update to the current mouse position pinned inside the autoscroll
|
|
|
|
// boundaries.
|
|
|
|
if( evt->IsPrime() && !ignorePrimePosition )
|
|
|
|
{
|
|
|
|
cursorPos = grid.Align( evt->Position() );
|
|
|
|
getViewControls()->WarpMouseCursor( cursorPos, true );
|
|
|
|
}
|
2022-03-07 12:45:24 +00:00
|
|
|
else
|
2022-05-16 22:41:30 +00:00
|
|
|
{
|
|
|
|
getViewControls()->PinCursorInsideNonAutoscrollArea( true );
|
|
|
|
cursorPos = getViewControls()->GetMousePosition();
|
2023-07-23 17:51:42 +00:00
|
|
|
cursorPos = grid.BestSnapAnchor( cursorPos, snapGrid, item );
|
2022-05-16 22:41:30 +00:00
|
|
|
}
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
if( item )
|
|
|
|
{
|
2022-03-07 12:45:24 +00:00
|
|
|
item->SetPosition( cursorPos );
|
|
|
|
|
2021-05-30 21:04:07 +00:00
|
|
|
item->SetFlags( IS_NEW | IS_MOVING );
|
2023-06-13 12:20:47 +00:00
|
|
|
item->AutoplaceFields( nullptr, false /* aManual */ );
|
2021-04-02 10:18:25 +00:00
|
|
|
updatePreview();
|
2024-02-25 14:23:59 +00:00
|
|
|
m_selectionTool->AddItemToSel( item );
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2022-05-16 22:41:30 +00:00
|
|
|
|
2020-10-08 02:47:01 +00:00
|
|
|
// update the cursor so it looks correct before another event
|
|
|
|
setCursor();
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 15:10:23 +00:00
|
|
|
controls->SetCursorPosition( cursorPos, false );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
2021-07-16 20:13:26 +00:00
|
|
|
else // ... and second click places:
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2023-06-24 11:35:14 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
|
2021-05-30 21:04:07 +00:00
|
|
|
item->ClearFlags( IS_MOVING );
|
2019-05-01 20:15:51 +00:00
|
|
|
|
2023-06-12 18:33:52 +00:00
|
|
|
if( item->IsConnectable() )
|
|
|
|
m_frame->AutoRotateItem( m_frame->GetScreen(), item );
|
|
|
|
|
2023-06-24 11:35:14 +00:00
|
|
|
if( isSheetPin )
|
|
|
|
{
|
|
|
|
// Sheet pins are owned by their parent sheet.
|
|
|
|
commit.Modify( sheet, m_frame->GetScreen() );
|
|
|
|
sheet->AddPin( (SCH_SHEET_PIN*) item );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-09 12:53:23 +00:00
|
|
|
m_frame->SaveCopyForRepeatItem( item );
|
2023-06-24 11:35:14 +00:00
|
|
|
m_frame->AddToScreen( item, m_frame->GetScreen() );
|
|
|
|
commit.Added( item, m_frame->GetScreen() );
|
|
|
|
}
|
|
|
|
|
2023-06-13 12:20:47 +00:00
|
|
|
item->AutoplaceFields( m_frame->GetScreen(), false /* aManual */ );
|
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Push( description );
|
|
|
|
|
2020-10-20 21:51:29 +00:00
|
|
|
m_view->ClearPreview();
|
2022-12-29 14:32:10 +00:00
|
|
|
|
2024-02-25 14:23:59 +00:00
|
|
|
if( m_dialogSyncSheetPin && m_dialogSyncSheetPin->GetPlacementTemplate() )
|
2022-12-29 14:32:10 +00:00
|
|
|
{
|
2024-02-25 14:23:59 +00:00
|
|
|
m_dialogSyncSheetPin->EndPlaceItem( item );
|
|
|
|
m_dialogSyncSheetPin->Show( true );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item = nullptr;
|
|
|
|
}
|
2023-06-24 11:35:14 +00:00
|
|
|
|
2024-02-25 14:23:59 +00:00
|
|
|
if( isSheetPin )
|
|
|
|
{
|
|
|
|
item = createNewSheetPin( sheet, cursorPos );
|
|
|
|
item->SetPosition( cursorPos );
|
|
|
|
m_selectionTool->ClearSelection();
|
|
|
|
m_selectionTool->AddItemToSel( item );
|
2022-12-29 14:32:10 +00:00
|
|
|
}
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2019-04-29 17:50:46 +00:00
|
|
|
// Warp after context menu only if dragging...
|
|
|
|
if( !item )
|
|
|
|
m_toolMgr->VetoContextMenuMouseWarp();
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
2019-04-29 17:50:46 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( item && evt->IsSelectionEvent() )
|
2019-04-29 17:50:46 +00:00
|
|
|
{
|
2019-05-01 20:15:51 +00:00
|
|
|
// This happens if our text was replaced out from under us by ConvertTextType()
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->GetSelection();
|
2019-04-28 23:34:43 +00:00
|
|
|
|
2019-04-29 17:50:46 +00:00
|
|
|
if( selection.GetSize() == 1 )
|
|
|
|
{
|
2019-05-01 21:50:11 +00:00
|
|
|
item = (SCH_ITEM*) selection.Front();
|
2021-04-02 10:18:25 +00:00
|
|
|
updatePreview();
|
2019-04-29 17:50:46 +00:00
|
|
|
}
|
|
|
|
else
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-04-29 17:50:46 +00:00
|
|
|
item = nullptr;
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
2024-02-15 12:36:36 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::duplicate )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::repeatDrawItem ) )
|
|
|
|
{
|
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
// This doesn't really make sense; we'll just end up dragging a stack of
|
|
|
|
// objects so we ignore the duplicate and just carry on.
|
|
|
|
wxBell();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exit. The duplicate will run in its own loop.
|
|
|
|
m_frame->PopTool( aEvent );
|
|
|
|
break;
|
|
|
|
}
|
2019-07-04 20:56:21 +00:00
|
|
|
else if( item && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2022-03-07 12:45:24 +00:00
|
|
|
item->SetPosition( cursorPos );
|
2021-04-02 10:18:25 +00:00
|
|
|
item->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
|
|
|
|
updatePreview();
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
2021-03-29 09:59:21 +00:00
|
|
|
else if( item && evt->IsAction( &ACTIONS::doDelete ) )
|
2021-03-15 14:23:17 +00:00
|
|
|
{
|
2021-03-29 09:59:21 +00:00
|
|
|
cleanup();
|
2021-03-15 14:23:17 +00:00
|
|
|
}
|
2023-06-16 20:44:16 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::redo ) )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
// Enable autopanning and cursor capture only when there is an item to be placed
|
2020-12-03 15:10:23 +00:00
|
|
|
controls->SetAutoPan( item != nullptr );
|
|
|
|
controls->CaptureCursor( item != nullptr );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
controls->SetAutoPan( false );
|
|
|
|
controls->CaptureCursor( false );
|
2021-02-23 21:27:15 +00:00
|
|
|
controls->ForceCursorPosition( false );
|
2021-06-20 10:02:44 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2024-02-25 14:23:59 +00:00
|
|
|
|
|
|
|
if( m_dialogSyncSheetPin && m_dialogSyncSheetPin->GetPlacementTemplate() )
|
|
|
|
{
|
|
|
|
m_dialogSyncSheetPin->EndPlaceItem( nullptr );
|
2024-02-26 12:43:56 +00:00
|
|
|
m_dialogSyncSheetPin->Show( true );
|
2024-02-25 14:23:59 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 19:09:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
int SCH_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2022-06-03 20:47:13 +00:00
|
|
|
SCHEMATIC* schematic = getModel<SCHEMATIC>();
|
|
|
|
SCHEMATIC_SETTINGS& sch_settings = schematic->Settings();
|
|
|
|
SCH_SHAPE* item = nullptr;
|
|
|
|
bool isTextBox = aEvent.IsAction( &EE_ACTIONS::drawTextBox );
|
|
|
|
SHAPE_T type = aEvent.Parameter<SHAPE_T>();
|
2023-06-09 16:24:49 +00:00
|
|
|
wxString description;
|
2022-03-28 20:16:47 +00:00
|
|
|
|
2023-11-19 14:17:36 +00:00
|
|
|
if( m_inDrawingTool )
|
2021-07-17 19:56:18 +00:00
|
|
|
return 0;
|
|
|
|
|
2023-11-19 14:17:36 +00:00
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2023-08-23 15:13:46 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
VECTOR2I cursorPos;
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
// We might be running as the same shape in another co-routine. Make sure that one
|
|
|
|
// gets whacked.
|
|
|
|
m_toolMgr->DeactivateTool();
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
|
|
|
};
|
|
|
|
|
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2021-07-17 19:56:18 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
delete item;
|
|
|
|
item = nullptr;
|
|
|
|
};
|
|
|
|
|
2022-03-28 20:16:47 +00:00
|
|
|
Activate();
|
2022-08-26 17:34:46 +00:00
|
|
|
|
2022-03-28 20:16:47 +00:00
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
getViewControls()->ShowCursor( true );
|
2022-08-26 17:34:46 +00:00
|
|
|
|
2022-03-28 20:16:47 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
if( aEvent.HasPosition() )
|
2022-05-16 09:22:55 +00:00
|
|
|
m_toolMgr->PrimeTool( aEvent.Position() );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
|
|
|
{
|
|
|
|
setCursor();
|
2023-08-23 15:13:46 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2023-08-23 15:13:46 +00:00
|
|
|
cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_GRAPHICS );
|
|
|
|
controls->ForceCursorPosition( true, cursorPos );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-06-09 15:53:24 +00:00
|
|
|
// The tool hotkey is interpreted as a click when drawing
|
2022-09-14 17:31:56 +00:00
|
|
|
bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition()
|
|
|
|
&& evt->Matches( aEvent );
|
2022-06-09 15:53:24 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( evt->IsCancelInteractive() || ( item && evt->IsAction( &ACTIONS::undo ) ) )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-06-09 15:53:24 +00:00
|
|
|
else if( evt->IsActivate() && !isSyntheticClick )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
if( item && evt->IsMoveTool() )
|
|
|
|
{
|
|
|
|
// we're already drawing our own item; ignore the move tool
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item )
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
if( evt->IsPointEditor() )
|
|
|
|
{
|
|
|
|
// don't exit (the point editor runs in the background)
|
|
|
|
}
|
|
|
|
else if( evt->IsMoveTool() )
|
|
|
|
{
|
|
|
|
// leave ourselves on the stack so we come back after the move
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) && !item )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
if( isTextBox )
|
2022-06-03 20:47:13 +00:00
|
|
|
{
|
2022-06-08 09:32:45 +00:00
|
|
|
SCH_TEXTBOX* textbox = new SCH_TEXTBOX( 0, m_lastTextboxFillStyle );
|
2022-06-03 20:47:13 +00:00
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
textbox->SetTextSize( VECTOR2I( sch_settings.m_DefaultTextSize,
|
|
|
|
sch_settings.m_DefaultTextSize ) );
|
2024-02-25 17:28:05 +00:00
|
|
|
|
|
|
|
// Must come after SetTextSize()
|
|
|
|
textbox->SetBold( m_lastTextBold );
|
|
|
|
textbox->SetItalic( m_lastTextItalic );
|
|
|
|
|
2023-11-07 15:45:48 +00:00
|
|
|
textbox->SetTextAngle( m_lastTextboxAngle );
|
|
|
|
textbox->SetHorizJustify( m_lastTextboxHJustify );
|
|
|
|
textbox->SetVertJustify( m_lastTextboxVJustify );
|
2022-06-08 09:32:45 +00:00
|
|
|
textbox->SetStroke( m_lastTextboxStroke );
|
|
|
|
textbox->SetFillColor( m_lastTextboxFillColor );
|
2023-05-24 09:28:46 +00:00
|
|
|
textbox->SetParent( schematic );
|
2022-06-03 20:47:13 +00:00
|
|
|
|
|
|
|
item = textbox;
|
2023-06-09 16:24:49 +00:00
|
|
|
description = _( "Add Text Box" );
|
2022-06-03 20:47:13 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
else
|
2022-06-03 20:47:13 +00:00
|
|
|
{
|
2022-05-02 21:26:55 +00:00
|
|
|
item = new SCH_SHAPE( type, 0, m_lastFillStyle );
|
2022-06-03 20:47:13 +00:00
|
|
|
|
2022-06-08 09:32:45 +00:00
|
|
|
item->SetStroke( m_lastStroke );
|
|
|
|
item->SetFillColor( m_lastFillColor );
|
2023-05-24 09:28:46 +00:00
|
|
|
item->SetParent( schematic );
|
2023-06-09 16:24:49 +00:00
|
|
|
description = wxString::Format( _( "Add %s" ), item->EDA_SHAPE::GetFriendlyName() );
|
2022-06-08 09:32:45 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
item->SetFlags( IS_NEW );
|
2022-08-30 14:13:51 +00:00
|
|
|
item->BeginEdit( cursorPos );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( item->Clone() );
|
|
|
|
}
|
2022-05-02 21:26:55 +00:00
|
|
|
else if( item && ( evt->IsClick( BUT_LEFT )
|
|
|
|
|| evt->IsDblClick( BUT_LEFT )
|
2022-06-09 15:53:24 +00:00
|
|
|
|| isSyntheticClick
|
2022-12-29 16:55:05 +00:00
|
|
|
|| evt->IsAction( &ACTIONS::finishInteractive ) ) )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2022-05-02 21:26:55 +00:00
|
|
|
if( evt->IsDblClick( BUT_LEFT )
|
2022-12-29 16:55:05 +00:00
|
|
|
|| evt->IsAction( &ACTIONS::finishInteractive )
|
2022-08-30 14:13:51 +00:00
|
|
|
|| !item->ContinueEdit( cursorPos ) )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
item->EndEdit();
|
|
|
|
item->ClearEditFlags();
|
|
|
|
item->SetFlags( IS_NEW );
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
if( isTextBox )
|
|
|
|
{
|
2022-06-03 20:47:13 +00:00
|
|
|
SCH_TEXTBOX* textbox = static_cast<SCH_TEXTBOX*>( item );
|
|
|
|
DIALOG_TEXT_PROPERTIES dlg( m_frame, textbox );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2023-05-06 10:04:16 +00:00
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
getViewControls()->CaptureCursor( false );
|
|
|
|
|
2023-05-24 11:08:52 +00:00
|
|
|
// QuasiModal required for syntax help and Scintilla auto-complete
|
2023-05-24 09:28:46 +00:00
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
continue;
|
|
|
|
}
|
2022-06-03 20:47:13 +00:00
|
|
|
|
|
|
|
m_lastTextBold = textbox->IsBold();
|
|
|
|
m_lastTextItalic = textbox->IsItalic();
|
2023-11-07 15:45:48 +00:00
|
|
|
m_lastTextboxAngle = textbox->GetTextAngle();
|
|
|
|
m_lastTextboxHJustify = textbox->GetHorizJustify();
|
|
|
|
m_lastTextboxVJustify = textbox->GetVertJustify();
|
2022-06-08 09:32:45 +00:00
|
|
|
m_lastTextboxStroke = textbox->GetStroke();
|
|
|
|
m_lastTextboxFillStyle = textbox->GetFillMode();
|
|
|
|
m_lastTextboxFillColor = textbox->GetFillColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_lastStroke = item->GetStroke();
|
|
|
|
m_lastFillStyle = item->GetFillMode();
|
|
|
|
m_lastFillColor = item->GetFillColor();
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2022-06-03 20:47:13 +00:00
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2023-06-16 14:50:15 +00:00
|
|
|
commit.Add( item, m_frame->GetScreen() );
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Push( wxString::Format( _( "Draw %s" ), item->GetClass() ) );
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
m_selectionTool->AddItemToSel( item );
|
|
|
|
item = nullptr;
|
|
|
|
|
|
|
|
m_view->ClearPreview();
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::activatePointEditor );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-15 12:36:36 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::duplicate )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::repeatDrawItem ) )
|
|
|
|
{
|
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
// This doesn't really make sense; we'll just end up dragging a stack of
|
|
|
|
// objects so we ignore the duplicate and just carry on.
|
|
|
|
wxBell();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exit. The duplicate will run in its own loop.
|
|
|
|
m_frame->PopTool( aEvent );
|
|
|
|
break;
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
else if( item && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
|
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
item->CalcEdit( cursorPos );
|
2021-07-17 19:56:18 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( item->Clone() );
|
2022-03-20 15:57:18 +00:00
|
|
|
m_frame->SetMsgPanel( item );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsDblClick( BUT_LEFT ) && !item )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::properties );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
// Warp after context menu only if dragging...
|
|
|
|
if( !item )
|
|
|
|
m_toolMgr->VetoContextMenuMouseWarp();
|
|
|
|
|
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( item && evt->IsAction( &ACTIONS::redo ) )
|
2023-06-16 20:44:16 +00:00
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is a shape being drawn
|
|
|
|
getViewControls()->SetAutoPan( item != nullptr );
|
|
|
|
getViewControls()->CaptureCursor( item != nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
getViewControls()->CaptureCursor( false );
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-19 18:45:08 +00:00
|
|
|
void SCH_DRAWING_TOOLS::initSharedInstancePageNumbers( const SCH_SHEET_PATH& aAddedSheet )
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST fullHierarchy = m_frame->Schematic().GetFullHierarchy();
|
|
|
|
SCH_SHEET_LIST instances = fullHierarchy.FindAllSheetsForScreen( aAddedSheet.LastScreen() );
|
|
|
|
|
|
|
|
long pageNo;
|
|
|
|
long addedSheetPageNo;
|
|
|
|
|
|
|
|
if( aAddedSheet.GetPageNumber().ToLong( &addedSheetPageNo ) )
|
|
|
|
pageNo = addedSheetPageNo + 1;
|
|
|
|
else
|
|
|
|
pageNo = (signed)( fullHierarchy.size() - instances.size() + 1 );
|
|
|
|
|
|
|
|
for( SCH_SHEET_PATH& sheet : instances )
|
|
|
|
{
|
|
|
|
if( sheet == aAddedSheet )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sheet.SetPageNumber( wxString::Format( wxS( "%ld" ), pageNo++ ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-25 12:38:24 +00:00
|
|
|
int SCH_DRAWING_TOOLS::DrawTable( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
SCHEMATIC* schematic = getModel<SCHEMATIC>();
|
|
|
|
SCH_TABLE* table = nullptr;
|
|
|
|
|
|
|
|
if( m_inDrawingTool )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
|
|
|
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
VECTOR2I cursorPos;
|
|
|
|
|
|
|
|
// We might be running as the same shape in another co-routine. Make sure that one
|
|
|
|
// gets whacked.
|
|
|
|
m_toolMgr->DeactivateTool();
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
|
|
|
|
|
|
|
m_frame->PushTool( aEvent );
|
|
|
|
|
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
|
|
|
};
|
|
|
|
|
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
|
|
|
m_view->ClearPreview();
|
|
|
|
delete table;
|
|
|
|
table = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
getViewControls()->ShowCursor( true );
|
|
|
|
|
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
|
|
|
if( aEvent.HasPosition() )
|
|
|
|
m_toolMgr->PrimeTool( aEvent.Position() );
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
|
|
|
{
|
|
|
|
setCursor();
|
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
|
|
|
|
|
|
|
cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_GRAPHICS );
|
|
|
|
controls->ForceCursorPosition( true, cursorPos );
|
|
|
|
|
|
|
|
// The tool hotkey is interpreted as a click when drawing
|
|
|
|
bool isSyntheticClick = table && evt->IsActivate() && evt->HasPosition()
|
|
|
|
&& evt->Matches( aEvent );
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() || ( table && evt->IsAction( &ACTIONS::undo ) ) )
|
|
|
|
{
|
|
|
|
if( table )
|
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_frame->PopTool( aEvent );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsActivate() && !isSyntheticClick )
|
|
|
|
{
|
|
|
|
if( table && evt->IsMoveTool() )
|
|
|
|
{
|
|
|
|
// we're already drawing our own item; ignore the move tool
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( table )
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
if( evt->IsPointEditor() )
|
|
|
|
{
|
|
|
|
// don't exit (the point editor runs in the background)
|
|
|
|
}
|
|
|
|
else if( evt->IsMoveTool() )
|
|
|
|
{
|
|
|
|
// leave ourselves on the stack so we come back after the move
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_frame->PopTool( aEvent );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) && !table )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
|
|
|
|
|
|
|
table = new SCH_TABLE( 0 );
|
|
|
|
table->SetColCount( 1 );
|
|
|
|
table->AddCell( new SCH_TABLECELL() );
|
|
|
|
|
|
|
|
table->SetParent( schematic );
|
|
|
|
table->SetFlags( IS_NEW );
|
|
|
|
table->SetPosition( cursorPos );
|
|
|
|
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( table->Clone() );
|
|
|
|
}
|
|
|
|
else if( table && ( evt->IsClick( BUT_LEFT )
|
|
|
|
|| evt->IsDblClick( BUT_LEFT )
|
|
|
|
|| isSyntheticClick
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::finishInteractive ) ) )
|
|
|
|
{
|
|
|
|
table->ClearEditFlags();
|
|
|
|
table->SetFlags( IS_NEW );
|
|
|
|
table->Normalize();
|
|
|
|
|
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
commit.Add( table, m_frame->GetScreen() );
|
|
|
|
commit.Push( _( "Draw Table" ) );
|
|
|
|
|
|
|
|
m_selectionTool->AddItemToSel( table );
|
|
|
|
table = nullptr;
|
|
|
|
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_toolMgr->PostAction( ACTIONS::activatePointEditor );
|
|
|
|
}
|
|
|
|
else if( table && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
|
|
|
|
{
|
|
|
|
VECTOR2I gridSize = grid.GetGridSize( grid.GetItemGrid( table ) );
|
2024-01-15 17:29:55 +00:00
|
|
|
int fontSize = schematic->Settings().m_DefaultTextSize;
|
2023-11-25 12:38:24 +00:00
|
|
|
VECTOR2I origin( table->GetPosition() );
|
|
|
|
VECTOR2I requestedSize( cursorPos - origin );
|
|
|
|
|
2024-01-15 17:29:55 +00:00
|
|
|
int colCount = std::max( 1, requestedSize.x / ( fontSize * 15 ) );
|
|
|
|
int rowCount = std::max( 1, requestedSize.y / ( fontSize * 2 ) );
|
2023-11-25 12:38:24 +00:00
|
|
|
|
2024-01-15 17:29:55 +00:00
|
|
|
VECTOR2I cellSize( std::max( gridSize.x * 5, requestedSize.x / colCount ),
|
2023-11-25 12:38:24 +00:00
|
|
|
std::max( gridSize.y * 2, requestedSize.y / rowCount ) );
|
|
|
|
|
|
|
|
cellSize.x = KiROUND( (double) cellSize.x / gridSize.x ) * gridSize.x;
|
|
|
|
cellSize.y = KiROUND( (double) cellSize.y / gridSize.y ) * gridSize.y;
|
|
|
|
|
|
|
|
table->ClearCells();
|
|
|
|
table->SetColCount( colCount );
|
|
|
|
|
|
|
|
for( int col = 0; col < colCount; ++col )
|
|
|
|
table->SetColWidth( col, cellSize.x );
|
|
|
|
|
|
|
|
for( int row = 0; row < rowCount; ++row )
|
|
|
|
{
|
|
|
|
table->SetRowHeight( row, cellSize.y );
|
|
|
|
|
|
|
|
for( int col = 0; col < colCount; ++col )
|
|
|
|
{
|
|
|
|
SCH_TABLECELL* cell = new SCH_TABLECELL();
|
|
|
|
cell->SetPosition( origin + VECTOR2I( col * cellSize.x, row * cellSize.y ) );
|
|
|
|
cell->SetEnd( cell->GetPosition() + cellSize );
|
|
|
|
table->AddCell( cell );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( table->Clone() );
|
|
|
|
m_frame->SetMsgPanel( table );
|
|
|
|
}
|
|
|
|
else if( evt->IsDblClick( BUT_LEFT ) && !table )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::properties );
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
// Warp after context menu only if dragging...
|
|
|
|
if( !table )
|
|
|
|
m_toolMgr->VetoContextMenuMouseWarp();
|
|
|
|
|
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
|
|
|
}
|
|
|
|
else if( table && evt->IsAction( &ACTIONS::redo ) )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is a shape being drawn
|
|
|
|
getViewControls()->SetAutoPan( table != nullptr );
|
|
|
|
getViewControls()->CaptureCursor( table != nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
getViewControls()->CaptureCursor( false );
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
|
2019-04-18 15:45:10 +00:00
|
|
|
{
|
2020-10-08 16:57:24 +00:00
|
|
|
SCH_SHEET* sheet = nullptr;
|
2019-06-15 00:29:42 +00:00
|
|
|
|
2023-11-19 14:17:36 +00:00
|
|
|
if( m_inDrawingTool )
|
2021-01-27 19:50:07 +00:00
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
2023-11-19 14:17:36 +00:00
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-01-27 19:50:07 +00:00
|
|
|
|
2023-08-23 15:13:46 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
VECTOR2I cursorPos;
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-04-18 15:45:10 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2019-04-18 15:45:10 +00:00
|
|
|
|
2020-10-08 16:57:24 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
|
|
|
};
|
|
|
|
|
2021-03-29 10:04:06 +00:00
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2021-03-29 10:04:06 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
delete sheet;
|
|
|
|
sheet = nullptr;
|
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
Activate();
|
2022-08-26 17:34:46 +00:00
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
getViewControls()->ShowCursor( true );
|
2022-08-26 17:34:46 +00:00
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2021-03-29 10:04:06 +00:00
|
|
|
if( aEvent.HasPosition() )
|
2022-05-16 09:22:55 +00:00
|
|
|
m_toolMgr->PrimeTool( aEvent.Position() );
|
2021-03-29 10:04:06 +00:00
|
|
|
|
2019-04-18 15:45:10 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-18 15:45:10 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2023-08-23 15:13:46 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2019-06-27 21:33:48 +00:00
|
|
|
|
2023-08-23 15:13:46 +00:00
|
|
|
cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_GRAPHICS );
|
|
|
|
controls->ForceCursorPosition( true, cursorPos );
|
2019-04-18 15:45:10 +00:00
|
|
|
|
2022-06-09 15:53:24 +00:00
|
|
|
// The tool hotkey is interpreted as a click when drawing
|
2022-09-14 17:31:56 +00:00
|
|
|
bool isSyntheticClick = sheet && evt->IsActivate() && evt->HasPosition()
|
|
|
|
&& evt->Matches( aEvent );
|
2022-06-09 15:53:24 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( evt->IsCancelInteractive() || ( sheet && evt->IsAction( &ACTIONS::undo ) ) )
|
2019-07-01 21:01:33 +00:00
|
|
|
{
|
2022-03-17 15:26:49 +00:00
|
|
|
m_frame->GetInfoBar()->Dismiss();
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
if( sheet )
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
2019-04-18 15:45:10 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
2019-04-18 15:45:10 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2022-06-09 15:53:24 +00:00
|
|
|
else if( evt->IsActivate() && !isSyntheticClick )
|
2019-07-01 21:01:33 +00:00
|
|
|
{
|
2021-02-23 15:34:27 +00:00
|
|
|
if( sheet && evt->IsMoveTool() )
|
|
|
|
{
|
|
|
|
// we're already drawing our own item; ignore the move tool
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( sheet )
|
2021-05-08 22:30:38 +00:00
|
|
|
{
|
|
|
|
m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel sheet creation." ) );
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
|
|
|
|
if( evt->IsPointEditor() )
|
|
|
|
{
|
|
|
|
// don't exit (the point editor runs in the background)
|
|
|
|
}
|
|
|
|
else if( evt->IsMoveTool() )
|
2019-06-18 17:56:40 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
// leave ourselves on the stack so we come back after the move
|
2019-06-27 11:47:24 +00:00
|
|
|
break;
|
2019-06-18 21:34:31 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-06-18 17:56:40 +00:00
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2019-04-18 15:45:10 +00:00
|
|
|
}
|
2020-12-14 22:03:17 +00:00
|
|
|
else if( !sheet && ( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) ) )
|
2019-04-18 15:45:10 +00:00
|
|
|
{
|
2022-05-30 13:07:28 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->GetSelection();
|
2020-04-12 23:09:17 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
|
|
|
|
2022-05-30 13:07:28 +00:00
|
|
|
if( selection.Size() == 1
|
|
|
|
&& selection.Front()->Type() == SCH_SHEET_T
|
|
|
|
&& selection.Front()->GetBoundingBox().Contains( cursorPos ) )
|
|
|
|
{
|
|
|
|
if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
// sheet already selected
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if( evt->IsDblClick( BUT_LEFT ) )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( EE_ACTIONS::enterSheet );
|
2022-05-30 13:07:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-10 16:48:46 +00:00
|
|
|
|
2022-05-30 13:07:28 +00:00
|
|
|
sheet = new SCH_SHEET( m_frame->GetCurrentSheet().Last(), cursorPos );
|
2022-12-28 14:49:15 +00:00
|
|
|
sheet->SetFlags( IS_NEW | IS_MOVING );
|
2021-07-16 20:13:26 +00:00
|
|
|
sheet->SetScreen( nullptr );
|
2022-09-16 23:42:20 +00:00
|
|
|
sheet->SetBorderWidth( schIUScale.MilsToIU( cfg->m_Drawing.default_line_thickness ) );
|
2020-04-12 23:09:17 +00:00
|
|
|
sheet->SetBorderColor( cfg->m_Drawing.default_sheet_border_color );
|
|
|
|
sheet->SetBackgroundColor( cfg->m_Drawing.default_sheet_background_color );
|
2020-06-06 09:21:23 +00:00
|
|
|
sheet->GetFields()[ SHEETNAME ].SetText( "Untitled Sheet" );
|
2023-12-28 02:10:01 +00:00
|
|
|
sheet->GetFields()[ SHEETFILENAME ].SetText( "untitled." + FILEEXT::KiCadSchematicFileExtension );
|
2019-05-08 18:56:03 +00:00
|
|
|
sizeSheet( sheet, cursorPos );
|
2019-04-30 20:01:17 +00:00
|
|
|
|
2019-05-07 23:51:37 +00:00
|
|
|
m_view->ClearPreview();
|
2019-05-08 18:56:03 +00:00
|
|
|
m_view->AddToPreview( sheet->Clone() );
|
2019-05-07 23:51:37 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
else if( sheet && ( evt->IsClick( BUT_LEFT )
|
2020-12-14 22:03:17 +00:00
|
|
|
|| evt->IsDblClick( BUT_LEFT )
|
2022-06-09 15:53:24 +00:00
|
|
|
|| isSyntheticClick
|
2022-12-29 16:55:05 +00:00
|
|
|
|| evt->IsAction( &ACTIONS::finishInteractive ) ) )
|
2019-05-07 23:51:37 +00:00
|
|
|
{
|
2019-08-25 23:45:10 +00:00
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
getViewControls()->CaptureCursor( false );
|
2019-05-07 23:51:37 +00:00
|
|
|
|
2020-06-02 19:27:39 +00:00
|
|
|
if( m_frame->EditSheetProperties( static_cast<SCH_SHEET*>( sheet ),
|
|
|
|
&m_frame->GetCurrentSheet(), nullptr ) )
|
2019-05-22 22:28:51 +00:00
|
|
|
{
|
2023-06-18 15:36:28 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
|
2020-03-06 12:05:21 +00:00
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
2023-06-12 18:33:52 +00:00
|
|
|
commit.Add( sheet, m_frame->GetScreen() );
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Push( "Draw Sheet" );
|
|
|
|
|
2024-01-19 18:45:08 +00:00
|
|
|
SCH_SHEET_PATH newPath = m_frame->GetCurrentSheet();
|
|
|
|
newPath.push_back( sheet );
|
|
|
|
initSharedInstancePageNumbers( newPath );
|
|
|
|
|
2019-10-24 17:07:01 +00:00
|
|
|
m_frame->UpdateHierarchyNavigator();
|
2019-05-22 22:28:51 +00:00
|
|
|
m_selectionTool->AddItemToSel( sheet );
|
|
|
|
}
|
2019-11-23 23:34:35 +00:00
|
|
|
else
|
2019-05-22 22:28:51 +00:00
|
|
|
{
|
2023-06-18 15:36:28 +00:00
|
|
|
m_view->ClearPreview();
|
2019-05-08 18:56:03 +00:00
|
|
|
delete sheet;
|
2019-05-22 22:28:51 +00:00
|
|
|
}
|
2019-05-01 20:15:51 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
sheet = nullptr;
|
2019-04-19 00:00:54 +00:00
|
|
|
}
|
2024-02-15 12:36:36 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::duplicate )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::repeatDrawItem ) )
|
|
|
|
{
|
|
|
|
if( sheet )
|
|
|
|
{
|
|
|
|
// This doesn't really make sense; we'll just end up dragging a stack of
|
|
|
|
// objects so we ignore the duplicate and just carry on.
|
|
|
|
wxBell();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exit. The duplicate will run in its own loop.
|
|
|
|
m_frame->PopTool( aEvent );
|
|
|
|
break;
|
|
|
|
}
|
2019-07-04 20:56:21 +00:00
|
|
|
else if( sheet && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
|
2019-04-18 15:45:10 +00:00
|
|
|
{
|
2019-05-08 18:56:03 +00:00
|
|
|
sizeSheet( sheet, cursorPos );
|
2019-04-18 15:45:10 +00:00
|
|
|
m_view->ClearPreview();
|
2019-05-08 18:56:03 +00:00
|
|
|
m_view->AddToPreview( sheet->Clone() );
|
2022-03-20 15:57:18 +00:00
|
|
|
m_frame->SetMsgPanel( sheet );
|
2019-04-18 15:45:10 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2019-04-29 17:50:46 +00:00
|
|
|
// Warp after context menu only if dragging...
|
2019-05-08 18:56:03 +00:00
|
|
|
if( !sheet )
|
2019-04-29 17:50:46 +00:00
|
|
|
m_toolMgr->VetoContextMenuMouseWarp();
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
2019-04-18 15:45:10 +00:00
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( sheet && evt->IsAction( &ACTIONS::redo ) )
|
2023-06-16 20:44:16 +00:00
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-04-18 15:45:10 +00:00
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is a sheet to be placed
|
2019-06-18 17:56:40 +00:00
|
|
|
getViewControls()->SetAutoPan( sheet != nullptr );
|
2019-08-25 23:45:10 +00:00
|
|
|
getViewControls()->CaptureCursor( sheet != nullptr );
|
2019-04-18 15:45:10 +00:00
|
|
|
}
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
getViewControls()->CaptureCursor( false );
|
2020-11-19 20:08:58 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2021-07-27 15:36:46 +00:00
|
|
|
|
2019-04-18 15:45:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
void SCH_DRAWING_TOOLS::sizeSheet( SCH_SHEET* aSheet, const VECTOR2I& aPos )
|
2019-04-30 20:01:17 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos = aSheet->GetPosition();
|
|
|
|
VECTOR2I size = aPos - pos;
|
2019-04-30 20:01:17 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
size.x = std::max( size.x, schIUScale.MilsToIU( MIN_SHEET_WIDTH ) );
|
|
|
|
size.y = std::max( size.y, schIUScale.MilsToIU( MIN_SHEET_HEIGHT ) );
|
2019-04-30 20:01:17 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I grid = m_frame->GetNearestGridPosition( pos + size );
|
2023-02-19 03:40:07 +00:00
|
|
|
aSheet->Resize( VECTOR2I( grid.x - pos.x, grid.y - pos.y ) );
|
2019-04-30 20:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-25 14:23:59 +00:00
|
|
|
int SCH_DRAWING_TOOLS::doSyncSheetsPins( std::list<SCH_SHEET_PATH> sheetPaths )
|
|
|
|
{
|
|
|
|
if( !sheetPaths.size() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
m_dialogSyncSheetPin = std::make_unique<DIALOG_SYNC_SHEET_PINS>(
|
|
|
|
m_frame, std::move( sheetPaths ),
|
|
|
|
std::make_shared<SHEET_SYNCHRONIZATION_AGENT>(
|
|
|
|
[&]( EDA_ITEM* aItem, SCH_SHEET_PATH aPath,
|
2024-03-04 19:45:05 +00:00
|
|
|
SHEET_SYNCHRONIZATION_AGENT::MODIFICATION const& aModify )
|
2024-02-25 14:23:59 +00:00
|
|
|
{
|
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
|
|
|
|
if( auto pin = dynamic_cast<SCH_SHEET_PIN*>( aItem ) )
|
|
|
|
{
|
|
|
|
commit.Modify( pin->GetParent(), aPath.LastScreen() );
|
|
|
|
aModify();
|
2024-03-09 13:50:26 +00:00
|
|
|
commit.Push( _( "Modify sheet pin" ) );
|
2024-02-25 14:23:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
commit.Modify( aItem, aPath.LastScreen() );
|
|
|
|
aModify();
|
2024-03-09 13:50:26 +00:00
|
|
|
commit.Push( _( "Modify schematic item" ) );
|
2024-02-25 14:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateItem( aItem, true );
|
|
|
|
m_frame->OnModify();
|
|
|
|
},
|
|
|
|
[&]( EDA_ITEM* aItem, SCH_SHEET_PATH aPath )
|
|
|
|
{
|
|
|
|
m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>(
|
|
|
|
EE_ACTIONS::changeSheet, &aPath );
|
|
|
|
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
selectionTool->UnbrightenItem( aItem );
|
|
|
|
selectionTool->AddItemToSel( aItem, true );
|
|
|
|
m_toolMgr->RunAction( ACTIONS::doDelete );
|
|
|
|
},
|
|
|
|
[&]( SCH_SHEET* aItem, SCH_SHEET_PATH aPath,
|
|
|
|
SHEET_SYNCHRONIZATION_AGENT::SHEET_SYNCHRONIZATION_PLACEMENT aOp,
|
|
|
|
EDA_ITEM* aTemplate )
|
|
|
|
{
|
|
|
|
switch( aOp )
|
|
|
|
{
|
|
|
|
case SHEET_SYNCHRONIZATION_AGENT::PLACE_HIERLABEL:
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
|
|
|
|
m_dialogSyncSheetPin->Hide();
|
|
|
|
m_dialogSyncSheetPin->BeginPlaceItem(
|
|
|
|
sheet, DIALOG_SYNC_SHEET_PINS::PlaceItemKind::HIERLABEL,
|
|
|
|
aTemplate );
|
|
|
|
m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>(
|
|
|
|
EE_ACTIONS::changeSheet, &aPath );
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::placeHierLabel );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SHEET_SYNCHRONIZATION_AGENT::PLACE_SHEET_PIN:
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
|
|
|
|
m_dialogSyncSheetPin->Hide();
|
|
|
|
m_dialogSyncSheetPin->BeginPlaceItem(
|
|
|
|
sheet, DIALOG_SYNC_SHEET_PINS::PlaceItemKind::SHEET_PIN,
|
|
|
|
aTemplate );
|
|
|
|
m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>(
|
|
|
|
EE_ACTIONS::changeSheet, &aPath );
|
|
|
|
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->SyncSelection( {}, nullptr,
|
|
|
|
{ sheet } );
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::placeSheetPin );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
m_toolMgr, m_frame ) );
|
|
|
|
m_dialogSyncSheetPin->Show( true );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_DRAWING_TOOLS::SyncSheetsPins( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( m_selectionTool->GetSelection().Front() );
|
|
|
|
|
|
|
|
if( !sheet )
|
|
|
|
{
|
|
|
|
VECTOR2I cursorPos = getViewControls()->GetMousePosition();
|
|
|
|
|
2024-02-26 12:43:56 +00:00
|
|
|
if( EDA_ITEM* i = nullptr; static_cast<void>(m_selectionTool->SelectPoint( cursorPos, { SCH_SHEET_T }, &i ) ) , i != nullptr )
|
2024-02-25 14:23:59 +00:00
|
|
|
{
|
|
|
|
sheet = dynamic_cast<SCH_SHEET*>( i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( sheet )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH current = m_frame->GetCurrentSheet();
|
|
|
|
current.push_back( sheet );
|
|
|
|
return doSyncSheetsPins( { current } );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_DRAWING_TOOLS::SyncAllSheetsPins( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
static const std::function<void( std::list<SCH_SHEET_PATH>&, SCH_SCREEN*,
|
|
|
|
std::set<SCH_SCREEN*>&, SCH_SHEET_PATH const& )>
|
|
|
|
getSheetChildren = []( std::list<SCH_SHEET_PATH>& aPaths, SCH_SCREEN* aScene,
|
|
|
|
std::set<SCH_SCREEN*>& aVisited, SCH_SHEET_PATH const& aCurPath )
|
|
|
|
{
|
|
|
|
if( ! aScene || aVisited.find(aScene) != aVisited.end() )
|
|
|
|
return ;
|
|
|
|
|
|
|
|
std::vector<SCH_ITEM*> sheetChildren;
|
|
|
|
aScene->GetSheets( &sheetChildren );
|
2024-02-26 12:43:56 +00:00
|
|
|
aVisited.insert( aScene );
|
2024-02-25 14:23:59 +00:00
|
|
|
|
2024-02-26 12:43:56 +00:00
|
|
|
for( SCH_ITEM* child : sheetChildren )
|
2024-02-25 14:23:59 +00:00
|
|
|
{
|
|
|
|
SCH_SHEET_PATH cp = aCurPath;
|
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( child );
|
2024-02-26 12:43:56 +00:00
|
|
|
cp.push_back( sheet );
|
2024-02-25 14:23:59 +00:00
|
|
|
aPaths.push_back( cp );
|
2024-02-26 12:43:56 +00:00
|
|
|
getSheetChildren( aPaths, sheet->GetScreen(), aVisited, cp );
|
2024-02-25 14:23:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::list<SCH_SHEET_PATH> sheetPaths;
|
|
|
|
std::set<SCH_SCREEN*> visited;
|
|
|
|
SCH_SHEET_PATH current;
|
2024-02-26 12:43:56 +00:00
|
|
|
current.push_back( &m_frame->Schematic().Root() );
|
|
|
|
getSheetChildren( sheetPaths, m_frame->Schematic().Root().GetScreen(), visited, current );
|
2024-03-04 19:45:05 +00:00
|
|
|
return doSyncSheetsPins( std::move( sheetPaths ) );
|
2024-02-25 14:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
void SCH_DRAWING_TOOLS::setTransitions()
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2021-03-18 11:46:07 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceSymbol, EE_ACTIONS::placeSymbol.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceSymbol, EE_ACTIONS::placePower.MakeEvent() );
|
2019-06-15 00:29:42 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::SingleClickPlace, EE_ACTIONS::placeNoConnect.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::SingleClickPlace, EE_ACTIONS::placeJunction.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::SingleClickPlace, EE_ACTIONS::placeBusWireEntry.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeLabel.MakeEvent() );
|
2021-10-12 20:05:37 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeClassLabel.MakeEvent() );
|
2019-06-15 00:29:42 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeHierLabel.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeGlobalLabel.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::DrawSheet, EE_ACTIONS::drawSheet.MakeEvent() );
|
2024-02-25 14:23:59 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeSheetPin.MakeEvent() );
|
2019-06-15 00:29:42 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeSchematicText.MakeEvent() );
|
2021-07-17 19:56:18 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawRectangle.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawCircle.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawArc.MakeEvent() );
|
2022-01-25 22:33:37 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawTextBox.MakeEvent() );
|
2023-11-25 12:38:24 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::DrawTable, EE_ACTIONS::drawTable.MakeEvent() );
|
2019-06-15 00:29:42 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceImage, EE_ACTIONS::placeImage.MakeEvent() );
|
2023-12-29 02:57:21 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::ImportGraphics, EE_ACTIONS::importGraphics.MakeEvent() );
|
2024-02-25 14:23:59 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::SyncSheetsPins, EE_ACTIONS::syncSheetPins.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::SyncAllSheetsPins, EE_ACTIONS::syncAllSheetsPins.MakeEvent() );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|