Refactor EDA_TEXT::TransformToSegmentList() to return a vector of points
This allows reading text object as it is rendered through python API.
This commit is contained in:
parent
51fcbe47a6
commit
b32c2a6c90
|
@ -50,6 +50,7 @@
|
|||
#include <i18n_utility.h>
|
||||
#include <geometry/shape_segment.h>
|
||||
#include <geometry/shape_compound.h>
|
||||
#include <geometry/shape_poly_set.h>
|
||||
|
||||
|
||||
#include <wx/debug.h> // for wxASSERT
|
||||
|
@ -580,8 +581,9 @@ static void addTextSegmToBuffer( int x0, int y0, int xf, int yf, void* aData )
|
|||
}
|
||||
|
||||
|
||||
void EDA_TEXT::TransformTextShapeToSegmentList( std::vector<wxPoint>& aCornerBuffer ) const
|
||||
std::vector<wxPoint> EDA_TEXT::TransformToSegmentList() const
|
||||
{
|
||||
std::vector<wxPoint> cornerBuffer;
|
||||
wxSize size = GetTextSize();
|
||||
|
||||
if( IsMirrored() )
|
||||
|
@ -605,15 +607,17 @@ void EDA_TEXT::TransformTextShapeToSegmentList( std::vector<wxPoint>& aCornerBuf
|
|||
wxString txt = strings_list.Item( ii );
|
||||
GRText( NULL, positions[ii], color, txt, GetDrawRotation(), size, GetHorizJustify(),
|
||||
GetVertJustify(), penWidth, IsItalic(), forceBold, addTextSegmToBuffer,
|
||||
&aCornerBuffer );
|
||||
&cornerBuffer );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GRText( NULL, GetTextPos(), color, GetText(), GetDrawRotation(), size, GetHorizJustify(),
|
||||
GetVertJustify(), penWidth, IsItalic(), forceBold, addTextSegmToBuffer,
|
||||
&aCornerBuffer );
|
||||
&cornerBuffer );
|
||||
}
|
||||
|
||||
return cornerBuffer;
|
||||
}
|
||||
|
||||
|
||||
|
@ -621,8 +625,7 @@ std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( ) const
|
|||
{
|
||||
std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
|
||||
int penWidth = GetEffectiveTextPenWidth();
|
||||
std::vector<wxPoint> pts;
|
||||
TransformTextShapeToSegmentList( pts );
|
||||
std::vector<wxPoint> pts = TransformToSegmentList();
|
||||
|
||||
for( unsigned jj = 0; jj < pts.size(); jj += 2 )
|
||||
shape->AddShape( new SHAPE_SEGMENT( pts[jj], pts[jj+1], penWidth ) );
|
||||
|
|
|
@ -280,10 +280,8 @@ public:
|
|||
*
|
||||
* Each segment is stored as 2 wxPoints: the starting point and the ending point
|
||||
* there are therefore 2*n points.
|
||||
*
|
||||
* @param aCornerBuffer = a buffer to store the polygon
|
||||
*/
|
||||
void TransformTextShapeToSegmentList( std::vector<wxPoint>& aCornerBuffer ) const;
|
||||
std::vector<wxPoint> TransformToSegmentList() const;
|
||||
|
||||
/**
|
||||
* Convert the text bounding box to a rectangular polygon depending on the text
|
||||
|
|
|
@ -991,9 +991,7 @@ bool PNS_KICAD_IFACE_BASE::syncTextItem( PNS::NODE* aWorld, EDA_TEXT* aText, PCB
|
|||
return false;
|
||||
|
||||
int textWidth = aText->GetEffectiveTextPenWidth();
|
||||
std::vector<wxPoint> textShape;
|
||||
|
||||
aText->TransformTextShapeToSegmentList( textShape );
|
||||
std::vector<wxPoint> textShape = aText->TransformToSegmentList();
|
||||
|
||||
if( textShape.size() < 2 )
|
||||
return false;
|
||||
|
|
|
@ -60,6 +60,24 @@ class TestPCBLoad(unittest.TestCase):
|
|||
self.verify_text(text[1], 176149000, 64643000, pcbnew.B_Cu,
|
||||
u'Actionneur\nPiezo New Amp\nV02')
|
||||
|
||||
def test_text_as_segments(self):
|
||||
footprint = self.pcb.FindFootprintByReference("U1")
|
||||
reference = footprint.Reference()
|
||||
segments = [[p.x, p.y] for p in reference.TransformToSegmentList()]
|
||||
expected_segments = [
|
||||
[141901333, 69196857], [143340666, 69196857], [143340666, 69196857],
|
||||
[143510000, 69142428], [143510000, 69142428], [143594666, 69088000],
|
||||
[143594666, 69088000], [143679333, 68979142], [143679333, 68979142],
|
||||
[143679333, 68761428], [143679333, 68761428], [143594666, 68652571],
|
||||
[143594666, 68652571], [143510000, 68598142], [143510000, 68598142],
|
||||
[143340666, 68543714], [143340666, 68543714], [141901333, 68543714],
|
||||
[143679333, 67400714], [143679333, 68053857], [143679333, 67727285],
|
||||
[141901333, 67727285], [141901333, 67727285], [142155333, 67836142],
|
||||
[142155333, 67836142], [142324666, 67945000], [142324666, 67945000],
|
||||
[142409333, 68053857]
|
||||
]
|
||||
self.assertEqual(segments, expected_segments)
|
||||
|
||||
def verify_text(self, text, x, y, layer, s):
|
||||
self.assertEquals(list(text.GetPosition()), [x, y])
|
||||
self.assertEquals(text.GetLayer(), layer)
|
||||
|
|
Loading…
Reference in New Issue