KiCad PCB EDA Suite
KIGFX::VIEW_GROUP Class Reference

Extend VIEW_ITEM by possibility of grouping items into a single object. More...

#include <view_group.h>

Inheritance diagram for KIGFX::VIEW_GROUP:
KIGFX::VIEW_ITEM INSPECTABLE SELECTION EE_SELECTION GERBVIEW_SELECTION PCB_SELECTION PL_SELECTION

Public Member Functions

 VIEW_GROUP (VIEW *aView=nullptr)
 
virtual ~VIEW_GROUP ()
 
virtual unsigned int GetSize () const
 Return the number of stored items. More...
 
virtual void Add (VIEW_ITEM *aItem)
 Add an item to the group. More...
 
virtual void Remove (VIEW_ITEM *aItem)
 Remove an item from the group. More...
 
virtual void Clear ()
 Remove all the stored items from the group. More...
 
virtual VIEW_ITEMGetItem (unsigned int aIdx) const
 
virtual const BOX2I ViewBBox () const override
 Return the bounding box for all stored items covering all its layers. More...
 
virtual void ViewDraw (int aLayer, VIEW *aView) const override
 Draw all the stored items in the group on the given layer. More...
 
virtual void ViewGetLayers (int aLayers[], int &aCount) const override
 Return all the layers used by the stored items. More...
 
virtual void SetLayer (int aLayer)
 Set layer used to draw the group. More...
 
void FreeItems ()
 Free all the items that were added to the group. More...
 
virtual double ViewGetLOD (int aLayer, VIEW *aView) const
 Return the level of detail (LOD) of the item. More...
 
VIEW_ITEM_DATAviewPrivData () const
 
void ClearViewPrivData ()
 
bool Set (PROPERTY_BASE *aProperty, wxAny &aValue)
 
template<typename T >
bool Set (PROPERTY_BASE *aProperty, T aValue)
 
template<typename T >
bool Set (const wxString &aProperty, T aValue)
 
wxAny Get (PROPERTY_BASE *aProperty)
 
template<typename T >
Get (PROPERTY_BASE *aProperty)
 
template<typename T >
boost::optional< T > Get (const wxString &aProperty)
 

Protected Member Functions

virtual const std::vector< VIEW_ITEM * > updateDrawList () const
 

Protected Attributes

int m_layer
 
std::vector< VIEW_ITEM * > m_groupItems
 

Detailed Description

Extend VIEW_ITEM by possibility of grouping items into a single object.

VIEW_GROUP does not take over ownership of the held items. The main purpose of this class is to group items and draw them on a single layer (in particular the overlay).

Definition at line 46 of file view_group.h.

Constructor & Destructor Documentation

◆ VIEW_GROUP()

VIEW_GROUP::VIEW_GROUP ( VIEW aView = nullptr)

Definition at line 44 of file view_group.cpp.

44  :
45  VIEW_ITEM(),
47 {
48 }
currently selected items overlay
Definition: layer_ids.h:226

◆ ~VIEW_GROUP()

VIEW_GROUP::~VIEW_GROUP ( )
virtual

Definition at line 51 of file view_group.cpp.

52 {
53  // VIEW_ITEM destructor removes the object from its parent view
54 }

Member Function Documentation

◆ Add()

void VIEW_GROUP::Add ( VIEW_ITEM aItem)
virtual

◆ Clear()

void VIEW_GROUP::Clear ( )
virtual

Remove all the stored items from the group.

Reimplemented in SELECTION.

Definition at line 69 of file view_group.cpp.

70 {
71  m_groupItems.clear();
72 }
std::vector< VIEW_ITEM * > m_groupItems
Definition: view_group.h:113

References m_groupItems.

Referenced by PCB_SELECTION_TOOL::ExitGroup(), FreeItems(), BOARD_EDITOR_CONTROL::PlaceTarget(), and PCB_SELECTION_TOOL::RebuildSelection().

◆ ClearViewPrivData()

void KIGFX::VIEW_ITEM::ClearViewPrivData ( )
inlineinherited

Definition at line 143 of file view_item.h.

144  {
145  m_viewPrivData = nullptr;
146  }
VIEW_ITEM_DATA * m_viewPrivData
Definition: view_item.h:151

References KIGFX::VIEW_ITEM::m_viewPrivData.

Referenced by KIGFX::VIEW::OnDestroy().

◆ FreeItems()

void VIEW_GROUP::FreeItems ( )

Free all the items that were added to the group.

Definition at line 196 of file view_group.cpp.

197 {
198  for( unsigned int i = 0 ; i < GetSize(); i++ )
199  delete GetItem( i );
200 
201  Clear();
202 }
virtual void Clear()
Remove all the stored items from the group.
Definition: view_group.cpp:69
virtual VIEW_ITEM * GetItem(unsigned int aIdx) const
Definition: view_group.cpp:81
virtual unsigned int GetSize() const
Return the number of stored items.
Definition: view_group.cpp:75

References Clear(), GetItem(), and GetSize().

Referenced by PNS_PCBNEW_DEBUG_DECORATOR::Clear(), PNS_KICAD_IFACE::EraseView(), PNS_KICAD_IFACE::SetView(), and PNS_KICAD_IFACE::~PNS_KICAD_IFACE().

◆ Get() [1/3]

wxAny INSPECTABLE::Get ( PROPERTY_BASE aProperty)
inlineinherited

Definition at line 86 of file inspectable.h.

87  {
89  TYPE_ID thisType = TYPE_HASH( *this );
90  void* object = propMgr.TypeCast( this, thisType, aProperty->OwnerHash() );
91  return object ? aProperty->getter( object ) : wxAny();
92  }
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:65
#define TYPE_HASH(x)
Definition: property.h:59
size_t TYPE_ID
Unique type identifier.
Definition: property_mgr.h:42
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Cast a type to another type.
virtual wxAny getter(void *aObject) const =0
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:62
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.

References PROPERTY_BASE::getter(), PROPERTY_MANAGER::Instance(), PROPERTY_BASE::OwnerHash(), TYPE_HASH, and PROPERTY_MANAGER::TypeCast().

Referenced by BOOST_AUTO_TEST_CASE(), CLASS_D_DESC::CLASS_D_DESC(), PCB_EXPR_VAR_REF::GetValue(), and PAD_DESC::PAD_DESC().

◆ Get() [2/3]

template<typename T >
T INSPECTABLE::Get ( PROPERTY_BASE aProperty)
inlineinherited

Definition at line 95 of file inspectable.h.

96  {
98  TYPE_ID thisType = TYPE_HASH( *this );
99  void* object = propMgr.TypeCast( this, thisType, aProperty->OwnerHash() );
100  return object ? aProperty->get<T>( object ) : T();
101  }
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:65
#define TYPE_HASH(x)
Definition: property.h:59
size_t TYPE_ID
Unique type identifier.
Definition: property_mgr.h:42
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Cast a type to another type.
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:62
T get(void *aObject)
Definition: property.h:268
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.

References PROPERTY_BASE::get(), PROPERTY_MANAGER::Instance(), PROPERTY_BASE::OwnerHash(), TYPE_HASH, and PROPERTY_MANAGER::TypeCast().

◆ Get() [3/3]

template<typename T >
boost::optional<T> INSPECTABLE::Get ( const wxString &  aProperty)
inlineinherited

Definition at line 104 of file inspectable.h.

105  {
107  TYPE_ID thisType = TYPE_HASH( *this );
108  PROPERTY_BASE* prop = propMgr.GetProperty( thisType, aProperty );
109  boost::optional<T> ret = T();
110 
111  if( prop )
112  {
113  void* object = propMgr.TypeCast( this, thisType, prop->OwnerHash() );
114 
115  if( object )
116  ret = prop->get<T>( object );
117  }
118 
119  return ret;
120  }
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:65
#define TYPE_HASH(x)
Definition: property.h:59
size_t TYPE_ID
Unique type identifier.
Definition: property_mgr.h:42
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Cast a type to another type.
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Return a property for a specific type.
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:62
T get(void *aObject)
Definition: property.h:268
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.

References PROPERTY_BASE::get(), PROPERTY_MANAGER::GetProperty(), PROPERTY_MANAGER::Instance(), PROPERTY_BASE::OwnerHash(), TYPE_HASH, and PROPERTY_MANAGER::TypeCast().

◆ GetItem()

VIEW_ITEM * VIEW_GROUP::GetItem ( unsigned int  aIdx) const
virtual

Reimplemented in SELECTION.

Definition at line 81 of file view_group.cpp.

82 {
83  return m_groupItems[idx];
84 }
std::vector< VIEW_ITEM * > m_groupItems
Definition: view_group.h:113

References m_groupItems.

Referenced by KIGFX::VIEW::draw(), and FreeItems().

◆ GetSize()

unsigned int VIEW_GROUP::GetSize ( ) const
virtual

Return the number of stored items.

Reimplemented in SELECTION.

Definition at line 75 of file view_group.cpp.

76 {
77  return m_groupItems.size();
78 }
std::vector< VIEW_ITEM * > m_groupItems
Definition: view_group.h:113

References m_groupItems.

Referenced by KIGFX::VIEW::draw(), and FreeItems().

◆ Remove()

void VIEW_GROUP::Remove ( VIEW_ITEM aItem)
virtual

Remove an item from the group.

Definition at line 63 of file view_group.cpp.

64 {
66 }
std::vector< VIEW_ITEM * > m_groupItems
Definition: view_group.h:113
void delete_matching(_Container &__c, _Value __value)
Covers for the horrifically named std::remove and std::remove_if (neither of which remove anything).
Definition: kicad_algo.h:164

References alg::delete_matching(), and m_groupItems.

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), and BOARD_EDITOR_CONTROL::PlaceTarget().

◆ Set() [1/3]

bool INSPECTABLE::Set ( PROPERTY_BASE aProperty,
wxAny &  aValue 
)
inlineinherited

Definition at line 42 of file inspectable.h.

43  {
45  TYPE_ID thisType = TYPE_HASH( *this );
46  void* object = propMgr.TypeCast( this, thisType, aProperty->OwnerHash() );
47 
48  if( object )
49  aProperty->setter( object, aValue );
50 
51  return object != nullptr;
52  }
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:65
#define TYPE_HASH(x)
Definition: property.h:59
size_t TYPE_ID
Unique type identifier.
Definition: property_mgr.h:42
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Cast a type to another type.
virtual void setter(void *aObject, wxAny &aValue)=0
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:62
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.

References PROPERTY_MANAGER::Instance(), PROPERTY_BASE::OwnerHash(), PROPERTY_BASE::setter(), TYPE_HASH, and PROPERTY_MANAGER::TypeCast().

◆ Set() [2/3]

template<typename T >
bool INSPECTABLE::Set ( PROPERTY_BASE aProperty,
aValue 
)
inlineinherited

Definition at line 55 of file inspectable.h.

56  {
58  TYPE_ID thisType = TYPE_HASH( *this );
59  void* object = propMgr.TypeCast( this, thisType, aProperty->OwnerHash() );
60 
61  if( object )
62  aProperty->set<T>( object, aValue );
63 
64  return object != nullptr;
65  }
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:65
#define TYPE_HASH(x)
Definition: property.h:59
size_t TYPE_ID
Unique type identifier.
Definition: property_mgr.h:42
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Cast a type to another type.
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:62
void set(void *aObject, T aValue)
Definition: property.h:261
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.

References PROPERTY_MANAGER::Instance(), PROPERTY_BASE::OwnerHash(), PROPERTY_BASE::set(), TYPE_HASH, and PROPERTY_MANAGER::TypeCast().

◆ Set() [3/3]

template<typename T >
bool INSPECTABLE::Set ( const wxString &  aProperty,
aValue 
)
inlineinherited

Definition at line 68 of file inspectable.h.

69  {
71  TYPE_ID thisType = TYPE_HASH( *this );
72  PROPERTY_BASE* prop = propMgr.GetProperty( thisType, aProperty );
73  void* object = nullptr;
74 
75  if( prop )
76  {
77  object = propMgr.TypeCast( this, thisType, prop->OwnerHash() );
78 
79  if( object )
80  prop->set<T>( object, aValue );
81  }
82 
83  return object != nullptr;
84  }
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:65
#define TYPE_HASH(x)
Definition: property.h:59
size_t TYPE_ID
Unique type identifier.
Definition: property_mgr.h:42
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Cast a type to another type.
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Return a property for a specific type.
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:62
void set(void *aObject, T aValue)
Definition: property.h:261
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.

References PROPERTY_MANAGER::GetProperty(), PROPERTY_MANAGER::Instance(), PROPERTY_BASE::OwnerHash(), PROPERTY_BASE::set(), TYPE_HASH, and PROPERTY_MANAGER::TypeCast().

◆ SetLayer()

virtual void KIGFX::VIEW_GROUP::SetLayer ( int  aLayer)
inlinevirtual

Set layer used to draw the group.

Definition at line 98 of file view_group.h.

99  {
100  m_layer = aLayer;
101  }

References m_layer.

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PCB_SELECTION_TOOL::doSelectionMenu(), PNS_KICAD_IFACE::SetView(), and PNS_PCBNEW_DEBUG_DECORATOR::SetView().

◆ updateDrawList()

const std::vector< VIEW_ITEM * > VIEW_GROUP::updateDrawList ( ) const
protectedvirtual

Reimplemented in SELECTION, and PCB_SELECTION.

Definition at line 205 of file view_group.cpp.

206 {
207  return m_groupItems;
208 }
std::vector< VIEW_ITEM * > m_groupItems
Definition: view_group.h:113

References m_groupItems.

Referenced by ViewDraw().

◆ ViewBBox()

const BOX2I VIEW_GROUP::ViewBBox ( ) const
overridevirtual

Return the bounding box for all stored items covering all its layers.

Implements KIGFX::VIEW_ITEM.

Reimplemented in SELECTION, and GERBVIEW_SELECTION.

Definition at line 87 of file view_group.cpp.

88 {
89  BOX2I bb;
90 
91  if( !m_groupItems.size() )
92  {
93  bb.SetMaximum();
94  }
95  else
96  {
97  bb = m_groupItems[0]->ViewBBox();
98 
99  for( VIEW_ITEM* item : m_groupItems )
100  bb.Merge( item->ViewBBox() );
101  }
102 
103  return bb;
104 }
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:76
A 2D bounding box built on top of an origin point and size vector.
Definition: box2.h:41
void SetMaximum()
Definition: box2.h:57
std::vector< VIEW_ITEM * > m_groupItems
Definition: view_group.h:113
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:363

References m_groupItems, BOX2< Vec >::Merge(), and BOX2< Vec >::SetMaximum().

◆ ViewDraw()

void VIEW_GROUP::ViewDraw ( int  aLayer,
VIEW aView 
) const
overridevirtual

Draw all the stored items in the group on the given layer.

Parameters
aLayeris the layer which should be drawn.
aViewis the VIEW that should be used for drawing.

Reimplemented from KIGFX::VIEW_ITEM.

Definition at line 107 of file view_group.cpp.

108 {
109  KIGFX::GAL* gal = aView->GetGAL();
110  PAINTER* painter = aView->GetPainter();
111  bool isSelection = m_layer == LAYER_SELECT_OVERLAY;
112 
113  const std::vector<VIEW_ITEM*> drawList = updateDrawList();
114 
115  std::unordered_map<int, std::vector<VIEW_ITEM*>> layer_item_map;
116 
117  // Build a list of layers used by the items in the group
118  for( VIEW_ITEM* item : drawList )
119  {
120  int item_layers[VIEW::VIEW_MAX_LAYERS], item_layers_count;
121  item->ViewGetLayers( item_layers, item_layers_count );
122 
123  for( int i = 0; i < item_layers_count; i++ )
124  {
125  if( layer_item_map.count( item_layers[i] ) == 0 )
126  {
127  layer_item_map.emplace( std::make_pair( item_layers[i],
128  std::vector<VIEW_ITEM*>() ) );
129  }
130 
131  layer_item_map[ item_layers[i] ].push_back( item );
132  }
133  }
134 
135  int layers[VIEW::VIEW_MAX_LAYERS] = { 0 };
136  int layers_count = 0;
137 
138  for( const std::pair<const int, std::vector<VIEW_ITEM*>>& entry : layer_item_map )
139  layers[ layers_count++ ] = entry.first;
140 
141  aView->SortLayers( layers, layers_count );
142 
143  // Now draw the layers in sorted order
144 
145  gal->PushDepth();
146 
147  for( int i = 0; i < layers_count; i++ )
148  {
149  int layer = layers[i];
150 
151  if( IsZoneLayer( layer ) )
152  layer = layer - LAYER_ZONE_START;
153 
154  bool draw = aView->IsLayerVisible( layer );
155 
156  if( isSelection )
157  {
158  switch( layer )
159  {
160  case LAYER_PADS_TH:
162  case LAYER_PAD_HOLEWALLS:
163  case LAYER_PAD_FR:
164  case LAYER_PAD_BK:
165  draw = true;
166  break;
167  default:
168  break;
169  }
170  }
171 
172  if( draw )
173  {
174  gal->AdvanceDepth();
175 
176  for( VIEW_ITEM* item : layer_item_map[ layers[i] ] )
177  {
178  if( !painter->Draw( item, layers[i] ) )
179  item->ViewDraw( layers[i], aView ); // Alternative drawing method
180  }
181  }
182  }
183 
184  gal->PopDepth();
185 }
currently selected items overlay
Definition: layer_ids.h:226
smd pads, front layer
Definition: layer_ids.h:209
smd pads, back layer
Definition: layer_ids.h:210
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:190
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:76
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:208
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:711
void SortLayers(int aLayers[], int &aCount) const
Change the order of given layer ids, so after sorting the order corresponds to layers rendering order...
Definition: view.cpp:649
Contains all the knowledge about how to draw graphical object onto any particular output device.
Definition: painter.h:57
void PopDepth()
Restore previously stored drawing depth for the depth stack.
Virtual layers for stacking zones and tracks on a given copper layer.
Definition: layer_ids.h:253
virtual const std::vector< VIEW_ITEM * > updateDrawList() const
Definition: view_group.cpp:205
virtual bool Draw(const VIEW_ITEM *aItem, int aLayer)=0
Takes an instance of VIEW_ITEM and passes it to a function that knows how to draw the item.
void PushDepth()
Store current drawing depth on the depth stack.
multilayer pads, usually with holes
Definition: layer_ids.h:220
to draw pad holes (plated)
Definition: layer_ids.h:221
bool IsZoneLayer(LAYER_NUM aLayer)
Definition: layer_ids.h:983
void AdvanceDepth()
Change the current depth to deeper, so it is possible to draw objects right beneath other.
Abstract interface for drawing on a 2D-surface.
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:405

References KIGFX::GAL::AdvanceDepth(), KIGFX::PAINTER::Draw(), KIGFX::VIEW::GetGAL(), KIGFX::VIEW::GetPainter(), KIGFX::VIEW::IsLayerVisible(), IsZoneLayer(), LAYER_PAD_BK, LAYER_PAD_FR, LAYER_PAD_HOLEWALLS, LAYER_PAD_PLATEDHOLES, LAYER_PADS_TH, LAYER_SELECT_OVERLAY, LAYER_ZONE_START, m_layer, KIGFX::GAL::PopDepth(), KIGFX::GAL::PushDepth(), KIGFX::VIEW::SortLayers(), updateDrawList(), and KIGFX::VIEW::VIEW_MAX_LAYERS.

◆ ViewGetLayers()

void VIEW_GROUP::ViewGetLayers ( int  aLayers[],
int &  aCount 
) const
overridevirtual

Return all the layers used by the stored items.

Parameters
aLayers[]is the output layer index array.
aCountis the number of layer indices in aLayers[].

Implements KIGFX::VIEW_ITEM.

Definition at line 188 of file view_group.cpp.

189 {
190  // Everything is displayed on a single layer
191  aLayers[0] = m_layer;
192  aCount = 1;
193 }

References m_layer.

◆ ViewGetLOD()

virtual double KIGFX::VIEW_ITEM::ViewGetLOD ( int  aLayer,
VIEW aView 
) const
inlinevirtualinherited

Return the level of detail (LOD) of the item.

A level of detail is the minimal VIEW scale that is sufficient for an item to be shown on a given layer.

Parameters
aLayeris the current drawing layer.
aViewis a pointer to the VIEW device we are drawing on.
Returns
the level of detail. 0 always show the item, because the actual zoom level (or VIEW scale) is always > 0

Reimplemented in FP_ZONE, PAD, FOOTPRINT, PCB_VIA, GERBER_DRAW_ITEM, FP_TEXT, PCB_TRACK, ZONE, PCB_GROUP, and FP_SHAPE.

Definition at line 132 of file view_item.h.

133  {
134  // By default always show the item
135  return 0.0;
136  }

Referenced by PNS_KICAD_IFACE::IsItemVisible(), KIGFX::VIEW::DRAW_ITEM_VISITOR::operator()(), EE_GRID_HELPER::queryVisible(), PCB_GRID_HELPER::queryVisible(), and PCB_SELECTION_TOOL::Selectable().

◆ viewPrivData()

Member Data Documentation

◆ m_groupItems

std::vector<VIEW_ITEM*> KIGFX::VIEW_GROUP::m_groupItems
protected

Definition at line 113 of file view_group.h.

Referenced by Add(), Clear(), GetItem(), GetSize(), Remove(), updateDrawList(), and ViewBBox().

◆ m_layer

int KIGFX::VIEW_GROUP::m_layer
protected

Definition at line 112 of file view_group.h.

Referenced by SetLayer(), ViewDraw(), and ViewGetLayers().


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