KiCad PCB EDA Suite
EE_RTREE Class Reference

Implements an R-tree for fast spatial and type indexing of schematic items. More...

#include <sch_rtree.h>

Classes

struct  EE_TYPE
 The EE_TYPE struct provides a type-specific auto-range iterator to the RTree. More...
 

Public Types

using iterator = typename ee_rtree::Iterator
 

Public Member Functions

 EE_RTREE ()
 
 ~EE_RTREE ()
 
void insert (SCH_ITEM *aItem)
 Insert an item into the tree. More...
 
bool remove (SCH_ITEM *aItem)
 Remove an item from the tree. More...
 
void clear ()
 Remove all items from the RTree. More...
 
bool contains (const SCH_ITEM *aItem, bool aRobust=false) const
 Determine if a given item exists in the tree. More...
 
size_t size () const
 Return the number of items in the tree. More...
 
bool empty () const
 
EE_TYPE OfType (KICAD_T aType) const
 
EE_TYPE Overlapping (const EDA_RECT &aRect) const
 
EE_TYPE Overlapping (const wxPoint &aPoint, int aAccuracy=0) const
 
EE_TYPE Overlapping (KICAD_T aType, const wxPoint &aPoint, int aAccuracy=0) const
 
EE_TYPE Overlapping (KICAD_T aType, const EDA_RECT &aRect) const
 
iterator begin ()
 Returns a read/write iterator that points to the first element in the EE_RTREE N.B. More...
 
iterator end ()
 Returns a read/write iterator that points to one past the last element in the EE_RTREE. More...
 
const iterator begin () const
 
const iterator end () const
 

Private Types

using ee_rtree = RTree< SCH_ITEM *, int, 3, double >
 

Private Attributes

ee_rtreem_tree
 
size_t m_count
 

Detailed Description

Implements an R-tree for fast spatial and type indexing of schematic items.

Non-owning.

Definition at line 40 of file sch_rtree.h.

Member Typedef Documentation

◆ ee_rtree

using EE_RTREE::ee_rtree = RTree<SCH_ITEM*, int, 3, double>
private

Definition at line 43 of file sch_rtree.h.

◆ iterator

using EE_RTREE::iterator = typename ee_rtree::Iterator

Definition at line 182 of file sch_rtree.h.

Constructor & Destructor Documentation

◆ EE_RTREE()

EE_RTREE::EE_RTREE ( )
inline

Definition at line 46 of file sch_rtree.h.

47  {
48  this->m_tree = new ee_rtree();
49  m_count = 0;
50  }
ee_rtree * m_tree
Definition: sch_rtree.h:295
RTree< SCH_ITEM *, int, 3, double > ee_rtree
Definition: sch_rtree.h:43
size_t m_count
Definition: sch_rtree.h:296

References m_count, and m_tree.

◆ ~EE_RTREE()

EE_RTREE::~EE_RTREE ( )
inline

Definition at line 52 of file sch_rtree.h.

53  {
54  delete this->m_tree;
55  }
ee_rtree * m_tree
Definition: sch_rtree.h:295

References m_tree.

Member Function Documentation

◆ begin() [1/2]

iterator EE_RTREE::begin ( )
inline

Returns a read/write iterator that points to the first element in the EE_RTREE N.B.

The iteration order of the RTree is not readily apparent and will change if/when you add or move items and the RTree is re-balanced. Any exposure of the RTree contents to the user MUST be sorted before being presented. See SCH_SEXPR_PLUGIN::Format or SCH_EDITOR_CONTROL::nextMatch for examples.

Returns
Complete RTree of the screen's items

Definition at line 268 of file sch_rtree.h.

269  {
270  return m_tree->begin();
271  }
ee_rtree * m_tree
Definition: sch_rtree.h:295

References m_tree.

Referenced by SCH_SCREEN::FreeDrawList(), CADSTAR_SCH_ARCHIVE_LOADER::Load(), and SCH_EAGLE_PLUGIN::loadSheet().

◆ begin() [2/2]

const iterator EE_RTREE::begin ( ) const
inline

Definition at line 283 of file sch_rtree.h.

284  {
285  return m_tree->begin();
286  }
ee_rtree * m_tree
Definition: sch_rtree.h:295

References m_tree.

◆ clear()

void EE_RTREE::clear ( )
inline

Remove all items from the RTree.

Definition at line 112 of file sch_rtree.h.

113  {
114  m_tree->RemoveAll();
115  m_count = 0;
116  }
ee_rtree * m_tree
Definition: sch_rtree.h:295
size_t m_count
Definition: sch_rtree.h:296

References m_count, and m_tree.

Referenced by SCH_SCREEN::Clear(), and SCH_SCREEN::FreeDrawList().

◆ contains()

bool EE_RTREE::contains ( const SCH_ITEM aItem,
bool  aRobust = false 
) const
inline

Determine if a given item exists in the tree.

Note that this does not search the full tree so if the item has been moved, this will return false when it should be true.

Parameters
aItemItem that may potentially exist in the tree.
aRobustIf true, search the whole tree, not just the bounding box.
Returns
true if the item definitely exists, false if it does not exist within bbox.

Definition at line 126 of file sch_rtree.h.

127  {
128  EDA_RECT bbox = aItem->GetBoundingBox();
129 
130  // Inflate a bit for safety, selection shadows, etc.
131  bbox.Inflate( aItem->GetPenWidth() );
132 
133  const int type = int( aItem->Type() );
134  const int mmin[3] = { type, bbox.GetX(), bbox.GetY() };
135  const int mmax[3] = { type, bbox.GetRight(), bbox.GetBottom() };
136  bool found = false;
137 
138  auto search =
139  [&found, &aItem]( const SCH_ITEM* aSearchItem )
140  {
141  if( aSearchItem == aItem )
142  {
143  found = true;
144  return false;
145  }
146 
147  return true;
148  };
149 
150  m_tree->Search( mmin, mmax, search );
151 
152  if( !found && aRobust )
153  {
154  // N.B. We must search the whole tree for the pointer to remove
155  // because the item may have been moved. We do not expand the item
156  // type search as this should not change.
157 
158  const int mmin2[3] = { type, INT_MIN, INT_MIN };
159  const int mmax2[3] = { type, INT_MAX, INT_MAX };
160 
161  m_tree->Search( mmin2, mmax2, search );
162  }
163 
164  return found;
165  }
int GetX() const
Definition: eda_rect.h:107
int GetBottom() const
Definition: eda_rect.h:123
ee_rtree * m_tree
Definition: sch_rtree.h:295
int GetRight() const
Definition: eda_rect.h:120
virtual int GetPenWidth() const
Definition: sch_item.h:276
Handle the component boundary box.
Definition: eda_rect.h:42
int GetY() const
Definition: eda_rect.h:108
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:75
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References EDA_RECT::GetBottom(), EDA_ITEM::GetBoundingBox(), SCH_ITEM::GetPenWidth(), EDA_RECT::GetRight(), EDA_RECT::GetX(), EDA_RECT::GetY(), EDA_RECT::Inflate(), m_tree, and EDA_ITEM::Type().

Referenced by SCH_SCREEN::CheckIfOnDrawList().

◆ empty()

bool EE_RTREE::empty ( ) const
inline

Definition at line 177 of file sch_rtree.h.

178  {
179  return m_count == 0;
180  }
size_t m_count
Definition: sch_rtree.h:296

References m_count.

Referenced by SCH_EDIT_TOOL::Init(), SCH_SCREEN::IsEmpty(), and SCH_EDIT_FRAME::setupUIConditions().

◆ end() [1/2]

iterator EE_RTREE::end ( )
inline

Returns a read/write iterator that points to one past the last element in the EE_RTREE.

Definition at line 277 of file sch_rtree.h.

278  {
279  return m_tree->end();
280  }
ee_rtree * m_tree
Definition: sch_rtree.h:295

References m_tree.

Referenced by SCH_SCREEN::FreeDrawList(), CADSTAR_SCH_ARCHIVE_LOADER::Load(), and SCH_EAGLE_PLUGIN::loadSheet().

◆ end() [2/2]

const iterator EE_RTREE::end ( ) const
inline

Definition at line 288 of file sch_rtree.h.

289  {
290  return m_tree->end();
291  }
ee_rtree * m_tree
Definition: sch_rtree.h:295

References m_tree.

◆ insert()

void EE_RTREE::insert ( SCH_ITEM aItem)
inline

Insert an item into the tree.

Item's bounding box is taken via its BBox() method.

Definition at line 60 of file sch_rtree.h.

61  {
62  EDA_RECT bbox = aItem->GetBoundingBox();
63 
64  // Inflate a bit for safety, selection shadows, etc.
65  bbox.Inflate( aItem->GetPenWidth() );
66 
67  const int type = int( aItem->Type() );
68  const int mmin[3] = { type, bbox.GetX(), bbox.GetY() };
69  const int mmax[3] = { type, bbox.GetRight(), bbox.GetBottom() };
70 
71  m_tree->Insert( mmin, mmax, aItem );
72  m_count++;
73  }
int GetX() const
Definition: eda_rect.h:107
int GetBottom() const
Definition: eda_rect.h:123
ee_rtree * m_tree
Definition: sch_rtree.h:295
int GetRight() const
Definition: eda_rect.h:120
virtual int GetPenWidth() const
Definition: sch_item.h:276
size_t m_count
Definition: sch_rtree.h:296
Handle the component boundary box.
Definition: eda_rect.h:42
int GetY() const
Definition: eda_rect.h:108
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:75
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References EDA_RECT::GetBottom(), EDA_ITEM::GetBoundingBox(), SCH_ITEM::GetPenWidth(), EDA_RECT::GetRight(), EDA_RECT::GetX(), EDA_RECT::GetY(), EDA_RECT::Inflate(), m_count, m_tree, and EDA_ITEM::Type().

Referenced by SCH_SCREEN::Append(), and SCH_SCREEN::UpdateLocalLibSymbolLinks().

◆ OfType()

EE_TYPE EE_RTREE::OfType ( KICAD_T  aType) const
inline

Definition at line 230 of file sch_rtree.h.

231  {
232  return EE_TYPE( m_tree, aType );
233  }
ee_rtree * m_tree
Definition: sch_rtree.h:295

References m_tree.

Referenced by SCH_EAGLE_PLUGIN::addBusEntries(), SCH_SHEET_LIST::AnnotatePowerSymbols(), SCH_EDIT_FRAME::BreakSegmentsOnJunctions(), CONNECTION_GRAPH::buildConnectionGraph(), SCH_SCREENS::buildScreenList(), SCH_SCREENS::ChangeSymbolLibNickname(), SCH_SHEET::CleanupSheet(), SCH_SHEET::CountSheets(), SCH_EDIT_FRAME::DeleteAnnotation(), SCH_EDITOR_CONTROL::FindSymbolAndItem(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), SCH_SCREEN::HasItems(), SCH_SHEET::HasUndefinedPins(), SCH_DRAWING_TOOLS::importHierLabel(), SCH_SEXPR_PLUGIN::loadHierarchy(), SCH_LEGACY_PLUGIN::loadHierarchy(), SCH_EAGLE_PLUGIN::loadSheet(), SCH_SHEET::LocatePathOfScreen(), EDIT_POINTS_FACTORY::Make(), NETLIST_EXPORTER_XML::makeSymbols(), DIALOG_SHEET_PIN_PROPERTIES::onComboBox(), DIALOG_ERC::OnERCItemRClick(), DIALOG_CHANGE_SYMBOLS::processMatchingSymbols(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), DIALOG_SYMBOL_REMAP::remapSymbolsToLibTable(), SCH_EDITOR_CONTROL::RepairSchematic(), SCH_EDIT_FRAME::SaveProject(), SCH_EDIT_FRAME::SchematicCleanUp(), SCH_SHEET::SearchHierarchy(), SCH_SHEET::SymbolCount(), ERC_TESTER::TestDuplicateSheetNames(), DIALOG_ERC::testErc(), ERC_TESTER::TestTextVars(), DIALOG_SHEET_PROPERTIES::TransferDataFromWindow(), DIALOG_SHEET_PIN_PROPERTIES::TransferDataToWindow(), DIALOG_CHANGE_SYMBOLS::updateFieldsList(), SIM_PLOT_FRAME::UpdateTunerValue(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().

◆ Overlapping() [1/4]

◆ Overlapping() [2/4]

EE_TYPE EE_RTREE::Overlapping ( const wxPoint &  aPoint,
int  aAccuracy = 0 
) const
inline

Definition at line 240 of file sch_rtree.h.

241  {
242  EDA_RECT rect( aPoint, wxSize( 0, 0 ) );
243  rect.Inflate( aAccuracy );
244  return EE_TYPE( m_tree, SCH_LOCATE_ANY_T, rect );
245  }
ee_rtree * m_tree
Definition: sch_rtree.h:295
Handle the component boundary box.
Definition: eda_rect.h:42

References EDA_RECT::Inflate(), m_tree, and SCH_LOCATE_ANY_T.

◆ Overlapping() [3/4]

EE_TYPE EE_RTREE::Overlapping ( KICAD_T  aType,
const wxPoint &  aPoint,
int  aAccuracy = 0 
) const
inline

Definition at line 247 of file sch_rtree.h.

248  {
249  EDA_RECT rect( aPoint, wxSize( 0, 0 ) );
250  rect.Inflate( aAccuracy );
251  return EE_TYPE( m_tree, aType, rect );
252  }
ee_rtree * m_tree
Definition: sch_rtree.h:295
Handle the component boundary box.
Definition: eda_rect.h:42

References EDA_RECT::Inflate(), and m_tree.

◆ Overlapping() [4/4]

EE_TYPE EE_RTREE::Overlapping ( KICAD_T  aType,
const EDA_RECT aRect 
) const
inline

Definition at line 254 of file sch_rtree.h.

255  {
256  return EE_TYPE( m_tree, aType, aRect );
257  }
ee_rtree * m_tree
Definition: sch_rtree.h:295

References m_tree.

◆ remove()

bool EE_RTREE::remove ( SCH_ITEM aItem)
inline

Remove an item from the tree.

Removal is done by comparing pointers, attempting to remove a copy of the item will fail.

Definition at line 79 of file sch_rtree.h.

80  {
81  // First, attempt to remove the item using its given BBox
82  EDA_RECT bbox = aItem->GetBoundingBox();
83 
84  // Inflate a bit for safety, selection shadows, etc.
85  bbox.Inflate( aItem->GetPenWidth() );
86 
87  const int type = int( aItem->Type() );
88  const int mmin[3] = { type, bbox.GetX(), bbox.GetY() };
89  const int mmax[3] = { type, bbox.GetRight(), bbox.GetBottom() };
90 
91  // If we are not successful ( true == not found ), then we expand
92  // the search to the full tree
93  if( m_tree->Remove( mmin, mmax, aItem ) )
94  {
95  // N.B. We must search the whole tree for the pointer to remove
96  // because the item may have been moved before we have the chance to
97  // delete it from the tree
98  const int mmin2[3] = { INT_MIN, INT_MIN, INT_MIN };
99  const int mmax2[3] = { INT_MAX, INT_MAX, INT_MAX };
100 
101  if( m_tree->Remove( mmin2, mmax2, aItem ) )
102  return false;
103  }
104 
105  m_count--;
106  return true;
107  }
int GetX() const
Definition: eda_rect.h:107
int GetBottom() const
Definition: eda_rect.h:123
ee_rtree * m_tree
Definition: sch_rtree.h:295
int GetRight() const
Definition: eda_rect.h:120
virtual int GetPenWidth() const
Definition: sch_item.h:276
size_t m_count
Definition: sch_rtree.h:296
Handle the component boundary box.
Definition: eda_rect.h:42
int GetY() const
Definition: eda_rect.h:108
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:75
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References EDA_RECT::GetBottom(), EDA_ITEM::GetBoundingBox(), SCH_ITEM::GetPenWidth(), EDA_RECT::GetRight(), EDA_RECT::GetX(), EDA_RECT::GetY(), EDA_RECT::Inflate(), m_count, m_tree, and EDA_ITEM::Type().

Referenced by SCH_SCREEN::Remove(), and SCH_SCREEN::UpdateLocalLibSymbolLinks().

◆ size()

size_t EE_RTREE::size ( ) const
inline

Return the number of items in the tree.

Returns
number of elements in the tree.

Definition at line 172 of file sch_rtree.h.

173  {
174  return m_count;
175  }
size_t m_count
Definition: sch_rtree.h:296

References m_count.

Member Data Documentation

◆ m_count

size_t EE_RTREE::m_count
private

Definition at line 296 of file sch_rtree.h.

Referenced by clear(), EE_RTREE(), empty(), insert(), remove(), and size().

◆ m_tree

ee_rtree* EE_RTREE::m_tree
private

Definition at line 295 of file sch_rtree.h.

Referenced by begin(), clear(), contains(), EE_RTREE(), end(), insert(), OfType(), Overlapping(), remove(), and ~EE_RTREE().


The documentation for this class was generated from the following file: