Commit 54b424ab authored by dickelbeck's avatar dickelbeck

fixed eeschema

parent 1efd56c1
...@@ -7,7 +7,6 @@ email address. ...@@ -7,7 +7,6 @@ email address.
2007-Aug-31 UPDATE Dick Hollenbeck <dick@softplc.com> 2007-Aug-31 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================ ================================================================================
These changes broke EESCHEMA, will fix late on Sep 1.
+ pcbnew & gerbview + pcbnew & gerbview
* Added TRACK::Copy() which can copy a SEGVIA or a TRACK. * Added TRACK::Copy() which can copy a SEGVIA or a TRACK.
* Changed export_to_pcbnew.cpp so it created a SEGVIA properly, a significant change. * Changed export_to_pcbnew.cpp so it created a SEGVIA properly, a significant change.
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
/***********************************************************/ /***********************************************************/
DrawSheetStruct::DrawSheetStruct( const wxPoint& pos ) : DrawSheetStruct::DrawSheetStruct( const wxPoint& pos ) :
SCH_SCREEN( DRAW_SHEET_STRUCT_TYPE ) SCH_SCREEN( SCHEMATIC_FRAME, DRAW_SHEET_STRUCT_TYPE )
/***********************************************************/ /***********************************************************/
{ {
m_Label = NULL; m_Label = NULL;
......
/******************************************************/ /******************************************************/
/* Routines de localisation d'un element d'un schema. */ /* Routines de localisation d'un element d'un schema. */
/******************************************************/ /******************************************************/
#include "fctsys.h" #include "fctsys.h"
#include "gr_basic.h" #include "gr_basic.h"
...@@ -15,57 +15,58 @@ ...@@ -15,57 +15,58 @@
#include "protos.h" #include "protos.h"
/* Routines exportees */ /* Routines exportees */
int distance(int dx, int dy, int spot_cX, int spot_cY, int seuil); int distance( int dx, int dy, int spot_cX, int spot_cY, int seuil );
/* Routines Locales */ /* Routines Locales */
static EDA_BaseStruct *LastSnappedStruct = NULL; static EDA_BaseStruct* LastSnappedStruct = NULL;
static int PickedBoxMinX, PickedBoxMinY, PickedBoxMaxX, PickedBoxMaxY ; static int PickedBoxMinX, PickedBoxMinY, PickedBoxMaxX, PickedBoxMaxY;
static bool IsBox1InBox2( int StartX1, int StartY1, int EndX1, int EndY1, static bool IsBox1InBox2( int StartX1, int StartY1, int EndX1, int EndY1,
int StartX2, int StartY2, int EndX2, int EndY2 ); int StartX2, int StartY2, int EndX2, int EndY2 );
static bool IsPointInBox( int pX, int pY, static bool IsPointInBox( int pX, int pY,
int BoxX1, int BoxY1, int BoxX2, int BoxY2 ); int BoxX1, int BoxY1, int BoxX2, int BoxY2 );
static bool IsPointOnSegment( int pX, int pY, static bool IsPointOnSegment( int pX, int pY,
int SegmX1, int SegmY1, int SegmX2, int SegmY2, int seuil = 0); int SegmX1, int SegmY1, int SegmX2, int SegmY2, int seuil = 0 );
static bool SnapPoint2(const wxPoint & PosRef, int SearchMask, static bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
EDA_BaseStruct *DrawList, DrawPickedStruct *DontSnapList, int zoom_value); EDA_BaseStruct* DrawList, DrawPickedStruct* DontSnapList, int zoom_value );
/*********************************************************************/ /*********************************************************************/
EDA_SchComponentStruct * LocateSmallestComponent( SCH_SCREEN * Screen ) EDA_SchComponentStruct* LocateSmallestComponent( SCH_SCREEN* Screen )
/*********************************************************************/ /*********************************************************************/
/* Search the smaller (considering its area) component under the mouse cursor or the pcb cursor /* Search the smaller (considering its area) component under the mouse cursor or the pcb cursor
If more than 1 component is found, a pointer to the smaller component is returned * If more than 1 component is found, a pointer to the smaller component is returned
*/ */
{ {
EDA_SchComponentStruct * DrawLibItem = NULL, * LastDrawLibItem = NULL; EDA_SchComponentStruct* DrawLibItem = NULL, * LastDrawLibItem = NULL;
EDA_BaseStruct *DrawList; EDA_BaseStruct* DrawList;
EDA_Rect BoundaryBox; EDA_Rect BoundaryBox;
float sizeref = 0, sizecurr; float sizeref = 0, sizecurr;
DrawList = Screen->EEDrawList; DrawList = Screen->EEDrawList;
while ( DrawList ) while( DrawList )
{ {
if( ( SnapPoint2(Screen->m_MousePosition, LIBITEM, if( ( SnapPoint2( Screen->m_MousePosition, LIBITEM,
DrawList,NULL, Screen->GetZoom())) == FALSE ) DrawList, NULL, Screen->GetZoom() ) ) == FALSE )
{ {
if( ( SnapPoint2(Screen->m_Curseur, LIBITEM, if( ( SnapPoint2( Screen->m_Curseur, LIBITEM,
DrawList,NULL, Screen->GetZoom())) == FALSE ) break; DrawList, NULL, Screen->GetZoom() ) ) == FALSE )
break;
} }
DrawLibItem = (EDA_SchComponentStruct *) LastSnappedStruct; DrawLibItem = (EDA_SchComponentStruct*) LastSnappedStruct;
DrawList = DrawLibItem->Pnext; DrawList = DrawLibItem->Pnext;
if ( LastDrawLibItem == NULL ) // First time a component is located if( LastDrawLibItem == NULL ) // First time a component is located
{ {
LastDrawLibItem = DrawLibItem; LastDrawLibItem = DrawLibItem;
BoundaryBox = LastDrawLibItem->GetBoundaryBox(); BoundaryBox = LastDrawLibItem->GetBoundaryBox();
sizeref = ABS((float)BoundaryBox.GetWidth() * BoundaryBox.GetHeight()); sizeref = ABS( (float) BoundaryBox.GetWidth() * BoundaryBox.GetHeight() );
} }
else else
{ {
BoundaryBox = DrawLibItem->GetBoundaryBox(); BoundaryBox = DrawLibItem->GetBoundaryBox();
sizecurr = ABS((float)BoundaryBox.GetWidth() * BoundaryBox.GetHeight()); sizecurr = ABS( (float) BoundaryBox.GetWidth() * BoundaryBox.GetHeight() );
if ( sizeref > sizecurr ) // a smallest component is found if( sizeref > sizecurr ) // a smallest component is found
{ {
sizeref = sizecurr; sizeref = sizecurr;
LastDrawLibItem = DrawLibItem; LastDrawLibItem = DrawLibItem;
...@@ -78,96 +79,104 @@ float sizeref = 0, sizecurr; ...@@ -78,96 +79,104 @@ float sizeref = 0, sizecurr;
/* SearchMask = (bitwise OR): /* SearchMask = (bitwise OR):
LIBITEM * LIBITEM
WIREITEM * WIREITEM
BUSITEM * BUSITEM
RACCORDITEM * RACCORDITEM
JUNCTIONITEM * JUNCTIONITEM
DRAWITEM * DRAWITEM
TEXTITEM * TEXTITEM
LABELITEM * LABELITEM
SHEETITEM * SHEETITEM
MARKERITEM * MARKERITEM
NOCONNECTITEM * NOCONNECTITEM
SEARCH_PINITEM * SEARCH_PINITEM
SHEETLABELITEM * SHEETLABELITEM
FIELDCMPITEM * FIELDCMPITEM
*
if EXCLUDE_WIRE_BUS_ENDPOINTS is set, in wire ou bus search and locate, * if EXCLUDE_WIRE_BUS_ENDPOINTS is set, in wire ou bus search and locate,
start and end points are not included in search * start and end points are not included in search
if WIRE_BUS_ENDPOINTS_ONLY is set, in wire ou bus search and locate, * if WIRE_BUS_ENDPOINTS_ONLY is set, in wire ou bus search and locate,
only start and end points are included in search * only start and end points are included in search
*
*
Return: * Return:
-Bloc search: * -Bloc search:
pointeur sur liste de pointeurs de structures si Plusieurs * pointeur sur liste de pointeurs de structures si Plusieurs
structures selectionnees. * structures selectionnees.
pointeur sur la structure si 1 seule * pointeur sur la structure si 1 seule
*
Positon serach: * Positon serach:
pointeur sur la structure. * pointeur sur la structure.
Si pas de structures selectionnees: retourne NULL * Si pas de structures selectionnees: retourne NULL
*
*/ */
/***********************************************************************/ /***********************************************************************/
EDA_BaseStruct * PickStruct(const wxPoint & refpos, EDA_BaseStruct* PickStruct( const wxPoint& refpos,
EDA_BaseStruct *DrawList, int SearchMask ) EDA_BaseStruct* DrawList, int SearchMask )
/************************************************************************/ /************************************************************************/
/* Search an item at pos pos /* Search an item at pos pos
*/ */
{ {
bool Snapped; bool Snapped;
int zoom = ActiveScreen->GetZoom(); int zoom = ActiveScreen->GetZoom();
if ( DrawList == NULL ) return NULL;
if( (Snapped = SnapPoint2(refpos, SearchMask, if( DrawList == NULL )
DrawList,NULL, zoom)) != FALSE) return NULL;
if( ( Snapped = SnapPoint2( refpos, SearchMask,
DrawList, NULL, zoom ) ) != FALSE )
{ {
return( LastSnappedStruct); return LastSnappedStruct;
} }
return( NULL ); return NULL;
} }
/***********************************************************************/ /***********************************************************************/
EDA_BaseStruct * PickStruct( EDA_Rect & block, EDA_BaseStruct* PickStruct( EDA_Rect& block,
EDA_BaseStruct *DrawList, int SearchMask ) EDA_BaseStruct* DrawList, int SearchMask )
/************************************************************************/ /************************************************************************/
/* Search items in block /* Search items in block
*/ */
{ {
int x, y, OrigX, OrigY; int x, y, OrigX, OrigY;
DrawPickedStruct *PickedList = NULL, *PickedItem; DrawPickedStruct* PickedList = NULL, * PickedItem;
EDA_BaseStruct *DrawStruct; EDA_BaseStruct* DrawStruct;
OrigX = block.GetX(); OrigX = block.GetX();
OrigY = block.GetY(); OrigY = block.GetY();
x = block.GetRight(); x = block.GetRight();
y = block.GetBottom(); y = block.GetBottom();
if (x < OrigX) EXCHG(x, OrigX); if( x < OrigX )
if (y < OrigY) EXCHG(y, OrigY); EXCHG( x, OrigX );
if( y < OrigY )
EXCHG( y, OrigY );
for (DrawStruct = DrawList; DrawStruct != NULL; DrawStruct = DrawStruct->Pnext) for( DrawStruct = DrawList; DrawStruct != NULL; DrawStruct = DrawStruct->Pnext )
{ {
if( DrawStructInBox(OrigX, OrigY, x, y, DrawStruct) ) if( DrawStructInBox( OrigX, OrigY, x, y, DrawStruct ) )
{ {
/* Put this structure in the picked list: */ /* Put this structure in the picked list: */
PickedItem = new DrawPickedStruct(DrawStruct); PickedItem = new DrawPickedStruct( DrawStruct );
PickedItem->Pnext = PickedList; PickedItem->Pnext = PickedList;
PickedList = PickedItem; PickedList = PickedItem;
} }
} }
if (PickedList && PickedList->Pnext == NULL) if( PickedList && PickedList->Pnext == NULL )
{ {
/* Only one item was picked - convert to scalar form (no list): */ /* Only one item was picked - convert to scalar form (no list): */
PickedItem = PickedList; PickedItem = PickedList;
PickedList = (DrawPickedStruct *) PickedList->m_PickedStruct; PickedList = (DrawPickedStruct*) PickedList->m_PickedStruct;
delete PickedItem; delete PickedItem;
} }
if (PickedList != NULL) if( PickedList != NULL )
{ {
PickedBoxMinX = OrigX; PickedBoxMinY = OrigY; PickedBoxMinX = OrigX; PickedBoxMinY = OrigY;
PickedBoxMaxX = x; PickedBoxMaxY = y; PickedBoxMaxX = x; PickedBoxMaxY = y;
...@@ -176,6 +185,7 @@ EDA_BaseStruct *DrawStruct; ...@@ -176,6 +185,7 @@ EDA_BaseStruct *DrawStruct;
return PickedList; return PickedList;
} }
/***************************************************************************** /*****************************************************************************
* Routine to search all objects for the closest point to a given point, in * * Routine to search all objects for the closest point to a given point, in *
* drawing space, and snap it to that points if closer than SnapDistance. * * drawing space, and snap it to that points if closer than SnapDistance. *
...@@ -185,71 +195,78 @@ EDA_BaseStruct *DrawStruct; ...@@ -185,71 +195,78 @@ EDA_BaseStruct *DrawStruct;
* If DontSnapList is not NULL, structes in this list are skipped. * * If DontSnapList is not NULL, structes in this list are skipped. *
* The routine returns TRUE if point was snapped. * * The routine returns TRUE if point was snapped. *
*****************************************************************************/ *****************************************************************************/
bool SnapPoint2(const wxPoint & PosRef, int SearchMask, bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
EDA_BaseStruct *DrawList, DrawPickedStruct *DontSnapList, int zoom_value) EDA_BaseStruct* DrawList, DrawPickedStruct* DontSnapList, int zoom_value )
{ {
int i, *Points, x = PosRef.x, y = PosRef.y; int i, * Points, x = PosRef.x, y = PosRef.y;
int x1, y1, x2, y2, NumOfPoints2; int x1, y1, x2, y2, NumOfPoints2;
DrawPickedStruct *DontSnap; DrawPickedStruct* DontSnap;
int dx, dy; int dx, dy;
for (; DrawList != NULL; DrawList = DrawList->Pnext) for( ; DrawList != NULL; DrawList = DrawList->Pnext )
{ {
/* Make sure this structure is NOT in the dont snap list: */ /* Make sure this structure is NOT in the dont snap list: */
DontSnap = DontSnapList; DontSnap = DontSnapList;
for( ; DontSnap != NULL; DontSnap = (DrawPickedStruct *)DontSnap->Pnext) for( ; DontSnap != NULL; DontSnap = (DrawPickedStruct*) DontSnap->Pnext )
if (DontSnap->m_PickedStruct == DrawList) break; if( DontSnap->m_PickedStruct == DrawList )
break;
if(DontSnap) if (DontSnap->m_PickedStruct == DrawList) continue; if( DontSnap )
if( DontSnap->m_PickedStruct == DrawList )
continue;
switch (DrawList->Type()) switch( DrawList->Type() )
{ {
case DRAW_POLYLINE_STRUCT_TYPE: case DRAW_POLYLINE_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawPolylineStruct *) DrawList) #define STRUCT ( (DrawPolylineStruct*) DrawList )
if( !(SearchMask & (DRAWITEM|WIREITEM|BUSITEM)) ) break; if( !( SearchMask & (DRAWITEM | WIREITEM | BUSITEM) ) )
break;
Points = STRUCT->m_Points; Points = STRUCT->m_Points;
NumOfPoints2 = STRUCT->m_NumOfPoints * 2; NumOfPoints2 = STRUCT->m_NumOfPoints * 2;
for (i = 0; i < NumOfPoints2 - 2; i += 2) for( i = 0; i < NumOfPoints2 - 2; i += 2 )
{ {
x1 = Points[i]; y1 = Points[i+1]; x1 = Points[i]; y1 = Points[i + 1];
x2 = Points[i+2]; y2 = Points[i+3]; x2 = Points[i + 2]; y2 = Points[i + 3];
if (IsPointOnSegment(x,y, x1, y1, x2, y2) ) if( IsPointOnSegment( x, y, x1, y1, x2, y2 ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return(TRUE); return TRUE;
} }
} }
break; break;
case DRAW_SEGMENT_STRUCT_TYPE: case DRAW_SEGMENT_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((EDA_DrawLineStruct *) DrawList) #define STRUCT ( (EDA_DrawLineStruct*) DrawList )
if( !(SearchMask & (DRAWITEM|WIREITEM|BUSITEM)) ) break; if( !( SearchMask & (DRAWITEM | WIREITEM | BUSITEM) ) )
break;
if (IsPointOnSegment(x,y, STRUCT->m_Start.x,STRUCT->m_Start.y , if( IsPointOnSegment( x, y, STRUCT->m_Start.x, STRUCT->m_Start.y,
STRUCT->m_End.x, STRUCT->m_End.y) ) STRUCT->m_End.x, STRUCT->m_End.y ) )
{ {
if( ((SearchMask & DRAWITEM) && (STRUCT->m_Layer == LAYER_NOTES)) || if( ( (SearchMask & DRAWITEM) && (STRUCT->m_Layer == LAYER_NOTES) )
((SearchMask & WIREITEM) && (STRUCT->m_Layer == LAYER_WIRE)) || || ( (SearchMask & WIREITEM) && (STRUCT->m_Layer == LAYER_WIRE) )
((SearchMask & BUSITEM) && (STRUCT->m_Layer == LAYER_BUS)) || ( (SearchMask & BUSITEM) && (STRUCT->m_Layer == LAYER_BUS) )
) )
{ {
if (SearchMask & EXCLUDE_WIRE_BUS_ENDPOINTS) if( SearchMask & EXCLUDE_WIRE_BUS_ENDPOINTS )
{ {
if ( x == STRUCT->m_Start.x && y == STRUCT->m_Start.y ) if( x == STRUCT->m_Start.x && y == STRUCT->m_Start.y )
break; break;
if ( x == STRUCT->m_End.x && y == STRUCT->m_End.y ) if( x == STRUCT->m_End.x && y == STRUCT->m_End.y )
break; break;
} }
if (SearchMask & WIRE_BUS_ENDPOINTS_ONLY) if( SearchMask & WIRE_BUS_ENDPOINTS_ONLY )
{ {
if ( ! STRUCT->IsOneEndPointAt(wxPoint(x, y)) ) break; if( !STRUCT->IsOneEndPointAt( wxPoint( x, y ) ) )
break;
} }
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return(TRUE); return TRUE;
} }
} }
break; break;
...@@ -257,148 +274,161 @@ int dx, dy; ...@@ -257,148 +274,161 @@ int dx, dy;
case DRAW_BUSENTRY_STRUCT_TYPE: case DRAW_BUSENTRY_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawBusEntryStruct *) DrawList) #define STRUCT ( (DrawBusEntryStruct*) DrawList )
if( !(SearchMask & (RACCORDITEM)) ) break; if( !( SearchMask & (RACCORDITEM) ) )
break;
if (IsPointOnSegment(x,y, STRUCT->m_Pos.x,STRUCT->m_Pos.y, if( IsPointOnSegment( x, y, STRUCT->m_Pos.x, STRUCT->m_Pos.y,
STRUCT->m_End().x, STRUCT->m_End().y) ) STRUCT->m_End().x, STRUCT->m_End().y ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return(TRUE); return TRUE;
} }
break; break;
case DRAW_JUNCTION_STRUCT_TYPE: case DRAW_JUNCTION_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawJunctionStruct *) DrawList) #define STRUCT ( (DrawJunctionStruct*) DrawList )
if( !(SearchMask & JUNCTIONITEM) )break; if( !(SearchMask & JUNCTIONITEM) )
break;
dx = DRAWJUNCTION_SIZE / 2; dx = DRAWJUNCTION_SIZE / 2;
x1 = STRUCT->m_Pos.x - dx; x1 = STRUCT->m_Pos.x - dx;
y1 = STRUCT->m_Pos.y - dx; y1 = STRUCT->m_Pos.y - dx;
x2 = STRUCT->m_Pos.x + dx; x2 = STRUCT->m_Pos.x + dx;
y2 = STRUCT->m_Pos.y + dx; y2 = STRUCT->m_Pos.y + dx;
if(IsPointInBox(x, y, x1,y1, x2,y2) ) if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return(TRUE); return TRUE;
} }
break; break;
case DRAW_NOCONNECT_STRUCT_TYPE: case DRAW_NOCONNECT_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawNoConnectStruct *) DrawList) #define STRUCT ( (DrawNoConnectStruct*) DrawList )
if( !(SearchMask & NOCONNECTITEM) )break; if( !(SearchMask & NOCONNECTITEM) )
dx = (DRAWNOCONNECT_SIZE*zoom_value) / 2; break;
dx = (DRAWNOCONNECT_SIZE * zoom_value) / 2;
x1 = STRUCT->m_Pos.x - dx; x1 = STRUCT->m_Pos.x - dx;
y1 = STRUCT->m_Pos.y - dx; y1 = STRUCT->m_Pos.y - dx;
x2 = STRUCT->m_Pos.x + dx; x2 = STRUCT->m_Pos.x + dx;
y2 = STRUCT->m_Pos.y + dx; y2 = STRUCT->m_Pos.y + dx;
if(IsPointInBox(x, y, x1,y1, x2,y2) ) if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return(TRUE); return TRUE;
} }
break; break;
case DRAW_MARKER_STRUCT_TYPE: case DRAW_MARKER_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawMarkerStruct *) DrawList) #define STRUCT ( (DrawMarkerStruct*) DrawList )
if( !(SearchMask & MARKERITEM) )break; if( !(SearchMask & MARKERITEM) )
dx = (DRAWMARKER_SIZE*zoom_value) / 2; break;
dx = (DRAWMARKER_SIZE * zoom_value) / 2;
x1 = STRUCT->m_Pos.x - dx; x1 = STRUCT->m_Pos.x - dx;
y1 = STRUCT->m_Pos.y - dx; y1 = STRUCT->m_Pos.y - dx;
x2 = STRUCT->m_Pos.x + dx; x2 = STRUCT->m_Pos.x + dx;
y2 = STRUCT->m_Pos.y + dx; y2 = STRUCT->m_Pos.y + dx;
if(IsPointInBox(x, y, x1,y1, x2,y2) ) if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return(TRUE); return TRUE;
} }
break; break;
case DRAW_LABEL_STRUCT_TYPE: case DRAW_LABEL_STRUCT_TYPE:
case DRAW_TEXT_STRUCT_TYPE: case DRAW_TEXT_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawTextStruct *) DrawList) #define STRUCT ( (DrawTextStruct*) DrawList )
if( !(SearchMask & (TEXTITEM|LABELITEM)) ) break; if( !( SearchMask & (TEXTITEM | LABELITEM) ) )
break;
dx = STRUCT->m_Size.x * STRUCT->GetLength(); dx = STRUCT->m_Size.x * STRUCT->GetLength();
dy = STRUCT->m_Size.y; dy = STRUCT->m_Size.y;
x1 = x2 = STRUCT->m_Pos.x; x1 = x2 = STRUCT->m_Pos.x;
y1 = y2 = STRUCT->m_Pos.y; y1 = y2 = STRUCT->m_Pos.y;
switch( STRUCT->m_Orient)
switch( STRUCT->m_Orient )
{ {
case 0 : /* HORIZONTAL */ case 0: /* HORIZONTAL */
x2 += dx; y2 -= dy; x2 += dx; y2 -= dy;
break; break;
case 1 : /* VERTICAL UP */ case 1: /* VERTICAL UP */
x2 -= dy; y2 -= dx; x2 -= dy; y2 -= dx;
break; break;
case 2 : /* horizontal inverse */ case 2: /* horizontal inverse */
x2 -= dx; y2 += dy; x2 -= dx; y2 += dy;
break; break;
case 3 : /* vertical DOWN */ case 3: /* vertical DOWN */
x2 += dy; y2 += dx; x2 += dy; y2 += dx;
break; break;
} }
if(IsPointInBox(x, y, x1,y1, x2,y2) )
if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return(TRUE); return TRUE;
} }
break; break;
case DRAW_GLOBAL_LABEL_STRUCT_TYPE: case DRAW_GLOBAL_LABEL_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawGlobalLabelStruct *) DrawList) #define STRUCT ( (DrawGlobalLabelStruct*) DrawList )
if( !(SearchMask & LABELITEM) ) break; if( !(SearchMask & LABELITEM) )
break;
dx = STRUCT->m_Size.x * ( STRUCT->GetLength() + 1 ); /* longueur */ dx = STRUCT->m_Size.x * ( STRUCT->GetLength() + 1 ); /* longueur */
dy = STRUCT->m_Size.y / 2; /* Demi hauteur */ dy = STRUCT->m_Size.y / 2; /* Demi hauteur */
x1 = x2 = STRUCT->m_Pos.x; x1 = x2 = STRUCT->m_Pos.x;
y1 = y2 = STRUCT->m_Pos.y; y1 = y2 = STRUCT->m_Pos.y;
switch( STRUCT->m_Orient)
switch( STRUCT->m_Orient )
{ {
case 0 : /* HORIZONTAL */ case 0: /* HORIZONTAL */
x2 -= dx; y2 += dy; y1 -= dy; x2 -= dx; y2 += dy; y1 -= dy;
break; break;
case 1 : /* VERTICAL UP */ case 1: /* VERTICAL UP */
x1 -= dy; x2 += dy; y2 += dx; x1 -= dy; x2 += dy; y2 += dx;
break; break;
case 2 : /* horizontal inverse */ case 2: /* horizontal inverse */
x2 += dx; y2 += dy; y1 -= dy; x2 += dx; y2 += dy; y1 -= dy;
break; break;
case 3 : /* vertical DOWN */ case 3: /* vertical DOWN */
x1 -= dy; x2 += dy; y2 -= dx; x1 -= dy; x2 += dy; y2 -= dx;
break; break;
} }
if(IsPointInBox(x, y, x1,y1, x2,y2) )
if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return(TRUE); return TRUE;
} }
break; break;
case DRAW_LIB_ITEM_STRUCT_TYPE: case DRAW_LIB_ITEM_STRUCT_TYPE:
if( !(SearchMask & (LIBITEM|FIELDCMPITEM) ) ) break; if( !( SearchMask & (LIBITEM | FIELDCMPITEM) ) )
break;
if ( SearchMask & FIELDCMPITEM ) if( SearchMask & FIELDCMPITEM )
{ {
PartTextStruct * Field; PartTextStruct* Field;
EDA_SchComponentStruct * DrawLibItem = (EDA_SchComponentStruct *) DrawList; EDA_SchComponentStruct* DrawLibItem = (EDA_SchComponentStruct*) DrawList;
for ( i = REFERENCE; i < NUMBER_OF_FIELDS; i++ ) for( i = REFERENCE; i < NUMBER_OF_FIELDS; i++ )
{ {
Field = &DrawLibItem->m_Field[i]; Field = &DrawLibItem->m_Field[i];
if ( (Field->m_Attributs & TEXT_NO_VISIBLE) ) continue; if( (Field->m_Attributs & TEXT_NO_VISIBLE) )
if ( Field->IsVoid() ) continue; continue;
if( Field->IsVoid() )
continue;
EDA_Rect BoundaryBox = Field->GetBoundaryBox(); EDA_Rect BoundaryBox = Field->GetBoundaryBox();
if(BoundaryBox.Inside(x, y) ) if( BoundaryBox.Inside( x, y ) )
{ {
LastSnappedStruct = Field; LastSnappedStruct = Field;
return TRUE; return TRUE;
...@@ -408,9 +438,9 @@ int dx, dy; ...@@ -408,9 +438,9 @@ int dx, dy;
else else
{ {
#undef STRUCT #undef STRUCT
#define STRUCT ((EDA_SchComponentStruct *) DrawList) #define STRUCT ( (EDA_SchComponentStruct*) DrawList )
EDA_Rect BoundaryBox = STRUCT->GetBoundaryBox(); EDA_Rect BoundaryBox = STRUCT->GetBoundaryBox();
if ( BoundaryBox.Inside(x, y) ) if( BoundaryBox.Inside( x, y ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return TRUE; return TRUE;
...@@ -420,33 +450,36 @@ int dx, dy; ...@@ -420,33 +450,36 @@ int dx, dy;
case DRAW_SHEET_STRUCT_TYPE: case DRAW_SHEET_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawSheetStruct *) DrawList) #define STRUCT ( (DrawSheetStruct*) DrawList )
if( !(SearchMask & SHEETITEM) ) break; if( !(SearchMask & SHEETITEM) )
break;
/* Recalcul des coordonnees de l'encadrement du composant */ /* Recalcul des coordonnees de l'encadrement du composant */
x1 = STRUCT->m_Pos.x; x1 = STRUCT->m_Pos.x;
y1 = STRUCT->m_Pos.y; y1 = STRUCT->m_Pos.y;
x2 = STRUCT->m_Pos.x + STRUCT->m_Size.x; x2 = STRUCT->m_Pos.x + STRUCT->m_Size.x;
y2 = STRUCT->m_Pos.y + STRUCT->m_Size.y; y2 = STRUCT->m_Pos.y + STRUCT->m_Size.y;
if(IsPointInBox(x, y, x1, y1, x2, y2) ) if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return TRUE; return TRUE;
} }
break; break;
case DRAW_PICK_ITEM_STRUCT_TYPE : break; case DRAW_PICK_ITEM_STRUCT_TYPE:
break;
default: default:
{ {
wxString msg; wxString msg;
msg.Printf(wxT("SnapPoint2() error: unexpected strct type %d ("), DrawList->Type()); msg.Printf( wxT( "SnapPoint2() error: unexpected strct type %d (" ), DrawList->Type() );
msg << DrawList->ReturnClassName() << wxT(")"); msg << DrawList->ReturnClassName() << wxT( ")" );
DisplayError(NULL, msg); DisplayError( NULL, msg );
break; break;
} }
} }
} }
return FALSE; return FALSE;
} }
...@@ -456,226 +489,246 @@ int dx, dy; ...@@ -456,226 +489,246 @@ int dx, dy;
* defined by x1/y1 and x2/y2 (x1 < x2, y1 < y2), and return TRUE if so. This * * defined by x1/y1 and x2/y2 (x1 < x2, y1 < y2), and return TRUE if so. This *
* routine is used to pick all points in a given box. * * routine is used to pick all points in a given box. *
*****************************************************************************/ *****************************************************************************/
bool DrawStructInBox(int x1, int y1, int x2, int y2, bool DrawStructInBox( int x1, int y1, int x2, int y2,
EDA_BaseStruct *DrawStruct) EDA_BaseStruct* DrawStruct )
{ {
int i, *Points, xt1, yt1, xt2, yt2, NumOfPoints2; int i, * Points, xt1, yt1, xt2, yt2, NumOfPoints2;
int dx, dy; int dx, dy;
wxString msg; wxString msg;
switch (DrawStruct->Type()) switch( DrawStruct->Type() )
{ {
case DRAW_POLYLINE_STRUCT_TYPE: case DRAW_POLYLINE_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawPolylineStruct *) DrawStruct) #define STRUCT ( (DrawPolylineStruct*) DrawStruct )
Points = STRUCT->m_Points; Points = STRUCT->m_Points;
NumOfPoints2 = STRUCT->m_NumOfPoints * 2; NumOfPoints2 = STRUCT->m_NumOfPoints * 2;
for (i = 0; i < NumOfPoints2; i += 2) for( i = 0; i < NumOfPoints2; i += 2 )
{ {
if (Points[i] >= x1 && Points[i] <= x2 && if( Points[i] >= x1 && Points[i] <= x2
Points[i+1] >= y1 && Points[i+1] <=y2) return TRUE; && Points[i + 1] >= y1 && Points[i + 1] <=y2 )
return TRUE;
} }
break; break;
case DRAW_SEGMENT_STRUCT_TYPE: case DRAW_SEGMENT_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((EDA_DrawLineStruct *) DrawStruct) #define STRUCT ( (EDA_DrawLineStruct*) DrawStruct )
if( STRUCT->m_Start.x >= x1 && STRUCT->m_Start.x <= x2 && if( STRUCT->m_Start.x >= x1 && STRUCT->m_Start.x <= x2
STRUCT->m_Start.y >= y1 && STRUCT->m_Start.y <=y2) return TRUE; && STRUCT->m_Start.y >= y1 && STRUCT->m_Start.y <=y2 )
if( (STRUCT->m_End.x >= x1) && (STRUCT->m_End.x <= x2) && return TRUE;
(STRUCT->m_End.y >= y1) && (STRUCT->m_End.y <=y2) ) return TRUE; if( (STRUCT->m_End.x >= x1) && (STRUCT->m_End.x <= x2)
&& (STRUCT->m_End.y >= y1) && (STRUCT->m_End.y <=y2) )
return TRUE;
break; break;
case DRAW_BUSENTRY_STRUCT_TYPE: case DRAW_BUSENTRY_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawBusEntryStruct *) DrawStruct) #define STRUCT ( (DrawBusEntryStruct*) DrawStruct )
if( STRUCT->m_Pos.x >= x1 && STRUCT->m_Pos.x <= x2 && if( STRUCT->m_Pos.x >= x1 && STRUCT->m_Pos.x <= x2
STRUCT->m_Pos.y >= y1 && STRUCT->m_Pos.y <=y2) && STRUCT->m_Pos.y >= y1 && STRUCT->m_Pos.y <=y2 )
return TRUE; return TRUE;
if( (STRUCT->m_End().x >= x1) && ( STRUCT->m_End().x <= x2) && if( (STRUCT->m_End().x >= x1) && ( STRUCT->m_End().x <= x2)
( STRUCT->m_End().y >= y1) && ( STRUCT->m_End().y <=y2) ) && ( STRUCT->m_End().y >= y1) && ( STRUCT->m_End().y <=y2) )
return TRUE; return TRUE;
break; break;
case DRAW_JUNCTION_STRUCT_TYPE: case DRAW_JUNCTION_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawJunctionStruct *) DrawStruct) #define STRUCT ( (DrawJunctionStruct*) DrawStruct )
if( (STRUCT->m_Pos.x >= x1) && (STRUCT->m_Pos.x <= x2) && if( (STRUCT->m_Pos.x >= x1) && (STRUCT->m_Pos.x <= x2)
(STRUCT->m_Pos.y >= y1) && (STRUCT->m_Pos.y <= y2) ) && (STRUCT->m_Pos.y >= y1) && (STRUCT->m_Pos.y <= y2) )
return TRUE; return TRUE;
break; break;
case DRAW_NOCONNECT_STRUCT_TYPE: case DRAW_NOCONNECT_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawNoConnectStruct *) DrawStruct) #define STRUCT ( (DrawNoConnectStruct*) DrawStruct )
if( (STRUCT->m_Pos.x >= x1) && (STRUCT->m_Pos.x <= x2) && if( (STRUCT->m_Pos.x >= x1) && (STRUCT->m_Pos.x <= x2)
(STRUCT->m_Pos.y >= y1) && (STRUCT->m_Pos.y <= y2) ) && (STRUCT->m_Pos.y >= y1) && (STRUCT->m_Pos.y <= y2) )
return TRUE; return TRUE;
break; break;
case DRAW_MARKER_STRUCT_TYPE: case DRAW_MARKER_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawMarkerStruct *) DrawStruct) #define STRUCT ( (DrawMarkerStruct*) DrawStruct )
if( (STRUCT->m_Pos.x >= x1) && (STRUCT->m_Pos.x <= x2) && if( (STRUCT->m_Pos.x >= x1) && (STRUCT->m_Pos.x <= x2)
(STRUCT->m_Pos.y >= y1) && (STRUCT->m_Pos.y <= y2) ) && (STRUCT->m_Pos.y >= y1) && (STRUCT->m_Pos.y <= y2) )
return TRUE; return TRUE;
break; break;
case DRAW_LABEL_STRUCT_TYPE: case DRAW_LABEL_STRUCT_TYPE:
case DRAW_TEXT_STRUCT_TYPE: case DRAW_TEXT_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawTextStruct *) DrawStruct) #define STRUCT ( (DrawTextStruct*) DrawStruct )
dx = STRUCT->m_Size.x * STRUCT->GetLength(); dx = STRUCT->m_Size.x * STRUCT->GetLength();
dy = STRUCT->m_Size.y; dy = STRUCT->m_Size.y;
xt1 = xt2 = STRUCT->m_Pos.x; xt1 = xt2 = STRUCT->m_Pos.x;
yt1 = yt2 = STRUCT->m_Pos.y; yt1 = yt2 = STRUCT->m_Pos.y;
switch( STRUCT->m_Orient)
switch( STRUCT->m_Orient )
{ {
case 0 : /* HORIZONTAL */ case 0: /* HORIZONTAL */
xt2 += dx; yt2 -= dy; xt2 += dx; yt2 -= dy;
break; break;
case 1 : /* VERTICAL UP */ case 1: /* VERTICAL UP */
xt2 -= dy; yt2 -= dx; xt2 -= dy; yt2 -= dx;
break; break;
case 2 : /* horizontal inverse */ case 2: /* horizontal inverse */
xt2 -= dx; yt2 += dy; xt2 -= dx; yt2 += dy;
break; break;
case 3 : /* vertical DOWN */ case 3: /* vertical DOWN */
xt2 += dy; yt2 += dx; xt2 += dy; yt2 += dx;
break; break;
} }
if( IsBox1InBox2(xt1,yt1, xt2, yt2, x1, y1, x2, y2) ) return TRUE;
if( IsBox1InBox2( xt1, yt1, xt2, yt2, x1, y1, x2, y2 ) )
return TRUE;
break; break;
case DRAW_GLOBAL_LABEL_STRUCT_TYPE: case DRAW_GLOBAL_LABEL_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawGlobalLabelStruct *) DrawStruct) #define STRUCT ( (DrawGlobalLabelStruct*) DrawStruct )
dx = STRUCT->m_Size.x * ( STRUCT->GetLength() + 1); /* longueur totale */ dx = STRUCT->m_Size.x * ( STRUCT->GetLength() + 1); /* longueur totale */
dy = STRUCT->m_Size.y / 2; /* Demi hauteur */ dy = STRUCT->m_Size.y / 2; /* Demi hauteur */
xt1 = xt2 = STRUCT->m_Pos.x; xt1 = xt2 = STRUCT->m_Pos.x;
yt1 = yt2 = STRUCT->m_Pos.y; yt1 = yt2 = STRUCT->m_Pos.y;
switch( STRUCT->m_Orient)
switch( STRUCT->m_Orient )
{ {
case 0 : /* HORIZONTAL */ case 0: /* HORIZONTAL */
xt2 -= dx; yt2 += dy; yt1 -= dy; xt2 -= dx; yt2 += dy; yt1 -= dy;
break; break;
case 1 : /* VERTICAL UP */ case 1: /* VERTICAL UP */
xt1 -= dy; xt2 += dy; yt2 += dx; xt1 -= dy; xt2 += dy; yt2 += dx;
break; break;
case 2 : /* horizontal inverse */ case 2: /* horizontal inverse */
xt2 += dx; yt2 += dy; yt1 -= dy; xt2 += dx; yt2 += dy; yt1 -= dy;
break; break;
case 3 : /* vertical DOWN */ case 3: /* vertical DOWN */
xt1 -= dy; xt2 += dy; yt2 -= dx; xt1 -= dy; xt2 += dy; yt2 -= dx;
break; break;
} }
if( IsBox1InBox2(xt1,yt1, xt2, yt2, x1, y1, x2, y2) ) return TRUE;
if( IsBox1InBox2( xt1, yt1, xt2, yt2, x1, y1, x2, y2 ) )
return TRUE;
break; break;
case DRAW_LIB_ITEM_STRUCT_TYPE: case DRAW_LIB_ITEM_STRUCT_TYPE:
{ {
#undef STRUCT #undef STRUCT
#define STRUCT ((EDA_SchComponentStruct *) DrawStruct) #define STRUCT ( (EDA_SchComponentStruct*) DrawStruct )
EDA_Rect BoundaryBox = STRUCT->GetBoundaryBox(); EDA_Rect BoundaryBox = STRUCT->GetBoundaryBox();
xt1 = BoundaryBox.GetX(); xt1 = BoundaryBox.GetX();
yt1 = BoundaryBox.GetY(); yt1 = BoundaryBox.GetY();
xt2 = BoundaryBox.GetRight(); xt2 = BoundaryBox.GetRight();
yt2 = BoundaryBox.GetBottom(); yt2 = BoundaryBox.GetBottom();
if( IsBox1InBox2(xt1,yt1, xt2, yt2, x1, y1, x2, y2) ) return TRUE; if( IsBox1InBox2( xt1, yt1, xt2, yt2, x1, y1, x2, y2 ) )
return TRUE;
break; break;
} }
case DRAW_SHEET_STRUCT_TYPE : case DRAW_SHEET_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ((DrawSheetStruct *) DrawStruct) #define STRUCT ( (DrawSheetStruct*) DrawStruct )
/* Recalcul des coordonnees de l'encadrement du composant */ /* Recalcul des coordonnees de l'encadrement du composant */
xt1 = STRUCT->m_Pos.x; xt1 = STRUCT->m_Pos.x;
yt1 = STRUCT->m_Pos.y; yt1 = STRUCT->m_Pos.y;
xt2 = STRUCT->m_Pos.x + STRUCT->m_Size.x; xt2 = STRUCT->m_Pos.x + STRUCT->m_Size.x;
yt2 = STRUCT->m_Pos.y + STRUCT->m_Size.y; yt2 = STRUCT->m_Pos.y + STRUCT->m_Size.y;
if( IsBox1InBox2(xt1,yt1, xt2, yt2, x1, y1, x2, y2) ) if( IsBox1InBox2( xt1, yt1, xt2, yt2, x1, y1, x2, y2 ) )
return TRUE; return TRUE;
break; break;
case DRAW_SHEETLABEL_STRUCT_TYPE : break; case DRAW_SHEETLABEL_STRUCT_TYPE:
case DRAW_PICK_ITEM_STRUCT_TYPE : break; break;
case DRAW_PICK_ITEM_STRUCT_TYPE:
break;
default: default:
msg.Printf( msg.Printf(
wxT("DrawStructInBox() Err: unexpected StructType %d ("), wxT( "DrawStructInBox() Err: unexpected StructType %d (" ),
DrawStruct->Type() ); DrawStruct->Type() );
msg << DrawStruct->ReturnClassName() << wxT(")"); msg << DrawStruct->ReturnClassName() << wxT( ")" );
DisplayError(NULL, msg ); DisplayError( NULL, msg );
break; break;
} }
return FALSE; return FALSE;
} }
/****************************************************************************/ /****************************************************************************/
static bool IsBox1InBox2( int StartX1, int StartY1, int EndX1, int EndY1, static bool IsBox1InBox2( int StartX1, int StartY1, int EndX1, int EndY1,
int StartX2, int StartY2, int EndX2, int EndY2 ) int StartX2, int StartY2, int EndX2, int EndY2 )
/****************************************************************************/ /****************************************************************************/
/* Routine detectant que le rectangle 1 (Box1) et le rectangle 2 (Box2) se
recouvrent.
Retourne TRUE ou FALSE.
On Considere ici qu'il y a recouvrement si l'un au moins des coins /* Routine detectant que le rectangle 1 (Box1) et le rectangle 2 (Box2) se
d'un 'Box' est compris dans l'autre * recouvrent.
*/ * Retourne TRUE ou FALSE.
*
* On Considere ici qu'il y a recouvrement si l'un au moins des coins
* d'un 'Box' est compris dans l'autre
*/
{ {
int cX, cY; int cX, cY;
if(StartX1 > EndX1) EXCHG(StartX1, EndX1); if( StartX1 > EndX1 )
if(StartX2 > EndX2) EXCHG(StartX2, EndX2); EXCHG( StartX1, EndX1 );
if(StartY1 > EndY1) EXCHG(StartY1, EndY1); if( StartX2 > EndX2 )
if(StartY2 > EndY2) EXCHG(StartY2, EndY2); EXCHG( StartX2, EndX2 );
if( StartY1 > EndY1 )
EXCHG( StartY1, EndY1 );
if( StartY2 > EndY2 )
EXCHG( StartY2, EndY2 );
/* Tst des 4 coins du rectangle 1 */ /* Tst des 4 coins du rectangle 1 */
cX = StartX1; cY = StartY1; /* 1er coin */ cX = StartX1; cY = StartY1; /* 1er coin */
if( (cX >= StartX2) && (cX <= EndX2) && (cY >= StartY2) && (cY <= EndY2) ) if( (cX >= StartX2) && (cX <= EndX2) && (cY >= StartY2) && (cY <= EndY2) )
return(TRUE); return TRUE;
cX = EndX1; cY = StartY1; /* 2er coin */ cX = EndX1; cY = StartY1; /* 2er coin */
if( (cX >= StartX2) && (cX <= EndX2) && (cY >= StartY2) && (cY <= EndY2) ) if( (cX >= StartX2) && (cX <= EndX2) && (cY >= StartY2) && (cY <= EndY2) )
return(TRUE); return TRUE;
cX = EndX1; cY = EndY1; /* 3eme coin */ cX = EndX1; cY = EndY1; /* 3eme coin */
if( (cX >= StartX2) && (cX <= EndX2) && (cY >= StartY2) && (cY <= EndY2) ) if( (cX >= StartX2) && (cX <= EndX2) && (cY >= StartY2) && (cY <= EndY2) )
return(TRUE); return TRUE;
cX = StartX1; cY = EndY1; /* 4eme coin */ cX = StartX1; cY = EndY1; /* 4eme coin */
if( (cX >= StartX2) && (cX <= EndX2) && (cY >= StartY2) && (cY <= EndY2) ) if( (cX >= StartX2) && (cX <= EndX2) && (cY >= StartY2) && (cY <= EndY2) )
return(TRUE); return TRUE;
/* Tst des 4 coins du rectangle 2 */ /* Tst des 4 coins du rectangle 2 */
cX = StartX2; cY = StartY2; /* 1er coin */ cX = StartX2; cY = StartY2; /* 1er coin */
if( (cX >= StartX1) && (cX <= EndX1) && (cY >= StartY1) && (cY <= EndY1) ) if( (cX >= StartX1) && (cX <= EndX1) && (cY >= StartY1) && (cY <= EndY1) )
return(TRUE); return TRUE;
cX = EndX2; cY = StartY2; /* 2er coin */ cX = EndX2; cY = StartY2; /* 2er coin */
if( (cX >= StartX1) && (cX <= EndX1) && (cY >= StartY1) && (cY <= EndY1) ) if( (cX >= StartX1) && (cX <= EndX1) && (cY >= StartY1) && (cY <= EndY1) )
return(TRUE); return TRUE;
cX = EndX2; cY = EndY2; /* 3er coin */ cX = EndX2; cY = EndY2; /* 3er coin */
if( (cX >= StartX1) && (cX <= EndX1) && (cY >= StartY1) && (cY <= EndY1) ) if( (cX >= StartX1) && (cX <= EndX1) && (cY >= StartY1) && (cY <= EndY1) )
return(TRUE); return TRUE;
cX = StartX2; cY = EndY2; /* 4er coin */ cX = StartX2; cY = EndY2; /* 4er coin */
if( (cX >= StartX1) && (cX <= EndX1) && (cY >= StartY1) && (cY <= EndY1) ) if( (cX >= StartX1) && (cX <= EndX1) && (cY >= StartY1) && (cY <= EndY1) )
return(TRUE); return TRUE;
return(FALSE); return FALSE;
} }
...@@ -683,18 +736,22 @@ int cX, cY; ...@@ -683,18 +736,22 @@ int cX, cY;
static bool IsPointInBox( int pX, int pY, static bool IsPointInBox( int pX, int pY,
int BoxX1, int BoxY1, int BoxX2, int BoxY2 ) int BoxX1, int BoxY1, int BoxX2, int BoxY2 )
/**********************************************************************/ /**********************************************************************/
/* Routine detectant que le point pX,pY est dans le rectangle (Box)
Retourne TRUE ou FALSE.
*/ /* Routine detectant que le point pX,pY est dans le rectangle (Box)
* Retourne TRUE ou FALSE.
*
*/
{ {
if(BoxX1 > BoxX2) EXCHG(BoxX1, BoxX2); if( BoxX1 > BoxX2 )
if(BoxY1 > BoxY2) EXCHG(BoxY1, BoxY2); EXCHG( BoxX1, BoxX2 );
if( BoxY1 > BoxY2 )
EXCHG( BoxY1, BoxY2 );
if( (pX >= BoxX1) && (pX <= BoxX2) && (pY >= BoxY1) && (pY <= BoxY2) ) if( (pX >= BoxX1) && (pX <= BoxX2) && (pY >= BoxY1) && (pY <= BoxY2) )
return(TRUE); return TRUE;
else return(FALSE); else
return FALSE;
} }
...@@ -702,40 +759,50 @@ static bool IsPointInBox( int pX, int pY, ...@@ -702,40 +759,50 @@ static bool IsPointInBox( int pX, int pY,
static bool IsPointOnSegment( int pX, int pY, static bool IsPointOnSegment( int pX, int pY,
int SegmX1, int SegmY1, int SegmX2, int SegmY2, int seuil ) int SegmX1, int SegmY1, int SegmX2, int SegmY2, int seuil )
/********************************************************************************/ /********************************************************************************/
/* Routine detectant que le point pX,pY est sur le Segment X1,Y1 a X2,Y2 /* Routine detectant que le point pX,pY est sur le Segment X1,Y1 a X2,Y2
Retourne TRUE ou FALSE. * Retourne TRUE ou FALSE.
*/ */
{ {
/* Recalcul des coord avec SegmX1, SegmX2 comme origine */ /* Recalcul des coord avec SegmX1, SegmX2 comme origine */
pX -= SegmX1; pY -= SegmY1; pX -= SegmX1; pY -= SegmY1;
SegmX2 -= SegmX1; SegmY2 -= SegmY1; SegmX2 -= SegmX1; SegmY2 -= SegmY1;
if( distance( SegmX2, SegmY2, pX, pY, seuil ) ) return(TRUE); if( distance( SegmX2, SegmY2, pX, pY, seuil ) )
return TRUE;
else return(FALSE); else
return FALSE;
} }
/*********************************************************************************/ /*********************************************************************************/
LibEDA_BaseStruct * LocateDrawItem(SCH_SCREEN * Screen, const wxPoint & refpoint, LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen,
EDA_LibComponentStruct * LibEntry, int Unit, int Convert, int masque) const wxPoint& refpoint,
EDA_LibComponentStruct* LibEntry,
int Unit,
int Convert,
int masque )
/*********************************************************************************/ /*********************************************************************************/
/* Routine de localisation d'un element de dessin de symbole( sauf pins ) /* Routine de localisation d'un element de dessin de symbole( sauf pins )
Unit = Unite d'appartenance (si Unit = 0, recherche sur toutes unites) * Unit = Unite d'appartenance (si Unit = 0, recherche sur toutes unites)
Convert = Conversion d'appartenance (si Convert = 0, recherche sur * Convert = Conversion d'appartenance (si Convert = 0, recherche sur
toutes variantes) * toutes variantes)
*/ */
{ {
int x, y, dx, dy, ii, *ptpoly; int x, y, dx, dy, ii, * ptpoly;
int px, py; int px, py;
LibEDA_BaseStruct * DrawItem; LibEDA_BaseStruct* DrawItem;
int seuil; int seuil;
if( LibEntry == NULL ) return(NULL); if( LibEntry == NULL )
return NULL;
if ( LibEntry->Type != ROOT ) if( LibEntry->Type != ROOT )
{ {
DisplayError(NULL, wxT("Error in LocateDrawItem: Entry is ALIAS")); DisplayError( NULL, wxT( "Error in LocateDrawItem: Entry is ALIAS" ) );
return(NULL); return NULL;
} }
DrawItem = LibEntry->m_Drawings; DrawItem = LibEntry->m_Drawings;
...@@ -744,99 +811,109 @@ int seuil; ...@@ -744,99 +811,109 @@ int seuil;
px = refpoint.x; px = refpoint.x;
py = refpoint.y; py = refpoint.y;
for( ; DrawItem != NULL ; DrawItem = DrawItem->Next() ) for( ; DrawItem != NULL; DrawItem = DrawItem->Next() )
{ {
if(Unit && DrawItem->m_Unit && (Unit != DrawItem->m_Unit) ) continue; if( Unit && DrawItem->m_Unit && (Unit != DrawItem->m_Unit) )
if(Convert && DrawItem->m_Convert && (Convert != DrawItem->m_Convert) ) continue;
if( Convert && DrawItem->m_Convert && (Convert != DrawItem->m_Convert) )
continue; continue;
switch ( DrawItem->Type() ) switch( DrawItem->Type() )
{ {
case COMPONENT_ARC_DRAW_TYPE: case COMPONENT_ARC_DRAW_TYPE:
{ {
LibDrawArc * Arc = (LibDrawArc *) DrawItem; LibDrawArc* Arc = (LibDrawArc*) DrawItem;
if( (masque & LOCATE_COMPONENT_ARC_DRAW_TYPE) == 0) break; if( (masque & LOCATE_COMPONENT_ARC_DRAW_TYPE) == 0 )
break;
dx = px - Arc->m_Pos.x; dx = px - Arc->m_Pos.x;
dy = py + Arc->m_Pos.y; dy = py + Arc->m_Pos.y;
ii = (int)sqrt( dx*dx + dy*dy); ii = (int) sqrt( dx * dx + dy * dy );
if ( abs(ii - Arc->m_Rayon) <= seuil) return( DrawItem); if( abs( ii - Arc->m_Rayon ) <= seuil )
return DrawItem;
} }
break; break;
case COMPONENT_CIRCLE_DRAW_TYPE: case COMPONENT_CIRCLE_DRAW_TYPE:
{ {
LibDrawCircle * Circle = (LibDrawCircle *) DrawItem; LibDrawCircle* Circle = (LibDrawCircle*) DrawItem;
if( (masque & LOCATE_COMPONENT_CIRCLE_DRAW_TYPE) == 0) break; if( (masque & LOCATE_COMPONENT_CIRCLE_DRAW_TYPE) == 0 )
break;
dx = px - Circle->m_Pos.x; dx = px - Circle->m_Pos.x;
dy = py + Circle->m_Pos.y; dy = py + Circle->m_Pos.y;
ii = (int)sqrt( dx*dx + dy*dy); ii = (int) sqrt( dx * dx + dy * dy );
if ( abs(ii - Circle->m_Rayon) <= seuil) return( DrawItem); if( abs( ii - Circle->m_Rayon ) <= seuil )
return DrawItem;
} }
break; break;
case COMPONENT_RECT_DRAW_TYPE: case COMPONENT_RECT_DRAW_TYPE:
{ // Locate a rect if the mouse cursor is on a segment { // Locate a rect if the mouse cursor is on a segment
LibDrawSquare * Square = (LibDrawSquare *) DrawItem; LibDrawSquare* Square = (LibDrawSquare*) DrawItem;
if( (masque & LOCATE_COMPONENT_RECT_DRAW_TYPE) == 0) break; if( (masque & LOCATE_COMPONENT_RECT_DRAW_TYPE) == 0 )
if(IsPointOnSegment(px,py, // locate lower segment break;
Square->m_Pos.x, - Square->m_Pos.y, if( IsPointOnSegment( px, py, // locate lower segment
Square->m_End.x, - Square->m_Pos.y, seuil) ) Square->m_Pos.x, -Square->m_Pos.y,
return(DrawItem); Square->m_End.x, -Square->m_Pos.y, seuil ) )
if(IsPointOnSegment(px, py, // locate right segment return DrawItem;
Square->m_End.x, - Square->m_Pos.y, if( IsPointOnSegment( px, py, // locate right segment
Square->m_End.x, - Square->m_End.y, seuil) ) Square->m_End.x, -Square->m_Pos.y,
return(DrawItem); Square->m_End.x, -Square->m_End.y, seuil ) )
if(IsPointOnSegment(px, py, // locate upper segment return DrawItem;
Square->m_End.x, - Square->m_End.y, if( IsPointOnSegment( px, py, // locate upper segment
Square->m_Pos.x, - Square->m_End.y, seuil) ) Square->m_End.x, -Square->m_End.y,
return(DrawItem); Square->m_Pos.x, -Square->m_End.y, seuil ) )
if(IsPointOnSegment(px, py, // locate left segment return DrawItem;
Square->m_Pos.x, - Square->m_End.y, if( IsPointOnSegment( px, py, // locate left segment
Square->m_Pos.x, - Square->m_Pos.y, seuil) ) Square->m_Pos.x, -Square->m_End.y,
return(DrawItem); Square->m_Pos.x, -Square->m_Pos.y, seuil ) )
return DrawItem;
} }
break; break;
case COMPONENT_POLYLINE_DRAW_TYPE: case COMPONENT_POLYLINE_DRAW_TYPE:
{ {
LibDrawPolyline * polyline = (LibDrawPolyline *) DrawItem; LibDrawPolyline* polyline = (LibDrawPolyline*) DrawItem;
if( (masque & LOCATE_COMPONENT_POLYLINE_DRAW_TYPE) == 0) break; if( (masque & LOCATE_COMPONENT_POLYLINE_DRAW_TYPE) == 0 )
break;
ptpoly = polyline->PolyList; ptpoly = polyline->PolyList;
for( ii = polyline->n-1; ii > 0; ii--, ptpoly += 2) for( ii = polyline->n - 1; ii > 0; ii--, ptpoly += 2 )
{ {
if(IsPointOnSegment(px, py, if( IsPointOnSegment( px, py,
ptpoly[0], - ptpoly[1], ptpoly[2], - ptpoly[3], seuil) ) ptpoly[0], -ptpoly[1], ptpoly[2], -ptpoly[3], seuil ) )
return(DrawItem); return DrawItem;
} }
} }
break; break;
case COMPONENT_LINE_DRAW_TYPE: case COMPONENT_LINE_DRAW_TYPE:
{ {
LibDrawSegment * Segment = (LibDrawSegment *) DrawItem; LibDrawSegment* Segment = (LibDrawSegment*) DrawItem;
if( (masque & LOCATE_COMPONENT_LINE_DRAW_TYPE) == 0) break; if( (masque & LOCATE_COMPONENT_LINE_DRAW_TYPE) == 0 )
if(IsPointOnSegment(px, py, break;
Segment->m_Pos.x, - Segment->m_Pos.y, if( IsPointOnSegment( px, py,
Segment->m_End.x, - Segment->m_End.y, seuil) ) Segment->m_Pos.x, -Segment->m_Pos.y,
return(DrawItem); Segment->m_End.x, -Segment->m_End.y, seuil ) )
return DrawItem;
} }
break; break;
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE: case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
{ {
LibDrawText * Text = (LibDrawText *) DrawItem; LibDrawText* Text = (LibDrawText*) DrawItem;
if( (masque & LOCATE_COMPONENT_GRAPHIC_TEXT_DRAW_TYPE) == 0) break; if( (masque & LOCATE_COMPONENT_GRAPHIC_TEXT_DRAW_TYPE) == 0 )
ii = Text->m_Text.Len(); if ( ii < 2 ) ii = 2; break;
ii = Text->m_Text.Len(); if( ii < 2 )
ii = 2;
dx = (Text->m_Size.x * ii) / 2; dx = (Text->m_Size.x * ii) / 2;
dy = Text->m_Size.y / 2; dy = Text->m_Size.y / 2;
if(Text->m_Horiz == TEXT_ORIENT_VERT) if( Text->m_Horiz == TEXT_ORIENT_VERT )
{ {
EXCHG(dx,dy); EXCHG( dx, dy );
} }
x = px - Text->m_Pos.x; x = px - Text->m_Pos.x;
y = py + Text->m_Pos.y; y = py + Text->m_Pos.y;
if( (abs(x) <= dx) && (abs(y) <= dy) ) if( (abs( x ) <= dx) && (abs( y ) <= dy) )
return(DrawItem); /* Texte trouve */ return DrawItem; /* Texte trouve */
} }
break; break;
...@@ -844,153 +921,159 @@ int seuil; ...@@ -844,153 +921,159 @@ int seuil;
; ;
} }
} }
return(NULL);
return NULL;
} }
/****************************************************************/ /****************************************************************/
int distance(int dx, int dy, int spot_cX, int spot_cY, int seuil) int distance( int dx, int dy, int spot_cX, int spot_cY, int seuil )
/****************************************************************/ /****************************************************************/
/* /*
Calcul de la distance du point spot_cx,spot_cy a un segment de droite, * Calcul de la distance du point spot_cx,spot_cy a un segment de droite,
d'origine 0,0 et d'extremite dx, dy; * d'origine 0,0 et d'extremite dx, dy;
retourne: * retourne:
0 si distance > seuil * 0 si distance > seuil
1 si distance <= seuil * 1 si distance <= seuil
Variables utilisees ( sont ramenees au repere centre sur l'origine du segment) * Variables utilisees ( sont ramenees au repere centre sur l'origine du segment)
dx, dy = coord de l'extremite segment. * dx, dy = coord de l'extremite segment.
spot_cX,spot_cY = coord du curseur souris * spot_cX,spot_cY = coord du curseur souris
la recherche se fait selon 4 cas: * la recherche se fait selon 4 cas:
segment horizontal * segment horizontal
segment vertical * segment vertical
segment quelconque * segment quelconque
*/ */
{ {
int cXrot, cYrot , /* coord du point (souris) dans le repere tourne */ int cXrot, cYrot, /* coord du point (souris) dans le repere tourne */
segX, segY; /* coord extremite segment tj >= 0 */ segX, segY; /* coord extremite segment tj >= 0 */
int pointX, pointY; /* coord point a tester dans repere modifie dans lequel int pointX, pointY;/* coord point a tester dans repere modifie dans lequel
segX et segY sont >=0 */ * segX et segY sont >=0 */
segX = dx ; segY = dy; pointX = spot_cX ; pointY = spot_cY ; segX = dx; segY = dy; pointX = spot_cX; pointY = spot_cY;
/*Recalcul coord pour que le segment soit dans 1er quadrant (coord >= 0)*/ /*Recalcul coord pour que le segment soit dans 1er quadrant (coord >= 0)*/
if (segX < 0) /* mise en0 par symetrie par rapport a l'axe Y */ if( segX < 0 ) /* mise en0 par symetrie par rapport a l'axe Y */
{ {
segX = -segX ; pointX = - pointX ; segX = -segX; pointX = -pointX;
} }
if (segY < 0) /* mise en > 0 par symymetrie par rapport a l'axe X */ if( segY < 0 ) /* mise en > 0 par symymetrie par rapport a l'axe X */
{ {
segY = -segY ; pointY = -pointY ; segY = -segY; pointY = -pointY;
} }
if ( segY == 0 ) /* piste Horizontale */ if( segY == 0 ) /* piste Horizontale */
{ {
if(abs(pointY) <= seuil ) if( abs( pointY ) <= seuil )
{ {
if((pointX >= 0) && (pointX <= segX) ) return(1); if( (pointX >= 0) && (pointX <= segX) )
return 1;
/* Etude des extremites : cercle de rayon seuil */ /* Etude des extremites : cercle de rayon seuil */
if( (pointX < 0) && (pointX >= -seuil) ) if( (pointX < 0) && (pointX >= -seuil) )
{ {
if( ((pointX * pointX) + (pointY*pointY)) <= (seuil*seuil) ) if( ( (pointX * pointX) + (pointY * pointY) ) <= (seuil * seuil) )
return(1); return 1;
} }
if( (pointX > segX) && (pointX <= (segX+seuil)) ) if( (pointX > segX) && ( pointX <= (segX + seuil) ) )
{ {
if( (((pointX-segX) * (pointX-segX)) + (pointY*pointY)) <= (seuil*seuil) ) if( ( ( (pointX - segX) * (pointX - segX) ) + (pointY * pointY) ) <=
return(1); (seuil * seuil) )
return 1;
} }
} }
} }
else if( segX == 0 ) /* piste verticale */
else if ( segX == 0 ) /* piste verticale */
{ {
if( abs(pointX) <= seuil) if( abs( pointX ) <= seuil )
{ {
if((pointY >= 0 ) && (pointY <= segY) ) return(1); if( (pointY >= 0 ) && (pointY <= segY) )
return 1;
if( (pointY < 0) && (pointY >= -seuil) ) if( (pointY < 0) && (pointY >= -seuil) )
{ {
if( ((pointY * pointY) + (pointX*pointX)) <= (seuil*seuil) ) if( ( (pointY * pointY) + (pointX * pointX) ) <= (seuil * seuil) )
return(1); return 1;
} }
if( (pointY > segY) && (pointY <= (segY+seuil)) ) if( (pointY > segY) && ( pointY <= (segY + seuil) ) )
{ {
if( ( ((pointY-segY) * (pointY-segY)) + (pointX*pointX)) <= (seuil*seuil) ) if( ( ( (pointY - segY) * (pointY - segY) ) + (pointX * pointX) ) <=
return(1); (seuil * seuil) )
return 1;
} }
} }
} }
else /* orientation quelconque */ else /* orientation quelconque */
{ {
/* On fait un changement d'axe (rotation) de facon a ce que le segment /* On fait un changement d'axe (rotation) de facon a ce que le segment
de piste soit horizontal dans le nouveau repere */ * de piste soit horizontal dans le nouveau repere */
int angle; int angle;
angle = (int)( atan2((float)segY, (float)segX) * 1800 / M_PI) ; angle = (int) ( atan2( (float) segY, (float) segX ) * 1800 / M_PI);
cXrot = pointX; cYrot = pointY; cXrot = pointX; cYrot = pointY;
RotatePoint(&cXrot, &cYrot, angle); /* Rotation du point a tester */ RotatePoint( &cXrot, &cYrot, angle ); /* Rotation du point a tester */
RotatePoint(&segX, &segY, angle) ; /* Rotation du segment */ RotatePoint( &segX, &segY, angle ); /* Rotation du segment */
/*la piste est Horizontale , par suite des modifs de coordonnes /*la piste est Horizontale , par suite des modifs de coordonnes
et d'axe, donc segX = longueur du segment */ * et d'axe, donc segX = longueur du segment */
if ( abs(cYrot) <= seuil ) /* ok sur axe vertical) */ if( abs( cYrot ) <= seuil ) /* ok sur axe vertical) */
{ {
if ((cXrot >= 0) && (cXrot <= segX) ) return(1) ; if( (cXrot >= 0) && (cXrot <= segX) )
return 1;
/* Etude des extremites : cercle de rayon seuil */ /* Etude des extremites : cercle de rayon seuil */
if( (cXrot < 0) && (cXrot >= -seuil) ) if( (cXrot < 0) && (cXrot >= -seuil) )
{ {
if( ((cXrot * cXrot) + (cYrot*cYrot)) <= (seuil*seuil) ) if( ( (cXrot * cXrot) + (cYrot * cYrot) ) <= (seuil * seuil) )
return(1); return 1;
} }
if( (cXrot > segX) && (cXrot <= (segX+seuil)) ) if( (cXrot > segX) && ( cXrot <= (segX + seuil) ) )
{ {
if( (((cXrot-segX) * (cXrot-segX)) + (cYrot*cYrot)) <= (seuil*seuil) ) if( ( ( (cXrot - segX) * (cXrot - segX) ) + (cYrot * cYrot) ) <= (seuil * seuil) )
return(1); return 1;
} }
} }
} }
return(0) ; return 0;
} }
/*******************************************************************/ /*******************************************************************/
LibEDA_BaseStruct * LocatePin( const wxPoint & RefPos, LibEDA_BaseStruct* LocatePin( const wxPoint& RefPos,
EDA_LibComponentStruct * Entry, EDA_LibComponentStruct* Entry,
int Unit, int convert, EDA_SchComponentStruct * DrawLibItem) int Unit, int convert, EDA_SchComponentStruct* DrawLibItem )
/*******************************************************************/ /*******************************************************************/
/* Routine de localisation d'une PIN de la PartLib pointee par Entry /* Routine de localisation d'une PIN de la PartLib pointee par Entry
retourne un pointeur sur la pin, ou NULL si pas trouve * retourne un pointeur sur la pin, ou NULL si pas trouve
Si Unit = 0, le numero d'unite n'est pas teste * Si Unit = 0, le numero d'unite n'est pas teste
Si convert = 0, le numero convert n'est pas teste * Si convert = 0, le numero convert n'est pas teste
*
m_Transform = matrice de transformation. * m_Transform = matrice de transformation.
Si NULL: matrice de transformation " normale" [1 , 0 , 0 , -1] * Si NULL: matrice de transformation " normale" [1 , 0 , 0 , -1]
(la matrice de transformation " normale" etant [1 , 0 , 0 , -1] * (la matrice de transformation " normale" etant [1 , 0 , 0 , -1]
la coord dy doit etre inversee). * la coord dy doit etre inversee).
PartX, PartY: coordonnees de positionnement du composant * PartX, PartY: coordonnees de positionnement du composant
*/ */
{ {
LibEDA_BaseStruct * DrawItem; LibEDA_BaseStruct* DrawItem;
LibDrawPin * Pin; LibDrawPin* Pin;
int x1, y1, x2, y2; int x1, y1, x2, y2;
if ( Entry == NULL ) return(NULL); if( Entry == NULL )
return NULL;
if ( Entry->Type != ROOT ) if( Entry->Type != ROOT )
{ {
DisplayError(NULL, wxT("LocatePin() error: Entry is ALIAS")); DisplayError( NULL, wxT( "LocatePin() error: Entry is ALIAS" ) );
return(NULL); return NULL;
} }
DrawItem = Entry->m_Drawings; DrawItem = Entry->m_Drawings;
for ( ; DrawItem != NULL; DrawItem = DrawItem->Next()) for( ; DrawItem != NULL; DrawItem = DrawItem->Next() )
{ {
if(DrawItem->Type() == COMPONENT_PIN_DRAW_TYPE) /* Pin Trouvee */ if( DrawItem->Type() == COMPONENT_PIN_DRAW_TYPE ) /* Pin Trouvee */
{ {
Pin = (LibDrawPin *) DrawItem; Pin = (LibDrawPin*) DrawItem;
if( Unit && DrawItem->m_Unit && (DrawItem->m_Unit != Unit) ) if( Unit && DrawItem->m_Unit && (DrawItem->m_Unit != Unit) )
continue; continue;
...@@ -1003,7 +1086,7 @@ int x1, y1, x2, y2; ...@@ -1003,7 +1086,7 @@ int x1, y1, x2, y2;
x1 = Pin->ReturnPinEndPoint().x; x1 = Pin->ReturnPinEndPoint().x;
y1 = Pin->ReturnPinEndPoint().y; y1 = Pin->ReturnPinEndPoint().y;
if(DrawLibItem == NULL ) if( DrawLibItem == NULL )
{ {
y1 = -y1; y2 = -y2; y1 = -y1; y2 = -y2;
} }
...@@ -1021,81 +1104,95 @@ int x1, y1, x2, y2; ...@@ -1021,81 +1104,95 @@ int x1, y1, x2, y2;
+ DrawLibItem->m_Transform[1][1] * y; + DrawLibItem->m_Transform[1][1] * y;
} }
if (x1 > x2 ) EXCHG(x1,x2); if (y1 > y2 ) EXCHG(y1,y2); if( x1 > x2 )
EXCHG( x1, x2 );if( y1 > y2 )
EXCHG( y1, y2 );
if( (RefPos.x >= x1) && (RefPos.x <= x2) && if( (RefPos.x >= x1) && (RefPos.x <= x2)
(RefPos.y >= y1) && (RefPos.y <= y2) ) && (RefPos.y >= y1) && (RefPos.y <= y2) )
return(DrawItem); return DrawItem;
} }
} }
return(NULL);
return NULL;
} }
/***********************************************************************************/ /***********************************************************************************/
DrawSheetLabelStruct * LocateSheetLabel(DrawSheetStruct *Sheet, const wxPoint & pos) DrawSheetLabelStruct* LocateSheetLabel( DrawSheetStruct* Sheet, const wxPoint& pos )
/***********************************************************************************/ /***********************************************************************************/
{ {
int size , dy, minx, maxx; int size, dy, minx, maxx;
DrawSheetLabelStruct * SheetLabel; DrawSheetLabelStruct* SheetLabel;
SheetLabel = Sheet->m_Label; SheetLabel = Sheet->m_Label;
while((SheetLabel) && (SheetLabel->Type()==DRAW_SHEETLABEL_STRUCT_TYPE)) while( (SheetLabel) && (SheetLabel->Type()==DRAW_SHEETLABEL_STRUCT_TYPE) )
{ {
size = ( SheetLabel->GetLength()+1 ) * SheetLabel->m_Size.x; size = ( SheetLabel->GetLength() + 1 ) * SheetLabel->m_Size.x;
if (SheetLabel->m_Edge) size = -size ; if( SheetLabel->m_Edge )
size = -size;
minx = SheetLabel->m_Pos.x; maxx = SheetLabel->m_Pos.x + size; minx = SheetLabel->m_Pos.x; maxx = SheetLabel->m_Pos.x + size;
if( maxx < minx ) EXCHG(maxx,minx); if( maxx < minx )
EXCHG( maxx, minx );
dy = SheetLabel->m_Size.x / 2; dy = SheetLabel->m_Size.x / 2;
if( (ABS(pos.y - SheetLabel->m_Pos.y) <= dy ) && if( (ABS( pos.y - SheetLabel->m_Pos.y ) <= dy )
(pos.x <= maxx) && && (pos.x <= maxx)
(pos.x >= minx) ) && (pos.x >= minx) )
return(SheetLabel); return SheetLabel;
SheetLabel = (DrawSheetLabelStruct *) SheetLabel->Pnext; SheetLabel = (DrawSheetLabelStruct*) SheetLabel->Pnext;
} }
return(NULL);
return NULL;
} }
/**************************************************************************/ /**************************************************************************/
LibDrawPin * LocateAnyPin(EDA_BaseStruct *DrawList, const wxPoint & RefPos, LibDrawPin* LocateAnyPin( EDA_BaseStruct* DrawList, const wxPoint& RefPos,
EDA_SchComponentStruct ** libpart) EDA_SchComponentStruct** libpart )
/**************************************************************************/ /**************************************************************************/
{ {
EDA_BaseStruct *DrawStruct; EDA_BaseStruct* DrawStruct;
EDA_LibComponentStruct * Entry; EDA_LibComponentStruct* Entry;
EDA_SchComponentStruct * LibItem = NULL; EDA_SchComponentStruct* LibItem = NULL;
LibDrawPin * Pin = NULL; LibDrawPin* Pin = NULL;
for(DrawStruct = DrawList; DrawStruct != NULL; DrawStruct = DrawStruct->Pnext ) for( DrawStruct = DrawList; DrawStruct != NULL; DrawStruct = DrawStruct->Pnext )
{ {
if( DrawStruct->Type() != DRAW_LIB_ITEM_STRUCT_TYPE ) if( DrawStruct->Type() != DRAW_LIB_ITEM_STRUCT_TYPE )
continue; continue;
LibItem = (EDA_SchComponentStruct *) DrawStruct; LibItem = (EDA_SchComponentStruct*) DrawStruct;
Entry = FindLibPart( LibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT); Entry = FindLibPart( LibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
if( Entry == NULL ) continue; if( Entry == NULL )
Pin = (LibDrawPin *) LocatePin(RefPos, Entry, LibItem->m_Multi, continue;
LibItem->m_Convert, LibItem); Pin = (LibDrawPin*) LocatePin( RefPos, Entry, LibItem->m_Multi,
if( Pin ) break; LibItem->m_Convert, LibItem );
} if( Pin )
if ( libpart ) *libpart = LibItem; break;
}
if( libpart )
*libpart = LibItem;
return Pin; return Pin;
} }
/***************************************************************/ /***************************************************************/
DrawSheetLabelStruct * LocateAnyPinSheet(const wxPoint & RefPos, DrawSheetLabelStruct* LocateAnyPinSheet( const wxPoint& RefPos,
EDA_BaseStruct *DrawList) EDA_BaseStruct* DrawList )
/***************************************************************/ /***************************************************************/
{ {
EDA_BaseStruct *DrawStruct; EDA_BaseStruct* DrawStruct;
DrawSheetLabelStruct * PinSheet = NULL; DrawSheetLabelStruct* PinSheet = NULL;
for( DrawStruct = DrawList; DrawStruct != NULL; DrawStruct = DrawStruct->Pnext ) for( DrawStruct = DrawList; DrawStruct != NULL; DrawStruct = DrawStruct->Pnext )
{ {
if( DrawStruct->Type() != DRAW_SHEET_STRUCT_TYPE ) if( DrawStruct->Type() != DRAW_SHEET_STRUCT_TYPE )
continue; continue;
PinSheet = LocateSheetLabel( (DrawSheetStruct *) DrawStruct, PinSheet = LocateSheetLabel( (DrawSheetStruct*) DrawStruct,
RefPos); RefPos );
if( PinSheet ) break; if( PinSheet )
break;
} }
return PinSheet; return PinSheet;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment