← Back to team overview

kicad-developers team mailing list archive

Label dragging patch

 

Hi again,

I intend to use global labels to name power nets instead of power symbols,
and, thus, I made some changes to enable dragging of labels. Most of the
code should be pretty straightforward. The changes in dangling_ends.cpp make
dangling label detection work for all wire orientations and not just for
horizontal or vertical. One thing about the original code I didn't quite get
is why the setting of the SELECTED flags was handled the way it was handled.
That code required some changes to prevent the labels from being added twice
into pickedlist. Now everything in pickedlist is flagged as SELECTED.

Marco

=== modified file 'eeschema/block.cpp'
--- eeschema/block.cpp    2010-06-24 18:31:43 +0000
+++ eeschema/block.cpp    2010-07-15 22:30:07 +0000
@@ -605,23 +605,10 @@
     for( Struct = screen->EEDrawList; Struct != NULL; Struct =
Struct->Next() )
         Struct->m_Flags = 0;

-    // Sel .m_Flags to selected for a wire or bus in selected area if there
is
-    // only one item:
-    if( pickedlist->GetCount() == 1 )
-    {
-        Struct = (SCH_ITEM*) pickedlist->GetPickedItem( 0 );
-        if( Struct->Type() == DRAW_SEGMENT_STRUCT_TYPE )
-            Struct->m_Flags = SELECTED;
-    }
-    // Sel .m_Flags to selected for a wire or bus in selected area for a
list
-    // of items:
-    else
-    {
-        for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
-        {
-            Struct = (SCH_ITEM*) pickedlist->GetPickedItem( ii );
-            Struct->m_Flags = SELECTED;
-        }
+    for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
+    {
+        Struct = (SCH_ITEM*) pickedlist->GetPickedItem( ii );
+        Struct->m_Flags = SELECTED;
     }

     if( screen->m_BlockLocate.m_Command != BLOCK_DRAG )
@@ -653,6 +640,18 @@
     for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
     {
         Struct = (SCH_ITEM*) (SCH_ITEM*) pickedlist->GetPickedItem( ii );
+    if( ( Struct->Type() == TYPE_SCH_LABEL )
+        || ( Struct->Type() == TYPE_SCH_GLOBALLABEL )
+        || ( Struct->Type() == TYPE_SCH_HIERLABEL ) )
+    {
+            #undef STRUCT
+            #define STRUCT ( (SCH_TEXT*) Struct )
+        if( !screen->m_BlockLocate.Inside( STRUCT->m_Pos ) )
+        {
+            AddPickedItem( screen, STRUCT->m_Pos );
+        }
+    }
+
         if( Struct->Type() == TYPE_SCH_COMPONENT )
         {
             // Add all pins of the selected component to list

=== modified file 'eeschema/dangling_ends.cpp'
--- eeschema/dangling_ends.cpp    2010-06-24 18:31:43 +0000
+++ eeschema/dangling_ends.cpp    2010-07-15 19:36:53 +0000
@@ -54,42 +54,23 @@
 DanglingEndHandle* RebuildEndList( EDA_BaseStruct* DrawList );


-/* Returns TRUE if the point P is on the segment S.
- * The segment is assumed horizontal or vertical.
- */
+/* Returns TRUE if the point P is on the segment S. */
 bool SegmentIntersect( int Sx1, int Sy1, int Sx2, int Sy2,
                        int Px1, int Py1 )
 {
-    int Sxmin, Sxmax, Symin, Symax;
-
-    if( Sx1 == Sx2 )          /* Line S is vertical. */
-    {
-        Symin = MIN( Sy1, Sy2 );
-        Symax = MAX( Sy1, Sy2 );
-
-        if( Px1 != Sx1 )
-            return FALSE;
-
-        if( Py1 >= Symin  &&  Py1 <= Symax )
-            return TRUE;
-        else
-            return FALSE;
-    }
-    else if( Sy1 == Sy2 )    /* Line S is horizontal. */
-    {
-        Sxmin = MIN( Sx1, Sx2 );
-        Sxmax = MAX( Sx1, Sx2 );
-
-        if( Py1 != Sy1 )
-            return FALSE;
-
-        if( Px1 >= Sxmin && Px1 <= Sxmax )
-            return TRUE;
-        else
-            return FALSE;
-    }
-    else
-        return FALSE;
+    int Sx = Sx2 - Sx1;      /* Vector from S1 to S2 */
+    int Sy = Sy2 - Sy1;
+
+    int Vx = Px1 - Sx1;      /* Vector from S1 to P */
+    int Vy = Py1 - Sy1;
+
+    if (Sx*Vy - Sy*Vx)
+        return FALSE;        /* Cross product non-zero, vectors not
parallel */
+
+    if (Sx*Vx + Sy*Vy < Vx*Vx + Vy*Vy)
+        return FALSE;          /* Point not on segment */
+
+    return TRUE;
 }



=== modified file 'eeschema/hotkeys.cpp'
--- eeschema/hotkeys.cpp    2010-07-15 14:18:11 +0000
+++ eeschema/hotkeys.cpp    2010-07-15 22:48:40 +0000
@@ -578,10 +578,13 @@
                 wxPostEvent( this, eventMoveOrDragComponent );
                 break;

-            case TYPE_SCH_TEXT:
             case TYPE_SCH_LABEL:
             case TYPE_SCH_GLOBALLABEL:
             case TYPE_SCH_HIERLABEL:
+                wxPostEvent( this, eventMoveOrDragComponent );
+            break;
+
+            case TYPE_SCH_TEXT:
             case DRAW_PART_TEXT_STRUCT_TYPE:
             case DRAW_BUSENTRY_STRUCT_TYPE:
                 if( HK_Descr->m_Idcommand != HK_DRAG )

=== modified file 'eeschema/onrightclick.cpp'
--- eeschema/onrightclick.cpp    2010-06-24 18:31:43 +0000
+++ eeschema/onrightclick.cpp    2010-07-15 21:09:57 +0000
@@ -342,6 +342,9 @@
         msg = AddHotkeyName( _( "Move Global Label" ),
s_Schematic_Hokeys_Descr,
                              HK_MOVE_COMPONENT_OR_ITEM );
         ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, msg,
move_text_xpm );
+        msg = AddHotkeyName( _( "Drag Global Label" ),
s_Schematic_Hokeys_Descr,
+                             HK_DRAG );
+        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST, msg,
move_text_xpm );
         msg = AddHotkeyName( _( "Copy Global Label" ),
s_Schematic_Hokeys_Descr,
                              HK_COPY_COMPONENT_OR_LABEL );
         ADD_MENUITEM( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, copy_button );
@@ -376,6 +379,9 @@
         msg = AddHotkeyName( _( "Move Hierarchical Label" ),
s_Schematic_Hokeys_Descr,
                              HK_MOVE_COMPONENT_OR_ITEM );
         ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, msg,
move_text_xpm );
+        msg = AddHotkeyName( _( "Drag Hierarchical Label" ),
s_Schematic_Hokeys_Descr,
+                             HK_DRAG );
+        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST, msg,
move_text_xpm );
         msg = AddHotkeyName( _( "Copy Hierarchical Label" ),
s_Schematic_Hokeys_Descr,
                              HK_COPY_COMPONENT_OR_LABEL );
         ADD_MENUITEM( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, copy_button );
@@ -409,6 +415,9 @@
         msg = AddHotkeyName( _( "Move Label" ), s_Schematic_Hokeys_Descr,
                              HK_MOVE_COMPONENT_OR_ITEM );
         ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, msg,
move_text_xpm );
+        msg = AddHotkeyName( _( "Drag Label" ), s_Schematic_Hokeys_Descr,
+                             HK_DRAG );
+        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST, msg,
move_text_xpm );
         msg = AddHotkeyName( _( "Copy Label" ), s_Schematic_Hokeys_Descr,
                              HK_COPY_COMPONENT_OR_LABEL );
         ADD_MENUITEM( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, copy_button );

=== modified file 'eeschema/schedit.cpp'
--- eeschema/schedit.cpp    2010-06-24 18:31:43 +0000
+++ eeschema/schedit.cpp    2010-07-15 22:35:16 +0000
@@ -414,7 +414,11 @@
     case ID_POPUP_SCH_MOVE_CMP_REQUEST:
         // Ensure the struct is a component (could be a struct of a
         // component, like Field, text..) or a hierachical sheet
+        // or a label
         if( (screen->GetCurItem()->Type() != TYPE_SCH_COMPONENT)
+        && (screen->GetCurItem()->Type() != TYPE_SCH_LABEL)
+        && (screen->GetCurItem()->Type() != TYPE_SCH_GLOBALLABEL)
+        && (screen->GetCurItem()->Type() != TYPE_SCH_HIERLABEL)
             && (screen->GetCurItem()->Type() != DRAW_SHEET_STRUCT_TYPE) )
             screen->SetCurItem( LocateSmallestComponent( screen ) );
         if( screen->GetCurItem() == NULL )

Follow ups