20#include <boost/test/unit_test.hpp>
27#include <system_error>
44#include <wx/filename.h>
56 explicit TEMP_FILE(
const wxString& aPrefix ) :
57 m_path( std::string( wxFileName::CreateTempFileName( aPrefix ).ToUTF8() ) )
64 std::filesystem::remove( m_path, ec );
67 const std::filesystem::path& Path()
const {
return m_path; }
68 std::string Str()
const {
return m_path.string(); }
69 wxString WxStr()
const {
return wxString( m_path.string() ); }
72 std::filesystem::path m_path;
76std::string slurp(
const std::filesystem::path& aPath )
78 std::ifstream in( aPath );
85std::unique_ptr<BOARD> loadTestBoard()
87 const std::filesystem::path boardPath =
96int countTraces(
BOARD* aBoard )
110void importSession(
BOARD* aBoard,
const wxString& aSesPath )
113 toolMgr.
SetEnvironment( aBoard,
nullptr,
nullptr,
nullptr,
nullptr );
118 commit.Push( wxT(
"Import Specctra Session" ),
SKIP_UNDO );
126 toolMgr.
SetEnvironment( aBoard,
nullptr,
nullptr,
nullptr,
nullptr );
131 commit.Push( wxT(
"Import Specctra Session" ),
SKIP_UNDO );
147 std::unique_ptr<BOARD> board = loadTestBoard();
150 board->Footprints().front()->SetValue( wxT(
"2x20 pin 0.1\" female header" ) );
152 TEMP_FILE out( wxT(
"kicad_specctra_24946_" ) );
155 const std::string dsn = slurp( out.Path() );
158 BOOST_CHECK( dsn.find(
"0.1\" female" ) == std::string::npos );
159 BOOST_CHECK( dsn.find(
"0.1'' female" ) != std::string::npos );
169 std::unique_ptr<BOARD> board = loadTestBoard();
171 BOOST_REQUIRE_GE( board->Footprints().size(), 5u );
173 board->Footprints()[0]->SetReference( wxEmptyString );
174 board->Footprints()[1]->SetReference( wxEmptyString );
175 board->Footprints()[2]->SetReference( wxT(
"U1" ) );
176 board->Footprints()[3]->SetReference( wxT(
"U1" ) );
177 board->Footprints()[4]->SetReference( wxT(
"u1" ) );
179 TEMP_FILE out( wxT(
"kicad_specctra_24947_" ) );
182 const std::string dsn = slurp( out.Path() );
185 BOOST_CHECK( dsn.find(
"(place REF**_1 " ) != std::string::npos );
186 BOOST_CHECK( dsn.find(
"(place U1 " ) != std::string::npos );
187 BOOST_CHECK( dsn.find(
"(place U1_1 " ) != std::string::npos );
188 BOOST_CHECK( dsn.find(
"(place u1_2 " ) != std::string::npos );
206 for(
int i = 0; i < 4; ++i )
211 edge->
SetEnd( corners[( i + 1 ) % 4] );
221 ZONE* keepout =
new ZONE( footprint );
230 footprint->
Add( keepout );
231 board.
Add( footprint );
233 TEMP_FILE out( wxT(
"kicad_specctra_keepout_" ) );
236 const std::string dsn = slurp( out.Path() );
237 const size_t image = dsn.find(
"(image " );
239 const std::string imageText = dsn.substr(
image, dsn.find(
"(network",
image ) -
image );
242 BOOST_CHECK_MESSAGE( imageText.find(
"(keepout" ) != std::string::npos, imageText );
243 BOOST_CHECK_MESSAGE( imageText.find(
"1000 -500" ) != std::string::npos, imageText );
244 BOOST_CHECK_MESSAGE( imageText.find(
"3000 -1500" ) != std::string::npos, imageText );
245 BOOST_CHECK_MESSAGE( imageText.find(
"3000 -500" ) != std::string::npos, imageText );
246 BOOST_CHECK_MESSAGE( imageText.find(
"1000 -1500" ) != std::string::npos, imageText );
253 std::unique_ptr<BOARD> board = loadTestBoard();
255 TEMP_FILE ses( wxT(
"kicad_specctra_allegro_poly_" ) );
257 const std::string validLayer = std::string( board->GetLayerName(
F_Cu ).ToUTF8() );
259 std::ofstream out( ses.Path() );
260 out <<
"(session test.ses\n"
261 <<
" (base_design test.dsn)\n"
263 <<
" (resolution um 10)\n"
264 <<
" (library_out )\n"
266 <<
" (net \"/ALLPST\"\n"
267 <<
" (wire (path \"" << validLayer <<
"\" 1600 0 0 1000 0)\n"
268 <<
" (type route))\n"
269 <<
" (wire (poly \"" << validLayer <<
"\" 0 0 0 1000 0 1000 1000 0 1000 0 0)\n"
270 <<
" (type normal))\n"
277 BOOST_REQUIRE_NO_THROW( importSession( board.get(), ses.Str() ) );
289 std::unique_ptr<BOARD> board = loadTestBoard();
291 TEMP_FILE ses( wxT(
"kicad_specctra_24948_" ) );
295 const std::string validLayer = std::string( board->GetLayerName(
F_Cu ).ToUTF8() );
297 std::ofstream out( ses.Path() );
298 out <<
"(session test.ses\n"
299 <<
" (base_design test.dsn)\n"
301 <<
" (resolution um 10)\n"
302 <<
" (component test\n"
303 <<
" (place Nonexistent_Ref 0 0 front 0)\n"
307 <<
" (resolution um 10)\n"
308 <<
" (library_out )\n"
310 <<
" (net \"/ALLPST\"\n"
311 <<
" (wire (path \"" << validLayer <<
"\" 1600 0 0 1000 0))\n"
312 <<
" (wire (path Bogus_Missing_Layer 1600 0 0 1000 1000))\n"
321 wxLog::SetTimestamp( wxEmptyString );
324 BOOST_REQUIRE_NO_THROW( importSession( board.get(), ses.Str() ) );
338 std::unique_ptr<BOARD> board = loadTestBoard();
340 TEMP_FILE out( wxT(
"kicad_specctra_parseable_" ) );
351 BOOST_FAIL( ioe.
What().ToStdString() );
359 std::unique_ptr<BOARD> board = loadTestBoard();
363 TEMP_FILE out( wxT(
"kicad_specctra_content_" ) );
366 const std::string dsn = slurp( out.Path() );
369 BOOST_CHECK( dsn.find(
"(unit um" ) != std::string::npos );
372 bool netHeaderFound =
false;
374 for(
const NETINFO_ITEM* net : board->GetNetInfo().NetsByNetcode() | std::views::values )
376 if( net->GetNetname().IsEmpty() )
379 if( dsn.find(
"(net \"" + std::string( net->GetNetname().ToUTF8() ) +
"\"" ) != std::string::npos )
380 netHeaderFound =
true;
391 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
394 TEMP_FILE out( wxT(
"kicad_specctra_reporter_" ) );
constexpr EDA_IU_SCALE pcbIUScale
General utilities for PCB file IO for QA programs.
Information pertinent to a Pcbnew printed circuit board.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
const TRACKS & Tracks() const
A DSN data tree, usually coming from a DSN file.
void LoadPCB(const wxString &aFilename)
A recursive descent parser for a SPECCTRA DSN "design" file.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Handle the data for a net.
void SetEnd(const VECTOR2I &aEnd) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStart(const VECTOR2I &aStart) override
A wrapper for reporting to a wxString object.
Handle a list of polygons defining a copper zone.
bool AppendCorner(const VECTOR2I &aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetIsRuleArea(bool aEnable)
void SetDoNotAllowTracks(bool aEnable)
void SetDoNotAllowVias(bool aEnable)
static constexpr EDA_ANGLE ANGLE_90
This source file implements export and import capabilities to the specctra dsn file format.
void ExportBoardToSpecctraFile(BOARD *aBoard, const wxString &aFullFilename, REPORTER *aReporter=nullptr)
Helper method to export board to DSN file.
bool ImportSpecctraSession(BOARD *aBoard, const wxString &fullFileName, COMMIT &aCommit, REPORTER *aReporter=nullptr, int *aSkippedCount=nullptr)
Helper method to import SES file to a board.
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
std::unique_ptr< BOARD > RequireBoardFromPcbnewQAData(const std::filesystem::path &aFilename)
Require a board from the path relative to the pcbnew QA data directory.
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
IbisParser parser & reporter
BOOST_AUTO_TEST_CASE(SpecctraExportQuoteInField)
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
VECTOR2< int32_t > VECTOR2I