diff --git a/eeschema/block.cpp b/eeschema/block.cpp index cc0bcea493..b84de207d5 100644 --- a/eeschema/block.cpp +++ b/eeschema/block.cpp @@ -8,7 +8,6 @@ #include "common.h" #include "class_drawpanel.h" #include "confirm.h" -#include "block_commande.h" #include "wxEeschemaStruct.h" #include "class_sch_screen.h" @@ -29,22 +28,16 @@ // Imported functions: -void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector ); -void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& Center ); -void Mirror_X_ListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint ); -void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& Center ); -void DeleteItemsInList( WinEDA_DrawPanel* panel, PICKED_ITEMS_LIST& aItemsList ); -void DuplicateItemsInList( SCH_SCREEN* screen, - PICKED_ITEMS_LIST& aItemsList, - const wxPoint aMoveVector ); +void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector ); +void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& Center ); +void Mirror_X_ListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint ); +void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& Center ); +void DeleteItemsInList( WinEDA_DrawPanel* panel, PICKED_ITEMS_LIST& aItemsList ); +void DuplicateItemsInList( SCH_SCREEN* screen, + PICKED_ITEMS_LIST& aItemsList, + const wxPoint aMoveVector ); -static void CollectStructsToDrag( SCH_SCREEN* screen ); -static void AddPickedItem( SCH_SCREEN* screen, wxPoint aPosition ); -static LIB_PIN* GetNextPinPosition( SCH_COMPONENT* aComponent, - wxPoint& aPosition, - LIB_PIN* aPin ); -static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ); -static void SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList ); +static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ); /* Return the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to @@ -92,7 +85,7 @@ void SCH_EDIT_FRAME::InitBlockPasteInfos() { BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate; - block->m_ItemsSelection.CopyList( g_BlockSaveDataList.m_ItemsSelection ); + block->m_ItemsSelection.CopyList( m_blockItems.m_ItemsSelection ); DrawPanel->ManageCurseur = DrawMovingBlockOutlines; } @@ -217,13 +210,16 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) { BlockState state = block->m_State; CmdBlockType command = block->m_Command; + if( DrawPanel->ForceCloseManageCurseur ) DrawPanel->ForceCloseManageCurseur( DrawPanel, DC ); + block->m_State = state; block->m_Command = command; DrawPanel->ManageCurseur = DrawAndSizingBlockOutlines; DrawPanel->ForceCloseManageCurseur = AbortBlockCurrentCommand; GetScreen()->m_Curseur = block->GetEnd(); + if( block->m_Command != BLOCK_ABORT ) DrawPanel->MouseToCursorSchema(); } @@ -250,7 +246,7 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) if( block->GetCount() ) { nextcmd = true; - CollectStructsToDrag( GetScreen() ); + GetScreen()->SelectBlockItems(); DrawPanel->ManageCurseur( DrawPanel, DC, false ); DrawPanel->ManageCurseur = DrawMovingBlockOutlines; DrawPanel->ManageCurseur( DrawPanel, DC, false ); @@ -267,11 +263,13 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) case BLOCK_DELETE: /* Delete */ PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() ); DrawAndSizingBlockOutlines( DrawPanel, DC, false ); + if( block->GetCount() ) { DeleteItemsInList( DrawPanel, block->m_ItemsSelection ); OnModify(); } + block->ClearItemsList(); TestDanglingEnds( GetScreen()->GetDrawItems(), DC ); DrawPanel->Refresh(); @@ -280,12 +278,14 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) case BLOCK_SAVE: /* Save */ PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() ); DrawAndSizingBlockOutlines( DrawPanel, DC, false ); + if( block->GetCount() ) { wxPoint move_vector = -GetScreen()->m_BlockLocate.m_BlockLastCursorPosition; - SaveStructListForPaste( block->m_ItemsSelection ); - MoveItemsInList( g_BlockSaveDataList.m_ItemsSelection, move_vector ); + copyBlockItems( block->m_ItemsSelection ); + MoveItemsInList( m_blockItems.m_ItemsSelection, move_vector ); } + block->ClearItemsList(); break; @@ -336,7 +336,7 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) * 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 immediately executed and multiple block commands * are not allowed (multiple commands are tricky to undo/redo in one time) */ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC ) @@ -350,6 +350,7 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC ) // can convert only a block move command to an other command if( block->m_Command != BLOCK_MOVE ) return; + // Useless if the new command is block move because we are already in block move. if( Command == BLOCK_MOVE ) return; @@ -367,18 +368,22 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC ) case BLOCK_DRAG: /* move to Drag */ if( DrawPanel->ManageCurseur ) DrawPanel->ManageCurseur( DrawPanel, DC, false ); + // Clear list of items to move, and rebuild it with items to drag: block->ClearItemsList(); BreakSegmentOnJunction( GetScreen() ); PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() ); + if( block->GetCount() ) { blockCmdFinished = false; - CollectStructsToDrag( GetScreen() ); + GetScreen()->SelectBlockItems(); + if( DrawPanel->ManageCurseur ) DrawPanel->ManageCurseur( DrawPanel, DC, false ); + block->m_State = STATE_BLOCK_MOVE; } break; @@ -386,11 +391,13 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC ) case BLOCK_DELETE: /* move to Delete */ if( DrawPanel->ManageCurseur ) DrawPanel->ManageCurseur( DrawPanel, DC, false ); + if( block->GetCount() ) { DeleteItemsInList( DrawPanel, block->m_ItemsSelection ); OnModify(); } + TestDanglingEnds( GetScreen()->GetDrawItems(), DC ); DrawPanel->Refresh(); break; @@ -398,11 +405,12 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC ) case BLOCK_SAVE: /* Save list in paste buffer*/ if( DrawPanel->ManageCurseur ) DrawPanel->ManageCurseur( DrawPanel, DC, false ); + if( block->GetCount() ) { wxPoint move_vector = -GetScreen()->m_BlockLocate.m_BlockLastCursorPosition; - SaveStructListForPaste( block->m_ItemsSelection ); - MoveItemsInList( g_BlockSaveDataList.m_ItemsSelection, move_vector ); + copyBlockItems( block->m_ItemsSelection ); + MoveItemsInList( m_blockItems.m_ItemsSelection, move_vector ); } break; @@ -418,7 +426,6 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC ) DrawPanel->ManageCurseur( DrawPanel, DC, false ); if( block->GetCount() ) { -// blockCmdFinished = true; /* Compute the rotation center and put it on grid */ wxPoint rotationPoint = block->Centre(); PutOnGrid( &rotationPoint ); @@ -426,26 +433,23 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC ) RotateListOfItems( block->m_ItemsSelection, rotationPoint ); OnModify(); } + TestDanglingEnds( GetScreen()->GetDrawItems(), DC ); DrawPanel->Refresh(); -// block->m_State = STATE_BLOCK_MOVE; -// block->m_Command = BLOCK_MOVE; //allows multiple rotate break; case BLOCK_MIRROR_X: if( DrawPanel->ManageCurseur ) DrawPanel->ManageCurseur( DrawPanel, DC, false ); + if( block->GetCount() ) { -// blockCmdFinished = true; /* Compute the mirror center and put it on grid */ wxPoint mirrorPoint = block->Centre(); PutOnGrid( &mirrorPoint ); SaveCopyInUndoList( block->m_ItemsSelection, UR_MIRRORED_X, mirrorPoint ); Mirror_X_ListOfItems( block->m_ItemsSelection, mirrorPoint ); OnModify(); -// block->m_State = STATE_BLOCK_MOVE; -// block->m_Command = BLOCK_MOVE; //allows multiple mirrors } TestDanglingEnds( GetScreen()->GetDrawItems(), DC ); DrawPanel->Refresh(); @@ -454,17 +458,15 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC ) case BLOCK_MIRROR_Y: if( DrawPanel->ManageCurseur ) DrawPanel->ManageCurseur( DrawPanel, DC, false ); + if( block->GetCount() ) { -// blockCmdFinished = true; /* Compute the mirror center and put it on grid */ wxPoint mirrorPoint = block->Centre(); PutOnGrid( &mirrorPoint ); SaveCopyInUndoList( block->m_ItemsSelection, UR_MIRRORED_Y, mirrorPoint ); MirrorListOfItems( block->m_ItemsSelection, mirrorPoint ); OnModify(); -// block->m_State = STATE_BLOCK_MOVE; -// block->m_Command = BLOCK_MOVE; //allows multiple mirrors } TestDanglingEnds( GetScreen()->GetDrawItems(), DC ); @@ -506,7 +508,7 @@ static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool era for( unsigned ii = 0; ii < block->GetCount(); ii++ ) { schitem = (SCH_ITEM*) block->m_ItemsSelection.GetPickedItem( ii ); - DrawStructsInGhost( panel, DC, schitem, block->m_MoveVector ); + schitem->Draw( panel, DC, block->m_MoveVector, g_XorMode, g_GhostColor ); } } @@ -518,27 +520,23 @@ static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool era for( unsigned ii = 0; ii < block->GetCount(); ii++ ) { schitem = (SCH_ITEM*) block->m_ItemsSelection.GetPickedItem( ii ); - DrawStructsInGhost( panel, DC, schitem, block->m_MoveVector ); + schitem->Draw( panel, DC, block->m_MoveVector, g_XorMode, g_GhostColor ); } } -/* Routine to Save an object from global drawing object list. - * This routine is the same as delete but: - * - the original list is NOT removed. - * - List is saved in g_BlockSaveDataList - */ -void SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList ) +void SCH_EDIT_FRAME::copyBlockItems( PICKED_ITEMS_LIST& aItemsList ) { - g_BlockSaveDataList.ClearListAndDeleteItems(); // delete previous saved list, if exists + m_blockItems.ClearListAndDeleteItems(); // delete previous saved list, if exists /* save the new list: */ ITEM_PICKER item; - // In list the wrapper is owner of the shematic item, we can use the UR_DELETED + // In list the wrapper is owner of the schematic item, we can use the UR_DELETED // status for the picker because pickers with this status are owner of the picked item // (or TODO ?: create a new status like UR_DUPLICATE) item.m_UndoRedoStatus = UR_DELETED; + for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) { // Clear m_Flag member of selected items: @@ -547,20 +545,20 @@ void SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList ) SCH_ITEM* DrawStructCopy = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) ); DrawStructCopy->SetParent( NULL ); item.m_PickedItem = DrawStructCopy; - g_BlockSaveDataList.PushItem( item ); + m_blockItems.PushItem( item ); } } /***************************************************************************** -* Routine to paste a structure from the g_BlockSaveDataList stack. +* Routine to paste a structure from the m_blockItems stack. * This routine is the same as undelete but original list is NOT removed. *****************************************************************************/ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC ) { SCH_ITEM* Struct; - if( g_BlockSaveDataList.GetCount() == 0 ) + if( m_blockItems.GetCount() == 0 ) { DisplayError( this, wxT( "No struct to paste" ) ); return; @@ -570,10 +568,10 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC ) // Creates data, and push it as new data in undo item list buffer ITEM_PICKER picker( NULL, UR_NEW ); - for( unsigned ii = 0; ii < g_BlockSaveDataList.GetCount(); ii++ ) + + for( unsigned ii = 0; ii < m_blockItems.GetCount(); ii++ ) { - Struct = DuplicateStruct( - (SCH_ITEM*) g_BlockSaveDataList.m_ItemsSelection.GetPickedItem( ii ) ); + Struct = DuplicateStruct( (SCH_ITEM*) m_blockItems.m_ItemsSelection.GetPickedItem( ii ) ); picker.m_PickedItem = Struct; picklist.PushItem( picker ); @@ -584,7 +582,7 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC ) ( (SCH_COMPONENT*) Struct )->ClearAnnotation( NULL ); } SetaParent( Struct, GetScreen() ); - RedrawOneStruct( DrawPanel, DC, Struct, GR_DEFAULT_DRAWMODE ); + Struct->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); Struct->SetNext( GetScreen()->GetDrawItems() ); GetScreen()->SetDrawItems( Struct ); } @@ -600,308 +598,3 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC ) return; } - - -/* Set in m_BlockLocate.m_ItemsSelection items members .m_Flags to SELECTED - * 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 ) - */ -static void CollectStructsToDrag( SCH_SCREEN* screen ) -{ - SCH_ITEM* Struct; - SCH_LINE* SegmStruct; - - PICKED_ITEMS_LIST* pickedlist = &screen->m_BlockLocate.m_ItemsSelection; - - if( pickedlist->GetCount() == 0 ) - return; - - screen->ClearDrawingState(); - - 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 ) - return; - - - /* Remove the displacement of segment and undo the selection. */ - for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ ) - { - Struct = (SCH_ITEM*)pickedlist->GetPickedItem( ii ); - if( Struct->Type() == SCH_LINE_T ) - { - SegmStruct = (SCH_LINE*) Struct; - if( !screen->m_BlockLocate.Contains( SegmStruct->m_Start ) ) - SegmStruct->m_Flags |= STARTPOINT; - - if( !screen->m_BlockLocate.Contains( SegmStruct->m_End ) ) - SegmStruct->m_Flags |= ENDPOINT; - - // Save m_Flags for Undo/redo drag operations: - pickedlist->SetPickerFlags( SegmStruct->m_Flags, ii ); - } - } - - /* Search for other items to drag. They are end wires connected to selected - * items - */ - for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ ) - { - Struct = (SCH_ITEM*)pickedlist->GetPickedItem( ii ); - if( ( Struct->Type() == SCH_LABEL_T ) - || ( Struct->Type() == SCH_GLOBAL_LABEL_T ) - || ( Struct->Type() == SCH_HIERARCHICAL_LABEL_T ) ) - { - #undef STRUCT - #define STRUCT ( (SCH_TEXT*) Struct ) - if( !screen->m_BlockLocate.Contains( STRUCT->m_Pos ) ) - { - AddPickedItem( screen, STRUCT->m_Pos ); - } - } - - if( Struct->Type() == SCH_COMPONENT_T ) - { - // Add all pins of the selected component to list - wxPoint pos; - LIB_PIN* pin = GetNextPinPosition( (SCH_COMPONENT*) Struct, pos, NULL ); - while( pin ) - { - if( !screen->m_BlockLocate.Contains( pos ) ) - { - // This pin is outside area, - // but because it is a pin of a selected component - // we must also select connected items to this pin - // and mainly wires - AddPickedItem( screen, pos ); - } - - pin = GetNextPinPosition( (SCH_COMPONENT*) Struct, pos, pin ); - } - } - - if( Struct->Type() == SCH_SHEET_T ) - { - SCH_SHEET* sheet = (SCH_SHEET*) Struct; - - // Add all pins sheets of a selected hierarchical sheet to the list - BOOST_FOREACH( SCH_SHEET_PIN label, sheet->GetSheetPins() ) - { - AddPickedItem( screen, label.m_Pos ); - } - } - - if( Struct->Type() == SCH_BUS_ENTRY_T ) - { - SCH_BUS_ENTRY* item = (SCH_BUS_ENTRY*) Struct; - AddPickedItem( screen, item->m_Pos ); - AddPickedItem( screen, item->m_End() ); - } - } -} - - -/** AddPickedItem - * add to the picked list in screen->m_BlockLocate items found at location - * position - * @param screen = the screen to consider - * @param position = the wxPoint where items must be located to be select - */ -static void AddPickedItem( SCH_SCREEN* screen, wxPoint position ) -{ - SCH_ITEM* Struct; - - /* Review the list of already selected elements. */ - PICKED_ITEMS_LIST* pickedlist = &screen->m_BlockLocate.m_ItemsSelection; - - for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ ) - { - Struct = (SCH_ITEM*) pickedlist->GetPickedItem( ii ); - - switch( Struct->Type() ) - { - case SCH_LINE_T: - #undef STRUCT - #define STRUCT ( (SCH_LINE*) Struct ) - if( STRUCT->m_Start == position ) - STRUCT->m_Flags &= ~STARTPOINT; - - if( STRUCT->m_End == position ) - STRUCT->m_Flags &= ~ENDPOINT; - - // Save m_Flags for Undo/redo drag operations: - pickedlist->SetPickerFlags( STRUCT->m_Flags, ii ); - break; - - default: - break; - } - } - - /* Review the list of elements not selected. */ - - ITEM_PICKER picker; - Struct = (SCH_ITEM*) screen->GetDrawItems(); - - while( Struct ) - { - picker.m_PickedItem = Struct; - picker.m_PickedItemType = Struct->Type(); - switch( Struct->Type() ) - { - case TYPE_NOT_INIT: - break; - - case SCH_POLYLINE_T: - if( Struct->m_Flags & SELECTED ) - break; - break; - - case SCH_JUNCTION_T: - #undef STRUCT - #define STRUCT ( (SCH_JUNCTION*) Struct ) - if( Struct->m_Flags & SELECTED ) - break; - if( STRUCT->m_Pos != position ) - break; - pickedlist->PushItem( picker ); - break; - - case SCH_LINE_T: - #undef STRUCT - #define STRUCT ( (SCH_LINE*) Struct ) - if( Struct->m_Flags & SELECTED ) - break; - if( STRUCT->m_Start == position ) - { - Struct->m_Flags = SELECTED | ENDPOINT | STARTPOINT; - Struct->m_Flags &= ~STARTPOINT; - // Save m_Flags for Undo/redo drag operations: - picker.m_PickerFlags = Struct->m_Flags; - pickedlist->PushItem( picker ); - } - else if( STRUCT->m_End == position ) - { - Struct->m_Flags = SELECTED | ENDPOINT | STARTPOINT; - Struct->m_Flags &= ~ENDPOINT; - // Save m_Flags for Undo/redo drag operations: - picker.m_PickerFlags = Struct->m_Flags; - pickedlist->PushItem( picker ); - } - break; - - case SCH_BUS_ENTRY_T: - break; - - case SCH_TEXT_T: - break; - - case SCH_LABEL_T: - #undef STRUCT - #define STRUCT ( (SCH_LABEL*) Struct ) - if( Struct->m_Flags & SELECTED ) - break; /* Already in list */ - if( STRUCT->m_Pos != position ) - break; - Struct->m_Flags |= SELECTED; - pickedlist->PushItem( picker ); - break; - - case SCH_HIERARCHICAL_LABEL_T: - case SCH_GLOBAL_LABEL_T: - #undef STRUCT - #define STRUCT ( (SCH_LABEL*) Struct ) - if( Struct->m_Flags & SELECTED ) - break; /* Already in list */ - if( STRUCT->m_Pos != position ) - break; - Struct->m_Flags |= SELECTED; - pickedlist->PushItem( picker ); - break; - - case SCH_COMPONENT_T: - case SCH_SHEET_T: - case SCH_SHEET_LABEL_T: - break; - - case SCH_MARKER_T: - #undef STRUCT - #define STRUCT ( (SCH_MARKER*) Struct ) - if( Struct->m_Flags & SELECTED ) - break; /* Already in list */ - if( STRUCT->m_Pos != position ) - break; - Struct->m_Flags |= SELECTED; - pickedlist->PushItem( picker ); - break; - - case SCH_NO_CONNECT_T: - #undef STRUCT - #define STRUCT ( (SCH_NO_CONNECT*) Struct ) - if( Struct->m_Flags & SELECTED ) - break; /* Already in list */ - if( STRUCT->m_Pos != position ) - break; - Struct->m_Flags |= SELECTED; - pickedlist->PushItem( picker ); - break; - - default: - break; - } - Struct = Struct->Next(); - } -} - - -/** - * Function GetNextPinPosition() - * calculate position of the "next" pin of the aDrawLibItem component - * @param aComponent = component to test. - * @param aPosition = the actual next pin position in schematic, according to the component - * orientation and position - * @param aPin = search for the next pin after aPin. aPin = NULL to find the first pin in list - * @return a pointer to the next pin found or NULL - */ -static LIB_PIN* GetNextPinPosition( SCH_COMPONENT* aComponent, - wxPoint& aPosition, - LIB_PIN* aPin ) -{ - static LIB_COMPONENT* Entry; - - if( aPin == NULL ) - { - Entry = CMP_LIBRARY::FindLibraryComponent( aComponent->GetLibName() ); - - if( Entry == NULL ) - return NULL; - } - - aPin = Entry->GetNextPin( aPin ); - - int multi = aComponent->GetUnit(); - int convert = aComponent->GetConvert(); - for( ; aPin != NULL; aPin = Entry->GetNextPin( aPin ) ) - { - wxASSERT( aPin->Type() == LIB_PIN_T ); - - /* Skip items not used for this part */ - if( multi && aPin->GetUnit() && ( aPin->GetUnit() != multi ) ) - continue; - - if( convert && aPin->GetConvert() && ( aPin->GetConvert() != convert ) ) - continue; - - /* Calculate the pin position (according to the component orientation) - */ - aPosition = aComponent->GetPinPhysicalPosition( aPin ); - return aPin; - } - - return NULL; -} diff --git a/eeschema/eeredraw.cpp b/eeschema/eeredraw.cpp index 517a79c04a..2f0777ece1 100644 --- a/eeschema/eeredraw.cpp +++ b/eeschema/eeredraw.cpp @@ -26,9 +26,6 @@ #include "build_version.h" -static EDA_ITEM* HighLightStruct = NULL; - - void DrawDanglingSymbol( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& pos, int Color ) { BASE_SCREEN* screen = panel->GetScreen(); @@ -43,12 +40,6 @@ void DrawDanglingSymbol( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& pos, } -void SetHighLightStruct( EDA_ITEM* HighLight ) -{ - HighLightStruct = HighLight; -} - - /* * Redraws only the active window which is assumed to be whole visible. */ @@ -78,8 +69,7 @@ void SCH_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) if( GetScreen()->m_FileName == m_DefaultSchematicFileName ) { wxString msg = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion(); - title.Printf( wxT( "%s [%s]" ), msg.GetData(), - GetScreen()->m_FileName.GetData() ); + title.Printf( wxT( "%s [%s]" ), GetChars( msg), GetChars( GetScreen()->m_FileName ) ); SetTitle( title ); } else @@ -149,7 +139,7 @@ void RedrawStructList( WinEDA_DrawPanel* panel, wxDC* DC, // EDA_ITEM::GetBoundingBox() // if( panel->m_ClipBox.Intersects( Structs->GetBoundingBox() // ) ) - RedrawOneStruct( panel, DC, Structlist, DrawMode, Color ); + Structlist->Draw( panel, DC, wxPoint( 0, 0 ), DrawMode, Color ); } Structlist = Structlist->Next(); @@ -157,152 +147,12 @@ void RedrawStructList( WinEDA_DrawPanel* panel, wxDC* DC, } -/***************************************************************************** -* Routine to redraw list of structs. * -*****************************************************************************/ +/* Routine to redraw on schematic object. */ void RedrawOneStruct( WinEDA_DrawPanel* panel, wxDC* DC, SCH_ITEM* Struct, int DrawMode, int Color ) { if( Struct == NULL ) return; - if( HighLightStruct == Struct ) - Color = HIGHLIGHT_COLOR; - Struct->Draw( panel, DC, wxPoint( 0, 0 ), DrawMode, Color ); } - - -/* Routine for repainting item in ghost mode. Used in the block moves. */ -void DrawStructsInGhost( WinEDA_DrawPanel* aPanel, - wxDC* aDC, - SCH_ITEM* aItem, - const wxPoint& aOffset ) -{ - int DrawMode = g_XorMode; - int width = g_DrawDefaultLineThickness; - - GRSetDrawMode( aDC, DrawMode ); - - switch( aItem->Type() ) - { - case SCH_POLYLINE_T: - { - SCH_POLYLINE* Struct = (SCH_POLYLINE*) aItem; - GRMoveTo( Struct->m_PolyPoints[0].x + aOffset.x, Struct->m_PolyPoints[0].y + aOffset.y ); - - for( unsigned ii = 1; ii < Struct->GetCornerCount(); ii++ ) - GRLineTo( &aPanel->m_ClipBox, - aDC, - Struct->m_PolyPoints[ii].x + aOffset.x, - Struct->m_PolyPoints[ii].y + aOffset.y, - width, - g_GhostColor ); - - break; - } - - case SCH_LINE_T: - { - SCH_LINE* Struct; - Struct = (SCH_LINE*) aItem; - - if( (Struct->m_Flags & STARTPOINT) == 0 ) - { - GRMoveTo( Struct->m_Start.x + aOffset.x, Struct->m_Start.y + aOffset.y ); - } - else - { - GRMoveTo( Struct->m_Start.x, Struct->m_Start.y ); - } - - if( (Struct->m_Flags & ENDPOINT) == 0 ) - { - GRLineTo( &aPanel->m_ClipBox, aDC, Struct->m_End.x + aOffset.x, - Struct->m_End.y + aOffset.y, width, g_GhostColor ); - } - else - { - GRLineTo( &aPanel->m_ClipBox, aDC, Struct->m_End.x, - Struct->m_End.y, width, g_GhostColor ); - } - break; - } - - case SCH_BUS_ENTRY_T: - { - SCH_BUS_ENTRY* Struct = (SCH_BUS_ENTRY*) aItem; - wxPoint start = Struct->m_Pos + aOffset; - GRMoveTo( start.x, start.y ); - GRLineTo( &aPanel->m_ClipBox, aDC, Struct->m_Size.x + start.x, - Struct->m_Size.y + start.y, width, g_GhostColor ); - break; - } - - case SCH_JUNCTION_T: - { - SCH_JUNCTION* Struct; - Struct = (SCH_JUNCTION*) aItem; - Struct->Draw( aPanel, aDC, aOffset, DrawMode, g_GhostColor ); - break; - } - - case SCH_TEXT_T: - { - SCH_TEXT* Struct; - Struct = (SCH_TEXT*) aItem; - Struct->Draw( aPanel, aDC, aOffset, DrawMode, g_GhostColor ); - break; - } - - case SCH_LABEL_T: - case SCH_GLOBAL_LABEL_T: - case SCH_HIERARCHICAL_LABEL_T: - { - SCH_LABEL* Struct; - Struct = (SCH_LABEL*) aItem; - Struct->Draw( aPanel, aDC, aOffset, DrawMode, g_GhostColor ); - break; - } - - case SCH_NO_CONNECT_T: - { - SCH_NO_CONNECT* Struct; - Struct = (SCH_NO_CONNECT*) aItem; - Struct->Draw( aPanel, aDC, aOffset, DrawMode, g_GhostColor ); - break; - } - - case SCH_COMPONENT_T: - { - SCH_COMPONENT* Component = (SCH_COMPONENT*) aItem; - - if( Component == NULL ) - break; - - Component->Draw( aPanel, aDC, aOffset, g_XorMode, g_GhostColor, false ); - break; - } - - case SCH_SHEET_T: - { - SCH_SHEET* Struct = (SCH_SHEET*) aItem; - GRRect( &aPanel->m_ClipBox, - aDC, - Struct->m_Pos.x + aOffset.x, - Struct->m_Pos.y + aOffset.y, - Struct->m_Pos.x + Struct->m_Size.x + aOffset.x, - Struct->m_Pos.y + Struct->m_Size.y + aOffset.y, - width, - g_GhostColor ); - break; - } - - case SCH_SHEET_LABEL_T: - case SCH_MARKER_T: - break; - - default: - break; - } -} diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index b011ad0b81..4616a832dc 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -37,10 +37,6 @@ SCH_ITEM* g_ItemToUndoCopy; /* copy of last modified schematic item * before it is modified (used for undo * managing to restore old values ) */ -/* Block operation (copy, paste) */ -BLOCK_SELECTOR g_BlockSaveDataList; // List of items to paste - // (Created by Block Save) - bool g_HVLines = true; // Bool: force H or V // directions (Wires, Bus ..) diff --git a/eeschema/general.h b/eeschema/general.h index a1a13665a8..9caf5d1cb4 100644 --- a/eeschema/general.h +++ b/eeschema/general.h @@ -142,10 +142,6 @@ extern SCH_ITEM* g_ItemToUndoCopy; /* copy of last modified schematic item * before it is modified (used for undo * managing to restore old values ) */ -/* Block operation (copy, paste) */ -extern BLOCK_SELECTOR g_BlockSaveDataList; /* List of items to paste (Created - * by Block Save) */ - // Management options. extern bool g_HVLines; diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index a8f08621cd..658511816e 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -212,8 +212,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC, // Set the component value that can differ from component name in lib, for aliases Component->GetField( VALUE )->m_Text = Name; Component->DisplayInfo( this ); - - DrawStructsInGhost( DrawPanel, DC, Component, wxPoint( 0, 0 ) ); + Component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); return Component; } @@ -232,13 +231,12 @@ static void ShowWhileMoving( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ) if( erase ) { - DrawStructsInGhost( panel, DC, Component, wxPoint(0,0) ); + Component->Draw( panel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); } move_vector = screen->m_Curseur - Component->m_Pos; Component->Move( move_vector ); - - DrawStructsInGhost( panel, DC, Component, wxPoint(0,0) ); + Component->Draw( panel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); } @@ -258,7 +256,7 @@ void SCH_EDIT_FRAME::CmpRotationMiroir( SCH_COMPONENT* DrawComponent, wxDC* DC, DrawPanel->CursorOff( DC ); if( DrawComponent->m_Flags ) - DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) ); + DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); else { DrawPanel->PostDirtyRect( DrawComponent->GetBoundingBox() ); @@ -271,7 +269,7 @@ void SCH_EDIT_FRAME::CmpRotationMiroir( SCH_COMPONENT* DrawComponent, wxDC* DC, if( DC ) { if( DrawComponent->m_Flags ) - DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) ); + DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); else DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); DrawPanel->CursorOn( DC ); @@ -342,7 +340,7 @@ void SCH_EDIT_FRAME::SelPartUnit( SCH_COMPONENT* DrawComponent, int unit, wxDC* unit = m_UnitCount; if( DrawComponent->m_Flags ) - DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) ); + DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); else DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode ); @@ -352,7 +350,7 @@ void SCH_EDIT_FRAME::SelPartUnit( SCH_COMPONENT* DrawComponent, int unit, wxDC* /* Redraw the component in the new position. */ if( DrawComponent->m_Flags ) - DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) ); + DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); else DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); @@ -380,7 +378,7 @@ void SCH_EDIT_FRAME::ConvertPart( SCH_COMPONENT* DrawComponent, wxDC* DC ) } if( DrawComponent->m_Flags ) - DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) ); + DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); else DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode ); @@ -397,7 +395,7 @@ void SCH_EDIT_FRAME::ConvertPart( SCH_COMPONENT* DrawComponent, wxDC* DC ) /* Redraw the component in the new position. */ if( DrawComponent->m_Flags & IS_MOVED ) - DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) ); + DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); else DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); @@ -444,11 +442,11 @@ void SCH_EDIT_FRAME::StartMovePart( SCH_COMPONENT* Component, wxDC* DC ) Component->m_Flags |= IS_MOVED; // omit redrawing the component, erase only DrawPanel->PostDirtyRect( Component->GetBoundingBox() ); - DrawStructsInGhost( DrawPanel, DC, Component, wxPoint(0,0) ); + Component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); #else - RedrawOneStruct( DrawPanel, DC, Component, g_XorMode ); + Component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode ); Component->m_Flags |= IS_MOVED; diff --git a/eeschema/protos.h b/eeschema/protos.h index 5fea6348bf..74c3f6986c 100644 --- a/eeschema/protos.h +++ b/eeschema/protos.h @@ -132,12 +132,6 @@ SCH_SHEET_PIN* LocateAnyPinSheet( const wxPoint& RefPos, SCH_ITEM* DrawList ); /* EEREDRAW.CPP */ /***************/ void DrawDanglingSymbol( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& pos, int Color ); - -void DrawStructsInGhost( WinEDA_DrawPanel* aPanel, - wxDC* aDC, - SCH_ITEM* aItem, - const wxPoint& aOffset ); -void SetHighLightStruct( SCH_ITEM* HighLight ); void RedrawActiveWindow( WinEDA_DrawPanel* panel, wxDC* DC ); void RedrawStructList( WinEDA_DrawPanel* panel, wxDC* DC, diff --git a/eeschema/sch_bus_entry.h b/eeschema/sch_bus_entry.h index f4b669329a..5c67d54fa6 100644 --- a/eeschema/sch_bus_entry.h +++ b/eeschema/sch_bus_entry.h @@ -103,6 +103,8 @@ public: virtual bool IsSelectStateChanged( const wxRect& aRect ); + virtual bool IsConnectable() const { return true; } + virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const; private: diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index 42e8982b1f..cb02f1bcaf 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -42,8 +42,8 @@ class SCH_COMPONENT : public SCH_ITEM SCH_FIELDS m_Fields; ///< Variable length list of fields. /** - * Defines the hierarchical path and reference of the component. This allowa support - * for hierarchical sheets that reference the same schematic. The foramt for the path + * Defines the hierarchical path and reference of the component. This allows support + * for hierarchical sheets that reference the same schematic. The format for the path * is /<sheet time stamp>/<sheet time stamp>/.../&lscomponent time stamp>. * A single / denotes the root sheet. */ @@ -282,7 +282,7 @@ public: * adds a full hierarchical reference (path + local reference) * @param aPath Hierarchical path (/<sheet timestamp>/<component * timestamp> like /05678E50/A23EF560) - * @param aRef :ocal reference like C45, R56 + * @param aRef :local reference like C45, R56 * @param aMulti Part selection, used in multi part per package (0 or 1 for non multi) */ void AddHierarchicalReference( const wxString& aPath, @@ -349,6 +349,8 @@ public: virtual bool IsSelectStateChanged( const wxRect& aRect ); + virtual bool IsConnectable() const { return true; } + virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const; /** @@ -360,8 +362,6 @@ public: * @return A pointer to the component library object if found, otherwise NULL. */ LIB_DRAW_ITEM* GetDrawItem( const wxPoint& aPosition, KICAD_T aType = TYPE_NOT_INIT ); - - #if defined(DEBUG) /** diff --git a/eeschema/sch_items.h b/eeschema/sch_items.h index f82cf692fa..018bd7a04e 100644 --- a/eeschema/sch_items.h +++ b/eeschema/sch_items.h @@ -87,6 +87,8 @@ public: virtual bool IsSelectStateChanged( const wxRect& aRect ); + virtual bool IsConnectable() const { return true; } + virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const; #if defined(DEBUG) diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp index 0cfb45f3f7..a0b3d5a07e 100644 --- a/eeschema/sch_line.cpp +++ b/eeschema/sch_line.cpp @@ -201,14 +201,18 @@ void SCH_LINE::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, GRSetDrawMode( DC, DrawMode ); + wxPoint start = m_Start; + wxPoint end = m_End; + + if( ( m_Flags & STARTPOINT ) == 0 ) + start += offset; + if( ( m_Flags & ENDPOINT ) == 0 ) + end += offset; + if( m_Layer == LAYER_NOTES ) - GRDashedLine( &panel->m_ClipBox, DC, m_Start.x + offset.x, - m_Start.y + offset.y, m_End.x + offset.x, - m_End.y + offset.y, width, color ); + GRDashedLine( &panel->m_ClipBox, DC, start.x, start.y, end.x, end.y, width, color ); else - GRLine( &panel->m_ClipBox, DC, m_Start.x + offset.x, - m_Start.y + offset.y, m_End.x + offset.x, m_End.y + offset.y, - width, color ); + GRLine( &panel->m_ClipBox, DC, start.x, start.y, end.x, end.y, width, color ); if( m_StartIsDangling ) DrawDanglingSymbol( panel, DC, m_Start + offset, color ); @@ -367,20 +371,38 @@ bool SCH_LINE::IsSelectStateChanged( const wxRect& aRect ) { bool previousState = IsSelected(); - if( aRect.Contains( m_Start ) ) - m_Flags |= STARTPOINT | SELECTED; + if( aRect.Contains( m_Start ) && aRect.Contains( m_End ) ) + { + m_Flags |= SELECTED; + } + else if( aRect.Contains( m_Start ) ) + { + m_Flags &= ~STARTPOINT; + m_Flags |= ( SELECTED | ENDPOINT ); + } + else if( aRect.Contains( m_End ) ) + { + m_Flags &= ~ENDPOINT; + m_Flags |= ( SELECTED | STARTPOINT ); + } else - m_Flags &= ~( STARTPOINT | SELECTED ); - - if( aRect.Contains( m_End ) ) - m_Flags |= ENDPOINT | SELECTED; - else - m_Flags &= ~( ENDPOINT | SELECTED ); + { + m_Flags &= ~( SELECTED | STARTPOINT | ENDPOINT ); + } return previousState != IsSelected(); } +bool SCH_LINE::IsConnectable() const +{ + if( m_Layer == LAYER_WIRE || m_Layer == LAYER_BUS ) + return true; + + return false; +} + + void SCH_LINE::GetConnectionPoints( vector< wxPoint >& aPoints ) const { aPoints.push_back( m_Start ); diff --git a/eeschema/sch_line.h b/eeschema/sch_line.h index 3c81f5df60..2f54c8adf8 100644 --- a/eeschema/sch_line.h +++ b/eeschema/sch_line.h @@ -119,6 +119,12 @@ public: virtual bool IsSelectStateChanged( const wxRect& aRect ); + /** + * Function IsConnectable + * returns true if the schematic item can connect to another schematic item. + */ + virtual bool IsConnectable() const; + virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const; #if defined(DEBUG) diff --git a/eeschema/sch_no_connect.h b/eeschema/sch_no_connect.h index d858e5c7d1..ccf23ba733 100644 --- a/eeschema/sch_no_connect.h +++ b/eeschema/sch_no_connect.h @@ -90,6 +90,8 @@ public: virtual bool IsSelectStateChanged( const wxRect& aRect ); + virtual bool IsConnectable() const { return true; } + virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const; private: diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 8b2c155875..6ed68e1314 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -15,7 +15,10 @@ #include "netlist.h" #include "class_library.h" #include "sch_items.h" +#include "sch_bus_entry.h" #include "sch_line.h" +#include "sch_marker.h" +#include "sch_no_connect.h" #include "sch_sheet.h" #include "sch_component.h" @@ -447,6 +450,80 @@ void SCH_SCREEN::GetHierarchicalItems( std::vector aItems ) } +void SCH_SCREEN::SelectBlockItems() +{ + SCH_ITEM* item; + + PICKED_ITEMS_LIST* pickedlist = &m_BlockLocate.m_ItemsSelection; + + if( pickedlist->GetCount() == 0 ) + return; + + ClearDrawingState(); + + for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ ) + { + item = (SCH_ITEM*) pickedlist->GetPickedItem( ii ); + item->m_Flags = SELECTED; + } + + if( !m_BlockLocate.IsDragging() ) + return; + + // Select all the items in the screen connected to the items in the block. + for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ ) + { + item = (SCH_ITEM*)pickedlist->GetPickedItem( ii ); + + if( item->Type() == SCH_LINE_T ) + { + item->IsSelectStateChanged( m_BlockLocate ); + pickedlist->SetPickerFlags( item->m_Flags, ii ); + } + else if( item->IsConnectable() ) + { + std::vector< wxPoint > connections; + + item->GetConnectionPoints( connections ); + + for( size_t i = 0; i < connections.size(); i++ ) + addConnectedItemsToBlock( connections[i] ); + } + } +} + + +void SCH_SCREEN::addConnectedItemsToBlock( const wxPoint& position ) +{ + SCH_ITEM* item; + ITEM_PICKER picker; + + for( item = GetDrawItems(); item != NULL; item = item = item->Next() ) + { + picker.m_PickedItem = item; + picker.m_PickedItemType = item->Type(); + + if( item->IsSelected() || !item->IsConnectable() || !item->IsConnected( position ) ) + continue; + + item->m_Flags = SELECTED; + + if( item->Type() == SCH_LINE_T ) + { + SCH_LINE* line = (SCH_LINE*) item; + + if( line->m_Start == position ) + item->m_Flags |= ENDPOINT; + else if( line->m_End == position ) + item->m_Flags |= STARTPOINT; + } + + picker.m_PickerFlags = item->m_Flags; + m_BlockLocate.m_ItemsSelection.PushItem( picker ); + } +} + + /******************************************************************/ /* Class SCH_SCREENS to handle the list of screens in a hierarchy */ /******************************************************************/ diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index ff79c0e0e8..e93183369c 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -389,7 +389,7 @@ void SCH_SHEET::Place( SCH_EDIT_FRAME* frame, wxDC* DC ) frame->GetScreen()->SetCurItem( NULL ); frame->DrawPanel->ManageCurseur = NULL; frame->DrawPanel->ForceCloseManageCurseur = NULL; - RedrawOneStruct( frame->DrawPanel, DC, this, g_XorMode ); + Draw( frame->DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode ); delete this; return; } diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 33b6842276..d5b9e4d2ea 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -187,6 +187,8 @@ public: virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ); virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ); + + virtual bool IsConnectable() const { return true; } }; @@ -500,6 +502,8 @@ public: virtual bool IsSelectStateChanged( const wxRect& aRect ); + virtual bool IsConnectable() const { return true; } + virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const; #if defined(DEBUG) diff --git a/eeschema/sch_text.h b/eeschema/sch_text.h index 7a4be08a7e..9f5613cf2c 100644 --- a/eeschema/sch_text.h +++ b/eeschema/sch_text.h @@ -288,6 +288,8 @@ public: */ virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ); + virtual bool IsConnectable() const { return true; } + private: virtual bool doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const; virtual EDA_ITEM* doClone() const; @@ -385,6 +387,8 @@ public: virtual void Rotate( wxPoint rotationPoint ); + virtual bool IsConnectable() const { return true; } + private: virtual bool doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const; virtual EDA_ITEM* doClone() const; @@ -484,6 +488,8 @@ public: virtual void Rotate( wxPoint rotationPoint ); + virtual bool IsConnectable() const { return true; } + private: virtual bool doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const; virtual EDA_ITEM* doClone() const; diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 9bfec40355..f787d8b35e 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -497,8 +497,8 @@ void SCH_EDIT_FRAME::OnUpdateBlockSelected( wxUpdateUIEvent& event ) void SCH_EDIT_FRAME::OnUpdatePaste( wxUpdateUIEvent& event ) { - event.Enable( g_BlockSaveDataList.GetCount() > 0 ); - m_HToolBar->EnableTool( wxID_PASTE, g_BlockSaveDataList.GetCount() > 0 ); + event.Enable( m_blockItems.GetCount() > 0 ); + m_HToolBar->EnableTool( wxID_PASTE, m_blockItems.GetCount() > 0 ); } diff --git a/include/block_commande.h b/include/block_commande.h index c55fa8ac35..8f4251ead3 100644 --- a/include/block_commande.h +++ b/include/block_commande.h @@ -124,6 +124,12 @@ public: { m_BlockLastCursorPosition = aPosition; } + + /** + * Function IsDragging + * returns true if the current block command is a drag operation. + */ + bool IsDragging() const { return m_Command == BLOCK_DRAG; } }; diff --git a/include/class_sch_screen.h b/include/class_sch_screen.h index e4696db625..4aec26c9f7 100644 --- a/include/class_sch_screen.h +++ b/include/class_sch_screen.h @@ -20,6 +20,18 @@ class SCH_SHEET_PATH; class SCH_SCREEN : public BASE_SCREEN { + /** + * Function addConnectedItemsToBlock + * add items connected at \a aPosition to the block pick list. + *

+ * This method tests all connectable unselected items in the screen that are connected to + * \a aPosition and adds them to the block selection pick list. This is used when a block + * drag is being performed to ensure connections to items in the block are not lost. + *

+ * @param aPosition = The connection point to test. + */ + void addConnectedItemsToBlock( const wxPoint& aPosition ); + public: int m_RefCount; ///< Number of sheets referencing this screen. ///< Delete when it goes to zero. @@ -133,6 +145,14 @@ public: */ void GetHierarchicalItems( std::vector aItems ); + /** + * Function SelectBlockItems + * creates a list of items found when a block command is initiated. The items selected + * depend on the block commad. If the drag block command is issued, than any items + * connected to items in the block are also selected. + */ + void SelectBlockItems(); + virtual void AddItem( SCH_ITEM* aItem ) { BASE_SCREEN::AddItem( (EDA_ITEM*) aItem ); } virtual void InsertItem( EDA_ITEMS::iterator aIter, SCH_ITEM* aItem ) { diff --git a/include/sch_item_struct.h b/include/sch_item_struct.h index 54272c232d..e13d83c3f6 100644 --- a/include/sch_item_struct.h +++ b/include/sch_item_struct.h @@ -247,6 +247,12 @@ public: */ virtual bool IsSelectStateChanged( const wxRect& aRect ) { return false; } + /** + * Function IsConnectable + * returns true if the schematic item can connect to another schematic item. + */ + virtual bool IsConnectable() const { return false; } + /** * Function GetConnectionPoints * add all the connection points for this item to \a aPoints. diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index 44b0879ed3..1f8dbd7560 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -9,6 +9,7 @@ #include "param_config.h" #include "class_undoredo_container.h" #include "template_fieldnames.h" +#include "block_commande.h" class LIB_EDIT_FRAME; @@ -91,6 +92,7 @@ private: wxSize m_findDialogSize; wxArrayString m_findStringHistoryList; wxArrayString m_replaceStringHistoryList; + BLOCK_SELECTOR m_blockItems; ///< List of selected items. public: SCH_EDIT_FRAME( wxWindow* father, @@ -617,6 +619,13 @@ private: */ void GetSchematicFromUndoList( wxCommandEvent& event ); + /** + * Function copyBlockItems + * copies the list of block item. + * @sa m_blockItems + * @param aItemList List to copy the block select items into. + */ + void copyBlockItems( PICKED_ITEMS_LIST& aItemsList ); public: void Key( wxDC* DC, int hotkey, EDA_ITEM* DrawStruct );