WIP: Fixed DXF reader

This commit is contained in:
Matthias Koefferlein 2020-12-19 23:37:37 +01:00
parent 72c933ed47
commit b6f710a9fe
6 changed files with 39 additions and 24 deletions

View File

@ -122,25 +122,31 @@ extract_ld (const char *s, int &l, int &d, std::string &n)
std::pair <bool, unsigned int> std::pair <bool, unsigned int>
NamedLayerReader::open_layer (db::Layout &layout, const std::string &n) NamedLayerReader::open_layer (db::Layout &layout, const std::string &n)
{
return open_layer (layout, n, keep_layer_names (), create_layers ());
}
std::pair <bool, unsigned int>
NamedLayerReader::open_layer (db::Layout &layout, const std::string &n, bool keep_layer_name, bool create_layer)
{ {
std::map<std::string, std::pair <bool, unsigned int> >::const_iterator lc = m_layer_cache.find (n); std::map<std::string, std::pair <bool, unsigned int> >::const_iterator lc = m_layer_cache.find (n);
if (lc != m_layer_cache.end ()) { if (lc != m_layer_cache.end ()) {
return lc->second; return lc->second;
} else { } else {
std::pair <bool, unsigned int> res = open_layer_uncached (layout, n); std::pair <bool, unsigned int> res = open_layer_uncached (layout, n, keep_layer_name, create_layer);
m_layer_cache.insert (std::make_pair (n, res)); m_layer_cache.insert (std::make_pair (n, res));
return res; return res;
} }
} }
std::pair <bool, unsigned int> std::pair <bool, unsigned int>
NamedLayerReader::open_layer_uncached (db::Layout &layout, const std::string &n) NamedLayerReader::open_layer_uncached (db::Layout &layout, const std::string &n, bool keep_layer_name, bool create_layer)
{ {
int l = -1, d = -1; int l = -1, d = -1;
std::string on; std::string on;
std::set<unsigned int> li = m_layer_map.logical (n, layout); std::set<unsigned int> li = m_layer_map.logical (n, layout);
if (li.empty () && ! m_keep_layer_names) { if (li.empty () && ! keep_layer_name) {
if (extract_plain_layer (n.c_str (), l)) { if (extract_plain_layer (n.c_str (), l)) {
@ -183,7 +189,7 @@ NamedLayerReader::open_layer_uncached (db::Layout &layout, const std::string &n)
} }
} else if (! m_create_layers) { } else if (! create_layer) {
return std::pair<bool, unsigned int> (false, 0); return std::pair<bool, unsigned int> (false, 0);
@ -212,6 +218,7 @@ NamedLayerReader::open_layer_uncached (db::Layout &layout, const std::string &n)
void void
NamedLayerReader::map_layer (const std::string &name, unsigned int layer) NamedLayerReader::map_layer (const std::string &name, unsigned int layer)
{ {
m_layer_cache [name] = std::make_pair (true, layer);
m_layer_map_out.map (name, layer); m_layer_map_out.map (name, layer);
} }

View File

@ -73,6 +73,14 @@ protected:
*/ */
void set_layer_map (const LayerMap &lm); void set_layer_map (const LayerMap &lm);
/**
* @brief Gets the input layer map
*/
const LayerMap &layer_map ()
{
return m_layer_map;
}
/** /**
* @brief Gets the layer map * @brief Gets the layer map
*/ */
@ -105,6 +113,14 @@ protected:
*/ */
std::pair <bool, unsigned int> open_layer (db::Layout &layout, const std::string &name); std::pair <bool, unsigned int> open_layer (db::Layout &layout, const std::string &name);
/**
* @brief Opens a new layer
* This method will create or locate a layer for a given name.
* The result's first attribute is true, if such a layer could be found
* or created. In this case, the second attribute is the layer index.
*/
std::pair <bool, unsigned int> open_layer (db::Layout &layout, const std::string &name, bool keep_layer_name, bool create_layer);
/** /**
* @brief Force mapping of a name to a layer index * @brief Force mapping of a name to a layer index
*/ */
@ -133,7 +149,7 @@ private:
std::map<std::string, std::pair <bool, unsigned int> > m_layer_cache; std::map<std::string, std::pair <bool, unsigned int> > m_layer_cache;
std::map<std::set<unsigned int>, unsigned int> m_multi_mapping_placeholders; std::map<std::set<unsigned int>, unsigned int> m_multi_mapping_placeholders;
std::pair <bool, unsigned int> open_layer_uncached (db::Layout &layout, const std::string &name); std::pair <bool, unsigned int> open_layer_uncached (db::Layout &layout, const std::string &name, bool keep_layer_name, bool create_layer);
}; };
} }

View File

@ -364,16 +364,6 @@ DXFReader::warn (const std::string &msg)
} }
} }
std::pair <bool, unsigned int>
DXFReader::open_layer (db::Layout &layout, const std::string &n)
{
if (n == zero_layer_name) {
return std::make_pair (true, m_zero_layer);
} else {
return NamedLayerReader::open_layer (layout, n);
}
}
void void
DXFReader::do_read (db::Layout &layout, db::cell_index_type top) DXFReader::do_read (db::Layout &layout, db::cell_index_type top)
{ {
@ -381,21 +371,24 @@ DXFReader::do_read (db::Layout &layout, db::cell_index_type top)
// create the zero layer - this is not mapped to GDS but can be specified in the layer mapping as // create the zero layer - this is not mapped to GDS but can be specified in the layer mapping as
// a layer named "0". // a layer named "0".
std::pair<bool, unsigned int> ll = open_layer (layout, zero_layer_name);
if (ll.first) {
// layer exists std::pair<bool, unsigned int> li = NamedLayerReader::open_layer (layout, zero_layer_name, true /*keep layer name*/, false /*don't create a new layer*/);
m_zero_layer = ll.second; if (li.first) {
// we got one from the layer mapping
m_zero_layer = li.second;
} else { } else {
// or explicitly create the layer: // or we explicitly create the layer
m_zero_layer = layout.insert_layer (db::LayerProperties (0, 0, zero_layer_name)); db::LayerProperties lp_zero (0, 0, zero_layer_name);
m_zero_layer = layout.insert_layer (lp_zero);
map_layer (zero_layer_name, m_zero_layer); map_layer (zero_layer_name, m_zero_layer);
} }
// Read sections // Read sections
int g; int g;
while (true) { while (true) {

View File

@ -193,7 +193,6 @@ private:
void do_read (db::Layout &layout, db::cell_index_type top); void do_read (db::Layout &layout, db::cell_index_type top);
std::pair <bool, unsigned int> open_layer (db::Layout &layout, const std::string &n);
db::cell_index_type make_layer_variant (db::Layout &layout, const std::string &cellname, db::cell_index_type template_cell, unsigned int layer, double sx, double sy); db::cell_index_type make_layer_variant (db::Layout &layout, const std::string &cellname, db::cell_index_type template_cell, unsigned int layer, double sx, double sy);
void cleanup (db::Layout &layout, db::cell_index_type top); void cleanup (db::Layout &layout, db::cell_index_type top);

View File

@ -6,7 +6,7 @@ TARGET = dxf_tests
include($$PWD/../../../../lib_ut.pri) include($$PWD/../../../../lib_ut.pri)
SOURCES = \ SOURCES = \
dbDXFReader.cc \ dbDXFReaderTests.cc
INCLUDEPATH += $$LAY_INC $$TL_INC $$DB_INC $$GSI_INC $$PWD/../db_plugin $$PWD/../../../common INCLUDEPATH += $$LAY_INC $$TL_INC $$DB_INC $$GSI_INC $$PWD/../db_plugin $$PWD/../../../common
DEPENDPATH += $$LAY_INC $$TL_INC $$DB_INC $$GSI_INC $$PWD/../db_plugin $$PWD/../../../common DEPENDPATH += $$LAY_INC $$TL_INC $$DB_INC $$GSI_INC $$PWD/../db_plugin $$PWD/../../../common