81 int* layersPtr = aLayers;
188 int new_layer = orig_layer;
192 new_layer = aReorderMap.at( orig_layer );
194 catch(
const std::out_of_range& ) {}
215 for(
int i = 0; i < aCount; ++i )
261 data->
m_view->VIEW::Remove( aItem );
269 m_enableOrderModifier( true ),
271 m_minScale( 0.2 ), m_maxScale( 5000.0 ),
272 m_mirrorX( false ), m_mirrorY( false ),
275 m_dynamic( aIsDynamic ),
276 m_useDrawPriority( false ),
277 m_nextDrawPriority( 0 ),
278 m_reverseDrawOrder( false )
284 typedef std::numeric_limits<int> coord_limits;
285 double pos = coord_limits::lowest() / 2 + coord_limits::epsilon();
286 double size = coord_limits::max() - coord_limits::epsilon();
291 m_allItems.reset(
new std::vector<VIEW_ITEM*> );
306 m_layers[ii].items = std::make_shared<VIEW_RTREE>();
331 if( aDrawPriority < 0 )
345 for(
int i = 0; i < layers_count; ++i )
348 l.
items->Insert( aItem );
367 wxCHECK( viewData->m_view ==
this, );
373 viewData->clearUpdateFlags();
377 viewData->getLayers( layers, layers_count );
379 for(
int i = 0; i < layers_count; ++i )
382 l.
items->Remove( aItem );
386 int prevGroup = viewData->getGroup( layers[i] );
392 viewData->deleteGroups();
393 viewData->m_view =
nullptr;
399 wxCHECK( (
unsigned) aLayerId <
m_layers.size(), );
400 wxCHECK( (
unsigned) aRequiredId <
m_layers.size(), );
403 m_layers[aLayerId].requiredLayers.insert( aRequiredId );
405 m_layers[aLayerId].requiredLayers.erase( aRequired );
410 template <
class Container>
438 std::vector<VIEW_LAYER*>::const_reverse_iterator i;
445 if( ( *i )->displayOnly || !( *i )->visible )
449 ( *i )->items->Query( aRect, visitor );
452 return aResult.size();
471 return fabs( matrix.
GetScale().
x * aSize );
496 wxASSERT_MSG(
false, wxT(
"This is not implemented" ) );
502 bool recacheGroups = (
m_gal != nullptr );
535 wxCHECK( ssize.
x > 0 && ssize.
y > 0, );
539 double zoom = 1.0 / std::max( fabs( vsize.
x / ssize.
x ), fabs( vsize.
y / ssize.
y ) );
548 wxASSERT_MSG( !aMirrorY,
_(
"Mirroring for Y axis is not supported yet" ) );
614 if( !screenRect.Intersects( occultingScreenRect ) )
621 double topExposed = occultedRect.
GetTop() - screenRect.GetTop();
622 double bottomExposed = screenRect.GetBottom() - occultedRect.
GetBottom();
623 double leftExposed = occultedRect.
GetLeft() - screenRect.GetLeft();
624 double rightExposed = screenRect.GetRight() - occultedRect.
GetRight();
626 if( std::max( topExposed, bottomExposed ) > std::max( leftExposed, rightExposed ) )
628 if( topExposed > bottomExposed )
629 aCenter.
y +=
ToWorld( screenRect.GetHeight() / 2 - topExposed / 2 );
631 aCenter.
y -=
ToWorld( screenRect.GetHeight() / 2 - bottomExposed / 2 );
635 if( leftExposed > rightExposed )
636 aCenter.
x +=
ToWorld( screenRect.GetWidth() / 2 - leftExposed / 2 );
638 aCenter.
x -=
ToWorld( screenRect.GetWidth() / 2 - rightExposed / 2 );
647 m_layers[aLayer].renderingOrder = aRenderingOrder;
655 return m_layers.at( aLayer ).renderingOrder;
661 int maxLay, maxOrd, maxIdx;
663 for(
int i = 0; i < aCount; ++i )
670 for(
int j = i; j < aCount; ++j )
681 aLayers[maxIdx] = aLayers[i];
689 std::vector<VIEW_LAYER> new_map;
693 new_map.emplace_back();
697 int orig_idx = layer.id;
698 int new_idx = orig_idx;
700 if( aReorderMap.count( orig_idx ) )
701 new_idx = aReorderMap.at( orig_idx );
703 new_map[new_idx] = layer;
704 new_map[new_idx].id = new_idx;
711 auto viewData = item->viewPrivData();
718 item->ViewGetLayers( layers, layers_count );
719 viewData->saveLayers( layers, layers_count );
721 viewData->reorderGroups( aReorderMap );
723 viewData->m_requiredUpdate |=
COLOR;
770 m_layers[aLayer].items->Query( r, visitor );
784 auto viewData = item->viewPrivData();
790 viewData->getLayers( layers, layers_count );
792 for(
int i = 0; i < layers_count; ++i )
795 int group = viewData->getGroup( layers[i] );
872 std::set<unsigned int>::iterator it;
892 std::set<unsigned int>::iterator it;
915 auto viewData = item->viewPrivData();
921 viewData->getLayers( layers, layers_count );
923 for(
int i = 0; i < layers_count; ++i )
925 int group = viewData->getGroup( layers[i] );
939 drawItem(
VIEW* aView,
int aLayer,
bool aUseDrawPriority,
bool aReverseDrawOrder ) :
998 l->items->Query( aRect, drawFunc );
1014 if(
IsCached( aLayer ) && !aImmediate )
1017 int group = viewData->
getGroup( aLayer );
1042 for(
int i = 0; i < layers_count; ++i )
1045 draw( aItem, layers[i], aImmediate );
1052 for(
unsigned int i = 0; i < aGroup->
GetSize(); i++)
1077 viewData->setGroup(
layer, -1 );
1096 layer.items->RemoveAll();
1138 if( rect.
GetWidth() > std::numeric_limits<int>::max() ||
1139 rect.
GetHeight() > std::numeric_limits<int>::max() )
1149 totalRealTime.
Stop();
1150 wxLogTrace(
"GAL_PROFILE",
"VIEW::Redraw(): %.1f ms", totalRealTime.
msecs() );
1187 layer.items->Query( r, visitor );
1202 if( aUpdateFlags &
LAYERS )
1216 for(
int i = 0; i < layers_count; ++i )
1218 int layerId = layers[i];
1224 else if( aUpdateFlags &
COLOR )
1254 wxCHECK( (
unsigned) aLayer <
m_layers.size(), );
1262 int group = viewData->getGroup( aLayer );
1273 wxCHECK( (
unsigned) aLayer <
m_layers.size(), );
1285 int group = viewData->getGroup( aLayer );
1291 viewData->setGroup( aLayer, group );
1293 if( !
m_painter->
Draw( static_cast<EDA_ITEM*>( aItem ), aLayer ) )
1306 for(
int i = 0; i < layers_count; ++i )
1309 l.
items->Remove( aItem );
1310 l.
items->Insert( aItem );
1325 viewData->
getLayers( layers, layers_count );
1327 for(
int i = 0; i < layers_count; ++i )
1330 l.
items->Remove( aItem );
1336 int prevGroup = viewData->getGroup( layers[i] );
1338 if( prevGroup >= 0 )
1341 viewData->setGroup( l.
id, -1 );
1348 viewData->saveLayers( layers, layers_count );
1350 for(
int i = 0; i < layers_count; i++ )
1353 l.
items->Insert( aItem );
1361 wxCHECK( (
unsigned) aLayerId <
m_layers.size(), false );
1363 std::set<int>::const_iterator it, it_end;
1365 for( it =
m_layers.at( aLayerId ).requiredLayers.begin(),
1366 it_end =
m_layers.at( aLayerId ).requiredLayers.end(); it != it_end; ++it )
1388 l.items->Query( r, visitor );
1402 auto viewData = item->viewPrivData();
1407 if( viewData->m_requiredUpdate !=
NONE )
1410 viewData->m_requiredUpdate =
NONE;
1421 auto viewData = item->viewPrivData();
1426 viewData->m_requiredUpdate |= aUpdateFlags;
1432 std::function<
bool(
VIEW_ITEM* )> aCondition )
1436 if( aCondition( item ) )
1438 auto viewData = item->viewPrivData();
1443 viewData->m_requiredUpdate |= aUpdateFlags;
1451 auto ret = std::make_unique<VIEW>();
1468 if( cur_visible != aIsVisible )
1473 viewData->m_flags &= ~
VISIBLE;
1487 if( !( viewData->m_flags &
VISIBLE ) )
1493 viewData->m_flags &= ~
HIDDEN;
1503 return viewData && ( viewData->m_flags &
VISIBLE );
1520 assert( aUpdateFlags !=
NONE );
1528 std::shared_ptr<VIEW_OVERLAY> overlay(
new VIEW_OVERLAY );
1530 Add( overlay.get() );
1556 Hide( aItem,
false );
1559 if( aTakeOwnership )
void Stop()
Save the time when this function was called, and set the counter stane to stop.
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hide the item in the view (e.g.
virtual void DrawGroup(int aGroupNumber)
Draw the stored group.
Item is being added to the view.
Item is temporarily hidden (e.g.
int requiredUpdate() const
Function viewRequiredUpdate() Returns current update flag for an item.
void deleteGroups()
Function deleteGroups() Removes all of the stored group ids.
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
VIEW_ITEM_DATA * m_viewPrivData
void SetViewport(const BOX2D &aViewport)
Set the visible area of the VIEW.
void updateLayers(VIEW_ITEM *aItem)
Determine rendering order of layers. Used in display order sorting function.
void UpdateAllItemsConditionally(int aUpdateFlags, std::function< bool(VIEW_ITEM *)> aCondition)
Update items in the view according to the given flags and condition.
void SetLayerOrder(int aLayer, int aRenderingOrder)
Set rendering order of a particular layer.
void SetRequired(int aLayerId, int aRequiredId, bool aRequired=true)
Mark the aRequiredId layer as required for the aLayerId layer.
void updateItemColor(VIEW_ITEM *aItem, int aLayer)
Update all information needed to draw an item.
bool m_useDrawPriority
The next sequential drawing priority.
std::unique_ptr< KIGFX::VIEW_GROUP > m_preview
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
virtual void DeleteGroup(int aGroupNumber)
Delete the group from the memory.
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.
static const int TOP_LAYER_MODIFIER
Flag to respect draw priority when drawing items.
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
void sortLayers()
Clear cached GAL group numbers (ONLY numbers stored in VIEW_ITEMs, not group objects used by GAL)
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
double msecs(bool aSinceLast=false)
coord_type GetTop() const
queryVisitor(Container &aCont, int aLayer)
void AddToPreview(EDA_ITEM *aItem, bool aTakeOwnership=true)
void RecacheAllItems()
Rebuild GAL display lists.
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
void SetFlip(bool xAxis, bool yAxis)
Sets flipping of the screen.
GAL * m_gal
Dynamic VIEW (eg.
bool areRequiredLayersEnabled(int aLayerId) const
coord_type GetRight() const
std::set< unsigned int > m_topLayers
Center point of the VIEW (the point at which we are looking at).
void SetSize(const Vec &size)
void clearUpdateFlags()
Function clearUpdateFlags() Marks an item as already updated, so it is not going to be redrawn.
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Visibility flag has changed.
coord_type GetBottom() const
void SetMirror(bool aMirrorX, bool aMirrorY)
Control the mirroring of the VIEW.
An abstract base class for deriving all objects that can be added to a VIEW.
virtual void ComputeWorldScreenMatrix()
Compute the world <-> screen transformation matrix.
A small class to help profiling.
virtual VIEW_ITEM * GetItem(unsigned int aIdx) const
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)
std::shared_ptr< VIEW_OVERLAY > MakeOverlay()
bool storesGroups() const
Function storesGroups() Returns information if the item uses at least one group id (ie.
virtual void EnableTopLayer(bool aEnable)
Enable or disable display of the top layer.
void setGroup(int aLayer, int aGroup)
Function setGroup() Sets a group id for the item and the layer combination.
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
VECTOR2D m_center
Scale of displayed VIEW_ITEMs.
VIEW * m_view
Current dynamic view the item is assigned to.
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
virtual void EndGroup()
End the group.
Auxiliary rendering target (noncached)
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
The set of layers that are displayed on the top.
void SortLayers(int aLayers[], int &aCount) const
Change the order of given layer ids, so after sorting the order corresponds to layers rendering order...
int getGroup(int aLayer) const
Function getGroup() Returns number of the group id for the given layer, or -1 in case it was not cach...
void ShowPreview(bool aShow=true)
double m_minScale
Scale upper limit.
bool operator()(VIEW_ITEM *aItem)
virtual void ChangeGroupColor(int aGroupNumber, const COLOR4D &aNewColor)
Changes the color used to draw the group.
drawItem(VIEW *aView, int aLayer, bool aUseDrawPriority, bool aReverseDrawOrder)
const VECTOR2I & GetScreenPixelSize() const
Returns GAL canvas size in pixels.
virtual unsigned int GetSize() const
Return the number of stored items.
void SetPrintMode(int aPrintMode)
Set the printing mode.
Contains all the knowledge about how to draw graphical object onto any particular output device.
Container::value_type item_type
bool operator()(VIEW_ITEM *aItem)
clearLayerCache(VIEW *aView)
Item needs to be redrawn.
VIEW_ITEM class definition.
int m_drawPriority
Order to draw this item in a layer, lowest first.
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
VECTOR2< double > VECTOR2D
virtual void Redraw()
Immediately redraws the whole view.
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
bool IsTargetDirty(int aTarget) const
Return true if any of layers belonging to the target or the target itself should be redrawn.
void Clear()
Remove all items from the view.
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
VIEW_ITEM_DATA * viewPrivData() const
virtual int GetTopLayer() const
coord_type GetWidth() const
virtual int BeginGroup()
Begin a group.
BOX2< Vec > & Normalize()
Function Normalize ensures that the height ant width are positive.
bool Contains(const Vec &aPoint) const
Function Contains.
virtual void ClearTarget(RENDER_TARGET aTarget)
Clears the target for rendering.
virtual void ViewGetLayers(int aLayers[], int &aCount) const =0
Return the all the layers within the VIEW the object is painted on.
bool m_mirrorX
Vertical flip flag.
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.
void reorderGroups(std::unordered_map< int, int > aReorderMap)
Reorders the stored groups (to facilitate reordering of layers)
int layers[VIEW_MAX_LAYERS]
Extend VIEW_ITEM by possibility of grouping items into a single object.
Items that may change while the view stays the same (noncached)
void ReorderLayerData(std::unordered_map< int, int > aReorderMap)
Remap the data between layer ids without invalidating that data.
void UpdateItems()
Iterate through the list of items that asked for updating and updates them.
void markTargetClean(int aTarget)
GroupPair * m_groups
Indexes of cached GAL display lists corresponding to the item (for every layer it occupies).
void updateBbox(VIEW_ITEM *aItem)
Update set of layers that an item occupies.
PAINTER * m_painter
Interface to #PAINTER that is used to draw items.
bool m_reverseDrawOrder
A control for printing: m_printMode <= 0 means no printing mode (normal draw mode m_printMode > 0 is ...
Item is visible (in general)
changeItemsDepth(int aLayer, int aDepth, GAL *aGal)
int m_nextDrawPriority
Flag to reverse the draw order when using draw priority.
VECTOR2D ToScreen(const VECTOR2D &aCoord, bool aAbsolute=true) const
Convert a world space point/vector to a point/vector in screen space coordinates.
void saveLayers(int *aLayers, int aCount)
Function saveLayers() Saves layers used by the item.
std::vector< VIEW_LAYER > m_layers
Sorted list of pointers to members of m_layers.
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
bool operator()(VIEW_ITEM *aItem)
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 SetEnd(coord_type x, coord_type y)
const Vec & GetPosition() const
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
double m_maxScale
Horizontal flip flag.
void UpdateLayerColor(int aLayer)
Apply the new coloring scheme held by RENDER_SETTINGS in case that it has changed.
std::unique_ptr< VIEW > DataReference() const
Return a new VIEW object that shares the same set of VIEW_ITEMs and LAYERs.
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...
std::vector< VIEW_ITEM * > drawItems
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
bool operator()(VIEW_ITEM *aItem)
bool operator()(VIEW_ITEM *aItem)
void redrawRect(const BOX2I &aRect)
bool isRenderable() const
Function isRenderable() Returns if the item should be drawn or not.
std::vector< EDA_ITEM * > m_ownedItems
Whether to use rendering order modifier or not.
void updateItemGeometry(VIEW_ITEM *aItem, int aLayer)
Update bounding box of an item.
Board layer functions and definitions.
Main rendering target (cached)
bool m_enableOrderModifier
The set of possible displayed layers and its properties.
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...
BOX2D m_boundary
Scale lower limit.
std::vector< VIEW_LAYER * > m_orderedLayers
Flat list of all items.
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
int GetLayerOrder(int aLayer) const
Return rendering order of a particular layer.
void draw(VIEW_ITEM *aItem, int aLayer, bool aImmediate=false)
Draw an item, but on a specified layers.
bool IsCached(int aLayer) const
Return true if the layer is cached.
void SetOrigin(const Vec &pos)
virtual bool IsVisible() const
Returns true if the GAL canvas is visible on the screen.
void SetZoomFactor(double aZoomFactor)
Set the zoom factor of the scene.
virtual void ChangeGroupDepth(int aGroupNumber, int aDepth)
Changes the depth (Z-axis position) of the group.
A base class for most all the KiCad significant classes used in schematics and boards.
bool m_mirrorY
PAINTER contains information how do draw items.
void ClearTargets()
Clear targets that are marked as dirty.
coord_type GetHeight() const
int m_flags
Visibility flags.
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
void CopySettings(const VIEW *aOtherView)
Copy layers and visibility settings from another view.
double m_scale
View boundaries.
int renderingOrder
Rendering order of this layer.
void SetLookAtPoint(const VECTOR2D &aPoint)
Set the Point in world space to look at.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
std::pair< int, int > GroupPair
Helper for storing cached items group ids
const Vec & GetSize() const
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.
coord_type GetLeft() const
VIEW(bool aIsDynamic=true)
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
const MATRIX3x3D & GetWorldScreenMatrix() const
Get the world <-> screen transformation matrix.
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
std::vector< int > m_layers
Stores layer numbers used by the item.
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
int m_requiredUpdate
Flag required for updating.
recacheItem(VIEW *aView, GAL *aGal, int aLayer)
static bool compareRenderingOrder(VIEW_LAYER *aI, VIEW_LAYER *aJ)
Check if every layer required by the aLayerId layer is enabled.
virtual void ClearCache()
Delete all data created during caching of graphic items.
virtual void SetTarget(RENDER_TARGET aTarget)
Sets the target for rendering.
void MarkDirty()
Force redraw of view on the next rendering.
updateItemsColor(int aLayer, PAINTER *aPainter, GAL *aGal)
virtual double ViewGetLOD(int aLayer, VIEW *aView) const
Return the level of detail (LOD) of the item.
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 getLayers(int *aLayers, int &aCount) const
Function getLayers() Returns layer numbers used by the item.
Class GAL is the abstract interface for drawing on a 2D-surface.
Position or shape has changed.
bool operator()(VIEW_ITEM *aItem)
virtual void ViewDraw(int aLayer, VIEW *aView) const
Draw the parts of the object belonging to layer aLayer.
A color representation with 4 components: red, green, blue, alpha.
BOX2< Vec > Intersect(const BOX2< Vec > &aRect)
Function Intersect Returns the intersection of this with another rectangle.
RENDER_TARGET target
Where the layer should be rendered.
std::shared_ptr< VIEW_RTREE > items
R-tree indexing all items on this layer.