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
|
2020-04-04 20:32:14 +00:00
|
|
|
* Copyright (C) 2019-2020 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>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2020-12-12 03:13:52 +00:00
|
|
|
#include <tools/symbol_editor_drawing_tools.h>
|
|
|
|
#include <tools/symbol_editor_pin_tool.h>
|
2019-05-07 18:49:53 +00:00
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <lib_text.h>
|
|
|
|
#include <dialogs/dialog_lib_edit_text.h>
|
2019-05-07 23:51:37 +00:00
|
|
|
#include <lib_arc.h>
|
|
|
|
#include <lib_circle.h>
|
|
|
|
#include <lib_polyline.h>
|
|
|
|
#include <lib_rectangle.h>
|
2020-05-23 15:50:08 +00:00
|
|
|
#include <pgm_base.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>
|
2020-12-01 14:58:33 +00:00
|
|
|
#include <kicad_string.h>
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
static void* g_lastPinWeakPtr;
|
|
|
|
|
|
|
|
|
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" ),
|
2020-05-23 15:50:08 +00:00
|
|
|
m_lastTextAngle( 0.0 ),
|
2020-10-15 01:45:20 +00:00
|
|
|
m_lastFillStyle( FILL_TYPE::NO_FILL ),
|
2020-05-23 15:50:08 +00:00
|
|
|
m_drawSpecificConvert( true ),
|
|
|
|
m_drawSpecificUnit( 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 )
|
|
|
|
{
|
|
|
|
LIB_ITEM* item = (LIB_ITEM*) aSel.Front();
|
|
|
|
return item && item->IsNew();
|
|
|
|
};
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
m_menu.GetMenu().AddItem( EE_ACTIONS::finishDrawing, 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
|
|
|
{
|
2020-12-12 03:13:52 +00:00
|
|
|
KICAD_T type = aEvent.Parameter<KICAD_T>();
|
|
|
|
auto* settings = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
|
|
|
|
auto* pinTool = type == LIB_PIN_T ? m_toolMgr->GetTool<SYMBOL_EDITOR_PIN_TOOL>() : nullptr;
|
|
|
|
VECTOR2I cursorPos;
|
|
|
|
EDA_ITEM* item = nullptr;
|
|
|
|
bool isText = aEvent.IsAction( &EE_ACTIONS::placeSymbolText );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-12 11:49:58 +00:00
|
|
|
getViewControls()->ShowCursor( true );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2019-05-07 18:49:53 +00:00
|
|
|
Activate();
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
// Prime the pump
|
2021-02-24 18:43:12 +00:00
|
|
|
if( aEvent.HasPosition() || ( isText && !aEvent.IsReactivate() ) )
|
2019-06-15 00:29:42 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
// 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();
|
2020-10-08 00:50:28 +00:00
|
|
|
|
2021-05-09 19:17:01 +00:00
|
|
|
cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2020-11-19 20:08:58 +00:00
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
m_view->ClearPreview();
|
|
|
|
delete item;
|
|
|
|
item = nullptr;
|
|
|
|
};
|
2019-07-01 21:01:33 +00:00
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
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
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
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
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
if( item )
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
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
|
|
|
}
|
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
|
|
|
{
|
|
|
|
LIB_PART* part = m_frame->GetCurPart();
|
|
|
|
|
|
|
|
if( !part )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// First click creates...
|
|
|
|
if( !item )
|
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
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
|
|
|
{
|
|
|
|
case LIB_PIN_T:
|
|
|
|
{
|
2019-08-15 18:32:19 +00:00
|
|
|
item = pinTool->CreatePin( wxPoint( cursorPos.x, -cursorPos.y ), part );
|
2019-05-08 18:56:03 +00:00
|
|
|
g_lastPinWeakPtr = item;
|
2019-05-07 18:49:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LIB_TEXT_T:
|
|
|
|
{
|
2020-04-18 20:04:41 +00:00
|
|
|
LIB_TEXT* text = new LIB_TEXT( part );
|
2020-05-23 15:50:08 +00:00
|
|
|
|
2019-08-15 18:32:19 +00:00
|
|
|
text->SetPosition( wxPoint( cursorPos.x, -cursorPos.y ) );
|
2020-05-23 15:50:08 +00:00
|
|
|
text->SetTextSize( wxSize( Mils2iu( settings->m_Defaults.text_size ),
|
|
|
|
Mils2iu( settings->m_Defaults.text_size ) ) );
|
|
|
|
text->SetTextAngle( m_lastTextAngle );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
|
|
|
DIALOG_LIB_EDIT_TEXT dlg( m_frame, text );
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Restore cursor after dialog
|
2019-06-13 13:34:38 +00:00
|
|
|
getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
|
|
|
if( item )
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
getViewControls()->SetCursorPosition( cursorPos, false );
|
2019-05-07 18:49:53 +00:00
|
|
|
}
|
|
|
|
// ... and second click places:
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_frame->SaveCopyInUndoList( part );
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case LIB_PIN_T:
|
|
|
|
pinTool->PlacePin( (LIB_PIN*) item );
|
|
|
|
break;
|
|
|
|
case LIB_TEXT_T:
|
|
|
|
part->AddDrawItem( (LIB_TEXT*) item );
|
|
|
|
break;
|
|
|
|
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
|
|
|
|
2019-06-26 23:01:39 +00:00
|
|
|
item->ClearEditFlags();
|
2019-05-07 18:49:53 +00:00
|
|
|
item = nullptr;
|
|
|
|
m_view->ClearPreview();
|
|
|
|
|
|
|
|
m_frame->RebuildView();
|
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2019-08-15 18:32:19 +00:00
|
|
|
static_cast<LIB_ITEM*>( item )->SetPosition( wxPoint( 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
|
2019-06-18 17:56:40 +00:00
|
|
|
getViewControls()->SetAutoPan( item != nullptr );
|
|
|
|
getViewControls()->CaptureCursor( item != nullptr );
|
2019-05-07 23:51:37 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
SYMBOL_EDITOR_SETTINGS* settings = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
|
2020-11-22 22:21:41 +00:00
|
|
|
KICAD_T type = aEvent.Parameter<KICAD_T>();
|
2019-06-15 00:29:42 +00:00
|
|
|
|
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();
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-12 11:49:58 +00:00
|
|
|
getViewControls()->ShowCursor( true );
|
2019-05-07 23:51:37 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2019-05-07 23:51:37 +00:00
|
|
|
Activate();
|
|
|
|
|
|
|
|
LIB_PART* part = m_frame->GetCurPart();
|
|
|
|
LIB_ITEM* item = nullptr;
|
|
|
|
|
2019-06-18 17:56:40 +00:00
|
|
|
// Prime the pump
|
2019-06-19 15:11:41 +00:00
|
|
|
if( aEvent.HasPosition() )
|
2019-06-18 17:56:40 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
|
|
|
|
2020-10-09 01:15:03 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
2020-10-08 02:47:01 +00:00
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
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();
|
2019-06-27 21:33:48 +00:00
|
|
|
|
2021-05-09 19:17:01 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
|
2019-05-07 23:51:37 +00:00
|
|
|
|
2020-11-19 20:08:58 +00:00
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
m_view->ClearPreview();
|
|
|
|
delete item;
|
|
|
|
item = nullptr;
|
|
|
|
};
|
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 )
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
|
|
|
else
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
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
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
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 )
|
|
|
|
{
|
|
|
|
if( !part )
|
|
|
|
continue;
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-10 16:48:46 +00:00
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
switch( type )
|
2019-05-07 23:51:37 +00:00
|
|
|
{
|
2019-06-15 00:29:42 +00:00
|
|
|
case LIB_ARC_T: item = new LIB_ARC( part ); break;
|
|
|
|
case LIB_CIRCLE_T: item = new LIB_CIRCLE( part ); break;
|
|
|
|
case LIB_POLYLINE_T: item = new LIB_POLYLINE( part ); break;
|
|
|
|
case LIB_RECTANGLE_T: item = new LIB_RECTANGLE( part ); break;
|
2019-06-16 07:12:32 +00:00
|
|
|
default: break; // keep compiler quiet
|
2019-05-07 23:51:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 18:23:50 +00:00
|
|
|
wxCHECK( item, 0 );
|
2019-06-16 07:12:32 +00:00
|
|
|
|
2021-03-13 00:07:58 +00:00
|
|
|
item->SetWidth( Mils2iu( settings->m_Defaults.line_width ) );
|
2020-05-23 15:50:08 +00:00
|
|
|
item->SetFillMode( m_lastFillStyle );
|
2019-05-20 10:23:32 +00:00
|
|
|
item->SetFlags( IS_NEW );
|
|
|
|
item->BeginEdit( wxPoint( cursorPos.x, -cursorPos.y ) );
|
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() );
|
|
|
|
|
2020-05-23 15:50:08 +00:00
|
|
|
if( m_drawSpecificConvert )
|
2019-05-07 23:51:37 +00:00
|
|
|
item->SetConvert( m_frame->GetConvert() );
|
|
|
|
|
|
|
|
m_selectionTool->AddItemToSel( item );
|
|
|
|
}
|
2019-06-18 21:34:31 +00:00
|
|
|
else if( item && ( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT )
|
2019-05-10 17:19:48 +00:00
|
|
|
|| evt->IsAction( &EE_ACTIONS::finishDrawing ) ) )
|
2019-05-07 23:51:37 +00:00
|
|
|
{
|
2019-06-18 21:34:31 +00:00
|
|
|
if( evt->IsDblClick( BUT_LEFT ) || evt->IsAction( &EE_ACTIONS::finishDrawing )
|
|
|
|
|| !item->ContinueEdit( wxPoint( cursorPos.x, -cursorPos.y ) ) )
|
2019-05-07 23:51:37 +00:00
|
|
|
{
|
2019-05-20 10:23:32 +00:00
|
|
|
item->EndEdit();
|
|
|
|
item->ClearEditFlags();
|
2019-05-07 23:51:37 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
|
|
|
|
m_frame->SaveCopyInUndoList( part );
|
|
|
|
part->AddDrawItem( item );
|
2019-05-07 18:49:53 +00:00
|
|
|
item = nullptr;
|
2019-05-07 23:51:37 +00:00
|
|
|
|
|
|
|
m_frame->RebuildView();
|
|
|
|
m_frame->OnModify();
|
2019-06-19 15:11:41 +00:00
|
|
|
m_toolMgr->RunAction( 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
|
|
|
{
|
2019-05-07 23:51:37 +00:00
|
|
|
item->CalcEdit( wxPoint( cursorPos.x, -cursorPos.y) );
|
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 )
|
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::properties, true );
|
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
|
2019-06-18 17:56:40 +00:00
|
|
|
getViewControls()->SetAutoPan( item != nullptr );
|
|
|
|
getViewControls()->CaptureCursor( item != nullptr );
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
getViewControls()->ShowCursor( true );
|
2019-05-07 18:49:53 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2019-05-07 18:49:53 +00:00
|
|
|
Activate();
|
|
|
|
|
2020-10-09 01:15:03 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::BULLSEYE );
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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() )
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
2019-05-07 18:49:53 +00:00
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
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
|
|
|
{
|
|
|
|
LIB_PART* part = m_frame->GetCurPart();
|
|
|
|
|
|
|
|
if( !part )
|
|
|
|
continue;
|
|
|
|
|
2021-05-09 19:17:01 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
|
2019-05-07 18:49:53 +00:00
|
|
|
wxPoint offset( -cursorPos.x, cursorPos.y );
|
|
|
|
|
|
|
|
part->SetOffset( offset );
|
|
|
|
|
|
|
|
// Refresh the view without changing the viewport
|
|
|
|
auto center = m_view->GetCenter();
|
|
|
|
center.x += offset.x;
|
|
|
|
center.y -= offset.y;
|
|
|
|
m_view->SetCenter( center );
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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>();
|
2019-05-08 18:56:03 +00:00
|
|
|
LIB_PART* part = m_frame->GetCurPart();
|
|
|
|
LIB_PIN* sourcePin = nullptr;
|
|
|
|
|
|
|
|
if( !part )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// See if we have a pin matching our weak ptr
|
|
|
|
for( LIB_PIN* test = part->GetNextPin(); test; test = part->GetNextPin( test ) )
|
|
|
|
{
|
|
|
|
if( (void*) test == g_lastPinWeakPtr )
|
|
|
|
sourcePin = test;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( sourcePin )
|
|
|
|
{
|
|
|
|
LIB_PIN* pin = pinTool->RepeatPin( sourcePin );
|
|
|
|
g_lastPinWeakPtr = pin;
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( pin )
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::addItemToSel, true, 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
|
|
|
{
|
2020-12-12 03:13:52 +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::drawSymbolRectangle.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawSymbolCircle.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawSymbolArc.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawSymbolLines.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor, EE_ACTIONS::placeSymbolAnchor.MakeEvent() );
|
|
|
|
Go( &SYMBOL_EDITOR_DRAWING_TOOLS::RepeatDrawItem, EE_ACTIONS::repeatDrawItem.MakeEvent() );
|
2019-05-07 18:49:53 +00:00
|
|
|
}
|