45 #ifdef KICAD_GAL_PROFILE 85 int* layersPtr = aLayers;
129 std::pair<int, int>* newGroups =
new std::pair<int, int>[
m_groupsSize + 1];
176 int new_layer = orig_layer;
180 new_layer = aReorderMap.at( orig_layer );
182 catch(
const std::out_of_range& )
199 for(
int i = 0; i < aCount; ++i )
253 data->
m_view->VIEW::Remove( aItem );
261 m_enableOrderModifier( true ),
263 m_minScale( 0.2 ), m_maxScale( 50000.0 ),
264 m_mirrorX( false ), m_mirrorY( false ),
265 m_painter( nullptr ),
267 m_dynamic( aIsDynamic ),
268 m_useDrawPriority( false ),
269 m_nextDrawPriority( 0 ),
270 m_reverseDrawOrder( false )
276 typedef std::numeric_limits<int> coord_limits;
277 double pos = coord_limits::lowest() / 2 + coord_limits::epsilon();
278 double size = coord_limits::max() - coord_limits::epsilon();
282 m_allItems.reset(
new std::vector<VIEW_ITEM*> );
297 m_layers[ii].items = std::make_shared<VIEW_RTREE>();
324 if( aDrawPriority < 0 )
338 for(
int i = 0; i < layers_count; ++i )
341 l.
items->Insert( aItem );
360 wxCHECK( viewData->m_view ==
this, );
366 viewData->clearUpdateFlags();
370 viewData->getLayers( layers, layers_count );
372 for(
int i = 0; i < layers_count; ++i )
375 l.
items->Remove( aItem );
379 int prevGroup = viewData->getGroup( layers[i] );
385 viewData->deleteGroups();
386 viewData->m_view =
nullptr;
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 );
403 template <
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( ssize.
x > 0 && 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() )
610 VECTOR2D unobscuredCenter = screenRect.Centre();
612 for(
const BOX2D& obscuringScreenRect : obscuringScreenRects )
622 BOX2I bbox = unobscuredPoly.BBox();
625 while( !unobscuredPoly.IsEmpty() )
627 unobscuredCenter = (wxPoint) unobscuredPoly.BBox().Centre();
628 unobscuredPoly.Deflate( step, 4 );
631 SetCenter( aCenter -
ToWorld( unobscuredCenter - screenRect.Centre(), false ) );
637 m_layers[aLayer].renderingOrder = aRenderingOrder;
645 return m_layers.at( aLayer ).renderingOrder;
651 int maxLay, maxOrd, maxIdx;
653 for(
int i = 0; i < aCount; ++i )
660 for(
int j = i; j < aCount; ++j )
671 aLayers[maxIdx] = aLayers[i];
679 std::vector<VIEW_LAYER> new_map;
683 new_map.push_back( layer );
685 for(
auto& pair : aReorderMap )
687 new_map[pair.second] =
m_layers[pair.first];
688 new_map[pair.second].id = pair.second;
702 item->ViewGetLayers( layers, layers_count );
756 m_layers[aLayer].items->Query(
r, visitor );
776 viewData->
getLayers( layers, layers_count );
778 for(
int i = 0; i < layers_count; ++i )
860 std::set<unsigned int>::iterator it;
880 std::set<unsigned int>::iterator it;
909 viewData->
getLayers( layers, layers_count );
911 for(
int i = 0; i < layers_count; ++i )
998 else if( l->hasNegatives )
1002 l->items->Query( aRect, drawFunc );
1009 else if( l->hasNegatives )
1023 if(
IsCached( aLayer ) && !aImmediate )
1051 for(
int i = 0; i < layers_count; ++i )
1054 draw( aItem, layers[i], aImmediate );
1061 for(
unsigned int i = 0; i < aGroup->
GetSize(); i++)
1107 layer.items->RemoveAll();
1136 #ifdef KICAD_GAL_PROFILE 1149 if( rect.
GetWidth() > std::numeric_limits<int>::max()
1150 || rect.
GetHeight() > std::numeric_limits<int>::max() )
1160 #ifdef KICAD_GAL_PROFILE 1161 totalRealTime.Stop();
1162 wxLogTrace(
traceGalProfile, wxT(
"VIEW::Redraw(): %.1f ms" ), totalRealTime.msecs() );
1199 layer.items->Query(
r, visitor );
1215 if( aUpdateFlags &
LAYERS )
1225 for(
int i = 0; i < layers_count; ++i )
1227 int layerId = layers[i];
1233 else if( aUpdateFlags &
COLOR )
1263 wxCHECK( (
unsigned) aLayer <
m_layers.size(), );
1282 wxCHECK( (
unsigned) aLayer <
m_layers.size(), );
1302 if( !
m_painter->
Draw( static_cast<EDA_ITEM*>( aItem ), aLayer ) )
1315 for(
int i = 0; i < layers_count; ++i )
1318 l.
items->Remove( aItem );
1319 l.
items->Insert( aItem );
1334 viewData->
getLayers( layers, layers_count );
1336 for(
int i = 0; i < layers_count; ++i )
1339 l.
items->Remove( aItem );
1345 int prevGroup = viewData->
getGroup( layers[i] );
1347 if( prevGroup >= 0 )
1357 viewData->
saveLayers( layers, layers_count );
1359 for(
int i = 0; i < layers_count; i++ )
1362 l.
items->Insert( aItem );
1370 wxCHECK( (
unsigned) aLayerId <
m_layers.size(), false );
1372 std::set<int>::const_iterator it, it_end;
1374 for(
int layer :
m_layers.at( aLayerId ).requiredLayers )
1396 l.items->Query(
r, visitor );
1407 unsigned int cntGeomUpdate = 0;
1408 unsigned int cntAnyUpdate = 0;
1412 auto vpd = item->viewPrivData();
1421 if( vpd->m_requiredUpdate !=
NONE )
1429 double ratio = (double) cntGeomUpdate / (
double) cntTotal;
1444 layer.items->RemoveAll();
1449 item->ViewGetLayers( layers, layers_count );
1450 item->viewPrivData()->saveLayers( layers, layers_count );
1452 for(
int i = 0; i < layers_count; ++i )
1455 l.
items->Insert( item );
1459 item->viewPrivData()->m_requiredUpdate &= ~(
LAYERS |
GEOMETRY );
1469 if( item->viewPrivData() && item->viewPrivData()->m_requiredUpdate !=
NONE )
1472 item->viewPrivData()->m_requiredUpdate =
NONE;
1478 cntGeomUpdate, cntAnyUpdate );
1486 if( item->viewPrivData() )
1487 item->viewPrivData()->m_requiredUpdate |= aUpdateFlags;
1493 std::function<
bool(
VIEW_ITEM* )> aCondition )
1497 if( aCondition( item ) )
1499 if( item->viewPrivData() )
1500 item->viewPrivData()->m_requiredUpdate |= aUpdateFlags;
1508 std::unique_ptr<VIEW> ret = std::make_unique<VIEW>();
1525 if( cur_visible != aIsVisible )
1577 assert( aUpdateFlags !=
NONE );
1616 Hide( aItem,
false );
1619 if( aTakeOwnership )
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
Return current update flag for an item.
void deleteGroups()
Remove 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
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.
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > overlay
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.
coord_type GetTop() const
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.
bool operator()(VIEW_ITEM *aItem)
void SetFlip(bool xAxis, bool yAxis)
Sets flipping of the screen.
bool operator()(VIEW_ITEM *aItem)
GAL * m_gal
Dynamic VIEW (eg.
bool areRequiredLayersEnabled(int aLayerId) const
coord_type GetRight() const
QUERY_VISITOR(CONTAINER &aCont, int aLayer)
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()
Mark an item as already updated, so it is not going to be redrawn.
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Visibility flag has changed.
bool operator()(VIEW_ITEM *aItem)
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 thread-safe event counter.
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
Return 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)
Set a group id for the item and the layer combination.
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
VIEW * m_view
Current dynamic view the item is assigned to.
bool operator()(VIEW_ITEM *aItem)
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
Return number of the group id for the given layer, or -1 in case it was not cached before.
void ShowPreview(bool aShow=true)
UPDATE_COLOR_VISITOR(int aLayer, PAINTER *aPainter, GAL *aGal)
virtual void ChangeGroupColor(int aGroupNumber, const COLOR4D &aNewColor)
Change the color used to draw the group.
const VECTOR2I & GetScreenPixelSize() const
Return GAL canvas size in pixels.
virtual unsigned int GetSize() const
Return the number of stored items.
int layers[VIEW_MAX_LAYERS]
Contains all the knowledge about how to draw graphical object onto any particular output device.
Item needs to be redrawn.
virtual void EndDiffLayer()
Ends rendering of a differential layer.
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.
UPDATE_DEPTH_VISITOR(int aLayer, int aDepth, GAL *aGal)
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).
Represent a set of closed polygons.
VIEW_ITEM_DATA * viewPrivData() const
bool operator()(VIEW_ITEM *aItem)
virtual int GetTopLayer() const
coord_type GetWidth() const
virtual int BeginGroup()
Begin a group.
BOX2< Vec > & Normalize()
Ensure that the height ant width are positive.
bool Contains(const Vec &aPoint) const
virtual void ClearTarget(RENDER_TARGET aTarget)
Clear 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.
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)
Reorder the stored groups (to facilitate reordering of layers).
Extend VIEW_ITEM by possibility of grouping items into a single object.
Items that may change while the view stays the same (noncached)
wxLogTrace helper definitions.
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 updateBbox(VIEW_ITEM *aItem)
Update set of layers that an item occupies.
virtual void StartNegativesLayer()
Begins rendering in a new layer that will be copied to the main layer in EndNegativesLayer().
PAINTER * m_painter
Interface to #PAINTER that is used to draw items.
Item is visible (in general)
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)
Save layers used by the item.
bool operator()(VIEW_ITEM *aItem)
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).
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.
virtual void StartDiffLayer()
Begins rendering of a differential layer.
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.
std::pair< int, int > * m_groups
layer_number:group_id pairs for each layer the item occupies.
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...
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
CONTAINER::value_type item_type
void redrawRect(const BOX2I &aRect)
bool isRenderable() const
Return 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.
Main rendering target (cached)
CLEAR_LAYER_CACHE_VISITOR(VIEW *aView)
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...
std::vector< VIEW_LAYER * > m_orderedLayers
Flat list of all items.
void MarkClean()
Force redraw of view on the next rendering.
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
Return 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)
Change 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.
virtual void EndNegativesLayer()
Ends rendering of a negatives layer and draws it to the main layer.
void CopySettings(const VIEW *aOtherView)
Copy layers and visibility settings from another view.
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.
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...
DRAW_ITEM_VISITOR(VIEW *aView, int aLayer, bool aUseDrawPriority, bool aReverseDrawOrder)
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
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
int m_requiredUpdate
Flag required for updating.
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)
Set the target for rendering.
void MarkDirty()
Force redraw of view on the next rendering.
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...
std::vector< VIEW_ITEM * > drawItems
void getLayers(int *aLayers, int &aCount) const
Return layer numbers used by the item.
Abstract interface for drawing on a 2D-surface.
Position or shape has changed.
RECACHE_ITEM_VISITOR(VIEW *aView, GAL *aGal, int aLayer)
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.
RENDER_TARGET target
Where the layer should be rendered.
std::shared_ptr< VIEW_RTREE > items
R-tree indexing all items on this layer.