kicad/pcbnew/mirepcb.cpp

295 lines
8.6 KiB
C++
Raw Normal View History

/********************************************/
/* Functions to edit targets (class MIRE) */
/********************************************/
2007-05-06 16:03:28 +00:00
#include "fctsys.h"
#include "common.h"
#include "class_drawpanel.h"
2007-05-06 16:03:28 +00:00
#include "pcbnew.h"
2009-07-30 11:04:07 +00:00
#include "wxPcbStruct.h"
2009-10-28 11:48:47 +00:00
#include "class_board_design_settings.h"
2010-11-18 21:16:28 +00:00
#include "dialog_helpers.h"
2007-05-06 16:03:28 +00:00
2009-08-03 07:55:08 +00:00
#include "protos.h"
2007-05-06 16:03:28 +00:00
/* Routines Locales */
static void AbortMoveAndEditTarget( EDA_DRAW_PANEL* Panel, wxDC* DC );
static void ShowTargetShapeWhileMovingMouse( EDA_DRAW_PANEL* aPanel,
wxDC* aDC,
const wxPoint& aPosition,
bool aErase );
2007-05-06 16:03:28 +00:00
2009-08-03 07:55:08 +00:00
/* Local variables : */
static int MireDefaultSize = 5000;
static MIREPCB s_TargetCopy( NULL ); /* Used to store "old" values of the
* current item parameters before
* edition (used in undo/redo or
* cancel operations)
2009-08-03 07:55:08 +00:00
*/
2007-05-06 16:03:28 +00:00
/************************************/
/* class TARGET_PROPERTIES_DIALOG_EDITOR */
/************************************/
2007-05-06 16:03:28 +00:00
class TARGET_PROPERTIES_DIALOG_EDITOR : public wxDialog
2007-05-06 16:03:28 +00:00
{
private:
PCB_EDIT_FRAME* m_Parent;
wxDC* m_DC;
MIREPCB* m_MirePcb;
WinEDA_ValueCtrl* m_MireWidthCtrl;
WinEDA_ValueCtrl* m_MireSizeCtrl;
wxRadioBox* m_MireShape;
2007-05-06 16:03:28 +00:00
public:
TARGET_PROPERTIES_DIALOG_EDITOR( PCB_EDIT_FRAME* parent, MIREPCB* Mire, wxDC* DC );
~TARGET_PROPERTIES_DIALOG_EDITOR() { }
2007-05-06 16:03:28 +00:00
private:
2009-08-03 07:55:08 +00:00
void OnOkClick( wxCommandEvent& event );
void OnCancelClick( wxCommandEvent& event );
2007-05-06 16:03:28 +00:00
DECLARE_EVENT_TABLE()
2007-05-06 16:03:28 +00:00
};
BEGIN_EVENT_TABLE( TARGET_PROPERTIES_DIALOG_EDITOR, wxDialog )
EVT_BUTTON( wxID_OK, TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick )
EVT_BUTTON( wxID_CANCEL, TARGET_PROPERTIES_DIALOG_EDITOR::OnCancelClick )
2007-05-06 16:03:28 +00:00
END_EVENT_TABLE()
void PCB_EDIT_FRAME::InstallMireOptionsFrame( MIREPCB* MirePcb, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
TARGET_PROPERTIES_DIALOG_EDITOR* frame =
new TARGET_PROPERTIES_DIALOG_EDITOR( this, MirePcb, DC );
frame->ShowModal();
frame->Destroy();
2007-05-06 16:03:28 +00:00
}
TARGET_PROPERTIES_DIALOG_EDITOR::TARGET_PROPERTIES_DIALOG_EDITOR(
PCB_EDIT_FRAME* parent,
MIREPCB* Mire, wxDC* DC ) :
wxDialog( parent, wxID_ANY, wxString( _( "Target Properties" ) ) )
2007-05-06 16:03:28 +00:00
{
wxString number;
wxButton* Button;
m_Parent = parent;
2009-08-03 07:55:08 +00:00
m_DC = DC;
Centre();
m_MirePcb = Mire;
wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
SetSizer( MainBoxSizer );
wxBoxSizer* LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* RightBoxSizer = new wxBoxSizer( wxVERTICAL );
MainBoxSizer->Add( LeftBoxSizer, 0, wxGROW | wxALL, 5 );
MainBoxSizer->Add( RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
/* Create of the command buttons. */
Button = new wxButton( this, wxID_OK, _( "OK" ) );
RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
// Size:
m_MireSizeCtrl = new WinEDA_ValueCtrl( this, _( "Size" ),
m_MirePcb->m_Size,
g_UserUnit, LeftBoxSizer,
m_Parent->m_InternalUnits );
// Width:
m_MireWidthCtrl = new WinEDA_ValueCtrl( this, _( "Width" ),
m_MirePcb->m_Width,
g_UserUnit, LeftBoxSizer,
m_Parent->m_InternalUnits );
// Shape
wxString shape_list[2] = { _( "shape +" ), _( "shape X" ) };
2009-10-28 11:48:47 +00:00
m_MireShape = new wxRadioBox( this, wxID_ANY,
2007-10-10 14:08:26 +00:00
_( "Target Shape:" ),
wxDefaultPosition, wxSize( -1, -1 ),
2, shape_list, 1 );
m_MireShape->SetSelection( m_MirePcb->m_Shape ? 1 : 0 );
LeftBoxSizer->Add( m_MireShape, 0, wxGROW | wxALL, 5 );
GetSizer()->Fit( this );
GetSizer()->SetSizeHints( this );
2007-05-06 16:03:28 +00:00
}
void TARGET_PROPERTIES_DIALOG_EDITOR::OnCancelClick( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
{
EndModal( -1 );
2007-05-06 16:03:28 +00:00
}
/* Updates the different parameters for the component being edited
*/
void TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
{
2008-04-01 05:21:50 +00:00
m_MirePcb->Draw( m_Parent->DrawPanel, m_DC, GR_XOR );
2007-05-06 16:03:28 +00:00
// Save old item in undo list, if is is not currently edited (will be later
// if so)
2009-08-03 07:55:08 +00:00
if( m_MirePcb->m_Flags == 0 )
m_Parent->SaveCopyInUndoList( m_MirePcb, UR_CHANGED );
if( m_MirePcb->m_Flags != 0 ) // other edition in progress (MOVE,
// NEW ..)
m_MirePcb->m_Flags |= IN_EDIT; // set flag in edit to force
// undo/redo/abort proper operation
2009-08-03 07:55:08 +00:00
m_MirePcb->m_Width = m_MireWidthCtrl->GetValue();
MireDefaultSize = m_MirePcb->m_Size = m_MireSizeCtrl->GetValue();
m_MirePcb->m_Shape = m_MireShape->GetSelection() ? 1 : 0;
2007-05-06 16:03:28 +00:00
m_MirePcb->Draw( m_Parent->DrawPanel, m_DC,
( m_MirePcb->m_Flags & IS_MOVED ) ? GR_XOR : GR_OR );
2007-05-06 16:03:28 +00:00
m_Parent->OnModify();
EndModal( 1 );
2007-05-06 16:03:28 +00:00
}
void PCB_EDIT_FRAME::Delete_Mire( MIREPCB* MirePcb, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
if( MirePcb == NULL )
return;
2007-05-06 16:03:28 +00:00
2008-04-01 05:21:50 +00:00
MirePcb->Draw( DrawPanel, DC, GR_XOR );
2009-08-03 07:55:08 +00:00
SaveCopyInUndoList( MirePcb, UR_DELETED );
MirePcb->UnLink();
2007-05-06 16:03:28 +00:00
}
static void AbortMoveAndEditTarget( EDA_DRAW_PANEL* Panel, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
BASE_SCREEN* screen = Panel->GetScreen();
MIREPCB* MirePcb = (MIREPCB*) screen->GetCurItem();
( (PCB_EDIT_FRAME*) Panel->GetParent() )->SetCurItem( NULL );
2009-08-03 07:55:08 +00:00
Panel->SetMouseCapture( NULL, NULL );
2009-08-03 07:55:08 +00:00
if( MirePcb == NULL )
return;
MirePcb->Draw( Panel, DC, GR_XOR );
if( MirePcb->IsNew() ) // If it is new, delete it
{
2008-04-01 05:21:50 +00:00
MirePcb->Draw( Panel, DC, GR_XOR );
2009-08-03 07:55:08 +00:00
MirePcb->DeleteStructure();
MirePcb = NULL;
}
else /* it is an existing item: retrieve initial values of parameters */
{
if( ( MirePcb->m_Flags & (IN_EDIT | IS_MOVED) ) )
{
MirePcb->m_Pos = s_TargetCopy.m_Pos;
2009-08-03 07:55:08 +00:00
MirePcb->m_Width = s_TargetCopy.m_Width;
MirePcb->m_Size = s_TargetCopy.m_Size;
MirePcb->m_Shape = s_TargetCopy.m_Shape;
}
2009-08-03 07:55:08 +00:00
MirePcb->m_Flags = 0;
MirePcb->Draw( Panel, DC, GR_OR );
}
2007-05-06 16:03:28 +00:00
}
/* Draw Symbol PCB type MIRE.
*/
MIREPCB* PCB_EDIT_FRAME::Create_Mire( wxDC* DC )
2007-05-06 16:03:28 +00:00
{
MIREPCB* MirePcb = new MIREPCB( GetBoard() );
2007-05-06 16:03:28 +00:00
2009-08-03 07:55:08 +00:00
MirePcb->m_Flags = IS_NEW;
GetBoard()->Add( MirePcb );
2007-05-06 16:03:28 +00:00
2007-08-23 04:28:46 +00:00
MirePcb->SetLayer( EDGE_N );
MirePcb->m_Width = GetBoard()->GetBoardDesignSettings()->m_EdgeSegmentWidth;
MirePcb->m_Size = MireDefaultSize;
MirePcb->m_Pos = DrawPanel->GetScreen()->GetCrossHairPosition();
2007-05-06 16:03:28 +00:00
Place_Mire( MirePcb, DC );
2007-05-06 16:03:28 +00:00
return MirePcb;
2007-05-06 16:03:28 +00:00
}
/* Routine to initialize the displacement of a focal
*/
void PCB_EDIT_FRAME::StartMove_Mire( MIREPCB* MirePcb, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
if( MirePcb == NULL )
return;
s_TargetCopy = *MirePcb;
MirePcb->m_Flags |= IS_MOVED;
DrawPanel->SetMouseCapture( ShowTargetShapeWhileMovingMouse, AbortMoveAndEditTarget );
SetCurItem( MirePcb );
2007-05-06 16:03:28 +00:00
}
void PCB_EDIT_FRAME::Place_Mire( MIREPCB* MirePcb, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
if( MirePcb == NULL )
return;
2007-05-06 16:03:28 +00:00
2008-04-01 05:21:50 +00:00
MirePcb->Draw( DrawPanel, DC, GR_OR );
DrawPanel->SetMouseCapture( NULL, NULL );
SetCurItem( NULL );
OnModify();
2009-08-03 07:55:08 +00:00
if( MirePcb->IsNew() )
2009-08-03 07:55:08 +00:00
{
SaveCopyInUndoList( MirePcb, UR_NEW );
MirePcb->m_Flags = 0;
return;
}
if( MirePcb->m_Flags == IS_MOVED )
{
SaveCopyInUndoList( MirePcb, UR_MOVED, MirePcb->m_Pos - s_TargetCopy.m_Pos );
2009-08-03 07:55:08 +00:00
MirePcb->m_Flags = 0;
return;
}
if( (MirePcb->m_Flags & IN_EDIT) )
{
SwapData( MirePcb, &s_TargetCopy );
SaveCopyInUndoList( MirePcb, UR_CHANGED );
SwapData( MirePcb, &s_TargetCopy );
}
2009-08-03 07:55:08 +00:00
MirePcb->m_Flags = 0;
2007-05-06 16:03:28 +00:00
}
/* Redraw the contour of the track while moving the mouse */
static void ShowTargetShapeWhileMovingMouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
const wxPoint& aPosition, bool aErase )
2007-05-06 16:03:28 +00:00
{
BASE_SCREEN* screen = aPanel->GetScreen();
MIREPCB* MirePcb = (MIREPCB*) screen->GetCurItem();
2007-05-06 16:03:28 +00:00
if( MirePcb == NULL )
return;
2007-05-06 16:03:28 +00:00
if( aErase )
MirePcb->Draw( aPanel, aDC, GR_XOR );
2007-05-06 16:03:28 +00:00
MirePcb->m_Pos = screen->GetCrossHairPosition();
2007-05-06 16:03:28 +00:00
MirePcb->Draw( aPanel, aDC, GR_XOR );
2007-05-06 16:03:28 +00:00
}