diff --git a/common/drawpanel_gal.cpp b/common/drawpanel_gal.cpp index 2ec46a048f..7837cf8d04 100644 --- a/common/drawpanel_gal.cpp +++ b/common/drawpanel_gal.cpp @@ -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_view = new KiGfx::VIEW( true, true ); + m_view = new KiGfx::VIEW( true ); m_view->SetPainter( m_painter ); m_view->SetGAL( m_gal ); diff --git a/common/view/view.cpp b/common/view/view.cpp index 91c216137a..9300869f8b 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -53,6 +53,7 @@ void VIEW::AddLayer( int aLayer, bool aDisplayOnly ) m_layers[aLayer].items = new VIEW_RTREE(); m_layers[aLayer].renderingOrder = aLayer; m_layers[aLayer].enabled = true; + m_layers[aLayer].cached = true; m_layers[aLayer].isDirty = false; m_layers[aLayer].displayOnly = aDisplayOnly; } @@ -138,13 +139,12 @@ int VIEW::Query( const BOX2I& aRect, std::vector& aResult ) } -VIEW::VIEW( bool aIsDynamic, bool aUseGroups ) : +VIEW::VIEW( bool aIsDynamic ) : m_enableTopLayer( false ), m_scale ( 1.0 ), m_painter( NULL ), m_gal( NULL ), - m_dynamic( aIsDynamic ), - m_useGroups( aUseGroups ) + m_dynamic( aIsDynamic ) { // By default there is no layer on the top m_topLayer.enabled = false; @@ -209,8 +209,7 @@ void VIEW::SetGAL( GAL* aGal ) m_gal = aGal; // clear group numbers, so everything is going to be recached - if( m_useGroups ) - clearGroupCache(); + clearGroupCache(); // force the new GAL to display the current viewport. SetCenter( m_center ); @@ -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() { int n = 0; @@ -452,7 +445,7 @@ void VIEW::EnableTopLayer( bool aEnable ) struct VIEW::drawItem { - drawItem( VIEW* aView, int aCurrentLayer ) : + drawItem( VIEW* aView, const VIEW_LAYER* aCurrentLayer ) : currentLayer( aCurrentLayer ), view( aView ) { } @@ -461,9 +454,10 @@ struct VIEW::drawItem { 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() ) { @@ -472,19 +466,20 @@ struct VIEW::drawItem else { group = gal->BeginGroup(); - aItem->setGroup( currentLayer, group ); - view->m_painter->Draw( aItem, currentLayer ); + aItem->setGroup( currentLayer->id, group ); + view->m_painter->Draw( aItem, currentLayer->id ); gal->EndGroup(); } } else if( aItem->ViewIsVisible() ) { - view->m_painter->Draw( aItem, currentLayer ); + // Immediate mode + view->m_painter->Draw( aItem, currentLayer->id ); } } - int currentLayer; - VIEW* view; + const VIEW_LAYER* currentLayer; + VIEW* view; }; @@ -494,10 +489,9 @@ void VIEW::redrawRect( const BOX2I& aRect ) { if( l->enabled ) { - drawItem drawFunc( this, l->id ); + drawItem drawFunc( this, l ); - if( !m_useGroups ) - m_gal->SetLayerDepth( static_cast( l->renderingOrder ) ); + m_gal->SetLayerDepth( static_cast( l->renderingOrder ) ); l->items->Query( aRect, drawFunc ); l->isDirty = false; } @@ -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 ) { } @@ -566,10 +560,7 @@ void VIEW::Clear() l->items->RemoveAll(); } - if( m_useGroups ) - { - m_gal->ClearCache(); - } + m_gal->ClearCache(); } @@ -608,12 +599,11 @@ void VIEW::invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags ) l->items->Remove( aItem ); l->items->Insert( aItem ); /* reinsert */ - if( m_useGroups ) - aItem->deleteGroups(); + aItem->deleteGroups(); } } - if( m_useGroups && aItem->storesGroups() ) + if( aItem->storesGroups() ) { std::vector groups = aItem->getAllGroups(); for(std::vector::iterator i = groups.begin(); i != groups.end(); i++ ) @@ -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 ) { } @@ -647,13 +637,10 @@ struct VIEW::clearItemCache void VIEW::clearGroupCache() { - if( !m_useGroups ) - return; - BOX2I r; r.SetMaximum(); - clearItemCache visitor( this ); + clearLayerCache visitor( this ); for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i ) { @@ -665,9 +652,6 @@ void VIEW::clearGroupCache() void VIEW::RecacheAllItems( bool aImmediately ) { - if( !m_useGroups ) - return; - BOX2I r; r.SetMaximum(); @@ -682,9 +666,13 @@ void VIEW::RecacheAllItems( bool aImmediately ) for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i ) { VIEW_LAYER* l = & ( ( *i ).second ); - m_gal->SetLayerDepth( (double) l->renderingOrder ); - recacheItem visitor( this, m_gal, l->id, aImmediately ); - l->items->Query( r, visitor ); + + if( l->cached ) + { + m_gal->SetLayerDepth( (double) l->renderingOrder ); + recacheLayer visitor( this, m_gal, l->id, aImmediately ); + l->items->Query( r, visitor ); + } } #ifdef __WXDEBUG__ diff --git a/include/view/view.h b/include/view/view.h index 9ebc3d09c6..7bb93fad15 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -64,7 +64,7 @@ public: * @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. */ - VIEW( bool aIsDynamic = true, bool aUseGroups = false ); + VIEW( bool aIsDynamic = true ); ~VIEW(); @@ -251,7 +251,21 @@ public: * visibility is updated * @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() @@ -339,6 +353,8 @@ private: bool enabled; ///* is the layer to be rendered? bool isDirty; ///* does it contain any dirty items (updated since last redraw) 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. std::vector dirtyItems; ///* set of dirty items collected since last redraw int renderingOrder; ///* rendering order of this layer @@ -354,10 +370,10 @@ private: typedef std::vector::iterator LayerOrderIter; // Function objects that need to access VIEW/VIEW_ITEM private/protected members - struct clearItemCache; - struct unlinkItem; - struct recacheItem; + struct clearLayerCache; + struct recacheLayer; struct drawItem; + struct unlinkItem; struct updateItemsColor; struct changeItemsDepth; @@ -408,9 +424,6 @@ private: /// Dynamic VIEW (eg. display PCB in window) allows changes once it is built, /// static (eg. image/PDF) - does not. bool m_dynamic; - - /// Determines whether to use cached groups of objects for displaying. - bool m_useGroups; }; } // namespace KiGfx diff --git a/include/view/view_item.h b/include/view/view_item.h index ffe7fe700f..b1710ca51b 100644 --- a/include/view/view_item.h +++ b/include/view/view_item.h @@ -205,7 +205,6 @@ public: * @param aLayers[]: output layer index array * @param aCount: number of layer indices in aLayers[] */ - virtual void ViewGetLayers( int aLayers[], int& aCount ) const = 0; /** @@ -216,7 +215,6 @@ public: */ void ViewSetVisible( bool aIsVisible = true ); - /** * Function ViewIsVisible() * Returns if the item is visible (or not).