2007-09-20 21:06:49 +00:00
|
|
|
/*********************************/
|
|
|
|
/* Module de nettoyage du schema */
|
|
|
|
/*********************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "netlist.h"
|
|
|
|
#include "macros.h"
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Routines locales */
|
2007-09-20 21:06:49 +00:00
|
|
|
static int TstAlignSegment( EDA_DrawLineStruct* RefSegm, EDA_DrawLineStruct* TstSegm );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/* Variable locales */
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
bool SCH_SCREEN::SchematicCleanUp( wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*******************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Routine de nettoyage:
|
2007-09-20 21:06:49 +00:00
|
|
|
* - regroupe les segments de fils (ou de bus) alignes en 1 seul segment
|
|
|
|
* - Detecte les objets identiques superposes
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* DrawList, * TstDrawList;
|
2007-09-20 21:06:49 +00:00
|
|
|
int flag;
|
|
|
|
bool Modify = FALSE;
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
flag = TstAlignSegment( (EDA_DrawLineStruct*) DrawList,
|
|
|
|
(EDA_DrawLineStruct*) TstDrawList );
|
|
|
|
if( flag ) /* Suppression de TstSegm */
|
|
|
|
{
|
|
|
|
/* keep the bits set in .m_Flags, because the deleted segment can be flagged */
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-26 06:08:19 +00:00
|
|
|
g_EDA_Appl->m_SchematicFrame->TestDanglingEnds( EEDrawList, DC );
|
2007-09-20 21:06:49 +00:00
|
|
|
return Modify;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
void BreakSegmentOnJunction( SCH_SCREEN* Screen )
|
2007-06-05 12:10:51 +00:00
|
|
|
/************************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Routine creant des debuts / fin de segment (BUS ou WIRES) sur les jonctions
|
2007-09-20 21:06:49 +00:00
|
|
|
* et les raccords
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* DrawList;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
if( Screen == NULL )
|
|
|
|
{
|
|
|
|
DisplayError( NULL, wxT( "BreakSegmentOnJunction() error: NULL screen" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawList = Screen->EEDrawList;
|
|
|
|
while( DrawList )
|
|
|
|
{
|
|
|
|
switch( DrawList->Type() )
|
|
|
|
{
|
|
|
|
case DRAW_JUNCTION_STRUCT_TYPE:
|
|
|
|
#undef STRUCT
|
|
|
|
#define STRUCT ( (DrawJunctionStruct*) DrawList )
|
|
|
|
BreakSegment( Screen, STRUCT->m_Pos );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_BUSENTRY_STRUCT_TYPE:
|
|
|
|
#undef STRUCT
|
|
|
|
#define STRUCT ( (DrawBusEntryStruct*) DrawList )
|
|
|
|
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_PICK_ITEM_STRUCT_TYPE:
|
|
|
|
case DRAW_POLYLINE_STRUCT_TYPE:
|
|
|
|
case DRAW_MARKER_STRUCT_TYPE:
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
DrawPickedStruct* BreakSegment( SCH_SCREEN* screen,
|
|
|
|
wxPoint breakpoint, bool PutInUndoList )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*********************************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Coupe un segment ( BUS, WIRE ) en 2 au point breakpoint,
|
2007-09-20 21:06:49 +00:00
|
|
|
* - si ce point est sur le segment
|
|
|
|
* - extremites non comprises
|
|
|
|
* If PutInUndoList == TRUE, create a list of modifictions, for undo command
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
EDA_BaseStruct* DrawList;
|
|
|
|
EDA_DrawLineStruct* segment, * NewSegment;
|
|
|
|
int ox, oy, fx, fy;
|
|
|
|
DrawPickedStruct* List = NULL;
|
|
|
|
|
|
|
|
DrawList = screen->EEDrawList;
|
|
|
|
while( DrawList )
|
|
|
|
{
|
|
|
|
switch( DrawList->Type() )
|
|
|
|
{
|
|
|
|
case DRAW_SEGMENT_STRUCT_TYPE:
|
|
|
|
segment = (EDA_DrawLineStruct*) DrawList;
|
|
|
|
ox = segment->m_Start.x; oy = segment->m_Start.y;
|
|
|
|
fx = segment->m_End.x; fy = segment->m_End.y;
|
|
|
|
if( distance( fx - ox, fy - oy, breakpoint.x - ox, breakpoint.y - oy, 0 ) == 0 )
|
|
|
|
break;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
/* Segment connecte: doit etre coupe en 2 si px,py n'est
|
|
|
|
* pas une extremite */
|
|
|
|
if( (ox == breakpoint.x) && (oy == breakpoint.y ) )
|
|
|
|
break;
|
|
|
|
if( (fx == breakpoint.x) && (fy == breakpoint.y ) )
|
|
|
|
break;
|
|
|
|
/* Ici il faut couper le segment en 2 */
|
|
|
|
if( PutInUndoList ) // First: put copy of the old segment in undo list
|
|
|
|
{
|
|
|
|
DrawPickedStruct* wrapper = new DrawPickedStruct();
|
|
|
|
|
|
|
|
wrapper->m_Flags = IS_CHANGED;
|
|
|
|
wrapper->m_PickedStruct = segment->GenCopy();
|
|
|
|
wrapper->m_Image = segment;
|
|
|
|
wrapper->m_PickedStruct->m_Image = segment;
|
2008-11-24 06:53:43 +00:00
|
|
|
wrapper->SetNext( List );
|
2007-09-20 21:06:49 +00:00
|
|
|
List = wrapper;
|
|
|
|
}
|
|
|
|
NewSegment = segment->GenCopy();
|
|
|
|
NewSegment->m_Start = breakpoint;
|
|
|
|
segment->m_End = NewSegment->m_Start;
|
2008-11-24 06:53:43 +00:00
|
|
|
NewSegment->SetNext( segment->Next() );
|
|
|
|
segment->SetNext( NewSegment );
|
2007-09-20 21:06:49 +00:00
|
|
|
DrawList = NewSegment;
|
|
|
|
if( PutInUndoList )
|
|
|
|
{
|
|
|
|
DrawPickedStruct* wrapper = new DrawPickedStruct();
|
|
|
|
|
|
|
|
wrapper->m_Flags = IS_NEW;
|
|
|
|
wrapper->m_Image = NewSegment;
|
2008-11-24 06:53:43 +00:00
|
|
|
wrapper->SetNext( List );
|
2007-09-20 21:06:49 +00:00
|
|
|
List = wrapper;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_JUNCTION_STRUCT_TYPE:
|
|
|
|
case DRAW_BUSENTRY_STRUCT_TYPE:
|
|
|
|
case DRAW_POLYLINE_STRUCT_TYPE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
DrawList = DrawList->Next();
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return List;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
static int TstAlignSegment( EDA_DrawLineStruct* RefSegm,
|
|
|
|
EDA_DrawLineStruct* TstSegm )
|
2007-06-05 12:10:51 +00:00
|
|
|
/***********************************************************/
|
|
|
|
|
|
|
|
/* Search if the 2 segments RefSegm and TstSegm are on a line.
|
2007-09-20 21:06:49 +00:00
|
|
|
* Retourn 0 if no
|
|
|
|
* 1 if yes, and RefSegm is modified to be the equivalent segment
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
// search for a common end, and modify coordinates to ensure RefSegm->m_End == TstSegm->m_Start
|
|
|
|
if( RefSegm->m_Start == TstSegm->m_Start )
|
|
|
|
{
|
|
|
|
if( RefSegm->m_End == TstSegm->m_End ) // trivial case: RefSegm and TstSegm are identical
|
|
|
|
return 1;
|
|
|
|
EXCHG( RefSegm->m_Start, RefSegm->m_End ); // at this point, RefSegm->m_End == TstSegm->m_Start
|
|
|
|
}
|
|
|
|
else if( RefSegm->m_Start == TstSegm->m_End )
|
|
|
|
{
|
|
|
|
EXCHG( RefSegm->m_Start, RefSegm->m_End );
|
|
|
|
EXCHG( TstSegm->m_Start, TstSegm->m_End ); // at this point, RefSegm->m_End == TstSegm->m_Start
|
|
|
|
}
|
|
|
|
else if( RefSegm->m_End == TstSegm->m_End )
|
|
|
|
{
|
|
|
|
EXCHG( TstSegm->m_Start, TstSegm->m_End ); // at this point, RefSegm->m_End == TstSegm->m_Start
|
|
|
|
}
|
|
|
|
else if( RefSegm->m_End != TstSegm->m_Start ) // No common end point, segments cannot be merged
|
|
|
|
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-10-29 15:26:53 +00:00
|
|
|
if( atan2( (double)(RefSegm->m_Start.x - RefSegm->m_End.x),
|
|
|
|
(double)(RefSegm->m_Start.y - RefSegm->m_End.y) ) ==
|
|
|
|
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;
|
|
|
|
}
|