Re: [Kicad-developers] LIB_TEXT bounding boxes

2015-06-17 Thread Chris Pavlina
Yeah, I know that much - I'm just trying to figure out where the 
LIB_TEXT bounding boxes are going /wrong/. Try it - turn on the switch 
to view the bounding boxes (sch_component.cpp line 382, recommend 
changing GetBoundingBox on 385 to GetBodyBoundingBox, it's a bit more 
helpful in this case) and move around some LIB_TEXT instances in a 
component. The vertical axis is inverted, so that when you move the text 
downwards, the bounding box grows upwards.

On Wed, Jun 17, 2015 at 05:35:43PM +0200, jp charras wrote:
 Le 17/06/2015 00:11, Chris Pavlina a écrit :
  Hi all,
  
  While working on that field autoplace feature, I noticed that 
  LIB_PART::GetBodyBoundingBox was returning incorrect bounding boxes when 
  the parts contained a LIB_TEXT. Further investigation revealed that 
  there was an extra negation of the vertical dimension somewhere in the 
  mix. The trouble is, there appear to be multiple of these, because 
  adding or removing negations would fix it in this place, but would cause 
  other troubles (text rendering in the wrong spot in libedit, or clicks 
  not being received). The only way I found that worked was to 
  special-case LIB_TEXT inside LIB_PART::GetBodyBoundingBox, negating both 
  the Y position and Y size. Ugly hack attached.
  
  Anyone familiar enough to have a guess as to what the real problem is, 
  without me spending hours digging into the entirety of the bounding box 
  code? The ugly hack works, but... ew.
  
  --
  Chris
 
 For historical reasons, the Y axis is bottom to top for coordinates of
 symbols (graphic items, texts ..) in libraries, and is top to bottom in
 schematic.
 
 When drawing a symbol, a matrix transform is applied to coordinates, to
 take in account the Y axis orientation, as well as component orientation
 (rotation, mirroring).
 
 
 -- 
 Jean-Pierre CHARRAS
 
 ___
 Mailing list: https://launchpad.net/~kicad-developers
 Post to : kicad-developers@lists.launchpad.net
 Unsubscribe : https://launchpad.net/~kicad-developers
 More help   : https://help.launchpad.net/ListHelp

___
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp


Re: [Kicad-developers] LIB_TEXT bounding boxes

2015-06-17 Thread Chris Pavlina
I'm looking into it, anyway, just wanted to know if anyone knew much 
about it. There's always the possibility that I misunderstood something, 
since I'm working in a section I haven't been in before, so I'd rather 
dive into it myself than waste your time. I'll submit a patch if there 
really is a bug here, after I investigate further to figure out 
/exactly/ what the problem is.


On Wed, Jun 17, 2015 at 06:29:56PM +0200, jp charras wrote:
 Le 17/06/2015 17:39, Chris Pavlina a écrit :
  Yeah, I know that much - I'm just trying to figure out where the 
  LIB_TEXT bounding boxes are going /wrong/. Try it - turn on the switch 
  to view the bounding boxes (sch_component.cpp line 382, recommend 
  changing GetBoundingBox on 385 to GetBodyBoundingBox, it's a bit more 
  helpful in this case) and move around some LIB_TEXT instances in a 
  component. The vertical axis is inverted, so that when you move the text 
  downwards, the bounding box grows upwards.
 
 OK.
 
 I see.
 
 
 -- 
 Jean-Pierre CHARRAS
 
 ___
 Mailing list: https://launchpad.net/~kicad-developers
 Post to : kicad-developers@lists.launchpad.net
 Unsubscribe : https://launchpad.net/~kicad-developers
 More help   : https://help.launchpad.net/ListHelp

___
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp


Re: [Kicad-developers] LIB_TEXT bounding boxes

2015-06-17 Thread Chris Pavlina
For the curious, have a look at this bizarre screenshot:

http://misc.c4757p.com/bbox_wtf.png

I turned on drawing of bounding boxes for both component bodies and 
LIB_TEXTs - the text's bounding box renders correctly, but it merges 
with the rest of the component drawing item boxes wrong, growing the box 
in the wrong direction...

My ugly hack patch in the first message fixes this, by special-casing 
it so that LIB_TEXT and LIB_FIELD items have their boxes inverted **only 
when merging to get the combined bounding box**.

WTF.



On Wed, Jun 17, 2015 at 06:29:56PM +0200, jp charras wrote:
 Le 17/06/2015 17:39, Chris Pavlina a écrit :
  Yeah, I know that much - I'm just trying to figure out where the 
  LIB_TEXT bounding boxes are going /wrong/. Try it - turn on the switch 
  to view the bounding boxes (sch_component.cpp line 382, recommend 
  changing GetBoundingBox on 385 to GetBodyBoundingBox, it's a bit more 
  helpful in this case) and move around some LIB_TEXT instances in a 
  component. The vertical axis is inverted, so that when you move the text 
  downwards, the bounding box grows upwards.
 
 OK.
 
 I see.
 
 
 -- 
 Jean-Pierre CHARRAS
 
 ___
 Mailing list: https://launchpad.net/~kicad-developers
 Post to : kicad-developers@lists.launchpad.net
 Unsubscribe : https://launchpad.net/~kicad-developers
 More help   : https://help.launchpad.net/ListHelp

___
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp


Re: [Kicad-developers] LIB_TEXT bounding boxes

2015-06-17 Thread jp charras
Le 17/06/2015 17:39, Chris Pavlina a écrit :
 Yeah, I know that much - I'm just trying to figure out where the 
 LIB_TEXT bounding boxes are going /wrong/. Try it - turn on the switch 
 to view the bounding boxes (sch_component.cpp line 382, recommend 
 changing GetBoundingBox on 385 to GetBodyBoundingBox, it's a bit more 
 helpful in this case) and move around some LIB_TEXT instances in a 
 component. The vertical axis is inverted, so that when you move the text 
 downwards, the bounding box grows upwards.

OK.

I see.


-- 
Jean-Pierre CHARRAS

___
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp


[Kicad-developers] LIB_TEXT bounding boxes

2015-06-16 Thread Chris Pavlina
Hi all,

While working on that field autoplace feature, I noticed that 
LIB_PART::GetBodyBoundingBox was returning incorrect bounding boxes when 
the parts contained a LIB_TEXT. Further investigation revealed that 
there was an extra negation of the vertical dimension somewhere in the 
mix. The trouble is, there appear to be multiple of these, because 
adding or removing negations would fix it in this place, but would cause 
other troubles (text rendering in the wrong spot in libedit, or clicks 
not being received). The only way I found that worked was to 
special-case LIB_TEXT inside LIB_PART::GetBodyBoundingBox, negating both 
the Y position and Y size. Ugly hack attached.

Anyone familiar enough to have a guess as to what the real problem is, 
without me spending hours digging into the entirety of the bounding box 
code? The ugly hack works, but... ew.

--
Chris

commit c2a1607092013825312608a454f3861fd4b07547
Author: Chris Pavlina cpavl...@binghamton.edu
Date:   Tue Jun 16 17:59:28 2015 -0400

Preliminary fix for eeschema text bounding boxes

diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp
index 2ba8989..81429c8 100644
--- a/eeschema/class_libentry.cpp
+++ b/eeschema/class_libentry.cpp
@@ -1142,6 +1142,7 @@ bool LIB_PART::LoadFootprints( LINE_READER aLineReader, wxString aErrorMsg )
 const EDA_RECT LIB_PART::GetBoundingBox( int aUnit, int aConvert ) const
 {
 EDA_RECT bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
+bool first = true;
 
 for( unsigned ii = 0; ii  drawings.size(); ii++  )
 {
@@ -1157,7 +1158,21 @@ const EDA_RECT LIB_PART::GetBoundingBox( int aUnit, int aConvert ) const
 if ( ( item.Type() == LIB_FIELD_T )  !( ( LIB_FIELD ) item ).IsVisible() )
 continue;
 
-bBox.Merge( item.GetBoundingBox() );
+EDA_RECT item_bb = item.GetBoundingBox();
+
+if( item.Type() == LIB_TEXT_T || item.Type() == LIB_FIELD_T )
+{
+item_bb.SetY( -item_bb.GetY() );
+item_bb.SetSize( item_bb.GetSize().x, -item_bb.GetSize().y );
+}
+
+if( first )
+{
+bBox = item_bb;
+first = false;
+}
+else
+bBox.Merge( item_bb );
 }
 
 return bBox;
@@ -1167,6 +1182,7 @@ const EDA_RECT LIB_PART::GetBoundingBox( 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 ) );
+bool first = true;
 
 for( unsigned ii = 0; ii  drawings.size(); ii++  )
 {
@@ -1182,7 +1198,21 @@ const EDA_RECT LIB_PART::GetBodyBoundingBox( int aUnit, int aConvert ) const
 if ( item.Type() == LIB_FIELD_T )
 continue;
 
-bBox.Merge( item.GetBoundingBox() );
+EDA_RECT item_bb = item.GetBoundingBox();
+
+if( item.Type() == LIB_TEXT_T )
+{
+item_bb.SetY( -item_bb.GetY() );
+item_bb.SetSize( item_bb.GetSize().x, -item_bb.GetSize().y );
+}
+
+if( first )
+{
+bBox = item_bb;
+first = false;
+}
+else
+bBox.Merge( item_bb );
 }
 
 return bBox;
___
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp