2011-09-06 19:42:46 +00:00
|
|
|
/**
|
|
|
|
* @file dimension.cpp
|
2011-09-20 15:07:52 +00:00
|
|
|
* @brief Dialog and code for editing a dimension object.
|
2011-09-06 19:42:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2010-04-22 17:47:10 +00:00
|
|
|
#include "confirm.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "gr_basic.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2009-07-30 11:04:07 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2010-04-22 17:47:10 +00:00
|
|
|
#include "drawtxt.h"
|
2010-11-18 21:16:28 +00:00
|
|
|
#include "dialog_helpers.h"
|
2011-11-24 19:57:41 +00:00
|
|
|
#include "macros.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "class_board.h"
|
|
|
|
#include "class_pcb_text.h"
|
|
|
|
#include "class_dimension.h"
|
|
|
|
|
|
|
|
#include "pcbnew.h"
|
2011-11-24 19:57:41 +00:00
|
|
|
#include "dialog_dimension_editor_base.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
/* Local functions */
|
2011-11-24 19:57:41 +00:00
|
|
|
static void BuildDimension( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
|
2011-09-20 15:07:52 +00:00
|
|
|
const wxPoint& aPosition, bool aErase );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
static void MoveDimensionText( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aPosition, bool aErase );
|
|
|
|
static void AbortMoveDimensionText( EDA_DRAW_PANEL* aPanel, wxDC* aDC );
|
|
|
|
|
|
|
|
|
2010-08-10 18:34:26 +00:00
|
|
|
/* Local variables : */
|
2011-09-20 15:07:52 +00:00
|
|
|
static int status_dimension; /* Used in dimension creation:
|
2010-08-23 17:30:51 +00:00
|
|
|
* = 0 : initial value: no dimension in progress
|
2011-09-20 15:07:52 +00:00
|
|
|
* = 1 : First point created
|
|
|
|
* = 2 : Second point created, the text must be placed */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/*
|
2010-08-10 18:34:26 +00:00
|
|
|
* A dimension has this shape:
|
|
|
|
* It has 2 reference points, and a text
|
2010-04-22 17:47:10 +00:00
|
|
|
* | |
|
|
|
|
* | dist |
|
|
|
|
* |<---------->|
|
|
|
|
* | |
|
2008-03-04 04:22:27 +00:00
|
|
|
*
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
/*********************************/
|
2011-11-24 19:57:41 +00:00
|
|
|
/* class DIALOG_DIMENSION_EDITOR */
|
2011-09-06 19:42:46 +00:00
|
|
|
/*********************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
class DIALOG_DIMENSION_EDITOR : public DIALOG_DIMENSION_EDITOR_BASE
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
PCB_EDIT_FRAME* m_Parent;
|
|
|
|
wxDC* m_DC;
|
|
|
|
DIMENSION* CurrentDimension;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
public:
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
// Constructor and destructor
|
2011-11-24 19:57:41 +00:00
|
|
|
DIALOG_DIMENSION_EDITOR( PCB_EDIT_FRAME* aParent, DIMENSION* aDimension, wxDC* aDC );
|
|
|
|
~DIALOG_DIMENSION_EDITOR()
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
private:
|
2011-09-20 15:07:52 +00:00
|
|
|
void OnCancelClick( wxCommandEvent& event );
|
2011-11-24 19:57:41 +00:00
|
|
|
void OnOKClick( wxCommandEvent& event );
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
DIALOG_DIMENSION_EDITOR::DIALOG_DIMENSION_EDITOR( PCB_EDIT_FRAME* aParent,
|
2011-09-20 15:07:52 +00:00
|
|
|
DIMENSION* aDimension, wxDC* aDC ) :
|
2011-11-24 19:57:41 +00:00
|
|
|
DIALOG_DIMENSION_EDITOR_BASE( aParent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-09-22 19:16:55 +00:00
|
|
|
SetFocus();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
m_Parent = aParent;
|
|
|
|
m_DC = aDC;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
CurrentDimension = aDimension;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
if( aDimension->m_Text->m_Mirror )
|
2011-11-24 19:57:41 +00:00
|
|
|
m_rbMirror->SetSelection( 1 );
|
|
|
|
else
|
|
|
|
m_rbMirror->SetSelection( 0 );
|
|
|
|
|
|
|
|
m_Name->SetValue( aDimension->m_Text->m_Text );
|
|
|
|
|
|
|
|
// Enter size value in dialog
|
|
|
|
PutValueInLocalUnits( *m_TxtSizeXCtrl, aDimension->m_Text->m_Size.x,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
AddUnitSymbol( *m_staticTextSizeX );
|
|
|
|
PutValueInLocalUnits( *m_TxtSizeYCtrl, aDimension->m_Text->m_Size.y,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
AddUnitSymbol( *m_staticTextSizeY );
|
|
|
|
|
|
|
|
// Enter lines thickness value in dialog
|
|
|
|
PutValueInLocalUnits( *m_TxtWidthCtrl, aDimension->m_Width,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
AddUnitSymbol( *m_staticTextWidth );
|
|
|
|
|
|
|
|
// Enter position value in dialog
|
|
|
|
PutValueInLocalUnits( *m_textCtrlPosX, aDimension->m_Text->m_Pos.x,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
AddUnitSymbol( *m_staticTextPosX );
|
|
|
|
PutValueInLocalUnits( *m_textCtrlPosY, aDimension->m_Text->m_Pos.y,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
AddUnitSymbol( *m_staticTextPosY );
|
2008-03-04 04:22:27 +00:00
|
|
|
|
|
|
|
for( int layer = FIRST_NO_COPPER_LAYER; layer<NB_LAYERS; layer++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-09-20 15:07:52 +00:00
|
|
|
m_SelLayerBox->Append( aParent->GetBoard()->GetLayerName( layer ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
m_SelLayerBox->SetSelection( aDimension->GetLayer() - FIRST_NO_COPPER_LAYER );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2011-09-22 19:16:55 +00:00
|
|
|
Centre();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
void DIALOG_DIMENSION_EDITOR::OnCancelClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-10-07 03:08:24 +00:00
|
|
|
EndModal( -1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
void DIALOG_DIMENSION_EDITOR::OnOKClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-09-06 19:42:46 +00:00
|
|
|
if( m_DC ) // Delete old text.
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-04-23 09:54:40 +00:00
|
|
|
CurrentDimension->Draw( m_Parent->DrawPanel, m_DC, GR_XOR );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
m_Parent->SaveCopyInUndoList(CurrentDimension, UR_CHANGED);
|
2011-09-06 19:42:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( m_Name->GetValue() != wxEmptyString )
|
|
|
|
{
|
2010-04-23 09:54:40 +00:00
|
|
|
CurrentDimension->SetText( m_Name->GetValue() );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
// Get new size value:
|
|
|
|
msg = m_TxtSizeXCtrl->GetValue();
|
|
|
|
CurrentDimension->m_Text->m_Size.x = ReturnValueFromString( g_UserUnit, msg,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
msg = m_TxtSizeYCtrl->GetValue();
|
|
|
|
CurrentDimension->m_Text->m_Size.y = ReturnValueFromString( g_UserUnit, msg,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
|
|
|
|
// Get new position value:
|
|
|
|
// It will be copied later in dimension, because
|
|
|
|
msg = m_textCtrlPosX->GetValue();
|
|
|
|
CurrentDimension->m_Text->m_Pos.x = ReturnValueFromString( g_UserUnit, msg,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
msg = m_textCtrlPosY->GetValue();
|
|
|
|
CurrentDimension->m_Text->m_Pos.y = ReturnValueFromString( g_UserUnit, msg,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
|
|
|
|
// Get new line thickness value:
|
|
|
|
msg = m_TxtWidthCtrl->GetValue();
|
|
|
|
int width = ReturnValueFromString( g_UserUnit, msg,
|
|
|
|
m_Parent->m_InternalUnits );
|
2010-08-23 17:30:51 +00:00
|
|
|
int maxthickness = Clamp_Text_PenSize( width, CurrentDimension->m_Text->m_Size );
|
2011-09-06 19:42:46 +00:00
|
|
|
|
2010-04-22 17:47:10 +00:00
|
|
|
if( width > maxthickness )
|
|
|
|
{
|
2010-08-23 17:30:51 +00:00
|
|
|
DisplayError( NULL,
|
|
|
|
_( "The text thickness is too large for the text size. It will be clamped") );
|
2010-04-22 17:47:10 +00:00
|
|
|
width = maxthickness;
|
|
|
|
}
|
2011-09-06 19:42:46 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
CurrentDimension->m_Text->m_Thickness = CurrentDimension->m_Width = width ;
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
CurrentDimension->m_Text->m_Mirror = ( m_rbMirror->GetSelection() == 1 ) ? true : false;
|
2010-04-22 17:47:10 +00:00
|
|
|
|
2011-04-19 19:19:41 +00:00
|
|
|
CurrentDimension->SetLayer( m_SelLayerBox->GetCurrentSelection() + FIRST_NO_COPPER_LAYER );
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
if( m_DC ) // Display new text
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-04-23 09:54:40 +00:00
|
|
|
CurrentDimension->Draw( m_Parent->DrawPanel, m_DC, GR_OR );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
m_Parent->OnModify();
|
2007-10-07 03:08:24 +00:00
|
|
|
EndModal( 1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
static void AbortBuildDimension( EDA_DRAW_PANEL* Panel, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-04-23 09:54:40 +00:00
|
|
|
DIMENSION* Dimension = (DIMENSION*) Panel->GetScreen()->GetCurItem();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
if( Dimension )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-21 13:54:29 +00:00
|
|
|
if( Dimension->IsNew() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-09-20 15:07:52 +00:00
|
|
|
Dimension->Draw( Panel, aDC, GR_XOR );
|
2010-04-23 09:54:40 +00:00
|
|
|
Dimension->DeleteStructure();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-20 15:07:52 +00:00
|
|
|
Dimension->Draw( Panel, aDC, GR_OR );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
status_dimension = 0;
|
2011-03-01 19:26:17 +00:00
|
|
|
((PCB_EDIT_FRAME*)Panel->GetParent())->SetCurItem( NULL );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
DIMENSION* PCB_EDIT_FRAME::EditDimension( DIMENSION* aDimension, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
wxPoint pos;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
if( aDimension == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-04-23 09:54:40 +00:00
|
|
|
status_dimension = 1;
|
2011-02-11 20:48:13 +00:00
|
|
|
pos = GetScreen()->GetCrossHairPosition();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension = new DIMENSION( GetBoard() );
|
|
|
|
aDimension->m_Flags = IS_NEW;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension->SetLayer( getActiveLayer() );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension->m_crossBarOx = aDimension->m_crossBarFx = pos.x;
|
|
|
|
aDimension->m_crossBarOy = aDimension->m_crossBarFy = pos.y;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension->m_featureLineDOx = aDimension->m_featureLineDFx = pos.x;
|
|
|
|
aDimension->m_featureLineDOy = aDimension->m_featureLineDFy = pos.y;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension->m_featureLineGOx = aDimension->m_featureLineGFx = pos.x;
|
|
|
|
aDimension->m_featureLineGOy = aDimension->m_featureLineGFy = pos.y;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension->m_arrowG1Ox = aDimension->m_arrowG1Fx = pos.x;
|
|
|
|
aDimension->m_arrowG1Oy = aDimension->m_arrowG1Fy = pos.y;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension->m_arrowG2Ox = aDimension->m_arrowG2Fx = pos.x;
|
|
|
|
aDimension->m_arrowG2Oy = aDimension->m_arrowG2Fy = pos.y;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension->m_arrowD1Ox = aDimension->m_arrowD1Fx = pos.x;
|
|
|
|
aDimension->m_arrowD1Oy = aDimension->m_arrowD1Fy = pos.y;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension->m_arrowD2Ox = aDimension->m_arrowD2Fx = pos.x;
|
|
|
|
aDimension->m_arrowD2Oy = aDimension->m_arrowD2Fy = pos.y;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension->m_Text->m_Size = GetBoard()->GetBoardDesignSettings()->m_PcbTextSize;
|
2010-04-22 17:47:10 +00:00
|
|
|
int width = GetBoard()->GetBoardDesignSettings()->m_PcbTextWidth;
|
2011-09-20 15:07:52 +00:00
|
|
|
int maxthickness = Clamp_Text_PenSize(width, aDimension->m_Text->m_Size );
|
2011-09-06 19:42:46 +00:00
|
|
|
|
2010-04-22 17:47:10 +00:00
|
|
|
if( width > maxthickness )
|
|
|
|
{
|
|
|
|
width = maxthickness;
|
|
|
|
}
|
2011-09-06 19:42:46 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension->m_Text->m_Thickness = aDimension->m_Width = width ;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension->AdjustDimensionDetails( );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension->Draw( DrawPanel, aDC, GR_XOR );
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
DrawPanel->SetMouseCapture( BuildDimension, AbortBuildDimension );
|
2011-09-20 15:07:52 +00:00
|
|
|
return aDimension;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
// Dimension != NULL
|
|
|
|
if( status_dimension == 1 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-04-23 09:54:40 +00:00
|
|
|
status_dimension = 2;
|
2011-09-20 15:07:52 +00:00
|
|
|
return aDimension;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
aDimension->Draw( DrawPanel, aDC, GR_OR );
|
|
|
|
aDimension->m_Flags = 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-04-22 17:47:10 +00:00
|
|
|
/* ADD this new item in list */
|
2011-09-20 15:07:52 +00:00
|
|
|
GetBoard()->Add( aDimension );
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2010-04-22 17:47:10 +00:00
|
|
|
// Add store it in undo/redo list
|
2011-09-20 15:07:52 +00:00
|
|
|
SaveCopyInUndoList( aDimension, UR_NEW );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->SetMouseCapture( NULL, NULL );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
static void BuildDimension( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
|
2011-09-20 15:07:52 +00:00
|
|
|
const wxPoint& aPosition, bool aErase )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
PCB_SCREEN* screen = (PCB_SCREEN*) aPanel->GetScreen();
|
|
|
|
DIMENSION* Dimension = (DIMENSION*) screen->GetCurItem();
|
2011-02-11 20:48:13 +00:00
|
|
|
wxPoint pos = screen->GetCrossHairPosition();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
if( Dimension == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
// Erase previous dimension.
|
|
|
|
if( aErase )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
Dimension->Draw( aPanel, aDC, GR_XOR );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
Dimension->SetLayer( screen->m_Active_Layer );
|
2011-02-03 19:27:28 +00:00
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
if( status_dimension == 1 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-09-20 15:07:52 +00:00
|
|
|
Dimension->m_featureLineDOx = pos.x;
|
|
|
|
Dimension->m_featureLineDOy = pos.y;
|
|
|
|
Dimension->m_crossBarFx = Dimension->m_featureLineDOx;
|
|
|
|
Dimension->m_crossBarFy = Dimension->m_featureLineDOy;
|
2010-04-23 09:54:40 +00:00
|
|
|
Dimension->AdjustDimensionDetails( );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int deltax, deltay, dx, dy;
|
|
|
|
float angle, depl;
|
2011-09-20 15:07:52 +00:00
|
|
|
deltax = Dimension->m_featureLineDOx - Dimension->m_featureLineGOx;
|
|
|
|
deltay = Dimension->m_featureLineDOy - Dimension->m_featureLineGOy;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
/* Calculating the direction of travel perpendicular to the selected axis. */
|
2008-10-29 15:26:53 +00:00
|
|
|
angle = atan2( (double)deltay, (double)deltax ) + (M_PI / 2);
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
deltax = pos.x - Dimension->m_featureLineDOx;
|
|
|
|
deltay = pos.y - Dimension->m_featureLineDOy;
|
2007-08-20 01:20:48 +00:00
|
|
|
depl = ( deltax * cos( angle ) ) + ( deltay * sin( angle ) );
|
|
|
|
dx = (int) ( depl * cos( angle ) );
|
|
|
|
dy = (int) ( depl * sin( angle ) );
|
2011-09-20 15:07:52 +00:00
|
|
|
Dimension->m_crossBarOx = Dimension->m_featureLineGOx + dx;
|
|
|
|
Dimension->m_crossBarOy = Dimension->m_featureLineGOy + dy;
|
|
|
|
Dimension->m_crossBarFx = Dimension->m_featureLineDOx + dx;
|
|
|
|
Dimension->m_crossBarFy = Dimension->m_featureLineDOy + dy;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
Dimension->AdjustDimensionDetails( );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
Dimension->Draw( aPanel, aDC, GR_XOR );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
void PCB_EDIT_FRAME::ShowDimensionPropertyDialog( DIMENSION* aDimension, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-09-20 15:07:52 +00:00
|
|
|
if( aDimension == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
DIALOG_DIMENSION_EDITOR* frame = new DIALOG_DIMENSION_EDITOR( this, aDimension, aDC );
|
2007-10-07 03:08:24 +00:00
|
|
|
frame->ShowModal();
|
|
|
|
frame->Destroy();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
void PCB_EDIT_FRAME::DeleteDimension( DIMENSION* aDimension, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-09-20 15:07:52 +00:00
|
|
|
if( aDimension == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
if( aDC )
|
|
|
|
aDimension->Draw( DrawPanel, aDC, GR_XOR );
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
SaveCopyInUndoList( aDimension, UR_DELETED );
|
|
|
|
aDimension->UnLink();
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2011-11-24 19:57:41 +00:00
|
|
|
|
|
|
|
/* Initialize parameters to move a pcb text
|
|
|
|
*/
|
|
|
|
static wxPoint initialTextPosition;
|
|
|
|
void PCB_EDIT_FRAME::BeginMoveDimensionText( DIMENSION* aItem, wxDC* DC )
|
|
|
|
{
|
|
|
|
if( aItem == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Store the initial position for undo/abort command
|
|
|
|
initialTextPosition = aItem->m_Text->m_Pos;
|
|
|
|
|
|
|
|
aItem->Draw( DrawPanel, DC, GR_XOR );
|
|
|
|
aItem->m_Flags |= IS_MOVED;
|
|
|
|
aItem->DisplayInfo( this );
|
|
|
|
|
|
|
|
GetScreen()->SetCrossHairPosition( aItem->m_Text->m_Pos );
|
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
|
|
|
|
|
|
|
DrawPanel->SetMouseCapture( MoveDimensionText, AbortMoveDimensionText );
|
|
|
|
SetCurItem( aItem );
|
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Move dimension text following the cursor. */
|
|
|
|
static void MoveDimensionText( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase )
|
|
|
|
{
|
|
|
|
DIMENSION* dimension = (DIMENSION*) aPanel->GetScreen()->GetCurItem();
|
|
|
|
|
|
|
|
if( dimension == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( aErase )
|
|
|
|
dimension->Draw( aPanel, aDC, GR_XOR );
|
|
|
|
|
|
|
|
dimension->m_Text->m_Pos = aPanel->GetScreen()->GetCrossHairPosition();
|
|
|
|
|
|
|
|
dimension->Draw( aPanel, aDC, GR_XOR );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Abort current text edit progress.
|
|
|
|
*
|
|
|
|
* If a text is selected, its initial coord are regenerated
|
|
|
|
*/
|
|
|
|
void AbortMoveDimensionText( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
|
|
|
|
{
|
|
|
|
DIMENSION* dimension = (DIMENSION*) aPanel->GetScreen()->GetCurItem();
|
|
|
|
( (PCB_EDIT_FRAME*) aPanel->GetParent() )->SetCurItem( NULL );
|
|
|
|
|
|
|
|
aPanel->SetMouseCapture( NULL, NULL );
|
|
|
|
|
|
|
|
if( dimension == NULL ) // Should not occur
|
|
|
|
return;
|
|
|
|
|
|
|
|
dimension->Draw( aPanel, aDC, GR_XOR );
|
|
|
|
dimension->m_Text->m_Pos = initialTextPosition;
|
|
|
|
dimension->m_Flags = 0;
|
|
|
|
dimension->Draw( aPanel, aDC, GR_OR );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Place the current dimension text being moving
|
|
|
|
*/
|
|
|
|
void PCB_EDIT_FRAME::PlaceDimensionText( DIMENSION* aItem, wxDC* DC )
|
|
|
|
{
|
|
|
|
DrawPanel->SetMouseCapture( NULL, NULL );
|
|
|
|
SetCurItem( NULL );
|
|
|
|
|
|
|
|
if( aItem == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
aItem->Draw( DrawPanel, DC, GR_OR );
|
|
|
|
OnModify();
|
|
|
|
|
|
|
|
EXCHG( aItem->m_Text->m_Pos, initialTextPosition );
|
|
|
|
SaveCopyInUndoList( aItem, UR_CHANGED );
|
|
|
|
EXCHG( aItem->m_Text->m_Pos, initialTextPosition );
|
|
|
|
|
|
|
|
aItem->m_Flags = 0;
|
|
|
|
}
|