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
|
2022-04-01 15:42:27 +00:00
|
|
|
* Copyright (C) 2019-2022 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/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>
|
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
|
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = getToolManager()->GetTool<EE_SELECTION_TOOL>();
|
2022-08-20 09:27:35 +00:00
|
|
|
EE_SELECTION& selection = selTool->RequestSelection( { SCH_ITEM_LOCATE_BUS_T } );
|
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();
|
|
|
|
|
2023-01-20 23:17:57 +00:00
|
|
|
// Pick up the pointer again because it may have been changed by SchematicCleanUp
|
|
|
|
selection = selTool->RequestSelection( { SCH_ITEM_LOCATE_BUS_T } );
|
|
|
|
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() :
|
2022-03-17 15:26:49 +00:00
|
|
|
EE_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveDrawingLineWireBus" ),
|
|
|
|
m_inDrawingTool( false )
|
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
|
|
|
|
2022-09-03 18:29:02 +00:00
|
|
|
std::shared_ptr<BUS_UNFOLD_MENU> busUnfoldMenu = std::make_shared<BUS_UNFOLD_MENU>();
|
|
|
|
busUnfoldMenu->SetTool( this );
|
|
|
|
m_menu.RegisterSubMenu( busUnfoldMenu );
|
|
|
|
|
|
|
|
std::shared_ptr<BUS_UNFOLD_MENU> selBusUnfoldMenu = std::make_shared<BUS_UNFOLD_MENU>();
|
|
|
|
selBusUnfoldMenu->SetTool( m_selectionTool );
|
|
|
|
m_selectionTool->GetToolMenu().RegisterSubMenu( selBusUnfoldMenu );
|
|
|
|
|
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 )
|
2022-08-20 09:27:35 +00:00
|
|
|
&& EE_CONDITIONS::OnlyTypes( { SCH_ITEM_LOCATE_BUS_T } );
|
2019-05-05 14:16:29 +00:00
|
|
|
|
2022-07-10 23:14:29 +00:00
|
|
|
auto haveHighlight =
|
|
|
|
[&]( const SELECTION& sel )
|
|
|
|
{
|
|
|
|
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
|
|
|
|
|
|
|
|
return editFrame && editFrame->GetHighlightedConnection() != nullptr;
|
|
|
|
};
|
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
auto& ctxMenu = m_menu.GetMenu();
|
|
|
|
|
|
|
|
// Build the tool menu
|
|
|
|
//
|
2022-07-10 23:14:29 +00:00
|
|
|
ctxMenu.AddItem( EE_ACTIONS::clearHighlight, haveHighlight && EE_CONDITIONS::Idle, 1 );
|
|
|
|
ctxMenu.AddSeparator( haveHighlight && EE_CONDITIONS::Idle, 1 );
|
|
|
|
|
|
|
|
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 );
|
2022-07-10 23:14:29 +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 );
|
2022-03-22 16:49:38 +00:00
|
|
|
|
|
|
|
ctxMenu.AddItem( EE_ACTIONS::undoLastSegment, EE_CONDITIONS::ShowAlways, 10 );
|
|
|
|
ctxMenu.AddItem( EE_ACTIONS::switchSegmentPosture, EE_CONDITIONS::ShowAlways, 10 );
|
|
|
|
|
2022-07-10 23:14:29 +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
|
|
|
|
2022-07-10 23:14:29 +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 );
|
2022-07-10 23:14:29 +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::placeClassLabel, 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 );
|
2022-12-15 15:26:48 +00:00
|
|
|
ctxMenu.AddItem( EE_ACTIONS::slice, ( wireOrBusTool || lineTool )
|
|
|
|
&& EE_CONDITIONS::Idle, 100 );
|
2019-06-15 16:40:14 +00:00
|
|
|
ctxMenu.AddSeparator( 200 );
|
2022-07-10 23:14:29 +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();
|
|
|
|
|
2022-07-10 23:14:29 +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
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
return IsDrawingLineWireOrBus( aSelection )
|
|
|
|
&& aSelection.Front()->IsType( { SCH_ITEM_LOCATE_GRAPHIC_LINE_T } );
|
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
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
return IsDrawingLineWireOrBus( aSelection )
|
|
|
|
&& aSelection.Front()->IsType( { SCH_ITEM_LOCATE_WIRE_T } );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
return IsDrawingLineWireOrBus( aSelection )
|
|
|
|
&& aSelection.Front()->IsType( { SCH_ITEM_LOCATE_BUS_T } );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2022-03-17 15:26:49 +00:00
|
|
|
if( m_inDrawingTool )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
|
|
|
|
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
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
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 );
|
2022-01-03 18:39:49 +00:00
|
|
|
startSegments( params->layer, cursorPos, params->sourceSegment );
|
2019-06-19 15:11:41 +00:00
|
|
|
}
|
2019-06-27 11:47:24 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
return doDrawSegments( aEvent, 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
|
|
|
{
|
2022-03-17 15:26:49 +00:00
|
|
|
if( m_inDrawingTool )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
|
|
|
|
2019-05-05 14:16:29 +00:00
|
|
|
wxString* netPtr = aEvent.Parameter<wxString*>();
|
|
|
|
wxString net;
|
|
|
|
SCH_LINE* segment = nullptr;
|
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
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
|
|
|
{
|
2022-08-25 22:50:47 +00:00
|
|
|
std::optional<int> id = evt->GetCommandId();
|
2019-05-05 14:16:29 +00:00
|
|
|
|
|
|
|
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 )
|
2022-09-09 17:08:18 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
return doDrawSegments( aEvent, LAYER_WIRE, false );
|
2022-09-09 17:08:18 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-07-01 21:01:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-05-05 14:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_LINE* SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus( const wxString& aNet, const VECTOR2I& 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
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos = aPos;
|
2021-07-26 19:35:12 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
if( aPos == VECTOR2I( 0, 0 ) )
|
|
|
|
pos = static_cast<VECTOR2I>( 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 );
|
2023-02-19 03:40:07 +00:00
|
|
|
m_busUnfold.label->SetTextSize( VECTOR2I( cfg.m_DefaultTextSize, cfg.m_DefaultTextSize ) );
|
2022-01-24 13:40:39 +00:00
|
|
|
m_busUnfold.label->SetTextSpinStyle( TEXT_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
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
const SCH_SHEET_PIN* SCH_LINE_WIRE_BUS_TOOL::getSheetPin( const VECTOR2I& 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,
|
2022-03-22 16:49:38 +00:00
|
|
|
VECTOR2I& aPosition,
|
2022-06-01 15:26:33 +00:00
|
|
|
LINE_MODE mode,
|
|
|
|
bool posture )
|
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
|
|
|
|
2022-03-22 16:49:38 +00:00
|
|
|
VECTOR2I midPoint;
|
|
|
|
SCH_LINE* segment = aSegments.first;
|
|
|
|
SCH_LINE* nextSegment = aSegments.second;
|
|
|
|
|
|
|
|
VECTOR2I delta = aPosition - segment->GetStartPoint();
|
|
|
|
int xDir = delta.x > 0 ? 1 : -1;
|
|
|
|
int yDir = delta.y > 0 ? 1 : -1;
|
|
|
|
|
|
|
|
|
|
|
|
bool preferHorizontal;
|
|
|
|
bool preferVertical;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2022-06-01 15:26:33 +00:00
|
|
|
if( ( mode == LINE_MODE_45 ) && posture )
|
2022-03-22 16:49:38 +00:00
|
|
|
{
|
|
|
|
preferHorizontal = ( nextSegment->GetEndPoint().x - nextSegment->GetStartPoint().x ) != 0;
|
|
|
|
preferVertical = ( nextSegment->GetEndPoint().y - nextSegment->GetStartPoint().y ) != 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
preferHorizontal = ( segment->GetEndPoint().x - segment->GetStartPoint().x ) != 0;
|
|
|
|
preferVertical = ( segment->GetEndPoint().y - segment->GetStartPoint().y ) != 0;
|
|
|
|
}
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2022-03-22 16:49:38 +00:00
|
|
|
// Check for times we need to force horizontal sheet pin connections
|
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
|
|
|
}
|
|
|
|
|
2022-03-22 16:49:38 +00:00
|
|
|
preferHorizontal = true;
|
|
|
|
preferVertical = false;
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
2022-03-22 16:49:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
auto breakVertical = [&]() mutable
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2022-03-22 16:49:38 +00:00
|
|
|
switch( mode )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2022-03-22 16:49:38 +00:00
|
|
|
case LINE_MODE_45:
|
2022-06-01 15:26:33 +00:00
|
|
|
if( !posture )
|
|
|
|
{
|
|
|
|
midPoint.x = segment->GetStartPoint().x;
|
|
|
|
midPoint.y = aPosition.y - yDir * abs( delta.x );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
midPoint.x = aPosition.x;
|
|
|
|
midPoint.y = segment->GetStartPoint().y + yDir * abs( delta.x );
|
|
|
|
}
|
2022-03-22 16:49:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
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;
|
|
|
|
}
|
2022-03-22 16:49:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
auto breakHorizontal = [&]() mutable
|
|
|
|
{
|
|
|
|
switch( mode )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2022-03-22 16:49:38 +00:00
|
|
|
case LINE_MODE_45:
|
2022-06-01 15:26:33 +00:00
|
|
|
if( !posture )
|
|
|
|
{
|
|
|
|
midPoint.x = aPosition.x - xDir * abs( delta.y );
|
|
|
|
midPoint.y = segment->GetStartPoint().y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
midPoint.x = segment->GetStartPoint().x + xDir * abs( delta.y );
|
|
|
|
midPoint.y = aPosition.y;
|
|
|
|
}
|
2022-03-22 16:49:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
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;
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
2022-03-22 16:49:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Maintain current line shape if we can, e.g. if we were originally moving
|
|
|
|
// vertically keep the first segment vertical
|
|
|
|
if( preferVertical )
|
|
|
|
breakVertical();
|
|
|
|
else if( preferHorizontal )
|
|
|
|
breakHorizontal();
|
|
|
|
|
|
|
|
// Check if our 45 degree angle is one of these shapes
|
|
|
|
// /
|
|
|
|
// /
|
|
|
|
// /
|
|
|
|
// /__________
|
|
|
|
VECTOR2I deltaMidpoint = midPoint - segment->GetStartPoint();
|
|
|
|
|
2022-06-01 15:26:33 +00:00
|
|
|
if( mode == LINE_MODE::LINE_MODE_45 && !posture
|
2022-03-22 16:49:38 +00:00
|
|
|
&& ( ( alg::signbit( deltaMidpoint.x ) != alg::signbit( delta.x ) )
|
|
|
|
|| ( alg::signbit( deltaMidpoint.y ) != alg::signbit( delta.y ) ) ) )
|
|
|
|
{
|
|
|
|
preferVertical = false;
|
|
|
|
preferHorizontal = false;
|
|
|
|
}
|
2022-06-01 15:26:33 +00:00
|
|
|
else if( mode == LINE_MODE::LINE_MODE_45 && posture
|
2022-03-22 16:49:38 +00:00
|
|
|
&& ( ( abs( deltaMidpoint.x ) > abs( delta.x ) )
|
|
|
|
|| ( abs( deltaMidpoint.y ) > abs( delta.y ) ) ) )
|
|
|
|
{
|
|
|
|
preferVertical = false;
|
|
|
|
preferHorizontal = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !preferHorizontal && !preferVertical )
|
|
|
|
{
|
|
|
|
if( std::abs( delta.x ) < std::abs( delta.y ) )
|
|
|
|
breakVertical();
|
|
|
|
else
|
|
|
|
breakHorizontal();
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
segment->SetEndPoint( midPoint );
|
2022-03-22 16:49:38 +00:00
|
|
|
nextSegment->SetStartPoint( midPoint );
|
|
|
|
nextSegment->SetEndPoint( aPosition );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const TOOL_EVENT& 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-03-22 16:49:38 +00:00
|
|
|
int lastMode = m_frame->eeconfig()->m_Drawing.line_mode;
|
2022-06-01 15:26:33 +00:00
|
|
|
static bool posture = false;
|
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();
|
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I contextMenuPos;
|
2020-12-27 18:07:16 +00:00
|
|
|
|
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
|
|
|
{
|
2022-03-22 16:49:38 +00:00
|
|
|
LINE_MODE currentMode = (LINE_MODE) m_frame->eeconfig()->m_Drawing.line_mode;
|
2022-06-09 15:53:24 +00:00
|
|
|
bool twoSegments = currentMode != LINE_MODE::LINE_MODE_FREE;
|
|
|
|
|
|
|
|
// The tool hotkey is interpreted as a click when drawing
|
2022-09-14 17:31:56 +00:00
|
|
|
bool isSyntheticClick = ( segment || m_busUnfold.in_progress ) && evt->IsActivate()
|
|
|
|
&& evt->HasPosition() && evt->Matches( aTool );
|
2022-03-22 16:49:38 +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 );
|
|
|
|
}
|
|
|
|
|
2022-05-02 21:26:55 +00:00
|
|
|
VECTOR2D eventPosition = evt->HasPosition() ? evt->Position()
|
|
|
|
: controls->GetMousePosition();
|
2020-12-03 15:10:23 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I cursorPos = grid.BestSnapAnchor( eventPosition, 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
|
2022-03-22 16:49:38 +00:00
|
|
|
if( currentMode != lastMode )
|
2022-02-16 15:06:17 +00:00
|
|
|
{
|
|
|
|
// Need to delete extra segment if we have one
|
2022-06-09 15:53:24 +00:00
|
|
|
if( segment && currentMode == LINE_MODE::LINE_MODE_FREE && m_wires.size() >= 2 )
|
2022-02-16 15:06:17 +00:00
|
|
|
{
|
|
|
|
m_wires.pop_back();
|
|
|
|
m_selectionTool->RemoveItemFromSel( segment );
|
|
|
|
delete segment;
|
|
|
|
|
|
|
|
segment = m_wires.back();
|
|
|
|
segment->SetEndPoint( cursorPos );
|
|
|
|
}
|
2022-03-22 16:49:38 +00:00
|
|
|
// Add a segment so we can move orthogonally/45
|
2022-06-09 15:53:24 +00:00
|
|
|
else if( segment && lastMode == LINE_MODE::LINE_MODE_FREE )
|
2022-02-16 15:06:17 +00:00
|
|
|
{
|
|
|
|
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*/ );
|
|
|
|
}
|
2022-03-22 16:49:38 +00:00
|
|
|
|
|
|
|
lastMode = currentMode;
|
2022-02-16 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 20:08:58 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Handle cancel:
|
|
|
|
//
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
|
|
|
{
|
2022-03-17 15:26:49 +00:00
|
|
|
m_frame->GetInfoBar()->Dismiss();
|
|
|
|
|
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();
|
2022-11-04 17:34:43 +00:00
|
|
|
|
|
|
|
if( aQuitOnDraw )
|
|
|
|
{
|
|
|
|
m_frame->PopTool( aTool );
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
}
|
2022-06-09 15:53:24 +00:00
|
|
|
else if( evt->IsActivate() && !isSyntheticClick )
|
2019-07-01 21:01:33 +00:00
|
|
|
{
|
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:
|
|
|
|
//
|
2022-06-09 15:53:24 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT )
|
|
|
|
|| ( segment && evt->IsDblClick( BUT_LEFT ) )
|
|
|
|
|| isSyntheticClick )
|
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
|
2022-03-22 16:49:38 +00:00
|
|
|
else if( !segment->IsNull()
|
|
|
|
|| ( twoSegments && !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
|
|
|
|
{
|
2022-03-22 16:49:38 +00:00
|
|
|
int placedSegments = 1;
|
|
|
|
|
|
|
|
// When placing lines with the forty-five degree end, the user is
|
|
|
|
// targetting the endpoint with the angled portion, so it's more
|
|
|
|
// intuitive to place both segments at the same time.
|
2022-06-01 15:26:33 +00:00
|
|
|
if( currentMode == LINE_MODE::LINE_MODE_45 )
|
2022-03-22 16:49:38 +00:00
|
|
|
placedSegments++;
|
|
|
|
|
2019-12-11 13:22:59 +00:00
|
|
|
segment->SetEndPoint( cursorPos );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2022-03-22 16:49:38 +00:00
|
|
|
for( int i = 0; i < placedSegments; i++ )
|
|
|
|
{
|
|
|
|
// 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 );
|
2019-05-03 08:48:53 +00:00
|
|
|
|
2022-03-22 16:49:38 +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
|
|
|
{
|
2022-03-22 16:49:38 +00:00
|
|
|
if( twoSegments && m_wires.size() >= 2 )
|
|
|
|
computeBreakPoint( { m_wires[m_wires.size() - 2], segment }, cursorPos,
|
2022-06-01 15:26:33 +00:00
|
|
|
currentMode, posture );
|
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 )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I cursor_delta = cursorPos - m_busUnfold.origin;
|
2019-05-02 15:01:51 +00:00
|
|
|
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
|
|
|
{
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I size = entry->GetSize();
|
2020-07-09 22:51:42 +00:00
|
|
|
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
|
|
|
{
|
2022-03-22 16:49:38 +00:00
|
|
|
// Coerce the line to vertical/horizontal/45 as necessary
|
|
|
|
if( twoSegments && m_wires.size() >= 2 )
|
2022-05-02 21:26:55 +00:00
|
|
|
{
|
2022-03-22 16:49:38 +00:00
|
|
|
computeBreakPoint( { m_wires[m_wires.size() - 2], segment }, cursorPos,
|
2022-06-01 15:26:33 +00:00
|
|
|
currentMode, posture );
|
2022-05-02 21:26:55 +00:00
|
|
|
}
|
2019-05-02 15:01:51 +00:00
|
|
|
else
|
2022-05-02 21:26:55 +00:00
|
|
|
{
|
2019-12-11 13:22:59 +00:00
|
|
|
segment->SetEndPoint( cursorPos );
|
2022-05-02 21:26:55 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
2022-03-22 16:49:38 +00:00
|
|
|
else if( evt->IsAction( &EE_ACTIONS::undoLastSegment ) )
|
|
|
|
{
|
|
|
|
if( ( currentMode == LINE_MODE::LINE_MODE_FREE && m_wires.size() > 1 )
|
|
|
|
|| ( LINE_MODE::LINE_MODE_90 && m_wires.size() > 2 ) )
|
|
|
|
{
|
|
|
|
m_view->ClearPreview();
|
|
|
|
|
|
|
|
m_wires.pop_back();
|
|
|
|
m_selectionTool->RemoveItemFromSel( segment );
|
|
|
|
delete segment;
|
|
|
|
|
|
|
|
segment = m_wires.back();
|
|
|
|
segment->SetEndPoint( cursorPos );
|
|
|
|
|
|
|
|
// Find new bend point for current mode
|
2022-04-01 15:42:27 +00:00
|
|
|
if( twoSegments && m_wires.size() >= 2 )
|
2022-05-02 21:26:55 +00:00
|
|
|
{
|
2022-04-01 15:42:27 +00:00
|
|
|
computeBreakPoint( { m_wires[m_wires.size() - 2], segment }, cursorPos,
|
2022-06-01 15:26:33 +00:00
|
|
|
currentMode, posture );
|
2022-05-02 21:26:55 +00:00
|
|
|
}
|
2022-04-01 15:42:27 +00:00
|
|
|
else
|
2022-05-02 21:26:55 +00:00
|
|
|
{
|
2022-04-01 15:42:27 +00:00
|
|
|
segment->SetEndPoint( cursorPos );
|
2022-05-02 21:26:55 +00:00
|
|
|
}
|
2022-03-22 16:49:38 +00:00
|
|
|
|
|
|
|
for( SCH_LINE* wire : m_wires )
|
|
|
|
{
|
|
|
|
if( !wire->IsNull() )
|
|
|
|
m_view->AddToPreview( wire->Clone() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
|
|
|
}
|
2022-06-01 15:26:33 +00:00
|
|
|
else if( evt->IsAction( &EE_ACTIONS::switchSegmentPosture ) && m_wires.size() >= 2 )
|
2022-03-22 16:49:38 +00:00
|
|
|
{
|
2022-06-01 15:26:33 +00:00
|
|
|
posture = !posture;
|
|
|
|
|
2022-03-22 16:49:38 +00:00
|
|
|
// The 90 degree mode doesn't have a forced posture like
|
2022-06-01 15:26:33 +00:00
|
|
|
// the 45 degree mode and computeBreakPoint maintains existing 90s' postures.
|
|
|
|
// Instead, just swap the 90 angle here.
|
|
|
|
if( currentMode == LINE_MODE::LINE_MODE_90 )
|
2022-03-22 16:49:38 +00:00
|
|
|
{
|
|
|
|
m_view->ClearPreview();
|
|
|
|
|
|
|
|
SCH_LINE* line2 = m_wires[m_wires.size() - 1];
|
|
|
|
SCH_LINE* line1 = m_wires[m_wires.size() - 2];
|
|
|
|
|
|
|
|
VECTOR2I delta2 = line2->GetEndPoint() - line2->GetStartPoint();
|
|
|
|
VECTOR2I delta1 = line1->GetEndPoint() - line1->GetStartPoint();
|
|
|
|
|
|
|
|
line2->SetStartPoint(line2->GetEndPoint() - delta1);
|
|
|
|
line1->SetEndPoint(line1->GetStartPoint() + delta2);
|
|
|
|
|
|
|
|
for( SCH_LINE* wire : m_wires )
|
|
|
|
{
|
|
|
|
if( !wire->IsNull() )
|
|
|
|
m_view->AddToPreview( wire->Clone() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-01 15:26:33 +00:00
|
|
|
computeBreakPoint( { m_wires[m_wires.size() - 2], segment }, cursorPos, currentMode,
|
|
|
|
posture );
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
2022-03-22 16:49:38 +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();
|
|
|
|
|
2023-02-19 03:40:07 +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
|
|
|
{
|
2022-08-30 20:58:43 +00:00
|
|
|
if( *evt->GetCommandId() >= ID_POPUP_SCH_UNFOLD_BUS
|
|
|
|
&& *evt->GetCommandId() <= ID_POPUP_SCH_UNFOLD_BUS_END )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
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*>();
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-03 18:39:49 +00:00
|
|
|
SCH_LINE* SCH_LINE_WIRE_BUS_TOOL::startSegments( int aType, const VECTOR2D& aPos,
|
|
|
|
SCH_LINE* aSegment )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2022-01-03 18:39:49 +00:00
|
|
|
// If a segment isn't provided to copy properties from, we need to create one
|
|
|
|
if( aSegment == nullptr )
|
|
|
|
{
|
|
|
|
switch( aType )
|
|
|
|
{
|
2022-05-02 21:26:55 +00:00
|
|
|
default: aSegment = new SCH_LINE( aPos, LAYER_NOTES ); break;
|
|
|
|
case LAYER_WIRE: aSegment = new SCH_LINE( aPos, LAYER_WIRE ); break;
|
|
|
|
case LAYER_BUS: aSegment = new SCH_LINE( aPos, LAYER_BUS ); break;
|
2022-01-03 18:39:49 +00:00
|
|
|
}
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2022-01-03 18:39:49 +00:00
|
|
|
// Give segments a parent so they find the default line/wire/bus widths
|
|
|
|
aSegment->SetParent( &m_frame->Schematic() );
|
|
|
|
}
|
|
|
|
else
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2022-01-03 18:39:49 +00:00
|
|
|
aSegment = static_cast<SCH_LINE*>( aSegment->Duplicate() );
|
2022-08-30 14:13:51 +00:00
|
|
|
aSegment->SetStartPoint( aPos );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 08:48:53 +00:00
|
|
|
|
2022-01-03 18:39:49 +00:00
|
|
|
aSegment->SetFlags( IS_NEW | IS_MOVING );
|
|
|
|
m_wires.push_back( aSegment );
|
|
|
|
|
|
|
|
m_selectionTool->AddItemToSel( aSegment, true /*quiet mode*/ );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
// 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.
|
2022-03-22 16:49:38 +00:00
|
|
|
if( m_frame->eeconfig()->m_Drawing.line_mode )
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
2022-01-03 18:39:49 +00:00
|
|
|
aSegment = static_cast<SCH_LINE*>( aSegment->Duplicate() );
|
|
|
|
aSegment->SetFlags( IS_NEW | IS_MOVING );
|
|
|
|
m_wires.push_back( aSegment );
|
2019-05-03 08:48:53 +00:00
|
|
|
|
2022-01-03 18:39:49 +00:00
|
|
|
m_selectionTool->AddItemToSel( aSegment, true /*quiet mode*/ );
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 18:39:49 +00:00
|
|
|
return aSegment;
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2022-08-18 18:40:25 +00:00
|
|
|
std::vector<VECTOR2I> connections = screen->GetConnections();
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> new_ends;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> tmpends = wire->GetConnectionPoints();
|
2020-09-08 13:27:13 +00:00
|
|
|
|
|
|
|
new_ends.insert( new_ends.end(), tmpends.begin(), tmpends.end() );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
for( const VECTOR2I& 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
|
|
|
}
|
2022-09-09 17:08:18 +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 ) );
|
2022-09-09 17:08:18 +00:00
|
|
|
m_frame->SaveCopyForRepeatItem( m_busUnfold.entry );
|
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
itemList.PushItem( ITEM_PICKER( screen, m_busUnfold.label, UNDO_REDO::NEWITEM ) );
|
2022-09-09 17:08:18 +00:00
|
|
|
m_frame->AddCopyForRepeatItem( m_busUnfold.label );
|
2019-12-02 13:30:22 +00:00
|
|
|
m_busUnfold.label->ClearEditFlags();
|
2019-05-02 15:01:51 +00:00
|
|
|
}
|
2022-09-09 17:08:18 +00:00
|
|
|
else if( !m_wires.empty() )
|
|
|
|
{
|
|
|
|
m_frame->SaveCopyForRepeatItem( m_wires[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( size_t ii = 1; ii < m_wires.size(); ++ii )
|
|
|
|
m_frame->AddCopyForRepeatItem( m_wires[ii] );
|
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() )
|
2022-09-09 17:08:18 +00:00
|
|
|
m_frame->AddCopyForRepeatItem( 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
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
for( const VECTOR2I& 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 = {};
|
|
|
|
|
2023-01-05 18:04:36 +00:00
|
|
|
for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
|
|
|
|
item->ClearEditFlags();
|
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-06 22:14:06 +00:00
|
|
|
int SCH_LINE_WIRE_BUS_TOOL::TrimOverLappingWires( EE_SELECTION* aSelection )
|
2022-02-20 00:49:26 +00:00
|
|
|
{
|
|
|
|
SCHEMATIC* sch = getModel<SCHEMATIC>();
|
|
|
|
SCH_SCREEN* screen = sch->CurrentSheet().LastScreen();
|
|
|
|
|
|
|
|
std::set<SCH_LINE*> lines;
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bb = aSelection->GetBoundingBox();
|
2022-02-20 00:49:26 +00:00
|
|
|
|
|
|
|
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 ) );
|
|
|
|
|
|
|
|
if( !item || !item->IsConnectable() || ( item->Type() == SCH_LINE_T ) )
|
|
|
|
continue;
|
|
|
|
|
2022-03-06 08:48:33 +00:00
|
|
|
std::vector<VECTOR2I> pts = item->GetConnectionPoints();
|
|
|
|
|
2022-02-20 00:49:26 +00:00
|
|
|
/// 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 )
|
|
|
|
{
|
2022-02-20 03:14:41 +00:00
|
|
|
std::vector<VECTOR2I> conn_pts;
|
2022-02-20 00:49:26 +00:00
|
|
|
|
2022-02-20 03:14:41 +00:00
|
|
|
for( VECTOR2I pt : pts )
|
2022-02-20 00:49:26 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-06 22:14:06 +00:00
|
|
|
int SCH_LINE_WIRE_BUS_TOOL::AddJunctionsIfNeeded( EE_SELECTION* aSelection )
|
2019-06-19 03:10:21 +00:00
|
|
|
{
|
2022-08-18 18:40:25 +00:00
|
|
|
SCH_SCREEN* screen = m_frame->GetScreen();
|
|
|
|
|
2022-08-18 19:52:31 +00:00
|
|
|
for( const VECTOR2I& point : screen->GetNeededJunctions( aSelection->Items() ) )
|
|
|
|
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
|
|
|
{
|
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
|
|
|
}
|