Commit d8acd1c7 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Moved Init() & Reset() from TOOL_INTERACTIVE to TOOL_BASE.

Added REASON enum for Reset() function, so tools will know why a reset occured.
Fixed SELECTION_TOOL (it was bailing out, when a new board was loaded and some items were still selected).
Added removal of VIEW_ITEM groups after changing layers and removing items.
parent aebb8b3f
Loading
Loading
Loading
Loading
+18 −22
Original line number Diff line number Diff line
@@ -140,11 +140,10 @@ void TOOL_MANAGER::RegisterTool( TOOL_BASE* aTool )

    aTool->m_toolMgr = this;

    if( aTool->GetType() == INTERACTIVE )
    if( !aTool->Init() )
    {
        if( !static_cast<TOOL_INTERACTIVE*>( aTool )->Init() )
        {
            std::string msg = StrPrintf( "Initialization of the %s tool failed", aTool->GetName().c_str() );
        std::string msg = StrPrintf( "Initialization of the %s tool failed",
                                     aTool->GetName().c_str() );

        DisplayError( NULL, wxString::FromUTF8( msg.c_str() ) );

@@ -157,7 +156,6 @@ void TOOL_MANAGER::RegisterTool( TOOL_BASE* aTool )
        delete aTool;
    }
}
}


bool TOOL_MANAGER::InvokeTool( TOOL_ID aToolId )
@@ -251,7 +249,7 @@ bool TOOL_MANAGER::runTool( TOOL_BASE* aTool )

    state->idle = false;

    static_cast<TOOL_INTERACTIVE*>( aTool )->Reset();
    aTool->Reset( TOOL_INTERACTIVE::RUN );

    // Add the tool on the front of the processing queue (it gets events first)
    m_activeTools.push_front( aTool->GetId() );
@@ -282,6 +280,13 @@ TOOL_BASE* TOOL_MANAGER::FindTool( const std::string& aName ) const
}


void TOOL_MANAGER::ResetTools( TOOL_BASE::RESET_REASON aReason )
{
    BOOST_FOREACH( TOOL_BASE* tool, m_toolState | boost::adaptors::map_keys )
        tool->Reset( aReason );
}


void TOOL_MANAGER::ScheduleNextState( TOOL_BASE* aTool, TOOL_STATE_FUNC& aHandler,
                                      const TOOL_EVENT_LIST& aConditions )
{
@@ -513,15 +518,6 @@ void TOOL_MANAGER::SetEnvironment( EDA_ITEM* aModel, KIGFX::VIEW* aView,
    m_view = aView;
    m_viewControls = aViewControls;
    m_editFrame = aFrame;

    // Reset state of the registered tools
    BOOST_FOREACH( TOOL_ID toolId, m_activeTools )
    {
        TOOL_BASE* tool = m_toolIdIndex[toolId]->theTool;

        if( tool->GetType() == INTERACTIVE )
            static_cast<TOOL_INTERACTIVE*>( tool )->Reset();
    }
}


+12 −0
Original line number Diff line number Diff line
@@ -122,6 +122,12 @@ void VIEW::Remove( VIEW_ITEM* aItem )
    {
        VIEW_LAYER& l = m_layers[layers[i]];
        l.items->Remove( aItem );
        MarkTargetDirty( l.target );

        // Clear the GAL cache
        int prevGroup = aItem->getGroup( layers[i] );
        if( prevGroup >= 0 )
            m_gal->DeleteGroup( prevGroup );
    }
}

@@ -930,6 +936,12 @@ void VIEW::updateLayers( VIEW_ITEM* aItem )
        VIEW_LAYER& l = m_layers[layers[i]];
        l.items->Remove( aItem );
        MarkTargetDirty( l.target );

        // Redraw the item from scratch
        int prevGroup = aItem->getGroup( layers[i] );

        if( prevGroup >= 0 )
            m_gal->DeleteGroup( prevGroup );
    }

    // Add the item to new layer set
+0 −6
Original line number Diff line number Diff line
@@ -34,18 +34,14 @@ void VIEW_ITEM::ViewSetVisible( bool aIsVisible )
    bool update = false;

    if( m_visible != aIsVisible )
    {
        update = true;
    }

    m_visible = aIsVisible;

    // update only if the visibility has really changed
    if( update )
    {
        ViewUpdate( APPEARANCE );
}
}


void VIEW_ITEM::ViewUpdate( int aUpdateFlags )
@@ -60,10 +56,8 @@ void VIEW_ITEM::ViewUpdate( int aUpdateFlags )
void VIEW_ITEM::ViewRelease()
{
    if( m_view && m_view->IsDynamic() )
    {
        m_view->Remove( this );
}
}


void VIEW_ITEM::getLayers( int* aLayers, int& aCount ) const
+27 −0
Original line number Diff line number Diff line
@@ -70,6 +70,33 @@ public:

    virtual ~TOOL_BASE() {};

    ///> Determines the reason of reset for a tool
    enum RESET_REASON
    {
        RUN,                ///< Tool is invoked after being inactive
        MODEL_RELOAD,       ///< Model changes
        GAL_SWITCH          ///< Rendering engine changes
    };

    /**
     * Function Init()
     * Init() is called once upon a registration of the tool.
     *
     * @return True if the initialization went fine, false - otherwise.
     */
    virtual bool Init()
    {
        return true;
    }

    /**
     * Function Reset()
     * Brings the tool to a known, initial state. If the tool claimed anything from
     * the model or the view, it must release it when its reset.
     * @param aReason contains information about the reason of tool reset.
     */
    virtual void Reset( RESET_REASON aReason ) = 0;

    /**
     * Function GetType()
     * Returns the type of the tool.
+0 −18
Original line number Diff line number Diff line
@@ -48,24 +48,6 @@ public:
    TOOL_INTERACTIVE( const std::string& aName );
    virtual ~TOOL_INTERACTIVE();

    /**
     * Function Reset()
     * Brings the tool to a known, initial state. If the tool claimed anything from
     * the model or the view, it must release it when its reset.
     */
    virtual void Reset() = 0;

    /**
     * Function Init()
     * Init() is called once upon a registration of the tool.
     *
     * @return True if the initialization went fine, false - otherwise.
     */
    virtual bool Init()
    {
        return true;
    }

    /**
     * Function SetContextMenu()
     *
Loading