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"
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "program.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "classes_body_items.h"
|
2010-03-04 09:32:51 +00:00
|
|
|
#include "class_pin.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Routines Locales */
|
2009-11-03 13:26:31 +00:00
|
|
|
static void Show_Polyline_in_Ghost( WinEDA_DrawPanel* panel,
|
|
|
|
wxDC* DC,
|
|
|
|
bool erase );
|
2007-08-20 01:20:48 +00:00
|
|
|
static void Segment_in_Ghost( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
|
|
|
|
static void AbortCreateNewLine( WinEDA_DrawPanel* Panel, wxDC* DC );
|
|
|
|
static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer );
|
|
|
|
static bool IsJunctionNeeded( WinEDA_SchematicFrame* frame, wxPoint& pos );
|
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
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Extract the old wires, junctions and buses, an if CreateCopy replace them
|
|
|
|
* by a copy. Old ones must be put in undo list, and the new ones can be
|
|
|
|
* modified by clean up safely.
|
|
|
|
* If an abort command is made, old wires must be put in EEDrawList, and
|
|
|
|
* copies must be deleted. This is because previously stored undo commands
|
|
|
|
* can handle pointers on wires or bus, and we do not delete wires or bus,
|
|
|
|
* we must put they in undo list.
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2009-11-03 13:26:31 +00:00
|
|
|
* Because cleanup delete and/or modify bus and wires, the more easy is to put
|
|
|
|
* all wires in undo list and use a new copy of wires for cleanup.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_ITEM* SCH_SCREEN::ExtractWires( bool CreateCopy )
|
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* item, * next_item, * new_item, * List = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
for( item = EEDrawList; item != NULL; item = next_item )
|
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
next_item = item->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
switch( item->Type() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
case DRAW_JUNCTION_STRUCT_TYPE:
|
|
|
|
case DRAW_SEGMENT_STRUCT_TYPE:
|
|
|
|
RemoveFromDrawList( item );
|
2008-11-24 06:53:43 +00:00
|
|
|
item->SetNext( List );
|
2007-08-20 01:20:48 +00:00
|
|
|
List = item;
|
|
|
|
if( CreateCopy )
|
|
|
|
{
|
2007-09-01 12:00:30 +00:00
|
|
|
if( item->Type() == DRAW_JUNCTION_STRUCT_TYPE )
|
2009-12-02 21:44:03 +00:00
|
|
|
new_item = ( (SCH_JUNCTION*) item )->GenCopy();
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2009-12-02 21:44:03 +00:00
|
|
|
new_item = ( (SCH_LINE*) item )->GenCopy();
|
2008-11-24 06:53:43 +00:00
|
|
|
new_item->SetNext( EEDrawList );
|
2007-08-20 01:20:48 +00:00
|
|
|
EEDrawList = new_item;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return List;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Replace the wires in screen->EEDrawList by s_OldWiresList wires.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
static void RestoreOldWires( SCH_SCREEN* screen )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
SCH_ITEM* item;
|
|
|
|
SCH_ITEM* next_item;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
for( item = screen->EEDrawList; item != NULL; item = next_item )
|
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
next_item = item->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
switch( item->Type() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
case DRAW_JUNCTION_STRUCT_TYPE:
|
|
|
|
case DRAW_SEGMENT_STRUCT_TYPE:
|
|
|
|
screen->RemoveFromDrawList( item );
|
|
|
|
delete item;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while( s_OldWiresList )
|
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
next_item = s_OldWiresList->Next();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
|
|
|
s_OldWiresList->SetNext( screen->EEDrawList );
|
2009-11-03 13:26:31 +00:00
|
|
|
screen->EEDrawList = s_OldWiresList;
|
|
|
|
s_OldWiresList = next_item;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void WinEDA_SchematicFrame::BeginSegment( wxDC* DC, int type )
|
|
|
|
{
|
|
|
|
SCH_LINE* oldsegment, * newsegment, * nextsegment;
|
|
|
|
wxPoint cursorpos = GetScreen()->m_Curseur;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( GetScreen()->GetCurItem() && (GetScreen()->GetCurItem()->m_Flags == 0) )
|
|
|
|
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
|
|
|
{
|
|
|
|
case DRAW_SEGMENT_STRUCT_TYPE:
|
|
|
|
case DRAW_POLYLINE_STRUCT_TYPE:
|
|
|
|
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;
|
2009-11-03 13:26:31 +00:00
|
|
|
s_OldWiresList = ( (SCH_SCREEN*) GetScreen() )->ExtractWires( TRUE );
|
|
|
|
( (SCH_SCREEN*) GetScreen() )->SchematicCleanUp( NULL );
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
newsegment->m_Flags = IS_NEW;
|
2009-11-03 13:26:31 +00:00
|
|
|
if( g_HVLines ) // We need 2 segments to go from a given start pint to
|
|
|
|
// an end point
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
nextsegment = newsegment->GenCopy();
|
|
|
|
nextsegment->m_Flags = IS_NEW;
|
2008-11-24 06:53:43 +00:00
|
|
|
newsegment->SetNext( nextsegment );
|
|
|
|
nextsegment->SetBack( newsegment );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
GetScreen()->SetCurItem( newsegment );
|
|
|
|
DrawPanel->ManageCurseur = Segment_in_Ghost;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = AbortCreateNewLine;
|
|
|
|
g_ItemToRepeat = NULL;
|
|
|
|
}
|
2009-11-03 13:26:31 +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();
|
2009-11-03 13:26:31 +00:00
|
|
|
if( !g_HVLines ) /* if only one segment is needed and the current is
|
|
|
|
* has len = 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
|
|
|
|
|
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 */
|
2009-10-06 13:19:40 +00:00
|
|
|
if( IsTerminalPoint( GetScreen(), cursorpos, oldsegment->GetLayer() ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
EndSegment( DC ); return;
|
|
|
|
}
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
oldsegment->SetNext( GetScreen()->EEDrawList );
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->EEDrawList = oldsegment;
|
|
|
|
DrawPanel->CursorOff( DC ); // Erase schematic cursor
|
|
|
|
RedrawOneStruct( DrawPanel, DC, oldsegment, GR_DEFAULT_DRAWMODE );
|
|
|
|
DrawPanel->CursorOn( DC ); // Display schematic cursor
|
|
|
|
|
|
|
|
/* Create a new segment, and chain it after the current new segment */
|
|
|
|
if( nextsegment )
|
|
|
|
{
|
|
|
|
newsegment = nextsegment->GenCopy();
|
|
|
|
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
|
|
|
|
{
|
|
|
|
newsegment = oldsegment->GenCopy();
|
|
|
|
newsegment->m_Start = oldsegment->m_End;
|
|
|
|
}
|
|
|
|
newsegment->m_End = cursorpos;
|
|
|
|
oldsegment->m_Flags = SELECTED;
|
|
|
|
newsegment->m_Flags = IS_NEW;
|
|
|
|
GetScreen()->SetCurItem( newsegment );
|
|
|
|
DrawPanel->ManageCurseur( DrawPanel, DC, 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
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
if( IsJunctionNeeded( this, s_ConnexionStartPoint ) )
|
|
|
|
CreateNewJunctionStruct( DC, s_ConnexionStartPoint );
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void WinEDA_SchematicFrame::EndSegment( wxDC* DC )
|
|
|
|
{
|
|
|
|
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;
|
2009-12-02 21:44:03 +00:00
|
|
|
if( ( firstsegment->m_Flags & IS_NEW ) == 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Delete Null segments and Put line it in Drawlist */
|
|
|
|
lastsegment = firstsegment;
|
|
|
|
while( lastsegment )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_LINE* nextsegment = lastsegment->Next();
|
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();
|
2007-08-20 01:20:48 +00:00
|
|
|
if( firstsegment == lastsegment )
|
|
|
|
firstsegment = nextsegment;
|
|
|
|
if( nextsegment )
|
2008-11-24 06:53:43 +00:00
|
|
|
nextsegment->SetBack( NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
if( previous_segment )
|
2008-11-24 06:53:43 +00:00
|
|
|
previous_segment->SetNext( nextsegment );
|
2007-08-20 01:20:48 +00:00
|
|
|
delete lastsegment;
|
|
|
|
}
|
|
|
|
lastsegment = nextsegment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* put the segment list to the main linked list */
|
|
|
|
segment = lastsegment = firstsegment;
|
|
|
|
while( segment )
|
|
|
|
{
|
|
|
|
lastsegment = segment;
|
2009-11-03 13:26:31 +00:00
|
|
|
segment = segment->Next();
|
2008-11-24 06:53:43 +00:00
|
|
|
lastsegment->SetNext( GetScreen()->EEDrawList );
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->EEDrawList = lastsegment;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawPanel->ManageCurseur = NULL;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = NULL;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
( (SCH_SCREEN*) GetScreen() )->SchematicCleanUp( NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
/* clear flags and find last segment entered, for repeat function */
|
2009-12-02 21:44:03 +00:00
|
|
|
segment = (SCH_LINE*) GetScreen()->EEDrawList;
|
2007-08-20 01:20:48 +00:00
|
|
|
while( segment )
|
|
|
|
{
|
|
|
|
if( segment->m_Flags )
|
|
|
|
{
|
|
|
|
if( !g_ItemToRepeat )
|
|
|
|
g_ItemToRepeat = segment;
|
|
|
|
}
|
|
|
|
segment->m_Flags = 0;
|
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 )
|
|
|
|
{
|
|
|
|
if( IsJunctionNeeded( this, end_point ) )
|
|
|
|
CreateNewJunctionStruct( DC, end_point );
|
|
|
|
|
|
|
|
else if( IsJunctionNeeded( this, alt_end_point ) )
|
|
|
|
CreateNewJunctionStruct( DC, alt_end_point );
|
|
|
|
}
|
|
|
|
|
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 */
|
2007-08-20 01:20:48 +00:00
|
|
|
if( IsJunctionNeeded( this, s_ConnexionStartPoint ) )
|
|
|
|
CreateNewJunctionStruct( DC, s_ConnexionStartPoint );
|
|
|
|
|
|
|
|
TestDanglingEnds( GetScreen()->EEDrawList, DC );
|
|
|
|
|
|
|
|
|
|
|
|
/* Redraw wires and junctions which can be changed by TestDanglingEnds() */
|
|
|
|
DrawPanel->CursorOff( DC ); // Erase schematic cursor
|
|
|
|
EDA_BaseStruct* item = GetScreen()->EEDrawList;
|
|
|
|
while( item )
|
|
|
|
{
|
2007-09-01 12:00:30 +00:00
|
|
|
switch( item->Type() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
case DRAW_JUNCTION_STRUCT_TYPE:
|
|
|
|
case DRAW_SEGMENT_STRUCT_TYPE:
|
2009-11-03 13:26:31 +00:00
|
|
|
DrawPanel->PostDirtyRect( 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DrawPanel->CursorOn( DC ); // Display schematic cursor
|
|
|
|
|
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-12-02 21:44:03 +00:00
|
|
|
/* Redraw the segment (g_HVLines == FALSE ) or the two segments (g_HVLines ==
|
2009-11-03 13:26:31 +00:00
|
|
|
* TRUE )
|
2007-08-20 01:20:48 +00:00
|
|
|
* from the start point to the cursor, when moving the mouse
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
static void Segment_in_Ghost( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
|
|
|
|
{
|
|
|
|
SCH_LINE* CurrentLine = (SCH_LINE*) panel->GetScreen()->GetCurItem();
|
|
|
|
SCH_LINE* segment;
|
2007-08-20 01:20:48 +00:00
|
|
|
int color;
|
|
|
|
|
|
|
|
if( CurrentLine == NULL )
|
|
|
|
return;
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
color = ReturnLayerColor( CurrentLine->GetLayer() ) ^ HIGHT_LIGHT_FLAG;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( erase )
|
|
|
|
{
|
|
|
|
segment = CurrentLine;
|
|
|
|
while( segment )
|
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
if( !segment->IsNull() ) // Redraw if segment length != 0
|
2007-08-20 01:20:48 +00:00
|
|
|
RedrawOneStruct( panel, DC, segment, g_XorMode, color );
|
2008-11-24 06:53:43 +00:00
|
|
|
segment = segment->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
wxPoint endpos = panel->GetScreen()->m_Curseur;
|
2007-08-20 01:20:48 +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 )
|
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
if( !segment->IsNull() ) // Redraw if segment length != 0
|
2007-08-20 01:20:48 +00:00
|
|
|
RedrawOneStruct( panel, DC, segment, g_XorMode, color );
|
2008-11-24 06:53:43 +00:00
|
|
|
segment = segment->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +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;
|
2009-11-03 13:26:31 +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;
|
|
|
|
}
|
2009-11-03 13:26:31 +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
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/* Drawing Polyline phantom at the displacement of the cursor
|
|
|
|
*/
|
2009-11-03 13:26:31 +00:00
|
|
|
static void Show_Polyline_in_Ghost( WinEDA_DrawPanel* panel,
|
|
|
|
wxDC* DC,
|
|
|
|
bool erase )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_POLYLINE* NewPoly = (SCH_POLYLINE*) panel->GetScreen()->GetCurItem();
|
|
|
|
int color;
|
|
|
|
wxPoint endpos;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
endpos = panel->GetScreen()->m_Curseur;
|
2008-04-14 19:22:48 +00:00
|
|
|
color = ReturnLayerColor( NewPoly->GetLayer() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
GRSetDrawMode( DC, g_XorMode );
|
|
|
|
|
2009-01-02 17:07:50 +00:00
|
|
|
int idx = NewPoly->GetCornerCount() - 1;
|
2007-08-20 01:20:48 +00:00
|
|
|
if( g_HVLines )
|
|
|
|
{
|
|
|
|
/* Coerce the line to vertical or horizontal one: */
|
2009-01-02 17:07:50 +00:00
|
|
|
if( ABS( endpos.x - NewPoly->m_PolyPoints[idx].x ) <
|
|
|
|
ABS( endpos.y - NewPoly->m_PolyPoints[idx].y ) )
|
|
|
|
endpos.x = NewPoly->m_PolyPoints[idx].x;
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2009-01-02 17:07:50 +00:00
|
|
|
endpos.y = NewPoly->m_PolyPoints[idx].y;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( erase )
|
|
|
|
RedrawOneStruct( panel, DC, NewPoly, g_XorMode, color );
|
|
|
|
|
2009-01-02 17:07:50 +00:00
|
|
|
NewPoly->m_PolyPoints[idx] = endpos;
|
2007-08-20 01:20:48 +00:00
|
|
|
RedrawOneStruct( panel, DC, NewPoly, g_XorMode, color );
|
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
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void WinEDA_SchematicFrame::DeleteCurrentSegment( wxDC* DC )
|
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
g_ItemToRepeat = NULL;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
if( ( GetScreen()->GetCurItem() == NULL )
|
|
|
|
|| ( ( GetScreen()->GetCurItem()->m_Flags & IS_NEW ) == 0 ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Cancel trace in progress */
|
2007-09-01 12:00:30 +00:00
|
|
|
if( GetScreen()->GetCurItem()->Type() == DRAW_POLYLINE_STRUCT_TYPE )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
Show_Polyline_in_Ghost( DrawPanel, DC, FALSE );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
Segment_in_Ghost( DrawPanel, DC, FALSE );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
EraseStruct( (SCH_ITEM*) GetScreen()->GetCurItem(),
|
|
|
|
(SCH_SCREEN*) GetScreen() );
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->ManageCurseur = NULL;
|
|
|
|
GetScreen()->SetCurItem( NULL );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Routine to create new connection struct.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_JUNCTION* WinEDA_SchematicFrame::CreateNewJunctionStruct(
|
|
|
|
wxDC* DC, const wxPoint& pos, bool PutInUndoList )
|
|
|
|
{
|
|
|
|
SCH_JUNCTION* NewJunction;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
NewJunction = new SCH_JUNCTION( pos );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
g_ItemToRepeat = NewJunction;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->CursorOff( DC ); // Erase schematic cursor
|
|
|
|
RedrawOneStruct( DrawPanel, DC, NewJunction, GR_DEFAULT_DRAWMODE );
|
|
|
|
DrawPanel->CursorOn( DC ); // Display schematic cursor
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
NewJunction->SetNext( GetScreen()->EEDrawList );
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->EEDrawList = NewJunction;
|
2010-02-18 20:07:29 +00:00
|
|
|
OnModify( );
|
2007-08-20 01:20:48 +00:00
|
|
|
if( PutInUndoList )
|
2009-07-26 17:16:42 +00:00
|
|
|
SaveCopyInUndoList( NewJunction, UR_NEW );
|
2007-08-20 01:20:48 +00:00
|
|
|
return NewJunction;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Routine to create new NoConnect struct. */
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_NO_CONNECT* WinEDA_SchematicFrame::CreateNewNoConnectStruct( wxDC* DC )
|
|
|
|
{
|
|
|
|
SCH_NO_CONNECT* NewNoConnect;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
NewNoConnect = new SCH_NO_CONNECT( GetScreen()->m_Curseur );
|
2007-08-20 01:20:48 +00:00
|
|
|
g_ItemToRepeat = NewNoConnect;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->CursorOff( DC ); // Erase schematic cursor
|
|
|
|
RedrawOneStruct( DrawPanel, DC, NewNoConnect, GR_DEFAULT_DRAWMODE );
|
|
|
|
DrawPanel->CursorOn( DC ); // Display schematic cursor
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
NewNoConnect->SetNext( GetScreen()->EEDrawList );
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->EEDrawList = NewNoConnect;
|
2010-02-18 20:07:29 +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
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
static void AbortCreateNewLine( WinEDA_DrawPanel* Panel, wxDC* DC )
|
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
SCH_SCREEN* Screen = (SCH_SCREEN*) Panel->GetScreen();
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
if( Screen->GetCurItem() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
Panel->ManageCurseur = NULL;
|
|
|
|
Panel->ForceCloseManageCurseur = NULL;
|
2008-04-14 19:22:48 +00:00
|
|
|
EraseStruct( (SCH_ITEM*) Screen->GetCurItem(), (SCH_SCREEN*) Screen );
|
2007-08-20 01:20:48 +00:00
|
|
|
Screen->SetCurItem( NULL );
|
|
|
|
RestoreOldWires( Screen );
|
2009-08-28 07:11:56 +00:00
|
|
|
Panel->Refresh();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
2009-11-03 13:26:31 +00:00
|
|
|
g_ItemToRepeat = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Clear m_Flags which is used in edit functions: */
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* item = Screen->EEDrawList;
|
2007-08-20 01:20:48 +00:00
|
|
|
while( item )
|
|
|
|
{
|
|
|
|
item->m_Flags = 0;
|
2008-04-14 19:22:48 +00:00
|
|
|
item = item->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
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
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void WinEDA_SchematicFrame::RepeatDrawItem( wxDC* DC )
|
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
wxPoint new_pos;
|
|
|
|
|
|
|
|
if( g_ItemToRepeat == NULL )
|
|
|
|
return;
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
switch( g_ItemToRepeat->Type() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
case DRAW_JUNCTION_STRUCT_TYPE:
|
2008-10-06 05:44:29 +00:00
|
|
|
#undef STRUCT
|
2009-12-02 21:44:03 +00:00
|
|
|
#define STRUCT ( (SCH_JUNCTION*) g_ItemToRepeat )
|
2007-08-20 01:20:48 +00:00
|
|
|
g_ItemToRepeat = STRUCT->GenCopy();
|
|
|
|
STRUCT->m_Pos += g_RepeatStep;
|
|
|
|
new_pos = STRUCT->m_Pos;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_NOCONNECT_STRUCT_TYPE:
|
2008-10-06 05:44:29 +00:00
|
|
|
#undef STRUCT
|
2009-12-02 21:44:03 +00:00
|
|
|
#define STRUCT ( (SCH_NO_CONNECT*) g_ItemToRepeat )
|
2007-08-20 01:20:48 +00:00
|
|
|
g_ItemToRepeat = STRUCT->GenCopy();
|
|
|
|
STRUCT->m_Pos += g_RepeatStep;
|
|
|
|
new_pos = STRUCT->m_Pos;
|
|
|
|
break;
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
case TYPE_SCH_TEXT:
|
2008-10-06 05:44:29 +00:00
|
|
|
#undef STRUCT
|
|
|
|
#define STRUCT ( (SCH_TEXT*) g_ItemToRepeat )
|
2007-08-20 01:20:48 +00:00
|
|
|
g_ItemToRepeat = STRUCT->GenCopy();
|
|
|
|
STRUCT->m_Pos += g_RepeatStep;
|
|
|
|
new_pos = STRUCT->m_Pos;
|
|
|
|
IncrementLabelMember( STRUCT->m_Text );
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
case TYPE_SCH_LABEL:
|
2008-10-06 05:44:29 +00:00
|
|
|
#undef STRUCT
|
|
|
|
#define STRUCT ( (SCH_LABEL*) g_ItemToRepeat )
|
2007-08-20 01:20:48 +00:00
|
|
|
g_ItemToRepeat = STRUCT->GenCopy();
|
|
|
|
STRUCT->m_Pos += g_RepeatStep;
|
|
|
|
new_pos = STRUCT->m_Pos;
|
|
|
|
IncrementLabelMember( STRUCT->m_Text );
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
case TYPE_SCH_HIERLABEL:
|
2008-10-06 05:44:29 +00:00
|
|
|
#undef STRUCT
|
|
|
|
#define STRUCT ( (SCH_HIERLABEL*) g_ItemToRepeat )
|
2008-02-12 21:12:46 +00:00
|
|
|
g_ItemToRepeat = STRUCT->GenCopy();
|
|
|
|
STRUCT->m_Pos += g_RepeatStep;
|
|
|
|
new_pos = STRUCT->m_Pos;
|
|
|
|
IncrementLabelMember( STRUCT->m_Text );
|
|
|
|
break;
|
2008-03-20 01:50:21 +00:00
|
|
|
|
|
|
|
case TYPE_SCH_GLOBALLABEL:
|
2008-10-06 05:44:29 +00:00
|
|
|
#undef STRUCT
|
|
|
|
#define STRUCT ( (SCH_GLOBALLABEL*) g_ItemToRepeat )
|
2007-08-20 01:20:48 +00:00
|
|
|
g_ItemToRepeat = STRUCT->GenCopy();
|
|
|
|
STRUCT->m_Pos += g_RepeatStep;
|
|
|
|
new_pos = STRUCT->m_Pos;
|
|
|
|
IncrementLabelMember( STRUCT->m_Text );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_SEGMENT_STRUCT_TYPE:
|
2008-10-06 05:44:29 +00:00
|
|
|
#undef STRUCT
|
2009-12-02 21:44:03 +00:00
|
|
|
#define STRUCT ( (SCH_LINE*) g_ItemToRepeat )
|
2007-08-20 01:20:48 +00:00
|
|
|
g_ItemToRepeat = STRUCT->GenCopy();
|
|
|
|
STRUCT->m_Start += g_RepeatStep;
|
|
|
|
new_pos = STRUCT->m_Start;
|
|
|
|
STRUCT->m_End += g_RepeatStep;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_BUSENTRY_STRUCT_TYPE:
|
|
|
|
#undef STRUCT
|
2009-12-02 21:44:03 +00:00
|
|
|
#define STRUCT ( (SCH_BUS_ENTRY*) g_ItemToRepeat )
|
2007-08-20 01:20:48 +00:00
|
|
|
g_ItemToRepeat = STRUCT->GenCopy();
|
|
|
|
STRUCT->m_Pos += g_RepeatStep;
|
|
|
|
new_pos = STRUCT->m_Pos;
|
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case TYPE_SCH_COMPONENT: // In repeat command the new component is put
|
|
|
|
// in move mode
|
2008-10-06 05:44:29 +00:00
|
|
|
#undef STRUCT
|
|
|
|
#define STRUCT ( (SCH_COMPONENT*) g_ItemToRepeat )
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
// Create the duplicate component, position = mouse cursor
|
|
|
|
g_ItemToRepeat = STRUCT->GenCopy();
|
2009-11-03 13:26:31 +00:00
|
|
|
new_pos.x = GetScreen()->m_Curseur.x - STRUCT->m_Pos.x;
|
|
|
|
new_pos.y = GetScreen()->m_Curseur.y - STRUCT->m_Pos.y;
|
|
|
|
STRUCT->m_Pos = GetScreen()->m_Curseur;
|
2007-08-20 01:20:48 +00:00
|
|
|
STRUCT->m_Flags = IS_NEW;
|
2008-03-20 01:50:21 +00:00
|
|
|
STRUCT->m_TimeStamp = GetTimeStamp();
|
2008-10-06 05:44:29 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < STRUCT->GetFieldCount(); ii++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
STRUCT->GetField( ii )->m_Pos += new_pos;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RedrawOneStruct( DrawPanel, DC, STRUCT, g_XorMode );
|
|
|
|
StartMovePart( STRUCT, DC );
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_ItemToRepeat = NULL;
|
|
|
|
DisplayError( this, wxT( "Repeat Type Error" ), 10 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( g_ItemToRepeat )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
g_ItemToRepeat->SetNext( GetScreen()->EEDrawList );
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->EEDrawList = g_ItemToRepeat;
|
|
|
|
TestDanglingEnds( GetScreen()->EEDrawList, NULL );
|
|
|
|
RedrawOneStruct( DrawPanel, DC, g_ItemToRepeat, GR_DEFAULT_DRAWMODE );
|
2009-07-26 17:16:42 +00:00
|
|
|
SaveCopyInUndoList( g_ItemToRepeat, UR_NEW );
|
2007-08-20 01:20:48 +00:00
|
|
|
g_ItemToRepeat->m_Flags = 0;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
// GetScreen()->Curseur = new_pos;
|
|
|
|
// DrawPanel->MouseTo( DrawPanel->CursorScreenPosition() );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Routine incrementing labels, ie for the text ending with a number, adding
|
|
|
|
* that a number <RepeatDeltaLabel>
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void IncrementLabelMember( wxString& name )
|
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int ii, nn;
|
|
|
|
long number = 0;
|
|
|
|
|
|
|
|
ii = name.Len() - 1; nn = 0;
|
|
|
|
if( !isdigit( name.GetChar( ii ) ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
while( (ii >= 0) && isdigit( name.GetChar( ii ) ) )
|
|
|
|
{
|
|
|
|
ii--; nn++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ii++; /* digits are starting at ii position */
|
|
|
|
wxString litt_number = name.Right( nn );
|
|
|
|
if( litt_number.ToLong( &number ) )
|
|
|
|
{
|
|
|
|
number += g_RepeatDeltaLabel;
|
|
|
|
name.Remove( ii ); name << number;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-10-06 13:19:40 +00:00
|
|
|
/* Return TRUE if pos can be a terminal point for a wire or a bus
|
|
|
|
* i.e. :
|
|
|
|
* for a WIRE, if at pos is found:
|
|
|
|
* - a junction
|
|
|
|
* - or a pin
|
|
|
|
* - or an other wire
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2009-10-06 13:19:40 +00:00
|
|
|
* - for a BUS, if at pos is found:
|
|
|
|
* - a BUS
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer )
|
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
EDA_BaseStruct* item;
|
|
|
|
LIB_PIN* pin;
|
|
|
|
SCH_COMPONENT* LibItem = NULL;
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET_PIN* pinsheet;
|
2009-11-03 13:26:31 +00:00
|
|
|
wxPoint itempos;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
switch( layer )
|
|
|
|
{
|
|
|
|
case LAYER_BUS:
|
2008-02-12 21:12:46 +00:00
|
|
|
item = PickStruct( pos, screen, BUSITEM );
|
2007-08-20 01:20:48 +00:00
|
|
|
if( item )
|
|
|
|
return TRUE;
|
|
|
|
pinsheet = LocateAnyPinSheet( pos, screen->EEDrawList );
|
|
|
|
if( pinsheet && IsBusLabel( pinsheet->m_Text ) )
|
|
|
|
{
|
|
|
|
itempos = pinsheet->m_Pos;
|
|
|
|
if( (itempos.x == pos.x) && (itempos.y == pos.y) )
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_NOTES:
|
2008-02-12 21:12:46 +00:00
|
|
|
item = PickStruct( pos, screen, DRAWITEM );
|
2007-08-20 01:20:48 +00:00
|
|
|
if( item )
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_WIRE:
|
2008-02-12 21:12:46 +00:00
|
|
|
item = PickStruct( pos, screen, RACCORDITEM | JUNCTIONITEM );
|
2007-08-20 01:20:48 +00:00
|
|
|
if( item )
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
pin = LocateAnyPin( screen->EEDrawList, pos, &LibItem );
|
|
|
|
if( pin && LibItem )
|
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
// Calculate the exact position of the connection point of the pin,
|
|
|
|
// depending on orientation of the component.
|
2007-08-20 01:20:48 +00:00
|
|
|
itempos = LibItem->GetScreenCoord( pin->m_Pos );
|
|
|
|
itempos.x += LibItem->m_Pos.x;
|
|
|
|
itempos.y += LibItem->m_Pos.y;
|
2009-12-02 21:44:03 +00:00
|
|
|
if( ( itempos.x == pos.x ) && ( itempos.y == pos.y ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
item = PickStruct( pos, screen, WIREITEM );
|
2007-08-20 01:20:48 +00:00
|
|
|
if( item )
|
|
|
|
return TRUE;
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
item = PickStruct( pos, screen, LABELITEM );
|
2008-03-20 01:50:21 +00:00
|
|
|
if( item && (item->Type() != TYPE_SCH_TEXT)
|
|
|
|
&& ( ( (SCH_GLOBALLABEL*) item )->m_Pos.x == pos.x )
|
|
|
|
&& ( ( (SCH_GLOBALLABEL*) item )->m_Pos.y == pos.y ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
pinsheet = LocateAnyPinSheet( pos, screen->EEDrawList );
|
2007-08-20 01:20:48 +00:00
|
|
|
if( pinsheet && !IsBusLabel( pinsheet->m_Text ) )
|
|
|
|
{
|
|
|
|
itempos = pinsheet->m_Pos;
|
2009-12-02 21:44:03 +00:00
|
|
|
if( ( itempos.x == pos.x ) && ( itempos.y == pos.y ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Return True when a wire is located at pos "pos" if
|
2007-08-20 01:20:48 +00:00
|
|
|
* - there is no junction.
|
|
|
|
* - The wire has no ends at pos "pos",
|
|
|
|
* and therefore it is considered as no connected.
|
|
|
|
* - One (or more) wire has one end at pos "pos"
|
|
|
|
* or
|
|
|
|
* - a pin is on location pos
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
bool IsJunctionNeeded( WinEDA_SchematicFrame* frame, wxPoint& pos )
|
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
if( PickStruct( pos, frame->GetScreen(), JUNCTIONITEM ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
if( PickStruct( pos, frame->GetScreen(), WIREITEM |
|
|
|
|
EXCLUDE_WIRE_BUS_ENDPOINTS ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
if( PickStruct( pos, frame->GetScreen(), WIREITEM |
|
|
|
|
WIRE_BUS_ENDPOINTS_ONLY ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
return TRUE;
|
2008-04-14 19:22:48 +00:00
|
|
|
if( frame->LocatePinEnd( frame->GetScreen()->EEDrawList, pos ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|