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
|
2016-02-20 14:59:42 +00:00
|
|
|
* Copyright (C) 2004-2016 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
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file bus-wire-junction.cpp
|
|
|
|
* @brief Code for editing buses, wires, and junctions.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <lib_draw_item.h>
|
|
|
|
#include <lib_pin.h>
|
|
|
|
#include <general.h>
|
|
|
|
#include <sch_bus_entry.h>
|
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_no_connect.h>
|
|
|
|
#include <sch_text.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_sheet.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_view.h>
|
|
|
|
#include <view/view_group.h>
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2015-04-10 11:22:44 +00:00
|
|
|
static void AbortCreateNewLine( EDA_DRAW_PANEL* aPanel, wxDC* aDC );
|
2018-05-11 20:49:18 +00:00
|
|
|
static void ComputeBreakPoint( SCH_SCREEN* aScreen, SCH_LINE* aSegment, wxPoint& new_pos );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-07-05 11:37:48 +00:00
|
|
|
static DLIST< SCH_ITEM > s_wires; // when creating a new set of wires,
|
|
|
|
// stores here the new wires.
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2015-06-23 15:01:34 +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:
|
|
|
|
* -------------------<====================>
|
|
|
|
*
|
|
|
|
* RemoveBacktracks is called:
|
|
|
|
* ------------------->
|
|
|
|
*/
|
|
|
|
static void RemoveBacktracks( DLIST<SCH_ITEM>& aWires )
|
|
|
|
{
|
|
|
|
EDA_ITEM* first = aWires.GetFirst();
|
2016-03-30 00:25:15 +00:00
|
|
|
std::vector<SCH_LINE*> last_lines;
|
|
|
|
|
2015-06-23 15:01:34 +00:00
|
|
|
for( EDA_ITEM* p = first; p; )
|
|
|
|
{
|
2016-03-30 00:25:15 +00:00
|
|
|
SCH_LINE *line = static_cast<SCH_LINE*>( p );
|
2015-06-23 15:01:34 +00:00
|
|
|
p = line->Next();
|
|
|
|
|
2017-10-31 19:33:00 +00:00
|
|
|
if( line->IsNull() )
|
|
|
|
{
|
|
|
|
delete s_wires.Remove( line );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-03-30 00:25:15 +00:00
|
|
|
if( !last_lines.empty() )
|
2015-06-23 15:01:34 +00:00
|
|
|
{
|
2016-03-30 00:25:15 +00:00
|
|
|
SCH_LINE* last_line = last_lines[last_lines.size() - 1];
|
|
|
|
bool contiguous = ( last_line->GetEndPoint() == line->GetStartPoint() );
|
|
|
|
bool backtracks = IsPointOnSegment( last_line->GetStartPoint(),
|
|
|
|
last_line->GetEndPoint(), line->GetEndPoint() );
|
|
|
|
bool total_backtrack = ( last_line->GetStartPoint() == line->GetEndPoint() );
|
|
|
|
|
|
|
|
if( contiguous && backtracks )
|
2015-06-23 15:01:34 +00:00
|
|
|
{
|
2016-03-30 00:25:15 +00:00
|
|
|
if( total_backtrack )
|
|
|
|
{
|
|
|
|
delete s_wires.Remove( last_line );
|
|
|
|
delete s_wires.Remove( line );
|
|
|
|
last_lines.pop_back();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
last_line->SetEndPoint( line->GetEndPoint() );
|
|
|
|
delete s_wires.Remove( line );
|
|
|
|
}
|
2015-06-23 15:01:34 +00:00
|
|
|
}
|
|
|
|
else
|
2016-03-30 00:25:15 +00:00
|
|
|
{
|
|
|
|
last_lines.push_back( line );
|
|
|
|
}
|
2015-06-23 15:01:34 +00:00
|
|
|
}
|
|
|
|
else
|
2016-03-30 00:25:15 +00:00
|
|
|
{
|
|
|
|
last_lines.push_back( line );
|
|
|
|
}
|
2015-06-23 15:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
/**
|
|
|
|
* Mouse capture callback for drawing line segments.
|
|
|
|
*/
|
2018-09-09 21:06:38 +00:00
|
|
|
static void DrawSegment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase )
|
2010-12-08 20:12:46 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
if( s_wires.GetCount() == 0 )
|
2010-12-08 20:12:46 +00:00
|
|
|
return;
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) aPanel->GetParent();
|
|
|
|
|
|
|
|
wxPoint endpos = frame->GetCrossHairPosition();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-09-28 17:47:41 +00:00
|
|
|
if( frame->GetForceHVLines() ) /* Coerce the line to vertical or horizontal one: */
|
2018-05-11 20:49:18 +00:00
|
|
|
ComputeBreakPoint( frame->GetScreen(), (SCH_LINE*) s_wires.GetLast()->Back(), endpos );
|
2010-12-08 20:12:46 +00:00
|
|
|
else
|
2012-02-26 18:39:39 +00:00
|
|
|
( (SCH_LINE*) s_wires.GetLast() )->SetEndPoint( endpos );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
auto view = static_cast<SCH_DRAW_PANEL*>( aPanel )->GetView();
|
|
|
|
|
|
|
|
view->ClearPreview();
|
|
|
|
|
2018-09-09 21:06:38 +00:00
|
|
|
for( SCH_LINE* segment = (SCH_LINE*) s_wires.begin(); segment; segment = segment->Next() )
|
2010-12-08 20:12:46 +00:00
|
|
|
{
|
2018-09-09 21:06:38 +00:00
|
|
|
if( !segment->IsNull() ) // Add to preview if segment length != 0
|
2018-08-03 12:18:26 +00:00
|
|
|
view->AddToPreview( segment->Clone() );
|
2010-12-08 20:12:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-09 21:06:38 +00:00
|
|
|
void SCH_EDIT_FRAME::BeginSegment( int type )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
SCH_LINE* segment;
|
|
|
|
SCH_LINE* nextSegment;
|
2013-08-03 05:15:23 +00:00
|
|
|
wxPoint cursorpos = GetCrossHairPosition();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-03-19 07:48:29 +00:00
|
|
|
// We should know if a segment is currently in progress
|
2012-02-26 18:39:39 +00:00
|
|
|
segment = (SCH_LINE*) GetScreen()->GetCurItem();
|
2012-03-16 19:08:57 +00:00
|
|
|
if( segment ) // a current item exists, but not necessary a currently edited item
|
|
|
|
{
|
|
|
|
if( !segment->GetFlags() || ( segment->Type() != SCH_LINE_T ) )
|
|
|
|
{
|
|
|
|
if( segment->GetFlags() )
|
2018-09-09 21:06:38 +00:00
|
|
|
wxLogDebug( wxT( "BeginSegment: item->GetFlags()== %X" ), segment->GetFlags() );
|
|
|
|
|
2012-03-16 19:08:57 +00:00
|
|
|
// no wire, bus or graphic line in progress
|
|
|
|
segment = NULL;
|
|
|
|
}
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2015-04-10 11:22:44 +00:00
|
|
|
if( !segment ) // first point : Create the first wire or bus segment
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
default:
|
2012-02-26 18:39:39 +00:00
|
|
|
segment = new SCH_LINE( cursorpos, LAYER_NOTES );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_WIRE:
|
2012-02-26 18:39:39 +00:00
|
|
|
segment = new SCH_LINE( cursorpos, LAYER_WIRE );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* A junction will be created later, when we'll know the
|
|
|
|
* segment end position, and if the junction is really needed */
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_BUS:
|
2012-02-26 18:39:39 +00:00
|
|
|
segment = new SCH_LINE( cursorpos, LAYER_BUS );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
segment->SetFlags( IS_NEW );
|
|
|
|
s_wires.PushBack( segment );
|
|
|
|
GetScreen()->SetCurItem( segment );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-26 18:39:39 +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.
|
2012-09-28 17:47:41 +00:00
|
|
|
if( GetForceHVLines() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
nextSegment = new SCH_LINE( *segment );
|
|
|
|
nextSegment->SetFlags( IS_NEW );
|
|
|
|
s_wires.PushBack( nextSegment );
|
|
|
|
GetScreen()->SetCurItem( nextSegment );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( DrawSegment, AbortCreateNewLine );
|
2013-08-05 21:02:41 +00:00
|
|
|
SetRepeatItem( NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
else // A segment is in progress: terminates the current segment and add a new segment.
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2015-11-03 19:44:05 +00:00
|
|
|
SCH_LINE* prevSegment = segment->Back();
|
2012-02-26 18:39:39 +00:00
|
|
|
|
2012-07-21 16:52:29 +00:00
|
|
|
// Be aware prevSegment can be null when the horizontal and vertical lines only switch is off
|
|
|
|
// when we create the first segment.
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-09-28 17:47:41 +00:00
|
|
|
if( !GetForceHVLines() )
|
2009-11-03 13:26:31 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
// If only one segment is needed and it has a zero length, do not create a new one.
|
|
|
|
if( segment->IsNull() )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
wxCHECK_RET( prevSegment != NULL, wxT( "Failed to create second line segment." ) );
|
|
|
|
|
|
|
|
// If two segments are required and they both have zero length, do not
|
|
|
|
// create a new one.
|
|
|
|
if( prevSegment && prevSegment->IsNull() && segment->IsNull() )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-09 21:06:38 +00:00
|
|
|
m_canvas->CallMouseCapture( nullptr, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
// Terminate the command if the end point is on a pin, junction, or another wire or bus.
|
|
|
|
if( GetScreen()->IsTerminalPoint( cursorpos, segment->GetLayer() ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2017-11-16 20:39:59 +00:00
|
|
|
EndSegment();
|
2010-12-08 20:12:46 +00:00
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
// Create a new segment, and chain it after the current new segment.
|
|
|
|
nextSegment = new SCH_LINE( *segment );
|
|
|
|
nextSegment->SetStartPoint( cursorpos );
|
|
|
|
s_wires.PushBack( nextSegment );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
segment->SetEndPoint( cursorpos );
|
|
|
|
segment->ClearFlags( IS_NEW );
|
|
|
|
segment->SetFlags( SELECTED );
|
|
|
|
nextSegment->SetFlags( IS_NEW );
|
|
|
|
GetScreen()->SetCurItem( nextSegment );
|
2018-09-09 21:06:38 +00:00
|
|
|
m_canvas->CallMouseCapture( nullptr, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
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
|
|
|
|
if( !( item->GetFlags() & ( IS_DRAGGED | IS_MOVED | IS_DELETED ) ) )
|
|
|
|
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-11-16 20:39:59 +00:00
|
|
|
void SCH_EDIT_FRAME::EndSegment()
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
SCH_LINE* segment = (SCH_LINE*) screen->GetCurItem();
|
2017-11-27 19:27:24 +00:00
|
|
|
PICKED_ITEMS_LIST itemList;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
if( segment == NULL || segment->Type() != SCH_LINE_T || !segment->IsNew() )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
// Remove segments backtracking over others
|
|
|
|
RemoveBacktracks( s_wires );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
if( s_wires.GetCount() == 0 )
|
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
// Collect the possible connection points for the new lines
|
|
|
|
std::vector< wxPoint > connections;
|
|
|
|
std::vector< wxPoint > new_ends;
|
|
|
|
GetSchematicConnections( connections );
|
2013-08-05 21:02:41 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
// Check each new segment for possible junctions and add/split if needed
|
|
|
|
for( SCH_ITEM* wire = s_wires.GetFirst(); wire; wire=wire->Next() )
|
|
|
|
{
|
|
|
|
SCH_LINE* test_line = (SCH_LINE*) wire;
|
|
|
|
if( wire->GetFlags() & SKIP_STRUCT )
|
|
|
|
continue;
|
2012-07-05 11:37:48 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
wire->GetConnectionPoints( new_ends );
|
2015-04-10 11:22:44 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
for( auto i : connections )
|
|
|
|
{
|
|
|
|
if( IsPointOnSegment( test_line->GetStartPoint(), test_line->GetEndPoint(), i ) )
|
|
|
|
{
|
|
|
|
new_ends.push_back( i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
itemList.PushItem( ITEM_PICKER( wire, UR_NEW ) );
|
2015-04-10 11:22:44 +00:00
|
|
|
}
|
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
// Get the last non-null wire (this is the last created segment).
|
|
|
|
SetRepeatItem( segment = (SCH_LINE*) s_wires.GetLast() );
|
2015-06-23 15:01:34 +00:00
|
|
|
|
2015-04-10 11:22:44 +00:00
|
|
|
// Add the new wires
|
2018-08-03 12:18:26 +00:00
|
|
|
AddToScreen( s_wires );
|
|
|
|
|
|
|
|
auto view = GetCanvas()->GetView();
|
|
|
|
view->ClearPreview();
|
|
|
|
view->ShowPreview( false );
|
|
|
|
view->ClearHiddenFlags();
|
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
SaveCopyInUndoList(itemList, UR_NEW);
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-07-05 11:37:48 +00:00
|
|
|
// Correct and remove segments that need to be merged.
|
2017-11-27 19:27:24 +00:00
|
|
|
SchematicCleanUp( true );
|
2018-09-24 13:36:21 +00:00
|
|
|
|
|
|
|
for( auto item = GetScreen()->GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::vector< wxPoint > pts;
|
|
|
|
item->GetConnectionPoints( pts );
|
|
|
|
|
|
|
|
if( pts.size() > 2 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for( auto i = pts.begin(); i != pts.end(); i++ )
|
|
|
|
for( auto j = i + 1; j != pts.end(); j++ )
|
|
|
|
TrimWire( *i, *j, true );
|
|
|
|
}
|
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
for( auto i : new_ends )
|
|
|
|
{
|
|
|
|
if( screen->IsJunctionNeeded( i, true ) )
|
|
|
|
AddJunction( i, true );
|
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2018-10-16 13:11:33 +00:00
|
|
|
TestDanglingEnds();
|
2017-11-27 19:27:24 +00:00
|
|
|
screen->ClearDrawingState();
|
|
|
|
screen->SetCurItem( NULL );
|
|
|
|
m_canvas->EndMouseCapture( -1, -1, wxEmptyString, false );
|
2018-10-16 13:11:33 +00:00
|
|
|
m_canvas->Refresh();
|
2012-02-26 18:39:39 +00:00
|
|
|
OnModify();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-05-11 20:49:18 +00:00
|
|
|
// A helper function to find any sheet pins at the specified position.
|
|
|
|
static const SCH_SHEET_PIN* getSheetPin( SCH_SCREEN* aScreen, const wxPoint& aPosition )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item = aScreen->GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) item;
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PIN& pin : sheet->GetPins() )
|
|
|
|
{
|
|
|
|
if( pin.GetPosition() == aPosition )
|
|
|
|
return &pin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
/**
|
|
|
|
* Function ComputeBreakPoint
|
|
|
|
* computes the middle coordinate for 2 segments from the start point to \a aPosition
|
|
|
|
* with the segments kept in the horizontal or vertical axis only.
|
2012-02-26 18:39:39 +00:00
|
|
|
*
|
|
|
|
* @param aSegment A pointer to a #SCH_LINE object containing the first line break point
|
|
|
|
* to compute.
|
|
|
|
* @param aPosition A reference to a wxPoint object containing the coordinates of the
|
|
|
|
* position used to calculate the line break point.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2018-05-11 20:49:18 +00:00
|
|
|
static void ComputeBreakPoint( SCH_SCREEN* aScreen, SCH_LINE* aSegment, wxPoint& aPosition )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2018-05-11 20:49:18 +00:00
|
|
|
wxCHECK_RET( aSegment != nullptr, wxT( "Cannot compute break point of NULL line segment." ) );
|
2012-02-26 18:39:39 +00:00
|
|
|
|
|
|
|
SCH_LINE* nextSegment = aSegment->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-05-11 20:49:18 +00:00
|
|
|
wxPoint midPoint;
|
2011-12-07 20:19:29 +00:00
|
|
|
int iDx = aSegment->GetEndPoint().x - aSegment->GetStartPoint().x;
|
|
|
|
int iDy = aSegment->GetEndPoint().y - aSegment->GetStartPoint().y;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2018-05-11 20:49:18 +00:00
|
|
|
const SCH_SHEET_PIN* connectedPin = getSheetPin( aScreen, aSegment->GetStartPoint() );
|
|
|
|
auto force = connectedPin ? connectedPin->GetEdge() : SCH_SHEET_PIN::SHEET_UNDEFINED_SIDE;
|
|
|
|
|
|
|
|
if( force == SCH_SHEET_PIN::SHEET_LEFT_SIDE || force == SCH_SHEET_PIN::SHEET_RIGHT_SIDE )
|
|
|
|
{
|
|
|
|
if( aPosition.x == connectedPin->GetPosition().x ) // push outside sheet boundary
|
|
|
|
{
|
|
|
|
int direction = ( force == SCH_SHEET_PIN::SHEET_LEFT_SIDE ) ? -1 : 1;
|
|
|
|
aPosition.x += aScreen->GetGridSize().x * direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
midPoint.x = aPosition.x;
|
|
|
|
midPoint.y = aSegment->GetStartPoint().y; // force horizontal
|
|
|
|
}
|
|
|
|
else if( iDy != 0 ) // keep the first segment orientation (vertical)
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
midPoint.x = aSegment->GetStartPoint().x;
|
2018-05-11 20:49:18 +00:00
|
|
|
midPoint.y = aPosition.y;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2018-05-11 20:49:18 +00:00
|
|
|
else if( iDx != 0 ) // keep the first segment orientation (horizontal)
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2018-05-11 20:49:18 +00:00
|
|
|
midPoint.x = aPosition.x;
|
2012-02-26 18:39:39 +00:00
|
|
|
midPoint.y = aSegment->GetStartPoint().y;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-11 20:49:18 +00:00
|
|
|
if( std::abs( aPosition.x - aSegment->GetStartPoint().x ) <
|
|
|
|
std::abs( aPosition.y - aSegment->GetStartPoint().y ) )
|
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
midPoint.x = aSegment->GetStartPoint().x;
|
2018-05-11 20:49:18 +00:00
|
|
|
midPoint.y = aPosition.y;
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2018-05-11 20:49:18 +00:00
|
|
|
{
|
|
|
|
midPoint.x = aPosition.x;
|
2012-02-26 18:39:39 +00:00
|
|
|
midPoint.y = aSegment->GetStartPoint().y;
|
2018-05-11 20:49:18 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
aSegment->SetEndPoint( midPoint );
|
|
|
|
nextSegment->SetStartPoint( midPoint );
|
|
|
|
nextSegment->SetEndPoint( aPosition );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-09-09 21:06:38 +00:00
|
|
|
void SCH_EDIT_FRAME::DeleteCurrentSegment()
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-02-05 02:21:11 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
|
2013-08-05 21:02:41 +00:00
|
|
|
SetRepeatItem( NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
if( ( screen->GetCurItem() == NULL ) || !screen->GetCurItem()->IsNew() )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
RemoveFromScreen( screen->GetCurItem() );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetMouseCaptureCallback( NULL );
|
2011-02-05 02:21:11 +00:00
|
|
|
screen->SetCurItem( NULL );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-26 15:25:47 +00:00
|
|
|
void SCH_EDIT_FRAME::SaveWireImage()
|
|
|
|
{
|
2018-09-05 12:46:29 +00:00
|
|
|
PICKED_ITEMS_LIST oldItems;
|
|
|
|
oldItems.m_Status = UR_WIRE_IMAGE;
|
2017-10-26 15:25:47 +00:00
|
|
|
|
2018-09-05 12:46:29 +00:00
|
|
|
SCH_ITEM* item;
|
|
|
|
SCH_ITEM* next_item;
|
2017-10-26 15:25:47 +00:00
|
|
|
|
2018-09-05 12:46:29 +00:00
|
|
|
for( item = GetScreen()->GetDrawItems(); item; item = next_item )
|
2017-10-26 15:25:47 +00:00
|
|
|
{
|
2018-09-05 12:46:29 +00:00
|
|
|
next_item = item->Next();
|
2017-10-26 15:25:47 +00:00
|
|
|
|
2018-09-05 12:46:29 +00:00
|
|
|
if( item->Type() == SCH_JUNCTION_T || item->Type() == SCH_LINE_T )
|
2017-10-26 15:25:47 +00:00
|
|
|
{
|
2018-09-05 12:46:29 +00:00
|
|
|
GetScreen()->Remove( item );
|
|
|
|
GetCanvas()->GetView()->Remove( item );
|
|
|
|
|
|
|
|
oldItems.PushItem( ITEM_PICKER( item, UR_WIRE_IMAGE ) );
|
|
|
|
|
|
|
|
SCH_ITEM* item_copy = static_cast<SCH_ITEM*>( item->Clone() );
|
|
|
|
|
|
|
|
GetScreen()->GetDrawList().Insert( item_copy, next_item );
|
|
|
|
GetCanvas()->GetView()->Add( item_copy );
|
2017-10-26 15:25:47 +00:00
|
|
|
}
|
2018-09-05 12:46:29 +00:00
|
|
|
}
|
2017-10-26 15:25:47 +00:00
|
|
|
|
2018-09-05 12:46:29 +00:00
|
|
|
if( oldItems.GetCount() != 0 )
|
2017-10-26 15:25:47 +00:00
|
|
|
SaveCopyInUndoList( oldItems, UR_WIRE_IMAGE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2018-11-20 21:44:11 +00:00
|
|
|
if( item->GetFlags() & ( 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 );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
bool SCH_EDIT_FRAME::SchematicCleanUp( bool aAppend )
|
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;
|
|
|
|
SCH_SCREEN* screen = 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 ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
BreakSegmentsOnJunctions( true );
|
|
|
|
|
|
|
|
for( item = screen->GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
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;
|
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
if( item->GetFlags() & STRUCT_DELETED )
|
|
|
|
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 )
|
2017-12-13 05:12:06 +00:00
|
|
|
&& ( !screen->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() )
|
|
|
|
{
|
|
|
|
if( item->Type() != secondItem->Type() || ( secondItem->GetFlags() & STRUCT_DELETED ) )
|
|
|
|
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;
|
|
|
|
|
|
|
|
if( !secondLine->IsParallel( firstLine ) )
|
|
|
|
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() ) )
|
2017-11-27 19:27:24 +00:00
|
|
|
needed = screen->IsJunctionNeeded( firstLine->GetStartPoint() );
|
2017-12-13 05:12:06 +00:00
|
|
|
else if( secondLine->IsEndPoint( firstLine->GetEndPoint() ) )
|
2017-11-27 19:27:24 +00:00
|
|
|
needed = screen->IsJunctionNeeded( firstLine->GetEndPoint() );
|
|
|
|
|
|
|
|
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 ) );
|
2018-09-10 10:58:50 +00:00
|
|
|
AddToScreen( line );
|
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
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
for( item = screen->GetDrawItems(); item; item = secondItem )
|
|
|
|
{
|
|
|
|
secondItem = item->Next();
|
2017-12-13 05:12:06 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
if( item->GetFlags() & STRUCT_DELETED )
|
2018-08-03 12:18:26 +00:00
|
|
|
RemoveFromScreen( item );
|
2017-11-27 19:27:24 +00:00
|
|
|
}
|
2017-12-13 05:12:06 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
SaveCopyInUndoList( itemList, UR_CHANGED, aAppend );
|
2017-10-25 22:21:42 +00:00
|
|
|
|
2018-10-16 13:11:33 +00:00
|
|
|
return itemList.GetCount() > 0;
|
2017-10-25 22:21:42 +00:00
|
|
|
}
|
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
|
2017-12-01 22:53:23 +00:00
|
|
|
bool SCH_EDIT_FRAME::BreakSegment( SCH_LINE* aSegment, const wxPoint& aPoint, bool aAppend,
|
|
|
|
SCH_LINE** aNewSegment )
|
2017-10-26 15:25:47 +00:00
|
|
|
{
|
|
|
|
if( !IsPointOnSegment( aSegment->GetStartPoint(), aSegment->GetEndPoint(), aPoint )
|
|
|
|
|| aSegment->IsEndPoint( aPoint ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SaveCopyInUndoList( aSegment, UR_CHANGED, aAppend );
|
|
|
|
SCH_LINE* newSegment = new SCH_LINE( *aSegment );
|
|
|
|
SaveCopyInUndoList( newSegment, UR_NEW, true );
|
|
|
|
|
|
|
|
newSegment->SetStartPoint( aPoint );
|
2018-08-03 12:18:26 +00:00
|
|
|
AddToScreen( newSegment );
|
2017-10-26 15:25:47 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::BreakSegments( const wxPoint& aPoint, bool aAppend )
|
|
|
|
{
|
|
|
|
bool brokenSegments = false;
|
|
|
|
|
|
|
|
for( SCH_ITEM* segment = GetScreen()->GetDrawItems(); segment; segment = segment->Next() )
|
|
|
|
{
|
|
|
|
if( ( segment->Type() != SCH_LINE_T ) || ( segment->GetLayer() == LAYER_NOTES ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
brokenSegments |= BreakSegment( (SCH_LINE*) segment, aPoint, aAppend || brokenSegments );
|
|
|
|
}
|
|
|
|
|
|
|
|
return brokenSegments;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::BreakSegmentsOnJunctions( bool aAppend )
|
|
|
|
{
|
|
|
|
bool brokenSegments = false;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item = GetScreen()->GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_JUNCTION_T )
|
|
|
|
{
|
|
|
|
SCH_JUNCTION* junction = ( SCH_JUNCTION* ) item;
|
|
|
|
|
|
|
|
if( BreakSegments( junction->GetPosition(), brokenSegments || aAppend ) )
|
|
|
|
brokenSegments = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_BUS_ENTRY_BASE* busEntry = dynamic_cast<SCH_BUS_ENTRY_BASE*>( item );
|
|
|
|
if( busEntry )
|
|
|
|
{
|
|
|
|
if( BreakSegments( busEntry->GetPosition(), brokenSegments || aAppend )
|
|
|
|
|| BreakSegments( busEntry->m_End(), brokenSegments || aAppend ) )
|
|
|
|
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() )
|
|
|
|
|| ( firstLine->GetFlags() & STRUCT_DELETED ) )
|
|
|
|
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() )
|
|
|
|
|| ( secondItem->GetFlags() & STRUCT_DELETED )
|
|
|
|
|| !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();
|
|
|
|
|
|
|
|
if( item->GetFlags() & STRUCT_DELETED )
|
2018-08-03 12:18:26 +00:00
|
|
|
RemoveFromScreen( item );
|
2018-02-02 20:04:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( const wxPoint& aPosition, bool aAppend )
|
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 );
|
2018-10-16 13:11:33 +00:00
|
|
|
TestDanglingEnds();
|
2017-11-27 19:27:24 +00:00
|
|
|
OnModify();
|
|
|
|
SaveCopyInUndoList( junction, UR_NEW, broken_segments || aAppend );
|
2018-08-03 12:18:26 +00:00
|
|
|
|
|
|
|
auto view = GetCanvas()->GetView();
|
|
|
|
view->ClearPreview();
|
|
|
|
view->ShowPreview( false );
|
|
|
|
view->ClearHiddenFlags();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Abort function for wire, bus or line creation
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2015-04-10 11:22:44 +00:00
|
|
|
static void AbortCreateNewLine( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2015-04-10 11:22:44 +00:00
|
|
|
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
|
2018-08-03 12:18:26 +00:00
|
|
|
SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) aPanel->GetParent();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
if( screen->GetCurItem() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2015-04-10 11:22:44 +00:00
|
|
|
s_wires.DeleteAll(); // Free the list, for a future usage
|
2011-02-05 02:21:11 +00:00
|
|
|
screen->SetCurItem( NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
2011-01-12 21:47:54 +00:00
|
|
|
{
|
|
|
|
parent->SetRepeatItem( NULL );
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
auto view = static_cast<SCH_DRAW_PANEL*>(aPanel)->GetView();
|
|
|
|
view->ClearPreview();
|
|
|
|
view->ShowPreview( false );
|
|
|
|
view->ClearHiddenFlags();
|
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
// Clear flags used in edit functions.
|
|
|
|
screen->ClearDrawingState();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-09 21:06:38 +00:00
|
|
|
void SCH_EDIT_FRAME::RepeatDrawItem()
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2013-08-05 21:02:41 +00:00
|
|
|
SCH_ITEM* repeater = GetRepeatItem();
|
|
|
|
|
|
|
|
if( !repeater )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2013-08-05 21:02:41 +00:00
|
|
|
// clone the repeater, move it, insert into display list, then save a copy
|
|
|
|
// via SetRepeatItem();
|
|
|
|
|
|
|
|
SCH_ITEM* my_clone = (SCH_ITEM*) repeater->Clone();
|
|
|
|
|
|
|
|
// If cloning a component then put into 'move' mode.
|
|
|
|
if( my_clone->Type() == SCH_COMPONENT_T )
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
2018-09-09 21:06:38 +00:00
|
|
|
wxPoint pos = GetCrossHairPosition() - ( (SCH_COMPONENT*) my_clone )->GetPosition();
|
2013-08-03 05:15:23 +00:00
|
|
|
|
2013-08-05 21:02:41 +00:00
|
|
|
my_clone->SetFlags( IS_NEW );
|
|
|
|
( (SCH_COMPONENT*) my_clone )->SetTimeStamp( GetNewTimeStamp() );
|
|
|
|
my_clone->Move( pos );
|
2018-09-09 21:06:38 +00:00
|
|
|
PrepareMoveItem( my_clone );
|
2010-12-21 15:13:09 +00:00
|
|
|
}
|
2013-08-05 21:02:41 +00:00
|
|
|
else
|
|
|
|
{
|
2015-04-22 11:39:00 +00:00
|
|
|
my_clone->Move( GetRepeatStep() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-08-05 21:02:41 +00:00
|
|
|
if( my_clone->CanIncrementLabel() )
|
2015-04-22 11:39:00 +00:00
|
|
|
( (SCH_TEXT*) my_clone )->IncrementLabel( GetRepeatDeltaLabel() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
AddToScreen( my_clone );
|
2016-02-19 15:41:32 +00:00
|
|
|
|
|
|
|
if( my_clone->IsConnectable() )
|
2018-10-16 13:11:33 +00:00
|
|
|
TestDanglingEnds();
|
2016-02-19 15:41:32 +00:00
|
|
|
|
2013-08-05 21:02:41 +00:00
|
|
|
SaveCopyInUndoList( my_clone, UR_NEW );
|
|
|
|
my_clone->ClearFlags();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2013-08-05 21:02:41 +00:00
|
|
|
|
|
|
|
// clone my_clone, now that it has been moved, thus saving new position.
|
|
|
|
SetRepeatItem( my_clone );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2018-10-16 13:11:33 +00:00
|
|
|
|
|
|
|
|