Commit 9c4e0237 authored by Maciej Suminski's avatar Maciej Suminski

Added the 'cached' parameter for VIEW_LAYER. The parameter decides if items...

Added the 'cached' parameter for VIEW_LAYER. The parameter decides if items drawn on the layer should be cached or drawn in immediate mode.
Removed m_useGroups from VIEW, as now groups are enabled per layer.
parent aff3787b
...@@ -65,7 +65,7 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin ...@@ -65,7 +65,7 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
m_painter = new KiGfx::PCB_PAINTER( m_gal ); m_painter = new KiGfx::PCB_PAINTER( m_gal );
m_view = new KiGfx::VIEW( true, true ); m_view = new KiGfx::VIEW( true );
m_view->SetPainter( m_painter ); m_view->SetPainter( m_painter );
m_view->SetGAL( m_gal ); m_view->SetGAL( m_gal );
......
...@@ -53,6 +53,7 @@ void VIEW::AddLayer( int aLayer, bool aDisplayOnly ) ...@@ -53,6 +53,7 @@ void VIEW::AddLayer( int aLayer, bool aDisplayOnly )
m_layers[aLayer].items = new VIEW_RTREE(); m_layers[aLayer].items = new VIEW_RTREE();
m_layers[aLayer].renderingOrder = aLayer; m_layers[aLayer].renderingOrder = aLayer;
m_layers[aLayer].enabled = true; m_layers[aLayer].enabled = true;
m_layers[aLayer].cached = true;
m_layers[aLayer].isDirty = false; m_layers[aLayer].isDirty = false;
m_layers[aLayer].displayOnly = aDisplayOnly; m_layers[aLayer].displayOnly = aDisplayOnly;
} }
...@@ -138,13 +139,12 @@ int VIEW::Query( const BOX2I& aRect, std::vector<LayerItemPair>& aResult ) ...@@ -138,13 +139,12 @@ int VIEW::Query( const BOX2I& aRect, std::vector<LayerItemPair>& aResult )
} }
VIEW::VIEW( bool aIsDynamic, bool aUseGroups ) : VIEW::VIEW( bool aIsDynamic ) :
m_enableTopLayer( false ), m_enableTopLayer( false ),
m_scale ( 1.0 ), m_scale ( 1.0 ),
m_painter( NULL ), m_painter( NULL ),
m_gal( NULL ), m_gal( NULL ),
m_dynamic( aIsDynamic ), m_dynamic( aIsDynamic )
m_useGroups( aUseGroups )
{ {
// By default there is no layer on the top // By default there is no layer on the top
m_topLayer.enabled = false; m_topLayer.enabled = false;
...@@ -209,8 +209,7 @@ void VIEW::SetGAL( GAL* aGal ) ...@@ -209,8 +209,7 @@ void VIEW::SetGAL( GAL* aGal )
m_gal = aGal; m_gal = aGal;
// clear group numbers, so everything is going to be recached // clear group numbers, so everything is going to be recached
if( m_useGroups ) clearGroupCache();
clearGroupCache();
// force the new GAL to display the current viewport. // force the new GAL to display the current viewport.
SetCenter( m_center ); SetCenter( m_center );
...@@ -282,12 +281,6 @@ void VIEW::SetCenter( const VECTOR2D& aCenter ) ...@@ -282,12 +281,6 @@ void VIEW::SetCenter( const VECTOR2D& aCenter )
} }
void VIEW::SetLayerVisible( int aLayer, bool aVisible )
{
m_layers[aLayer].enabled = aVisible;
}
void VIEW::sortLayers() void VIEW::sortLayers()
{ {
int n = 0; int n = 0;
...@@ -452,7 +445,7 @@ void VIEW::EnableTopLayer( bool aEnable ) ...@@ -452,7 +445,7 @@ void VIEW::EnableTopLayer( bool aEnable )
struct VIEW::drawItem struct VIEW::drawItem
{ {
drawItem( VIEW* aView, int aCurrentLayer ) : drawItem( VIEW* aView, const VIEW_LAYER* aCurrentLayer ) :
currentLayer( aCurrentLayer ), view( aView ) currentLayer( aCurrentLayer ), view( aView )
{ {
} }
...@@ -461,9 +454,10 @@ struct VIEW::drawItem ...@@ -461,9 +454,10 @@ struct VIEW::drawItem
{ {
GAL* gal = view->GetGAL(); GAL* gal = view->GetGAL();
if( view->m_useGroups ) if( currentLayer->cached )
{ {
int group = aItem->getGroup( currentLayer ); // Draw using cached information or create one
int group = aItem->getGroup( currentLayer->id );
if( group >= 0 && aItem->ViewIsVisible() ) if( group >= 0 && aItem->ViewIsVisible() )
{ {
...@@ -472,19 +466,20 @@ struct VIEW::drawItem ...@@ -472,19 +466,20 @@ struct VIEW::drawItem
else else
{ {
group = gal->BeginGroup(); group = gal->BeginGroup();
aItem->setGroup( currentLayer, group ); aItem->setGroup( currentLayer->id, group );
view->m_painter->Draw( aItem, currentLayer ); view->m_painter->Draw( aItem, currentLayer->id );
gal->EndGroup(); gal->EndGroup();
} }
} }
else if( aItem->ViewIsVisible() ) else if( aItem->ViewIsVisible() )
{ {
view->m_painter->Draw( aItem, currentLayer ); // Immediate mode
view->m_painter->Draw( aItem, currentLayer->id );
} }
} }
int currentLayer; const VIEW_LAYER* currentLayer;
VIEW* view; VIEW* view;
}; };
...@@ -494,10 +489,9 @@ void VIEW::redrawRect( const BOX2I& aRect ) ...@@ -494,10 +489,9 @@ void VIEW::redrawRect( const BOX2I& aRect )
{ {
if( l->enabled ) if( l->enabled )
{ {
drawItem drawFunc( this, l->id ); drawItem drawFunc( this, l );
if( !m_useGroups ) m_gal->SetLayerDepth( static_cast<double>( l->renderingOrder ) );
m_gal->SetLayerDepth( static_cast<double>( l->renderingOrder ) );
l->items->Query( aRect, drawFunc ); l->items->Query( aRect, drawFunc );
l->isDirty = false; l->isDirty = false;
} }
...@@ -514,9 +508,9 @@ struct VIEW::unlinkItem ...@@ -514,9 +508,9 @@ struct VIEW::unlinkItem
}; };
struct VIEW::recacheItem struct VIEW::recacheLayer
{ {
recacheItem( VIEW* aView, GAL* aGal, int aLayer, bool aImmediately ) : recacheLayer( VIEW* aView, GAL* aGal, int aLayer, bool aImmediately ) :
view( aView ), gal( aGal ), layer( aLayer ), immediately( aImmediately ) view( aView ), gal( aGal ), layer( aLayer ), immediately( aImmediately )
{ {
} }
...@@ -566,10 +560,7 @@ void VIEW::Clear() ...@@ -566,10 +560,7 @@ void VIEW::Clear()
l->items->RemoveAll(); l->items->RemoveAll();
} }
if( m_useGroups ) m_gal->ClearCache();
{
m_gal->ClearCache();
}
} }
...@@ -608,12 +599,11 @@ void VIEW::invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags ) ...@@ -608,12 +599,11 @@ void VIEW::invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags )
l->items->Remove( aItem ); l->items->Remove( aItem );
l->items->Insert( aItem ); /* reinsert */ l->items->Insert( aItem ); /* reinsert */
if( m_useGroups ) aItem->deleteGroups();
aItem->deleteGroups();
} }
} }
if( m_useGroups && aItem->storesGroups() ) if( aItem->storesGroups() )
{ {
std::vector<int> groups = aItem->getAllGroups(); std::vector<int> groups = aItem->getAllGroups();
for(std::vector<int>::iterator i = groups.begin(); i != groups.end(); i++ ) for(std::vector<int>::iterator i = groups.begin(); i != groups.end(); i++ )
...@@ -626,9 +616,9 @@ void VIEW::invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags ) ...@@ -626,9 +616,9 @@ void VIEW::invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags )
} }
struct VIEW::clearItemCache struct VIEW::clearLayerCache
{ {
clearItemCache( VIEW* aView ) : clearLayerCache( VIEW* aView ) :
view( aView ) view( aView )
{ {
} }
...@@ -647,13 +637,10 @@ struct VIEW::clearItemCache ...@@ -647,13 +637,10 @@ struct VIEW::clearItemCache
void VIEW::clearGroupCache() void VIEW::clearGroupCache()
{ {
if( !m_useGroups )
return;
BOX2I r; BOX2I r;
r.SetMaximum(); r.SetMaximum();
clearItemCache visitor( this ); clearLayerCache visitor( this );
for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i ) for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i )
{ {
...@@ -665,9 +652,6 @@ void VIEW::clearGroupCache() ...@@ -665,9 +652,6 @@ void VIEW::clearGroupCache()
void VIEW::RecacheAllItems( bool aImmediately ) void VIEW::RecacheAllItems( bool aImmediately )
{ {
if( !m_useGroups )
return;
BOX2I r; BOX2I r;
r.SetMaximum(); r.SetMaximum();
...@@ -682,9 +666,13 @@ void VIEW::RecacheAllItems( bool aImmediately ) ...@@ -682,9 +666,13 @@ void VIEW::RecacheAllItems( bool aImmediately )
for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i ) for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i )
{ {
VIEW_LAYER* l = & ( ( *i ).second ); VIEW_LAYER* l = & ( ( *i ).second );
m_gal->SetLayerDepth( (double) l->renderingOrder );
recacheItem visitor( this, m_gal, l->id, aImmediately ); if( l->cached )
l->items->Query( r, visitor ); {
m_gal->SetLayerDepth( (double) l->renderingOrder );
recacheLayer visitor( this, m_gal, l->id, aImmediately );
l->items->Query( r, visitor );
}
} }
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
......
...@@ -64,7 +64,7 @@ public: ...@@ -64,7 +64,7 @@ public:
* @param aIsDynamic decides whether we are creating a static or a dynamic VIEW. * @param aIsDynamic decides whether we are creating a static or a dynamic VIEW.
* @param aUseGroups tells if items added to the VIEW should be stored in groups. * @param aUseGroups tells if items added to the VIEW should be stored in groups.
*/ */
VIEW( bool aIsDynamic = true, bool aUseGroups = false ); VIEW( bool aIsDynamic = true );
~VIEW(); ~VIEW();
...@@ -251,7 +251,21 @@ public: ...@@ -251,7 +251,21 @@ public:
* visibility is updated * visibility is updated
* @param aVisible: the obivous * @param aVisible: the obivous
*/ */
void SetLayerVisible( int aLayer, bool aVisible = true ); inline void SetLayerVisible( int aLayer, bool aVisible = true )
{
m_layers[aLayer].enabled = aVisible;
}
/**
* Function SetLayerDynamic()
* Turns on or off the dynamic parameter of a particular layer.
* @param aLayer: the layer
* @param aDynamic: the parameter
*/
inline void SetLayerCached( int aLayer, bool aCached = true )
{
m_layers[aLayer].cached = aCached;
}
/** /**
* Function SetLayerOrder() * Function SetLayerOrder()
...@@ -339,6 +353,8 @@ private: ...@@ -339,6 +353,8 @@ private:
bool enabled; ///* is the layer to be rendered? bool enabled; ///* is the layer to be rendered?
bool isDirty; ///* does it contain any dirty items (updated since last redraw) bool isDirty; ///* does it contain any dirty items (updated since last redraw)
bool displayOnly; ///* is the layer display only? bool displayOnly; ///* is the layer display only?
bool cached; ///* items on non-cached layers are displayed in
///* immediate mode
VIEW_RTREE* items; ///* R-tree indexing all items on this layer. VIEW_RTREE* items; ///* R-tree indexing all items on this layer.
std::vector<VIEW_ITEM*> dirtyItems; ///* set of dirty items collected since last redraw std::vector<VIEW_ITEM*> dirtyItems; ///* set of dirty items collected since last redraw
int renderingOrder; ///* rendering order of this layer int renderingOrder; ///* rendering order of this layer
...@@ -354,10 +370,10 @@ private: ...@@ -354,10 +370,10 @@ private:
typedef std::vector<VIEW_LAYER*>::iterator LayerOrderIter; typedef std::vector<VIEW_LAYER*>::iterator LayerOrderIter;
// Function objects that need to access VIEW/VIEW_ITEM private/protected members // Function objects that need to access VIEW/VIEW_ITEM private/protected members
struct clearItemCache; struct clearLayerCache;
struct unlinkItem; struct recacheLayer;
struct recacheItem;
struct drawItem; struct drawItem;
struct unlinkItem;
struct updateItemsColor; struct updateItemsColor;
struct changeItemsDepth; struct changeItemsDepth;
...@@ -408,9 +424,6 @@ private: ...@@ -408,9 +424,6 @@ private:
/// Dynamic VIEW (eg. display PCB in window) allows changes once it is built, /// Dynamic VIEW (eg. display PCB in window) allows changes once it is built,
/// static (eg. image/PDF) - does not. /// static (eg. image/PDF) - does not.
bool m_dynamic; bool m_dynamic;
/// Determines whether to use cached groups of objects for displaying.
bool m_useGroups;
}; };
} // namespace KiGfx } // namespace KiGfx
......
...@@ -205,7 +205,6 @@ public: ...@@ -205,7 +205,6 @@ public:
* @param aLayers[]: output layer index array * @param aLayers[]: output layer index array
* @param aCount: number of layer indices in aLayers[] * @param aCount: number of layer indices in aLayers[]
*/ */
virtual void ViewGetLayers( int aLayers[], int& aCount ) const = 0; virtual void ViewGetLayers( int aLayers[], int& aCount ) const = 0;
/** /**
...@@ -216,7 +215,6 @@ public: ...@@ -216,7 +215,6 @@ public:
*/ */
void ViewSetVisible( bool aIsVisible = true ); void ViewSetVisible( bool aIsVisible = true );
/** /**
* Function ViewIsVisible() * Function ViewIsVisible()
* Returns if the item is visible (or not). * Returns if the item is visible (or not).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment