kicad/pcbnew/block.cpp

878 lines
25 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 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
*/
/**
* @file pcbnew/block.cpp
*/
2007-05-06 16:03:28 +00:00
#include <fctsys.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <block_commande.h>
#include <pcbcommon.h>
#include <wxPcbStruct.h>
#include <trigo.h>
2007-05-06 16:03:28 +00:00
#include <class_board.h>
#include <class_track.h>
#include <class_drawsegment.h>
#include <class_pcb_text.h>
#include <class_mire.h>
#include <class_module.h>
#include <class_dimension.h>
#include <class_zone.h>
#include <dialog_block_options_base.h>
#include <pcbnew.h>
#include <protos.h>
2007-05-06 16:03:28 +00:00
#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 );
2011-11-26 20:02:59 +00:00
void OnCancel( wxCommandEvent& event )
{
EndModal( wxID_CANCEL );
}
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
{
wxPoint oldpos = parent->GetCrossHairPosition();
2007-05-06 16:03:28 +00:00
parent->GetCanvas()->SetIgnoreMouseEvents( true );
2011-11-26 20:02:59 +00:00
DIALOG_BLOCK_OPTIONS * dlg = new DIALOG_BLOCK_OPTIONS( parent, title );
2008-04-01 05:21:50 +00:00
2011-11-26 20:02:59 +00:00
int cmd = dlg->ShowModal();
dlg->Destroy();
2008-04-01 05:21:50 +00:00
parent->SetCrossHairPosition( oldpos );
parent->GetCanvas()->MoveCursorToCrossHair();
parent->GetCanvas()->SetIgnoreMouseEvents( false );
2007-05-06 16:03:28 +00:00
2011-11-26 20:02:59 +00:00
return cmd == wxID_OK;
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();
2011-11-26 20:02:59 +00:00
EndModal( wxID_OK );
2007-05-06 16:03:28 +00:00
}
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
int PCB_EDIT_FRAME::BlockCommand( 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
}
void PCB_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
2007-05-06 16:03:28 +00:00
{
if( !m_canvas->IsMouseCaptured() )
{
DisplayError( this, wxT( "Error in HandleBlockPLace : m_mouseCaptureCallback = NULL" ) );
}
GetScreen()->m_BlockLocate.SetState( STATE_BLOCK_STOP );
switch( GetScreen()->m_BlockLocate.GetCommand() )
{
2009-08-01 19:26:05 +00:00
case BLOCK_IDLE:
break;
case BLOCK_DRAG: // Drag
case BLOCK_MOVE: // Move
case BLOCK_PRESELECT_MOVE: // Move with preselection list
if( m_canvas->IsMouseCaptured() )
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
2009-08-01 19:26:05 +00:00
Block_Move();
GetScreen()->m_BlockLocate.ClearItemsList();
break;
case BLOCK_COPY: // Copy
if( m_canvas->IsMouseCaptured() )
m_canvas->CallMouseCapture( 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();
m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, false );
GetScreen()->ClearBlockCommand();
if( GetScreen()->m_BlockLocate.GetCount() )
{
DisplayError( this, wxT( "Error in HandleBlockPLace some items left in list" ) );
GetScreen()->m_BlockLocate.ClearItemsList();
}
2007-05-06 16:03:28 +00:00
}
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.GetState() == STATE_NO_BLOCK )
{
m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString,
false );
GetScreen()->ClearBlockCommand();
return false;
}
// Show dialog if there are no selected items and we're not zooming
if( !GetScreen()->m_BlockLocate.GetCount()
&& GetScreen()->m_BlockLocate.GetCommand() != BLOCK_ZOOM )
{
2011-11-26 20:02:59 +00:00
if( InstallBlockCmdFrame( this, _( "Block Operation" ) ) == false )
{
cancelCmd = true;
// undraw block outline
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
}
else
{
DrawAndSizingBlockOutlines( m_canvas, 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 && m_canvas->IsMouseCaptured() )
{
switch( GetScreen()->m_BlockLocate.GetCommand() )
{
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.SetState( STATE_BLOCK_MOVE );
nextcmd = true;
m_canvas->SetMouseCaptureCallback( drawMovingBlock );
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
break;
case BLOCK_DELETE: // Delete
m_canvas->SetMouseCaptureCallback( NULL );
GetScreen()->m_BlockLocate.SetState( STATE_BLOCK_STOP );
2009-08-01 19:26:05 +00:00
Block_Delete();
break;
case BLOCK_ROTATE: // Rotation
m_canvas->SetMouseCaptureCallback( NULL );
GetScreen()->m_BlockLocate.SetState( STATE_BLOCK_STOP );
2009-08-01 19:26:05 +00:00
Block_Rotate();
break;
case BLOCK_FLIP: // Flip
m_canvas->SetMouseCaptureCallback( NULL );
GetScreen()->m_BlockLocate.SetState( 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.SetState( 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
m_canvas->SetMouseCaptureCallback( NULL );
Window_Zoom( GetScreen()->m_BlockLocate );
break;
default:
break;
}
}
if( ! nextcmd )
{
GetScreen()->ClearBlockCommand();
m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString,
false );
}
return nextcmd;
2007-05-06 16:03:28 +00:00
}
void PCB_EDIT_FRAME::Block_SelectItems()
2007-05-06 16:03:28 +00:00
{
LAYER_MSK layerMask;
bool selectOnlyComplete = GetScreen()->m_BlockLocate.GetWidth() > 0 ;
GetScreen()->m_BlockLocate.Normalize();
PICKED_ITEMS_LIST* itemsList = &GetScreen()->m_BlockLocate.GetItems();
2009-08-01 19:26:05 +00:00
ITEM_PICKER picker( NULL, UR_UNSPECIFIED );
// Add modules
if( blockIncludeModules )
{
for( MODULE* module = m_Pcb->m_Modules; module != NULL; module = module->Next() )
{
LAYER_NUM layer = module->GetLayer();
if( module->HitTest( GetScreen()->m_BlockLocate, selectOnlyComplete )
&& ( !module->IsLocked() || blockIncludeLockedModules ) )
2008-04-01 05:21:50 +00:00
{
if( blockIncludeItemsOnInvisibleLayers || m_Pcb->IsModuleLayerVisible( layer ) )
{
2012-02-05 13:02:46 +00:00
picker.SetItem ( module );
itemsList->PushItem( picker );
}
2008-04-01 05:21:50 +00:00
}
}
}
// Add tracks and vias
if( blockIncludeTracks )
{
for( TRACK* track = m_Pcb->m_Track; track != NULL; track = track->Next() )
{
if( track->HitTest( GetScreen()->m_BlockLocate, selectOnlyComplete ) )
2008-04-01 05:21:50 +00:00
{
if( blockIncludeItemsOnInvisibleLayers
|| m_Pcb->IsLayerVisible( track->GetLayer() ) )
{
picker.SetItem ( track );
itemsList->PushItem( picker );
}
}
}
}
// Add graphic items
layerMask = EDGE_LAYER;
if( blockIncludeItemsOnTechLayers )
layerMask = ALL_LAYERS;
2008-04-01 05:21:50 +00:00
if( !blockIncludeBoardOutlineLayer )
layerMask &= ~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 PCB_LINE_T:
if( (GetLayerMask( PtStruct->GetLayer() ) & layerMask) == 0 )
break;
if( !PtStruct->HitTest( GetScreen()->m_BlockLocate, selectOnlyComplete ) )
break;
2009-08-01 19:26:05 +00:00
select_me = true; // This item is in bloc: select it
break;
case PCB_TEXT_T:
if( !blockIncludePcbTexts )
break;
if( !PtStruct->HitTest( GetScreen()->m_BlockLocate, selectOnlyComplete ) )
break;
2009-08-01 19:26:05 +00:00
select_me = true; // This item is in bloc: select it
break;
case PCB_TARGET_T:
if( ( GetLayerMask( PtStruct->GetLayer() ) & layerMask ) == 0 )
break;
if( !PtStruct->HitTest( GetScreen()->m_BlockLocate, selectOnlyComplete ) )
break;
2009-08-01 19:26:05 +00:00
select_me = true; // This item is in bloc: select it
break;
case PCB_DIMENSION_T:
if( ( GetLayerMask( PtStruct->GetLayer() ) & layerMask ) == 0 )
break;
if( !PtStruct->HitTest( GetScreen()->m_BlockLocate, selectOnlyComplete ) )
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 )
{
2012-02-05 13:02:46 +00:00
picker.SetItem ( PtStruct );
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, selectOnlyComplete ) )
2008-04-01 05:21:50 +00:00
{
if( blockIncludeItemsOnInvisibleLayers
|| m_Pcb->IsLayerVisible( area->GetLayer() ) )
{
BOARD_ITEM* zone_c = (BOARD_ITEM*) area;
2012-02-05 13:02:46 +00:00
picker.SetItem ( zone_c );
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.GetItems();
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 PCB_MODULE_T:
frame->GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
DrawModuleOutlines( aPanel, aDC, (MODULE*) item );
break;
case PCB_LINE_T:
case PCB_TEXT_T:
case PCB_TRACE_T:
case PCB_VIA_T:
case PCB_TARGET_T:
case PCB_DIMENSION_T: // Currently markers are not affected by block commands
case PCB_MARKER_T:
item->Draw( aPanel, aDC, GR_XOR, aOffset );
break;
case PCB_ZONE_AREA_T:
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.GetMoveVector().x || screen->m_BlockLocate.GetMoveVector().y )
{
screen->m_BlockLocate.Draw( aPanel, aDC, screen->m_BlockLocate.GetMoveVector(),
GR_XOR, BLOCK_OUTLINE_COLOR );
if( blockDrawItems )
drawPickedItems( aPanel, aDC, screen->m_BlockLocate.GetMoveVector() );
}
}
if( screen->m_BlockLocate.GetState() != STATE_BLOCK_STOP )
{
screen->m_BlockLocate.SetMoveVector( aPanel->GetParent()->GetCrossHairPosition() -
screen->m_BlockLocate.GetLastCursorPosition() );
}
if( screen->m_BlockLocate.GetMoveVector().x || screen->m_BlockLocate.GetMoveVector().y )
{
screen->m_BlockLocate.Draw( aPanel, aDC, screen->m_BlockLocate.GetMoveVector(),
GR_XOR, BLOCK_OUTLINE_COLOR );
if( blockDrawItems )
drawPickedItems( aPanel, aDC, screen->m_BlockLocate.GetMoveVector() );
}
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.GetItems();
2009-08-01 19:26:05 +00:00
itemsList->m_Status = UR_DELETED;
// unlink items and clear flags
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_DELETED, ii );
2009-08-01 19:26:05 +00:00
switch( item->Type() )
{
case PCB_MODULE_T:
2009-08-01 19:26:05 +00:00
{
MODULE* module = (MODULE*) item;
module->ClearFlags();
2009-08-01 19:26:05 +00:00
module->UnLink();
m_Pcb->m_Status_Pcb = 0;
}
break;
case PCB_ZONE_AREA_T: // a zone area
2009-08-01 19:26:05 +00:00
m_Pcb->Remove( item );
break;
case PCB_LINE_T: // a segment not on copper layers
case PCB_TEXT_T: // a text on a layer
case PCB_TRACE_T: // a track segment (segment on a copper layer)
case PCB_VIA_T: // a via (like track segment on a copper layer)
case PCB_DIMENSION_T: // a dimension (graphic item)
case PCB_TARGET_T: // 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 PCB_MARKER_T: // a marker used to show something
case PCB_ZONE_T: // 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 );
m_canvas->Refresh( true );
2007-05-06 16:03:28 +00:00
}
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 = m_rotationAngle; // rotation angle in 0.1 deg.
oldpos = GetCrossHairPosition();
centre = GetScreen()->m_BlockLocate.Centre();
OnModify();
PICKED_ITEMS_LIST* itemsList = &GetScreen()->m_BlockLocate.GetItems();
itemsList->m_Status = UR_CHANGED;
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 );
wxASSERT( item );
itemsList->SetPickedItemStatus( UR_CHANGED, ii );
2009-08-01 19:26:05 +00:00
switch( item->Type() )
{
case PCB_MODULE_T:
( (MODULE*) item )->ClearFlags();
m_Pcb->m_Status_Pcb = 0;
break;
2009-08-01 19:26:05 +00:00
// Move and rotate the track segments
case PCB_TRACE_T: // a track segment (segment on a copper layer)
case PCB_VIA_T: // a via (like track segment on a copper layer)
2009-08-01 19:26:05 +00:00
m_Pcb->m_Status_Pcb = 0;
break;
case PCB_ZONE_AREA_T:
case PCB_LINE_T:
case PCB_TEXT_T:
case PCB_TARGET_T:
case PCB_DIMENSION_T:
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 PCB_ZONE_T: // 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;
}
}
// Save all the block items in there current state before applying the rotation.
SaveCopyInUndoList( *itemsList, UR_CHANGED, centre );
// Now perform the rotation.
for( unsigned ii = 0; ii < itemsList->GetCount(); ii++ )
{
BOARD_ITEM* item = (BOARD_ITEM*) itemsList->GetPickedItem( ii );
wxASSERT( item );
item->Rotate( centre, rotAngle );
}
Compile_Ratsnest( NULL, true );
m_canvas->Refresh( true );
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.GetItems();
2009-08-01 19:26:05 +00:00
itemsList->m_Status = UR_FLIPPED;
memo = 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() )
{
case PCB_MODULE_T:
item->ClearFlags();
2009-08-01 19:26:05 +00:00
m_Pcb->m_Status_Pcb = 0;
break;
// Move and rotate the track segments
case PCB_TRACE_T: // a track segment (segment on a copper layer)
case PCB_VIA_T: // a via (like track segment on a copper layer)
2009-08-01 19:26:05 +00:00
m_Pcb->m_Status_Pcb = 0;
break;
case PCB_ZONE_AREA_T:
case PCB_LINE_T:
case PCB_TEXT_T:
case PCB_TARGET_T:
case PCB_DIMENSION_T:
break;
2009-08-06 15:42:09 +00:00
// This item is not put in undo list
case PCB_ZONE_T: // 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 );
m_canvas->Refresh( true );
2007-05-06 16:03:28 +00:00
}
void PCB_EDIT_FRAME::Block_Move()
2007-05-06 16:03:28 +00:00
{
OnModify();
wxPoint MoveVector = GetScreen()->m_BlockLocate.GetMoveVector();
PICKED_ITEMS_LIST* itemsList = &GetScreen()->m_BlockLocate.GetItems();
2009-08-01 19:26:05 +00:00
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
{
case PCB_MODULE_T:
m_Pcb->m_Status_Pcb = 0;
item->ClearFlags();
break;
// Move track segments
case PCB_TRACE_T: // a track segment (segment on a copper layer)
case PCB_VIA_T: // 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;
case PCB_ZONE_AREA_T:
case PCB_LINE_T:
case PCB_TEXT_T:
case PCB_TARGET_T:
case PCB_DIMENSION_T:
break;
2009-08-06 15:42:09 +00:00
// This item is not put in undo list
case PCB_ZONE_T: // 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 );
m_canvas->Refresh( true );
2007-05-06 16:03:28 +00:00
}
void PCB_EDIT_FRAME::Block_Duplicate()
2007-05-06 16:03:28 +00:00
{
wxPoint MoveVector = GetScreen()->m_BlockLocate.GetMoveVector();
OnModify();
PICKED_ITEMS_LIST* itemsList = &GetScreen()->m_BlockLocate.GetItems();
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 = (BOARD_ITEM*)item->Clone();
if( item->Type() == PCB_MODULE_T )
m_Pcb->m_Status_Pcb = 0;
m_Pcb->Add( newitem );
2009-08-01 19:26:05 +00:00
2010-11-12 17:33:20 +00:00
if( newitem )
{
newitem->Move( MoveVector );
2012-02-05 13:02:46 +00:00
picker.SetItem ( newitem );
newList.PushItem( picker );
}
}
2009-08-01 19:26:05 +00:00
if( newList.GetCount() )
SaveCopyInUndoList( newList, UR_NEW );
Compile_Ratsnest( NULL, true );
m_canvas->Refresh( true );
2007-05-06 16:03:28 +00:00
}