WIP: fixing undo, implement layout cleanup

This commit is contained in:
Matthias Koefferlein 2025-08-18 23:21:18 +02:00
parent 39c8e0ca15
commit 331d16ab7c
2 changed files with 50 additions and 60 deletions

View File

@ -306,13 +306,8 @@ ShapeEditService::deliver_shape (const db::Polygon &poly)
{ {
if (m_combine_mode == CM_Add) { if (m_combine_mode == CM_Add) {
if (manager ()) { db::Transaction transaction (manager (), tl::to_string (tr ("Create polygon")));
manager ()->transaction (tl::to_string (tr ("Create polygon")));
}
cell ().shapes (layer ()).insert (poly); cell ().shapes (layer ()).insert (poly);
if (manager ()) {
manager ()->commit ();
}
} else { } else {
@ -370,9 +365,7 @@ ShapeEditService::deliver_shape (const db::Polygon &poly)
result = input; result = input;
} }
if (manager ()) { db::Transaction transaction (manager (), tl::to_string (tr ("Combine shape with background")));
manager ()->transaction (tl::to_string (tr ("Combine shape with background")));
}
// Erase existing shapes // Erase existing shapes
for (std::vector<db::Shape>::const_iterator s = shapes.begin (); s != shapes.end (); ++s) { for (std::vector<db::Shape>::const_iterator s = shapes.begin (); s != shapes.end (); ++s) {
@ -387,10 +380,6 @@ ShapeEditService::deliver_shape (const db::Polygon &poly)
cell ().shapes (layer ()).insert (*p); cell ().shapes (layer ()).insert (*p);
} }
if (manager ()) {
manager ()->commit ();
}
} }
} }
@ -398,13 +387,8 @@ void
ShapeEditService::deliver_shape (const db::Path &path) ShapeEditService::deliver_shape (const db::Path &path)
{ {
if (m_combine_mode == CM_Add) { if (m_combine_mode == CM_Add) {
if (manager ()) { db::Transaction transaction (manager (), tl::to_string (tr ("Create path")));
manager ()->transaction (tl::to_string (tr ("Create path")));
}
cell ().shapes (layer ()).insert (path); cell ().shapes (layer ()).insert (path);
if (manager ()) {
manager ()->commit ();
}
} else { } else {
deliver_shape (path.polygon ()); deliver_shape (path.polygon ());
} }
@ -414,13 +398,8 @@ void
ShapeEditService::deliver_shape (const db::Box &box) ShapeEditService::deliver_shape (const db::Box &box)
{ {
if (m_combine_mode == CM_Add) { if (m_combine_mode == CM_Add) {
if (manager ()) { db::Transaction transaction (manager (), tl::to_string (tr ("Create box")));
manager ()->transaction (tl::to_string (tr ("Create box")));
}
cell ().shapes (layer ()).insert (box); cell ().shapes (layer ()).insert (box);
if (manager ()) {
manager ()->commit ();
}
} else { } else {
deliver_shape (db::Polygon (box)); deliver_shape (db::Polygon (box));
} }
@ -430,13 +409,8 @@ void
ShapeEditService::deliver_shape (const db::Point &point) ShapeEditService::deliver_shape (const db::Point &point)
{ {
if (m_combine_mode == CM_Add) { if (m_combine_mode == CM_Add) {
if (manager ()) { db::Transaction transaction (manager (), tl::to_string (tr ("Create point")));
manager ()->transaction (tl::to_string (tr ("Create point")));
}
cell ().shapes (layer ()).insert (point); cell ().shapes (layer ()).insert (point);
if (manager ()) {
manager ()->commit ();
}
} }
} }
@ -1490,12 +1464,9 @@ PathService::via ()
return; return;
} }
/* @@@ if (combine_mode () != CM_Add) {
if (m_combine_mode != CM_Add) { throw tl::Exception (tl::to_string (tr ("Vias are only available in 'Add' combination mode")));
// @@@ an error?
return;
} }
*/
db::LayerProperties lp = layout ().get_properties (layer ()); db::LayerProperties lp = layout ().get_properties (layer ());
std::vector<db::SelectedViaDefinition> via_defs = db::find_via_definitions_for (layout ().technology_name (), lp); std::vector<db::SelectedViaDefinition> via_defs = db::find_via_definitions_for (layout ().technology_name (), lp);
@ -1543,7 +1514,12 @@ PathService::via ()
// produce the path up to the current point // produce the path up to the current point
db::DPoint via_pos = m_points.back (); db::DPoint via_pos = m_points.back ();
db::Shape path_shape = cell ().shapes (layer ()).insert (get_path ());
db::Shape path_shape;
{
db::Transaction transaction (manager (), tl::to_string (tr ("Create path")));
path_shape = cell ().shapes (layer ()).insert (get_path ());
}
bool is_bottom = via_def.via_type.bottom.log_equal (lp); bool is_bottom = via_def.via_type.bottom.log_equal (lp);
db::LayerProperties lp_new = is_bottom ? via_def.via_type.top : via_def.via_type.bottom; db::LayerProperties lp_new = is_bottom ? via_def.via_type.top : via_def.via_type.bottom;
@ -1568,11 +1544,14 @@ PathService::via ()
params.insert (std::make_pair ("h_bottom", tl::Variant (h_bottom))); params.insert (std::make_pair ("h_bottom", tl::Variant (h_bottom)));
params.insert (std::make_pair ("h_top", tl::Variant (h_top))); params.insert (std::make_pair ("h_top", tl::Variant (h_top)));
{
db::Transaction transaction (manager (), tl::to_string (tr ("Create via")));
auto via_lib_cell = via_def.lib->layout ().get_pcell_variant_dict (via_def.pcell, params); auto via_lib_cell = via_def.lib->layout ().get_pcell_variant_dict (via_def.pcell, params);
auto via_cell = layout ().get_lib_proxy (via_def.lib, via_lib_cell); auto via_cell = layout ().get_lib_proxy (via_def.lib, via_lib_cell);
db::Instance via_instance = cell ().insert (db::CellInstArray (db::CellInst (via_cell), db::Trans (trans () * via_pos - db::Point ()))); db::Instance via_instance = cell ().insert (db::CellInstArray (db::CellInst (via_cell), db::Trans (trans () * via_pos - db::Point ())));
push_segment (path_shape, via_instance, via_def.via_type); push_segment (path_shape, via_instance, via_def.via_type, transaction.id ());
if (! via_def.via_type.cut.is_null ()) { if (! via_def.via_type.cut.is_null ()) {
edt::set_or_request_current_layer (view (), via_def.via_type.cut, cv_index (), false /*don't make current*/); edt::set_or_request_current_layer (view (), via_def.via_type.cut, cv_index (), false /*don't make current*/);
@ -1587,6 +1566,7 @@ PathService::via ()
update_marker (); update_marker ();
update_via (); update_via ();
}
} }
void void
@ -1600,16 +1580,18 @@ PathService::update_via ()
return; return;
} }
if (! m_previous_segments.back ().via_instance.instances ()) { PathSegment &ps = m_previous_segments.back ();
if (! ps.via_instance.instances ()) {
return; return;
} }
db::Cell *via_parent_cell = m_previous_segments.back ().via_instance.instances ()->cell (); db::Cell *via_parent_cell = ps.via_instance.instances ()->cell ();
// Compute the parameters to change // Compute the parameters to change
db::LayerProperties lp = layout ().get_properties (layer ()); db::LayerProperties lp = layout ().get_properties (layer ());
bool is_bottom = m_previous_segments.back ().via_type.bottom.log_equal (lp); bool is_bottom = ps.via_type.bottom.log_equal (lp);
double w = 0.0, h = 0.0; double w = 0.0, h = 0.0;
db::DVector dwire = m_points [1] - m_points.front (); db::DVector dwire = m_points [1] - m_points.front ();
@ -1632,17 +1614,23 @@ PathService::update_via ()
// change the via PCell // change the via PCell
m_previous_segments.back ().via_instance = via_parent_cell->change_pcell_parameters (m_previous_segments.back ().via_instance, params); {
db::Transaction transaction (manager (), tl::to_string (tr ("Create via")), ps.via_transaction_id);
ps.via_instance = via_parent_cell->change_pcell_parameters (ps.via_instance, params);
layout ().cleanup ();
}
} }
void void
PathService::push_segment (const db::Shape &shape, const db::Instance &instance, const db::ViaType &via_type) PathService::push_segment (const db::Shape &shape, const db::Instance &instance, const db::ViaType &via_type, db::Manager::transaction_id_t via_transaction_id)
{ {
m_previous_segments.push_back (PathSegment ()); m_previous_segments.push_back (PathSegment ());
PathSegment &ps = m_previous_segments.back (); PathSegment &ps = m_previous_segments.back ();
ps.path_shape = shape; ps.path_shape = shape;
ps.via_instance = instance; ps.via_instance = instance;
ps.via_transaction_id = via_transaction_id;
ps.via_type = via_type; ps.via_type = via_type;
ps.layer = layer (); ps.layer = layer ();
ps.cv_index = cv_index (); ps.cv_index = cv_index ();

View File

@ -75,6 +75,7 @@ protected:
template <class Shape> template <class Shape>
void deliver_shape_to_hooks (const Shape &shape); void deliver_shape_to_hooks (const Shape &shape);
void close_editor_hooks (bool with_commit); void close_editor_hooks (bool with_commit);
combine_mode_type combine_mode () const { return m_combine_mode; }
const tl::weak_collection<edt::EditorHooks> &editor_hooks () const tl::weak_collection<edt::EditorHooks> &editor_hooks ()
{ {
@ -247,13 +248,14 @@ protected:
private: private:
struct PathSegment struct PathSegment
{ {
PathSegment () : layer (0), cv_index (0) { } PathSegment () : layer (0), cv_index (0), via_transaction_id (0) { }
unsigned int layer; unsigned int layer;
int cv_index; int cv_index;
std::list<std::pair<std::string, std::string> > config; std::list<std::pair<std::string, std::string> > config;
db::Shape path_shape; db::Shape path_shape;
db::Instance via_instance; db::Instance via_instance;
db::Manager::transaction_id_t via_transaction_id;
db::ViaType via_type; db::ViaType via_type;
}; };
@ -268,7 +270,7 @@ private:
db::Path get_path () const; db::Path get_path () const;
void set_last_point (const db::DPoint &p); void set_last_point (const db::DPoint &p);
void update_via (); void update_via ();
void push_segment (const db::Shape &shape, const db::Instance &instance, const db::ViaType &via_type); void push_segment (const db::Shape &shape, const db::Instance &instance, const db::ViaType &via_type, db::Manager::transaction_id_t via_transaction_id);
void pop_segment (); void pop_segment ();
}; };