2009-11-03 13:26:31 +00:00
|
|
|
/***************************************************************/
|
|
|
|
/* Code for handling creation of buses, wires, and junctions. */
|
|
|
|
/***************************************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "wxEeschemaStruct.h"
|
|
|
|
#include "class_sch_screen.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2010-10-08 20:40:57 +00:00
|
|
|
#include "lib_draw_item.h"
|
2010-10-22 12:11:52 +00:00
|
|
|
#include "lib_pin.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2010-12-21 15:13:09 +00:00
|
|
|
#include "sch_bus_entry.h"
|
2011-01-12 21:47:54 +00:00
|
|
|
#include "sch_junction.h"
|
2010-12-21 15:13:09 +00:00
|
|
|
#include "sch_line.h"
|
|
|
|
#include "sch_no_connect.h"
|
|
|
|
#include "sch_polyline.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#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
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* s_OldWiresList;
|
2009-11-03 13:26:31 +00:00
|
|
|
wxPoint s_ConnexionStartPoint;
|
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* CurrentLine = (SCH_LINE*) aPanel->GetScreen()->GetCurItem();
|
|
|
|
SCH_LINE* segment;
|
|
|
|
int color;
|
|
|
|
|
|
|
|
if( CurrentLine == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
color = ReturnLayerColor( CurrentLine->GetLayer() ) ^ HIGHLIGHT_FLAG;
|
|
|
|
|
|
|
|
if( aErase )
|
|
|
|
{
|
|
|
|
segment = CurrentLine;
|
|
|
|
|
|
|
|
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: */
|
|
|
|
ComputeBreakPoint( CurrentLine, endpos );
|
|
|
|
else
|
|
|
|
CurrentLine->m_End = endpos;
|
|
|
|
|
|
|
|
segment = CurrentLine;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-06 13:19:40 +00:00
|
|
|
/* Creates a new segment ( WIRE, BUS ),
|
|
|
|
* or terminates the current segment
|
2009-11-03 13:26:31 +00:00
|
|
|
* If the end of the current segment is on an other segment, place a junction
|
|
|
|
* if needed and terminates the command
|
2009-10-06 13:19:40 +00:00
|
|
|
* If the end of the current segment is on a pin, terminates the command
|
|
|
|
* In others cases starts a new segment
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* oldsegment, * newsegment, * nextsegment;
|
2011-02-11 20:48:13 +00:00
|
|
|
wxPoint cursorpos = GetScreen()->GetCrossHairPosition();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
if( GetScreen()->GetCurItem() && (GetScreen()->GetCurItem()->GetFlags() == 0) )
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetCurItem( NULL );
|
|
|
|
|
|
|
|
if( GetScreen()->GetCurItem() )
|
|
|
|
{
|
2007-09-01 12:00:30 +00:00
|
|
|
switch( GetScreen()->GetCurItem()->Type() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_LINE_T:
|
|
|
|
case SCH_POLYLINE_T:
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
oldsegment = newsegment = (SCH_LINE*) GetScreen()->GetCurItem();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
if( !newsegment ) /* first point : Create first wire or bus */
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
s_ConnexionStartPoint = cursorpos;
|
2011-02-03 19:27:28 +00:00
|
|
|
s_OldWiresList = GetScreen()->ExtractWires( true );
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->SchematicCleanUp( DrawPanel );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
default:
|
2009-12-02 21:44:03 +00:00
|
|
|
newsegment = new SCH_LINE( cursorpos, LAYER_NOTES );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_WIRE:
|
2009-12-02 21:44:03 +00:00
|
|
|
newsegment = 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:
|
2009-12-02 21:44:03 +00:00
|
|
|
newsegment = new SCH_LINE( cursorpos, LAYER_BUS );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
newsegment->SetFlags( IS_NEW );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
|
|
|
if( g_HVLines ) // We need 2 segments to go from a given start pin to an end point
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-12-21 15:13:09 +00:00
|
|
|
nextsegment = new SCH_LINE( *newsegment );
|
2011-03-10 19:36:30 +00:00
|
|
|
nextsegment->SetFlags( IS_NEW );
|
2008-11-24 06:53:43 +00:00
|
|
|
newsegment->SetNext( nextsegment );
|
|
|
|
nextsegment->SetBack( newsegment );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetCurItem( newsegment );
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->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
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
nextsegment = oldsegment->Next();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
|
|
|
if( !g_HVLines )
|
2009-11-03 13:26:31 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
// if only one segment is needed and it has length = 0, do not create a new one.
|
2007-08-20 01:20:48 +00:00
|
|
|
if( oldsegment->IsNull() )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
/* if we want 2 segment and the last two have len = 0, do not
|
|
|
|
* create a new one */
|
2007-08-20 01:20:48 +00:00
|
|
|
if( oldsegment->IsNull() && nextsegment && nextsegment->IsNull() )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-10-06 13:19:40 +00:00
|
|
|
/* Creates the new segment, or terminates the command
|
2009-11-03 13:26:31 +00:00
|
|
|
* if the end point is on a pin, junction or an other wire or bus */
|
2011-03-25 19:16:05 +00:00
|
|
|
if( GetScreen()->IsTerminalPoint( cursorpos, oldsegment->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
|
|
|
}
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
oldsegment->SetNext( GetScreen()->GetDrawItems() );
|
|
|
|
GetScreen()->SetDrawItems( oldsegment );
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->CrossHairOff( DC ); // Erase schematic cursor
|
2011-01-10 16:50:40 +00:00
|
|
|
oldsegment->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->CrossHairOn( DC ); // Display schematic cursor
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
/* Create a new segment, and chain it after the current new segment */
|
|
|
|
if( nextsegment )
|
|
|
|
{
|
2010-12-21 15:13:09 +00:00
|
|
|
newsegment = new SCH_LINE( *nextsegment );
|
2007-08-20 01:20:48 +00:00
|
|
|
nextsegment->m_Start = newsegment->m_End;
|
2008-11-24 06:53:43 +00:00
|
|
|
nextsegment->SetNext( NULL );
|
|
|
|
nextsegment->SetBack( newsegment );
|
|
|
|
newsegment->SetNext( nextsegment );
|
|
|
|
newsegment->SetBack( NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-21 15:13:09 +00:00
|
|
|
newsegment = new SCH_LINE( *oldsegment );
|
2007-08-20 01:20:48 +00:00
|
|
|
newsegment->m_Start = oldsegment->m_End;
|
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
newsegment->m_End = cursorpos;
|
2011-03-10 19:36:30 +00:00
|
|
|
oldsegment->ClearFlags( IS_NEW );
|
|
|
|
oldsegment->SetFlags( SELECTED );
|
|
|
|
newsegment->SetFlags( IS_NEW );
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetCurItem( newsegment );
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
2009-11-03 13:26:31 +00:00
|
|
|
|
|
|
|
/* This is the first segment: Now we know the start segment position.
|
|
|
|
* Create a junction if needed. Note: a junction can be needed later,
|
|
|
|
* if the new segment is merged (after a cleanup) with an older one
|
|
|
|
* (tested when the connection will be finished)*/
|
2007-08-20 01:20:48 +00:00
|
|
|
if( oldsegment->m_Start == s_ConnexionStartPoint )
|
2009-11-03 13:26:31 +00:00
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
if( GetScreen()->IsJunctionNeeded( s_ConnexionStartPoint ) )
|
2011-02-05 02:21:11 +00:00
|
|
|
AddJunction( DC, s_ConnexionStartPoint );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Called to terminate a bus, wire, or line creation
|
2007-08-20 01:20:48 +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
|
|
|
{
|
|
|
|
SCH_LINE* firstsegment = (SCH_LINE*) GetScreen()->GetCurItem();
|
|
|
|
SCH_LINE* lastsegment = firstsegment;
|
|
|
|
SCH_LINE* segment;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( firstsegment == NULL )
|
|
|
|
return;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2011-02-21 13:54:29 +00:00
|
|
|
if( !firstsegment->IsNew() )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Delete Null segments and Put line it in Drawlist */
|
|
|
|
lastsegment = firstsegment;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
while( lastsegment )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_LINE* nextsegment = lastsegment->Next();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( lastsegment->IsNull() )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_LINE* previous_segment = lastsegment->Back();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( firstsegment == lastsegment )
|
|
|
|
firstsegment = nextsegment;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( nextsegment )
|
2008-11-24 06:53:43 +00:00
|
|
|
nextsegment->SetBack( NULL );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( previous_segment )
|
2008-11-24 06:53:43 +00:00
|
|
|
previous_segment->SetNext( nextsegment );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
delete lastsegment;
|
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
lastsegment = nextsegment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* put the segment list to the main linked list */
|
|
|
|
segment = lastsegment = firstsegment;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
while( segment )
|
|
|
|
{
|
|
|
|
lastsegment = segment;
|
2009-11-03 13:26:31 +00:00
|
|
|
segment = segment->Next();
|
2010-12-08 20:12:46 +00:00
|
|
|
lastsegment->SetNext( GetScreen()->GetDrawItems() );
|
|
|
|
GetScreen()->SetDrawItems( lastsegment );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->SetMouseCapture( NULL, NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetCurItem( NULL );
|
|
|
|
|
|
|
|
wxPoint end_point, alt_end_point;
|
|
|
|
|
|
|
|
/* A junction can be needed to connect the last segment
|
|
|
|
* usually to m_End coordinate.
|
2009-11-03 13:26:31 +00:00
|
|
|
* But if the last segment is removed by a cleanup, because of redundancy,
|
|
|
|
* a junction can be needed to connect the previous segment m_End
|
|
|
|
* coordinate with is also the lastsegment->m_Start coordinate */
|
2007-08-20 01:20:48 +00:00
|
|
|
if( lastsegment )
|
|
|
|
{
|
|
|
|
end_point = lastsegment->m_End;
|
|
|
|
alt_end_point = lastsegment->m_Start;
|
|
|
|
}
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->SchematicCleanUp( DrawPanel );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
/* clear flags and find last segment entered, for repeat function */
|
2010-12-08 20:12:46 +00:00
|
|
|
segment = (SCH_LINE*) GetScreen()->GetDrawItems();
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
while( segment )
|
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
if( segment->GetFlags() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-01-12 21:47:54 +00:00
|
|
|
if( !m_itemToRepeat )
|
|
|
|
m_itemToRepeat = segment;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
segment->ClearFlags();
|
2008-11-24 06:53:43 +00:00
|
|
|
segment = segment->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Automatic place of a junction on the end point, if needed
|
|
|
|
if( lastsegment )
|
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
if( GetScreen()->IsJunctionNeeded( end_point ) )
|
2011-02-05 02:21:11 +00:00
|
|
|
AddJunction( DC, end_point );
|
2011-03-10 19:36:30 +00:00
|
|
|
else if( GetScreen()->IsJunctionNeeded( alt_end_point ) )
|
2011-02-05 02:21:11 +00:00
|
|
|
AddJunction( DC, alt_end_point );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Automatic place of a junction on the start point if necessary because
|
|
|
|
* the cleanup can suppress intermediate points by merging wire segments */
|
2011-03-10 19:36:30 +00:00
|
|
|
if( GetScreen()->IsJunctionNeeded( s_ConnexionStartPoint ) )
|
2011-02-05 02:21:11 +00:00
|
|
|
AddJunction( DC, s_ConnexionStartPoint );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->TestDanglingEnds( DrawPanel, DC );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
/* Redraw wires and junctions which can be changed by TestDanglingEnds() */
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->CrossHairOff( DC ); // Erase schematic cursor
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* item = GetScreen()->GetDrawItems();
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
while( item )
|
|
|
|
{
|
2007-09-01 12:00:30 +00:00
|
|
|
switch( item->Type() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
case SCH_LINE_T:
|
2011-01-30 22:22:38 +00:00
|
|
|
DrawPanel->RefreshDrawingRect( item->GetBoundingBox() );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
item = item->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->CrossHairOn( DC ); // Display schematic cursor
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-26 17:16:42 +00:00
|
|
|
SaveCopyInUndoList( s_OldWiresList, UR_WIRE_IMAGE );
|
2007-08-20 01:20:48 +00:00
|
|
|
s_OldWiresList = NULL;
|
|
|
|
|
2010-02-18 20:07:29 +00:00
|
|
|
OnModify( );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* compute the middle coordinate for 2 segments, from the start point to
|
|
|
|
* new_pos
|
2007-08-20 01:20:48 +00:00
|
|
|
* with the 2 segments kept H or V only
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
static void ComputeBreakPoint( SCH_LINE* segment, const wxPoint& new_pos )
|
|
|
|
{
|
|
|
|
SCH_LINE* nextsegment = segment->Next();
|
|
|
|
wxPoint middle_position = new_pos;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( nextsegment == NULL )
|
|
|
|
return;
|
|
|
|
#if 0
|
|
|
|
if( ABS( middle_position.x - segment->m_Start.x ) <
|
2009-12-02 21:44:03 +00:00
|
|
|
ABS( middle_position.y - segment->m_Start.y ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
middle_position.x = segment->m_Start.x;
|
|
|
|
else
|
|
|
|
middle_position.y = segment->m_Start.y;
|
2007-05-06 16:03:28 +00:00
|
|
|
#else
|
2007-08-20 01:20:48 +00:00
|
|
|
int iDx = segment->m_End.x - segment->m_Start.x;
|
|
|
|
int iDy = segment->m_End.y - segment->m_Start.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
|
|
|
{
|
|
|
|
middle_position.x = segment->m_Start.x;
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
middle_position.y = segment->m_Start.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( ABS( middle_position.x - segment->m_Start.x ) <
|
2009-12-02 21:44:03 +00:00
|
|
|
ABS( middle_position.y - segment->m_Start.y ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
middle_position.x = segment->m_Start.x;
|
|
|
|
else
|
|
|
|
middle_position.y = segment->m_Start.y;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
segment->m_End = middle_position;
|
|
|
|
|
|
|
|
nextsegment->m_Start = middle_position;
|
|
|
|
nextsegment->m_End = new_pos;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/*
|
2009-11-03 13:26:31 +00:00
|
|
|
* Erase the last trace or the element at the current mouse position.
|
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;
|
|
|
|
|
|
|
|
if( g_HVLines )
|
|
|
|
{
|
|
|
|
/* Coerce the line to vertical or horizontal one: */
|
|
|
|
if( ABS( endpos.x - polyLine->m_PolyPoints[idx].x ) <
|
|
|
|
ABS( endpos.y - polyLine->m_PolyPoints[idx].y ) )
|
|
|
|
endpos.x = polyLine->m_PolyPoints[idx].x;
|
|
|
|
else
|
|
|
|
endpos.y = polyLine->m_PolyPoints[idx].y;
|
|
|
|
}
|
|
|
|
|
|
|
|
polyLine->m_PolyPoints[idx] = endpos;
|
|
|
|
polyLine->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
DrawSegment( DrawPanel, DC, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
screen->RemoveFromDrawList( screen->GetCurItem() );
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->m_mouseCaptureCallback = NULL;
|
2011-02-05 02:21:11 +00:00
|
|
|
screen->SetCurItem( NULL );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Routine to create new connection struct.
|
2007-08-20 01:20:48 +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-02-11 20:48:13 +00:00
|
|
|
DrawPanel->CrossHairOff( aDC ); // Erase schematic cursor
|
2011-02-05 02:21:11 +00:00
|
|
|
junction->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->CrossHairOn( aDC ); // Display schematic cursor
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
junction->SetNext( GetScreen()->GetDrawItems() );
|
|
|
|
GetScreen()->SetDrawItems( junction );
|
2010-12-08 20:12:46 +00:00
|
|
|
OnModify();
|
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
if( aPutInUndoList )
|
|
|
|
SaveCopyInUndoList( junction, UR_NEW );
|
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-02-11 20:48:13 +00:00
|
|
|
DrawPanel->CrossHairOff( aDC ); // Erase schematic cursor
|
2011-02-03 19:27:28 +00:00
|
|
|
NewNoConnect->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->CrossHairOn( aDC ); // Display schematic cursor
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
NewNoConnect->SetNext( GetScreen()->GetDrawItems() );
|
|
|
|
GetScreen()->SetDrawItems( NewNoConnect );
|
|
|
|
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
|
|
|
{
|
2011-02-05 02:21:11 +00:00
|
|
|
screen->RemoveFromDrawList( (SCH_ITEM*) screen->GetCurItem() );
|
|
|
|
screen->SetCurItem( NULL );
|
|
|
|
screen->ReplaceWires( s_OldWiresList );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Repeat the last item placement.
|
|
|
|
* Bus lines, text, labels
|
|
|
|
* Labels that end with a number will be incremented.
|
2007-08-20 01:20:48 +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;
|
|
|
|
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat = 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() -
|
|
|
|
( (SCH_COMPONENT*) m_itemToRepeat )->m_Pos;
|
2011-03-10 19:36:30 +00:00
|
|
|
m_itemToRepeat->SetFlags( IS_NEW );
|
2011-01-12 21:47:54 +00:00
|
|
|
( (SCH_COMPONENT*) m_itemToRepeat )->m_TimeStamp = GetTimeStamp();
|
|
|
|
m_itemToRepeat->Move( pos );
|
|
|
|
m_itemToRepeat->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
|
|
|
|
StartMovePart( (SCH_COMPONENT*) 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
|
|
|
{
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat->SetNext( GetScreen()->GetDrawItems() );
|
|
|
|
GetScreen()->SetDrawItems( m_itemToRepeat );
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->TestDanglingEnds();
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
|
|
|
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
|
|
|
}
|
|
|
|
|