Skip to content

Commit

Permalink
Merge branch 'master' of github.com:KLayout/klayout
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koefferlein committed Jul 8, 2024
2 parents f45095e + b4b2b57 commit f0b15e1
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 190 deletions.
8 changes: 5 additions & 3 deletions src/edt/edt/edtInstPropertiesPage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ static bool is_orthogonal (const db::DVector &rv, const db::DVector &cv)
InstPropertiesPage::InstPropertiesPage (edt::Service *service, db::Manager *manager, QWidget *parent)
: lay::PropertiesPage (parent, manager, service), mp_service (service), m_enable_cb_callback (true), mp_pcell_parameters (0)
{
m_selection_ptrs.reserve (service->selection ().size ());
for (edt::Service::obj_iterator s = service->selection ().begin (); s != service->selection ().end (); ++s) {
const edt::Service::objects &selection = service->selection ();
m_selection_ptrs.reserve (selection.size ());
for (edt::Service::obj_iterator s = selection.begin (); s != selection.end (); ++s) {
m_selection_ptrs.push_back (s);
}

Expand Down Expand Up @@ -787,7 +788,8 @@ InstPropertiesPage::recompute_selection_ptrs (const std::vector<lay::ObjectInstP
{
std::map<lay::ObjectInstPath, edt::Service::obj_iterator> ptrs;

for (edt::Service::obj_iterator pos = mp_service->selection ().begin (); pos != mp_service->selection ().end (); ++pos) {
const edt::Service::objects &selection = mp_service->selection ();
for (edt::Service::obj_iterator pos = selection.begin (); pos != selection.end (); ++pos) {
ptrs.insert (std::make_pair (*pos, pos));
}

Expand Down
101 changes: 67 additions & 34 deletions src/edt/edt/edtMainService.cc

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/edt/edt/edtPropertiesPageUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ CombinedChangeApplicator::~CombinedChangeApplicator ()
bool CombinedChangeApplicator::supports_relative_mode () const
{
for (std::vector<ChangeApplicator *>::const_iterator a = m_appl.begin (); a != m_appl.end (); ++a) {
if ((*a)->supports_relative_mode ()) {
if ((*a) && (*a)->supports_relative_mode ()) {
return true;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/edt/edt/edtPropertiesPages.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ ShapePropertiesPage::ShapePropertiesPage (const std::string &description, edt::S
: lay::PropertiesPage (parent, manager, service),
m_description (description), mp_service (service), m_enable_cb_callback (true)
{
m_selection_ptrs.reserve (service->selection ().size ());
for (edt::Service::obj_iterator s = service->selection ().begin (); s != service->selection ().end (); ++s) {
const edt::Service::objects &selection = service->selection ();
m_selection_ptrs.reserve (selection.size ());
for (edt::Service::obj_iterator s = selection.begin (); s != selection.end (); ++s) {
m_selection_ptrs.push_back (s);
}
m_prop_id = 0;
Expand Down Expand Up @@ -202,7 +203,8 @@ ShapePropertiesPage::recompute_selection_ptrs (const std::vector<lay::ObjectInst
{
std::map<lay::ObjectInstPath, edt::Service::obj_iterator> ptrs;

for (edt::Service::obj_iterator pos = mp_service->selection ().begin (); pos != mp_service->selection ().end (); ++pos) {
const edt::Service::objects &selection = mp_service->selection ();
for (edt::Service::obj_iterator pos = selection.begin (); pos != selection.end (); ++pos) {
ptrs.insert (std::make_pair (*pos, pos));
}

Expand Down
42 changes: 29 additions & 13 deletions src/edt/edt/edtService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ Service::copy_selected ()
unsigned int inst_mode = 0;

if (m_hier_copy_mode < 0) {
for (objects::const_iterator r = selection ().begin (); r != selection ().end () && ! need_to_ask_for_copy_mode; ++r) {
const objects &sel = selection ();
for (objects::const_iterator r = sel.begin (); r != sel.end () && ! need_to_ask_for_copy_mode; ++r) {
if (r->is_cell_inst ()) {
const db::Cell &cell = view ()->cellview (r->cv_index ())->layout ().cell (r->back ().inst_ptr.cell_index ());
if (! cell.is_proxy ()) {
Expand Down Expand Up @@ -499,10 +500,12 @@ Service::copy_selected ()
void
Service::copy_selected (unsigned int inst_mode)
{
const objects &sel = selection ();

// create one ClipboardData object per cv_index because, this one assumes that there is
// only one source layout object.
std::set <unsigned int> cv_indices;
for (objects::const_iterator r = selection ().begin (); r != selection ().end (); ++r) {
for (objects::const_iterator r = sel.begin (); r != sel.end (); ++r) {
cv_indices.insert (r->cv_index ());
}

Expand All @@ -512,7 +515,7 @@ Service::copy_selected (unsigned int inst_mode)

// add the selected objects to the clipboard data objects.
const lay::CellView &cv = view ()->cellview (*cvi);
for (objects::const_iterator r = selection ().begin (); r != selection ().end (); ++r) {
for (objects::const_iterator r = sel.begin (); r != sel.end (); ++r) {
if (r->cv_index () == *cvi) {
if (! r->is_cell_inst ()) {
cd->get ().add (cv->layout (), r->layer (), r->shape (), cv.context_trans () * r->trans ());
Expand Down Expand Up @@ -614,7 +617,9 @@ Service::selection_bbox ()
lay::TextInfo text_info (view ());

db::DBox box;
for (objects::const_iterator r = selection ().begin (); r != selection ().end (); ++r) {

const objects &sel = selection ();
for (objects::const_iterator r = sel.begin (); r != sel.end (); ++r) {

const lay::CellView &cv = view ()->cellview (r->cv_index ());
const db::Layout &layout = cv->layout ();
Expand Down Expand Up @@ -694,10 +699,12 @@ Service::transform (const db::DCplxTrans &trans, const std::vector<db::DCplxTran

size_t n;

const objects &sel = selection ();

// build a list of object references corresponding to the p_trv vector
std::vector <objects::iterator> obj_ptrs;
obj_ptrs.reserve (selection ().size ());
for (objects::iterator r = selection ().begin (); r != selection ().end (); ++r) {
obj_ptrs.reserve (sel.size ());
for (objects::iterator r = sel.begin (); r != sel.end (); ++r) {
obj_ptrs.push_back (r);
}

Expand All @@ -710,7 +717,7 @@ Service::transform (const db::DCplxTrans &trans, const std::vector<db::DCplxTran
// The key is a triple: cell_index, cv_index, layer
std::map <std::pair <db::cell_index_type, std::pair <unsigned int, unsigned int> >, std::vector <size_t> > shapes_by_cell;
n = 0;
for (objects::iterator r = selection ().begin (); r != selection ().end (); ++r, ++n) {
for (objects::iterator r = sel.begin (); r != sel.end (); ++r, ++n) {
if (! r->is_cell_inst ()) {
shapes_by_cell.insert (std::make_pair (std::make_pair (r->cell_index (), std::make_pair (r->cv_index (), r->layer ())), std::vector <size_t> ())).first->second.push_back (n);
}
Expand Down Expand Up @@ -780,7 +787,7 @@ Service::transform (const db::DCplxTrans &trans, const std::vector<db::DCplxTran
// The key is a pair: cell_index, cv_index
std::map <std::pair <db::cell_index_type, unsigned int>, std::vector <size_t> > insts_by_cell;
n = 0;
for (objects::iterator r = selection ().begin (); r != selection ().end (); ++r, ++n) {
for (objects::iterator r = sel.begin (); r != sel.end (); ++r, ++n) {
if (r->is_cell_inst ()) {
insts_by_cell.insert (std::make_pair (std::make_pair (r->cell_index (), r->cv_index ()), std::vector <size_t> ())).first->second.push_back (n);
}
Expand Down Expand Up @@ -1032,7 +1039,8 @@ Service::del_selected ()
std::set<db::Layout *> needs_cleanup;

// delete all shapes and instances.
for (objects::const_iterator r = selection ().begin (); r != selection ().end (); ++r) {
const objects &sel = selection ();
for (objects::const_iterator r = sel.begin (); r != sel.end (); ++r) {
const lay::CellView &cv = view ()->cellview (r->cv_index ());
if (cv.is_valid ()) {
db::Cell &cell = cv->layout ().cell (r->cell_index ());
Expand Down Expand Up @@ -1722,15 +1730,17 @@ Service::selection_to_view ()
void
Service::do_selection_to_view ()
{
const objects &sel = selection ();

// Hint: this is a lower bound:
m_markers.reserve (selection ().size ());
m_markers.reserve (sel.size ());

// build the transformation variants cache
TransformationVariants tv (view ());

// Build markers

for (std::set<lay::ObjectInstPath>::iterator r = selection ().begin (); r != selection ().end (); ++r) {
for (objects::const_iterator r = sel.begin (); r != sel.end (); ++r) {

const lay::CellView &cv = view ()->cellview (r->cv_index ());

Expand Down Expand Up @@ -1984,10 +1994,16 @@ EditableSelectionIterator::operator++ ()
return *this;
}

const EditableSelectionIterator::value_type &
EditableSelectionIterator::pointer
EditableSelectionIterator::operator-> () const
{
return m_iter.operator-> ();
}

EditableSelectionIterator::reference
EditableSelectionIterator::operator* () const
{
return *m_iter;
return m_iter.operator* ();
}

void
Expand Down
5 changes: 3 additions & 2 deletions src/edt/edt/edtService.h
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ class EditableSelectionIterator
public:
typedef edt::Service::objects::value_type value_type;
typedef edt::Service::objects::const_iterator iterator_type;
typedef void pointer;
typedef const value_type *pointer;
typedef const value_type &reference;
typedef std::forward_iterator_tag iterator_category;
typedef void difference_type;
Expand All @@ -710,7 +710,8 @@ class EditableSelectionIterator
bool at_end () const;

EditableSelectionIterator &operator++ ();
const value_type &operator* () const;
reference operator* () const;
pointer operator-> () const;

private:
std::vector<edt::Service *> m_services;
Expand Down
67 changes: 0 additions & 67 deletions src/edt/edt/edtUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,73 +74,6 @@ std::map<std::string, tl::Variant> pcell_parameters_from_string (const std::stri
return pm;
}

// -------------------------------------------------------------
// SelectionIterator implementation

SelectionIterator::SelectionIterator (lay::LayoutViewBase *view, bool including_transient)
: m_transient_mode (false)
{
mp_edt_services = view->get_plugins <edt::Service> ();

m_current_service = mp_edt_services.begin ();
if (m_current_service != mp_edt_services.end ()) {
m_current_object = (*m_current_service)->selection ().begin ();
}

next ();

if (at_end () && including_transient) {

m_transient_mode = true;

m_current_service = mp_edt_services.begin ();
if (m_current_service != mp_edt_services.end ()) {
m_current_object = (*m_current_service)->transient_selection ().begin ();
}

next ();

}
}

bool
SelectionIterator::at_end () const
{
return m_current_service == mp_edt_services.end ();
}

void
SelectionIterator::inc ()
{
tl_assert (! at_end ());
++m_current_object;
}

void
SelectionIterator::next ()
{
if (at_end ()) {
return;
}

const edt::Service::objects *sel = m_transient_mode ? &(*m_current_service)->transient_selection () : &(*m_current_service)->selection ();

while (m_current_object == sel->end ()) {

++m_current_service;

if (m_current_service != mp_edt_services.end ()) {

sel = m_transient_mode ? &(*m_current_service)->transient_selection () : &(*m_current_service)->selection ();
m_current_object = sel->begin ();

} else {
break;
}

}
}

// -------------------------------------------------------------
// TransformationsVariants implementation
// for a lay::LayoutView
Expand Down
67 changes: 0 additions & 67 deletions src/edt/edt/edtUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,73 +92,6 @@ class TransformationVariants
std::map < std::pair<unsigned int, unsigned int>, std::vector<db::DCplxTrans> > m_per_cv_and_layer_tv;
};

/**
* @brief An iterator for the selected objects of all edt services in a layout view
*/
class SelectionIterator
{
public:
typedef lay::ObjectInstPath value_type;
typedef const lay::ObjectInstPath &reference;
typedef const lay::ObjectInstPath *pointer;

/**
* @brief Creates a new iterator iterating over all selected edt objects from the given view
*
* If "including_transient" is true, the transient selection will be used as fallback.
*/
SelectionIterator (lay::LayoutViewBase *view, bool including_transient = true);

/**
* @brief Returns a value indicating whether the transient selection is taken
*/
bool is_transient () const
{
return m_transient_mode;
}

/**
* @brief Increments the iterator
*/
void operator++ ()
{
inc ();
next ();
}

/**
* @brief Dereferencing
*/
const lay::ObjectInstPath &operator* () const
{
tl_assert (! at_end ());
return *m_current_object;
}

/**
* @brief Arrow operator
*/
const lay::ObjectInstPath *operator-> () const
{
return & operator* ();
}

/**
* @brief Returns a value indicating whether the iterator has finished
*/
bool at_end () const;

private:
void inc ();
void next ();

private:
std::vector<edt::Service *> mp_edt_services;
std::vector<edt::Service *>::const_iterator m_current_service;
std::set<lay::ObjectInstPath>::const_iterator m_current_object;
bool m_transient_mode;
};

} // namespace edt

#endif
Expand Down

0 comments on commit f0b15e1

Please sign in to comment.