2011-10-19 16:32:21 -04:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-03-19 08:48:29 +01:00
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-19 16:32:21 -04: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 16:39:58 -07:00
|
|
|
#include <core/kicad_algo.h>
|
2012-01-22 22:33:36 -06:00
|
|
|
#include <general.h>
|
|
|
|
#include <sch_bus_entry.h>
|
2019-06-25 16:39:58 -07:00
|
|
|
#include <sch_edit_frame.h>
|
2012-01-22 22:33:36 -06:00
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_no_connect.h>
|
2023-06-09 22:41:33 +01:00
|
|
|
#include <sch_commit.h>
|
2019-06-25 16:39:58 -07:00
|
|
|
#include <tool/tool_manager.h>
|
2025-03-12 14:41:25 +00:00
|
|
|
#include <tools/sch_selection_tool.h>
|
2020-10-13 23:37:48 -04:00
|
|
|
#include <trigo.h>
|
2019-06-25 16:39:58 -07:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2020-12-06 21:23:16 +00:00
|
|
|
void SCH_EDIT_FRAME::TestDanglingEnds()
|
2018-10-16 14:11:33 +01: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 14:11:33 +01:00
|
|
|
|
2020-12-06 21:23:16 +00:00
|
|
|
GetScreen()->TestDanglingEnds( nullptr, &changeHandler );
|
2018-10-16 14:11:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 22:41:33 +01:00
|
|
|
bool SCH_EDIT_FRAME::TrimWire( SCH_COMMIT* aCommit, const VECTOR2I& aStart, const VECTOR2I& aEnd )
|
2017-12-01 14:53:23 -08:00
|
|
|
{
|
2022-08-31 10:15:42 +01:00
|
|
|
if( aStart == aEnd )
|
|
|
|
return false;
|
2017-12-01 14:53:23 -08:00
|
|
|
|
2022-08-31 10:15:42 +01:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
2021-01-23 13:39:57 -08:00
|
|
|
std::vector<SCH_LINE*> wires;
|
2022-08-31 10:15:42 +01:00
|
|
|
BOX2I bb( aStart );
|
2021-01-23 13:39:57 -08:00
|
|
|
|
|
|
|
bb.Merge( aEnd );
|
|
|
|
|
|
|
|
// 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 14:53:23 -08:00
|
|
|
{
|
2019-06-25 16:39:58 -07:00
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( item );
|
2017-12-29 12:01:56 -08:00
|
|
|
|
2021-01-23 13:39:57 -08:00
|
|
|
if( item->Type() == SCH_LINE_T && line->GetLayer() == LAYER_WIRE )
|
|
|
|
wires.push_back( line );
|
|
|
|
}
|
2017-12-01 14:53:23 -08:00
|
|
|
|
2021-01-23 13:39:57 -08:00
|
|
|
for( SCH_LINE* line : wires )
|
|
|
|
{
|
2019-06-25 16:39:58 -07:00
|
|
|
// Don't remove wires that are already deleted or are currently being dragged
|
2022-12-28 09:59:38 -05:00
|
|
|
if( line->GetEditFlags() & ( STRUCT_DELETED | IS_MOVING | SKIP_STRUCT ) )
|
2017-12-01 14:53:23 -08: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 14:53:23 -08: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 14:53:23 -08:00
|
|
|
|
2022-12-24 11:16:33 +00:00
|
|
|
// Step 1: break the segment on one end.
|
2017-12-01 14:53:23 -08:00
|
|
|
// Ensure that *line points to the segment containing aEnd
|
2022-12-24 11:16:33 +00:00
|
|
|
SCH_LINE* new_line;
|
2023-06-09 17:24:49 +01:00
|
|
|
BreakSegment( aCommit, line, aStart, &new_line, screen );
|
2020-07-13 12:21:40 +01:00
|
|
|
|
2022-12-24 11:16:33 +00:00
|
|
|
if( IsPointOnSegment( new_line->GetStartPoint(), new_line->GetEndPoint(), aEnd ) )
|
|
|
|
line = new_line;
|
2017-12-01 14:53:23 -08:00
|
|
|
|
2022-12-24 11:16:33 +00:00
|
|
|
// Step 2: break the remaining segment.
|
2017-12-01 14:53:23 -08:00
|
|
|
// Ensure that *line _also_ contains aStart. This is our overlapping segment
|
2023-06-09 17:24:49 +01:00
|
|
|
BreakSegment( aCommit, line, aEnd, &new_line, screen );
|
2020-07-13 12:21:40 +01:00
|
|
|
|
2022-12-24 11:16:33 +00:00
|
|
|
if( IsPointOnSegment( new_line->GetStartPoint(), new_line->GetEndPoint(), aStart ) )
|
|
|
|
line = new_line;
|
2017-12-01 14:53:23 -08:00
|
|
|
|
2020-07-13 12:21:40 +01:00
|
|
|
RemoveFromScreen( line, screen );
|
2023-06-09 17:24:49 +01:00
|
|
|
aCommit->Removed( line, screen );
|
2019-03-17 22:07:32 -04:00
|
|
|
|
2022-08-31 10:15:42 +01:00
|
|
|
return true;
|
2017-12-01 14:53:23 -08:00
|
|
|
}
|
2017-12-29 12:01:56 -08:00
|
|
|
|
2022-08-31 10:15:42 +01:00
|
|
|
return false;
|
2017-12-01 14:53:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 22:41:33 +01:00
|
|
|
void SCH_EDIT_FRAME::SchematicCleanUp( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen )
|
2017-10-25 15:21:42 -07:00
|
|
|
{
|
2025-03-12 14:41:25 +00:00
|
|
|
SCH_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<SCH_SELECTION_TOOL>();
|
2019-06-25 16:39:58 -07:00
|
|
|
std::vector<SCH_LINE*> lines;
|
|
|
|
std::vector<SCH_JUNCTION*> junctions;
|
|
|
|
std::vector<SCH_NO_CONNECT*> ncs;
|
2023-08-02 15:57:56 -07:00
|
|
|
std::vector<SCH_ITEM*> items_to_remove;
|
2020-08-20 06:48:01 -07:00
|
|
|
bool changed = true;
|
2019-03-11 17:32:05 -04:00
|
|
|
|
|
|
|
if( aScreen == nullptr )
|
|
|
|
aScreen = GetScreen();
|
2017-10-25 15:21:42 -07:00
|
|
|
|
2020-08-20 06:48:01 -07:00
|
|
|
auto remove_item = [&]( SCH_ITEM* aItem ) -> void
|
2020-07-13 12:21:40 +01:00
|
|
|
{
|
2020-08-20 06:48:01 -07:00
|
|
|
changed = true;
|
2022-11-25 15:04:36 +00:00
|
|
|
|
|
|
|
if( !( aItem->GetFlags() & STRUCT_DELETED ) )
|
|
|
|
{
|
|
|
|
aItem->SetFlags( STRUCT_DELETED );
|
2023-06-09 17:24:49 +01:00
|
|
|
|
|
|
|
if( aItem->IsSelected() )
|
|
|
|
selectionTool->RemoveItemFromSel( aItem, true /*quiet mode*/ );
|
|
|
|
|
|
|
|
RemoveFromScreen( aItem, aScreen );
|
|
|
|
aCommit->Removed( aItem, aScreen );
|
2022-11-25 15:04:36 +00:00
|
|
|
}
|
2020-07-13 12:21:40 +01:00
|
|
|
};
|
2017-11-27 11:27:24 -08:00
|
|
|
|
2023-06-09 17:24:49 +01:00
|
|
|
BreakSegmentsOnJunctions( aCommit, aScreen );
|
2017-11-27 11:27:24 -08:00
|
|
|
|
2020-04-24 14:36:10 +01:00
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_JUNCTION_T ) )
|
2019-06-25 16:39:58 -07:00
|
|
|
{
|
2021-11-04 12:38:15 +00:00
|
|
|
if( !aScreen->IsExplicitJunction( item->GetPosition() ) )
|
2023-08-02 15:57:56 -07:00
|
|
|
items_to_remove.push_back( item );
|
2019-06-25 16:39:58 -07:00
|
|
|
else
|
|
|
|
junctions.push_back( static_cast<SCH_JUNCTION*>( item ) );
|
|
|
|
}
|
|
|
|
|
2023-08-02 15:57:56 -07:00
|
|
|
for( SCH_ITEM* item : items_to_remove )
|
|
|
|
remove_item( item );
|
|
|
|
|
2020-04-24 14:36:10 +01:00
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_NO_CONNECT_T ) )
|
2019-06-25 16:39:58 -07:00
|
|
|
ncs.push_back( static_cast<SCH_NO_CONNECT*>( item ) );
|
|
|
|
|
2020-08-10 12:40:58 +01:00
|
|
|
alg::for_all_pairs( junctions.begin(), junctions.end(),
|
|
|
|
[&]( SCH_JUNCTION* aFirst, SCH_JUNCTION* aSecond )
|
|
|
|
{
|
2019-06-25 16:39:58 -07:00
|
|
|
if( ( aFirst->GetEditFlags() & STRUCT_DELETED )
|
|
|
|
|| ( aSecond->GetEditFlags() & STRUCT_DELETED ) )
|
2020-08-10 12:40:58 +01:00
|
|
|
{
|
2019-06-25 16:39:58 -07:00
|
|
|
return;
|
2020-08-10 12:40:58 +01:00
|
|
|
}
|
2019-06-25 16:39:58 -07:00
|
|
|
|
|
|
|
if( aFirst->GetPosition() == aSecond->GetPosition() )
|
|
|
|
remove_item( aSecond );
|
|
|
|
} );
|
|
|
|
|
2020-08-10 12:40:58 +01:00
|
|
|
alg::for_all_pairs( ncs.begin(), ncs.end(),
|
|
|
|
[&]( SCH_NO_CONNECT* aFirst, SCH_NO_CONNECT* aSecond )
|
|
|
|
{
|
2019-06-25 16:39:58 -07:00
|
|
|
if( ( aFirst->GetEditFlags() & STRUCT_DELETED )
|
|
|
|
|| ( aSecond->GetEditFlags() & STRUCT_DELETED ) )
|
2020-08-10 12:40:58 +01:00
|
|
|
{
|
2019-06-25 16:39:58 -07:00
|
|
|
return;
|
2020-08-10 12:40:58 +01:00
|
|
|
}
|
2019-06-25 16:39:58 -07:00
|
|
|
|
|
|
|
if( aFirst->GetPosition() == aSecond->GetPosition() )
|
|
|
|
remove_item( aSecond );
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
2024-02-12 08:39:11 +01:00
|
|
|
auto minX = []( const SCH_LINE* l )
|
|
|
|
{
|
|
|
|
return std::min( l->GetStartPoint().x, l->GetEndPoint().x );
|
|
|
|
};
|
|
|
|
|
|
|
|
auto maxX = []( const SCH_LINE* l )
|
|
|
|
{
|
|
|
|
return std::max( l->GetStartPoint().x, l->GetEndPoint().x );
|
|
|
|
};
|
|
|
|
|
|
|
|
auto minY = []( const SCH_LINE* l )
|
|
|
|
{
|
|
|
|
return std::min( l->GetStartPoint().y, l->GetEndPoint().y );
|
|
|
|
};
|
|
|
|
|
|
|
|
auto maxY = []( const SCH_LINE* l )
|
|
|
|
{
|
|
|
|
return std::max( l->GetStartPoint().y, l->GetEndPoint().y );
|
|
|
|
};
|
|
|
|
|
|
|
|
// Would be nice to put lines in a canonical form here by swapping
|
|
|
|
// start <-> end as needed but I don't know what swapping breaks.
|
2020-08-20 06:48:01 -07:00
|
|
|
while( changed )
|
|
|
|
{
|
|
|
|
changed = false;
|
|
|
|
lines.clear();
|
2017-12-12 21:12:06 -08:00
|
|
|
|
2020-08-20 06:48:01 -07:00
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_LINE_T ) )
|
2017-11-27 11:27:24 -08:00
|
|
|
{
|
2020-08-20 06:48:01 -07:00
|
|
|
if( item->GetLayer() == LAYER_WIRE || item->GetLayer() == LAYER_BUS )
|
|
|
|
lines.push_back( static_cast<SCH_LINE*>( item ) );
|
2017-11-27 11:27:24 -08:00
|
|
|
}
|
2017-10-25 15:21:42 -07:00
|
|
|
|
2024-02-12 08:39:11 +01:00
|
|
|
// Sort by minimum X position
|
|
|
|
std::sort( lines.begin(), lines.end(),
|
|
|
|
[&]( const SCH_LINE* a, const SCH_LINE* b )
|
|
|
|
{
|
|
|
|
return minX( a ) < minX( b );
|
|
|
|
} );
|
|
|
|
|
2020-08-20 06:48:01 -07:00
|
|
|
for( auto it1 = lines.begin(); it1 != lines.end(); ++it1 )
|
2017-11-27 11:27:24 -08:00
|
|
|
{
|
2020-08-20 06:48:01 -07:00
|
|
|
SCH_LINE* firstLine = *it1;
|
2017-11-27 11:27:24 -08:00
|
|
|
|
2020-08-20 06:48:01 -07:00
|
|
|
if( firstLine->GetEditFlags() & STRUCT_DELETED )
|
2019-06-25 16:39:58 -07:00
|
|
|
continue;
|
2017-11-27 11:27:24 -08:00
|
|
|
|
2020-08-20 06:48:01 -07:00
|
|
|
if( firstLine->IsNull() )
|
2019-06-25 16:39:58 -07:00
|
|
|
{
|
2020-08-20 06:48:01 -07:00
|
|
|
remove_item( firstLine );
|
2019-06-25 16:39:58 -07:00
|
|
|
continue;
|
|
|
|
}
|
2017-12-12 21:12:06 -08:00
|
|
|
|
2024-02-12 08:39:11 +01:00
|
|
|
int firstRightXEdge = maxX( firstLine );
|
2020-08-20 06:48:01 -07:00
|
|
|
auto it2 = it1;
|
2019-09-12 20:08:35 +01:00
|
|
|
|
2020-08-20 06:48:01 -07:00
|
|
|
for( ++it2; it2 != lines.end(); ++it2 )
|
2019-06-25 16:39:58 -07:00
|
|
|
{
|
2020-08-20 06:48:01 -07:00
|
|
|
SCH_LINE* secondLine = *it2;
|
2024-02-12 08:39:11 +01:00
|
|
|
int secondLeftXEdge = minX( secondLine );
|
|
|
|
|
|
|
|
// impossible to overlap remaining lines
|
|
|
|
if( secondLeftXEdge > firstRightXEdge )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// No Y axis overlap
|
|
|
|
if( !( std::max( minY( firstLine ), minY( secondLine ) )
|
|
|
|
<= std::min( maxY( firstLine ), maxY( secondLine ) ) ) )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-20 06:48:01 -07:00
|
|
|
|
|
|
|
if( secondLine->GetFlags() & STRUCT_DELETED )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !secondLine->IsParallel( firstLine )
|
2020-10-21 18:41:44 +01:00
|
|
|
|| !secondLine->IsStrokeEquivalent( firstLine )
|
2020-08-20 06:48:01 -07:00
|
|
|
|| secondLine->GetLayer() != firstLine->GetLayer() )
|
2020-10-21 17:23:19 +01:00
|
|
|
{
|
2020-08-20 06:48:01 -07:00
|
|
|
continue;
|
2020-10-21 17:23:19 +01:00
|
|
|
}
|
2020-08-20 06:48:01 -07:00
|
|
|
|
|
|
|
// Remove identical lines
|
|
|
|
if( firstLine->IsEndPoint( secondLine->GetStartPoint() )
|
|
|
|
&& firstLine->IsEndPoint( secondLine->GetEndPoint() ) )
|
|
|
|
{
|
|
|
|
remove_item( secondLine );
|
|
|
|
continue;
|
|
|
|
}
|
2019-09-12 20:08:35 +01:00
|
|
|
|
2020-10-21 18:41:44 +01:00
|
|
|
// See if we can merge an overlap (or two colinear touching segments with
|
|
|
|
// no junction where they meet).
|
2020-10-24 00:50:02 -04:00
|
|
|
SCH_LINE* mergedLine = secondLine->MergeOverlap( aScreen, firstLine, true );
|
2019-06-25 16:39:58 -07:00
|
|
|
|
2020-10-24 00:50:02 -04:00
|
|
|
if( mergedLine != nullptr )
|
2020-08-20 06:48:01 -07:00
|
|
|
{
|
|
|
|
remove_item( firstLine );
|
|
|
|
remove_item( secondLine );
|
|
|
|
|
|
|
|
AddToScreen( mergedLine, aScreen );
|
2023-06-09 17:24:49 +01:00
|
|
|
aCommit->Added( mergedLine, aScreen );
|
2020-08-20 06:48:01 -07:00
|
|
|
|
2022-01-01 16:52:17 -08:00
|
|
|
if( firstLine->IsSelected() || secondLine->IsSelected() )
|
2020-08-20 06:48:01 -07:00
|
|
|
selectionTool->AddItemToSel( mergedLine, true /*quiet mode*/ );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2017-10-25 15:21:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-23 17:34:27 -04:00
|
|
|
}
|
2019-03-17 22:07:32 -04:00
|
|
|
|
2019-03-23 17:34:27 -04:00
|
|
|
|
2023-06-09 22:41:33 +01:00
|
|
|
void SCH_EDIT_FRAME::BreakSegment( SCH_COMMIT* aCommit, SCH_LINE* aSegment, const VECTOR2I& aPoint,
|
|
|
|
SCH_LINE** aNewSegment, SCH_SCREEN* aScreen )
|
2017-10-26 08:25:47 -07:00
|
|
|
{
|
2023-01-15 13:28:25 +01:00
|
|
|
// Save the copy of aSegment before breaking it
|
2023-06-09 17:24:49 +01:00
|
|
|
aCommit->Modify( aSegment, aScreen );
|
2017-10-26 08:25:47 -07:00
|
|
|
|
2025-05-19 21:36:46 +01:00
|
|
|
SCH_LINE* newSegment = aSegment->BreakAt( aCommit, aPoint );
|
2023-06-09 17:24:49 +01:00
|
|
|
|
2023-01-15 13:28:25 +01:00
|
|
|
aSegment->SetFlags( IS_CHANGED | IS_BROKEN );
|
2022-12-28 09:50:40 -05:00
|
|
|
newSegment->SetFlags( IS_NEW | IS_BROKEN );
|
2022-12-13 09:01:52 -05:00
|
|
|
|
2023-06-09 17:24:49 +01:00
|
|
|
AddToScreen( newSegment, aScreen );
|
|
|
|
aCommit->Added( newSegment, aScreen );
|
2018-10-24 23:18:53 +01:00
|
|
|
|
2023-06-09 17:24:49 +01:00
|
|
|
*aNewSegment = newSegment;
|
2017-10-26 08:25:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 22:41:33 +01:00
|
|
|
bool SCH_EDIT_FRAME::BreakSegments( SCH_COMMIT* aCommit, const VECTOR2I& aPos, SCH_SCREEN* aScreen )
|
2017-10-26 08:25:47 -07:00
|
|
|
{
|
2023-06-09 17:24:49 +01:00
|
|
|
bool brokenSegments = false;
|
|
|
|
SCH_LINE* new_line;
|
2017-10-26 08:25:47 -07:00
|
|
|
|
2023-06-09 22:41:33 +01:00
|
|
|
for( SCH_LINE* wire : aScreen->GetBusesAndWires( aPos, true ) )
|
2022-12-24 11:16:33 +00:00
|
|
|
{
|
2023-06-09 22:41:33 +01:00
|
|
|
BreakSegment( aCommit, wire, aPos, &new_line, aScreen );
|
2022-12-24 11:16:33 +00:00
|
|
|
brokenSegments = true;
|
|
|
|
}
|
2019-06-25 16:39:58 -07:00
|
|
|
|
2017-10-26 08:25:47 -07:00
|
|
|
return brokenSegments;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 22:41:33 +01:00
|
|
|
bool SCH_EDIT_FRAME::BreakSegmentsOnJunctions( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen )
|
2017-10-26 08:25:47 -07:00
|
|
|
{
|
|
|
|
bool brokenSegments = false;
|
|
|
|
|
2022-01-01 01:04:08 -05:00
|
|
|
std::set<VECTOR2I> point_set;
|
2020-04-24 14:36:10 +01:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_JUNCTION_T ) )
|
2019-06-25 16:39:58 -07:00
|
|
|
point_set.insert( item->GetPosition() );
|
|
|
|
|
2020-04-24 14:36:10 +01:00
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_BUS_WIRE_ENTRY_T ) )
|
2017-10-26 08:25:47 -07:00
|
|
|
{
|
2020-04-24 14:36:10 +01:00
|
|
|
SCH_BUS_WIRE_ENTRY* entry = static_cast<SCH_BUS_WIRE_ENTRY*>( item );
|
2019-06-25 16:39:58 -07:00
|
|
|
point_set.insert( entry->GetPosition() );
|
2020-09-08 06:27:13 -07:00
|
|
|
point_set.insert( entry->GetEnd() );
|
2019-06-25 16:39:58 -07:00
|
|
|
}
|
2017-10-26 08:25:47 -07:00
|
|
|
|
2022-01-01 01:04:08 -05:00
|
|
|
for( const VECTOR2I& pt : point_set )
|
2022-12-24 11:16:33 +00:00
|
|
|
{
|
2023-06-09 17:24:49 +01:00
|
|
|
BreakSegments( aCommit, pt, aScreen );
|
2022-12-24 11:16:33 +00:00
|
|
|
brokenSegments = true;
|
|
|
|
}
|
2017-10-26 08:25:47 -07:00
|
|
|
|
|
|
|
return brokenSegments;
|
|
|
|
}
|
|
|
|
|
2017-10-25 15:21:42 -07:00
|
|
|
|
2023-06-09 22:41:33 +01:00
|
|
|
void SCH_EDIT_FRAME::DeleteJunction( SCH_COMMIT* aCommit, SCH_ITEM* aJunction )
|
2018-02-02 12:04:36 -08:00
|
|
|
{
|
2025-03-12 14:41:25 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
PICKED_ITEMS_LIST undoList;
|
|
|
|
SCH_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<SCH_SELECTION_TOOL>();
|
2018-02-02 12:04:36 -08:00
|
|
|
|
2023-06-09 17:24:49 +01:00
|
|
|
aJunction->SetFlags( STRUCT_DELETED );
|
2020-07-13 12:21:40 +01:00
|
|
|
RemoveFromScreen( aJunction, screen );
|
2023-06-09 17:24:49 +01:00
|
|
|
aCommit->Removed( aJunction, screen );
|
2018-02-02 12:04:36 -08:00
|
|
|
|
2019-06-25 16:39:58 -07: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 12:04:36 -08:00
|
|
|
|
2020-04-24 14:36:10 +01:00
|
|
|
for( SCH_ITEM* item : screen->Items().Overlapping( SCH_LINE_T, aJunction->GetPosition() ) )
|
2019-06-25 16:39:58 -07:00
|
|
|
{
|
2020-04-24 14:36:10 +01:00
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( item );
|
2018-02-02 12:04:36 -08:00
|
|
|
|
2024-06-21 19:07:42 +01:00
|
|
|
if( ( line->IsWire() || line->IsBus() )
|
2022-08-20 10:27:35 +01:00
|
|
|
&& line->IsEndPoint( aJunction->GetPosition() )
|
2019-06-25 16:39:58 -07:00
|
|
|
&& !( line->GetEditFlags() & STRUCT_DELETED ) )
|
2022-08-20 10:27:35 +01:00
|
|
|
{
|
2019-06-25 16:39:58 -07:00
|
|
|
lines.push_back( line );
|
2022-08-20 10:27:35 +01:00
|
|
|
}
|
2019-06-25 16:39:58 -07:00
|
|
|
}
|
2018-02-02 12:04:36 -08:00
|
|
|
|
2020-08-10 12:40:58 +01:00
|
|
|
alg::for_all_pairs( lines.begin(), lines.end(),
|
|
|
|
[&]( SCH_LINE* firstLine, SCH_LINE* secondLine )
|
|
|
|
{
|
2019-06-25 16:39:58 -07:00
|
|
|
if( ( firstLine->GetEditFlags() & STRUCT_DELETED )
|
|
|
|
|| ( secondLine->GetEditFlags() & STRUCT_DELETED )
|
|
|
|
|| !secondLine->IsParallel( firstLine ) )
|
2020-08-10 12:40:58 +01:00
|
|
|
{
|
2019-06-25 16:39:58 -07:00
|
|
|
return;
|
2020-08-10 12:40:58 +01:00
|
|
|
}
|
2018-02-02 12:04:36 -08:00
|
|
|
|
2019-06-25 16:39:58 -07:00
|
|
|
// Remove identical lines
|
|
|
|
if( firstLine->IsEndPoint( secondLine->GetStartPoint() )
|
|
|
|
&& firstLine->IsEndPoint( secondLine->GetEndPoint() ) )
|
|
|
|
{
|
2023-06-09 17:24:49 +01:00
|
|
|
firstLine->SetFlags( STRUCT_DELETED );
|
2019-06-25 16:39:58 -07:00
|
|
|
return;
|
|
|
|
}
|
2019-09-12 20:08:35 +01:00
|
|
|
|
2019-06-25 16:39:58 -07:00
|
|
|
// Try to merge the remaining lines
|
2023-06-09 17:24:49 +01:00
|
|
|
if( SCH_LINE* new_line = secondLine->MergeOverlap( screen, firstLine, false ) )
|
2019-06-25 16:39:58 -07:00
|
|
|
{
|
2023-06-09 17:24:49 +01:00
|
|
|
firstLine->SetFlags( STRUCT_DELETED );
|
|
|
|
secondLine->SetFlags( STRUCT_DELETED );
|
|
|
|
AddToScreen( new_line, screen );
|
|
|
|
aCommit->Added( new_line, screen );
|
2019-09-12 20:08:35 +01:00
|
|
|
|
2023-06-09 17:24:49 +01:00
|
|
|
if( new_line->IsSelected() )
|
|
|
|
selectionTool->AddItemToSel( new_line, true /*quiet mode*/ );
|
2019-09-12 20:08:35 +01:00
|
|
|
|
2023-06-09 17:24:49 +01:00
|
|
|
lines.push_back( new_line );
|
2019-06-25 16:39:58 -07:00
|
|
|
}
|
|
|
|
} );
|
2018-02-02 12:04:36 -08:00
|
|
|
|
2021-02-23 12:49:02 +00:00
|
|
|
for( SCH_LINE* line : lines )
|
2019-06-25 16:39:58 -07:00
|
|
|
{
|
|
|
|
if( line->GetEditFlags() & STRUCT_DELETED )
|
2019-09-12 20:08:35 +01:00
|
|
|
{
|
2019-06-25 16:39:58 -07:00
|
|
|
if( line->IsSelected() )
|
|
|
|
selectionTool->RemoveItemFromSel( line, true /*quiet mode*/ );
|
2019-09-12 20:08:35 +01:00
|
|
|
|
2020-07-13 12:21:40 +01:00
|
|
|
RemoveFromScreen( line, screen );
|
2023-06-09 17:24:49 +01:00
|
|
|
aCommit->Removed( line, screen );
|
2019-09-12 20:08:35 +01:00
|
|
|
}
|
2018-02-02 12:04:36 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-09 22:41:33 +01:00
|
|
|
SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen,
|
2023-06-09 17:24:49 +01:00
|
|
|
const VECTOR2I& aPos )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2019-05-11 11:06:28 +01:00
|
|
|
SCH_JUNCTION* junction = new SCH_JUNCTION( aPos );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2020-07-13 12:21:40 +01:00
|
|
|
AddToScreen( junction, aScreen );
|
2023-06-09 17:24:49 +01:00
|
|
|
aCommit->Added( junction, aScreen );
|
2018-08-03 14:18:26 +02:00
|
|
|
|
2023-06-09 17:24:49 +01:00
|
|
|
BreakSegments( aCommit, aPos, aScreen );
|
2018-08-03 14:18:26 +02:00
|
|
|
|
2011-02-04 21:21:11 -05:00
|
|
|
return junction;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|