Libedit: Fix an issue relative to bounding boxes of symbol items: some were calculated using the top to bottom draw Y axis, some others using the bottom to top libedit Y axis

Now all are calculated using the top to bottom draw Y axis. This is perhaps not a good idea, but at least it will be easy to change, later.
Code cleaning relative to these bounding boxes.
This commit is contained in:
jean-pierre charras 2015-06-18 16:56:08 +02:00
parent 1c8fd8b207
commit d4d201f0d8
13 changed files with 127 additions and 66 deletions

View File

@ -423,8 +423,10 @@ void LIB_PART::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
* the bounding box calculations. */ * the bounding box calculations. */
#if 0 #if 0
EDA_RECT bBox = GetBoundingBox( aMulti, aConvert ); EDA_RECT bBox = GetBoundingBox( aMulti, aConvert );
GRRect( aPanel ? aPanel->GetClipBox() : NULL, aDc, bBox.GetOrigin().x, bBox.GetOrigin().y, bBox.RevertYAxis();
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA ); bBox = aTransform.TransformCoordinate( bBox );
bBox.Move( aOffset );
GRRect( aPanel ? aPanel->GetClipBox() : NULL, aDc, bBox, 0, LIGHTMAGENTA );
#endif #endif
} }
@ -1141,7 +1143,8 @@ bool LIB_PART::LoadFootprints( LINE_READER& aLineReader, wxString& aErrorMsg )
const EDA_RECT LIB_PART::GetBoundingBox( int aUnit, int aConvert ) const const EDA_RECT LIB_PART::GetBoundingBox( int aUnit, int aConvert ) const
{ {
EDA_RECT bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) ); EDA_RECT bBox;
bool initialized = false;
for( unsigned ii = 0; ii < drawings.size(); ii++ ) for( unsigned ii = 0; ii < drawings.size(); ii++ )
{ {
@ -1157,7 +1160,13 @@ const EDA_RECT LIB_PART::GetBoundingBox( int aUnit, int aConvert ) const
if ( ( item.Type() == LIB_FIELD_T ) && !( ( LIB_FIELD& ) item ).IsVisible() ) if ( ( item.Type() == LIB_FIELD_T ) && !( ( LIB_FIELD& ) item ).IsVisible() )
continue; continue;
bBox.Merge( item.GetBoundingBox() ); if( initialized )
bBox.Merge( item.GetBoundingBox() );
else
{
bBox = item.GetBoundingBox();
initialized = true;
}
} }
return bBox; return bBox;
@ -1166,7 +1175,8 @@ const EDA_RECT LIB_PART::GetBoundingBox( int aUnit, int aConvert ) const
const EDA_RECT LIB_PART::GetBodyBoundingBox( int aUnit, int aConvert ) const const EDA_RECT LIB_PART::GetBodyBoundingBox( int aUnit, int aConvert ) const
{ {
EDA_RECT bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) ); EDA_RECT bBox;
bool initialized = false;
for( unsigned ii = 0; ii < drawings.size(); ii++ ) for( unsigned ii = 0; ii < drawings.size(); ii++ )
{ {
@ -1182,7 +1192,13 @@ const EDA_RECT LIB_PART::GetBodyBoundingBox( int aUnit, int aConvert ) const
if ( item.Type() == LIB_FIELD_T ) if ( item.Type() == LIB_FIELD_T )
continue; continue;
bBox.Merge( item.GetBoundingBox() ); if( initialized )
bBox.Merge( item.GetBoundingBox() );
else
{
bBox = item.GetBoundingBox();
initialized = true;
}
} }
return bBox; return bBox;

View File

@ -482,8 +482,10 @@ void LIB_ARC::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOf
* calculation. */ * calculation. */
#if 0 #if 0
EDA_RECT bBox = GetBoundingBox(); EDA_RECT bBox = GetBoundingBox();
GRRect( clipbox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y, bBox.RevertYAxis();
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA ); bBox = aTransform.TransformCoordinate( bBox );
bBox.Move( aOffset );
GRRect( clipbox, aDC, bBox, 0, LIGHTMAGENTA );
#endif #endif
} }
@ -545,7 +547,7 @@ start(%d, %d), end(%d, %d), radius %d" ),
rect.SetOrigin( minX, minY ); rect.SetOrigin( minX, minY );
rect.SetEnd( maxX, maxY ); rect.SetEnd( maxX, maxY );
rect.Inflate( m_Width / 2, m_Width / 2 ); rect.Inflate( ( GetPenSize()+1 ) / 2 );
return rect; return rect;
} }

View File

@ -338,7 +338,6 @@ void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
* bounding box calculation. */ * bounding box calculation. */
#if 0 #if 0
EDA_RECT bBox = GetBoundingBox(); EDA_RECT bBox = GetBoundingBox();
bBox.Inflate( m_Thickness + 1, m_Thickness + 1 );
GRRect( aPanel->GetClipBox(), aDC, bBox.GetOrigin().x, bBox.GetOrigin().y, GRRect( aPanel->GetClipBox(), aDC, bBox.GetOrigin().x, bBox.GetOrigin().y,
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA ); bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
#endif #endif
@ -396,9 +395,11 @@ const EDA_RECT LIB_BEZIER::GetBoundingBox() const
ymax = std::max( ymax, m_PolyPoints[ii].y ); ymax = std::max( ymax, m_PolyPoints[ii].y );
} }
rect.SetOrigin( xmin, - ymin ); rect.SetOrigin( xmin, ymin );
rect.SetEnd( xmax, - ymax ); rect.SetEnd( xmax, ymax );
rect.Inflate( m_Width / 2 ); rect.Inflate( ( GetPenSize()+1 ) / 2 );
rect.RevertYAxis();
return rect; return rect;
} }

View File

@ -245,8 +245,10 @@ void LIB_CIRCLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
* box calculation. */ * box calculation. */
#if 0 #if 0
EDA_RECT bBox = GetBoundingBox(); EDA_RECT bBox = GetBoundingBox();
GRRect( clipbox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y, bBox.RevertYAxis();
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA ); bBox = aTransform.TransformCoordinate( bBox );
bBox.Move( aOffset );
GRRect( clipbox, aDC, bBox, 0, LIGHTMAGENTA );
#endif #endif
} }
@ -255,9 +257,11 @@ const EDA_RECT LIB_CIRCLE::GetBoundingBox() const
{ {
EDA_RECT rect; EDA_RECT rect;
rect.SetOrigin( m_Pos.x - m_Radius, ( m_Pos.y - m_Radius ) * -1 ); rect.SetOrigin( m_Pos.x - m_Radius, m_Pos.y - m_Radius );
rect.SetEnd( m_Pos.x + m_Radius, ( m_Pos.y + m_Radius ) * -1 ); rect.SetEnd( m_Pos.x + m_Radius, m_Pos.y + m_Radius );
rect.Inflate( m_Width / 2, m_Width / 2 ); rect.Inflate( ( GetPenSize()+1 ) / 2 );
rect.RevertYAxis();
return rect; return rect;
} }

View File

@ -303,11 +303,10 @@ void LIB_FIELD::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& a
* bounding box calculation. */ * bounding box calculation. */
#if 0 #if 0
EDA_RECT bBox = GetBoundingBox(); EDA_RECT bBox = GetBoundingBox();
EDA_RECT grBox; bBox.RevertYAxis();
grBox.SetOrigin( aTransform.TransformCoordinate( bBox.GetOrigin() ) ); bBox = aTransform.TransformCoordinate( bBox );
grBox.SetEnd( aTransform.TransformCoordinate( bBox.GetEnd() ) ); bBox.Move( aOffset );
grBox.Move( aOffset ); GRRect( clipbox, aDC, bBox, 0, LIGHTMAGENTA );
GRRect( clipbox, aDC, grBox, 0, LIGHTMAGENTA );
#endif #endif
} }
@ -477,6 +476,8 @@ void LIB_FIELD::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
} }
EDA_RECT BoundaryBox = GetBoundingBox(); EDA_RECT BoundaryBox = GetBoundingBox();
BoundaryBox.RevertYAxis();
EDA_TEXT_HJUSTIFY_T hjustify = GR_TEXT_HJUSTIFY_CENTER; EDA_TEXT_HJUSTIFY_T hjustify = GR_TEXT_HJUSTIFY_CENTER;
EDA_TEXT_VJUSTIFY_T vjustify = GR_TEXT_VJUSTIFY_CENTER; EDA_TEXT_VJUSTIFY_T vjustify = GR_TEXT_VJUSTIFY_CENTER;
wxPoint textpos = aTransform.TransformCoordinate( BoundaryBox.Centre() ) wxPoint textpos = aTransform.TransformCoordinate( BoundaryBox.Centre() )
@ -509,17 +510,18 @@ const EDA_RECT LIB_FIELD::GetBoundingBox() const
* calling GetTextBox() that works using top to bottom Y axis orientation. * calling GetTextBox() that works using top to bottom Y axis orientation.
*/ */
EDA_RECT rect = GetTextBox( -1, -1, true ); EDA_RECT rect = GetTextBox( -1, -1, true );
rect.RevertYAxis();
// We are using now a bottom to top Y axis.
wxPoint orig = rect.GetOrigin(); wxPoint orig = rect.GetOrigin();
wxPoint end = rect.GetEnd(); wxPoint end = rect.GetEnd();
NEGATE( orig.y);
NEGATE( end.y);
RotatePoint( &orig, m_Pos, -m_Orient ); RotatePoint( &orig, m_Pos, -m_Orient );
RotatePoint( &end, m_Pos, -m_Orient ); RotatePoint( &end, m_Pos, -m_Orient );
rect.SetOrigin( orig ); rect.SetOrigin( orig );
rect.SetEnd( end ); rect.SetEnd( end );
rect.Normalize();
// We are using now a top to bottom Y axis:
rect.RevertYAxis();
return rect; return rect;
} }

View File

@ -901,14 +901,11 @@ void LIB_PIN::drawGraphic( EDA_DRAW_PANEL* aPanel,
/* Set to one (1) to draw bounding box around pin to validate bounding /* Set to one (1) to draw bounding box around pin to validate bounding
* box calculation. */ * box calculation. */
#if 0 #if 0
EDA_RECT* clipbox = aPanel ? aPanel->GetClipBox() : NULL;
TRANSFORM transform = DefaultTransform;
DefaultTransform = aTransform;
EDA_RECT bBox = GetBoundingBox(); EDA_RECT bBox = GetBoundingBox();
bBox.RevertYAxis();
bBox = aTransform.TransformCoordinate( bBox );
bBox.Move( aOffset ); bBox.Move( aOffset );
//Restore matrix GRRect( aPanel ? aPanel->GetClipBox() : NULL, aDC, bBox, 0, LIGHTMAGENTA );
DefaultTransform = transform;
GRRect( clipbox, aDC, bBox, 0, LIGHTMAGENTA );
#endif #endif
} }
@ -2101,18 +2098,16 @@ const EDA_RECT LIB_PIN::GetBoundingBox() const
break; break;
} }
// Draw Y axis is reversed in schematic: begin += m_position;
NEGATE( begin.y ); end += m_position;
NEGATE( end.y );
wxPoint pos1 = DefaultTransform.TransformCoordinate( m_position );
begin += pos1;
end += pos1;
bbox.SetOrigin( begin ); bbox.SetOrigin( begin );
bbox.SetEnd( end ); bbox.SetEnd( end );
bbox.Normalize(); bbox.Normalize();
bbox.Inflate( GetPenSize() / 2 ); bbox.Inflate( ( GetPenSize() / 2 ) + 1 );
// Draw Y axis is reversed in schematic:
bbox.RevertYAxis();
return bbox; return bbox;
} }

View File

@ -315,9 +315,10 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint
* bounding box calculation. */ * bounding box calculation. */
#if 0 #if 0
EDA_RECT bBox = GetBoundingBox(); EDA_RECT bBox = GetBoundingBox();
bBox.Inflate( m_Thickness + 1, m_Thickness + 1 ); bBox.RevertYAxis();
GRRect( clipbox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y, bBox = aTransform.TransformCoordinate( bBox );
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA ); bBox.Move( aOffset );
GRRect( clipbox, aDC, bBox, 0, LIGHTMAGENTA );
#endif #endif
} }
@ -370,9 +371,11 @@ const EDA_RECT LIB_POLYLINE::GetBoundingBox() const
ymax = std::max( ymax, m_PolyPoints[ii].y ); ymax = std::max( ymax, m_PolyPoints[ii].y );
} }
rect.SetOrigin( xmin, ymin * -1 ); rect.SetOrigin( xmin, ymin );
rect.SetEnd( xmax, ymax * -1 ); rect.SetEnd( xmax, ymax );
rect.Inflate( m_Width / 2, m_Width / 2 ); rect.Inflate( ( GetPenSize()+1 ) / 2 );
rect.RevertYAxis();
return rect; return rect;
} }

View File

@ -237,9 +237,10 @@ void LIB_RECTANGLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
* bounding box calculation. */ * bounding box calculation. */
#if 0 #if 0
EDA_RECT bBox = GetBoundingBox(); EDA_RECT bBox = GetBoundingBox();
bBox.Inflate( m_Thickness + 1, m_Thickness + 1 ); bBox.RevertYAxis();
GRRect( clipbox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y, bBox = aTransform.TransformCoordinate( bBox );
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA ); bBox.Move( aOffset );
GRRect( clipbox, aDC, bBox, 0, LIGHTMAGENTA );
#endif #endif
} }
@ -260,9 +261,12 @@ const EDA_RECT LIB_RECTANGLE::GetBoundingBox() const
{ {
EDA_RECT rect; EDA_RECT rect;
rect.SetOrigin( m_Pos.x, m_Pos.y * -1 ); rect.SetOrigin( m_Pos );
rect.SetEnd( m_End.x, m_End.y * -1 ); rect.SetEnd( m_End );
rect.Inflate( (GetPenSize() / 2) + 1 ); rect.Inflate( ( GetPenSize()+1 ) / 2 );
rect.RevertYAxis();
return rect; return rect;
} }

View File

@ -388,9 +388,11 @@ void LIB_TEXT::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aO
* and use GetBoundaryBox to know the text coordinate considered as centered * and use GetBoundaryBox to know the text coordinate considered as centered
*/ */
EDA_RECT bBox = GetBoundingBox(); EDA_RECT bBox = GetBoundingBox();
// convert coordinates from draw Y axis to libedit Y axis:
bBox.RevertYAxis();
wxPoint txtpos = bBox.Centre(); wxPoint txtpos = bBox.Centre();
// Calculate pos accordint to mirror/rotation. // Calculate pos according to mirror/rotation.
txtpos = aTransform.TransformCoordinate( txtpos ) + aOffset; txtpos = aTransform.TransformCoordinate( txtpos ) + aOffset;
EDA_RECT* clipbox = aPanel? aPanel->GetClipBox() : NULL; EDA_RECT* clipbox = aPanel? aPanel->GetClipBox() : NULL;
@ -403,11 +405,10 @@ void LIB_TEXT::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aO
* the bounding box calculations. * the bounding box calculations.
*/ */
#if 0 #if 0
EDA_RECT grBox; // bBox already uses libedit Y axis.
grBox.SetOrigin( aTransform.TransformCoordinate( bBox.GetOrigin() ) ); bBox = aTransform.TransformCoordinate( bBox );
grBox.SetEnd( aTransform.TransformCoordinate( bBox.GetEnd() ) ); bBox.Move( aOffset );
grBox.Move( aOffset ); GRRect( clipbox, aDC, bBox, 0, LIGHTMAGENTA );
GRRect( clipbox, aDC, grBox, 0, LIGHTMAGENTA );
#endif #endif
} }
@ -430,17 +431,19 @@ const EDA_RECT LIB_TEXT::GetBoundingBox() const
* calling GetTextBox() that works using top to bottom Y axis orientation. * calling GetTextBox() that works using top to bottom Y axis orientation.
*/ */
EDA_RECT rect = GetTextBox( -1, -1, true ); EDA_RECT rect = GetTextBox( -1, -1, true );
rect.RevertYAxis();
// We are using now a bottom to top Y axis.
wxPoint orig = rect.GetOrigin(); wxPoint orig = rect.GetOrigin();
wxPoint end = rect.GetEnd(); wxPoint end = rect.GetEnd();
NEGATE( orig.y);
NEGATE( end.y);
RotatePoint( &orig, m_Pos, -m_Orient ); RotatePoint( &orig, m_Pos, -m_Orient );
RotatePoint( &end, m_Pos, -m_Orient ); RotatePoint( &end, m_Pos, -m_Orient );
rect.SetOrigin( orig ); rect.SetOrigin( orig );
rect.SetEnd( end ); rect.SetEnd( end );
rect.Normalize();
// We are using now a top to bottom Y axis:
rect.RevertYAxis();
return rect; return rect;
} }

View File

@ -383,7 +383,6 @@ void SCH_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOff
// Only for testing purposes, draw the component bounding box // Only for testing purposes, draw the component bounding box
{ {
EDA_RECT boundingBox = GetBoundingBox(); EDA_RECT boundingBox = GetBoundingBox();
GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN ); GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN );
#if 1 #if 1
if( GetField( REFERENCE )->IsVisible() ) if( GetField( REFERENCE )->IsVisible() )

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2010 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2010 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors. * Copyright (C) 2015 KiCad Developers, see CHANGELOG.TXT for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -26,6 +26,7 @@
#include <trigo.h> #include <trigo.h>
#include <transform.h> #include <transform.h>
#include <common.h> #include <common.h>
#include <class_eda_rect.h>
TRANSFORM& TRANSFORM::operator=( const TRANSFORM& aTransform ) TRANSFORM& TRANSFORM::operator=( const TRANSFORM& aTransform )
@ -56,6 +57,14 @@ wxPoint TRANSFORM::TransformCoordinate( const wxPoint& aPoint ) const
( x2 * aPoint.x ) + ( y2 * aPoint.y ) ); ( x2 * aPoint.x ) + ( y2 * aPoint.y ) );
} }
EDA_RECT TRANSFORM::TransformCoordinate( const EDA_RECT& aRect ) const
{
EDA_RECT rect;
rect.SetOrigin( TransformCoordinate( aRect.GetOrigin() ) );
rect.SetEnd( TransformCoordinate( aRect.GetEnd() ) );
return rect;
}
/* /*
* Calculate the Inverse mirror/rotation transform. * Calculate the Inverse mirror/rotation transform.
*/ */

View File

@ -32,6 +32,8 @@
#include <wx/gdicmn.h> #include <wx/gdicmn.h>
class EDA_RECT;
/** /**
* Class for tranforming drawing coordinates for a wxDC device context. * Class for tranforming drawing coordinates for a wxDC device context.
* *
@ -62,7 +64,7 @@ public:
bool operator!=( const TRANSFORM& aTransform ) const { return !( *this == aTransform ); } bool operator!=( const TRANSFORM& aTransform ) const { return !( *this == aTransform ); }
/** /**
* Calculate new coordinate according to the mirror/rotation transform. * Calculate a new coordinate according to the mirror/rotation transform.
* Useful to calculate actual coordinates of a point * Useful to calculate actual coordinates of a point
* from coordinates relative to a component * from coordinates relative to a component
* which are given for a non rotated, non mirrored item * which are given for a non rotated, non mirrored item
@ -72,6 +74,16 @@ public:
wxPoint TransformCoordinate( const wxPoint& aPoint ) const; wxPoint TransformCoordinate( const wxPoint& aPoint ) const;
/** /**
* Calculate a new rect according to the mirror/rotation transform.
* Useful to calculate actual coordinates of a point
* from coordinates relative to a component
* which are given for a non rotated, non mirrored item
* @param aRect = The rectangle to transform
* @return The transformed rectangle.
*/
EDA_RECT TransformCoordinate( const EDA_RECT& aRect ) const;
/**
* Calculate the Inverse mirror/rotation transform. * Calculate the Inverse mirror/rotation transform.
* Useful to calculate coordinates relative to a component * Useful to calculate coordinates relative to a component
* which must be for a non rotated, non mirrored item * which must be for a non rotated, non mirrored item

View File

@ -122,6 +122,17 @@ public:
m_Size.x = pos.x - m_Pos.x; m_Size.y = pos.y - m_Pos.y; m_Size.x = pos.x - m_Pos.x; m_Size.y = pos.y - m_Pos.y;
} }
/**
* Function RevertYAxis
* Mirror the rectangle from the X axis (negate Y pos and size)
*/
void RevertYAxis()
{
m_Pos.y = -m_Pos.y;
m_Size.y = -m_Size.y;
Normalize();
}
/** /**
* Function Intersects * Function Intersects
* tests for a common area between rectangles. * tests for a common area between rectangles.