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
|
2019-03-28 17:46:05 +00:00
|
|
|
* Copyright (C) 2004-2019 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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <lib_draw_item.h>
|
|
|
|
#include <general.h>
|
|
|
|
#include <sch_bus_entry.h>
|
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_no_connect.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_sheet.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_view.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
void SCH_EDIT_FRAME::GetSchematicConnections( std::vector< wxPoint >& aConnections )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item = GetScreen()->GetDrawItems(); item; item = item->Next() )
|
2018-01-23 20:29:15 +00:00
|
|
|
{
|
|
|
|
// Avoid items that are changing
|
2019-04-22 08:58:06 +00:00
|
|
|
if( !( item->GetEditFlags() & ( IS_DRAGGED | IS_MOVED | IS_DELETED ) ) )
|
2018-01-23 20:29:15 +00:00
|
|
|
item->GetConnectionPoints( aConnections );
|
|
|
|
}
|
2017-11-27 19:27:24 +00:00
|
|
|
|
|
|
|
// We always have some overlapping connection points. Drop duplicates here
|
|
|
|
std::sort( aConnections.begin(), aConnections.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); } );
|
|
|
|
aConnections.erase( unique( aConnections.begin(), aConnections.end() ), aConnections.end() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-16 13:11:33 +00:00
|
|
|
bool SCH_EDIT_FRAME::TestDanglingEnds()
|
|
|
|
{
|
|
|
|
std::vector<DANGLING_END_ITEM> endPoints;
|
|
|
|
bool hasStateChanged = false;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item = GetScreen()->GetDrawList().begin(); item; item = item->Next() )
|
|
|
|
item->GetEndPoints( endPoints );
|
|
|
|
|
|
|
|
for( SCH_ITEM* item = GetScreen()->GetDrawList().begin(); item; item = item->Next() )
|
|
|
|
{
|
2018-10-29 18:11:04 +00:00
|
|
|
if( item->UpdateDanglingState( endPoints ) )
|
2018-10-16 13:11:33 +00:00
|
|
|
{
|
|
|
|
GetCanvas()->GetView()->Update( item, KIGFX::REPAINT );
|
|
|
|
hasStateChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hasStateChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-29 20:01:56 +00:00
|
|
|
bool SCH_EDIT_FRAME::TrimWire( const wxPoint& aStart, const wxPoint& aEnd, bool aAppend )
|
2017-12-01 22:53:23 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* line;
|
2017-12-29 20:01:56 +00:00
|
|
|
SCH_ITEM* next_item = NULL;
|
|
|
|
bool retval = false;
|
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
|
|
|
|
2017-12-29 20:01:56 +00:00
|
|
|
for( SCH_ITEM* item = GetScreen()->GetDrawItems(); item; item = next_item )
|
2017-12-01 22:53:23 +00:00
|
|
|
{
|
2017-12-29 20:01:56 +00:00
|
|
|
next_item = item->Next();
|
|
|
|
|
2018-09-24 13:36:21 +00:00
|
|
|
// Don't remove wires that are already deleted or are currently being dragged
|
2019-04-22 08:58:06 +00:00
|
|
|
if( item->GetEditFlags() & ( STRUCT_DELETED | IS_DRAGGED | IS_MOVED | SKIP_STRUCT ) )
|
2017-12-01 22:53:23 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item->Type() != SCH_LINE_T || item->GetLayer() != LAYER_WIRE )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
line = (SCH_LINE*) item;
|
|
|
|
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;
|
|
|
|
aAppend |= BreakSegment( line, aStart, aAppend, &return_line );
|
|
|
|
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
|
|
|
|
aAppend |= BreakSegment( line, aEnd, aAppend, &return_line );
|
|
|
|
if( IsPointOnSegment( return_line->GetStartPoint(), return_line->GetEndPoint(), aStart ) )
|
|
|
|
line = return_line;
|
|
|
|
|
|
|
|
SaveCopyInUndoList( (SCH_ITEM*)line, UR_DELETED, aAppend );
|
2018-08-03 12:18:26 +00:00
|
|
|
RemoveFromScreen( (SCH_ITEM*)line );
|
2019-03-18 02:07:32 +00:00
|
|
|
|
2017-12-29 20:01:56 +00:00
|
|
|
aAppend = true;
|
|
|
|
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-03-18 02:07:32 +00:00
|
|
|
bool SCH_EDIT_FRAME::SchematicCleanUp( bool aUndo, SCH_SCREEN* aScreen )
|
2017-10-25 22:21:42 +00:00
|
|
|
{
|
2017-11-27 19:27:24 +00:00
|
|
|
SCH_ITEM* item = NULL;
|
|
|
|
SCH_ITEM* secondItem = NULL;
|
|
|
|
PICKED_ITEMS_LIST itemList;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
if( aScreen == nullptr )
|
|
|
|
aScreen = GetScreen();
|
2017-10-25 22:21:42 +00:00
|
|
|
|
2017-12-13 05:12:06 +00:00
|
|
|
auto remove_item = [ &itemList ]( SCH_ITEM* aItem ) -> void
|
2017-10-25 22:21:42 +00:00
|
|
|
{
|
2017-11-27 19:27:24 +00:00
|
|
|
aItem->SetFlags( STRUCT_DELETED );
|
|
|
|
itemList.PushItem( ITEM_PICKER( aItem, UR_DELETED ) );
|
|
|
|
};
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
BreakSegmentsOnJunctions( true, aScreen );
|
2017-11-27 19:27:24 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
for( item = aScreen->GetDrawItems(); item; item = item->Next() )
|
2017-11-27 19:27:24 +00:00
|
|
|
{
|
2017-12-13 05:12:06 +00:00
|
|
|
if( ( item->Type() != SCH_LINE_T )
|
|
|
|
&& ( item->Type() != SCH_JUNCTION_T )
|
|
|
|
&& ( item->Type() != SCH_NO_CONNECT_T ) )
|
2017-10-25 22:21:42 +00:00
|
|
|
continue;
|
|
|
|
|
2019-04-22 08:58:06 +00:00
|
|
|
if( item->GetEditFlags() & STRUCT_DELETED )
|
2017-11-27 19:27:24 +00:00
|
|
|
continue;
|
2017-10-25 22:21:42 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
// Remove unneeded junctions
|
|
|
|
if( ( item->Type() == SCH_JUNCTION_T )
|
2019-03-11 21:32:05 +00:00
|
|
|
&& ( !aScreen->IsJunctionNeeded( item->GetPosition() ) ) )
|
2017-10-25 22:21:42 +00:00
|
|
|
{
|
2017-11-27 19:27:24 +00:00
|
|
|
remove_item( item );
|
|
|
|
continue;
|
|
|
|
}
|
2017-12-13 05:12:06 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
// Remove zero-length lines
|
|
|
|
if( item->Type() == SCH_LINE_T
|
2017-12-13 05:12:06 +00:00
|
|
|
&& ( (SCH_LINE*) item )->IsNull() )
|
2017-11-27 19:27:24 +00:00
|
|
|
{
|
|
|
|
remove_item( item );
|
|
|
|
continue;
|
|
|
|
}
|
2017-10-25 22:21:42 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
for( secondItem = item->Next(); secondItem; secondItem = secondItem->Next() )
|
|
|
|
{
|
2019-04-22 08:58:06 +00:00
|
|
|
if( item->Type() != secondItem->Type()
|
|
|
|
|| ( secondItem->GetEditFlags() & STRUCT_DELETED ) )
|
2017-11-27 19:27:24 +00:00
|
|
|
continue;
|
2017-10-25 22:21:42 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
// Merge overlapping lines
|
|
|
|
if( item->Type() == SCH_LINE_T )
|
2017-10-25 22:21:42 +00:00
|
|
|
{
|
2017-12-13 05:12:06 +00:00
|
|
|
SCH_LINE* firstLine = (SCH_LINE*) item;
|
|
|
|
SCH_LINE* secondLine = (SCH_LINE*) secondItem;
|
|
|
|
SCH_LINE* line = NULL;
|
2017-11-27 19:27:24 +00:00
|
|
|
bool needed = false;
|
|
|
|
|
2019-03-28 17:46:05 +00:00
|
|
|
if( !secondLine->IsParallel( firstLine )
|
|
|
|
|| secondLine->GetLineStyle() != firstLine->GetLineStyle()
|
|
|
|
|| secondLine->GetLineColor() != firstLine->GetLineColor()
|
|
|
|
|| secondLine->GetLineSize() != firstLine->GetLineSize() )
|
2017-11-27 19:27:24 +00:00
|
|
|
continue;
|
|
|
|
|
2017-12-13 05:12:06 +00:00
|
|
|
// Remove identical lines
|
|
|
|
if( firstLine->IsEndPoint( secondLine->GetStartPoint() )
|
|
|
|
&& firstLine->IsEndPoint( secondLine->GetEndPoint() ) )
|
|
|
|
{
|
|
|
|
remove_item( secondItem );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the end points overlap, check if we still need the junction
|
|
|
|
if( secondLine->IsEndPoint( firstLine->GetStartPoint() ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
needed = aScreen->IsJunctionNeeded( firstLine->GetStartPoint() );
|
2017-12-13 05:12:06 +00:00
|
|
|
else if( secondLine->IsEndPoint( firstLine->GetEndPoint() ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
needed = aScreen->IsJunctionNeeded( firstLine->GetEndPoint() );
|
2017-11-27 19:27:24 +00:00
|
|
|
|
|
|
|
if( !needed && ( line = (SCH_LINE*) secondLine->MergeOverlap( firstLine ) ) )
|
2017-10-25 22:21:42 +00:00
|
|
|
{
|
2017-11-27 19:27:24 +00:00
|
|
|
remove_item( item );
|
|
|
|
remove_item( secondItem );
|
|
|
|
itemList.PushItem( ITEM_PICKER( line, UR_NEW ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
AddToScreen( line, aScreen );
|
2017-11-27 19:27:24 +00:00
|
|
|
break;
|
2017-10-25 22:21:42 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-27 19:27:24 +00:00
|
|
|
// Remove duplicate junctions and no-connects
|
|
|
|
else if( secondItem->GetPosition() == item->GetPosition() )
|
|
|
|
remove_item( secondItem );
|
2017-10-25 22:21:42 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-13 05:12:06 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
for( item = aScreen->GetDrawItems(); item; item = secondItem )
|
2017-11-27 19:27:24 +00:00
|
|
|
{
|
|
|
|
secondItem = item->Next();
|
2017-12-13 05:12:06 +00:00
|
|
|
|
2019-04-22 08:58:06 +00:00
|
|
|
if( item->GetEditFlags() & STRUCT_DELETED )
|
2019-03-11 21:32:05 +00:00
|
|
|
RemoveFromScreen( item, aScreen );
|
2019-03-23 21:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( itemList.GetCount() && aUndo )
|
|
|
|
SaveCopyInUndoList( itemList, UR_DELETED, true );
|
|
|
|
|
|
|
|
return itemList.GetCount() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::AddMissingJunctions( SCH_SCREEN* aScreen )
|
|
|
|
{
|
|
|
|
bool added = false;
|
|
|
|
|
|
|
|
auto add_junction = [ & ]( const wxPoint& aPosition ) -> void
|
|
|
|
{
|
|
|
|
auto junction = new SCH_JUNCTION( aPosition );
|
|
|
|
AddToScreen( junction, aScreen );
|
|
|
|
BreakSegments( aPosition, false );
|
|
|
|
added = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
for( auto item = aScreen->GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_LINE_T )
|
2019-03-23 20:53:26 +00:00
|
|
|
{
|
|
|
|
auto line = static_cast<SCH_LINE*>( item );
|
|
|
|
|
2019-03-23 21:34:27 +00:00
|
|
|
if( aScreen->IsJunctionNeeded( line->GetStartPoint(), true ) )
|
2019-03-23 20:53:26 +00:00
|
|
|
add_junction( line->GetStartPoint() );
|
|
|
|
|
2019-03-23 21:34:27 +00:00
|
|
|
if( aScreen->IsJunctionNeeded( line->GetEndPoint(), true ) )
|
2019-03-23 20:53:26 +00:00
|
|
|
add_junction( line->GetEndPoint() );
|
|
|
|
}
|
2017-11-27 19:27:24 +00:00
|
|
|
}
|
2017-12-13 05:12:06 +00:00
|
|
|
|
2019-03-23 21:34:27 +00:00
|
|
|
return added;
|
|
|
|
}
|
2019-03-18 02:07:32 +00:00
|
|
|
|
2019-03-23 21:34:27 +00:00
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::NormalizeSchematicOnFirstLoad()
|
|
|
|
{
|
|
|
|
BreakSegmentsOnJunctions();
|
|
|
|
SchematicCleanUp();
|
|
|
|
|
|
|
|
SCH_SHEET_LIST list( g_RootSheet );
|
|
|
|
|
|
|
|
for( const auto& sheet : list )
|
|
|
|
AddMissingJunctions( sheet.LastScreen() );
|
2017-10-25 22:21:42 +00:00
|
|
|
}
|
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
bool SCH_EDIT_FRAME::BreakSegment( SCH_LINE* aSegment, const wxPoint& aPoint,
|
|
|
|
bool aAppend, SCH_LINE** aNewSegment,
|
|
|
|
SCH_SCREEN* aScreen )
|
2017-10-26 15:25:47 +00:00
|
|
|
{
|
|
|
|
if( !IsPointOnSegment( aSegment->GetStartPoint(), aSegment->GetEndPoint(), aPoint )
|
|
|
|
|| aSegment->IsEndPoint( aPoint ) )
|
|
|
|
return false;
|
|
|
|
|
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
|
|
|
|
2019-04-13 02:51:18 +00:00
|
|
|
SaveCopyInUndoList( newSegment, UR_NEW, aAppend );
|
|
|
|
SaveCopyInUndoList( aSegment, UR_CHANGED, true );
|
2019-03-18 02:07:32 +00:00
|
|
|
|
2018-10-24 22:18:53 +00:00
|
|
|
RefreshItem( aSegment );
|
|
|
|
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-04-26 22:23:12 +00:00
|
|
|
bool SCH_EDIT_FRAME::BreakSegments( const wxPoint& aPoint, bool aAppend, 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-03-11 21:32:05 +00:00
|
|
|
for( SCH_ITEM* segment = aScreen->GetDrawItems(); segment; segment = segment->Next() )
|
2017-10-26 15:25:47 +00:00
|
|
|
{
|
|
|
|
if( ( segment->Type() != SCH_LINE_T ) || ( segment->GetLayer() == LAYER_NOTES ) )
|
|
|
|
continue;
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
brokenSegments |= BreakSegment( (SCH_LINE*) segment, aPoint,
|
|
|
|
aAppend || brokenSegments, NULL, aScreen );
|
2017-10-26 15:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return brokenSegments;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
bool SCH_EDIT_FRAME::BreakSegmentsOnJunctions( bool aAppend, 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-03-11 21:32:05 +00:00
|
|
|
for( SCH_ITEM* item = aScreen->GetDrawItems(); item; item = item->Next() )
|
2017-10-26 15:25:47 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == SCH_JUNCTION_T )
|
|
|
|
{
|
|
|
|
SCH_JUNCTION* junction = ( SCH_JUNCTION* ) item;
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
if( BreakSegments( junction->GetPosition(), brokenSegments || aAppend, aScreen ) )
|
2017-10-26 15:25:47 +00:00
|
|
|
brokenSegments = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_BUS_ENTRY_BASE* busEntry = dynamic_cast<SCH_BUS_ENTRY_BASE*>( item );
|
|
|
|
if( busEntry )
|
|
|
|
{
|
2019-04-13 02:53:41 +00:00
|
|
|
if( BreakSegments( busEntry->GetPosition(), brokenSegments || aAppend, aScreen ) )
|
|
|
|
brokenSegments = true;
|
|
|
|
|
|
|
|
if( BreakSegments( busEntry->m_End(), brokenSegments || aAppend, aScreen ) )
|
2017-10-26 15:25:47 +00:00
|
|
|
brokenSegments = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
PICKED_ITEMS_LIST itemList;
|
|
|
|
|
|
|
|
auto remove_item = [ & ]( SCH_ITEM* aItem ) -> void
|
|
|
|
{
|
|
|
|
aItem->SetFlags( STRUCT_DELETED );
|
|
|
|
itemList.PushItem( ITEM_PICKER( aItem, UR_DELETED ) );
|
2018-08-03 12:18:26 +00:00
|
|
|
RemoveFromScreen( aItem );
|
2018-02-02 20:04:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
remove_item( aJunction );
|
|
|
|
|
|
|
|
for( SCH_ITEM* item = screen->GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
SCH_LINE* firstLine = dynamic_cast<SCH_LINE*>( item );
|
|
|
|
|
|
|
|
if( !firstLine || !firstLine->IsEndPoint( aJunction->GetPosition() )
|
2019-04-22 08:58:06 +00:00
|
|
|
|| ( firstLine->GetEditFlags() & STRUCT_DELETED ) )
|
2018-02-02 20:04:36 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
for( SCH_ITEM* secondItem = item->Next(); secondItem; secondItem = secondItem->Next() )
|
|
|
|
{
|
|
|
|
SCH_LINE* secondLine = dynamic_cast<SCH_LINE*>( secondItem );
|
|
|
|
|
|
|
|
if( !secondLine || !secondLine->IsEndPoint( aJunction->GetPosition() )
|
2019-04-22 08:58:06 +00:00
|
|
|
|| ( secondItem->GetEditFlags() & STRUCT_DELETED )
|
2018-02-02 20:04:36 +00:00
|
|
|
|| !secondLine->IsParallel( firstLine ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
// Remove identical lines
|
|
|
|
if( firstLine->IsEndPoint( secondLine->GetStartPoint() )
|
|
|
|
&& firstLine->IsEndPoint( secondLine->GetEndPoint() ) )
|
|
|
|
{
|
|
|
|
remove_item( secondItem );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to merge the remaining lines
|
|
|
|
if( SCH_LINE* line = (SCH_LINE*) secondLine->MergeOverlap( firstLine ) )
|
|
|
|
{
|
|
|
|
remove_item( item );
|
|
|
|
remove_item( secondItem );
|
|
|
|
itemList.PushItem( ITEM_PICKER( line, UR_NEW ) );
|
2018-08-03 12:18:26 +00:00
|
|
|
AddToScreen( line );
|
2018-02-02 20:04:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SaveCopyInUndoList( itemList, UR_DELETED, aAppend );
|
|
|
|
|
|
|
|
SCH_ITEM* nextitem;
|
|
|
|
for( SCH_ITEM* item = screen->GetDrawItems(); item; item = nextitem )
|
|
|
|
{
|
|
|
|
nextitem = item->Next();
|
|
|
|
|
2019-04-22 08:58:06 +00:00
|
|
|
if( item->GetEditFlags() & STRUCT_DELETED )
|
2018-08-03 12:18:26 +00:00
|
|
|
RemoveFromScreen( item );
|
2018-02-02 20:04:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-26 22:23:12 +00:00
|
|
|
SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( const wxPoint& aPosition, bool aAppend, bool aFinal )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-02-05 02:21:11 +00:00
|
|
|
SCH_JUNCTION* junction = new SCH_JUNCTION( aPosition );
|
2017-11-27 19:27:24 +00:00
|
|
|
bool broken_segments = false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
AddToScreen( junction );
|
2017-11-27 19:27:24 +00:00
|
|
|
broken_segments = BreakSegments( aPosition, aAppend );
|
|
|
|
SaveCopyInUndoList( junction, UR_NEW, broken_segments || aAppend );
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2019-03-18 02:07:32 +00:00
|
|
|
if( aFinal )
|
|
|
|
{
|
|
|
|
TestDanglingEnds();
|
|
|
|
OnModify();
|
|
|
|
|
|
|
|
auto view = GetCanvas()->GetView();
|
|
|
|
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
|
|
|
|
2017-11-16 20:39:59 +00:00
|
|
|
SCH_NO_CONNECT* SCH_EDIT_FRAME::AddNoConnect( const wxPoint& aPosition )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2013-08-05 21:02:41 +00:00
|
|
|
SCH_NO_CONNECT* no_connect = new SCH_NO_CONNECT( aPosition );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-08-05 21:02:41 +00:00
|
|
|
SetRepeatItem( no_connect );
|
2018-08-03 12:18:26 +00:00
|
|
|
AddToScreen( no_connect );
|
2017-10-25 22:21:42 +00:00
|
|
|
SchematicCleanUp();
|
2018-10-16 13:11:33 +00:00
|
|
|
TestDanglingEnds();
|
2010-12-08 20:12:46 +00:00
|
|
|
OnModify();
|
2018-08-03 12:18:26 +00:00
|
|
|
|
|
|
|
auto view = GetCanvas()->GetView();
|
|
|
|
view->ClearPreview();
|
|
|
|
view->ShowPreview( false );
|
|
|
|
view->ClearHiddenFlags();
|
|
|
|
|
2013-08-05 21:02:41 +00:00
|
|
|
SaveCopyInUndoList( no_connect, UR_NEW );
|
|
|
|
return no_connect;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|