2019-04-17 19:09:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
#include <ee_actions.h>
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <sch_view.h>
|
|
|
|
#include <class_draw_panel_gal.h>
|
|
|
|
#include <project.h>
|
|
|
|
#include <id.h>
|
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <view/view_group.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <view/view.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <ee_hotkeys.h>
|
2019-04-17 19:09:48 +00:00
|
|
|
#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>
|
|
|
|
#include <class_library.h>
|
|
|
|
|
|
|
|
|
|
|
|
// Drawing tool actions
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::placeSymbol( "eeschema.InteractiveDrawing.placeSymbol",
|
2019-04-17 19:09:48 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_NEW_COMPONENT ),
|
2019-04-29 10:41:27 +00:00
|
|
|
_( "Add Symbol" ), _( "Add a symbol" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
add_component_xpm, AF_ACTIVATE );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::placePower( "eeschema.InteractiveDrawing.placePowerPort",
|
2019-04-17 19:09:48 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_NEW_POWER ),
|
2019-04-29 10:41:27 +00:00
|
|
|
_( "Add Power" ), _( "Add a power port" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
add_power_xpm, AF_ACTIVATE );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::placeNoConnect( "eeschema.InteractiveDrawing.placeNoConnect",
|
2019-04-17 19:09:48 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_NOCONN_FLAG ),
|
2019-04-29 10:41:27 +00:00
|
|
|
_( "Add No Connect Flag" ), _( "Add a no-connection flag" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
noconn_xpm, AF_ACTIVATE );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::placeJunction( "eeschema.InteractiveDrawing.placeJunction",
|
2019-04-17 19:09:48 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_JUNCTION ),
|
2019-04-29 10:41:27 +00:00
|
|
|
_( "Add Junction" ), _( "Add a junction" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
add_junction_xpm, AF_ACTIVATE );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::placeBusWireEntry( "eeschema.InteractiveDrawing.placeBusWireEntry",
|
2019-04-17 19:09:48 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_WIRE_ENTRY ),
|
2019-04-29 10:41:27 +00:00
|
|
|
_( "Add Wire to Bus Entry" ), _( "Add a wire entry to a bus" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
add_line2bus_xpm, AF_ACTIVATE );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::placeBusBusEntry( "eeschema.InteractiveDrawing.placeBusBusEntry",
|
2019-04-17 19:09:48 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_BUS_ENTRY ),
|
2019-04-29 10:41:27 +00:00
|
|
|
_( "Add Bus to Bus Entry" ), _( "Add a bus entry to a bus" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
add_bus2bus_xpm, AF_ACTIVATE );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::placeLabel( "eeschema.InteractiveDrawing.placeLabel",
|
2019-04-17 19:09:48 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_LABEL ),
|
2019-04-29 10:41:27 +00:00
|
|
|
_( "Add Label" ), _( "Add a net label" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
add_line_label_xpm, AF_ACTIVATE );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::placeHierarchicalLabel( "eeschema.InteractiveDrawing.placeHierarchicalLabel",
|
2019-04-17 19:09:48 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_HLABEL ),
|
2019-04-29 10:41:27 +00:00
|
|
|
_( "Add Hierarchical Label" ), _( "Add a hierarchical sheet label" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
add_hierarchical_label_xpm, AF_ACTIVATE );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::drawSheet( "eeschema.InteractiveDrawing.drawSheet",
|
2019-04-18 15:45:10 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_HIER_SHEET ),
|
2019-04-29 10:41:27 +00:00
|
|
|
_( "Add Sheet" ), _( "Add a hierarchical sheet" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
add_hierarchical_subsheet_xpm, AF_ACTIVATE );
|
2019-04-18 15:45:10 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::placeSheetPin( "eeschema.InteractiveDrawing.placeSheetPin",
|
2019-04-29 10:41:27 +00:00
|
|
|
AS_GLOBAL, 0, _( "Add Sheet Pin" ), _( "Add a sheet pin" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
add_hierar_pin_xpm, AF_ACTIVATE );
|
2019-04-18 15:45:10 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::importSheetPin( "eeschema.InteractiveDrawing.importSheetPin",
|
2019-04-29 10:41:27 +00:00
|
|
|
AS_GLOBAL, 0, _( "Import Sheet Pin" ), _( "Import a hierarchical sheet pin" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
import_hierarchical_label_xpm, AF_ACTIVATE );
|
2019-04-18 15:45:10 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::placeGlobalLabel( "eeschema.InteractiveDrawing.placeGlobalLabel",
|
2019-04-17 19:09:48 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_GLABEL ),
|
2019-04-29 10:41:27 +00:00
|
|
|
_( "Add Global Label" ), _( "Add a global label" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
add_glabel_xpm, AF_ACTIVATE );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::placeSchematicText( "eeschema.InteractiveDrawing.placeSchematicText",
|
2019-04-17 19:09:48 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_GRAPHIC_TEXT ),
|
2019-04-29 10:41:27 +00:00
|
|
|
_( "Add Text" ), _( "Add text" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
text_xpm, AF_ACTIVATE );
|
2019-04-29 10:41:27 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::placeImage( "eeschema.InteractiveDrawing.placeImage",
|
2019-04-29 10:41:27 +00:00
|
|
|
AS_GLOBAL, 0, _( "Add Image" ), _( "Add bitmap image" ),
|
2019-04-30 20:01:17 +00:00
|
|
|
image_xpm, AF_ACTIVATE );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::finishSheet( "eeschema.InteractiveDrawing.finishSheet",
|
2019-04-29 10:41:27 +00:00
|
|
|
AS_GLOBAL, 0, _( "Finish Sheet" ), _( "Finish drawing sheet" ),
|
|
|
|
checked_ok_xpm, AF_NONE );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::addJunction( "eeschema.InteractiveEditing.addJunction",
|
2019-04-29 10:41:27 +00:00
|
|
|
AS_GLOBAL, 0, _( "Add Junction" ), _( "Add a wire or bus junction" ),
|
|
|
|
add_junction_xpm, AF_NONE );
|
2019-04-18 23:42:50 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::addLabel( "eeschema.InteractiveEditing.addLabel",
|
2019-04-29 10:41:27 +00:00
|
|
|
AS_GLOBAL, 0, _( "Add Label" ), _( "Add a label to a wire or bus" ),
|
|
|
|
add_line_label_xpm, AF_NONE );
|
2019-04-18 23:42:50 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::addGlobalLabel( "eeschema.InteractiveEditing.addGlobalLabel",
|
2019-04-29 10:41:27 +00:00
|
|
|
AS_GLOBAL, 0, _( "Add Global Label" ), _( "Add a global label to a wire or bus" ),
|
|
|
|
add_glabel_xpm, AF_NONE );
|
2019-04-18 23:42:50 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::addHierLabel( "eeschema.InteractiveEditing.addHierLabel",
|
2019-05-01 13:24:51 +00:00
|
|
|
AS_GLOBAL, 0, _( "Add Hierarchical Label" ), _( "Add a hierarchical label to a wire or bus" ),
|
|
|
|
add_hierarchical_label_xpm, AF_NONE );
|
|
|
|
|
2019-05-17 15:16:13 +00:00
|
|
|
TOOL_ACTION EE_ACTIONS::addSheetPin( "eeschema.InteractiveEditing.addSheetPin",
|
|
|
|
AS_GLOBAL, 0, _( "Add Sheet Pin" ), _( "Add a sheet pin to the selected sheet" ),
|
|
|
|
add_hierarchical_label_xpm, AF_NONE );
|
|
|
|
|
|
|
|
TOOL_ACTION EE_ACTIONS::addImportedSheetPin( "eeschema.InteractiveEditing.addImportedSheetPin",
|
|
|
|
AS_GLOBAL, 0, _( "Add Imported Sheet Pin" ), _( "Add an imported sheet pin" ),
|
|
|
|
add_hierarchical_label_xpm, AF_NONE );
|
|
|
|
|
2019-04-18 23:42:50 +00:00
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
SCH_DRAWING_TOOLS::SCH_DRAWING_TOOLS() :
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveDrawing" )
|
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
|
|
|
SCH_DRAWING_TOOLS::~SCH_DRAWING_TOOLS()
|
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
|
|
|
|
2019-05-03 22:48:24 +00:00
|
|
|
auto belowRootSheetCondition = [] ( const SELECTION& aSel ) {
|
|
|
|
return g_CurrentSheet->Last() != g_RootSheet;
|
2019-04-29 10:41:27 +00:00
|
|
|
};
|
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-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::AddJunction( const TOOL_EVENT& aEvent )
|
2019-04-18 23:42:50 +00:00
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->GetSelection();
|
|
|
|
SCH_LINE* wire = dynamic_cast<SCH_LINE*>( selection.Front() );
|
2019-05-17 15:16:13 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-04-18 23:42:50 +00:00
|
|
|
|
2019-05-17 15:16:13 +00:00
|
|
|
if( wire )
|
|
|
|
{
|
|
|
|
SEG seg( wire->GetStartPoint(), wire->GetEndPoint() );
|
|
|
|
VECTOR2I nearest = seg.NearestPoint( m_frame->GetCrossHairPosition() );
|
|
|
|
m_frame->SetCrossHairPosition( (wxPoint) nearest, false );
|
|
|
|
}
|
|
|
|
|
2019-05-30 12:25:08 +00:00
|
|
|
getViewControls()->WarpCursor( m_frame->GetCrossHairPosition(), true );
|
2019-05-17 15:16:13 +00:00
|
|
|
SCH_JUNCTION* junction = m_frame->AddJunction( m_frame->GetCrossHairPosition() );
|
|
|
|
m_selectionTool->AddItemToSel( junction );
|
2019-04-18 23:42:50 +00:00
|
|
|
|
2019-05-02 10:59:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-04-18 23:42:50 +00:00
|
|
|
|
2019-05-01 13:24:51 +00:00
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::AddLabel( const TOOL_EVENT& aEvent )
|
2019-05-02 10:59:36 +00:00
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-02 10:59:36 +00:00
|
|
|
|
|
|
|
int layer = LAYER_NOTES;
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::addLabel ) )
|
2019-05-02 10:59:36 +00:00
|
|
|
layer = LAYER_LOCLABEL;
|
2019-05-10 17:19:48 +00:00
|
|
|
else if( aEvent.IsAction( &EE_ACTIONS::addGlobalLabel ) )
|
2019-05-02 10:59:36 +00:00
|
|
|
layer = LAYER_GLOBLABEL;
|
2019-05-10 17:19:48 +00:00
|
|
|
else if( aEvent.IsAction( &EE_ACTIONS::addHierLabel ) )
|
2019-05-02 10:59:36 +00:00
|
|
|
layer = LAYER_HIERLABEL;
|
|
|
|
|
|
|
|
SCH_ITEM* item = m_frame->CreateNewText( layer );
|
|
|
|
m_frame->AddItemToScreenAndUndoList( item );
|
2019-05-17 15:16:13 +00:00
|
|
|
m_selectionTool->AddItemToSel( item );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_DRAWING_TOOLS::AddSheetPin( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->GetSelection();
|
2019-05-17 15:16:13 +00:00
|
|
|
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( selection.Front() );
|
|
|
|
SCH_HIERLABEL* label = nullptr;
|
|
|
|
|
|
|
|
if( !sheet )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
|
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::addImportedSheetPin ) )
|
|
|
|
{
|
|
|
|
label = m_frame->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 ) );
|
2019-05-19 21:04:04 +00:00
|
|
|
m_statusPopup->PopupFor( 2000 );
|
2019-05-17 15:16:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_SHEET_PIN* pin = m_frame->CreateSheetPin( sheet, label );
|
|
|
|
m_frame->AddItemToScreenAndUndoList( pin );
|
|
|
|
m_selectionTool->AddItemToSel( pin );
|
2019-04-18 23:42:50 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-17 19:09:48 +00:00
|
|
|
// History lists for PlaceSymbol()
|
|
|
|
static SCH_BASE_FRAME::HISTORY_LIST s_SymbolHistoryList;
|
|
|
|
static SCH_BASE_FRAME::HISTORY_LIST s_PowerHistoryList;
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = aEvent.Parameter<SCH_COMPONENT*>();
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_PLACE_SYMBOL_TOOL, wxCURSOR_PENCIL, _( "Add Symbol" ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
return doPlaceComponent( component, nullptr, s_SymbolHistoryList );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlacePower( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = aEvent.Parameter<SCH_COMPONENT*>();
|
|
|
|
SCHLIB_FILTER filter;
|
|
|
|
|
|
|
|
filter.FilterPowerParts( true );
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_PLACE_POWER_TOOL, wxCURSOR_PENCIL, _( "Add Power" ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
return doPlaceComponent( component, &filter, s_PowerHistoryList );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::doPlaceComponent( SCH_COMPONENT* aComponent, SCHLIB_FILTER* aFilter,
|
2019-05-31 22:17:54 +00:00
|
|
|
SCH_BASE_FRAME::HISTORY_LIST& aHistoryList )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
|
|
|
|
getViewControls()->ShowCursor( true );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
2019-05-01 09:24:43 +00:00
|
|
|
// If a component was passed in get it ready for placement.
|
2019-04-17 19:09:48 +00:00
|
|
|
if( aComponent )
|
|
|
|
{
|
2019-05-01 09:24:43 +00:00
|
|
|
aComponent->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-05-01 21:50:11 +00:00
|
|
|
m_selectionTool->AddItemToSel( aComponent );
|
2019-05-01 09:24:43 +00:00
|
|
|
|
|
|
|
// Queue up a refresh event so we don't have to wait for the next mouse-moved event
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::refreshPreview );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-04-29 17:50:46 +00:00
|
|
|
if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
|
|
|
if( aComponent )
|
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-04-17 19:09:48 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
delete aComponent;
|
|
|
|
aComponent = nullptr;
|
2019-05-03 08:48:53 +00:00
|
|
|
|
|
|
|
if( !evt->IsActivate() )
|
|
|
|
continue;
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 08:48:53 +00:00
|
|
|
break;
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
if( !aComponent )
|
|
|
|
{
|
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
|
2019-05-01 09:24:43 +00:00
|
|
|
auto sel = m_frame->SelectCompFromLibTree( aFilter, aHistoryList, true, 1, 1,
|
|
|
|
m_frame->GetShowFootprintPreviews());
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-05-01 09:24:43 +00:00
|
|
|
// Restore cursor after dialog
|
2019-05-30 12:25:08 +00:00
|
|
|
getViewControls()->WarpCursor( m_frame->GetCrossHairPosition(), 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;
|
|
|
|
|
2019-05-01 09:24:43 +00:00
|
|
|
aComponent = new SCH_COMPONENT( *part, g_CurrentSheet, sel, (wxPoint) cursorPos );
|
2019-05-03 08:48:53 +00:00
|
|
|
aComponent->SetFlags( IS_NEW | IS_MOVED );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
// Be sure the link to the corresponding LIB_PART is OK:
|
|
|
|
aComponent->Resolve( *m_frame->Prj().SchSymbolLibTable() );
|
|
|
|
|
|
|
|
if( m_frame->GetAutoplaceFields() )
|
|
|
|
aComponent->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
|
|
|
|
|
2019-05-10 16:48:46 +00:00
|
|
|
m_frame->SaveCopyForRepeatItem( aComponent );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-04-30 20:01:17 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( aComponent->Clone() );
|
2019-05-01 20:15:51 +00:00
|
|
|
m_selectionTool->AddItemToSel( aComponent );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-01 13:24:51 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( aComponent );
|
2019-04-17 19:09:48 +00:00
|
|
|
aComponent = nullptr;
|
2019-05-01 20:15:51 +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( !aComponent )
|
|
|
|
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-05-02 20:03:03 +00:00
|
|
|
else if( evt->Category() == TC_COMMAND && evt->Action() == TA_CONTEXT_MENU_CHOICE )
|
|
|
|
{
|
|
|
|
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-05-02 20:03:03 +00:00
|
|
|
if( aComponent )
|
|
|
|
{
|
2019-05-02 20:44:23 +00:00
|
|
|
m_frame->SelectUnit( aComponent, unit );
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::refreshPreview );
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-10 17:19:48 +00:00
|
|
|
else if( aComponent && ( evt->IsAction( &EE_ACTIONS::refreshPreview )
|
2019-05-07 23:51:37 +00:00
|
|
|
|| evt->IsMotion() ) )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
|
|
|
aComponent->SetPosition( (wxPoint)cursorPos );
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( aComponent->Clone() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is a module to be placed
|
2019-05-12 11:49:58 +00:00
|
|
|
getViewControls()->SetAutoPan( !!aComponent );
|
|
|
|
getViewControls()->CaptureCursor( !!aComponent );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->SetNoToolSelected();
|
|
|
|
|
|
|
|
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-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_PLACE_IMAGE_TOOL, wxCURSOR_PENCIL, _( "Add image" ) );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2019-05-12 11:49:58 +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
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
// Add all the drawable parts to preview
|
|
|
|
if( image )
|
|
|
|
{
|
|
|
|
image->SetPosition( (wxPoint)cursorPos );
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->AddToPreview( image->Clone() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
|
2019-04-26 22:23:12 +00:00
|
|
|
|
2019-04-29 17:50:46 +00:00
|
|
|
if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) )
|
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 );
|
2019-04-26 22:23:12 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
delete image;
|
|
|
|
image = nullptr;
|
2019-05-03 08:48:53 +00:00
|
|
|
|
|
|
|
if( !evt->IsActivate() )
|
|
|
|
continue;
|
2019-04-26 22:23:12 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 08:48:53 +00:00
|
|
|
break;
|
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,
|
|
|
|
_( "Image Files " ) + wxImage::GetImageExtWildcard(), wxFD_OPEN );
|
|
|
|
|
2019-04-26 22:23:12 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Restore cursor after dialog
|
2019-05-30 12:25:08 +00:00
|
|
|
getViewControls()->WarpCursor( m_frame->GetCrossHairPosition(), 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 );
|
2019-04-26 22:23:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-01 13:24:51 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( image );
|
2019-04-26 22:23:12 +00:00
|
|
|
image = nullptr;
|
2019-05-01 20:15:51 +00:00
|
|
|
|
|
|
|
m_view->ClearPreview();
|
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-05-10 17:19:48 +00:00
|
|
|
else if( image && ( evt->IsAction( &EE_ACTIONS::refreshPreview )
|
2019-05-07 23:51:37 +00:00
|
|
|
|| 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
|
|
|
}
|
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is a module to be placed
|
2019-05-12 11:49:58 +00:00
|
|
|
getViewControls()->SetAutoPan( !!image );
|
|
|
|
getViewControls()->CaptureCursor( !!image );
|
2019-04-26 22:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->SetNoToolSelected();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlaceNoConnect( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_NOCONNECT_TOOL, wxCURSOR_PENCIL, _( "Add no connect" ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
return doSingleClickPlace( SCH_NO_CONNECT_T );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlaceJunction( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_JUNCTION_TOOL, wxCURSOR_PENCIL, _( "Add junction" ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
return doSingleClickPlace( SCH_JUNCTION_T );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlaceBusWireEntry( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_WIRETOBUS_ENTRY_TOOL, wxCURSOR_PENCIL, _( "Add wire to bus entry" ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
return doSingleClickPlace( SCH_BUS_WIRE_ENTRY_T );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlaceBusBusEntry( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_BUSTOBUS_ENTRY_TOOL, wxCURSOR_PENCIL, _( "Add bus to bus entry" ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
return doSingleClickPlace( SCH_BUS_BUS_ENTRY_T );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::doSingleClickPlace( KICAD_T aType )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
wxPoint cursorPos;
|
|
|
|
|
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 );
|
|
|
|
getViewControls()->SetSnapping( true );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
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-04-29 17:50:46 +00:00
|
|
|
if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item = nullptr;
|
|
|
|
|
|
|
|
if( !m_frame->GetScreen()->GetItem( cursorPos, 0, aType ) )
|
|
|
|
{
|
|
|
|
switch( aType )
|
|
|
|
{
|
2019-04-29 17:50:46 +00:00
|
|
|
case SCH_NO_CONNECT_T:
|
|
|
|
item = new SCH_NO_CONNECT( cursorPos );
|
|
|
|
break;
|
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
item = m_frame->AddJunction( cursorPos );
|
|
|
|
break;
|
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
|
|
|
item = new SCH_BUS_WIRE_ENTRY( cursorPos, g_lastBusEntryShape );
|
|
|
|
break;
|
|
|
|
case SCH_BUS_BUS_ENTRY_T:
|
|
|
|
item = new SCH_BUS_BUS_ENTRY( cursorPos, g_lastBusEntryShape );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( "doSingleClickPlace(): unknown type" );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item )
|
|
|
|
{
|
2019-04-29 17:50:46 +00:00
|
|
|
item->SetFlags( IS_NEW );
|
2019-05-01 13:24:51 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( item );
|
2019-04-29 17:50:46 +00:00
|
|
|
|
2019-05-10 16:48:46 +00:00
|
|
|
m_frame->SaveCopyForRepeatItem( item );
|
2019-04-29 17:50:46 +00:00
|
|
|
|
|
|
|
m_frame->SchematicCleanUp();
|
|
|
|
m_frame->TestDanglingEnds();
|
|
|
|
m_frame->OnModify();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->SetNoToolSelected();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlaceLabel( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_LABEL_TOOL, wxCURSOR_PENCIL, _( "Add net label" ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
return doTwoClickPlace( SCH_LABEL_T );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlaceGlobalLabel( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_GLOBALLABEL_TOOL, wxCURSOR_PENCIL, _( "Add global label" ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
return doTwoClickPlace( SCH_GLOBAL_LABEL_T );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlaceHierarchicalLabel( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_HIERLABEL_TOOL, wxCURSOR_PENCIL, _( "Add hierarchical label" ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
return doTwoClickPlace( SCH_HIER_LABEL_T );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlaceSheetPin( const TOOL_EVENT& aEvent )
|
2019-04-18 15:45:10 +00:00
|
|
|
{
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_SHEETPIN_TOOL, wxCURSOR_PENCIL, _( "Add sheet pins" ) );
|
2019-04-18 15:45:10 +00:00
|
|
|
return doTwoClickPlace( SCH_SHEET_PIN_T );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::ImportSheetPin( const TOOL_EVENT& aEvent )
|
2019-04-18 15:45:10 +00:00
|
|
|
{
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_IMPORT_SHEETPIN_TOOL, wxCURSOR_PENCIL, _( "Import sheet pins" ) );
|
2019-04-18 15:45:10 +00:00
|
|
|
return doTwoClickPlace( SCH_SHEET_PIN_T );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::PlaceSchematicText( const TOOL_EVENT& aEvent )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_SCHEMATIC_TEXT_TOOL, wxCURSOR_PENCIL, _( "Add text" ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
return doTwoClickPlace( SCH_TEXT_T );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 18:49:53 +00:00
|
|
|
int SCH_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
VECTOR2I cursorPos;
|
2019-05-05 10:33:34 +00:00
|
|
|
EDA_ITEM* item = nullptr;
|
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
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
|
2019-04-17 19:09:48 +00:00
|
|
|
|
2019-04-29 17:50:46 +00:00
|
|
|
if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) )
|
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
|
|
|
m_view->ClearPreview();
|
|
|
|
delete item;
|
|
|
|
item = nullptr;
|
2019-05-03 08:48:53 +00:00
|
|
|
|
|
|
|
if( !evt->IsActivate() )
|
|
|
|
continue;
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 08:48:53 +00:00
|
|
|
break;
|
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
|
|
|
|
|
|
|
switch( aType )
|
|
|
|
{
|
2019-04-18 15:45:10 +00:00
|
|
|
case SCH_LABEL_T:
|
|
|
|
item = m_frame->CreateNewText( LAYER_LOCLABEL );
|
|
|
|
break;
|
|
|
|
case SCH_HIER_LABEL_T:
|
|
|
|
item = m_frame->CreateNewText( LAYER_HIERLABEL );
|
|
|
|
break;
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
item = m_frame->CreateNewText( LAYER_GLOBLABEL );
|
|
|
|
break;
|
|
|
|
case SCH_TEXT_T:
|
|
|
|
item = m_frame->CreateNewText( LAYER_NOTES );
|
|
|
|
break;
|
|
|
|
case SCH_SHEET_PIN_T:
|
2019-05-16 21:58:47 +00:00
|
|
|
{
|
|
|
|
SCH_HIERLABEL* label = nullptr;
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) m_selectionTool->SelectPoint( cursorPos,
|
|
|
|
EE_COLLECTOR::SheetsOnly );
|
|
|
|
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
|
|
|
|
|
|
|
if( m_frame->GetToolId() == ID_IMPORT_SHEETPIN_TOOL )
|
|
|
|
{
|
|
|
|
label = m_frame->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 ) );
|
2019-05-19 21:04:04 +00:00
|
|
|
m_statusPopup->PopupFor( 2000 );
|
2019-05-16 21:58:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
item = m_frame->CreateSheetPin( sheet, label );
|
2019-04-18 15:45:10 +00:00
|
|
|
break;
|
2019-05-16 21:58:47 +00:00
|
|
|
}
|
2019-04-18 15:45:10 +00:00
|
|
|
default:
|
|
|
|
wxFAIL_MSG( "doTwoClickPlace(): unknown type" );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Restore cursor after dialog
|
2019-05-30 12:25:08 +00:00
|
|
|
getViewControls()->WarpCursor( m_frame->GetCrossHairPosition(), 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 );
|
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 );
|
2019-05-05 10:33:34 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( (SCH_ITEM*) item );
|
2019-04-17 19:09:48 +00:00
|
|
|
item = nullptr;
|
2019-05-01 20:15:51 +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-05-10 15:05:28 +00:00
|
|
|
else if( item && TOOL_EVT_UTILS::IsSelectionEvent( evt.get() ) )
|
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-05-10 17:19:48 +00:00
|
|
|
else if( item && ( evt->IsAction( &EE_ACTIONS::refreshPreview )
|
2019-05-07 23:51:37 +00:00
|
|
|
|| evt->IsMotion() ) )
|
2019-04-17 19:09:48 +00:00
|
|
|
{
|
2019-05-05 10:33:34 +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() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is a module to be placed
|
2019-05-12 11:49:58 +00:00
|
|
|
getViewControls()->SetAutoPan( !!item );
|
|
|
|
getViewControls()->CaptureCursor( !!item );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->SetNoToolSelected();
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SetToolID( ID_SHEET_TOOL, wxCURSOR_PENCIL, _( "Add sheet" ) );
|
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-05-08 18:56:03 +00:00
|
|
|
SCH_SHEET* sheet = nullptr;
|
2019-04-18 15:45:10 +00:00
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( auto evt = Wait() )
|
|
|
|
{
|
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-04-29 17:50:46 +00:00
|
|
|
if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) )
|
2019-04-18 15:45:10 +00:00
|
|
|
{
|
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-04-18 15:45:10 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
if( sheet )
|
2019-04-18 15:45:10 +00:00
|
|
|
{
|
2019-05-08 18:56:03 +00:00
|
|
|
delete sheet;
|
|
|
|
sheet = nullptr;
|
2019-05-03 08:48:53 +00:00
|
|
|
|
|
|
|
if( !evt->IsActivate() )
|
|
|
|
continue;
|
2019-04-18 15:45:10 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 08:48:53 +00:00
|
|
|
break;
|
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
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-10 16:48:46 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
sheet = new SCH_SHEET( (wxPoint) cursorPos );
|
|
|
|
sheet->SetFlags( IS_NEW | IS_RESIZED );
|
|
|
|
sheet->SetTimeStamp( GetNewTimeStamp() );
|
|
|
|
sheet->SetParent( m_frame->GetScreen() );
|
|
|
|
sheet->SetScreen( NULL );
|
|
|
|
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-05-08 18:56:03 +00:00
|
|
|
if( m_frame->EditSheet( (SCH_SHEET*)sheet, g_CurrentSheet, nullptr ) )
|
2019-05-22 22:28:51 +00:00
|
|
|
{
|
2019-05-08 18:56:03 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( sheet );
|
2019-05-22 22:28:51 +00:00
|
|
|
m_selectionTool->AddItemToSel( sheet );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
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-05-10 17:19:48 +00:00
|
|
|
else if( sheet && ( evt->IsAction( &EE_ACTIONS::refreshPreview )
|
2019-05-08 18:56:03 +00:00
|
|
|
|| 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
|
|
|
}
|
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is a sheet to be placed
|
2019-05-12 11:49:58 +00:00
|
|
|
getViewControls()->SetAutoPan( !!sheet );
|
|
|
|
getViewControls()->CaptureCursor( !!sheet );
|
2019-04-18 15:45:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->SetNoToolSelected();
|
|
|
|
|
|
|
|
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-05-10 17:19:48 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceSymbol, EE_ACTIONS::placeSymbol.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlacePower, EE_ACTIONS::placePower.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceNoConnect, EE_ACTIONS::placeNoConnect.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceJunction, EE_ACTIONS::placeJunction.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceBusWireEntry, EE_ACTIONS::placeBusWireEntry.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceBusBusEntry, EE_ACTIONS::placeBusBusEntry.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceLabel, EE_ACTIONS::placeLabel.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceHierarchicalLabel,EE_ACTIONS::placeHierarchicalLabel.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceGlobalLabel, EE_ACTIONS::placeGlobalLabel.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::DrawSheet, EE_ACTIONS::drawSheet.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceSheetPin, EE_ACTIONS::placeSheetPin.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::ImportSheetPin, EE_ACTIONS::importSheetPin.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceSchematicText, EE_ACTIONS::placeSchematicText.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::PlaceImage, EE_ACTIONS::placeImage.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &SCH_DRAWING_TOOLS::AddJunction, EE_ACTIONS::addJunction.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::AddLabel, EE_ACTIONS::addLabel.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::AddLabel, EE_ACTIONS::addGlobalLabel.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::AddLabel, EE_ACTIONS::addHierLabel.MakeEvent() );
|
2019-05-17 15:16:13 +00:00
|
|
|
Go( &SCH_DRAWING_TOOLS::AddSheetPin, EE_ACTIONS::addSheetPin.MakeEvent() );
|
|
|
|
Go( &SCH_DRAWING_TOOLS::AddSheetPin, EE_ACTIONS::addImportedSheetPin.MakeEvent() );
|
2019-04-17 19:09:48 +00:00
|
|
|
}
|