kicad/pcbnew/editedge.cpp

333 lines
9.1 KiB
C++
Raw Normal View History

/***********************************/
/* Edit segments and edges of PCB. */
/***********************************/
2007-05-06 16:03:28 +00:00
#include "fctsys.h"
#include "class_drawpanel.h"
#include "confirm.h"
2009-07-30 11:04:07 +00:00
#include "wxPcbStruct.h"
#include "gr_basic.h"
#include "pcbcommon.h"
2009-07-30 11:04:07 +00:00
#include "pcbnew.h"
2007-05-06 16:03:28 +00:00
#include "protos.h"
#include "class_board.h"
#include "class_drawsegment.h"
static void Abort_EditEdge( EDA_DRAW_PANEL* Panel, wxDC* DC );
static void DrawSegment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase );
static void Move_Segment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase );
2007-05-06 16:03:28 +00:00
static wxPoint s_InitialPosition; // Initial cursor position.
static wxPoint s_LastPosition; // Current cursor position.
/* Start move of a graphic element type DRAWSEGMENT */
void PCB_EDIT_FRAME::Start_Move_DrawItem( DRAWSEGMENT* drawitem, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
if( drawitem == NULL )
return;
2008-04-01 06:32:48 +00:00
drawitem->Draw( DrawPanel, DC, GR_XOR );
drawitem->m_Flags |= IS_MOVED;
s_InitialPosition = s_LastPosition = GetScreen()->GetCrossHairPosition();
drawitem->DisplayInfo( this );
DrawPanel->SetMouseCapture( Move_Segment, Abort_EditEdge );
SetCurItem( drawitem );
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
2007-05-06 16:03:28 +00:00
}
2007-05-06 16:03:28 +00:00
/*
* Place graphic element of type DRAWSEGMENT.
*/
void PCB_EDIT_FRAME::Place_DrawItem( DRAWSEGMENT* drawitem, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
if( drawitem == NULL )
return;
drawitem->m_Flags = 0;
2009-08-06 15:42:09 +00:00
SaveCopyInUndoList(drawitem, UR_MOVED, s_LastPosition - s_InitialPosition);
2008-04-01 06:32:48 +00:00
drawitem->Draw( DrawPanel, DC, GR_OR );
DrawPanel->SetMouseCapture( NULL, NULL );
SetCurItem( NULL );
OnModify();
2007-05-06 16:03:28 +00:00
}
/*
* Redraw segment during cursor movement.
*/
static void Move_Segment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase )
2007-05-06 16:03:28 +00:00
{
2011-12-14 04:29:25 +00:00
DRAWSEGMENT* segment = (DRAWSEGMENT*) aPanel->GetScreen()->GetCurItem();
2011-12-14 04:29:25 +00:00
if( segment == NULL )
return;
if( aErase )
2011-12-14 04:29:25 +00:00
segment->Draw( aPanel, aDC, GR_XOR );
wxPoint delta;
delta = aPanel->GetScreen()->GetCrossHairPosition() - s_LastPosition;
2011-12-14 04:29:25 +00:00
segment->SetStart( segment->GetStart() + delta );
segment->SetEnd( segment->GetEnd() + delta );
s_LastPosition = aPanel->GetScreen()->GetCrossHairPosition();
2011-12-14 04:29:25 +00:00
segment->Draw( aPanel, aDC, GR_XOR );
2007-05-06 16:03:28 +00:00
}
void PCB_EDIT_FRAME::Delete_Segment_Edge( DRAWSEGMENT* Segment, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
EDA_ITEM* PtStruct;
int track_fill_copy = DisplayOpt.DisplayDrawItems;
if( Segment == NULL )
return;
if( Segment->IsNew() ) // Trace in progress.
{
/* Delete current segment. */
DisplayOpt.DisplayDrawItems = SKETCH;
2008-04-01 06:32:48 +00:00
Segment->Draw( DrawPanel, DC, GR_XOR );
PtStruct = Segment->Back();
Segment ->DeleteStructure();
if( PtStruct && (PtStruct->Type() == PCB_LINE_T ) )
Segment = (DRAWSEGMENT*) PtStruct;
DisplayOpt.DisplayDrawItems = track_fill_copy;
SetCurItem( NULL );
}
else if( Segment->m_Flags == 0 )
{
2008-04-01 06:32:48 +00:00
Segment->Draw( DrawPanel, DC, GR_XOR );
Segment->m_Flags = 0;
SaveCopyInUndoList(Segment, UR_DELETED);
Segment->UnLink();
SetCurItem( NULL );
OnModify();
}
2007-05-06 16:03:28 +00:00
}
void PCB_EDIT_FRAME::Delete_Drawings_All_Layer( int aLayer )
2007-05-06 16:03:28 +00:00
{
2009-08-11 10:27:21 +00:00
if( aLayer <= LAST_COPPER_LAYER )
{
DisplayError( this, _( "Copper layer global delete not allowed!" ) );
return;
}
2009-08-11 10:27:21 +00:00
wxString msg = _( "Delete Layer " ) + GetBoard()->GetLayerName( aLayer );
if( !IsOK( this, msg ) )
return;
2009-08-06 15:42:09 +00:00
PICKED_ITEMS_LIST pickList;
ITEM_PICKER picker(NULL, UR_DELETED);
2009-08-11 10:27:21 +00:00
2008-04-01 05:21:50 +00:00
BOARD_ITEM* PtNext;
for( BOARD_ITEM* item = GetBoard()->m_Drawings; item; item = PtNext )
{
2008-04-01 05:21:50 +00:00
PtNext = item->Next();
2008-04-01 05:21:50 +00:00
switch( item->Type() )
{
case PCB_LINE_T:
case PCB_TEXT_T:
case PCB_DIMENSION_T:
case PCB_TARGET_T:
2009-08-11 10:27:21 +00:00
if( item->GetLayer() == aLayer )
{
2009-08-06 15:42:09 +00:00
item->UnLink();
picker.m_PickedItem = item;
pickList.PushItem( picker );
}
break;
default:
2009-08-11 10:27:21 +00:00
{
wxString msg;
msg.Printf( wxT("Delete_Drawings_All_Layer() error: unknown type %d"),
item->Type() );
2009-08-11 10:27:21 +00:00
wxMessageBox( msg );
break;
}
2009-08-11 10:27:21 +00:00
}
}
2009-08-06 15:42:09 +00:00
if( pickList.GetCount() )
{
OnModify();
2009-08-11 10:27:21 +00:00
SaveCopyInUndoList(pickList, UR_DELETED);
2009-08-06 15:42:09 +00:00
}
2007-05-06 16:03:28 +00:00
}
static void Abort_EditEdge( EDA_DRAW_PANEL* Panel, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
DRAWSEGMENT* Segment = (DRAWSEGMENT*) Panel->GetScreen()->GetCurItem();
if( Segment == NULL )
{
Panel->SetMouseCapture( NULL, NULL );
return;
}
if( Segment->IsNew() )
{
Panel->m_mouseCaptureCallback( Panel, DC, wxDefaultPosition, false );
Segment ->DeleteStructure();
Segment = NULL;
}
else
{
wxPoint pos = Panel->GetScreen()->GetCrossHairPosition();
Panel->GetScreen()->SetCrossHairPosition( s_InitialPosition );
Panel->m_mouseCaptureCallback( Panel, DC, wxDefaultPosition, true );
Panel->GetScreen()->SetCrossHairPosition( pos );
Segment->m_Flags = 0;
2008-04-01 06:32:48 +00:00
Segment->Draw( Panel, DC, GR_OR );
}
Panel->SetMouseCapture( NULL, NULL );
( (PCB_EDIT_FRAME*) Panel->GetParent() )->SetCurItem( NULL );
2007-05-06 16:03:28 +00:00
}
/* Initialize the drawing of a segment of type other than trace.
*/
DRAWSEGMENT* PCB_EDIT_FRAME::Begin_DrawSegment( DRAWSEGMENT* Segment, int shape, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
int s_large;
DRAWSEGMENT* DrawItem;
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
s_large = GetBoard()->GetDesignSettings().m_DrawSegmentWidth;
if( getActiveLayer() == EDGE_N )
{
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
s_large = GetBoard()->GetDesignSettings().m_EdgeSegmentWidth;
}
if( Segment == NULL ) /* Create new trace. */
{
SetCurItem( Segment = new DRAWSEGMENT( GetBoard() ) );
Segment->m_Flags = IS_NEW;
Segment->SetLayer( getActiveLayer() );
2011-12-14 04:29:25 +00:00
Segment->SetWidth( s_large );
Segment->SetShape( shape );
Segment->SetAngle( 900 );
Segment->SetStart( GetScreen()->GetCrossHairPosition() );
Segment->SetEnd( GetScreen()->GetCrossHairPosition() );
DrawPanel->SetMouseCapture( DrawSegment, Abort_EditEdge );
}
2009-11-15 14:12:53 +00:00
else /* The ending point ccordinate Segment->m_End was updated by he function
* DrawSegment() called on a move mouse event
2009-11-15 14:12:53 +00:00
* during the segment creation
*/
{
2011-12-14 04:29:25 +00:00
if( Segment->GetStart() != Segment->GetEnd() )
{
2011-12-14 04:29:25 +00:00
if( Segment->GetShape() == S_SEGMENT )
{
2011-12-14 04:29:25 +00:00
SaveCopyInUndoList( Segment, UR_NEW );
GetBoard()->Add( Segment );
OnModify();
Segment->m_Flags = 0;
2008-04-01 06:32:48 +00:00
Segment->Draw( DrawPanel, DC, GR_OR );
DrawItem = Segment;
SetCurItem( Segment = new DRAWSEGMENT( GetBoard() ) );
Segment->m_Flags = IS_NEW;
2007-08-23 04:28:46 +00:00
Segment->SetLayer( DrawItem->GetLayer() );
2011-12-14 04:29:25 +00:00
Segment->SetWidth( s_large );
Segment->SetShape( DrawItem->GetShape() );
Segment->SetType( DrawItem->GetType() );
Segment->SetAngle( DrawItem->GetAngle() );
Segment->SetStart( DrawItem->GetEnd() );
Segment->SetEnd( DrawItem->GetEnd() );
DrawSegment( DrawPanel, DC, wxDefaultPosition, false );
}
else
{
End_Edge( Segment, DC );
Segment = NULL;
}
}
}
return Segment;
2007-05-06 16:03:28 +00:00
}
void PCB_EDIT_FRAME::End_Edge( DRAWSEGMENT* Segment, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
if( Segment == NULL )
return;
2008-04-01 06:32:48 +00:00
Segment->Draw( DrawPanel, DC, GR_OR );
2011-12-14 04:29:25 +00:00
// Delete if segment length is zero.
if( Segment->GetStart() == Segment->GetEnd() )
{
2011-12-14 04:29:25 +00:00
Segment->DeleteStructure();
}
else
{
Segment->m_Flags = 0;
GetBoard()->Add( Segment );
OnModify();
SaveCopyInUndoList( Segment, UR_NEW );
}
DrawPanel->SetMouseCapture( NULL, NULL );
SetCurItem( NULL );
2007-05-06 16:03:28 +00:00
}
/* Redraw segment during cursor movement
*/
static void DrawSegment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase )
2007-05-06 16:03:28 +00:00
{
DRAWSEGMENT* Segment = (DRAWSEGMENT*) aPanel->GetScreen()->GetCurItem();
int t_fill = DisplayOpt.DisplayDrawItems;
if( Segment == NULL )
return;
DisplayOpt.DisplayDrawItems = SKETCH;
if( aErase )
Segment->Draw( aPanel, aDC, GR_XOR );
2011-12-14 04:29:25 +00:00
if( Segments_45_Only && Segment->GetShape() == S_SEGMENT )
{
2011-12-14 04:29:25 +00:00
wxPoint pt;
CalculateSegmentEndPoint( aPanel->GetScreen()->GetCrossHairPosition(),
2011-12-14 04:29:25 +00:00
Segment->GetStart().x, Segment->GetStart().y,
&pt.x, &pt.y );
Segment->SetEnd( pt );
}
2011-12-14 04:29:25 +00:00
else // here the angle is arbitrary
{
2011-12-14 04:29:25 +00:00
Segment->SetEnd( aPanel->GetScreen()->GetCrossHairPosition() );
}
Segment->Draw( aPanel, aDC, GR_XOR );
DisplayOpt.DisplayDrawItems = t_fill;
2007-05-06 16:03:28 +00:00
}