Commit 99408024 authored by charras's avatar charras

Code cleaning. Some bugs fixed. Added contributors to list in About Kicad.

parent 5813a12e
...@@ -9,7 +9,10 @@ email address. ...@@ -9,7 +9,10 @@ email address.
================================================================================ ================================================================================
++All: ++All:
Print functions and display zoom level modified to use the new zoom implementation Print functions and display zoom level modified to use the new zoom implementation
Comments adde in some functions. Comments added in some functions.
Code cleaning
some bugs fixed.
Added contributors to list in about Kicad.
2009-Jan-29 UPDATE Wayne Stambaugh <stambaughw@verizon.net> 2009-Jan-29 UPDATE Wayne Stambaugh <stambaughw@verizon.net>
================================================================================ ================================================================================
......
...@@ -110,9 +110,11 @@ InitKiCadAbout( wxAboutDialogInfo& info ) ...@@ -110,9 +110,11 @@ InitKiCadAbout( wxAboutDialogInfo& info )
/* Add developers */ /* Add developers */
info.AddDeveloper( wxT( "Jean-Pierre Charras <jean-pierre.charras@inpg.fr>" ) ); info.AddDeveloper( wxT( "Jean-Pierre Charras <jean-pierre.charras@inpg.fr>" ) );
info.AddDeveloper( SetMsg( wxT( "Jerry Jacobs <jerkejacobs@gmail.com>" ) ) );
info.AddDeveloper( SetMsg( wxT( "Dick Hollenbeck <dick@softplc.com>" ) ) ); info.AddDeveloper( SetMsg( wxT( "Dick Hollenbeck <dick@softplc.com>" ) ) );
info.AddDeveloper( SetMsg( wxT( "Jerry Jacobs <jerkejacobs@gmail.com>" ) ) );
info.AddDeveloper( SetMsg( wxT( "Jonas Diemer <diemer@gmx.de>" ) ) );
info.AddDeveloper( SetMsg( wxT( "KBool Library <http://boolean.klaasholwerda.nl/bool.html>" ) ) ); info.AddDeveloper( SetMsg( wxT( "KBool Library <http://boolean.klaasholwerda.nl/bool.html>" ) ) );
info.AddDeveloper( SetMsg( wxT( "Rok Markovic <rok@kanardia.eu>" ) ) );
info.AddDeveloper( SetMsg( wxT( "Vesa Solonen <vesa.solonen@hut.fi>" ) ) ); info.AddDeveloper( SetMsg( wxT( "Vesa Solonen <vesa.solonen@hut.fi>" ) ) );
info.AddDeveloper( SetMsg( wxT( "Wayne Stambaugh <stambaughw@verizon.net>" ) ) ); info.AddDeveloper( SetMsg( wxT( "Wayne Stambaugh <stambaughw@verizon.net>" ) ) );
......
...@@ -209,18 +209,17 @@ bool EDA_TextStruct::HitTest( const wxPoint& posref ) ...@@ -209,18 +209,17 @@ bool EDA_TextStruct::HitTest( const wxPoint& posref )
*/ */
{ {
int dx, dy; int dx, dy;
int spot_cX, spot_cY; wxPoint location;
dx = (int) (( Pitch() * GetLength() ) / 2); dx = (int) (( Pitch() * GetLength() ) / 2);
dy = m_Size.y / 2; dy = m_Size.y / 2;
/* Is the ref point inside the text area ? */ /* Is the ref point inside the text area ? */
spot_cX = posref.x - m_Pos.x; location = posref - m_Pos;
spot_cY = posref.y - m_Pos.y;
RotatePoint( &spot_cX, &spot_cY, -m_Orient ); RotatePoint( &location, -m_Orient );
if( ( abs( spot_cX ) <= abs( dx ) ) && ( abs( spot_cY ) <= abs( dy ) ) ) if( ( abs( location.x ) <= abs( dx ) ) && ( abs( location.y ) <= abs( dy ) ) )
return true; return true;
return false; return false;
......
...@@ -374,6 +374,18 @@ EDA_Rect DrawSheetStruct::GetBoundingBox() ...@@ -374,6 +374,18 @@ EDA_Rect DrawSheetStruct::GetBoundingBox()
return box; return box;
} }
/************************************************/
bool DrawSheetStruct::HitTest( const wxPoint& aPosRef )
/************************************************/
/** Function HitTest
* @return true if the point aPosRef is within item area
* @param aPosRef = a wxPoint to test
*/
{
EDA_Rect rect = GetBoundingBox();
return rect.Inside( aPosRef );
}
/************************************/ /************************************/
int DrawSheetStruct::ComponentCount() int DrawSheetStruct::ComponentCount()
......
...@@ -129,10 +129,17 @@ public: ...@@ -129,10 +129,17 @@ public:
void Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, void Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset,
int aDrawMode, int aColor = -1 ); int aDrawMode, int aColor = -1 );
/** Function HitTest
* @return true if the point aPosRef is within item area
* @param aPosRef = a wxPoint to test
*/
bool HitTest( const wxPoint& aPosRef );
/** Function GetBoundingBox /** Function GetBoundingBox
* @return an EDA_Rect giving the bouding box of the sheet * @return an EDA_Rect giving the bouding box of the sheet
*/ */
EDA_Rect GetBoundingBox(); EDA_Rect GetBoundingBox();
void SwapData( DrawSheetStruct* copyitem ); void SwapData( DrawSheetStruct* copyitem );
/** Function ComponentCount /** Function ComponentCount
......
...@@ -249,8 +249,8 @@ EDA_Rect EDA_LibComponentStruct::GetBoundaryBox( int Unit, int Convert ) ...@@ -249,8 +249,8 @@ EDA_Rect EDA_LibComponentStruct::GetBoundaryBox( int Unit, int Convert )
} }
// Update the BoundaryBox. Remember the fact the screen Y axis is the reverse */ // Update the BoundaryBox. Remember the fact the screen Y axis is the reverse */
NEGATE(ymax); NEGATE(ymin); // Y is not is screen axis sense NEGATE(ymax); NEGATE(ymin); // y coordinates are screen oriented
// Ensure H > 0 (wxRect assume it) // Ensure H > 0
if( ymax < ymin ) if( ymax < ymin )
EXCHG( ymax, ymin ); EXCHG( ymax, ymin );
BoundaryBox.SetX( xmin ); BoundaryBox.SetWidth( xmax - xmin ); BoundaryBox.SetX( xmin ); BoundaryBox.SetWidth( xmax - xmin );
......
...@@ -40,9 +40,9 @@ DrawBusEntryStruct::DrawBusEntryStruct( const wxPoint& pos, int shape, int id ) ...@@ -40,9 +40,9 @@ DrawBusEntryStruct::DrawBusEntryStruct( const wxPoint& pos, int shape, int id )
} }
/*************************************/ /****************************************/
wxPoint DrawBusEntryStruct::m_End() const wxPoint DrawBusEntryStruct::m_End() const
/*************************************/ /****************************************/
// retourne la coord de fin du raccord // retourne la coord de fin du raccord
{ {
...@@ -98,6 +98,21 @@ bool DrawBusEntryStruct::Save( FILE* aFile ) const ...@@ -98,6 +98,21 @@ bool DrawBusEntryStruct::Save( FILE* aFile ) const
} }
/*********************************************/
EDA_Rect DrawBusEntryStruct::GetBoundingBox()
/*********************************************/
{
int dx = m_Pos.x - m_End().x;
int dy = m_Pos.y - m_End().y;
EDA_Rect box( wxPoint( m_Pos.x, m_Pos.y ), wxSize( dx, dy ) );
box.Normalize();
int width = MAX( m_Width, g_DrawMinimunLineWidth );
box.Inflate(width/2, width/2);
return box;
}
/****************************/ /****************************/
/* class DrawJunctionStruct */ /* class DrawJunctionStruct */
/***************************/ /***************************/
...@@ -143,6 +158,7 @@ bool DrawJunctionStruct::Save( FILE* aFile ) const ...@@ -143,6 +158,7 @@ bool DrawJunctionStruct::Save( FILE* aFile ) const
EDA_Rect DrawJunctionStruct::GetBoundingBox() EDA_Rect DrawJunctionStruct::GetBoundingBox()
// return a bounding box
{ {
int width = DRAWJUNCTION_SIZE * 2; int width = DRAWJUNCTION_SIZE * 2;
int xmin = m_Pos.x - DRAWJUNCTION_SIZE; int xmin = m_Pos.x - DRAWJUNCTION_SIZE;
...@@ -153,6 +169,21 @@ EDA_Rect DrawJunctionStruct::GetBoundingBox() ...@@ -153,6 +169,21 @@ EDA_Rect DrawJunctionStruct::GetBoundingBox()
return ret; return ret;
}; };
/*********************************************************/
bool DrawJunctionStruct::HitTest( const wxPoint& aPosRef )
/*********************************************************/
/** Function HitTest
* @return true if the point aPosRef is within item area
* @param aPosRef = a wxPoint to test
*/
{
wxPoint dist = aPosRef - m_Pos;
if( sqrt( ((double) dist.x * dist.x) + ((double) dist.y * dist.y) ) < DRAWJUNCTION_SIZE )
return true;
return false;
}
#if defined(DEBUG) #if defined(DEBUG)
void DrawJunctionStruct::Show( int nestLevel, std::ostream& os ) void DrawJunctionStruct::Show( int nestLevel, std::ostream& os )
...@@ -188,6 +219,35 @@ DrawNoConnectStruct* DrawNoConnectStruct::GenCopy() ...@@ -188,6 +219,35 @@ DrawNoConnectStruct* DrawNoConnectStruct::GenCopy()
return newitem; return newitem;
} }
/*********************************************/
EDA_Rect DrawNoConnectStruct::GetBoundingBox()
/*********************************************/
{
const int DELTA = DRAWNOCONNECT_SIZE / 2;
EDA_Rect box( wxPoint( m_Pos.x - DELTA, m_Pos.y - DELTA ), wxSize( 2 * DELTA, 2 * DELTA ) );
box.Normalize();
return box;
}
/*********************************************************/
bool DrawNoConnectStruct::HitTest( const wxPoint& aPosRef )
/*********************************************************/
/** Function HitTest
* @return true if the point aPosRef is within item area
* @param aPosRef = a wxPoint to test
*/
{
int width = g_DrawMinimunLineWidth;
int delta = ( DRAWNOCONNECT_SIZE + width) / 2;
wxPoint dist = aPosRef - m_Pos;
if( (ABS(dist.x) <= delta) && (ABS(dist.y) <= delta) )
return true;
return false;
}
/** /**
* Function Save * Function Save
......
...@@ -162,6 +162,12 @@ public: ...@@ -162,6 +162,12 @@ public:
*/ */
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
/** Function HitTest
* @return true if the point aPosRef is within item area
* @param aPosRef = a wxPoint to test
*/
bool HitTest( const wxPoint& aPosRef );
EDA_Rect GetBoundingBox(); EDA_Rect GetBoundingBox();
}; };
...@@ -261,6 +267,12 @@ public: ...@@ -261,6 +267,12 @@ public:
} }
/** Function HitTest
* @return true if the point aPosRef is within item area
* @param aPosRef = a wxPoint to test
*/
bool HitTest( const wxPoint& aPosRef );
EDA_Rect GetBoundingBox(); EDA_Rect GetBoundingBox();
DrawJunctionStruct* GenCopy(); DrawJunctionStruct* GenCopy();
......
...@@ -35,6 +35,16 @@ SCH_TEXT::SCH_TEXT( const wxPoint& pos, const wxString& text, KICAD_T aType ) : ...@@ -35,6 +35,16 @@ SCH_TEXT::SCH_TEXT( const wxPoint& pos, const wxString& text, KICAD_T aType ) :
m_IsDangling = FALSE; m_IsDangling = FALSE;
} }
/** Function HitTest
* @return true if the point aPosRef is within item area
* @param aPosRef = a wxPoint to test
*/
bool SCH_TEXT::HitTest( const wxPoint& aPosRef )
{
EDA_Rect rect = GetBoundingBox();
return rect.Inside( aPosRef );
}
/*********************************************/ /*********************************************/
SCH_TEXT* SCH_TEXT::GenCopy() SCH_TEXT* SCH_TEXT::GenCopy()
...@@ -290,6 +300,19 @@ bool SCH_GLOBALLABEL::Save( FILE* aFile ) const ...@@ -290,6 +300,19 @@ bool SCH_GLOBALLABEL::Save( FILE* aFile ) const
return success; return success;
} }
/************************************************/
bool SCH_GLOBALLABEL::HitTest( const wxPoint& aPosRef )
/************************************************/
/** Function HitTest
* @return true if the point aPosRef is within item area
* @param aPosRef = a wxPoint to test
*/
{
EDA_Rect rect = GetBoundingBox();
return rect.Inside( aPosRef );
}
/***********************************************************************************/ /***********************************************************************************/
SCH_HIERLABEL::SCH_HIERLABEL( const wxPoint& pos, const wxString& text ) : SCH_HIERLABEL::SCH_HIERLABEL( const wxPoint& pos, const wxString& text ) :
...@@ -327,6 +350,18 @@ bool SCH_HIERLABEL::Save( FILE* aFile ) const ...@@ -327,6 +350,18 @@ bool SCH_HIERLABEL::Save( FILE* aFile ) const
return success; return success;
} }
/************************************************/
bool SCH_HIERLABEL::HitTest( const wxPoint& aPosRef )
/************************************************/
/** Function HitTest
* @return true if the point aPosRef is within item area
* @param aPosRef = a wxPoint to test
*/
{
EDA_Rect rect = GetBoundingBox();
return rect.Inside( aPosRef );
}
/*********************************************************************************************/ /*********************************************************************************************/
void SCH_LABEL::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, void SCH_LABEL::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
...@@ -426,7 +461,9 @@ void SCH_HIERLABEL::CreateGraphicShape( int* corner_list, const wxPoint& Pos ) ...@@ -426,7 +461,9 @@ void SCH_HIERLABEL::CreateGraphicShape( int* corner_list, const wxPoint& Pos )
} }
} }
/****************************************/
EDA_Rect SCH_HIERLABEL::GetBoundingBox() EDA_Rect SCH_HIERLABEL::GetBoundingBox()
/****************************************/
{ {
int x, y, dx, dy, length, height; int x, y, dx, dy, length, height;
...@@ -639,7 +676,9 @@ void SCH_GLOBALLABEL::CreateGraphicShape( int* corner_list, const wxPoint& Pos ) ...@@ -639,7 +676,9 @@ void SCH_GLOBALLABEL::CreateGraphicShape( int* corner_list, const wxPoint& Pos )
} }
/******************************************/
EDA_Rect SCH_GLOBALLABEL::GetBoundingBox() EDA_Rect SCH_GLOBALLABEL::GetBoundingBox()
/******************************************/
{ {
int x, y, dx, dy, length, height; int x, y, dx, dy, length, height;
...@@ -688,7 +727,9 @@ EDA_Rect SCH_GLOBALLABEL::GetBoundingBox() ...@@ -688,7 +727,9 @@ EDA_Rect SCH_GLOBALLABEL::GetBoundingBox()
} }
/***********************************/
EDA_Rect SCH_TEXT::GetBoundingBox() EDA_Rect SCH_TEXT::GetBoundingBox()
/***********************************/
{ {
int x, y, dx, dy, length, height; int x, y, dx, dy, length, height;
......
...@@ -102,6 +102,13 @@ public: ...@@ -102,6 +102,13 @@ public:
void SwapData( SCH_TEXT* copyitem ); void SwapData( SCH_TEXT* copyitem );
void Place( WinEDA_SchematicFrame* frame, wxDC* DC ); void Place( WinEDA_SchematicFrame* frame, wxDC* DC );
/** Function HitTest
* @return true if the point aPosRef is within item area
* @param aPosRef = a wxPoint to test
*/
bool HitTest( const wxPoint& aPosRef );
EDA_Rect GetBoundingBox(); EDA_Rect GetBoundingBox();
/** /**
...@@ -175,6 +182,12 @@ public: ...@@ -175,6 +182,12 @@ public:
*/ */
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
/** Function HitTest
* @return true if the point aPosRef is within item area
* @param aPosRef = a wxPoint to test
*/
bool HitTest( const wxPoint& aPosRef );
EDA_Rect GetBoundingBox(); EDA_Rect GetBoundingBox();
}; };
...@@ -212,6 +225,12 @@ public: ...@@ -212,6 +225,12 @@ public:
*/ */
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
/** Function HitTest
* @return true if the point aPosRef is within item area
* @param aPosRef = a wxPoint to test
*/
bool HitTest( const wxPoint& aPosRef );
EDA_Rect GetBoundingBox(); EDA_Rect GetBoundingBox();
}; };
......
...@@ -557,10 +557,10 @@ bool LibDrawPolyline::HitTest( wxPoint aPosRef, int aThreshold, const int aTrans ...@@ -557,10 +557,10 @@ bool LibDrawPolyline::HitTest( wxPoint aPosRef, int aThreshold, const int aTrans
{ {
wxPoint ref, start, end; wxPoint ref, start, end;
for( unsigned ii = 0; ii < m_PolyPoints.size() - 1; ii++ ) for( unsigned ii = 1; ii < GetCornerCount(); ii++ )
{ {
start = TransformCoordinate( aTransMat, m_PolyPoints[0] ); start = TransformCoordinate( aTransMat, m_PolyPoints[ii-1] );
end = TransformCoordinate( aTransMat, m_PolyPoints[1] ); end = TransformCoordinate( aTransMat, m_PolyPoints[ii] );
ref = aPosRef - start; ref = aPosRef - start;
end -= start; end -= start;
...@@ -584,14 +584,15 @@ EDA_Rect LibDrawPolyline::GetBoundaryBox() ...@@ -584,14 +584,15 @@ EDA_Rect LibDrawPolyline::GetBoundaryBox()
ymin = ymax = m_PolyPoints[0].y; ymin = ymax = m_PolyPoints[0].y;
for( unsigned ii = 1; ii < GetCornerCount(); ii++ ) for( unsigned ii = 1; ii < GetCornerCount(); ii++ )
{ {
xmin = MIN( xmin, m_PolyPoints[0].x ); xmin = MIN( xmin, m_PolyPoints[ii-1].x );
xmax = MAX( xmax, m_PolyPoints[0].x ); xmax = MAX( xmax, m_PolyPoints[ii-1].x );
ymin = MIN( ymin, m_PolyPoints[0].y ); ymin = MIN( ymin, m_PolyPoints[ii].y );
ymax = MAX( ymax, m_PolyPoints[0].y ); ymax = MAX( ymax, m_PolyPoints[ii].y );
} }
BoundaryBox.SetX( xmin ); BoundaryBox.SetWidth( xmax - xmin ); BoundaryBox.SetX( xmin ); BoundaryBox.SetWidth( xmax - xmin );
BoundaryBox.SetY( ymin ); BoundaryBox.SetHeight( ymax - ymin ); BoundaryBox.SetY( ymin ); BoundaryBox.SetHeight( ymax - ymin );
BoundaryBox.Inflate(m_Width, m_Width);
return BoundaryBox; return BoundaryBox;
} }
...@@ -353,7 +353,7 @@ EDA_Rect SCH_COMPONENT::GetBoundaryBox() const ...@@ -353,7 +353,7 @@ EDA_Rect SCH_COMPONENT::GetBoundaryBox() const
int y2 = m_Transform[1][0] * xm + m_Transform[1][1] * ym; int y2 = m_Transform[1][0] * xm + m_Transform[1][1] * ym;
// H and W must be > 0 for wxRect: // H and W must be > 0:
if( x2 < x1 ) if( x2 < x1 )
EXCHG( x2, x1 ); EXCHG( x2, x1 );
if( y2 < y1 ) if( y2 < y1 )
......
...@@ -294,16 +294,6 @@ void DrawNoConnectStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint ...@@ -294,16 +294,6 @@ void DrawNoConnectStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint
} }
EDA_Rect DrawNoConnectStruct::GetBoundingBox()
{
const int DELTA = (DRAWNOCONNECT_SIZE / 2);
EDA_Rect box( wxPoint( m_Pos.x - DELTA, m_Pos.y - DELTA ), wxSize( 2 * DELTA, 2 * DELTA ) );
box.Normalize();
return box;
}
/**************************************************************/ /**************************************************************/
void DrawBusEntryStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, void DrawBusEntryStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
int DrawMode, int Color ) int DrawMode, int Color )
...@@ -329,16 +319,6 @@ void DrawBusEntryStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& ...@@ -329,16 +319,6 @@ void DrawBusEntryStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint&
} }
EDA_Rect DrawBusEntryStruct::GetBoundingBox()
{
int dx = m_Pos.x - m_End().x;
int dy = m_Pos.y - m_End().y;
EDA_Rect box( wxPoint( m_Pos.x, m_Pos.y ), wxSize( dx, dy ) );
box.Normalize();
return box;
}
/***************************************************************************** /*****************************************************************************
* Routine to redraw polyline struct. * * Routine to redraw polyline struct. *
...@@ -411,7 +391,6 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC, ...@@ -411,7 +391,6 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC,
* Utilisee dans les deplacements de blocs * Utilisee dans les deplacements de blocs
*/ */
{ {
int Width;
int DrawMode = g_XorMode; int DrawMode = g_XorMode;
int width = g_DrawMinimunLineWidth; int width = g_DrawMinimunLineWidth;
...@@ -477,15 +456,7 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC, ...@@ -477,15 +456,7 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC,
{ {
DrawJunctionStruct* Struct; DrawJunctionStruct* Struct;
Struct = (DrawJunctionStruct*) DrawStruct; Struct = (DrawJunctionStruct*) DrawStruct;
Width = DRAWJUNCTION_SIZE; Struct->Draw( panel, DC, wxPoint(0,0), DrawMode, g_GhostColor );
GRFilledRect( &panel->m_ClipBox,
DC,
Struct->m_Pos.x - Width + dx,
Struct->m_Pos.y - Width + dy,
Struct->m_Pos.x + Width + dx,
Struct->m_Pos.y + Width + dy,
g_GhostColor,
g_GhostColor );
break; break;
} }
......
...@@ -22,11 +22,9 @@ static SCH_ITEM* LastSnappedStruct = NULL; ...@@ -22,11 +22,9 @@ static SCH_ITEM* 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( wxPoint aPosRef,
int BoxX1, int BoxY1, int BoxX2, int BoxY2 );
static bool IsPointOnSegment( wxPoint aPosRef, wxPoint aSegmStart, wxPoint aSegmEnd, int aDist = 0 ); static bool IsPointOnSegment( wxPoint aPosRef, wxPoint aSegmStart, wxPoint aSegmEnd, int aDist = 0 );
static bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, static bool SnapPoint2( const wxPoint& aPosRef, int SearchMask,
SCH_ITEM* DrawList, DrawPickedStruct* DontSnapList, int zoom_value ); SCH_ITEM* DrawList, DrawPickedStruct* DontSnapList, double aScaleFactor);
/*********************************************************************/ /*********************************************************************/
...@@ -37,7 +35,7 @@ SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen ) ...@@ -37,7 +35,7 @@ SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen )
* 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
*/ */
{ {
SCH_COMPONENT* DrawLibItem = NULL, * LastDrawLibItem = NULL; SCH_COMPONENT* component = NULL, * lastcomponent = NULL;
SCH_ITEM* DrawList; SCH_ITEM* DrawList;
EDA_Rect BoundaryBox; EDA_Rect BoundaryBox;
float sizeref = 0, sizecurr; float sizeref = 0, sizecurr;
...@@ -50,34 +48,39 @@ SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen ) ...@@ -50,34 +48,39 @@ SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen )
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 ) DrawList, NULL, Screen->GetScalingFactor() ) ) == FALSE )
break; break;
} }
DrawLibItem = (SCH_COMPONENT*) LastSnappedStruct; component = (SCH_COMPONENT*) LastSnappedStruct;
DrawList = DrawLibItem->Next(); DrawList = component->Next();
if( LastDrawLibItem == NULL ) // First time a component is located if( lastcomponent == NULL ) // First time a component is located
{ {
LastDrawLibItem = DrawLibItem; lastcomponent = component;
BoundaryBox = LastDrawLibItem->GetBoundaryBox(); BoundaryBox = lastcomponent->GetBoundaryBox();
sizeref = ABS( (float) BoundaryBox.GetWidth() * BoundaryBox.GetHeight() ); sizeref = ABS( (float) BoundaryBox.GetWidth() * BoundaryBox.GetHeight() );
} }
else else
{ {
BoundaryBox = DrawLibItem->GetBoundaryBox(); BoundaryBox = component->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; lastcomponent = component;
} }
} }
} }
return LastDrawLibItem; return lastcomponent;
} }
/* SearchMask = (bitwise OR): /********************************************************************************/
SCH_ITEM* PickStruct( const wxPoint& refpos, BASE_SCREEN* screen, int SearchMask )
/******************************************************************************/
/* Search an item at pos refpos
* SearchMask = (bitwise OR):
* LIBITEM * LIBITEM
* WIREITEM * WIREITEM
* BUSITEM * BUSITEM
...@@ -100,29 +103,16 @@ SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen ) ...@@ -100,29 +103,16 @@ SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen )
* *
* *
* Return: * Return:
* -Bloc search: * pointer on item found or NULL
* pointeur sur liste de pointeurs de structures si Plusieurs
* structures selectionnees.
* pointeur sur la structure si 1 seule
*
* Positon serach:
* pointeur sur la structure.
* Si pas de structures selectionnees: retourne NULL
* *
*/ */
/********************************************************************************/
SCH_ITEM* PickStruct( const wxPoint& refpos, BASE_SCREEN* screen, int SearchMask )
/******************************************************************************/
/* Search an item at pos refpos
*/
{ {
bool Snapped; bool Snapped;
if( screen == NULL || screen->EEDrawList == NULL ) if( screen == NULL || screen->EEDrawList == NULL )
return NULL; return NULL;
if( ( Snapped = SnapPoint2( refpos, SearchMask, if( ( Snapped = SnapPoint2( refpos, SearchMask,
screen->EEDrawList, NULL, screen->GetZoom() ) ) != FALSE ) screen->EEDrawList, NULL, screen->GetScalingFactor() ) ) != FALSE )
{ {
return LastSnappedStruct; return LastSnappedStruct;
} }
...@@ -135,6 +125,11 @@ SCH_ITEM* PickStruct( EDA_Rect& block, BASE_SCREEN* screen, int SearchMask ) ...@@ -135,6 +125,11 @@ SCH_ITEM* PickStruct( EDA_Rect& block, BASE_SCREEN* screen, int SearchMask )
/************************************************************************/ /************************************************************************/
/* Search items in block /* Search items in block
* Return:
* pointeur sur liste de pointeurs de structures si Plusieurs
* structures selectionnees.
* pointeur sur la structure si 1 seule
*
*/ */
{ {
int x, y, OrigX, OrigY; int x, y, OrigX, OrigY;
...@@ -195,11 +190,9 @@ SCH_ITEM* PickStruct( EDA_Rect& block, BASE_SCREEN* screen, int SearchMask ) ...@@ -195,11 +190,9 @@ SCH_ITEM* PickStruct( EDA_Rect& block, BASE_SCREEN* screen, int SearchMask )
* The routine returns TRUE if point was snapped. * * The routine returns TRUE if point was snapped. *
*****************************************************************************/ *****************************************************************************/
bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, bool SnapPoint2( const wxPoint& aPosRef, int SearchMask,
SCH_ITEM* DrawList, DrawPickedStruct* DontSnapList, int zoom_value ) SCH_ITEM* DrawList, DrawPickedStruct* DontSnapList, double aScaleFactor )
{ {
int x1, y1, x2, y2;
DrawPickedStruct* DontSnap; DrawPickedStruct* DontSnap;
int dx, dy;
for( ; DrawList != NULL; DrawList = DrawList->Next() ) for( ; DrawList != NULL; DrawList = DrawList->Next() )
{ {
...@@ -282,30 +275,19 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, ...@@ -282,30 +275,19 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask,
#define STRUCT ( (DrawJunctionStruct*) DrawList ) #define STRUCT ( (DrawJunctionStruct*) DrawList )
if( !(SearchMask & JUNCTIONITEM) ) if( !(SearchMask & JUNCTIONITEM) )
break; break;
dx = DRAWJUNCTION_SIZE / 2; if( STRUCT->HitTest(aPosRef) )
x1 = STRUCT->m_Pos.x - dx;
y1 = STRUCT->m_Pos.y - dx;
x2 = STRUCT->m_Pos.x + dx;
y2 = STRUCT->m_Pos.y + dx;
if( IsPointInBox( aPosRef, 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) ) if( !(SearchMask & NOCONNECTITEM) )
break; break;
dx = (DRAWNOCONNECT_SIZE * zoom_value) / 2; if( STRUCT->HitTest(aPosRef) )
x1 = STRUCT->m_Pos.x - dx;
y1 = STRUCT->m_Pos.y - dx;
x2 = STRUCT->m_Pos.x + dx;
y2 = STRUCT->m_Pos.y + dx;
if( IsPointInBox( aPosRef, x1, y1, x2, y2 ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return TRUE; return TRUE;
...@@ -313,21 +295,20 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, ...@@ -313,21 +295,20 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask,
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) ) if( !(SearchMask & MARKERITEM) )
break; break;
dx = (DRAWMARKER_SIZE * zoom_value) / 2; int size = (int)((DRAWMARKER_SIZE / aScaleFactor) / 2);
x1 = STRUCT->m_Pos.x - dx; wxPoint dist = aPosRef - STRUCT->m_Pos;
y1 = STRUCT->m_Pos.y - dx; if( (abs(dist.x ) <= size) && (abs(dist.y ) <= size) )
x2 = STRUCT->m_Pos.x + dx;
y2 = STRUCT->m_Pos.y + dx;
if( IsPointInBox( aPosRef, x1, y1, x2, y2 ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return TRUE; return TRUE;
} }
break; break;
}
case TYPE_SCH_LABEL: case TYPE_SCH_LABEL:
case TYPE_SCH_TEXT: case TYPE_SCH_TEXT:
...@@ -335,31 +316,7 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, ...@@ -335,31 +316,7 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask,
#define STRUCT ( (SCH_TEXT*) DrawList ) #define STRUCT ( (SCH_TEXT*) DrawList )
if( !( SearchMask & (TEXTITEM | LABELITEM) ) ) if( !( SearchMask & (TEXTITEM | LABELITEM) ) )
break; break;
dx = STRUCT->m_Size.x * STRUCT->GetLength(); if( STRUCT->HitTest( aPosRef ) )
dy = STRUCT->m_Size.y;
x1 = x2 = STRUCT->m_Pos.x;
y1 = y2 = STRUCT->m_Pos.y;
switch( STRUCT->m_Orient )
{
case 0: /* HORIZONTAL Left justified */
x2 += dx; y2 -= dy;
break;
case 1: /* VERTICAL UP */
x2 -= dy; y2 -= dx;
break;
case 2: /* horizontal Right justified */
x2 -= dx; y2 -= dy;
break;
case 3: /* vertical DOWN */
x2 -= dy; y2 += dx;
break;
}
if( IsPointInBox( aPosRef, x1, y1, x2, y2 ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return TRUE; return TRUE;
...@@ -368,36 +325,23 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, ...@@ -368,36 +325,23 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask,
case TYPE_SCH_GLOBALLABEL: case TYPE_SCH_GLOBALLABEL:
case TYPE_SCH_HIERLABEL:
#undef STRUCT #undef STRUCT
#define STRUCT ( (SCH_LABEL*) DrawList ) #define STRUCT ( (SCH_GLOBALLABEL*) DrawList )
if( !(SearchMask & LABELITEM) ) if( !(SearchMask & LABELITEM) )
break; break;
dx = STRUCT->m_Size.x * ( STRUCT->GetLength() + 1 ); /* longueur */ if( STRUCT->HitTest( aPosRef ) )
dy = STRUCT->m_Size.y / 2; /* Demi hauteur */
x1 = x2 = STRUCT->m_Pos.x;
y1 = y2 = STRUCT->m_Pos.y;
switch( STRUCT->m_Orient )
{ {
case 0: /* HORIZONTAL */ LastSnappedStruct = DrawList;
x2 -= dx; y2 += dy; y1 -= dy; return TRUE;
break; }
case 1: /* VERTICAL UP */
x1 -= dy; x2 += dy; y2 += dx;
break;
case 2: /* horizontal inverse */
x2 += dx; y2 += dy; y1 -= dy;
break; break;
case 3: /* vertical DOWN */ case TYPE_SCH_HIERLABEL:
x1 -= dy; x2 += dy; y2 -= dx; #undef STRUCT
#define STRUCT ( (SCH_HIERLABEL*) DrawList )
if( !(SearchMask & LABELITEM) )
break; break;
} if( STRUCT->HitTest( aPosRef ) )
if( IsPointInBox( aPosRef, x1, y1, x2, y2 ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return TRUE; return TRUE;
...@@ -447,13 +391,7 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, ...@@ -447,13 +391,7 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask,
#define STRUCT ( (DrawSheetStruct*) DrawList ) #define STRUCT ( (DrawSheetStruct*) DrawList )
if( !(SearchMask & SHEETITEM) ) if( !(SearchMask & SHEETITEM) )
break; break;
/* Recalcul des coordonnees de l'encadrement du composant */ if( STRUCT->HitTest( aPosRef ) )
x1 = STRUCT->m_Pos.x;
y1 = STRUCT->m_Pos.y;
x2 = STRUCT->m_Pos.x + STRUCT->m_Size.x;
y2 = STRUCT->m_Pos.y + STRUCT->m_Size.y;
if( IsPointInBox( aPosRef, x1, y1, x2, y2 ) )
{ {
LastSnappedStruct = DrawList; LastSnappedStruct = DrawList;
return TRUE; return TRUE;
...@@ -724,29 +662,6 @@ static bool IsBox1InBox2( int StartX1, int StartY1, int EndX1, int EndY1, ...@@ -724,29 +662,6 @@ static bool IsBox1InBox2( int StartX1, int StartY1, int EndX1, int EndY1,
} }
/**********************************************************************/
static bool IsPointInBox( wxPoint aPosRef,
int BoxX1, int BoxY1, int BoxX2, int BoxY2 )
/**********************************************************************/
/* Routine detectant que le point pX,pY est dans le rectangle (Box)
* Retourne TRUE ou FALSE.
*
*/
{
if( BoxX1 > BoxX2 )
EXCHG( BoxX1, BoxX2 );
if( BoxY1 > BoxY2 )
EXCHG( BoxY1, BoxY2 );
if( (aPosRef.x >= BoxX1) && (aPosRef.x <= BoxX2) && (aPosRef.y >= BoxY1) && (aPosRef.y <= BoxY2) )
return TRUE;
else
return FALSE;
}
/********************************************************************************/ /********************************************************************************/
static bool IsPointOnSegment( wxPoint aPosRef, wxPoint aSegmStart, wxPoint aSegmEnd, int aDist ) static bool IsPointOnSegment( wxPoint aPosRef, wxPoint aSegmStart, wxPoint aSegmEnd, int aDist )
/********************************************************************************/ /********************************************************************************/
......
...@@ -324,11 +324,12 @@ void WinEDA_SchematicFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) ...@@ -324,11 +324,12 @@ void WinEDA_SchematicFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
void WinEDA_SchematicFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos ) void WinEDA_SchematicFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
/***************************************************************************/ /***************************************************************************/
/* Appel� sur un double click: /** Function OnLeftDClick
* pour un �l�ment editable (textes, composant): * called on a double click event from the drawpanel mouse handler
* appel de l'editeur correspondant. * if an editable item is found (text, component)
* pour une connexion en cours: * Call the suitable dialog editor.
* termine la connexion * Id a creat command is in progress:
* validate and finish the command
*/ */
{ {
EDA_BaseStruct* DrawStruct = GetScreen()->GetCurItem(); EDA_BaseStruct* DrawStruct = GetScreen()->GetCurItem();
......
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