kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #05500
[PATCH] Object selection into EESchema
Dear developers,
as I wrote in my last e-mail, with this message I want to send you a patch
that should allow object selection in EEschema with just the mouse click.
This is my first attempt to be helpful in one open source project (sorry for
related troubles...).
The patch should leave the program fully functional, but with some
workarounds, as described in the attached document. The next step will be
the complete modification of the way a block command is issued and handled.
I send you this patch before going on (and working on something not useful
or not well coded), with drag and drop functionality.
Attached to this message you will find
1) the bazaar patch
2) the eeselect.cpp file, that is not automatically added to the patch with
the diff command
3) A descriptive document
Waiting for your comments,
Best regards.
Lorenzo Farina
=== modified file 'common/block_commande.cpp'
--- common/block_commande.cpp 2010-02-08 18:15:42 +0000
+++ common/block_commande.cpp 2010-09-25 16:33:08 +0000
@@ -44,6 +44,7 @@
case BLOCK_MOVE: /* Move */
case BLOCK_PRESELECT_MOVE: /* Move with preselection list*/
+ case BLOCK_MOVE_SELECTED:
msg = _( "Block Move" );
break;
@@ -181,6 +182,7 @@
case BLOCK_IDLE:
break;
+ case BLOCK_SELECT_ITEMS_ONLY: /* Select items */
case BLOCK_MOVE: /* Move */
case BLOCK_DRAG: /* Drag */
case BLOCK_COPY: /* Copy */
=== modified file 'common/gr_basic.cpp'
--- common/gr_basic.cpp 2010-09-11 16:33:43 +0000
+++ common/gr_basic.cpp 2010-09-19 17:47:32 +0000
@@ -79,7 +79,8 @@
static void GRSRect( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1,
int x2, int y2, int Color );
static void GRSRect( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1,
- int x2, int y2, int width, int Color );
+ int x2, int y2, int width, int Color,
+ wxPenStyle Style = wxPENSTYLE_SOLID );
/*
* Macro clipping the trace of a line:
@@ -624,6 +625,12 @@
#else
DC->SetLogicalFunction( wxEQUIV );
#endif
+ else if( draw_mode & GR_INVERT )
+#if defined( USE_WX_GRAPHICS_CONTEXT )
+ DC->SetLogicalFunction( wxCOPY );
+#else
+ DC->SetLogicalFunction( wxINVERT );
+#endif
else
DC->SetLogicalFunction( wxCOPY );
}
@@ -1694,8 +1701,8 @@
}
void GRRect( EDA_Rect* aClipBox, wxDC* aDC,
- const EDA_Rect& aRect,
- int aWidth, int aColor )
+ const EDA_Rect& aRect, int aWidth,
+ int aColor, wxPenStyle aStyle )
{
int x1 = GRMapX( aRect.GetX() );
int y1 = GRMapY( aRect.GetY() );
@@ -1704,7 +1711,7 @@
int width = ZoomValue( aWidth );
- GRSRect( aClipBox, aDC, x1, y1, x2, y2, width, aColor );
+ GRSRect( aClipBox, aDC, x1, y1, x2, y2, width, aColor, aStyle );
}
@@ -1755,7 +1762,7 @@
void GRSRect( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
- int width, int Color )
+ int width, int Color, wxPenStyle Style )
{
if( x1 > x2 )
EXCHG( x1, x2 );
@@ -1779,7 +1786,7 @@
return;
}
- GRSetColorPen( DC, Color, width );
+ GRSetColorPen( DC, Color, width, Style );
if( ( x1 == x2 ) || ( y1 == y2 ) )
DC->DrawLine( x1, y1, x2, y2 );
else
=== modified file 'common/sch_item_struct.cpp'
--- common/sch_item_struct.cpp 2010-03-16 18:22:59 +0000
+++ common/sch_item_struct.cpp 2010-09-17 21:54:13 +0000
@@ -27,6 +27,9 @@
EDA_BaseStruct( aParent, aType )
{
m_Layer = 0;
+ //The item is unselected when created
+ selection_status.logically_selected = false;
+ selection_status.drawn_selected = false;
}
SCH_ITEM::~SCH_ITEM()
=== modified file 'eeschema/CMakeLists.txt'
--- eeschema/CMakeLists.txt 2010-08-09 16:56:00 +0000
+++ eeschema/CMakeLists.txt 2010-09-19 11:19:08 +0000
@@ -83,6 +83,7 @@
eeredraw.cpp
eeschema.cpp
eeschema_config.cpp
+ eeselect.cpp
erc.cpp
events_called_functions_for_edit.cpp
files-io.cpp
=== modified file 'eeschema/block.cpp'
--- eeschema/block.cpp 2010-09-06 09:10:12 +0000
+++ eeschema/block.cpp 2010-09-25 17:11:26 +0000
@@ -58,12 +58,8 @@
break;
case 0:
- cmd = BLOCK_MOVE;
- break;
-
- case GR_KB_ALT:
case GR_KB_SHIFT:
- cmd = BLOCK_COPY;
+ cmd = BLOCK_SELECT_ITEMS_ONLY;
break;
case GR_KB_CTRL:
@@ -71,9 +67,13 @@
break;
case GR_KB_SHIFTCTRL:
- cmd = BLOCK_DELETE;
+ cmd = BLOCK_COPY;
break;
+ //case GR_KB_SHIFTCTRL:
+ // cmd = BLOCK_DELETE;
+ // break;
+
case MOUSE_MIDDLE:
cmd = BLOCK_ZOOM;
break;
@@ -128,6 +128,8 @@
err = TRUE;
break;
+ case BLOCK_MOVE_SELECTED:
+ UnselectAll( DC );
case BLOCK_ROTATE:
case BLOCK_MIRROR_X:
case BLOCK_MIRROR_Y:
@@ -269,6 +271,24 @@
}
break;
+ case BLOCK_MOVE_SELECTED:
+ PickSelectedItems( GetScreen()->m_BlockLocate, GetScreen() );
+ if( block->GetCount() )
+ {
+ ii = 1;
+ DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
+ DrawPanel->ManageCurseur = DrawMovingBlockOutlines;
+ DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
+ block->m_State = STATE_BLOCK_MOVE;
+ }
+ else
+ {
+ DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
+ DrawPanel->ManageCurseur = NULL;
+ DrawPanel->ForceCloseManageCurseur = NULL;
+ }
+ break;
+
case BLOCK_DELETE: /* Delete */
PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() );
DrawAndSizingBlockOutlines( DrawPanel, DC, FALSE );
@@ -310,7 +330,14 @@
zoom_command = TRUE;
break;
- case BLOCK_SELECT_ITEMS_ONLY: /* Not used */
+ case BLOCK_SELECT_ITEMS_ONLY:
+ PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() );
+ //Remove the selection block drawn on the DC
+ DrawAndSizingBlockOutlines( DrawPanel, DC, FALSE );
+ //Perform selection
+ SelectItemsList( DC, &GetScreen()->m_BlockLocate.m_ItemsSelection );
+ block->ClearItemsList();
+ break;
case BLOCK_ABORT: /* not executed here */
break;
}
@@ -351,7 +378,7 @@
* and if the current command is block move.
* Execute a command other than block move from the current block move selected items list.
* Due to (minor) problems in undo/redo or/and display block,
- * a mirror/rotate command is immediatly executed and multible block commands
+ * a mirror/rotate command is immediatly executed and multiple block commands
* are not allowed (multiple commands are tricky to undo/redo in one time)
*/
void WinEDA_SchematicFrame::HandleBlockEndByPopUp( int Command, wxDC* DC )
@@ -363,7 +390,7 @@
BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;
// can convert only a block move command to an other command
- if( block->m_Command != BLOCK_MOVE )
+ if( block->m_Command != BLOCK_MOVE && block->m_Command != BLOCK_MOVE_SELECTED )
return;
// Useless if the new command is block move because we are already in block move.
if( Command == BLOCK_MOVE )
@@ -631,7 +658,6 @@
return;
}
-
/* creates the list of items found when a drag block is initiated.
* items are those selected in window block an some items outside this area but
* connected to a selected item (connected wires to a component or an entry )
=== modified file 'eeschema/class_drawsheet.cpp'
--- eeschema/class_drawsheet.cpp 2010-09-09 17:37:25 +0000
+++ eeschema/class_drawsheet.cpp 2010-09-19 19:51:26 +0000
@@ -413,6 +413,27 @@
if( !( sheetPin.m_Flags & IS_MOVED ) )
sheetPin.Draw( aPanel, aDC, aOffset, aDrawMode, aColor );
}
+ selection_status.drawn_selected = false;
+}
+
+void SCH_SHEET::DrawSelected( WinEDA_DrawPanel* aPanel, wxDC* aDC,
+ const wxPoint& aOffset, bool aSelected, int aColor)
+{
+ selection_status.logically_selected = aSelected;
+ if( IsLogicallySelected() && IsDrawnSelected() ) return;
+ if( !IsLogicallySelected() && !IsDrawnSelected() ) return;
+ //Invert the color of the object
+ Draw( aPanel, aDC, aOffset, GR_INVERT, aColor );
+ //Draw a selection box around in inverted mode
+ GRSetDrawMode( aDC, GR_INVERT );
+ EDA_Rect bounding_box = GetBoundingBox();
+ bounding_box.SetHeight( bounding_box.GetHeight() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetWidth( bounding_box.GetWidth() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetX( bounding_box.GetX() - SELECTION_BORDER_CLEARANCE / 2 );
+ bounding_box.SetY( bounding_box.GetY() - SELECTION_BORDER_CLEARANCE / 2 );
+ GRRect( &aPanel->m_ClipBox, aDC, bounding_box, 0, 5, wxPENSTYLE_LONG_DASH );
+ //Flag
+ selection_status.drawn_selected = aSelected;
}
=== modified file 'eeschema/class_drawsheet.h'
--- eeschema/class_drawsheet.h 2010-09-11 16:33:43 +0000
+++ eeschema/class_drawsheet.h 2010-09-17 21:29:21 +0000
@@ -308,6 +308,15 @@
int aDrawMode,
int aColor = -1 );
+ /**
+ @see SCH_ITEM::DrawSelected
+ **/
+ virtual void DrawSelected( WinEDA_DrawPanel* aPanel,
+ wxDC* aDC,
+ const wxPoint& aOffset,
+ bool aSelected,
+ int aColor = -1 );
+
/** Function HitTest
* @return true if the point aPosRef is within item area
* @param aPosRef = a wxPoint to test
=== modified file 'eeschema/class_marker_sch.cpp'
--- eeschema/class_marker_sch.cpp 2010-09-05 17:01:48 +0000
+++ eeschema/class_marker_sch.cpp 2010-09-19 20:40:04 +0000
@@ -4,6 +4,7 @@
#include "fctsys.h"
#include "class_drawpanel.h"
+#include "gr_basic.h"
#include "common.h"
#include "program.h"
@@ -112,6 +113,27 @@
DrawMarker( aPanel, aDC, aDrawMode, aOffset );
m_Color = tmp;
+ selection_status.drawn_selected = false;
+}
+
+void SCH_MARKER::DrawSelected( WinEDA_DrawPanel* aPanel, wxDC* aDC,
+ const wxPoint& aOffset, bool aSelected, int aColor)
+{
+ selection_status.logically_selected = aSelected;
+ if( IsLogicallySelected() && IsDrawnSelected() ) return;
+ if( !IsLogicallySelected() && !IsDrawnSelected() ) return;
+ //Invert the color of the object
+ Draw( aPanel, aDC, aOffset, GR_INVERT, aColor );
+ //Draw a selection box around in inverted mode
+ GRSetDrawMode( aDC, GR_INVERT );
+ EDA_Rect bounding_box = GetBoundingBox();
+ bounding_box.SetHeight( bounding_box.GetHeight() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetWidth( bounding_box.GetWidth() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetX( bounding_box.GetX() - SELECTION_BORDER_CLEARANCE / 2 );
+ bounding_box.SetY( bounding_box.GetY() - SELECTION_BORDER_CLEARANCE / 2 );
+ GRRect( &aPanel->m_ClipBox, aDC, bounding_box, 0, 5, wxPENSTYLE_LONG_DASH );
+ //Flag
+ selection_status.drawn_selected = aSelected;
}
=== modified file 'eeschema/class_marker_sch.h'
--- eeschema/class_marker_sch.h 2010-09-05 17:01:48 +0000
+++ eeschema/class_marker_sch.h 2010-09-17 21:29:21 +0000
@@ -43,6 +43,14 @@
const wxPoint& aOffset, int aDraw_mode,
int aColor = -1 );
+ /**
+ @see SCH_ITEM::DrawSelected
+ **/
+ virtual void DrawSelected( WinEDA_DrawPanel* aPanel,
+ wxDC* aDC,
+ const wxPoint& aOffset,
+ bool aSelected,
+ int aColor = -1 );
/**
* Function Save
=== modified file 'eeschema/class_sch_cmp_field.cpp'
--- eeschema/class_sch_cmp_field.cpp 2010-09-05 17:01:48 +0000
+++ eeschema/class_sch_cmp_field.cpp 2010-09-19 19:51:27 +0000
@@ -149,6 +149,7 @@
LineWidth, m_Italic,
m_Bold, false );
}
+ selection_status.drawn_selected = false;
/* Enable this to draw the bounding box around the text field to validate
* the bounding box calculations.
@@ -177,6 +178,25 @@
#endif
}
+void SCH_FIELD::DrawSelected( WinEDA_DrawPanel* aPanel, wxDC* aDC,
+ const wxPoint& aOffset, bool aSelected, int aColor)
+{
+ selection_status.logically_selected = aSelected;
+ if( IsLogicallySelected() && IsDrawnSelected() ) return;
+ if( !IsLogicallySelected() && !IsDrawnSelected() ) return;
+ //Invert the color of the object
+ Draw( aPanel, aDC, aOffset, GR_INVERT, aColor );
+ //Draw a selection box around in inverted mode
+ GRSetDrawMode( aDC, GR_INVERT );
+ EDA_Rect bounding_box = GetBoundingBox();
+ bounding_box.SetHeight( bounding_box.GetHeight() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetWidth( bounding_box.GetWidth() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetX( bounding_box.GetX() - SELECTION_BORDER_CLEARANCE / 2 );
+ bounding_box.SetY( bounding_box.GetY() - SELECTION_BORDER_CLEARANCE / 2 );
+ GRRect( &aPanel->m_ClipBox, aDC, bounding_box, 0, 5, wxPENSTYLE_LONG_DASH );
+ //Flag
+ selection_status.drawn_selected = aSelected;
+}
/**
* Function ImportValues
=== modified file 'eeschema/class_sch_cmp_field.h'
--- eeschema/class_sch_cmp_field.h 2010-09-05 17:01:48 +0000
+++ eeschema/class_sch_cmp_field.h 2010-09-17 21:29:21 +0000
@@ -97,6 +97,15 @@
int Color = -1 );
/**
+ @see SCH_ITEM::DrawSelected
+ **/
+ virtual void DrawSelected( WinEDA_DrawPanel* aPanel,
+ wxDC* aDC,
+ const wxPoint& aOffset,
+ bool aSelected,
+ int aColor = -1 );
+
+ /**
* Function Save
* writes the data structures for this object out to a FILE in "*.sch"
* format.
=== modified file 'eeschema/class_sch_component.cpp'
--- eeschema/class_sch_component.cpp 2010-09-05 17:01:48 +0000
+++ eeschema/class_sch_component.cpp 2010-09-20 20:44:05 +0000
@@ -173,6 +173,14 @@
m_PrefixString = wxString( _( "U" ) );
}
+//Virtual Draw version
+void SCH_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
+ const wxPoint& offset, int draw_mode,
+ int Color )
+{
+ Draw( panel, DC, offset, draw_mode, Color, true );
+ selection_status.drawn_selected = false;
+}
/*****************************************************************************
* Routine to draw the given part at given position, transformed/mirror as *
@@ -251,6 +259,26 @@
#endif
}
+void SCH_COMPONENT::DrawSelected( WinEDA_DrawPanel* aPanel, wxDC* aDC,
+ const wxPoint& aOffset, bool aSelected, int aColor)
+{
+ selection_status.logically_selected = aSelected;
+ if( IsLogicallySelected() && IsDrawnSelected() ) return;
+ if( !IsLogicallySelected() && !IsDrawnSelected() ) return;
+ //Invert the color of the object
+ Draw( aPanel, aDC, aOffset, GR_INVERT, aColor );
+ //Draw a selection box around in inverted mode
+ GRSetDrawMode( aDC, GR_INVERT );
+ EDA_Rect bounding_box = GetBoundingBox();
+ bounding_box.SetHeight( bounding_box.GetHeight() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetWidth( bounding_box.GetWidth() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetX( bounding_box.GetX() - SELECTION_BORDER_CLEARANCE / 2 );
+ bounding_box.SetY( bounding_box.GetY() - SELECTION_BORDER_CLEARANCE / 2 );
+ GRRect( &aPanel->m_ClipBox, aDC, bounding_box, 0, 5, wxPENSTYLE_LONG_DASH );
+ //Flag
+ selection_status.drawn_selected = aSelected;
+}
+
/**
* Function AddHierarchicalReference
=== modified file 'eeschema/class_sch_component.h'
--- eeschema/class_sch_component.h 2010-09-05 17:01:48 +0000
+++ eeschema/class_sch_component.h 2010-09-20 20:41:55 +0000
@@ -265,10 +265,7 @@
wxDC* DC,
const wxPoint& offset,
int draw_mode,
- int Color = -1 )
- {
- Draw( panel, DC, offset, draw_mode, Color, true );
- }
+ int Color = -1 );
void Draw( WinEDA_DrawPanel* panel,
@@ -278,6 +275,15 @@
int Color,
bool DrawPinText );
+ /**
+ @see SCH_ITEM::DrawSelected
+ **/
+ virtual void DrawSelected( WinEDA_DrawPanel* aPanel,
+ wxDC* aDC,
+ const wxPoint& aOffset,
+ bool aSelected,
+ int aColor = -1 );
+
void SwapData( SCH_COMPONENT* copyitem );
void Place( WinEDA_SchematicFrame* frame, wxDC* DC );
=== modified file 'eeschema/class_schematic_items.cpp'
--- eeschema/class_schematic_items.cpp 2010-09-05 17:01:48 +0000
+++ eeschema/class_schematic_items.cpp 2010-09-19 19:51:27 +0000
@@ -139,6 +139,28 @@
GRLine( &panel->m_ClipBox, DC, m_Pos.x + offset.x, m_Pos.y + offset.y,
m_End().x + offset.x, m_End().y + offset.y, GetPenSize(), color );
+ //Flags
+ selection_status.drawn_selected = false;
+}
+
+void SCH_BUS_ENTRY::DrawSelected( WinEDA_DrawPanel* aPanel, wxDC* aDC,
+ const wxPoint& aOffset, bool aSelected, int aColor)
+{
+ selection_status.logically_selected = aSelected;
+ if( IsLogicallySelected() && IsDrawnSelected() ) return;
+ if( !IsLogicallySelected() && !IsDrawnSelected() ) return;
+ //Invert the color of the object
+ Draw( aPanel, aDC, aOffset, GR_INVERT, aColor );
+ //Draw a selection box around in inverted mode
+ GRSetDrawMode( aDC, GR_INVERT );
+ EDA_Rect bounding_box = GetBoundingBox();
+ bounding_box.SetHeight( bounding_box.GetHeight() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetWidth( bounding_box.GetWidth() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetX( bounding_box.GetX() - SELECTION_BORDER_CLEARANCE / 2 );
+ bounding_box.SetY( bounding_box.GetY() - SELECTION_BORDER_CLEARANCE / 2 );
+ GRRect( &aPanel->m_ClipBox, aDC, bounding_box, 0, 5, wxPENSTYLE_LONG_DASH );
+ //Flag
+ selection_status.drawn_selected = aSelected;
}
@@ -264,8 +286,28 @@
GRFilledCircle( &panel->m_ClipBox, DC, m_Pos.x + offset.x,
m_Pos.y + offset.y, (m_Size.x / 2), 0, color,
color );
+ selection_status.drawn_selected = false;
}
+void SCH_JUNCTION::DrawSelected( WinEDA_DrawPanel* aPanel, wxDC* aDC,
+ const wxPoint& aOffset, bool aSelected, int aColor)
+{
+ selection_status.logically_selected = aSelected;
+ if( IsLogicallySelected() && IsDrawnSelected() ) return;
+ if( !IsLogicallySelected() && !IsDrawnSelected() ) return;
+ //Invert the color of the object
+ Draw( aPanel, aDC, aOffset, GR_INVERT, aColor );
+ //Draw a selection box around in inverted mode
+ GRSetDrawMode( aDC, GR_INVERT );
+ EDA_Rect bounding_box = GetBoundingBox();
+ bounding_box.SetHeight( bounding_box.GetHeight() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetWidth( bounding_box.GetWidth() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetX( bounding_box.GetX() - SELECTION_BORDER_CLEARANCE / 2 );
+ bounding_box.SetY( bounding_box.GetY() - SELECTION_BORDER_CLEARANCE / 2 );
+ GRRect( &aPanel->m_ClipBox, aDC, bounding_box, 0, 5, wxPENSTYLE_LONG_DASH );
+ //Flag
+ selection_status.drawn_selected = aSelected;
+}
void SCH_JUNCTION::Mirror_X( int aXaxis_position )
{
@@ -406,6 +448,27 @@
pY + delta, width, color );
GRLine( &panel->m_ClipBox, DC, pX + delta, pY - delta, pX - delta,
pY + delta, width, color );
+ selection_status.drawn_selected = false;
+}
+
+void SCH_NO_CONNECT::DrawSelected( WinEDA_DrawPanel* aPanel, wxDC* aDC,
+ const wxPoint& aOffset, bool aSelected, int aColor)
+{
+ selection_status.logically_selected = aSelected;
+ if( IsLogicallySelected() && IsDrawnSelected() ) return;
+ if( !IsLogicallySelected() && !IsDrawnSelected() ) return;
+ //Invert the color of the object
+ Draw( aPanel, aDC, aOffset, GR_INVERT, aColor );
+ //Draw a selection box around in inverted mode
+ GRSetDrawMode( aDC, GR_INVERT );
+ EDA_Rect bounding_box = GetBoundingBox();
+ bounding_box.SetHeight( bounding_box.GetHeight() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetWidth( bounding_box.GetWidth() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetX( bounding_box.GetX() - SELECTION_BORDER_CLEARANCE / 2 );
+ bounding_box.SetY( bounding_box.GetY() - SELECTION_BORDER_CLEARANCE / 2 );
+ GRRect( &aPanel->m_ClipBox, aDC, bounding_box, 0, 5, wxPENSTYLE_LONG_DASH );
+ //Flag
+ selection_status.drawn_selected = aSelected;
}
@@ -599,8 +662,37 @@
if( m_EndIsDangling )
DrawDanglingSymbol( panel, DC, m_End + offset, color );
+ //Selection flag
+ selection_status.drawn_selected = false;
}
+void SCH_LINE::DrawSelected( WinEDA_DrawPanel* aPanel, wxDC* aDC,
+ const wxPoint& aOffset, bool aSelected, int aColor)
+{
+ //Logical selection
+ selection_status.logically_selected = aSelected;
+ if( IsLogicallySelected() && IsDrawnSelected() ) return;
+ if( !IsLogicallySelected() && !IsDrawnSelected() ) return;
+ //The color
+ aColor = aColor>=0 ? aColor : ReturnLayerColor( m_Layer );
+ //Test if the ends are already selected
+ bool draw_start, draw_end;
+ lineSharesSelectedEnds( aPanel->GetScreen()->EEDrawList, draw_start, draw_end );
+ //If the ends are selected, we always want to remove caps first.
+ //This should be done even if the current line was selected (and has to be unselected...)
+ if( draw_start || IsDrawnSelected() )
+ drawEndCap( aPanel, aDC, GR_XOR, m_Start + aOffset, aColor );
+ if( draw_end || IsDrawnSelected() )
+ drawEndCap( aPanel, aDC, GR_XOR, m_End + aOffset, aColor );
+ //Now draw the current line
+ Draw( aPanel, aDC, aOffset, GR_INVERT, aColor);
+ if( draw_start || IsLogicallySelected() )
+ drawEndCap( aPanel, aDC, GR_XOR, m_Start + aOffset, aColor );
+ if( draw_end || IsLogicallySelected() )
+ drawEndCap( aPanel, aDC, GR_XOR, m_End + aOffset, aColor );
+ //Issue flag
+ selection_status.drawn_selected = aSelected;
+}
void SCH_LINE::Mirror_X( int aXaxis_position )
{
@@ -630,6 +722,41 @@
RotatePoint( &m_End, rotationPoint, 900 );
}
+void SCH_LINE::drawEndCap( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode,
+ const wxPoint& aPos, int aColor )
+{
+ BASE_SCREEN* screen = aPanel->GetScreen();
+ GRSetDrawMode( aDC, aDrawMode );
+ GRFilledRect( &aPanel->m_ClipBox, aDC,
+ aPos.x - LINE_SQUARE_CAP_DIMENSION, aPos.y - LINE_SQUARE_CAP_DIMENSION,
+ aPos.x + LINE_SQUARE_CAP_DIMENSION, aPos.y + LINE_SQUARE_CAP_DIMENSION,
+ aColor, aColor );
+}
+
+void SCH_LINE::lineSharesSelectedEnds(SCH_ITEM *aDrawList, bool &aDrawStart, bool &aDrawEnd)
+{
+ aDrawStart = aDrawEnd = false;
+ SCH_LINE *line;
+ for(SCH_ITEM* item = aDrawList; item; item = item->Next())
+ {
+ //Skip the current line
+ if(item == dynamic_cast<SCH_ITEM*>(this) ) continue;
+ if(item->Type() == DRAW_SEGMENT_STRUCT_TYPE)
+ {
+ line = dynamic_cast<SCH_LINE*>(item);
+ if(m_Layer == line->GetLayer())
+ if( line->IsDrawnSelected() )
+ {
+ if( m_Start == line->m_Start || m_Start == line->m_End)
+ aDrawStart = true;
+ if( m_End == line->m_End || m_End == line->m_Start)
+ aDrawEnd = true;
+ if( aDrawStart && aDrawEnd ) return;
+ }
+ }
+ }
+}
+
/***********************/
/* Class SCH_POLYLINE */
@@ -748,6 +875,27 @@
GRLineTo( &panel->m_ClipBox, DC, m_PolyPoints[i].x + offset.x,
m_PolyPoints[i].y + offset.y, width, color );
}
+ selection_status.drawn_selected = false;
+}
+
+void SCH_POLYLINE::DrawSelected( WinEDA_DrawPanel* aPanel, wxDC* aDC,
+ const wxPoint& aOffset, bool aSelected, int aColor)
+{
+ selection_status.logically_selected = aSelected;
+ if( IsLogicallySelected() && IsDrawnSelected() ) return;
+ if( !IsLogicallySelected() && !IsDrawnSelected() ) return;
+ //Invert the color of the object
+ Draw( aPanel, aDC, aOffset, GR_INVERT, aColor );
+ //Draw a selection box around in inverted mode
+ GRSetDrawMode( aDC, GR_INVERT );
+ EDA_Rect bounding_box = GetBoundingBox();
+ bounding_box.SetHeight( bounding_box.GetHeight() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetWidth( bounding_box.GetWidth() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetX( bounding_box.GetX() - SELECTION_BORDER_CLEARANCE / 2 );
+ bounding_box.SetY( bounding_box.GetY() - SELECTION_BORDER_CLEARANCE / 2 );
+ GRRect( &aPanel->m_ClipBox, aDC, bounding_box, 0, 5, wxPENSTYLE_LONG_DASH );
+ //Flag
+ selection_status.drawn_selected = aSelected;
}
=== modified file 'eeschema/class_schematic_items.h'
--- eeschema/class_schematic_items.h 2010-09-05 17:01:48 +0000
+++ eeschema/class_schematic_items.h 2010-09-19 11:12:00 +0000
@@ -60,6 +60,22 @@
int draw_mode, int Color = -1 );
/**
+ @brief Draw on the schematic item to highlight selection.
+ The lines, when selected, are shown with caps on the ends. This is quite tricky when lines
+ that share ends are selected together: an iteration over the current draw list is done
+ for every selected line.
+ @see SCH_ITEM::DrawSelected
+ @todo The GR_INVERT draw mode should be considered when the resulting color
+ is the background color
+ **/
+ virtual void DrawSelected( WinEDA_DrawPanel* aPanel,
+ wxDC* aDC,
+ const wxPoint& aOffset,
+ bool aSelected,
+ int aColor = -1 );
+
+
+ /**
* Function Save
* writes the data structures for this object out to a FILE in "*.sch"
* format.
@@ -100,6 +116,22 @@
void Show( int nestLevel, std::ostream& os );
#endif
+
+private:
+ /**
+ @brief Draw the end cap of the selected line
+ Draw in XOR mode the end cap at the specified position
+ **/
+ void drawEndCap( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode,
+ const wxPoint& aPos, int aColor );
+ /**
+ @brief Test if the line shares starting and ending points with selected lines
+ The function checks if there are selected lines (already drawn) with the same layer
+ and m_Start/m_End points.
+ @param aDrawStart is true if the starting cap is already drawn
+ @param aDrawEnd is true if the ending cap is already drawn
+ **/
+ void lineSharesSelectedEnds(SCH_ITEM *aDrawList, bool &aDrawStart, bool &aDrawEnd);
};
@@ -130,6 +162,16 @@
int Color = -1 );
/**
+ @see SCH_ITEM::DrawSelected
+ **/
+ virtual void DrawSelected( WinEDA_DrawPanel* aPanel,
+ wxDC* aDC,
+ const wxPoint& aOffset,
+ bool aSelected,
+ int aColor = -1 );
+
+
+ /**
* Function Save
* writes the data structures for this object out to a FILE in "*.sch"
* format.
@@ -205,6 +247,15 @@
int Color = -1 );
/**
+ @see SCH_ITEM::DrawSelected
+ **/
+ virtual void DrawSelected( WinEDA_DrawPanel* aPanel,
+ wxDC* aDC,
+ const wxPoint& aOffset,
+ bool aSelected,
+ int aColor = -1 );
+
+ /**
* Function Save
* writes the data structures for this object out to a FILE in "*.sch"
* format.
@@ -266,11 +317,21 @@
SCH_POLYLINE* GenCopy();
+
virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC,
const wxPoint& offset, int draw_mode,
int Color = -1 );
/**
+ @see SCH_ITEM::DrawSelected
+ **/
+ virtual void DrawSelected( WinEDA_DrawPanel* aPanel,
+ wxDC* aDC,
+ const wxPoint& aOffset,
+ bool aSelected,
+ int aColor = -1 );
+
+ /**
* Function Save
* writes the data structures for this object out to a FILE in "*.sch"
* format.
@@ -365,6 +426,15 @@
const wxPoint& offset, int draw_mode, int Color = -1 );
/**
+ @see SCH_ITEM::DrawSelected
+ **/
+ virtual void DrawSelected( WinEDA_DrawPanel* aPanel,
+ wxDC* aDC,
+ const wxPoint& aOffset,
+ bool aSelected,
+ int aColor = -1 );
+
+ /**
* Function Save
* writes the data structures for this object out to a FILE in "*.sch"
* format.
=== modified file 'eeschema/class_text-label.cpp'
--- eeschema/class_text-label.cpp 2010-09-11 16:33:43 +0000
+++ eeschema/class_text-label.cpp 2010-09-20 20:27:06 +0000
@@ -772,6 +772,8 @@
if( m_IsDangling )
DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color );
+ selection_status.drawn_selected = false;
+
// Enable these line to draw the bounding box (debug tests purposes only)
#if 0
{
@@ -786,6 +788,25 @@
#endif
}
+void SCH_TEXT::DrawSelected( WinEDA_DrawPanel* aPanel, wxDC* aDC,
+ const wxPoint& aOffset, bool aSelected, int aColor)
+{
+ selection_status.logically_selected = aSelected;
+ if( IsLogicallySelected() && IsDrawnSelected() ) return;
+ if( !IsLogicallySelected() && !IsDrawnSelected() ) return;
+ //Invert the color of the object.
+ Draw( aPanel, aDC, aOffset, GR_INVERT, aColor );
+ //Draw a selection box around in inverted mode
+ GRSetDrawMode( aDC, GR_INVERT );
+ EDA_Rect bounding_box = GetBoundingBox();
+ bounding_box.SetHeight( bounding_box.GetHeight() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetWidth( bounding_box.GetWidth() + SELECTION_BORDER_CLEARANCE );
+ bounding_box.SetX( bounding_box.GetX() - SELECTION_BORDER_CLEARANCE / 2 );
+ bounding_box.SetY( bounding_box.GetY() - SELECTION_BORDER_CLEARANCE / 2 );
+ GRRect( &aPanel->m_ClipBox, aDC, bounding_box, 0, 5, wxPENSTYLE_LONG_DASH );
+ //Flag
+ selection_status.drawn_selected = aSelected;
+}
/**
* Function Save
=== modified file 'eeschema/class_text-label.h'
--- eeschema/class_text-label.h 2010-09-11 16:33:43 +0000
+++ eeschema/class_text-label.h 2010-09-17 21:29:21 +0000
@@ -93,6 +93,15 @@
int draw_mode,
int Color = -1 );
+ /**
+ @see SCH_ITEM::DrawSelected
+ **/
+ virtual void DrawSelected( WinEDA_DrawPanel* aPanel,
+ wxDC* aDC,
+ const wxPoint& aOffset,
+ bool aSelected,
+ int aColor = -1 );
+
/** function CreateGraphicShape
* Calculates the graphic shape (a polygon) associated to the text
* @param aCorner_list = a buffer to fill with polygon corners coordinates
=== modified file 'eeschema/dangling_ends.cpp'
--- eeschema/dangling_ends.cpp 2010-09-11 16:33:43 +0000
+++ eeschema/dangling_ends.cpp 2010-09-26 21:20:46 +0000
@@ -163,6 +163,8 @@
{
bool Sdangstate = true, Edangstate = true;
+ if( DC ) frame->UnselectAll( DC );
+
BOOST_FOREACH( DANGLING_END_ITEM terminal_item, aItemList )
{
if( terminal_item.m_Item == DrawRef )
=== modified file 'eeschema/eeredraw.cpp'
--- eeschema/eeredraw.cpp 2010-08-31 10:43:10 +0000
+++ eeschema/eeredraw.cpp 2010-09-19 12:08:57 +0000
@@ -134,19 +134,26 @@
void RedrawStructList( WinEDA_DrawPanel* panel, wxDC* DC,
SCH_ITEM* Structlist, int DrawMode, int Color )
{
- while( Structlist )
+ SCH_ITEM * struct_list_ptr = Structlist;
+ while( struct_list_ptr )
{
- if( !(Structlist->m_Flags & IS_MOVED) )
+ if( !(struct_list_ptr->m_Flags & IS_MOVED) )
{
// uncomment line below when there is a virtual
// EDA_BaseStruct::GetBoundingBox()
// if( panel->m_ClipBox.Intersects( Structs->GetBoundingBox()
// ) )
- RedrawOneStruct( panel, DC, Structlist, DrawMode, Color );
+ RedrawOneStruct( panel, DC, struct_list_ptr, DrawMode, Color );
}
- Structlist = Structlist->Next();
+ struct_list_ptr = struct_list_ptr->Next();
}
+ //Apply selection if we are not printing
+ if( !panel->GetScreen()->m_IsPrinting )
+ for( struct_list_ptr = Structlist; struct_list_ptr;
+ struct_list_ptr = struct_list_ptr->Next() )
+ if( struct_list_ptr->IsLogicallySelected() )
+ struct_list_ptr->DrawSelected( panel, DC, wxPoint(0,0), true );
}
=== modified file 'eeschema/eeschema_id.h'
--- eeschema/eeschema_id.h 2010-03-20 19:57:59 +0000
+++ eeschema/eeschema_id.h 2010-09-22 20:01:48 +0000
@@ -125,6 +125,9 @@
ID_POPUP_SCH_ADD_GLABEL,
ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
ID_POPUP_SCH_GETINFO_MARKER,
+ ID_POPUP_SCH_MOVE_SELECTED,
+ ID_POPUP_SCH_DELETE_SELECTED,
+ ID_POPUP_SCH_COPY_SELECTED,
ID_POPUP_END_RANGE,
/* Library editor main menubar IDs. */
=== modified file 'eeschema/general.h'
--- eeschema/general.h 2010-07-14 13:24:36 +0000
+++ eeschema/general.h 2010-09-19 12:54:40 +0000
@@ -31,6 +31,8 @@
#define GR_DEFAULT_DRAWMODE GR_COPY
#define DANGLING_SYMBOL_SIZE 12
+#define LINE_SQUARE_CAP_DIMENSION 40
+#define SELECTION_BORDER_CLEARANCE 10
extern wxString g_DefaultSchematicFileName;
=== modified file 'eeschema/hotkeys.cpp'
--- eeschema/hotkeys.cpp 2010-09-05 17:01:48 +0000
+++ eeschema/hotkeys.cpp 2010-09-19 12:42:04 +0000
@@ -147,6 +147,10 @@
static Ki_HotkeyInfo HkFindNextDrcMarker( wxT( "Find next DRC marker" ), HK_FIND_NEXT_DRC_MARKER,
WXK_F5 + GR_KB_SHIFT );
+// Selection
+static Ki_HotkeyInfo HkUnselectAll( wxT( "Unselect every item" ), HK_UNSELECT_ALL,
+ WXK_ESCAPE );
+
// Special keys for library editor:
static Ki_HotkeyInfo HkCreatePin( wxT( "Create Pin" ),
HK_LIBEDIT_CREATE_PIN, 'P' );
@@ -193,6 +197,7 @@
&HkBeginWire,
&HkAddLabel,
&HkAddNoConn,
+ &HkUnselectAll,
NULL
};
@@ -709,6 +714,10 @@
EditComponentFootprint( (SCH_COMPONENT*) DrawStruct, DC );
}
break;
+
+ case HK_UNSELECT_ALL:
+ UnselectAll( DC );
+ break;
}
if( RefreshToolBar )
=== modified file 'eeschema/hotkeys.h'
--- eeschema/hotkeys.h 2010-07-26 17:06:36 +0000
+++ eeschema/hotkeys.h 2010-09-19 12:42:04 +0000
@@ -32,7 +32,8 @@
HK_ADD_NEW_COMPONENT,
HK_BEGIN_WIRE,
HK_ADD_LABEL,
- HK_ADD_NOCONN_FLAG
+ HK_ADD_NOCONN_FLAG,
+ HK_UNSELECT_ALL
};
// List of hotkey descriptors for eeschema
=== modified file 'eeschema/locate.cpp'
--- eeschema/locate.cpp 2010-06-24 18:31:43 +0000
+++ eeschema/locate.cpp 2010-09-25 15:55:55 +0000
@@ -154,6 +154,29 @@
return itemcount;
}
+int PickSelectedItems( BLOCK_SELECTOR& aBlock, SCH_SCREEN* aScreen )
+{
+ int itemcount = 0;
+
+ if( aScreen == NULL )
+ return itemcount;
+
+ ITEM_PICKER picker;
+ SCH_ITEM* DrawStruct = aScreen->EEDrawList;
+ for( ; DrawStruct != NULL; DrawStruct = DrawStruct->Next() )
+ {
+ if( DrawStruct->IsLogicallySelected() )
+ {
+ /* Put this structure in the picked list: */
+ picker.m_PickedItem = DrawStruct;
+ picker.m_PickedItemType = DrawStruct->Type();
+ aBlock.PushItem( picker );
+ itemcount++;
+ }
+ }
+ return itemcount;
+}
+
/*****************************************************************************
* Routine to search all objects for the closest point to a given point, in *
=== modified file 'eeschema/onleftclick.cpp'
--- eeschema/onleftclick.cpp 2010-08-28 18:02:24 +0000
+++ eeschema/onleftclick.cpp 2010-09-20 20:36:53 +0000
@@ -79,6 +79,8 @@
switch( m_ID_current_state )
{
case 0:
+ DrawStruct = SchematicGeneralLocateAndDisplay( true );
+ SelectDrawStruct( DC, DrawStruct );
break;
case ID_NO_SELECT_BUTT:
@@ -318,6 +320,9 @@
void WinEDA_SchematicFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
{
+ //Unselect every item here
+ UnselectAll( DC );
+
EDA_BaseStruct* DrawStruct = GetScreen()->GetCurItem();
wxPoint pos = GetPosition();
=== modified file 'eeschema/onrightclick.cpp'
--- eeschema/onrightclick.cpp 2010-09-05 17:01:48 +0000
+++ eeschema/onrightclick.cpp 2010-09-25 17:56:01 +0000
@@ -34,6 +34,7 @@
WinEDA_SchematicFrame* frame );
static void AddMenusForMarkers( wxMenu* aPopMenu, SCH_MARKER* aMarker,
WinEDA_SchematicFrame* aFrame );
+static void addMenusForSelectedElements( wxMenu* aPopMenu, WinEDA_SchematicFrame* aFrame );
/* Prepare context menu when a click on the right mouse button occurs.
@@ -55,8 +56,34 @@
return true;
}
+ //Check the number of selected objects
+ int n_selected_objects = GetSelectedElementsCount();
+ //This will be useful when the behavoir of the selection is defined
+ /*
+ if( n_selected_objects == 1 )
+ {
+ //One element selected: set the DrawStruct to the selected item
+ SCH_ITEM *items_list = GetScreen()->EEDrawList;
+ while( ! items_list->IsLogicallySelected() ) items_list = items_list->Next();
+ DrawStruct = items_list;
+
+ if( DrawStruct && (DrawStruct->Type() == DRAW_SHEET_STRUCT_TYPE) )
+ {
+ SCH_SHEET_PIN* slabel;
+ slabel = LocateSheetLabel( (SCH_SHEET*) DrawStruct, GetScreen()->m_Curseur );
+ if( slabel )
+ DrawStruct = slabel;
+ }
+ }
+ else*/ if (n_selected_objects)
+ {
+ addMenusForSelectedElements( PopMenu, this );
+ PopMenu->AppendSeparator();
+ return true;
+ }
+
// Try to locate items at cursor position.
- if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
+ else if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
{
DrawStruct = SchematicGeneralLocateAndDisplay( false );
@@ -642,7 +669,8 @@
// After a block move (that is also a block selection) one can reselect
// a block function.
- if( frame->GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE )
+ if( frame->GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE
+ || frame->GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE_SELECTED )
{
ADD_MENUITEM( PopMenu, wxID_COPY, _( "Save Block" ), copy_button );
ADD_MENUITEM( PopMenu, ID_POPUP_COPY_BLOCK, _( "Copy Block" ), copyblock_xpm );
@@ -663,6 +691,18 @@
}
}
+void addMenusForSelectedElements( wxMenu* aPopMenu, WinEDA_SchematicFrame* aFrame )
+{
+ ///@todo THIS INFO SHOULD POP UP PROBABLY ONLY WHEN THE MOUSE IS OVER ONE SELECTED ITEM...
+ ///@todo copy to clipboard objects and other operations (block mirror...)
+ ///@todo add copy XPM
+ ADD_MENUITEM( aPopMenu, ID_POPUP_SCH_MOVE_SELECTED,
+ _( " Move selected block " ), move_xpm );
+ //ADD_MENUITEM( aPopMenu, ID_POPUP_SCH_DELETE_SELECTED,
+ // _( " Delete selected objects " ), delete_xpm );
+ //ADD_MENUITEM( aPopMenu, ID_POPUP_SCH_COPY_SELECTED,
+ // _( " Duplicate selected objects " ), copyblock_xpm );
+}
void AddMenusForMarkers( wxMenu* aPopMenu, SCH_MARKER* aMarker, WinEDA_SchematicFrame* aFrame )
{
=== modified file 'eeschema/protos.h'
--- eeschema/protos.h 2010-08-28 18:02:24 +0000
+++ eeschema/protos.h 2010-09-25 15:55:08 +0000
@@ -96,6 +96,16 @@
int PickItemsInBlock( BLOCK_SELECTOR& aBlock,
BASE_SCREEN* screen );
+/**
+@brief Fill the list of selected items for block commands
+Generate a list of selected object in the BLOCK_SELECTOR class.
+<br>
+The selected objects are logically selected by the mouse click.
+@return the number of selected items.
+@see PickItemsInBlock()
+**/
+int PickSelectedItems( BLOCK_SELECTOR& aBlock, SCH_SCREEN* aScreen );
+
/* function PickStruct:
* Search at location pos
*
=== modified file 'eeschema/schedit.cpp'
--- eeschema/schedit.cpp 2010-09-11 16:33:43 +0000
+++ eeschema/schedit.cpp 2010-09-25 16:15:19 +0000
@@ -740,6 +740,23 @@
( (SCH_MARKER*) screen->GetCurItem() )->DisplayMarkerInfo( this );
break;
+ case ID_POPUP_SCH_MOVE_SELECTED:
+ //Clear the actual block list
+ screen->m_BlockLocate.InitData( DrawPanel, screen->m_Curseur );
+ //Set the command
+ screen->m_BlockLocate.m_Command = BLOCK_MOVE_SELECTED;
+ HandleBlockEnd( &dc );
+ break;
+
+
+ case ID_POPUP_SCH_DELETE_SELECTED:
+ //Not implemented yet
+ break;
+
+ case ID_POPUP_SCH_COPY_SELECTED:
+ //Not implemented yet
+ break;
+
default: // Log error:
DisplayError( this,
wxT( "WinEDA_SchematicFrame::Process_Special_Functions error" ) );
=== modified file 'include/block_commande.h'
--- include/block_commande.h 2009-11-23 20:18:47 +0000
+++ include/block_commande.h 2010-09-25 15:26:21 +0000
@@ -42,6 +42,7 @@
BLOCK_DELETE,
BLOCK_PASTE,
BLOCK_DRAG,
+ BLOCK_MOVE_SELECTED,
BLOCK_ROTATE,
BLOCK_FLIP,
BLOCK_ZOOM,
=== modified file 'include/gr_basic.h'
--- include/gr_basic.h 2010-02-22 19:56:32 +0000
+++ include/gr_basic.h 2010-09-26 21:18:03 +0000
@@ -10,11 +10,12 @@
class EDA_Rect;
-#define GR_COPY 0
-#define GR_OR 0x01000000
-#define GR_XOR 0x02000000
-#define GR_AND 0x04000000
-#define GR_NXOR 0x08000000
+#define GR_COPY 0
+#define GR_OR 0x01000000
+#define GR_XOR 0x02000000
+#define GR_AND 0x04000000
+#define GR_NXOR 0x08000000
+#define GR_INVERT 0x10000000
#define GR_SURBRILL 0x80000000
@@ -23,6 +24,10 @@
#define GR_M_MIDDLE_DOWN 0x40000000
#define GR_M_DCLICK 0x80000000
+//wxW 2.8 compatibility
+//#define wxPENSTYLE_SOLID wxSOLID
+//typedef int wxPenStyle;
+
extern int g_XorMode;
extern int g_DrawBgColor;
@@ -223,7 +228,7 @@
void GRRect( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1,
int x2, int y2, int width, int Color );
void GRRect( EDA_Rect* aClipBox, wxDC* aDC,const EDA_Rect& aRect,
- int aWidth, int aColor );
+ int aWidth, int aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID );
#endif /* define GR_BASIC */
=== modified file 'include/sch_item_struct.h'
--- include/sch_item_struct.h 2010-09-05 17:01:48 +0000
+++ include/sch_item_struct.h 2010-09-17 21:53:17 +0000
@@ -22,6 +22,13 @@
protected:
int m_Layer;
+ //We store here selection stauts
+ struct
+ {
+ bool drawn_selected;
+ bool logically_selected;
+ } selection_status;
+
public:
SCH_ITEM( EDA_BaseStruct* aParent, KICAD_T aType );
@@ -63,6 +70,34 @@
int draw_mode,
int Color = -1 ) = 0;
+ /**
+ @brief Draw on the schematic item to highlight selection.
+ This function is implemented in every SCH_ITEM derived class and describes how
+ the item appears when selected. The function can also "toggle" the selection and remove it.
+ <br />
+ This method is ALWAYS applied on a drawn element (it generally makes use of color inversion).
+ <br />
+ @param aSelected the logical selection status. This status is saved on memory.
+ **/
+ virtual void DrawSelected( WinEDA_DrawPanel* aPanel,
+ wxDC* aDC,
+ const wxPoint& aOffset,
+ bool aSelected,
+ int aColor = -1 ) = 0;
+
+ /**
+ @brief Get the status of the logical selection
+ @return true if the element is logically selected.
+ **/
+ bool IsLogicallySelected()
+ { return selection_status.logically_selected; }
+
+ /**
+ @brief Get the status of the selection on the DC
+ @return true if the element is painted selected.
+ **/
+ bool IsDrawnSelected()
+ { return selection_status.drawn_selected; }
/* Place function */
virtual void Place( WinEDA_SchematicFrame* frame, wxDC* DC );
=== modified file 'include/wxEeschemaStruct.h'
--- include/wxEeschemaStruct.h 2010-07-14 13:24:36 +0000
+++ include/wxEeschemaStruct.h 2010-09-19 12:11:04 +0000
@@ -370,6 +370,38 @@
bool SaveEEFile( SCH_SCREEN* screen, int FileSave );
+ //Selection functions
+ /**
+ @brief Get the number of selected items.
+ @return the number of selected items in the SCH_ITEM* struct list.
+ **/
+ int GetSelectedElementsCount();
+
+ /**
+ @brief Unselect every SCH element.
+ Unselect elements from SCH_ITEM* list and set appearance accordingly.
+ **/
+ void UnselectAll( wxDC *aDC );
+
+ /**
+ @brief Update on passed DC every element that is logically selected but not drawn selected.
+ This function is used to update the DC after a repaint.
+ **/
+ void UpdatePaintSelections( wxDC *aDC );
+
+ /**
+ @brief Select the passed SCH_ITEM.
+ Logically select the passed item and draw it on the screen
+ **/
+ void SelectDrawStruct( wxDC *aDC, SCH_ITEM *aDrawStruct );
+
+ /**
+ @brief Select the passed PICKED_ITEMS_LIST
+ Logically select the passed item list and draw it on the screen
+ @param aSelectedItemsList the list of elements to be selected
+ **/
+ void SelectItemsList( wxDC *aDC, PICKED_ITEMS_LIST *aSelectedItemsList );
+
// General search:
private:
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 1992-2009 Jean-Pierre Charras, jean-pierre.charras@xxxxxxx
* Copyright (C) 1992-2009 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 "common.h"
#include "gr_basic.h"
#include "base_struct.h"
#include "sch_item_struct.h"
#include "class_sch_screen.h"
#include "class_drawpanel.h"
#include "wxEeschemaStruct.h"
#include "program.h"
#include "general.h"
#include "protos.h"
int WinEDA_SchematicFrame::GetSelectedElementsCount()
{
int counter = 0;
for( SCH_ITEM *list = GetScreen()->EEDrawList; list; list = list->Next() )
if( list->IsLogicallySelected() )
counter ++;
return counter;
}
void WinEDA_SchematicFrame::UnselectAll( wxDC *aDC )
{
for( SCH_ITEM *list = GetScreen()->EEDrawList; list; list = list->Next() )
if( list->IsLogicallySelected() )
list->DrawSelected( DrawPanel, aDC, wxPoint(0,0), false );
}
void WinEDA_SchematicFrame::UpdatePaintSelections( wxDC *aDC )
{
for( SCH_ITEM *list = GetScreen()->EEDrawList; list; list = list->Next() )
if( list->IsLogicallySelected() )
list->DrawSelected( DrawPanel, aDC, wxPoint(0,0), true );
}
void WinEDA_SchematicFrame::SelectDrawStruct( wxDC *aDC, SCH_ITEM *aDrawStruct )
{
//Multiple selection
if( wxGetKeyState( WXK_SHIFT ) )
{
if( !aDrawStruct )
return;
if( aDrawStruct->IsLogicallySelected() )
aDrawStruct->DrawSelected( DrawPanel, aDC, wxPoint(0, 0), false );
else
aDrawStruct->DrawSelected( DrawPanel, aDC, wxPoint(0,0), true );
}
else
{
if( !aDrawStruct )
{
UnselectAll( aDC );
return;
}
if( aDrawStruct->IsLogicallySelected() )
{
//Iterate within the list: if more than one structure is selected, this
//command will select only the clicked structure
int selected_elements_count = GetSelectedElementsCount();
if( selected_elements_count )
{
UnselectAll( aDC );
//Only one selected element was picked: we clicked on a selected element.
//This generally means we want to unselect it, so do nothing else than deselect.
if( selected_elements_count != 1 )
aDrawStruct->DrawSelected( DrawPanel, aDC, wxPoint(0,0), true );
}
else
UnselectAll( aDC );
}
else
{
UnselectAll( aDC );
aDrawStruct->DrawSelected( DrawPanel, aDC, wxPoint(0,0), true );
}
}
}
void WinEDA_SchematicFrame::SelectItemsList( wxDC *aDC,
PICKED_ITEMS_LIST *aSelectedItemsList )
{
//Check if user pressed CTRL key; if not unselect every element (new selection)
if( !wxGetKeyState( WXK_SHIFT ) ) UnselectAll( aDC );
SCH_ITEM *item_ptr;
for( unsigned int i = 0; i<aSelectedItemsList->GetCount(); i++ )
{
item_ptr = dynamic_cast<SCH_ITEM*>( aSelectedItemsList->GetPickedItem( i ) );
if( ! ( item_ptr->IsLogicallySelected() ) )
item_ptr->DrawSelected( DrawPanel, aDC, wxPoint(0,0), true );
}
}
Attachment:
[Patch] Mouse click selection - 2010-09-27.pdf
Description: Adobe PDF document
Follow ups