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
|
2019-01-23 14:39:08 +00:00
|
|
|
* Copyright (C) 2018-2019 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"
|
2017-02-21 12:42:08 +00:00
|
|
|
#include "pcb_actions.h"
|
2014-02-06 16:12:37 +00:00
|
|
|
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2014-05-12 15:17:51 +00:00
|
|
|
#include <project.h>
|
2014-02-19 12:51:32 +00:00
|
|
|
#include <id.h>
|
2014-02-13 11:46:39 +00:00
|
|
|
#include <confirm.h>
|
2018-10-13 18:37:28 +00:00
|
|
|
#include <import_gfx/dialog_import_gfx.h>
|
2014-02-06 16:12:37 +00:00
|
|
|
#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>
|
2018-07-12 12:05:18 +00:00
|
|
|
#include <geometry/geometry_utils.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>
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <bitmaps.h>
|
2017-02-26 17:45:52 +00:00
|
|
|
#include <painter.h>
|
2018-02-19 14:25:07 +00:00
|
|
|
#include <status_popup.h>
|
2018-04-08 16:47:39 +00:00
|
|
|
#include "grid_helper.h"
|
2019-06-27 21:33:48 +00:00
|
|
|
#include "point_editor.h"
|
2018-06-06 10:05:56 +00:00
|
|
|
#include <dialogs/dialog_text_properties.h>
|
2017-02-26 20:08:45 +00:00
|
|
|
#include <preview_items/arc_assistant.h>
|
|
|
|
|
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-02-26 17:45:52 +00:00
|
|
|
#include <tools/zone_create_helper.h>
|
2017-01-09 17:29:40 +00:00
|
|
|
|
|
|
|
using SCOPED_DRAW_MODE = SCOPED_SET_RESET<DRAWING_TOOL::MODE>;
|
|
|
|
|
2017-02-26 20:08:45 +00:00
|
|
|
|
2014-02-06 16:12:37 +00:00
|
|
|
DRAWING_TOOL::DRAWING_TOOL() :
|
2019-05-12 11:49:58 +00:00
|
|
|
PCB_TOOL_BASE( "pcbnew.InteractiveDrawing" ),
|
2017-01-09 17:29:40 +00:00
|
|
|
m_view( nullptr ), m_controls( nullptr ),
|
|
|
|
m_board( nullptr ), m_frame( nullptr ), m_mode( MODE::NONE ),
|
2018-08-01 16:58:27 +00:00
|
|
|
m_lineWidth( 1 )
|
2014-02-06 16:12:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DRAWING_TOOL::~DRAWING_TOOL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
bool DRAWING_TOOL::Init()
|
|
|
|
{
|
2017-02-06 16:00:51 +00:00
|
|
|
auto activeToolFunctor = [ this ] ( const SELECTION& aSel ) {
|
2017-05-04 22:43:43 +00:00
|
|
|
return m_mode != MODE::NONE;
|
|
|
|
};
|
2017-02-06 16:00:51 +00:00
|
|
|
|
2017-02-26 17:45:52 +00:00
|
|
|
// some interactive drawing tools can undo the last point
|
2017-02-26 20:08:45 +00:00
|
|
|
auto canUndoPoint = [ this ] ( const SELECTION& aSel ) {
|
2017-05-04 22:43:43 +00:00
|
|
|
return m_mode == MODE::ARC || m_mode == MODE::ZONE;
|
|
|
|
};
|
2017-02-26 17:45:52 +00:00
|
|
|
|
|
|
|
// functor for zone-only actions
|
|
|
|
auto zoneActiveFunctor = [this ] ( const SELECTION& aSel ) {
|
2017-05-04 22:43:43 +00:00
|
|
|
return m_mode == MODE::ZONE;
|
|
|
|
};
|
2017-02-26 20:08:45 +00:00
|
|
|
|
2017-02-06 16:00:51 +00:00
|
|
|
auto& ctxMenu = m_menu.GetMenu();
|
|
|
|
|
2018-08-01 16:58:27 +00:00
|
|
|
// cancel current tool goes in main context menu at the top if present
|
|
|
|
ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1 );
|
2019-06-15 16:40:14 +00:00
|
|
|
ctxMenu.AddSeparator( 1 );
|
2017-02-26 20:08:45 +00:00
|
|
|
|
2017-02-26 17:45:52 +00:00
|
|
|
// tool-specific actions
|
2019-06-17 00:34:21 +00:00
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::closeZoneOutline, zoneActiveFunctor, 200 );
|
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::deleteLastPoint, canUndoPoint, 200 );
|
2017-02-26 20:08:45 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
ctxMenu.AddSeparator( 500 );
|
2017-02-06 16:00:51 +00:00
|
|
|
|
2017-02-26 17:45:52 +00:00
|
|
|
// Type-specific sub-menus will be added for us by other tools
|
|
|
|
// For example, zone fill/unfill is provided by the PCB control tool
|
|
|
|
|
|
|
|
// Finally, add the standard zoom/grid items
|
2019-06-11 14:38:21 +00:00
|
|
|
getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( m_menu );
|
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
|
|
|
{
|
2018-05-14 03:22:11 +00:00
|
|
|
if( m_editModules && !m_frame->GetModel() )
|
|
|
|
return 0;
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
MODULE* module = dynamic_cast<MODULE*>( m_frame->GetModel() );
|
|
|
|
DRAWSEGMENT* line = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT;
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE );
|
2019-07-02 13:31:30 +00:00
|
|
|
OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
|
2017-01-09 17:29:40 +00:00
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
line->SetFlags( IS_NEW );
|
|
|
|
|
|
|
|
if( aEvent.HasPosition() )
|
|
|
|
startingPoint = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) );
|
2014-04-04 09:50:15 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2019-06-16 10:03:56 +00:00
|
|
|
Activate();
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
while( drawSegment( tool, S_SEGMENT, line, startingPoint ) )
|
2016-06-08 09:24:46 +00:00
|
|
|
{
|
|
|
|
if( line )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2019-01-17 16:58:17 +00:00
|
|
|
if( m_editModules )
|
|
|
|
static_cast<EDGE_MODULE*>( line )->SetLocalCoord();
|
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( line );
|
|
|
|
commit.Push( _( "Draw a line segment" ) );
|
2017-11-01 11:14:16 +00:00
|
|
|
startingPoint = VECTOR2D( 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
|
|
|
{
|
2017-11-01 11:14:16 +00:00
|
|
|
startingPoint = NULLOPT;
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
line = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT;
|
2019-06-15 19:42:17 +00:00
|
|
|
line->SetFlags( IS_NEW );
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2014-02-06 16:12:37 +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
|
|
|
{
|
2018-05-14 03:22:11 +00:00
|
|
|
if( m_editModules && !m_frame->GetModel() )
|
|
|
|
return 0;
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
MODULE* module = dynamic_cast<MODULE*>( m_frame->GetModel() );
|
|
|
|
DRAWSEGMENT* circle = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT;
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE );
|
2019-07-02 13:31:30 +00:00
|
|
|
OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
|
2014-02-10 09:58:58 +00:00
|
|
|
|
2019-06-15 19:42:17 +00:00
|
|
|
circle->SetFlags( IS_NEW );
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
if( aEvent.HasPosition() )
|
|
|
|
startingPoint = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) );
|
2014-02-14 10:35:48 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2019-06-16 10:03:56 +00:00
|
|
|
Activate();
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
while( drawSegment( tool, S_CIRCLE, circle, startingPoint ) )
|
2016-06-08 09:24:46 +00:00
|
|
|
{
|
|
|
|
if( circle )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2019-01-17 16:58:17 +00:00
|
|
|
if( m_editModules )
|
|
|
|
static_cast<EDGE_MODULE*>( circle )->SetLocalCoord();
|
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( circle );
|
|
|
|
commit.Push( _( "Draw a circle" ) );
|
2019-06-27 11:47:24 +00:00
|
|
|
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, circle );
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
circle = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT;
|
2019-06-15 19:42:17 +00:00
|
|
|
circle->SetFlags( IS_NEW );
|
2019-06-24 15:27:05 +00:00
|
|
|
startingPoint = NULLOPT;
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2018-05-14 03:22:11 +00:00
|
|
|
if( m_editModules && !m_frame->GetModel() )
|
|
|
|
return 0;
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
MODULE* module = dynamic_cast<MODULE*>( m_frame->GetModel() );
|
|
|
|
DRAWSEGMENT* arc = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT;
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC );
|
2019-06-24 15:27:05 +00:00
|
|
|
bool immediateMode = aEvent.HasPosition();
|
2017-01-09 17:29:40 +00:00
|
|
|
|
2019-06-15 19:42:17 +00:00
|
|
|
arc->SetFlags( IS_NEW );
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2019-06-24 15:27:05 +00:00
|
|
|
Activate();
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
while( drawArc( tool, arc, immediateMode ) )
|
2016-06-08 09:24:46 +00:00
|
|
|
{
|
|
|
|
if( arc )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2019-01-17 16:58:17 +00:00
|
|
|
if( m_editModules )
|
|
|
|
static_cast<EDGE_MODULE*>( arc )->SetLocalCoord();
|
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( arc );
|
|
|
|
commit.Push( _( "Draw an arc" ) );
|
2019-06-27 11:47:24 +00:00
|
|
|
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, arc );
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
arc = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT;
|
2019-06-15 19:42:17 +00:00
|
|
|
arc->SetFlags( IS_NEW );
|
2019-06-24 15:27:05 +00:00
|
|
|
immediateMode = false;
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
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
|
|
|
{
|
2018-05-14 03:22:11 +00:00
|
|
|
if( m_editModules && !m_frame->GetModel() )
|
|
|
|
return 0;
|
|
|
|
|
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
|
|
|
|
2019-07-27 05:38:04 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2016-06-08 09:24:46 +00:00
|
|
|
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 );
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2016-06-08 09:24:46 +00:00
|
|
|
Activate();
|
|
|
|
|
2018-01-19 13:20:15 +00:00
|
|
|
bool reselect = false;
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
// Prime the pump
|
|
|
|
if( aEvent.HasPosition() )
|
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2016-06-08 09:24:46 +00:00
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( text ? wxCURSOR_ARROW : wxCURSOR_PENCIL );
|
2016-06-08 09:24:46 +00:00
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
2014-02-10 09:58:58 +00:00
|
|
|
|
2018-01-19 13:20:15 +00:00
|
|
|
if( reselect && text )
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, text );
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
auto cleanup = [&] () {
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2019-08-01 05:09:55 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
|
|
|
m_controls->ShowCursor( true );
|
2019-07-01 21:01:33 +00:00
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
|
|
|
delete text;
|
|
|
|
text = NULL;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
if( text )
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
|
|
|
else
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
if( text )
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
if( evt->IsMoveTool() )
|
2019-06-24 15:27:05 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
// leave ourselves on the stack so we come back after the move
|
2019-06-27 11:47:24 +00:00
|
|
|
break;
|
2019-06-24 15:27:05 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2016-06-08 09:24:46 +00:00
|
|
|
break;
|
2019-07-01 21:01:33 +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
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( selection() );
|
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
|
|
|
{
|
2019-05-16 18:54:54 +00:00
|
|
|
bool placing = text != nullptr;
|
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
if( !text )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2018-11-11 13:09:02 +00:00
|
|
|
m_controls->ForceCursorPosition( true, m_controls->GetCursorPosition() );
|
2018-04-28 15:22:25 +00:00
|
|
|
PCB_LAYER_ID layer = m_frame->GetActiveLayer();
|
|
|
|
|
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
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
textMod->SetLayer( layer );
|
|
|
|
textMod->SetTextSize( dsnSettings.GetTextSize( layer ) );
|
|
|
|
textMod->SetThickness( dsnSettings.GetTextThickness( layer ) );
|
|
|
|
textMod->SetItalic( dsnSettings.GetTextItalic( layer ) );
|
|
|
|
textMod->SetKeepUpright( dsnSettings.GetTextUpright( layer ) );
|
2019-04-19 18:23:18 +00:00
|
|
|
textMod->SetTextPos( (wxPoint) cursorPos );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2019-05-16 18:54:54 +00:00
|
|
|
text = textMod;
|
|
|
|
|
2019-05-28 23:23:58 +00:00
|
|
|
DIALOG_TEXT_PROPERTIES textDialog( m_frame, textMod );
|
2019-05-16 18:54:54 +00:00
|
|
|
bool cancelled;
|
2016-09-21 09:54:58 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
RunMainStack([&]() {
|
2019-05-16 18:54:54 +00:00
|
|
|
cancelled = !textDialog.ShowModal() || textMod->GetText().IsEmpty();
|
2016-09-21 09:54:58 +00:00
|
|
|
} );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2019-05-16 18:54:54 +00:00
|
|
|
if( cancelled )
|
|
|
|
{
|
|
|
|
delete text;
|
|
|
|
text = nullptr;
|
|
|
|
}
|
|
|
|
else if( textMod->GetTextPos() != (wxPoint) cursorPos )
|
|
|
|
{
|
|
|
|
// If the user modified the location then go ahead and place it there.
|
|
|
|
// Otherwise we'll drag.
|
|
|
|
placing = true;
|
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
}
|
|
|
|
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 );
|
|
|
|
|
|
|
|
textPcb->SetLayer( layer );
|
|
|
|
|
|
|
|
// Set the mirrored option for layers on the BACK side of the board
|
|
|
|
if( IsBackLayer( layer ) )
|
|
|
|
textPcb->SetMirrored( true );
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
textPcb->SetTextSize( dsnSettings.GetTextSize( layer ) );
|
|
|
|
textPcb->SetThickness( dsnSettings.GetTextThickness( layer ) );
|
|
|
|
textPcb->SetItalic( dsnSettings.GetTextItalic( layer ) );
|
2019-04-19 18:23:18 +00:00
|
|
|
textPcb->SetTextPos( (wxPoint) cursorPos );
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
RunMainStack([&]() {
|
2019-05-28 23:23:58 +00:00
|
|
|
m_frame->InstallTextOptionsFrame( textPcb );
|
2016-09-21 09:54:58 +00:00
|
|
|
} );
|
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
|
|
|
}
|
|
|
|
|
2019-08-01 05:09:55 +00:00
|
|
|
if( text )
|
|
|
|
{
|
|
|
|
m_controls->WarpCursor( text->GetPosition(), true );
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, text );
|
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
}
|
2019-05-16 18:54:54 +00:00
|
|
|
|
|
|
|
if( placing )
|
2016-06-08 09:24:46 +00:00
|
|
|
{
|
|
|
|
text->ClearFlags();
|
2018-01-19 13:19:19 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
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
|
|
|
|
2019-06-27 11:47:24 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, text );
|
|
|
|
|
2019-08-01 05:09:55 +00:00
|
|
|
text = nullptr;
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
2019-08-01 05:09:55 +00:00
|
|
|
|
|
|
|
m_controls->ForceCursorPosition( false );
|
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->CaptureCursor( text != nullptr );
|
|
|
|
m_controls->SetAutoPan( text != nullptr );
|
2016-06-08 09:24:46 +00:00
|
|
|
}
|
|
|
|
else if( text && evt->IsMotion() )
|
|
|
|
{
|
2019-04-19 18:23:18 +00:00
|
|
|
text->SetPosition( (wxPoint) cursorPos );
|
2019-05-19 21:04:04 +00:00
|
|
|
selection().SetReferencePoint( cursorPos );
|
|
|
|
m_view->Update( &selection() );
|
2018-04-12 16:08:45 +00:00
|
|
|
frame()->SetMsgPanel( text );
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2018-01-19 13:20:15 +00:00
|
|
|
|
|
|
|
else if( text && evt->IsAction( &PCB_ACTIONS::properties ) )
|
|
|
|
{
|
|
|
|
// Calling 'Properties' action clears the selection, so we need to restore it
|
|
|
|
reselect = true;
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
2014-02-10 09:58:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 16:33:18 +00:00
|
|
|
frame()->SetMsgPanel( board() );
|
2014-02-10 09:58:58 +00:00
|
|
|
return 0;
|
2014-02-10 14:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-03 04:01:01 +00:00
|
|
|
void DRAWING_TOOL::constrainDimension( DIMENSION* dimension )
|
|
|
|
{
|
2018-07-12 12:05:18 +00:00
|
|
|
const VECTOR2I lineVector{ dimension->GetEnd() - dimension->GetOrigin() };
|
2018-06-03 04:01:01 +00:00
|
|
|
|
2018-07-12 12:05:18 +00:00
|
|
|
dimension->SetEnd( wxPoint(
|
|
|
|
VECTOR2I( dimension->GetOrigin() ) + GetVectorSnapped45( lineVector ) ) );
|
2018-06-03 04:01:01 +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
|
|
|
{
|
2018-05-14 03:22:11 +00:00
|
|
|
if( m_editModules && !m_frame->GetModel() )
|
|
|
|
return 0;
|
|
|
|
|
2019-06-27 21:33:48 +00:00
|
|
|
POINT_EDITOR* pointEditor = m_toolMgr->GetTool<POINT_EDITOR>();
|
|
|
|
DIMENSION* dimension = NULL;
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
GRID_HELPER grid( m_frame );
|
2014-02-11 13:38:44 +00:00
|
|
|
|
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
2019-06-08 21:48:22 +00:00
|
|
|
PCBNEW_SELECTION preview;
|
2017-05-04 22:43:43 +00:00
|
|
|
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Add( &preview );
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2019-07-27 05:38:04 +00:00
|
|
|
m_toolMgr->RunAction( PCB_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 );
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2014-02-11 13:38:44 +00:00
|
|
|
Activate();
|
|
|
|
|
2014-02-14 10:35:48 +00:00
|
|
|
enum DIMENSION_STEPS
|
|
|
|
{
|
|
|
|
SET_ORIGIN = 0,
|
|
|
|
SET_END,
|
|
|
|
SET_HEIGHT,
|
|
|
|
FINISHED
|
|
|
|
};
|
|
|
|
int step = SET_ORIGIN;
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
// Prime the pump
|
2019-07-11 08:48:11 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
if( aEvent.HasPosition() )
|
2019-10-03 16:21:52 +00:00
|
|
|
m_toolMgr->PrimeTool( aEvent.Position() );
|
2019-06-24 15:27:05 +00:00
|
|
|
|
2014-02-11 13:38:44 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2014-02-11 13:38:44 +00:00
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
if( !pointEditor->HasPoint() )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
|
|
|
|
|
2018-10-06 16:50:43 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
|
2018-10-07 03:20:38 +00:00
|
|
|
m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
|
2019-10-03 16:21:52 +00:00
|
|
|
VECTOR2I cursorPos = grid.BestSnapAnchor(
|
|
|
|
evt->IsPrime() ? evt->Position() : m_controls->GetMousePosition(), nullptr );
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
2018-10-06 16:50:43 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
auto cleanup = [&] () {
|
2019-08-29 22:07:57 +00:00
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
preview.Clear();
|
2019-08-29 22:07:57 +00:00
|
|
|
m_view->Update( &preview );
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
delete dimension;
|
|
|
|
dimension = nullptr;
|
|
|
|
step = SET_ORIGIN;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
2014-02-11 13:38:44 +00:00
|
|
|
{
|
2018-08-06 08:15:58 +00:00
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
|
2014-02-19 12:51:32 +00:00
|
|
|
if( step != SET_ORIGIN ) // start from the beginning
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
|
|
|
else
|
2014-02-19 12:51:32 +00:00
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
if( step != SET_ORIGIN )
|
|
|
|
cleanup();
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsPointEditor() )
|
|
|
|
{
|
|
|
|
// don't exit (the point editor runs in the background)
|
2014-02-19 12:51:32 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsMoveTool() )
|
2019-06-24 15:27:05 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
// leave ourselves on the stack so we come back after the move
|
2019-06-27 11:47:24 +00:00
|
|
|
break;
|
2019-06-24 15:27:05 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2014-07-09 11:50:27 +00:00
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2014-02-11 13:38:44 +00:00
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_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 );
|
2018-04-12 16:08:45 +00:00
|
|
|
frame()->SetMsgPanel( dimension );
|
2014-09-01 11:48:51 +00:00
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && step != SET_ORIGIN )
|
2014-09-01 11:48:51 +00:00
|
|
|
{
|
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 );
|
2018-04-12 16:08:45 +00:00
|
|
|
frame()->SetMsgPanel( dimension );
|
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
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( selection() );
|
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:
|
2017-05-04 22:43:43 +00:00
|
|
|
{
|
2019-06-27 11:47:24 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
PCB_LAYER_ID layer = getDrawingLayer();
|
2018-04-28 15:22:25 +00:00
|
|
|
const BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings();
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
if( layer == Edge_Cuts ) // dimensions are not allowed on EdgeCuts
|
|
|
|
layer = Dwgs_User;
|
2017-03-02 12:52:23 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
// Init the new item attributes
|
|
|
|
dimension = new DIMENSION( m_board );
|
|
|
|
dimension->SetLayer( layer );
|
2019-04-19 18:23:18 +00:00
|
|
|
dimension->SetOrigin( (wxPoint) cursorPos );
|
|
|
|
dimension->SetEnd( (wxPoint) cursorPos );
|
2018-04-28 15:22:25 +00:00
|
|
|
dimension->Text().SetTextSize( boardSettings.GetTextSize( layer ) );
|
|
|
|
dimension->Text().SetThickness( boardSettings.GetTextThickness( layer ) );
|
|
|
|
dimension->Text().SetItalic( boardSettings.GetTextItalic( layer ) );
|
|
|
|
dimension->SetWidth( boardSettings.GetLineThickness( layer ) );
|
2018-07-21 12:49:19 +00:00
|
|
|
dimension->SetUnits( m_frame->GetUserUnits(), false );
|
|
|
|
dimension->AdjustDimensionDetails();
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
preview.Add( dimension );
|
2018-04-12 16:08:45 +00:00
|
|
|
frame()->SetMsgPanel( dimension );
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
m_controls->SetAutoPan( true );
|
|
|
|
m_controls->CaptureCursor( true );
|
|
|
|
}
|
|
|
|
break;
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2014-02-14 14:13:42 +00:00
|
|
|
case SET_END:
|
2019-04-19 18:23:18 +00:00
|
|
|
dimension->SetEnd( (wxPoint) cursorPos );
|
2014-02-19 14:20:42 +00:00
|
|
|
|
2018-06-03 04:01:01 +00:00
|
|
|
if( !!evt->Modifier( MD_CTRL ) )
|
|
|
|
constrainDimension( dimension );
|
|
|
|
|
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;
|
2017-05-04 22:43:43 +00:00
|
|
|
|
2014-02-14 14:13:42 +00:00
|
|
|
break;
|
|
|
|
|
2014-02-14 10:35:48 +00:00
|
|
|
case SET_HEIGHT:
|
2017-05-04 22:43:43 +00:00
|
|
|
{
|
2019-04-19 18:23:18 +00:00
|
|
|
if( (wxPoint) cursorPos != dimension->GetPosition() )
|
2014-02-11 13:38:44 +00:00
|
|
|
{
|
2017-05-04 22:43:43 +00:00
|
|
|
assert( dimension->GetOrigin() != dimension->GetEnd() );
|
|
|
|
assert( dimension->GetWidth() > 0 );
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
preview.Remove( dimension );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
commit.Add( dimension );
|
|
|
|
commit.Push( _( "Draw a dimension" ) );
|
2019-06-27 11:47:24 +00:00
|
|
|
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, dimension );
|
2014-02-11 13:38:44 +00:00
|
|
|
}
|
2017-05-04 22:43:43 +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:
|
2019-04-19 18:23:18 +00:00
|
|
|
dimension->SetEnd( (wxPoint) cursorPos );
|
2018-06-03 04:01:01 +00:00
|
|
|
|
|
|
|
if( !!evt->Modifier( MD_CTRL ) )
|
|
|
|
constrainDimension( dimension );
|
|
|
|
|
2014-02-11 13:38:44 +00:00
|
|
|
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 );
|
|
|
|
|
2019-04-19 18:23:18 +00:00
|
|
|
wxPoint delta( (wxPoint) cursorPos - dimension->m_featureLineDO );
|
2017-05-04 22:43:43 +00:00
|
|
|
double height = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
|
2014-02-11 13:38:44 +00:00
|
|
|
dimension->SetHeight( height );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show a preview of the item
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2018-04-18 17:05:56 +00:00
|
|
|
if( step )
|
|
|
|
frame()->SetMsgPanel( dimension );
|
|
|
|
else
|
|
|
|
frame()->SetMsgPanel( board() );
|
2014-02-11 13:38:44 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
2014-02-11 13:38:44 +00:00
|
|
|
}
|
|
|
|
|
2014-02-19 12:51:32 +00:00
|
|
|
if( step != SET_ORIGIN )
|
|
|
|
delete dimension;
|
|
|
|
|
2018-08-06 08:15:58 +00:00
|
|
|
m_controls->SetAutoPan( false );
|
2019-05-11 08:02:59 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2019-08-29 22:07:57 +00:00
|
|
|
m_controls->CaptureCursor( false );
|
2018-08-06 08:15:58 +00:00
|
|
|
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2018-04-12 16:33:18 +00:00
|
|
|
frame()->SetMsgPanel( board() );
|
2014-02-11 13:38:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-01 09:47:41 +00:00
|
|
|
int DRAWING_TOOL::PlaceImportedGraphics( 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;
|
|
|
|
|
2019-05-31 23:24:38 +00:00
|
|
|
// Note: PlaceImportedGraphics() will convert PCB_LINE_T and PCB_TEXT_T to module graphic
|
|
|
|
// items if needed
|
2018-11-05 16:04:05 +00:00
|
|
|
DIALOG_IMPORT_GFX dlg( m_frame, m_editModules );
|
2014-07-09 13:02:56 +00:00
|
|
|
int dlgResult = dlg.ShowModal();
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
auto& list = dlg.GetImportedItems();
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
if( dlgResult != wxID_OK )
|
2014-07-09 13:02:56 +00:00
|
|
|
return 0;
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
// Ensure the list is not empty:
|
|
|
|
if( list.empty() )
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "No graphic items found in file to import") );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-27 11:47:24 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cancelInteractive, true );
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
2019-06-08 21:48:22 +00:00
|
|
|
PCBNEW_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
|
2019-05-05 10:33:34 +00:00
|
|
|
for( auto& ptr : list)
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
EDA_ITEM* item = ptr.get();
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
if( m_editModules )
|
|
|
|
wxASSERT( item->Type() == PCB_MODULE_EDGE_T || item->Type() == PCB_MODULE_TEXT_T );
|
|
|
|
else
|
|
|
|
wxASSERT( item->Type() == PCB_LINE_T || item->Type() == PCB_TEXT_T );
|
|
|
|
|
|
|
|
if( dlg.IsPlacementInteractive() )
|
|
|
|
preview.Add( item );
|
|
|
|
else
|
|
|
|
commit.Add( item );
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
ptr.release();
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
if( !dlg.IsPlacementInteractive() )
|
|
|
|
{
|
|
|
|
commit.Push( _( "Place a DXF_SVG drawing" ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-28 03:04:44 +00:00
|
|
|
BOARD_ITEM* firstItem = static_cast<BOARD_ITEM*>( preview.Front() );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Add( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2014-07-09 13:02:56 +00:00
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->SetSnapping( true );
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
|
|
|
|
|
2018-07-07 11:04:01 +00:00
|
|
|
// Now move the new items to the current cursor position:
|
2018-10-13 18:37:28 +00:00
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition();
|
|
|
|
VECTOR2I delta = cursorPos - firstItem->GetPosition();
|
2018-07-07 11:04:01 +00:00
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
for( EDA_ITEM* item : preview )
|
2019-04-19 18:23:18 +00:00
|
|
|
static_cast<BOARD_ITEM*>( item )->Move( (wxPoint) delta );
|
2018-07-07 11:04:01 +00:00
|
|
|
|
|
|
|
m_view->Update( &preview );
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2014-07-09 13:02:56 +00:00
|
|
|
Activate();
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
|
2014-07-09 13:02:56 +00:00
|
|
|
cursorPos = m_controls->GetCursorPosition();
|
|
|
|
|
2019-07-09 23:51:47 +00:00
|
|
|
if( evt->IsCancelInteractive() || evt->IsActivate() )
|
|
|
|
{
|
|
|
|
preview.FreeItems();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsMotion() )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
|
|
|
delta = cursorPos - firstItem->GetPosition();
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : preview )
|
2019-04-19 18:23:18 +00:00
|
|
|
static_cast<BOARD_ITEM*>( item )->Move( (wxPoint) delta );
|
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?
|
2019-07-09 23:51:47 +00:00
|
|
|
if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2019-04-19 18:23:18 +00:00
|
|
|
const auto rotationPoint = (wxPoint) cursorPos;
|
|
|
|
const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *m_frame, *evt );
|
2017-02-04 05:09:50 +00:00
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : preview )
|
2017-02-28 03:04:44 +00:00
|
|
|
static_cast<BOARD_ITEM*>( 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
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::flip ) )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2019-07-12 21:02:10 +00:00
|
|
|
bool leftRight = m_frame->Settings().m_FlipLeftRight;
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : preview )
|
2019-07-12 21:02:10 +00:00
|
|
|
static_cast<BOARD_ITEM*>( item )->Flip( (wxPoint) cursorPos, leftRight);
|
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
|
|
|
}
|
|
|
|
}
|
2017-02-10 22:20:18 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
2017-01-09 17:29:40 +00:00
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( selection() );
|
2017-01-09 17:29:40 +00:00
|
|
|
}
|
2014-07-09 13:02:56 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
2018-11-05 16:04:05 +00:00
|
|
|
// Place the imported drawings
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : preview )
|
2018-11-05 16:04:05 +00:00
|
|
|
commit.Add( item );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2018-11-01 09:47:41 +00:00
|
|
|
commit.Push( _( "Place a DXF_SVG drawing" ) );
|
2019-08-29 22:02:51 +00:00
|
|
|
break; // This is a one-shot command, not a tool
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
preview.Clear();
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2019-08-29 22:02:51 +00:00
|
|
|
m_frame->PopTool( tool );
|
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 );
|
|
|
|
|
2018-05-14 03:22:11 +00:00
|
|
|
if( !m_frame->GetModel() )
|
|
|
|
return 0;
|
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR );
|
2019-08-28 04:38:27 +00:00
|
|
|
GRID_HELPER grid( m_frame );
|
2017-01-09 17:29:40 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2014-07-09 12:01:06 +00:00
|
|
|
Activate();
|
|
|
|
|
2019-07-27 05:38:04 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
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
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_BULLSEYE );
|
2019-06-08 17:23:38 +00:00
|
|
|
|
2019-08-28 04:38:27 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
|
|
|
|
m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
|
|
|
|
VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), LSET::AllLayersMask() );
|
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
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
|
2019-04-19 18:23:18 +00:00
|
|
|
wxPoint moveVector = module->GetPosition() - (wxPoint) cursorPos;
|
2016-06-08 09:24:46 +00:00
|
|
|
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
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2014-07-09 12:01:06 +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
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( selection() );
|
2017-01-09 17:29:40 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() || evt->IsActivate() )
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2014-07-09 12:01:06 +00:00
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, DRAWSEGMENT*& aGraphic,
|
|
|
|
OPT<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 );
|
2019-06-27 21:33:48 +00:00
|
|
|
GRID_HELPER grid( m_frame );
|
|
|
|
POINT_EDITOR* pointEditor = m_toolMgr->GetTool<POINT_EDITOR>();
|
2014-02-17 10:33:03 +00:00
|
|
|
|
2018-10-18 14:15:22 +00:00
|
|
|
m_lineWidth = getSegmentWidth( getDrawingLayer() );
|
2018-10-03 12:57:02 +00:00
|
|
|
m_frame->SetActiveLayer( getDrawingLayer() );
|
|
|
|
|
2014-02-11 16:15:33 +00:00
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
2019-06-08 21:48:22 +00:00
|
|
|
PCBNEW_SELECTION preview;
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Add( &preview );
|
2014-02-11 16:15:33 +00:00
|
|
|
|
2014-02-14 09:47:43 +00:00
|
|
|
m_controls->ShowCursor( true );
|
2014-02-11 16:15:33 +00:00
|
|
|
|
2019-06-13 13:34:38 +00:00
|
|
|
bool direction45 = false; // 45 degrees only mode
|
|
|
|
bool started = false;
|
2019-07-01 21:01:33 +00:00
|
|
|
bool cancelled = false;
|
2019-06-13 13:34:38 +00:00
|
|
|
bool isLocalOriginSet = ( m_frame->GetScreen()->m_LocalOrigin != VECTOR2D( 0, 0 ) );
|
2018-10-07 03:20:38 +00:00
|
|
|
VECTOR2I cursorPos = m_controls->GetMousePosition();
|
2014-07-09 13:10:32 +00:00
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
// Prime the pump
|
2019-07-11 08:48:11 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
if( aStartingPoint )
|
2019-06-24 15:27:05 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
2014-02-17 10:33:03 +00:00
|
|
|
|
2014-02-11 16:15:33 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2014-02-11 16:15:33 +00:00
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
if( !pointEditor->HasPoint() )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
|
|
|
|
|
2018-10-04 00:15:54 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2018-10-05 04:08:15 +00:00
|
|
|
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
|
2018-10-07 03:20:38 +00:00
|
|
|
m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
|
|
|
|
cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), getDrawingLayer() );
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
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
|
2019-06-27 11:47:24 +00:00
|
|
|
bool limit45 = frame()->Settings().m_Use45DegreeGraphicSegments;
|
|
|
|
|
|
|
|
if( evt->Modifier( MD_CTRL ) )
|
|
|
|
limit45 = !limit45;
|
2017-01-10 11:16:47 +00:00
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2018-12-08 06:07:53 +00:00
|
|
|
const VECTOR2I lineVector( cursorPos - VECTOR2I( aGraphic->GetStart() ) );
|
|
|
|
|
|
|
|
// get a restricted 45/H/V line from the last fixed point to the cursor
|
|
|
|
auto newEnd = GetVectorSnapped45( lineVector );
|
2019-04-19 18:23:18 +00:00
|
|
|
aGraphic->SetEnd( aGraphic->GetStart() + (wxPoint) newEnd );
|
2018-12-08 06:07:53 +00:00
|
|
|
m_controls->ForceCursorPosition( true, VECTOR2I( aGraphic->GetEnd() ) );
|
2014-02-17 10:33:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-19 18:23:18 +00:00
|
|
|
aGraphic->SetEnd( (wxPoint) cursorPos );
|
2014-02-17 10:33:03 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
m_view->Update( &preview );
|
2018-04-12 16:08:45 +00:00
|
|
|
frame()->SetMsgPanel( aGraphic );
|
2014-02-17 10:33:03 +00:00
|
|
|
}
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
auto cleanup = [&] () {
|
|
|
|
preview.Clear();
|
|
|
|
m_view->Update( &preview );
|
|
|
|
delete aGraphic;
|
|
|
|
aGraphic = nullptr;
|
|
|
|
|
|
|
|
if( !isLocalOriginSet )
|
|
|
|
m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
|
|
|
|
};
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
2014-02-14 14:13:42 +00:00
|
|
|
{
|
2019-06-24 15:27:05 +00:00
|
|
|
if( started )
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
|
|
|
else
|
2019-06-24 15:27:05 +00:00
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( aTool );
|
2019-07-01 21:01:33 +00:00
|
|
|
cancelled = true;
|
2019-06-24 15:27:05 +00:00
|
|
|
}
|
2019-07-03 10:42:56 +00:00
|
|
|
|
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
if( evt->IsPointEditor() )
|
|
|
|
{
|
|
|
|
// don't exit (the point editor runs in the background)
|
|
|
|
}
|
|
|
|
else if( evt->IsMoveTool() )
|
|
|
|
{
|
2019-07-03 10:42:56 +00:00
|
|
|
if( started )
|
|
|
|
cleanup();
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
// leave ourselves on the stack so we come back after the move
|
|
|
|
cancelled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-03 10:42:56 +00:00
|
|
|
if( started )
|
|
|
|
cleanup();
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( aTool );
|
2019-07-01 21:01:33 +00:00
|
|
|
cancelled = true;
|
|
|
|
break;
|
|
|
|
}
|
2014-02-14 14:13:42 +00:00
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
|
2017-02-08 09:13:43 +00:00
|
|
|
{
|
2018-10-07 04:38:37 +00:00
|
|
|
m_lineWidth = getSegmentWidth( getDrawingLayer() );
|
2017-02-08 09:13:43 +00:00
|
|
|
aGraphic->SetLayer( getDrawingLayer() );
|
2018-10-07 04:38:37 +00:00
|
|
|
aGraphic->SetWidth( m_lineWidth );
|
2017-02-08 09:13:43 +00:00
|
|
|
m_view->Update( &preview );
|
2018-04-12 16:08:45 +00:00
|
|
|
frame()->SetMsgPanel( aGraphic );
|
2017-02-08 09:13:43 +00:00
|
|
|
}
|
2017-01-09 17:29:40 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( selection() );
|
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
|
|
|
{
|
2019-06-27 11:47:24 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
if( aStartingPoint )
|
|
|
|
{
|
|
|
|
cursorPos = aStartingPoint.get();
|
|
|
|
aStartingPoint = NULLOPT;
|
|
|
|
}
|
|
|
|
|
2018-10-18 14:15:22 +00:00
|
|
|
m_lineWidth = getSegmentWidth( getDrawingLayer() );
|
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
// Init the new item attributes
|
|
|
|
aGraphic->SetShape( (STROKE_T) aShape );
|
|
|
|
aGraphic->SetWidth( m_lineWidth );
|
2019-04-19 18:23:18 +00:00
|
|
|
aGraphic->SetStart( (wxPoint) cursorPos );
|
|
|
|
aGraphic->SetEnd( (wxPoint) cursorPos );
|
2017-02-08 09:13:43 +00:00
|
|
|
aGraphic->SetLayer( getDrawingLayer() );
|
2014-02-14 09:47:43 +00:00
|
|
|
|
2019-06-13 13:34:38 +00:00
|
|
|
if( !isLocalOriginSet )
|
|
|
|
m_frame->GetScreen()->m_LocalOrigin = cursorPos;
|
2017-12-21 20:49:52 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
preview.Add( aGraphic );
|
2018-04-12 16:08:45 +00:00
|
|
|
frame()->SetMsgPanel( aGraphic );
|
2017-02-08 09:13:43 +00:00
|
|
|
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
|
|
|
|
{
|
2018-11-24 15:58:33 +00:00
|
|
|
auto snapItem = dyn_cast<DRAWSEGMENT*>( grid.GetSnapped() );
|
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
if( aGraphic->GetEnd() == aGraphic->GetStart()
|
2018-11-24 15:58:33 +00:00
|
|
|
|| ( evt->IsDblClick( BUT_LEFT ) && aShape == S_SEGMENT )
|
|
|
|
|| snapItem )
|
2017-05-04 22:43:43 +00:00
|
|
|
// User has clicked twice in the same spot
|
2018-11-24 15:58:33 +00:00
|
|
|
// or clicked on the end of an existing segment (closing a path)
|
2017-05-04 22:43:43 +00:00
|
|
|
{
|
2018-11-24 15:58:33 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
|
|
|
|
// If the user clicks on an existing snap point from a drawsegment
|
|
|
|
// we finish the segment as they are likely closing a path
|
2018-12-08 06:07:53 +00:00
|
|
|
if( snapItem && aGraphic->GetLength() > 0.0 )
|
2018-11-24 15:58:33 +00:00
|
|
|
{
|
2019-06-27 11:47:24 +00:00
|
|
|
commit.Add( aGraphic );
|
|
|
|
commit.Push( _( "Draw a line segment" ) );
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, aGraphic );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete aGraphic;
|
2015-07-03 18:58:13 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 13:34:38 +00:00
|
|
|
aGraphic = nullptr;
|
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 )
|
2018-12-08 06:07:53 +00:00
|
|
|
{
|
|
|
|
const VECTOR2I lineVector( cursorPos - VECTOR2I( aGraphic->GetStart() ) );
|
|
|
|
|
|
|
|
// get a restricted 45/H/V line from the last fixed point to the cursor
|
|
|
|
auto newEnd = GetVectorSnapped45( lineVector );
|
2019-04-19 18:23:18 +00:00
|
|
|
aGraphic->SetEnd( aGraphic->GetStart() + (wxPoint) newEnd );
|
2018-12-08 06:07:53 +00:00
|
|
|
m_controls->ForceCursorPosition( true, VECTOR2I( aGraphic->GetEnd() ) );
|
|
|
|
}
|
2014-02-14 09:47:43 +00:00
|
|
|
else
|
2019-04-19 18:23:18 +00:00
|
|
|
aGraphic->SetEnd( (wxPoint) cursorPos );
|
2014-02-14 09:47:43 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
m_view->Update( &preview );
|
2018-04-12 16:33:18 +00:00
|
|
|
|
|
|
|
if( started )
|
|
|
|
frame()->SetMsgPanel( aGraphic );
|
|
|
|
else
|
|
|
|
frame()->SetMsgPanel( board() );
|
2014-02-11 16:15:33 +00:00
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
|
2014-08-04 12:23:19 +00:00
|
|
|
{
|
2015-02-15 22:21:52 +00:00
|
|
|
m_lineWidth += WIDTH_STEP;
|
|
|
|
aGraphic->SetWidth( m_lineWidth );
|
2017-02-08 09:13:43 +00:00
|
|
|
m_view->Update( &preview );
|
2018-04-12 16:08:45 +00:00
|
|
|
frame()->SetMsgPanel( aGraphic );
|
2014-08-04 12:23:19 +00:00
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_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 );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2018-04-12 16:08:45 +00:00
|
|
|
frame()->SetMsgPanel( aGraphic );
|
2017-02-08 09:13:43 +00:00
|
|
|
}
|
2019-05-28 14:39:14 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::resetLocalCoords ) )
|
2017-12-21 20:49:52 +00:00
|
|
|
{
|
2019-06-13 13:34:38 +00:00
|
|
|
isLocalOriginSet = true;
|
2017-12-21 20:49:52 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
2014-02-11 16:15:33 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 13:34:38 +00:00
|
|
|
if( !isLocalOriginSet ) // reset the relative coordinte if it was not set before
|
|
|
|
m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
|
2017-12-21 20:49:52 +00:00
|
|
|
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2018-04-12 16:33:18 +00:00
|
|
|
frame()->SetMsgPanel( board() );
|
2017-03-23 13:15:34 +00:00
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2019-07-03 10:42:56 +00:00
|
|
|
return !cancelled;
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2014-02-11 16:15:33 +00:00
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2017-02-26 20:08:45 +00:00
|
|
|
/**
|
|
|
|
* Update an arc DRAWSEGMENT from the current state
|
2017-04-23 22:00:47 +00:00
|
|
|
* of an Arc Geometry Manager
|
2017-02-26 20:08:45 +00:00
|
|
|
*/
|
2017-05-04 22:43:43 +00:00
|
|
|
static void updateArcFromConstructionMgr( const KIGFX::PREVIEW::ARC_GEOM_MANAGER& aMgr,
|
2019-07-19 21:13:52 +00:00
|
|
|
DRAWSEGMENT& aArc )
|
2017-02-26 20:08:45 +00:00
|
|
|
{
|
|
|
|
auto vec = aMgr.GetOrigin();
|
|
|
|
|
|
|
|
aArc.SetCenter( { vec.x, vec.y } );
|
|
|
|
|
|
|
|
vec = aMgr.GetStartRadiusEnd();
|
|
|
|
aArc.SetArcStart( { vec.x, vec.y } );
|
|
|
|
|
|
|
|
aArc.SetAngle( RAD2DECIDEG( -aMgr.GetSubtended() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT*& aGraphic, bool aImmediateMode )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2018-10-18 14:15:22 +00:00
|
|
|
m_lineWidth = getSegmentWidth( getDrawingLayer() );
|
|
|
|
|
2017-02-26 20:08:45 +00:00
|
|
|
// Arc geometric construction manager
|
|
|
|
KIGFX::PREVIEW::ARC_GEOM_MANAGER arcManager;
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2017-02-26 20:08:45 +00:00
|
|
|
// Arc drawing assistant overlay
|
2018-06-14 08:26:11 +00:00
|
|
|
KIGFX::PREVIEW::ARC_ASSISTANT arcAsst( arcManager, m_frame->GetUserUnits() );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
2019-06-08 21:48:22 +00:00
|
|
|
PCBNEW_SELECTION preview;
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Add( &preview );
|
2017-02-26 20:08:45 +00:00
|
|
|
m_view->Add( &arcAsst );
|
2018-10-04 00:15:54 +00:00
|
|
|
GRID_HELPER grid( m_frame );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
|
|
|
m_controls->ShowCursor( true );
|
2018-10-07 03:20:38 +00:00
|
|
|
m_controls->SetSnapping( true );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2017-02-26 20:08:45 +00:00
|
|
|
bool firstPoint = false;
|
2019-07-01 21:01:33 +00:00
|
|
|
bool cancelled = false;
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
// Prime the pump
|
2019-07-11 08:48:11 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
if( aImmediateMode )
|
|
|
|
m_toolMgr->RunAction( ACTIONS::cursorClick );
|
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2018-10-04 00:15:54 +00:00
|
|
|
PCB_LAYER_ID layer = getDrawingLayer();
|
|
|
|
aGraphic->SetLayer( layer );
|
|
|
|
|
2019-06-27 21:33:48 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
|
2018-10-04 00:15:54 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2018-10-05 04:08:15 +00:00
|
|
|
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
|
2018-10-07 03:20:38 +00:00
|
|
|
m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
|
|
|
|
VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), aGraphic );
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
auto cleanup = [&] () {
|
|
|
|
preview.Clear();
|
|
|
|
delete aGraphic;
|
|
|
|
aGraphic = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
|
|
|
{
|
|
|
|
if( firstPoint )
|
|
|
|
cleanup();
|
|
|
|
else
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( aTool );
|
2019-07-01 21:01:33 +00:00
|
|
|
cancelled = true;
|
|
|
|
}
|
2019-07-03 10:42:56 +00:00
|
|
|
|
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
if( evt->IsPointEditor() )
|
|
|
|
{
|
|
|
|
// don't exit (the point editor runs in the background)
|
|
|
|
}
|
|
|
|
else if( evt->IsMoveTool() )
|
|
|
|
{
|
2019-07-03 10:42:56 +00:00
|
|
|
if( firstPoint )
|
|
|
|
cleanup();
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
// leave ourselves on the stack so we come back after the move
|
|
|
|
cancelled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-03 10:42:56 +00:00
|
|
|
if( firstPoint )
|
|
|
|
cleanup();
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( aTool );
|
2019-07-01 21:01:33 +00:00
|
|
|
cancelled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2017-02-26 20:08:45 +00:00
|
|
|
if( !firstPoint )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2019-06-27 11:47:24 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
|
2017-02-26 20:08:45 +00:00
|
|
|
m_controls->SetAutoPan( true );
|
|
|
|
m_controls->CaptureCursor( true );
|
|
|
|
|
2018-10-18 14:15:22 +00:00
|
|
|
m_lineWidth = getSegmentWidth( getDrawingLayer() );
|
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
// Init the new item attributes
|
2017-02-26 20:08:45 +00:00
|
|
|
// (non-geometric, those are handled by the manager)
|
2017-02-08 09:13:43 +00:00
|
|
|
aGraphic->SetShape( S_ARC );
|
|
|
|
aGraphic->SetWidth( m_lineWidth );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
preview.Add( aGraphic );
|
2017-02-26 20:08:45 +00:00
|
|
|
firstPoint = true;
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
|
|
|
|
2017-02-26 20:08:45 +00:00
|
|
|
arcManager.AddPoint( cursorPos, true );
|
|
|
|
}
|
2019-06-17 00:34:21 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) )
|
2017-02-26 20:08:45 +00:00
|
|
|
{
|
|
|
|
arcManager.RemoveLastPoint();
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsMotion() )
|
|
|
|
{
|
2017-02-26 20:08:45 +00:00
|
|
|
// set angle snap
|
|
|
|
arcManager.SetAngleSnap( evt->Modifier( MD_CTRL ) );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2017-02-26 20:08:45 +00:00
|
|
|
// update, but don't step the manager state
|
|
|
|
arcManager.AddPoint( cursorPos, false );
|
|
|
|
}
|
2018-10-07 04:38:37 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
|
|
|
|
{
|
|
|
|
m_lineWidth = getSegmentWidth( getDrawingLayer() );
|
|
|
|
aGraphic->SetLayer( getDrawingLayer() );
|
|
|
|
aGraphic->SetWidth( m_lineWidth );
|
|
|
|
m_view->Update( &preview );
|
|
|
|
frame()->SetMsgPanel( aGraphic );
|
|
|
|
}
|
2017-02-26 20:08:45 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( selection() );
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
|
2014-08-04 12:23:19 +00:00
|
|
|
{
|
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 );
|
2018-04-12 16:33:18 +00:00
|
|
|
frame()->SetMsgPanel( aGraphic );
|
2014-08-04 12:23:19 +00:00
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_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 );
|
2018-04-12 16:08:45 +00:00
|
|
|
frame()->SetMsgPanel( aGraphic );
|
2014-08-04 12:23:19 +00:00
|
|
|
}
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::arcPosture ) )
|
2014-08-04 12:23:19 +00:00
|
|
|
{
|
2017-02-26 20:08:45 +00:00
|
|
|
arcManager.ToggleClockwise();
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
2014-08-04 12:23:19 +00:00
|
|
|
|
2017-02-26 20:08:45 +00:00
|
|
|
if( arcManager.IsComplete() )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( arcManager.HasGeometryChanged() )
|
|
|
|
{
|
|
|
|
updateArcFromConstructionMgr( arcManager, *aGraphic );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Update( &preview );
|
2017-02-26 20:08:45 +00:00
|
|
|
m_view->Update( &arcAsst );
|
2018-04-12 16:33:18 +00:00
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
if( firstPoint )
|
2018-04-12 16:33:18 +00:00
|
|
|
frame()->SetMsgPanel( aGraphic );
|
|
|
|
else
|
|
|
|
frame()->SetMsgPanel( board() );
|
2014-08-04 12:23:19 +00:00
|
|
|
}
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
|
|
|
|
2017-02-26 20:08:45 +00:00
|
|
|
preview.Remove( aGraphic );
|
|
|
|
m_view->Remove( &arcAsst );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2018-04-12 16:33:18 +00:00
|
|
|
frame()->SetMsgPanel( board() );
|
2017-03-23 13:15:34 +00:00
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2019-07-03 10:42:56 +00:00
|
|
|
return !cancelled;
|
2014-02-11 16:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2018-08-28 21:49:48 +00:00
|
|
|
bool clearSelection = false;
|
2017-02-06 05:59:55 +00:00
|
|
|
aZone = nullptr;
|
|
|
|
|
|
|
|
// not an action that needs a source zone
|
2017-10-19 21:14:01 +00:00
|
|
|
if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::GRAPHIC_POLYGON )
|
2017-02-06 05:59:55 +00:00
|
|
|
return true;
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
const PCBNEW_SELECTION& selection = selTool->GetSelection();
|
2017-02-06 05:59:55 +00:00
|
|
|
|
|
|
|
if( selection.Empty() )
|
2018-08-28 21:49:48 +00:00
|
|
|
{
|
|
|
|
clearSelection = true;
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true );
|
2018-08-28 21:49:48 +00:00
|
|
|
}
|
2017-02-06 05:59:55 +00:00
|
|
|
|
|
|
|
// we want a single zone
|
2018-08-28 21:49:48 +00:00
|
|
|
if( selection.Size() == 1 )
|
|
|
|
aZone = dyn_cast<ZONE_CONTAINER*>( selection[0] );
|
2017-02-06 05:59:55 +00:00
|
|
|
|
|
|
|
// expected a zone, but didn't get one
|
|
|
|
if( !aZone )
|
2018-08-28 21:49:48 +00:00
|
|
|
{
|
|
|
|
if( clearSelection )
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
|
2017-02-06 05:59:55 +00:00
|
|
|
return false;
|
2018-08-28 21:49:48 +00:00
|
|
|
}
|
2017-02-06 05:59:55 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
|
2017-02-06 05:59:55 +00:00
|
|
|
{
|
2019-07-19 21:13:52 +00:00
|
|
|
if( m_editModules && !m_frame->GetModel() )
|
|
|
|
return 0;
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
ZONE_MODE zoneMode = aEvent.Parameter<ZONE_MODE>();
|
|
|
|
MODE drawMode = MODE::ZONE;
|
|
|
|
|
|
|
|
if( aEvent.IsAction( &PCB_ACTIONS::drawZoneKeepout ) )
|
|
|
|
drawMode = MODE::KEEPOUT;
|
|
|
|
|
|
|
|
if( aEvent.IsAction( &PCB_ACTIONS::drawPolygon ) )
|
|
|
|
drawMode = MODE::GRAPHIC_POLYGON;
|
|
|
|
|
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, drawMode );
|
|
|
|
|
2018-10-12 04:11:42 +00:00
|
|
|
// get a source zone, if we need one. We need it for:
|
|
|
|
// ZONE_MODE::CUTOUT (adding a hole to the source zone)
|
|
|
|
// ZONE_MODE::SIMILAR (creating a new zone using settings of source zone
|
|
|
|
ZONE_CONTAINER* sourceZone = nullptr;
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
if( !getSourceZoneForAction( zoneMode, sourceZone ) )
|
2018-10-12 04:11:42 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
ZONE_CREATE_HELPER::PARAMS params;
|
2018-03-02 09:55:59 +00:00
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
params.m_keepout = drawMode == MODE::KEEPOUT;
|
|
|
|
params.m_mode = zoneMode;
|
2018-10-12 04:11:42 +00:00
|
|
|
params.m_sourceZone = sourceZone;
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
if( zoneMode == ZONE_MODE::GRAPHIC_POLYGON )
|
2018-10-12 04:11:42 +00:00
|
|
|
params.m_layer = getDrawingLayer();
|
2019-06-24 15:27:05 +00:00
|
|
|
else if( zoneMode == ZONE_MODE::SIMILAR )
|
2018-10-12 04:11:42 +00:00
|
|
|
params.m_layer = sourceZone->GetLayer();
|
|
|
|
else
|
|
|
|
params.m_layer = m_frame->GetActiveLayer();
|
|
|
|
|
|
|
|
ZONE_CREATE_HELPER zoneTool( *this, params );
|
|
|
|
|
|
|
|
// the geometry manager which handles the zone geometry, and
|
|
|
|
// hands the calculated points over to the zone creator tool
|
|
|
|
POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool );
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2018-10-12 04:11:42 +00:00
|
|
|
Activate(); // register for events
|
|
|
|
|
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->SetSnapping( true );
|
|
|
|
|
|
|
|
bool started = false;
|
2018-10-04 00:15:54 +00:00
|
|
|
GRID_HELPER grid( m_frame );
|
2018-02-19 14:25:07 +00:00
|
|
|
STATUS_TEXT_POPUP status( m_frame );
|
2018-03-02 09:55:59 +00:00
|
|
|
status.SetTextColor( wxColour( 255, 0, 0 ) );
|
|
|
|
status.SetText( _( "Self-intersecting polygons are not allowed" ) );
|
2014-02-14 09:47:43 +00:00
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
// Prime the pump
|
|
|
|
if( aEvent.HasPosition() )
|
2019-10-03 16:21:52 +00:00
|
|
|
m_toolMgr->PrimeTool( aEvent.Position() );
|
2019-06-24 15:27:05 +00:00
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2014-02-13 11:46:39 +00:00
|
|
|
{
|
2019-06-13 17:28:55 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
|
2018-10-04 00:15:54 +00:00
|
|
|
LSET layers( m_frame->GetActiveLayer() );
|
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2018-10-05 04:08:15 +00:00
|
|
|
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
|
2018-10-07 03:20:38 +00:00
|
|
|
m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
|
2019-10-03 16:21:52 +00:00
|
|
|
VECTOR2I cursorPos = grid.BestSnapAnchor(
|
|
|
|
evt->IsPrime() ? evt->Position() : m_controls->GetMousePosition(), layers );
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
2014-02-17 10:33:03 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
auto cleanup = [&] () {
|
|
|
|
polyGeomMgr.Reset();
|
|
|
|
started = false;
|
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
|
|
|
};
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive())
|
2014-02-13 11:46:39 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
if( polyGeomMgr.IsPolygonInProgress() )
|
|
|
|
cleanup();
|
|
|
|
else
|
2019-06-24 15:27:05 +00:00
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
if( polyGeomMgr.IsPolygonInProgress() )
|
|
|
|
cleanup();
|
2019-06-24 15:27:05 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsPointEditor() )
|
|
|
|
{
|
|
|
|
// don't exit (the point editor runs in the background)
|
2019-06-24 15:27:05 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsMoveTool() )
|
2014-02-19 12:51:32 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
// leave ourselves on the stack so we come back after the move
|
2014-02-19 12:51:32 +00:00
|
|
|
break;
|
2017-02-26 17:45:52 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2019-06-24 15:27:05 +00:00
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2018-10-12 04:11:42 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
|
|
|
|
{
|
2019-06-24 15:27:05 +00:00
|
|
|
if( zoneMode == ZONE_MODE::GRAPHIC_POLYGON )
|
2018-10-12 04:11:42 +00:00
|
|
|
params.m_layer = getDrawingLayer();
|
2019-06-24 15:27:05 +00:00
|
|
|
else if( zoneMode == ZONE_MODE::ADD || zoneMode == ZONE_MODE::CUTOUT )
|
2018-10-12 04:11:42 +00:00
|
|
|
params.m_layer = frame()->GetActiveLayer();
|
2014-02-13 11:46:39 +00:00
|
|
|
}
|
2017-01-09 17:29:40 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( selection() );
|
2017-01-09 17:29:40 +00:00
|
|
|
}
|
2017-02-26 17:45:52 +00:00
|
|
|
// events that lock in nodes
|
|
|
|
else if( evt->IsClick( BUT_LEFT )
|
2017-05-04 22:43:43 +00:00
|
|
|
|| evt->IsDblClick( BUT_LEFT )
|
2019-06-17 00:34:21 +00:00
|
|
|
|| evt->IsAction( &PCB_ACTIONS::closeZoneOutline ) )
|
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)
|
2017-02-26 17:45:52 +00:00
|
|
|
const bool endPolygon = evt->IsDblClick( BUT_LEFT )
|
2019-06-17 00:34:21 +00:00
|
|
|
|| evt->IsAction( &PCB_ACTIONS::closeZoneOutline )
|
2017-05-04 22:43:43 +00:00
|
|
|
|| polyGeomMgr.NewPointClosesOutline( cursorPos );
|
2017-02-26 17:45:52 +00:00
|
|
|
|
|
|
|
if( endPolygon )
|
2014-02-13 11:46:39 +00:00
|
|
|
{
|
2017-02-26 17:45:52 +00:00
|
|
|
polyGeomMgr.SetFinished();
|
|
|
|
polyGeomMgr.Reset();
|
2014-02-14 14:52:13 +00:00
|
|
|
|
2017-02-26 17:45:52 +00:00
|
|
|
started = false;
|
2018-10-12 04:11:42 +00:00
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
2017-02-26 17:45:52 +00:00
|
|
|
}
|
2018-02-19 14:25:07 +00:00
|
|
|
|
2018-01-01 21:14:08 +00:00
|
|
|
// adding a corner
|
|
|
|
else if( polyGeomMgr.AddPoint( cursorPos ) )
|
2017-02-26 17:45:52 +00:00
|
|
|
{
|
|
|
|
if( !started )
|
|
|
|
{
|
|
|
|
started = true;
|
2018-10-12 04:11:42 +00:00
|
|
|
m_controls->SetAutoPan( true );
|
|
|
|
m_controls->CaptureCursor( true );
|
2017-02-26 17:45:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-17 00:34:21 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) )
|
2017-02-26 17:45:52 +00:00
|
|
|
{
|
|
|
|
polyGeomMgr.DeleteLastCorner();
|
2014-02-14 09:47:43 +00:00
|
|
|
|
2017-02-26 17:45:52 +00:00
|
|
|
if( !polyGeomMgr.IsPolygonInProgress() )
|
|
|
|
{
|
|
|
|
// report finished as an empty shape
|
|
|
|
polyGeomMgr.SetFinished();
|
2017-02-06 05:59:55 +00:00
|
|
|
|
2017-02-26 17:45:52 +00:00
|
|
|
// start again
|
|
|
|
started = false;
|
2018-10-12 04:11:42 +00:00
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
2017-02-26 17:45:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( polyGeomMgr.IsPolygonInProgress()
|
2017-05-04 22:43:43 +00:00
|
|
|
&& ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
|
2017-02-26 17:45:52 +00:00
|
|
|
{
|
2018-02-20 14:51:40 +00:00
|
|
|
polyGeomMgr.SetCursorPosition( cursorPos, evt->Modifier( MD_CTRL )
|
|
|
|
? POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45
|
|
|
|
: POLYGON_GEOM_MANAGER::LEADER_MODE::DIRECT );
|
2018-03-02 09:55:59 +00:00
|
|
|
|
|
|
|
if( polyGeomMgr.IsSelfIntersecting( true ) )
|
|
|
|
{
|
|
|
|
wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 );
|
|
|
|
status.Move( p );
|
2019-05-19 21:04:04 +00:00
|
|
|
status.PopupFor( 1500 );
|
2018-03-02 09:55:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status.Hide();
|
|
|
|
}
|
2017-02-26 17:45:52 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
} // end while
|
2014-02-13 11:46:39 +00:00
|
|
|
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2014-07-09 12:01:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-22 15:46:31 +00:00
|
|
|
int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
struct VIA_PLACER : public INTERACTIVE_PLACER_BASE
|
|
|
|
{
|
2018-04-08 16:47:39 +00:00
|
|
|
GRID_HELPER m_gridHelper;
|
|
|
|
|
2019-06-09 23:21:50 +00:00
|
|
|
VIA_PLACER( PCB_BASE_EDIT_FRAME* aFrame ) : m_gridHelper( aFrame )
|
2018-04-08 16:47:39 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
TRACK* findTrack( VIA* aVia )
|
2017-04-22 15:46:31 +00:00
|
|
|
{
|
2018-04-08 16:47:39 +00:00
|
|
|
const LSET lset = aVia->GetLayerSet();
|
2019-07-22 03:19:55 +00:00
|
|
|
wxPoint position = aVia->GetPosition();
|
2019-01-23 15:18:44 +00:00
|
|
|
BOX2I bbox = aVia->GetBoundingBox();
|
2019-07-22 03:19:55 +00:00
|
|
|
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
|
2019-06-13 17:28:55 +00:00
|
|
|
auto view = m_frame->GetCanvas()->GetView();
|
2019-01-25 15:12:04 +00:00
|
|
|
std::vector<TRACK*> possible_tracks;
|
2017-04-22 15:46:31 +00:00
|
|
|
|
2019-01-23 15:18:44 +00:00
|
|
|
view->Query( bbox, items );
|
|
|
|
|
|
|
|
for( auto it : items )
|
2017-06-23 11:56:28 +00:00
|
|
|
{
|
2019-01-23 15:18:44 +00:00
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
|
|
|
|
|
|
|
|
if( !(item->GetLayerSet() & lset ).any() )
|
2018-04-08 16:47:39 +00:00
|
|
|
continue;
|
|
|
|
|
2019-01-23 15:18:44 +00:00
|
|
|
if( auto track = dyn_cast<TRACK*>( item ) )
|
|
|
|
{
|
2019-07-22 03:19:55 +00:00
|
|
|
if( TestSegmentHit( position, track->GetStart(), track->GetEnd(),
|
2019-01-23 15:18:44 +00:00
|
|
|
( track->GetWidth() + aVia->GetWidth() ) / 2 ) )
|
2019-01-25 15:12:04 +00:00
|
|
|
possible_tracks.push_back( track );
|
2019-01-23 15:18:44 +00:00
|
|
|
}
|
2017-06-23 11:56:28 +00:00
|
|
|
}
|
2017-05-04 22:43:43 +00:00
|
|
|
|
2019-01-25 15:12:04 +00:00
|
|
|
TRACK* return_track = nullptr;
|
|
|
|
int min_d = std::numeric_limits<int>::max();
|
|
|
|
for( auto track : possible_tracks )
|
|
|
|
{
|
|
|
|
SEG test( track->GetStart(), track->GetEnd() );
|
2019-07-22 03:19:55 +00:00
|
|
|
auto dist = ( test.NearestPoint( position ) - position ).EuclideanNorm();
|
2019-01-25 15:12:04 +00:00
|
|
|
|
|
|
|
if( dist < min_d )
|
|
|
|
{
|
|
|
|
min_d = dist;
|
|
|
|
return_track = track;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return return_track;
|
2018-04-08 16:47:39 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 15:18:44 +00:00
|
|
|
|
|
|
|
bool hasDRCViolation( VIA* aVia )
|
|
|
|
{
|
|
|
|
const LSET lset = aVia->GetLayerSet();
|
2019-07-22 03:19:55 +00:00
|
|
|
wxPoint position = aVia->GetPosition();
|
|
|
|
int drillRadius = aVia->GetDrillValue() / 2;
|
|
|
|
BOX2I bbox = aVia->GetBoundingBox();
|
|
|
|
|
2019-01-23 15:18:44 +00:00
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
|
|
|
|
int net = 0;
|
|
|
|
int clearance = 0;
|
2019-06-13 17:28:55 +00:00
|
|
|
auto view = m_frame->GetCanvas()->GetView();
|
2019-07-22 03:19:55 +00:00
|
|
|
int holeToHoleMin = m_frame->GetBoard()->GetDesignSettings().m_HoleToHoleMin;
|
2019-01-23 15:18:44 +00:00
|
|
|
|
|
|
|
view->Query( bbox, items );
|
|
|
|
|
|
|
|
for( auto it : items )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
|
|
|
|
|
|
|
|
if( !(item->GetLayerSet() & lset ).any() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( auto track = dyn_cast<TRACK*>( item ) )
|
|
|
|
{
|
|
|
|
int max_clearance = std::max( clearance, track->GetClearance() );
|
|
|
|
|
2019-07-22 03:19:55 +00:00
|
|
|
if( TestSegmentHit( position, track->GetStart(), track->GetEnd(),
|
2019-01-23 15:18:44 +00:00
|
|
|
( track->GetWidth() + aVia->GetWidth() ) / 2 + max_clearance ) )
|
|
|
|
{
|
|
|
|
if( net && track->GetNetCode() != net )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
net = track->GetNetCode();
|
|
|
|
clearance = track->GetClearance();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-22 03:19:55 +00:00
|
|
|
if( auto via = dyn_cast<VIA*>( item ) )
|
|
|
|
{
|
|
|
|
int dist = KiROUND( GetLineLength( position, via->GetPosition() ) );
|
|
|
|
|
|
|
|
if( dist < drillRadius + via->GetDrillValue() / 2 + holeToHoleMin )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-23 15:18:44 +00:00
|
|
|
if( auto mod = dyn_cast<MODULE*>( item ) )
|
|
|
|
{
|
2019-07-22 03:19:55 +00:00
|
|
|
for( D_PAD* pad : mod->Pads() )
|
2019-01-23 15:18:44 +00:00
|
|
|
{
|
|
|
|
int max_clearance = std::max( clearance, pad->GetClearance() );
|
|
|
|
|
|
|
|
if( pad->HitTest( aVia->GetBoundingBox(), false, max_clearance ) )
|
|
|
|
{
|
|
|
|
if( net && pad->GetNetCode() != net )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
net = pad->GetNetCode();
|
|
|
|
clearance = pad->GetClearance();
|
|
|
|
}
|
2019-07-22 03:19:55 +00:00
|
|
|
|
|
|
|
if( pad->GetDrillSize().x && pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
|
|
|
|
{
|
|
|
|
int dist = KiROUND( GetLineLength( position, pad->GetPosition() ) );
|
|
|
|
|
|
|
|
if( dist < drillRadius + pad->GetDrillSize().x / 2 + holeToHoleMin )
|
|
|
|
return true;
|
|
|
|
}
|
2019-01-23 15:18:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-08 16:47:39 +00:00
|
|
|
int findStitchedZoneNet( VIA* aVia )
|
|
|
|
{
|
2019-07-22 03:19:55 +00:00
|
|
|
const wxPoint position = aVia->GetPosition();
|
|
|
|
const LSET lset = aVia->GetLayerSet();
|
2018-04-08 16:47:39 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
for( auto mod : m_board->Modules() )
|
2017-06-23 11:56:28 +00:00
|
|
|
{
|
2018-04-08 16:47:39 +00:00
|
|
|
for( D_PAD* pad : mod->Pads() )
|
2017-06-23 11:56:28 +00:00
|
|
|
{
|
2019-07-22 03:19:55 +00:00
|
|
|
if( pad->HitTest( position ) && ( pad->GetLayerSet() & lset ).any() )
|
2017-05-04 22:43:43 +00:00
|
|
|
return -1;
|
2017-06-23 11:56:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-04 22:43:43 +00:00
|
|
|
|
|
|
|
std::vector<ZONE_CONTAINER*> foundZones;
|
2017-04-22 15:46:31 +00:00
|
|
|
|
2019-07-22 03:19:55 +00:00
|
|
|
for( ZONE_CONTAINER* zone : m_board->Zones() )
|
2017-04-22 15:46:31 +00:00
|
|
|
{
|
2019-07-22 03:19:55 +00:00
|
|
|
if( zone->HitTestFilledArea( position ) )
|
2017-05-04 22:43:43 +00:00
|
|
|
foundZones.push_back( zone );
|
2017-04-22 15:46:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
std::sort( foundZones.begin(), foundZones.end(),
|
2019-07-22 03:19:55 +00:00
|
|
|
[] ( const ZONE_CONTAINER* a, const ZONE_CONTAINER* b )
|
|
|
|
{
|
|
|
|
return a->GetLayer() < b->GetLayer();
|
|
|
|
} );
|
2017-05-04 22:43:43 +00:00
|
|
|
|
|
|
|
// first take the net of the active layer
|
2019-07-22 03:19:55 +00:00
|
|
|
for( ZONE_CONTAINER* z : foundZones )
|
2017-04-22 15:46:31 +00:00
|
|
|
{
|
2017-05-04 22:43:43 +00:00
|
|
|
if( m_frame->GetActiveLayer() == z->GetLayer() )
|
2017-04-22 15:46:31 +00:00
|
|
|
return z->GetNetCode();
|
|
|
|
}
|
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
// none? take the topmost visible layer
|
2019-07-22 03:19:55 +00:00
|
|
|
for( ZONE_CONTAINER* z : foundZones )
|
2017-05-04 22:43:43 +00:00
|
|
|
{
|
|
|
|
if( m_board->IsLayerVisible( z->GetLayer() ) )
|
|
|
|
return z->GetNetCode();
|
|
|
|
}
|
2017-04-22 15:46:31 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-04-08 16:47:39 +00:00
|
|
|
void SnapItem( BOARD_ITEM *aItem ) override
|
|
|
|
{
|
|
|
|
// If you place a Via on a track but not on its centerline, the current
|
|
|
|
// connectivity algorithm will require us to put a kink in the track when
|
|
|
|
// we break it (so that each of the two segments ends on the via center).
|
|
|
|
// That's not ideal, and is in fact probably worse than forcing snap in
|
|
|
|
// this situation.
|
2018-05-07 20:49:36 +00:00
|
|
|
|
2018-10-04 00:15:54 +00:00
|
|
|
m_gridHelper.SetSnap( !( m_modifiers & MD_SHIFT ) );
|
|
|
|
auto via = static_cast<VIA*>( aItem );
|
2019-07-22 03:19:55 +00:00
|
|
|
wxPoint position = via->GetPosition();
|
2018-10-04 00:15:54 +00:00
|
|
|
TRACK* track = findTrack( via );
|
2018-05-07 20:49:36 +00:00
|
|
|
|
2018-10-04 00:15:54 +00:00
|
|
|
if( track )
|
2018-04-08 16:47:39 +00:00
|
|
|
{
|
2019-07-22 03:19:55 +00:00
|
|
|
SEG trackSeg( track->GetStart(), track->GetEnd() );
|
|
|
|
VECTOR2I snap = m_gridHelper.AlignToSegment( position, trackSeg );
|
2018-04-08 16:47:39 +00:00
|
|
|
|
2019-04-19 18:23:18 +00:00
|
|
|
aItem->SetPosition( (wxPoint) snap );
|
2018-04-08 16:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 15:18:44 +00:00
|
|
|
bool PlaceItem( BOARD_ITEM* aItem, BOARD_COMMIT& aCommit ) override
|
2017-04-22 15:46:31 +00:00
|
|
|
{
|
2019-07-06 21:53:50 +00:00
|
|
|
VIA* via = static_cast<VIA*>( aItem );
|
|
|
|
wxPoint viaPos = via->GetPosition();
|
2018-04-08 16:47:39 +00:00
|
|
|
int newNet;
|
|
|
|
TRACK* track = findTrack( via );
|
|
|
|
|
2019-01-23 15:18:44 +00:00
|
|
|
if( hasDRCViolation( via ) )
|
|
|
|
return false;
|
|
|
|
|
2018-04-08 16:47:39 +00:00
|
|
|
if( track )
|
|
|
|
{
|
2019-07-06 21:53:50 +00:00
|
|
|
if( viaPos != track->GetStart() && viaPos != track->GetEnd() )
|
|
|
|
{
|
|
|
|
aCommit.Modify( track );
|
|
|
|
TRACK* newTrack = dynamic_cast<TRACK*>( track->Clone() );
|
|
|
|
track->SetEnd( viaPos );
|
|
|
|
newTrack->SetStart( viaPos );
|
|
|
|
aCommit.Add( newTrack );
|
|
|
|
}
|
2018-04-08 16:47:39 +00:00
|
|
|
|
|
|
|
newNet = track->GetNetCode();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
newNet = findStitchedZoneNet( via );
|
2017-04-22 15:46:31 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
if( newNet > 0 )
|
2017-04-22 15:46:31 +00:00
|
|
|
via->SetNetCode( newNet );
|
|
|
|
|
2018-04-08 16:47:39 +00:00
|
|
|
aCommit.Add( aItem );
|
2019-01-23 15:18:44 +00:00
|
|
|
return true;
|
2017-04-22 15:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<BOARD_ITEM> CreateItem() override
|
|
|
|
{
|
2017-05-04 22:43:43 +00:00
|
|
|
auto& ds = m_board->GetDesignSettings();
|
|
|
|
VIA* via = new VIA( m_board );
|
2017-04-22 15:46:31 +00:00
|
|
|
|
|
|
|
via->SetNetCode( 0 );
|
|
|
|
via->SetViaType( ds.m_CurrentViaType );
|
|
|
|
|
|
|
|
// for microvias, the size and hole will be changed later.
|
2017-05-04 22:43:43 +00:00
|
|
|
via->SetWidth( ds.GetCurrentViaSize() );
|
2017-04-22 15:46:31 +00:00
|
|
|
via->SetDrill( ds.GetCurrentViaDrill() );
|
|
|
|
|
|
|
|
// Usual via is from copper to component.
|
|
|
|
// layer pair is B_Cu and F_Cu.
|
|
|
|
via->SetLayerPair( B_Cu, F_Cu );
|
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
PCB_LAYER_ID first_layer = m_frame->GetActiveLayer();
|
|
|
|
PCB_LAYER_ID last_layer;
|
2017-04-22 15:46:31 +00:00
|
|
|
|
|
|
|
// prepare switch to new active layer:
|
|
|
|
if( first_layer != m_frame->GetScreen()->m_Route_Layer_TOP )
|
|
|
|
last_layer = m_frame->GetScreen()->m_Route_Layer_TOP;
|
|
|
|
else
|
|
|
|
last_layer = m_frame->GetScreen()->m_Route_Layer_BOTTOM;
|
|
|
|
|
|
|
|
// Adjust the actual via layer pair
|
|
|
|
switch( via->GetViaType() )
|
|
|
|
{
|
|
|
|
case VIA_BLIND_BURIED:
|
|
|
|
via->SetLayerPair( first_layer, last_layer );
|
|
|
|
break;
|
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
case VIA_MICROVIA: // from external to the near neighbor inner layer
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID last_inner_layer =
|
|
|
|
ToLAYER_ID( ( m_board->GetCopperLayerCount() - 2 ) );
|
|
|
|
|
|
|
|
if( first_layer == B_Cu )
|
|
|
|
last_layer = last_inner_layer;
|
|
|
|
else if( first_layer == F_Cu )
|
|
|
|
last_layer = In1_Cu;
|
|
|
|
else if( first_layer == last_inner_layer )
|
|
|
|
last_layer = B_Cu;
|
|
|
|
else if( first_layer == In1_Cu )
|
|
|
|
last_layer = F_Cu;
|
|
|
|
|
|
|
|
// else error: will be removed later
|
|
|
|
via->SetLayerPair( first_layer, last_layer );
|
|
|
|
|
|
|
|
// Update diameter and hole size, which where set previously
|
|
|
|
// for normal vias
|
|
|
|
NETINFO_ITEM* net = via->GetNet();
|
|
|
|
|
|
|
|
if( net )
|
2017-04-22 15:46:31 +00:00
|
|
|
{
|
2017-05-04 22:43:43 +00:00
|
|
|
via->SetWidth( net->GetMicroViaSize() );
|
|
|
|
via->SetDrill( net->GetMicroViaDrillSize() );
|
2017-04-22 15:46:31 +00:00
|
|
|
}
|
2017-05-04 22:43:43 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-04-22 15:46:31 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
return std::unique_ptr<BOARD_ITEM>( via );
|
2017-04-22 15:46:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-08 16:47:39 +00:00
|
|
|
VIA_PLACER placer( frame() );
|
2017-04-22 15:46:31 +00:00
|
|
|
|
2018-08-01 16:58:27 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::VIA );
|
2017-04-22 15:46:31 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
doInteractiveItemPlacement( aEvent.GetCommandStr().get(), &placer, _( "Place via" ),
|
|
|
|
IPO_REPEAT | IPO_SINGLE_CLICK );
|
2017-04-22 15:46:31 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-02-14 13:24:12 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
int DRAWING_TOOL::getSegmentWidth( PCB_LAYER_ID aLayer ) const
|
2014-09-01 11:48:51 +00:00
|
|
|
{
|
|
|
|
assert( m_board );
|
2018-04-28 15:22:25 +00:00
|
|
|
return m_board->GetDesignSettings().GetLineThickness( aLayer );
|
2014-09-01 11:48:51 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 15:58:26 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID DRAWING_TOOL::getDrawingLayer() const
|
2017-02-08 09:13:43 +00:00
|
|
|
{
|
2019-04-03 17:20:14 +00:00
|
|
|
PCB_LAYER_ID layer = m_frame->GetActiveLayer();
|
|
|
|
|
|
|
|
if( ( GetDrawingMode() == MODE::DIMENSION || GetDrawingMode() == MODE::GRAPHIC_POLYGON )
|
|
|
|
&& 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;
|
2017-02-08 09:13:43 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
|
2019-02-14 09:55:57 +00:00
|
|
|
const unsigned int DRAWING_TOOL::WIDTH_STEP = Millimeter2iu( 0.1 );
|
2019-06-24 15:27:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DRAWING_TOOL::setTransitions()
|
|
|
|
{
|
|
|
|
Go( &DRAWING_TOOL::DrawLine, PCB_ACTIONS::drawLine.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawPolygon.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawCircle, PCB_ACTIONS::drawCircle.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawArc, PCB_ACTIONS::drawArc.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawDimension, PCB_ACTIONS::drawDimension.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawZone.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawZoneKeepout.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawZoneCutout.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawSimilarZone.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawVia, PCB_ACTIONS::drawVia.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::PlaceText, PCB_ACTIONS::placeText.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::PlaceImportedGraphics, PCB_ACTIONS::placeImportedGraphics.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::SetAnchor, PCB_ACTIONS::setAnchor.MakeEvent() );
|
|
|
|
}
|