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
|
2011-10-19 20:32:21 +00:00
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <wxEeschemaStruct.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 <protos.h>
|
|
|
|
#include <sch_bus_entry.h>
|
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_no_connect.h>
|
|
|
|
#include <sch_polyline.h>
|
|
|
|
#include <sch_text.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_sheet.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
static void AbortCreateNewLine( EDA_DRAW_PANEL* Panel, wxDC* DC );
|
2009-12-02 21:44:03 +00:00
|
|
|
static void ComputeBreakPoint( SCH_LINE* segment, const wxPoint& new_pos );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
static DLIST< SCH_ITEM > s_wires;
|
|
|
|
static DLIST< SCH_ITEM > s_oldWires;
|
|
|
|
|
|
|
|
static wxPoint s_startPoint;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
/**
|
|
|
|
* Mouse capture callback for drawing line segments.
|
|
|
|
*/
|
2011-02-03 19:27:28 +00:00
|
|
|
static void DrawSegment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase )
|
2010-12-08 20:12:46 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* segment;
|
|
|
|
int color;
|
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
if( s_wires.GetCount() == 0 )
|
2010-12-08 20:12:46 +00:00
|
|
|
return;
|
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
segment = (SCH_LINE*) s_wires.begin();
|
|
|
|
color = ReturnLayerColor( segment->GetLayer() ) ^ HIGHLIGHT_FLAG;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
|
|
|
if( aErase )
|
|
|
|
{
|
|
|
|
while( segment )
|
|
|
|
{
|
|
|
|
if( !segment->IsNull() ) // Redraw if segment length != 0
|
2011-01-10 16:50:40 +00:00
|
|
|
segment->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, color );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
|
|
|
segment = segment->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
wxPoint endpos = aPanel->GetScreen()->GetCrossHairPosition();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
|
|
|
if( g_HVLines ) /* Coerce the line to vertical or horizontal one: */
|
2012-02-26 18:39:39 +00:00
|
|
|
ComputeBreakPoint( (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
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
segment = (SCH_LINE*) s_wires.begin();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
|
|
|
while( segment )
|
|
|
|
{
|
|
|
|
if( !segment->IsNull() ) // Redraw if segment length != 0
|
2011-01-10 16:50:40 +00:00
|
|
|
segment->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, color );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
|
|
|
segment = segment->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
SCH_LINE* segment;
|
|
|
|
SCH_LINE* nextSegment;
|
2011-02-11 20:48:13 +00:00
|
|
|
wxPoint cursorpos = GetScreen()->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() )
|
|
|
|
{
|
|
|
|
wxLogDebug( wxT( "BeginSegment: item->GetFlags()== %X" ),
|
|
|
|
segment->GetFlags() );
|
|
|
|
}
|
|
|
|
// no wire, bus or graphic line in progress
|
|
|
|
segment = NULL;
|
|
|
|
}
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
if( !segment ) /* first point : Create first wire or bus */
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
s_startPoint = cursorpos;
|
|
|
|
GetScreen()->ExtractWires( s_oldWires, true );
|
2011-12-22 13:28:11 +00:00
|
|
|
GetScreen()->SchematicCleanUp( m_canvas );
|
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.
|
|
|
|
if( g_HVLines )
|
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 );
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat = 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
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
SCH_LINE* prevSegment = (SCH_LINE*) segment->Back();
|
|
|
|
|
2012-03-19 07:48:29 +00:00
|
|
|
wxLogDebug( wxT( "Adding new segment after " ) + prevSegment->GetSelectMenuText() );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
|
|
|
if( !g_HVLines )
|
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;
|
|
|
|
}
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, 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
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
EndSegment( DC );
|
|
|
|
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 );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::EndSegment( wxDC* DC )
|
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();
|
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;
|
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
// Delete zero length segments and clear item flags.
|
|
|
|
SCH_ITEM* item = s_wires.begin();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
while( item )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
item->ClearFlags();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
wxCHECK_RET( item->Type() == SCH_LINE_T, wxT( "Unexpected object type in wire list." ) );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
segment = (SCH_LINE*) item;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
if( segment->IsNull() )
|
|
|
|
{
|
|
|
|
wxLogDebug( wxT( "Removing null segment: " ) + segment->GetSelectMenuText() );
|
|
|
|
|
|
|
|
SCH_ITEM* previousSegment = item->Back();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
delete s_wires.Remove( item );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
if( previousSegment == NULL )
|
|
|
|
item = s_wires.begin();
|
|
|
|
else
|
|
|
|
item = previousSegment;
|
2012-03-19 07:48:29 +00:00
|
|
|
wxLogDebug( wxT( "Segment count after removal: %d" ), s_wires.GetCount() );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
item = item->Next();
|
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
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
// Get the last non-null wire.
|
|
|
|
m_itemToRepeat = segment = (SCH_LINE*) s_wires.GetLast();
|
|
|
|
screen->SetCurItem( NULL );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture( -1, -1, wxEmptyString, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
DLIST< SCH_ITEM > tmp;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
for( item = s_wires.begin(); item != NULL; item = item->Next() )
|
|
|
|
tmp.PushBack( (SCH_ITEM*) item->Clone() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
// Temporarily add the new segments to the schematic item list to test if any
|
|
|
|
// junctions are required.
|
|
|
|
screen->Append( tmp );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
// Correct and remove segments that need merged.
|
2012-03-09 18:58:58 +00:00
|
|
|
screen->SchematicCleanUp( NULL, DC );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
// A junction may be needed to connect the last segment. If the last segment was
|
|
|
|
// removed by a cleanup, a junction may be needed to connect the segment's end point
|
|
|
|
// which is also the same as the previous segment's start point.
|
|
|
|
if( screen->IsJunctionNeeded( segment->GetEndPoint() ) )
|
|
|
|
s_wires.Append( AddJunction( DC, segment->GetEndPoint() ) );
|
|
|
|
else if( screen->IsJunctionNeeded( segment->GetStartPoint() ) )
|
|
|
|
s_wires.Append( AddJunction( DC, segment->GetStartPoint() ) );
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
// Automatically place a junction on the start point if necessary because the cleanup
|
|
|
|
// can suppress intermediate points by merging wire segments.
|
|
|
|
if( screen->IsJunctionNeeded( s_startPoint ) )
|
|
|
|
s_wires.Append( AddJunction( DC, s_startPoint ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
// Make a copy of the original wires, buses, and junctions.
|
|
|
|
for( item = s_oldWires.begin(); item != NULL; item = item->Next() )
|
|
|
|
tmp.PushBack( (SCH_ITEM*) item->Clone() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
// Restore the old wires.
|
|
|
|
if( tmp.GetCount() != 0 )
|
|
|
|
screen->ReplaceWires( tmp );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
// Now add the new wires and any required junctions to the schematic item list.
|
|
|
|
screen->Append( s_wires );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-03-09 18:58:58 +00:00
|
|
|
screen->SchematicCleanUp( NULL, DC );
|
|
|
|
m_canvas->Refresh();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
// Put the snap shot of the previous wire, buses, and junctions in the undo/redo list.
|
|
|
|
PICKED_ITEMS_LIST oldItems;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
oldItems.m_Status = UR_WIRE_IMAGE;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
while( s_oldWires.GetCount() != 0 )
|
|
|
|
{
|
|
|
|
ITEM_PICKER picker = ITEM_PICKER( s_oldWires.PopFront(), UR_WIRE_IMAGE );
|
|
|
|
oldItems.PushItem( picker );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
SaveCopyInUndoList( oldItems, UR_WIRE_IMAGE );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
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
|
|
|
|
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
|
|
|
*/
|
2011-11-10 15:55:05 +00:00
|
|
|
static void ComputeBreakPoint( SCH_LINE* aSegment, const wxPoint& aPosition )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
wxCHECK_RET( aSegment != NULL, wxT( "Cannot compute break point of NULL line segment." ) );
|
|
|
|
|
|
|
|
SCH_LINE* nextSegment = aSegment->Next();
|
|
|
|
wxPoint midPoint = aPosition;
|
|
|
|
|
|
|
|
wxCHECK_RET( nextSegment != NULL,
|
|
|
|
wxT( "Cannot compute break point of NULL second line segment." ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
#if 0
|
2012-02-26 18:39:39 +00:00
|
|
|
if( ABS( midPoint.x - aSegment->GetStartPoint().x ) <
|
|
|
|
ABS( midPoint.y - aSegment->GetStartPoint().y ) )
|
|
|
|
midPoint.x = aSegment->GetStartPoint().x;
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2012-02-26 18:39:39 +00:00
|
|
|
midPoint.y = aSegment->GetStartPoint().y;
|
2007-05-06 16:03:28 +00:00
|
|
|
#else
|
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
|
|
|
|
|
|
|
if( iDy != 0 ) // keep the first segment orientation (currently horizontal)
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
midPoint.x = aSegment->GetStartPoint().x;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
else if( iDx != 0 ) // keep the first segment orientation (currently vertical)
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
midPoint.y = aSegment->GetStartPoint().y;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
if( ABS( midPoint.x - aSegment->GetStartPoint().x ) <
|
|
|
|
ABS( midPoint.y - aSegment->GetStartPoint().y ) )
|
|
|
|
midPoint.x = aSegment->GetStartPoint().x;
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2012-02-26 18:39:39 +00:00
|
|
|
midPoint.y = aSegment->GetStartPoint().y;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif
|
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
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::DeleteCurrentSegment( wxDC* DC )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-02-05 02:21:11 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat = 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;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Cancel trace in progress */
|
2011-02-05 02:21:11 +00:00
|
|
|
if( screen->GetCurItem()->Type() == SCH_POLYLINE_T )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-05 02:21:11 +00:00
|
|
|
SCH_POLYLINE* polyLine = (SCH_POLYLINE*) screen->GetCurItem();
|
|
|
|
wxPoint endpos;
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
endpos = screen->GetCrossHairPosition();
|
2011-02-05 02:21:11 +00:00
|
|
|
|
|
|
|
int idx = polyLine->GetCornerCount() - 1;
|
2011-12-08 15:45:01 +00:00
|
|
|
wxPoint pt = (*polyLine)[idx];
|
2011-02-05 02:21:11 +00:00
|
|
|
|
|
|
|
if( g_HVLines )
|
|
|
|
{
|
|
|
|
/* Coerce the line to vertical or horizontal one: */
|
2011-12-08 15:45:01 +00:00
|
|
|
if( ABS( endpos.x - pt.x ) < ABS( endpos.y - pt.y ) )
|
|
|
|
endpos.x = pt.x;
|
2011-02-05 02:21:11 +00:00
|
|
|
else
|
2011-12-08 15:45:01 +00:00
|
|
|
endpos.y = pt.y;
|
2011-02-05 02:21:11 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
polyLine->SetPoint( idx, endpos );
|
2011-12-22 13:28:11 +00:00
|
|
|
polyLine->Draw( m_canvas, DC, wxPoint( 0, 0 ), g_XorMode );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
DrawSegment( m_canvas, DC, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
screen->Remove( 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aPutInUndoList )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-02-05 02:21:11 +00:00
|
|
|
SCH_JUNCTION* junction = new SCH_JUNCTION( aPosition );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
m_itemToRepeat = junction;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( aDC ); // Erase schematic cursor
|
|
|
|
junction->Draw( m_canvas, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
|
|
|
m_canvas->CrossHairOn( aDC ); // Display schematic cursor
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
if( aPutInUndoList )
|
2012-02-26 18:39:39 +00:00
|
|
|
{
|
|
|
|
GetScreen()->Append( junction );
|
2011-02-05 02:21:11 +00:00
|
|
|
SaveCopyInUndoList( junction, UR_NEW );
|
2012-02-26 18:39:39 +00:00
|
|
|
OnModify();
|
|
|
|
}
|
2010-12-08 20:12:46 +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
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
SCH_NO_CONNECT* SCH_EDIT_FRAME::AddNoConnect( wxDC* aDC, const wxPoint& aPosition )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
|
|
|
SCH_NO_CONNECT* NewNoConnect;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
NewNoConnect = new SCH_NO_CONNECT( aPosition );
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat = NewNoConnect;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( aDC ); // Erase schematic cursor
|
|
|
|
NewNoConnect->Draw( m_canvas, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
|
|
|
m_canvas->CrossHairOn( aDC ); // Display schematic cursor
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
GetScreen()->Append( NewNoConnect );
|
2010-12-08 20:12:46 +00:00
|
|
|
OnModify();
|
2009-07-26 17:16:42 +00:00
|
|
|
SaveCopyInUndoList( NewNoConnect, UR_NEW );
|
2007-08-20 01:20:48 +00:00
|
|
|
return NewNoConnect;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Abort function for wire, bus or line creation
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
static void AbortCreateNewLine( EDA_DRAW_PANEL* Panel, wxDC* DC )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-02-05 02:21:11 +00:00
|
|
|
SCH_SCREEN* screen = (SCH_SCREEN*) Panel->GetScreen();
|
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
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
s_wires.DeleteAll();
|
|
|
|
s_oldWires.DeleteAll();
|
2011-02-05 02:21:11 +00:00
|
|
|
screen->SetCurItem( NULL );
|
2009-08-28 07:11:56 +00:00
|
|
|
Panel->Refresh();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
2011-01-12 21:47:54 +00:00
|
|
|
{
|
|
|
|
SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) Panel->GetParent();
|
|
|
|
parent->SetRepeatItem( NULL );
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
// Clear flags used in edit functions.
|
|
|
|
screen->ClearDrawingState();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-01-12 21:47:54 +00:00
|
|
|
if( m_itemToRepeat == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
m_itemToRepeat = (SCH_ITEM*) m_itemToRepeat->Clone();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-12 21:47:54 +00:00
|
|
|
if( m_itemToRepeat->Type() == SCH_COMPONENT_T ) // If repeat component then put in move mode
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
wxPoint pos = GetScreen()->GetCrossHairPosition() -
|
2011-10-19 20:32:21 +00:00
|
|
|
( (SCH_COMPONENT*) m_itemToRepeat )->GetPosition();
|
2011-03-10 19:36:30 +00:00
|
|
|
m_itemToRepeat->SetFlags( IS_NEW );
|
2011-12-12 08:37:05 +00:00
|
|
|
( (SCH_COMPONENT*) m_itemToRepeat )->SetTimeStamp( GetNewTimeStamp() );
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat->Move( pos );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_itemToRepeat->Draw( m_canvas, DC, wxPoint( 0, 0 ), g_XorMode );
|
2011-10-19 20:32:21 +00:00
|
|
|
MoveItem( m_itemToRepeat, DC );
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
2010-12-21 15:13:09 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat->Move( wxPoint( g_RepeatStep.GetWidth(), g_RepeatStep.GetHeight() ) );
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
if( m_itemToRepeat->CanIncrementLabel() )
|
2011-01-12 21:47:54 +00:00
|
|
|
( (SCH_TEXT*) m_itemToRepeat )->IncrementLabel();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-12 21:47:54 +00:00
|
|
|
if( m_itemToRepeat )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-02-26 18:39:39 +00:00
|
|
|
GetScreen()->Append( m_itemToRepeat );
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->TestDanglingEnds();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_itemToRepeat->Draw( m_canvas, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2011-01-12 21:47:54 +00:00
|
|
|
SaveCopyInUndoList( m_itemToRepeat, UR_NEW );
|
2011-03-10 19:36:30 +00:00
|
|
|
m_itemToRepeat->ClearFlags();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|