From 62ea71fcaed8e6f41a264c5c4fd59465b43296a6 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 7 Aug 2013 10:52:50 +0200 Subject: [PATCH] Fixed layers caching settings. Added some comments. --- common/tool/tool_manager.cpp | 1 + common/view/view.cpp | 18 ++++++++++++------ common/view/view_item.cpp | 9 +++------ include/class_drawpanel_gal.h | 3 +-- include/view/view.h | 7 ++++++- pcbnew/basepcbframe.cpp | 29 +++++++++++++++++------------ 6 files changed, 40 insertions(+), 27 deletions(-) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index f1855907ee..3238100c68 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -212,6 +212,7 @@ TOOL_ID TOOL_MANAGER::MakeToolId( const std::string& aToolName ) return currentId++; } + void TOOL_MANAGER::SetEnvironment( EDA_ITEM* aModel, KiGfx::VIEW* aView, KiGfx::VIEW_CONTROLS* aViewControls, wxWindow* aFrame ) { diff --git a/common/view/view.cpp b/common/view/view.cpp index 3ec8ef6a80..fa5aade34f 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -544,7 +544,8 @@ void VIEW::redrawRect( const BOX2I& aRect ) } } -bool VIEW::IsDirty() + +bool VIEW::IsDirty() const { BOOST_FOREACH( VIEW_LAYER* l, m_orderedLayers ) { @@ -554,6 +555,7 @@ bool VIEW::IsDirty() return false; } + struct VIEW::unlinkItem { void operator()( VIEW_ITEM* aItem ) @@ -644,28 +646,32 @@ void VIEW::invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags ) for( int i = 0; i < layer_count; i++ ) { - if(m_layers.find(layer_indices[i]) != m_layers.end()) + // Iterate through the layers used by the item + if( m_layers.find( layer_indices[i] ) != m_layers.end() ) { VIEW_LAYER* l = &m_layers[layer_indices[i]]; + // Mark the area occupied by the item as dirty l->dirtyExtents = l->isDirty ? aItem->ViewBBox() : l->dirtyExtents.Merge( aItem->ViewBBox() ); l->isDirty = true; + // If geometry has to be updated, then we need to reinsert the item if( aUpdateFlags & VIEW_ITEM::GEOMETRY ) { l->items->Remove( aItem ); - l->items->Insert( aItem ); /* reinsert */ - aItem->deleteGroups(); + l->items->Insert( aItem ); } - } + } } + // Remove all the groups, so the item will be recached if( aItem->storesGroups() ) { + // Clear the cached groups stored in GAL std::vector groups = aItem->getAllGroups(); - for(std::vector::iterator i = groups.begin(); i != groups.end(); i++ ) + for( std::vector::iterator i = groups.begin(); i != groups.end(); i++ ) { m_gal->DeleteGroup( *i ); } diff --git a/common/view/view_item.cpp b/common/view/view_item.cpp index 3649516a25..2598eb8ee6 100644 --- a/common/view/view_item.cpp +++ b/common/view/view_item.cpp @@ -50,7 +50,7 @@ void VIEW_ITEM::ViewSetVisible( bool aIsVisible ) void VIEW_ITEM::ViewUpdate( int aUpdateFlags, bool aForceImmediateRedraw ) { - if(!m_view) + if( !m_view ) return; m_view->invalidateItem( this, aUpdateFlags ); @@ -124,11 +124,8 @@ void VIEW_ITEM::setGroup( int aLayer, int aId ) void VIEW_ITEM::deleteGroups() { - if( m_groupsSize > 0 ) - { - delete[] m_groups; - m_groupsSize = 0; - } + delete[] m_groups; + m_groupsSize = 0; } diff --git a/include/class_drawpanel_gal.h b/include/class_drawpanel_gal.h index 400229e75e..9c789ac3b0 100644 --- a/include/class_drawpanel_gal.h +++ b/include/class_drawpanel_gal.h @@ -99,8 +99,7 @@ protected: ///< using GAL KiGfx::WX_VIEW_CONTROLS* m_viewControls; ///< Control for VIEW (moving, zooming, etc.) GalType m_currentGal; ///< Currently used GAL - wxLongLong m_timeStamp; - TOOL_DISPATCHER* m_eventDispatcher; + TOOL_DISPATCHER* m_eventDispatcher; }; #endif diff --git a/include/view/view.h b/include/view/view.h index b37747da19..7a3a7603de 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -371,7 +371,12 @@ public: */ bool IsDynamic() const { return m_dynamic; } - bool IsDirty(); + /** + * Function IsDirty() + * Returns true if any of the VIEW layers needs to be refreshened. + * @return True in case if any of layers is marked as dirty. + */ + bool IsDirty() const; static const int VIEW_MAX_LAYERS = 128; ///* maximum number of layers that may be shown diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index c1b0ccc809..b55ba8aabd 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -178,6 +178,9 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard ) // Load module's texts (name and value) view->Add( &module->Reference() ); view->Add( &module->Value() ); + + // Add the module itself + view->Add( module ); } // Segzones (equivalent of ZONE_CONTAINER for legacy boards) @@ -191,8 +194,8 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard ) m_galCanvas->Refresh(); // update the tool manager with the new board and its view. - if(m_toolManager) - m_toolManager->SetEnvironment( m_Pcb, view, m_galCanvas->GetViewControls(), this); + if( m_toolManager ) + m_toolManager->SetEnvironment( m_Pcb, view, m_galCanvas->GetViewControls(), this ); } } @@ -799,31 +802,33 @@ void PCB_BASE_FRAME::LoadSettings() // Apply display settings for GAL KiGfx::VIEW* view = m_galCanvas->GetView(); - // Set rendering order of layers - for( LAYER_NUM i = 0; i < sizeof(GalLayerOrder) / sizeof(LAYER_NUM); ++i ) + + // Set rendering order and properties of layers + for( LAYER_NUM i = 0; (unsigned) i < sizeof(GalLayerOrder) / sizeof(LAYER_NUM); ++i ) { - wxASSERT( i < KiGfx::VIEW::VIEW_MAX_LAYERS ); + LAYER_NUM layer = GalLayerOrder[i]; + wxASSERT( layer < KiGfx::VIEW::VIEW_MAX_LAYERS ); - view->SetLayerOrder( GalLayerOrder[i], i ); - view->SetLayerTarget( i, KiGfx::TARGET_NONCACHED ); + view->SetLayerOrder( layer, i ); - if( IsCopperLayer( i ) ) + if( IsCopperLayer( layer ) ) { // Copper layers are required for netname layers - view->SetRequired( GetNetnameLayer( i ), i ); + view->SetRequired( GetNetnameLayer( layer ), layer ); + view->SetLayerTarget( layer, KiGfx::TARGET_CACHED ); } - else - if( IsNetnameLayer( i ) ) + else if( IsNetnameLayer( layer ) ) { // Netnames are drawn only when scale is sufficient (level of details) // so there is no point in caching them - view->SetLayerTarget( i, KiGfx::TARGET_NONCACHED ); + view->SetLayerTarget( layer, KiGfx::TARGET_NONCACHED ); } } // Some more required layers settings view->SetRequired( ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( VIAS_VISIBLE ) ); view->SetRequired( ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ) ); + view->SetRequired( ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ) ); view->SetRequired( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); view->SetRequired( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( PAD_BK_VISIBLE ) );