diff --git a/common/view/view.cpp b/common/view/view.cpp index 14a765f014..3ec8ef6a80 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -89,6 +89,22 @@ void VIEW::Remove( VIEW_ITEM* aItem ) } +void VIEW::SetRequired( int aLayerId, int aRequiredId, bool aRequired ) +{ + wxASSERT( (unsigned) aLayerId < m_layers.size() ); + wxASSERT( (unsigned) aRequiredId < m_layers.size() ); + + if( aRequired ) + { + m_layers[aLayerId].requiredLayers.insert( aRequiredId ); + } + else + { + m_layers[aLayerId].requiredLayers.erase( aRequired ); + } +} + + // stupid C++... python lamda would do this in one line template struct queryVisitor @@ -474,14 +490,9 @@ struct VIEW::drawItem { GAL* gal = view->GetGAL(); - // Obtain layers that are required to be enabled for drawing an item - // (eg. there is no point in drawing track labels, if the track is not visible) - aItem->ViewGetRequiredLayers( layers, layersCount ); - // Conditions that have te be fulfilled for an item to be drawn bool drawCondition = aItem->ViewIsVisible() && - aItem->ViewGetLOD( currentLayer->id ) < view->m_scale && - view->isEveryLayerEnabled( layers, layersCount ); + aItem->ViewGetLOD( currentLayer->id ) < view->m_scale; if( !drawCondition ) return; @@ -521,7 +532,7 @@ void VIEW::redrawRect( const BOX2I& aRect ) { BOOST_FOREACH( VIEW_LAYER* l, m_orderedLayers ) { - if( l->enabled ) + if( l->enabled && areRequiredLayersEnabled( l->id ) ) { drawItem drawFunc( this, l ); @@ -537,7 +548,7 @@ bool VIEW::IsDirty() { BOOST_FOREACH( VIEW_LAYER* l, m_orderedLayers ) { - if(l->isDirty) + if( l->isDirty ) return true; } return false; @@ -698,11 +709,17 @@ void VIEW::clearGroupCache() } -bool VIEW::isEveryLayerEnabled( const int aLayers[], int aCount ) const +bool VIEW::areRequiredLayersEnabled( int aLayerId ) const { - for( int i = 0; i < aCount; ++i ) + wxASSERT( (unsigned) aLayerId < m_layers.size() ); + + std::set::iterator it, it_end; + + for( it = m_layers.at( aLayerId ).requiredLayers.begin(), it_end = m_layers.at( aLayerId ).requiredLayers.end(); + it != it_end; ++it ) { - if( !m_layers.at( aLayers[i] ).enabled ) + // That is enough if just one layer is not enabled + if( !m_layers.at( *it ).enabled ) return false; } diff --git a/common/view/view_item.cpp b/common/view/view_item.cpp index 12651ed7c3..f1d1fdecba 100644 --- a/common/view/view_item.cpp +++ b/common/view/view_item.cpp @@ -48,13 +48,6 @@ void VIEW_ITEM::ViewSetVisible( bool aIsVisible ) } -void VIEW_ITEM::ViewGetRequiredLayers( int aLayers[], int& aCount ) const -{ - // By default there is no layer required - aCount = 0; -} - - void VIEW_ITEM::ViewUpdate( int aUpdateFlags, bool aForceImmediateRedraw ) { if(!m_view) @@ -144,8 +137,9 @@ bool VIEW_ITEM::storesGroups() const return ( m_groupsSize > 0 ); } + void VIEW_ITEM::ViewSetHighlighted( bool aIsHighlighted ) { m_highlighted = aIsHighlighted; - ViewUpdate(APPEARANCE | GEOMETRY); + ViewUpdate( APPEARANCE | GEOMETRY ); } diff --git a/include/view/view.h b/include/view/view.h index 27e9a48358..b37747da19 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -84,7 +84,8 @@ public: */ void Remove( VIEW_ITEM* aItem ); - /** Function Query() + /** + * Function Query() * Finds all visible items that touch or are within the rectangle aRect. * @param aRect area to search for items * @param aResult result of the search, containing VIEW_ITEMs associated with their layers. @@ -93,6 +94,16 @@ public: */ int Query( const BOX2I& aRect, std::vector& aResult ); + /** + * Function SetRequired() + * Marks the aRequiredId layer as required for the aLayerId layer. In order to display the + * layer, all of its required layers have to be enabled. + * @param aLayerId is the id of the layer for which we enable/disable the required layer. + * @param aRequiredId is the id of the required layer. + * @param aRequired tells if the required layer should be added or removed from the list. + */ + void SetRequired( int aLayerId, int aRequiredId, bool aRequired = true ); + /** * Function CopySettings() * Copies layers and visibility settings from another view. @@ -377,6 +388,7 @@ private: BOX2I extents; ///* sum of bboxes of all items on the layer BOX2I dirtyExtents; ///* sum of bboxes of all dirty items on the layer RenderTarget target; ///* where the layer should be rendered + std::set requiredLayers; ///* layers that are required to be enabled to show the layer }; // Convenience typedefs @@ -416,8 +428,8 @@ private: return i->renderingOrder > j->renderingOrder; } - /// Checks if every layer stored in aLayers array is enabled. - bool isEveryLayerEnabled( const int aLayers[], int aCount ) const; + /// Checks if every layer required by the aLayerId layer is enabled. + bool areRequiredLayersEnabled( int aLayerId ) const; /// Contains set of possible displayed layers and its properties LayerMap m_layers; diff --git a/include/view/view_item.h b/include/view/view_item.h index 5f73124e6d..acef72c512 100644 --- a/include/view/view_item.h +++ b/include/view/view_item.h @@ -115,16 +115,6 @@ public: */ virtual void ViewGetLayers( int aLayers[], int& aCount ) const = 0; - /** - * Function ViewGetRequiredLayers() - * Returns the all the layers that are required for an item to be drawn. Eg. there is no point - * to draw netnames, when the track is not visible - so track layer should be marked as - * required. - * @param aLayers[]: output layer index array - * @param aCount: number of layer indices in aLayers[] - */ - virtual void ViewGetRequiredLayers( int aLayers[], int& aCount ) const; - /** * Function ViewSetVisible() * Sets the item visibility. diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 30cb46d540..c1b0ccc809 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -93,8 +93,8 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( wxWindow* aParent, ID_DRAWFRAME_TYPE aFrameType, EDA_DRAW_FRAME( aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ) { m_Pcb = NULL; - m_toolManager = NULL; - m_toolDispatcher = NULL; + m_toolManager = NULL; + m_toolDispatcher = NULL; m_DisplayPadFill = true; // How to draw pads m_DisplayViaFill = true; // How to draw vias @@ -806,14 +806,26 @@ void PCB_BASE_FRAME::LoadSettings() view->SetLayerOrder( GalLayerOrder[i], i ); view->SetLayerTarget( i, KiGfx::TARGET_NONCACHED ); + + if( IsCopperLayer( i ) ) + { + // Copper layers are required for netname layers + view->SetRequired( GetNetnameLayer( i ), i ); + } + else + if( IsNetnameLayer( i ) ) + { + // 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 ); + } } - // Netnames are drawn only when scale is sufficient (level of details) - // so there is no point in caching them - for( LAYER_NUM layer = FIRST_NETNAME_LAYER; layer <= LAST_NETNAME_LAYER; ++layer ) - { - 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( 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 ) ); // Apply layer coloring scheme & display options if( view->GetPainter() ) diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index 3950a73147..1f223e2335 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -850,27 +850,6 @@ void D_PAD::ViewGetLayers( int aLayers[], int& aCount ) const } -void D_PAD::ViewGetRequiredLayers( int aLayers[], int& aCount ) const -{ - ViewGetLayers( aLayers, aCount ); - - // Remove pad description layer & soldermask from the required layers group - if( IsOnLayer( LAYER_N_FRONT ) && IsOnLayer( LAYER_N_BACK ) ) - { - // Multilayer pads have 2 soldermask layers (front and back), 2 solder paste layer - // (front and back) and one description layer that do not have to be enabled in order to - // display a pad. - aCount -= 5; - } - else - { - // Rest of pads have one soldermask layer, one solder paste layer and one description layer - // that are not necessary for pad to be displayed. - aCount -= 3; - } -} - - unsigned int D_PAD::ViewGetLOD( int aLayer ) const { // Netnames and soldermasks will be shown only if zoom is appropriate diff --git a/pcbnew/class_pad.h b/pcbnew/class_pad.h index f72705e9fc..765b8d46fc 100644 --- a/pcbnew/class_pad.h +++ b/pcbnew/class_pad.h @@ -436,9 +436,6 @@ public: /// @copydoc VIEW_ITEM::ViewGetLayers() virtual void ViewGetLayers( int aLayers[], int& aCount ) const; - /// @copydoc VIEW_ITEM::ViewGetRequiredLayers() - virtual void ViewGetRequiredLayers( int aLayers[], int& aCount ) const; - /// @copydoc VIEW_ITEM::ViewGetLOD() virtual unsigned int ViewGetLOD( int aLayer ) const; diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index a3a8d2b2e7..bed16cca36 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -760,14 +760,6 @@ void TRACK::ViewGetLayers( int aLayers[], int& aCount ) const } -void TRACK::ViewGetRequiredLayers( int aLayers[], int& aCount ) const -{ - // The only required layer is the track layer itself - aLayers[0] = GetLayer(); - aCount = 1; -} - - unsigned int TRACK::ViewGetLOD( int aLayer ) const { // Netnames will be shown only if zoom is appropriate @@ -1004,14 +996,6 @@ void SEGVIA::ViewGetLayers( int aLayers[], int& aCount ) const } -void SEGVIA::ViewGetRequiredLayers( int aLayers[], int& aCount ) const -{ - // The only required layer is via itself, holes are optional - aLayers[0] = ITEM_GAL_LAYER( VIAS_VISIBLE ); - aCount = 1; -} - - // see class_track.h void TRACK::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) { diff --git a/pcbnew/class_track.h b/pcbnew/class_track.h index bbacb4e3aa..ce8e6cf282 100644 --- a/pcbnew/class_track.h +++ b/pcbnew/class_track.h @@ -331,9 +331,6 @@ public: /// @copydoc VIEW_ITEM::ViewGetLayers() virtual void ViewGetLayers( int aLayers[], int& aCount ) const; - /// @copydoc VIEW_ITEM::ViewGetRequiredLayers() - virtual void ViewGetRequiredLayers( int aLayers[], int& aCount ) const; - /// @copydoc VIEW_ITEM::ViewGetLOD() virtual unsigned int ViewGetLOD( int aLayer ) const; @@ -424,9 +421,6 @@ public: /// @copydoc VIEW_ITEM::ViewGetLayers() virtual void ViewGetLayers( int aLayers[], int& aCount ) const; - /// @copydoc VIEW_ITEM::ViewGetRequiredLayers() - virtual void ViewGetRequiredLayers( int aLayers[], int& aCount ) const; - #if defined (DEBUG) virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override #endif