Commit fd8bfe0c authored by Marco Mattila's avatar Marco Mattila
Browse files

Move pcbnew find dialog into dialogs subdirectory and use wxFormBuilder for it.

parent 28bcad84
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -238,9 +238,10 @@ public:
     * Function CursorGoto
     * Function CursorGoto
     * positions the cursor at a given coordinate and reframes the drawing if the
     * positions the cursor at a given coordinate and reframes the drawing if the
     * requested point is out of view.
     * requested point is out of view.
     * @param aPos The point to go to.
     * @param aPos is the point to go to.
     * @param aWarp is true if the pointer should be warped to the new position.
     */
     */
    void CursorGoto( const wxPoint& aPos );
    void CursorGoto( const wxPoint& aPos, bool aWarp = true );


    /**
    /**
     * Function Save_Module_In_Library
     * Function Save_Module_In_Library
+1 −1
Original line number Original line Diff line number Diff line
@@ -1488,7 +1488,7 @@ public:


    void Clean_Pcb( wxDC* DC );
    void Clean_Pcb( wxDC* DC );


    void InstallFindFrame( const wxPoint& pos, wxDC* DC );
    void InstallFindFrame();


    /**
    /**
     * Function SendMessageToEESCHEMA
     * Function SendMessageToEESCHEMA
+2 −1
Original line number Original line Diff line number Diff line
@@ -39,6 +39,8 @@ set(PCBNEW_DIALOGS
    dialogs/dialog_edit_module_text_base.cpp
    dialogs/dialog_edit_module_text_base.cpp
    dialogs/dialog_exchange_modules_base.cpp
    dialogs/dialog_exchange_modules_base.cpp
    dialogs/dialog_export_3Dfiles_base.cpp
    dialogs/dialog_export_3Dfiles_base.cpp
    dialogs/dialog_find_base.cpp
    dialogs/dialog_find.cpp
    dialogs/dialog_freeroute_exchange.cpp
    dialogs/dialog_freeroute_exchange.cpp
    dialogs/dialog_freeroute_exchange_base.cpp
    dialogs/dialog_freeroute_exchange_base.cpp
    dialogs/dialog_gendrill.cpp
    dialogs/dialog_gendrill.cpp
@@ -123,7 +125,6 @@ set(PCBNEW_SRCS
    export_gencad.cpp
    export_gencad.cpp
    export_vrml.cpp
    export_vrml.cpp
    files.cpp
    files.cpp
    find.cpp
    gen_drill_report_files.cpp
    gen_drill_report_files.cpp
    gen_holes_and_tools_lists_for_drill.cpp
    gen_holes_and_tools_lists_for_drill.cpp
    gen_modules_placefile.cpp
    gen_modules_placefile.cpp
+8 −5
Original line number Original line Diff line number Diff line
@@ -266,28 +266,31 @@ double PCB_BASE_FRAME::BestZoom()
}
}




void PCB_BASE_FRAME::CursorGoto( const wxPoint& aPos )
void PCB_BASE_FRAME::CursorGoto( const wxPoint& aPos, bool aWarp )
{
{
    // factored out of pcbnew/find.cpp
    // factored out of pcbnew/find.cpp


    PCB_SCREEN* screen = (PCB_SCREEN*)GetScreen();
    PCB_SCREEN* screen = (PCB_SCREEN*)GetScreen();


    wxClientDC dc( m_canvas );
    INSTALL_UNBUFFERED_DC( dc, m_canvas );


    // There may be need to reframe the drawing.
    // There may be need to reframe the drawing.
    if( !m_canvas->IsPointOnDisplay( aPos ) )
    if( !m_canvas->IsPointOnDisplay( aPos ) )
    {
    {
        screen->SetCrossHairPosition( aPos );
        screen->SetCrossHairPosition( aPos );
        RedrawScreen( aPos, true );
        RedrawScreen( aPos, aWarp );
    }
    }
    else
    else
    {
    {
        // Put cursor on item position
        // Put cursor on item position
        m_canvas->CrossHairOff( &dc );
        m_canvas->CrossHairOff( &dc );
        screen->SetCrossHairPosition( aPos );
        screen->SetCrossHairPosition( aPos );

        if( aWarp )
            m_canvas->MoveCursorToCrossHair();
            m_canvas->MoveCursorToCrossHair();
        m_canvas->CrossHairOn( &dc );
    }
    }
    m_canvas->CrossHairOn( &dc );
    m_canvas->CrossHairOn( &dc );
}
}




+212 −0
Original line number Original line Diff line number Diff line
/*
 * This program source code file is part of KICAD, a free EDA CAD application.
 *
 * Copyright (C) 1992-2012 Marco Mattila <marcom99@gmail.com>
 * Copyright (C) 1992-2012 Kicad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#include <fctsys.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <kicad_string.h>
#include <wxPcbStruct.h>

#include <class_board.h>
#include <class_module.h>
#include <class_marker_pcb.h>

#include <pcbnew.h>
#include <pcbnew_id.h>
#include <protos.h>
#include <dialog_find_base.h>


class DIALOG_FIND : public DIALOG_FIND_BASE
{
public:
    DIALOG_FIND( PCB_BASE_FRAME* aParent );

private:
    PCB_BASE_FRAME* parent;

    int itemCount, markerCount;
    static wxString prevSearchString;
    static bool warpMouse;

    static wxPoint prevPosition;
    static wxSize prevSize;

    void onButtonFindItemClick( wxCommandEvent& event );
    void onButtonFindMarkerClick( wxCommandEvent& event );
    void onButtonCloseClick( wxCommandEvent& event );
    void onClose( wxCloseEvent& event );
};


// Initialize static member variables
wxPoint DIALOG_FIND::prevPosition( -1, -1 );
wxSize DIALOG_FIND::prevSize;
wxString DIALOG_FIND::prevSearchString;
bool DIALOG_FIND::warpMouse = true;


DIALOG_FIND::DIALOG_FIND( PCB_BASE_FRAME* aParent ) : DIALOG_FIND_BASE( aParent )
{
    parent = aParent;
    SetFocus();
    GetSizer()->SetSizeHints( this );

    m_SearchTextCtrl->AppendText( prevSearchString );
    m_NoMouseWarpCheckBox->SetValue( !warpMouse );

    itemCount = markerCount = 0;

    if( prevPosition.x != -1 )
        SetSize( prevPosition.x, prevPosition.y,
                 prevSize.x, prevSize.y );
    else
        Center();
}


void DIALOG_FIND::onButtonCloseClick( wxCommandEvent& aEvent )
{
    Close( true );
}


void DIALOG_FIND::onButtonFindItemClick( wxCommandEvent& aEvent )
{
    PCB_SCREEN* screen = (PCB_SCREEN*) ( parent->GetScreen() );
    wxPoint     pos;
    BOARD_ITEM* foundItem = 0;

    wxString searchString = m_SearchTextCtrl->GetValue();

    if( !searchString.IsSameAs( prevSearchString, false ) )
    {
        itemCount = 0;
    }
    prevSearchString = searchString;

    parent->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );

    int count = 0;

    for( MODULE* module = parent->GetBoard()->m_Modules; module; module = module->Next() )
    {
        if( WildCompareString( searchString, module->GetReference().GetData(), false ) )
        {
            count++;

            if( count > itemCount )
            {
                foundItem = module;
                pos = module->GetPosition();
                itemCount++;
                break;
            }
        }

        if( WildCompareString( searchString, module->m_Value->m_Text.GetData(), false ) )
        {
            count++;

            if( count > itemCount )
            {
                foundItem = module;
                pos = module->m_Pos;
                itemCount++;
                break;
            }
        }
    }

    wxString msg;
    if( foundItem )
    {
        parent->SetCurItem( foundItem );
        msg.Printf( _( "<%s> found" ), GetChars( searchString ) );
        parent->SetStatusText( msg );

        parent->CursorGoto( pos, !m_NoMouseWarpCheckBox->IsChecked() );
    }
    else
    {
        parent->SetStatusText( wxEmptyString );
        msg.Printf( _( "<%s> not found" ), GetChars( searchString ) );
        DisplayError( this, msg, 10 );
        itemCount = 0;
    }
}


void DIALOG_FIND::onButtonFindMarkerClick( wxCommandEvent& aEvent )
{
    PCB_SCREEN* screen = (PCB_SCREEN*) ( parent->GetScreen() );
    wxPoint     pos;
    BOARD_ITEM* foundItem = 0;

    parent->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );

    MARKER_PCB* marker = parent->GetBoard()->GetMARKER( markerCount++ );

    if( marker )
    {
        foundItem = marker;
        pos = marker->GetPosition();
    }

    wxString msg;
    if( foundItem )
    {
        parent->SetCurItem( foundItem );
        msg = _( "Marker found" );
        parent->SetStatusText( msg );

        parent->CursorGoto( pos, !m_NoMouseWarpCheckBox->IsChecked() );
    }
    else
    {
        parent->SetStatusText( wxEmptyString );
        msg = _( "No marker found" );
        DisplayError( this, msg, 10 );
        markerCount = 0;
    }
}


void DIALOG_FIND::onClose( wxCloseEvent& aEvent )
{
    prevPosition = GetPosition();
    prevSize = GetSize();
    warpMouse = !m_NoMouseWarpCheckBox->IsChecked();

    EndModal( 1 );
}


void PCB_EDIT_FRAME::InstallFindFrame()
{
    DIALOG_FIND dlg( this );
    dlg.ShowModal();
}
Loading