Commit 6a26a7f9 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Use logical cursor position and other minor changes.

* Remove unused member variable m_SizeVisu from base screen object.
* Move nearest grid position code into base screen object.
* Add get cursor position method to base screen object.
* Add position parameter to OnHotKey method in base draw frame and all
  derived objects.
* Pass logical position on left mouse button click and double click
  events instead of device position.
* Pass logical position to on right mouse button click instead of device
  position.
* Use logical event position parameter for locating items in EESchema
  instead of the stored position.
* Remove unused position parameter when displaying component edit dialog
  in EESchema.
* Comment out debugging macro in eeschema/template_field_names.cpp that was
  preventing debug builds using wxWidgets 2.8.x.
parent 0093f4f6
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -390,6 +390,39 @@ int BASE_SCREEN::GetGridId()
}


wxPoint BASE_SCREEN::GetNearestGridPosition( const wxPoint& aPosition, wxRealPoint* aGridSize )
{
    wxPoint pt;
    wxRealPoint gridSize;

    if( aGridSize )
        gridSize = *aGridSize;
    else
        gridSize = GetGridSize();

    wxPoint gridOrigin = m_GridOrigin;

    double offset = fmod( gridOrigin.x, gridSize.x );
    int x = wxRound( (aPosition.x - offset) / gridSize.x );
    pt.x = wxRound( x * gridSize.x + offset );

    offset = fmod( gridOrigin.y, gridSize.y );
    int y = wxRound( (aPosition.y - offset) / gridSize.y );
    pt.y = wxRound ( y * gridSize.y + offset );

    return pt;
}


wxPoint BASE_SCREEN::GetCursorPosition( bool aOnGrid, wxRealPoint* aGridSize )
{
    if( aOnGrid )
        return GetNearestGridPosition( m_Curseur, aGridSize );

    return m_Curseur;
}


/* free the undo and the redo lists
 */
void BASE_SCREEN::ClearUndoRedoList()
+1 −1
Original line number Diff line number Diff line
@@ -176,7 +176,7 @@ void EDA_DRAW_FRAME::ReCreateMenuBar()


// Virtual function
void EDA_DRAW_FRAME::OnHotKey( wxDC* DC, int hotkey, EDA_ITEM* DrawStruct )
void EDA_DRAW_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem )
{
}

+12 −9
Original line number Diff line number Diff line
@@ -778,14 +778,17 @@ bool EDA_DRAW_PANEL::OnRightClick( wxMouseEvent& event )
    wxPoint pos;
    wxMenu  MasterMenu;

    pos = event.GetPosition();
    INSTALL_UNBUFFERED_DC( dc, this );

    pos = event.GetLogicalPosition( dc );

    if( !m_Parent->OnRightClick( pos, &MasterMenu ) )
        return false;

    m_Parent->AddMenuZoomAndGrid( &MasterMenu );

    m_IgnoreMouseEvents = TRUE;
    pos = event.GetPosition();
    m_IgnoreMouseEvents = true;
    PopupMenu( &MasterMenu, pos );
    MouseToCursorSchema();
    m_IgnoreMouseEvents = false;
@@ -940,14 +943,14 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )

    localrealbutt |= localbutt;     /* compensation default wxGTK */

    INSTALL_UNBUFFERED_DC( DC, this );
    DC.SetBackground( *wxBLACK_BRUSH );

    /* Compute the cursor position in screen (device) units. */
    wxPoint pos = CalcUnscrolledPosition( event.GetPosition() );

    /* Compute the cursor position in drawing (logical) units. */
    screen->m_MousePosition = CursorRealPosition( pos );

    INSTALL_UNBUFFERED_DC( DC, this );
    DC.SetBackground( *wxBLACK_BRUSH );
    screen->m_MousePosition = event.GetLogicalPosition( DC );

    int kbstat = 0;

@@ -967,7 +970,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
    // Calling Double Click and Click functions :
    if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
    {
        m_Parent->OnLeftDClick( &DC, pos );
        m_Parent->OnLeftDClick( &DC, screen->m_MousePosition );

        // inhibit a response to the mouse left button release,
        // because we have a double click, and we do not want a new
@@ -979,7 +982,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
        // A block command is in progress: a left up is the end of block
        // or this is the end of a double click, already seen
        if( screen->m_BlockLocate.m_State==STATE_NO_BLOCK && !s_IgnoreNextLeftButtonRelease )
            m_Parent->OnLeftClick( &DC, pos );
            m_Parent->OnLeftClick( &DC, screen->m_MousePosition );

        s_IgnoreNextLeftButtonRelease = false;
    }
@@ -1217,7 +1220,7 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event )
        }
    }

    /* Some key commands use the current mouse position: refresh it */
    // Some key commands use the current mouse position: refresh it.
    pos = wxGetMousePosition() - GetScreenPosition();

    // Compute the cursor position in drawing units.  Also known as logical units to wxDC.
+2 −14
Original line number Diff line number Diff line
@@ -51,21 +51,9 @@ void EDA_DRAW_FRAME::RedrawScreen( bool aWarpPointer )
 */
void EDA_DRAW_FRAME::PutOnGrid( wxPoint* aCoord , wxRealPoint* aGridSize )
{
    wxRealPoint grid_size;
    wxCHECK_RET( aCoord != NULL, wxT( "Cannot pull NULL coordinate pointer on grid." ) );

    if( aGridSize )
        grid_size = *aGridSize;
    else
        grid_size = GetBaseScreen()->GetGridSize();

    const wxPoint& grid_origin = GetBaseScreen()->GetGridOrigin();
    double offset = fmod( grid_origin.x, grid_size.x );
    int tmp = wxRound( (aCoord->x - offset) / grid_size.x );
    aCoord->x = wxRound( tmp * grid_size.x + offset );

    offset = fmod( grid_origin.y, grid_size.y );
    tmp = wxRound( (aCoord->y - offset) / grid_size.y );
    aCoord->y = wxRound ( tmp * grid_size.y + offset );
    *aCoord = GetBaseScreen()->GetNearestGridPosition( *aCoord, aGridSize );
}


+89 −100
Original line number Diff line number Diff line
@@ -23,55 +23,60 @@


/**
 * Function SchematicGeneralLocateAndDisplay
 * Overlaid function
 *  Find the schematic item at cursor position
 *  the priority order is:
 *  - marker
 *  - noconnect
 *  - junction
 *  - wire/bus/entry
 *  - label
 *  - pin
 *  - component
 * @return  an EDA_ITEM pointer on the item or NULL if no item found
 * @param IncludePin = true to search for pins, false to ignore them
 * Function LocateAndShowItem
 * search the schematic at \a aPosition in logical (drawing) units for any item.
 * <p>
 * The search is first performed at \a aPosition which may be off grid.  If no item is
 * found at \a aPosition, the search is repeated for the nearest grid position to \a
 * aPosition.
 *
 *  For some items, characteristics are displayed on the screen.
 * The search order is as follows:
 * <ul>
 * <li>Marker</li>
 * <li>No Connect</li>
 * <li>Junction</li>
 * <li>Wire, bus, or entry</li>
 * <li>Label</li>
 * <li>Pin</li>
 * <li>Component</li>
 * </ul></p>
 * @param aPosition The wxPoint on the schematic to search.
 * @param aIncludePin = true to search for pins, false to ignore them
 * @return A SCH_ITEM pointer on the item or NULL if no item found
 */
SCH_ITEM* SCH_EDIT_FRAME::SchematicGeneralLocateAndDisplay( bool IncludePin )
SCH_ITEM* SCH_EDIT_FRAME::LocateAndShowItem( const wxPoint& aPosition, bool aIncludePin )
{
    SCH_ITEM*      DrawStruct;
    SCH_ITEM*      item;
    wxString       msg;
    wxPoint        mouse_position = GetScreen()->m_MousePosition;
    LIB_PIN*       Pin     = NULL;
    SCH_COMPONENT* LibItem = NULL;
    wxPoint        gridPosition = GetScreen()->GetNearestGridPosition( aPosition );

    DrawStruct = SchematicGeneralLocateAndDisplay( mouse_position, IncludePin );
    item = LocateItem( aPosition, aIncludePin );

    if( !DrawStruct && ( mouse_position != GetScreen()->m_Curseur) )
    {
        DrawStruct = SchematicGeneralLocateAndDisplay( GetScreen()->m_Curseur, IncludePin );
    }
    if( !item && aPosition != gridPosition )
        item = LocateItem( gridPosition, aIncludePin );

    if( !DrawStruct )
    if( !item )
        return NULL;

    /* Cross probing to pcbnew if a pin or a component is found */
    switch( DrawStruct->Type() )
    switch( item->Type() )
    {
    case SCH_FIELD_T:
    case LIB_FIELD_T:
        LibItem = (SCH_COMPONENT*) DrawStruct->GetParent();
        SendMessageToPCBNEW( DrawStruct, LibItem );
        LibItem = (SCH_COMPONENT*) item->GetParent();
        SendMessageToPCBNEW( item, LibItem );
        break;

    case SCH_COMPONENT_T:
        Pin = GetScreen()->GetPin( GetScreen()->m_Curseur, &LibItem );

        if( Pin )
            break;  // Priority is probing a pin first
        LibItem = (SCH_COMPONENT*) DrawStruct;
        SendMessageToPCBNEW( DrawStruct, LibItem );

        LibItem = (SCH_COMPONENT*) item;
        SendMessageToPCBNEW( item, LibItem );
        break;

    default:
@@ -79,85 +84,71 @@ SCH_ITEM* SCH_EDIT_FRAME::SchematicGeneralLocateAndDisplay( bool IncludePin )
        break;

    case LIB_PIN_T:
        Pin = (LIB_PIN*) DrawStruct;
        Pin = (LIB_PIN*) item;
        break;
    }

    if( Pin )
    {
        /* Force display pin information (the previous display could be a
         * component info) */
        // Force display pin information (the previous display could be a component info)
        Pin->DisplayInfo( this );

        if( LibItem )
            AppendMsgPanel( LibItem->GetRef( GetSheet() ),
                            LibItem->GetField( VALUE )->m_Text, DARKCYAN );

        // Cross probing:2 - pin found, and send a locate pin command to
        // pcbnew (highlight net)
        // Cross probing:2 - pin found, and send a locate pin command to pcbnew (highlight net)
        SendMessageToPCBNEW( Pin, LibItem );
    }
    return DrawStruct;

    return item;
}


/**
 * Function SchematicGeneralLocateAndDisplay
 * Overlaid function
 *  Find the schematic item at a given position
 *  the priority order is:
 *  - marker
 *  - noconnect
 *  - junction
 *  - wire/bus/entry
 *  - label
 *  - pin
 *  - component
 * @return  an EDA_ITEM pointer on the item or NULL if no item found
 * @param refpoint = the wxPoint location where to search
 * @param IncludePin = true to search for pins, false to ignore them
 *
 *  For some items, characteristics are displayed on the screen.
 * Function LocateItem
 * searches for an item at \a aPosition.
 * @param aPosition The wxPoint location where to search.
 * @param aIncludePin True to search for pins, false to ignore them.
 * @return The SCH_ITEM pointer of the item or NULL if no item found.
 */
SCH_ITEM* SCH_EDIT_FRAME::SchematicGeneralLocateAndDisplay( const wxPoint& refpoint,
                                                            bool           IncludePin )
SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin )
{
    SCH_ITEM*      DrawStruct;
    SCH_ITEM*      item;
    LIB_PIN*       Pin;
    SCH_COMPONENT* LibItem;
    wxString       Text;
    wxString       msg;

    DrawStruct = (SCH_ITEM*) PickStruct( refpoint, GetScreen(), MARKER_T );
    item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), MARKER_T );

    if( DrawStruct )
    if( item )
    {
        DrawStruct->DisplayInfo( this );
        return DrawStruct;
        item->DisplayInfo( this );
        return item;
    }

    DrawStruct = (SCH_ITEM*) PickStruct( refpoint, GetScreen(), NO_CONNECT_T );
    item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), NO_CONNECT_T );

    if( DrawStruct )
    if( item )
    {
        ClearMsgPanel();
        return DrawStruct;
        return item;
    }

    DrawStruct = (SCH_ITEM*) PickStruct( refpoint, GetScreen(), JUNCTION_T );
    item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), JUNCTION_T );

    if( DrawStruct )
    if( item )
    {
        ClearMsgPanel();
        return DrawStruct;
        return item;
    }

    DrawStruct = (SCH_ITEM*) PickStruct( refpoint, GetScreen(),
                                         WIRE_T | BUS_T | BUS_ENTRY_T );
    item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), WIRE_T | BUS_T | BUS_ENTRY_T );

    if( DrawStruct )  // We have found a wire: Search for a connected pin at the same location
    if( item )  // We have found a wire: Search for a connected pin at the same location
    {
        Pin = GetScreen()->GetPin( refpoint, &LibItem );
        Pin = GetScreen()->GetPin( aPosition, &LibItem );

        if( Pin )
        {
@@ -170,30 +161,30 @@ SCH_ITEM* SCH_EDIT_FRAME::SchematicGeneralLocateAndDisplay( const wxPoint& refpo
        else
            ClearMsgPanel();

        return DrawStruct;
        return item;
    }

    DrawStruct = (SCH_ITEM*) PickStruct( refpoint, GetScreen(), FIELD_T );
    item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), FIELD_T );

    if( DrawStruct )
    if( item )
    {
        SCH_FIELD* Field = (SCH_FIELD*) DrawStruct;
        SCH_FIELD* Field = (SCH_FIELD*) item;
        LibItem = (SCH_COMPONENT*) Field->GetParent();
        LibItem->DisplayInfo( this );

        return DrawStruct;
        return item;
    }

    DrawStruct = (SCH_ITEM*) PickStruct( refpoint, GetScreen(), LABEL_T | TEXT_T );
    item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), LABEL_T | TEXT_T );

    if( DrawStruct )
    if( item )
    {
        ClearMsgPanel();
        return DrawStruct;
        return item;
    }

    /* search for a pin */
    Pin = GetScreen()->GetPin( refpoint, &LibItem );
    Pin = GetScreen()->GetPin( aPosition, &LibItem );

    if( Pin )
    {
@@ -202,41 +193,39 @@ SCH_ITEM* SCH_EDIT_FRAME::SchematicGeneralLocateAndDisplay( const wxPoint& refpo
        if( LibItem )
            AppendMsgPanel( LibItem->GetRef( GetSheet() ),
                            LibItem->GetField( VALUE )->m_Text, DARKCYAN );
        if( IncludePin )
        if( aIncludePin )
            return LibItem;
    }

    DrawStruct = (SCH_ITEM*) PickStruct( refpoint, GetScreen(), COMPONENT_T );
    item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), COMPONENT_T );

    if( DrawStruct )
    if( item )
    {
        DrawStruct = LocateSmallestComponent( GetScreen() );
        LibItem    = (SCH_COMPONENT*) DrawStruct;
        item = LocateSmallestComponent( GetScreen() );
        LibItem    = (SCH_COMPONENT*) item;
        LibItem->DisplayInfo( this );
        return DrawStruct;
        return item;
    }

    DrawStruct = (SCH_ITEM*) PickStruct( refpoint, GetScreen(), SHEET_T );
    item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), SHEET_T );

    if( DrawStruct )
    if( item )
    {
        ( (SCH_SHEET*) DrawStruct )->DisplayInfo( this );
        return DrawStruct;
        ( (SCH_SHEET*) item )->DisplayInfo( this );
        return item;
    }

    DrawStruct = (SCH_ITEM*) PickStruct( refpoint, GetScreen(), NO_FILTER_T );
    item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), NO_FILTER_T );

    if( DrawStruct )
    {
        return DrawStruct;
    }
    if( item )
        return item;

    ClearMsgPanel();
    return NULL;
}


void SCH_EDIT_FRAME::GeneralControle( wxDC* aDC, wxPoint aPosition )
void SCH_EDIT_FRAME::GeneralControle( wxDC* aDC, const wxPoint& aPosition )
{
    wxRealPoint gridSize;
    SCH_SCREEN* screen = GetScreen();
@@ -308,9 +297,9 @@ void SCH_EDIT_FRAME::GeneralControle( wxDC* aDC, wxPoint aPosition )
    if( hotkey )
    {
        if( screen->GetCurItem() && screen->GetCurItem()->m_Flags )
            OnHotKey( aDC, hotkey, screen->GetCurItem() );
            OnHotKey( aDC, hotkey, aPosition, screen->GetCurItem() );
        else
            OnHotKey( aDC, hotkey, NULL );
            OnHotKey( aDC, hotkey, aPosition, NULL );
    }

    UpdateStatusBar();    /* Display cursor coordinates info */
@@ -318,7 +307,7 @@ void SCH_EDIT_FRAME::GeneralControle( wxDC* aDC, wxPoint aPosition )
}


void LIB_EDIT_FRAME::GeneralControle( wxDC* aDC, wxPoint aPosition )
void LIB_EDIT_FRAME::GeneralControle( wxDC* aDC, const wxPoint& aPosition )
{
    wxRealPoint gridSize;
    SCH_SCREEN* screen = GetScreen();
@@ -390,16 +379,16 @@ void LIB_EDIT_FRAME::GeneralControle( wxDC* aDC, wxPoint aPosition )
    if( hotkey )
    {
        if( screen->GetCurItem() && screen->GetCurItem()->m_Flags )
            OnHotKey( aDC, hotkey, screen->GetCurItem() );
            OnHotKey( aDC, hotkey, aPosition, screen->GetCurItem() );
        else
            OnHotKey( aDC, hotkey, NULL );
            OnHotKey( aDC, hotkey, aPosition, NULL );
    }

    UpdateStatusBar();
}


void LIB_VIEW_FRAME::GeneralControle( wxDC* aDC, wxPoint aPosition )
void LIB_VIEW_FRAME::GeneralControle( wxDC* aDC, const wxPoint& aPosition )
{
    wxRealPoint gridSize;
    SCH_SCREEN* screen = GetScreen();
@@ -471,9 +460,9 @@ void LIB_VIEW_FRAME::GeneralControle( wxDC* aDC, wxPoint aPosition )
    if( hotkey )
    {
        if( screen->GetCurItem() && screen->GetCurItem()->m_Flags )
            OnHotKey( aDC, hotkey, screen->GetCurItem() );
            OnHotKey( aDC, hotkey, aPosition, screen->GetCurItem() );
        else
            OnHotKey( aDC, hotkey, NULL );
            OnHotKey( aDC, hotkey, aPosition, NULL );
    }

    UpdateStatusBar();
Loading