From 2d57a11f8c77402a49398c26077a533a3e306a10 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 12 Jul 2019 23:13:50 +0200 Subject: [PATCH] Fixed #287 (RecursiveShapeIterator to ObjectInstPath) There is a new constructor for ObjectInstPath to create one from a RecursiveShapeIterator. --- src/edt/edt/gsiDeclEdt.cc | 50 +++++++++++++++++++++++++++++++++++++-- testdata/ruby/edtTest.rb | 10 ++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/edt/edt/gsiDeclEdt.cc b/src/edt/edt/gsiDeclEdt.cc index 9af7a6e8c..e3af87305 100644 --- a/src/edt/edt/gsiDeclEdt.cc +++ b/src/edt/edt/gsiDeclEdt.cc @@ -23,6 +23,7 @@ #include "gsiDecl.h" #include "edtService.h" +#include "dbRecursiveShapeIterator.h" #include "layObjectInstPath.h" #include "layLayoutView.h" @@ -94,7 +95,42 @@ static db::DCplxTrans dtrans (const lay::ObjectInstPath *p) } } +static std::vector get_path (const lay::ObjectInstPath *p) +{ + std::vector pe; + pe.insert (pe.end (), p->begin (), p->end ()); + return pe; +} + +static void set_path (lay::ObjectInstPath *p, const std::vector &pe) +{ + p->assign_path (pe.begin (), pe.end ()); +} + +static lay::ObjectInstPath *from_si (const db::RecursiveShapeIterator &si, int cv_index) +{ + lay::ObjectInstPath *ip = new lay::ObjectInstPath (); + + if (! si.at_end ()) { + + ip->set_cv_index (cv_index); + ip->set_layer (si.layer ()); + ip->set_shape (si.shape ()); + ip->set_topcell (si.top_cell ()->cell_index ()); + std::vector path (si.path ()); + ip->assign_path (path.begin (), path.end ()); + + } + + return ip; +} + gsi::Class decl_ObjectInstPath ("lay", "ObjectInstPath", + gsi::constructor ("new", &from_si, gsi::arg ("si"), gsi::arg ("cv_index"), + "@brief Creates a new path object from a \\RecursiveShapeIterator\n" + "Use this constructor to quickly turn a recursive shape iterator delivery " + "into a shape selection." + ) + gsi::method ("<", &lay::ObjectInstPath::operator<, "@brief Provides an order criterion for two ObjectInstPath objects\n" "@args b\n" @@ -281,7 +317,18 @@ gsi::Class decl_ObjectInstPath ("lay", "ObjectInstPath", "\n" "This method was introduced in version 0.24.\n" ) + - gsi::method ("append_path", (void (lay::ObjectInstPath::*) (const db::InstElement &)) &lay::ObjectInstPath::add_path, + gsi::method_ext ("path", &get_path, + "@brief Gets the instantiation path\n" + "The path is a sequence of \\InstElement objects leading to the target object.\n" + "\n" + "This method was introduced in version 0.26.\n" + ) + + gsi::method_ext ("path=", &set_path, gsi::arg ("p"), + "@brief Sets the instantiation path\n" + "\n" + "This method was introduced in version 0.26.\n" + ) + + gsi::method ("append_path", (void (lay::ObjectInstPath::*) (const db::InstElement &)) &lay::ObjectInstPath::add_path, "@brief Appends an element to the instantiation path\n" "@args element\n" "\n" @@ -528,7 +575,6 @@ static EditableSelectionIterator begin_objects_selected_transient (const lay::La return EditableSelectionIterator (view->get_plugins (), true); } - static gsi::ClassExt layout_view_decl ( gsi::method_ext ("has_object_selection?", &has_object_selection, diff --git a/testdata/ruby/edtTest.rb b/testdata/ruby/edtTest.rb index 6708c6b6a..2ee85bc55 100644 --- a/testdata/ruby/edtTest.rb +++ b/testdata/ruby/edtTest.rb @@ -109,6 +109,16 @@ class EDT_TestClass < TestBase assert_equal(p.trans.to_s, "r0 *1 0,0") assert_equal(p.source_trans.to_s, "r0 *1 0,0") + # ObjectInstPath from RecursiveShapeIterator + + si = tc.begin_shapes_rec(li) + oi = RBA::ObjectInstPath::new(si, 2) + + assert_equal(oi.cv_index, 2) + assert_equal(oi.shape.to_s, si.shape.to_s) + assert_equal(oi.cell_index, si.cell.cell_index) + assert_equal(oi.top, tc.cell_index) + end # Selection