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
|
2021-06-10 14:10:55 +00:00
|
|
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-02 15:01:51 +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-06-16 13:42:40 +00:00
|
|
|
#include <sch_line_wire_bus_tool.h>
|
2019-12-11 13:22:59 +00:00
|
|
|
|
|
|
|
#include <wx/debug.h>
|
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/string.h>
|
|
|
|
#include <wx/stringimpl.h>
|
|
|
|
#include <wx/translation.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <iterator>
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <bitmaps.h>
|
2019-12-11 13:22:59 +00:00
|
|
|
#include <core/typeinfo.h>
|
2021-07-29 09:47:43 +00:00
|
|
|
#include <layer_ids.h>
|
2019-12-11 13:22:59 +00:00
|
|
|
#include <math/vector2d.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <advanced_config.h>
|
2019-12-11 13:22:59 +00:00
|
|
|
#include <tool/actions.h>
|
|
|
|
#include <tool/conditional_menu.h>
|
|
|
|
#include <tool/selection.h>
|
|
|
|
#include <tool/selection_conditions.h>
|
|
|
|
#include <tool/tool_event.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <undo_redo_container.h>
|
|
|
|
#include <connection_graph.h>
|
|
|
|
#include <eeschema_id.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_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>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2019-12-11 13:22:59 +00:00
|
|
|
#include <sch_text.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2019-12-11 13:22:59 +00:00
|
|
|
#include <ee_actions.h>
|
2020-09-09 02:54:17 +00:00
|
|
|
#include <ee_grid_helper.h>
|
2019-12-11 13:22:59 +00:00
|
|
|
#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
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
SetIcon( BITMAPS::add_line2bus );
|
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;
|
|
|
|
}
|
|
|
|
|
2021-02-10 15:02:28 +00:00
|
|
|
bool PassHelpTextToHandler() override { return 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
|
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) getToolManager()->GetToolHolder();
|
2019-05-10 17:19:48 +00:00
|
|
|
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
|
2020-11-16 11:16:44 +00:00
|
|
|
if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
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();
|
|
|
|
}
|
2020-01-22 03:02:07 +00:00
|
|
|
|
2019-05-02 20:03:03 +00:00
|
|
|
if( !bus )
|
|
|
|
{
|
2020-01-22 03:02:07 +00:00
|
|
|
Append( ID_POPUP_SCH_UNFOLD_BUS, _( "No bus selected" ), wxEmptyString );
|
2019-05-02 20:03:03 +00:00
|
|
|
Enable( ID_POPUP_SCH_UNFOLD_BUS, false );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
SCH_CONNECTION* connection = bus->Connection();
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
if( !connection || !connection->IsBus() || connection->Members().empty() )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2020-07-06 10:51:04 +00:00
|
|
|
Append( ID_POPUP_SCH_UNFOLD_BUS, _( "Bus has no members" ), wxEmptyString );
|
2019-05-02 20:03:03 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2021-03-15 14:23:17 +00:00
|
|
|
for( const std::shared_ptr<SCH_CONNECTION>& member : connection->Members() )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
|
|
|
int id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ );
|
2021-02-10 15:02:28 +00:00
|
|
|
wxString name = member->FullLocalName();
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
if( member->Type() == CONNECTION_TYPE::BUS )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2021-03-27 19:16:58 +00:00
|
|
|
ACTION_MENU* submenu = new ACTION_MENU( true, m_tool );
|
2021-02-10 15:02:28 +00:00
|
|
|
AppendSubMenu( submenu, SCH_CONNECTION::PrintBusForUI( name ), name );
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2021-03-15 14:23:17 +00:00
|
|
|
for( const std::shared_ptr<SCH_CONNECTION>& sub_member : member->Members() )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
|
|
|
id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ );
|
2021-02-10 15:02:28 +00:00
|
|
|
name = sub_member->FullLocalName();
|
|
|
|
submenu->Append( id, SCH_CONNECTION::PrintBusForUI( name ), name );
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
auto wireOrBusTool =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return ( m_frame->IsCurrentTool( EE_ACTIONS::drawWire )
|
|
|
|
|| m_frame->IsCurrentTool( EE_ACTIONS::drawBus ) );
|
|
|
|
};
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
auto lineTool =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_frame->IsCurrentTool( EE_ACTIONS::drawLines );
|
|
|
|
};
|
2019-05-02 15:01:51 +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-05-03 22:48:24 +00:00
|
|
|
|
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
|
|
|
{
|
2020-10-01 23:53:47 +00:00
|
|
|
DRAW_SEGMENT_EVENT_PARAMS* params = aEvent.Parameter<DRAW_SEGMENT_EVENT_PARAMS*>();
|
2019-05-05 14:16:29 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2020-10-13 23:04:53 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-06-19 15:11:41 +00:00
|
|
|
|
|
|
|
if( aEvent.HasPosition() )
|
|
|
|
{
|
2021-01-29 22:07:49 +00:00
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
grid.SetSnap( !aEvent.Modifier( MD_SHIFT ) );
|
2021-05-09 19:17:01 +00:00
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !aEvent.DisableGridSnapping() );
|
2021-01-29 22:07:49 +00:00
|
|
|
|
|
|
|
VECTOR2D cursorPos = grid.BestSnapAnchor( aEvent.Position(), LAYER_CONNECTABLE, nullptr );
|
2020-10-01 23:53:47 +00:00
|
|
|
startSegments( params->layer, cursorPos );
|
2019-06-19 15:11:41 +00:00
|
|
|
}
|
2019-06-27 11:47:24 +00:00
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
return doDrawSegments( tool, params->layer, params->quitOnDraw );
|
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
|
|
|
}
|
2020-01-22 03:02:07 +00:00
|
|
|
else if( evt->Action() == TA_CHOICE_MENU_CLOSED )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
}
|
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 )
|
2020-10-01 23:53:47 +00:00
|
|
|
return doDrawSegments( tool, LAYER_WIRE, false );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
SCH_LINE* SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus( const wxString& aNet, const wxPoint& aPos )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2020-05-23 15:50:08 +00:00
|
|
|
SCHEMATIC_SETTINGS& cfg = getModel<SCHEMATIC>()->Settings();
|
2020-12-27 18:07:16 +00:00
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
wxPoint pos = aPos;
|
|
|
|
|
2020-12-27 18:07:16 +00:00
|
|
|
if( aPos == wxDefaultPosition )
|
2021-07-26 19:35:12 +00:00
|
|
|
pos = static_cast<wxPoint>( getViewControls()->GetCursorPosition() );
|
2019-08-21 13:27:22 +00:00
|
|
|
|
2020-05-23 15:50:08 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
m_busUnfold.entry = new SCH_BUS_WIRE_ENTRY( pos );
|
2019-05-02 15:01:51 +00:00
|
|
|
m_busUnfold.entry->SetParent( m_frame->GetScreen() );
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->AddToScreen( m_busUnfold.entry, m_frame->GetScreen() );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
m_busUnfold.label = new SCH_LABEL( m_busUnfold.entry->GetEnd(), aNet );
|
2020-05-23 15:50:08 +00:00
|
|
|
m_busUnfold.label->SetTextSize( wxSize( cfg.m_DefaultTextSize, cfg.m_DefaultTextSize ) );
|
2020-01-22 03:02:07 +00:00
|
|
|
m_busUnfold.label->SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT );
|
2019-05-02 15:01:51 +00:00
|
|
|
m_busUnfold.label->SetParent( m_frame->GetScreen() );
|
2021-05-30 21:04:07 +00:00
|
|
|
m_busUnfold.label->SetFlags( IS_NEW | IS_MOVING );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
m_busUnfold.in_progress = true;
|
2021-07-26 19:35:12 +00:00
|
|
|
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
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
getViewControls()->SetCrossHairCursorPosition( m_busUnfold.entry->GetEnd(), false );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
return startSegments( LAYER_WIRE, m_busUnfold.entry->GetEnd() );
|
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-06-25 23:39:58 +00:00
|
|
|
SCH_SCREEN* screen = m_frame->GetScreen();
|
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items().Overlapping( SCH_SHEET_T, aPosition ) )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2020-11-22 22:21:41 +00:00
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2020-01-12 18:40:50 +00:00
|
|
|
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2020-01-12 18:40:50 +00:00
|
|
|
if( pin->GetPosition() == aPosition )
|
|
|
|
return pin;
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2020-12-03 15:10:23 +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,
|
2020-11-22 22:21:41 +00:00
|
|
|
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() );
|
2021-11-28 19:06:08 +00:00
|
|
|
SHEET_SIDE force = connectedPin ? connectedPin->GetSide() : SHEET_SIDE::UNDEFINED;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2021-05-31 01:20:43 +00:00
|
|
|
if( force == SHEET_SIDE::LEFT || force == SHEET_SIDE::RIGHT )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
if( aPosition.x == connectedPin->GetPosition().x ) // push outside sheet boundary
|
|
|
|
{
|
2021-05-31 01:20:43 +00:00
|
|
|
int direction = ( force == SHEET_SIDE::LEFT ) ? -1 : 1;
|
2020-06-12 10:58:56 +00:00
|
|
|
aPosition.x += KiROUND( getView()->GetGAL()->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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType, bool aQuitOnDraw )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2021-04-07 09:47:03 +00:00
|
|
|
SCH_SCREEN* screen = m_frame->GetScreen();
|
|
|
|
SCH_LINE* segment = nullptr;
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
2020-09-09 02:54:17 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
2022-02-16 15:06:17 +00:00
|
|
|
bool forceHV = m_frame->eeconfig()->m_Drawing.hv_lines_only;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2020-10-09 01:15:03 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
2020-10-08 02:47:01 +00:00
|
|
|
{
|
2020-10-10 22:25:28 +00:00
|
|
|
if( aType == LAYER_WIRE )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::LINE_WIRE );
|
|
|
|
else if( aType == LAYER_BUS )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::LINE_BUS );
|
|
|
|
else if( aType == LAYER_NOTES )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::LINE_GRAPHIC );
|
|
|
|
else
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::LINE_WIRE );
|
2020-10-08 02:47:01 +00:00
|
|
|
};
|
|
|
|
|
2021-04-07 09:47:03 +00:00
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
|
|
|
|
for( SCH_LINE* wire : m_wires )
|
|
|
|
delete wire;
|
|
|
|
|
|
|
|
m_wires.clear();
|
|
|
|
segment = nullptr;
|
|
|
|
|
|
|
|
if( m_busUnfold.entry )
|
|
|
|
m_frame->RemoveFromScreen( m_busUnfold.entry, screen );
|
|
|
|
|
|
|
|
if( m_busUnfold.label && !m_busUnfold.label_placed )
|
|
|
|
m_selectionTool->RemoveItemFromSel( m_busUnfold.label, true );
|
|
|
|
|
|
|
|
if( m_busUnfold.label && m_busUnfold.label_placed )
|
|
|
|
m_frame->RemoveFromScreen( m_busUnfold.label, screen );
|
|
|
|
|
|
|
|
delete m_busUnfold.entry;
|
|
|
|
delete m_busUnfold.label;
|
|
|
|
m_busUnfold = {};
|
|
|
|
|
|
|
|
m_view->ClearPreview();
|
|
|
|
m_view->ShowPreview( false );
|
|
|
|
};
|
|
|
|
|
|
|
|
Activate();
|
2021-09-13 12:23:10 +00:00
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
controls->ShowCursor( true );
|
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
2021-04-07 09:47:03 +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 );
|
|
|
|
|
|
|
|
// Continue the existing wires if we've started (usually by immediate action preference)
|
|
|
|
if( !m_wires.empty() )
|
|
|
|
segment = m_wires.back();
|
|
|
|
|
2020-12-27 18:07:16 +00:00
|
|
|
wxPoint contextMenuPos;
|
|
|
|
|
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
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2021-02-02 17:40:04 +00:00
|
|
|
grid.SetMask( GRID_HELPER::ALL );
|
2020-09-09 02:54:17 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2021-05-09 19:17:01 +00:00
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2020-12-03 15:10:23 +00:00
|
|
|
|
2021-02-02 17:40:04 +00:00
|
|
|
if( segment )
|
|
|
|
{
|
|
|
|
if( segment->GetStartPoint().x == segment->GetEndPoint().x )
|
|
|
|
grid.ClearMaskFlag( GRID_HELPER::VERTICAL );
|
|
|
|
|
|
|
|
if( segment->GetStartPoint().y == segment->GetEndPoint().y )
|
|
|
|
grid.ClearMaskFlag( GRID_HELPER::HORIZONTAL );
|
|
|
|
}
|
|
|
|
|
2021-03-01 17:17:08 +00:00
|
|
|
wxPoint cursorPos = static_cast<wxPoint>( evt->HasPosition() ?
|
|
|
|
evt->Position() :
|
|
|
|
controls->GetMousePosition() );
|
2020-12-03 15:10:23 +00:00
|
|
|
|
2021-02-02 17:40:04 +00:00
|
|
|
cursorPos = (wxPoint) grid.BestSnapAnchor( cursorPos, LAYER_CONNECTABLE, segment );
|
2020-09-09 02:54:17 +00:00
|
|
|
controls->ForceCursorPosition( true, cursorPos );
|
|
|
|
|
2022-02-16 15:06:17 +00:00
|
|
|
// Need to handle change in H/V mode while drawing
|
|
|
|
if( forceHV != m_frame->eeconfig()->m_Drawing.hv_lines_only )
|
|
|
|
{
|
|
|
|
forceHV = m_frame->eeconfig()->m_Drawing.hv_lines_only;
|
|
|
|
|
|
|
|
// Need to delete extra segment if we have one
|
|
|
|
if( !forceHV && m_wires.size() >= 2 && segment != nullptr )
|
|
|
|
{
|
|
|
|
m_wires.pop_back();
|
|
|
|
m_selectionTool->RemoveItemFromSel( segment );
|
|
|
|
delete segment;
|
|
|
|
|
|
|
|
segment = m_wires.back();
|
|
|
|
segment->SetEndPoint( cursorPos );
|
|
|
|
}
|
|
|
|
// Add a segment so we can move orthogonally
|
|
|
|
else if( forceHV && segment )
|
|
|
|
{
|
|
|
|
segment->SetEndPoint( cursorPos );
|
|
|
|
|
|
|
|
// Create a new segment, and chain it after the current segment.
|
|
|
|
segment = static_cast<SCH_LINE*>( segment->Duplicate() );
|
|
|
|
segment->SetFlags( IS_NEW | IS_MOVING );
|
|
|
|
segment->SetStartPoint( cursorPos );
|
|
|
|
m_wires.push_back( segment );
|
|
|
|
|
|
|
|
m_selectionTool->AddItemToSel( segment, true /*quiet mode*/ );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2020-11-19 20:08:58 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle cancel:
|
|
|
|
//
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
if( segment || m_busUnfold.in_progress )
|
2021-03-15 14:23:17 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
2021-03-15 14:23:17 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
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 )
|
2021-05-08 22:30:38 +00:00
|
|
|
{
|
|
|
|
m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel drawing." ) );
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
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;
|
2020-10-01 23:53:47 +00:00
|
|
|
|
|
|
|
if( aQuitOnDraw )
|
|
|
|
{
|
|
|
|
m_frame->PopTool( aTool );
|
|
|
|
break;
|
|
|
|
}
|
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 );
|
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->AddToScreen( m_busUnfold.label, screen );
|
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
|
2020-04-07 10:24:39 +00:00
|
|
|
else if( !segment->IsNull() || ( forceHV && !m_wires[ m_wires.size() - 2 ]->IsNull() ) )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2021-02-06 23:35:24 +00:00
|
|
|
// Terminate the command if the end point is on a pin, junction, label, or another
|
2019-05-02 15:01:51 +00:00
|
|
|
// wire or bus.
|
2021-02-06 23:35:24 +00:00
|
|
|
if( screen->IsTerminalPoint( cursorPos, segment->GetLayer() ) )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
finishSegments();
|
2019-12-11 13:22:59 +00:00
|
|
|
segment = nullptr;
|
2020-10-01 23:53:47 +00:00
|
|
|
|
|
|
|
if( aQuitOnDraw )
|
|
|
|
{
|
|
|
|
m_frame->PopTool( aTool );
|
|
|
|
break;
|
|
|
|
}
|
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.
|
2021-11-24 11:02:38 +00:00
|
|
|
segment = static_cast<SCH_LINE*>( segment->Duplicate() );
|
2021-05-30 21:04:07 +00:00
|
|
|
segment->SetFlags( IS_NEW | IS_MOVING );
|
2019-12-11 13:22:59 +00:00
|
|
|
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 )
|
2020-04-07 10:24:39 +00:00
|
|
|
computeBreakPoint( { m_wires[ m_wires.size() - 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;
|
2020-10-01 23:53:47 +00:00
|
|
|
|
|
|
|
if( aQuitOnDraw )
|
|
|
|
{
|
|
|
|
m_frame->PopTool( aTool );
|
|
|
|
break;
|
|
|
|
}
|
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;
|
|
|
|
|
2020-07-09 22:51:42 +00:00
|
|
|
bool flipX = ( cursor_delta.x < 0 );
|
|
|
|
bool flipY = ( cursor_delta.y < 0 );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
// Erase and redraw if necessary
|
2020-07-09 22:51:42 +00:00
|
|
|
if( flipX != m_busUnfold.flipX || flipY != m_busUnfold.flipY )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2020-07-09 22:51:42 +00:00
|
|
|
wxSize size = entry->GetSize();
|
|
|
|
int ySign = flipY ? -1 : 1;
|
|
|
|
int xSign = flipX ? -1 : 1;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2020-07-09 22:51:42 +00:00
|
|
|
size.x = std::abs( size.x ) * xSign;
|
|
|
|
size.y = std::abs( size.y ) * ySign;
|
|
|
|
entry->SetSize( size );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2020-07-09 22:51:42 +00:00
|
|
|
m_busUnfold.flipY = flipY;
|
|
|
|
m_busUnfold.flipX = flipX;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2021-10-06 03:10:20 +00:00
|
|
|
m_frame->UpdateItem( entry, false, true );
|
2020-09-08 13:27:13 +00:00
|
|
|
m_wires.front()->SetStartPoint( entry->GetEnd() );
|
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() );
|
2020-01-22 03:02:07 +00:00
|
|
|
|
|
|
|
// Ensure segment is non-null at the start of bus unfold
|
|
|
|
if( !segment )
|
|
|
|
segment = m_wires.back();
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
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 )
|
2020-04-07 10:24:39 +00:00
|
|
|
computeBreakPoint( { m_wires[ m_wires.size() - 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
|
|
|
}
|
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
for( SCH_LINE* 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();
|
|
|
|
|
2020-12-27 18:07:16 +00:00
|
|
|
contextMenuPos = cursorPos;
|
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 )
|
|
|
|
{
|
2022-02-08 23:14:18 +00:00
|
|
|
wxASSERT_MSG( !segment, wxT( "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*>();
|
2020-12-27 18:07:16 +00:00
|
|
|
segment = doUnfoldBus( net, contextMenuPos );
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-21 12:25:22 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle TOOL_ACTION special cases
|
|
|
|
//
|
2021-09-17 20:55:21 +00:00
|
|
|
else if( evt->IsAction( &EE_ACTIONS::rotateCW ) || evt->IsAction( &EE_ACTIONS::rotateCCW ) )
|
|
|
|
{
|
|
|
|
if( m_busUnfold.in_progress )
|
|
|
|
{
|
|
|
|
m_busUnfold.label->Rotate90( evt->IsAction( &EE_ACTIONS::rotateCW ) );
|
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
|
|
|
}
|
2021-07-24 02:06:26 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::doDelete ) && ( segment || m_busUnfold.in_progress ) )
|
2021-03-15 14:23:17 +00:00
|
|
|
{
|
2021-07-24 02:06:26 +00:00
|
|
|
cleanup();
|
2021-03-15 14:23:17 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is a segment to be placed
|
2020-09-09 02:54:17 +00:00
|
|
|
controls->SetAutoPan( segment != nullptr );
|
|
|
|
controls->CaptureCursor( segment != nullptr );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
controls->SetAutoPan( false );
|
|
|
|
controls->CaptureCursor( false );
|
2020-11-19 20:08:58 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2020-09-18 23:09:19 +00:00
|
|
|
controls->ForceCursorPosition( false );
|
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
|
|
|
{
|
2020-11-22 22:21:41 +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
|
|
|
}
|
|
|
|
|
2020-08-09 20:51:40 +00:00
|
|
|
// Give segments a parent so they find the default line/wire/bus widths
|
|
|
|
segment->SetParent( &m_frame->Schematic() );
|
2021-05-30 21:04:07 +00:00
|
|
|
segment->SetFlags( IS_NEW | IS_MOVING );
|
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.
|
2020-04-12 23:09:17 +00:00
|
|
|
if( m_frame->eeconfig()->m_Drawing.hv_lines_only )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2021-11-24 11:02:38 +00:00
|
|
|
segment = static_cast<SCH_LINE*>( segment->Duplicate() );
|
2021-05-30 21:04:07 +00:00
|
|
|
segment->SetFlags( IS_NEW | IS_MOVING );
|
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;
|
|
|
|
|
2020-10-21 17:41:44 +00:00
|
|
|
if( SCH_LINE* merged = line->MergeOverlap( m_frame->GetScreen(), next_line, false ) )
|
2019-12-11 13:22:59 +00:00
|
|
|
{
|
2020-10-21 17:41:44 +00:00
|
|
|
delete line;
|
|
|
|
delete next_line;
|
|
|
|
it = m_wires.erase( it );
|
|
|
|
*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
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
SCH_SCREEN* screen = m_frame->GetScreen();
|
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
|
2020-09-08 13:27:13 +00:00
|
|
|
std::vector< wxPoint > connections = m_frame->GetSchematicConnections();
|
2019-05-02 15:01:51 +00:00
|
|
|
std::vector< wxPoint > new_ends;
|
|
|
|
|
|
|
|
// Check each new segment for possible junctions and add/split if needed
|
2020-11-22 22:21:41 +00:00
|
|
|
for( SCH_LINE* 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;
|
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
std::vector<wxPoint> tmpends = wire->GetConnectionPoints();
|
|
|
|
|
|
|
|
new_ends.insert( new_ends.end(), tmpends.begin(), tmpends.end() );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
for( const wxPoint& pt : connections )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2020-11-22 22:21:41 +00:00
|
|
|
if( IsPointOnSegment( wire->GetStartPoint(), wire->GetEndPoint(), pt ) )
|
|
|
|
new_ends.push_back( pt );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
2020-08-26 18:04:32 +00:00
|
|
|
itemList.PushItem( ITEM_PICKER( screen, wire, UNDO_REDO::NEWITEM ) );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_busUnfold.in_progress && m_busUnfold.label_placed )
|
|
|
|
{
|
|
|
|
wxASSERT( m_busUnfold.entry && m_busUnfold.label );
|
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
itemList.PushItem( ITEM_PICKER( screen, m_busUnfold.entry, UNDO_REDO::NEWITEM ) );
|
|
|
|
itemList.PushItem( ITEM_PICKER( screen, m_busUnfold.label, UNDO_REDO::NEWITEM ) );
|
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
|
2020-11-22 22:21:41 +00:00
|
|
|
for( SCH_LINE* wire : m_wires )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2021-05-30 21:04:07 +00:00
|
|
|
wire->ClearFlags( IS_NEW | IS_MOVING );
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->AddToScreen( wire, screen );
|
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
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
m_frame->SaveCopyInUndoList( itemList, UNDO_REDO::NEWITEM, false );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2021-03-29 10:46:05 +00:00
|
|
|
std::vector<SCH_ITEM*> symbols;
|
2021-01-29 16:33:01 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_ITEM* symbol : m_frame->GetScreen()->Items().OfType( SCH_SYMBOL_T ) )
|
2021-03-29 10:46:05 +00:00
|
|
|
symbols.push_back( symbol );
|
2021-01-29 16:33:01 +00:00
|
|
|
|
2021-03-29 10:46:05 +00:00
|
|
|
for( SCH_ITEM* symbol : symbols )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2021-03-29 10:46:05 +00:00
|
|
|
std::vector<wxPoint> pts = symbol->GetConnectionPoints();
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
if( pts.size() > 2 )
|
|
|
|
continue;
|
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
for( auto pt = pts.begin(); pt != pts.end(); pt++ )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2020-11-22 22:21:41 +00:00
|
|
|
for( auto secondPt = pt + 1; secondPt != pts.end(); secondPt++ )
|
|
|
|
m_frame->TrimWire( *pt, *secondPt );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
for( const wxPoint& pt : new_ends )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2021-11-04 12:38:15 +00:00
|
|
|
if( m_frame->GetScreen()->IsExplicitJunctionNeeded( pt ) )
|
2020-11-22 22:21:41 +00:00
|
|
|
m_frame->AddJunction( m_frame->GetScreen(), pt, true, false );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-20 00:49:26 +00:00
|
|
|
int SCH_LINE_WIRE_BUS_TOOL::TrimOverLappingWires( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EE_SELECTION* aSelection = aEvent.Parameter<EE_SELECTION*>();
|
|
|
|
SCHEMATIC* sch = getModel<SCHEMATIC>();
|
|
|
|
SCH_SCREEN* screen = sch->CurrentSheet().LastScreen();
|
|
|
|
|
|
|
|
std::set<SCH_LINE*> lines;
|
|
|
|
EDA_RECT bb = aSelection->GetBoundingBox();
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : screen->Items().Overlapping( SCH_LINE_T, bb ) )
|
|
|
|
lines.insert( static_cast<SCH_LINE*>( item ) );
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < aSelection->GetSize(); ii++ )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aSelection->GetItem( ii ) );
|
|
|
|
std::vector<wxPoint> pts = item->GetConnectionPoints();
|
|
|
|
|
|
|
|
if( !item || !item->IsConnectable() || ( item->Type() == SCH_LINE_T ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/// If the line intersects with an item in the selection at only two points,
|
|
|
|
/// then we can remove the line between the two points.
|
|
|
|
for( SCH_LINE* line : lines )
|
|
|
|
{
|
|
|
|
std::vector<wxPoint> conn_pts;
|
|
|
|
|
|
|
|
for( wxPoint pt : pts )
|
|
|
|
{
|
|
|
|
if( IsPointOnSegment( line->GetStartPoint(), line->GetEndPoint(), pt ) )
|
|
|
|
conn_pts.push_back( pt );
|
|
|
|
|
|
|
|
if( conn_pts.size() > 2 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( conn_pts.size() == 2 )
|
|
|
|
m_frame->TrimWire( conn_pts[0], conn_pts[1] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2020-09-08 13:27:13 +00:00
|
|
|
std::vector<wxPoint> connections = m_frame->GetSchematicConnections();
|
2019-06-19 03:10:21 +00:00
|
|
|
|
2022-02-20 00:49:26 +00:00
|
|
|
std::set<SCH_LINE*> lines;
|
|
|
|
EDA_RECT bb = aSelection->GetBoundingBox();
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : m_frame->GetScreen()->Items().Overlapping( SCH_LINE_T, bb ) )
|
|
|
|
lines.insert( static_cast<SCH_LINE*>( item ) );
|
|
|
|
|
2019-06-19 03:10:21 +00:00
|
|
|
for( unsigned ii = 0; ii < aSelection->GetSize(); ii++ )
|
|
|
|
{
|
2020-11-22 22:21:41 +00:00
|
|
|
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aSelection->GetItem( ii ) );
|
2019-06-19 03:10:21 +00:00
|
|
|
|
2019-10-18 04:29:26 +00:00
|
|
|
if( !item || !item->IsConnectable() )
|
2019-06-19 03:10:21 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
std::vector<wxPoint> new_pts = item->GetConnectionPoints();
|
2019-06-19 03:10:21 +00:00
|
|
|
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;
|
2020-11-22 22:21:41 +00:00
|
|
|
|
|
|
|
for( const wxPoint& pt : connections )
|
2019-06-19 03:10:21 +00:00
|
|
|
{
|
2020-11-22 22:21:41 +00:00
|
|
|
if( IsPointOnSegment( line->GetStartPoint(), line->GetEndPoint(), pt ) )
|
|
|
|
pts.push_back( pt );
|
2019-06-19 03:10:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We always have some overlapping connection points. Drop duplicates here
|
2020-11-22 22:21:41 +00:00
|
|
|
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 );
|
|
|
|
} );
|
2019-06-19 03:10:21 +00:00
|
|
|
|
|
|
|
pts.erase( unique( pts.begin(), pts.end() ), pts.end() );
|
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
for( const wxPoint& point : pts )
|
2019-06-19 03:10:21 +00:00
|
|
|
{
|
2021-11-04 12:38:15 +00:00
|
|
|
if( m_frame->GetScreen()->IsExplicitJunctionNeeded( point ) )
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->AddJunction( m_frame->GetScreen(), point, true, false );
|
2019-06-19 03:10:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2021-04-07 09:47:03 +00:00
|
|
|
|
|
|
|
|
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() );
|
2022-02-20 00:49:26 +00:00
|
|
|
Go( &SCH_LINE_WIRE_BUS_TOOL::TrimOverLappingWires, EE_ACTIONS::trimOverlappingWires.MakeEvent() );
|
2020-12-27 12:36:11 +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
|
|
|
|
2020-12-27 12:36:11 +00:00
|
|
|
Go( &SCH_LINE_WIRE_BUS_TOOL::UnfoldBus, EE_ACTIONS::unfoldBus.MakeEvent() );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|