Commit 8753bef2 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Moved VIEW_ITEM::ViewGetRequiredLayers() functionality to the VIEW class. Now...

Moved VIEW_ITEM::ViewGetRequiredLayers() functionality to the VIEW class. Now required layers are set per layer basis instead of per item.
parent 2c2e506e
Loading
Loading
Loading
Loading
+28 −11
Original line number Diff line number Diff line
@@ -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 <class Container>
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 );

@@ -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<int>::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;
    }

+2 −8
Original line number Diff line number Diff line
@@ -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,6 +137,7 @@ bool VIEW_ITEM::storesGroups() const
    return ( m_groupsSize > 0 );
}


void VIEW_ITEM::ViewSetHighlighted( bool aIsHighlighted )
{
    m_highlighted = aIsHighlighted;
+15 −3
Original line number Diff line number Diff line
@@ -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<LayerItemPair>& 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<int>           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;
+0 −10
Original line number Diff line number Diff line
@@ -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.
+20 −8
Original line number Diff line number Diff line
@@ -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
    for( LAYER_NUM layer = FIRST_NETNAME_LAYER; layer <= LAST_NETNAME_LAYER; ++layer )
    {
         view->SetLayerTarget( layer, KiGfx::TARGET_NONCACHED );
            view->SetLayerTarget( i, 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() )
Loading