2019-04-17 19:09:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2023-01-03 21:08:36 +00:00
|
|
|
* Copyright (C) 2019-2023 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
|
|
|
|
*/
|
|
|
|
|
2022-12-19 13:19:21 +00:00
|
|
|
#include <memory>
|
|
|
|
|
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>
|
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>
|
|
|
|
#include <project.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>
|
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>
|
2019-04-17 19:09:48 +00:00
|
|
|
#include <sch_bitmap.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2022-01-29 19:07:07 +00:00
|
|
|
#include <symbol_library_common.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>
|
2020-10-31 00:25:46 +00:00
|
|
|
#include <dialogs/dialog_sheet_pin_properties.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 ),
|
2022-01-24 13:40:39 +00:00
|
|
|
m_lastTextOrientation( TEXT_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 ),
|
|
|
|
m_lastTextJust( GR_TEXT_H_ALIGN_LEFT ),
|
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 ),
|
2022-06-03 20:47:13 +00:00
|
|
|
m_lastStroke( 0, PLOT_DASH_TYPE::DEFAULT, COLOR4D::UNSPECIFIED ),
|
2022-06-08 09:32:45 +00:00
|
|
|
m_lastTextboxStroke( 0, PLOT_DASH_TYPE::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 ),
|
2021-03-28 16:55:07 +00:00
|
|
|
m_inPlaceSymbol( false ),
|
2021-07-17 19:56:18 +00:00
|
|
|
m_inDrawShape( false ),
|
2021-01-27 19:50:07 +00:00
|
|
|
m_inPlaceImage( false ),
|
|
|
|
m_inSingleClickPlace( false ),
|
|
|
|
m_inTwoClickPlace( false ),
|
|
|
|
m_inDrawSheet( 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();
|
2019-05-10 17:19:48 +00:00
|
|
|
ctxMenu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 2 );
|
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();
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2021-03-28 16:55:07 +00:00
|
|
|
if( m_inPlaceSymbol )
|
2021-01-27 19:50:07 +00:00
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inPlaceSymbol );
|
2021-01-27 19:50:07 +00:00
|
|
|
|
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 =
|
2021-06-10 14:10:55 +00:00
|
|
|
[&]( SCH_SYMBOL* aSymbol )
|
2021-03-18 11:27:15 +00:00
|
|
|
{
|
2021-03-28 19:04:58 +00:00
|
|
|
m_frame->SaveCopyForRepeatItem( aSymbol );
|
|
|
|
|
2021-03-18 11:27:15 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2021-03-28 19:04:58 +00:00
|
|
|
m_selectionTool->AddItemToSel( aSymbol );
|
2021-03-18 11:27:15 +00:00
|
|
|
|
|
|
|
aSymbol->SetParent( m_frame->GetScreen() );
|
2021-05-30 21:04:07 +00:00
|
|
|
aSymbol->SetFlags( IS_NEW | IS_MOVING );
|
2021-03-18 11:27:15 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), aSymbol, false );
|
2021-03-28 19:04:58 +00:00
|
|
|
|
2021-05-30 21:04:07 +00:00
|
|
|
// Set IS_MOVING again, as AddItemToScreenAndUndoList() will have cleared it.
|
|
|
|
aSymbol->SetFlags( IS_MOVING );
|
2021-03-18 11:27:15 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
m_frame->RollbackSchematicFromUndo();
|
2022-11-29 21:36:02 +00:00
|
|
|
existingRefs.Clear();
|
|
|
|
hierarchy.GetSymbols( existingRefs );
|
|
|
|
existingRefs.SortByReferenceOnly();
|
2021-03-18 11:46:07 +00:00
|
|
|
symbol = nullptr;
|
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
|
|
|
{
|
|
|
|
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 );
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2021-03-18 11:46:07 +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() );
|
|
|
|
|
2021-05-09 19:17:01 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
|
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
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
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
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-01 09:24:43 +00:00
|
|
|
|
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;
|
2020-11-07 14:31:50 +00:00
|
|
|
PICKED_SYMBOL sel = m_frame->PickSymbolFromLibTree( &filter, *historyList, true,
|
|
|
|
1, 1, 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 )
|
|
|
|
{
|
|
|
|
cursorPos = grid.Align( evt->Position() );
|
|
|
|
getViewControls()->WarpMouseCursor( cursorPos, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
getViewControls()->PinCursorInsideNonAutoscrollArea( true );
|
|
|
|
cursorPos = getViewControls()->GetMousePosition();
|
|
|
|
}
|
|
|
|
|
2022-08-26 17:34:46 +00:00
|
|
|
symbol = new SCH_SYMBOL( *libSymbol, &m_frame->GetCurrentSheet(), sel, cursorPos,
|
|
|
|
&m_frame->Schematic() );
|
2021-03-18 11:46:07 +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
|
|
|
|
{
|
2021-03-14 22:29:41 +00:00
|
|
|
if( m_frame->eeconfig()->m_AutoplaceFields.enable )
|
2021-07-16 20:13:26 +00:00
|
|
|
symbol->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
|
2021-03-14 22:29:41 +00:00
|
|
|
|
2021-03-28 19:04:58 +00:00
|
|
|
symbol->ClearEditFlags();
|
2022-02-20 00:49:26 +00:00
|
|
|
m_view->Update( symbol );
|
|
|
|
m_frame->GetScreen()->Update( symbol );
|
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>();
|
|
|
|
lwbTool->TrimOverLappingWires( &m_selectionTool->GetSelection() );
|
|
|
|
lwbTool->AddJunctionsIfNeeded( &m_selectionTool->GetSelection() );
|
2019-10-29 05:06:39 +00:00
|
|
|
|
2019-11-26 21:03:19 +00:00
|
|
|
m_frame->OnModify();
|
|
|
|
|
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 );
|
|
|
|
|
2021-03-18 11:46:07 +00:00
|
|
|
addSymbol( nextSymbol );
|
2022-07-20 15:40:38 +00:00
|
|
|
symbol = nextSymbol; // annotate() looks at symbol, update it
|
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
|
|
|
{
|
2022-08-30 20:58:43 +00:00
|
|
|
if( *evt->GetCommandId() >= ID_POPUP_SCH_SELECT_UNIT_CMP
|
|
|
|
&& *evt->GetCommandId() <= ID_POPUP_SCH_SELECT_UNIT_SYM_MAX )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2022-08-30 20:58:43 +00:00
|
|
|
int unit = *evt->GetCommandId() - ID_POPUP_SCH_SELECT_UNIT_CMP;
|
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 );
|
2019-07-04 20:56:21 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-24 19:39:57 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::duplicate ) )
|
|
|
|
{
|
|
|
|
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 );
|
2021-03-18 11:46:07 +00:00
|
|
|
m_view->Update( symbol );
|
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
|
|
|
}
|
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;
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
bool ignorePrimePosition = false;
|
|
|
|
COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2021-01-27 19:50:07 +00:00
|
|
|
if( m_inPlaceImage )
|
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inPlaceImage );
|
2021-01-27 19:50:07 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
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 =
|
|
|
|
[&] ()
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
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
|
|
|
{
|
2021-03-29 10:04:06 +00:00
|
|
|
m_toolMgr->RunAction( 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();
|
2022-05-16 22:41:30 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
|
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
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
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 )
|
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
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
|
2019-05-03 10:16:24 +00:00
|
|
|
m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
|
|
|
|
|
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
|
|
|
|
{
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), image, false );
|
2019-04-26 22:23:12 +00:00
|
|
|
image = nullptr;
|
2019-06-19 10:31:21 +00:00
|
|
|
m_toolMgr->RunAction( 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
|
|
|
}
|
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
|
2019-05-03 10:16:24 +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
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2021-01-27 19:50:07 +00:00
|
|
|
if( m_inSingleClickPlace )
|
|
|
|
return 0;
|
|
|
|
|
2021-07-27 15:36:46 +00:00
|
|
|
REENTRANCY_GUARD guard( &m_inSingleClickPlace );
|
|
|
|
|
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 );
|
2021-02-21 15:44:38 +00:00
|
|
|
previewItem->SetParent( m_frame->GetScreen() );
|
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 );
|
2021-02-21 15:44:38 +00:00
|
|
|
previewItem->SetParent( m_frame->GetScreen() );
|
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 );
|
2021-02-21 15:44:38 +00:00
|
|
|
previewItem->SetParent( m_frame->GetScreen() );
|
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;
|
|
|
|
}
|
|
|
|
|
2021-02-21 15:44:38 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
|
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
|
|
|
|
m_toolMgr->RunAction( 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();
|
|
|
|
cursorPos = grid.BestSnapAnchor( cursorPos, LAYER_CONNECTABLE, nullptr );
|
2021-01-31 23:16:36 +00:00
|
|
|
controls->ForceCursorPosition( true, cursorPos );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-07-01 21:01:33 +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
|
|
|
{
|
2019-06-15 00:29:42 +00:00
|
|
|
if( !m_frame->GetScreen()->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 )
|
|
|
|
{
|
2021-11-04 12:38:15 +00:00
|
|
|
if( !m_frame->GetScreen()->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 );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2020-10-08 17:03:58 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), newItem, false );
|
2021-02-21 15:44:38 +00:00
|
|
|
|
2020-10-08 17:03:58 +00:00
|
|
|
if( type == SCH_JUNCTION_T )
|
|
|
|
m_frame->TestDanglingEnds();
|
|
|
|
else
|
2019-06-28 18:32:18 +00:00
|
|
|
m_frame->SchematicCleanUp();
|
2020-10-08 17:03:58 +00:00
|
|
|
|
|
|
|
m_frame->OnModify();
|
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
|
|
|
{
|
2021-02-16 20:45:25 +00:00
|
|
|
busItem->MirrorVertically( busItem->GetPosition().x );
|
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
|
|
|
{
|
2021-02-16 20:45:25 +00:00
|
|
|
busItem->MirrorHorizontally( busItem->GetPosition().y );
|
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
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
|
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
|
|
|
}
|
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 );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
|
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
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;
|
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;
|
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
|
|
|
|
2022-09-22 00:05:51 +00:00
|
|
|
if( aType != LAYER_NETCLASS_REFS )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
textItem->SetTextSpinStyle( m_lastTextOrientation );
|
2023-02-19 03:40:07 +00:00
|
|
|
textItem->SetTextSize( VECTOR2I( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
|
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 );
|
|
|
|
|
|
|
|
// Must be quasi modal for syntax help
|
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
|
|
|
{
|
|
|
|
delete textItem;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
m_lastTextOrientation = textItem->GetTextSpinStyle();
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 00:25:46 +00:00
|
|
|
SCH_HIERLABEL* SCH_DRAWING_TOOLS::importHierLabel( SCH_SHEET* aSheet )
|
|
|
|
{
|
|
|
|
if( !aSheet->GetScreen() )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : aSheet->GetScreen()->Items().OfType( SCH_HIER_LABEL_T ) )
|
|
|
|
{
|
|
|
|
SCH_HIERLABEL* label = static_cast<SCH_HIERLABEL*>( item );
|
|
|
|
|
|
|
|
/* A global label has been found: check if there a corresponding sheet label. */
|
|
|
|
if( !aSheet->HasPin( label->GetText() ) )
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-19 12:27:34 +00:00
|
|
|
SCH_SHEET_PIN* SCH_DRAWING_TOOLS::createSheetPin( SCH_SHEET* aSheet, SCH_HIERLABEL* aLabel,
|
|
|
|
const VECTOR2I& aPosition )
|
2020-10-31 00:25:46 +00:00
|
|
|
{
|
|
|
|
SCHEMATIC_SETTINGS& settings = aSheet->Schematic()->Settings();
|
|
|
|
wxString text;
|
|
|
|
SCH_SHEET_PIN* sheetPin;
|
|
|
|
|
|
|
|
if( aLabel )
|
|
|
|
{
|
|
|
|
text = aLabel->GetText();
|
|
|
|
m_lastSheetPinType = aLabel->GetShape();
|
|
|
|
}
|
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
sheetPin = new SCH_SHEET_PIN( aSheet, VECTOR2I( 0, 0 ), text );
|
2020-10-31 00:25:46 +00:00
|
|
|
sheetPin->SetFlags( IS_NEW );
|
2023-02-19 03:40:07 +00:00
|
|
|
sheetPin->SetTextSize( VECTOR2I( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
|
2020-10-31 00:25:46 +00:00
|
|
|
sheetPin->SetShape( m_lastSheetPinType );
|
|
|
|
|
|
|
|
if( !aLabel )
|
|
|
|
{
|
|
|
|
DIALOG_SHEET_PIN_PROPERTIES dlg( m_frame, sheetPin );
|
|
|
|
|
2020-12-01 14:58:33 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK || NoPrintableChars( sheetPin->GetText() ) )
|
2020-10-31 00:25:46 +00:00
|
|
|
{
|
|
|
|
delete sheetPin;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lastSheetPinType = sheetPin->GetShape();
|
|
|
|
|
2022-12-19 12:27:34 +00:00
|
|
|
sheetPin->SetPosition( aPosition );
|
2020-10-31 00:25:46 +00:00
|
|
|
|
|
|
|
return sheetPin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2021-03-05 00:01:17 +00:00
|
|
|
|
2021-01-27 19:50:07 +00:00
|
|
|
if( m_inTwoClickPlace )
|
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inTwoClickPlace );
|
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 );
|
|
|
|
bool isSheetPin = aEvent.IsAction( &EE_ACTIONS::importSheetPin );
|
|
|
|
int snapLayer = isText ? LAYER_GRAPHICS : LAYER_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() );
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
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
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
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();
|
2021-02-23 15:28:45 +00:00
|
|
|
cursorPos = grid.BestSnapAnchor( cursorPos, snapLayer, item );
|
|
|
|
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
|
|
|
|
2022-12-29 14:32:10 +00:00
|
|
|
auto createNextSheetPin =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
if( !sheet )
|
|
|
|
return;
|
|
|
|
|
|
|
|
SCH_HIERLABEL* label = importHierLabel( sheet );
|
|
|
|
|
|
|
|
if( !label )
|
|
|
|
{
|
|
|
|
m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( m_frame );
|
|
|
|
m_statusPopup->SetText( _( "No new hierarchical labels found." ) );
|
|
|
|
m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
|
|
|
|
m_statusPopup->PopupFor( 2000 );
|
|
|
|
item = nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item = createSheetPin( sheet, label, cursorPos );
|
|
|
|
|
|
|
|
if( item->Type() == SCH_SHEET_PIN_T )
|
|
|
|
{
|
|
|
|
item->ClearSelected();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
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 )
|
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
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 );
|
2021-02-22 11:52:33 +00:00
|
|
|
}
|
|
|
|
else if( isHierLabel )
|
|
|
|
{
|
|
|
|
item = createNewText( cursorPos, LAYER_HIERLABEL );
|
|
|
|
}
|
2022-05-02 08:42:15 +00:00
|
|
|
else if( isNetLabel || isGlobalLabel )
|
2021-02-22 11:52:33 +00:00
|
|
|
{
|
2022-05-02 08:42:15 +00:00
|
|
|
wxString netName;
|
|
|
|
|
|
|
|
for( SCH_ITEM* overlapItem :
|
|
|
|
m_frame->GetScreen()->Items().Overlapping( cursorPos ) )
|
|
|
|
{
|
|
|
|
if( overlapItem->GetEditFlags() & STRUCT_DELETED )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( overlapItem->Type() == SCH_LINE_T )
|
|
|
|
{
|
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( overlapItem );
|
|
|
|
if( line->IsWire() )
|
|
|
|
{
|
|
|
|
netName = line->GetNetname(m_frame->GetCurrentSheet());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( netName.IsEmpty() )
|
|
|
|
{
|
|
|
|
// no connected net label found -> open up the new label dialog
|
|
|
|
if( isGlobalLabel )
|
|
|
|
item = createNewText( cursorPos, LAYER_GLOBLABEL );
|
|
|
|
else
|
|
|
|
item = createNewText( cursorPos, LAYER_LOCLABEL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// connected net label found -> create the label immediately
|
|
|
|
SCHEMATIC* schematic = getModel<SCHEMATIC>();
|
2022-05-02 13:25:55 +00:00
|
|
|
SCHEMATIC_SETTINGS& sch_settings = schematic->Settings();
|
2022-05-02 08:42:15 +00:00
|
|
|
SCH_LABEL_BASE* labelItem = nullptr;
|
2022-05-02 21:31:17 +00:00
|
|
|
|
2022-05-02 08:42:15 +00:00
|
|
|
if( isGlobalLabel )
|
|
|
|
{
|
|
|
|
labelItem = new SCH_GLOBALLABEL( cursorPos );
|
|
|
|
labelItem->SetShape( m_lastGlobalLabelShape );
|
|
|
|
// make intersheets reference visible based on settings
|
2022-05-02 13:25:55 +00:00
|
|
|
labelItem->GetFields()[0].SetVisible( sch_settings.m_IntersheetRefsShow );
|
2022-05-02 08:42:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
labelItem = new SCH_LABEL( cursorPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
labelItem->SetParent( getModel<SCHEMATIC>() );
|
|
|
|
labelItem->SetBold( m_lastTextBold );
|
|
|
|
labelItem->SetItalic( m_lastTextItalic );
|
|
|
|
labelItem->SetTextSpinStyle( m_lastTextOrientation );
|
2023-02-19 03:40:07 +00:00
|
|
|
labelItem->SetTextSize( VECTOR2I( sch_settings.m_DefaultTextSize,
|
|
|
|
sch_settings.m_DefaultTextSize ) );
|
2022-05-02 08:42:15 +00:00
|
|
|
labelItem->SetFlags( IS_NEW | IS_MOVING );
|
|
|
|
labelItem->SetText( netName );
|
|
|
|
item = labelItem;
|
|
|
|
}
|
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 );
|
|
|
|
}
|
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." ) );
|
2019-05-16 21:27:03 +00:00
|
|
|
m_statusPopup->Move( wxGetMousePosition() + 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
|
|
|
{
|
2022-12-29 14:32:10 +00:00
|
|
|
createNextSheetPin();
|
2019-05-16 21:58:47 +00:00
|
|
|
|
2022-12-29 14:32:10 +00:00
|
|
|
if( !item )
|
2019-05-16 21:58:47 +00:00
|
|
|
{
|
2022-12-29 14:32:10 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
|
|
|
break;
|
2019-05-16 21:58:47 +00:00
|
|
|
}
|
|
|
|
}
|
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-04-18 22:42:35 +00:00
|
|
|
cursorPos = grid.BestSnapAnchor( cursorPos, snapLayer, 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 );
|
2021-04-03 10:14:21 +00:00
|
|
|
item->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
|
2021-04-02 10:18:25 +00:00
|
|
|
updatePreview();
|
2020-10-08 02:47:01 +00:00
|
|
|
|
2022-05-22 04:42:22 +00:00
|
|
|
if( item->Type() != SCH_SHEET_PIN_T )
|
|
|
|
m_selectionTool->AddItemToSel( item );
|
2021-04-03 18:39:56 +00:00
|
|
|
|
2022-05-16 22:41:30 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
|
|
|
|
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
|
|
|
{
|
2021-05-30 21:04:07 +00:00
|
|
|
item->ClearFlags( IS_MOVING );
|
2021-07-17 19:56:18 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), item, false );
|
2020-10-20 21:51:29 +00:00
|
|
|
item = nullptr;
|
2019-05-01 20:15:51 +00:00
|
|
|
|
2020-10-20 21:51:29 +00:00
|
|
|
m_view->ClearPreview();
|
2022-12-29 14:32:10 +00:00
|
|
|
|
|
|
|
// Exit the tool when this sheet runs out of pins for convenience
|
|
|
|
if( isSheetPin )
|
|
|
|
{
|
|
|
|
createNextSheetPin();
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
{
|
|
|
|
m_frame->PopTool( aEvent );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
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
|
|
|
}
|
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 );
|
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>();
|
2022-03-28 20:16:47 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
if( m_inDrawShape )
|
|
|
|
return 0;
|
|
|
|
|
2022-03-28 20:16:47 +00:00
|
|
|
REENTRANCY_GUARD guard( &m_inDrawShape );
|
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();
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
|
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 =
|
|
|
|
[&] ()
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
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();
|
|
|
|
|
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
|
|
|
|
|
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
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
|
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
|
|
|
|
|
|
|
textbox->SetBold( m_lastTextBold );
|
|
|
|
textbox->SetItalic( m_lastTextItalic );
|
2023-02-19 03:40:07 +00:00
|
|
|
textbox->SetTextSize( VECTOR2I( sch_settings.m_DefaultTextSize,
|
|
|
|
sch_settings.m_DefaultTextSize ) );
|
2022-06-03 20:47:13 +00:00
|
|
|
textbox->SetTextAngle( m_lastTextAngle );
|
|
|
|
textbox->SetHorizJustify( m_lastTextJust );
|
2022-06-08 09:32:45 +00:00
|
|
|
textbox->SetStroke( m_lastTextboxStroke );
|
|
|
|
textbox->SetFillColor( m_lastTextboxFillColor );
|
2022-06-03 20:47:13 +00:00
|
|
|
|
|
|
|
item = textbox;
|
|
|
|
}
|
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 );
|
|
|
|
}
|
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
|
2021-07-17 19:56:18 +00:00
|
|
|
|| evt->IsAction( &EE_ACTIONS::finishDrawing ) ) )
|
|
|
|
{
|
2022-05-02 21:26:55 +00:00
|
|
|
if( evt->IsDblClick( BUT_LEFT )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::finishDrawing )
|
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
|
|
|
|
2022-07-19 16:19:38 +00:00
|
|
|
// This is modal not quasi to protect against place symbol calls starting
|
|
|
|
// TwoClickPlace wait routines in the middle
|
|
|
|
if( dlg.ShowModal() != 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();
|
|
|
|
m_lastTextAngle = textbox->GetTextAngle();
|
|
|
|
m_lastTextJust = textbox->GetHorizJustify();
|
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
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), item, false );
|
|
|
|
m_selectionTool->AddItemToSel( item );
|
|
|
|
item = nullptr;
|
|
|
|
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_toolMgr->RunAction( ACTIONS::activatePointEditor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::properties, true );
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
// Warp after context menu only if dragging...
|
|
|
|
if( !item )
|
|
|
|
m_toolMgr->VetoContextMenuMouseWarp();
|
|
|
|
|
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-01-27 19:50:07 +00:00
|
|
|
if( m_inDrawSheet )
|
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawSheet );
|
2021-01-27 19:50:07 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
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 =
|
|
|
|
[&] ()
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
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();
|
2019-06-27 21:33:48 +00:00
|
|
|
|
2021-05-09 19:17:01 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
|
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
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
|
|
|
{
|
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 ) )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::enterSheet, false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
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" );
|
2021-03-03 01:06:25 +00:00
|
|
|
sheet->GetFields()[ SHEETFILENAME ].SetText( "untitled." + 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
|
2019-05-10 17:19:48 +00:00
|
|
|
|| evt->IsAction( &EE_ACTIONS::finishSheet ) ) )
|
2019-05-07 23:51:37 +00:00
|
|
|
{
|
|
|
|
m_view->ClearPreview();
|
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
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
|
2020-03-06 12:05:21 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), sheet, false );
|
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
|
|
|
{
|
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
|
|
|
}
|
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
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::importSheetPin.MakeEvent() );
|
|
|
|
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() );
|
2019-06-15 00:29:42 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceImage, EE_ACTIONS::placeImage.MakeEvent() );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|