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,167 +15,177 @@ ...@@ -15,167 +15,177 @@
#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; }
DrawList = DrawLibItem->Pnext; DrawLibItem = (EDA_SchComponentStruct*) LastSnappedStruct;
if ( LastDrawLibItem == NULL ) // First time a component is located DrawList = DrawLibItem->Pnext;
{ if( LastDrawLibItem == NULL ) // First time a component is located
LastDrawLibItem = DrawLibItem; {
BoundaryBox = LastDrawLibItem->GetBoundaryBox(); LastDrawLibItem = DrawLibItem;
sizeref = ABS((float)BoundaryBox.GetWidth() * BoundaryBox.GetHeight()); BoundaryBox = LastDrawLibItem->GetBoundaryBox();
} sizeref = ABS( (float) BoundaryBox.GetWidth() * BoundaryBox.GetHeight() );
else }
{ else
BoundaryBox = DrawLibItem->GetBoundaryBox(); {
sizecurr = ABS((float)BoundaryBox.GetWidth() * BoundaryBox.GetHeight()); BoundaryBox = DrawLibItem->GetBoundaryBox();
if ( sizeref > sizecurr ) // a smallest component is found sizecurr = ABS( (float) BoundaryBox.GetWidth() * BoundaryBox.GetHeight() );
{ if( sizeref > sizecurr ) // a smallest component is found
sizeref = sizecurr; {
LastDrawLibItem = DrawLibItem; sizeref = sizecurr;
} LastDrawLibItem = DrawLibItem;
} }
} }
}
return LastDrawLibItem;
return LastDrawLibItem;
} }
/* 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( DrawList == NULL )
if( (Snapped = SnapPoint2(refpos, SearchMask, return NULL;
DrawList,NULL, zoom)) != FALSE)
{ if( ( Snapped = SnapPoint2( refpos, SearchMask,
return( LastSnappedStruct); DrawList, NULL, zoom ) ) != FALSE )
} {
return( NULL ); return LastSnappedStruct;
}
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 )
for (DrawStruct = DrawList; DrawStruct != NULL; DrawStruct = DrawStruct->Pnext) EXCHG( y, OrigY );
{
if( DrawStructInBox(OrigX, OrigY, x, y, DrawStruct) ) for( DrawStruct = DrawList; DrawStruct != NULL; DrawStruct = DrawStruct->Pnext )
{ {
/* Put this structure in the picked list: */ if( DrawStructInBox( OrigX, OrigY, x, y, DrawStruct ) )
PickedItem = new DrawPickedStruct(DrawStruct); {
PickedItem->Pnext = PickedList; /* Put this structure in the picked list: */
PickedList = PickedItem; PickedItem = new DrawPickedStruct( DrawStruct );
}
} PickedItem->Pnext = PickedList;
PickedList = PickedItem;
if (PickedList && PickedList->Pnext == NULL) }
{ }
/* Only one item was picked - convert to scalar form (no list): */
PickedItem = PickedList; if( PickedList && PickedList->Pnext == NULL )
PickedList = (DrawPickedStruct *) PickedList->m_PickedStruct; {
delete PickedItem; /* Only one item was picked - convert to scalar form (no list): */
} PickedItem = PickedList;
PickedList = (DrawPickedStruct*) PickedList->m_PickedStruct;
if (PickedList != NULL) delete PickedItem;
{ }
PickedBoxMinX = OrigX; PickedBoxMinY = OrigY;
PickedBoxMaxX = x; PickedBoxMaxY = y; if( PickedList != NULL )
} {
PickedBoxMinX = OrigX; PickedBoxMinY = OrigY;
return PickedList; PickedBoxMaxX = x; PickedBoxMaxY = y;
}
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,269 +195,292 @@ EDA_BaseStruct *DrawStruct; ...@@ -185,269 +195,292 @@ 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 )
switch (DrawList->Type()) if( DontSnap->m_PickedStruct == DrawList )
{ continue;
case DRAW_POLYLINE_STRUCT_TYPE:
#undef STRUCT switch( DrawList->Type() )
#define STRUCT ((DrawPolylineStruct *) DrawList) {
if( !(SearchMask & (DRAWITEM|WIREITEM|BUSITEM)) ) break; case DRAW_POLYLINE_STRUCT_TYPE:
Points = STRUCT->m_Points; #undef STRUCT
NumOfPoints2 = STRUCT->m_NumOfPoints * 2; #define STRUCT ( (DrawPolylineStruct*) DrawList )
for (i = 0; i < NumOfPoints2 - 2; i += 2) if( !( SearchMask & (DRAWITEM | WIREITEM | BUSITEM) ) )
{ break;
x1 = Points[i]; y1 = Points[i+1];
x2 = Points[i+2]; y2 = Points[i+3]; Points = STRUCT->m_Points;
if (IsPointOnSegment(x,y, x1, y1, x2, y2) ) NumOfPoints2 = STRUCT->m_NumOfPoints * 2;
{ for( i = 0; i < NumOfPoints2 - 2; i += 2 )
LastSnappedStruct = DrawList; {
return(TRUE); x1 = Points[i]; y1 = Points[i + 1];
} x2 = Points[i + 2]; y2 = Points[i + 3];
} if( IsPointOnSegment( x, y, x1, y1, x2, y2 ) )
break; {
LastSnappedStruct = DrawList;
case DRAW_SEGMENT_STRUCT_TYPE: return TRUE;
#undef STRUCT }
#define STRUCT ((EDA_DrawLineStruct *) DrawList) }
if( !(SearchMask & (DRAWITEM|WIREITEM|BUSITEM)) ) break; break;
if (IsPointOnSegment(x,y, STRUCT->m_Start.x,STRUCT->m_Start.y , case DRAW_SEGMENT_STRUCT_TYPE:
STRUCT->m_End.x, STRUCT->m_End.y) ) #undef STRUCT
{ #define STRUCT ( (EDA_DrawLineStruct*) DrawList )
if( ((SearchMask & DRAWITEM) && (STRUCT->m_Layer == LAYER_NOTES)) || if( !( SearchMask & (DRAWITEM | WIREITEM | BUSITEM) ) )
((SearchMask & WIREITEM) && (STRUCT->m_Layer == LAYER_WIRE)) || break;
((SearchMask & BUSITEM) && (STRUCT->m_Layer == LAYER_BUS))
) if( IsPointOnSegment( x, y, STRUCT->m_Start.x, STRUCT->m_Start.y,
{ STRUCT->m_End.x, STRUCT->m_End.y ) )
if (SearchMask & EXCLUDE_WIRE_BUS_ENDPOINTS) {
{ if( ( (SearchMask & DRAWITEM) && (STRUCT->m_Layer == LAYER_NOTES) )
if ( x == STRUCT->m_Start.x && y == STRUCT->m_Start.y ) || ( (SearchMask & WIREITEM) && (STRUCT->m_Layer == LAYER_WIRE) )
break; || ( (SearchMask & BUSITEM) && (STRUCT->m_Layer == LAYER_BUS) )
if ( x == STRUCT->m_End.x && y == STRUCT->m_End.y ) )
break; {
} if( SearchMask & EXCLUDE_WIRE_BUS_ENDPOINTS )
{
if (SearchMask & WIRE_BUS_ENDPOINTS_ONLY) if( x == STRUCT->m_Start.x && y == STRUCT->m_Start.y )
{ break;
if ( ! STRUCT->IsOneEndPointAt(wxPoint(x, y)) ) break; if( x == STRUCT->m_End.x && y == STRUCT->m_End.y )
} break;
}
LastSnappedStruct = DrawList;
return(TRUE); if( SearchMask & WIRE_BUS_ENDPOINTS_ONLY )
} {
} if( !STRUCT->IsOneEndPointAt( wxPoint( x, y ) ) )
break; break;
}
case DRAW_BUSENTRY_STRUCT_TYPE: LastSnappedStruct = DrawList;
#undef STRUCT return TRUE;
#define STRUCT ((DrawBusEntryStruct *) DrawList) }
if( !(SearchMask & (RACCORDITEM)) ) break; }
break;
if (IsPointOnSegment(x,y, STRUCT->m_Pos.x,STRUCT->m_Pos.y,
STRUCT->m_End().x, STRUCT->m_End().y) )
{ case DRAW_BUSENTRY_STRUCT_TYPE:
LastSnappedStruct = DrawList; #undef STRUCT
return(TRUE); #define STRUCT ( (DrawBusEntryStruct*) DrawList )
} if( !( SearchMask & (RACCORDITEM) ) )
break; break;
case DRAW_JUNCTION_STRUCT_TYPE: if( IsPointOnSegment( x, y, STRUCT->m_Pos.x, STRUCT->m_Pos.y,
#undef STRUCT STRUCT->m_End().x, STRUCT->m_End().y ) )
#define STRUCT ((DrawJunctionStruct *) DrawList) {
if( !(SearchMask & JUNCTIONITEM) )break; LastSnappedStruct = DrawList;
dx = DRAWJUNCTION_SIZE / 2; return TRUE;
x1 = STRUCT->m_Pos.x - dx; }
y1 = STRUCT->m_Pos.y - dx; break;
x2 = STRUCT->m_Pos.x + dx;
y2 = STRUCT->m_Pos.y + dx; case DRAW_JUNCTION_STRUCT_TYPE:
if(IsPointInBox(x, y, x1,y1, x2,y2) ) #undef STRUCT
{ #define STRUCT ( (DrawJunctionStruct*) DrawList )
LastSnappedStruct = DrawList; if( !(SearchMask & JUNCTIONITEM) )
return(TRUE); break;
} dx = DRAWJUNCTION_SIZE / 2;
break; x1 = STRUCT->m_Pos.x - dx;
y1 = STRUCT->m_Pos.y - dx;
x2 = STRUCT->m_Pos.x + dx;
case DRAW_NOCONNECT_STRUCT_TYPE: y2 = STRUCT->m_Pos.y + dx;
#undef STRUCT if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
#define STRUCT ((DrawNoConnectStruct *) DrawList) {
if( !(SearchMask & NOCONNECTITEM) )break; LastSnappedStruct = DrawList;
dx = (DRAWNOCONNECT_SIZE*zoom_value) / 2; return TRUE;
x1 = STRUCT->m_Pos.x - dx; }
y1 = STRUCT->m_Pos.y - dx; break;
x2 = STRUCT->m_Pos.x + dx;
y2 = STRUCT->m_Pos.y + dx;
if(IsPointInBox(x, y, x1,y1, x2,y2) ) case DRAW_NOCONNECT_STRUCT_TYPE:
{ #undef STRUCT
LastSnappedStruct = DrawList; #define STRUCT ( (DrawNoConnectStruct*) DrawList )
return(TRUE); if( !(SearchMask & NOCONNECTITEM) )
} break;
break; dx = (DRAWNOCONNECT_SIZE * zoom_value) / 2;
x1 = STRUCT->m_Pos.x - dx;
case DRAW_MARKER_STRUCT_TYPE: y1 = STRUCT->m_Pos.y - dx;
#undef STRUCT x2 = STRUCT->m_Pos.x + dx;
#define STRUCT ((DrawMarkerStruct *) DrawList) y2 = STRUCT->m_Pos.y + dx;
if( !(SearchMask & MARKERITEM) )break; if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
dx = (DRAWMARKER_SIZE*zoom_value) / 2; {
x1 = STRUCT->m_Pos.x - dx; LastSnappedStruct = DrawList;
y1 = STRUCT->m_Pos.y - dx; return TRUE;
x2 = STRUCT->m_Pos.x + dx; }
y2 = STRUCT->m_Pos.y + dx; break;
if(IsPointInBox(x, y, x1,y1, x2,y2) )
{ case DRAW_MARKER_STRUCT_TYPE:
LastSnappedStruct = DrawList; #undef STRUCT
return(TRUE); #define STRUCT ( (DrawMarkerStruct*) DrawList )
} if( !(SearchMask & MARKERITEM) )
break; break;
dx = (DRAWMARKER_SIZE * zoom_value) / 2;
case DRAW_LABEL_STRUCT_TYPE: x1 = STRUCT->m_Pos.x - dx;
case DRAW_TEXT_STRUCT_TYPE: y1 = STRUCT->m_Pos.y - dx;
#undef STRUCT x2 = STRUCT->m_Pos.x + dx;
#define STRUCT ((DrawTextStruct *) DrawList) y2 = STRUCT->m_Pos.y + dx;
if( !(SearchMask & (TEXTITEM|LABELITEM)) ) break; if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
dx = STRUCT->m_Size.x * STRUCT->GetLength(); {
dy = STRUCT->m_Size.y; LastSnappedStruct = DrawList;
x1 = x2 = STRUCT->m_Pos.x; return TRUE;
y1 = y2 = STRUCT->m_Pos.y; }
switch( STRUCT->m_Orient) break;
{
case 0 : /* HORIZONTAL */ case DRAW_LABEL_STRUCT_TYPE:
x2 += dx; y2 -= dy; case DRAW_TEXT_STRUCT_TYPE:
break; #undef STRUCT
#define STRUCT ( (DrawTextStruct*) DrawList )
case 1 : /* VERTICAL UP */ if( !( SearchMask & (TEXTITEM | LABELITEM) ) )
x2 -= dy; y2 -= dx; break;
break; dx = STRUCT->m_Size.x * STRUCT->GetLength();
dy = STRUCT->m_Size.y;
case 2 : /* horizontal inverse */ x1 = x2 = STRUCT->m_Pos.x;
x2 -= dx; y2 += dy; y1 = y2 = STRUCT->m_Pos.y;
break;
switch( STRUCT->m_Orient )
case 3 : /* vertical DOWN */ {
x2 += dy; y2 += dx; case 0: /* HORIZONTAL */
break; x2 += dx; y2 -= dy;
} break;
if(IsPointInBox(x, y, x1,y1, x2,y2) )
{ case 1: /* VERTICAL UP */
LastSnappedStruct = DrawList; x2 -= dy; y2 -= dx;
return(TRUE); break;
}
break; case 2: /* horizontal inverse */
x2 -= dx; y2 += dy;
break;
case DRAW_GLOBAL_LABEL_STRUCT_TYPE:
#undef STRUCT case 3: /* vertical DOWN */
#define STRUCT ((DrawGlobalLabelStruct *) DrawList) x2 += dy; y2 += dx;
if( !(SearchMask & LABELITEM) ) break; break;
dx = STRUCT->m_Size.x * ( STRUCT->GetLength() + 1 ); /* longueur */ }
dy = STRUCT->m_Size.y / 2; /* Demi hauteur */
x1 = x2 = STRUCT->m_Pos.x; if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
y1 = y2 = STRUCT->m_Pos.y; {
switch( STRUCT->m_Orient) LastSnappedStruct = DrawList;
{ return TRUE;
case 0 : /* HORIZONTAL */ }
x2 -= dx; y2 += dy; y1 -= dy; break;
break;
case 1 : /* VERTICAL UP */ case DRAW_GLOBAL_LABEL_STRUCT_TYPE:
x1 -= dy; x2 += dy; y2 += dx; #undef STRUCT
break; #define STRUCT ( (DrawGlobalLabelStruct*) DrawList )
if( !(SearchMask & LABELITEM) )
case 2 : /* horizontal inverse */ break;
x2 += dx; y2 += dy; y1 -= dy; dx = STRUCT->m_Size.x * ( STRUCT->GetLength() + 1 ); /* longueur */
break; dy = STRUCT->m_Size.y / 2; /* Demi hauteur */
x1 = x2 = STRUCT->m_Pos.x;
case 3 : /* vertical DOWN */ y1 = y2 = STRUCT->m_Pos.y;
x1 -= dy; x2 += dy; y2 -= dx;
break; switch( STRUCT->m_Orient )
} {
if(IsPointInBox(x, y, x1,y1, x2,y2) ) case 0: /* HORIZONTAL */
{ x2 -= dx; y2 += dy; y1 -= dy;
LastSnappedStruct = DrawList; break;
return(TRUE);
} case 1: /* VERTICAL UP */
break; x1 -= dy; x2 += dy; y2 += dx;
break;
case DRAW_LIB_ITEM_STRUCT_TYPE:
if( !(SearchMask & (LIBITEM|FIELDCMPITEM) ) ) break; case 2: /* horizontal inverse */
x2 += dx; y2 += dy; y1 -= dy;
if ( SearchMask & FIELDCMPITEM ) break;
{
PartTextStruct * Field; case 3: /* vertical DOWN */
EDA_SchComponentStruct * DrawLibItem = (EDA_SchComponentStruct *) DrawList; x1 -= dy; x2 += dy; y2 -= dx;
for ( i = REFERENCE; i < NUMBER_OF_FIELDS; i++ ) break;
{ }
Field = &DrawLibItem->m_Field[i];
if ( (Field->m_Attributs & TEXT_NO_VISIBLE) ) continue; if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
if ( Field->IsVoid() ) continue; {
EDA_Rect BoundaryBox = Field->GetBoundaryBox(); LastSnappedStruct = DrawList;
if(BoundaryBox.Inside(x, y) ) return TRUE;
{ }
LastSnappedStruct = Field; break;
return TRUE;
} case DRAW_LIB_ITEM_STRUCT_TYPE:
} if( !( SearchMask & (LIBITEM | FIELDCMPITEM) ) )
} break;
else
{ if( SearchMask & FIELDCMPITEM )
#undef STRUCT {
#define STRUCT ((EDA_SchComponentStruct *) DrawList) PartTextStruct* Field;
EDA_Rect BoundaryBox = STRUCT->GetBoundaryBox(); EDA_SchComponentStruct* DrawLibItem = (EDA_SchComponentStruct*) DrawList;
if ( BoundaryBox.Inside(x, y) ) for( i = REFERENCE; i < NUMBER_OF_FIELDS; i++ )
{ {
LastSnappedStruct = DrawList; Field = &DrawLibItem->m_Field[i];
return TRUE; if( (Field->m_Attributs & TEXT_NO_VISIBLE) )
} continue;
} if( Field->IsVoid() )
break; continue;
EDA_Rect BoundaryBox = Field->GetBoundaryBox();
case DRAW_SHEET_STRUCT_TYPE: if( BoundaryBox.Inside( x, y ) )
#undef STRUCT {
#define STRUCT ((DrawSheetStruct *) DrawList) LastSnappedStruct = Field;
if( !(SearchMask & SHEETITEM) ) break; return TRUE;
/* Recalcul des coordonnees de l'encadrement du composant */ }
x1 = STRUCT->m_Pos.x; }
y1 = STRUCT->m_Pos.y; }
x2 = STRUCT->m_Pos.x + STRUCT->m_Size.x; else
y2 = STRUCT->m_Pos.y + STRUCT->m_Size.y; {
#undef STRUCT
if(IsPointInBox(x, y, x1, y1, x2, y2) ) #define STRUCT ( (EDA_SchComponentStruct*) DrawList )
{ EDA_Rect BoundaryBox = STRUCT->GetBoundaryBox();
LastSnappedStruct = DrawList; if( BoundaryBox.Inside( x, y ) )
return TRUE; {
} LastSnappedStruct = DrawList;
break; return TRUE;
}
case DRAW_PICK_ITEM_STRUCT_TYPE : break; }
break;
default:
{ case DRAW_SHEET_STRUCT_TYPE:
wxString msg; #undef STRUCT
msg.Printf(wxT("SnapPoint2() error: unexpected strct type %d ("), DrawList->Type()); #define STRUCT ( (DrawSheetStruct*) DrawList )
msg << DrawList->ReturnClassName() << wxT(")"); if( !(SearchMask & SHEETITEM) )
DisplayError(NULL, msg); break;
break; /* Recalcul des coordonnees de l'encadrement du composant */
} x1 = STRUCT->m_Pos.x;
} y1 = STRUCT->m_Pos.y;
} x2 = STRUCT->m_Pos.x + STRUCT->m_Size.x;
return FALSE; y2 = STRUCT->m_Pos.y + STRUCT->m_Size.y;
if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
{
LastSnappedStruct = DrawList;
return TRUE;
}
break;
case DRAW_PICK_ITEM_STRUCT_TYPE:
break;
default:
{
wxString msg;
msg.Printf( wxT( "SnapPoint2() error: unexpected strct type %d (" ), DrawList->Type() );
msg << DrawList->ReturnClassName() << wxT( ")" );
DisplayError( NULL, msg );
break;
}
}
}
return FALSE;
} }
...@@ -456,646 +489,710 @@ int dx, dy; ...@@ -456,646 +489,710 @@ 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; }
case DRAW_SEGMENT_STRUCT_TYPE: break;
#undef STRUCT
#define STRUCT ((EDA_DrawLineStruct *) DrawStruct) case DRAW_SEGMENT_STRUCT_TYPE:
if( STRUCT->m_Start.x >= x1 && STRUCT->m_Start.x <= x2 && #undef STRUCT
STRUCT->m_Start.y >= y1 && STRUCT->m_Start.y <=y2) return TRUE; #define STRUCT ( (EDA_DrawLineStruct*) DrawStruct )
if( (STRUCT->m_End.x >= x1) && (STRUCT->m_End.x <= x2) && if( STRUCT->m_Start.x >= x1 && STRUCT->m_Start.x <= x2
(STRUCT->m_End.y >= y1) && (STRUCT->m_End.y <=y2) ) return TRUE; && STRUCT->m_Start.y >= y1 && STRUCT->m_Start.y <=y2 )
break; return TRUE;
if( (STRUCT->m_End.x >= x1) && (STRUCT->m_End.x <= x2)
case DRAW_BUSENTRY_STRUCT_TYPE: && (STRUCT->m_End.y >= y1) && (STRUCT->m_End.y <=y2) )
#undef STRUCT return TRUE;
#define STRUCT ((DrawBusEntryStruct *) DrawStruct) break;
if( STRUCT->m_Pos.x >= x1 && STRUCT->m_Pos.x <= x2 &&
STRUCT->m_Pos.y >= y1 && STRUCT->m_Pos.y <=y2) case DRAW_BUSENTRY_STRUCT_TYPE:
return TRUE; #undef STRUCT
if( (STRUCT->m_End().x >= x1) && ( STRUCT->m_End().x <= x2) && #define STRUCT ( (DrawBusEntryStruct*) DrawStruct )
( STRUCT->m_End().y >= y1) && ( STRUCT->m_End().y <=y2) ) if( STRUCT->m_Pos.x >= x1 && STRUCT->m_Pos.x <= x2
return TRUE; && STRUCT->m_Pos.y >= y1 && STRUCT->m_Pos.y <=y2 )
break; return TRUE;
if( (STRUCT->m_End().x >= x1) && ( STRUCT->m_End().x <= x2)
case DRAW_JUNCTION_STRUCT_TYPE: && ( STRUCT->m_End().y >= y1) && ( STRUCT->m_End().y <=y2) )
#undef STRUCT return TRUE;
#define STRUCT ((DrawJunctionStruct *) DrawStruct) break;
if( (STRUCT->m_Pos.x >= x1) && (STRUCT->m_Pos.x <= x2) &&
(STRUCT->m_Pos.y >= y1) && (STRUCT->m_Pos.y <= y2) ) case DRAW_JUNCTION_STRUCT_TYPE:
return TRUE; #undef STRUCT
break; #define STRUCT ( (DrawJunctionStruct*) DrawStruct )
if( (STRUCT->m_Pos.x >= x1) && (STRUCT->m_Pos.x <= x2)
&& (STRUCT->m_Pos.y >= y1) && (STRUCT->m_Pos.y <= y2) )
case DRAW_NOCONNECT_STRUCT_TYPE: return TRUE;
#undef STRUCT break;
#define STRUCT ((DrawNoConnectStruct *) DrawStruct)
if( (STRUCT->m_Pos.x >= x1) && (STRUCT->m_Pos.x <= x2) &&
(STRUCT->m_Pos.y >= y1) && (STRUCT->m_Pos.y <= y2) ) case DRAW_NOCONNECT_STRUCT_TYPE:
return TRUE; #undef STRUCT
break; #define STRUCT ( (DrawNoConnectStruct*) DrawStruct )
if( (STRUCT->m_Pos.x >= x1) && (STRUCT->m_Pos.x <= x2)
&& (STRUCT->m_Pos.y >= y1) && (STRUCT->m_Pos.y <= y2) )
case DRAW_MARKER_STRUCT_TYPE: return TRUE;
#undef STRUCT break;
#define STRUCT ((DrawMarkerStruct *) DrawStruct)
if( (STRUCT->m_Pos.x >= x1) && (STRUCT->m_Pos.x <= x2) &&
(STRUCT->m_Pos.y >= y1) && (STRUCT->m_Pos.y <= y2) ) case DRAW_MARKER_STRUCT_TYPE:
return TRUE; #undef STRUCT
break; #define STRUCT ( (DrawMarkerStruct*) DrawStruct )
if( (STRUCT->m_Pos.x >= x1) && (STRUCT->m_Pos.x <= x2)
case DRAW_LABEL_STRUCT_TYPE: && (STRUCT->m_Pos.y >= y1) && (STRUCT->m_Pos.y <= y2) )
case DRAW_TEXT_STRUCT_TYPE: return TRUE;
#undef STRUCT break;
#define STRUCT ((DrawTextStruct *) DrawStruct)
dx = STRUCT->m_Size.x * STRUCT->GetLength(); case DRAW_LABEL_STRUCT_TYPE:
dy = STRUCT->m_Size.y; case DRAW_TEXT_STRUCT_TYPE:
xt1 = xt2 = STRUCT->m_Pos.x; #undef STRUCT
yt1 = yt2 = STRUCT->m_Pos.y; #define STRUCT ( (DrawTextStruct*) DrawStruct )
switch( STRUCT->m_Orient) dx = STRUCT->m_Size.x * STRUCT->GetLength();
{ dy = STRUCT->m_Size.y;
case 0 : /* HORIZONTAL */ xt1 = xt2 = STRUCT->m_Pos.x;
xt2 += dx; yt2 -= dy; yt1 = yt2 = STRUCT->m_Pos.y;
break;
switch( STRUCT->m_Orient )
case 1 : /* VERTICAL UP */ {
xt2 -= dy; yt2 -= dx; case 0: /* HORIZONTAL */
break; xt2 += dx; yt2 -= dy;
break;
case 2 : /* horizontal inverse */
xt2 -= dx; yt2 += dy; case 1: /* VERTICAL UP */
break; xt2 -= dy; yt2 -= dx;
break;
case 3 : /* vertical DOWN */
xt2 += dy; yt2 += dx; case 2: /* horizontal inverse */
break; xt2 -= dx; yt2 += dy;
} break;
if( IsBox1InBox2(xt1,yt1, xt2, yt2, x1, y1, x2, y2) ) return TRUE;
break; case 3: /* vertical DOWN */
xt2 += dy; yt2 += dx;
case DRAW_GLOBAL_LABEL_STRUCT_TYPE: break;
#undef STRUCT }
#define STRUCT ((DrawGlobalLabelStruct *) DrawStruct)
dx = STRUCT->m_Size.x * ( STRUCT->GetLength() + 1); /* longueur totale */ if( IsBox1InBox2( xt1, yt1, xt2, yt2, x1, y1, x2, y2 ) )
dy = STRUCT->m_Size.y / 2; /* Demi hauteur */ return TRUE;
xt1 = xt2 = STRUCT->m_Pos.x; break;
yt1 = yt2 = STRUCT->m_Pos.y;
switch( STRUCT->m_Orient) case DRAW_GLOBAL_LABEL_STRUCT_TYPE:
{ #undef STRUCT
case 0 : /* HORIZONTAL */ #define STRUCT ( (DrawGlobalLabelStruct*) DrawStruct )
xt2 -= dx; yt2 += dy; yt1 -= dy; dx = STRUCT->m_Size.x * ( STRUCT->GetLength() + 1); /* longueur totale */
break; dy = STRUCT->m_Size.y / 2; /* Demi hauteur */
xt1 = xt2 = STRUCT->m_Pos.x;
case 1 : /* VERTICAL UP */ yt1 = yt2 = STRUCT->m_Pos.y;
xt1 -= dy; xt2 += dy; yt2 += dx;
break; switch( STRUCT->m_Orient )
{
case 2 : /* horizontal inverse */ case 0: /* HORIZONTAL */
xt2 += dx; yt2 += dy; yt1 -= dy; xt2 -= dx; yt2 += dy; yt1 -= dy;
break; break;
case 3 : /* vertical DOWN */ case 1: /* VERTICAL UP */
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; case 2: /* horizontal inverse */
break; xt2 += dx; yt2 += dy; yt1 -= dy;
break;
case DRAW_LIB_ITEM_STRUCT_TYPE:
{ case 3: /* vertical DOWN */
#undef STRUCT xt1 -= dy; xt2 += dy; yt2 -= dx;
#define STRUCT ((EDA_SchComponentStruct *) DrawStruct) break;
EDA_Rect BoundaryBox = STRUCT->GetBoundaryBox(); }
xt1 = BoundaryBox.GetX();
yt1 = BoundaryBox.GetY(); if( IsBox1InBox2( xt1, yt1, xt2, yt2, x1, y1, x2, y2 ) )
xt2 = BoundaryBox.GetRight(); return TRUE;
yt2 = BoundaryBox.GetBottom(); break;
if( IsBox1InBox2(xt1,yt1, xt2, yt2, x1, y1, x2, y2) ) return TRUE;
break; case DRAW_LIB_ITEM_STRUCT_TYPE:
} {
#undef STRUCT
case DRAW_SHEET_STRUCT_TYPE : #define STRUCT ( (EDA_SchComponentStruct*) DrawStruct )
#undef STRUCT EDA_Rect BoundaryBox = STRUCT->GetBoundaryBox();
#define STRUCT ((DrawSheetStruct *) DrawStruct) xt1 = BoundaryBox.GetX();
/* Recalcul des coordonnees de l'encadrement du composant */ yt1 = BoundaryBox.GetY();
xt1 = STRUCT->m_Pos.x; xt2 = BoundaryBox.GetRight();
yt1 = STRUCT->m_Pos.y; yt2 = BoundaryBox.GetBottom();
xt2 = STRUCT->m_Pos.x + STRUCT->m_Size.x; if( IsBox1InBox2( xt1, yt1, xt2, yt2, x1, y1, x2, y2 ) )
yt2 = STRUCT->m_Pos.y + STRUCT->m_Size.y; return TRUE;
break;
if( IsBox1InBox2(xt1,yt1, xt2, yt2, x1, y1, x2, y2) ) }
return TRUE;
break; case DRAW_SHEET_STRUCT_TYPE:
#undef STRUCT
case DRAW_SHEETLABEL_STRUCT_TYPE : break; #define STRUCT ( (DrawSheetStruct*) DrawStruct )
case DRAW_PICK_ITEM_STRUCT_TYPE : break; /* Recalcul des coordonnees de l'encadrement du composant */
xt1 = STRUCT->m_Pos.x;
default: yt1 = STRUCT->m_Pos.y;
msg.Printf( xt2 = STRUCT->m_Pos.x + STRUCT->m_Size.x;
wxT("DrawStructInBox() Err: unexpected StructType %d ("), yt2 = STRUCT->m_Pos.y + STRUCT->m_Size.y;
DrawStruct->Type() );
msg << DrawStruct->ReturnClassName() << wxT(")"); if( IsBox1InBox2( xt1, yt1, xt2, yt2, x1, y1, x2, y2 ) )
DisplayError(NULL, msg ); return TRUE;
break; break;
}
case DRAW_SHEETLABEL_STRUCT_TYPE:
return FALSE; break;
case DRAW_PICK_ITEM_STRUCT_TYPE:
break;
default:
msg.Printf(
wxT( "DrawStructInBox() Err: unexpected StructType %d (" ),
DrawStruct->Type() );
msg << DrawStruct->ReturnClassName() << wxT( ")" );
DisplayError( NULL, msg );
break;
}
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;
} }
/**********************************************************************/ /**********************************************************************/
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;
} }
/********************************************************************************/ /********************************************************************************/
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")); {
return(NULL); DisplayError( NULL, wxT( "Error in LocateDrawItem: Entry is ALIAS" ) );
} return NULL;
}
DrawItem = LibEntry->m_Drawings;
DrawItem = LibEntry->m_Drawings;
seuil = 3; /* Tolerance: 1/2 pas de petite grille */
px = refpoint.x; seuil = 3; /* Tolerance: 1/2 pas de petite grille */
py = refpoint.y; px = refpoint.x;
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(Convert && DrawItem->m_Convert && (Convert != DrawItem->m_Convert) ) if( Unit && DrawItem->m_Unit && (Unit != DrawItem->m_Unit) )
continue; continue;
if( Convert && DrawItem->m_Convert && (Convert != DrawItem->m_Convert) )
switch ( DrawItem->Type() ) continue;
{
case COMPONENT_ARC_DRAW_TYPE: switch( DrawItem->Type() )
{ {
LibDrawArc * Arc = (LibDrawArc *) DrawItem; case COMPONENT_ARC_DRAW_TYPE:
if( (masque & LOCATE_COMPONENT_ARC_DRAW_TYPE) == 0) break; {
dx = px - Arc->m_Pos.x; LibDrawArc* Arc = (LibDrawArc*) DrawItem;
dy = py + Arc->m_Pos.y; if( (masque & LOCATE_COMPONENT_ARC_DRAW_TYPE) == 0 )
ii = (int)sqrt( dx*dx + dy*dy); break;
if ( abs(ii - Arc->m_Rayon) <= seuil) return( DrawItem); dx = px - Arc->m_Pos.x;
} dy = py + Arc->m_Pos.y;
break; ii = (int) sqrt( dx * dx + dy * dy );
if( abs( ii - Arc->m_Rayon ) <= seuil )
case COMPONENT_CIRCLE_DRAW_TYPE: return DrawItem;
{ }
LibDrawCircle * Circle = (LibDrawCircle *) DrawItem; break;
if( (masque & LOCATE_COMPONENT_CIRCLE_DRAW_TYPE) == 0) break;
dx = px - Circle->m_Pos.x; case COMPONENT_CIRCLE_DRAW_TYPE:
dy = py + Circle->m_Pos.y; {
ii = (int)sqrt( dx*dx + dy*dy); LibDrawCircle* Circle = (LibDrawCircle*) DrawItem;
if ( abs(ii - Circle->m_Rayon) <= seuil) return( DrawItem); if( (masque & LOCATE_COMPONENT_CIRCLE_DRAW_TYPE) == 0 )
} break;
break; dx = px - Circle->m_Pos.x;
dy = py + Circle->m_Pos.y;
case COMPONENT_RECT_DRAW_TYPE: ii = (int) sqrt( dx * dx + dy * dy );
{ // Locate a rect if the mouse cursor is on a segment if( abs( ii - Circle->m_Rayon ) <= seuil )
LibDrawSquare * Square = (LibDrawSquare *) DrawItem; return DrawItem;
if( (masque & LOCATE_COMPONENT_RECT_DRAW_TYPE) == 0) break; }
if(IsPointOnSegment(px,py, // locate lower segment break;
Square->m_Pos.x, - Square->m_Pos.y,
Square->m_End.x, - Square->m_Pos.y, seuil) ) case COMPONENT_RECT_DRAW_TYPE:
return(DrawItem); { // Locate a rect if the mouse cursor is on a segment
if(IsPointOnSegment(px, py, // locate right segment LibDrawSquare* Square = (LibDrawSquare*) DrawItem;
Square->m_End.x, - Square->m_Pos.y, if( (masque & LOCATE_COMPONENT_RECT_DRAW_TYPE) == 0 )
Square->m_End.x, - Square->m_End.y, seuil) ) break;
return(DrawItem); if( IsPointOnSegment( px, py, // locate lower segment
if(IsPointOnSegment(px, py, // locate upper segment Square->m_Pos.x, -Square->m_Pos.y,
Square->m_End.x, - Square->m_End.y, Square->m_End.x, -Square->m_Pos.y, seuil ) )
Square->m_Pos.x, - Square->m_End.y, seuil) ) return DrawItem;
return(DrawItem); if( IsPointOnSegment( px, py, // locate right segment
if(IsPointOnSegment(px, py, // locate left segment Square->m_End.x, -Square->m_Pos.y,
Square->m_Pos.x, - Square->m_End.y, Square->m_End.x, -Square->m_End.y, seuil ) )
Square->m_Pos.x, - Square->m_Pos.y, seuil) ) return DrawItem;
return(DrawItem); if( IsPointOnSegment( px, py, // locate upper segment
} Square->m_End.x, -Square->m_End.y,
break; Square->m_Pos.x, -Square->m_End.y, seuil ) )
return DrawItem;
case COMPONENT_POLYLINE_DRAW_TYPE: if( IsPointOnSegment( px, py, // locate left segment
{ Square->m_Pos.x, -Square->m_End.y,
LibDrawPolyline * polyline = (LibDrawPolyline *) DrawItem; Square->m_Pos.x, -Square->m_Pos.y, seuil ) )
if( (masque & LOCATE_COMPONENT_POLYLINE_DRAW_TYPE) == 0) break; return DrawItem;
ptpoly = polyline->PolyList; }
for( ii = polyline->n-1; ii > 0; ii--, ptpoly += 2) break;
{
if(IsPointOnSegment(px, py, case COMPONENT_POLYLINE_DRAW_TYPE:
ptpoly[0], - ptpoly[1], ptpoly[2], - ptpoly[3], seuil) ) {
return(DrawItem); LibDrawPolyline* polyline = (LibDrawPolyline*) DrawItem;
} if( (masque & LOCATE_COMPONENT_POLYLINE_DRAW_TYPE) == 0 )
} break;
break; ptpoly = polyline->PolyList;
for( ii = polyline->n - 1; ii > 0; ii--, ptpoly += 2 )
case COMPONENT_LINE_DRAW_TYPE: {
{ if( IsPointOnSegment( px, py,
LibDrawSegment * Segment = (LibDrawSegment *) DrawItem; ptpoly[0], -ptpoly[1], ptpoly[2], -ptpoly[3], seuil ) )
if( (masque & LOCATE_COMPONENT_LINE_DRAW_TYPE) == 0) break; return DrawItem;
if(IsPointOnSegment(px, py, }
Segment->m_Pos.x, - Segment->m_Pos.y, }
Segment->m_End.x, - Segment->m_End.y, seuil) ) break;
return(DrawItem);
} case COMPONENT_LINE_DRAW_TYPE:
break; {
LibDrawSegment* Segment = (LibDrawSegment*) DrawItem;
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE: if( (masque & LOCATE_COMPONENT_LINE_DRAW_TYPE) == 0 )
{ break;
LibDrawText * Text = (LibDrawText *) DrawItem; if( IsPointOnSegment( px, py,
if( (masque & LOCATE_COMPONENT_GRAPHIC_TEXT_DRAW_TYPE) == 0) break; Segment->m_Pos.x, -Segment->m_Pos.y,
ii = Text->m_Text.Len(); if ( ii < 2 ) ii = 2; Segment->m_End.x, -Segment->m_End.y, seuil ) )
dx = (Text->m_Size.x * ii) / 2; return DrawItem;
dy = Text->m_Size.y / 2; }
if(Text->m_Horiz == TEXT_ORIENT_VERT) break;
{
EXCHG(dx,dy); case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
} {
x = px - Text->m_Pos.x; LibDrawText* Text = (LibDrawText*) DrawItem;
y = py + Text->m_Pos.y; if( (masque & LOCATE_COMPONENT_GRAPHIC_TEXT_DRAW_TYPE) == 0 )
if( (abs(x) <= dx) && (abs(y) <= dy) ) break;
return(DrawItem); /* Texte trouve */ ii = Text->m_Text.Len(); if( ii < 2 )
} ii = 2;
break; dx = (Text->m_Size.x * ii) / 2;
dy = Text->m_Size.y / 2;
default: if( Text->m_Horiz == TEXT_ORIENT_VERT )
; {
} EXCHG( dx, dy );
} }
return(NULL); x = px - Text->m_Pos.x;
y = py + Text->m_Pos.y;
if( (abs( x ) <= dx) && (abs( y ) <= dy) )
return DrawItem; /* Texte trouve */
}
break;
default:
;
}
}
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) )
/* Etude des extremites : cercle de rayon seuil */ return 1;
if( (pointX < 0) && (pointX >= -seuil) ) /* Etude des extremites : cercle de rayon seuil */
{ if( (pointX < 0) && (pointX >= -seuil) )
if( ((pointX * pointX) + (pointY*pointY)) <= (seuil*seuil) ) {
return(1); if( ( (pointX * pointX) + (pointY * pointY) ) <= (seuil * seuil) )
} return 1;
if( (pointX > segX) && (pointX <= (segX+seuil)) ) }
{ if( (pointX > segX) && ( pointX <= (segX + seuil) ) )
if( (((pointX-segX) * (pointX-segX)) + (pointY*pointY)) <= (seuil*seuil) ) {
return(1); if( ( ( (pointX - segX) * (pointX - segX) ) + (pointY * pointY) ) <=
} (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 >= -seuil) ) if( (pointY >= 0 ) && (pointY <= segY) )
{ return 1;
if( ((pointY * pointY) + (pointX*pointX)) <= (seuil*seuil) ) if( (pointY < 0) && (pointY >= -seuil) )
return(1); {
} if( ( (pointY * pointY) + (pointX * pointX) ) <= (seuil * seuil) )
if( (pointY > segY) && (pointY <= (segY+seuil)) ) return 1;
{ }
if( ( ((pointY-segY) * (pointY-segY)) + (pointX*pointX)) <= (seuil*seuil) ) if( (pointY > segY) && ( pointY <= (segY + seuil) ) )
return(1); {
} if( ( ( (pointY - segY) * (pointY - segY) ) + (pointX * pointX) ) <=
} (seuil * seuil) )
} return 1;
}
else /* orientation quelconque */ }
{ }
/* On fait un changement d'axe (rotation) de facon a ce que le segment else /* orientation quelconque */
de piste soit horizontal dans le nouveau repere */ {
int angle; /* On fait un changement d'axe (rotation) de facon a ce que le segment
* de piste soit horizontal dans le nouveau repere */
angle = (int)( atan2((float)segY, (float)segX) * 1800 / M_PI) ; int angle;
cXrot = pointX; cYrot = pointY;
RotatePoint(&cXrot, &cYrot, angle); /* Rotation du point a tester */ angle = (int) ( atan2( (float) segY, (float) segX ) * 1800 / M_PI);
RotatePoint(&segX, &segY, angle) ; /* Rotation du segment */ cXrot = pointX; cYrot = pointY;
RotatePoint( &cXrot, &cYrot, angle ); /* Rotation du point a tester */
/*la piste est Horizontale , par suite des modifs de coordonnes RotatePoint( &segX, &segY, angle ); /* Rotation du segment */
et d'axe, donc segX = longueur du segment */
/*la piste est Horizontale , par suite des modifs de coordonnes
if ( abs(cYrot) <= seuil ) /* ok sur axe vertical) */ * et d'axe, donc segX = longueur du segment */
{
if ((cXrot >= 0) && (cXrot <= segX) ) return(1) ; if( abs( cYrot ) <= seuil ) /* ok sur axe vertical) */
/* Etude des extremites : cercle de rayon seuil */ {
if( (cXrot < 0) && (cXrot >= -seuil) ) if( (cXrot >= 0) && (cXrot <= segX) )
{ return 1;
if( ((cXrot * cXrot) + (cYrot*cYrot)) <= (seuil*seuil) ) /* Etude des extremites : cercle de rayon seuil */
return(1); if( (cXrot < 0) && (cXrot >= -seuil) )
} {
if( (cXrot > segX) && (cXrot <= (segX+seuil)) ) if( ( (cXrot * cXrot) + (cYrot * cYrot) ) <= (seuil * seuil) )
{ return 1;
if( (((cXrot-segX) * (cXrot-segX)) + (cYrot*cYrot)) <= (seuil*seuil) ) }
return(1); if( (cXrot > segX) && ( cXrot <= (segX + seuil) ) )
} {
} if( ( ( (cXrot - segX) * (cXrot - segX) ) + (cYrot * cYrot) ) <= (seuil * seuil) )
} 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")); {
return(NULL); DisplayError( NULL, wxT( "LocatePin() error: Entry is ALIAS" ) );
} return NULL;
}
DrawItem = Entry->m_Drawings;
for ( ; DrawItem != NULL; DrawItem = DrawItem->Next()) DrawItem = Entry->m_Drawings;
{ 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) )
continue; if( Unit && DrawItem->m_Unit && (DrawItem->m_Unit != Unit) )
continue;
if( convert && DrawItem->m_Convert && (DrawItem->m_Convert != convert) )
continue; if( convert && DrawItem->m_Convert && (DrawItem->m_Convert != convert) )
continue;
x2 = Pin->m_Pos.x;
y2 = Pin->m_Pos.y; x2 = Pin->m_Pos.x;
x1 = Pin->ReturnPinEndPoint().x; y2 = Pin->m_Pos.y;
y1 = Pin->ReturnPinEndPoint().y; x1 = Pin->ReturnPinEndPoint().x;
y1 = Pin->ReturnPinEndPoint().y;
if(DrawLibItem == NULL )
{ if( DrawLibItem == NULL )
y1 = -y1; y2 = -y2; {
} y1 = -y1; y2 = -y2;
else }
{ else
int x = x1, y = y1; {
x1 = DrawLibItem->m_Pos.x + DrawLibItem->m_Transform[0][0] * x int x = x1, y = y1;
+ DrawLibItem->m_Transform[0][1] * y; x1 = DrawLibItem->m_Pos.x + DrawLibItem->m_Transform[0][0] * x
y1 = DrawLibItem->m_Pos.y + DrawLibItem->m_Transform[1][0] * x + DrawLibItem->m_Transform[0][1] * y;
+ DrawLibItem->m_Transform[1][1] * y; y1 = DrawLibItem->m_Pos.y + DrawLibItem->m_Transform[1][0] * x
x = x2; y = y2; + DrawLibItem->m_Transform[1][1] * y;
x2 = DrawLibItem->m_Pos.x + DrawLibItem->m_Transform[0][0] * x x = x2; y = y2;
+ DrawLibItem->m_Transform[0][1] * y; x2 = DrawLibItem->m_Pos.x + DrawLibItem->m_Transform[0][0] * x
y2 = DrawLibItem->m_Pos.y + DrawLibItem->m_Transform[1][0] * x + DrawLibItem->m_Transform[0][1] * y;
+ DrawLibItem->m_Transform[1][1] * y; y2 = DrawLibItem->m_Pos.y + DrawLibItem->m_Transform[1][0] * x
} + DrawLibItem->m_Transform[1][1] * y;
}
if (x1 > x2 ) EXCHG(x1,x2); if (y1 > y2 ) EXCHG(y1,y2);
if( x1 > x2 )
if( (RefPos.x >= x1) && (RefPos.x <= x2) && EXCHG( x1, x2 );if( y1 > y2 )
(RefPos.y >= y1) && (RefPos.y <= y2) ) EXCHG( y1, y2 );
return(DrawItem);
} if( (RefPos.x >= x1) && (RefPos.x <= x2)
} && (RefPos.y >= y1) && (RefPos.y <= y2) )
return(NULL); return DrawItem;
}
}
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 )
minx = SheetLabel->m_Pos.x; maxx = SheetLabel->m_Pos.x + size; size = -size;
if( maxx < minx ) EXCHG(maxx,minx); minx = SheetLabel->m_Pos.x; maxx = SheetLabel->m_Pos.x + size;
dy = SheetLabel->m_Size.x / 2; if( maxx < minx )
if( (ABS(pos.y - SheetLabel->m_Pos.y) <= dy ) && EXCHG( maxx, minx );
(pos.x <= maxx) && dy = SheetLabel->m_Size.x / 2;
(pos.x >= minx) ) if( (ABS( pos.y - SheetLabel->m_Pos.y ) <= dy )
return(SheetLabel); && (pos.x <= maxx)
SheetLabel = (DrawSheetLabelStruct *) SheetLabel->Pnext; && (pos.x >= minx) )
} return SheetLabel;
return(NULL); SheetLabel = (DrawSheetLabelStruct*) SheetLabel->Pnext;
}
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;
return Pin; }
if( libpart )
*libpart = LibItem;
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