2011-10-19 20:32:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-03-19 07:48:29 +00:00
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr
|
2021-01-23 21:39:57 +00:00
|
|
|
* Copyright (C) 2004-2021 KiCad Developers, see change_log.txt for contributors.
|
2011-10-19 20:32:21 +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-25 23:39:58 +00:00
|
|
|
#include <core/kicad_algo.h>
|
|
|
|
#include <eeschema_id.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <lib_item.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_bus_entry.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_no_connect.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <sch_screen.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_sheet.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_view.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <tools/ee_actions.h>
|
|
|
|
#include <tools/ee_selection_tool.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
std::vector<wxPoint> SCH_EDIT_FRAME::GetSchematicConnections()
|
2017-11-27 19:27:24 +00:00
|
|
|
{
|
2020-09-08 13:27:13 +00:00
|
|
|
std::vector<wxPoint> retval;
|
|
|
|
|
2021-02-23 12:49:02 +00:00
|
|
|
for( SCH_ITEM* item : GetScreen()->Items() )
|
2018-01-23 20:29:15 +00:00
|
|
|
{
|
|
|
|
// Avoid items that are changing
|
2021-05-30 21:04:07 +00:00
|
|
|
if( !( item->GetEditFlags() & ( IS_DRAGGING | IS_MOVING | IS_DELETED ) ) )
|
2020-09-08 13:27:13 +00:00
|
|
|
{
|
|
|
|
std::vector<wxPoint> pts = item->GetConnectionPoints();
|
|
|
|
retval.insert( retval.end(), pts.begin(), pts.end() );
|
|
|
|
}
|
2018-01-23 20:29:15 +00:00
|
|
|
}
|
2017-11-27 19:27:24 +00:00
|
|
|
|
|
|
|
// We always have some overlapping connection points. Drop duplicates here
|
2020-09-08 13:27:13 +00:00
|
|
|
std::sort( retval.begin(), retval.end(),
|
2017-12-02 13:22:43 +00:00
|
|
|
[]( const wxPoint& a, const wxPoint& b ) -> bool
|
2017-11-27 19:27:24 +00:00
|
|
|
{ return a.x < b.x || (a.x == b.x && a.y < b.y); } );
|
2020-09-08 13:27:13 +00:00
|
|
|
retval.erase(
|
|
|
|
std::unique( retval.begin(), retval.end() ), retval.end() );
|
|
|
|
|
|
|
|
return retval;
|
2017-11-27 19:27:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-06 21:23:16 +00:00
|
|
|
void SCH_EDIT_FRAME::TestDanglingEnds()
|
2018-10-16 13:11:33 +00:00
|
|
|
{
|
2020-12-06 21:23:16 +00:00
|
|
|
std::function<void( SCH_ITEM* )> changeHandler =
|
|
|
|
[&]( SCH_ITEM* aChangedItem ) -> void
|
|
|
|
{
|
|
|
|
GetCanvas()->GetView()->Update( aChangedItem, KIGFX::REPAINT );
|
|
|
|
};
|
2018-10-16 13:11:33 +00:00
|
|
|
|
2020-12-06 21:23:16 +00:00
|
|
|
GetScreen()->TestDanglingEnds( nullptr, &changeHandler );
|
2018-10-16 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
bool SCH_EDIT_FRAME::TrimWire( const wxPoint& aStart, const wxPoint& aEnd )
|
2017-12-01 22:53:23 +00:00
|
|
|
{
|
2020-07-13 11:21:40 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
bool retval = false;
|
2017-12-01 22:53:23 +00:00
|
|
|
|
2021-01-23 21:39:57 +00:00
|
|
|
std::vector<SCH_LINE*> wires;
|
|
|
|
EDA_RECT bb( aStart, wxSize( 1, 1 ) );
|
|
|
|
|
|
|
|
bb.Merge( aEnd );
|
|
|
|
|
2017-12-01 22:53:23 +00:00
|
|
|
if( aStart == aEnd )
|
2017-12-29 20:01:56 +00:00
|
|
|
return retval;
|
2017-12-01 22:53:23 +00:00
|
|
|
|
2021-01-23 21:39:57 +00:00
|
|
|
// We cannot modify the RTree while iterating, so push the possible
|
|
|
|
// wires into a separate structure.
|
|
|
|
for( EDA_ITEM* item : screen->Items().Overlapping( bb ) )
|
2017-12-01 22:53:23 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( item );
|
2017-12-29 20:01:56 +00:00
|
|
|
|
2021-01-23 21:39:57 +00:00
|
|
|
if( item->Type() == SCH_LINE_T && line->GetLayer() == LAYER_WIRE )
|
|
|
|
wires.push_back( line );
|
|
|
|
}
|
2017-12-01 22:53:23 +00:00
|
|
|
|
2021-01-23 21:39:57 +00:00
|
|
|
for( SCH_LINE* line : wires )
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
// Don't remove wires that are already deleted or are currently being dragged
|
2021-05-30 21:04:07 +00:00
|
|
|
if( line->GetEditFlags() & ( STRUCT_DELETED | IS_DRAGGING | IS_MOVING | SKIP_STRUCT ) )
|
2017-12-01 22:53:23 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !IsPointOnSegment( line->GetStartPoint(), line->GetEndPoint(), aStart ) ||
|
|
|
|
!IsPointOnSegment( line->GetStartPoint(), line->GetEndPoint(), aEnd ) )
|
2018-11-20 21:44:11 +00:00
|
|
|
{
|
2017-12-01 22:53:23 +00:00
|
|
|
continue;
|
2018-11-20 21:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't remove entire wires
|
|
|
|
if( ( line->GetStartPoint() == aStart && line->GetEndPoint() == aEnd )
|
|
|
|
|| ( line->GetStartPoint() == aEnd && line->GetEndPoint() == aStart ) )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2017-12-01 22:53:23 +00:00
|
|
|
|
|
|
|
// Step 1: break the segment on one end. return_line remains line if not broken.
|
|
|
|
// Ensure that *line points to the segment containing aEnd
|
|
|
|
SCH_LINE* return_line = line;
|
2019-05-11 10:06:28 +00:00
|
|
|
BreakSegment( line, aStart, &return_line );
|
2020-07-13 11:21:40 +00:00
|
|
|
|
2017-12-01 22:53:23 +00:00
|
|
|
if( IsPointOnSegment( return_line->GetStartPoint(), return_line->GetEndPoint(), aEnd ) )
|
|
|
|
line = return_line;
|
|
|
|
|
|
|
|
// Step 2: break the remaining segment. return_line remains line if not broken.
|
|
|
|
// Ensure that *line _also_ contains aStart. This is our overlapping segment
|
2019-05-11 10:06:28 +00:00
|
|
|
BreakSegment( line, aEnd, &return_line );
|
2020-07-13 11:21:40 +00:00
|
|
|
|
2017-12-01 22:53:23 +00:00
|
|
|
if( IsPointOnSegment( return_line->GetStartPoint(), return_line->GetEndPoint(), aStart ) )
|
|
|
|
line = return_line;
|
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
SaveCopyInUndoList( screen, line, UNDO_REDO::DELETED, true );
|
2020-07-13 11:21:40 +00:00
|
|
|
RemoveFromScreen( line, screen );
|
2019-03-18 02:07:32 +00:00
|
|
|
|
2017-12-29 20:01:56 +00:00
|
|
|
retval = true;
|
2017-12-01 22:53:23 +00:00
|
|
|
}
|
2017-12-29 20:01:56 +00:00
|
|
|
|
|
|
|
return retval;
|
2017-12-01 22:53:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
bool SCH_EDIT_FRAME::SchematicCleanUp( SCH_SCREEN* aScreen )
|
2017-10-25 22:21:42 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
PICKED_ITEMS_LIST itemList;
|
|
|
|
EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
std::vector<SCH_ITEM*> deletedItems;
|
|
|
|
std::vector<SCH_LINE*> lines;
|
|
|
|
std::vector<SCH_JUNCTION*> junctions;
|
|
|
|
std::vector<SCH_NO_CONNECT*> ncs;
|
2020-08-20 13:48:01 +00:00
|
|
|
bool changed = true;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
if( aScreen == nullptr )
|
|
|
|
aScreen = GetScreen();
|
2017-10-25 22:21:42 +00:00
|
|
|
|
2020-08-20 13:48:01 +00:00
|
|
|
auto remove_item = [&]( SCH_ITEM* aItem ) -> void
|
2020-07-13 11:21:40 +00:00
|
|
|
{
|
2020-08-20 13:48:01 +00:00
|
|
|
changed = true;
|
2020-07-13 11:21:40 +00:00
|
|
|
aItem->SetFlags( STRUCT_DELETED );
|
2020-08-26 18:04:32 +00:00
|
|
|
itemList.PushItem( ITEM_PICKER( aScreen, aItem, UNDO_REDO::DELETED ) );
|
2020-07-13 11:21:40 +00:00
|
|
|
deletedItems.push_back( aItem );
|
|
|
|
};
|
2017-11-27 19:27:24 +00:00
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
BreakSegmentsOnJunctions( aScreen );
|
2017-11-27 19:27:24 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_JUNCTION_T ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
if( !aScreen->IsJunctionNeeded( item->GetPosition() ) )
|
2017-11-27 19:27:24 +00:00
|
|
|
remove_item( item );
|
2019-06-25 23:39:58 +00:00
|
|
|
else
|
|
|
|
junctions.push_back( static_cast<SCH_JUNCTION*>( item ) );
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_NO_CONNECT_T ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
ncs.push_back( static_cast<SCH_NO_CONNECT*>( item ) );
|
|
|
|
}
|
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
alg::for_all_pairs( junctions.begin(), junctions.end(),
|
|
|
|
[&]( SCH_JUNCTION* aFirst, SCH_JUNCTION* aSecond )
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
if( ( aFirst->GetEditFlags() & STRUCT_DELETED )
|
|
|
|
|| ( aSecond->GetEditFlags() & STRUCT_DELETED ) )
|
2020-08-10 11:40:58 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
return;
|
2020-08-10 11:40:58 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
|
|
|
|
if( aFirst->GetPosition() == aSecond->GetPosition() )
|
|
|
|
remove_item( aSecond );
|
|
|
|
} );
|
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
alg::for_all_pairs( ncs.begin(), ncs.end(),
|
|
|
|
[&]( SCH_NO_CONNECT* aFirst, SCH_NO_CONNECT* aSecond )
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
if( ( aFirst->GetEditFlags() & STRUCT_DELETED )
|
|
|
|
|| ( aSecond->GetEditFlags() & STRUCT_DELETED ) )
|
2020-08-10 11:40:58 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
return;
|
2020-08-10 11:40:58 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
|
|
|
|
if( aFirst->GetPosition() == aSecond->GetPosition() )
|
|
|
|
remove_item( aSecond );
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
2020-08-20 13:48:01 +00:00
|
|
|
while( changed )
|
|
|
|
{
|
|
|
|
changed = false;
|
|
|
|
lines.clear();
|
2017-12-13 05:12:06 +00:00
|
|
|
|
2020-08-20 13:48:01 +00:00
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_LINE_T ) )
|
2017-11-27 19:27:24 +00:00
|
|
|
{
|
2020-08-20 13:48:01 +00:00
|
|
|
if( item->GetLayer() == LAYER_WIRE || item->GetLayer() == LAYER_BUS )
|
|
|
|
lines.push_back( static_cast<SCH_LINE*>( item ) );
|
2017-11-27 19:27:24 +00:00
|
|
|
}
|
2017-10-25 22:21:42 +00:00
|
|
|
|
2020-08-20 13:48:01 +00:00
|
|
|
for( auto it1 = lines.begin(); it1 != lines.end(); ++it1 )
|
2017-11-27 19:27:24 +00:00
|
|
|
{
|
2020-08-20 13:48:01 +00:00
|
|
|
SCH_LINE* firstLine = *it1;
|
2017-11-27 19:27:24 +00:00
|
|
|
|
2020-08-20 13:48:01 +00:00
|
|
|
if( firstLine->GetEditFlags() & STRUCT_DELETED )
|
2019-06-25 23:39:58 +00:00
|
|
|
continue;
|
2017-11-27 19:27:24 +00:00
|
|
|
|
2020-08-20 13:48:01 +00:00
|
|
|
if( firstLine->IsNull() )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2020-08-20 13:48:01 +00:00
|
|
|
remove_item( firstLine );
|
2019-06-25 23:39:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-12-13 05:12:06 +00:00
|
|
|
|
2020-08-20 13:48:01 +00:00
|
|
|
auto it2 = it1;
|
2019-09-12 19:08:35 +00:00
|
|
|
|
2020-08-20 13:48:01 +00:00
|
|
|
for( ++it2; it2 != lines.end(); ++it2 )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2020-08-20 13:48:01 +00:00
|
|
|
SCH_LINE* secondLine = *it2;
|
|
|
|
|
|
|
|
if( secondLine->GetFlags() & STRUCT_DELETED )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !secondLine->IsParallel( firstLine )
|
2020-10-21 17:41:44 +00:00
|
|
|
|| !secondLine->IsStrokeEquivalent( firstLine )
|
2020-08-20 13:48:01 +00:00
|
|
|
|| secondLine->GetLayer() != firstLine->GetLayer() )
|
2020-10-21 16:23:19 +00:00
|
|
|
{
|
2020-08-20 13:48:01 +00:00
|
|
|
continue;
|
2020-10-21 16:23:19 +00:00
|
|
|
}
|
2020-08-20 13:48:01 +00:00
|
|
|
|
|
|
|
// Remove identical lines
|
|
|
|
if( firstLine->IsEndPoint( secondLine->GetStartPoint() )
|
|
|
|
&& firstLine->IsEndPoint( secondLine->GetEndPoint() ) )
|
|
|
|
{
|
|
|
|
remove_item( secondLine );
|
|
|
|
continue;
|
|
|
|
}
|
2019-09-12 19:08:35 +00:00
|
|
|
|
2020-10-21 17:41:44 +00:00
|
|
|
// See if we can merge an overlap (or two colinear touching segments with
|
|
|
|
// no junction where they meet).
|
2020-10-24 04:50:02 +00:00
|
|
|
SCH_LINE* mergedLine = secondLine->MergeOverlap( aScreen, firstLine, true );
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2020-10-24 04:50:02 +00:00
|
|
|
if( mergedLine != nullptr )
|
2020-08-20 13:48:01 +00:00
|
|
|
{
|
|
|
|
remove_item( firstLine );
|
|
|
|
remove_item( secondLine );
|
2020-08-26 18:04:32 +00:00
|
|
|
itemList.PushItem( ITEM_PICKER( aScreen, mergedLine, UNDO_REDO::NEWITEM ) );
|
2020-08-20 13:48:01 +00:00
|
|
|
|
|
|
|
AddToScreen( mergedLine, aScreen );
|
|
|
|
|
|
|
|
if( firstLine->IsSelected() )
|
|
|
|
selectionTool->AddItemToSel( mergedLine, true /*quiet mode*/ );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2017-10-25 22:21:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-13 05:12:06 +00:00
|
|
|
|
2021-02-23 12:49:02 +00:00
|
|
|
for( SCH_ITEM* item : deletedItems )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
if( item->IsSelected() )
|
|
|
|
selectionTool->RemoveItemFromSel( item, true /*quiet mode*/ );
|
2019-09-12 19:08:35 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
RemoveFromScreen( item, aScreen );
|
2019-03-23 21:34:27 +00:00
|
|
|
}
|
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
if( itemList.GetCount() )
|
2020-08-26 18:04:32 +00:00
|
|
|
SaveCopyInUndoList( itemList, UNDO_REDO::DELETED, true );
|
2019-03-23 21:34:27 +00:00
|
|
|
|
|
|
|
return itemList.GetCount() > 0;
|
|
|
|
}
|
2019-03-18 02:07:32 +00:00
|
|
|
|
2019-03-23 21:34:27 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
bool SCH_EDIT_FRAME::BreakSegment( SCH_LINE* aSegment, const wxPoint& aPoint,
|
2019-05-11 10:06:28 +00:00
|
|
|
SCH_LINE** aNewSegment, SCH_SCREEN* aScreen )
|
2017-10-26 15:25:47 +00:00
|
|
|
{
|
2019-03-11 21:32:05 +00:00
|
|
|
if( aScreen == nullptr )
|
|
|
|
aScreen = GetScreen();
|
|
|
|
|
2017-10-26 15:25:47 +00:00
|
|
|
SCH_LINE* newSegment = new SCH_LINE( *aSegment );
|
|
|
|
|
|
|
|
newSegment->SetStartPoint( aPoint );
|
2019-03-11 21:32:05 +00:00
|
|
|
AddToScreen( newSegment, aScreen );
|
2017-10-26 15:25:47 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
SaveCopyInUndoList( aScreen, newSegment, UNDO_REDO::NEWITEM, true );
|
|
|
|
SaveCopyInUndoList( aScreen, aSegment, UNDO_REDO::CHANGED, true );
|
2019-03-18 02:07:32 +00:00
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
UpdateItem( aSegment );
|
2018-10-24 22:18:53 +00:00
|
|
|
aSegment->SetEndPoint( aPoint );
|
|
|
|
|
2017-12-01 22:53:23 +00:00
|
|
|
if( aNewSegment )
|
|
|
|
*aNewSegment = newSegment;
|
|
|
|
|
2017-10-26 15:25:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
bool SCH_EDIT_FRAME::BreakSegments( const wxPoint& aPoint, SCH_SCREEN* aScreen )
|
2017-10-26 15:25:47 +00:00
|
|
|
{
|
2020-04-02 17:03:53 +00:00
|
|
|
static const KICAD_T wiresAndBuses[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T, EOT };
|
2019-05-11 10:06:28 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
if( aScreen == nullptr )
|
|
|
|
aScreen = GetScreen();
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
bool brokenSegments = false;
|
|
|
|
std::vector<SCH_LINE*> wires;
|
2017-10-26 15:25:47 +00:00
|
|
|
|
2021-02-23 12:49:02 +00:00
|
|
|
for( SCH_ITEM* item : aScreen->Items().Overlapping( SCH_LINE_T, aPoint ) )
|
2017-10-26 15:25:47 +00:00
|
|
|
{
|
2020-04-02 17:03:53 +00:00
|
|
|
if( item->IsType( wiresAndBuses ) )
|
2021-02-16 18:09:56 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* wire = static_cast<SCH_LINE*>( item );
|
|
|
|
|
|
|
|
if( IsPointOnSegment( wire->GetStartPoint(), wire->GetEndPoint(), aPoint )
|
2021-07-16 20:13:26 +00:00
|
|
|
&& !wire->IsEndPoint( aPoint ) )
|
2021-02-16 18:09:56 +00:00
|
|
|
{
|
|
|
|
wires.push_back( wire );
|
|
|
|
}
|
|
|
|
}
|
2017-10-26 15:25:47 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 12:49:02 +00:00
|
|
|
for( SCH_LINE* wire : wires )
|
2021-07-16 20:13:26 +00:00
|
|
|
brokenSegments |= BreakSegment( wire, aPoint, nullptr, aScreen );
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2017-10-26 15:25:47 +00:00
|
|
|
return brokenSegments;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
bool SCH_EDIT_FRAME::BreakSegmentsOnJunctions( SCH_SCREEN* aScreen )
|
2017-10-26 15:25:47 +00:00
|
|
|
{
|
2019-03-11 21:32:05 +00:00
|
|
|
if( aScreen == nullptr )
|
|
|
|
aScreen = GetScreen();
|
|
|
|
|
2017-10-26 15:25:47 +00:00
|
|
|
bool brokenSegments = false;
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
std::set<wxPoint> point_set;
|
2020-04-24 13:36:10 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_JUNCTION_T ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
point_set.insert( item->GetPosition() );
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_BUS_WIRE_ENTRY_T ) )
|
2017-10-26 15:25:47 +00:00
|
|
|
{
|
2020-04-24 13:36:10 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* entry = static_cast<SCH_BUS_WIRE_ENTRY*>( item );
|
2019-06-25 23:39:58 +00:00
|
|
|
point_set.insert( entry->GetPosition() );
|
2020-09-08 13:27:13 +00:00
|
|
|
point_set.insert( entry->GetEnd() );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2017-10-26 15:25:47 +00:00
|
|
|
|
2019-04-13 02:53:41 +00:00
|
|
|
|
2021-02-23 12:49:02 +00:00
|
|
|
for( const wxPoint& pt : point_set )
|
2019-06-25 23:39:58 +00:00
|
|
|
brokenSegments |= BreakSegments( pt, aScreen );
|
2017-10-26 15:25:47 +00:00
|
|
|
|
|
|
|
return brokenSegments;
|
|
|
|
}
|
|
|
|
|
2017-10-25 22:21:42 +00:00
|
|
|
|
2018-02-02 20:04:36 +00:00
|
|
|
void SCH_EDIT_FRAME::DeleteJunction( SCH_ITEM* aJunction, bool aAppend )
|
|
|
|
{
|
2019-09-12 19:08:35 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
2019-09-19 18:10:32 +00:00
|
|
|
PICKED_ITEMS_LIST undoList;
|
2019-09-12 19:08:35 +00:00
|
|
|
EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
|
2020-04-02 17:03:53 +00:00
|
|
|
KICAD_T wiresAndBuses[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T, EOT };
|
2018-02-02 20:04:36 +00:00
|
|
|
|
|
|
|
auto remove_item = [ & ]( SCH_ITEM* aItem ) -> void
|
|
|
|
{
|
|
|
|
aItem->SetFlags( STRUCT_DELETED );
|
2020-08-26 18:04:32 +00:00
|
|
|
undoList.PushItem( ITEM_PICKER( screen, aItem, UNDO_REDO::DELETED ) );
|
2018-02-02 20:04:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
remove_item( aJunction );
|
2020-07-13 11:21:40 +00:00
|
|
|
RemoveFromScreen( aJunction, screen );
|
2018-02-02 20:04:36 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
/// Note that std::list or similar is required here as we may insert values in the
|
|
|
|
/// loop below. This will invalidate iterators in a std::vector or std::deque
|
|
|
|
std::list<SCH_LINE*> lines;
|
2018-02-02 20:04:36 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items().Overlapping( SCH_LINE_T, aJunction->GetPosition() ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2020-04-24 13:36:10 +00:00
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( item );
|
2018-02-02 20:04:36 +00:00
|
|
|
|
2020-04-02 17:03:53 +00:00
|
|
|
if( line->IsType( wiresAndBuses ) && line->IsEndPoint( aJunction->GetPosition() )
|
2019-06-25 23:39:58 +00:00
|
|
|
&& !( line->GetEditFlags() & STRUCT_DELETED ) )
|
|
|
|
lines.push_back( line );
|
|
|
|
}
|
2018-02-02 20:04:36 +00:00
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
alg::for_all_pairs( lines.begin(), lines.end(),
|
|
|
|
[&]( SCH_LINE* firstLine, SCH_LINE* secondLine )
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
if( ( firstLine->GetEditFlags() & STRUCT_DELETED )
|
|
|
|
|| ( secondLine->GetEditFlags() & STRUCT_DELETED )
|
|
|
|
|| !secondLine->IsParallel( firstLine ) )
|
2020-08-10 11:40:58 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
return;
|
2020-08-10 11:40:58 +00:00
|
|
|
}
|
2018-02-02 20:04:36 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
// Remove identical lines
|
|
|
|
if( firstLine->IsEndPoint( secondLine->GetStartPoint() )
|
|
|
|
&& firstLine->IsEndPoint( secondLine->GetEndPoint() ) )
|
|
|
|
{
|
|
|
|
remove_item( firstLine );
|
|
|
|
return;
|
|
|
|
}
|
2019-09-12 19:08:35 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
// Try to merge the remaining lines
|
2020-10-21 17:41:44 +00:00
|
|
|
if( SCH_LINE* line = secondLine->MergeOverlap( screen, firstLine, false ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
remove_item( firstLine );
|
|
|
|
remove_item( secondLine );
|
2020-08-26 18:04:32 +00:00
|
|
|
undoList.PushItem( ITEM_PICKER( screen, line, UNDO_REDO::NEWITEM ) );
|
2020-07-13 11:21:40 +00:00
|
|
|
AddToScreen( line, screen );
|
2019-09-12 19:08:35 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
if( line->IsSelected() )
|
|
|
|
selectionTool->AddItemToSel( line, true /*quiet mode*/ );
|
2019-09-12 19:08:35 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
lines.push_back( line );
|
|
|
|
}
|
|
|
|
} );
|
2018-02-02 20:04:36 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
SaveCopyInUndoList( undoList, UNDO_REDO::DELETED, aAppend );
|
2018-02-02 20:04:36 +00:00
|
|
|
|
2021-02-23 12:49:02 +00:00
|
|
|
for( SCH_LINE* line : lines )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
if( line->GetEditFlags() & STRUCT_DELETED )
|
2019-09-12 19:08:35 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
if( line->IsSelected() )
|
|
|
|
selectionTool->RemoveItemFromSel( line, true /*quiet mode*/ );
|
2019-09-12 19:08:35 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
RemoveFromScreen( line, screen );
|
2019-09-12 19:08:35 +00:00
|
|
|
}
|
2018-02-02 20:04:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( SCH_SCREEN* aScreen, const wxPoint& aPos,
|
|
|
|
bool aUndoAppend, bool aFinal )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2019-05-11 10:06:28 +00:00
|
|
|
SCH_JUNCTION* junction = new SCH_JUNCTION( aPos );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
AddToScreen( junction, aScreen );
|
2020-08-26 18:04:32 +00:00
|
|
|
SaveCopyInUndoList( aScreen, junction, UNDO_REDO::NEWITEM, aUndoAppend );
|
2019-05-11 10:06:28 +00:00
|
|
|
BreakSegments( aPos );
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2019-03-18 02:07:32 +00:00
|
|
|
if( aFinal )
|
|
|
|
{
|
2019-05-12 17:03:17 +00:00
|
|
|
m_toolManager->PostEvent( EVENTS::SelectedItemsModified );
|
|
|
|
|
2019-03-18 02:07:32 +00:00
|
|
|
TestDanglingEnds();
|
|
|
|
OnModify();
|
|
|
|
|
2021-02-23 12:49:02 +00:00
|
|
|
KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
|
2019-03-18 02:07:32 +00:00
|
|
|
view->ClearPreview();
|
|
|
|
view->ShowPreview( false );
|
|
|
|
view->ClearHiddenFlags();
|
|
|
|
}
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
return junction;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|