2019-05-02 15:01:51 +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
|
2019-05-02 15:01:51 +00:00
|
|
|
* 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-06-16 13:42:40 +00:00
|
|
|
#include <sch_line_wire_bus_tool.h>
|
2019-12-11 13:22:59 +00:00
|
|
|
|
|
|
|
#include <boost/optional/optional.hpp>
|
|
|
|
#include <wx/debug.h>
|
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/menu.h>
|
|
|
|
#include <wx/string.h>
|
|
|
|
#include <wx/stringimpl.h>
|
|
|
|
#include <wx/translation.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <deque>
|
|
|
|
#include <iterator>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <advanced_config.h>
|
|
|
|
#include <base_screen.h>
|
|
|
|
#include <base_struct.h>
|
|
|
|
#include <core/typeinfo.h>
|
|
|
|
#include <eda_text.h>
|
|
|
|
#include <layers_id_colors_and_visibility.h>
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
#include <tool/actions.h>
|
|
|
|
#include <tool/conditional_menu.h>
|
|
|
|
#include <tool/selection.h>
|
|
|
|
#include <tool/selection_conditions.h>
|
|
|
|
#include <tool/tool_action.h>
|
|
|
|
#include <tool/tool_event.h>
|
|
|
|
#include <tool/tool_interactive.h>
|
2019-05-02 15:01:51 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2019-12-11 13:22:59 +00:00
|
|
|
#include <trigo.h>
|
|
|
|
#include <undo_redo_container.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
|
|
|
|
#include <connection_graph.h>
|
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <general.h>
|
2019-05-02 15:01:51 +00:00
|
|
|
#include <sch_bus_entry.h>
|
2019-12-11 13:22:59 +00:00
|
|
|
#include <sch_connection.h>
|
|
|
|
#include <sch_draw_panel.h>
|
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <sch_item.h>
|
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_screen.h>
|
2019-05-02 15:01:51 +00:00
|
|
|
#include <sch_sheet.h>
|
2019-12-11 13:22:59 +00:00
|
|
|
#include <sch_sheet_path.h>
|
|
|
|
#include <sch_text.h>
|
|
|
|
#include <sch_view.h>
|
|
|
|
|
|
|
|
#include <ee_actions.h>
|
|
|
|
#include <ee_point_editor.h>
|
|
|
|
#include <ee_selection.h>
|
|
|
|
#include <ee_selection_tool.h>
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-05-14 11:14:00 +00:00
|
|
|
class BUS_UNFOLD_MENU : public ACTION_MENU
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-05-05 14:16:29 +00:00
|
|
|
BUS_UNFOLD_MENU() :
|
2019-06-15 00:29:42 +00:00
|
|
|
ACTION_MENU( true ),
|
2019-05-05 14:16:29 +00:00
|
|
|
m_showTitle( false )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
|
|
|
SetIcon( add_line2bus_xpm );
|
2019-05-05 16:00:59 +00:00
|
|
|
SetTitle( _( "Unfold from Bus" ) );
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
|
|
|
|
2019-05-05 14:16:29 +00:00
|
|
|
void SetShowTitle()
|
|
|
|
{
|
|
|
|
m_showTitle = true;
|
|
|
|
}
|
|
|
|
|
2019-05-02 20:03:03 +00:00
|
|
|
|
|
|
|
protected:
|
2019-05-14 11:14:00 +00:00
|
|
|
ACTION_MENU* create() const override
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
|
|
|
return new BUS_UNFOLD_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void update() override
|
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) getToolManager()->GetEditFrame();
|
|
|
|
EE_SELECTION_TOOL* selTool = getToolManager()->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
KICAD_T busType[] = { SCH_LINE_LOCATE_BUS_T, EOT };
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = selTool->RequestSelection( busType );
|
2019-05-10 17:19:48 +00:00
|
|
|
SCH_LINE* bus = (SCH_LINE*) selection.Front();
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2019-05-22 21:11:05 +00:00
|
|
|
Clear();
|
|
|
|
|
2019-05-02 20:03:03 +00:00
|
|
|
// TODO(JE) remove once real-time is enabled
|
|
|
|
if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
|
|
|
|
{
|
2019-11-10 23:24:27 +00:00
|
|
|
frame->RecalculateConnections( NO_CLEANUP );
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2019-06-18 17:56:40 +00:00
|
|
|
// Pick up the pointer again because it may have been changed by SchematicCleanUp
|
2019-05-02 20:03:03 +00:00
|
|
|
selection = selTool->RequestSelection( busType );
|
|
|
|
bus = (SCH_LINE*) selection.Front();
|
|
|
|
}
|
|
|
|
if( !bus )
|
|
|
|
{
|
|
|
|
Append( ID_POPUP_SCH_UNFOLD_BUS, _( "no bus selected" ), wxEmptyString );
|
|
|
|
Enable( ID_POPUP_SCH_UNFOLD_BUS, false );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_CONNECTION* connection = bus->Connection( *g_CurrentSheet );
|
|
|
|
|
|
|
|
if( !connection || !connection->IsBus() || connection->Members().empty() )
|
|
|
|
{
|
|
|
|
Append( ID_POPUP_SCH_UNFOLD_BUS, _( "bus has no connections" ), wxEmptyString );
|
|
|
|
Enable( ID_POPUP_SCH_UNFOLD_BUS, false );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int idx = 0;
|
|
|
|
|
2019-05-05 14:16:29 +00:00
|
|
|
if( m_showTitle )
|
|
|
|
{
|
|
|
|
Append( ID_POPUP_SCH_UNFOLD_BUS, _( "Unfold from Bus" ), wxEmptyString );
|
|
|
|
Enable( ID_POPUP_SCH_UNFOLD_BUS, false );
|
|
|
|
}
|
|
|
|
|
2019-05-02 20:03:03 +00:00
|
|
|
for( const auto& member : connection->Members() )
|
|
|
|
{
|
|
|
|
int id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ );
|
|
|
|
wxString name = member->Name( true );
|
|
|
|
|
|
|
|
if( member->Type() == CONNECTION_BUS )
|
|
|
|
{
|
2019-06-15 00:29:42 +00:00
|
|
|
ACTION_MENU* submenu = new ACTION_MENU( true );
|
2019-05-02 20:03:03 +00:00
|
|
|
AppendSubMenu( submenu, name );
|
|
|
|
|
|
|
|
for( const auto& sub_member : member->Members() )
|
|
|
|
{
|
|
|
|
id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ );
|
|
|
|
submenu->Append( id, sub_member->Name( true ), wxEmptyString );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Append( id, name, wxEmptyString );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-05 14:16:29 +00:00
|
|
|
bool m_showTitle;
|
|
|
|
};
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
SCH_LINE_WIRE_BUS_TOOL::SCH_LINE_WIRE_BUS_TOOL() :
|
2019-06-15 00:29:42 +00:00
|
|
|
EE_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveDrawingLineWireBus" )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
m_busUnfold = {};
|
2019-12-13 14:39:13 +00:00
|
|
|
m_wires.reserve( 16 );
|
2019-05-05 14:16:29 +00:00
|
|
|
}
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
SCH_LINE_WIRE_BUS_TOOL::~SCH_LINE_WIRE_BUS_TOOL()
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
bool SCH_LINE_WIRE_BUS_TOOL::Init()
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE::Init();
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
auto wireOrBusTool = [ this ] ( const SELECTION& aSel ) {
|
2019-06-24 15:27:05 +00:00
|
|
|
return ( m_frame->IsCurrentTool( EE_ACTIONS::drawWire )
|
|
|
|
|| m_frame->IsCurrentTool( EE_ACTIONS::drawBus ) );
|
2019-05-02 15:01:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto lineTool = [ this ] ( const SELECTION& aSel ) {
|
2019-06-24 15:27:05 +00:00
|
|
|
return ( m_frame->IsCurrentTool( EE_ACTIONS::drawLines ) );
|
2019-05-02 15:01:51 +00:00
|
|
|
};
|
|
|
|
|
2019-05-03 22:48:24 +00:00
|
|
|
auto belowRootSheetCondition = [] ( const SELECTION& aSel ) {
|
|
|
|
return g_CurrentSheet->Last() != g_RootSheet;
|
|
|
|
};
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
auto busSelection = EE_CONDITIONS::MoreThan( 0 )
|
|
|
|
&& EE_CONDITIONS::OnlyType( SCH_LINE_LOCATE_BUS_T );
|
2019-05-05 14:16:29 +00:00
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
auto& ctxMenu = m_menu.GetMenu();
|
|
|
|
|
|
|
|
// Build the tool menu
|
|
|
|
//
|
2019-06-15 00:29:42 +00:00
|
|
|
ctxMenu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 2 );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
ctxMenu.AddSeparator( 10 );
|
2019-06-24 15:27:05 +00:00
|
|
|
ctxMenu.AddItem( EE_ACTIONS::drawWire, wireOrBusTool && EE_CONDITIONS::Idle, 10 );
|
|
|
|
ctxMenu.AddItem( EE_ACTIONS::drawBus, wireOrBusTool && EE_CONDITIONS::Idle, 10 );
|
|
|
|
ctxMenu.AddItem( EE_ACTIONS::drawLines, lineTool && EE_CONDITIONS::Idle, 10 );
|
2019-05-17 16:45:27 +00:00
|
|
|
ctxMenu.AddItem( EE_ACTIONS::finishWire, IsDrawingWire, 10 );
|
|
|
|
ctxMenu.AddItem( EE_ACTIONS::finishBus, IsDrawingBus, 10 );
|
|
|
|
ctxMenu.AddItem( EE_ACTIONS::finishLine, IsDrawingLine, 10 );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-05-02 20:03:03 +00:00
|
|
|
std::shared_ptr<BUS_UNFOLD_MENU> busUnfoldMenu = std::make_shared<BUS_UNFOLD_MENU>();
|
|
|
|
busUnfoldMenu->SetTool( this );
|
|
|
|
m_menu.AddSubMenu( busUnfoldMenu );
|
2019-06-15 00:29:42 +00:00
|
|
|
ctxMenu.AddMenu( busUnfoldMenu.get(), EE_CONDITIONS::Idle, 10 );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
ctxMenu.AddSeparator( 100 );
|
2019-06-24 15:27:05 +00:00
|
|
|
ctxMenu.AddItem( EE_ACTIONS::placeJunction, wireOrBusTool && EE_CONDITIONS::Idle, 100 );
|
|
|
|
ctxMenu.AddItem( EE_ACTIONS::placeLabel, wireOrBusTool && EE_CONDITIONS::Idle, 100 );
|
|
|
|
ctxMenu.AddItem( EE_ACTIONS::placeGlobalLabel, wireOrBusTool && EE_CONDITIONS::Idle, 100 );
|
|
|
|
ctxMenu.AddItem( EE_ACTIONS::placeHierLabel, wireOrBusTool && EE_CONDITIONS::Idle, 100 );
|
|
|
|
ctxMenu.AddItem( EE_ACTIONS::breakWire, wireOrBusTool && EE_CONDITIONS::Idle, 100 );
|
|
|
|
ctxMenu.AddItem( EE_ACTIONS::breakBus, wireOrBusTool && EE_CONDITIONS::Idle, 100 );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
ctxMenu.AddSeparator( 200 );
|
2019-06-24 15:27:05 +00:00
|
|
|
ctxMenu.AddItem( EE_ACTIONS::selectNode, wireOrBusTool && EE_CONDITIONS::Idle, 200 );
|
|
|
|
ctxMenu.AddItem( EE_ACTIONS::selectConnection, wireOrBusTool && EE_CONDITIONS::Idle, 200 );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-05-05 14:16:29 +00:00
|
|
|
// Add bus unfolding to the selection tool
|
|
|
|
//
|
|
|
|
CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
|
|
|
|
|
|
|
|
std::shared_ptr<BUS_UNFOLD_MENU> selBusUnfoldMenu = std::make_shared<BUS_UNFOLD_MENU>();
|
|
|
|
selBusUnfoldMenu->SetTool( m_selectionTool );
|
|
|
|
m_selectionTool->GetToolMenu().AddSubMenu( selBusUnfoldMenu );
|
2019-06-24 15:27:05 +00:00
|
|
|
selToolMenu.AddMenu( selBusUnfoldMenu.get(), busSelection && EE_CONDITIONS::Idle, 100 );
|
2019-05-05 14:16:29 +00:00
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingLine( const SELECTION& aSelection )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-05-08 18:56:03 +00:00
|
|
|
static KICAD_T graphicLineType[] = { SCH_LINE_LOCATE_GRAPHIC_LINE_T, EOT };
|
|
|
|
return IsDrawingLineWireOrBus( aSelection ) && aSelection.Front()->IsType( graphicLineType );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingWire( const SELECTION& aSelection )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
static KICAD_T wireType[] = { SCH_LINE_LOCATE_WIRE_T, EOT };
|
|
|
|
return IsDrawingLineWireOrBus( aSelection ) && aSelection.Front()->IsType( wireType );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingBus( const SELECTION& aSelection )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
static KICAD_T busType[] = { SCH_LINE_LOCATE_BUS_T, EOT };
|
|
|
|
return IsDrawingLineWireOrBus( aSelection ) && aSelection.Front()->IsType( busType );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( const SELECTION& aSelection )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
// NOTE: for immediate hotkeys, it is NOT required that the line, wire or bus tool
|
|
|
|
// be selected
|
|
|
|
SCH_ITEM* item = (SCH_ITEM*) aSelection.Front();
|
2019-12-13 14:39:13 +00:00
|
|
|
return item && item->IsNew() && item->Type() == SCH_LINE_T;
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-18 17:56:40 +00:00
|
|
|
int SCH_LINE_WIRE_BUS_TOOL::DrawSegments( const TOOL_EVENT& aEvent )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-06-18 17:56:40 +00:00
|
|
|
SCH_LAYER_ID layer = aEvent.Parameter<SCH_LAYER_ID>();
|
2019-05-05 14:16:29 +00:00
|
|
|
|
2019-06-18 17:56:40 +00:00
|
|
|
if( aEvent.HasPosition() )
|
2019-06-15 00:29:42 +00:00
|
|
|
getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2019-06-19 15:11:41 +00:00
|
|
|
|
|
|
|
if( aEvent.HasPosition() )
|
|
|
|
{
|
|
|
|
VECTOR2D cursorPos = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) );
|
2019-12-11 13:22:59 +00:00
|
|
|
startSegments( layer, cursorPos );
|
2019-06-19 15:11:41 +00:00
|
|
|
}
|
2019-06-27 11:47:24 +00:00
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
return doDrawSegments( tool, layer );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
int SCH_LINE_WIRE_BUS_TOOL::UnfoldBus( const TOOL_EVENT& aEvent )
|
2019-05-05 14:16:29 +00:00
|
|
|
{
|
|
|
|
wxString* netPtr = aEvent.Parameter<wxString*>();
|
|
|
|
wxString net;
|
|
|
|
SCH_LINE* segment = nullptr;
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2019-05-05 14:16:29 +00:00
|
|
|
Activate();
|
|
|
|
|
|
|
|
if( netPtr )
|
|
|
|
{
|
|
|
|
net = *netPtr;
|
|
|
|
delete netPtr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BUS_UNFOLD_MENU unfoldMenu;
|
|
|
|
unfoldMenu.SetTool( this );
|
|
|
|
unfoldMenu.SetShowTitle();
|
|
|
|
|
|
|
|
SetContextMenu( &unfoldMenu, CMENU_NOW );
|
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-05-05 14:16:29 +00:00
|
|
|
{
|
2019-06-15 00:29:42 +00:00
|
|
|
if( evt->Action() == TA_CHOICE_MENU_CHOICE )
|
2019-05-05 14:16:29 +00:00
|
|
|
{
|
|
|
|
OPT<int> id = evt->GetCommandId();
|
|
|
|
|
|
|
|
if( id && ( *id > 0 ) )
|
|
|
|
net = *evt->Parameter<wxString*>();
|
2019-05-05 18:48:11 +00:00
|
|
|
|
|
|
|
break;
|
2019-05-05 14:16:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-18 17:56:40 +00:00
|
|
|
// Break a wire for the given net out of the bus
|
2019-05-05 14:16:29 +00:00
|
|
|
if( !net.IsEmpty() )
|
|
|
|
segment = doUnfoldBus( net );
|
|
|
|
|
2019-05-05 18:48:11 +00:00
|
|
|
// If we have an unfolded wire to draw, then draw it
|
2019-05-05 14:16:29 +00:00
|
|
|
if( segment )
|
2019-12-11 13:22:59 +00:00
|
|
|
return doDrawSegments( tool, LAYER_WIRE );
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2019-07-01 21:01:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-05-05 14:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
SCH_LINE* SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus( const wxString& aNet )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-08-21 13:27:22 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
|
2019-06-13 13:34:38 +00:00
|
|
|
wxPoint pos = (wxPoint) getViewControls()->GetCursorPosition();
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
m_busUnfold.entry = new SCH_BUS_WIRE_ENTRY( pos, '\\' );
|
|
|
|
m_busUnfold.entry->SetParent( m_frame->GetScreen() );
|
|
|
|
m_frame->AddToScreen( m_busUnfold.entry );
|
|
|
|
|
2019-05-02 20:03:03 +00:00
|
|
|
m_busUnfold.label = new SCH_LABEL( m_busUnfold.entry->m_End(), aNet );
|
2019-05-02 15:01:51 +00:00
|
|
|
m_busUnfold.label->SetTextSize( wxSize( GetDefaultTextSize(), GetDefaultTextSize() ) );
|
|
|
|
m_busUnfold.label->SetLabelSpinStyle( 0 );
|
|
|
|
m_busUnfold.label->SetParent( m_frame->GetScreen() );
|
2019-12-02 13:30:22 +00:00
|
|
|
m_busUnfold.label->SetFlags( IS_NEW | IS_MOVED );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
m_busUnfold.in_progress = true;
|
|
|
|
m_busUnfold.origin = pos;
|
2019-05-02 20:03:03 +00:00
|
|
|
m_busUnfold.net_name = aNet;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-06-13 13:34:38 +00:00
|
|
|
getViewControls()->SetCrossHairCursorPosition( m_busUnfold.entry->m_End(), false );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-05-02 20:03:03 +00:00
|
|
|
return startSegments( LAYER_WIRE, m_busUnfold.entry->m_End() );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-13 14:39:13 +00:00
|
|
|
const SCH_SHEET_PIN* SCH_LINE_WIRE_BUS_TOOL::getSheetPin( const wxPoint& aPosition )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-12-13 14:39:13 +00:00
|
|
|
for( SCH_ITEM* item = m_frame->GetScreen()->GetDrawItems(); item; item = item->Next() )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) item;
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PIN& pin : sheet->GetPins() )
|
|
|
|
{
|
|
|
|
if( pin.GetPosition() == aPosition )
|
|
|
|
return &pin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-13 14:39:13 +00:00
|
|
|
void SCH_LINE_WIRE_BUS_TOOL::computeBreakPoint( const std::pair<SCH_LINE*, SCH_LINE*>& aSegments,
|
2019-12-11 13:22:59 +00:00
|
|
|
wxPoint& aPosition )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
wxCHECK_RET( aSegments.first && aSegments.second,
|
|
|
|
wxT( "Cannot compute break point of NULL line segment." ) );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
SCH_LINE* segment = aSegments.first;
|
|
|
|
SCH_LINE* next_segment = aSegments.second;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
wxPoint midPoint;
|
2019-12-11 13:22:59 +00:00
|
|
|
int iDx = segment->GetEndPoint().x - segment->GetStartPoint().x;
|
|
|
|
int iDy = segment->GetEndPoint().y - segment->GetStartPoint().y;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-12-13 14:39:13 +00:00
|
|
|
const SCH_SHEET_PIN* connectedPin = getSheetPin( segment->GetStartPoint() );
|
2019-05-17 16:45:27 +00:00
|
|
|
auto force = connectedPin ? connectedPin->GetEdge() : SHEET_UNDEFINED_SIDE;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
if( force == SHEET_LEFT_SIDE || force == SHEET_RIGHT_SIDE )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
if( aPosition.x == connectedPin->GetPosition().x ) // push outside sheet boundary
|
|
|
|
{
|
2019-05-17 16:45:27 +00:00
|
|
|
int direction = ( force == SHEET_LEFT_SIDE ) ? -1 : 1;
|
2019-12-13 14:39:13 +00:00
|
|
|
aPosition.x += int( m_frame->GetScreen()->GetGridSize().x * direction );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
midPoint.x = aPosition.x;
|
2019-12-11 13:22:59 +00:00
|
|
|
midPoint.y = segment->GetStartPoint().y; // force horizontal
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
else if( iDy != 0 ) // keep the first segment orientation (vertical)
|
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
midPoint.x = segment->GetStartPoint().x;
|
2019-05-02 15:01:51 +00:00
|
|
|
midPoint.y = aPosition.y;
|
|
|
|
}
|
|
|
|
else if( iDx != 0 ) // keep the first segment orientation (horizontal)
|
|
|
|
{
|
|
|
|
midPoint.x = aPosition.x;
|
2019-12-11 13:22:59 +00:00
|
|
|
midPoint.y = segment->GetStartPoint().y;
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
if( std::abs( aPosition.x - segment->GetStartPoint().x ) <
|
|
|
|
std::abs( aPosition.y - segment->GetStartPoint().y ) )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
midPoint.x = segment->GetStartPoint().x;
|
2019-05-02 15:01:51 +00:00
|
|
|
midPoint.y = aPosition.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
midPoint.x = aPosition.x;
|
2019-12-11 13:22:59 +00:00
|
|
|
midPoint.y = segment->GetStartPoint().y;
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
segment->SetEndPoint( midPoint );
|
|
|
|
next_segment->SetStartPoint( midPoint );
|
|
|
|
next_segment->SetEndPoint( aPosition );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
SCH_SCREEN* screen = m_frame->GetScreen();
|
|
|
|
EE_POINT_EDITOR* pointEditor = m_toolMgr->GetTool<EE_POINT_EDITOR>();
|
2019-12-11 13:22:59 +00:00
|
|
|
SCH_LINE* segment = nullptr;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-12 11:49:58 +00:00
|
|
|
getViewControls()->ShowCursor( true );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
Activate();
|
|
|
|
|
2019-11-15 20:43:56 +00:00
|
|
|
// Add the new label to the selection so the rotate command operates on it
|
|
|
|
if( m_busUnfold.label )
|
|
|
|
m_selectionTool->AddItemToSel( m_busUnfold.label, true );
|
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-07-21 08:02:43 +00:00
|
|
|
if( !pointEditor->HasPoint() ) // Set wxCursor shape when starting the tool
|
2019-06-27 21:33:48 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
|
|
|
|
|
2019-07-21 08:02:43 +00:00
|
|
|
wxPoint cursorPos = (wxPoint) getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
|
|
|
|
bool forceHV = m_frame->GetForceHVLines();
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-05-02 20:03:03 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle cancel:
|
|
|
|
//
|
2019-07-01 21:01:33 +00:00
|
|
|
auto cleanup = [&] () {
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
for( auto wire : m_wires )
|
|
|
|
delete wire;
|
|
|
|
|
|
|
|
m_wires.clear();
|
|
|
|
segment = nullptr;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( m_busUnfold.entry )
|
|
|
|
m_frame->RemoveFromScreen( m_busUnfold.entry );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-11-15 20:43:56 +00:00
|
|
|
if( m_busUnfold.label && !m_busUnfold.label_placed )
|
|
|
|
m_selectionTool->RemoveItemFromSel( m_busUnfold.label, true );
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( m_busUnfold.label && m_busUnfold.label_placed )
|
|
|
|
m_frame->RemoveFromScreen( m_busUnfold.label );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
delete m_busUnfold.entry;
|
|
|
|
delete m_busUnfold.label;
|
|
|
|
m_busUnfold = {};
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->ShowPreview( false );
|
|
|
|
};
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
if( segment || m_busUnfold.in_progress )
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
|
|
|
else
|
2019-06-18 17:56:40 +00:00
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( aTool );
|
2019-06-24 15:27:05 +00:00
|
|
|
break;
|
2019-06-18 21:34:31 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
if( segment || m_busUnfold.in_progress )
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
2019-05-02 15:01:51 +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
|
2019-06-18 17:56:40 +00:00
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( aTool );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
2019-05-02 20:03:03 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle finish:
|
|
|
|
//
|
2019-05-10 17:19:48 +00:00
|
|
|
else if( evt->IsAction( &EE_ACTIONS::finishLineWireOrBus )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::finishWire )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::finishBus )
|
|
|
|
|| evt->IsAction( &EE_ACTIONS::finishLine ) )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
if( segment || m_busUnfold.in_progress )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
finishSegments();
|
2019-12-11 13:22:59 +00:00
|
|
|
segment = nullptr;
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-02 20:03:03 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle click:
|
|
|
|
//
|
2019-12-11 13:22:59 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || ( segment && evt->IsDblClick( BUT_LEFT ) ) )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
// First click when unfolding places the label and wire-to-bus entry
|
|
|
|
if( m_busUnfold.in_progress && !m_busUnfold.label_placed )
|
|
|
|
{
|
|
|
|
wxASSERT( aType == LAYER_WIRE );
|
|
|
|
|
|
|
|
m_frame->AddToScreen( m_busUnfold.label );
|
2019-11-15 20:43:56 +00:00
|
|
|
m_selectionTool->RemoveItemFromSel( m_busUnfold.label, true );
|
2019-05-02 15:01:51 +00:00
|
|
|
m_busUnfold.label_placed = true;
|
|
|
|
}
|
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
if( !segment )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
segment = startSegments( aType, VECTOR2D( cursorPos ) );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
// Create a new segment if we're out of previously-created ones
|
2019-12-11 13:22:59 +00:00
|
|
|
else if( !segment->IsNull() || ( forceHV && !m_wires.end()[-2]->IsNull() ) )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
// Terminate the command if the end point is on a pin, junction, or another
|
|
|
|
// wire or bus.
|
|
|
|
if( !m_busUnfold.in_progress
|
2019-12-11 13:22:59 +00:00
|
|
|
&& screen->IsTerminalPoint( cursorPos, segment->GetLayer() ) )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
finishSegments();
|
2019-12-11 13:22:59 +00:00
|
|
|
segment = nullptr;
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
segment->SetEndPoint( cursorPos );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
// Create a new segment, and chain it after the current segment.
|
2019-12-11 13:22:59 +00:00
|
|
|
segment = new SCH_LINE( *segment );
|
|
|
|
segment->SetFlags( IS_NEW | IS_MOVED );
|
|
|
|
segment->SetStartPoint( cursorPos );
|
|
|
|
m_wires.push_back( segment );
|
2019-05-03 08:48:53 +00:00
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
m_selectionTool->AddItemToSel( segment, true /*quiet mode*/ );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
if( evt->IsDblClick( BUT_LEFT ) && segment )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
if( forceHV && m_wires.size() >= 2 )
|
2019-12-13 14:39:13 +00:00
|
|
|
computeBreakPoint( { m_wires.end()[-2], segment }, cursorPos );
|
2019-05-05 17:38:49 +00:00
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
finishSegments();
|
2019-12-11 13:22:59 +00:00
|
|
|
segment = nullptr;
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-02 20:03:03 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle motion:
|
|
|
|
//
|
2019-12-02 13:30:22 +00:00
|
|
|
else if( evt->IsMotion() || evt->IsAction( &ACTIONS::refreshPreview ) )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
m_view->ClearPreview();
|
|
|
|
|
|
|
|
// Update the bus unfold posture based on the mouse movement
|
|
|
|
if( m_busUnfold.in_progress && !m_busUnfold.label_placed )
|
|
|
|
{
|
|
|
|
wxPoint cursor_delta = cursorPos - m_busUnfold.origin;
|
|
|
|
SCH_BUS_WIRE_ENTRY* entry = m_busUnfold.entry;
|
|
|
|
|
|
|
|
bool offset = ( cursor_delta.x < 0 );
|
|
|
|
char shape = ( offset ? ( ( cursor_delta.y >= 0 ) ? '/' : '\\' )
|
|
|
|
: ( ( cursor_delta.y >= 0 ) ? '\\' : '/' ) );
|
|
|
|
|
|
|
|
// Erase and redraw if necessary
|
|
|
|
if( shape != entry->GetBusEntryShape() || offset != m_busUnfold.offset )
|
|
|
|
{
|
|
|
|
entry->SetBusEntryShape( shape );
|
|
|
|
wxPoint entry_pos = m_busUnfold.origin;
|
|
|
|
|
|
|
|
if( offset )
|
|
|
|
entry_pos -= entry->GetSize();
|
|
|
|
|
|
|
|
entry->SetPosition( entry_pos );
|
|
|
|
m_busUnfold.offset = offset;
|
|
|
|
|
|
|
|
m_frame->RefreshItem( entry );
|
|
|
|
|
|
|
|
wxPoint wire_start = offset ? entry->GetPosition() : entry->m_End();
|
2019-12-11 13:22:59 +00:00
|
|
|
m_wires.front()->SetStartPoint( wire_start );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the label "ghost" position
|
|
|
|
m_busUnfold.label->SetPosition( cursorPos );
|
|
|
|
m_view->AddToPreview( m_busUnfold.label->Clone() );
|
|
|
|
}
|
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
if( segment )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
// Coerce the line to vertical or horizontal if necessary
|
2019-12-11 13:22:59 +00:00
|
|
|
if( forceHV && m_wires.size() >= 2 )
|
2019-12-13 14:39:13 +00:00
|
|
|
computeBreakPoint( { m_wires.end()[-2], segment }, cursorPos );
|
2019-05-02 15:01:51 +00:00
|
|
|
else
|
2019-12-11 13:22:59 +00:00
|
|
|
segment->SetEndPoint( cursorPos );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
for( auto wire : m_wires )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
if( !wire->IsNull() )
|
|
|
|
m_view->AddToPreview( wire->Clone() );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-02 20:03:03 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle context menu:
|
|
|
|
//
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
// Warp after context menu only if dragging...
|
2019-12-11 13:22:59 +00:00
|
|
|
if( !segment )
|
2019-05-02 20:03:03 +00:00
|
|
|
m_toolMgr->VetoContextMenuMouseWarp();
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
|
2019-05-02 20:03:03 +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_UNFOLD_BUS
|
|
|
|
&& evt->GetCommandId().get() <= ID_POPUP_SCH_UNFOLD_BUS_END )
|
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
wxASSERT_MSG( !segment, "Bus unfold event received when already drawing!" );
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2019-05-05 16:00:59 +00:00
|
|
|
aType = LAYER_WIRE;
|
2019-05-02 20:03:03 +00:00
|
|
|
wxString net = *evt->Parameter<wxString*>();
|
2019-12-11 13:22:59 +00:00
|
|
|
segment = doUnfoldBus( net );
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is a segment to be placed
|
2019-12-11 13:22:59 +00:00
|
|
|
getViewControls()->SetAutoPan( segment != nullptr );
|
|
|
|
getViewControls()->CaptureCursor( segment != nullptr );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
SCH_LINE* SCH_LINE_WIRE_BUS_TOOL::startSegments( int aType, const VECTOR2D& aPos )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* segment = nullptr;
|
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
switch ( aType )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
default:
|
|
|
|
segment = new SCH_LINE( aPos, LAYER_NOTES );
|
|
|
|
break;
|
|
|
|
case LAYER_WIRE:
|
|
|
|
segment = new SCH_LINE( aPos, LAYER_WIRE );
|
|
|
|
break;
|
|
|
|
case LAYER_BUS:
|
|
|
|
segment = new SCH_LINE( aPos, LAYER_BUS );
|
|
|
|
break;
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
segment->SetFlags( IS_NEW | IS_MOVED );
|
2019-12-11 13:22:59 +00:00
|
|
|
m_wires.push_back( segment );
|
2019-05-03 08:48:53 +00:00
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
m_selectionTool->AddItemToSel( segment, true /*quiet mode*/ );
|
|
|
|
|
|
|
|
// We need 2 segments to go from a given start pin to an end point when the
|
|
|
|
// horizontal and vertical lines only switch is on.
|
2019-12-11 13:22:59 +00:00
|
|
|
if( m_frame->GetForceHVLines() )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
segment = new SCH_LINE( *segment );
|
|
|
|
segment->SetFlags( IS_NEW | IS_MOVED );
|
2019-12-11 13:22:59 +00:00
|
|
|
m_wires.push_back( segment );
|
2019-05-03 08:48:53 +00:00
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
m_selectionTool->AddItemToSel( segment, true /*quiet mode*/ );
|
|
|
|
}
|
|
|
|
|
|
|
|
return segment;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In a contiguous list of wires, remove wires that backtrack over the previous
|
|
|
|
* wire. Example:
|
|
|
|
*
|
|
|
|
* Wire is added:
|
|
|
|
* ---------------------------------------->
|
|
|
|
*
|
|
|
|
* A second wire backtracks over it:
|
|
|
|
* -------------------<====================>
|
|
|
|
*
|
2019-12-13 14:39:13 +00:00
|
|
|
* simplifyWireList is called:
|
2019-05-02 15:01:51 +00:00
|
|
|
* ------------------->
|
|
|
|
*/
|
2019-12-13 14:39:13 +00:00
|
|
|
void SCH_LINE_WIRE_BUS_TOOL::simplifyWireList()
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-12-13 14:39:13 +00:00
|
|
|
for( auto it = m_wires.begin(); it != m_wires.end(); )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
SCH_LINE* line = *it;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
if( line->IsNull() )
|
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
delete line;
|
2019-12-13 14:39:13 +00:00
|
|
|
it = m_wires.erase( it );
|
2019-05-02 15:01:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
auto next_it = it;
|
|
|
|
++next_it;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-12-13 14:39:13 +00:00
|
|
|
if( next_it == m_wires.end() )
|
2019-12-11 13:22:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
SCH_LINE* next_line = *next_it;
|
|
|
|
|
|
|
|
if( line->IsParallel( next_line ) )
|
|
|
|
{
|
|
|
|
if( SCH_LINE* merged = line->MergeOverlap( next_line ) )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
delete line;
|
|
|
|
delete next_line;
|
2019-12-13 14:39:13 +00:00
|
|
|
it = m_wires.erase( it );
|
2019-12-11 13:22:59 +00:00
|
|
|
*it = merged;
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-11 13:22:59 +00:00
|
|
|
|
|
|
|
++it;
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
void SCH_LINE_WIRE_BUS_TOOL::finishSegments()
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
// Clear selection when done so that a new wire can be started.
|
2019-12-13 14:39:13 +00:00
|
|
|
// NOTE: this must be done before simplifyWireList is called or we might end up with
|
2019-05-02 15:01:51 +00:00
|
|
|
// freed selected items.
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
PICKED_ITEMS_LIST itemList;
|
|
|
|
|
|
|
|
// Remove segments backtracking over others
|
2019-12-13 14:39:13 +00:00
|
|
|
simplifyWireList();
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
// Collect the possible connection points for the new lines
|
|
|
|
std::vector< wxPoint > connections;
|
|
|
|
std::vector< wxPoint > new_ends;
|
|
|
|
m_frame->GetSchematicConnections( connections );
|
|
|
|
|
|
|
|
// Check each new segment for possible junctions and add/split if needed
|
2019-12-11 13:22:59 +00:00
|
|
|
for( auto wire : m_wires )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-08-27 12:12:34 +00:00
|
|
|
if( wire->HasFlag( SKIP_STRUCT ) )
|
2019-05-02 15:01:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
wire->GetConnectionPoints( new_ends );
|
|
|
|
|
|
|
|
for( auto i : connections )
|
|
|
|
{
|
|
|
|
if( IsPointOnSegment( wire->GetStartPoint(), wire->GetEndPoint(), i ) )
|
|
|
|
new_ends.push_back( i );
|
|
|
|
}
|
|
|
|
itemList.PushItem( ITEM_PICKER( wire, UR_NEW ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_busUnfold.in_progress && m_busUnfold.label_placed )
|
|
|
|
{
|
|
|
|
wxASSERT( m_busUnfold.entry && m_busUnfold.label );
|
|
|
|
|
|
|
|
itemList.PushItem( ITEM_PICKER( m_busUnfold.entry, UR_NEW ) );
|
|
|
|
itemList.PushItem( ITEM_PICKER( m_busUnfold.label, UR_NEW ) );
|
2019-12-02 13:30:22 +00:00
|
|
|
m_busUnfold.label->ClearEditFlags();
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the last non-null wire (this is the last created segment).
|
2019-12-11 13:22:59 +00:00
|
|
|
if( !m_wires.empty() )
|
|
|
|
m_frame->SaveCopyForRepeatItem( m_wires.back() );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
// Add the new wires
|
2019-12-11 13:22:59 +00:00
|
|
|
for( auto wire : m_wires )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
wire->ClearFlags( IS_NEW | IS_MOVED );
|
|
|
|
m_frame->AddToScreen( wire );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
m_wires.clear();
|
2019-05-02 15:01:51 +00:00
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->ShowPreview( false );
|
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
getViewControls()->CaptureCursor( false );
|
|
|
|
getViewControls()->SetAutoPan( false );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
m_frame->SaveCopyInUndoList( itemList, UR_NEW );
|
|
|
|
|
|
|
|
// Correct and remove segments that need to be merged.
|
2019-05-11 10:06:28 +00:00
|
|
|
m_frame->SchematicCleanUp();
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
for( auto item = m_frame->GetScreen()->GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::vector< wxPoint > pts;
|
|
|
|
item->GetConnectionPoints( pts );
|
|
|
|
|
|
|
|
if( pts.size() > 2 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for( auto i = pts.begin(); i != pts.end(); i++ )
|
|
|
|
{
|
|
|
|
for( auto j = i + 1; j != pts.end(); j++ )
|
2019-05-11 10:06:28 +00:00
|
|
|
m_frame->TrimWire( *i, *j );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto i : new_ends )
|
|
|
|
{
|
|
|
|
if( m_frame->GetScreen()->IsJunctionNeeded( i, true ) )
|
|
|
|
m_frame->AddJunction( i, true, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_busUnfold.in_progress )
|
|
|
|
m_busUnfold = {};
|
|
|
|
|
|
|
|
m_frame->TestDanglingEnds();
|
2019-05-12 17:03:17 +00:00
|
|
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-19 03:10:21 +00:00
|
|
|
int SCH_LINE_WIRE_BUS_TOOL::AddJunctionsIfNeeded( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EE_SELECTION* aSelection = aEvent.Parameter<EE_SELECTION*>();
|
|
|
|
|
|
|
|
std::vector<wxPoint> pts;
|
|
|
|
std::vector<wxPoint> connections;
|
|
|
|
|
|
|
|
m_frame->GetSchematicConnections( connections );
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < aSelection->GetSize(); ii++ )
|
|
|
|
{
|
2019-10-18 04:29:26 +00:00
|
|
|
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aSelection->GetItem( ii ) );
|
2019-06-19 03:10:21 +00:00
|
|
|
std::vector<wxPoint> new_pts;
|
|
|
|
|
2019-10-18 04:29:26 +00:00
|
|
|
if( !item || !item->IsConnectable() )
|
2019-06-19 03:10:21 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
item->GetConnectionPoints( new_pts );
|
|
|
|
pts.insert( pts.end(), new_pts.begin(), new_pts.end() );
|
|
|
|
|
|
|
|
// If the item is a line, we also add any connection points from the rest of the schematic
|
|
|
|
// that terminate on the line after it is moved.
|
|
|
|
if( item->Type() == SCH_LINE_T )
|
|
|
|
{
|
|
|
|
SCH_LINE* line = (SCH_LINE*) item;
|
|
|
|
for( auto i : connections )
|
|
|
|
{
|
|
|
|
if( IsPointOnSegment( line->GetStartPoint(), line->GetEndPoint(), i ) )
|
|
|
|
pts.push_back( i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Clean up any wires that short non-wire connections in the list
|
|
|
|
for( auto point = new_pts.begin(); point != new_pts.end(); point++ )
|
|
|
|
{
|
|
|
|
for( auto second_point = point + 1; second_point != new_pts.end(); second_point++ )
|
|
|
|
m_frame->TrimWire( *point, *second_point );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We always have some overlapping connection points. Drop duplicates here
|
|
|
|
std::sort( pts.begin(), pts.end(), []( const wxPoint& a, const wxPoint& b ) -> bool {
|
|
|
|
return a.x < b.x || ( a.x == b.x && a.y < b.y );
|
|
|
|
} );
|
|
|
|
|
|
|
|
pts.erase( unique( pts.begin(), pts.end() ), pts.end() );
|
|
|
|
|
|
|
|
for( auto point : pts )
|
|
|
|
{
|
|
|
|
if( m_frame->GetScreen()->IsJunctionNeeded( point, true ) )
|
|
|
|
m_frame->AddJunction( point, true, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
void SCH_LINE_WIRE_BUS_TOOL::setTransitions()
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2019-06-19 03:10:21 +00:00
|
|
|
Go( &SCH_LINE_WIRE_BUS_TOOL::AddJunctionsIfNeeded, EE_ACTIONS::addNeededJunctions.MakeEvent() );
|
2019-06-18 17:56:40 +00:00
|
|
|
Go( &SCH_LINE_WIRE_BUS_TOOL::DrawSegments, EE_ACTIONS::drawWire.MakeEvent() );
|
|
|
|
Go( &SCH_LINE_WIRE_BUS_TOOL::DrawSegments, EE_ACTIONS::drawBus.MakeEvent() );
|
|
|
|
Go( &SCH_LINE_WIRE_BUS_TOOL::DrawSegments, EE_ACTIONS::drawLines.MakeEvent() );
|
2019-05-05 14:16:29 +00:00
|
|
|
|
2019-06-18 17:56:40 +00:00
|
|
|
Go( &SCH_LINE_WIRE_BUS_TOOL::UnfoldBus, EE_ACTIONS::unfoldBus.MakeEvent() );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|