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.
|
|
|
|
*
|
2016-07-19 17:44:28 +00:00
|
|
|
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2016-07-19 17:44:28 +00:00
|
|
|
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-06-08 09:56:42 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2018-01-28 21:02:31 +00:00
|
|
|
#include <draw_graphic_text.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_helpers.h>
|
|
|
|
#include <macros.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2016-06-20 13:46:58 +00:00
|
|
|
#include <board_commit.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>
|
2018-01-31 08:23:20 +00:00
|
|
|
#include <pcb_layer_box_selector.h>
|
2018-06-06 10:05:56 +00:00
|
|
|
#include <dialogs/dialog_text_properties.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,
|
2015-08-01 21:30:38 +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
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
2016-07-19 17:44:28 +00:00
|
|
|
DIMENSION* dimension = (DIMENSION*) Panel->GetScreen()->GetCurItem();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2016-07-19 17:44:28 +00:00
|
|
|
if( dimension )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2016-07-19 17:44:28 +00:00
|
|
|
if( dimension->IsNew() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2016-07-19 17:44:28 +00:00
|
|
|
dimension->Draw( Panel, aDC, GR_XOR );
|
|
|
|
dimension->DeleteStructure();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-19 17:44:28 +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
|
|
|
{
|
2018-04-28 15:22:25 +00:00
|
|
|
const BOARD_DESIGN_SETTINGS& boardSettings = GetBoard()->GetDesignSettings();
|
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
status_dimension = 1;
|
2013-08-03 05:15:23 +00:00
|
|
|
pos = 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 );
|
2014-03-21 10:17:47 +00:00
|
|
|
aDimension->SetLayer( GetActiveLayer() );
|
2014-02-11 12:22:30 +00:00
|
|
|
aDimension->SetOrigin( pos );
|
|
|
|
aDimension->SetEnd( pos );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
aDimension->Text().SetTextSize( boardSettings.GetTextSize( GetActiveLayer() ) );
|
|
|
|
aDimension->Text().SetThickness( boardSettings.GetTextThickness( GetActiveLayer() ) );
|
|
|
|
aDimension->Text().SetItalic( boardSettings.GetTextItalic( GetActiveLayer() ) );
|
|
|
|
aDimension->SetWidth( boardSettings.GetLineThickness( GetActiveLayer() ) );
|
2018-06-13 16:05:43 +00:00
|
|
|
aDimension->AdjustDimensionDetails( GetUserUnits() );
|
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,
|
2015-08-01 21:30:38 +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();
|
2013-08-03 05:15:23 +00:00
|
|
|
wxPoint pos = aPanel->GetParent()->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;
|
2018-06-13 16:05:43 +00:00
|
|
|
Dimension->AdjustDimensionDetails();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-06 19:42:46 +00:00
|
|
|
/* Calculating the direction of travel perpendicular to the selected axis. */
|
2014-02-11 12:22:30 +00:00
|
|
|
double angle = Dimension->GetAngle() + (M_PI / 2);
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2014-02-11 12:22:30 +00:00
|
|
|
wxPoint delta = pos - Dimension->m_featureLineDO;
|
|
|
|
double depl = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
|
|
|
|
Dimension->SetHeight( depl );
|
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
|
|
|
|
2018-06-06 10:05:56 +00:00
|
|
|
DIALOG_TEXT_PROPERTIES dlg( this, aDimension, aDC );
|
2016-07-19 17:44:28 +00:00
|
|
|
dlg.ShowModal();
|
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
|
|
|
|
2015-08-01 21:30:38 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
/* Initialize parameters to move a pcb text
|
|
|
|
*/
|
|
|
|
static wxPoint initialTextPosition;
|
2015-08-01 21:30:38 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
void PCB_EDIT_FRAME::BeginMoveDimensionText( DIMENSION* aItem, wxDC* DC )
|
|
|
|
{
|
|
|
|
if( aItem == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Store the initial position for undo/abort command
|
2017-01-23 20:30:11 +00:00
|
|
|
initialTextPosition = aItem->Text().GetTextPos();
|
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
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
SetCrossHairPosition( aItem->Text().GetTextPos() );
|
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,
|
2015-08-01 21:30:38 +00:00
|
|
|
bool aErase )
|
2011-11-24 19:57:41 +00:00
|
|
|
{
|
|
|
|
DIMENSION* dimension = (DIMENSION*) aPanel->GetScreen()->GetCurItem();
|
|
|
|
|
|
|
|
if( dimension == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( aErase )
|
|
|
|
dimension->Draw( aPanel, aDC, GR_XOR );
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
dimension->Text().SetTextPos( aPanel->GetParent()->GetCrossHairPosition() );
|
2011-11-24 19:57:41 +00:00
|
|
|
|
|
|
|
dimension->Draw( aPanel, aDC, GR_XOR );
|
|
|
|
}
|
|
|
|
|
2015-08-01 21:30:38 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
/*
|
|
|
|
* 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 );
|
2017-01-23 20:30:11 +00:00
|
|
|
dimension->Text().SetTextPos( 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 );
|
|
|
|
}
|
|
|
|
|
2015-08-01 21:30:38 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
/*
|
|
|
|
* 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();
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint tmp = aItem->Text().GetTextPos();
|
|
|
|
aItem->Text().SetTextPos( initialTextPosition );
|
2011-11-24 19:57:41 +00:00
|
|
|
SaveCopyInUndoList( aItem, UR_CHANGED );
|
2017-01-23 20:30:11 +00:00
|
|
|
aItem->Text().SetTextPos( tmp );
|
2011-12-21 13:42:02 +00:00
|
|
|
aItem->ClearFlags();
|
2011-11-24 19:57:41 +00:00
|
|
|
}
|