kicad/pcbnew/block.cpp

963 lines
28 KiB
C++
Raw Normal View History

/*************/
/* block.cpp */
/*************/
2007-05-06 16:03:28 +00:00
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "class_drawpanel.h"
#include "confirm.h"
#include "block_commande.h"
2007-05-06 16:03:28 +00:00
#include "pcbnew.h"
2009-07-30 11:04:07 +00:00
#include "wxPcbStruct.h"
2007-05-06 16:03:28 +00:00
#include "trigo.h"
#include "dialog_block_options_base.h"
2007-05-06 16:03:28 +00:00
#include "protos.h"
#define BLOCK_OUTLINE_COLOR YELLOW
/**
* Function drawPickedItems
* draws items currently selected in a block
* @param aPanel = Current draw panel
* @param aDC = Current device context
* @param aOffset = Drawing offset
**/
static void drawPickedItems( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint aOffset );
/**
* Function drawMovingBlock
* handles drawing of a moving block
* @param aPanel = Current draw panel
* @param aDC = Current device context
* @param aPosition The cursor position in logical (drawing) units.
* @param aErase = Erase block at current position
**/
static void drawMovingBlock( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase );
2007-05-06 16:03:28 +00:00
static bool blockIncludeModules = true;
static bool blockIncludeLockedModules = true;
static bool blockIncludeTracks = true;
static bool blockIncludeZones = true;
static bool blockIncludeItemsOnTechLayers = true;
static bool blockIncludeBoardOutlineLayer = true;
static bool blockIncludePcbTexts = true;
static bool blockDrawItems = true;
static bool blockIncludeItemsOnInvisibleLayers = false;
/************************************/
/* class DIALOG_BLOCK_OPTIONS */
/************************************/
2007-05-06 16:03:28 +00:00
class DIALOG_BLOCK_OPTIONS : public DIALOG_BLOCK_OPTIONS_BASE
2007-05-06 16:03:28 +00:00
{
private:
PCB_BASE_FRAME* m_Parent;
2007-05-06 16:03:28 +00:00
public:
DIALOG_BLOCK_OPTIONS( PCB_BASE_FRAME* parent, const wxString& title );
~DIALOG_BLOCK_OPTIONS()
{
}
2007-05-06 16:03:28 +00:00
private:
2009-08-01 19:26:05 +00:00
void ExecuteCommand( wxCommandEvent& event );
void OnCancel( wxCommandEvent& event ) { EndModal( -1 ); }
void checkBoxClicked( wxCommandEvent& aEvent )
{
if( m_Include_Modules->GetValue() )
m_IncludeLockedModules->Enable();
else
m_IncludeLockedModules->Disable();
}
2007-05-06 16:03:28 +00:00
};
static bool InstallBlockCmdFrame( PCB_BASE_FRAME* parent, const wxString& title )
2007-05-06 16:03:28 +00:00
{
int nocmd;
wxPoint oldpos = parent->GetScreen()->GetCrossHairPosition();
2007-05-06 16:03:28 +00:00
parent->DrawPanel->m_IgnoreMouseEvents = true;
DIALOG_BLOCK_OPTIONS dlg( parent, title );
2008-04-01 05:21:50 +00:00
nocmd = dlg.ShowModal();
2008-04-01 05:21:50 +00:00
parent->GetScreen()->SetCrossHairPosition( oldpos );
parent->DrawPanel->MoveCursorToCrossHair();
parent->DrawPanel->m_IgnoreMouseEvents = false;
2007-05-06 16:03:28 +00:00
return nocmd ? false : true;
2007-05-06 16:03:28 +00:00
}
DIALOG_BLOCK_OPTIONS::DIALOG_BLOCK_OPTIONS( PCB_BASE_FRAME* aParent, const wxString& aTitle ) :
DIALOG_BLOCK_OPTIONS_BASE( aParent, -1, aTitle )
2007-05-06 16:03:28 +00:00
{
m_Parent = aParent;
m_Include_Modules->SetValue( blockIncludeModules );
m_IncludeLockedModules->SetValue( blockIncludeLockedModules );
if( m_Include_Modules->GetValue() )
m_IncludeLockedModules->Enable();
else
m_IncludeLockedModules->Disable();
m_Include_Tracks->SetValue( blockIncludeTracks );
m_Include_Zones->SetValue( blockIncludeZones );
m_Include_Draw_Items->SetValue( blockIncludeItemsOnTechLayers );
m_Include_Edges_Items->SetValue( blockIncludeBoardOutlineLayer );
m_Include_PcbTextes->SetValue( blockIncludePcbTexts );
m_DrawBlockItems->SetValue( blockDrawItems );
m_checkBoxIncludeInvisible->SetValue( blockIncludeItemsOnInvisibleLayers );
m_sdbSizer1OK->SetDefault();
SetFocus();
GetSizer()->SetSizeHints( this );
Centre();
2007-05-06 16:03:28 +00:00
}
void DIALOG_BLOCK_OPTIONS::ExecuteCommand( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
{
blockIncludeModules = m_Include_Modules->GetValue();
blockIncludeLockedModules = m_IncludeLockedModules->GetValue();
blockIncludeTracks = m_Include_Tracks->GetValue();
blockIncludeZones = m_Include_Zones->GetValue();
blockIncludeItemsOnTechLayers = m_Include_Draw_Items->GetValue();
blockIncludeBoardOutlineLayer = m_Include_Edges_Items->GetValue();
blockIncludePcbTexts = m_Include_PcbTextes->GetValue();
blockDrawItems = m_DrawBlockItems->GetValue();
blockIncludeItemsOnInvisibleLayers = m_checkBoxIncludeInvisible->GetValue();
EndModal( 0 );
2007-05-06 16:03:28 +00:00
}
/**
* Function ReturnBlockCommand
* Returns the block command internat code (BLOCK_MOVE, BLOCK_COPY...)
* corresponding to the keys pressed (ALT, SHIFT, SHIFT ALT ..) when
* block command is started by dragging the mouse.
* @param aKey = the key modifiers (Alt, Shift ...)
* @return the block command id (BLOCK_MOVE, BLOCK_COPY...)
*/
int PCB_EDIT_FRAME::ReturnBlockCommand( int aKey )
2007-05-06 16:03:28 +00:00
{
int cmd = 0;
2007-05-06 16:03:28 +00:00
switch( aKey )
{
default:
cmd = aKey & 0x255;
break;
2007-05-06 16:03:28 +00:00
case 0:
cmd = BLOCK_MOVE;
break;
2007-05-06 16:03:28 +00:00
case GR_KB_SHIFT:
cmd = BLOCK_COPY;
break;
2007-05-06 16:03:28 +00:00
case GR_KB_CTRL:
cmd = BLOCK_ROTATE;
break;
2007-05-06 16:03:28 +00:00
case GR_KB_SHIFTCTRL:
cmd = BLOCK_DELETE;
break;
2007-05-06 16:03:28 +00:00
case GR_KB_ALT:
cmd = BLOCK_FLIP;
break;
2007-05-06 16:03:28 +00:00
case MOUSE_MIDDLE:
cmd = BLOCK_ZOOM;
break;
}
2007-05-06 16:03:28 +00:00
return cmd;
2007-05-06 16:03:28 +00:00
}
/**
* Function HandleBlockPlace( )
* Called after HandleBlockEnd, when a block command needs to be
* executed after the block is moved to its new place
* (bloc move, drag, copy .. )
* Parameters must be initialized in GetScreen()->m_BlockLocate
*/
void PCB_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
2007-05-06 16:03:28 +00:00
{
bool err = false;
if( !DrawPanel->IsMouseCaptured() )
{
err = true;
DisplayError( this, wxT( "Error in HandleBlockPLace : m_mouseCaptureCallback = NULL" ) );
}
GetScreen()->m_BlockLocate.m_State = STATE_BLOCK_STOP;
switch( GetScreen()->m_BlockLocate.m_Command )
{
2009-08-01 19:26:05 +00:00
case BLOCK_IDLE:
err = true;
break;
case BLOCK_DRAG: /* Drag */
case BLOCK_MOVE: /* Move */
case BLOCK_PRESELECT_MOVE: /* Move with preselection list*/
if( DrawPanel->IsMouseCaptured() )
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
2009-08-01 19:26:05 +00:00
Block_Move();
GetScreen()->m_BlockLocate.ClearItemsList();
break;
case BLOCK_COPY: /* Copy */
if( DrawPanel->IsMouseCaptured() )
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
2009-08-01 19:26:05 +00:00
Block_Duplicate();
GetScreen()->m_BlockLocate.ClearItemsList();
break;
case BLOCK_PASTE:
break;
case BLOCK_ZOOM: // Handled by HandleBlockEnd()
default:
break;
}
OnModify();
DrawPanel->SetMouseCapture( NULL, NULL );
GetScreen()->ClearBlockCommand();
if( GetScreen()->m_BlockLocate.GetCount() )
{
DisplayError( this, wxT( "Error in HandleBlockPLace some items left in list" ) );
GetScreen()->m_BlockLocate.ClearItemsList();
}
DisplayToolMsg( wxEmptyString );
DrawPanel->SetCursor( DrawPanel->GetCurrentCursor() );
2007-05-06 16:03:28 +00:00
}
/**
* Function HandleBlockEnd( )
* Handle the "end" of a block command,
* i.e. is called at the end of the definition of the area of a block.
* depending on the current block command, this command is executed
* or parameters are initialized to prepare a call to HandleBlockPlace
* in GetScreen()->m_BlockLocate
* @return false if no item selected, or command finished,
* true if some items found and HandleBlockPlace must be called later
*/
bool PCB_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
2007-05-06 16:03:28 +00:00
{
bool nextcmd = false; // Will be set to true if a block place is needed
bool cancelCmd = false;
// If coming here after cancel block, clean up and exit
if( GetScreen()->m_BlockLocate.m_State == STATE_NO_BLOCK )
{
DrawPanel->SetMouseCapture( NULL, NULL );
GetScreen()->ClearBlockCommand();
DisplayToolMsg( wxEmptyString );
return false;
}
// Show dialog if there are no selected items and we're not zooming
if( !GetScreen()->m_BlockLocate.GetCount()
&& GetScreen()->m_BlockLocate.m_Command != BLOCK_ZOOM )
{
if( !InstallBlockCmdFrame( this, _( "Block Operation" ) ) )
{
cancelCmd = true;
// undraw block outline
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
}
else
{
DrawAndSizingBlockOutlines( DrawPanel, DC, wxDefaultPosition, false );
Block_SelectItems();
2010-11-12 17:33:20 +00:00
// Exit if no items found
if( !GetScreen()->m_BlockLocate.GetCount() )
cancelCmd = true;
}
}
if( !cancelCmd && DrawPanel->IsMouseCaptured() )
{
switch( GetScreen()->m_BlockLocate.m_Command )
{
2009-08-01 19:26:05 +00:00
case BLOCK_IDLE:
DisplayError( this, wxT( "Error in HandleBlockPLace" ) );
break;
case BLOCK_DRAG: /* Drag (not used, for future enhancements)*/
case BLOCK_MOVE: /* Move */
case BLOCK_COPY: /* Copy */
case BLOCK_PRESELECT_MOVE: /* Move with preselection list*/
GetScreen()->m_BlockLocate.m_State = STATE_BLOCK_MOVE;
nextcmd = true;
DrawPanel->m_mouseCaptureCallback = drawMovingBlock;
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
break;
case BLOCK_DELETE: /* Delete */
DrawPanel->m_mouseCaptureCallback = NULL;
GetScreen()->m_BlockLocate.m_State = STATE_BLOCK_STOP;
2009-08-01 19:26:05 +00:00
Block_Delete();
break;
case BLOCK_ROTATE: /* Rotation */
DrawPanel->m_mouseCaptureCallback = NULL;
GetScreen()->m_BlockLocate.m_State = STATE_BLOCK_STOP;
2009-08-01 19:26:05 +00:00
Block_Rotate();
break;
case BLOCK_FLIP: /* Flip */
DrawPanel->m_mouseCaptureCallback = NULL;
GetScreen()->m_BlockLocate.m_State = STATE_BLOCK_STOP;
2009-08-01 19:26:05 +00:00
Block_Flip();
break;
case BLOCK_SAVE: /* Save (not used, for future enhancements)*/
GetScreen()->m_BlockLocate.m_State = STATE_BLOCK_STOP;
if( GetScreen()->m_BlockLocate.GetCount() )
{
2010-11-12 17:33:20 +00:00
// @todo (if useful) Save_Block( );
}
break;
case BLOCK_PASTE:
break;
case BLOCK_ZOOM: /* Window Zoom */
// Turn off the redraw block routine now so it is not displayed
// with one corner at the new center of the screen
DrawPanel->m_mouseCaptureCallback = NULL;
Window_Zoom( GetScreen()->m_BlockLocate );
break;
default:
break;
}
}
if( ! nextcmd )
{
GetScreen()->ClearBlockCommand();
DrawPanel->SetMouseCapture( NULL, NULL );
DisplayToolMsg( wxEmptyString );
}
return nextcmd;
2007-05-06 16:03:28 +00:00
}
2009-08-01 19:26:05 +00:00
/* Block operations: */
2010-12-29 17:47:32 +00:00
/*
2009-08-01 19:26:05 +00:00
* Function Block_SelectItems
* Uses GetScreen()->m_BlockLocate
2009-08-01 19:26:05 +00:00
* select items within the selected block.
* selected items are put in the pick list
*/
void PCB_EDIT_FRAME::Block_SelectItems()
2007-05-06 16:03:28 +00:00
{
int masque_layer;
GetScreen()->m_BlockLocate.Normalize();
2009-08-01 19:26:05 +00:00
PICKED_ITEMS_LIST* itemsList = &GetScreen()->m_BlockLocate.m_ItemsSelection;
ITEM_PICKER picker( NULL, UR_UNSPECIFIED );
// Add modules
if( blockIncludeModules )
{
for( MODULE* module = m_Pcb->m_Modules; module != NULL;
module = module->Next() )
{
int layer = module->GetLayer();
if( module->HitTest( GetScreen()->m_BlockLocate )
&& ( !module->IsLocked() || blockIncludeLockedModules ) )
2008-04-01 05:21:50 +00:00
{
if( blockIncludeItemsOnInvisibleLayers || m_Pcb->IsModuleLayerVisible( layer ) )
{
picker.m_PickedItem = module;
picker.m_PickedItemType = module->Type();
itemsList->PushItem( picker );
}
2008-04-01 05:21:50 +00:00
}
}
}
// Add tracks and vias
if( blockIncludeTracks )
{
for( TRACK* pt_segm = m_Pcb->m_Track; pt_segm != NULL;
pt_segm = pt_segm->Next() )
{
if( pt_segm->HitTest( GetScreen()->m_BlockLocate ) )
2008-04-01 05:21:50 +00:00
{
if( blockIncludeItemsOnInvisibleLayers || m_Pcb->IsLayerVisible( pt_segm->GetLayer() ) )
{
picker.m_PickedItem = pt_segm;
picker.m_PickedItemType = pt_segm->Type();
itemsList->PushItem( picker );
}
}
}
}
// Add graphic items
masque_layer = EDGE_LAYER;
if( blockIncludeItemsOnTechLayers )
masque_layer = ALL_LAYERS;
2008-04-01 05:21:50 +00:00
if( !blockIncludeBoardOutlineLayer )
masque_layer &= ~EDGE_LAYER;
for( BOARD_ITEM* PtStruct = m_Pcb->m_Drawings; PtStruct != NULL;
PtStruct = PtStruct->Next() )
{
if( !m_Pcb->IsLayerVisible( PtStruct->GetLayer() ) && ! blockIncludeItemsOnInvisibleLayers)
continue;
2009-08-01 19:26:05 +00:00
bool select_me = false;
2007-09-01 12:00:30 +00:00
switch( PtStruct->Type() )
{
case TYPE_DRAWSEGMENT:
if( (g_TabOneLayerMask[PtStruct->GetLayer()] & masque_layer) == 0 )
break;
2009-08-01 19:26:05 +00:00
if( !PtStruct->HitTest( GetScreen()->m_BlockLocate ) )
break;
2009-08-01 19:26:05 +00:00
select_me = true; // This item is in bloc: select it
break;
case TYPE_TEXTE:
if( !blockIncludePcbTexts )
break;
2009-08-01 19:26:05 +00:00
if( !PtStruct->HitTest( GetScreen()->m_BlockLocate ) )
break;
2009-08-01 19:26:05 +00:00
select_me = true; // This item is in bloc: select it
break;
case TYPE_MIRE:
if( ( g_TabOneLayerMask[PtStruct->GetLayer()] & masque_layer ) == 0 )
break;
2009-08-01 19:26:05 +00:00
if( !PtStruct->HitTest( GetScreen()->m_BlockLocate ) )
break;
2009-08-01 19:26:05 +00:00
select_me = true; // This item is in bloc: select it
break;
case TYPE_DIMENSION:
if( ( g_TabOneLayerMask[PtStruct->GetLayer()] & masque_layer ) == 0 )
break;
2009-08-01 19:26:05 +00:00
if( !PtStruct->HitTest( GetScreen()->m_BlockLocate ) )
break;
2009-08-01 19:26:05 +00:00
select_me = true; // This item is in bloc: select it
break;
default:
break;
}
2009-08-01 19:26:05 +00:00
if( select_me )
{
2009-08-01 19:26:05 +00:00
picker.m_PickedItem = PtStruct;
picker.m_PickedItemType = PtStruct->Type();
2009-08-01 19:26:05 +00:00
itemsList->PushItem( picker );
}
}
// Add zones
if( blockIncludeZones )
{
2009-08-01 19:26:05 +00:00
for( int ii = 0; ii < m_Pcb->GetAreaCount(); ii++ )
2008-04-01 05:21:50 +00:00
{
ZONE_CONTAINER* area = m_Pcb->GetArea( ii );
if( area->HitTest( GetScreen()->m_BlockLocate ) )
2008-04-01 05:21:50 +00:00
{
if( blockIncludeItemsOnInvisibleLayers || m_Pcb->IsLayerVisible( area->GetLayer() ) )
{
BOARD_ITEM* zone_c = (BOARD_ITEM*) area;
picker.m_PickedItem = zone_c;
picker.m_PickedItemType = zone_c->Type();
itemsList->PushItem( picker );
}
2008-04-01 05:21:50 +00:00
}
}
}
2010-11-12 17:33:20 +00:00
}
2007-05-06 16:03:28 +00:00
static void drawPickedItems( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint aOffset )
2007-05-06 16:03:28 +00:00
{
PICKED_ITEMS_LIST* itemsList = &aPanel->GetScreen()->m_BlockLocate.m_ItemsSelection;
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent();
2010-11-12 17:33:20 +00:00
g_Offset_Module = -aOffset;
for( unsigned ii = 0; ii < itemsList->GetCount(); ii++ )
{
BOARD_ITEM* item = (BOARD_ITEM*) itemsList->GetPickedItem( ii );
switch( item->Type() )
{
case TYPE_MODULE:
frame->GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
DrawModuleOutlines( aPanel, aDC, (MODULE*) item );
break;
case TYPE_DRAWSEGMENT:
case TYPE_TEXTE:
case TYPE_TRACK:
case TYPE_VIA:
case TYPE_MIRE:
case TYPE_DIMENSION: // Currently markers are not affected by block commands
case TYPE_MARKER_PCB:
item->Draw( aPanel, aDC, GR_XOR, aOffset );
break;
case TYPE_ZONE_CONTAINER:
item->Draw( aPanel, aDC, GR_XOR, aOffset );
((ZONE_CONTAINER*) item)->DrawFilledArea( aPanel, aDC, GR_XOR, aOffset );
break;
2010-11-12 15:43:26 +00:00
default:
break;
}
}
g_Offset_Module = wxPoint( 0, 0 );
}
static void drawMovingBlock( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase )
{
BASE_SCREEN* screen = aPanel->GetScreen();
if( aErase )
{
if( screen->m_BlockLocate.m_MoveVector.x || screen->m_BlockLocate.m_MoveVector.y )
{
screen->m_BlockLocate.Draw( aPanel, aDC, screen->m_BlockLocate.m_MoveVector,
GR_XOR, BLOCK_OUTLINE_COLOR );
if( blockDrawItems )
drawPickedItems( aPanel, aDC, screen->m_BlockLocate.m_MoveVector );
}
}
2009-08-01 19:26:05 +00:00
if( screen->m_BlockLocate.m_State != STATE_BLOCK_STOP )
{
screen->m_BlockLocate.m_MoveVector = screen->GetCrossHairPosition() -
screen->m_BlockLocate.m_BlockLastCursorPosition;
}
if( screen->m_BlockLocate.m_MoveVector.x
|| screen->m_BlockLocate.m_MoveVector.y )
{
screen->m_BlockLocate.Draw( aPanel, aDC, screen->m_BlockLocate.m_MoveVector,
GR_XOR, BLOCK_OUTLINE_COLOR );
if( blockDrawItems )
drawPickedItems( aPanel, aDC, screen->m_BlockLocate.m_MoveVector );
}
2009-08-01 19:26:05 +00:00
}
2009-08-01 19:26:05 +00:00
/*
* Erase selected block.
2009-08-01 19:26:05 +00:00
*/
void PCB_EDIT_FRAME::Block_Delete()
2009-08-01 19:26:05 +00:00
{
OnModify();
2009-08-01 19:26:05 +00:00
SetCurItem( NULL );
PICKED_ITEMS_LIST* itemsList = &GetScreen()->m_BlockLocate.m_ItemsSelection;
itemsList->m_Status = UR_DELETED;
/* unlink items and clear flags */
for( unsigned ii = 0; ii < itemsList->GetCount(); ii++ )
{
2009-08-01 19:26:05 +00:00
BOARD_ITEM* item = (BOARD_ITEM*) itemsList->GetPickedItem( ii );
itemsList->SetPickedItemStatus( UR_DELETED, ii );
switch( item->Type() )
{
2009-08-01 19:26:05 +00:00
case TYPE_MODULE:
{
MODULE* module = (MODULE*) item;
module->m_Flags = 0;
module->UnLink();
m_Pcb->m_Status_Pcb = 0;
}
break;
case TYPE_ZONE_CONTAINER: // a zone area
2009-08-01 19:26:05 +00:00
m_Pcb->Remove( item );
break;
case TYPE_DRAWSEGMENT: // a segment not on copper layers
case TYPE_TEXTE: // a text on a layer
case TYPE_TRACK: // a track segment (segment on a copper layer)
case TYPE_VIA: // a via (like atrack segment on a copper layer)
case TYPE_DIMENSION: // a dimension (graphic item)
case TYPE_MIRE: // a target (graphic item)
2009-08-01 19:26:05 +00:00
item->UnLink();
break;
2009-08-06 15:42:09 +00:00
// These items are deleted, but not put in undo list
case TYPE_MARKER_PCB: // a marker used to show something
case TYPE_ZONE: // SEG_ZONE items are now deprecated
2009-08-06 15:42:09 +00:00
item->UnLink();
itemsList->RemovePicker( ii );
ii--;
item->DeleteStructure();
break;
default:
wxMessageBox( wxT( "PCB_EDIT_FRAME::Block_Delete( ) error: unexpected type" ) );
break;
}
}
2009-08-01 19:26:05 +00:00
SaveCopyInUndoList( *itemsList, UR_DELETED );
Compile_Ratsnest( NULL, true );
DrawPanel->Refresh( true );
2007-05-06 16:03:28 +00:00
}
2010-12-29 17:47:32 +00:00
/*
2009-08-01 19:26:05 +00:00
* Function Block_Rotate
* Rotate all items within the selected block.
* The rotation center is the center of the block
*/
void PCB_EDIT_FRAME::Block_Rotate()
2008-01-06 12:43:57 +00:00
{
2009-08-01 19:26:05 +00:00
wxPoint oldpos;
wxPoint centre; // rotation cent-re for the rotation transform
int rotAngle = 900; // rotation angle in 0.1 deg.
oldpos = GetScreen()->GetCrossHairPosition();
centre = GetScreen()->m_BlockLocate.Centre();
OnModify();
2009-08-01 19:26:05 +00:00
PICKED_ITEMS_LIST* itemsList = &GetScreen()->m_BlockLocate.m_ItemsSelection;
itemsList->m_Status = UR_ROTATED;
for( unsigned ii = 0; ii < itemsList->GetCount(); ii++ )
{
2009-08-01 19:26:05 +00:00
BOARD_ITEM* item = (BOARD_ITEM*) itemsList->GetPickedItem( ii );
wxASSERT( item );
2009-08-01 19:26:05 +00:00
itemsList->SetPickedItemStatus( UR_ROTATED, ii );
item->Rotate( centre, rotAngle );
2009-08-01 19:26:05 +00:00
switch( item->Type() )
{
2009-08-01 19:26:05 +00:00
case TYPE_MODULE:
( (MODULE*) item )->m_Flags = 0;
m_Pcb->m_Status_Pcb = 0;
break;
2009-08-01 19:26:05 +00:00
/* Move and rotate the track segments */
case TYPE_TRACK: // a track segment (segment on a copper layer)
case TYPE_VIA: // a via (like atrack segment on a copper layer)
2009-08-01 19:26:05 +00:00
m_Pcb->m_Status_Pcb = 0;
break;
2009-08-01 19:26:05 +00:00
case TYPE_ZONE_CONTAINER:
case TYPE_DRAWSEGMENT:
case TYPE_TEXTE:
case TYPE_MIRE:
case TYPE_DIMENSION:
2009-08-01 19:26:05 +00:00
break;
2009-08-06 15:42:09 +00:00
// This item is not put in undo list
case TYPE_ZONE: // SEG_ZONE items are now deprecated
2009-08-06 15:42:09 +00:00
itemsList->RemovePicker( ii );
ii--;
break;
2009-08-01 19:26:05 +00:00
default:
wxMessageBox( wxT( "PCB_EDIT_FRAME::Block_Rotate( ) error: unexpected type" ) );
2009-08-01 19:26:05 +00:00
break;
}
}
2009-08-01 19:26:05 +00:00
SaveCopyInUndoList( *itemsList, UR_ROTATED, centre );
Compile_Ratsnest( NULL, true );
DrawPanel->Refresh( true );
2009-08-01 19:26:05 +00:00
}
2009-08-01 19:26:05 +00:00
/**
* Function Block_Flip
* flips items within the selected block.
* The flip center is the center of the block
2009-08-01 19:26:05 +00:00
*/
void PCB_EDIT_FRAME::Block_Flip()
2009-08-01 19:26:05 +00:00
{
#define INVERT( pos ) (pos) = center.y - ( (pos) - center.y )
wxPoint memo;
wxPoint center; /* Position of the axis for inversion of all elements */
OnModify();
2009-08-01 19:26:05 +00:00
PICKED_ITEMS_LIST* itemsList = &GetScreen()->m_BlockLocate.m_ItemsSelection;
itemsList->m_Status = UR_FLIPPED;
memo = GetScreen()->GetCrossHairPosition();
2009-08-01 19:26:05 +00:00
center = GetScreen()->m_BlockLocate.Centre();
for( unsigned ii = 0; ii < itemsList->GetCount(); ii++ )
{
2009-08-01 19:26:05 +00:00
BOARD_ITEM* item = (BOARD_ITEM*) itemsList->GetPickedItem( ii );
wxASSERT( item );
2009-08-01 19:26:05 +00:00
itemsList->SetPickedItemStatus( UR_FLIPPED, ii );
item->Flip( center );
2009-08-01 19:26:05 +00:00
switch( item->Type() )
{
2009-08-01 19:26:05 +00:00
case TYPE_MODULE:
item->m_Flags = 0;
2009-08-01 19:26:05 +00:00
m_Pcb->m_Status_Pcb = 0;
break;
2009-08-01 19:26:05 +00:00
/* Move and rotate the track segments */
case TYPE_TRACK: // a track segment (segment on a copper layer)
case TYPE_VIA: // a via (like atrack segment on a copper layer)
2009-08-01 19:26:05 +00:00
m_Pcb->m_Status_Pcb = 0;
break;
2009-08-01 19:26:05 +00:00
case TYPE_ZONE_CONTAINER:
case TYPE_DRAWSEGMENT:
case TYPE_TEXTE:
case TYPE_MIRE:
case TYPE_DIMENSION:
break;
2009-08-06 15:42:09 +00:00
// This item is not put in undo list
case TYPE_ZONE: // SEG_ZONE items are now deprecated
2009-08-06 15:42:09 +00:00
itemsList->RemovePicker( ii );
ii--;
break;
2009-08-01 19:26:05 +00:00
default:
wxMessageBox( wxT( "PCB_EDIT_FRAME::Block_Flip( ) error: unexpected type" ) );
break;
}
}
2009-08-01 19:26:05 +00:00
SaveCopyInUndoList( *itemsList, UR_FLIPPED, center );
Compile_Ratsnest( NULL, true );
DrawPanel->Refresh( true );
2007-05-06 16:03:28 +00:00
}
2010-12-29 17:47:32 +00:00
/*
2009-08-01 19:26:05 +00:00
* Function Block_Move
* moves all tracks and segments within the selected block.
* New location is determined by the current offset from the selected block's
* original location.
*/
void PCB_EDIT_FRAME::Block_Move()
2007-05-06 16:03:28 +00:00
{
OnModify();
wxPoint MoveVector = GetScreen()->m_BlockLocate.m_MoveVector;
2009-08-01 19:26:05 +00:00
PICKED_ITEMS_LIST* itemsList = &GetScreen()->m_BlockLocate.m_ItemsSelection;
itemsList->m_Status = UR_MOVED;
2009-08-01 19:26:05 +00:00
for( unsigned ii = 0; ii < itemsList->GetCount(); ii++ )
{
2009-08-01 19:26:05 +00:00
BOARD_ITEM* item = (BOARD_ITEM*) itemsList->GetPickedItem( ii );
itemsList->SetPickedItemStatus( UR_MOVED, ii );
item->Move( MoveVector );
2009-08-01 19:26:05 +00:00
switch( item->Type() )
2008-04-01 05:21:50 +00:00
{
2009-08-01 19:26:05 +00:00
case TYPE_MODULE:
m_Pcb->m_Status_Pcb = 0;
item->m_Flags = 0;
break;
2009-08-01 19:26:05 +00:00
/* Move track segments */
case TYPE_TRACK: // a track segment (segment on a copper layer)
case TYPE_VIA: // a via (like a track segment on a copper layer)
2009-08-01 19:26:05 +00:00
m_Pcb->m_Status_Pcb = 0;
break;
2009-08-01 19:26:05 +00:00
case TYPE_ZONE_CONTAINER:
case TYPE_DRAWSEGMENT:
case TYPE_TEXTE:
case TYPE_MIRE:
case TYPE_DIMENSION:
break;
2009-08-06 15:42:09 +00:00
// This item is not put in undo list
case TYPE_ZONE: // SEG_ZONE items are now deprecated
2009-08-06 15:42:09 +00:00
itemsList->RemovePicker( ii );
ii--;
break;
default:
wxMessageBox( wxT( "PCB_EDIT_FRAME::Block_Move( ) error: unexpected type" ) );
break;
}
}
2009-08-01 19:26:05 +00:00
SaveCopyInUndoList( *itemsList, UR_MOVED, MoveVector );
Compile_Ratsnest( NULL, true );
DrawPanel->Refresh( true );
2007-05-06 16:03:28 +00:00
}
2010-12-29 17:47:32 +00:00
/*
2009-08-01 19:26:05 +00:00
* Function Block_Duplicate
* duplicates all items within the selected block.
* New location is determined by the current offset from the selected block's
* original location.
*/
void PCB_EDIT_FRAME::Block_Duplicate()
2007-05-06 16:03:28 +00:00
{
wxPoint MoveVector = GetScreen()->m_BlockLocate.m_MoveVector;
OnModify();
2009-08-01 19:26:05 +00:00
PICKED_ITEMS_LIST* itemsList = &GetScreen()->m_BlockLocate.m_ItemsSelection;
PICKED_ITEMS_LIST newList;
2009-08-01 19:26:05 +00:00
newList.m_Status = UR_NEW;
ITEM_PICKER picker( NULL, UR_NEW );
BOARD_ITEM* newitem;
2009-08-01 19:26:05 +00:00
for( unsigned ii = 0; ii < itemsList->GetCount(); ii++ )
{
BOARD_ITEM* item = (BOARD_ITEM*) itemsList->GetPickedItem( ii );
newitem = NULL;
switch( item->Type() )
{
case TYPE_MODULE:
{
MODULE* module = (MODULE*) item;
MODULE* new_module;
m_Pcb->m_Status_Pcb = 0;
module->m_Flags = 0;
newitem = new_module = new MODULE( m_Pcb );
new_module->Copy( module );
new_module->m_TimeStamp = GetTimeStamp();
m_Pcb->m_Modules.PushFront( new_module );
}
break;
2009-08-01 19:26:05 +00:00
case TYPE_TRACK:
case TYPE_VIA:
{
TRACK* track = (TRACK*) item;
m_Pcb->m_Status_Pcb = 0;
TRACK* new_track = track->Copy();
newitem = new_track;
m_Pcb->m_Track.PushFront( new_track );
}
break;
2009-08-08 06:07:08 +00:00
case TYPE_ZONE: // SEG_ZONE items are now deprecated
break;
2008-01-06 12:43:57 +00:00
2009-08-01 19:26:05 +00:00
case TYPE_ZONE_CONTAINER:
{
ZONE_CONTAINER* new_zone =
new ZONE_CONTAINER( (BOARD*) item->GetParent() );
new_zone->Copy( (ZONE_CONTAINER*) item );
new_zone->m_TimeStamp = GetTimeStamp();
newitem = new_zone;
m_Pcb->Add( new_zone );
}
break;
case TYPE_DRAWSEGMENT:
{
DRAWSEGMENT* new_drawsegment = new DRAWSEGMENT( m_Pcb );
new_drawsegment->Copy( (DRAWSEGMENT*) item );
m_Pcb->Add( new_drawsegment );
newitem = new_drawsegment;
}
break;
case TYPE_TEXTE:
{
TEXTE_PCB* new_pcbtext = new TEXTE_PCB( m_Pcb );
new_pcbtext->Copy( (TEXTE_PCB*) item );
m_Pcb->Add( new_pcbtext );
newitem = new_pcbtext;
}
break;
case TYPE_MIRE:
{
MIREPCB* new_mire = new MIREPCB( m_Pcb );
new_mire->Copy( (MIREPCB*) item );
m_Pcb->Add( new_mire );
newitem = new_mire;
}
break;
case TYPE_DIMENSION:
{
DIMENSION* new_cotation = new DIMENSION( m_Pcb );
new_cotation->Copy( (DIMENSION*) item );
m_Pcb->Add( new_cotation );
newitem = new_cotation;
}
break;
default:
wxMessageBox( wxT( "PCB_EDIT_FRAME::Block_Duplicate( ) error: unexpected type" ) );
break;
}
2009-08-01 19:26:05 +00:00
2010-11-12 17:33:20 +00:00
if( newitem )
{
newitem->Move( MoveVector );
picker.m_PickedItem = newitem;
picker.m_PickedItemType = newitem->Type();
newList.PushItem( picker );
}
}
2009-08-01 19:26:05 +00:00
if( newList.GetCount() )
SaveCopyInUndoList( newList, UR_NEW );
Compile_Ratsnest( NULL, true );
DrawPanel->Refresh( true );
2007-05-06 16:03:28 +00:00
}