2009-11-03 13:26:31 +00:00
|
|
|
/**************************************/
|
|
|
|
/* Code to handle schematic clean up. */
|
|
|
|
/**************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "common.h"
|
2009-06-13 17:06:07 +00:00
|
|
|
#include "trigo.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "macros.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "netlist.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
static int TstAlignSegment( SCH_LINE* RefSegm, SCH_LINE* TstSegm );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Routine cleaning:
|
|
|
|
* - Includes segments or buses aligned in only 1 segment
|
|
|
|
* - Detects identical objects superimposed
|
2007-09-20 21:06:49 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
bool SCH_SCREEN::SchematicCleanUp( wxDC* DC )
|
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* DrawList, * TstDrawList;
|
2008-12-08 15:27:13 +00:00
|
|
|
int flag;
|
|
|
|
bool Modify = FALSE;
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
DrawList = EEDrawList;
|
2008-04-14 19:22:48 +00:00
|
|
|
for( ; DrawList != NULL; DrawList = DrawList->Next() )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
|
|
|
if( DrawList->Type() == DRAW_SEGMENT_STRUCT_TYPE )
|
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
TstDrawList = DrawList->Next();
|
2007-09-20 21:06:49 +00:00
|
|
|
while( TstDrawList )
|
|
|
|
{
|
|
|
|
if( TstDrawList->Type() == DRAW_SEGMENT_STRUCT_TYPE )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
flag = TstAlignSegment( (SCH_LINE*) DrawList,
|
|
|
|
(SCH_LINE*) TstDrawList );
|
2009-11-03 13:26:31 +00:00
|
|
|
if( flag )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
/* keep the bits set in .m_Flags, because the deleted
|
|
|
|
* segment can be flagged */
|
2007-09-20 21:06:49 +00:00
|
|
|
DrawList->m_Flags |= TstDrawList->m_Flags;
|
|
|
|
EraseStruct( TstDrawList, this );
|
|
|
|
SetRefreshReq();
|
|
|
|
TstDrawList = EEDrawList;
|
|
|
|
Modify = TRUE;
|
|
|
|
}
|
|
|
|
else
|
2008-04-14 19:22:48 +00:00
|
|
|
TstDrawList = TstDrawList->Next();
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
else
|
2008-04-14 19:22:48 +00:00
|
|
|
TstDrawList = TstDrawList->Next();
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-13 13:43:36 +00:00
|
|
|
WinEDA_SchematicFrame* frame;
|
|
|
|
frame = (WinEDA_SchematicFrame*) wxGetApp().GetTopWindow();
|
2008-12-08 15:27:13 +00:00
|
|
|
frame->TestDanglingEnds( EEDrawList, DC );
|
2010-01-13 13:43:36 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
return Modify;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Routine to start/end segment (BUS or wires) on junctions.
|
2007-09-20 21:06:49 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void BreakSegmentOnJunction( SCH_SCREEN* Screen )
|
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* DrawList;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
if( Screen == NULL )
|
|
|
|
{
|
2008-12-08 15:27:13 +00:00
|
|
|
DisplayError( NULL,
|
2009-11-03 13:26:31 +00:00
|
|
|
wxT( "BreakSegmentOnJunction() error: NULL screen" ) );
|
2007-09-20 21:06:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawList = Screen->EEDrawList;
|
|
|
|
while( DrawList )
|
|
|
|
{
|
|
|
|
switch( DrawList->Type() )
|
|
|
|
{
|
|
|
|
case DRAW_JUNCTION_STRUCT_TYPE:
|
|
|
|
#undef STRUCT
|
2009-12-02 21:44:03 +00:00
|
|
|
#define STRUCT ( (SCH_JUNCTION*) DrawList )
|
2007-09-20 21:06:49 +00:00
|
|
|
BreakSegment( Screen, STRUCT->m_Pos );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_BUSENTRY_STRUCT_TYPE:
|
|
|
|
#undef STRUCT
|
2009-12-02 21:44:03 +00:00
|
|
|
#define STRUCT ( (SCH_BUS_ENTRY*) DrawList )
|
2007-09-20 21:06:49 +00:00
|
|
|
BreakSegment( Screen, STRUCT->m_Pos );
|
|
|
|
BreakSegment( Screen, STRUCT->m_End() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_SEGMENT_STRUCT_TYPE:
|
|
|
|
case DRAW_NOCONNECT_STRUCT_TYPE:
|
2008-03-20 01:50:21 +00:00
|
|
|
case TYPE_SCH_LABEL:
|
|
|
|
case TYPE_SCH_GLOBALLABEL:
|
|
|
|
case TYPE_SCH_HIERLABEL:
|
|
|
|
case TYPE_SCH_COMPONENT:
|
2007-09-20 21:06:49 +00:00
|
|
|
case DRAW_POLYLINE_STRUCT_TYPE:
|
2009-12-02 21:44:03 +00:00
|
|
|
case TYPE_SCH_MARKER:
|
2008-03-20 01:50:21 +00:00
|
|
|
case TYPE_SCH_TEXT:
|
2007-09-20 21:06:49 +00:00
|
|
|
case DRAW_SHEET_STRUCT_TYPE:
|
2008-04-15 19:38:19 +00:00
|
|
|
case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE:
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-04-14 19:22:48 +00:00
|
|
|
DrawList = DrawList->Next();
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-25 07:31:07 +00:00
|
|
|
/* Break a segment ( BUS, WIRE ) int 2 segments at location aBreakpoint,
|
|
|
|
* if aBreakpoint in on segment segment
|
|
|
|
* ( excluding ends)
|
|
|
|
* fill aPicklist with modified items if non null
|
2007-09-20 21:06:49 +00:00
|
|
|
*/
|
2009-11-03 13:26:31 +00:00
|
|
|
void BreakSegment( SCH_SCREEN* aScreen, wxPoint aBreakpoint )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_LINE* segment, * NewSegment;
|
2009-11-03 13:26:31 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* DrawList = aScreen->EEDrawList; DrawList;
|
|
|
|
DrawList = DrawList->Next() )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
if( DrawList->Type() != DRAW_SEGMENT_STRUCT_TYPE )
|
|
|
|
continue;
|
2009-06-13 17:06:07 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
segment = (SCH_LINE*) DrawList;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-07-25 07:31:07 +00:00
|
|
|
if( !TestSegmentHit( aBreakpoint, segment->m_Start, segment->m_End, 0 ) )
|
|
|
|
continue;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2009-11-23 20:18:47 +00:00
|
|
|
/* ???
|
|
|
|
* Segment connecte: doit etre coupe en 2 si px,py
|
2009-11-03 13:26:31 +00:00
|
|
|
* n'est
|
2009-07-25 07:31:07 +00:00
|
|
|
* pas une extremite */
|
2009-11-03 13:26:31 +00:00
|
|
|
if( ( segment->m_Start == aBreakpoint )
|
|
|
|
|| ( segment->m_End == aBreakpoint ) )
|
2009-07-25 07:31:07 +00:00
|
|
|
continue;
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Here we must cut the segment into 2. */
|
2009-07-25 07:31:07 +00:00
|
|
|
NewSegment = segment->GenCopy();
|
|
|
|
NewSegment->m_Start = aBreakpoint;
|
|
|
|
segment->m_End = NewSegment->m_Start;
|
|
|
|
NewSegment->SetNext( segment->Next() );
|
|
|
|
segment->SetNext( NewSegment );
|
|
|
|
DrawList = NewSegment;
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Search if the 2 segments RefSegm and TstSegm are on a line.
|
2009-11-03 13:26:31 +00:00
|
|
|
* Return 0 if no
|
2007-09-20 21:06:49 +00:00
|
|
|
* 1 if yes, and RefSegm is modified to be the equivalent segment
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
static int TstAlignSegment( SCH_LINE* RefSegm, SCH_LINE* TstSegm )
|
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
if( RefSegm == TstSegm )
|
|
|
|
return 0;
|
2008-04-14 19:22:48 +00:00
|
|
|
if( RefSegm->GetLayer() != TstSegm->GetLayer() )
|
2007-09-20 21:06:49 +00:00
|
|
|
return 0;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
// search for a common end, and modify coordinates to ensure RefSegm->m_End
|
|
|
|
// == TstSegm->m_Start
|
2007-09-20 21:06:49 +00:00
|
|
|
if( RefSegm->m_Start == TstSegm->m_Start )
|
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
if( RefSegm->m_End == TstSegm->m_End )
|
2007-09-20 21:06:49 +00:00
|
|
|
return 1;
|
2009-11-03 13:26:31 +00:00
|
|
|
EXCHG( RefSegm->m_Start, RefSegm->m_End );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
else if( RefSegm->m_Start == TstSegm->m_End )
|
|
|
|
{
|
|
|
|
EXCHG( RefSegm->m_Start, RefSegm->m_End );
|
2009-11-03 13:26:31 +00:00
|
|
|
EXCHG( TstSegm->m_Start, TstSegm->m_End );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
else if( RefSegm->m_End == TstSegm->m_End )
|
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
EXCHG( TstSegm->m_Start, TstSegm->m_End );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
2009-11-03 13:26:31 +00:00
|
|
|
else if( RefSegm->m_End != TstSegm->m_Start )
|
|
|
|
// No common end point, segments cannot be merged.
|
2007-09-20 21:06:49 +00:00
|
|
|
return 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
/* Test alignment: */
|
|
|
|
if( RefSegm->m_Start.y == RefSegm->m_End.y ) // Horizontal segment
|
|
|
|
{
|
|
|
|
if( TstSegm->m_Start.y == TstSegm->m_End.y )
|
|
|
|
{
|
|
|
|
RefSegm->m_End = TstSegm->m_End;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( RefSegm->m_Start.x == RefSegm->m_End.x ) // Vertical segment
|
|
|
|
{
|
|
|
|
if( TstSegm->m_Start.x == TstSegm->m_End.x )
|
|
|
|
{
|
|
|
|
RefSegm->m_End = TstSegm->m_End;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-08 15:27:13 +00:00
|
|
|
if( atan2( (double) ( RefSegm->m_Start.x - RefSegm->m_End.x ),
|
|
|
|
(double) ( RefSegm->m_Start.y - RefSegm->m_End.y ) ) ==
|
2009-12-02 21:44:03 +00:00
|
|
|
atan2( (double) ( TstSegm->m_Start.x - TstSegm->m_End.x ),
|
|
|
|
(double) ( TstSegm->m_Start.y - TstSegm->m_End.y ) ) )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
|
|
|
RefSegm->m_End = TstSegm->m_End;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|