46#include <unordered_map>
47#include <unordered_set>
52#ifdef KICAD_GAL_PROFILE
123 std::pair<int, int>* newGroups =
new std::pair<int, int>[
m_groupsSize + 1];
167 auto it = aReorderMap.find(
m_groups[i].first );
169 if( it != aReorderMap.end() )
183 for(
int layer : aLayers )
186 wxString::Format( wxT(
"Invalid layer number: %d" ), layer ) );
242 bool aUseDrawPriority,
bool aReverseDrawOrder,
246 key.
priority = aUseDrawPriority ? ( aReverseDrawOrder ? -int64_t( aPriority ) : int64_t( aPriority ) ) : 0;
250 key.
lodScale = std::isnan( aLodScale ) ? std::numeric_limits<double>::infinity() : aLodScale;
259 std::sort( aEntries.begin(), aEntries.end(), [](
const T& a,
const T& b )
261 return a.order < b.order;
264 for(
size_t first = 0; first < aEntries.size(); )
266 size_t last = first + 1;
268 while( last < aEntries.size() && aEntries[first].order.SamePrefix( aEntries[last].order ) )
271 if( last - first > 1 )
273 for(
size_t i = first; i < last; ++i )
275 T& entry = aEntries[i];
277 entry.order.contentTie =
true;
280 std::sort( aEntries.begin() + first, aEntries.begin() + last,
281 [](
const T& a,
const T& b ) { return a.order < b.order; } );
321 typedef std::numeric_limits<int> coord_limits;
322 double pos = coord_limits::lowest() / 2 + coord_limits::epsilon();
323 double size = coord_limits::max() - coord_limits::epsilon();
327 m_allItems.reset(
new std::vector<VIEW_ITEM*> );
342 l.
items = std::make_shared<VIEW_RTREE>();
367 if( aDrawPriority < 0 )
376 previous->unlinkItem( aItem );
387 std::erase_if( layers, [](
int layer )
399 for(
int layer : layers )
402 l.
items->Insert( aItem, bbox );
417 std::unordered_map<int, std::vector<std::pair<VIEW_ITEM*, BOX2I>>> layerBulk;
418 std::unordered_set<VIEW_ITEM*> seen;
421 seen.reserve( aItems.size() );
428 if( !item || !seen.insert( item ).second )
433 if( !item->m_viewPrivData )
437 if(
VIEW* previous = item->m_viewPrivData->m_view )
438 previous->unlinkItem( item );
440 item->m_viewPrivData->
m_view =
this;
441 item->m_viewPrivData->m_pendingIndex = -1;
442 item->m_viewPrivData->m_drawPriority = drawPriority;
443 const BOX2I bbox = item->ViewBBox();
444 item->m_viewPrivData->m_bbox = bbox;
445 item->m_viewPrivData->m_cachedIndex =
m_allItems->size();
447 std::vector<int> layers = item->ViewGetLayers();
449 std::erase_if( layers, [](
int layer )
457 item->viewPrivData()->saveLayers( layers );
461 for(
int layer : layers )
462 layerBulk[layer].emplace_back( item, bbox );
466 for(
auto& [layerId, items] : layerBulk )
469 l.
items->BulkLoad( items );
473 if( !aItems.empty() )
496 static int s_gcCounter = 0;
505 std::vector<VIEW_ITEM*>::iterator item =
m_allItems->end();
509 && cachedIndex <
static_cast<ssize_t
>(
m_allItems->size() )
532 if( s_gcCounter > 4096 )
538 return it ==
nullptr;
542 for(
size_t idx = 0; idx <
m_allItems->size(); idx++ )
543 ( *
m_allItems )[idx]->m_viewPrivData->m_cachedIndex = idx;
554 l.
items->Remove( aItem, bbox );
561 m_gal->DeleteGroup( prevGroup );
575 wxCHECK( (
unsigned) aLayerId <
m_layers.size(), );
576 wxCHECK( (
unsigned) aRequiredId <
m_layers.size(), );
578 std::set<int>& required =
m_layers[aLayerId].requiredLayers;
579 const bool changed = aRequired ? required.insert( aRequiredId ).second : required.erase( aRequiredId ) > 0;
616 std::vector<bool>& readers =
m_lodReads[aLayer];
618 if( readers.empty() )
635 for(
const auto& [
id, l] :
m_layers )
639 m_gal->SetSceneLayerState(
id, l.renderingOrder, drawn, l.hasNegatives );
645 m_gal->SetSceneLayerDim(
id, toward, keep );
663 if( !
m_gal->IsVisible() || !
m_gal->IsInitialized() )
684 if( it->second[reader] )
685 readers[reader] =
true;
699 const int layer = id;
701 auto place = [&](
VIEW_ITEM* aItem ) ->
bool
707 l.items->Query( everywhere, place );
717 m_gal->MarkStaticDirty();
721 if(
m_gal->HasRetainedScene() )
756 std::vector<VIEW_LAYER*>::const_reverse_iterator i;
763 if( ( *i )->displayOnly || !( *i )->visible )
767 ( *i )->items->Query( aRect, visitor );
770 return aResult.size();
782 if( i->displayOnly || !i->visible )
785 i->items->Query( aRect, aFunc );
805 return fabs( matrix.
GetScale().
x * aSize );
830 wxASSERT_MSG(
false, wxT(
"This is not implemented" ) );
836 bool recacheGroups = (
m_gal != nullptr );
868 return rect.Normalize();
876 wxCHECK( fabs(ssize.
x) > 0 && fabs(ssize.
y) > 0, );
880 double zoom = 1.0 / std::max( fabs( vsize.
x / ssize.
x ), fabs( vsize.
y / ssize.
y ) );
889 wxASSERT_MSG( !aMirrorY,
_(
"Mirroring for Y axis is not supported yet" ) );
893 m_gal->SetFlip( aMirrorX, aMirrorY );
906 const double oldScale =
m_scale;
916 m_gal->ComputeWorldScreenMatrix();
988 m_gal->ComputeWorldScreenMatrix();
997 if( obscuringScreenRects.empty() )
1000 BOX2D screenRect( { 0, 0 },
m_gal->GetScreenPixelSize() );
1004 for(
const BOX2D& obscuringScreenRect : obscuringScreenRects )
1020 while( !unobscuredPoly.
IsEmpty() )
1022 unobscuredCenter = unobscuredPoly.
BBox().
Centre();
1032 m_layers[aLayer].renderingOrder = aRenderingOrder;
1041 return m_layers.at( aLayer ).renderingOrder;
1047 std::sort( aLayers.begin(), aLayers.end(),
1048 [
this](
int a,
int b )
1050 return GetLayerOrder( a ) > GetLayerOrder( b );
1059 std::map<int, VIEW_LAYER>
moved;
1060 std::unordered_set<int> destinations;
1062 for(
const auto& [from, to] : aReorderMap )
1073 destinations.insert( to );
1077 for(
const auto& [from, layer] :
moved )
1079 auto destination =
m_layers.find( aReorderMap.at( from ) );
1081 destination->second = layer;
1082 destination->second.id = destination->first;
1087 for(
const auto& [from,
_] :
moved )
1089 if( !destinations.count( from ) )
1090 m_layers.find( from )->second.items = std::make_shared<VIEW_RTREE>();
1112 std::vector<int> layers = item->ViewGetLayers();
1139 if(
m_gal->IsVisible() )
1145 std::vector<std::pair<VIEW_ITEM*, int>> groups;
1149 if(
int group = aItem->viewPrivData()->getGroup( aLayer );
group >= 0 )
1150 groups.emplace_back( aItem,
group );
1155 m_layers[aLayer].items->Query( r, collect );
1158 for(
const auto& [item,
group] : groups )
1201 if(
m_gal->IsVisible() )
1217 for(
int layer : viewData->
m_layers )
1219 if( aLayers && !aLayers( layer ) )
1227 if(
group >= 0 && aReplace )
1281 std::set<unsigned int>::iterator it;
1301 std::set<unsigned int>::iterator it;
1319 if(
m_gal->IsVisible() && !
m_gal->HasRetainedScene() )
1335 for(
int layer : viewData->
m_layers )
1387 view->noteKeptLod( itemLOD );
1392 if( !drawCondition )
1407 std::vector<VIEW::LAYER_ITEM_PAIR> items;
1411 items.emplace_back( item,
layer );
1413 view->placeRetainedInOrder( items,
false );
1422 return b->viewPrivData()->m_drawPriority
1423 < a->viewPrivData()->m_drawPriority;
1431 return a->viewPrivData()->m_drawPriority
1432 < b->viewPrivData()->m_drawPriority;
1452 std::vector<RETAINED_ORDER_ITEM> ordered;
1453 ordered.reserve( aItems.size() );
1455 for(
const auto& [item, layer] : aItems )
1465 ordered.push_back( { item, layer, data->
getGroup( layer ),
1499 if( viewData->
getGroup( aLayer ) < 0 )
1521 m_gal->SetGroupPlacement(
group, aLayer, lod,
1529 const double lod = aItem->
ViewGetLOD( aLayer,
this );
1539 const bool retained =
m_gal &&
m_gal->HasRetainedScene();
1554 if( l->items->IsEmpty() )
1557 const bool placing = retained && l->target ==
TARGET_CACHED;
1565 const bool targetDirty = placing ?
m_gal->HasStaticRebuildPending()
1568 &&
m_gal->HasStaticRebuildPending() ) );
1575 m_gal->SetTarget( l->target );
1576 m_gal->SetLayerDepth( l->renderingOrder );
1581 m_gal->StartDiffLayer();
1582 else if( l->hasNegatives )
1583 m_gal->StartNegativesLayer();
1588 m_gal->BeginSceneLayer( l->id );
1597 m_gal->TakeWorldScaleRead();
1599 double below, above;
1600 m_gal->TakeWorldScaleLimits( below, above );
1603 l->items->Query( aRect, drawFunc );
1614 if( kept &&
m_gal->GetWorldScaleForScreenSpace() > 0.0 )
1616 const double toView =
m_scale /
m_gal->GetWorldScaleForScreenSpace();
1617 double below, above;
1619 m_gal->TakeWorldScaleLimits( below, above );
1624 if( above < std::numeric_limits<double>::max() )
1629 m_gal->EndDiffLayer();
1630 else if( l->hasNegatives )
1631 m_gal->EndNegativesLayer();
1638 m_gal->EnableDepthTest(
true );
1639 m_gal->SetLayerDepth( l->renderingOrder );
1641 l->items->Query( aRect, drawFunc );
1665 wxLogTrace(
traceRhi, wxS(
"ViewCache: miss layer=%d item=%p drawingMode=%d" ),
1666 aLayer,
static_cast<const void*
>( aItem ),
m_gal->IsDrawingMode() ? 1 : 0 );
1670 if( !
m_gal->HasRetainedScene() )
1676 if(
m_gal->IsDrawingMode() )
1689 wxLogTrace(
traceRhi, wxS(
"ViewCache: defer-build layer=%d item=%p" ),
1690 aLayer,
static_cast<const void*
>( aItem ) );
1712 for(
int layer : layers )
1720 m_gal->SetLayerDepth( it->second.renderingOrder );
1722 draw( aItem, layer, aImmediate );
1729 for(
unsigned int i = 0; i < aGroup->
GetSize(); i++ )
1752 if( !
gal->HasRetainedScene() )
1785 if( item && item->m_viewPrivData )
1786 item->m_viewPrivData->m_view =
nullptr;
1792 layer.items->RemoveAll();
1796 m_gal->ClearCache();
1803 if(
m_gal &&
m_gal->HasRetainedScene() && !
m_gal->RefillsNonCachedTargets() )
1842#ifdef KICAD_GAL_PROFILE
1843 PROF_TIMER totalRealTime(
"view-redraw-total");
1844 latencyProbeZoomToRender.Checkpoint(
"view-redraw-start");
1869#ifdef KICAD_GAL_PROFILE
1870 totalRealTime.
Stop();
1872 latencyProbeZoomToRender.AddTimer( totalRealTime );
1873 latencyProbeZoomToRender.Checkpoint(
"view-redraw-end");
1881 return m_gal->GetScreenPixelSize();
1911 layer.items->Query( r, visitor );
1919 if( aUpdateFlags &
LAYERS )
1929 bool cachedMutation =
false;
1930 const bool retained =
m_gal &&
m_gal->HasRetainedScene();
1933 for(
int layer : layers )
1937 cachedMutation =
true;
1941 else if( aUpdateFlags &
COLOR )
1945 if( retained && ( aUpdateFlags &
APPEARANCE ) )
1963 else if( cachedMutation && ( aUpdateFlags & (
APPEARANCE |
COLOR ) ) )
1967 const bool colorOnlyPatchable = ( aUpdateFlags &
COLOR ) && !( aUpdateFlags &
APPEARANCE )
1970 if( !colorOnlyPatchable )
1984 for(
auto& [layer_id, layer] :
m_layers )
1998 if(
m_painter->HasUniformColor( aItem, aLayer ) )
2000 m_gal->ChangeGroupColor( aGroup,
m_painter->GetSettings()->GetColor( aItem, aLayer ) );
2012 if(
m_gal->HasRetainedScene() )
2013 m_gal->ChangeGroupUndimmed( aGroup,
m_painter->GetSettings()->IsDimExempt( aItem ) );
2060 if(
group >= 0 && !keepForPlacement )
2066 wxLogTrace(
traceGalGroups, wxS(
"updateItemGeometry() item=%p layer=%d newGroup=%d" ),
2067 static_cast<void*
>( aItem ), aLayer,
group );
2075 if( aPlace &&
m_gal->HasRetainedScene() )
2087 m_gal->DeleteGroup( it->second );
2115 if( new_bbox == old_bbox )
2120 for(
int layer : layers )
2128 l.
items->Remove( aItem, &old_bbox );
2129 l.
items->Insert( aItem, new_bbox );
2148 if( newLayers == viewData->
m_layers && new_bbox == viewData->
m_bbox )
2162 l.
items->Remove( aItem, &old_bbox );
2168 int prevGroup = viewData->
getGroup( layer );
2170 if( prevGroup >= 0 )
2172 m_gal->DeleteGroup( prevGroup );
2181 for(
int layer : newLayers )
2189 l.
items->Insert( aItem, new_bbox );
2199 auto it =
m_layers.find( aLayerId );
2204 for(
int layer : it->second.requiredLayers )
2210 if( it2 ==
m_layers.end() || !it2->second.visible )
2232 l.items->Query( r, visitor );
2240 if( !
m_gal->IsVisible() || !
m_gal->IsInitialized() )
2243 wxS(
"UpdateItems() SKIP: visible=%d initialized=%d" ),
2244 m_gal->IsVisible(),
m_gal->IsInitialized() );
2248#ifdef KICAD_GAL_PROFILE
2249 latencyProbeZoomToRender.Checkpoint(
"view-update-items");
2256 if(
m_gal->HasRetainedScene() )
2259 unsigned int cntGeomUpdate = 0;
2260 bool anyUpdated =
false;
2263 const bool retained =
m_gal->HasRetainedScene();
2273 auto vpd = item->viewPrivData();
2278 if( vpd->m_requiredUpdate !=
NONE )
2289 double ratio = (double) cntGeomUpdate / (
double) cntTotal;
2300 layer.items->RemoveAll();
2303 std::unordered_map<int, std::vector<std::pair<VIEW_ITEM*, BOX2I>>> layerBulk;
2310 const BOX2I bbox = item->ViewBBox();
2311 item->m_viewPrivData->m_bbox = bbox;
2313 std::vector<int> layers = item->ViewGetLayers();
2314 item->viewPrivData()->saveLayers( layers );
2316 for(
int layer : layers )
2320 wxCHECK2_MSG( it !=
m_layers.end(),
continue, wxS(
"Invalid layer" ) );
2321 layerBulk[layer].emplace_back( item, bbox );
2327 if( item->viewPrivData()->m_requiredUpdate & (
LAYERS |
GEOMETRY ) )
2329 item->viewPrivData()->m_requiredUpdate &= ~(
LAYERS |
GEOMETRY );
2330 item->viewPrivData()->m_requiredUpdate |=
REPAINT;
2335 for(
auto& [layerId, items] : layerBulk )
2337 auto it =
m_layers.find( layerId );
2341 it->second.items->BulkLoad( items );
2351 bool updatesProcessed =
true;
2355 unsigned int cntInvalidated = 0;
2360 auto invalidate = [&](
VIEW_ITEM* item )
2362 if( item && item->viewPrivData() && item->viewPrivData()->m_requiredUpdate !=
NONE )
2366 item->viewPrivData()->m_requiredUpdate =
NONE;
2372 if(
m_gal->HasStaticRebuildPending() )
2378 invalidate( flagged[
next] );
2389 while(
next < flagged.size() )
2391 std::vector<RETAINED_ORDER_ITEM> batch;
2393 while(
next < flagged.size() )
2404 { item, front, front < 0 ? -1 : data->
getGroup( front ),
2412 std::sort( batch.begin(), batch.end(),
2415 return a.order < b.order;
2421 invalidate( entry.item );
2432 for(
size_t ii = 0; ii < flagged.size(); ++ii )
2433 invalidate( flagged[ii] );
2438 updatesProcessed =
false;
2441 wxLogTrace(
traceGalGroups, wxS(
"UpdateItems() invalidated %u items" ), cntInvalidated );
2445 wxS(
"UpdateItems() total=%u geomUpdate=%u anyUpdated=%d bulkRebuild=%d" ),
2446 cntTotal, cntGeomUpdate, anyUpdated, ratio > 0.05 );
2448#ifdef KICAD_GAL_PROFILE
2449 wxLogTrace(
traceGalProfile, wxS(
"View update: total items %u, geom %u anyUpdated %u" ),
2450 cntTotal, cntGeomUpdate, (
unsigned) anyUpdated );
2453 if( updatesProcessed )
2466 if( item && item->viewPrivData() )
2467 item->viewPrivData()->m_pendingIndex = -1;
2476 if( aUpdateFlags ==
NONE )
2481 if( item && item->viewPrivData() )
2483 item->viewPrivData()->m_requiredUpdate |= aUpdateFlags;
2492 std::function<
bool(
VIEW_ITEM* )> aCondition )
2494 if( aUpdateFlags ==
NONE )
2502 if( aCondition( item ) )
2504 if( item->viewPrivData() )
2506 item->viewPrivData()->m_requiredUpdate |= aUpdateFlags;
2522 if( item->viewPrivData() )
2524 int flags = aItemFlagsProvider( item );
2525 item->viewPrivData()->m_requiredUpdate |= flags;
2540 std::unique_ptr<VIEW> ret = std::make_unique<VIEW>();
2544 ret->m_pendingListIncomplete =
true;
2546 ret->SortOrderedLayers();
2563 if( cur_visible != aIsVisible )
2620 return viewData && viewData->
m_view ==
this;
2637 assert( aUpdateFlags !=
NONE );
2643 if( viewData->
m_view !=
this )
2656 const std::function<
bool(
VIEW_ITEM*,
int )>& aItemFilter )
2658 if( !
m_gal->IsVisible() || !
m_gal->IsInitialized() )
2661 std::vector<LAYER_ITEM_PAIR> stale;
2665 if( l->target !=
TARGET_CACHED || !l->visible || !aLayerFilter( l->id ) )
2668 auto collect = [&](
VIEW_ITEM* aItem ) ->
bool
2670 if( aItemFilter( aItem, l->id ) )
2671 stale.emplace_back( aItem, l->id );
2676 l->items->Query( aRect, collect );
2687 if(
m_gal->HasRetainedScene() )
2711 std::shared_ptr<VIEW_OVERLAY>
overlay = std::make_shared<VIEW_OVERLAY>();
2742 Hide( aItem,
false );
2745 if( aTakeOwnership )
2766 for(
const auto& layer :
m_layers )
constexpr int ARC_LOW_DEF
constexpr BOX2I BOX2ISafe(const BOX2D &aInput)
constexpr void SetMaximum()
constexpr size_type GetWidth() const
constexpr Vec Centre() const
constexpr size_type GetHeight() const
constexpr coord_type GetLeft() const
constexpr coord_type GetRight() const
constexpr const SizeVec & GetSize() const
constexpr coord_type GetTop() const
constexpr coord_type GetBottom() const
A color representation with 4 components: red, green, blue, alpha.
static const COLOR4D BLACK
Abstract interface for drawing on a 2D-surface.
virtual std::array< uint64_t, 2 > GroupContentFingerprint(int aGroupNumber) const
Extend VIEW_ITEM by possibility of grouping items into a single object.
virtual unsigned int GetSize() const
Return the number of stored items.
virtual VIEW_ITEM * GetItem(unsigned int aIdx) const
bool storesGroups() const
Return information if the item uses at least one group id (ie.
std::vector< int > m_layers
int requiredUpdate() const
Return current update flag for an item.
int m_requiredUpdate
Flag required for updating.
int m_flags
Visibility flags.
int m_cachedIndex
Cached index in m_allItems.
void deleteGroups()
Remove all of the stored group ids.
bool isRenderable() const
Return if the item should be drawn or not.
int m_drawPriority
Order to draw this item in a layer, lowest first.
VIEW * m_view
Current dynamic view the item is assigned to.
std::pair< int, int > * m_groups
layer_number:group_id pairs for each layer the item occupies.
int getGroup(int aLayer) const
Return number of the group id for the given layer, or -1 in case it was not cached before.
void reorderGroups(const std::unordered_map< int, int > &aReorderMap)
Reorder the stored groups (to facilitate reordering of layers).
BOX2I m_bbox
Stores layer numbers used by the item.
void setGroup(int aLayer, int aGroup)
Set a group id for the item and the layer combination.
void saveLayers(const std::vector< int > &aLayers)
Save layers used by the item.
void clearUpdateFlags()
Mark an item as already updated, so it is not going to be redrawn.
An abstract base class for deriving all objects that can be added to a VIEW.
virtual const BOX2I ViewBBox() const =0
Return the bounding box of the item covering all its layers.
double m_forcedTransparency
Additional transparency for diff'ing items.
VIEW_ITEM_DATA * viewPrivData() const
virtual void ViewDraw(int aLayer, VIEW *aView) const
Draw the parts of the object belonging to layer aLayer.
virtual std::vector< int > ViewGetLayers() const =0
Return the all the layers within the VIEW the object is painted on.
virtual wxString GetClass() const =0
Return the class name.
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
virtual double ViewGetLOD(int aLayer, const VIEW *aView) const
Return the level of detail (LOD) of the item.
VIEW_ITEM_DATA * m_viewPrivData
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
void SetMirror(bool aMirrorX, bool aMirrorY)
Control the mirroring of the VIEW.
bool m_layerCachesStale
A layer's visibility or target changed since SyncLayerVisibilityCache() last copied them.
void ShowPreview(bool aShow=true)
void markSceneEdited()
Note that items of the cached scene were added, removed or re-cached.
std::vector< int > m_lodRefreshLayers
Layers shown or hidden since the last sync, whose readers have to be placed again.
bool m_cameraDirtyOnly
The current dirty state is due only to camera changes.
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
void releaseReplacedGroup(VIEW_ITEM *aItem, int aLayer)
Delete the group a deferred placement of an item on a layer replaces, if it is still kept.
void CopySettings(const VIEW *aOtherView)
Copy layers and visibility settings from another view.
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
static constexpr int TOP_LAYER_MODIFIER
Rendering order modifier for layers that are marked as top layers.
void draw(VIEW_ITEM *aItem, int aLayer, bool aImmediate=false)
Draw an item, but on a specified layers.
SCALE_USE * m_keptScaleUse
The SCALE_USE of the kept target being drawn, updated by each level of detail drawn.
bool m_reverseDrawOrder
Flag to reverse the draw order when using draw priority.
std::unordered_map< int, std::vector< bool > > m_lodReads
For each layer whose visibility an item asked about, the cached layers those items were placed on.
bool m_targetEdited[TARGETS_NUMBER]
The target's content changed, not just the camera.
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
int m_lodProbeLayer
Cached layer being placed while an item is asked for its level of detail, else -1.
void placeCachedGroup(VIEW_ITEM *aItem, int aLayer, const RETAINED_GROUP_ORDER *aOrder=nullptr)
Tell a retained scene whether the cached group of aItem on aLayer belongs in it, caching the group fi...
void updateItemColor(VIEW_ITEM *aItem, int aLayer)
Update colors that are used for an item to be drawn.
void SetViewport(const BOX2D &aViewport)
Set the visible area of the VIEW.
void SetRequired(int aLayerId, int aRequiredId, bool aRequired=true)
Mark the aRequiredId layer as required for the aLayerId layer.
VECTOR2D ToScreen(const VECTOR2D &aCoord, bool aAbsolute=true) const
Convert a world space point/vector to a point/vector in screen space coordinates.
void recolorGroup(VIEW_ITEM *aItem, int aLayer, int aGroup)
void markDimExemption(const VIEW_ITEM *aItem, int aGroup)
Keep a group of a retained scene out of its layer's fade if the painter exempts its item.
double cachedGroupLOD(VIEW_ITEM *aItem, int aLayer)
static bool compareRenderingOrder(VIEW_LAYER *aI, VIEW_LAYER *aJ)
Determine rendering order of layers. Used in display order sorting function.
int GetLayerOrder(int aLayer) const
Return rendering order of a particular layer.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
void ClearTargets()
Clear targets that are marked as dirty.
virtual void EnableTopLayer(bool aEnable)
Enable or disable display of the top layer.
void updateItemGeometry(VIEW_ITEM *aItem, int aLayer, bool aPlace=true)
Update all information needed to draw an item.
std::vector< std::pair< VIEW_ITEM *, int > > m_deferredRetainedPlacements
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
void MarkStaticDirty()
Flag the GAL's static geometry pool as dirty so the next full redraw rebuilds it.
bool m_deferRetainedPlacement
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
Flat list of all items.
std::shared_ptr< VIEW_OVERLAY > MakeOverlay()
void MarkGeometryDirty()
Signal a change to cached geometry so the next paint leaves the camera-reuse path and rebuilds the st...
void rescaleKeptTargets()
Mark the kept targets whose content the new scale changes, so they are emitted again.
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Find all visible items that touch or are within the rectangle aRect.
std::vector< VIEW_ITEM * > m_ownedItems
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
void invalidateItem(VIEW_ITEM *aItem, int aUpdateFlags)
Manage dirty flags & redraw queuing when updating an item.
const VECTOR2I & GetScreenPixelSize() const
Return the size of the our rendering area in pixels.
bool HasItem(const VIEW_ITEM *aItem) const
Indicates whether or not the given item has been added to the view.
virtual int GetTopLayer() const
PAINTER * m_painter
PAINTER contains information how do draw items.
virtual void Redraw()
Immediately redraws the whole view.
void Clear()
Remove all items from the view.
std::set< unsigned int > m_topLayers
The set of layers that are displayed on the top.
bool m_enableOrderModifier
Whether to use rendering order modifier or not.
SCALE_USE m_scaleUse[TARGETS_NUMBER]
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
void UpdateAllLayersColorAndVisibility()
Apply the new coloring scheme to all layers after a render settings change that can also hide items,...
bool IsHiddenOnOverlay(const VIEW_ITEM *aItem) const
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
bool m_dirtyTargets[TARGETS_NUMBER]
Flag to mark targets as dirty so they have to be redrawn on the next refresh event.
void SetLayerOrder(int aLayer, int aRenderingOrder, bool aAutoSort=true)
Set rendering order of a particular layer.
void MarkClean()
Force redraw of view on the next rendering.
bool IsShownAtScale(double aLod) const
Return true if something with level of detail aLod is drawn at the current scale.
static constexpr int VIEW_MAX_LAYERS
Maximum number of layers that may be shown.
void layerStateChanged(int aLayer)
React to a change of a layer's visibility, order, required layers or negatives.
void SyncRetainedScene()
Bring a retained scene up to date with the view scale and layer state, and place again the items whos...
void updateLayers(VIEW_ITEM *aItem)
Update set of layers that an item occupies.
void RecacheAllItems()
Rebuild GAL display lists.
bool areRequiredLayersEnabled(int aLayerId) const
Check if every layer required by the aLayerId layer is enabled.
bool IsTargetDirty(int aTarget) const
Return true if any of layers belonging to the target or the target itself should be redrawn.
bool m_pendingListIncomplete
Items were flagged without being listed, so UpdateItems() has to scan them all.
int m_nextDrawPriority
The next sequential drawing priority.
bool m_scaleRead
GetScale() was called, see SCALE_USE::read.
bool m_useDrawPriority
Flag to respect draw priority when drawing items.
void UpdateItems()
Iterate through the list of items that asked for updating and updates them.
void MarkViewportDirty()
Force a redraw for a camera change alone, which lets the paint reuse the cached scene.
void SyncLayerVisibilityCache()
bool IsCached(int aLayer) const
Return true if the layer is cached.
void AddBatch(const std::vector< VIEW_ITEM * > &aItems)
Add a batch of items to the view, using bulk-loaded R-trees for initial population.
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
void SortLayers(std::vector< int > &aLayers) const
Change the order of given layer ids, so after sorting the order corresponds to layers rendering order...
BASE_SET m_layerVisibilityCache
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
bool m_hasPendingItemUpdates
True when at least one item has deferred update flags that still need processing.
std::unique_ptr< KIGFX::VIEW_GROUP > m_preview
static void OnDestroy(VIEW_ITEM *aItem)
Nasty hack, invoked by the destructor of VIEW_ITEM to auto-remove the item from the owning VIEW if th...
void clearPendingItems()
Empty m_pendingItems and forget each listed item's place in it.
bool m_sceneLayersStale
A layer's order, visibility, required layers or negatives changed since the last sync.
std::vector< VIEW_ITEM * > m_pendingItems
Items flagged through Update() since the last UpdateItems(), so a frame that changed a few items need...
GAL * m_gal
Interface to PAINTER that is used to draw items.
bool IsDirty() const
Return true if any of the VIEW layers needs to be refreshened.
void placeRetainedInOrder(const std::vector< LAYER_ITEM_PAIR > &aItems, bool aReplacing)
Cache the missing groups of these items, then place them all in retained draw order.
std::map< int, VIEW_LAYER > m_layers
The set of possible displayed layers and its properties.
void RepaintLayers(const BOX2I &aRect, const std::function< bool(int)> &aLayerFilter, const std::function< bool(VIEW_ITEM *, int)> &aItemFilter)
Re-cache only some layers of the items in aRect.
std::unique_ptr< VIEW > DataReference() const
Return a new VIEW object that shares the same set of VIEW_ITEMs and LAYERs.
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
virtual void SetTopLayer(int aLayer, bool aEnabled=true)
Set given layer to be displayed on the top or sets back the default order of layers.
void AddToPreview(VIEW_ITEM *aItem, bool aTakeOwnership=true)
void UpdateLayerColor(int aLayer)
Apply the new coloring scheme held by RENDER_SETTINGS in case that it has changed.
void MarkDirty()
Force redraw of view on the next rendering.
void noteLodRead(int aLayer) const
Record that the item being placed asked whether aLayer is visible.
void recolorAllLayers(bool aReplace, const std::function< bool(int)> &aLayers={})
Recolor every cached group on the layers aLayers accepts, or all when empty, and place it again in a ...
void noteKeptLod(double aLod) const
std::map< std::pair< VIEW_ITEM *, int >, int > m_replacedRetainedGroups
Groups replaced by items redrawn during a deferred placement.
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
std::vector< VIEW_LAYER * > m_orderedLayers
Sorted list of pointers to members of m_layers.
void clearGroupCache()
Clear cached GAL group numbers (ONLY numbers stored in VIEW_ITEMs, not group objects used by GAL).
VECTOR2D m_center
Center point of the VIEW (the point at which we are looking at).
void SortOrderedLayers()
Sorts m_orderedLayers after layer rendering order has changed.
void unlinkItem(VIEW_ITEM *aItem)
Detach a single VIEW_ITEM from this view.
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
void UpdateLayersColor(bool aVisibility, const std::function< bool(int)> &aLayers)
Recolor only the layers aLayers accepts, along with the fade the canvas may apply to them.
void updateBbox(VIEW_ITEM *aItem)
Update bounding box of an item.
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
void releaseReplacedGroups()
Delete every group still kept for a deferred placement that did not happen.
BASE_SET m_layerCachedFlagCache
void UpdateAllItemsConditionally(int aUpdateFlags, std::function< bool(VIEW_ITEM *)> aCondition)
Update items in the view according to the given flags and condition.
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
void ReorderLayerData(std::unordered_map< int, int > aReorderMap)
Remap the data between layer ids without invalidating that data.
void redrawRect(const BOX2I &aRect)
Redraw contents within rectangle aRect.
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
A small class to help profiling.
void Stop()
Save the time when this function was called, and set the counter stane to stop.
double msecs(bool aSinceLast=false)
Represent a set of closed polygons.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
void Deflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError)
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
@ ALLOW_ACUTE_CORNERS
just inflate the polygon. Acute angles create spikes
const wxChar *const traceGalGroups
Flag to enable debug output of GAL cached group creation and drawing.
const wxChar *const traceRhi
Flag to enable debug output of the RHI rendering backend.
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
MATRIX3x3< double > MATRIX3x3D
The Cairo implementation of the graphics abstraction layer.
static RETAINED_GROUP_ORDER retainedOrderKey(VIEW_ITEM *aItem, int aPriority, const BOX2I &aBBox, bool aUseDrawPriority, bool aReverseDrawOrder, double aLodScale)
static void sortRetainedOrder(VIEW *aView, std::vector< T > &aEntries)
@ COLOR
Color has changed.
@ INITIAL_ADD
Item is being added to the view.
@ NONE
No updates are required.
@ REPAINT
Item needs to be redrawn.
@ APPEARANCE
Visibility flag has changed.
@ GEOMETRY
Position or shape has changed.
@ LAYERS
Layers have changed.
@ ALL
All except INITIAL_ADD.
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
@ TARGET_CACHED
Main rendering target (cached)
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
@ HIDDEN
Item is temporarily hidden (usually in favor of a being drawn from an overlay, such as a SELECTION).
@ OVERLAY_HIDDEN
Item is temporarily hidden from being drawn on an overlay.
@ VISIBLE
Item is visible (in general)
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > overlay
std::array< uint64_t, 2 > contentHash
std::array< int, 4 > bbox
RETAINED_GROUP_ORDER order
bool operator()(VIEW_ITEM *aItem)
CLEAR_LAYER_CACHE_VISITOR(VIEW *aView)
bool operator()(VIEW_ITEM *aItem)
DRAW_ITEM_VISITOR(VIEW *aView, int aLayer, bool aUseDrawPriority, bool aReverseDrawOrder)
bool foundForcedTransparent
int layers[VIEW_MAX_LAYERS]
bool drawForcedTransparent
std::vector< VIEW_ITEM * > drawItems
bool operator()(VIEW_ITEM *aItem)
RECACHE_ITEM_VISITOR(VIEW *aView, GAL *aGal, int aLayer)
How the content of a kept target depends on the scale it was emitted at.
bool read
something was sized from the scale
double lodAbove
nearest threshold above it
double lodBelow
nearest threshold under that scale
bool diffLayer
Layer should be drawn differentially over lower layers.
int renderingOrder
Rendering order of this layer.
bool hasNegatives
Layer should be drawn separately to not delete lower layers.
bool visible
Is the layer to be rendered?
bool displayOnly
Is the layer display only?
std::shared_ptr< VIEW_RTREE > items
R-tree indexing all items on this layer.
RENDER_TARGET target
Where the layer should be rendered.
wxLogTrace helper definitions.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)