44#ifdef KICAD_GAL_PROFILE
84 int* layersPtr = aLayers;
128 std::pair<int, int>* newGroups =
new std::pair<int, int>[
m_groupsSize + 1];
175 int new_layer = orig_layer;
177 if( aReorderMap.count( orig_layer ) )
178 new_layer = aReorderMap.at( orig_layer );
194 for(
int i = 0; i < aCount; ++i )
256 m_enableOrderModifier( true ),
258 m_minScale( 0.2 ), m_maxScale( 50000.0 ),
259 m_mirrorX( false ), m_mirrorY( false ),
260 m_painter( nullptr ),
262 m_dynamic( aIsDynamic ),
263 m_useDrawPriority( false ),
264 m_nextDrawPriority( 0 ),
265 m_reverseDrawOrder( false )
271 typedef std::numeric_limits<int> coord_limits;
272 double pos = coord_limits::lowest() / 2 + coord_limits::epsilon();
273 double size = coord_limits::max() - coord_limits::epsilon();
277 m_allItems.reset(
new std::vector<VIEW_ITEM*> );
292 m_layers[ii].items = std::make_shared<VIEW_RTREE>();
319 if( aDrawPriority < 0 )
327 wxS(
"Already in a different view!" ) );
339 for(
int i = 0; i < layers_count; ++i )
341 wxCHECK2_MSG( layers[i] >= 0 &&
static_cast<unsigned>( layers[i] ) <
m_layers.size(),
342 continue, wxS(
"Invalid layer" ) );
345 l.
items->Insert( aItem, bbox );
371 for(
int i = 0; i < layers_count; ++i )
374 l.
items->Remove( aItem, bbox );
392 wxCHECK( (
unsigned) aLayerId <
m_layers.size(), );
393 wxCHECK( (
unsigned) aRequiredId <
m_layers.size(), );
396 m_layers[aLayerId].requiredLayers.insert( aRequiredId );
398 m_layers[aLayerId].requiredLayers.erase( aRequired );
403template <
class CONTAINER>
431 std::vector<VIEW_LAYER*>::const_reverse_iterator i;
438 if( ( *i )->displayOnly || !( *i )->visible )
442 ( *i )->items->Query( aRect, visitor );
445 return aResult.size();
464 return fabs( matrix.
GetScale().
x * aSize );
489 wxASSERT_MSG(
false, wxT(
"This is not implemented" ) );
495 bool recacheGroups = (
m_gal != nullptr );
528 wxCHECK( fabs(ssize.
x) > 0 && fabs(ssize.
y) > 0, );
532 double zoom = 1.0 / std::max( fabs( vsize.
x / ssize.
x ), fabs( vsize.
y / ssize.
y ) );
541 wxASSERT_MSG( !aMirrorY,
_(
"Mirroring for Y axis is not supported yet" ) );
605 if( obscuringScreenRects.empty() )
612 for(
const BOX2D& obscuringScreenRect : obscuringScreenRects )
628 while( !unobscuredPoly.
IsEmpty() )
630 unobscuredCenter = unobscuredPoly.
BBox().
Centre();
640 m_layers[aLayer].renderingOrder = aRenderingOrder;
648 return m_layers.at( aLayer ).renderingOrder;
654 int maxLay, maxOrd, maxIdx;
656 for(
int i = 0; i < aCount; ++i )
663 for(
int j = i; j < aCount; ++j )
674 aLayers[maxIdx] = aLayers[i];
682 std::vector<VIEW_LAYER> new_map;
686 new_map.push_back( layer );
688 for(
auto& pair : aReorderMap )
690 new_map[pair.second] =
m_layers[pair.first];
691 new_map[pair.second].id = pair.second;
706 item->ViewGetLayers( layers, layers_count );
760 m_layers[aLayer].items->Query( r, visitor );
780 viewData->
getLayers( layers, layers_count );
782 for(
int i = 0; i < layers_count; ++i )
864 std::set<unsigned int>::iterator it;
884 std::set<unsigned int>::iterator it;
913 viewData->
getLayers( layers, layers_count );
915 for(
int i = 0; i < layers_count; ++i )
972 return b->viewPrivData()->m_drawPriority < a->viewPrivData()->m_drawPriority;
980 return a->viewPrivData()->m_drawPriority < b->viewPrivData()->m_drawPriority;
1012 else if( l->hasNegatives )
1015 l->items->Query( aRect, drawFunc );
1022 else if( l->hasNegatives )
1033 l->items->Query( aRect, drawFunc );
1047 if(
IsCached( aLayer ) && !aImmediate )
1075 for(
int i = 0; i < layers_count; ++i )
1078 draw( aItem, layers[i], aImmediate );
1085 for(
unsigned int i = 0; i < aGroup->
GetSize(); i++)
1131 layer.items->RemoveAll();
1160#ifdef KICAD_GAL_PROFILE
1176#ifdef KICAD_GAL_PROFILE
1177 totalRealTime.
Stop();
1215 layer.items->Query( r, visitor );
1231 if( aUpdateFlags &
LAYERS )
1241 for(
int i = 0; i < layers_count; ++i )
1243 int layerId = layers[i];
1249 else if( aUpdateFlags &
COLOR )
1279 wxCHECK( (
unsigned) aLayer <
m_layers.size(), );
1298 wxCHECK( (
unsigned) aLayer <
m_layers.size(), );
1336 for(
int i = 0; i < layers_count; ++i )
1339 l.
items->Remove( aItem, old_bbox );
1340 l.
items->Insert( aItem, new_bbox );
1355 viewData->
getLayers( layers, layers_count );
1358 for(
int i = 0; i < layers_count; ++i )
1361 l.
items->Remove( aItem, old_bbox );
1367 int prevGroup = viewData->
getGroup( layers[i] );
1369 if( prevGroup >= 0 )
1382 viewData->
saveLayers( layers, layers_count );
1384 for(
int i = 0; i < layers_count; i++ )
1387 l.
items->Insert( aItem, new_bbox );
1395 wxCHECK( (
unsigned) aLayerId <
m_layers.size(),
false );
1397 std::set<int>::const_iterator it, it_end;
1399 for(
int layer :
m_layers.at( aLayerId ).requiredLayers )
1421 l.items->Query( r, visitor );
1432 unsigned int cntGeomUpdate = 0;
1433 bool anyUpdated =
false;
1437 auto vpd = item->viewPrivData();
1442 if( vpd->m_requiredUpdate !=
NONE )
1455 double ratio = (double) cntGeomUpdate / (
double) cntTotal;
1470 layer.items->RemoveAll();
1475 const BOX2I bbox = item->ViewBBox();
1476 item->m_viewPrivData->m_bbox = bbox;
1478 item->ViewGetLayers( layers, layers_count );
1479 item->viewPrivData()->saveLayers( layers, layers_count );
1481 for(
int i = 0; i < layers_count; ++i )
1483 wxCHECK2_MSG( layers[i] >= 0 &&
static_cast<unsigned>( layers[i] ) <
m_layers.size(),
1484 continue, wxS(
"Invalid layer" ) );
1486 l.
items->Insert( item, bbox );
1490 item->viewPrivData()->m_requiredUpdate &= ~(
LAYERS |
GEOMETRY );
1500 if( item->viewPrivData() && item->viewPrivData()->m_requiredUpdate !=
NONE )
1503 item->viewPrivData()->m_requiredUpdate =
NONE;
1509 cntGeomUpdate, (
unsigned) anyUpdated );
1517 if( item->viewPrivData() )
1518 item->viewPrivData()->m_requiredUpdate |= aUpdateFlags;
1524 std::function<
bool(
VIEW_ITEM* )> aCondition )
1528 if( aCondition( item ) )
1530 if( item->viewPrivData() )
1531 item->viewPrivData()->m_requiredUpdate |= aUpdateFlags;
1541 if( item->viewPrivData() )
1542 item->viewPrivData()->m_requiredUpdate |= aItemFlagsProvider( item );
1550 std::unique_ptr<VIEW> ret = std::make_unique<VIEW>();
1567 if( cur_visible != aIsVisible )
1572 viewData->
m_flags &= ~VISIBLE;
1621 return viewData && viewData->
m_view ==
this;
1638 assert( aUpdateFlags !=
NONE );
1646 std::shared_ptr<VIEW_OVERLAY>
overlay = std::make_shared<VIEW_OVERLAY>();
1677 Hide( aItem,
false );
1680 if( aTakeOwnership )
constexpr int ARC_LOW_DEF
BOX2I BOX2ISafe(const BOX2D &aInput)
void SetOrigin(const Vec &pos)
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
void SetSize(const SizeVec &size)
const SizeVec & GetSize() const
size_type GetHeight() const
coord_type GetTop() const
size_type GetWidth() const
bool Contains(const Vec &aPoint) const
coord_type GetRight() const
coord_type GetLeft() const
coord_type GetBottom() const
void SetEnd(coord_type x, coord_type y)
A color representation with 4 components: red, green, blue, alpha.
Abstract interface for drawing on a 2D-surface.
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)
const MATRIX3x3D & GetWorldScreenMatrix() const
Get the world <-> screen transformation matrix.
virtual void StartDiffLayer()
Begins rendering of a differential layer.
virtual void EndDiffLayer()
Ends rendering of a differential layer.
void SetFlip(bool xAxis, bool yAxis)
Sets flipping of the screen.
virtual void DeleteGroup(int aGroupNumber)
Delete the group from the memory.
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
virtual void ClearTarget(RENDER_TARGET aTarget)
Clear the target for rendering.
void SetZoomFactor(double aZoomFactor)
virtual int BeginGroup()
Begin a group.
virtual void ChangeGroupDepth(int aGroupNumber, int aDepth)
Change the depth (Z-axis position) of the group.
virtual void EndNegativesLayer()
Ends rendering of a negatives layer and draws it to the main layer.
virtual void StartNegativesLayer()
Begins rendering in a new layer that will be copied to the main layer in EndNegativesLayer().
virtual void ChangeGroupColor(int aGroupNumber, const COLOR4D &aNewColor)
Change the color used to draw the group.
virtual void DrawGroup(int aGroupNumber)
Draw the stored group.
void SetLookAtPoint(const VECTOR2D &aPoint)
Get/set the Point in world space to look at.
virtual bool IsInitialized() const
Return the initialization status for the canvas.
virtual void ComputeWorldScreenMatrix()
Compute the world <-> screen transformation matrix.
virtual void EndGroup()
End the group.
virtual void ClearCache()
Delete all data created during caching of graphic items.
virtual void SetTarget(RENDER_TARGET aTarget)
Set the target for rendering.
const VECTOR2I & GetScreenPixelSize() const
Return GAL canvas size in pixels.
virtual bool IsVisible() const
Return true if the GAL canvas is visible on the screen.
virtual void EnableDepthTest(bool aEnabled=false)
Contains all the knowledge about how to draw graphical object onto any particular output device.
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.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
virtual COLOR4D GetColor(const VIEW_ITEM *aItem, int aLayer) const =0
Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer using curr...
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.
void reorderGroups(std::unordered_map< int, int > aReorderMap)
Reorder the stored groups (to facilitate reordering of layers).
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.
BOX2I m_bbox
Stores layer numbers used by the item.
void getLayers(int *aLayers, int &aCount) const
Return layer numbers used by the item.
void saveLayers(int *aLayers, int aCount)
Save layers used by the item.
void setGroup(int aLayer, int aGroup)
Set a group id for the item and the layer combination.
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 void ViewGetLayers(int aLayers[], int &aCount) const =0
Return the all the layers within the VIEW the object is painted on.
virtual double ViewGetLOD(int aLayer, 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.
void SortLayers(int aLayers[], int &aCount) const
Change the order of given layer ids, so after sorting the order corresponds to layers rendering order...
void ShowPreview(bool aShow=true)
void sortLayers()
Clear cached GAL group numbers (ONLY numbers stored in VIEW_ITEMs, not group objects used by GAL)
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
std::vector< VIEW_LAYER > m_layers
Sorted list of pointers to members of m_layers.
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
void draw(VIEW_ITEM *aItem, int aLayer, bool aImmediate=false)
Draw an item, but on a specified layers.
std::vector< VIEW_ITEM * > m_ownedItems
Whether to use rendering order modifier or not.
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
void updateItemColor(VIEW_ITEM *aItem, int aLayer)
Update all information needed to draw an item.
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.
static bool compareRenderingOrder(VIEW_LAYER *aI, VIEW_LAYER *aJ)
Check if every layer required by the aLayerId layer is enabled.
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 UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
bool m_mirrorY
PAINTER contains information how do draw items.
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
The set of layers that are displayed on the top.
std::shared_ptr< VIEW_OVERLAY > MakeOverlay()
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
virtual int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Find all visible items that touch or are within the rectangle aRect.
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
Interface to #PAINTER that is used to draw items.
virtual void Redraw()
Immediately redraws the whole view.
void Clear()
Remove all items from the view.
std::set< unsigned int > m_topLayers
Center point of the VIEW (the point at which we are looking at).
bool m_enableOrderModifier
The set of possible displayed layers and its properties.
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
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).
void MarkClean()
Force redraw of view on the next rendering.
void updateItemGeometry(VIEW_ITEM *aItem, int aLayer)
Update bounding box of an item.
static constexpr int VIEW_MAX_LAYERS
Rendering order modifier for layers that are marked as top layers.
void updateLayers(VIEW_ITEM *aItem)
Determine rendering order of layers. Used in display order sorting function.
void RecacheAllItems()
Rebuild GAL display lists.
bool areRequiredLayersEnabled(int aLayerId) const
bool IsTargetDirty(int aTarget) const
Return true if any of layers belonging to the target or the target itself should be redrawn.
int m_nextDrawPriority
Flag to reverse the draw order when using draw priority.
VIEW(bool aIsDynamic=true)
bool m_useDrawPriority
The next sequential drawing priority.
void UpdateItems()
Iterate through the list of items that asked for updating and updates them.
bool IsCached(int aLayer) const
Return true if the layer is cached.
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
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...
GAL * m_gal
Dynamic VIEW (eg.
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 SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
std::vector< VIEW_LAYER * > m_orderedLayers
Flat list of all items.
void SetLayerOrder(int aLayer, int aRenderingOrder)
Set rendering order of a particular layer.
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
void updateBbox(VIEW_ITEM *aItem)
Update set of layers that an item occupies.
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
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)
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.
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset difference For aFastMode meaning, see function booleanOp.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
void Deflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError)
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
The Cairo implementation of the graphics abstraction layer.
@ 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
CONTAINER::value_type item_type
QUERY_VISITOR(CONTAINER &aCont, int aLayer)
bool operator()(VIEW_ITEM *aItem)
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)
bool operator()(VIEW_ITEM *aItem)
UPDATE_COLOR_VISITOR(int aLayer, PAINTER *aPainter, GAL *aGal)
UPDATE_DEPTH_VISITOR(int aLayer, int aDepth, GAL *aGal)
bool operator()(VIEW_ITEM *aItem)
int renderingOrder
Rendering order of this layer.
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.
#define KI_TRACE(aWhat,...)
VECTOR2< double > VECTOR2D