2019-05-07 18:49:53 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2024-04-15 20:18:54 +00:00
|
|
|
* Copyright (C) 2019-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-07 18:49:53 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <ee_actions.h>
|
2023-06-28 23:01:07 +00:00
|
|
|
#include <optional>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2023-06-09 21:41:33 +00:00
|
|
|
#include <sch_commit.h>
|
2023-09-18 23:52:27 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2020-12-12 03:13:52 +00:00
|
|
|
#include <tools/symbol_editor_drawing_tools.h>
|
|
|
|
#include <tools/symbol_editor_pin_tool.h>
|
2022-03-07 12:45:24 +00:00
|
|
|
#include <tools/ee_grid_helper.h>
|
2024-04-14 18:04:53 +00:00
|
|
|
#include <dialogs/dialog_text_properties.h>
|
2024-04-15 20:18:54 +00:00
|
|
|
#include <sch_shape.h>
|
|
|
|
#include <sch_textbox.h>
|
2020-05-23 15:50:08 +00:00
|
|
|
#include <pgm_base.h>
|
2024-04-27 19:57:24 +00:00
|
|
|
#include <view/view_controls.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_editor/symbol_editor_settings.h>
|
2020-05-23 15:50:08 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2023-10-09 00:54:34 +00:00
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <import_gfx/dialog_import_gfx_sch.h>
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2024-06-23 21:36:24 +00:00
|
|
|
|
|
|
|
KIID SYMBOL_EDITOR_DRAWING_TOOLS::g_lastPin;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
SYMBOL_EDITOR_DRAWING_TOOLS::SYMBOL_EDITOR_DRAWING_TOOLS() :
|
2020-10-31 01:27:16 +00:00
|
|
|
EE_TOOL_BASE<SYMBOL_EDIT_FRAME>( "eeschema.SymbolDrawing" ),
|
2022-06-04 20:24:31 +00:00
|
|
|
m_lastTextBold( false ),
|
|
|
|
m_lastTextItalic( false ),
|
2022-01-13 12:29:46 +00:00
|
|
|
m_lastTextAngle( ANGLE_HORIZONTAL ),
|
2022-06-04 20:24:31 +00:00
|
|
|
m_lastTextJust( GR_TEXT_H_ALIGN_LEFT ),
|
2021-07-18 23:08:54 +00:00
|
|
|
m_lastFillStyle( FILL_T::NO_FILL ),
|
2022-06-04 20:24:31 +00:00
|
|
|
m_lastFillColor( COLOR4D::UNSPECIFIED ),
|
2023-11-25 13:05:45 +00:00
|
|
|
m_lastStroke( 0, LINE_STYLE::DEFAULT, COLOR4D::UNSPECIFIED ),
|
2024-01-26 16:16:13 +00:00
|
|
|
m_drawSpecificBodyStyle( true ),
|
2022-06-09 15:53:24 +00:00
|
|
|
m_drawSpecificUnit( false ),
|
|
|
|
m_inDrawShape( false ),
|
|
|
|
m_inTwoClickPlace( false )
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
bool SYMBOL_EDITOR_DRAWING_TOOLS::Init()
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE::Init();
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
auto isDrawingCondition =
|
|
|
|
[] ( const SELECTION& aSel )
|
|
|
|
{
|
2024-04-06 13:14:44 +00:00
|
|
|
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aSel.Front() );
|
2020-11-22 22:21:41 +00:00
|
|
|
return item && item->IsNew();
|
|
|
|
};
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2022-12-29 16:55:05 +00:00
|
|
|
m_menu.GetMenu().AddItem( ACTIONS::finishInteractive, isDrawingCondition, 2 );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2022-03-07 12:45:24 +00:00
|
|
|
KICAD_T type = aEvent.Parameter<KICAD_T>();
|
|
|
|
auto* settings = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
|
2024-04-20 09:44:34 +00:00
|
|
|
auto* pinTool = type == SCH_PIN_T ? m_toolMgr->GetTool<SYMBOL_EDITOR_PIN_TOOL>() : nullptr;
|
2022-03-07 12:45:24 +00:00
|
|
|
|
2022-06-09 15:53:24 +00:00
|
|
|
if( m_inTwoClickPlace )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inTwoClickPlace );
|
|
|
|
|
2022-03-07 12:45:24 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
VECTOR2I cursorPos;
|
|
|
|
bool ignorePrimePosition = false;
|
2024-04-06 13:14:44 +00:00
|
|
|
SCH_ITEM* item = nullptr;
|
2022-03-07 12:45:24 +00:00
|
|
|
bool isText = aEvent.IsAction( &EE_ACTIONS::placeSymbolText );
|
2022-05-16 22:41:30 +00:00
|
|
|
COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2019-06-15 00:29:42 +00:00
|
|
|
|
2020-10-09 01:15:03 +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-11-19 20:08:58 +00:00
|
|
|
else if( isText )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::TEXT );
|
2020-10-08 02:47:01 +00:00
|
|
|
else
|
2020-11-19 20:08:58 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
2020-10-08 02:47:01 +00:00
|
|
|
};
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
Activate();
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
2022-03-07 12:45:24 +00:00
|
|
|
controls->ShowCursor( true );
|
2020-10-08 02:47:01 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2022-03-07 12:45:24 +00:00
|
|
|
if( aEvent.HasPosition() )
|
|
|
|
{
|
|
|
|
m_toolMgr->PrimeTool( aEvent.Position() );
|
|
|
|
}
|
2022-05-16 22:41:30 +00:00
|
|
|
else if( common_settings->m_Input.immediate_actions && !aEvent.IsReactivate() )
|
2022-03-07 12:45:24 +00:00
|
|
|
{
|
|
|
|
m_toolMgr->PrimeTool( { 0, 0 } );
|
|
|
|
ignorePrimePosition = true;
|
|
|
|
}
|
2021-09-13 12:23:10 +00:00
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2022-03-07 12:45:24 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2020-10-08 00:50:28 +00:00
|
|
|
|
2023-08-22 14:09:04 +00:00
|
|
|
cursorPos = grid.Align( controls->GetMousePosition(), grid.GetItemGrid( item ) );
|
2022-03-07 12:45:24 +00:00
|
|
|
controls->ForceCursorPosition( true, cursorPos );
|
2019-05-07 18:49:53 +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
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2022-03-17 15:26:49 +00:00
|
|
|
m_frame->GetInfoBar()->Dismiss();
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
if( item )
|
2020-11-22 22:21:41 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
2020-11-22 22:21:41 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
2019-05-07 18:49:53 +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
|
|
|
{
|
2022-03-07 12:45:24 +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 )
|
2022-03-07 12:45:24 +00:00
|
|
|
{
|
|
|
|
m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel item creation." ) );
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
|
2022-03-07 12:45:24 +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-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-05-07 18:49:53 +00:00
|
|
|
}
|
2022-06-09 15:53:24 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) || isSyntheticClick )
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !symbol )
|
2019-05-07 18:49:53 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// First click creates...
|
|
|
|
if( !item )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2019-06-18 17:56:40 +00:00
|
|
|
switch( type )
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2024-04-20 09:44:34 +00:00
|
|
|
case SCH_PIN_T:
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2024-04-27 12:47:56 +00:00
|
|
|
item = pinTool->CreatePin( cursorPos, symbol );
|
2024-06-23 21:36:24 +00:00
|
|
|
g_lastPin = item->m_Uuid;
|
2019-05-07 18:49:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2024-04-14 18:04:53 +00:00
|
|
|
case SCH_TEXT_T:
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2024-04-27 12:47:56 +00:00
|
|
|
SCH_TEXT* text = new SCH_TEXT( cursorPos, wxEmptyString, LAYER_DEVICE );
|
2024-04-14 18:04:53 +00:00
|
|
|
|
|
|
|
text->SetParent( symbol );
|
2020-05-23 15:50:08 +00:00
|
|
|
|
2023-01-06 00:32:25 +00:00
|
|
|
if( m_drawSpecificUnit )
|
|
|
|
text->SetUnit( m_frame->GetUnit() );
|
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
if( m_drawSpecificBodyStyle )
|
|
|
|
text->SetBodyStyle( m_frame->GetBodyStyle() );
|
2023-01-06 00:32:25 +00:00
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
text->SetTextSize( VECTOR2I( schIUScale.MilsToIU( settings->m_Defaults.text_size ),
|
|
|
|
schIUScale.MilsToIU( settings->m_Defaults.text_size ) ) );
|
2020-05-23 15:50:08 +00:00
|
|
|
text->SetTextAngle( m_lastTextAngle );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2024-04-14 18:04:53 +00:00
|
|
|
DIALOG_TEXT_PROPERTIES dlg( m_frame, text );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2020-12-01 14:58:33 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK || NoPrintableChars( text->GetText() ) )
|
2019-05-07 18:49:53 +00:00
|
|
|
delete text;
|
|
|
|
else
|
|
|
|
item = text;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2019-06-18 17:56:40 +00:00
|
|
|
wxFAIL_MSG( "TwoClickPlace(): unknown type" );
|
2019-05-07 18:49:53 +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 )
|
|
|
|
{
|
2023-08-22 14:09:04 +00:00
|
|
|
cursorPos = grid.Align( evt->Position(), grid.GetItemGrid( item ) );
|
2022-05-16 22:41:30 +00:00
|
|
|
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();
|
|
|
|
}
|
2019-05-07 18:49:53 +00:00
|
|
|
|
|
|
|
if( item )
|
|
|
|
{
|
2022-03-07 12:45:24 +00:00
|
|
|
item->SetPosition( VECTOR2I( cursorPos.x, -cursorPos.y ) );
|
|
|
|
|
2021-05-30 21:04:07 +00:00
|
|
|
item->SetFlags( IS_NEW | IS_MOVING );
|
2019-05-07 18:49:53 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( item->Clone() );
|
|
|
|
m_selectionTool->AddItemToSel( item );
|
2020-10-08 02:47:01 +00:00
|
|
|
|
|
|
|
// update the cursor so it looks correct before another event
|
|
|
|
setCursor();
|
2019-05-07 18:49:53 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 12:45:24 +00:00
|
|
|
controls->SetCursorPosition( cursorPos, false );
|
2019-05-07 18:49:53 +00:00
|
|
|
}
|
|
|
|
// ... and second click places:
|
|
|
|
else
|
|
|
|
{
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
commit.Modify( symbol, m_frame->GetScreen() );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2024-04-20 09:44:34 +00:00
|
|
|
case SCH_PIN_T:
|
|
|
|
pinTool->PlacePin( static_cast<SCH_PIN*>( item ) );
|
2023-07-16 12:56:09 +00:00
|
|
|
item->ClearEditFlags();
|
|
|
|
commit.Push( _( "Add Pin" ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
break;
|
2023-07-16 12:56:09 +00:00
|
|
|
|
2024-04-14 18:04:53 +00:00
|
|
|
case SCH_TEXT_T:
|
|
|
|
symbol->AddDrawItem( static_cast<SCH_TEXT*>( item ) );
|
2023-07-16 12:56:09 +00:00
|
|
|
item->ClearEditFlags();
|
|
|
|
commit.Push( _( "Add Text" ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
break;
|
2023-07-16 12:56:09 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
default:
|
2019-06-18 17:56:40 +00:00
|
|
|
wxFAIL_MSG( "TwoClickPlace(): unknown type" );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2019-05-07 18:49:53 +00:00
|
|
|
|
|
|
|
item = nullptr;
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_frame->RebuildView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
// Warp after context menu only if dragging...
|
|
|
|
if( !item )
|
|
|
|
m_toolMgr->VetoContextMenuMouseWarp();
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
2019-05-07 18:49:53 +00:00
|
|
|
}
|
2019-07-04 20:56:21 +00:00
|
|
|
else if( item && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
|
2019-05-07 23:51:37 +00:00
|
|
|
{
|
2024-05-05 21:20:42 +00:00
|
|
|
item->SetPosition( VECTOR2I( cursorPos.x, cursorPos.y ) );
|
2019-05-07 23:51:37 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( item->Clone() );
|
|
|
|
}
|
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-07-26 18:16:44 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
// Enable autopanning and cursor capture only when there is an item to be placed
|
2022-03-07 12:45:24 +00:00
|
|
|
controls->SetAutoPan( item != nullptr );
|
|
|
|
controls->CaptureCursor( item != nullptr );
|
2019-05-07 23:51:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 12:45:24 +00:00
|
|
|
controls->SetAutoPan( false );
|
|
|
|
controls->CaptureCursor( false );
|
2022-05-14 21:38:04 +00:00
|
|
|
controls->ForceCursorPosition( false );
|
2020-11-19 20:08:58 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2019-05-07 23:51:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
|
2019-05-07 23:51:37 +00:00
|
|
|
{
|
2023-06-28 23:01:07 +00:00
|
|
|
SHAPE_T requestedShape = aEvent.Parameter<SHAPE_T>();
|
|
|
|
|
|
|
|
return doDrawShape( aEvent, requestedShape );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SYMBOL_EDITOR_DRAWING_TOOLS::DrawSymbolTextBox( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
return doDrawShape( aEvent, std::nullopt /* Draw text box */ );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SYMBOL_EDITOR_DRAWING_TOOLS::doDrawShape( const TOOL_EVENT& aEvent, std::optional<SHAPE_T> aDrawingShape )
|
|
|
|
{
|
|
|
|
bool isTextBox = !aDrawingShape.has_value();
|
|
|
|
SHAPE_T toolType = aDrawingShape.value_or( SHAPE_T::SEGMENT );
|
|
|
|
|
2023-08-22 14:09:04 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
2021-09-13 12:23:10 +00:00
|
|
|
SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
|
|
|
|
SYMBOL_EDITOR_SETTINGS* settings = settingsMgr.GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
|
2023-08-22 14:09:04 +00:00
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
VECTOR2I cursorPos;
|
2023-05-07 13:51:17 +00:00
|
|
|
SHAPE_T shapeType = toolType == SHAPE_T::SEGMENT ? SHAPE_T::POLY : toolType;
|
2021-09-13 12:23:10 +00:00
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* item = nullptr;
|
2023-06-09 21:41:33 +00:00
|
|
|
wxString description;
|
2019-06-15 00:29:42 +00:00
|
|
|
|
2022-06-09 15:53:24 +00:00
|
|
|
if( m_inDrawShape )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawShape );
|
|
|
|
|
2019-05-10 18:55:48 +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 );
|
2019-05-07 23:51:37 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2019-06-18 17:56:40 +00:00
|
|
|
|
2020-10-09 01:15:03 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
2020-10-08 02:47:01 +00:00
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2021-09-13 12:23:10 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
delete item;
|
|
|
|
item = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
2023-08-22 14:09:04 +00:00
|
|
|
controls->ShowCursor( true );
|
2020-10-08 02:47:01 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
if( aEvent.HasPosition() )
|
2022-05-16 09:22:55 +00:00
|
|
|
m_toolMgr->PrimeTool( aEvent.Position() );
|
2021-09-13 12:23:10 +00:00
|
|
|
|
2019-05-07 23:51:37 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-27 21:33:48 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-05-07 23:51:37 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2023-08-22 14:09:04 +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-22 14:09:04 +00:00
|
|
|
cursorPos = grid.Align( controls->GetMousePosition(), grid.GetItemGrid( item ) );
|
|
|
|
controls->ForceCursorPosition( true, cursorPos );
|
2019-05-07 23:51:37 +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
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2019-05-07 23:51:37 +00:00
|
|
|
if( item )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
2019-05-07 18:49:53 +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
|
|
|
{
|
|
|
|
if( item )
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
if( evt->IsPointEditor() )
|
2019-06-18 17:56:40 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
// 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
|
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-05-07 23:51:37 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) && !item )
|
|
|
|
{
|
2022-01-06 00:50:24 +00:00
|
|
|
// Update in case the symbol was changed while the tool was running
|
|
|
|
symbol = m_frame->GetCurSymbol();
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !symbol )
|
2019-05-07 23:51:37 +00:00
|
|
|
continue;
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-10 16:48:46 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
int lineWidth = schIUScale.MilsToIU( settings->m_Defaults.line_width );
|
2019-06-16 07:12:32 +00:00
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
if( isTextBox )
|
2022-06-04 20:24:31 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_TEXTBOX* textbox = new SCH_TEXTBOX( LAYER_DEVICE, lineWidth, m_lastFillStyle );
|
2022-06-04 20:24:31 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
textbox->SetParent( symbol );
|
2023-02-19 03:40:07 +00:00
|
|
|
textbox->SetTextSize( VECTOR2I( schIUScale.MilsToIU( settings->m_Defaults.text_size ),
|
|
|
|
schIUScale.MilsToIU( settings->m_Defaults.text_size ) ) );
|
2024-02-25 17:28:05 +00:00
|
|
|
|
|
|
|
// Must be after SetTextSize()
|
|
|
|
textbox->SetBold( m_lastTextBold );
|
|
|
|
textbox->SetItalic( m_lastTextItalic );
|
|
|
|
|
2022-06-04 20:24:31 +00:00
|
|
|
textbox->SetTextAngle( m_lastTextAngle );
|
|
|
|
textbox->SetHorizJustify( m_lastTextJust );
|
|
|
|
|
|
|
|
item = textbox;
|
2023-06-09 21:41:33 +00:00
|
|
|
description = _( "Add Text Box" );
|
2022-06-04 20:24:31 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
else
|
2022-06-04 20:24:31 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
item = new SCH_SHAPE( shapeType, LAYER_DEVICE, lineWidth, m_lastFillStyle );
|
|
|
|
item->SetParent( symbol );
|
|
|
|
description = wxString::Format( _( "Add %s" ), item->GetFriendlyName() );
|
2022-06-04 20:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
item->SetStroke( m_lastStroke );
|
|
|
|
item->SetFillColor( m_lastFillColor );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
item->SetFlags( IS_NEW );
|
2024-04-27 12:47:56 +00:00
|
|
|
item->BeginEdit( cursorPos );
|
2019-05-07 23:51:37 +00:00
|
|
|
|
2020-05-23 15:50:08 +00:00
|
|
|
if( m_drawSpecificUnit )
|
2019-05-07 23:51:37 +00:00
|
|
|
item->SetUnit( m_frame->GetUnit() );
|
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
if( m_drawSpecificBodyStyle )
|
|
|
|
item->SetBodyStyle( m_frame->GetBodyStyle() );
|
2019-05-07 23:51:37 +00:00
|
|
|
|
|
|
|
m_selectionTool->AddItemToSel( item );
|
|
|
|
}
|
2022-06-09 15:53:24 +00:00
|
|
|
else if( item && ( evt->IsClick( BUT_LEFT )
|
|
|
|
|| evt->IsDblClick( BUT_LEFT )
|
|
|
|
|| isSyntheticClick
|
2022-12-29 16:55:05 +00:00
|
|
|
|| evt->IsAction( &ACTIONS::finishInteractive ) ) )
|
2019-05-07 23:51:37 +00:00
|
|
|
{
|
2022-01-06 00:50:24 +00:00
|
|
|
if( symbol != m_frame->GetCurSymbol() )
|
|
|
|
{
|
|
|
|
symbol = m_frame->GetCurSymbol();
|
|
|
|
item->SetParent( symbol );
|
|
|
|
}
|
|
|
|
|
2022-12-29 16:55:05 +00:00
|
|
|
if( evt->IsDblClick( BUT_LEFT ) || evt->IsAction( &ACTIONS::finishInteractive )
|
2022-01-25 22:33:37 +00:00
|
|
|
|| !item->ContinueEdit( VECTOR2I( cursorPos.x, -cursorPos.y ) ) )
|
2019-05-07 23:51:37 +00:00
|
|
|
{
|
2023-05-07 13:51:17 +00:00
|
|
|
if( toolType == SHAPE_T::POLY )
|
|
|
|
{
|
|
|
|
item->CalcEdit( item->GetPosition() ); // Close shape
|
|
|
|
item->EndEdit( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item->EndEdit();
|
|
|
|
}
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
item->ClearEditFlags();
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
if( isTextBox )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_TEXTBOX* textbox = static_cast<SCH_TEXTBOX*>( item );
|
|
|
|
DIALOG_TEXT_PROPERTIES dlg( m_frame, static_cast<SCH_TEXTBOX*>( item ) );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2024-03-10 12:18:27 +00:00
|
|
|
// QuasiModal required for syntax help and Scintilla auto-complete
|
2022-01-25 22:33:37 +00:00
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
continue;
|
|
|
|
}
|
2022-06-04 20:24:31 +00:00
|
|
|
|
|
|
|
m_lastTextBold = textbox->IsBold();
|
|
|
|
m_lastTextItalic = textbox->IsItalic();
|
|
|
|
m_lastTextAngle = textbox->GetTextAngle();
|
|
|
|
m_lastTextJust = textbox->GetHorizJustify();
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
|
|
|
|
2022-06-04 20:24:31 +00:00
|
|
|
m_lastStroke = item->GetStroke();
|
|
|
|
m_lastFillStyle = item->GetFillMode();
|
|
|
|
m_lastFillColor = item->GetFillColor();
|
|
|
|
|
2019-05-07 23:51:37 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
commit.Modify( symbol, m_frame->GetScreen() );
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
symbol->AddDrawItem( item );
|
2019-05-07 18:49:53 +00:00
|
|
|
item = nullptr;
|
2019-05-07 23:51:37 +00:00
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
commit.Push( description );
|
2019-05-07 23:51:37 +00:00
|
|
|
m_frame->RebuildView();
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::activatePointEditor );
|
2019-05-07 23:51:37 +00:00
|
|
|
}
|
2019-05-07 18:49:53 +00:00
|
|
|
}
|
2019-07-04 20:56:21 +00:00
|
|
|
else if( item && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2024-04-27 12:47:56 +00:00
|
|
|
item->CalcEdit( cursorPos );
|
2019-05-07 18:49:53 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( item->Clone() );
|
|
|
|
}
|
2019-05-07 23:51:37 +00:00
|
|
|
else if( evt->IsDblClick( BUT_LEFT ) && !item )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::properties );
|
2019-05-07 23:51:37 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
// Warp after context menu only if dragging...
|
|
|
|
if( !item )
|
|
|
|
m_toolMgr->VetoContextMenuMouseWarp();
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
2019-05-07 23:51:37 +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-07-26 18:16:44 +00:00
|
|
|
|
2019-05-07 23:51:37 +00:00
|
|
|
// Enable autopanning and cursor capture only when there is a shape being drawn
|
2023-08-22 14:09:04 +00:00
|
|
|
controls->SetAutoPan( item != nullptr );
|
|
|
|
controls->CaptureCursor( item != nullptr );
|
2019-05-07 18:49:53 +00:00
|
|
|
}
|
|
|
|
|
2023-08-22 14:09:04 +00:00
|
|
|
controls->SetAutoPan( false );
|
|
|
|
controls->CaptureCursor( false );
|
2020-11-19 20:08:58 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2019-05-07 18:49:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent )
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2020-10-09 01:15:03 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::BULLSEYE );
|
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
Activate();
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
getViewControls()->ShowCursor( true );
|
2020-10-08 02:47:01 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2019-06-27 21:33:48 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-05-07 18:49:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-12-14 22:03:17 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !symbol )
|
2019-05-07 18:49:53 +00:00
|
|
|
continue;
|
|
|
|
|
2021-05-09 19:17:01 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2024-04-27 12:47:56 +00:00
|
|
|
symbol->Move( -cursorPos );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
|
|
|
// Refresh the view without changing the viewport
|
2024-04-27 12:47:56 +00:00
|
|
|
m_view->SetCenter( m_view->GetCenter() + cursorPos );
|
2019-05-07 18:49:53 +00:00
|
|
|
m_view->RecacheAllItems();
|
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
2019-05-07 18:49:53 +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-05-07 18:49:53 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 20:08:58 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2019-05-07 18:49:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-29 02:57:21 +00:00
|
|
|
int SYMBOL_EDITOR_DRAWING_TOOLS::ImportGraphics( const TOOL_EVENT& aEvent )
|
2023-10-09 00:54:34 +00:00
|
|
|
{
|
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
|
|
|
|
|
|
|
if( !symbol )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// 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();
|
2024-04-06 13:14:44 +00:00
|
|
|
std::vector<SCH_ITEM*> newItems; // all new items, including group
|
|
|
|
std::vector<SCH_ITEM*> selectedItems; // the group, or newItems if no group
|
2023-10-09 00:54:34 +00:00
|
|
|
EE_SELECTION preview;
|
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
|
|
|
|
for( std::unique_ptr<EDA_ITEM>& ptr : list )
|
|
|
|
{
|
2024-04-06 13:14:44 +00:00
|
|
|
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( ptr.get() );
|
2023-10-09 00:54:34 +00:00
|
|
|
wxCHECK2( item, continue );
|
|
|
|
|
|
|
|
newItems.push_back( item );
|
|
|
|
selectedItems.push_back( item );
|
|
|
|
preview.Add( item );
|
|
|
|
|
|
|
|
ptr.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !dlg.IsPlacementInteractive() )
|
|
|
|
{
|
|
|
|
commit.Modify( symbol, m_frame->GetScreen() );
|
|
|
|
|
|
|
|
// Place the imported drawings
|
2024-04-06 13:14:44 +00:00
|
|
|
for( SCH_ITEM* item : newItems )
|
2023-10-09 00:54:34 +00:00
|
|
|
{
|
|
|
|
symbol->AddDrawItem( item );
|
|
|
|
item->ClearEditFlags();
|
|
|
|
}
|
|
|
|
|
|
|
|
commit.Push( _( "Import Graphic" ) );
|
|
|
|
m_frame->RebuildView();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
for( SCH_ITEM* item : selectedItems )
|
|
|
|
item->Move( delta );
|
2023-10-09 00:54:34 +00:00
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
for( SCH_ITEM* item : newItems )
|
2023-10-09 00:54:34 +00:00
|
|
|
delete item;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsMotion() )
|
|
|
|
{
|
2024-04-27 12:47:56 +00:00
|
|
|
delta = cursorPos - currentOffset;
|
2023-10-09 00:54:34 +00:00
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
for( SCH_ITEM* item : selectedItems )
|
|
|
|
item->Move( delta );
|
2023-10-09 00:54:34 +00:00
|
|
|
|
|
|
|
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 ) )
|
|
|
|
{
|
|
|
|
commit.Modify( symbol, m_frame->GetScreen() );
|
|
|
|
|
|
|
|
// Place the imported drawings
|
2024-04-06 13:14:44 +00:00
|
|
|
for( SCH_ITEM* item : newItems )
|
2023-10-09 00:54:34 +00:00
|
|
|
{
|
|
|
|
symbol->AddDrawItem( item );
|
|
|
|
item->ClearEditFlags();
|
|
|
|
}
|
|
|
|
|
|
|
|
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->RebuildView();
|
|
|
|
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
|
|
|
|
m_frame->PopTool( aEvent );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
int SYMBOL_EDITOR_DRAWING_TOOLS::RepeatDrawItem( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-12-12 03:13:52 +00:00
|
|
|
SYMBOL_EDITOR_PIN_TOOL* pinTool = m_toolMgr->GetTool<SYMBOL_EDITOR_PIN_TOOL>();
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN* sourcePin = nullptr;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !symbol )
|
2019-05-08 18:56:03 +00:00
|
|
|
return 0;
|
|
|
|
|
2024-04-20 09:44:34 +00:00
|
|
|
for( SCH_PIN* test : symbol->GetAllLibPins() )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2024-06-23 21:36:24 +00:00
|
|
|
if( test->m_Uuid == g_lastPin )
|
2023-01-20 22:12:15 +00:00
|
|
|
{
|
2019-05-08 18:56:03 +00:00
|
|
|
sourcePin = test;
|
2023-01-20 22:12:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( sourcePin )
|
|
|
|
{
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN* pin = pinTool->RepeatPin( sourcePin );
|
2024-06-23 21:36:24 +00:00
|
|
|
g_lastPin = pin->m_Uuid;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( pin )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEM*>( EE_ACTIONS::addItemToSel, pin );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:13:52 +00:00
|
|
|
void SYMBOL_EDITOR_DRAWING_TOOLS::setTransitions()
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2023-06-28 23:01:07 +00:00
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeSymbolPin.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeSymbolText.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawRectangle.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawCircle.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawArc.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawSymbolLines.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawSymbolPolygon.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::DrawSymbolTextBox, EE_ACTIONS::drawSymbolTextBox.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor, EE_ACTIONS::placeSymbolAnchor.MakeEvent() );
|
2023-12-29 02:57:21 +00:00
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::ImportGraphics, EE_ACTIONS::importGraphics.MakeEvent() );
|
2023-06-28 23:01:07 +00:00
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::RepeatDrawItem, EE_ACTIONS::repeatDrawItem.MakeEvent() );
|
2019-05-07 18:49:53 +00:00
|
|
|
}
|