2014-02-06 16:12:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-02-08 09:13:43 +00:00
|
|
|
* Copyright (C) 2014-2017 CERN
|
2016-09-30 04:31:59 +00:00
|
|
|
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-02-06 16:12:37 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "drawing_tool.h"
|
|
|
|
#include "common_actions.h"
|
|
|
|
|
|
|
|
#include <wxPcbStruct.h>
|
2014-07-09 08:57:32 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
2014-05-12 15:17:51 +00:00
|
|
|
#include <project.h>
|
2014-02-19 12:51:32 +00:00
|
|
|
#include <id.h>
|
2014-04-04 09:50:15 +00:00
|
|
|
#include <pcbnew_id.h>
|
2014-02-13 11:46:39 +00:00
|
|
|
#include <confirm.h>
|
2014-07-09 12:01:06 +00:00
|
|
|
#include <dialog_edit_module_text.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
#include <import_dxf/dialog_dxf_import.h>
|
2014-02-13 11:46:39 +00:00
|
|
|
|
2014-02-06 16:12:37 +00:00
|
|
|
#include <view/view_group.h>
|
|
|
|
#include <view/view_controls.h>
|
2016-12-02 17:58:12 +00:00
|
|
|
#include <view/view.h>
|
2014-02-13 11:46:39 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2014-02-17 10:33:03 +00:00
|
|
|
#include <router/direction.h>
|
2015-11-18 14:35:17 +00:00
|
|
|
#include <ratsnest_data.h>
|
2016-06-21 15:06:28 +00:00
|
|
|
#include <board_commit.h>
|
2017-01-11 17:22:53 +00:00
|
|
|
#include <scoped_set_reset.h>
|
2014-02-13 11:46:39 +00:00
|
|
|
|
2014-02-06 16:12:37 +00:00
|
|
|
#include <class_board.h>
|
2014-07-09 12:01:06 +00:00
|
|
|
#include <class_edge_mod.h>
|
2014-02-10 14:40:25 +00:00
|
|
|
#include <class_pcb_text.h>
|
2014-02-11 13:38:44 +00:00
|
|
|
#include <class_dimension.h>
|
2014-02-13 15:10:32 +00:00
|
|
|
#include <class_zone.h>
|
2014-02-13 11:46:39 +00:00
|
|
|
#include <class_module.h>
|
2014-02-06 16:12:37 +00:00
|
|
|
|
2016-11-04 21:29:47 +00:00
|
|
|
#include <tools/selection_tool.h>
|
2017-02-04 05:09:50 +00:00
|
|
|
#include <tools/tool_event_utils.h>
|
2017-01-09 17:29:40 +00:00
|
|
|
|
|
|
|
using SCOPED_DRAW_MODE = SCOPED_SET_RESET<DRAWING_TOOL::MODE>;
|
|
|
|
|
2014-02-06 16:12:37 +00:00
|
|
|
DRAWING_TOOL::DRAWING_TOOL() :
|
2017-01-09 17:29:40 +00:00
|
|
|
PCB_TOOL( "pcbnew.InteractiveDrawing" ),
|
|
|
|
m_view( nullptr ), m_controls( nullptr ),
|
|
|
|
m_board( nullptr ), m_frame( nullptr ), m_mode( MODE::NONE ),
|
|
|
|
m_lineWidth( 1 ),
|
2017-01-11 17:22:53 +00:00
|
|
|
m_menu( *this )
|
2014-02-06 16:12:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DRAWING_TOOL::~DRAWING_TOOL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
bool DRAWING_TOOL::Init()
|
|
|
|
{
|
|
|
|
// Drawing type-specific options will be added by the PCB control tool
|
2017-01-11 17:22:53 +00:00
|
|
|
m_menu.AddStandardSubMenus( *getEditFrame<PCB_BASE_FRAME>() );
|
2017-01-09 17:29:40 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-06 16:12:37 +00:00
|
|
|
void DRAWING_TOOL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
2014-02-14 08:49:49 +00:00
|
|
|
// Init variables used by every drawing tool
|
|
|
|
m_view = getView();
|
|
|
|
m_controls = getViewControls();
|
2014-06-06 12:59:25 +00:00
|
|
|
m_board = getModel<BOARD>();
|
2016-06-08 09:24:46 +00:00
|
|
|
m_frame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
2014-02-06 16:12:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
DRAWING_TOOL::MODE DRAWING_TOOL::GetDrawingMode() const
|
|
|
|
{
|
|
|
|
return m_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent )
|
2014-02-06 16:12:37 +00:00
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
BOARD_ITEM_CONTAINER* parent = m_frame->GetModel();
|
|
|
|
DRAWSEGMENT* line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
|
2014-07-09 13:10:32 +00:00
|
|
|
boost::optional<VECTOR2D> startingPoint;
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2014-07-09 13:10:32 +00:00
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE );
|
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
m_frame->SetToolID( m_editModules ? ID_MODEDIT_LINE_TOOL : ID_PCB_ADD_LINE_BUTT,
|
|
|
|
wxCURSOR_PENCIL, _( "Add graphic line" ) );
|
2017-02-08 09:13:43 +00:00
|
|
|
m_lineWidth = getSegmentWidth( getDrawingLayer() );
|
2014-04-04 09:50:15 +00:00
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
while( drawSegment( S_SEGMENT, line, startingPoint ) )
|
|
|
|
{
|
|
|
|
if( line )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( line );
|
|
|
|
commit.Push( _( "Draw a line segment" ) );
|
2016-06-08 09:24:46 +00:00
|
|
|
startingPoint = line->GetEnd();
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
else
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
startingPoint = boost::none;
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
|
|
|
|
line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2014-02-06 16:12:37 +00:00
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
|
2014-04-04 09:50:15 +00:00
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
return 0;
|
2014-02-06 16:12:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent )
|
2014-02-10 09:58:58 +00:00
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
BOARD_ITEM_CONTAINER* parent = m_frame->GetModel();
|
|
|
|
DRAWSEGMENT* circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2014-02-10 09:58:58 +00:00
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE );
|
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
m_frame->SetToolID( m_editModules ? ID_MODEDIT_CIRCLE_TOOL : ID_PCB_CIRCLE_BUTT,
|
|
|
|
wxCURSOR_PENCIL, _( "Add graphic circle" ) );
|
2017-02-08 09:13:43 +00:00
|
|
|
m_lineWidth = getSegmentWidth( getDrawingLayer() );
|
2014-02-14 10:35:48 +00:00
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
while( drawSegment( S_CIRCLE, circle ) )
|
|
|
|
{
|
|
|
|
if( circle )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( circle );
|
|
|
|
commit.Push( _( "Draw a circle" ) );
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
|
|
|
|
circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
BOARD_ITEM_CONTAINER* parent = m_frame->GetModel();
|
|
|
|
DRAWSEGMENT* arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC );
|
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
m_frame->SetToolID( m_editModules ? ID_MODEDIT_ARC_TOOL : ID_PCB_ARC_BUTT,
|
|
|
|
wxCURSOR_PENCIL, _( "Add graphic arc" ) );
|
2017-02-08 09:13:43 +00:00
|
|
|
m_lineWidth = getSegmentWidth( getDrawingLayer() );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
while( drawArc( arc ) )
|
|
|
|
{
|
|
|
|
if( arc )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( arc );
|
|
|
|
commit.Push( _( "Draw an arc" ) );
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
|
|
|
|
arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2014-02-10 09:58:58 +00:00
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
|
2014-02-10 09:58:58 +00:00
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-02-10 09:58:58 +00:00
|
|
|
|
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
BOARD_ITEM* text = NULL;
|
|
|
|
const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
2017-01-17 14:07:57 +00:00
|
|
|
SELECTION preview;
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Add( &preview );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->SetSnapping( true );
|
|
|
|
// do not capture or auto-pan until we start placing some text
|
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
|
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
Activate();
|
|
|
|
m_frame->SetToolID( m_editModules ? ID_MODEDIT_TEXT_TOOL : ID_PCB_ADD_TEXT_BUTT,
|
|
|
|
wxCURSOR_PENCIL, _( "Add text" ) );
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
2014-02-10 09:58:58 +00:00
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
if( evt->IsCancel() || evt->IsActivate() )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
if( text )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
// Delete the old text and have another try
|
2016-06-21 15:06:28 +00:00
|
|
|
delete text;
|
2016-06-08 09:24:46 +00:00
|
|
|
text = NULL;
|
|
|
|
|
|
|
|
preview.Clear();
|
|
|
|
|
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
|
|
|
m_controls->ShowCursor( true );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
else
|
|
|
|
break;
|
2014-02-10 09:58:58 +00:00
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
if( evt->IsActivate() ) // now finish unconditionally
|
|
|
|
break;
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
else if( text && evt->Category() == TC_COMMAND )
|
|
|
|
{
|
2017-02-04 05:09:50 +00:00
|
|
|
if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) )
|
2016-06-08 09:24:46 +00:00
|
|
|
{
|
2017-02-04 05:09:50 +00:00
|
|
|
const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle(
|
|
|
|
*m_frame, *evt );
|
|
|
|
|
|
|
|
text->Rotate( text->GetPosition(), rotationAngle );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2016-06-08 09:24:46 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
|
|
|
|
{
|
|
|
|
text->Flip( text->GetPosition() );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2016-06-08 09:24:46 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2017-02-10 22:20:18 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
2017-01-09 17:29:40 +00:00
|
|
|
{
|
2017-01-11 17:22:53 +00:00
|
|
|
m_menu.ShowContextMenu();
|
2017-01-09 17:29:40 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
if( !text )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
// Init the new item attributes
|
|
|
|
if( m_editModules )
|
|
|
|
{
|
|
|
|
TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) m_frame->GetModel() );
|
2016-06-21 15:06:28 +00:00
|
|
|
|
|
|
|
textMod->SetLayer( m_frame->GetActiveLayer() );
|
2017-01-23 20:30:11 +00:00
|
|
|
textMod->SetTextSize( dsnSettings.m_ModuleTextSize );
|
2016-06-08 09:24:46 +00:00
|
|
|
textMod->SetThickness( dsnSettings.m_ModuleTextWidth );
|
2017-01-23 20:30:11 +00:00
|
|
|
textMod->SetTextPos( wxPoint( cursorPos.x, cursorPos.y ) );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
|
|
|
DialogEditModuleText textDialog( m_frame, textMod, NULL );
|
2016-09-21 09:54:58 +00:00
|
|
|
bool placing;
|
|
|
|
|
|
|
|
RunMainStack( [&]() {
|
|
|
|
placing = textDialog.ShowModal() && ( textMod->GetText().Length() > 0 );
|
|
|
|
} );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2016-09-20 08:18:44 +00:00
|
|
|
if( placing )
|
2016-06-08 09:24:46 +00:00
|
|
|
text = textMod;
|
|
|
|
else
|
|
|
|
delete textMod;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
TEXTE_PCB* textPcb = new TEXTE_PCB( m_frame->GetModel() );
|
|
|
|
// TODO we have to set IS_NEW, otherwise InstallTextPCB.. creates an undo entry :| LEGACY_CLEANUP
|
|
|
|
textPcb->SetFlags( IS_NEW );
|
|
|
|
|
|
|
|
LAYER_ID layer = m_frame->GetActiveLayer();
|
|
|
|
textPcb->SetLayer( layer );
|
|
|
|
|
|
|
|
// Set the mirrored option for layers on the BACK side of the board
|
|
|
|
if( IsBackLayer( layer ) )
|
|
|
|
textPcb->SetMirrored( true );
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
textPcb->SetTextSize( dsnSettings.m_PcbTextSize );
|
2016-06-21 15:06:28 +00:00
|
|
|
textPcb->SetThickness( dsnSettings.m_PcbTextWidth );
|
2017-01-23 20:30:11 +00:00
|
|
|
textPcb->SetTextPos( wxPoint( cursorPos.x, cursorPos.y ) );
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2016-09-21 09:54:58 +00:00
|
|
|
RunMainStack( [&]() {
|
|
|
|
getEditFrame<PCB_EDIT_FRAME>()->InstallTextPCBOptionsFrame( textPcb, NULL );
|
|
|
|
} );
|
2016-06-21 15:06:28 +00:00
|
|
|
|
|
|
|
if( textPcb->GetText().IsEmpty() )
|
|
|
|
delete textPcb;
|
|
|
|
else
|
|
|
|
text = textPcb;
|
2016-06-08 09:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( text == NULL )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
m_controls->CaptureCursor( true );
|
|
|
|
m_controls->SetAutoPan( true );
|
|
|
|
//m_controls->ShowCursor( false );
|
|
|
|
|
|
|
|
preview.Add( text );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//assert( text->GetText().Length() > 0 );
|
2017-01-23 20:30:11 +00:00
|
|
|
//assert( text->GetTextSize().x > 0 && text->GetTextSize().y > 0 );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
|
|
|
text->ClearFlags();
|
2016-06-21 15:06:28 +00:00
|
|
|
preview.Remove( text );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( text );
|
|
|
|
commit.Push( _( "Place a text" ) );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
|
|
|
m_controls->CaptureCursor( false );
|
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
|
|
|
|
text = NULL;
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
}
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
else if( text && evt->IsMotion() )
|
|
|
|
{
|
|
|
|
text->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
|
|
|
|
// Show a preview of the item
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2014-02-10 09:58:58 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
m_controls->ShowCursor( false );
|
|
|
|
m_controls->SetSnapping( false );
|
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
|
|
|
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2014-02-19 12:51:32 +00:00
|
|
|
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
|
2014-02-10 09:58:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2014-02-10 14:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
|
2014-02-11 13:38:44 +00:00
|
|
|
{
|
2014-02-24 10:17:49 +00:00
|
|
|
DIMENSION* dimension = NULL;
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2016-06-01 12:22:05 +00:00
|
|
|
int maxThickness;
|
2014-02-11 13:38:44 +00:00
|
|
|
|
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
2017-01-17 14:07:57 +00:00
|
|
|
SELECTION preview;
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Add( &preview );
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2014-02-14 08:49:49 +00:00
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->SetSnapping( true );
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
|
|
|
|
|
2014-02-11 13:38:44 +00:00
|
|
|
Activate();
|
2014-04-04 09:50:15 +00:00
|
|
|
m_frame->SetToolID( ID_PCB_DIMENSION_BUTT, wxCURSOR_PENCIL, _( "Add dimension" ) );
|
2017-02-08 09:13:43 +00:00
|
|
|
m_lineWidth = getSegmentWidth( getDrawingLayer() );
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2014-02-14 10:35:48 +00:00
|
|
|
enum DIMENSION_STEPS
|
|
|
|
{
|
|
|
|
SET_ORIGIN = 0,
|
|
|
|
SET_END,
|
|
|
|
SET_HEIGHT,
|
|
|
|
FINISHED
|
|
|
|
};
|
|
|
|
int step = SET_ORIGIN;
|
|
|
|
|
2014-02-11 13:38:44 +00:00
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
2014-02-14 08:49:49 +00:00
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
if( evt->IsCancel() || evt->IsActivate() )
|
2014-02-11 13:38:44 +00:00
|
|
|
{
|
2014-02-19 12:51:32 +00:00
|
|
|
if( step != SET_ORIGIN ) // start from the beginning
|
|
|
|
{
|
|
|
|
preview.Clear();
|
|
|
|
|
|
|
|
delete dimension;
|
|
|
|
step = SET_ORIGIN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
2014-07-09 11:50:27 +00:00
|
|
|
|
|
|
|
if( evt->IsActivate() ) // now finish unconditionally
|
|
|
|
break;
|
2014-02-11 13:38:44 +00:00
|
|
|
}
|
|
|
|
|
2014-09-01 11:48:51 +00:00
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::incWidth ) && step != SET_ORIGIN )
|
2014-02-11 13:38:44 +00:00
|
|
|
{
|
2017-02-08 09:13:43 +00:00
|
|
|
m_lineWidth += WIDTH_STEP;
|
|
|
|
dimension->SetWidth( m_lineWidth );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2014-09-01 11:48:51 +00:00
|
|
|
}
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2014-09-01 11:48:51 +00:00
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::decWidth ) && step != SET_ORIGIN )
|
|
|
|
{
|
2017-02-08 09:13:43 +00:00
|
|
|
if( m_lineWidth > WIDTH_STEP )
|
2014-09-01 11:48:51 +00:00
|
|
|
{
|
2017-02-08 09:13:43 +00:00
|
|
|
m_lineWidth -= WIDTH_STEP;
|
|
|
|
dimension->SetWidth( m_lineWidth );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2014-09-01 11:48:51 +00:00
|
|
|
}
|
2014-02-11 13:38:44 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 22:20:18 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
2017-01-09 17:29:40 +00:00
|
|
|
{
|
2017-01-11 17:22:53 +00:00
|
|
|
m_menu.ShowContextMenu();
|
2017-01-09 17:29:40 +00:00
|
|
|
}
|
|
|
|
|
2014-02-11 13:38:44 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
switch( step )
|
|
|
|
{
|
2014-02-14 10:35:48 +00:00
|
|
|
case SET_ORIGIN:
|
2014-02-11 13:38:44 +00:00
|
|
|
{
|
2017-02-08 09:13:43 +00:00
|
|
|
LAYER_ID layer = getDrawingLayer();
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
// Init the new item attributes
|
|
|
|
dimension = new DIMENSION( m_board );
|
|
|
|
dimension->SetLayer( layer );
|
|
|
|
dimension->SetOrigin( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
dimension->Text().SetTextSize( m_board->GetDesignSettings().m_PcbTextSize );
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
int width = m_board->GetDesignSettings().m_PcbTextWidth;
|
|
|
|
maxThickness = Clamp_Text_PenSize( width, dimension->Text().GetTextSize() );
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
if( width > maxThickness )
|
|
|
|
width = maxThickness;
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
dimension->Text().SetThickness( width );
|
|
|
|
dimension->SetWidth( width );
|
|
|
|
dimension->AdjustDimensionDetails();
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
preview.Add( dimension );
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
m_controls->SetAutoPan( true );
|
|
|
|
m_controls->CaptureCursor( true );
|
2014-02-11 13:38:44 +00:00
|
|
|
}
|
2014-06-24 16:17:18 +00:00
|
|
|
break;
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2014-02-14 14:13:42 +00:00
|
|
|
case SET_END:
|
2014-02-19 14:20:42 +00:00
|
|
|
dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
|
2014-02-14 14:13:42 +00:00
|
|
|
// Dimensions that have origin and end in the same spot are not valid
|
2014-02-19 14:20:42 +00:00
|
|
|
if( dimension->GetOrigin() == dimension->GetEnd() )
|
2014-02-14 14:13:42 +00:00
|
|
|
--step;
|
|
|
|
break;
|
|
|
|
|
2014-02-14 10:35:48 +00:00
|
|
|
case SET_HEIGHT:
|
2014-02-11 13:38:44 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
if( wxPoint( cursorPos.x, cursorPos.y ) != dimension->GetPosition() )
|
|
|
|
{
|
|
|
|
assert( dimension->GetOrigin() != dimension->GetEnd() );
|
|
|
|
assert( dimension->GetWidth() > 0 );
|
2014-02-14 14:52:13 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
preview.Remove( dimension );
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( dimension );
|
|
|
|
commit.Push( _( "Draw a dimension" ) );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
}
|
2014-02-11 13:38:44 +00:00
|
|
|
}
|
2014-06-24 16:17:18 +00:00
|
|
|
break;
|
2014-02-11 13:38:44 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 10:35:48 +00:00
|
|
|
if( ++step == FINISHED )
|
2014-02-19 12:51:32 +00:00
|
|
|
{
|
|
|
|
step = SET_ORIGIN;
|
|
|
|
m_controls->SetAutoPan( false );
|
2015-03-10 13:43:14 +00:00
|
|
|
m_controls->CaptureCursor( false );
|
2014-02-19 12:51:32 +00:00
|
|
|
}
|
2014-02-11 13:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsMotion() )
|
|
|
|
{
|
|
|
|
switch( step )
|
|
|
|
{
|
2014-02-14 10:35:48 +00:00
|
|
|
case SET_END:
|
2014-02-11 13:38:44 +00:00
|
|
|
dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
break;
|
|
|
|
|
2014-02-14 10:35:48 +00:00
|
|
|
case SET_HEIGHT:
|
2014-02-11 13:38:44 +00:00
|
|
|
{
|
2014-02-14 10:35:48 +00:00
|
|
|
// Calculating the direction of travel perpendicular to the selected axis
|
2014-02-11 13:38:44 +00:00
|
|
|
double angle = dimension->GetAngle() + ( M_PI / 2 );
|
|
|
|
|
|
|
|
wxPoint pos( cursorPos.x, cursorPos.y );
|
|
|
|
wxPoint delta( pos - dimension->m_featureLineDO );
|
|
|
|
double height = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
|
|
|
|
dimension->SetHeight( height );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show a preview of the item
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2014-02-11 13:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-19 12:51:32 +00:00
|
|
|
if( step != SET_ORIGIN )
|
|
|
|
delete dimension;
|
|
|
|
|
2014-02-14 08:49:49 +00:00
|
|
|
m_controls->ShowCursor( false );
|
|
|
|
m_controls->SetSnapping( false );
|
|
|
|
m_controls->SetAutoPan( false );
|
2015-03-10 13:43:14 +00:00
|
|
|
m_controls->CaptureCursor( false );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2014-02-19 12:51:32 +00:00
|
|
|
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
|
2014-02-11 13:38:44 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
|
2014-02-13 15:10:32 +00:00
|
|
|
{
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE );
|
2014-04-04 09:50:15 +00:00
|
|
|
m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add zones" ) );
|
|
|
|
|
2017-02-06 05:59:55 +00:00
|
|
|
return drawZone( false, ZONE_MODE::ADD );
|
2014-02-14 09:47:43 +00:00
|
|
|
}
|
2014-02-13 15:10:32 +00:00
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int DRAWING_TOOL::DrawKeepout( const TOOL_EVENT& aEvent )
|
2014-02-14 09:47:43 +00:00
|
|
|
{
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::KEEPOUT );
|
2014-04-04 09:50:15 +00:00
|
|
|
m_frame->SetToolID( ID_PCB_KEEPOUT_AREA_BUTT, wxCURSOR_PENCIL, _( "Add keepout" ) );
|
|
|
|
|
2017-02-06 05:59:55 +00:00
|
|
|
return drawZone( true, ZONE_MODE::ADD );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DRAWING_TOOL::DrawZoneCutout( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE );
|
|
|
|
m_frame->SetToolID( ID_PCB_KEEPOUT_AREA_BUTT, wxCURSOR_PENCIL, _( "Add zone cutout" ) );
|
|
|
|
|
|
|
|
return drawZone( false, ZONE_MODE::CUTOUT );
|
2014-02-14 09:47:43 +00:00
|
|
|
}
|
2014-02-13 15:10:32 +00:00
|
|
|
|
|
|
|
|
2017-02-06 07:37:13 +00:00
|
|
|
int DRAWING_TOOL::DrawSimilarZone( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE );
|
|
|
|
m_frame->SetToolID( ID_PCB_KEEPOUT_AREA_BUTT, wxCURSOR_PENCIL, _( "Add similar zone" ) );
|
|
|
|
|
|
|
|
return drawZone( false, ZONE_MODE::SIMILAR );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
if( !m_frame->GetModel() )
|
2015-09-13 16:44:07 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
DIALOG_DXF_IMPORT dlg( m_frame );
|
|
|
|
int dlgResult = dlg.ShowModal();
|
|
|
|
|
|
|
|
const std::list<BOARD_ITEM*>& list = dlg.GetImportedItems();
|
|
|
|
|
2015-07-30 11:49:36 +00:00
|
|
|
if( dlgResult != wxID_OK || list.empty() )
|
2014-07-09 13:02:56 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
2016-11-04 21:29:47 +00:00
|
|
|
VECTOR2I delta = cursorPos - list.front()->GetPosition();
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
2017-01-17 14:07:57 +00:00
|
|
|
SELECTION preview;
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
// Build the undo list & add items to the current view
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : list )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2016-12-12 08:06:32 +00:00
|
|
|
assert( item->Type() == PCB_LINE_T || item->Type() == PCB_TEXT_T );
|
2016-11-04 21:29:47 +00:00
|
|
|
preview.Add( item );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 21:29:47 +00:00
|
|
|
BOARD_ITEM* firstItem = preview.Front();
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Add( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2014-07-09 13:02:56 +00:00
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->SetSnapping( true );
|
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
Activate();
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
|
|
|
cursorPos = m_controls->GetCursorPosition();
|
|
|
|
|
|
|
|
if( evt->IsMotion() )
|
|
|
|
{
|
|
|
|
delta = cursorPos - firstItem->GetPosition();
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : preview )
|
2016-11-04 21:29:47 +00:00
|
|
|
item->Move( wxPoint( delta.x, delta.y ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->Category() == TC_COMMAND )
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
// TODO it should be handled by EDIT_TOOL, so add items and select?
|
2017-02-04 05:09:50 +00:00
|
|
|
if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2017-02-04 05:09:50 +00:00
|
|
|
const auto rotationPoint = wxPoint( cursorPos.x, cursorPos.y );
|
|
|
|
const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle(
|
|
|
|
*m_frame, *evt );
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : preview )
|
2017-02-04 05:09:50 +00:00
|
|
|
{
|
|
|
|
item->Rotate( rotationPoint, rotationAngle );
|
|
|
|
}
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
|
|
|
|
{
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : preview )
|
2016-11-04 21:29:47 +00:00
|
|
|
item->Flip( wxPoint( cursorPos.x, cursorPos.y ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsCancel() || evt->IsActivate() )
|
|
|
|
{
|
2017-01-18 21:04:35 +00:00
|
|
|
preview.FreeItems();
|
2014-07-09 13:02:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-10 22:20:18 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
2017-01-09 17:29:40 +00:00
|
|
|
{
|
2017-01-11 17:22:53 +00:00
|
|
|
m_menu.ShowContextMenu();
|
2017-01-09 17:29:40 +00:00
|
|
|
}
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
// Place the drawing
|
2016-06-08 09:24:46 +00:00
|
|
|
BOARD_ITEM_CONTAINER* parent = m_frame->GetModel();
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : preview )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
if( m_editModules )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2015-08-03 19:11:59 +00:00
|
|
|
// Modules use different types for the same things,
|
|
|
|
// so we need to convert imported items to appropriate classes.
|
2016-09-30 04:31:59 +00:00
|
|
|
BOARD_ITEM* converted = NULL;
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2015-08-03 19:11:59 +00:00
|
|
|
case PCB_TEXT_T:
|
2016-09-27 11:35:03 +00:00
|
|
|
{
|
|
|
|
TEXTE_PCB* text = static_cast<TEXTE_PCB*>( item );
|
|
|
|
TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) parent );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2016-09-27 11:35:03 +00:00
|
|
|
// Assignment operator also copies the item PCB_TEXT_T type,
|
|
|
|
// so it cannot be added to a module which handles PCB_MODULE_TEXT_T
|
|
|
|
textMod->SetText( text->GetText() );
|
2017-01-23 20:30:11 +00:00
|
|
|
#if 0
|
|
|
|
textMod->SetTextSize( text->GetTextSize() );
|
2016-09-27 11:35:03 +00:00
|
|
|
textMod->SetThickness( text->GetThickness() );
|
2017-01-23 20:30:11 +00:00
|
|
|
textMod->SetOrientation( text->GetTextAngle() );
|
|
|
|
textMod->SetTextPos( text->GetTextPos() );
|
|
|
|
textMod->SetTextSize( text->GetTextSize() );
|
|
|
|
textMod->SetVisible( text->GetVisible() );
|
2016-09-27 11:35:03 +00:00
|
|
|
textMod->SetMirrored( text->IsMirrored() );
|
|
|
|
textMod->SetItalic( text->IsItalic() );
|
|
|
|
textMod->SetBold( text->IsBold() );
|
|
|
|
textMod->SetHorizJustify( text->GetHorizJustify() );
|
|
|
|
textMod->SetVertJustify( text->GetVertJustify() );
|
|
|
|
textMod->SetMultilineAllowed( text->IsMultilineAllowed() );
|
2017-01-23 20:30:11 +00:00
|
|
|
#else
|
|
|
|
textMod->EDA_TEXT::SetEffects( *text );
|
|
|
|
textMod->SetLocalCoord(); // using changed SetTexPos() via SetEffects()
|
|
|
|
#endif
|
2016-09-27 11:35:03 +00:00
|
|
|
converted = textMod;
|
2014-07-09 13:02:56 +00:00
|
|
|
break;
|
2016-09-27 11:35:03 +00:00
|
|
|
}
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2015-08-03 19:11:59 +00:00
|
|
|
case PCB_LINE_T:
|
2016-09-27 11:35:03 +00:00
|
|
|
{
|
|
|
|
DRAWSEGMENT* seg = static_cast<DRAWSEGMENT*>( item );
|
|
|
|
EDGE_MODULE* modSeg = new EDGE_MODULE( (MODULE*) parent );
|
|
|
|
|
|
|
|
// Assignment operator also copies the item PCB_LINE_T type,
|
|
|
|
// so it cannot be added to a module which handles PCB_MODULE_EDGE_T
|
|
|
|
modSeg->SetWidth( seg->GetWidth() );
|
|
|
|
modSeg->SetStart( seg->GetStart() );
|
|
|
|
modSeg->SetEnd( seg->GetEnd() );
|
2016-09-27 18:54:51 +00:00
|
|
|
modSeg->SetAngle( seg->GetAngle() );
|
2016-09-27 11:35:03 +00:00
|
|
|
modSeg->SetShape( seg->GetShape() );
|
|
|
|
modSeg->SetType( seg->GetType() );
|
|
|
|
modSeg->SetBezControl1( seg->GetBezControl1() );
|
|
|
|
modSeg->SetBezControl2( seg->GetBezControl2() );
|
|
|
|
modSeg->SetBezierPoints( seg->GetBezierPoints() );
|
|
|
|
modSeg->SetPolyPoints( seg->GetPolyPoints() );
|
|
|
|
converted = modSeg;
|
2014-07-09 13:02:56 +00:00
|
|
|
break;
|
2016-09-27 11:35:03 +00:00
|
|
|
}
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
assert( false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-30 04:31:59 +00:00
|
|
|
if( converted )
|
|
|
|
converted->SetLayer( item->GetLayer() );
|
|
|
|
|
2015-08-03 19:11:59 +00:00
|
|
|
delete item;
|
2016-06-08 09:24:46 +00:00
|
|
|
item = converted;
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
2016-09-30 04:31:59 +00:00
|
|
|
if( item )
|
|
|
|
commit.Add( item );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Push( _( "Place a DXF drawing" ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
preview.Clear();
|
|
|
|
|
|
|
|
m_controls->ShowCursor( false );
|
|
|
|
m_controls->SetSnapping( false );
|
|
|
|
m_controls->SetAutoPan( false );
|
2015-03-10 13:43:14 +00:00
|
|
|
m_controls->CaptureCursor( false );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
|
|
|
assert( m_editModules );
|
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR );
|
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
Activate();
|
|
|
|
m_frame->SetToolID( ID_MODEDIT_ANCHOR_TOOL, wxCURSOR_PENCIL,
|
|
|
|
_( "Place the footprint anchor" ) );
|
|
|
|
|
2015-03-10 13:43:14 +00:00
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->SetSnapping( true );
|
|
|
|
m_controls->SetAutoPan( true );
|
|
|
|
m_controls->CaptureCursor( false );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
|
|
|
if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
MODULE* module = (MODULE*) m_frame->GetModel();
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
commit.Modify( module );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
|
|
|
// set the new relative internal local coordinates of footprint items
|
2015-03-10 13:43:14 +00:00
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
2016-06-08 09:24:46 +00:00
|
|
|
wxPoint moveVector = module->GetPosition() - wxPoint( cursorPos.x, cursorPos.y );
|
|
|
|
module->MoveAnchorPosition( moveVector );
|
2016-06-21 15:06:28 +00:00
|
|
|
|
|
|
|
commit.Push( _( "Move the footprint reference anchor" ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
// Usually, we do not need to change twice the anchor position,
|
|
|
|
// so deselect the active tool
|
|
|
|
break;
|
|
|
|
}
|
2017-02-10 22:20:18 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
2017-01-09 17:29:40 +00:00
|
|
|
{
|
2017-01-11 17:22:53 +00:00
|
|
|
m_menu.ShowContextMenu();
|
2017-01-09 17:29:40 +00:00
|
|
|
}
|
2014-07-09 12:01:06 +00:00
|
|
|
else if( evt->IsCancel() || evt->IsActivate() )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-10 13:43:14 +00:00
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
|
|
|
m_controls->SetSnapping( false );
|
|
|
|
m_controls->ShowCursor( false );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
|
|
|
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic,
|
|
|
|
boost::optional<VECTOR2D> aStartingPoint )
|
2014-02-11 16:15:33 +00:00
|
|
|
{
|
2014-02-14 09:47:43 +00:00
|
|
|
// Only two shapes are currently supported
|
|
|
|
assert( aShape == S_SEGMENT || aShape == S_CIRCLE );
|
|
|
|
|
2014-02-19 12:51:32 +00:00
|
|
|
DRAWSEGMENT line45;
|
2014-02-17 10:33:03 +00:00
|
|
|
|
2014-02-11 16:15:33 +00:00
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
2017-01-17 14:07:57 +00:00
|
|
|
SELECTION preview;
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Add( &preview );
|
2014-02-11 16:15:33 +00:00
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2014-02-14 09:47:43 +00:00
|
|
|
m_controls->ShowCursor( true );
|
2014-02-14 08:49:49 +00:00
|
|
|
m_controls->SetSnapping( true );
|
2014-02-11 16:15:33 +00:00
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
2014-02-17 10:33:03 +00:00
|
|
|
bool direction45 = false; // 45 degrees only mode
|
2014-07-09 12:01:06 +00:00
|
|
|
bool started = false;
|
2014-07-09 13:10:32 +00:00
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
|
|
|
|
|
|
|
if( aStartingPoint )
|
|
|
|
{
|
|
|
|
// Init the new item attributes
|
|
|
|
aGraphic->SetShape( (STROKE_T) aShape );
|
2015-02-15 22:21:52 +00:00
|
|
|
aGraphic->SetWidth( m_lineWidth );
|
2014-07-09 13:10:32 +00:00
|
|
|
aGraphic->SetStart( wxPoint( aStartingPoint->x, aStartingPoint->y ) );
|
|
|
|
aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
2017-02-08 09:13:43 +00:00
|
|
|
aGraphic->SetLayer( getDrawingLayer() );
|
2014-07-09 13:10:32 +00:00
|
|
|
|
|
|
|
if( aShape == S_SEGMENT )
|
|
|
|
line45 = *aGraphic; // used only for direction 45 mode with lines
|
|
|
|
|
|
|
|
preview.Add( aGraphic );
|
|
|
|
m_controls->SetAutoPan( true );
|
2015-03-10 13:43:14 +00:00
|
|
|
m_controls->CaptureCursor( true );
|
2014-07-09 13:10:32 +00:00
|
|
|
|
|
|
|
started = true;
|
|
|
|
}
|
2014-02-17 10:33:03 +00:00
|
|
|
|
2014-02-11 16:15:33 +00:00
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
2014-07-09 13:10:32 +00:00
|
|
|
cursorPos = m_controls->GetCursorPosition();
|
2014-02-11 16:15:33 +00:00
|
|
|
|
2017-01-10 11:16:47 +00:00
|
|
|
// 45 degree angle constraint enabled with an option and toggled with Ctrl
|
|
|
|
const bool limit45 = ( g_Segments_45_Only != !!( evt->Modifier( MD_CTRL ) ) );
|
|
|
|
|
|
|
|
if( direction45 != limit45 && started && aShape == S_SEGMENT )
|
2014-02-17 10:33:03 +00:00
|
|
|
{
|
2017-01-10 11:16:47 +00:00
|
|
|
direction45 = limit45;
|
2014-02-17 10:33:03 +00:00
|
|
|
|
|
|
|
if( direction45 )
|
|
|
|
{
|
|
|
|
preview.Add( &line45 );
|
2014-07-09 12:01:06 +00:00
|
|
|
make45DegLine( aGraphic, &line45 );
|
2014-02-17 10:33:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
preview.Remove( &line45 );
|
2014-07-09 12:01:06 +00:00
|
|
|
aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
2014-02-17 10:33:03 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
m_view->Update( &preview );
|
2014-02-17 10:33:03 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
if( evt->IsCancel() || evt->IsActivate() )
|
2014-02-14 14:13:42 +00:00
|
|
|
{
|
2014-02-19 14:20:42 +00:00
|
|
|
preview.Clear();
|
2017-02-08 09:13:43 +00:00
|
|
|
m_view->Update( &preview );
|
2014-07-09 12:01:06 +00:00
|
|
|
delete aGraphic;
|
2014-07-09 13:02:56 +00:00
|
|
|
aGraphic = NULL;
|
2014-07-09 12:01:06 +00:00
|
|
|
break;
|
2014-02-14 14:13:42 +00:00
|
|
|
}
|
2017-02-08 09:13:43 +00:00
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::layerChanged ) )
|
|
|
|
{
|
|
|
|
aGraphic->SetLayer( getDrawingLayer() );
|
|
|
|
m_view->Update( &preview );
|
|
|
|
}
|
2017-01-09 17:29:40 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2017-01-11 17:22:53 +00:00
|
|
|
m_menu.ShowContextMenu();
|
2017-01-09 17:29:40 +00:00
|
|
|
}
|
2015-07-03 18:58:13 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
|
2014-02-11 16:15:33 +00:00
|
|
|
{
|
2014-07-09 12:01:06 +00:00
|
|
|
if( !started )
|
2014-02-14 09:47:43 +00:00
|
|
|
{
|
2017-02-08 09:13:43 +00:00
|
|
|
// Init the new item attributes
|
|
|
|
aGraphic->SetShape( (STROKE_T) aShape );
|
|
|
|
aGraphic->SetWidth( m_lineWidth );
|
|
|
|
aGraphic->SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
aGraphic->SetLayer( getDrawingLayer() );
|
2014-02-14 09:47:43 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
if( aShape == S_SEGMENT )
|
|
|
|
line45 = *aGraphic; // used only for direction 45 mode with lines
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
preview.Add( aGraphic );
|
|
|
|
m_controls->SetAutoPan( true );
|
|
|
|
m_controls->CaptureCursor( true );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
started = true;
|
2014-02-14 09:47:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-03 18:58:13 +00:00
|
|
|
if( aGraphic->GetEnd() == aGraphic->GetStart() ||
|
|
|
|
( evt->IsDblClick( BUT_LEFT ) && aShape == S_SEGMENT ) )
|
2017-02-08 09:13:43 +00:00
|
|
|
// User has clicked twice in the same spot
|
|
|
|
{ // a clear sign that the current drawing is finished
|
2016-06-08 09:24:46 +00:00
|
|
|
// Now we have to add the helper line as well
|
2015-07-03 18:58:13 +00:00
|
|
|
if( direction45 )
|
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
BOARD_ITEM_CONTAINER* parent = m_frame->GetModel();
|
|
|
|
DRAWSEGMENT* l = m_editModules ? new EDGE_MODULE( (MODULE*) parent )
|
|
|
|
: new DRAWSEGMENT;
|
2015-10-01 13:52:45 +00:00
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
// Copy coordinates, layer, etc.
|
|
|
|
*static_cast<DRAWSEGMENT*>( l ) = line45;
|
|
|
|
l->SetEnd( aGraphic->GetStart() );
|
2015-10-01 13:52:45 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
commit.Add( l );
|
|
|
|
commit.Push( _( "Draw a line" ) );
|
2015-07-03 18:58:13 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 13:52:45 +00:00
|
|
|
delete aGraphic;
|
|
|
|
aGraphic = NULL;
|
2015-07-03 18:58:13 +00:00
|
|
|
}
|
2014-07-09 12:01:06 +00:00
|
|
|
|
|
|
|
preview.Clear();
|
|
|
|
break;
|
2014-02-14 09:47:43 +00:00
|
|
|
}
|
2014-02-11 16:15:33 +00:00
|
|
|
}
|
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
else if( evt->IsMotion() )
|
2014-02-11 16:15:33 +00:00
|
|
|
{
|
2014-02-14 09:47:43 +00:00
|
|
|
// 45 degree lines
|
2014-02-17 10:33:03 +00:00
|
|
|
if( direction45 && aShape == S_SEGMENT )
|
2014-07-09 12:01:06 +00:00
|
|
|
make45DegLine( aGraphic, &line45 );
|
2014-02-14 09:47:43 +00:00
|
|
|
else
|
2014-07-09 12:01:06 +00:00
|
|
|
aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
2014-02-14 09:47:43 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
m_view->Update( &preview );
|
2014-02-11 16:15:33 +00:00
|
|
|
}
|
2014-02-17 10:33:03 +00:00
|
|
|
|
2014-08-04 12:23:19 +00:00
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::incWidth ) )
|
|
|
|
{
|
2015-02-15 22:21:52 +00:00
|
|
|
m_lineWidth += WIDTH_STEP;
|
|
|
|
aGraphic->SetWidth( m_lineWidth );
|
2017-02-08 09:13:43 +00:00
|
|
|
line45.SetWidth( m_lineWidth );
|
|
|
|
m_view->Update( &preview );
|
2014-08-04 12:23:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::decWidth ) && ( m_lineWidth > WIDTH_STEP ) )
|
2014-08-04 12:23:19 +00:00
|
|
|
{
|
2017-02-08 09:13:43 +00:00
|
|
|
m_lineWidth -= WIDTH_STEP;
|
|
|
|
aGraphic->SetWidth( m_lineWidth );
|
|
|
|
line45.SetWidth( m_lineWidth );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2017-02-08 09:13:43 +00:00
|
|
|
}
|
2014-02-11 16:15:33 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 09:47:43 +00:00
|
|
|
m_controls->ShowCursor( false );
|
2014-02-14 08:49:49 +00:00
|
|
|
m_controls->SetSnapping( false );
|
|
|
|
m_controls->SetAutoPan( false );
|
2015-03-10 13:43:14 +00:00
|
|
|
m_controls->CaptureCursor( false );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
return started;
|
|
|
|
}
|
2014-02-11 16:15:33 +00:00
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
|
|
|
bool clockwise = true; // drawing direction of the arc
|
|
|
|
double startAngle = 0.0f; // angle of the first arc line
|
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
// Line from the arc center to its origin, to visualize its radius
|
2014-07-09 12:01:06 +00:00
|
|
|
DRAWSEGMENT helperLine;
|
|
|
|
helperLine.SetShape( S_SEGMENT );
|
|
|
|
helperLine.SetLayer( Dwgs_User );
|
|
|
|
helperLine.SetWidth( 1 );
|
|
|
|
|
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
2017-01-17 14:07:57 +00:00
|
|
|
SELECTION preview;
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Add( &preview );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2014-07-09 12:01:06 +00:00
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->SetSnapping( true );
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
enum ARC_STEPS
|
|
|
|
{
|
|
|
|
SET_ORIGIN = 0,
|
|
|
|
SET_END,
|
|
|
|
SET_ANGLE,
|
|
|
|
FINISHED
|
|
|
|
};
|
|
|
|
int step = SET_ORIGIN;
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
|
|
|
cursorPos = m_controls->GetCursorPosition();
|
|
|
|
|
|
|
|
if( evt->IsCancel() || evt->IsActivate() )
|
|
|
|
{
|
|
|
|
preview.Clear();
|
|
|
|
delete aGraphic;
|
2014-07-09 13:02:56 +00:00
|
|
|
aGraphic = NULL;
|
2014-07-09 12:01:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-09 17:29:40 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2017-01-11 17:22:53 +00:00
|
|
|
m_menu.ShowContextMenu();
|
2017-01-09 17:29:40 +00:00
|
|
|
}
|
2014-07-09 12:01:06 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
switch( step )
|
|
|
|
{
|
|
|
|
case SET_ORIGIN:
|
|
|
|
{
|
2017-02-08 09:13:43 +00:00
|
|
|
LAYER_ID layer = getDrawingLayer();
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
if( layer == Edge_Cuts ) // dimensions are not allowed on EdgeCuts
|
|
|
|
layer = Dwgs_User;
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
// Init the new item attributes
|
|
|
|
aGraphic->SetShape( S_ARC );
|
|
|
|
aGraphic->SetAngle( 0.0 );
|
|
|
|
aGraphic->SetWidth( m_lineWidth );
|
|
|
|
aGraphic->SetCenter( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
aGraphic->SetLayer( layer );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
helperLine.SetStart( aGraphic->GetCenter() );
|
|
|
|
helperLine.SetEnd( aGraphic->GetCenter() );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
preview.Add( aGraphic );
|
|
|
|
preview.Add( &helperLine );
|
|
|
|
|
|
|
|
m_controls->SetAutoPan( true );
|
|
|
|
m_controls->CaptureCursor( true );
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SET_END:
|
|
|
|
{
|
|
|
|
if( wxPoint( cursorPos.x, cursorPos.y ) != aGraphic->GetCenter() )
|
|
|
|
{
|
|
|
|
VECTOR2D startLine( aGraphic->GetArcStart() - aGraphic->GetCenter() );
|
|
|
|
startAngle = startLine.Angle();
|
|
|
|
aGraphic->SetArcStart( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
--step; // one another chance to draw a proper arc
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SET_ANGLE:
|
|
|
|
{
|
2015-06-02 18:16:55 +00:00
|
|
|
if( wxPoint( cursorPos.x, cursorPos.y ) != aGraphic->GetArcStart() && aGraphic->GetAngle() != 0 )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
|
|
|
assert( aGraphic->GetArcStart() != aGraphic->GetArcEnd() );
|
|
|
|
assert( aGraphic->GetWidth() > 0 );
|
|
|
|
|
|
|
|
preview.Remove( aGraphic );
|
|
|
|
preview.Remove( &helperLine );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
--step; // one another chance to draw a proper arc
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ++step == FINISHED )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsMotion() )
|
|
|
|
{
|
|
|
|
switch( step )
|
|
|
|
{
|
|
|
|
case SET_END:
|
|
|
|
helperLine.SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
aGraphic->SetArcStart( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SET_ANGLE:
|
|
|
|
{
|
|
|
|
VECTOR2D endLine( wxPoint( cursorPos.x, cursorPos.y ) - aGraphic->GetCenter() );
|
|
|
|
double newAngle = RAD2DECIDEG( endLine.Angle() - startAngle );
|
|
|
|
|
|
|
|
// Adjust the new angle to (counter)clockwise setting
|
|
|
|
if( clockwise && newAngle < 0.0 )
|
|
|
|
newAngle += 3600.0;
|
|
|
|
else if( !clockwise && newAngle > 0.0 )
|
|
|
|
newAngle -= 3600.0;
|
|
|
|
|
|
|
|
aGraphic->SetAngle( newAngle );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2014-08-04 12:23:19 +00:00
|
|
|
|
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::incWidth ) )
|
|
|
|
{
|
2017-02-08 09:13:43 +00:00
|
|
|
m_lineWidth += WIDTH_STEP;
|
|
|
|
aGraphic->SetWidth( m_lineWidth );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2014-08-04 12:23:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::decWidth ) && m_lineWidth > WIDTH_STEP )
|
2014-08-04 12:23:19 +00:00
|
|
|
{
|
2017-02-08 09:13:43 +00:00
|
|
|
m_lineWidth -= WIDTH_STEP;
|
|
|
|
aGraphic->SetWidth( m_lineWidth );
|
|
|
|
m_view->Update( &preview );
|
2014-08-04 12:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::arcPosture ) )
|
|
|
|
{
|
|
|
|
if( clockwise )
|
|
|
|
aGraphic->SetAngle( aGraphic->GetAngle() - 3600.0 );
|
|
|
|
else
|
|
|
|
aGraphic->SetAngle( aGraphic->GetAngle() + 3600.0 );
|
|
|
|
|
|
|
|
clockwise = !clockwise;
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2014-08-04 12:23:19 +00:00
|
|
|
}
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_controls->ShowCursor( false );
|
|
|
|
m_controls->SetSnapping( false );
|
|
|
|
m_controls->SetAutoPan( false );
|
2015-03-10 13:43:14 +00:00
|
|
|
m_controls->CaptureCursor( false );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
|
|
|
return ( step > SET_ORIGIN );
|
2014-02-11 16:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-06 05:04:04 +00:00
|
|
|
std::unique_ptr<ZONE_CONTAINER> DRAWING_TOOL::createNewZone(
|
|
|
|
bool aKeepout )
|
|
|
|
{
|
|
|
|
const auto& board = *getModel<BOARD>();
|
|
|
|
|
|
|
|
// Get the current default settings for zones
|
|
|
|
ZONE_SETTINGS zoneInfo = m_frame->GetZoneSettings();
|
|
|
|
zoneInfo.m_CurrentZone_Layer = m_frame->GetScreen()->m_Active_Layer;
|
|
|
|
zoneInfo.m_NetcodeSelection = board.GetHighLightNetCode();
|
|
|
|
zoneInfo.SetIsKeepout( aKeepout );
|
|
|
|
|
|
|
|
m_controls->SetAutoPan( true );
|
|
|
|
m_controls->CaptureCursor( true );
|
|
|
|
|
|
|
|
// Show options dialog
|
|
|
|
ZONE_EDIT_T dialogResult;
|
|
|
|
|
|
|
|
if( aKeepout )
|
|
|
|
dialogResult = InvokeKeepoutAreaEditor( m_frame, &zoneInfo );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( IsCopperLayer( zoneInfo.m_CurrentZone_Layer ) )
|
|
|
|
dialogResult = InvokeCopperZonesEditor( m_frame, &zoneInfo );
|
|
|
|
else
|
|
|
|
dialogResult = InvokeNonCopperZonesEditor( m_frame, NULL, &zoneInfo );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( dialogResult == ZONE_ABORT )
|
|
|
|
{
|
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto newZone = std::make_unique<ZONE_CONTAINER>( m_board );
|
|
|
|
|
|
|
|
// Apply the selected settings
|
|
|
|
zoneInfo.ExportSetting( *newZone );
|
|
|
|
|
|
|
|
return newZone;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-06 05:59:55 +00:00
|
|
|
std::unique_ptr<ZONE_CONTAINER> DRAWING_TOOL::createZoneFromExisting(
|
|
|
|
const ZONE_CONTAINER& aSrcZone )
|
|
|
|
{
|
|
|
|
auto newZone = std::make_unique<ZONE_CONTAINER>( m_board );
|
|
|
|
|
|
|
|
ZONE_SETTINGS zoneSettings;
|
|
|
|
zoneSettings << aSrcZone;
|
|
|
|
|
|
|
|
zoneSettings.ExportSetting( *newZone );
|
|
|
|
|
|
|
|
return newZone;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-10 22:20:18 +00:00
|
|
|
bool DRAWING_TOOL::getSourceZoneForAction( ZONE_MODE aMode, ZONE_CONTAINER*& aZone )
|
2017-02-06 05:59:55 +00:00
|
|
|
{
|
|
|
|
aZone = nullptr;
|
|
|
|
|
|
|
|
// not an action that needs a source zone
|
|
|
|
if( aMode == ZONE_MODE::ADD )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
const SELECTION& selection = selTool->GetSelection();
|
|
|
|
|
|
|
|
if( selection.Empty() )
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionCursor, true );
|
|
|
|
|
|
|
|
// we want a single zone
|
|
|
|
if( selection.Size() != 1 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
aZone = dyn_cast<ZONE_CONTAINER*>( selection[0] );
|
|
|
|
|
|
|
|
// expected a zone, but didn't get one
|
|
|
|
if( !aZone )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-10 22:20:18 +00:00
|
|
|
void DRAWING_TOOL::performZoneCutout( ZONE_CONTAINER& aExistingZone, ZONE_CONTAINER& aCutout )
|
2017-02-06 05:59:55 +00:00
|
|
|
{
|
|
|
|
// Copy cutout corners into existing zone
|
2017-02-10 22:20:18 +00:00
|
|
|
for( int ii = 0; ii < aCutout.GetNumCorners(); ii++ )
|
2017-02-06 05:59:55 +00:00
|
|
|
{
|
2017-02-10 22:20:18 +00:00
|
|
|
aExistingZone.AppendCorner( aCutout.GetCornerPosition( ii ) );
|
2017-02-06 05:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close the current corner list
|
|
|
|
aExistingZone.Outline()->CloseLastContour();
|
|
|
|
|
|
|
|
m_board->OnAreaPolygonModified( nullptr, &aExistingZone );
|
|
|
|
|
|
|
|
// Re-fill if needed
|
|
|
|
if( aExistingZone.IsFilled() )
|
|
|
|
{
|
|
|
|
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
|
|
|
|
auto& selection = selTool->GetSelection();
|
|
|
|
|
|
|
|
selection.Clear();
|
|
|
|
selection.Add( &aExistingZone );
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::zoneFill, true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode )
|
2014-02-13 11:46:39 +00:00
|
|
|
{
|
2017-02-06 05:04:04 +00:00
|
|
|
std::unique_ptr<ZONE_CONTAINER> zone;
|
2014-02-19 12:51:32 +00:00
|
|
|
DRAWSEGMENT line45;
|
2014-02-24 10:17:49 +00:00
|
|
|
DRAWSEGMENT* helperLine = NULL; // we will need more than one helper line
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2017-02-06 05:59:55 +00:00
|
|
|
ZONE_CONTAINER* sourceZone = nullptr;
|
|
|
|
|
|
|
|
// get a source zone, if we need one
|
|
|
|
if( !getSourceZoneForAction( aMode, sourceZone ) )
|
|
|
|
return 0;
|
2014-02-13 11:46:39 +00:00
|
|
|
|
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
2017-01-17 14:07:57 +00:00
|
|
|
SELECTION preview;
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Add( &preview );
|
2014-02-13 11:46:39 +00:00
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2014-02-14 09:47:43 +00:00
|
|
|
m_controls->ShowCursor( true );
|
2014-02-14 08:49:49 +00:00
|
|
|
m_controls->SetSnapping( true );
|
2014-02-13 11:46:39 +00:00
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
2014-02-14 09:47:43 +00:00
|
|
|
VECTOR2I origin;
|
|
|
|
int numPoints = 0;
|
2014-02-17 10:33:03 +00:00
|
|
|
bool direction45 = false; // 45 degrees only mode
|
2014-02-14 09:47:43 +00:00
|
|
|
|
2014-02-13 11:46:39 +00:00
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
2014-02-14 09:47:43 +00:00
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
2014-02-13 11:46:39 +00:00
|
|
|
|
2014-02-17 10:33:03 +00:00
|
|
|
// Enable 45 degrees lines only mode by holding control
|
|
|
|
if( direction45 != ( evt->Modifier( MD_CTRL ) && numPoints > 0 ) )
|
|
|
|
{
|
|
|
|
direction45 = evt->Modifier( MD_CTRL );
|
|
|
|
|
|
|
|
if( direction45 )
|
|
|
|
{
|
|
|
|
preview.Add( &line45 );
|
|
|
|
make45DegLine( helperLine, &line45 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
preview.Remove( &line45 );
|
|
|
|
helperLine->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
}
|
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
m_view->Update( &preview );
|
2014-02-17 10:33:03 +00:00
|
|
|
}
|
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
if( evt->IsCancel() || evt->IsActivate() )
|
2014-02-13 11:46:39 +00:00
|
|
|
{
|
2014-02-19 12:51:32 +00:00
|
|
|
if( numPoints > 0 ) // cancel the current zone
|
|
|
|
{
|
2017-02-06 05:04:04 +00:00
|
|
|
zone = nullptr;
|
2014-02-19 12:51:32 +00:00
|
|
|
m_controls->SetAutoPan( false );
|
2015-03-10 13:43:14 +00:00
|
|
|
m_controls->CaptureCursor( false );
|
2014-02-19 12:51:32 +00:00
|
|
|
|
|
|
|
if( direction45 )
|
2014-03-18 10:33:49 +00:00
|
|
|
{
|
2014-02-19 12:51:32 +00:00
|
|
|
preview.Remove( &line45 );
|
2014-03-18 10:33:49 +00:00
|
|
|
direction45 = false;
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:04:35 +00:00
|
|
|
preview.FreeItems();
|
2017-02-08 09:13:43 +00:00
|
|
|
m_view->Update( &preview );
|
2014-02-19 12:51:32 +00:00
|
|
|
|
|
|
|
numPoints = 0;
|
|
|
|
}
|
|
|
|
else // there is no zone currently drawn - just stop the tool
|
|
|
|
break;
|
2014-07-09 11:50:27 +00:00
|
|
|
|
|
|
|
if( evt->IsActivate() ) // now finish unconditionally
|
|
|
|
break;
|
2014-02-13 11:46:39 +00:00
|
|
|
}
|
2017-01-09 17:29:40 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2017-01-11 17:22:53 +00:00
|
|
|
m_menu.ShowContextMenu();
|
2017-01-09 17:29:40 +00:00
|
|
|
}
|
2015-07-03 18:58:13 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
|
2014-02-13 11:46:39 +00:00
|
|
|
{
|
2014-02-19 12:51:32 +00:00
|
|
|
// Check if it is double click / closing line (so we have to finish the zone)
|
2015-07-28 15:33:18 +00:00
|
|
|
if( evt->IsDblClick( BUT_LEFT ) || ( numPoints > 0 && cursorPos == origin ) )
|
2014-02-13 11:46:39 +00:00
|
|
|
{
|
2014-02-19 12:51:32 +00:00
|
|
|
if( numPoints > 2 ) // valid zone consists of more than 2 points
|
2014-02-14 09:47:43 +00:00
|
|
|
{
|
2014-02-14 14:52:13 +00:00
|
|
|
assert( zone->GetNumCorners() > 2 );
|
|
|
|
|
2014-02-14 09:47:43 +00:00
|
|
|
// Finish the zone
|
2015-06-30 11:55:30 +00:00
|
|
|
if( direction45 )
|
|
|
|
zone->AppendCorner( cursorPos == origin ? line45.GetStart() : line45.GetEnd() );
|
|
|
|
|
2014-02-14 09:47:43 +00:00
|
|
|
zone->Outline()->CloseLastContour();
|
|
|
|
zone->Outline()->RemoveNullSegments();
|
|
|
|
|
|
|
|
if( !aKeepout )
|
2017-02-06 05:04:04 +00:00
|
|
|
static_cast<PCB_EDIT_FRAME*>( m_frame )->Fill_Zone( zone.get() );
|
2014-02-14 09:47:43 +00:00
|
|
|
|
2017-02-10 22:20:18 +00:00
|
|
|
if( aMode == ZONE_MODE::CUTOUT )
|
2017-02-06 05:59:55 +00:00
|
|
|
{
|
|
|
|
// For cutouts, subtract from the source
|
|
|
|
commit.Modify( sourceZone );
|
|
|
|
|
|
|
|
performZoneCutout( *sourceZone, *zone );
|
|
|
|
|
|
|
|
commit.Push( _( "Add a zone cutout" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Add the zone as a new board item
|
|
|
|
commit.Add( zone.release() );
|
|
|
|
commit.Push( _( "Draw a zone" ) );
|
|
|
|
}
|
2014-03-18 10:33:49 +00:00
|
|
|
}
|
2014-02-14 09:47:43 +00:00
|
|
|
|
2017-02-06 05:04:04 +00:00
|
|
|
// if kept, this was released. if still not null,
|
|
|
|
// this zone is now unwanted and can be removed
|
|
|
|
zone = nullptr;
|
|
|
|
|
2014-02-19 12:51:32 +00:00
|
|
|
numPoints = 0;
|
|
|
|
m_controls->SetAutoPan( false );
|
2015-03-10 13:43:14 +00:00
|
|
|
m_controls->CaptureCursor( false );
|
2014-03-18 10:33:49 +00:00
|
|
|
|
|
|
|
if( direction45 )
|
|
|
|
{
|
|
|
|
preview.Remove( &line45 );
|
|
|
|
direction45 = false;
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:04:35 +00:00
|
|
|
preview.FreeItems();
|
2017-02-08 09:13:43 +00:00
|
|
|
m_view->Update( &preview );
|
2014-02-13 11:46:39 +00:00
|
|
|
}
|
2014-02-14 09:47:43 +00:00
|
|
|
else
|
2014-02-13 11:46:39 +00:00
|
|
|
{
|
2014-02-19 12:51:32 +00:00
|
|
|
if( numPoints == 0 ) // it's the first click
|
2014-02-14 09:47:43 +00:00
|
|
|
{
|
2017-02-06 05:59:55 +00:00
|
|
|
if( sourceZone )
|
|
|
|
{
|
|
|
|
zone = createZoneFromExisting( *sourceZone );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zone = createNewZone( aKeepout );
|
|
|
|
}
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2017-02-06 05:04:04 +00:00
|
|
|
if( !zone )
|
2014-03-18 13:01:09 +00:00
|
|
|
{
|
2014-02-19 12:51:32 +00:00
|
|
|
continue;
|
2014-03-18 13:01:09 +00:00
|
|
|
}
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2017-02-06 05:04:04 +00:00
|
|
|
m_frame->GetGalCanvas()->SetTopLayer( zone->GetLayer() );
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2014-02-14 09:47:43 +00:00
|
|
|
// Add the first point
|
2017-02-06 05:04:04 +00:00
|
|
|
zone->Outline()->Start( zone->GetLayer(),
|
2014-02-14 14:13:42 +00:00
|
|
|
cursorPos.x, cursorPos.y,
|
2014-02-14 09:47:43 +00:00
|
|
|
zone->GetHatchStyle() );
|
|
|
|
origin = cursorPos;
|
2014-02-19 12:51:32 +00:00
|
|
|
|
|
|
|
// Helper line represents the currently drawn line of the zone polygon
|
|
|
|
helperLine = new DRAWSEGMENT;
|
|
|
|
helperLine->SetShape( S_SEGMENT );
|
|
|
|
helperLine->SetWidth( 1 );
|
2017-02-06 05:04:04 +00:00
|
|
|
helperLine->SetLayer( zone->GetLayer() );
|
2014-02-19 12:51:32 +00:00
|
|
|
helperLine->SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
helperLine->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
line45 = *helperLine;
|
|
|
|
|
2014-02-14 09:47:43 +00:00
|
|
|
preview.Add( helperLine );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zone->AppendCorner( helperLine->GetEnd() );
|
|
|
|
helperLine = new DRAWSEGMENT( *helperLine );
|
|
|
|
helperLine->SetStart( helperLine->GetEnd() );
|
|
|
|
preview.Add( helperLine );
|
|
|
|
}
|
|
|
|
|
2014-02-19 12:51:32 +00:00
|
|
|
++numPoints;
|
2017-02-08 09:13:43 +00:00
|
|
|
m_view->Update( &preview );
|
2014-02-13 11:46:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-19 12:51:32 +00:00
|
|
|
else if( evt->IsMotion() && numPoints > 0 )
|
2014-02-13 11:46:39 +00:00
|
|
|
{
|
2014-02-14 09:47:43 +00:00
|
|
|
// 45 degree lines
|
2014-02-17 10:33:03 +00:00
|
|
|
if( direction45 )
|
|
|
|
make45DegLine( helperLine, &line45 );
|
2014-02-14 09:47:43 +00:00
|
|
|
else
|
|
|
|
helperLine->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2017-02-08 09:13:43 +00:00
|
|
|
}
|
2014-02-13 11:46:39 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 09:47:43 +00:00
|
|
|
m_controls->ShowCursor( false );
|
2014-02-14 08:49:49 +00:00
|
|
|
m_controls->SetSnapping( false );
|
|
|
|
m_controls->SetAutoPan( false );
|
2015-03-10 13:43:14 +00:00
|
|
|
m_controls->CaptureCursor( false );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2014-02-13 11:46:39 +00:00
|
|
|
|
2014-02-19 12:51:32 +00:00
|
|
|
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
|
2014-02-13 11:46:39 +00:00
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-17 10:33:03 +00:00
|
|
|
void DRAWING_TOOL::make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) const
|
2014-02-14 13:24:12 +00:00
|
|
|
{
|
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
2014-02-17 10:33:03 +00:00
|
|
|
VECTOR2I origin( aSegment->GetStart() );
|
|
|
|
DIRECTION_45 direction( origin - cursorPos );
|
|
|
|
SHAPE_LINE_CHAIN newChain = direction.BuildInitialTrace( origin, cursorPos );
|
2014-02-14 13:24:12 +00:00
|
|
|
|
2014-02-17 10:33:03 +00:00
|
|
|
if( newChain.PointCount() > 2 )
|
|
|
|
{
|
|
|
|
aSegment->SetEnd( wxPoint( newChain.Point( -2 ).x, newChain.Point( -2 ).y ) );
|
|
|
|
aHelper->SetStart( wxPoint( newChain.Point( -2 ).x, newChain.Point( -2 ).y ) );
|
|
|
|
aHelper->SetEnd( wxPoint( newChain.Point( -1 ).x, newChain.Point( -1 ).y ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aSegment->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
aHelper->SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
aHelper->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
}
|
2014-02-14 13:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-30 08:46:03 +00:00
|
|
|
void DRAWING_TOOL::SetTransitions()
|
2014-02-06 16:12:37 +00:00
|
|
|
{
|
2014-07-09 12:01:06 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawLine, COMMON_ACTIONS::drawLine.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawCircle, COMMON_ACTIONS::drawCircle.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawArc, COMMON_ACTIONS::drawArc.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawDimension, COMMON_ACTIONS::drawDimension.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawZone, COMMON_ACTIONS::drawZone.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawKeepout, COMMON_ACTIONS::drawKeepout.MakeEvent() );
|
2017-02-06 05:59:55 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawZoneCutout, COMMON_ACTIONS::drawZoneCutout.MakeEvent() );
|
2017-02-06 07:37:13 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawSimilarZone, COMMON_ACTIONS::drawSimilarZone.MakeEvent() );
|
2014-07-09 12:01:06 +00:00
|
|
|
Go( &DRAWING_TOOL::PlaceText, COMMON_ACTIONS::placeText.MakeEvent() );
|
2014-07-09 13:02:56 +00:00
|
|
|
Go( &DRAWING_TOOL::PlaceDXF, COMMON_ACTIONS::placeDXF.MakeEvent() );
|
2014-07-09 12:01:06 +00:00
|
|
|
Go( &DRAWING_TOOL::SetAnchor, COMMON_ACTIONS::setAnchor.MakeEvent() );
|
2014-02-06 16:12:37 +00:00
|
|
|
}
|
2014-09-01 11:48:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
int DRAWING_TOOL::getSegmentWidth( unsigned int aLayer ) const
|
|
|
|
{
|
|
|
|
assert( m_board );
|
|
|
|
|
|
|
|
if( aLayer == Edge_Cuts )
|
|
|
|
return m_board->GetDesignSettings().m_EdgeSegmentWidth;
|
|
|
|
else if( m_editModules )
|
|
|
|
return m_board->GetDesignSettings().m_ModuleSegmentWidth;
|
|
|
|
else
|
|
|
|
return m_board->GetDesignSettings().m_DrawSegmentWidth;
|
|
|
|
}
|
|
|
|
|
2015-03-10 15:58:26 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
LAYER_ID DRAWING_TOOL::getDrawingLayer() const
|
|
|
|
{
|
|
|
|
LAYER_ID layer = m_frame->GetActiveLayer();
|
|
|
|
|
|
|
|
if( IsCopperLayer( layer ) )
|
|
|
|
{
|
|
|
|
if( layer == F_Cu )
|
|
|
|
layer = F_SilkS;
|
|
|
|
else if( layer == B_Cu )
|
|
|
|
layer = B_SilkS;
|
|
|
|
else
|
|
|
|
layer = Dwgs_User;
|
|
|
|
|
|
|
|
m_frame->SetActiveLayer( layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned int DRAWING_TOOL::WIDTH_STEP = 100000;
|