From 6a842cdc53cf71f383e14dd97454b0f07a379940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=B6fferlein?= Date: Sat, 9 Apr 2022 18:07:30 +0200 Subject: [PATCH] First attempt to implement X2 net names. Needs reconfirmation. (#1056) --- .../pcb/db_plugin/dbGerberImporter.cc | 23 +++++++++++- .../pcb/db_plugin/dbGerberImporter.h | 2 +- .../streamers/pcb/db_plugin/dbRS274XReader.cc | 37 +++++++++++++++++++ .../streamers/pcb/db_plugin/dbRS274XReader.h | 2 + 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.cc b/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.cc index 44afbddad..7f1a64142 100644 --- a/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.cc +++ b/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.cc @@ -415,7 +415,7 @@ GerberFileReader::collect (db::Region ®ion) } void -GerberFileReader::flush () +GerberFileReader::flush (const std::string &net_name) { process_clear_polygons (); @@ -425,14 +425,35 @@ GerberFileReader::flush () m_polygons.swap (merged_polygons); } + std::string nn = net_name; for (std::vector ::const_iterator t = m_target_layers.begin (); t != m_target_layers.end (); ++t) { + db::Shapes &shapes = mp_top_cell->shapes (*t); + for (std::vector::const_iterator p = m_polygons.begin (); p != m_polygons.end (); ++p) { + shapes.insert (*p); + + if (! nn.empty () && p->hull ().begin () != p->hull ().end ()) { + db::Point pt = *p->hull ().begin (); + shapes.insert (db::Text (nn, db::Trans (pt - db::Point ()))); + nn.clear (); + } + } + for (std::vector::const_iterator p = m_lines.begin (); p != m_lines.end (); ++p) { + shapes.insert (*p); + + if (! nn.empty () && p->begin () != p->end ()) { + db::Point pt = *p->begin (); + shapes.insert (db::Text (nn, db::Trans (pt - db::Point ()))); + nn.clear (); + } + } + } m_polygons.clear (); diff --git a/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.h b/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.h index cdfe8c2ca..0fcf5ebc4 100644 --- a/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.h +++ b/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.h @@ -445,7 +445,7 @@ protected: * @brief Flush the stored data to the output * This method is similar to collect(), but writes the data to the layout. */ - void flush (); + void flush (const std::string &net_name = std::string ()); /** * @brief Collects the data taken so far into the given region diff --git a/src/plugins/streamers/pcb/db_plugin/dbRS274XReader.cc b/src/plugins/streamers/pcb/db_plugin/dbRS274XReader.cc index bdeaa0b87..ee8e4eec8 100644 --- a/src/plugins/streamers/pcb/db_plugin/dbRS274XReader.cc +++ b/src/plugins/streamers/pcb/db_plugin/dbRS274XReader.cc @@ -66,6 +66,7 @@ RS274XReader::init () { // Initialize reader: m_clear = false; + m_net_name.clear (); m_guess_polarity = true; m_neg_polarity = false; m_relative = false; @@ -263,6 +264,16 @@ RS274XReader::do_read () read_pf_parameter (get_block ()); } else if (param == "AD") { read_ad_parameter (get_block ()); + } else if (param == "TO") { + + std::string net_name; + if (read_net_name (get_block (), net_name)) { + if (! m_net_name.empty ()) { + flush (m_net_name); + } + m_net_name = net_name; + } + } else if (param == "TA" || param == "TD" || param == "TF") { // TA, TD and TF paramters are skipped for layout @@ -677,6 +688,10 @@ RS274XReader::do_read () } + if (! m_net_name.empty ()) { + flush (m_net_name); + } + if (! graphics_stack_empty ()) { throw tl::Exception (tl::to_string (tr ("AB block not closed"))); } @@ -963,6 +978,28 @@ RS274XReader::read_pf_parameter (const std::string & /*block*/) warn (tl::to_string (tr ("PF parameters are ignored"))); } +bool +RS274XReader::read_net_name (const std::string &block, std::string &net_name) const +{ + tl::Extractor ex (block.c_str ()); + + ex.test ("."); + + if (ex.test ("N")) { + + // only parse net names + ex.test (","); + + std::string n = ex.get (); + if (! n.empty () && n != "N/C") { + net_name = n; + return true; + } + } + + return false; +} + void RS274XReader::read_ad_parameter (const std::string &block) { diff --git a/src/plugins/streamers/pcb/db_plugin/dbRS274XReader.h b/src/plugins/streamers/pcb/db_plugin/dbRS274XReader.h index 40ff94a11..77db31ee0 100644 --- a/src/plugins/streamers/pcb/db_plugin/dbRS274XReader.h +++ b/src/plugins/streamers/pcb/db_plugin/dbRS274XReader.h @@ -80,6 +80,7 @@ private: std::map m_aperture_macros; enum { ab_xy, ab_yx } m_axis_mapping; RS274XApertureBase *m_current_aperture; + std::string m_net_name; void read_as_parameter (const std::string &block); void read_fs_parameter (const std::string &block); @@ -103,6 +104,7 @@ private: void read_lp_parameter (const std::string &block); void read_sr_parameter (const std::string &block); void read_if_parameter (const std::string &block); + bool read_net_name (const std::string &block, std::string &net_name) const; void install_block_aperture (const std::string &dcode, const db::Region ®ion); void process_mcode (int mcode); const std::string &get_block ();