mirror of https://github.com/KLayout/klayout.git
Code cleanup + fixing another bug (crash when doing 'change layer' on multiple selected shapes)
This commit is contained in:
parent
930a5d7424
commit
6bca4a07b6
|
|
@ -2409,7 +2409,7 @@ MainService::cm_change_layer ()
|
|||
int cv_index = -1;
|
||||
|
||||
// get (common) cellview index of the selected shapes
|
||||
for (SelectionIterator s (view ()); ! s.at_end (); ++s) {
|
||||
for (EditableSelectionIterator s = begin_objects_selected (view ()); ! s.at_end (); ++s) {
|
||||
if (cv_index >= 0 && cv_index != int (s->cv_index ())) {
|
||||
throw tl::Exception (tl::to_string (tr ("Selections originate from different layouts - cannot switch layer in this case.")));
|
||||
}
|
||||
|
|
@ -2477,7 +2477,7 @@ MainService::cm_change_layer ()
|
|||
|
||||
// Insert and delete the shape. This exploits the fact, that a shape can be erased multiple times -
|
||||
// this is important since the selection potentially contains the same shape multiple times.
|
||||
for (SelectionIterator s (view ()); ! s.at_end (); ++s) {
|
||||
for (EditableSelectionIterator s = begin_objects_selected (view ()); ! s.at_end (); ++s) {
|
||||
|
||||
if (!s->is_cell_inst () && int (s->layer ()) != layer) {
|
||||
|
||||
|
|
|
|||
|
|
@ -1994,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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -710,7 +710,8 @@ public:
|
|||
bool at_end () const;
|
||||
|
||||
EditableSelectionIterator &operator++ ();
|
||||
const value_type &operator* () const;
|
||||
reference operator* () const;
|
||||
pointer operator-> () const;
|
||||
|
||||
private:
|
||||
std::vector<edt::Service *> m_services;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -92,73 +92,6 @@ private:
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue