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
|
2020-04-16 16:43:50 +00:00
|
|
|
* Copyright (C) 2019-2020 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"
|
2019-06-27 21:33:48 +00:00
|
|
|
#include "ee_point_editor.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>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#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>
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <sch_bitmap.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2019-04-17 19:09:48 +00:00
|
|
|
#include <class_library.h>
|
2020-04-12 23:09:17 +00:00
|
|
|
#include <eeschema_settings.h>
|
2020-05-23 15:50:08 +00:00
|
|
|
#include <dialogs/dialog_edit_label.h>
|
2020-10-08 17:03:58 +00:00
|
|
|
#include <dialogs/dialog_edit_line_style.h>
|
|
|
|
#include <dialogs/dialog_junction_props.h>
|
2020-10-31 00:25:46 +00:00
|
|
|
#include <dialogs/dialog_sheet_pin_properties.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" ),
|
2020-10-31 00:25:46 +00:00
|
|
|
m_lastSheetPinType( PINSHEETLABEL_SHAPE::PS_INPUT ),
|
2020-05-23 15:50:08 +00:00
|
|
|
m_lastGlobalLabelShape( PINSHEETLABEL_SHAPE::PS_INPUT ),
|
|
|
|
m_lastTextOrientation( LABEL_SPIN_STYLE::LEFT ),
|
|
|
|
m_lastTextBold( false ),
|
|
|
|
m_lastTextItalic( 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
|
|
|
|
2019-04-17 19:09:48 +00:00
|
|
|
auto& 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2020-11-07 14:31:50 +00:00
|
|
|
SCH_COMPONENT* component = aEvent.Parameter<SCH_COMPONENT*>();
|
|
|
|
SCHLIB_FILTER filter;
|
|
|
|
std::vector<PICKED_SYMBOL>* historyList = nullptr;
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::placeSymbol ) )
|
2020-05-23 15:50:08 +00:00
|
|
|
historyList = &m_symbolHistoryList;
|
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;
|
2019-06-15 00:29:42 +00:00
|
|
|
filter.FilterPowerParts( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
wxFAIL_MSG( "PlaceCompontent(): unexpected request" );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
getViewControls()->ShowCursor( true );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-01 09:24:43 +00:00
|
|
|
// If a component was passed in get it ready for placement.
|
2019-06-15 00:29:42 +00:00
|
|
|
if( component )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-06-15 00:29:42 +00:00
|
|
|
component->SetFlags( IS_NEW | IS_MOVED );
|
2019-04-30 20:01:17 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-06-15 00:29:42 +00:00
|
|
|
m_selectionTool->AddItemToSel( component );
|
|
|
|
}
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2019-06-15 00:29:42 +00:00
|
|
|
Activate();
|
2019-05-01 09:24:43 +00:00
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
// Prime the pump
|
|
|
|
if( component )
|
2019-06-16 18:51:47 +00:00
|
|
|
{
|
|
|
|
getViewControls()->WarpCursor( getViewControls()->GetMousePosition( false ) );
|
2019-07-04 20:56:21 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
2019-06-16 18:51:47 +00:00
|
|
|
}
|
2019-06-19 15:11:41 +00:00
|
|
|
else if( aEvent.HasPosition() )
|
2019-06-15 00:29:42 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::cursorClick );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2020-10-08 16:57:24 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
2020-10-09 00:52:00 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( component ? KICURSOR::MOVING : KICURSOR::COMPONENT );
|
2020-10-08 02:47:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
2020-10-08 00:50:28 +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();
|
2019-06-15 00:29:42 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
auto cleanup = [&] () {
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
m_view->ClearPreview();
|
|
|
|
delete component;
|
|
|
|
component = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-06-15 00:29:42 +00:00
|
|
|
if( component )
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
|
|
|
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() )
|
|
|
|
{
|
|
|
|
if( component )
|
|
|
|
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-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
2019-06-15 00:29:42 +00:00
|
|
|
if( !component )
|
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
|
|
|
|
2019-04-17 19:09:48 +00:00
|
|
|
// Pick the module to be placed
|
2020-04-12 23:09:17 +00:00
|
|
|
bool footprintPreviews = m_frame->eeconfig()->m_Appearance.footprint_preview;
|
2020-11-07 14:31:50 +00:00
|
|
|
PICKED_SYMBOL sel = m_frame->PickSymbolFromLibTree( &filter, *historyList, true,
|
|
|
|
1, 1, footprintPreviews );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-01 09:24:43 +00:00
|
|
|
// Restore cursor after dialog
|
2019-06-13 13:34:38 +00:00
|
|
|
getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-01 09:24:43 +00:00
|
|
|
LIB_PART* part = sel.LibId.IsValid() ? m_frame->GetLibPart( sel.LibId ) : nullptr;
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
if( !part )
|
|
|
|
continue;
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
component = new SCH_COMPONENT(
|
|
|
|
*part, &m_frame->GetCurrentSheet(), sel, (wxPoint) cursorPos );
|
2020-05-19 17:24:57 +00:00
|
|
|
component->SetParent( m_frame->GetCurrentSheet().LastScreen() );
|
2019-06-15 00:29:42 +00:00
|
|
|
component->SetFlags( IS_NEW | IS_MOVED );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2020-04-12 23:09:17 +00:00
|
|
|
if( m_frame->eeconfig()->m_AutoplaceFields.enable )
|
2019-06-15 00:29:42 +00:00
|
|
|
component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
m_frame->SaveCopyForRepeatItem( component );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-04-30 20:01:17 +00:00
|
|
|
m_view->ClearPreview();
|
2019-06-15 00:29:42 +00:00
|
|
|
m_view->AddToPreview( component->Clone() );
|
|
|
|
m_selectionTool->AddItemToSel( component );
|
2020-10-08 02:47:01 +00:00
|
|
|
|
|
|
|
// Update cursor now that we have a component
|
|
|
|
setCursor();
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-29 05:06:39 +00:00
|
|
|
SCH_COMPONENT* next_comp = nullptr;
|
2019-05-01 20:15:51 +00:00
|
|
|
|
|
|
|
m_view->ClearPreview();
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), component, false );
|
2019-10-29 05:06:39 +00:00
|
|
|
|
2019-11-27 07:13:01 +00:00
|
|
|
EE_SELECTION new_sel;
|
|
|
|
new_sel.Add( component );
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::addNeededJunctions, true, &new_sel );
|
2019-11-26 21:03:19 +00:00
|
|
|
m_frame->OnModify();
|
|
|
|
|
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
|
|
|
{
|
|
|
|
int new_unit = component->GetUnit();
|
|
|
|
|
2020-04-12 23:09:17 +00:00
|
|
|
if( m_frame->eeconfig()->m_SymChooserPanel.place_all_units
|
2019-10-29 05:06:39 +00:00
|
|
|
&& component->GetUnit() < component->GetUnitCount() )
|
|
|
|
new_unit++;
|
|
|
|
else
|
|
|
|
new_unit = 1;
|
|
|
|
|
|
|
|
// We are either stepping to the next unit or next component
|
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
|
|
|
{
|
2020-04-06 11:00:58 +00:00
|
|
|
// Deselect the last placed symbol: obviously we do not want to
|
|
|
|
// apply some changes (like rotation, mirror...) to previously placed
|
|
|
|
// symbols.
|
|
|
|
m_selectionTool->ClearSelection();
|
|
|
|
|
2019-10-29 05:06:39 +00:00
|
|
|
next_comp = static_cast<SCH_COMPONENT*>( component->Duplicate() );
|
|
|
|
next_comp->SetFlags( IS_NEW | IS_MOVED );
|
|
|
|
next_comp->SetUnit( new_unit );
|
2020-05-13 02:00:37 +00:00
|
|
|
next_comp->SetUnitSelection( &m_frame->GetCurrentSheet(), new_unit );
|
2019-10-29 05:06:39 +00:00
|
|
|
|
2020-04-12 23:09:17 +00:00
|
|
|
if( m_frame->eeconfig()->m_AutoplaceFields.enable )
|
2019-10-29 05:06:39 +00:00
|
|
|
component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
|
|
|
|
|
|
|
|
m_frame->SaveCopyForRepeatItem( next_comp );
|
|
|
|
m_view->AddToPreview( next_comp->Clone() );
|
|
|
|
m_selectionTool->AddItemToSel( next_comp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
component = next_comp;
|
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...
|
2019-06-15 00:29:42 +00:00
|
|
|
if( !component )
|
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
|
|
|
|
&& evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_CMP_MAX )
|
|
|
|
{
|
2019-05-02 20:44:23 +00:00
|
|
|
int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP;
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
if( component )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2019-06-15 00:29:42 +00:00
|
|
|
m_frame->SelectUnit( component, unit );
|
2019-07-04 20:56:21 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-04 20:56:21 +00:00
|
|
|
else if( component && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-06-15 00:29:42 +00:00
|
|
|
component->SetPosition( (wxPoint)cursorPos );
|
2019-04-17 19:09:48 +00:00
|
|
|
m_view->ClearPreview();
|
2019-06-15 00:29:42 +00:00
|
|
|
m_view->AddToPreview( component->Clone() );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is a module to be placed
|
2019-06-18 17:56:40 +00:00
|
|
|
getViewControls()->SetAutoPan( component != nullptr );
|
|
|
|
getViewControls()->CaptureCursor( component != nullptr );
|
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
|
|
|
|
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-04-26 22:23:12 +00:00
|
|
|
|
|
|
|
// Add all the drawable parts to preview
|
|
|
|
if( image )
|
|
|
|
{
|
|
|
|
image->SetPosition( (wxPoint)cursorPos );
|
|
|
|
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 );
|
2019-06-15 00:29:42 +00:00
|
|
|
Activate();
|
|
|
|
|
|
|
|
// Prime the pump
|
|
|
|
if( image )
|
2019-07-04 20:56:21 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
2019-06-19 15:11:41 +00:00
|
|
|
else if( aEvent.HasPosition() )
|
2019-06-15 00:29:42 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
|
|
|
|
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 );
|
|
|
|
};
|
|
|
|
|
2020-10-08 00:50:28 +00:00
|
|
|
// Set initial cursor
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2020-10-08 00:50:28 +00:00
|
|
|
|
2019-04-26 22:23:12 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-26 22:23:12 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2019-05-12 11:49:58 +00:00
|
|
|
cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
auto cleanup = [&] () {
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
m_view->ClearPreview();
|
|
|
|
delete image;
|
|
|
|
image = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
2019-04-26 22:23:12 +00:00
|
|
|
{
|
|
|
|
if( image )
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
|
|
|
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() )
|
|
|
|
{
|
|
|
|
if( image )
|
|
|
|
cleanup();
|
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
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
if( !image )
|
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-10 16:48:46 +00:00
|
|
|
wxFileDialog dlg( m_frame, _( "Choose Image" ), wxEmptyString, wxEmptyString,
|
2020-10-20 19:05:04 +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;
|
|
|
|
|
|
|
|
// Restore cursor after dialog
|
2019-06-13 13:34:38 +00:00
|
|
|
getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
|
|
|
wxString fullFilename = dlg.GetPath();
|
|
|
|
|
2019-05-01 20:15:51 +00:00
|
|
|
if( wxFileExists( fullFilename ) )
|
|
|
|
image = new SCH_BITMAP( (wxPoint)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
|
|
|
{
|
|
|
|
wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename );
|
|
|
|
delete image;
|
2019-05-01 20:15:51 +00:00
|
|
|
image = nullptr;
|
2019-04-26 22:23:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-05-03 08:48:53 +00:00
|
|
|
image->SetFlags( IS_NEW | IS_MOVED );
|
|
|
|
|
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
|
|
|
{
|
|
|
|
image->SetPosition( (wxPoint)cursorPos );
|
|
|
|
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
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
2019-04-26 22:23:12 +00:00
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is a module 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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2019-06-28 18:32:18 +00:00
|
|
|
wxPoint cursorPos;
|
|
|
|
KICAD_T type = aEvent.Parameter<KICAD_T>();
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-06-28 18:32:18 +00:00
|
|
|
if( type == SCH_JUNCTION_T && aEvent.HasPosition() )
|
|
|
|
{
|
|
|
|
EE_SELECTION& selection = m_selectionTool->GetSelection();
|
|
|
|
SCH_LINE* wire = dynamic_cast<SCH_LINE*>( selection.Front() );
|
|
|
|
|
|
|
|
if( wire )
|
|
|
|
{
|
|
|
|
SEG seg( wire->GetStartPoint(), wire->GetEndPoint() );
|
|
|
|
VECTOR2I nearest = seg.NearestPoint( getViewControls()->GetCursorPosition() );
|
|
|
|
getViewControls()->SetCrossHairCursorPosition( nearest, false );
|
|
|
|
getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
|
2019-06-15 00:29:42 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-28 18:32:18 +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-04-17 19:09:48 +00:00
|
|
|
|
2019-11-23 23:34:35 +00:00
|
|
|
SCH_ITEM* previewItem;
|
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
case SCH_NO_CONNECT_T:
|
|
|
|
previewItem = new SCH_NO_CONNECT( cursorPos );
|
|
|
|
break;
|
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
previewItem = new SCH_JUNCTION( cursorPos );
|
|
|
|
break;
|
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
2020-06-30 01:08:33 +00:00
|
|
|
previewItem = new SCH_BUS_WIRE_ENTRY( cursorPos );
|
2019-11-23 23:34:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wxASSERT_MSG( false, "Unknown item type in SCH_DRAWING_TOOLS::SingleClickPlace" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-20 03:34:55 +00:00
|
|
|
previewItem->SetParent( m_frame->GetScreen() );
|
|
|
|
|
2019-06-28 18:32:18 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( previewItem->Clone() );
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2019-04-17 19:09:48 +00:00
|
|
|
Activate();
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
// Prime the pump
|
2019-06-19 15:11:41 +00:00
|
|
|
if( aEvent.HasPosition() )
|
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
|
|
|
|
2020-10-08 16:57:24 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
2020-10-08 02:47:01 +00:00
|
|
|
{
|
2020-10-11 03:45:21 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PLACE );
|
2020-10-08 02:47:01 +00:00
|
|
|
};
|
|
|
|
|
2020-10-08 00:50:28 +00:00
|
|
|
// Set initial cursor
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2020-10-08 00:50:28 +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();
|
2019-05-12 11:49:58 +00:00
|
|
|
cursorPos = (wxPoint) getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
|
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
|
|
|
{
|
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 );
|
|
|
|
m_frame->SaveCopyForRepeatItem( newItem );
|
2019-04-29 17:50:46 +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
|
|
|
|
|
|
|
if( evt->IsDblClick( BUT_LEFT ) ) // Finish tool.
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::mirrorX )
|
2020-06-30 01:08:33 +00:00
|
|
|
|| evt->IsAction( &EE_ACTIONS::mirrorY ) ) )
|
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
|
|
|
}
|
2019-11-23 23:34:35 +00:00
|
|
|
else if( evt->IsAction( &EE_ACTIONS::mirrorX ) )
|
2020-10-08 16:57:24 +00:00
|
|
|
{
|
2019-11-23 23:34:35 +00:00
|
|
|
busItem->MirrorX( busItem->GetPosition().x );
|
2020-10-08 16:57:24 +00:00
|
|
|
}
|
2019-11-23 23:34:35 +00:00
|
|
|
else if( evt->IsAction( &EE_ACTIONS::mirrorY ) )
|
2020-10-08 16:57:24 +00:00
|
|
|
{
|
2019-11-23 23:34:35 +00:00
|
|
|
busItem->MirrorY( 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 );
|
|
|
|
|
|
|
|
DIALOG_EDIT_LINE_STYLE dlg( m_frame, strokeItems );
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
switch( aType )
|
|
|
|
{
|
|
|
|
case LAYER_NOTES:
|
|
|
|
textItem = new SCH_TEXT( (wxPoint) aPosition );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_LOCLABEL:
|
|
|
|
textItem = new SCH_LABEL( (wxPoint) aPosition );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_HIERLABEL:
|
|
|
|
textItem = new SCH_HIERLABEL( (wxPoint) aPosition );
|
|
|
|
textItem->SetShape( m_lastGlobalLabelShape );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_GLOBLABEL:
|
|
|
|
textItem = new SCH_GLOBALLABEL( (wxPoint) aPosition );
|
|
|
|
textItem->SetShape( m_lastGlobalLabelShape );
|
|
|
|
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 );
|
|
|
|
textItem->SetItalic( m_lastTextItalic );
|
|
|
|
textItem->SetLabelSpinStyle( m_lastTextOrientation );
|
|
|
|
textItem->SetTextSize( wxSize( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
|
|
|
|
textItem->SetFlags( IS_NEW | IS_MOVED );
|
|
|
|
|
|
|
|
DIALOG_LABEL_EDITOR dlg( m_frame, textItem );
|
|
|
|
|
2020-10-20 19:54:28 +00:00
|
|
|
// Must be quasi modal for syntax help
|
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK || textItem->GetText().IsEmpty() )
|
2020-05-23 15:50:08 +00:00
|
|
|
{
|
|
|
|
delete textItem;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lastTextBold = textItem->IsBold();
|
|
|
|
m_lastTextItalic = textItem->IsItalic();
|
|
|
|
m_lastTextOrientation = textItem->GetLabelSpinStyle();
|
|
|
|
|
|
|
|
if( textItem->Type() == SCH_GLOBAL_LABEL_T || textItem->Type() == SCH_HIER_LABEL_T )
|
|
|
|
m_lastGlobalLabelShape = textItem->GetShape();
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), text );
|
|
|
|
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 );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK || sheetPin->GetText().IsEmpty() )
|
|
|
|
{
|
|
|
|
delete sheetPin;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lastSheetPinType = sheetPin->GetShape();
|
|
|
|
|
|
|
|
sheetPin->SetPosition( (wxPoint) getViewControls()->GetCursorPosition() );
|
|
|
|
|
|
|
|
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-10-09 00:40:03 +00:00
|
|
|
EDA_ITEM* item = nullptr;
|
|
|
|
bool isImportMode = aEvent.IsAction( &EE_ACTIONS::importSheetPin );
|
|
|
|
bool isText = aEvent.IsAction( &EE_ACTIONS::placeSchematicText );
|
|
|
|
bool isGlobalLabel = aEvent.IsAction( &EE_ACTIONS::placeGlobalLabel );
|
2020-10-10 22:25:28 +00:00
|
|
|
bool isHierLabel = aEvent.IsAction( &EE_ACTIONS::placeHierLabel );
|
2020-10-09 00:40:03 +00:00
|
|
|
bool isNetLabel = aEvent.IsAction( &EE_ACTIONS::placeLabel );
|
|
|
|
KICAD_T type = aEvent.Parameter<KICAD_T>();
|
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-12 11:49:58 +00:00
|
|
|
getViewControls()->ShowCursor( 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 );
|
2019-04-17 19:09:48 +00:00
|
|
|
Activate();
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
// Prime the pump
|
2019-06-19 15:11:41 +00:00
|
|
|
if( aEvent.HasPosition() )
|
2019-06-15 00:29:42 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
|
|
|
|
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 );
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2020-10-08 00:50:28 +00:00
|
|
|
// Set initial cursor
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2020-10-08 00:50:28 +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();
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
auto cleanup = [&] () {
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
m_view->ClearPreview();
|
|
|
|
delete item;
|
|
|
|
item = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
|
|
|
if( item )
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
|
|
|
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() )
|
|
|
|
{
|
|
|
|
if( item )
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
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-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
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
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
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
switch( type )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-04-18 15:45:10 +00:00
|
|
|
case SCH_LABEL_T:
|
2020-05-23 15:50:08 +00:00
|
|
|
item = createNewText( cursorPos, LAYER_LOCLABEL );
|
2019-04-18 15:45:10 +00:00
|
|
|
break;
|
|
|
|
case SCH_HIER_LABEL_T:
|
2020-05-23 15:50:08 +00:00
|
|
|
item = createNewText( cursorPos, LAYER_HIERLABEL );
|
2019-04-18 15:45:10 +00:00
|
|
|
break;
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
2020-05-23 15:50:08 +00:00
|
|
|
item = createNewText( cursorPos, LAYER_GLOBLABEL );
|
2019-04-18 15:45:10 +00:00
|
|
|
break;
|
|
|
|
case SCH_TEXT_T:
|
2020-05-23 15:50:08 +00:00
|
|
|
item = createNewText( cursorPos, LAYER_NOTES );
|
2019-04-18 15:45:10 +00:00
|
|
|
break;
|
|
|
|
case SCH_SHEET_PIN_T:
|
2019-05-16 21:58:47 +00:00
|
|
|
{
|
|
|
|
SCH_HIERLABEL* label = nullptr;
|
2020-05-27 15:18:12 +00:00
|
|
|
SCH_SHEET* sheet = nullptr;
|
|
|
|
|
|
|
|
if( m_selectionTool->SelectPoint( cursorPos, EE_COLLECTOR::SheetsOnly, &item ) )
|
|
|
|
sheet = dynamic_cast<SCH_SHEET*>( item );
|
|
|
|
|
|
|
|
item = nullptr;
|
|
|
|
|
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 );
|
2019-05-16 21:58:47 +00:00
|
|
|
break;
|
2019-05-16 21:27:03 +00:00
|
|
|
}
|
2019-05-16 21:58:47 +00:00
|
|
|
|
2020-10-09 00:40:03 +00:00
|
|
|
if( isImportMode )
|
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 );
|
2019-05-16 21:58:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-31 00:25:46 +00:00
|
|
|
item = createSheetPin( sheet, label );
|
2019-04-18 15:45:10 +00:00
|
|
|
break;
|
2019-05-16 21:58:47 +00:00
|
|
|
}
|
2019-06-15 19:31:20 +00:00
|
|
|
default:
|
|
|
|
break;
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Restore cursor after dialog
|
2019-06-13 13:34:38 +00:00
|
|
|
getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
if( item )
|
|
|
|
{
|
2019-05-01 20:15:51 +00:00
|
|
|
item->SetFlags( IS_NEW | IS_MOVED );
|
2019-04-17 19:09:48 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( item->Clone() );
|
2019-05-01 20:15:51 +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
|
|
|
}
|
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
getViewControls()->SetCursorPosition( cursorPos, false );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
2019-04-29 17:50:46 +00:00
|
|
|
|
|
|
|
// ... and second click places:
|
2019-04-17 19:09:48 +00:00
|
|
|
else
|
|
|
|
{
|
2019-05-24 01:51:07 +00:00
|
|
|
item->ClearFlags( IS_MOVED );
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), (SCH_ITEM*) 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();
|
2019-04-29 17:50:46 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( item->Clone() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
item = nullptr;
|
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
|
|
|
{
|
2019-06-18 21:34:31 +00:00
|
|
|
static_cast<SCH_ITEM*>( item )->SetPosition( (wxPoint) cursorPos );
|
2019-04-17 19:09:48 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( item->Clone() );
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is a module to be placed
|
2019-06-17 13:43:22 +00:00
|
|
|
getViewControls()->SetAutoPan( item != nullptr );
|
|
|
|
getViewControls()->CaptureCursor( item != nullptr );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
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-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
|
|
|
Activate();
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
// Prime the pump
|
2019-06-19 15:11:41 +00:00
|
|
|
if( aEvent.HasPosition() )
|
2019-06-15 00:29:42 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
|
|
|
|
2020-10-08 16:57:24 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
2020-10-08 00:50:28 +00:00
|
|
|
|
2019-04-18 15:45:10 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-18 15:45:10 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2019-06-27 21:33:48 +00:00
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
|
2019-04-18 15:45:10 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
auto cleanup = [&] () {
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-03 08:48:53 +00:00
|
|
|
m_view->ClearPreview();
|
2019-07-01 21:01:33 +00:00
|
|
|
delete sheet;
|
|
|
|
sheet = nullptr;
|
|
|
|
};
|
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 )
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
|
|
|
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() )
|
|
|
|
{
|
|
|
|
if( sheet )
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2019-05-07 23:51:37 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) && !sheet )
|
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
|
|
|
|
2020-06-02 19:27:39 +00:00
|
|
|
sheet = new SCH_SHEET( m_frame->GetCurrentSheet().Last(),
|
|
|
|
static_cast<wxPoint>( cursorPos ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
sheet->SetFlags( IS_NEW | IS_RESIZED );
|
|
|
|
sheet->SetScreen( NULL );
|
2020-05-23 15:50:08 +00:00
|
|
|
sheet->SetBorderWidth( 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" );
|
|
|
|
sheet->GetFields()[ SHEETFILENAME ].SetText( "untitled.kicad_sch" );
|
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-04-19 00:00:54 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
else if( sheet && ( evt->IsClick( 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
|
|
|
|
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
|
|
|
{
|
2020-03-06 12:05:21 +00:00
|
|
|
sheet->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
|
|
|
|
|
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-05-07 23:51:37 +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
|
|
|
}
|
2019-05-07 23:51:37 +00:00
|
|
|
|
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
|
|
|
|
evt->SetPassEvent();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
void SCH_DRAWING_TOOLS::sizeSheet( SCH_SHEET* aSheet, VECTOR2I aPos )
|
2019-04-30 20:01:17 +00:00
|
|
|
{
|
|
|
|
wxPoint pos = aSheet->GetPosition();
|
|
|
|
wxPoint size = (wxPoint) aPos - pos;
|
|
|
|
|
|
|
|
size.x = std::max( size.x, MIN_SHEET_WIDTH );
|
|
|
|
size.y = std::max( size.y, MIN_SHEET_HEIGHT );
|
|
|
|
|
|
|
|
wxPoint grid = m_frame->GetNearestGridPosition( pos + size );
|
|
|
|
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
|
|
|
{
|
2019-06-15 00:29:42 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceComponent, EE_ACTIONS::placeSymbol.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceComponent, EE_ACTIONS::placePower.MakeEvent() );
|
|
|
|
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() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeHierLabel.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeGlobalLabel.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::DrawSheet, EE_ACTIONS::drawSheet.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::importSheetPin.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeSchematicText.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceImage, EE_ACTIONS::placeImage.MakeEvent() );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|