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=NULL)
 
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 Types

typedef std::vector< VIEW_ITEM * > ITEMS
 

Protected Member Functions

virtual const ITEMS updateDrawList () const
 Layer on which the group is drawn. More...
 

Protected Attributes

int m_layer
 Container for storing VIEW_ITEMs. More...
 
ITEMS 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.

Member Typedef Documentation

◆ ITEMS

typedef std::vector<VIEW_ITEM*> KIGFX::VIEW_GROUP::ITEMS
protected

Definition at line 119 of file view_group.h.

Constructor & Destructor Documentation

◆ VIEW_GROUP()

VIEW_GROUP::VIEW_GROUP ( VIEW aView = NULL)

Definition at line 43 of file view_group.cpp.

43  :
44  VIEW_ITEM(),
46 {
47 }
int m_layer
Container for storing VIEW_ITEMs.
Definition: view_group.h:124
currently selected items overlay

◆ ~VIEW_GROUP()

VIEW_GROUP::~VIEW_GROUP ( )
virtual

Definition at line 50 of file view_group.cpp.

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

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 75 of file view_group.cpp.

76 {
77  m_groupItems.clear();
78 }

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 148 of file view_item.h.

149  {
150  m_viewPrivData = nullptr;
151  }
VIEW_ITEM_DATA * m_viewPrivData
Definition: view_item.h:156

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 197 of file view_group.cpp.

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

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 84 of file inspectable.h.

85  {
87  TYPE_ID thisType = TYPE_HASH( *this );
88  void* object = propMgr.TypeCast( this, thisType, aProperty->OwnerHash() );
89  return object ? aProperty->getter( object ) : wxAny();
90  }
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:64
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:56
size_t TYPE_ID
Unique type identifier
Definition: property_mgr.h:41
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Casts a type to another type.
virtual wxAny getter(void *aObject) const =0
Provides class metadata.
Definition: property_mgr.h:61
virtual size_t OwnerHash() const =0
Returns type-id of the Owner class.

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

Referenced by 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 93 of file inspectable.h.

94  {
96  TYPE_ID thisType = TYPE_HASH( *this );
97  void* object = propMgr.TypeCast( this, thisType, aProperty->OwnerHash() );
98  return object ? aProperty->get<T>( object ) : T();
99  }
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:64
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:56
size_t TYPE_ID
Unique type identifier
Definition: property_mgr.h:41
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Casts a type to another type.
Provides class metadata.
Definition: property_mgr.h:61
T get(void *aObject)
Definition: property.h:265
virtual size_t OwnerHash() const =0
Returns 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 102 of file inspectable.h.

103  {
105  TYPE_ID thisType = TYPE_HASH( *this );
106  PROPERTY_BASE* prop = propMgr.GetProperty( thisType, aProperty );
107  boost::optional<T> ret;
108 
109  if( prop )
110  {
111  void* object = propMgr.TypeCast( this, thisType, prop->OwnerHash() );
112 
113  if( object )
114  ret = prop->get<T>( object );
115  }
116 
117  return ret;
118  }
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:64
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:56
size_t TYPE_ID
Unique type identifier
Definition: property_mgr.h:41
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Casts a type to another type.
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Returns a property for a specific type.
Provides class metadata.
Definition: property_mgr.h:61
T get(void *aObject)
Definition: property.h:265
virtual size_t OwnerHash() const =0
Returns 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 87 of file view_group.cpp.

88 {
89  return m_groupItems[idx];
90 }

References m_groupItems.

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

◆ GetSize()

unsigned int VIEW_GROUP::GetSize ( ) const
virtual

Return the number of stored items.

Returns
Number of stored items.

Reimplemented in SELECTION.

Definition at line 81 of file view_group.cpp.

82 {
83  return m_groupItems.size();
84 }

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.

Parameters
aItemis the item to be removed.

Definition at line 62 of file view_group.cpp.

63 {
64  for( auto iter = m_groupItems.begin(); iter != m_groupItems.end(); ++iter )
65  {
66  if( aItem == *iter )
67  {
68  m_groupItems.erase( iter );
69  break;
70  }
71  }
72 }

References 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 40 of file inspectable.h.

41  {
43  TYPE_ID thisType = TYPE_HASH( *this );
44  void* object = propMgr.TypeCast( this, thisType, aProperty->OwnerHash() );
45 
46  if( object )
47  aProperty->setter( object, aValue );
48 
49  return object != nullptr;
50  }
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:64
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:56
size_t TYPE_ID
Unique type identifier
Definition: property_mgr.h:41
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Casts a type to another type.
virtual void setter(void *aObject, wxAny &aValue)=0
Provides class metadata.
Definition: property_mgr.h:61
virtual size_t OwnerHash() const =0
Returns 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 53 of file inspectable.h.

54  {
56  TYPE_ID thisType = TYPE_HASH( *this );
57  void* object = propMgr.TypeCast( this, thisType, aProperty->OwnerHash() );
58 
59  if( object )
60  aProperty->set<T>( object, aValue );
61 
62  return object != nullptr;
63  }
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:64
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:56
size_t TYPE_ID
Unique type identifier
Definition: property_mgr.h:41
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Casts a type to another type.
Provides class metadata.
Definition: property_mgr.h:61
void set(void *aObject, T aValue)
Definition: property.h:258
virtual size_t OwnerHash() const =0
Returns 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 66 of file inspectable.h.

67  {
69  TYPE_ID thisType = TYPE_HASH( *this );
70  PROPERTY_BASE* prop = propMgr.GetProperty( thisType, aProperty );
71  void* object = nullptr;
72 
73  if( prop )
74  {
75  object = propMgr.TypeCast( this, thisType, prop->OwnerHash() );
76 
77  if( object )
78  prop->set<T>( object, aValue );
79  }
80 
81  return object != nullptr;
82  }
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:64
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:56
size_t TYPE_ID
Unique type identifier
Definition: property_mgr.h:41
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Casts a type to another type.
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Returns a property for a specific type.
Provides class metadata.
Definition: property_mgr.h:61
void set(void *aObject, T aValue)
Definition: property.h:258
virtual size_t OwnerHash() const =0
Returns 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.

Parameters
aLayeris the layer used for drawing.

Definition at line 108 of file view_group.h.

109  {
110  m_layer = aLayer;
111  }
int m_layer
Container for storing VIEW_ITEMs.
Definition: view_group.h:124

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 VIEW_GROUP::ITEMS VIEW_GROUP::updateDrawList ( ) const
protectedvirtual

Layer on which the group is drawn.

Reimplemented in SELECTION, and PCB_SELECTION.

Definition at line 206 of file view_group.cpp.

207 {
208  return m_groupItems;
209 }

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.

Returns
The current bounding box

Implements KIGFX::VIEW_ITEM.

Reimplemented in SELECTION, and GERBVIEW_SELECTION.

Definition at line 93 of file view_group.cpp.

94 {
95  BOX2I bb;
96 
97  if( !m_groupItems.size() )
98  {
99  bb.SetMaximum();
100  }
101  else
102  {
103  bb = m_groupItems[0]->ViewBBox();
104 
105  for( auto item : m_groupItems )
106  bb.Merge( item->ViewBBox() );
107  }
108 
109  return bb;
110 }
void SetMaximum()
Definition: box2.h:73
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect.
Definition: box2.h:386

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 113 of file view_group.cpp.

114 {
115  KIGFX::GAL* gal = aView->GetGAL();
116  PAINTER* painter = aView->GetPainter();
117  bool isSelection = m_layer == LAYER_SELECT_OVERLAY;
118 
119  const std::vector<VIEW_ITEM*> drawList = updateDrawList();
120 
121  std::unordered_map<int, std::vector<VIEW_ITEM*>> layer_item_map;
122 
123  // Build a list of layers used by the items in the group
124  for( VIEW_ITEM* item : drawList )
125  {
126  int item_layers[VIEW::VIEW_MAX_LAYERS], item_layers_count;
127  item->ViewGetLayers( item_layers, item_layers_count );
128 
129  for( int i = 0; i < item_layers_count; i++ )
130  {
131  if( layer_item_map.count( item_layers[i] ) == 0 )
132  {
133  layer_item_map.emplace( std::make_pair( item_layers[i],
134  std::vector<VIEW_ITEM*>() ) );
135  }
136 
137  layer_item_map[ item_layers[i] ].push_back( item );
138  }
139  }
140 
141  int layers[VIEW::VIEW_MAX_LAYERS] = { 0 };
142  int layers_count = 0;
143 
144  for( const std::pair<const int, std::vector<VIEW_ITEM*>>& entry : layer_item_map )
145  layers[ layers_count++ ] = entry.first;
146 
147  aView->SortLayers( layers, layers_count );
148 
149  // Now draw the layers in sorted order
150 
151  gal->PushDepth();
152 
153  for( int i = 0; i < layers_count; i++ )
154  {
155  int layer = layers[i];
156  bool draw = aView->IsLayerVisible( layer );
157 
158  if( isSelection )
159  {
160  switch( layer )
161  {
162  case LAYER_PADS_TH:
164  case LAYER_PAD_FR:
165  case LAYER_PAD_BK:
166  draw = true;
167  break;
168  default:
169  break;
170  }
171  }
172 
173  if( draw )
174  {
175  gal->AdvanceDepth();
176 
177  for( VIEW_ITEM* item : layer_item_map[ layers[i] ] )
178  {
179  if( !painter->Draw( item, layers[i] ) )
180  item->ViewDraw( layers[i], aView ); // Alternative drawing method
181  }
182  }
183  }
184 
185  gal->PopDepth();
186 }
multilayer pads, usually with holes
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:81
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:207
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:696
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:659
virtual const ITEMS updateDrawList() const
Layer on which the group is drawn.
Definition: view_group.cpp:206
Contains all the knowledge about how to draw graphical object onto any particular output device.
Definition: painter.h:57
void PopDepth()
Restores previously stored drawing depth for the depth stack.
int m_layer
Container for storing VIEW_ITEMs.
Definition: view_group.h:124
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()
Stores current drawing depth on the depth stack.
smd pads, front layer
currently selected items overlay
void AdvanceDepth()
Changes the current depth to deeper, so it is possible to draw objects right beneath other.
Class GAL is the abstract interface for drawing on a 2D-surface.
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:404

References KIGFX::GAL::AdvanceDepth(), KIGFX::PAINTER::Draw(), KIGFX::VIEW::GetGAL(), KIGFX::VIEW::GetPainter(), KIGFX::VIEW::IsLayerVisible(), LAYER_PAD_BK, LAYER_PAD_FR, LAYER_PADS_PLATEDHOLES, LAYER_PADS_TH, LAYER_SELECT_OVERLAY, 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 189 of file view_group.cpp.

190 {
191  // Everything is displayed on a single layer
192  aLayers[0] = m_layer;
193  aCount = 1;
194 }
int m_layer
Container for storing VIEW_ITEMs.
Definition: view_group.h:124

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, VIA, GERBER_DRAW_ITEM, FP_TEXT, TRACK, ZONE, PCB_GROUP, and FP_SHAPE.

Definition at line 137 of file view_item.h.

138  {
139  // By default always show the item
140  return 0.0;
141  }

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

◆ viewPrivData()

Member Data Documentation

◆ m_groupItems

ITEMS KIGFX::VIEW_GROUP::m_groupItems
protected

Definition at line 127 of file view_group.h.

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

◆ m_layer

int KIGFX::VIEW_GROUP::m_layer
protected

Container for storing VIEW_ITEMs.

Definition at line 124 of file view_group.h.

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


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