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(), );
579 m_layers[aLayerId].requiredLayers.insert( aRequiredId );
581 m_layers[aLayerId].requiredLayers.erase( aRequiredId );
617 std::vector<bool>& readers =
m_lodReads[aLayer];
619 if( readers.empty() )
636 for(
const auto& [
id, l] :
m_layers )
640 m_gal->SetSceneLayerState(
id, l.renderingOrder, drawn, l.hasNegatives );
646 m_gal->SetSceneLayerDim(
id, toward, keep );
664 if( !
m_gal->IsVisible() || !
m_gal->IsInitialized() )
685 if( it->second[reader] )
686 readers[reader] =
true;
700 const int layer = id;
702 auto place = [&](
VIEW_ITEM* aItem ) ->
bool
708 l.items->Query( everywhere, place );
718 m_gal->MarkStaticDirty();
722 if(
m_gal->HasRetainedScene() )
757 std::vector<VIEW_LAYER*>::const_reverse_iterator i;
764 if( ( *i )->displayOnly || !( *i )->visible )
768 ( *i )->items->Query( aRect, visitor );
771 return aResult.size();
783 if( i->displayOnly || !i->visible )
786 i->items->Query( aRect, aFunc );
806 return fabs( matrix.
GetScale().
x * aSize );
831 wxASSERT_MSG(
false, wxT(
"This is not implemented" ) );
837 bool recacheGroups = (
m_gal != nullptr );
877 wxCHECK( fabs(ssize.
x) > 0 && fabs(ssize.
y) > 0, );
881 double zoom = 1.0 / std::max( fabs( vsize.
x / ssize.
x ), fabs( vsize.
y / ssize.
y ) );
890 wxASSERT_MSG( !aMirrorY,
_(
"Mirroring for Y axis is not supported yet" ) );
894 m_gal->SetFlip( aMirrorX, aMirrorY );
907 const double oldScale =
m_scale;
917 m_gal->ComputeWorldScreenMatrix();
989 m_gal->ComputeWorldScreenMatrix();
998 if( obscuringScreenRects.empty() )
1001 BOX2D screenRect( { 0, 0 },
m_gal->GetScreenPixelSize() );
1005 for(
const BOX2D& obscuringScreenRect : obscuringScreenRects )
1021 while( !unobscuredPoly.
IsEmpty() )
1023 unobscuredCenter = unobscuredPoly.
BBox().
Centre();
1033 m_layers[aLayer].renderingOrder = aRenderingOrder;
1042 return m_layers.at( aLayer ).renderingOrder;
1048 std::sort( aLayers.begin(), aLayers.end(),
1049 [
this](
int a,
int b )
1051 return GetLayerOrder( a ) > GetLayerOrder( b );
1060 std::map<int, VIEW_LAYER>
moved;
1061 std::unordered_set<int> destinations;
1063 for(
const auto& [from, to] : aReorderMap )
1074 destinations.insert( to );
1078 for(
const auto& [from, layer] :
moved )
1080 auto destination =
m_layers.find( aReorderMap.at( from ) );
1082 destination->second = layer;
1083 destination->second.id = destination->first;
1088 for(
const auto& [from,
_] :
moved )
1090 if( !destinations.count( from ) )
1091 m_layers.find( from )->second.items = std::make_shared<VIEW_RTREE>();
1113 std::vector<int> layers = item->ViewGetLayers();
1140 if(
m_gal->IsVisible() )
1146 std::vector<std::pair<VIEW_ITEM*, int>> groups;
1150 if(
int group = aItem->viewPrivData()->getGroup( aLayer );
group >= 0 )
1151 groups.emplace_back( aItem,
group );
1156 m_layers[aLayer].items->Query( r, collect );
1159 for(
const auto& [item,
group] : groups )
1202 if(
m_gal->IsVisible() )
1218 for(
int layer : viewData->
m_layers )
1220 if( aLayers && !aLayers( layer ) )
1228 if(
group >= 0 && aReplace )
1282 std::set<unsigned int>::iterator it;
1302 std::set<unsigned int>::iterator it;
1320 if(
m_gal->IsVisible() && !
m_gal->HasRetainedScene() )
1336 for(
int layer : viewData->
m_layers )
1388 view->noteKeptLod( itemLOD );
1393 if( !drawCondition )
1408 std::vector<VIEW::LAYER_ITEM_PAIR> items;
1412 items.emplace_back( item,
layer );
1414 view->placeRetainedInOrder( items,
false );
1423 return b->viewPrivData()->m_drawPriority
1424 < a->viewPrivData()->m_drawPriority;
1432 return a->viewPrivData()->m_drawPriority
1433 < b->viewPrivData()->m_drawPriority;
1453 std::vector<RETAINED_ORDER_ITEM> ordered;
1454 ordered.reserve( aItems.size() );
1456 for(
const auto& [item, layer] : aItems )
1466 ordered.push_back( { item, layer, data->
getGroup( layer ),
1500 if( viewData->
getGroup( aLayer ) < 0 )
1522 m_gal->SetGroupPlacement(
group, aLayer, lod,
1530 const double lod = aItem->
ViewGetLOD( aLayer,
this );
1540 const bool retained =
m_gal &&
m_gal->HasRetainedScene();
1555 if( l->items->IsEmpty() )
1558 const bool placing = retained && l->target ==
TARGET_CACHED;
1566 const bool targetDirty = placing ?
m_gal->HasStaticRebuildPending()
1569 &&
m_gal->HasStaticRebuildPending() ) );
1576 m_gal->SetTarget( l->target );
1577 m_gal->SetLayerDepth( l->renderingOrder );
1582 m_gal->StartDiffLayer();
1583 else if( l->hasNegatives )
1584 m_gal->StartNegativesLayer();
1589 m_gal->BeginSceneLayer( l->id );
1598 m_gal->TakeWorldScaleRead();
1600 double below, above;
1601 m_gal->TakeWorldScaleLimits( below, above );
1604 l->items->Query( aRect, drawFunc );
1615 if( kept &&
m_gal->GetWorldScaleForScreenSpace() > 0.0 )
1617 const double toView =
m_scale /
m_gal->GetWorldScaleForScreenSpace();
1618 double below, above;
1620 m_gal->TakeWorldScaleLimits( below, above );
1625 if( above < std::numeric_limits<double>::max() )
1630 m_gal->EndDiffLayer();
1631 else if( l->hasNegatives )
1632 m_gal->EndNegativesLayer();
1639 m_gal->EnableDepthTest(
true );
1640 m_gal->SetLayerDepth( l->renderingOrder );
1642 l->items->Query( aRect, drawFunc );
1666 wxLogTrace(
traceRhi, wxS(
"ViewCache: miss layer=%d item=%p drawingMode=%d" ),
1667 aLayer,
static_cast<const void*
>( aItem ),
m_gal->IsDrawingMode() ? 1 : 0 );
1671 if( !
m_gal->HasRetainedScene() )
1677 if(
m_gal->IsDrawingMode() )
1690 wxLogTrace(
traceRhi, wxS(
"ViewCache: defer-build layer=%d item=%p" ),
1691 aLayer,
static_cast<const void*
>( aItem ) );
1713 for(
int layer : layers )
1721 m_gal->SetLayerDepth( it->second.renderingOrder );
1723 draw( aItem, layer, aImmediate );
1730 for(
unsigned int i = 0; i < aGroup->
GetSize(); i++ )
1753 if( !
gal->HasRetainedScene() )
1786 if( item && item->m_viewPrivData )
1787 item->m_viewPrivData->m_view =
nullptr;
1793 layer.items->RemoveAll();
1797 m_gal->ClearCache();
1804 if(
m_gal &&
m_gal->HasRetainedScene() && !
m_gal->RefillsNonCachedTargets() )
1843#ifdef KICAD_GAL_PROFILE
1844 PROF_TIMER totalRealTime(
"view-redraw-total");
1845 latencyProbeZoomToRender.Checkpoint(
"view-redraw-start");
1870#ifdef KICAD_GAL_PROFILE
1871 totalRealTime.
Stop();
1873 latencyProbeZoomToRender.AddTimer( totalRealTime );
1874 latencyProbeZoomToRender.Checkpoint(
"view-redraw-end");
1882 return m_gal->GetScreenPixelSize();
1912 layer.items->Query( r, visitor );
1920 if( aUpdateFlags &
LAYERS )
1930 bool cachedMutation =
false;
1931 const bool retained =
m_gal &&
m_gal->HasRetainedScene();
1934 for(
int layer : layers )
1938 cachedMutation =
true;
1942 else if( aUpdateFlags &
COLOR )
1946 if( retained && ( aUpdateFlags &
APPEARANCE ) )
1964 else if( cachedMutation && ( aUpdateFlags & (
APPEARANCE |
COLOR ) ) )
1968 const bool colorOnlyPatchable = ( aUpdateFlags &
COLOR ) && !( aUpdateFlags &
APPEARANCE )
1971 if( !colorOnlyPatchable )
1985 for(
auto& [layer_id, layer] :
m_layers )
1999 if(
m_painter->HasUniformColor( aItem, aLayer ) )
2001 m_gal->ChangeGroupColor( aGroup,
m_painter->GetSettings()->GetColor( aItem, aLayer ) );
2013 if(
m_gal->HasRetainedScene() )
2014 m_gal->ChangeGroupUndimmed( aGroup,
m_painter->GetSettings()->IsDimExempt( aItem ) );
2061 if(
group >= 0 && !keepForPlacement )
2067 wxLogTrace(
traceGalGroups, wxS(
"updateItemGeometry() item=%p layer=%d newGroup=%d" ),
2068 static_cast<void*
>( aItem ), aLayer,
group );
2076 if( aPlace &&
m_gal->HasRetainedScene() )
2088 m_gal->DeleteGroup( it->second );
2116 if( new_bbox == old_bbox )
2121 for(
int layer : layers )
2129 l.
items->Remove( aItem, &old_bbox );
2130 l.
items->Insert( aItem, new_bbox );
2149 if( newLayers == viewData->
m_layers && new_bbox == viewData->
m_bbox )
2163 l.
items->Remove( aItem, &old_bbox );
2169 int prevGroup = viewData->
getGroup( layer );
2171 if( prevGroup >= 0 )
2173 m_gal->DeleteGroup( prevGroup );
2182 for(
int layer : newLayers )
2190 l.
items->Insert( aItem, new_bbox );
2200 auto it =
m_layers.find( aLayerId );
2205 for(
int layer : it->second.requiredLayers )
2211 if( it2 ==
m_layers.end() || !it2->second.visible )
2233 l.items->Query( r, visitor );
2241 if( !
m_gal->IsVisible() || !
m_gal->IsInitialized() )
2244 wxS(
"UpdateItems() SKIP: visible=%d initialized=%d" ),
2245 m_gal->IsVisible(),
m_gal->IsInitialized() );
2249#ifdef KICAD_GAL_PROFILE
2250 latencyProbeZoomToRender.Checkpoint(
"view-update-items");
2257 if(
m_gal->HasRetainedScene() )
2260 unsigned int cntGeomUpdate = 0;
2261 bool anyUpdated =
false;
2264 const bool retained =
m_gal->HasRetainedScene();
2274 auto vpd = item->viewPrivData();
2279 if( vpd->m_requiredUpdate !=
NONE )
2290 double ratio = (double) cntGeomUpdate / (
double) cntTotal;
2301 layer.items->RemoveAll();
2304 std::unordered_map<int, std::vector<std::pair<VIEW_ITEM*, BOX2I>>> layerBulk;
2311 const BOX2I bbox = item->ViewBBox();
2312 item->m_viewPrivData->m_bbox = bbox;
2314 std::vector<int> layers = item->ViewGetLayers();
2315 item->viewPrivData()->saveLayers( layers );
2317 for(
int layer : layers )
2321 wxCHECK2_MSG( it !=
m_layers.end(),
continue, wxS(
"Invalid layer" ) );
2322 layerBulk[layer].emplace_back( item, bbox );
2328 if( item->viewPrivData()->m_requiredUpdate & (
LAYERS |
GEOMETRY ) )
2330 item->viewPrivData()->m_requiredUpdate &= ~(
LAYERS |
GEOMETRY );
2331 item->viewPrivData()->m_requiredUpdate |=
REPAINT;
2336 for(
auto& [layerId, items] : layerBulk )
2338 auto it =
m_layers.find( layerId );
2342 it->second.items->BulkLoad( items );
2352 bool updatesProcessed =
true;
2356 unsigned int cntInvalidated = 0;
2361 auto invalidate = [&](
VIEW_ITEM* item )
2363 if( item && item->viewPrivData() && item->viewPrivData()->m_requiredUpdate !=
NONE )
2367 item->viewPrivData()->m_requiredUpdate =
NONE;
2373 if(
m_gal->HasStaticRebuildPending() )
2379 invalidate( flagged[
next] );
2390 while(
next < flagged.size() )
2392 std::vector<RETAINED_ORDER_ITEM> batch;
2394 while(
next < flagged.size() )
2405 { item, front, front < 0 ? -1 : data->
getGroup( front ),
2413 std::sort( batch.begin(), batch.end(),
2416 return a.order < b.order;
2422 invalidate( entry.item );
2433 for(
size_t ii = 0; ii < flagged.size(); ++ii )
2434 invalidate( flagged[ii] );
2439 updatesProcessed =
false;
2442 wxLogTrace(
traceGalGroups, wxS(
"UpdateItems() invalidated %u items" ), cntInvalidated );
2446 wxS(
"UpdateItems() total=%u geomUpdate=%u anyUpdated=%d bulkRebuild=%d" ),
2447 cntTotal, cntGeomUpdate, anyUpdated, ratio > 0.05 );
2449#ifdef KICAD_GAL_PROFILE
2450 wxLogTrace(
traceGalProfile, wxS(
"View update: total items %u, geom %u anyUpdated %u" ),
2451 cntTotal, cntGeomUpdate, (
unsigned) anyUpdated );
2454 if( updatesProcessed )
2467 if( item && item->viewPrivData() )
2468 item->viewPrivData()->m_pendingIndex = -1;
2477 if( aUpdateFlags ==
NONE )
2482 if( item && item->viewPrivData() )
2484 item->viewPrivData()->m_requiredUpdate |= aUpdateFlags;
2493 std::function<
bool(
VIEW_ITEM* )> aCondition )
2495 if( aUpdateFlags ==
NONE )
2503 if( aCondition( item ) )
2505 if( item->viewPrivData() )
2507 item->viewPrivData()->m_requiredUpdate |= aUpdateFlags;
2523 if( item->viewPrivData() )
2525 int flags = aItemFlagsProvider( item );
2526 item->viewPrivData()->m_requiredUpdate |= flags;
2541 std::unique_ptr<VIEW> ret = std::make_unique<VIEW>();
2545 ret->m_pendingListIncomplete =
true;
2547 ret->SortOrderedLayers();
2564 if( cur_visible != aIsVisible )
2621 return viewData && viewData->
m_view ==
this;
2638 assert( aUpdateFlags !=
NONE );
2644 if( viewData->
m_view !=
this )
2657 const std::function<
bool(
VIEW_ITEM*,
int )>& aItemFilter )
2659 if( !
m_gal->IsVisible() || !
m_gal->IsInitialized() )
2662 std::vector<LAYER_ITEM_PAIR> stale;
2666 if( l->target !=
TARGET_CACHED || !l->visible || !aLayerFilter( l->id ) )
2669 auto collect = [&](
VIEW_ITEM* aItem ) ->
bool
2671 if( aItemFilter( aItem, l->id ) )
2672 stale.emplace_back( aItem, l->id );
2677 l->items->Query( aRect, collect );
2688 if(
m_gal->HasRetainedScene() )
2712 std::shared_ptr<VIEW_OVERLAY>
overlay = std::make_shared<VIEW_OVERLAY>();
2743 Hide( aItem,
false );
2746 if( aTakeOwnership )
2767 for(
const auto& layer :
m_layers )
constexpr int ARC_LOW_DEF
constexpr BOX2I BOX2ISafe(const BOX2D &aInput)
constexpr void SetMaximum()
constexpr void SetOrigin(const Vec &pos)
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
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 void SetEnd(coord_type x, coord_type y)
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