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
|
2022-01-29 19:07:07 +00:00
|
|
|
* Copyright (C) 2019-2022 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
|
|
|
|
*/
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
#include "sch_drawing_tools.h"
|
2019-05-10 17:19:48 +00:00
|
|
|
#include "ee_selection_tool.h"
|
2020-12-03 15:10:23 +00:00
|
|
|
#include "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>
|
|
|
|
#include <id.h>
|
|
|
|
#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>
|
2021-07-12 10:58:14 +00:00
|
|
|
#include <dialogs/dialog_line_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>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <sch_shape.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-01-24 13:40:39 +00:00
|
|
|
m_lastNetClassDirectiveItalic( true ),
|
2021-07-17 19:56:18 +00:00
|
|
|
m_lastFillStyle( FILL_T::NO_FILL ),
|
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-04-11 16:01:25 +00:00
|
|
|
EDA_RECT SCH_DRAWING_TOOLS::GetCanvasFreeAreaPixels()
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
// calculate the area of the canvas in pixels that create no autopan when
|
2021-04-11 16:01:25 +00:00
|
|
|
// is inside this area the mouse cursor
|
|
|
|
wxSize canvas_size = m_frame->GetCanvas()->GetSize();
|
|
|
|
EDA_RECT canvas_area( wxPoint( 0, 0 ), canvas_size );
|
|
|
|
const KIGFX::VC_SETTINGS& v_settings = getViewControls()->GetSettings();
|
|
|
|
|
|
|
|
if( v_settings.m_autoPanEnabled )
|
|
|
|
canvas_area.Inflate( - v_settings.m_autoPanMargin );
|
|
|
|
|
|
|
|
// Gives a margin of 2 pixels
|
|
|
|
canvas_area.Inflate( -2 );
|
|
|
|
|
|
|
|
return canvas_area;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
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
|
|
|
|
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
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
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 =
|
|
|
|
[&] ()
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
m_frame->RollbackSchematicFromUndo();
|
2021-03-18 11:46:07 +00:00
|
|
|
symbol = nullptr;
|
2021-03-18 11:27:15 +00:00
|
|
|
};
|
|
|
|
|
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 );
|
|
|
|
// 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 );
|
2019-06-16 18:51:47 +00:00
|
|
|
getViewControls()->WarpCursor( getViewControls()->GetMousePosition( false ) );
|
|
|
|
}
|
2021-02-24 18:43:12 +00:00
|
|
|
else if( !aEvent.IsReactivate() )
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-06-15 00:29:42 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::cursorClick );
|
2020-11-19 20:08:58 +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-05-09 19:17:01 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
|
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
|
|
|
{
|
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
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
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
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
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
|
|
|
|
{
|
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-04-17 19:09:48 +00:00
|
|
|
}
|
2020-12-14 22:03:17 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
|
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
|
|
|
|
2021-04-11 16:01:25 +00:00
|
|
|
// Store the mouse position: if it is outside the canvas,
|
|
|
|
// (happens when clicking on a toolbar tool) one cannot
|
|
|
|
// use the last stored cursor position to place the new symbol
|
|
|
|
// (Current mouse pos after closing the dialog will be used)
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
VECTOR2D initialMousePos = controls->GetMousePosition(false);
|
|
|
|
// Build the rectangle area acceptable to move the cursor without
|
|
|
|
// having an auto-pan
|
|
|
|
EDA_RECT canvas_area = GetCanvasFreeAreaPixels();
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
// Pick the footprint 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 );
|
2021-04-11 16:01:25 +00:00
|
|
|
// Restore cursor position after closing the dialog,
|
|
|
|
// but only if it has meaning (i.e inside the canvas)
|
|
|
|
VECTOR2D newMousePos = controls->GetMousePosition(false);
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
if( canvas_area.Contains( VECTOR2I( initialMousePos ) ) )
|
2021-04-11 16:01:25 +00:00
|
|
|
controls->WarpCursor( controls->GetCursorPosition(), true );
|
2022-01-01 17:11:21 +00:00
|
|
|
else if( !canvas_area.Contains( VECTOR2I( newMousePos ) ) )
|
2021-04-11 16:01:25 +00:00
|
|
|
// The mouse is outside the canvas area, after closing the dialog,
|
2021-07-16 20:13:26 +00:00
|
|
|
// thus can creating autopan issues. Warp the mouse to the canvas center
|
2021-04-11 16:01:25 +00:00
|
|
|
controls->WarpCursor( canvas_area.Centre(), false );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* libSymbol = sel.LibId.IsValid() ?
|
2021-06-17 21:22:10 +00:00
|
|
|
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-01-01 17:11:21 +00:00
|
|
|
VECTOR2I pos( cursorPos );
|
2021-06-10 18:51:46 +00:00
|
|
|
symbol = new SCH_SYMBOL( *libSymbol, &m_frame->GetCurrentSheet(), sel, pos );
|
2021-03-18 11:46:07 +00:00
|
|
|
addSymbol( symbol );
|
2020-10-08 02:47:01 +00:00
|
|
|
|
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
|
|
|
|
2022-02-20 00:49:26 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::trimOverlappingWires, true,
|
|
|
|
&m_selectionTool->GetSelection() );
|
2021-03-15 18:00:38 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::addNeededJunctions, true,
|
|
|
|
&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
|
|
|
|
2021-03-18 11:46:07 +00:00
|
|
|
addSymbol( nextSymbol );
|
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
|
|
|
{
|
|
|
|
if( evt->GetCommandId().get() >= ID_POPUP_SCH_SELECT_UNIT_CMP
|
2021-06-10 14:10:55 +00:00
|
|
|
&& evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_SYM_MAX )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2019-05-02 20:44:23 +00:00
|
|
|
int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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 );
|
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
|
|
|
{
|
|
|
|
SCH_BITMAP* image = aEvent.Parameter<SCH_BITMAP*>();
|
2019-06-19 15:11:41 +00:00
|
|
|
bool immediateMode = image;
|
2019-06-27 11:47:24 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
|
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-01-01 17:11:21 +00:00
|
|
|
image->SetPosition( cursorPos );
|
2019-04-26 22:23:12 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( image->Clone() );
|
|
|
|
}
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
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();
|
|
|
|
delete image;
|
|
|
|
image = nullptr;
|
|
|
|
};
|
|
|
|
|
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 );
|
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2021-03-29 10:04:06 +00:00
|
|
|
// Prime the pump
|
|
|
|
if( image )
|
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
|
|
|
else if( !aEvent.IsReactivate() )
|
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
|
|
|
|
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();
|
2021-05-09 19:17:01 +00:00
|
|
|
cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
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
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
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
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
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 if( evt->IsActivate() )
|
|
|
|
{
|
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
|
|
|
|
{
|
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-04-26 22:23:12 +00:00
|
|
|
}
|
2020-12-14 22:03:17 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
|
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
|
|
|
|
|
|
|
// Store the mouse position: if it is outside the canvas,
|
|
|
|
// (happens when clicking on a toolbar tool) one cannot
|
|
|
|
// use the last stored cursor position to place the new symbol
|
|
|
|
// (Current mouse pos after closing the dialog will be used)
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
VECTOR2D initialMousePos = controls->GetMousePosition(false);
|
2021-07-26 23:47:26 +00:00
|
|
|
|
2021-04-11 16:01:25 +00:00
|
|
|
// Build the rectangle area acceptable to move the cursor without
|
|
|
|
// having an auto-pan
|
|
|
|
EDA_RECT canvas_area = GetCanvasFreeAreaPixels();
|
|
|
|
|
2019-05-10 16:48:46 +00:00
|
|
|
wxFileDialog dlg( m_frame, _( "Choose Image" ), wxEmptyString, 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;
|
|
|
|
|
2021-04-11 16:01:25 +00:00
|
|
|
// Restore cursor position after closing the dialog,
|
|
|
|
// but only if it has meaning (i.e inside the canvas)
|
|
|
|
VECTOR2D newMousePos = controls->GetMousePosition( false );
|
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
if( canvas_area.Contains( VECTOR2I( initialMousePos ) ) )
|
2021-04-11 16:01:25 +00:00
|
|
|
controls->WarpCursor( controls->GetCursorPosition(), true );
|
2022-01-01 17:11:21 +00:00
|
|
|
else if( !canvas_area.Contains( VECTOR2I( newMousePos ) ) )
|
2021-04-11 16:01:25 +00:00
|
|
|
// The mouse is outside the canvas area, after closing the dialog,
|
2021-07-16 20:13:26 +00:00
|
|
|
// thus can creating autopan issues. Warp the mouse to the canvas center
|
2021-04-11 16:01:25 +00:00
|
|
|
controls->WarpCursor( canvas_area.Centre(), false );
|
|
|
|
|
|
|
|
cursorPos = controls->GetMousePosition( true );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
|
|
|
wxString fullFilename = dlg.GetPath();
|
|
|
|
|
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();
|
|
|
|
m_view->AddToPreview( image->Clone() );
|
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
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
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();
|
|
|
|
m_view->AddToPreview( image->Clone() );
|
2019-05-03 10:16:24 +00:00
|
|
|
m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
|
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
|
|
|
{
|
2021-02-21 15:44:38 +00:00
|
|
|
wxPoint cursorPos;
|
|
|
|
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 );
|
|
|
|
getViewControls()->WarpCursor( 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
|
|
|
|
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
{
|
|
|
|
EE_SELECTION& selection = m_selectionTool->GetSelection();
|
|
|
|
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( selection.Front() );
|
|
|
|
|
|
|
|
if( !sheet )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
SCH_HIERLABEL* label = importHierLabel( sheet );
|
|
|
|
|
|
|
|
if( !label )
|
|
|
|
{
|
|
|
|
m_statusPopup.reset( new STATUS_TEXT_POPUP( m_frame ) );
|
|
|
|
m_statusPopup->SetText( _( "No new hierarchical labels found." ) );
|
|
|
|
m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
|
|
|
|
m_statusPopup->PopupFor( 2000 );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
previewItem = createSheetPin( sheet, label );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
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 );
|
|
|
|
|
2021-03-04 01:09:24 +00:00
|
|
|
cursorPos = static_cast<wxPoint>( aEvent.HasPosition() ?
|
|
|
|
aEvent.Position() :
|
|
|
|
controls->GetMousePosition() );
|
2019-06-28 18:32:18 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
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();
|
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 );
|
|
|
|
// 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 )
|
2019-06-15 00:29:42 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
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
|
|
|
|
|
|
|
cursorPos = evt->IsPrime() ? (wxPoint) evt->Position()
|
|
|
|
: (wxPoint) controls->GetMousePosition();
|
|
|
|
|
|
|
|
cursorPos = wxPoint( grid.BestSnapAnchor( cursorPos, LAYER_CONNECTABLE, nullptr ) );
|
|
|
|
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
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
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
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
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() );
|
|
|
|
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
|
|
|
{
|
|
|
|
m_frame->PopTool( tool );
|
|
|
|
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
|
|
|
{
|
|
|
|
previewItem->SetPosition( (wxPoint)cursorPos );
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( previewItem->Clone() );
|
|
|
|
}
|
2019-10-30 23:20:11 +00:00
|
|
|
else if( evt->Category() == TC_COMMAND )
|
|
|
|
{
|
2020-06-30 01:08:33 +00:00
|
|
|
if( ( type == SCH_BUS_WIRE_ENTRY_T )
|
2019-10-30 23:20:11 +00:00
|
|
|
&& ( evt->IsAction( &EE_ACTIONS::rotateCW )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::rotateCCW )
|
2021-02-16 20:45:25 +00:00
|
|
|
|| 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 );
|
|
|
|
|
2021-07-12 10:58:14 +00:00
|
|
|
DIALOG_LINE_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 );
|
|
|
|
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 );
|
|
|
|
labelItem->GetFields()[0].SetVisible( true );
|
|
|
|
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 );
|
|
|
|
textItem->SetBold( m_lastTextBold );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
if( aType == LAYER_NETCLASS_REFS )
|
|
|
|
textItem->SetItalic( m_lastNetClassDirectiveItalic );
|
2021-10-12 20:05:37 +00:00
|
|
|
else
|
|
|
|
textItem->SetItalic( m_lastTextItalic );
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
textItem->SetTextSpinStyle( m_lastTextOrientation );
|
2020-05-23 15:50:08 +00:00
|
|
|
textItem->SetTextSize( wxSize( 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lastTextBold = textItem->IsBold();
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
if( aType == LAYER_NETCLASS_REFS )
|
|
|
|
m_lastNetClassDirectiveItalic = textItem->IsItalic();
|
2021-10-12 20:05:37 +00:00
|
|
|
else
|
|
|
|
m_lastTextItalic = textItem->IsItalic();
|
|
|
|
|
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 )
|
|
|
|
m_lastGlobalLabelShape = labelItem->GetShape();
|
|
|
|
else if( aType == LAYER_NETCLASS_REFS )
|
|
|
|
m_lastNetClassFlagShape = labelItem->GetShape();
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_SHEET_PIN* SCH_DRAWING_TOOLS::createSheetPin( SCH_SHEET* aSheet, SCH_HIERLABEL* aLabel )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
sheetPin->SetTextSize( wxSize( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
|
|
|
|
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-01-01 17:11:21 +00:00
|
|
|
sheetPin->SetPosition( (VECTOR2I) getViewControls()->GetCursorPosition() );
|
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 );
|
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
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
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() );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
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();
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
controls->ShowCursor( true );
|
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
|
|
|
// Prime the pump if the tool isn't being re-activated
|
2021-03-29 10:04:06 +00:00
|
|
|
if( aEvent.HasPosition() || ( !aEvent.IsReactivate()
|
2021-10-12 20:05:37 +00:00
|
|
|
&& ( isText || isGlobalLabel || isHierLabel || isClassLabel || isNetLabel ) ) )
|
2021-03-29 10:04:06 +00:00
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-02-23 15:28:45 +00:00
|
|
|
VECTOR2I cursorPos = evt->IsPrime() ? evt->Position() : controls->GetMousePosition();
|
|
|
|
cursorPos = grid.BestSnapAnchor( cursorPos, snapLayer, item );
|
|
|
|
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
|
|
|
{
|
|
|
|
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
|
|
|
{
|
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() )
|
|
|
|
{
|
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
|
|
|
{
|
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-04-17 19:09:48 +00:00
|
|
|
}
|
2020-12-14 22:03:17 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
|
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( isGlobalLabel )
|
|
|
|
{
|
2020-05-23 15:50:08 +00:00
|
|
|
item = createNewText( cursorPos, LAYER_GLOBLABEL );
|
2021-02-22 11:52:33 +00:00
|
|
|
}
|
|
|
|
else if( isHierLabel )
|
|
|
|
{
|
|
|
|
item = createNewText( cursorPos, LAYER_HIERLABEL );
|
|
|
|
}
|
|
|
|
else if( isNetLabel )
|
|
|
|
{
|
|
|
|
item = createNewText( cursorPos, LAYER_LOCLABEL );
|
|
|
|
}
|
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
|
|
|
{
|
2020-11-17 16:02:47 +00:00
|
|
|
EDA_ITEM* i;
|
2019-05-16 21:58:47 +00:00
|
|
|
SCH_HIERLABEL* label = nullptr;
|
2020-05-27 15:18:12 +00:00
|
|
|
SCH_SHEET* sheet = nullptr;
|
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
if( m_selectionTool->SelectPoint( cursorPos, EE_COLLECTOR::SheetsOnly, &i ) )
|
|
|
|
sheet = dynamic_cast<SCH_SHEET*>( i );
|
2020-05-27 15:18:12 +00:00
|
|
|
|
2021-04-03 18:39:56 +00:00
|
|
|
m_selectionTool->ClearSelection();
|
|
|
|
|
2019-05-16 21:58:47 +00:00
|
|
|
if( !sheet )
|
2019-05-16 21:27:03 +00:00
|
|
|
{
|
|
|
|
m_statusPopup.reset( new 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
|
|
|
{
|
2020-10-31 00:25:46 +00:00
|
|
|
label = importHierLabel( sheet );
|
2019-05-16 21:58:47 +00:00
|
|
|
|
|
|
|
if( !label )
|
|
|
|
{
|
|
|
|
m_statusPopup.reset( new STATUS_TEXT_POPUP( m_frame ) );
|
|
|
|
m_statusPopup->SetText( _( "No new hierarchical labels found." ) );
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item = createSheetPin( sheet, label );
|
2019-05-16 21:58:47 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Restore cursor after dialog
|
2020-12-03 15:10:23 +00:00
|
|
|
controls->WarpCursor( controls->GetCursorPosition(), true );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
if( item )
|
|
|
|
{
|
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
|
|
|
|
2021-04-03 18:39:56 +00:00
|
|
|
m_selectionTool->AddItemToSel( item );
|
|
|
|
|
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();
|
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
|
|
|
{
|
2021-04-02 10:18:25 +00:00
|
|
|
item->SetPosition( (wxPoint) cursorPos );
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
if( m_inDrawShape )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
m_inDrawShape = true;
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
bool isTextBox = aEvent.IsAction( &EE_ACTIONS::drawTextBox );
|
2021-07-17 19:56:18 +00:00
|
|
|
SHAPE_T type = aEvent.Parameter<SHAPE_T>();
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
getViewControls()->ShowCursor( true );
|
|
|
|
|
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
SCH_SHAPE* item = nullptr;
|
|
|
|
|
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
|
|
|
};
|
|
|
|
|
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
m_view->ClearPreview();
|
|
|
|
delete item;
|
|
|
|
item = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Prime the pump
|
|
|
|
if( aEvent.HasPosition() )
|
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
|
|
|
|
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
|
|
|
{
|
|
|
|
setCursor();
|
|
|
|
|
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
|
|
|
{
|
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_frame->PopTool( tool );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
m_frame->PopTool( tool );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) && !item )
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
|
|
|
|
int lineWidth = Mils2iu( cfg->m_Drawing.default_line_thickness );
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
if( isTextBox )
|
|
|
|
item = new SCH_TEXTBOX( lineWidth, m_lastFillStyle );
|
|
|
|
else
|
|
|
|
item = new SCH_SHAPE( type, lineWidth, m_lastFillStyle );
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
item->SetFlags( IS_NEW );
|
|
|
|
item->BeginEdit( (wxPoint) cursorPos );
|
|
|
|
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( item->Clone() );
|
|
|
|
}
|
|
|
|
else if( item && ( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::finishDrawing ) ) )
|
|
|
|
{
|
|
|
|
if( evt->IsDblClick( BUT_LEFT ) || evt->IsAction( &EE_ACTIONS::finishDrawing )
|
|
|
|
|| !item->ContinueEdit( (wxPoint) cursorPos ) )
|
|
|
|
{
|
|
|
|
item->EndEdit();
|
|
|
|
item->ClearEditFlags();
|
|
|
|
item->SetFlags( IS_NEW );
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
if( isTextBox )
|
|
|
|
{
|
|
|
|
DIALOG_TEXT_PROPERTIES dlg( m_frame, item );
|
|
|
|
|
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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() ) )
|
|
|
|
{
|
|
|
|
item->CalcEdit( (wxPoint) cursorPos );
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( item->Clone() );
|
|
|
|
}
|
|
|
|
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 );
|
|
|
|
m_inDrawShape = false;
|
|
|
|
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
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
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();
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
getViewControls()->ShowCursor( true );
|
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2021-03-29 10:04:06 +00:00
|
|
|
// Prime the pump
|
|
|
|
if( aEvent.HasPosition() )
|
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
|
|
|
|
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
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
|
|
|
{
|
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
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
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
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
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
|
|
|
|
{
|
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-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
|
|
|
{
|
2020-04-12 23:09:17 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-10 16:48:46 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
sheet = new SCH_SHEET( m_frame->GetCurrentSheet().Last(), (VECTOR2I) cursorPos );
|
2021-05-30 21:04:07 +00:00
|
|
|
sheet->SetFlags( IS_NEW | IS_RESIZING );
|
2021-07-16 20:13:26 +00:00
|
|
|
sheet->SetScreen( nullptr );
|
2021-08-17 12:19:23 +00:00
|
|
|
sheet->SetBorderWidth( Mils2iu( 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 )
|
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
|
|
|
|
2021-05-21 17:24:38 +00:00
|
|
|
// Find the list of paths in the hierarchy that refer to the destination sheet where
|
|
|
|
// the new sheet will be drawn
|
|
|
|
SCH_SCREEN* currentScreen = m_frame->GetCurrentSheet().LastScreen();
|
|
|
|
SCH_SHEET_LIST hierarchy = m_frame->Schematic().GetSheets();
|
|
|
|
SCH_SHEET_LIST instances = hierarchy.FindAllSheetsForScreen( currentScreen );
|
|
|
|
instances.SortByPageNumbers();
|
|
|
|
|
|
|
|
int pageNum = static_cast<int>( hierarchy.size() ) + 1;
|
|
|
|
|
|
|
|
// Set a page number for all the instances of the new sheet in the hierarchy
|
|
|
|
for( SCH_SHEET_PATH& instance : instances )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH sheetPath = instance;
|
|
|
|
sheetPath.push_back( sheet );
|
2021-12-08 18:36:23 +00:00
|
|
|
sheet->AddInstance( sheetPath );
|
2021-12-06 12:47:18 +00:00
|
|
|
sheet->SetPageNumber( sheetPath, wxString::Format( "%d", pageNum++ ) );
|
2021-05-21 17:24:38 +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() );
|
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
|
|
|
|
|
|
|
size.x = std::max( size.x, MIN_SHEET_WIDTH );
|
|
|
|
size.y = std::max( size.y, MIN_SHEET_HEIGHT );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I grid = m_frame->GetNearestGridPosition( pos + size );
|
2019-04-30 20:01:17 +00:00
|
|
|
aSheet->Resize( wxSize( grid.x - pos.x, grid.y - pos.y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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() );
|
2021-02-21 15:44:38 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::SingleClickPlace, EE_ACTIONS::importSingleSheetPin.MakeEvent() );
|
2019-06-15 00:29:42 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeSchematicText.MakeEvent() );
|
2021-07-17 19:56:18 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawRectangle.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawCircle.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawArc.MakeEvent() );
|
2022-01-25 22:33:37 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawTextBox.MakeEvent() );
|
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
|
|
|
}
|