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
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
/*
|
|
|
|
* 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) 1992-2012 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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <drawtxt.h>
|
|
|
|
#include <dialog_helpers.h>
|
|
|
|
#include <macros.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_pcb_text.h>
|
|
|
|
#include <class_dimension.h>
|
|
|
|
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#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
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( aDimension->Text().IsMirrored() )
|
2011-11-24 19:57:41 +00:00
|
|
|
m_rbMirror->SetSelection( 1 );
|
|
|
|
else
|
|
|
|
m_rbMirror->SetSelection( 0 );
|
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
m_Name->SetValue( aDimension->Text().GetText() );
|
2011-11-24 19:57:41 +00:00
|
|
|
|
|
|
|
// Enter size value in dialog
|
2013-03-13 18:53:58 +00:00
|
|
|
PutValueInLocalUnits( *m_TxtSizeXCtrl, aDimension->Text().GetSize().x );
|
2011-11-24 19:57:41 +00:00
|
|
|
AddUnitSymbol( *m_staticTextSizeX );
|
2013-03-13 18:53:58 +00:00
|
|
|
PutValueInLocalUnits( *m_TxtSizeYCtrl, aDimension->Text().GetSize().y );
|
2011-11-24 19:57:41 +00:00
|
|
|
AddUnitSymbol( *m_staticTextSizeY );
|
|
|
|
|
|
|
|
// Enter lines thickness value in dialog
|
2013-03-13 18:53:58 +00:00
|
|
|
PutValueInLocalUnits( *m_TxtWidthCtrl, aDimension->GetWidth() );
|
2011-11-24 19:57:41 +00:00
|
|
|
AddUnitSymbol( *m_staticTextWidth );
|
|
|
|
|
|
|
|
// Enter position value in dialog
|
2013-03-18 19:36:07 +00:00
|
|
|
PutValueInLocalUnits( *m_textCtrlPosX, aDimension->Text().GetTextPosition().x );
|
2011-11-24 19:57:41 +00:00
|
|
|
AddUnitSymbol( *m_staticTextPosX );
|
2013-03-18 19:36:07 +00:00
|
|
|
PutValueInLocalUnits( *m_textCtrlPosY, aDimension->Text().GetTextPosition().y );
|
2011-11-24 19:57:41 +00:00
|
|
|
AddUnitSymbol( *m_staticTextPosY );
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
for( LAYER_NUM layer = FIRST_NON_COPPER_LAYER; layer < NB_PCB_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
|
|
|
}
|
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
m_SelLayerBox->SetSelection( aDimension->GetLayer() - FIRST_NON_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
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
CurrentDimension->Draw( m_Parent->GetCanvas(), 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();
|
2013-03-13 18:53:58 +00:00
|
|
|
CurrentDimension->Text().SetWidth( ReturnValueFromString( g_UserUnit, msg ) );
|
2011-11-24 19:57:41 +00:00
|
|
|
msg = m_TxtSizeYCtrl->GetValue();
|
2013-03-13 18:53:58 +00:00
|
|
|
CurrentDimension->Text().SetHeight( ReturnValueFromString( g_UserUnit, msg ) );
|
2011-11-24 19:57:41 +00:00
|
|
|
|
|
|
|
// Get new position value:
|
|
|
|
// It will be copied later in dimension, because
|
|
|
|
msg = m_textCtrlPosX->GetValue();
|
2013-03-13 18:53:58 +00:00
|
|
|
wxPoint pos;
|
|
|
|
pos.x = ReturnValueFromString( g_UserUnit, msg );
|
2011-11-24 19:57:41 +00:00
|
|
|
msg = m_textCtrlPosY->GetValue();
|
2013-03-13 18:53:58 +00:00
|
|
|
pos.y = ReturnValueFromString( g_UserUnit, msg );
|
2013-03-18 19:36:07 +00:00
|
|
|
CurrentDimension->Text().SetTextPosition( pos );
|
2011-11-24 19:57:41 +00:00
|
|
|
|
|
|
|
// Get new line thickness value:
|
|
|
|
msg = m_TxtWidthCtrl->GetValue();
|
2012-04-16 17:39:32 +00:00
|
|
|
int width = ReturnValueFromString( g_UserUnit, msg );
|
2013-03-13 18:53:58 +00:00
|
|
|
int maxthickness = Clamp_Text_PenSize( width, CurrentDimension->Text().GetSize() );
|
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
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
CurrentDimension->SetWidth( width );
|
|
|
|
CurrentDimension->Text().SetThickness( width );
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
CurrentDimension->Text().SetMirrored( ( m_rbMirror->GetSelection() == 1 ) ? true : false );
|
2010-04-22 17:47:10 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
CurrentDimension->SetLayer( FIRST_NON_COPPER_LAYER + m_SelLayerBox->GetCurrentSelection() );
|
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
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
CurrentDimension->Draw( m_Parent->GetCanvas(), 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() );
|
2011-12-21 13:42:02 +00:00
|
|
|
aDimension->SetFlags( 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
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
aDimension->m_crossBarO = aDimension->m_crossBarF = pos;
|
|
|
|
aDimension->m_featureLineDO = aDimension->m_featureLineDF = pos;
|
|
|
|
aDimension->m_featureLineGO = aDimension->m_featureLineGF = pos;
|
|
|
|
aDimension->m_arrowG1O = aDimension->m_arrowG1F = pos;
|
|
|
|
aDimension->m_arrowG2O = aDimension->m_arrowG2F = pos;
|
|
|
|
aDimension->m_arrowD1O = aDimension->m_arrowD1F = pos;
|
|
|
|
aDimension->m_arrowD2O = aDimension->m_arrowD2F = pos;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
aDimension->Text().SetSize( GetBoard()->GetDesignSettings().m_PcbTextSize );
|
++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
|
|
|
int width = GetBoard()->GetDesignSettings().m_PcbTextWidth;
|
2013-03-13 18:53:58 +00:00
|
|
|
int maxthickness = Clamp_Text_PenSize(width, aDimension->Text().GetSize() );
|
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
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
aDimension->Text().SetThickness( width );
|
|
|
|
aDimension->SetWidth( width );
|
|
|
|
aDimension->AdjustDimensionDetails();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
aDimension->Draw( m_canvas, aDC, GR_XOR );
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->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-12-22 13:28:11 +00:00
|
|
|
aDimension->Draw( m_canvas, aDC, GR_OR );
|
2011-12-21 13:42:02 +00:00
|
|
|
aDimension->ClearFlags();
|
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-12-22 13:28:11 +00:00
|
|
|
m_canvas->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
|
|
|
{
|
2012-12-19 19:31:36 +00:00
|
|
|
Dimension->m_featureLineDO = pos;
|
|
|
|
Dimension->m_crossBarF = Dimension->m_featureLineDO;
|
2010-04-23 09:54:40 +00:00
|
|
|
Dimension->AdjustDimensionDetails( );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-19 19:31:36 +00:00
|
|
|
wxPoint delta;
|
|
|
|
int dx, dy;
|
2013-05-07 17:31:52 +00:00
|
|
|
double angle, depl;
|
2012-12-19 19:31:36 +00:00
|
|
|
delta = Dimension->m_featureLineDO - Dimension->m_featureLineGO;
|
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. */
|
2013-05-01 17:32:36 +00:00
|
|
|
angle = atan2( delta.y, delta.x ) + (M_PI / 2);
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
delta = pos - Dimension->m_featureLineDO;
|
|
|
|
depl = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
|
2013-05-01 17:32:36 +00:00
|
|
|
dx = KiROUND( depl * cos( angle ) );
|
|
|
|
dy = KiROUND( depl * sin( angle ) );
|
2012-12-19 19:31:36 +00:00
|
|
|
Dimension->m_crossBarO.x = Dimension->m_featureLineGO.x + dx;
|
|
|
|
Dimension->m_crossBarO.y = Dimension->m_featureLineGO.y + dy;
|
|
|
|
Dimension->m_crossBarF.x = Dimension->m_featureLineDO.x + dx;
|
|
|
|
Dimension->m_crossBarF.y = Dimension->m_featureLineDO.y + 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 )
|
2011-12-22 13:28:11 +00:00
|
|
|
aDimension->Draw( m_canvas, 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
|
2013-03-18 19:36:07 +00:00
|
|
|
initialTextPosition = aItem->Text().GetTextPosition();
|
2011-11-24 19:57:41 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
aItem->Draw( m_canvas, DC, GR_XOR );
|
2011-12-21 13:42:02 +00:00
|
|
|
aItem->SetFlags( IS_MOVED );
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( aItem );
|
2011-11-24 19:57:41 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( aItem->Text().GetTextPosition() );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-11-24 19:57:41 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( MoveDimensionText, AbortMoveDimensionText );
|
2011-11-24 19:57:41 +00:00
|
|
|
SetCurItem( aItem );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2011-11-24 19:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 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 );
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
dimension->Text().SetTextPosition( aPanel->GetScreen()->GetCrossHairPosition() );
|
2011-11-24 19:57:41 +00:00
|
|
|
|
|
|
|
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 );
|
2013-03-18 19:36:07 +00:00
|
|
|
dimension->Text().SetTextPosition( initialTextPosition );
|
2011-12-21 13:42:02 +00:00
|
|
|
dimension->ClearFlags();
|
2011-11-24 19:57:41 +00:00
|
|
|
dimension->Draw( aPanel, aDC, GR_OR );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Place the current dimension text being moving
|
|
|
|
*/
|
|
|
|
void PCB_EDIT_FRAME::PlaceDimensionText( DIMENSION* aItem, wxDC* DC )
|
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( NULL, NULL );
|
2011-11-24 19:57:41 +00:00
|
|
|
SetCurItem( NULL );
|
|
|
|
|
|
|
|
if( aItem == NULL )
|
|
|
|
return;
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
aItem->Draw( m_canvas, DC, GR_OR );
|
2011-11-24 19:57:41 +00:00
|
|
|
OnModify();
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
wxPoint tmp = aItem->Text().GetTextPosition();
|
|
|
|
aItem->Text().SetTextPosition( initialTextPosition );
|
2011-11-24 19:57:41 +00:00
|
|
|
SaveCopyInUndoList( aItem, UR_CHANGED );
|
2013-03-18 19:36:07 +00:00
|
|
|
aItem->Text().SetTextPosition( tmp );
|
2011-11-24 19:57:41 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
aItem->ClearFlags();
|
2011-11-24 19:57:41 +00:00
|
|
|
}
|