← Back to team overview

kicad-developers team mailing list archive

Re: Alt+Mousewheel to change working copper layer

 

Here is a patch that could be applied, then, to get this feature.

It is cleaner than the one I sent last time, and it refreshes the
track so the user sees the change of layer without having to move the
mouse.

It does NOT use hotkeys, I don't think it's necessary right now (as
alt+mousewheel wasn't available anyway), but it could be a nice
addition in the future.

Guillaume

On Fri, Dec 16, 2011 at 4:22 PM, Wayne Stambaugh <stambaughw@xxxxxxxxxxx> wrote:
> On 12/15/2011 11:42 AM, Guillaume Simard wrote:
>> Hello,
>>
>> I have created a nifty little patch to be able to change the working
>> copper layout while routing, *without* creating a via at the same
>> time. From what I see, there exists commands that can be bound to
>> hotkeys to switch layers, but these commands will create a via under
>> the mouse cursor as you change layers, and they will not work if you
>> use them over an already placed via (ie.: you didn't select the right
>> layer on the first try). The result of this is that you have to press
>> backspace if you didn't select the right layer right away (to delete
>> the via). This might not sound like a big deal and is just personal
>> taste, but perhaps adding an alternative that doesn't get it the way
>> could be possible.
>>
>> Basically, the workflow could be as follows:
>>
>> - you start routing (X)
>> - give a few clicks
>> - place a via (V)
>> - you switch layers AFTER the via is placed, using ALT+Mousewheel.
>> - place a via (V)
>> - you switch layers AFTER the via is placed, using ALT+Mousewheel.
>> - terminate the trace on a pad or otherwise
>>
>> I stress that this workflow is parallel to the already existing one
>> and does not try to replace/remove it, it simply would be an
>> alternative (as Alt suggests).
>>
>> I'm attaching the (nifty) patch to this email, just as a proof of
>> concept. Beware that if you apply it for testing *it will force
>> recompilation of every file* that uses id.h, which is mostly every
>> file out there.
>>
>> A better way of implementing this feature would be to make
>> ALT+Mousewheel Up/Down available as a hotkey instead (any problem with
>> that ?), and defining functions NextCopperNoVia and
>> PreviousCopperNoVia, or something like that, so that the user has the
>> freedom required to bind or not this behaviour to the mousewheel or
>> elsewhere.
>>
>> What do you think ?
>
> Guillaume,
>
> It's a clever solution that can save a few keystrokes here and there.  If no
> one objects, I'm willing to commit it.
>
> Wayne
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp



-- 
Guillaume Simard, B.Ing., M.Sc.A.
e.   gsimard@xxxxxxxxx
t.    514-501-5707
=== modified file 'common/drawpanel.cpp'
--- common/drawpanel.cpp	2011-12-14 20:03:15 +0000
+++ common/drawpanel.cpp	2011-12-16 21:45:21 +0000
@@ -811,6 +811,8 @@
             cmd.SetId( ID_PAN_UP );
         else if( event.ControlDown() && !event.ShiftDown() )
             cmd.SetId( ID_PAN_LEFT );
+        else if( event.AltDown() )
+            cmd.SetId( ID_MOUSEWHEEL_ALT_UP );
         else
             cmd.SetId( ID_POPUP_ZOOM_IN );
     }
@@ -820,6 +822,8 @@
             cmd.SetId( ID_PAN_DOWN );
         else if( event.ControlDown() && !event.ShiftDown() )
             cmd.SetId( ID_PAN_RIGHT );
+        else if( event.AltDown() )
+            cmd.SetId( ID_MOUSEWHEEL_ALT_DOWN );
         else
             cmd.SetId( ID_POPUP_ZOOM_OUT );
     }

=== modified file 'include/id.h'
--- include/id.h	2011-11-30 11:45:49 +0000
+++ include/id.h	2011-12-16 21:45:21 +0000
@@ -214,6 +214,9 @@
     ID_ZOOM_PAGE,
     ID_ZOOM_REDRAW,
 
+    ID_MOUSEWHEEL_ALT_UP,
+    ID_MOUSEWHEEL_ALT_DOWN,
+
     /* Panning command event IDs. */
     ID_PAN_UP,
     ID_PAN_DOWN,

=== modified file 'include/wxPcbStruct.h'
--- include/wxPcbStruct.h	2011-12-16 13:32:23 +0000
+++ include/wxPcbStruct.h	2011-12-16 21:55:08 +0000
@@ -545,6 +545,8 @@
     void OnLeftClick( wxDC* DC, const wxPoint& MousePos );
     void OnLeftDClick( wxDC* DC, const wxPoint& MousePos );
 
+    void OnMouseWheelAlt( wxCommandEvent& event );
+
     /**
      * Function OnRightClick
      * populates a popup menu with the choices appropriate for the current context.

=== modified file 'pcbnew/pcbframe.cpp'
--- pcbnew/pcbframe.cpp	2011-12-16 13:32:23 +0000
+++ pcbnew/pcbframe.cpp	2011-12-16 21:53:03 +0000
@@ -33,6 +33,7 @@
 #include "appl_wxstruct.h"
 #include "class_drawpanel.h"
 #include "confirm.h"
+#include "kicad_device_context.h"
 #include "wxPcbStruct.h"
 #include "pcbcommon.h"      // enum PCB_VISIBLE
 #include "collectors.h"
@@ -220,6 +221,10 @@
                     ID_POPUP_PCB_SELECT_WIDTH_END_RANGE,
                     PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event )
 
+    // Mousewheel + Alt event
+    EVT_MENU_RANGE( ID_MOUSEWHEEL_ALT_UP, ID_MOUSEWHEEL_ALT_DOWN,
+                    PCB_EDIT_FRAME::OnMouseWheelAlt )
+
     // popup menus
     EVT_MENU( ID_POPUP_PCB_DELETE_TRACKSEG, PCB_EDIT_FRAME::Process_Special_Functions )
     EVT_MENU_RANGE( ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE,
@@ -768,3 +773,43 @@
     }
 }
 
+
+void PCB_EDIT_FRAME::OnMouseWheelAlt( wxCommandEvent& event )
+{
+    INSTALL_UNBUFFERED_DC( dc, DrawPanel );
+    int curLayer = getActiveLayer();
+    int newLayer;
+
+    if( DrawPanel->m_mouseCaptureCallback == ShowNewTrackWhenMovingCursor )
+        ShowNewTrackWhenMovingCursor( DrawPanel, &dc, wxDefaultPosition, false );
+
+    switch( event.GetId() )
+    {
+    case ID_MOUSEWHEEL_ALT_UP:
+        if( curLayer < GetBoard()->GetCopperLayerCount() - 2 )
+            newLayer = curLayer + 1;
+        else
+            newLayer = LAYER_N_FRONT;
+
+        break;
+
+    case ID_MOUSEWHEEL_ALT_DOWN:
+        if( curLayer == LAYER_N_FRONT )
+            newLayer = GetBoard()->GetCopperLayerCount() - 2;
+        else if( curLayer > 0 )
+            newLayer = curLayer - 1;
+
+        break;
+
+    default:
+        wxLogDebug( wxT( "Unknown ID %d in PCB_EDIT_FRAME::OnAltWheel()." ), event.GetId() );
+    }
+
+    if( ( newLayer == LAYER_N_BACK ) || ( newLayer == LAYER_N_FRONT )
+        || ( newLayer < GetBoard()->GetCopperLayerCount() - 1
+             && newLayer >= 1 ) )
+        setActiveLayer( newLayer );
+
+    if( DrawPanel->m_mouseCaptureCallback == ShowNewTrackWhenMovingCursor )
+        ShowNewTrackWhenMovingCursor( DrawPanel, &dc, wxDefaultPosition, false );
+}


References