Commit 2b62a852 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Refactoring: made VIEW, VIEW_CONTROLS, BOARD and PCB_EDIT_FRAME fields in DRAWING_TOOL.

parent 597e98db
Loading
Loading
Loading
Loading
+132 −153
Original line number Original line Diff line number Diff line
@@ -55,6 +55,12 @@ DRAWING_TOOL::~DRAWING_TOOL()


void DRAWING_TOOL::Reset( RESET_REASON aReason )
void DRAWING_TOOL::Reset( RESET_REASON aReason )
{
{
    // Init variables used by every drawing tool
    m_view = getView();
    m_controls = getViewControls();
    m_board = getModel<BOARD>( PCB_T );
    m_frame = getEditFrame<PCB_EDIT_FRAME>();

    setTransitions();
    setTransitions();
}
}


@@ -81,9 +87,6 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )


    int step = 0;
    int step = 0;


    KIGFX::VIEW* view = getView();
    KIGFX::VIEW_CONTROLS* controls = getViewControls();
    BOARD* board = getModel<BOARD>( PCB_T );
    DRAWSEGMENT graphic;
    DRAWSEGMENT graphic;
    DRAWSEGMENT helperLine;
    DRAWSEGMENT helperLine;
    bool positive = true;
    bool positive = true;
@@ -91,25 +94,25 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
    // Init the new item attributes
    // Init the new item attributes
    graphic.SetShape( S_ARC );
    graphic.SetShape( S_ARC );
    graphic.SetAngle( 0.0 );
    graphic.SetAngle( 0.0 );
    graphic.SetWidth( board->GetDesignSettings().m_DrawSegmentWidth );
    graphic.SetWidth( m_board->GetDesignSettings().m_DrawSegmentWidth );


    helperLine.SetShape( S_SEGMENT );
    helperLine.SetShape( S_SEGMENT );
    helperLine.SetLayer( DRAW_N );
    helperLine.SetLayer( DRAW_N );
    helperLine.SetWidth( 1 );
    helperLine.SetWidth( 1 );


    // Add a VIEW_GROUP that serves as a preview for the new item
    // Add a VIEW_GROUP that serves as a preview for the new item
    KIGFX::VIEW_GROUP preview( view );
    KIGFX::VIEW_GROUP preview( m_view );
    view->Add( &preview );
    m_view->Add( &preview );


    controls->ShowCursor( true );
    m_controls->ShowCursor( true );
    controls->SetSnapping( true );
    m_controls->SetSnapping( true );


    Activate();
    Activate();


    // Main loop: keep receiving events
    // Main loop: keep receiving events
    while( OPT_TOOL_EVENT evt = Wait() )
    while( OPT_TOOL_EVENT evt = Wait() )
    {
    {
        VECTOR2I cursorPos = controls->GetCursorPosition();
        VECTOR2I cursorPos = m_controls->GetCursorPosition();


        if( evt->IsCancel() )
        if( evt->IsCancel() )
            break;
            break;
@@ -151,7 +154,7 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
                }
                }
                else
                else
                {
                {
                    controls->SetAutoPan( true );
                    m_controls->SetAutoPan( true );


                    helperLine.SetStart( graphic.GetCenter() );
                    helperLine.SetStart( graphic.GetCenter() );
                    graphic.SetLayer( layer );
                    graphic.SetLayer( layer );
@@ -166,8 +169,8 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
                if( wxPoint( cursorPos.x, cursorPos.y ) != graphic.GetCenter() )
                if( wxPoint( cursorPos.x, cursorPos.y ) != graphic.GetCenter() )
                {
                {
                    DRAWSEGMENT* newItem = new DRAWSEGMENT( graphic );
                    DRAWSEGMENT* newItem = new DRAWSEGMENT( graphic );
                    view->Add( newItem );
                    m_view->Add( newItem );
                    board->Add( newItem );
                    m_board->Add( newItem );
                    newItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
                    newItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
                }
                }
            }
            }
@@ -217,10 +220,10 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
        }
        }
    }
    }


    controls->ShowCursor( false );
    m_controls->ShowCursor( false );
    controls->SetSnapping( false );
    m_controls->SetSnapping( false );
    controls->SetAutoPan( false );
    m_controls->SetAutoPan( false );
    view->Remove( &preview );
    m_view->Remove( &preview );


    setTransitions();
    setTransitions();


@@ -228,24 +231,21 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
}
}




int DRAWING_TOOL::draw( STROKE_T aShape )
int DRAWING_TOOL::draw( int aShape )
{
{
    bool started = false;
    bool started = false;
    KIGFX::VIEW* view = getView();
    KIGFX::VIEW_CONTROLS* controls = getViewControls();
    BOARD* board = getModel<BOARD>( PCB_T );
    DRAWSEGMENT graphic;
    DRAWSEGMENT graphic;


    // Init the new item attributes
    // Init the new item attributes
    graphic.SetShape( aShape );
    graphic.SetShape( (STROKE_T) aShape );
    graphic.SetWidth( board->GetDesignSettings().m_DrawSegmentWidth );
    graphic.SetWidth( m_board->GetDesignSettings().m_DrawSegmentWidth );


    // Add a VIEW_GROUP that serves as a preview for the new item
    // Add a VIEW_GROUP that serves as a preview for the new item
    KIGFX::VIEW_GROUP preview( view );
    KIGFX::VIEW_GROUP preview( m_view );
    view->Add( &preview );
    m_view->Add( &preview );


    controls->ShowCursor( true );
    m_controls->ShowCursor( true );
    controls->SetSnapping( true );
    m_controls->SetSnapping( true );


    Activate();
    Activate();


@@ -254,7 +254,7 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
    {
    {
        // Enable 45 degrees lines only mode by holding shift
        // Enable 45 degrees lines only mode by holding shift
        bool linesAngle45 = evt->Modifier( MD_SHIFT );
        bool linesAngle45 = evt->Modifier( MD_SHIFT );
        VECTOR2I cursorPos = controls->GetCursorPosition();
        VECTOR2I cursorPos = m_controls->GetCursorPosition();


        if( evt->IsCancel() )
        if( evt->IsCancel() )
            break;
            break;
@@ -276,7 +276,7 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
        {
        {
            if( !started )
            if( !started )
            {
            {
                LAYER_NUM layer = getEditFrame<PCB_EDIT_FRAME>()->GetScreen()->m_Active_Layer;
                LAYER_NUM layer = m_frame->GetScreen()->m_Active_Layer;


                if( IsCopperLayer( layer ) )
                if( IsCopperLayer( layer ) )
                {
                {
@@ -284,7 +284,7 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
                }
                }
                else
                else
                {
                {
                    controls->SetAutoPan( true );
                    m_controls->SetAutoPan( true );


                    graphic.SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
                    graphic.SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
                    graphic.SetLayer( layer );
                    graphic.SetLayer( layer );
@@ -298,8 +298,8 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
                if( wxPoint( cursorPos.x, cursorPos.y ) != graphic.GetStart() )
                if( wxPoint( cursorPos.x, cursorPos.y ) != graphic.GetStart() )
                {
                {
                    DRAWSEGMENT* newItem = new DRAWSEGMENT( graphic );
                    DRAWSEGMENT* newItem = new DRAWSEGMENT( graphic );
                    view->Add( newItem );
                    m_view->Add( newItem );
                    board->Add( newItem );
                    m_board->Add( newItem );
                    newItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
                    newItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );


                    if( m_continous )
                    if( m_continous )
@@ -325,7 +325,7 @@ int DRAWING_TOOL::draw( STROKE_T aShape )


                // Snap the new line to the grid // TODO fix it, does not work good..
                // Snap the new line to the grid // TODO fix it, does not work good..
                VECTOR2D newLineEnd = VECTOR2D( graphic.GetStart() ) + newLineVector;
                VECTOR2D newLineEnd = VECTOR2D( graphic.GetStart() ) + newLineVector;
                VECTOR2D snapped = view->GetGAL()->GetGridPoint( newLineEnd );
                VECTOR2D snapped = m_view->GetGAL()->GetGridPoint( newLineEnd );


                graphic.SetEnd( wxPoint( snapped.x, snapped.y ) );
                graphic.SetEnd( wxPoint( snapped.x, snapped.y ) );
            }
            }
@@ -339,10 +339,10 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
        }
        }
    }
    }


    controls->ShowCursor( false );
    m_controls->ShowCursor( false );
    controls->SetSnapping( false );
    m_controls->SetSnapping( false );
    controls->SetAutoPan( false );
    m_controls->SetAutoPan( false );
    view->Remove( &preview );
    m_view->Remove( &preview );
    setTransitions();
    setTransitions();


    return 0;
    return 0;
@@ -351,11 +351,8 @@ int DRAWING_TOOL::draw( STROKE_T aShape )


int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
{
{
    KIGFX::VIEW* view = getView();
    KIGFX::VIEW_CONTROLS* controls = getViewControls();

    // Init the new item attributes
    // Init the new item attributes
    TEXTE_PCB* newText = getEditFrame<PCB_EDIT_FRAME>()->CreateTextePcb( NULL );
    TEXTE_PCB* newText = m_frame->CreateTextePcb( NULL );
    if( newText == NULL )
    if( newText == NULL )
    {
    {
        setTransitions();
        setTransitions();
@@ -363,25 +360,25 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
    }
    }


    // Add a VIEW_GROUP that serves as a preview for the new item
    // Add a VIEW_GROUP that serves as a preview for the new item
    KIGFX::VIEW_GROUP preview( view );
    KIGFX::VIEW_GROUP preview( m_view );
    preview.Add( newText );
    preview.Add( newText );
    view->Add( &preview );
    m_view->Add( &preview );


    controls->ShowCursor( true );
    m_controls->ShowCursor( true );
    controls->SetSnapping( true );
    m_controls->SetSnapping( true );
    controls->SetAutoPan( true );
    m_controls->SetAutoPan( true );


    Activate();
    Activate();


    // Main loop: keep receiving events
    // Main loop: keep receiving events
    while( OPT_TOOL_EVENT evt = Wait() )
    while( OPT_TOOL_EVENT evt = Wait() )
    {
    {
        VECTOR2I cursorPos = controls->GetCursorPosition();
        VECTOR2I cursorPos = m_controls->GetCursorPosition();


        if( evt->IsCancel() )
        if( evt->IsCancel() )
        {
        {
            // it was already added by CreateTextPcb()
            // it was already added by CreateTextPcb()
            getModel<BOARD>( PCB_T )->Delete( newText );
            m_board->Delete( newText );
            break;
            break;
        }
        }


@@ -389,7 +386,7 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
        {
        {
            if( evt->IsAction( &COMMON_ACTIONS::rotate ) )
            if( evt->IsAction( &COMMON_ACTIONS::rotate ) )
            {
            {
                newText->Rotate( newText->GetPosition(), getEditFrame<PCB_EDIT_FRAME>()->GetRotationAngle() );
                newText->Rotate( newText->GetPosition(), m_frame->GetRotationAngle() );
                preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
                preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
            }
            }
            else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
            else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
@@ -402,8 +399,8 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
        else if( evt->IsClick( BUT_LEFT ) )
        else if( evt->IsClick( BUT_LEFT ) )
        {
        {
            newText->ClearFlags();
            newText->ClearFlags();
            view->Add( newText );
            m_view->Add( newText );
            // board->Add( newText );        // it is already added by CreateTextePcb()
            // m_board->Add( newText );        // it is already added by CreateTextePcb()
            newText->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
            newText->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
            break;
            break;
        }
        }
@@ -417,10 +414,10 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
        }
        }
    }
    }


    controls->ShowCursor( false );
    m_controls->ShowCursor( false );
    controls->SetSnapping( false );
    m_controls->SetSnapping( false );
    controls->SetAutoPan( false );
    m_controls->SetAutoPan( false );
    view->Remove( &preview );
    m_view->Remove( &preview );


    setTransitions();
    setTransitions();


@@ -434,14 +431,11 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )


    int step = 0;
    int step = 0;


    KIGFX::VIEW* view = getView();
    DIMENSION* dimension = new DIMENSION( m_board );
    KIGFX::VIEW_CONTROLS* controls = getViewControls();
    BOARD* board = getModel<BOARD>( PCB_T );
    DIMENSION* dimension = new DIMENSION( board );


    // Init the new item attributes
    // Init the new item attributes
    dimension->Text().SetSize( board->GetDesignSettings().m_PcbTextSize );
    dimension->Text().SetSize( m_board->GetDesignSettings().m_PcbTextSize );
    int width = board->GetDesignSettings().m_PcbTextWidth;
    int width = m_board->GetDesignSettings().m_PcbTextWidth;
    int maxthickness = Clamp_Text_PenSize( width, dimension->Text().GetSize() );
    int maxthickness = Clamp_Text_PenSize( width, dimension->Text().GetSize() );


    if( width > maxthickness )
    if( width > maxthickness )
@@ -453,18 +447,18 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
    dimension->AdjustDimensionDetails();
    dimension->AdjustDimensionDetails();


    // Add a VIEW_GROUP that serves as a preview for the new item
    // Add a VIEW_GROUP that serves as a preview for the new item
    KIGFX::VIEW_GROUP preview( view );
    KIGFX::VIEW_GROUP preview( m_view );
    view->Add( &preview );
    m_view->Add( &preview );


    controls->ShowCursor( true );
    m_controls->ShowCursor( true );
    controls->SetSnapping( true );
    m_controls->SetSnapping( true );


    Activate();
    Activate();


    // Main loop: keep receiving events
    // Main loop: keep receiving events
    while( OPT_TOOL_EVENT evt = Wait() )
    while( OPT_TOOL_EVENT evt = Wait() )
    {
    {
        VECTOR2I cursorPos = controls->GetCursorPosition();
        VECTOR2I cursorPos = m_controls->GetCursorPosition();


        if( evt->IsCancel() )
        if( evt->IsCancel() )
        {
        {
@@ -491,7 +485,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
            {
            {
            case 0:
            case 0:
            {
            {
                LAYER_NUM layer = getEditFrame<PCB_EDIT_FRAME>()->GetScreen()->m_Active_Layer;
                LAYER_NUM layer = m_frame->GetScreen()->m_Active_Layer;


                if( IsCopperLayer( layer ) )
                if( IsCopperLayer( layer ) )
                {
                {
@@ -500,7 +494,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
                }
                }
                else
                else
                {
                {
                    controls->SetAutoPan( true );
                    m_controls->SetAutoPan( true );


                    dimension->SetLayer( layer );
                    dimension->SetLayer( layer );
                    dimension->SetOrigin( wxPoint( cursorPos.x, cursorPos.y ) );
                    dimension->SetOrigin( wxPoint( cursorPos.x, cursorPos.y ) );
@@ -514,8 +508,8 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
            {
            {
                if( wxPoint( cursorPos.x, cursorPos.y ) != dimension->GetPosition() )
                if( wxPoint( cursorPos.x, cursorPos.y ) != dimension->GetPosition() )
                {
                {
                    view->Add( dimension );
                    m_view->Add( dimension );
                    board->Add( dimension );
                    m_board->Add( dimension );
                    dimension->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
                    dimension->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
                }
                }
            }
            }
@@ -552,10 +546,10 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
        }
        }
    }
    }


    controls->ShowCursor( false );
    m_controls->ShowCursor( false );
    controls->SetSnapping( false );
    m_controls->SetSnapping( false );
    controls->SetAutoPan( false );
    m_controls->SetAutoPan( false );
    view->Remove( &preview );
    m_view->Remove( &preview );


    setTransitions();
    setTransitions();


@@ -565,20 +559,16 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )


int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
{
{
    KIGFX::VIEW* view = getView();
    ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
    KIGFX::VIEW_CONTROLS* controls = getViewControls();
    BOARD* board = getModel<BOARD>( PCB_T );
    ZONE_CONTAINER* zone = new ZONE_CONTAINER( board );
    PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();


    // Get the current, default settings for zones
    // Get the current, default settings for zones
    ZONE_SETTINGS zoneInfo = editFrame->GetZoneSettings();
    ZONE_SETTINGS zoneInfo = m_frame->GetZoneSettings();


    ZONE_EDIT_T dialogResult;
    ZONE_EDIT_T dialogResult;
    if( IsCopperLayer( editFrame->GetScreen()->m_Active_Layer ) )
    if( IsCopperLayer( m_frame->GetScreen()->m_Active_Layer ) )
        dialogResult = InvokeCopperZonesEditor( editFrame, &zoneInfo );
        dialogResult = InvokeCopperZonesEditor( m_frame, &zoneInfo );
    else
    else
        dialogResult = InvokeNonCopperZonesEditor( editFrame, zone, &zoneInfo );
        dialogResult = InvokeNonCopperZonesEditor( m_frame, zone, &zoneInfo );


    if( dialogResult == ZONE_ABORT )
    if( dialogResult == ZONE_ABORT )
    {
    {
@@ -588,7 +578,7 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
    }
    }


    zoneInfo.ExportSetting( *zone );
    zoneInfo.ExportSetting( *zone );
    editFrame->SetTopLayer( zoneInfo.m_CurrentZone_Layer );
    m_frame->SetTopLayer( zoneInfo.m_CurrentZone_Layer );


    DRAWSEGMENT* helperLine = new DRAWSEGMENT;
    DRAWSEGMENT* helperLine = new DRAWSEGMENT;
    helperLine->SetShape( S_SEGMENT );
    helperLine->SetShape( S_SEGMENT );
@@ -596,23 +586,23 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
    helperLine->SetWidth( 1 );
    helperLine->SetWidth( 1 );


    // Add a VIEW_GROUP that serves as a preview for the new item
    // Add a VIEW_GROUP that serves as a preview for the new item
    KIGFX::VIEW_GROUP preview( view );
    KIGFX::VIEW_GROUP preview( m_view );
    view->Add( &preview );
    m_view->Add( &preview );


    controls->ShowCursor( true );
    m_controls->ShowCursor( true );
    controls->SetSnapping( true );
    m_controls->SetSnapping( true );
    controls->SetAutoPan( true );
    m_controls->SetAutoPan( true );


    Activate();
    Activate();


    VECTOR2I lastCursorPos = controls->GetCursorPosition();
    VECTOR2I lastCursorPos = m_controls->GetCursorPosition();


    // Main loop: keep receiving events
    // Main loop: keep receiving events
    while( OPT_TOOL_EVENT evt = Wait() )
    while( OPT_TOOL_EVENT evt = Wait() )
    {
    {
        // Enable 45 degrees lines only mode by holding shift
        // Enable 45 degrees lines only mode by holding shift
        bool linesAngle45 = evt->Modifier( MD_SHIFT );
        bool linesAngle45 = evt->Modifier( MD_SHIFT );
        VECTOR2I cursorPos = controls->GetCursorPosition();
        VECTOR2I cursorPos = m_controls->GetCursorPosition();


        if( evt->IsCancel() )
        if( evt->IsCancel() )
        {
        {
@@ -631,10 +621,10 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
                    zone->Outline()->CloseLastContour();
                    zone->Outline()->CloseLastContour();
                    zone->Outline()->RemoveNullSegments();
                    zone->Outline()->RemoveNullSegments();


                    board->Add( zone );
                    m_board->Add( zone );
                    view->Add( zone );
                    m_view->Add( zone );


                    editFrame->Fill_Zone( zone );
                    m_frame->Fill_Zone( zone );
                    zone->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
                    zone->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
                }
                }
                else
                else
@@ -684,7 +674,7 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )


                // Snap the new line to the grid // TODO fix it, does not work good..
                // Snap the new line to the grid // TODO fix it, does not work good..
                VECTOR2D newLineEnd = VECTOR2D( helperLine->GetStart() ) + newLineVector;
                VECTOR2D newLineEnd = VECTOR2D( helperLine->GetStart() ) + newLineVector;
                VECTOR2D snapped = view->GetGAL()->GetGridPoint( newLineEnd );
                VECTOR2D snapped = m_view->GetGAL()->GetGridPoint( newLineEnd );


                helperLine->SetEnd( wxPoint( snapped.x, snapped.y ) );
                helperLine->SetEnd( wxPoint( snapped.x, snapped.y ) );
            }
            }
@@ -698,10 +688,10 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
        }
        }
    }
    }


    controls->ShowCursor( false );
    m_controls->ShowCursor( false );
    controls->SetSnapping( false );
    m_controls->SetSnapping( false );
    controls->SetAutoPan( false );
    m_controls->SetAutoPan( false );
    view->Remove( &preview );
    m_view->Remove( &preview );


    // delete helper lines
    // delete helper lines
    preview.FreeItems();
    preview.FreeItems();
@@ -714,16 +704,12 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )


int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
{
{
    KIGFX::VIEW* view = getView();
    ZONE_CONTAINER* keepout = new ZONE_CONTAINER( m_board );
    KIGFX::VIEW_CONTROLS* controls = getViewControls();
    BOARD* board = getModel<BOARD>( PCB_T );
    ZONE_CONTAINER* keepout = new ZONE_CONTAINER( board );
    PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();


    // Get the current, default settings for zones
    // Get the current, default settings for zones
    ZONE_SETTINGS zoneInfo = editFrame->GetZoneSettings();
    ZONE_SETTINGS zoneInfo = m_frame->GetZoneSettings();


    ZONE_EDIT_T dialogResult = InvokeKeepoutAreaEditor( editFrame, &zoneInfo );
    ZONE_EDIT_T dialogResult = InvokeKeepoutAreaEditor( m_frame, &zoneInfo );
    if( dialogResult == ZONE_ABORT )
    if( dialogResult == ZONE_ABORT )
    {
    {
        delete keepout;
        delete keepout;
@@ -732,7 +718,7 @@ int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
    }
    }


    zoneInfo.ExportSetting( *keepout );
    zoneInfo.ExportSetting( *keepout );
    editFrame->SetTopLayer( zoneInfo.m_CurrentZone_Layer );
    m_frame->SetTopLayer( zoneInfo.m_CurrentZone_Layer );


    DRAWSEGMENT* helperLine = new DRAWSEGMENT;
    DRAWSEGMENT* helperLine = new DRAWSEGMENT;
    helperLine->SetShape( S_SEGMENT );
    helperLine->SetShape( S_SEGMENT );
@@ -740,23 +726,23 @@ int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
    helperLine->SetWidth( 1 );
    helperLine->SetWidth( 1 );


    // Add a VIEW_GROUP that serves as a preview for the new item
    // Add a VIEW_GROUP that serves as a preview for the new item
    KIGFX::VIEW_GROUP preview( view );
    KIGFX::VIEW_GROUP preview( m_view );
    view->Add( &preview );
    m_view->Add( &preview );


    controls->ShowCursor( true );
    m_controls->ShowCursor( true );
    controls->SetSnapping( true );
    m_controls->SetSnapping( true );
    controls->SetAutoPan( true );
    m_controls->SetAutoPan( true );


    Activate();
    Activate();


    VECTOR2I lastCursorPos = controls->GetCursorPosition();
    VECTOR2I lastCursorPos = m_controls->GetCursorPosition();


    // Main loop: keep receiving events
    // Main loop: keep receiving events
    while( OPT_TOOL_EVENT evt = Wait() )
    while( OPT_TOOL_EVENT evt = Wait() )
    {
    {
        // Enable 45 degrees lines only mode by holding shift
        // Enable 45 degrees lines only mode by holding shift
        bool linesAngle45 = evt->Modifier( MD_SHIFT );
        bool linesAngle45 = evt->Modifier( MD_SHIFT );
        VECTOR2I cursorPos = controls->GetCursorPosition();
        VECTOR2I cursorPos = m_controls->GetCursorPosition();


        if( evt->IsCancel() )
        if( evt->IsCancel() )
        {
        {
@@ -775,8 +761,8 @@ int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
                    keepout->Outline()->CloseLastContour();
                    keepout->Outline()->CloseLastContour();
                    keepout->Outline()->RemoveNullSegments();
                    keepout->Outline()->RemoveNullSegments();


                    board->Add( keepout );
                    m_board->Add( keepout );
                    view->Add( keepout );
                    m_view->Add( keepout );


                    keepout->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
                    keepout->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
                }
                }
@@ -827,7 +813,7 @@ int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )


                // Snap the new line to the grid // TODO fix it, does not work good..
                // Snap the new line to the grid // TODO fix it, does not work good..
                VECTOR2D newLineEnd = VECTOR2D( helperLine->GetStart() ) + newLineVector;
                VECTOR2D newLineEnd = VECTOR2D( helperLine->GetStart() ) + newLineVector;
                VECTOR2D snapped = view->GetGAL()->GetGridPoint( newLineEnd );
                VECTOR2D snapped = m_view->GetGAL()->GetGridPoint( newLineEnd );


                helperLine->SetEnd( wxPoint( snapped.x, snapped.y ) );
                helperLine->SetEnd( wxPoint( snapped.x, snapped.y ) );
            }
            }
@@ -841,10 +827,10 @@ int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
        }
        }
    }
    }


    controls->ShowCursor( false );
    m_controls->ShowCursor( false );
    controls->SetSnapping( false );
    m_controls->SetSnapping( false );
    controls->SetAutoPan( false );
    m_controls->SetAutoPan( false );
    view->Remove( &preview );
    m_view->Remove( &preview );


    // delete helper lines
    // delete helper lines
    preview.FreeItems();
    preview.FreeItems();
@@ -857,32 +843,29 @@ int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )


int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
{
{
    KIGFX::VIEW* view = getView();
    PCB_TARGET* target = new PCB_TARGET( m_board );
    KIGFX::VIEW_CONTROLS* controls = getViewControls();
    BOARD* board = getModel<BOARD>( PCB_T );
    PCB_TARGET* target = new PCB_TARGET( board );


    // Init the new item attributes
    // Init the new item attributes
    target->SetLayer( EDGE_N );
    target->SetLayer( EDGE_N );
    target->SetWidth( board->GetDesignSettings().m_EdgeSegmentWidth );
    target->SetWidth( m_board->GetDesignSettings().m_EdgeSegmentWidth );
    target->SetSize( Millimeter2iu( 5 ) );
    target->SetSize( Millimeter2iu( 5 ) );
    VECTOR2I cursorPos = controls->GetCursorPosition();
    VECTOR2I cursorPos = m_controls->GetCursorPosition();
    target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
    target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );


    // Add a VIEW_GROUP that serves as a preview for the new item
    // Add a VIEW_GROUP that serves as a preview for the new item
    KIGFX::VIEW_GROUP preview( view );
    KIGFX::VIEW_GROUP preview( m_view );
    preview.Add( target );
    preview.Add( target );
    view->Add( &preview );
    m_view->Add( &preview );
    preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
    preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );


    controls->SetSnapping( true );
    m_controls->SetSnapping( true );


    Activate();
    Activate();


    // Main loop: keep receiving events
    // Main loop: keep receiving events
    while( OPT_TOOL_EVENT evt = Wait() )
    while( OPT_TOOL_EVENT evt = Wait() )
    {
    {
        VECTOR2I cursorPos = controls->GetCursorPosition();
        VECTOR2I cursorPos = m_controls->GetCursorPosition();


        if( evt->IsCancel() )
        if( evt->IsCancel() )
        {
        {
@@ -905,8 +888,8 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )


        else if( evt->IsClick( BUT_LEFT ) )
        else if( evt->IsClick( BUT_LEFT ) )
        {
        {
            view->Add( target );
            m_view->Add( target );
            board->Add( target );
            m_board->Add( target );
            target->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
            target->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
            break;
            break;
        }
        }
@@ -918,9 +901,9 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
        }
        }
    }
    }


    controls->SetSnapping( false );
    m_controls->SetSnapping( false );
    controls->SetAutoPan( false );
    m_controls->SetAutoPan( false );
    view->Remove( &preview );
    m_view->Remove( &preview );


    setTransitions();
    setTransitions();


@@ -930,12 +913,8 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )


int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
{
{
    KIGFX::VIEW* view = getView();
    MODULE* module = m_frame->LoadModuleFromLibrary( wxEmptyString,
    KIGFX::VIEW_CONTROLS* controls = getViewControls();
                                               m_frame->GetFootprintLibraryTable(), true, NULL );
    BOARD* board = getModel<BOARD>( PCB_T );
    PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
    MODULE* module = editFrame->LoadModuleFromLibrary( wxEmptyString,
                                               editFrame->GetFootprintLibraryTable(), true, NULL );
    if( module == NULL )
    if( module == NULL )
    {
    {
        setTransitions();
        setTransitions();
@@ -943,28 +922,28 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
    }
    }


    // Init the new item attributes
    // Init the new item attributes
    VECTOR2I cursorPos = controls->GetCursorPosition();
    VECTOR2I cursorPos = m_controls->GetCursorPosition();
    module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
    module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );


    // Add a VIEW_GROUP that serves as a preview for the new item
    // Add a VIEW_GROUP that serves as a preview for the new item
    KIGFX::VIEW_GROUP preview( view );
    KIGFX::VIEW_GROUP preview( m_view );
    preview.Add( module );
    preview.Add( module );
    module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW_GROUP::Add ), &preview ) );
    module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW_GROUP::Add ), &preview ) );
    view->Add( &preview );
    m_view->Add( &preview );
    preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
    preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );


    controls->SetSnapping( true );
    m_controls->SetSnapping( true );


    Activate();
    Activate();


    // Main loop: keep receiving events
    // Main loop: keep receiving events
    while( OPT_TOOL_EVENT evt = Wait() )
    while( OPT_TOOL_EVENT evt = Wait() )
    {
    {
        cursorPos = controls->GetCursorPosition();
        cursorPos = m_controls->GetCursorPosition();


        if( evt->IsCancel() )
        if( evt->IsCancel() )
        {
        {
            board->Delete( module );
            m_board->Delete( module );
            break;
            break;
        }
        }


@@ -972,7 +951,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
        {
        {
            if( evt->IsAction( &COMMON_ACTIONS::rotate ) )
            if( evt->IsAction( &COMMON_ACTIONS::rotate ) )
            {
            {
                module->Rotate( module->GetPosition(), getEditFrame<PCB_EDIT_FRAME>()->GetRotationAngle() );
                module->Rotate( module->GetPosition(), m_frame->GetRotationAngle() );
                preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
                preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
            }
            }
            else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
            else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
@@ -984,8 +963,8 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )


        else if( evt->IsClick( BUT_LEFT ) )
        else if( evt->IsClick( BUT_LEFT ) )
        {
        {
            module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), view ) );
            module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), m_view ) );
            view->Add( module );
            m_view->Add( module );
            module->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
            module->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
            break;
            break;
        }
        }
@@ -997,9 +976,9 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
        }
        }
    }
    }


    controls->SetSnapping( false );
    m_controls->SetSnapping( false );
    controls->SetAutoPan( false );
    m_controls->SetAutoPan( false );
    view->Remove( &preview );
    m_view->Remove( &preview );


    setTransitions();
    setTransitions();


+14 −2
Original line number Original line Diff line number Diff line
@@ -26,7 +26,14 @@
#define __DRAWING_TOOL_H
#define __DRAWING_TOOL_H


#include <tool/tool_interactive.h>
#include <tool/tool_interactive.h>
#include <class_board_item.h>

namespace KIGFX
{
    class VIEW;
    class VIEW_CONTROLS;
}
class BOARD;
class PCB_EDIT_FRAME;


/**
/**
 * Class DRAWING_TOOL
 * Class DRAWING_TOOL
@@ -69,7 +76,7 @@ public:


private:
private:
    ///> Starts drawing a selected shape.
    ///> Starts drawing a selected shape.
    int draw( STROKE_T aShape );
    int draw( int aShape );


    ///> Sets up handlers for various events.
    ///> Sets up handlers for various events.
    void setTransitions();
    void setTransitions();
@@ -77,6 +84,11 @@ private:
    ///> Should drawing be stopped after drawing one object or should it continue with another one.
    ///> Should drawing be stopped after drawing one object or should it continue with another one.
    bool m_continous;
    bool m_continous;


    KIGFX::VIEW* m_view;
    KIGFX::VIEW_CONTROLS* m_controls;
    BOARD* m_board;
    PCB_EDIT_FRAME* m_frame;

    // How does line width change after one -/+ key press.
    // How does line width change after one -/+ key press.
    static const int WIDTH_STEP = 100000;
    static const int WIDTH_STEP = 100000;
};
};