Unit tests fixed

The "active_cellview_changed" event was issued multiple times.
This fix avoids this redundancy.
This commit is contained in:
Matthias Koefferlein 2017-06-05 22:27:49 +02:00
parent dbdb46c5cb
commit 1bc0243c0a
2 changed files with 172 additions and 135 deletions

View File

@ -335,7 +335,7 @@ LayoutView::init (db::Manager *mgr, lay::PluginRoot *root, QWidget * /*parent*/)
m_annotation_shapes.manager (mgr); m_annotation_shapes.manager (mgr);
m_visibility_changed = false; m_visibility_changed = false;
m_active_cellview_changed_event_enabled = true;
m_disabled_edits = 0; m_disabled_edits = 0;
m_synchronous = false; m_synchronous = false;
m_drawing_workers = 1; m_drawing_workers = 1;
@ -2886,103 +2886,119 @@ LayoutView::reload_layout (unsigned int cv_index)
unsigned int unsigned int
LayoutView::add_layout (lay::LayoutHandle *layout_handle, bool add_cellview, bool initialize_layers) LayoutView::add_layout (lay::LayoutHandle *layout_handle, bool add_cellview, bool initialize_layers)
{ {
stop (); unsigned int cv_index = 0;
bool set_max_hier = (m_full_hier_new_cell || has_max_hier ()); try {
lay::CellView cv; m_active_cellview_changed_event_enabled = false;
unsigned int cv_index;
if (! add_cellview) { stop ();
clear_cellviews ();
}
cv.set (layout_handle); bool set_max_hier = (m_full_hier_new_cell || has_max_hier ());
cv->layout ().update (); lay::CellView cv;
// select the cell with the largest area as the first top cell if (! add_cellview) {
db::Layout::top_down_const_iterator top = cv->layout ().begin_top_down (); clear_cellviews ();
for (db::Layout::top_down_const_iterator t = cv->layout ().begin_top_down (); t != cv->layout ().end_top_cells (); ++t) {
if (cv->layout ().cell (*t).bbox ().area () > cv->layout ().cell (*top).bbox ().area ()) {
top = t;
}
}
if (top != cv->layout ().end_top_down ()) {
std::vector <db::cell_index_type> p;
p.push_back (*top);
cv.set_unspecific_path (p);
}
cv_index = cellviews ();
set_layout (cv, cv_index);
if (top != cv->layout ().end_top_cells ()) {
std::vector <db::cell_index_type> p;
p.push_back (*top);
select_cell (p, cv_index);
} else {
// even if there is no cell, select the cellview item
// to support applications with an active cellview (that is however invalid)
set_active_cellview_index (cv_index);
}
if (initialize_layers) {
bool add_other_layers = m_add_other_layers;
// Use the "layer-properties-file" meta info from the handle to get the layer properties file.
// If no such file is present, use the default file or the technology specific file.
std::string lyp_file = m_def_lyp_file;
const lay::Technology *tech = lay::Technologies::instance ()->technology_by_name (layout_handle->tech_name ());
if (tech && ! tech->eff_layer_properties_file ().empty ()) {
lyp_file = tech->eff_layer_properties_file ();
add_other_layers = tech->add_other_layers ();
} }
// Give the layout object a chance to specify a certain layer property file cv.set (layout_handle);
for (db::Layout::meta_info_iterator meta = cv->layout ().begin_meta (); meta != cv->layout ().end_meta (); ++meta) {
if (meta->name == "layer-properties-file") { cv->layout ().update ();
lyp_file = meta->value;
// select the cell with the largest area as the first top cell
db::Layout::top_down_const_iterator top = cv->layout ().begin_top_down ();
for (db::Layout::top_down_const_iterator t = cv->layout ().begin_top_down (); t != cv->layout ().end_top_cells (); ++t) {
if (cv->layout ().cell (*t).bbox ().area () > cv->layout ().cell (*top).bbox ().area ()) {
top = t;
} }
if (meta->name == "layer-properties-add-other-layers") { }
try {
tl::from_string (meta->value, add_other_layers); if (top != cv->layout ().end_top_down ()) {
} catch (...) { std::vector <db::cell_index_type> p;
p.push_back (*top);
cv.set_unspecific_path (p);
}
cv_index = cellviews ();
set_layout (cv, cv_index);
if (top != cv->layout ().end_top_cells ()) {
std::vector <db::cell_index_type> p;
p.push_back (*top);
select_cell (p, cv_index);
} else {
// even if there is no cell, select the cellview item
// to support applications with an active cellview (that is however invalid)
set_active_cellview_index (cv_index);
}
if (initialize_layers) {
bool add_other_layers = m_add_other_layers;
// Use the "layer-properties-file" meta info from the handle to get the layer properties file.
// If no such file is present, use the default file or the technology specific file.
std::string lyp_file = m_def_lyp_file;
const lay::Technology *tech = lay::Technologies::instance ()->technology_by_name (layout_handle->tech_name ());
if (tech && ! tech->eff_layer_properties_file ().empty ()) {
lyp_file = tech->eff_layer_properties_file ();
add_other_layers = tech->add_other_layers ();
}
// Give the layout object a chance to specify a certain layer property file
for (db::Layout::meta_info_iterator meta = cv->layout ().begin_meta (); meta != cv->layout ().end_meta (); ++meta) {
if (meta->name == "layer-properties-file") {
lyp_file = meta->value;
}
if (meta->name == "layer-properties-add-other-layers") {
try {
tl::from_string (meta->value, add_other_layers);
} catch (...) {
}
} }
} }
// interpolate the layout properties file name
tl::Eval expr;
expr.set_var ("layoutfile", layout_handle->filename ());
lyp_file = expr.interpolate (lyp_file);
// create the initial layer properties
create_initial_layer_props (cv_index, lyp_file, add_other_layers);
} }
// interpolate the layout properties file name // signal to any observers
tl::Eval expr; file_open_event ();
expr.set_var ("layoutfile", layout_handle->filename ());
lyp_file = expr.interpolate (lyp_file);
// create the initial layer properties if (cv->layout ().begin_top_down () != cv->layout ().end_top_down ()) {
create_initial_layer_props (cv_index, lyp_file, add_other_layers);
} // do a fit and update layer lists etc.
zoom_fit ();
if (set_max_hier) {
max_hier ();
}
update_content ();
// signal to any observers } else {
file_open_event (); // even if there is no cell, select the cellview item
// to support applications with an active cellview (that is however invalid)
if (cv->layout ().begin_top_down () != cv->layout ().end_top_down ()) { set_active_cellview_index (cv_index);
// do a fit and update layer lists etc.
zoom_fit ();
if (set_max_hier) {
max_hier ();
} }
m_active_cellview_changed_event_enabled = true;
} catch (...) {
update_content (); update_content ();
} else { m_active_cellview_changed_event_enabled = true;
// even if there is no cell, select the cellview item throw;
// to support applications with an active cellview (that is however invalid)
set_active_cellview_index (cv_index);
} }
// this event may not be generated otherwise: // this event may not be generated otherwise, hence force it now.
active_cellview_changed (cv_index); active_cellview_changed (cv_index);
return cv_index; return cv_index;
@ -3066,65 +3082,80 @@ LayoutView::load_layout (const std::string &filename, const db::LoadLayoutOption
} }
// select the cell with the largest area as the first top cell try {
db::Layout::top_down_const_iterator top = cv->layout ().begin_top_down ();
for (db::Layout::top_down_const_iterator t = cv->layout ().begin_top_down (); t != cv->layout ().end_top_cells (); ++t) {
if (cv->layout ().cell (*t).bbox ().area () > cv->layout ().cell (*top).bbox ().area ()) {
top = t;
}
}
if (top != cv->layout ().end_top_cells ()) {
std::vector <db::cell_index_type> p;
p.push_back (*top);
select_cell (p, cv_index);
} else {
// even if there is no cell, select the cellview item
// to support applications with an active cellview (that is however invalid)
set_active_cellview_index (cv_index);
}
bool add_other_layers = m_add_other_layers; m_active_cellview_changed_event_enabled = false;
// Use the "layer-properties-file" meta info from the handle to get the layer properties file. // select the cell with the largest area as the first top cell
// If no such file is present, use the default file or the technology specific file. db::Layout::top_down_const_iterator top = cv->layout ().begin_top_down ();
std::string lyp_file = m_def_lyp_file; for (db::Layout::top_down_const_iterator t = cv->layout ().begin_top_down (); t != cv->layout ().end_top_cells (); ++t) {
if (tech && ! tech->eff_layer_properties_file ().empty ()) { if (cv->layout ().cell (*t).bbox ().area () > cv->layout ().cell (*top).bbox ().area ()) {
lyp_file = tech->eff_layer_properties_file (); top = t;
add_other_layers = tech->add_other_layers ();
}
// Give the layout object a chance to specify a certain layer property file
for (db::Layout::meta_info_iterator meta = cv->layout().begin_meta (); meta != cv->layout().end_meta (); ++meta) {
if (meta->name == "layer-properties-file") {
lyp_file = meta->value;
}
if (meta->name == "layer-properties-add-other-layers") {
try {
tl::from_string (meta->value, add_other_layers);
} catch (...) {
} }
} }
if (top != cv->layout ().end_top_cells ()) {
std::vector <db::cell_index_type> p;
p.push_back (*top);
select_cell (p, cv_index);
} else {
// even if there is no cell, select the cellview item
// to support applications with an active cellview (that is however invalid)
set_active_cellview_index (cv_index);
}
bool add_other_layers = m_add_other_layers;
// Use the "layer-properties-file" meta info from the handle to get the layer properties file.
// If no such file is present, use the default file or the technology specific file.
std::string lyp_file = m_def_lyp_file;
if (tech && ! tech->eff_layer_properties_file ().empty ()) {
lyp_file = tech->eff_layer_properties_file ();
add_other_layers = tech->add_other_layers ();
}
// Give the layout object a chance to specify a certain layer property file
for (db::Layout::meta_info_iterator meta = cv->layout().begin_meta (); meta != cv->layout().end_meta (); ++meta) {
if (meta->name == "layer-properties-file") {
lyp_file = meta->value;
}
if (meta->name == "layer-properties-add-other-layers") {
try {
tl::from_string (meta->value, add_other_layers);
} catch (...) {
}
}
}
// interpolate the layout properties file name
tl::Eval expr;
expr.set_var ("layoutfile", filename);
lyp_file = expr.interpolate (lyp_file);
// create the initial layer properties
create_initial_layer_props (cv_index, lyp_file, add_other_layers);
// signal to any observers
file_open_event ();
// do a fit and update layer lists etc.
zoom_fit ();
if (set_max_hier) {
max_hier ();
}
update_content ();
m_active_cellview_changed_event_enabled = true;
} catch (...) {
update_content ();
m_active_cellview_changed_event_enabled = true;
throw;
} }
// interpolate the layout properties file name // this event may not be generated otherwise, hence force it now.
tl::Eval expr;
expr.set_var ("layoutfile", filename);
lyp_file = expr.interpolate (lyp_file);
// create the initial layer properties
create_initial_layer_props (cv_index, lyp_file, add_other_layers);
// signal to any observers
file_open_event ();
// do a fit and update layer lists etc.
zoom_fit ();
if (set_max_hier) {
max_hier ();
}
update_content ();
// this event may not be generated otherwise:
active_cellview_changed (cv_index); active_cellview_changed (cv_index);
return cv_index; return cv_index;
@ -4296,6 +4327,15 @@ LayoutView::select_cellviews_fit (const std::list <CellView> &cvs)
} }
} }
void
LayoutView::active_cellview_changed (int index)
{
if (m_active_cellview_changed_event_enabled) {
active_cellview_changed_event ();
active_cellview_changed_with_index_event (index);
}
}
void void
LayoutView::select_cell_dispatch (const cell_path_type &path, int cellview_index) LayoutView::select_cell_dispatch (const cell_path_type &path, int cellview_index)
{ {

View File

@ -2391,11 +2391,7 @@ public slots:
* *
* This signal is forwarded to the active_cellview_changed event * This signal is forwarded to the active_cellview_changed event
*/ */
void active_cellview_changed (int index) void active_cellview_changed (int index);
{
active_cellview_changed_event ();
active_cellview_changed_with_index_event (index);
}
/** /**
* @brief Gets the full field box * @brief Gets the full field box
@ -2687,6 +2683,7 @@ private:
int m_copy_layera, m_copy_layerr; int m_copy_layera, m_copy_layerr;
bool m_visibility_changed; bool m_visibility_changed;
bool m_active_cellview_changed_event_enabled;
tl::DeferredMethod<lay::LayoutView> dm_prop_changed; tl::DeferredMethod<lay::LayoutView> dm_prop_changed;
void init (db::Manager *mgr, lay::PluginRoot *root, QWidget *parent); void init (db::Manager *mgr, lay::PluginRoot *root, QWidget *parent);