KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_convert_tool.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <algorithm>
23#include <deque>
24
25#include <board.h>
26#include <pcb_shape.h>
27#include <eda_item.h>
28#include <locale_io.h>
32#include <tools/convert_tool.h>
33
35
36
42{
43public:
44 SHAPE_POLY_SET MakePolys( const std::deque<EDA_ITEM*>& aItems )
45 {
46 return m_tool.makePolysFromChainedSegs( aItems, CENTERLINE );
47 }
48
49private:
51};
52
53
54BOOST_FIXTURE_TEST_SUITE( ConvertTool, CONVERT_TOOL_TEST_FIXTURE )
55
56
57
65BOOST_AUTO_TEST_CASE( CreatePolygonFromSplineOutline )
66{
67 BOARD board;
68
69 DXF_IMPORT_PLUGIN plugin;
70 GRAPHICS_IMPORTER_PCBNEW importer( &board );
71
72 plugin.SetImporter( &importer );
74 importer.SetLayer( Edge_Cuts );
75
76 wxString dxfPath = wxString::FromUTF8(
77 KI_TEST::GetPcbnewTestDataDir() + "../common/import_gfx/issue22127_fusion360_splines.dxf" );
78
79 {
81 BOOST_REQUIRE( plugin.Load( dxfPath ) );
82 BOOST_REQUIRE( plugin.Import() );
83 }
84
85 std::deque<EDA_ITEM*> items;
86
87 for( std::unique_ptr<EDA_ITEM>& item : importer.GetItems() )
88 items.push_back( item.get() );
89
90 // The outline is built from lines and splines (splines become a chain of bezier PCB_SHAPEs).
91 BOOST_REQUIRE_MESSAGE( items.size() >= 6, "Expected several imported shapes, got " << items.size() );
92
93 for( EDA_ITEM* item : items )
94 item->ClearFlags( SKIP_STRUCT );
95
96 SHAPE_POLY_SET result = MakePolys( items );
97
98 BOOST_CHECK_MESSAGE( result.OutlineCount() == 1,
99 "Spline+line outline should chain into exactly one closed polygon, got "
100 << result.OutlineCount() );
101
102 if( result.OutlineCount() == 1 )
103 {
104 const SHAPE_LINE_CHAIN& outline = result.COutline( 0 );
105
106 BOOST_CHECK_MESSAGE( outline.IsClosed(), "Resulting polygon must be closed" );
107 BOOST_CHECK_MESSAGE( outline.Area() > 0.0,
108 "Resulting polygon must enclose a non-zero area" );
109 }
110
111 // A closed subset loop would also satisfy the checks above, so confirm that every imported
112 // shape was actually chained. makePolysFromChainedSegs marks consumed items with SKIP_STRUCT.
113 size_t chainedItems = std::count_if( items.begin(), items.end(),
114 []( EDA_ITEM* aItem )
115 {
116 return aItem->GetFlags() & SKIP_STRUCT;
117 } );
118
119 BOOST_CHECK_EQUAL( chainedItems, items.size() );
120}
121
122
General utilities for PCB file IO for QA programs.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
Exposes CONVERT_TOOL's private chaining routine so the regression test can drive the real production ...
SHAPE_POLY_SET MakePolys(const std::deque< EDA_ITEM * > &aItems)
bool Import() override
Actually imports the file.
bool Load(const wxString &aFileName) override
Load file for import.
void SetUnit(DXF_IMPORT_UNITS aUnit)
Set the default units when importing DXFs.
virtual void SetImporter(GRAPHICS_IMPORTER *aImporter) override
Set the receiver of the imported shapes.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
void SetLayer(PCB_LAYER_ID aLayer)
std::list< std::unique_ptr< EDA_ITEM > > & GetItems()
Return the list of objects representing the imported shapes.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool IsClosed() const override
double Area(bool aAbsolute=true) const
Return the area of this chain.
Represent a set of closed polygons.
#define SKIP_STRUCT
flag indicating that the structure should be ignored
@ Edge_Cuts
Definition layer_ids.h:108
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
@ CENTERLINE
std::vector< FAB_LAYER_COLOR > dummy
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")