Commit 946b9d19 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

setTransitions() are called automatically for tools.

parent 6e45180b
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -389,6 +389,7 @@ bool TOOL_MANAGER::runTool( TOOL_BASE* aTool )
    }
    }


    aTool->Reset( TOOL_INTERACTIVE::RUN );
    aTool->Reset( TOOL_INTERACTIVE::RUN );
    aTool->SetTransitions();


    // Add the tool on the front of the processing queue (it gets events first)
    // Add the tool on the front of the processing queue (it gets events first)
    m_activeTools.push_front( aTool->GetId() );
    m_activeTools.push_front( aTool->GetId() );
@@ -425,7 +426,10 @@ void TOOL_MANAGER::ResetTools( TOOL_BASE::RESET_REASON aReason )
    ProcessEvent( evt );
    ProcessEvent( evt );


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




@@ -621,6 +625,8 @@ void TOOL_MANAGER::finishTool( TOOL_STATE* aState )
        if( tool != m_activeTools.end() )
        if( tool != m_activeTools.end() )
            m_activeTools.erase( tool );
            m_activeTools.erase( tool );
    }
    }

    aState->theTool->SetTransitions();
}
}




+7 −0
Original line number Original line Diff line number Diff line
@@ -140,6 +140,13 @@ public:
        return m_toolMgr;
        return m_toolMgr;
    }
    }


    /**
     * Function SetTransitions()
     * This method is meant to be overridden in order to specify handlers for events. It is called
     * every time tool is reset or finished.
     */
    virtual void SetTransitions() {};

protected:
protected:
    friend class TOOL_MANAGER;
    friend class TOOL_MANAGER;


+1 −17
Original line number Original line Diff line number Diff line
@@ -66,8 +66,6 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason )
    m_controls = getViewControls();
    m_controls = getViewControls();
    m_board = getModel<BOARD>();
    m_board = getModel<BOARD>();
    m_frame = getEditFrame<PCB_EDIT_FRAME>();
    m_frame = getEditFrame<PCB_EDIT_FRAME>();

    setTransitions();
}
}




@@ -124,7 +122,6 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent )
        }
        }
    }
    }


    setTransitions();
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );


    return 0;
    return 0;
@@ -172,7 +169,6 @@ int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent )
        }
        }
    }
    }


    setTransitions();
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );


    return 0;
    return 0;
@@ -220,7 +216,6 @@ int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent )
        }
        }
    }
    }


    setTransitions();
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );


    return 0;
    return 0;
@@ -411,7 +406,6 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
    m_controls->CaptureCursor( false );
    m_controls->CaptureCursor( false );
    m_view->Remove( &preview );
    m_view->Remove( &preview );


    setTransitions();
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );


    return 0;
    return 0;
@@ -442,11 +436,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
    const std::list<BOARD_ITEM*>& list = dlg.GetImportedItems();
    const std::list<BOARD_ITEM*>& list = dlg.GetImportedItems();


    if( dlgResult != wxID_OK || m_board->m_Modules == NULL || list.empty() )
    if( dlgResult != wxID_OK || m_board->m_Modules == NULL || list.empty() )
    {
        setTransitions();

        return 0;
        return 0;
    }


    VECTOR2I cursorPos = m_controls->GetCursorPosition();
    VECTOR2I cursorPos = m_controls->GetCursorPosition();
    VECTOR2I delta = cursorPos - (*list.begin())->GetPosition();
    VECTOR2I delta = cursorPos - (*list.begin())->GetPosition();
@@ -617,8 +607,6 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
    m_controls->CaptureCursor( false );
    m_controls->CaptureCursor( false );
    m_view->Remove( &preview );
    m_view->Remove( &preview );


    setTransitions();

    return 0;
    return 0;
}
}


@@ -663,7 +651,6 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
    m_controls->SetSnapping( false );
    m_controls->SetSnapping( false );
    m_controls->ShowCursor( false );
    m_controls->ShowCursor( false );


    setTransitions();
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );


    return 0;
    return 0;
@@ -1230,7 +1217,6 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
    m_controls->CaptureCursor( false );
    m_controls->CaptureCursor( false );
    m_view->Remove( &preview );
    m_view->Remove( &preview );


    setTransitions();
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );


    return 0;
    return 0;
@@ -1351,7 +1337,6 @@ int DRAWING_TOOL::placeTextModule()
    m_controls->CaptureCursor( true );
    m_controls->CaptureCursor( true );
    m_view->Remove( &preview );
    m_view->Remove( &preview );


    setTransitions();
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );


    return 0;
    return 0;
@@ -1461,7 +1446,6 @@ int DRAWING_TOOL::placeTextPcb()
    m_controls->CaptureCursor( false );
    m_controls->CaptureCursor( false );
    m_view->Remove( &preview );
    m_view->Remove( &preview );


    setTransitions();
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );


    return 0;
    return 0;
@@ -1490,7 +1474,7 @@ void DRAWING_TOOL::make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper )
}
}




void DRAWING_TOOL::setTransitions()
void DRAWING_TOOL::SetTransitions()
{
{
    Go( &DRAWING_TOOL::DrawLine,         COMMON_ACTIONS::drawLine.MakeEvent() );
    Go( &DRAWING_TOOL::DrawLine,         COMMON_ACTIONS::drawLine.MakeEvent() );
    Go( &DRAWING_TOOL::DrawCircle,       COMMON_ACTIONS::drawCircle.MakeEvent() );
    Go( &DRAWING_TOOL::DrawCircle,       COMMON_ACTIONS::drawCircle.MakeEvent() );
+3 −3
Original line number Original line Diff line number Diff line
@@ -132,6 +132,9 @@ public:
        m_editModules = aEnabled;
        m_editModules = aEnabled;
    }
    }


    ///> Sets up handlers for various events.
    void SetTransitions();

private:
private:
    ///> Starts drawing a selected shape (i.e. DRAWSEGMENT).
    ///> Starts drawing a selected shape (i.e. DRAWSEGMENT).
    ///> @param aShape is the type of created shape (@see STROKE_T).
    ///> @param aShape is the type of created shape (@see STROKE_T).
@@ -176,9 +179,6 @@ private:
     */
     */
    void make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) const;
    void make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) const;


    ///> Sets up handlers for various events.
    void setTransitions();

    ///> Returns the appropriate width for a segment depending on the settings.
    ///> Returns the appropriate width for a segment depending on the settings.
    int getSegmentWidth( unsigned int aLayer ) const;
    int getSegmentWidth( unsigned int aLayer ) const;


+1 −46
Original line number Original line Diff line number Diff line
@@ -96,8 +96,6 @@ bool EDIT_TOOL::Init()
    m_offset.x = 0;
    m_offset.x = 0;
    m_offset.y = 0;
    m_offset.y = 0;


    setTransitions();

    return true;
    return true;
}
}


@@ -128,10 +126,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
    // Be sure that there is at least one item that we can modify. If nothing was selected before,
    // Be sure that there is at least one item that we can modify. If nothing was selected before,
    // try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection)
    // try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection)
    if( !hoverSelection( selection ) )
    if( !hoverSelection( selection ) )
    {
        setTransitions();
        return 0;
        return 0;
    }


    Activate();
    Activate();


@@ -345,8 +340,6 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
    controls->SetAutoPan( false );
    controls->SetAutoPan( false );
    controls->ForceCursorPosition( false );
    controls->ForceCursorPosition( false );


    setTransitions();

    return 0;
    return 0;
}
}


@@ -357,11 +350,7 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
    PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
    PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();


    if( !hoverSelection( selection, false ) )
    if( !hoverSelection( selection, false ) )
    {
        setTransitions();

        return 0;
        return 0;
    }


    // Properties are displayed when there is only one item selected
    // Properties are displayed when there is only one item selected
    if( selection.Size() == 1 )
    if( selection.Size() == 1 )
@@ -398,8 +387,6 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
        item->SetFlags( flags );
        item->SetFlags( flags );
    }
    }


    setTransitions();

    return 0;
    return 0;
}
}


@@ -413,11 +400,7 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
    bool unselect = selection.Empty();
    bool unselect = selection.Empty();


    if( !hoverSelection( selection ) )
    if( !hoverSelection( selection ) )
    {
        setTransitions();

        return 0;
        return 0;
    }


    wxPoint rotatePoint = getModificationPoint( selection );
    wxPoint rotatePoint = getModificationPoint( selection );


@@ -453,7 +436,6 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
        m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
        m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );


    m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
    m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
    setTransitions();


    return 0;
    return 0;
}
}
@@ -468,11 +450,7 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
    bool unselect = selection.Empty();
    bool unselect = selection.Empty();


    if( !hoverSelection( selection ) )
    if( !hoverSelection( selection ) )
    {
        setTransitions();

        return 0;
        return 0;
    }


    wxPoint flipPoint = getModificationPoint( selection );
    wxPoint flipPoint = getModificationPoint( selection );


@@ -507,7 +485,6 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
        m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
        m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );


    m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
    m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
    setTransitions();


    return 0;
    return 0;
}
}
@@ -518,11 +495,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
    const SELECTION& selection = m_selectionTool->GetSelection();
    const SELECTION& selection = m_selectionTool->GetSelection();


    if( !hoverSelection( selection ) )
    if( !hoverSelection( selection ) )
    {
        setTransitions();

        return 0;
        return 0;
    }


    // Get a copy of the selected items set
    // Get a copy of the selected items set
    PICKED_ITEMS_LIST selectedItems = selection.items;
    PICKED_ITEMS_LIST selectedItems = selection.items;
@@ -544,8 +517,6 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )


    getModel<BOARD>()->GetRatsnest()->Recalculate();
    getModel<BOARD>()->GetRatsnest()->Recalculate();


    setTransitions();

    return 0;
    return 0;
}
}


@@ -655,11 +626,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
    bool unselect = selection.Empty();
    bool unselect = selection.Empty();


    if( !hoverSelection( selection ) )
    if( !hoverSelection( selection ) )
    {
        setTransitions();

        return 0;
        return 0;
    }


    wxPoint translation;
    wxPoint translation;
    double rotation = 0;
    double rotation = 0;
@@ -705,8 +672,6 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
        m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
        m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
    }
    }


    setTransitions();

    return 0;
    return 0;
}
}


@@ -721,10 +686,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )


    // Be sure that there is at least one item that we can modify
    // Be sure that there is at least one item that we can modify
    if( !hoverSelection( selection ) )
    if( !hoverSelection( selection ) )
    {
        setTransitions();
        return 0;
        return 0;
    }


    // we have a selection to work on now, so start the tool process
    // we have a selection to work on now, so start the tool process


@@ -803,8 +765,6 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
    // and re-enable undos
    // and re-enable undos
    decUndoInhibit();
    decUndoInhibit();


    setTransitions();

    return 0;
    return 0;
}
}


@@ -817,10 +777,7 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent )


    // Be sure that there is at least one item that we can modify
    // Be sure that there is at least one item that we can modify
    if( !hoverSelection( selection ) )
    if( !hoverSelection( selection ) )
    {
        setTransitions();
        return 0;
        return 0;
    }


    bool originalItemsModified = false;
    bool originalItemsModified = false;


@@ -980,13 +937,12 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent )
    }
    }


    getModel<BOARD>()->GetRatsnest()->Recalculate();
    getModel<BOARD>()->GetRatsnest()->Recalculate();
    setTransitions();


    return 0;
    return 0;
}
}




void EDIT_TOOL::setTransitions()
void EDIT_TOOL::SetTransitions()
{
{
    Go( &EDIT_TOOL::Main,       COMMON_ACTIONS::editActivate.MakeEvent() );
    Go( &EDIT_TOOL::Main,       COMMON_ACTIONS::editActivate.MakeEvent() );
    Go( &EDIT_TOOL::Rotate,     COMMON_ACTIONS::rotate.MakeEvent() );
    Go( &EDIT_TOOL::Rotate,     COMMON_ACTIONS::rotate.MakeEvent() );
@@ -1125,6 +1081,5 @@ int EDIT_TOOL::editFootprintInFpEditor( const TOOL_EVENT& aEvent )
    editor->Show( true );
    editor->Show( true );
    editor->Raise();        // Iconize( false );
    editor->Raise();        // Iconize( false );


    setTransitions();
    return 0;
    return 0;
}
}
Loading